@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.
Files changed (348) hide show
  1. package/dist/cjs/graphs/Graph.cjs +15 -3
  2. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  3. package/dist/cjs/langfuse.cjs +63 -35
  4. package/dist/cjs/langfuse.cjs.map +1 -1
  5. package/dist/cjs/langfuseConfig.cjs +6 -0
  6. package/dist/cjs/langfuseConfig.cjs.map +1 -1
  7. package/dist/cjs/langfuseToolOutputTracing.cjs +1 -1
  8. package/dist/cjs/langfuseToolOutputTracing.cjs.map +1 -1
  9. package/dist/cjs/langfuseTraceShaping.cjs +18 -8
  10. package/dist/cjs/langfuseTraceShaping.cjs.map +1 -1
  11. package/dist/cjs/llm/anthropic/index.cjs +4 -3
  12. package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
  13. package/dist/cjs/llm/anthropic/utils/container.cjs +37 -0
  14. package/dist/cjs/llm/anthropic/utils/container.cjs.map +1 -0
  15. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +25 -23
  16. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
  17. package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +15 -21
  18. package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
  19. package/dist/cjs/llm/anthropic/utils/stream_events.cjs +16 -14
  20. package/dist/cjs/llm/anthropic/utils/stream_events.cjs.map +1 -1
  21. package/dist/cjs/llm/bedrock/index.cjs +1 -1
  22. package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
  23. package/dist/cjs/llm/bedrock/toolCache.cjs +1 -1
  24. package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +19 -13
  25. package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
  26. package/dist/cjs/llm/google/utils/common.cjs +59 -13
  27. package/dist/cjs/llm/google/utils/common.cjs.map +1 -1
  28. package/dist/cjs/llm/init.cjs +12 -2
  29. package/dist/cjs/llm/init.cjs.map +1 -1
  30. package/dist/cjs/llm/openai/index.cjs +15 -2
  31. package/dist/cjs/llm/openai/index.cjs.map +1 -1
  32. package/dist/cjs/llm/openai/responseToolArguments.cjs +62 -0
  33. package/dist/cjs/llm/openai/responseToolArguments.cjs.map +1 -0
  34. package/dist/cjs/llm/openrouter/index.cjs +11 -2
  35. package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
  36. package/dist/cjs/llm/openrouter/toolCache.cjs +1 -1
  37. package/dist/cjs/llm/prepareProviderRequest.cjs +35 -7
  38. package/dist/cjs/llm/prepareProviderRequest.cjs.map +1 -1
  39. package/dist/cjs/main.cjs +9 -3
  40. package/dist/cjs/messages/alternation.cjs +1 -1
  41. package/dist/cjs/messages/anthropicServerTools.cjs +20 -0
  42. package/dist/cjs/messages/anthropicServerTools.cjs.map +1 -0
  43. package/dist/cjs/messages/budget.cjs +1 -1
  44. package/dist/cjs/messages/cache.cjs +14 -1
  45. package/dist/cjs/messages/cache.cjs.map +1 -1
  46. package/dist/cjs/messages/core.cjs +4 -3
  47. package/dist/cjs/messages/core.cjs.map +1 -1
  48. package/dist/cjs/messages/format.cjs +3 -3
  49. package/dist/cjs/messages/index.cjs +1 -1
  50. package/dist/cjs/messages/prune.cjs +1 -1
  51. package/dist/cjs/messages/recency.cjs +1 -1
  52. package/dist/cjs/messages/toolResultTypes.cjs +21 -45
  53. package/dist/cjs/messages/toolResultTypes.cjs.map +1 -1
  54. package/dist/cjs/protection/providerText.cjs +4 -0
  55. package/dist/cjs/protection/providerText.cjs.map +1 -1
  56. package/dist/cjs/protection/toolResult.cjs +119 -0
  57. package/dist/cjs/protection/toolResult.cjs.map +1 -0
  58. package/dist/cjs/run.cjs +31 -13
  59. package/dist/cjs/run.cjs.map +1 -1
  60. package/dist/cjs/runtime/admission.cjs +1 -1
  61. package/dist/cjs/runtime/client.cjs +3 -0
  62. package/dist/cjs/runtime/client.cjs.map +1 -1
  63. package/dist/cjs/stream.cjs +2 -1
  64. package/dist/cjs/stream.cjs.map +1 -1
  65. package/dist/cjs/summarization/node.cjs +9 -4
  66. package/dist/cjs/summarization/node.cjs.map +1 -1
  67. package/dist/cjs/tools/ProgrammaticToolCalling.cjs +1 -1
  68. package/dist/cjs/tools/ToolNode.cjs +47 -14
  69. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  70. package/dist/cjs/tools/local/CompileCheckTool.cjs +1 -1
  71. package/dist/cjs/tools/local/LocalCodingTools.cjs +1 -1
  72. package/dist/cjs/tools/search/content.cjs +163 -42
  73. package/dist/cjs/tools/search/content.cjs.map +1 -1
  74. package/dist/cjs/tools/subagent/SubagentExecutor.cjs +8 -0
  75. package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
  76. package/dist/cjs/utils/events.cjs +2 -2
  77. package/dist/cjs/utils/events.cjs.map +1 -1
  78. package/dist/cjs/utils/tokens.cjs +7 -2
  79. package/dist/cjs/utils/tokens.cjs.map +1 -1
  80. package/dist/esm/graphs/Graph.mjs +15 -3
  81. package/dist/esm/graphs/Graph.mjs.map +1 -1
  82. package/dist/esm/langfuse.mjs +63 -35
  83. package/dist/esm/langfuse.mjs.map +1 -1
  84. package/dist/esm/langfuseConfig.mjs +6 -1
  85. package/dist/esm/langfuseConfig.mjs.map +1 -1
  86. package/dist/esm/langfuseToolOutputTracing.mjs +2 -2
  87. package/dist/esm/langfuseToolOutputTracing.mjs.map +1 -1
  88. package/dist/esm/langfuseTraceShaping.mjs +18 -9
  89. package/dist/esm/langfuseTraceShaping.mjs.map +1 -1
  90. package/dist/esm/llm/anthropic/index.mjs +4 -3
  91. package/dist/esm/llm/anthropic/index.mjs.map +1 -1
  92. package/dist/esm/llm/anthropic/utils/container.mjs +37 -0
  93. package/dist/esm/llm/anthropic/utils/container.mjs.map +1 -0
  94. package/dist/esm/llm/anthropic/utils/message_inputs.mjs +25 -23
  95. package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
  96. package/dist/esm/llm/anthropic/utils/message_outputs.mjs +15 -21
  97. package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
  98. package/dist/esm/llm/anthropic/utils/stream_events.mjs +16 -14
  99. package/dist/esm/llm/anthropic/utils/stream_events.mjs.map +1 -1
  100. package/dist/esm/llm/bedrock/index.mjs +2 -2
  101. package/dist/esm/llm/bedrock/index.mjs.map +1 -1
  102. package/dist/esm/llm/bedrock/toolCache.mjs +1 -1
  103. package/dist/esm/llm/bedrock/utils/message_inputs.mjs +19 -14
  104. package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -1
  105. package/dist/esm/llm/google/utils/common.mjs +59 -13
  106. package/dist/esm/llm/google/utils/common.mjs.map +1 -1
  107. package/dist/esm/llm/init.mjs +12 -2
  108. package/dist/esm/llm/init.mjs.map +1 -1
  109. package/dist/esm/llm/openai/index.mjs +16 -3
  110. package/dist/esm/llm/openai/index.mjs.map +1 -1
  111. package/dist/esm/llm/openai/responseToolArguments.mjs +62 -0
  112. package/dist/esm/llm/openai/responseToolArguments.mjs.map +1 -0
  113. package/dist/esm/llm/openrouter/index.mjs +11 -2
  114. package/dist/esm/llm/openrouter/index.mjs.map +1 -1
  115. package/dist/esm/llm/openrouter/toolCache.mjs +1 -1
  116. package/dist/esm/llm/prepareProviderRequest.mjs +35 -7
  117. package/dist/esm/llm/prepareProviderRequest.mjs.map +1 -1
  118. package/dist/esm/main.mjs +5 -4
  119. package/dist/esm/messages/alternation.mjs +1 -1
  120. package/dist/esm/messages/anthropicServerTools.mjs +18 -0
  121. package/dist/esm/messages/anthropicServerTools.mjs.map +1 -0
  122. package/dist/esm/messages/budget.mjs +1 -1
  123. package/dist/esm/messages/cache.mjs +12 -2
  124. package/dist/esm/messages/cache.mjs.map +1 -1
  125. package/dist/esm/messages/core.mjs +4 -3
  126. package/dist/esm/messages/core.mjs.map +1 -1
  127. package/dist/esm/messages/format.mjs +3 -3
  128. package/dist/esm/messages/index.mjs +1 -1
  129. package/dist/esm/messages/prune.mjs +1 -1
  130. package/dist/esm/messages/recency.mjs +1 -1
  131. package/dist/esm/messages/toolResultTypes.mjs +21 -45
  132. package/dist/esm/messages/toolResultTypes.mjs.map +1 -1
  133. package/dist/esm/protection/providerText.mjs +4 -1
  134. package/dist/esm/protection/providerText.mjs.map +1 -1
  135. package/dist/esm/protection/toolResult.mjs +114 -0
  136. package/dist/esm/protection/toolResult.mjs.map +1 -0
  137. package/dist/esm/run.mjs +32 -14
  138. package/dist/esm/run.mjs.map +1 -1
  139. package/dist/esm/runtime/admission.mjs +1 -1
  140. package/dist/esm/runtime/client.mjs +3 -0
  141. package/dist/esm/runtime/client.mjs.map +1 -1
  142. package/dist/esm/stream.mjs +2 -1
  143. package/dist/esm/stream.mjs.map +1 -1
  144. package/dist/esm/summarization/node.mjs +9 -4
  145. package/dist/esm/summarization/node.mjs.map +1 -1
  146. package/dist/esm/tools/ProgrammaticToolCalling.mjs +1 -1
  147. package/dist/esm/tools/ToolNode.mjs +47 -14
  148. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  149. package/dist/esm/tools/local/CompileCheckTool.mjs +1 -1
  150. package/dist/esm/tools/local/LocalCodingTools.mjs +1 -1
  151. package/dist/esm/tools/search/content.mjs +163 -42
  152. package/dist/esm/tools/search/content.mjs.map +1 -1
  153. package/dist/esm/tools/subagent/SubagentExecutor.mjs +8 -0
  154. package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
  155. package/dist/esm/utils/events.mjs +2 -2
  156. package/dist/esm/utils/events.mjs.map +1 -1
  157. package/dist/esm/utils/tokens.mjs +7 -2
  158. package/dist/esm/utils/tokens.mjs.map +1 -1
  159. package/dist/types/common/index.d.ts +2 -2
  160. package/dist/types/decisions/breaker.d.ts +2 -2
  161. package/dist/types/decisions/core.d.ts +13 -13
  162. package/dist/types/decisions/dialect.d.ts +1 -1
  163. package/dist/types/decisions/http.d.ts +2 -2
  164. package/dist/types/decisions/index.d.ts +5 -5
  165. package/dist/types/decisions/node.d.ts +2 -2
  166. package/dist/types/decisions/presets.d.ts +2 -2
  167. package/dist/types/decisions/probe.d.ts +1 -1
  168. package/dist/types/decisions/questions.d.ts +1 -1
  169. package/dist/types/decisions/structuredChat.d.ts +2 -2
  170. package/dist/types/decisions/transport.d.ts +1 -1
  171. package/dist/types/eventActor/EventActorExecutor.d.ts +1 -1
  172. package/dist/types/eventActor/index.d.ts +2 -2
  173. package/dist/types/graphs/Graph.d.ts +6 -2
  174. package/dist/types/graphs/MultiAgentGraph.d.ts +1 -1
  175. package/dist/types/graphs/applyGraphRuntimeConfig.d.ts +1 -1
  176. package/dist/types/graphs/graphFactory.d.ts +1 -1
  177. package/dist/types/graphs/index.d.ts +5 -5
  178. package/dist/types/harness/fileBindings.d.ts +2 -2
  179. package/dist/types/harness/fileService.d.ts +2 -2
  180. package/dist/types/harness/fileStream.d.ts +1 -1
  181. package/dist/types/harness/index.d.ts +15 -15
  182. package/dist/types/harness/model.d.ts +1 -1
  183. package/dist/types/harness/modelService.d.ts +2 -2
  184. package/dist/types/harness/modelStreamCallbacks.d.ts +1 -1
  185. package/dist/types/harness/providerText.d.ts +1 -1
  186. package/dist/types/hitl/index.d.ts +3 -3
  187. package/dist/types/hooks/HookRegistry.d.ts +1 -1
  188. package/dist/types/hooks/createToolPolicyHook.d.ts +1 -1
  189. package/dist/types/hooks/createWorkspacePolicyHook.d.ts +1 -1
  190. package/dist/types/hooks/executeHooks.d.ts +2 -2
  191. package/dist/types/hooks/index.d.ts +11 -11
  192. package/dist/types/index.d.ts +62 -60
  193. package/dist/types/langchain/index.d.ts +8 -8
  194. package/dist/types/langfuse.d.ts +7 -4
  195. package/dist/types/langfuseConfig.d.ts +5 -0
  196. package/dist/types/langfuseTraceShaping.d.ts +5 -0
  197. package/dist/types/llm/anthropic/utils/container.d.ts +4 -0
  198. package/dist/types/llm/anthropic/utils/message_inputs.d.ts +1 -1
  199. package/dist/types/llm/anthropic/utils/message_outputs.d.ts +1 -1
  200. package/dist/types/llm/anthropic/utils/stream_events.d.ts +1 -1
  201. package/dist/types/llm/bedrock/index.d.ts +2 -3
  202. package/dist/types/llm/bedrock/utils/harmony.d.ts +1 -1
  203. package/dist/types/llm/bedrock/utils/index.d.ts +2 -2
  204. package/dist/types/llm/bedrock/utils/message_inputs.d.ts +3 -12
  205. package/dist/types/llm/bedrock/utils/message_outputs.d.ts +1 -1
  206. package/dist/types/llm/google/index.d.ts +2 -2
  207. package/dist/types/llm/google/utils/common.d.ts +1 -1
  208. package/dist/types/llm/google/utils/tools.d.ts +1 -1
  209. package/dist/types/llm/openai/index.d.ts +2 -1
  210. package/dist/types/llm/openai/responseToolArguments.d.ts +7 -0
  211. package/dist/types/llm/openrouter/index.d.ts +1 -0
  212. package/dist/types/llm/prepareProviderRequest.d.ts +4 -1
  213. package/dist/types/llm/providerRegistry.d.ts +1 -1
  214. package/dist/types/llm/providers.d.ts +1 -1
  215. package/dist/types/messages/anthropicServerTools.d.ts +13 -0
  216. package/dist/types/messages/cache.d.ts +13 -0
  217. package/dist/types/messages/contextPruning.d.ts +1 -1
  218. package/dist/types/messages/core.d.ts +4 -4
  219. package/dist/types/messages/format.d.ts +1 -1
  220. package/dist/types/messages/index.d.ts +21 -21
  221. package/dist/types/messages/prune.d.ts +1 -1
  222. package/dist/types/openai/index.d.ts +2 -2
  223. package/dist/types/openai/toolProjection.d.ts +1 -1
  224. package/dist/types/prompts/index.d.ts +2 -2
  225. package/dist/types/protection/providerText.d.ts +3 -1
  226. package/dist/types/protection/toolResult.d.ts +69 -0
  227. package/dist/types/provider-registration.d.ts +1 -1
  228. package/dist/types/rerank/bm25.d.ts +1 -1
  229. package/dist/types/rerank/core.d.ts +17 -17
  230. package/dist/types/rerank/crossEncoder.d.ts +3 -3
  231. package/dist/types/rerank/fallback.d.ts +1 -1
  232. package/dist/types/rerank/index.d.ts +2 -2
  233. package/dist/types/rerank/outcome.d.ts +2 -2
  234. package/dist/types/rerank/pin.d.ts +2 -2
  235. package/dist/types/rerank/search.d.ts +1 -1
  236. package/dist/types/rerank/systemone.d.ts +4 -4
  237. package/dist/types/rerank/types.d.ts +1 -1
  238. package/dist/types/run.d.ts +2 -0
  239. package/dist/types/runtime/admission.d.ts +1 -1
  240. package/dist/types/runtime/checkpoint.d.ts +1 -1
  241. package/dist/types/runtime/client.d.ts +2 -2
  242. package/dist/types/runtime/files.d.ts +4 -4
  243. package/dist/types/runtime/hostTools.d.ts +2 -2
  244. package/dist/types/runtime/index.d.ts +12 -12
  245. package/dist/types/runtime/model.d.ts +5 -5
  246. package/dist/types/runtime/policy.d.ts +3 -3
  247. package/dist/types/runtime/recovery/client.d.ts +3 -3
  248. package/dist/types/runtime/recovery/log.d.ts +2 -2
  249. package/dist/types/runtime/recovery/redis.d.ts +1 -1
  250. package/dist/types/runtime/recovery/server.d.ts +3 -3
  251. package/dist/types/runtime/resume.d.ts +1 -1
  252. package/dist/types/runtime/server.d.ts +3 -3
  253. package/dist/types/runtime/snapshot.d.ts +1 -1
  254. package/dist/types/runtime/types.d.ts +2 -2
  255. package/dist/types/session/AgentSession.d.ts +2 -2
  256. package/dist/types/session/JsonlSessionStore.d.ts +1 -1
  257. package/dist/types/session/deriveMessages.d.ts +1 -1
  258. package/dist/types/session/handlers.d.ts +1 -1
  259. package/dist/types/session/index.d.ts +7 -7
  260. package/dist/types/session/messageSerialization.d.ts +1 -1
  261. package/dist/types/session/sessionProjection.d.ts +3 -3
  262. package/dist/types/summarization/index.d.ts +2 -2
  263. package/dist/types/summarization/node.d.ts +2 -0
  264. package/dist/types/tools/BashProgrammaticToolCalling.d.ts +1 -1
  265. package/dist/types/tools/GitHubCompare.d.ts +6 -6
  266. package/dist/types/tools/ProgrammaticToolCalling.d.ts +1 -1
  267. package/dist/types/tools/ReadFile.d.ts +6 -6
  268. package/dist/types/tools/SkillTool.d.ts +6 -6
  269. package/dist/types/tools/ToolNode.d.ts +5 -1
  270. package/dist/types/tools/cloudflare/index.d.ts +4 -4
  271. package/dist/types/tools/local/FileCheckpointer.d.ts +1 -1
  272. package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -1
  273. package/dist/types/tools/local/attachments.d.ts +1 -1
  274. package/dist/types/tools/local/index.d.ts +12 -12
  275. package/dist/types/tools/search/anthropic.d.ts +1 -1
  276. package/dist/types/tools/search/content.d.ts +38 -1
  277. package/dist/types/tools/search/crw-scraper.d.ts +1 -1
  278. package/dist/types/tools/search/crw-search.d.ts +1 -1
  279. package/dist/types/tools/search/firecrawl.d.ts +1 -1
  280. package/dist/types/tools/search/format.d.ts +1 -1
  281. package/dist/types/tools/search/highlights.d.ts +1 -1
  282. package/dist/types/tools/search/index.d.ts +3 -3
  283. package/dist/types/tools/search/keenable-scraper.d.ts +1 -1
  284. package/dist/types/tools/search/keenable-search.d.ts +1 -1
  285. package/dist/types/tools/search/metrics.d.ts +1 -1
  286. package/dist/types/tools/search/rerankers.d.ts +1 -1
  287. package/dist/types/tools/search/schema.d.ts +6 -6
  288. package/dist/types/tools/search/search.d.ts +1 -1
  289. package/dist/types/tools/search/serper-scraper.d.ts +1 -1
  290. package/dist/types/tools/search/tavily-scraper.d.ts +1 -1
  291. package/dist/types/tools/search/tavily-search.d.ts +1 -1
  292. package/dist/types/tools/search/tool.d.ts +3 -3
  293. package/dist/types/tools/search/types.d.ts +2 -2
  294. package/dist/types/tools/search/utils.d.ts +3 -3
  295. package/dist/types/tools/subagent/SubagentExecutionRegistry.d.ts +1 -1
  296. package/dist/types/tools/subagent/SubagentExecutor.d.ts +9 -3
  297. package/dist/types/tools/subagent/diagnostics.d.ts +1 -1
  298. package/dist/types/tools/subagent/index.d.ts +7 -7
  299. package/dist/types/types/attachments.d.ts +25 -0
  300. package/dist/types/types/graph.d.ts +15 -0
  301. package/dist/types/types/index.d.ts +14 -13
  302. package/dist/types/types/llm.d.ts +2 -2
  303. package/dist/types/types/run.d.ts +7 -2
  304. package/dist/types/types/subagentTasks.d.ts +2 -2
  305. package/dist/types/types/tools.d.ts +6 -3
  306. package/dist/types/utils/events.d.ts +2 -1
  307. package/dist/types/utils/index.d.ts +10 -10
  308. package/dist/types/utils/tokens.d.ts +1 -0
  309. package/package.json +14 -12
  310. package/src/graphs/Graph.ts +32 -1
  311. package/src/index.ts +8 -0
  312. package/src/langfuse.ts +129 -41
  313. package/src/langfuseConfig.ts +14 -0
  314. package/src/langfuseToolOutputTracing.ts +5 -4
  315. package/src/langfuseTraceShaping.ts +49 -12
  316. package/src/llm/anthropic/index.ts +11 -3
  317. package/src/llm/anthropic/utils/container.ts +63 -0
  318. package/src/llm/anthropic/utils/message_inputs.ts +57 -51
  319. package/src/llm/anthropic/utils/message_outputs.ts +12 -39
  320. package/src/llm/anthropic/utils/stream_events.ts +17 -12
  321. package/src/llm/bedrock/index.ts +7 -5
  322. package/src/llm/bedrock/utils/message_inputs.ts +28 -35
  323. package/src/llm/google/utils/common.ts +88 -36
  324. package/src/llm/init.ts +35 -3
  325. package/src/llm/openai/index.ts +17 -2
  326. package/src/llm/openai/responseToolArguments.ts +104 -0
  327. package/src/llm/openrouter/index.ts +13 -0
  328. package/src/llm/prepareProviderRequest.ts +75 -13
  329. package/src/messages/anthropicServerTools.ts +24 -0
  330. package/src/messages/cache.ts +25 -5
  331. package/src/messages/core.ts +12 -11
  332. package/src/messages/toolResultTypes.ts +80 -88
  333. package/src/protection/providerText.ts +127 -40
  334. package/src/protection/toolResult.ts +272 -0
  335. package/src/run.ts +112 -47
  336. package/src/runtime/client.ts +7 -0
  337. package/src/stream.ts +7 -1
  338. package/src/summarization/node.ts +17 -4
  339. package/src/tools/ToolNode.ts +114 -18
  340. package/src/tools/search/content.ts +282 -62
  341. package/src/tools/subagent/SubagentExecutor.ts +12 -0
  342. package/src/types/attachments.ts +31 -0
  343. package/src/types/graph.ts +12 -0
  344. package/src/types/index.ts +1 -0
  345. package/src/types/run.ts +8 -1
  346. package/src/types/tools.ts +3 -0
  347. package/src/utils/events.ts +9 -2
  348. package/src/utils/tokens.ts +28 -2
