@valerypopoff/rivet2-core 2.6.0 → 2.8.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 +2779 -780
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/cjs/interpolationRuntime.cjs +7 -3
- package/dist/cjs/interpolationRuntime.cjs.map +2 -2
- package/dist/esm/api/createProcessor.js +3 -0
- package/dist/esm/exports.js +2 -1
- package/dist/esm/integrations/CodeRunner.js +6 -2
- package/dist/esm/integrations/mcp/MCPBase.js +2 -1
- package/dist/esm/model/ExecutionOutputClone.js +46 -0
- package/dist/esm/model/GlobalVariables.js +452 -0
- package/dist/esm/model/GraphBoundaryEffects.js +12 -4
- package/dist/esm/model/GraphProcessor.js +838 -41
- package/dist/esm/model/Nodes.js +6 -0
- package/dist/esm/model/ProcessContextBuilder.js +3 -1
- package/dist/esm/model/ProjectReferenceLoader.js +36 -1
- package/dist/esm/model/RecordingPlayer.js +39 -4
- package/dist/esm/model/StreamingOutputWatch.js +262 -0
- package/dist/esm/model/StreamingOutputWatchHistory.js +162 -0
- package/dist/esm/model/SubprocessorBridge.js +29 -19
- package/dist/esm/model/chat-v2/llmChatV2OutputClone.js +3 -42
- package/dist/esm/model/nodes/ChatLoopNode.js +8 -4
- package/dist/esm/model/nodes/CodeNewNode.js +5 -2
- package/dist/esm/model/nodes/ExpressionNode.js +5 -2
- package/dist/esm/model/nodes/ExtractObjectPathNode.js +4 -4
- package/dist/esm/model/nodes/GraphOutputNode.js +13 -8
- package/dist/esm/model/nodes/LoopControllerNode.js +6 -4
- package/dist/esm/model/nodes/MCPGetPromptNode.js +2 -1
- package/dist/esm/model/nodes/MCPToolCallNode.js +2 -1
- package/dist/esm/model/nodes/ObjectNode.js +5 -3
- package/dist/esm/model/nodes/PromptNode.js +5 -2
- package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +9 -1
- package/dist/esm/model/nodes/StopWatchingStreamingOutputNode.js +48 -0
- package/dist/esm/model/nodes/SubGraphNode.js +11 -1
- package/dist/esm/model/nodes/TextNode.js +5 -2
- package/dist/esm/model/nodes/ToTreeNode.js +10 -3
- package/dist/esm/model/nodes/ToolNode.js +5 -2
- package/dist/esm/model/nodes/WatchStreamingOutputNode.js +126 -0
- package/dist/esm/model/nodes/jsListCallbackHelpers.js +7 -1
- package/dist/esm/model/nodes/jsValueInterpolation.js +21 -4
- package/dist/esm/plugins/openai/nodes/ThreadMessageNode.js +2 -1
- package/dist/esm/recording/ExecutionRecorder.js +18 -8
- package/dist/esm/utils/interpolation.js +35 -2
- package/dist/esm/utils/serialization/serializationUtils.js +9 -0
- package/dist/esm/utils/serialization/serialization_v4.js +7 -0
- package/dist/types/exports.d.ts +2 -1
- package/dist/types/integrations/CodeRunner.d.ts +3 -3
- package/dist/types/integrations/CodeRunnerOptions.d.ts +5 -0
- package/dist/types/integrations/mcp/MCPBase.d.ts +1 -1
- package/dist/types/model/ExecutionOutputClone.d.ts +11 -0
- package/dist/types/model/ExecutorProtocol.d.ts +9 -2
- package/dist/types/model/GlobalVariables.d.ts +29 -0
- package/dist/types/model/GraphBoundaryEffects.d.ts +7 -1
- package/dist/types/model/GraphProcessor.d.ts +49 -3
- package/dist/types/model/Nodes.d.ts +4 -2
- package/dist/types/model/ProcessContext.d.ts +14 -0
- package/dist/types/model/ProcessContextBuilder.d.ts +3 -1
- package/dist/types/model/Project.d.ts +7 -1
- package/dist/types/model/ProjectReferenceLoader.d.ts +15 -1
- package/dist/types/model/StreamingOutputWatch.d.ts +74 -0
- package/dist/types/model/StreamingOutputWatchHistory.d.ts +60 -0
- package/dist/types/model/SubprocessorBridge.d.ts +2 -0
- package/dist/types/model/chat-v2/llmChatV2OutputClone.d.ts +3 -3
- package/dist/types/model/nodes/ChatLoopNode.d.ts +2 -0
- package/dist/types/model/nodes/ExtractObjectPathNode.d.ts +1 -1
- package/dist/types/model/nodes/GraphOutputNode.d.ts +8 -1
- package/dist/types/model/nodes/LoopControllerNode.d.ts +2 -0
- package/dist/types/model/nodes/ObjectNode.d.ts +1 -1
- package/dist/types/model/nodes/StopWatchingStreamingOutputNode.d.ts +14 -0
- package/dist/types/model/nodes/ToTreeNode.d.ts +5 -1
- package/dist/types/model/nodes/WatchStreamingOutputNode.d.ts +17 -0
- package/dist/types/model/nodes/jsValueInterpolation.d.ts +10 -1
- package/dist/types/recording/RecordedEvents.d.ts +8 -0
- package/dist/types/utils/interpolation.d.ts +14 -5
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { dedent } from 'ts-dedent';
|
|
2
|
+
import { getInterpolationGlobalValues } from '../../utils/interpolation.js';
|
|
2
3
|
import { buildClonedInputValueAssignments, buildJsValueInterpolatedSource, buildJsValueInputClonePreamble, buildJsValuePreview, getJsValueInterpolationCodeRunnerOptions, getJsValueInterpolationInputDefinitions, getJsValueInterpolationRuntimeContext, interpolateJsValuePreviewSource, sanitizeGeneratedJsValueError, } from './jsValueInterpolation.js';
|
|
3
4
|
const MAX_CALLBACK_PREVIEW_BODY_LINES = 13;
|
|
4
5
|
const JS_LIST_CALLBACK_SIGNATURE = '(item, index, array)';
|
|
@@ -37,6 +38,9 @@ function buildJSListRuntimePreamble(interpolationContext) {
|
|
|
37
38
|
cacheIdentifier: interpolationContext.cloneCacheIdentifier,
|
|
38
39
|
contextIdentifier: interpolationContext.contextIdentifier,
|
|
39
40
|
graphInputsIdentifier: interpolationContext.graphInputsIdentifier,
|
|
41
|
+
globalValuesCloneIdentifier: interpolationContext.globalValuesCloneIdentifier,
|
|
42
|
+
globalValuesIdentifier: interpolationContext.globalValuesIdentifier,
|
|
43
|
+
usesGlobalValues: interpolationContext.requiresGlobalValues,
|
|
40
44
|
inputsIdentifier: interpolationContext.inputsIdentifier,
|
|
41
45
|
})}
|
|
42
46
|
const array = cloneJsInputValue(inputs.array?.value, ${interpolationContext.cloneCacheIdentifier});
|
|
@@ -54,6 +58,8 @@ function sanitizeJSListError(error, callbackBody, nodeName) {
|
|
|
54
58
|
return sanitizeGeneratedJsValueError(error, interpolationContext.inputNames, interpolationContext.inputsIdentifier, fallbackLabel, [
|
|
55
59
|
interpolationContext.cloneCacheIdentifier,
|
|
56
60
|
interpolationContext.contextIdentifier,
|
|
61
|
+
interpolationContext.globalValuesCloneIdentifier,
|
|
62
|
+
interpolationContext.globalValuesIdentifier,
|
|
57
63
|
interpolationContext.graphInputsIdentifier,
|
|
58
64
|
interpolationContext.interpolationHelperIdentifier,
|
|
59
65
|
]);
|
|
@@ -186,7 +192,7 @@ export function assertJSListNodeOutputs(outputs, outputId, nodeName) {
|
|
|
186
192
|
}
|
|
187
193
|
export async function runJSListNodeCode({ buildWrapper, callbackBody, context, inputs, nodeName, outputId, }) {
|
|
188
194
|
try {
|
|
189
|
-
const outputs = await context.codeRunner.runCode(buildWrapper(callbackBody), inputs, getJsValueInterpolationCodeRunnerOptions(JS_LIST_CODE_RUNNER_OPTIONS, getJSListInterpolationContext(callbackBody)), context.graphInputNodeValues, context.contextValues);
|
|
195
|
+
const outputs = await context.codeRunner.runCode(buildWrapper(callbackBody), inputs, getJsValueInterpolationCodeRunnerOptions(JS_LIST_CODE_RUNNER_OPTIONS, getJSListInterpolationContext(callbackBody)), context.graphInputNodeValues, context.contextValues, getInterpolationGlobalValues(callbackBody, context.getGlobal));
|
|
190
196
|
assertJSListNodeOutputs(outputs, outputId, nodeName);
|
|
191
197
|
return outputs;
|
|
192
198
|
}
|
|
@@ -2,7 +2,8 @@ import { dedent } from 'ts-dedent';
|
|
|
2
2
|
import { createInterpolationInputDefinition } from '../interpolationInputDefinition.js';
|
|
3
3
|
import { getError } from '../../utils/errors.js';
|
|
4
4
|
import { extractInterpolationVariables, parseInterpolationTemplate, replaceInterpolationTokens, resolveInterpolationExpressionRawValue, } from '../../utils/interpolation.js';
|
|
5
|
-
const MISSING_INTERPOLATION_HELPER_MESSAGE = 'This CodeRunner must honor CodeRunnerOptions.interpolationHelperIdentifier to resolve JSONPath or @graphInputs/@context interpolation.';
|
|
5
|
+
const MISSING_INTERPOLATION_HELPER_MESSAGE = 'This CodeRunner must honor CodeRunnerOptions.interpolationHelperIdentifier to resolve JSONPath or @graphInputs/@context/@globals interpolation.';
|
|
6
|
+
const MISSING_GLOBAL_VALUES_MESSAGE = 'This CodeRunner must honor CodeRunnerOptions.globalValuesIdentifier to resolve @globals interpolation.';
|
|
6
7
|
function escapeRegExp(value) {
|
|
7
8
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
8
9
|
}
|
|
@@ -41,7 +42,7 @@ function buildJsValueReference(token, interpolationContext, options) {
|
|
|
41
42
|
const sourceInputs = isLocalReference
|
|
42
43
|
? `{ ${JSON.stringify(token.reference.baseName)}: { type: 'any', value: ${token.reference.baseName} } }`
|
|
43
44
|
: interpolationContext.inputsIdentifier;
|
|
44
|
-
const resolveExpression = `${interpolationContext.interpolationHelperIdentifier}(${sourceInputs}, ${JSON.stringify(token.tokenName)}, ${interpolationContext.graphInputsIdentifier}, ${interpolationContext.contextIdentifier})`;
|
|
45
|
+
const resolveExpression = `${interpolationContext.interpolationHelperIdentifier}(${sourceInputs}, ${JSON.stringify(token.tokenName)}, ${interpolationContext.graphInputsIdentifier}, ${interpolationContext.contextIdentifier}, ${interpolationContext.globalValuesCloneIdentifier})`;
|
|
45
46
|
return `(typeof ${interpolationContext.interpolationHelperIdentifier} === 'function'
|
|
46
47
|
? ${resolveExpression}
|
|
47
48
|
: (() => { throw new Error(${JSON.stringify(MISSING_INTERPOLATION_HELPER_MESSAGE)}); })())`;
|
|
@@ -84,6 +85,8 @@ export function getJsValueInterpolationRuntimeContext(template, baseInputsIdenti
|
|
|
84
85
|
const cloneCacheIdentifier = getSafeJsValueInterpolationIdentifier(`${template}\n${inputsIdentifier}\n${interpolationHelperIdentifier}`, `${baseInputsIdentifier}CloneCache`);
|
|
85
86
|
const graphInputsIdentifier = getSafeJsValueInterpolationIdentifier(`${template}\n${inputsIdentifier}\n${interpolationHelperIdentifier}\n${cloneCacheIdentifier}`, `${baseInputsIdentifier}GraphInputs`);
|
|
86
87
|
const contextIdentifier = getSafeJsValueInterpolationIdentifier(`${template}\n${inputsIdentifier}\n${interpolationHelperIdentifier}\n${cloneCacheIdentifier}\n${graphInputsIdentifier}`, `${baseInputsIdentifier}Context`);
|
|
88
|
+
const globalValuesIdentifier = getSafeJsValueInterpolationIdentifier(`${template}\n${inputsIdentifier}\n${interpolationHelperIdentifier}\n${cloneCacheIdentifier}\n${graphInputsIdentifier}\n${contextIdentifier}`, `${baseInputsIdentifier}Globals`);
|
|
89
|
+
const globalValuesCloneIdentifier = getSafeJsValueInterpolationIdentifier(`${template}\n${inputsIdentifier}\n${interpolationHelperIdentifier}\n${cloneCacheIdentifier}\n${graphInputsIdentifier}\n${contextIdentifier}\n${globalValuesIdentifier}`, `${baseInputsIdentifier}GlobalValues`);
|
|
87
90
|
const parsedTemplate = parseInterpolationTemplate(template);
|
|
88
91
|
return {
|
|
89
92
|
inputNames: getJsValueInterpolationInputNames(template, options),
|
|
@@ -92,8 +95,11 @@ export function getJsValueInterpolationRuntimeContext(template, baseInputsIdenti
|
|
|
92
95
|
cloneCacheIdentifier,
|
|
93
96
|
graphInputsIdentifier,
|
|
94
97
|
contextIdentifier,
|
|
98
|
+
globalValuesIdentifier,
|
|
99
|
+
globalValuesCloneIdentifier,
|
|
95
100
|
requiresInterpolationHelper: parsedTemplate.tokens.some((token) => token.reference !== undefined &&
|
|
96
101
|
(token.reference.source !== 'variable' || token.reference.jsonPath !== undefined)),
|
|
102
|
+
requiresGlobalValues: parsedTemplate.tokens.some((token) => token.reference?.source === 'globals'),
|
|
97
103
|
};
|
|
98
104
|
}
|
|
99
105
|
export function buildJsValueInterpolatedSource(template, interpolationContext, options = {}) {
|
|
@@ -206,7 +212,7 @@ export function buildClonedInputValueAssignments(inputNames, targetIdentifier, c
|
|
|
206
212
|
})();`)
|
|
207
213
|
.join('\n');
|
|
208
214
|
}
|
|
209
|
-
export function buildJsValueInputClonePreamble({ cacheIdentifier, contextIdentifier, graphInputsIdentifier, inputsIdentifier, }) {
|
|
215
|
+
export function buildJsValueInputClonePreamble({ cacheIdentifier, contextIdentifier, graphInputsIdentifier, globalValuesCloneIdentifier, globalValuesIdentifier, usesGlobalValues, inputsIdentifier, }) {
|
|
210
216
|
return dedent `
|
|
211
217
|
${buildCloneJsInputValueFunction()}
|
|
212
218
|
const ${inputsIdentifier} = Object.create(null);
|
|
@@ -217,15 +223,23 @@ export function buildJsValueInputClonePreamble({ cacheIdentifier, contextIdentif
|
|
|
217
223
|
const ${contextIdentifier} = typeof context === 'undefined'
|
|
218
224
|
? Object.create(null)
|
|
219
225
|
: cloneJsInputValue(context, ${cacheIdentifier});
|
|
226
|
+
const ${globalValuesCloneIdentifier} = ${usesGlobalValues
|
|
227
|
+
? `typeof ${globalValuesIdentifier} === 'undefined'
|
|
228
|
+
? (() => { throw new Error(${JSON.stringify(MISSING_GLOBAL_VALUES_MESSAGE)}); })()
|
|
229
|
+
: cloneJsInputValue(${globalValuesIdentifier}, ${cacheIdentifier})`
|
|
230
|
+
: 'Object.create(null)'};
|
|
220
231
|
`;
|
|
221
232
|
}
|
|
222
233
|
export function buildJsValueInputsInitializer({ interpolationContext, }) {
|
|
223
|
-
const { cloneCacheIdentifier, contextIdentifier, graphInputsIdentifier, inputNames, inputsIdentifier } = interpolationContext;
|
|
234
|
+
const { cloneCacheIdentifier, contextIdentifier, globalValuesCloneIdentifier, globalValuesIdentifier, graphInputsIdentifier, inputNames, inputsIdentifier, } = interpolationContext;
|
|
224
235
|
return dedent `
|
|
225
236
|
${buildJsValueInputClonePreamble({
|
|
226
237
|
cacheIdentifier: cloneCacheIdentifier,
|
|
227
238
|
contextIdentifier,
|
|
228
239
|
graphInputsIdentifier,
|
|
240
|
+
globalValuesCloneIdentifier,
|
|
241
|
+
globalValuesIdentifier,
|
|
242
|
+
usesGlobalValues: interpolationContext.requiresGlobalValues,
|
|
229
243
|
inputsIdentifier,
|
|
230
244
|
})}
|
|
231
245
|
${buildClonedInputValueAssignments(inputNames, inputsIdentifier, cloneCacheIdentifier)}
|
|
@@ -238,6 +252,9 @@ export function getJsValueInterpolationCodeRunnerOptions(options, interpolationC
|
|
|
238
252
|
return {
|
|
239
253
|
...options,
|
|
240
254
|
interpolationHelperIdentifier: interpolationContext.interpolationHelperIdentifier,
|
|
255
|
+
...(interpolationContext.requiresGlobalValues
|
|
256
|
+
? { globalValuesIdentifier: interpolationContext.globalValuesIdentifier }
|
|
257
|
+
: {}),
|
|
241
258
|
};
|
|
242
259
|
}
|
|
243
260
|
export function sanitizeGeneratedJsValueText(text, inputNames, targetIdentifier, fallbackLabel, generatedIdentifiers = []) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {} from '../../../index.js';
|
|
2
2
|
import { newId, coerceTypeOptional, getInputOrData } from '../../../utils/index.js';
|
|
3
|
-
import { extractInterpolationVariableReferences, interpolate } from '../../../utils/interpolation.js';
|
|
3
|
+
import { extractInterpolationVariableReferences, getInterpolationGlobalValues, interpolate } from '../../../utils/interpolation.js';
|
|
4
4
|
import { pluginNodeDefinition } from '../../../model/NodeDefinition.js';
|
|
5
5
|
import { createInterpolationInputDefinition } from '../../../model/interpolationInputDefinition.js';
|
|
6
6
|
export const ThreadMessageNodeImpl = {
|
|
@@ -127,6 +127,7 @@ export const ThreadMessageNodeImpl = {
|
|
|
127
127
|
}
|
|
128
128
|
const interpolated = interpolate(text, inputData, context?.graphInputNodeValues, context?.contextValues, {
|
|
129
129
|
coerceBareVariableDataValues: true,
|
|
130
|
+
globalValues: getInterpolationGlobalValues(text, context?.getGlobal),
|
|
130
131
|
});
|
|
131
132
|
// Here you would typically make a call to an API to create the message
|
|
132
133
|
// For the sake of this example, we'll just return the data as is
|
|
@@ -31,11 +31,12 @@ const toRecordedEventMap = {
|
|
|
31
31
|
processId,
|
|
32
32
|
...(resultOrigin === undefined ? {} : { resultOrigin }),
|
|
33
33
|
}, execution),
|
|
34
|
-
nodeFinish: ({ node, outputs, processId, resultOrigin, durationMs, splitRunDurationMs, execution }) => withExecution(withDuration({
|
|
34
|
+
nodeFinish: ({ node, outputs, processId, resultOrigin, durationMs, splitRunDurationMs, streamingWatchTerminal, execution }) => withExecution(withDuration({
|
|
35
35
|
nodeId: node.id,
|
|
36
36
|
outputs,
|
|
37
37
|
processId,
|
|
38
38
|
...(resultOrigin === undefined ? {} : { resultOrigin }),
|
|
39
|
+
...(streamingWatchTerminal ? { streamingWatchTerminal: true } : {}),
|
|
39
40
|
}, durationMs, splitRunDurationMs), execution),
|
|
40
41
|
nodeError: ({ node, error, processId, outputs, splitOutputs, resultOrigin, durationMs, splitRunDurationMs, execution }) => withExecution(withDuration({
|
|
41
42
|
nodeId: node.id,
|
|
@@ -94,6 +95,7 @@ const toRecordedEventMap = {
|
|
|
94
95
|
nodeId: node.id,
|
|
95
96
|
processId,
|
|
96
97
|
}, execution),
|
|
98
|
+
streamingOutputWatchSummary: ({ watchNode, summary, execution }) => withExecution({ watchNodeId: watchNode.id, summary }, execution),
|
|
97
99
|
error: ({ error }) => ({
|
|
98
100
|
error: typeof error === 'string' ? error : error.stack,
|
|
99
101
|
}),
|
|
@@ -127,24 +129,32 @@ function toRecordedEvent(event, data) {
|
|
|
127
129
|
ts: Date.now(),
|
|
128
130
|
};
|
|
129
131
|
}
|
|
130
|
-
const recordableData =
|
|
132
|
+
const { recordableData, occurredAt } = omitTransientEventTiming(data);
|
|
131
133
|
const recordedEvent = {
|
|
132
134
|
type: event,
|
|
133
135
|
data: toRecordedEventMap[event](recordableData),
|
|
134
136
|
ts: Date.now(),
|
|
137
|
+
...(occurredAt === undefined ? {} : { occurredAt }),
|
|
135
138
|
};
|
|
136
139
|
return recordedEvent;
|
|
137
140
|
}
|
|
138
141
|
/**
|
|
139
142
|
* Replay provenance belongs to the current delivery, not the historical event
|
|
140
|
-
* itself.
|
|
141
|
-
*
|
|
143
|
+
* itself. A deferred Watch event additionally carries the moment it occurred;
|
|
144
|
+
* persist that separately while retaining the append-time `ts` so recording
|
|
145
|
+
* order remains monotonic and replayable.
|
|
142
146
|
*/
|
|
143
|
-
function
|
|
147
|
+
function omitTransientEventTiming(data) {
|
|
144
148
|
if (data == null || typeof data !== 'object')
|
|
145
|
-
return data;
|
|
146
|
-
const { replayRecordedAt: _replayRecordedAt, ...recordableData } = data;
|
|
147
|
-
return
|
|
149
|
+
return { recordableData: data, occurredAt: undefined };
|
|
150
|
+
const { replayRecordedAt: _replayRecordedAt, eventOccurredAt, ...recordableData } = data;
|
|
151
|
+
return {
|
|
152
|
+
recordableData: recordableData,
|
|
153
|
+
occurredAt: isRecordedTimestamp(eventOccurredAt) ? eventOccurredAt : undefined,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function isRecordedTimestamp(value) {
|
|
157
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0;
|
|
148
158
|
}
|
|
149
159
|
function isRecordableProcessEvent(message) {
|
|
150
160
|
return message in toRecordedEventMap || isPrefix(message, 'globalSet:') || isPrefix(message, 'userEvent:');
|
|
@@ -269,6 +269,7 @@ function parseInterpolationExpressionUncached(trimmedExpression) {
|
|
|
269
269
|
for (const [prefix, source] of [
|
|
270
270
|
['@graphInputs', 'graphInputs'],
|
|
271
271
|
['@context', 'context'],
|
|
272
|
+
['@globals', 'globals'],
|
|
272
273
|
]) {
|
|
273
274
|
if (trimmedExpression.startsWith(`${prefix}.`)) {
|
|
274
275
|
return parseBaseReference(trimmedExpression.slice(prefix.length + 1), source);
|
|
@@ -428,7 +429,7 @@ export function replaceInterpolationTokens(template, getReplacement, options = {
|
|
|
428
429
|
}
|
|
429
430
|
/**
|
|
430
431
|
* Discovers connectable interpolation bases in first-occurrence order. Special
|
|
431
|
-
* graph/context references are intentionally omitted because they do not make ports.
|
|
432
|
+
* graph/context/global references are intentionally omitted because they do not make ports.
|
|
432
433
|
*/
|
|
433
434
|
export function extractInterpolationVariableReferences(template) {
|
|
434
435
|
if (!template.includes('{{')) {
|
|
@@ -452,6 +453,33 @@ export function extractInterpolationVariableReferences(template) {
|
|
|
452
453
|
}
|
|
453
454
|
return Array.from(discovered.values(), (reference) => ({ ...reference }));
|
|
454
455
|
}
|
|
456
|
+
/**
|
|
457
|
+
* Captures only globals referenced by a template into a safe record. Globals
|
|
458
|
+
* are intentionally snapshotted at node execution: interpolation neither
|
|
459
|
+
* waits for a writer nor creates an execution dependency.
|
|
460
|
+
*/
|
|
461
|
+
export function getInterpolationGlobalValues(template, getGlobal) {
|
|
462
|
+
const values = Object.create(null);
|
|
463
|
+
if (!getGlobal || !template.includes('{{')) {
|
|
464
|
+
return values;
|
|
465
|
+
}
|
|
466
|
+
for (const token of parseInterpolationTemplate(template).tokens) {
|
|
467
|
+
const reference = token.reference;
|
|
468
|
+
if (!reference || reference.source !== 'globals' || Object.prototype.hasOwnProperty.call(values, reference.baseName)) {
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
const value = getGlobal(reference.baseName);
|
|
472
|
+
if (value !== undefined) {
|
|
473
|
+
Object.defineProperty(values, reference.baseName, {
|
|
474
|
+
configurable: true,
|
|
475
|
+
enumerable: true,
|
|
476
|
+
value,
|
|
477
|
+
writable: true,
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
return values;
|
|
482
|
+
}
|
|
455
483
|
/** Extracts base port names only. Prefer `extractInterpolationVariableReferences` when type selection matters. */
|
|
456
484
|
export function extractInterpolationVariables(template) {
|
|
457
485
|
return extractInterpolationVariableReferences(template).map((reference) => reference.baseName);
|
|
@@ -464,6 +492,8 @@ function getInterpolationSource(reference, sources) {
|
|
|
464
492
|
return sources.graphInputValues;
|
|
465
493
|
case 'context':
|
|
466
494
|
return sources.contextValues;
|
|
495
|
+
case 'globals':
|
|
496
|
+
return sources.globalValues;
|
|
467
497
|
}
|
|
468
498
|
}
|
|
469
499
|
/**
|
|
@@ -503,6 +533,7 @@ export function resolveExpressionRawValue(source, expression, sourceType) {
|
|
|
503
533
|
return resolveInterpolationExpressionRawValue(`@${sourceType}.${expression}`, {
|
|
504
534
|
graphInputValues: sourceType === 'graphInputs' ? source : undefined,
|
|
505
535
|
contextValues: sourceType === 'context' ? source : undefined,
|
|
536
|
+
globalValues: sourceType === 'globals' ? source : undefined,
|
|
506
537
|
});
|
|
507
538
|
}
|
|
508
539
|
function stringifyInterpolationValue(value) {
|
|
@@ -557,6 +588,7 @@ export function interpolate(template, variables, graphInputValues, contextValues
|
|
|
557
588
|
variables,
|
|
558
589
|
graphInputValues,
|
|
559
590
|
contextValues,
|
|
591
|
+
globalValues: options.globalValues,
|
|
560
592
|
unwrapVariableDataValues: options.unwrapVariableDataValues,
|
|
561
593
|
});
|
|
562
594
|
if (resolvedValue === undefined) {
|
|
@@ -574,10 +606,11 @@ export function interpolate(template, variables, graphInputValues, contextValues
|
|
|
574
606
|
});
|
|
575
607
|
}
|
|
576
608
|
/** Runtime helper injected into JavaScript runners without exposing the whole Rivet API. */
|
|
577
|
-
export function resolveCodeInterpolationExpression(inputs, expression, graphInputValues, contextValues) {
|
|
609
|
+
export function resolveCodeInterpolationExpression(inputs, expression, graphInputValues, contextValues, globalValues) {
|
|
578
610
|
return resolveInterpolationExpressionRawValue(expression, {
|
|
579
611
|
variables: inputs,
|
|
580
612
|
graphInputValues,
|
|
581
613
|
contextValues,
|
|
614
|
+
globalValues,
|
|
582
615
|
});
|
|
583
616
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { formatUiGraphNormalizationIssue, normalizeUiGraphRecord, UiGraphNormalizationError, } from '../../model/UiGraphNormalization.js';
|
|
2
2
|
import { prepareSerializedInput } from './serializationInput.js';
|
|
3
3
|
import { isReservedKnowledgeObjectKey, normalizeKnowledgeConnectionId, normalizeKnowledgeMetadata, } from '../../integrations/KnowledgeStoreValidation.js';
|
|
4
|
+
import { validateProjectGlobalVariables } from '../../model/GlobalVariables.js';
|
|
4
5
|
export class ProjectValidationError extends Error {
|
|
5
6
|
validation;
|
|
6
7
|
constructor(validation) {
|
|
@@ -29,6 +30,14 @@ export function validateProject(project) {
|
|
|
29
30
|
errors.push('Missing project metadata.title');
|
|
30
31
|
if (meta.knowledgeStores != null)
|
|
31
32
|
validateKnowledgeStores(meta.knowledgeStores, errors);
|
|
33
|
+
if (meta.globalVariables != null) {
|
|
34
|
+
try {
|
|
35
|
+
validateProjectGlobalVariables(meta.globalVariables);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
errors.push(error instanceof Error ? error.message : String(error));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
32
41
|
}
|
|
33
42
|
// Graphs checks
|
|
34
43
|
if (!p.graphs || typeof p.graphs !== 'object') {
|
|
@@ -3,6 +3,7 @@ import { doubleCheckProject } from './serializationUtils.js';
|
|
|
3
3
|
import { entries } from '../typeSafety.js';
|
|
4
4
|
import {} from '../../model/Project.js';
|
|
5
5
|
import { normalizeUiGraphRecord } from '../../model/UiGraphNormalization.js';
|
|
6
|
+
import { validateProjectGlobalVariables } from '../../model/GlobalVariables.js';
|
|
6
7
|
import { serializeConnection, deserializeConnection, parseVisualData, packVisualDataV4, wrapInYamlEnvelope, unwrapYamlEnvelope, } from './serializationHelpers.js';
|
|
7
8
|
export function projectV4Deserializer(data) {
|
|
8
9
|
const serializedProject = unwrapYamlEnvelope(data, 4, 'Project v4');
|
|
@@ -15,6 +16,12 @@ export function graphV4Deserializer(data) {
|
|
|
15
16
|
return fromSerializedGraph(serializedGraph);
|
|
16
17
|
}
|
|
17
18
|
export function projectV4Serializer(project, attachedData) {
|
|
19
|
+
// Project Settings canonicalizes these values, but integrations and callers
|
|
20
|
+
// can author Project objects directly. Never write a project file that will
|
|
21
|
+
// later fail its own project-global validation at load or execution time.
|
|
22
|
+
if (project.metadata.globalVariables != null) {
|
|
23
|
+
validateProjectGlobalVariables(project.metadata.globalVariables);
|
|
24
|
+
}
|
|
18
25
|
const filteredProject = {
|
|
19
26
|
...project,
|
|
20
27
|
metadata: {
|
package/dist/types/exports.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export * from './model/NodeImpl.js';
|
|
|
24
24
|
export * from './model/NodeDefinition.js';
|
|
25
25
|
export * from './model/Nodes.js';
|
|
26
26
|
export * from './model/Project.js';
|
|
27
|
+
export * from './model/GlobalVariables.js';
|
|
27
28
|
export * from './native/BaseDir.js';
|
|
28
29
|
export * from './native/NativeApi.js';
|
|
29
30
|
export * from './native/BrowserNativeApi.js';
|
|
@@ -68,7 +69,7 @@ export * from './integrations/Tokenizer.js';
|
|
|
68
69
|
export * from './integrations/GptTokenizerTokenizer.js';
|
|
69
70
|
export { JS_LIST_CALLBACK_LOCAL_NAMES, interpolateJSListCallbackBody } from './model/nodes/jsListCallbackHelpers.js';
|
|
70
71
|
export { findAutoDelegateGraphCandidate } from './model/nodes/toolCallDelegation.js';
|
|
71
|
-
export { extractInterpolationVariables, extractInterpolationVariableReferences, findInterpolationTokenSpans, getInterpolationTokenReference, getInterpolationTokenName, interpolate, parseInterpolationExpression, parseInterpolationTemplate, protectEscapedInterpolationTokens, resolveCodeInterpolationExpression, resolveInterpolationExpressionRawValue, resolveInterpolationTokenRawValue, restoreEscapedInterpolationTokens, stringifyInterpolationSourceValue, } from './utils/interpolation.js';
|
|
72
|
+
export { extractInterpolationVariables, extractInterpolationVariableReferences, findInterpolationTokenSpans, getInterpolationGlobalValues, getInterpolationTokenReference, getInterpolationTokenName, interpolate, parseInterpolationExpression, parseInterpolationTemplate, protectEscapedInterpolationTokens, resolveCodeInterpolationExpression, resolveInterpolationExpressionRawValue, resolveInterpolationTokenRawValue, restoreEscapedInterpolationTokens, stringifyInterpolationSourceValue, } from './utils/interpolation.js';
|
|
72
73
|
export type { InterpolateOptions, InterpolationReferenceSource, InterpolationTokenReplacementInfo, InterpolationTokenSpan, InterpolationValueSources, InterpolationVariableReference, ParsedInterpolationExpression, ParsedInterpolationTemplate, ParsedInterpolationToken, ReplaceInterpolationTokensOptions, } from './utils/interpolation.js';
|
|
73
74
|
export { scanInterpolationTokenSpans } from './utils/interpolationSyntax.js';
|
|
74
75
|
export { WarningsPort } from './utils/symbols.js';
|
|
@@ -12,11 +12,11 @@ export type { CodeRunnerOptions } from './CodeRunnerOptions.js';
|
|
|
12
12
|
*/
|
|
13
13
|
/** An object that can run arbitrary code (evals it). */
|
|
14
14
|
export interface CodeRunner {
|
|
15
|
-
runCode: (code: string, inputs: Inputs, options: CodeRunnerOptions, graphInputs?: Record<string, DataValue>, contextValues?: Record<string, DataValue>) => Promise<Outputs>;
|
|
15
|
+
runCode: (code: string, inputs: Inputs, options: CodeRunnerOptions, graphInputs?: Record<string, DataValue>, contextValues?: Record<string, DataValue>, globalValues?: Record<string, DataValue>) => Promise<Outputs>;
|
|
16
16
|
}
|
|
17
17
|
export declare class IsomorphicCodeRunner implements CodeRunner {
|
|
18
|
-
runCode(code: string, inputs: Inputs, options: CodeRunnerOptions, graphInputs?: Record<string, DataValue>, contextValues?: Record<string, DataValue>): Promise<Outputs>;
|
|
18
|
+
runCode(code: string, inputs: Inputs, options: CodeRunnerOptions, graphInputs?: Record<string, DataValue>, contextValues?: Record<string, DataValue>, globalValues?: Record<string, DataValue>): Promise<Outputs>;
|
|
19
19
|
}
|
|
20
20
|
export declare class NotAllowedCodeRunner implements CodeRunner {
|
|
21
|
-
runCode(_code: string, _inputs: Inputs, _options: CodeRunnerOptions, _graphInputs?: Record<string, DataValue>, _contextValues?: Record<string, DataValue>): Promise<Outputs>;
|
|
21
|
+
runCode(_code: string, _inputs: Inputs, _options: CodeRunnerOptions, _graphInputs?: Record<string, DataValue>, _contextValues?: Record<string, DataValue>, _globalValues?: Record<string, DataValue>): Promise<Outputs>;
|
|
22
22
|
}
|
|
@@ -20,5 +20,10 @@ export interface CodeRunnerOptions {
|
|
|
20
20
|
* and @graphInputs/@context references depend on that contract.
|
|
21
21
|
*/
|
|
22
22
|
interpolationHelperIdentifier?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The collision-safe name of the globals snapshot injected beside the
|
|
25
|
+
* interpolation helper. Generated wrappers use it only for @globals paths.
|
|
26
|
+
*/
|
|
27
|
+
globalValuesIdentifier?: string;
|
|
23
28
|
}
|
|
24
29
|
export declare const ALL_CODE_RUNNER_OPTIONS: CodeRunnerOptions;
|
|
@@ -39,5 +39,5 @@ export declare function getMCPServerEditors<T extends ChartNode<string, MCPBaseN
|
|
|
39
39
|
export declare function getMCPBaseBody(data: MCPBaseNodeData, context: RivetUIContext): string;
|
|
40
40
|
export declare function requireMCPProvider(context: InternalProcessContext): MCPProvider;
|
|
41
41
|
export declare function resolveMCPServer(data: MCPBaseNodeData, inputs: Inputs, context: InternalProcessContext): Promise<MCPResolvedServer | undefined>;
|
|
42
|
-
export declare function interpolateMCPArgumentTemplate(template: string, inputs: Inputs, graphInputValues?: Record<string, DataValue>, contextValues?: Record<string, DataValue>): string;
|
|
42
|
+
export declare function interpolateMCPArgumentTemplate(template: string, inputs: Inputs, graphInputValues?: Record<string, DataValue>, contextValues?: Record<string, DataValue>, globalValues?: Record<string, unknown>): string;
|
|
43
43
|
export declare function getMCPArgumentTemplateInputs(template: string | undefined): NodeInputDefinition[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Outputs } from './GraphProcessor.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a cycle-safe copy at an execution-data ownership boundary.
|
|
4
|
+
*
|
|
5
|
+
* Providers may continue mutating output objects after a partial event. A
|
|
6
|
+
* snapshot, recorder, or deferred branch must therefore never retain the
|
|
7
|
+
* producer-owned reference.
|
|
8
|
+
*/
|
|
9
|
+
export declare function cloneExecutionValue<T>(value: T): T;
|
|
10
|
+
/** Creates a cycle-safe snapshot specifically for a node output map. */
|
|
11
|
+
export declare function cloneExecutionOutputs(outputs: Outputs): Outputs;
|
|
@@ -5,8 +5,9 @@ import type { GraphId, NodeGraph } from './NodeGraph.js';
|
|
|
5
5
|
import type { ChatV2CallTraceEvent, EvaluationExecutionMetadata, GraphExecutionMetadata, LLMProfileAttemptTraceEvent, LLMChatOutputSnapshotEvent, ProcessId, ToolCallFinishedEvent } from './ProcessContext.js';
|
|
6
6
|
import type { Project, ProjectId } from './Project.js';
|
|
7
7
|
import type { Settings } from './Settings.js';
|
|
8
|
-
import type { FrozenNodeOutputsByGraph, NodeResultOrigin, ReplayEventTiming } from './GraphProcessor.js';
|
|
8
|
+
import type { EventOccurrenceTiming, FrozenNodeOutputsByGraph, NodeResultOrigin, ReplayEventTiming } from './GraphProcessor.js';
|
|
9
9
|
import type { GraphProgress } from './GraphProgress.js';
|
|
10
|
+
import type { StreamingOutputWatchHistorySummary } from './StreamingOutputWatchHistory.js';
|
|
10
11
|
import type { RivetWebAppStorage } from './UiGraphWebAppStorage.js';
|
|
11
12
|
export type GraphInputs = Record<string, DataValue>;
|
|
12
13
|
export type GraphOutputs = Record<string, DataValue>;
|
|
@@ -20,7 +21,7 @@ export type CodeConsoleMessage = {
|
|
|
20
21
|
};
|
|
21
22
|
type WithExecution<T extends object> = T & {
|
|
22
23
|
execution: GraphExecutionMetadata;
|
|
23
|
-
} & ReplayEventTiming;
|
|
24
|
+
} & ReplayEventTiming & EventOccurrenceTiming;
|
|
24
25
|
export type SerializedProcessEventMap = {
|
|
25
26
|
start: WithExecution<{
|
|
26
27
|
project: Project;
|
|
@@ -66,6 +67,7 @@ export type SerializedProcessEventMap = {
|
|
|
66
67
|
resultOrigin?: NodeResultOrigin;
|
|
67
68
|
durationMs?: number;
|
|
68
69
|
splitRunDurationMs?: Record<number, number>;
|
|
70
|
+
streamingWatchTerminal?: boolean;
|
|
69
71
|
}>;
|
|
70
72
|
nodeError: WithExecution<{
|
|
71
73
|
node: ChartNode;
|
|
@@ -116,6 +118,10 @@ export type SerializedProcessEventMap = {
|
|
|
116
118
|
node: ChartNode;
|
|
117
119
|
processId?: ProcessId;
|
|
118
120
|
}>;
|
|
121
|
+
streamingOutputWatchSummary: WithExecution<{
|
|
122
|
+
watchNode: ChartNode;
|
|
123
|
+
summary: StreamingOutputWatchHistorySummary;
|
|
124
|
+
}>;
|
|
119
125
|
error: {
|
|
120
126
|
error: Error | string;
|
|
121
127
|
} & ReplayEventTiming;
|
|
@@ -171,6 +177,7 @@ export type ProcessEventMessageMap = {
|
|
|
171
177
|
llmProfileAttempt: SerializedProcessEventMap['llmProfileAttempt'];
|
|
172
178
|
toolCallFinished: SerializedProcessEventMap['toolCallFinished'];
|
|
173
179
|
nodeOutputsCleared: SerializedProcessEventMap['nodeOutputsCleared'];
|
|
180
|
+
streamingOutputWatchSummary: SerializedProcessEventMap['streamingOutputWatchSummary'];
|
|
174
181
|
error: SerializedProcessEventMap['error'];
|
|
175
182
|
graphError: SerializedProcessEventMap['graphError'];
|
|
176
183
|
trace: string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ScalarOrArrayDataType, type ScalarOrArrayDataValue } from './DataValue.js';
|
|
2
|
+
import type { Project, ProjectId } from './Project.js';
|
|
3
|
+
/**
|
|
4
|
+
* A JSON-safe representation of a global value authored in project metadata.
|
|
5
|
+
*
|
|
6
|
+
* The marker is intentionally private to this codec. User objects with the
|
|
7
|
+
* marker key are escaped, so no ordinary object can be mistaken for a value
|
|
8
|
+
* sentinel after a project is saved and loaded again.
|
|
9
|
+
*/
|
|
10
|
+
/** Runtime validation, rather than a recursive TypeScript JSON type, keeps Project usable with Immer. */
|
|
11
|
+
export type ProjectGlobalVariableLiteral = unknown;
|
|
12
|
+
export type ProjectGlobalVariableDefinition = {
|
|
13
|
+
type: ScalarOrArrayDataType;
|
|
14
|
+
value: ProjectGlobalVariableLiteral;
|
|
15
|
+
};
|
|
16
|
+
export type ProjectGlobalVariables = Record<string, ProjectGlobalVariableDefinition>;
|
|
17
|
+
/** Encodes a normal global value into a portable project-file definition. */
|
|
18
|
+
export declare function encodeProjectGlobalVariable(value: ScalarOrArrayDataValue): ProjectGlobalVariableDefinition;
|
|
19
|
+
/** Decodes and validates a single portable project-file global definition. */
|
|
20
|
+
export declare function decodeProjectGlobalVariable(value: unknown, label?: string): ScalarOrArrayDataValue;
|
|
21
|
+
/** Validates definitions without retaining decoded runtime values. */
|
|
22
|
+
export declare function validateProjectGlobalVariables(value: unknown, label?: string): void;
|
|
23
|
+
export declare function getProjectGlobalVariableIds(project: Pick<Project, 'metadata'> | undefined): string[];
|
|
24
|
+
/**
|
|
25
|
+
* Resolves referenced projects depth-first in reference order, then the root
|
|
26
|
+
* project. Later definitions intentionally replace earlier ones; the root
|
|
27
|
+
* project therefore always wins a collision with one of its references.
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveProjectGlobalVariables(rootProject: Project, loadedProjects: Readonly<Record<ProjectId, Project>>): Map<string, ScalarOrArrayDataValue>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ScalarOrArrayDataValue } from './DataValue.js';
|
|
1
|
+
import type { DataValue, ScalarOrArrayDataValue } from './DataValue.js';
|
|
2
2
|
import type { GraphOutputs, Outputs } from './GraphProcessor.js';
|
|
3
3
|
import type { ChartNode } from './NodeBase.js';
|
|
4
4
|
import type { RivetStoredValue } from './StoredValueStore.js';
|
|
@@ -13,5 +13,11 @@ export type FrozenSetStoredValueEffect = {
|
|
|
13
13
|
value: RivetStoredValue;
|
|
14
14
|
};
|
|
15
15
|
export type FrozenGraphBoundaryEffect = FrozenSetGlobalEffect | FrozenSetStoredValueEffect;
|
|
16
|
+
/**
|
|
17
|
+
* Graph Outputs with the same public ID retain the first non-excluded value.
|
|
18
|
+
* Normal execution, frozen replay, and control-flow exclusion all use this
|
|
19
|
+
* single boundary rule.
|
|
20
|
+
*/
|
|
21
|
+
export declare function commitGraphOutputValue(graphOutputs: GraphOutputs, outputId: string, value: DataValue): void;
|
|
16
22
|
export declare function ensureGraphCostOutput(graphOutputs: GraphOutputs, totalCost: number): void;
|
|
17
23
|
export declare function applyFrozenGraphBoundaryEffects(graphOutputs: GraphOutputs, node: ChartNode, outputValues: Outputs): FrozenGraphBoundaryEffect | undefined;
|
|
@@ -12,6 +12,7 @@ import { type GraphExecutionPlan } from './GraphPreprocessor.js';
|
|
|
12
12
|
import { type GraphBoundaryCache } from './GraphBoundaryCache.js';
|
|
13
13
|
import { type GraphProgress } from './GraphProgress.js';
|
|
14
14
|
import { type RivetStoredValueStore } from './StoredValueStore.js';
|
|
15
|
+
import { type StreamingOutputWatchHistorySummary } from './StreamingOutputWatchHistory.js';
|
|
15
16
|
import type { RivetKnowledgeStoreRegistry } from '../integrations/KnowledgeStore.js';
|
|
16
17
|
/**
|
|
17
18
|
* Provenance attached only while RecordingPlayer re-emits a historical event.
|
|
@@ -21,11 +22,20 @@ import type { RivetKnowledgeStoreRegistry } from '../integrations/KnowledgeStore
|
|
|
21
22
|
export type ReplayEventTiming = {
|
|
22
23
|
replayRecordedAt?: number;
|
|
23
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Timestamp carried by a delayed-but-retained execution event. Delivery may
|
|
27
|
+
* happen after a Watch settles; observability must still use this original
|
|
28
|
+
* occurrence time rather than the later emitter receipt time.
|
|
29
|
+
*/
|
|
30
|
+
export type EventOccurrenceTiming = {
|
|
31
|
+
eventOccurredAt?: number;
|
|
32
|
+
};
|
|
24
33
|
type WithExecution<T extends object> = T & {
|
|
25
34
|
execution: GraphExecutionMetadata;
|
|
26
|
-
} & ReplayEventTiming;
|
|
35
|
+
} & ReplayEventTiming & EventOccurrenceTiming;
|
|
27
36
|
declare const graphProcessorGraphOverride: unique symbol;
|
|
28
37
|
declare const consumedAsyncBranchTriggerOverride: unique symbol;
|
|
38
|
+
declare const consumedStreamingWatchNodeOverride: unique symbol;
|
|
29
39
|
export type NodeResultOrigin = 'executed' | 'preloaded' | 'frozen' | 'editor-cache' | 'unknown';
|
|
30
40
|
export type ProcessEvents = {
|
|
31
41
|
/** Called when processing has started. */
|
|
@@ -78,6 +88,8 @@ export type ProcessEvents = {
|
|
|
78
88
|
resultOrigin?: NodeResultOrigin;
|
|
79
89
|
durationMs?: number;
|
|
80
90
|
splitRunDurationMs?: Record<number, number>;
|
|
91
|
+
/** True only for the one Stop result accepted by a repeated Watch branch. */
|
|
92
|
+
streamingWatchTerminal?: boolean;
|
|
81
93
|
}>;
|
|
82
94
|
/** Called when a node has errored during processing. */
|
|
83
95
|
nodeError: WithExecution<{
|
|
@@ -148,6 +160,11 @@ export type ProcessEvents = {
|
|
|
148
160
|
node: ChartNode;
|
|
149
161
|
processId?: ProcessId;
|
|
150
162
|
}>;
|
|
163
|
+
/** Compact accounting for a completed Watch Streaming Output boundary. */
|
|
164
|
+
streamingOutputWatchSummary: WithExecution<{
|
|
165
|
+
watchNode: ChartNode;
|
|
166
|
+
summary: StreamingOutputWatchHistorySummary;
|
|
167
|
+
}>;
|
|
151
168
|
/** Called when the root graph has errored. The root graph will also throw. */
|
|
152
169
|
error: {
|
|
153
170
|
error: Error | string;
|
|
@@ -194,6 +211,13 @@ export type ProcessEvent = {
|
|
|
194
211
|
}[keyof ProcessEvents];
|
|
195
212
|
export type GraphOutputs = Record<string, DataValue>;
|
|
196
213
|
export type GraphInputs = Record<string, DataValue>;
|
|
214
|
+
/**
|
|
215
|
+
* Ephemeral named Graph Output updates. This is deliberately an in-process
|
|
216
|
+
* callback rather than a ProcessEvent: it bridges a named graph-boundary
|
|
217
|
+
* caller's execution boundary for a parent Watch without adding a second
|
|
218
|
+
* recorded/node-history stream for every token.
|
|
219
|
+
*/
|
|
220
|
+
type GraphOutputPartialListener = (outputs: GraphOutputs) => void;
|
|
197
221
|
export type NodeResults = Map<NodeId, Outputs>;
|
|
198
222
|
export type Inputs = NodeInputs;
|
|
199
223
|
export type Outputs = NodeOutputs;
|
|
@@ -205,7 +229,21 @@ export type FrozenNodeOutputResolverRequest = {
|
|
|
205
229
|
node: ChartNode;
|
|
206
230
|
processId: ProcessId;
|
|
207
231
|
};
|
|
208
|
-
export type
|
|
232
|
+
export type FrozenNodeOutputEligibilityRequest = Pick<FrozenNodeOutputResolverRequest, 'graphId' | 'node'>;
|
|
233
|
+
/**
|
|
234
|
+
* A resolver may expose this non-consuming predicate when it can determine
|
|
235
|
+
* whether a node has frozen output without advancing its replay cursor.
|
|
236
|
+
* Streaming topology preparation uses it to keep a frozen named boundary
|
|
237
|
+
* final-only; custom resolvers without the predicate are conservatively
|
|
238
|
+
* treated as unknown rather than invoked speculatively. Return `false` only
|
|
239
|
+
* when this resolver cannot produce frozen output for the node in this run;
|
|
240
|
+
* returning `true` is allowed to be conservative and merely makes the
|
|
241
|
+
* boundary final-only.
|
|
242
|
+
*/
|
|
243
|
+
export type FrozenNodeOutputResolver = {
|
|
244
|
+
(request: FrozenNodeOutputResolverRequest): Outputs | undefined;
|
|
245
|
+
hasFrozenNodeOutput?: (request: FrozenNodeOutputEligibilityRequest) => boolean;
|
|
246
|
+
};
|
|
209
247
|
export declare function cloneFrozenNodeOutputs(outputs: Outputs): Outputs;
|
|
210
248
|
export declare function cloneFrozenNodeOutputsByGraph(outputsByGraph: FrozenNodeOutputsByGraph): FrozenNodeOutputsByGraph;
|
|
211
249
|
export declare function hasFrozenNodeOutputs(outputsByGraph: FrozenNodeOutputsByGraph | undefined): boolean;
|
|
@@ -226,7 +264,7 @@ export type GraphProcessorRuntimeCache = {
|
|
|
226
264
|
};
|
|
227
265
|
export type GraphProcessorExecutionPlanCacheMode = 'all' | 'subprocessors';
|
|
228
266
|
export type GraphProcessorScheduler = 'compatible' | 'fast-acyclic';
|
|
229
|
-
export type GraphProcessorRuntimeProfileBucket = 'initializeGraphRun' | 'loadProjectReferences' | 'prepareNodeProcessContextBase' | 'preprocessGraph' | 'emitGraphStart' | 'emitPreloadedNodeResults' | 'waitUntilUnpaused' | 'processFastAcyclicGraph' | 'processCompatibleGraph' | 'drainManagedAsyncBranches' | 'throwIfGraphErrored' | 'finalizeGraphRun' | 'emitFinish' | 'fetchNodeDataAndProcessNode' | 'getInputNodesTo' | 'getInputValuesForNode' | 'nodeDispatch' | 'nodeImplementation' | 'createNodeProcessContext' | 'getOutputNodesFrom' | 'queueOutputNodes' | 'createSubProcessor' | 'wireSubProcessorEvents' | 'wireSubProcessorLifecycle';
|
|
267
|
+
export type GraphProcessorRuntimeProfileBucket = 'initializeGraphRun' | 'loadProjectReferences' | 'initializeProjectGlobalVariables' | 'prepareNodeProcessContextBase' | 'preprocessGraph' | 'emitGraphStart' | 'emitInitialProjectGlobalVariables' | 'emitPreloadedNodeResults' | 'waitUntilUnpaused' | 'processFastAcyclicGraph' | 'processCompatibleGraph' | 'drainManagedAsyncBranches' | 'drainStreamingOutputWatches' | 'throwIfGraphErrored' | 'finalizeGraphRun' | 'emitFinish' | 'fetchNodeDataAndProcessNode' | 'getInputNodesTo' | 'getInputValuesForNode' | 'nodeDispatch' | 'nodeImplementation' | 'createNodeProcessContext' | 'getOutputNodesFrom' | 'queueOutputNodes' | 'createSubProcessor' | 'wireSubProcessorEvents' | 'wireSubProcessorLifecycle';
|
|
230
268
|
export type GraphProcessorRuntimeProfiler = {
|
|
231
269
|
addDuration: (bucket: GraphProcessorRuntimeProfileBucket, durationMs: number) => void;
|
|
232
270
|
};
|
|
@@ -277,6 +315,7 @@ export declare class GraphProcessor {
|
|
|
277
315
|
scheduler?: GraphProcessorScheduler;
|
|
278
316
|
[graphProcessorGraphOverride]?: NodeGraph;
|
|
279
317
|
[consumedAsyncBranchTriggerOverride]?: NodeId;
|
|
318
|
+
[consumedStreamingWatchNodeOverride]?: NodeId;
|
|
280
319
|
});
|
|
281
320
|
on: Emittery<ProcessEvents>["on"];
|
|
282
321
|
off: Emittery<ProcessEvents>["off"];
|
|
@@ -311,6 +350,13 @@ export declare class GraphProcessor {
|
|
|
311
350
|
returnWhenGraphOutputsReady?: boolean;
|
|
312
351
|
/** Restrict this invocation to named graph outputs and their prerequisites. Cannot be combined with runToNodeIds. */
|
|
313
352
|
requestedGraphOutputIds?: readonly string[];
|
|
353
|
+
/**
|
|
354
|
+
* Receives partial values only when a producer directly feeds a named
|
|
355
|
+
* Graph Output. Used internally to stream a named graph-boundary caller
|
|
356
|
+
* output to its parent without changing the persisted graph or public
|
|
357
|
+
* event protocol.
|
|
358
|
+
*/
|
|
359
|
+
onGraphOutputPartial?: GraphOutputPartialListener;
|
|
314
360
|
}): Promise<GraphOutputs>;
|
|
315
361
|
getRootProcessor(): GraphProcessor;
|
|
316
362
|
/** Raise a user event on the processor, all subprocessors, and their children. */
|