(
context: SearchContext,
startReference: BoundaryReference,
endReference: BoundaryReference,
)
| 107 | } |
| 108 | |
| 109 | export function resolveSelection( |
| 110 | context: SearchContext, |
| 111 | startReference: BoundaryReference, |
| 112 | endReference: BoundaryReference, |
| 113 | ): SelectionResolution { |
| 114 | const startRawIndex = startReference.rawIndex |
| 115 | const endRawIndex = endReference.rawIndex |
| 116 | const messageIds: string[] = [] |
| 117 | const messageSeen = new Set<string>() |
| 118 | const toolIds: string[] = [] |
| 119 | const toolSeen = new Set<string>() |
| 120 | const requiredBlockIds: number[] = [] |
| 121 | const requiredBlockSeen = new Set<number>() |
| 122 | const messageTokenById = new Map<string, number>() |
| 123 | |
| 124 | for (let index = startRawIndex; index <= endRawIndex; index++) { |
| 125 | const rawMessage = context.rawMessages[index] |
| 126 | if (!rawMessage) { |
| 127 | continue |
| 128 | } |
| 129 | if (isIgnoredUserMessage(rawMessage)) { |
| 130 | continue |
| 131 | } |
| 132 | |
| 133 | const messageId = rawMessage.info.id |
| 134 | if (!messageSeen.has(messageId)) { |
| 135 | messageSeen.add(messageId) |
| 136 | messageIds.push(messageId) |
| 137 | } |
| 138 | |
| 139 | if (!messageTokenById.has(messageId)) { |
| 140 | messageTokenById.set(messageId, countAllMessageTokens(rawMessage)) |
| 141 | } |
| 142 | |
| 143 | const parts = Array.isArray(rawMessage.parts) ? rawMessage.parts : [] |
| 144 | for (const part of parts) { |
| 145 | if (part.type !== "tool" || !part.callID) { |
| 146 | continue |
| 147 | } |
| 148 | if (toolSeen.has(part.callID)) { |
| 149 | continue |
| 150 | } |
| 151 | toolSeen.add(part.callID) |
| 152 | toolIds.push(part.callID) |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | const selectedMessageIds = new Set(messageIds) |
| 157 | const summariesInSelection: Array<{ blockId: number; rawIndex: number }> = [] |
| 158 | for (const summary of context.summaryByBlockId.values()) { |
| 159 | if (!selectedMessageIds.has(summary.anchorMessageId)) { |
| 160 | continue |
| 161 | } |
| 162 | |
| 163 | const anchorIndex = context.rawIndexById.get(summary.anchorMessageId) |
| 164 | if (anchorIndex === undefined) { |
| 165 | continue |
| 166 | } |
no test coverage detected