@librechat/agents 4.2.12 → 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.
Files changed (280) hide show
  1. package/dist/cjs/graphs/Graph.cjs +11 -3
  2. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  3. package/dist/cjs/llm/anthropic/index.cjs +4 -3
  4. package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
  5. package/dist/cjs/llm/anthropic/utils/container.cjs +37 -0
  6. package/dist/cjs/llm/anthropic/utils/container.cjs.map +1 -0
  7. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +25 -23
  8. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
  9. package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +15 -21
  10. package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
  11. package/dist/cjs/llm/anthropic/utils/stream_events.cjs +16 -14
  12. package/dist/cjs/llm/anthropic/utils/stream_events.cjs.map +1 -1
  13. package/dist/cjs/llm/bedrock/index.cjs +1 -1
  14. package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
  15. package/dist/cjs/llm/bedrock/toolCache.cjs +1 -1
  16. package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +19 -13
  17. package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
  18. package/dist/cjs/llm/google/utils/common.cjs +59 -13
  19. package/dist/cjs/llm/google/utils/common.cjs.map +1 -1
  20. package/dist/cjs/llm/init.cjs +12 -2
  21. package/dist/cjs/llm/init.cjs.map +1 -1
  22. package/dist/cjs/llm/openai/index.cjs +1 -1
  23. package/dist/cjs/llm/openrouter/toolCache.cjs +1 -1
  24. package/dist/cjs/llm/prepareProviderRequest.cjs +1 -1
  25. package/dist/cjs/main.cjs +6 -3
  26. package/dist/cjs/messages/alternation.cjs +1 -1
  27. package/dist/cjs/messages/anthropicServerTools.cjs +20 -0
  28. package/dist/cjs/messages/anthropicServerTools.cjs.map +1 -0
  29. package/dist/cjs/messages/budget.cjs +1 -1
  30. package/dist/cjs/messages/core.cjs +3 -2
  31. package/dist/cjs/messages/core.cjs.map +1 -1
  32. package/dist/cjs/messages/format.cjs +2 -2
  33. package/dist/cjs/messages/index.cjs +1 -1
  34. package/dist/cjs/messages/prune.cjs +1 -1
  35. package/dist/cjs/messages/recency.cjs +1 -1
  36. package/dist/cjs/messages/toolResultTypes.cjs +21 -45
  37. package/dist/cjs/messages/toolResultTypes.cjs.map +1 -1
  38. package/dist/cjs/protection/providerText.cjs +4 -0
  39. package/dist/cjs/protection/providerText.cjs.map +1 -1
  40. package/dist/cjs/protection/toolResult.cjs +119 -0
  41. package/dist/cjs/protection/toolResult.cjs.map +1 -0
  42. package/dist/cjs/run.cjs +7 -1
  43. package/dist/cjs/run.cjs.map +1 -1
  44. package/dist/cjs/runtime/client.cjs +2 -0
  45. package/dist/cjs/runtime/client.cjs.map +1 -1
  46. package/dist/cjs/stream.cjs +1 -0
  47. package/dist/cjs/stream.cjs.map +1 -1
  48. package/dist/cjs/summarization/node.cjs +1 -1
  49. package/dist/cjs/tools/ToolNode.cjs +46 -13
  50. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  51. package/dist/cjs/tools/search/content.cjs +163 -42
  52. package/dist/cjs/tools/search/content.cjs.map +1 -1
  53. package/dist/cjs/tools/subagent/SubagentExecutor.cjs +4 -0
  54. package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
  55. package/dist/cjs/utils/tokens.cjs +7 -2
  56. package/dist/cjs/utils/tokens.cjs.map +1 -1
  57. package/dist/esm/graphs/Graph.mjs +11 -3
  58. package/dist/esm/graphs/Graph.mjs.map +1 -1
  59. package/dist/esm/llm/anthropic/index.mjs +4 -3
  60. package/dist/esm/llm/anthropic/index.mjs.map +1 -1
  61. package/dist/esm/llm/anthropic/utils/container.mjs +37 -0
  62. package/dist/esm/llm/anthropic/utils/container.mjs.map +1 -0
  63. package/dist/esm/llm/anthropic/utils/message_inputs.mjs +25 -23
  64. package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
  65. package/dist/esm/llm/anthropic/utils/message_outputs.mjs +15 -21
  66. package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
  67. package/dist/esm/llm/anthropic/utils/stream_events.mjs +16 -14
  68. package/dist/esm/llm/anthropic/utils/stream_events.mjs.map +1 -1
  69. package/dist/esm/llm/bedrock/index.mjs +2 -2
  70. package/dist/esm/llm/bedrock/index.mjs.map +1 -1
  71. package/dist/esm/llm/bedrock/toolCache.mjs +1 -1
  72. package/dist/esm/llm/bedrock/utils/message_inputs.mjs +19 -14
  73. package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -1
  74. package/dist/esm/llm/google/utils/common.mjs +59 -13
  75. package/dist/esm/llm/google/utils/common.mjs.map +1 -1
  76. package/dist/esm/llm/init.mjs +12 -2
  77. package/dist/esm/llm/init.mjs.map +1 -1
  78. package/dist/esm/llm/openai/index.mjs +1 -1
  79. package/dist/esm/llm/openrouter/toolCache.mjs +1 -1
  80. package/dist/esm/llm/prepareProviderRequest.mjs +1 -1
  81. package/dist/esm/main.mjs +5 -4
  82. package/dist/esm/messages/alternation.mjs +1 -1
  83. package/dist/esm/messages/anthropicServerTools.mjs +18 -0
  84. package/dist/esm/messages/anthropicServerTools.mjs.map +1 -0
  85. package/dist/esm/messages/budget.mjs +1 -1
  86. package/dist/esm/messages/core.mjs +3 -2
  87. package/dist/esm/messages/core.mjs.map +1 -1
  88. package/dist/esm/messages/format.mjs +2 -2
  89. package/dist/esm/messages/index.mjs +1 -1
  90. package/dist/esm/messages/prune.mjs +1 -1
  91. package/dist/esm/messages/recency.mjs +1 -1
  92. package/dist/esm/messages/toolResultTypes.mjs +21 -45
  93. package/dist/esm/messages/toolResultTypes.mjs.map +1 -1
  94. package/dist/esm/protection/providerText.mjs +4 -1
  95. package/dist/esm/protection/providerText.mjs.map +1 -1
  96. package/dist/esm/protection/toolResult.mjs +114 -0
  97. package/dist/esm/protection/toolResult.mjs.map +1 -0
  98. package/dist/esm/run.mjs +7 -1
  99. package/dist/esm/run.mjs.map +1 -1
  100. package/dist/esm/runtime/client.mjs +2 -0
  101. package/dist/esm/runtime/client.mjs.map +1 -1
  102. package/dist/esm/stream.mjs +1 -0
  103. package/dist/esm/stream.mjs.map +1 -1
  104. package/dist/esm/summarization/node.mjs +1 -1
  105. package/dist/esm/tools/ToolNode.mjs +46 -13
  106. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  107. package/dist/esm/tools/search/content.mjs +163 -42
  108. package/dist/esm/tools/search/content.mjs.map +1 -1
  109. package/dist/esm/tools/subagent/SubagentExecutor.mjs +4 -0
  110. package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
  111. package/dist/esm/utils/tokens.mjs +7 -2
  112. package/dist/esm/utils/tokens.mjs.map +1 -1
  113. package/dist/types/common/index.d.ts +2 -2
  114. package/dist/types/decisions/breaker.d.ts +2 -2
  115. package/dist/types/decisions/core.d.ts +13 -13
  116. package/dist/types/decisions/dialect.d.ts +1 -1
  117. package/dist/types/decisions/http.d.ts +2 -2
  118. package/dist/types/decisions/index.d.ts +5 -5
  119. package/dist/types/decisions/node.d.ts +2 -2
  120. package/dist/types/decisions/presets.d.ts +2 -2
  121. package/dist/types/decisions/probe.d.ts +1 -1
  122. package/dist/types/decisions/questions.d.ts +1 -1
  123. package/dist/types/decisions/structuredChat.d.ts +2 -2
  124. package/dist/types/decisions/transport.d.ts +1 -1
  125. package/dist/types/eventActor/EventActorExecutor.d.ts +1 -1
  126. package/dist/types/eventActor/index.d.ts +2 -2
  127. package/dist/types/graphs/Graph.d.ts +4 -2
  128. package/dist/types/graphs/MultiAgentGraph.d.ts +1 -1
  129. package/dist/types/graphs/applyGraphRuntimeConfig.d.ts +1 -1
  130. package/dist/types/graphs/graphFactory.d.ts +1 -1
  131. package/dist/types/graphs/index.d.ts +5 -5
  132. package/dist/types/harness/fileBindings.d.ts +2 -2
  133. package/dist/types/harness/fileService.d.ts +2 -2
  134. package/dist/types/harness/fileStream.d.ts +1 -1
  135. package/dist/types/harness/index.d.ts +15 -15
  136. package/dist/types/harness/model.d.ts +1 -1
  137. package/dist/types/harness/modelService.d.ts +2 -2
  138. package/dist/types/harness/modelStreamCallbacks.d.ts +1 -1
  139. package/dist/types/harness/providerText.d.ts +1 -1
  140. package/dist/types/hitl/index.d.ts +3 -3
  141. package/dist/types/hooks/HookRegistry.d.ts +1 -1
  142. package/dist/types/hooks/createToolPolicyHook.d.ts +1 -1
  143. package/dist/types/hooks/createWorkspacePolicyHook.d.ts +1 -1
  144. package/dist/types/hooks/executeHooks.d.ts +2 -2
  145. package/dist/types/hooks/index.d.ts +11 -11
  146. package/dist/types/index.d.ts +62 -60
  147. package/dist/types/langchain/index.d.ts +8 -8
  148. package/dist/types/llm/anthropic/utils/container.d.ts +4 -0
  149. package/dist/types/llm/anthropic/utils/message_inputs.d.ts +1 -1
  150. package/dist/types/llm/anthropic/utils/message_outputs.d.ts +1 -1
  151. package/dist/types/llm/anthropic/utils/stream_events.d.ts +1 -1
  152. package/dist/types/llm/bedrock/index.d.ts +2 -3
  153. package/dist/types/llm/bedrock/utils/harmony.d.ts +1 -1
  154. package/dist/types/llm/bedrock/utils/index.d.ts +2 -2
  155. package/dist/types/llm/bedrock/utils/message_inputs.d.ts +3 -12
  156. package/dist/types/llm/bedrock/utils/message_outputs.d.ts +1 -1
  157. package/dist/types/llm/google/index.d.ts +2 -2
  158. package/dist/types/llm/google/utils/common.d.ts +1 -1
  159. package/dist/types/llm/google/utils/tools.d.ts +1 -1
  160. package/dist/types/llm/openai/index.d.ts +1 -1
  161. package/dist/types/llm/providerRegistry.d.ts +1 -1
  162. package/dist/types/llm/providers.d.ts +1 -1
  163. package/dist/types/messages/anthropicServerTools.d.ts +13 -0
  164. package/dist/types/messages/contextPruning.d.ts +1 -1
  165. package/dist/types/messages/core.d.ts +4 -4
  166. package/dist/types/messages/format.d.ts +1 -1
  167. package/dist/types/messages/index.d.ts +21 -21
  168. package/dist/types/messages/prune.d.ts +1 -1
  169. package/dist/types/openai/index.d.ts +2 -2
  170. package/dist/types/openai/toolProjection.d.ts +1 -1
  171. package/dist/types/prompts/index.d.ts +2 -2
  172. package/dist/types/protection/providerText.d.ts +3 -1
  173. package/dist/types/protection/toolResult.d.ts +69 -0
  174. package/dist/types/provider-registration.d.ts +1 -1
  175. package/dist/types/rerank/bm25.d.ts +1 -1
  176. package/dist/types/rerank/core.d.ts +17 -17
  177. package/dist/types/rerank/crossEncoder.d.ts +3 -3
  178. package/dist/types/rerank/fallback.d.ts +1 -1
  179. package/dist/types/rerank/index.d.ts +2 -2
  180. package/dist/types/rerank/outcome.d.ts +2 -2
  181. package/dist/types/rerank/pin.d.ts +2 -2
  182. package/dist/types/rerank/search.d.ts +1 -1
  183. package/dist/types/rerank/systemone.d.ts +4 -4
  184. package/dist/types/rerank/types.d.ts +1 -1
  185. package/dist/types/run.d.ts +1 -0
  186. package/dist/types/runtime/admission.d.ts +1 -1
  187. package/dist/types/runtime/checkpoint.d.ts +1 -1
  188. package/dist/types/runtime/client.d.ts +2 -2
  189. package/dist/types/runtime/files.d.ts +3 -3
  190. package/dist/types/runtime/hostTools.d.ts +2 -2
  191. package/dist/types/runtime/index.d.ts +12 -12
  192. package/dist/types/runtime/model.d.ts +5 -5
  193. package/dist/types/runtime/policy.d.ts +3 -3
  194. package/dist/types/runtime/recovery/client.d.ts +3 -3
  195. package/dist/types/runtime/recovery/log.d.ts +2 -2
  196. package/dist/types/runtime/recovery/redis.d.ts +1 -1
  197. package/dist/types/runtime/recovery/server.d.ts +3 -3
  198. package/dist/types/runtime/resume.d.ts +1 -1
  199. package/dist/types/runtime/server.d.ts +3 -3
  200. package/dist/types/runtime/snapshot.d.ts +1 -1
  201. package/dist/types/runtime/types.d.ts +2 -2
  202. package/dist/types/session/AgentSession.d.ts +2 -2
  203. package/dist/types/session/JsonlSessionStore.d.ts +1 -1
  204. package/dist/types/session/deriveMessages.d.ts +1 -1
  205. package/dist/types/session/handlers.d.ts +1 -1
  206. package/dist/types/session/index.d.ts +7 -7
  207. package/dist/types/session/messageSerialization.d.ts +1 -1
  208. package/dist/types/session/sessionProjection.d.ts +3 -3
  209. package/dist/types/summarization/index.d.ts +2 -2
  210. package/dist/types/tools/BashProgrammaticToolCalling.d.ts +1 -1
  211. package/dist/types/tools/GitHubCompare.d.ts +6 -6
  212. package/dist/types/tools/ProgrammaticToolCalling.d.ts +1 -1
  213. package/dist/types/tools/ReadFile.d.ts +6 -6
  214. package/dist/types/tools/SkillTool.d.ts +6 -6
  215. package/dist/types/tools/ToolNode.d.ts +5 -1
  216. package/dist/types/tools/cloudflare/index.d.ts +4 -4
  217. package/dist/types/tools/local/FileCheckpointer.d.ts +1 -1
  218. package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -1
  219. package/dist/types/tools/local/attachments.d.ts +1 -1
  220. package/dist/types/tools/local/index.d.ts +12 -12
  221. package/dist/types/tools/search/anthropic.d.ts +1 -1
  222. package/dist/types/tools/search/content.d.ts +38 -1
  223. package/dist/types/tools/search/crw-scraper.d.ts +1 -1
  224. package/dist/types/tools/search/crw-search.d.ts +1 -1
  225. package/dist/types/tools/search/firecrawl.d.ts +1 -1
  226. package/dist/types/tools/search/format.d.ts +1 -1
  227. package/dist/types/tools/search/highlights.d.ts +1 -1
  228. package/dist/types/tools/search/index.d.ts +3 -3
  229. package/dist/types/tools/search/keenable-scraper.d.ts +1 -1
  230. package/dist/types/tools/search/keenable-search.d.ts +1 -1
  231. package/dist/types/tools/search/metrics.d.ts +1 -1
  232. package/dist/types/tools/search/rerankers.d.ts +1 -1
  233. package/dist/types/tools/search/schema.d.ts +6 -6
  234. package/dist/types/tools/search/search.d.ts +1 -1
  235. package/dist/types/tools/search/serper-scraper.d.ts +1 -1
  236. package/dist/types/tools/search/tavily-scraper.d.ts +1 -1
  237. package/dist/types/tools/search/tavily-search.d.ts +1 -1
  238. package/dist/types/tools/search/tool.d.ts +3 -3
  239. package/dist/types/tools/search/types.d.ts +2 -2
  240. package/dist/types/tools/search/utils.d.ts +3 -3
  241. package/dist/types/tools/subagent/SubagentExecutionRegistry.d.ts +1 -1
  242. package/dist/types/tools/subagent/SubagentExecutor.d.ts +6 -3
  243. package/dist/types/tools/subagent/diagnostics.d.ts +1 -1
  244. package/dist/types/tools/subagent/index.d.ts +7 -7
  245. package/dist/types/types/attachments.d.ts +1 -1
  246. package/dist/types/types/graph.d.ts +4 -1
  247. package/dist/types/types/index.d.ts +14 -14
  248. package/dist/types/types/llm.d.ts +2 -2
  249. package/dist/types/types/run.d.ts +3 -1
  250. package/dist/types/types/subagentTasks.d.ts +2 -2
  251. package/dist/types/types/tools.d.ts +6 -3
  252. package/dist/types/utils/index.d.ts +10 -10
  253. package/dist/types/utils/tokens.d.ts +1 -0
  254. package/package.json +3 -2
  255. package/src/graphs/Graph.ts +22 -0
  256. package/src/index.ts +8 -0
  257. package/src/llm/anthropic/index.ts +11 -3
  258. package/src/llm/anthropic/utils/container.ts +63 -0
  259. package/src/llm/anthropic/utils/message_inputs.ts +57 -51
  260. package/src/llm/anthropic/utils/message_outputs.ts +12 -39
  261. package/src/llm/anthropic/utils/stream_events.ts +17 -12
  262. package/src/llm/bedrock/index.ts +7 -5
  263. package/src/llm/bedrock/utils/message_inputs.ts +28 -35
  264. package/src/llm/google/utils/common.ts +88 -36
  265. package/src/llm/init.ts +35 -3
  266. package/src/messages/anthropicServerTools.ts +24 -0
  267. package/src/messages/core.ts +12 -11
  268. package/src/messages/toolResultTypes.ts +80 -88
  269. package/src/protection/providerText.ts +127 -40
  270. package/src/protection/toolResult.ts +272 -0
  271. package/src/run.ts +15 -4
  272. package/src/runtime/client.ts +3 -0
  273. package/src/stream.ts +5 -0
  274. package/src/tools/ToolNode.ts +112 -17
  275. package/src/tools/search/content.ts +282 -62
  276. package/src/tools/subagent/SubagentExecutor.ts +6 -0
  277. package/src/types/graph.ts +3 -0
  278. package/src/types/run.ts +3 -0
  279. package/src/types/tools.ts +3 -0
  280. package/src/utils/tokens.ts +28 -2
