@librechat/agents 3.4.6 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/agents/AgentContext.cjs +0 -356
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/agents/projection.cjs +0 -9
- package/dist/cjs/agents/projection.cjs.map +1 -1
- package/dist/cjs/common/constants.cjs +0 -26
- package/dist/cjs/common/constants.cjs.map +1 -1
- package/dist/cjs/common/enum.cjs +0 -85
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/events.cjs +0 -14
- package/dist/cjs/events.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +1 -909
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +7 -272
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/graphs/applyGraphRuntimeConfig.cjs.map +1 -1
- package/dist/cjs/graphs/createGraph.cjs.map +1 -1
- package/dist/cjs/hitl/askUserQuestion.cjs +0 -53
- package/dist/cjs/hitl/askUserQuestion.cjs.map +1 -1
- package/dist/cjs/hitl/askUserQuestions.cjs +0 -20
- package/dist/cjs/hitl/askUserQuestions.cjs.map +1 -1
- package/dist/cjs/hitl/askUserQuestionsInterrupt.cjs +0 -6
- package/dist/cjs/hitl/askUserQuestionsInterrupt.cjs.map +1 -1
- package/dist/cjs/hooks/HookRegistry.cjs +0 -127
- package/dist/cjs/hooks/HookRegistry.cjs.map +1 -1
- package/dist/cjs/hooks/createToolPolicyHook.cjs +0 -38
- package/dist/cjs/hooks/createToolPolicyHook.cjs.map +1 -1
- package/dist/cjs/hooks/createWorkspacePolicyHook.cjs +0 -77
- package/dist/cjs/hooks/createWorkspacePolicyHook.cjs.map +1 -1
- package/dist/cjs/hooks/executeHooks.cjs +0 -79
- package/dist/cjs/hooks/executeHooks.cjs.map +1 -1
- package/dist/cjs/hooks/index.cjs +0 -16
- package/dist/cjs/hooks/index.cjs.map +1 -1
- package/dist/cjs/hooks/matchers.cjs +0 -104
- package/dist/cjs/hooks/matchers.cjs.map +1 -1
- package/dist/cjs/hooks/types.cjs +0 -8
- package/dist/cjs/hooks/types.cjs.map +1 -1
- package/dist/cjs/instrumentation.cjs +0 -14
- package/dist/cjs/instrumentation.cjs.map +1 -1
- package/dist/cjs/langfuse.cjs +0 -75
- package/dist/cjs/langfuse.cjs.map +1 -1
- package/dist/cjs/langfuseConfig.cjs.map +1 -1
- package/dist/cjs/langfuseRuntimeContext.cjs +0 -13
- package/dist/cjs/langfuseRuntimeContext.cjs.map +1 -1
- package/dist/cjs/langfuseRuntimeScope.cjs +0 -4
- package/dist/cjs/langfuseRuntimeScope.cjs.map +1 -1
- package/dist/cjs/langfuseSpanRegistry.cjs +0 -28
- package/dist/cjs/langfuseSpanRegistry.cjs.map +1 -1
- package/dist/cjs/langfuseToolOutputTracing.cjs +0 -3
- package/dist/cjs/langfuseToolOutputTracing.cjs.map +1 -1
- package/dist/cjs/langfuseTraceShaping.cjs +0 -74
- package/dist/cjs/langfuseTraceShaping.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/index.cjs +0 -3
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/types.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +1 -111
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +0 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/stream_events.cjs +0 -8
- package/dist/cjs/llm/anthropic/utils/stream_events.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/tools.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/cachePoints.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/index.cjs +1 -95
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/toolCache.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +0 -78
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/utils/message_outputs.cjs +0 -24
- package/dist/cjs/llm/bedrock/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/contextOverflowRecovery.cjs +0 -62
- package/dist/cjs/llm/contextOverflowRecovery.cjs.map +1 -1
- package/dist/cjs/llm/fake.cjs.map +1 -1
- package/dist/cjs/llm/google/index.cjs +2 -21
- package/dist/cjs/llm/google/index.cjs.map +1 -1
- package/dist/cjs/llm/google/utils/common.cjs +5 -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 +5 -35
- package/dist/esm/llm/google/utils/common.mjs.map +1 -1
- package/dist/esm/llm/init.mjs +0 -9
- package/dist/esm/llm/init.mjs.map +1 -1
- package/dist/esm/llm/invoke.mjs +1 -270
- package/dist/esm/llm/invoke.mjs.map +1 -1
- package/dist/esm/llm/mistral/index.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +0 -99
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/streamMetadata.mjs +0 -21
- package/dist/esm/llm/openai/streamMetadata.mjs.map +1 -1
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
- package/dist/esm/llm/openrouter/index.mjs +0 -1
- package/dist/esm/llm/openrouter/index.mjs.map +1 -1
- package/dist/esm/llm/openrouter/toolCache.mjs +0 -6
- package/dist/esm/llm/openrouter/toolCache.mjs.map +1 -1
- package/dist/esm/llm/preempt.mjs +0 -75
- package/dist/esm/llm/preempt.mjs.map +1 -1
- package/dist/esm/llm/providers.mjs.map +1 -1
- package/dist/esm/llm/request.mjs +0 -10
- package/dist/esm/llm/request.mjs.map +1 -1
- package/dist/esm/llm/stream/chunkAdapters.mjs +0 -62
- package/dist/esm/llm/stream/chunkAdapters.mjs.map +1 -1
- package/dist/esm/llm/stream/smoother.mjs +0 -58
- package/dist/esm/llm/stream/smoother.mjs.map +1 -1
- package/dist/esm/llm/streamLimits.mjs +4 -293
- package/dist/esm/llm/streamLimits.mjs.map +1 -1
- package/dist/esm/llm/truncation.mjs +0 -36
- package/dist/esm/llm/truncation.mjs.map +1 -1
- package/dist/esm/llm/vertexai/index.mjs +0 -330
- package/dist/esm/llm/vertexai/index.mjs.map +1 -1
- package/dist/esm/messages/alternation.mjs +0 -43
- package/dist/esm/messages/alternation.mjs.map +1 -1
- package/dist/esm/messages/anthropicToolCache.mjs +0 -45
- package/dist/esm/messages/anthropicToolCache.mjs.map +1 -1
- package/dist/esm/messages/assistantPhase.mjs +0 -12
- package/dist/esm/messages/assistantPhase.mjs.map +1 -1
- package/dist/esm/messages/budget.mjs +0 -9
- package/dist/esm/messages/budget.mjs.map +1 -1
- package/dist/esm/messages/cache.mjs +0 -172
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/content.mjs +0 -9
- package/dist/esm/messages/content.mjs.map +1 -1
- package/dist/esm/messages/contextPruning.mjs +0 -15
- package/dist/esm/messages/contextPruning.mjs.map +1 -1
- package/dist/esm/messages/contextPruningSettings.mjs +0 -3
- package/dist/esm/messages/contextPruningSettings.mjs.map +1 -1
- package/dist/esm/messages/core.mjs +0 -48
- package/dist/esm/messages/core.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +1 -345
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/messages/handoffCue.mjs +0 -36
- package/dist/esm/messages/handoffCue.mjs.map +1 -1
- package/dist/esm/messages/ids.mjs.map +1 -1
- package/dist/esm/messages/injected.mjs +0 -33
- package/dist/esm/messages/injected.mjs.map +1 -1
- package/dist/esm/messages/langchain.mjs +0 -14
- package/dist/esm/messages/langchain.mjs.map +1 -1
- package/dist/esm/messages/prune.mjs +1 -184
- package/dist/esm/messages/prune.mjs.map +1 -1
- package/dist/esm/messages/recency.mjs +0 -32
- package/dist/esm/messages/recency.mjs.map +1 -1
- package/dist/esm/messages/reducer.mjs +0 -30
- package/dist/esm/messages/reducer.mjs.map +1 -1
- package/dist/esm/messages/tools.mjs +0 -14
- package/dist/esm/messages/tools.mjs.map +1 -1
- package/dist/esm/openai/index.mjs.map +1 -1
- package/dist/esm/prompts/activityLabel.mjs +9 -79
- package/dist/esm/prompts/activityLabel.mjs.map +1 -1
- package/dist/esm/responses/index.mjs.map +1 -1
- package/dist/esm/run.mjs +2 -538
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/session/AgentSession.mjs +1 -17
- package/dist/esm/session/AgentSession.mjs.map +1 -1
- package/dist/esm/session/JsonlSessionStore.mjs.map +1 -1
- package/dist/esm/session/handlers.mjs +0 -7
- package/dist/esm/session/handlers.mjs.map +1 -1
- package/dist/esm/session/ids.mjs.map +1 -1
- package/dist/esm/session/messageSerialization.mjs +0 -4
- package/dist/esm/session/messageSerialization.mjs.map +1 -1
- package/dist/esm/stream.mjs +1 -93
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/index.mjs +0 -27
- package/dist/esm/summarization/index.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +0 -273
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +0 -35
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +0 -24
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/Calculator.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +0 -13
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/CodeSessionFileSummary.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +0 -101
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ReadFile.mjs.map +1 -1
- package/dist/esm/tools/SkillTool.mjs +0 -5
- package/dist/esm/tools/SkillTool.mjs.map +1 -1
- package/dist/esm/tools/SubagentTool.mjs +0 -10
- package/dist/esm/tools/SubagentTool.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +6 -1038
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/ToolSearch.mjs +0 -179
- package/dist/esm/tools/ToolSearch.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareBridgeRuntime.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs +0 -39
- package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareSandboxTools.mjs.map +1 -1
- package/dist/esm/tools/eagerEventExecution.mjs +0 -6
- package/dist/esm/tools/eagerEventExecution.mjs.map +1 -1
- package/dist/esm/tools/handlers.mjs +1 -41
- package/dist/esm/tools/handlers.mjs.map +1 -1
- package/dist/esm/tools/intentArg.mjs +1 -132
- package/dist/esm/tools/intentArg.mjs.map +1 -1
- package/dist/esm/tools/local/CompileCheckTool.mjs +0 -25
- package/dist/esm/tools/local/CompileCheckTool.mjs.map +1 -1
- package/dist/esm/tools/local/FileCheckpointer.mjs +0 -23
- package/dist/esm/tools/local/FileCheckpointer.mjs.map +1 -1
- package/dist/esm/tools/local/LocalCodingTools.mjs +0 -80
- package/dist/esm/tools/local/LocalCodingTools.mjs.map +1 -1
- package/dist/esm/tools/local/LocalExecutionEngine.mjs +0 -126
- package/dist/esm/tools/local/LocalExecutionEngine.mjs.map +1 -1
- package/dist/esm/tools/local/LocalExecutionTools.mjs.map +1 -1
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs +0 -12
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/local/attachments.mjs +0 -44
- package/dist/esm/tools/local/attachments.mjs.map +1 -1
- package/dist/esm/tools/local/bashAst.mjs +0 -16
- package/dist/esm/tools/local/bashAst.mjs.map +1 -1
- package/dist/esm/tools/local/editStrategies.mjs +0 -14
- package/dist/esm/tools/local/editStrategies.mjs.map +1 -1
- package/dist/esm/tools/local/resolveLocalExecutionTools.mjs.map +1 -1
- package/dist/esm/tools/local/syntaxCheck.mjs +0 -31
- package/dist/esm/tools/local/syntaxCheck.mjs.map +1 -1
- package/dist/esm/tools/local/textEncoding.mjs +0 -11
- package/dist/esm/tools/local/textEncoding.mjs.map +1 -1
- package/dist/esm/tools/local/workspaceFS.mjs +0 -33
- package/dist/esm/tools/local/workspaceFS.mjs.map +1 -1
- package/dist/esm/tools/ptcTimeout.mjs.map +1 -1
- package/dist/esm/tools/schema.mjs +0 -8
- package/dist/esm/tools/schema.mjs.map +1 -1
- package/dist/esm/tools/search/anthropic.mjs +0 -9
- package/dist/esm/tools/search/anthropic.mjs.map +1 -1
- package/dist/esm/tools/search/content.mjs.map +1 -1
- package/dist/esm/tools/search/crw-scraper.mjs +0 -33
- package/dist/esm/tools/search/crw-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/crw-search.mjs +0 -2
- package/dist/esm/tools/search/crw-search.mjs.map +1 -1
- package/dist/esm/tools/search/firecrawl.mjs +0 -25
- package/dist/esm/tools/search/firecrawl.mjs.map +1 -1
- package/dist/esm/tools/search/format.mjs +0 -30
- package/dist/esm/tools/search/format.mjs.map +1 -1
- package/dist/esm/tools/search/highlights.mjs +0 -16
- package/dist/esm/tools/search/highlights.mjs.map +1 -1
- package/dist/esm/tools/search/keenable-scraper.mjs +0 -8
- package/dist/esm/tools/search/keenable-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/keenable-search.mjs +0 -7
- package/dist/esm/tools/search/keenable-search.mjs.map +1 -1
- package/dist/esm/tools/search/rerankers.mjs +0 -35
- package/dist/esm/tools/search/rerankers.mjs.map +1 -1
- package/dist/esm/tools/search/schema.mjs +0 -1
- package/dist/esm/tools/search/schema.mjs.map +1 -1
- package/dist/esm/tools/search/search.mjs +1 -14
- package/dist/esm/tools/search/search.mjs.map +1 -1
- package/dist/esm/tools/search/serper-scraper.mjs +0 -46
- package/dist/esm/tools/search/serper-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/tavily-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/tavily-search.mjs.map +1 -1
- package/dist/esm/tools/search/tool.mjs +0 -25
- package/dist/esm/tools/search/tool.mjs.map +1 -1
- package/dist/esm/tools/search/utils.mjs +0 -8
- package/dist/esm/tools/search/utils.mjs.map +1 -1
- package/dist/esm/tools/skillCatalog.mjs +0 -6
- package/dist/esm/tools/skillCatalog.mjs.map +1 -1
- package/dist/esm/tools/streamedToolCallSeals.mjs +0 -6
- package/dist/esm/tools/streamedToolCallSeals.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs +0 -2
- package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +3 -213
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentReplay.mjs.map +1 -1
- package/dist/esm/tools/subagent/childGraphConfig.mjs +0 -4
- package/dist/esm/tools/subagent/childGraphConfig.mjs.map +1 -1
- package/dist/esm/tools/subagent/runtimeLimits.mjs.map +1 -1
- package/dist/esm/tools/toolOutputReferences.mjs +1 -322
- package/dist/esm/tools/toolOutputReferences.mjs.map +1 -1
- package/dist/esm/types/hitl.mjs +0 -5
- package/dist/esm/types/hitl.mjs.map +1 -1
- package/dist/esm/utils/callbacks.mjs.map +1 -1
- package/dist/esm/utils/errors.mjs +14 -165
- package/dist/esm/utils/errors.mjs.map +1 -1
- package/dist/esm/utils/events.mjs +0 -10
- package/dist/esm/utils/events.mjs.map +1 -1
- package/dist/esm/utils/graph.mjs.map +1 -1
- package/dist/esm/utils/handlers.mjs +0 -3
- package/dist/esm/utils/handlers.mjs.map +1 -1
- package/dist/esm/utils/llm.mjs +0 -1
- package/dist/esm/utils/llm.mjs.map +1 -1
- package/dist/esm/utils/misc.mjs +0 -16
- package/dist/esm/utils/misc.mjs.map +1 -1
- package/dist/esm/utils/proxy.mjs +0 -26
- package/dist/esm/utils/proxy.mjs.map +1 -1
- package/dist/esm/utils/run.mjs +0 -6
- package/dist/esm/utils/run.mjs.map +1 -1
- package/dist/esm/utils/schema.mjs +0 -5
- package/dist/esm/utils/schema.mjs.map +1 -1
- package/dist/esm/utils/title.mjs +0 -6
- package/dist/esm/utils/title.mjs.map +1 -1
- package/dist/esm/utils/tokens.mjs +0 -113
- package/dist/esm/utils/tokens.mjs.map +1 -1
- package/dist/esm/utils/toolContent.mjs +0 -41
- package/dist/esm/utils/toolContent.mjs.map +1 -1
- package/dist/esm/utils/truncation.mjs +0 -61
- package/dist/esm/utils/truncation.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +3 -3
- package/dist/types/agents/__tests__/promptCacheLiveHelpers.d.ts +3 -3
- package/dist/types/agents/projection.d.ts +1 -1
- package/dist/types/events.d.ts +2 -2
- package/dist/types/graphs/Graph.d.ts +11 -11
- package/dist/types/graphs/MultiAgentGraph.d.ts +2 -2
- package/dist/types/graphs/createGraph.d.ts +4 -4
- package/dist/types/graphs/graphFactory.d.ts +1 -1
- package/dist/types/hitl/askUserQuestion.d.ts +1 -1
- package/dist/types/hitl/askUserQuestions.d.ts +1 -1
- package/dist/types/hitl/askUserQuestionsInterrupt.d.ts +1 -1
- package/dist/types/hooks/types.d.ts +1 -1
- package/dist/types/instrumentation.d.ts +1 -1
- package/dist/types/langfuse.d.ts +3 -3
- package/dist/types/langfuseConfig.d.ts +2 -2
- package/dist/types/langfuseRuntimeContext.d.ts +1 -1
- package/dist/types/langfuseRuntimeScope.d.ts +2 -2
- package/dist/types/langfuseSpanRegistry.d.ts +1 -1
- package/dist/types/langfuseToolOutputTracing.d.ts +3 -3
- package/dist/types/llm/anthropic/index.d.ts +1 -1
- package/dist/types/llm/bedrock/index.d.ts +1 -1
- package/dist/types/llm/bedrock/toolCache.d.ts +2 -2
- package/dist/types/llm/contextOverflowRecovery.d.ts +2 -2
- package/dist/types/llm/google/index.d.ts +1 -1
- package/dist/types/llm/init.d.ts +2 -2
- package/dist/types/llm/invoke.d.ts +6 -6
- package/dist/types/llm/mistral/index.d.ts +1 -1
- package/dist/types/llm/openai/index.d.ts +2 -2
- package/dist/types/llm/openrouter/index.d.ts +2 -2
- package/dist/types/llm/openrouter/toolCache.d.ts +2 -2
- package/dist/types/llm/providers.d.ts +2 -2
- package/dist/types/llm/request.d.ts +2 -2
- package/dist/types/llm/stream/chunkAdapters.d.ts +1 -1
- package/dist/types/llm/streamLimits.d.ts +1 -1
- package/dist/types/llm/truncation.d.ts +1 -1
- package/dist/types/llm/vertexai/index.d.ts +1 -1
- package/dist/types/messages/alternation.d.ts +1 -1
- package/dist/types/messages/anthropicToolCache.d.ts +2 -2
- package/dist/types/messages/assistantPhase.d.ts +3 -3
- package/dist/types/messages/budget.d.ts +1 -1
- package/dist/types/messages/cache.d.ts +1 -1
- package/dist/types/messages/contextPruning.d.ts +2 -2
- package/dist/types/messages/core.d.ts +2 -2
- package/dist/types/messages/format.d.ts +2 -2
- package/dist/types/messages/ids.d.ts +2 -2
- package/dist/types/messages/injected.d.ts +1 -1
- package/dist/types/messages/langchain.d.ts +1 -1
- package/dist/types/messages/prune.d.ts +3 -3
- package/dist/types/openai/index.d.ts +1 -1
- package/dist/types/prompts/activityLabel.d.ts +2 -2
- package/dist/types/responses/index.d.ts +1 -1
- package/dist/types/run.d.ts +3 -3
- package/dist/types/session/handlers.d.ts +1 -1
- package/dist/types/session/types.d.ts +1 -1
- package/dist/types/stream.d.ts +4 -4
- package/dist/types/summarization/index.d.ts +1 -1
- package/dist/types/summarization/node.d.ts +6 -6
- package/dist/types/test/mockTools.d.ts +1 -1
- package/dist/types/tools/BashExecutor.d.ts +2 -2
- package/dist/types/tools/BashProgrammaticToolCalling.d.ts +2 -2
- package/dist/types/tools/CodeExecutor.d.ts +3 -3
- package/dist/types/tools/CodeSessionFileSummary.d.ts +1 -1
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +2 -2
- package/dist/types/tools/ReadFile.d.ts +1 -1
- package/dist/types/tools/SkillTool.d.ts +1 -1
- package/dist/types/tools/SubagentTool.d.ts +3 -3
- package/dist/types/tools/ToolNode.d.ts +5 -5
- package/dist/types/tools/ToolSearch.d.ts +2 -2
- package/dist/types/tools/cloudflare/CloudflareBridgeRuntime.d.ts +1 -1
- package/dist/types/tools/cloudflare/CloudflareProgrammaticToolCalling.d.ts +1 -1
- package/dist/types/tools/cloudflare/CloudflareSandboxExecutionEngine.d.ts +2 -2
- package/dist/types/tools/cloudflare/CloudflareSandboxTools.d.ts +1 -1
- package/dist/types/tools/eagerEventExecution.d.ts +1 -1
- package/dist/types/tools/handlers.d.ts +3 -3
- package/dist/types/tools/intentArg.d.ts +1 -1
- package/dist/types/tools/local/CompileCheckTool.d.ts +2 -2
- package/dist/types/tools/local/FileCheckpointer.d.ts +1 -1
- package/dist/types/tools/local/LocalCodingTools.d.ts +2 -2
- package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -1
- package/dist/types/tools/local/LocalExecutionTools.d.ts +1 -1
- package/dist/types/tools/local/LocalProgrammaticToolCalling.d.ts +1 -1
- package/dist/types/tools/local/bashAst.d.ts +1 -1
- package/dist/types/tools/local/resolveLocalExecutionTools.d.ts +1 -1
- package/dist/types/tools/local/syntaxCheck.d.ts +1 -1
- package/dist/types/tools/ptcTimeout.d.ts +1 -1
- package/dist/types/tools/schema.d.ts +1 -1
- package/dist/types/tools/search/anthropic.d.ts +1 -1
- package/dist/types/tools/skillCatalog.d.ts +1 -1
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +5 -5
- package/dist/types/tools/subagent/SubagentReplay.d.ts +3 -3
- package/dist/types/tools/subagent/childGraphConfig.d.ts +2 -2
- package/dist/types/types/activityLabel.d.ts +3 -3
- package/dist/types/types/graph.d.ts +7 -7
- package/dist/types/types/llm.d.ts +9 -9
- package/dist/types/types/run.d.ts +7 -7
- package/dist/types/types/stream.d.ts +5 -5
- package/dist/types/types/summarize.d.ts +2 -2
- package/dist/types/types/tools.d.ts +5 -5
- package/dist/types/utils/__tests__/fixtures/contextOverflowSignatures.d.ts +1 -1
- package/dist/types/utils/errors.d.ts +1 -1
- package/dist/types/utils/events.d.ts +1 -1
- package/dist/types/utils/handlers.d.ts +3 -3
- package/dist/types/utils/llm.d.ts +1 -1
- package/dist/types/utils/llmConfig.d.ts +1 -1
- package/dist/types/utils/title.d.ts +1 -1
- package/package.json +10 -3
- package/src/llm/google/utils/common.ts +6 -4
- 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 -185
- 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,1578 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { tool } from '@langchain/core/tools';
|
|
3
|
-
import { LangfuseOtelSpanAttributes } from '@langfuse/tracing';
|
|
4
|
-
import { CallbackManager } from '@langchain/core/callbacks/manager';
|
|
5
|
-
import { AIMessage, HumanMessage, ToolMessage } from '@langchain/core/messages';
|
|
6
|
-
import { context as otelContext, trace as otelTrace } from '@opentelemetry/api';
|
|
7
|
-
import {
|
|
8
|
-
Command,
|
|
9
|
-
END,
|
|
10
|
-
GraphInterrupt,
|
|
11
|
-
MemorySaver,
|
|
12
|
-
MessagesAnnotation,
|
|
13
|
-
NodeInterrupt,
|
|
14
|
-
ParentCommand,
|
|
15
|
-
START,
|
|
16
|
-
StateGraph,
|
|
17
|
-
isGraphInterrupt,
|
|
18
|
-
isInterrupted,
|
|
19
|
-
} from '@langchain/langgraph';
|
|
20
|
-
import type { ToolCall } from '@langchain/core/messages/tool';
|
|
21
|
-
import type * as t from '@/types';
|
|
22
|
-
import { handleConverseStreamMetadata } from '@/llm/bedrock/utils/message_outputs';
|
|
23
|
-
import { traceIdFromSeed } from '@/langfuseRuntimeContext';
|
|
24
|
-
import { Constants, Providers } from '@/common';
|
|
25
|
-
import { ToolNode } from '@/tools/ToolNode';
|
|
26
|
-
import { askUserQuestion } from '@/hitl';
|
|
27
|
-
import { Run } from '@/run';
|
|
28
|
-
|
|
29
|
-
const mockProcessorStarts: Array<{
|
|
30
|
-
params: unknown;
|
|
31
|
-
traceId: string;
|
|
32
|
-
}> = [];
|
|
33
|
-
const mockSpanAttributeSets: Array<Record<string, unknown>> = [];
|
|
34
|
-
let mockSpansStarted = 0;
|
|
35
|
-
let mockSpansEnded = 0;
|
|
36
|
-
let mockProviderInput:
|
|
37
|
-
| {
|
|
38
|
-
spanProcessors?: Array<{
|
|
39
|
-
onStart?: (span: unknown, parentContext: unknown) => void;
|
|
40
|
-
onEnd?: (span: unknown) => void;
|
|
41
|
-
}>;
|
|
42
|
-
idGenerator?: {
|
|
43
|
-
generateTraceId: () => string;
|
|
44
|
-
generateSpanId: () => string;
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
| undefined;
|
|
48
|
-
|
|
49
|
-
const createMockSpan = (traceIdOverride?: string) => {
|
|
50
|
-
mockSpansStarted += 1;
|
|
51
|
-
const traceId =
|
|
52
|
-
traceIdOverride ??
|
|
53
|
-
mockProviderInput?.idGenerator?.generateTraceId() ??
|
|
54
|
-
'trace-id';
|
|
55
|
-
const spanId = mockProviderInput?.idGenerator?.generateSpanId() ?? 'span-id';
|
|
56
|
-
const span = {
|
|
57
|
-
end: jest.fn(() => {
|
|
58
|
-
mockSpansEnded += 1;
|
|
59
|
-
for (const processor of mockProviderInput?.spanProcessors ?? []) {
|
|
60
|
-
processor.onEnd?.(span);
|
|
61
|
-
}
|
|
62
|
-
}),
|
|
63
|
-
spanContext: jest.fn(() => ({
|
|
64
|
-
traceId,
|
|
65
|
-
spanId,
|
|
66
|
-
traceFlags: 1,
|
|
67
|
-
})),
|
|
68
|
-
setAttributes: jest.fn((attributes: Record<string, unknown>) => {
|
|
69
|
-
mockSpanAttributeSets.push(attributes);
|
|
70
|
-
}),
|
|
71
|
-
setStatus: jest.fn(),
|
|
72
|
-
attributes: {},
|
|
73
|
-
};
|
|
74
|
-
for (const processor of mockProviderInput?.spanProcessors ?? []) {
|
|
75
|
-
processor.onStart?.(span, otelContext.active());
|
|
76
|
-
}
|
|
77
|
-
return span;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const mockStartSpan = jest.fn(() => createMockSpan());
|
|
81
|
-
const mockStartActiveSpan = jest.fn(
|
|
82
|
-
(
|
|
83
|
-
_name: string,
|
|
84
|
-
_options: unknown,
|
|
85
|
-
activeContext: Parameters<typeof otelTrace.getSpanContext>[0],
|
|
86
|
-
callback: (span: ReturnType<typeof createMockSpan>) => unknown
|
|
87
|
-
) =>
|
|
88
|
-
callback(createMockSpan(otelTrace.getSpanContext(activeContext)?.traceId))
|
|
89
|
-
);
|
|
90
|
-
const mockForceFlush = jest.fn();
|
|
91
|
-
const mockShutdown = jest.fn();
|
|
92
|
-
|
|
93
|
-
jest.mock('@langfuse/otel', () => ({
|
|
94
|
-
LangfuseSpanProcessor: jest.fn().mockImplementation((params) => ({
|
|
95
|
-
forceFlush: jest.fn(),
|
|
96
|
-
onEnd: jest.fn(),
|
|
97
|
-
onStart: jest.fn((span) => {
|
|
98
|
-
mockProcessorStarts.push({
|
|
99
|
-
params,
|
|
100
|
-
traceId: span.spanContext().traceId,
|
|
101
|
-
});
|
|
102
|
-
}),
|
|
103
|
-
shutdown: jest.fn(),
|
|
104
|
-
})),
|
|
105
|
-
isDefaultExportSpan: jest.fn(() => false),
|
|
106
|
-
}));
|
|
107
|
-
|
|
108
|
-
jest.mock('@opentelemetry/sdk-trace-base', () => ({
|
|
109
|
-
BasicTracerProvider: jest.fn().mockImplementation((input) => {
|
|
110
|
-
mockProviderInput = input;
|
|
111
|
-
return {
|
|
112
|
-
forceFlush: mockForceFlush,
|
|
113
|
-
getTracer: jest.fn(() => ({
|
|
114
|
-
startActiveSpan: mockStartActiveSpan,
|
|
115
|
-
startSpan: mockStartSpan,
|
|
116
|
-
})),
|
|
117
|
-
shutdown: mockShutdown,
|
|
118
|
-
};
|
|
119
|
-
}),
|
|
120
|
-
}));
|
|
121
|
-
|
|
122
|
-
describe('Langfuse callback composition', () => {
|
|
123
|
-
beforeEach(() => {
|
|
124
|
-
jest.clearAllMocks();
|
|
125
|
-
mockProcessorStarts.length = 0;
|
|
126
|
-
mockSpanAttributeSets.length = 0;
|
|
127
|
-
mockSpansStarted = 0;
|
|
128
|
-
mockSpansEnded = 0;
|
|
129
|
-
delete process.env.LANGFUSE_PUBLIC_KEY;
|
|
130
|
-
delete process.env.LANGFUSE_SECRET_KEY;
|
|
131
|
-
delete process.env.LANGFUSE_BASE_URL;
|
|
132
|
-
delete process.env.LANGFUSE_BASEURL;
|
|
133
|
-
delete process.env.LANGFUSE_FORCE_FLUSH_ON_DISPOSE;
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('runs explicit per-agent tracing when callbacks is a CallbackManager', async () => {
|
|
137
|
-
const manager = CallbackManager.fromHandlers({
|
|
138
|
-
handleCustomEvent: async (): Promise<void> => undefined,
|
|
139
|
-
});
|
|
140
|
-
const run = await Run.create<t.IState>({
|
|
141
|
-
runId: 'test-langfuse-callback-manager',
|
|
142
|
-
graphConfig: {
|
|
143
|
-
type: 'standard',
|
|
144
|
-
agents: [
|
|
145
|
-
{
|
|
146
|
-
agentId: 'agent_abc123',
|
|
147
|
-
name: 'DWAINE',
|
|
148
|
-
provider: Providers.OPENAI,
|
|
149
|
-
clientOptions: { model: 'gpt-4' },
|
|
150
|
-
tools: [],
|
|
151
|
-
langfuse: {
|
|
152
|
-
enabled: true,
|
|
153
|
-
publicKey: 'pk-test',
|
|
154
|
-
secretKey: 'sk-test',
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
],
|
|
158
|
-
},
|
|
159
|
-
skipCleanup: true,
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
run.Graph?.overrideTestModel(['hello']);
|
|
163
|
-
|
|
164
|
-
const config = {
|
|
165
|
-
callbacks: manager,
|
|
166
|
-
configurable: { thread_id: 'thread-1', user_id: 'user-1' },
|
|
167
|
-
streamMode: 'values' as const,
|
|
168
|
-
version: 'v2' as const,
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
await run.processStream({ messages: [new HumanMessage('hello')] }, config);
|
|
172
|
-
|
|
173
|
-
expect(mockStartActiveSpan).toHaveBeenCalled();
|
|
174
|
-
expect(mockForceFlush).not.toHaveBeenCalled();
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it('attaches Langfuse callbacks for direct graph invocations', async () => {
|
|
178
|
-
const run = await Run.create<t.IState>({
|
|
179
|
-
runId: 'test-langfuse-direct-graph',
|
|
180
|
-
graphConfig: {
|
|
181
|
-
type: 'standard',
|
|
182
|
-
agents: [
|
|
183
|
-
{
|
|
184
|
-
agentId: 'agent_abc123',
|
|
185
|
-
name: 'DWAINE',
|
|
186
|
-
provider: Providers.OPENAI,
|
|
187
|
-
clientOptions: { model: 'gpt-4' },
|
|
188
|
-
tools: [],
|
|
189
|
-
langfuse: {
|
|
190
|
-
enabled: true,
|
|
191
|
-
publicKey: 'pk-test',
|
|
192
|
-
secretKey: 'sk-test',
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
],
|
|
196
|
-
},
|
|
197
|
-
skipCleanup: true,
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
run.Graph?.overrideTestModel(['hello']);
|
|
201
|
-
const workflow = run.Graph?.createWorkflow();
|
|
202
|
-
await workflow?.invoke(
|
|
203
|
-
{ messages: [new HumanMessage('hello')] },
|
|
204
|
-
{
|
|
205
|
-
callbacks: [],
|
|
206
|
-
configurable: { thread_id: 'thread-1', user_id: 'user-1' },
|
|
207
|
-
}
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
expect(mockStartActiveSpan).toHaveBeenCalled();
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
it('preserves per-agent Langfuse config when a stream callback already exists', async () => {
|
|
214
|
-
const { LangfuseSpanProcessor } = await import('@langfuse/otel');
|
|
215
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
216
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
217
|
-
initializeLangfuseTracing({
|
|
218
|
-
publicKey: 'pk-run',
|
|
219
|
-
secretKey: 'sk-run',
|
|
220
|
-
baseUrl: 'https://langfuse.run',
|
|
221
|
-
});
|
|
222
|
-
const streamHandler = createLangfuseHandler({
|
|
223
|
-
langfuse: {
|
|
224
|
-
publicKey: 'pk-run',
|
|
225
|
-
secretKey: 'sk-run',
|
|
226
|
-
baseUrl: 'https://langfuse.run',
|
|
227
|
-
},
|
|
228
|
-
});
|
|
229
|
-
const run = await Run.create<t.IState>({
|
|
230
|
-
runId: 'test-langfuse-agent-callback-override',
|
|
231
|
-
graphConfig: {
|
|
232
|
-
type: 'standard',
|
|
233
|
-
agents: [
|
|
234
|
-
{
|
|
235
|
-
agentId: 'agent_abc123',
|
|
236
|
-
name: 'DWAINE',
|
|
237
|
-
provider: Providers.OPENAI,
|
|
238
|
-
clientOptions: { model: 'gpt-4' },
|
|
239
|
-
tools: [],
|
|
240
|
-
langfuse: {
|
|
241
|
-
enabled: true,
|
|
242
|
-
publicKey: 'pk-agent',
|
|
243
|
-
secretKey: 'sk-agent',
|
|
244
|
-
baseUrl: 'https://langfuse.agent',
|
|
245
|
-
},
|
|
246
|
-
},
|
|
247
|
-
],
|
|
248
|
-
},
|
|
249
|
-
skipCleanup: true,
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
run.Graph?.overrideTestModel(['hello']);
|
|
253
|
-
const workflow = run.Graph?.createWorkflow();
|
|
254
|
-
await workflow?.invoke(
|
|
255
|
-
{ messages: [new HumanMessage('hello')] },
|
|
256
|
-
{
|
|
257
|
-
callbacks: streamHandler != null ? [streamHandler] : [],
|
|
258
|
-
configurable: { thread_id: 'thread-1', user_id: 'user-1' },
|
|
259
|
-
}
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
expect(LangfuseSpanProcessor).toHaveBeenCalledWith(
|
|
263
|
-
expect.objectContaining({
|
|
264
|
-
publicKey: 'pk-agent',
|
|
265
|
-
secretKey: 'sk-agent',
|
|
266
|
-
baseUrl: 'https://langfuse.agent',
|
|
267
|
-
})
|
|
268
|
-
);
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
it('binds handler callback spans to their own Langfuse config and trace seed', async () => {
|
|
272
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
273
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
274
|
-
const tenantA = {
|
|
275
|
-
publicKey: 'pk-tenant-a',
|
|
276
|
-
secretKey: 'sk-tenant-a',
|
|
277
|
-
baseUrl: 'https://langfuse.proxy',
|
|
278
|
-
deterministicTraceId: true,
|
|
279
|
-
};
|
|
280
|
-
const tenantB = {
|
|
281
|
-
publicKey: 'pk-tenant-b',
|
|
282
|
-
secretKey: 'sk-tenant-b',
|
|
283
|
-
baseUrl: 'https://langfuse.proxy',
|
|
284
|
-
deterministicTraceId: true,
|
|
285
|
-
};
|
|
286
|
-
initializeLangfuseTracing(tenantA);
|
|
287
|
-
initializeLangfuseTracing(tenantB);
|
|
288
|
-
|
|
289
|
-
const handlerA = createLangfuseHandler({
|
|
290
|
-
langfuse: tenantA,
|
|
291
|
-
traceIdSeed: 'run-tenant-a',
|
|
292
|
-
});
|
|
293
|
-
const handlerB = createLangfuseHandler({
|
|
294
|
-
langfuse: tenantB,
|
|
295
|
-
traceIdSeed: 'run-tenant-b',
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
await Promise.all([
|
|
299
|
-
handlerA?.handleChainStart(
|
|
300
|
-
{ lc: 1, type: 'not_implemented', id: ['TenantAChain'] },
|
|
301
|
-
{ input: 'tenant a' },
|
|
302
|
-
'lc-run-a'
|
|
303
|
-
),
|
|
304
|
-
handlerB?.handleChainStart(
|
|
305
|
-
{ lc: 1, type: 'not_implemented', id: ['TenantBChain'] },
|
|
306
|
-
{ input: 'tenant b' },
|
|
307
|
-
'lc-run-b'
|
|
308
|
-
),
|
|
309
|
-
]);
|
|
310
|
-
|
|
311
|
-
expect(mockProcessorStarts).toEqual(
|
|
312
|
-
expect.arrayContaining([
|
|
313
|
-
expect.objectContaining({
|
|
314
|
-
params: expect.objectContaining({
|
|
315
|
-
publicKey: 'pk-tenant-a',
|
|
316
|
-
secretKey: 'sk-tenant-a',
|
|
317
|
-
baseUrl: 'https://langfuse.proxy',
|
|
318
|
-
}),
|
|
319
|
-
traceId: traceIdFromSeed('run-tenant-a'),
|
|
320
|
-
}),
|
|
321
|
-
expect.objectContaining({
|
|
322
|
-
params: expect.objectContaining({
|
|
323
|
-
publicKey: 'pk-tenant-b',
|
|
324
|
-
secretKey: 'sk-tenant-b',
|
|
325
|
-
baseUrl: 'https://langfuse.proxy',
|
|
326
|
-
}),
|
|
327
|
-
traceId: traceIdFromSeed('run-tenant-b'),
|
|
328
|
-
}),
|
|
329
|
-
])
|
|
330
|
-
);
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
it('preserves an active agent Langfuse runtime scope for callback-created spans', async () => {
|
|
334
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
335
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
336
|
-
const { withLangfuseRuntimeScope } = await import('@/langfuseRuntimeScope');
|
|
337
|
-
const runLangfuse = {
|
|
338
|
-
publicKey: 'pk-run',
|
|
339
|
-
secretKey: 'sk-run',
|
|
340
|
-
baseUrl: 'https://langfuse.run',
|
|
341
|
-
deterministicTraceId: true,
|
|
342
|
-
};
|
|
343
|
-
const agentLangfuse = {
|
|
344
|
-
publicKey: 'pk-agent',
|
|
345
|
-
secretKey: 'sk-agent',
|
|
346
|
-
baseUrl: 'https://langfuse.agent',
|
|
347
|
-
deterministicTraceId: true,
|
|
348
|
-
};
|
|
349
|
-
initializeLangfuseTracing(runLangfuse);
|
|
350
|
-
initializeLangfuseTracing(agentLangfuse);
|
|
351
|
-
const streamHandler = createLangfuseHandler({
|
|
352
|
-
langfuse: runLangfuse,
|
|
353
|
-
traceIdSeed: 'run-seed',
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
await withLangfuseRuntimeScope(
|
|
357
|
-
{ langfuse: agentLangfuse, traceIdSeed: 'agent-seed' },
|
|
358
|
-
() =>
|
|
359
|
-
streamHandler?.handleChainStart(
|
|
360
|
-
{ lc: 1, type: 'not_implemented', id: ['AgentScopedChain'] },
|
|
361
|
-
{ input: 'agent scoped' },
|
|
362
|
-
'lc-agent-run'
|
|
363
|
-
)
|
|
364
|
-
);
|
|
365
|
-
|
|
366
|
-
expect(mockProcessorStarts).toContainEqual(
|
|
367
|
-
expect.objectContaining({
|
|
368
|
-
params: expect.objectContaining({
|
|
369
|
-
publicKey: 'pk-agent',
|
|
370
|
-
secretKey: 'sk-agent',
|
|
371
|
-
baseUrl: 'https://langfuse.agent',
|
|
372
|
-
}),
|
|
373
|
-
traceId: traceIdFromSeed('agent-seed'),
|
|
374
|
-
})
|
|
375
|
-
);
|
|
376
|
-
expect(mockProcessorStarts).not.toContainEqual(
|
|
377
|
-
expect.objectContaining({
|
|
378
|
-
params: expect.objectContaining({
|
|
379
|
-
publicKey: 'pk-run',
|
|
380
|
-
secretKey: 'sk-run',
|
|
381
|
-
baseUrl: 'https://langfuse.run',
|
|
382
|
-
}),
|
|
383
|
-
traceId: traceIdFromSeed('run-seed'),
|
|
384
|
-
})
|
|
385
|
-
);
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
it('keeps callback spans on their own run when a foreign run scope is active', async () => {
|
|
389
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
390
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
391
|
-
const { withLangfuseRuntimeScope } = await import('@/langfuseRuntimeScope');
|
|
392
|
-
const tenantA = {
|
|
393
|
-
publicKey: 'pk-tenant-a',
|
|
394
|
-
secretKey: 'sk-tenant-a',
|
|
395
|
-
baseUrl: 'https://langfuse.tenant-a',
|
|
396
|
-
deterministicTraceId: true,
|
|
397
|
-
};
|
|
398
|
-
const tenantB = {
|
|
399
|
-
publicKey: 'pk-tenant-b',
|
|
400
|
-
secretKey: 'sk-tenant-b',
|
|
401
|
-
baseUrl: 'https://langfuse.tenant-b',
|
|
402
|
-
deterministicTraceId: true,
|
|
403
|
-
};
|
|
404
|
-
initializeLangfuseTracing(tenantA);
|
|
405
|
-
initializeLangfuseTracing(tenantB);
|
|
406
|
-
const handlerB = createLangfuseHandler({
|
|
407
|
-
langfuse: tenantB,
|
|
408
|
-
traceIdSeed: 'run-b',
|
|
409
|
-
runId: 'run-b',
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
// LangChain's background callback queue (`consumeCallback`) executes
|
|
413
|
-
// non-awaited callbacks inside whichever concurrent run's async context
|
|
414
|
-
// the queue drain happens to be on — here, tenant-A's. A scope stamped
|
|
415
|
-
// with a different run must never reroute tenant-B's spans.
|
|
416
|
-
await withLangfuseRuntimeScope(
|
|
417
|
-
{ langfuse: tenantA, traceIdSeed: 'run-a', runId: 'run-a' },
|
|
418
|
-
() =>
|
|
419
|
-
handlerB?.handleChainStart(
|
|
420
|
-
{ lc: 1, type: 'not_implemented', id: ['ForeignScopedChain'] },
|
|
421
|
-
{ input: 'foreign scoped' },
|
|
422
|
-
'lc-foreign-run'
|
|
423
|
-
)
|
|
424
|
-
);
|
|
425
|
-
|
|
426
|
-
expect(mockProcessorStarts).toContainEqual(
|
|
427
|
-
expect.objectContaining({
|
|
428
|
-
params: expect.objectContaining({
|
|
429
|
-
publicKey: 'pk-tenant-b',
|
|
430
|
-
secretKey: 'sk-tenant-b',
|
|
431
|
-
baseUrl: 'https://langfuse.tenant-b',
|
|
432
|
-
}),
|
|
433
|
-
traceId: traceIdFromSeed('run-b'),
|
|
434
|
-
})
|
|
435
|
-
);
|
|
436
|
-
expect(
|
|
437
|
-
mockProcessorStarts.filter(
|
|
438
|
-
(record) =>
|
|
439
|
-
(record.params as { publicKey?: string }).publicKey ===
|
|
440
|
-
'pk-tenant-a' || record.traceId === traceIdFromSeed('run-a')
|
|
441
|
-
)
|
|
442
|
-
).toHaveLength(0);
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
it('adopts an agent overlay scope stamped with the handler run', async () => {
|
|
446
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
447
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
448
|
-
const { withLangfuseRuntimeScope } = await import('@/langfuseRuntimeScope');
|
|
449
|
-
const runLangfuse = {
|
|
450
|
-
publicKey: 'pk-run',
|
|
451
|
-
secretKey: 'sk-run',
|
|
452
|
-
baseUrl: 'https://langfuse.run',
|
|
453
|
-
deterministicTraceId: true,
|
|
454
|
-
};
|
|
455
|
-
const agentLangfuse = {
|
|
456
|
-
publicKey: 'pk-agent',
|
|
457
|
-
secretKey: 'sk-agent',
|
|
458
|
-
baseUrl: 'https://langfuse.agent',
|
|
459
|
-
deterministicTraceId: true,
|
|
460
|
-
};
|
|
461
|
-
initializeLangfuseTracing(runLangfuse);
|
|
462
|
-
initializeLangfuseTracing(agentLangfuse);
|
|
463
|
-
const streamHandler = createLangfuseHandler({
|
|
464
|
-
langfuse: runLangfuse,
|
|
465
|
-
traceIdSeed: 'run-seed',
|
|
466
|
-
runId: 'run-1',
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
await withLangfuseRuntimeScope(
|
|
470
|
-
{ langfuse: agentLangfuse, traceIdSeed: 'agent-seed', runId: 'run-1' },
|
|
471
|
-
() =>
|
|
472
|
-
streamHandler?.handleChainStart(
|
|
473
|
-
{ lc: 1, type: 'not_implemented', id: ['SameRunOverlayChain'] },
|
|
474
|
-
{ input: 'same run overlay' },
|
|
475
|
-
'lc-overlay-run'
|
|
476
|
-
)
|
|
477
|
-
);
|
|
478
|
-
|
|
479
|
-
expect(mockProcessorStarts).toContainEqual(
|
|
480
|
-
expect.objectContaining({
|
|
481
|
-
params: expect.objectContaining({
|
|
482
|
-
publicKey: 'pk-agent',
|
|
483
|
-
secretKey: 'sk-agent',
|
|
484
|
-
baseUrl: 'https://langfuse.agent',
|
|
485
|
-
}),
|
|
486
|
-
traceId: traceIdFromSeed('agent-seed'),
|
|
487
|
-
})
|
|
488
|
-
);
|
|
489
|
-
});
|
|
490
|
-
|
|
491
|
-
it('scopes agent overlays to the callback agent in parallel fan-out', async () => {
|
|
492
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
493
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
494
|
-
const { withLangfuseRuntimeScope } = await import('@/langfuseRuntimeScope');
|
|
495
|
-
const runLangfuse = {
|
|
496
|
-
publicKey: 'pk-run',
|
|
497
|
-
secretKey: 'sk-run',
|
|
498
|
-
baseUrl: 'https://langfuse.run',
|
|
499
|
-
deterministicTraceId: true,
|
|
500
|
-
};
|
|
501
|
-
const agentBLangfuse = {
|
|
502
|
-
publicKey: 'pk-agent-b',
|
|
503
|
-
secretKey: 'sk-agent-b',
|
|
504
|
-
baseUrl: 'https://langfuse.agent-b',
|
|
505
|
-
deterministicTraceId: true,
|
|
506
|
-
};
|
|
507
|
-
initializeLangfuseTracing(runLangfuse);
|
|
508
|
-
initializeLangfuseTracing(agentBLangfuse);
|
|
509
|
-
const streamHandler = createLangfuseHandler({
|
|
510
|
-
langfuse: runLangfuse,
|
|
511
|
-
traceIdSeed: 'run-seed',
|
|
512
|
-
runId: 'run-1',
|
|
513
|
-
});
|
|
514
|
-
|
|
515
|
-
// Agent B's overlay scope is ambient (the background callback queue can
|
|
516
|
-
// interleave concurrent fan-out agents), but this callback reports agent
|
|
517
|
-
// A via inherited langgraph metadata — a sibling's overlay must not
|
|
518
|
-
// capture it.
|
|
519
|
-
await withLangfuseRuntimeScope(
|
|
520
|
-
{
|
|
521
|
-
langfuse: agentBLangfuse,
|
|
522
|
-
traceIdSeed: 'agent-b-seed',
|
|
523
|
-
runId: 'run-1',
|
|
524
|
-
agentId: 'agent-b',
|
|
525
|
-
},
|
|
526
|
-
() =>
|
|
527
|
-
streamHandler?.handleChainStart(
|
|
528
|
-
{ lc: 1, type: 'not_implemented', id: ['SiblingAgentChain'] },
|
|
529
|
-
{ input: 'sibling agent' },
|
|
530
|
-
'lc-sibling-run',
|
|
531
|
-
undefined,
|
|
532
|
-
undefined,
|
|
533
|
-
{ langgraph_node: 'agent=agent-a' }
|
|
534
|
-
)
|
|
535
|
-
);
|
|
536
|
-
|
|
537
|
-
expect(mockProcessorStarts).toContainEqual(
|
|
538
|
-
expect.objectContaining({
|
|
539
|
-
params: expect.objectContaining({ publicKey: 'pk-run' }),
|
|
540
|
-
traceId: traceIdFromSeed('run-seed'),
|
|
541
|
-
})
|
|
542
|
-
);
|
|
543
|
-
|
|
544
|
-
// The SAME agent's overlay scope is still adopted.
|
|
545
|
-
await withLangfuseRuntimeScope(
|
|
546
|
-
{
|
|
547
|
-
langfuse: agentBLangfuse,
|
|
548
|
-
traceIdSeed: 'agent-b-seed',
|
|
549
|
-
runId: 'run-1',
|
|
550
|
-
agentId: 'agent-b',
|
|
551
|
-
},
|
|
552
|
-
() =>
|
|
553
|
-
streamHandler?.handleChainStart(
|
|
554
|
-
{ lc: 1, type: 'not_implemented', id: ['OwnAgentChain'] },
|
|
555
|
-
{ input: 'own agent' },
|
|
556
|
-
'lc-own-agent-run',
|
|
557
|
-
undefined,
|
|
558
|
-
undefined,
|
|
559
|
-
{ langgraph_node: 'agent=agent-b' }
|
|
560
|
-
)
|
|
561
|
-
);
|
|
562
|
-
|
|
563
|
-
expect(mockProcessorStarts).toContainEqual(
|
|
564
|
-
expect.objectContaining({
|
|
565
|
-
params: expect.objectContaining({ publicKey: 'pk-agent-b' }),
|
|
566
|
-
traceId: traceIdFromSeed('agent-b-seed'),
|
|
567
|
-
})
|
|
568
|
-
);
|
|
569
|
-
|
|
570
|
-
// Explicit `agentId` metadata (stamped by the graph's model path and
|
|
571
|
-
// ToolNode) beats node-name parsing: agent `research`'s inner node is
|
|
572
|
-
// named `agent=research`, indistinguishable by name from a sibling
|
|
573
|
-
// literally named `agent=research` — the explicit identity disambiguates.
|
|
574
|
-
await withLangfuseRuntimeScope(
|
|
575
|
-
{
|
|
576
|
-
langfuse: agentBLangfuse,
|
|
577
|
-
traceIdSeed: 'prefixed-sibling-seed',
|
|
578
|
-
runId: 'run-1',
|
|
579
|
-
agentId: 'agent=research',
|
|
580
|
-
},
|
|
581
|
-
() =>
|
|
582
|
-
streamHandler?.handleChainStart(
|
|
583
|
-
{ lc: 1, type: 'not_implemented', id: ['AmbiguousNodeChain'] },
|
|
584
|
-
{ input: 'ambiguous node' },
|
|
585
|
-
'lc-ambiguous-node-run',
|
|
586
|
-
undefined,
|
|
587
|
-
undefined,
|
|
588
|
-
{ langgraph_node: 'agent=research', agentId: 'research' }
|
|
589
|
-
)
|
|
590
|
-
);
|
|
591
|
-
|
|
592
|
-
expect(mockProcessorStarts).toContainEqual(
|
|
593
|
-
expect.objectContaining({
|
|
594
|
-
params: expect.objectContaining({ publicKey: 'pk-run' }),
|
|
595
|
-
traceId: traceIdFromSeed('run-seed'),
|
|
596
|
-
})
|
|
597
|
-
);
|
|
598
|
-
|
|
599
|
-
// An agent id that itself begins with an internal node prefix is carried
|
|
600
|
-
// VERBATIM by its outer workflow node — still recognized as its own scope.
|
|
601
|
-
await withLangfuseRuntimeScope(
|
|
602
|
-
{
|
|
603
|
-
langfuse: agentBLangfuse,
|
|
604
|
-
traceIdSeed: 'prefixed-agent-seed',
|
|
605
|
-
runId: 'run-1',
|
|
606
|
-
agentId: 'agent=research',
|
|
607
|
-
},
|
|
608
|
-
() =>
|
|
609
|
-
streamHandler?.handleChainStart(
|
|
610
|
-
{ lc: 1, type: 'not_implemented', id: ['PrefixedAgentChain'] },
|
|
611
|
-
{ input: 'prefixed agent' },
|
|
612
|
-
'lc-prefixed-agent-run',
|
|
613
|
-
undefined,
|
|
614
|
-
undefined,
|
|
615
|
-
{ langgraph_node: 'agent=research' }
|
|
616
|
-
)
|
|
617
|
-
);
|
|
618
|
-
|
|
619
|
-
expect(mockProcessorStarts).toContainEqual(
|
|
620
|
-
expect.objectContaining({
|
|
621
|
-
params: expect.objectContaining({ publicKey: 'pk-agent-b' }),
|
|
622
|
-
traceId: traceIdFromSeed('prefixed-agent-seed'),
|
|
623
|
-
})
|
|
624
|
-
);
|
|
625
|
-
});
|
|
626
|
-
|
|
627
|
-
it('rejects a sibling agent overlay for tool callbacks', async () => {
|
|
628
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
629
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
630
|
-
const { withLangfuseRuntimeScope } = await import('@/langfuseRuntimeScope');
|
|
631
|
-
const runLangfuse = {
|
|
632
|
-
publicKey: 'pk-run',
|
|
633
|
-
secretKey: 'sk-run',
|
|
634
|
-
baseUrl: 'https://langfuse.run',
|
|
635
|
-
deterministicTraceId: true,
|
|
636
|
-
};
|
|
637
|
-
const agentBLangfuse = {
|
|
638
|
-
publicKey: 'pk-agent-b',
|
|
639
|
-
secretKey: 'sk-agent-b',
|
|
640
|
-
baseUrl: 'https://langfuse.agent-b',
|
|
641
|
-
deterministicTraceId: true,
|
|
642
|
-
};
|
|
643
|
-
initializeLangfuseTracing(runLangfuse);
|
|
644
|
-
initializeLangfuseTracing(agentBLangfuse);
|
|
645
|
-
const streamHandler = createLangfuseHandler({
|
|
646
|
-
langfuse: runLangfuse,
|
|
647
|
-
traceIdSeed: 'run-seed',
|
|
648
|
-
runId: 'run-1',
|
|
649
|
-
});
|
|
650
|
-
|
|
651
|
-
// Tool supersteps stamp their scope with the executing agent; a tool
|
|
652
|
-
// callback reporting a different agent via `tools=<id>` metadata must
|
|
653
|
-
// not adopt the sibling's overlay.
|
|
654
|
-
await withLangfuseRuntimeScope(
|
|
655
|
-
{
|
|
656
|
-
langfuse: agentBLangfuse,
|
|
657
|
-
traceIdSeed: 'agent-b-seed',
|
|
658
|
-
runId: 'run-1',
|
|
659
|
-
agentId: 'agent-b',
|
|
660
|
-
},
|
|
661
|
-
() =>
|
|
662
|
-
streamHandler?.handleToolStart(
|
|
663
|
-
{ lc: 1, type: 'not_implemented', id: ['SiblingTool'] },
|
|
664
|
-
'sibling tool input',
|
|
665
|
-
'lc-sibling-tool-run',
|
|
666
|
-
undefined,
|
|
667
|
-
undefined,
|
|
668
|
-
{ langgraph_node: 'tools=agent-a' }
|
|
669
|
-
)
|
|
670
|
-
);
|
|
671
|
-
|
|
672
|
-
expect(mockProcessorStarts).toContainEqual(
|
|
673
|
-
expect.objectContaining({
|
|
674
|
-
params: expect.objectContaining({ publicKey: 'pk-run' }),
|
|
675
|
-
traceId: traceIdFromSeed('run-seed'),
|
|
676
|
-
})
|
|
677
|
-
);
|
|
678
|
-
expect(
|
|
679
|
-
mockProcessorStarts.filter(
|
|
680
|
-
(record) =>
|
|
681
|
-
(record.params as { publicKey?: string }).publicKey === 'pk-agent-b'
|
|
682
|
-
)
|
|
683
|
-
).toHaveLength(0);
|
|
684
|
-
});
|
|
685
|
-
|
|
686
|
-
it('replaces foreign propagated identity attributes with its own', async () => {
|
|
687
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
688
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
689
|
-
const { withLangfuseRuntimeScope } = await import('@/langfuseRuntimeScope');
|
|
690
|
-
const { propagateAttributes } = await import('@langfuse/tracing');
|
|
691
|
-
const { getPropagatedAttributesFromContext } = await import(
|
|
692
|
-
'@langfuse/core'
|
|
693
|
-
);
|
|
694
|
-
const tenantA = {
|
|
695
|
-
publicKey: 'pk-tenant-a',
|
|
696
|
-
secretKey: 'sk-tenant-a',
|
|
697
|
-
baseUrl: 'https://langfuse.tenant-a',
|
|
698
|
-
};
|
|
699
|
-
const tenantB = {
|
|
700
|
-
publicKey: 'pk-tenant-b',
|
|
701
|
-
secretKey: 'sk-tenant-b',
|
|
702
|
-
baseUrl: 'https://langfuse.tenant-b',
|
|
703
|
-
};
|
|
704
|
-
initializeLangfuseTracing(tenantA);
|
|
705
|
-
initializeLangfuseTracing(tenantB);
|
|
706
|
-
const handlerB = createLangfuseHandler({
|
|
707
|
-
langfuse: tenantB,
|
|
708
|
-
userId: 'user-b',
|
|
709
|
-
runId: 'run-b',
|
|
710
|
-
});
|
|
711
|
-
|
|
712
|
-
let observedAttributes: Record<string, unknown> | undefined;
|
|
713
|
-
mockStartActiveSpan.mockImplementationOnce(
|
|
714
|
-
(_name, _options, activeContext, callback) => {
|
|
715
|
-
observedAttributes = getPropagatedAttributesFromContext(
|
|
716
|
-
otelContext.active()
|
|
717
|
-
) as Record<string, unknown>;
|
|
718
|
-
return callback(
|
|
719
|
-
createMockSpan(otelTrace.getSpanContext(activeContext)?.traceId)
|
|
720
|
-
);
|
|
721
|
-
}
|
|
722
|
-
);
|
|
723
|
-
|
|
724
|
-
// Run A's propagated identity (user, session) is ambient; B's spans must
|
|
725
|
-
// carry B's identity — and NOT retain A's session where B has none.
|
|
726
|
-
await propagateAttributes(
|
|
727
|
-
{ userId: 'user-a', sessionId: 'session-a' },
|
|
728
|
-
async () =>
|
|
729
|
-
withLangfuseRuntimeScope({ langfuse: tenantA, runId: 'run-a' }, () =>
|
|
730
|
-
handlerB?.handleChainStart(
|
|
731
|
-
{ lc: 1, type: 'not_implemented', id: ['IdentityChain'] },
|
|
732
|
-
{ input: 'identity' },
|
|
733
|
-
'lc-identity-run'
|
|
734
|
-
)
|
|
735
|
-
)
|
|
736
|
-
);
|
|
737
|
-
|
|
738
|
-
expect(observedAttributes?.['user.id']).toBe('user-b');
|
|
739
|
-
expect(observedAttributes?.['session.id']).toBeUndefined();
|
|
740
|
-
});
|
|
741
|
-
|
|
742
|
-
it('clears a foreign scope for env-credential runs instead of inheriting it', async () => {
|
|
743
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
744
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
745
|
-
const { withLangfuseRuntimeScope } = await import('@/langfuseRuntimeScope');
|
|
746
|
-
process.env.LANGFUSE_PUBLIC_KEY = 'pk-env';
|
|
747
|
-
process.env.LANGFUSE_SECRET_KEY = 'sk-env';
|
|
748
|
-
const tenantA = {
|
|
749
|
-
publicKey: 'pk-tenant-a',
|
|
750
|
-
secretKey: 'sk-tenant-a',
|
|
751
|
-
baseUrl: 'https://langfuse.tenant-a',
|
|
752
|
-
deterministicTraceId: true,
|
|
753
|
-
};
|
|
754
|
-
initializeLangfuseTracing(tenantA);
|
|
755
|
-
initializeLangfuseTracing();
|
|
756
|
-
// Run B has no explicit config or seed of its own — it relies on env
|
|
757
|
-
// credentials. Rejecting a foreign scope must CLEAR the foreign values
|
|
758
|
-
// rather than let merge inheritance re-adopt them through `undefined`.
|
|
759
|
-
const handlerB = createLangfuseHandler({ runId: 'run-b' });
|
|
760
|
-
|
|
761
|
-
await withLangfuseRuntimeScope(
|
|
762
|
-
{ langfuse: tenantA, traceIdSeed: 'run-a', runId: 'run-a' },
|
|
763
|
-
() =>
|
|
764
|
-
handlerB?.handleChainStart(
|
|
765
|
-
{ lc: 1, type: 'not_implemented', id: ['EnvCredentialChain'] },
|
|
766
|
-
{ input: 'env credentials' },
|
|
767
|
-
'lc-env-run'
|
|
768
|
-
)
|
|
769
|
-
);
|
|
770
|
-
|
|
771
|
-
expect(mockProcessorStarts).toContainEqual(
|
|
772
|
-
expect.objectContaining({
|
|
773
|
-
params: expect.objectContaining({
|
|
774
|
-
publicKey: 'pk-env',
|
|
775
|
-
secretKey: 'sk-env',
|
|
776
|
-
}),
|
|
777
|
-
})
|
|
778
|
-
);
|
|
779
|
-
expect(
|
|
780
|
-
mockProcessorStarts.filter(
|
|
781
|
-
(record) =>
|
|
782
|
-
(record.params as { publicKey?: string }).publicKey ===
|
|
783
|
-
'pk-tenant-a' || record.traceId === traceIdFromSeed('run-a')
|
|
784
|
-
)
|
|
785
|
-
).toHaveLength(0);
|
|
786
|
-
});
|
|
787
|
-
|
|
788
|
-
it('applies its own tool-output policy inside a foreign run scope', async () => {
|
|
789
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
790
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
791
|
-
const { withLangfuseRuntimeScope } = await import('@/langfuseRuntimeScope');
|
|
792
|
-
const { resolveToolOutputTracingConfig } = await import('@/langfuseConfig');
|
|
793
|
-
const { getLangfuseRuntimeToolOutputTracingConfig } = await import(
|
|
794
|
-
'@/langfuseRuntimeContext'
|
|
795
|
-
);
|
|
796
|
-
const tenantA = {
|
|
797
|
-
publicKey: 'pk-tenant-a',
|
|
798
|
-
secretKey: 'sk-tenant-a',
|
|
799
|
-
baseUrl: 'https://langfuse.tenant-a',
|
|
800
|
-
toolOutputTracing: { enabled: true },
|
|
801
|
-
};
|
|
802
|
-
const tenantB = {
|
|
803
|
-
publicKey: 'pk-tenant-b',
|
|
804
|
-
secretKey: 'sk-tenant-b',
|
|
805
|
-
baseUrl: 'https://langfuse.tenant-b',
|
|
806
|
-
toolOutputTracing: { enabled: false },
|
|
807
|
-
};
|
|
808
|
-
initializeLangfuseTracing(tenantA);
|
|
809
|
-
initializeLangfuseTracing(tenantB);
|
|
810
|
-
const handlerB = createLangfuseHandler({
|
|
811
|
-
langfuse: tenantB,
|
|
812
|
-
runId: 'run-b',
|
|
813
|
-
});
|
|
814
|
-
|
|
815
|
-
let observedPolicy: { enabled: boolean } | undefined;
|
|
816
|
-
mockStartActiveSpan.mockImplementationOnce(
|
|
817
|
-
(_name, _options, activeContext, callback) => {
|
|
818
|
-
observedPolicy = getLangfuseRuntimeToolOutputTracingConfig();
|
|
819
|
-
return callback(
|
|
820
|
-
createMockSpan(otelTrace.getSpanContext(activeContext)?.traceId)
|
|
821
|
-
);
|
|
822
|
-
}
|
|
823
|
-
);
|
|
824
|
-
|
|
825
|
-
// Tenant A permits tool output; tenant B redacts. B's callback running
|
|
826
|
-
// inside A's scope must not inherit A's permissive policy.
|
|
827
|
-
await withLangfuseRuntimeScope(
|
|
828
|
-
{
|
|
829
|
-
langfuse: tenantA,
|
|
830
|
-
runId: 'run-a',
|
|
831
|
-
toolOutputTracing: resolveToolOutputTracingConfig(tenantA),
|
|
832
|
-
},
|
|
833
|
-
() =>
|
|
834
|
-
handlerB?.handleToolStart(
|
|
835
|
-
{ lc: 1, type: 'not_implemented', id: ['SensitiveTool'] },
|
|
836
|
-
'sensitive input',
|
|
837
|
-
'lc-tool-run'
|
|
838
|
-
)
|
|
839
|
-
);
|
|
840
|
-
|
|
841
|
-
expect(observedPolicy?.enabled).toBe(false);
|
|
842
|
-
});
|
|
843
|
-
|
|
844
|
-
it('attaches configured trace attributes to Langfuse callback spans', async () => {
|
|
845
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
846
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
847
|
-
const langfuse = {
|
|
848
|
-
publicKey: 'pk-tenant-a',
|
|
849
|
-
secretKey: 'sk-tenant-a',
|
|
850
|
-
baseUrl: 'https://langfuse.proxy',
|
|
851
|
-
librechatTraceAttributes: {
|
|
852
|
-
'librechat.langfuse.tenant_export.enabled': 'true',
|
|
853
|
-
'librechat.langfuse.destination': 'eu',
|
|
854
|
-
ignored: '',
|
|
855
|
-
},
|
|
856
|
-
};
|
|
857
|
-
initializeLangfuseTracing(langfuse);
|
|
858
|
-
const handler = createLangfuseHandler({ langfuse });
|
|
859
|
-
|
|
860
|
-
await handler?.handleChainStart(
|
|
861
|
-
{ lc: 1, type: 'not_implemented', id: ['TenantAChain'] },
|
|
862
|
-
{ input: 'tenant a' },
|
|
863
|
-
'lc-run-a'
|
|
864
|
-
);
|
|
865
|
-
|
|
866
|
-
expect(mockSpanAttributeSets).toContainEqual({
|
|
867
|
-
'librechat.langfuse.tenant_export.enabled': 'true',
|
|
868
|
-
'librechat.langfuse.destination': 'eu',
|
|
869
|
-
});
|
|
870
|
-
});
|
|
871
|
-
|
|
872
|
-
it('ends nested ParentCommand control flow without reporting an error', async () => {
|
|
873
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
874
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
875
|
-
const langfuse = {
|
|
876
|
-
publicKey: 'pk-test',
|
|
877
|
-
secretKey: 'sk-test',
|
|
878
|
-
};
|
|
879
|
-
initializeLangfuseTracing(langfuse);
|
|
880
|
-
const handler = createLangfuseHandler({ langfuse });
|
|
881
|
-
const runId = 'test-langfuse-parent-command';
|
|
882
|
-
|
|
883
|
-
await handler?.handleChainStart(
|
|
884
|
-
{ lc: 1, type: 'not_implemented', id: ['HandoffChain'] },
|
|
885
|
-
{ input: 'handoff' },
|
|
886
|
-
runId,
|
|
887
|
-
'parent-run'
|
|
888
|
-
);
|
|
889
|
-
await handler?.handleChainError(
|
|
890
|
-
new ParentCommand(
|
|
891
|
-
new Command({ graph: 'source:graph', goto: 'destination' })
|
|
892
|
-
),
|
|
893
|
-
runId,
|
|
894
|
-
'parent-run'
|
|
895
|
-
);
|
|
896
|
-
|
|
897
|
-
expect(mockSpanAttributeSets).not.toContainEqual(
|
|
898
|
-
expect.objectContaining({
|
|
899
|
-
[LangfuseOtelSpanAttributes.OBSERVATION_LEVEL]: 'ERROR',
|
|
900
|
-
})
|
|
901
|
-
);
|
|
902
|
-
expect(mockSpanAttributeSets).toContainEqual(
|
|
903
|
-
expect.objectContaining({
|
|
904
|
-
[LangfuseOtelSpanAttributes.OBSERVATION_OUTPUT]: JSON.stringify({
|
|
905
|
-
controlFlow: 'ParentCommand',
|
|
906
|
-
}),
|
|
907
|
-
})
|
|
908
|
-
);
|
|
909
|
-
});
|
|
910
|
-
|
|
911
|
-
it('ends nested GraphInterrupt control flow without reporting an error', async () => {
|
|
912
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
913
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
914
|
-
const langfuse = {
|
|
915
|
-
publicKey: 'pk-graph-interrupt',
|
|
916
|
-
secretKey: 'sk-graph-interrupt',
|
|
917
|
-
};
|
|
918
|
-
initializeLangfuseTracing(langfuse);
|
|
919
|
-
const handler = createLangfuseHandler({ langfuse });
|
|
920
|
-
const runId = 'test-langfuse-graph-interrupt';
|
|
921
|
-
const sensitiveQuestion = 'sensitive question payload';
|
|
922
|
-
|
|
923
|
-
await handler?.handleChainStart(
|
|
924
|
-
{ lc: 1, type: 'not_implemented', id: ['InterruptedChain'] },
|
|
925
|
-
{ input: 'ask' },
|
|
926
|
-
runId,
|
|
927
|
-
'parent-run'
|
|
928
|
-
);
|
|
929
|
-
await handler?.handleChainError(
|
|
930
|
-
new GraphInterrupt([
|
|
931
|
-
{
|
|
932
|
-
value: {
|
|
933
|
-
type: 'ask_user_question',
|
|
934
|
-
question: sensitiveQuestion,
|
|
935
|
-
},
|
|
936
|
-
},
|
|
937
|
-
]),
|
|
938
|
-
runId,
|
|
939
|
-
'parent-run'
|
|
940
|
-
);
|
|
941
|
-
|
|
942
|
-
expect(mockSpanAttributeSets).not.toContainEqual(
|
|
943
|
-
expect.objectContaining({
|
|
944
|
-
[LangfuseOtelSpanAttributes.OBSERVATION_LEVEL]: 'ERROR',
|
|
945
|
-
})
|
|
946
|
-
);
|
|
947
|
-
expect(mockSpanAttributeSets).toContainEqual(
|
|
948
|
-
expect.objectContaining({
|
|
949
|
-
[LangfuseOtelSpanAttributes.OBSERVATION_OUTPUT]: JSON.stringify({
|
|
950
|
-
controlFlow: 'GraphInterrupt',
|
|
951
|
-
}),
|
|
952
|
-
})
|
|
953
|
-
);
|
|
954
|
-
expect(JSON.stringify(mockSpanAttributeSets)).not.toContain(
|
|
955
|
-
sensitiveQuestion
|
|
956
|
-
);
|
|
957
|
-
});
|
|
958
|
-
|
|
959
|
-
it('ends nested GraphInterrupt tool control flow without reporting an error', async () => {
|
|
960
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
961
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
962
|
-
const langfuse = {
|
|
963
|
-
publicKey: 'pk-tool-graph-interrupt',
|
|
964
|
-
secretKey: 'sk-tool-graph-interrupt',
|
|
965
|
-
};
|
|
966
|
-
initializeLangfuseTracing(langfuse);
|
|
967
|
-
const handler = createLangfuseHandler({ langfuse });
|
|
968
|
-
const runId = 'test-langfuse-tool-graph-interrupt';
|
|
969
|
-
const sensitiveQuestion = 'sensitive tool question payload';
|
|
970
|
-
|
|
971
|
-
await handler?.handleToolStart(
|
|
972
|
-
{ lc: 1, type: 'not_implemented', id: ['AskUserQuestion'] },
|
|
973
|
-
'{}',
|
|
974
|
-
runId,
|
|
975
|
-
'parent-run'
|
|
976
|
-
);
|
|
977
|
-
await handler?.handleToolError(
|
|
978
|
-
new GraphInterrupt([
|
|
979
|
-
{
|
|
980
|
-
value: {
|
|
981
|
-
type: 'ask_user_question',
|
|
982
|
-
question: sensitiveQuestion,
|
|
983
|
-
},
|
|
984
|
-
},
|
|
985
|
-
]),
|
|
986
|
-
runId,
|
|
987
|
-
'parent-run'
|
|
988
|
-
);
|
|
989
|
-
|
|
990
|
-
expect(mockSpanAttributeSets).not.toContainEqual(
|
|
991
|
-
expect.objectContaining({
|
|
992
|
-
[LangfuseOtelSpanAttributes.OBSERVATION_LEVEL]: 'ERROR',
|
|
993
|
-
})
|
|
994
|
-
);
|
|
995
|
-
expect(mockSpanAttributeSets).toContainEqual(
|
|
996
|
-
expect.objectContaining({
|
|
997
|
-
[LangfuseOtelSpanAttributes.OBSERVATION_OUTPUT]: JSON.stringify({
|
|
998
|
-
controlFlow: 'GraphInterrupt',
|
|
999
|
-
}),
|
|
1000
|
-
})
|
|
1001
|
-
);
|
|
1002
|
-
expect(JSON.stringify(mockSpanAttributeSets)).not.toContain(
|
|
1003
|
-
sensitiveQuestion
|
|
1004
|
-
);
|
|
1005
|
-
});
|
|
1006
|
-
|
|
1007
|
-
it('normalizes a real ask_user_question pause and preserves resume behavior', async () => {
|
|
1008
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
1009
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
1010
|
-
const langfuse = {
|
|
1011
|
-
publicKey: 'pk-ask-user-question',
|
|
1012
|
-
secretKey: 'sk-ask-user-question',
|
|
1013
|
-
};
|
|
1014
|
-
initializeLangfuseTracing(langfuse);
|
|
1015
|
-
const handler = createLangfuseHandler({ langfuse });
|
|
1016
|
-
expect(handler).toBeDefined();
|
|
1017
|
-
|
|
1018
|
-
const sensitiveQuestion = 'Should the workflow continue?';
|
|
1019
|
-
const askTool = tool(
|
|
1020
|
-
async () => {
|
|
1021
|
-
const { answer } = askUserQuestion({ question: sensitiveQuestion });
|
|
1022
|
-
return `answered: ${answer}`;
|
|
1023
|
-
},
|
|
1024
|
-
{
|
|
1025
|
-
name: 'ask_user_question',
|
|
1026
|
-
description: 'suspends to collect a human answer',
|
|
1027
|
-
schema: z.object({}).passthrough(),
|
|
1028
|
-
}
|
|
1029
|
-
);
|
|
1030
|
-
const toolNode = new ToolNode({
|
|
1031
|
-
tools: [askTool],
|
|
1032
|
-
eventDrivenMode: true,
|
|
1033
|
-
directToolNames: new Set(['ask_user_question']),
|
|
1034
|
-
interruptingToolNames: new Set(['ask_user_question']),
|
|
1035
|
-
});
|
|
1036
|
-
const graph = new StateGraph(MessagesAnnotation)
|
|
1037
|
-
.addNode('agent', () => ({
|
|
1038
|
-
messages: [
|
|
1039
|
-
new AIMessage({
|
|
1040
|
-
content: '',
|
|
1041
|
-
tool_calls: [
|
|
1042
|
-
{ id: 'ask-call', name: 'ask_user_question', args: {} },
|
|
1043
|
-
],
|
|
1044
|
-
}),
|
|
1045
|
-
],
|
|
1046
|
-
}))
|
|
1047
|
-
.addNode('tools', toolNode)
|
|
1048
|
-
.addEdge(START, 'agent')
|
|
1049
|
-
.addEdge('agent', 'tools')
|
|
1050
|
-
.addEdge('tools', END)
|
|
1051
|
-
.compile({ checkpointer: new MemorySaver() });
|
|
1052
|
-
const chainErrorSpy = jest.spyOn(handler!, 'handleChainError');
|
|
1053
|
-
const toolErrorSpy = jest.spyOn(handler!, 'handleToolError');
|
|
1054
|
-
const config = {
|
|
1055
|
-
callbacks: [handler!],
|
|
1056
|
-
configurable: { thread_id: 'ask-user-question-langfuse' },
|
|
1057
|
-
};
|
|
1058
|
-
|
|
1059
|
-
const first = await graph.invoke({ messages: [] }, config);
|
|
1060
|
-
|
|
1061
|
-
expect(isInterrupted<t.HumanInterruptPayload>(first)).toBe(true);
|
|
1062
|
-
expect(
|
|
1063
|
-
(
|
|
1064
|
-
first as {
|
|
1065
|
-
__interrupt__?: Array<{
|
|
1066
|
-
value?: t.HumanInterruptPayload;
|
|
1067
|
-
}>;
|
|
1068
|
-
}
|
|
1069
|
-
).__interrupt__?.[0]?.value
|
|
1070
|
-
).toMatchObject({
|
|
1071
|
-
type: 'ask_user_question',
|
|
1072
|
-
question: { question: sensitiveQuestion },
|
|
1073
|
-
});
|
|
1074
|
-
expect(
|
|
1075
|
-
chainErrorSpy.mock.calls.some(
|
|
1076
|
-
([error, , parentRunId]) =>
|
|
1077
|
-
isGraphInterrupt(error) && parentRunId != null
|
|
1078
|
-
)
|
|
1079
|
-
).toBe(true);
|
|
1080
|
-
expect(
|
|
1081
|
-
toolErrorSpy.mock.calls.some(
|
|
1082
|
-
([error, , parentRunId]) =>
|
|
1083
|
-
isGraphInterrupt(error) && parentRunId != null
|
|
1084
|
-
)
|
|
1085
|
-
).toBe(true);
|
|
1086
|
-
const controlFlowOutputs = mockSpanAttributeSets.filter(
|
|
1087
|
-
(attributes) =>
|
|
1088
|
-
attributes[LangfuseOtelSpanAttributes.OBSERVATION_OUTPUT] ===
|
|
1089
|
-
JSON.stringify({ controlFlow: 'GraphInterrupt' })
|
|
1090
|
-
);
|
|
1091
|
-
expect(controlFlowOutputs.length).toBeGreaterThanOrEqual(2);
|
|
1092
|
-
expect(mockSpanAttributeSets).not.toContainEqual(
|
|
1093
|
-
expect.objectContaining({
|
|
1094
|
-
[LangfuseOtelSpanAttributes.OBSERVATION_LEVEL]: 'ERROR',
|
|
1095
|
-
})
|
|
1096
|
-
);
|
|
1097
|
-
expect(mockSpanAttributeSets).not.toContainEqual(
|
|
1098
|
-
expect.objectContaining({
|
|
1099
|
-
[LangfuseOtelSpanAttributes.OBSERVATION_STATUS_MESSAGE]:
|
|
1100
|
-
expect.stringContaining('GraphInterrupt'),
|
|
1101
|
-
})
|
|
1102
|
-
);
|
|
1103
|
-
expect(mockSpansEnded).toBe(mockSpansStarted);
|
|
1104
|
-
|
|
1105
|
-
const second = await graph.invoke(
|
|
1106
|
-
new Command({ resume: { answer: 'yes' } }),
|
|
1107
|
-
config
|
|
1108
|
-
);
|
|
1109
|
-
|
|
1110
|
-
expect(isInterrupted<t.HumanInterruptPayload>(second)).toBe(false);
|
|
1111
|
-
const messages = (second as { messages: ToolMessage[] }).messages;
|
|
1112
|
-
expect(
|
|
1113
|
-
messages.find(
|
|
1114
|
-
(message) =>
|
|
1115
|
-
message instanceof ToolMessage && message.name === 'ask_user_question'
|
|
1116
|
-
)?.content
|
|
1117
|
-
).toBe('answered: yes');
|
|
1118
|
-
expect(mockSpanAttributeSets).not.toContainEqual(
|
|
1119
|
-
expect.objectContaining({
|
|
1120
|
-
[LangfuseOtelSpanAttributes.OBSERVATION_LEVEL]: 'ERROR',
|
|
1121
|
-
})
|
|
1122
|
-
);
|
|
1123
|
-
expect(mockSpansEnded).toBe(mockSpansStarted);
|
|
1124
|
-
});
|
|
1125
|
-
|
|
1126
|
-
it('defensively reports a synthetic root GraphInterrupt as an error', async () => {
|
|
1127
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
1128
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
1129
|
-
const langfuse = {
|
|
1130
|
-
publicKey: 'pk-root-graph-interrupt',
|
|
1131
|
-
secretKey: 'sk-root-graph-interrupt',
|
|
1132
|
-
};
|
|
1133
|
-
initializeLangfuseTracing(langfuse);
|
|
1134
|
-
const handler = createLangfuseHandler({ langfuse });
|
|
1135
|
-
const runId = 'test-langfuse-root-graph-interrupt';
|
|
1136
|
-
|
|
1137
|
-
await handler?.handleChainStart(
|
|
1138
|
-
{ lc: 1, type: 'not_implemented', id: ['RootChain'] },
|
|
1139
|
-
{ input: 'root interrupt' },
|
|
1140
|
-
runId
|
|
1141
|
-
);
|
|
1142
|
-
await handler?.handleChainError(new GraphInterrupt(), runId);
|
|
1143
|
-
|
|
1144
|
-
expect(mockSpanAttributeSets).toContainEqual(
|
|
1145
|
-
expect.objectContaining({
|
|
1146
|
-
[LangfuseOtelSpanAttributes.OBSERVATION_LEVEL]: 'ERROR',
|
|
1147
|
-
})
|
|
1148
|
-
);
|
|
1149
|
-
});
|
|
1150
|
-
|
|
1151
|
-
it('normalizes nested NodeInterrupt control flow', async () => {
|
|
1152
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
1153
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
1154
|
-
const langfuse = {
|
|
1155
|
-
publicKey: 'pk-node-interrupt',
|
|
1156
|
-
secretKey: 'sk-node-interrupt',
|
|
1157
|
-
};
|
|
1158
|
-
initializeLangfuseTracing(langfuse);
|
|
1159
|
-
const handler = createLangfuseHandler({ langfuse });
|
|
1160
|
-
const runId = 'test-langfuse-node-interrupt';
|
|
1161
|
-
|
|
1162
|
-
await handler?.handleChainStart(
|
|
1163
|
-
{ lc: 1, type: 'not_implemented', id: ['InterruptedChain'] },
|
|
1164
|
-
{ input: 'ask' },
|
|
1165
|
-
runId,
|
|
1166
|
-
'parent-run'
|
|
1167
|
-
);
|
|
1168
|
-
await handler?.handleChainError(
|
|
1169
|
-
new NodeInterrupt('pause'),
|
|
1170
|
-
runId,
|
|
1171
|
-
'parent-run'
|
|
1172
|
-
);
|
|
1173
|
-
|
|
1174
|
-
expect(mockSpanAttributeSets).not.toContainEqual(
|
|
1175
|
-
expect.objectContaining({
|
|
1176
|
-
[LangfuseOtelSpanAttributes.OBSERVATION_LEVEL]: 'ERROR',
|
|
1177
|
-
})
|
|
1178
|
-
);
|
|
1179
|
-
expect(mockSpanAttributeSets).toContainEqual(
|
|
1180
|
-
expect.objectContaining({
|
|
1181
|
-
[LangfuseOtelSpanAttributes.OBSERVATION_OUTPUT]: JSON.stringify({
|
|
1182
|
-
controlFlow: 'GraphInterrupt',
|
|
1183
|
-
}),
|
|
1184
|
-
})
|
|
1185
|
-
);
|
|
1186
|
-
});
|
|
1187
|
-
|
|
1188
|
-
it('continues reporting genuine nested tool failures as errors', async () => {
|
|
1189
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
1190
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
1191
|
-
const langfuse = {
|
|
1192
|
-
publicKey: 'pk-genuine-tool-error',
|
|
1193
|
-
secretKey: 'sk-genuine-tool-error',
|
|
1194
|
-
};
|
|
1195
|
-
initializeLangfuseTracing(langfuse);
|
|
1196
|
-
const handler = createLangfuseHandler({ langfuse });
|
|
1197
|
-
const runId = 'test-langfuse-genuine-tool-error';
|
|
1198
|
-
|
|
1199
|
-
await handler?.handleToolStart(
|
|
1200
|
-
{ lc: 1, type: 'not_implemented', id: ['FailingTool'] },
|
|
1201
|
-
'{}',
|
|
1202
|
-
runId,
|
|
1203
|
-
'parent-run'
|
|
1204
|
-
);
|
|
1205
|
-
await handler?.handleToolError(new Error('tool boom'), runId, 'parent-run');
|
|
1206
|
-
|
|
1207
|
-
expect(mockSpanAttributeSets).toContainEqual(
|
|
1208
|
-
expect.objectContaining({
|
|
1209
|
-
[LangfuseOtelSpanAttributes.OBSERVATION_LEVEL]: 'ERROR',
|
|
1210
|
-
[LangfuseOtelSpanAttributes.OBSERVATION_STATUS_MESSAGE]:
|
|
1211
|
-
'Error: tool boom',
|
|
1212
|
-
})
|
|
1213
|
-
);
|
|
1214
|
-
});
|
|
1215
|
-
|
|
1216
|
-
it('reports a ParentCommand that escapes the root graph as an error', async () => {
|
|
1217
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
1218
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
1219
|
-
const langfuse = {
|
|
1220
|
-
publicKey: 'pk-root-parent-command',
|
|
1221
|
-
secretKey: 'sk-root-parent-command',
|
|
1222
|
-
};
|
|
1223
|
-
initializeLangfuseTracing(langfuse);
|
|
1224
|
-
const handler = createLangfuseHandler({ langfuse });
|
|
1225
|
-
const runId = 'test-langfuse-root-parent-command';
|
|
1226
|
-
|
|
1227
|
-
await handler?.handleChainStart(
|
|
1228
|
-
{ lc: 1, type: 'not_implemented', id: ['RootChain'] },
|
|
1229
|
-
{ input: 'root handoff' },
|
|
1230
|
-
runId
|
|
1231
|
-
);
|
|
1232
|
-
await handler?.handleChainError(
|
|
1233
|
-
new ParentCommand(
|
|
1234
|
-
new Command({ graph: Command.PARENT, goto: 'destination' })
|
|
1235
|
-
),
|
|
1236
|
-
runId
|
|
1237
|
-
);
|
|
1238
|
-
|
|
1239
|
-
expect(mockSpanAttributeSets).toContainEqual(
|
|
1240
|
-
expect.objectContaining({
|
|
1241
|
-
[LangfuseOtelSpanAttributes.OBSERVATION_LEVEL]: 'ERROR',
|
|
1242
|
-
[LangfuseOtelSpanAttributes.OBSERVATION_STATUS_MESSAGE]:
|
|
1243
|
-
'ParentCommand',
|
|
1244
|
-
})
|
|
1245
|
-
);
|
|
1246
|
-
});
|
|
1247
|
-
|
|
1248
|
-
it('continues reporting genuine nested chain failures as errors', async () => {
|
|
1249
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
1250
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
1251
|
-
const langfuse = {
|
|
1252
|
-
publicKey: 'pk-genuine-error',
|
|
1253
|
-
secretKey: 'sk-genuine-error',
|
|
1254
|
-
};
|
|
1255
|
-
initializeLangfuseTracing(langfuse);
|
|
1256
|
-
const handler = createLangfuseHandler({ langfuse });
|
|
1257
|
-
const runId = 'test-langfuse-genuine-error';
|
|
1258
|
-
|
|
1259
|
-
await handler?.handleChainStart(
|
|
1260
|
-
{ lc: 1, type: 'not_implemented', id: ['FailingChain'] },
|
|
1261
|
-
{ input: 'fail' },
|
|
1262
|
-
runId,
|
|
1263
|
-
'parent-run'
|
|
1264
|
-
);
|
|
1265
|
-
await handler?.handleChainError(new Error('boom'), runId, 'parent-run');
|
|
1266
|
-
|
|
1267
|
-
expect(mockSpanAttributeSets).toContainEqual(
|
|
1268
|
-
expect.objectContaining({
|
|
1269
|
-
[LangfuseOtelSpanAttributes.OBSERVATION_LEVEL]: 'ERROR',
|
|
1270
|
-
[LangfuseOtelSpanAttributes.OBSERVATION_STATUS_MESSAGE]: 'Error: boom',
|
|
1271
|
-
})
|
|
1272
|
-
);
|
|
1273
|
-
});
|
|
1274
|
-
|
|
1275
|
-
it('delegates null chain errors without throwing during classification', async () => {
|
|
1276
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
1277
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
1278
|
-
const langfuse = {
|
|
1279
|
-
publicKey: 'pk-null-error',
|
|
1280
|
-
secretKey: 'sk-null-error',
|
|
1281
|
-
};
|
|
1282
|
-
initializeLangfuseTracing(langfuse);
|
|
1283
|
-
const handler = createLangfuseHandler({ langfuse });
|
|
1284
|
-
const runId = 'test-langfuse-null-error';
|
|
1285
|
-
|
|
1286
|
-
await handler?.handleChainStart(
|
|
1287
|
-
{ lc: 1, type: 'not_implemented', id: ['NullErrorChain'] },
|
|
1288
|
-
{ input: 'fail' },
|
|
1289
|
-
runId,
|
|
1290
|
-
'parent-run'
|
|
1291
|
-
);
|
|
1292
|
-
|
|
1293
|
-
await expect(
|
|
1294
|
-
handler?.handleChainError(null, runId, 'parent-run')
|
|
1295
|
-
).resolves.toBeUndefined();
|
|
1296
|
-
});
|
|
1297
|
-
|
|
1298
|
-
it('delegates null tool errors without throwing during classification', async () => {
|
|
1299
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
1300
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
1301
|
-
const langfuse = {
|
|
1302
|
-
publicKey: 'pk-null-tool-error',
|
|
1303
|
-
secretKey: 'sk-null-tool-error',
|
|
1304
|
-
};
|
|
1305
|
-
initializeLangfuseTracing(langfuse);
|
|
1306
|
-
const handler = createLangfuseHandler({ langfuse });
|
|
1307
|
-
const runId = 'test-langfuse-null-tool-error';
|
|
1308
|
-
|
|
1309
|
-
await handler?.handleToolStart(
|
|
1310
|
-
{ lc: 1, type: 'not_implemented', id: ['NullErrorTool'] },
|
|
1311
|
-
'{}',
|
|
1312
|
-
runId,
|
|
1313
|
-
'parent-run'
|
|
1314
|
-
);
|
|
1315
|
-
|
|
1316
|
-
await expect(
|
|
1317
|
-
handler?.handleToolError(null, runId, 'parent-run')
|
|
1318
|
-
).resolves.toBeUndefined();
|
|
1319
|
-
});
|
|
1320
|
-
|
|
1321
|
-
it('traces a completed two-agent handoff without false error spans', async () => {
|
|
1322
|
-
const langfuse = {
|
|
1323
|
-
publicKey: 'pk-handoff',
|
|
1324
|
-
secretKey: 'sk-handoff',
|
|
1325
|
-
};
|
|
1326
|
-
const run = await Run.create<t.IState>({
|
|
1327
|
-
runId: 'test-langfuse-completed-handoff',
|
|
1328
|
-
graphConfig: {
|
|
1329
|
-
type: 'multi-agent',
|
|
1330
|
-
agents: [
|
|
1331
|
-
{
|
|
1332
|
-
agentId: 'agent_source',
|
|
1333
|
-
name: 'Source Agent',
|
|
1334
|
-
provider: Providers.OPENAI,
|
|
1335
|
-
clientOptions: { model: 'gpt-4' },
|
|
1336
|
-
instructions: 'Transfer to the destination agent.',
|
|
1337
|
-
tools: [],
|
|
1338
|
-
},
|
|
1339
|
-
{
|
|
1340
|
-
agentId: 'agent_destination',
|
|
1341
|
-
name: 'Destination Agent',
|
|
1342
|
-
provider: Providers.OPENAI,
|
|
1343
|
-
clientOptions: { model: 'gpt-4' },
|
|
1344
|
-
instructions: 'Complete the request.',
|
|
1345
|
-
tools: [],
|
|
1346
|
-
},
|
|
1347
|
-
],
|
|
1348
|
-
edges: [
|
|
1349
|
-
{
|
|
1350
|
-
from: 'agent_source',
|
|
1351
|
-
to: 'agent_destination',
|
|
1352
|
-
edgeType: 'handoff',
|
|
1353
|
-
},
|
|
1354
|
-
],
|
|
1355
|
-
},
|
|
1356
|
-
langfuse,
|
|
1357
|
-
skipCleanup: true,
|
|
1358
|
-
});
|
|
1359
|
-
run.Graph?.overrideTestModel(
|
|
1360
|
-
['Transferring to destination', 'Destination complete'],
|
|
1361
|
-
10,
|
|
1362
|
-
[
|
|
1363
|
-
{
|
|
1364
|
-
id: 'handoff-call',
|
|
1365
|
-
name: `${Constants.LC_TRANSFER_TO_}agent_destination`,
|
|
1366
|
-
args: {},
|
|
1367
|
-
} as ToolCall,
|
|
1368
|
-
]
|
|
1369
|
-
);
|
|
1370
|
-
|
|
1371
|
-
await run.processStream(
|
|
1372
|
-
{ messages: [new HumanMessage('Please hand this off')] },
|
|
1373
|
-
{
|
|
1374
|
-
configurable: {
|
|
1375
|
-
thread_id: 'test-langfuse-completed-handoff-thread',
|
|
1376
|
-
},
|
|
1377
|
-
version: 'v2',
|
|
1378
|
-
}
|
|
1379
|
-
);
|
|
1380
|
-
|
|
1381
|
-
expect(
|
|
1382
|
-
run
|
|
1383
|
-
.getRunMessages()
|
|
1384
|
-
?.some((message) => message.content === 'Destination complete')
|
|
1385
|
-
).toBe(true);
|
|
1386
|
-
expect(mockSpanAttributeSets).toContainEqual(
|
|
1387
|
-
expect.objectContaining({
|
|
1388
|
-
[LangfuseOtelSpanAttributes.OBSERVATION_OUTPUT]: JSON.stringify({
|
|
1389
|
-
controlFlow: 'ParentCommand',
|
|
1390
|
-
}),
|
|
1391
|
-
})
|
|
1392
|
-
);
|
|
1393
|
-
expect(mockSpanAttributeSets).not.toContainEqual(
|
|
1394
|
-
expect.objectContaining({
|
|
1395
|
-
[LangfuseOtelSpanAttributes.OBSERVATION_LEVEL]: 'ERROR',
|
|
1396
|
-
})
|
|
1397
|
-
);
|
|
1398
|
-
});
|
|
1399
|
-
|
|
1400
|
-
it('exports Bedrock prompt-cache usage buckets to Langfuse', async () => {
|
|
1401
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
1402
|
-
const { initializeLangfuseTracing } = await import('@/instrumentation');
|
|
1403
|
-
initializeLangfuseTracing({
|
|
1404
|
-
publicKey: 'pk-test',
|
|
1405
|
-
secretKey: 'sk-test',
|
|
1406
|
-
});
|
|
1407
|
-
const handler = createLangfuseHandler({
|
|
1408
|
-
langfuse: {
|
|
1409
|
-
publicKey: 'pk-test',
|
|
1410
|
-
secretKey: 'sk-test',
|
|
1411
|
-
},
|
|
1412
|
-
});
|
|
1413
|
-
const runId = 'test-langfuse-bedrock-cache-usage';
|
|
1414
|
-
|
|
1415
|
-
await handler?.handleChatModelStart(
|
|
1416
|
-
{
|
|
1417
|
-
lc: 1,
|
|
1418
|
-
type: 'constructor',
|
|
1419
|
-
id: ['LibreChatBedrockConverse'],
|
|
1420
|
-
kwargs: {},
|
|
1421
|
-
},
|
|
1422
|
-
[[new HumanMessage('hello')]],
|
|
1423
|
-
runId
|
|
1424
|
-
);
|
|
1425
|
-
|
|
1426
|
-
const generation = handleConverseStreamMetadata(
|
|
1427
|
-
{
|
|
1428
|
-
usage: {
|
|
1429
|
-
inputTokens: 13,
|
|
1430
|
-
outputTokens: 5,
|
|
1431
|
-
totalTokens: 20849,
|
|
1432
|
-
cacheReadInputTokens: 10831,
|
|
1433
|
-
cacheWriteInputTokens: 10000,
|
|
1434
|
-
},
|
|
1435
|
-
metrics: { latencyMs: 1000 },
|
|
1436
|
-
},
|
|
1437
|
-
{ streamUsage: true }
|
|
1438
|
-
);
|
|
1439
|
-
await handler?.handleLLMEnd({ generations: [[generation]] }, runId);
|
|
1440
|
-
|
|
1441
|
-
const usageDetails = mockSpanAttributeSets
|
|
1442
|
-
.map(
|
|
1443
|
-
(attributes) =>
|
|
1444
|
-
attributes[LangfuseOtelSpanAttributes.OBSERVATION_USAGE_DETAILS]
|
|
1445
|
-
)
|
|
1446
|
-
.find((value): value is string => typeof value === 'string');
|
|
1447
|
-
|
|
1448
|
-
expect(usageDetails).toBe(
|
|
1449
|
-
JSON.stringify({
|
|
1450
|
-
input: 13,
|
|
1451
|
-
output: 5,
|
|
1452
|
-
total: 20849,
|
|
1453
|
-
input_cache_read: 10831,
|
|
1454
|
-
input_cache_creation: 10000,
|
|
1455
|
-
})
|
|
1456
|
-
);
|
|
1457
|
-
});
|
|
1458
|
-
|
|
1459
|
-
it('uses deterministic trace ids when tracing is configured from env only', async () => {
|
|
1460
|
-
process.env.LANGFUSE_PUBLIC_KEY = 'pk-env';
|
|
1461
|
-
process.env.LANGFUSE_SECRET_KEY = 'sk-env';
|
|
1462
|
-
process.env.LANGFUSE_BASE_URL = 'https://langfuse.env';
|
|
1463
|
-
|
|
1464
|
-
const runId = 'test-langfuse-env-deterministic-run';
|
|
1465
|
-
const run = await Run.create<t.IState>({
|
|
1466
|
-
runId,
|
|
1467
|
-
graphConfig: {
|
|
1468
|
-
type: 'standard',
|
|
1469
|
-
agents: [
|
|
1470
|
-
{
|
|
1471
|
-
agentId: 'agent_abc123',
|
|
1472
|
-
name: 'DWAINE',
|
|
1473
|
-
provider: Providers.OPENAI,
|
|
1474
|
-
clientOptions: { model: 'gpt-4' },
|
|
1475
|
-
tools: [],
|
|
1476
|
-
},
|
|
1477
|
-
],
|
|
1478
|
-
},
|
|
1479
|
-
langfuse: {
|
|
1480
|
-
deterministicTraceId: true,
|
|
1481
|
-
metadata: { 'librechat.tenant.id': 'tenant-env' },
|
|
1482
|
-
tags: ['tenant:tenant-env'],
|
|
1483
|
-
},
|
|
1484
|
-
skipCleanup: true,
|
|
1485
|
-
});
|
|
1486
|
-
|
|
1487
|
-
run.Graph?.overrideTestModel(['hello']);
|
|
1488
|
-
|
|
1489
|
-
await run.processStream(
|
|
1490
|
-
{ messages: [new HumanMessage('hello')] },
|
|
1491
|
-
{
|
|
1492
|
-
configurable: { thread_id: 'thread-1', user_id: 'user-1' },
|
|
1493
|
-
version: 'v2' as const,
|
|
1494
|
-
}
|
|
1495
|
-
);
|
|
1496
|
-
|
|
1497
|
-
expect(mockProcessorStarts).toEqual(
|
|
1498
|
-
expect.arrayContaining([
|
|
1499
|
-
expect.objectContaining({
|
|
1500
|
-
params: expect.objectContaining({
|
|
1501
|
-
publicKey: 'pk-env',
|
|
1502
|
-
secretKey: 'sk-env',
|
|
1503
|
-
baseUrl: 'https://langfuse.env',
|
|
1504
|
-
}),
|
|
1505
|
-
traceId: traceIdFromSeed(runId),
|
|
1506
|
-
}),
|
|
1507
|
-
])
|
|
1508
|
-
);
|
|
1509
|
-
});
|
|
1510
|
-
|
|
1511
|
-
it('adds current agent metadata when a stream Langfuse callback already exists', async () => {
|
|
1512
|
-
const metadataSpy = jest.fn();
|
|
1513
|
-
const { createLangfuseHandler } = await import('@/langfuse');
|
|
1514
|
-
const streamHandler = createLangfuseHandler({
|
|
1515
|
-
langfuse: {
|
|
1516
|
-
publicKey: 'pk-run',
|
|
1517
|
-
secretKey: 'sk-run',
|
|
1518
|
-
baseUrl: 'https://langfuse.run',
|
|
1519
|
-
},
|
|
1520
|
-
});
|
|
1521
|
-
const run = await Run.create<t.IState>({
|
|
1522
|
-
runId: 'test-langfuse-agent-metadata-with-stream-callback',
|
|
1523
|
-
graphConfig: {
|
|
1524
|
-
type: 'multi-agent',
|
|
1525
|
-
agents: [
|
|
1526
|
-
{
|
|
1527
|
-
agentId: 'agent_default',
|
|
1528
|
-
name: 'Default Agent',
|
|
1529
|
-
provider: Providers.OPENAI,
|
|
1530
|
-
clientOptions: { model: 'gpt-4' },
|
|
1531
|
-
tools: [],
|
|
1532
|
-
},
|
|
1533
|
-
{
|
|
1534
|
-
agentId: 'agent_specialist',
|
|
1535
|
-
name: 'Specialist Agent',
|
|
1536
|
-
provider: Providers.OPENAI,
|
|
1537
|
-
clientOptions: { model: 'gpt-4' },
|
|
1538
|
-
tools: [],
|
|
1539
|
-
},
|
|
1540
|
-
],
|
|
1541
|
-
edges: [],
|
|
1542
|
-
},
|
|
1543
|
-
skipCleanup: true,
|
|
1544
|
-
});
|
|
1545
|
-
|
|
1546
|
-
run.Graph?.overrideTestModel(['hello from specialist']);
|
|
1547
|
-
const agentNode = run.Graph?.createAgentNode('agent_specialist');
|
|
1548
|
-
await agentNode?.invoke(
|
|
1549
|
-
{ messages: [new HumanMessage('hello')] },
|
|
1550
|
-
{
|
|
1551
|
-
callbacks: [
|
|
1552
|
-
...(streamHandler != null ? [streamHandler] : []),
|
|
1553
|
-
{
|
|
1554
|
-
handleChatModelStart: async (
|
|
1555
|
-
_llm: unknown,
|
|
1556
|
-
_messages: unknown,
|
|
1557
|
-
_runId: string,
|
|
1558
|
-
_parentRunId?: string,
|
|
1559
|
-
_extraParams?: unknown,
|
|
1560
|
-
_tags?: string[],
|
|
1561
|
-
metadata?: Record<string, unknown>
|
|
1562
|
-
): Promise<void> => {
|
|
1563
|
-
metadataSpy(metadata);
|
|
1564
|
-
},
|
|
1565
|
-
},
|
|
1566
|
-
],
|
|
1567
|
-
configurable: { thread_id: 'thread-1', user_id: 'user-1' },
|
|
1568
|
-
}
|
|
1569
|
-
);
|
|
1570
|
-
|
|
1571
|
-
expect(metadataSpy).toHaveBeenCalledWith(
|
|
1572
|
-
expect.objectContaining({
|
|
1573
|
-
agentId: 'agent_specialist',
|
|
1574
|
-
agentName: 'Specialist Agent',
|
|
1575
|
-
})
|
|
1576
|
-
);
|
|
1577
|
-
});
|
|
1578
|
-
});
|