@valerypopoff/rivet2-core 2.13.0 → 2.17.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 (134) hide show
  1. package/dist/cjs/bundle.cjs +28167 -23834
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/cjs/interpolationRuntime.cjs +22 -3
  4. package/dist/cjs/interpolationRuntime.cjs.map +3 -3
  5. package/dist/cjs/interpolationSyntax.cjs +9 -5
  6. package/dist/cjs/interpolationSyntax.cjs.map +2 -2
  7. package/dist/esm/api/createProcessor.js +10 -2
  8. package/dist/esm/api/processSettings.js +1 -0
  9. package/dist/esm/exports.js +6 -0
  10. package/dist/esm/model/GraphBoundaryCache.js +2 -1
  11. package/dist/esm/model/GraphProcessor.js +278 -22
  12. package/dist/esm/model/MarkdownSanitizationPolicy.js +2 -0
  13. package/dist/esm/model/NodeImpl.js +1 -1
  14. package/dist/esm/model/Nodes.js +16 -0
  15. package/dist/esm/model/ProjectBundle.js +235 -0
  16. package/dist/esm/model/SplitRunProcessor.js +28 -7
  17. package/dist/esm/model/StreamingWatchTopology.js +211 -64
  18. package/dist/esm/model/SubgraphProjectTarget.js +7 -0
  19. package/dist/esm/model/chat-v2/aiSdkBridge.js +7 -5
  20. package/dist/esm/model/chat-v2/chatV2Pipeline.js +13 -8
  21. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +19 -1
  22. package/dist/esm/model/chat-v2/chatV2Shared.js +2 -1
  23. package/dist/esm/model/chat-v2/llmChatV2Body.js +11 -8
  24. package/dist/esm/model/chat-v2/llmChatV2NodeData.js +2 -0
  25. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +15 -1
  26. package/dist/esm/model/chat-v2/llmChatV2NodeMigration.js +22 -2
  27. package/dist/esm/model/chat-v2/llmProfile.js +3 -0
  28. package/dist/esm/model/chat-v2/llmProfileBody.js +2 -2
  29. package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +1 -1
  30. package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +1 -1
  31. package/dist/esm/model/chat-v2/temperature.js +9 -0
  32. package/dist/esm/model/classifier/credentials.js +107 -0
  33. package/dist/esm/model/classifier/images.js +176 -0
  34. package/dist/esm/model/classifier/json.js +57 -0
  35. package/dist/esm/model/classifier/limits.js +270 -0
  36. package/dist/esm/model/classifier/migration.js +97 -0
  37. package/dist/esm/model/classifier/openai.js +118 -0
  38. package/dist/esm/model/classifier/preparation.js +74 -0
  39. package/dist/esm/model/classifier/providers.js +422 -0
  40. package/dist/esm/model/classifier/questionHelpers.js +109 -0
  41. package/dist/esm/model/classifier/questions.js +53 -0
  42. package/dist/esm/model/classifier/response.js +75 -0
  43. package/dist/esm/model/classifier/state.js +204 -0
  44. package/dist/esm/model/classifier/types.js +1 -0
  45. package/dist/esm/model/nodeBodyMarkdown.js +37 -0
  46. package/dist/esm/model/nodeRunFailure.js +47 -0
  47. package/dist/esm/model/nodes/CatchStreamingChunksNode.js +42 -0
  48. package/dist/esm/model/nodes/ClassifierEvaluateNode.js +432 -0
  49. package/dist/esm/model/nodes/ClassifierQuestionNode.js +613 -0
  50. package/dist/esm/model/nodes/CodeNewNode.js +33 -9
  51. package/dist/esm/model/nodes/GetGlobalNode.js +2 -2
  52. package/dist/esm/model/nodes/HttpCallNode.js +44 -75
  53. package/dist/esm/model/nodes/ImageNode.js +44 -3
  54. package/dist/esm/model/nodes/LLMChatV2Node.js +27 -15
  55. package/dist/esm/model/nodes/LLMProfileNode.js +6 -12
  56. package/dist/esm/model/nodes/MatchCaseNode.js +76 -1
  57. package/dist/esm/model/nodes/MatchCaseNodeBase.js +24 -2
  58. package/dist/esm/model/nodes/ObjectNode.js +68 -50
  59. package/dist/esm/model/nodes/PassthroughNode.js +1 -1
  60. package/dist/esm/model/nodes/PromptNode.js +2 -1
  61. package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +4 -1
  62. package/dist/esm/model/nodes/SetGlobalNode.js +5 -3
  63. package/dist/esm/model/nodes/StopWatchingStreamingOutputNode.js +8 -8
  64. package/dist/esm/model/nodes/StreamValueNode.js +38 -0
  65. package/dist/esm/model/nodes/SubGraphNode.js +196 -35
  66. package/dist/esm/model/nodes/ToBase64Node.js +106 -0
  67. package/dist/esm/model/nodes/WatchStreamingOutputNode.js +7 -7
  68. package/dist/esm/model/nodes/codeOutputInference.js +292 -0
  69. package/dist/esm/recording/ExecutionRecorder.js +26 -0
  70. package/dist/esm/utils/base64.js +18 -15
  71. package/dist/esm/utils/errors.js +41 -0
  72. package/dist/esm/utils/interpolation.js +44 -22
  73. package/dist/esm/utils/interpolationSyntax.js +15 -6
  74. package/dist/esm/utils/serialization/serialization.js +7 -2
  75. package/dist/esm/utils/serialization/serializationUtils.js +6 -0
  76. package/dist/esm/utils/serialization/serialization_v4.js +15 -3
  77. package/dist/types/api/createProcessor.d.ts +7 -1
  78. package/dist/types/exports.d.ts +6 -0
  79. package/dist/types/model/CycleDetector.d.ts +1 -2
  80. package/dist/types/model/EditorDefinition.d.ts +24 -0
  81. package/dist/types/model/ExecutorProtocol.d.ts +2 -0
  82. package/dist/types/model/GraphBoundaryCache.d.ts +2 -0
  83. package/dist/types/model/GraphProcessor.d.ts +1 -0
  84. package/dist/types/model/MarkdownSanitizationPolicy.d.ts +1 -1
  85. package/dist/types/model/NodeImpl.d.ts +3 -1
  86. package/dist/types/model/Nodes.d.ts +10 -4
  87. package/dist/types/model/ProcessContext.d.ts +12 -0
  88. package/dist/types/model/ProjectBundle.d.ts +54 -0
  89. package/dist/types/model/ProjectReferenceLoader.d.ts +3 -0
  90. package/dist/types/model/Settings.d.ts +4 -0
  91. package/dist/types/model/StreamingWatchTopology.d.ts +17 -1
  92. package/dist/types/model/SubgraphProjectTarget.d.ts +38 -0
  93. package/dist/types/model/chat-v2/chatV2Shared.d.ts +1 -1
  94. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +3 -1
  95. package/dist/types/model/chat-v2/llmChatV2NodeMigration.d.ts +3 -1
  96. package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +6 -6
  97. package/dist/types/model/chat-v2/temperature.d.ts +2 -0
  98. package/dist/types/model/classifier/credentials.d.ts +26 -0
  99. package/dist/types/model/classifier/images.d.ts +18 -0
  100. package/dist/types/model/classifier/json.d.ts +19 -0
  101. package/dist/types/model/classifier/limits.d.ts +42 -0
  102. package/dist/types/model/classifier/migration.d.ts +18 -0
  103. package/dist/types/model/classifier/openai.d.ts +5 -0
  104. package/dist/types/model/classifier/preparation.d.ts +16 -0
  105. package/dist/types/model/classifier/providers.d.ts +136 -0
  106. package/dist/types/model/classifier/questionHelpers.d.ts +33 -0
  107. package/dist/types/model/classifier/questions.d.ts +4 -0
  108. package/dist/types/model/classifier/response.d.ts +4 -0
  109. package/dist/types/model/classifier/state.d.ts +37 -0
  110. package/dist/types/model/classifier/types.d.ts +60 -0
  111. package/dist/types/model/nodeBodyMarkdown.d.ts +19 -0
  112. package/dist/types/model/nodeRunFailure.d.ts +13 -0
  113. package/dist/types/model/nodes/CatchStreamingChunksNode.d.ts +20 -0
  114. package/dist/types/model/nodes/ClassifierEvaluateNode.d.ts +50 -0
  115. package/dist/types/model/nodes/ClassifierQuestionNode.d.ts +60 -0
  116. package/dist/types/model/nodes/CodeNewNode.d.ts +6 -0
  117. package/dist/types/model/nodes/GetGlobalNode.d.ts +7 -0
  118. package/dist/types/model/nodes/ImageNode.d.ts +4 -0
  119. package/dist/types/model/nodes/LLMChatV2Node.d.ts +1 -0
  120. package/dist/types/model/nodes/MatchCaseNode.d.ts +8 -1
  121. package/dist/types/model/nodes/MatchCaseNodeBase.d.ts +13 -1
  122. package/dist/types/model/nodes/ObjectNode.d.ts +6 -0
  123. package/dist/types/model/nodes/StreamValueNode.d.ts +14 -0
  124. package/dist/types/model/nodes/SubGraphNode.d.ts +21 -2
  125. package/dist/types/model/nodes/ToBase64Node.d.ts +12 -0
  126. package/dist/types/model/nodes/codeOutputInference.d.ts +31 -0
  127. package/dist/types/recording/ExecutionRecorder.d.ts +8 -2
  128. package/dist/types/utils/base64.d.ts +1 -1
  129. package/dist/types/utils/errors.d.ts +4 -0
  130. package/dist/types/utils/interpolation.d.ts +13 -2
  131. package/dist/types/utils/interpolationSyntax.d.ts +1 -1
  132. package/dist/types/utils/serialization/serialization.d.ts +3 -1
  133. package/dist/types/utils/serialization/serializationUtils.d.ts +1 -0
  134. package/package.json +1 -1
