@valerypopoff/rivet2-core 2.8.0 → 2.10.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/cjs/bundle.cjs +508 -320
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/cjs/interpolationRuntime.cjs.map +2 -2
- package/dist/esm/model/GraphPreprocessor.js +11 -0
- package/dist/esm/model/GraphProcessor.js +60 -3
- package/dist/esm/model/LegacyChatEditorCache.js +50 -0
- package/dist/esm/model/NodeExclusionPolicy.js +1 -0
- package/dist/esm/model/Nodes.js +6 -0
- package/dist/esm/model/StreamingOutputWatch.js +18 -18
- package/dist/esm/model/chat-v2/chatV2Shared.js +2 -1
- package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +2 -1
- package/dist/esm/model/nodes/ChatNodeBase.js +18 -13
- package/dist/esm/model/nodes/CoalesceNewNode.js +22 -0
- package/dist/esm/model/nodes/CoalesceNode.js +15 -133
- package/dist/esm/model/nodes/CoalesceNodeBase.js +131 -0
- package/dist/esm/model/nodes/GraphCallPathNode.js +42 -0
- package/dist/esm/model/nodes/StopWatchingStreamingOutputNode.js +2 -0
- package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +17 -15
- package/dist/esm/plugins/google/google.js +8 -128
- package/dist/esm/plugins/google/googleGenerativeAi.js +101 -0
- package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +36 -15
- package/dist/types/model/GraphPreprocessor.d.ts +2 -0
- package/dist/types/model/GraphProcessor.d.ts +3 -1
- package/dist/types/model/LegacyChatEditorCache.d.ts +39 -0
- package/dist/types/model/Nodes.d.ts +4 -2
- package/dist/types/model/ProcessContext.d.ts +2 -0
- package/dist/types/model/StreamingOutputWatch.d.ts +13 -11
- package/dist/types/model/chat-v2/chatV2Shared.d.ts +1 -0
- package/dist/types/model/nodes/CoalesceNewNode.d.ts +10 -0
- package/dist/types/model/nodes/CoalesceNode.d.ts +9 -15
- package/dist/types/model/nodes/CoalesceNodeBase.d.ts +19 -0
- package/dist/types/model/nodes/GraphCallPathNode.d.ts +12 -0
- package/dist/types/plugins/google/google.d.ts +3 -110
- package/dist/types/plugins/google/googleGenerativeAi.d.ts +110 -0
- package/package.json +1 -1
|
@@ -36,6 +36,7 @@ export function preprocessGraphState(options) {
|
|
|
36
36
|
connections[connection.outputNodeId].push(connection);
|
|
37
37
|
}
|
|
38
38
|
const definitions = loadInputOutputDefinitions({
|
|
39
|
+
inputAnchorDefinitions: options.inputAnchorDefinitions,
|
|
39
40
|
connections,
|
|
40
41
|
loadedProjects,
|
|
41
42
|
nodeInstances,
|
|
@@ -102,6 +103,11 @@ function loadInputOutputDefinitions(options) {
|
|
|
102
103
|
const definitions = {};
|
|
103
104
|
if (!definitionContext) {
|
|
104
105
|
for (const node of values(nodesById)) {
|
|
106
|
+
const anchorDefinitions = options.inputAnchorDefinitions?.[node.id];
|
|
107
|
+
if (anchorDefinitions) {
|
|
108
|
+
definitions[node.id] = anchorDefinitions;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
105
111
|
const connectionsForNode = connections[node.id] ?? [];
|
|
106
112
|
const inputDefinitions = nodeInstances[node.id].getInputDefinitionsIncludingBuiltIn(connectionsForNode, nodesById, project, loadedProjects);
|
|
107
113
|
const outputDefinitions = nodeInstances[node.id].getOutputDefinitions(connectionsForNode, nodesById, project, loadedProjects);
|
|
@@ -144,6 +150,11 @@ function loadInputOutputDefinitions(options) {
|
|
|
144
150
|
return definitions;
|
|
145
151
|
}
|
|
146
152
|
for (const node of values(nodesById)) {
|
|
153
|
+
const anchorDefinitions = options.inputAnchorDefinitions?.[node.id];
|
|
154
|
+
if (anchorDefinitions) {
|
|
155
|
+
definitions[node.id] = anchorDefinitions;
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
147
158
|
const connectionsForNode = connections[node.id] ?? [];
|
|
148
159
|
const nodeDefinitionContext = usesGraphBoundaryDefinitionContext(node) ? definitionContext : undefined;
|
|
149
160
|
const inputDefinitions = nodeDefinitionContext
|
|
@@ -43,6 +43,7 @@ import { loadProjectReferenceTree } from './ProjectReferenceLoader.js';
|
|
|
43
43
|
import { IsomorphicCodeRunner } from '../integrations/CodeRunner.js';
|
|
44
44
|
const graphProcessorGraphOverride = Symbol('graphProcessorGraphOverride');
|
|
45
45
|
const consumedAsyncBranchTriggerOverride = Symbol('consumedAsyncBranchTriggerOverride');
|
|
46
|
+
const asyncBranchInputAnchorsOverride = Symbol('asyncBranchInputAnchorsOverride');
|
|
46
47
|
const consumedStreamingWatchNodeOverride = Symbol('consumedStreamingWatchNodeOverride');
|
|
47
48
|
/**
|
|
48
49
|
* These nodes expose a child graph's named Graph Output ports verbatim. Other
|
|
@@ -154,6 +155,7 @@ function replaceRecordContents(target, source) {
|
|
|
154
155
|
export class GraphProcessor {
|
|
155
156
|
// Per-instance state
|
|
156
157
|
#graph;
|
|
158
|
+
#graphCallPath;
|
|
157
159
|
#project;
|
|
158
160
|
#nodesById;
|
|
159
161
|
#nodeInstances;
|
|
@@ -177,6 +179,7 @@ export class GraphProcessor {
|
|
|
177
179
|
#effectiveConnectionsForRun;
|
|
178
180
|
#asyncBranchPlansByTriggerNodeId = new Map();
|
|
179
181
|
#consumedAsyncBranchTriggerNodeId;
|
|
182
|
+
#asyncBranchInputAnchors;
|
|
180
183
|
#streamingWatchPlansBySourceNodeId = new Map();
|
|
181
184
|
#streamingWatchPlansByWatchNodeId = new Map();
|
|
182
185
|
#streamingOutputWatches = new Map();
|
|
@@ -225,6 +228,11 @@ export class GraphProcessor {
|
|
|
225
228
|
#graphOutputs = undefined;
|
|
226
229
|
#executionCache = undefined;
|
|
227
230
|
#queuedNodes = undefined;
|
|
231
|
+
/**
|
|
232
|
+
* Nodes deferred only because Run To reached its initial scheduler quiescence.
|
|
233
|
+
* A streaming Stop can legitimately resume one of those selected paths later.
|
|
234
|
+
*/
|
|
235
|
+
#deferredRunToIgnoredNodes = undefined;
|
|
228
236
|
#loopControllersSeen = undefined;
|
|
229
237
|
#subprocessors = undefined;
|
|
230
238
|
#contextValues = undefined;
|
|
@@ -316,6 +324,7 @@ export class GraphProcessor {
|
|
|
316
324
|
throw new Error(`Graph ${graphId} not found in project`);
|
|
317
325
|
}
|
|
318
326
|
this.#graph = graph;
|
|
327
|
+
this.#graphCallPath = Object.freeze([graph.metadata?.name || '(Unnamed Graph)']);
|
|
319
328
|
this.#includeTrace = includeTrace;
|
|
320
329
|
this.#nodeInstances = {};
|
|
321
330
|
this.#connections = {};
|
|
@@ -329,6 +338,7 @@ export class GraphProcessor {
|
|
|
329
338
|
this.#runtimeProfiler = options?.runtimeProfiler;
|
|
330
339
|
this.#captureNodeTimings = options?.captureNodeTimings ?? false;
|
|
331
340
|
this.#consumedAsyncBranchTriggerNodeId = options?.[consumedAsyncBranchTriggerOverride];
|
|
341
|
+
this.#asyncBranchInputAnchors = options?.[asyncBranchInputAnchorsOverride];
|
|
332
342
|
this.#consumedStreamingWatchNodeId = options?.[consumedStreamingWatchNodeOverride];
|
|
333
343
|
this.#emitter.bindMethods(this, ['on', 'off', 'once', 'onAny', 'offAny']);
|
|
334
344
|
this.setExternalFunction('echo', async (value) => ({ type: 'any', value }));
|
|
@@ -354,6 +364,7 @@ export class GraphProcessor {
|
|
|
354
364
|
return;
|
|
355
365
|
}
|
|
356
366
|
const preprocessedGraph = preprocessGraphState({
|
|
367
|
+
inputAnchorDefinitions: this.#asyncBranchInputAnchors,
|
|
357
368
|
graph: this.#graph,
|
|
358
369
|
loadedProjects: this.#loadedProjects,
|
|
359
370
|
project: this.#project,
|
|
@@ -691,6 +702,7 @@ export class GraphProcessor {
|
|
|
691
702
|
this.#graphOutputs = this.#sharedRunStateOverride?.graphOutputs ?? {};
|
|
692
703
|
this.#executionCache ??= new Map();
|
|
693
704
|
this.#queuedNodes = new Set();
|
|
705
|
+
this.#deferredRunToIgnoredNodes = new Set();
|
|
694
706
|
this.#connectedToolContinuationHost.reset();
|
|
695
707
|
this.#continuationCompletionOwnerByNodeId = new Map();
|
|
696
708
|
this.#effectiveConnectionsForRun = undefined;
|
|
@@ -921,6 +933,7 @@ export class GraphProcessor {
|
|
|
921
933
|
graphInputNodeValues: this.#graphInputNodeValues,
|
|
922
934
|
graphInputs: this.#graphInputs,
|
|
923
935
|
graphOutputs: this.#graphOutputs,
|
|
936
|
+
graphCallPath: this.#graphCallPath,
|
|
924
937
|
onChatV2CallFinished: (event) => {
|
|
925
938
|
try {
|
|
926
939
|
const observerResult = hostChatV2Observer?.(event);
|
|
@@ -1190,8 +1203,9 @@ export class GraphProcessor {
|
|
|
1190
1203
|
return;
|
|
1191
1204
|
}
|
|
1192
1205
|
for (const node of this.#executionGraphNodes) {
|
|
1193
|
-
if (this.#queuedNodes.has(node.id) === false) {
|
|
1206
|
+
if (this.#queuedNodes.has(node.id) === false && !this.#ignoreNodes.has(node.id)) {
|
|
1194
1207
|
this.#ignoreNodes.add(node.id);
|
|
1208
|
+
this.#deferredRunToIgnoredNodes.add(node.id);
|
|
1195
1209
|
}
|
|
1196
1210
|
}
|
|
1197
1211
|
}
|
|
@@ -1578,6 +1592,12 @@ export class GraphProcessor {
|
|
|
1578
1592
|
const selectedOutputs = this.#graphOutputSelection
|
|
1579
1593
|
? outputNodes.filter((outputNode) => this.#isNodeSelected(outputNode.id))
|
|
1580
1594
|
: outputNodes;
|
|
1595
|
+
const relevantNodeIds = this.#getExecutionRelevantNodeIds();
|
|
1596
|
+
for (const outputNode of selectedOutputs) {
|
|
1597
|
+
if (relevantNodeIds?.has(outputNode.id) && this.#deferredRunToIgnoredNodes.delete(outputNode.id)) {
|
|
1598
|
+
this.#ignoreNodes.delete(outputNode.id);
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1581
1601
|
void this.#processingQueue.addAll(selectedOutputs.map((outputNode) => async () => {
|
|
1582
1602
|
this.#emitTraceEvent(`Trying to run output node from ${node.title}: ${outputNode.title} (${outputNode.id})`);
|
|
1583
1603
|
await this.#processNodeIfAllInputsAvailable(outputNode);
|
|
@@ -1647,6 +1667,9 @@ export class GraphProcessor {
|
|
|
1647
1667
|
scheduler: this.#scheduler,
|
|
1648
1668
|
[graphProcessorGraphOverride]: plan.graph,
|
|
1649
1669
|
[consumedAsyncBranchTriggerOverride]: triggerNode.id,
|
|
1670
|
+
[asyncBranchInputAnchorsOverride]: Object.fromEntries(plan.graph.connections
|
|
1671
|
+
.filter((connection) => connection.inputNodeId === triggerNode.id)
|
|
1672
|
+
.map((connection) => [connection.outputNodeId, this.#definitions[connection.outputNodeId]])),
|
|
1650
1673
|
});
|
|
1651
1674
|
onProcessorCreated(processor);
|
|
1652
1675
|
processor.executor = this.executor;
|
|
@@ -1655,6 +1678,7 @@ export class GraphProcessor {
|
|
|
1655
1678
|
processor.#externalFunctions = this.#externalFunctions;
|
|
1656
1679
|
processor.#contextValues = this.#contextValues;
|
|
1657
1680
|
processor.#parent = sameGraphOwner;
|
|
1681
|
+
processor.#graphCallPath = this.#graphCallPath;
|
|
1658
1682
|
processor.#abortOwnerOverride = root;
|
|
1659
1683
|
processor.#suppressGraphPartialOutputs = true;
|
|
1660
1684
|
processor.#globals = this.#globals;
|
|
@@ -2357,6 +2381,7 @@ export class GraphProcessor {
|
|
|
2357
2381
|
processor.#externalFunctions = this.#externalFunctions;
|
|
2358
2382
|
processor.#contextValues = this.#contextValues;
|
|
2359
2383
|
processor.#parent = this;
|
|
2384
|
+
processor.#graphCallPath = this.#graphCallPath;
|
|
2360
2385
|
processor.#abortOwnerOverride = this.#abortOwnerOverride ?? this;
|
|
2361
2386
|
processor.#sameGraphRunOwnerOverride = this.#sameGraphRunOwnerOverride ?? this;
|
|
2362
2387
|
processor.#globals = this.#globals;
|
|
@@ -2649,12 +2674,13 @@ export class GraphProcessor {
|
|
|
2649
2674
|
nextUpdateIndex: 0,
|
|
2650
2675
|
history: new StreamingOutputWatchHistory(),
|
|
2651
2676
|
historySummaryEmitted: false,
|
|
2677
|
+
unmatchedStopResolved: false,
|
|
2652
2678
|
};
|
|
2653
2679
|
const plans = this.#streamingWatchPlansBySourceNodeId.get(sourceNode.id) ?? [];
|
|
2654
2680
|
plans.push(plan);
|
|
2655
2681
|
this.#streamingWatchPlansBySourceNodeId.set(sourceNode.id, plans);
|
|
2656
2682
|
this.#streamingWatchPlansByWatchNodeId.set(watchNode.id, plan);
|
|
2657
|
-
const watch = new StreamingOutputWatch(watchNode.data, (snapshot, registerCancel) => this.#runStreamingOutputWatchInvocation(plan, snapshot, registerCancel), (error) => this.#recordStreamingWatchFailure(watchNode, error)
|
|
2683
|
+
const watch = new StreamingOutputWatch(watchNode.data, (snapshot, registerCancel) => this.#runStreamingOutputWatchInvocation(plan, snapshot, registerCancel), (error) => this.#recordStreamingWatchFailure(watchNode, error));
|
|
2658
2684
|
this.#streamingOutputWatches.set(watchNode.id, watch);
|
|
2659
2685
|
for (const nodeId of [watchNode.id, ...branchNodeIds]) {
|
|
2660
2686
|
this.#ignoreNodes.add(nodeId);
|
|
@@ -2944,6 +2970,7 @@ export class GraphProcessor {
|
|
|
2944
2970
|
processor.#externalFunctions = this.#externalFunctions;
|
|
2945
2971
|
processor.#contextValues = this.#contextValues;
|
|
2946
2972
|
processor.#parent = this;
|
|
2973
|
+
processor.#graphCallPath = this.#graphCallPath;
|
|
2947
2974
|
processor.#abortOwnerOverride = root;
|
|
2948
2975
|
processor.#suppressGraphPartialOutputs = true;
|
|
2949
2976
|
processor.#globals = this.#globals;
|
|
@@ -3104,7 +3131,10 @@ export class GraphProcessor {
|
|
|
3104
3131
|
return [...this.#streamingOutputWatches.values()].some((watch) => watch.hasPending);
|
|
3105
3132
|
}
|
|
3106
3133
|
#hasUnresolvedForegroundOutputStreamingWatch() {
|
|
3107
|
-
return [...this.#streamingOutputWatches
|
|
3134
|
+
return [...this.#streamingOutputWatches].some(([watchNodeId, watch]) => {
|
|
3135
|
+
const plan = this.#streamingWatchPlansByWatchNodeId.get(watchNodeId);
|
|
3136
|
+
return plan?.stopNodeId != null && !plan.unmatchedStopResolved && !watch.stopped;
|
|
3137
|
+
});
|
|
3108
3138
|
}
|
|
3109
3139
|
#hasDrainableStreamingOutputWatches() {
|
|
3110
3140
|
return [...this.#streamingOutputWatches.values()].some((watch) => watch.hasPending && !watch.isAwaitingProducer);
|
|
@@ -3127,6 +3157,11 @@ export class GraphProcessor {
|
|
|
3127
3157
|
// work after the compatible scheduler has returned, so wait for that work
|
|
3128
3158
|
// before deciding every Watch boundary is quiet.
|
|
3129
3159
|
await this.#processingQueue.onIdle();
|
|
3160
|
+
this.#resolveUnmatchedStreamingWatchStops();
|
|
3161
|
+
// Excluding the parent Stop queues its ordinary downstream nodes. Let
|
|
3162
|
+
// their normal control-flow rules run before emitting the settled Watch
|
|
3163
|
+
// summary or finalizing the root graph.
|
|
3164
|
+
await this.#processingQueue.onIdle();
|
|
3130
3165
|
} while (this.#hasDrainableStreamingOutputWatches());
|
|
3131
3166
|
for (const [watchNodeId, watch] of this.#streamingOutputWatches) {
|
|
3132
3167
|
const plan = this.#streamingWatchPlansByWatchNodeId.get(watchNodeId);
|
|
@@ -3137,6 +3172,20 @@ export class GraphProcessor {
|
|
|
3137
3172
|
await this.#emitter.emit('streamingOutputWatchSummary', this.#withExecution({ watchNode: plan.watchNode, summary }));
|
|
3138
3173
|
}
|
|
3139
3174
|
}
|
|
3175
|
+
#resolveUnmatchedStreamingWatchStops() {
|
|
3176
|
+
for (const [watchNodeId, watch] of this.#streamingOutputWatches) {
|
|
3177
|
+
const plan = this.#streamingWatchPlansByWatchNodeId.get(watchNodeId);
|
|
3178
|
+
if (!plan?.stopNodeId || plan.unmatchedStopResolved || !watch.finishedNormally) {
|
|
3179
|
+
continue;
|
|
3180
|
+
}
|
|
3181
|
+
const stopNode = this.#nodesById[plan.stopNodeId];
|
|
3182
|
+
if (!stopNode) {
|
|
3183
|
+
throw new Error(`Watch Streaming Output "${plan.watchNode.title}" lost its Stop Watching Streaming Output node.`);
|
|
3184
|
+
}
|
|
3185
|
+
plan.unmatchedStopResolved = true;
|
|
3186
|
+
this.#excludeNode(stopNode, nanoid(), {}, 'stream completed without Stop Watching Streaming Output accepting a value');
|
|
3187
|
+
}
|
|
3188
|
+
}
|
|
3140
3189
|
#prepareAsyncBranchTopology() {
|
|
3141
3190
|
const connections = this.#getEffectiveConnections().filter((connection) => this.#isDefinitionValidConnection(connection));
|
|
3142
3191
|
const outgoingByNodeId = new Map();
|
|
@@ -3152,6 +3201,10 @@ export class GraphProcessor {
|
|
|
3152
3201
|
incomingByNodeId.set(connection.inputNodeId, incoming);
|
|
3153
3202
|
}
|
|
3154
3203
|
for (const triggerNode of Object.values(this.#nodesById)) {
|
|
3204
|
+
// Input anchors describe the consumed trigger's ports, not executable work.
|
|
3205
|
+
// A variadic anchor may itself be an outer async trigger.
|
|
3206
|
+
if (this.#asyncBranchInputAnchors?.[triggerNode.id])
|
|
3207
|
+
continue;
|
|
3155
3208
|
if (triggerNode.type !== 'startBackgroundBranch' || triggerNode.disabled || !isRelevant(triggerNode.id)) {
|
|
3156
3209
|
continue;
|
|
3157
3210
|
}
|
|
@@ -3393,6 +3446,10 @@ export class GraphProcessor {
|
|
|
3393
3446
|
processor.#externalFunctions = this.#externalFunctions;
|
|
3394
3447
|
processor.#contextValues = this.#contextValues;
|
|
3395
3448
|
processor.#parent = this;
|
|
3449
|
+
processor.#graphCallPath = Object.freeze([
|
|
3450
|
+
...this.#graphCallPath,
|
|
3451
|
+
processor.#graph.metadata?.name || '(Unnamed Graph)',
|
|
3452
|
+
]);
|
|
3396
3453
|
processor.#globals = this.#globals;
|
|
3397
3454
|
processor.#storedValueController = this.#storedValueController;
|
|
3398
3455
|
processor.#knowledgeStoreController = this.#knowledgeStoreController;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import CryptoJS from 'crypto-js';
|
|
2
|
+
import stableStringify from 'safe-stable-stringify';
|
|
3
|
+
import { cloneExecutionOutputs } from './ExecutionOutputClone.js';
|
|
4
|
+
/**
|
|
5
|
+
* Builds an opaque cache key for a legacy chat request.
|
|
6
|
+
*
|
|
7
|
+
* Legacy chat nodes may receive credentials and request headers from settings,
|
|
8
|
+
* neither of which belongs in a process-global key (or in clear text in any
|
|
9
|
+
* cache key). The digest scopes entries to the graph/node and all effective
|
|
10
|
+
* request/provider inputs without retaining those values in the Map key.
|
|
11
|
+
*/
|
|
12
|
+
export function buildLegacyChatEditorCacheKey(parts) {
|
|
13
|
+
const serialized = stableStringify({ cacheVersion: 1, ...parts }) ?? '';
|
|
14
|
+
return `legacy-chat:v1:sha256:${CryptoJS.SHA256(serialized).toString(CryptoJS.enc.Hex)}`;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolves the existing host-owned editor cache for a legacy chat request.
|
|
18
|
+
* Programmatic callers that do not supply an editor cache remain isolated to
|
|
19
|
+
* their GraphProcessor's execution cache instead of sharing process state.
|
|
20
|
+
*/
|
|
21
|
+
export function resolveLegacyChatEditorCache(params) {
|
|
22
|
+
if (!params.enabled) {
|
|
23
|
+
return { cache: undefined, cachedOutputs: undefined };
|
|
24
|
+
}
|
|
25
|
+
const cache = params.context.editorExecutionCache ?? params.context.executionCache;
|
|
26
|
+
if (cache == null) {
|
|
27
|
+
// Lightweight direct plugin callers historically provide only the process
|
|
28
|
+
// fields they need. Caching is optional, so an absent host cache must not
|
|
29
|
+
// make that invocation fail.
|
|
30
|
+
return { cache: undefined, cachedOutputs: undefined };
|
|
31
|
+
}
|
|
32
|
+
const cacheKey = buildLegacyChatEditorCacheKey({
|
|
33
|
+
graphId: params.context.execution?.graphId,
|
|
34
|
+
nodeId: params.context.node.id,
|
|
35
|
+
nodeType: params.context.node.type,
|
|
36
|
+
providerIdentity: params.providerIdentity,
|
|
37
|
+
request: params.request,
|
|
38
|
+
});
|
|
39
|
+
const cached = cache.get(cacheKey);
|
|
40
|
+
return {
|
|
41
|
+
cache: { cache, cacheKey },
|
|
42
|
+
cachedOutputs: cached == null ? undefined : cloneExecutionOutputs(cached),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** Stores a private snapshot so downstream execution cannot mutate a cache entry. */
|
|
46
|
+
export function writeLegacyChatEditorCache(cache, outputs) {
|
|
47
|
+
if (cache != null) {
|
|
48
|
+
cache.cache.set(cache.cacheKey, cloneExecutionOutputs(outputs));
|
|
49
|
+
}
|
|
50
|
+
}
|
package/dist/esm/model/Nodes.js
CHANGED
|
@@ -60,8 +60,12 @@ import { reportProgressNode } from './nodes/ReportProgressNode.js';
|
|
|
60
60
|
export * from './nodes/ReportProgressNode.js';
|
|
61
61
|
import { contextNode } from './nodes/ContextNode.js';
|
|
62
62
|
export * from './nodes/ContextNode.js';
|
|
63
|
+
import { graphCallPathNode } from './nodes/GraphCallPathNode.js';
|
|
64
|
+
export * from './nodes/GraphCallPathNode.js';
|
|
63
65
|
import { coalesceNode } from './nodes/CoalesceNode.js';
|
|
64
66
|
export * from './nodes/CoalesceNode.js';
|
|
67
|
+
import { coalesceNewNode } from './nodes/CoalesceNewNode.js';
|
|
68
|
+
export * from './nodes/CoalesceNewNode.js';
|
|
65
69
|
import { didRunNode } from './nodes/DidRunNode.js';
|
|
66
70
|
export * from './nodes/DidRunNode.js';
|
|
67
71
|
import { passthroughNode } from './nodes/PassthroughNode.js';
|
|
@@ -242,7 +246,9 @@ export const registerBuiltInNodes = (registry) => {
|
|
|
242
246
|
.register(raiseEventNode)
|
|
243
247
|
.register(reportProgressNode)
|
|
244
248
|
.register(contextNode)
|
|
249
|
+
.register(graphCallPathNode)
|
|
245
250
|
.register(coalesceNode)
|
|
251
|
+
.register(coalesceNewNode)
|
|
246
252
|
.register(didRunNode)
|
|
247
253
|
.register(passthroughNode)
|
|
248
254
|
.register(dataBusNode)
|
|
@@ -25,14 +25,13 @@ function normalizePositiveInteger(value, fallback, maximum) {
|
|
|
25
25
|
/**
|
|
26
26
|
* Owns bounded, cancellable delivery of a streaming node's immutable output
|
|
27
27
|
* snapshots. It deliberately knows nothing about graph topology: the owning
|
|
28
|
-
* GraphProcessor decides how a snapshot runs and whether
|
|
29
|
-
*
|
|
28
|
+
* GraphProcessor decides how a snapshot runs and whether a Stop boundary
|
|
29
|
+
* must be resolved after the stream completes.
|
|
30
30
|
*/
|
|
31
31
|
export class StreamingOutputWatch {
|
|
32
32
|
#options;
|
|
33
33
|
#run;
|
|
34
34
|
#onFailure;
|
|
35
|
-
#requiresAcceptedStop;
|
|
36
35
|
#queue = [];
|
|
37
36
|
#activeRuns = new Set();
|
|
38
37
|
#timer;
|
|
@@ -46,7 +45,7 @@ export class StreamingOutputWatch {
|
|
|
46
45
|
#coalescedUpdates = 0;
|
|
47
46
|
#droppedUpdates = 0;
|
|
48
47
|
#maximumQueuedUpdates = 0;
|
|
49
|
-
constructor(options, run, onFailure
|
|
48
|
+
constructor(options, run, onFailure) {
|
|
50
49
|
this.#options = {
|
|
51
50
|
triggerMode: options.triggerMode === 'interval' ? 'interval' : 'every-update',
|
|
52
51
|
executionMode: options.executionMode === 'parallel' ? 'parallel' : 'sequential',
|
|
@@ -57,13 +56,12 @@ export class StreamingOutputWatch {
|
|
|
57
56
|
};
|
|
58
57
|
this.#run = run;
|
|
59
58
|
this.#onFailure = onFailure;
|
|
60
|
-
this.#requiresAcceptedStop = requiresAcceptedStop;
|
|
61
59
|
}
|
|
62
60
|
get hasPending() {
|
|
63
61
|
// Stop prevents new delivery, but accepted and failing invocations still
|
|
64
62
|
// belong to the root lifecycle until they settle. Hiding those active runs
|
|
65
|
-
// here
|
|
66
|
-
// actual child failure.
|
|
63
|
+
// here would let a later completion resolve the Stop boundary before the
|
|
64
|
+
// actual child failure is observed.
|
|
67
65
|
return this.#activeRuns.size > 0 || (!this.#stopped && (this.#queue.length > 0 || this.#timer != null));
|
|
68
66
|
}
|
|
69
67
|
get isAwaitingProducer() {
|
|
@@ -80,6 +78,19 @@ export class StreamingOutputWatch {
|
|
|
80
78
|
get isSettled() {
|
|
81
79
|
return !this.hasPending && (this.#stopped || this.#failure != null || this.#producerFinished);
|
|
82
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* The producer delivered its final snapshot and every scheduled invocation
|
|
83
|
+
* settled without cancellation or failure. The scheduler deliberately does
|
|
84
|
+
* not infer graph topology; GraphProcessor decides whether this means a
|
|
85
|
+
* parent Stop must be excluded.
|
|
86
|
+
*/
|
|
87
|
+
get finishedNormally() {
|
|
88
|
+
return (!this.#stopped &&
|
|
89
|
+
this.#failure == null &&
|
|
90
|
+
this.#producerFinished &&
|
|
91
|
+
this.#finalSnapshotSettled &&
|
|
92
|
+
!this.hasPending);
|
|
93
|
+
}
|
|
83
94
|
get runtimeSummary() {
|
|
84
95
|
return {
|
|
85
96
|
receivedUpdates: this.#receivedUpdates,
|
|
@@ -89,14 +100,6 @@ export class StreamingOutputWatch {
|
|
|
89
100
|
...(this.#failureKind === undefined ? {} : { failureKind: this.#failureKind }),
|
|
90
101
|
};
|
|
91
102
|
}
|
|
92
|
-
/**
|
|
93
|
-
* A Stop boundary can enqueue ordinary parent-graph work when its node
|
|
94
|
-
* completes. Until it settles, its result is not safe to expose
|
|
95
|
-
* through the foreground-output boundary.
|
|
96
|
-
*/
|
|
97
|
-
get canAffectForegroundOutputs() {
|
|
98
|
-
return this.#requiresAcceptedStop;
|
|
99
|
-
}
|
|
100
103
|
publish(snapshot) {
|
|
101
104
|
// A producer's terminal snapshot closes its partial stream. Ignore a
|
|
102
105
|
// misbehaving late callback rather than scheduling work after a final
|
|
@@ -157,9 +160,6 @@ export class StreamingOutputWatch {
|
|
|
157
160
|
}
|
|
158
161
|
await Promise.all([...this.#activeRuns].map((run) => run.promise));
|
|
159
162
|
}
|
|
160
|
-
if (this.#producerFinished && this.#finalSnapshotSettled && !this.#stopped && this.#requiresAcceptedStop) {
|
|
161
|
-
this.#fail(new Error('The watched streaming output completed before Stop Watching Streaming Output accepted a value.'), 'missing-stop');
|
|
162
|
-
}
|
|
163
163
|
}
|
|
164
164
|
#scheduleInterval() {
|
|
165
165
|
if (this.#timer != null) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export const STREAM_RESPONSE_HELPER_MESSAGE = 'Shows streamed response updates in the editor, including direct consumer previews. Ordinary consumers run after the final response; Watch Streaming Output branches can run during streaming.';
|
|
1
2
|
export function createChatV2CommonNodeData(overrides = {}) {
|
|
2
3
|
return {
|
|
3
4
|
model: 'gpt-4o',
|
|
@@ -271,7 +272,7 @@ export function getCommonChatV2Editors(modelOptions) {
|
|
|
271
272
|
type: 'toggle',
|
|
272
273
|
label: 'Stream response',
|
|
273
274
|
dataKey: 'useAsGraphPartialOutput',
|
|
274
|
-
helperMessage:
|
|
275
|
+
helperMessage: STREAM_RESPONSE_HELPER_MESSAGE,
|
|
275
276
|
},
|
|
276
277
|
],
|
|
277
278
|
},
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { STREAM_RESPONSE_HELPER_MESSAGE } from './chatV2Shared.js';
|
|
1
2
|
import { DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_COOLDOWN_MS, DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_REPEAT_TIMES, } from './chatV2Retry.js';
|
|
2
3
|
import { anthropicCacheControlTtlOptions, anthropicEffortOptions, anthropicThinkingModeOptions, chatV2ProviderOptions, customProviderApiOptions, getChatV2ModelOptions, googleThinkingLevelOptions, openAIReasoningEffortOptions, openAIWebSearchContextSizeOptions, } from './providerOptions.js';
|
|
3
4
|
import { LLM_CHAT_V2_PARALLEL_TOOL_CALLS_HELPER_MESSAGE, supportsLLMChatV2ParallelToolCalls, } from './parallelToolCalls.js';
|
|
@@ -417,7 +418,7 @@ function getResponseSettingsEditors() {
|
|
|
417
418
|
type: 'toggle',
|
|
418
419
|
label: 'Stream response',
|
|
419
420
|
dataKey: 'useAsGraphPartialOutput',
|
|
420
|
-
helperMessage:
|
|
421
|
+
helperMessage: STREAM_RESPONSE_HELPER_MESSAGE,
|
|
421
422
|
},
|
|
422
423
|
{
|
|
423
424
|
type: 'string',
|
|
@@ -10,8 +10,7 @@ import { resolveAdditionalHeaders, resolveAdditionalParameters, resolveAudioAndM
|
|
|
10
10
|
import { coercePromptToChatMessages, prependSystemPrompt } from '../chat/chatMessages.js';
|
|
11
11
|
import { clampMaxTokensToModelLimit } from '../chat/tokenBudget.js';
|
|
12
12
|
import { applyOpenAINonStreamingResponse, applyOpenAIStreamingResponse, handleOpenAIRetryableFailure, } from '../chat/openAIChatRuntime.js';
|
|
13
|
-
|
|
14
|
-
const cache = new Map();
|
|
13
|
+
import { resolveLegacyChatEditorCache, writeLegacyChatEditorCache } from '../LegacyChatEditorCache.js';
|
|
15
14
|
export const ChatNodeBase = {
|
|
16
15
|
defaultData: () => ({
|
|
17
16
|
model: 'gpt-5',
|
|
@@ -652,9 +651,9 @@ export const ChatNodeBase = {
|
|
|
652
651
|
},
|
|
653
652
|
{
|
|
654
653
|
type: 'toggle',
|
|
655
|
-
label: 'Cache
|
|
654
|
+
label: 'Cache outputs (editor only)',
|
|
656
655
|
dataKey: 'cache',
|
|
657
|
-
helperMessage: '
|
|
656
|
+
helperMessage: 'Reuses a matching ordinary chat response while this project remains open. Tool-capable requests always run normally.',
|
|
658
657
|
},
|
|
659
658
|
{
|
|
660
659
|
type: 'toggle',
|
|
@@ -816,13 +815,19 @@ export const ChatNodeBase = {
|
|
|
816
815
|
options.temperature = useTopP ? undefined : temperature; // Not supported in o1-preview
|
|
817
816
|
options.max_tokens = maxTokens;
|
|
818
817
|
}
|
|
819
|
-
const
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
context.
|
|
824
|
-
|
|
825
|
-
|
|
818
|
+
const { cache, cachedOutputs } = resolveLegacyChatEditorCache({
|
|
819
|
+
context,
|
|
820
|
+
enabled: data.cache && !data.enableFunctionUse,
|
|
821
|
+
providerIdentity: {
|
|
822
|
+
apiKey: context.settings.openAiKey ?? '',
|
|
823
|
+
organization: context.settings.openAiOrganization,
|
|
824
|
+
headers: allAdditionalHeaders,
|
|
825
|
+
},
|
|
826
|
+
request: options,
|
|
827
|
+
});
|
|
828
|
+
if (cachedOutputs != null) {
|
|
829
|
+
context.markResultAsEditorCacheHit?.();
|
|
830
|
+
return cachedOutputs;
|
|
826
831
|
}
|
|
827
832
|
const startTime = Date.now();
|
|
828
833
|
// Non-streaming APIs
|
|
@@ -851,7 +856,7 @@ export const ChatNodeBase = {
|
|
|
851
856
|
durationMs: Date.now() - startTime,
|
|
852
857
|
});
|
|
853
858
|
Object.freeze(output);
|
|
854
|
-
cache
|
|
859
|
+
writeLegacyChatEditorCache(cache, output);
|
|
855
860
|
return output;
|
|
856
861
|
}
|
|
857
862
|
const chunks = streamChatCompletions({
|
|
@@ -883,7 +888,7 @@ export const ChatNodeBase = {
|
|
|
883
888
|
});
|
|
884
889
|
output['duration'] = { type: 'number', value: Date.now() - startTime };
|
|
885
890
|
Object.freeze(output);
|
|
886
|
-
cache
|
|
891
|
+
writeLegacyChatEditorCache(cache, output);
|
|
887
892
|
return output;
|
|
888
893
|
}, {
|
|
889
894
|
forever: true,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { dedent } from 'ts-dedent';
|
|
2
|
+
import { nodeDefinition } from '../NodeDefinition.js';
|
|
3
|
+
import {} from '../NodeImpl.js';
|
|
4
|
+
import {} from '../NodeBase.js';
|
|
5
|
+
import { CoalesceNodeBase, createCoalesceNode } from './CoalesceNodeBase.js';
|
|
6
|
+
export class CoalesceNewNodeImpl extends CoalesceNodeBase {
|
|
7
|
+
includesLegacyConditionalInput = false;
|
|
8
|
+
static create = () => createCoalesceNode('coalesceNew', 'Coalesce');
|
|
9
|
+
static getUIData() {
|
|
10
|
+
return {
|
|
11
|
+
infoBoxBody: dedent `
|
|
12
|
+
Takes in any number of inputs and outputs the first value that is not "Not Ran". Useful for consolidating branches after a Match node.
|
|
13
|
+
|
|
14
|
+
Null and undefined input values are emitted by default, but the node can be configured to skip either value and continue checking later inputs.
|
|
15
|
+
`,
|
|
16
|
+
infoBoxTitle: 'Coalesce Node',
|
|
17
|
+
contextMenuTitle: 'Coalesce',
|
|
18
|
+
group: ['Logic'],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export const coalesceNewNode = nodeDefinition(CoalesceNewNodeImpl, 'Coalesce');
|