MCPcopy Index your code
hub / github.com/Noumena-Network/code / yieldMissingToolResultBlocks

Function yieldMissingToolResultBlocks

src/query.ts:128–158  ·  view source on GitHub ↗
(
  assistantMessages: AssistantMessage[],
  errorMessage: string,
  existingToolResultIds: ReadonlySet<string> = new Set(),
)

Source from the content-addressed store, hash-verified

126/* eslint-enable @typescript-eslint/no-require-imports */
127
128function* yieldMissingToolResultBlocks(
129 assistantMessages: AssistantMessage[],
130 errorMessage: string,
131 existingToolResultIds: ReadonlySet<string> = new Set(),
132) {
133 for (const assistantMessage of assistantMessages) {
134 // Extract all tool use blocks from this assistant message
135 const toolUseBlocks = assistantMessage.message.content.filter(
136 content => content.type === 'tool_use',
137 ) as ToolUseBlock[]
138
139 // Emit an interruption message for each tool use
140 for (const toolUse of toolUseBlocks) {
141 if (existingToolResultIds.has(toolUse.id)) {
142 continue
143 }
144 yield createUserMessage({
145 content: [
146 {
147 type: 'tool_result',
148 content: errorMessage,
149 is_error: true,
150 tool_use_id: toolUse.id,
151 },
152 ],
153 toolUseResult: errorMessage,
154 sourceToolAssistantUUID: assistantMessage.uuid,
155 })
156 }
157 }
158}
159
160function collectToolResultIds(messages: Message[]): Set<string> {
161 const ids = new Set<string>()

Callers 1

queryLoopFunction · 0.85

Calls 2

createUserMessageFunction · 0.50
hasMethod · 0.45

Tested by

no test coverage detected