@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,342 @@
1
+ import { createHash } from 'node:crypto';
2
+ import type {
3
+ RuntimeJournal,
4
+ RuntimeJournalFailure,
5
+ RuntimeJournalResult,
6
+ RuntimeJournalState,
7
+ } from './journal';
8
+
9
+ /** Operator-supplied client; no app singleton or credentials cross the runtime boundary. */
10
+ export interface RuntimeJournalRedis {
11
+ evalsha?(
12
+ sha: string,
13
+ numberOfKeys: number,
14
+ ...args: Array<string | number>
15
+ ): Promise<unknown>;
16
+ eval(
17
+ script: string,
18
+ numberOfKeys: number,
19
+ ...args: Array<string | number>
20
+ ): Promise<unknown>;
21
+ }
22
+ export interface RuntimeJournalLimits {
23
+ prefix: string;
24
+ retentionMs: number;
25
+ leaseMs: number;
26
+ maxFrames: number;
27
+ maxBytes: number;
28
+ maxBatchFrames: number;
29
+ maxBatchBytes: number;
30
+ }
31
+ const SCRIPT = `
32
+ local op, scope, owner = ARGV[1], ARGV[2], ARGV[3]
33
+ local t = redis.call('TIME')
34
+ local now = tonumber(t[1]) * 1000 + math.floor(tonumber(t[2]) / 1000)
35
+ local retention, lease = tonumber(ARGV[5]), tonumber(ARGV[6])
36
+ local function touch()
37
+ for _, key in ipairs(KEYS) do redis.call('PEXPIRE', key, retention) end
38
+ end
39
+ local function fail(code) return {0, code} end
40
+ if op == 'create' and redis.call('EXISTS', KEYS[1]) == 0 then
41
+ redis.call('HSET', KEYS[1], 'scope', scope, 'owner', owner, 'epoch', 1,
42
+ 'until', now + lease, 'head', 0, 'ack', 0, 'bytes', 0, 'state', 'open', 'started', 0)
43
+ touch()
44
+ return {1, 1}
45
+ end
46
+ if redis.call('EXISTS', KEYS[1]) == 0 then return fail('missing') end
47
+ if redis.call('HGET', KEYS[1], 'scope') ~= scope then return fail('scope_mismatch') end
48
+ if op == 'purge' then redis.call('DEL', unpack(KEYS)); return {1} end
49
+ local state = redis.call('HGET', KEYS[1], 'state')
50
+ local head = tonumber(redis.call('HGET', KEYS[1], 'head'))
51
+ local ack = tonumber(redis.call('HGET', KEYS[1], 'ack'))
52
+ if op == 'read' then
53
+ local after, count = tonumber(ARGV[10]), tonumber(ARGV[11])
54
+ if after > head then return fail('cursor_ahead') end
55
+ local frames = redis.call('LRANGE', KEYS[2], after, after + count - 1)
56
+ return {1, state, redis.call('HGET', KEYS[1], 'started'), head, ack, frames}
57
+ end
58
+ -- A lost reply to a terminal append must remain retryable, but only by its original owner.
59
+ if op == 'append' then
60
+ local receipt = redis.call('HGET', KEYS[3], ARGV[10])
61
+ if receipt then
62
+ if redis.call('HGET', KEYS[1], 'owner') ~= owner or
63
+ tonumber(redis.call('HGET', KEYS[1], 'epoch')) ~= tonumber(ARGV[4]) then return fail('fenced') end
64
+ local decoded = cjson.decode(receipt)
65
+ if decoded[3] ~= ARGV[11] then return fail('batch_conflict') end
66
+ return {1, decoded[1], decoded[2]}
67
+ end
68
+ end
69
+ if state ~= 'open' then return fail('closed') end
70
+ local currentOwner = redis.call('HGET', KEYS[1], 'owner')
71
+ local epoch = tonumber(redis.call('HGET', KEYS[1], 'epoch'))
72
+ local expires = tonumber(redis.call('HGET', KEYS[1], 'until'))
73
+ if op == 'create' then
74
+ if currentOwner ~= owner or expires <= now then return fail('already_exists') end
75
+ return {1, epoch}
76
+ end
77
+ if op == 'claim' then
78
+ if currentOwner ~= owner and expires > now then return fail('fenced') end
79
+ if expires <= now or currentOwner ~= owner then epoch = epoch + 1 end
80
+ redis.call('HSET', KEYS[1], 'owner', owner, 'epoch', epoch, 'until', now + lease)
81
+ touch()
82
+ return {1, epoch, redis.call('HGET', KEYS[1], 'started')}
83
+ end
84
+ if currentOwner ~= owner or epoch ~= tonumber(ARGV[4]) or expires <= now then return fail('fenced') end
85
+ if op == 'renew' then
86
+ redis.call('HSET', KEYS[1], 'until', now + lease)
87
+ touch()
88
+ return {1}
89
+ end
90
+ if op == 'start' then
91
+ local started = redis.call('HGET', KEYS[1], 'started')
92
+ redis.call('HSET', KEYS[1], 'started', 1)
93
+ touch()
94
+ return {1, started == '0' and 1 or 0}
95
+ end
96
+ if op == 'append' then
97
+ local batch, digest = ARGV[10], ARGV[11]
98
+ local count, bytes = #ARGV - 11, 0
99
+ for i = 12, #ARGV do bytes = bytes + #ARGV[i] end
100
+ if head + count > tonumber(ARGV[7]) or
101
+ tonumber(redis.call('HGET', KEYS[1], 'bytes')) + bytes > tonumber(ARGV[8]) then return fail('limit') end
102
+ local first = head + 1
103
+ for i = 12, #ARGV do redis.call('RPUSH', KEYS[2], ARGV[i]) end
104
+ head = head + count
105
+ redis.call('HSET', KEYS[1], 'head', head)
106
+ redis.call('HINCRBY', KEYS[1], 'bytes', bytes)
107
+ redis.call('HSET', KEYS[3], batch, cjson.encode({first, head, digest}))
108
+ if ARGV[9] ~= '0' then redis.call('HSET', KEYS[1], 'state', ARGV[9], 'until', 0) end
109
+ touch()
110
+ return {1, first, head}
111
+ end
112
+ if op == 'ack' then
113
+ local cursor = tonumber(ARGV[10])
114
+ if cursor > head then return fail('cursor_ahead') end
115
+ ack = math.max(ack, cursor)
116
+ redis.call('HSET', KEYS[1], 'ack', ack)
117
+ touch()
118
+ return {1, ack}
119
+ end
120
+ if op == 'finish' then
121
+ if tonumber(ARGV[11]) ~= head then return fail('cursor_ahead') end
122
+ redis.call('HSET', KEYS[1], 'state', ARGV[10], 'until', 0)
123
+ touch()
124
+ return {1}
125
+ end
126
+ return fail('closed')
127
+ `;
128
+ const SCRIPT_SHA = createHash('sha1').update(SCRIPT).digest('hex');
129
+ const failures = new Set<RuntimeJournalFailure>([
130
+ 'missing',
131
+ 'scope_mismatch',
132
+ 'fenced',
133
+ 'closed',
134
+ 'limit',
135
+ 'cursor_ahead',
136
+ 'batch_conflict',
137
+ 'already_exists',
138
+ ]);
139
+ function integer(value: unknown): number {
140
+ if (
141
+ typeof value !== 'number' &&
142
+ (typeof value !== 'string' || !/^[0-9]+$/.test(value))
143
+ )
144
+ throw new Error('Invalid runtime journal number');
145
+ const n = Number(value);
146
+ if (!Number.isSafeInteger(n) || n < 0)
147
+ throw new Error('Invalid runtime journal response');
148
+ return n;
149
+ }
150
+ function id(value: string): void {
151
+ if (typeof value !== 'string' || !/^[A-Za-z0-9_-]{1,128}$/.test(value))
152
+ throw new Error('Invalid runtime journal identity');
153
+ }
154
+ /** Redis persistence/AOF policy is deployment-owned; storage acknowledgement precedes publication. */
155
+ export function createRedisRuntimeJournal(
156
+ redis: RuntimeJournalRedis,
157
+ limits: RuntimeJournalLimits
158
+ ): RuntimeJournal {
159
+ if (
160
+ !/^[A-Za-z0-9:_-]{1,128}$/.test(limits.prefix) ||
161
+ Object.entries(limits).some(
162
+ ([key, value]) =>
163
+ key !== 'prefix' && (!Number.isSafeInteger(value) || Number(value) <= 0)
164
+ ) ||
165
+ limits.retentionMs <= limits.leaseMs ||
166
+ limits.maxBatchFrames > limits.maxFrames ||
167
+ limits.maxBatchBytes > limits.maxBytes
168
+ ) {
169
+ throw new Error('Invalid runtime journal limits');
170
+ }
171
+ const invoke = async <T>(
172
+ op: string,
173
+ session: { sessionId: string; scope: string },
174
+ owner: string,
175
+ epoch: number,
176
+ args: Array<string | number>,
177
+ map: (data: unknown[]) => T,
178
+ terminal?: Exclude<RuntimeJournalState, 'open'>
179
+ ): Promise<RuntimeJournalResult<T>> => {
180
+ id(session.sessionId);
181
+ if (!/^[a-f0-9]{64}$/.test(session.scope))
182
+ throw new Error('Invalid runtime journal scope');
183
+ if (op !== 'read' && op !== 'purge') id(owner);
184
+ const key = `${limits.prefix}:{${session.sessionId}}`;
185
+ const arguments_: Array<string | number> = [
186
+ `${key}:meta`,
187
+ `${key}:frames`,
188
+ `${key}:receipts`,
189
+ op,
190
+ session.scope,
191
+ owner,
192
+ epoch,
193
+ limits.retentionMs,
194
+ limits.leaseMs,
195
+ limits.maxFrames,
196
+ limits.maxBytes,
197
+ terminal ?? 0,
198
+ ...args,
199
+ ];
200
+ let raw: unknown;
201
+ if (redis.evalsha) {
202
+ try {
203
+ raw = await redis.evalsha(SCRIPT_SHA, 3, ...arguments_);
204
+ } catch (error) {
205
+ // NOSCRIPT guarantees no execution. Never retry an ambiguous network failure.
206
+ if (!(error instanceof Error) || !/^NOSCRIPT\b/.test(error.message))
207
+ throw error;
208
+ raw = await redis.eval(SCRIPT, 3, ...arguments_);
209
+ }
210
+ } else raw = await redis.eval(SCRIPT, 3, ...arguments_);
211
+ if (!Array.isArray(raw))
212
+ throw new Error('Invalid runtime journal response');
213
+ if (raw[0] === 0 && failures.has(raw[1]))
214
+ return { ok: false, error: { code: raw[1] } };
215
+ if (raw[0] !== 1) throw new Error('Invalid runtime journal response');
216
+ return { ok: true, value: map(raw) };
217
+ };
218
+ return {
219
+ leaseMs: limits.leaseMs,
220
+ maxBatchFrames: limits.maxBatchFrames,
221
+ maxBatchBytes: limits.maxBatchBytes,
222
+ purge: (session) => invoke('purge', session, '', 0, [], () => null),
223
+ create: (session, owner) =>
224
+ invoke('create', session, owner, 0, [], (r) => ({
225
+ owner,
226
+ epoch: integer(r[1]),
227
+ })),
228
+ claim: (session, owner) =>
229
+ invoke('claim', session, owner, 0, [], (r) => ({
230
+ owner,
231
+ epoch: integer(r[1]),
232
+ started: r[2] === '1',
233
+ })),
234
+ renew: (session, lease) =>
235
+ invoke('renew', session, lease.owner, lease.epoch, [], () => null),
236
+ markStarted: (session, lease) =>
237
+ invoke('start', session, lease.owner, lease.epoch, [], (r) => ({
238
+ first: r[1] === 1,
239
+ })),
240
+ append: async (
241
+ session,
242
+ lease,
243
+ batchId,
244
+ payloads,
245
+ terminal
246
+ ): Promise<RuntimeJournalResult<{ first: number; last: number }>> => {
247
+ id(batchId);
248
+ if (
249
+ !payloads.length ||
250
+ payloads.length > limits.maxBatchFrames ||
251
+ payloads.some((p) => typeof p !== 'string') ||
252
+ payloads.reduce((sum, p) => sum + Buffer.byteLength(p), 0) >
253
+ limits.maxBatchBytes
254
+ ) {
255
+ return { ok: false, error: { code: 'limit' } };
256
+ }
257
+ if (
258
+ terminal != null &&
259
+ !['completed', 'failed', 'cancelled', 'paused'].includes(terminal)
260
+ )
261
+ throw new Error('Invalid runtime journal terminal state');
262
+ const digest = createHash('sha256')
263
+ .update(JSON.stringify([terminal ?? null, payloads]))
264
+ .digest('hex');
265
+ return invoke(
266
+ 'append',
267
+ session,
268
+ lease.owner,
269
+ lease.epoch,
270
+ [batchId, digest, ...payloads],
271
+ (r) => ({ first: integer(r[1]), last: integer(r[2]) }),
272
+ terminal
273
+ );
274
+ },
275
+ acknowledge: (session, lease, sequence) =>
276
+ invoke(
277
+ 'ack',
278
+ session,
279
+ lease.owner,
280
+ lease.epoch,
281
+ [integer(sequence)],
282
+ (r) => ({
283
+ acknowledged: integer(r[1]),
284
+ })
285
+ ),
286
+ read: (
287
+ session,
288
+ after,
289
+ count
290
+ ): Promise<
291
+ RuntimeJournalResult<{
292
+ state: RuntimeJournalState;
293
+ started: boolean;
294
+ head: number;
295
+ acknowledged: number;
296
+ frames: { sequence: number; payload: string }[];
297
+ }>
298
+ > => {
299
+ integer(after);
300
+ integer(count);
301
+ if (count === 0 || count > limits.maxBatchFrames)
302
+ throw new Error('Invalid runtime journal page limit');
303
+ return invoke('read', session, '', 0, [after, count], (r) => {
304
+ if (
305
+ !['open', 'completed', 'failed', 'cancelled', 'paused'].includes(
306
+ String(r[1])
307
+ )
308
+ )
309
+ throw new Error('Invalid runtime journal state');
310
+ if (!Array.isArray(r[5]) || r[5].some((p) => typeof p !== 'string'))
311
+ throw new Error('Invalid runtime journal frames');
312
+ return {
313
+ state: r[1] as RuntimeJournalState,
314
+ started: r[2] === '1',
315
+ head: integer(r[3]),
316
+ acknowledged: integer(r[4]),
317
+ frames: r[5].map((payload: string, index: number) => ({
318
+ sequence: after + index + 1,
319
+ payload,
320
+ })),
321
+ };
322
+ });
323
+ },
324
+ finish: (
325
+ session,
326
+ lease,
327
+ state,
328
+ head
329
+ ): Promise<RuntimeJournalResult<null>> => {
330
+ if (!['completed', 'failed', 'cancelled', 'paused'].includes(state))
331
+ throw new Error('Invalid runtime journal terminal state');
332
+ return invoke(
333
+ 'finish',
334
+ session,
335
+ lease.owner,
336
+ lease.epoch,
337
+ [state, integer(head)],
338
+ () => null
339
+ );
340
+ },
341
+ };
342
+ }
@@ -0,0 +1,280 @@
1
+ import { z } from 'zod';
2
+ import { createHash, randomUUID } from 'node:crypto';
3
+ import type { WebSocket } from 'ws';
4
+ import type {
5
+ RuntimeJournal,
6
+ RuntimeJournalLease,
7
+ RuntimeJournalSession,
8
+ RuntimeJournalState,
9
+ } from './journal';
10
+ import type { SdkAgentIdentity } from '../identity';
11
+ import { createJournalRecoveryLog, journalValue } from './log';
12
+ import { RecoverySocket } from './socket';
13
+
14
+ export interface RecoveryClaim {
15
+ ownerId?: string;
16
+ sessionId: string;
17
+ after: number;
18
+ resume: boolean;
19
+ generation?: string;
20
+ }
21
+ export const recoveryClaimSchema: z.ZodType<RecoveryClaim> = z
22
+ .object({
23
+ ownerId: z.string().min(1).max(128).optional(),
24
+ sessionId: z.string().uuid(),
25
+ after: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
26
+ resume: z.boolean(),
27
+ generation: z.string().optional(),
28
+ })
29
+ .strict();
30
+ export interface RuntimeRecoveryOptions {
31
+ /** Stable operator identity used for direct reconnect routing. */
32
+ ownerId?: string;
33
+ journal: RuntimeJournal;
34
+ maxDisconnectMs?: number;
35
+ }
36
+ export interface RuntimeRecoverySession {
37
+ socket: RecoverySocket;
38
+ controller: AbortController;
39
+ needsEngine: boolean;
40
+ begin: () => Promise<void>;
41
+ complete: (state: Exclude<RuntimeJournalState, 'open'>) => Promise<void>;
42
+ attach: (socket: WebSocket, after: number) => void;
43
+ dispose: () => void;
44
+ }
45
+ /** One live execution owner; reconnect only replaces its wire. A restart never repeats a started Run. */
46
+ export function createRuntimeRecovery(
47
+ options: RuntimeRecoveryOptions & {
48
+ maxFrameBytes: number;
49
+ maxBufferedBytes: number;
50
+ onError?: (error: unknown) => void;
51
+ }
52
+ ): {
53
+ prepare(
54
+ identity: Readonly<SdkAgentIdentity>,
55
+ threadId: string,
56
+ claim: RecoveryClaim
57
+ ): Promise<RuntimeRecoverySession>;
58
+ close(): void;
59
+ } {
60
+ const sessions = new Map<
61
+ string,
62
+ { scope: string; value: RuntimeRecoverySession }
63
+ >();
64
+ const pending = new Map<string, Promise<RuntimeRecoverySession>>();
65
+ let closed = false;
66
+ const isClosed = (): boolean => closed;
67
+ const graceMs = options.maxDisconnectMs ?? 15000;
68
+ if (
69
+ options.ownerId != null &&
70
+ (!options.ownerId.length || options.ownerId.length > 128)
71
+ )
72
+ throw new Error('Invalid SDK recovery owner identity');
73
+ if (
74
+ !Number.isSafeInteger(graceMs) ||
75
+ graceMs <= 0 ||
76
+ options.journal.leaseMs < 30
77
+ )
78
+ throw new Error('Invalid SDK recovery settings');
79
+ const report = (error: unknown): void => {
80
+ try {
81
+ options.onError?.(error);
82
+ } catch {
83
+ /* Trusted diagnostics only. */
84
+ }
85
+ };
86
+ const prepare = async (
87
+ identity: Readonly<SdkAgentIdentity>,
88
+ threadId: string,
89
+ claim: RecoveryClaim
90
+ ): Promise<RuntimeRecoverySession> => {
91
+ if (isClosed()) throw new Error('SDK recovery closed');
92
+ if (claim.ownerId != null && claim.ownerId !== options.ownerId)
93
+ throw new Error('SDK recovery owner mismatch');
94
+ const scope = createHash('sha256')
95
+ .update(
96
+ JSON.stringify([
97
+ identity.runtimeId,
98
+ identity.agentId,
99
+ identity.runId,
100
+ identity.userId,
101
+ identity.tenantId ?? null,
102
+ identity.conversationId ?? null,
103
+ threadId,
104
+ claim.generation ?? null,
105
+ ])
106
+ )
107
+ .digest('hex');
108
+ const existing = sessions.get(claim.sessionId);
109
+ if (existing) {
110
+ if (existing.scope !== scope || existing.value.socket.readyState !== 1)
111
+ throw new Error('SDK recovery identity mismatch');
112
+ return existing.value;
113
+ }
114
+ const session: RuntimeJournalSession = {
115
+ sessionId: claim.sessionId,
116
+ scope,
117
+ };
118
+ const journal = options.journal;
119
+ let lease: RuntimeJournalLease | undefined;
120
+ let page = await journal.read(session, 0, 1);
121
+ let needsEngine = false;
122
+ if (!page.ok) {
123
+ if (page.error.code !== 'missing' || claim.resume)
124
+ throw new Error('SDK recovery session unavailable');
125
+ lease = journalValue(await journal.create(session, randomUUID()));
126
+ page = await journal.read(session, 0, 1);
127
+ needsEngine = true;
128
+ } else if (page.value.state === 'open') {
129
+ const claimed = journalValue(await journal.claim(session, randomUUID()));
130
+ lease = claimed;
131
+ needsEngine = !claimed.started;
132
+ }
133
+ const initial = journalValue(page);
134
+ const log = createJournalRecoveryLog({
135
+ journal,
136
+ session,
137
+ lease,
138
+ head: initial.head,
139
+ });
140
+ if (!needsEngine && initial.state === 'open') {
141
+ // The previous process crossed the execution-start barrier. Its effects are uncertain.
142
+ // Replay committed output and fail; never invoke its factory again.
143
+ await log.append(
144
+ randomUUID(),
145
+ JSON.stringify({ kind: 'data', payload: '{"type":"error"}' })
146
+ );
147
+ }
148
+ const controller = new AbortController();
149
+ let deadline: ReturnType<typeof setTimeout> | undefined;
150
+ let heartbeat: ReturnType<typeof setInterval> | undefined;
151
+ let renewing = false;
152
+ let running = false;
153
+ let settled = false;
154
+ const expire = (): void => {
155
+ clearTimeout(deadline);
156
+ deadline = setTimeout(() => socket.terminate(), graceMs);
157
+ deadline.unref();
158
+ };
159
+ const socket = new RecoverySocket({
160
+ log,
161
+ maxFrameBytes: options.maxFrameBytes,
162
+ maxBufferedBytes: options.maxBufferedBytes,
163
+ terminalFailure:
164
+ initial.state === 'failed' || initial.state === 'cancelled',
165
+ onDisconnect: expire,
166
+ onFailure: (error): void => {
167
+ report(error);
168
+ controller.abort();
169
+ },
170
+ });
171
+ const dispose = (): void => {
172
+ clearTimeout(deadline);
173
+ clearInterval(heartbeat);
174
+ controller.abort();
175
+ socket.terminate();
176
+ if (sessions.get(claim.sessionId)?.value === value)
177
+ sessions.delete(claim.sessionId);
178
+ };
179
+ const value: RuntimeRecoverySession = {
180
+ socket,
181
+ controller,
182
+ needsEngine,
183
+ begin: async () => {
184
+ if (!lease || !needsEngine)
185
+ throw new Error('SDK recovery execution is already started');
186
+ const marker = journalValue(await journal.markStarted(session, lease));
187
+ if (!marker.first)
188
+ throw new Error('SDK recovery execution is already started');
189
+ running = true;
190
+ },
191
+ complete: async (state) => {
192
+ if (settled) return;
193
+ settled = true;
194
+ running = false;
195
+ await socket.flush();
196
+ if (
197
+ lease &&
198
+ journalValue(await journal.read(session, 0, 1)).state === 'open'
199
+ )
200
+ journalValue(await journal.finish(session, lease, state, log.head()));
201
+ clearInterval(heartbeat);
202
+ if (socket.readyState !== 1) dispose();
203
+ else expire();
204
+ },
205
+ attach: (wire, after) => {
206
+ clearTimeout(deadline);
207
+ const connection = randomUUID();
208
+ socket.attach(
209
+ wire,
210
+ connection,
211
+ after,
212
+ JSON.stringify({
213
+ version: 1,
214
+ kind: 'ready',
215
+ ownerId: options.ownerId,
216
+ connection,
217
+ sessionId: claim.sessionId,
218
+ received: socket.cursor,
219
+ })
220
+ );
221
+ if (settled || !needsEngine) expire();
222
+ },
223
+ dispose,
224
+ };
225
+ socket.once('close', () => {
226
+ controller.abort();
227
+ if (!running) dispose();
228
+ });
229
+ if (lease && needsEngine) {
230
+ heartbeat = setInterval(
231
+ () => {
232
+ if (renewing) return;
233
+ renewing = true;
234
+ void journal
235
+ .renew(session, lease!)
236
+ .then(journalValue)
237
+ .catch((error) => {
238
+ if (!settled) {
239
+ report(error);
240
+ dispose();
241
+ }
242
+ })
243
+ .finally(() => {
244
+ renewing = false;
245
+ });
246
+ },
247
+ Math.floor(journal.leaseMs / 3)
248
+ );
249
+ heartbeat.unref();
250
+ }
251
+ if (isClosed()) {
252
+ dispose();
253
+ throw new Error('SDK recovery closed');
254
+ }
255
+ sessions.set(claim.sessionId, { scope, value });
256
+ expire();
257
+ return value;
258
+ };
259
+ return {
260
+ async prepare(identity, threadId, claim): Promise<RuntimeRecoverySession> {
261
+ // Serialize admission by session, then recheck the caller's full scope.
262
+ const previous = pending.get(claim.sessionId);
263
+ const operation = (async (): Promise<RuntimeRecoverySession> => {
264
+ if (previous) await previous.catch(() => undefined);
265
+ return prepare(identity, threadId, claim);
266
+ })();
267
+ pending.set(claim.sessionId, operation);
268
+ try {
269
+ return await operation;
270
+ } finally {
271
+ if (pending.get(claim.sessionId) === operation)
272
+ pending.delete(claim.sessionId);
273
+ }
274
+ },
275
+ close: (): void => {
276
+ closed = true;
277
+ for (const entry of [...sessions.values()]) entry.value.dispose();
278
+ },
279
+ };
280
+ }