@nodetool-ai/kernel 0.7.0-rc.23 → 0.8.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.
- package/README.md +51 -0
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/actor.d.ts +387 -20
- package/dist/actor.d.ts.map +1 -1
- package/dist/actor.js +1658 -187
- package/dist/actor.js.map +1 -1
- package/dist/correlation-analysis.d.ts +104 -0
- package/dist/correlation-analysis.d.ts.map +1 -0
- package/dist/correlation-analysis.js +840 -0
- package/dist/correlation-analysis.js.map +1 -0
- package/dist/durable-inbox.d.ts +9 -0
- package/dist/durable-inbox.d.ts.map +1 -1
- package/dist/durable-inbox.js +55 -2
- package/dist/durable-inbox.js.map +1 -1
- package/dist/dynamic-slots.d.ts +73 -0
- package/dist/dynamic-slots.d.ts.map +1 -0
- package/dist/dynamic-slots.js +192 -0
- package/dist/dynamic-slots.js.map +1 -0
- package/dist/edge-ids.d.ts +11 -0
- package/dist/edge-ids.d.ts.map +1 -0
- package/dist/edge-ids.js +15 -0
- package/dist/edge-ids.js.map +1 -0
- package/dist/graph-utils.d.ts +12 -0
- package/dist/graph-utils.d.ts.map +1 -1
- package/dist/graph-utils.js +51 -16
- package/dist/graph-utils.js.map +1 -1
- package/dist/graph.d.ts +60 -9
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +313 -101
- package/dist/graph.js.map +1 -1
- package/dist/inbox.d.ts +158 -2
- package/dist/inbox.d.ts.map +1 -1
- package/dist/inbox.js +253 -11
- package/dist/inbox.js.map +1 -1
- package/dist/index.d.ts +14 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -7
- package/dist/index.js.map +1 -1
- package/dist/io.d.ts +103 -6
- package/dist/io.d.ts.map +1 -1
- package/dist/io.js +123 -12
- package/dist/io.js.map +1 -1
- package/dist/loop.d.ts +36 -0
- package/dist/loop.d.ts.map +1 -0
- package/dist/loop.js +166 -0
- package/dist/loop.js.map +1 -0
- package/dist/message-stream.d.ts +32 -0
- package/dist/message-stream.d.ts.map +1 -0
- package/dist/message-stream.js +64 -0
- package/dist/message-stream.js.map +1 -0
- package/dist/predicates.d.ts +8 -0
- package/dist/predicates.d.ts.map +1 -0
- package/dist/predicates.js +8 -0
- package/dist/predicates.js.map +1 -0
- package/dist/run-state.d.ts +65 -0
- package/dist/run-state.d.ts.map +1 -0
- package/dist/run-state.js +42 -0
- package/dist/run-state.js.map +1 -0
- package/dist/runner.d.ts +312 -15
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +1226 -157
- package/dist/runner.js.map +1 -1
- package/dist/substitute-validator.d.ts +44 -0
- package/dist/substitute-validator.d.ts.map +1 -0
- package/dist/substitute-validator.js +169 -0
- package/dist/substitute-validator.js.map +1 -0
- package/dist/supervisor.d.ts +148 -0
- package/dist/supervisor.d.ts.map +1 -0
- package/dist/supervisor.js +287 -0
- package/dist/supervisor.js.map +1 -0
- package/dist/trigger-wakeup.d.ts +74 -5
- package/dist/trigger-wakeup.d.ts.map +1 -1
- package/dist/trigger-wakeup.js +167 -45
- package/dist/trigger-wakeup.js.map +1 -1
- package/package.json +27 -9
- package/dist/channel.d.ts +0 -46
- package/dist/channel.d.ts.map +0 -1
- package/dist/channel.js +0 -191
- package/dist/channel.js.map +0 -1
- package/dist/suspendable.d.ts +0 -68
- package/dist/suspendable.d.ts.map +0 -1
- package/dist/suspendable.js +0 -108
- package/dist/suspendable.js.map +0 -1
- package/dist/trigger-manager.d.ts +0 -107
- package/dist/trigger-manager.d.ts.map +0 -1
- package/dist/trigger-manager.js +0 -214
- package/dist/trigger-manager.js.map +0 -1
- package/dist/trigger.d.ts +0 -57
- package/dist/trigger.d.ts.map +0 -1
- package/dist/trigger.js +0 -145
- package/dist/trigger.js.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# @nodetool-ai/kernel
|
|
2
|
+
|
|
3
|
+
The workflow kernel: the `Graph` model, `NodeInbox`, the actor runtime, and
|
|
4
|
+
`WorkflowRunner`. Executes a workflow graph via message-passing between node
|
|
5
|
+
actors. The graph is acyclic except for loops that close on a `Loop` node.
|
|
6
|
+
|
|
7
|
+
## Responsibilities
|
|
8
|
+
|
|
9
|
+
- `Graph` — structural model + validation (edge endpoints, types, source handles).
|
|
10
|
+
- `NodeActor` / `NodeInbox` — correlation-aware, buffered scheduling.
|
|
11
|
+
- `WorkflowRunner` — drives a run, emits `ProcessingMessage`s, collects outputs.
|
|
12
|
+
|
|
13
|
+
## Untaken branches
|
|
14
|
+
|
|
15
|
+
A node wired to data inputs that receives nothing on any of them does not run.
|
|
16
|
+
Its upstreams closed without emitting — an `If` emits only the taken handle, a
|
|
17
|
+
filter can emit nothing — so the node is on a branch nobody took. Skipping it
|
|
18
|
+
closes its own outputs with nothing, which cascades down the untaken subgraph.
|
|
19
|
+
|
|
20
|
+
Partial input still fires: a node that got a value on one handle and nothing on
|
|
21
|
+
another runs, with the declared default filling in the empty handle.
|
|
22
|
+
|
|
23
|
+
## Loops
|
|
24
|
+
|
|
25
|
+
A cycle is valid only when it closes on the `next` or `condition` input of a
|
|
26
|
+
`nodetool.control.Loop` node. Correlation analysis leaves those back edges out
|
|
27
|
+
of the topological order and gives the loop body its own iteration scope. The
|
|
28
|
+
Loop runs in its own actor mode (`src/loop.ts`) and closes its iteration
|
|
29
|
+
outputs itself, because the body's EOS cannot reach it first. For graphs with
|
|
30
|
+
a Loop, the runner reports a quiescent graph (every actor parked on its inbox)
|
|
31
|
+
so a Loop can end runs whose body stopped feeding back. Design:
|
|
32
|
+
[docs/workflow-loops.md](../../docs/workflow-loops.md).
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { WorkflowRunner } from "@nodetool-ai/kernel";
|
|
38
|
+
|
|
39
|
+
const runner = new WorkflowRunner("job-1", { resolveExecutor });
|
|
40
|
+
const result = await runner.run({ job_id: "job-1", params }, { nodes, edges });
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Develop
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm run build --workspace=packages/kernel
|
|
47
|
+
npm run test --workspace=packages/kernel
|
|
48
|
+
npm run lint --workspace=packages/kernel
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Scheduling design: [docs/correlation-design.md](../../docs/correlation-design.md).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2026-10-07T23:09:23.422Z
|
package/dist/actor.d.ts
CHANGED
|
@@ -8,15 +8,54 @@
|
|
|
8
8
|
* 2. Streaming input: node drains inbox via iterInput / iterAny.
|
|
9
9
|
* 3. Streaming output: call genProcess() which yields items.
|
|
10
10
|
* 4. Controlled: accept control events, cache inputs for replay.
|
|
11
|
+
* 5. Loop: `nodetool.control.Loop`, run by `runLoop` (loop.ts).
|
|
11
12
|
*
|
|
12
13
|
* Sync modes:
|
|
13
14
|
* - on_any: fire when ANY input handle has data.
|
|
14
15
|
* - zip_all: wait until ALL handles have data (with sticky semantics).
|
|
15
16
|
*/
|
|
16
|
-
import type { NodeDescriptor } from "@nodetool-ai/protocol";
|
|
17
|
+
import type { CorrelationLineage, NodeDescriptor } from "@nodetool-ai/protocol";
|
|
17
18
|
import type { ProcessingContext, NodeExecutor } from "@nodetool-ai/runtime";
|
|
19
|
+
import type { Intervention } from "@nodetool-ai/protocol";
|
|
20
|
+
import { type SupervisorHandle } from "./supervisor.js";
|
|
18
21
|
import { NodeInbox } from "./inbox.js";
|
|
22
|
+
import type { NodeAnalysis } from "./correlation-analysis.js";
|
|
23
|
+
/**
|
|
24
|
+
* Hints from the actor about how to route an invocation's outputs.
|
|
25
|
+
* See runner.ts for the consumer.
|
|
26
|
+
*/
|
|
27
|
+
export interface OutputRoutingHints {
|
|
28
|
+
invocationLineage?: CorrelationLineage;
|
|
29
|
+
perSlotLineage?: Record<string, CorrelationLineage>;
|
|
30
|
+
/**
|
|
31
|
+
* Slots in this set are being dropped (lineage_done) for the given lineage,
|
|
32
|
+
* not emitted with a value. §5. The runner sends `signalLineageDone` to
|
|
33
|
+
* downstream inboxes instead of `put`.
|
|
34
|
+
*/
|
|
35
|
+
lineageDoneSlots?: Set<string>;
|
|
36
|
+
/**
|
|
37
|
+
* A supervisor `skip` verdict: this invocation produced nothing. The runner
|
|
38
|
+
* sends `lineage_done` on every outgoing data edge at `invocationLineage`,
|
|
39
|
+
* *and* `lineage_scope_closed` for every child root the invocation would have
|
|
40
|
+
* opened — `drop()` alone signals only the former, which leaves an aggregate
|
|
41
|
+
* downstream waiting forever on a scope a skipped iterator never opened.
|
|
42
|
+
* Design §5.2.
|
|
43
|
+
*/
|
|
44
|
+
skipInvocation?: boolean;
|
|
45
|
+
}
|
|
19
46
|
export type { NodeExecutor };
|
|
47
|
+
/**
|
|
48
|
+
* Canonical lineage keys join `root=index` pairs with `,`. To compute the
|
|
49
|
+
* parent key for a shorter scope, take the first `prefixLength` pairs.
|
|
50
|
+
*/
|
|
51
|
+
export declare function trimKey(key: string, prefixLength: number): string;
|
|
52
|
+
/**
|
|
53
|
+
* Find every pending max-scope key in `maxBuckets` whose parent (trimmed to
|
|
54
|
+
* `parentLength`) equals `parentKey`. Used when a strict-prefix sticky
|
|
55
|
+
* arrival can unblock pending child firings.
|
|
56
|
+
*/
|
|
57
|
+
export declare function enumerateCandidateKeysForParent(maxBuckets: ReadonlyMap<string, ReadonlyMap<string, ReadonlyArray<unknown>>>, _dataHandles: ReadonlyArray<string>, _handleClass: ReadonlyMap<string, "max" | "prefix" | "empty">, _handleScope: ReadonlyMap<string, ReadonlyArray<string>>, _maxLength: number, parentKey: string, parentLength: number): string[];
|
|
58
|
+
export declare function enumerateAllPendingKeys(maxBuckets: ReadonlyMap<string, ReadonlyMap<string, ReadonlyArray<unknown>>>): string[];
|
|
20
59
|
export interface ActorResult {
|
|
21
60
|
outputs: Record<string, unknown>;
|
|
22
61
|
error?: string;
|
|
@@ -33,25 +72,79 @@ export declare class NodeActor {
|
|
|
33
72
|
private _latestResult;
|
|
34
73
|
/** Collected non-null outputs for streaming-output nodes. */
|
|
35
74
|
private _streamingCollectedOutputs;
|
|
36
|
-
/** Handles
|
|
37
|
-
private
|
|
75
|
+
/** Handles where multiple upstream values should be collected into a list. */
|
|
76
|
+
private _listInputHandles;
|
|
38
77
|
/** Callback to route outputs downstream. */
|
|
39
78
|
private _sendOutputs;
|
|
79
|
+
/**
|
|
80
|
+
* Lineage of the current invocation. Set when the actor consumes input(s)
|
|
81
|
+
* under the correlation flag and the inheritance case is unambiguous
|
|
82
|
+
* (single-edge single-input handle).
|
|
83
|
+
*/
|
|
84
|
+
private _currentInvocationLineage;
|
|
85
|
+
/**
|
|
86
|
+
* A node fed by a streaming handle is invoked once per chunk, so logging
|
|
87
|
+
* every invocation at INFO buries the run: one Preview on an agent's chunk
|
|
88
|
+
* output produced 1112 of 1142 lines in a run whose plan, six tasks and
|
|
89
|
+
* twelve steps took 30. The first invocation is the informative one.
|
|
90
|
+
*/
|
|
91
|
+
private _executionsLogged;
|
|
92
|
+
/**
|
|
93
|
+
* Most recent envelope consumed per handle during the current gather.
|
|
94
|
+
* Reset before each invocation. Used to compute invocation lineage when
|
|
95
|
+
* the correlation flag is on.
|
|
96
|
+
*/
|
|
97
|
+
private _lastEnvelopes;
|
|
40
98
|
/** Callback to emit processing messages (NodeUpdate, etc.). */
|
|
41
99
|
private _emitMessage;
|
|
42
100
|
/** Optional execution context passed into node executors. */
|
|
43
101
|
private _executionContext;
|
|
44
102
|
/** Control context for controller nodes (injected as _control_context input). */
|
|
45
103
|
private _controlContext;
|
|
104
|
+
/**
|
|
105
|
+
* Static correlation analysis for this node, supplied by the runner.
|
|
106
|
+
*/
|
|
107
|
+
private _correlation;
|
|
108
|
+
/**
|
|
109
|
+
* Per-iteration-root, per-parent-key counter for actor-minted iteration
|
|
110
|
+
* tokens. §2 — counters are scoped by `(root id, exact parent lineage)`
|
|
111
|
+
* and never reset for repeated invocations with the same parent key.
|
|
112
|
+
*/
|
|
113
|
+
private _iterationCounters;
|
|
114
|
+
/**
|
|
115
|
+
* Run-level cancellation signal (aborted by `WorkflowRunner.cancel()`),
|
|
116
|
+
* exposed to node code via `NodeInputs.signal`. Defaults to a
|
|
117
|
+
* never-aborted signal for test fixtures.
|
|
118
|
+
*/
|
|
119
|
+
private _cancelSignal;
|
|
120
|
+
/**
|
|
121
|
+
* Callback wired by the runner to signal early end-of-stream for a single
|
|
122
|
+
* output slot (`outputs.complete(slot)`). Marks the slot's downstream edges
|
|
123
|
+
* done immediately, rather than waiting for the actor to finish.
|
|
124
|
+
*/
|
|
125
|
+
private _signalSlotEos;
|
|
126
|
+
/**
|
|
127
|
+
* Supervisor for this run, if any. Absent means no escalation is ever
|
|
128
|
+
* constructed and the actor behaves exactly as it did before — a clean run
|
|
129
|
+
* with no supervisor costs nothing, because nothing runs.
|
|
130
|
+
*/
|
|
131
|
+
private _supervisor;
|
|
132
|
+
/** Records every escalation/verdict pair for `RunResult.interventions`. */
|
|
133
|
+
private _onIntervention;
|
|
46
134
|
constructor(opts: {
|
|
47
135
|
node: NodeDescriptor;
|
|
48
136
|
inbox: NodeInbox;
|
|
49
137
|
executor: NodeExecutor;
|
|
50
|
-
sendOutputs: (nodeId: string, outputs: Record<string, unknown
|
|
138
|
+
sendOutputs: (nodeId: string, outputs: Record<string, unknown>, hints?: OutputRoutingHints) => Promise<void>;
|
|
51
139
|
emitMessage: (msg: unknown) => void;
|
|
52
140
|
executionContext?: ProcessingContext;
|
|
53
|
-
|
|
141
|
+
listInputHandles?: Set<string>;
|
|
54
142
|
controlContext?: Record<string, unknown> | null;
|
|
143
|
+
correlation?: NodeAnalysis;
|
|
144
|
+
cancelSignal?: AbortSignal;
|
|
145
|
+
signalSlotEos?: (nodeId: string, slot: string) => void;
|
|
146
|
+
supervisor?: SupervisorHandle;
|
|
147
|
+
onIntervention?: (i: Intervention) => void;
|
|
55
148
|
});
|
|
56
149
|
/**
|
|
57
150
|
* Run the actor to completion.
|
|
@@ -60,19 +153,290 @@ export declare class NodeActor {
|
|
|
60
153
|
run(): Promise<ActorResult>;
|
|
61
154
|
private _runImpl;
|
|
62
155
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
156
|
+
* Run the node in whichever of the four execution modes applies.
|
|
157
|
+
*
|
|
158
|
+
* Trigger entry comes first: when this run was started by a delivered
|
|
159
|
+
* trigger event targeting this node, the node does not listen — it emits the
|
|
160
|
+
* event payload on its declared outputs via emitTriggerEvent() and
|
|
161
|
+
* completes. Runs without a trigger event (user pressed Run in the editor)
|
|
162
|
+
* fall through to the normal modes below, preserving the in-editor
|
|
163
|
+
* live-test experience.
|
|
164
|
+
*/
|
|
165
|
+
private _runExecutionMode;
|
|
166
|
+
/**
|
|
167
|
+
* Loop mode: the kernel owns iteration, feedback matching, and termination
|
|
168
|
+
* for `nodetool.control.Loop`; the node's process() is never called.
|
|
169
|
+
* docs/workflow-loops.md.
|
|
170
|
+
*/
|
|
171
|
+
private _runLoopMode;
|
|
172
|
+
/**
|
|
173
|
+
* Trigger entry: emit the delivered event's payload on the declared output
|
|
174
|
+
* slots and complete. One committed result per trigger event (RFC §5 site
|
|
175
|
+
* parity with the streaming-input run() path).
|
|
176
|
+
*/
|
|
177
|
+
private _runTriggerEntry;
|
|
178
|
+
/**
|
|
179
|
+
* Streaming input mode with run(): the node drains the inbox via NodeInputs
|
|
180
|
+
* and pushes outputs via NodeOutputs. Passing _lastEnvelopes as the tracker
|
|
181
|
+
* lets unmigrated filters that call inputs.stream()+outputs.emit() inherit
|
|
182
|
+
* lineage from the single-edge input automatically — matching the buffered
|
|
183
|
+
* rule.
|
|
184
|
+
*/
|
|
185
|
+
private _runStreamingInputMode;
|
|
186
|
+
/**
|
|
187
|
+
* Routing hints for one `outputs.emit()` from a streaming-input node.
|
|
188
|
+
*
|
|
189
|
+
* An explicit lineage from the caller wins outright — they own the lineage
|
|
190
|
+
* shape (e.g. forward(), or a source seeding its own root). Otherwise the
|
|
191
|
+
* emit inherits the invocation lineage, and the slot's own
|
|
192
|
+
* `output_correlation` may override it for that one slot: an `aggregate`
|
|
193
|
+
* output collapses a root from the consumed lineage (the static analyzer
|
|
194
|
+
* drops it from the output scope; the runtime lineage must match), an
|
|
195
|
+
* `iteration` output mints a token per (group, parent_key) so
|
|
196
|
+
* `outputs.emit()` still attaches the new root. A slot declares one kind or
|
|
197
|
+
* the other, so at most one of the two applies.
|
|
198
|
+
*/
|
|
199
|
+
private _streamingEmitHints;
|
|
200
|
+
/**
|
|
201
|
+
* Streaming-input node declared without a run() implementation: call
|
|
202
|
+
* process() once with the node's own property values, matching the defaults
|
|
203
|
+
* merge every other execution path applies. process() reads no inbox data,
|
|
204
|
+
* so any value queued on a connected data handle is dropped. Surface that
|
|
205
|
+
* instead of completing silently: the node is misdeclared (registry says
|
|
206
|
+
* is_streaming_input, implementation has no run()). Downgraded to a warning
|
|
207
|
+
* rather than a hard error because existing fixtures rely on the fallback
|
|
208
|
+
* firing with connected inputs.
|
|
209
|
+
*/
|
|
210
|
+
private _runStreamingInputWithoutRun;
|
|
211
|
+
/**
|
|
212
|
+
* Project an envelope's lineage onto a static scope, returning the
|
|
213
|
+
* canonical key or `null` if the lineage is incomplete for the scope.
|
|
214
|
+
*/
|
|
215
|
+
private _projectKey;
|
|
216
|
+
/**
|
|
217
|
+
* Mint the next token index for `rootId` under `parentKey` and remember it.
|
|
218
|
+
* Counters never reset within one workflow run, matching §2's rule that
|
|
219
|
+
* repeated invocations with the same parent key continue numbering instead
|
|
220
|
+
* of restarting at 0.
|
|
221
|
+
*/
|
|
222
|
+
private _mintIterationToken;
|
|
223
|
+
/**
|
|
224
|
+
* Correlated buffered scheduler — replaces `_runBuffered` under
|
|
225
|
+
* correlation.
|
|
226
|
+
*
|
|
227
|
+
* Algorithm (v1 of §4):
|
|
228
|
+
* 1. Classify each connected data handle by its static scope:
|
|
229
|
+
* - max-scope: scope length == invocation scope length → bucket per key
|
|
230
|
+
* - strict-prefix sticky: shorter non-empty scope → sticky per projected
|
|
231
|
+
* parent key
|
|
232
|
+
* - empty: empty scope → single sticky entry
|
|
233
|
+
* 2. Find the repeating driver, if any: at most one max-scope handle may be
|
|
234
|
+
* `repeats_per_key`. Static validation already rejects more than one.
|
|
235
|
+
* 3. Pull envelopes via `iterAnyWithEnvelope`. On each arrival:
|
|
236
|
+
* - record into the right bucket,
|
|
237
|
+
* - re-evaluate the keys that could now be ready.
|
|
238
|
+
* 4. For each ready key, gather values and call `_executeWithInputs`.
|
|
239
|
+
*
|
|
240
|
+
* Source nodes (no connected data handles) fire once with empty inputs.
|
|
241
|
+
*/
|
|
242
|
+
private _runCorrelated;
|
|
243
|
+
private _runCorrelatedImpl;
|
|
244
|
+
/**
|
|
245
|
+
* Under the correlated scheduler the invocation lineage is the projected
|
|
246
|
+
* lineage of the consumed max-scope envelopes, written canonically. PR 2's
|
|
247
|
+
* fallback (single non-list handle) still applies when the analyzer is not
|
|
248
|
+
* available.
|
|
249
|
+
*/
|
|
250
|
+
private _correlatedInvocationLineage;
|
|
251
|
+
/**
|
|
252
|
+
* Build the per-slot lineage map for an emission. Single/forward/chunk
|
|
253
|
+
* outputs inherit the invocation lineage; iteration outputs mint a token
|
|
254
|
+
* per group per frame.
|
|
255
|
+
*/
|
|
256
|
+
private _correlatedOutputLineage;
|
|
257
|
+
/**
|
|
258
|
+
* Coerce and check every input that has a declared dynamic slot on this
|
|
259
|
+
* node (`dynamic_inputs`). Slots without a declaration are untyped and
|
|
260
|
+
* pass through untouched. Throws on a value that cannot fit its declared
|
|
261
|
+
* type; the caller's catch turns that into a node error.
|
|
65
262
|
*/
|
|
66
|
-
private
|
|
263
|
+
private _applyDynamicSlots;
|
|
67
264
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
265
|
+
* Put the node's static list items after the connected items on the handles
|
|
266
|
+
* the executor names in `appendStaticInputs`. Every other edge input still
|
|
267
|
+
* replaces the node's own property value.
|
|
70
268
|
*/
|
|
71
|
-
private
|
|
269
|
+
private _appendStaticItems;
|
|
72
270
|
/**
|
|
73
271
|
* Execute process or genProcess with the given inputs.
|
|
74
272
|
*/
|
|
273
|
+
/**
|
|
274
|
+
* Run one invocation under the supervisor, if there is one.
|
|
275
|
+
*
|
|
276
|
+
* The catch wraps node execution and nothing else. `sendOutputs` routes to
|
|
277
|
+
* downstream inboxes sequentially, so if edge 1 delivered and edge 2 threw, a
|
|
278
|
+
* retry would duplicate edge 1's delivery — routing failures therefore fail
|
|
279
|
+
* the node without escalation. Design §5.1.
|
|
280
|
+
*
|
|
281
|
+
* Returns the outputs to route, or `SKIPPED` when the invocation was retired
|
|
282
|
+
* without emitting.
|
|
283
|
+
*/
|
|
284
|
+
private _invokeWithRecovery;
|
|
285
|
+
/**
|
|
286
|
+
* Build the escalation, ask the supervisor, and enforce the allowed set
|
|
287
|
+
* against whatever comes back. The schema shown to an agent is UX; this check
|
|
288
|
+
* is the guarantee — a buggy or third-party handle returning `retry` for an
|
|
289
|
+
* unsafe node gets `fail`.
|
|
290
|
+
*/
|
|
291
|
+
private _escalate;
|
|
292
|
+
/**
|
|
293
|
+
* Mint the escalation record. Redaction happens *here*, not at some later
|
|
294
|
+
* prompt: `Escalation` is public — it becomes a message, lands in
|
|
295
|
+
* `RunResult.interventions`, and crosses the websocket — so no unredacted
|
|
296
|
+
* instance may exist anywhere in the system. Design §6.1.
|
|
297
|
+
*/
|
|
298
|
+
private _buildEscalation;
|
|
299
|
+
/**
|
|
300
|
+
* A repaired value is type-checked against the node's declared outputs
|
|
301
|
+
* before it enters the graph. An invalid repair is not a repair.
|
|
302
|
+
*/
|
|
303
|
+
private _validateSubstitute;
|
|
304
|
+
/**
|
|
305
|
+
* Retire this invocation without emitting: `lineage_done` plus scope closure
|
|
306
|
+
* on every outgoing edge, so downstream joins move past the skipped key and
|
|
307
|
+
* aggregates see the scopes the invocation would have opened get closed.
|
|
308
|
+
*/
|
|
309
|
+
private _skipInvocation;
|
|
310
|
+
/**
|
|
311
|
+
* Whether to drop this item instead of the run, after the provider's own
|
|
312
|
+
* bounded retries failed to get past its content filter. The built-in policy
|
|
313
|
+
* for an unsupervised run — a supervised one escalates instead, because
|
|
314
|
+
* putting an agent on the failure path is what `--supervise` is for.
|
|
315
|
+
*
|
|
316
|
+
* Veo filtered one shot of a five-shot trailer on an ordinary cinematic
|
|
317
|
+
* prompt. Failing the node there fails the run and discards the four shots
|
|
318
|
+
* already generated and paid for, which is worse than delivering a four-shot
|
|
319
|
+
* cut and saying which shot was refused.
|
|
320
|
+
*
|
|
321
|
+
* Only for an invocation that is one item of a fan-out: a non-empty
|
|
322
|
+
* correlation lineage says an upstream item keyed this invocation, so the
|
|
323
|
+
* siblings are real work a failure would throw away. A single-shot node has
|
|
324
|
+
* no siblings to protect and still fails loudly. An invocation that already
|
|
325
|
+
* emitted is out too — its partial output is downstream, so retiring the
|
|
326
|
+
* lineage now would tell joins nothing arrived.
|
|
327
|
+
*/
|
|
328
|
+
private _degradeOnContentFilter;
|
|
75
329
|
private _executeWithInputs;
|
|
330
|
+
/**
|
|
331
|
+
* The streaming-output invocation, with its own recovery rules.
|
|
332
|
+
*
|
|
333
|
+
* Frames are routed inside the generator loop, so "retry" only means
|
|
334
|
+
* something before the first emit — after that the coherent choices are
|
|
335
|
+
* ending the stream (keeping what was produced) or failing. Design §5.4.
|
|
336
|
+
*/
|
|
337
|
+
private _executeStreaming;
|
|
338
|
+
/**
|
|
339
|
+
* The streaming-input invocation. A `run()` node drains its own inbox and may
|
|
340
|
+
* have consumed messages long before it threw, across arbitrary lineages —
|
|
341
|
+
* nothing is replayable and there is no single lineage for a skip to target.
|
|
342
|
+
* So the verdict set here is exactly `end_stream` · `fail`. Design §5.4.
|
|
343
|
+
*/
|
|
344
|
+
private _runStreamingInput;
|
|
345
|
+
/** Route one yielded frame. Returns true when anything went downstream. */
|
|
346
|
+
private _routeStreamingFrame;
|
|
347
|
+
/**
|
|
348
|
+
* Route values downstream, tagging any failure as a routing failure so the
|
|
349
|
+
* recovery loops let it through instead of escalating a delivery problem as
|
|
350
|
+
* if the node had failed.
|
|
351
|
+
*/
|
|
352
|
+
private _route;
|
|
353
|
+
/**
|
|
354
|
+
* Close every output slot, keeping whatever the stream already emitted —
|
|
355
|
+
* the `end_stream` verdict. Slots come from the node's declared outputs,
|
|
356
|
+
* falling back to what the stream actually produced.
|
|
357
|
+
*/
|
|
358
|
+
private _completeOutputSlots;
|
|
359
|
+
/**
|
|
360
|
+
* For each iteration group present in `frame`, mint or reuse a token. If
|
|
361
|
+
* the frame supplies an `index` value for a group that has an `index`
|
|
362
|
+
* sibling handle declared, overwrite it with the actor-minted index. §1.
|
|
363
|
+
*
|
|
364
|
+
* Returns the override map (only the slots that needed mutation) or null
|
|
365
|
+
* when no iteration groups are in play.
|
|
366
|
+
*/
|
|
367
|
+
private _mintIterationFrameOverrides;
|
|
368
|
+
/** Tokens minted for the most recent frame, reused by output lineage. */
|
|
369
|
+
private _lastMintedFrameTokens;
|
|
370
|
+
/**
|
|
371
|
+
* Atomically route a frame of values across multiple slots, minting one
|
|
372
|
+
* shared token per iteration group so sibling handles in the same group
|
|
373
|
+
* (e.g. Zip's `left` and `right`) end up as one logical item downstream.
|
|
374
|
+
* §1, §7.
|
|
375
|
+
*
|
|
376
|
+
* Algorithm:
|
|
377
|
+
* 1. Walk every slot in `values` and resolve its `output_correlation`.
|
|
378
|
+
* 2. For each iteration group present in this frame, mint exactly one
|
|
379
|
+
* token (per (root, parent_key)) and remember it for the duration of
|
|
380
|
+
* this emit.
|
|
381
|
+
* 3. Build a per-slot lineage map that attaches the same token to every
|
|
382
|
+
* sibling handle in a group. Non-iteration slots inherit the
|
|
383
|
+
* caller-supplied lineage (or the actor's invocation lineage).
|
|
384
|
+
* 4. Hand the whole frame to `_sendOutputs` in one call so the runner
|
|
385
|
+
* routes them as a single atomic delivery.
|
|
386
|
+
*/
|
|
387
|
+
private _emitGroup;
|
|
388
|
+
/**
|
|
389
|
+
* For `aggregate(innermost)` outputs, drop the collapsed root from the
|
|
390
|
+
* inherited lineage so the emitted envelope sits at the parent scope.
|
|
391
|
+
* The static analyzer drops the root from the output scope at graph load;
|
|
392
|
+
* this is the runtime mirror.
|
|
393
|
+
*
|
|
394
|
+
* Returns the rewritten lineage, or `undefined` when no collapse applies.
|
|
395
|
+
*/
|
|
396
|
+
private _maybeCollapseForSlot;
|
|
397
|
+
/**
|
|
398
|
+
* For stream-mode iteration outputs (e.g. `Zip.pair`), mint a fresh token
|
|
399
|
+
* whenever `outputs.emit()` is called without an explicit lineage. Each
|
|
400
|
+
* emit is a logical item, so the token advances per call. Sibling-handle
|
|
401
|
+
* reuse within a single frame is handled by genProcess via
|
|
402
|
+
* `_mintIterationFrameOverrides`, or by `outputs.emitGroup()` in stream
|
|
403
|
+
* mode — see `_emitGroup` above.
|
|
404
|
+
*/
|
|
405
|
+
private _maybeMintForSlot;
|
|
406
|
+
/**
|
|
407
|
+
* For each outgoing edge that consumes `slot`, send `signalLineageDone` to
|
|
408
|
+
* the downstream inbox with the envelope's projected key. §5/§6.
|
|
409
|
+
*/
|
|
410
|
+
private _propagateLineageDone;
|
|
411
|
+
/**
|
|
412
|
+
* True while `_runCorrelated` is the active execution path.
|
|
413
|
+
*/
|
|
414
|
+
private _inCorrelatedBuffered;
|
|
415
|
+
/**
|
|
416
|
+
* Build routing hints for the current invocation.
|
|
417
|
+
*
|
|
418
|
+
* When correlation analysis is available and the invocation emitted handles,
|
|
419
|
+
* the actor mints per-slot lineage for those outputs and pairs it with the
|
|
420
|
+
* invocation lineage. Otherwise it forwards just the invocation lineage,
|
|
421
|
+
* which the runner applies to outputs that inherit the invocation scope.
|
|
422
|
+
* Returns undefined when no invocation lineage is known.
|
|
423
|
+
*/
|
|
424
|
+
private _currentHints;
|
|
425
|
+
/**
|
|
426
|
+
* Compute the invocation lineage for the current set of consumed
|
|
427
|
+
* envelopes. Returns undefined when the case is ambiguous.
|
|
428
|
+
*
|
|
429
|
+
* In correlated buffered mode the lineage comes from the correlation
|
|
430
|
+
* scheduler. Otherwise the lineage is taken from the sole consumed data
|
|
431
|
+
* envelope when exactly one non-control, non-list data handle was consumed;
|
|
432
|
+
* any other arity is ambiguous and yields undefined.
|
|
433
|
+
*
|
|
434
|
+
* The map is NOT cleared here so that streaming-input nodes that emit
|
|
435
|
+
* multiple times per consumed envelope continue to inherit lineage on
|
|
436
|
+
* every emit. Buffered gather paths overwrite envelopes per handle on
|
|
437
|
+
* each iteration, which naturally tracks the latest consumed envelope.
|
|
438
|
+
*/
|
|
439
|
+
private _computeInvocationLineage;
|
|
76
440
|
/**
|
|
77
441
|
* Controlled execution: wait for control events on __control__ handle.
|
|
78
442
|
*
|
|
@@ -94,17 +458,20 @@ export declare class NodeActor {
|
|
|
94
458
|
* arrived while waiting for the next control event.
|
|
95
459
|
*/
|
|
96
460
|
private _cacheBufferedDataInputs;
|
|
461
|
+
private _emitNodeStatus;
|
|
97
462
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
*
|
|
463
|
+
* Emit a BARE `generation_complete` for one committed `process()` result
|
|
464
|
+
* (RFC §4.2 / §5). Routes through the same `_emitMessage` path as
|
|
465
|
+
* `node_update` (runner `_emit`), so it is NEVER edge-suppressed and is
|
|
466
|
+
* retained for replay. The actor stamps NO `job_id` and NO `index` — both
|
|
467
|
+
* are backfilled downstream by the relay (RFC Decision 8).
|
|
468
|
+
*
|
|
469
|
+
* Skips `nodetool.constant.*` / `nodetool.input.*` (the same set
|
|
470
|
+
* `_emitNodeStatus`'s `skipResult` rule covers): those nodes have no
|
|
471
|
+
* generation. List-valued results are carried as-is — no per-element
|
|
472
|
+
* fan-out happens in the actor (RFC Decision 1).
|
|
105
473
|
*/
|
|
106
|
-
private
|
|
107
|
-
private _emitNodeStatus;
|
|
474
|
+
private _emitGenerationComplete;
|
|
108
475
|
private _filterStreamingPartial;
|
|
109
476
|
}
|
|
110
477
|
//# sourceMappingURL=actor.d.ts.map
|
package/dist/actor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actor.d.ts","sourceRoot":"","sources":["../src/actor.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"actor.d.ts","sourceRoot":"","sources":["../src/actor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EAGf,MAAM,uBAAuB,CAAC;AAU/B,OAAO,KAAK,EACV,iBAAiB,EACjB,YAAY,EAGb,MAAM,sBAAsB,CAAC;AAQ9B,OAAO,KAAK,EAGV,YAAY,EAEb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAML,KAAK,gBAAgB,EACtB,MAAM,iBAAiB,CAAC;AAQzB,OAAO,EAAE,SAAS,EAAwB,MAAM,YAAY,CAAC;AAE7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAS9D;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,iBAAiB,CAAC,EAAE,kBAAkB,CAAC;IACvC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IACpD;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,YAAY,EAAE,YAAY,EAAE,CAAC;AAkB7B;;;GAGG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAejE;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,EAC5E,YAAY,EAAE,aAAa,CAAC,MAAM,CAAC,EACnC,YAAY,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,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