@@ -5,14 +5,16 @@ 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, getJsValueInterpolationCodeRunnerOptions, getJsValueInterpolationInputDefinitions, getJsValueInterpolationRuntimeContext, interpolateJsValuePreviewSource, sanitizeGeneratedJsValueError, } from './jsValueInterpolation.js';
8
+ import { buildJsValueInterpolatedSource, buildJsValueInputsInitializer, buildJsValuePreview, getJsValueInterpolationCodeRunnerOptions, getJsValueInterpolationInputDefinitions, getJsValueInterpolationRuntimeContext, getSafeJsValueInterpolationIdentifier, interpolateJsValuePreviewSource, sanitizeGeneratedJsValueError, } from './jsValueInterpolation.js';
9
9
  import { ALL_CODE_RUNNER_OPTIONS } from '../../integrations/CodeRunnerOptions.js';
10
10
  import { getInterpolationGlobalValues } from '../../utils/interpolation.js';
11
+ import { getCodeOutputFields } from './codeOutputInference.js';
12
+ export { analyzeCodeOutputs, getCodeOutputFields, getCodeOutputKeys, prepareCodeOutputEdit, } from './codeOutputInference.js';
11
13
  const CODE_RUNTIME_HELPER_MESSAGE = 'Node execution also provides "require" and "process". Browser execution provides "fetch", "console", and "Rivet".';
