@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,85 @@
1
+ import type { StructuredTool } from "@langchain/core/tools";
2
+ import type { AgentMiddleware } from "langchain";
3
+ import type { ScriptExecutor } from "../sandbox/executor.js";
4
+ import type { PtcToolGateway } from "../sandbox/ptc-gateway.js";
5
+ import { LifecycleRunner, type HookExecutor, type HookScriptResolver } from "../lifecycle/runner.js";
6
+ import type { WorkflowMachine } from "../machine/machine.js";
7
+ import type { Rubric } from "../rubrics/rubrics.js";
8
+ import type { Workspace } from "../core/workspace.js";
9
+ import { type WorkflowEventHandler } from "../core/events.js";
10
+ import type { VariableStore } from "../machine/variables.js";
11
+ import type { SubWorkflowDispatcher } from "./sub-workflow.js";
12
+ import type { GovernanceRule } from "../kernel/kernel.js";
13
+ import { type MountPrefixes } from "../core/mounts.js";
14
+ import type { SkillRegistry } from "../core/skills.js";
15
+ import { type PricingTable } from "../core/usage.js";
16
+ import { type PromptShaping, type StateModels } from "./governance.js";
17
+ export type { PromptShaping, StateModels } from "./governance.js";
18
+ export { resolveToolName } from "./governance.js";
19
+ export { pruneUndisclosedToolSections, upstreamSectionsFor, type PruneResult } from "./prompt-pruning.js";
20
+ export interface WorkflowInstrumentation {
21
+ /**
22
+ * The suspension site: the one middleware that calls `interrupt()`. It must be
23
+ * the FIRST middleware in the agent's array that declares an `afterModel` hook:
24
+ * hook nodes run in array order before the model and in reverse after it, so
25
+ * that position puts every hook that emits before the one that suspends, and
26
+ * makes the final router honour this hook's `jumpTo` when a resume continues
27
+ * to the model.
28
+ */
29
+ parkMiddleware: AgentMiddleware;
30
+ /** The governance middleware proper; assembled after {@link parkMiddleware}. */
31
+ middleware: AgentMiddleware;
32
+ tools: StructuredTool[];
33
+ lifecycle: LifecycleRunner;
34
+ /** Release every per-session resource (idempotent; safe for sessions that never ran). */
35
+ dispose(sessionId: string): void;
36
+ }
37
+ export interface WorkflowMiddlewareOptions {
38
+ machine: WorkflowMachine;
39
+ /** Serves the agent's own `archmax_eval`/`archmax_run` over the agent workspace. */
40
+ executor: ScriptExecutor;
41
+ /** The workflow's grading rubrics, dispatched by a `{ rubric: … }` hook. */
42
+ rubrics?: Map<string, Rubric>;
43
+ ptcNames: string[];
44
+ /** Consumer rules, evaluated after the safety and `policy` rules, before per-state defaults. */
45
+ policyRules?: GovernanceRule[];
46
+ /** The workspace's resolved mount keys, so the kernel's read-only rule can classify authored paths. */
47
+ mountPrefixes?: MountPrefixes;
48
+ /** The workspace's skills: one table for what the kernel refuses, the prompt names, a listing returns. */
49
+ skills?: SkillRegistry;
50
+ /** Custom hook-kind executors registered alongside the built-in `script`/`rubric`. */
51
+ hookExecutors?: Record<string, HookExecutor>;
52
+ /** Script executor for lifecycle hooks, reading from the authoring backend. Defaults to {@link executor}. */
53
+ hookExecutor?: ScriptExecutor;
54
+ /** Resolves a hook's declared `script:` to its authoring-backend path. */
55
+ resolveHookScript?: HookScriptResolver;
56
+ /** Governs the `tools.*` calls hook scripts make and carries the live per-session context. */
57
+ ptcGateway?: PtcToolGateway;
58
+ /** Runs delegated machines. Omitted, a delegation call falls through to the tool's own body. */
59
+ subWorkflows?: SubWorkflowDispatcher;
60
+ /** Lifecycle event subscriber (default: console rendering). */
61
+ onEvent?: WorkflowEventHandler;
62
+ /** How the model-facing payload is shaped for this assembly. */
63
+ promptShaping?: PromptShaping;
64
+ /** Which model each state's calls run on; omitted, every call uses the graph's own. */
65
+ stateModels?: StateModels;
66
+ /** Workspace backend for writing the spec snapshot into the session zone. */
67
+ workspace?: Workspace;
68
+ /** The `workflows/<slug>/` name, used only to name the machine in a refusal. */
69
+ workflowName?: string;
70
+ /** The assembly-time default trigger, used when an invocation supplies none. */
71
+ trigger?: {
72
+ id: string;
73
+ };
74
+ /** Host-seeded run variables, applied at each turn boundary (already locked). */
75
+ seededVariables?: VariableStore;
76
+ /** Token prices used to attach `costUsd` to usage events. */
77
+ pricing?: PricingTable;
78
+ }
79
+ /**
80
+ * In-graph governance for the Deep Agent: the turn boundary, per-state tool
81
+ * disclosure and the kernel's verdict on every call, lifecycle hooks, the
82
+ * control tools, budgets, `on_error` routing, and every park's commit, closing
83
+ * turn and suspension.
84
+ */
85
+ export declare function createWorkflowInstrumentation(opts: WorkflowMiddlewareOptions): WorkflowInstrumentation;
@@ -0,0 +1,283 @@
1
+ import { RemoveMessage } from "@langchain/core/messages";
2
+ import { v4 as uuidv4 } from "@langchain/core/utils/uuid";
3
+ import { createMiddleware } from "langchain";
4
+ import { LifecycleRunner } from "../lifecycle/runner.js";
5
+ import { createWorkflowEventEmitter } from "../core/events.js";
6
+ import { createControlTools, SET_VARIABLES_TOOL } from "./control-tools.js";
7
+ import { currentWorkflowState, isReplyOnly, pendingParkOf, readRunUsage, readVariables, readWorkflowState, WORKFLOW_STATUSES, workflowStateSchema, } from "./state.js";
8
+ import { sessionScopeFrom } from "../sessions/scope.js";
9
+ import { contentToString, isAiMessage, isRuntimeNote, lastMessageIsHuman, runtimeNote } from "../core/messages.js";
10
+ import { NO_MOUNTS } from "../core/mounts.js";
11
+ import { addSummaries, extractUsage, summarizeUsage } from "../core/usage.js";
12
+ import { routeFailure } from "./on-error.js";
13
+ import { servePark, suspendIfParked } from "./parks.js";
14
+ import { openTurn } from "./turn-boundary.js";
15
+ import { beforeVetoReason, budgetExhaustedReason, buildRunnableConfig, createGovernance, } from "./governance.js";
16
+ export { resolveToolName } from "./governance.js";
17
+ export { pruneUndisclosedToolSections, upstreamSectionsFor } from "./prompt-pruning.js";
18
+ /**
19
+ * The id a message will be committed under, assigning one when it arrived
20
+ * without: LangGraph's reducer does the same at commit, so the id on the event
21
+ * and in the transcript are one value.
22
+ */
23
+ function committedMessageId(msg) {
24
+ const id = msg.id;
25
+ if (typeof id === "string" && id)
26
+ return id;
27
+ const assigned = uuidv4();
28
+ msg.id = assigned;
29
+ // The reducer keeps `lc_kwargs.id` in step with `id`.
30
+ const kwargs = msg.lc_kwargs;
31
+ if (kwargs && typeof kwargs === "object")
32
+ kwargs.id = assigned;
33
+ return assigned;
34
+ }
35
+ /** Whether an AI message still carries tool calls the tools node has to answer. */
36
+ function callsTools(message) {
37
+ const calls = message?.tool_calls;
38
+ return Array.isArray(calls) && calls.length > 0;
39
+ }
40
+ /** The middleware's declared hook result type — the update, however typed. */
41
+ const asHookResult = (update) => update;
42
+ /**
43
+ * In-graph governance for the Deep Agent: the turn boundary, per-state tool
44
+ * disclosure and the kernel's verdict on every call, lifecycle hooks, the
45
+ * control tools, budgets, `on_error` routing, and every park's commit, closing
46
+ * turn and suspension.
47
+ */
48
+ export function createWorkflowInstrumentation(opts) {
49
+ const { machine, executor, rubrics = new Map(), ptcNames, ptcGateway, subWorkflows, onEvent, pricing, stateModels } = opts;
50
+ const emit = createWorkflowEventEmitter(onEvent);
51
+ const lifecycleHooks = machine.lifecycleHooks();
52
+ const lifecycle = new LifecycleRunner(machine, opts.hookExecutor ?? executor, rubrics, ptcNames, opts.hookExecutors, onEvent, ...(opts.resolveHookScript ? [{ resolveScript: opts.resolveHookScript }] : []));
53
+ if (Object.keys(lifecycleHooks).length > 0) {
54
+ emit({
55
+ type: "hooks-summary",
56
+ summary: Object.entries(lifecycleHooks)
57
+ .map(([s, l]) => `${s}(${[l.before && "before", l.after && "after"].filter(Boolean).join("+")})`)
58
+ .join(", "),
59
+ });
60
+ }
61
+ const sessionIdOf = (runtime) => sessionScopeFrom(runtime).sessionId;
62
+ const configOf = (runtime) => buildRunnableConfig((runtime ?? {}));
63
+ const governance = createGovernance({
64
+ machine,
65
+ emit,
66
+ lifecycle,
67
+ policyRules: opts.policyRules ?? [],
68
+ mountPrefixes: opts.mountPrefixes ?? NO_MOUNTS,
69
+ skills: opts.skills ?? new Map(),
70
+ shaping: opts.promptShaping ?? {},
71
+ ...(opts.stateModels ? { stateModels: opts.stateModels } : {}),
72
+ ...(ptcGateway ? { ptcGateway } : {}),
73
+ ...(subWorkflows ? { subWorkflows } : {}),
74
+ sessionIdOf,
75
+ });
76
+ const parkCtx = {
77
+ machine,
78
+ emit,
79
+ ...(subWorkflows ? { dispatcher: subWorkflows } : {}),
80
+ sessionIdOf,
81
+ configOf,
82
+ };
83
+ const failureCtx = { machine, emit, sessionIdOf };
84
+ const turnCtx = {
85
+ machine,
86
+ emit,
87
+ onEvent,
88
+ ...(opts.workspace ? { workspace: opts.workspace } : {}),
89
+ ...(opts.workflowName ? { workflowName: opts.workflowName } : {}),
90
+ ...(opts.trigger ? { defaultTrigger: opts.trigger } : {}),
91
+ ...(opts.seededVariables ? { seededVariables: opts.seededVariables } : {}),
92
+ };
93
+ /**
94
+ * The suspension site. Its `beforeModel` runs first of all before-model hooks
95
+ * and its `afterModel` last of all after-model hooks, so by the time it looks
96
+ * at a park every record is committed and every event emitted, and the only
97
+ * thing it does before `interrupt()` is read state — which is what makes its
98
+ * re-execution on resume repeat nothing.
99
+ */
100
+ const parkMiddleware = createMiddleware({
101
+ name: "WorkflowParkMiddleware",
102
+ stateSchema: workflowStateSchema,
103
+ beforeModel: {
104
+ canJumpTo: ["end"],
105
+ hook: async (state, runtime) => asHookResult(await suspendIfParked(parkCtx, state, runtime, "before-model")),
106
+ },
107
+ afterModel: {
108
+ canJumpTo: ["model"],
109
+ hook: async (state, runtime) => asHookResult(await suspendIfParked(parkCtx, state, runtime, "after-model")),
110
+ },
111
+ });
112
+ const middleware = createMiddleware({
113
+ name: "WorkflowMiddleware",
114
+ stateSchema: workflowStateSchema,
115
+ // The turn boundary: once per invoke, never on a resume.
116
+ beforeAgent: {
117
+ canJumpTo: ["end"],
118
+ hook: async (state, runtime) => asHookResult(await openTurn(turnCtx, state, runtime)),
119
+ },
120
+ beforeModel: {
121
+ canJumpTo: ["end"],
122
+ hook: (state, runtime) => {
123
+ const fields = readWorkflowState(state);
124
+ const workflowState = currentWorkflowState(state, machine.entry);
125
+ // A park in progress: the closing turn it owes, or a delegated child's decision to present.
126
+ const served = servePark(parkCtx, state, runtime, "before-model");
127
+ if (served)
128
+ return asHookResult(served);
129
+ // A reply-only turn is owed exactly one model call; anything after the
130
+ // person's message means it has been spent.
131
+ if (isReplyOnly(state)) {
132
+ return asHookResult(lastMessageIsHuman(state.messages ?? []) ? undefined : { jumpTo: "end" });
133
+ }
134
+ // The exact per-state turn budget: this call would be one too many.
135
+ const maxTurns = machine.spec.states[workflowState]?.budget?.maxTurns;
136
+ const spent = fields.stateTurns?.state === workflowState ? fields.stateTurns.count : 0;
137
+ if (maxTurns != null && spent + 1 > maxTurns) {
138
+ const routed = routeFailure(failureCtx, state, runtime, workflowState, `state '${workflowState}' exhausted its turn budget (maxTurns: ${maxTurns})`, "before-model");
139
+ // The error handler's first call is the one about to be made.
140
+ if (routed.workflowState)
141
+ routed.stateTurns = { state: routed.workflowState, count: 1 };
142
+ return asHookResult(routed);
143
+ }
144
+ return asHookResult({ stateTurns: { state: workflowState, count: spent + 1 } });
145
+ },
146
+ },
147
+ wrapModelCall: governance.wrapModelCall,
148
+ wrapToolCall: governance.wrapToolCall,
149
+ afterModel: {
150
+ canJumpTo: ["model"],
151
+ hook: async (state, runtime) => {
152
+ const fields = readWorkflowState(state);
153
+ const workflowState = currentWorkflowState(state, machine.entry);
154
+ const messages = state.messages ?? [];
155
+ const last = messages[messages.length - 1];
156
+ const update = {};
157
+ // 1. Report the message the model just produced and what it cost. Usage is
158
+ // committed as the new total: the channel is last-value and this hook is its one writer.
159
+ if (last && isAiMessage(last) && !isRuntimeNote(last)) {
160
+ const text = contentToString(last.content).trim();
161
+ if (text)
162
+ emit({ type: "agent-text", state: workflowState, text, messageId: committedMessageId(last) });
163
+ const extracted = extractUsage(last);
164
+ if (extracted) {
165
+ // What the response said, else what we asked the endpoint to run,
166
+ // else nothing. The reported id leads deliberately — a proxy may
167
+ // serve an alias, a fallback or a load-balanced deployment, and what
168
+ // it served is the honest thing to price — but a response naming no
169
+ // model must not cost the call its price when assembly knows which
170
+ // model it built. The id used is reported, so a host can attribute
171
+ // the call to a model rather than to nothing.
172
+ const modelId = extracted.model ?? stateModels?.idFor(workflowState);
173
+ const summary = summarizeUsage(extracted.usage, pricing, modelId);
174
+ emit({
175
+ type: "model-usage",
176
+ state: workflowState,
177
+ ...summary,
178
+ ...(modelId ? { model: modelId } : {}),
179
+ });
180
+ update.usage = addSummaries(readRunUsage(state), summary);
181
+ }
182
+ }
183
+ // 2. A model call that ran out of its time budget: the marker leaves the transcript, the failure routes.
184
+ const exhausted = budgetExhaustedReason(last);
185
+ if (exhausted !== undefined && typeof last?.id === "string") {
186
+ const routed = routeFailure(failureCtx, state, runtime, workflowState, exhausted, "after-model");
187
+ return asHookResult({
188
+ ...update,
189
+ ...routed,
190
+ messages: [new RemoveMessage({ id: last.id }), ...(routed.messages ?? [])],
191
+ });
192
+ }
193
+ // 3. A `before` hook refused this state: the model never ran, so nothing
194
+ // below applies. Routed like any terminal rejection — the refusal text
195
+ // stays in the transcript as the reply the person is owed, unlike the
196
+ // budget marker above, which stood in for an answer that never came.
197
+ const refusedEntry = beforeVetoReason(last);
198
+ if (refusedEntry !== undefined) {
199
+ return asHookResult({
200
+ ...update,
201
+ ...routeFailure(failureCtx, state, runtime, workflowState, refusedEntry, "after-model"),
202
+ });
203
+ }
204
+ // 4. A park's closing or answering turn was just spent.
205
+ const served = servePark(parkCtx, state, runtime, "after-model");
206
+ if (served)
207
+ return asHookResult({ ...update, ...served });
208
+ if (pendingParkOf(state) || (fields.pendingDelegations ?? []).length > 0) {
209
+ return asHookResult(update);
210
+ }
211
+ // 5. The run ends here only when the model finished — no tool calls pending — in a state that is not parked.
212
+ if (!last || !isAiMessage(last) || callsTools(last) || isReplyOnly(state)) {
213
+ return asHookResult(update);
214
+ }
215
+ // A rejection a tool committed (a terminal kernel block, an exhausted park
216
+ // budget, a failed sub-run) routes once the model has finished in the failing state.
217
+ if (fields.rejected) {
218
+ return asHookResult({
219
+ ...update,
220
+ ...routeFailure(failureCtx, state, runtime, workflowState, fields.rejected, "after-model"),
221
+ });
222
+ }
223
+ // A terminal state has no `archmax_advance` out of it, so its `after` hook
224
+ // runs at completion: `correct` hands the state back with a note, a
225
+ // terminal failure routes through `on_error`.
226
+ if (machine.isTerminal(workflowState) && lifecycleHooks[workflowState]?.after?.length) {
227
+ const ctx = governance.lifecycleCtx(sessionIdOf(runtime), state, messages);
228
+ const reject = await lifecycle.runPhase(workflowState, "after", ctx, undefined, true);
229
+ if (reject) {
230
+ if (reject.terminal) {
231
+ return asHookResult({
232
+ ...update,
233
+ iterations: ctx.iterations,
234
+ ...routeFailure(failureCtx, state, runtime, workflowState, reject.reason, "after-model"),
235
+ });
236
+ }
237
+ return asHookResult({
238
+ ...update,
239
+ messages: runtimeNote("after", `[after] The '${workflowState}' completion check did not pass: ${reject.reason}. ` +
240
+ `Revise your work and produce a corrected final response.`),
241
+ iterations: ctx.iterations,
242
+ jumpTo: "model",
243
+ });
244
+ }
245
+ update.iterations = ctx.iterations;
246
+ }
247
+ // The exit half of the trigger's signature, checked where a run completes — never at a park.
248
+ const unsetReturns = (machine.returnsForTrigger(fields.trigger?.id ?? "") ?? []).filter((name) => readVariables(state)[name] === undefined);
249
+ if (unsetReturns.length > 0) {
250
+ const reason = `Completed in state '${workflowState}' without setting ` +
251
+ `${unsetReturns.map((n) => `'${n}'`).join(", ")}, which trigger ` +
252
+ `'${fields.trigger?.id}' declares in its 'returns'. Set ` +
253
+ `${unsetReturns.length === 1 ? "it" : "them"} with '${SET_VARIABLES_TOOL}' before ` +
254
+ `finishing.`;
255
+ return asHookResult({ ...update, rejected: reason, status: WORKFLOW_STATUSES.rejected });
256
+ }
257
+ emit({ type: "state-leave", state: workflowState, next: workflowState });
258
+ return asHookResult({ ...update, status: WORKFLOW_STATUSES.completed });
259
+ },
260
+ },
261
+ // Flush this turn's staged `beforeDone` entries as one state update.
262
+ afterAgent: (state, runtime) => {
263
+ const staged = governance.endTurn(sessionIdOf(runtime));
264
+ if (!staged)
265
+ return undefined;
266
+ return { beforeDone: { ...(readWorkflowState(state).beforeDone ?? {}), ...staged } };
267
+ },
268
+ });
269
+ return {
270
+ parkMiddleware,
271
+ middleware,
272
+ tools: createControlTools(),
273
+ lifecycle,
274
+ dispose: (sessionId) => {
275
+ // Requested per session, so it sweeps the session and every sub-run session nested beneath it.
276
+ for (const scope of new Set([...governance.release(sessionId), sessionId])) {
277
+ ptcGateway?.release(scope);
278
+ lifecycle.dispose(scope);
279
+ }
280
+ },
281
+ };
282
+ }
283
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/workflow/middleware.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAI7C,OAAO,EAAE,eAAe,EAA8C,MAAM,wBAAwB,CAAC;AAIrG,OAAO,EAAE,0BAA0B,EAA6B,MAAM,mBAAmB,CAAC;AAC1F,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE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E,EAAE,GAAG,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,GAAG,MAAM,EAAE,EAAE,CAAC;QACvF,CAAC;KACF,CAAC,CAAC;IAEH,OAAO;QACL,cAAc;QACd,UAAU;QACV,KAAK,EAAE,kBAAkB,EAAE;QAC3B,SAAS;QACT,OAAO,EAAE,CAAC,SAAS,EAAE,EAAE;YACrB,+FAA+F;YAC/F,KAAK,MAAM,KAAK,IAAI,IAAI,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC;gBAC3E,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;gBAC3B,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * `on_error`: where a failed state sends the run. Every failure a state cannot
3
+ * recover from in place arrives here as a `reason`; the run routes to the
4
+ * declared `on_error` target with an `[error]` runtime note, or ends rejected.
5
+ * Fail-closed either way: nothing continues in the state that failed.
6
+ */
7
+ import type { WorkflowEventEmitter } from "../core/events.js";
8
+ import type { WorkflowMachine } from "../machine/machine.js";
9
+ import { type WorkflowUpdate } from "./state.js";
10
+ /** Which hook is routing: decides how the loop continues after the update. */
11
+ export type HookSite = "before-model" | "after-model";
12
+ export interface FailureRoutingContext {
13
+ machine: WorkflowMachine;
14
+ emit: WorkflowEventEmitter;
15
+ /** The session the failing hook is executing for, for the park it may open. */
16
+ sessionIdOf(runtime: unknown): string;
17
+ }
18
+ /**
19
+ * The update that settles a failed state. With an `on_error` target: the note,
20
+ * the new position, an `on_error` trail step, every park record cleared, and —
21
+ * from `afterModel`, where the loop would otherwise exit — a jump back to the
22
+ * model. Without one: `rejected`; `beforeModel` ends the turn outright. A human
23
+ * `on_error` target is presented at once, with the closing message owed.
24
+ */
25
+ export declare function routeFailure(ctx: FailureRoutingContext, state: unknown, runtime: unknown, from: string, reason: string, site: HookSite): WorkflowUpdate;
@@ -0,0 +1,58 @@
1
+ import { runtimeNote } from "../core/messages.js";
2
+ import { decisionRecordFor } from "./parks.js";
3
+ import { readWorkflowState, WORKFLOW_STATUSES, } from "./state.js";
4
+ /**
5
+ * The update that settles a failed state. With an `on_error` target: the note,
6
+ * the new position, an `on_error` trail step, every park record cleared, and —
7
+ * from `afterModel`, where the loop would otherwise exit — a jump back to the
8
+ * model. Without one: `rejected`; `beforeModel` ends the turn outright. A human
9
+ * `on_error` target is presented at once, with the closing message owed.
10
+ */
11
+ export function routeFailure(ctx, state, runtime, from, reason, site) {
12
+ const errorTarget = ctx.machine.onError(from);
13
+ if (!errorTarget) {
14
+ return {
15
+ rejected: reason,
16
+ status: WORKFLOW_STATUSES.rejected,
17
+ ...(site === "before-model" ? { jumpTo: "end" } : {}),
18
+ };
19
+ }
20
+ ctx.emit({ type: "state-error-routed", state: from, to: errorTarget, reason });
21
+ ctx.emit({ type: "state-leave", state: from, next: errorTarget });
22
+ ctx.emit({ type: "state-enter", state: errorTarget });
23
+ const routed = {
24
+ messages: runtimeNote("error", `[error] The '${from}' state failed: ${reason}. Routing to the '${errorTarget}' error handler.`),
25
+ workflowState: errorTarget,
26
+ rejected: null,
27
+ status: WORKFLOW_STATUSES.running,
28
+ pendingInput: null,
29
+ pendingDecision: null,
30
+ pendingDelegations: null,
31
+ parkPhase: null,
32
+ replyOnly: null,
33
+ stateTurns: null,
34
+ auditTrail: [
35
+ { to: errorTarget, kind: "on_error", reason, ts: Date.now() },
36
+ ],
37
+ ...(site === "after-model" ? { jumpTo: "model" } : {}),
38
+ };
39
+ if (!ctx.machine.isHumanState(errorTarget))
40
+ return routed;
41
+ const seq = (readWorkflowState(state).decisionCount ?? 0) + 1;
42
+ ctx.emit({
43
+ type: "parked",
44
+ node: errorTarget,
45
+ state: errorTarget,
46
+ sessionId: ctx.sessionIdOf(runtime),
47
+ awaiting: "decision",
48
+ });
49
+ return {
50
+ ...routed,
51
+ pendingDecision: decisionRecordFor(ctx.machine, errorTarget, seq),
52
+ decisionCount: seq,
53
+ status: WORKFLOW_STATUSES.awaitingDecision,
54
+ parkPhase: "suspend",
55
+ replyOnly: true,
56
+ };
57
+ }
58
+ //# sourceMappingURL=on-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"on-error.js","sourceRoot":"","sources":["../../src/workflow/on-error.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EACL,iBAAiB,EACjB,iBAAiB,GAGlB,MAAM,YAAY,CAAC;AAYpB;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,GAA0B,EAC1B,KAAc,EACd,OAAgB,EAChB,IAAY,EACZ,MAAc,EACd,IAAc;IAEd,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO;YACL,QAAQ,EAAE,MAAM;YAChB,MAAM,EAAE,iBAAiB,CAAC,QAAQ;YAClC,GAAG,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACtD,CAAC;IACJ,CAAC;IACD,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,oBAAoB,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;IAC/E,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;IAClE,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE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SAAS,EAAE,SAAS;QACpB,SAAS,EAAE,IAAI;KAChB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,46 @@
1
+ import type { RunnableConfig } from "@langchain/core/runnables";
2
+ import type { WorkflowEventEmitter } from "../core/events.js";
3
+ import type { WorkflowMachine } from "../machine/machine.js";
4
+ import type { HookSite } from "./on-error.js";
5
+ import { type PendingDecision, type PendingInput, type WorkflowUpdate } from "./state.js";
6
+ import { type SubWorkflowDispatcher } from "./sub-workflow.js";
7
+ /**
8
+ * The pending-decision record for a human state: its declared transitions and
9
+ * evidence (the author's list leads and is never displaced), plus whatever the
10
+ * transition attached, duplicates removed keeping first position.
11
+ */
12
+ export declare function decisionRecordFor(machine: WorkflowMachine, state: string, seq: number, attached?: readonly string[]): PendingDecision;
13
+ /** The pending-input record for a state the agent parked with `archmax_wait`. */
14
+ export declare function inputRecordFor(machine: WorkflowMachine, state: string, reason: string, resumeAt?: string): PendingInput;
15
+ /**
16
+ * What a reply-only turn is told. Four shapes of park reach this — handing the
17
+ * run to a person, being routed to one by a decision, waiting for something
18
+ * from outside, and answering someone while a person decides — each with its
19
+ * own first sentence. The last paragraph is the same in all: it is what stands
20
+ * between a parked run and a model that would rather keep working.
21
+ */
22
+ export declare function replyOnlyDirective(machine: WorkflowMachine, state: unknown): string;
23
+ export interface ParkContext {
24
+ machine: WorkflowMachine;
25
+ emit: WorkflowEventEmitter;
26
+ /** Resumes a parked child; absent in an assembly that cannot run sub-workflows. */
27
+ dispatcher?: SubWorkflowDispatcher;
28
+ /** The session a hook is executing for, read from its runtime. */
29
+ sessionIdOf(runtime: unknown): string;
30
+ /** The runnable config a hook's runtime stands for, for a child's resume. */
31
+ configOf(runtime: unknown): RunnableConfig;
32
+ }
33
+ /**
34
+ * Move a park along, deterministically on state. Before the model: a record in
35
+ * phase `closing` gets its closing turn; a delegated child that parked becomes
36
+ * the pending decision and gets its closing turn. After the model: a reply-only
37
+ * turn that just spoke is spent, and an answer to a person's message is reported.
38
+ */
39
+ export declare function servePark(ctx: ParkContext, state: unknown, runtime: unknown, site: HookSite): WorkflowUpdate | undefined;
40
+ /**
41
+ * The suspension site: with a record in phase `suspend` and nothing owed, park
42
+ * the session on it. `interrupt()` throws on first arrival — the session parks
43
+ * durably — and on resume returns what a surface resumed with, which
44
+ * {@link applyResume} turns into the run's continuation.
45
+ */
46
+ export declare function suspendIfParked(ctx: ParkContext, state: unknown, runtime: unknown, site: HookSite): Promise<WorkflowUpdate | undefined>;