@valerypopoff/rivet2-core 2.4.0 → 2.6.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 (82) hide show
  1. package/dist/cjs/bundle.cjs +1800 -753
  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/AgentResponseTrace.js +8 -3
  13. package/dist/esm/model/GraphBoundaryCache.js +0 -6
  14. package/dist/esm/model/GraphBoundaryEffects.js +5 -1
  15. package/dist/esm/model/GraphOutputSelection.js +34 -0
  16. package/dist/esm/model/GraphProcessor.js +177 -50
  17. package/dist/esm/model/ProcessContextBuilder.js +4 -1
  18. package/dist/esm/model/RecordingPlayer.js +46 -14
  19. package/dist/esm/model/SplitRunProcessor.js +37 -16
  20. package/dist/esm/model/StoredValueStore.js +4 -3
  21. package/dist/esm/model/UiGraphRendererStyles.js +20 -0
  22. package/dist/esm/model/chat/aiSdkStreaming.js +3 -2
  23. package/dist/esm/model/chat-v2/aiSdkBridge.js +63 -5
  24. package/dist/esm/model/chat-v2/chatV2Pipeline.js +66 -3
  25. package/dist/esm/model/chat-v2/llmInvocationResultProjector.js +20 -7
  26. package/dist/esm/model/chat-v2/llmProfileFallback.js +12 -4
  27. package/dist/esm/model/nodes/CodeNewNode.js +16 -16
  28. package/dist/esm/model/nodes/DestructureNode.js +2 -2
  29. package/dist/esm/model/nodes/ExpressionNode.js +16 -16
  30. package/dist/esm/model/nodes/ExtractObjectPathNode.js +2 -2
  31. package/dist/esm/model/nodes/ExtractYamlNode.js +5 -5
  32. package/dist/esm/model/nodes/JSFilterNode.js +3 -1
  33. package/dist/esm/model/nodes/JSMapNode.js +3 -1
  34. package/dist/esm/model/nodes/LLMChatV2Node.js +30 -4
  35. package/dist/esm/model/nodes/MCPGetPromptNode.js +6 -2
  36. package/dist/esm/model/nodes/MCPToolCallNode.js +6 -2
  37. package/dist/esm/model/nodes/ObjectNode.js +19 -20
  38. package/dist/esm/model/nodes/PromptNode.js +10 -11
  39. package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +2 -40
  40. package/dist/esm/model/nodes/SubGraphNode.js +40 -26
  41. package/dist/esm/model/nodes/TextNode.js +11 -32
  42. package/dist/esm/model/nodes/ToTreeNode.js +6 -13
  43. package/dist/esm/model/nodes/ToolNode.js +33 -16
  44. package/dist/esm/model/nodes/jsListCallbackHelpers.js +19 -15
  45. package/dist/esm/model/nodes/jsValueInterpolation.js +83 -30
  46. package/dist/esm/model/nodes/nodeBodyPreview.js +23 -0
  47. package/dist/esm/plugins/openai/nodes/ThreadMessageNode.js +14 -11
  48. package/dist/esm/recording/ExecutionRecorder.js +55 -23
  49. package/dist/esm/utils/index.js +2 -0
  50. package/dist/esm/utils/interpolation.js +478 -221
  51. package/dist/esm/utils/interpolationSyntax.js +175 -0
  52. package/dist/esm/utils/jsonPath.js +129 -0
  53. package/dist/types/exports.d.ts +3 -1
  54. package/dist/types/integrations/CodeRunnerOptions.d.ts +9 -0
  55. package/dist/types/integrations/mcp/MCPBase.d.ts +3 -1
  56. package/dist/types/interpolationRuntime.d.ts +5 -0
  57. package/dist/types/model/AgentResponseTrace.d.ts +2 -0
  58. package/dist/types/model/ExecutorProtocol.d.ts +4 -0
  59. package/dist/types/model/GraphBoundaryCache.d.ts +0 -2
  60. package/dist/types/model/GraphOutputSelection.d.ts +8 -0
  61. package/dist/types/model/GraphProcessor.d.ts +12 -3
  62. package/dist/types/model/ProcessContext.d.ts +9 -2
  63. package/dist/types/model/ProcessContextBuilder.d.ts +2 -1
  64. package/dist/types/model/SplitRunProcessor.d.ts +2 -1
  65. package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
  66. package/dist/types/model/chat/aiSdkStreaming.d.ts +1 -1
  67. package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +1 -1
  68. package/dist/types/model/chat-v2/chatV2Types.d.ts +29 -0
  69. package/dist/types/model/chat-v2/llmInvocationResultProjector.d.ts +5 -1
  70. package/dist/types/model/nodes/ObjectNode.d.ts +1 -1
  71. package/dist/types/model/nodes/SubGraphNode.d.ts +2 -0
  72. package/dist/types/model/nodes/ToTreeNode.d.ts +5 -2
  73. package/dist/types/model/nodes/ToolNode.d.ts +13 -1
  74. package/dist/types/model/nodes/jsValueInterpolation.d.ts +16 -8
  75. package/dist/types/model/nodes/nodeBodyPreview.d.ts +7 -0
  76. package/dist/types/recording/ExecutionRecorder.d.ts +6 -1
  77. package/dist/types/recording/RecordedEvents.d.ts +2 -0
  78. package/dist/types/utils/index.d.ts +2 -0
  79. package/dist/types/utils/interpolation.d.ts +93 -8
  80. package/dist/types/utils/interpolationSyntax.d.ts +21 -0
  81. package/dist/types/utils/jsonPath.d.ts +15 -0
  82. package/package.json +11 -1