12
14
  const DEFAULT_CODE_NEW = dedent `
13
15
  // This is a Code node. Write JavaScript here and return one value.
14
16
  // Interpolation tokens create input ports and evaluate as connected values.
15
- // The returned value becomes the node's single output.
17
+ // Output carries the returned value; explicit object fields also get ports.
16
18
  const value = {{input}};
17
19
  return value;
18
20
  `;
@@ -43,21 +45,31 @@ function sanitizeCodeNewError(error, interpolationContext) {
43
45
  interpolationContext.interpolationHelperIdentifier,
44
46
  ]);
45
47
  }
46
- function buildCodeNewWrapper(code, interpolationContext) {
48
+ function buildCodeNewWrapper(code, interpolationContext, outputFields) {
49
+ const resultIdentifier = getSafeJsValueInterpolationIdentifier(code, '__codeNewResult');
50
+ const outputsIdentifier = getSafeJsValueInterpolationIdentifier(code, '__codeNewOutputs');
47
51
  const beforeUserCodeLines = [
48
52
  ...buildCodeNewInputsInitializer(interpolationContext).split(/\r?\n/),
49
53
  '',
50
- 'const __codeNewResult = await (async () => {',
54
+ `const ${resultIdentifier} = await (async () => {`,
51
55
  ];
52
56
  const afterUserCodeLines = [
53
57
  '})();',
54
58
  '',
55
- 'return {',
59
+ `const ${outputsIdentifier} = {`,
56
60
  ' output: {',
57
61
  " type: 'any',",
58
- ' value: __codeNewResult,',
62
+ ` value: ${resultIdentifier},`,
59
63
  ' },',
60
64
  '};',
65
+ `for (const { id, key } of ${JSON.stringify(outputFields)}) {`,
66
+ ` const descriptor = ${resultIdentifier} !== null && typeof ${resultIdentifier} === "object" && !Array.isArray(${resultIdentifier})`,
67
+ ` ? Object.getOwnPropertyDescriptor(${resultIdentifier}, key) : undefined;`,
68
+ ` ${outputsIdentifier}[id] = descriptor?.enumerable && Object.prototype.hasOwnProperty.call(descriptor, "value")`,
69
+ ' ? { type: "any", value: descriptor.value }',
70
+ ' : { type: "control-flow-excluded", value: undefined };',
71
+ '}',
72
+ `return ${outputsIdentifier};`,
61
73
  ];
62
74
  return {
63
75
  source: [...beforeUserCodeLines, buildCodeNewRuntimeSource(code, interpolationContext), ...afterUserCodeLines].join('\n'),
@@ -70,7 +82,7 @@ function isDataValueLike(value) {
70
82
  typeof value.type === 'string' &&
71
83
  Object.prototype.hasOwnProperty.call(value, 'value'));
72
84
  }
73
- function validateCodeNewRunnerOutputs(outputs) {
85
+ function validateCodeNewRunnerOutputs(outputs, outputFields) {
74
86
  if (outputs == null || typeof outputs !== 'object' || ('then' in outputs && typeof outputs.then === 'function')) {
75
87
  throw new Error('Code node runner must return an object containing the Output value.');
76
88
  }
@@ -81,6 +93,12 @@ function validateCodeNewRunnerOutputs(outputs) {
81
93
  if (output.type !== 'any') {
82
94
  throw new Error('Code node runner must return an any DataValue for the Output port.');
83
95
  }
96
+ for (const { id, key } of outputFields) {
97
+ const value = outputs[id];
98
+ if (!isDataValueLike(value) || (value.type !== 'any' && value.type !== 'control-flow-excluded')) {
99
+ throw new Error(`Code node runner must return a DataValue for field ${JSON.stringify(key)}.`);
100
+ }
101
+ }
84
102
  return outputs;
85
103
  }
86
104
  export class CodeNewNodeImpl extends NodeImpl {
@@ -109,6 +127,11 @@ export class CodeNewNodeImpl extends NodeImpl {
109
127
  title: 'Output',
110
128
  dataType: 'any',
111
129
  },
130
+ ...getCodeOutputFields(this.data).map(({ id, key }) => ({
131
+ id: id,
132
+ title: key,
133
+ dataType: 'any',
134
+ })),
112
135
  ];
113
136
  }
114
137
  getEditors() {
@@ -147,10 +170,11 @@ export class CodeNewNodeImpl extends NodeImpl {
147
170
  async process(inputs, context) {
148
171
  const sourceUrl = buildCodeNodeSourceUrl(this.chartNode.id);
149
172
  const interpolationContext = getJsValueInterpolationRuntimeContext(this.data.code, CODE_NEW_INPUTS_IDENTIFIER);
150
- const { source, userCodeLineOffset } = buildCodeNewWrapper(this.data.code, interpolationContext);
173
+ const outputFields = getCodeOutputFields(this.data);
174
+ const { source, userCodeLineOffset } = buildCodeNewWrapper(this.data.code, interpolationContext, outputFields);
151
175
  try {
152
176
  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));
153
- return validateCodeNewRunnerOutputs(outputs);
177
+ return validateCodeNewRunnerOutputs(outputs, outputFields);
154
178
  }
155
179
  catch (error) {
156
180
  const enrichedError = await enrichCodeNodeErrorWithLocation({
@@ -42,11 +42,11 @@ export class GetGlobalNodeImpl extends NodeImpl {
42
42
  return [];
43
43
  }
44
44
  getOutputDefinitions() {
45
- const { onDemand, dataType } = this.chartNode.data;
45
+ const { id, useIdInput, onDemand, dataType } = this.chartNode.data;
46
46
  return [
47
47
  {
48
48
  id: 'value',
49
- title: 'Value',
49
+ title: !useIdInput && typeof id === 'string' && id.trim() ? id : 'Value',
50
50
  dataType: onDemand ? `fn<${dataType}>` : dataType,
51
51
  },
52
52
  {
@@ -5,53 +5,16 @@ import { nodeDefinition } from '../NodeDefinition.js';
5
5
  import {} from '../GraphProcessor.js';
6
6
  import {} from '../../index.js';
7
7
  import { coerceType, dedent, getInputOrData } from '../../utils/index.js';
8
- import { getError } from '../../utils/errors.js';
8
+ import { getError, isAbortError, formatCaughtRunError as formatCaughtRequestFailureError } from '../../utils/errors.js';
9
9
  const REQUEST_FAILED_OUTPUT_ID = 'requestFailed';
10
10
  const REQUEST_ERROR_OUTPUT_ID = 'requestError';
11
11
  const STATUS_CODE_OUTPUT_ID = 'statusCode';
12
12
  const RESPONSE_HEADERS_OUTPUT_ID = 'res_headers';
13
13
  const DEFAULT_RETRY_ON_NON_200_REPEAT_TIMES = 1;
14
14
  const DEFAULT_RETRY_ON_NON_200_COOLDOWN_MS = 0;
15
- function isAbortError(error, signal) {
16
- return signal.aborted || getError(error).name === 'AbortError';
17
- }
18
15
  function buildNon2xxStatusCodeError(statusCode) {
19
16
  return new Error(`HTTP call returned non-2XX status code: ${statusCode}`);
20
17
  }
21
- function stringifyNonErrorValue(value) {
22
- if (value == null) {
23
- return String(value);
24
- }
25
- if (typeof value === 'string') {
26
- return value;
27
- }
28
- if (typeof value !== 'object') {
29
- return String(value);
30
- }
31
- try {
32
- return JSON.stringify(value, null, 2) ?? String(value);
33
- }
34
- catch (_error) {
35
- return String(value);
36
- }
37
- }
38
- function formatCaughtRequestFailureError(error, seen = new Set()) {
39
- if (error && typeof error === 'object') {
40
- if (seen.has(error)) {
41
- return '[Circular error reference]';
42
- }
43
- seen.add(error);
44
- }
45
- if (error instanceof Error) {
46
- const errorText = error.stack?.trim() || `${error.name}: ${error.message}`.trim();
47
- const cause = error.cause;
48
- if (cause == null) {
49
- return errorText;
50
- }
51
- return `${errorText}\n\nCaused by: ${formatCaughtRequestFailureError(cause, seen)}`;
52
- }
53
- return stringifyNonErrorValue(error);
54
- }
55
18
  function createHttpCallRequestAttempts() {
56
19
  return {
57
20
  statusCodeValues: [],
@@ -396,52 +359,58 @@ export class HttpCallNodeImpl extends NodeImpl {
396
359
  language: 'json',
397
360
  enableFolding: true,
398
361
  },
362
+ {
363
+ type: 'toggle',
364
+ label: 'Binary Output',
365
+ dataKey: 'isBinaryOutput',
366
+ helperMessage: 'Toggle on if the response is expected to be binary data',
367
+ },
399
368
  {
400
369
  type: 'group',
401
- label: 'Retry on non-200',
402
- toggleDataKey: 'retryOnNon200',
370
+ label: 'Error behavior',
403
371
  editors: [
404
372
  {
405
- type: 'number',
406
- label: 'Repeat times',
407
- dataKey: 'retryOnNon200RepeatTimes',
408
- defaultValue: DEFAULT_RETRY_ON_NON_200_REPEAT_TIMES,
409
- min: 1,
410
- step: 1,
411
- layout: 'inline',
412
- helperMessage: 'Times to repeat after the initial request',
373
+ type: 'group',
374
+ label: 'Retry on non-200',
375
+ toggleDataKey: 'retryOnNon200',
376
+ editors: [
377
+ {
378
+ type: 'number',
379
+ label: 'Repeat times',
380
+ dataKey: 'retryOnNon200RepeatTimes',
381
+ defaultValue: DEFAULT_RETRY_ON_NON_200_REPEAT_TIMES,
382
+ min: 1,
383
+ step: 1,
384
+ layout: 'inline',
385
+ helperMessage: 'Times to repeat after the initial request',
386
+ },
387
+ {
388
+ type: 'number',
389
+ label: 'Cooldown, ms',
390
+ dataKey: 'retryOnNon200CooldownMs',
391
+ defaultValue: DEFAULT_RETRY_ON_NON_200_COOLDOWN_MS,
392
+ min: 0,
393
+ step: 1,
394
+ layout: 'inline',
395
+ helperMessage: 'Milliseconds to wait between repeats',
396
+ },
397
+ ],
398
+ },
399
+ {
400
+ type: 'toggle',
401
+ label: 'Fail on non-2XX status code',
402
+ dataKey: 'errorOnNon200',
403
+ helperMessage: (data) => data.retryOnNon200
404
+ ? 'With Retry on non-200 enabled, only the final response after all retries is checked.'
405
+ : undefined,
413
406
  },
414
407
  {
415
- type: 'number',
416
- label: 'Cooldown, ms',
417
- dataKey: 'retryOnNon200CooldownMs',
418
- defaultValue: DEFAULT_RETRY_ON_NON_200_COOLDOWN_MS,
419
- min: 0,
420
- step: 1,
421
- layout: 'inline',
422
- helperMessage: 'Milliseconds to wait between repeats',
408
+ type: 'toggle',
409
+ label: 'Catch all request failures',
410
+ dataKey: 'catchRequestFailed',
423
411
  },
424
412
  ],
425
413
  },
426
- {
427
- type: 'toggle',
428
- label: 'Binary Output',
429
- dataKey: 'isBinaryOutput',
430
- helperMessage: 'Toggle on if the response is expected to be binary data',
431
- },
432
- {
433
- type: 'toggle',
434
- label: 'Fail on non-2XX status code',
435
- dataKey: 'errorOnNon200',
436
- helperMessage: (data) => data.retryOnNon200
437
- ? 'With Retry on non-200 enabled, only the final response after all retries is checked.'
438
- : undefined,
439
- },
440
- {
441
- type: 'toggle',
442
- label: 'Catch all request failures',
443
- dataKey: 'catchRequestFailed',
444
- },
445
414
  ];
446
415
  }
447
416
  getBody() {
@@ -13,7 +13,10 @@ export class ImageNodeImpl extends NodeImpl {
13
13
  title: 'Image',
14
14
  visualData: { x: 0, y: 0, width: 250 },
15
15
  data: {
16
+ sourceType: 'binary',
16
17
  useDataInput: false,
18
+ base64: '',
19
+ useBase64Input: false,
17
20
  mediaType: 'image/png',
18
21
  useMediaTypeInput: false,
19
22
  },
@@ -21,7 +24,15 @@ export class ImageNodeImpl extends NodeImpl {
21
24
  }
22
25
  getInputDefinitions() {
23
26
  const inputDefinitions = [];
24
- if (this.chartNode.data.useDataInput) {
27
+ if (this.chartNode.data.sourceType === 'base64' && this.chartNode.data.useBase64Input) {
28
+ inputDefinitions.push({
29
+ id: 'base64',
30
+ title: 'Base64',
31
+ dataType: 'string',
32
+ coerced: false,
33
+ });
34
+ }
35
+ else if (this.chartNode.data.sourceType !== 'base64' && this.chartNode.data.useDataInput) {
25
36
  inputDefinitions.push({
26
37
  id: 'data',
27
38
  title: 'Data',
@@ -49,6 +60,16 @@ export class ImageNodeImpl extends NodeImpl {
49
60
  }
50
61
  getEditors() {
51
62
  return [
63
+ {
64
+ type: 'segmented',
65
+ label: 'Image source',
66
+ dataKey: 'sourceType',
67
+ defaultValue: 'binary',
68
+ options: [
69
+ { value: 'binary', label: 'Binary data' },
70
+ { value: 'base64', label: 'Base64' },
71
+ ],
72
+ },
52
73
  {
53
74
  type: 'dropdown',
54
75
  label: 'Media Type',
@@ -66,6 +87,17 @@ export class ImageNodeImpl extends NodeImpl {
66
87
  dataKey: 'data',
67
88
  useInputToggleDataKey: 'useDataInput',
68
89
  mediaTypeDataKey: 'mediaType',
90
+ hideIf: (data) => data.sourceType === 'base64',
91
+ },
92
+ {
93
+ type: 'code',
94
+ label: 'Base64',
95
+ dataKey: 'base64',
96
+ defaultValue: '',
97
+ language: 'plaintext',
98
+ useInputToggleDataKey: 'useBase64Input',
99
+ hideIf: (data) => data.sourceType !== 'base64',
100
+ helperMessage: 'Raw base64-encoded image bytes. The Media Type setting describes the decoded image.',
69
101
  },
70
102
  ];
71
103
  }
@@ -74,12 +106,21 @@ export class ImageNodeImpl extends NodeImpl {
74
106
  contextMenuTitle: 'Image',
75
107
  group: 'Data',
76
108
  infoBoxTitle: 'Image Node',
77
- infoBoxBody: 'Defines a static image for use with other nodes. Can convert a binary type into an image type.',
109
+ infoBoxBody: 'Defines an image from a file, binary input, or base64 text. Media Type describes the resulting image.',
78
110
  };
79
111
  }
80
112
  async process(inputData, context) {
81
113
  let data;
82
- if (this.chartNode.data.useDataInput) {
114
+ if (this.chartNode.data.sourceType === 'base64') {
115
+ const encodedData = this.chartNode.data.useBase64Input
116
+ ? expectType(inputData['base64'], 'string')
117
+ : this.data.base64;
118
+ if (!encodedData?.trim()) {
119
+ throw new Error('No base64 image data');
120
+ }
121
+ data = base64ToUint8Array(encodedData.trim());
122
+ }
123
+ else if (this.chartNode.data.useDataInput) {
83
124
  data = expectType(inputData['data'], 'binary');
84
125
  }
85
126
  else {
@@ -2,6 +2,7 @@ import { nanoid } from 'nanoid/non-secure';
2
2
  import { dedent } from 'ts-dedent';
3
3
  import { nodeDefinition } from '../NodeDefinition.js';
4
4
  import { NodeImpl } from '../NodeImpl.js';
5
+ import { formatNodeBodyMarkdownField, formatNodeBodyMarkdownLabel } from '../nodeBodyMarkdown.js';
5
6
  import { getCommonChatV2Inputs, getCommonChatV2Outputs } from '../chat-v2/chatV2Shared.js';
6
7
  import { getLLMChatV2Editors } from '../chat-v2/llmChatV2NodeEditors.js';
7
8
  import { createLLMChatV2NodeData, shouldIncludeLLMChatV2ToolCalls, } from '../chat-v2/llmChatV2NodeData.js';
@@ -15,22 +16,13 @@ import { shouldOutputChatV2RequestBody, shouldOutputChatV2ResponseBody } from '.
15
16
  import { buildLLMChatV2EditorCacheKey, resolveLLMChatV2RuntimeConfig, resolveLLMChatV2RuntimeProviderOptions, } from '../chat-v2/llmChatV2NodeRuntime.js';
16
17
  import { projectLLMChatV2EditorCacheHit, writeLLMChatV2EditorCache } from '../chat-v2/llmChatV2CacheBoundary.js';
17
18
  import { cloneLLMChatV2Outputs } from '../chat-v2/llmChatV2OutputClone.js';
19
+ import { createCaughtRunFailureOutputs, getRunFailureOutputDefinitions, shouldCatchRunFailure, withRunSuccessOutputs, } from '../nodeRunFailure.js';
18
20
  export { buildLLMChatV2EditorCacheKey, resolveLLMChatV2RuntimeProviderOptions };
19
21
  function usesBaseURLInput(data) {
20
22
  return data.provider === 'custom' && data.useCustomProviderBaseURLInput;
21
23
  }
22
- function escapeMarkdownInline(value) {
23
- return value
24
- .replace(/\r/g, '\\r')
25
- .replace(/\n/g, '\\n')
26
- .replace(/&/g, '&amp;')
27
- .replace(/</g, '&lt;')
28
- .replace(/>/g, '&gt;')
29
- .replace(/"/g, '&quot;')
30
- .replace(/([\\`*_[\]{}()#+\-.!|])/g, '\\$1');
31
- }
32
24
  function getBodyLine(label, value) {
33
- return `<span style="opacity: 0.55">${label}:</span> ${escapeMarkdownInline(value)}`;
25
+ return formatNodeBodyMarkdownField(label, value);
34
26
  }
35
27
  function escapeMarkdownPreformatted(value) {
36
28
  return value.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
@@ -40,7 +32,7 @@ function getBodySectionText(section) {
40
32
  ...section.fields.map((field) => getBodyLine(field.label, field.value)),
41
33
  ...(section.snippet
42
34
  ? [
43
- `<span style="opacity: 0.55">${section.snippet.label}:</span>`,
35
+ formatNodeBodyMarkdownLabel(section.snippet.label),
44
36
  `<pre>${escapeMarkdownPreformatted(section.snippet.text)}</pre>`,
45
37
  ]
46
38
  : []),
@@ -236,7 +228,7 @@ export class LLMChatV2NodeImpl extends NodeImpl {
236
228
  description: 'Human-readable profile fallback outcome for this LLM Chat run.',
237
229
  });
238
230
  }
239
- return outputs;
231
+ return [...outputs, ...getRunFailureOutputDefinitions(this.data)];
240
232
  }
241
233
  static getUIData() {
242
234
  return {
@@ -262,6 +254,20 @@ export class LLMChatV2NodeImpl extends NodeImpl {
262
254
  };
263
255
  }
264
256
  async process(inputs, context) {
257
+ let failureEvidence;
258
+ try {
259
+ context.signal.throwIfAborted();
260
+ return await this.processRun(inputs, context, (outputs) => {
261
+ failureEvidence = outputs;
262
+ });
263
+ }
264
+ catch (error) {
265
+ if (!shouldCatchRunFailure(this.data, error, context.signal))
266
+ throw error;
267
+ return createCaughtRunFailureOutputs(this.getOutputDefinitions(), error, failureEvidence);
268
+ }
269
+ }
270
+ async processRun(inputs, context, onFailure) {
265
271
  const invocationJournal = new LLMInvocationJournal();
266
272
  let profileAttemptSequence = 0;
267
273
  let latestFailureEvidence;
@@ -296,11 +302,13 @@ export class LLMChatV2NodeImpl extends NodeImpl {
296
302
  });
297
303
  },
298
304
  });
305
+ context.signal.throwIfAborted();
299
306
  const toolCallContinuation = context.toolCallContinuation;
300
307
  const cacheHit = projectLLMChatV2EditorCacheHit(runtime);
301
308
  if (cacheHit != null) {
302
309
  context.markResultAsEditorCacheHit?.();
303
- return cacheHit;
310
+ context.signal.throwIfAborted();
311
+ return withRunSuccessOutputs(this.data, cacheHit);
304
312
  }
305
313
  let invocation;
306
314
  try {
@@ -333,7 +341,8 @@ export class LLMChatV2NodeImpl extends NodeImpl {
333
341
  profileSummary: runtime.getProfileSummary?.(),
334
342
  });
335
343
  const failureOutputs = mergeLLMInvocationFailureOutputs(latestFailureEvidence, diagnostics);
336
- if (Object.keys(failureOutputs).length > 0) {
344
+ onFailure(failureOutputs);
345
+ if (!shouldCatchRunFailure(this.data, error, context.signal) && Object.keys(failureOutputs).length > 0) {
337
346
  // This checkpoint is the durable terminal counterpart to the live
338
347
  // partial-output stream. GraphProcessor attaches it to nodeError,
339
348
  // so recordings and remote executors cannot lose evidence merely
@@ -354,6 +363,7 @@ export class LLMChatV2NodeImpl extends NodeImpl {
354
363
  }
355
364
  throw error;
356
365
  }
366
+ context.signal.throwIfAborted();
357
367
  const { result, terminalSnapshot } = invocation;
358
368
  projectLLMInvocationResult({
359
369
  result,
@@ -363,6 +373,7 @@ export class LLMChatV2NodeImpl extends NodeImpl {
363
373
  llmAttempts: invocationJournal.llmAttempts,
364
374
  profileSummary: runtime.getProfileSummary?.(),
365
375
  });
376
+ result.commonOutputs = withRunSuccessOutputs(this.data, result.commonOutputs);
366
377
  // The final display page is taken after result projection, so it exactly
367
378
  // matches the one graph-semantic output map returned below.
368
379
  if (terminalSnapshot != null) {
@@ -383,6 +394,7 @@ export class LLMChatV2NodeImpl extends NodeImpl {
383
394
  if (toolCallContinuation && !isChatV2PipelineProviderFailureResult(result) && result.functionCalls.length > 0) {
384
395
  toolCallContinuation.release();
385
396
  }
397
+ context.signal.throwIfAborted();
386
398
  writeLLMChatV2EditorCache({ runtime, result });
387
399
  return result.commonOutputs;
388
400
  }
@@ -1,22 +1,13 @@
1
1
  import { nanoid } from 'nanoid/non-secure';
2
2
  import { nodeDefinition } from '../NodeDefinition.js';
3
3
  import { NodeImpl } from '../NodeImpl.js';
4
+ import { formatNodeBodyMarkdownField, formatNodeBodyMarkdownLabel } from '../nodeBodyMarkdown.js';
4
5
  import { getLLMProfileEditors } from '../chat-v2/llmChatV2NodeEditors.js';
5
6
  import { getLLMProfileBodySections } from '../chat-v2/llmProfileBody.js';
6
7
  import { resolveLLMProfileNodeValue } from '../chat-v2/llmProfileNodeRuntime.js';
7
8
  import { createLLMProfileNodeData } from '../chat-v2/llmProfileTypes.js';
8
- function escapeMarkdownInline(value) {
9
- return String(value)
10
- .replace(/\r/g, '\\r')
11
- .replace(/\n/g, '\\n')
12
- .replace(/&/g, '&amp;')
13
- .replace(/</g, '&lt;')
14
- .replace(/>/g, '&gt;')
15
- .replace(/"/g, '&quot;')
16
- .replace(/([\\`*_[\]{}()#+\-.!|])/g, '\\$1');
17
- }
18
9
  function getBodyLine(label, value) {
19
- return `<span style="opacity: 0.55">${label}:</span> ${escapeMarkdownInline(value)}`;
10
+ return formatNodeBodyMarkdownField(label, value);
20
11
  }
21
12
  export class LLMProfileNodeImpl extends NodeImpl {
22
13
  static create() {
@@ -120,7 +111,7 @@ export class LLMProfileNodeImpl extends NodeImpl {
120
111
  .map((section) => {
121
112
  const fields = section.fields.map((field) => getBodyLine(field.label, field.value));
122
113
  const snippet = section.snippet
123
- ? `${getBodyLine(section.snippet.label, '')}\n${escapeMarkdownInline(section.snippet.text)}`
114
+ ? `${formatNodeBodyMarkdownLabel(section.snippet.label)}\n<pre>${escapeHtml(section.snippet.text)}</pre>`
124
115
  : undefined;
125
116
  return [...fields, ...(snippet ? [snippet] : [])].join('\n');
126
117
  })
@@ -148,4 +139,7 @@ export class LLMProfileNodeImpl extends NodeImpl {
148
139
  };
149
140
  }
150
141
  }
142
+ function escapeHtml(value) {
143
+ return String(value).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
144
+ }
151
145
  export const llmProfileNode = nodeDefinition(LLMProfileNodeImpl, 'LLM Profile');
@@ -4,11 +4,45 @@ import { nodeDefinition } from '../NodeDefinition.js';
4
4
  import {} from '../NodeImpl.js';
5
5
  import {} from '../NodeBase.js';
6
6
  import {} from '../EditorDefinition.js';
7
+ import {} from '../GraphProcessor.js';
8
+ import {} from '../ProcessContext.js';
9
+ import {} from '../DataValue.js';
10
+ import { extractInterpolationVariableReferences, getInterpolationGlobalValues, interpolate, } from '../../utils/interpolation.js';
11
+ import { createInterpolationInputDefinition } from '../interpolationInputDefinition.js';
7
12
  import { MatchCaseNodeBase, } from './MatchCaseNodeBase.js';
13
+ const MATCH_CASE_INTERPOLATION_INPUT_PREFIX = 'input-';
14
+ /**
15
+ * Discovers case-template inputs without joining case strings, so an incomplete
16
+ * token at one row boundary can never become a token in a neighboring row.
17
+ */
18
+ function getMatchCaseInterpolationVariableReferences(cases) {
19
+ const references = new Map();
20
+ for (const caseValue of cases) {
21
+ for (const reference of extractInterpolationVariableReferences(caseValue)) {
22
+ const existing = references.get(reference.baseName);
23
+ if (existing) {
24
+ existing.hasPath ||= reference.hasPath;
25
+ }
26
+ else {
27
+ references.set(reference.baseName, { ...reference });
28
+ }
29
+ }
30
+ }
31
+ return Array.from(references.values(), (reference) => ({ ...reference }));
32
+ }
33
+ function getMatchCaseInterpolationInputId(name) {
34
+ return `${MATCH_CASE_INTERPOLATION_INPUT_PREFIX}${name}`;
35
+ }
36
+ function getMatchCaseInterpolationInputs(references, inputs) {
37
+ return Object.fromEntries(references.map(({ baseName }) => [baseName, inputs[getMatchCaseInterpolationInputId(baseName)]]));
38
+ }
8
39
  /** Match case is the current routing node; legacy `match` remains regex-only. */
9
40
  export class MatchCaseNodeImpl extends MatchCaseNodeBase {
10
41
  caseEditorLabel = 'Cases';
11
42
  caseEditorPlaceholder = 'Case';
43
+ caseEditorHighlightsInterpolation = true;
44
+ caseEditorInputFontFamily = 'monospace';
45
+ caseEditorBoxed = true;
12
46
  casesEditorPlacement = 'before-trigger';
13
47
  customCaseValuesEditorLabel = '';
14
48
  defaultExclusive = true;
@@ -88,12 +122,52 @@ export class MatchCaseNodeImpl extends MatchCaseNodeBase {
88
122
  shouldHideCustomCaseValues(data) {
89
123
  return (data.returnValue ?? 'true') !== 'custom';
90
124
  }
125
+ getInterpolationInputDefinitions() {
126
+ return getMatchCaseInterpolationVariableReferences(this.data.cases).map(({ baseName, hasPath }) => createInterpolationInputDefinition({
127
+ id: getMatchCaseInterpolationInputId(baseName),
128
+ interpolationName: baseName,
129
+ dataType: hasPath ? 'any' : 'string',
130
+ required: false,
131
+ description: `The value substituted for {{${baseName}}} in Cases.`,
132
+ }));
133
+ }
134
+ resolveCaseValues(inputs, context) {
135
+ const references = getMatchCaseInterpolationVariableReferences(this.data.cases);
136
+ if (references.length === 0 && !this.data.cases.some((caseValue) => caseValue.includes('{{'))) {
137
+ return this.data.cases;
138
+ }
139
+ const globalValueCache = new Map();
140
+ const missingGlobalIds = new Set();
141
+ const getCachedGlobal = (id) => {
142
+ if (globalValueCache.has(id)) {
143
+ return globalValueCache.get(id);
144
+ }
145
+ if (missingGlobalIds.has(id)) {
146
+ return undefined;
147
+ }
148
+ const value = context?.getGlobal?.(id);
149
+ if (value === undefined) {
150
+ missingGlobalIds.add(id);
151
+ }
152
+ else {
153
+ globalValueCache.set(id, value);
154
+ }
155
+ return value;
156
+ };
157
+ const interpolationInputs = getMatchCaseInterpolationInputs(references, inputs);
158
+ return this.data.cases.map((caseValue) => interpolate(caseValue, interpolationInputs, context?.graphInputNodeValues, context?.contextValues, {
159
+ coerceBareVariableDataValues: true,
160
+ globalValues: getInterpolationGlobalValues(caseValue, getCachedGlobal),
161
+ }));
162
+ }
91
163
  getEditors() {
92
164
  return [
93
165
  {
94
166
  type: 'segmented',
95
167
  label: 'Match mode',
96
168
  dataKey: 'matchMode',
169
+ layout: 'inline',
170
+ allowOptionWrap: false,
97
171
  defaultValue: 'plainText',
98
172
  options: [
99
173
  { value: 'plainText', label: 'Plain text' },
@@ -104,6 +178,7 @@ export class MatchCaseNodeImpl extends MatchCaseNodeBase {
104
178
  type: 'toggle',
105
179
  label: 'Case sensitive',
106
180
  dataKey: 'caseSensitive',
181
+ layout: 'inline',
107
182
  defaultValue: true,
108
183
  hideIf: (data) => data.matchMode === 'regex',
109
184
  },
@@ -113,7 +188,7 @@ export class MatchCaseNodeImpl extends MatchCaseNodeBase {
113
188
  static getUIData() {
114
189
  return {
115
190
  infoBoxBody: dedent `
116
- Routes an Input value to matching case outputs. Plain text cases use exact, case-sensitive equality by default; turn off Case sensitive to ignore letter case. Choose Regular expression to use the existing JavaScript RegExp pattern behavior; the Case sensitive switch does not apply in that mode.
191
+ Routes an Input value to matching case outputs. Plain text cases use exact, case-sensitive equality by default; turn off Case sensitive to ignore letter case. Choose Regular expression to use the existing JavaScript RegExp pattern behavior; the Case sensitive switch does not apply in that mode. Cases support {{variable}} interpolation, JSONPath, and the @graphInputs, @context, and @globals runtime roots; ordinary variables create optional inputs.
117
192
 
118
193
  Choose First matching case to trigger only the first matching output, or All matching cases to trigger every matching output. Active outputs return True by default. They can instead return the Input value, or a custom value supplied through one shared Output value input or separate Output values inputs for every case and Unmatched.
119
194
  `,