@intx/workflow-host 0.2.2

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 (81) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +287 -0
  3. package/dist/adapters/blob-substrate.d.ts +49 -0
  4. package/dist/adapters/blob-substrate.js +140 -0
  5. package/dist/adapters/repo-store.d.ts +39 -0
  6. package/dist/adapters/repo-store.js +344 -0
  7. package/dist/adapters/spawn-child.d.ts +74 -0
  8. package/dist/adapters/spawn-child.js +152 -0
  9. package/dist/adapters/step-invoker.d.ts +114 -0
  10. package/dist/adapters/step-invoker.js +360 -0
  11. package/dist/child/env-bootstrap.d.ts +56 -0
  12. package/dist/child/env-bootstrap.js +120 -0
  13. package/dist/child/from-process-env.d.ts +127 -0
  14. package/dist/child/from-process-env.js +183 -0
  15. package/dist/child/index.d.ts +9 -0
  16. package/dist/child/index.js +9 -0
  17. package/dist/child/outbound-mail-bridge.d.ts +36 -0
  18. package/dist/child/outbound-mail-bridge.js +143 -0
  19. package/dist/child/proxy-repo-store.d.ts +27 -0
  20. package/dist/child/proxy-repo-store.js +200 -0
  21. package/dist/child/run-child.d.ts +320 -0
  22. package/dist/child/run-child.js +900 -0
  23. package/dist/child/self-discovery.d.ts +29 -0
  24. package/dist/child/self-discovery.js +57 -0
  25. package/dist/child/substrate-write-bridge.d.ts +72 -0
  26. package/dist/child/substrate-write-bridge.js +188 -0
  27. package/dist/child/supervisor-backed-transport.d.ts +10 -0
  28. package/dist/child/supervisor-backed-transport.js +113 -0
  29. package/dist/child/warm-agent-cache.d.ts +78 -0
  30. package/dist/child/warm-agent-cache.js +112 -0
  31. package/dist/drain-controller.d.ts +37 -0
  32. package/dist/drain-controller.js +46 -0
  33. package/dist/index.d.ts +10 -0
  34. package/dist/index.js +10 -0
  35. package/dist/ipc/control-channel.d.ts +336 -0
  36. package/dist/ipc/control-channel.js +532 -0
  37. package/dist/ipc/crypto.d.ts +46 -0
  38. package/dist/ipc/crypto.js +126 -0
  39. package/dist/ipc/envelope.d.ts +53 -0
  40. package/dist/ipc/envelope.js +88 -0
  41. package/dist/ipc/event-channel.d.ts +677 -0
  42. package/dist/ipc/event-channel.js +278 -0
  43. package/dist/ipc/index.d.ts +4 -0
  44. package/dist/ipc/index.js +143 -0
  45. package/dist/mail-bus/hub-transport-adapter.d.ts +30 -0
  46. package/dist/mail-bus/hub-transport-adapter.js +76 -0
  47. package/dist/mail-bus/index.d.ts +1 -0
  48. package/dist/mail-bus/index.js +1 -0
  49. package/dist/seams/index.d.ts +3 -0
  50. package/dist/seams/index.js +3 -0
  51. package/dist/seams/scheduler-adapter.d.ts +3 -0
  52. package/dist/seams/scheduler-adapter.js +24 -0
  53. package/dist/seams/scheduler.d.ts +94 -0
  54. package/dist/seams/scheduler.js +397 -0
  55. package/dist/seams/signal-channel.d.ts +74 -0
  56. package/dist/seams/signal-channel.js +304 -0
  57. package/dist/supervisor/cancel-signing.d.ts +68 -0
  58. package/dist/supervisor/cancel-signing.js +144 -0
  59. package/dist/supervisor/child-termination.d.ts +51 -0
  60. package/dist/supervisor/child-termination.js +76 -0
  61. package/dist/supervisor/credentials.d.ts +101 -0
  62. package/dist/supervisor/credentials.js +153 -0
  63. package/dist/supervisor/dispatch-attribution.d.ts +37 -0
  64. package/dist/supervisor/dispatch-attribution.js +114 -0
  65. package/dist/supervisor/drain-timeout.d.ts +127 -0
  66. package/dist/supervisor/drain-timeout.js +231 -0
  67. package/dist/supervisor/index.d.ts +7 -0
  68. package/dist/supervisor/index.js +6 -0
  69. package/dist/supervisor/recycle.d.ts +212 -0
  70. package/dist/supervisor/recycle.js +440 -0
  71. package/dist/supervisor/run-event-compaction.d.ts +34 -0
  72. package/dist/supervisor/run-event-compaction.js +115 -0
  73. package/dist/supervisor/spawn-env.d.ts +39 -0
  74. package/dist/supervisor/spawn-env.js +36 -0
  75. package/dist/supervisor/supervisor.d.ts +202 -0
  76. package/dist/supervisor/supervisor.js +2244 -0
  77. package/dist/supervisor/terminal-broadcaster.d.ts +45 -0
  78. package/dist/supervisor/terminal-broadcaster.js +184 -0
  79. package/dist/supervisor/types.d.ts +542 -0
  80. package/dist/supervisor/types.js +10 -0
  81. package/package.json +35 -0
