@librechat/agents 4.2.9 → 4.2.11

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 (340) hide show
  1. package/dist/cjs/agents/AgentContext.cjs +32 -2
  2. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  3. package/dist/cjs/harness/fileBindings.cjs +93 -0
  4. package/dist/cjs/harness/fileBindings.cjs.map +1 -0
  5. package/dist/cjs/harness/fileService.cjs +141 -0
  6. package/dist/cjs/harness/fileService.cjs.map +1 -0
  7. package/dist/cjs/harness/fileStream.cjs +76 -0
  8. package/dist/cjs/harness/fileStream.cjs.map +1 -0
  9. package/dist/cjs/harness/files.cjs +106 -0
  10. package/dist/cjs/harness/files.cjs.map +1 -0
  11. package/dist/cjs/harness/index.cjs +3 -0
  12. package/dist/cjs/harness/index.cjs.map +1 -1
  13. package/dist/cjs/llm/google/utils/signatures.cjs +5 -3
  14. package/dist/cjs/llm/google/utils/signatures.cjs.map +1 -1
  15. package/dist/cjs/main.cjs +13 -0
  16. package/dist/cjs/runtime/admission.cjs +135 -0
  17. package/dist/cjs/runtime/admission.cjs.map +1 -0
  18. package/dist/cjs/runtime/checkpoint.cjs +40 -0
  19. package/dist/cjs/runtime/checkpoint.cjs.map +1 -0
  20. package/dist/cjs/runtime/client.cjs +435 -0
  21. package/dist/cjs/runtime/client.cjs.map +1 -0
  22. package/dist/cjs/runtime/files.cjs +301 -0
  23. package/dist/cjs/runtime/files.cjs.map +1 -0
  24. package/dist/cjs/runtime/hostTools.cjs +165 -0
  25. package/dist/cjs/runtime/hostTools.cjs.map +1 -0
  26. package/dist/cjs/runtime/index.cjs +11 -0
  27. package/dist/cjs/runtime/model.cjs +303 -0
  28. package/dist/cjs/runtime/model.cjs.map +1 -0
  29. package/dist/cjs/runtime/peer.cjs +209 -0
  30. package/dist/cjs/runtime/peer.cjs.map +1 -0
  31. package/dist/cjs/runtime/policy.cjs +77 -0
  32. package/dist/cjs/runtime/policy.cjs.map +1 -0
  33. package/dist/cjs/runtime/recovery/client.cjs +172 -0
  34. package/dist/cjs/runtime/recovery/client.cjs.map +1 -0
  35. package/dist/cjs/runtime/recovery/log.cjs +47 -0
  36. package/dist/cjs/runtime/recovery/log.cjs.map +1 -0
  37. package/dist/cjs/runtime/recovery/redis.cjs +239 -0
  38. package/dist/cjs/runtime/recovery/redis.cjs.map +1 -0
  39. package/dist/cjs/runtime/recovery/server.cjs +190 -0
  40. package/dist/cjs/runtime/recovery/server.cjs.map +1 -0
  41. package/dist/cjs/runtime/recovery/socket.cjs +298 -0
  42. package/dist/cjs/runtime/recovery/socket.cjs.map +1 -0
  43. package/dist/cjs/runtime/resume.cjs +115 -0
  44. package/dist/cjs/runtime/resume.cjs.map +1 -0
  45. package/dist/cjs/runtime/sealed.cjs +107 -0
  46. package/dist/cjs/runtime/sealed.cjs.map +1 -0
  47. package/dist/cjs/runtime/server.cjs +415 -0
  48. package/dist/cjs/runtime/server.cjs.map +1 -0
  49. package/dist/cjs/runtime/snapshot.cjs +61 -0
  50. package/dist/cjs/runtime/snapshot.cjs.map +1 -0
  51. package/dist/cjs/runtime/types.cjs +20 -0
  52. package/dist/cjs/runtime/types.cjs.map +1 -0
  53. package/dist/cjs/runtime/wire.cjs +84 -0
  54. package/dist/cjs/runtime/wire.cjs.map +1 -0
  55. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +3 -2
  56. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
  57. package/dist/cjs/tools/ProgrammaticCallerPolicy.cjs +24 -1
  58. package/dist/cjs/tools/ProgrammaticCallerPolicy.cjs.map +1 -1
  59. package/dist/cjs/tools/ProgrammaticToolCalling.cjs +3 -2
  60. package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
  61. package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs +2 -1
  62. package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs.map +1 -1
  63. package/dist/cjs/tools/subagent/SubagentExecutor.cjs +15 -3
  64. package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
  65. package/dist/cjs/tools/subagent/childGraphConfig.cjs +13 -1
  66. package/dist/cjs/tools/subagent/childGraphConfig.cjs.map +1 -1
  67. package/dist/cjs/tools/subagent/hostArgs.cjs +2 -0
  68. package/dist/cjs/tools/subagent/hostArgs.cjs.map +1 -1
  69. package/dist/esm/agents/AgentContext.mjs +32 -2
  70. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  71. package/dist/esm/harness/fileBindings.mjs +93 -0
  72. package/dist/esm/harness/fileBindings.mjs.map +1 -0
  73. package/dist/esm/harness/fileService.mjs +140 -0
  74. package/dist/esm/harness/fileService.mjs.map +1 -0
  75. package/dist/esm/harness/fileStream.mjs +76 -0
  76. package/dist/esm/harness/fileStream.mjs.map +1 -0
  77. package/dist/esm/harness/files.mjs +97 -0
  78. package/dist/esm/harness/files.mjs.map +1 -0
  79. package/dist/esm/harness/index.mjs +3 -0
  80. package/dist/esm/harness/index.mjs.map +1 -1
  81. package/dist/esm/llm/google/utils/signatures.mjs +5 -3
  82. package/dist/esm/llm/google/utils/signatures.mjs.map +1 -1
  83. package/dist/esm/main.mjs +5 -2
  84. package/dist/esm/runtime/admission.mjs +133 -0
  85. package/dist/esm/runtime/admission.mjs.map +1 -0
  86. package/dist/esm/runtime/checkpoint.mjs +39 -0
  87. package/dist/esm/runtime/checkpoint.mjs.map +1 -0
  88. package/dist/esm/runtime/client.mjs +432 -0
  89. package/dist/esm/runtime/client.mjs.map +1 -0
  90. package/dist/esm/runtime/files.mjs +299 -0
  91. package/dist/esm/runtime/files.mjs.map +1 -0
  92. package/dist/esm/runtime/hostTools.mjs +164 -0
  93. package/dist/esm/runtime/hostTools.mjs.map +1 -0
  94. package/dist/esm/runtime/index.mjs +5 -0
  95. package/dist/esm/runtime/model.mjs +301 -0
  96. package/dist/esm/runtime/model.mjs.map +1 -0
  97. package/dist/esm/runtime/peer.mjs +209 -0
  98. package/dist/esm/runtime/peer.mjs.map +1 -0
  99. package/dist/esm/runtime/policy.mjs +75 -0
  100. package/dist/esm/runtime/policy.mjs.map +1 -0
  101. package/dist/esm/runtime/recovery/client.mjs +172 -0
  102. package/dist/esm/runtime/recovery/client.mjs.map +1 -0
  103. package/dist/esm/runtime/recovery/log.mjs +46 -0
  104. package/dist/esm/runtime/recovery/log.mjs.map +1 -0
  105. package/dist/esm/runtime/recovery/redis.mjs +239 -0
  106. package/dist/esm/runtime/recovery/redis.mjs.map +1 -0
  107. package/dist/esm/runtime/recovery/server.mjs +189 -0
  108. package/dist/esm/runtime/recovery/server.mjs.map +1 -0
  109. package/dist/esm/runtime/recovery/socket.mjs +297 -0
  110. package/dist/esm/runtime/recovery/socket.mjs.map +1 -0
  111. package/dist/esm/runtime/resume.mjs +111 -0
  112. package/dist/esm/runtime/resume.mjs.map +1 -0
  113. package/dist/esm/runtime/sealed.mjs +106 -0
  114. package/dist/esm/runtime/sealed.mjs.map +1 -0
  115. package/dist/esm/runtime/server.mjs +413 -0
  116. package/dist/esm/runtime/server.mjs.map +1 -0
  117. package/dist/esm/runtime/snapshot.mjs +60 -0
  118. package/dist/esm/runtime/snapshot.mjs.map +1 -0
  119. package/dist/esm/runtime/types.mjs +19 -0
  120. package/dist/esm/runtime/types.mjs.map +1 -0
  121. package/dist/esm/runtime/wire.mjs +80 -0
  122. package/dist/esm/runtime/wire.mjs.map +1 -0
  123. package/dist/esm/tools/BashProgrammaticToolCalling.mjs +3 -2
  124. package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
  125. package/dist/esm/tools/ProgrammaticCallerPolicy.mjs +24 -1
  126. package/dist/esm/tools/ProgrammaticCallerPolicy.mjs.map +1 -1
  127. package/dist/esm/tools/ProgrammaticToolCalling.mjs +3 -2
  128. package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
  129. package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs +2 -1
  130. package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs.map +1 -1
  131. package/dist/esm/tools/subagent/SubagentExecutor.mjs +15 -3
  132. package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
  133. package/dist/esm/tools/subagent/childGraphConfig.mjs +13 -1
  134. package/dist/esm/tools/subagent/childGraphConfig.mjs.map +1 -1
  135. package/dist/esm/tools/subagent/hostArgs.mjs +2 -1
  136. package/dist/esm/tools/subagent/hostArgs.mjs.map +1 -1
  137. package/dist/types/agents/AgentContext.d.ts +4 -4
  138. package/dist/types/agents/projection.d.ts +1 -1
  139. package/dist/types/events.d.ts +2 -2
  140. package/dist/types/graphs/Graph.d.ts +13 -13
  141. package/dist/types/graphs/MultiAgentGraph.d.ts +2 -2
  142. package/dist/types/graphs/acceptedModelResponse.d.ts +1 -1
  143. package/dist/types/graphs/createGraph.d.ts +4 -4
  144. package/dist/types/graphs/graphFactory.d.ts +1 -1
  145. package/dist/types/graphs/handoff.d.ts +1 -1
  146. package/dist/types/harness/fileBindings.d.ts +13 -0
  147. package/dist/types/harness/fileService.d.ts +37 -0
  148. package/dist/types/harness/fileStream.d.ts +7 -0
  149. package/dist/types/harness/files.d.ts +108 -0
  150. package/dist/types/harness/index.d.ts +8 -2
  151. package/dist/types/harness/model.d.ts +3 -3
  152. package/dist/types/harness/providerText.d.ts +2 -2
  153. package/dist/types/hitl/approvalReview.d.ts +1 -1
  154. package/dist/types/hitl/askUserQuestion.d.ts +1 -1
  155. package/dist/types/hitl/askUserQuestions.d.ts +1 -1
  156. package/dist/types/hitl/askUserQuestionsInterrupt.d.ts +1 -1
  157. package/dist/types/hooks/types.d.ts +2 -2
  158. package/dist/types/instrumentation.d.ts +1 -1
  159. package/dist/types/langfuse.d.ts +3 -3
  160. package/dist/types/langfuseConfig.d.ts +2 -2
  161. package/dist/types/langfuseRuntimeContext.d.ts +1 -1
  162. package/dist/types/langfuseRuntimeScope.d.ts +2 -2
  163. package/dist/types/langfuseSpanRegistry.d.ts +1 -1
  164. package/dist/types/langfuseToolOutputTracing.d.ts +3 -3
  165. package/dist/types/llm/anthropic/index.d.ts +1 -1
  166. package/dist/types/llm/bedrock/index.d.ts +1 -1
  167. package/dist/types/llm/bedrock/toolCache.d.ts +2 -2
  168. package/dist/types/llm/contextOverflowRecovery.d.ts +2 -2
  169. package/dist/types/llm/contextPressureMeter.d.ts +2 -2
  170. package/dist/types/llm/google/index.d.ts +1 -1
  171. package/dist/types/llm/init.d.ts +1 -1
  172. package/dist/types/llm/invoke.d.ts +9 -9
  173. package/dist/types/llm/mistral/index.d.ts +1 -1
  174. package/dist/types/llm/openai/index.d.ts +2 -2
  175. package/dist/types/llm/openrouter/index.d.ts +2 -2
  176. package/dist/types/llm/openrouter/toolCache.d.ts +2 -2
  177. package/dist/types/llm/prepareProviderRequest.d.ts +3 -3
  178. package/dist/types/llm/promptCacheTools.d.ts +1 -1
  179. package/dist/types/llm/providerRegistry.d.ts +1 -1
  180. package/dist/types/llm/providerTextBoundary.d.ts +2 -2
  181. package/dist/types/llm/providerTextControls.d.ts +1 -1
  182. package/dist/types/llm/providers.d.ts +2 -2
  183. package/dist/types/llm/request.d.ts +1 -1
  184. package/dist/types/llm/stream/chunkAdapters.d.ts +1 -1
  185. package/dist/types/llm/streamLimits.d.ts +1 -1
  186. package/dist/types/llm/truncation.d.ts +1 -1
  187. package/dist/types/llm/vertexai/index.d.ts +1 -1
  188. package/dist/types/messages/alternation.d.ts +1 -1
  189. package/dist/types/messages/anthropicToolCache.d.ts +2 -2
  190. package/dist/types/messages/assistantPhase.d.ts +3 -3
  191. package/dist/types/messages/budget.d.ts +1 -1
  192. package/dist/types/messages/cache.d.ts +1 -1
  193. package/dist/types/messages/contextPruning.d.ts +2 -2
  194. package/dist/types/messages/core.d.ts +1 -1
  195. package/dist/types/messages/fading.d.ts +1 -1
  196. package/dist/types/messages/format.d.ts +2 -2
  197. package/dist/types/messages/ids.d.ts +2 -2
  198. package/dist/types/messages/injected.d.ts +1 -1
  199. package/dist/types/messages/langchain.d.ts +1 -1
  200. package/dist/types/messages/prune.d.ts +4 -4
  201. package/dist/types/messages/recency.d.ts +1 -1
  202. package/dist/types/messages/toolResultTypes.d.ts +1 -1
  203. package/dist/types/openai/arguments.d.ts +1 -1
  204. package/dist/types/openai/index.d.ts +1 -1
  205. package/dist/types/openai/toolProjection.d.ts +1 -1
  206. package/dist/types/prompts/activityLabel.d.ts +2 -2
  207. package/dist/types/prompts/reasoningLabel.d.ts +1 -1
  208. package/dist/types/rerank/search.d.ts +1 -1
  209. package/dist/types/responses/index.d.ts +1 -1
  210. package/dist/types/run.d.ts +3 -3
  211. package/dist/types/runtime/admission.d.ts +30 -0
  212. package/dist/types/runtime/checkpoint.d.ts +14 -0
  213. package/dist/types/runtime/client.d.ts +12 -0
  214. package/dist/types/runtime/files.d.ts +75 -0
  215. package/dist/types/runtime/hostTools.d.ts +22 -0
  216. package/dist/types/runtime/identity.d.ts +2 -0
  217. package/dist/types/runtime/index.d.ts +12 -0
  218. package/dist/types/runtime/model.d.ts +42 -0
  219. package/dist/types/runtime/peer.d.ts +55 -0
  220. package/dist/types/runtime/policy.d.ts +43 -0
  221. package/dist/types/runtime/recovery/client.d.ts +12 -0
  222. package/dist/types/runtime/recovery/journal.d.ts +62 -0
  223. package/dist/types/runtime/recovery/log.d.ts +9 -0
  224. package/dist/types/runtime/recovery/redis.d.ts +17 -0
  225. package/dist/types/runtime/recovery/server.d.ts +37 -0
  226. package/dist/types/runtime/recovery/socket.d.ts +72 -0
  227. package/dist/types/runtime/resume.d.ts +66 -0
  228. package/dist/types/runtime/sealed.d.ts +19 -0
  229. package/dist/types/runtime/server.d.ts +21 -0
  230. package/dist/types/runtime/snapshot.d.ts +12 -0
  231. package/dist/types/runtime/types.d.ts +125 -0
  232. package/dist/types/runtime/wire.d.ts +3 -0
  233. package/dist/types/session/handlers.d.ts +1 -1
  234. package/dist/types/session/types.d.ts +1 -1
  235. package/dist/types/stream.d.ts +3 -3
  236. package/dist/types/summarization/index.d.ts +1 -1
  237. package/dist/types/summarization/input.d.ts +1 -1
  238. package/dist/types/summarization/node.d.ts +6 -6
  239. package/dist/types/summarization/retry.d.ts +2 -2
  240. package/dist/types/summarization/semanticIndex.d.ts +2 -2
  241. package/dist/types/summarization/toolBudget.d.ts +1 -1
  242. package/dist/types/summarization/usage.d.ts +1 -1
  243. package/dist/types/tools/ArtifactDelivery.d.ts +1 -1
  244. package/dist/types/tools/ArtifactTruncation.d.ts +1 -1
  245. package/dist/types/tools/BashExecutor.d.ts +2 -2
  246. package/dist/types/tools/BashProgrammaticToolCalling.d.ts +2 -2
  247. package/dist/types/tools/CallerCapabilities.d.ts +1 -1
  248. package/dist/types/tools/CodeExecutor.d.ts +4 -4
  249. package/dist/types/tools/CodeSessionFileSummary.d.ts +1 -1
  250. package/dist/types/tools/ProgrammaticCallerPolicy.d.ts +2 -1
  251. package/dist/types/tools/ProgrammaticToolCalling.d.ts +2 -2
  252. package/dist/types/tools/ReadFile.d.ts +1 -1
  253. package/dist/types/tools/SkillTool.d.ts +1 -1
  254. package/dist/types/tools/SubagentTool.d.ts +3 -3
  255. package/dist/types/tools/ToolNode.d.ts +5 -5
  256. package/dist/types/tools/ToolSearch.d.ts +2 -2
  257. package/dist/types/tools/cloudflare/CloudflareBridgeRuntime.d.ts +1 -1
  258. package/dist/types/tools/cloudflare/CloudflareProgrammaticToolCalling.d.ts +1 -1
  259. package/dist/types/tools/cloudflare/CloudflareSandboxExecutionEngine.d.ts +2 -2
  260. package/dist/types/tools/cloudflare/CloudflareSandboxTools.d.ts +1 -1
  261. package/dist/types/tools/diagnostics.d.ts +1 -1
  262. package/dist/types/tools/eagerEventExecution.d.ts +1 -1
  263. package/dist/types/tools/handlers.d.ts +3 -3
  264. package/dist/types/tools/intentArg.d.ts +1 -1
  265. package/dist/types/tools/local/CompileCheckTool.d.ts +2 -2
  266. package/dist/types/tools/local/FileCheckpointer.d.ts +1 -1
  267. package/dist/types/tools/local/LocalCodingTools.d.ts +2 -2
  268. package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -1
  269. package/dist/types/tools/local/LocalExecutionTools.d.ts +1 -1
  270. package/dist/types/tools/local/LocalProgrammaticToolCalling.d.ts +1 -1
  271. package/dist/types/tools/local/bashAst.d.ts +1 -1
  272. package/dist/types/tools/local/resolveLocalExecutionTools.d.ts +1 -1
  273. package/dist/types/tools/local/syntaxCheck.d.ts +1 -1
  274. package/dist/types/tools/ptcTimeout.d.ts +1 -1
  275. package/dist/types/tools/runStepResume.d.ts +1 -1
  276. package/dist/types/tools/schema.d.ts +1 -1
  277. package/dist/types/tools/search/anthropic.d.ts +1 -1
  278. package/dist/types/tools/skillCatalog.d.ts +1 -1
  279. package/dist/types/tools/subagent/InMemorySubagentTaskStore.d.ts +1 -1
  280. package/dist/types/tools/subagent/SubagentExecutor.d.ts +5 -5
  281. package/dist/types/tools/subagent/SubagentReplay.d.ts +3 -3
  282. package/dist/types/tools/subagent/childGraphConfig.d.ts +2 -2
  283. package/dist/types/tools/subagent/diagnostics.d.ts +2 -2
  284. package/dist/types/tools/subagent/hostArgs.d.ts +8 -2
  285. package/dist/types/tools/subagent/index.d.ts +1 -1
  286. package/dist/types/tools/toolBatchReplay.d.ts +3 -3
  287. package/dist/types/types/activityLabel.d.ts +2 -2
  288. package/dist/types/types/graph.d.ts +16 -13
  289. package/dist/types/types/llm.d.ts +9 -9
  290. package/dist/types/types/reasoningLabel.d.ts +1 -1
  291. package/dist/types/types/run.d.ts +8 -8
  292. package/dist/types/types/stream.d.ts +5 -5
  293. package/dist/types/types/summarize.d.ts +2 -2
  294. package/dist/types/types/tools.d.ts +8 -8
  295. package/dist/types/utils/errors.d.ts +1 -1
  296. package/dist/types/utils/events.d.ts +3 -3
  297. package/dist/types/utils/handlers.d.ts +3 -3
  298. package/dist/types/utils/llm.d.ts +2 -2
  299. package/dist/types/utils/llmConfig.d.ts +1 -1
  300. package/dist/types/utils/title.d.ts +1 -1
  301. package/dist/types/utils/toolSessions.d.ts +1 -1
  302. package/package.json +22 -3
  303. package/src/agents/AgentContext.ts +68 -2
  304. package/src/harness/fileBindings.ts +156 -0
  305. package/src/harness/fileService.ts +217 -0
  306. package/src/harness/fileStream.ts +99 -0
  307. package/src/harness/files.ts +185 -0
  308. package/src/harness/index.ts +24 -0
  309. package/src/llm/google/utils/signatures.ts +10 -3
  310. package/src/runtime/admission.ts +224 -0
  311. package/src/runtime/checkpoint.ts +66 -0
  312. package/src/runtime/client.ts +674 -0
  313. package/src/runtime/files.ts +503 -0
  314. package/src/runtime/hostTools.ts +243 -0
  315. package/src/runtime/identity.ts +3 -0
  316. package/src/runtime/index.ts +33 -0
  317. package/src/runtime/model.ts +452 -0
  318. package/src/runtime/peer.ts +262 -0
  319. package/src/runtime/policy.ts +150 -0
  320. package/src/runtime/recovery/client.ts +232 -0
  321. package/src/runtime/recovery/journal.ts +88 -0
  322. package/src/runtime/recovery/log.ts +70 -0
  323. package/src/runtime/recovery/redis.ts +342 -0
  324. package/src/runtime/recovery/server.ts +280 -0
  325. package/src/runtime/recovery/socket.ts +422 -0
  326. package/src/runtime/resume.ts +268 -0
  327. package/src/runtime/sealed.ts +144 -0
  328. package/src/runtime/server.ts +653 -0
  329. package/src/runtime/snapshot.ts +87 -0
  330. package/src/runtime/types.ts +184 -0
  331. package/src/runtime/wire.ts +96 -0
  332. package/src/tools/BashProgrammaticToolCalling.ts +5 -2
  333. package/src/tools/ProgrammaticCallerPolicy.ts +42 -3
  334. package/src/tools/ProgrammaticToolCalling.ts +4 -1
  335. package/src/tools/local/LocalProgrammaticToolCalling.ts +4 -0
  336. package/src/tools/subagent/SubagentExecutor.ts +98 -32
  337. package/src/tools/subagent/childGraphConfig.ts +33 -1
  338. package/src/tools/subagent/hostArgs.ts +7 -0
  339. package/src/tools/subagent/index.ts +1 -0
  340. package/src/types/graph.ts +6 -3
