@librechat/agents 3.4.7 → 3.5.1
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/package.json +35 -32
- package/dist/types/agents/__tests__/promptCacheLiveHelpers.d.ts +0 -52
- package/dist/types/test/mockTools.d.ts +0 -28
- package/dist/types/utils/__tests__/fixtures/contextOverflowSignatures.d.ts +0 -40
- 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,1982 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Regression tests for the streamed tool-argument circuit breaker.
|
|
3
|
-
*
|
|
4
|
-
* Incident: a model streamed a single malformed tool-call argument (a SQL
|
|
5
|
-
* query) to 149,923 characters over 26 minutes, never completing it, until
|
|
6
|
-
* the 64k output-token ceiling ended the run. Nothing bounded a single tool
|
|
7
|
-
* call's streamed argument growth mid-flight.
|
|
8
|
-
*
|
|
9
|
-
* The guard lives on the SDK stream dispatch path: `ChatModelStreamHandler`
|
|
10
|
-
* enforces `Graph.streamLimits` on every streamed chunk event and throws
|
|
11
|
-
* `StreamLimitExceededError` out of the run's `streamEvents` loop, which
|
|
12
|
-
* tears down the in-flight provider request (see the mid-flight halt notes
|
|
13
|
-
* in `Run.processStream`).
|
|
14
|
-
*/
|
|
15
|
-
import { describe, it, expect, jest } from '@jest/globals';
|
|
16
|
-
import type { AgentContext } from '@/agents/AgentContext';
|
|
17
|
-
import type { StandardGraph } from '@/graphs';
|
|
18
|
-
import type * as t from '@/types';
|
|
19
|
-
import {
|
|
20
|
-
STREAMED_TOOL_CALL_ADAPTER_METADATA_KEY,
|
|
21
|
-
STREAMED_TOOL_CALL_SEAL_METADATA_KEY,
|
|
22
|
-
OPENAI_RESPONSES_STREAMED_TOOL_CALL_ADAPTER,
|
|
23
|
-
} from '@/tools/streamedToolCallSeals';
|
|
24
|
-
import {
|
|
25
|
-
DEFAULT_MAX_TOOL_CALL_ARG_BYTES,
|
|
26
|
-
STREAM_LIMIT_REDISPATCH_KEY,
|
|
27
|
-
STREAM_LIMIT_EPOCH_KEY,
|
|
28
|
-
StreamLimitExceededError,
|
|
29
|
-
enforceStreamLimitsForWireChunk,
|
|
30
|
-
resolveGenerationKey,
|
|
31
|
-
resolveStreamLimits,
|
|
32
|
-
} from '@/llm/streamLimits';
|
|
33
|
-
import { GraphEvents, Providers, StepTypes } from '@/common';
|
|
34
|
-
import { ChatModelStreamHandler } from '@/stream';
|
|
35
|
-
import { HandlerRegistry } from '@/events';
|
|
36
|
-
|
|
37
|
-
function createGraph(overrides: Partial<StandardGraph> = {}): StandardGraph {
|
|
38
|
-
const runSteps = new Map<string, t.RunStep>();
|
|
39
|
-
const stepIdsByKey = new Map<string, string>();
|
|
40
|
-
let stepCounter = 0;
|
|
41
|
-
|
|
42
|
-
const graph = {
|
|
43
|
-
config: {
|
|
44
|
-
configurable: { user_id: 'user_1' },
|
|
45
|
-
metadata: { run_id: 'run_1' },
|
|
46
|
-
},
|
|
47
|
-
eagerEventToolExecution: undefined,
|
|
48
|
-
eagerEventToolExecutions: new Map(),
|
|
49
|
-
eagerEventToolCallChunks: new Map(),
|
|
50
|
-
eagerEventToolSuppressions: new Set<string>(),
|
|
51
|
-
handlerRegistry: new HandlerRegistry(),
|
|
52
|
-
hookRegistry: undefined,
|
|
53
|
-
humanInTheLoop: undefined,
|
|
54
|
-
toolOutputReferences: undefined,
|
|
55
|
-
sessions: new Map(),
|
|
56
|
-
toolCallStepIds: new Map(),
|
|
57
|
-
messageIdsByStepKey: new Map(),
|
|
58
|
-
messageStepHasToolCalls: new Map(),
|
|
59
|
-
prelimMessageIdsByStepKey: new Map(),
|
|
60
|
-
getAgentContext: jest.fn(
|
|
61
|
-
(): Partial<AgentContext> => ({
|
|
62
|
-
provider: Providers.OPENAI,
|
|
63
|
-
reasoningKey: 'reasoning_content',
|
|
64
|
-
toolDefinitions: [],
|
|
65
|
-
graphTools: [],
|
|
66
|
-
agentId: 'agent_1',
|
|
67
|
-
})
|
|
68
|
-
),
|
|
69
|
-
getStepKey: jest.fn(() => 'step-key'),
|
|
70
|
-
getStepIdByKey: jest.fn((stepKey: string) => {
|
|
71
|
-
const stepId = stepIdsByKey.get(stepKey);
|
|
72
|
-
if (stepId == null) {
|
|
73
|
-
throw new Error('no current step');
|
|
74
|
-
}
|
|
75
|
-
return stepId;
|
|
76
|
-
}),
|
|
77
|
-
getRunStep: jest.fn((stepId: string) => runSteps.get(stepId)),
|
|
78
|
-
dispatchRunStep: jest.fn(async (stepKey: string, details: unknown) => {
|
|
79
|
-
const id = `step_${++stepCounter}`;
|
|
80
|
-
stepIdsByKey.set(stepKey, id);
|
|
81
|
-
runSteps.set(id, {
|
|
82
|
-
id,
|
|
83
|
-
type: (details as { type: t.RunStep['type'] }).type,
|
|
84
|
-
stepDetails: details as t.RunStep['stepDetails'],
|
|
85
|
-
} as t.RunStep);
|
|
86
|
-
return id;
|
|
87
|
-
}),
|
|
88
|
-
dispatchRunStepDelta: jest.fn(async () => undefined),
|
|
89
|
-
...overrides,
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
return graph as unknown as StandardGraph;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const generation = (step: number): Record<string, unknown> => ({
|
|
96
|
-
langgraph_checkpoint_ns: '',
|
|
97
|
-
langgraph_node: 'agent',
|
|
98
|
-
langgraph_step: step,
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
async function streamEvent(args: {
|
|
102
|
-
handler: ChatModelStreamHandler;
|
|
103
|
-
graph: StandardGraph;
|
|
104
|
-
chunk: Record<string, unknown>;
|
|
105
|
-
metadata?: Record<string, unknown>;
|
|
106
|
-
}): Promise<void> {
|
|
107
|
-
const { handler, graph, chunk, metadata } = args;
|
|
108
|
-
await handler.handle(
|
|
109
|
-
GraphEvents.CHAT_MODEL_STREAM,
|
|
110
|
-
{ chunk: chunk as unknown as t.StreamChunk },
|
|
111
|
-
metadata ?? {},
|
|
112
|
-
graph
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async function streamToolCallChunks(args: {
|
|
117
|
-
handler: ChatModelStreamHandler;
|
|
118
|
-
graph: StandardGraph;
|
|
119
|
-
chunks: Array<Record<string, unknown>>;
|
|
120
|
-
metadata?: Record<string, unknown>;
|
|
121
|
-
}): Promise<void> {
|
|
122
|
-
const { handler, graph, chunks, metadata } = args;
|
|
123
|
-
for (const toolCallChunk of chunks) {
|
|
124
|
-
await streamEvent({
|
|
125
|
-
handler,
|
|
126
|
-
graph,
|
|
127
|
-
metadata,
|
|
128
|
-
chunk: { content: '', tool_call_chunks: [toolCallChunk] },
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
describe('streamed tool-call argument circuit breaker', () => {
|
|
134
|
-
it('aborts the stream once a single call exceeds the default 64 KiB', async () => {
|
|
135
|
-
const handler = new ChatModelStreamHandler();
|
|
136
|
-
const graph = createGraph({ streamLimits: resolveStreamLimits() });
|
|
137
|
-
|
|
138
|
-
await streamToolCallChunks({
|
|
139
|
-
handler,
|
|
140
|
-
graph,
|
|
141
|
-
chunks: [
|
|
142
|
-
{ id: 'call_1', name: 'query_database', args: '', index: 0 },
|
|
143
|
-
...Array.from({ length: 8 }, () => ({
|
|
144
|
-
args: 'x'.repeat(8_192),
|
|
145
|
-
index: 0,
|
|
146
|
-
})),
|
|
147
|
-
],
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
await expect(
|
|
151
|
-
streamToolCallChunks({
|
|
152
|
-
handler,
|
|
153
|
-
graph,
|
|
154
|
-
chunks: [{ args: 'x', index: 0 }],
|
|
155
|
-
})
|
|
156
|
-
).rejects.toMatchObject({
|
|
157
|
-
name: 'StreamLimitExceededError',
|
|
158
|
-
kind: 'tool_call_args',
|
|
159
|
-
limit: DEFAULT_MAX_TOOL_CALL_ARG_BYTES,
|
|
160
|
-
observed: DEFAULT_MAX_TOOL_CALL_ARG_BYTES + 1,
|
|
161
|
-
toolName: 'query_database',
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
const dispatchDelta = graph.dispatchRunStepDelta as jest.Mock;
|
|
165
|
-
expect(dispatchDelta).toHaveBeenCalledTimes(9);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('keeps parallel tool calls on independent budgets', async () => {
|
|
169
|
-
const handler = new ChatModelStreamHandler();
|
|
170
|
-
const graph = createGraph({
|
|
171
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
await streamEvent({
|
|
175
|
-
handler,
|
|
176
|
-
graph,
|
|
177
|
-
chunk: {
|
|
178
|
-
content: '',
|
|
179
|
-
tool_call_chunks: [
|
|
180
|
-
{ id: 'call_1', name: 'first', args: 'a'.repeat(60), index: 0 },
|
|
181
|
-
{ id: 'call_2', name: 'second', args: 'b'.repeat(60), index: 1 },
|
|
182
|
-
],
|
|
183
|
-
},
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
await expect(
|
|
187
|
-
streamToolCallChunks({
|
|
188
|
-
handler,
|
|
189
|
-
graph,
|
|
190
|
-
chunks: [{ args: 'b'.repeat(41), index: 1 }],
|
|
191
|
-
})
|
|
192
|
-
).rejects.toThrow('(tool call: second)');
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it('counts argument bytes, not characters', async () => {
|
|
196
|
-
const handler = new ChatModelStreamHandler();
|
|
197
|
-
const graph = createGraph({
|
|
198
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 1_000 }),
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
await expect(
|
|
202
|
-
streamToolCallChunks({
|
|
203
|
-
handler,
|
|
204
|
-
graph,
|
|
205
|
-
chunks: [
|
|
206
|
-
{ id: 'call_1', name: 'writer', args: '€'.repeat(300), index: 0 },
|
|
207
|
-
{ args: '€'.repeat(100), index: 0 },
|
|
208
|
-
],
|
|
209
|
-
})
|
|
210
|
-
).rejects.toMatchObject({ kind: 'tool_call_args', observed: 1_200 });
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
it('enforces the cap before a complete arrival-sealed call can dispatch', async () => {
|
|
214
|
-
const handler = new ChatModelStreamHandler();
|
|
215
|
-
const graph = createGraph({
|
|
216
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
217
|
-
});
|
|
218
|
-
const oversized = JSON.stringify({ payload: 'x'.repeat(200) });
|
|
219
|
-
|
|
220
|
-
await expect(
|
|
221
|
-
streamEvent({
|
|
222
|
-
handler,
|
|
223
|
-
graph,
|
|
224
|
-
chunk: {
|
|
225
|
-
content: '',
|
|
226
|
-
tool_calls: [
|
|
227
|
-
{ id: 'call_1', name: 'side_effect', args: { payload: 'x'.repeat(200) } },
|
|
228
|
-
],
|
|
229
|
-
tool_call_chunks: [
|
|
230
|
-
{ id: 'call_1', name: 'side_effect', args: oversized, index: 0 },
|
|
231
|
-
],
|
|
232
|
-
},
|
|
233
|
-
})
|
|
234
|
-
).rejects.toMatchObject({ kind: 'tool_call_args', toolName: 'side_effect' });
|
|
235
|
-
|
|
236
|
-
const dispatchStep = graph.dispatchRunStep as jest.Mock;
|
|
237
|
-
expect(dispatchStep).not.toHaveBeenCalled();
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
it('enforces the cap for chunks that carry no numeric index', async () => {
|
|
241
|
-
const handler = new ChatModelStreamHandler();
|
|
242
|
-
const graph = createGraph({
|
|
243
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
await streamToolCallChunks({
|
|
247
|
-
handler,
|
|
248
|
-
graph,
|
|
249
|
-
chunks: [{ id: 'call_1', name: 'no_index_tool', args: 'x'.repeat(80) }],
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
await expect(
|
|
253
|
-
streamToolCallChunks({
|
|
254
|
-
handler,
|
|
255
|
-
graph,
|
|
256
|
-
chunks: [{ id: 'call_1', args: 'x'.repeat(21) }],
|
|
257
|
-
})
|
|
258
|
-
).rejects.toMatchObject({ kind: 'tool_call_args', toolName: 'no_index_tool' });
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it('does not double-count OpenAI Responses seal restatements', async () => {
|
|
262
|
-
const handler = new ChatModelStreamHandler();
|
|
263
|
-
const graph = createGraph({
|
|
264
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 50 }),
|
|
265
|
-
});
|
|
266
|
-
const fullArgs = 'x'.repeat(40);
|
|
267
|
-
|
|
268
|
-
await streamToolCallChunks({
|
|
269
|
-
handler,
|
|
270
|
-
graph,
|
|
271
|
-
chunks: [
|
|
272
|
-
{ args: fullArgs.slice(0, 20), index: 0 },
|
|
273
|
-
{ args: fullArgs.slice(20), index: 0 },
|
|
274
|
-
],
|
|
275
|
-
});
|
|
276
|
-
await streamEvent({
|
|
277
|
-
handler,
|
|
278
|
-
graph,
|
|
279
|
-
chunk: {
|
|
280
|
-
content: '',
|
|
281
|
-
tool_call_chunks: [{ name: 'writer', args: fullArgs, index: 0 }],
|
|
282
|
-
response_metadata: {
|
|
283
|
-
[STREAMED_TOOL_CALL_ADAPTER_METADATA_KEY]:
|
|
284
|
-
OPENAI_RESPONSES_STREAMED_TOOL_CALL_ADAPTER,
|
|
285
|
-
[STREAMED_TOOL_CALL_SEAL_METADATA_KEY]: { kind: 'single', index: 0 },
|
|
286
|
-
},
|
|
287
|
-
},
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
const key = `${resolveGenerationKey({})}:0`;
|
|
291
|
-
expect(graph.streamedToolCallArgTallies.has(key)).toBe(false);
|
|
292
|
-
expect(graph.streamedToolCallArgTallies.size).toBe(0);
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
it('keeps parallel anonymous arrival-sealed calls on separate budgets (Google)', async () => {
|
|
296
|
-
const handler = new ChatModelStreamHandler();
|
|
297
|
-
const graph = createGraph({
|
|
298
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 64 }),
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
await streamEvent({
|
|
302
|
-
handler,
|
|
303
|
-
graph,
|
|
304
|
-
chunk: {
|
|
305
|
-
content: '',
|
|
306
|
-
tool_call_chunks: [
|
|
307
|
-
{ name: 'search_a', args: 'x'.repeat(40) },
|
|
308
|
-
{ name: 'search_b', args: 'y'.repeat(40) },
|
|
309
|
-
],
|
|
310
|
-
response_metadata: {
|
|
311
|
-
[STREAMED_TOOL_CALL_SEAL_METADATA_KEY]: { kind: 'all' },
|
|
312
|
-
},
|
|
313
|
-
},
|
|
314
|
-
});
|
|
315
|
-
expect(graph.streamedToolCallArgTallies.size).toBe(0);
|
|
316
|
-
|
|
317
|
-
await expect(
|
|
318
|
-
streamEvent({
|
|
319
|
-
handler,
|
|
320
|
-
graph,
|
|
321
|
-
chunk: {
|
|
322
|
-
content: '',
|
|
323
|
-
tool_call_chunks: [{ name: 'search_c', args: 'z'.repeat(70) }],
|
|
324
|
-
response_metadata: {
|
|
325
|
-
[STREAMED_TOOL_CALL_SEAL_METADATA_KEY]: { kind: 'all' },
|
|
326
|
-
},
|
|
327
|
-
},
|
|
328
|
-
})
|
|
329
|
-
).rejects.toMatchObject({ kind: 'tool_call_args', toolName: 'search_c' });
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
it('streams unbounded when explicitly disabled', async () => {
|
|
333
|
-
const handler = new ChatModelStreamHandler();
|
|
334
|
-
const graph = createGraph({
|
|
335
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 0 }),
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
await streamToolCallChunks({
|
|
339
|
-
handler,
|
|
340
|
-
graph,
|
|
341
|
-
chunks: [
|
|
342
|
-
{ id: 'call_1', name: 'query_database', args: '', index: 0 },
|
|
343
|
-
...Array.from({ length: 4 }, () => ({
|
|
344
|
-
args: 'x'.repeat(65_536),
|
|
345
|
-
index: 0,
|
|
346
|
-
})),
|
|
347
|
-
],
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
const dispatchDelta = graph.dispatchRunStepDelta as jest.Mock;
|
|
351
|
-
expect(dispatchDelta).toHaveBeenCalledTimes(5);
|
|
352
|
-
expect(graph.streamedToolCallArgTallies).toBeUndefined();
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
it('creates the tool_calls run step before the breaker can trip', async () => {
|
|
356
|
-
const handler = new ChatModelStreamHandler();
|
|
357
|
-
const graph = createGraph({
|
|
358
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 50 }),
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
await streamToolCallChunks({
|
|
362
|
-
handler,
|
|
363
|
-
graph,
|
|
364
|
-
chunks: [{ id: 'call_1', name: 'query_database', args: '{"q":', index: 0 }],
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
const dispatchStep = graph.dispatchRunStep as jest.Mock;
|
|
368
|
-
const dispatchedTypes = dispatchStep.mock.calls.map(
|
|
369
|
-
(call) => (call[1] as { type: string }).type
|
|
370
|
-
);
|
|
371
|
-
expect(dispatchedTypes).toContain(StepTypes.TOOL_CALLS);
|
|
372
|
-
});
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
describe('per-tool argument byte overrides', () => {
|
|
376
|
-
it('raises the cap for the named tool without loosening others', async () => {
|
|
377
|
-
const handler = new ChatModelStreamHandler();
|
|
378
|
-
const graph = createGraph({
|
|
379
|
-
streamLimits: resolveStreamLimits({
|
|
380
|
-
maxToolCallArgBytes: 100,
|
|
381
|
-
maxToolCallArgBytesByTool: { create_file: 1_000 },
|
|
382
|
-
}),
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
await streamToolCallChunks({
|
|
386
|
-
handler,
|
|
387
|
-
graph,
|
|
388
|
-
chunks: [
|
|
389
|
-
{ id: 'call_1', name: 'create_file', args: 'x'.repeat(500), index: 0 },
|
|
390
|
-
],
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
await expect(
|
|
394
|
-
streamToolCallChunks({
|
|
395
|
-
handler,
|
|
396
|
-
graph,
|
|
397
|
-
chunks: [
|
|
398
|
-
{ id: 'call_2', name: 'query_database', args: 'y'.repeat(101), index: 1 },
|
|
399
|
-
],
|
|
400
|
-
})
|
|
401
|
-
).rejects.toMatchObject({
|
|
402
|
-
kind: 'tool_call_args',
|
|
403
|
-
limit: 100,
|
|
404
|
-
toolName: 'query_database',
|
|
405
|
-
});
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
it('trips the named tool at its own lower cap', async () => {
|
|
409
|
-
const handler = new ChatModelStreamHandler();
|
|
410
|
-
const graph = createGraph({
|
|
411
|
-
streamLimits: resolveStreamLimits({
|
|
412
|
-
maxToolCallArgBytes: 1_000,
|
|
413
|
-
maxToolCallArgBytesByTool: { chatty_tool: 50 },
|
|
414
|
-
}),
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
await expect(
|
|
418
|
-
streamToolCallChunks({
|
|
419
|
-
handler,
|
|
420
|
-
graph,
|
|
421
|
-
chunks: [
|
|
422
|
-
{ id: 'call_1', name: 'chatty_tool', args: 'x'.repeat(51), index: 0 },
|
|
423
|
-
],
|
|
424
|
-
})
|
|
425
|
-
).rejects.toMatchObject({
|
|
426
|
-
kind: 'tool_call_args',
|
|
427
|
-
limit: 50,
|
|
428
|
-
toolName: 'chatty_tool',
|
|
429
|
-
});
|
|
430
|
-
});
|
|
431
|
-
|
|
432
|
-
it('enforces a per-tool cap even when the global cap is disabled', async () => {
|
|
433
|
-
const handler = new ChatModelStreamHandler();
|
|
434
|
-
const graph = createGraph({
|
|
435
|
-
streamLimits: resolveStreamLimits({
|
|
436
|
-
maxToolCallArgBytes: 0,
|
|
437
|
-
maxToolCallArgBytesByTool: { create_file: 100 },
|
|
438
|
-
}),
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
await streamToolCallChunks({
|
|
442
|
-
handler,
|
|
443
|
-
graph,
|
|
444
|
-
chunks: [
|
|
445
|
-
{ id: 'call_1', name: 'unbounded_tool', args: 'x'.repeat(500), index: 0 },
|
|
446
|
-
],
|
|
447
|
-
});
|
|
448
|
-
|
|
449
|
-
await expect(
|
|
450
|
-
streamToolCallChunks({
|
|
451
|
-
handler,
|
|
452
|
-
graph,
|
|
453
|
-
chunks: [
|
|
454
|
-
{ id: 'call_2', name: 'create_file', args: 'y'.repeat(101), index: 1 },
|
|
455
|
-
],
|
|
456
|
-
})
|
|
457
|
-
).rejects.toMatchObject({
|
|
458
|
-
kind: 'tool_call_args',
|
|
459
|
-
limit: 100,
|
|
460
|
-
toolName: 'create_file',
|
|
461
|
-
});
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
it('applies overrides to arrival-sealed complete calls', async () => {
|
|
465
|
-
const handler = new ChatModelStreamHandler();
|
|
466
|
-
const graph = createGraph({
|
|
467
|
-
streamLimits: resolveStreamLimits({
|
|
468
|
-
maxToolCallArgBytes: 64,
|
|
469
|
-
maxToolCallArgBytesByTool: { create_file: 1_000 },
|
|
470
|
-
}),
|
|
471
|
-
});
|
|
472
|
-
|
|
473
|
-
await streamEvent({
|
|
474
|
-
handler,
|
|
475
|
-
graph,
|
|
476
|
-
chunk: {
|
|
477
|
-
content: '',
|
|
478
|
-
tool_call_chunks: [{ name: 'create_file', args: 'x'.repeat(500) }],
|
|
479
|
-
response_metadata: {
|
|
480
|
-
[STREAMED_TOOL_CALL_SEAL_METADATA_KEY]: { kind: 'all' },
|
|
481
|
-
},
|
|
482
|
-
},
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
await expect(
|
|
486
|
-
streamEvent({
|
|
487
|
-
handler,
|
|
488
|
-
graph,
|
|
489
|
-
chunk: {
|
|
490
|
-
content: '',
|
|
491
|
-
tool_call_chunks: [{ name: 'search_c', args: 'z'.repeat(70) }],
|
|
492
|
-
response_metadata: {
|
|
493
|
-
[STREAMED_TOOL_CALL_SEAL_METADATA_KEY]: { kind: 'all' },
|
|
494
|
-
},
|
|
495
|
-
},
|
|
496
|
-
})
|
|
497
|
-
).rejects.toMatchObject({ kind: 'tool_call_args', toolName: 'search_c' });
|
|
498
|
-
});
|
|
499
|
-
|
|
500
|
-
it('re-judges tallied bytes when the tool name arrives on a later empty chunk', async () => {
|
|
501
|
-
const handler = new ChatModelStreamHandler();
|
|
502
|
-
const graph = createGraph({
|
|
503
|
-
streamLimits: resolveStreamLimits({
|
|
504
|
-
maxToolCallArgBytes: 1_000,
|
|
505
|
-
maxToolCallArgBytesByTool: { capped_tool: 50 },
|
|
506
|
-
}),
|
|
507
|
-
});
|
|
508
|
-
|
|
509
|
-
await streamToolCallChunks({
|
|
510
|
-
handler,
|
|
511
|
-
graph,
|
|
512
|
-
chunks: [{ args: 'x'.repeat(60), index: 0 }],
|
|
513
|
-
});
|
|
514
|
-
|
|
515
|
-
await expect(
|
|
516
|
-
streamToolCallChunks({
|
|
517
|
-
handler,
|
|
518
|
-
graph,
|
|
519
|
-
chunks: [{ id: 'call_1', name: 'capped_tool', args: '', index: 0 }],
|
|
520
|
-
})
|
|
521
|
-
).rejects.toMatchObject({
|
|
522
|
-
kind: 'tool_call_args',
|
|
523
|
-
limit: 50,
|
|
524
|
-
observed: 60,
|
|
525
|
-
toolName: 'capped_tool',
|
|
526
|
-
});
|
|
527
|
-
});
|
|
528
|
-
|
|
529
|
-
it('honors an override for a tool named __proto__', async () => {
|
|
530
|
-
const handler = new ChatModelStreamHandler();
|
|
531
|
-
const graph = createGraph({
|
|
532
|
-
streamLimits: resolveStreamLimits({
|
|
533
|
-
maxToolCallArgBytes: 100,
|
|
534
|
-
maxToolCallArgBytesByTool: JSON.parse('{"__proto__": 1000}') as Record<
|
|
535
|
-
string,
|
|
536
|
-
number
|
|
537
|
-
>,
|
|
538
|
-
}),
|
|
539
|
-
});
|
|
540
|
-
|
|
541
|
-
await streamToolCallChunks({
|
|
542
|
-
handler,
|
|
543
|
-
graph,
|
|
544
|
-
chunks: [{ id: 'call_1', name: '__proto__', args: 'x'.repeat(500), index: 0 }],
|
|
545
|
-
});
|
|
546
|
-
|
|
547
|
-
await expect(
|
|
548
|
-
streamToolCallChunks({
|
|
549
|
-
handler,
|
|
550
|
-
graph,
|
|
551
|
-
chunks: [{ args: 'x'.repeat(501), index: 0 }],
|
|
552
|
-
})
|
|
553
|
-
).rejects.toMatchObject({
|
|
554
|
-
kind: 'tool_call_args',
|
|
555
|
-
limit: 1_000,
|
|
556
|
-
toolName: '__proto__',
|
|
557
|
-
});
|
|
558
|
-
});
|
|
559
|
-
|
|
560
|
-
it('keeps charging a call whose later deltas omit both id and index', async () => {
|
|
561
|
-
const handler = new ChatModelStreamHandler();
|
|
562
|
-
const graph = createGraph({
|
|
563
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
564
|
-
});
|
|
565
|
-
|
|
566
|
-
await streamToolCallChunks({
|
|
567
|
-
handler,
|
|
568
|
-
graph,
|
|
569
|
-
chunks: [{ id: 'call_1', name: 'writer', args: 'a'.repeat(60) }],
|
|
570
|
-
});
|
|
571
|
-
|
|
572
|
-
await expect(
|
|
573
|
-
streamToolCallChunks({
|
|
574
|
-
handler,
|
|
575
|
-
graph,
|
|
576
|
-
chunks: [{ args: 'a'.repeat(60) }],
|
|
577
|
-
})
|
|
578
|
-
).rejects.toMatchObject({
|
|
579
|
-
kind: 'tool_call_args',
|
|
580
|
-
limit: 100,
|
|
581
|
-
observed: 120,
|
|
582
|
-
toolName: 'writer',
|
|
583
|
-
});
|
|
584
|
-
});
|
|
585
|
-
|
|
586
|
-
it('does not charge argument bytes for marked OpenRouter redispatches', async () => {
|
|
587
|
-
const handler = new ChatModelStreamHandler();
|
|
588
|
-
const graph = createGraph({
|
|
589
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
590
|
-
});
|
|
591
|
-
|
|
592
|
-
await streamToolCallChunks({
|
|
593
|
-
handler,
|
|
594
|
-
graph,
|
|
595
|
-
chunks: [{ id: 'call_1', name: 'writer', args: 'a'.repeat(60), index: 0 }],
|
|
596
|
-
});
|
|
597
|
-
await streamEvent({
|
|
598
|
-
handler,
|
|
599
|
-
graph,
|
|
600
|
-
metadata: { [STREAM_LIMIT_REDISPATCH_KEY]: true },
|
|
601
|
-
chunk: {
|
|
602
|
-
content: '',
|
|
603
|
-
tool_call_chunks: [{ args: 'a'.repeat(60), index: 0 }],
|
|
604
|
-
},
|
|
605
|
-
});
|
|
606
|
-
await streamToolCallChunks({
|
|
607
|
-
handler,
|
|
608
|
-
graph,
|
|
609
|
-
chunks: [{ args: 'a'.repeat(40), index: 0 }],
|
|
610
|
-
});
|
|
611
|
-
|
|
612
|
-
await expect(
|
|
613
|
-
streamToolCallChunks({
|
|
614
|
-
handler,
|
|
615
|
-
graph,
|
|
616
|
-
chunks: [{ args: 'a', index: 0 }],
|
|
617
|
-
})
|
|
618
|
-
).rejects.toMatchObject({ kind: 'tool_call_args', observed: 101 });
|
|
619
|
-
});
|
|
620
|
-
|
|
621
|
-
it('judges client tool chunks arriving with a server-tool result before the early return', async () => {
|
|
622
|
-
const handler = new ChatModelStreamHandler();
|
|
623
|
-
const graph = createGraph({
|
|
624
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
625
|
-
});
|
|
626
|
-
(graph.getAgentContext as jest.Mock).mockReturnValue({
|
|
627
|
-
provider: Providers.ANTHROPIC,
|
|
628
|
-
reasoningKey: 'reasoning_content',
|
|
629
|
-
toolDefinitions: [],
|
|
630
|
-
graphTools: [],
|
|
631
|
-
agentId: 'agent_1',
|
|
632
|
-
});
|
|
633
|
-
await graph.dispatchRunStep('step-key', {
|
|
634
|
-
type: StepTypes.TOOL_CALLS,
|
|
635
|
-
tool_calls: [{ id: 'srvtoolu_1', name: 'web_search', args: {} }],
|
|
636
|
-
});
|
|
637
|
-
graph.toolCallStepIds.set('srvtoolu_1', 'step_1');
|
|
638
|
-
|
|
639
|
-
await expect(
|
|
640
|
-
streamEvent({
|
|
641
|
-
handler,
|
|
642
|
-
graph,
|
|
643
|
-
chunk: {
|
|
644
|
-
content: [
|
|
645
|
-
{ type: 'web_search_tool_result', tool_use_id: 'srvtoolu_1', content: [] },
|
|
646
|
-
],
|
|
647
|
-
tool_call_chunks: [
|
|
648
|
-
{ id: 'call_big', name: 'side_effect', args: 'x'.repeat(200), index: 0 },
|
|
649
|
-
],
|
|
650
|
-
},
|
|
651
|
-
})
|
|
652
|
-
).rejects.toMatchObject({ kind: 'tool_call_args', toolName: 'side_effect' });
|
|
653
|
-
});
|
|
654
|
-
|
|
655
|
-
it('judges complete parsed tool calls that arrive without raw chunks', async () => {
|
|
656
|
-
const handler = new ChatModelStreamHandler();
|
|
657
|
-
const graph = createGraph({
|
|
658
|
-
streamLimits: resolveStreamLimits({
|
|
659
|
-
maxToolCallArgBytes: 100,
|
|
660
|
-
maxToolCallArgBytesByTool: { create_file: 1_000 },
|
|
661
|
-
}),
|
|
662
|
-
});
|
|
663
|
-
|
|
664
|
-
await streamEvent({
|
|
665
|
-
handler,
|
|
666
|
-
graph,
|
|
667
|
-
chunk: {
|
|
668
|
-
content: '',
|
|
669
|
-
tool_calls: [
|
|
670
|
-
{ id: 'call_1', name: 'create_file', args: { content: 'x'.repeat(500) } },
|
|
671
|
-
],
|
|
672
|
-
},
|
|
673
|
-
});
|
|
674
|
-
|
|
675
|
-
await expect(
|
|
676
|
-
streamEvent({
|
|
677
|
-
handler,
|
|
678
|
-
graph,
|
|
679
|
-
chunk: {
|
|
680
|
-
content: '',
|
|
681
|
-
tool_calls: [
|
|
682
|
-
{ id: 'call_2', name: 'side_effect', args: { payload: 'x'.repeat(200) } },
|
|
683
|
-
],
|
|
684
|
-
},
|
|
685
|
-
})
|
|
686
|
-
).rejects.toMatchObject({
|
|
687
|
-
kind: 'tool_call_args',
|
|
688
|
-
limit: 100,
|
|
689
|
-
toolName: 'side_effect',
|
|
690
|
-
});
|
|
691
|
-
});
|
|
692
|
-
|
|
693
|
-
it('charges a chunk once when the handler echo wins the race', async () => {
|
|
694
|
-
const handler = new ChatModelStreamHandler();
|
|
695
|
-
const graph = createGraph({
|
|
696
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
697
|
-
});
|
|
698
|
-
const wireChunk = {
|
|
699
|
-
content: '',
|
|
700
|
-
tool_call_chunks: [{ id: 'call_1', name: 'writer', args: 'a'.repeat(60), index: 0 }],
|
|
701
|
-
};
|
|
702
|
-
|
|
703
|
-
await streamEvent({ handler, graph, chunk: wireChunk });
|
|
704
|
-
enforceStreamLimitsForWireChunk({
|
|
705
|
-
graph,
|
|
706
|
-
metadata: {},
|
|
707
|
-
chunk: wireChunk as never,
|
|
708
|
-
});
|
|
709
|
-
await streamToolCallChunks({
|
|
710
|
-
handler,
|
|
711
|
-
graph,
|
|
712
|
-
chunks: [{ args: 'a'.repeat(40), index: 0 }],
|
|
713
|
-
});
|
|
714
|
-
|
|
715
|
-
await expect(
|
|
716
|
-
streamToolCallChunks({
|
|
717
|
-
handler,
|
|
718
|
-
graph,
|
|
719
|
-
chunks: [{ args: 'a', index: 0 }],
|
|
720
|
-
})
|
|
721
|
-
).rejects.toMatchObject({ kind: 'tool_call_args', observed: 101 });
|
|
722
|
-
});
|
|
723
|
-
|
|
724
|
-
it('charges wire chunks synchronously and skips the handler echo', async () => {
|
|
725
|
-
const handler = new ChatModelStreamHandler();
|
|
726
|
-
const graph = createGraph({
|
|
727
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
728
|
-
});
|
|
729
|
-
const wireChunk = {
|
|
730
|
-
content: '',
|
|
731
|
-
tool_call_chunks: [{ id: 'call_1', name: 'writer', args: 'a'.repeat(60), index: 0 }],
|
|
732
|
-
};
|
|
733
|
-
|
|
734
|
-
enforceStreamLimitsForWireChunk({
|
|
735
|
-
graph,
|
|
736
|
-
metadata: {},
|
|
737
|
-
chunk: wireChunk as never,
|
|
738
|
-
});
|
|
739
|
-
await streamEvent({ handler, graph, chunk: wireChunk });
|
|
740
|
-
await streamToolCallChunks({
|
|
741
|
-
handler,
|
|
742
|
-
graph,
|
|
743
|
-
chunks: [{ args: 'a'.repeat(40), index: 0 }],
|
|
744
|
-
});
|
|
745
|
-
|
|
746
|
-
await expect(
|
|
747
|
-
streamToolCallChunks({
|
|
748
|
-
handler,
|
|
749
|
-
graph,
|
|
750
|
-
chunks: [{ args: 'a', index: 0 }],
|
|
751
|
-
})
|
|
752
|
-
).rejects.toMatchObject({ kind: 'tool_call_args', observed: 101 });
|
|
753
|
-
});
|
|
754
|
-
|
|
755
|
-
it('keeps charging a mutable chunk object re-yielded across emissions', async () => {
|
|
756
|
-
const handler = new ChatModelStreamHandler();
|
|
757
|
-
const graph = createGraph({
|
|
758
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
759
|
-
});
|
|
760
|
-
const reused: Record<string, unknown> = {
|
|
761
|
-
content: '',
|
|
762
|
-
tool_call_chunks: [{ id: 'call_1', name: 'writer', args: 'a'.repeat(60), index: 0 }],
|
|
763
|
-
};
|
|
764
|
-
|
|
765
|
-
await streamEvent({ handler, graph, chunk: reused });
|
|
766
|
-
reused.tool_call_chunks = [{ args: 'a'.repeat(40), index: 0 }];
|
|
767
|
-
await streamEvent({ handler, graph, chunk: reused });
|
|
768
|
-
reused.tool_call_chunks = [{ args: 'a', index: 0 }];
|
|
769
|
-
|
|
770
|
-
await expect(streamEvent({ handler, graph, chunk: reused })).rejects.toMatchObject({
|
|
771
|
-
kind: 'tool_call_args',
|
|
772
|
-
observed: 101,
|
|
773
|
-
});
|
|
774
|
-
});
|
|
775
|
-
|
|
776
|
-
it('pairs producer and echo charges per emission for reused chunk objects', async () => {
|
|
777
|
-
const handler = new ChatModelStreamHandler();
|
|
778
|
-
const graph = createGraph({
|
|
779
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
780
|
-
});
|
|
781
|
-
const reused: Record<string, unknown> = {
|
|
782
|
-
content: '',
|
|
783
|
-
tool_call_chunks: [{ id: 'call_1', name: 'writer', args: 'a'.repeat(60), index: 0 }],
|
|
784
|
-
};
|
|
785
|
-
|
|
786
|
-
enforceStreamLimitsForWireChunk({ graph, metadata: {}, chunk: reused as never });
|
|
787
|
-
await streamEvent({ handler, graph, chunk: reused });
|
|
788
|
-
reused.tool_call_chunks = [{ args: 'a'.repeat(40), index: 0 }];
|
|
789
|
-
enforceStreamLimitsForWireChunk({ graph, metadata: {}, chunk: reused as never });
|
|
790
|
-
await streamEvent({ handler, graph, chunk: reused });
|
|
791
|
-
reused.tool_call_chunks = [{ args: 'a', index: 0 }];
|
|
792
|
-
|
|
793
|
-
let thrown: unknown;
|
|
794
|
-
try {
|
|
795
|
-
enforceStreamLimitsForWireChunk({ graph, metadata: {}, chunk: reused as never });
|
|
796
|
-
} catch (error) {
|
|
797
|
-
thrown = error;
|
|
798
|
-
}
|
|
799
|
-
expect(thrown).toMatchObject({ kind: 'tool_call_args', observed: 101 });
|
|
800
|
-
});
|
|
801
|
-
|
|
802
|
-
it('keeps parallel index-less calls on distinct budgets when one seals', async () => {
|
|
803
|
-
const handler = new ChatModelStreamHandler();
|
|
804
|
-
const graph = createGraph({
|
|
805
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
806
|
-
});
|
|
807
|
-
|
|
808
|
-
await streamToolCallChunks({
|
|
809
|
-
handler,
|
|
810
|
-
graph,
|
|
811
|
-
chunks: [{ id: 'call_a', name: 'a_tool', args: 'a'.repeat(60) }],
|
|
812
|
-
});
|
|
813
|
-
await streamToolCallChunks({
|
|
814
|
-
handler,
|
|
815
|
-
graph,
|
|
816
|
-
chunks: [{ id: 'call_b', name: 'b_tool', args: 'b'.repeat(60) }],
|
|
817
|
-
});
|
|
818
|
-
await streamEvent({
|
|
819
|
-
handler,
|
|
820
|
-
graph,
|
|
821
|
-
chunk: {
|
|
822
|
-
content: '',
|
|
823
|
-
tool_call_chunks: [{ id: 'call_a', args: '' }],
|
|
824
|
-
response_metadata: {
|
|
825
|
-
[STREAMED_TOOL_CALL_SEAL_METADATA_KEY]: { kind: 'single', id: 'call_a' },
|
|
826
|
-
},
|
|
827
|
-
},
|
|
828
|
-
});
|
|
829
|
-
|
|
830
|
-
await expect(
|
|
831
|
-
streamToolCallChunks({
|
|
832
|
-
handler,
|
|
833
|
-
graph,
|
|
834
|
-
chunks: [{ args: 'b'.repeat(41) }],
|
|
835
|
-
})
|
|
836
|
-
).rejects.toMatchObject({
|
|
837
|
-
kind: 'tool_call_args',
|
|
838
|
-
observed: 101,
|
|
839
|
-
toolName: 'b_tool',
|
|
840
|
-
});
|
|
841
|
-
});
|
|
842
|
-
|
|
843
|
-
it('scopes charge credits per generation for shared chunk objects', async () => {
|
|
844
|
-
const handler = new ChatModelStreamHandler();
|
|
845
|
-
const graph = createGraph({
|
|
846
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
847
|
-
});
|
|
848
|
-
const shared: Record<string, unknown> = {
|
|
849
|
-
content: '',
|
|
850
|
-
tool_call_chunks: [{ id: 'call_1', name: 'writer', args: 'a'.repeat(60), index: 0 }],
|
|
851
|
-
};
|
|
852
|
-
|
|
853
|
-
await streamEvent({ handler, graph, chunk: shared, metadata: generation(1) });
|
|
854
|
-
enforceStreamLimitsForWireChunk({
|
|
855
|
-
graph,
|
|
856
|
-
metadata: generation(2),
|
|
857
|
-
chunk: shared as never,
|
|
858
|
-
});
|
|
859
|
-
|
|
860
|
-
await expect(
|
|
861
|
-
streamToolCallChunks({
|
|
862
|
-
handler,
|
|
863
|
-
graph,
|
|
864
|
-
chunks: [{ args: 'a'.repeat(41), index: 0 }],
|
|
865
|
-
metadata: generation(2),
|
|
866
|
-
})
|
|
867
|
-
).rejects.toMatchObject({ kind: 'tool_call_args', observed: 101 });
|
|
868
|
-
});
|
|
869
|
-
|
|
870
|
-
it('judges parsed calls even when a raw chunk representation is present', async () => {
|
|
871
|
-
const handler = new ChatModelStreamHandler();
|
|
872
|
-
const graph = createGraph({
|
|
873
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
874
|
-
});
|
|
875
|
-
|
|
876
|
-
await expect(
|
|
877
|
-
streamEvent({
|
|
878
|
-
handler,
|
|
879
|
-
graph,
|
|
880
|
-
chunk: {
|
|
881
|
-
content: '',
|
|
882
|
-
tool_call_chunks: [{ id: 'call_1', name: 'side_effect', args: '', index: 0 }],
|
|
883
|
-
tool_calls: [
|
|
884
|
-
{ id: 'call_1', name: 'side_effect', args: { payload: 'x'.repeat(200) } },
|
|
885
|
-
],
|
|
886
|
-
},
|
|
887
|
-
})
|
|
888
|
-
).rejects.toMatchObject({ kind: 'tool_call_args', toolName: 'side_effect' });
|
|
889
|
-
});
|
|
890
|
-
|
|
891
|
-
it('keeps one budget when a call drops its index but keeps its id', async () => {
|
|
892
|
-
const handler = new ChatModelStreamHandler();
|
|
893
|
-
const graph = createGraph({
|
|
894
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
895
|
-
});
|
|
896
|
-
|
|
897
|
-
await streamToolCallChunks({
|
|
898
|
-
handler,
|
|
899
|
-
graph,
|
|
900
|
-
chunks: [{ id: 'call_1', name: 'writer', args: 'a'.repeat(60), index: 0 }],
|
|
901
|
-
});
|
|
902
|
-
|
|
903
|
-
await expect(
|
|
904
|
-
streamToolCallChunks({
|
|
905
|
-
handler,
|
|
906
|
-
graph,
|
|
907
|
-
chunks: [{ id: 'call_1', args: 'a'.repeat(41) }],
|
|
908
|
-
})
|
|
909
|
-
).rejects.toMatchObject({
|
|
910
|
-
kind: 'tool_call_args',
|
|
911
|
-
observed: 101,
|
|
912
|
-
toolName: 'writer',
|
|
913
|
-
});
|
|
914
|
-
});
|
|
915
|
-
|
|
916
|
-
it('keeps one budget when a call drops both identifiers on later deltas', async () => {
|
|
917
|
-
const handler = new ChatModelStreamHandler();
|
|
918
|
-
const graph = createGraph({
|
|
919
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
920
|
-
});
|
|
921
|
-
|
|
922
|
-
await streamToolCallChunks({
|
|
923
|
-
handler,
|
|
924
|
-
graph,
|
|
925
|
-
chunks: [{ id: 'call_1', name: 'writer', args: 'a'.repeat(60), index: 0 }],
|
|
926
|
-
});
|
|
927
|
-
|
|
928
|
-
await expect(
|
|
929
|
-
streamToolCallChunks({
|
|
930
|
-
handler,
|
|
931
|
-
graph,
|
|
932
|
-
chunks: [{ args: 'a'.repeat(41) }],
|
|
933
|
-
})
|
|
934
|
-
).rejects.toMatchObject({
|
|
935
|
-
kind: 'tool_call_args',
|
|
936
|
-
observed: 101,
|
|
937
|
-
toolName: 'writer',
|
|
938
|
-
});
|
|
939
|
-
});
|
|
940
|
-
|
|
941
|
-
it('adopts the existing tally when a later delta adds an index', async () => {
|
|
942
|
-
const handler = new ChatModelStreamHandler();
|
|
943
|
-
const graph = createGraph({
|
|
944
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
945
|
-
});
|
|
946
|
-
|
|
947
|
-
await streamToolCallChunks({
|
|
948
|
-
handler,
|
|
949
|
-
graph,
|
|
950
|
-
chunks: [{ id: 'call_1', name: 'writer', args: 'a'.repeat(60) }],
|
|
951
|
-
});
|
|
952
|
-
|
|
953
|
-
await expect(
|
|
954
|
-
streamToolCallChunks({
|
|
955
|
-
handler,
|
|
956
|
-
graph,
|
|
957
|
-
chunks: [{ id: 'call_1', args: 'a'.repeat(41), index: 0 }],
|
|
958
|
-
})
|
|
959
|
-
).rejects.toMatchObject({
|
|
960
|
-
kind: 'tool_call_args',
|
|
961
|
-
observed: 101,
|
|
962
|
-
toolName: 'writer',
|
|
963
|
-
});
|
|
964
|
-
});
|
|
965
|
-
|
|
966
|
-
it('names anonymous raw chunks from parsed calls so overrides apply', async () => {
|
|
967
|
-
const handler = new ChatModelStreamHandler();
|
|
968
|
-
const graph = createGraph({
|
|
969
|
-
streamLimits: resolveStreamLimits({
|
|
970
|
-
maxToolCallArgBytes: 100,
|
|
971
|
-
maxToolCallArgBytesByTool: { create_file: 1_000 },
|
|
972
|
-
}),
|
|
973
|
-
});
|
|
974
|
-
|
|
975
|
-
await expect(
|
|
976
|
-
streamEvent({
|
|
977
|
-
handler,
|
|
978
|
-
graph,
|
|
979
|
-
chunk: {
|
|
980
|
-
content: '',
|
|
981
|
-
tool_call_chunks: [{ id: 'call_1', args: 'x'.repeat(500), index: 0 }],
|
|
982
|
-
tool_calls: [
|
|
983
|
-
{ id: 'call_1', name: 'create_file', args: { content: 'x'.repeat(500) } },
|
|
984
|
-
],
|
|
985
|
-
},
|
|
986
|
-
})
|
|
987
|
-
).resolves.toBeUndefined();
|
|
988
|
-
|
|
989
|
-
await expect(
|
|
990
|
-
streamToolCallChunks({
|
|
991
|
-
handler,
|
|
992
|
-
graph,
|
|
993
|
-
chunks: [{ args: 'x'.repeat(501), index: 0 }],
|
|
994
|
-
})
|
|
995
|
-
).rejects.toMatchObject({
|
|
996
|
-
kind: 'tool_call_args',
|
|
997
|
-
limit: 1_000,
|
|
998
|
-
toolName: 'create_file',
|
|
999
|
-
});
|
|
1000
|
-
});
|
|
1001
|
-
|
|
1002
|
-
it('stops queued events once the shared breaker has tripped', async () => {
|
|
1003
|
-
const handler = new ChatModelStreamHandler();
|
|
1004
|
-
const breakerAbort = new AbortController();
|
|
1005
|
-
const trip = new StreamLimitExceededError({
|
|
1006
|
-
kind: 'tool_call_args',
|
|
1007
|
-
limit: 10,
|
|
1008
|
-
observed: 11,
|
|
1009
|
-
toolName: 'db_query',
|
|
1010
|
-
});
|
|
1011
|
-
breakerAbort.abort(trip);
|
|
1012
|
-
const graph = createGraph({
|
|
1013
|
-
streamLimits: resolveStreamLimits(),
|
|
1014
|
-
breakerAbort,
|
|
1015
|
-
});
|
|
1016
|
-
|
|
1017
|
-
/** A sibling branch tripped the breaker while this event sat queued in
|
|
1018
|
-
* streamEvents; the handler must rethrow instead of continuing into
|
|
1019
|
-
* content handling or the eager-tool dispatch paths. */
|
|
1020
|
-
await expect(
|
|
1021
|
-
streamEvent({ handler, graph, chunk: { content: 'queued text' } })
|
|
1022
|
-
).rejects.toBe(trip);
|
|
1023
|
-
});
|
|
1024
|
-
|
|
1025
|
-
it('does not charge an anonymous sparse delta to an identified call\'s override', async () => {
|
|
1026
|
-
const handler = new ChatModelStreamHandler();
|
|
1027
|
-
const graph = createGraph({
|
|
1028
|
-
streamLimits: resolveStreamLimits({
|
|
1029
|
-
maxToolCallArgBytes: 100,
|
|
1030
|
-
maxToolCallArgBytesByTool: { create_file: 1_000 },
|
|
1031
|
-
}),
|
|
1032
|
-
});
|
|
1033
|
-
|
|
1034
|
-
/** Parallel batch: two identified calls share one event, so batch
|
|
1035
|
-
* positions are NOT stable identities for later sparse events. */
|
|
1036
|
-
await expect(
|
|
1037
|
-
streamEvent({
|
|
1038
|
-
handler,
|
|
1039
|
-
graph,
|
|
1040
|
-
chunk: {
|
|
1041
|
-
content: '',
|
|
1042
|
-
tool_call_chunks: [
|
|
1043
|
-
{ id: 'call_a', name: 'create_file', args: 'x'.repeat(50) },
|
|
1044
|
-
{ id: 'call_b', name: 'db_query', args: 'x'.repeat(10) },
|
|
1045
|
-
],
|
|
1046
|
-
},
|
|
1047
|
-
})
|
|
1048
|
-
).resolves.toBeUndefined();
|
|
1049
|
-
|
|
1050
|
-
/** A sparse continuation event with a single anonymous delta lands on
|
|
1051
|
-
* batch position 0 — inheriting call_a's tally would judge these bytes
|
|
1052
|
-
* under create_file's 1000-byte override and bypass the global cap. */
|
|
1053
|
-
await expect(
|
|
1054
|
-
streamToolCallChunks({
|
|
1055
|
-
handler,
|
|
1056
|
-
graph,
|
|
1057
|
-
chunks: [{ args: 'x'.repeat(200) }],
|
|
1058
|
-
})
|
|
1059
|
-
).rejects.toMatchObject({ kind: 'tool_call_args', limit: 100 });
|
|
1060
|
-
});
|
|
1061
|
-
|
|
1062
|
-
it('judges ambiguous sparse deltas under each candidate\'s own limit', async () => {
|
|
1063
|
-
const handler = new ChatModelStreamHandler();
|
|
1064
|
-
const graph = createGraph({
|
|
1065
|
-
streamLimits: resolveStreamLimits({
|
|
1066
|
-
maxToolCallArgBytes: 1_000,
|
|
1067
|
-
maxToolCallArgBytesByTool: { tight_tool: 50 },
|
|
1068
|
-
}),
|
|
1069
|
-
});
|
|
1070
|
-
|
|
1071
|
-
await expect(
|
|
1072
|
-
streamEvent({
|
|
1073
|
-
handler,
|
|
1074
|
-
graph,
|
|
1075
|
-
chunk: {
|
|
1076
|
-
content: '',
|
|
1077
|
-
tool_call_chunks: [
|
|
1078
|
-
{ id: 'call_a', name: 'tight_tool', args: 'x'.repeat(10) },
|
|
1079
|
-
{ id: 'call_b', name: 'db_query', args: 'x'.repeat(10) },
|
|
1080
|
-
],
|
|
1081
|
-
},
|
|
1082
|
-
})
|
|
1083
|
-
).resolves.toBeUndefined();
|
|
1084
|
-
|
|
1085
|
-
/** The anonymous continuation might belong to tight_tool, whose 50-byte
|
|
1086
|
-
* override is LOWER than the raised global cap — judging candidates
|
|
1087
|
-
* only against the global limit would let it stream past indefinitely. */
|
|
1088
|
-
await expect(
|
|
1089
|
-
streamToolCallChunks({
|
|
1090
|
-
handler,
|
|
1091
|
-
graph,
|
|
1092
|
-
chunks: [{ args: 'x'.repeat(60) }],
|
|
1093
|
-
})
|
|
1094
|
-
).rejects.toMatchObject({
|
|
1095
|
-
kind: 'tool_call_args',
|
|
1096
|
-
limit: 50,
|
|
1097
|
-
toolName: 'tight_tool',
|
|
1098
|
-
});
|
|
1099
|
-
});
|
|
1100
|
-
|
|
1101
|
-
it('keeps the sole live call\'s budget continuous across anonymous continuations', async () => {
|
|
1102
|
-
const handler = new ChatModelStreamHandler();
|
|
1103
|
-
const graph = createGraph({
|
|
1104
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
1105
|
-
});
|
|
1106
|
-
|
|
1107
|
-
await streamToolCallChunks({
|
|
1108
|
-
handler,
|
|
1109
|
-
graph,
|
|
1110
|
-
chunks: [{ id: 'call_a', name: 'writer', args: 'x'.repeat(60) }],
|
|
1111
|
-
});
|
|
1112
|
-
/** A second id-only call takes over the #0 position alias, then seals —
|
|
1113
|
-
* releasing it removes the alias while call_a stays live under its id. */
|
|
1114
|
-
await streamToolCallChunks({
|
|
1115
|
-
handler,
|
|
1116
|
-
graph,
|
|
1117
|
-
chunks: [{ id: 'call_b', name: 'other', args: 'x'.repeat(10) }],
|
|
1118
|
-
});
|
|
1119
|
-
await streamEvent({
|
|
1120
|
-
handler,
|
|
1121
|
-
graph,
|
|
1122
|
-
chunk: {
|
|
1123
|
-
content: '',
|
|
1124
|
-
tool_call_chunks: [{ id: 'call_b', args: '' }],
|
|
1125
|
-
response_metadata: {
|
|
1126
|
-
[STREAMED_TOOL_CALL_SEAL_METADATA_KEY]: {
|
|
1127
|
-
kind: 'single',
|
|
1128
|
-
id: 'call_b',
|
|
1129
|
-
},
|
|
1130
|
-
},
|
|
1131
|
-
},
|
|
1132
|
-
});
|
|
1133
|
-
|
|
1134
|
-
/** The anonymous continuation must charge call_a's existing 60-byte
|
|
1135
|
-
* tally — a fresh #0 tally would reset the sole remaining call's
|
|
1136
|
-
* budget and let combined args exceed the cap. */
|
|
1137
|
-
await expect(
|
|
1138
|
-
streamToolCallChunks({
|
|
1139
|
-
handler,
|
|
1140
|
-
graph,
|
|
1141
|
-
chunks: [{ args: 'x'.repeat(60) }],
|
|
1142
|
-
})
|
|
1143
|
-
).rejects.toMatchObject({ kind: 'tool_call_args', limit: 100 });
|
|
1144
|
-
});
|
|
1145
|
-
|
|
1146
|
-
it('still accounts when per-tool overrides exist with the global cap off', async () => {
|
|
1147
|
-
const handler = new ChatModelStreamHandler();
|
|
1148
|
-
const graph = createGraph({
|
|
1149
|
-
streamLimits: resolveStreamLimits({
|
|
1150
|
-
maxToolCallArgBytes: 0,
|
|
1151
|
-
maxToolCallArgBytesByTool: { create_file: 500 },
|
|
1152
|
-
}),
|
|
1153
|
-
});
|
|
1154
|
-
|
|
1155
|
-
await expect(
|
|
1156
|
-
streamToolCallChunks({
|
|
1157
|
-
handler,
|
|
1158
|
-
graph,
|
|
1159
|
-
chunks: [
|
|
1160
|
-
{ id: 'call_1', name: 'create_file', args: 'x'.repeat(501), index: 0 },
|
|
1161
|
-
],
|
|
1162
|
-
})
|
|
1163
|
-
).rejects.toMatchObject({
|
|
1164
|
-
kind: 'tool_call_args',
|
|
1165
|
-
limit: 500,
|
|
1166
|
-
toolName: 'create_file',
|
|
1167
|
-
});
|
|
1168
|
-
});
|
|
1169
|
-
|
|
1170
|
-
it('allocates nothing when overrides contain only zero-valued disables', async () => {
|
|
1171
|
-
const handler = new ChatModelStreamHandler();
|
|
1172
|
-
const graph = createGraph({
|
|
1173
|
-
streamLimits: resolveStreamLimits({
|
|
1174
|
-
maxToolCallArgBytes: 0,
|
|
1175
|
-
maxToolCallArgBytesByTool: { writer: 0 },
|
|
1176
|
-
}),
|
|
1177
|
-
});
|
|
1178
|
-
|
|
1179
|
-
/** `{ writer: 0 }` is a per-tool disable, not a limit — with the global
|
|
1180
|
-
* cap off too, no argument limit can fire and accounting must not
|
|
1181
|
-
* allocate. */
|
|
1182
|
-
await expect(
|
|
1183
|
-
streamToolCallChunks({
|
|
1184
|
-
handler,
|
|
1185
|
-
graph,
|
|
1186
|
-
chunks: [
|
|
1187
|
-
{ id: 'call_1', name: 'writer', args: 'x'.repeat(100_000), index: 0 },
|
|
1188
|
-
],
|
|
1189
|
-
})
|
|
1190
|
-
).resolves.toBeUndefined();
|
|
1191
|
-
expect(graph.streamLimitChargeCredits).toBeUndefined();
|
|
1192
|
-
expect(graph.streamedToolCallArgTallies).toBeUndefined();
|
|
1193
|
-
});
|
|
1194
|
-
|
|
1195
|
-
it('allocates no charge bookkeeping when every guard is disabled', async () => {
|
|
1196
|
-
const handler = new ChatModelStreamHandler();
|
|
1197
|
-
const graph = createGraph({
|
|
1198
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 0 }),
|
|
1199
|
-
});
|
|
1200
|
-
|
|
1201
|
-
await expect(
|
|
1202
|
-
streamToolCallChunks({
|
|
1203
|
-
handler,
|
|
1204
|
-
graph,
|
|
1205
|
-
chunks: [
|
|
1206
|
-
{ id: 'call_1', name: 'writer', args: 'x'.repeat(100_000), index: 0 },
|
|
1207
|
-
],
|
|
1208
|
-
})
|
|
1209
|
-
).resolves.toBeUndefined();
|
|
1210
|
-
expect(graph.streamLimitChargeCredits).toBeUndefined();
|
|
1211
|
-
expect(graph.streamedToolCallArgTallies).toBeUndefined();
|
|
1212
|
-
});
|
|
1213
|
-
|
|
1214
|
-
it('binds consumer trips to the event epoch, sparing a newer run', async () => {
|
|
1215
|
-
const handler = new ChatModelStreamHandler();
|
|
1216
|
-
const newRunBreaker = new AbortController();
|
|
1217
|
-
const graph = createGraph({
|
|
1218
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
1219
|
-
breakerAbort: newRunBreaker,
|
|
1220
|
-
breakerEpoch: 5,
|
|
1221
|
-
});
|
|
1222
|
-
|
|
1223
|
-
/** A straggling oversized chunk from a failed run (epoch 4) handled
|
|
1224
|
-
* after resetValues installed epoch 5 is dropped outright — acting on
|
|
1225
|
-
* it (content handling, eager dispatch) would compose the new run's
|
|
1226
|
-
* live controller — and the new run's controller stays live. */
|
|
1227
|
-
await expect(
|
|
1228
|
-
streamToolCallChunks({
|
|
1229
|
-
handler,
|
|
1230
|
-
graph,
|
|
1231
|
-
chunks: [
|
|
1232
|
-
{ id: 'call_1', name: 'writer', args: 'x'.repeat(101), index: 0 },
|
|
1233
|
-
],
|
|
1234
|
-
metadata: { [STREAM_LIMIT_EPOCH_KEY]: 4 },
|
|
1235
|
-
})
|
|
1236
|
-
).resolves.toBeUndefined();
|
|
1237
|
-
expect(newRunBreaker.signal.aborted).toBe(false);
|
|
1238
|
-
|
|
1239
|
-
/** Same breach with the matching epoch trips the controller. */
|
|
1240
|
-
await expect(
|
|
1241
|
-
streamToolCallChunks({
|
|
1242
|
-
handler,
|
|
1243
|
-
graph,
|
|
1244
|
-
chunks: [
|
|
1245
|
-
{ id: 'call_2', name: 'writer', args: 'x'.repeat(101), index: 0 },
|
|
1246
|
-
],
|
|
1247
|
-
metadata: { [STREAM_LIMIT_EPOCH_KEY]: 5 },
|
|
1248
|
-
})
|
|
1249
|
-
).rejects.toMatchObject({ kind: 'tool_call_args' });
|
|
1250
|
-
expect(newRunBreaker.signal.aborted).toBe(true);
|
|
1251
|
-
});
|
|
1252
|
-
|
|
1253
|
-
it('lets stale-epoch events pass the queued-event breaker check', async () => {
|
|
1254
|
-
const handler = new ChatModelStreamHandler();
|
|
1255
|
-
const breakerAbort = new AbortController();
|
|
1256
|
-
breakerAbort.abort(
|
|
1257
|
-
new StreamLimitExceededError({
|
|
1258
|
-
kind: 'tool_call_args',
|
|
1259
|
-
limit: 10,
|
|
1260
|
-
observed: 11,
|
|
1261
|
-
toolName: 'db_query',
|
|
1262
|
-
})
|
|
1263
|
-
);
|
|
1264
|
-
const graph = createGraph({
|
|
1265
|
-
streamLimits: resolveStreamLimits(),
|
|
1266
|
-
breakerAbort,
|
|
1267
|
-
breakerEpoch: 5,
|
|
1268
|
-
});
|
|
1269
|
-
|
|
1270
|
-
/** The tripped controller belongs to the CURRENT run (epoch 5); an
|
|
1271
|
-
* old-run chunk (epoch 4) must not be failed against it. The same
|
|
1272
|
-
* event WITH the matching epoch throws, proving only the epoch gate
|
|
1273
|
-
* differs. */
|
|
1274
|
-
await expect(
|
|
1275
|
-
streamEvent({
|
|
1276
|
-
handler,
|
|
1277
|
-
graph,
|
|
1278
|
-
chunk: { content: '' },
|
|
1279
|
-
metadata: { [STREAM_LIMIT_EPOCH_KEY]: 4 },
|
|
1280
|
-
})
|
|
1281
|
-
).resolves.toBeUndefined();
|
|
1282
|
-
|
|
1283
|
-
await expect(
|
|
1284
|
-
streamEvent({
|
|
1285
|
-
handler,
|
|
1286
|
-
graph,
|
|
1287
|
-
chunk: { content: '' },
|
|
1288
|
-
metadata: { [STREAM_LIMIT_EPOCH_KEY]: 5 },
|
|
1289
|
-
})
|
|
1290
|
-
).rejects.toMatchObject({ kind: 'tool_call_args' });
|
|
1291
|
-
});
|
|
1292
|
-
|
|
1293
|
-
it('treats empty tool-call ids as anonymous, keeping parallel calls apart', async () => {
|
|
1294
|
-
const handler = new ChatModelStreamHandler();
|
|
1295
|
-
const graph = createGraph({
|
|
1296
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
1297
|
-
});
|
|
1298
|
-
|
|
1299
|
-
/** OpenAI-compatible adapters can emit index-less parallel calls whose
|
|
1300
|
-
* ids are empty placeholders; a shared ':c:' identity would merge the
|
|
1301
|
-
* two 60-byte calls into a phantom 120-byte one and falsely trip. */
|
|
1302
|
-
await expect(
|
|
1303
|
-
streamEvent({
|
|
1304
|
-
handler,
|
|
1305
|
-
graph,
|
|
1306
|
-
chunk: {
|
|
1307
|
-
content: '',
|
|
1308
|
-
tool_call_chunks: [
|
|
1309
|
-
{ id: '', args: 'x'.repeat(60) },
|
|
1310
|
-
{ id: '', args: 'x'.repeat(60) },
|
|
1311
|
-
],
|
|
1312
|
-
},
|
|
1313
|
-
})
|
|
1314
|
-
).resolves.toBeUndefined();
|
|
1315
|
-
});
|
|
1316
|
-
|
|
1317
|
-
it('does not hand a lone parsed call\'s override to multiple id-less chunks', async () => {
|
|
1318
|
-
const handler = new ChatModelStreamHandler();
|
|
1319
|
-
const graph = createGraph({
|
|
1320
|
-
streamLimits: resolveStreamLimits({
|
|
1321
|
-
maxToolCallArgBytes: 100,
|
|
1322
|
-
maxToolCallArgBytesByTool: { create_file: 1_000 },
|
|
1323
|
-
}),
|
|
1324
|
-
});
|
|
1325
|
-
|
|
1326
|
-
/** Mixed event: two id-less raw chunks while only one call is parseable.
|
|
1327
|
-
* Positional correlation is ambiguous here — naming both chunks
|
|
1328
|
-
* 'create_file' would judge the unrelated 500-byte call against the
|
|
1329
|
-
* higher override and bypass the global cap. */
|
|
1330
|
-
await expect(
|
|
1331
|
-
streamEvent({
|
|
1332
|
-
handler,
|
|
1333
|
-
graph,
|
|
1334
|
-
chunk: {
|
|
1335
|
-
content: '',
|
|
1336
|
-
tool_call_chunks: [
|
|
1337
|
-
{ args: 'x'.repeat(50), index: 0 },
|
|
1338
|
-
{ args: 'x'.repeat(500), index: 1 },
|
|
1339
|
-
],
|
|
1340
|
-
tool_calls: [
|
|
1341
|
-
{ id: 'call_1', name: 'create_file', args: { content: 'x' } },
|
|
1342
|
-
],
|
|
1343
|
-
},
|
|
1344
|
-
})
|
|
1345
|
-
).rejects.toMatchObject({ kind: 'tool_call_args', limit: 100 });
|
|
1346
|
-
});
|
|
1347
|
-
|
|
1348
|
-
it('prefers the id-correlated complete name over a raw name fragment', async () => {
|
|
1349
|
-
const handler = new ChatModelStreamHandler();
|
|
1350
|
-
const graph = createGraph({
|
|
1351
|
-
streamLimits: resolveStreamLimits({
|
|
1352
|
-
maxToolCallArgBytes: 100,
|
|
1353
|
-
maxToolCallArgBytesByTool: { create_file: 1_000 },
|
|
1354
|
-
}),
|
|
1355
|
-
});
|
|
1356
|
-
|
|
1357
|
-
/** A custom adapter can emit a raw chunk whose name is only a FRAGMENT
|
|
1358
|
-
* ("create_") alongside the complete parsed call for the same id. The
|
|
1359
|
-
* complete call's name must select the per-tool override — judging the
|
|
1360
|
-
* bytes under the fragment would trip the global cap instead. */
|
|
1361
|
-
await expect(
|
|
1362
|
-
streamEvent({
|
|
1363
|
-
handler,
|
|
1364
|
-
graph,
|
|
1365
|
-
chunk: {
|
|
1366
|
-
content: '',
|
|
1367
|
-
tool_call_chunks: [
|
|
1368
|
-
{ id: 'call_1', name: 'create_', args: 'x'.repeat(500), index: 0 },
|
|
1369
|
-
],
|
|
1370
|
-
tool_calls: [
|
|
1371
|
-
{
|
|
1372
|
-
id: 'call_1',
|
|
1373
|
-
name: 'create_file',
|
|
1374
|
-
args: { content: 'x'.repeat(500) },
|
|
1375
|
-
},
|
|
1376
|
-
],
|
|
1377
|
-
},
|
|
1378
|
-
})
|
|
1379
|
-
).resolves.toBeUndefined();
|
|
1380
|
-
|
|
1381
|
-
await expect(
|
|
1382
|
-
streamToolCallChunks({
|
|
1383
|
-
handler,
|
|
1384
|
-
graph,
|
|
1385
|
-
chunks: [{ args: 'x'.repeat(501), index: 0 }],
|
|
1386
|
-
})
|
|
1387
|
-
).rejects.toMatchObject({
|
|
1388
|
-
kind: 'tool_call_args',
|
|
1389
|
-
limit: 1_000,
|
|
1390
|
-
toolName: 'create_file',
|
|
1391
|
-
});
|
|
1392
|
-
});
|
|
1393
|
-
|
|
1394
|
-
it('keeps an index 0 call and an id "0" call on separate budgets', async () => {
|
|
1395
|
-
const handler = new ChatModelStreamHandler();
|
|
1396
|
-
const graph = createGraph({
|
|
1397
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
1398
|
-
});
|
|
1399
|
-
|
|
1400
|
-
await streamToolCallChunks({
|
|
1401
|
-
handler,
|
|
1402
|
-
graph,
|
|
1403
|
-
chunks: [{ name: 'a_tool', args: 'a'.repeat(60), index: 0 }],
|
|
1404
|
-
});
|
|
1405
|
-
await streamToolCallChunks({
|
|
1406
|
-
handler,
|
|
1407
|
-
graph,
|
|
1408
|
-
chunks: [{ id: '0', name: 'b_tool', args: 'b'.repeat(60) }],
|
|
1409
|
-
});
|
|
1410
|
-
|
|
1411
|
-
await expect(
|
|
1412
|
-
streamToolCallChunks({
|
|
1413
|
-
handler,
|
|
1414
|
-
graph,
|
|
1415
|
-
chunks: [{ id: '0', args: 'b'.repeat(41) }],
|
|
1416
|
-
})
|
|
1417
|
-
).rejects.toMatchObject({
|
|
1418
|
-
kind: 'tool_call_args',
|
|
1419
|
-
observed: 101,
|
|
1420
|
-
toolName: 'b_tool',
|
|
1421
|
-
});
|
|
1422
|
-
});
|
|
1423
|
-
|
|
1424
|
-
it('adopts an anonymous tally when a later delta adds only an index', async () => {
|
|
1425
|
-
const handler = new ChatModelStreamHandler();
|
|
1426
|
-
const graph = createGraph({
|
|
1427
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
1428
|
-
});
|
|
1429
|
-
|
|
1430
|
-
await streamToolCallChunks({
|
|
1431
|
-
handler,
|
|
1432
|
-
graph,
|
|
1433
|
-
chunks: [{ name: 'writer', args: 'a'.repeat(60) }],
|
|
1434
|
-
});
|
|
1435
|
-
|
|
1436
|
-
await expect(
|
|
1437
|
-
streamToolCallChunks({
|
|
1438
|
-
handler,
|
|
1439
|
-
graph,
|
|
1440
|
-
chunks: [{ args: 'a'.repeat(41), index: 0 }],
|
|
1441
|
-
})
|
|
1442
|
-
).rejects.toMatchObject({
|
|
1443
|
-
kind: 'tool_call_args',
|
|
1444
|
-
observed: 101,
|
|
1445
|
-
toolName: 'writer',
|
|
1446
|
-
});
|
|
1447
|
-
});
|
|
1448
|
-
|
|
1449
|
-
it('adopts a sparse indexed continuation by its stable call index', async () => {
|
|
1450
|
-
const handler = new ChatModelStreamHandler();
|
|
1451
|
-
const graph = createGraph({
|
|
1452
|
-
streamLimits: resolveStreamLimits({
|
|
1453
|
-
maxToolCallArgBytes: 100,
|
|
1454
|
-
maxToolCallArgBytesByTool: { wide_tool: 1_000 },
|
|
1455
|
-
}),
|
|
1456
|
-
});
|
|
1457
|
-
|
|
1458
|
-
await streamEvent({
|
|
1459
|
-
handler,
|
|
1460
|
-
graph,
|
|
1461
|
-
chunk: {
|
|
1462
|
-
content: '',
|
|
1463
|
-
tool_call_chunks: [
|
|
1464
|
-
{ name: 'wide_tool', args: 'x'.repeat(60) },
|
|
1465
|
-
{ name: 'tight_tool', args: 'x'.repeat(40) },
|
|
1466
|
-
],
|
|
1467
|
-
},
|
|
1468
|
-
});
|
|
1469
|
-
|
|
1470
|
-
/** The event position is 0, but index 1 identifies the second call from
|
|
1471
|
-
* the original parallel batch. Its existing 40 bytes must stay under
|
|
1472
|
-
* the global cap rather than adopting wide_tool's raised allowance. */
|
|
1473
|
-
await expect(
|
|
1474
|
-
streamToolCallChunks({
|
|
1475
|
-
handler,
|
|
1476
|
-
graph,
|
|
1477
|
-
chunks: [{ args: 'x'.repeat(61), index: 1 }],
|
|
1478
|
-
})
|
|
1479
|
-
).rejects.toMatchObject({
|
|
1480
|
-
kind: 'tool_call_args',
|
|
1481
|
-
limit: 100,
|
|
1482
|
-
observed: 101,
|
|
1483
|
-
toolName: 'tight_tool',
|
|
1484
|
-
});
|
|
1485
|
-
});
|
|
1486
|
-
|
|
1487
|
-
it('adopts the sole anonymous tally when a later nonzero index appears', async () => {
|
|
1488
|
-
const handler = new ChatModelStreamHandler();
|
|
1489
|
-
const graph = createGraph({
|
|
1490
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
1491
|
-
});
|
|
1492
|
-
|
|
1493
|
-
await streamToolCallChunks({
|
|
1494
|
-
handler,
|
|
1495
|
-
graph,
|
|
1496
|
-
chunks: [{ name: 'writer', args: 'x'.repeat(60) }],
|
|
1497
|
-
});
|
|
1498
|
-
|
|
1499
|
-
await expect(
|
|
1500
|
-
streamToolCallChunks({
|
|
1501
|
-
handler,
|
|
1502
|
-
graph,
|
|
1503
|
-
chunks: [{ args: 'x'.repeat(41), index: 1 }],
|
|
1504
|
-
})
|
|
1505
|
-
).rejects.toMatchObject({
|
|
1506
|
-
kind: 'tool_call_args',
|
|
1507
|
-
observed: 101,
|
|
1508
|
-
toolName: 'writer',
|
|
1509
|
-
});
|
|
1510
|
-
});
|
|
1511
|
-
|
|
1512
|
-
it('does not use the sole anonymous fallback while another call is live', async () => {
|
|
1513
|
-
const handler = new ChatModelStreamHandler();
|
|
1514
|
-
const graph = createGraph({
|
|
1515
|
-
streamLimits: resolveStreamLimits({
|
|
1516
|
-
maxToolCallArgBytes: 100,
|
|
1517
|
-
maxToolCallArgBytesByTool: { wide_tool: 1_000 },
|
|
1518
|
-
}),
|
|
1519
|
-
});
|
|
1520
|
-
|
|
1521
|
-
await streamEvent({
|
|
1522
|
-
handler,
|
|
1523
|
-
graph,
|
|
1524
|
-
chunk: {
|
|
1525
|
-
content: '',
|
|
1526
|
-
tool_call_chunks: [
|
|
1527
|
-
{ id: 'call_a', name: 'tight_tool', args: 'x'.repeat(10) },
|
|
1528
|
-
{ name: 'wide_tool', args: 'x'.repeat(10) },
|
|
1529
|
-
],
|
|
1530
|
-
},
|
|
1531
|
-
});
|
|
1532
|
-
|
|
1533
|
-
/** Index 0 could identify call_a; the one anonymous tally belongs to
|
|
1534
|
-
* batch position 1 and must not lend wide_tool's raised override. */
|
|
1535
|
-
await expect(
|
|
1536
|
-
streamToolCallChunks({
|
|
1537
|
-
handler,
|
|
1538
|
-
graph,
|
|
1539
|
-
chunks: [{ args: 'x'.repeat(101), index: 0 }],
|
|
1540
|
-
})
|
|
1541
|
-
).rejects.toMatchObject({
|
|
1542
|
-
kind: 'tool_call_args',
|
|
1543
|
-
limit: 100,
|
|
1544
|
-
});
|
|
1545
|
-
});
|
|
1546
|
-
|
|
1547
|
-
it('applies a late anonymous name before charging its lower override', async () => {
|
|
1548
|
-
const handler = new ChatModelStreamHandler();
|
|
1549
|
-
const graph = createGraph({
|
|
1550
|
-
streamLimits: resolveStreamLimits({
|
|
1551
|
-
maxToolCallArgBytes: 1_000,
|
|
1552
|
-
maxToolCallArgBytesByTool: { tight_tool: 50 },
|
|
1553
|
-
}),
|
|
1554
|
-
});
|
|
1555
|
-
|
|
1556
|
-
await streamToolCallChunks({
|
|
1557
|
-
handler,
|
|
1558
|
-
graph,
|
|
1559
|
-
chunks: [{ args: 'x'.repeat(40) }],
|
|
1560
|
-
});
|
|
1561
|
-
|
|
1562
|
-
await expect(
|
|
1563
|
-
streamToolCallChunks({
|
|
1564
|
-
handler,
|
|
1565
|
-
graph,
|
|
1566
|
-
chunks: [{ name: 'tight_tool', args: 'x'.repeat(11) }],
|
|
1567
|
-
})
|
|
1568
|
-
).rejects.toMatchObject({
|
|
1569
|
-
kind: 'tool_call_args',
|
|
1570
|
-
limit: 50,
|
|
1571
|
-
observed: 51,
|
|
1572
|
-
toolName: 'tight_tool',
|
|
1573
|
-
});
|
|
1574
|
-
});
|
|
1575
|
-
|
|
1576
|
-
it('assembles a late anonymous name before applying its higher override', async () => {
|
|
1577
|
-
const handler = new ChatModelStreamHandler();
|
|
1578
|
-
const graph = createGraph({
|
|
1579
|
-
streamLimits: resolveStreamLimits({
|
|
1580
|
-
maxToolCallArgBytes: 100,
|
|
1581
|
-
maxToolCallArgBytesByTool: { create_file: 1_000 },
|
|
1582
|
-
}),
|
|
1583
|
-
});
|
|
1584
|
-
|
|
1585
|
-
await streamToolCallChunks({
|
|
1586
|
-
handler,
|
|
1587
|
-
graph,
|
|
1588
|
-
chunks: [{ name: 'create_', args: 'x'.repeat(60) }],
|
|
1589
|
-
});
|
|
1590
|
-
|
|
1591
|
-
await expect(
|
|
1592
|
-
streamToolCallChunks({
|
|
1593
|
-
handler,
|
|
1594
|
-
graph,
|
|
1595
|
-
chunks: [{ name: 'file', args: 'x'.repeat(60) }],
|
|
1596
|
-
})
|
|
1597
|
-
).resolves.toBeUndefined();
|
|
1598
|
-
});
|
|
1599
|
-
|
|
1600
|
-
it('names id-less raw chunks from a single parsed call so overrides apply', async () => {
|
|
1601
|
-
const handler = new ChatModelStreamHandler();
|
|
1602
|
-
const graph = createGraph({
|
|
1603
|
-
streamLimits: resolveStreamLimits({
|
|
1604
|
-
maxToolCallArgBytes: 100,
|
|
1605
|
-
maxToolCallArgBytesByTool: { create_file: 1_000 },
|
|
1606
|
-
}),
|
|
1607
|
-
});
|
|
1608
|
-
|
|
1609
|
-
await expect(
|
|
1610
|
-
streamEvent({
|
|
1611
|
-
handler,
|
|
1612
|
-
graph,
|
|
1613
|
-
chunk: {
|
|
1614
|
-
content: '',
|
|
1615
|
-
tool_call_chunks: [{ args: 'x'.repeat(500), index: 0 }],
|
|
1616
|
-
tool_calls: [
|
|
1617
|
-
{ id: 'call_1', name: 'create_file', args: { content: 'x'.repeat(500) } },
|
|
1618
|
-
],
|
|
1619
|
-
},
|
|
1620
|
-
})
|
|
1621
|
-
).resolves.toBeUndefined();
|
|
1622
|
-
});
|
|
1623
|
-
|
|
1624
|
-
it('matches a dual-identifier seal against a chunk carrying only its id', async () => {
|
|
1625
|
-
const handler = new ChatModelStreamHandler();
|
|
1626
|
-
const graph = createGraph({
|
|
1627
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
1628
|
-
});
|
|
1629
|
-
|
|
1630
|
-
await streamToolCallChunks({
|
|
1631
|
-
handler,
|
|
1632
|
-
graph,
|
|
1633
|
-
chunks: [{ id: 'call_1', name: 'writer', args: 'a'.repeat(60), index: 0 }],
|
|
1634
|
-
});
|
|
1635
|
-
|
|
1636
|
-
await expect(
|
|
1637
|
-
streamEvent({
|
|
1638
|
-
handler,
|
|
1639
|
-
graph,
|
|
1640
|
-
chunk: {
|
|
1641
|
-
content: '',
|
|
1642
|
-
tool_call_chunks: [{ id: 'call_1', args: 'a'.repeat(60) }],
|
|
1643
|
-
response_metadata: {
|
|
1644
|
-
[STREAMED_TOOL_CALL_SEAL_METADATA_KEY]: {
|
|
1645
|
-
kind: 'single',
|
|
1646
|
-
index: 0,
|
|
1647
|
-
id: 'call_1',
|
|
1648
|
-
},
|
|
1649
|
-
},
|
|
1650
|
-
},
|
|
1651
|
-
})
|
|
1652
|
-
).resolves.toBeUndefined();
|
|
1653
|
-
expect(graph.streamedToolCallArgTallies.size).toBe(0);
|
|
1654
|
-
});
|
|
1655
|
-
|
|
1656
|
-
it('adopts an anonymous tally when a later delta adds only an id', async () => {
|
|
1657
|
-
const handler = new ChatModelStreamHandler();
|
|
1658
|
-
const graph = createGraph({
|
|
1659
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
1660
|
-
});
|
|
1661
|
-
|
|
1662
|
-
await streamToolCallChunks({
|
|
1663
|
-
handler,
|
|
1664
|
-
graph,
|
|
1665
|
-
chunks: [{ name: 'writer', args: 'a'.repeat(60) }],
|
|
1666
|
-
});
|
|
1667
|
-
|
|
1668
|
-
await expect(
|
|
1669
|
-
streamToolCallChunks({
|
|
1670
|
-
handler,
|
|
1671
|
-
graph,
|
|
1672
|
-
chunks: [{ id: 'call_1', args: 'a'.repeat(41) }],
|
|
1673
|
-
})
|
|
1674
|
-
).rejects.toMatchObject({
|
|
1675
|
-
kind: 'tool_call_args',
|
|
1676
|
-
observed: 101,
|
|
1677
|
-
toolName: 'writer',
|
|
1678
|
-
});
|
|
1679
|
-
});
|
|
1680
|
-
|
|
1681
|
-
it('does not adopt a live id-bearing call through its position alias', async () => {
|
|
1682
|
-
const handler = new ChatModelStreamHandler();
|
|
1683
|
-
const graph = createGraph({
|
|
1684
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
1685
|
-
});
|
|
1686
|
-
|
|
1687
|
-
await streamToolCallChunks({
|
|
1688
|
-
handler,
|
|
1689
|
-
graph,
|
|
1690
|
-
chunks: [{ id: 'call_a', name: 'a_tool', args: 'a'.repeat(60) }],
|
|
1691
|
-
});
|
|
1692
|
-
|
|
1693
|
-
await expect(
|
|
1694
|
-
streamToolCallChunks({
|
|
1695
|
-
handler,
|
|
1696
|
-
graph,
|
|
1697
|
-
chunks: [{ id: 'call_b', name: 'b_tool', args: 'b'.repeat(60) }],
|
|
1698
|
-
})
|
|
1699
|
-
).resolves.toBeUndefined();
|
|
1700
|
-
});
|
|
1701
|
-
|
|
1702
|
-
it('judges invalid parsed tool calls that arrive without raw chunks', async () => {
|
|
1703
|
-
const handler = new ChatModelStreamHandler();
|
|
1704
|
-
const graph = createGraph({
|
|
1705
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
1706
|
-
});
|
|
1707
|
-
|
|
1708
|
-
await expect(
|
|
1709
|
-
streamEvent({
|
|
1710
|
-
handler,
|
|
1711
|
-
graph,
|
|
1712
|
-
chunk: {
|
|
1713
|
-
content: '',
|
|
1714
|
-
invalid_tool_calls: [
|
|
1715
|
-
{
|
|
1716
|
-
id: 'call_1',
|
|
1717
|
-
name: 'side_effect',
|
|
1718
|
-
args: 'x'.repeat(200),
|
|
1719
|
-
error: 'Unparseable arguments',
|
|
1720
|
-
},
|
|
1721
|
-
],
|
|
1722
|
-
},
|
|
1723
|
-
})
|
|
1724
|
-
).rejects.toMatchObject({
|
|
1725
|
-
kind: 'tool_call_args',
|
|
1726
|
-
limit: 100,
|
|
1727
|
-
toolName: 'side_effect',
|
|
1728
|
-
});
|
|
1729
|
-
});
|
|
1730
|
-
|
|
1731
|
-
it('keeps one budget when an index-only call drops its index', async () => {
|
|
1732
|
-
const handler = new ChatModelStreamHandler();
|
|
1733
|
-
const graph = createGraph({
|
|
1734
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
1735
|
-
});
|
|
1736
|
-
|
|
1737
|
-
await streamToolCallChunks({
|
|
1738
|
-
handler,
|
|
1739
|
-
graph,
|
|
1740
|
-
chunks: [{ name: 'writer', args: 'a'.repeat(60), index: 0 }],
|
|
1741
|
-
});
|
|
1742
|
-
|
|
1743
|
-
await expect(
|
|
1744
|
-
streamToolCallChunks({
|
|
1745
|
-
handler,
|
|
1746
|
-
graph,
|
|
1747
|
-
chunks: [{ args: 'a'.repeat(41) }],
|
|
1748
|
-
})
|
|
1749
|
-
).rejects.toMatchObject({
|
|
1750
|
-
kind: 'tool_call_args',
|
|
1751
|
-
observed: 101,
|
|
1752
|
-
toolName: 'writer',
|
|
1753
|
-
});
|
|
1754
|
-
});
|
|
1755
|
-
|
|
1756
|
-
it('names unnamed raw chunks from invalid calls so overrides apply', async () => {
|
|
1757
|
-
const handler = new ChatModelStreamHandler();
|
|
1758
|
-
const graph = createGraph({
|
|
1759
|
-
streamLimits: resolveStreamLimits({
|
|
1760
|
-
maxToolCallArgBytes: 100,
|
|
1761
|
-
maxToolCallArgBytesByTool: { create_file: 1_000 },
|
|
1762
|
-
}),
|
|
1763
|
-
});
|
|
1764
|
-
|
|
1765
|
-
await expect(
|
|
1766
|
-
streamEvent({
|
|
1767
|
-
handler,
|
|
1768
|
-
graph,
|
|
1769
|
-
chunk: {
|
|
1770
|
-
content: '',
|
|
1771
|
-
tool_call_chunks: [{ id: 'call_1', args: 'x'.repeat(500), index: 0 }],
|
|
1772
|
-
invalid_tool_calls: [
|
|
1773
|
-
{
|
|
1774
|
-
id: 'call_1',
|
|
1775
|
-
name: 'create_file',
|
|
1776
|
-
args: 'x'.repeat(500),
|
|
1777
|
-
error: 'Unparseable arguments',
|
|
1778
|
-
},
|
|
1779
|
-
],
|
|
1780
|
-
},
|
|
1781
|
-
})
|
|
1782
|
-
).resolves.toBeUndefined();
|
|
1783
|
-
});
|
|
1784
|
-
|
|
1785
|
-
it('accumulates fragmented tool names before selecting overrides', async () => {
|
|
1786
|
-
const handler = new ChatModelStreamHandler();
|
|
1787
|
-
const graph = createGraph({
|
|
1788
|
-
streamLimits: resolveStreamLimits({
|
|
1789
|
-
maxToolCallArgBytes: 100,
|
|
1790
|
-
maxToolCallArgBytesByTool: { create_file: 1_000 },
|
|
1791
|
-
}),
|
|
1792
|
-
});
|
|
1793
|
-
|
|
1794
|
-
await streamToolCallChunks({
|
|
1795
|
-
handler,
|
|
1796
|
-
graph,
|
|
1797
|
-
chunks: [{ id: 'call_1', name: 'create_', args: 'x'.repeat(50), index: 0 }],
|
|
1798
|
-
});
|
|
1799
|
-
await expect(
|
|
1800
|
-
streamToolCallChunks({
|
|
1801
|
-
handler,
|
|
1802
|
-
graph,
|
|
1803
|
-
chunks: [{ name: 'file', args: 'x'.repeat(100), index: 0 }],
|
|
1804
|
-
})
|
|
1805
|
-
).resolves.toBeUndefined();
|
|
1806
|
-
|
|
1807
|
-
await expect(
|
|
1808
|
-
streamToolCallChunks({
|
|
1809
|
-
handler,
|
|
1810
|
-
graph,
|
|
1811
|
-
chunks: [{ args: 'x'.repeat(900), index: 0 }],
|
|
1812
|
-
})
|
|
1813
|
-
).rejects.toMatchObject({
|
|
1814
|
-
kind: 'tool_call_args',
|
|
1815
|
-
limit: 1_000,
|
|
1816
|
-
observed: 1_050,
|
|
1817
|
-
toolName: 'create_file',
|
|
1818
|
-
});
|
|
1819
|
-
});
|
|
1820
|
-
|
|
1821
|
-
it('matches a seal by id when the indices disagree', async () => {
|
|
1822
|
-
const handler = new ChatModelStreamHandler();
|
|
1823
|
-
const graph = createGraph({
|
|
1824
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
1825
|
-
});
|
|
1826
|
-
|
|
1827
|
-
await streamToolCallChunks({
|
|
1828
|
-
handler,
|
|
1829
|
-
graph,
|
|
1830
|
-
chunks: [{ id: 'call_1', name: 'writer', args: 'a'.repeat(60), index: 0 }],
|
|
1831
|
-
});
|
|
1832
|
-
|
|
1833
|
-
await expect(
|
|
1834
|
-
streamEvent({
|
|
1835
|
-
handler,
|
|
1836
|
-
graph,
|
|
1837
|
-
chunk: {
|
|
1838
|
-
content: '',
|
|
1839
|
-
tool_call_chunks: [{ id: 'call_1', args: 'a'.repeat(60), index: 1 }],
|
|
1840
|
-
response_metadata: {
|
|
1841
|
-
[STREAMED_TOOL_CALL_SEAL_METADATA_KEY]: {
|
|
1842
|
-
kind: 'single',
|
|
1843
|
-
index: 0,
|
|
1844
|
-
id: 'call_1',
|
|
1845
|
-
},
|
|
1846
|
-
},
|
|
1847
|
-
},
|
|
1848
|
-
})
|
|
1849
|
-
).resolves.toBeUndefined();
|
|
1850
|
-
expect(graph.streamedToolCallArgTallies.size).toBe(0);
|
|
1851
|
-
});
|
|
1852
|
-
|
|
1853
|
-
it('trips the shared graph breaker when the consumer path detects a breach', async () => {
|
|
1854
|
-
const handler = new ChatModelStreamHandler();
|
|
1855
|
-
const breakerAbort = new AbortController();
|
|
1856
|
-
const graph = createGraph({
|
|
1857
|
-
streamLimits: resolveStreamLimits({ maxToolCallArgBytes: 100 }),
|
|
1858
|
-
breakerAbort,
|
|
1859
|
-
});
|
|
1860
|
-
|
|
1861
|
-
await expect(
|
|
1862
|
-
streamToolCallChunks({
|
|
1863
|
-
handler,
|
|
1864
|
-
graph,
|
|
1865
|
-
chunks: [{ id: 'call_1', name: 'writer', args: 'a'.repeat(101), index: 0 }],
|
|
1866
|
-
})
|
|
1867
|
-
).rejects.toMatchObject({ kind: 'tool_call_args' });
|
|
1868
|
-
|
|
1869
|
-
expect(breakerAbort.signal.aborted).toBe(true);
|
|
1870
|
-
expect(breakerAbort.signal.reason).toMatchObject({
|
|
1871
|
-
kind: 'tool_call_args',
|
|
1872
|
-
observed: 101,
|
|
1873
|
-
});
|
|
1874
|
-
});
|
|
1875
|
-
|
|
1876
|
-
it('allocates no charge credits for text-only deltas with the event cap off', async () => {
|
|
1877
|
-
const handler = new ChatModelStreamHandler();
|
|
1878
|
-
const graph = createGraph({
|
|
1879
|
-
streamLimits: resolveStreamLimits(),
|
|
1880
|
-
dispatchMessageDelta: jest.fn(async () => undefined),
|
|
1881
|
-
dispatchReasoningDelta: jest.fn(async () => undefined),
|
|
1882
|
-
} as never);
|
|
1883
|
-
|
|
1884
|
-
await streamEvent({
|
|
1885
|
-
handler,
|
|
1886
|
-
graph,
|
|
1887
|
-
chunk: { content: 'an ordinary text delta' },
|
|
1888
|
-
});
|
|
1889
|
-
expect(graph.streamLimitChargeCredits).toBeUndefined();
|
|
1890
|
-
|
|
1891
|
-
enforceStreamLimitsForWireChunk({
|
|
1892
|
-
graph,
|
|
1893
|
-
metadata: {},
|
|
1894
|
-
chunk: { tool_call_chunks: undefined } as never,
|
|
1895
|
-
});
|
|
1896
|
-
expect(graph.streamLimitChargeCredits).toBeUndefined();
|
|
1897
|
-
|
|
1898
|
-
await streamEvent({
|
|
1899
|
-
handler,
|
|
1900
|
-
graph,
|
|
1901
|
-
chunk: {
|
|
1902
|
-
content: '',
|
|
1903
|
-
tool_call_chunks: [{ id: 'call_1', name: 'writer', args: 'x', index: 0 }],
|
|
1904
|
-
},
|
|
1905
|
-
});
|
|
1906
|
-
expect(graph.streamLimitChargeCredits).toBeDefined();
|
|
1907
|
-
});
|
|
1908
|
-
|
|
1909
|
-
it('normalizes override entries like the global field', () => {
|
|
1910
|
-
const resolved = resolveStreamLimits({
|
|
1911
|
-
maxToolCallArgBytes: 100,
|
|
1912
|
-
maxToolCallArgBytesByTool: {
|
|
1913
|
-
create_file: 131_072.9,
|
|
1914
|
-
disabled_tool: -5,
|
|
1915
|
-
unlimited_tool: Infinity,
|
|
1916
|
-
invalid_tool: Number.NaN,
|
|
1917
|
-
'': 42,
|
|
1918
|
-
},
|
|
1919
|
-
});
|
|
1920
|
-
|
|
1921
|
-
expect(resolved.maxToolCallArgBytesByTool).toEqual({
|
|
1922
|
-
create_file: 131_072,
|
|
1923
|
-
disabled_tool: 0,
|
|
1924
|
-
unlimited_tool: 0,
|
|
1925
|
-
});
|
|
1926
|
-
});
|
|
1927
|
-
});
|
|
1928
|
-
|
|
1929
|
-
describe('per-generation delta event circuit breaker', () => {
|
|
1930
|
-
it('is opt-in and counts every streamed chunk event, including empty ones', async () => {
|
|
1931
|
-
const handler = new ChatModelStreamHandler();
|
|
1932
|
-
const graph = createGraph({
|
|
1933
|
-
streamLimits: resolveStreamLimits({ maxDeltaEventsPerTurn: 3 }),
|
|
1934
|
-
});
|
|
1935
|
-
|
|
1936
|
-
const emptyChunkEvent = (): Promise<void> =>
|
|
1937
|
-
streamEvent({ handler, graph, chunk: { content: '' }, metadata: generation(1) });
|
|
1938
|
-
|
|
1939
|
-
await emptyChunkEvent();
|
|
1940
|
-
await emptyChunkEvent();
|
|
1941
|
-
await emptyChunkEvent();
|
|
1942
|
-
await expect(emptyChunkEvent()).rejects.toMatchObject({
|
|
1943
|
-
name: 'StreamLimitExceededError',
|
|
1944
|
-
kind: 'delta_events',
|
|
1945
|
-
limit: 3,
|
|
1946
|
-
observed: 4,
|
|
1947
|
-
});
|
|
1948
|
-
});
|
|
1949
|
-
|
|
1950
|
-
it('scopes the budget per model generation, surviving step-key forks', async () => {
|
|
1951
|
-
const handler = new ChatModelStreamHandler();
|
|
1952
|
-
let stepKey = 'reasoning-key';
|
|
1953
|
-
const graph = createGraph({
|
|
1954
|
-
streamLimits: resolveStreamLimits({ maxDeltaEventsPerTurn: 2 }),
|
|
1955
|
-
getStepKey: jest.fn(() => stepKey) as unknown as StandardGraph['getStepKey'],
|
|
1956
|
-
});
|
|
1957
|
-
|
|
1958
|
-
const emptyChunkEvent = (step: number): Promise<void> =>
|
|
1959
|
-
streamEvent({ handler, graph, chunk: { content: '' }, metadata: generation(step) });
|
|
1960
|
-
|
|
1961
|
-
await emptyChunkEvent(1);
|
|
1962
|
-
stepKey = 'post-reasoning-key';
|
|
1963
|
-
await emptyChunkEvent(1);
|
|
1964
|
-
await expect(emptyChunkEvent(1)).rejects.toMatchObject({
|
|
1965
|
-
kind: 'delta_events',
|
|
1966
|
-
observed: 3,
|
|
1967
|
-
});
|
|
1968
|
-
|
|
1969
|
-
await emptyChunkEvent(2);
|
|
1970
|
-
expect(graph.streamDeltaEventCounts.get('|agent|2|')?.count).toBe(1);
|
|
1971
|
-
});
|
|
1972
|
-
|
|
1973
|
-
it('never counts when left at the default (disabled)', async () => {
|
|
1974
|
-
const handler = new ChatModelStreamHandler();
|
|
1975
|
-
const graph = createGraph({ streamLimits: resolveStreamLimits() });
|
|
1976
|
-
|
|
1977
|
-
for (let i = 0; i < 10; i++) {
|
|
1978
|
-
await streamEvent({ handler, graph, chunk: { content: '' }, metadata: generation(1) });
|
|
1979
|
-
}
|
|
1980
|
-
expect(graph.streamDeltaEventCounts).toBeUndefined();
|
|
1981
|
-
});
|
|
1982
|
-
});
|