@librechat/agents 4.2.10 → 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 (261) hide show
  1. package/dist/cjs/runtime/admission.cjs +135 -0
  2. package/dist/cjs/runtime/admission.cjs.map +1 -0
  3. package/dist/cjs/runtime/checkpoint.cjs +40 -0
  4. package/dist/cjs/runtime/checkpoint.cjs.map +1 -0
  5. package/dist/cjs/runtime/client.cjs +435 -0
  6. package/dist/cjs/runtime/client.cjs.map +1 -0
  7. package/dist/cjs/runtime/files.cjs +301 -0
  8. package/dist/cjs/runtime/files.cjs.map +1 -0
  9. package/dist/cjs/runtime/hostTools.cjs +165 -0
  10. package/dist/cjs/runtime/hostTools.cjs.map +1 -0
  11. package/dist/cjs/runtime/index.cjs +11 -0
  12. package/dist/cjs/runtime/model.cjs +303 -0
  13. package/dist/cjs/runtime/model.cjs.map +1 -0
  14. package/dist/cjs/runtime/peer.cjs +209 -0
  15. package/dist/cjs/runtime/peer.cjs.map +1 -0
  16. package/dist/cjs/runtime/policy.cjs +77 -0
  17. package/dist/cjs/runtime/policy.cjs.map +1 -0
  18. package/dist/cjs/runtime/recovery/client.cjs +172 -0
  19. package/dist/cjs/runtime/recovery/client.cjs.map +1 -0
  20. package/dist/cjs/runtime/recovery/log.cjs +47 -0
  21. package/dist/cjs/runtime/recovery/log.cjs.map +1 -0
  22. package/dist/cjs/runtime/recovery/redis.cjs +239 -0
  23. package/dist/cjs/runtime/recovery/redis.cjs.map +1 -0
  24. package/dist/cjs/runtime/recovery/server.cjs +190 -0
  25. package/dist/cjs/runtime/recovery/server.cjs.map +1 -0
  26. package/dist/cjs/runtime/recovery/socket.cjs +298 -0
  27. package/dist/cjs/runtime/recovery/socket.cjs.map +1 -0
  28. package/dist/cjs/runtime/resume.cjs +115 -0
  29. package/dist/cjs/runtime/resume.cjs.map +1 -0
  30. package/dist/cjs/runtime/sealed.cjs +107 -0
  31. package/dist/cjs/runtime/sealed.cjs.map +1 -0
  32. package/dist/cjs/runtime/server.cjs +415 -0
  33. package/dist/cjs/runtime/server.cjs.map +1 -0
  34. package/dist/cjs/runtime/snapshot.cjs +61 -0
  35. package/dist/cjs/runtime/snapshot.cjs.map +1 -0
  36. package/dist/cjs/runtime/types.cjs +20 -0
  37. package/dist/cjs/runtime/types.cjs.map +1 -0
  38. package/dist/cjs/runtime/wire.cjs +84 -0
  39. package/dist/cjs/runtime/wire.cjs.map +1 -0
  40. package/dist/esm/runtime/admission.mjs +133 -0
  41. package/dist/esm/runtime/admission.mjs.map +1 -0
  42. package/dist/esm/runtime/checkpoint.mjs +39 -0
  43. package/dist/esm/runtime/checkpoint.mjs.map +1 -0
  44. package/dist/esm/runtime/client.mjs +432 -0
  45. package/dist/esm/runtime/client.mjs.map +1 -0
  46. package/dist/esm/runtime/files.mjs +299 -0
  47. package/dist/esm/runtime/files.mjs.map +1 -0
  48. package/dist/esm/runtime/hostTools.mjs +164 -0
  49. package/dist/esm/runtime/hostTools.mjs.map +1 -0
  50. package/dist/esm/runtime/index.mjs +5 -0
  51. package/dist/esm/runtime/model.mjs +301 -0
  52. package/dist/esm/runtime/model.mjs.map +1 -0
  53. package/dist/esm/runtime/peer.mjs +209 -0
  54. package/dist/esm/runtime/peer.mjs.map +1 -0
  55. package/dist/esm/runtime/policy.mjs +75 -0
  56. package/dist/esm/runtime/policy.mjs.map +1 -0
  57. package/dist/esm/runtime/recovery/client.mjs +172 -0
  58. package/dist/esm/runtime/recovery/client.mjs.map +1 -0
  59. package/dist/esm/runtime/recovery/log.mjs +46 -0
  60. package/dist/esm/runtime/recovery/log.mjs.map +1 -0
  61. package/dist/esm/runtime/recovery/redis.mjs +239 -0
  62. package/dist/esm/runtime/recovery/redis.mjs.map +1 -0
  63. package/dist/esm/runtime/recovery/server.mjs +189 -0
  64. package/dist/esm/runtime/recovery/server.mjs.map +1 -0
  65. package/dist/esm/runtime/recovery/socket.mjs +297 -0
  66. package/dist/esm/runtime/recovery/socket.mjs.map +1 -0
  67. package/dist/esm/runtime/resume.mjs +111 -0
  68. package/dist/esm/runtime/resume.mjs.map +1 -0
  69. package/dist/esm/runtime/sealed.mjs +106 -0
  70. package/dist/esm/runtime/sealed.mjs.map +1 -0
  71. package/dist/esm/runtime/server.mjs +413 -0
  72. package/dist/esm/runtime/server.mjs.map +1 -0
  73. package/dist/esm/runtime/snapshot.mjs +60 -0
  74. package/dist/esm/runtime/snapshot.mjs.map +1 -0
  75. package/dist/esm/runtime/types.mjs +19 -0
  76. package/dist/esm/runtime/types.mjs.map +1 -0
  77. package/dist/esm/runtime/wire.mjs +80 -0
  78. package/dist/esm/runtime/wire.mjs.map +1 -0
  79. package/dist/types/agents/AgentContext.d.ts +4 -4
  80. package/dist/types/agents/projection.d.ts +1 -1
  81. package/dist/types/events.d.ts +2 -2
  82. package/dist/types/graphs/Graph.d.ts +13 -13
  83. package/dist/types/graphs/MultiAgentGraph.d.ts +2 -2
  84. package/dist/types/graphs/acceptedModelResponse.d.ts +1 -1
  85. package/dist/types/graphs/createGraph.d.ts +4 -4
  86. package/dist/types/graphs/graphFactory.d.ts +1 -1
  87. package/dist/types/graphs/handoff.d.ts +1 -1
  88. package/dist/types/harness/index.d.ts +2 -2
  89. package/dist/types/harness/model.d.ts +3 -3
  90. package/dist/types/harness/providerText.d.ts +2 -2
  91. package/dist/types/hitl/approvalReview.d.ts +1 -1
  92. package/dist/types/hitl/askUserQuestion.d.ts +1 -1
  93. package/dist/types/hitl/askUserQuestions.d.ts +1 -1
  94. package/dist/types/hitl/askUserQuestionsInterrupt.d.ts +1 -1
  95. package/dist/types/hooks/types.d.ts +2 -2
  96. package/dist/types/instrumentation.d.ts +1 -1
  97. package/dist/types/langfuse.d.ts +3 -3
  98. package/dist/types/langfuseConfig.d.ts +2 -2
  99. package/dist/types/langfuseRuntimeContext.d.ts +1 -1
  100. package/dist/types/langfuseRuntimeScope.d.ts +2 -2
  101. package/dist/types/langfuseSpanRegistry.d.ts +1 -1
  102. package/dist/types/langfuseToolOutputTracing.d.ts +3 -3
  103. package/dist/types/llm/anthropic/index.d.ts +1 -1
  104. package/dist/types/llm/bedrock/index.d.ts +1 -1
  105. package/dist/types/llm/bedrock/toolCache.d.ts +2 -2
  106. package/dist/types/llm/contextOverflowRecovery.d.ts +2 -2
  107. package/dist/types/llm/contextPressureMeter.d.ts +2 -2
  108. package/dist/types/llm/google/index.d.ts +1 -1
  109. package/dist/types/llm/init.d.ts +1 -1
  110. package/dist/types/llm/invoke.d.ts +9 -9
  111. package/dist/types/llm/mistral/index.d.ts +1 -1
  112. package/dist/types/llm/openai/index.d.ts +2 -2
  113. package/dist/types/llm/openrouter/index.d.ts +2 -2
  114. package/dist/types/llm/openrouter/toolCache.d.ts +2 -2
  115. package/dist/types/llm/prepareProviderRequest.d.ts +3 -3
  116. package/dist/types/llm/promptCacheTools.d.ts +1 -1
  117. package/dist/types/llm/providerRegistry.d.ts +1 -1
  118. package/dist/types/llm/providerTextBoundary.d.ts +2 -2
  119. package/dist/types/llm/providerTextControls.d.ts +1 -1
  120. package/dist/types/llm/providers.d.ts +2 -2
  121. package/dist/types/llm/request.d.ts +1 -1
  122. package/dist/types/llm/stream/chunkAdapters.d.ts +1 -1
  123. package/dist/types/llm/streamLimits.d.ts +1 -1
  124. package/dist/types/llm/truncation.d.ts +1 -1
  125. package/dist/types/llm/vertexai/index.d.ts +1 -1
  126. package/dist/types/messages/alternation.d.ts +1 -1
  127. package/dist/types/messages/anthropicToolCache.d.ts +2 -2
  128. package/dist/types/messages/assistantPhase.d.ts +3 -3
  129. package/dist/types/messages/budget.d.ts +1 -1
  130. package/dist/types/messages/cache.d.ts +1 -1
  131. package/dist/types/messages/contextPruning.d.ts +2 -2
  132. package/dist/types/messages/core.d.ts +1 -1
  133. package/dist/types/messages/fading.d.ts +1 -1
  134. package/dist/types/messages/format.d.ts +2 -2
  135. package/dist/types/messages/ids.d.ts +2 -2
  136. package/dist/types/messages/injected.d.ts +1 -1
  137. package/dist/types/messages/langchain.d.ts +1 -1
  138. package/dist/types/messages/prune.d.ts +4 -4
  139. package/dist/types/messages/recency.d.ts +1 -1
  140. package/dist/types/messages/toolResultTypes.d.ts +1 -1
  141. package/dist/types/openai/arguments.d.ts +1 -1
  142. package/dist/types/openai/index.d.ts +1 -1
  143. package/dist/types/openai/toolProjection.d.ts +1 -1
  144. package/dist/types/prompts/activityLabel.d.ts +2 -2
  145. package/dist/types/prompts/reasoningLabel.d.ts +1 -1
  146. package/dist/types/rerank/search.d.ts +1 -1
  147. package/dist/types/responses/index.d.ts +1 -1
  148. package/dist/types/run.d.ts +3 -3
  149. package/dist/types/runtime/admission.d.ts +30 -0
  150. package/dist/types/runtime/checkpoint.d.ts +14 -0
  151. package/dist/types/runtime/client.d.ts +12 -0
  152. package/dist/types/runtime/files.d.ts +75 -0
  153. package/dist/types/runtime/hostTools.d.ts +22 -0
  154. package/dist/types/runtime/identity.d.ts +2 -0
  155. package/dist/types/runtime/index.d.ts +12 -0
  156. package/dist/types/runtime/model.d.ts +42 -0
  157. package/dist/types/runtime/peer.d.ts +55 -0
  158. package/dist/types/runtime/policy.d.ts +43 -0
  159. package/dist/types/runtime/recovery/client.d.ts +12 -0
  160. package/dist/types/runtime/recovery/journal.d.ts +62 -0
  161. package/dist/types/runtime/recovery/log.d.ts +9 -0
  162. package/dist/types/runtime/recovery/redis.d.ts +17 -0
  163. package/dist/types/runtime/recovery/server.d.ts +37 -0
  164. package/dist/types/runtime/recovery/socket.d.ts +72 -0
  165. package/dist/types/runtime/resume.d.ts +66 -0
  166. package/dist/types/runtime/sealed.d.ts +19 -0
  167. package/dist/types/runtime/server.d.ts +21 -0
  168. package/dist/types/runtime/snapshot.d.ts +12 -0
  169. package/dist/types/runtime/types.d.ts +125 -0
  170. package/dist/types/runtime/wire.d.ts +3 -0
  171. package/dist/types/session/handlers.d.ts +1 -1
  172. package/dist/types/session/types.d.ts +1 -1
  173. package/dist/types/stream.d.ts +3 -3
  174. package/dist/types/summarization/index.d.ts +1 -1
  175. package/dist/types/summarization/input.d.ts +1 -1
  176. package/dist/types/summarization/node.d.ts +6 -6
  177. package/dist/types/summarization/retry.d.ts +2 -2
  178. package/dist/types/summarization/semanticIndex.d.ts +2 -2
  179. package/dist/types/summarization/toolBudget.d.ts +1 -1
  180. package/dist/types/summarization/usage.d.ts +1 -1
  181. package/dist/types/tools/ArtifactDelivery.d.ts +1 -1
  182. package/dist/types/tools/ArtifactTruncation.d.ts +1 -1
  183. package/dist/types/tools/BashExecutor.d.ts +2 -2
  184. package/dist/types/tools/BashProgrammaticToolCalling.d.ts +2 -2
  185. package/dist/types/tools/CallerCapabilities.d.ts +1 -1
  186. package/dist/types/tools/CodeExecutor.d.ts +4 -4
  187. package/dist/types/tools/CodeSessionFileSummary.d.ts +1 -1
  188. package/dist/types/tools/ProgrammaticCallerPolicy.d.ts +1 -1
  189. package/dist/types/tools/ProgrammaticToolCalling.d.ts +2 -2
  190. package/dist/types/tools/ReadFile.d.ts +1 -1
  191. package/dist/types/tools/SkillTool.d.ts +1 -1
  192. package/dist/types/tools/SubagentTool.d.ts +3 -3
  193. package/dist/types/tools/ToolNode.d.ts +5 -5
  194. package/dist/types/tools/ToolSearch.d.ts +2 -2
  195. package/dist/types/tools/cloudflare/CloudflareBridgeRuntime.d.ts +1 -1
  196. package/dist/types/tools/cloudflare/CloudflareProgrammaticToolCalling.d.ts +1 -1
  197. package/dist/types/tools/cloudflare/CloudflareSandboxExecutionEngine.d.ts +2 -2
  198. package/dist/types/tools/cloudflare/CloudflareSandboxTools.d.ts +1 -1
  199. package/dist/types/tools/diagnostics.d.ts +1 -1
  200. package/dist/types/tools/eagerEventExecution.d.ts +1 -1
  201. package/dist/types/tools/handlers.d.ts +3 -3
  202. package/dist/types/tools/intentArg.d.ts +1 -1
  203. package/dist/types/tools/local/CompileCheckTool.d.ts +2 -2
  204. package/dist/types/tools/local/FileCheckpointer.d.ts +1 -1
  205. package/dist/types/tools/local/LocalCodingTools.d.ts +2 -2
  206. package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -1
  207. package/dist/types/tools/local/LocalExecutionTools.d.ts +1 -1
  208. package/dist/types/tools/local/LocalProgrammaticToolCalling.d.ts +1 -1
  209. package/dist/types/tools/local/bashAst.d.ts +1 -1
  210. package/dist/types/tools/local/resolveLocalExecutionTools.d.ts +1 -1
  211. package/dist/types/tools/local/syntaxCheck.d.ts +1 -1
  212. package/dist/types/tools/ptcTimeout.d.ts +1 -1
  213. package/dist/types/tools/runStepResume.d.ts +1 -1
  214. package/dist/types/tools/schema.d.ts +1 -1
  215. package/dist/types/tools/search/anthropic.d.ts +1 -1
  216. package/dist/types/tools/skillCatalog.d.ts +1 -1
  217. package/dist/types/tools/subagent/InMemorySubagentTaskStore.d.ts +1 -1
  218. package/dist/types/tools/subagent/SubagentExecutor.d.ts +5 -5
  219. package/dist/types/tools/subagent/SubagentReplay.d.ts +3 -3
  220. package/dist/types/tools/subagent/childGraphConfig.d.ts +2 -2
  221. package/dist/types/tools/subagent/diagnostics.d.ts +2 -2
  222. package/dist/types/tools/subagent/hostArgs.d.ts +2 -2
  223. package/dist/types/tools/toolBatchReplay.d.ts +3 -3
  224. package/dist/types/types/activityLabel.d.ts +2 -2
  225. package/dist/types/types/graph.d.ts +10 -10
  226. package/dist/types/types/llm.d.ts +9 -9
  227. package/dist/types/types/reasoningLabel.d.ts +1 -1
  228. package/dist/types/types/run.d.ts +8 -8
  229. package/dist/types/types/stream.d.ts +5 -5
  230. package/dist/types/types/summarize.d.ts +2 -2
  231. package/dist/types/types/tools.d.ts +8 -8
  232. package/dist/types/utils/errors.d.ts +1 -1
  233. package/dist/types/utils/events.d.ts +3 -3
  234. package/dist/types/utils/handlers.d.ts +3 -3
  235. package/dist/types/utils/llm.d.ts +2 -2
  236. package/dist/types/utils/llmConfig.d.ts +1 -1
  237. package/dist/types/utils/title.d.ts +1 -1
  238. package/dist/types/utils/toolSessions.d.ts +1 -1
  239. package/package.json +22 -3
  240. package/src/runtime/admission.ts +224 -0
  241. package/src/runtime/checkpoint.ts +66 -0
  242. package/src/runtime/client.ts +674 -0
  243. package/src/runtime/files.ts +503 -0
  244. package/src/runtime/hostTools.ts +243 -0
  245. package/src/runtime/identity.ts +3 -0
  246. package/src/runtime/index.ts +33 -0
  247. package/src/runtime/model.ts +452 -0
  248. package/src/runtime/peer.ts +262 -0
  249. package/src/runtime/policy.ts +150 -0
  250. package/src/runtime/recovery/client.ts +232 -0
  251. package/src/runtime/recovery/journal.ts +88 -0
  252. package/src/runtime/recovery/log.ts +70 -0
  253. package/src/runtime/recovery/redis.ts +342 -0
  254. package/src/runtime/recovery/server.ts +280 -0
  255. package/src/runtime/recovery/socket.ts +422 -0
  256. package/src/runtime/resume.ts +268 -0
  257. package/src/runtime/sealed.ts +144 -0
  258. package/src/runtime/server.ts +653 -0
  259. package/src/runtime/snapshot.ts +87 -0
  260. package/src/runtime/types.ts +184 -0
  261. package/src/runtime/wire.ts +96 -0