@@ -1,13 +1,14 @@
1
1
  import type { RunnableConfig, RunnableToolLike } from '@langchain/core/runnables';
2
2
  import type { StructuredToolInterface } from '@langchain/core/tools';
3
3
  import type { ToolCall } from '@langchain/core/messages/tool';
4
- import type { MessageContentComplex, RunStepResumeState, ToolErrorData } from './stream';
4
+ import type { MessageContentComplex, RunStepResumeState, ToolErrorData } from './stream.js';
5
5
  import type { ToolOutputReferenceRegistry } from '../tools/toolOutputReferences.js';
6
- import type { LangfuseConfig, SubagentExecutionContext } from './graph';
6
+ import type { LangfuseConfig, SubagentExecutionContext } from './graph.js';
7
+ import type { ToolResultProtection } from '../protection/toolResult.js';
7
8
  import type { PreparedSubagents } from '../tools/preparedSubagents.js';
8
9
  import type { RunBreakerScope } from '../llm/streamLimits.js';
9
10
  import type { HandoffRouting } from '../graphs/handoff.js';
10
- import type { HumanInTheLoopConfig } from './hitl';
11
+ import type { HumanInTheLoopConfig } from './hitl.js';
11
12
  import type { HookRegistry } from '../hooks/index.js';
12
13
  /** Replacement type for `import type { ToolCall } from '@langchain/core/messages/tool'` in order to have stringified args typed */
