@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,243 @@
1
+ import { z } from 'zod';
2
+ import { randomUUID } from 'node:crypto';
3
+ import type {
4
+ EventHandler,
5
+ HostToolDescriptor,
6
+ HostToolRequest,
7
+ HostToolService,
8
+ HostToolEvents,
9
+ HostToolSessionUpdate,
10
+ ToolExecuteResult,
11
+ } from '@/index';
12
+ import type { SdkAgentIdentity } from './identity';
13
+ import type { SdkRpc } from './peer';
14
+ import { GraphEvents } from '@/index';
15
+
16
+ const toolResultSchema = z.object({
17
+ id: z.string().uuid(),
18
+ result: z
19
+ .object({
20
+ toolCallId: z.string().min(1),
21
+ status: z.enum(['success', 'error']),
22
+ })
23
+ .passthrough(),
24
+ });
25
+
26
+ /** Local credentials/configuration are supplied by the authenticated host, never by the worker. */
27
+ export function createHostToolService(options: {
28
+ identity: Readonly<SdkAgentIdentity>;
29
+ tools: HostToolDescriptor[];
30
+ handler: EventHandler;
31
+ graph?: Parameters<EventHandler['handle']>[3];
32
+ configurable: Record<string, unknown>;
33
+ metadata?: Record<string, unknown>;
34
+ peer: { call: SdkRpc };
35
+ signal: AbortSignal;
36
+ }): (
37
+ data: unknown,
38
+ invocationSignal?: AbortSignal
39
+ ) => Promise<ToolExecuteResult[]> {
40
+ const references = new Map(
41
+ options.tools.map((t) => [t.definition.name, t.reference])
42
+ );
43
+ return async (
44
+ data: unknown,
45
+ invocationSignal?: AbortSignal
46
+ ): Promise<ToolExecuteResult[]> => {
47
+ const signal = invocationSignal
48
+ ? AbortSignal.any([options.signal, invocationSignal])
49
+ : options.signal;
50
+ const envelope = z
51
+ .object({
52
+ id: z.string().uuid(),
53
+ incremental: z.boolean(),
54
+ request: z.object({
55
+ version: z.literal(1),
56
+ identity: z.record(z.string(), z.unknown()),
57
+ executingAgentId: z.string().optional(),
58
+ executionContext: z.unknown().optional(),
59
+ callerCapabilityProjection: z.unknown().optional(),
60
+ calls: z
61
+ .array(
62
+ z.object({
63
+ reference: z.string(),
64
+ call: z
65
+ .object({
66
+ id: z.string().min(1),
67
+ name: z.string(),
68
+ args: z.record(z.string(), z.unknown()),
69
+ })
70
+ .passthrough(),
71
+ })
72
+ )
73
+ .min(1),
74
+ }),
75
+ })
76
+ .parse(data);
77
+ const request = envelope.request as HostToolRequest;
78
+ for (const key of [
79
+ 'runtimeId',
80
+ 'agentId',
81
+ 'runId',
82
+ 'userId',
83
+ 'tenantId',
84
+ 'conversationId',
85
+ ] as const)
86
+ if (request.identity[key] !== options.identity[key])
87
+ throw new Error('Host tool identity mismatch');
88
+ if (
89
+ request.executionContext !== undefined ||
90
+ (request.executingAgentId !== undefined &&
91
+ request.executingAgentId !== options.identity.agentId)
92
+ )
93
+ throw new Error('Host tool execution subject is unsupported');
94
+ const ids = new Set<string>();
95
+ for (const { call, reference } of request.calls) {
96
+ if (references.get(call.name) !== reference || ids.has(call.id))
97
+ throw new Error('Host tool capability mismatch');
98
+ ids.add(call.id);
99
+ }
100
+ signal.throwIfAborted();
101
+ const notifications: Promise<unknown>[] = [];
102
+ let active = true;
103
+ let resolve!: (results: ToolExecuteResult[]) => void;
104
+ let reject!: (error: Error) => void;
105
+ const result = new Promise<ToolExecuteResult[]>((yes, no) => {
106
+ resolve = yes;
107
+ reject = no;
108
+ });
109
+ // Install rejection handling before invoking a handler that may reject synchronously.
110
+ void result.catch(() => undefined);
111
+ const abort = (): void =>
112
+ reject(new Error('Host tool invocation cancelled'));
113
+ signal.addEventListener('abort', abort, { once: true });
114
+ try {
115
+ await options.handler.handle(
116
+ GraphEvents.ON_TOOL_EXECUTE,
117
+ {
118
+ toolCalls: request.calls.map((c) => c.call),
119
+ userId: options.identity.userId,
120
+ agentId: options.identity.agentId,
121
+ configurable: options.configurable,
122
+ metadata: options.metadata,
123
+ callerCapabilityProjection: request.callerCapabilityProjection,
124
+ signal,
125
+ resolve,
126
+ reject,
127
+ ...(envelope.incremental
128
+ ? {
129
+ onResult: (value: ToolExecuteResult): void => {
130
+ if (!active || signal.aborted) return;
131
+ if (!ids.has(value.toolCallId))
132
+ throw new Error('Invalid incremental tool receipt');
133
+ const notice = options.peer.call('tool.result', {
134
+ id: envelope.id,
135
+ result: value,
136
+ });
137
+ void notice.catch(() => undefined);
138
+ notifications.push(notice);
139
+ },
140
+ }
141
+ : {}),
142
+ },
143
+ options.metadata,
144
+ options.graph
145
+ );
146
+ // Handler settlement is the drain boundary: async cancellation cleanup may refresh
147
+ // sessions. Never publish a final receipt while that cleanup is still running.
148
+ signal.throwIfAborted();
149
+ const results = await result;
150
+ active = false;
151
+ await Promise.all(notifications);
152
+ signal.throwIfAborted();
153
+ return results;
154
+ } finally {
155
+ active = false;
156
+ signal.removeEventListener('abort', abort);
157
+ for (const { call } of request.calls) {
158
+ notifications.push(
159
+ options.peer.call('tool.session', {
160
+ id: envelope.id,
161
+ update: {
162
+ toolCallId: call.id,
163
+ context: {
164
+ codeSessionContext: call.codeSessionContext,
165
+ codeSessionBaselineId: call.codeSessionBaselineId,
166
+ retainCodeSessionInputs: call.retainCodeSessionInputs,
167
+ runtimeSessionHint: call.runtimeSessionHint,
168
+ },
169
+ },
170
+ })
171
+ );
172
+ }
173
+ await Promise.all(notifications);
174
+ signal.throwIfAborted();
175
+ }
176
+ };
177
+ }
178
+
179
+ export function createWorkerToolService(peer: { call: SdkRpc }): {
180
+ service: HostToolService;
181
+ accept: (data: unknown, kind?: 'result' | 'session') => null;
182
+ } {
183
+ const pending = new Map<
184
+ string,
185
+ { events: HostToolEvents; signal?: AbortSignal }
186
+ >();
187
+ return {
188
+ service: {
189
+ version: 1,
190
+ invoke: async (request, signal, events): Promise<ToolExecuteResult[]> => {
191
+ signal?.throwIfAborted();
192
+ const id = randomUUID();
193
+ if (events) pending.set(id, { events, signal });
194
+ try {
195
+ return (await peer.call(
196
+ 'tools',
197
+ {
198
+ id,
199
+ request,
200
+ incremental: Boolean(events?.onResult),
201
+ },
202
+ undefined,
203
+ signal
204
+ )) as ToolExecuteResult[];
205
+ } finally {
206
+ pending.delete(id);
207
+ }
208
+ },
209
+ },
210
+ accept: (data, kind = 'result'): null => {
211
+ if (kind === 'session') {
212
+ const value = z
213
+ .object({
214
+ id: z.string().uuid(),
215
+ update: z
216
+ .object({
217
+ toolCallId: z.string(),
218
+ context: z
219
+ .object({
220
+ codeSessionContext: z.unknown().optional(),
221
+ codeSessionBaselineId: z.string().optional(),
222
+ retainCodeSessionInputs: z.literal(true).optional(),
223
+ runtimeSessionHint: z.string().optional(),
224
+ })
225
+ .strict(),
226
+ })
227
+ .strict(),
228
+ })
229
+ .parse(data);
230
+ const events = pending.get(value.id);
231
+ if (!events) throw new Error('Unknown tool session invocation');
232
+ events.events.onSessionUpdate(value.update as HostToolSessionUpdate);
233
+ return null;
234
+ }
235
+ const value = toolResultSchema.parse(data);
236
+ const handler = pending.get(value.id);
237
+ if (!handler) throw new Error('Unknown tool result invocation');
238
+ if (handler.signal?.aborted !== true)
239
+ handler.events.onResult?.(value.result as ToolExecuteResult);
240
+ return null;
241
+ },
242
+ };
243
+ }
@@ -0,0 +1,3 @@
1
+ import type { ExecutionIdentity } from '@/index';
2
+
3
+ export type SdkAgentIdentity = Readonly<ExecutionIdentity>;
@@ -0,0 +1,33 @@
1
+ export { createRemoteSdkServer } from './server';
2
+ export { createRemoteSdkRun } from './client';
3
+ export { createRedisRuntimeJournal } from './recovery/redis';
4
+ export type { RemoteSdkServerOptions } from './server';
5
+ export type { SdkAgentIdentity } from './identity';
6
+ export type {
7
+ RemoteSdkFactoryInput,
8
+ RemoteSdkHostServices,
9
+ RemoteSdkOptions,
10
+ RemoteSdkResumeState,
11
+ RemoteSdkLimits,
12
+ RemoteSdkModelProfile,
13
+ } from './types';
14
+ export type { HostModelLifecycle, RemoteModelAttempt } from './admission';
15
+ export type {
16
+ RuntimeJournalRedis,
17
+ RuntimeJournalLimits,
18
+ } from './recovery/redis';
19
+ export type {
20
+ RuntimeJournal,
21
+ RuntimeJournalSession,
22
+ RuntimeJournalLease,
23
+ RuntimeJournalResult,
24
+ RuntimeJournalState,
25
+ RuntimeJournalFailure,
26
+ } from './recovery/journal';
27
+ export type { RuntimeRecoveryOptions } from './recovery/server';
28
+ export type { RemoteSdkRecoveryOptions } from './types';
29
+ export {
30
+ normalizeResumeRunStepIndices,
31
+ hydrateResumeRunSteps,
32
+ createContentIndexOffsetHandlers,
33
+ } from './resume';