@kindgi/runtime 0.0.0-bootstrap.0 → 0.1.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 (58) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +65 -1
  3. package/dist/bindings.d.ts +186 -0
  4. package/dist/bindings.d.ts.map +1 -0
  5. package/dist/bindings.js +4 -0
  6. package/dist/bindings.js.map +1 -0
  7. package/dist/derivation.d.ts +123 -0
  8. package/dist/derivation.d.ts.map +1 -0
  9. package/dist/derivation.js +249 -0
  10. package/dist/derivation.js.map +1 -0
  11. package/dist/errors.d.ts +78 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +4 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/event-bus.d.ts +41 -0
  16. package/dist/event-bus.d.ts.map +1 -0
  17. package/dist/event-bus.js +13 -0
  18. package/dist/event-bus.js.map +1 -0
  19. package/dist/index.d.ts +11 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +13 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/inputs.d.ts +160 -0
  24. package/dist/inputs.d.ts.map +1 -0
  25. package/dist/inputs.js +4 -0
  26. package/dist/inputs.js.map +1 -0
  27. package/dist/runs.d.ts +73 -0
  28. package/dist/runs.d.ts.map +1 -0
  29. package/dist/runs.js +4 -0
  30. package/dist/runs.js.map +1 -0
  31. package/dist/schedulers/registry.d.ts +142 -0
  32. package/dist/schedulers/registry.d.ts.map +1 -0
  33. package/dist/schedulers/registry.js +4 -0
  34. package/dist/schedulers/registry.js.map +1 -0
  35. package/dist/schedulers/types.d.ts +99 -0
  36. package/dist/schedulers/types.d.ts.map +1 -0
  37. package/dist/schedulers/types.js +4 -0
  38. package/dist/schedulers/types.js.map +1 -0
  39. package/dist/types.d.ts +317 -0
  40. package/dist/types.d.ts.map +1 -0
  41. package/dist/types.js +6 -0
  42. package/dist/types.js.map +1 -0
  43. package/dist/versioning.d.ts +59 -0
  44. package/dist/versioning.d.ts.map +1 -0
  45. package/dist/versioning.js +89 -0
  46. package/dist/versioning.js.map +1 -0
  47. package/package.json +50 -4
  48. package/src/bindings.ts +244 -0
  49. package/src/derivation.ts +354 -0
  50. package/src/errors.ts +92 -0
  51. package/src/event-bus.ts +51 -0
  52. package/src/index.ts +13 -0
  53. package/src/inputs.ts +169 -0
  54. package/src/runs.ts +84 -0
  55. package/src/schedulers/registry.ts +197 -0
  56. package/src/schedulers/types.ts +112 -0
  57. package/src/types.ts +378 -0
  58. package/src/versioning.ts +110 -0
