@illuma-ai/agents 1.0.90 → 1.0.93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/agents/AgentContext.cjs +98 -49
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/common/constants.cjs +25 -0
- package/dist/cjs/common/constants.cjs.map +1 -0
- package/dist/cjs/common/enum.cjs +30 -0
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/events.cjs +9 -4
- package/dist/cjs/events.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +397 -92
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +223 -92
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/instrumentation.cjs +30 -14
- package/dist/cjs/instrumentation.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/index.cjs +43 -11
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/types.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +10 -7
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +32 -0
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/tools.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/index.cjs +129 -101
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +489 -0
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -0
- package/dist/cjs/llm/bedrock/utils/message_outputs.cjs +176 -0
- package/dist/cjs/llm/bedrock/utils/message_outputs.cjs.map +1 -0
- package/dist/cjs/llm/fake.cjs.map +1 -1
- package/dist/cjs/llm/google/index.cjs.map +1 -1
- package/dist/cjs/llm/google/utils/common.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +1 -1
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
- package/dist/cjs/llm/openrouter/index.cjs +59 -5
- package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
- package/dist/cjs/llm/providers.cjs.map +1 -1
- package/dist/cjs/llm/text.cjs.map +1 -1
- package/dist/cjs/llm/vertexai/index.cjs +80 -2
- package/dist/cjs/llm/vertexai/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +60 -27
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/messages/cache.cjs +131 -108
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/messages/content.cjs.map +1 -1
- package/dist/cjs/messages/core.cjs +3 -0
- package/dist/cjs/messages/core.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +265 -47
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/messages/ids.cjs.map +1 -1
- package/dist/cjs/messages/prune.cjs +55 -2
- package/dist/cjs/messages/prune.cjs.map +1 -1
- package/dist/cjs/messages/summarize.cjs +170 -0
- package/dist/cjs/messages/summarize.cjs.map +1 -0
- package/dist/cjs/messages/tools.cjs.map +1 -1
- package/dist/cjs/run.cjs +87 -30
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/schemas/validate.cjs.map +1 -1
- package/dist/cjs/splitStream.cjs.map +1 -1
- package/dist/cjs/stream.cjs +59 -25
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/tools/AskUser.cjs +131 -0
- package/dist/cjs/tools/AskUser.cjs.map +1 -0
- package/dist/cjs/tools/BrowserTools.cjs +11 -7
- package/dist/cjs/tools/BrowserTools.cjs.map +1 -1
- package/dist/cjs/tools/Calculator.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +46 -4
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +36 -53
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/StreamingToolCallBuffer.cjs +208 -0
- package/dist/cjs/tools/StreamingToolCallBuffer.cjs.map +1 -0
- package/dist/cjs/tools/ToolNode.cjs +333 -30
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/ToolSearch.cjs +66 -30
- package/dist/cjs/tools/ToolSearch.cjs.map +1 -1
- package/dist/cjs/tools/handlers.cjs +94 -8
- package/dist/cjs/tools/handlers.cjs.map +1 -1
- package/dist/cjs/tools/schema.cjs.map +1 -1
- package/dist/cjs/tools/search/content.cjs.map +1 -1
- package/dist/cjs/tools/search/firecrawl.cjs.map +1 -1
- package/dist/cjs/tools/search/format.cjs.map +1 -1
- package/dist/cjs/tools/search/highlights.cjs.map +1 -1
- package/dist/cjs/tools/search/rerankers.cjs.map +1 -1
- package/dist/cjs/tools/search/schema.cjs.map +1 -1
- package/dist/cjs/tools/search/search.cjs +1 -0
- package/dist/cjs/tools/search/search.cjs.map +1 -1
- package/dist/cjs/tools/search/serper-scraper.cjs.map +1 -1
- package/dist/cjs/tools/search/tool.cjs.map +1 -1
- package/dist/cjs/tools/search/utils.cjs.map +1 -1
- package/dist/cjs/types/graph.cjs +1 -1
- package/dist/cjs/types/graph.cjs.map +1 -1
- package/dist/cjs/utils/contextAnalytics.cjs +23 -6
- package/dist/cjs/utils/contextAnalytics.cjs.map +1 -1
- package/dist/cjs/utils/events.cjs.map +1 -1
- package/dist/cjs/utils/graph.cjs.map +1 -1
- package/dist/cjs/utils/handlers.cjs.map +1 -1
- package/dist/cjs/utils/llm.cjs.map +1 -1
- package/dist/cjs/utils/misc.cjs.map +1 -1
- package/dist/cjs/utils/run.cjs +3 -1
- package/dist/cjs/utils/run.cjs.map +1 -1
- package/dist/cjs/utils/schema.cjs.map +1 -1
- package/dist/cjs/utils/title.cjs.map +1 -1
- package/dist/cjs/utils/tokens.cjs +33 -58
- package/dist/cjs/utils/tokens.cjs.map +1 -1
- package/dist/cjs/utils/toolCallContinuation.cjs +55 -0
- package/dist/cjs/utils/toolCallContinuation.cjs.map +1 -0
- package/dist/cjs/utils/toonFormat.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +98 -49
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/common/constants.mjs +22 -0
- package/dist/esm/common/constants.mjs.map +1 -0
- package/dist/esm/common/enum.mjs +31 -1
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/events.mjs +9 -4
- package/dist/esm/events.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +393 -88
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +224 -93
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/instrumentation.mjs +30 -14
- package/dist/esm/instrumentation.mjs.map +1 -1
- package/dist/esm/llm/anthropic/index.mjs +43 -11
- package/dist/esm/llm/anthropic/index.mjs.map +1 -1
- package/dist/esm/llm/anthropic/types.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +10 -7
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs +32 -0
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/tools.mjs.map +1 -1
- package/dist/esm/llm/bedrock/index.mjs +128 -101
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs +484 -0
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -0
- package/dist/esm/llm/bedrock/utils/message_outputs.mjs +171 -0
- package/dist/esm/llm/bedrock/utils/message_outputs.mjs.map +1 -0
- package/dist/esm/llm/fake.mjs.map +1 -1
- package/dist/esm/llm/google/index.mjs.map +1 -1
- package/dist/esm/llm/google/utils/common.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +1 -1
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
- package/dist/esm/llm/openrouter/index.mjs +59 -5
- package/dist/esm/llm/openrouter/index.mjs.map +1 -1
- package/dist/esm/llm/providers.mjs.map +1 -1
- package/dist/esm/llm/text.mjs.map +1 -1
- package/dist/esm/llm/vertexai/index.mjs +80 -2
- package/dist/esm/llm/vertexai/index.mjs.map +1 -1
- package/dist/esm/main.mjs +8 -3
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/messages/cache.mjs +131 -108
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/content.mjs.map +1 -1
- package/dist/esm/messages/core.mjs +4 -1
- package/dist/esm/messages/core.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +267 -49
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/messages/ids.mjs.map +1 -1
- package/dist/esm/messages/prune.mjs +56 -4
- package/dist/esm/messages/prune.mjs.map +1 -1
- package/dist/esm/messages/summarize.mjs +161 -0
- package/dist/esm/messages/summarize.mjs.map +1 -0
- package/dist/esm/messages/tools.mjs.map +1 -1
- package/dist/esm/run.mjs +88 -31
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/schemas/validate.mjs.map +1 -1
- package/dist/esm/splitStream.mjs.map +1 -1
- package/dist/esm/stream.mjs +60 -26
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/tools/AskUser.mjs +125 -0
- package/dist/esm/tools/AskUser.mjs.map +1 -0
- package/dist/esm/tools/BrowserTools.mjs +11 -7
- package/dist/esm/tools/BrowserTools.mjs.map +1 -1
- package/dist/esm/tools/Calculator.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +46 -4
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +37 -54
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/StreamingToolCallBuffer.mjs +206 -0
- package/dist/esm/tools/StreamingToolCallBuffer.mjs.map +1 -0
- package/dist/esm/tools/ToolNode.mjs +333 -30
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/ToolSearch.mjs +66 -30
- package/dist/esm/tools/ToolSearch.mjs.map +1 -1
- package/dist/esm/tools/handlers.mjs +95 -9
- package/dist/esm/tools/handlers.mjs.map +1 -1
- package/dist/esm/tools/schema.mjs.map +1 -1
- package/dist/esm/tools/search/content.mjs.map +1 -1
- package/dist/esm/tools/search/firecrawl.mjs.map +1 -1
- package/dist/esm/tools/search/format.mjs.map +1 -1
- package/dist/esm/tools/search/highlights.mjs.map +1 -1
- package/dist/esm/tools/search/rerankers.mjs.map +1 -1
- package/dist/esm/tools/search/schema.mjs.map +1 -1
- package/dist/esm/tools/search/search.mjs +1 -0
- package/dist/esm/tools/search/search.mjs.map +1 -1
- package/dist/esm/tools/search/serper-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/tool.mjs.map +1 -1
- package/dist/esm/tools/search/utils.mjs.map +1 -1
- package/dist/esm/types/graph.mjs +1 -1
- package/dist/esm/types/graph.mjs.map +1 -1
- package/dist/esm/utils/contextAnalytics.mjs +23 -6
- package/dist/esm/utils/contextAnalytics.mjs.map +1 -1
- package/dist/esm/utils/events.mjs.map +1 -1
- package/dist/esm/utils/graph.mjs.map +1 -1
- package/dist/esm/utils/handlers.mjs.map +1 -1
- package/dist/esm/utils/llm.mjs.map +1 -1
- package/dist/esm/utils/misc.mjs.map +1 -1
- package/dist/esm/utils/run.mjs +3 -1
- package/dist/esm/utils/run.mjs.map +1 -1
- package/dist/esm/utils/schema.mjs.map +1 -1
- package/dist/esm/utils/title.mjs.map +1 -1
- package/dist/esm/utils/tokens.mjs +33 -59
- package/dist/esm/utils/tokens.mjs.map +1 -1
- package/dist/esm/utils/toolCallContinuation.mjs +52 -0
- package/dist/esm/utils/toolCallContinuation.mjs.map +1 -0
- package/dist/esm/utils/toonFormat.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +14 -7
- package/dist/types/common/constants.d.ts +18 -0
- package/dist/types/common/enum.d.ts +28 -0
- package/dist/types/common/index.d.ts +1 -0
- package/dist/types/events.d.ts +10 -3
- package/dist/types/graphs/Graph.d.ts +37 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/llm/anthropic/index.d.ts +7 -1
- package/dist/types/llm/anthropic/types.d.ts +5 -2
- package/dist/types/llm/anthropic/utils/message_outputs.d.ts +1 -1
- package/dist/types/llm/bedrock/index.d.ts +40 -33
- package/dist/types/llm/bedrock/utils/message_outputs.d.ts +1 -1
- package/dist/types/llm/google/index.d.ts +2 -3
- package/dist/types/llm/openrouter/index.d.ts +21 -1
- package/dist/types/llm/vertexai/index.d.ts +3 -2
- package/dist/types/messages/cache.d.ts +1 -1
- package/dist/types/messages/index.d.ts +1 -0
- package/dist/types/messages/prune.d.ts +2 -7
- package/dist/types/messages/summarize.d.ts +33 -0
- package/dist/types/run.d.ts +6 -0
- package/dist/types/tools/AskUser.d.ts +408 -0
- package/dist/types/tools/BrowserTools.d.ts +2 -2
- package/dist/types/tools/CodeExecutor.d.ts +2 -2
- package/dist/types/tools/StreamingToolCallBuffer.d.ts +106 -0
- package/dist/types/tools/ToolNode.d.ts +55 -3
- package/dist/types/tools/ToolSearch.d.ts +9 -5
- package/dist/types/tools/handlers.d.ts +2 -2
- package/dist/types/types/graph.d.ts +9 -2
- package/dist/types/types/llm.d.ts +8 -3
- package/dist/types/types/run.d.ts +2 -0
- package/dist/types/types/tools.d.ts +20 -2
- package/dist/types/utils/contextAnalytics.d.ts +5 -4
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/tokens.d.ts +6 -19
- package/dist/types/utils/toolCallContinuation.d.ts +30 -0
- package/package.json +15 -8
- package/src/agents/AgentContext.js +782 -0
- package/src/agents/AgentContext.js.map +1 -0
- package/src/agents/AgentContext.test.js +421 -0
- package/src/agents/AgentContext.test.js.map +1 -0
- package/src/agents/AgentContext.ts +132 -64
- package/src/agents/__tests__/AgentContext.test.js +678 -0
- package/src/agents/__tests__/AgentContext.test.js.map +1 -0
- package/src/agents/__tests__/AgentContext.test.ts +25 -4
- package/src/agents/__tests__/resolveStructuredOutputMode.test.js +117 -0
- package/src/agents/__tests__/resolveStructuredOutputMode.test.js.map +1 -0
- package/src/common/__tests__/enum.test.ts +135 -0
- package/src/common/constants.ts +21 -0
- package/src/common/enum.js +192 -0
- package/src/common/enum.js.map +1 -0
- package/src/common/enum.ts +30 -0
- package/src/common/index.js +3 -0
- package/src/common/index.js.map +1 -0
- package/src/common/index.ts +2 -1
- package/src/events.js +166 -0
- package/src/events.js.map +1 -0
- package/src/events.ts +11 -14
- package/src/graphs/Graph.js +1857 -0
- package/src/graphs/Graph.js.map +1 -0
- package/src/graphs/Graph.ts +580 -162
- package/src/graphs/MultiAgentGraph.js +1092 -0
- package/src/graphs/MultiAgentGraph.js.map +1 -0
- package/src/graphs/MultiAgentGraph.ts +331 -112
- package/src/graphs/__tests__/adaptive-thinking.test.ts +369 -0
- package/src/graphs/__tests__/graph-direct-tool-names.test.ts +210 -0
- package/src/graphs/__tests__/multi-agent-edges.test.ts +237 -0
- package/src/graphs/__tests__/structured-output.integration.test.js +624 -0
- package/src/graphs/__tests__/structured-output.integration.test.js.map +1 -0
- package/src/graphs/__tests__/structured-output.test.js +144 -0
- package/src/graphs/__tests__/structured-output.test.js.map +1 -0
- package/src/graphs/contextManagement.e2e.test.js +718 -0
- package/src/graphs/contextManagement.e2e.test.js.map +1 -0
- package/src/graphs/contextManagement.e2e.test.ts +990 -0
- package/src/graphs/contextManagement.test.js +485 -0
- package/src/graphs/contextManagement.test.js.map +1 -0
- package/src/graphs/contextManagement.test.ts +625 -0
- package/src/graphs/handoffValidation.test.js +276 -0
- package/src/graphs/handoffValidation.test.js.map +1 -0
- package/src/graphs/handoffValidation.test.ts +353 -0
- package/src/graphs/index.js +3 -0
- package/src/graphs/index.js.map +1 -0
- package/src/index.js +28 -0
- package/src/index.js.map +1 -0
- package/src/index.ts +13 -0
- package/src/instrumentation.js +21 -0
- package/src/instrumentation.js.map +1 -0
- package/src/instrumentation.ts +38 -17
- package/src/llm/anthropic/index.js +319 -0
- package/src/llm/anthropic/index.js.map +1 -0
- package/src/llm/anthropic/index.ts +68 -15
- package/src/llm/anthropic/llm.spec.ts +402 -0
- package/src/llm/anthropic/types.js +46 -0
- package/src/llm/anthropic/types.js.map +1 -0
- package/src/llm/anthropic/types.ts +8 -2
- package/src/llm/anthropic/utils/message_inputs.js +627 -0
- package/src/llm/anthropic/utils/message_inputs.js.map +1 -0
- package/src/llm/anthropic/utils/message_inputs.ts +16 -33
- package/src/llm/anthropic/utils/message_outputs.js +290 -0
- package/src/llm/anthropic/utils/message_outputs.js.map +1 -0
- package/src/llm/anthropic/utils/message_outputs.ts +40 -1
- package/src/llm/anthropic/utils/output_parsers.js +89 -0
- package/src/llm/anthropic/utils/output_parsers.js.map +1 -0
- package/src/llm/anthropic/utils/tools.js +25 -0
- package/src/llm/anthropic/utils/tools.js.map +1 -0
- package/src/llm/bedrock/__tests__/bedrock-caching.test.js +392 -0
- package/src/llm/bedrock/__tests__/bedrock-caching.test.js.map +1 -0
- package/src/llm/bedrock/__tests__/bedrock-caching.test.ts +24 -40
- package/src/llm/bedrock/index.js +303 -0
- package/src/llm/bedrock/index.js.map +1 -0
- package/src/llm/bedrock/index.ts +171 -134
- package/src/llm/bedrock/llm.spec.ts +395 -52
- package/src/llm/bedrock/types.js +2 -0
- package/src/llm/bedrock/types.js.map +1 -0
- package/src/llm/bedrock/utils/index.js +6 -0
- package/src/llm/bedrock/utils/index.js.map +1 -0
- package/src/llm/bedrock/utils/message_inputs.js +463 -0
- package/src/llm/bedrock/utils/message_inputs.js.map +1 -0
- package/src/llm/bedrock/utils/message_inputs.ts +30 -5
- package/src/llm/bedrock/utils/message_outputs.js +269 -0
- package/src/llm/bedrock/utils/message_outputs.js.map +1 -0
- package/src/llm/bedrock/utils/message_outputs.ts +70 -22
- package/src/llm/fake.js +92 -0
- package/src/llm/fake.js.map +1 -0
- package/src/llm/google/index.js +215 -0
- package/src/llm/google/index.js.map +1 -0
- package/src/llm/google/index.ts +2 -3
- package/src/llm/google/types.js +12 -0
- package/src/llm/google/types.js.map +1 -0
- package/src/llm/google/utils/common.js +670 -0
- package/src/llm/google/utils/common.js.map +1 -0
- package/src/llm/google/utils/tools.js +111 -0
- package/src/llm/google/utils/tools.js.map +1 -0
- package/src/llm/google/utils/zod_to_genai_parameters.js +47 -0
- package/src/llm/google/utils/zod_to_genai_parameters.js.map +1 -0
- package/src/llm/openai/index.js +1033 -0
- package/src/llm/openai/index.js.map +1 -0
- package/src/llm/openai/types.js +2 -0
- package/src/llm/openai/types.js.map +1 -0
- package/src/llm/openai/utils/index.js +756 -0
- package/src/llm/openai/utils/index.js.map +1 -0
- package/src/llm/openai/utils/isReasoningModel.test.js +79 -0
- package/src/llm/openai/utils/isReasoningModel.test.js.map +1 -0
- package/src/llm/openrouter/index.js +261 -0
- package/src/llm/openrouter/index.js.map +1 -0
- package/src/llm/openrouter/index.ts +117 -6
- package/src/llm/openrouter/reasoning.test.js +181 -0
- package/src/llm/openrouter/reasoning.test.js.map +1 -0
- package/src/llm/openrouter/reasoning.test.ts +207 -0
- package/src/llm/providers.js +36 -0
- package/src/llm/providers.js.map +1 -0
- package/src/llm/text.js +65 -0
- package/src/llm/text.js.map +1 -0
- package/src/llm/vertexai/index.js +402 -0
- package/src/llm/vertexai/index.js.map +1 -0
- package/src/llm/vertexai/index.ts +115 -5
- package/src/llm/vertexai/llm.spec.ts +114 -0
- package/src/messages/__tests__/tools.test.js +392 -0
- package/src/messages/__tests__/tools.test.js.map +1 -0
- package/src/messages/cache.js +404 -0
- package/src/messages/cache.js.map +1 -0
- package/src/messages/cache.test.js +1167 -0
- package/src/messages/cache.test.js.map +1 -0
- package/src/messages/cache.test.ts +178 -16
- package/src/messages/cache.ts +152 -147
- package/src/messages/content.js +48 -0
- package/src/messages/content.js.map +1 -0
- package/src/messages/content.test.js +314 -0
- package/src/messages/content.test.js.map +1 -0
- package/src/messages/core.js +359 -0
- package/src/messages/core.js.map +1 -0
- package/src/messages/core.ts +5 -0
- package/src/messages/ensureThinkingBlock.test.js +997 -0
- package/src/messages/ensureThinkingBlock.test.js.map +1 -0
- package/src/messages/ensureThinkingBlock.test.ts +751 -10
- package/src/messages/format.js +973 -0
- package/src/messages/format.js.map +1 -0
- package/src/messages/format.ts +334 -57
- package/src/messages/formatAgentMessages.test.js +2278 -0
- package/src/messages/formatAgentMessages.test.js.map +1 -0
- package/src/messages/formatAgentMessages.test.ts +1175 -1
- package/src/messages/formatAgentMessages.tools.test.js +362 -0
- package/src/messages/formatAgentMessages.tools.test.js.map +1 -0
- package/src/messages/formatMessage.test.js +608 -0
- package/src/messages/formatMessage.test.js.map +1 -0
- package/src/messages/ids.js +18 -0
- package/src/messages/ids.js.map +1 -0
- package/src/messages/index.js +9 -0
- package/src/messages/index.js.map +1 -0
- package/src/messages/index.ts +1 -0
- package/src/messages/labelContentByAgent.test.js +725 -0
- package/src/messages/labelContentByAgent.test.js.map +1 -0
- package/src/messages/prune.js +438 -0
- package/src/messages/prune.js.map +1 -0
- package/src/messages/prune.ts +87 -25
- package/src/messages/reducer.js +60 -0
- package/src/messages/reducer.js.map +1 -0
- package/src/messages/shiftIndexTokenCountMap.test.js +63 -0
- package/src/messages/shiftIndexTokenCountMap.test.js.map +1 -0
- package/src/messages/summarize.js +146 -0
- package/src/messages/summarize.js.map +1 -0
- package/src/messages/summarize.test.js +332 -0
- package/src/messages/summarize.test.js.map +1 -0
- package/src/messages/summarize.test.ts +466 -0
- package/src/messages/summarize.ts +222 -0
- package/src/messages/tools.js +90 -0
- package/src/messages/tools.js.map +1 -0
- package/src/mockStream.js +81 -0
- package/src/mockStream.js.map +1 -0
- package/src/prompts/collab.js +7 -0
- package/src/prompts/collab.js.map +1 -0
- package/src/prompts/index.js +3 -0
- package/src/prompts/index.js.map +1 -0
- package/src/prompts/taskmanager.js +58 -0
- package/src/prompts/taskmanager.js.map +1 -0
- package/src/run.js +427 -0
- package/src/run.js.map +1 -0
- package/src/run.ts +101 -33
- package/src/schemas/index.js +3 -0
- package/src/schemas/index.js.map +1 -0
- package/src/schemas/schema-preparation.test.js +370 -0
- package/src/schemas/schema-preparation.test.js.map +1 -0
- package/src/schemas/validate.js +314 -0
- package/src/schemas/validate.js.map +1 -0
- package/src/schemas/validate.test.js +264 -0
- package/src/schemas/validate.test.js.map +1 -0
- package/src/scripts/abort.js +127 -0
- package/src/scripts/abort.js.map +1 -0
- package/src/scripts/ant_web_search.js +130 -0
- package/src/scripts/ant_web_search.js.map +1 -0
- package/src/scripts/ant_web_search.ts +1 -0
- package/src/scripts/ant_web_search_edge_case.js +133 -0
- package/src/scripts/ant_web_search_edge_case.js.map +1 -0
- package/src/scripts/ant_web_search_edge_case.ts +1 -0
- package/src/scripts/ant_web_search_error_edge_case.js +119 -0
- package/src/scripts/ant_web_search_error_edge_case.js.map +1 -0
- package/src/scripts/ant_web_search_error_edge_case.ts +1 -0
- package/src/scripts/args.js +41 -0
- package/src/scripts/args.js.map +1 -0
- package/src/scripts/bedrock-cache-debug.js +186 -0
- package/src/scripts/bedrock-cache-debug.js.map +1 -0
- package/src/scripts/bedrock-cache-debug.ts +250 -0
- package/src/scripts/bedrock-content-aggregation-test.js +195 -0
- package/src/scripts/bedrock-content-aggregation-test.js.map +1 -0
- package/src/scripts/bedrock-content-aggregation-test.ts +266 -0
- package/src/scripts/bedrock-merge-test.js +80 -0
- package/src/scripts/bedrock-merge-test.js.map +1 -0
- package/src/scripts/bedrock-merge-test.ts +107 -0
- package/src/scripts/bedrock-parallel-tools-test.js +150 -0
- package/src/scripts/bedrock-parallel-tools-test.js.map +1 -0
- package/src/scripts/bedrock-parallel-tools-test.ts +204 -0
- package/src/scripts/caching.js +106 -0
- package/src/scripts/caching.js.map +1 -0
- package/src/scripts/caching.ts +1 -0
- package/src/scripts/cli.js +152 -0
- package/src/scripts/cli.js.map +1 -0
- package/src/scripts/cli2.js +119 -0
- package/src/scripts/cli2.js.map +1 -0
- package/src/scripts/cli3.js +163 -0
- package/src/scripts/cli3.js.map +1 -0
- package/src/scripts/cli4.js +165 -0
- package/src/scripts/cli4.js.map +1 -0
- package/src/scripts/cli5.js +165 -0
- package/src/scripts/cli5.js.map +1 -0
- package/src/scripts/code_exec.js +171 -0
- package/src/scripts/code_exec.js.map +1 -0
- package/src/scripts/code_exec.ts +1 -0
- package/src/scripts/code_exec_files.js +180 -0
- package/src/scripts/code_exec_files.js.map +1 -0
- package/src/scripts/code_exec_files.ts +1 -0
- package/src/scripts/code_exec_multi_session.js +185 -0
- package/src/scripts/code_exec_multi_session.js.map +1 -0
- package/src/scripts/code_exec_multi_session.ts +9 -13
- package/src/scripts/code_exec_ptc.js +265 -0
- package/src/scripts/code_exec_ptc.js.map +1 -0
- package/src/scripts/code_exec_ptc.ts +1 -0
- package/src/scripts/code_exec_session.js +217 -0
- package/src/scripts/code_exec_session.js.map +1 -0
- package/src/scripts/code_exec_session.ts +1 -0
- package/src/scripts/code_exec_simple.js +120 -0
- package/src/scripts/code_exec_simple.js.map +1 -0
- package/src/scripts/code_exec_simple.ts +1 -0
- package/src/scripts/content.js +111 -0
- package/src/scripts/content.js.map +1 -0
- package/src/scripts/content.ts +1 -0
- package/src/scripts/empty_input.js +125 -0
- package/src/scripts/empty_input.js.map +1 -0
- package/src/scripts/handoff-test.js +96 -0
- package/src/scripts/handoff-test.js.map +1 -0
- package/src/scripts/image.js +138 -0
- package/src/scripts/image.js.map +1 -0
- package/src/scripts/image.ts +3 -1
- package/src/scripts/memory.js +83 -0
- package/src/scripts/memory.js.map +1 -0
- package/src/scripts/memory.ts +16 -6
- package/src/scripts/multi-agent-chain.js +271 -0
- package/src/scripts/multi-agent-chain.js.map +1 -0
- package/src/scripts/multi-agent-chain.ts +1 -0
- package/src/scripts/multi-agent-conditional.js +185 -0
- package/src/scripts/multi-agent-conditional.js.map +1 -0
- package/src/scripts/multi-agent-conditional.ts +1 -0
- package/src/scripts/multi-agent-document-review-chain.js +171 -0
- package/src/scripts/multi-agent-document-review-chain.js.map +1 -0
- package/src/scripts/multi-agent-document-review-chain.ts +1 -0
- package/src/scripts/multi-agent-hybrid-flow.js +264 -0
- package/src/scripts/multi-agent-hybrid-flow.js.map +1 -0
- package/src/scripts/multi-agent-hybrid-flow.ts +1 -0
- package/src/scripts/multi-agent-parallel-start.js +214 -0
- package/src/scripts/multi-agent-parallel-start.js.map +1 -0
- package/src/scripts/multi-agent-parallel-start.ts +4 -4
- package/src/scripts/multi-agent-parallel.js +346 -0
- package/src/scripts/multi-agent-parallel.js.map +1 -0
- package/src/scripts/multi-agent-parallel.ts +1 -0
- package/src/scripts/multi-agent-sequence.js +184 -0
- package/src/scripts/multi-agent-sequence.js.map +1 -0
- package/src/scripts/multi-agent-sequence.ts +4 -4
- package/src/scripts/multi-agent-supervisor.js +324 -0
- package/src/scripts/multi-agent-supervisor.js.map +1 -0
- package/src/scripts/multi-agent-supervisor.ts +1 -0
- package/src/scripts/multi-agent-test.js +147 -0
- package/src/scripts/multi-agent-test.js.map +1 -0
- package/src/scripts/multi-agent-test.ts +1 -0
- package/src/scripts/parallel-asymmetric-tools-test.js +202 -0
- package/src/scripts/parallel-asymmetric-tools-test.js.map +1 -0
- package/src/scripts/parallel-asymmetric-tools-test.ts +1 -0
- package/src/scripts/parallel-full-metadata-test.js +176 -0
- package/src/scripts/parallel-full-metadata-test.js.map +1 -0
- package/src/scripts/parallel-full-metadata-test.ts +1 -0
- package/src/scripts/parallel-tools-test.js +256 -0
- package/src/scripts/parallel-tools-test.js.map +1 -0
- package/src/scripts/parallel-tools-test.ts +1 -0
- package/src/scripts/poc-multi-agent-comprehensive.ts +1222 -0
- package/src/scripts/programmatic_exec.js +277 -0
- package/src/scripts/programmatic_exec.js.map +1 -0
- package/src/scripts/programmatic_exec_agent.js +168 -0
- package/src/scripts/programmatic_exec_agent.js.map +1 -0
- package/src/scripts/programmatic_exec_agent.ts +1 -0
- package/src/scripts/search.js +118 -0
- package/src/scripts/search.js.map +1 -0
- package/src/scripts/search.ts +1 -0
- package/src/scripts/sequential-full-metadata-test.js +143 -0
- package/src/scripts/sequential-full-metadata-test.js.map +1 -0
- package/src/scripts/sequential-full-metadata-test.ts +1 -0
- package/src/scripts/simple.js +174 -0
- package/src/scripts/simple.js.map +1 -0
- package/src/scripts/simple.ts +2 -1
- package/src/scripts/single-agent-metadata-test.js +152 -0
- package/src/scripts/single-agent-metadata-test.js.map +1 -0
- package/src/scripts/single-agent-metadata-test.ts +4 -6
- package/src/scripts/stream.js +113 -0
- package/src/scripts/stream.js.map +1 -0
- package/src/scripts/stream.ts +1 -0
- package/src/scripts/test-custom-prompt-key.js +132 -0
- package/src/scripts/test-custom-prompt-key.js.map +1 -0
- package/src/scripts/test-handoff-input.js +143 -0
- package/src/scripts/test-handoff-input.js.map +1 -0
- package/src/scripts/test-handoff-preamble.js +227 -0
- package/src/scripts/test-handoff-preamble.js.map +1 -0
- package/src/scripts/test-handoff-preamble.ts +1 -0
- package/src/scripts/test-handoff-steering.js +353 -0
- package/src/scripts/test-handoff-steering.js.map +1 -0
- package/src/scripts/test-handoff-steering.ts +430 -0
- package/src/scripts/test-multi-agent-list-handoff.js +318 -0
- package/src/scripts/test-multi-agent-list-handoff.js.map +1 -0
- package/src/scripts/test-multi-agent-list-handoff.ts +1 -0
- package/src/scripts/test-parallel-agent-labeling.js +253 -0
- package/src/scripts/test-parallel-agent-labeling.js.map +1 -0
- package/src/scripts/test-parallel-agent-labeling.ts +2 -0
- package/src/scripts/test-parallel-handoffs.js +229 -0
- package/src/scripts/test-parallel-handoffs.js.map +1 -0
- package/src/scripts/test-parallel-handoffs.ts +1 -0
- package/src/scripts/test-thinking-handoff-bedrock.js +132 -0
- package/src/scripts/test-thinking-handoff-bedrock.js.map +1 -0
- package/src/scripts/test-thinking-handoff-bedrock.ts +1 -0
- package/src/scripts/test-thinking-handoff.js +132 -0
- package/src/scripts/test-thinking-handoff.js.map +1 -0
- package/src/scripts/test-thinking-handoff.ts +1 -0
- package/src/scripts/test-thinking-to-thinking-handoff-bedrock.js +140 -0
- package/src/scripts/test-thinking-to-thinking-handoff-bedrock.js.map +1 -0
- package/src/scripts/test-thinking-to-thinking-handoff-bedrock.ts +166 -0
- package/src/scripts/test-tool-before-handoff-role-order.js +223 -0
- package/src/scripts/test-tool-before-handoff-role-order.js.map +1 -0
- package/src/scripts/test-tool-before-handoff-role-order.ts +276 -0
- package/src/scripts/test-tools-before-handoff.js +187 -0
- package/src/scripts/test-tools-before-handoff.js.map +1 -0
- package/src/scripts/test-tools-before-handoff.ts +4 -8
- package/src/scripts/test_code_api.js +263 -0
- package/src/scripts/test_code_api.js.map +1 -0
- package/src/scripts/thinking-bedrock.js +128 -0
- package/src/scripts/thinking-bedrock.js.map +1 -0
- package/src/scripts/thinking-bedrock.ts +1 -0
- package/src/scripts/thinking-vertexai.js +130 -0
- package/src/scripts/thinking-vertexai.js.map +1 -0
- package/src/scripts/thinking-vertexai.ts +168 -0
- package/src/scripts/thinking.js +134 -0
- package/src/scripts/thinking.js.map +1 -0
- package/src/scripts/thinking.ts +1 -0
- package/src/scripts/tool_search.js +114 -0
- package/src/scripts/tool_search.js.map +1 -0
- package/src/scripts/tools.js +125 -0
- package/src/scripts/tools.js.map +1 -0
- package/src/scripts/tools.ts +5 -19
- package/src/specs/agent-handoffs-bedrock.integration.test.js +280 -0
- package/src/specs/agent-handoffs-bedrock.integration.test.js.map +1 -0
- package/src/specs/agent-handoffs-bedrock.integration.test.ts +412 -375
- package/src/specs/agent-handoffs.test.js +924 -0
- package/src/specs/agent-handoffs.test.js.map +1 -0
- package/src/specs/agent-handoffs.test.ts +152 -39
- package/src/specs/anthropic.simple.test.js +287 -0
- package/src/specs/anthropic.simple.test.js.map +1 -0
- package/src/specs/anthropic.simple.test.ts +7 -4
- package/src/specs/azure.simple.test.js +381 -0
- package/src/specs/azure.simple.test.js.map +1 -0
- package/src/specs/azure.simple.test.ts +143 -5
- package/src/specs/cache.simple.test.js +282 -0
- package/src/specs/cache.simple.test.js.map +1 -0
- package/src/specs/cache.simple.test.ts +9 -2
- package/src/specs/custom-event-await.test.js +148 -0
- package/src/specs/custom-event-await.test.js.map +1 -0
- package/src/specs/custom-event-await.test.ts +215 -0
- package/src/specs/deepseek.simple.test.js +189 -0
- package/src/specs/deepseek.simple.test.js.map +1 -0
- package/src/specs/deepseek.simple.test.ts +4 -2
- package/src/specs/emergency-prune.test.js +308 -0
- package/src/specs/emergency-prune.test.js.map +1 -0
- package/src/specs/moonshot.simple.test.js +237 -0
- package/src/specs/moonshot.simple.test.js.map +1 -0
- package/src/specs/moonshot.simple.test.ts +6 -2
- package/src/specs/observability.integration.test.js +1337 -0
- package/src/specs/observability.integration.test.js.map +1 -0
- package/src/specs/observability.integration.test.ts +2223 -0
- package/src/specs/openai.simple.test.js +233 -0
- package/src/specs/openai.simple.test.js.map +1 -0
- package/src/specs/openai.simple.test.ts +4 -2
- package/src/specs/openrouter.simple.test.js +202 -0
- package/src/specs/openrouter.simple.test.js.map +1 -0
- package/src/specs/openrouter.simple.test.ts +165 -4
- package/src/specs/prune.test.js +733 -0
- package/src/specs/prune.test.js.map +1 -0
- package/src/specs/prune.test.ts +1 -0
- package/src/specs/reasoning.test.js +144 -0
- package/src/specs/reasoning.test.js.map +1 -0
- package/src/specs/reasoning.test.ts +2 -2
- package/src/specs/spec.utils.js +4 -0
- package/src/specs/spec.utils.js.map +1 -0
- package/src/specs/thinking-handoff.test.js +486 -0
- package/src/specs/thinking-handoff.test.js.map +1 -0
- package/src/specs/thinking-handoff.test.ts +3 -2
- package/src/specs/thinking-prune.test.js +600 -0
- package/src/specs/thinking-prune.test.js.map +1 -0
- package/src/specs/token-distribution-edge-case.test.js +246 -0
- package/src/specs/token-distribution-edge-case.test.js.map +1 -0
- package/src/specs/token-memoization.test.js +32 -0
- package/src/specs/token-memoization.test.js.map +1 -0
- package/src/specs/token-memoization.test.ts +14 -5
- package/src/specs/tokens.test.js +49 -0
- package/src/specs/tokens.test.js.map +1 -0
- package/src/specs/tokens.test.ts +64 -0
- package/src/specs/tool-error.test.js +139 -0
- package/src/specs/tool-error.test.js.map +1 -0
- package/src/specs/tool-error.test.ts +2 -2
- package/src/splitStream.js +204 -0
- package/src/splitStream.js.map +1 -0
- package/src/splitStream.test.js +504 -0
- package/src/splitStream.test.js.map +1 -0
- package/src/stream.js +650 -0
- package/src/stream.js.map +1 -0
- package/src/stream.test.js +225 -0
- package/src/stream.test.js.map +1 -0
- package/src/stream.test.ts +25 -15
- package/src/stream.ts +82 -32
- package/src/test/mockTools.js +340 -0
- package/src/test/mockTools.js.map +1 -0
- package/src/tools/AskUser.ts +159 -0
- package/src/tools/BrowserTools.js +245 -0
- package/src/tools/BrowserTools.js.map +1 -0
- package/src/tools/BrowserTools.ts +12 -8
- package/src/tools/Calculator.js +38 -0
- package/src/tools/Calculator.js.map +1 -0
- package/src/tools/Calculator.test.js +225 -0
- package/src/tools/Calculator.test.js.map +1 -0
- package/src/tools/CodeExecutor.js +233 -0
- package/src/tools/CodeExecutor.js.map +1 -0
- package/src/tools/CodeExecutor.selfhealing.test.ts +435 -0
- package/src/tools/CodeExecutor.ts +62 -4
- package/src/tools/ProgrammaticToolCalling.js +602 -0
- package/src/tools/ProgrammaticToolCalling.js.map +1 -0
- package/src/tools/ProgrammaticToolCalling.ts +40 -52
- package/src/tools/StreamingToolCallBuffer.js +179 -0
- package/src/tools/StreamingToolCallBuffer.js.map +1 -0
- package/src/tools/StreamingToolCallBuffer.ts +218 -0
- package/src/tools/ToolNode.js +930 -0
- package/src/tools/ToolNode.js.map +1 -0
- package/src/tools/ToolNode.ts +454 -41
- package/src/tools/ToolSearch.js +904 -0
- package/src/tools/ToolSearch.js.map +1 -0
- package/src/tools/ToolSearch.ts +84 -33
- package/src/tools/__tests__/AskUser.test.ts +537 -0
- package/src/tools/__tests__/BrowserTools.test.js +306 -0
- package/src/tools/__tests__/BrowserTools.test.js.map +1 -0
- package/src/tools/__tests__/BrowserTools.test.ts +131 -6
- package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.js +276 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.js.map +1 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.test.js +807 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.test.js.map +1 -0
- package/src/tools/__tests__/StreamingToolCallBuffer.test.js +175 -0
- package/src/tools/__tests__/StreamingToolCallBuffer.test.js.map +1 -0
- package/src/tools/__tests__/StreamingToolCallBuffer.test.ts +263 -0
- package/src/tools/__tests__/ToolApproval.test.js +675 -0
- package/src/tools/__tests__/ToolApproval.test.js.map +1 -0
- package/src/tools/__tests__/ToolApproval.test.ts +194 -20
- package/src/tools/__tests__/ToolNode.hitl.test.ts +267 -0
- package/src/tools/__tests__/ToolNode.recovery.test.js +200 -0
- package/src/tools/__tests__/ToolNode.recovery.test.js.map +1 -0
- package/src/tools/__tests__/ToolNode.recovery.test.ts +276 -0
- package/src/tools/__tests__/ToolNode.session.test.js +319 -0
- package/src/tools/__tests__/ToolNode.session.test.js.map +1 -0
- package/src/tools/__tests__/ToolNode.session.test.ts +465 -0
- package/src/tools/__tests__/ToolSearch.integration.test.js +125 -0
- package/src/tools/__tests__/ToolSearch.integration.test.js.map +1 -0
- package/src/tools/__tests__/ToolSearch.test.js +812 -0
- package/src/tools/__tests__/ToolSearch.test.js.map +1 -0
- package/src/tools/__tests__/ToolSearch.test.ts +78 -5
- package/src/tools/__tests__/handlers.test.js +799 -0
- package/src/tools/__tests__/handlers.test.js.map +1 -0
- package/src/tools/__tests__/handlers.test.ts +1100 -0
- package/src/tools/__tests__/truncation-recovery.integration.test.js +362 -0
- package/src/tools/__tests__/truncation-recovery.integration.test.js.map +1 -0
- package/src/tools/__tests__/truncation-recovery.integration.test.ts +560 -0
- package/src/tools/handlers.js +306 -0
- package/src/tools/handlers.js.map +1 -0
- package/src/tools/handlers.ts +119 -16
- package/src/tools/schema.js +25 -0
- package/src/tools/schema.js.map +1 -0
- package/src/tools/search/anthropic.js +34 -0
- package/src/tools/search/anthropic.js.map +1 -0
- package/src/tools/search/content.js +116 -0
- package/src/tools/search/content.js.map +1 -0
- package/src/tools/search/content.test.js +133 -0
- package/src/tools/search/content.test.js.map +1 -0
- package/src/tools/search/firecrawl.js +173 -0
- package/src/tools/search/firecrawl.js.map +1 -0
- package/src/tools/search/format.js +198 -0
- package/src/tools/search/format.js.map +1 -0
- package/src/tools/search/highlights.js +241 -0
- package/src/tools/search/highlights.js.map +1 -0
- package/src/tools/search/index.js +3 -0
- package/src/tools/search/index.js.map +1 -0
- package/src/tools/search/jina-reranker.test.js +106 -0
- package/src/tools/search/jina-reranker.test.js.map +1 -0
- package/src/tools/search/rerankers.js +165 -0
- package/src/tools/search/rerankers.js.map +1 -0
- package/src/tools/search/schema.js +102 -0
- package/src/tools/search/schema.js.map +1 -0
- package/src/tools/search/search.js +561 -0
- package/src/tools/search/search.js.map +1 -0
- package/src/tools/search/serper-scraper.js +126 -0
- package/src/tools/search/serper-scraper.js.map +1 -0
- package/src/tools/search/test.js +129 -0
- package/src/tools/search/test.js.map +1 -0
- package/src/tools/search/tool.js +453 -0
- package/src/tools/search/tool.js.map +1 -0
- package/src/tools/search/types.js +2 -0
- package/src/tools/search/types.js.map +1 -0
- package/src/tools/search/utils.js +59 -0
- package/src/tools/search/utils.js.map +1 -0
- package/src/types/graph.js +24 -0
- package/src/types/graph.js.map +1 -0
- package/src/types/graph.test.js +192 -0
- package/src/types/graph.test.js.map +1 -0
- package/src/types/graph.ts +26 -6
- package/src/types/index.js +7 -0
- package/src/types/index.js.map +1 -0
- package/src/types/llm.js +2 -0
- package/src/types/llm.js.map +1 -0
- package/src/types/llm.ts +8 -3
- package/src/types/messages.js +2 -0
- package/src/types/messages.js.map +1 -0
- package/src/types/run.js +2 -0
- package/src/types/run.js.map +1 -0
- package/src/types/run.ts +2 -0
- package/src/types/stream.js +2 -0
- package/src/types/stream.js.map +1 -0
- package/src/types/tools.js +2 -0
- package/src/types/tools.js.map +1 -0
- package/src/types/tools.ts +21 -2
- package/src/utils/contextAnalytics.js +79 -0
- package/src/utils/contextAnalytics.js.map +1 -0
- package/src/utils/contextAnalytics.test.js +166 -0
- package/src/utils/contextAnalytics.test.js.map +1 -0
- package/src/utils/contextAnalytics.test.ts +222 -0
- package/src/utils/contextAnalytics.ts +27 -9
- package/src/utils/events.js +26 -0
- package/src/utils/events.js.map +1 -0
- package/src/utils/graph.js +11 -0
- package/src/utils/graph.js.map +1 -0
- package/src/utils/handlers.js +65 -0
- package/src/utils/handlers.js.map +1 -0
- package/src/utils/index.js +10 -0
- package/src/utils/index.js.map +1 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/llm.js +21 -0
- package/src/utils/llm.js.map +1 -0
- package/src/utils/llmConfig.js +205 -0
- package/src/utils/llmConfig.js.map +1 -0
- package/src/utils/llmConfig.ts +5 -5
- package/src/utils/logging.js +37 -0
- package/src/utils/logging.js.map +1 -0
- package/src/utils/misc.js +51 -0
- package/src/utils/misc.js.map +1 -0
- package/src/utils/run.js +69 -0
- package/src/utils/run.js.map +1 -0
- package/src/utils/run.ts +108 -106
- package/src/utils/schema.js +21 -0
- package/src/utils/schema.js.map +1 -0
- package/src/utils/title.js +119 -0
- package/src/utils/title.js.map +1 -0
- package/src/utils/tokens.js +92 -0
- package/src/utils/tokens.js.map +1 -0
- package/src/utils/tokens.ts +118 -142
- package/src/utils/toolCallContinuation.ts +55 -0
- package/src/utils/toonFormat.js +379 -0
- package/src/utils/toonFormat.js.map +1 -0
|
@@ -0,0 +1,799 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, jest } from '@jest/globals';
|
|
2
|
+
import { StepTypes, ToolCallTypes, Providers, GraphEvents } from '@/common';
|
|
3
|
+
import { handleToolCallChunks, handleToolCalls, handleServerToolResult, } from '../handlers';
|
|
4
|
+
function createMockGraph(overrides) {
|
|
5
|
+
let stepCounter = 0;
|
|
6
|
+
return {
|
|
7
|
+
getStepKey: jest.fn().mockReturnValue('step-key'),
|
|
8
|
+
getStepIdByKey: jest.fn().mockReturnValue('prev-step-id'),
|
|
9
|
+
getRunStep: jest
|
|
10
|
+
.fn()
|
|
11
|
+
.mockReturnValue(undefined),
|
|
12
|
+
dispatchRunStep: jest
|
|
13
|
+
.fn()
|
|
14
|
+
.mockImplementation(async () => `new-step-${++stepCounter}`),
|
|
15
|
+
dispatchRunStepDelta: jest
|
|
16
|
+
.fn()
|
|
17
|
+
.mockResolvedValue(undefined),
|
|
18
|
+
toolCallStepIds: new Map(),
|
|
19
|
+
messageStepHasToolCalls: new Map(),
|
|
20
|
+
messageIdsByStepKey: new Map(),
|
|
21
|
+
prelimMessageIdsByStepKey: new Map(),
|
|
22
|
+
invokedToolIds: undefined,
|
|
23
|
+
handlerRegistry: undefined,
|
|
24
|
+
streamingToolCallBuffer: {
|
|
25
|
+
append: jest.fn(),
|
|
26
|
+
setToolName: jest.fn(),
|
|
27
|
+
getToolName: jest.fn(),
|
|
28
|
+
getRawArgs: jest.fn(),
|
|
29
|
+
extractFieldValue: jest.fn(),
|
|
30
|
+
has: jest.fn().mockReturnValue(false),
|
|
31
|
+
clear: jest.fn(),
|
|
32
|
+
clearAll: jest.fn(),
|
|
33
|
+
setIndexMapping: jest.fn(),
|
|
34
|
+
getIdByIndex: jest.fn().mockReturnValue(undefined),
|
|
35
|
+
},
|
|
36
|
+
...overrides,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function makeRunStep(type, opts) {
|
|
40
|
+
const stepDetails = type === StepTypes.MESSAGE_CREATION
|
|
41
|
+
? {
|
|
42
|
+
type: StepTypes.MESSAGE_CREATION,
|
|
43
|
+
message_creation: { message_id: 'msg-1' },
|
|
44
|
+
}
|
|
45
|
+
: { type: StepTypes.TOOL_CALLS, tool_calls: opts?.tool_calls ?? [] };
|
|
46
|
+
return {
|
|
47
|
+
type,
|
|
48
|
+
id: opts?.id ?? 'run-step-1',
|
|
49
|
+
index: opts?.index ?? 0,
|
|
50
|
+
stepDetails,
|
|
51
|
+
usage: null,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function makeToolCall(id, name = 'calculator') {
|
|
55
|
+
return { id, name, args: {}, type: 'tool_call' };
|
|
56
|
+
}
|
|
57
|
+
function makeToolCallChunk(opts) {
|
|
58
|
+
return {
|
|
59
|
+
id: opts?.id,
|
|
60
|
+
name: opts?.name,
|
|
61
|
+
args: '',
|
|
62
|
+
index: opts?.index ?? 0,
|
|
63
|
+
type: 'tool_call_chunk',
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const defaultMetadata = { run_id: 'test-run' };
|
|
67
|
+
describe('handleToolCallChunks', () => {
|
|
68
|
+
let graph;
|
|
69
|
+
beforeEach(() => {
|
|
70
|
+
graph = createMockGraph();
|
|
71
|
+
});
|
|
72
|
+
it('creates TOOL_CALLS step when previous step is MESSAGE_CREATION', async () => {
|
|
73
|
+
const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
|
|
74
|
+
graph.getRunStep.mockReturnValue(msgStep);
|
|
75
|
+
const chunks = [makeToolCallChunk({ index: 2 })];
|
|
76
|
+
await handleToolCallChunks({
|
|
77
|
+
graph: graph,
|
|
78
|
+
stepKey: 'step-key',
|
|
79
|
+
toolCallChunks: chunks,
|
|
80
|
+
metadata: defaultMetadata,
|
|
81
|
+
});
|
|
82
|
+
const dispatchCalls = graph.dispatchRunStep.mock.calls;
|
|
83
|
+
expect(dispatchCalls).toHaveLength(1);
|
|
84
|
+
expect(dispatchCalls[0][1]).toEqual(expect.objectContaining({ type: StepTypes.TOOL_CALLS }));
|
|
85
|
+
expect(graph.messageStepHasToolCalls.has('prev-step-id')).toBe(true);
|
|
86
|
+
expect(graph.dispatchRunStepDelta).toHaveBeenCalledTimes(1);
|
|
87
|
+
});
|
|
88
|
+
it('reuses existing TOOL_CALLS step without dispatching a new one', async () => {
|
|
89
|
+
const toolStep = makeRunStep(StepTypes.TOOL_CALLS);
|
|
90
|
+
graph.getRunStep.mockReturnValue(toolStep);
|
|
91
|
+
const chunks = [makeToolCallChunk({ index: 2 })];
|
|
92
|
+
await handleToolCallChunks({
|
|
93
|
+
graph: graph,
|
|
94
|
+
stepKey: 'step-key',
|
|
95
|
+
toolCallChunks: chunks,
|
|
96
|
+
metadata: defaultMetadata,
|
|
97
|
+
});
|
|
98
|
+
expect(graph.dispatchRunStep).not.toHaveBeenCalled();
|
|
99
|
+
expect(graph.dispatchRunStepDelta).toHaveBeenCalledTimes(1);
|
|
100
|
+
expect(graph.dispatchRunStepDelta).toHaveBeenCalledWith('prev-step-id', expect.objectContaining({ type: StepTypes.TOOL_CALLS }));
|
|
101
|
+
});
|
|
102
|
+
it('creates MESSAGE_CREATION when no previous step exists', async () => {
|
|
103
|
+
let callCount = 0;
|
|
104
|
+
graph.getStepIdByKey.mockImplementation(() => {
|
|
105
|
+
callCount++;
|
|
106
|
+
if (callCount === 1) {
|
|
107
|
+
throw new Error('No step found');
|
|
108
|
+
}
|
|
109
|
+
return 'new-step-1';
|
|
110
|
+
});
|
|
111
|
+
graph.getRunStep.mockReturnValue(makeRunStep(StepTypes.MESSAGE_CREATION));
|
|
112
|
+
const chunks = [makeToolCallChunk({ index: 0 })];
|
|
113
|
+
await handleToolCallChunks({
|
|
114
|
+
graph: graph,
|
|
115
|
+
stepKey: 'step-key',
|
|
116
|
+
toolCallChunks: chunks,
|
|
117
|
+
metadata: defaultMetadata,
|
|
118
|
+
});
|
|
119
|
+
const dispatchCalls = graph.dispatchRunStep.mock.calls;
|
|
120
|
+
expect(dispatchCalls.length).toBeGreaterThanOrEqual(2);
|
|
121
|
+
expect(dispatchCalls[0][1]).toEqual(expect.objectContaining({ type: StepTypes.MESSAGE_CREATION }));
|
|
122
|
+
expect(dispatchCalls[1][1]).toEqual(expect.objectContaining({ type: StepTypes.TOOL_CALLS }));
|
|
123
|
+
});
|
|
124
|
+
it('skips TOOL_CALLS dispatch when already dispatched for this MESSAGE_CREATION', async () => {
|
|
125
|
+
const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
|
|
126
|
+
graph.getRunStep.mockReturnValue(msgStep);
|
|
127
|
+
graph.messageStepHasToolCalls.set('prev-step-id', true);
|
|
128
|
+
const chunks = [makeToolCallChunk({ index: 2 })];
|
|
129
|
+
await handleToolCallChunks({
|
|
130
|
+
graph: graph,
|
|
131
|
+
stepKey: 'step-key',
|
|
132
|
+
toolCallChunks: chunks,
|
|
133
|
+
metadata: defaultMetadata,
|
|
134
|
+
});
|
|
135
|
+
expect(graph.dispatchRunStep).not.toHaveBeenCalled();
|
|
136
|
+
expect(graph.dispatchRunStepDelta).toHaveBeenCalledTimes(1);
|
|
137
|
+
});
|
|
138
|
+
it('sanitizes empty string id and name to undefined', async () => {
|
|
139
|
+
const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
|
|
140
|
+
graph.getRunStep.mockReturnValue(msgStep);
|
|
141
|
+
const chunk = makeToolCallChunk({ id: '', name: '' });
|
|
142
|
+
await handleToolCallChunks({
|
|
143
|
+
graph: graph,
|
|
144
|
+
stepKey: 'step-key',
|
|
145
|
+
toolCallChunks: [chunk],
|
|
146
|
+
metadata: defaultMetadata,
|
|
147
|
+
});
|
|
148
|
+
expect(chunk.id).toBeUndefined();
|
|
149
|
+
expect(chunk.name).toBeUndefined();
|
|
150
|
+
});
|
|
151
|
+
it('populates tool_calls when chunk has valid id and name', async () => {
|
|
152
|
+
const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
|
|
153
|
+
graph.getRunStep.mockReturnValue(msgStep);
|
|
154
|
+
const chunks = [
|
|
155
|
+
makeToolCallChunk({ id: 'tooluse_abc', name: 'calculator', index: 2 }),
|
|
156
|
+
];
|
|
157
|
+
await handleToolCallChunks({
|
|
158
|
+
graph: graph,
|
|
159
|
+
stepKey: 'step-key',
|
|
160
|
+
toolCallChunks: chunks,
|
|
161
|
+
metadata: defaultMetadata,
|
|
162
|
+
});
|
|
163
|
+
const toolCallsArg = graph.dispatchRunStep.mock
|
|
164
|
+
.calls[0][1];
|
|
165
|
+
expect(toolCallsArg.tool_calls).toEqual([
|
|
166
|
+
expect.objectContaining({
|
|
167
|
+
id: 'tooluse_abc',
|
|
168
|
+
name: 'calculator',
|
|
169
|
+
type: ToolCallTypes.TOOL_CALL,
|
|
170
|
+
}),
|
|
171
|
+
]);
|
|
172
|
+
});
|
|
173
|
+
it('never dispatches empty text block alongside TOOL_CALLS step', async () => {
|
|
174
|
+
const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
|
|
175
|
+
graph.getRunStep.mockReturnValue(msgStep);
|
|
176
|
+
const chunks = [
|
|
177
|
+
makeToolCallChunk({ id: 'tooluse_abc', name: 'calculator', index: 2 }),
|
|
178
|
+
];
|
|
179
|
+
await handleToolCallChunks({
|
|
180
|
+
graph: graph,
|
|
181
|
+
stepKey: 'step-key',
|
|
182
|
+
toolCallChunks: chunks,
|
|
183
|
+
metadata: defaultMetadata,
|
|
184
|
+
});
|
|
185
|
+
const allDispatches = graph.dispatchRunStep.mock.calls;
|
|
186
|
+
expect(allDispatches).toHaveLength(1);
|
|
187
|
+
const stepDetails = allDispatches[0][1];
|
|
188
|
+
expect(stepDetails.type).toBe(StepTypes.TOOL_CALLS);
|
|
189
|
+
expect(stepDetails).not.toHaveProperty('content');
|
|
190
|
+
expect(stepDetails).not.toHaveProperty('text');
|
|
191
|
+
});
|
|
192
|
+
it('feeds buffer with id+args on same chunk (OpenAI/Anthropic pattern)', async () => {
|
|
193
|
+
const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
|
|
194
|
+
graph.getRunStep.mockReturnValue(msgStep);
|
|
195
|
+
const chunk = {
|
|
196
|
+
id: 'tc_1',
|
|
197
|
+
name: 'content_tool',
|
|
198
|
+
args: '{"action":"wri',
|
|
199
|
+
index: 0,
|
|
200
|
+
type: 'tool_call_chunk',
|
|
201
|
+
};
|
|
202
|
+
await handleToolCallChunks({
|
|
203
|
+
graph: graph,
|
|
204
|
+
stepKey: 'step-key',
|
|
205
|
+
toolCallChunks: [chunk],
|
|
206
|
+
metadata: defaultMetadata,
|
|
207
|
+
});
|
|
208
|
+
expect(graph.streamingToolCallBuffer.setIndexMapping).toHaveBeenCalledWith(0, 'tc_1');
|
|
209
|
+
expect(graph.streamingToolCallBuffer.setToolName).toHaveBeenCalledWith('tc_1', 'content_tool');
|
|
210
|
+
expect(graph.streamingToolCallBuffer.append).toHaveBeenCalledWith('tc_1', '{"action":"wri');
|
|
211
|
+
});
|
|
212
|
+
it('feeds buffer via index lookup for Bedrock DELTA chunks (no id)', async () => {
|
|
213
|
+
const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
|
|
214
|
+
graph.getRunStep.mockReturnValue(msgStep);
|
|
215
|
+
// Simulate: index 0 was previously mapped to 'tc_1'
|
|
216
|
+
graph.streamingToolCallBuffer.getIdByIndex.mockReturnValue('tc_1');
|
|
217
|
+
const deltaChunk = {
|
|
218
|
+
id: undefined,
|
|
219
|
+
name: undefined,
|
|
220
|
+
args: 'te","content":"hello',
|
|
221
|
+
index: 0,
|
|
222
|
+
type: 'tool_call_chunk',
|
|
223
|
+
};
|
|
224
|
+
await handleToolCallChunks({
|
|
225
|
+
graph: graph,
|
|
226
|
+
stepKey: 'step-key',
|
|
227
|
+
toolCallChunks: [deltaChunk],
|
|
228
|
+
metadata: defaultMetadata,
|
|
229
|
+
});
|
|
230
|
+
expect(graph.streamingToolCallBuffer.getIdByIndex).toHaveBeenCalledWith(0);
|
|
231
|
+
expect(graph.streamingToolCallBuffer.append).toHaveBeenCalledWith('tc_1', 'te","content":"hello');
|
|
232
|
+
});
|
|
233
|
+
it('does not feed buffer when DELTA chunk has no index mapping', async () => {
|
|
234
|
+
const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
|
|
235
|
+
graph.getRunStep.mockReturnValue(msgStep);
|
|
236
|
+
// No index mapping exists
|
|
237
|
+
graph.streamingToolCallBuffer.getIdByIndex.mockReturnValue(undefined);
|
|
238
|
+
const deltaChunk = {
|
|
239
|
+
id: undefined,
|
|
240
|
+
name: undefined,
|
|
241
|
+
args: 'some args',
|
|
242
|
+
index: 5,
|
|
243
|
+
type: 'tool_call_chunk',
|
|
244
|
+
};
|
|
245
|
+
await handleToolCallChunks({
|
|
246
|
+
graph: graph,
|
|
247
|
+
stepKey: 'step-key',
|
|
248
|
+
toolCallChunks: [deltaChunk],
|
|
249
|
+
metadata: defaultMetadata,
|
|
250
|
+
});
|
|
251
|
+
expect(graph.streamingToolCallBuffer.append).not.toHaveBeenCalled();
|
|
252
|
+
});
|
|
253
|
+
it('dispatches delta even when chunks lack id/name (Bedrock pattern)', async () => {
|
|
254
|
+
const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
|
|
255
|
+
graph.getRunStep.mockReturnValue(msgStep);
|
|
256
|
+
const chunks = [makeToolCallChunk({ index: 2 })];
|
|
257
|
+
await handleToolCallChunks({
|
|
258
|
+
graph: graph,
|
|
259
|
+
stepKey: 'step-key',
|
|
260
|
+
toolCallChunks: chunks,
|
|
261
|
+
metadata: defaultMetadata,
|
|
262
|
+
});
|
|
263
|
+
expect(graph.dispatchRunStepDelta).toHaveBeenCalledTimes(1);
|
|
264
|
+
const toolCallsArg = graph.dispatchRunStep.mock
|
|
265
|
+
.calls[0][1];
|
|
266
|
+
expect(toolCallsArg.tool_calls).toEqual([]);
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
describe('handleToolCalls', () => {
|
|
270
|
+
let graph;
|
|
271
|
+
beforeEach(() => {
|
|
272
|
+
graph = createMockGraph();
|
|
273
|
+
});
|
|
274
|
+
it('returns early when metadata is missing', async () => {
|
|
275
|
+
await handleToolCalls([makeToolCall('id-1')], undefined, graph);
|
|
276
|
+
expect(graph.dispatchRunStep).not.toHaveBeenCalled();
|
|
277
|
+
});
|
|
278
|
+
it('returns early when toolCalls is undefined', async () => {
|
|
279
|
+
await handleToolCalls(undefined, defaultMetadata, graph);
|
|
280
|
+
expect(graph.dispatchRunStep).not.toHaveBeenCalled();
|
|
281
|
+
});
|
|
282
|
+
it('returns early when toolCalls is empty', async () => {
|
|
283
|
+
await handleToolCalls([], defaultMetadata, graph);
|
|
284
|
+
expect(graph.dispatchRunStep).not.toHaveBeenCalled();
|
|
285
|
+
});
|
|
286
|
+
it('skips tool call when id already in toolCallStepIds', async () => {
|
|
287
|
+
graph.toolCallStepIds.set('id-1', 'existing-step');
|
|
288
|
+
const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
|
|
289
|
+
graph.getRunStep.mockReturnValue(msgStep);
|
|
290
|
+
await handleToolCalls([makeToolCall('id-1')], defaultMetadata, graph);
|
|
291
|
+
expect(graph.dispatchRunStep).not.toHaveBeenCalled();
|
|
292
|
+
});
|
|
293
|
+
it('assigns fallback id when tool_call.id is undefined', async () => {
|
|
294
|
+
const tc = {
|
|
295
|
+
id: undefined,
|
|
296
|
+
name: 'calc',
|
|
297
|
+
args: {},
|
|
298
|
+
type: 'tool_call',
|
|
299
|
+
};
|
|
300
|
+
graph.getStepIdByKey.mockImplementation(() => {
|
|
301
|
+
throw new Error('no step');
|
|
302
|
+
});
|
|
303
|
+
await handleToolCalls([tc], defaultMetadata, graph);
|
|
304
|
+
expect(tc.id).toBeDefined();
|
|
305
|
+
expect(tc.id.startsWith('toolu_')).toBe(true);
|
|
306
|
+
expect(graph.dispatchRunStep).toHaveBeenCalled();
|
|
307
|
+
});
|
|
308
|
+
it('flags messageStepHasToolCalls and dispatches TOOL_CALLS when prev step is MESSAGE_CREATION', async () => {
|
|
309
|
+
const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
|
|
310
|
+
graph.getRunStep.mockReturnValue(msgStep);
|
|
311
|
+
await handleToolCalls([makeToolCall('id-1')], defaultMetadata, graph);
|
|
312
|
+
expect(graph.messageStepHasToolCalls.get('prev-step-id')).toBe(true);
|
|
313
|
+
const calls = graph.dispatchRunStep.mock.calls;
|
|
314
|
+
expect(calls).toHaveLength(1);
|
|
315
|
+
expect(calls[0][1]).toEqual(expect.objectContaining({ type: StepTypes.TOOL_CALLS }));
|
|
316
|
+
});
|
|
317
|
+
it('creates MESSAGE_CREATION when no previous step exists', async () => {
|
|
318
|
+
graph.getStepIdByKey.mockImplementation(() => {
|
|
319
|
+
throw new Error('no step');
|
|
320
|
+
});
|
|
321
|
+
await handleToolCalls([makeToolCall('id-1')], defaultMetadata, graph);
|
|
322
|
+
const calls = graph.dispatchRunStep.mock.calls;
|
|
323
|
+
expect(calls).toHaveLength(2);
|
|
324
|
+
expect(calls[0][1]).toEqual(expect.objectContaining({ type: StepTypes.MESSAGE_CREATION }));
|
|
325
|
+
expect(calls[1][1]).toEqual(expect.objectContaining({ type: StepTypes.TOOL_CALLS }));
|
|
326
|
+
});
|
|
327
|
+
it('reuses empty TOOL_CALLS step exactly once', async () => {
|
|
328
|
+
const emptyToolStep = makeRunStep(StepTypes.TOOL_CALLS, {
|
|
329
|
+
id: 'empty-step',
|
|
330
|
+
tool_calls: [],
|
|
331
|
+
});
|
|
332
|
+
graph.getRunStep.mockReturnValue(emptyToolStep);
|
|
333
|
+
graph.getStepIdByKey.mockReturnValue('empty-step-id');
|
|
334
|
+
await handleToolCalls([makeToolCall('id-1'), makeToolCall('id-2')], defaultMetadata, graph);
|
|
335
|
+
expect(graph.toolCallStepIds.get('id-1')).toBe('empty-step-id');
|
|
336
|
+
const calls = graph.dispatchRunStep.mock.calls;
|
|
337
|
+
expect(calls).toHaveLength(1);
|
|
338
|
+
expect(calls[0][1]).toEqual(expect.objectContaining({
|
|
339
|
+
type: StepTypes.TOOL_CALLS,
|
|
340
|
+
tool_calls: [expect.objectContaining({ id: 'id-2' })],
|
|
341
|
+
}));
|
|
342
|
+
});
|
|
343
|
+
it('gives each parallel tool call its own step (3 tool calls)', async () => {
|
|
344
|
+
const emptyToolStep = makeRunStep(StepTypes.TOOL_CALLS, { tool_calls: [] });
|
|
345
|
+
graph.getStepIdByKey.mockReturnValue('chunk-step-id');
|
|
346
|
+
let callCount = 0;
|
|
347
|
+
graph.getRunStep.mockImplementation(() => {
|
|
348
|
+
if (callCount === 0) {
|
|
349
|
+
callCount++;
|
|
350
|
+
return emptyToolStep;
|
|
351
|
+
}
|
|
352
|
+
return makeRunStep(StepTypes.TOOL_CALLS, {
|
|
353
|
+
tool_calls: [
|
|
354
|
+
{
|
|
355
|
+
id: 'prev',
|
|
356
|
+
name: 'calc',
|
|
357
|
+
args: {},
|
|
358
|
+
type: 'tool_call',
|
|
359
|
+
},
|
|
360
|
+
],
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
await handleToolCalls([makeToolCall('id-1'), makeToolCall('id-2'), makeToolCall('id-3')], defaultMetadata, graph);
|
|
364
|
+
expect(graph.toolCallStepIds.get('id-1')).toBe('chunk-step-id');
|
|
365
|
+
const calls = graph.dispatchRunStep.mock.calls;
|
|
366
|
+
expect(calls).toHaveLength(2);
|
|
367
|
+
expect(calls[0][1].tool_calls[0].id).toBe('id-2');
|
|
368
|
+
expect(calls[1][1].tool_calls[0].id).toBe('id-3');
|
|
369
|
+
});
|
|
370
|
+
it('never creates MESSAGE_CREATION for parallel tool calls after TOOL_CALLS prev', async () => {
|
|
371
|
+
const emptyToolStep = makeRunStep(StepTypes.TOOL_CALLS, { tool_calls: [] });
|
|
372
|
+
graph.getStepIdByKey.mockReturnValue('chunk-step-id');
|
|
373
|
+
let callCount = 0;
|
|
374
|
+
graph.getRunStep.mockImplementation(() => {
|
|
375
|
+
if (callCount === 0) {
|
|
376
|
+
callCount++;
|
|
377
|
+
return emptyToolStep;
|
|
378
|
+
}
|
|
379
|
+
return makeRunStep(StepTypes.TOOL_CALLS, {
|
|
380
|
+
tool_calls: [
|
|
381
|
+
{
|
|
382
|
+
id: 'prev',
|
|
383
|
+
name: 'calc',
|
|
384
|
+
args: {},
|
|
385
|
+
type: 'tool_call',
|
|
386
|
+
},
|
|
387
|
+
],
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
await handleToolCalls([makeToolCall('id-1'), makeToolCall('id-2'), makeToolCall('id-3')], defaultMetadata, graph);
|
|
391
|
+
const msgCreationCalls = graph.dispatchRunStep.mock.calls.filter((call) => call[1].type === StepTypes.MESSAGE_CREATION);
|
|
392
|
+
expect(msgCreationCalls).toHaveLength(0);
|
|
393
|
+
});
|
|
394
|
+
it('dispatches new TOOL_CALLS directly when prev TOOL_CALLS has existing data', async () => {
|
|
395
|
+
const populatedToolStep = makeRunStep(StepTypes.TOOL_CALLS, {
|
|
396
|
+
tool_calls: [
|
|
397
|
+
{
|
|
398
|
+
id: 'existing',
|
|
399
|
+
name: 'calc',
|
|
400
|
+
args: {},
|
|
401
|
+
type: 'tool_call',
|
|
402
|
+
},
|
|
403
|
+
],
|
|
404
|
+
});
|
|
405
|
+
graph.getRunStep.mockReturnValue(populatedToolStep);
|
|
406
|
+
await handleToolCalls([makeToolCall('id-1')], defaultMetadata, graph);
|
|
407
|
+
const calls = graph.dispatchRunStep.mock.calls;
|
|
408
|
+
expect(calls).toHaveLength(1);
|
|
409
|
+
expect(calls[0][1]).toEqual(expect.objectContaining({ type: StepTypes.TOOL_CALLS }));
|
|
410
|
+
});
|
|
411
|
+
it('never dispatches empty text block with tool_call_ids (MESSAGE_CREATION path)', async () => {
|
|
412
|
+
const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
|
|
413
|
+
graph.getRunStep.mockReturnValue(msgStep);
|
|
414
|
+
await handleToolCalls([makeToolCall('id-1')], defaultMetadata, graph);
|
|
415
|
+
for (const call of graph.dispatchRunStep.mock.calls) {
|
|
416
|
+
const stepDetails = call[1];
|
|
417
|
+
if (stepDetails.type === StepTypes.TOOL_CALLS) {
|
|
418
|
+
expect(stepDetails).not.toHaveProperty('content');
|
|
419
|
+
expect(stepDetails).not.toHaveProperty('text');
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
it('never dispatches empty text block with tool_call_ids (no prev step path)', async () => {
|
|
424
|
+
graph.getStepIdByKey.mockImplementation(() => {
|
|
425
|
+
throw new Error('no step');
|
|
426
|
+
});
|
|
427
|
+
await handleToolCalls([makeToolCall('id-1')], defaultMetadata, graph);
|
|
428
|
+
for (const call of graph.dispatchRunStep.mock.calls) {
|
|
429
|
+
const stepDetails = call[1];
|
|
430
|
+
if (stepDetails.type === StepTypes.TOOL_CALLS) {
|
|
431
|
+
expect(stepDetails).not.toHaveProperty('content');
|
|
432
|
+
expect(stepDetails).not.toHaveProperty('text');
|
|
433
|
+
}
|
|
434
|
+
if (stepDetails.type === StepTypes.MESSAGE_CREATION) {
|
|
435
|
+
const msgDetails = stepDetails;
|
|
436
|
+
expect(msgDetails.message_creation.message_id).toBeDefined();
|
|
437
|
+
expect(msgDetails).not.toHaveProperty('tool_call_ids');
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
describe('handleToolCallChunks + handleToolCalls integration', () => {
|
|
443
|
+
let graph;
|
|
444
|
+
const stepKey = 'step-key';
|
|
445
|
+
beforeEach(() => {
|
|
446
|
+
graph = createMockGraph();
|
|
447
|
+
});
|
|
448
|
+
it('Bedrock single tool: chunks create empty TOOL_CALLS, then handleToolCalls reuses it', async () => {
|
|
449
|
+
const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
|
|
450
|
+
graph.getRunStep.mockReturnValue(msgStep);
|
|
451
|
+
await handleToolCallChunks({
|
|
452
|
+
graph: graph,
|
|
453
|
+
stepKey,
|
|
454
|
+
toolCallChunks: [makeToolCallChunk({ index: 2 })],
|
|
455
|
+
metadata: defaultMetadata,
|
|
456
|
+
});
|
|
457
|
+
const chunkStepId = graph.dispatchRunStep.mock.results[0].value;
|
|
458
|
+
const resolvedChunkStepId = await chunkStepId;
|
|
459
|
+
const emptyToolStep = makeRunStep(StepTypes.TOOL_CALLS, { tool_calls: [] });
|
|
460
|
+
graph.getRunStep.mockReturnValue(emptyToolStep);
|
|
461
|
+
graph.getStepIdByKey.mockReturnValue(resolvedChunkStepId);
|
|
462
|
+
graph.dispatchRunStep.mockClear();
|
|
463
|
+
await handleToolCalls([makeToolCall('tooluse_abc')], defaultMetadata, graph);
|
|
464
|
+
expect(graph.toolCallStepIds.get('tooluse_abc')).toBe(resolvedChunkStepId);
|
|
465
|
+
expect(graph.dispatchRunStep).not.toHaveBeenCalled();
|
|
466
|
+
});
|
|
467
|
+
it('Bedrock parallel: 3 chunks then 3 tool calls yields 3 unique step IDs', async () => {
|
|
468
|
+
const msgStep = makeRunStep(StepTypes.MESSAGE_CREATION);
|
|
469
|
+
graph.getRunStep.mockReturnValue(msgStep);
|
|
470
|
+
await handleToolCallChunks({
|
|
471
|
+
graph: graph,
|
|
472
|
+
stepKey,
|
|
473
|
+
toolCallChunks: [makeToolCallChunk({ index: 2 })],
|
|
474
|
+
metadata: defaultMetadata,
|
|
475
|
+
});
|
|
476
|
+
const chunkStepId = await graph.dispatchRunStep.mock.results[0]
|
|
477
|
+
.value;
|
|
478
|
+
const emptyToolStep = makeRunStep(StepTypes.TOOL_CALLS, { tool_calls: [] });
|
|
479
|
+
graph.getStepIdByKey.mockReturnValue(chunkStepId);
|
|
480
|
+
let callIdx = 0;
|
|
481
|
+
graph.getRunStep.mockImplementation(() => {
|
|
482
|
+
if (callIdx === 0) {
|
|
483
|
+
callIdx++;
|
|
484
|
+
return emptyToolStep;
|
|
485
|
+
}
|
|
486
|
+
return makeRunStep(StepTypes.TOOL_CALLS, {
|
|
487
|
+
tool_calls: [
|
|
488
|
+
{
|
|
489
|
+
id: 'prev',
|
|
490
|
+
name: 'calc',
|
|
491
|
+
args: {},
|
|
492
|
+
type: 'tool_call',
|
|
493
|
+
},
|
|
494
|
+
],
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
graph.dispatchRunStep.mockClear();
|
|
498
|
+
let newStepCounter = 10;
|
|
499
|
+
graph.dispatchRunStep.mockImplementation(async () => `new-step-${++newStepCounter}`);
|
|
500
|
+
await handleToolCalls([makeToolCall('id-1'), makeToolCall('id-2'), makeToolCall('id-3')], defaultMetadata, graph);
|
|
501
|
+
expect(graph.toolCallStepIds.get('id-1')).toBe(chunkStepId);
|
|
502
|
+
const dispatchedIds = graph.dispatchRunStep.mock.calls.map((_, i) => graph.dispatchRunStep.mock.results[i].value);
|
|
503
|
+
expect(dispatchedIds).toHaveLength(2);
|
|
504
|
+
const allStepIds = new Set([
|
|
505
|
+
chunkStepId,
|
|
506
|
+
graph.toolCallStepIds.get('id-1'),
|
|
507
|
+
...graph.dispatchRunStep.mock.calls.map((call) => {
|
|
508
|
+
const tc = call[1].tool_calls;
|
|
509
|
+
return tc?.[0]?.id;
|
|
510
|
+
}),
|
|
511
|
+
]);
|
|
512
|
+
expect(graph.toolCallStepIds.get('id-1')).toBe(chunkStepId);
|
|
513
|
+
expect(allStepIds.size).toBeGreaterThanOrEqual(2);
|
|
514
|
+
const msgCreationCalls = graph.dispatchRunStep.mock.calls.filter((call) => call[1].type === StepTypes.MESSAGE_CREATION);
|
|
515
|
+
expect(msgCreationCalls).toHaveLength(0);
|
|
516
|
+
});
|
|
517
|
+
});
|
|
518
|
+
describe('handleServerToolResult', () => {
|
|
519
|
+
let graph;
|
|
520
|
+
const anthropicContext = { provider: Providers.ANTHROPIC };
|
|
521
|
+
beforeEach(() => {
|
|
522
|
+
graph = createMockGraph();
|
|
523
|
+
});
|
|
524
|
+
it('returns false when provider is not Anthropic', async () => {
|
|
525
|
+
const result = await handleServerToolResult({
|
|
526
|
+
graph: graph,
|
|
527
|
+
content: [{ type: 'tool_result', tool_use_id: 'tu-1', content: 'ok' }],
|
|
528
|
+
agentContext: { provider: Providers.OPENAI },
|
|
529
|
+
});
|
|
530
|
+
expect(result).toBe(false);
|
|
531
|
+
});
|
|
532
|
+
it('returns false when content is a string', async () => {
|
|
533
|
+
const result = await handleServerToolResult({
|
|
534
|
+
graph: graph,
|
|
535
|
+
content: 'plain text',
|
|
536
|
+
agentContext: anthropicContext,
|
|
537
|
+
});
|
|
538
|
+
expect(result).toBe(false);
|
|
539
|
+
});
|
|
540
|
+
it('returns false when content is null/undefined', async () => {
|
|
541
|
+
const result = await handleServerToolResult({
|
|
542
|
+
graph: graph,
|
|
543
|
+
content: undefined,
|
|
544
|
+
agentContext: anthropicContext,
|
|
545
|
+
});
|
|
546
|
+
expect(result).toBe(false);
|
|
547
|
+
});
|
|
548
|
+
it('returns false when content is empty array', async () => {
|
|
549
|
+
const result = await handleServerToolResult({
|
|
550
|
+
graph: graph,
|
|
551
|
+
content: [],
|
|
552
|
+
agentContext: anthropicContext,
|
|
553
|
+
});
|
|
554
|
+
expect(result).toBe(false);
|
|
555
|
+
});
|
|
556
|
+
it('returns false when single content item has no tool_use_id', async () => {
|
|
557
|
+
const result = await handleServerToolResult({
|
|
558
|
+
graph: graph,
|
|
559
|
+
content: [{ type: 'tool_result', content: 'ok' }],
|
|
560
|
+
agentContext: anthropicContext,
|
|
561
|
+
});
|
|
562
|
+
expect(result).toBe(false);
|
|
563
|
+
});
|
|
564
|
+
it('skips content parts with empty tool_use_id', async () => {
|
|
565
|
+
const result = await handleServerToolResult({
|
|
566
|
+
graph: graph,
|
|
567
|
+
content: [
|
|
568
|
+
{ type: 'tool_result', tool_use_id: '', content: 'ok' },
|
|
569
|
+
{ type: 'tool_result', tool_use_id: 'tu-valid', content: 'ok' },
|
|
570
|
+
],
|
|
571
|
+
agentContext: anthropicContext,
|
|
572
|
+
});
|
|
573
|
+
expect(result).toBe(false);
|
|
574
|
+
});
|
|
575
|
+
it('warns and skips when toolCallStepIds has no mapping for tool_use_id', async () => {
|
|
576
|
+
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => { });
|
|
577
|
+
const result = await handleServerToolResult({
|
|
578
|
+
graph: graph,
|
|
579
|
+
content: [
|
|
580
|
+
{ type: 'tool_result', tool_use_id: 'tu-missing', content: 'ok' },
|
|
581
|
+
],
|
|
582
|
+
agentContext: anthropicContext,
|
|
583
|
+
});
|
|
584
|
+
expect(result).toBe(false);
|
|
585
|
+
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('tu-missing'));
|
|
586
|
+
warnSpy.mockRestore();
|
|
587
|
+
});
|
|
588
|
+
it('warns when run step does not exist for stepId', async () => {
|
|
589
|
+
graph.toolCallStepIds.set('tu-1', 'step-1');
|
|
590
|
+
graph.getRunStep.mockReturnValue(undefined);
|
|
591
|
+
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => { });
|
|
592
|
+
const result = await handleServerToolResult({
|
|
593
|
+
graph: graph,
|
|
594
|
+
content: [
|
|
595
|
+
{ type: 'tool_result', tool_use_id: 'tu-1', content: 'ok' },
|
|
596
|
+
],
|
|
597
|
+
agentContext: anthropicContext,
|
|
598
|
+
});
|
|
599
|
+
expect(result).toBe(false);
|
|
600
|
+
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('does not exist'));
|
|
601
|
+
warnSpy.mockRestore();
|
|
602
|
+
});
|
|
603
|
+
it('warns when run step is not a TOOL_CALLS type', async () => {
|
|
604
|
+
graph.toolCallStepIds.set('tu-1', 'step-1');
|
|
605
|
+
graph.getRunStep.mockReturnValue(makeRunStep(StepTypes.MESSAGE_CREATION));
|
|
606
|
+
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => { });
|
|
607
|
+
const result = await handleServerToolResult({
|
|
608
|
+
graph: graph,
|
|
609
|
+
content: [
|
|
610
|
+
{ type: 'tool_result', tool_use_id: 'tu-1', content: 'ok' },
|
|
611
|
+
],
|
|
612
|
+
agentContext: anthropicContext,
|
|
613
|
+
});
|
|
614
|
+
expect(result).toBe(false);
|
|
615
|
+
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('not a tool call step'));
|
|
616
|
+
warnSpy.mockRestore();
|
|
617
|
+
});
|
|
618
|
+
it('skips when no matching tool call found in step details', async () => {
|
|
619
|
+
graph.toolCallStepIds.set('tu-1', 'step-1');
|
|
620
|
+
graph.getRunStep.mockReturnValue(makeRunStep(StepTypes.TOOL_CALLS, {
|
|
621
|
+
tool_calls: [
|
|
622
|
+
{
|
|
623
|
+
id: 'tu-other',
|
|
624
|
+
name: 'calc',
|
|
625
|
+
args: {},
|
|
626
|
+
type: 'tool_call',
|
|
627
|
+
},
|
|
628
|
+
],
|
|
629
|
+
}));
|
|
630
|
+
const result = await handleServerToolResult({
|
|
631
|
+
graph: graph,
|
|
632
|
+
content: [
|
|
633
|
+
{ type: 'tool_result', tool_use_id: 'tu-1', content: 'ok' },
|
|
634
|
+
],
|
|
635
|
+
agentContext: anthropicContext,
|
|
636
|
+
});
|
|
637
|
+
expect(result).toBe(false);
|
|
638
|
+
});
|
|
639
|
+
it('returns true and sets skipHandling when a valid tool result is found', async () => {
|
|
640
|
+
graph.toolCallStepIds.set('tu-1', 'step-1');
|
|
641
|
+
graph.getRunStep.mockReturnValue(makeRunStep(StepTypes.TOOL_CALLS, {
|
|
642
|
+
tool_calls: [
|
|
643
|
+
{
|
|
644
|
+
id: 'tu-1',
|
|
645
|
+
name: 'calc',
|
|
646
|
+
args: {},
|
|
647
|
+
type: 'tool_call',
|
|
648
|
+
},
|
|
649
|
+
],
|
|
650
|
+
}));
|
|
651
|
+
const result = await handleServerToolResult({
|
|
652
|
+
graph: graph,
|
|
653
|
+
content: [
|
|
654
|
+
{ type: 'tool_result', tool_use_id: 'tu-1', content: 'ok' },
|
|
655
|
+
],
|
|
656
|
+
agentContext: anthropicContext,
|
|
657
|
+
});
|
|
658
|
+
expect(result).toBe(true);
|
|
659
|
+
});
|
|
660
|
+
it('calls handleAnthropicSearchResults for web_search_result type', async () => {
|
|
661
|
+
const mockToolEndHandle = jest
|
|
662
|
+
.fn()
|
|
663
|
+
.mockResolvedValue(undefined);
|
|
664
|
+
graph.handlerRegistry = {
|
|
665
|
+
getHandler: jest.fn().mockReturnValue({ handle: mockToolEndHandle }),
|
|
666
|
+
};
|
|
667
|
+
graph.toolCallStepIds.set('tu-1', 'step-1');
|
|
668
|
+
graph.getRunStep.mockReturnValue(makeRunStep(StepTypes.TOOL_CALLS, {
|
|
669
|
+
tool_calls: [
|
|
670
|
+
{
|
|
671
|
+
id: 'tu-1',
|
|
672
|
+
name: 'web_search',
|
|
673
|
+
args: { query: 'test' },
|
|
674
|
+
type: 'tool_call',
|
|
675
|
+
},
|
|
676
|
+
],
|
|
677
|
+
}));
|
|
678
|
+
const webSearchContent = {
|
|
679
|
+
type: 'web_search_result',
|
|
680
|
+
tool_use_id: 'tu-1',
|
|
681
|
+
content: [
|
|
682
|
+
{
|
|
683
|
+
type: 'web_search_result',
|
|
684
|
+
url: 'https://example.com',
|
|
685
|
+
title: 'Example',
|
|
686
|
+
encrypted_index: 'abc',
|
|
687
|
+
page_age: '2024-01-01',
|
|
688
|
+
},
|
|
689
|
+
],
|
|
690
|
+
};
|
|
691
|
+
const result = await handleServerToolResult({
|
|
692
|
+
graph: graph,
|
|
693
|
+
content: [webSearchContent],
|
|
694
|
+
metadata: defaultMetadata,
|
|
695
|
+
agentContext: anthropicContext,
|
|
696
|
+
});
|
|
697
|
+
expect(result).toBe(true);
|
|
698
|
+
expect(mockToolEndHandle).toHaveBeenCalledWith(GraphEvents.TOOL_END, expect.objectContaining({ input: { query: 'test' } }), defaultMetadata, graph);
|
|
699
|
+
expect(graph.invokedToolIds).toBeDefined();
|
|
700
|
+
expect(graph.invokedToolIds.has('tu-1')).toBe(true);
|
|
701
|
+
});
|
|
702
|
+
it('initializes invokedToolIds set when null', async () => {
|
|
703
|
+
const mockToolEndHandle = jest
|
|
704
|
+
.fn()
|
|
705
|
+
.mockResolvedValue(undefined);
|
|
706
|
+
graph.handlerRegistry = {
|
|
707
|
+
getHandler: jest.fn().mockReturnValue({ handle: mockToolEndHandle }),
|
|
708
|
+
};
|
|
709
|
+
graph.invokedToolIds = undefined;
|
|
710
|
+
graph.toolCallStepIds.set('tu-1', 'step-1');
|
|
711
|
+
graph.getRunStep.mockReturnValue(makeRunStep(StepTypes.TOOL_CALLS, {
|
|
712
|
+
tool_calls: [
|
|
713
|
+
{
|
|
714
|
+
id: 'tu-1',
|
|
715
|
+
name: 'web_search',
|
|
716
|
+
args: {},
|
|
717
|
+
type: 'tool_call',
|
|
718
|
+
},
|
|
719
|
+
],
|
|
720
|
+
}));
|
|
721
|
+
const webSearchContent = {
|
|
722
|
+
type: 'web_search_tool_result',
|
|
723
|
+
tool_use_id: 'tu-1',
|
|
724
|
+
content: [
|
|
725
|
+
{
|
|
726
|
+
type: 'web_search_result',
|
|
727
|
+
url: 'https://example.com',
|
|
728
|
+
title: 'Test',
|
|
729
|
+
encrypted_index: 'x',
|
|
730
|
+
},
|
|
731
|
+
],
|
|
732
|
+
};
|
|
733
|
+
await handleServerToolResult({
|
|
734
|
+
graph: graph,
|
|
735
|
+
content: [webSearchContent],
|
|
736
|
+
metadata: defaultMetadata,
|
|
737
|
+
agentContext: anthropicContext,
|
|
738
|
+
});
|
|
739
|
+
expect(graph.invokedToolIds).toBeInstanceOf(Set);
|
|
740
|
+
expect(graph.invokedToolIds.has('tu-1')).toBe(true);
|
|
741
|
+
});
|
|
742
|
+
it('warns when web search content is not an array', async () => {
|
|
743
|
+
graph.toolCallStepIds.set('tu-1', 'step-1');
|
|
744
|
+
graph.getRunStep.mockReturnValue(makeRunStep(StepTypes.TOOL_CALLS, {
|
|
745
|
+
tool_calls: [
|
|
746
|
+
{
|
|
747
|
+
id: 'tu-1',
|
|
748
|
+
name: 'web_search',
|
|
749
|
+
args: {},
|
|
750
|
+
type: 'tool_call',
|
|
751
|
+
},
|
|
752
|
+
],
|
|
753
|
+
}));
|
|
754
|
+
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => { });
|
|
755
|
+
const webSearchContent = {
|
|
756
|
+
type: 'web_search_result',
|
|
757
|
+
tool_use_id: 'tu-1',
|
|
758
|
+
content: 'not an array',
|
|
759
|
+
};
|
|
760
|
+
const result = await handleServerToolResult({
|
|
761
|
+
graph: graph,
|
|
762
|
+
content: [webSearchContent],
|
|
763
|
+
metadata: defaultMetadata,
|
|
764
|
+
agentContext: anthropicContext,
|
|
765
|
+
});
|
|
766
|
+
expect(result).toBe(true);
|
|
767
|
+
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('Expected content to be an array'));
|
|
768
|
+
warnSpy.mockRestore();
|
|
769
|
+
});
|
|
770
|
+
it('warns when content is not an Anthropic web search result', async () => {
|
|
771
|
+
graph.toolCallStepIds.set('tu-1', 'step-1');
|
|
772
|
+
graph.getRunStep.mockReturnValue(makeRunStep(StepTypes.TOOL_CALLS, {
|
|
773
|
+
tool_calls: [
|
|
774
|
+
{
|
|
775
|
+
id: 'tu-1',
|
|
776
|
+
name: 'web_search',
|
|
777
|
+
args: {},
|
|
778
|
+
type: 'tool_call',
|
|
779
|
+
},
|
|
780
|
+
],
|
|
781
|
+
}));
|
|
782
|
+
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => { });
|
|
783
|
+
const webSearchContent = {
|
|
784
|
+
type: 'web_search_result',
|
|
785
|
+
tool_use_id: 'tu-1',
|
|
786
|
+
content: [{ type: 'text', text: 'not a search result' }],
|
|
787
|
+
};
|
|
788
|
+
const result = await handleServerToolResult({
|
|
789
|
+
graph: graph,
|
|
790
|
+
content: [webSearchContent],
|
|
791
|
+
metadata: defaultMetadata,
|
|
792
|
+
agentContext: anthropicContext,
|
|
793
|
+
});
|
|
794
|
+
expect(result).toBe(true);
|
|
795
|
+
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('Expected content to be an Anthropic web search result'));
|
|
796
|
+
warnSpy.mockRestore();
|
|
797
|
+
});
|
|
798
|
+
});
|
|
799
|
+
//# sourceMappingURL=handlers.test.js.map
|