@@ -0,0 +1,87 @@
1
+ import { z } from 'zod';
2
+ import type { RemoteSdkSnapshot, RemoteSdkLimits } from './types';
3
+ import { encodeSdkValue, decodeSdkValue } from './wire';
4
+
5
+ /** One bounded transfer per execution; chunks precede the terminal receipt in the ordered durable stream. */
6
+ export function createSnapshotReceiver(maxBytes: number): {
7
+ accept(data: unknown): null;
8
+ finish(data: unknown): RemoteSdkSnapshot;
9
+ } {
10
+ let buffer: Buffer | undefined;
11
+ let received = 0;
12
+ let total: number | undefined;
13
+ let finished = false;
14
+ return {
15
+ accept(data: unknown): null {
16
+ const chunk = z
17
+ .object({
18
+ offset: z.number().int().nonnegative(),
19
+ total: z.number().int().positive().max(maxBytes),
20
+ data: z
21
+ .string()
22
+ .regex(
23
+ /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/
24
+ ),
25
+ })
26
+ .parse(data);
27
+ const bytes = Buffer.from(chunk.data, 'base64');
28
+ if (
29
+ finished ||
30
+ !bytes.length ||
31
+ chunk.offset !== received ||
32
+ (total !== undefined && total !== chunk.total) ||
33
+ received + bytes.length > chunk.total
34
+ )
35
+ throw new Error('Invalid SDK snapshot transfer');
36
+ total = chunk.total;
37
+ buffer ??= Buffer.alloc(chunk.total);
38
+ bytes.copy(buffer, received);
39
+ received += bytes.length;
40
+ return null;
41
+ },
42
+ finish(data: unknown): RemoteSdkSnapshot {
43
+ const receipt = z
44
+ .object({ snapshotBytes: z.number().int().positive().max(maxBytes) })
45
+ .parse(data);
46
+ if (finished || received !== total || receipt.snapshotBytes !== total)
47
+ throw new Error('Incomplete SDK snapshot transfer');
48
+ finished = true;
49
+ const snapshot = decodeSdkValue(
50
+ JSON.parse(buffer!.toString('utf8'))
51
+ ) as RemoteSdkSnapshot;
52
+ buffer = undefined;
53
+ return snapshot;
54
+ },
55
+ };
56
+ }
57
+
58
+ export async function sendSnapshot(
59
+ peer: { send: (frame: { type: 'snapshot' | 'done'; data: unknown }) => void },
60
+ snapshot: RemoteSdkSnapshot,
61
+ limits: RemoteSdkLimits,
62
+ flush?: () => Promise<void>
63
+ ): Promise<void> {
64
+ const bytes = Buffer.from(JSON.stringify(encodeSdkValue(snapshot)));
65
+ if (bytes.length > limits.maxBufferedBytes)
66
+ throw new Error('SDK snapshot capacity exceeded');
67
+ // Leave room for base64 expansion, RPC identity and the wire value tags.
68
+ const chunkBytes = Math.max(1, Math.floor(limits.maxFrameBytes / 4));
69
+ for (let offset = 0; offset < bytes.length; offset += chunkBytes) {
70
+ peer.send({
71
+ type: 'snapshot',
72
+ data: {
73
+ offset,
74
+ total: bytes.length,
75
+ data: bytes.subarray(offset, offset + chunkBytes).toString('base64'),
76
+ },
77
+ });
78
+ await flush?.();
79
+ }
80
+ peer.send({
81
+ type: 'done',
82
+ data: {
83
+ snapshotBytes: bytes.length,
84
+ interrupt: snapshot.interrupt == null ? undefined : true,
85
+ },
86
+ });
87
+ }
@@ -0,0 +1,184 @@
1
+ import type {
2
+ RunStep,
3
+ AgentInputs,
4
+ createHostFileService,
5
+ HostFileBindings,
6
+ HostFileDescriptor,
7
+ HostFileServiceDescriptor,
8
+ createHostProviderTextService,
9
+ createHostModelService,
10
+ HostModelDescriptor,
11
+ HostChatModel,
12
+ HostProviderTextDescriptor,
13
+ HostToolDescriptor,
14
+ HostToolBindings,
15
+ Run,
16
+ RunConfig,
17
+ EventHandler,
18
+ IState,
19
+ HookEvent,
20
+ } from '@/index';
21
+ import type { HostModelLifecycle } from './admission';
22
+ import type { SdkAgentIdentity } from './identity';
23
+
24
+ export interface RemoteSdkRecoveryOptions {
25
+ /** Operator-allowlisted direct worker routes, keyed by stable owner identity. */
26
+ routes?: Record<string, string>;
27
+ maxDisconnectMs: number;
28
+ retryDelayMs: number;
29
+ maxJournalBytes: number;
30
+ }
31
+ export interface RemoteSdkOptions {
32
+ /** Opt in to the saved-agent host model, configured by the operator. */
33
+ hostModel?: boolean;
34
+ /** Opt in to native host attachment reads. */
35
+ hostFiles?: boolean;
36
+ recovery?: RemoteSdkRecoveryOptions;
37
+ url: string;
38
+ secret: string;
39
+ connectTimeoutMs?: number;
40
+ rpcTimeoutMs?: number;
41
+ maxFrameBytes?: number;
42
+ maxBufferedBytes?: number;
43
+ maxRunMs?: number;
44
+ /** Trusted host diagnostics; never delivered to the browser or runtime. */
45
+ onError?: (error: unknown) => void;
46
+ }
47
+ export interface RemoteSdkLimits {
48
+ connectTimeoutMs: number;
49
+ rpcTimeoutMs: number;
50
+ maxFrameBytes: number;
51
+ maxBufferedBytes: number;
52
+ maxRunMs: number;
53
+ }
54
+ export function remoteSdkLimits(
55
+ options: Partial<RemoteSdkLimits>
56
+ ): RemoteSdkLimits {
57
+ const limits = {
58
+ connectTimeoutMs: options.connectTimeoutMs ?? 10_000,
59
+ rpcTimeoutMs: options.rpcTimeoutMs ?? 60_000,
60
+ maxFrameBytes: options.maxFrameBytes ?? 1_048_576,
61
+ maxBufferedBytes: options.maxBufferedBytes ?? 4_194_304,
62
+ maxRunMs: options.maxRunMs ?? 600_000,
63
+ };
64
+ if (
65
+ Object.values(limits).some(
66
+ (value) => !Number.isSafeInteger(value) || value <= 0
67
+ )
68
+ )
69
+ throw new Error('Invalid SDK runtime limits');
70
+ return limits;
71
+ }
72
+ export type SdkRun = Awaited<ReturnType<typeof Run.create>>;
73
+ export type SdkRunInput = Parameters<SdkRun['processStream']>[0];
74
+ export type SdkRunOptions = Parameters<SdkRun['processStream']>[1];
75
+ export type SdkEventData = Parameters<EventHandler['handle']>[1];
76
+ /** Public primary-model configuration required by the worker graph. */
77
+ export interface RemoteSdkModelProfile {
78
+ provider: AgentInputs['provider'];
79
+ name: string;
80
+ streaming: boolean;
81
+ }
82
+
83
+ /** Explicit host-owned capabilities; never reconstructed from worker claims or YAML. */
84
+ export interface RemoteSdkHostServices {
85
+ /** Already authorized host binding; storage credentials and policy stay with the host. */
86
+ files?: ReturnType<typeof createHostFileService> & {
87
+ sources: readonly HostFileDescriptor[];
88
+ };
89
+ modelLifecycle?: HostModelLifecycle;
90
+ modelProfile?: RemoteSdkModelProfile;
91
+ model?: ReturnType<typeof createHostModelService>;
92
+ providerText?: ReturnType<typeof createHostProviderTextService>;
93
+ }
94
+
95
+ export interface RemoteSdkStart {
96
+ transportVersion: 2;
97
+ files?: {
98
+ version: 1;
99
+ publicKey: string;
100
+ descriptor: HostFileServiceDescriptor;
101
+ sources: HostFileDescriptor[];
102
+ };
103
+ modelAdmission?: { version: 1; maxEntries: number };
104
+ model?: { version: 1; publicKey: string; descriptor: HostModelDescriptor };
105
+ providerText?: {
106
+ version: 1;
107
+ publicKey: string;
108
+ limits: HostProviderTextDescriptor;
109
+ };
110
+ hostTools?: HostToolDescriptor[];
111
+ operation: 'start' | 'resume';
112
+ input: IState;
113
+ resume?: unknown;
114
+ commandOptions?: Parameters<SdkRun['resume']>[3];
115
+ options: Pick<SdkRunOptions, 'recursionLimit' | 'configurable'>;
116
+ handlers: string[];
117
+ hooks: HookEvent[];
118
+ checkpoint: boolean;
119
+ humanInTheLoop?: RunConfig['humanInTheLoop'];
120
+ streamLimits?: RunConfig['streamLimits'];
121
+ agent: {
122
+ id: string;
123
+ name?: string;
124
+ instructions?: string;
125
+ model?: RemoteSdkModelProfile;
126
+ };
127
+ }
128
+ export interface RemoteSdkSnapshot {
129
+ state?: {
130
+ [K in
131
+ | 'getDiscoveredTools'
132
+ | 'getCalibrationRatio'
133
+ | 'getFadingTier'
134
+ | 'getFadingTiers'
135
+ | 'getFadingTierResetAgentIds'
136
+ | 'getResolvedInstructionOverhead'
137
+ | 'getToolCount'
138
+ | 'getOutputTruncated'
139
+ | 'getHandoffOutcome']: ReturnType<SdkRun[K]>;
140
+ };
141
+ content?: ReturnType<NonNullable<SdkRun['Graph']>['getContentParts']>;
142
+ messages?: ReturnType<SdkRun['getRunMessages']>;
143
+ interrupt?: ReturnType<SdkRun['getInterrupt']>;
144
+ haltReason?: string;
145
+ runSteps?: ReturnType<
146
+ NonNullable<SdkRun['Graph']>['createRunStepResumeState']
147
+ >;
148
+ }
149
+ export interface RemoteSdkFactoryInput {
150
+ hostFiles?: HostFileBindings & {
151
+ readonly sources: readonly HostFileDescriptor[];
152
+ };
153
+ /** Retain this model as Graph.overrideModel when supplied by the authenticated host. */
154
+ hostModel?: ReturnType<HostChatModel['bindTools']>;
155
+ hostTools?: HostToolBindings;
156
+ identity: Readonly<SdkAgentIdentity>;
157
+ /** Host-owned event, hook, and checkpoint adapters. Retain these in the returned Run. */
158
+ config: Pick<
159
+ RunConfig,
160
+ | 'runId'
161
+ | 'customHandlers'
162
+ | 'hooks'
163
+ | 'humanInTheLoop'
164
+ | 'streamLimits'
165
+ | 'providerTextProtection'
166
+ >;
167
+ compileOptions: NonNullable<RunConfig['graphConfig']['compileOptions']>;
168
+ signal: AbortSignal;
169
+ agent: RemoteSdkStart['agent'];
170
+ }
171
+
172
+ export interface RemoteSdkResumeState {
173
+ content: NonNullable<RemoteSdkSnapshot['content']>;
174
+ steps: RunStep[];
175
+ }
176
+
177
+ /** Missing environment substitutions must never become predictable signing keys. */
178
+ export function isRemoteSdkSecret(secret: unknown): secret is string {
179
+ return (
180
+ typeof secret === 'string' &&
181
+ secret.length >= 32 &&
182
+ !/\$\{[^}]+\}/.test(secret)
183
+ );
184
+ }
@@ -0,0 +1,96 @@
1
+ import { Send } from '@langchain/langgraph';
2
+ import isPlainObject from 'lodash/isPlainObject.js';
3
+ import type { StoredMessage } from '@/langchain/messages';
4
+ import {
5
+ BaseMessage,
6
+ mapStoredMessagesToChatMessages,
7
+ } from '@/langchain/messages';
8
+ import { toStoredMessage } from '@/index';
9
+
10
+ /** Only data crosses the runtime boundary; never serialize a host RunConfig or request. */
11
+ export function encodeSdkValue(value: unknown): unknown {
12
+ if (value instanceof Send)
13
+ return {
14
+ $sdk: 'send',
15
+ node: value.node,
16
+ value: encodeSdkValue(value.args),
17
+ };
18
+ if (
19
+ typeof value === 'number' &&
20
+ (!Number.isFinite(value) || Object.is(value, -0))
21
+ )
22
+ return {
23
+ $sdk: 'number',
24
+ value: Object.is(value, -0) ? '-0' : String(value),
25
+ };
26
+ if (value instanceof BaseMessage)
27
+ return { $sdk: 'message', value: encodeSdkValue(toStoredMessage(value)) };
28
+ if (value instanceof Uint8Array)
29
+ return { $sdk: 'bytes', value: Buffer.from(value).toString('base64') };
30
+ if (value instanceof Date)
31
+ return { $sdk: 'date', value: value.toISOString() };
32
+ if (value instanceof Map)
33
+ return { $sdk: 'map', value: [...value].map(encodeSdkValue) };
34
+ if (value instanceof Set)
35
+ return { $sdk: 'set', value: [...value].map(encodeSdkValue) };
36
+ if (typeof value === 'bigint')
37
+ return { $sdk: 'bigint', value: value.toString() };
38
+ if (value === undefined) return { $sdk: 'undefined' };
39
+ if (Array.isArray(value)) return value.map(encodeSdkValue);
40
+ if (value != null && typeof value === 'object') {
41
+ if (!isPlainObject(value))
42
+ throw new Error('SDK runtime class is not serializable');
43
+ const entries = Object.entries(value).map(([key, item]) => [
44
+ key,
45
+ encodeSdkValue(item),
46
+ ]);
47
+ return Object.prototype.hasOwnProperty.call(value, '$sdk')
48
+ ? { $sdk: 'record', value: entries }
49
+ : Object.fromEntries(entries);
50
+ }
51
+ if (typeof value === 'function' || typeof value === 'symbol') {
52
+ throw new Error('SDK runtime value is not serializable');
53
+ }
54
+ return value;
55
+ }
56
+
57
+ export function decodeSdkValue(value: unknown): unknown {
58
+ if (Array.isArray(value)) return value.map(decodeSdkValue);
59
+ if (value != null && typeof value === 'object') {
60
+ const record = value as Record<string, unknown>;
61
+ if (record.$sdk === 'send' && typeof record.node === 'string')
62
+ return new Send(record.node, decodeSdkValue(record.value));
63
+ if (
64
+ record.$sdk === 'number' &&
65
+ typeof record.value === 'string' &&
66
+ ['NaN', 'Infinity', '-Infinity', '-0'].includes(record.value)
67
+ )
68
+ return Number(record.value);
69
+ if (record.$sdk === 'message')
70
+ return mapStoredMessagesToChatMessages([
71
+ decodeSdkValue(record.value) as StoredMessage,
72
+ ])[0];
73
+ if (record.$sdk === 'bytes' && typeof record.value === 'string')
74
+ return Uint8Array.from(Buffer.from(record.value, 'base64'));
75
+ if (record.$sdk === 'date' && typeof record.value === 'string')
76
+ return new Date(record.value);
77
+ if (record.$sdk === 'map' && Array.isArray(record.value))
78
+ return new Map(record.value.map(decodeSdkValue) as [unknown, unknown][]);
79
+ if (record.$sdk === 'set' && Array.isArray(record.value))
80
+ return new Set(record.value.map(decodeSdkValue));
81
+ if (record.$sdk === 'bigint' && typeof record.value === 'string')
82
+ return BigInt(record.value);
83
+ if (record.$sdk === 'record' && Array.isArray(record.value))
84
+ return Object.fromEntries(
85
+ record.value.map(([key, item]: [string, unknown]) => [
86
+ key,
87
+ decodeSdkValue(item),
88
+ ])
89
+ );
90
+ if (record.$sdk === 'undefined') return undefined;
91
+ return Object.fromEntries(
92
+ Object.entries(record).map(([key, item]) => [key, decodeSdkValue(item)])
93
+ );
94
+ }
95
+ return value;
96
+ }
@@ -32,8 +32,8 @@ import {
32
32
  runPlainExecution,
33
33
  formatCompletedResponse,
34
34
  } from './ProgrammaticToolCalling';
