| 104 | } |
| 105 | |
| 106 | export function createCacheEditsBlock( |
| 107 | state: CachedMCState, |
| 108 | toolUseIds: string[], |
| 109 | ): CacheEditsBlock | null { |
| 110 | const uniqueIds = toolUseIds.filter( |
| 111 | (toolUseId, index, ids) => |
| 112 | ids.indexOf(toolUseId) === index && !state.deletedRefs.has(toolUseId), |
| 113 | ) |
| 114 | |
| 115 | if (uniqueIds.length === 0) { |
| 116 | return null |
| 117 | } |
| 118 | |
| 119 | for (const toolUseId of uniqueIds) { |
| 120 | state.deletedRefs.add(toolUseId) |
| 121 | } |
| 122 | |
| 123 | return { |
| 124 | type: 'cache_edits', |
| 125 | edits: uniqueIds.map(cache_reference => ({ |
| 126 | type: 'delete', |
| 127 | cache_reference, |
| 128 | })), |
| 129 | } |
| 130 | } |