@@ -0,0 +1,133 @@
1
+ import { HostChatModel, HostModelServiceError } from "../harness/model.mjs";
2
+ import "../main.mjs";
3
+ import { AsyncLocalStorage } from "node:async_hooks";
4
+ import { ensureHandler } from "@langchain/core/callbacks/manager";
5
+ import { z } from "zod";
6
+ //#region src/runtime/admission.ts
7
+ const modelAttemptSchema = z.object({
8
+ nodeId: z.string().uuid(),
9
+ modelId: z.string().uuid()
10
+ }).strict();
11
+ const invocationContextSchema = z.object({
12
+ version: z.literal(1),
13
+ runId: z.string().uuid()
14
+ }).strict();
15
+ const supportsModelInvocationContext = Number(HostChatModel.invocationContextVersion) === 1;
16
+ const blocked = () => new HostModelServiceError("blocked");
17
+ async function* scopedStream(storage, context, source) {
18
+ const iterator = storage.run(context, () => source()[Symbol.asyncIterator]());
19
+ try {
20
+ for (;;) {
21
+ const next = await storage.run(context, () => iterator.next());
22
+ if (next.done === true) return;
23
+ yield next.value;
24
+ }
25
+ } finally {
26
+ await storage.run(context, () => iterator.return?.());
27
+ }
28
+ }
29
+ function createWorkerModelLifecycle(agentId, maxEntries, peer) {
30
+ const parents = /* @__PURE__ */ new Map();
31
+ const nodes = /* @__PURE__ */ new Set();
32
+ const models = /* @__PURE__ */ new Map();
33
+ const attemptedNodes = /* @__PURE__ */ new Set();
34
+ const storage = new AsyncLocalStorage();
35
+ let admitted = false;
36
+ const budget = () => {
37
+ if (parents.size + nodes.size + models.size >= maxEntries) throw blocked();
38
+ };
39
+ const context = (manager) => {
40
+ if (admitted) return void 0;
41
+ const value = manager && models.get(manager.runId);
42
+ if (!value) throw blocked();
43
+ attemptedNodes.add(value.nodeId);
44
+ return value;
45
+ };
46
+ const end = async (nodeId, completed) => {
47
+ parents.delete(nodeId);
48
+ nodes.delete(nodeId);
49
+ for (const [modelId, attempt] of models) if (attempt.nodeId === nodeId) models.delete(modelId);
50
+ if (!attemptedNodes.delete(nodeId)) return;
51
+ if (z.object({
52
+ version: z.literal(1),
53
+ ok: z.literal(true),
54
+ admitted: z.boolean()
55
+ }).parse(await peer.call("model.node.end", {
56
+ nodeId,
57
+ completed
58
+ })).admitted) {
59
+ admitted = true;
60
+ parents.clear();
61
+ nodes.clear();
62
+ models.clear();
63
+ attemptedNodes.clear();
64
+ }
65
+ };
66
+ class CorrelatedHostModel extends HostChatModel {
67
+ _generate(messages, options, manager) {
68
+ return storage.run(context(manager), () => super._generate(messages, options));
69
+ }
70
+ async *_streamResponseChunks(messages, options, manager) {
71
+ yield* scopedStream(storage, context(manager), () => super._streamResponseChunks(messages, options, manager));
72
+ }
73
+ }
74
+ return {
75
+ current(context) {
76
+ if (admitted) return void 0;
77
+ if (supportsModelInvocationContext) {
78
+ const { runId } = invocationContextSchema.parse(context);
79
+ const attempt = models.get(runId);
80
+ if (!attempt) throw blocked();
81
+ attemptedNodes.add(attempt.nodeId);
82
+ return attempt;
83
+ }
84
+ const value = storage.getStore();
85
+ if (!value) throw blocked();
86
+ return value;
87
+ },
88
+ model: (options) => supportsModelInvocationContext ? new HostChatModel(options) : new CorrelatedHostModel(options),
89
+ callback: ensureHandler({
90
+ name: "librechat-remote-model-admission",
91
+ raiseError: true,
92
+ awaitHandlers: true,
93
+ handleChainStart: (_chain, _inputs, runId, parentRunId, _tags, metadata, _type, name) => {
94
+ if (admitted) return;
95
+ budget();
96
+ if (parentRunId != null && parentRunId.length > 0) parents.set(runId, parentRunId);
97
+ if (name === `agent=${agentId}` && metadata?.langgraph_node === name) nodes.add(runId);
98
+ },
99
+ handleChatModelStart: (_model, _messages, runId, parentRunId, _extra, _tags, metadata) => {
100
+ if (admitted) return;
101
+ if (metadata?.summarization === true || metadata?.agentId !== agentId || metadata.langgraph_node !== `agent=${agentId}`) return;
102
+ const seen = /* @__PURE__ */ new Set();
103
+ let parent = parentRunId;
104
+ while (parent != null && parent.length > 0 && !seen.has(parent)) {
105
+ if (nodes.has(parent)) {
106
+ budget();
107
+ models.set(runId, {
108
+ nodeId: parent,
109
+ modelId: runId
110
+ });
111
+ return;
112
+ }
113
+ seen.add(parent);
114
+ parent = parents.get(parent);
115
+ }
116
+ },
117
+ handleChainEnd: async (output, runId) => {
118
+ if (admitted) return;
119
+ if (!nodes.has(runId)) {
120
+ parents.delete(runId);
121
+ return;
122
+ }
123
+ const result = output;
124
+ await end(runId, Array.isArray(result?.messages) && result.messages.length > 0 && result.summarizationRequest == null);
125
+ },
126
+ handleChainError: (_error, runId) => admitted ? void 0 : end(runId, false)
127
+ })
128
+ };
129
+ }
130
+ //#endregion
131
+ export { createWorkerModelLifecycle, modelAttemptSchema, supportsModelInvocationContext };
132
+
133
+ //# sourceMappingURL=admission.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admission.mjs","names":[],"sources":["../../../src/runtime/admission.ts"],"mappings":";;;;;;AAiBA,MAAa,qBAAoD,EAC9D,OAAO;CAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,KAAK;CAAG,SAAS,EAAE,OAAO,CAAC,CAAC,KAAK;AAAE,CAAC,CAAC,CACjE,OAAO;AACV,MAAM,0BAA0B,EAC7B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AM,IAAI,KAAK;GACnB;GACA,uBACE,QACA,WACA,OACA,aACA,QACA,OACA,aACG;IACH,IAAI,UAAU;IACd,IACE,UAAU,kBAAkB,QAC5B,UAAU,YAAY,WACtB,SAAS,mBAAmB,SAAS,WAErC;IACF,MAAM,uBAAO,IAAI,IAAY;IAC7B,IAAI,SAAS;IACb,OAAO,UAAU,QAAQ,OAAO,SAAS,KAAK,CAAC,KAAK,IAAI,MAAM,GAAG;KAC/D,IAAI,MAAM,IAAI,MAAM,GAAG;MACrB,OAAO;MACP,OAAO,IAAI,OAAO;OAAE,QAAQ;OAAQ,SAAS;MAAM,CAAC;MACpD;KACF;KACA,KAAK,IAAI,MAAM;KACf,SAAS,QAAQ,IAAI,MAAM;IAC7B;GACF;GACA,gBAAgB,OAAO,QAAQ,UAAU;IACvC,IAAI,UAAU;IACd,IAAI,CAAC,MAAM,IAAI,KAAK,GAAG;KACrB,QAAQ,OAAO,KAAK;KACpB;IACF;IACA,MAAM,SAAS;IAIf,MAAM,IACJ,OACA,MAAM,QAAQ,QAAQ,QAAQ,KAC5B,OAAO,SAAS,SAAS,KACzB,OAAO,wBAAwB,IACnC;GACF;GACA,mBAAmB,QAAQ,UACzB,WAAW,KAAA,IAAY,IAAI,OAAO,KAAK;EAC3C,CAAC;CACH;AACF"}
@@ -0,0 +1,39 @@
1
+ import { BaseCheckpointSaver } from "../main.mjs";
2
+ //#region src/runtime/checkpoint.ts
3
+ function checkpointConfig(config) {
4
+ return { configurable: Object.fromEntries(Object.entries(config.configurable ?? {}).filter(([key, value]) => ([
5
+ "thread_id",
6
+ "checkpoint_ns",
7
+ "checkpoint_id"
8
+ ].includes(key) || key.startsWith("__librechat_")) && (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value == null))) };
9
+ }
10
+ var RemoteSdkCheckpointer = class extends BaseCheckpointSaver {
11
+ call;
12
+ constructor(call) {
13
+ super();
14
+ this.call = call;
15
+ }
16
+ async getTuple(...args) {
17
+ return await this.call("checkpoint.getTuple", [checkpointConfig(args[0])]);
18
+ }
19
+ async *list(...args) {
20
+ const tuples = await this.call("checkpoint.list", [checkpointConfig(args[0]), args[1] && {
21
+ ...args[1],
22
+ before: args[1].before ? checkpointConfig(args[1].before) : void 0
23
+ }]);
24
+ for (const tuple of tuples) if (tuple != null) yield tuple;
25
+ }
26
+ async put(...args) {
27
+ return await this.call("checkpoint.put", [checkpointConfig(args[0]), ...args.slice(1)]);
28
+ }
29
+ async putWrites(...args) {
30
+ await this.call("checkpoint.putWrites", [checkpointConfig(args[0]), ...args.slice(1)]);
31
+ }
32
+ async deleteThread() {
33
+ throw new Error("Runtime checkpoint deletion is not permitted");
34
+ }
35
+ };
36
+ //#endregion
37
+ export { RemoteSdkCheckpointer };
38
+
39
+ //# sourceMappingURL=checkpoint.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkpoint.mjs","names":[],"sources":["../../../src/runtime/checkpoint.ts"],"mappings":";;AAIA,SAAS,iBACP,QACkC;CAClC,OAAO,EACL,cAAc,OAAO,YACnB,OAAO,QAAQ,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAAC,QACvC,CAAC,KAAK,YACJ;EAAC;EAAa;EAAiB;CAAe,CAAC,CAAC,SAAS,GAAG,KAC3D,IAAI,WAAW,cAAc,OAC9B,OAAO,UAAU,YAChB,OAAO,UAAU,YACjB,OAAO,UAAU,aACjB,SAAS,KACf,CACF,EACF;AACF;AAEA,IAAa,wBAAb,cAA2C,oBAAoB;CAChC;CAA7B,YAAY,MAA+B;EACzC,MAAM;EADqB,KAAA,OAAA;CAE7B;CAEA,MAAM,SACJ,GAAG,MAC4B;EAC/B,OAAQ,MAAM,KAAK,KAAK,uBAAuB,CAC7C,iBAAiB,KAAK,EAAE,CAC1B,CAAC;CACH;CAEA,OAAO,KAAK,GAAG,MAA4D;EACzE,MAAM,SAAU,MAAM,KAAK,KAAK,mBAAmB,CACjD,iBAAiB,KAAK,EAAE,GACxB,KAAK,MAAM;GACT,GAAG,KAAK;GACR,QAAQ,KAAK,EAAE,CAAC,SAAS,iBAAiB,KAAK,EAAE,CAAC,MAAM,IAAI,KAAA;EAC9D,CACF,CAAC;EACD,KAAK,MAAM,SAAS,QAAQ,IAAI,SAAS,MAAM,MAAM;CACvD;CAEA,MAAM,IAAI,GAAG,MAA0D;EACrE,OAAQ,MAAM,KAAK,KAAK,kBAAkB,CACxC,iBAAiB,KAAK,EAAE,GACxB,GAAG,KAAK,MAAM,CAAC,CACjB,CAAC;CACH;CAEA,MAAM,UACJ,GAAG,MAC6B;EAChC,MAAM,KAAK,KAAK,wBAAwB,CACtC,iBAAiB,KAAK,EAAE,GACxB,GAAG,KAAK,MAAM,CAAC,CACjB,CAAC;CACH;CAEA,MAAM,eAA8B;EAClC,MAAM,IAAI,MAAM,8CAA8C;CAChE;AACF"}
@@ -0,0 +1,432 @@
1
+ import { HOOK_EVENTS, TOOL_APPROVAL_EXECUTION_SCOPE_CONFIG_KEY } from "../hooks/types.mjs";
2
+ import { GraphEvents } from "../common/enum.mjs";
3
+ import { executeHooks } from "../hooks/executeHooks.mjs";
4
+ import { createContentAggregator } from "../stream.mjs";
5
+ import { Run } from "../run.mjs";
6
+ import { BaseCheckpointSaver } from "../main.mjs";
7
+ import { createHostPolicyChannel } from "./policy.mjs";
8
+ import { createHostFileChannel } from "./files.mjs";
9
+ import { isRemoteSdkSecret, remoteSdkLimits } from "./types.mjs";
10
+ import { createHostToolService } from "./hostTools.mjs";
11
+ import { createHostModelChannel } from "./model.mjs";
12
+ import { createSnapshotReceiver } from "./snapshot.mjs";
13
+ import { createSdkPeer } from "./peer.mjs";
14
+ import { hydrateResumeRunSteps, reconcileRemoteResumeContent } from "./resume.mjs";
15
+ import { connectRecoveringSdkSocket } from "./recovery/client.mjs";
16
+ import { randomUUID } from "node:crypto";
17
+ import { z } from "zod";
18
+ import jwt from "jsonwebtoken";
19
+ import { WebSocket } from "ws";
20
+ //#region src/runtime/client.ts
21
+ async function createRemoteSdkRun({ config, identity, remote, resumeState, hostServices }) {
22
+ if (hostServices?.modelProfile && !hostServices.model) throw new Error("Builder model profile requires a host model");
23
+ if ((config.clientDelegatedToolNames?.length ?? 0) > 0) throw new Error("Remote SDK client-owned tools require a supported ownership adapter");
24
+ if (config.providerTextProtection && !hostServices?.providerText) throw new Error("Remote SDK provider protection requires a supported policy adapter");
25
+ identity = Object.freeze({ ...identity });
26
+ const limits = remoteSdkLimits(remote);
27
+ const url = new URL(remote.url);
28
+ if (url.username || url.password || url.hash || url.search || url.protocol !== "wss:" && !(url.protocol === "ws:" && [
29
+ "127.0.0.1",
30
+ "localhost",
31
+ "[::1]"
32
+ ].includes(url.hostname)) || !isRemoteSdkSecret(remote.secret)) throw new Error("Invalid SDK runtime connection configuration");
33
+ const run = await Run.create(config);
34
+ const graph = run.Graph;
35
+ if (graph == null) throw new Error("SDK runtime graph is unavailable");
36
+ let snapshot;
37
+ const projection = createContentAggregator();
38
+ if (resumeState) {
39
+ projection.contentParts.push(...resumeState.content);
40
+ hydrateResumeRunSteps(resumeState.steps, projection.stepMap, graph, resumeState.content);
41
+ for (const step of resumeState.steps) {
42
+ if (step.id.length === 0) continue;
43
+ graph.contentIndexMap.set(step.id, graph.contentData.length);
44
+ graph.contentData.push({ ...step });
45
+ }
46
+ }
47
+ const projectEvent = (event, data) => {
48
+ projection.aggregateContent({
49
+ event,
50
+ data
51
+ });
52
+ if (event === "on_run_step") {
53
+ const step = data;
54
+ const position = graph.contentIndexMap.get(step.id);
55
+ if (position === void 0) {
56
+ graph.contentIndexMap.set(step.id, graph.contentData.length);
57
+ graph.contentData.push(step);
58
+ } else graph.contentData[position] = step;
59
+ hydrateResumeRunSteps([step], void 0, graph);
60
+ } else if (event === "on_run_step_closed") {
61
+ const closed = data;
62
+ const step = graph.getRunStep(closed.id);
63
+ if (step) Object.assign(step, {
64
+ status: closed.status,
65
+ closed_at: closed.closed_at
66
+ });
67
+ }
68
+ };
69
+ const createResumeState = graph.createRunStepResumeState.bind(graph);
70
+ graph.createRunStepResumeState = () => snapshot?.runSteps ?? createResumeState();
71
+ graph.getContentParts = () => snapshot?.content ?? projection.contentParts.filter((part) => part != null);
72
+ run.getRunMessages = () => snapshot?.messages ?? [];
73
+ graph.getRunMessages = run.getRunMessages;
74
+ run.getInterrupt = () => snapshot?.interrupt;
75
+ run.getHaltReason = () => snapshot?.haltReason;
76
+ run.getDiscoveredTools = () => snapshot?.state?.getDiscoveredTools ?? [];
77
+ run.getCalibrationRatio = () => snapshot?.state?.getCalibrationRatio ?? 1;
78
+ run.getFadingTier = () => snapshot?.state?.getFadingTier;
79
+ run.getFadingTiers = () => snapshot?.state?.getFadingTiers ?? {};
80
+ run.getFadingTierResetAgentIds = () => snapshot?.state?.getFadingTierResetAgentIds ?? [];
81
+ run.getResolvedInstructionOverhead = () => snapshot?.state?.getResolvedInstructionOverhead;
82
+ run.getToolCount = () => snapshot?.state?.getToolCount ?? 0;
83
+ run.getOutputTruncated = () => snapshot?.state?.getOutputTruncated ?? false;
84
+ run.getHandoffOutcome = () => snapshot?.state?.getHandoffOutcome;
85
+ const candidate = config.graphConfig.compileOptions?.checkpointer;
86
+ const saver = candidate instanceof BaseCheckpointSaver ? candidate : void 0;
87
+ if (config.humanInTheLoop?.enabled === true && !saver) throw new Error("Remote SDK approvals require a host checkpointer");
88
+ const descriptors = (("agents" in config.graphConfig ? config.graphConfig.agents[0] : config.graphConfig).toolDefinitions ?? []).map((definition) => ({
89
+ definition,
90
+ reference: definition.name
91
+ }));
92
+ const toolHandler = config.customHandlers?.["on_tool_execute"];
93
+ if (descriptors.length && !toolHandler) throw new Error("Host tool handler is unavailable");
94
+ let invoked = false;
95
+ const execute = async (operation, input, options, resume, commandOptions) => {
96
+ options.signal?.throwIfAborted();
97
+ if (invoked) throw new Error("SDK runtime Run already invoked; create a fresh Run for continuation");
98
+ invoked = true;
99
+ const threadId = options.configurable?.thread_id ?? identity.conversationId ?? identity.runId;
100
+ if (typeof threadId !== "string" || identity.conversationId != null && identity.conversationId.length > 0 && identity.conversationId !== threadId) throw new Error("SDK runtime thread identity mismatch");
101
+ const boundConfigurable = {
102
+ ...options.configurable,
103
+ thread_id: threadId
104
+ };
105
+ const makeToken = (recovery) => jwt.sign({
106
+ protocolVersion: 1,
107
+ identity,
108
+ threadId,
109
+ invocationId: randomUUID(),
110
+ recovery
111
+ }, remote.secret, {
112
+ algorithm: "HS256",
113
+ audience: identity.runtimeId,
114
+ issuer: "librechat-sdk",
115
+ expiresIn: "60s"
116
+ });
117
+ const legacy = async () => {
118
+ const socket = new WebSocket(remote.url, {
119
+ headers: { Authorization: `Bearer ${makeToken()}` },
120
+ handshakeTimeout: limits.connectTimeoutMs,
121
+ maxPayload: limits.maxFrameBytes,
122
+ followRedirects: false
123
+ });
124
+ await new Promise((resolve, reject) => {
125
+ const abort = () => {
126
+ socket.terminate();
127
+ reject(Object.assign(/* @__PURE__ */ new Error("SDK runtime connection cancelled"), { name: "AbortError" }));
128
+ };
129
+ const cleanup = () => options.signal?.removeEventListener("abort", abort);
130
+ socket.once("open", () => {
131
+ cleanup();
132
+ resolve();
133
+ });
134
+ socket.once("error", () => {
135
+ cleanup();
136
+ reject(/* @__PURE__ */ new Error("SDK runtime connection failed"));
137
+ });
138
+ options.signal?.addEventListener("abort", abort, { once: true });
139
+ if (options.signal?.aborted === true) abort();
140
+ });
141
+ return socket;
142
+ };
143
+ const modelAdmission = hostServices?.modelLifecycle?.attach(options.callbacks) === true;
144
+ const socket = await (remote.recovery ? connectRecoveringSdkSocket({
145
+ url: remote.url,
146
+ token: makeToken,
147
+ generation: typeof boundConfigurable.__librechat_checkpoint_ns === "string" ? boundConfigurable.__librechat_checkpoint_ns : void 0,
148
+ limits,
149
+ recovery: remote.recovery,
150
+ signal: options.signal,
151
+ onError: remote.onError
152
+ }) : legacy()).catch((error) => {
153
+ hostServices?.modelLifecycle?.dispose();
154
+ throw error;
155
+ });
156
+ const execution = new AbortController();
157
+ const providerText = hostServices?.providerText ? createHostPolicyChannel(hostServices.providerText, limits) : void 0;
158
+ const terminal = createSnapshotReceiver(limits.maxBufferedBytes);
159
+ snapshot = void 0;
160
+ let settled = false;
161
+ const hostInvocations = /* @__PURE__ */ new Set();
162
+ const advertisedHooks = HOOK_EVENTS.filter((event) => config.hooks?.hasHookFor(event, identity.runId) === true);
163
+ let hostFileChannel;
164
+ let hostModelChannel;
165
+ const result = new Promise((resolve, reject) => {
166
+ const finish = (value) => {
167
+ if (settled) return;
168
+ settled = true;
169
+ if (value == null || hostServices?.modelLifecycle?.failure()) reject(options.signal?.aborted === true ? Object.assign(/* @__PURE__ */ new Error("SDK runtime execution cancelled"), { name: "AbortError" }) : hostServices?.modelLifecycle?.failure() ?? /* @__PURE__ */ new Error("SDK runtime execution failed"));
170
+ else resolve(value);
171
+ };
172
+ hostModelChannel = hostServices?.model ? createHostModelChannel({
173
+ model: hostServices.model,
174
+ lifecycle: modelAdmission ? hostServices.modelLifecycle : void 0,
175
+ peer: { call: (...args) => peer.call(...args) },
176
+ limits,
177
+ signal: execution.signal
178
+ }) : void 0;
179
+ hostFileChannel = hostServices?.files ? createHostFileChannel({
180
+ files: hostServices.files,
181
+ identity,
182
+ peer: { call: (...args) => peer.call(...args) },
183
+ limits,
184
+ signal: execution.signal
185
+ }) : void 0;
186
+ let hostToolInvoke;
187
+ const peer = createSdkPeer(socket, {
188
+ ...limits,
189
+ timeoutMs: limits.rpcTimeoutMs,
190
+ onClose: () => {
191
+ execution.abort();
192
+ finish();
193
+ },
194
+ onError: remote.onError,
195
+ onFrame: async (frame) => {
196
+ if (frame.type === "event") {
197
+ const event = z.nativeEnum(GraphEvents).parse(frame.name);
198
+ if (event === "on_tool_execute") throw new Error("Remote events cannot invoke host tools");
199
+ projectEvent(event, frame.data);
200
+ await config.customHandlers?.[event]?.handle(event, frame.data, frame.metadata, graph);
201
+ } else if (frame.type === "snapshot") terminal.accept(frame.data);
202
+ else if (frame.type === "done") {
203
+ if (hostInvocations.size) throw new Error("Host tool execution has not drained");
204
+ finish(terminal.finish(frame.data));
205
+ } else if (frame.type === "error") finish();
206
+ else throw new Error("Unexpected SDK runtime frame");
207
+ },
208
+ onCall: async (method, data, _timeoutMs, signal) => {
209
+ if (execution.signal.aborted || options.signal?.aborted === true) throw new Error("SDK runtime execution stopped");
210
+ if (method.startsWith("files.")) {
211
+ if (!hostFileChannel) throw new Error("Host files are unavailable");
212
+ const invocation = hostFileChannel.call(method, data, signal);
213
+ hostInvocations.add(invocation);
214
+ try {
215
+ return await invocation;
216
+ } finally {
217
+ hostInvocations.delete(invocation);
218
+ }
219
+ }
220
+ if (method === "model.node.end") {
221
+ if (!modelAdmission || !hostServices.modelLifecycle) throw new Error("Model admission unavailable");
222
+ return {
223
+ version: 1,
224
+ ok: true,
225
+ admitted: hostServices.modelLifecycle.end(data)
226
+ };
227
+ }
228
+ if (method === "model.invoke" || method === "model.stream") {
229
+ if (!hostModelChannel) throw new Error("Host model is unavailable");
230
+ const invocation = hostModelChannel.call(method, data, signal);
231
+ hostInvocations.add(invocation);
232
+ try {
233
+ return await invocation;
234
+ } finally {
235
+ hostInvocations.delete(invocation);
236
+ }
237
+ }
238
+ if (method === "policy.providerText") {
239
+ if (!providerText) throw new Error("Host provider policy is unavailable");
240
+ return providerText.inspect(data, signal ? AbortSignal.any([execution.signal, signal]) : execution.signal);
241
+ }
242
+ if (method === "tools") {
243
+ if (!toolHandler || !descriptors.length) throw new Error("Host tools are unavailable");
244
+ hostToolInvoke ??= createHostToolService({
245
+ identity,
246
+ tools: descriptors,
247
+ handler: toolHandler,
248
+ graph,
249
+ metadata: options.metadata,
250
+ configurable: {
251
+ ...options.configurable,
252
+ user_id: identity.userId,
253
+ run_id: identity.runId,
254
+ thread_id: threadId
255
+ },
256
+ peer,
257
+ signal: execution.signal
258
+ });
259
+ const invocation = hostToolInvoke(data, signal);
260
+ hostInvocations.add(invocation);
261
+ try {
262
+ return await invocation;
263
+ } finally {
264
+ hostInvocations.delete(invocation);
265
+ }
266
+ }
267
+ if (method === "hook") {
268
+ if (config.hooks == null) throw new Error("Host hooks are unavailable");
269
+ const args = data;
270
+ if (args.input == null || !advertisedHooks.includes(args.input.hook_event_name)) throw new Error("Host hook is not enabled");
271
+ return executeHooks({
272
+ registry: config.hooks,
273
+ input: {
274
+ ...args.input,
275
+ runId: identity.runId,
276
+ threadId
277
+ },
278
+ matchQuery: args.matchQuery,
279
+ sessionId: identity.runId,
280
+ signal: execution.signal
281
+ });
282
+ }
283
+ if (!saver || typeof saver !== "object" || !method.startsWith("checkpoint.")) throw new Error("Unsupported SDK operation");
284
+ const args = data;
285
+ const scope = (config, before = false) => {
286
+ const configurable = config.configurable;
287
+ const ns = configurable?.checkpoint_ns ?? "";
288
+ if ((!before || configurable?.thread_id != null) && configurable?.thread_id !== threadId || configurable?.__librechat_checkpoint_ns != null && configurable.__librechat_checkpoint_ns !== boundConfigurable.__librechat_checkpoint_ns || typeof ns !== "string" || configurable?.checkpoint_id != null && typeof configurable.checkpoint_id !== "string") throw new Error("Checkpoint scope mismatch");
289
+ return { configurable: {
290
+ thread_id: threadId,
291
+ checkpoint_ns: ns,
292
+ ...configurable?.checkpoint_id != null ? { checkpoint_id: configurable.checkpoint_id } : {},
293
+ ...Object.fromEntries(Object.entries(boundConfigurable).filter(([key]) => key.startsWith("__librechat_")))
294
+ } };
295
+ };
296
+ args[0] = scope(args[0]);
297
+ if (method === "checkpoint.getTuple") return saver.getTuple(args[0]);
298
+ if (method === "checkpoint.put") return saver.put(...args);
299
+ if (method === "checkpoint.putWrites") return saver.putWrites(...data);
300
+ if (method === "checkpoint.list") {
301
+ const list = z.object({
302
+ limit: z.number().int().nonnegative().optional(),
303
+ filter: z.record(z.string(), z.unknown()).optional(),
304
+ before: z.object({ configurable: z.record(z.string(), z.unknown()).optional() }).optional()
305
+ }).strict().parse(Array.isArray(data) ? data[1] ?? {} : {});
306
+ const limit = Math.min(list.limit ?? 32, 32);
307
+ if (limit === 0) return [];
308
+ const tuples = [];
309
+ for await (const tuple of saver.list(args[0], {
310
+ limit,
311
+ filter: list.filter,
312
+ before: list.before ? scope(list.before, true) : void 0
313
+ })) {
314
+ tuples.push(tuple);
315
+ if (tuples.length >= limit) break;
316
+ }
317
+ return tuples;
318
+ }
319
+ throw new Error("Unsupported SDK operation");
320
+ }
321
+ });
322
+ const abort = () => {
323
+ execution.abort();
324
+ socket.close(1e3);
325
+ finish();
326
+ };
327
+ options.signal?.addEventListener("abort", abort, { once: true });
328
+ if (options.signal?.aborted === true) abort();
329
+ const timer = setTimeout(abort, limits.maxRunMs);
330
+ timer.unref();
331
+ socket.once("close", () => {
332
+ clearTimeout(timer);
333
+ options.signal?.removeEventListener("abort", abort);
334
+ });
335
+ const agent = "agents" in config.graphConfig ? config.graphConfig.agents[0] : config.graphConfig;
336
+ const start = {
337
+ transportVersion: 2,
338
+ files: hostFileChannel?.descriptor,
339
+ modelAdmission: modelAdmission ? {
340
+ version: 1,
341
+ maxEntries: hostServices.modelLifecycle.maxEntries
342
+ } : void 0,
343
+ model: hostModelChannel?.descriptor,
344
+ providerText: providerText?.descriptor,
345
+ hostTools: descriptors.length ? descriptors : void 0,
346
+ operation,
347
+ input,
348
+ resume,
349
+ commandOptions,
350
+ options: {
351
+ recursionLimit: options.recursionLimit,
352
+ configurable: {
353
+ thread_id: threadId,
354
+ checkpoint_ns: options.configurable?.checkpoint_ns,
355
+ __librechat_checkpoint_ns: options.configurable?.__librechat_checkpoint_ns,
356
+ [TOOL_APPROVAL_EXECUTION_SCOPE_CONFIG_KEY]: options.configurable?.[TOOL_APPROVAL_EXECUTION_SCOPE_CONFIG_KEY],
357
+ run_id: identity.runId,
358
+ user_id: identity.userId
359
+ }
360
+ },
361
+ handlers: [...new Set([
362
+ ...Object.keys(config.customHandlers ?? {}),
363
+ "on_run_step",
364
+ "on_run_step_delta",
365
+ "on_run_step_completed",
366
+ "on_run_step_closed",
367
+ "on_message_delta",
368
+ "on_reasoning_delta"
369
+ ])].filter((name) => name !== "on_tool_execute"),
370
+ hooks: advertisedHooks,
371
+ checkpoint: Boolean(saver),
372
+ humanInTheLoop: config.humanInTheLoop,
373
+ streamLimits: config.streamLimits,
374
+ agent: {
375
+ id: identity.agentId,
376
+ name: agent.name,
377
+ instructions: agent.instructions,
378
+ model: hostServices?.modelProfile
379
+ }
380
+ };
381
+ (async () => {
382
+ const capabilities = await peer.call("capabilities", null);
383
+ if (capabilities?.transportVersion !== 2) throw new Error("Worker transport capability unavailable");
384
+ if (hostFileChannel && capabilities.hostFiles !== 1) throw new Error("Worker host file capability unavailable");
385
+ if (modelAdmission && capabilities.modelAdmission !== 1) throw new Error("Worker model admission capability unavailable");
386
+ if (modelAdmission && hostServices.providerText && capabilities.modelAdmissionWithProviderText !== 1) throw new Error("Worker protected model admission capability unavailable");
387
+ if (hostServices?.modelProfile && capabilities.builderModel !== 1) throw new Error("Worker builder model capability unavailable");
388
+ if (hostServices?.model && capabilities.hostModel !== 1) throw new Error("Worker host model capability unavailable");
389
+ if (providerText && capabilities.providerText !== 1) throw new Error("Worker provider policy capability unavailable");
390
+ if (descriptors.length) {
391
+ if (capabilities.hostTools !== 2) throw new Error("Worker host tool capability unavailable");
392
+ }
393
+ await peer.call("run", start);
394
+ })().catch(() => finish());
395
+ });
396
+ try {
397
+ snapshot = await result;
398
+ if (operation === "resume" && resumeState != null && resumeState.content.length > 0) snapshot.content = reconcileRemoteResumeContent(projection.contentParts.slice(0, resumeState.content.length), snapshot);
399
+ if (snapshot.runSteps) graph.restoreRunStepResumeState(snapshot.runSteps);
400
+ return snapshot.content?.filter(Boolean);
401
+ } finally {
402
+ execution.abort();
403
+ hostServices?.modelLifecycle?.dispose();
404
+ providerText?.dispose();
405
+ hostModelChannel?.dispose();
406
+ hostFileChannel?.dispose();
407
+ await Promise.allSettled([...hostInvocations]);
408
+ socket.close(1e3);
409
+ if ("waitForClose" in socket) {
410
+ let timeout;
411
+ await Promise.race([socket.waitForClose(), new Promise((resolve) => {
412
+ timeout = setTimeout(() => {
413
+ socket.terminate();
414
+ resolve();
415
+ }, remote.recovery.maxDisconnectMs);
416
+ })]);
417
+ clearTimeout(timeout);
418
+ }
419
+ if (snapshot?.interrupt == null) config.hooks?.clearSession(identity.runId);
420
+ }
421
+ };
422
+ run.processStream = (input, options) => {
423
+ if (!("messages" in input)) throw new Error("Use the SDK resume entry point for continuation");
424
+ return execute("start", input, options);
425
+ };
426
+ run.resume = (resume, options, _streamOptions, commandOptions) => execute("resume", { messages: [] }, options, resume, commandOptions);
427
+ return run;
428
+ }
429
+ //#endregion
430
+ export { createRemoteSdkRun };
431
+
432
+ //# sourceMappingURL=client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.mjs","names":[],"sources":["../../../src/runtime/client.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;AA+CA,eAAsB,mBAAmB,EACvC,QACA,UACA,QACA,aACA,gBAOgC;CAChC,IAAI,cAAc,gBAAgB,CAAC,aAAa,OAC9C,MAAM,IAAI,MAAM,6CAA6C;CAC/D,KAAK,OAAO,0BAA0B,UAAU,KAAK,GACnD,MAAM,IAAI,MACR,qEACF;CACF,IAAI,OAAO,0BAA0B,CAAC,cAAc,cAClD,MAAM,IAAI,MACR,oEACF;CACF,WAAW,OAAO,OAAO,EAAE,GAAG,SAAS,CAAC;CACxC,MAAM,SAAS,gBAAgB,MAAM;CACrC,MAAM,MAAM,IAAI,IAAI,OAAO,GAAG;CAC9B,IACE,IAAI,YACJ,IAAI,YACJ,IAAI,QACJ,IAAI,UACH,IAAI,aAAa,UAChB,EACE,IAAI,aAAa,SACjB;EAAC;EAAa;EAAa;CAAO,CAAC,CAAC,SAAS,IAAI,QAAQ,MAE7D,CAAC,kBAAkB,OAAO,MAAM,GAEhC,MAAM,IAAI,MAAM,8CAA8C;CAChE,MAAM,MAAM,MAAM,IAAI,OAAO,MAAM;CACnC,MAAM,QAAQ,IAAI;CAClB,IAAI,SAAS,MAAM,MAAM,IAAI,MAAM,kCAAkC;CACrE,IAAI;CACJ,MAAM,aAAa,wBAAwB;CAC3C,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