@valerypopoff/rivet2-core 2.6.0 → 2.7.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.
Files changed (70) hide show
  1. package/dist/cjs/bundle.cjs +2735 -767
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/cjs/interpolationRuntime.cjs +7 -3
  4. package/dist/cjs/interpolationRuntime.cjs.map +2 -2
  5. package/dist/esm/api/createProcessor.js +3 -0
  6. package/dist/esm/exports.js +2 -1
  7. package/dist/esm/integrations/CodeRunner.js +6 -2
  8. package/dist/esm/integrations/mcp/MCPBase.js +2 -1
  9. package/dist/esm/model/ExecutionOutputClone.js +46 -0
  10. package/dist/esm/model/GlobalVariables.js +452 -0
  11. package/dist/esm/model/GraphBoundaryEffects.js +12 -4
  12. package/dist/esm/model/GraphProcessor.js +825 -41
  13. package/dist/esm/model/Nodes.js +6 -0
  14. package/dist/esm/model/ProcessContextBuilder.js +3 -1
  15. package/dist/esm/model/ProjectReferenceLoader.js +36 -1
  16. package/dist/esm/model/RecordingPlayer.js +21 -4
  17. package/dist/esm/model/StreamingOutputWatch.js +262 -0
  18. package/dist/esm/model/StreamingOutputWatchHistory.js +161 -0
  19. package/dist/esm/model/SubprocessorBridge.js +29 -19
  20. package/dist/esm/model/chat-v2/llmChatV2OutputClone.js +3 -42
  21. package/dist/esm/model/nodes/CodeNewNode.js +4 -1
  22. package/dist/esm/model/nodes/ExpressionNode.js +4 -1
  23. package/dist/esm/model/nodes/ExtractObjectPathNode.js +4 -4
  24. package/dist/esm/model/nodes/GraphOutputNode.js +13 -8
  25. package/dist/esm/model/nodes/MCPGetPromptNode.js +2 -1
  26. package/dist/esm/model/nodes/MCPToolCallNode.js +2 -1
  27. package/dist/esm/model/nodes/ObjectNode.js +5 -3
  28. package/dist/esm/model/nodes/PromptNode.js +5 -2
  29. package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +9 -1
  30. package/dist/esm/model/nodes/StopWatchingStreamingOutputNode.js +48 -0
  31. package/dist/esm/model/nodes/SubGraphNode.js +11 -1
  32. package/dist/esm/model/nodes/TextNode.js +5 -2
  33. package/dist/esm/model/nodes/ToTreeNode.js +10 -3
  34. package/dist/esm/model/nodes/ToolNode.js +5 -2
  35. package/dist/esm/model/nodes/WatchStreamingOutputNode.js +126 -0
  36. package/dist/esm/model/nodes/jsListCallbackHelpers.js +7 -1
  37. package/dist/esm/model/nodes/jsValueInterpolation.js +21 -4
  38. package/dist/esm/plugins/openai/nodes/ThreadMessageNode.js +2 -1
  39. package/dist/esm/recording/ExecutionRecorder.js +16 -7
  40. package/dist/esm/utils/interpolation.js +35 -2
  41. package/dist/esm/utils/serialization/serializationUtils.js +9 -0
  42. package/dist/esm/utils/serialization/serialization_v4.js +7 -0
  43. package/dist/types/exports.d.ts +2 -1
  44. package/dist/types/integrations/CodeRunner.d.ts +3 -3
  45. package/dist/types/integrations/CodeRunnerOptions.d.ts +5 -0
  46. package/dist/types/integrations/mcp/MCPBase.d.ts +1 -1
  47. package/dist/types/model/ExecutionOutputClone.d.ts +11 -0
  48. package/dist/types/model/ExecutorProtocol.d.ts +8 -2
  49. package/dist/types/model/GlobalVariables.d.ts +29 -0
  50. package/dist/types/model/GraphBoundaryEffects.d.ts +7 -1
  51. package/dist/types/model/GraphProcessor.d.ts +47 -3
  52. package/dist/types/model/Nodes.d.ts +4 -2
  53. package/dist/types/model/ProcessContext.d.ts +14 -0
  54. package/dist/types/model/ProcessContextBuilder.d.ts +3 -1
  55. package/dist/types/model/Project.d.ts +7 -1
  56. package/dist/types/model/ProjectReferenceLoader.d.ts +15 -1
  57. package/dist/types/model/StreamingOutputWatch.d.ts +74 -0
  58. package/dist/types/model/StreamingOutputWatchHistory.d.ts +58 -0
  59. package/dist/types/model/SubprocessorBridge.d.ts +2 -0
  60. package/dist/types/model/chat-v2/llmChatV2OutputClone.d.ts +3 -3
  61. package/dist/types/model/nodes/ExtractObjectPathNode.d.ts +1 -1
  62. package/dist/types/model/nodes/GraphOutputNode.d.ts +8 -1
  63. package/dist/types/model/nodes/ObjectNode.d.ts +1 -1
  64. package/dist/types/model/nodes/StopWatchingStreamingOutputNode.d.ts +14 -0
  65. package/dist/types/model/nodes/ToTreeNode.d.ts +5 -1
  66. package/dist/types/model/nodes/WatchStreamingOutputNode.d.ts +17 -0
  67. package/dist/types/model/nodes/jsValueInterpolation.d.ts +10 -1
  68. package/dist/types/recording/RecordedEvents.d.ts +7 -0
  69. package/dist/types/utils/interpolation.d.ts +14 -5
  70. package/package.json +1 -1
