@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,37 @@
1
+ import { type DrainController } from "@intx/workflow";
2
+ import type { DrainBehavior, WorkflowDefinition } from "@intx/workflow";
3
+ export interface WorkflowHostDrainController extends DrainController {
4
+ /**
5
+ * Flip the drain signal. Idempotent; a second call after the
6
+ * signal has already aborted is a no-op so the supervisor's
7
+ * control-loop can re-deliver `drain` without breaking the
8
+ * accumulator's ordering.
9
+ */
10
+ requestDrain(): void;
11
+ /**
12
+ * Whether the drain has been requested. Distinct from
13
+ * `signal.aborted` only across the brief window where the signal
14
+ * has been aborted but a downstream observer has not yet read it.
15
+ */
16
+ readonly drainRequested: boolean;
17
+ }
18
+ export interface CreateWorkflowHostDrainControllerOpts {
19
+ /**
20
+ * The workflow definition the child loaded at startup. The
21
+ * controller consults this for `behaviorFor` resolution. The
22
+ * definition is immutable across the run lifetime; a redeploy
23
+ * tears the workflow-process down and respawns it.
24
+ */
25
+ definition: WorkflowDefinition;
26
+ /**
27
+ * Optional per-id override resolver. When supplied, the controller
28
+ * consults this before falling back to `resolveDrainBehavior`. The
29
+ * supervisor uses this for map-iteration steps whose runtime id
30
+ * shape (`<mapId>[<index>]`) the workflow definition does not
31
+ * carry directly; `resolveDrainBehavior` already handles the
32
+ * common case, so the override is reserved for host-specific
33
+ * extensions that diverge from the workflow-level conventions.
34
+ */
35
+ behaviorOverride?: (stepId: string) => DrainBehavior | undefined;
36
+ }
37
+ export declare function createWorkflowHostDrainController(opts: CreateWorkflowHostDrainControllerOpts): WorkflowHostDrainController;
@@ -0,0 +1,46 @@
1
+ // Production `DrainController` implementation for the workflow-host
2
+ // child.
3
+ //
4
+ // The `@intx/workflow` runtime body observes drain at four sites
5
+ // (main loop entry, retry-between-attempts in runStep, waitForTimer,
6
+ // runAwaitSignal). Each observation consults `behaviorFor(stepId)`
7
+ // to decide whether to abort the step's local controller. This file
8
+ // supplies the production controller the workflow-process child wires
9
+ // against the runtime env.
10
+ //
11
+ // The controller owns three pieces of state:
12
+ // 1. An `AbortController` whose signal exposes drain status to the
13
+ // runtime body.
14
+ // 2. A reference to the live `WorkflowDefinition` the child loaded;
15
+ // `behaviorFor` consults the primitive at the requested stepId
16
+ // and returns its declared drainBehavior.
17
+ // 3. An `accumulatedCancelMs` counter the supervisor's drainTimeout
18
+ // accumulator reads. The runtime body increments it; the
19
+ // supervisor consults it without owning the writer.
20
+ //
21
+ // The supervisor calls `requestDrain()` when its control-loop receives
22
+ // the `drain` mail; the controller flips its signal and the runtime
23
+ // body's observation points pick up the change on their next tick.
24
+ import { resolveDrainBehavior } from "@intx/workflow";
25
+ export function createWorkflowHostDrainController(opts) {
26
+ const controller = new AbortController();
27
+ let requested = false;
28
+ return {
29
+ signal: controller.signal,
30
+ behaviorFor(stepId) {
31
+ const override = opts.behaviorOverride?.(stepId);
32
+ if (override !== undefined)
33
+ return override;
34
+ return resolveDrainBehavior(opts.definition, stepId);
35
+ },
36
+ requestDrain() {
37
+ if (requested)
38
+ return;
39
+ requested = true;
40
+ controller.abort();
41
+ },
42
+ get drainRequested() {
43
+ return requested;
44
+ },
45
+ };
46
+ }
@@ -0,0 +1,10 @@
1
+ export { createWorkflowRunRepoStore, type WorkflowRunRepoStoreOpts, } from "./adapters/repo-store.js";
2
+ export { createWorkflowRunBlobSubstrate, type WorkflowRunBlobSubstrateOpts, } from "./adapters/blob-substrate.js";
3
+ export { createWorkflowStepInvoker, type StepEnvBase, type WorkflowStepInvokerOpts, } from "./adapters/step-invoker.js";
4
+ export { createWorkflowSpawnChild, type ChildTerminalStatus, type RunChildWorkflow, type WorkflowSpawnChildOpts, } from "./adapters/spawn-child.js";
5
+ export { createWorkflowSupervisor, assembleCredentialsSnapshot, commitCancelRequested, createDrainTimeoutAccumulator, createRecyclePolicy, defaultStepRepoId, hashGrants, triggerRecycle, DEFAULT_DRAIN_TIMEOUT_MS, DEFAULT_KILL_TIMEOUT_MS, DEFAULT_POLICY_INTERVAL_MS, DEFAULT_TERMINAL_WRITE_WATCHDOG_MS, MAX_BUFFERED_MAIL, STEP_GRANTS_PATH, STEP_GRANTS_REF, SUPERVISOR_PRINCIPAL_KIND, type AssembleCredentialsSnapshotOpts, type CancelCommitInfo, type CancelRequestOpts, type CommitCancelRequestedOpts, type CommitCancelRequestedResult, type CredentialsSnapshot, type CredentialsSnapshotStep, type DeliverSignalOpts, type DeliverSourcesOpts, type DeriveMailAuditRef, type DeriveStepAddress, type DeriveStepRepoId, type DrainOpts, type DrainTimeoutAccumulator, type DrainTimeoutAccumulatorFactory, type DrainTimeoutOpts, type InboxPrimitives, type MailAuditRef, type MailBusBindings, type PrincipalSigner, type RecycleAttempt, type RecycleContext, type RecycleOpts, type RecycleOrigin, type RecyclePolicy, type RecyclePolicyBounds, type RecyclePolicyOpts, type SignedPayload, type SpawnOpts, type SpawnResult, type SubprocessHandle, type SubprocessSpawner, type TerminalEventSource, type TerminalRunEvent, type TriggerRecycleOpts, type DispatchTimingMark, type DispatchStructuralCounters, type DispatchSubstrateLeg, type WorkflowSupervisor, type WorkflowSupervisorBindings, type WorkflowSupervisorPrincipalKind, } from "./supervisor/index.js";
6
+ export { createWorkflowHostDrainController, type WorkflowHostDrainController, type CreateWorkflowHostDrainControllerOpts, } from "./drain-controller.js";
7
+ export { wrapHubTransportAsMailBus, type HubTransportMailBusAdapter, } from "./mail-bus/index.js";
8
+ export { ControlPayload, DEFAULT_EVENT_BUFFER_LIMIT, EventPayload, FrameEnvelope, IPC_CRYPTO, SourcesUpdatedData, MacedEnvelope, OutboundAttachmentPayload, OutboundMessagePayload, SignedEnvelope, createControlChannelSender, createEventChannelSender, decodeEnvelope, encodeEnvelope, generateChannelId, generateHmacKey, receiveControlChannel, receiveEventChannel, signEd25519, signHmac, verifyEd25519, verifyHmac, type ControlChannelReceiverOpts, type ControlChannelSender, type ControlChannelSenderOpts, type EventChannelReceiverOpts, type EventChannelSender, type EventChannelSenderOpts, type FrameReader, type FrameWriter, type NdjsonReader, type NdjsonWriter, } from "./ipc/index.js";
9
+ export { EVENT_CHANNEL_FD, createChildOutboundMailBridge, createChildSubstrateWriteBridge, createCredentialsBackedAuthorize, createProxyWorkflowRunRepoStore, createSupervisorBackedTransport, createWarmAgentCache, discoverInFlightRuns, parseSpawnTimeEnv, runWorkflowChild, runWorkflowChildFromProcessEnv, type ChildOutboundMailBridge, type ChildStepInvoker, type ChildSubstrateWriteBridge, type CreateChildOutboundMailBridgeOpts, type CreateChildSubstrateWriteBridgeOpts, type CreateProxyWorkflowRunRepoStoreOpts, type CredentialsSnapshotRef, type DiscoverRunsOpts, type DiscoveredRun, type DrainController, type GrantEvaluator, type RunWorkflowChildBindings, type RunWorkflowChildFromProcessEnvOpts, type RunWorkflowChildOpts, type RunWorkflowChildResult, type SourcesSnapshotRef, type SpawnTimeEnv, type SubstrateFactory, type SubstrateFactoryEnv, type SubstrateWriteRequest, type SubstrateWriteResponseSink, type WarmAgentCache, type WarmEventSinkRef, } from "./child/index.js";
10
+ export { adaptHostScheduler, createWorkflowHostScheduler, createWorkflowHostSignalChannel, SignalReceivedEnvelope, type SchedulerHandle, type SchedulerOpts, type SignalChannelHandle, type SignalChannelOpts, } from "./seams/index.js";
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ export { createWorkflowRunRepoStore, } from "./adapters/repo-store.js";
2
+ export { createWorkflowRunBlobSubstrate, } from "./adapters/blob-substrate.js";
3
+ export { createWorkflowStepInvoker, } from "./adapters/step-invoker.js";
4
+ export { createWorkflowSpawnChild, } from "./adapters/spawn-child.js";
5
+ export { createWorkflowSupervisor, assembleCredentialsSnapshot, commitCancelRequested, createDrainTimeoutAccumulator, createRecyclePolicy, defaultStepRepoId, hashGrants, triggerRecycle, DEFAULT_DRAIN_TIMEOUT_MS, DEFAULT_KILL_TIMEOUT_MS, DEFAULT_POLICY_INTERVAL_MS, DEFAULT_TERMINAL_WRITE_WATCHDOG_MS, MAX_BUFFERED_MAIL, STEP_GRANTS_PATH, STEP_GRANTS_REF, SUPERVISOR_PRINCIPAL_KIND, } from "./supervisor/index.js";
6
+ export { createWorkflowHostDrainController, } from "./drain-controller.js";
7
+ export { wrapHubTransportAsMailBus, } from "./mail-bus/index.js";
8
+ export { ControlPayload, DEFAULT_EVENT_BUFFER_LIMIT, EventPayload, FrameEnvelope, IPC_CRYPTO, SourcesUpdatedData, MacedEnvelope, OutboundAttachmentPayload, OutboundMessagePayload, SignedEnvelope, createControlChannelSender, createEventChannelSender, decodeEnvelope, encodeEnvelope, generateChannelId, generateHmacKey, receiveControlChannel, receiveEventChannel, signEd25519, signHmac, verifyEd25519, verifyHmac, } from "./ipc/index.js";
9
+ export { EVENT_CHANNEL_FD, createChildOutboundMailBridge, createChildSubstrateWriteBridge, createCredentialsBackedAuthorize, createProxyWorkflowRunRepoStore, createSupervisorBackedTransport, createWarmAgentCache, discoverInFlightRuns, parseSpawnTimeEnv, runWorkflowChild, runWorkflowChildFromProcessEnv, } from "./child/index.js";
10
+ export { adaptHostScheduler, createWorkflowHostScheduler, createWorkflowHostSignalChannel, SignalReceivedEnvelope, } from "./seams/index.js";
@@ -0,0 +1,336 @@
1
+ import { decodeEnvelope } from "./envelope.js";
2
+ /**
3
+ * Wire-shape of one per-step credentials entry the supervisor pushes
4
+ * inside a `grants-updated` frame. Mirrors `CredentialsSnapshotStep`
5
+ * in `supervisor/credentials.ts` -- duplicated here as an arktype
6
+ * validator so the control-channel module stays free of a
7
+ * compile-time import on the supervisor module (the IPC module sits
8
+ * underneath the supervisor and child modules in the dependency
9
+ * graph). The contentHash pins the per-step grants so the child can
10
+ * detect a stale push and ignore an out-of-order one.
11
+ */
12
+ export declare const CredentialsSnapshotStepPayload: import("arktype/internal/variants/object.ts").ObjectType<{
13
+ stepId: string;
14
+ address: string;
15
+ grants: unknown[];
16
+ contentHash: string;
17
+ }, {}>;
18
+ export declare const CredentialsSnapshotPayload: import("arktype/internal/variants/object.ts").ObjectType<{
19
+ steps: {
20
+ stepId: string;
21
+ address: string;
22
+ grants: unknown[];
23
+ contentHash: string;
24
+ }[];
25
+ }, {}>;
26
+ /**
27
+ * Wire shape of a `sources-updated` frame's `data`: the full ordered
28
+ * inference-source failover chain plus the default source id. Carried
29
+ * inline like the grants snapshot -- a single-producer, single-consumer
30
+ * supervisor->child push, so a substrate round-trip would only add
31
+ * latency. No per-source hash rides along; a source list is flat, with no
32
+ * per-item pin for a receiver to cross-check.
33
+ *
34
+ * The `narrow` pins two frame-structural invariants at this boundary so
35
+ * every consumer can trust them without re-checking: source ids are
36
+ * unique, and the first element is the default source. The head-is-default
37
+ * rule is what keeps the two rotation paths in agreement -- a warm agent's
38
+ * `setSources` activates the matched default index, while a cold rebuild
39
+ * pins element 0 -- so they pick the same active source only when the
40
+ * default is the head.
41
+ */
42
+ export declare const SourcesUpdatedData: import("arktype/internal/variants/object.ts").ObjectType<{
43
+ sources: {
44
+ id: string;
45
+ provider: string;
46
+ baseURL: string;
47
+ apiKey: string;
48
+ model: string;
49
+ defaults?: {
50
+ maxTokens?: number;
51
+ providerOptions?: Record<string, unknown>;
52
+ };
53
+ capabilities?: string[];
54
+ }[];
55
+ defaultSource: string;
56
+ }, {}>;
57
+ /**
58
+ * Wire projection of an attachment on an outbound mail message. The
59
+ * runtime `MessageAttachment.data` is raw bytes; the NDJSON control
60
+ * channel is text, so the bytes ride base64-encoded under `dataBase64`.
61
+ * The child encodes on send; the supervisor decodes before handing the
62
+ * `OutboundMessage` to the host transport.
63
+ */
64
+ export declare const OutboundAttachmentPayload: import("arktype/internal/variants/object.ts").ObjectType<{
65
+ name: string;
66
+ contentType: string;
67
+ dataBase64: string;
68
+ }, {}>;
69
+ /**
70
+ * Wire projection of `@intx/types/runtime`'s `OutboundMessage`. Mirrors
71
+ * that type field-for-field with two adjustments for the NDJSON wire:
72
+ * attachment bytes are base64 strings (see `OutboundAttachmentPayload`),
73
+ * and every optional field is spelled with the `"?"` suffix so an
74
+ * absent field round-trips as absent rather than `null`. The supervisor
75
+ * reconstructs the runtime `OutboundMessage` from this shape before
76
+ * invoking `MailBusBindings.sendOutbound`.
77
+ *
78
+ * Duplicated here as an arktype validator (rather than importing the
79
+ * TypeScript `OutboundMessage` type) so the IPC module validates the
80
+ * child-supplied payload at the wire boundary -- the child is a separate
81
+ * process and its frames are untrusted input the receiver must parse.
82
+ */
83
+ export declare const OutboundMessagePayload: import("arktype/internal/variants/object.ts").ObjectType<{
84
+ to: string | string[];
85
+ type: "conversation.message" | "conversation.join" | "conversation.leave" | "offering.request" | "offering.response" | "offering.error" | "offering.discover" | "offering.catalog" | "payment.required" | "payment.receipt" | "payment.verified" | "approval.request" | "approval.granted" | "approval.denied" | "system.health" | "system.register" | "system.deregister" | "system.credential.refresh";
86
+ cc?: string | string[];
87
+ subject?: string;
88
+ content?: string;
89
+ payload?: Record<string, unknown>;
90
+ summary?: string;
91
+ attachments?: {
92
+ name: string;
93
+ contentType: string;
94
+ dataBase64: string;
95
+ }[];
96
+ inReplyTo?: string;
97
+ correlationId?: string;
98
+ sessionId?: string;
99
+ tenantId?: string;
100
+ }, {}>;
101
+ export type OutboundMessagePayload = typeof OutboundMessagePayload.infer;
102
+ /**
103
+ * Discriminated union of every control-channel payload kind. The
104
+ * `type` discriminator namespaces the control-plane vocabulary so a
105
+ * future addition (e.g. `connector-bind`) lands by extending this
106
+ * union and not by widening the envelope shape. Inference events
107
+ * NEVER appear here; they ride the event channel.
108
+ */
109
+ export declare const ControlPayload: import("arktype/internal/variants/object.ts").ObjectType<{
110
+ type: "trigger.fire";
111
+ data: {
112
+ runId: string;
113
+ messageId: string;
114
+ receivedAt: number;
115
+ };
116
+ } | {
117
+ type: "signal.deliver";
118
+ data: {
119
+ runId: string;
120
+ signalName: string;
121
+ signalId: string;
122
+ payload: unknown;
123
+ };
124
+ } | {
125
+ type: "drain";
126
+ data: {
127
+ deadlineMs: number;
128
+ };
129
+ } | {
130
+ type: "shutdown";
131
+ data: {
132
+ reason: string;
133
+ };
134
+ } | {
135
+ type: "grants-updated";
136
+ data: {
137
+ snapshot: {
138
+ steps: {
139
+ stepId: string;
140
+ address: string;
141
+ grants: unknown[];
142
+ contentHash: string;
143
+ }[];
144
+ };
145
+ stepHashes?: Record<string, string>;
146
+ };
147
+ } | {
148
+ type: "sources-updated";
149
+ data: {
150
+ sources: {
151
+ id: string;
152
+ provider: string;
153
+ baseURL: string;
154
+ apiKey: string;
155
+ model: string;
156
+ defaults?: {
157
+ maxTokens?: number;
158
+ providerOptions?: Record<string, unknown>;
159
+ };
160
+ capabilities?: string[];
161
+ }[];
162
+ defaultSource: string;
163
+ };
164
+ } | {
165
+ type: "ready";
166
+ data: {
167
+ childPid: number;
168
+ childPublicKey: string;
169
+ };
170
+ } | {
171
+ type: "recycle.request";
172
+ data: {
173
+ reason: string;
174
+ };
175
+ } | {
176
+ type: "substrate.write.request";
177
+ data: {
178
+ requestId: string;
179
+ repoId: {
180
+ kind: string;
181
+ id: string;
182
+ };
183
+ ref: string;
184
+ preservePrefix: string;
185
+ message: string;
186
+ };
187
+ } | {
188
+ type: "substrate.merge.request";
189
+ data: {
190
+ requestId: string;
191
+ existing: {
192
+ path: string;
193
+ contentBase64: string;
194
+ }[];
195
+ };
196
+ } | {
197
+ type: "substrate.merge.response";
198
+ data: {
199
+ requestId: string;
200
+ result: {
201
+ ok: true;
202
+ files: {
203
+ path: string;
204
+ contentBase64: string;
205
+ }[];
206
+ } | {
207
+ ok: false;
208
+ reason: string;
209
+ };
210
+ };
211
+ } | {
212
+ type: "substrate.write.response";
213
+ data: {
214
+ requestId: string;
215
+ result: {
216
+ ok: true;
217
+ commitSha: string;
218
+ } | {
219
+ ok: false;
220
+ reason: string;
221
+ };
222
+ };
223
+ } | {
224
+ type: "outbound.message";
225
+ data: {
226
+ requestId: string;
227
+ senderAddress: string;
228
+ message: {
229
+ to: string | string[];
230
+ type: "conversation.message" | "conversation.join" | "conversation.leave" | "offering.request" | "offering.response" | "offering.error" | "offering.discover" | "offering.catalog" | "payment.required" | "payment.receipt" | "payment.verified" | "approval.request" | "approval.granted" | "approval.denied" | "system.health" | "system.register" | "system.deregister" | "system.credential.refresh";
231
+ cc?: string | string[];
232
+ subject?: string;
233
+ content?: string;
234
+ payload?: Record<string, unknown>;
235
+ summary?: string;
236
+ attachments?: {
237
+ name: string;
238
+ contentType: string;
239
+ dataBase64: string;
240
+ }[];
241
+ inReplyTo?: string;
242
+ correlationId?: string;
243
+ sessionId?: string;
244
+ tenantId?: string;
245
+ };
246
+ mailbox?: string;
247
+ };
248
+ } | {
249
+ type: "outbound.result";
250
+ data: {
251
+ requestId: string;
252
+ result: {
253
+ ok: true;
254
+ messageId: string;
255
+ status: "delivered" | "queued";
256
+ } | {
257
+ ok: false;
258
+ reason: string;
259
+ };
260
+ };
261
+ } | {
262
+ type: "terminal.event";
263
+ data: {
264
+ runId: string;
265
+ seq: number;
266
+ kind: "RunCompleted" | "RunFailed" | "RunCancelled";
267
+ at: string;
268
+ error?: {
269
+ message: string;
270
+ };
271
+ };
272
+ }, {}>;
273
+ export type ControlPayload = typeof ControlPayload.infer;
274
+ export interface NdjsonWriter {
275
+ write(line: string): Promise<void> | void;
276
+ }
277
+ export interface NdjsonReader {
278
+ read(): AsyncIterableIterator<string>;
279
+ }
280
+ export interface ControlChannelSenderOpts {
281
+ privateKeySeed: Uint8Array;
282
+ channelId: string;
283
+ writer: NdjsonWriter;
284
+ }
285
+ export interface ControlChannelSender {
286
+ send(payload: ControlPayload): Promise<void>;
287
+ readonly seq: number;
288
+ }
289
+ /**
290
+ * Construct the supervisor-side control-channel sender. The
291
+ * supervisor's Ed25519 seed lives in closure. The matching public
292
+ * key flows to the child through spawn-time env -- never the seed.
293
+ */
294
+ export declare function createControlChannelSender(opts: ControlChannelSenderOpts): ControlChannelSender;
295
+ export interface ControlChannelReceiverOpts {
296
+ /**
297
+ * Public key used to verify every inbound frame. When `Uint8Array`
298
+ * the value is fixed at construction time (the child's downstream
299
+ * receiver uses the supervisor's pubkey from `HOST_PUBKEY`). When
300
+ * `{ bootstrapFromReady: true }` the receiver opens in
301
+ * bootstrap mode: the first frame must be `ready` and must carry
302
+ * a `childPublicKey` hex-encoded Ed25519 public key in its payload.
303
+ * The receiver extracts the key, verifies the first frame's
304
+ * signature against it, then continues verifying subsequent frames
305
+ * against the same key. The supervisor's upstream receiver opens
306
+ * in bootstrap mode so the child can publish its own public key
307
+ * over the wire without the supervisor ever holding the matching
308
+ * private half.
309
+ */
310
+ publicKey: Uint8Array | {
311
+ bootstrapFromReady: true;
312
+ };
313
+ channelId: string;
314
+ reader: NdjsonReader;
315
+ /**
316
+ * Invoked when any invariant is violated: signature failure,
317
+ * channelId mismatch, non-monotonic seq, malformed payload. The
318
+ * receiver's contract is to crash on any such violation. The
319
+ * caller wires this to a process-exit path; tests inject a
320
+ * recorder to assert on the failure mode.
321
+ */
322
+ onCrash: (reason: string) => void;
323
+ }
324
+ /**
325
+ * Construct the child-side control-channel receiver. Yields one
326
+ * verified, in-order `ControlPayload` per call. Any frame that
327
+ * fails verification, carries a non-current channelId, or arrives
328
+ * out of order calls `onCrash` and ends the iterator.
329
+ */
330
+ export declare function receiveControlChannel(opts: ControlChannelReceiverOpts): AsyncGenerator<ControlPayload, void, void>;
331
+ /**
332
+ * Re-export the envelope decoder for callers that need to inspect
333
+ * a control frame's envelope without going through the receiver
334
+ * iterator (testing harnesses that fuzz the wire format).
335
+ */
336
+ export { decodeEnvelope };