35
- import { logCodeApiDiagnostic } from '@/tools/diagnostics';
36
35
  import { resolveAttachedWorkspaceInstanceId } from '@/tools/workspaceIdentity';
36
+ import { logCodeApiDiagnostic } from '@/tools/diagnostics';
37
37
  import { INTENT_PROPERTY } from '@/tools/intentArg';
38
38
  import { Constants } from '@/common';
39
39
 
@@ -155,7 +155,9 @@ ${EXAMPLES}
155
155
  ${CORE_RULES}`;
156
156
 
157
157
  const TOOL_MANIFEST_DESCRIPTION =
158
- 'Exact registered tool names used by the code. Required when direct-only tools are configured; ' +
158
+ 'Registered tool names or their normalized sandbox function names used by the code. ' +
159
+ 'Use sandbox names in code, but registered names in tool_manifest when sandbox names collide. ' +
160
+ 'Required when direct-only tools are configured; ' +
159
161
  'validated before execution starts. Pass [] when the code calls no tools at all.';
160
162
 
161
163
  // ============================================================================
@@ -433,6 +435,7 @@ export function createBashProgrammaticToolCallingTool(
433
435
  allowedToolDefs: toolDefs,
434
436
  disallowedToolDefs,
435
437
  programmaticToolName,
438
+ normalizeIdentifier: normalizeToBashIdentifier,
436
439
  });
437
440
 
438
441
  /* These guard the replay path only. A call that selected no tools never
@@ -79,6 +79,7 @@ export function selectProgrammaticTools(args: {
79
79
  allowedToolDefs?: t.LCTool[];
80
80
  disallowedToolDefs?: t.LCTool[];
81
81
  programmaticToolName: string;
82
+ normalizeIdentifier?: (name: string) => string;
82
83
  }): t.LCTool[] {
83
84
  const allowedToolDefs = args.allowedToolDefs ?? [];
84
85
  const disallowedToolDefs = args.disallowedToolDefs ?? [];
@@ -111,6 +112,42 @@ export function selectProgrammaticTools(args: {
111
112
  const unknownNames = new Set(
112
113
  requestedToolNames.filter((name) => !allowedByName.has(name))
113
114
  );
115
+ if (unknownNames.size > 0 && args.normalizeIdentifier != null) {
116
+ const candidatesByIdentifier = new Map<string, t.LCTool[]>();
117
+ for (const toolDef of allowedToolDefs) {
118
+ const identifier = args.normalizeIdentifier(toolDef.name);
119
+ if (!unknownNames.has(identifier)) {
120
+ continue;
121
+ }
122
+ const candidates = candidatesByIdentifier.get(identifier) ?? [];
123
+ candidates.push(toolDef);
124
+ candidatesByIdentifier.set(identifier, candidates);
125
+ }
126
+
127
+ const disallowedAliases = new Set<string>();
128
+ for (const toolDef of disallowedToolDefs) {
129
+ const identifier = args.normalizeIdentifier(toolDef.name);
130
+ if (unknownNames.has(identifier)) {
131
+ disallowedAliases.add(toolDef.name);
132
+ }
133
+ }
134
+ assertDisallowedToolUsage(disallowedAliases, args.programmaticToolName);
135
+
136
+ for (const name of unknownNames) {
137
+ const candidates = candidatesByIdentifier.get(name);
138
+ if (candidates == null) {
139
+ continue;
140
+ }
141
+ assertUnambiguousIdentifiers(
142
+ candidates,
143
+ args.normalizeIdentifier,
144
+ args.programmaticToolName
145
+ );
146
+ allowedByName.set(name, candidates[0]);
147
+ unknownNames.delete(name);
148
+ }
149
+ }
150
+
114
151
  if (unknownNames.size > 0) {
115
152
  throw new Error(
116
153
  `Tool${unknownNames.size === 1 ? '' : 's'} ${[...unknownNames]
@@ -122,7 +159,9 @@ export function selectProgrammaticTools(args: {
122
159
  );
123
160
  }
124
161
 
125
- return [...new Set(requestedToolNames)].map(
126
- (name) => allowedByName.get(name) as t.LCTool
127
- );
162
+ return [
163
+ ...new Set(
164
+ requestedToolNames.map((name) => allowedByName.get(name) as t.LCTool)
165
+ ),
166
+ ];
128
167
  }