@@ -1,42 +1,3 @@
1
- /**
2
- * Copies displayed LLM Chat outputs at an ownership boundary. Provider and
3
- * continuation code intentionally continues to accumulate messages, usage,
4
- * reasoning, and direct results after intermediate rounds complete; historical
5
- * pages must therefore never retain those mutable references.
6
- */
7
- function cloneOutputValue(value, seen = new WeakMap()) {
8
- if (value == null || typeof value !== 'object') {
9
- return value;
10
- }
11
- if (value instanceof Uint8Array) {
12
- return new Uint8Array(value);
13
- }
14
- const existing = seen.get(value);
15
- if (existing != null) {
16
- return existing;
17
- }
18
- if (Array.isArray(value)) {
19
- const clone = [];
20
- seen.set(value, clone);
21
- clone.push(...value.map((item) => cloneOutputValue(item, seen)));
22
- return clone;
23
- }
24
- const clone = {};
25
- seen.set(value, clone);
26
- for (const [key, item] of Object.entries(value)) {
27
- clone[key] = cloneOutputValue(item, seen);
28
- }
29
- return clone;
30
- }
31
- /** Cycle-safe clone shared by the editor cache and LLM logical-round snapshots. */
32
- export function cloneLLMChatV2Outputs(outputs) {
33
- if (typeof structuredClone === 'function') {
34
- try {
35
- return structuredClone(outputs);
36
- }
37
- catch {
38
- // Fall through for values structuredClone cannot copy.
39
- }
40
- }
41
- return cloneOutputValue(outputs);
42
- }
1
+ export { cloneExecutionOutputs } from '../ExecutionOutputClone.js';
2
+ /** @deprecated Prefer cloneExecutionOutputs for new non-Chat call sites. */
3
+ export { cloneExecutionOutputs as cloneLLMChatV2Outputs } from '../ExecutionOutputClone.js';
@@ -7,6 +7,7 @@ import {} from '../NodeBodySpec.js';
7
7
  import { appendCodeNodeSourceUrl, buildCodeNodeSourceUrl, enrichCodeNodeErrorWithLocation, } from './codeNodeErrorDiagnostics.js';
8
8
  import { buildJsValueInterpolatedSource, buildJsValueInputsInitializer, buildJsValuePreview, getJsValueInterpolationCodeRunnerOptions, getJsValueInterpolationInputDefinitions, getJsValueInterpolationRuntimeContext, interpolateJsValuePreviewSource, sanitizeGeneratedJsValueError, } from './jsValueInterpolation.js';
9
9
  import { ALL_CODE_RUNNER_OPTIONS } from '../../integrations/CodeRunnerOptions.js';
10
+ import { getInterpolationGlobalValues } from '../../utils/interpolation.js';
10
11
  const CODE_RUNTIME_HELPER_MESSAGE = 'Node execution also provides "require" and "process". Browser execution provides "fetch", "console", and "Rivet".';
