@nodetool-ai/kernel 0.8.7 → 0.8.9-bootstrap.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.
- package/dist/.nodetool-build-stamp +1 -1
- package/dist/actor.d.ts +1 -479
- package/dist/actor.d.ts.map +1 -1
- package/dist/actor.js +1 -1911
- package/dist/actor.js.map +1 -1
- package/dist/correlation-analysis.d.ts +1 -103
- package/dist/correlation-analysis.d.ts.map +1 -1
- package/dist/correlation-analysis.js +1 -845
- package/dist/correlation-analysis.js.map +1 -1
- package/dist/durable-inbox.d.ts +1 -90
- package/dist/durable-inbox.d.ts.map +1 -1
- package/dist/durable-inbox.js +1 -210
- package/dist/durable-inbox.js.map +1 -1
- package/dist/dynamic-slots.d.ts +1 -72
- package/dist/dynamic-slots.d.ts.map +1 -1
- package/dist/dynamic-slots.js +1 -191
- package/dist/dynamic-slots.js.map +1 -1
- package/dist/edge-ids.d.ts +1 -10
- package/dist/edge-ids.d.ts.map +1 -1
- package/dist/edge-ids.js +1 -14
- package/dist/edge-ids.js.map +1 -1
- package/dist/graph-utils.d.ts +1 -71
- package/dist/graph-utils.d.ts.map +1 -1
- package/dist/graph-utils.js +1 -283
- package/dist/graph-utils.js.map +1 -1
- package/dist/graph.d.ts +1 -203
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +1 -867
- package/dist/graph.js.map +1 -1
- package/dist/inbox.d.ts +1 -264
- package/dist/inbox.d.ts.map +1 -1
- package/dist/inbox.js +1 -551
- package/dist/inbox.js.map +1 -1
- package/dist/index.d.ts +1 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -19
- package/dist/index.js.map +1 -1
- package/dist/io.d.ts +1 -188
- package/dist/io.d.ts.map +1 -1
- package/dist/io.js +1 -238
- package/dist/io.js.map +1 -1
- package/dist/loop.d.ts +1 -35
- package/dist/loop.d.ts.map +1 -1
- package/dist/loop.js +1 -165
- package/dist/loop.js.map +1 -1
- package/dist/message-stream.d.ts +1 -31
- package/dist/message-stream.d.ts.map +1 -1
- package/dist/message-stream.js +1 -63
- package/dist/message-stream.js.map +1 -1
- package/dist/predicates.d.ts +1 -7
- package/dist/predicates.d.ts.map +1 -1
- package/dist/predicates.js +1 -7
- package/dist/predicates.js.map +1 -1
- package/dist/run-state.d.ts +1 -64
- package/dist/run-state.d.ts.map +1 -1
- package/dist/run-state.js +1 -41
- package/dist/run-state.js.map +1 -1
- package/dist/runner.d.ts +1 -523
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +1 -2126
- package/dist/runner.js.map +1 -1
- package/dist/substitute-validator.d.ts +1 -43
- package/dist/substitute-validator.d.ts.map +1 -1
- package/dist/substitute-validator.js +1 -168
- package/dist/substitute-validator.js.map +1 -1
- package/dist/supervisor.d.ts +1 -147
- package/dist/supervisor.d.ts.map +1 -1
- package/dist/supervisor.js +1 -286
- package/dist/supervisor.js.map +1 -1
- package/dist/trigger-wakeup.d.ts +1 -122
- package/dist/trigger-wakeup.d.ts.map +1 -1
- package/dist/trigger-wakeup.js +1 -220
- package/dist/trigger-wakeup.js.map +1 -1
- package/package.json +4 -4
package/dist/io.d.ts
CHANGED
|
@@ -1,189 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* NodeInputs / NodeOutputs – node I/O convenience wrappers.
|
|
3
|
-
*
|
|
4
|
-
* Port of src/nodetool/workflows/io.py.
|
|
5
|
-
*
|
|
6
|
-
* NodeInputs wraps a NodeInbox for reading inputs in node implementations.
|
|
7
|
-
* NodeOutputs provides an emit-based output interface backed by callbacks
|
|
8
|
-
* supplied by the actor/runner, decoupled from WorkflowRunner internals.
|
|
9
|
-
*/
|
|
10
|
-
import type { CorrelationLineage } from "@nodetool-ai/protocol";
|
|
11
|
-
import type { MessageEnvelope } from "./inbox.js";
|
|
12
|
-
import { NodeInbox } from "./inbox.js";
|
|
13
|
-
import type { NodeAnalysis, Scope } from "./correlation-analysis.js";
|
|
14
|
-
export declare class NodeInputs {
|
|
15
|
-
private _inbox;
|
|
16
|
-
private _envelopeTracker;
|
|
17
|
-
private _analysis;
|
|
18
|
-
private _signal;
|
|
19
|
-
/**
|
|
20
|
-
* `envelopeTracker`, when provided, records the most recently consumed
|
|
21
|
-
* envelope per handle. The actor passes its own `_lastEnvelopes` map so
|
|
22
|
-
* raw `stream()`/`first()`/`any()` consumers still surface lineage to the
|
|
23
|
-
* actor — that's how unmigrated stream filters (Take, Drop, Filter*)
|
|
24
|
-
* inherit lineage even when they call `outputs.emit()` with no options.
|
|
25
|
-
*
|
|
26
|
-
* `analysis` is the per-node static correlation analysis; nodes that need
|
|
27
|
-
* scope information at runtime (Zip/Cross) read it via `scopeFor()` and
|
|
28
|
-
* `invocationScope()`.
|
|
29
|
-
*
|
|
30
|
-
* `signal` is the run's cancellation signal (aborted by
|
|
31
|
-
* `WorkflowRunner.cancel()`). Defaults to a never-aborted signal so test
|
|
32
|
-
* fixtures that construct NodeInputs directly stay terse.
|
|
33
|
-
*/
|
|
34
|
-
constructor(inbox: NodeInbox, envelopeTracker?: Map<string, MessageEnvelope> | null, analysis?: NodeAnalysis, signal?: AbortSignal);
|
|
35
|
-
/**
|
|
36
|
-
* Aborted when the run is cancelled. Inbox closure only unblocks
|
|
37
|
-
* consumers; producing loops (generators, pacers) must observe this.
|
|
38
|
-
*/
|
|
39
|
-
get signal(): AbortSignal;
|
|
40
|
-
/**
|
|
41
|
-
* Static scope of a connected input handle, or `[]` when analysis is off
|
|
42
|
-
* or the handle has no scope.
|
|
43
|
-
*/
|
|
44
|
-
scopeFor(handle: string): Scope;
|
|
45
|
-
/**
|
|
46
|
-
* The node's invocation scope (largest comparable input scope, or longest
|
|
47
|
-
* common parent prefix on join nodes), or `[]` when analysis is off.
|
|
48
|
-
*/
|
|
49
|
-
invocationScope(): Scope;
|
|
50
|
-
/**
|
|
51
|
-
* Return the first available item for a handle, or default if EOS.
|
|
52
|
-
*
|
|
53
|
-
* HOLDOUT (anti-slop/no-unknown-returns): the item is whatever the upstream
|
|
54
|
-
* node put on the handle — the open workflow-value domain, which NodeTool
|
|
55
|
-
* has no named union for. The kernel never inspects the payload.
|
|
56
|
-
*/
|
|
57
|
-
first(name: string, defaultValue?: unknown): Promise<unknown>;
|
|
58
|
-
/**
|
|
59
|
-
* Return the first available MessageEnvelope for a handle, or default if EOS.
|
|
60
|
-
*/
|
|
61
|
-
firstWithEnvelope<TDefault>(name: string, defaultValue?: TDefault): Promise<MessageEnvelope | TDefault | undefined>;
|
|
62
|
-
/**
|
|
63
|
-
* Async generator: yields items until EOS. The most recent envelope per
|
|
64
|
-
* handle is recorded so the actor can derive invocation lineage.
|
|
65
|
-
*/
|
|
66
|
-
stream(name: string): AsyncGenerator<unknown>;
|
|
67
|
-
/**
|
|
68
|
-
* Async generator: yields MessageEnvelopes until EOS.
|
|
69
|
-
*/
|
|
70
|
-
streamWithEnvelope(name: string): AsyncGenerator<MessageEnvelope>;
|
|
71
|
-
/**
|
|
72
|
-
* Async generator: yields [handle, item] tuples in arrival order.
|
|
73
|
-
*/
|
|
74
|
-
any(): AsyncGenerator<[string, unknown]>;
|
|
75
|
-
/**
|
|
76
|
-
* Async generator: yields [handle, MessageEnvelope] tuples.
|
|
77
|
-
*/
|
|
78
|
-
anyWithEnvelope(): AsyncGenerator<[string, MessageEnvelope]>;
|
|
79
|
-
/**
|
|
80
|
-
* True if handle has buffered items.
|
|
81
|
-
*/
|
|
82
|
-
hasBuffered(name: string): boolean;
|
|
83
|
-
/**
|
|
84
|
-
* True if handle has open upstream sources.
|
|
85
|
-
*/
|
|
86
|
-
hasStream(name: string): boolean;
|
|
87
|
-
}
|
|
88
|
-
export interface EmitOptions {
|
|
89
|
-
/**
|
|
90
|
-
* Override the lineage propagated downstream for this emission.
|
|
91
|
-
* Used by `outputs.forward()` to copy the source envelope's lineage; can be
|
|
92
|
-
* supplied directly when a stream node mints lineage itself.
|
|
93
|
-
*/
|
|
94
|
-
lineage?: CorrelationLineage;
|
|
95
|
-
}
|
|
96
|
-
export interface NodeOutputsOptions {
|
|
97
|
-
/**
|
|
98
|
-
* Called for each emitted (slot, value) pair to route the value downstream.
|
|
99
|
-
* If not provided, outputs are only collected locally.
|
|
100
|
-
*
|
|
101
|
-
* `opts.lineage` is forwarded to the inbox `put()` call so the downstream
|
|
102
|
-
* envelope carries the correct correlation lineage.
|
|
103
|
-
*/
|
|
104
|
-
sendFn?: (slot: string, value: unknown, opts?: EmitOptions) => Promise<void>;
|
|
105
|
-
/**
|
|
106
|
-
* Called when complete(slot) is invoked to signal early EOS on a slot.
|
|
107
|
-
*/
|
|
108
|
-
eosCallback?: (slot: string) => void;
|
|
109
|
-
/**
|
|
110
|
-
* Send `lineage_done` for `slot` at the projected key carried by
|
|
111
|
-
* `envelope`. Wired by the actor so a stream node calling `outputs.drop()`
|
|
112
|
-
* propagates the slot's done signal to downstream inboxes.
|
|
113
|
-
*/
|
|
114
|
-
dropFn?: (slot: string, envelope: MessageEnvelope) => Promise<void>;
|
|
115
|
-
/**
|
|
116
|
-
* Atomically emit a frame across multiple slots, minting one shared token
|
|
117
|
-
* per iteration group so sibling handles in a group share lineage. Falls
|
|
118
|
-
* back to sequential `sendFn` if not supplied.
|
|
119
|
-
*/
|
|
120
|
-
emitGroupFn?: (values: Record<string, unknown>, opts?: EmitOptions) => Promise<void>;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Emitter wrapper for routing node outputs.
|
|
124
|
-
*
|
|
125
|
-
* Port of src/nodetool/workflows/io.py (NodeOutputs class).
|
|
126
|
-
*
|
|
127
|
-
* Provides a clean emit-based interface for nodes to produce outputs.
|
|
128
|
-
* Routing is decoupled via callbacks provided by the actor/runner.
|
|
129
|
-
*/
|
|
130
|
-
export declare class NodeOutputs {
|
|
131
|
-
private _collected;
|
|
132
|
-
private _sendFn;
|
|
133
|
-
private _eosCallback;
|
|
134
|
-
private _dropFn;
|
|
135
|
-
private _emitGroupFn;
|
|
136
|
-
constructor(opts?: NodeOutputsOptions);
|
|
137
|
-
/**
|
|
138
|
-
* Atomically emit a frame across multiple slots, sharing one minted token
|
|
139
|
-
* per iteration group. Required for stream-mode iteration outputs (Zip,
|
|
140
|
-
* Cross) so paired sibling handles do not get split into independent
|
|
141
|
-
* items. §1.
|
|
142
|
-
*
|
|
143
|
-
* Falls back to sequential `emit()` (which mints independently per slot)
|
|
144
|
-
* if no `emitGroupFn` is wired — preserved for test fixtures with no
|
|
145
|
-
* actor.
|
|
146
|
-
*/
|
|
147
|
-
emitGroup(values: Record<string, unknown>, opts?: EmitOptions): Promise<void>;
|
|
148
|
-
/**
|
|
149
|
-
* Emit a value to a named output slot.
|
|
150
|
-
* Routes downstream via sendFn (if set) and collects the last value per slot.
|
|
151
|
-
* An empty or null slot name defaults to "output".
|
|
152
|
-
*
|
|
153
|
-
* If `opts.lineage` is provided, that lineage is propagated to the
|
|
154
|
-
* downstream envelope; otherwise the actor's ambient invocation lineage is
|
|
155
|
-
* used.
|
|
156
|
-
*/
|
|
157
|
-
emit(slot: string, value: unknown, opts?: EmitOptions): Promise<void>;
|
|
158
|
-
/**
|
|
159
|
-
* Convenience: emit to the "output" slot.
|
|
160
|
-
*/
|
|
161
|
-
default(value: unknown): Promise<void>;
|
|
162
|
-
/**
|
|
163
|
-
* Forward an envelope to `slot`, preserving its correlation lineage.
|
|
164
|
-
*
|
|
165
|
-
* With two arguments, the envelope's `data` is forwarded unchanged. With
|
|
166
|
-
* three arguments, the caller-supplied value replaces it — including
|
|
167
|
-
* `null`/`undefined`, which would otherwise be indistinguishable from
|
|
168
|
-
* "not supplied" if we used `??`.
|
|
169
|
-
*/
|
|
170
|
-
forward(slot: string, envelope: MessageEnvelope, ...overrideValue: [] | [unknown]): Promise<void>;
|
|
171
|
-
/**
|
|
172
|
-
* Send `lineage_done` for `slot` at the projected key carried by
|
|
173
|
-
* `envelope`, via the actor's drop callback, so downstream inboxes learn the
|
|
174
|
-
* slot produced no value for this lineage.
|
|
175
|
-
*/
|
|
176
|
-
drop(slot: string, envelope: MessageEnvelope): Promise<void>;
|
|
177
|
-
/**
|
|
178
|
-
* Signal early end-of-stream for a specific output slot.
|
|
179
|
-
* Calls the eosCallback if provided.
|
|
180
|
-
*/
|
|
181
|
-
complete(slot: string): void;
|
|
182
|
-
/**
|
|
183
|
-
* Return a snapshot of all collected outputs (slot → last emitted value).
|
|
184
|
-
*/
|
|
185
|
-
collected(): {
|
|
186
|
-
[x: string]: unknown;
|
|
187
|
-
};
|
|
188
|
-
}
|
|
1
|
+
export * from "@nodetool-ai/execution-core/io";
|
|
189
2
|
//# sourceMappingURL=io.d.ts.map
|
package/dist/io.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../src/io.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../src/io.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC"}
|
package/dist/io.js
CHANGED
|
@@ -1,239 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* NodeInputs / NodeOutputs – node I/O convenience wrappers.
|
|
3
|
-
*
|
|
4
|
-
* Port of src/nodetool/workflows/io.py.
|
|
5
|
-
*
|
|
6
|
-
* NodeInputs wraps a NodeInbox for reading inputs in node implementations.
|
|
7
|
-
* NodeOutputs provides an emit-based output interface backed by callbacks
|
|
8
|
-
* supplied by the actor/runner, decoupled from WorkflowRunner internals.
|
|
9
|
-
*/
|
|
10
|
-
export class NodeInputs {
|
|
11
|
-
_inbox;
|
|
12
|
-
_envelopeTracker;
|
|
13
|
-
_analysis;
|
|
14
|
-
_signal;
|
|
15
|
-
/**
|
|
16
|
-
* `envelopeTracker`, when provided, records the most recently consumed
|
|
17
|
-
* envelope per handle. The actor passes its own `_lastEnvelopes` map so
|
|
18
|
-
* raw `stream()`/`first()`/`any()` consumers still surface lineage to the
|
|
19
|
-
* actor — that's how unmigrated stream filters (Take, Drop, Filter*)
|
|
20
|
-
* inherit lineage even when they call `outputs.emit()` with no options.
|
|
21
|
-
*
|
|
22
|
-
* `analysis` is the per-node static correlation analysis; nodes that need
|
|
23
|
-
* scope information at runtime (Zip/Cross) read it via `scopeFor()` and
|
|
24
|
-
* `invocationScope()`.
|
|
25
|
-
*
|
|
26
|
-
* `signal` is the run's cancellation signal (aborted by
|
|
27
|
-
* `WorkflowRunner.cancel()`). Defaults to a never-aborted signal so test
|
|
28
|
-
* fixtures that construct NodeInputs directly stay terse.
|
|
29
|
-
*/
|
|
30
|
-
constructor(inbox, envelopeTracker, analysis, signal) {
|
|
31
|
-
this._inbox = inbox;
|
|
32
|
-
this._envelopeTracker = envelopeTracker ?? null;
|
|
33
|
-
this._analysis = analysis;
|
|
34
|
-
this._signal = signal ?? new AbortController().signal;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Aborted when the run is cancelled. Inbox closure only unblocks
|
|
38
|
-
* consumers; producing loops (generators, pacers) must observe this.
|
|
39
|
-
*/
|
|
40
|
-
get signal() {
|
|
41
|
-
return this._signal;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Static scope of a connected input handle, or `[]` when analysis is off
|
|
45
|
-
* or the handle has no scope.
|
|
46
|
-
*/
|
|
47
|
-
scopeFor(handle) {
|
|
48
|
-
return this._analysis?.inputs.get(handle)?.scope ?? [];
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* The node's invocation scope (largest comparable input scope, or longest
|
|
52
|
-
* common parent prefix on join nodes), or `[]` when analysis is off.
|
|
53
|
-
*/
|
|
54
|
-
invocationScope() {
|
|
55
|
-
return this._analysis?.invocationScope ?? [];
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Return the first available item for a handle, or default if EOS.
|
|
59
|
-
*
|
|
60
|
-
* HOLDOUT (anti-slop/no-unknown-returns): the item is whatever the upstream
|
|
61
|
-
* node put on the handle — the open workflow-value domain, which NodeTool
|
|
62
|
-
* has no named union for. The kernel never inspects the payload.
|
|
63
|
-
*/
|
|
64
|
-
async first(name, defaultValue) {
|
|
65
|
-
for await (const envelope of this._inbox.iterInputWithEnvelope(name)) {
|
|
66
|
-
this._envelopeTracker?.set(name, envelope);
|
|
67
|
-
return envelope.data;
|
|
68
|
-
}
|
|
69
|
-
return defaultValue;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Return the first available MessageEnvelope for a handle, or default if EOS.
|
|
73
|
-
*/
|
|
74
|
-
async firstWithEnvelope(name, defaultValue) {
|
|
75
|
-
for await (const envelope of this._inbox.iterInputWithEnvelope(name)) {
|
|
76
|
-
this._envelopeTracker?.set(name, envelope);
|
|
77
|
-
return envelope;
|
|
78
|
-
}
|
|
79
|
-
return defaultValue;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Async generator: yields items until EOS. The most recent envelope per
|
|
83
|
-
* handle is recorded so the actor can derive invocation lineage.
|
|
84
|
-
*/
|
|
85
|
-
async *stream(name) {
|
|
86
|
-
for await (const envelope of this._inbox.iterInputWithEnvelope(name)) {
|
|
87
|
-
this._envelopeTracker?.set(name, envelope);
|
|
88
|
-
yield envelope.data;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Async generator: yields MessageEnvelopes until EOS.
|
|
93
|
-
*/
|
|
94
|
-
async *streamWithEnvelope(name) {
|
|
95
|
-
for await (const envelope of this._inbox.iterInputWithEnvelope(name)) {
|
|
96
|
-
this._envelopeTracker?.set(name, envelope);
|
|
97
|
-
yield envelope;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Async generator: yields [handle, item] tuples in arrival order.
|
|
102
|
-
*/
|
|
103
|
-
async *any() {
|
|
104
|
-
for await (const [handle, envelope] of this._inbox.iterAnyWithEnvelope()) {
|
|
105
|
-
this._envelopeTracker?.set(handle, envelope);
|
|
106
|
-
yield [handle, envelope.data];
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Async generator: yields [handle, MessageEnvelope] tuples.
|
|
111
|
-
*/
|
|
112
|
-
async *anyWithEnvelope() {
|
|
113
|
-
for await (const [handle, envelope] of this._inbox.iterAnyWithEnvelope()) {
|
|
114
|
-
this._envelopeTracker?.set(handle, envelope);
|
|
115
|
-
yield [handle, envelope];
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* True if handle has buffered items.
|
|
120
|
-
*/
|
|
121
|
-
hasBuffered(name) {
|
|
122
|
-
return this._inbox.hasBuffered(name);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* True if handle has open upstream sources.
|
|
126
|
-
*/
|
|
127
|
-
hasStream(name) {
|
|
128
|
-
return this._inbox.isOpen(name);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Emitter wrapper for routing node outputs.
|
|
133
|
-
*
|
|
134
|
-
* Port of src/nodetool/workflows/io.py (NodeOutputs class).
|
|
135
|
-
*
|
|
136
|
-
* Provides a clean emit-based interface for nodes to produce outputs.
|
|
137
|
-
* Routing is decoupled via callbacks provided by the actor/runner.
|
|
138
|
-
*/
|
|
139
|
-
export class NodeOutputs {
|
|
140
|
-
_collected = {};
|
|
141
|
-
_sendFn;
|
|
142
|
-
_eosCallback;
|
|
143
|
-
_dropFn;
|
|
144
|
-
_emitGroupFn;
|
|
145
|
-
constructor(opts = {}) {
|
|
146
|
-
this._sendFn = opts.sendFn ?? null;
|
|
147
|
-
this._eosCallback = opts.eosCallback ?? null;
|
|
148
|
-
this._dropFn = opts.dropFn ?? null;
|
|
149
|
-
this._emitGroupFn = opts.emitGroupFn ?? null;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Atomically emit a frame across multiple slots, sharing one minted token
|
|
153
|
-
* per iteration group. Required for stream-mode iteration outputs (Zip,
|
|
154
|
-
* Cross) so paired sibling handles do not get split into independent
|
|
155
|
-
* items. §1.
|
|
156
|
-
*
|
|
157
|
-
* Falls back to sequential `emit()` (which mints independently per slot)
|
|
158
|
-
* if no `emitGroupFn` is wired — preserved for test fixtures with no
|
|
159
|
-
* actor.
|
|
160
|
-
*/
|
|
161
|
-
async emitGroup(values, opts) {
|
|
162
|
-
for (const [slot, value] of Object.entries(values)) {
|
|
163
|
-
this._collected[slot] = value;
|
|
164
|
-
}
|
|
165
|
-
if (this._emitGroupFn) {
|
|
166
|
-
await this._emitGroupFn(values, opts);
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
for (const [slot, value] of Object.entries(values)) {
|
|
170
|
-
if (this._sendFn) {
|
|
171
|
-
await this._sendFn(slot, value, opts);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Emit a value to a named output slot.
|
|
177
|
-
* Routes downstream via sendFn (if set) and collects the last value per slot.
|
|
178
|
-
* An empty or null slot name defaults to "output".
|
|
179
|
-
*
|
|
180
|
-
* If `opts.lineage` is provided, that lineage is propagated to the
|
|
181
|
-
* downstream envelope; otherwise the actor's ambient invocation lineage is
|
|
182
|
-
* used.
|
|
183
|
-
*/
|
|
184
|
-
async emit(slot, value, opts) {
|
|
185
|
-
const resolvedSlot = slot || "output";
|
|
186
|
-
this._collected[resolvedSlot] = value;
|
|
187
|
-
if (this._sendFn) {
|
|
188
|
-
await this._sendFn(resolvedSlot, value, opts);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Convenience: emit to the "output" slot.
|
|
193
|
-
*/
|
|
194
|
-
async default(value) {
|
|
195
|
-
// Stryker disable next-line StringLiteral: emit() maps a falsy slot to
|
|
196
|
-
// "output" via `slot || "output"`, so passing "output" vs "" is identical.
|
|
197
|
-
await this.emit("output", value);
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Forward an envelope to `slot`, preserving its correlation lineage.
|
|
201
|
-
*
|
|
202
|
-
* With two arguments, the envelope's `data` is forwarded unchanged. With
|
|
203
|
-
* three arguments, the caller-supplied value replaces it — including
|
|
204
|
-
* `null`/`undefined`, which would otherwise be indistinguishable from
|
|
205
|
-
* "not supplied" if we used `??`.
|
|
206
|
-
*/
|
|
207
|
-
async forward(slot, envelope, ...overrideValue) {
|
|
208
|
-
const value = overrideValue.length > 0 ? overrideValue[0] : envelope.data;
|
|
209
|
-
await this.emit(slot, value, {
|
|
210
|
-
lineage: envelope.correlation_lineage
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Send `lineage_done` for `slot` at the projected key carried by
|
|
215
|
-
* `envelope`, via the actor's drop callback, so downstream inboxes learn the
|
|
216
|
-
* slot produced no value for this lineage.
|
|
217
|
-
*/
|
|
218
|
-
async drop(slot, envelope) {
|
|
219
|
-
if (this._dropFn) {
|
|
220
|
-
await this._dropFn(slot || "output", envelope);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Signal early end-of-stream for a specific output slot.
|
|
225
|
-
* Calls the eosCallback if provided.
|
|
226
|
-
*/
|
|
227
|
-
complete(slot) {
|
|
228
|
-
if (this._eosCallback) {
|
|
229
|
-
this._eosCallback(slot);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Return a snapshot of all collected outputs (slot → last emitted value).
|
|
234
|
-
*/
|
|
235
|
-
collected() {
|
|
236
|
-
return { ...this._collected };
|
|
237
|
-
}
|
|
238
|
-
}
|
|
1
|
+
export * from "@nodetool-ai/execution-core/io";
|
|
239
2
|
//# sourceMappingURL=io.js.map
|
package/dist/io.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.js","sourceRoot":"","sources":["../src/io.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"io.js","sourceRoot":"","sources":["../src/io.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC"}
|
package/dist/loop.d.ts
CHANGED
|
@@ -1,36 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Loop node runtime: the actor mode for `nodetool.control.Loop`.
|
|
3
|
-
*
|
|
4
|
-
* A Loop starts one run per parent key of `initial`, emits each iteration on
|
|
5
|
-
* `value`/`index` under the loop root, and waits for the body to feed back
|
|
6
|
-
* `next` (and `condition` when wired) for that iteration. It then either
|
|
7
|
-
* starts the next iteration or emits `done` at the parent key.
|
|
8
|
-
*
|
|
9
|
-
* The body is a cycle, so its EOS cannot end the loop. The Loop closes
|
|
10
|
-
* `value`/`index` itself once `initial` has closed and no run is active; EOS
|
|
11
|
-
* then flows around the body into the feedback inputs and the inbox drains.
|
|
12
|
-
* Runs whose feedback can no longer arrive end without a `done` value: when a
|
|
13
|
-
* feedback input has closed, or when the runner reports the graph quiescent.
|
|
14
|
-
* docs/workflow-loops.md.
|
|
15
|
-
*/
|
|
16
|
-
import type { CorrelationLineage, NodeDescriptor } from "@nodetool-ai/protocol";
|
|
17
|
-
import type { NodeAnalysis } from "./correlation-analysis.js";
|
|
18
|
-
import type { NodeInbox } from "./inbox.js";
|
|
19
|
-
export declare const DEFAULT_MAX_ITERATIONS = 10;
|
|
20
|
-
export declare const MAX_ITERATIONS_LIMIT = 1000;
|
|
21
|
-
/** Clamp the `max_iterations` property to [1, MAX_ITERATIONS_LIMIT]. */
|
|
22
|
-
export declare function resolveMaxIterations(raw: unknown): number;
|
|
23
|
-
/** What the Loop runtime needs from its actor. */
|
|
24
|
-
export interface LoopHost {
|
|
25
|
-
node: NodeDescriptor;
|
|
26
|
-
inbox: NodeInbox;
|
|
27
|
-
analysis: NodeAnalysis;
|
|
28
|
-
/** Route `value` on `slot` downstream with an explicit lineage. */
|
|
29
|
-
emit(slot: string, value: unknown, lineage: CorrelationLineage): Promise<void>;
|
|
30
|
-
/** Close an output slot early (EOS on its outgoing edges). */
|
|
31
|
-
closeSlot(slot: string): void;
|
|
32
|
-
/** Surface a node warning to the client. */
|
|
33
|
-
warn(message: string): void;
|
|
34
|
-
}
|
|
35
|
-
export declare function runLoop(host: LoopHost): Promise<void>;
|
|
1
|
+
export * from "@nodetool-ai/execution-core/loop";
|
|
36
2
|
//# sourceMappingURL=loop.d.ts.map
|
package/dist/loop.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loop.d.ts","sourceRoot":"","sources":["../src/loop.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"loop.d.ts","sourceRoot":"","sources":["../src/loop.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC"}
|
package/dist/loop.js
CHANGED
|
@@ -1,166 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Loop node runtime: the actor mode for `nodetool.control.Loop`.
|
|
3
|
-
*
|
|
4
|
-
* A Loop starts one run per parent key of `initial`, emits each iteration on
|
|
5
|
-
* `value`/`index` under the loop root, and waits for the body to feed back
|
|
6
|
-
* `next` (and `condition` when wired) for that iteration. It then either
|
|
7
|
-
* starts the next iteration or emits `done` at the parent key.
|
|
8
|
-
*
|
|
9
|
-
* The body is a cycle, so its EOS cannot end the loop. The Loop closes
|
|
10
|
-
* `value`/`index` itself once `initial` has closed and no run is active; EOS
|
|
11
|
-
* then flows around the body into the feedback inputs and the inbox drains.
|
|
12
|
-
* Runs whose feedback can no longer arrive end without a `done` value: when a
|
|
13
|
-
* feedback input has closed, or when the runner reports the graph quiescent.
|
|
14
|
-
* docs/workflow-loops.md.
|
|
15
|
-
*/
|
|
16
|
-
import { createLogger } from "@nodetool-ai/config";
|
|
17
|
-
import { loopRootId } from "@nodetool-ai/protocol";
|
|
18
|
-
import { tryProjectLineageKey } from "./correlation-analysis.js";
|
|
19
|
-
// Stryker disable next-line StringLiteral: logger name is a diagnostic label
|
|
20
|
-
const log = createLogger("nodetool.kernel.loop");
|
|
21
|
-
export const DEFAULT_MAX_ITERATIONS = 10;
|
|
22
|
-
export const MAX_ITERATIONS_LIMIT = 1000;
|
|
23
|
-
/** Clamp the `max_iterations` property to [1, MAX_ITERATIONS_LIMIT]. */
|
|
24
|
-
export function resolveMaxIterations(raw) {
|
|
25
|
-
const n = Math.floor(Number(raw ?? DEFAULT_MAX_ITERATIONS));
|
|
26
|
-
if (Number.isNaN(n))
|
|
27
|
-
return DEFAULT_MAX_ITERATIONS;
|
|
28
|
-
return Math.min(MAX_ITERATIONS_LIMIT, Math.max(1, n));
|
|
29
|
-
}
|
|
30
|
-
export async function runLoop(host) {
|
|
31
|
-
const { node, inbox, analysis } = host;
|
|
32
|
-
const parentScope = analysis.invocationScope;
|
|
33
|
-
const root = loopRootId(node.id);
|
|
34
|
-
const maxIterations = resolveMaxIterations(node.properties?.max_iterations);
|
|
35
|
-
const handles = new Set(inbox.handles());
|
|
36
|
-
const initialWired = handles.has("initial");
|
|
37
|
-
const conditionWired = handles.has("condition");
|
|
38
|
-
const runs = new Map();
|
|
39
|
-
const started = new Set();
|
|
40
|
-
let iterationsClosed = false;
|
|
41
|
-
const parentOf = (lineage) => {
|
|
42
|
-
const parent = {};
|
|
43
|
-
for (const r of parentScope) {
|
|
44
|
-
const token = lineage[r];
|
|
45
|
-
if (token)
|
|
46
|
-
parent[r] = token;
|
|
47
|
-
}
|
|
48
|
-
return parent;
|
|
49
|
-
};
|
|
50
|
-
const emitIteration = async (run, value) => {
|
|
51
|
-
const lineage = { ...run.parent, [root]: { index: run.iteration } };
|
|
52
|
-
await host.emit("value", value, lineage);
|
|
53
|
-
await host.emit("index", run.iteration, lineage);
|
|
54
|
-
};
|
|
55
|
-
const start = async (lineage, value) => {
|
|
56
|
-
const key = tryProjectLineageKey(lineage, parentScope) ?? "";
|
|
57
|
-
if (started.has(key)) {
|
|
58
|
-
log.warn("Loop ignored a second initial value for the same key", {
|
|
59
|
-
nodeId: node.id,
|
|
60
|
-
key
|
|
61
|
-
});
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
started.add(key);
|
|
65
|
-
const run = { parent: parentOf(lineage), iteration: 0 };
|
|
66
|
-
runs.set(key, run);
|
|
67
|
-
await emitIteration(run, value);
|
|
68
|
-
};
|
|
69
|
-
const endWithoutResult = (key, reason) => {
|
|
70
|
-
const run = runs.get(key);
|
|
71
|
-
if (!run)
|
|
72
|
-
return;
|
|
73
|
-
runs.delete(key);
|
|
74
|
-
log.info("Loop run ended without a result", {
|
|
75
|
-
nodeId: node.id,
|
|
76
|
-
key,
|
|
77
|
-
iteration: run.iteration,
|
|
78
|
-
reason
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
const decide = async (key, run) => {
|
|
82
|
-
const value = run.next.data;
|
|
83
|
-
const again = conditionWired ? Boolean(run.condition.data) : true;
|
|
84
|
-
if (again && run.iteration + 1 < maxIterations) {
|
|
85
|
-
run.iteration += 1;
|
|
86
|
-
run.next = undefined;
|
|
87
|
-
run.condition = undefined;
|
|
88
|
-
await emitIteration(run, value);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
if (again && conditionWired) {
|
|
92
|
-
host.warn(`Loop stopped after max_iterations (${maxIterations}) while its condition was still true.`);
|
|
93
|
-
}
|
|
94
|
-
runs.delete(key);
|
|
95
|
-
await host.emit("done", value, run.parent);
|
|
96
|
-
};
|
|
97
|
-
const onFeedback = async (handle, env) => {
|
|
98
|
-
const key = tryProjectLineageKey(env.correlation_lineage, parentScope);
|
|
99
|
-
const run = key === null ? undefined : runs.get(key);
|
|
100
|
-
const iteration = env.correlation_lineage[root]?.index;
|
|
101
|
-
if (!run || iteration !== run.iteration) {
|
|
102
|
-
log.warn("Loop dropped feedback for an iteration that is not waiting", {
|
|
103
|
-
nodeId: node.id,
|
|
104
|
-
handle,
|
|
105
|
-
key,
|
|
106
|
-
iteration
|
|
107
|
-
});
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (run[handle]) {
|
|
111
|
-
log.warn("Loop received a second feedback value for one iteration", {
|
|
112
|
-
nodeId: node.id,
|
|
113
|
-
handle,
|
|
114
|
-
key,
|
|
115
|
-
iteration
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
run[handle] = env;
|
|
119
|
-
if (run.next && (!conditionWired || run.condition)) {
|
|
120
|
-
await decide(key, run);
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
const closedAndEmpty = (handle) => !inbox.isOpen(handle) && !inbox.hasBuffered(handle);
|
|
124
|
-
if (!initialWired) {
|
|
125
|
-
await start({}, node.properties?.initial ?? null);
|
|
126
|
-
}
|
|
127
|
-
while (true) {
|
|
128
|
-
const popped = inbox.tryPopAnyWithEnvelope();
|
|
129
|
-
if (popped) {
|
|
130
|
-
const [handle, env] = popped;
|
|
131
|
-
if (handle === "initial") {
|
|
132
|
-
await start(env.correlation_lineage, env.data);
|
|
133
|
-
}
|
|
134
|
-
else if (handle === "next" || handle === "condition") {
|
|
135
|
-
await onFeedback(handle, env);
|
|
136
|
-
}
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
if (inbox.isClosed())
|
|
140
|
-
break;
|
|
141
|
-
if (inbox.takeQuiescent()) {
|
|
142
|
-
for (const key of [...runs.keys()]) {
|
|
143
|
-
endWithoutResult(key, "the loop body stopped feeding back");
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
for (const [key, run] of [...runs]) {
|
|
147
|
-
if (!run.next && closedAndEmpty("next")) {
|
|
148
|
-
endWithoutResult(key, '"next" closed');
|
|
149
|
-
}
|
|
150
|
-
else if (conditionWired && !run.condition && closedAndEmpty("condition")) {
|
|
151
|
-
endWithoutResult(key, '"condition" closed');
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (!iterationsClosed &&
|
|
155
|
-
runs.size === 0 &&
|
|
156
|
-
(!initialWired || closedAndEmpty("initial"))) {
|
|
157
|
-
iterationsClosed = true;
|
|
158
|
-
host.closeSlot("value");
|
|
159
|
-
host.closeSlot("index");
|
|
160
|
-
}
|
|
161
|
-
if (inbox.isFullyDrained())
|
|
162
|
-
break;
|
|
163
|
-
await inbox.waitForActivity();
|
|
164
|
-
}
|
|
165
|
-
}
|
|
1
|
+
export * from "@nodetool-ai/execution-core/loop";
|
|
166
2
|
//# sourceMappingURL=loop.js.map
|
package/dist/loop.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loop.js","sourceRoot":"","sources":["../src/loop.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"loop.js","sourceRoot":"","sources":["../src/loop.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC"}
|