13
14
  export type CustomToolCall = {
@@ -254,6 +255,8 @@ export type ToolNodeOptions = {
254
255
  * precedence over `toolOutputReferences` when both are set.
255
256
  */
256
257
  toolOutputRegistry?: ToolOutputReferenceRegistry;
258
+ /** Host inspection of selected tools' result text; see {@link ToolResultProtection}. */
259
+ toolResultProtection?: ToolResultProtection;
257
260
  /**
258
261
  * Selects where built-in code execution tools run. Defaults to the
259
262
  * remote LibreChat Code API sandbox; `local` swaps those same tool names
@@ -1,10 +1,10 @@
1
- export * from './graph';
2
- export * from './llm';
3
- export * from './misc';
4
- export * from './proxy';
5
- export * from './handlers';
6
- export * from './run';
7
- export * from './tokens';
8
- export * from './schema';
9
- export * from './truncation';
10
- export * from './errors';
1
+ export * from './graph.js';
2
+ export * from './llm.js';
3
+ export * from './misc.js';
4
+ export * from './proxy.js';
5
+ export * from './handlers.js';
6
+ export * from './run.js';
7
+ export * from './tokens.js';
8
+ export * from './schema.js';
9
+ export * from './truncation.js';
10
+ export * from './errors.js';
@@ -38,6 +38,7 @@ export declare function estimateImageBlockTokens(block: Record<string, unknown>,
38
38
  *
39
39
  * - Plain text: tokenized directly via `getTokenCount`.
40
40
  * - Base64 PDF: page count estimated from base64 length × per-page cost.
41
+ * - Other base64 documents: decoded text, or decoded size when binary.
41
42
  * - URL reference: conservative flat estimate.
42
43
  */
43
44
  export declare function estimateDocumentBlockTokens(block: Record<string, unknown>, encoding: EncodingName, getTokenCount: (text: string) => number): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@librechat/agents",
3
- "version": "4.2.12",
3
+ "version": "4.2.13",
4
4
  "reova": {
5
5
  "enabled": true,
6
6
  "endpoint": "https://telemetry.reo.dev/data"
@@ -313,7 +313,8 @@
313
313
  "label:eval": "tsx -r dotenv/config ./src/scripts/activity-labels/run.ts",
314
314
  "label:rescore": "node ./src/scripts/activity-labels/rescore.cjs",
315
315
  "test:runtime-package": "node --test config/runtime-package.test.mjs",
316
- "build:types": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json"
316
+ "test:declaration-extensions": "node --test scripts/fix-dts-extensions.test.mjs",
317
+ "build:types": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && node scripts/fix-dts-extensions.mjs dist/types"
317
318
  },
318
319
  "overrides": {
319
320
  "@langchain/openai": "$@langchain/openai",
@@ -163,6 +163,10 @@ import {
163
163
  getToolContentCharLength,
164
164
  serializeToolContentBounded,
165
165
  } from '@/utils/toolContent';
166
+ import {
167
+ createToolResultGate,
168
+ ToolResultProtectionError,
169
+ } from '@/protection/toolResult';
166
170
  import {
167
171
  appendCallbacks,
168
172
  findCallback,
@@ -1440,6 +1444,8 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
1440
1444
  streamLimits: ResolvedStreamLimits;
1441
1445
  /** Default-off mandatory provider prose release. */
1442
1446
  providerTextProtection?: t.StandardGraphInput['providerTextProtection'];
1447
+ /** Default-off host inspection of selected tools' result text. */
1448
+ toolResultProtection?: t.StandardGraphInput['toolResultProtection'];
1443
1449
  /** Host lookup for attachments carried by reference; read while a provider request is prepared. */
1444
1450
  resolveAttachment?: t.StandardGraphInput['resolveAttachment'];
1445
1451
  /**
@@ -1622,6 +1628,7 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
1622
1628
  preemption,
1623
1629
  streamLimits,
1624
1630
  providerTextProtection,
1631
+ toolResultProtection,
1625
1632
  resolveAttachment,
1626
1633
  toolExecution,
1627
1634
  clientDelegatedToolNames,
@@ -1655,6 +1662,11 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
1655
1662
  if (providerTextProtection != null)
1656
1663
  validateProviderTextProtection(providerTextProtection);
1657
1664
  this.providerTextProtection = providerTextProtection;
1665
+ const toolResultGate =
1666
+ toolResultProtection == null
1667
+ ? undefined
1668
+ : createToolResultGate(toolResultProtection);
1669
+ this.toolResultProtection = toolResultProtection;
1658
1670
  this.resolveAttachment = resolveAttachment;
1659
1671
  this.toolExecution = toolExecution;
1660
1672
  if (
@@ -1667,6 +1679,13 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
1667
1679
  if (clientDelegatedToolNames.some((name) => !name.trim())) {
1668
1680
  throw new Error('Client delegated tool names must be nonempty');
1669
1681
  }
1682
+ if (
1683
+ clientDelegatedToolNames.some(
1684
+ (name) => toolResultGate?.toolNames.has(name) === true
1685
+ )
1686
+ ) {
1687
+ throw new ToolResultProtectionError('unsupported');
1688
+ }
1670
1689
  this.clientDelegatedToolNames = new Set(clientDelegatedToolNames);
1671
1690
  }
1672
1691
 
@@ -3031,6 +3050,7 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
3031
3050
  maxContextTokens: agentContext?.maxContextTokens,
3032
3051
  maxToolResultChars: agentContext?.maxToolResultChars,
3033
3052
  toolOutputRegistry: this.getOrCreateToolOutputRegistry(),
3053
+ toolResultProtection: this.toolResultProtection,
3034
3054
  fileCheckpointer: this.getOrCreateFileCheckpointer(),
3035
3055
  getBreakerSignal: (): AbortSignal => this.breakerAbort.signal,
3036
3056
  getRunScope: (): RunBreakerScope => this.runScope,
@@ -3114,6 +3134,7 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
3114
3134
  maxContextTokens: agentContext?.maxContextTokens,
3115
3135
  maxToolResultChars: agentContext?.maxToolResultChars,
3116
3136
  toolOutputRegistry: this.getOrCreateToolOutputRegistry(),
3137
+ toolResultProtection: this.toolResultProtection,
3117
3138
  fileCheckpointer: this.getOrCreateFileCheckpointer(),
3118
3139
  getBreakerSignal: (): AbortSignal => this.breakerAbort.signal,
3119
3140
  getRunScope: (): RunBreakerScope => this.runScope,
@@ -5449,6 +5470,7 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
5449
5470
  onResolutionFailure: this.onSubagentResolutionFailure,
5450
5471
  streamLimits: this.streamLimits,
5451
5472
  providerTextProtection: this.providerTextProtection,
5473
+ toolResultProtection: this.toolResultProtection,
5452
5474
  resolveAttachment: this.resolveAttachment,
5453
5475
  humanInTheLoop: this.humanInTheLoop,
5454
5476
  checkpointer: this.compileOptions?.checkpointer,
package/src/index.ts CHANGED
@@ -135,6 +135,14 @@ export type {
135
135
  ProviderTextProtectionErrorCode,
136
136
  ProviderTextProtectionFailure,
137
137
  } from './protection/providerText';
138
+ export {
139
+ TOOL_RESULT_PROTECTION_VERSION,
140
+ ToolResultProtectionError,
141
+ } from './protection/toolResult';
142
+ export type {
143
+ ToolResultProtection,
144
+ ToolResultProtectionResult,
145
+ } from './protection/toolResult';
138
146
 
139
147
  export {
140
148
  GEMINI_PARTS,
@@ -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(options);
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(options);
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 === '' && (chunk.usage_metadata != null || chunk.id != null))
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((block) => {
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 block;
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 ?? 'web_search') as 'web_search',
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
- typeof (contentPart as Record<string, unknown>).tool_use_id ===
711
- 'string' &&
712
- (
713
- (contentPart as Record<string, unknown>).tool_use_id as string
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 rawPart = contentPart as Record<string, unknown>;
718
- const content = rawPart.content;
719
- const isValidContent =
720
- Array.isArray(content) ||
721
- (content != null &&
722
- typeof content === 'object' &&
723
- 'type' in content &&
724
- (content as Record<string, unknown>).type ===
725
- 'web_search_tool_result_error');
726
-
727
- if (isValidContent) {
728
- const corrected: AnthropicWebSearchToolResultBlockParam = {
729
- type: 'web_search_tool_result',
730
- tool_use_id: rawPart.tool_use_id as string,
731
- content:
732
- content as AnthropicWebSearchToolResultBlockParam['content'],
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 null;
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
- let args = contentPart.args;
753
- if (typeof args === 'string') {
754
- try {
755
- args = JSON.parse(args);
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
- args: args as Record<string, unknown>,
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
- 'tool_use',
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 contentBlock = data.content_block;
126
- let toolCallChunks: ToolCallChunk[];
127
- if (contentBlock.type === 'tool_use') {
128
- toolCallChunks = [
129
- {
130
- id: contentBlock.id,
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: { model_provider: 'anthropic' },
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: 'server_tool_call_chunk' as const,
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 { type: 'non_standard' as const, value: { ...block }, index };
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
 
@@ -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
- isBedrockOpenAIModel(this.model) ||
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 replays reasoning and sends harmony control tokens as written,
297
- * both of which OpenAI models on Bedrock fail on, and it cannot strip a trailing
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[],