@valerypopoff/rivet2-core 2.4.0 → 2.5.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 (61) hide show
  1. package/dist/cjs/bundle.cjs +1430 -669
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/cjs/interpolationRuntime.cjs +1578 -0
  4. package/dist/cjs/interpolationRuntime.cjs.map +7 -0
  5. package/dist/cjs/interpolationSyntax.cjs +186 -0
  6. package/dist/cjs/interpolationSyntax.cjs.map +7 -0
  7. package/dist/cjs/webAppRuntime.cjs.map +2 -2
  8. package/dist/esm/exports.js +2 -1
  9. package/dist/esm/integrations/CodeRunner.js +5 -0
  10. package/dist/esm/integrations/mcp/MCPBase.js +16 -6
  11. package/dist/esm/interpolationRuntime.js +5 -0
  12. package/dist/esm/model/GraphBoundaryCache.js +0 -6
  13. package/dist/esm/model/GraphBoundaryEffects.js +5 -1
  14. package/dist/esm/model/GraphOutputSelection.js +34 -0
  15. package/dist/esm/model/GraphProcessor.js +136 -44
  16. package/dist/esm/model/ProcessContextBuilder.js +2 -0
  17. package/dist/esm/model/RecordingPlayer.js +11 -6
  18. package/dist/esm/model/StoredValueStore.js +4 -3
  19. package/dist/esm/model/nodes/CodeNewNode.js +16 -16
  20. package/dist/esm/model/nodes/DestructureNode.js +2 -2
  21. package/dist/esm/model/nodes/ExpressionNode.js +16 -16
  22. package/dist/esm/model/nodes/ExtractObjectPathNode.js +2 -2
  23. package/dist/esm/model/nodes/ExtractYamlNode.js +5 -5
  24. package/dist/esm/model/nodes/JSFilterNode.js +3 -1
  25. package/dist/esm/model/nodes/JSMapNode.js +3 -1
  26. package/dist/esm/model/nodes/MCPGetPromptNode.js +6 -2
  27. package/dist/esm/model/nodes/MCPToolCallNode.js +6 -2
  28. package/dist/esm/model/nodes/ObjectNode.js +19 -20
  29. package/dist/esm/model/nodes/PromptNode.js +10 -11
  30. package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +2 -40
  31. package/dist/esm/model/nodes/SubGraphNode.js +40 -26
  32. package/dist/esm/model/nodes/TextNode.js +11 -32
  33. package/dist/esm/model/nodes/ToTreeNode.js +6 -13
  34. package/dist/esm/model/nodes/ToolNode.js +33 -16
  35. package/dist/esm/model/nodes/jsListCallbackHelpers.js +19 -15
  36. package/dist/esm/model/nodes/jsValueInterpolation.js +83 -30
  37. package/dist/esm/model/nodes/nodeBodyPreview.js +23 -0
  38. package/dist/esm/plugins/openai/nodes/ThreadMessageNode.js +14 -11
  39. package/dist/esm/utils/index.js +2 -0
  40. package/dist/esm/utils/interpolation.js +478 -221
  41. package/dist/esm/utils/interpolationSyntax.js +175 -0
  42. package/dist/esm/utils/jsonPath.js +129 -0
  43. package/dist/types/exports.d.ts +3 -1
  44. package/dist/types/integrations/CodeRunnerOptions.d.ts +9 -0
  45. package/dist/types/integrations/mcp/MCPBase.d.ts +3 -1
  46. package/dist/types/interpolationRuntime.d.ts +5 -0
  47. package/dist/types/model/GraphBoundaryCache.d.ts +0 -2
  48. package/dist/types/model/GraphOutputSelection.d.ts +8 -0
  49. package/dist/types/model/GraphProcessor.d.ts +4 -3
  50. package/dist/types/model/ProcessContext.d.ts +3 -2
  51. package/dist/types/model/nodes/ObjectNode.d.ts +1 -1
  52. package/dist/types/model/nodes/SubGraphNode.d.ts +2 -0
  53. package/dist/types/model/nodes/ToTreeNode.d.ts +5 -2
  54. package/dist/types/model/nodes/ToolNode.d.ts +13 -1
  55. package/dist/types/model/nodes/jsValueInterpolation.d.ts +16 -8
  56. package/dist/types/model/nodes/nodeBodyPreview.d.ts +7 -0
  57. package/dist/types/utils/index.d.ts +2 -0
  58. package/dist/types/utils/interpolation.d.ts +93 -8
  59. package/dist/types/utils/interpolationSyntax.d.ts +21 -0
  60. package/dist/types/utils/jsonPath.d.ts +15 -0
  61. package/package.json +11 -1
@@ -5,7 +5,7 @@ import { nodeDefinition } from '../NodeDefinition.js';
5
5
  import { NodeImpl } from '../NodeImpl.js';
6
6
  import {} from '../NodeBodySpec.js';
7
7
  import { appendCodeNodeSourceUrl, buildCodeNodeSourceUrl, enrichCodeNodeErrorWithLocation, } from './codeNodeErrorDiagnostics.js';
8
- import { buildJsValueInterpolatedSource, buildJsValueInputsInitializer, buildJsValuePreview, getJsValueInterpolationInputDefinitions, getJsValueInterpolationRuntimeContext, interpolateJsValuePreviewSource, sanitizeGeneratedJsValueError, } from './jsValueInterpolation.js';
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
10
  const CODE_RUNTIME_HELPER_MESSAGE = 'Node execution also provides "require" and "process". Browser execution provides "fetch", "console", and "Rivet".';
