@archmax-ai/harness 0.0.0

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 (351) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +219 -0
  3. package/dist/agent.d.ts +174 -0
  4. package/dist/agent.js +140 -0
  5. package/dist/agent.js.map +1 -0
  6. package/dist/assembly/compose.d.ts +170 -0
  7. package/dist/assembly/compose.js +391 -0
  8. package/dist/assembly/compose.js.map +1 -0
  9. package/dist/assembly/delegation-registry.d.ts +5 -0
  10. package/dist/assembly/delegation-registry.js +118 -0
  11. package/dist/assembly/delegation-registry.js.map +1 -0
  12. package/dist/assembly/index.d.ts +192 -0
  13. package/dist/assembly/index.js +265 -0
  14. package/dist/assembly/index.js.map +1 -0
  15. package/dist/assembly/plain.d.ts +7 -0
  16. package/dist/assembly/plain.js +41 -0
  17. package/dist/assembly/plain.js.map +1 -0
  18. package/dist/authoring-skill/archmax-harness/README.md +76 -0
  19. package/dist/authoring-skill/archmax-harness/SKILL.md +241 -0
  20. package/dist/authoring-skill/archmax-harness/references/backend-integration.md +626 -0
  21. package/dist/authoring-skill/archmax-harness/references/cases.md +41 -0
  22. package/dist/authoring-skill/archmax-harness/references/diagnostics.md +51 -0
  23. package/dist/authoring-skill/archmax-harness/references/hook-and-test-scripts.md +1070 -0
  24. package/dist/authoring-skill/archmax-harness/references/hooks-and-scripts.md +82 -0
  25. package/dist/authoring-skill/archmax-harness/references/wiring.md +101 -0
  26. package/dist/authoring-skill/archmax-harness/references/workflow-schema.md +1631 -0
  27. package/dist/authoring-skill/archmax-harness/references/workflow-yaml.md +241 -0
  28. package/dist/behaviour/support.d.ts +232 -0
  29. package/dist/behaviour/support.js +339 -0
  30. package/dist/behaviour/support.js.map +1 -0
  31. package/dist/cli/banner.d.ts +11 -0
  32. package/dist/cli/banner.js +29 -0
  33. package/dist/cli/banner.js.map +1 -0
  34. package/dist/cli/bootstrap.d.ts +33 -0
  35. package/dist/cli/bootstrap.js +153 -0
  36. package/dist/cli/bootstrap.js.map +1 -0
  37. package/dist/cli/command.d.ts +39 -0
  38. package/dist/cli/command.js +97 -0
  39. package/dist/cli/command.js.map +1 -0
  40. package/dist/cli/state-flow.d.ts +46 -0
  41. package/dist/cli/state-flow.js +268 -0
  42. package/dist/cli/state-flow.js.map +1 -0
  43. package/dist/cli/style.d.ts +41 -0
  44. package/dist/cli/style.js +64 -0
  45. package/dist/cli/style.js.map +1 -0
  46. package/dist/cli/turn.d.ts +41 -0
  47. package/dist/cli/turn.js +161 -0
  48. package/dist/cli/turn.js.map +1 -0
  49. package/dist/cli.d.ts +10 -0
  50. package/dist/cli.js +426 -0
  51. package/dist/cli.js.map +1 -0
  52. package/dist/core/code-description.d.ts +22 -0
  53. package/dist/core/code-description.js +38 -0
  54. package/dist/core/code-description.js.map +1 -0
  55. package/dist/core/deepagents.d.ts +183 -0
  56. package/dist/core/deepagents.js +128 -0
  57. package/dist/core/deepagents.js.map +1 -0
  58. package/dist/core/events.d.ts +350 -0
  59. package/dist/core/events.js +205 -0
  60. package/dist/core/events.js.map +1 -0
  61. package/dist/core/frontmatter.d.ts +15 -0
  62. package/dist/core/frontmatter.js +32 -0
  63. package/dist/core/frontmatter.js.map +1 -0
  64. package/dist/core/listing-redact.d.ts +37 -0
  65. package/dist/core/listing-redact.js +88 -0
  66. package/dist/core/listing-redact.js.map +1 -0
  67. package/dist/core/match.d.ts +26 -0
  68. package/dist/core/match.js +75 -0
  69. package/dist/core/match.js.map +1 -0
  70. package/dist/core/message-readers.d.ts +84 -0
  71. package/dist/core/message-readers.js +159 -0
  72. package/dist/core/message-readers.js.map +1 -0
  73. package/dist/core/messages.d.ts +49 -0
  74. package/dist/core/messages.js +85 -0
  75. package/dist/core/messages.js.map +1 -0
  76. package/dist/core/mount-prompt.d.ts +28 -0
  77. package/dist/core/mount-prompt.js +55 -0
  78. package/dist/core/mount-prompt.js.map +1 -0
  79. package/dist/core/mount-redact.d.ts +28 -0
  80. package/dist/core/mount-redact.js +32 -0
  81. package/dist/core/mount-redact.js.map +1 -0
  82. package/dist/core/mounts.d.ts +88 -0
  83. package/dist/core/mounts.js +147 -0
  84. package/dist/core/mounts.js.map +1 -0
  85. package/dist/core/path-mapping.d.ts +52 -0
  86. package/dist/core/path-mapping.js +113 -0
  87. package/dist/core/path-mapping.js.map +1 -0
  88. package/dist/core/platform-prompt.generated.d.ts +2 -0
  89. package/dist/core/platform-prompt.generated.js +4 -0
  90. package/dist/core/platform-prompt.generated.js.map +1 -0
  91. package/dist/core/prompt.d.ts +42 -0
  92. package/dist/core/prompt.js +75 -0
  93. package/dist/core/prompt.js.map +1 -0
  94. package/dist/core/session-id.d.ts +38 -0
  95. package/dist/core/session-id.js +61 -0
  96. package/dist/core/session-id.js.map +1 -0
  97. package/dist/core/session-store.d.ts +85 -0
  98. package/dist/core/session-store.js +149 -0
  99. package/dist/core/session-store.js.map +1 -0
  100. package/dist/core/session-zone.d.ts +54 -0
  101. package/dist/core/session-zone.js +82 -0
  102. package/dist/core/session-zone.js.map +1 -0
  103. package/dist/core/skill-prompt.d.ts +31 -0
  104. package/dist/core/skill-prompt.js +54 -0
  105. package/dist/core/skill-prompt.js.map +1 -0
  106. package/dist/core/skill-redact.d.ts +15 -0
  107. package/dist/core/skill-redact.js +27 -0
  108. package/dist/core/skill-redact.js.map +1 -0
  109. package/dist/core/skills.d.ts +172 -0
  110. package/dist/core/skills.js +214 -0
  111. package/dist/core/skills.js.map +1 -0
  112. package/dist/core/tool-mocks.d.ts +23 -0
  113. package/dist/core/tool-mocks.js +39 -0
  114. package/dist/core/tool-mocks.js.map +1 -0
  115. package/dist/core/tool-telemetry.d.ts +16 -0
  116. package/dist/core/tool-telemetry.js +40 -0
  117. package/dist/core/tool-telemetry.js.map +1 -0
  118. package/dist/core/usage.d.ts +114 -0
  119. package/dist/core/usage.js +226 -0
  120. package/dist/core/usage.js.map +1 -0
  121. package/dist/core/workspace-context.d.ts +136 -0
  122. package/dist/core/workspace-context.js +178 -0
  123. package/dist/core/workspace-context.js.map +1 -0
  124. package/dist/core/workspace-prompt.d.ts +7 -0
  125. package/dist/core/workspace-prompt.js +102 -0
  126. package/dist/core/workspace-prompt.js.map +1 -0
  127. package/dist/core/workspace-router.d.ts +61 -0
  128. package/dist/core/workspace-router.js +145 -0
  129. package/dist/core/workspace-router.js.map +1 -0
  130. package/dist/core/workspace.d.ts +85 -0
  131. package/dist/core/workspace.js +193 -0
  132. package/dist/core/workspace.js.map +1 -0
  133. package/dist/core/zones.d.ts +181 -0
  134. package/dist/core/zones.js +202 -0
  135. package/dist/core/zones.js.map +1 -0
  136. package/dist/env.d.ts +99 -0
  137. package/dist/env.js +271 -0
  138. package/dist/env.js.map +1 -0
  139. package/dist/index.d.ts +265 -0
  140. package/dist/index.js +197 -0
  141. package/dist/index.js.map +1 -0
  142. package/dist/kernel/kernel.d.ts +192 -0
  143. package/dist/kernel/kernel.js +751 -0
  144. package/dist/kernel/kernel.js.map +1 -0
  145. package/dist/lifecycle/hook-shape.d.ts +44 -0
  146. package/dist/lifecycle/hook-shape.js +66 -0
  147. package/dist/lifecycle/hook-shape.js.map +1 -0
  148. package/dist/lifecycle/runner.d.ts +177 -0
  149. package/dist/lifecycle/runner.js +372 -0
  150. package/dist/lifecycle/runner.js.map +1 -0
  151. package/dist/lifecycle/transcript.d.ts +27 -0
  152. package/dist/lifecycle/transcript.js +43 -0
  153. package/dist/lifecycle/transcript.js.map +1 -0
  154. package/dist/machine/allow.d.ts +65 -0
  155. package/dist/machine/allow.js +107 -0
  156. package/dist/machine/allow.js.map +1 -0
  157. package/dist/machine/delegation.d.ts +9 -0
  158. package/dist/machine/delegation.js +10 -0
  159. package/dist/machine/delegation.js.map +1 -0
  160. package/dist/machine/diagnostic.d.ts +14 -0
  161. package/dist/machine/diagnostic.js +2 -0
  162. package/dist/machine/diagnostic.js.map +1 -0
  163. package/dist/machine/lint-spec.d.ts +4 -0
  164. package/dist/machine/lint-spec.js +266 -0
  165. package/dist/machine/lint-spec.js.map +1 -0
  166. package/dist/machine/load-spec.d.ts +90 -0
  167. package/dist/machine/load-spec.js +120 -0
  168. package/dist/machine/load-spec.js.map +1 -0
  169. package/dist/machine/machine.d.ts +273 -0
  170. package/dist/machine/machine.js +551 -0
  171. package/dist/machine/machine.js.map +1 -0
  172. package/dist/machine/mount-grants.d.ts +25 -0
  173. package/dist/machine/mount-grants.js +24 -0
  174. package/dist/machine/mount-grants.js.map +1 -0
  175. package/dist/machine/slug.d.ts +14 -0
  176. package/dist/machine/slug.js +17 -0
  177. package/dist/machine/slug.js.map +1 -0
  178. package/dist/machine/spec-schema.d.ts +662 -0
  179. package/dist/machine/spec-schema.js +717 -0
  180. package/dist/machine/spec-schema.js.map +1 -0
  181. package/dist/machine/tool-names.d.ts +98 -0
  182. package/dist/machine/tool-names.js +144 -0
  183. package/dist/machine/tool-names.js.map +1 -0
  184. package/dist/machine/triggers.d.ts +114 -0
  185. package/dist/machine/triggers.js +165 -0
  186. package/dist/machine/triggers.js.map +1 -0
  187. package/dist/machine/types.d.ts +186 -0
  188. package/dist/machine/types.js +12 -0
  189. package/dist/machine/types.js.map +1 -0
  190. package/dist/machine/validate-spec.d.ts +42 -0
  191. package/dist/machine/validate-spec.js +29 -0
  192. package/dist/machine/validate-spec.js.map +1 -0
  193. package/dist/machine/variables.d.ts +196 -0
  194. package/dist/machine/variables.js +415 -0
  195. package/dist/machine/variables.js.map +1 -0
  196. package/dist/public/cli.d.ts +15 -0
  197. package/dist/public/cli.js +14 -0
  198. package/dist/public/cli.js.map +1 -0
  199. package/dist/public/messages.d.ts +33 -0
  200. package/dist/public/messages.js +33 -0
  201. package/dist/public/messages.js.map +1 -0
  202. package/dist/public/sandbox.d.ts +99 -0
  203. package/dist/public/sandbox.js +32 -0
  204. package/dist/public/sandbox.js.map +1 -0
  205. package/dist/public/spec.d.ts +147 -0
  206. package/dist/public/spec.js +149 -0
  207. package/dist/public/spec.js.map +1 -0
  208. package/dist/public/testing.d.ts +71 -0
  209. package/dist/public/testing.js +39 -0
  210. package/dist/public/testing.js.map +1 -0
  211. package/dist/rubrics/rubrics.d.ts +135 -0
  212. package/dist/rubrics/rubrics.js +145 -0
  213. package/dist/rubrics/rubrics.js.map +1 -0
  214. package/dist/runtime/contract.d.ts +73 -0
  215. package/dist/runtime/contract.js +96 -0
  216. package/dist/runtime/contract.js.map +1 -0
  217. package/dist/sandbox/assets/parts/core.js +22 -0
  218. package/dist/sandbox/assets/parts/lifecycle-hook.js +47 -0
  219. package/dist/sandbox/bridge.d.ts +16 -0
  220. package/dist/sandbox/bridge.js +95 -0
  221. package/dist/sandbox/bridge.js.map +1 -0
  222. package/dist/sandbox/executor.d.ts +46 -0
  223. package/dist/sandbox/executor.js +119 -0
  224. package/dist/sandbox/executor.js.map +1 -0
  225. package/dist/sandbox/imports.d.ts +33 -0
  226. package/dist/sandbox/imports.js +67 -0
  227. package/dist/sandbox/imports.js.map +1 -0
  228. package/dist/sandbox/prelude.d.ts +12 -0
  229. package/dist/sandbox/prelude.js +51 -0
  230. package/dist/sandbox/prelude.js.map +1 -0
  231. package/dist/sandbox/ptc-gateway.d.ts +104 -0
  232. package/dist/sandbox/ptc-gateway.js +167 -0
  233. package/dist/sandbox/ptc-gateway.js.map +1 -0
  234. package/dist/sandbox/runtime.d.ts +59 -0
  235. package/dist/sandbox/runtime.js +51 -0
  236. package/dist/sandbox/runtime.js.map +1 -0
  237. package/dist/sandbox/tools.d.ts +34 -0
  238. package/dist/sandbox/tools.js +147 -0
  239. package/dist/sandbox/tools.js.map +1 -0
  240. package/dist/sessions/operations.d.ts +79 -0
  241. package/dist/sessions/operations.js +121 -0
  242. package/dist/sessions/operations.js.map +1 -0
  243. package/dist/sessions/resolve.d.ts +97 -0
  244. package/dist/sessions/resolve.js +145 -0
  245. package/dist/sessions/resolve.js.map +1 -0
  246. package/dist/sessions/resume.d.ts +242 -0
  247. package/dist/sessions/resume.js +288 -0
  248. package/dist/sessions/resume.js.map +1 -0
  249. package/dist/sessions/scope.d.ts +99 -0
  250. package/dist/sessions/scope.js +145 -0
  251. package/dist/sessions/scope.js.map +1 -0
  252. package/dist/sessions/summary.d.ts +65 -0
  253. package/dist/sessions/summary.js +56 -0
  254. package/dist/sessions/summary.js.map +1 -0
  255. package/dist/testing/assertions.d.ts +30 -0
  256. package/dist/testing/assertions.js +231 -0
  257. package/dist/testing/assertions.js.map +1 -0
  258. package/dist/testing/case-document.d.ts +141 -0
  259. package/dist/testing/case-document.js +51 -0
  260. package/dist/testing/case-document.js.map +1 -0
  261. package/dist/testing/case-schema.d.ts +29 -0
  262. package/dist/testing/case-schema.js +519 -0
  263. package/dist/testing/case-schema.js.map +1 -0
  264. package/dist/testing/discovery.d.ts +10 -0
  265. package/dist/testing/discovery.js +24 -0
  266. package/dist/testing/discovery.js.map +1 -0
  267. package/dist/testing/driver.d.ts +78 -0
  268. package/dist/testing/driver.js +117 -0
  269. package/dist/testing/driver.js.map +1 -0
  270. package/dist/testing/grade.d.ts +116 -0
  271. package/dist/testing/grade.js +261 -0
  272. package/dist/testing/grade.js.map +1 -0
  273. package/dist/testing/interpreter.d.ts +55 -0
  274. package/dist/testing/interpreter.js +103 -0
  275. package/dist/testing/interpreter.js.map +1 -0
  276. package/dist/testing/mock-middleware.d.ts +5 -0
  277. package/dist/testing/mock-middleware.js +33 -0
  278. package/dist/testing/mock-middleware.js.map +1 -0
  279. package/dist/testing/runner.d.ts +205 -0
  280. package/dist/testing/runner.js +266 -0
  281. package/dist/testing/runner.js.map +1 -0
  282. package/dist/testing/target.d.ts +27 -0
  283. package/dist/testing/target.js +21 -0
  284. package/dist/testing/target.js.map +1 -0
  285. package/dist/validate/validate.d.ts +41 -0
  286. package/dist/validate/validate.js +669 -0
  287. package/dist/validate/validate.js.map +1 -0
  288. package/dist/workflow/agent-tools.d.ts +10 -0
  289. package/dist/workflow/agent-tools.js +10 -0
  290. package/dist/workflow/agent-tools.js.map +1 -0
  291. package/dist/workflow/checkpointer.d.ts +52 -0
  292. package/dist/workflow/checkpointer.js +200 -0
  293. package/dist/workflow/checkpointer.js.map +1 -0
  294. package/dist/workflow/control-tools.d.ts +174 -0
  295. package/dist/workflow/control-tools.js +468 -0
  296. package/dist/workflow/control-tools.js.map +1 -0
  297. package/dist/workflow/governance.d.ts +104 -0
  298. package/dist/workflow/governance.js +546 -0
  299. package/dist/workflow/governance.js.map +1 -0
  300. package/dist/workflow/middleware.d.ts +85 -0
  301. package/dist/workflow/middleware.js +283 -0
  302. package/dist/workflow/middleware.js.map +1 -0
  303. package/dist/workflow/on-error.d.ts +25 -0
  304. package/dist/workflow/on-error.js +58 -0
  305. package/dist/workflow/on-error.js.map +1 -0
  306. package/dist/workflow/parks.d.ts +46 -0
  307. package/dist/workflow/parks.js +513 -0
  308. package/dist/workflow/parks.js.map +1 -0
  309. package/dist/workflow/paths.d.ts +67 -0
  310. package/dist/workflow/paths.js +108 -0
  311. package/dist/workflow/paths.js.map +1 -0
  312. package/dist/workflow/prompt-cache.d.ts +70 -0
  313. package/dist/workflow/prompt-cache.js +103 -0
  314. package/dist/workflow/prompt-cache.js.map +1 -0
  315. package/dist/workflow/prompt-pruning.d.ts +20 -0
  316. package/dist/workflow/prompt-pruning.js +83 -0
  317. package/dist/workflow/prompt-pruning.js.map +1 -0
  318. package/dist/workflow/render-prompt.d.ts +45 -0
  319. package/dist/workflow/render-prompt.js +140 -0
  320. package/dist/workflow/render-prompt.js.map +1 -0
  321. package/dist/workflow/runtime-config.d.ts +7 -0
  322. package/dist/workflow/runtime-config.js +9 -0
  323. package/dist/workflow/runtime-config.js.map +1 -0
  324. package/dist/workflow/session-artifacts.d.ts +90 -0
  325. package/dist/workflow/session-artifacts.js +134 -0
  326. package/dist/workflow/session-artifacts.js.map +1 -0
  327. package/dist/workflow/session-view.d.ts +31 -0
  328. package/dist/workflow/session-view.js +94 -0
  329. package/dist/workflow/session-view.js.map +1 -0
  330. package/dist/workflow/snapshot.d.ts +14 -0
  331. package/dist/workflow/snapshot.js +97 -0
  332. package/dist/workflow/snapshot.js.map +1 -0
  333. package/dist/workflow/state.d.ts +347 -0
  334. package/dist/workflow/state.js +322 -0
  335. package/dist/workflow/state.js.map +1 -0
  336. package/dist/workflow/sub-workflow.d.ts +174 -0
  337. package/dist/workflow/sub-workflow.js +392 -0
  338. package/dist/workflow/sub-workflow.js.map +1 -0
  339. package/dist/workflow/tool-service.d.ts +48 -0
  340. package/dist/workflow/tool-service.js +291 -0
  341. package/dist/workflow/tool-service.js.map +1 -0
  342. package/dist/workflow/turn-boundary.d.ts +39 -0
  343. package/dist/workflow/turn-boundary.js +128 -0
  344. package/dist/workflow/turn-boundary.js.map +1 -0
  345. package/dist/workflow/turn-runner.d.ts +40 -0
  346. package/dist/workflow/turn-runner.js +122 -0
  347. package/dist/workflow/turn-runner.js.map +1 -0
  348. package/dist/workflow/workflow-tools.d.ts +46 -0
  349. package/dist/workflow/workflow-tools.js +90 -0
  350. package/dist/workflow/workflow-tools.js.map +1 -0
  351. package/package.json +119 -0