@@ -0,0 +1,202 @@
1
+ import type { InferenceSource } from "@intx/types/runtime";
2
+ import type { CancelOrigin } from "@intx/workflow";
3
+ import { type EventPayload } from "../ipc/index.js";
4
+ import { type CredentialsSnapshot } from "./credentials.js";
5
+ import { type RecycleAttempt, type RecycleOrigin } from "./recycle.js";
6
+ import type { WorkflowSupervisorBindings } from "./types.js";
7
+ /**
8
+ * Default watchdog timeout for the supervisor's
9
+ * `synchronouslyDispatchTerminalWrite`. The handler holds the
10
+ * `substrate.write.response` back to the child until the dispatch
11
+ * loop's `markConsumed` settles for the matching terminal event; an
12
+ * unbounded wait would chain into a child / runtime / dispatch loop
13
+ * deadlock if `markConsumed` never armed (bug in the dispatch loop, a
14
+ * torn-down cohort, a stalled inbox primitive). 30s sits between the
15
+ * recycle path's `DEFAULT_KILL_TIMEOUT_MS` (5s, a hard process-level
16
+ * kill cap) and `DEFAULT_DRAIN_TIMEOUT_MS` (60s, the per-deployment
17
+ * drain budget) -- generous enough to absorb a slow legitimate
18
+ * markConsumed, tight enough to surface a real deadlock long before
19
+ * the drainTimeout would otherwise mask it.
20
+ */
21
+ export declare const DEFAULT_TERMINAL_WRITE_WATCHDOG_MS = 30000;
22
+ /**
23
+ * Public surface returned by `createWorkflowSupervisor`. Each method
24
+ * advances the supervisor through one lifecycle transition; the
25
+ * supervisor's internal state is encapsulated.
26
+ */
27
+ export interface WorkflowSupervisor {
28
+ /**
29
+ * Spawn the workflow-process child, complete the IPC handshake,
30
+ * assemble the credentialsSnapshot, register the deployment's mail
31
+ * address, and begin forwarding inbound mail. Resolves once the
32
+ * child's `ready` frame has been received and credentials have
33
+ * been pushed.
34
+ */
35
+ spawn(opts: SpawnOpts): Promise<SpawnResult>;
36
+ /**
37
+ * Sign and commit a CancelRequested event under the named origin.
38
+ * Used by the host directly for `supervisor-operator` and `hub-
39
+ * admin` origins; the `self` origin is invoked indirectly by the
40
+ * supervisor when the child requests cancellation over the
41
+ * control IPC.
42
+ */
43
+ requestCancel(opts: CancelRequestOpts): Promise<CancelCommitInfo>;
44
+ /**
45
+ * Tear the deployment down: unregister the mail address, kill the
46
+ * child, dispose subscriptions, await child exit. Idempotent.
47
+ */
48
+ shutdown(): Promise<void>;
49
+ /**
50
+ * Send the supervisor's `drain` control mail to the child and arm
51
+ * a drainTimeout accumulator against every in-flight run. The
52
+ * child's `DrainController` flips its signal on receipt and the
53
+ * runtime body picks the change up at the four observation
54
+ * points; cancel-mode steps abort locally, wait-mode steps continue
55
+ * running. On accumulator expiry, the supervisor commits a signed
56
+ * `CancelRequested{origin: "supervisor-drain"}` per run via the
57
+ * accumulator's existing path. The promise resolves once the
58
+ * `drain` mail has been forwarded; the accumulators tick in the
59
+ * background and stop on shutdown or terminal-phase reach. The
60
+ * recycle path reuses this primitive verbatim for its drain step.
61
+ */
62
+ drain(opts: DrainOpts): Promise<void>;
63
+ /**
64
+ * Recycle the child: drain -> kill -> respawn with a fresh
65
+ * channelId. Funnels every recycle origin (operator command,
66
+ * supervisor policy, child self-initiated) through the same
67
+ * `triggerRecycle` code path.
68
+ */
69
+ recycle(opts: RecycleOpts): Promise<RecycleAttempt>;
70
+ /**
71
+ * Deliver a workflow-run signal to the child by sending a
72
+ * `signal.deliver` control IPC frame. The child commits the
73
+ * resulting `SignalReceived` event through its own substrate, which
74
+ * keeps the workflow-run repo's single-writer invariant intact -- the
75
+ * child is the only writer of `runs/<runId>/events/` on the sidecar
76
+ * side, and the pack-push pipeline propagates the commit to the hub
77
+ * without racing against a concurrent host-side write.
78
+ *
79
+ * Throws when the supervisor is not in a phase where it can address
80
+ * the child (idle / stopping / stopped); the caller is responsible
81
+ * for serializing delivery against `spawn` completion.
82
+ */
83
+ deliverSignal(opts: DeliverSignalOpts): Promise<void>;
84
+ /**
85
+ * Push a rotated inference-source list to the child's warm single-step
86
+ * agent. Mirrors `deliverSignal`: the supervisor is the single producer
87
+ * of `sources-updated` control frames, and delivery is phase-guarded to
88
+ * starting/running so a frame is never written into a recycling child's
89
+ * closing pipe. Throws otherwise.
90
+ */
91
+ deliverSources(opts: DeliverSourcesOpts): Promise<void>;
92
+ /**
93
+ * Current snapshot of the credentials pushed to the child. Surfaced
94
+ * so the host can audit the per-step contentHash without
95
+ * round-tripping the substrate. Returns `null` before spawn.
96
+ */
97
+ getCredentialsSnapshot(): CredentialsSnapshot | null;
98
+ }
99
+ export type SpawnOpts = {
100
+ /** Step ids in this deployment's `stepOrder` for credentials assembly. */
101
+ stepOrder: readonly string[];
102
+ /** Content hash of the deployment's workflow definition. */
103
+ definitionHash: string;
104
+ /**
105
+ * Whether the spawned child warm-keeps its agent across messages
106
+ * (design §3b). The host sets this true only for the single-step
107
+ * long-lived deployment the deploy projection marked a warm candidate;
108
+ * the supervisor threads it into the child's spawn env as `WARM_KEEP`
109
+ * so the child's run-loop builds a warm-agent cache. Carried
110
+ * explicitly so the warm-keep decision is deterministic and survives
111
+ * recycle (the recycle path re-spawns with the same env).
112
+ */
113
+ warmKeep: boolean;
114
+ /**
115
+ * Callback the supervisor invokes for each verified InferenceEvent
116
+ * the child publishes. Mirrors the existing `agent.event` event
117
+ * sink the host exposes; the supervisor is the in-host translator.
118
+ */
119
+ onInferenceEvent: (event: EventPayload) => void;
120
+ };
121
+ export type SpawnResult = {
122
+ /** Child process pid. */
123
+ pid: number;
124
+ /** IPC channelId minted for this spawn. */
125
+ channelId: string;
126
+ /** Initial credentials snapshot pushed to the child. */
127
+ credentialsSnapshot: CredentialsSnapshot;
128
+ };
129
+ export type CancelRequestOpts = {
130
+ runId: string;
131
+ origin: CancelOrigin;
132
+ reason: string;
133
+ /** ISO-8601 commit timestamp. */
134
+ at: string;
135
+ };
136
+ export type CancelCommitInfo = {
137
+ commitSha: string;
138
+ seq: number;
139
+ };
140
+ export type DrainOpts = {
141
+ /**
142
+ * Wire `deadlineMs` carried on the `drain` control frame so the
143
+ * child can echo the policy in its logs. The supervisor-side
144
+ * `drainTimeout` accumulator is driven by
145
+ * `WorkflowSupervisorBindings.drainTimeoutMs`, not by this value:
146
+ * the timeout policy is a per-deployment operator setting baked
147
+ * into the supervisor's bindings, not a per-call argument.
148
+ */
149
+ deadlineMs: number;
150
+ };
151
+ export type DeliverSignalOpts = {
152
+ /** Run the signal targets. The child rejects a delivery whose runId is unknown. */
153
+ runId: string;
154
+ /** Signal name the run's `awaitSignal` step matches against. */
155
+ signalName: string;
156
+ /**
157
+ * Producer-supplied dedup id. The workflow-run state machine
158
+ * rejects duplicate deliveries via `observedSignalIds`; callers
159
+ * mint a fresh value per call.
160
+ */
161
+ signalId: string;
162
+ /** Opaque signal payload the awaiter resolves with. */
163
+ payload: unknown;
164
+ };
165
+ export type DeliverSourcesOpts = {
166
+ /**
167
+ * The rotated ordered inference-source failover chain; element 0 is the
168
+ * active source. The wire boundary enforces a non-empty list with unique
169
+ * ids whose head is the default.
170
+ */
171
+ sources: InferenceSource[];
172
+ /** The default source id; the wire boundary requires it to equal `sources[0].id`. */
173
+ defaultSource: string;
174
+ };
175
+ export type RecycleOpts = {
176
+ reason: string;
177
+ /**
178
+ * Origin of the recycle request. Defaults to `"operator"` when the
179
+ * supervisor's caller-facing API is invoked directly; the policy
180
+ * timer wires `"policy"` and the child-side `recycle.request`
181
+ * upstream frame wires `"self"`.
182
+ */
183
+ origin?: RecycleOrigin;
184
+ };
185
+ /**
186
+ * Raised when a `pendingMerges` entry or a
187
+ * `markConsumedCompletionWaiters` waiter is rejected because the
188
+ * cohort it was registered against has been aborted (cohort transition
189
+ * during a recycle, or a supervisor shutdown). Callers awaiting the
190
+ * resolved value receive an instance of this error so the failure mode
191
+ * is recognisable from a generic substrate-merge or markConsumed
192
+ * failure.
193
+ */
194
+ export declare class MergeAbortedError extends Error {
195
+ constructor(reason: string);
196
+ }
197
+ /**
198
+ * Construct a per-deployment supervisor. All host-specific
199
+ * dependencies are pulled in via `bindings`; nothing in the
200
+ * supervisor reaches into `process.env` or a singleton.
201
+ */
202
+ export declare function createWorkflowSupervisor(bindings: WorkflowSupervisorBindings): WorkflowSupervisor;