11
12
  const DEFAULT_CODE_NEW = dedent `
12
13
  // This is a Code node. Write JavaScript here and return one value.
@@ -36,6 +37,8 @@ function sanitizeCodeNewError(error, interpolationContext) {
36
37
  return sanitizeGeneratedJsValueError(error, interpolationContext.inputNames, interpolationContext.inputsIdentifier, 'code input', [
37
38
  interpolationContext.cloneCacheIdentifier,
38
39
  interpolationContext.contextIdentifier,
40
+ interpolationContext.globalValuesCloneIdentifier,
41
+ interpolationContext.globalValuesIdentifier,
39
42
  interpolationContext.graphInputsIdentifier,
40
43
  interpolationContext.interpolationHelperIdentifier,
41
44
  ]);
@@ -146,7 +149,7 @@ export class CodeNewNodeImpl extends NodeImpl {
146
149
  const interpolationContext = getJsValueInterpolationRuntimeContext(this.data.code, CODE_NEW_INPUTS_IDENTIFIER);
147
150
  const { source, userCodeLineOffset } = buildCodeNewWrapper(this.data.code, interpolationContext);
148
151
  try {
149
- const outputs = await context.codeRunner.runCode(appendCodeNodeSourceUrl(source, sourceUrl), inputs, getJsValueInterpolationCodeRunnerOptions(ALL_CODE_RUNNER_OPTIONS, interpolationContext), context.graphInputNodeValues, context.contextValues);
152
+ const outputs = await context.codeRunner.runCode(appendCodeNodeSourceUrl(source, sourceUrl), inputs, getJsValueInterpolationCodeRunnerOptions(ALL_CODE_RUNNER_OPTIONS, interpolationContext), context.graphInputNodeValues, context.contextValues, getInterpolationGlobalValues(this.data.code, context.getGlobal));
150
153
  return validateCodeNewRunnerOutputs(outputs);
151
154
  }
152
155
  catch (error) {
@@ -6,6 +6,7 @@ import { dedent } from 'ts-dedent';
6
6
  import { nodeDefinition } from '../NodeDefinition.js';
7
7
  import { buildJsValueInterpolatedSource, buildJsValueInputsInitializer, buildJsValuePreview, getJsValueInterpolationCodeRunnerOptions, getJsValueInterpolationInputDefinitions, getJsValueInterpolationRuntimeContext, interpolateJsValuePreviewSource, sanitizeGeneratedJsValueError, } from './jsValueInterpolation.js';
8
8
  import { ALL_CODE_RUNNER_OPTIONS } from '../../integrations/CodeRunnerOptions.js';
9
+ import { getInterpolationGlobalValues } from '../../utils/interpolation.js';
9
10
  const CODE_RUNTIME_HELPER_MESSAGE = 'Node execution also provides "require" and "process". Browser execution provides "fetch", "console", and "Rivet".';
10
11
  const DEFAULT_EXPRESSION = '{{a}} == "123" ? {{b}} : {{c}}';
11
12
  const MAX_BODY_PREVIEW_LINES = 15;
@@ -29,6 +30,8 @@ function sanitizeExpressionError(error, interpolationContext) {
29
30
  return sanitizeGeneratedJsValueError(error, interpolationContext.inputNames, interpolationContext.inputsIdentifier, 'expression input', [
30
31
  interpolationContext.cloneCacheIdentifier,
31
32
  interpolationContext.contextIdentifier,
33
+ interpolationContext.globalValuesCloneIdentifier,
34
+ interpolationContext.globalValuesIdentifier,
32
35
  interpolationContext.graphInputsIdentifier,
33
36
  interpolationContext.interpolationHelperIdentifier,
34
37
  ]);
@@ -114,7 +117,7 @@ export class ExpressionNodeImpl extends NodeImpl {
114
117
  const interpolationContext = getJsValueInterpolationRuntimeContext(this.data.expression, EXPRESSION_INPUTS_IDENTIFIER);
115
118
  const source = buildExpressionWrapper(this.data.expression, interpolationContext);
116
119
  try {
117
- return await context.codeRunner.runCode(source, inputs, getJsValueInterpolationCodeRunnerOptions(ALL_CODE_RUNNER_OPTIONS, interpolationContext), context.graphInputNodeValues, context.contextValues);
120
+ return await context.codeRunner.runCode(source, inputs, getJsValueInterpolationCodeRunnerOptions(ALL_CODE_RUNNER_OPTIONS, interpolationContext), context.graphInputNodeValues, context.contextValues, getInterpolationGlobalValues(this.data.expression, context.getGlobal));
118
121
  }
119
122
  catch (error) {
120
123
  throw sanitizeExpressionError(error, interpolationContext);
@@ -7,7 +7,7 @@ import { expectType } from '../../utils/expectType.js';
7
7
  import {} from '../../index.js';
8
8
  import { dedent } from 'ts-dedent';
9
9
  import { coerceTypeOptional } from '../../utils/coerceType.js';
10
- import { extractInterpolationVariables, interpolate } from '../../utils/interpolation.js';
10
+ import { extractInterpolationVariables, getInterpolationGlobalValues, interpolate } from '../../utils/interpolation.js';
11
11
  import { createInterpolationInputDefinition } from '../interpolationInputDefinition.js';
12
12
  import { evaluateJsonPath } from '../../utils/jsonPath.js';
13
13
  // Keep built-in ports from becoming implicit interpolation variables.
@@ -21,8 +21,8 @@ function buildExtractObjectPathInterpolationInputs(path, inputs) {
21
21
  RESERVED_INPUT_IDS.has(inputName) ? '' : inputs[inputName],
22
22
  ]));
23
23
  }
24
- export function interpolateExtractObjectPathSource(path, inputs, graphInputValues, contextValues) {
25
- return interpolate(path, buildExtractObjectPathInterpolationInputs(path, inputs), graphInputValues, contextValues).trim();
24
+ export function interpolateExtractObjectPathSource(path, inputs, graphInputValues, contextValues, globalValues) {
25
+ return interpolate(path, buildExtractObjectPathInterpolationInputs(path, inputs), graphInputValues, contextValues, { globalValues }).trim();
26
26
  }
27
27
  export class ExtractObjectPathNodeImpl extends NodeImpl {
28
28
  static create() {
@@ -122,7 +122,7 @@ export class ExtractObjectPathNodeImpl extends NodeImpl {
122
122
  }
123
123
  const inputPath = usePathInput
124
124
  ? rawPath.trim()
125
- : interpolateExtractObjectPathSource(rawPath, inputs, context.graphInputNodeValues, context.contextValues);
125
+ : interpolateExtractObjectPathSource(rawPath, inputs, context.graphInputNodeValues, context.contextValues, getInterpolationGlobalValues(rawPath, context.getGlobal));
126
126
  let matches;
127
127
  try {
128
128
  // Wrap doesn't seem to wrap when the input is undefined or null...
@@ -8,6 +8,7 @@ import {} from '../ProcessContext.js';
8
8
  import { dedent } from 'ts-dedent';
9
9
  import {} from '../EditorDefinition.js';
10
10
  import {} from '../NodeBodySpec.js';
11
+ import { commitGraphOutputValue } from '../GraphBoundaryEffects.js';
11
12
  function isPlainObjectRecordValue(value) {
12
13
  if (value === null || typeof value !== 'object' || Array.isArray(value)) {
13
14
  return false;
@@ -15,7 +16,13 @@ function isPlainObjectRecordValue(value) {
15
16
  const prototype = Object.getPrototypeOf(value);
16
17
  return prototype === Object.prototype || prototype === null;
17
18
  }
18
- function coerceAnyGraphOutputValue(value, dataType) {
19
+ /**
20
+ * Graph Output applies the same boundary coercion to both its terminal value
21
+ * and a partial value forwarded across a Subgraph boundary. Keeping this
22
+ * conversion here prevents a streamed named output from disagreeing with the
23
+ * value that the Graph Output will eventually publish.
24
+ */
25
+ export function coerceGraphOutputValue(value, dataType) {
19
26
  if (value.type === 'control-flow-excluded' || dataType === 'any' || value.type === dataType) {
20
27
  return value;
21
28
  }
@@ -105,18 +112,16 @@ export class GraphOutputNodeImpl extends NodeImpl {
105
112
  }
106
113
  async process(inputs, context) {
107
114
  const inputValue = inputs['value'];
108
- const value = coerceAnyGraphOutputValue(inputValue ?? { type: 'any', value: undefined }, this.data.dataType);
115
+ const value = coerceGraphOutputValue(inputValue ?? { type: 'any', value: undefined }, this.data.dataType);
109
116
  const isExcluded = value.type === 'control-flow-excluded';
110
117
  if (isExcluded && context.graphOutputs[this.data.id] == null) {
111
- context.graphOutputs[this.data.id] = {
118
+ commitGraphOutputValue(context.graphOutputs, this.data.id, {
112
119
  type: 'control-flow-excluded',
113
120
  value: undefined,
114
- };
121
+ });
115
122
  }
116
- else if ((context.graphOutputs[this.data.id] == null ||
117
- context.graphOutputs[this.data.id]?.type === 'control-flow-excluded') &&
118
- inputValue) {
119
- context.graphOutputs[this.data.id] = value;
123
+ else if (inputValue) {
124
+ commitGraphOutputValue(context.graphOutputs, this.data.id, value);
120
125
  }
121
126
  if (isExcluded) {
122
127
  return {
@@ -7,6 +7,7 @@ import {} from '../../index.js';
7
7
  import { MCPError, MCPErrorType } from '../../integrations/mcp/MCPProvider.js';
8
8
  import { dedent, getInputOrData } from '../../utils/index.js';
9
9
  import { getError } from '../../utils/errors.js';
10
+ import { getInterpolationGlobalValues } from '../../utils/interpolation.js';
10
11
  import { getMCPBaseBody, getMCPArgumentTemplateInputs, getMCPBaseInputs, getMCPClientEditors, getMCPServerEditors, interpolateMCPArgumentTemplate, requireMCPProvider, resolveMCPServer, } from '../../integrations/mcp/MCPBase.js';
11
12
  export class MCPGetPromptNodeImpl extends NodeImpl {
12
13
  static create() {
@@ -116,7 +117,7 @@ export class MCPGetPromptNodeImpl extends NodeImpl {
116
117
  }
117
118
  }
118
119
  else {
119
- promptArguments = JSON.parse(interpolateMCPArgumentTemplate(this.data.promptArguments ?? '', inputs, context.graphInputNodeValues, context.contextValues));
120
+ promptArguments = JSON.parse(interpolateMCPArgumentTemplate(this.data.promptArguments ?? '', inputs, context.graphInputNodeValues, context.contextValues, getInterpolationGlobalValues(this.data.promptArguments ?? '', context.getGlobal)));
120
121
  }
121
122
  const getPromptRequest = {
122
123
  name: promptName,
@@ -7,6 +7,7 @@ import {} from '../../index.js';
7
7
  import { MCPError, MCPErrorType } from '../../integrations/mcp/MCPProvider.js';
8
8
  import { getInputOrData } from '../../utils/index.js';
9
9
  import { getError } from '../../utils/errors.js';
10
+ import { getInterpolationGlobalValues } from '../../utils/interpolation.js';
10
11
  import { getMCPBaseBody, getMCPArgumentTemplateInputs, getMCPBaseInputs, getMCPClientEditors, getMCPServerEditors, interpolateMCPArgumentTemplate, requireMCPProvider, resolveMCPServer, } from '../../integrations/mcp/MCPBase.js';
11
12
  import { dedent } from 'ts-dedent';
12
13
  import {} from '../EditorDefinition.js';
@@ -140,7 +141,7 @@ export class MCPToolCallNodeImpl extends NodeImpl {
140
141
  }
141
142
  }
142
143
  else {
143
- toolArguments = JSON.parse(interpolateMCPArgumentTemplate(this.data.toolArguments ?? '', inputs, context.graphInputNodeValues, context.contextValues));
144
+ toolArguments = JSON.parse(interpolateMCPArgumentTemplate(this.data.toolArguments ?? '', inputs, context.graphInputNodeValues, context.contextValues, getInterpolationGlobalValues(this.data.toolArguments ?? '', context.getGlobal)));
144
145
  }
145
146
  const toolCall = {
146
147
  name: toolName,
@@ -5,7 +5,7 @@ import { nodeDefinition } from '../NodeDefinition.js';
5
5
  import {} from '../DataValue.js';
6
6
  import { dedent } from 'ts-dedent';
7
7
  import {} from '../EditorDefinition.js';
8
- import { extractInterpolationVariables, parseInterpolationTemplate, protectEscapedInterpolationTokens, resolveInterpolationExpressionRawValue, restoreEscapedInterpolationTokens, unwrapPotentialDataValue, } from '../../utils/interpolation.js';
8
+ import { extractInterpolationVariables, getInterpolationGlobalValues, parseInterpolationTemplate, protectEscapedInterpolationTokens, resolveInterpolationExpressionRawValue, restoreEscapedInterpolationTokens, unwrapPotentialDataValue, } from '../../utils/interpolation.js';
9
9
  import { createInterpolationInputDefinition } from '../interpolationInputDefinition.js';
10
10
  const DEFAULT_JSON_TEMPLATE = `{
11
11
  "key": "{{input}}"
@@ -116,7 +116,7 @@ export class ObjectNodeImpl extends NodeImpl {
116
116
  group: ['Objects'],
117
117
  };
118
118
  }