@@ -112,7 +112,9 @@ ${EXAMPLES}
112
112
  ${CORE_RULES}`;
113
113
 
114
114
  const TOOL_MANIFEST_DESCRIPTION =
115
- 'Exact registered tool names used by the code. Required when direct-only tools are configured; ' +
115
+ 'Registered tool names or their normalized sandbox function names used by the code. ' +
116
+ 'Use sandbox names in code, but registered names in tool_manifest when sandbox names collide. ' +
117
+ 'Required when direct-only tools are configured; ' +
116
118
  'validated before execution starts. Pass [] when the code calls no tools at all.';
117
119
 
118
120
  export function createProgrammaticToolCallingSchema(
@@ -1127,6 +1129,7 @@ export function createProgrammaticToolCallingTool(
1127
1129
  allowedToolDefs: toolDefs,
1128
1130
  disallowedToolDefs,
1129
1131
  programmaticToolName,
1132
+ normalizeIdentifier: normalizeToPythonIdentifier,
1130
1133
  });
1131
1134
 
1132
1135
  /* These guard the replay path only. A call that selected no tools never
@@ -600,6 +600,10 @@ async function runLocalProgrammaticTool(args: {
600
600
  allowedToolDefs: toolDefs,
601
601
  disallowedToolDefs,
602
602
  programmaticToolName: runnerName,
603
+ normalizeIdentifier:
604
+ args.runtime === 'bash'
605
+ ? normalizeToBashIdentifier
606
+ : normalizeToPythonIdentifier,
603
607
  });
604
608
 
605
609
  /* The local program builder supports zero stubs, so a call that selected no