@librechat/agents 4.2.12 → 4.2.14
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 +56 -6
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/harness/providerText.cjs +1 -0
- package/dist/cjs/harness/providerText.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/google/utils/signatures.cjs +22 -14
- package/dist/cjs/llm/google/utils/signatures.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/invoke.cjs +122 -13
- package/dist/cjs/llm/invoke.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +9 -3
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/typedContent.cjs +94 -0
- package/dist/cjs/llm/openai/typedContent.cjs.map +1 -0
- package/dist/cjs/llm/openrouter/toolCache.cjs +1 -1
- package/dist/cjs/llm/prepareProviderRequest.cjs +81 -4
- package/dist/cjs/llm/prepareProviderRequest.cjs.map +1 -1
- package/dist/cjs/llm/providerTextBatch.cjs +128 -0
- package/dist/cjs/llm/providerTextBatch.cjs.map +1 -0
- package/dist/cjs/llm/providerTextBoundary.cjs +81 -12
- package/dist/cjs/llm/providerTextBoundary.cjs.map +1 -1
- package/dist/cjs/main.cjs +8 -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/core.cjs +3 -2
- package/dist/cjs/messages/core.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +2 -2
- 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 +60 -6
- package/dist/cjs/protection/providerText.cjs.map +1 -1
- package/dist/cjs/protection/providerTextAdmission.cjs +5 -0
- package/dist/cjs/protection/providerTextAdmission.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 +14 -3
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/runtime/client.cjs +4 -0
- package/dist/cjs/runtime/client.cjs.map +1 -1
- package/dist/cjs/stream.cjs +10 -2
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +1 -1
- package/dist/cjs/tools/ToolNode.cjs +46 -13
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/handlers.cjs +47 -1
- package/dist/cjs/tools/handlers.cjs.map +1 -1
- package/dist/cjs/tools/search/citations.cjs +194 -0
- package/dist/cjs/tools/search/citations.cjs.map +1 -0
- package/dist/cjs/tools/search/content.cjs +163 -42
- package/dist/cjs/tools/search/content.cjs.map +1 -1
- package/dist/cjs/tools/search/firecrawl.cjs +4 -9
- package/dist/cjs/tools/search/firecrawl.cjs.map +1 -1
- package/dist/cjs/tools/search/google.cjs +68 -0
- package/dist/cjs/tools/search/google.cjs.map +1 -0
- package/dist/cjs/tools/search/openai.cjs +80 -0
- package/dist/cjs/tools/search/openai.cjs.map +1 -0
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +4 -0
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/utils/tokens.cjs +12 -2
- package/dist/cjs/utils/tokens.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +57 -7
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/harness/providerText.mjs +1 -0
- package/dist/esm/harness/providerText.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/google/utils/signatures.mjs +22 -14
- package/dist/esm/llm/google/utils/signatures.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/invoke.mjs +124 -15
- package/dist/esm/llm/invoke.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +9 -3
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/typedContent.mjs +93 -0
- package/dist/esm/llm/openai/typedContent.mjs.map +1 -0
- package/dist/esm/llm/openrouter/toolCache.mjs +1 -1
- package/dist/esm/llm/prepareProviderRequest.mjs +81 -4
- package/dist/esm/llm/prepareProviderRequest.mjs.map +1 -1
- package/dist/esm/llm/providerTextBatch.mjs +128 -0
- package/dist/esm/llm/providerTextBatch.mjs.map +1 -0
- package/dist/esm/llm/providerTextBoundary.mjs +81 -12
- package/dist/esm/llm/providerTextBoundary.mjs.map +1 -1
- package/dist/esm/main.mjs +7 -6
- 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/core.mjs +3 -2
- package/dist/esm/messages/core.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +2 -2
- 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 +58 -7
- package/dist/esm/protection/providerText.mjs.map +1 -1
- package/dist/esm/protection/providerTextAdmission.mjs +5 -0
- package/dist/esm/protection/providerTextAdmission.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 +14 -3
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/runtime/client.mjs +4 -0
- package/dist/esm/runtime/client.mjs.map +1 -1
- package/dist/esm/stream.mjs +10 -2
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +1 -1
- package/dist/esm/tools/ToolNode.mjs +46 -13
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/handlers.mjs +47 -2
- package/dist/esm/tools/handlers.mjs.map +1 -1
- package/dist/esm/tools/search/citations.mjs +190 -0
- package/dist/esm/tools/search/citations.mjs.map +1 -0
- package/dist/esm/tools/search/content.mjs +163 -42
- package/dist/esm/tools/search/content.mjs.map +1 -1
- package/dist/esm/tools/search/firecrawl.mjs +4 -9
- package/dist/esm/tools/search/firecrawl.mjs.map +1 -1
- package/dist/esm/tools/search/google.mjs +67 -0
- package/dist/esm/tools/search/google.mjs.map +1 -0
- package/dist/esm/tools/search/openai.mjs +80 -0
- package/dist/esm/tools/search/openai.mjs.map +1 -0
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +4 -0
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/utils/tokens.mjs +12 -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 +18 -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/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 +1 -1
- package/dist/types/llm/openai/typedContent.d.ts +14 -0
- package/dist/types/llm/providerRegistry.d.ts +1 -1
- package/dist/types/llm/providerTextBatch.d.ts +26 -0
- package/dist/types/llm/providerTextBoundary.d.ts +7 -1
- package/dist/types/llm/providers.d.ts +1 -1
- package/dist/types/messages/anthropicServerTools.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 +32 -2
- package/dist/types/protection/providerTextAdmission.d.ts +1 -0
- 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 +1 -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 +3 -3
- 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/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/handlers.d.ts +13 -0
- 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/citations.d.ts +88 -0
- 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 +4 -2
- package/dist/types/tools/search/format.d.ts +1 -1
- package/dist/types/tools/search/google.d.ts +11 -0
- 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/openai.d.ts +3 -0
- 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 +26 -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 +6 -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 +1 -1
- package/dist/types/types/graph.d.ts +4 -1
- package/dist/types/types/index.d.ts +14 -14
- package/dist/types/types/llm.d.ts +2 -2
- package/dist/types/types/run.d.ts +3 -1
- package/dist/types/types/stream.d.ts +12 -0
- package/dist/types/types/subagentTasks.d.ts +2 -2
- package/dist/types/types/tools.d.ts +6 -3
- package/dist/types/utils/index.d.ts +10 -10
- package/dist/types/utils/tokens.d.ts +2 -0
- package/package.json +3 -2
- package/src/graphs/Graph.ts +125 -3
- package/src/harness/providerText.ts +1 -0
- package/src/index.ts +10 -0
- 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/google/utils/signatures.ts +52 -36
- package/src/llm/init.ts +35 -3
- package/src/llm/invoke.ts +160 -16
- package/src/llm/openai/index.ts +18 -5
- package/src/llm/openai/typedContent.ts +110 -0
- package/src/llm/prepareProviderRequest.ts +154 -4
- package/src/llm/providerTextBatch.ts +158 -0
- package/src/llm/providerTextBoundary.ts +119 -13
- package/src/messages/anthropicServerTools.ts +24 -0
- package/src/messages/core.ts +12 -11
- package/src/messages/toolResultTypes.ts +80 -88
- package/src/protection/providerText.ts +222 -46
- package/src/protection/providerTextAdmission.ts +6 -0
- package/src/protection/toolResult.ts +272 -0
- package/src/run.ts +37 -5
- package/src/runtime/client.ts +6 -0
- package/src/stream.ts +23 -2
- package/src/tools/ToolNode.ts +112 -17
- package/src/tools/handlers.ts +110 -5
- package/src/tools/search/citations.ts +375 -0
- package/src/tools/search/content.ts +282 -62
- package/src/tools/search/firecrawl.ts +13 -16
- package/src/tools/search/google.ts +122 -0
- package/src/tools/search/openai.ts +118 -0
- package/src/tools/search/types.ts +21 -0
- package/src/tools/subagent/SubagentExecutor.ts +6 -0
- package/src/types/graph.ts +3 -0
- package/src/types/run.ts +3 -0
- package/src/types/stream.ts +9 -0
- package/src/types/tools.ts +3 -0
- package/src/utils/tokens.ts +37 -2
|
@@ -16,6 +16,7 @@ export interface ProviderTextAdmissionSnapshot {
|
|
|
16
16
|
/** Internal ownership lease; only the attempt that acquires it may release it. */
|
|
17
17
|
export interface ProviderTextAdmissionLease {
|
|
18
18
|
charge(bytes: number): void;
|
|
19
|
+
uncharge(bytes: number): void;
|
|
19
20
|
retain(): void;
|
|
20
21
|
release(): void;
|
|
21
22
|
}
|
|
@@ -66,6 +67,11 @@ export class ProviderTextAdmission {
|
|
|
66
67
|
bytes += amount;
|
|
67
68
|
if (retained) this.retainedBytes += amount;
|
|
68
69
|
},
|
|
70
|
+
uncharge: (amount): void => {
|
|
71
|
+
this.bufferedBytes -= amount;
|
|
72
|
+
bytes -= amount;
|
|
73
|
+
if (retained) this.retainedBytes -= amount;
|
|
74
|
+
},
|
|
69
75
|
retain: (): void => {
|
|
70
76
|
if (retained || released) return;
|
|
71
77
|
retained = true;
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { ToolMessage } from '@langchain/core/messages';
|
|
2
|
+
import type {
|
|
3
|
+
ProviderTextProtection,
|
|
4
|
+
ProviderTextProtectionResult,
|
|
5
|
+
ProviderTextProtectionErrorCode,
|
|
6
|
+
} from './providerText';
|
|
7
|
+
import type { ToolExecuteResult } from '@/types/tools';
|
|
8
|
+
import {
|
|
9
|
+
ProviderTextAttempt,
|
|
10
|
+
readProviderTextResult,
|
|
11
|
+
ProviderTextProtectionError,
|
|
12
|
+
validateProviderTextProtection,
|
|
13
|
+
} from './providerText';
|
|
14
|
+
import { PreparedSubagentError } from '@/tools/preparedSubagents';
|
|
15
|
+
import { cloneToolMessageWithContent } from '@/utils/toolContent';
|
|
16
|
+
import { StreamLimitExceededError } from '@/llm/streamLimits';
|
|
17
|
+
|
|
18
|
+
export const TOOL_RESULT_PROTECTION_VERSION = 1;
|
|
19
|
+
|
|
20
|
+
export type ToolResultProtectionResult = ProviderTextProtectionResult;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Host inspection of the text returned by selected tools. Default off.
|
|
24
|
+
*
|
|
25
|
+
* The SDK calls `inspect` on a selected tool's text before anything else reads
|
|
26
|
+
* it: hooks, completion events, the output reference registry, checkpoints and
|
|
27
|
+
* the model all receive the inspected text. A failed inspection ends the run
|
|
28
|
+
* with a {@link ToolResultProtectionError}.
|
|
29
|
+
*
|
|
30
|
+
* Trust boundary: the tool's text is untrusted data; code running in the host
|
|
31
|
+
* process is trusted. Tools, hooks, event handlers, callbacks and checkpoint
|
|
32
|
+
* savers are not defended against, text they author is not inspected, and
|
|
33
|
+
* history the host supplies is the host's to have inspected. Tracing observes
|
|
34
|
+
* a selected tool's raw result; redact those tools with the tracing
|
|
35
|
+
* configuration.
|
|
36
|
+
*
|
|
37
|
+
* Selected tools must return plain text. A structured result, an artifact or a
|
|
38
|
+
* `Command` fails as `unsupported`. Selected tools are not offered to
|
|
39
|
+
* programmatic tool calling, are not started eagerly, and cannot be client
|
|
40
|
+
* delegated. Unselected tools are untouched.
|
|
41
|
+
*/
|
|
42
|
+
export interface ToolResultProtection {
|
|
43
|
+
readonly version: 1;
|
|
44
|
+
readonly toolNames: readonly string[];
|
|
45
|
+
readonly timeoutMs: number;
|
|
46
|
+
readonly maxAttemptBytes: number;
|
|
47
|
+
/** Shared across all inspections using this policy, including child graphs. */
|
|
48
|
+
readonly maxBufferedBytes: number;
|
|
49
|
+
readonly classify: (content: string) => 'prose' | 'unsupported';
|
|
50
|
+
readonly inspect: (input: {
|
|
51
|
+
readonly version: 1;
|
|
52
|
+
readonly content: string;
|
|
53
|
+
readonly toolName: string;
|
|
54
|
+
readonly toolCallId: string;
|
|
55
|
+
readonly target: {
|
|
56
|
+
readonly source: 'tool_argument';
|
|
57
|
+
readonly field: 'output';
|
|
58
|
+
readonly provenance: 'tool';
|
|
59
|
+
readonly outcome: ToolResultOutcome;
|
|
60
|
+
};
|
|
61
|
+
readonly signal: AbortSignal;
|
|
62
|
+
}) => ToolResultProtectionResult | Promise<ToolResultProtectionResult>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export class ToolResultProtectionError extends ProviderTextProtectionError {
|
|
66
|
+
constructor(code: ProviderTextProtectionErrorCode) {
|
|
67
|
+
super(code);
|
|
68
|
+
this.name = 'ToolResultProtectionError';
|
|
69
|
+
this.message = `Tool result protection: ${this.code}`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type ToolResultOutcome = 'success' | 'error';
|
|
74
|
+
|
|
75
|
+
export interface ToolResultCall {
|
|
76
|
+
readonly name: string;
|
|
77
|
+
readonly id: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** A validated policy. One per policy object, so every graph of a run shares its byte budget. */
|
|
81
|
+
export interface ToolResultGate {
|
|
82
|
+
readonly policy: ToolResultProtection;
|
|
83
|
+
readonly toolNames: ReadonlySet<string>;
|
|
84
|
+
readonly budget: ProviderTextProtection;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const gates = new WeakMap<ToolResultProtection, ToolResultGate>();
|
|
88
|
+
|
|
89
|
+
/** Budget accounting only: tool text is never released through the provider-text path. */
|
|
90
|
+
const rejectProviderRelease = (): ProviderTextProtectionResult => ({
|
|
91
|
+
version: 1,
|
|
92
|
+
ok: false,
|
|
93
|
+
error: { code: 'incompatible' },
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
/** Run-level safety aborts keep their identity; nothing else carries text out of an inspection. */
|
|
97
|
+
function toToolResultError(error: unknown): Error {
|
|
98
|
+
if (
|
|
99
|
+
error instanceof ToolResultProtectionError ||
|
|
100
|
+
error instanceof StreamLimitExceededError ||
|
|
101
|
+
error instanceof PreparedSubagentError
|
|
102
|
+
) {
|
|
103
|
+
return error;
|
|
104
|
+
}
|
|
105
|
+
return new ToolResultProtectionError(
|
|
106
|
+
error instanceof ProviderTextProtectionError ? error.code : 'unavailable'
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function hasValidToolNames(toolNames: readonly string[]): boolean {
|
|
111
|
+
return (
|
|
112
|
+
Array.isArray(toolNames) &&
|
|
113
|
+
toolNames.length > 0 &&
|
|
114
|
+
toolNames.every((name) => typeof name === 'string' && name.trim() !== '')
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function createToolResultGate(
|
|
119
|
+
policy: ToolResultProtection
|
|
120
|
+
): ToolResultGate {
|
|
121
|
+
const existing = gates.get(policy);
|
|
122
|
+
if (existing != null) {
|
|
123
|
+
return existing;
|
|
124
|
+
}
|
|
125
|
+
if (typeof policy.inspect !== 'function') {
|
|
126
|
+
throw new ToolResultProtectionError('unavailable');
|
|
127
|
+
}
|
|
128
|
+
if (!hasValidToolNames(policy.toolNames)) {
|
|
129
|
+
throw new ToolResultProtectionError('incompatible');
|
|
130
|
+
}
|
|
131
|
+
const budget: ProviderTextProtection = {
|
|
132
|
+
version: policy.version,
|
|
133
|
+
timeoutMs: policy.timeoutMs,
|
|
134
|
+
maxAttemptBytes: policy.maxAttemptBytes,
|
|
135
|
+
maxBufferedBytes: policy.maxBufferedBytes,
|
|
136
|
+
classify: policy.classify,
|
|
137
|
+
inspect: rejectProviderRelease,
|
|
138
|
+
};
|
|
139
|
+
try {
|
|
140
|
+
validateProviderTextProtection(budget);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
throw toToolResultError(error);
|
|
143
|
+
}
|
|
144
|
+
const gate: ToolResultGate = {
|
|
145
|
+
policy,
|
|
146
|
+
toolNames: new Set(policy.toolNames),
|
|
147
|
+
budget,
|
|
148
|
+
};
|
|
149
|
+
gates.set(policy, gate);
|
|
150
|
+
return gate;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Returns the inspected text, or throws; the raw text and inspector errors never leave. */
|
|
154
|
+
export async function inspectToolText(
|
|
155
|
+
gate: ToolResultGate,
|
|
156
|
+
call: ToolResultCall,
|
|
157
|
+
content: string,
|
|
158
|
+
outcome: ToolResultOutcome,
|
|
159
|
+
signal?: AbortSignal
|
|
160
|
+
): Promise<string> {
|
|
161
|
+
if (content === '') {
|
|
162
|
+
return content;
|
|
163
|
+
}
|
|
164
|
+
let attempt: ProviderTextAttempt | undefined;
|
|
165
|
+
try {
|
|
166
|
+
attempt = new ProviderTextAttempt(gate.budget, signal);
|
|
167
|
+
const inspection = attempt;
|
|
168
|
+
inspection.append(content);
|
|
169
|
+
if (gate.policy.classify(content) !== 'prose') {
|
|
170
|
+
throw new ToolResultProtectionError('unsupported');
|
|
171
|
+
}
|
|
172
|
+
const result = await inspection.wait(
|
|
173
|
+
(async (): Promise<ToolResultProtectionResult> =>
|
|
174
|
+
gate.policy.inspect({
|
|
175
|
+
version: 1,
|
|
176
|
+
content,
|
|
177
|
+
toolName: call.name,
|
|
178
|
+
toolCallId: call.id,
|
|
179
|
+
target: {
|
|
180
|
+
source: 'tool_argument',
|
|
181
|
+
field: 'output',
|
|
182
|
+
provenance: 'tool',
|
|
183
|
+
outcome,
|
|
184
|
+
},
|
|
185
|
+
signal: inspection.signal,
|
|
186
|
+
}))()
|
|
187
|
+
);
|
|
188
|
+
inspection.check();
|
|
189
|
+
const inspected = readProviderTextResult(result);
|
|
190
|
+
inspection.retain(inspected.length * 2);
|
|
191
|
+
return inspected;
|
|
192
|
+
} catch (error) {
|
|
193
|
+
throw toToolResultError(
|
|
194
|
+
attempt?.signal.aborted === true ? attempt.signal.reason : error
|
|
195
|
+
);
|
|
196
|
+
} finally {
|
|
197
|
+
attempt?.finish();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Inspects what a selected in-process tool returned. */
|
|
202
|
+
export async function inspectToolOutput(
|
|
203
|
+
gate: ToolResultGate,
|
|
204
|
+
call: ToolResultCall,
|
|
205
|
+
output: unknown,
|
|
206
|
+
signal?: AbortSignal
|
|
207
|
+
): Promise<ToolMessage | string> {
|
|
208
|
+
if (typeof output === 'string') {
|
|
209
|
+
return inspectToolText(gate, call, output, 'success', signal);
|
|
210
|
+
}
|
|
211
|
+
if (
|
|
212
|
+
!ToolMessage.isInstance(output) ||
|
|
213
|
+
output.artifact != null ||
|
|
214
|
+
typeof output.content !== 'string'
|
|
215
|
+
) {
|
|
216
|
+
throw new ToolResultProtectionError('unsupported');
|
|
217
|
+
}
|
|
218
|
+
const content = await inspectToolText(
|
|
219
|
+
gate,
|
|
220
|
+
call,
|
|
221
|
+
output.content,
|
|
222
|
+
output.status === 'error' ? 'error' : 'success',
|
|
223
|
+
signal
|
|
224
|
+
);
|
|
225
|
+
return content === output.content
|
|
226
|
+
? output
|
|
227
|
+
: cloneToolMessageWithContent(output, content);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Inspects what the host returned for a selected tool call. */
|
|
231
|
+
export async function inspectToolExecuteResult(
|
|
232
|
+
gate: ToolResultGate,
|
|
233
|
+
call: ToolResultCall,
|
|
234
|
+
result: ToolExecuteResult,
|
|
235
|
+
signal?: AbortSignal
|
|
236
|
+
): Promise<ToolExecuteResult> {
|
|
237
|
+
if (result.artifact != null) {
|
|
238
|
+
throw new ToolResultProtectionError('unsupported');
|
|
239
|
+
}
|
|
240
|
+
if (result.status === 'error') {
|
|
241
|
+
if (result.errorMessage == null) {
|
|
242
|
+
return { ...result, content: '' };
|
|
243
|
+
}
|
|
244
|
+
if (typeof result.errorMessage !== 'string') {
|
|
245
|
+
throw new ToolResultProtectionError('unsupported');
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
...result,
|
|
249
|
+
content: '',
|
|
250
|
+
errorMessage: await inspectToolText(
|
|
251
|
+
gate,
|
|
252
|
+
call,
|
|
253
|
+
result.errorMessage,
|
|
254
|
+
'error',
|
|
255
|
+
signal
|
|
256
|
+
),
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
if (typeof result.content !== 'string') {
|
|
260
|
+
throw new ToolResultProtectionError('unsupported');
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
...result,
|
|
264
|
+
content: await inspectToolText(
|
|
265
|
+
gate,
|
|
266
|
+
call,
|
|
267
|
+
result.content,
|
|
268
|
+
'success',
|
|
269
|
+
signal
|
|
270
|
+
),
|
|
271
|
+
};
|
|
272
|
+
}
|
package/src/run.ts
CHANGED
|
@@ -95,6 +95,10 @@ import {
|
|
|
95
95
|
findCallback,
|
|
96
96
|
type CallbackEntry,
|
|
97
97
|
} from '@/utils/callbacks';
|
|
98
|
+
import {
|
|
99
|
+
BATCHED_PROVIDER_EVENT_OWNER,
|
|
100
|
+
ProviderTextProtectionError,
|
|
101
|
+
} from '@/protection/providerText';
|
|
98
102
|
import {
|
|
99
103
|
resolveLangfuseRuntimeScope,
|
|
100
104
|
withLangfuseRuntimeScope,
|
|
@@ -108,10 +112,10 @@ import {
|
|
|
108
112
|
createTitleRunnable,
|
|
109
113
|
} from '@/utils/title';
|
|
110
114
|
import { applyGraphRuntimeConfig } from '@/graphs/applyGraphRuntimeConfig';
|
|
111
|
-
import { ProviderTextProtectionError } from '@/protection/providerText';
|
|
112
115
|
import { LANGFUSE_OPERATION_METADATA_KEY } from '@/langfuseOperation';
|
|
113
116
|
import { createTokenCounter, encodingForModel } from '@/utils/tokens';
|
|
114
117
|
import { stampSyntheticProviderMessage } from '@/messages/provenance';
|
|
118
|
+
import { ToolResultProtectionError } from '@/protection/toolResult';
|
|
115
119
|
import { isOpenAILike, isLibreChatOpenAIModel } from '@/utils/llm';
|
|
116
120
|
import { executeHooks, mergeAggregatedHookResults } from '@/hooks';
|
|
117
121
|
import { convertInjectedMessages } from '@/messages/injected';
|
|
@@ -397,9 +401,7 @@ async function resolveCompletedSegmentConfig(
|
|
|
397
401
|
);
|
|
398
402
|
}
|
|
399
403
|
|
|
400
|
-
function getFirstPersistedInterrupt(
|
|
401
|
-
snapshot: InterruptStateSnapshot
|
|
402
|
-
):
|
|
404
|
+
function getFirstPersistedInterrupt(snapshot: InterruptStateSnapshot):
|
|
403
405
|
| {
|
|
404
406
|
id: string;
|
|
405
407
|
value: unknown;
|
|
@@ -511,6 +513,7 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
511
513
|
private preemption?: t.StreamPreemption;
|
|
512
514
|
private maxStopContinuations: number;
|
|
513
515
|
private providerTextProtection?: t.StandardGraphInput['providerTextProtection'];
|
|
516
|
+
private toolResultProtection?: t.StandardGraphInput['toolResultProtection'];
|
|
514
517
|
private resolveAttachment?: t.StandardGraphInput['resolveAttachment'];
|
|
515
518
|
private streamLimits?: t.StreamLimits;
|
|
516
519
|
private subagentTasks?: t.SubagentTaskConfig;
|
|
@@ -616,6 +619,7 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
616
619
|
);
|
|
617
620
|
this.streamLimits = config.streamLimits;
|
|
618
621
|
this.providerTextProtection = config.providerTextProtection;
|
|
622
|
+
this.toolResultProtection = config.toolResultProtection;
|
|
619
623
|
this.resolveAttachment = config.resolveAttachment;
|
|
620
624
|
|
|
621
625
|
if (!config.graphConfig) {
|
|
@@ -627,6 +631,21 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
627
631
|
) {
|
|
628
632
|
throw new ProviderTextProtectionError('incompatible');
|
|
629
633
|
}
|
|
634
|
+
if (
|
|
635
|
+
'toolResultProtection' in config.graphConfig &&
|
|
636
|
+
config.graphConfig.toolResultProtection != null
|
|
637
|
+
) {
|
|
638
|
+
throw new ToolResultProtectionError('incompatible');
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
if (
|
|
642
|
+
this.providerTextProtection?.batching != null &&
|
|
643
|
+
(config.humanInTheLoop?.enabled === true ||
|
|
644
|
+
('agents' in config.graphConfig &&
|
|
645
|
+
config.graphConfig.agents.length !== 1))
|
|
646
|
+
) {
|
|
647
|
+
throw new ProviderTextProtectionError('unsupported');
|
|
648
|
+
}
|
|
630
649
|
|
|
631
650
|
/** Handle different graph types */
|
|
632
651
|
if (config.graphConfig.type === 'multi-agent') {
|
|
@@ -727,6 +746,7 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
727
746
|
preemption: this.preemption,
|
|
728
747
|
streamLimits: this.streamLimits,
|
|
729
748
|
providerTextProtection: this.providerTextProtection,
|
|
749
|
+
toolResultProtection: this.toolResultProtection,
|
|
730
750
|
resolveAttachment: this.resolveAttachment,
|
|
731
751
|
toolExecution: this.toolExecution,
|
|
732
752
|
clientDelegatedToolNames: this.clientDelegatedToolNames,
|
|
@@ -776,6 +796,7 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
776
796
|
preemption: this.preemption,
|
|
777
797
|
streamLimits: this.streamLimits,
|
|
778
798
|
providerTextProtection: this.providerTextProtection,
|
|
799
|
+
toolResultProtection: this.toolResultProtection,
|
|
779
800
|
resolveAttachment: this.resolveAttachment,
|
|
780
801
|
toolExecution: this.toolExecution,
|
|
781
802
|
},
|
|
@@ -1619,6 +1640,14 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
1619
1640
|
for await (const event of stream) {
|
|
1620
1641
|
const { data, metadata, ...info } = event;
|
|
1621
1642
|
const eventName: t.EventName = info.event;
|
|
1643
|
+
// The batched attempt owns start and delta delivery and their deadline.
|
|
1644
|
+
if (
|
|
1645
|
+
this.providerTextProtection?.batching != null &&
|
|
1646
|
+
(eventName === GraphEvents.CHAT_MODEL_START ||
|
|
1647
|
+
eventName === GraphEvents.CHAT_MODEL_STREAM) &&
|
|
1648
|
+
metadata[BATCHED_PROVIDER_EVENT_OWNER] === true
|
|
1649
|
+
)
|
|
1650
|
+
continue;
|
|
1622
1651
|
|
|
1623
1652
|
if (CUSTOM_GRAPH_EVENTS.has(eventName)) {
|
|
1624
1653
|
continue;
|
|
@@ -1663,6 +1692,7 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
1663
1692
|
}
|
|
1664
1693
|
|
|
1665
1694
|
if (eventName === GraphEvents.CHAT_MODEL_END && this.Graph != null) {
|
|
1695
|
+
await this.Graph.settleSearchCitations(metadata);
|
|
1666
1696
|
await this.Graph.closeOpenMessageStep(metadata, modelEndAt);
|
|
1667
1697
|
}
|
|
1668
1698
|
|
|
@@ -3082,7 +3112,9 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
3082
3112
|
reasoningChainOptions.runName ?? REASONING_LABEL_TRACE_NAME;
|
|
3083
3113
|
const reasoningTags = ['librechat', 'reasoning-label', 'reasoning-step'];
|
|
3084
3114
|
const reasoningRunLangfuse = withoutSkillsAvailable(this.langfuse);
|
|
3085
|
-
const reasoningLangfuseOverlay = withoutSkillsAvailable(
|
|
3115
|
+
const reasoningLangfuseOverlay = withoutSkillsAvailable(
|
|
3116
|
+
reasoningContext?.langfuse
|
|
3117
|
+
);
|
|
3086
3118
|
const reasoningLangfuseConfig = resolveLangfuseConfig(
|
|
3087
3119
|
reasoningRunLangfuse,
|
|
3088
3120
|
reasoningLangfuseOverlay
|
package/src/runtime/client.ts
CHANGED
|
@@ -27,6 +27,8 @@ import type { RecoveryClaim } from './recovery/server';
|
|
|
27
27
|
import type { SdkAgentIdentity } from './identity';
|
|
28
28
|
import {
|
|
29
29
|
Run,
|
|
30
|
+
ToolResultProtectionError,
|
|
31
|
+
ProviderTextProtectionError,
|
|
30
32
|
executeHooks,
|
|
31
33
|
GraphEvents,
|
|
32
34
|
HOOK_EVENTS,
|
|
@@ -64,6 +66,10 @@ export async function createRemoteSdkRun({
|
|
|
64
66
|
throw new Error(
|
|
65
67
|
'Remote SDK client-owned tools require a supported ownership adapter'
|
|
66
68
|
);
|
|
69
|
+
if (config.toolResultProtection != null)
|
|
70
|
+
throw new ToolResultProtectionError('unsupported');
|
|
71
|
+
if (config.providerTextProtection?.batching != null)
|
|
72
|
+
throw new ProviderTextProtectionError('unsupported');
|
|
67
73
|
if (config.providerTextProtection && !hostServices?.providerText)
|
|
68
74
|
throw new Error(
|
|
69
75
|
'Remote SDK provider protection requires a supported policy adapter'
|
package/src/stream.ts
CHANGED
|
@@ -63,8 +63,10 @@ import { resolveToolOutcome, outcomeFieldsFromResult } from '@/tools/intentArg';
|
|
|
63
63
|
import { snapshotValidatedModelChunk } from '@/graphs/acceptedModelResponse';
|
|
64
64
|
import { ProviderTextProtectionError } from '@/protection/providerText';
|
|
65
65
|
import { TOOL_OUTPUT_REF_PATTERN } from '@/tools/toolOutputReferences';
|
|
66
|
+
import { getGoogleGroundingMetadata } from '@/tools/search/google';
|
|
66
67
|
import { formatToolErrorContent } from '@/tools/toolErrorContent';
|
|
67
68
|
import { PreparedSubagentError } from '@/tools/preparedSubagents';
|
|
69
|
+
import { applyTextEdits } from '@/tools/search/citations';
|
|
68
70
|
import { isReasoningContentBlock } from '@/messages/core';
|
|
69
71
|
import { composeAbortSignals } from '@/utils/misc';
|
|
70
72
|
import { isGoogleLike } from '@/utils/llm';
|
|
@@ -194,6 +196,11 @@ function isEagerExecutionExcludedTool(
|
|
|
194
196
|
if (excluded != null && excluded.includes(name)) {
|
|
195
197
|
return true;
|
|
196
198
|
}
|
|
199
|
+
// A protected result must be inspected before its completion is published,
|
|
200
|
+
// which only the committed ToolNode path guarantees.
|
|
201
|
+
if (graph.toolResultProtection?.toolNames.includes(name) === true) {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
197
204
|
// Run-scoped circuit breaker: once a prestart for this tool diverged from
|
|
198
205
|
// the final request ("changed after eager execution started"), stop
|
|
199
206
|
// prestarting it so the model's retry executes normally instead of
|
|
@@ -1811,6 +1818,12 @@ export class ChatModelStreamHandler implements t.EventHandler {
|
|
|
1811
1818
|
if (metadata?.summarization === true) return;
|
|
1812
1819
|
|
|
1813
1820
|
const agentContext = graph.getAgentContext(metadata);
|
|
1821
|
+
const grounding = isGoogleLike(agentContext.provider)
|
|
1822
|
+
? getGoogleGroundingMetadata(chunk)
|
|
1823
|
+
: undefined;
|
|
1824
|
+
if (grounding != null) {
|
|
1825
|
+
graph.groundSearchCitations(metadata, grounding);
|
|
1826
|
+
}
|
|
1814
1827
|
|
|
1815
1828
|
const content = getChunkContent({
|
|
1816
1829
|
chunk,
|
|
@@ -2498,16 +2511,24 @@ export function createContentAggregator(): t.ContentAggregatorResult {
|
|
|
2498
2511
|
citations?: t.MessageDeltaUpdate['citations'];
|
|
2499
2512
|
};
|
|
2500
2513
|
const incomingCitations = Array.isArray(citations) ? citations : undefined;
|
|
2514
|
+
const { edits } = contentPart as { edits?: t.MessageDeltaUpdate['edits'] };
|
|
2515
|
+
const incomingEdits = Array.isArray(edits) ? edits : undefined;
|
|
2501
2516
|
|
|
2502
2517
|
if (
|
|
2503
2518
|
partType.startsWith(ContentTypes.TEXT) &&
|
|
2504
|
-
(incomingText !== undefined ||
|
|
2519
|
+
(incomingText !== undefined ||
|
|
2520
|
+
incomingCitations !== undefined ||
|
|
2521
|
+
incomingEdits !== undefined)
|
|
2505
2522
|
) {
|
|
2506
2523
|
// TODO: update this!!
|
|
2507
2524
|
const currentContent = contentParts[index] as t.MessageDeltaUpdate;
|
|
2525
|
+
const text = (currentContent.text || '') + (incomingText ?? '');
|
|
2508
2526
|
const update: t.MessageDeltaUpdate = {
|
|
2509
2527
|
type: ContentTypes.TEXT,
|
|
2510
|
-
text:
|
|
2528
|
+
text:
|
|
2529
|
+
incomingEdits === undefined
|
|
2530
|
+
? text
|
|
2531
|
+
: applyTextEdits(text, incomingEdits),
|
|
2511
2532
|
};
|
|
2512
2533
|
|
|
2513
2534
|
if (contentPart.tool_call_ids) {
|