@@ -0,0 +1,288 @@
1
+ /**
2
+ * Resuming a parked session — the one path behind `decide`, `reply` and
3
+ * `deliver`, and the `Outcome` every way of entering a session settles to.
4
+ *
5
+ * A park is two facts: the checkpointed status and a live suspension. Every
6
+ * resume reads both, validates its payload **before** the graph is touched (a
7
+ * rejected resume leaves the park untouched), hands the payload to the suspended
8
+ * `interrupt()` through `Command({ resume })`, and reads the settled state off
9
+ * the invoke result — the same shape a turn produces.
10
+ */
11
+ import { Command } from "@langchain/langgraph";
12
+ import { mergeConfigs } from "@langchain/core/runnables";
13
+ import { lastAgentText } from "../core/messages.js";
14
+ import { hasUsage } from "../core/usage.js";
15
+ import { InvalidVariableNameError, VARIABLE_NAME_PATTERN, } from "../machine/variables.js";
16
+ import { parkedStateOf, readAuditTrail, readRunUsage, readVariables, WORKFLOW_STATUSES, } from "../workflow/state.js";
17
+ import { childSessionId } from "./scope.js";
18
+ /**
19
+ * Whether a resume payload is a message rather than a decision or a delivery.
20
+ * Told apart **structurally** — a `target` routes, a `trigger` is delivered (and
21
+ * may carry a message with it), a `message` alone is answered — never by reading
22
+ * the words: "yes, approve it" typed into the chat is not a decision.
23
+ */
24
+ export function isMessageResume(resume) {
25
+ const payload = resume;
26
+ if (payload?.trigger !== undefined && payload.trigger !== null)
27
+ return false;
28
+ const message = payload?.message;
29
+ return typeof message === "string" && message.trim() !== "";
30
+ }
31
+ // --- Errors --------------------------------------------------------------------
32
+ /** Thrown when a decision or reply targets a session that is not parked at a human state. */
33
+ export class SessionNotParkedError extends Error {
34
+ sessionId;
35
+ constructor(sessionId) {
36
+ super(`Session '${sessionId}' is not parked at a human state; there is nothing to decide.`);
37
+ this.sessionId = sessionId;
38
+ this.name = "SessionNotParkedError";
39
+ }
40
+ }
41
+ /** Thrown when a decision names a target that is not one of the parked state's transitions. */
42
+ export class InvalidDecisionTargetError extends Error {
43
+ sessionId;
44
+ target;
45
+ validTargets;
46
+ constructor(sessionId, target, validTargets) {
47
+ super((target
48
+ ? `'${target}' is not a valid decision target for session '${sessionId}'. `
49
+ : `A decision target is required for session '${sessionId}'. `) +
50
+ `Choose one of: ${validTargets.join(", ")}.`);
51
+ this.sessionId = sessionId;
52
+ this.target = target;
53
+ this.validTargets = validTargets;
54
+ this.name = "InvalidDecisionTargetError";
55
+ }
56
+ }
57
+ /** Thrown when a reply is sent to a parked session without any content. */
58
+ export class EmptyMessageError extends Error {
59
+ sessionId;
60
+ constructor(sessionId) {
61
+ super(`A message is required to reply to session '${sessionId}': there is nothing to answer, and ` +
62
+ `a parked session is not moved by an empty turn.`);
63
+ this.sessionId = sessionId;
64
+ this.name = "EmptyMessageError";
65
+ }
66
+ }
67
+ /** Thrown when a delivery targets a session that is not parked awaiting input. */
68
+ export class SessionNotAwaitingInputError extends Error {
69
+ sessionId;
70
+ constructor(sessionId) {
71
+ super(`Session '${sessionId}' is not parked awaiting an event; there is nothing to deliver to. ` +
72
+ `A session awaiting a human decision resumes through a decision instead.`);
73
+ this.sessionId = sessionId;
74
+ this.name = "SessionNotAwaitingInputError";
75
+ }
76
+ }
77
+ /** Thrown when a delivery carries no trigger id to record as the session's current one. */
78
+ export class MissingDeliveryTriggerError extends Error {
79
+ sessionId;
80
+ constructor(sessionId) {
81
+ super(`A trigger id is required to deliver to session '${sessionId}': it becomes the session's ` +
82
+ `current trigger, which its hooks and guards read. Any id is accepted — a park ` +
83
+ `awaits no particular one.`);
84
+ this.sessionId = sessionId;
85
+ this.name = "MissingDeliveryTriggerError";
86
+ }
87
+ }
88
+ // --- Reading parked state ------------------------------------------------------
89
+ /**
90
+ * Read a session that must be parked in `status`, or `null`. "Parked" is two
91
+ * conditions — the checkpointed status *and* a pending interrupt — so every
92
+ * resume asks it here.
93
+ */
94
+ export async function readParkedSession(graph, sessionId, status) {
95
+ const snapshot = await graph.getState({ configurable: { thread_id: sessionId } });
96
+ const values = (snapshot?.values ?? {});
97
+ const suspensions = (snapshot?.tasks ?? []).flatMap((t) => t.interrupts ?? []);
98
+ if (suspensions.length === 0)
99
+ return null;
100
+ return values.status === status ? values : null;
101
+ }
102
+ /** The park a settled state presents, on whichever channel, or nothing. */
103
+ function parkOf(values) {
104
+ const deciding = values.pendingDecision;
105
+ const waiting = values.pendingInput;
106
+ if (values.status === WORKFLOW_STATUSES.awaitingDecision && deciding) {
107
+ return { channel: "decision", pending: deciding };
108
+ }
109
+ if (values.status === WORKFLOW_STATUSES.awaitingInput && waiting) {
110
+ return { channel: "input", pending: waiting };
111
+ }
112
+ return undefined;
113
+ }
114
+ /**
115
+ * The delegated child a decision park belongs to, read from the head of the
116
+ * `pendingDelegations` queue — the record the runtime presents as the session's
117
+ * pending decision. Only a decision park can be delegated; a wait park is always
118
+ * the session's own.
119
+ */
120
+ function delegationOf(values, channel, sessionId) {
121
+ if (channel !== "decision")
122
+ return undefined;
123
+ const queue = values.pendingDelegations;
124
+ const head = Array.isArray(queue) ? queue[0] : undefined;
125
+ if (!head)
126
+ return undefined;
127
+ return {
128
+ workflow: head.workflow,
129
+ ...(sessionId ? { sessionId: childSessionId(sessionId, head.identity) } : {}),
130
+ identity: head.identity,
131
+ dispatchId: head.dispatchId,
132
+ toolCallId: head.toolCallId,
133
+ state: parkedStateOf(head),
134
+ };
135
+ }
136
+ /**
137
+ * The settled values of a turn or a resume, read into a {@link ResumeOutcome}.
138
+ * `sessionId` is the session the values belong to, when the caller knows it; it
139
+ * lets a delegated park name the child's session id.
140
+ */
141
+ export function settle(result, sessionId) {
142
+ const messages = Array.isArray(result.messages) ? result.messages : [];
143
+ const park = parkOf(result);
144
+ const parkedAt = park ? parkedStateOf(park.pending) : undefined;
145
+ const delegation = delegationOf(result, park?.channel, sessionId);
146
+ const usage = readRunUsage(result);
147
+ return {
148
+ status: typeof result.status === "string" ? result.status : undefined,
149
+ workflowState: typeof result.workflowState === "string" ? result.workflowState : undefined,
150
+ reparked: park !== undefined,
151
+ ...(park ? { parkedChannel: park.channel, pending: park.pending } : {}),
152
+ ...(parkedAt ? { state: parkedAt, node: parkedAt } : {}),
153
+ ...(delegation ? { delegation } : {}),
154
+ reply: lastAgentText(messages),
155
+ messages,
156
+ auditTrail: readAuditTrail(result),
157
+ variables: readVariables(result),
158
+ ...(hasUsage(usage) ? { usage } : {}),
159
+ };
160
+ }
161
+ /** The {@link Outcome} a settled {@link ResumeOutcome} amounts to. */
162
+ export function outcomeOf(settled, disposition) {
163
+ const kind = settled.reparked
164
+ ? "parked"
165
+ : settled.status === WORKFLOW_STATUSES.rejected
166
+ ? "rejected"
167
+ : "completed";
168
+ const state = settled.state ?? settled.workflowState;
169
+ return {
170
+ kind,
171
+ disposition,
172
+ ...(settled.status ? { status: settled.status } : {}),
173
+ ...(state ? { state } : {}),
174
+ ...(settled.parkedChannel ? { parkedChannel: settled.parkedChannel } : {}),
175
+ ...(settled.pending ? { pending: settled.pending } : {}),
176
+ ...(settled.delegation ? { delegation: settled.delegation } : {}),
177
+ reply: settled.reply,
178
+ messages: settled.messages,
179
+ auditTrail: settled.auditTrail,
180
+ variables: settled.variables,
181
+ ...(settled.usage ? { usage: settled.usage } : {}),
182
+ };
183
+ }
184
+ // --- The one resume path ---------------------------------------------------------
185
+ /**
186
+ * Validate a payload against the parked session and produce the value the
187
+ * suspended `interrupt()` receives — before the graph is touched. Also returns
188
+ * the state the session is parked at, which a reply (never routing) reports as its own.
189
+ */
190
+ async function validate(graph, sessionId, payload) {
191
+ if ("decision" in payload) {
192
+ const values = await readParkedSession(graph, sessionId, WORKFLOW_STATUSES.awaitingDecision);
193
+ if (!values)
194
+ throw new SessionNotParkedError(sessionId);
195
+ const pending = values.pendingDecision;
196
+ // A decision routes only to a target the session can actually leave for: a
197
+ // self-targeted transition would end the session as `completed`. Refused
198
+ // with the options that do lead somewhere.
199
+ const parkedAt = parkedStateOf(pending);
200
+ const validTargets = (pending?.transitions ?? []).map((t) => t.to).filter((to) => to !== parkedAt);
201
+ const target = (payload.decision?.target ?? "").trim();
202
+ if (!target || !validTargets.includes(target)) {
203
+ throw new InvalidDecisionTargetError(sessionId, target || undefined, validTargets);
204
+ }
205
+ return { value: payload.decision, parkedAt };
206
+ }
207
+ if ("delivery" in payload) {
208
+ const values = await readParkedSession(graph, sessionId, WORKFLOW_STATUSES.awaitingInput);
209
+ if (!values)
210
+ throw new SessionNotAwaitingInputError(sessionId);
211
+ const requested = (payload.delivery?.trigger?.id ?? "").trim();
212
+ if (requested === "")
213
+ throw new MissingDeliveryTriggerError(sessionId);
214
+ // The same rule host seeds obey at assembly, and the same error.
215
+ for (const name of Object.keys(payload.delivery.variables ?? {})) {
216
+ if (!VARIABLE_NAME_PATTERN.test(name)) {
217
+ throw new InvalidVariableNameError(name, `delivered to session '${sessionId}'`);
218
+ }
219
+ }
220
+ const message = (payload.delivery.message ?? "").trim();
221
+ return {
222
+ value: {
223
+ trigger: { id: requested },
224
+ variables: payload.delivery.variables ?? {},
225
+ ...(message ? { message } : {}),
226
+ },
227
+ parkedAt: parkedStateOf(values.pendingInput),
228
+ };
229
+ }
230
+ const values = await readParkedSession(graph, sessionId, WORKFLOW_STATUSES.awaitingDecision);
231
+ if (!values)
232
+ throw new SessionNotParkedError(sessionId);
233
+ const text = (payload.message ?? "").trim();
234
+ if (!text)
235
+ throw new EmptyMessageError(sessionId);
236
+ return {
237
+ value: { message: text },
238
+ parkedAt: parkedStateOf(values.pendingDecision),
239
+ };
240
+ }
241
+ /**
242
+ * Resume a parked session with a decision, a reply or a delivery. Everything is
243
+ * validated before the graph is touched; the invoke result *is* the resumed state.
244
+ */
245
+ export async function resume(graph, sessionId, payload, config) {
246
+ const { value, parkedAt } = await validate(graph, sessionId, payload);
247
+ // A resumed turn is a turn: the caller's config carries that turn's tool mocks
248
+ // and its abort signal, so it merges here exactly as it does on a fresh turn.
249
+ // The thread id is applied last, so no caller can redirect the resume.
250
+ const result = await graph.invoke(new Command({ resume: value }), mergeConfigs(config, { configurable: { thread_id: sessionId } }));
251
+ const outcome = settle(result, sessionId);
252
+ if ("message" in payload) {
253
+ // A message never routes: the session is parked where it was. The resumed
254
+ // record is preferred only so the two cannot disagree.
255
+ const state = outcome.state || parkedAt || "";
256
+ return { ...outcome, reparked: true, parkedChannel: "decision", state, node: state };
257
+ }
258
+ return outcome;
259
+ }
260
+ // --- Conveniences ----------------------------------------------------------------
261
+ /**
262
+ * Resume a session parked at a human state with the person's decision. Throws
263
+ * {@link SessionNotParkedError} when the session is not awaiting a decision, and
264
+ * {@link InvalidDecisionTargetError} when `target` is not a declared transition.
265
+ */
266
+ export function decide(graph, sessionId, resolution, config) {
267
+ return resume(graph, sessionId, { decision: resolution }, config);
268
+ }
269
+ /**
270
+ * Reply to a session parked at a human state and get its answer: a turn with no
271
+ * tools, after which the session stays parked at the same state with the same
272
+ * pending decision. Throws {@link SessionNotParkedError} and {@link EmptyMessageError}.
273
+ */
274
+ export async function reply(graph, sessionId, message, config) {
275
+ return (await resume(graph, sessionId, { message }, config));
276
+ }
277
+ /** @deprecated Older spelling of {@link reply}; kept for one release. */
278
+ export const respond = reply;
279
+ /**
280
+ * Resume a parked session with a delivered firing: the session continues in the
281
+ * state it parked in, the delivered id becomes its current trigger, and the
282
+ * variables seed what the event carried. Throws {@link SessionNotAwaitingInputError}
283
+ * and {@link MissingDeliveryTriggerError}.
284
+ */
285
+ export function deliver(graph, sessionId, delivery, config) {
286
+ return resume(graph, sessionId, { delivery }, config);
287
+ }
288
+ //# sourceMappingURL=resume.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resume.js","sourceRoot":"","sources":["../../src/sessions/resume.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAuB,MAAM,2BAA2B,CAAC;AAE9E,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAqB,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EACL,wBAAwB,EACxB,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,aAAa,EACb,cAAc,EACd,YAAY,EACZ,aAAa,EACb,iBAAiB,GAOlB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AA2B5C;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,MAAe;IAC7C,MAAM,OAAO,GAAG,MAAiE,CAAC;IAClF,IAAI,OAAO,EAAE,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,OAAO,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC7E,MAAM,OAAO,GAAG,OAAO,EAAE,OAAO,CAAC;IACjC,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;AAC9D,CAAC;AA6BD,kFAAkF;AAElF,6FAA6F;AAC7F,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IACzB;IAArB,YAAqB,SAAiB;QACpC,KAAK,CAAC,YAAY,S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AE,SAAS,EAAE,EAAE,OAAO,EAAE,EAAE,MAAM,CAAC,CAAiB,CAAC;AAC/E,CAAC;AAED,yEAAyE;AACzE,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CACrB,KAA+B,EAC/B,SAAiB,EACjB,QAAyB,EACzB,MAAuB;IAEvB,OAAO,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,QAAQ,EAAE,EAAE,MAAM,CAAC,CAAC;AACxD,CAAC"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * The **session scope** — the unit every per-session resource is keyed by (the
3
+ * sandbox REPL session, the middleware's per-session context, the PTC budget).
4
+ * A sub-workflow's child is an ordinary session with its own id
5
+ * (`<parent>~<dispatch identity>`); only the dispatch **chain** (cycle and depth
6
+ * refusals) and the **dispatch id** (event attribution) ride the config.
7
+ */
8
+ import type { RunnableConfig } from "@langchain/core/runnables";
9
+ /** The session id assumed when a config carries no `thread_id`; every per-session map keys on this spelling. */
10
+ export declare const DEFAULT_SESSION_ID = "__default__";
11
+ /**
12
+ * Where the dispatch chain of workflow slugs rides between a parent session and
13
+ * its child; what makes depth and cycle refusals possible without a shared registry.
14
+ */
15
+ export declare const SUB_WORKFLOW_CHAIN_KEY = "archmax_sub_workflow_chain";
16
+ /** Where a child session's dispatch id rides, so events emitted inside it can be nested. */
17
+ export declare const SUB_WORKFLOW_DISPATCH_KEY = "archmax_sub_workflow_dispatch";
18
+ /**
19
+ * Where the slug of the state a **script's** tool call is made from rides. The
20
+ * PTC gateway is refreshed with the state in force on every model call and hands
21
+ * the tool only a `RunnableConfig`; an agent-initiated delegation never needs it.
22
+ */
23
+ export declare const CALLING_STATE_KEY = "archmax_calling_state";
24
+ /** The state a script's call is made from, read from its config. */
25
+ export declare function callingStateFrom(config: {
26
+ configurable?: Configurable;
27
+ }): string | undefined;
28
+ /**
29
+ * Where **per-invocation** variable seeds ride. A child's seeds differ per
30
+ * dispatch while the composed child is shared, and the graph input cannot carry
31
+ * them (the turn boundary rewrites the `variables` channel); the config is the
32
+ * one per-invocation, never-checkpointed channel.
33
+ */
34
+ export declare const SEED_VARIABLES_KEY = "archmax_seed_variables";
35
+ /** The `configurable` bag of a runnable config, however partially typed the caller has it. */
36
+ type Configurable = Record<string, unknown> | undefined;
37
+ /** A turn's execution scope: which session, and how it was reached. */
38
+ export interface SessionScope {
39
+ /** The LangGraph `thread_id` — the session whose zone and store this turn uses. */
40
+ sessionId: string;
41
+ /** Workflow slugs from the outermost session down to and including this one. */
42
+ chain: readonly string[];
43
+ /** How many delegations deep this session is; `0` at the top level. */
44
+ depth: number;
45
+ /** The dispatch this child session belongs to, for event nesting; absent at the top level. */
46
+ dispatchId?: string;
47
+ }
48
+ /** The dispatch chain carried by a config, or an empty chain at the top level. */
49
+ export declare function subWorkflowChain(configurable: Configurable): readonly string[];
50
+ /** The dispatch id of the child session this config belongs to, if it is one. */
51
+ export declare function subWorkflowDispatchId(configurable: Configurable): string | undefined;
52
+ /**
53
+ * Variable seeds this invocation carries, layered **over** the assembly's own at
54
+ * the turn boundary. Absent for an ordinary turn.
55
+ */
56
+ export declare function seedVariablesFrom(configurable: Configurable): Record<string, unknown> | undefined;
57
+ /** Read the session scope from a config; a config with no `thread_id` is {@link DEFAULT_SESSION_ID}. */
58
+ export declare function sessionScopeFrom(config: {
59
+ configurable?: Record<string, unknown>;
60
+ } | undefined, fallbackSessionId?: string): SessionScope;
61
+ /**
62
+ * Drop `sessionId`'s entry and every child session's entry from a session-keyed
63
+ * map. Disposal is requested per session, so it must reach the children nested
64
+ * under it or a delegating session leaks a REPL per dispatch. Returns the ids
65
+ * released, so a caller holding several parallel maps can release the same set.
66
+ */
67
+ export declare function releaseScopes<V>(map: Map<string, V>, sessionId: string): string[];
68
+ /**
69
+ * The child identity for one dispatch: `<state>:<workflow>:<ordinal>`. The
70
+ * ordinal keeps a second visit to the same state (an `on_error` loop, a retried
71
+ * turn) and concurrently dispatched children of one state apart.
72
+ */
73
+ export declare function subRunIdentity(state: string, workflow: string, ordinal: number): string;
74
+ /**
75
+ * The session id one child gets: `<parent>~<state>:<workflow>:<ordinal>` — an
76
+ * ordinary session with its own checkpoints and zone. Derived rather than minted
77
+ * at random, so a re-dispatch of the same call resolves to the same child and a
78
+ * resumed parent finds the child it parked on.
79
+ */
80
+ export declare function childSessionId(parentSessionId: string, identity: string): string;
81
+ /**
82
+ * The session that dispatched `sessionId`, or `undefined` for a top-level
83
+ * session. Derived from the id, so there is no index to drift.
84
+ */
85
+ export declare function parentSessionIdOf(sessionId: string): string | undefined;
86
+ /** Whether `sessionId` is a session dispatched by `parentSessionId`, at any depth. */
87
+ export declare function isChildSessionOf(sessionId: string, parentSessionId: string): boolean;
88
+ /**
89
+ * The config a child session is invoked with: its **own** `thread_id` (see
90
+ * {@link childSessionId}), the extended dispatch chain and the dispatch id.
91
+ * `checkpoint_id` and `checkpoint_ns` are cleared: each pins a position in the
92
+ * *caller's* thread, which the child's thread has never written.
93
+ */
94
+ export declare function childRunConfig(parentConfig: RunnableConfig, child: {
95
+ identity: string;
96
+ workflow: string;
97
+ dispatchId: string;
98
+ }): RunnableConfig;
99
+ export {};
@@ -0,0 +1,145 @@
1
+ /** The session id assumed when a config carries no `thread_id`; every per-session map keys on this spelling. */
2
+ export const DEFAULT_SESSION_ID = "__default__";
3
+ /**
4
+ * Where the dispatch chain of workflow slugs rides between a parent session and
5
+ * its child; what makes depth and cycle refusals possible without a shared registry.
6
+ */
7
+ export const SUB_WORKFLOW_CHAIN_KEY = "archmax_sub_workflow_chain";
8
+ /** Where a child session's dispatch id rides, so events emitted inside it can be nested. */
9
+ export const SUB_WORKFLOW_DISPATCH_KEY = "archmax_sub_workflow_dispatch";
10
+ /**
11
+ * Where the slug of the state a **script's** tool call is made from rides. The
12
+ * PTC gateway is refreshed with the state in force on every model call and hands
13
+ * the tool only a `RunnableConfig`; an agent-initiated delegation never needs it.
14
+ */
15
+ export const CALLING_STATE_KEY = "archmax_calling_state";
16
+ /** The state a script's call is made from, read from its config. */
17
+ export function callingStateFrom(config) {
18
+ const slug = config?.configurable?.[CALLING_STATE_KEY];
19
+ return typeof slug === "string" && slug ? slug : undefined;
20
+ }
21
+ /**
22
+ * Where **per-invocation** variable seeds ride. A child's seeds differ per
23
+ * dispatch while the composed child is shared, and the graph input cannot carry
24
+ * them (the turn boundary rewrites the `variables` channel); the config is the
25
+ * one per-invocation, never-checkpointed channel.
26
+ */
27
+ export const SEED_VARIABLES_KEY = "archmax_seed_variables";
28
+ /** The dispatch chain carried by a config, or an empty chain at the top level. */
29
+ export function subWorkflowChain(configurable) {
30
+ const chain = configurable?.[SUB_WORKFLOW_CHAIN_KEY];
31
+ return Array.isArray(chain) ? chain : [];
32
+ }
33
+ /** The dispatch id of the child session this config belongs to, if it is one. */
34
+ export function subWorkflowDispatchId(configurable) {
35
+ const id = configurable?.[SUB_WORKFLOW_DISPATCH_KEY];
36
+ return typeof id === "string" && id !== "" ? id : undefined;
37
+ }
38
+ /**
39
+ * Variable seeds this invocation carries, layered **over** the assembly's own at
40
+ * the turn boundary. Absent for an ordinary turn.
41
+ */
42
+ export function seedVariablesFrom(configurable) {
43
+ const seeds = configurable?.[SEED_VARIABLES_KEY];
44
+ return seeds && typeof seeds === "object" && !Array.isArray(seeds)
45
+ ? seeds
46
+ : undefined;
47
+ }
48
+ /** Read the session scope from a config; a config with no `thread_id` is {@link DEFAULT_SESSION_ID}. */
49
+ export function sessionScopeFrom(config, fallbackSessionId = DEFAULT_SESSION_ID) {
50
+ const configurable = config?.configurable;
51
+ const sessionId = configurable?.thread_id ?? fallbackSessionId;
52
+ const chain = subWorkflowChain(configurable);
53
+ const dispatchId = subWorkflowDispatchId(configurable);
54
+ return {
55
+ sessionId,
56
+ chain,
57
+ depth: chain.length,
58
+ ...(dispatchId ? { dispatchId } : {}),
59
+ };
60
+ }
61
+ /**
62
+ * Drop `sessionId`'s entry and every child session's entry from a session-keyed
63
+ * map. Disposal is requested per session, so it must reach the children nested
64
+ * under it or a delegating session leaks a REPL per dispatch. Returns the ids
65
+ * released, so a caller holding several parallel maps can release the same set.
66
+ */
67
+ export function releaseScopes(map, sessionId) {
68
+ const released = [];
69
+ for (const key of map.keys()) {
70
+ if (key === sessionId || isChildSessionOf(key, sessionId))
71
+ released.push(key);
72
+ }
73
+ for (const key of released)
74
+ map.delete(key);
75
+ return released;
76
+ }
77
+ /**
78
+ * The child identity for one dispatch: `<state>:<workflow>:<ordinal>`. The
79
+ * ordinal keeps a second visit to the same state (an `on_error` loop, a retried
80
+ * turn) and concurrently dispatched children of one state apart.
81
+ */
82
+ export function subRunIdentity(state, workflow, ordinal) {
83
+ return `${state}:${workflow}:${ordinal}`;
84
+ }
85
+ /**
86
+ * Separator between a parent's session id and a child's dispatch identity. A
87
+ * session id becomes a directory name in the filesystem store, so it must be
88
+ * legal on every platform: `~` is, LangGraph's `|` is not.
89
+ */
90
+ const CHILD_SESSION_SEPARATOR = "~";
91
+ /**
92
+ * The session id one child gets: `<parent>~<state>:<workflow>:<ordinal>` — an
93
+ * ordinary session with its own checkpoints and zone. Derived rather than minted
94
+ * at random, so a re-dispatch of the same call resolves to the same child and a
95
+ * resumed parent finds the child it parked on.
96
+ */
97
+ export function childSessionId(parentSessionId, identity) {
98
+ return `${parentSessionId}${CHILD_SESSION_SEPARATOR}${identity}`;
99
+ }
100
+ /**
101
+ * The shape a dispatch identity takes: `<state>:<workflow>:<ordinal>`. Matched
102
+ * rather than assumed, so a host id like `tenant~conversation` is not read as a
103
+ * child of `tenant` (and disposed with it); only ids this module minted count.
104
+ */
105
+ const CHILD_IDENTITY = /^[^~:]+:[^~:]+:\d+$/;
106
+ /**
107
+ * The session that dispatched `sessionId`, or `undefined` for a top-level
108
+ * session. Derived from the id, so there is no index to drift.
109
+ */
110
+ export function parentSessionIdOf(sessionId) {
111
+ const at = sessionId.lastIndexOf(CHILD_SESSION_SEPARATOR);
112
+ if (at <= 0)
113
+ return undefined;
114
+ return CHILD_IDENTITY.test(sessionId.slice(at + 1)) ? sessionId.slice(0, at) : undefined;
115
+ }
116
+ /** Whether `sessionId` is a session dispatched by `parentSessionId`, at any depth. */
117
+ export function isChildSessionOf(sessionId, parentSessionId) {
118
+ if (!sessionId.startsWith(`${parentSessionId}${CHILD_SESSION_SEPARATOR}`))
119
+ return false;
120
+ const descent = sessionId.slice(parentSessionId.length + 1).split(CHILD_SESSION_SEPARATOR);
121
+ return descent.every((segment) => CHILD_IDENTITY.test(segment));
122
+ }
123
+ /**
124
+ * The config a child session is invoked with: its **own** `thread_id` (see
125
+ * {@link childSessionId}), the extended dispatch chain and the dispatch id.
126
+ * `checkpoint_id` and `checkpoint_ns` are cleared: each pins a position in the
127
+ * *caller's* thread, which the child's thread has never written.
128
+ */
129
+ export function childRunConfig(parentConfig, child) {
130
+ const configurable = { ...(parentConfig.configurable ?? {}) };
131
+ delete configurable.checkpoint_id;
132
+ delete configurable.checkpoint_ns;
133
+ const parentScope = sessionScopeFrom(parentConfig, "");
134
+ const parentSessionId = configurable.thread_id ?? "";
135
+ return {
136
+ ...parentConfig,
137
+ configurable: {
138
+ ...configurable,
139
+ thread_id: childSessionId(parentSessionId, child.identity),
140
+ [SUB_WORKFLOW_CHAIN_KEY]: [...parentScope.chain, child.workflow],
141
+ [SUB_WORKFLOW_DISPATCH_KEY]: child.dispatchId,
142
+ },
143
+ };
144
+ }
145
+ //# sourceMappingURL=scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../src/sessions/scope.ts"],"names":[],"mappings":"AASA,gHAAgH;AAChH,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAAC;AAEhD;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,4BAA4B,CAAC;AAEnE,4FAA4F;AAC5F,MAAM,CAAC,MAAM,yBAAyB,GAAG,+BAA+B,CAAC;AAEzE;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,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C;YAC1D,CAAC,sBAAsB,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC;YAChE,CAAC,yBAAyB,CAAC,EAAE,KAAK,CAAC,UAAU;SAC9C;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * One session's projection, read by key from its latest checkpoint — and the
3
+ * listing built from it. A reading of checkpointed state rather than part of the
4
+ * saver, so it works for any `BaseCheckpointSaver`, an in-memory one included.
5
+ */
6
+ import type { BaseCheckpointSaver } from "@langchain/langgraph-checkpoint";
7
+ import { type UsageSummary } from "../core/usage.js";
8
+ import type { Workspace } from "../core/workspace.js";
9
+ import type { VariableStore } from "../machine/variables.js";
10
+ import { type SessionClassification, type WorkflowStatus } from "../workflow/state.js";
11
+ /** Coarse projection of a durable session, derived from its latest checkpoint. */
12
+ export interface SessionSummary {
13
+ /** The conversation this summary describes — the only id there is. */
14
+ sessionId: string;
15
+ status?: WorkflowStatus;
16
+ /** Which side of the open/finished partition {@link status} falls on — a parked session is open, never finished. */
17
+ classification?: SessionClassification;
18
+ /** The state the session currently occupies — where its next turn continues. */
19
+ workflowState?: string;
20
+ /** The definition the session's latest turn ran under (metadata, never a guard). */
21
+ specHash?: string;
22
+ /** For parked sessions, the state awaiting a human decision or an external event. */
23
+ state?: string;
24
+ /** @deprecated Older spelling of {@link state}; kept for one release. */
25
+ node?: string;
26
+ /**
27
+ * For a session the agent parked with `archmax_wait`, its own stated reason. A
28
+ * park declares no awaited trigger ids (any firing resumes it), so this is
29
+ * what a surface shows instead.
30
+ */
31
+ waitReason?: string;
32
+ /**
33
+ * When such a park asked to be resumed (absolute), when it declared an `until`.
34
+ * A host's scheduler is a query over this listing; the runtime schedules nothing.
35
+ */
36
+ resumeAt?: string;
37
+ /**
38
+ * The session's variables as the checkpoint holds them — `name → { value, locked }`,
39
+ * omitted when the session has none. `locked` marks a host-established entry;
40
+ * an unlocked one came from the agent's own `archmax_set_variables`.
41
+ */
42
+ variables?: VariableStore;
43
+ /**
44
+ * What the session has cost so far: cumulative token counts, plus `costUsd`
45
+ * when pricing is configured; omitted when nothing has been spent. Read from
46
+ * the checkpoint, so a session resumed in another process reports the whole.
47
+ */
48
+ usage?: UsageSummary;
49
+ /** The session that dispatched this one, when it is a child session (see `isChildSessionOf`). */
50
+ parentSessionId?: string;
51
+ }
52
+ /**
53
+ * Project a session's latest checkpoint into a {@link SessionSummary} using only
54
+ * `getTuple`, so it works for **any** `BaseCheckpointSaver`. Session resolution
55
+ * depends on this answer being real: `null` means "this session has not run yet".
56
+ */
57
+ export declare function summarizeCheckpointedSession(checkpointer: BaseCheckpointSaver, sessionId: string): Promise<SessionSummary | null>;
58
+ /**
59
+ * Enumerate durable sessions by listing the session store's root (one
60
+ * `<sessionId>/` folder per session) and projecting each latest checkpoint.
61
+ * Runs outside any bound session, so the listing is the raw store root: reserved
62
+ * root names (authored mounts, `_specs/`, session areas) and sessions without a
63
+ * readable checkpoint are skipped.
64
+ */
65
+ export declare function listSessions(workspace: Workspace, checkpointer: BaseCheckpointSaver): Promise<SessionSummary[]>;