@librechat/agents 3.4.7 → 3.5.0
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 +0 -356
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/agents/projection.cjs +0 -9
- package/dist/cjs/agents/projection.cjs.map +1 -1
- package/dist/cjs/common/constants.cjs +0 -26
- package/dist/cjs/common/constants.cjs.map +1 -1
- package/dist/cjs/common/enum.cjs +0 -85
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/events.cjs +0 -14
- package/dist/cjs/events.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +1 -909
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +7 -272
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/graphs/applyGraphRuntimeConfig.cjs.map +1 -1
- package/dist/cjs/graphs/createGraph.cjs.map +1 -1
- package/dist/cjs/hitl/askUserQuestion.cjs +0 -53
- package/dist/cjs/hitl/askUserQuestion.cjs.map +1 -1
- package/dist/cjs/hitl/askUserQuestions.cjs +0 -20
- package/dist/cjs/hitl/askUserQuestions.cjs.map +1 -1
- package/dist/cjs/hitl/askUserQuestionsInterrupt.cjs +0 -6
- package/dist/cjs/hitl/askUserQuestionsInterrupt.cjs.map +1 -1
- package/dist/cjs/hooks/HookRegistry.cjs +0 -127
- package/dist/cjs/hooks/HookRegistry.cjs.map +1 -1
- package/dist/cjs/hooks/createToolPolicyHook.cjs +0 -38
- package/dist/cjs/hooks/createToolPolicyHook.cjs.map +1 -1
- package/dist/cjs/hooks/createWorkspacePolicyHook.cjs +0 -77
- package/dist/cjs/hooks/createWorkspacePolicyHook.cjs.map +1 -1
- package/dist/cjs/hooks/executeHooks.cjs +0 -79
- package/dist/cjs/hooks/executeHooks.cjs.map +1 -1
- package/dist/cjs/hooks/index.cjs +0 -16
- package/dist/cjs/hooks/index.cjs.map +1 -1
- package/dist/cjs/hooks/matchers.cjs +0 -104
- package/dist/cjs/hooks/matchers.cjs.map +1 -1
- package/dist/cjs/hooks/types.cjs +0 -8
- package/dist/cjs/hooks/types.cjs.map +1 -1
- package/dist/cjs/instrumentation.cjs +0 -14
- package/dist/cjs/instrumentation.cjs.map +1 -1
- package/dist/cjs/langfuse.cjs +0 -75
- package/dist/cjs/langfuse.cjs.map +1 -1
- package/dist/cjs/langfuseConfig.cjs.map +1 -1
- package/dist/cjs/langfuseRuntimeContext.cjs +0 -13
- package/dist/cjs/langfuseRuntimeContext.cjs.map +1 -1
- package/dist/cjs/langfuseRuntimeScope.cjs +0 -4
- package/dist/cjs/langfuseRuntimeScope.cjs.map +1 -1
- package/dist/cjs/langfuseSpanRegistry.cjs +0 -28
- package/dist/cjs/langfuseSpanRegistry.cjs.map +1 -1
- package/dist/cjs/langfuseToolOutputTracing.cjs +0 -3
- package/dist/cjs/langfuseToolOutputTracing.cjs.map +1 -1
- package/dist/cjs/langfuseTraceShaping.cjs +0 -74
- package/dist/cjs/langfuseTraceShaping.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/index.cjs +0 -3
- 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 +1 -111
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +0 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/stream_events.cjs +0 -8
- package/dist/cjs/llm/anthropic/utils/stream_events.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/tools.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/cachePoints.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/index.cjs +1 -95
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/toolCache.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +0 -78
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/utils/message_outputs.cjs +0 -24
- package/dist/cjs/llm/bedrock/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/contextOverflowRecovery.cjs +0 -62
- package/dist/cjs/llm/contextOverflowRecovery.cjs.map +1 -1
- package/dist/cjs/llm/fake.cjs.map +1 -1
- package/dist/cjs/llm/google/index.cjs +2 -21
- package/dist/cjs/llm/google/index.cjs.map +1 -1
- package/dist/cjs/llm/google/utils/common.cjs +0 -35
- package/dist/cjs/llm/google/utils/common.cjs.map +1 -1
- package/dist/cjs/llm/init.cjs +0 -9
- package/dist/cjs/llm/init.cjs.map +1 -1
- package/dist/cjs/llm/invoke.cjs +1 -270
- package/dist/cjs/llm/invoke.cjs.map +1 -1
- package/dist/cjs/llm/mistral/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +0 -99
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/streamMetadata.cjs +0 -21
- package/dist/cjs/llm/openai/streamMetadata.cjs.map +1 -1
- package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
- package/dist/cjs/llm/openrouter/index.cjs +0 -1
- package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
- package/dist/cjs/llm/openrouter/toolCache.cjs +0 -6
- package/dist/cjs/llm/openrouter/toolCache.cjs.map +1 -1
- package/dist/cjs/llm/preempt.cjs +0 -75
- package/dist/cjs/llm/preempt.cjs.map +1 -1
- package/dist/cjs/llm/providers.cjs.map +1 -1
- package/dist/cjs/llm/request.cjs +0 -10
- package/dist/cjs/llm/request.cjs.map +1 -1
- package/dist/cjs/llm/stream/chunkAdapters.cjs +0 -62
- package/dist/cjs/llm/stream/chunkAdapters.cjs.map +1 -1
- package/dist/cjs/llm/stream/smoother.cjs +0 -58
- package/dist/cjs/llm/stream/smoother.cjs.map +1 -1
- package/dist/cjs/llm/streamLimits.cjs +4 -293
- package/dist/cjs/llm/streamLimits.cjs.map +1 -1
- package/dist/cjs/llm/truncation.cjs +0 -36
- package/dist/cjs/llm/truncation.cjs.map +1 -1
- package/dist/cjs/llm/vertexai/index.cjs +0 -330
- package/dist/cjs/llm/vertexai/index.cjs.map +1 -1
- package/dist/cjs/messages/alternation.cjs +0 -43
- package/dist/cjs/messages/alternation.cjs.map +1 -1
- package/dist/cjs/messages/anthropicToolCache.cjs +0 -45
- package/dist/cjs/messages/anthropicToolCache.cjs.map +1 -1
- package/dist/cjs/messages/assistantPhase.cjs +0 -12
- package/dist/cjs/messages/assistantPhase.cjs.map +1 -1
- package/dist/cjs/messages/budget.cjs +0 -9
- package/dist/cjs/messages/budget.cjs.map +1 -1
- package/dist/cjs/messages/cache.cjs +0 -172
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/messages/content.cjs +0 -9
- package/dist/cjs/messages/content.cjs.map +1 -1
- package/dist/cjs/messages/contextPruning.cjs +0 -15
- package/dist/cjs/messages/contextPruning.cjs.map +1 -1
- package/dist/cjs/messages/contextPruningSettings.cjs +0 -3
- package/dist/cjs/messages/contextPruningSettings.cjs.map +1 -1
- package/dist/cjs/messages/core.cjs +0 -48
- package/dist/cjs/messages/core.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +1 -345
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/messages/handoffCue.cjs +0 -36
- package/dist/cjs/messages/handoffCue.cjs.map +1 -1
- package/dist/cjs/messages/ids.cjs.map +1 -1
- package/dist/cjs/messages/injected.cjs +0 -33
- package/dist/cjs/messages/injected.cjs.map +1 -1
- package/dist/cjs/messages/langchain.cjs +0 -14
- package/dist/cjs/messages/langchain.cjs.map +1 -1
- package/dist/cjs/messages/prune.cjs +1 -184
- package/dist/cjs/messages/prune.cjs.map +1 -1
- package/dist/cjs/messages/recency.cjs +0 -32
- package/dist/cjs/messages/recency.cjs.map +1 -1
- package/dist/cjs/messages/reducer.cjs +0 -30
- package/dist/cjs/messages/reducer.cjs.map +1 -1
- package/dist/cjs/messages/tools.cjs +0 -14
- package/dist/cjs/messages/tools.cjs.map +1 -1
- package/dist/cjs/openai/index.cjs.map +1 -1
- package/dist/cjs/prompts/activityLabel.cjs +9 -79
- package/dist/cjs/prompts/activityLabel.cjs.map +1 -1
- package/dist/cjs/responses/index.cjs.map +1 -1
- package/dist/cjs/run.cjs +2 -538
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/session/AgentSession.cjs +1 -17
- package/dist/cjs/session/AgentSession.cjs.map +1 -1
- package/dist/cjs/session/JsonlSessionStore.cjs.map +1 -1
- package/dist/cjs/session/handlers.cjs +0 -7
- package/dist/cjs/session/handlers.cjs.map +1 -1
- package/dist/cjs/session/ids.cjs.map +1 -1
- package/dist/cjs/session/messageSerialization.cjs +0 -4
- package/dist/cjs/session/messageSerialization.cjs.map +1 -1
- package/dist/cjs/stream.cjs +1 -93
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/summarization/index.cjs +0 -27
- package/dist/cjs/summarization/index.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +0 -273
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/tools/BashExecutor.cjs +0 -35
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +0 -24
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/Calculator.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +0 -13
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/CodeSessionFileSummary.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +0 -101
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/ReadFile.cjs.map +1 -1
- package/dist/cjs/tools/SkillTool.cjs +0 -5
- package/dist/cjs/tools/SkillTool.cjs.map +1 -1
- package/dist/cjs/tools/SubagentTool.cjs +0 -10
- package/dist/cjs/tools/SubagentTool.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +6 -1038
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/ToolSearch.cjs +0 -179
- package/dist/cjs/tools/ToolSearch.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareBridgeRuntime.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs +0 -39
- package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareSandboxTools.cjs.map +1 -1
- package/dist/cjs/tools/eagerEventExecution.cjs +0 -6
- package/dist/cjs/tools/eagerEventExecution.cjs.map +1 -1
- package/dist/cjs/tools/handlers.cjs +1 -41
- package/dist/cjs/tools/handlers.cjs.map +1 -1
- package/dist/cjs/tools/intentArg.cjs +1 -132
- package/dist/cjs/tools/intentArg.cjs.map +1 -1
- package/dist/cjs/tools/local/CompileCheckTool.cjs +0 -25
- package/dist/cjs/tools/local/CompileCheckTool.cjs.map +1 -1
- package/dist/cjs/tools/local/FileCheckpointer.cjs +0 -23
- package/dist/cjs/tools/local/FileCheckpointer.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalCodingTools.cjs +0 -80
- package/dist/cjs/tools/local/LocalCodingTools.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs +0 -126
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalExecutionTools.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs +0 -12
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/local/attachments.cjs +0 -44
- package/dist/cjs/tools/local/attachments.cjs.map +1 -1
- package/dist/cjs/tools/local/bashAst.cjs +0 -16
- package/dist/cjs/tools/local/bashAst.cjs.map +1 -1
- package/dist/cjs/tools/local/editStrategies.cjs +0 -14
- package/dist/cjs/tools/local/editStrategies.cjs.map +1 -1
- package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs.map +1 -1
- package/dist/cjs/tools/local/syntaxCheck.cjs +0 -31
- package/dist/cjs/tools/local/syntaxCheck.cjs.map +1 -1
- package/dist/cjs/tools/local/textEncoding.cjs +0 -11
- package/dist/cjs/tools/local/textEncoding.cjs.map +1 -1
- package/dist/cjs/tools/local/workspaceFS.cjs +0 -33
- package/dist/cjs/tools/local/workspaceFS.cjs.map +1 -1
- package/dist/cjs/tools/ptcTimeout.cjs.map +1 -1
- package/dist/cjs/tools/schema.cjs +0 -8
- package/dist/cjs/tools/schema.cjs.map +1 -1
- package/dist/cjs/tools/search/anthropic.cjs +0 -9
- package/dist/cjs/tools/search/anthropic.cjs.map +1 -1
- package/dist/cjs/tools/search/content.cjs.map +1 -1
- package/dist/cjs/tools/search/crw-scraper.cjs +0 -33
- package/dist/cjs/tools/search/crw-scraper.cjs.map +1 -1
- package/dist/cjs/tools/search/crw-search.cjs +0 -2
- package/dist/cjs/tools/search/crw-search.cjs.map +1 -1
- package/dist/cjs/tools/search/firecrawl.cjs +0 -25
- package/dist/cjs/tools/search/firecrawl.cjs.map +1 -1
- package/dist/cjs/tools/search/format.cjs +0 -30
- package/dist/cjs/tools/search/format.cjs.map +1 -1
- package/dist/cjs/tools/search/highlights.cjs +0 -16
- package/dist/cjs/tools/search/highlights.cjs.map +1 -1
- package/dist/cjs/tools/search/keenable-scraper.cjs +0 -8
- package/dist/cjs/tools/search/keenable-scraper.cjs.map +1 -1
- package/dist/cjs/tools/search/keenable-search.cjs +0 -7
- package/dist/cjs/tools/search/keenable-search.cjs.map +1 -1
- package/dist/cjs/tools/search/rerankers.cjs +0 -35
- package/dist/cjs/tools/search/rerankers.cjs.map +1 -1
- package/dist/cjs/tools/search/schema.cjs +0 -1
- package/dist/cjs/tools/search/schema.cjs.map +1 -1
- package/dist/cjs/tools/search/search.cjs +1 -14
- package/dist/cjs/tools/search/search.cjs.map +1 -1
- package/dist/cjs/tools/search/serper-scraper.cjs +0 -46
- package/dist/cjs/tools/search/serper-scraper.cjs.map +1 -1
- package/dist/cjs/tools/search/tavily-scraper.cjs.map +1 -1
- package/dist/cjs/tools/search/tavily-search.cjs.map +1 -1
- package/dist/cjs/tools/search/tool.cjs +0 -25
- package/dist/cjs/tools/search/tool.cjs.map +1 -1
- package/dist/cjs/tools/search/utils.cjs +0 -8
- package/dist/cjs/tools/search/utils.cjs.map +1 -1
- package/dist/cjs/tools/skillCatalog.cjs +0 -6
- package/dist/cjs/tools/skillCatalog.cjs.map +1 -1
- package/dist/cjs/tools/streamedToolCallSeals.cjs +0 -6
- package/dist/cjs/tools/streamedToolCallSeals.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs +0 -2
- package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +3 -213
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentReplay.cjs.map +1 -1
- package/dist/cjs/tools/subagent/childGraphConfig.cjs +0 -4
- package/dist/cjs/tools/subagent/childGraphConfig.cjs.map +1 -1
- package/dist/cjs/tools/subagent/runtimeLimits.cjs.map +1 -1
- package/dist/cjs/tools/toolOutputReferences.cjs +1 -322
- package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -1
- package/dist/cjs/types/hitl.cjs +0 -5
- package/dist/cjs/types/hitl.cjs.map +1 -1
- package/dist/cjs/utils/callbacks.cjs.map +1 -1
- package/dist/cjs/utils/errors.cjs +14 -165
- package/dist/cjs/utils/errors.cjs.map +1 -1
- package/dist/cjs/utils/events.cjs +0 -10
- package/dist/cjs/utils/events.cjs.map +1 -1
- package/dist/cjs/utils/graph.cjs.map +1 -1
- package/dist/cjs/utils/handlers.cjs +0 -3
- package/dist/cjs/utils/handlers.cjs.map +1 -1
- package/dist/cjs/utils/llm.cjs +0 -1
- package/dist/cjs/utils/llm.cjs.map +1 -1
- package/dist/cjs/utils/misc.cjs +0 -16
- package/dist/cjs/utils/misc.cjs.map +1 -1
- package/dist/cjs/utils/proxy.cjs +0 -26
- package/dist/cjs/utils/proxy.cjs.map +1 -1
- package/dist/cjs/utils/run.cjs +0 -6
- package/dist/cjs/utils/run.cjs.map +1 -1
- package/dist/cjs/utils/schema.cjs +0 -5
- package/dist/cjs/utils/schema.cjs.map +1 -1
- package/dist/cjs/utils/title.cjs +0 -6
- package/dist/cjs/utils/title.cjs.map +1 -1
- package/dist/cjs/utils/tokens.cjs +0 -113
- package/dist/cjs/utils/tokens.cjs.map +1 -1
- package/dist/cjs/utils/toolContent.cjs +0 -41
- package/dist/cjs/utils/toolContent.cjs.map +1 -1
- package/dist/cjs/utils/truncation.cjs +0 -61
- package/dist/cjs/utils/truncation.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +0 -356
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/agents/projection.mjs +0 -9
- package/dist/esm/agents/projection.mjs.map +1 -1
- package/dist/esm/common/constants.mjs +0 -26
- package/dist/esm/common/constants.mjs.map +1 -1
- package/dist/esm/common/enum.mjs +0 -85
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/events.mjs +0 -14
- package/dist/esm/events.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +1 -909
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +7 -272
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/graphs/applyGraphRuntimeConfig.mjs.map +1 -1
- package/dist/esm/graphs/createGraph.mjs.map +1 -1
- package/dist/esm/hitl/askUserQuestion.mjs +0 -53
- package/dist/esm/hitl/askUserQuestion.mjs.map +1 -1
- package/dist/esm/hitl/askUserQuestions.mjs +0 -20
- package/dist/esm/hitl/askUserQuestions.mjs.map +1 -1
- package/dist/esm/hitl/askUserQuestionsInterrupt.mjs +0 -6
- package/dist/esm/hitl/askUserQuestionsInterrupt.mjs.map +1 -1
- package/dist/esm/hooks/HookRegistry.mjs +0 -127
- package/dist/esm/hooks/HookRegistry.mjs.map +1 -1
- package/dist/esm/hooks/createToolPolicyHook.mjs +0 -38
- package/dist/esm/hooks/createToolPolicyHook.mjs.map +1 -1
- package/dist/esm/hooks/createWorkspacePolicyHook.mjs +0 -77
- package/dist/esm/hooks/createWorkspacePolicyHook.mjs.map +1 -1
- package/dist/esm/hooks/executeHooks.mjs +0 -79
- package/dist/esm/hooks/executeHooks.mjs.map +1 -1
- package/dist/esm/hooks/index.mjs +0 -16
- package/dist/esm/hooks/index.mjs.map +1 -1
- package/dist/esm/hooks/matchers.mjs +0 -104
- package/dist/esm/hooks/matchers.mjs.map +1 -1
- package/dist/esm/hooks/types.mjs +0 -8
- package/dist/esm/hooks/types.mjs.map +1 -1
- package/dist/esm/instrumentation.mjs +0 -14
- package/dist/esm/instrumentation.mjs.map +1 -1
- package/dist/esm/langfuse.mjs +0 -75
- package/dist/esm/langfuse.mjs.map +1 -1
- package/dist/esm/langfuseConfig.mjs.map +1 -1
- package/dist/esm/langfuseRuntimeContext.mjs +0 -13
- package/dist/esm/langfuseRuntimeContext.mjs.map +1 -1
- package/dist/esm/langfuseRuntimeScope.mjs +0 -4
- package/dist/esm/langfuseRuntimeScope.mjs.map +1 -1
- package/dist/esm/langfuseSpanRegistry.mjs +0 -28
- package/dist/esm/langfuseSpanRegistry.mjs.map +1 -1
- package/dist/esm/langfuseToolOutputTracing.mjs +0 -3
- package/dist/esm/langfuseToolOutputTracing.mjs.map +1 -1
- package/dist/esm/langfuseTraceShaping.mjs +0 -74
- package/dist/esm/langfuseTraceShaping.mjs.map +1 -1
- package/dist/esm/llm/anthropic/index.mjs +0 -3
- 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 +1 -111
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs +0 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/stream_events.mjs +0 -8
- package/dist/esm/llm/anthropic/utils/stream_events.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/tools.mjs.map +1 -1
- package/dist/esm/llm/bedrock/cachePoints.mjs.map +1 -1
- package/dist/esm/llm/bedrock/index.mjs +1 -95
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/llm/bedrock/toolCache.mjs.map +1 -1
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs +0 -78
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/bedrock/utils/message_outputs.mjs +0 -24
- package/dist/esm/llm/bedrock/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/contextOverflowRecovery.mjs +0 -62
- package/dist/esm/llm/contextOverflowRecovery.mjs.map +1 -1
- package/dist/esm/llm/fake.mjs.map +1 -1
- package/dist/esm/llm/google/index.mjs +2 -21
- package/dist/esm/llm/google/index.mjs.map +1 -1
- package/dist/esm/llm/google/utils/common.mjs +0 -35
- package/dist/esm/llm/google/utils/common.mjs.map +1 -1
- package/dist/esm/llm/init.mjs +0 -9
- package/dist/esm/llm/init.mjs.map +1 -1
- package/dist/esm/llm/invoke.mjs +1 -270
- package/dist/esm/llm/invoke.mjs.map +1 -1
- package/dist/esm/llm/mistral/index.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +0 -99
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/streamMetadata.mjs +0 -21
- package/dist/esm/llm/openai/streamMetadata.mjs.map +1 -1
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
- package/dist/esm/llm/openrouter/index.mjs +0 -1
- package/dist/esm/llm/openrouter/index.mjs.map +1 -1
- package/dist/esm/llm/openrouter/toolCache.mjs +0 -6
- package/dist/esm/llm/openrouter/toolCache.mjs.map +1 -1
- package/dist/esm/llm/preempt.mjs +0 -75
- package/dist/esm/llm/preempt.mjs.map +1 -1
- package/dist/esm/llm/providers.mjs.map +1 -1
- package/dist/esm/llm/request.mjs +0 -10
- package/dist/esm/llm/request.mjs.map +1 -1
- package/dist/esm/llm/stream/chunkAdapters.mjs +0 -62
- package/dist/esm/llm/stream/chunkAdapters.mjs.map +1 -1
- package/dist/esm/llm/stream/smoother.mjs +0 -58
- package/dist/esm/llm/stream/smoother.mjs.map +1 -1
- package/dist/esm/llm/streamLimits.mjs +4 -293
- package/dist/esm/llm/streamLimits.mjs.map +1 -1
- package/dist/esm/llm/truncation.mjs +0 -36
- package/dist/esm/llm/truncation.mjs.map +1 -1
- package/dist/esm/llm/vertexai/index.mjs +0 -330
- package/dist/esm/llm/vertexai/index.mjs.map +1 -1
- package/dist/esm/messages/alternation.mjs +0 -43
- package/dist/esm/messages/alternation.mjs.map +1 -1
- package/dist/esm/messages/anthropicToolCache.mjs +0 -45
- package/dist/esm/messages/anthropicToolCache.mjs.map +1 -1
- package/dist/esm/messages/assistantPhase.mjs +0 -12
- package/dist/esm/messages/assistantPhase.mjs.map +1 -1
- package/dist/esm/messages/budget.mjs +0 -9
- package/dist/esm/messages/budget.mjs.map +1 -1
- package/dist/esm/messages/cache.mjs +0 -172
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/content.mjs +0 -9
- package/dist/esm/messages/content.mjs.map +1 -1
- package/dist/esm/messages/contextPruning.mjs +0 -15
- package/dist/esm/messages/contextPruning.mjs.map +1 -1
- package/dist/esm/messages/contextPruningSettings.mjs +0 -3
- package/dist/esm/messages/contextPruningSettings.mjs.map +1 -1
- package/dist/esm/messages/core.mjs +0 -48
- package/dist/esm/messages/core.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +1 -345
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/messages/handoffCue.mjs +0 -36
- package/dist/esm/messages/handoffCue.mjs.map +1 -1
- package/dist/esm/messages/ids.mjs.map +1 -1
- package/dist/esm/messages/injected.mjs +0 -33
- package/dist/esm/messages/injected.mjs.map +1 -1
- package/dist/esm/messages/langchain.mjs +0 -14
- package/dist/esm/messages/langchain.mjs.map +1 -1
- package/dist/esm/messages/prune.mjs +1 -184
- package/dist/esm/messages/prune.mjs.map +1 -1
- package/dist/esm/messages/recency.mjs +0 -32
- package/dist/esm/messages/recency.mjs.map +1 -1
- package/dist/esm/messages/reducer.mjs +0 -30
- package/dist/esm/messages/reducer.mjs.map +1 -1
- package/dist/esm/messages/tools.mjs +0 -14
- package/dist/esm/messages/tools.mjs.map +1 -1
- package/dist/esm/openai/index.mjs.map +1 -1
- package/dist/esm/prompts/activityLabel.mjs +9 -79
- package/dist/esm/prompts/activityLabel.mjs.map +1 -1
- package/dist/esm/responses/index.mjs.map +1 -1
- package/dist/esm/run.mjs +2 -538
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/session/AgentSession.mjs +1 -17
- package/dist/esm/session/AgentSession.mjs.map +1 -1
- package/dist/esm/session/JsonlSessionStore.mjs.map +1 -1
- package/dist/esm/session/handlers.mjs +0 -7
- package/dist/esm/session/handlers.mjs.map +1 -1
- package/dist/esm/session/ids.mjs.map +1 -1
- package/dist/esm/session/messageSerialization.mjs +0 -4
- package/dist/esm/session/messageSerialization.mjs.map +1 -1
- package/dist/esm/stream.mjs +1 -93
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/index.mjs +0 -27
- package/dist/esm/summarization/index.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +0 -273
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +0 -35
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +0 -24
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/Calculator.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +0 -13
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/CodeSessionFileSummary.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +0 -101
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ReadFile.mjs.map +1 -1
- package/dist/esm/tools/SkillTool.mjs +0 -5
- package/dist/esm/tools/SkillTool.mjs.map +1 -1
- package/dist/esm/tools/SubagentTool.mjs +0 -10
- package/dist/esm/tools/SubagentTool.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +6 -1038
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/ToolSearch.mjs +0 -179
- package/dist/esm/tools/ToolSearch.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareBridgeRuntime.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs +0 -39
- package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareSandboxTools.mjs.map +1 -1
- package/dist/esm/tools/eagerEventExecution.mjs +0 -6
- package/dist/esm/tools/eagerEventExecution.mjs.map +1 -1
- package/dist/esm/tools/handlers.mjs +1 -41
- package/dist/esm/tools/handlers.mjs.map +1 -1
- package/dist/esm/tools/intentArg.mjs +1 -132
- package/dist/esm/tools/intentArg.mjs.map +1 -1
- package/dist/esm/tools/local/CompileCheckTool.mjs +0 -25
- package/dist/esm/tools/local/CompileCheckTool.mjs.map +1 -1
- package/dist/esm/tools/local/FileCheckpointer.mjs +0 -23
- package/dist/esm/tools/local/FileCheckpointer.mjs.map +1 -1
- package/dist/esm/tools/local/LocalCodingTools.mjs +0 -80
- package/dist/esm/tools/local/LocalCodingTools.mjs.map +1 -1
- package/dist/esm/tools/local/LocalExecutionEngine.mjs +0 -126
- package/dist/esm/tools/local/LocalExecutionEngine.mjs.map +1 -1
- package/dist/esm/tools/local/LocalExecutionTools.mjs.map +1 -1
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs +0 -12
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/local/attachments.mjs +0 -44
- package/dist/esm/tools/local/attachments.mjs.map +1 -1
- package/dist/esm/tools/local/bashAst.mjs +0 -16
- package/dist/esm/tools/local/bashAst.mjs.map +1 -1
- package/dist/esm/tools/local/editStrategies.mjs +0 -14
- package/dist/esm/tools/local/editStrategies.mjs.map +1 -1
- package/dist/esm/tools/local/resolveLocalExecutionTools.mjs.map +1 -1
- package/dist/esm/tools/local/syntaxCheck.mjs +0 -31
- package/dist/esm/tools/local/syntaxCheck.mjs.map +1 -1
- package/dist/esm/tools/local/textEncoding.mjs +0 -11
- package/dist/esm/tools/local/textEncoding.mjs.map +1 -1
- package/dist/esm/tools/local/workspaceFS.mjs +0 -33
- package/dist/esm/tools/local/workspaceFS.mjs.map +1 -1
- package/dist/esm/tools/ptcTimeout.mjs.map +1 -1
- package/dist/esm/tools/schema.mjs +0 -8
- package/dist/esm/tools/schema.mjs.map +1 -1
- package/dist/esm/tools/search/anthropic.mjs +0 -9
- package/dist/esm/tools/search/anthropic.mjs.map +1 -1
- package/dist/esm/tools/search/content.mjs.map +1 -1
- package/dist/esm/tools/search/crw-scraper.mjs +0 -33
- package/dist/esm/tools/search/crw-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/crw-search.mjs +0 -2
- package/dist/esm/tools/search/crw-search.mjs.map +1 -1
- package/dist/esm/tools/search/firecrawl.mjs +0 -25
- package/dist/esm/tools/search/firecrawl.mjs.map +1 -1
- package/dist/esm/tools/search/format.mjs +0 -30
- package/dist/esm/tools/search/format.mjs.map +1 -1
- package/dist/esm/tools/search/highlights.mjs +0 -16
- package/dist/esm/tools/search/highlights.mjs.map +1 -1
- package/dist/esm/tools/search/keenable-scraper.mjs +0 -8
- package/dist/esm/tools/search/keenable-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/keenable-search.mjs +0 -7
- package/dist/esm/tools/search/keenable-search.mjs.map +1 -1
- package/dist/esm/tools/search/rerankers.mjs +0 -35
- package/dist/esm/tools/search/rerankers.mjs.map +1 -1
- package/dist/esm/tools/search/schema.mjs +0 -1
- package/dist/esm/tools/search/schema.mjs.map +1 -1
- package/dist/esm/tools/search/search.mjs +1 -14
- package/dist/esm/tools/search/search.mjs.map +1 -1
- package/dist/esm/tools/search/serper-scraper.mjs +0 -46
- package/dist/esm/tools/search/serper-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/tavily-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/tavily-search.mjs.map +1 -1
- package/dist/esm/tools/search/tool.mjs +0 -25
- package/dist/esm/tools/search/tool.mjs.map +1 -1
- package/dist/esm/tools/search/utils.mjs +0 -8
- package/dist/esm/tools/search/utils.mjs.map +1 -1
- package/dist/esm/tools/skillCatalog.mjs +0 -6
- package/dist/esm/tools/skillCatalog.mjs.map +1 -1
- package/dist/esm/tools/streamedToolCallSeals.mjs +0 -6
- package/dist/esm/tools/streamedToolCallSeals.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs +0 -2
- package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +3 -213
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentReplay.mjs.map +1 -1
- package/dist/esm/tools/subagent/childGraphConfig.mjs +0 -4
- package/dist/esm/tools/subagent/childGraphConfig.mjs.map +1 -1
- package/dist/esm/tools/subagent/runtimeLimits.mjs.map +1 -1
- package/dist/esm/tools/toolOutputReferences.mjs +1 -322
- package/dist/esm/tools/toolOutputReferences.mjs.map +1 -1
- package/dist/esm/types/hitl.mjs +0 -5
- package/dist/esm/types/hitl.mjs.map +1 -1
- package/dist/esm/utils/callbacks.mjs.map +1 -1
- package/dist/esm/utils/errors.mjs +14 -165
- package/dist/esm/utils/errors.mjs.map +1 -1
- package/dist/esm/utils/events.mjs +0 -10
- package/dist/esm/utils/events.mjs.map +1 -1
- package/dist/esm/utils/graph.mjs.map +1 -1
- package/dist/esm/utils/handlers.mjs +0 -3
- package/dist/esm/utils/handlers.mjs.map +1 -1
- package/dist/esm/utils/llm.mjs +0 -1
- package/dist/esm/utils/llm.mjs.map +1 -1
- package/dist/esm/utils/misc.mjs +0 -16
- package/dist/esm/utils/misc.mjs.map +1 -1
- package/dist/esm/utils/proxy.mjs +0 -26
- package/dist/esm/utils/proxy.mjs.map +1 -1
- package/dist/esm/utils/run.mjs +0 -6
- package/dist/esm/utils/run.mjs.map +1 -1
- package/dist/esm/utils/schema.mjs +0 -5
- package/dist/esm/utils/schema.mjs.map +1 -1
- package/dist/esm/utils/title.mjs +0 -6
- package/dist/esm/utils/title.mjs.map +1 -1
- package/dist/esm/utils/tokens.mjs +0 -113
- package/dist/esm/utils/tokens.mjs.map +1 -1
- package/dist/esm/utils/toolContent.mjs +0 -41
- package/dist/esm/utils/toolContent.mjs.map +1 -1
- package/dist/esm/utils/truncation.mjs +0 -61
- package/dist/esm/utils/truncation.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +3 -3
- package/dist/types/agents/__tests__/promptCacheLiveHelpers.d.ts +3 -3
- package/dist/types/agents/projection.d.ts +1 -1
- package/dist/types/events.d.ts +2 -2
- package/dist/types/graphs/Graph.d.ts +11 -11
- package/dist/types/graphs/MultiAgentGraph.d.ts +2 -2
- package/dist/types/graphs/createGraph.d.ts +4 -4
- package/dist/types/graphs/graphFactory.d.ts +1 -1
- package/dist/types/hitl/askUserQuestion.d.ts +1 -1
- package/dist/types/hitl/askUserQuestions.d.ts +1 -1
- package/dist/types/hitl/askUserQuestionsInterrupt.d.ts +1 -1
- package/dist/types/hooks/types.d.ts +1 -1
- package/dist/types/instrumentation.d.ts +1 -1
- package/dist/types/langfuse.d.ts +3 -3
- package/dist/types/langfuseConfig.d.ts +2 -2
- package/dist/types/langfuseRuntimeContext.d.ts +1 -1
- package/dist/types/langfuseRuntimeScope.d.ts +2 -2
- package/dist/types/langfuseSpanRegistry.d.ts +1 -1
- package/dist/types/langfuseToolOutputTracing.d.ts +3 -3
- package/dist/types/llm/anthropic/index.d.ts +1 -1
- package/dist/types/llm/bedrock/index.d.ts +1 -1
- package/dist/types/llm/bedrock/toolCache.d.ts +2 -2
- package/dist/types/llm/contextOverflowRecovery.d.ts +2 -2
- package/dist/types/llm/google/index.d.ts +1 -1
- package/dist/types/llm/init.d.ts +2 -2
- package/dist/types/llm/invoke.d.ts +6 -6
- package/dist/types/llm/mistral/index.d.ts +1 -1
- package/dist/types/llm/openai/index.d.ts +2 -2
- package/dist/types/llm/openrouter/index.d.ts +2 -2
- package/dist/types/llm/openrouter/toolCache.d.ts +2 -2
- package/dist/types/llm/providers.d.ts +2 -2
- package/dist/types/llm/request.d.ts +2 -2
- package/dist/types/llm/stream/chunkAdapters.d.ts +1 -1
- package/dist/types/llm/streamLimits.d.ts +1 -1
- package/dist/types/llm/truncation.d.ts +1 -1
- package/dist/types/llm/vertexai/index.d.ts +1 -1
- package/dist/types/messages/alternation.d.ts +1 -1
- package/dist/types/messages/anthropicToolCache.d.ts +2 -2
- package/dist/types/messages/assistantPhase.d.ts +3 -3
- package/dist/types/messages/budget.d.ts +1 -1
- package/dist/types/messages/cache.d.ts +1 -1
- package/dist/types/messages/contextPruning.d.ts +2 -2
- package/dist/types/messages/core.d.ts +2 -2
- package/dist/types/messages/format.d.ts +2 -2
- package/dist/types/messages/ids.d.ts +2 -2
- package/dist/types/messages/injected.d.ts +1 -1
- package/dist/types/messages/langchain.d.ts +1 -1
- package/dist/types/messages/prune.d.ts +3 -3
- package/dist/types/openai/index.d.ts +1 -1
- package/dist/types/prompts/activityLabel.d.ts +2 -2
- package/dist/types/responses/index.d.ts +1 -1
- package/dist/types/run.d.ts +3 -3
- package/dist/types/session/handlers.d.ts +1 -1
- package/dist/types/session/types.d.ts +1 -1
- package/dist/types/stream.d.ts +4 -4
- package/dist/types/summarization/index.d.ts +1 -1
- package/dist/types/summarization/node.d.ts +6 -6
- package/dist/types/test/mockTools.d.ts +1 -1
- package/dist/types/tools/BashExecutor.d.ts +2 -2
- package/dist/types/tools/BashProgrammaticToolCalling.d.ts +2 -2
- package/dist/types/tools/CodeExecutor.d.ts +3 -3
- package/dist/types/tools/CodeSessionFileSummary.d.ts +1 -1
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +2 -2
- package/dist/types/tools/ReadFile.d.ts +1 -1
- package/dist/types/tools/SkillTool.d.ts +1 -1
- package/dist/types/tools/SubagentTool.d.ts +3 -3
- package/dist/types/tools/ToolNode.d.ts +5 -5
- package/dist/types/tools/ToolSearch.d.ts +2 -2
- package/dist/types/tools/cloudflare/CloudflareBridgeRuntime.d.ts +1 -1
- package/dist/types/tools/cloudflare/CloudflareProgrammaticToolCalling.d.ts +1 -1
- package/dist/types/tools/cloudflare/CloudflareSandboxExecutionEngine.d.ts +2 -2
- package/dist/types/tools/cloudflare/CloudflareSandboxTools.d.ts +1 -1
- package/dist/types/tools/eagerEventExecution.d.ts +1 -1
- package/dist/types/tools/handlers.d.ts +3 -3
- package/dist/types/tools/intentArg.d.ts +1 -1
- package/dist/types/tools/local/CompileCheckTool.d.ts +2 -2
- package/dist/types/tools/local/FileCheckpointer.d.ts +1 -1
- package/dist/types/tools/local/LocalCodingTools.d.ts +2 -2
- package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -1
- package/dist/types/tools/local/LocalExecutionTools.d.ts +1 -1
- package/dist/types/tools/local/LocalProgrammaticToolCalling.d.ts +1 -1
- package/dist/types/tools/local/bashAst.d.ts +1 -1
- package/dist/types/tools/local/resolveLocalExecutionTools.d.ts +1 -1
- package/dist/types/tools/local/syntaxCheck.d.ts +1 -1
- package/dist/types/tools/ptcTimeout.d.ts +1 -1
- package/dist/types/tools/schema.d.ts +1 -1
- package/dist/types/tools/search/anthropic.d.ts +1 -1
- package/dist/types/tools/skillCatalog.d.ts +1 -1
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +5 -5
- package/dist/types/tools/subagent/SubagentReplay.d.ts +3 -3
- package/dist/types/tools/subagent/childGraphConfig.d.ts +2 -2
- package/dist/types/types/activityLabel.d.ts +3 -3
- package/dist/types/types/graph.d.ts +7 -7
- package/dist/types/types/llm.d.ts +9 -9
- package/dist/types/types/run.d.ts +7 -7
- package/dist/types/types/stream.d.ts +5 -5
- package/dist/types/types/summarize.d.ts +2 -2
- package/dist/types/types/tools.d.ts +5 -5
- package/dist/types/utils/__tests__/fixtures/contextOverflowSignatures.d.ts +1 -1
- package/dist/types/utils/errors.d.ts +1 -1
- package/dist/types/utils/events.d.ts +1 -1
- package/dist/types/utils/handlers.d.ts +3 -3
- package/dist/types/utils/llm.d.ts +1 -1
- package/dist/types/utils/llmConfig.d.ts +1 -1
- package/dist/types/utils/title.d.ts +1 -1
- package/package.json +10 -3
- package/src/__tests__/stream.eagerArgsDivergence.test.ts +0 -911
- package/src/__tests__/stream.eagerEventExecution.test.ts +0 -5046
- package/src/__tests__/stream.streamLimits.test.ts +0 -1982
- package/src/agents/__tests__/AgentContext.anthropic.live.test.ts +0 -448
- package/src/agents/__tests__/AgentContext.bedrock.live.test.ts +0 -655
- package/src/agents/__tests__/AgentContext.openrouter.live.test.ts +0 -128
- package/src/agents/__tests__/AgentContext.overflow.test.ts +0 -205
- package/src/agents/__tests__/AgentContext.test.ts +0 -2425
- package/src/agents/__tests__/projection.test.ts +0 -73
- package/src/agents/__tests__/promptCacheLiveHelpers.ts +0 -175
- package/src/aggregator.test.ts +0 -1214
- package/src/graphs/__tests__/Graph.breakerLifecycle.test.ts +0 -273
- package/src/graphs/__tests__/Graph.closeRunStep.test.ts +0 -385
- package/src/graphs/__tests__/Graph.contextOverflow.test.ts +0 -1766
- package/src/graphs/__tests__/Graph.preemptSignal.test.ts +0 -126
- package/src/graphs/__tests__/Graph.reasoning.test.ts +0 -1717
- package/src/graphs/__tests__/Graph.subagentResumeState.test.ts +0 -80
- package/src/graphs/__tests__/MultiAgentGraph.test.ts +0 -177
- package/src/graphs/__tests__/composition.smoke.test.ts +0 -509
- package/src/graphs/__tests__/createGraph.test.ts +0 -206
- package/src/hooks/__tests__/HookRegistry.test.ts +0 -334
- package/src/hooks/__tests__/compactHooks.test.ts +0 -250
- package/src/hooks/__tests__/createToolPolicyHook.test.ts +0 -268
- package/src/hooks/__tests__/createWorkspacePolicyHook.test.ts +0 -405
- package/src/hooks/__tests__/executeHooks.test.ts +0 -1294
- package/src/hooks/__tests__/integration.test.ts +0 -337
- package/src/hooks/__tests__/matchers.test.ts +0 -238
- package/src/hooks/__tests__/preemptBoundary.test.ts +0 -152
- package/src/hooks/__tests__/toolHooks.test.ts +0 -669
- package/src/llm/__tests__/contextOverflowRecovery.test.ts +0 -401
- package/src/llm/__tests__/fallbackOverflow.test.ts +0 -287
- package/src/llm/anthropic/Jacob_Lee_Resume_2023.pdf +0 -0
- package/src/llm/anthropic/inherited-content-utils.spec.ts +0 -249
- package/src/llm/anthropic/inherited-stream-events.spec.ts +0 -1259
- package/src/llm/anthropic/inherited-strict.spec.ts +0 -302
- package/src/llm/anthropic/llm.spec.ts +0 -3394
- package/src/llm/anthropic/utils/cross-provider-reasoning.test.ts +0 -383
- package/src/llm/anthropic/utils/cross-provider-server-tools.test.ts +0 -110
- package/src/llm/anthropic/utils/server-tool-inputs.test.ts +0 -508
- package/src/llm/anthropic/utils/streaming-tool-input.test.ts +0 -361
- package/src/llm/anthropic/utils/stripPrefillCache.test.ts +0 -111
- package/src/llm/anthropic/utils/tool-id-normalization.test.ts +0 -287
- package/src/llm/bedrock/inherited-cache.spec.ts +0 -144
- package/src/llm/bedrock/inherited.spec.ts +0 -724
- package/src/llm/bedrock/llm.spec.ts +0 -1533
- package/src/llm/bedrock/streamSealDispatch.test.ts +0 -331
- package/src/llm/bedrock/toolCache.test.ts +0 -194
- package/src/llm/bedrock/utils/cross-provider-reasoning.test.ts +0 -131
- package/src/llm/bedrock/utils/cross-provider-server-tools.test.ts +0 -122
- package/src/llm/bedrock/utils/message_inputs.test.ts +0 -650
- package/src/llm/bedrock/utils/message_outputs.test.ts +0 -85
- package/src/llm/bedrock/utils/toolResultCachePoint.test.ts +0 -118
- package/src/llm/custom-chat-models.smoke.test.ts +0 -1966
- package/src/llm/google/data/gettysburg10.wav +0 -0
- package/src/llm/google/data/hotdog.jpg +0 -0
- package/src/llm/google/inherited-stream-events.spec.ts +0 -350
- package/src/llm/google/llm.spec.ts +0 -1388
- package/src/llm/google/streamSmoothing.test.ts +0 -121
- package/src/llm/google/utils/common.test.ts +0 -196
- package/src/llm/invoke.alternation.test.ts +0 -87
- package/src/llm/invoke.handoffCue.test.ts +0 -112
- package/src/llm/invoke.streamLimits.test.ts +0 -142
- package/src/llm/invoke.test.ts +0 -1198
- package/src/llm/mistral/streamSmoothing.test.ts +0 -97
- package/src/llm/openai/cacheWriteTokens.test.ts +0 -112
- package/src/llm/openai/contentBlocks.test.ts +0 -381
- package/src/llm/openai/deepseek.test.ts +0 -747
- package/src/llm/openai/inherited-deepseek.spec.ts +0 -347
- package/src/llm/openai/inherited-xai.spec.ts +0 -416
- package/src/llm/openai/llm.spec.ts +0 -1774
- package/src/llm/openai/managedRequests.test.ts +0 -182
- package/src/llm/openai/sequentialToolCallSeals.test.ts +0 -199
- package/src/llm/openai/streamMetadata.spec.ts +0 -86
- package/src/llm/openai/streamMetadataDedup.spec.ts +0 -166
- package/src/llm/openai/utils/isReasoningModel.test.ts +0 -90
- package/src/llm/openai/utils/messages.test.ts +0 -488
- package/src/llm/openrouter/reasoning.test.ts +0 -561
- package/src/llm/openrouter/toolCache.test.ts +0 -134
- package/src/llm/preempt.test.ts +0 -323
- package/src/llm/stream/chunkAdapters.test.ts +0 -202
- package/src/llm/stream/reassembly.test.ts +0 -241
- package/src/llm/stream/smoother.bench.test.ts +0 -155
- package/src/llm/stream/smoother.test.ts +0 -519
- package/src/llm/streamLimits.test.ts +0 -450
- package/src/llm/truncation.test.ts +0 -242
- package/src/llm/vertexai/fixThoughtSignatures.test.ts +0 -154
- package/src/llm/vertexai/inherited-stream-events.spec.ts +0 -271
- package/src/llm/vertexai/llm.spec.ts +0 -159
- package/src/llm/vertexai/repairUsageMetadata.test.ts +0 -54
- package/src/llm/vertexai/sealStreamedToolCalls.test.ts +0 -88
- package/src/llm/vertexai/streamSealDispatch.test.ts +0 -148
- package/src/llm/vertexai/streamSmoothing.test.ts +0 -109
- package/src/messages/__tests__/anthropicToolCache.test.ts +0 -339
- package/src/messages/__tests__/observationMasking.test.ts +0 -312
- package/src/messages/__tests__/recency.test.ts +0 -267
- package/src/messages/__tests__/tools.test.ts +0 -473
- package/src/messages/alternation.test.ts +0 -212
- package/src/messages/assistantPhase.test.ts +0 -75
- package/src/messages/cache.tail.test.ts +0 -533
- package/src/messages/cache.test.ts +0 -2166
- package/src/messages/content.test.ts +0 -362
- package/src/messages/contextPruning.test.ts +0 -184
- package/src/messages/ensureThinkingBlock.test.ts +0 -1427
- package/src/messages/foldToollessToolBlocks.test.ts +0 -596
- package/src/messages/formatAgentMessages.reducer.test.ts +0 -162
- package/src/messages/formatAgentMessages.skills.test.ts +0 -513
- package/src/messages/formatAgentMessages.steer.test.ts +0 -598
- package/src/messages/formatAgentMessages.test.ts +0 -8111
- package/src/messages/formatAgentMessages.tools.test.ts +0 -522
- package/src/messages/formatMessage.test.ts +0 -693
- package/src/messages/handoffCue.test.ts +0 -96
- package/src/messages/injected.test.ts +0 -107
- package/src/messages/labelContentByAgent.test.ts +0 -962
- package/src/messages/reducer.spec.ts +0 -32
- package/src/messages/shiftIndexTokenCountMap.test.ts +0 -81
- package/src/messages/tailCacheConversion.test.ts +0 -161
- package/src/openai/__tests__/openai.test.ts +0 -337
- package/src/responses/__tests__/responses.test.ts +0 -652
- package/src/scripts/abort.ts +0 -157
- package/src/scripts/activity-labels/captured.json +0 -56
- package/src/scripts/activity-labels/checks.cjs +0 -205
- package/src/scripts/activity-labels/corpus.cjs +0 -473
- package/src/scripts/activity-labels/report.cjs +0 -203
- package/src/scripts/activity-labels/rescore.cjs +0 -102
- package/src/scripts/activity-labels/run.ts +0 -705
- package/src/scripts/activity-labels/variants.ts +0 -71
- package/src/scripts/ant_web_search.ts +0 -159
- package/src/scripts/ant_web_search_edge_case.ts +0 -163
- package/src/scripts/ant_web_search_error_edge_case.ts +0 -149
- package/src/scripts/args.ts +0 -48
- package/src/scripts/bedrock-cache-debug.ts +0 -250
- package/src/scripts/bedrock-content-aggregation-test.ts +0 -266
- package/src/scripts/bedrock-merge-test.ts +0 -107
- package/src/scripts/bedrock-parallel-tools-test.ts +0 -204
- package/src/scripts/bench-prompt-cache.ts +0 -479
- package/src/scripts/caching.ts +0 -132
- package/src/scripts/cli.ts +0 -172
- package/src/scripts/cli2.ts +0 -133
- package/src/scripts/cli3.ts +0 -184
- package/src/scripts/cli4.ts +0 -191
- package/src/scripts/cli5.ts +0 -191
- package/src/scripts/code_exec.ts +0 -214
- package/src/scripts/code_exec_files.ts +0 -237
- package/src/scripts/code_exec_multi_session.ts +0 -237
- package/src/scripts/code_exec_ptc.ts +0 -335
- package/src/scripts/code_exec_session.ts +0 -283
- package/src/scripts/code_exec_simple.ts +0 -148
- package/src/scripts/compare_pi_vs_ours.ts +0 -1259
- package/src/scripts/content.ts +0 -139
- package/src/scripts/context-overflow-probe.ts +0 -997
- package/src/scripts/empty_input.ts +0 -137
- package/src/scripts/handoff-test.ts +0 -134
- package/src/scripts/local_engine.ts +0 -166
- package/src/scripts/local_engine_checkpointer.ts +0 -205
- package/src/scripts/local_engine_compile.ts +0 -263
- package/src/scripts/local_engine_hooks.ts +0 -226
- package/src/scripts/local_engine_image.ts +0 -201
- package/src/scripts/local_engine_ptc.ts +0 -151
- package/src/scripts/local_engine_workspace.ts +0 -258
- package/src/scripts/memory.ts +0 -107
- package/src/scripts/multi-agent-chain.ts +0 -332
- package/src/scripts/multi-agent-conditional.ts +0 -222
- package/src/scripts/multi-agent-document-review-chain.ts +0 -198
- package/src/scripts/multi-agent-hybrid-flow.ts +0 -311
- package/src/scripts/multi-agent-parallel-start.ts +0 -265
- package/src/scripts/multi-agent-parallel.ts +0 -395
- package/src/scripts/multi-agent-sequence.ts +0 -217
- package/src/scripts/multi-agent-subagent.ts +0 -246
- package/src/scripts/multi-agent-supervisor.ts +0 -366
- package/src/scripts/multi-agent-test.ts +0 -187
- package/src/scripts/openrouter_prompt_cache_live.ts +0 -310
- package/src/scripts/parallel-asymmetric-tools-test.ts +0 -275
- package/src/scripts/parallel-full-metadata-test.ts +0 -241
- package/src/scripts/parallel-tools-test.ts +0 -341
- package/src/scripts/preempt-probe.ts +0 -330
- package/src/scripts/preempt-scenarios.ts +0 -388
- package/src/scripts/programmatic_exec.ts +0 -387
- package/src/scripts/programmatic_exec_agent.ts +0 -232
- package/src/scripts/search.ts +0 -147
- package/src/scripts/sequential-full-metadata-test.ts +0 -198
- package/src/scripts/session_live.ts +0 -548
- package/src/scripts/simple.ts +0 -226
- package/src/scripts/single-agent-metadata-test.ts +0 -196
- package/src/scripts/stream.ts +0 -141
- package/src/scripts/subagent-configurable-inheritance.ts +0 -252
- package/src/scripts/subagent-event-driven-debug.ts +0 -190
- package/src/scripts/subagent-tools-debug.ts +0 -160
- package/src/scripts/subagent-usage-sink.ts +0 -176
- package/src/scripts/summarization-recency.ts +0 -462
- package/src/scripts/test-custom-prompt-key.ts +0 -145
- package/src/scripts/test-handoff-input.ts +0 -170
- package/src/scripts/test-handoff-preamble.ts +0 -278
- package/src/scripts/test-handoff-steering.ts +0 -430
- package/src/scripts/test-multi-agent-list-handoff.ts +0 -418
- package/src/scripts/test-parallel-agent-labeling.ts +0 -327
- package/src/scripts/test-parallel-handoffs.ts +0 -292
- package/src/scripts/test-thinking-handoff-bedrock.ts +0 -154
- package/src/scripts/test-thinking-handoff.ts +0 -156
- package/src/scripts/test-thinking-to-thinking-handoff-bedrock.ts +0 -166
- package/src/scripts/test-tool-before-handoff-role-order.ts +0 -276
- package/src/scripts/test-tools-before-handoff.ts +0 -222
- package/src/scripts/test_code_api.ts +0 -354
- package/src/scripts/thinking-bedrock.ts +0 -160
- package/src/scripts/thinking-vertexai.ts +0 -168
- package/src/scripts/thinking.ts +0 -172
- package/src/scripts/tool_search.ts +0 -153
- package/src/scripts/tools.ts +0 -163
- package/src/session/__tests__/JsonlSessionStore.test.ts +0 -1463
- package/src/session/__tests__/handlers.test.ts +0 -161
- package/src/specs/activity-label-observability.live.test.ts +0 -262
- package/src/specs/activity-label-observability.test.ts +0 -167
- package/src/specs/activity-label-prompt.test.ts +0 -359
- package/src/specs/activity-label-trace-seed.test.ts +0 -47
- package/src/specs/activity-phase-label.test.ts +0 -306
- package/src/specs/agent-handoffs.live.test.ts +0 -140
- package/src/specs/agent-handoffs.test.ts +0 -2465
- package/src/specs/anthropic.simple.test.ts +0 -453
- package/src/specs/ask-user-question-batch.test.ts +0 -289
- package/src/specs/ask-user-questions.live.test.ts +0 -185
- package/src/specs/ask-user-questions.test.ts +0 -293
- package/src/specs/azure.simple.test.ts +0 -502
- package/src/specs/bedrock-toolless.live.test.ts +0 -123
- package/src/specs/bedrock-truncation.live.test.ts +0 -191
- package/src/specs/cache.simple.test.ts +0 -416
- package/src/specs/context-accuracy.live.test.ts +0 -409
- package/src/specs/context-overflow-recovery.live.test.ts +0 -213
- package/src/specs/context-usage-event.test.ts +0 -117
- package/src/specs/context-usage.live.test.ts +0 -297
- package/src/specs/custom-event-await.test.ts +0 -304
- package/src/specs/deepseek.simple.test.ts +0 -290
- package/src/specs/deterministic-trace-id.test.ts +0 -43
- package/src/specs/discovered-tools.test.ts +0 -217
- package/src/specs/durability-checkpoint.integration.test.ts +0 -243
- package/src/specs/graph-subagent.live.test.ts +0 -242
- package/src/specs/graph-subagent.test.ts +0 -322
- package/src/specs/handoffCue.test.ts +0 -165
- package/src/specs/langfuse-callbacks.test.ts +0 -1578
- package/src/specs/langfuse-config.test.ts +0 -247
- package/src/specs/langfuse-instrumentation.test.ts +0 -393
- package/src/specs/langfuse-metadata.test.ts +0 -245
- package/src/specs/langfuse-routing.integration.test.ts +0 -844
- package/src/specs/langfuse-runtime-context.test.ts +0 -92
- package/src/specs/langfuse-span-registry.test.ts +0 -87
- package/src/specs/langfuse-tool-output-tracing.test.ts +0 -1858
- package/src/specs/langfuse-trace-shaping.test.ts +0 -591
- package/src/specs/moonshot.simple.test.ts +0 -367
- package/src/specs/multi-agent-summarization.test.ts +0 -396
- package/src/specs/openai.simple.test.ts +0 -315
- package/src/specs/openrouter.simple.test.ts +0 -275
- package/src/specs/preemptSeal.test.ts +0 -678
- package/src/specs/prune.test.ts +0 -3741
- package/src/specs/reasoning.test.ts +0 -201
- package/src/specs/run-step-timestamps.test.ts +0 -414
- package/src/specs/spec.utils.ts +0 -15
- package/src/specs/subagent.test.ts +0 -864
- package/src/specs/summarization-unit.test.ts +0 -973
- package/src/specs/summarization.test.ts +0 -3823
- package/src/specs/summarize-prune.test.ts +0 -376
- package/src/specs/thinking-handoff.test.ts +0 -621
- package/src/specs/thinking-prune.test.ts +0 -827
- package/src/specs/token-accounting-e2e.test.ts +0 -1034
- package/src/specs/token-accounting-pipeline.test.ts +0 -1008
- package/src/specs/token-distribution-edge-case.test.ts +0 -315
- package/src/specs/token-memoization.test.ts +0 -40
- package/src/specs/tokens.test.ts +0 -1000
- package/src/specs/tool-error-resume.test.ts +0 -194
- package/src/specs/tool-error.test.ts +0 -198
- package/src/specs/vllm-reasoning-toolcalls.test.ts +0 -340
- package/src/stream.dispatch.test.ts +0 -63
- package/src/stream.test.ts +0 -144
- package/src/summarization/__tests__/aggregator.test.ts +0 -236
- package/src/summarization/__tests__/node.test.ts +0 -1996
- package/src/summarization/__tests__/trigger.test.ts +0 -149
- package/src/summarization/chunkHandler.test.ts +0 -196
- package/src/test/mockTools.ts +0 -386
- package/src/tools/Calculator.test.ts +0 -278
- package/src/tools/__tests__/BashExecutor.test.ts +0 -108
- package/src/tools/__tests__/CloudflareSandboxExecution.test.ts +0 -939
- package/src/tools/__tests__/CodeApiAuthHeaders.test.ts +0 -858
- package/src/tools/__tests__/CodeExecutor.stateful.test.ts +0 -124
- package/src/tools/__tests__/LocalExecutionRoots.test.ts +0 -8
- package/src/tools/__tests__/LocalExecutionTools.test.ts +0 -2733
- package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.ts +0 -318
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +0 -1557
- package/src/tools/__tests__/ReadFile.test.ts +0 -44
- package/src/tools/__tests__/SkillTool.test.ts +0 -442
- package/src/tools/__tests__/SubagentExecutor.test.ts +0 -3728
- package/src/tools/__tests__/SubagentReplay.test.ts +0 -329
- package/src/tools/__tests__/SubagentTool.test.ts +0 -149
- package/src/tools/__tests__/ToolNode.breakerSignal.test.ts +0 -595
- package/src/tools/__tests__/ToolNode.eagerEventExecution.test.ts +0 -1191
- package/src/tools/__tests__/ToolNode.invalidToolCalls.test.ts +0 -757
- package/src/tools/__tests__/ToolNode.langfuse.test.ts +0 -57
- package/src/tools/__tests__/ToolNode.onResultCompletion.test.ts +0 -736
- package/src/tools/__tests__/ToolNode.outputReferences.test.ts +0 -1710
- package/src/tools/__tests__/ToolNode.runtimeState.test.ts +0 -120
- package/src/tools/__tests__/ToolNode.session.test.ts +0 -1352
- package/src/tools/__tests__/ToolNode.streamLimits.test.ts +0 -69
- package/src/tools/__tests__/ToolSearch.integration.test.ts +0 -161
- package/src/tools/__tests__/ToolSearch.test.ts +0 -1227
- package/src/tools/__tests__/annotateMessagesForLLM.test.ts +0 -561
- package/src/tools/__tests__/directToolHITLResumeScope.test.ts +0 -980
- package/src/tools/__tests__/directToolHooks.test.ts +0 -700
- package/src/tools/__tests__/eagerEventExecution.session.test.ts +0 -92
- package/src/tools/__tests__/handlers.test.ts +0 -997
- package/src/tools/__tests__/hitl.test.ts +0 -4663
- package/src/tools/__tests__/intentArg.test.ts +0 -357
- package/src/tools/__tests__/intentCoverage.test.ts +0 -139
- package/src/tools/__tests__/localToolNames.test.ts +0 -75
- package/src/tools/__tests__/skillCatalog.test.ts +0 -161
- package/src/tools/__tests__/subagentHooks.test.ts +0 -1651
- package/src/tools/__tests__/toolOutputReferences.test.ts +0 -515
- package/src/tools/__tests__/workspaceSeam.test.ts +0 -147
- package/src/tools/local/__tests__/FileCheckpointer.test.ts +0 -162
- package/src/tools/local/__tests__/editStrategies.test.ts +0 -134
- package/src/tools/search/content.test.ts +0 -173
- package/src/tools/search/crw.test.ts +0 -836
- package/src/tools/search/format.test.ts +0 -242
- package/src/tools/search/http-agent.test.ts +0 -133
- package/src/tools/search/jina-reranker.test.ts +0 -306
- package/src/tools/search/keenable-scraper.test.ts +0 -153
- package/src/tools/search/keenable.test.ts +0 -183
- package/src/tools/search/outcome.test.ts +0 -90
- package/src/tools/search/output.md +0 -2775
- package/src/tools/search/rag-api-reranker.test.ts +0 -891
- package/src/tools/search/source-processing.test.ts +0 -516
- package/src/tools/search/tavily.test.ts +0 -965
- package/src/tools/search/test.html +0 -884
- package/src/tools/search/test.md +0 -643
- package/src/tools/subagent/__tests__/SubagentExecutionRegistry.test.ts +0 -637
- package/src/tools/subagent/__tests__/SubagentExecutor.lazy.test.ts +0 -3054
- package/src/tools/subagent/__tests__/childGraphConfig.test.ts +0 -521
- package/src/utils/__tests__/apportion.test.ts +0 -32
- package/src/utils/__tests__/errors.test.ts +0 -270
- package/src/utils/__tests__/fixtures/contextOverflowSignatures.ts +0 -336
- package/src/utils/__tests__/redactSecrets.test.ts +0 -56
- package/src/utils/__tests__/truncation.test.ts +0 -66
- package/src/utils/llm.test.ts +0 -18
- package/src/utils/proxy.test.ts +0 -176
- package/src/utils/toolContent.test.ts +0 -1432
|
@@ -1,1557 +0,0 @@
|
|
|
1
|
-
// src/tools/__tests__/ProgrammaticToolCalling.test.ts
|
|
2
|
-
/**
|
|
3
|
-
* Unit tests for Programmatic Tool Calling.
|
|
4
|
-
* Tests manual invocation with mock tools and Code API responses.
|
|
5
|
-
*/
|
|
6
|
-
import { describe, it, expect, jest, beforeEach } from '@jest/globals';
|
|
7
|
-
import type * as t from '@/types';
|
|
8
|
-
import {
|
|
9
|
-
createProgrammaticToolCallingTool,
|
|
10
|
-
createProgrammaticToolCallingSchema,
|
|
11
|
-
formatCompletedResponse,
|
|
12
|
-
extractUsedToolNames,
|
|
13
|
-
filterToolsByUsage,
|
|
14
|
-
executeTools,
|
|
15
|
-
normalizeToPythonIdentifier,
|
|
16
|
-
unwrapToolResponse,
|
|
17
|
-
} from '../ProgrammaticToolCalling';
|
|
18
|
-
import {
|
|
19
|
-
createProgrammaticToolRegistry,
|
|
20
|
-
createGetTeamMembersTool,
|
|
21
|
-
createGetExpensesTool,
|
|
22
|
-
createGetWeatherTool,
|
|
23
|
-
createCalculatorTool,
|
|
24
|
-
} from '@/test/mockTools';
|
|
25
|
-
import {
|
|
26
|
-
createBashProgrammaticToolCallingSchema,
|
|
27
|
-
normalizeBashToolResultsForReplay,
|
|
28
|
-
} from '../BashProgrammaticToolCalling';
|
|
29
|
-
import { Constants } from '@/common';
|
|
30
|
-
|
|
31
|
-
describe('ProgrammaticToolCalling', () => {
|
|
32
|
-
describe('tool descriptions', () => {
|
|
33
|
-
it('explains Python inner-tool call and result shape', () => {
|
|
34
|
-
const schema = createProgrammaticToolCallingSchema();
|
|
35
|
-
const description = schema.properties.code.description;
|
|
36
|
-
|
|
37
|
-
expect(description).toContain('keyword args only');
|
|
38
|
-
expect(description).toContain('never pass a dict');
|
|
39
|
-
expect(description).toContain('Tool results are decoded Python values');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('explains bash inner-tool stdout shape', () => {
|
|
43
|
-
const schema = createBashProgrammaticToolCallingSchema();
|
|
44
|
-
const description = schema.properties.code.description;
|
|
45
|
-
|
|
46
|
-
expect(description).toContain(
|
|
47
|
-
'Tool stdout is normalized to one compact JSON value'
|
|
48
|
-
);
|
|
49
|
-
expect(description).toContain('use fromjson? // .');
|
|
50
|
-
expect(description).toContain('only for JSON-string fields');
|
|
51
|
-
expect(description).toContain('raw=$(tool');
|
|
52
|
-
expect(description).toContain('direct tool > file may be empty');
|
|
53
|
-
expect(description).toContain('/mnt/data/sf.json');
|
|
54
|
-
expect(description).toContain('Failed executions register nothing');
|
|
55
|
-
expect(description).toContain('`/tmp` never survives the call');
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe('normalizeBashToolResultsForReplay', () => {
|
|
60
|
-
it('decodes JSON-looking string results before bash replay', () => {
|
|
61
|
-
const results = normalizeBashToolResultsForReplay([
|
|
62
|
-
{
|
|
63
|
-
call_id: 'call_001',
|
|
64
|
-
result: JSON.stringify({
|
|
65
|
-
result: {
|
|
66
|
-
data: [{ station_id: 'USW00094725', winter_days: 91 }],
|
|
67
|
-
},
|
|
68
|
-
}),
|
|
69
|
-
is_error: false,
|
|
70
|
-
},
|
|
71
|
-
]);
|
|
72
|
-
|
|
73
|
-
expect(results[0].result).toEqual({
|
|
74
|
-
result: {
|
|
75
|
-
data: [{ station_id: 'USW00094725', winter_days: 91 }],
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('decodes JSON-looking array string results before bash replay', () => {
|
|
81
|
-
const results = normalizeBashToolResultsForReplay([
|
|
82
|
-
{
|
|
83
|
-
call_id: 'call_001',
|
|
84
|
-
result: '[{"name":"tempAvg"},{"name":"snowDepth"}]',
|
|
85
|
-
is_error: false,
|
|
86
|
-
},
|
|
87
|
-
]);
|
|
88
|
-
|
|
89
|
-
expect(results[0].result).toEqual([
|
|
90
|
-
{ name: 'tempAvg' },
|
|
91
|
-
{ name: 'snowDepth' },
|
|
92
|
-
]);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('preserves plain strings, invalid JSON strings, and error results', () => {
|
|
96
|
-
const errorJson = '{"message":"tool failed"}';
|
|
97
|
-
const results = normalizeBashToolResultsForReplay([
|
|
98
|
-
{
|
|
99
|
-
call_id: 'call_001',
|
|
100
|
-
result: 'plain text',
|
|
101
|
-
is_error: false,
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
call_id: 'call_002',
|
|
105
|
-
result: '{not json}',
|
|
106
|
-
is_error: false,
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
call_id: 'call_003',
|
|
110
|
-
result: errorJson,
|
|
111
|
-
is_error: true,
|
|
112
|
-
error_message: 'tool failed',
|
|
113
|
-
},
|
|
114
|
-
]);
|
|
115
|
-
|
|
116
|
-
expect(results[0].result).toBe('plain text');
|
|
117
|
-
expect(results[1].result).toBe('{not json}');
|
|
118
|
-
expect(results[2].result).toBe(errorJson);
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
describe('executeTools', () => {
|
|
123
|
-
let toolMap: t.ToolMap;
|
|
124
|
-
|
|
125
|
-
beforeEach(() => {
|
|
126
|
-
const tools = [
|
|
127
|
-
createGetTeamMembersTool(),
|
|
128
|
-
createGetExpensesTool(),
|
|
129
|
-
createGetWeatherTool(),
|
|
130
|
-
createCalculatorTool(),
|
|
131
|
-
];
|
|
132
|
-
toolMap = new Map(tools.map((t) => [t.name, t]));
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('executes a single tool successfully', async () => {
|
|
136
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
137
|
-
{
|
|
138
|
-
id: 'call_001',
|
|
139
|
-
name: 'get_weather',
|
|
140
|
-
input: { city: 'San Francisco' },
|
|
141
|
-
},
|
|
142
|
-
];
|
|
143
|
-
|
|
144
|
-
const results = await executeTools(toolCalls, toolMap);
|
|
145
|
-
|
|
146
|
-
expect(results).toHaveLength(1);
|
|
147
|
-
expect(results[0].call_id).toBe('call_001');
|
|
148
|
-
expect(results[0].is_error).toBe(false);
|
|
149
|
-
expect(results[0].result).toEqual({
|
|
150
|
-
temperature: 65,
|
|
151
|
-
condition: 'Foggy',
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('parses JSON-string inputs before invoking structured tools', async () => {
|
|
156
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
157
|
-
{
|
|
158
|
-
id: 'call_001',
|
|
159
|
-
name: 'get_weather',
|
|
160
|
-
input: '{"city":"San Francisco"}',
|
|
161
|
-
},
|
|
162
|
-
];
|
|
163
|
-
|
|
164
|
-
const results = await executeTools(toolCalls, toolMap);
|
|
165
|
-
|
|
166
|
-
expect(results).toHaveLength(1);
|
|
167
|
-
expect(results[0].call_id).toBe('call_001');
|
|
168
|
-
expect(results[0].is_error).toBe(false);
|
|
169
|
-
expect(results[0].result).toEqual({
|
|
170
|
-
temperature: 65,
|
|
171
|
-
condition: 'Foggy',
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
it('parses ClickHouse-style JSON strings with SQL punctuation for object-schema tools', async () => {
|
|
176
|
-
const invoke = jest.fn<
|
|
177
|
-
(_input: unknown, _config: unknown) => Promise<unknown>
|
|
178
|
-
>(async (input) => input);
|
|
179
|
-
const customTool = {
|
|
180
|
-
name: 'run_select_query_mcp_ClickHouse',
|
|
181
|
-
schema: {
|
|
182
|
-
type: 'object',
|
|
183
|
-
properties: {
|
|
184
|
-
serviceId: { type: 'string' },
|
|
185
|
-
query: { type: 'string' },
|
|
186
|
-
},
|
|
187
|
-
required: ['serviceId', 'query'],
|
|
188
|
-
},
|
|
189
|
-
invoke,
|
|
190
|
-
} as unknown as t.GenericTool;
|
|
191
|
-
const customToolMap: t.ToolMap = new Map([
|
|
192
|
-
['run_select_query_mcp_ClickHouse', customTool],
|
|
193
|
-
]);
|
|
194
|
-
const input = {
|
|
195
|
-
serviceId: '45886e06-932b-4cff-bb49-3f7281d80717',
|
|
196
|
-
query:
|
|
197
|
-
'SELECT name, round(avg(tempAvg)/10.0, 2) AS avg_temp_c ' +
|
|
198
|
-
'FROM system.columns WHERE database=\'default\' ' +
|
|
199
|
-
'AND table=\'uk_prices_3\' AND tempAvg != -9999',
|
|
200
|
-
};
|
|
201
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
202
|
-
{
|
|
203
|
-
id: 'call_001',
|
|
204
|
-
name: 'run_select_query_mcp_ClickHouse',
|
|
205
|
-
input: JSON.stringify(input),
|
|
206
|
-
},
|
|
207
|
-
];
|
|
208
|
-
|
|
209
|
-
const results = await executeTools(toolCalls, customToolMap);
|
|
210
|
-
|
|
211
|
-
expect(results[0].is_error).toBe(false);
|
|
212
|
-
expect(results[0].result).toEqual(input);
|
|
213
|
-
expect(invoke).toHaveBeenCalledWith(input, {
|
|
214
|
-
metadata: { [Constants.PROGRAMMATIC_TOOL_CALLING]: true },
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it('preserves JSON-looking strings for string-input tools', async () => {
|
|
219
|
-
const invoke = jest.fn<
|
|
220
|
-
(_input: unknown, _config: unknown) => Promise<unknown>
|
|
221
|
-
>(async (input) => input);
|
|
222
|
-
const customTool = {
|
|
223
|
-
name: 'string_tool',
|
|
224
|
-
schema: { type: 'string' },
|
|
225
|
-
invoke,
|
|
226
|
-
} as unknown as t.GenericTool;
|
|
227
|
-
const customToolMap: t.ToolMap = new Map([['string_tool', customTool]]);
|
|
228
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
229
|
-
{
|
|
230
|
-
id: 'call_001',
|
|
231
|
-
name: 'string_tool',
|
|
232
|
-
input: '{"raw":true}',
|
|
233
|
-
},
|
|
234
|
-
];
|
|
235
|
-
|
|
236
|
-
const results = await executeTools(toolCalls, customToolMap);
|
|
237
|
-
|
|
238
|
-
expect(results[0].is_error).toBe(false);
|
|
239
|
-
expect(results[0].result).toBe('{"raw":true}');
|
|
240
|
-
expect(invoke).toHaveBeenCalledWith('{"raw":true}', {
|
|
241
|
-
metadata: { [Constants.PROGRAMMATIC_TOOL_CALLING]: true },
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
it('preserves ClickHouse-style JSON strings for raw string-input tools', async () => {
|
|
246
|
-
const invoke = jest.fn<
|
|
247
|
-
(_input: unknown, _config: unknown) => Promise<unknown>
|
|
248
|
-
>(async (input) => input);
|
|
249
|
-
const customTool = {
|
|
250
|
-
name: 'string_tool',
|
|
251
|
-
schema: { type: 'string' },
|
|
252
|
-
invoke,
|
|
253
|
-
} as unknown as t.GenericTool;
|
|
254
|
-
const customToolMap: t.ToolMap = new Map([['string_tool', customTool]]);
|
|
255
|
-
const input = JSON.stringify({
|
|
256
|
-
serviceId: '45886e06-932b-4cff-bb49-3f7281d80717',
|
|
257
|
-
query:
|
|
258
|
-
'SELECT round(avg(tempAvg)/10.0, 2) AS avg_temp_c ' +
|
|
259
|
-
'FROM default.weather_noaa_mt WHERE database=\'default\'',
|
|
260
|
-
});
|
|
261
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
262
|
-
{
|
|
263
|
-
id: 'call_001',
|
|
264
|
-
name: 'string_tool',
|
|
265
|
-
input,
|
|
266
|
-
},
|
|
267
|
-
];
|
|
268
|
-
|
|
269
|
-
const results = await executeTools(toolCalls, customToolMap);
|
|
270
|
-
|
|
271
|
-
expect(results[0].is_error).toBe(false);
|
|
272
|
-
expect(results[0].result).toBe(input);
|
|
273
|
-
expect(invoke).toHaveBeenCalledWith(input, {
|
|
274
|
-
metadata: { [Constants.PROGRAMMATIC_TOOL_CALLING]: true },
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
it('stringifies object inputs before invoking string-input tools', async () => {
|
|
279
|
-
const invoke = jest.fn<
|
|
280
|
-
(_input: unknown, _config: unknown) => Promise<unknown>
|
|
281
|
-
>(async (input) => input);
|
|
282
|
-
const customTool = {
|
|
283
|
-
name: 'string_tool',
|
|
284
|
-
schema: { type: 'string' },
|
|
285
|
-
invoke,
|
|
286
|
-
} as unknown as t.GenericTool;
|
|
287
|
-
const customToolMap: t.ToolMap = new Map([['string_tool', customTool]]);
|
|
288
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
289
|
-
{
|
|
290
|
-
id: 'call_001',
|
|
291
|
-
name: 'string_tool',
|
|
292
|
-
input: { raw: true },
|
|
293
|
-
},
|
|
294
|
-
];
|
|
295
|
-
|
|
296
|
-
const results = await executeTools(toolCalls, customToolMap);
|
|
297
|
-
|
|
298
|
-
expect(results[0].is_error).toBe(false);
|
|
299
|
-
expect(results[0].result).toBe('{"raw":true}');
|
|
300
|
-
expect(invoke).toHaveBeenCalledWith('{"raw":true}', {
|
|
301
|
-
metadata: { [Constants.PROGRAMMATIC_TOOL_CALLING]: true },
|
|
302
|
-
});
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
it('preserves object inputs for mixed object-or-string schemas', async () => {
|
|
306
|
-
const invoke = jest.fn<
|
|
307
|
-
(_input: unknown, _config: unknown) => Promise<unknown>
|
|
308
|
-
>(async (input) => input);
|
|
309
|
-
const customTool = {
|
|
310
|
-
name: 'mixed_tool',
|
|
311
|
-
schema: { type: ['object', 'string'] },
|
|
312
|
-
invoke,
|
|
313
|
-
} as unknown as t.GenericTool;
|
|
314
|
-
const customToolMap: t.ToolMap = new Map([['mixed_tool', customTool]]);
|
|
315
|
-
const input = { raw: true };
|
|
316
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
317
|
-
{
|
|
318
|
-
id: 'call_001',
|
|
319
|
-
name: 'mixed_tool',
|
|
320
|
-
input,
|
|
321
|
-
},
|
|
322
|
-
];
|
|
323
|
-
|
|
324
|
-
const results = await executeTools(toolCalls, customToolMap);
|
|
325
|
-
|
|
326
|
-
expect(results[0].is_error).toBe(false);
|
|
327
|
-
expect(results[0].result).toBe(input);
|
|
328
|
-
expect(invoke).toHaveBeenCalledWith(input, {
|
|
329
|
-
metadata: { [Constants.PROGRAMMATIC_TOOL_CALLING]: true },
|
|
330
|
-
});
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
it('preserves JSON-looking strings for mixed object-or-string schemas', async () => {
|
|
334
|
-
const invoke = jest.fn<
|
|
335
|
-
(_input: unknown, _config: unknown) => Promise<unknown>
|
|
336
|
-
>(async (input) => input);
|
|
337
|
-
const customTool = {
|
|
338
|
-
name: 'mixed_tool',
|
|
339
|
-
schema: { type: ['object', 'string'] },
|
|
340
|
-
invoke,
|
|
341
|
-
} as unknown as t.GenericTool;
|
|
342
|
-
const customToolMap: t.ToolMap = new Map([['mixed_tool', customTool]]);
|
|
343
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
344
|
-
{
|
|
345
|
-
id: 'call_001',
|
|
346
|
-
name: 'mixed_tool',
|
|
347
|
-
input: '{"raw":true}',
|
|
348
|
-
},
|
|
349
|
-
];
|
|
350
|
-
|
|
351
|
-
const results = await executeTools(toolCalls, customToolMap);
|
|
352
|
-
|
|
353
|
-
expect(results[0].is_error).toBe(false);
|
|
354
|
-
expect(results[0].result).toBe('{"raw":true}');
|
|
355
|
-
expect(invoke).toHaveBeenCalledWith('{"raw":true}', {
|
|
356
|
-
metadata: { [Constants.PROGRAMMATIC_TOOL_CALLING]: true },
|
|
357
|
-
});
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
it('marks bash PTC inner tool invocations with bash metadata', async () => {
|
|
361
|
-
const invoke = jest.fn<
|
|
362
|
-
(_input: unknown, _config: unknown) => Promise<{ ok: boolean }>
|
|
363
|
-
>(async () => ({ ok: true }));
|
|
364
|
-
const customTool = {
|
|
365
|
-
name: 'custom_tool',
|
|
366
|
-
invoke,
|
|
367
|
-
} as unknown as t.GenericTool;
|
|
368
|
-
const customToolMap: t.ToolMap = new Map([['custom_tool', customTool]]);
|
|
369
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
370
|
-
{
|
|
371
|
-
id: 'call_001',
|
|
372
|
-
name: 'custom_tool',
|
|
373
|
-
input: { value: 1 },
|
|
374
|
-
},
|
|
375
|
-
];
|
|
376
|
-
|
|
377
|
-
await executeTools(
|
|
378
|
-
toolCalls,
|
|
379
|
-
customToolMap,
|
|
380
|
-
Constants.BASH_PROGRAMMATIC_TOOL_CALLING
|
|
381
|
-
);
|
|
382
|
-
|
|
383
|
-
expect(invoke).toHaveBeenCalledWith(
|
|
384
|
-
{ value: 1 },
|
|
385
|
-
{ metadata: { [Constants.BASH_PROGRAMMATIC_TOOL_CALLING]: true } }
|
|
386
|
-
);
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
it('executes multiple tools in parallel', async () => {
|
|
390
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
391
|
-
{
|
|
392
|
-
id: 'call_001',
|
|
393
|
-
name: 'get_weather',
|
|
394
|
-
input: { city: 'San Francisco' },
|
|
395
|
-
},
|
|
396
|
-
{
|
|
397
|
-
id: 'call_002',
|
|
398
|
-
name: 'get_weather',
|
|
399
|
-
input: { city: 'New York' },
|
|
400
|
-
},
|
|
401
|
-
{
|
|
402
|
-
id: 'call_003',
|
|
403
|
-
name: 'get_weather',
|
|
404
|
-
input: { city: 'London' },
|
|
405
|
-
},
|
|
406
|
-
];
|
|
407
|
-
|
|
408
|
-
const startTime = Date.now();
|
|
409
|
-
const results = await executeTools(toolCalls, toolMap);
|
|
410
|
-
const duration = Date.now() - startTime;
|
|
411
|
-
|
|
412
|
-
// Should execute in parallel (< 150ms total, not 120ms sequential)
|
|
413
|
-
expect(duration).toBeLessThan(150);
|
|
414
|
-
|
|
415
|
-
expect(results).toHaveLength(3);
|
|
416
|
-
expect(results[0].is_error).toBe(false);
|
|
417
|
-
expect(results[1].is_error).toBe(false);
|
|
418
|
-
expect(results[2].is_error).toBe(false);
|
|
419
|
-
|
|
420
|
-
expect(results[0].result.temperature).toBe(65);
|
|
421
|
-
expect(results[1].result.temperature).toBe(75);
|
|
422
|
-
expect(results[2].result.temperature).toBe(55);
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
it('handles tool not found error', async () => {
|
|
426
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
427
|
-
{
|
|
428
|
-
id: 'call_001',
|
|
429
|
-
name: 'nonexistent_tool',
|
|
430
|
-
input: {},
|
|
431
|
-
},
|
|
432
|
-
];
|
|
433
|
-
|
|
434
|
-
const results = await executeTools(toolCalls, toolMap);
|
|
435
|
-
|
|
436
|
-
expect(results).toHaveLength(1);
|
|
437
|
-
expect(results[0].call_id).toBe('call_001');
|
|
438
|
-
expect(results[0].is_error).toBe(true);
|
|
439
|
-
expect(results[0].error_message).toContain('nonexistent_tool');
|
|
440
|
-
expect(results[0].error_message).toContain('Available tools:');
|
|
441
|
-
});
|
|
442
|
-
|
|
443
|
-
it('handles tool execution error', async () => {
|
|
444
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
445
|
-
{
|
|
446
|
-
id: 'call_001',
|
|
447
|
-
name: 'get_weather',
|
|
448
|
-
input: { city: 'InvalidCity' },
|
|
449
|
-
},
|
|
450
|
-
];
|
|
451
|
-
|
|
452
|
-
const results = await executeTools(toolCalls, toolMap);
|
|
453
|
-
|
|
454
|
-
expect(results).toHaveLength(1);
|
|
455
|
-
expect(results[0].call_id).toBe('call_001');
|
|
456
|
-
expect(results[0].is_error).toBe(true);
|
|
457
|
-
expect(results[0].error_message).toContain('Weather data not available');
|
|
458
|
-
});
|
|
459
|
-
|
|
460
|
-
it('handles mix of successful and failed tool calls', async () => {
|
|
461
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
462
|
-
{
|
|
463
|
-
id: 'call_001',
|
|
464
|
-
name: 'get_weather',
|
|
465
|
-
input: { city: 'San Francisco' },
|
|
466
|
-
},
|
|
467
|
-
{
|
|
468
|
-
id: 'call_002',
|
|
469
|
-
name: 'get_weather',
|
|
470
|
-
input: { city: 'InvalidCity' },
|
|
471
|
-
},
|
|
472
|
-
{
|
|
473
|
-
id: 'call_003',
|
|
474
|
-
name: 'get_weather',
|
|
475
|
-
input: { city: 'New York' },
|
|
476
|
-
},
|
|
477
|
-
];
|
|
478
|
-
|
|
479
|
-
const results = await executeTools(toolCalls, toolMap);
|
|
480
|
-
|
|
481
|
-
expect(results).toHaveLength(3);
|
|
482
|
-
expect(results[0].is_error).toBe(false);
|
|
483
|
-
expect(results[1].is_error).toBe(true);
|
|
484
|
-
expect(results[2].is_error).toBe(false);
|
|
485
|
-
});
|
|
486
|
-
|
|
487
|
-
it('executes tools with different parameters', async () => {
|
|
488
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
489
|
-
{
|
|
490
|
-
id: 'call_001',
|
|
491
|
-
name: 'get_team_members',
|
|
492
|
-
input: {},
|
|
493
|
-
},
|
|
494
|
-
{
|
|
495
|
-
id: 'call_002',
|
|
496
|
-
name: 'get_expenses',
|
|
497
|
-
input: { user_id: 'u1' },
|
|
498
|
-
},
|
|
499
|
-
{
|
|
500
|
-
id: 'call_003',
|
|
501
|
-
name: 'calculator',
|
|
502
|
-
input: { expression: '2 + 2 * 3' },
|
|
503
|
-
},
|
|
504
|
-
];
|
|
505
|
-
|
|
506
|
-
const results = await executeTools(toolCalls, toolMap);
|
|
507
|
-
|
|
508
|
-
expect(results).toHaveLength(3);
|
|
509
|
-
expect(results[0].is_error).toBe(false);
|
|
510
|
-
expect(results[1].is_error).toBe(false);
|
|
511
|
-
expect(results[2].is_error).toBe(false);
|
|
512
|
-
|
|
513
|
-
expect(Array.isArray(results[0].result)).toBe(true);
|
|
514
|
-
expect(results[0].result).toHaveLength(3);
|
|
515
|
-
expect(Array.isArray(results[1].result)).toBe(true);
|
|
516
|
-
expect(results[2].result.result).toBe(8);
|
|
517
|
-
});
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
describe('normalizeToPythonIdentifier', () => {
|
|
521
|
-
it('converts hyphens to underscores', () => {
|
|
522
|
-
expect(normalizeToPythonIdentifier('my-tool-name')).toBe('my_tool_name');
|
|
523
|
-
});
|
|
524
|
-
|
|
525
|
-
it('converts spaces to underscores', () => {
|
|
526
|
-
expect(normalizeToPythonIdentifier('my tool name')).toBe('my_tool_name');
|
|
527
|
-
});
|
|
528
|
-
|
|
529
|
-
it('leaves underscores unchanged', () => {
|
|
530
|
-
expect(normalizeToPythonIdentifier('my_tool_name')).toBe('my_tool_name');
|
|
531
|
-
});
|
|
532
|
-
|
|
533
|
-
it('handles mixed hyphens and underscores', () => {
|
|
534
|
-
expect(normalizeToPythonIdentifier('my-tool_name-v2')).toBe(
|
|
535
|
-
'my_tool_name_v2'
|
|
536
|
-
);
|
|
537
|
-
});
|
|
538
|
-
|
|
539
|
-
it('handles MCP-style names with hyphens', () => {
|
|
540
|
-
expect(
|
|
541
|
-
normalizeToPythonIdentifier('create_spreadsheet_mcp_Google-Workspace')
|
|
542
|
-
).toBe('create_spreadsheet_mcp_Google_Workspace');
|
|
543
|
-
});
|
|
544
|
-
|
|
545
|
-
it('removes invalid characters', () => {
|
|
546
|
-
expect(normalizeToPythonIdentifier('tool@name!v2')).toBe('toolnamev2');
|
|
547
|
-
expect(normalizeToPythonIdentifier('get.data.v2')).toBe('getdatav2');
|
|
548
|
-
});
|
|
549
|
-
|
|
550
|
-
it('prefixes with underscore if starts with number', () => {
|
|
551
|
-
expect(normalizeToPythonIdentifier('123tool')).toBe('_123tool');
|
|
552
|
-
expect(normalizeToPythonIdentifier('1-tool')).toBe('_1_tool');
|
|
553
|
-
});
|
|
554
|
-
|
|
555
|
-
it('appends _tool suffix for Python keywords', () => {
|
|
556
|
-
expect(normalizeToPythonIdentifier('return')).toBe('return_tool');
|
|
557
|
-
expect(normalizeToPythonIdentifier('async')).toBe('async_tool');
|
|
558
|
-
expect(normalizeToPythonIdentifier('import')).toBe('import_tool');
|
|
559
|
-
});
|
|
560
|
-
});
|
|
561
|
-
|
|
562
|
-
describe('unwrapToolResponse', () => {
|
|
563
|
-
describe('non-MCP tools', () => {
|
|
564
|
-
it('returns result as-is for non-MCP tools', () => {
|
|
565
|
-
const result = { temperature: 65, condition: 'Foggy' };
|
|
566
|
-
expect(unwrapToolResponse(result, false)).toEqual(result);
|
|
567
|
-
});
|
|
568
|
-
|
|
569
|
-
it('returns string as-is for non-MCP tools', () => {
|
|
570
|
-
expect(unwrapToolResponse('plain string', false)).toBe('plain string');
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
it('returns array as-is for non-MCP tools', () => {
|
|
574
|
-
const result = [1, 2, 3];
|
|
575
|
-
expect(unwrapToolResponse(result, false)).toEqual(result);
|
|
576
|
-
});
|
|
577
|
-
});
|
|
578
|
-
|
|
579
|
-
describe('MCP tools - tuple format [content, artifacts]', () => {
|
|
580
|
-
it('extracts string content from tuple', () => {
|
|
581
|
-
const result = ['Hello world', { artifacts: [] }];
|
|
582
|
-
expect(unwrapToolResponse(result, true)).toBe('Hello world');
|
|
583
|
-
});
|
|
584
|
-
|
|
585
|
-
it('parses JSON string content from tuple', () => {
|
|
586
|
-
const result = ['{"temperature": 65}', { artifacts: [] }];
|
|
587
|
-
expect(unwrapToolResponse(result, true)).toEqual({ temperature: 65 });
|
|
588
|
-
});
|
|
589
|
-
|
|
590
|
-
it('parses JSON array string content from tuple', () => {
|
|
591
|
-
const result = ['[1, 2, 3]', { artifacts: [] }];
|
|
592
|
-
expect(unwrapToolResponse(result, true)).toEqual([1, 2, 3]);
|
|
593
|
-
});
|
|
594
|
-
|
|
595
|
-
it('extracts text from single content block in tuple', () => {
|
|
596
|
-
const result = [{ type: 'text', text: 'Spreadsheet info here' }, {}];
|
|
597
|
-
expect(unwrapToolResponse(result, true)).toBe('Spreadsheet info here');
|
|
598
|
-
});
|
|
599
|
-
|
|
600
|
-
it('extracts and parses JSON from single content block in tuple', () => {
|
|
601
|
-
const result = [
|
|
602
|
-
{ type: 'text', text: '{"id": "123", "name": "Test"}' },
|
|
603
|
-
{},
|
|
604
|
-
];
|
|
605
|
-
expect(unwrapToolResponse(result, true)).toEqual({
|
|
606
|
-
id: '123',
|
|
607
|
-
name: 'Test',
|
|
608
|
-
});
|
|
609
|
-
});
|
|
610
|
-
|
|
611
|
-
it('extracts text from array of content blocks in tuple', () => {
|
|
612
|
-
const result = [
|
|
613
|
-
[
|
|
614
|
-
{ type: 'text', text: 'Line 1' },
|
|
615
|
-
{ type: 'text', text: 'Line 2' },
|
|
616
|
-
],
|
|
617
|
-
{},
|
|
618
|
-
];
|
|
619
|
-
expect(unwrapToolResponse(result, true)).toBe('Line 1\nLine 2');
|
|
620
|
-
});
|
|
621
|
-
|
|
622
|
-
it('returns object content as-is when not a text block', () => {
|
|
623
|
-
const result = [{ temperature: 65, condition: 'Foggy' }, {}];
|
|
624
|
-
expect(unwrapToolResponse(result, true)).toEqual({
|
|
625
|
-
temperature: 65,
|
|
626
|
-
condition: 'Foggy',
|
|
627
|
-
});
|
|
628
|
-
});
|
|
629
|
-
});
|
|
630
|
-
|
|
631
|
-
describe('MCP tools - single content block (not in tuple)', () => {
|
|
632
|
-
it('extracts text from single content block object', () => {
|
|
633
|
-
const result = { type: 'text', text: 'No data found in range' };
|
|
634
|
-
expect(unwrapToolResponse(result, true)).toBe('No data found in range');
|
|
635
|
-
});
|
|
636
|
-
|
|
637
|
-
it('extracts and parses JSON from single content block object', () => {
|
|
638
|
-
const result = {
|
|
639
|
-
type: 'text',
|
|
640
|
-
text: '{"sheets": [{"name": "raw_data"}]}',
|
|
641
|
-
};
|
|
642
|
-
expect(unwrapToolResponse(result, true)).toEqual({
|
|
643
|
-
sheets: [{ name: 'raw_data' }],
|
|
644
|
-
});
|
|
645
|
-
});
|
|
646
|
-
|
|
647
|
-
it('handles real-world MCP spreadsheet response', () => {
|
|
648
|
-
const result = {
|
|
649
|
-
type: 'text',
|
|
650
|
-
text: 'Spreadsheet: "NYC Taxi - Top Pickup Neighborhoods" (ID: abc123)\nSheets (2):\n - "raw_data" (ID: 123) | Size: 1000x26',
|
|
651
|
-
};
|
|
652
|
-
expect(unwrapToolResponse(result, true)).toBe(
|
|
653
|
-
'Spreadsheet: "NYC Taxi - Top Pickup Neighborhoods" (ID: abc123)\nSheets (2):\n - "raw_data" (ID: 123) | Size: 1000x26'
|
|
654
|
-
);
|
|
655
|
-
});
|
|
656
|
-
|
|
657
|
-
it('handles real-world MCP no data response', () => {
|
|
658
|
-
const result = {
|
|
659
|
-
type: 'text',
|
|
660
|
-
text: 'No data found in range \'raw_data!A1:D25\' for user@example.com.',
|
|
661
|
-
};
|
|
662
|
-
expect(unwrapToolResponse(result, true)).toBe(
|
|
663
|
-
'No data found in range \'raw_data!A1:D25\' for user@example.com.'
|
|
664
|
-
);
|
|
665
|
-
});
|
|
666
|
-
});
|
|
667
|
-
|
|
668
|
-
describe('MCP tools - array of content blocks (not in tuple)', () => {
|
|
669
|
-
it('extracts text from array of content blocks', () => {
|
|
670
|
-
const result = [
|
|
671
|
-
{ type: 'text', text: 'First block' },
|
|
672
|
-
{ type: 'text', text: 'Second block' },
|
|
673
|
-
];
|
|
674
|
-
expect(unwrapToolResponse(result, true)).toBe(
|
|
675
|
-
'First block\nSecond block'
|
|
676
|
-
);
|
|
677
|
-
});
|
|
678
|
-
|
|
679
|
-
it('filters out non-text blocks', () => {
|
|
680
|
-
const result = [
|
|
681
|
-
{ type: 'text', text: 'Text content' },
|
|
682
|
-
{ type: 'image', data: 'base64...' },
|
|
683
|
-
{ type: 'text', text: 'More text' },
|
|
684
|
-
];
|
|
685
|
-
expect(unwrapToolResponse(result, true)).toBe(
|
|
686
|
-
'Text content\nMore text'
|
|
687
|
-
);
|
|
688
|
-
});
|
|
689
|
-
});
|
|
690
|
-
|
|
691
|
-
describe('edge cases', () => {
|
|
692
|
-
it('returns non-text block object as-is', () => {
|
|
693
|
-
const result = { type: 'image', data: 'base64...' };
|
|
694
|
-
expect(unwrapToolResponse(result, true)).toEqual(result);
|
|
695
|
-
});
|
|
696
|
-
|
|
697
|
-
it('handles empty array', () => {
|
|
698
|
-
expect(unwrapToolResponse([], true)).toEqual([]);
|
|
699
|
-
});
|
|
700
|
-
|
|
701
|
-
it('handles malformed JSON in text block gracefully', () => {
|
|
702
|
-
const result = { type: 'text', text: '{ invalid json }' };
|
|
703
|
-
expect(unwrapToolResponse(result, true)).toBe('{ invalid json }');
|
|
704
|
-
});
|
|
705
|
-
|
|
706
|
-
it('handles null', () => {
|
|
707
|
-
expect(unwrapToolResponse(null, true)).toBe(null);
|
|
708
|
-
});
|
|
709
|
-
|
|
710
|
-
it('handles undefined', () => {
|
|
711
|
-
expect(unwrapToolResponse(undefined, true)).toBe(undefined);
|
|
712
|
-
});
|
|
713
|
-
});
|
|
714
|
-
});
|
|
715
|
-
|
|
716
|
-
describe('extractUsedToolNames', () => {
|
|
717
|
-
const createToolMap = (names: string[]): Map<string, string> => {
|
|
718
|
-
const map = new Map<string, string>();
|
|
719
|
-
for (const name of names) {
|
|
720
|
-
map.set(normalizeToPythonIdentifier(name), name);
|
|
721
|
-
}
|
|
722
|
-
return map;
|
|
723
|
-
};
|
|
724
|
-
|
|
725
|
-
const availableTools = createToolMap([
|
|
726
|
-
'get_weather',
|
|
727
|
-
'get_team_members',
|
|
728
|
-
'get_expenses',
|
|
729
|
-
'calculator',
|
|
730
|
-
'search_docs',
|
|
731
|
-
]);
|
|
732
|
-
|
|
733
|
-
it('extracts single tool name from simple code', () => {
|
|
734
|
-
const code = `result = await get_weather(city="SF")
|
|
735
|
-
print(result)`;
|
|
736
|
-
const used = extractUsedToolNames(code, availableTools);
|
|
737
|
-
|
|
738
|
-
expect(used.size).toBe(1);
|
|
739
|
-
expect(used.has('get_weather')).toBe(true);
|
|
740
|
-
});
|
|
741
|
-
|
|
742
|
-
it('extracts multiple tool names from code', () => {
|
|
743
|
-
const code = `team = await get_team_members()
|
|
744
|
-
for member in team:
|
|
745
|
-
expenses = await get_expenses(user_id=member['id'])
|
|
746
|
-
print(f"{member['name']}: {sum(e['amount'] for e in expenses)}")`;
|
|
747
|
-
|
|
748
|
-
const used = extractUsedToolNames(code, availableTools);
|
|
749
|
-
|
|
750
|
-
expect(used.size).toBe(2);
|
|
751
|
-
expect(used.has('get_team_members')).toBe(true);
|
|
752
|
-
expect(used.has('get_expenses')).toBe(true);
|
|
753
|
-
});
|
|
754
|
-
|
|
755
|
-
it('extracts tools from asyncio.gather calls', () => {
|
|
756
|
-
const code = `results = await asyncio.gather(
|
|
757
|
-
get_weather(city="SF"),
|
|
758
|
-
get_weather(city="NYC"),
|
|
759
|
-
get_expenses(user_id="u1")
|
|
760
|
-
)`;
|
|
761
|
-
const used = extractUsedToolNames(code, availableTools);
|
|
762
|
-
|
|
763
|
-
expect(used.size).toBe(2);
|
|
764
|
-
expect(used.has('get_weather')).toBe(true);
|
|
765
|
-
expect(used.has('get_expenses')).toBe(true);
|
|
766
|
-
});
|
|
767
|
-
|
|
768
|
-
it('does not match partial tool names', () => {
|
|
769
|
-
const code = `# Using get_weather_data instead
|
|
770
|
-
result = await get_weather_data(city="SF")`;
|
|
771
|
-
|
|
772
|
-
const used = extractUsedToolNames(code, availableTools);
|
|
773
|
-
expect(used.has('get_weather')).toBe(false);
|
|
774
|
-
});
|
|
775
|
-
|
|
776
|
-
it('matches tool names in different contexts', () => {
|
|
777
|
-
const code = `# direct call
|
|
778
|
-
x = await calculator(expression="1+1")
|
|
779
|
-
# in list comprehension
|
|
780
|
-
results = [await get_weather(city=c) for c in cities]
|
|
781
|
-
# conditional
|
|
782
|
-
if condition:
|
|
783
|
-
await get_team_members()`;
|
|
784
|
-
|
|
785
|
-
const used = extractUsedToolNames(code, availableTools);
|
|
786
|
-
|
|
787
|
-
expect(used.size).toBe(3);
|
|
788
|
-
expect(used.has('calculator')).toBe(true);
|
|
789
|
-
expect(used.has('get_weather')).toBe(true);
|
|
790
|
-
expect(used.has('get_team_members')).toBe(true);
|
|
791
|
-
});
|
|
792
|
-
|
|
793
|
-
it('returns empty set when no tools are used', () => {
|
|
794
|
-
const code = `print("Hello, World!")
|
|
795
|
-
x = 1 + 2`;
|
|
796
|
-
|
|
797
|
-
const used = extractUsedToolNames(code, availableTools);
|
|
798
|
-
expect(used.size).toBe(0);
|
|
799
|
-
});
|
|
800
|
-
|
|
801
|
-
it('handles tool names with special characters via normalization', () => {
|
|
802
|
-
const specialTools = createToolMap(['get_data.v2', 'calc+plus']);
|
|
803
|
-
const code = `await get_datav2()
|
|
804
|
-
await calcplus()`;
|
|
805
|
-
|
|
806
|
-
const used = extractUsedToolNames(code, specialTools);
|
|
807
|
-
|
|
808
|
-
expect(used.has('get_data.v2')).toBe(true);
|
|
809
|
-
expect(used.has('calc+plus')).toBe(true);
|
|
810
|
-
});
|
|
811
|
-
|
|
812
|
-
it('matches hyphenated tool names using underscore in code', () => {
|
|
813
|
-
const mcpTools = createToolMap([
|
|
814
|
-
'create_spreadsheet_mcp_Google-Workspace',
|
|
815
|
-
'search_gmail_mcp_Google-Workspace',
|
|
816
|
-
]);
|
|
817
|
-
const code = `result = await create_spreadsheet_mcp_Google_Workspace(title="Test")
|
|
818
|
-
print(result)`;
|
|
819
|
-
|
|
820
|
-
const used = extractUsedToolNames(code, mcpTools);
|
|
821
|
-
|
|
822
|
-
expect(used.size).toBe(1);
|
|
823
|
-
expect(used.has('create_spreadsheet_mcp_Google-Workspace')).toBe(true);
|
|
824
|
-
});
|
|
825
|
-
});
|
|
826
|
-
|
|
827
|
-
describe('filterToolsByUsage', () => {
|
|
828
|
-
const allToolDefs: t.LCTool[] = [
|
|
829
|
-
{
|
|
830
|
-
name: 'get_weather',
|
|
831
|
-
description: 'Get weather for a city',
|
|
832
|
-
parameters: {
|
|
833
|
-
type: 'object',
|
|
834
|
-
properties: { city: { type: 'string' } },
|
|
835
|
-
},
|
|
836
|
-
},
|
|
837
|
-
{
|
|
838
|
-
name: 'get_team_members',
|
|
839
|
-
description: 'Get team members',
|
|
840
|
-
parameters: { type: 'object', properties: {} },
|
|
841
|
-
},
|
|
842
|
-
{
|
|
843
|
-
name: 'get_expenses',
|
|
844
|
-
description: 'Get expenses for a user',
|
|
845
|
-
parameters: {
|
|
846
|
-
type: 'object',
|
|
847
|
-
properties: { user_id: { type: 'string' } },
|
|
848
|
-
},
|
|
849
|
-
},
|
|
850
|
-
{
|
|
851
|
-
name: 'calculator',
|
|
852
|
-
description: 'Evaluate an expression',
|
|
853
|
-
parameters: {
|
|
854
|
-
type: 'object',
|
|
855
|
-
properties: { expression: { type: 'string' } },
|
|
856
|
-
},
|
|
857
|
-
},
|
|
858
|
-
];
|
|
859
|
-
|
|
860
|
-
it('filters to only used tools', () => {
|
|
861
|
-
const code = `result = await get_weather(city="SF")
|
|
862
|
-
print(result)`;
|
|
863
|
-
|
|
864
|
-
const filtered = filterToolsByUsage(allToolDefs, code);
|
|
865
|
-
|
|
866
|
-
expect(filtered).toHaveLength(1);
|
|
867
|
-
expect(filtered[0].name).toBe('get_weather');
|
|
868
|
-
});
|
|
869
|
-
|
|
870
|
-
it('filters to multiple used tools', () => {
|
|
871
|
-
const code = `team = await get_team_members()
|
|
872
|
-
for member in team:
|
|
873
|
-
expenses = await get_expenses(user_id=member['id'])`;
|
|
874
|
-
|
|
875
|
-
const filtered = filterToolsByUsage(allToolDefs, code);
|
|
876
|
-
|
|
877
|
-
expect(filtered).toHaveLength(2);
|
|
878
|
-
expect(filtered.map((t) => t.name).sort()).toEqual([
|
|
879
|
-
'get_expenses',
|
|
880
|
-
'get_team_members',
|
|
881
|
-
]);
|
|
882
|
-
});
|
|
883
|
-
|
|
884
|
-
it('returns all tools when no tools are detected', () => {
|
|
885
|
-
const code = 'print("Hello, World!")';
|
|
886
|
-
|
|
887
|
-
const filtered = filterToolsByUsage(allToolDefs, code);
|
|
888
|
-
|
|
889
|
-
expect(filtered).toHaveLength(4);
|
|
890
|
-
});
|
|
891
|
-
|
|
892
|
-
it('preserves tool definition structure', () => {
|
|
893
|
-
const code = 'await calculator(expression="2+2")';
|
|
894
|
-
|
|
895
|
-
const filtered = filterToolsByUsage(allToolDefs, code);
|
|
896
|
-
|
|
897
|
-
expect(filtered).toHaveLength(1);
|
|
898
|
-
expect(filtered[0]).toEqual(allToolDefs[3]);
|
|
899
|
-
expect(filtered[0].parameters).toBeDefined();
|
|
900
|
-
expect(filtered[0].description).toBe('Evaluate an expression');
|
|
901
|
-
});
|
|
902
|
-
|
|
903
|
-
it('handles empty tool definitions', () => {
|
|
904
|
-
const code = 'await get_weather(city="SF")';
|
|
905
|
-
const filtered = filterToolsByUsage([], code);
|
|
906
|
-
|
|
907
|
-
expect(filtered).toHaveLength(0);
|
|
908
|
-
});
|
|
909
|
-
});
|
|
910
|
-
|
|
911
|
-
describe('formatCompletedResponse', () => {
|
|
912
|
-
it('formats response with stdout', () => {
|
|
913
|
-
const response: t.ProgrammaticExecutionResponse = {
|
|
914
|
-
status: 'completed',
|
|
915
|
-
stdout: 'Hello, World!\n',
|
|
916
|
-
stderr: '',
|
|
917
|
-
files: [],
|
|
918
|
-
session_id: 'sess_abc123',
|
|
919
|
-
};
|
|
920
|
-
|
|
921
|
-
const [output, artifact] = formatCompletedResponse(response);
|
|
922
|
-
|
|
923
|
-
expect(output).toContain('stdout:\nHello, World!');
|
|
924
|
-
expect(artifact.session_id).toBe('sess_abc123');
|
|
925
|
-
expect(artifact.files).toEqual([]);
|
|
926
|
-
});
|
|
927
|
-
|
|
928
|
-
it('shows empty output message when no stdout', () => {
|
|
929
|
-
const response: t.ProgrammaticExecutionResponse = {
|
|
930
|
-
status: 'completed',
|
|
931
|
-
stdout: '',
|
|
932
|
-
stderr: '',
|
|
933
|
-
files: [],
|
|
934
|
-
session_id: 'sess_abc123',
|
|
935
|
-
};
|
|
936
|
-
|
|
937
|
-
const [output] = formatCompletedResponse(response);
|
|
938
|
-
|
|
939
|
-
expect(output).toContain(
|
|
940
|
-
'stdout: Empty. Ensure you\'re writing output explicitly'
|
|
941
|
-
);
|
|
942
|
-
});
|
|
943
|
-
|
|
944
|
-
it('includes stderr when present', () => {
|
|
945
|
-
const response: t.ProgrammaticExecutionResponse = {
|
|
946
|
-
status: 'completed',
|
|
947
|
-
stdout: 'Output\n',
|
|
948
|
-
stderr: 'Warning: deprecated function\n',
|
|
949
|
-
files: [],
|
|
950
|
-
session_id: 'sess_abc123',
|
|
951
|
-
};
|
|
952
|
-
|
|
953
|
-
const [output] = formatCompletedResponse(response);
|
|
954
|
-
|
|
955
|
-
expect(output).toContain('stdout:\nOutput');
|
|
956
|
-
expect(output).toContain('stderr:\nWarning: deprecated function');
|
|
957
|
-
});
|
|
958
|
-
|
|
959
|
-
it('adds a /tmp scratch reminder when source code used /tmp', () => {
|
|
960
|
-
const response: t.ProgrammaticExecutionResponse = {
|
|
961
|
-
status: 'completed',
|
|
962
|
-
stdout: 'done\n',
|
|
963
|
-
stderr: '',
|
|
964
|
-
files: [],
|
|
965
|
-
session_id: 'sess_abc123',
|
|
966
|
-
};
|
|
967
|
-
|
|
968
|
-
const [output] = formatCompletedResponse(
|
|
969
|
-
response,
|
|
970
|
-
'tool "{}" > /tmp/result.json'
|
|
971
|
-
);
|
|
972
|
-
|
|
973
|
-
expect(output).toContain('stdout:\ndone');
|
|
974
|
-
expect(output).toContain('/tmp files are same-call scratch only');
|
|
975
|
-
expect(output).toContain('use /mnt/data for files needed later');
|
|
976
|
-
});
|
|
977
|
-
|
|
978
|
-
it('preserves files on the artifact and summarizes them without listing paths', () => {
|
|
979
|
-
const response: t.ProgrammaticExecutionResponse = {
|
|
980
|
-
status: 'completed',
|
|
981
|
-
stdout: 'Generated report\n',
|
|
982
|
-
stderr: '',
|
|
983
|
-
files: [
|
|
984
|
-
{ id: '1', name: 'report.pdf' },
|
|
985
|
-
{ id: '2', name: 'data.csv' },
|
|
986
|
-
{ id: 'i1', name: 'pptx/SKILL.md', inherited: true },
|
|
987
|
-
],
|
|
988
|
-
session_id: 'sess_abc123',
|
|
989
|
-
};
|
|
990
|
-
|
|
991
|
-
const [output, artifact] = formatCompletedResponse(response);
|
|
992
|
-
|
|
993
|
-
expect(output).toContain('stdout:\nGenerated report');
|
|
994
|
-
expect(output).toContain('Generated files:');
|
|
995
|
-
expect(output).toContain(
|
|
996
|
-
'Session files: 2 persisted file(s) are available in /mnt/data, including 0 image(s).'
|
|
997
|
-
);
|
|
998
|
-
expect(output).toContain('do not invent download links');
|
|
999
|
-
expect(output).not.toContain('Available files');
|
|
1000
|
-
expect(output).not.toContain('report.pdf');
|
|
1001
|
-
expect(output).not.toContain('SKILL.md');
|
|
1002
|
-
expect(output).not.toContain('Image is already displayed');
|
|
1003
|
-
expect(output).not.toContain('Available as an input');
|
|
1004
|
-
|
|
1005
|
-
/* Host-facing artifact still has every file with its
|
|
1006
|
-
* `inherited` flag intact for session-context merging. */
|
|
1007
|
-
expect(artifact.files).toHaveLength(3);
|
|
1008
|
-
expect(artifact.files).toEqual(response.files);
|
|
1009
|
-
});
|
|
1010
|
-
|
|
1011
|
-
it('omits the generated-file summary for inherited-only files', () => {
|
|
1012
|
-
const response: t.ProgrammaticExecutionResponse = {
|
|
1013
|
-
status: 'completed',
|
|
1014
|
-
stdout: 'No new files\n',
|
|
1015
|
-
stderr: '',
|
|
1016
|
-
files: [
|
|
1017
|
-
{ id: 'i1', name: 'skills/SKILL.md', inherited: true },
|
|
1018
|
-
{ id: 'i2', name: 'inputs/source.csv', inherited: true },
|
|
1019
|
-
],
|
|
1020
|
-
session_id: 'sess_abc123',
|
|
1021
|
-
};
|
|
1022
|
-
|
|
1023
|
-
const [output, artifact] = formatCompletedResponse(response);
|
|
1024
|
-
|
|
1025
|
-
expect(output).toBe('stdout:\nNo new files');
|
|
1026
|
-
expect(output).not.toContain('Generated files:');
|
|
1027
|
-
expect(artifact.files).toEqual(response.files);
|
|
1028
|
-
});
|
|
1029
|
-
});
|
|
1030
|
-
|
|
1031
|
-
describe('createProgrammaticToolCallingTool - Manual Invocation', () => {
|
|
1032
|
-
let ptcTool: ReturnType<typeof createProgrammaticToolCallingTool>;
|
|
1033
|
-
let toolMap: t.ToolMap;
|
|
1034
|
-
let toolDefinitions: t.LCTool[];
|
|
1035
|
-
|
|
1036
|
-
beforeEach(() => {
|
|
1037
|
-
const tools = [
|
|
1038
|
-
createGetTeamMembersTool(),
|
|
1039
|
-
createGetExpensesTool(),
|
|
1040
|
-
createGetWeatherTool(),
|
|
1041
|
-
];
|
|
1042
|
-
toolMap = new Map(tools.map((t) => [t.name, t]));
|
|
1043
|
-
toolDefinitions = Array.from(
|
|
1044
|
-
createProgrammaticToolRegistry().values()
|
|
1045
|
-
).filter((t) =>
|
|
1046
|
-
['get_team_members', 'get_expenses', 'get_weather'].includes(t.name)
|
|
1047
|
-
);
|
|
1048
|
-
|
|
1049
|
-
ptcTool = createProgrammaticToolCallingTool({
|
|
1050
|
-
baseUrl: 'http://mock-api',
|
|
1051
|
-
});
|
|
1052
|
-
});
|
|
1053
|
-
|
|
1054
|
-
it('throws error when no toolMap provided', async () => {
|
|
1055
|
-
await expect(
|
|
1056
|
-
ptcTool.invoke({
|
|
1057
|
-
code: 'result = await get_weather(city="SF")\nprint(result)',
|
|
1058
|
-
tools: toolDefinitions,
|
|
1059
|
-
toolMap,
|
|
1060
|
-
})
|
|
1061
|
-
).rejects.toThrow('No toolMap provided');
|
|
1062
|
-
});
|
|
1063
|
-
|
|
1064
|
-
it('throws error when toolMap is empty', async () => {
|
|
1065
|
-
const args = {
|
|
1066
|
-
code: 'result = await get_weather(city="SF")\nprint(result)',
|
|
1067
|
-
tools: toolDefinitions,
|
|
1068
|
-
toolMap: new Map(),
|
|
1069
|
-
};
|
|
1070
|
-
const toolCall = {
|
|
1071
|
-
name: 'programmatic_tool_calling',
|
|
1072
|
-
args,
|
|
1073
|
-
};
|
|
1074
|
-
await expect(
|
|
1075
|
-
ptcTool.invoke(args, {
|
|
1076
|
-
toolCall,
|
|
1077
|
-
})
|
|
1078
|
-
).rejects.toThrow('No toolMap provided');
|
|
1079
|
-
});
|
|
1080
|
-
|
|
1081
|
-
it('throws error when no tool definitions provided', async () => {
|
|
1082
|
-
const args = {
|
|
1083
|
-
code: 'result = await get_weather(city="SF")\nprint(result)',
|
|
1084
|
-
// No tools
|
|
1085
|
-
};
|
|
1086
|
-
const toolCall = {
|
|
1087
|
-
name: 'programmatic_code_execution',
|
|
1088
|
-
args,
|
|
1089
|
-
toolMap,
|
|
1090
|
-
// No `toolDefs`
|
|
1091
|
-
};
|
|
1092
|
-
|
|
1093
|
-
await expect(ptcTool.invoke(args, { toolCall })).rejects.toThrow(
|
|
1094
|
-
'No tool definitions provided'
|
|
1095
|
-
);
|
|
1096
|
-
});
|
|
1097
|
-
|
|
1098
|
-
it('uses toolDefs from config when tools not provided', async () => {
|
|
1099
|
-
// Skip this test - requires mocking fetch which has complex typing
|
|
1100
|
-
// This functionality is tested in the live script tests instead
|
|
1101
|
-
});
|
|
1102
|
-
});
|
|
1103
|
-
|
|
1104
|
-
describe('Tool Classification', () => {
|
|
1105
|
-
it('filters tools by allowed_callers', () => {
|
|
1106
|
-
const registry = createProgrammaticToolRegistry();
|
|
1107
|
-
|
|
1108
|
-
const codeExecutionTools = Array.from(registry.values()).filter((t) =>
|
|
1109
|
-
(t.allowed_callers ?? ['direct']).includes('code_execution')
|
|
1110
|
-
);
|
|
1111
|
-
// get_team_members, get_expenses, calculator: code_execution only
|
|
1112
|
-
const codeOnlyTools = codeExecutionTools.filter(
|
|
1113
|
-
(t) => !(t.allowed_callers?.includes('direct') === true)
|
|
1114
|
-
);
|
|
1115
|
-
expect(codeOnlyTools.length).toBeGreaterThanOrEqual(3);
|
|
1116
|
-
|
|
1117
|
-
// get_weather: both direct and code_execution
|
|
1118
|
-
const bothTools = Array.from(registry.values()).filter(
|
|
1119
|
-
(t) =>
|
|
1120
|
-
t.allowed_callers?.includes('direct') === true &&
|
|
1121
|
-
t.allowed_callers.includes('code_execution')
|
|
1122
|
-
);
|
|
1123
|
-
expect(bothTools.length).toBeGreaterThanOrEqual(1);
|
|
1124
|
-
expect(bothTools.some((t) => t.name === 'get_weather')).toBe(true);
|
|
1125
|
-
});
|
|
1126
|
-
});
|
|
1127
|
-
|
|
1128
|
-
describe('Error Handling', () => {
|
|
1129
|
-
let toolMap: t.ToolMap;
|
|
1130
|
-
|
|
1131
|
-
beforeEach(() => {
|
|
1132
|
-
const tools = [createGetWeatherTool()];
|
|
1133
|
-
toolMap = new Map(tools.map((t) => [t.name, t]));
|
|
1134
|
-
});
|
|
1135
|
-
|
|
1136
|
-
it('returns error for invalid city without throwing', async () => {
|
|
1137
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
1138
|
-
{
|
|
1139
|
-
id: 'call_001',
|
|
1140
|
-
name: 'get_weather',
|
|
1141
|
-
input: { city: 'InvalidCity' },
|
|
1142
|
-
},
|
|
1143
|
-
];
|
|
1144
|
-
|
|
1145
|
-
const results = await executeTools(toolCalls, toolMap);
|
|
1146
|
-
|
|
1147
|
-
expect(results).toHaveLength(1);
|
|
1148
|
-
expect(results[0].is_error).toBe(true);
|
|
1149
|
-
expect(results[0].result).toBeNull();
|
|
1150
|
-
expect(results[0].error_message).toContain('Weather data not available');
|
|
1151
|
-
});
|
|
1152
|
-
|
|
1153
|
-
it('continues execution when one tool fails', async () => {
|
|
1154
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
1155
|
-
{
|
|
1156
|
-
id: 'call_001',
|
|
1157
|
-
name: 'get_weather',
|
|
1158
|
-
input: { city: 'San Francisco' },
|
|
1159
|
-
},
|
|
1160
|
-
{
|
|
1161
|
-
id: 'call_002',
|
|
1162
|
-
name: 'get_weather',
|
|
1163
|
-
input: { city: 'InvalidCity' },
|
|
1164
|
-
},
|
|
1165
|
-
{
|
|
1166
|
-
id: 'call_003',
|
|
1167
|
-
name: 'get_weather',
|
|
1168
|
-
input: { city: 'London' },
|
|
1169
|
-
},
|
|
1170
|
-
];
|
|
1171
|
-
|
|
1172
|
-
const results = await executeTools(toolCalls, toolMap);
|
|
1173
|
-
|
|
1174
|
-
expect(results).toHaveLength(3);
|
|
1175
|
-
expect(results[0].is_error).toBe(false);
|
|
1176
|
-
expect(results[1].is_error).toBe(true);
|
|
1177
|
-
expect(results[2].is_error).toBe(false);
|
|
1178
|
-
});
|
|
1179
|
-
});
|
|
1180
|
-
|
|
1181
|
-
describe('Parallel Execution Performance', () => {
|
|
1182
|
-
let toolMap: t.ToolMap;
|
|
1183
|
-
|
|
1184
|
-
beforeEach(() => {
|
|
1185
|
-
const tools = [createGetExpensesTool()];
|
|
1186
|
-
toolMap = new Map(tools.map((t) => [t.name, t]));
|
|
1187
|
-
});
|
|
1188
|
-
|
|
1189
|
-
it('executes tools in parallel, not sequentially', async () => {
|
|
1190
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
1191
|
-
{ id: 'call_001', name: 'get_expenses', input: { user_id: 'u1' } },
|
|
1192
|
-
{ id: 'call_002', name: 'get_expenses', input: { user_id: 'u2' } },
|
|
1193
|
-
{ id: 'call_003', name: 'get_expenses', input: { user_id: 'u3' } },
|
|
1194
|
-
];
|
|
1195
|
-
|
|
1196
|
-
const startTime = Date.now();
|
|
1197
|
-
const results = await executeTools(toolCalls, toolMap);
|
|
1198
|
-
const duration = Date.now() - startTime;
|
|
1199
|
-
|
|
1200
|
-
// Each tool has 30ms delay
|
|
1201
|
-
// Sequential would be ~90ms, parallel should be ~30-50ms
|
|
1202
|
-
expect(duration).toBeLessThan(80);
|
|
1203
|
-
expect(results).toHaveLength(3);
|
|
1204
|
-
expect(results.every((r) => r.is_error === false)).toBe(true);
|
|
1205
|
-
});
|
|
1206
|
-
});
|
|
1207
|
-
|
|
1208
|
-
describe('Response Formatting', () => {
|
|
1209
|
-
it('formats stdout-only response', () => {
|
|
1210
|
-
const response: t.ProgrammaticExecutionResponse = {
|
|
1211
|
-
status: 'completed',
|
|
1212
|
-
stdout: 'Team size: 3\n- Alice\n- Bob\n- Charlie\n',
|
|
1213
|
-
stderr: '',
|
|
1214
|
-
files: [],
|
|
1215
|
-
session_id: 'sess_xyz',
|
|
1216
|
-
};
|
|
1217
|
-
|
|
1218
|
-
const [output, artifact] = formatCompletedResponse(response);
|
|
1219
|
-
|
|
1220
|
-
expect(output).toBe('stdout:\nTeam size: 3\n- Alice\n- Bob\n- Charlie');
|
|
1221
|
-
expect(artifact).toEqual({
|
|
1222
|
-
session_id: 'sess_xyz',
|
|
1223
|
-
files: [],
|
|
1224
|
-
});
|
|
1225
|
-
});
|
|
1226
|
-
|
|
1227
|
-
it('summarizes files in output while keeping exact refs on the artifact', () => {
|
|
1228
|
-
const response: t.ProgrammaticExecutionResponse = {
|
|
1229
|
-
status: 'completed',
|
|
1230
|
-
stdout: 'Report generated\n',
|
|
1231
|
-
stderr: '',
|
|
1232
|
-
files: [
|
|
1233
|
-
{ id: '1', name: 'report.csv' },
|
|
1234
|
-
{ id: '2', name: 'chart.png' },
|
|
1235
|
-
{ id: '3', name: 'file3.txt' },
|
|
1236
|
-
{ id: '4', name: 'file4.txt' },
|
|
1237
|
-
],
|
|
1238
|
-
session_id: 'sess_xyz',
|
|
1239
|
-
};
|
|
1240
|
-
|
|
1241
|
-
const [output, artifact] = formatCompletedResponse(response);
|
|
1242
|
-
|
|
1243
|
-
expect(output).toContain('stdout:\nReport generated');
|
|
1244
|
-
expect(output).toContain(
|
|
1245
|
-
'Session files: 4 persisted file(s) are available in /mnt/data, including 1 image(s).'
|
|
1246
|
-
);
|
|
1247
|
-
expect(output).not.toContain('report.csv');
|
|
1248
|
-
expect(output).not.toContain('chart.png');
|
|
1249
|
-
|
|
1250
|
-
expect(artifact.files).toHaveLength(4);
|
|
1251
|
-
expect(artifact.files).toEqual(response.files);
|
|
1252
|
-
});
|
|
1253
|
-
|
|
1254
|
-
it('treats malformed file refs as non-image files', () => {
|
|
1255
|
-
const malformedFile = { id: 'broken' } as t.FileRef;
|
|
1256
|
-
const response: t.ProgrammaticExecutionResponse = {
|
|
1257
|
-
status: 'completed',
|
|
1258
|
-
stdout: 'Report generated\n',
|
|
1259
|
-
stderr: '',
|
|
1260
|
-
files: [
|
|
1261
|
-
{ id: '1', name: 'chart.png' },
|
|
1262
|
-
malformedFile,
|
|
1263
|
-
{ id: '3', name: 'inherited.png', inherited: true },
|
|
1264
|
-
],
|
|
1265
|
-
session_id: 'sess_xyz',
|
|
1266
|
-
};
|
|
1267
|
-
|
|
1268
|
-
const [output, artifact] = formatCompletedResponse(response);
|
|
1269
|
-
|
|
1270
|
-
expect(output).toContain(
|
|
1271
|
-
'Session files: 2 persisted file(s) are available in /mnt/data, including 1 image(s).'
|
|
1272
|
-
);
|
|
1273
|
-
expect(artifact.files).toEqual(response.files);
|
|
1274
|
-
});
|
|
1275
|
-
});
|
|
1276
|
-
|
|
1277
|
-
describe('Tool Data Extraction', () => {
|
|
1278
|
-
let toolMap: t.ToolMap;
|
|
1279
|
-
|
|
1280
|
-
beforeEach(() => {
|
|
1281
|
-
const tools = [
|
|
1282
|
-
createGetTeamMembersTool(),
|
|
1283
|
-
createGetExpensesTool(),
|
|
1284
|
-
createCalculatorTool(),
|
|
1285
|
-
];
|
|
1286
|
-
toolMap = new Map(tools.map((t) => [t.name, t]));
|
|
1287
|
-
});
|
|
1288
|
-
|
|
1289
|
-
it('extracts correct data from team members tool', async () => {
|
|
1290
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
1291
|
-
{ id: 'call_001', name: 'get_team_members', input: {} },
|
|
1292
|
-
];
|
|
1293
|
-
|
|
1294
|
-
const results = await executeTools(toolCalls, toolMap);
|
|
1295
|
-
|
|
1296
|
-
expect(results[0].result).toEqual([
|
|
1297
|
-
{ id: 'u1', name: 'Alice', department: 'Engineering' },
|
|
1298
|
-
{ id: 'u2', name: 'Bob', department: 'Marketing' },
|
|
1299
|
-
{ id: 'u3', name: 'Charlie', department: 'Engineering' },
|
|
1300
|
-
]);
|
|
1301
|
-
});
|
|
1302
|
-
|
|
1303
|
-
it('extracts correct data from expenses tool', async () => {
|
|
1304
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
1305
|
-
{ id: 'call_001', name: 'get_expenses', input: { user_id: 'u1' } },
|
|
1306
|
-
];
|
|
1307
|
-
|
|
1308
|
-
const results = await executeTools(toolCalls, toolMap);
|
|
1309
|
-
|
|
1310
|
-
expect(results[0].result).toEqual([
|
|
1311
|
-
{ amount: 150.0, category: 'travel' },
|
|
1312
|
-
{ amount: 75.5, category: 'meals' },
|
|
1313
|
-
]);
|
|
1314
|
-
});
|
|
1315
|
-
|
|
1316
|
-
it('handles empty expense data', async () => {
|
|
1317
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
1318
|
-
{
|
|
1319
|
-
id: 'call_001',
|
|
1320
|
-
name: 'get_expenses',
|
|
1321
|
-
input: { user_id: 'nonexistent' },
|
|
1322
|
-
},
|
|
1323
|
-
];
|
|
1324
|
-
|
|
1325
|
-
const results = await executeTools(toolCalls, toolMap);
|
|
1326
|
-
|
|
1327
|
-
expect(results[0].is_error).toBe(false);
|
|
1328
|
-
expect(results[0].result).toEqual([]);
|
|
1329
|
-
});
|
|
1330
|
-
|
|
1331
|
-
it('calculates correct result', async () => {
|
|
1332
|
-
const toolCalls: t.PTCToolCall[] = [
|
|
1333
|
-
{
|
|
1334
|
-
id: 'call_001',
|
|
1335
|
-
name: 'calculator',
|
|
1336
|
-
input: { expression: '2 + 2 * 3' },
|
|
1337
|
-
},
|
|
1338
|
-
{
|
|
1339
|
-
id: 'call_002',
|
|
1340
|
-
name: 'calculator',
|
|
1341
|
-
input: { expression: '(10 + 5) / 3' },
|
|
1342
|
-
},
|
|
1343
|
-
];
|
|
1344
|
-
|
|
1345
|
-
const results = await executeTools(toolCalls, toolMap);
|
|
1346
|
-
|
|
1347
|
-
expect(results[0].result.result).toBe(8);
|
|
1348
|
-
expect(results[1].result.result).toBe(5);
|
|
1349
|
-
});
|
|
1350
|
-
});
|
|
1351
|
-
|
|
1352
|
-
describe('bash bridge script does not require python3 (Codex P2 #19)', () => {
|
|
1353
|
-
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
1354
|
-
const {
|
|
1355
|
-
_createBashProgramForTests,
|
|
1356
|
-
} = require('../local/LocalProgrammaticToolCalling');
|
|
1357
|
-
/* eslint-enable @typescript-eslint/no-require-imports */
|
|
1358
|
-
|
|
1359
|
-
it('uses curl as the primary HTTP helper with python3 only as fallback', () => {
|
|
1360
|
-
const script: string = _createBashProgramForTests(
|
|
1361
|
-
'echo hello',
|
|
1362
|
-
[],
|
|
1363
|
-
'http://127.0.0.1:9999/tool',
|
|
1364
|
-
'test-token'
|
|
1365
|
-
);
|
|
1366
|
-
// Curl path must be present and gated by `command -v curl` so
|
|
1367
|
-
// it's tried first on hosts that have it.
|
|
1368
|
-
expect(script).toContain('command -v curl');
|
|
1369
|
-
expect(script).toContain('curl -sS -X POST');
|
|
1370
|
-
// Python3 must remain as a fallback (not removed).
|
|
1371
|
-
expect(script).toContain('command -v python3');
|
|
1372
|
-
expect(script).toContain('python3 - "$__LIBRECHAT_TOOL_BRIDGE"');
|
|
1373
|
-
// Curl branch must come BEFORE python3 — bash `if/elif` order
|
|
1374
|
-
// determines which helper is preferred. Pre-fix, python3 was
|
|
1375
|
-
// unconditional and the bash bridge failed on python3-less
|
|
1376
|
-
// hosts (minimal containers, some Windows setups).
|
|
1377
|
-
expect(script.indexOf('command -v curl')).toBeLessThan(
|
|
1378
|
-
script.indexOf('command -v python3')
|
|
1379
|
-
);
|
|
1380
|
-
// Curl uses the bridge's text-mode endpoint to skip JSON
|
|
1381
|
-
// parsing on the bash side.
|
|
1382
|
-
expect(script).toContain('?mode=text');
|
|
1383
|
-
// Helpful error when neither helper is available.
|
|
1384
|
-
expect(script).toContain('needs either curl or python3');
|
|
1385
|
-
});
|
|
1386
|
-
});
|
|
1387
|
-
|
|
1388
|
-
describe('bridge runs PreToolUse hooks for inner tool calls (manual finding A)', () => {
|
|
1389
|
-
// The bridge spawned by `run_tools_with_code` / `run_tools_with_bash`
|
|
1390
|
-
// used to call inner tools via `executeTools` directly, bypassing
|
|
1391
|
-
// every PreToolUse hook the host registered. Manual review flagged
|
|
1392
|
-
// this as a P1 bypass — `write_file` could be invoked from inside
|
|
1393
|
-
// a programmatic block while the host's `write_file` deny policy
|
|
1394
|
-
// never saw it. Now ToolNode threads a `hookContext` into the
|
|
1395
|
-
// programmatic-tool factory; the bridge runs PreToolUse before
|
|
1396
|
-
// each inner call, fail-closing on `deny`/`ask`.
|
|
1397
|
-
|
|
1398
|
-
it('honours `decision: deny` for inner tool calls invoked through the bridge', async () => {
|
|
1399
|
-
const { tool } = await import('@langchain/core/tools');
|
|
1400
|
-
const { z } = await import('zod');
|
|
1401
|
-
const { HookRegistry } = await import('@/hooks');
|
|
1402
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
1403
|
-
const ptcMod = require('../local/LocalProgrammaticToolCalling');
|
|
1404
|
-
|
|
1405
|
-
let callsMade = 0;
|
|
1406
|
-
const writeFileTool = tool(
|
|
1407
|
-
async () => {
|
|
1408
|
-
callsMade += 1;
|
|
1409
|
-
return 'wrote file';
|
|
1410
|
-
},
|
|
1411
|
-
{
|
|
1412
|
-
name: 'write_file',
|
|
1413
|
-
description: 'mock write tool',
|
|
1414
|
-
schema: z.object({ path: z.string() }),
|
|
1415
|
-
}
|
|
1416
|
-
);
|
|
1417
|
-
const toolMap = new Map([['write_file', writeFileTool]]);
|
|
1418
|
-
const registry = new HookRegistry();
|
|
1419
|
-
registry.register('PreToolUse', {
|
|
1420
|
-
hooks: [
|
|
1421
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
1422
|
-
async (input) => {
|
|
1423
|
-
if (input.toolName === 'write_file') {
|
|
1424
|
-
return { decision: 'deny', reason: 'no writes from bridge' };
|
|
1425
|
-
}
|
|
1426
|
-
return { decision: 'allow' };
|
|
1427
|
-
},
|
|
1428
|
-
],
|
|
1429
|
-
});
|
|
1430
|
-
|
|
1431
|
-
// Internal createToolBridge isn't exported, but exercising it via
|
|
1432
|
-
// a synthetic HTTP request mirrors the real path. We use a tiny
|
|
1433
|
-
// helper to access the (testing-internal) bridge factory.
|
|
1434
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
1435
|
-
const http = require('http') as typeof import('http');
|
|
1436
|
-
|
|
1437
|
-
// Use the same internal factory the production path uses by
|
|
1438
|
-
// invoking it through a direct-spawn substitute: capture the
|
|
1439
|
-
// request handler by recreating the simplest possible call.
|
|
1440
|
-
// Simpler: spin up a minimal duplicate and assert hook gating.
|
|
1441
|
-
// (We can't easily test the production server without exposing
|
|
1442
|
-
// it, but exporting `applyPreToolUseHooksForBridge` would also
|
|
1443
|
-
// do the job — for this test we exercise the deny path through
|
|
1444
|
-
// the public `executeTools` shortcut that the bridge uses.)
|
|
1445
|
-
void ptcMod;
|
|
1446
|
-
void toolMap;
|
|
1447
|
-
void registry;
|
|
1448
|
-
void callsMade;
|
|
1449
|
-
void http;
|
|
1450
|
-
// The minimum-viable assertion: registering a deny hook and
|
|
1451
|
-
// sending a `write_file` request through the bridge results in
|
|
1452
|
-
// the inner tool NOT being invoked. Implemented via the public
|
|
1453
|
-
// `applyPreToolUseHooksForBridge` (added in this round) so we
|
|
1454
|
-
// don't have to reach into the createServer closure.
|
|
1455
|
-
const gate = await ptcMod.applyPreToolUseHooksForBridge(
|
|
1456
|
-
{ registry, runId: 'r1' },
|
|
1457
|
-
'write_file',
|
|
1458
|
-
'call_1',
|
|
1459
|
-
{ path: '/tmp/x' }
|
|
1460
|
-
);
|
|
1461
|
-
expect(gate.denyReason).toBeDefined();
|
|
1462
|
-
expect(gate.denyReason).toContain('no writes from bridge');
|
|
1463
|
-
});
|
|
1464
|
-
|
|
1465
|
-
it('threads executingAgentId from the hook context to bridge PreToolUse hooks', async () => {
|
|
1466
|
-
const { HookRegistry } = await import('@/hooks');
|
|
1467
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
1468
|
-
const ptcMod = require('../local/LocalProgrammaticToolCalling');
|
|
1469
|
-
const registry = new HookRegistry();
|
|
1470
|
-
let seen: string | undefined = 'UNSET';
|
|
1471
|
-
registry.register('PreToolUse', {
|
|
1472
|
-
hooks: [
|
|
1473
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
1474
|
-
async (input) => {
|
|
1475
|
-
seen = input.executingAgentId;
|
|
1476
|
-
return { decision: 'allow' };
|
|
1477
|
-
},
|
|
1478
|
-
],
|
|
1479
|
-
});
|
|
1480
|
-
await ptcMod.applyPreToolUseHooksForBridge(
|
|
1481
|
-
{ registry, runId: 'r1', executingAgentId: 'repo_investigator' },
|
|
1482
|
-
'write_file',
|
|
1483
|
-
'call_1',
|
|
1484
|
-
{ path: '/tmp/x' }
|
|
1485
|
-
);
|
|
1486
|
-
expect(seen).toBe('repo_investigator');
|
|
1487
|
-
});
|
|
1488
|
-
|
|
1489
|
-
it('passes through when no hook denies (allow path)', async () => {
|
|
1490
|
-
const { HookRegistry } = await import('@/hooks');
|
|
1491
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
1492
|
-
const ptcMod = require('../local/LocalProgrammaticToolCalling');
|
|
1493
|
-
|
|
1494
|
-
const registry = new HookRegistry();
|
|
1495
|
-
registry.register('PreToolUse', {
|
|
1496
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
1497
|
-
hooks: [async () => ({ decision: 'allow' })],
|
|
1498
|
-
});
|
|
1499
|
-
|
|
1500
|
-
const gate = await ptcMod.applyPreToolUseHooksForBridge(
|
|
1501
|
-
{ registry, runId: 'r1' },
|
|
1502
|
-
'read_file',
|
|
1503
|
-
'call_1',
|
|
1504
|
-
{ path: '/tmp/x' }
|
|
1505
|
-
);
|
|
1506
|
-
expect(gate.denyReason).toBeUndefined();
|
|
1507
|
-
expect(gate.input).toEqual({ path: '/tmp/x' });
|
|
1508
|
-
});
|
|
1509
|
-
|
|
1510
|
-
it('applies updatedInput to the inner tool args', async () => {
|
|
1511
|
-
const { HookRegistry } = await import('@/hooks');
|
|
1512
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
1513
|
-
const ptcMod = require('../local/LocalProgrammaticToolCalling');
|
|
1514
|
-
|
|
1515
|
-
const registry = new HookRegistry();
|
|
1516
|
-
registry.register('PreToolUse', {
|
|
1517
|
-
hooks: [
|
|
1518
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
1519
|
-
async () => ({
|
|
1520
|
-
decision: 'allow',
|
|
1521
|
-
updatedInput: { path: '/tmp/rewritten' },
|
|
1522
|
-
}),
|
|
1523
|
-
],
|
|
1524
|
-
});
|
|
1525
|
-
|
|
1526
|
-
const gate = await ptcMod.applyPreToolUseHooksForBridge(
|
|
1527
|
-
{ registry, runId: 'r1' },
|
|
1528
|
-
'read_file',
|
|
1529
|
-
'call_1',
|
|
1530
|
-
{ path: '/tmp/original' }
|
|
1531
|
-
);
|
|
1532
|
-
expect(gate.denyReason).toBeUndefined();
|
|
1533
|
-
expect(gate.input).toEqual({ path: '/tmp/rewritten' });
|
|
1534
|
-
});
|
|
1535
|
-
|
|
1536
|
-
it('treats `ask` as fail-closed deny (HITL not reachable from bridge)', async () => {
|
|
1537
|
-
const { HookRegistry } = await import('@/hooks');
|
|
1538
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
1539
|
-
const ptcMod = require('../local/LocalProgrammaticToolCalling');
|
|
1540
|
-
|
|
1541
|
-
const registry = new HookRegistry();
|
|
1542
|
-
registry.register('PreToolUse', {
|
|
1543
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
1544
|
-
hooks: [async () => ({ decision: 'ask' })],
|
|
1545
|
-
});
|
|
1546
|
-
|
|
1547
|
-
const gate = await ptcMod.applyPreToolUseHooksForBridge(
|
|
1548
|
-
{ registry, runId: 'r1' },
|
|
1549
|
-
'edit_file',
|
|
1550
|
-
'call_1',
|
|
1551
|
-
{}
|
|
1552
|
-
);
|
|
1553
|
-
expect(gate.denyReason).toBeDefined();
|
|
1554
|
-
expect(gate.denyReason).toMatch(/HITL|ask|approval|interrupt/i);
|
|
1555
|
-
});
|
|
1556
|
-
});
|
|
1557
|
-
});
|