@@ -456,7 +456,9 @@ export function createLLMProfileFallbackRunner(params) {
456
456
  healthDisposition: 'deny',
457
457
  ...(begin.retryAt == null ? {} : { retryAt: begin.retryAt }),
458
458
  });
459
- clearPartialResponse(roundOptions);
459
+ if (profileIndex + 1 < params.candidates.length) {
460
+ clearPartialResponse(roundOptions);
461
+ }
460
462
  continue;
461
463
  }
462
464
  const permitId = begin.permitId;
@@ -530,7 +532,9 @@ export function createLLMProfileFallbackRunner(params) {
530
532
  outcome: 'failure',
531
533
  error: getLLMAttemptErrorMessage(error),
532
534
  });
533
- clearPartialResponse(roundOptions);
535
+ if (profileIndex + 1 < params.candidates.length) {
536
+ clearPartialResponse(roundOptions);
537
+ }
534
538
  await healthPermit?.finish('ignored');
535
539
  continue;
536
540
  }
@@ -617,7 +621,9 @@ export function createLLMProfileFallbackRunner(params) {
617
621
  outcome: 'failure',
618
622
  error: getLLMAttemptErrorMessage(error),
619
623
  });
620
- clearPartialResponse(roundOptions);
624
+ if (profileIndex + 1 < params.candidates.length) {
625
+ clearPartialResponse(roundOptions);
626
+ }
621
627
  await healthPermit?.finish('ignored');
622
628
  continue;
623
629
  }
@@ -629,7 +635,9 @@ export function createLLMProfileFallbackRunner(params) {
629
635
  }
630
636
  lastError = execution.failure.normalizedError;
631
637
  await healthPermit?.finish(isUnhealthyLLMProfileProviderFailure(execution.failure.normalizedError) ? 'unhealthy' : 'ignored');
632
- clearPartialResponse(roundOptions);
638
+ if (profileIndex + 1 < params.candidates.length) {
639
+ clearPartialResponse(roundOptions);
640
+ }
633
641
  }
634
642
  exhausted = true;
635
643
  // A scalar profile keeps its underlying provider/configuration error.
@@ -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',
@@ -9,7 +9,7 @@ import { getLLMChatV2BodySections } from '../chat-v2/llmChatV2Body.js';
9
9
  import { isLLMChatV2StructuredResponseFormat } from '../chat-v2/chatV2FeatureCompatibility.js';