11
11
  const DEFAULT_CODE_NEW = dedent `
@@ -17,31 +17,32 @@ const DEFAULT_CODE_NEW = dedent `
17
17
  `;
18
18
  const MAX_BODY_PREVIEW_LINES = 15;
19
19
  const CODE_NEW_INPUTS_IDENTIFIER = '__codeNewInputs';
20
- const CODE_NEW_INPUT_CLONE_CACHE_IDENTIFIER = 'codeNewInputCloneCache';
21
20
  export const CODE_NEW_OUTPUT_PORT_ID = 'output';
22
21
  function buildCodeNewPreview(code) {
23
22
  return buildJsValuePreview(code, MAX_BODY_PREVIEW_LINES);
24
23
  }
25
- function buildCodeNewRuntimeSource(code, inputsIdentifier) {
26
- return buildJsValueInterpolatedSource(code, inputsIdentifier, { trim: false });
24
+ function buildCodeNewRuntimeSource(code, interpolationContext) {
25
+ return buildJsValueInterpolatedSource(code, interpolationContext, { trim: false });
27
26
  }
28
- function buildCodeNewInputsInitializer(inputNames, inputsIdentifier) {
27
+ function buildCodeNewInputsInitializer(interpolationContext) {
29
28
  return buildJsValueInputsInitializer({
30
- cacheIdentifier: CODE_NEW_INPUT_CLONE_CACHE_IDENTIFIER,
31
- inputNames,
32
- inputsIdentifier,
29
+ interpolationContext,
33
30
  });
34
31
  }
35
32
  export function interpolateCodeNewSource(code, inputs) {
36
33
  return interpolateJsValuePreviewSource(code, inputs, { trim: false });
37
34
  }
38
- function sanitizeCodeNewError(error, inputNames, inputsIdentifier) {
39
- return sanitizeGeneratedJsValueError(error, inputNames, inputsIdentifier, 'code input');
35
+ function sanitizeCodeNewError(error, interpolationContext) {
36
+ return sanitizeGeneratedJsValueError(error, interpolationContext.inputNames, interpolationContext.inputsIdentifier, 'code input', [
37
+ interpolationContext.cloneCacheIdentifier,
38
+ interpolationContext.contextIdentifier,
39
+ interpolationContext.graphInputsIdentifier,
40
+ interpolationContext.interpolationHelperIdentifier,
41
+ ]);
40
42
  }
41
43
  function buildCodeNewWrapper(code, interpolationContext) {
42
- const { inputNames, inputsIdentifier } = interpolationContext;
43
44
  const beforeUserCodeLines = [
44
- ...buildCodeNewInputsInitializer(inputNames, inputsIdentifier).split(/\r?\n/),
45
+ ...buildCodeNewInputsInitializer(interpolationContext).split(/\r?\n/),
45
46
  '',
46
47
  'const __codeNewResult = await (async () => {',
47
48
  ];
@@ -56,7 +57,7 @@ function buildCodeNewWrapper(code, interpolationContext) {
56
57
  '};',
57
58
  ];
58
59
  return {
59
- source: [...beforeUserCodeLines, buildCodeNewRuntimeSource(code, inputsIdentifier), ...afterUserCodeLines].join('\n'),
60
+ source: [...beforeUserCodeLines, buildCodeNewRuntimeSource(code, interpolationContext), ...afterUserCodeLines].join('\n'),
60
61
  userCodeLineOffset: beforeUserCodeLines.length,
61
62
  };
62
63
  }
@@ -143,10 +144,9 @@ export class CodeNewNodeImpl extends NodeImpl {
143
144
  async process(inputs, context) {
144
145
  const sourceUrl = buildCodeNodeSourceUrl(this.chartNode.id);
145
146
  const interpolationContext = getJsValueInterpolationRuntimeContext(this.data.code, CODE_NEW_INPUTS_IDENTIFIER);
146
- const { inputNames, inputsIdentifier } = interpolationContext;
147
147
  const { source, userCodeLineOffset } = buildCodeNewWrapper(this.data.code, interpolationContext);
148
148
  try {
149
- const outputs = await context.codeRunner.runCode(appendCodeNodeSourceUrl(source, sourceUrl), inputs, ALL_CODE_RUNNER_OPTIONS, context.graphInputNodeValues, context.contextValues);
149
+ const outputs = await context.codeRunner.runCode(appendCodeNodeSourceUrl(source, sourceUrl), inputs, getJsValueInterpolationCodeRunnerOptions(ALL_CODE_RUNNER_OPTIONS, interpolationContext), context.graphInputNodeValues, context.contextValues);
150
150
  return validateCodeNewRunnerOutputs(outputs);
151
151
  }
152
152
  catch (error) {
@@ -158,7 +158,7 @@ export class CodeNewNodeImpl extends NodeImpl {
158
158
  sourceUrl,
159
159
  userCodeLineOffset,
160
160
  });
161
- throw sanitizeCodeNewError(enrichedError, inputNames, inputsIdentifier);
161
+ throw sanitizeCodeNewError(enrichedError, interpolationContext);
162
162
  }
163
163
  }
164
164
  }
@@ -3,11 +3,11 @@ import { nanoid } from 'nanoid/non-secure';
3
3
  import { NodeImpl } from '../NodeImpl.js';
4
4
  import { nodeDefinition } from '../NodeDefinition.js';
5
5
  import {} from '../DataValue.js';
6
- import { JSONPath } from 'jsonpath-plus';
7
6
  import {} from '../../index.js';
8
7
  import { dedent } from 'ts-dedent';
9
8
  import { coerceTypeOptional } from '../../utils/coerceType.js';
10
9
  import { resolveStoredOrderedPortIds } from '../../utils/orderedStringPortIds.js';
10
+ import { evaluateJsonPath } from '../../utils/jsonPath.js';
11
11
  export class DestructureNodeImpl extends NodeImpl {
12
12
  static create() {
13
13
  const chartNode = {
@@ -94,7 +94,7 @@ export class DestructureNodeImpl extends NodeImpl {
94
94
  this.data.paths.forEach((path, index) => {
95
95
  let match;
96
96
  try {
97
- match = JSONPath({ json: inputObject ?? null, path: path.trim(), wrap: false });
97
+ match = evaluateJsonPath(inputObject, path, false);
98
98
  }
99
99
  catch (err) {
100
100
  match = undefined;
@@ -4,38 +4,39 @@ import { NodeImpl } from '../NodeImpl.js';
4
4
  import {} from '../../index.js';
5
5
  import { dedent } from 'ts-dedent';
6
6
  import { nodeDefinition } from '../NodeDefinition.js';
7
- import { buildJsValueInterpolatedSource, buildJsValueInputsInitializer, buildJsValuePreview, getJsValueInterpolationInputDefinitions, getJsValueInterpolationRuntimeContext, interpolateJsValuePreviewSource, sanitizeGeneratedJsValueError, } from './jsValueInterpolation.js';
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
9
  const CODE_RUNTIME_HELPER_MESSAGE = 'Node execution also provides "require" and "process". Browser execution provides "fetch", "console", and "Rivet".';
10
10
  const DEFAULT_EXPRESSION = '{{a}} == "123" ? {{b}} : {{c}}';
11
11
  const MAX_BODY_PREVIEW_LINES = 15;
12
12
  const EXPRESSION_INPUTS_IDENTIFIER = '__expressionInputs';
13
- const EXPRESSION_INPUT_CLONE_CACHE_IDENTIFIER = 'expressionInputCloneCache';
14
13
  export const EXPRESSION_OUTPUT_PORT_ID = 'output';
15
14
  function buildExpressionPreview(expression) {
16
15
  return buildJsValuePreview(expression, MAX_BODY_PREVIEW_LINES);
17
16
  }
18
- function buildExpressionRuntimeSource(expression, inputsIdentifier) {
19
- return buildJsValueInterpolatedSource(expression, inputsIdentifier);
17
+ function buildExpressionRuntimeSource(expression, interpolationContext) {
18
+ return buildJsValueInterpolatedSource(expression, interpolationContext);
20
19
  }
21
- function buildExpressionInputsInitializer(inputNames, inputsIdentifier) {
20
+ function buildExpressionInputsInitializer(interpolationContext) {
22
21
  return buildJsValueInputsInitializer({
23
- cacheIdentifier: EXPRESSION_INPUT_CLONE_CACHE_IDENTIFIER,
24
- inputNames,
25
- inputsIdentifier,
22
+ interpolationContext,
26
23
  });
27
24
  }
28
25
  export function interpolateExpressionSource(expression, inputs) {
29
26
  return interpolateJsValuePreviewSource(expression, inputs);
30
27
  }
31
- function sanitizeExpressionError(error, inputNames, inputsIdentifier) {
32
- return sanitizeGeneratedJsValueError(error, inputNames, inputsIdentifier, 'expression input');
28
+ function sanitizeExpressionError(error, interpolationContext) {
29
+ return sanitizeGeneratedJsValueError(error, interpolationContext.inputNames, interpolationContext.inputsIdentifier, 'expression input', [
30
+ interpolationContext.cloneCacheIdentifier,
31
+ interpolationContext.contextIdentifier,
32
+ interpolationContext.graphInputsIdentifier,
33
+ interpolationContext.interpolationHelperIdentifier,
34
+ ]);
33
35
  }
34
36
  function buildExpressionWrapper(expression, interpolationContext) {
35
- const { inputNames, inputsIdentifier } = interpolationContext;
36
- const expressionSource = buildExpressionRuntimeSource(expression, inputsIdentifier);
37
+ const expressionSource = buildExpressionRuntimeSource(expression, interpolationContext);
37
38
  return dedent `