@@ -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
@@ -79,6 +79,7 @@ import {
79
79
  hasToolOutputTracingConfig,
80
80
  resolveLangfuseConfig,
81
81
  resolveToolOutputTracingConfig,
82
+ withoutSkillsAvailable,
82
83
  } from '@/langfuseConfig';
83
84
  import {
84
85
  cloneToolApprovalInterruptPayload,
@@ -111,6 +112,7 @@ import { ProviderTextProtectionError } from '@/protection/providerText';
111
112
  import { LANGFUSE_OPERATION_METADATA_KEY } from '@/langfuseOperation';
112
113
  import { createTokenCounter, encodingForModel } from '@/utils/tokens';
113
114
  import { stampSyntheticProviderMessage } from '@/messages/provenance';
115
+ import { ToolResultProtectionError } from '@/protection/toolResult';
114
116
  import { isOpenAILike, isLibreChatOpenAIModel } from '@/utils/llm';
115
117
  import { executeHooks, mergeAggregatedHookResults } from '@/hooks';
116
118
  import { convertInjectedMessages } from '@/messages/injected';
@@ -396,9 +398,13 @@ async function resolveCompletedSegmentConfig(
396
398
  );
397
399
  }
398
400
 
399
- function getFirstPersistedInterrupt(
400
- snapshot: InterruptStateSnapshot
401
- ): { id: string; value: unknown; pending: Array<{ id: string; value: unknown }> } | undefined {
401
+ function getFirstPersistedInterrupt(snapshot: InterruptStateSnapshot):
402
+ | {
403
+ id: string;
404
+ value: unknown;
405
+ pending: Array<{ id: string; value: unknown }>;
406
+ }
407
+ | undefined {
402
408
  const pending: Array<{ id: string; value: unknown }> = [];
403
409
  const nestedStates: InterruptStateSnapshot[] = [];
404
410
  const next = snapshot.next == null ? undefined : new Set(snapshot.next);
@@ -410,7 +416,11 @@ function getFirstPersistedInterrupt(
410
416
  }
411
417
  }
412
418
  const nestedState = task.state;
413
- if (nestedState != null && 'tasks' in nestedState && Array.isArray(nestedState.tasks)) {
419
+ if (
420
+ nestedState != null &&
421
+ 'tasks' in nestedState &&
422
+ Array.isArray(nestedState.tasks)
423
+ ) {
414
424
  nestedStates.push(nestedState);
415
425
  }
416
426
  }
@@ -418,7 +428,9 @@ function getFirstPersistedInterrupt(
418
428
  const nested = getFirstPersistedInterrupt(nestedState);
419
429
  if (nested != null) pending.push(...nested.pending);
420
430
  }
421
- const unique = [...new Map(pending.map((entry) => [entry.id, entry])).values()];
431
+ const unique = [
432
+ ...new Map(pending.map((entry) => [entry.id, entry])).values(),
433
+ ];
422
434
  return unique.length === 0 ? undefined : { ...unique[0], pending: unique };
423
435
  }
