@librechat/agents 4.2.11 → 4.2.13
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/graphs/Graph.cjs +15 -3
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/langfuse.cjs +63 -35
- package/dist/cjs/langfuse.cjs.map +1 -1
- package/dist/cjs/langfuseConfig.cjs +6 -0
- package/dist/cjs/langfuseConfig.cjs.map +1 -1
- package/dist/cjs/langfuseToolOutputTracing.cjs +1 -1
- package/dist/cjs/langfuseToolOutputTracing.cjs.map +1 -1
- package/dist/cjs/langfuseTraceShaping.cjs +18 -8
- package/dist/cjs/langfuseTraceShaping.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/index.cjs +4 -3
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/container.cjs +37 -0
- package/dist/cjs/llm/anthropic/utils/container.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +25 -23
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +15 -21
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/stream_events.cjs +16 -14
- package/dist/cjs/llm/anthropic/utils/stream_events.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/index.cjs +1 -1
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/toolCache.cjs +1 -1
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +19 -13
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/google/utils/common.cjs +59 -13
- package/dist/cjs/llm/google/utils/common.cjs.map +1 -1
- package/dist/cjs/llm/init.cjs +12 -2
- package/dist/cjs/llm/init.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +15 -2
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/responseToolArguments.cjs +62 -0
- package/dist/cjs/llm/openai/responseToolArguments.cjs.map +1 -0
- package/dist/cjs/llm/openrouter/index.cjs +11 -2
- package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
- package/dist/cjs/llm/openrouter/toolCache.cjs +1 -1
- package/dist/cjs/llm/prepareProviderRequest.cjs +35 -7
- package/dist/cjs/llm/prepareProviderRequest.cjs.map +1 -1
- package/dist/cjs/main.cjs +9 -3
- package/dist/cjs/messages/alternation.cjs +1 -1
- package/dist/cjs/messages/anthropicServerTools.cjs +20 -0
- package/dist/cjs/messages/anthropicServerTools.cjs.map +1 -0
- package/dist/cjs/messages/budget.cjs +1 -1
- package/dist/cjs/messages/cache.cjs +14 -1
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/messages/core.cjs +4 -3
- package/dist/cjs/messages/core.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +3 -3
- package/dist/cjs/messages/index.cjs +1 -1
- package/dist/cjs/messages/prune.cjs +1 -1
- package/dist/cjs/messages/recency.cjs +1 -1
- package/dist/cjs/messages/toolResultTypes.cjs +21 -45
- package/dist/cjs/messages/toolResultTypes.cjs.map +1 -1
- package/dist/cjs/protection/providerText.cjs +4 -0
- package/dist/cjs/protection/providerText.cjs.map +1 -1
- package/dist/cjs/protection/toolResult.cjs +119 -0
- package/dist/cjs/protection/toolResult.cjs.map +1 -0
- package/dist/cjs/run.cjs +31 -13
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/runtime/admission.cjs +1 -1
- package/dist/cjs/runtime/client.cjs +3 -0
- package/dist/cjs/runtime/client.cjs.map +1 -1
- package/dist/cjs/stream.cjs +2 -1
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +9 -4
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +1 -1
- package/dist/cjs/tools/ToolNode.cjs +47 -14
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/local/CompileCheckTool.cjs +1 -1
- package/dist/cjs/tools/local/LocalCodingTools.cjs +1 -1
- package/dist/cjs/tools/search/content.cjs +163 -42
- package/dist/cjs/tools/search/content.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +8 -0
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/utils/events.cjs +2 -2
- package/dist/cjs/utils/events.cjs.map +1 -1
- package/dist/cjs/utils/tokens.cjs +7 -2
- package/dist/cjs/utils/tokens.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +15 -3
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/langfuse.mjs +63 -35
- package/dist/esm/langfuse.mjs.map +1 -1
- package/dist/esm/langfuseConfig.mjs +6 -1
- package/dist/esm/langfuseConfig.mjs.map +1 -1
- package/dist/esm/langfuseToolOutputTracing.mjs +2 -2
- package/dist/esm/langfuseToolOutputTracing.mjs.map +1 -1
- package/dist/esm/langfuseTraceShaping.mjs +18 -9
- package/dist/esm/langfuseTraceShaping.mjs.map +1 -1
- package/dist/esm/llm/anthropic/index.mjs +4 -3
- package/dist/esm/llm/anthropic/index.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/container.mjs +37 -0
- package/dist/esm/llm/anthropic/utils/container.mjs.map +1 -0
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +25 -23
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs +15 -21
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/stream_events.mjs +16 -14
- package/dist/esm/llm/anthropic/utils/stream_events.mjs.map +1 -1
- package/dist/esm/llm/bedrock/index.mjs +2 -2
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/llm/bedrock/toolCache.mjs +1 -1
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs +19 -14
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/google/utils/common.mjs +59 -13
- package/dist/esm/llm/google/utils/common.mjs.map +1 -1
- package/dist/esm/llm/init.mjs +12 -2
- package/dist/esm/llm/init.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +16 -3
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/responseToolArguments.mjs +62 -0
- package/dist/esm/llm/openai/responseToolArguments.mjs.map +1 -0
- package/dist/esm/llm/openrouter/index.mjs +11 -2
- package/dist/esm/llm/openrouter/index.mjs.map +1 -1
- package/dist/esm/llm/openrouter/toolCache.mjs +1 -1
- package/dist/esm/llm/prepareProviderRequest.mjs +35 -7
- package/dist/esm/llm/prepareProviderRequest.mjs.map +1 -1
- package/dist/esm/main.mjs +5 -4
- package/dist/esm/messages/alternation.mjs +1 -1
- package/dist/esm/messages/anthropicServerTools.mjs +18 -0
- package/dist/esm/messages/anthropicServerTools.mjs.map +1 -0
- package/dist/esm/messages/budget.mjs +1 -1
- package/dist/esm/messages/cache.mjs +12 -2
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/core.mjs +4 -3
- package/dist/esm/messages/core.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +3 -3
- package/dist/esm/messages/index.mjs +1 -1
- package/dist/esm/messages/prune.mjs +1 -1
- package/dist/esm/messages/recency.mjs +1 -1
- package/dist/esm/messages/toolResultTypes.mjs +21 -45
- package/dist/esm/messages/toolResultTypes.mjs.map +1 -1
- package/dist/esm/protection/providerText.mjs +4 -1
- package/dist/esm/protection/providerText.mjs.map +1 -1
- package/dist/esm/protection/toolResult.mjs +114 -0
- package/dist/esm/protection/toolResult.mjs.map +1 -0
- package/dist/esm/run.mjs +32 -14
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/runtime/admission.mjs +1 -1
- package/dist/esm/runtime/client.mjs +3 -0
- package/dist/esm/runtime/client.mjs.map +1 -1
- package/dist/esm/stream.mjs +2 -1
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +9 -4
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +1 -1
- package/dist/esm/tools/ToolNode.mjs +47 -14
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/local/CompileCheckTool.mjs +1 -1
- package/dist/esm/tools/local/LocalCodingTools.mjs +1 -1
- package/dist/esm/tools/search/content.mjs +163 -42
- package/dist/esm/tools/search/content.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +8 -0
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/utils/events.mjs +2 -2
- package/dist/esm/utils/events.mjs.map +1 -1
- package/dist/esm/utils/tokens.mjs +7 -2
- package/dist/esm/utils/tokens.mjs.map +1 -1
- package/dist/types/common/index.d.ts +2 -2
- package/dist/types/decisions/breaker.d.ts +2 -2
- package/dist/types/decisions/core.d.ts +13 -13
- package/dist/types/decisions/dialect.d.ts +1 -1
- package/dist/types/decisions/http.d.ts +2 -2
- package/dist/types/decisions/index.d.ts +5 -5
- package/dist/types/decisions/node.d.ts +2 -2
- package/dist/types/decisions/presets.d.ts +2 -2
- package/dist/types/decisions/probe.d.ts +1 -1
- package/dist/types/decisions/questions.d.ts +1 -1
- package/dist/types/decisions/structuredChat.d.ts +2 -2
- package/dist/types/decisions/transport.d.ts +1 -1
- package/dist/types/eventActor/EventActorExecutor.d.ts +1 -1
- package/dist/types/eventActor/index.d.ts +2 -2
- package/dist/types/graphs/Graph.d.ts +6 -2
- package/dist/types/graphs/MultiAgentGraph.d.ts +1 -1
- package/dist/types/graphs/applyGraphRuntimeConfig.d.ts +1 -1
- package/dist/types/graphs/graphFactory.d.ts +1 -1
- package/dist/types/graphs/index.d.ts +5 -5
- package/dist/types/harness/fileBindings.d.ts +2 -2
- package/dist/types/harness/fileService.d.ts +2 -2
- package/dist/types/harness/fileStream.d.ts +1 -1
- package/dist/types/harness/index.d.ts +15 -15
- package/dist/types/harness/model.d.ts +1 -1
- package/dist/types/harness/modelService.d.ts +2 -2
- package/dist/types/harness/modelStreamCallbacks.d.ts +1 -1
- package/dist/types/harness/providerText.d.ts +1 -1
- package/dist/types/hitl/index.d.ts +3 -3
- package/dist/types/hooks/HookRegistry.d.ts +1 -1
- package/dist/types/hooks/createToolPolicyHook.d.ts +1 -1
- package/dist/types/hooks/createWorkspacePolicyHook.d.ts +1 -1
- package/dist/types/hooks/executeHooks.d.ts +2 -2
- package/dist/types/hooks/index.d.ts +11 -11
- package/dist/types/index.d.ts +62 -60
- package/dist/types/langchain/index.d.ts +8 -8
- package/dist/types/langfuse.d.ts +7 -4
- package/dist/types/langfuseConfig.d.ts +5 -0
- package/dist/types/langfuseTraceShaping.d.ts +5 -0
- package/dist/types/llm/anthropic/utils/container.d.ts +4 -0
- package/dist/types/llm/anthropic/utils/message_inputs.d.ts +1 -1
- package/dist/types/llm/anthropic/utils/message_outputs.d.ts +1 -1
- package/dist/types/llm/anthropic/utils/stream_events.d.ts +1 -1
- package/dist/types/llm/bedrock/index.d.ts +2 -3
- package/dist/types/llm/bedrock/utils/harmony.d.ts +1 -1
- package/dist/types/llm/bedrock/utils/index.d.ts +2 -2
- package/dist/types/llm/bedrock/utils/message_inputs.d.ts +3 -12
- package/dist/types/llm/bedrock/utils/message_outputs.d.ts +1 -1
- package/dist/types/llm/google/index.d.ts +2 -2
- package/dist/types/llm/google/utils/common.d.ts +1 -1
- package/dist/types/llm/google/utils/tools.d.ts +1 -1
- package/dist/types/llm/openai/index.d.ts +2 -1
- package/dist/types/llm/openai/responseToolArguments.d.ts +7 -0
- package/dist/types/llm/openrouter/index.d.ts +1 -0
- package/dist/types/llm/prepareProviderRequest.d.ts +4 -1
- package/dist/types/llm/providerRegistry.d.ts +1 -1
- package/dist/types/llm/providers.d.ts +1 -1
- package/dist/types/messages/anthropicServerTools.d.ts +13 -0
- package/dist/types/messages/cache.d.ts +13 -0
- package/dist/types/messages/contextPruning.d.ts +1 -1
- package/dist/types/messages/core.d.ts +4 -4
- package/dist/types/messages/format.d.ts +1 -1
- package/dist/types/messages/index.d.ts +21 -21
- package/dist/types/messages/prune.d.ts +1 -1
- package/dist/types/openai/index.d.ts +2 -2
- package/dist/types/openai/toolProjection.d.ts +1 -1
- package/dist/types/prompts/index.d.ts +2 -2
- package/dist/types/protection/providerText.d.ts +3 -1
- package/dist/types/protection/toolResult.d.ts +69 -0
- package/dist/types/provider-registration.d.ts +1 -1
- package/dist/types/rerank/bm25.d.ts +1 -1
- package/dist/types/rerank/core.d.ts +17 -17
- package/dist/types/rerank/crossEncoder.d.ts +3 -3
- package/dist/types/rerank/fallback.d.ts +1 -1
- package/dist/types/rerank/index.d.ts +2 -2
- package/dist/types/rerank/outcome.d.ts +2 -2
- package/dist/types/rerank/pin.d.ts +2 -2
- package/dist/types/rerank/search.d.ts +1 -1
- package/dist/types/rerank/systemone.d.ts +4 -4
- package/dist/types/rerank/types.d.ts +1 -1
- package/dist/types/run.d.ts +2 -0
- package/dist/types/runtime/admission.d.ts +1 -1
- package/dist/types/runtime/checkpoint.d.ts +1 -1
- package/dist/types/runtime/client.d.ts +2 -2
- package/dist/types/runtime/files.d.ts +4 -4
- package/dist/types/runtime/hostTools.d.ts +2 -2
- package/dist/types/runtime/index.d.ts +12 -12
- package/dist/types/runtime/model.d.ts +5 -5
- package/dist/types/runtime/policy.d.ts +3 -3
- package/dist/types/runtime/recovery/client.d.ts +3 -3
- package/dist/types/runtime/recovery/log.d.ts +2 -2
- package/dist/types/runtime/recovery/redis.d.ts +1 -1
- package/dist/types/runtime/recovery/server.d.ts +3 -3
- package/dist/types/runtime/resume.d.ts +1 -1
- package/dist/types/runtime/server.d.ts +3 -3
- package/dist/types/runtime/snapshot.d.ts +1 -1
- package/dist/types/runtime/types.d.ts +2 -2
- package/dist/types/session/AgentSession.d.ts +2 -2
- package/dist/types/session/JsonlSessionStore.d.ts +1 -1
- package/dist/types/session/deriveMessages.d.ts +1 -1
- package/dist/types/session/handlers.d.ts +1 -1
- package/dist/types/session/index.d.ts +7 -7
- package/dist/types/session/messageSerialization.d.ts +1 -1
- package/dist/types/session/sessionProjection.d.ts +3 -3
- package/dist/types/summarization/index.d.ts +2 -2
- package/dist/types/summarization/node.d.ts +2 -0
- package/dist/types/tools/BashProgrammaticToolCalling.d.ts +1 -1
- package/dist/types/tools/GitHubCompare.d.ts +6 -6
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +1 -1
- package/dist/types/tools/ReadFile.d.ts +6 -6
- package/dist/types/tools/SkillTool.d.ts +6 -6
- package/dist/types/tools/ToolNode.d.ts +5 -1
- package/dist/types/tools/cloudflare/index.d.ts +4 -4
- package/dist/types/tools/local/FileCheckpointer.d.ts +1 -1
- package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -1
- package/dist/types/tools/local/attachments.d.ts +1 -1
- package/dist/types/tools/local/index.d.ts +12 -12
- package/dist/types/tools/search/anthropic.d.ts +1 -1
- package/dist/types/tools/search/content.d.ts +38 -1
- package/dist/types/tools/search/crw-scraper.d.ts +1 -1
- package/dist/types/tools/search/crw-search.d.ts +1 -1
- package/dist/types/tools/search/firecrawl.d.ts +1 -1
- package/dist/types/tools/search/format.d.ts +1 -1
- package/dist/types/tools/search/highlights.d.ts +1 -1
- package/dist/types/tools/search/index.d.ts +3 -3
- package/dist/types/tools/search/keenable-scraper.d.ts +1 -1
- package/dist/types/tools/search/keenable-search.d.ts +1 -1
- package/dist/types/tools/search/metrics.d.ts +1 -1
- package/dist/types/tools/search/rerankers.d.ts +1 -1
- package/dist/types/tools/search/schema.d.ts +6 -6
- package/dist/types/tools/search/search.d.ts +1 -1
- package/dist/types/tools/search/serper-scraper.d.ts +1 -1
- package/dist/types/tools/search/tavily-scraper.d.ts +1 -1
- package/dist/types/tools/search/tavily-search.d.ts +1 -1
- package/dist/types/tools/search/tool.d.ts +3 -3
- package/dist/types/tools/search/types.d.ts +2 -2
- package/dist/types/tools/search/utils.d.ts +3 -3
- package/dist/types/tools/subagent/SubagentExecutionRegistry.d.ts +1 -1
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +9 -3
- package/dist/types/tools/subagent/diagnostics.d.ts +1 -1
- package/dist/types/tools/subagent/index.d.ts +7 -7
- package/dist/types/types/attachments.d.ts +25 -0
- package/dist/types/types/graph.d.ts +15 -0
- package/dist/types/types/index.d.ts +14 -13
- package/dist/types/types/llm.d.ts +2 -2
- package/dist/types/types/run.d.ts +7 -2
- package/dist/types/types/subagentTasks.d.ts +2 -2
- package/dist/types/types/tools.d.ts +6 -3
- package/dist/types/utils/events.d.ts +2 -1
- package/dist/types/utils/index.d.ts +10 -10
- package/dist/types/utils/tokens.d.ts +1 -0
- package/package.json +14 -12
- package/src/graphs/Graph.ts +32 -1
- package/src/index.ts +8 -0
- package/src/langfuse.ts +129 -41
- package/src/langfuseConfig.ts +14 -0
- package/src/langfuseToolOutputTracing.ts +5 -4
- package/src/langfuseTraceShaping.ts +49 -12
- package/src/llm/anthropic/index.ts +11 -3
- package/src/llm/anthropic/utils/container.ts +63 -0
- package/src/llm/anthropic/utils/message_inputs.ts +57 -51
- package/src/llm/anthropic/utils/message_outputs.ts +12 -39
- package/src/llm/anthropic/utils/stream_events.ts +17 -12
- package/src/llm/bedrock/index.ts +7 -5
- package/src/llm/bedrock/utils/message_inputs.ts +28 -35
- package/src/llm/google/utils/common.ts +88 -36
- package/src/llm/init.ts +35 -3
- package/src/llm/openai/index.ts +17 -2
- package/src/llm/openai/responseToolArguments.ts +104 -0
- package/src/llm/openrouter/index.ts +13 -0
- package/src/llm/prepareProviderRequest.ts +75 -13
- package/src/messages/anthropicServerTools.ts +24 -0
- package/src/messages/cache.ts +25 -5
- package/src/messages/core.ts +12 -11
- package/src/messages/toolResultTypes.ts +80 -88
- package/src/protection/providerText.ts +127 -40
- package/src/protection/toolResult.ts +272 -0
- package/src/run.ts +112 -47
- package/src/runtime/client.ts +7 -0
- package/src/stream.ts +7 -1
- package/src/summarization/node.ts +17 -4
- package/src/tools/ToolNode.ts +114 -18
- package/src/tools/search/content.ts +282 -62
- package/src/tools/subagent/SubagentExecutor.ts +12 -0
- package/src/types/attachments.ts +31 -0
- package/src/types/graph.ts +12 -0
- package/src/types/index.ts +1 -0
- package/src/types/run.ts +8 -1
- package/src/types/tools.ts +3 -0
- package/src/utils/events.ts +9 -2
- package/src/utils/tokens.ts +28 -2
package/src/langfuseConfig.ts
CHANGED
|
@@ -279,3 +279,17 @@ export function resolveLangfuseConfig(
|
|
|
279
279
|
...(toolOutputTracing != null ? { toolOutputTracing } : {}),
|
|
280
280
|
};
|
|
281
281
|
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Removes the agent's skills from the config of a run the agent does not
|
|
285
|
+
* drive, such as the title or a label. Those runs cannot load the skills.
|
|
286
|
+
*/
|
|
287
|
+
export function withoutSkillsAvailable(
|
|
288
|
+
langfuse?: t.LangfuseConfig
|
|
289
|
+
): t.LangfuseConfig | undefined {
|
|
290
|
+
if (langfuse?.skillsAvailable == null) {
|
|
291
|
+
return langfuse;
|
|
292
|
+
}
|
|
293
|
+
const { skillsAvailable: _skillsAvailable, ...auxiliary } = langfuse;
|
|
294
|
+
return auxiliary;
|
|
295
|
+
}
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
resolveToolOutputTracingConfig,
|
|
18
18
|
} from '@/langfuseConfig';
|
|
19
19
|
import {
|
|
20
|
+
getObservationMetadataAttribute,
|
|
20
21
|
shapeLangfuseSpan,
|
|
21
22
|
shouldDropLangfuseSpan,
|
|
22
23
|
} from '@/langfuseTraceShaping';
|
|
@@ -741,10 +742,10 @@ function classifyLangGraphToolNodeSpan(
|
|
|
741
742
|
return;
|
|
742
743
|
}
|
|
743
744
|
|
|
744
|
-
const langGraphNode =
|
|
745
|
-
attributes
|
|
746
|
-
|
|
747
|
-
|
|
745
|
+
const langGraphNode = getObservationMetadataAttribute(
|
|
746
|
+
attributes,
|
|
747
|
+
'langgraph_node'
|
|
748
|
+
);
|
|
748
749
|
if (
|
|
749
750
|
typeof langGraphNode === 'string' &&
|
|
750
751
|
langGraphNode.startsWith(LANGGRAPH_TOOL_NODE_PREFIX)
|
|
@@ -33,14 +33,34 @@ const EPHEMERAL_AGENT_SENDER_SEPARATOR = '___';
|
|
|
33
33
|
const EPHEMERAL_AGENT_INDEX_SEPARATOR = '____';
|
|
34
34
|
const DEPRECATED_TRACE_INPUT_ATTRIBUTE = 'langfuse.trace.input';
|
|
35
35
|
const DEPRECATED_TRACE_OUTPUT_ATTRIBUTE = 'langfuse.trace.output';
|
|
36
|
-
const OBSERVATION_METADATA_LANGGRAPH_NODE =
|
|
37
|
-
const OBSERVATION_METADATA_OPERATION =
|
|
36
|
+
const OBSERVATION_METADATA_LANGGRAPH_NODE = 'langgraph_node';
|
|
37
|
+
const OBSERVATION_METADATA_OPERATION = LANGFUSE_OPERATION_METADATA_KEY;
|
|
38
38
|
const OBSERVATION_METADATA_COMPACTION_SEMANTIC_INDEX_ENTRIES = `${LangfuseOtelSpanAttributes.OBSERVATION_METADATA}.compaction_semantic_index_entries`;
|
|
39
39
|
const COMPACTION_SEMANTIC_INDEX_OPEN = '<compaction-semantic-index>';
|
|
40
40
|
const COMPACTION_SEMANTIC_INDEX_CLOSE = '</compaction-semantic-index>';
|
|
41
41
|
const REDACTED_COMPACTION_SEMANTIC_INDEX =
|
|
42
42
|
'<compaction-semantic-index redacted="true" />\n\n';
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Returns an observation metadata value. `@langfuse/tracing` stores each
|
|
46
|
+
* metadata value on the span as JSON, strings included.
|
|
47
|
+
*/
|
|
48
|
+
export function getObservationMetadataAttribute(
|
|
49
|
+
attributes: Record<string, unknown>,
|
|
50
|
+
key: string
|
|
51
|
+
): unknown {
|
|
52
|
+
const value =
|
|
53
|
+
attributes[`${LangfuseOtelSpanAttributes.OBSERVATION_METADATA}.${key}`];
|
|
54
|
+
if (typeof value !== 'string') {
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
return JSON.parse(value);
|
|
59
|
+
} catch {
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
44
64
|
type MutableSpan = ReadableSpan & {
|
|
45
65
|
name: string;
|
|
46
66
|
attributes: Record<string, unknown>;
|
|
@@ -481,7 +501,10 @@ function isAgentModelCallSpan(span: MutableSpan): boolean {
|
|
|
481
501
|
) {
|
|
482
502
|
return false;
|
|
483
503
|
}
|
|
484
|
-
const node =
|
|
504
|
+
const node = getObservationMetadataAttribute(
|
|
505
|
+
span.attributes,
|
|
506
|
+
OBSERVATION_METADATA_LANGGRAPH_NODE
|
|
507
|
+
);
|
|
485
508
|
return (
|
|
486
509
|
typeof node === 'string' && node.startsWith(LANGGRAPH_AGENT_NODE_PREFIX)
|
|
487
510
|
);
|
|
@@ -501,22 +524,30 @@ function shapeActivityPhaseSpan(span: MutableSpan): void {
|
|
|
501
524
|
function shapeGenerationSpan(span: MutableSpan): void {
|
|
502
525
|
if (
|
|
503
526
|
hasTraceTag(span, ACTIVITY_LABEL_TRACE_TAG) &&
|
|
504
|
-
|
|
527
|
+
getObservationMetadataAttribute(
|
|
528
|
+
span.attributes,
|
|
529
|
+
OBSERVATION_METADATA_OPERATION
|
|
530
|
+
) === ACTIVITY_LABEL_RUN_NAME
|
|
505
531
|
) {
|
|
506
532
|
span.name = ACTIVITY_LABEL_RUN_NAME;
|
|
507
533
|
return;
|
|
508
534
|
}
|
|
509
535
|
if (
|
|
510
536
|
hasTraceTag(span, REASONING_LABEL_TRACE_TAG) &&
|
|
511
|
-
|
|
537
|
+
getObservationMetadataAttribute(
|
|
538
|
+
span.attributes,
|
|
539
|
+
OBSERVATION_METADATA_OPERATION
|
|
540
|
+
) === REASONING_LABEL_RUN_NAME
|
|
512
541
|
) {
|
|
513
542
|
span.name = REASONING_LABEL_RUN_NAME;
|
|
514
543
|
return;
|
|
515
544
|
}
|
|
516
545
|
if (
|
|
517
546
|
hasTraceTag(span, ACTIVITY_PHASE_TRACE_TAG) &&
|
|
518
|
-
|
|
519
|
-
|
|
547
|
+
getObservationMetadataAttribute(
|
|
548
|
+
span.attributes,
|
|
549
|
+
OBSERVATION_METADATA_OPERATION
|
|
550
|
+
) === ACTIVITY_PHASE_LABEL_RUN_NAME
|
|
520
551
|
) {
|
|
521
552
|
span.name = ACTIVITY_PHASE_LABEL_RUN_NAME;
|
|
522
553
|
return;
|
|
@@ -534,7 +565,10 @@ function isGraphSpan(span: MutableSpan): boolean {
|
|
|
534
565
|
}
|
|
535
566
|
return (
|
|
536
567
|
isRootSpan(span) ||
|
|
537
|
-
typeof
|
|
568
|
+
typeof getObservationMetadataAttribute(
|
|
569
|
+
span.attributes,
|
|
570
|
+
OBSERVATION_METADATA_LANGGRAPH_NODE
|
|
571
|
+
) === 'string' ||
|
|
538
572
|
hasTraceTag(span, AGENT_TRACE_TAG)
|
|
539
573
|
);
|
|
540
574
|
}
|
|
@@ -581,12 +615,15 @@ function isToolSpan(span: MutableSpan): boolean {
|
|
|
581
615
|
|
|
582
616
|
/**
|
|
583
617
|
* Whether the span is a LangGraph node execution whose node id is the span
|
|
584
|
-
* name — the shape of the outer workflow-agent node.
|
|
585
|
-
* flattens object metadata to per-key attributes with string values stored
|
|
586
|
-
* raw, so LangGraph's `langgraph_node` arrives directly comparable.
|
|
618
|
+
* name — the shape of the outer workflow-agent node.
|
|
587
619
|
*/
|
|
588
620
|
function isWorkflowNodeSpan(span: MutableSpan): boolean {
|
|
589
|
-
return
|
|
621
|
+
return (
|
|
622
|
+
getObservationMetadataAttribute(
|
|
623
|
+
span.attributes,
|
|
624
|
+
OBSERVATION_METADATA_LANGGRAPH_NODE
|
|
625
|
+
) === span.name
|
|
626
|
+
);
|
|
590
627
|
}
|
|
591
628
|
|
|
592
629
|
/**
|
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
import { _makeMessageChunkFromAnthropicEvent } from './utils/message_outputs';
|
|
36
36
|
import { convertAnthropicStream } from './utils/stream_events';
|
|
37
37
|
import { getCurrentClaudeDefaultMaxTokens } from './defaults';
|
|
38
|
+
import { withCurrentTurnContainer } from './utils/container';
|
|
38
39
|
import { handleToolChoice } from './utils/tools';
|
|
39
40
|
|
|
40
41
|
type StreamTokenType = 'string' | 'input' | 'content';
|
|
@@ -642,7 +643,9 @@ export class CustomAnthropic extends ChatAnthropicMessages {
|
|
|
642
643
|
options: this['ParsedCallOptions'],
|
|
643
644
|
_runManager?: CallbackManagerForLLMRun
|
|
644
645
|
): AsyncGenerator<ChatModelStreamEvent> {
|
|
645
|
-
const params = this.invocationParams(
|
|
646
|
+
const params = this.invocationParams(
|
|
647
|
+
withCurrentTurnContainer(messages, options)
|
|
648
|
+
);
|
|
646
649
|
const formattedMessages = _convertMessagesToAnthropicPayload(messages);
|
|
647
650
|
const payload = stripUnsupportedAssistantPrefill({
|
|
648
651
|
...params,
|
|
@@ -666,7 +669,9 @@ export class CustomAnthropic extends ChatAnthropicMessages {
|
|
|
666
669
|
runManager?: CallbackManagerForLLMRun
|
|
667
670
|
): AsyncGenerator<ChatGenerationChunk> {
|
|
668
671
|
this.resetTokenEvents();
|
|
669
|
-
const params = this.invocationParams(
|
|
672
|
+
const params = this.invocationParams(
|
|
673
|
+
withCurrentTurnContainer(messages, options)
|
|
674
|
+
);
|
|
670
675
|
const formattedMessages = _convertMessagesToAnthropicPayload(messages);
|
|
671
676
|
const payload = stripUnsupportedAssistantPrefill({
|
|
672
677
|
...params,
|
|
@@ -740,7 +745,10 @@ export class CustomAnthropic extends ChatAnthropicMessages {
|
|
|
740
745
|
if (
|
|
741
746
|
!tokenType ||
|
|
742
747
|
tokenType === 'input' ||
|
|
743
|
-
(token === '' &&
|
|
748
|
+
(token === '' &&
|
|
749
|
+
(chunk.usage_metadata != null ||
|
|
750
|
+
chunk.id != null ||
|
|
751
|
+
chunk.additional_kwargs.container != null))
|
|
744
752
|
) {
|
|
745
753
|
yield {
|
|
746
754
|
text: '',
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { BaseMessage } from '@langchain/core/messages';
|
|
2
|
+
import type { InjectedMessage } from '@/types/tools';
|
|
3
|
+
|
|
4
|
+
const IN_TURN_SOURCES: ReadonlySet<string> = new Set<
|
|
5
|
+
NonNullable<InjectedMessage['source']> | 'routing' | 'handoff'
|
|
6
|
+
>(['skill', 'hook', 'system', 'steer', 'routing', 'handoff']);
|
|
7
|
+
|
|
8
|
+
function getContainerId(container: unknown): string | undefined {
|
|
9
|
+
if (
|
|
10
|
+
typeof container !== 'object' ||
|
|
11
|
+
container === null ||
|
|
12
|
+
!('id' in container)
|
|
13
|
+
) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
return typeof container.id === 'string' && container.id !== ''
|
|
17
|
+
? container.id
|
|
18
|
+
: undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function withCurrentTurnContainer<T extends { container?: string }>(
|
|
22
|
+
messages: readonly BaseMessage[],
|
|
23
|
+
options: T
|
|
24
|
+
): T {
|
|
25
|
+
if (options.container != null) {
|
|
26
|
+
return options;
|
|
27
|
+
}
|
|
28
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
29
|
+
const message = messages[i];
|
|
30
|
+
const kwargs = message.additional_kwargs;
|
|
31
|
+
const type = message.getType();
|
|
32
|
+
if (type === 'human') {
|
|
33
|
+
if (
|
|
34
|
+
kwargs.injected !== true &&
|
|
35
|
+
!(
|
|
36
|
+
typeof kwargs.source === 'string' &&
|
|
37
|
+
IN_TURN_SOURCES.has(kwargs.source)
|
|
38
|
+
)
|
|
39
|
+
) {
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (type !== 'ai') {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const metadata = message.response_metadata as {
|
|
47
|
+
model_provider?: string;
|
|
48
|
+
container?: { id?: string };
|
|
49
|
+
};
|
|
50
|
+
if (
|
|
51
|
+
metadata.model_provider != null &&
|
|
52
|
+
metadata.model_provider !== 'anthropic'
|
|
53
|
+
) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const container =
|
|
57
|
+
getContainerId(kwargs.container) ?? getContainerId(metadata.container);
|
|
58
|
+
if (container != null) {
|
|
59
|
+
return { ...options, container };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return options;
|
|
63
|
+
}
|
|
@@ -28,7 +28,6 @@ import {
|
|
|
28
28
|
AnthropicThinkingBlockParam,
|
|
29
29
|
AnthropicRedactedThinkingBlockParam,
|
|
30
30
|
AnthropicServerToolUseBlockParam,
|
|
31
|
-
AnthropicWebSearchToolResultBlockParam,
|
|
32
31
|
isAnthropicImageBlockParam,
|
|
33
32
|
AnthropicSearchResultBlockParam,
|
|
34
33
|
AnthropicCompactionBlockParam,
|
|
@@ -38,6 +37,7 @@ import {
|
|
|
38
37
|
cloneToolMessageWithContent,
|
|
39
38
|
serializeStructuredValueBounded,
|
|
40
39
|
} from '@/utils/toolContent';
|
|
40
|
+
import { isAnthropicServerToolResultType } from '@/messages/anthropicServerTools';
|
|
41
41
|
import { isReasoningContentBlock } from '@/messages/reasoningTypes';
|
|
42
42
|
import { HARD_MAX_TOOL_RESULT_CHARS } from '@/utils/truncation';
|
|
43
43
|
import { Constants } from '@/common';
|
|
@@ -167,9 +167,10 @@ function hoistToolResultCacheControl(
|
|
|
167
167
|
return { content, cacheControl: undefined };
|
|
168
168
|
}
|
|
169
169
|
let cacheControl: unknown;
|
|
170
|
-
const stripped = content.map((
|
|
170
|
+
const stripped = content.map((part) => {
|
|
171
|
+
const block = part as MessageContentComplex | null;
|
|
171
172
|
if (typeof block !== 'object' || block == null || isProxy(block)) {
|
|
172
|
-
return
|
|
173
|
+
return part;
|
|
173
174
|
}
|
|
174
175
|
try {
|
|
175
176
|
const descriptors = Object.getOwnPropertyDescriptors(block);
|
|
@@ -210,7 +211,7 @@ function unwrapToolMessageResultContent(content: ToolMessage['content']): {
|
|
|
210
211
|
return { content, cacheControl: undefined, isError: undefined };
|
|
211
212
|
}
|
|
212
213
|
|
|
213
|
-
const block = content[0];
|
|
214
|
+
const block = content[0] as MessageContentComplex | null;
|
|
214
215
|
if (typeof block !== 'object' || block == null || isProxy(block)) {
|
|
215
216
|
return { content, cacheControl: undefined, isError: undefined };
|
|
216
217
|
}
|
|
@@ -650,7 +651,6 @@ function _formatContent(message: BaseMessage) {
|
|
|
650
651
|
'tool_result',
|
|
651
652
|
'input_json_delta',
|
|
652
653
|
'server_tool_use',
|
|
653
|
-
'web_search_tool_result',
|
|
654
654
|
'web_search_result',
|
|
655
655
|
];
|
|
656
656
|
const textTypes = ['text', 'text_delta'];
|
|
@@ -694,46 +694,60 @@ function _formatContent(message: BaseMessage) {
|
|
|
694
694
|
const corrected: AnthropicServerToolUseBlockParam = {
|
|
695
695
|
type: 'server_tool_use',
|
|
696
696
|
id: rawPart.id as string,
|
|
697
|
-
name: (rawPart.name ??
|
|
697
|
+
name: (rawPart.name ??
|
|
698
|
+
'web_search') as AnthropicServerToolUseBlockParam['name'],
|
|
698
699
|
input: coerceAnthropicToolUseInput(rawPart.input ?? rawPart.args),
|
|
700
|
+
...(rawPart.caller != null
|
|
701
|
+
? {
|
|
702
|
+
caller:
|
|
703
|
+
rawPart.caller as AnthropicServerToolUseBlockParam['caller'],
|
|
704
|
+
}
|
|
705
|
+
: {}),
|
|
706
|
+
...(rawPart.cache_control != null
|
|
707
|
+
? {
|
|
708
|
+
cache_control:
|
|
709
|
+
rawPart.cache_control as AnthropicServerToolUseBlockParam['cache_control'],
|
|
710
|
+
}
|
|
711
|
+
: {}),
|
|
699
712
|
};
|
|
700
713
|
return corrected;
|
|
701
714
|
}
|
|
702
715
|
|
|
703
|
-
|
|
704
|
-
* Normalize web_search_tool_result blocks into a clean shape.
|
|
705
|
-
* Same rationale as above — the block may carry extra properties from
|
|
706
|
-
* streaming (input, index, etc.) that the API rejects. Rebuild cleanly.
|
|
707
|
-
*/
|
|
716
|
+
const isServerResult = isAnthropicServerToolResultType(contentPart.type);
|
|
708
717
|
if (
|
|
718
|
+
isServerResult ||
|
|
719
|
+
((contentPart.type === 'text' || contentPart.type === 'tool_result') &&
|
|
709
720
|
'tool_use_id' in contentPart &&
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
).startsWith(Constants.ANTHROPIC_SERVER_TOOL_PREFIX) &&
|
|
715
|
-
'content' in contentPart
|
|
721
|
+
typeof contentPart.tool_use_id === 'string' &&
|
|
722
|
+
contentPart.tool_use_id.startsWith(
|
|
723
|
+
Constants.ANTHROPIC_SERVER_TOOL_PREFIX
|
|
724
|
+
))
|
|
716
725
|
) {
|
|
717
|
-
const
|
|
718
|
-
|
|
719
|
-
const
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
content
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
return corrected;
|
|
726
|
+
const { tool_use_id, content, caller, cache_control } =
|
|
727
|
+
contentPart as Record<string, unknown>;
|
|
728
|
+
const type = isServerResult
|
|
729
|
+
? contentPart.type
|
|
730
|
+
: 'web_search_tool_result';
|
|
731
|
+
if (
|
|
732
|
+
typeof tool_use_id !== 'string' ||
|
|
733
|
+
!tool_use_id.startsWith(Constants.ANTHROPIC_SERVER_TOOL_PREFIX) ||
|
|
734
|
+
content == null ||
|
|
735
|
+
typeof content !== 'object' ||
|
|
736
|
+
(type === 'web_search_tool_result'
|
|
737
|
+
? !Array.isArray(content) &&
|
|
738
|
+
(!('type' in content) ||
|
|
739
|
+
content.type !== 'web_search_tool_result_error')
|
|
740
|
+
: Array.isArray(content))
|
|
741
|
+
) {
|
|
742
|
+
return null;
|
|
735
743
|
}
|
|
736
|
-
return
|
|
744
|
+
return {
|
|
745
|
+
type,
|
|
746
|
+
tool_use_id,
|
|
747
|
+
content,
|
|
748
|
+
...(caller != null ? { caller } : {}),
|
|
749
|
+
...(cache_control != null ? { cache_control } : {}),
|
|
750
|
+
};
|
|
737
751
|
}
|
|
738
752
|
|
|
739
753
|
/**
|
|
@@ -749,22 +763,14 @@ function _formatContent(message: BaseMessage) {
|
|
|
749
763
|
typeof contentPart.name === 'string' &&
|
|
750
764
|
'args' in contentPart
|
|
751
765
|
) {
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
} catch {
|
|
757
|
-
args = {};
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
if (args == null || typeof args !== 'object' || Array.isArray(args)) {
|
|
761
|
-
args = {};
|
|
762
|
-
}
|
|
763
|
-
return _convertLangChainToolCallToAnthropic({
|
|
764
|
-
id: contentPart.id,
|
|
766
|
+
const caller = 'caller' in contentPart ? contentPart.caller : undefined;
|
|
767
|
+
return {
|
|
768
|
+
type: 'tool_use' as const,
|
|
769
|
+
id: normalizeAnthropicToolCallId(contentPart.id),
|
|
765
770
|
name: contentPart.name,
|
|
766
|
-
|
|
767
|
-
|
|
771
|
+
input: coerceAnthropicToolUseInput(contentPart.args),
|
|
772
|
+
...(caller != null ? { caller } : {}),
|
|
773
|
+
};
|
|
768
774
|
}
|
|
769
775
|
|
|
770
776
|
/**
|
|
@@ -6,6 +6,7 @@ import type { ChatGeneration } from '@langchain/core/outputs';
|
|
|
6
6
|
import type Anthropic from '@anthropic-ai/sdk';
|
|
7
7
|
import type { AnthropicMessageResponse } from '../types';
|
|
8
8
|
import type { MessageContentComplex } from '@/types';
|
|
9
|
+
import { isAnthropicServerToolResultType } from '@/messages/anthropicServerTools';
|
|
9
10
|
import { toLangChainContent } from '@/messages/langchain';
|
|
10
11
|
import { extractToolCalls } from './output_parsers';
|
|
11
12
|
|
|
@@ -52,6 +53,8 @@ function _isAnthropicCompactionBlock(
|
|
|
52
53
|
);
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
const OTHER_REPLAYABLE_BLOCK_TYPES: ReadonlySet<string> = new Set(['tool_use', 'document', 'server_tool_use']);
|
|
57
|
+
|
|
55
58
|
export function _makeMessageChunkFromAnthropicEvent(
|
|
56
59
|
data: Anthropic.Beta.Messages.BetaRawMessageStreamEvent,
|
|
57
60
|
fields: {
|
|
@@ -115,47 +118,17 @@ export function _makeMessageChunkFromAnthropicEvent(
|
|
|
115
118
|
};
|
|
116
119
|
} else if (
|
|
117
120
|
data.type === 'content_block_start' &&
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
'document',
|
|
121
|
-
'server_tool_use',
|
|
122
|
-
'web_search_tool_result',
|
|
123
|
-
].includes(data.content_block.type)
|
|
121
|
+
(OTHER_REPLAYABLE_BLOCK_TYPES.has(data.content_block.type) ||
|
|
122
|
+
isAnthropicServerToolResultType(data.content_block.type))
|
|
124
123
|
) {
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
index: data.index,
|
|
132
|
-
name: contentBlock.name,
|
|
133
|
-
args: '',
|
|
134
|
-
},
|
|
135
|
-
];
|
|
136
|
-
} else if (contentBlock.type === 'server_tool_use') {
|
|
137
|
-
// Handle anthropic built-in server tool use (like web search)
|
|
138
|
-
toolCallChunks = [
|
|
139
|
-
{
|
|
140
|
-
id: contentBlock.id,
|
|
141
|
-
index: data.index,
|
|
142
|
-
name: contentBlock.name,
|
|
143
|
-
args: '',
|
|
144
|
-
},
|
|
145
|
-
];
|
|
146
|
-
} else {
|
|
147
|
-
toolCallChunks = [];
|
|
148
|
-
}
|
|
124
|
+
const block = data.content_block;
|
|
125
|
+
const isToolUse =
|
|
126
|
+
block.type === 'tool_use' || block.type === 'server_tool_use';
|
|
127
|
+
const toolCallChunks: ToolCallChunk[] = isToolUse
|
|
128
|
+
? [{ id: block.id, index: data.index, name: block.name, args: '' }]
|
|
129
|
+
: [];
|
|
149
130
|
const content = [
|
|
150
|
-
{
|
|
151
|
-
index: data.index,
|
|
152
|
-
...data.content_block,
|
|
153
|
-
input:
|
|
154
|
-
contentBlock.type === 'server_tool_use' ||
|
|
155
|
-
contentBlock.type === 'tool_use'
|
|
156
|
-
? ''
|
|
157
|
-
: undefined,
|
|
158
|
-
},
|
|
131
|
+
{ ...block, index: data.index, ...(isToolUse ? { input: '' } : {}) },
|
|
159
132
|
];
|
|
160
133
|
return {
|
|
161
134
|
chunk: new AIMessageChunk({
|
|
@@ -16,6 +16,7 @@ import type {
|
|
|
16
16
|
AnthropicMessageStreamEvent,
|
|
17
17
|
} from '../types';
|
|
18
18
|
import type { AnthropicUsageData } from './message_outputs';
|
|
19
|
+
import { isAnthropicServerToolResultType } from '@/messages/anthropicServerTools';
|
|
19
20
|
import { getAnthropicUsageMetadata } from './message_outputs';
|
|
20
21
|
|
|
21
22
|
type AnthropicContentBlock =
|
|
@@ -75,12 +76,17 @@ export async function* convertAnthropicStream(
|
|
|
75
76
|
let usageSnapshot: UsageMetadata | undefined;
|
|
76
77
|
let eventUsage: AnthropicEventUsage | undefined;
|
|
77
78
|
let stopReason: string | null = null;
|
|
79
|
+
let container: Extract<
|
|
80
|
+
AnthropicMessageStreamEvent,
|
|
81
|
+
{ type: 'message_start' }
|
|
82
|
+
>['message']['container'] = null;
|
|
78
83
|
|
|
79
84
|
for await (const data of source) {
|
|
80
85
|
switch (data.type) {
|
|
81
86
|
// ── Message lifecycle ──────────────────────────────────
|
|
82
87
|
case 'message_start': {
|
|
83
88
|
const { usage, id, model } = data.message;
|
|
89
|
+
container = data.message.container;
|
|
84
90
|
if (shouldStreamUsage) {
|
|
85
91
|
eventUsage = {
|
|
86
92
|
inputTokens: usage.input_tokens,
|
|
@@ -106,6 +112,7 @@ export async function* convertAnthropicStream(
|
|
|
106
112
|
|
|
107
113
|
case 'message_delta': {
|
|
108
114
|
stopReason = data.delta.stop_reason;
|
|
115
|
+
container = data.delta.container ?? container;
|
|
109
116
|
if (shouldStreamUsage) {
|
|
110
117
|
eventUsage = updateEventUsage(eventUsage, data.usage);
|
|
111
118
|
usageSnapshot = buildUsageSnapshot(eventUsage);
|
|
@@ -130,7 +137,10 @@ export async function* convertAnthropicStream(
|
|
|
130
137
|
event: 'message-finish' as const,
|
|
131
138
|
reason: mapStopReason(stopReason),
|
|
132
139
|
...(usageSnapshot ? { usage: usageSnapshot } : {}),
|
|
133
|
-
responseMetadata: {
|
|
140
|
+
responseMetadata: {
|
|
141
|
+
model_provider: 'anthropic',
|
|
142
|
+
...(container != null ? { container } : {}),
|
|
143
|
+
},
|
|
134
144
|
};
|
|
135
145
|
yield finishEvent;
|
|
136
146
|
break;
|
|
@@ -295,27 +305,21 @@ function mapBlockToContentBlock(
|
|
|
295
305
|
case 'redacted_thinking':
|
|
296
306
|
return { ...block, index };
|
|
297
307
|
case 'tool_use':
|
|
298
|
-
return {
|
|
299
|
-
type: 'tool_call_chunk' as const,
|
|
300
|
-
id: block.id,
|
|
301
|
-
name: block.name,
|
|
302
|
-
args: '',
|
|
303
|
-
index,
|
|
304
|
-
};
|
|
305
308
|
case 'server_tool_use':
|
|
306
309
|
return {
|
|
307
|
-
type: '
|
|
310
|
+
type: block.type === 'tool_use' ? 'tool_call_chunk' : 'server_tool_call_chunk',
|
|
308
311
|
id: block.id,
|
|
309
312
|
name: block.name,
|
|
313
|
+
...('caller' in block ? { caller: block.caller } : {}),
|
|
310
314
|
args: '',
|
|
311
315
|
index,
|
|
312
316
|
};
|
|
313
|
-
case 'web_search_tool_result':
|
|
314
|
-
return { ...block, index };
|
|
315
317
|
case 'compaction':
|
|
316
318
|
return { ...block, index };
|
|
317
319
|
default:
|
|
318
|
-
return
|
|
320
|
+
return isAnthropicServerToolResultType(block.type)
|
|
321
|
+
? { ...block, index }
|
|
322
|
+
: { type: 'non_standard' as const, value: { ...block }, index };
|
|
319
323
|
}
|
|
320
324
|
}
|
|
321
325
|
|
|
@@ -463,6 +467,7 @@ function finalizeBlock(accumulated: BlockAccumulator): ContentBlock {
|
|
|
463
467
|
id: getStringField(accumulated, 'id'),
|
|
464
468
|
name: getStringField(accumulated, 'name'),
|
|
465
469
|
args: parsedArgs,
|
|
470
|
+
...(accumulated.caller != null ? { caller: accumulated.caller } : {}),
|
|
466
471
|
} as ContentBlock;
|
|
467
472
|
}
|
|
468
473
|
|
package/src/llm/bedrock/index.ts
CHANGED
|
@@ -58,9 +58,12 @@ import {
|
|
|
58
58
|
resolveStreamDelay,
|
|
59
59
|
isSignalAborted,
|
|
60
60
|
} from '@/llm/stream/smoother';
|
|
61
|
+
import {
|
|
62
|
+
isBedrockOpenAIModel,
|
|
63
|
+
replaysBedrockReasoning,
|
|
64
|
+
} from './utils/message_inputs';
|
|
61
65
|
import { modelDisallowsAssistantPrefill } from '@/llm/anthropic/utils/message_inputs';
|
|
62
66
|
import { linkStreamLimitCanonical } from '@/llm/streamLimits';
|
|
63
|
-
import { isBedrockOpenAIModel } from './utils/message_inputs';
|
|
64
67
|
import { neutralizeHarmonyToolConfig } from './utils/harmony';
|
|
65
68
|
import { insertBedrockToolCachePoint } from './toolCache';
|
|
66
69
|
|
|
@@ -271,7 +274,7 @@ export class CustomChatBedrockConverse extends ChatBedrockConverse {
|
|
|
271
274
|
runManager?: CallbackManagerForLLMRun
|
|
272
275
|
): Promise<ChatResult> {
|
|
273
276
|
if (
|
|
274
|
-
|
|
277
|
+
!replaysBedrockReasoning(this.model) ||
|
|
275
278
|
modelDisallowsAssistantPrefill(this.model)
|
|
276
279
|
) {
|
|
277
280
|
return this.generateWithLocalConverter(messages, options);
|
|
@@ -293,9 +296,8 @@ export class CustomChatBedrockConverse extends ChatBedrockConverse {
|
|
|
293
296
|
|
|
294
297
|
/**
|
|
295
298
|
* Non-streaming Converse through this package's converter, as the stream already uses.
|
|
296
|
-
* The parent's converter
|
|
297
|
-
*
|
|
298
|
-
* assistant prefill that Claude 4.6 and later reject.
|
|
299
|
+
* The parent's converter cannot omit unsupported reasoning replay, neutralize
|
|
300
|
+
* OpenAI Harmony tokens, or strip unsupported Claude assistant prefill.
|
|
299
301
|
*/
|
|
300
302
|
private async generateWithLocalConverter(
|
|
301
303
|
messages: BaseMessage[],
|