38
- ${buildExpressionInputsInitializer(inputNames, inputsIdentifier)}
39
+ ${buildExpressionInputsInitializer(interpolationContext)}
39
40
 
40
41
  return {
41
42
  output: {
@@ -111,13 +112,12 @@ export class ExpressionNodeImpl extends NodeImpl {
111
112
  }
112
113
  async process(inputs, context) {
113
114
  const interpolationContext = getJsValueInterpolationRuntimeContext(this.data.expression, EXPRESSION_INPUTS_IDENTIFIER);
114
- const { inputNames, inputsIdentifier } = interpolationContext;
115
115
  const source = buildExpressionWrapper(this.data.expression, interpolationContext);
116
116
  try {
117
- return await context.codeRunner.runCode(source, inputs, ALL_CODE_RUNNER_OPTIONS, context.graphInputNodeValues, context.contextValues);
117
+ return await context.codeRunner.runCode(source, inputs, getJsValueInterpolationCodeRunnerOptions(ALL_CODE_RUNNER_OPTIONS, interpolationContext), context.graphInputNodeValues, context.contextValues);
118
118
  }
119
119
  catch (error) {
120
- throw sanitizeExpressionError(error, inputNames, inputsIdentifier);
120
+ throw sanitizeExpressionError(error, interpolationContext);
121
121
  }
122
122
  }
123
123
  }
@@ -3,13 +3,13 @@ import { nanoid } from 'nanoid/non-secure';
3
3
  import { NodeImpl } from '../NodeImpl.js';
4
4
  import { nodeDefinition } from '../NodeDefinition.js';
5
5
  import {} from '../DataValue.js';
6
- import { JSONPath } from 'jsonpath-plus';
7
6
  import { expectType } from '../../utils/expectType.js';
8
7
  import {} from '../../index.js';
9
8
  import { dedent } from 'ts-dedent';
10
9
  import { coerceTypeOptional } from '../../utils/coerceType.js';
11
10
  import { extractInterpolationVariables, interpolate } from '../../utils/interpolation.js';
12
11
  import { createInterpolationInputDefinition } from '../interpolationInputDefinition.js';
12
+ import { evaluateJsonPath } from '../../utils/jsonPath.js';
13
13
  // Keep built-in ports from becoming implicit interpolation variables.
14
14
  const RESERVED_INPUT_IDS = new Set(['object']);
15
15
  export function getExtractObjectPathInterpolationInputNames(path) {
@@ -126,7 +126,7 @@ export class ExtractObjectPathNodeImpl extends NodeImpl {
126
126
  let matches;
127
127
  try {
128
128
  // Wrap doesn't seem to wrap when the input is undefined or null...
129
- const match = JSONPath({ json: inputObject ?? null, path: inputPath, wrap: true });
129
+ const match = evaluateJsonPath(inputObject, inputPath, true);
130
130
  matches = match == null ? [] : match;
131
131
  }
132
132
  catch (err) {
@@ -5,10 +5,10 @@ import { nodeDefinition } from '../NodeDefinition.js';
5
5
  import {} from '../DataValue.js';
6
6
  import yaml from 'yaml';
7
7
  import { expectType } from '../../utils/expectType.js';
8
- import { JSONPath } from 'jsonpath-plus';
9
8
  import { dedent } from 'ts-dedent';
10
9
  import {} from '../../index.js';
11
10
  import { coerceType } from '../../utils/coerceType.js';
11
+ import { evaluateJsonPath } from '../../utils/jsonPath.js';
12
12
  export class ExtractYamlNodeImpl extends NodeImpl {
13
13
  static create() {
14
14
  const chartNode = {
@@ -164,9 +164,9 @@ export class ExtractYamlNodeImpl extends NodeImpl {
164
164
  let matches = [];
165
165
  if (objectPath) {
166
166
  try {
167
- const extractedValue = JSONPath({ json: yamlObject, path: objectPath.trim() });
168
- matches = extractedValue;
169
- yamlObject = extractedValue.length > 0 ? extractedValue[0] : undefined;
167
+ const extractedValue = evaluateJsonPath(yamlObject, objectPath, true);
168
+ matches = extractedValue == null ? [] : extractedValue;
169
+ yamlObject = matches.length > 0 ? matches[0] : undefined;
170
170
  }
171
171
  catch (err) {
172
172
  return {
@@ -191,7 +191,7 @@ export class ExtractYamlNodeImpl extends NodeImpl {
191
191
  type: 'control-flow-excluded',
192
192
  value: undefined,
193
193
  }
194
- : this.data.objectPath
194
+ : objectPath
195
195
  ? {
196
196
  type: 'any',
197
197
  value: yamlObject,
@@ -48,7 +48,9 @@ export class JSFilterNodeImpl extends NodeImpl {
48
48
 
49
49
  Available callback parameters are <code>item</code>, <code>index</code>, and <code>array</code>.
50
50
  Write only the callback body and still use <code>return</code> to decide whether each item is included.
51
- Use <code>{{var}}</code> to add input ports that evaluate as connected values.
51
+ Use <code>{{var}}</code> to add input ports that evaluate as connected values. A path such as
52
+ <code>{{config.limit.max}}</code> creates only <code>config</code>; <code>{{item.name}}</code> and
53
+ <code>{{array[0]}}</code> use callback locals and do not add ports.
52
54
  `,
53
55
  infoBoxTitle: 'JS Filter Node',
54
56
  contextMenuTitle: 'JS Filter',
@@ -48,7 +48,9 @@ export class JSMapNodeImpl extends NodeImpl {
48
48
 
49
49
  Available callback parameters are <code>item</code>, <code>index</code>, and <code>array</code>.
50
50
  Write only the callback body and still use <code>return</code> to produce each mapped item.
51
- Use <code>{{var}}</code> to add input ports that evaluate as connected values.
51
+ Use <code>{{var}}</code> to add input ports that evaluate as connected values. A path such as
52
+ <code>{{config.limit.max}}</code> creates only <code>config</code>; <code>{{item.name}}</code> and
53
+ <code>{{array[0]}}</code> use callback locals and do not add ports.
52
54
  `,
53
55
  infoBoxTitle: 'JS Map Node',
54
56
  contextMenuTitle: 'JS Map',
@@ -7,7 +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 { getMCPBaseBody, getMCPBaseInputs, getMCPClientEditors, getMCPServerEditors, interpolateMCPArgumentTemplate, requireMCPProvider, resolveMCPServer, } from '../../integrations/mcp/MCPBase.js';
10
+ import { getMCPBaseBody, getMCPArgumentTemplateInputs, getMCPBaseInputs, getMCPClientEditors, getMCPServerEditors, interpolateMCPArgumentTemplate, requireMCPProvider, resolveMCPServer, } from '../../integrations/mcp/MCPBase.js';
11
11
  export class MCPGetPromptNodeImpl extends NodeImpl {
12
12
  static create() {
13
13
  const chartNode = {
@@ -54,6 +54,9 @@ export class MCPGetPromptNodeImpl extends NodeImpl {
54
54
  title: 'Prompt Arguments',
55
55
  });
56
56
  }
57
+ else {
58
+ inputs.push(...getMCPArgumentTemplateInputs(this.data.promptArguments));
59
+ }
57
60
  return inputs;
58
61
  }
59
62
  getOutputDefinitions() {
@@ -82,6 +85,7 @@ export class MCPGetPromptNodeImpl extends NodeImpl {
82
85
  dataKey: 'promptArguments',
83
86
  useInputToggleDataKey: 'usePromptArgumentsInput',
84
87
  language: 'json',
88
+ interpolationSyntax: 'json-template',
85
89
  helperMessage: 'Arguments to provide the prompt',
86
90
  enableFolding: true,
87
91
  },
@@ -112,7 +116,7 @@ export class MCPGetPromptNodeImpl extends NodeImpl {
112
116
  }
113
117
  }
114
118
  else {
115
- promptArguments = JSON.parse(interpolateMCPArgumentTemplate(this.data.promptArguments ?? '', inputs));
119
+ promptArguments = JSON.parse(interpolateMCPArgumentTemplate(this.data.promptArguments ?? '', inputs, context.graphInputNodeValues, context.contextValues));
116
120
  }
117
121
  const getPromptRequest = {
118
122
  name: promptName,
@@ -7,7 +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 { getMCPBaseBody, getMCPBaseInputs, getMCPClientEditors, getMCPServerEditors, interpolateMCPArgumentTemplate, requireMCPProvider, resolveMCPServer, } from '../../integrations/mcp/MCPBase.js';
10
+ import { getMCPBaseBody, getMCPArgumentTemplateInputs, getMCPBaseInputs, getMCPClientEditors, getMCPServerEditors, interpolateMCPArgumentTemplate, requireMCPProvider, resolveMCPServer, } from '../../integrations/mcp/MCPBase.js';
11
11
  import { dedent } from 'ts-dedent';
12
12
  import {} from '../EditorDefinition.js';
13
13
  export class MCPToolCallNodeImpl extends NodeImpl {
@@ -58,6 +58,9 @@ export class MCPToolCallNodeImpl extends NodeImpl {
58
58
  title: 'Tool Arguments',
59
59
  });
60
60
  }
61
+ else {
62
+ inputs.push(...getMCPArgumentTemplateInputs(this.data.toolArguments));
63
+ }
61
64
  if (this.data.useToolCallIdInput) {
62
65
  inputs.push({
63
66
  dataType: 'object',
@@ -98,6 +101,7 @@ export class MCPToolCallNodeImpl extends NodeImpl {
98
101
  label: 'Tool Arguments',
99
102
  dataKey: 'toolArguments',
100
103
  language: 'json',
104
+ interpolationSyntax: 'json-template',
101
105
  useInputToggleDataKey: 'useToolArgumentsInput',
102
106
  enableFolding: true,
103
107
  },
@@ -136,7 +140,7 @@ export class MCPToolCallNodeImpl extends NodeImpl {
136
140
  }
137
141
  }
138
142
  else {
139
- toolArguments = JSON.parse(interpolateMCPArgumentTemplate(this.data.toolArguments ?? '', inputs));
143
+ toolArguments = JSON.parse(interpolateMCPArgumentTemplate(this.data.toolArguments ?? '', inputs, context.graphInputNodeValues, context.contextValues));
140
144
  }
141
145
  const toolCall = {
142
146
  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, findInterpolationTokenSpans, getInterpolationTokenName, protectEscapedInterpolationTokens, resolveExpressionRawValue, restoreEscapedInterpolationTokens, unwrapPotentialDataValue, } from '../../utils/interpolation.js';
8
+ import { extractInterpolationVariables, 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}}"
@@ -118,33 +118,32 @@ export class ObjectNodeImpl extends NodeImpl {
118
118
  }
119
119
  interpolate(baseString, values, graphInputNodeValues, contextValues) {
120
120
  const protectedBaseString = protectEscapedInterpolationTokens(baseString);
121
- const tokenSpans = findInterpolationTokenSpans(protectedBaseString);
122
- if (tokenSpans.length === 0) {
121
+ const parsedTemplate = parseInterpolationTemplate(protectedBaseString);
122
+ if (parsedTemplate.tokens.length === 0) {
123
123
  return restoreEscapedInterpolationTokens(protectedBaseString);
124
124
  }
125
125
  let result = '';
126
126
  let cursor = 0;
127
- for (const tokenSpan of tokenSpans) {
127
+ for (const token of parsedTemplate.tokens) {
128
+ const tokenSpan = token.span;
128
129
  const isInsideString = isInsideJsonString(protectedBaseString, tokenSpan.start);
129
130
  const isWholeQuotedToken = isInsideString &&
130
131
  isUnescapedQuoteAt(protectedBaseString, tokenSpan.start - 1) &&
131
132
  isUnescapedQuoteAt(protectedBaseString, tokenSpan.end);
132
133
  const replacementStart = isWholeQuotedToken ? tokenSpan.start - 1 : tokenSpan.start;
133
134
  const replacementEnd = isWholeQuotedToken ? tokenSpan.end + 1 : tokenSpan.end;
134
- const trimmedKey = getInterpolationTokenName(tokenSpan.rawInner) ?? tokenSpan.rawInner.trim();
135
- let value;
136
- const graphInputPrefix = '@graphInputs.';
137
- const contextPrefix = '@context.';
138
- if (trimmedKey.startsWith(graphInputPrefix) && graphInputNodeValues) {
139
- value = resolveExpressionRawValue(graphInputNodeValues, trimmedKey.substring(graphInputPrefix.length), 'graphInputs');
140
- }
141
- else if (trimmedKey.startsWith(contextPrefix) && contextValues) {
142
- value = resolveExpressionRawValue(contextValues, trimmedKey.substring(contextPrefix.length), 'context');
143
- }
144
- else {
145
- value = values[trimmedKey]; // Original logic for non-@ variables
146
- }
147
- result += protectedBaseString.slice(cursor, replacementStart);
135
+ const value = token.reference
136
+ ? resolveInterpolationExpressionRawValue(token.reference, {
137
+ variables: values,
138
+ graphInputValues: graphInputNodeValues,
139
+ contextValues,
140
+ unwrapVariableDataValues: false,
141
+ })
142
+ : undefined;
143
+ // Restore escaped delimiters only from the authored JSON template. An
144
+ // interpolated string may itself contain literal interpolation syntax and
145
+ // must not be processed again while the final JSON is assembled.
146
+ result += restoreEscapedInterpolationTokens(protectedBaseString.slice(cursor, replacementStart));
148
147
  if (isInsideString && !isWholeQuotedToken) {
149
148
  result += stringifyEmbeddedJsonStringFragment(value);
150
149
  }
@@ -156,8 +155,8 @@ export class ObjectNodeImpl extends NodeImpl {
156
155
  }
157
156
  cursor = replacementEnd;
158
157
  }
159
- result += protectedBaseString.slice(cursor);
160
- return restoreEscapedInterpolationTokens(result);
158
+ result += restoreEscapedInterpolationTokens(protectedBaseString.slice(cursor));
159
+ return result;
161
160
  }
162
161
  async process(inputs, context) {
163
162
  const inputMap = Object.keys(inputs).reduce((acc, key) => {
@@ -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 { interpolate, extractInterpolationVariables } from '../../utils/interpolation.js';
9
+ import { extractInterpolationVariableReferences, 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 {
@@ -60,16 +60,19 @@ export class PromptNodeImpl extends NodeImpl {
60
60
  });
61
61
  }
62
62
  // Extract inputs from promptText, everything like {{input}}
63
- const inputNames = extractInterpolationVariables(this.data.promptText);
63
+ const inputReferences = extractInterpolationVariableReferences(this.data.promptText);
64
+ const fixedInputIds = new Set(inputs.map((input) => input.id));
64
65
  inputs = [
65
66
  ...inputs,
66
- ...(inputNames?.map((inputName) => {
67
+ ...inputReferences
68
+ .filter(({ baseName }) => !fixedInputIds.has(baseName))
69
+ .map(({ baseName, hasPath }) => {
67
70
  return createInterpolationInputDefinition({
68
- interpolationName: inputName,
69
- dataType: 'string',
71
+ interpolationName: baseName,
72
+ dataType: hasPath ? 'any' : 'string',
70
73
  required: false,
71
74
  });
72
- }) ?? []),
75
+ }),
73
76
  ];
74
77
  return inputs;
75
78
  }
@@ -182,11 +185,7 @@ export class PromptNodeImpl extends NodeImpl {
182
185
  };
183
186
  }
184
187
  async process(inputs, context) {
185
- const inputMap = Object.keys(inputs).reduce((acc, key) => {
186
- acc[key] = coerceTypeOptional(inputs[key], 'string') ?? '';
187
- return acc;
188
- }, {});
189
- let outputValue = interpolate(this.chartNode.data.promptText, inputMap, context.graphInputNodeValues, context.contextValues);
188
+ let outputValue = interpolate(this.chartNode.data.promptText, inputs, context.graphInputNodeValues, context.contextValues, { coerceBareVariableDataValues: true });
190
189
  outputValue = outputValue.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
191
190
  const type = getInputOrData(this.data, inputs, 'type', 'string');
192
191
  const isCacheBreakpoint = getInputOrData(this.data, inputs, 'isCacheBreakpoint', 'boolean');
@@ -9,7 +9,7 @@ import {} from '../DataValue.js';
9
9
  import {} from '../ProcessContext.js';
10
10
  import { dedent } from 'ts-dedent';
11
11
  import { getError } from '../../utils/errors.js';
12
- import { buildExcludedGraphBoundaryOutputs, buildGraphBoundaryInputData, GRAPH_BOUNDARY_OUTPUT_DEMAND_OPTIMIZATION_ENABLED, getGraphBoundary, getGraphBoundaryInputDefinitions, getGraphBoundaryOutputDefinitions, getRequestedGraphOutputNodeIds, } from '../GraphBoundaryCache.js';
12
+ import { buildExcludedGraphBoundaryOutputs, buildGraphBoundaryInputData, getGraphBoundary, getGraphBoundaryInputDefinitions, getGraphBoundaryOutputDefinitions, } from '../GraphBoundaryCache.js';
13
13
  export class ReferencedGraphAliasNodeImpl extends NodeImpl {
14
14
  static create() {
15
15
  const chartNode = {
@@ -117,32 +117,14 @@ export class ReferencedGraphAliasNodeImpl extends NodeImpl {
117
117
  const boundary = context.getGraphBoundary?.(referencedProject, this.data.graphId) ??
118
118
  getGraphBoundary(referencedProject, this.data.graphId);
119
119
  const inputData = buildGraphBoundaryInputData(boundary, inputs, this.data.inputData);
120
- const shouldRunWholeGraph = !GRAPH_BOUNDARY_OUTPUT_DEMAND_OPTIMIZATION_ENABLED ||
121
- context.isDirectRunTarget ||
122
- (this.data.useErrorOutput === true && context.activeOutputPortIds.has('error'));
123
- const requestedGraphOutputNodeIds = shouldRunWholeGraph
124
- ? []
125
- : getRequestedGraphOutputNodeIds(boundary, context.activeOutputPortIds);
126
- if (!shouldRunWholeGraph && requestedGraphOutputNodeIds.length === 0) {
127
- return buildSkippedReferencedGraphOutputs(boundary, this.data.useErrorOutput, this.data.outputCostDuration);
128
- }
129
120
  // Create a subprocessor using the referenced project's graph
130
121
  const subGraphProcessor = context.createSubProcessor(this.data.graphId, {
131
122
  signal: context.signal,
132
123
  project: referencedProject,
133
124
  });
134
- if (!shouldRunWholeGraph) {
135
- subGraphProcessor.runToNodeIds = requestedGraphOutputNodeIds;
136
- }
137
125
  try {
138
126
  const startTime = Date.now();
139
- const graphOutputs = await subGraphProcessor.processGraph(context, inputData, context.contextValues);
140
- const outputs = shouldRunWholeGraph
141
- ? graphOutputs
142
- : {
143
- ...buildExcludedGraphBoundaryOutputs(boundary),
144
- ...graphOutputs,
145
- };
127
+ const outputs = await subGraphProcessor.processGraph(context, inputData, context.contextValues);
146
128
  const duration = Date.now() - startTime;
147
129
  if (this.data.useErrorOutput) {
148
130
  outputs['error'] = {
@@ -172,26 +154,6 @@ export class ReferencedGraphAliasNodeImpl extends NodeImpl {
172
154
  }
173
155
  }
174
156
  export const referencedGraphAliasNode = nodeDefinition(ReferencedGraphAliasNodeImpl, 'Referenced Graph Alias');
175
- function buildSkippedReferencedGraphOutputs(boundary, useErrorOutput, outputCostDuration) {
176
- const outputs = buildExcludedGraphBoundaryOutputs(boundary);
177
- if (useErrorOutput) {
178
- outputs['error'] = {
179
- type: 'control-flow-excluded',
180
- value: undefined,
181
- };
182
- }
183
- if (outputCostDuration) {
184
- outputs['cost'] = {
185
- type: 'number',
186
- value: 0,
187
- };
188
- outputs['duration'] = {
189
- type: 'number',
190
- value: 0,
191
- };
192
- }
193
- return applyMetricOutputSetting(outputs, outputCostDuration);
194
- }
195
157
  function applyMetricOutputSetting(outputs, outputCostDuration) {
196
158
  if (outputCostDuration) {
197
159
  return outputs;
@@ -10,7 +10,7 @@ import {} from '../ProcessContext.js';
10
10
  import {} from '../../index.js';
11
11
  import { dedent } from 'ts-dedent';
12
12
  import { getError } from '../../utils/errors.js';
13
- import { applyGraphBoundaryPortOrder, buildExcludedGraphBoundaryOutputs, buildGraphBoundaryInputData, GRAPH_BOUNDARY_OUTPUT_DEMAND_OPTIMIZATION_ENABLED, getGraphBoundary, getGraphBoundaryInputDefinitions, getGraphBoundaryOutputDefinitions, getRequestedGraphOutputNodeIds, } from '../GraphBoundaryCache.js';
13
+ import { applyGraphBoundaryPortOrder, buildExcludedGraphBoundaryOutputs, buildGraphBoundaryInputData, getGraphBoundary, getGraphBoundaryInputDefinitions, getGraphBoundaryOutputDefinitions, } from '../GraphBoundaryCache.js';
14
14
  export class SubGraphNodeImpl extends NodeImpl {
15
15
  static create() {
16
16
  const chartNode = {
@@ -26,6 +26,7 @@ export class SubGraphNodeImpl extends NodeImpl {
26
26
  graphId: '',
27
27
  useErrorOutput: false,
28
28
  useAsGraphPartialOutput: false,
29
+ skipUnusedOutputs: false,
29
30
  },
30
31
  };
31
32
  return chartNode;
@@ -65,6 +66,13 @@ export class SubGraphNodeImpl extends NodeImpl {
65
66
  label: 'Use Error Output',
66
67
  dataKey: 'useErrorOutput',
67
68
  },
69
+ {
70
+ type: 'toggle',
71
+ label: 'Skip unused outputs',
72
+ dataKey: 'skipUnusedOutputs',
73
+ helperMessage: 'Only run branches needed by connected outputs. Skipped branches also skip their side effects and errors. ' +
74
+ 'Runs the full subgraph for Run to here, partial-output forwarding, or a connected Error output.',
75
+ },
68
76
  ];
69
77
  if (this.data.graphId) {
70
78
  const boundary = getGraphBoundary(context.project, this.data.graphId);
@@ -104,30 +112,25 @@ export class SubGraphNodeImpl extends NodeImpl {
104
112
  }
105
113
  const boundary = context.getGraphBoundary?.(project, this.data.graphId) ?? getGraphBoundary(project, this.data.graphId);
106
114
  const inputData = buildGraphBoundaryInputData(boundary, inputs, this.data.inputData);
107
- const shouldRunWholeGraph = !GRAPH_BOUNDARY_OUTPUT_DEMAND_OPTIMIZATION_ENABLED ||
115
+ const shouldRunWholeGraph = this.data.skipUnusedOutputs !== true ||
108
116
  context.isDirectRunTarget ||
109
117
  this.data.useAsGraphPartialOutput === true ||
110
118
  (this.data.useErrorOutput === true && context.activeOutputPortIds.has('error'));
111
- const requestedGraphOutputNodeIds = shouldRunWholeGraph
112
- ? []
113
- : getRequestedGraphOutputNodeIds(boundary, context.activeOutputPortIds);
114
- if (!shouldRunWholeGraph && requestedGraphOutputNodeIds.length === 0) {
115
- return buildSkippedSubgraphOutputs(boundary, this.data.useErrorOutput);
119
+ const requestedGraphOutputIds = shouldRunWholeGraph
120
+ ? undefined
121
+ : boundary.outputs.filter((output) => context.activeOutputPortIds.has(output.portId)).map((output) => output.id);
122
+ if (requestedGraphOutputIds?.length === 0) {
123
+ return buildOptimizedSubgraphOutputs(boundary, [], {}, 0, this.data.useErrorOutput);
116
124
  }
117
125
  const subGraphProcessor = context.createSubProcessor(this.data.graphId, { signal: context.signal });
118
- if (!shouldRunWholeGraph) {
119
- subGraphProcessor.runToNodeIds = requestedGraphOutputNodeIds;
120
- }
121
126
  try {
122
127
  const startTime = Date.now();
123
- const graphOutputs = await subGraphProcessor.processGraph(context, inputData, context.contextValues);
124
- const outputs = shouldRunWholeGraph
125
- ? graphOutputs
126
- : {
127
- ...buildExcludedGraphBoundaryOutputs(boundary),
128
- ...graphOutputs,
129
- };
128
+ const graphOutputs = await subGraphProcessor.processGraph(context, inputData, context.contextValues, requestedGraphOutputIds ? { requestedGraphOutputIds } : undefined);
130
129
  const duration = Date.now() - startTime;
130
+ if (requestedGraphOutputIds) {
131
+ return buildOptimizedSubgraphOutputs(boundary, requestedGraphOutputIds, graphOutputs, duration, this.data.useErrorOutput);
132
+ }
133
+ const outputs = graphOutputs;
131
134
  if (this.data.useErrorOutput) {
132
135
  outputs['error'] = {
133
136
  type: 'control-flow-excluded',
@@ -156,21 +159,32 @@ export class SubGraphNodeImpl extends NodeImpl {
156
159
  }
157
160
  }
158
161
  export const subGraphNode = nodeDefinition(SubGraphNodeImpl, 'Subgraph');
159
- function buildSkippedSubgraphOutputs(boundary, useErrorOutput) {
162
+ function buildOptimizedSubgraphOutputs(boundary, requestedOutputIds, graphOutputs, duration, useErrorOutput) {
160
163
  const outputs = buildExcludedGraphBoundaryOutputs(boundary);
164
+ for (const outputId of requestedOutputIds) {
165
+ if (Object.hasOwn(graphOutputs, outputId)) {
166
+ outputs[outputId] = graphOutputs[outputId];
167
+ }
168
+ else {
169
+ // Missing requested values must remain missing: downstream optional inputs
170
+ // may use defaults, whereas an excluded value would skip their node.
171
+ delete outputs[outputId];
172
+ }
173
+ }
161
174
  if (useErrorOutput) {
162
175
  outputs['error'] = {
163
176
  type: 'control-flow-excluded',
164
177
  value: undefined,
165
178
  };
166
179
  }
167
- outputs['cost'] = {
168
- type: 'number',
169
- value: 0,
170
- };
171
- outputs['duration'] = {
172
- type: 'number',
173
- value: 0,
174
- };
180
+ // Authored boundary values retain ownership of metric-named ports, including
181
+ // exclusions. An unrequested Graph Output may still run as another output's
182
+ // dependency, so do not copy arbitrary child results into the caller map.
183
+ if (!boundary.outputs.some((output) => output.id === 'cost')) {
184
+ outputs['cost'] = graphOutputs['cost'] ?? { type: 'number', value: 0 };
185
+ }
186
+ if (!boundary.outputs.some((output) => output.id === 'duration')) {
187
+ outputs['duration'] = { type: 'number', value: duration };
188
+ }
175
189
  return outputs;
176
190
  }