@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,44 +1,7 @@
|
|
|
1
1
|
//#region src/hooks/matchers.ts
|
|
2
|
-
/**
|
|
3
|
-
* Upper bound on hook-matcher pattern length. Patterns longer than this
|
|
4
|
-
* are rejected outright — the goal is a cheap cap on pathological inputs
|
|
5
|
-
* (repeated quantifiers, huge alternation groups) without pulling in a
|
|
6
|
-
* safe-regex dependency.
|
|
7
|
-
*
|
|
8
|
-
* Legitimate matchers are almost always under 50 characters (tool names,
|
|
9
|
-
* short alternations, simple prefix anchors); 512 leaves generous
|
|
10
|
-
* headroom while preventing 10KB regexes.
|
|
11
|
-
*/
|
|
12
2
|
const MAX_PATTERN_LENGTH = 512;
|
|
13
|
-
/**
|
|
14
|
-
* Upper bound on the compilation cache. Chosen to comfortably hold every
|
|
15
|
-
* distinct pattern a single multi-tenant run is likely to see (tools,
|
|
16
|
-
* agent types, basename filters) without growing without bound.
|
|
17
|
-
*
|
|
18
|
-
* Under hosts that register unique patterns per tenant, LRU eviction
|
|
19
|
-
* keeps the working set bounded — cold patterns are re-compiled on next
|
|
20
|
-
* use, which is the correct cost trade-off for long-running processes
|
|
21
|
-
* that must not leak memory.
|
|
22
|
-
*/
|
|
23
3
|
const MAX_CACHE_SIZE = 256;
|
|
24
|
-
/**
|
|
25
|
-
* Module-level LRU cache keyed by pattern string. Map iteration order is
|
|
26
|
-
* insertion order in ECMAScript, so refreshing an entry's position means
|
|
27
|
-
* "delete then re-set". On overflow we evict the first key (least
|
|
28
|
-
* recently used).
|
|
29
|
-
*
|
|
30
|
-
* Failed compiles are cached as `{ regex: null }` so a malformed pattern
|
|
31
|
-
* does not re-enter the compiler — and so a tenant spamming bad patterns
|
|
32
|
-
* doesn't burn CPU on every call.
|
|
33
|
-
*/
|
|
34
4
|
const patternCache = /* @__PURE__ */ new Map();
|
|
35
|
-
/**
|
|
36
|
-
* Threshold above which `touchCacheEntry` actually performs the LRU
|
|
37
|
-
* refresh. Below this watermark the cache has zero eviction pressure, so
|
|
38
|
-
* the delete+set on every hit would be pure overhead. Above it we refresh
|
|
39
|
-
* properly so hot patterns survive evictions. 75% of capacity is the
|
|
40
|
-
* standard sweet spot.
|
|
41
|
-
*/
|
|
42
5
|
const LRU_REFRESH_THRESHOLD = Math.floor(256 * 3 / 4);
|
|
43
6
|
function touchCacheEntry(pattern, entry) {
|
|
44
7
|
if (patternCache.size < LRU_REFRESH_THRESHOLD) return;
|
|
@@ -65,38 +28,6 @@ function skipGroupSyntaxPrefix(pattern, start) {
|
|
|
65
28
|
if (i < pattern.length) i++;
|
|
66
29
|
return i;
|
|
67
30
|
}
|
|
68
|
-
/**
|
|
69
|
-
* Cheap syntactic detector for the most common catastrophic-backtracking
|
|
70
|
-
* shape: a quantified group that contains another quantifier (e.g.
|
|
71
|
-
* `(a+)+`, `(.*)*`, `(\w+)+$`, `(?:(a+))+`). This is the "nested
|
|
72
|
-
* quantifier" class of ReDoS — runs in polynomial-or-worse time on
|
|
73
|
-
* adversarial inputs.
|
|
74
|
-
*
|
|
75
|
-
* The scan walks the pattern linearly using an explicit stack of group
|
|
76
|
-
* frames. For each group it tracks whether the group's contents include
|
|
77
|
-
* "backtrack risk" — meaning a direct quantifier OR a nested group that
|
|
78
|
-
* carries risk up. When a group closes with a trailing quantifier AND its
|
|
79
|
-
* frame carries backtrack risk, the pattern is flagged. Risk propagates
|
|
80
|
-
* to the enclosing frame when a child group closes (whether the child
|
|
81
|
-
* itself was quantified or not), so `(?:(a+))+` — equivalent to `(a+)+`
|
|
82
|
-
* — is flagged correctly even though the outer non-capturing wrapper is
|
|
83
|
-
* one level removed from the inner quantifier.
|
|
84
|
-
*
|
|
85
|
-
* ## Group-syntax prefixes
|
|
86
|
-
*
|
|
87
|
-
* Non-capturing groups (`(?:`), lookaheads (`(?=`, `(?!`), lookbehinds
|
|
88
|
-
* (`(?<=`, `(?<!`), and named groups (`(?<name>`) are skipped over at
|
|
89
|
-
* the `(` so their `?` is not misread as a quantifier. Without this,
|
|
90
|
-
* `(?:pre_)?tool_name` would be incorrectly rejected because the scanner
|
|
91
|
-
* would see the group-syntax `?` as a quantifier at depth 1.
|
|
92
|
-
*
|
|
93
|
-
* ## Heuristic, not a proof
|
|
94
|
-
*
|
|
95
|
-
* This catches the common forms but not all. Ambiguous-alternation ReDoS
|
|
96
|
-
* like `(a|a)+` is not detected. Pathologically long patterns are also
|
|
97
|
-
* caught by {@link MAX_PATTERN_LENGTH}. Hosts that accept user-supplied
|
|
98
|
-
* patterns must still validate upstream.
|
|
99
|
-
*/
|
|
100
31
|
function hasNestedQuantifier(pattern) {
|
|
101
32
|
const stack = [];
|
|
102
33
|
let i = 0;
|
|
@@ -171,41 +102,6 @@ function compile(pattern) {
|
|
|
171
102
|
return null;
|
|
172
103
|
}
|
|
173
104
|
}
|
|
174
|
-
/**
|
|
175
|
-
* Tests whether a hook matcher pattern matches the given query string.
|
|
176
|
-
*
|
|
177
|
-
* ## Semantics
|
|
178
|
-
*
|
|
179
|
-
* - `undefined` or empty `pattern` matches any query (wildcard). This is
|
|
180
|
-
* the intended shape for events that do not supply a query string at
|
|
181
|
-
* all (`RunStart`, `Stop`, etc.) — register such matchers without a
|
|
182
|
-
* pattern.
|
|
183
|
-
* - `undefined` or empty `query` with a non-empty `pattern` never matches.
|
|
184
|
-
* Setting a pattern on a query-less event is therefore inert: the
|
|
185
|
-
* matcher will simply never fire. This is intentional — it keeps
|
|
186
|
-
* query-based filtering out of event types where "query" has no meaning,
|
|
187
|
-
* and is documented on `HookMatcher.pattern`.
|
|
188
|
-
* - Otherwise, the pattern is compiled once (via a bounded LRU cache) and
|
|
189
|
-
* tested against the query.
|
|
190
|
-
* - Invalid regex patterns never throw — a failed compile is cached as
|
|
191
|
-
* "never matches" so a single malformed pattern cannot take out a whole
|
|
192
|
-
* `executeHooks` batch.
|
|
193
|
-
*
|
|
194
|
-
* ## ReDoS mitigations
|
|
195
|
-
*
|
|
196
|
-
* Patterns compile through three cheap gates before reaching `new RegExp`:
|
|
197
|
-
*
|
|
198
|
-
* 1. {@link MAX_PATTERN_LENGTH} length cap rejects oversized inputs.
|
|
199
|
-
* 2. {@link hasNestedQuantifier} rejects the most common catastrophic-
|
|
200
|
-
* backtracking shape (quantified group containing a quantifier).
|
|
201
|
-
* 3. Successful compiles are cached in a bounded LRU so repeated calls
|
|
202
|
-
* never re-enter the regex compiler.
|
|
203
|
-
*
|
|
204
|
-
* These are a floor, not a ceiling. Hosts that accept user-supplied
|
|
205
|
-
* patterns should still validate upstream. The design report §3.8 routes
|
|
206
|
-
* persistable hooks through a host-side compiler before they reach this
|
|
207
|
-
* module.
|
|
208
|
-
*/
|
|
209
105
|
function matchesQuery(pattern, query) {
|
|
210
106
|
if (pattern === void 0 || pattern === "") return true;
|
|
211
107
|
if (query === void 0 || query === "") return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matchers.mjs","names":[],"sources":["../../../src/hooks/matchers.ts"],"sourcesContent":["// src/hooks/matchers.ts\n\n/**\n * Upper bound on hook-matcher pattern length. Patterns longer than this\n * are rejected outright — the goal is a cheap cap on pathological inputs\n * (repeated quantifiers, huge alternation groups) without pulling in a\n * safe-regex dependency.\n *\n * Legitimate matchers are almost always under 50 characters (tool names,\n * short alternations, simple prefix anchors); 512 leaves generous\n * headroom while preventing 10KB regexes.\n */\nexport const MAX_PATTERN_LENGTH = 512;\n\n/**\n * Upper bound on the compilation cache. Chosen to comfortably hold every\n * distinct pattern a single multi-tenant run is likely to see (tools,\n * agent types, basename filters) without growing without bound.\n *\n * Under hosts that register unique patterns per tenant, LRU eviction\n * keeps the working set bounded — cold patterns are re-compiled on next\n * use, which is the correct cost trade-off for long-running processes\n * that must not leak memory.\n */\nexport const MAX_CACHE_SIZE = 256;\n\ninterface CacheEntry {\n regex: RegExp | null;\n}\n\n/**\n * Module-level LRU cache keyed by pattern string. Map iteration order is\n * insertion order in ECMAScript, so refreshing an entry's position means\n * \"delete then re-set\". On overflow we evict the first key (least\n * recently used).\n *\n * Failed compiles are cached as `{ regex: null }` so a malformed pattern\n * does not re-enter the compiler — and so a tenant spamming bad patterns\n * doesn't burn CPU on every call.\n */\nconst patternCache: Map<string, CacheEntry> = new Map();\n\n/**\n * Threshold above which `touchCacheEntry` actually performs the LRU\n * refresh. Below this watermark the cache has zero eviction pressure, so\n * the delete+set on every hit would be pure overhead. Above it we refresh\n * properly so hot patterns survive evictions. 75% of capacity is the\n * standard sweet spot.\n */\nconst LRU_REFRESH_THRESHOLD = Math.floor((MAX_CACHE_SIZE * 3) / 4);\n\nfunction touchCacheEntry(pattern: string, entry: CacheEntry): void {\n if (patternCache.size < LRU_REFRESH_THRESHOLD) {\n return;\n }\n patternCache.delete(pattern);\n patternCache.set(pattern, entry);\n}\n\nfunction setCacheEntry(pattern: string, entry: CacheEntry): void {\n if (patternCache.size >= MAX_CACHE_SIZE) {\n const oldestKey = patternCache.keys().next().value;\n if (oldestKey !== undefined) {\n patternCache.delete(oldestKey);\n }\n }\n patternCache.set(pattern, entry);\n}\n\ninterface QuantifierFrame {\n hasBacktrackRisk: boolean;\n}\n\nfunction skipGroupSyntaxPrefix(pattern: string, start: number): number {\n if (start >= pattern.length || pattern[start] !== '?') {\n return start;\n }\n let i = start + 1;\n if (i >= pattern.length) {\n return i;\n }\n const modifier = pattern[i];\n if (modifier === ':' || modifier === '=' || modifier === '!') {\n return i + 1;\n }\n if (modifier !== '<') {\n return i;\n }\n i++;\n if (i < pattern.length && (pattern[i] === '=' || pattern[i] === '!')) {\n return i + 1;\n }\n while (i < pattern.length && pattern[i] !== '>') {\n i++;\n }\n if (i < pattern.length) {\n i++;\n }\n return i;\n}\n\n/**\n * Cheap syntactic detector for the most common catastrophic-backtracking\n * shape: a quantified group that contains another quantifier (e.g.\n * `(a+)+`, `(.*)*`, `(\\w+)+$`, `(?:(a+))+`). This is the \"nested\n * quantifier\" class of ReDoS — runs in polynomial-or-worse time on\n * adversarial inputs.\n *\n * The scan walks the pattern linearly using an explicit stack of group\n * frames. For each group it tracks whether the group's contents include\n * \"backtrack risk\" — meaning a direct quantifier OR a nested group that\n * carries risk up. When a group closes with a trailing quantifier AND its\n * frame carries backtrack risk, the pattern is flagged. Risk propagates\n * to the enclosing frame when a child group closes (whether the child\n * itself was quantified or not), so `(?:(a+))+` — equivalent to `(a+)+`\n * — is flagged correctly even though the outer non-capturing wrapper is\n * one level removed from the inner quantifier.\n *\n * ## Group-syntax prefixes\n *\n * Non-capturing groups (`(?:`), lookaheads (`(?=`, `(?!`), lookbehinds\n * (`(?<=`, `(?<!`), and named groups (`(?<name>`) are skipped over at\n * the `(` so their `?` is not misread as a quantifier. Without this,\n * `(?:pre_)?tool_name` would be incorrectly rejected because the scanner\n * would see the group-syntax `?` as a quantifier at depth 1.\n *\n * ## Heuristic, not a proof\n *\n * This catches the common forms but not all. Ambiguous-alternation ReDoS\n * like `(a|a)+` is not detected. Pathologically long patterns are also\n * caught by {@link MAX_PATTERN_LENGTH}. Hosts that accept user-supplied\n * patterns must still validate upstream.\n */\nexport function hasNestedQuantifier(pattern: string): boolean {\n const stack: QuantifierFrame[] = [];\n let i = 0;\n while (i < pattern.length) {\n const ch = pattern[i];\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '[') {\n i = findCharClassEnd(pattern, i) + 1;\n continue;\n }\n if (ch === '(') {\n stack.push({ hasBacktrackRisk: false });\n i = skipGroupSyntaxPrefix(pattern, i + 1);\n continue;\n }\n if (ch === ')') {\n const frame = stack.pop();\n if (frame === undefined) {\n i++;\n continue;\n }\n const next = pattern[i + 1];\n const isQuantifier =\n next === '*' || next === '+' || next === '?' || next === '{';\n if (isQuantifier && frame.hasBacktrackRisk) {\n return true;\n }\n if (stack.length > 0 && (frame.hasBacktrackRisk || isQuantifier)) {\n stack[stack.length - 1].hasBacktrackRisk = true;\n }\n i++;\n continue;\n }\n if (ch === '*' || ch === '+' || ch === '?' || ch === '{') {\n if (stack.length > 0) {\n stack[stack.length - 1].hasBacktrackRisk = true;\n }\n }\n i++;\n }\n return false;\n}\n\nfunction findCharClassEnd(pattern: string, start: number): number {\n let i = start + 1;\n while (i < pattern.length) {\n const ch = pattern[i];\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === ']') {\n return i;\n }\n i++;\n }\n return pattern.length - 1;\n}\n\nfunction compile(pattern: string): RegExp | null {\n const cached = patternCache.get(pattern);\n if (cached !== undefined) {\n touchCacheEntry(pattern, cached);\n return cached.regex;\n }\n if (pattern.length > MAX_PATTERN_LENGTH) {\n setCacheEntry(pattern, { regex: null });\n return null;\n }\n if (hasNestedQuantifier(pattern)) {\n setCacheEntry(pattern, { regex: null });\n return null;\n }\n try {\n const regex = new RegExp(pattern);\n setCacheEntry(pattern, { regex });\n return regex;\n } catch {\n setCacheEntry(pattern, { regex: null });\n return null;\n }\n}\n\n/**\n * Tests whether a hook matcher pattern matches the given query string.\n *\n * ## Semantics\n *\n * - `undefined` or empty `pattern` matches any query (wildcard). This is\n * the intended shape for events that do not supply a query string at\n * all (`RunStart`, `Stop`, etc.) — register such matchers without a\n * pattern.\n * - `undefined` or empty `query` with a non-empty `pattern` never matches.\n * Setting a pattern on a query-less event is therefore inert: the\n * matcher will simply never fire. This is intentional — it keeps\n * query-based filtering out of event types where \"query\" has no meaning,\n * and is documented on `HookMatcher.pattern`.\n * - Otherwise, the pattern is compiled once (via a bounded LRU cache) and\n * tested against the query.\n * - Invalid regex patterns never throw — a failed compile is cached as\n * \"never matches\" so a single malformed pattern cannot take out a whole\n * `executeHooks` batch.\n *\n * ## ReDoS mitigations\n *\n * Patterns compile through three cheap gates before reaching `new RegExp`:\n *\n * 1. {@link MAX_PATTERN_LENGTH} length cap rejects oversized inputs.\n * 2. {@link hasNestedQuantifier} rejects the most common catastrophic-\n * backtracking shape (quantified group containing a quantifier).\n * 3. Successful compiles are cached in a bounded LRU so repeated calls\n * never re-enter the regex compiler.\n *\n * These are a floor, not a ceiling. Hosts that accept user-supplied\n * patterns should still validate upstream. The design report §3.8 routes\n * persistable hooks through a host-side compiler before they reach this\n * module.\n */\nexport function matchesQuery(\n pattern: string | undefined,\n query: string | undefined\n): boolean {\n if (pattern === undefined || pattern === '') {\n return true;\n }\n if (query === undefined || query === '') {\n return false;\n }\n const regex = compile(pattern);\n if (regex === null) {\n return false;\n }\n return regex.test(query);\n}\n\n/** Clears the regex compilation cache. Intended for test isolation. */\nexport function clearMatcherCache(): void {\n patternCache.clear();\n}\n\n/** Returns the current size of the compilation cache. Intended for tests. */\nexport function getMatcherCacheSize(): number {\n return patternCache.size;\n}\n"],"mappings":";;;;;;;;;;;AAYA,MAAa,qBAAqB;;;;;;;;;;;AAYlC,MAAa,iBAAiB;;;;;;;;;;;AAgB9B,MAAM,+BAAwC,IAAI,IAAI;;;;;;;;AAStD,MAAM,wBAAwB,KAAK,MAAA,MAAwB,IAAK,CAAC;AAEjE,SAAS,gBAAgB,SAAiB,OAAyB;CACjE,IAAI,aAAa,OAAO,uBACtB;CAEF,aAAa,OAAO,OAAO;CAC3B,aAAa,IAAI,SAAS,KAAK;AACjC;AAEA,SAAS,cAAc,SAAiB,OAAyB;CAC/D,IAAI,aAAa,QAAA,KAAwB;EACvC,MAAM,YAAY,aAAa,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC;EAC7C,IAAI,cAAc,KAAA,GAChB,aAAa,OAAO,SAAS;CAEjC;CACA,aAAa,IAAI,SAAS,KAAK;A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S;CACT,IAAI,YAAY,KAAA,KAAa,YAAY,IACvC,OAAO;CAET,IAAI,UAAU,KAAA,KAAa,UAAU,IACnC,OAAO;CAET,MAAM,QAAQ,QAAQ,OAAO;CAC7B,IAAI,UAAU,MACZ,OAAO;CAET,OAAO,MAAM,KAAK,KAAK;AACzB"}
|
package/dist/esm/hooks/types.mjs
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
//#region src/hooks/types.ts
|
|
2
|
-
/**
|
|
3
|
-
* Closed set of hook lifecycle events supported by the hooks system.
|
|
4
|
-
*
|
|
5
|
-
* These mirror the subset of Claude Code's event surface that makes sense
|
|
6
|
-
* for a library context (no filesystem/CLI-specific events). See
|
|
7
|
-
* `docs/hooks-design-report.md` §3.2 for the mapping to existing
|
|
8
|
-
* `@librechat/agents` emission points.
|
|
9
|
-
*/
|
|
10
2
|
const HOOK_EVENTS = [
|
|
11
3
|
"RunStart",
|
|
12
4
|
"UserPromptSubmit",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","names":[],"sources":["../../../src/hooks/types.ts"],"sourcesContent":["// src/hooks/types.ts\nimport type { BaseMessage } from '@langchain/core/messages';\nimport type { InjectedMessage } from '@/types/tools';\n\n/**\n * Closed set of hook lifecycle events supported by the hooks system.\n *\n * These mirror the subset of Claude Code's event surface that makes sense\n * for a library context (no filesystem/CLI-specific events). See\n * `docs/hooks-design-report.md` §3.2 for the mapping to existing\n * `@librechat/agents` emission points.\n */\nexport const HOOK_EVENTS = [\n 'RunStart',\n 'UserPromptSubmit',\n 'PreToolUse',\n 'PostToolUse',\n 'PostToolUseFailure',\n 'PostToolBatch',\n 'PreemptBoundary',\n 'PermissionDenied',\n 'SubagentStart',\n 'SubagentStop',\n 'Stop',\n 'StopFailure',\n 'PreCompact',\n 'PostCompact',\n] as const;\n\nexport const TOOL_APPROVAL_EXECUTION_SCOPE_CONFIG_KEY =\n '__librechat_tool_approval_execution_scope';\n\nexport type HookEvent = (typeof HOOK_EVENTS)[number];\n\n/** Tool-gating decision; executeHooks folds with `deny > ask > allow` precedence. */\nexport type ToolDecision = 'allow' | 'deny' | 'ask';\n\n/** Stop-loop decision; `block` means \"do not stop, run another turn\". Any `block` wins. */\nexport type StopDecision = 'continue' | 'block';\n\n/**\n * Fields shared by every `HookInput`. Discriminated by `hook_event_name`.\n *\n * - `runId` identifies the current agent run and is always present.\n * - `threadId` identifies the conversation thread when the host has one.\n * - `agentId` is only set when the hook fires inside a subagent scope.\n * - `executingAgentId` identifies the agent that owns the node emitting the hook,\n * whenever the graph knows it — including top-level agents in a multi-agent\n * graph (where `agentId` is intentionally undefined). Use this to attribute a\n * hook to a specific agent regardless of subagent scope.\n */\nexport interface BaseHookInput {\n runId: string;\n threadId?: string;\n agentId?: string;\n executingAgentId?: string;\n}\n\nexport interface RunStartHookInput extends BaseHookInput {\n hook_event_name: 'RunStart';\n messages: BaseMessage[];\n}\n\nexport interface UserPromptSubmitHookInput extends BaseHookInput {\n hook_event_name: 'UserPromptSubmit';\n prompt: string;\n attachments?: BaseMessage[];\n}\n\n/**\n * Fires before a tool is invoked. Hook may return `deny`/`ask`/`allow` and/or\n * an `updatedInput` that replaces the tool arguments before invocation.\n *\n * `toolInput` is intentionally typed as `Record<string, unknown>` because the\n * SDK is tool-agnostic — concrete tool argument shapes are only known at the\n * call site and are narrowed by the host. This is the one escape hatch in\n * the hook type system.\n */\nexport interface PreToolUseHookInput extends BaseHookInput {\n hook_event_name: 'PreToolUse';\n toolName: string;\n toolInput: Record<string, unknown>;\n toolUseId: string;\n stepId?: string;\n /**\n * Number of times this tool has been invoked in prior batches within the\n * current run. Within a single batch of parallel calls, all calls to the\n * same tool share the same turn value — per-call discrimination within a\n * batch is not supported in v1.\n */\n turn?: number;\n}\n\nexport interface PostToolUseHookInput extends BaseHookInput {\n hook_event_name: 'PostToolUse';\n toolName: string;\n toolInput: Record<string, unknown>;\n toolOutput: unknown;\n toolUseId: string;\n stepId?: string;\n turn?: number;\n}\n\nexport interface PostToolUseFailureHookInput extends BaseHookInput {\n hook_event_name: 'PostToolUseFailure';\n toolName: string;\n toolInput: Record<string, unknown>;\n toolUseId: string;\n error: string;\n stepId?: string;\n turn?: number;\n}\n\n/**\n * Per-tool result snapshot included in a `PostToolBatch` event. Mirrors\n * the data PostToolUse / PostToolUseFailure get individually, but the\n * batch view lets a single hook see the whole set so it can inject one\n * consolidated convention/audit message rather than N per-tool ones.\n */\nexport interface PostToolBatchEntry {\n toolName: string;\n toolInput: Record<string, unknown>;\n toolUseId: string;\n stepId?: string;\n turn?: number;\n /** Successful tool output, present only when `status === 'success'`. */\n toolOutput?: unknown;\n /** Error message, present only when `status === 'error'`. */\n error?: string;\n status: 'success' | 'error';\n}\n\n/**\n * Fires once after every tool call in a single batch finishes (including\n * any that were rejected via HITL). Lets a hook react to the batch as a\n * whole — useful for \"inject conventions once for the whole batch\", batch\n * audit logging, or coordinating cleanup that depends on knowing the full\n * result set rather than streaming each tool's result independently.\n *\n * Order: fires AFTER all per-tool PostToolUse / PostToolUseFailure hooks\n * for the same batch have completed, BEFORE the next model call. Pass an\n * `additionalContext` to inject context for that next model turn, or\n * `injectedMessages` to inject standalone per-message user speech (e.g.\n * mid-run steering) that must not be consolidated with hook context.\n */\nexport interface PostToolBatchHookInput extends BaseHookInput {\n hook_event_name: 'PostToolBatch';\n /** All tool calls (and their outcomes) from this batch, in batch order. */\n entries: PostToolBatchEntry[];\n}\n\n/**\n * Fires when a cooperative preemption seals the model stream mid-generation\n * — the second injection boundary, and the only one that exists during a\n * long text answer with no tool calls in it.\n *\n * Order: fires after the model stream is sealed and BEFORE the next model\n * call. The `injectedMessages` a hook returns here are appended verbatim and\n * the agent node self-loops. Returning nothing is a valid outcome (the host's\n * queue was cancelled or already drained): the run stops honestly rather than\n * self-looping into an empty turn.\n *\n * The sealed turn is NOT yet observable from graph state when this fires.\n * Dispatch happens inside the agent node, and only the outer graph's reducer\n * writes `StandardGraph.messages` — which cannot run until the node returns.\n * A hook calling `Run.getRunMessages()` here sees the state as of the last\n * completed superstep, so the sealed text is absent. `PostToolBatch` behaves\n * the same way: a tool-boundary hook cannot see the assistant turn that\n * requested the tool. This is a property of the single-node outer graph, not\n * of preemption, and committing first would mean returning from the node and\n * re-entering — precisely what the self-loop exists to avoid.\n *\n * A hook that needs the sealed text should therefore not go looking for it in\n * graph state. Decide from the host's own queue, or read it after the run.\n *\n * Requires `RunConfig.preemption`. This event is deliberately NOT\n * result-altering, so registering it never disables eager tool execution.\n */\nexport interface PreemptBoundaryHookInput extends BaseHookInput {\n hook_event_name: 'PreemptBoundary';\n /** 1-based index of this seal within the run. */\n sealCount: number;\n}\n\nexport interface PermissionDeniedHookInput extends BaseHookInput {\n hook_event_name: 'PermissionDenied';\n toolName: string;\n toolInput: Record<string, unknown>;\n toolUseId: string;\n reason: string;\n}\n\nexport interface SubagentStartHookInput extends BaseHookInput {\n hook_event_name: 'SubagentStart';\n parentAgentId?: string;\n agentId: string;\n agentType: string;\n inputs: BaseMessage[];\n}\n\nexport interface SubagentStopHookInput extends BaseHookInput {\n hook_event_name: 'SubagentStop';\n agentId: string;\n agentType: string;\n messages: BaseMessage[];\n}\n\nexport interface StopHookInput extends BaseHookInput {\n hook_event_name: 'Stop';\n messages: BaseMessage[];\n stopReason?: string;\n stopHookActive: boolean;\n}\n\nexport interface StopFailureHookInput extends BaseHookInput {\n hook_event_name: 'StopFailure';\n error: string;\n lastAssistantMessage?: BaseMessage;\n}\n\nexport interface PreCompactHookInput extends BaseHookInput {\n hook_event_name: 'PreCompact';\n messagesBeforeCount: number;\n /**\n * What triggered compaction. Matches `SummarizationTrigger.type` from the\n * agent's summarization config. `'default'` means no trigger was\n * configured and compaction fired because messages were pruned.\n */\n trigger:\n | 'token_ratio'\n | 'remaining_tokens'\n | 'messages_to_refine'\n | 'default'\n | (string & {});\n}\n\nexport interface PostCompactHookInput extends BaseHookInput {\n hook_event_name: 'PostCompact';\n summary: string;\n /**\n * Number of messages remaining after compaction. The summarize node\n * returns a `removeAll` signal that clears all messages from state;\n * the summary itself is injected into the system prompt, not as a\n * message. This is `0` at the point of hook dispatch.\n */\n messagesAfterCount: number;\n}\n\n/** Discriminated union of every hook input shape. */\nexport type HookInput =\n | RunStartHookInput\n | UserPromptSubmitHookInput\n | PreToolUseHookInput\n | PostToolUseHookInput\n | PostToolUseFailureHookInput\n | PostToolBatchHookInput\n | PreemptBoundaryHookInput\n | PermissionDeniedHookInput\n | SubagentStartHookInput\n | SubagentStopHookInput\n | StopHookInput\n | StopFailureHookInput\n | PreCompactHookInput\n | PostCompactHookInput;\n\n/** Compile-time map from event name to its input shape. */\nexport type HookInputByEvent = {\n RunStart: RunStartHookInput;\n UserPromptSubmit: UserPromptSubmitHookInput;\n PreToolUse: PreToolUseHookInput;\n PostToolUse: PostToolUseHookInput;\n PostToolUseFailure: PostToolUseFailureHookInput;\n PostToolBatch: PostToolBatchHookInput;\n PreemptBoundary: PreemptBoundaryHookInput;\n PermissionDenied: PermissionDeniedHookInput;\n SubagentStart: SubagentStartHookInput;\n SubagentStop: SubagentStopHookInput;\n Stop: StopHookInput;\n StopFailure: StopFailureHookInput;\n PreCompact: PreCompactHookInput;\n PostCompact: PostCompactHookInput;\n};\n\n/**\n * Fields common to every hook output. Hooks that have nothing to say simply\n * return `{}` (or omit the fields below).\n */\nexport interface BaseHookOutput {\n /** Context string to inject into the conversation. Accumulated across hooks. */\n additionalContext?: string;\n /**\n * Messages to inject into graph state, one `HumanMessage` per entry\n * (converted via `convertInjectedMessages`, which preserves\n * `role`/`source`/`isMeta` in `additional_kwargs`). Unlike\n * `additionalContext` — which is consolidated across hooks into a single\n * system-flavored message — each entry keeps its own identity and role,\n * making this the channel for injecting verbatim user speech (e.g. a\n * mid-run steering message). Accumulated across hooks in registration\n * order.\n *\n * Consumed at exactly two dispatch sites, both of which run the same\n * converter so the emitted shapes cannot drift: `PostToolBatch` (the tool\n * boundary) and `PreemptBoundary` (a cooperative mid-generation seal).\n * Every other event ignores the field.\n */\n injectedMessages?: InjectedMessage[];\n /** True to prevent the next model turn. Any hook can set this. */\n preventContinuation?: boolean;\n /** Reason reported alongside `preventContinuation`. */\n stopReason?: string;\n /**\n * Marks this hook output as fire-and-forget for INFLUENCE only.\n * When `true`, the SDK skips every other field on this output —\n * `decision`, `additionalContext`, `updatedInput`,\n * `preventContinuation`, `allowedDecisions`, `updatedOutput` are\n * all ignored. The hook's return value cannot block, modify, or\n * inject context, so it's safe to use for pure side effects\n * (logging, metrics, webhooks).\n *\n * Important caveat: the hook's CALLBACK promise is still awaited\n * by `executeHooks` (subject to the matcher's timeout and the\n * default `DEFAULT_HOOK_TIMEOUT_MS`). The SDK does not\n * speculatively detach hooks based on output shape, because the\n * shape is only known after the promise resolves. For TRUE\n * fire-and-forget where the agent doesn't wait at all, the hook\n * body should detach its side effect itself and return\n * immediately:\n *\n * @example\n * ```ts\n * async (input) => {\n * // Detach the slow work — the SDK awaits this hook's\n * // returned promise, which resolves immediately because we\n * // don't `await` the side effect.\n * void sendToLoggingService(input).catch(console.error);\n * return { async: true };\n * };\n * ```\n *\n * @example WRONG — the agent will block on the webhook\n * ```ts\n * async (input) => {\n * await sendToLoggingService(input); // ← awaited, blocks\n * return { async: true }; // returning async:true doesn't undo the await\n * };\n * ```\n *\n * Mirrors Claude Code Agent SDK's `async` output, with the same\n * \"detach inside the hook body\" pattern.\n */\n async?: boolean;\n /**\n * Optional advisory timeout in milliseconds for the background work\n * a host has detached inside an `async: true` hook body. The SDK\n * does not enforce this (the hook's own AbortSignal handling does)\n * but the field is preserved on the wire so downstream\n * observability can surface long-running side effects. Ignored\n * unless `async` is true.\n */\n asyncTimeout?: number;\n}\n\nexport type RunStartHookOutput = BaseHookOutput;\n\nexport interface UserPromptSubmitHookOutput extends BaseHookOutput {\n decision?: ToolDecision;\n reason?: string;\n}\n\nexport interface PreToolUseHookOutput extends BaseHookOutput {\n decision?: ToolDecision;\n reason?: string;\n /**\n * Replacement tool input. Merged into the pending tool call by the host.\n *\n * When multiple hooks set `updatedInput` within a single `executeHooks`\n * call, the last writer in registration order wins (outer loop: matcher\n * registration order; inner loop: hook position within the matcher). The\n * winner is deterministic — `Promise.all` preserves input-array order.\n * Consumers that need a single authoritative rewrite should still scope\n * `updatedInput` to one hook per matcher to avoid confusing precedence.\n */\n updatedInput?: Record<string, unknown>;\n /**\n * Restricts which decisions the host UI is allowed to surface for this\n * tool call when the hook returns `decision: 'ask'`. Pass to lock a\n * tool down to a subset of `'approve' | 'reject' | 'edit' | 'respond'`\n * — for example, `['approve', 'reject']` to forbid the user from\n * editing the tool's args or substituting a custom response.\n *\n * The values flow into the resulting interrupt's\n * `review_configs[i].allowed_decisions`. Omitting the field keeps the\n * SDK default (all four decisions advertised). Last-writer-wins in\n * registration order, same precedence rules as `updatedInput`.\n */\n allowedDecisions?: ReadonlyArray<'approve' | 'reject' | 'edit' | 'respond'>;\n}\n\n/** Stable identity for replaying a consumed one-shot tool approval. */\nexport interface ToolApprovalReplayKey {\n executionScope: string;\n agentId: string;\n toolUseId: string;\n}\n\n/** Checkpoint-safe copy of a consumed one-shot approval contribution. */\nexport interface ToolApprovalReplaySnapshot {\n key: ToolApprovalReplayKey;\n result: AggregatedHookResult;\n}\n\nexport interface PostToolUseHookOutput extends BaseHookOutput {\n /**\n * Replacement tool output. Flows through the aggregated result so the\n * host can substitute it before appending the tool result message.\n * Ordering semantics match `PreToolUseHookOutput.updatedInput`:\n * last-writer-wins in registration order.\n */\n updatedOutput?: unknown;\n}\n\nexport type PostToolUseFailureHookOutput = BaseHookOutput;\n\nexport type PostToolBatchHookOutput = BaseHookOutput;\n\nexport type PreemptBoundaryHookOutput = BaseHookOutput;\n\nexport type PermissionDeniedHookOutput = BaseHookOutput;\n\nexport interface SubagentStartHookOutput extends BaseHookOutput {\n decision?: ToolDecision;\n reason?: string;\n}\n\nexport type SubagentStopHookOutput = BaseHookOutput;\n\nexport interface StopHookOutput extends BaseHookOutput {\n decision?: StopDecision;\n reason?: string;\n}\n\nexport type StopFailureHookOutput = BaseHookOutput;\n\nexport type PreCompactHookOutput = BaseHookOutput;\n\nexport type PostCompactHookOutput = BaseHookOutput;\n\n/** Compile-time map from event name to its output shape. */\nexport type HookOutputByEvent = {\n RunStart: RunStartHookOutput;\n UserPromptSubmit: UserPromptSubmitHookOutput;\n PreToolUse: PreToolUseHookOutput;\n PostToolUse: PostToolUseHookOutput;\n PostToolUseFailure: PostToolUseFailureHookOutput;\n PostToolBatch: PostToolBatchHookOutput;\n PreemptBoundary: PreemptBoundaryHookOutput;\n PermissionDenied: PermissionDeniedHookOutput;\n SubagentStart: SubagentStartHookOutput;\n SubagentStop: SubagentStopHookOutput;\n Stop: StopHookOutput;\n StopFailure: StopFailureHookOutput;\n PreCompact: PreCompactHookOutput;\n PostCompact: PostCompactHookOutput;\n};\n\n/** Superset output shape used by the executor's fold loop. */\nexport type HookOutput =\n | RunStartHookOutput\n | UserPromptSubmitHookOutput\n | PreToolUseHookOutput\n | PostToolUseHookOutput\n | PostToolUseFailureHookOutput\n | PostToolBatchHookOutput\n | PreemptBoundaryHookOutput\n | PermissionDeniedHookOutput\n | SubagentStartHookOutput\n | SubagentStopHookOutput\n | StopHookOutput\n | StopFailureHookOutput\n | PreCompactHookOutput\n | PostCompactHookOutput;\n\n/**\n * A hook callback is a plain async function registered against a specific\n * event. The `signal` is always supplied by `executeHooks` and combines the\n * batch's parent signal with the per-hook timeout — callbacks that perform\n * long-running work should observe it.\n */\nexport type HookCallback<E extends HookEvent = HookEvent> = (\n input: HookInputByEvent[E],\n signal: AbortSignal\n) => HookOutputByEvent[E] | Promise<HookOutputByEvent[E]>;\n\n/**\n * A matcher groups one or more callbacks under a shared regex filter and\n * shared timeout/once/internal flags. The generic `E` ties the callback\n * types to the event the matcher is registered against.\n */\nexport interface HookMatcher<E extends HookEvent = HookEvent> {\n /**\n * Regex pattern matched against the event's primary query string (e.g.\n * the tool name for `PreToolUse`, the agent type for `SubagentStart`).\n *\n * Omitted or empty means \"always match\". For events that do not supply a\n * query string (`RunStart`, `Stop`, etc.), only wildcard matchers fire —\n * a non-empty pattern on such events will never match.\n *\n * Patterns are treated as trusted input: `executeHooks` compiles them\n * with `new RegExp(pattern)` without any sandbox, and a pathological\n * pattern can block the event loop. Host registration code is expected\n * to validate or length-bound patterns that originate from user input.\n */\n pattern?: string;\n /** Callbacks that fire when the matcher hits. Executed in parallel. */\n hooks: HookCallback<E>[];\n /** Per-matcher timeout in ms. Defaults to the executor's batch timeout. */\n timeout?: number;\n /**\n * Atomically remove the matcher before its first dispatch.\n *\n * `executeHooks` claims `once: true` matchers synchronously — between\n * `getMatchers` and its first `await` — so two concurrent calls cannot\n * both dispatch the same matcher. Whichever call runs its sync prefix\n * first wins the matcher; the other sees an empty bucket.\n *\n * Semantics are \"at most one dispatch, ever\" — if every hook in the\n * matcher throws, the matcher is still gone. Use `once` for\n * fire-and-forget bootstrapping (registration, telemetry, setup). Hosts\n * that need retry semantics should register a normal matcher and\n * self-unregister via the callback returned from `registry.register`.\n */\n once?: boolean;\n /** Internal hooks are excluded from telemetry and non-fatal error logging. */\n internal?: boolean;\n}\n\n/**\n * Storage shape for matchers keyed by event. Each event's matcher list is\n * a generic array parameterized by that event type, so lookup via\n * `HooksByEvent[E]` preserves type-safe callback signatures.\n */\nexport type HooksByEvent = {\n [E in HookEvent]?: HookMatcher<E>[];\n};\n\n/**\n * Aggregated result of a single `executeHooks` call. Fields are populated\n * according to the fold rules in `executeHooks.ts`.\n */\nexport interface AggregatedHookResult {\n /** Folded tool-gating decision; `deny > ask > allow`. */\n decision?: ToolDecision;\n /** Folded stop decision; any `block` wins. */\n stopDecision?: StopDecision;\n /** Reason from the hook that set the winning decision. */\n reason?: string;\n /**\n * Replacement tool input from a `PreToolUse` hook.\n *\n * Last-writer-wins in **registration order**: `executeHooks` uses\n * `Promise.all`, which preserves input-array order, so the fold iterates\n * outcomes in the same order they were pushed — outer loop over matchers\n * as they sit in the registry, inner loop over each matcher's `hooks`\n * array. The winner is therefore deterministic but may not match the\n * order in which hooks actually completed. Consumers that want a single\n * authoritative rewrite should still register one `updatedInput`-setting\n * hook per matcher to avoid subtle precedence bugs.\n */\n updatedInput?: Record<string, unknown>;\n /**\n * Restricted decision set from a `PreToolUse` hook. Same last-writer-wins\n * semantics as `updatedInput`. Surfaces to the interrupt payload's\n * `review_configs[i].allowed_decisions`.\n */\n allowedDecisions?: ReadonlyArray<'approve' | 'reject' | 'edit' | 'respond'>;\n /**\n * Replacement tool output from a `PostToolUse` hook.\n *\n * Same last-writer-wins-in-registration-order semantics as\n * `updatedInput`. Present only when at least one hook set it; `undefined`\n * means \"use the original tool output\".\n */\n updatedOutput?: unknown;\n /** Accumulated `additionalContext` strings from every hook, in order. */\n additionalContexts: string[];\n /** Accumulated `injectedMessages` from every hook, in registration order. */\n injectedMessages: InjectedMessage[];\n /** True if any hook returned `preventContinuation`. */\n preventContinuation?: boolean;\n /**\n * Reason recorded alongside `preventContinuation`. First winner wins:\n * once a hook sets both flags, later hooks that also set\n * `preventContinuation` do not overwrite the reason.\n */\n stopReason?: string;\n /** Error messages from hooks that threw; always present (possibly empty). */\n errors: string[];\n}\n"],"mappings":";;;;;;;;;AAYA,MAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,2CACX"}
|
|
1
|
+
{"version":3,"file":"types.mjs","names":[],"sources":["../../../src/hooks/types.ts"],"mappings":";AAYA,MAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,2CACX"}
|
|
@@ -10,17 +10,6 @@ import { randomBytes } from "node:crypto";
|
|
|
10
10
|
import { BasicTracerProvider } from "@opentelemetry/sdk-trace-base";
|
|
11
11
|
import { AsyncLocalStorageContextManager } from "@opentelemetry/context-async-hooks";
|
|
12
12
|
//#region src/instrumentation.ts
|
|
13
|
-
/**
|
|
14
|
-
* Per-run seed for deterministic Langfuse trace ids. When a run opts in
|
|
15
|
-
* (`LangfuseConfig.deterministicTraceId`), it executes its stream inside
|
|
16
|
-
* `runWithTraceIdSeed(runId, ...)` from `./langfuseRuntimeContext`, and the
|
|
17
|
-
* IdGenerator below derives the root trace id from that seed instead of a
|
|
18
|
-
* random one. This lets external systems (e.g. a host app recording user
|
|
19
|
-
* feedback after the fact) attach scores or observations to the trace by
|
|
20
|
-
* regenerating the same id from the run/message id; no trace lookup required.
|
|
21
|
-
* With no active seed it falls back to random ids, so default behavior is
|
|
22
|
-
* unchanged.
|
|
23
|
-
*/
|
|
24
13
|
var SeededTraceIdGenerator = class {
|
|
25
14
|
generateTraceId() {
|
|
26
15
|
const seed = resolveTraceIdSeedForSpan(context.active());
|
|
@@ -42,9 +31,6 @@ function ensureOpenTelemetryContextManager() {
|
|
|
42
31
|
contextManager.enable();
|
|
43
32
|
if (!context.setGlobalContextManager(contextManager)) contextManager.disable();
|
|
44
33
|
}
|
|
45
|
-
/** Cache key for processor instances: the destination plus processor-level
|
|
46
|
-
* policy (`toolOutputTracing` is baked into each processor's redaction
|
|
47
|
-
* behavior), unlike the pure destination identity used for span parenting. */
|
|
48
34
|
function getLangfuseProcessorCacheKey(destinationKey, langfuse) {
|
|
49
35
|
return JSON.stringify({
|
|
50
36
|
destinationKey,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.mjs","names":[],"sources":["../../src/instrumentation.ts"],"
|
|
1
|
+
{"version":3,"file":"instrumentation.mjs","names":[],"sources":["../../src/instrumentation.ts"],"mappings":";;;;;;;;;;;;AAuCA,IAAM,yBAAN,MAAoD;CAClD,kBAA0B;EACxB,MAAM,OAAO,0BAA0B,QAAQ,OAAO,CAAC;EACvD,OAAO,UAAU,IAAI,IACjB,gBAAgB,IAAI,IACpB,YAAY,EAAE,CAAC,CAAC,SAAS,KAAK;CACpC;CAEA,iBAAyB;EACvB,OAAO,YAAY,CAAC,CAAC,CAAC,SAAS,KAAK;CACt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CACzC;EACA,IAAI,OAAO,KAAK,wBAAwB,CAAC,CAAC,SAAS,GACjD,KAAK,cAAc,wBAAwB;EAG7C,KAAK,eAAe,IAAI,MAAM,SAAS;EACvC,UAAU,QAAQ,MAAM,aAAa;CACvC;CAEA,MAAM,MAA0B;EAC9B,KAAK,eAAe,IAAI,IAAI,CAAC,EAAE,MAAM,IAAI;CAC3C;CAEA,MAAM,aAA4B;EAChC,MAAM,QAAQ,IACZ,MAAM,KAAK,KAAK,WAAW,OAAO,IAAI,cACpC,UAAU,WAAW,CACvB,CACF;CACF;CAEA,MAAM,WAA0B;EAC9B,MAAM,QAAQ,IACZ,MAAM,KAAK,KAAK,WAAW,OAAO,IAAI,cAAc,UAAU,SAAS,CAAC,CAC1E;CACF;AACF;AAEA,SAAgB,0BACd,UACiC;CAEjC,IADe,+BAA+B,QACrC,KAAK,MACZ;CAGF,IAAI,0BAA0B,MAAM;EAClC,8BAA8B,gBAAgB,QAAQ;EACtD,OAAO;CACT;CAEA,kCAAkC;CAClC,+BAA+B,IAAI,6BAA6B;CAChE,6BAA6B,gBAAgB,QAAQ;CACrD,yBAAyB,IAAI,oBAAoB;EAC/C,gBAAgB,CAAC,4BAA4B;EAC7C,aAAa,IAAI,uBAAuB;CAC1C,CAAC;CAED,0BAA0B,sBAAsB;CAChD,OAAO;AACT;AAEA,SAAgB,mCAEF;CACZ,OAAO,0BAA0B;AACnC;AAEA,iCAAiC"}
|
package/dist/esm/langfuse.mjs
CHANGED
|
@@ -71,50 +71,21 @@ function normalizeBedrockUsageForLangfuse(output) {
|
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
73
|
const LANGGRAPH_NODE_METADATA_KEY = "langgraph_node";
|
|
74
|
-
/** Explicit agent identity in invoke metadata. Every identity-stamping
|
|
75
|
-
* component (graph model path, ToolNode, summarization node) overwrites the
|
|
76
|
-
* canonical `agentId` at its own invoke, so spread order guarantees the
|
|
77
|
-
* closest stamper wins — key priority alone could not (an inherited key of
|
|
78
|
-
* either casing can name the wrong agent). `agent_id` remains a fallback
|
|
79
|
-
* for third-party graphs that only stamp the snake-case form. */
|
|
80
74
|
const AGENT_ID_METADATA_KEYS = ["agentId", "agent_id"];
|
|
81
75
|
const LANGGRAPH_NODE_AGENT_PREFIXES = [
|
|
82
76
|
"agent=",
|
|
83
77
|
"tools=",
|
|
84
78
|
"summarize="
|
|
85
79
|
];
|
|
86
|
-
/** The LangGraph node a callback executes under, from its inherited
|
|
87
|
-
* `langgraph_node` run metadata. `undefined` when the callback carries no
|
|
88
|
-
* node identity. */
|
|
89
80
|
function getCallbackNode(metadata) {
|
|
90
81
|
const node = metadata?.[LANGGRAPH_NODE_METADATA_KEY];
|
|
91
82
|
return typeof node === "string" && node !== "" ? node : void 0;
|
|
92
83
|
}
|
|
93
|
-
/** Whether a callback's node identifies the given agent. The outer workflow
|
|
94
|
-
* node carries the agent id VERBATIM — including ids that themselves begin
|
|
95
|
-
* with an internal prefix (an agent literally named `agent=research`) — so
|
|
96
|
-
* an exact match is checked before decoding the inner subgraph prefixes
|
|
97
|
-
* (`agent=` / `tools=` / `summarize=`). */
|
|
98
84
|
function callbackNodeMatchesAgent(node, agentId) {
|
|
99
85
|
if (node === agentId) return true;
|
|
100
86
|
for (const prefix of LANGGRAPH_NODE_AGENT_PREFIXES) if (node.startsWith(prefix) && node.slice(prefix.length) === agentId) return true;
|
|
101
87
|
return false;
|
|
102
88
|
}
|
|
103
|
-
/**
|
|
104
|
-
* Hosts often execute agent code inside their own OpenTelemetry spans (HTTP
|
|
105
|
-
* server auto-instrumentation on the global provider). Root observations must
|
|
106
|
-
* not inherit that ambient identity: the foreign parent is never exported to
|
|
107
|
-
* Langfuse, which orphans the trace root (root/trace input-output shaping is
|
|
108
|
-
* skipped because the span no longer looks like a root), collapses concurrent
|
|
109
|
-
* runs inside one request context — an agent run and the previous turn's
|
|
110
|
-
* title run — into a single merged trace with racing names and unioned tags,
|
|
111
|
-
* and bypasses the seeded deterministic trace id generator. Only a
|
|
112
|
-
* Langfuse-managed span bound to the same export destination as the starting
|
|
113
|
-
* run is a safe parent — that is the sanctioned way for hosts to group runs
|
|
114
|
-
* under their own Langfuse observations; a managed span from a different
|
|
115
|
-
* destination (another tenant's project) would leave this run's trace
|
|
116
|
-
* dangling in its own destination while inheriting the other trace's id.
|
|
117
|
-
*/
|
|
118
89
|
function detachForeignAmbientSpan(activeContext, destinationKey) {
|
|
119
90
|
const activeSpan = trace.getSpan(activeContext);
|
|
120
91
|
if (activeSpan == null) return activeContext;
|
|
@@ -147,27 +118,11 @@ var ScopedLangfuseCallbackHandler = class extends CallbackHandler {
|
|
|
147
118
|
getDeterministicTraceSeed() {
|
|
148
119
|
return this.langfuse?.deterministicTraceId === true ? this.traceIdSeed : void 0;
|
|
149
120
|
}
|
|
150
|
-
/**
|
|
151
|
-
* Mirrors the base handler's `runMap`: a start callback whose `parentRunId`
|
|
152
|
-
* this handler never observed gets no explicit parent span and falls back
|
|
153
|
-
* to the ambient OTEL context (`startAndRegisterOtelSpan`), so it needs the
|
|
154
|
-
* same foreign-span detachment as a true root. This happens whenever a
|
|
155
|
-
* handler is attached mid-graph — e.g. the per-agent handler created for a
|
|
156
|
-
* detached subagent's model invocations, whose surrounding graph runs were
|
|
157
|
-
* never traced.
|
|
158
|
-
*/
|
|
159
121
|
startsDetachedRun(runId, parentRunId) {
|
|
160
122
|
const detached = parentRunId == null || !this.trackedRunIds.has(parentRunId);
|
|
161
123
|
this.trackedRunIds.add(runId);
|
|
162
124
|
return detached;
|
|
163
125
|
}
|
|
164
|
-
/**
|
|
165
|
-
* Whether the ambient runtime scope belongs to a different run — or, for
|
|
166
|
-
* per-agent overlay scopes, to a different concurrently executing agent of
|
|
167
|
-
* the same run than the one this callback reports via its inherited
|
|
168
|
-
* `langgraph_node` metadata. Unstamped scopes on unstamped handlers are
|
|
169
|
-
* never foreign (host-managed handler semantics).
|
|
170
|
-
*/
|
|
171
126
|
isForeignScope(scopeRunId, scopeAgentId, callbackMetadata) {
|
|
172
127
|
if (this.runId == null || scopeRunId == null) return false;
|
|
173
128
|
if (scopeRunId !== this.runId) return true;
|
|
@@ -179,26 +134,6 @@ var ScopedLangfuseCallbackHandler = class extends CallbackHandler {
|
|
|
179
134
|
const callbackNode = getCallbackNode(callbackMetadata);
|
|
180
135
|
return callbackNode != null && !callbackNodeMatchesAgent(callbackNode, scopeAgentId);
|
|
181
136
|
}
|
|
182
|
-
/**
|
|
183
|
-
* LangChain executes non-awaited callbacks on a process-wide background
|
|
184
|
-
* queue (`consumeCallback`), so this callback may be running inside a
|
|
185
|
-
* DIFFERENT concurrent run's async context. The ambient runtime scope is
|
|
186
|
-
* therefore only adopted when it belongs to this handler's run (and, for
|
|
187
|
-
* agent sub-scopes, to this callback's agent): scopes are stamped at their
|
|
188
|
-
* call sites, and a foreign stamp means the scope's config would route
|
|
189
|
-
* spans to the wrong destination, its seed would collapse this run's spans
|
|
190
|
-
* into the foreign trace, and its tool-output policy could leak output the
|
|
191
|
-
* foreign run permits but this run redacts — so config, seed, AND redaction
|
|
192
|
-
* policy all fall back to this handler's own run. Unstamped scopes on
|
|
193
|
-
* unstamped handlers keep scope-first semantics (agent overlays and
|
|
194
|
-
* per-path seeds like the title/label scopes, host-managed handlers).
|
|
195
|
-
*
|
|
196
|
-
* Detached runs (roots, or starts whose parent this handler never tracked)
|
|
197
|
-
* take their span parent from the ambient OTEL context, so drop any
|
|
198
|
-
* foreign ambient span first — a run launched from a host's instrumented
|
|
199
|
-
* request context must start its own trace, not join an unexported
|
|
200
|
-
* foreign one.
|
|
201
|
-
*/
|
|
202
137
|
withRuntimeContext(action, isDetachedRun = false, callbackMetadata) {
|
|
203
138
|
const currentContext = context.active();
|
|
204
139
|
const scopeRunId = resolveLangfuseScopeRunId(currentContext);
|
|
@@ -213,16 +148,6 @@ var ScopedLangfuseCallbackHandler = class extends CallbackHandler {
|
|
|
213
148
|
}, action);
|
|
214
149
|
return activeContext === currentContext ? scoped() : context.with(activeContext, scoped);
|
|
215
150
|
}
|
|
216
|
-
/**
|
|
217
|
-
* A foreign concurrent run's context must be replaced wholesale, not
|
|
218
|
-
* merged: this library's scope keys (config, seed, tool-output policy,
|
|
219
|
-
* identity stamps) via the replace-mode runtime scope, `@langfuse/tracing`'s
|
|
220
|
-
* propagated trace attributes (userId, sessionId, tags, metadata, …) by
|
|
221
|
-
* deleting their context keys and re-propagating this handler's own
|
|
222
|
-
* identity, and the foreign active span — removed both so detached runs
|
|
223
|
-
* root their own trace and so `propagateAttributes` cannot stamp this
|
|
224
|
-
* run's identity onto the foreign run's still-recording span.
|
|
225
|
-
*/
|
|
226
151
|
withForeignScopeRejected(action) {
|
|
227
152
|
let cleanContext = trace.deleteSpan(context.active());
|
|
228
153
|
for (const key of Object.values(LangfuseOtelContextKeys)) cleanContext = cleanContext.deleteValue(key);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"langfuse.mjs","names":["otelTrace","otelContext"],"sources":["../../src/langfuse.ts"],"sourcesContent":["import { CallbackHandler } from '@langfuse/langchain';\nimport { LangfuseOtelContextKeys } from '@langfuse/core';\nimport { AIMessage, AIMessageChunk } from '@langchain/core/messages';\nimport { isGraphInterrupt, isParentCommand } from '@langchain/langgraph';\nimport { context as otelContext, trace as otelTrace } from '@opentelemetry/api';\nimport {\n getLangfuseTracerProvider,\n propagateAttributes,\n} from '@langfuse/tracing';\nimport type {\n AIMessageChunkFields,\n AIMessageFields,\n UsageMetadata,\n} from '@langchain/core/messages';\nimport type {\n ChatGeneration,\n Generation,\n LLMResult,\n} from '@langchain/core/outputs';\nimport type { PropagateAttributesParams } from '@langfuse/tracing';\nimport type { Context } from '@opentelemetry/api';\nimport type { ResolvedLangfuseToolOutputTracingConfig } from '@/langfuseRuntimeContext';\nimport type * as t from '@/types';\nimport {\n resolveLangfuseConfigForSpan,\n resolveLangfuseScopeAgentId,\n resolveLangfuseScopeRunId,\n resolveTraceIdSeedForSpan,\n withLangfuseRuntimeScope,\n} from '@/langfuseRuntimeScope';\nimport {\n hasLangfuseConfigCredentials,\n hasLangfuseEnvCredentials,\n resolveToolOutputTracingConfig,\n hasLangfuseEnvConfig,\n} from '@/langfuseConfig';\nimport {\n getLangfuseManagedSpanDestination,\n resolveLangfuseDestinationKey,\n} from '@/langfuseSpanRegistry';\nimport { isPresent, parseBooleanEnv } from '@/utils/misc';\n\nexport {\n hasLangfuseConfigCredentials,\n hasLangfuseEnvCredentials,\n hasLangfuseEnvConfig,\n};\n\nconst TRACE_METADATA_MAX_LENGTH = 200;\nconst LANGFUSE_FORCE_FLUSH_ON_DISPOSE = 'LANGFUSE_FORCE_FLUSH_ON_DISPOSE';\nconst GRAPH_INTERRUPT_CONTROL_FLOW = { controlFlow: 'GraphInterrupt' } as const;\nconst GRAPH_INTERRUPT_TOOL_OUTPUT = JSON.stringify(\n GRAPH_INTERRUPT_CONTROL_FLOW\n);\n\nexport type LangfuseTraceMetadata = Record<string, string>;\nexport type LangfuseTraceAttributes = Record<string, string | number | boolean>;\ntype LangfuseMetadata = NonNullable<t.LangfuseConfig['metadata']>;\ntype LangfuseConfigTraceAttributes = NonNullable<\n t.LangfuseConfig['librechatTraceAttributes']\n>;\n\ntype LangfuseHandlerParams = {\n userId?: string;\n sessionId?: string;\n traceMetadata?: LangfuseTraceMetadata;\n tags?: string[];\n traceIdSeed?: string;\n /** Identity of the run this handler traces; ambient runtime scopes are\n * only adopted when stamped with the same run (see\n * `LangfuseRuntimeContext.runId`). */\n runId?: string;\n /** The run's resolved tool-output policy — for multi-agent streams the\n * conservative aggregate across agents, which `this.langfuse` (the\n * primary agent's config) cannot reproduce. Applied when a foreign\n * scope's policy is rejected. */\n toolOutputTracing?: ResolvedLangfuseToolOutputTracingConfig;\n /** The run's propagated trace name, re-propagated when a foreign scope's\n * attributes are cleared. */\n traceName?: string;\n};\n\ntype AgentLangfuseHandlerParams = LangfuseHandlerParams & {\n langfuse?: t.LangfuseConfig;\n};\n\ntype HandlerIdentity = {\n userId?: string;\n sessionId?: string;\n tags?: string[];\n metadata?: LangfuseTraceMetadata;\n traceName?: string;\n};\n\ntype LangfuseAttributeParams = AgentLangfuseHandlerParams & {\n traceName?: string;\n};\n\ntype FlushableTracerProvider = {\n forceFlush?: () => Promise<void> | void;\n};\n\ntype BedrockResponseUsage = {\n inputTokens?: number;\n cacheReadInputTokens?: number;\n cacheWriteInputTokens?: number;\n};\n\ntype BedrockResponseMetadata = {\n metadata?: {\n usage?: BedrockResponseUsage;\n };\n};\n\nfunction getLangfuseBedrockUsage(\n message: AIMessage | AIMessageChunk\n): UsageMetadata | undefined {\n const usageMetadata = message.usage_metadata;\n const bedrockUsage = (message.response_metadata as BedrockResponseMetadata)\n .metadata?.usage;\n if (\n usageMetadata == null ||\n bedrockUsage == null ||\n usageMetadata.input_tokens !== bedrockUsage.inputTokens\n ) {\n return usageMetadata;\n }\n\n const cacheRead = bedrockUsage.cacheReadInputTokens ?? 0;\n const cacheCreation = bedrockUsage.cacheWriteInputTokens ?? 0;\n if (cacheRead === 0 && cacheCreation === 0) {\n return usageMetadata;\n }\n\n return {\n ...usageMetadata,\n input_tokens: usageMetadata.input_tokens + cacheRead + cacheCreation,\n };\n}\n\nfunction cloneMessageWithUsage(\n message: AIMessage | AIMessageChunk,\n usageMetadata: UsageMetadata\n): AIMessage | AIMessageChunk {\n const fields: AIMessageFields = {\n content: message.content,\n additional_kwargs: message.additional_kwargs,\n response_metadata: message.response_metadata,\n id: message.id,\n name: message.name,\n tool_calls: message.tool_calls,\n invalid_tool_calls: message.invalid_tool_calls,\n usage_metadata: usageMetadata,\n };\n\n if (message instanceof AIMessageChunk) {\n const chunkFields: AIMessageChunkFields = {\n ...fields,\n tool_call_chunks: message.tool_call_chunks,\n };\n return new AIMessageChunk(chunkFields);\n }\n\n return new AIMessage(fields);\n}\n\nfunction normalizeGenerationForLangfuse(generation: Generation): Generation {\n if (!('message' in generation)) {\n return generation;\n }\n\n const message = (generation as ChatGeneration).message;\n if (!(message instanceof AIMessage || message instanceof AIMessageChunk)) {\n return generation;\n }\n\n const usageMetadata = getLangfuseBedrockUsage(message);\n if (usageMetadata == null || usageMetadata === message.usage_metadata) {\n return generation;\n }\n\n const chatGeneration: ChatGeneration = {\n ...(generation as ChatGeneration),\n message: cloneMessageWithUsage(message, usageMetadata),\n };\n return chatGeneration;\n}\n\nfunction normalizeBedrockUsageForLangfuse(output: LLMResult): LLMResult {\n if (output.generations.length === 0) {\n return output;\n }\n\n const listIndex = output.generations.length - 1;\n const generationList = output.generations[listIndex];\n if (generationList.length === 0) {\n return output;\n }\n\n const generationIndex = generationList.length - 1;\n const generation = generationList[generationIndex];\n const normalized = normalizeGenerationForLangfuse(generation);\n if (normalized === generation) {\n return output;\n }\n\n const generations = [...output.generations];\n generations[listIndex] = [...generationList];\n generations[listIndex][generationIndex] = normalized;\n return { ...output, generations };\n}\n\nconst LANGGRAPH_NODE_METADATA_KEY = 'langgraph_node';\n/** Explicit agent identity in invoke metadata. Every identity-stamping\n * component (graph model path, ToolNode, summarization node) overwrites the\n * canonical `agentId` at its own invoke, so spread order guarantees the\n * closest stamper wins — key priority alone could not (an inherited key of\n * either casing can name the wrong agent). `agent_id` remains a fallback\n * for third-party graphs that only stamp the snake-case form. */\nconst AGENT_ID_METADATA_KEYS = ['agentId', 'agent_id'];\nconst LANGGRAPH_NODE_AGENT_PREFIXES = ['agent=', 'tools=', 'summarize='];\n\n/** The LangGraph node a callback executes under, from its inherited\n * `langgraph_node` run metadata. `undefined` when the callback carries no\n * node identity. */\nfunction getCallbackNode(\n metadata?: Record<string, unknown>\n): string | undefined {\n const node = metadata?.[LANGGRAPH_NODE_METADATA_KEY];\n return typeof node === 'string' && node !== '' ? node : undefined;\n}\n\n/** Whether a callback's node identifies the given agent. The outer workflow\n * node carries the agent id VERBATIM — including ids that themselves begin\n * with an internal prefix (an agent literally named `agent=research`) — so\n * an exact match is checked before decoding the inner subgraph prefixes\n * (`agent=` / `tools=` / `summarize=`). */\nfunction callbackNodeMatchesAgent(node: string, agentId: string): boolean {\n if (node === agentId) {\n return true;\n }\n for (const prefix of LANGGRAPH_NODE_AGENT_PREFIXES) {\n if (node.startsWith(prefix) && node.slice(prefix.length) === agentId) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Hosts often execute agent code inside their own OpenTelemetry spans (HTTP\n * server auto-instrumentation on the global provider). Root observations must\n * not inherit that ambient identity: the foreign parent is never exported to\n * Langfuse, which orphans the trace root (root/trace input-output shaping is\n * skipped because the span no longer looks like a root), collapses concurrent\n * runs inside one request context — an agent run and the previous turn's\n * title run — into a single merged trace with racing names and unioned tags,\n * and bypasses the seeded deterministic trace id generator. Only a\n * Langfuse-managed span bound to the same export destination as the starting\n * run is a safe parent — that is the sanctioned way for hosts to group runs\n * under their own Langfuse observations; a managed span from a different\n * destination (another tenant's project) would leave this run's trace\n * dangling in its own destination while inheriting the other trace's id.\n */\nfunction detachForeignAmbientSpan(\n activeContext: Context,\n destinationKey?: string\n): Context {\n const activeSpan = otelTrace.getSpan(activeContext);\n if (activeSpan == null) {\n return activeContext;\n }\n const parentDestination = getLangfuseManagedSpanDestination(activeSpan);\n if (parentDestination != null && parentDestination === destinationKey) {\n return activeContext;\n }\n return otelTrace.deleteSpan(activeContext);\n}\n\nclass ScopedLangfuseCallbackHandler extends CallbackHandler {\n private readonly langfuse?: t.LangfuseConfig;\n private readonly traceIdSeed?: string;\n private readonly runId?: string;\n private readonly identity: HandlerIdentity;\n private readonly toolOutputTracing?: ResolvedLangfuseToolOutputTracingConfig;\n private readonly trackedRunIds = new Set<string>();\n\n constructor(params?: AgentLangfuseHandlerParams) {\n const {\n langfuse,\n traceIdSeed,\n runId,\n toolOutputTracing,\n traceName,\n ...handlerParams\n } = params ?? {};\n super(handlerParams);\n this.langfuse = langfuse;\n this.traceIdSeed = traceIdSeed;\n this.runId = runId;\n this.toolOutputTracing = toolOutputTracing;\n this.identity = {\n userId: handlerParams.userId,\n sessionId: handlerParams.sessionId,\n tags: handlerParams.tags,\n metadata: handlerParams.traceMetadata,\n traceName,\n };\n }\n\n private getDeterministicTraceSeed(): string | undefined {\n return this.langfuse?.deterministicTraceId === true\n ? this.traceIdSeed\n : undefined;\n }\n\n /**\n * Mirrors the base handler's `runMap`: a start callback whose `parentRunId`\n * this handler never observed gets no explicit parent span and falls back\n * to the ambient OTEL context (`startAndRegisterOtelSpan`), so it needs the\n * same foreign-span detachment as a true root. This happens whenever a\n * handler is attached mid-graph — e.g. the per-agent handler created for a\n * detached subagent's model invocations, whose surrounding graph runs were\n * never traced.\n */\n private startsDetachedRun(runId: string, parentRunId?: string): boolean {\n const detached =\n parentRunId == null || !this.trackedRunIds.has(parentRunId);\n this.trackedRunIds.add(runId);\n return detached;\n }\n\n /**\n * Whether the ambient runtime scope belongs to a different run — or, for\n * per-agent overlay scopes, to a different concurrently executing agent of\n * the same run than the one this callback reports via its inherited\n * `langgraph_node` metadata. Unstamped scopes on unstamped handlers are\n * never foreign (host-managed handler semantics).\n */\n private isForeignScope(\n scopeRunId: string | undefined,\n scopeAgentId: string | undefined,\n callbackMetadata?: Record<string, unknown>\n ): boolean {\n if (this.runId == null || scopeRunId == null) {\n return false;\n }\n if (scopeRunId !== this.runId) {\n return true;\n }\n if (scopeAgentId == null) {\n return false;\n }\n // Explicit agent identity (stamped into invoke metadata by the graph's\n // model path and ToolNode) is unambiguous; node names are a fallback —\n // an agent literally named `agent=research` makes its outer node\n // indistinguishable from agent `research`'s inner model node.\n for (const key of AGENT_ID_METADATA_KEYS) {\n const explicitAgentId = callbackMetadata?.[key];\n if (typeof explicitAgentId === 'string' && explicitAgentId !== '') {\n return explicitAgentId !== scopeAgentId;\n }\n }\n const callbackNode = getCallbackNode(callbackMetadata);\n return (\n callbackNode != null &&\n !callbackNodeMatchesAgent(callbackNode, scopeAgentId)\n );\n }\n\n /**\n * LangChain executes non-awaited callbacks on a process-wide background\n * queue (`consumeCallback`), so this callback may be running inside a\n * DIFFERENT concurrent run's async context. The ambient runtime scope is\n * therefore only adopted when it belongs to this handler's run (and, for\n * agent sub-scopes, to this callback's agent): scopes are stamped at their\n * call sites, and a foreign stamp means the scope's config would route\n * spans to the wrong destination, its seed would collapse this run's spans\n * into the foreign trace, and its tool-output policy could leak output the\n * foreign run permits but this run redacts — so config, seed, AND redaction\n * policy all fall back to this handler's own run. Unstamped scopes on\n * unstamped handlers keep scope-first semantics (agent overlays and\n * per-path seeds like the title/label scopes, host-managed handlers).\n *\n * Detached runs (roots, or starts whose parent this handler never tracked)\n * take their span parent from the ambient OTEL context, so drop any\n * foreign ambient span first — a run launched from a host's instrumented\n * request context must start its own trace, not join an unexported\n * foreign one.\n */\n private withRuntimeContext<T>(\n action: () => T,\n isDetachedRun = false,\n callbackMetadata?: Record<string, unknown>\n ): T {\n const currentContext = otelContext.active();\n const scopeRunId = resolveLangfuseScopeRunId(currentContext);\n const scopeAgentId = resolveLangfuseScopeAgentId(currentContext);\n if (this.isForeignScope(scopeRunId, scopeAgentId, callbackMetadata)) {\n return this.withForeignScopeRejected(action);\n }\n const langfuse =\n resolveLangfuseConfigForSpan(currentContext) ?? this.langfuse;\n const activeContext = isDetachedRun\n ? detachForeignAmbientSpan(\n currentContext,\n resolveLangfuseDestinationKey(langfuse)\n )\n : currentContext;\n const scoped = (): T =>\n withLangfuseRuntimeScope(\n {\n langfuse,\n traceIdSeed:\n resolveTraceIdSeedForSpan(activeContext) ??\n this.getDeterministicTraceSeed(),\n runId: scopeRunId ?? this.runId,\n },\n action\n );\n return activeContext === currentContext\n ? scoped()\n : otelContext.with(activeContext, scoped);\n }\n\n /**\n * A foreign concurrent run's context must be replaced wholesale, not\n * merged: this library's scope keys (config, seed, tool-output policy,\n * identity stamps) via the replace-mode runtime scope, `@langfuse/tracing`'s\n * propagated trace attributes (userId, sessionId, tags, metadata, …) by\n * deleting their context keys and re-propagating this handler's own\n * identity, and the foreign active span — removed both so detached runs\n * root their own trace and so `propagateAttributes` cannot stamp this\n * run's identity onto the foreign run's still-recording span.\n */\n private withForeignScopeRejected<T>(action: () => T): T {\n let cleanContext = otelTrace.deleteSpan(otelContext.active());\n for (const key of Object.values(LangfuseOtelContextKeys)) {\n cleanContext = cleanContext.deleteValue(key);\n }\n const scoped = (): T =>\n withLangfuseRuntimeScope(\n {\n langfuse: this.langfuse,\n traceIdSeed: this.getDeterministicTraceSeed(),\n runId: this.runId,\n toolOutputTracing:\n this.toolOutputTracing ??\n resolveToolOutputTracingConfig(this.langfuse),\n },\n action,\n { replace: true }\n );\n const { userId, sessionId, tags, metadata, traceName } = this.identity;\n const hasIdentity =\n userId != null ||\n sessionId != null ||\n metadata != null ||\n traceName != null ||\n (tags?.length ?? 0) > 0;\n return otelContext.with(cleanContext, () =>\n hasIdentity\n ? propagateAttributes(\n { userId, sessionId, tags, metadata, traceName },\n scoped\n )\n : scoped()\n );\n }\n\n // LangChain may invoke callback handlers outside the caller's OTEL context.\n // Re-enter tenant scope only for callbacks that start Langfuse observations;\n // end/error/token callbacks use spans already bound to a processor at start.\n override handleChainStart(\n ...args: Parameters<CallbackHandler['handleChainStart']>\n ): ReturnType<CallbackHandler['handleChainStart']> {\n return this.withRuntimeContext(\n () => super.handleChainStart(...args),\n this.startsDetachedRun(args[2], args[3]),\n args[5]\n );\n }\n\n override handleChainError(\n ...args: Parameters<CallbackHandler['handleChainError']>\n ): ReturnType<CallbackHandler['handleChainError']> {\n const [error, runId, parentRunId] = args;\n if (error != null && parentRunId != null && isGraphInterrupt(error)) {\n return super.handleChainEnd(\n GRAPH_INTERRUPT_CONTROL_FLOW,\n runId,\n parentRunId\n );\n }\n if (error != null && parentRunId != null && isParentCommand(error)) {\n return super.handleChainEnd(\n { controlFlow: 'ParentCommand' },\n runId,\n parentRunId\n );\n }\n return super.handleChainError(...args);\n }\n\n override handleAgentAction(\n ...args: Parameters<CallbackHandler['handleAgentAction']>\n ): ReturnType<CallbackHandler['handleAgentAction']> {\n return this.withRuntimeContext(\n () => super.handleAgentAction(...args),\n this.startsDetachedRun(args[1], args[2])\n );\n }\n\n override handleGenerationStart(\n ...args: Parameters<CallbackHandler['handleGenerationStart']>\n ): ReturnType<CallbackHandler['handleGenerationStart']> {\n return this.withRuntimeContext(\n () => super.handleGenerationStart(...args),\n this.startsDetachedRun(args[2], args[3]),\n args[6]\n );\n }\n\n override handleChatModelStart(\n ...args: Parameters<CallbackHandler['handleChatModelStart']>\n ): ReturnType<CallbackHandler['handleChatModelStart']> {\n return this.withRuntimeContext(\n () => super.handleChatModelStart(...args),\n this.startsDetachedRun(args[2], args[3]),\n args[6]\n );\n }\n\n override handleLLMStart(\n ...args: Parameters<CallbackHandler['handleLLMStart']>\n ): ReturnType<CallbackHandler['handleLLMStart']> {\n return this.withRuntimeContext(\n () => super.handleLLMStart(...args),\n this.startsDetachedRun(args[2], args[3]),\n args[6]\n );\n }\n\n override handleLLMEnd(\n output: LLMResult,\n runId: string,\n parentRunId?: string\n ): Promise<void> {\n return super.handleLLMEnd(\n normalizeBedrockUsageForLangfuse(output),\n runId,\n parentRunId\n );\n }\n\n override handleToolStart(\n ...args: Parameters<CallbackHandler['handleToolStart']>\n ): ReturnType<CallbackHandler['handleToolStart']> {\n return this.withRuntimeContext(\n () => super.handleToolStart(...args),\n this.startsDetachedRun(args[2], args[3]),\n args[5]\n );\n }\n\n override handleToolError(\n ...args: Parameters<CallbackHandler['handleToolError']>\n ): ReturnType<CallbackHandler['handleToolError']> {\n const [error, runId, parentRunId] = args;\n if (error != null && parentRunId != null && isGraphInterrupt(error)) {\n return super.handleToolEnd(\n GRAPH_INTERRUPT_TOOL_OUTPUT,\n runId,\n parentRunId\n );\n }\n return super.handleToolError(...args);\n }\n\n override handleRetrieverStart(\n ...args: Parameters<CallbackHandler['handleRetrieverStart']>\n ): ReturnType<CallbackHandler['handleRetrieverStart']> {\n return this.withRuntimeContext(\n () => super.handleRetrieverStart(...args),\n this.startsDetachedRun(args[2], args[3]),\n args[5]\n );\n }\n}\n\nfunction hasLangfuseTracingConfig(langfuse?: t.LangfuseConfig): boolean {\n return (\n langfuse?.toolNodeTracing != null || langfuse?.toolOutputTracing != null\n );\n}\n\nfunction hasLangfuseTraceAttributes(langfuse?: t.LangfuseConfig): boolean {\n return (\n Object.keys(createTraceMetadata(langfuse?.metadata ?? {})).length > 0 ||\n Object.keys(\n createLibreChatTraceAttributes(langfuse?.librechatTraceAttributes ?? {})\n ).length > 0 ||\n (mergeLangfuseTags(undefined, langfuse?.tags)?.length ?? 0) > 0\n );\n}\n\nfunction hasLangfuseConfigBaseUrl(langfuse?: t.LangfuseConfig): boolean {\n return isPresent(langfuse?.baseUrl);\n}\n\nexport function isExplicitLangfuseConfig(langfuse?: t.LangfuseConfig): boolean {\n return (\n langfuse?.enabled != null ||\n isPresent(langfuse?.publicKey) ||\n isPresent(langfuse?.secretKey) ||\n isPresent(langfuse?.baseUrl) ||\n hasLangfuseTraceAttributes(langfuse) ||\n hasLangfuseTracingConfig(langfuse)\n );\n}\n\nfunction createTraceMetadata(\n metadata: Record<string, unknown>\n): LangfuseTraceMetadata {\n const traceMetadata: LangfuseTraceMetadata = {};\n for (const [key, value] of Object.entries(metadata)) {\n if (value == null) {\n continue;\n }\n const stringValue = typeof value === 'string' ? value : String(value);\n if (\n stringValue.trim() === '' ||\n stringValue.length > TRACE_METADATA_MAX_LENGTH\n ) {\n continue;\n }\n traceMetadata[key] = stringValue;\n }\n return traceMetadata;\n}\n\nexport function createLibreChatTraceAttributes(\n attributes: LangfuseConfigTraceAttributes\n): LangfuseTraceAttributes {\n const librechatTraceAttributes: LangfuseTraceAttributes = {};\n for (const [key, value] of Object.entries(attributes)) {\n if (value == null || key.trim() === '') {\n continue;\n }\n if (typeof value === 'string') {\n if (value.trim() === '' || value.length > TRACE_METADATA_MAX_LENGTH) {\n continue;\n }\n librechatTraceAttributes[key] = value;\n continue;\n }\n librechatTraceAttributes[key] = value;\n }\n return librechatTraceAttributes;\n}\n\nexport function createLangfuseTraceMetadata({\n messageId,\n parentMessageId,\n agentId,\n agentName,\n}: {\n messageId?: unknown;\n parentMessageId?: unknown;\n agentId?: unknown;\n agentName?: unknown;\n}): LangfuseTraceMetadata {\n return createTraceMetadata({\n messageId,\n parentMessageId,\n agentId,\n agentName,\n });\n}\n\nfunction mergeLangfuseTraceMetadata(\n traceMetadata?: LangfuseTraceMetadata,\n metadata?: LangfuseMetadata\n): LangfuseTraceMetadata | undefined {\n const merged = createTraceMetadata({\n ...(metadata ?? {}),\n ...(traceMetadata ?? {}),\n });\n return Object.keys(merged).length > 0 ? merged : undefined;\n}\n\nfunction mergeLangfuseTags(\n tags?: string[],\n configTags?: string[]\n): string[] | undefined {\n const merged = [...(tags ?? []), ...(configTags ?? [])].filter(\n (tag) => tag.trim() !== ''\n );\n return merged.length > 0 ? [...new Set(merged)] : undefined;\n}\n\nexport function getLangfuseTraceName(\n traceMetadata?: LangfuseTraceMetadata,\n fallback: string = 'LibreChat Agent'\n): string {\n const agentName = traceMetadata?.agentName;\n return isPresent(agentName) ? `${fallback}: ${agentName}` : fallback;\n}\n\nexport function shouldCreateLangfuseHandler(\n langfuse?: t.LangfuseConfig\n): boolean {\n if (langfuse?.enabled === false) {\n return false;\n }\n return (\n hasLangfuseEnvConfig() ||\n hasLangfuseConfigCredentials(langfuse) ||\n (hasLangfuseConfigBaseUrl(langfuse) && hasLangfuseEnvCredentials())\n );\n}\n\nexport function createLegacyLangfuseHandler(\n params: LangfuseHandlerParams\n): CallbackHandler {\n return new ScopedLangfuseCallbackHandler(params);\n}\n\nexport function createLangfuseHandler({\n langfuse,\n userId,\n sessionId,\n traceMetadata,\n tags,\n traceIdSeed,\n runId,\n toolOutputTracing,\n traceName,\n}: AgentLangfuseHandlerParams): CallbackHandler | undefined {\n if (!shouldCreateLangfuseHandler(langfuse)) {\n return undefined;\n }\n return new ScopedLangfuseCallbackHandler({\n userId,\n sessionId,\n traceMetadata: mergeLangfuseTraceMetadata(\n traceMetadata,\n langfuse?.metadata\n ),\n tags: mergeLangfuseTags(tags, langfuse?.tags),\n langfuse,\n traceIdSeed,\n runId,\n toolOutputTracing,\n traceName,\n });\n}\n\nfunction createPropagateAttributeParams({\n langfuse,\n userId,\n sessionId,\n traceMetadata,\n traceName,\n tags,\n}: LangfuseAttributeParams): PropagateAttributesParams {\n return {\n userId,\n sessionId,\n traceName,\n tags: mergeLangfuseTags(tags, langfuse?.tags),\n metadata: mergeLangfuseTraceMetadata(traceMetadata, langfuse?.metadata),\n };\n}\n\nexport function withLangfuseAttributes<T>(\n params: LangfuseAttributeParams,\n action: () => T\n): T {\n if (!shouldCreateLangfuseHandler(params.langfuse)) {\n return action();\n }\n return propagateAttributes(createPropagateAttributeParams(params), action);\n}\n\nexport function hasExplicitLangfuseConfig(\n contexts: Iterable<{ langfuse?: t.LangfuseConfig }>\n): boolean {\n for (const context of contexts) {\n if (isExplicitLangfuseConfig(context.langfuse)) {\n return true;\n }\n }\n return false;\n}\n\nexport function isLangfuseCallbackHandler(value: unknown): boolean {\n return value instanceof CallbackHandler;\n}\n\nexport async function disposeLangfuseHandler(value: unknown): Promise<void> {\n if (\n value == null ||\n parseBooleanEnv(process.env[LANGFUSE_FORCE_FLUSH_ON_DISPOSE]) !== true\n ) {\n return;\n }\n const provider = getLangfuseTracerProvider() as FlushableTracerProvider;\n await provider.forceFlush?.();\n}\n"],"mappings":";;;;;;;;;;;AAgDA,MAAM,4BAA4B;AAClC,MAAM,kCAAkC;AACxC,MAAM,+BAA+B,EAAE,aAAa,iBAAiB;AACrE,MAAM,8BAA8B,KAAK,UACvC,4BACF;AA6DA,SAAS,wBACP,SAC2B;CAC3B,MAAM,gBAAgB,QAAQ;CAC9B,MAAM,eAAgB,QAAQ,kBAC3B,UAAU;CACb,IACE,iBAAiB,QACjB,gBAAgB,QAChB,cAAc,iBAAiB,aAAa,aAE5C,OAAO;CAGT,MAAM,YAAY,aAAa,wBAAwB;CACvD,MAAM,gBAAgB,aAAa,yBAAyB;CAC5D,IAAI,cAAc,KAAK,kBAAkB,GACvC,OAAO;CAGT,OAAO;EACL,GAAG;EACH,cAAc,cAAc,eAAe,YAAY;CACzD;AACF;A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D;AAEA,SAAgB,qBACd,eACA,WAAmB,mBACX;CACR,MAAM,YAAY,eAAe;CACjC,OAAO,UAAU,SAAS,IAAI,GAAG,SAAS,IAAI,cAAc;AAC9D;AAEA,SAAgB,4BACd,UACS;CACT,IAAI,UAAU,YAAY,OACxB,OAAO;CAET,OACE,qBAAqB,KACrB,6BAA6B,QAAQ,KACpC,yBAAyB,QAAQ,KAAK,0BAA0B;AAErE;AAQA,SAAgB,sBAAsB,EACpC,UACA,QACA,WACA,eACA,MACA,aACA,OACA,mBACA,aAC0D;CAC1D,IAAI,CAAC,4BAA4B,QAAQ,GACvC;CAEF,OAAO,IAAI,8BAA8B;EACvC;EACA;EACA,eAAe,2BACb,eACA,UAAU,QACZ;EACA,MAAM,kBAAkB,MAAM,UAAU,IAAI;EAC5C;EACA;EACA;EACA;EACA;CACF,CAAC;AACH;AAEA,SAAS,+BAA+B,EACtC,UACA,QACA,WACA,eACA,WACA,QACqD;CACrD,OAAO;EACL;EACA;EACA;EACA,MAAM,kBAAkB,MAAM,UAAU,IAAI;EAC5C,UAAU,2BAA2B,eAAe,UAAU,QAAQ;CACxE;AACF;AAEA,SAAgB,uBACd,QACA,QACG;CACH,IAAI,CAAC,4BAA4B,OAAO,QAAQ,GAC9C,OAAO,OAAO;CAEhB,OAAO,oBAAoB,+BAA+B,MAAM,GAAG,MAAM;AAC3E;AAaA,SAAgB,0BAA0B,OAAyB;CACjE,OAAO,iBAAiB;AAC1B;AAEA,eAAsB,uBAAuB,OAA+B;CAC1E,IACE,SAAS,QACT,gBAAgB,QAAQ,IAAI,gCAAgC,MAAM,MAElE;CAGF,MADiB,0BACJ,CAAC,CAAC,aAAa;AAC9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"langfuseConfig.mjs","names":[],"sources":["../../src/langfuseConfig.ts"],"
|
|
1
|
+
{"version":3,"file":"langfuseConfig.mjs","names":[],"sources":["../../src/langfuseConfig.ts"],"mappings":";;AAIA,MAAa,sCAAsC;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AAY;EACf,GAAG,cAAc;CACnB,IACE,KAAA;CACN,MAAM,WACJ,YAAY,YAAY,QAAQ,cAAc,YAAY,OACtD;EACA,GAAG,YAAY;EACf,GAAG,cAAc;CACnB,IACE,KAAA;CACN,MAAM,2BACJ,YAAY,4BAA4B,QACxC,cAAc,4BAA4B,OACtC;EACA,GAAG,YAAY;EACf,GAAG,cAAc;CACnB,IACE,KAAA;CACN,MAAM,OACJ,YAAY,QAAQ,QAAQ,cAAc,QAAQ,OAC9C,CACA,GAAG,IAAI,IAAI,CACT,GAAI,YAAY,QAAQ,CAAC,GACzB,GAAI,cAAc,QAAQ,CAAC,CAC7B,CAAC,CACH,IACE,KAAA;CAEN,OAAO;EACL,GAAG;EACH,GAAG;EACH,GAAI,YAAY,OAAO,EAAE,SAAS,IAAI,CAAC;EACvC,GAAI,4BAA4B,OAAO,EAAE,yBAAyB,IAAI,CAAC;EACvE,GAAI,QAAQ,OAAO,EAAE,KAAK,IAAI,CAAC;EAC/B,GAAI,mBAAmB,OAAO,EAAE,gBAAgB,IAAI,CAAC;EACrD,GAAI,qBAAqB,OAAO,EAAE,kBAAkB,IAAI,CAAC;CAC3D;AACF"}
|
|
@@ -8,7 +8,6 @@ function hasText(value) {
|
|
|
8
8
|
function hasLangfuseRuntimeContextValue(context) {
|
|
9
9
|
return context.langfuse != null || hasText(context.traceIdSeed) || hasText(context.runId) || hasText(context.agentId) || context.toolOutputTracing != null;
|
|
10
10
|
}
|
|
11
|
-
/** sha256(seed) -> first 32 hex chars; matches `@langfuse/tracing` `createTraceId`. */
|
|
12
11
|
function traceIdFromSeed(seed) {
|
|
13
12
|
return createHash("sha256").update(seed, "utf8").digest("hex").slice(0, 32);
|
|
14
13
|
}
|
|
@@ -30,12 +29,6 @@ function getLangfuseScopeAgentId() {
|
|
|
30
29
|
function getLangfuseRuntimeToolOutputTracingConfig() {
|
|
31
30
|
return getLangfuseRuntimeContext()?.toolOutputTracing;
|
|
32
31
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Runs `fn` with a merged Langfuse runtime context. Undefined fields inherit
|
|
35
|
-
* from the parent scope; callers intentionally cannot clear parent values by
|
|
36
|
-
* passing `undefined` — use `replaceLangfuseRuntimeContext` when the parent
|
|
37
|
-
* scope must NOT leak through (a foreign concurrent run's scope).
|
|
38
|
-
*/
|
|
39
32
|
function runWithLangfuseRuntimeContext(context, fn) {
|
|
40
33
|
const next = {
|
|
41
34
|
...getLangfuseRuntimeContext() ?? {},
|
|
@@ -47,12 +40,6 @@ function runWithLangfuseRuntimeContext(context, fn) {
|
|
|
47
40
|
};
|
|
48
41
|
return hasLangfuseRuntimeContextValue(next) ? langfuseRuntimeContextStore.run(next, fn) : fn();
|
|
49
42
|
}
|
|
50
|
-
/**
|
|
51
|
-
* Runs `fn` with EXACTLY the provided context — the surrounding scope's
|
|
52
|
-
* fields do not leak through. A rejected foreign run's explicit destination
|
|
53
|
-
* or seed must not survive via merge inheritance when this run has none of
|
|
54
|
-
* its own (env-credential runs, non-deterministic runs).
|
|
55
|
-
*/
|
|
56
43
|
function replaceLangfuseRuntimeContext(context, fn) {
|
|
57
44
|
return langfuseRuntimeContextStore.run({ ...context }, fn);
|
|
58
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"langfuseRuntimeContext.mjs","names":[],"sources":["../../src/langfuseRuntimeContext.ts"],"
|
|
1
|
+
{"version":3,"file":"langfuseRuntimeContext.mjs","names":[],"sources":["../../src/langfuseRuntimeContext.ts"],"mappings":";;;AAiCA,MAAM,8BACJ,IAAI,kBAA0C;AAEhD,SAAS,QAAQ,OAA4C;CAC3D,OAAO,SAAS,QAAQ,MAAM,KAAK,MAAM;AAC3C;AAEA,SAAgB,+BACd,SACS;CACT,OACE,QAAQ,YAAY,QACpB,QAAQ,QAAQ,WAAW,KAC3B,QAAQ,QAAQ,KAAK,KACrB,QAAQ,QAAQ,OAAO,KACvB,QAAQ,qBAAqB;AAEjC;AAGA,SAAgB,gBAAgB,MAAsB;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string" && value.trim() !== "" ? value : void 0;
|
|
41
41
|
}
|
|
42
|
-
/** The run identity the active scope belongs to (see
|
|
43
|
-
* `LangfuseRuntimeContext.runId`), or `undefined` for unstamped scopes. */
|
|
44
42
|
function resolveLangfuseScopeRunId(activeContext) {
|
|
45
43
|
return getLangfuseScopeRunId() ?? getOtelScopeRunId(activeContext);
|
|
46
44
|
}
|
|
47
|
-
/** The agent identity of a per-agent overlay scope (see
|
|
48
|
-
* `LangfuseRuntimeContext.agentId`), or `undefined` for run-level scopes. */
|
|
49
45
|
function resolveLangfuseScopeAgentId(activeContext) {
|
|
50
46
|
return getLangfuseScopeAgentId() ?? getOtelScopeAgentId(activeContext);
|
|
51
47
|
}
|