424
436
 
@@ -498,6 +510,8 @@ export class Run<_T extends t.BaseGraphState> {
498
510
  private preemption?: t.StreamPreemption;
499
511
  private maxStopContinuations: number;
500
512
  private providerTextProtection?: t.StandardGraphInput['providerTextProtection'];
513
+ private toolResultProtection?: t.StandardGraphInput['toolResultProtection'];
514
+ private resolveAttachment?: t.StandardGraphInput['resolveAttachment'];
501
515
  private streamLimits?: t.StreamLimits;
502
516
  private subagentTasks?: t.SubagentTaskConfig;
503
517
  private subagentContext?: t.SubagentContextAdapter;
@@ -578,7 +592,9 @@ export class Run<_T extends t.BaseGraphState> {
578
592
  (config.clientDelegatedToolNames?.length ?? 0) > 0 &&
579
593
  handlerRegistry.getHandler(GraphEvents.ON_MODEL_RESPONSE) == null
580
594
  ) {
581
- throw new Error('Client tool delegation requires an accepted-result handler');
595
+ throw new Error(
596
+ 'Client tool delegation requires an accepted-result handler'
597
+ );
582
598
  }
583
599
  this.handlerRegistry = handlerRegistry;
584
600
  this.hookRegistry = config.hooks;
@@ -600,18 +616,31 @@ export class Run<_T extends t.BaseGraphState> {
600
616
  );
601
617
  this.streamLimits = config.streamLimits;
602
618
  this.providerTextProtection = config.providerTextProtection;
619
+ this.toolResultProtection = config.toolResultProtection;
620
+ this.resolveAttachment = config.resolveAttachment;
603
621
 
604
622
  if (!config.graphConfig) {
605
623
  throw new Error('Graph config not provided');
606
624
  }
607
- if ('providerTextProtection' in config.graphConfig &&
608
- config.graphConfig.providerTextProtection != null) {
625
+ if (
626
+ 'providerTextProtection' in config.graphConfig &&
627
+ config.graphConfig.providerTextProtection != null
628
+ ) {
609
629
  throw new ProviderTextProtectionError('incompatible');
610
630
  }
631
+ if (
632
+ 'toolResultProtection' in config.graphConfig &&
633
+ config.graphConfig.toolResultProtection != null
634
+ ) {
635
+ throw new ToolResultProtectionError('incompatible');
636
+ }
611
637
 
612
638
  /** Handle different graph types */
613
639
  if (config.graphConfig.type === 'multi-agent') {
614
- if (this.clientDelegatedToolNames != null && this.clientDelegatedToolNames.length > 0) {
640
+ if (
641
+ this.clientDelegatedToolNames != null &&
642
+ this.clientDelegatedToolNames.length > 0
643
+ ) {
615
644
  throw new Error('Client tool delegation requires a single-agent graph');
616
645
  }
617
646
  this.graphRunnable = this.createMultiAgentGraph(config.graphConfig);
@@ -705,6 +734,8 @@ export class Run<_T extends t.BaseGraphState> {
705
734
  preemption: this.preemption,
706
735
  streamLimits: this.streamLimits,
707
736
  providerTextProtection: this.providerTextProtection,
737
+ toolResultProtection: this.toolResultProtection,
738
+ resolveAttachment: this.resolveAttachment,
708
739
  toolExecution: this.toolExecution,
709
740
  clientDelegatedToolNames: this.clientDelegatedToolNames,
710
741
  },
@@ -753,6 +784,8 @@ export class Run<_T extends t.BaseGraphState> {
753
784
  preemption: this.preemption,
754
785
  streamLimits: this.streamLimits,
755
786
  providerTextProtection: this.providerTextProtection,
787
+ toolResultProtection: this.toolResultProtection,
788
+ resolveAttachment: this.resolveAttachment,
756
789
  toolExecution: this.toolExecution,
757
790
  },
758
791
  });
@@ -1108,7 +1141,8 @@ export class Run<_T extends t.BaseGraphState> {
1108
1141
  if (
1109
1142
  eventName === GraphEvents.ON_MODEL_RESPONSE ||
1110
1143
  eventName === GraphEvents.ON_MODEL_TOOLS_CLAIMED
1111
- ) return;
1144
+ )
1145
+ return;
1112
1146
  const handler = this.handlerRegistry?.getHandler(eventName);
1113
1147
  /**
1114
1148
  * Tool completions arriving over the custom-event channel are the only
@@ -1599,18 +1633,20 @@ export class Run<_T extends t.BaseGraphState> {
1599
1633
  continue;
1600
1634
  }
1601
1635
 
1602
- if (
1603
- data.chunk != null &&
1604
- isInterrupted<unknown>(data.chunk)
1605
- ) {
1636
+ if (data.chunk != null && isInterrupted<unknown>(data.chunk)) {
1606
1637
  const interrupts = data.chunk[INTERRUPT];
1607
1638
  if (interrupts.length > 0) {
1608
1639
  const pending = new Map(
1609
- (this._interrupt?.pendingInterrupts ?? []).map((entry) => [entry.interruptId, entry])
1640
+ (this._interrupt?.pendingInterrupts ?? []).map((entry) => [
1641
+ entry.interruptId,
1642
+ entry,
1643
+ ])
1610
1644
  );
1611
- for (const entry of interrupts) pending.set(entry.id ?? '', {
1612
- interruptId: entry.id ?? '', payload: entry.value,
1613
- });
1645
+ for (const entry of interrupts)
1646
+ pending.set(entry.id ?? '', {
1647
+ interruptId: entry.id ?? '',
1648
+ payload: entry.value,
1649
+ });
1614
1650
  const first = this._interrupt ?? {
1615
1651
  interruptId: interrupts[0].id ?? '',
1616
1652
  payload: cloneToolApprovalInterruptPayload(interrupts[0].value),
@@ -1628,7 +1664,8 @@ export class Run<_T extends t.BaseGraphState> {
1628
1664
  if (
1629
1665
  eventName === GraphEvents.ON_MODEL_RESPONSE ||
1630
1666
  eventName === GraphEvents.ON_MODEL_TOOLS_CLAIMED
1631
- ) continue;
1667
+ )
1668
+ continue;
1632
1669
  const handler = this.handlerRegistry?.getHandler(eventName);
1633
1670
  if (handler) {
1634
1671
  await handler.handle(eventName, data, metadata, this.Graph);
@@ -1975,10 +2012,12 @@ export class Run<_T extends t.BaseGraphState> {
1975
2012
  pending: NonNullable<t.RunInterruptResult<unknown>['pendingInterrupts']>;
1976
2013
  ids: Set<string>;
1977
2014
  } {
1978
- const roots = this._interrupt?.pendingInterrupts ??
2015
+ const roots =
2016
+ this._interrupt?.pendingInterrupts ??
1979
2017
  (this._interrupt == null ? [] : [this._interrupt]);
1980
2018
  const pending = new Map<
1981
- string, Pick<t.RunInterruptResult<unknown>, 'interruptId' | 'payload'>
2019
+ string,
2020
+ Pick<t.RunInterruptResult<unknown>, 'interruptId' | 'payload'>
1982
2021
  >();
1983
2022
  const ids = new Set<string>();
1984
2023
  const executions: SubagentResumeManifest['executions'] = [];
@@ -2038,7 +2077,9 @@ export class Run<_T extends t.BaseGraphState> {
2038
2077
  ),
2039
2078
  pendingInterrupts: pending.map((pending) => ({
2040
2079
  interruptId: pending.interruptId,
2041
- payload: cloneToolApprovalInterruptPayload(getPublicToolInterruptPayload(pending.payload)),
2080
+ payload: cloneToolApprovalInterruptPayload(
2081
+ getPublicToolInterruptPayload(pending.payload)
2082
+ ),
2042
2083
  })),
2043
2084
  } as t.RunInterruptResult<TPayload>;
2044
2085
  }
@@ -2186,14 +2227,20 @@ export class Run<_T extends t.BaseGraphState> {
2186
2227
  );
2187
2228
  return;
2188
2229
  }
2189
- const addressed = new Set(pending.flatMap((entry) =>
2190
- resumeValue != null && typeof resumeValue === 'object' &&
2230
+ const addressed = new Set(
2231
+ pending.flatMap((entry) =>
2232
+ resumeValue != null &&
2233
+ typeof resumeValue === 'object' &&
2191
2234
  Object.prototype.hasOwnProperty.call(resumeValue, entry.interruptId)
2192
- ? [entry.interruptId] : []
2193
- ));
2194
- if (addressed.size === 0 && interrupt != null) addressed.add(interrupt.interruptId);
2235
+ ? [entry.interruptId]
2236
+ : []
2237
+ )
2238
+ );
2239
+ if (addressed.size === 0 && interrupt != null)
2240
+ addressed.add(interrupt.interruptId);
2195
2241
  const scope = getToolBatchReplayScope({ configurable }) ?? '';
2196
- const thread = typeof configurable.thread_id === 'string' ? configurable.thread_id : '';
2242
+ const thread =
2243
+ typeof configurable.thread_id === 'string' ? configurable.thread_id : '';
2197
2244
  restoreToolReplayConfigs(
2198
2245
  configurable,
2199
2246
  pending.map((entry) => ({ id: entry.interruptId, value: entry.payload })),
@@ -2259,14 +2306,19 @@ export class Run<_T extends t.BaseGraphState> {
2259
2306
  .map((entry) => getInterruptHookSessionId(entry.payload))
2260
2307
  .filter((id): id is string => id != null)
2261
2308
  );
2262
- for (const hookSessionId of hookSessions) this.hookRegistry?.copySession(hookSessionId, this.id);
2309
+ for (const hookSessionId of hookSessions)
2310
+ this.hookRegistry?.copySession(hookSessionId, this.id);
2263
2311
  const interruptId = interrupt?.interruptId;
2264
2312
  const workflow = this.graphRunnable as
2265
2313
  | (t.CompiledStateWorkflow & WorkflowWithStateHistory)
2266
2314
  | undefined;
2267
2315
  const stateHistory = workflow?.getStateHistory;
2268
2316
  if (interrupt?.checkpointId != null && interrupt.checkpointId.length > 0) {
2269
- return this.selectInterruptCheckpoint(manifestConfig, interrupt.checkpointId, interrupt.checkpointNs);
2317
+ return this.selectInterruptCheckpoint(
2318
+ manifestConfig,
2319
+ interrupt.checkpointId,
2320
+ interrupt.checkpointNs
2321
+ );
2270
2322
  }
2271
2323
  if (
2272
2324
  interrupt == null ||
@@ -2357,7 +2409,10 @@ export class Run<_T extends t.BaseGraphState> {
2357
2409
  this._interrupt = {
2358
2410
  interruptId: persistedInterrupt.id,
2359
2411
  payload: cloneToolApprovalInterruptPayload(persistedInterrupt.value),
2360
- pendingInterrupts: persistedInterrupt.pending.map((entry) => ({ interruptId: entry.id, payload: entry.value })),
2412
+ pendingInterrupts: persistedInterrupt.pending.map((entry) => ({
2413
+ interruptId: entry.id,
2414
+ payload: entry.value,
2415
+ })),
2361
2416
  ...(typeof threadId === 'string' ? { threadId } : {}),
2362
2417
  ...(typeof checkpointId === 'string' ? { checkpointId } : {}),
2363
2418
  ...(typeof checkpointNs === 'string' ? { checkpointNs } : {}),
@@ -2411,9 +2466,11 @@ export class Run<_T extends t.BaseGraphState> {
2411
2466
  this.Graph == null
2412
2467
  ? undefined
2413
2468
  : this.Graph.agentContexts.get(this.Graph.defaultAgentId);
2469
+ const titleRunLangfuse = withoutSkillsAvailable(this.langfuse);
2470
+ const titleLangfuseOverlay = withoutSkillsAvailable(titleContext?.langfuse);
2414
2471
  const titleLangfuseConfig = resolveLangfuseConfig(
2415
- this.langfuse,
2416
- titleContext?.langfuse
2472
+ titleRunLangfuse,
2473
+ titleLangfuseOverlay
2417
2474
  );
2418
2475
  const traceMetadata = createLangfuseTraceMetadata({
2419
2476
  messageId: 'title-' + this.id,
@@ -2432,8 +2489,8 @@ export class Run<_T extends t.BaseGraphState> {
2432
2489
  * parent seed is live; otherwise unseeded, matching the other paths. */
2433
2490
  const inheritedTraceSeed = getTraceIdSeed();
2434
2491
  const titleRuntimeScope = resolveLangfuseRuntimeScope({
2435
- runLangfuse: this.langfuse,
2436
- langfuseOverlay: titleContext?.langfuse,
2492
+ runLangfuse: titleRunLangfuse,
2493
+ langfuseOverlay: titleLangfuseOverlay,
2437
2494
  traceIdSeed:
2438
2495
  titleLangfuseConfig?.deterministicTraceId === true ||
2439
2496
  inheritedTraceSeed != null
@@ -2681,9 +2738,11 @@ export class Run<_T extends t.BaseGraphState> {
2681
2738
  };
2682
2739
  const labelRunName = labelChainOptions.runName ?? ACTIVITY_LABEL_TRACE_NAME;
2683
2740
  const labelTags = ['librechat', 'activity-label'];
2741
+ const labelRunLangfuse = withoutSkillsAvailable(this.langfuse);
2742
+ const labelLangfuseOverlay = withoutSkillsAvailable(labelContext?.langfuse);
2684
2743
  const labelLangfuseConfig = resolveLangfuseConfig(
2685
- this.langfuse,
2686
- labelContext?.langfuse
2744
+ labelRunLangfuse,
2745
+ labelLangfuseOverlay
2687
2746
  );
2688
2747
  initializeLangfuseTracing(labelLangfuseConfig);
2689
2748
  /** A captured source observation parents the label in the agent trace.
@@ -2698,8 +2757,8 @@ export class Run<_T extends t.BaseGraphState> {
2698
2757
  /** Opaque per-execution component: see `titleScopeRunId`. */
2699
2758
  const labelScopeRunId = `activity-label:${this.id}:${labelSeq}:${nanoid()}`;
2700
2759
  const labelRuntimeScope = resolveLangfuseRuntimeScope({
2701
- runLangfuse: this.langfuse,
2702
- langfuseOverlay: labelContext?.langfuse,
2760
+ runLangfuse: labelRunLangfuse,
2761
+ langfuseOverlay: labelLangfuseOverlay,
2703
2762
  traceIdSeed: labelTraceSeed,
2704
2763
  runId: labelScopeRunId,
2705
2764
  });
@@ -3031,10 +3090,14 @@ export class Run<_T extends t.BaseGraphState> {
3031
3090
  const reasoningRunName =
3032
3091
  reasoningChainOptions.runName ?? REASONING_LABEL_TRACE_NAME;
3033
3092
  const reasoningTags = ['librechat', 'reasoning-label', 'reasoning-step'];
3034
- const reasoningLangfuseConfig = resolveLangfuseConfig(
3035
- this.langfuse,
3093
+ const reasoningRunLangfuse = withoutSkillsAvailable(this.langfuse);
3094
+ const reasoningLangfuseOverlay = withoutSkillsAvailable(
3036
3095
  reasoningContext?.langfuse
3037
3096
  );
3097
+ const reasoningLangfuseConfig = resolveLangfuseConfig(
3098
+ reasoningRunLangfuse,
3099
+ reasoningLangfuseOverlay
3100
+ );
3038
3101
  initializeLangfuseTracing(reasoningLangfuseConfig);
3039
3102
 
3040
3103
  const inheritedTraceSeed = getTraceIdSeed();
@@ -3050,8 +3113,8 @@ export class Run<_T extends t.BaseGraphState> {
3050
3113
  : undefined;
3051
3114
  const reasoningScopeRunId = `reasoning-label:${this.id}:${reasoningSeq}:${nanoid()}`;
3052
3115
  const reasoningRuntimeScope = resolveLangfuseRuntimeScope({
3053
- runLangfuse: this.langfuse,
3054
- langfuseOverlay: reasoningContext?.langfuse,
3116
+ runLangfuse: reasoningRunLangfuse,
3117
+ langfuseOverlay: reasoningLangfuseOverlay,
3055
3118
  traceIdSeed: reasoningTraceSeed,
3056
3119
  runId: reasoningScopeRunId,
3057
3120
  });
@@ -3265,9 +3328,11 @@ export class Run<_T extends t.BaseGraphState> {
3265
3328
  this.Graph == null
3266
3329
  ? undefined
3267
3330
  : this.Graph.agentContexts.get(this.Graph.defaultAgentId);
3331
+ const phaseRunLangfuse = withoutSkillsAvailable(this.langfuse);
3332
+ const phaseLangfuseOverlay = withoutSkillsAvailable(phaseContext?.langfuse);
3268
3333
  const phaseLangfuseConfig = resolveLangfuseConfig(
3269
- this.langfuse,
3270
- phaseContext?.langfuse
3334
+ phaseRunLangfuse,
3335
+ phaseLangfuseOverlay
3271
3336
  );
3272
3337
 
3273
3338
  let redaction = hasToolOutputTracingConfig(
@@ -3396,8 +3461,8 @@ export class Run<_T extends t.BaseGraphState> {
3396
3461
  : undefined;
3397
3462
  const phaseScopeRunId = `activity-phase:${this.id}:${phaseSeq}:${nanoid()}`;
3398
3463
  const phaseRuntimeScope = resolveLangfuseRuntimeScope({
3399
- runLangfuse: this.langfuse,
3400
- langfuseOverlay: phaseContext?.langfuse,
3464
+ runLangfuse: phaseRunLangfuse,
3465
+ langfuseOverlay: phaseLangfuseOverlay,
3401
3466
  traceIdSeed: phaseTraceSeed,
3402
3467
  runId: phaseScopeRunId,
3403
3468
  });
@@ -27,6 +27,7 @@ import type { RecoveryClaim } from './recovery/server';
27
27
  import type { SdkAgentIdentity } from './identity';
28
28
  import {
29
29
  Run,
30
+ ToolResultProtectionError,
30
31
  executeHooks,
31
32
  GraphEvents,
32
33
  HOOK_EVENTS,
@@ -64,10 +65,16 @@ export async function createRemoteSdkRun({
64
65
  throw new Error(
65
66
  'Remote SDK client-owned tools require a supported ownership adapter'
66
67
  );
68
+ if (config.toolResultProtection != null)
69
+ throw new ToolResultProtectionError('unsupported');
67
70
  if (config.providerTextProtection && !hostServices?.providerText)
68
71
  throw new Error(
69
72
  'Remote SDK provider protection requires a supported policy adapter'
70
73
  );
74
+ if (config.resolveAttachment)
75
+ throw new Error(
76
+ 'Remote SDK attachment references require a supported file adapter'
77
+ );
71
78
  identity = Object.freeze({ ...identity });
72
79
  const limits = remoteSdkLimits(remote);
73
80
  const url = new URL(remote.url);
package/src/stream.ts CHANGED
@@ -194,6 +194,11 @@ function isEagerExecutionExcludedTool(
194
194
  if (excluded != null && excluded.includes(name)) {
195
195
  return true;
196
196
  }
197
+ // A protected result must be inspected before its completion is published,
198
+ // which only the committed ToolNode path guarantees.
199
+ if (graph.toolResultProtection?.toolNames.includes(name) === true) {
200
+ return true;
201
+ }
197
202
  // Run-scoped circuit breaker: once a prestart for this tool diverged from
198
203
  // the final request ("changed after eager execution started"), stop
199
204
  // prestarting it so the model's retry executes normally instead of
@@ -894,7 +899,8 @@ function startEagerToolExecutions(args: {
894
899
  void safeDispatchCustomEvent(
895
900
  GraphEvents.ON_TOOL_EXECUTE,
896
901
  batchRequest,
897
- graph.config
902
+ graph.config,
903
+ toolCalls
898
904
  )
899
905
  .then(() => {
900
906
  dispatchSettled = true;