@nodetool-ai/kernel 0.7.0-rc.11
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/actor.d.ts +110 -0
- package/dist/actor.d.ts.map +1 -0
- package/dist/actor.js +430 -0
- package/dist/actor.js.map +1 -0
- package/dist/channel.d.ts +46 -0
- package/dist/channel.d.ts.map +1 -0
- package/dist/channel.js +191 -0
- package/dist/channel.js.map +1 -0
- package/dist/durable-inbox.d.ts +82 -0
- package/dist/durable-inbox.d.ts.map +1 -0
- package/dist/durable-inbox.js +158 -0
- package/dist/durable-inbox.js.map +1 -0
- package/dist/graph-utils.d.ts +60 -0
- package/dist/graph-utils.d.ts.map +1 -0
- package/dist/graph-utils.js +249 -0
- package/dist/graph-utils.js.map +1 -0
- package/dist/graph.d.ts +153 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +656 -0
- package/dist/graph.js.map +1 -0
- package/dist/inbox.d.ts +109 -0
- package/dist/inbox.d.ts.map +1 -0
- package/dist/inbox.js +310 -0
- package/dist/inbox.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/io.d.ts +92 -0
- package/dist/io.d.ts.map +1 -0
- package/dist/io.js +128 -0
- package/dist/io.js.map +1 -0
- package/dist/runner.d.ts +221 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +1018 -0
- package/dist/runner.js.map +1 -0
- package/dist/suspendable.d.ts +68 -0
- package/dist/suspendable.d.ts.map +1 -0
- package/dist/suspendable.js +108 -0
- package/dist/suspendable.js.map +1 -0
- package/dist/trigger-manager.d.ts +107 -0
- package/dist/trigger-manager.d.ts.map +1 -0
- package/dist/trigger-manager.js +214 -0
- package/dist/trigger-manager.js.map +1 -0
- package/dist/trigger-wakeup.d.ts +54 -0
- package/dist/trigger-wakeup.d.ts.map +1 -0
- package/dist/trigger-wakeup.js +99 -0
- package/dist/trigger-wakeup.js.map +1 -0
- package/dist/trigger.d.ts +57 -0
- package/dist/trigger.d.ts.map +1 -0
- package/dist/trigger.js +145 -0
- package/dist/trigger.js.map +1 -0
- package/package.json +49 -0
package/dist/actor.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NodeActor – per-node asynchronous execution.
|
|
3
|
+
*
|
|
4
|
+
* Port of src/nodetool/workflows/actor.py.
|
|
5
|
+
*
|
|
6
|
+
* Execution modes:
|
|
7
|
+
* 1. Buffered: gather all inputs, call process() once.
|
|
8
|
+
* 2. Streaming input: node drains inbox via iterInput / iterAny.
|
|
9
|
+
* 3. Streaming output: call genProcess() which yields items.
|
|
10
|
+
* 4. Controlled: accept control events, cache inputs for replay.
|
|
11
|
+
*
|
|
12
|
+
* Sync modes:
|
|
13
|
+
* - on_any: fire when ANY input handle has data.
|
|
14
|
+
* - zip_all: wait until ALL handles have data (with sticky semantics).
|
|
15
|
+
*/
|
|
16
|
+
import type { NodeDescriptor } from "@nodetool-ai/protocol";
|
|
17
|
+
import type { ProcessingContext, NodeExecutor } from "@nodetool-ai/runtime";
|
|
18
|
+
import { NodeInbox } from "./inbox.js";
|
|
19
|
+
export type { NodeExecutor };
|
|
20
|
+
export interface ActorResult {
|
|
21
|
+
outputs: Record<string, unknown>;
|
|
22
|
+
error?: string;
|
|
23
|
+
}
|
|
24
|
+
export declare class NodeActor {
|
|
25
|
+
readonly node: NodeDescriptor;
|
|
26
|
+
readonly inbox: NodeInbox;
|
|
27
|
+
private _executor;
|
|
28
|
+
/** Cached inputs for controlled-node replay. */
|
|
29
|
+
private _cachedInputs;
|
|
30
|
+
/** Properties from the latest control event. */
|
|
31
|
+
private _currentControlProperties;
|
|
32
|
+
/** Latest execution result. */
|
|
33
|
+
private _latestResult;
|
|
34
|
+
/** Collected non-null outputs for streaming-output nodes. */
|
|
35
|
+
private _streamingCollectedOutputs;
|
|
36
|
+
/** Handles that are sticky from the start (non-streaming edges). */
|
|
37
|
+
private _initialStickyHandles;
|
|
38
|
+
/** Callback to route outputs downstream. */
|
|
39
|
+
private _sendOutputs;
|
|
40
|
+
/** Callback to emit processing messages (NodeUpdate, etc.). */
|
|
41
|
+
private _emitMessage;
|
|
42
|
+
/** Optional execution context passed into node executors. */
|
|
43
|
+
private _executionContext;
|
|
44
|
+
/** Control context for controller nodes (injected as _control_context input). */
|
|
45
|
+
private _controlContext;
|
|
46
|
+
constructor(opts: {
|
|
47
|
+
node: NodeDescriptor;
|
|
48
|
+
inbox: NodeInbox;
|
|
49
|
+
executor: NodeExecutor;
|
|
50
|
+
sendOutputs: (nodeId: string, outputs: Record<string, unknown>) => Promise<void>;
|
|
51
|
+
emitMessage: (msg: unknown) => void;
|
|
52
|
+
executionContext?: ProcessingContext;
|
|
53
|
+
stickyHandles?: Set<string>;
|
|
54
|
+
controlContext?: Record<string, unknown> | null;
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* Run the actor to completion.
|
|
58
|
+
* Returns the last outputs produced.
|
|
59
|
+
*/
|
|
60
|
+
run(): Promise<ActorResult>;
|
|
61
|
+
private _runImpl;
|
|
62
|
+
/**
|
|
63
|
+
* Buffered / streaming-output execution.
|
|
64
|
+
* Gathers inputs per sync_mode, then runs process or genProcess.
|
|
65
|
+
*/
|
|
66
|
+
private _runBuffered;
|
|
67
|
+
/**
|
|
68
|
+
* on_any execution: wait for all handles to have at least one value,
|
|
69
|
+
* then fire. After initial fire, each subsequent item fires immediately.
|
|
70
|
+
*/
|
|
71
|
+
private _runOnAny;
|
|
72
|
+
/**
|
|
73
|
+
* Execute process or genProcess with the given inputs.
|
|
74
|
+
*/
|
|
75
|
+
private _executeWithInputs;
|
|
76
|
+
/**
|
|
77
|
+
* Controlled execution: wait for control events on __control__ handle.
|
|
78
|
+
*
|
|
79
|
+
* Unlike the generic iterAny() approach, this iterates ONLY the
|
|
80
|
+
* __control__ handle so that the loop terminates as soon as all
|
|
81
|
+
* controllers signal EOS (markSourceDone). Data inputs are drained
|
|
82
|
+
* from the inbox buffers before each execution and cached for replay.
|
|
83
|
+
*/
|
|
84
|
+
private _runControlled;
|
|
85
|
+
/**
|
|
86
|
+
* Wait until every data handle has at least one buffered value.
|
|
87
|
+
* Drains items from the inbox as they arrive, caching them, until
|
|
88
|
+
* all required handles are satisfied.
|
|
89
|
+
*/
|
|
90
|
+
private _waitForDataInputs;
|
|
91
|
+
/**
|
|
92
|
+
* Drain all buffered data (non-control) inputs and cache them.
|
|
93
|
+
* Called before each controlled execution to pick up any data that
|
|
94
|
+
* arrived while waiting for the next control event.
|
|
95
|
+
*/
|
|
96
|
+
private _cacheBufferedDataInputs;
|
|
97
|
+
/**
|
|
98
|
+
* zip_all: wait until every registered handle has at least one item,
|
|
99
|
+
* using "sticky" semantics for handles that have no more upstream.
|
|
100
|
+
*/
|
|
101
|
+
private _stickyValues;
|
|
102
|
+
private _gatherZipAll;
|
|
103
|
+
/**
|
|
104
|
+
* Pop a single item from a specific handle's buffer.
|
|
105
|
+
*/
|
|
106
|
+
private _popHandle;
|
|
107
|
+
private _emitNodeStatus;
|
|
108
|
+
private _filterStreamingPartial;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=actor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actor.d.ts","sourceRoot":"","sources":["../src/actor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAgB,MAAM,uBAAuB,CAAC;AAG1E,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAE5E,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,YAAY,EAAE,YAAY,EAAE,CAAC;AAM7B,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,M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hC;;;;;;;OAOG;YACW,cAAc;IA2C5B;;;;OAIG;YACW,kBAAkB;IAiChC;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IAoBhC;;;OAGG;IACH,OAAO,CAAC,aAAa,CAA+B;YAEtC,aAAa;IA2D3B;;OAEG;IACH,OAAO,CAAC,UAAU;IAWlB,OAAO,CAAC,eAAe;IAoBvB,OAAO,CAAC,uBAAuB;CAUhC"}
|
package/dist/actor.js
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NodeActor – per-node asynchronous execution.
|
|
3
|
+
*
|
|
4
|
+
* Port of src/nodetool/workflows/actor.py.
|
|
5
|
+
*
|
|
6
|
+
* Execution modes:
|
|
7
|
+
* 1. Buffered: gather all inputs, call process() once.
|
|
8
|
+
* 2. Streaming input: node drains inbox via iterInput / iterAny.
|
|
9
|
+
* 3. Streaming output: call genProcess() which yields items.
|
|
10
|
+
* 4. Controlled: accept control events, cache inputs for replay.
|
|
11
|
+
*
|
|
12
|
+
* Sync modes:
|
|
13
|
+
* - on_any: fire when ANY input handle has data.
|
|
14
|
+
* - zip_all: wait until ALL handles have data (with sticky semantics).
|
|
15
|
+
*/
|
|
16
|
+
import { createLogger } from "@nodetool-ai/config";
|
|
17
|
+
const log = createLogger("nodetool.kernel.actor");
|
|
18
|
+
import { withNodeSpan } from "@nodetool-ai/runtime";
|
|
19
|
+
import { NodeInputs, NodeOutputs } from "./io.js";
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// NodeActor
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
export class NodeActor {
|
|
24
|
+
node;
|
|
25
|
+
inbox;
|
|
26
|
+
_executor;
|
|
27
|
+
/** Cached inputs for controlled-node replay. */
|
|
28
|
+
_cachedInputs = null;
|
|
29
|
+
/** Properties from the latest control event. */
|
|
30
|
+
_currentControlProperties = {};
|
|
31
|
+
/** Latest execution result. */
|
|
32
|
+
_latestResult = null;
|
|
33
|
+
/** Collected non-null outputs for streaming-output nodes. */
|
|
34
|
+
_streamingCollectedOutputs = null;
|
|
35
|
+
/** Handles that are sticky from the start (non-streaming edges). */
|
|
36
|
+
_initialStickyHandles;
|
|
37
|
+
/** Callback to route outputs downstream. */
|
|
38
|
+
_sendOutputs;
|
|
39
|
+
/** Callback to emit processing messages (NodeUpdate, etc.). */
|
|
40
|
+
_emitMessage;
|
|
41
|
+
/** Optional execution context passed into node executors. */
|
|
42
|
+
_executionContext;
|
|
43
|
+
/** Control context for controller nodes (injected as _control_context input). */
|
|
44
|
+
_controlContext;
|
|
45
|
+
constructor(opts) {
|
|
46
|
+
this.node = opts.node;
|
|
47
|
+
this.inbox = opts.inbox;
|
|
48
|
+
this._executor = opts.executor;
|
|
49
|
+
this._sendOutputs = opts.sendOutputs;
|
|
50
|
+
this._emitMessage = opts.emitMessage;
|
|
51
|
+
this._executionContext = opts.executionContext;
|
|
52
|
+
this._initialStickyHandles = opts.stickyHandles ?? new Set();
|
|
53
|
+
this._controlContext = opts.controlContext ?? null;
|
|
54
|
+
}
|
|
55
|
+
// -----------------------------------------------------------------------
|
|
56
|
+
// Main execution entry point
|
|
57
|
+
// -----------------------------------------------------------------------
|
|
58
|
+
/**
|
|
59
|
+
* Run the actor to completion.
|
|
60
|
+
* Returns the last outputs produced.
|
|
61
|
+
*/
|
|
62
|
+
async run() {
|
|
63
|
+
return withNodeSpan({ nodeId: this.node.id, nodeType: this.node.type }, () => this._runImpl());
|
|
64
|
+
}
|
|
65
|
+
async _runImpl() {
|
|
66
|
+
let errorMessage;
|
|
67
|
+
try {
|
|
68
|
+
log.debug("Actor started", {
|
|
69
|
+
nodeId: this.node.id,
|
|
70
|
+
type: this.node.type
|
|
71
|
+
});
|
|
72
|
+
this._emitNodeStatus("running");
|
|
73
|
+
if (this._executor.preProcess) {
|
|
74
|
+
await this._executor.preProcess();
|
|
75
|
+
}
|
|
76
|
+
// Determine execution mode
|
|
77
|
+
if (this.node.is_streaming_input) {
|
|
78
|
+
if (this._executor.run) {
|
|
79
|
+
// Streaming input mode with run(): node drains inbox via
|
|
80
|
+
// NodeInputs and pushes outputs via NodeOutputs.
|
|
81
|
+
const nodeInputs = new NodeInputs(this.inbox);
|
|
82
|
+
const nodeOutputs = new NodeOutputs({
|
|
83
|
+
sendFn: async (slot, value) => {
|
|
84
|
+
await this._sendOutputs(this.node.id, { [slot]: value });
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
await this._executor.run(nodeInputs, nodeOutputs, this._executionContext);
|
|
88
|
+
this._latestResult = nodeOutputs.collected();
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// Legacy fallback: call process() once with empty inputs.
|
|
92
|
+
const outputs = await this._executor.process({}, this._executionContext);
|
|
93
|
+
this._latestResult = outputs;
|
|
94
|
+
await this._sendOutputs(this.node.id, outputs);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else if (this.node.is_controlled) {
|
|
98
|
+
// Controlled mode: wait for control events from inbox
|
|
99
|
+
await this._runControlled();
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// Standard buffered or streaming-output mode
|
|
103
|
+
await this._runBuffered();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
errorMessage = err instanceof Error ? err.message : String(err);
|
|
108
|
+
log.error("Actor failed", {
|
|
109
|
+
nodeId: this.node.id,
|
|
110
|
+
type: this.node.type,
|
|
111
|
+
error: errorMessage
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
// Always finalize, even on error (Python parity: gap #13)
|
|
116
|
+
if (this._executor.finalize) {
|
|
117
|
+
try {
|
|
118
|
+
await this._executor.finalize();
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// Swallow finalize errors — don't mask original error
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (errorMessage !== undefined) {
|
|
126
|
+
this._emitNodeStatus("error", undefined, errorMessage);
|
|
127
|
+
return { outputs: {}, error: errorMessage };
|
|
128
|
+
}
|
|
129
|
+
log.debug("Actor completed", {
|
|
130
|
+
nodeId: this.node.id,
|
|
131
|
+
type: this.node.type
|
|
132
|
+
});
|
|
133
|
+
// Skip attaching result for constant/input nodes: the client already
|
|
134
|
+
// holds these values as properties, so echoing them back is redundant.
|
|
135
|
+
const skipResult = this.node.type.startsWith("nodetool.constant.") ||
|
|
136
|
+
this.node.type.startsWith("nodetool.input.");
|
|
137
|
+
this._emitNodeStatus("completed", skipResult ? undefined : (this._latestResult ?? {}));
|
|
138
|
+
return { outputs: this._latestResult ?? {} };
|
|
139
|
+
}
|
|
140
|
+
// -----------------------------------------------------------------------
|
|
141
|
+
// Execution modes
|
|
142
|
+
// -----------------------------------------------------------------------
|
|
143
|
+
/**
|
|
144
|
+
* Buffered / streaming-output execution.
|
|
145
|
+
* Gathers inputs per sync_mode, then runs process or genProcess.
|
|
146
|
+
*/
|
|
147
|
+
async _runBuffered() {
|
|
148
|
+
const syncMode = this.node.sync_mode ?? "zip_all";
|
|
149
|
+
const inputHandles = [...this.inbox["_buffers"].keys()].filter((h) => h !== "__control__");
|
|
150
|
+
// Source nodes with no data inputs should execute once with empty inputs.
|
|
151
|
+
if (inputHandles.length === 0) {
|
|
152
|
+
await this._executeWithInputs({});
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (syncMode === "on_any") {
|
|
156
|
+
return this._runOnAny(inputHandles);
|
|
157
|
+
}
|
|
158
|
+
// zip_all: keep gathering input batches until inbox is drained
|
|
159
|
+
while (true) {
|
|
160
|
+
const inputs = await this._gatherZipAll();
|
|
161
|
+
if (inputs === null)
|
|
162
|
+
break;
|
|
163
|
+
await this._executeWithInputs(inputs);
|
|
164
|
+
if (this.inbox.isFullyDrained())
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* on_any execution: wait for all handles to have at least one value,
|
|
170
|
+
* then fire. After initial fire, each subsequent item fires immediately.
|
|
171
|
+
*/
|
|
172
|
+
async _runOnAny(inputHandles) {
|
|
173
|
+
const current = {};
|
|
174
|
+
const pendingHandles = new Set(inputHandles);
|
|
175
|
+
let initialFired = false;
|
|
176
|
+
for await (const [handle, item] of this.inbox.iterAny()) {
|
|
177
|
+
if (handle === "__control__")
|
|
178
|
+
continue;
|
|
179
|
+
current[handle] = item;
|
|
180
|
+
if (!initialFired) {
|
|
181
|
+
pendingHandles.delete(handle);
|
|
182
|
+
if (pendingHandles.size > 0)
|
|
183
|
+
continue;
|
|
184
|
+
await this._executeWithInputs({ ...current });
|
|
185
|
+
initialFired = true;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
await this._executeWithInputs({ ...current });
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Execute process or genProcess with the given inputs.
|
|
194
|
+
*/
|
|
195
|
+
async _executeWithInputs(inputs) {
|
|
196
|
+
// Merge node properties as defaults — edge inputs override.
|
|
197
|
+
// This matches Python's behavior where process() always receives
|
|
198
|
+
// the node's own property values as baseline inputs.
|
|
199
|
+
// Precedence: declared properties < dynamic_properties (user-typed) < edge inputs.
|
|
200
|
+
if (this.node.properties || this.node.dynamic_properties) {
|
|
201
|
+
inputs = {
|
|
202
|
+
...(this.node.properties ?? {}),
|
|
203
|
+
...(this.node.dynamic_properties ?? {}),
|
|
204
|
+
...inputs
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
// Inject _control_context for controller nodes (Python parity:
|
|
208
|
+
// process_streaming_node_with_inputs / _is_controller / _build_control_context)
|
|
209
|
+
if (this._controlContext) {
|
|
210
|
+
inputs = { ...inputs, _control_context: this._controlContext };
|
|
211
|
+
}
|
|
212
|
+
log.info("Executing node", {
|
|
213
|
+
nodeId: this.node.id,
|
|
214
|
+
type: this.node.type,
|
|
215
|
+
syncMode: this.node.sync_mode ?? "on_any",
|
|
216
|
+
inputHandles: Object.keys(inputs)
|
|
217
|
+
});
|
|
218
|
+
if (this.node.is_streaming_output && this._executor.genProcess) {
|
|
219
|
+
this._streamingCollectedOutputs = {};
|
|
220
|
+
for await (const partial of this._executor.genProcess(inputs, this._executionContext)) {
|
|
221
|
+
const routed = this._filterStreamingPartial(partial);
|
|
222
|
+
if (Object.keys(routed).length === 0)
|
|
223
|
+
continue;
|
|
224
|
+
Object.assign(this._streamingCollectedOutputs, routed);
|
|
225
|
+
this._latestResult = { ...this._streamingCollectedOutputs };
|
|
226
|
+
await this._sendOutputs(this.node.id, routed);
|
|
227
|
+
}
|
|
228
|
+
this._latestResult = { ...(this._streamingCollectedOutputs ?? {}) };
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
const outputs = await this._executor.process(inputs, this._executionContext);
|
|
232
|
+
this._latestResult = outputs;
|
|
233
|
+
await this._sendOutputs(this.node.id, outputs);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Controlled execution: wait for control events on __control__ handle.
|
|
238
|
+
*
|
|
239
|
+
* Unlike the generic iterAny() approach, this iterates ONLY the
|
|
240
|
+
* __control__ handle so that the loop terminates as soon as all
|
|
241
|
+
* controllers signal EOS (markSourceDone). Data inputs are drained
|
|
242
|
+
* from the inbox buffers before each execution and cached for replay.
|
|
243
|
+
*/
|
|
244
|
+
async _runControlled() {
|
|
245
|
+
// Identify data handles (non-control) that need to be populated
|
|
246
|
+
const dataHandles = [...this.inbox["_buffers"].keys()].filter((h) => h !== "__control__");
|
|
247
|
+
// Wait for all data handles to have at least one value before
|
|
248
|
+
// processing the first control event. This ensures that when an
|
|
249
|
+
// upstream node feeds data into the controlled node, the data
|
|
250
|
+
// arrives before we try to execute.
|
|
251
|
+
if (dataHandles.length > 0 && !this._cachedInputs) {
|
|
252
|
+
await this._waitForDataInputs(dataHandles);
|
|
253
|
+
}
|
|
254
|
+
for await (const item of this.inbox.iterInput("__control__")) {
|
|
255
|
+
const event = item;
|
|
256
|
+
if (event.event_type === "stop") {
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
if (event.event_type === "run") {
|
|
260
|
+
this._currentControlProperties = event.properties;
|
|
261
|
+
// Drain any buffered data inputs before processing (replay)
|
|
262
|
+
this._cacheBufferedDataInputs();
|
|
263
|
+
const inputs = this._cachedInputs ?? {};
|
|
264
|
+
// Merge node properties as defaults (matching _executeWithInputs behavior)
|
|
265
|
+
const baseProps = this.node.properties ?? {};
|
|
266
|
+
const dynProps = this.node.dynamic_properties ?? {};
|
|
267
|
+
const merged = {
|
|
268
|
+
...baseProps,
|
|
269
|
+
...dynProps,
|
|
270
|
+
...inputs,
|
|
271
|
+
...this._currentControlProperties
|
|
272
|
+
};
|
|
273
|
+
const outputs = await this._executor.process(merged, this._executionContext);
|
|
274
|
+
this._latestResult = outputs;
|
|
275
|
+
await this._sendOutputs(this.node.id, outputs);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Wait until every data handle has at least one buffered value.
|
|
281
|
+
* Drains items from the inbox as they arrive, caching them, until
|
|
282
|
+
* all required handles are satisfied.
|
|
283
|
+
*/
|
|
284
|
+
async _waitForDataInputs(dataHandles) {
|
|
285
|
+
const pending = new Set(dataHandles);
|
|
286
|
+
// Check what's already buffered
|
|
287
|
+
for (const handle of dataHandles) {
|
|
288
|
+
if (this.inbox.hasBuffered(handle)) {
|
|
289
|
+
pending.delete(handle);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (pending.size === 0) {
|
|
293
|
+
this._cacheBufferedDataInputs();
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
// Drain items until all data handles have at least one value
|
|
297
|
+
for await (const [handle, item] of this.inbox.iterAny()) {
|
|
298
|
+
if (handle === "__control__") {
|
|
299
|
+
// Push control events back – they'll be consumed by iterInput later
|
|
300
|
+
this.inbox.prepend("__control__", {
|
|
301
|
+
data: item,
|
|
302
|
+
metadata: {},
|
|
303
|
+
timestamp: Date.now(),
|
|
304
|
+
event_id: ""
|
|
305
|
+
});
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
if (!this._cachedInputs)
|
|
309
|
+
this._cachedInputs = {};
|
|
310
|
+
this._cachedInputs[handle] = item;
|
|
311
|
+
pending.delete(handle);
|
|
312
|
+
if (pending.size === 0)
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Drain all buffered data (non-control) inputs and cache them.
|
|
318
|
+
* Called before each controlled execution to pick up any data that
|
|
319
|
+
* arrived while waiting for the next control event.
|
|
320
|
+
*/
|
|
321
|
+
_cacheBufferedDataInputs() {
|
|
322
|
+
const buffers = this.inbox["_buffers"];
|
|
323
|
+
for (const [handle, buf] of buffers) {
|
|
324
|
+
if (handle === "__control__" || buf.length === 0)
|
|
325
|
+
continue;
|
|
326
|
+
// Use the latest buffered value for each data handle
|
|
327
|
+
while (buf.length > 0) {
|
|
328
|
+
const envelope = buf.shift();
|
|
329
|
+
if (!this._cachedInputs)
|
|
330
|
+
this._cachedInputs = {};
|
|
331
|
+
this._cachedInputs[handle] = envelope.data;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
// -----------------------------------------------------------------------
|
|
336
|
+
// Input gathering (sync modes)
|
|
337
|
+
// -----------------------------------------------------------------------
|
|
338
|
+
/**
|
|
339
|
+
* zip_all: wait until every registered handle has at least one item,
|
|
340
|
+
* using "sticky" semantics for handles that have no more upstream.
|
|
341
|
+
*/
|
|
342
|
+
_stickyValues = {};
|
|
343
|
+
async _gatherZipAll() {
|
|
344
|
+
const handles = [...this.inbox["_buffers"].keys()].filter((h) => h !== "__control__");
|
|
345
|
+
if (handles.length === 0)
|
|
346
|
+
return null;
|
|
347
|
+
const result = {};
|
|
348
|
+
let gotNew = false;
|
|
349
|
+
for (const handle of handles) {
|
|
350
|
+
if (this.inbox.hasBuffered(handle)) {
|
|
351
|
+
const popped = this._popHandle(handle);
|
|
352
|
+
if (popped !== undefined) {
|
|
353
|
+
result[handle] = popped;
|
|
354
|
+
this._stickyValues[handle] = popped;
|
|
355
|
+
gotNew = true;
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
// Use sticky value if handle is closed or marked sticky from streaming analysis
|
|
360
|
+
const isSticky = !this.inbox.isOpen(handle) || this._initialStickyHandles.has(handle);
|
|
361
|
+
if (isSticky && handle in this._stickyValues) {
|
|
362
|
+
result[handle] = this._stickyValues[handle];
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
// Handle still open but no data yet – wait
|
|
366
|
+
if (this.inbox.isOpen(handle)) {
|
|
367
|
+
const gen = this.inbox.iterInput(handle);
|
|
368
|
+
const next = await gen.next();
|
|
369
|
+
if (next.done) {
|
|
370
|
+
// EOS – use sticky if available
|
|
371
|
+
if (handle in this._stickyValues) {
|
|
372
|
+
result[handle] = this._stickyValues[handle];
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
return null; // no sticky, no data
|
|
376
|
+
}
|
|
377
|
+
result[handle] = next.value;
|
|
378
|
+
this._stickyValues[handle] = next.value;
|
|
379
|
+
gotNew = true;
|
|
380
|
+
await gen.return(undefined);
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
// Handle closed, no sticky
|
|
384
|
+
if (!(handle in this._stickyValues)) {
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
result[handle] = this._stickyValues[handle];
|
|
388
|
+
}
|
|
389
|
+
if (!gotNew)
|
|
390
|
+
return null; // all sticky, no new data
|
|
391
|
+
return result;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Pop a single item from a specific handle's buffer.
|
|
395
|
+
*/
|
|
396
|
+
_popHandle(handle) {
|
|
397
|
+
const buf = this.inbox["_buffers"].get(handle);
|
|
398
|
+
if (!buf || buf.length === 0)
|
|
399
|
+
return undefined;
|
|
400
|
+
const envelope = buf.shift();
|
|
401
|
+
return envelope.data;
|
|
402
|
+
}
|
|
403
|
+
// -----------------------------------------------------------------------
|
|
404
|
+
// Status helpers
|
|
405
|
+
// -----------------------------------------------------------------------
|
|
406
|
+
_emitNodeStatus(status, result, error) {
|
|
407
|
+
this._emitMessage({
|
|
408
|
+
type: "node_update",
|
|
409
|
+
node_id: this.node.id,
|
|
410
|
+
node_name: this.node.name ?? this.node.type,
|
|
411
|
+
node_type: this.node.type,
|
|
412
|
+
status,
|
|
413
|
+
result: result ?? null,
|
|
414
|
+
error: error ?? null,
|
|
415
|
+
properties: this.node.properties && typeof this.node.properties === "object"
|
|
416
|
+
? this.node.properties
|
|
417
|
+
: null
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
_filterStreamingPartial(partial) {
|
|
421
|
+
const filtered = {};
|
|
422
|
+
for (const [key, value] of Object.entries(partial)) {
|
|
423
|
+
if (value === null || value === undefined)
|
|
424
|
+
continue;
|
|
425
|
+
filtered[key] = value;
|
|
426
|
+
}
|
|
427
|
+
return filtered;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
//# sourceMappingURL=actor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actor.js","sourceRoot":"","sources":["../src/actor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,MAAM,GAAG,GAAG,YAAY,CAAC,uBAAuB,CAAC,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAalD,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,MAAM,OAAO,SAAS;IACX,IAAI,CAAiB;IACrB,KAAK,CAAY;IAClB,SAAS,CAAe;IAEhC,gDAAgD;IACxC,aAAa,GAAmC,IA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S,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI;YAC3C,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;YACzB,MAAM;YACN,MAAM,EAAE,MAAM,IAAI,IAAI;YACtB,KAAK,EAAE,KAAK,IAAI,IAAI;YACpB,UAAU,EACR,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,KAAK,QAAQ;gBAC9D,CAAC,CAAE,IAAI,CAAC,IAAI,CAAC,UAAsC;gBACnD,CAAC,CAAC,IAAI;SACX,CAAC,CAAC;IACL,CAAC;IAEO,uBAAuB,CAC7B,OAAgC;QAEhC,MAAM,QAAQ,GAA4B,EAAE,CAAC;QAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YACnD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;gBAAE,SAAS;YACpD,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACxB,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streaming channels for named, many-to-many, graph-independent communication.
|
|
3
|
+
*
|
|
4
|
+
* Port of src/nodetool/workflows/channel.py.
|
|
5
|
+
*
|
|
6
|
+
* Architecture:
|
|
7
|
+
* - Queue-per-Subscriber: Each subscriber gets its own buffer for isolation.
|
|
8
|
+
* - Broadcast Pattern: Publishing pushes to all subscriber buffers.
|
|
9
|
+
* - Backpressure via buffer limits per subscriber queue.
|
|
10
|
+
*/
|
|
11
|
+
export interface ChannelStats {
|
|
12
|
+
name: string;
|
|
13
|
+
subscriberCount: number;
|
|
14
|
+
isClosed: boolean;
|
|
15
|
+
messageType?: unknown;
|
|
16
|
+
}
|
|
17
|
+
export declare class Channel<T = unknown> {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
private _subscribers;
|
|
20
|
+
private _closed;
|
|
21
|
+
private _messageType?;
|
|
22
|
+
constructor(name: string, _bufferLimit?: number, messageType?: new (...args: unknown[]) => T);
|
|
23
|
+
get messageType(): (new (...args: unknown[]) => T) | undefined;
|
|
24
|
+
get isClosed(): boolean;
|
|
25
|
+
publish(item: T): Promise<void>;
|
|
26
|
+
subscribe(subscriberId: string): AsyncGenerator<T>;
|
|
27
|
+
close(): Promise<void>;
|
|
28
|
+
getStats(): ChannelStats;
|
|
29
|
+
}
|
|
30
|
+
export declare class ChannelManager {
|
|
31
|
+
private _channels;
|
|
32
|
+
private _channelTypes;
|
|
33
|
+
getChannel(name: string): Channel<unknown> | undefined;
|
|
34
|
+
createChannel<T = unknown>(name: string, bufferLimit?: number, replace?: boolean, messageType?: new (...args: unknown[]) => T): Promise<Channel<T>>;
|
|
35
|
+
getOrCreateChannel<T = unknown>(name: string, bufferLimit?: number, messageType?: new (...args: unknown[]) => T): Promise<Channel<T>>;
|
|
36
|
+
getChannelType(name: string): unknown;
|
|
37
|
+
publish(name: string, item: unknown, bufferLimit?: number): Promise<void>;
|
|
38
|
+
publishTyped<T>(name: string, item: T, messageType: new (...args: unknown[]) => T, bufferLimit?: number): Promise<void>;
|
|
39
|
+
subscribe(name: string, subscriberId: string, bufferLimit?: number): AsyncGenerator<unknown>;
|
|
40
|
+
subscribeTyped<T>(name: string, subscriberId: string, messageType: new (...args: unknown[]) => T, bufferLimit?: number): AsyncGenerator<T>;
|
|
41
|
+
closeChannel(name: string): Promise<void>;
|
|
42
|
+
closeAll(): Promise<void>;
|
|
43
|
+
listChannels(): string[];
|
|
44
|
+
getAllStats(): ChannelStats[];
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=channel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AA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