10
10
  import { LLMInvocationJournal } from '../chat-v2/llmInvocationJournal.js';
11
11
  import { executeLLMInvocation } from '../chat-v2/llmInvocationCoordinator.js';
12
- import { projectLLMInvocationDiagnostics, projectLLMInvocationResult, } from '../chat-v2/llmInvocationResultProjector.js';
12
+ import { mergeLLMInvocationFailureOutputs, projectLLMInvocationDiagnostics, projectLLMInvocationResult, } from '../chat-v2/llmInvocationResultProjector.js';
13
13
  import { isChatV2PipelineProviderFailureResult } from '../chat-v2/chatV2Pipeline.js';
14
14
  import { shouldOutputChatV2RequestBody, shouldOutputChatV2ResponseBody } from '../chat-v2/chatV2Types.js';
15
15
  import { buildLLMChatV2EditorCacheKey, resolveLLMChatV2RuntimeConfig, resolveLLMChatV2RuntimeProviderOptions, } from '../chat-v2/llmChatV2NodeRuntime.js';
@@ -264,6 +264,7 @@ export class LLMChatV2NodeImpl extends NodeImpl {
264
264
  async process(inputs, context) {
265
265
  const invocationJournal = new LLMInvocationJournal();
266
266
  let profileAttemptSequence = 0;
267
+ let latestFailureEvidence;
267
268
  // Retries, fallback profiles, and tool continuation produce several
268
269
  // physical provider calls underneath one node invocation. Always observe
269
270
  // them locally so every later output projection shares one truthful
@@ -306,7 +307,18 @@ export class LLMChatV2NodeImpl extends NodeImpl {
306
307
  invocation = await executeLLMInvocation({
307
308
  context,
308
309
  journal: invocationJournal,
309
- runtime,
310
+ runtime: {
311
+ ...runtime,
312
+ runOptions: {
313
+ ...runtime.runOptions,
314
+ onFailureCheckpoint: (outputs) => {
315
+ // The pipeline emits request/response evidence separately from
316
+ // presentation updates. Snapshot it here because streams and
317
+ // tool continuation may keep accumulating after this callback.
318
+ latestFailureEvidence = cloneLLMChatV2Outputs(outputs);
319
+ },
320
+ },
321
+ },
310
322
  toolCallContinuation,
311
323
  });
312
324
  }
@@ -315,11 +327,25 @@ export class LLMChatV2NodeImpl extends NodeImpl {
315
327
  const diagnostics = projectLLMInvocationDiagnostics({
316
328
  runOptions: runtime.runOptions,
317
329
  outputLLMAttempts: this.data.outputLLMAttempts,
330
+ modelCalls: invocationJournal.modelCalls,
331
+ outputUsage: this.data.outputUsage,
318
332
  llmAttempts: invocationJournal.llmAttempts,
319
333
  profileSummary: runtime.getProfileSummary?.(),
320
334
  });
321
- if (Object.keys(diagnostics).length > 0) {
322
- context.onPartialOutputs?.(diagnostics);
335
+ const failureOutputs = mergeLLMInvocationFailureOutputs(latestFailureEvidence, diagnostics);
336
+ if (Object.keys(failureOutputs).length > 0) {
337
+ // This checkpoint is the durable terminal counterpart to the live
338
+ // partial-output stream. GraphProcessor attaches it to nodeError,
339
+ // so recordings and remote executors cannot lose evidence merely
340
+ // because their recorder omits transient partial events.
341
+ if (context.setFailureOutputs) {
342
+ context.setFailureOutputs(failureOutputs);
343
+ }
344
+ else {
345
+ // Keep direct/custom node consumers working without asking them
346
+ // to implement the GraphProcessor-only terminal channel.
347
+ context.onPartialOutputs?.(failureOutputs);
348
+ }
323
349
  }
324
350
  }
325
351
  catch {
@@ -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;