@@ -0,0 +1,317 @@
1
+ import type { LoopContext } from '@kindgi/handler';
2
+ import type { NodeId, ProjectId, RunId, TenantId, Timestamp } from '@kindgi/types';
3
+ /** Terminal states are `completed`, `failed`, `cancelled`. */
4
+ export type RunStatus = 'pending' | 'running' | 'suspended' | 'completed' | 'failed' | 'cancelled';
5
+ export interface RunResult<TOutput = unknown> {
6
+ readonly runId: RunId;
7
+ readonly status: RunStatus;
8
+ /**
9
+ * For completed runs: the flow's declared output (`Flow.output`) when the
10
+ * flow has one; otherwise the output of the node whose edge reached
11
+ * `$end`. When multiple `$end`-terminating edges fire, one is picked
12
+ * deterministically (lowest edge id in traversal order).
13
+ */
14
+ readonly output?: TOutput;
15
+ readonly failureMessage?: string;
16
+ /** Free-form projectId echoed back if the run was bound to one. */
17
+ readonly projectId?: ProjectId;
18
+ readonly tenantId: TenantId;
19
+ }
20
+ /** Kernel journal entry kinds. */
21
+ export type JournalKind = 'run.started' | 'step.started' | 'step.completed' | 'step.failed' | 'step.retry-scheduled' | 'step.concurrency-deferred' | 'edge.evaluated' | 'iteration.started' | 'iteration.completed' | 'fanout.dispatched' | 'fanout.branch-completed' | 'fanout.branch-failed' | 'fanout.converged' | 'fanout.cancelled-siblings' | 'subgraph.dispatched' | 'subgraph.completed' | 'subgraph.failed' | 'subgraph.cancelled' | 'run.completed' | 'run.failed' | 'run.cancelled' | 'wait.suspended' | 'wait.resumed' | 'wait.cancelled' | 'clock.read';
22
+ /**
23
+ * Journal payload for `step.retry-scheduled`. Emitted when a node handler
24
+ * fails but the destination's sole incoming edge carries a `retry` policy
25
+ * with attempts remaining. The executor waits `nextDelayMs` (subject to the
26
+ * backoff shape) then re-dispatches the node.
27
+ *
28
+ * `attempt` is 1-based: `1` means the first retry (following the initial
29
+ * failure), `2` the second, etc. The number of `step.retry-scheduled`
30
+ * entries for a given node is the attempt count at derivation time.
31
+ */
32
+ export interface StepRetryScheduledPayload {
33
+ readonly nodeId: NodeId;
34
+ readonly attempt: number;
35
+ readonly nextDelayMs: number;
36
+ readonly previousError: string;
37
+ }
38
+ /**
39
+ * Journal payload for `step.concurrency-deferred`. Emitted when the
40
+ * dispatcher attempts to acquire a `policy.concurrencyKey` lease for a
41
+ * ready node and the lease is already held. The node stays in the ready
42
+ * set (from the scheduler's POV) but is deferred for the current tick;
43
+ * on the next tick, after the current holder releases, one waiter
44
+ * acquires and dispatches.
45
+ *
46
+ * `holderRunId` + `holderNodeId` attribute the current holder so an
47
+ * operator can debug "why is my node stuck?" without looking up other runs.
48
+ * `holderRunId` may equal the deferred node's run (self-contention) or a
49
+ * different run in the same tenant.
50
+ *
51
+ * Multiple `step.concurrency-deferred` entries for the same node are
52
+ * expected under long-held leases — derivation records only that the
53
+ * node is in the deferred bucket, not the count.
54
+ */
55
+ export interface StepConcurrencyDeferredPayload {
56
+ readonly nodeId: NodeId;
57
+ readonly concurrencyKey: string;
58
+ readonly holderRunId: RunId;
59
+ readonly holderNodeId: NodeId;
60
+ }
61
+ /**
62
+ * Journal payload doc shape for `iteration.started`.
63
+ *
64
+ * `bodyExecuted` is `false` only when a `while` loop with
65
+ * `evaluationTiming: 'before'` short-circuits its exit check before the
66
+ * body runs — in that case `exitConditionResult` is populated on
67
+ * `iteration.started` (and `iteration.completed` isn't emitted for the
68
+ * skipped iteration).
69
+ */
70
+ export interface IterationStartedPayload {
71
+ readonly iteration: number;
72
+ readonly bodyExecuted: boolean;
73
+ readonly exitConditionResult?: boolean | undefined;
74
+ readonly loopContext?: LoopContext | undefined;
75
+ }
76
+ /**
77
+ * Journal payload doc shape for `iteration.completed`.
78
+ *
79
+ * `outputSchemaValid` records whether the iteration's `$loop-end` output
80
+ * validated against the loop's `outputSchema`. On failure, `stopReason`
81
+ * is `'output-schema-violation'` and `schemaErrors` is populated.
82
+ *
83
+ * For `while` loops with `evaluationTiming: 'after'`, `exitConditionResult`
84
+ * is populated. For `while+before`, the check happens on the NEXT
85
+ * iteration's `iteration.started` and is absent here. For `foreach`, no
86
+ * exit condition — absent.
87
+ *
88
+ * `stopReason` is only populated on the FINAL iteration (the one that
89
+ * caused the loop to exit). Intermediate iterations have it as undefined.
90
+ */
91
+ export interface IterationCompletedPayload {
92
+ readonly iteration: number;
93
+ readonly output: unknown;
94
+ readonly outputSchemaValid: boolean;
95
+ readonly schemaErrors?: readonly unknown[] | undefined;
96
+ readonly exitConditionResult?: boolean | undefined;
97
+ readonly stopReason?: 'exit-condition' | 'max-iterations' | 'array-exhausted' | 'output-schema-violation' | 'body-failure' | 'cancelled' | 'iterate-over-not-array' | undefined;
98
+ readonly loopContext?: LoopContext | undefined;
99
+ }
100
+ /**
101
+ * Journal payload for `fanout.dispatched`. Emitted once per branch, before
102
+ * the branch handler is invoked. `input` is the same value every branch of
103
+ * the fanout receives (the fanout node's own resolved input).
104
+ */
105
+ export interface FanoutDispatchedPayload {
106
+ readonly fanoutNodeId: NodeId;
107
+ readonly branchId: string;
108
+ readonly handler: string;
109
+ readonly input: unknown;
110
+ }
111
+ /**
112
+ * Journal payload for `fanout.branch-completed`. Emitted when a branch's
113
+ * handler returns AND the resulting output validates against the branch's
114
+ * declared `outputSchema`.
115
+ */
116
+ export interface FanoutBranchCompletedPayload {
117
+ readonly fanoutNodeId: NodeId;
118
+ readonly branchId: string;
119
+ readonly output: unknown;
120
+ }
121
+ /**
122
+ * Journal payload for `fanout.branch-failed`. Emitted when a branch fails.
123
+ * `reason` narrows the failure attribution so consumers do not have to
124
+ * match on the message. `schemaErrors` is populated when
125
+ * `reason === 'output-schema-violation'`.
126
+ */
127
+ export interface FanoutBranchFailedPayload {
128
+ readonly fanoutNodeId: NodeId;
129
+ readonly branchId: string;
130
+ readonly message: string;
131
+ readonly reason: 'handler-throw' | 'output-schema-violation' | 'cancelled';
132
+ readonly schemaErrors?: readonly unknown[];
133
+ }
134
+ /**
135
+ * Journal payload for `fanout.converged`. Emitted once, after the fanout
136
+ * finalizes on a successful convergence. Carries the fan-in-shaped output
137
+ * that will be handed to downstream consumers via `nodeOutputs`.
138
+ */
139
+ export interface FanoutConvergedPayload {
140
+ readonly fanoutNodeId: NodeId;
141
+ readonly convergence: 'all-succeed' | 'any-succeed' | 'settle-all';
142
+ readonly output: unknown;
143
+ }
144
+ /**
145
+ * Journal payload for `fanout.cancelled-siblings`. Emitted once, when the
146
+ * convergence mode short-circuits (all-succeed on first failure OR
147
+ * any-succeed on first success) and in-flight sibling branches are
148
+ * cancelled. `reason` records which convergence trigger fired;
149
+ * `cancelledBranchIds` enumerates every branch that received the abort
150
+ * signal (whether or not it had already settled — the journal captures
151
+ * intent).
152
+ */
153
+ export interface FanoutCancelledSiblingsPayload {
154
+ readonly fanoutNodeId: NodeId;
155
+ readonly cancelledBranchIds: readonly string[];
156
+ readonly reason: 'first-failure' | 'first-success';
157
+ }
158
+ /**
159
+ * Fan-in shape emitted by a fanout node whose convergence mode is
160
+ * `'all-succeed'`. Object keyed by every branchId, mapping to that
161
+ * branch's validated output.
162
+ */
163
+ export interface FanoutAllSucceedOutput {
164
+ readonly [branchId: string]: unknown;
165
+ }
166
+ /**
167
+ * Fan-in shape emitted by a fanout node whose convergence mode is
168
+ * `'any-succeed'`. Records the identity of the winning branch and its
169
+ * validated output. In-flight siblings were cancelled and do not appear.
170
+ */
171
+ export interface FanoutAnySucceedOutput {
172
+ readonly winnerBranchId: string;
173
+ readonly output: unknown;
174
+ }
175
+ /**
176
+ * Per-branch outcome inside a `'settle-all'` fan-in output. `status` is
177
+ * `'succeeded'` when the branch handler returned a schema-valid output
178
+ * (present in `output`), `'failed'` when the branch failed (handler
179
+ * threw OR output schema violation, message in `error`).
180
+ */
181
+ export interface FanoutSettleAllBranchOutcome {
182
+ readonly status: 'succeeded' | 'failed';
183
+ readonly output?: unknown;
184
+ readonly error?: string;
185
+ }
186
+ /**
187
+ * Fan-in shape emitted by a fanout node whose convergence mode is
188
+ * `'settle-all'`. Object keyed by every branchId, mapping to that
189
+ * branch's terminal outcome.
190
+ */
191
+ export interface FanoutSettleAllOutput {
192
+ readonly [branchId: string]: FanoutSettleAllBranchOutcome;
193
+ }
194
+ /**
195
+ * Journal payload for `subgraph.dispatched`. Emitted before the child
196
+ * kernel run is started, so restarts observe consistent parent-journal
197
+ * state. Carries the child `runId` so replay can resolve back to the
198
+ * exact sub-run (rather than re-dispatching a fresh one).
199
+ */
200
+ export interface SubflowDispatchedPayload {
201
+ readonly subgraphNodeId: NodeId;
202
+ readonly subRunId: RunId;
203
+ readonly flowRef: {
204
+ readonly flowId: string;
205
+ readonly version: string;
206
+ };
207
+ readonly subInput: unknown;
208
+ readonly depth: number;
209
+ }
210
+ /**
211
+ * Journal payload for `subgraph.completed`. Emitted when the child kernel
212
+ * run reaches `status: 'completed'` AND its terminal output validates
213
+ * against the parent's declared `outputSchema`. `validatedOutput` is the
214
+ * schema-valid value; the parent node's own `step.completed` follows,
215
+ * with an output shape decided by the parent's `convergence` mode.
216
+ */
217
+ export interface SubflowCompletedPayload {
218
+ readonly subgraphNodeId: NodeId;
219
+ readonly subRunId: RunId;
220
+ readonly output: unknown;
221
+ }
222
+ /**
223
+ * Journal payload for `subgraph.failed`. Emitted when the child run
224
+ * failed OR its terminal output failed schema validation. Attribution:
225
+ * - `child-failed` → child kernel run terminated with `failed` status.
226
+ * - `output-schema-violation` → child completed but its output did not
227
+ * match the parent's declared `outputSchema`.
228
+ * - `subgraph-flow-not-found` → resolver returned null at dispatch.
229
+ * - `subgraph-depth-exceeded` → parent's `RunOptions.maxSubflowDepth`
230
+ * was hit at dispatch.
231
+ * - `subgraph-cross-tenant` → attempted lookup of a flow registered
232
+ * under a different tenant (reserved — cannot happen with the current
233
+ * resolver contract but journaled defensively).
234
+ * - `resolver-missing` → the run was started without a `flowResolver`
235
+ * dependency wired in, so the subgraph node cannot dispatch.
236
+ */
237
+ export interface SubflowFailedPayload {
238
+ readonly subgraphNodeId: NodeId;
239
+ readonly subRunId?: RunId;
240
+ readonly flowRef?: {
241
+ readonly flowId: string;
242
+ readonly version: string;
243
+ };
244
+ readonly reason: 'child-failed' | 'output-schema-violation' | 'subgraph-flow-not-found' | 'subgraph-depth-exceeded' | 'subgraph-cross-tenant' | 'resolver-missing';
245
+ readonly message: string;
246
+ readonly schemaErrors?: readonly unknown[];
247
+ }
248
+ /**
249
+ * Journal payload for `subgraph.cancelled`. Emitted when the parent run is
250
+ * being torn down (external `cancelRun`) OR when a sibling handler failed
251
+ * and the composed abort signal cascades to the child. Under `settle-all`
252
+ * convergence, the parent step still transitions to `step.completed` with
253
+ * an `error` envelope; under `success-only`, the parent step transitions
254
+ * to `step.failed`.
255
+ */
256
+ export interface SubflowCancelledPayload {
257
+ readonly subgraphNodeId: NodeId;
258
+ readonly subRunId: RunId;
259
+ readonly stopReason: 'cancelled';
260
+ }
261
+ /**
262
+ * Fan-in shape emitted by a `subgraph` node whose convergence mode is
263
+ * `'success-only'`. When the child run succeeded and its output
264
+ * validated, the parent node's output IS the validated child output.
265
+ * No wrapping envelope. When the child fails, the parent step
266
+ * transitions to `step.failed` (no output written).
267
+ */
268
+ export type SubflowSuccessOnlyOutput = unknown;
269
+ /**
270
+ * Fan-in shape emitted by a `subgraph` node whose convergence mode is
271
+ * `'settle-all'`. Always a settled envelope: on success the `output`
272
+ * carries the schema-valid child output; on failure the `error` names
273
+ * the attribution.
274
+ */
275
+ export interface SubflowSettleAllOutput {
276
+ readonly status: 'succeeded' | 'failed';
277
+ readonly output?: unknown;
278
+ readonly error?: string;
279
+ }
280
+ export interface JournalEntry {
281
+ readonly sequence: number;
282
+ readonly kind: JournalKind;
283
+ readonly nodeId?: NodeId;
284
+ readonly payload?: unknown;
285
+ readonly timestamp: Timestamp;
286
+ }
287
+ /** Kernel run-configuration knobs. */
288
+ export interface RunOptions {
289
+ /**
290
+ * Maximum number of node handlers dispatched concurrently in a single
291
+ * tick. Prevents accidental self-DoS on downstream systems from wide
292
+ * fan-outs. Default: 8.
293
+ */
294
+ readonly maxParallelism?: number;
295
+ /**
296
+ * When `true`, the run executes in dry-run mode: `NodeContext.dryRun`
297
+ * is exposed to every handler so they can self-mock side-effecting
298
+ * calls (tool invocation, model calls, DB writes). The run record is
299
+ * marked `dryRun: true` (`KernelRunRecord.dryRun`); the journal shape is
300
+ * unchanged. Consumers (the client's `runs.dryRun`, cost estimators,
301
+ * plan viewers) filter on that flag. Default: `false`.
302
+ */
303
+ readonly dryRun?: boolean;
304
+ /**
305
+ * Maximum sub-flow invocation depth. A parent run at depth 0 that
306
+ * dispatches a `subgraph` node produces a child at depth 1; the child
307
+ * dispatching its own subgraph node produces a grandchild at depth 2;
308
+ * and so on. Exceeding this cap fails the subgraph node at dispatch
309
+ * with `subgraph-depth-exceeded`. Default: 10. Configured on the
310
+ * outermost `RunBinding.runGraph` call — children inherit the same cap.
311
+ */
312
+ readonly maxSubflowDepth?: number;
313
+ }
314
+ export declare const DEFAULT_MAX_PARALLELISM = 8;
315
+ /** Default cap on nested sub-flow depth. See `RunOptions.maxSubflowDepth`. */
316
+ export declare const DEFAULT_MAX_SUBGRAPH_DEPTH = 10;
317
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CA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AE,MAAM,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC;CAClC;AAED;;;;;;GAMG;AACH,MAAM,MAAM,wBAAwB,GAAG,OAAO,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,QAAQ,CAAC;IACxC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;CAC/B;AAED,sCAAsC;AACtC,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC;;;;;;;OAOG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;;OAOG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACnC;AAED,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC,8EAA8E;AAC9E,eAAO,MAAM,0BAA0B,KAAK,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ export const DEFAULT_MAX_PARALLELISM = 8;
4
+ /** Default cap on nested sub-flow depth. See `RunOptions.maxSubflowDepth`. */
5
+ export const DEFAULT_MAX_SUBGRAPH_DEPTH = 10;
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAqXjC,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAEzC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAE,CAAC"}
@@ -0,0 +1,59 @@
1
+ import type { Result } from '@kindgi/types';
2
+ /**
3
+ * Payload versioning for the documents the runtime stores (journal
4
+ * payloads, run input / output, …).
5
+ *
6
+ * Every stored payload is a nested envelope `{ v: 1, doc: <content> }`.
7
+ * Wrapping under a dedicated `doc` key means the envelope's version
8
+ * marker cannot collide with any user field named `version`,
9
+ * `schemaVersion`, etc. Readers switch on `v` and return the inner `doc`,
10
+ * so consumer code sees the same content shape as if no envelope
11
+ * existed.
12
+ *
13
+ * Newer versions than this reader knows about are a hard error — a
14
+ * writer/reader skew would silently drop v2 data otherwise. No implicit
15
+ * versioning: every payload must carry an explicit envelope.
16
+ */
17
+ export declare const CURRENT_KERNEL_PAYLOAD_VERSION = 1;
18
+ /** Discriminated error surfaced when a stored payload's version exceeds the reader's. */
19
+ export interface UnsupportedPayloadVersionError {
20
+ readonly code: 'unsupported-payload-version';
21
+ readonly message: string;
22
+ readonly version: number;
23
+ readonly currentVersion: number;
24
+ }
25
+ /** Emitted when a stored payload lacks the envelope entirely. */
26
+ export interface MalformedEnvelopeError {
27
+ readonly code: 'malformed-envelope';
28
+ readonly message: string;
29
+ }
30
+ export type EnvelopeError = UnsupportedPayloadVersionError | MalformedEnvelopeError;
31
+ /**
32
+ * Thrown by `*OrThrow` helpers when a stored payload can't be unwrapped.
33
+ * Catch at the operation boundary (e.g. `readJournal`) and surface
34
+ * as a KernelError.
35
+ */
36
+ export declare class EnvelopeThrown extends Error {
37
+ readonly error: EnvelopeError;
38
+ constructor(error: EnvelopeError);
39
+ }
40
+ /**
41
+ * Wrap any value in the current-version envelope. The stored payload is
42
+ * always `{ v: 1, doc: value }` regardless of whether `value` is an
43
+ * object, array, primitive, or null.
44
+ */
45
+ export declare function wrap<T>(value: T): {
46
+ readonly v: number;
47
+ readonly doc: T;
48
+ };
49
+ /**
50
+ * Unwrap a stored envelope and return the inner document. Handles:
51
+ * - null / undefined: returned as-is (nothing was stored).
52
+ * - `{ v: 1, doc: X }`: returns `X`.
53
+ * - `{ v: N, doc: X }` with any other numeric N:
54
+ * `unsupported-payload-version` error.
55
+ * - Anything else: `malformed-envelope` error.
56
+ */
57
+ export declare function unwrap<T = unknown>(raw: unknown): Result<T | null | undefined, EnvelopeError>;
58
+ export declare function unwrapOrThrow<T = unknown>(raw: unknown): T | null | undefined;
59
+ //# sourceMappingURL=versioning.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"versioning.d.ts","sourceRoot":"","sources":["../src/versioning.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;;;;;;;;;;;GAcG;AAEH,eAAO,MAAM,8BAA8B,IAAI,CAAC;AAEhD,yFAAyF;AACzF,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,IAAI,EAAE,6BAA6B,CAAC;IAC7C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAED,iEAAiE;AACjE,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,MAAM,aAAa,GAAG,8BAA8B,GAAG,sBAAsB,CAAC;AAEpF;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;gBAClB,KAAK,EAAE,aAAa;CAKjC;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG;IAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAA;CAAE,CAEzE;AAED;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,EAAE,aAAa,CAAC,CAiC7F;AAED,wBAAgB,aAAa,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,OAAO,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAI7E"}
@@ -0,0 +1,89 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ /**
4
+ * Payload versioning for the documents the runtime stores (journal
5
+ * payloads, run input / output, …).
6
+ *
7
+ * Every stored payload is a nested envelope `{ v: 1, doc: <content> }`.
8
+ * Wrapping under a dedicated `doc` key means the envelope's version
9
+ * marker cannot collide with any user field named `version`,
10
+ * `schemaVersion`, etc. Readers switch on `v` and return the inner `doc`,
11
+ * so consumer code sees the same content shape as if no envelope
12
+ * existed.
13
+ *
14
+ * Newer versions than this reader knows about are a hard error — a
15
+ * writer/reader skew would silently drop v2 data otherwise. No implicit
16
+ * versioning: every payload must carry an explicit envelope.
17
+ */
18
+ export const CURRENT_KERNEL_PAYLOAD_VERSION = 1;
19
+ /**
20
+ * Thrown by `*OrThrow` helpers when a stored payload can't be unwrapped.
21
+ * Catch at the operation boundary (e.g. `readJournal`) and surface
22
+ * as a KernelError.
23
+ */
24
+ export class EnvelopeThrown extends Error {
25
+ error;
26
+ constructor(error) {
27
+ super(error.message);
28
+ this.error = error;
29
+ this.name = 'EnvelopeThrown';
30
+ }
31
+ }
32
+ /**
33
+ * Wrap any value in the current-version envelope. The stored payload is
34
+ * always `{ v: 1, doc: value }` regardless of whether `value` is an
35
+ * object, array, primitive, or null.
36
+ */
37
+ export function wrap(value) {
38
+ return { v: CURRENT_KERNEL_PAYLOAD_VERSION, doc: value };
39
+ }
40
+ /**
41
+ * Unwrap a stored envelope and return the inner document. Handles:
42
+ * - null / undefined: returned as-is (nothing was stored).
43
+ * - `{ v: 1, doc: X }`: returns `X`.
44
+ * - `{ v: N, doc: X }` with any other numeric N:
45
+ * `unsupported-payload-version` error.
46
+ * - Anything else: `malformed-envelope` error.
47
+ */
48
+ export function unwrap(raw) {
49
+ if (raw === null || raw === undefined)
50
+ return { kind: 'ok', value: raw };
51
+ if (typeof raw !== 'object' || Array.isArray(raw)) {
52
+ return {
53
+ kind: 'err',
54
+ error: {
55
+ code: 'malformed-envelope',
56
+ message: `Expected { v, doc } envelope, got ${typeof raw === 'object' ? 'array' : typeof raw}`,
57
+ },
58
+ };
59
+ }
60
+ const envelope = raw;
61
+ if (typeof envelope.v !== 'number' || !('doc' in envelope)) {
62
+ return {
63
+ kind: 'err',
64
+ error: {
65
+ code: 'malformed-envelope',
66
+ message: 'Payload is missing v or doc field',
67
+ },
68
+ };
69
+ }
70
+ if (envelope.v === CURRENT_KERNEL_PAYLOAD_VERSION) {
71
+ return { kind: 'ok', value: envelope.doc };
72
+ }
73
+ return {
74
+ kind: 'err',
75
+ error: {
76
+ code: 'unsupported-payload-version',
77
+ message: `Unsupported payload version ${envelope.v} (this reader handles version ${CURRENT_KERNEL_PAYLOAD_VERSION})`,
78
+ version: envelope.v,
79
+ currentVersion: CURRENT_KERNEL_PAYLOAD_VERSION,
80
+ },
81
+ };
82
+ }
83
+ export function unwrapOrThrow(raw) {
84
+ const r = unwrap(raw);
85
+ if (r.kind === 'err')
86
+ throw new EnvelopeThrown(r.error);
87
+ return r.value;
88
+ }
89
+ //# sourceMappingURL=versioning.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"versioning.js","sourceRoot":"","sources":["../src/versioning.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAIjC;;;;;;;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D,IAAI,QAAQ,CAAC,CAAC,KAAK,8BAA8B,EAAE,CAAC;QAClD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,GAAQ,EAAE,CAAC;IAClD,CAAC;IACD,OAAO;QACL,IAAI,EAAE,KAAK;QACX,KAAK,EAAE;YACL,IAAI,EAAE,6BAA6B;YACnC,OAAO,EAAE,+BAA+B,QAAQ,CAAC,CAAC,iCAAiC,8BAA8B,GAAG;YACpH,OAAO,EAAE,QAAQ,CAAC,CAAC;YACnB,cAAc,EAAE,8BAA8B;SAC/C;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,aAAa,CAAc,GAAY;IACrD,MAAM,CAAC,GAAG,MAAM,CAAI,GAAG,CAAC,CAAC;IACzB,IAAI,CAAC,CAAC,IAAI,KAAK,KAAK;QAAE,MAAM,IAAI,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACxD,OAAO,CAAC,CAAC,KAAK,CAAC;AACjB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,53 @@
1
1
  {
2
2
  "name": "@kindgi/runtime",
3
- "version": "0.0.0-bootstrap.0",
4
- "description": "Placeholder so a trusted publisher can be attached. Releases are published from https://github.com/kindgi/kindgi-sdk with provenance; use 0.1.0 or later.",
3
+ "version": "0.1.0",
4
+ "description": "Kindgi™ runtime wire-vocabulary + binding interfaces. Public shape covering: RunStatus / RunResult / RunOptions / JournalEntry / JournalKind and all fanout/subgraph/iteration/step payload types; all kernel error shapes (KernelError, RunNotFoundError, HandlerMissingError, WaitpointError, etc.); run inputs and records (RunFlowInput / ResumeRunInput / StartRunParams, FlowResolver, HandlerResolver, ParentRunRef, KernelRunRecord, ListRunsInput); trigger schemas (Cron/Event/Webhook records + inputs + errors, plus TriggerRegistryBinding + RunFlowBinding + TRIGGER_KINDS); versioning envelope + wrap/unwrap; event-bus channel + KernelEventBusBinding; and the binding interfaces (RunBinding, SchedulerBinding, WaitpointBinding, RunRetentionBinding, umbrella KernelBinding) that deployments plug into `createApp`. Types + pure derivation functions — no runtime state, no dependency on a runtime implementation. The Kindgi runtime implements the bindings.",
5
5
  "license": "Apache-2.0",
6
- "repository": { "type": "git", "url": "git+https://github.com/kindgi/kindgi-sdk.git" }
7
- }
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/kindgi/kindgi-sdk.git",
9
+ "directory": "packages/runtime"
10
+ },
11
+ "homepage": "https://github.com/kindgi/kindgi-sdk/tree/main/packages/runtime#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/kindgi/kindgi-sdk/issues"
14
+ },
15
+ "type": "module",
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "src",
27
+ "README.md"
28
+ ],
29
+ "dependencies": {
30
+ "@kindgi/authz": "0.1.0",
31
+ "@kindgi/flow": "0.1.0",
32
+ "@kindgi/handler": "0.1.0",
33
+ "@kindgi/types": "0.1.0"
34
+ },
35
+ "engines": {
36
+ "node": ">=22.0.0"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public",
40
+ "provenance": true
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^22.10.5",
44
+ "typescript": "^5.7.3",
45
+ "vitest": "^2.1.8"
46
+ },
47
+ "scripts": {
48
+ "build": "tsc -p tsconfig.build.json",
49
+ "typecheck": "tsc --noEmit",
50
+ "test": "vitest run --typecheck --typecheck.only --passWithNoTests",
51
+ "clean": "rm -rf dist *.tsbuildinfo"
52
+ }
53
+ }