@valerypopoff/rivet2-core 2.0.8 → 2.0.9
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/cjs/bundle.cjs +1056 -462
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/esm/api/createProcessor.js +1 -0
- package/dist/esm/api/streaming.js +1 -0
- package/dist/esm/exports.js +1 -0
- package/dist/esm/model/DebuggerTransportSentinel.js +78 -0
- package/dist/esm/model/GraphAbortReasons.js +69 -0
- package/dist/esm/model/GraphBoundaryCache.js +92 -0
- package/dist/esm/model/GraphPreprocessor.js +88 -30
- package/dist/esm/model/GraphProcessor.js +295 -96
- package/dist/esm/model/NodeImpl.js +6 -4
- package/dist/esm/model/ProcessContextBuilder.js +2 -17
- package/dist/esm/model/RecordingPlayer.js +27 -7
- package/dist/esm/model/SplitRunProcessor.js +48 -9
- package/dist/esm/model/SubprocessorBridge.js +30 -23
- package/dist/esm/model/nodes/GetGlobalNode.js +14 -4
- package/dist/esm/model/nodes/GraphOutputNode.js +31 -2
- package/dist/esm/model/nodes/LoopUntilNode.js +18 -45
- package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +24 -63
- package/dist/esm/model/nodes/SetGlobalNode.js +2 -1
- package/dist/esm/model/nodes/SubGraphNode.js +22 -63
- package/dist/esm/recording/ExecutionRecorder.js +19 -6
- package/dist/esm/utils/emitDetached.js +2 -2
- package/dist/esm/utils/interpolation.js +41 -1
- package/dist/esm/utils/serialization/serialization.js +6 -5
- package/dist/esm/utils/serialization/serializationHelpers.js +2 -2
- package/dist/esm/utils/serialization/serializationInput.js +48 -0
- package/dist/esm/utils/serialization/serializationUtils.js +2 -33
- package/dist/esm/utils/serialization/serialization_v2.js +8 -8
- package/dist/types/api/createProcessor.d.ts +1 -0
- package/dist/types/api/streaming.d.ts +1 -0
- package/dist/types/exports.d.ts +1 -0
- package/dist/types/model/DebuggerTransportSentinel.d.ts +21 -0
- package/dist/types/model/EditorDefinition.d.ts +2 -0
- package/dist/types/model/ExecutorProtocol.d.ts +5 -0
- package/dist/types/model/GraphAbortReasons.d.ts +23 -0
- package/dist/types/model/GraphBoundaryCache.d.ts +27 -0
- package/dist/types/model/GraphPreprocessor.d.ts +3 -1
- package/dist/types/model/GraphProcessor.d.ts +8 -0
- package/dist/types/model/NodeImpl.d.ts +10 -5
- package/dist/types/model/Nodes.d.ts +2 -2
- package/dist/types/model/ProcessContext.d.ts +3 -0
- package/dist/types/model/ProcessContextBuilder.d.ts +4 -20
- package/dist/types/model/SplitRunProcessor.d.ts +8 -3
- package/dist/types/model/nodes/LoopUntilNode.d.ts +5 -4
- package/dist/types/model/nodes/ReferencedGraphAliasNode.d.ts +5 -4
- package/dist/types/model/nodes/SubGraphNode.d.ts +6 -5
- package/dist/types/recording/RecordedEvents.d.ts +4 -0
- package/dist/types/utils/emitDetached.d.ts +2 -2
- package/dist/types/utils/serialization/serializationInput.d.ts +7 -0
- package/package.json +1 -1
|
@@ -19,8 +19,10 @@ export class NodeImpl {
|
|
|
19
19
|
get data() {
|
|
20
20
|
return this.chartNode.data;
|
|
21
21
|
}
|
|
22
|
-
getInputDefinitionsIncludingBuiltIn(connections, nodes, project, referencedProjects) {
|
|
23
|
-
const ports =
|
|
22
|
+
getInputDefinitionsIncludingBuiltIn(connections, nodes, project, referencedProjects, definitionContext) {
|
|
23
|
+
const ports = definitionContext
|
|
24
|
+
? [...this.getInputDefinitions(connections, nodes, project, referencedProjects, definitionContext)]
|
|
25
|
+
: [...this.getInputDefinitions(connections, nodes, project, referencedProjects)];
|
|
24
26
|
if (this.chartNode.isConditional) {
|
|
25
27
|
ports.push(IF_PORT);
|
|
26
28
|
}
|
|
@@ -39,10 +41,10 @@ export class PluginNodeImplClass extends NodeImpl {
|
|
|
39
41
|
super(chartNode);
|
|
40
42
|
this.impl = impl;
|
|
41
43
|
}
|
|
42
|
-
getInputDefinitions(connections, nodes, project) {
|
|
44
|
+
getInputDefinitions(connections, nodes, project, _referencedProjects, _definitionContext) {
|
|
43
45
|
return this.impl.getInputDefinitions(this.data, connections, nodes, project);
|
|
44
46
|
}
|
|
45
|
-
getOutputDefinitions(connections, nodes, project) {
|
|
47
|
+
getOutputDefinitions(connections, nodes, project, _referencedProjects, _definitionContext) {
|
|
46
48
|
return this.impl.getOutputDefinitions(this.data, connections, nodes, project);
|
|
47
49
|
}
|
|
48
50
|
process(inputData, context) {
|
|
@@ -1,33 +1,18 @@
|
|
|
1
1
|
export function buildNodeProcessContext(options) {
|
|
2
|
-
const { attachedData,
|
|
2
|
+
const { attachedData, base, createSubProcessor, execution, externalFunctions, getPluginConfig, node, nodeAbortController, onPartialOutputs, processId, requestUserInput, setGlobal, waitEvent, } = options;
|
|
3
3
|
return {
|
|
4
|
-
...
|
|
4
|
+
...base,
|
|
5
5
|
node,
|
|
6
|
-
tokenizer,
|
|
7
|
-
executor,
|
|
8
|
-
project,
|
|
9
|
-
executionCache,
|
|
10
|
-
graphInputs,
|
|
11
|
-
graphOutputs,
|
|
12
6
|
attachedData,
|
|
13
|
-
codeRunner,
|
|
14
|
-
referencedProjects: loadedProjects,
|
|
15
7
|
waitEvent,
|
|
16
|
-
raiseEvent,
|
|
17
|
-
contextValues,
|
|
18
8
|
externalFunctions: { ...externalFunctions },
|
|
19
9
|
onPartialOutputs,
|
|
20
10
|
signal: nodeAbortController.signal,
|
|
21
11
|
processId,
|
|
22
|
-
getGlobal,
|
|
23
12
|
setGlobal,
|
|
24
|
-
waitForGlobal,
|
|
25
13
|
createSubProcessor: createSubProcessor,
|
|
26
|
-
trace,
|
|
27
|
-
abortGraph,
|
|
28
14
|
getPluginConfig,
|
|
29
15
|
requestUserInput,
|
|
30
|
-
graphInputNodeValues,
|
|
31
16
|
execution,
|
|
32
17
|
};
|
|
33
18
|
}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { getError } from '../utils/errors.js';
|
|
2
2
|
import { nanoid } from 'nanoid/non-secure';
|
|
3
3
|
import { emitDetached } from '../utils/emitDetached.js';
|
|
4
|
+
function withOptionalDuration(payload, durationMs, splitRunDurationMs) {
|
|
5
|
+
return {
|
|
6
|
+
...payload,
|
|
7
|
+
...(durationMs === undefined ? {} : { durationMs }),
|
|
8
|
+
...(splitRunDurationMs === undefined ? {} : { splitRunDurationMs }),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
4
11
|
export async function replayExecutionRecording(options) {
|
|
5
12
|
const { emitter, erroredNodes, graphOutputs, project, recorder, recordingPlaybackChatLatency, setContextValues, setGraphInputs, setGraphOutputs, setRunning, visitedNodes, waitUntilUnpaused, nodeResults, isAborted, } = options;
|
|
6
13
|
const nodesByIdAllGraphs = {};
|
|
@@ -36,6 +43,7 @@ export async function replayExecutionRecording(options) {
|
|
|
36
43
|
try {
|
|
37
44
|
const legacyRootRunId = nanoid();
|
|
38
45
|
const legacyGraphRunsByGraphId = new Map();
|
|
46
|
+
const nodeStartTimestamps = new Map();
|
|
39
47
|
const getExecution = (graphId, recordedExecution) => {
|
|
40
48
|
if (recordedExecution) {
|
|
41
49
|
return recordedExecution;
|
|
@@ -51,6 +59,14 @@ export async function replayExecutionRecording(options) {
|
|
|
51
59
|
rootRunId: legacyRootRunId,
|
|
52
60
|
};
|
|
53
61
|
};
|
|
62
|
+
const getNodeRunKey = (execution, nodeId, processId) => `${execution.rootRunId}:${execution.graphRunId}:${nodeId}:${processId}`;
|
|
63
|
+
const getRecordedDuration = (recordedDuration, execution, nodeId, processId, terminalTs) => {
|
|
64
|
+
if (recordedDuration !== undefined) {
|
|
65
|
+
return recordedDuration;
|
|
66
|
+
}
|
|
67
|
+
const startedAt = nodeStartTimestamps.get(getNodeRunKey(execution, nodeId, processId));
|
|
68
|
+
return startedAt === undefined ? undefined : Math.max(0, terminalTs - startedAt);
|
|
69
|
+
};
|
|
54
70
|
for (const event of recorder.events) {
|
|
55
71
|
if (isAborted()) {
|
|
56
72
|
break;
|
|
@@ -142,11 +158,13 @@ export async function replayExecutionRecording(options) {
|
|
|
142
158
|
case 'nodeStart': {
|
|
143
159
|
const { data } = event;
|
|
144
160
|
const node = getNode(data.nodeId);
|
|
161
|
+
const execution = getExecution(data.execution?.graphId ?? getGraphIdForNode(data.nodeId), data.execution);
|
|
162
|
+
nodeStartTimestamps.set(getNodeRunKey(execution, data.nodeId, data.processId), event.ts);
|
|
145
163
|
emitDetached(emitter, 'nodeStart', {
|
|
146
164
|
node,
|
|
147
165
|
inputs: data.inputs,
|
|
148
166
|
processId: data.processId,
|
|
149
|
-
execution
|
|
167
|
+
execution,
|
|
150
168
|
});
|
|
151
169
|
if (node.type === 'chat') {
|
|
152
170
|
await new Promise((resolve) => setTimeout(resolve, recordingPlaybackChatLatency));
|
|
@@ -156,12 +174,13 @@ export async function replayExecutionRecording(options) {
|
|
|
156
174
|
case 'nodeFinish': {
|
|
157
175
|
const { data } = event;
|
|
158
176
|
const node = getNode(data.nodeId);
|
|
159
|
-
|
|
177
|
+
const execution = getExecution(data.execution?.graphId ?? getGraphIdForNode(data.nodeId), data.execution);
|
|
178
|
+
emitDetached(emitter, 'nodeFinish', withOptionalDuration({
|
|
160
179
|
node,
|
|
161
180
|
outputs: data.outputs,
|
|
162
181
|
processId: data.processId,
|
|
163
|
-
execution
|
|
164
|
-
});
|
|
182
|
+
execution,
|
|
183
|
+
}, getRecordedDuration(data.durationMs, execution, data.nodeId, data.processId, event.ts), data.splitRunDurationMs));
|
|
165
184
|
nodeResults.set(data.nodeId, data.outputs);
|
|
166
185
|
visitedNodes.add(data.nodeId);
|
|
167
186
|
break;
|
|
@@ -169,12 +188,13 @@ export async function replayExecutionRecording(options) {
|
|
|
169
188
|
case 'nodeError': {
|
|
170
189
|
const { data } = event;
|
|
171
190
|
const node = getNode(data.nodeId);
|
|
172
|
-
|
|
191
|
+
const execution = getExecution(data.execution?.graphId ?? getGraphIdForNode(data.nodeId), data.execution);
|
|
192
|
+
emitDetached(emitter, 'nodeError', withOptionalDuration({
|
|
173
193
|
node,
|
|
174
194
|
error: data.error,
|
|
175
195
|
processId: data.processId,
|
|
176
|
-
execution
|
|
177
|
-
});
|
|
196
|
+
execution,
|
|
197
|
+
}, getRecordedDuration(data.durationMs, execution, data.nodeId, data.processId, event.ts), data.splitRunDurationMs));
|
|
178
198
|
erroredNodes.set(data.nodeId, data.error);
|
|
179
199
|
visitedNodes.add(data.nodeId);
|
|
180
200
|
break;
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import { max, range } from 'lodash-es';
|
|
2
2
|
import { isArrayDataValue, arrayizeDataValue, } from './DataValue.js';
|
|
3
3
|
import {} from './NodeBase.js';
|
|
4
|
+
import { getGraphAbortReasonFromError, isAbortLikeError } from './GraphAbortReasons.js';
|
|
4
5
|
import { getError } from '../utils/errors.js';
|
|
5
6
|
import PQueue from '../utils/pQueueCompat.js';
|
|
6
7
|
import { entries, fromEntries, values } from '../utils/typeSafety.js';
|
|
8
|
+
function withOptionalDuration(payload, durationMs, splitRunDurationMs) {
|
|
9
|
+
return {
|
|
10
|
+
...payload,
|
|
11
|
+
...(durationMs === undefined ? {} : { durationMs }),
|
|
12
|
+
...(splitRunDurationMs === undefined ? {} : { splitRunDurationMs }),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
7
15
|
export async function processSplitRunNode(node, processId, deps) {
|
|
8
16
|
const inputValues = deps.getInputValues(node);
|
|
9
17
|
if (deps.isExcludedDueToControlFlow(node, inputValues, processId)) {
|
|
10
18
|
return;
|
|
11
19
|
}
|
|
12
20
|
const splittingAmount = Math.min(max(values(inputValues).map((value) => (Array.isArray(value?.value) ? value?.value.length : 1))) ?? 1, node.splitRunMax ?? 10);
|
|
13
|
-
deps.emit('nodeStart', { node, inputs: inputValues, processId });
|
|
21
|
+
await deps.emit('nodeStart', { node, inputs: inputValues, processId });
|
|
22
|
+
const timingStart = deps.startNodeTiming?.();
|
|
23
|
+
let splitRunDurationMs;
|
|
14
24
|
try {
|
|
15
25
|
let results;
|
|
16
26
|
if (node.isSplitSequential) {
|
|
@@ -19,38 +29,47 @@ export async function processSplitRunNode(node, processId, deps) {
|
|
|
19
29
|
else {
|
|
20
30
|
results = await runParallel(node, inputValues, splittingAmount, processId, deps);
|
|
21
31
|
}
|
|
32
|
+
splitRunDurationMs = getSplitRunDurationMs(results);
|
|
22
33
|
const errors = results.filter((r) => r.type === 'error').map((r) => r.error);
|
|
23
34
|
if (errors.length === 1) {
|
|
24
35
|
throw errors[0];
|
|
25
36
|
}
|
|
26
37
|
else if (errors.length > 0) {
|
|
38
|
+
if (deps.isAborted() && errors.every(isGraphAbortOrAbortLikeError)) {
|
|
39
|
+
throw deps.getAbortError();
|
|
40
|
+
}
|
|
27
41
|
throw new AggregateError(errors);
|
|
28
42
|
}
|
|
29
43
|
const aggregateResults = aggregateOutputs(results);
|
|
30
44
|
deps.setNodeResults(node.id, aggregateResults);
|
|
31
45
|
deps.markNodeVisited(node.id);
|
|
32
|
-
deps.emit('nodeFinish', {
|
|
46
|
+
await deps.emit('nodeFinish', withOptionalDuration({
|
|
47
|
+
node,
|
|
48
|
+
outputs: aggregateResults,
|
|
49
|
+
processId,
|
|
50
|
+
}, deps.finishNodeTiming?.(timingStart), splitRunDurationMs));
|
|
33
51
|
}
|
|
34
52
|
catch (error) {
|
|
35
|
-
deps.nodeErrored(node, error, processId);
|
|
53
|
+
await deps.nodeErrored(node, error, processId, deps.finishNodeTiming?.(timingStart), splitRunDurationMs);
|
|
36
54
|
}
|
|
37
55
|
}
|
|
38
56
|
async function runSequential(node, inputValues, splittingAmount, processId, deps) {
|
|
39
57
|
const results = [];
|
|
40
58
|
for (let i = 0; i < splittingAmount; i++) {
|
|
41
59
|
if (deps.isAborted()) {
|
|
42
|
-
throw
|
|
60
|
+
throw deps.getAbortError();
|
|
43
61
|
}
|
|
44
62
|
const inputs = splitInputsAtIndex(inputValues, i);
|
|
63
|
+
const splitTimingStart = deps.startNodeTiming?.();
|
|
45
64
|
try {
|
|
46
65
|
const output = await deps.processNodeWithInputData(node, inputs, i, processId, (n, partialOutputs, index) => {
|
|
47
66
|
deps.emit('partialOutput', { node: n, outputs: partialOutputs, index, processId });
|
|
48
67
|
});
|
|
49
68
|
deps.accumulateCost(output);
|
|
50
|
-
results.push({ type: 'output', output });
|
|
69
|
+
results.push({ type: 'output', output, durationMs: deps.finishNodeTiming?.(splitTimingStart) });
|
|
51
70
|
}
|
|
52
71
|
catch (error) {
|
|
53
|
-
results.push({ type: 'error', error: getError(error) });
|
|
72
|
+
results.push({ type: 'error', error: getError(error), durationMs: deps.finishNodeTiming?.(splitTimingStart) });
|
|
54
73
|
}
|
|
55
74
|
}
|
|
56
75
|
return results;
|
|
@@ -59,16 +78,24 @@ async function runParallel(node, inputValues, splittingAmount, processId, deps)
|
|
|
59
78
|
const queue = new PQueue({ concurrency: getParallelSplitRunConcurrency(node, deps.splitRunConcurrency) });
|
|
60
79
|
return Promise.all(range(0, splittingAmount).map(async (i) => {
|
|
61
80
|
const result = await queue.add(async () => {
|
|
62
|
-
const
|
|
81
|
+
const splitTimingStart = deps.startNodeTiming?.();
|
|
63
82
|
try {
|
|
83
|
+
if (deps.isAborted()) {
|
|
84
|
+
throw deps.getAbortError();
|
|
85
|
+
}
|
|
86
|
+
const inputs = splitInputsAtIndex(inputValues, i);
|
|
64
87
|
const output = await deps.processNodeWithInputData(node, inputs, i, processId, (n, partialOutputs, index) => {
|
|
65
88
|
deps.emit('partialOutput', { node: n, outputs: partialOutputs, index, processId });
|
|
66
89
|
});
|
|
67
90
|
deps.accumulateCost(output);
|
|
68
|
-
return { type: 'output', output };
|
|
91
|
+
return { type: 'output', output, durationMs: deps.finishNodeTiming?.(splitTimingStart) };
|
|
69
92
|
}
|
|
70
93
|
catch (error) {
|
|
71
|
-
return {
|
|
94
|
+
return {
|
|
95
|
+
type: 'error',
|
|
96
|
+
error: getError(error),
|
|
97
|
+
durationMs: deps.finishNodeTiming?.(splitTimingStart),
|
|
98
|
+
};
|
|
72
99
|
}
|
|
73
100
|
});
|
|
74
101
|
if (!result) {
|
|
@@ -96,3 +123,15 @@ function aggregateOutputs(results) {
|
|
|
96
123
|
return acc;
|
|
97
124
|
}, {});
|
|
98
125
|
}
|
|
126
|
+
function getSplitRunDurationMs(results) {
|
|
127
|
+
const durations = {};
|
|
128
|
+
for (const [index, result] of results.entries()) {
|
|
129
|
+
if (result.durationMs !== undefined) {
|
|
130
|
+
durations[index] = result.durationMs;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return Object.keys(durations).length > 0 ? durations : undefined;
|
|
134
|
+
}
|
|
135
|
+
function isGraphAbortOrAbortLikeError(error) {
|
|
136
|
+
return getGraphAbortReasonFromError(error) != null || isAbortLikeError(error);
|
|
137
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getGraphAbortReasonFromSignal } from './GraphAbortReasons.js';
|
|
1
2
|
function subscribeOwnGraphRunLifecycle(processor, onLifecycleEvent) {
|
|
2
3
|
let ownGraphRunId;
|
|
3
4
|
const unsubscribeGraphStart = processor.on('graphStart', (event) => {
|
|
@@ -19,20 +20,24 @@ function subscribeOwnGraphRunLifecycle(processor, onLifecycleEvent) {
|
|
|
19
20
|
};
|
|
20
21
|
}
|
|
21
22
|
export function wireSubprocessorEvents(processor, parentEmitter, parentState) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
// Some successful graph-abort paths can emit node terminals just after their
|
|
24
|
+
// graph-level terminal event. Keep passive forwarding alive for the
|
|
25
|
+
// subprocessor object lifetime so remote-debugger/recorder consumers do not
|
|
26
|
+
// miss those node terminals.
|
|
27
|
+
processor.on('nodeError', (event) => parentEmitter.emit('nodeError', event));
|
|
28
|
+
processor.on('nodeFinish', (event) => parentEmitter.emit('nodeFinish', event));
|
|
29
|
+
processor.on('partialOutput', (event) => parentEmitter.emit('partialOutput', event));
|
|
30
|
+
processor.on('nodeExcluded', (event) => parentEmitter.emit('nodeExcluded', event));
|
|
31
|
+
processor.on('nodeStart', (event) => parentEmitter.emit('nodeStart', event));
|
|
32
|
+
processor.on('graphAbort', (event) => parentEmitter.emit('graphAbort', event));
|
|
33
|
+
processor.on('graphError', (event) => parentEmitter.emit('graphError', event));
|
|
34
|
+
processor.on('userInput', (event) => parentEmitter.emit('userInput', event));
|
|
35
|
+
processor.on('graphStart', (event) => parentEmitter.emit('graphStart', event));
|
|
36
|
+
processor.on('graphFinish', (event) => parentEmitter.emit('graphFinish', event));
|
|
37
|
+
processor.on('nodeOutputsCleared', (event) => parentEmitter.emit('nodeOutputsCleared', event));
|
|
38
|
+
processor.on('globalSet', (event) => parentEmitter.emit('globalSet', event));
|
|
39
|
+
processor.on('newAbortController', (event) => parentEmitter.emit('newAbortController', event));
|
|
40
|
+
const controlUnsubscribers = [
|
|
36
41
|
processor.on('pause', () => {
|
|
37
42
|
if (!parentState.isPaused()) {
|
|
38
43
|
parentState.pause();
|
|
@@ -44,27 +49,29 @@ export function wireSubprocessorEvents(processor, parentEmitter, parentState) {
|
|
|
44
49
|
}
|
|
45
50
|
}),
|
|
46
51
|
];
|
|
47
|
-
|
|
52
|
+
processor.onAny((event, data) => {
|
|
48
53
|
if (event.startsWith('globalSet:')) {
|
|
49
54
|
void parentEmitter.emit(event, data);
|
|
50
55
|
}
|
|
51
56
|
});
|
|
52
|
-
let
|
|
53
|
-
const
|
|
54
|
-
if (
|
|
57
|
+
let controlsCleanedUp = false;
|
|
58
|
+
const cleanupControls = () => {
|
|
59
|
+
if (controlsCleanedUp) {
|
|
55
60
|
return;
|
|
56
61
|
}
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
controlsCleanedUp = true;
|
|
63
|
+
controlUnsubscribers.forEach((unsubscribe) => unsubscribe());
|
|
59
64
|
};
|
|
60
|
-
|
|
65
|
+
controlUnsubscribers.push(subscribeOwnGraphRunLifecycle(processor, cleanupControls));
|
|
61
66
|
}
|
|
62
67
|
export function wireSubprocessorLifecycle(processor, options) {
|
|
63
68
|
const abortFromSignal = () => {
|
|
64
|
-
|
|
69
|
+
const abortReason = getGraphAbortReasonFromSignal(options.signal);
|
|
70
|
+
void processor.abort(abortReason?.successful ?? false, abortReason?.error);
|
|
65
71
|
};
|
|
66
72
|
const abortFromParent = () => {
|
|
67
|
-
|
|
73
|
+
const abortReason = getGraphAbortReasonFromSignal(options.parentAbortSignal);
|
|
74
|
+
void processor.abort(abortReason?.successful ?? false, abortReason?.error);
|
|
68
75
|
};
|
|
69
76
|
const pauseProcessor = () => {
|
|
70
77
|
void processor.pause();
|
|
@@ -22,9 +22,9 @@ export class GetGlobalNodeImpl extends NodeImpl {
|
|
|
22
22
|
data: {
|
|
23
23
|
id: 'variable-name',
|
|
24
24
|
dataType: 'string',
|
|
25
|
-
onDemand:
|
|
25
|
+
onDemand: false,
|
|
26
26
|
useIdInput: false,
|
|
27
|
-
wait:
|
|
27
|
+
wait: true,
|
|
28
28
|
},
|
|
29
29
|
};
|
|
30
30
|
return chartNode;
|
|
@@ -35,7 +35,7 @@ export class GetGlobalNodeImpl extends NodeImpl {
|
|
|
35
35
|
{
|
|
36
36
|
id: 'id',
|
|
37
37
|
title: 'Variable ID',
|
|
38
|
-
dataType:
|
|
38
|
+
dataType: 'string',
|
|
39
39
|
},
|
|
40
40
|
];
|
|
41
41
|
}
|
|
@@ -58,11 +58,18 @@ export class GetGlobalNodeImpl extends NodeImpl {
|
|
|
58
58
|
}
|
|
59
59
|
getEditors() {
|
|
60
60
|
return [
|
|
61
|
+
{
|
|
62
|
+
type: 'custom',
|
|
63
|
+
label: 'Search Global Variables',
|
|
64
|
+
customEditorId: 'GetGlobalVariableSelector',
|
|
65
|
+
autoFocus: true,
|
|
66
|
+
},
|
|
61
67
|
{
|
|
62
68
|
type: 'string',
|
|
63
69
|
label: 'Variable ID',
|
|
64
70
|
dataKey: 'id',
|
|
65
71
|
useInputToggleDataKey: 'useIdInput',
|
|
72
|
+
includeInGraphSearch: true,
|
|
66
73
|
},
|
|
67
74
|
{
|
|
68
75
|
type: 'dataTypeSelector',
|
|
@@ -73,11 +80,13 @@ export class GetGlobalNodeImpl extends NodeImpl {
|
|
|
73
80
|
type: 'toggle',
|
|
74
81
|
label: 'On Demand',
|
|
75
82
|
dataKey: 'onDemand',
|
|
83
|
+
turnOffDataKeysWhenEnabled: ['wait'],
|
|
76
84
|
},
|
|
77
85
|
{
|
|
78
86
|
type: 'toggle',
|
|
79
87
|
label: 'Wait',
|
|
80
88
|
dataKey: 'wait',
|
|
89
|
+
turnOffDataKeysWhenEnabled: ['onDemand'],
|
|
81
90
|
},
|
|
82
91
|
];
|
|
83
92
|
}
|
|
@@ -103,11 +112,11 @@ export class GetGlobalNodeImpl extends NodeImpl {
|
|
|
103
112
|
if (this.data.wait) {
|
|
104
113
|
throw new Error('Cannot use onDemand and wait together');
|
|
105
114
|
}
|
|
115
|
+
const id = this.data.useIdInput ? coerceType(inputs['id'], 'string') : this.data.id;
|
|
106
116
|
return {
|
|
107
117
|
['value']: {
|
|
108
118
|
type: `fn<${this.data.dataType}>`,
|
|
109
119
|
value: () => {
|
|
110
|
-
const id = this.data.useIdInput ? coerceType(inputs['id'], 'string') : this.data.id;
|
|
111
120
|
const value = context.getGlobal(id);
|
|
112
121
|
if (value) {
|
|
113
122
|
return value.value;
|
|
@@ -119,6 +128,7 @@ export class GetGlobalNodeImpl extends NodeImpl {
|
|
|
119
128
|
return scalarDefaults[this.data.dataType];
|
|
120
129
|
},
|
|
121
130
|
},
|
|
131
|
+
['variable_id_out']: { type: 'string', value: id },
|
|
122
132
|
};
|
|
123
133
|
}
|
|
124
134
|
const id = this.data.useIdInput ? coerceType(inputs['id'], 'string') : this.data.id;
|
|
@@ -8,6 +8,34 @@ import {} from '../ProcessContext.js';
|
|
|
8
8
|
import { dedent } from 'ts-dedent';
|
|
9
9
|
import {} from '../EditorDefinition.js';
|
|
10
10
|
import {} from '../NodeBodySpec.js';
|
|
11
|
+
function isPlainObjectRecordValue(value) {
|
|
12
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const prototype = Object.getPrototypeOf(value);
|
|
16
|
+
return prototype === Object.prototype || prototype === null;
|
|
17
|
+
}
|
|
18
|
+
function coerceAnyGraphOutputValue(value, dataType) {
|
|
19
|
+
if (value.type === 'control-flow-excluded' || dataType === 'any' || value.type === dataType) {
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
if (value.type !== 'any') {
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
if (dataType === 'object' && isPlainObjectRecordValue(value.value)) {
|
|
26
|
+
return {
|
|
27
|
+
type: 'object',
|
|
28
|
+
value: value.value,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (dataType === 'object[]' && Array.isArray(value.value) && value.value.every(isPlainObjectRecordValue)) {
|
|
32
|
+
return {
|
|
33
|
+
type: 'object[]',
|
|
34
|
+
value: value.value,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
11
39
|
export class GraphOutputNodeImpl extends NodeImpl {
|
|
12
40
|
static create() {
|
|
13
41
|
const chartNode = {
|
|
@@ -75,7 +103,8 @@ export class GraphOutputNodeImpl extends NodeImpl {
|
|
|
75
103
|
};
|
|
76
104
|
}
|
|
77
105
|
async process(inputs, context) {
|
|
78
|
-
const
|
|
106
|
+
const inputValue = inputs['value'];
|
|
107
|
+
const value = coerceAnyGraphOutputValue(inputValue ?? { type: 'any', value: undefined }, this.data.dataType);
|
|
79
108
|
const isExcluded = value.type === 'control-flow-excluded';
|
|
80
109
|
if (isExcluded && context.graphOutputs[this.data.id] == null) {
|
|
81
110
|
context.graphOutputs[this.data.id] = {
|
|
@@ -85,7 +114,7 @@ export class GraphOutputNodeImpl extends NodeImpl {
|
|
|
85
114
|
}
|
|
86
115
|
else if ((context.graphOutputs[this.data.id] == null ||
|
|
87
116
|
context.graphOutputs[this.data.id]?.type === 'control-flow-excluded') &&
|
|
88
|
-
|
|
117
|
+
inputValue) {
|
|
89
118
|
context.graphOutputs[this.data.id] = value;
|
|
90
119
|
}
|
|
91
120
|
if (isExcluded) {
|
|
@@ -5,12 +5,11 @@ import {} from '../GraphProcessor.js';
|
|
|
5
5
|
import {} from '../NodeGraph.js';
|
|
6
6
|
import { nanoid } from 'nanoid/non-secure';
|
|
7
7
|
import {} from '../Project.js';
|
|
8
|
-
import {} from './GraphInputNode.js';
|
|
9
|
-
import {} from './GraphOutputNode.js';
|
|
10
8
|
import {} from '../DataValue.js';
|
|
11
9
|
import {} from '../ProcessContext.js';
|
|
12
10
|
import {} from '../EditorDefinition.js';
|
|
13
11
|
import { dedent } from 'ts-dedent';
|
|
12
|
+
import { getGraphBoundary, getGraphBoundaryInputDefinitions, getGraphBoundaryOutputDefinitions, } from '../GraphBoundaryCache.js';
|
|
14
13
|
export class LoopUntilNodeImpl extends NodeImpl {
|
|
15
14
|
static create() {
|
|
16
15
|
const chartNode = {
|
|
@@ -29,40 +28,13 @@ export class LoopUntilNodeImpl extends NodeImpl {
|
|
|
29
28
|
};
|
|
30
29
|
return chartNode;
|
|
31
30
|
}
|
|
32
|
-
getInputDefinitions(_connections, _nodes, project) {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
const graph = project.graphs[this.data.targetGraph ?? ''];
|
|
36
|
-
if (graph) {
|
|
37
|
-
const inputNodes = graph.nodes.filter((node) => node.type === 'graphInput');
|
|
38
|
-
const inputIds = [...new Set(inputNodes.map((node) => node.data.id))].sort();
|
|
39
|
-
inputIds.forEach((id) => {
|
|
40
|
-
const inputNode = inputNodes.find((node) => node.data.id === id);
|
|
41
|
-
inputs.push({
|
|
42
|
-
id: id,
|
|
43
|
-
title: id,
|
|
44
|
-
dataType: inputNode.data.dataType,
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
return inputs;
|
|
31
|
+
getInputDefinitions(_connections, _nodes, project, _referencedProjects, definitionContext) {
|
|
32
|
+
const boundary = this.getBoundary(project, definitionContext);
|
|
33
|
+
return boundary ? getGraphBoundaryInputDefinitions(boundary) : [];
|
|
49
34
|
}
|
|
50
|
-
getOutputDefinitions(_connections, _nodes, project) {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
const graph = project.graphs[this.data.targetGraph ?? ''];
|
|
54
|
-
if (graph) {
|
|
55
|
-
const outputNodes = graph.nodes.filter((node) => node.type === 'graphOutput');
|
|
56
|
-
const outputIds = [...new Set(outputNodes.map((node) => node.data.id))].sort();
|
|
57
|
-
outputIds.forEach((id) => {
|
|
58
|
-
const outputNode = outputNodes.find((node) => node.data.id === id);
|
|
59
|
-
outputs.push({
|
|
60
|
-
id: id,
|
|
61
|
-
title: id,
|
|
62
|
-
dataType: outputNode.data.dataType,
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
}
|
|
35
|
+
getOutputDefinitions(_connections, _nodes, project, _referencedProjects, definitionContext) {
|
|
36
|
+
const boundary = this.getBoundary(project, definitionContext);
|
|
37
|
+
const outputs = boundary ? getGraphBoundaryOutputDefinitions(boundary) : [];
|
|
66
38
|
// Add standard loop outputs
|
|
67
39
|
outputs.push({
|
|
68
40
|
id: 'iteration',
|
|
@@ -117,19 +89,16 @@ export class LoopUntilNodeImpl extends NodeImpl {
|
|
|
117
89
|
}
|
|
118
90
|
// Add dynamic editors for graph inputs
|
|
119
91
|
if (this.data.targetGraph) {
|
|
120
|
-
const
|
|
121
|
-
if (
|
|
122
|
-
const
|
|
123
|
-
const inputIds = [...new Set(inputNodes.map((node) => node.data.id))].sort();
|
|
124
|
-
for (const inputId of inputIds) {
|
|
125
|
-
const inputNode = inputNodes.find((node) => node.data.id === inputId);
|
|
92
|
+
const boundary = getGraphBoundary(context.project, this.data.targetGraph);
|
|
93
|
+
if (boundary) {
|
|
94
|
+
for (const input of boundary.inputs) {
|
|
126
95
|
definitions.push({
|
|
127
96
|
type: 'dynamic',
|
|
128
97
|
dataKey: 'inputData',
|
|
129
|
-
dynamicDataKey:
|
|
130
|
-
dataType:
|
|
131
|
-
label:
|
|
132
|
-
editor:
|
|
98
|
+
dynamicDataKey: input.id,
|
|
99
|
+
dataType: input.dataType,
|
|
100
|
+
label: input.id,
|
|
101
|
+
editor: input.editor ?? 'auto',
|
|
133
102
|
});
|
|
134
103
|
}
|
|
135
104
|
}
|
|
@@ -159,6 +128,10 @@ export class LoopUntilNodeImpl extends NodeImpl {
|
|
|
159
128
|
const maxIterations = this.data.maxIterations ? `\nMax iterations: ${this.data.maxIterations}` : '';
|
|
160
129
|
return `Executes ${graphName}\nuntil ${condition}${maxIterations}`;
|
|
161
130
|
}
|
|
131
|
+
getBoundary(project, definitionContext) {
|
|
132
|
+
return (definitionContext?.getGraphBoundary(project, this.data.targetGraph) ??
|
|
133
|
+
getGraphBoundary(project, this.data.targetGraph));
|
|
134
|
+
}
|
|
162
135
|
shouldBreak(outputs) {
|
|
163
136
|
if (this.data.conditionType === 'allOutputsSet') {
|
|
164
137
|
// Check if any output is control-flow-excluded
|