119
- interpolate(baseString, values, graphInputNodeValues, contextValues) {
119
+ interpolate(baseString, values, graphInputNodeValues, contextValues, globalValues) {
120
120
  const protectedBaseString = protectEscapedInterpolationTokens(baseString);
121
121
  const parsedTemplate = parseInterpolationTemplate(protectedBaseString);
122
122
  if (parsedTemplate.tokens.length === 0) {
@@ -137,6 +137,7 @@ export class ObjectNodeImpl extends NodeImpl {
137
137
  variables: values,
138
138
  graphInputValues: graphInputNodeValues,
139
139
  contextValues,
140
+ globalValues,
140
141
  unwrapVariableDataValues: false,
141
142
  })
142
143
  : undefined;
@@ -164,7 +165,8 @@ export class ObjectNodeImpl extends NodeImpl {
164
165
  return acc;
165
166
  }, {});
166
167
  const interpolatedString = this.interpolate(this.chartNode.data.jsonTemplate, inputMap, context.graphInputNodeValues, // Pass graph inputs
167
- context.contextValues);
168
+ context.contextValues, // Pass context values
169
+ getInterpolationGlobalValues(this.chartNode.data.jsonTemplate, context.getGlobal));
168
170
  let outputValue;
169
171
  try {
170
172
  outputValue = JSON.parse(interpolatedString);
@@ -6,7 +6,7 @@ import {} from '../../index.js';
6
6
  import { dedent } from 'ts-dedent';
7
7
  import { coerceTypeOptional } from '../../utils/coerceType.js';
8
8
  import { getInputOrData } from '../../utils/index.js';
9
- import { extractInterpolationVariableReferences, interpolate } from '../../utils/interpolation.js';
9
+ import { extractInterpolationVariableReferences, getInterpolationGlobalValues, interpolate } from '../../utils/interpolation.js';
10
10
  import { match } from 'ts-pattern';
11
11
  import { createInterpolationInputDefinition } from '../interpolationInputDefinition.js';
12
12
  export class PromptNodeImpl extends NodeImpl {
@@ -185,7 +185,10 @@ export class PromptNodeImpl extends NodeImpl {
185
185
  };
186
186
  }
187
187
  async process(inputs, context) {
188
- let outputValue = interpolate(this.chartNode.data.promptText, inputs, context.graphInputNodeValues, context.contextValues, { coerceBareVariableDataValues: true });
188
+ let outputValue = interpolate(this.chartNode.data.promptText, inputs, context.graphInputNodeValues, context.contextValues, {
189
+ coerceBareVariableDataValues: true,
190
+ globalValues: getInterpolationGlobalValues(this.chartNode.data.promptText, context.getGlobal),
191
+ });
189
192
  outputValue = outputValue.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
190
193
  const type = getInputOrData(this.data, inputs, 'type', 'string');
191
194
  const isCacheBreakpoint = getInputOrData(this.data, inputs, 'isCacheBreakpoint', 'boolean');
@@ -124,7 +124,15 @@ export class ReferencedGraphAliasNodeImpl extends NodeImpl {
124
124
  });
125
125
  try {
126
126
  const startTime = Date.now();
127
- const outputs = await subGraphProcessor.processGraph(context, inputData, context.contextValues);
127
+ const outputs = await subGraphProcessor.processGraph(context, inputData, context.contextValues, {
128
+ // This node preserves the referenced graph's named boundary ports,
129
+ // so it may relay their direct producer partials to a parent Watch.
130
+ // An Error-output alias can replace normal ports with exclusions,
131
+ // making it final-only just like an Error-output Subgraph.
132
+ ...(context.onGraphOutputPartial && this.data.useErrorOutput !== true
133
+ ? { onGraphOutputPartial: context.onGraphOutputPartial }
134
+ : {}),
135
+ });
128
136
  const duration = Date.now() - startTime;
129
137
  if (this.data.useErrorOutput) {
130
138
  outputs['error'] = {
@@ -0,0 +1,48 @@
1
+ import { nanoid } from 'nanoid/non-secure';
2
+ import { dedent } from 'ts-dedent';
3
+ import { nodeDefinition } from '../NodeDefinition.js';
4
+ import { NodeImpl } from '../NodeImpl.js';
5
+ export class StopWatchingStreamingOutputNodeImpl extends NodeImpl {
6
+ static create() {
7
+ return {
8
+ data: {},
9
+ id: nanoid(),
10
+ title: 'Stop Watching Streaming Output',
11
+ type: 'stopWatchingStreamingOutput',
12
+ visualData: { x: 0, y: 0, width: 230 },
13
+ };
14
+ }
15
+ getInputDefinitions() {
16
+ return [{ dataType: 'any', id: 'value', title: 'Value', required: true }];
17
+ }
18
+ getOutputDefinitions() {
19
+ return [{ dataType: 'any', id: 'value', title: 'Value' }];
20
+ }
21
+ static getUIData() {
22
+ return {
23
+ contextMenuTitle: 'Stop Watching Streaming Output',
24
+ group: ['Logic'],
25
+ infoBoxTitle: 'Stop Watching Streaming Output Node',
26
+ infoBoxBody: dedent `
27
+ Accepts a value from a Watch Streaming Output branch, stops future streaming
28
+ snapshots, and lets its completed output continue through the ordinary graph.
29
+ In parallel mode, the first completed branch to reach this node wins.
30
+ `,
31
+ };
32
+ }
33
+ getBody() {
34
+ return 'First completed Stop continues';
35
+ }
36
+ async process(inputs, context) {
37
+ const value = inputs['value'];
38
+ if (!value) {
39
+ throw new Error('Stop Watching Streaming Output requires a value.');
40
+ }
41
+ if (!context.acceptStreamingWatchStop) {
42
+ throw new Error('Stop Watching Streaming Output must be downstream of Watch Streaming Output.');
43
+ }
44
+ context.acceptStreamingWatchStop();
45
+ return { ['value']: value };
46
+ }
47
+ }
48
+ export const stopWatchingStreamingOutputNode = nodeDefinition(StopWatchingStreamingOutputNodeImpl, 'Stop Watching Streaming Output');
@@ -125,7 +125,17 @@ export class SubGraphNodeImpl extends NodeImpl {
125
125
  const subGraphProcessor = context.createSubProcessor(this.data.graphId, { signal: context.signal });
126
126
  try {
127
127
  const startTime = Date.now();
128
- const graphOutputs = await subGraphProcessor.processGraph(context, inputData, context.contextValues, requestedGraphOutputIds ? { requestedGraphOutputIds } : undefined);
128
+ const graphOutputs = await subGraphProcessor.processGraph(context, inputData, context.contextValues, {
129
+ ...(requestedGraphOutputIds ? { requestedGraphOutputIds } : {}),
130
+ // A child Graph Output can relay a direct producer's partial value
131
+ // under the public boundary port ID. An Error-output Subgraph may
132
+ // later replace that same normal output with an exclusion, so it is
133
+ // final-only even if a caller supplies this internal callback.
134
+ // The parent owns all Watch scheduling.
135
+ ...(context.onGraphOutputPartial && this.data.useErrorOutput !== true
136
+ ? { onGraphOutputPartial: context.onGraphOutputPartial }
137
+ : {}),
138
+ });
129
139
  const duration = Date.now() - startTime;
130
140
  if (requestedGraphOutputIds) {
131
141
  return buildOptimizedSubgraphOutputs(boundary, requestedGraphOutputIds, graphOutputs, duration, this.data.useErrorOutput);
@@ -5,7 +5,7 @@ import { nodeDefinition } from '../NodeDefinition.js';
5
5
  import {} from '../DataValue.js';
6
6
  import {} from '../../index.js';
7
7
  import { dedent } from 'ts-dedent';
8
- import { extractInterpolationVariableReferences, interpolate } from '../../utils/interpolation.js';
8
+ import { extractInterpolationVariableReferences, getInterpolationGlobalValues, interpolate } from '../../utils/interpolation.js';
9
9
  import { createInterpolationInputDefinition } from '../interpolationInputDefinition.js';
10
10
  import { buildNodeBodyPreview } from './nodeBodyPreview.js';
11
11
  export class TextNodeImpl extends NodeImpl {
@@ -78,7 +78,10 @@ export class TextNodeImpl extends NodeImpl {
78
78
  async process(inputs, context) {
79
79
  let outputValue = interpolate(this.chartNode.data.text, inputs, context.graphInputNodeValues, // Pass graph inputs
80
80
  context.contextValues, // Pass context values
81
- { coerceBareVariableDataValues: true });
81
+ {
82
+ coerceBareVariableDataValues: true,
83
+ globalValues: getInterpolationGlobalValues(this.chartNode.data.text, context?.getGlobal),
84
+ });
82
85
  if (this.chartNode.data.normalizeLineEndings) {
83
86
  outputValue = outputValue.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
84
87
  }
@@ -6,7 +6,7 @@ import {} from '../DataValue.js';
6
6
  import {} from '../EditorDefinition.js';
7
7
  import { dedent } from 'ts-dedent';
8
8
  import { coerceTypeOptional } from '../../utils/coerceType.js';
9
- import { interpolate } from '../../utils/interpolation.js';
9
+ import { getInterpolationGlobalValues, interpolate } from '../../utils/interpolation.js';
10
10
  import { get, sortBy } from 'lodash-es';
11
11
  export class ToTreeNodeImpl extends NodeImpl {
12
12
  static create() {
@@ -100,7 +100,10 @@ export class ToTreeNodeImpl extends NodeImpl {
100
100
  const isLastItem = index === sortedObjects.length - 1;
101
101
  const prefix = level === 0 ? '' : isLast ? '└── ' : '├── ';
102
102
  const indent = level === 0 ? '' : ' '.repeat(level - 1) + (isLast ? ' ' : '│ ');
103
- const formattedNode = interpolate(this.data.format, obj != null && typeof obj === 'object' ? obj : {}, interpolationContext?.graphInputNodeValues, interpolationContext?.contextValues, { unwrapVariableDataValues: false });
103
+ const formattedNode = interpolate(this.data.format, obj != null && typeof obj === 'object' ? obj : {}, interpolationContext?.graphInputNodeValues, interpolationContext?.contextValues, {
104
+ globalValues: interpolationContext?.globalValues,
105
+ unwrapVariableDataValues: false,
106
+ });
104
107
  // Add this node to the result
105
108
  result += indent + prefix + formattedNode + '\n';
106
109
  // Process children if they exist
@@ -114,7 +117,11 @@ export class ToTreeNodeImpl extends NodeImpl {
114
117
  }
115
118
  async process(inputs, context) {
116
119
  const objects = coerceTypeOptional(inputs['objects'], 'object[]') ?? [];
117
- const treeOutput = this.buildTree(objects, '', 0, true, context);
120
+ const treeOutput = this.buildTree(objects, '', 0, true, {
121
+ contextValues: context?.contextValues,
122
+ globalValues: getInterpolationGlobalValues(this.data.format, context?.getGlobal),
123
+ graphInputNodeValues: context?.graphInputNodeValues,
124
+ });
118
125
  return {
119
126
  ['tree']: {
120
127
  type: 'string',
@@ -5,7 +5,7 @@ import { nodeDefinition } from '../NodeDefinition.js';
5
5
  import { dedent } from 'ts-dedent';
6
6
  import {} from '../EditorDefinition.js';
7
7
  import {} from '../NodeBodySpec.js';
8
- import { extractInterpolationVariableReferences, interpolate } from '../../utils/interpolation.js';
8
+ import { extractInterpolationVariableReferences, getInterpolationGlobalValues, interpolate } from '../../utils/interpolation.js';
9
9
  import { keys } from '../../utils/typeSafety.js';
10
10
  import { coerceType } from '../../utils/coerceType.js';
11
11
  import { getInputOrData } from '../../utils/index.js';
@@ -191,7 +191,10 @@ export class GptFunctionNodeImpl extends NodeImpl {
191
191
  acc[interpolationKey] = inputs[key];
192
192
  return acc;
193
193
  }, {});
194
- const interpolated = interpolate(this.data.schema, inputMap, context?.graphInputNodeValues, context?.contextValues, { coerceBareVariableDataValues: true });
194
+ const interpolated = interpolate(this.data.schema, inputMap, context?.graphInputNodeValues, context?.contextValues, {
195
+ coerceBareVariableDataValues: true,
196
+ globalValues: getInterpolationGlobalValues(this.data.schema, context?.getGlobal),
197
+ });
195
198
  schema = JSON.parse(interpolated);
196
199
  }
197
200
  return {
@@ -0,0 +1,126 @@
1
+ import { nanoid } from 'nanoid/non-secure';
2
+ import { dedent } from 'ts-dedent';
3
+ import { nodeDefinition } from '../NodeDefinition.js';
4
+ import { NodeImpl } from '../NodeImpl.js';
5
+ import { streamingOutputWatchDefaults, streamingOutputWatchLimits, } from '../StreamingOutputWatch.js';
6
+ export class WatchStreamingOutputNodeImpl extends NodeImpl {
7
+ static create() {
8
+ return {
9
+ data: {
10
+ triggerMode: 'every-update',
11
+ intervalMs: streamingOutputWatchDefaults.intervalMs,
12
+ executionMode: 'sequential',
13
+ maxParallelRuns: streamingOutputWatchDefaults.maxParallelRuns,
14
+ maxQueuedUpdates: streamingOutputWatchDefaults.maxQueuedUpdates,
15
+ queueOverflowBehavior: streamingOutputWatchDefaults.queueOverflowBehavior,
16
+ },
17
+ id: nanoid(),
18
+ title: 'Watch Streaming Output',
19
+ type: 'watchStreamingOutput',
20
+ visualData: { x: 0, y: 0, width: 230 },
21
+ };
22
+ }
23
+ getInputDefinitions() {
24
+ return [{ dataType: 'any', id: 'stream', title: 'Streaming Output', required: true }];
25
+ }
26
+ getOutputDefinitions() {
27
+ return [
28
+ { dataType: 'any', id: 'value', title: 'Chunk' },
29
+ {
30
+ dataType: 'any[]',
31
+ id: 'allStreamedOutput',
32
+ title: 'All Chunks',
33
+ description: 'Every streamed value received so far, in order. Cumulative text streams contribute only new text.',
34
+ },
35
+ { dataType: 'number', id: 'updateIndex', title: 'Chunk Index' },
36
+ { dataType: 'boolean', id: 'isFinal', title: 'Is Final' },
37
+ ];
38
+ }
39
+ static getUIData() {
40
+ return {
41
+ contextMenuTitle: 'Watch Streaming Output',
42
+ group: ['Logic'],
43
+ infoBoxTitle: 'Watch Streaming Output Node',
44
+ infoBoxBody: dedent `
45
+ Runs its downstream branch for streaming output snapshots. Without Stop Watching
46
+ Streaming Output, every snapshot runs the branch and the watch finishes with its
47
+ producer. Add one Stop node only when a chosen value must continue through the
48
+ ordinary graph. Non-watched connections still wait for their upstream node's final result.
49
+ `,
50
+ };
51
+ }
52
+ getEditors() {
53
+ return [
54
+ {
55
+ type: 'dropdown',
56
+ dataKey: 'triggerMode',
57
+ label: 'Trigger',
58
+ options: [
59
+ { label: 'Every update', value: 'every-update' },
60
+ { label: 'Every N milliseconds', value: 'interval' },
61
+ ],
62
+ },
63
+ {
64
+ type: 'number',
65
+ dataKey: 'intervalMs',
66
+ hideIf: (data) => data.triggerMode !== 'interval',
67
+ label: 'Interval (ms)',
68
+ min: 1,
69
+ max: streamingOutputWatchLimits.intervalMs,
70
+ },
71
+ {
72
+ type: 'dropdown',
73
+ dataKey: 'executionMode',
74
+ label: 'Branch execution',
75
+ options: [
76
+ { label: 'Sequential', value: 'sequential' },
77
+ { label: 'Parallel', value: 'parallel' },
78
+ ],
79
+ },
80
+ {
81
+ type: 'number',
82
+ dataKey: 'maxParallelRuns',
83
+ hideIf: (data) => data.executionMode !== 'parallel',
84
+ label: 'Maximum parallel runs',
85
+ min: 1,
86
+ max: streamingOutputWatchLimits.maxParallelRuns,
87
+ },
88
+ {
89
+ type: 'number',
90
+ dataKey: 'maxQueuedUpdates',
91
+ label: 'Maximum queued updates',
92
+ min: 1,
93
+ max: streamingOutputWatchLimits.maxQueuedUpdates,
94
+ },
95
+ {
96
+ type: 'dropdown',
97
+ dataKey: 'queueOverflowBehavior',
98
+ label: 'On queue overflow',
99
+ defaultValue: streamingOutputWatchDefaults.queueOverflowBehavior,
100
+ options: [
101
+ { label: 'Fail run', value: 'fail' },
102
+ { label: 'Drop new update', value: 'drop' },
103
+ ],
104
+ },
105
+ ];
106
+ }
107
+ getBody() {
108
+ const trigger = this.data.triggerMode === 'interval' ? `Every ${this.data.intervalMs}ms` : 'Every update';
109
+ const execution = this.data.executionMode === 'parallel' ? `Parallel ×${this.data.maxParallelRuns}` : 'Sequential';
110
+ return `${trigger} · ${execution}`;
111
+ }
112
+ async process(inputs) {
113
+ // Watch instances are preloaded by GraphProcessor with an immutable snapshot.
114
+ // Returning this fallback keeps direct node tests and legacy execution readable.
115
+ return {
116
+ ['allStreamedOutput']: {
117
+ type: 'any[]',
118
+ value: inputs['stream'] == null ? [] : [inputs['stream'].value],
119
+ },
120
+ ['value']: inputs['stream'],
121
+ ['updateIndex']: { type: 'number', value: 0 },
122
+ ['isFinal']: { type: 'boolean', value: false },
123
+ };
124
+ }
125
+ }
126
+ export const watchStreamingOutputNode = nodeDefinition(WatchStreamingOutputNodeImpl, 'Watch Streaming Output');
@@ -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
  }