@valerypopoff/rivet2-core 2.15.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 (111) hide show
  1. package/dist/cjs/bundle.cjs +4350 -2077
  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 +5 -2
  8. package/dist/esm/exports.js +2 -0
  9. package/dist/esm/model/GraphBoundaryCache.js +2 -1
  10. package/dist/esm/model/GraphProcessor.js +268 -6
  11. package/dist/esm/model/Nodes.js +10 -0
  12. package/dist/esm/model/ProjectBundle.js +235 -0
  13. package/dist/esm/model/SplitRunProcessor.js +28 -7
  14. package/dist/esm/model/StreamingWatchTopology.js +118 -8
  15. package/dist/esm/model/SubgraphProjectTarget.js +7 -0
  16. package/dist/esm/model/chat-v2/aiSdkBridge.js +7 -5
  17. package/dist/esm/model/chat-v2/chatV2Pipeline.js +13 -8
  18. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +19 -1
  19. package/dist/esm/model/chat-v2/chatV2Shared.js +2 -1
  20. package/dist/esm/model/chat-v2/llmChatV2Body.js +11 -8
  21. package/dist/esm/model/chat-v2/llmChatV2NodeData.js +2 -0
  22. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +15 -1
  23. package/dist/esm/model/chat-v2/llmChatV2NodeMigration.js +22 -2
  24. package/dist/esm/model/chat-v2/llmProfile.js +3 -0
  25. package/dist/esm/model/chat-v2/llmProfileBody.js +2 -2
  26. package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +1 -1
  27. package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +1 -1
  28. package/dist/esm/model/chat-v2/temperature.js +9 -0
  29. package/dist/esm/model/classifier/credentials.js +30 -4
  30. package/dist/esm/model/classifier/images.js +176 -0
  31. package/dist/esm/model/classifier/json.js +57 -0
  32. package/dist/esm/model/classifier/limits.js +270 -0
  33. package/dist/esm/model/classifier/openai.js +118 -0
  34. package/dist/esm/model/classifier/preparation.js +74 -0
  35. package/dist/esm/model/classifier/providers.js +260 -185
  36. package/dist/esm/model/classifier/questionHelpers.js +29 -45
  37. package/dist/esm/model/classifier/questions.js +53 -0
  38. package/dist/esm/model/classifier/response.js +75 -0
  39. package/dist/esm/model/classifier/state.js +204 -0
  40. package/dist/esm/model/nodeRunFailure.js +47 -0
  41. package/dist/esm/model/nodes/CatchStreamingChunksNode.js +42 -0
  42. package/dist/esm/model/nodes/ClassifierEvaluateNode.js +178 -138
  43. package/dist/esm/model/nodes/ClassifierQuestionNode.js +59 -15
  44. package/dist/esm/model/nodes/GetGlobalNode.js +2 -2
  45. package/dist/esm/model/nodes/HttpCallNode.js +44 -75
  46. package/dist/esm/model/nodes/ImageNode.js +44 -3
  47. package/dist/esm/model/nodes/LLMChatV2Node.js +24 -3
  48. package/dist/esm/model/nodes/ObjectNode.js +29 -18
  49. package/dist/esm/model/nodes/PromptNode.js +2 -1
  50. package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +4 -1
  51. package/dist/esm/model/nodes/SetGlobalNode.js +5 -3
  52. package/dist/esm/model/nodes/StopWatchingStreamingOutputNode.js +8 -8
  53. package/dist/esm/model/nodes/StreamValueNode.js +38 -0
  54. package/dist/esm/model/nodes/SubGraphNode.js +196 -35
  55. package/dist/esm/model/nodes/ToBase64Node.js +106 -0
  56. package/dist/esm/model/nodes/WatchStreamingOutputNode.js +7 -7
  57. package/dist/esm/recording/ExecutionRecorder.js +26 -0
  58. package/dist/esm/utils/base64.js +18 -15
  59. package/dist/esm/utils/errors.js +41 -0
  60. package/dist/esm/utils/interpolation.js +44 -22
  61. package/dist/esm/utils/interpolationSyntax.js +15 -6
  62. package/dist/esm/utils/serialization/serialization.js +3 -2
  63. package/dist/esm/utils/serialization/serializationUtils.js +6 -0
  64. package/dist/esm/utils/serialization/serialization_v4.js +15 -3
  65. package/dist/types/api/createProcessor.d.ts +7 -1
  66. package/dist/types/exports.d.ts +2 -0
  67. package/dist/types/model/CycleDetector.d.ts +1 -2
  68. package/dist/types/model/ExecutorProtocol.d.ts +2 -0
  69. package/dist/types/model/GraphBoundaryCache.d.ts +2 -0
  70. package/dist/types/model/GraphProcessor.d.ts +1 -0
  71. package/dist/types/model/Nodes.d.ts +6 -2
  72. package/dist/types/model/ProcessContext.d.ts +12 -0
  73. package/dist/types/model/ProjectBundle.d.ts +54 -0
  74. package/dist/types/model/ProjectReferenceLoader.d.ts +3 -0
  75. package/dist/types/model/StreamingWatchTopology.d.ts +11 -1
  76. package/dist/types/model/SubgraphProjectTarget.d.ts +38 -0
  77. package/dist/types/model/chat-v2/chatV2Shared.d.ts +1 -1
  78. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +3 -1
  79. package/dist/types/model/chat-v2/llmChatV2NodeMigration.d.ts +3 -1
  80. package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +6 -6
  81. package/dist/types/model/chat-v2/temperature.d.ts +2 -0
  82. package/dist/types/model/classifier/credentials.d.ts +3 -1
  83. package/dist/types/model/classifier/images.d.ts +18 -0
  84. package/dist/types/model/classifier/json.d.ts +19 -0
  85. package/dist/types/model/classifier/limits.d.ts +42 -0
  86. package/dist/types/model/classifier/openai.d.ts +5 -0
  87. package/dist/types/model/classifier/preparation.d.ts +16 -0
  88. package/dist/types/model/classifier/providers.d.ts +67 -9
  89. package/dist/types/model/classifier/questionHelpers.d.ts +6 -4
  90. package/dist/types/model/classifier/questions.d.ts +4 -0
  91. package/dist/types/model/classifier/response.d.ts +4 -0
  92. package/dist/types/model/classifier/state.d.ts +37 -0
  93. package/dist/types/model/classifier/types.d.ts +2 -0
  94. package/dist/types/model/nodeRunFailure.d.ts +13 -0
  95. package/dist/types/model/nodes/CatchStreamingChunksNode.d.ts +20 -0
  96. package/dist/types/model/nodes/ClassifierEvaluateNode.d.ts +3 -0
  97. package/dist/types/model/nodes/GetGlobalNode.d.ts +7 -0
  98. package/dist/types/model/nodes/ImageNode.d.ts +4 -0
  99. package/dist/types/model/nodes/LLMChatV2Node.d.ts +1 -0
  100. package/dist/types/model/nodes/ObjectNode.d.ts +2 -1
  101. package/dist/types/model/nodes/StreamValueNode.d.ts +14 -0
  102. package/dist/types/model/nodes/SubGraphNode.d.ts +21 -2
  103. package/dist/types/model/nodes/ToBase64Node.d.ts +12 -0
  104. package/dist/types/recording/ExecutionRecorder.d.ts +8 -2
  105. package/dist/types/utils/base64.d.ts +1 -1
  106. package/dist/types/utils/errors.d.ts +4 -0
  107. package/dist/types/utils/interpolation.d.ts +13 -2
  108. package/dist/types/utils/interpolationSyntax.d.ts +1 -1
  109. package/dist/types/utils/serialization/serialization.d.ts +3 -1
  110. package/dist/types/utils/serialization/serializationUtils.d.ts +1 -0
  111. package/package.json +1 -1
@@ -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 {
@@ -16,6 +16,7 @@ import { shouldOutputChatV2RequestBody, shouldOutputChatV2ResponseBody } from '.
16
16
  import { buildLLMChatV2EditorCacheKey, resolveLLMChatV2RuntimeConfig, resolveLLMChatV2RuntimeProviderOptions, } from '../chat-v2/llmChatV2NodeRuntime.js';
17
17
  import { projectLLMChatV2EditorCacheHit, writeLLMChatV2EditorCache } from '../chat-v2/llmChatV2CacheBoundary.js';
18
18
  import { cloneLLMChatV2Outputs } from '../chat-v2/llmChatV2OutputClone.js';
19
+ import { createCaughtRunFailureOutputs, getRunFailureOutputDefinitions, shouldCatchRunFailure, withRunSuccessOutputs, } from '../nodeRunFailure.js';
19
20
  export { buildLLMChatV2EditorCacheKey, resolveLLMChatV2RuntimeProviderOptions };
20
21
  function usesBaseURLInput(data) {
21
22
  return data.provider === 'custom' && data.useCustomProviderBaseURLInput;
@@ -227,7 +228,7 @@ export class LLMChatV2NodeImpl extends NodeImpl {
227
228
  description: 'Human-readable profile fallback outcome for this LLM Chat run.',
228
229
  });
229
230
  }
230
- return outputs;
231
+ return [...outputs, ...getRunFailureOutputDefinitions(this.data)];
231
232
  }
232
233
  static getUIData() {
233
234
  return {
@@ -253,6 +254,20 @@ export class LLMChatV2NodeImpl extends NodeImpl {
253
254
  };
254
255
  }
255
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) {
256
271
  const invocationJournal = new LLMInvocationJournal();
257
272
  let profileAttemptSequence = 0;
258
273
  let latestFailureEvidence;
@@ -287,11 +302,13 @@ export class LLMChatV2NodeImpl extends NodeImpl {
287
302
  });
288
303
  },
289
304
  });
305
+ context.signal.throwIfAborted();
290
306
  const toolCallContinuation = context.toolCallContinuation;
291
307
  const cacheHit = projectLLMChatV2EditorCacheHit(runtime);
292
308
  if (cacheHit != null) {
293
309
  context.markResultAsEditorCacheHit?.();
294
- return cacheHit;
310
+ context.signal.throwIfAborted();
311
+ return withRunSuccessOutputs(this.data, cacheHit);
295
312
  }
296
313
  let invocation;
297
314
  try {
@@ -324,7 +341,8 @@ export class LLMChatV2NodeImpl extends NodeImpl {
324
341
  profileSummary: runtime.getProfileSummary?.(),
325
342
  });
326
343
  const failureOutputs = mergeLLMInvocationFailureOutputs(latestFailureEvidence, diagnostics);
327
- if (Object.keys(failureOutputs).length > 0) {
344
+ onFailure(failureOutputs);
345
+ if (!shouldCatchRunFailure(this.data, error, context.signal) && Object.keys(failureOutputs).length > 0) {
328
346
  // This checkpoint is the durable terminal counterpart to the live
329
347
  // partial-output stream. GraphProcessor attaches it to nodeError,
330
348
  // so recordings and remote executors cannot lose evidence merely
@@ -345,6 +363,7 @@ export class LLMChatV2NodeImpl extends NodeImpl {
345
363
  }
346
364
  throw error;
347
365
  }
366
+ context.signal.throwIfAborted();
348
367
  const { result, terminalSnapshot } = invocation;
349
368
  projectLLMInvocationResult({
350
369
  result,
@@ -354,6 +373,7 @@ export class LLMChatV2NodeImpl extends NodeImpl {
354
373
  llmAttempts: invocationJournal.llmAttempts,
355
374
  profileSummary: runtime.getProfileSummary?.(),
356
375
  });
376
+ result.commonOutputs = withRunSuccessOutputs(this.data, result.commonOutputs);
357
377
  // The final display page is taken after result projection, so it exactly
358
378
  // matches the one graph-semantic output map returned below.
359
379
  if (terminalSnapshot != null) {
@@ -374,6 +394,7 @@ export class LLMChatV2NodeImpl extends NodeImpl {
374
394
  if (toolCallContinuation && !isChatV2PipelineProviderFailureResult(result) && result.functionCalls.length > 0) {
375
395
  toolCallContinuation.release();
376
396
  }
397
+ context.signal.throwIfAborted();
377
398
  writeLLMChatV2EditorCache({ runtime, result });
378
399
  return result.commonOutputs;
379
400
  }
@@ -20,15 +20,6 @@ function isEscapedCharacter(value, index) {
20
20
  function isUnescapedQuoteAt(value, index) {
21
21
  return index >= 0 && index < value.length && value[index] === '"' && !isEscapedCharacter(value, index);
22
22
  }
23
- function isInsideJsonString(value, index) {
24
- let insideString = false;
25
- for (let i = 0; i < index; i++) {
26
- if (isUnescapedQuoteAt(value, i)) {
27
- insideString = !insideString;
28
- }
29
- }
30
- return insideString;
31
- }
32
23
  function stringifyJsonValue(value) {
33
24
  if (value == null) {
34
25
  return 'null';
@@ -52,17 +43,36 @@ function stringifyEmbeddedJsonStringFragment(value) {
52
43
  * Interpolates a JSON template without parsing it. Shared by Object and other
53
44
  * first-party nodes which author structured EntryType values.
54
45
  */
55
- export function interpolateJsonTemplate(baseString, values, graphInputNodeValues, contextValues, globalValues) {
46
+ export function interpolateJsonTemplate(baseString, values, graphInputNodeValues, contextValues, globalValues, guard, unwrapVariableDataValues = false) {
47
+ guard?.check();
56
48
  const protectedBaseString = protectEscapedInterpolationTokens(baseString);
57
- const parsedTemplate = parseInterpolationTemplate(protectedBaseString);
49
+ const parsedTemplate = parseInterpolationTemplate(protectedBaseString, guard?.check, guard?.tokenLimit);
58
50
  if (parsedTemplate.tokens.length === 0) {
59
51
  return restoreEscapedInterpolationTokens(protectedBaseString);
60
52
  }
61
53
  let result = '';
62
54
  let cursor = 0;
55
+ let quoteCursor = 0;
56
+ let insideString = false;
57
+ let escaped = false;
58
+ const append = (fragment) => {
59
+ guard?.output(fragment, result.length);
60
+ result += fragment;
61
+ };
63
62
  for (const token of parsedTemplate.tokens) {
64
63
  const tokenSpan = token.span;
65
- const isInsideString = isInsideJsonString(protectedBaseString, tokenSpan.start);
64
+ guard?.check();
65
+ // Scan authored quotes once, including token contents, matching the old
66
+ // per-token scan without repeatedly walking the entire template prefix.
67
+ for (; quoteCursor < tokenSpan.start; quoteCursor++) {
68
+ if ((quoteCursor & 4095) === 0)
69
+ guard?.check();
70
+ const character = protectedBaseString[quoteCursor];
71
+ if (character === '"' && !escaped)
72
+ insideString = !insideString;
73
+ escaped = character === '\\' && !escaped;
74
+ }
75
+ const isInsideString = insideString;
66
76
  const isWholeQuotedToken = isInsideString &&
67
77
  isUnescapedQuoteAt(protectedBaseString, tokenSpan.start - 1) &&
68
78
  isUnescapedQuoteAt(protectedBaseString, tokenSpan.end);
@@ -74,25 +84,26 @@ export function interpolateJsonTemplate(baseString, values, graphInputNodeValues
74
84
  graphInputValues: graphInputNodeValues,
75
85
  contextValues,
76
86
  globalValues,
77
- unwrapVariableDataValues: false,
87
+ unwrapVariableDataValues,
88
+ guard,
78
89
  })
79
90
  : undefined;
80
91
  // Restore escaped delimiters only from the authored JSON template. An
81
92
  // interpolated string may itself contain literal interpolation syntax and
82
93
  // must not be processed again while the final JSON is assembled.
83
- result += restoreEscapedInterpolationTokens(protectedBaseString.slice(cursor, replacementStart));
94
+ append(restoreEscapedInterpolationTokens(protectedBaseString.slice(cursor, replacementStart)));
84
95
  if (isInsideString && !isWholeQuotedToken) {
85
- result += stringifyEmbeddedJsonStringFragment(value);
96
+ append(stringifyEmbeddedJsonStringFragment(value));
86
97
  }
87
98
  else if (isWholeQuotedToken) {
88
- result += stringifyWholeQuotedJsonValue(value);
99
+ append(stringifyWholeQuotedJsonValue(value));
89
100
  }
90
101
  else {
91
- result += stringifyJsonValue(value);
102
+ append(stringifyJsonValue(value));
92
103
  }
93
104
  cursor = replacementEnd;
94
105
  }
95
- result += restoreEscapedInterpolationTokens(protectedBaseString.slice(cursor));
106
+ append(restoreEscapedInterpolationTokens(protectedBaseString.slice(cursor)));
96
107
  return result;
97
108
  }
98
109
  export class ObjectNodeImpl extends NodeImpl {
@@ -9,6 +9,7 @@ import { getInputOrData } from '../../utils/index.js';
9
9
  import { extractInterpolationVariableReferences, getInterpolationGlobalValues, interpolate } from '../../utils/interpolation.js';
10
10
  import { match } from 'ts-pattern';
11
11
  import { createInterpolationInputDefinition } from '../interpolationInputDefinition.js';
12
+ import { buildNodeBodyPreview } from './nodeBodyPreview.js';
12
13
  export class PromptNodeImpl extends NodeImpl {
13
14
  static create() {
14
15
  const chartNode = {
@@ -164,7 +165,7 @@ export class PromptNodeImpl extends NodeImpl {
164
165
  },
165
166
  {
166
167
  type: 'colorized',
167
- text: this.data.promptText.split('\n').slice(0, 15).join('\n').trim(),
168
+ text: buildNodeBodyPreview(this.data.promptText),
168
169
  language: 'prompt-interpolation-markdown',
169
170
  theme: 'prompt-interpolation',
170
171
  },
@@ -124,7 +124,10 @@ export class ReferencedGraphAliasNodeImpl extends NodeImpl {
124
124
  });
125
125
  try {
126
126
  const startTime = Date.now();
127
- const outputs = await subGraphProcessor.processGraph(context, inputData, context.contextValues, {
127
+ const outputs = await subGraphProcessor.processGraph({
128
+ ...context,
129
+ datasetProvider: context.projectReferenceLoader?.getDatasetProvider?.(referencedProject) ?? context.datasetProvider,
130
+ }, inputData, context.contextValues, {
128
131
  graphInputStreams: context.graphInputStreams,
129
132
  // This node preserves the referenced graph's named boundary ports,
130
133
  // so it may relay their direct producer partials to a parent Watch.
@@ -46,15 +46,17 @@ export class SetGlobalNodeImpl extends NodeImpl {
46
46
  return inputs;
47
47
  }
48
48
  getOutputDefinitions() {
49
+ const { id, useIdInput } = this.data;
50
+ const fixedId = !useIdInput && typeof id === 'string' && id.trim() ? id : undefined;
49
51
  return [
50
52
  {
51
53
  id: 'saved-value',
52
- title: 'Value',
54
+ title: fixedId ?? 'Value',
53
55
  dataType: this.data.dataType,
54
56
  },
55
57
  {
56
58
  id: 'previous-value',
57
- title: 'Previous Value',
59
+ title: fixedId ? `Prev value of: ${fixedId}` : 'Previous Value',
58
60
  dataType: this.data.dataType,
59
61
  },
60
62
  {
@@ -83,7 +85,7 @@ export class SetGlobalNodeImpl extends NodeImpl {
83
85
  }
84
86
  getBody() {
85
87
  return dedent `
86
- ${this.data.id}
88
+ ${this.data.useIdInput ? '(ID from input)' : this.data.id}
87
89
  Type: ${this.data.dataType}
88
90
  `;
89
91
  }
@@ -7,7 +7,7 @@ export class StopWatchingStreamingOutputNodeImpl extends NodeImpl {
7
7
  return {
8
8
  data: {},
9
9
  id: nanoid(),
10
- title: 'Stop Watching Streaming Output',
10
+ title: 'Stop watching streaming',
11
11
  type: 'stopWatchingStreamingOutput',
12
12
  visualData: { x: 0, y: 0, width: 230 },
13
13
  };
@@ -20,11 +20,11 @@ export class StopWatchingStreamingOutputNodeImpl extends NodeImpl {
20
20
  }
21
21
  static getUIData() {
22
22
  return {
23
- contextMenuTitle: 'Stop Watching Streaming Output',
24
- group: ['Logic'],
25
- infoBoxTitle: 'Stop Watching Streaming Output Node',
23
+ contextMenuTitle: 'Stop watching streaming',
24
+ group: ['Streaming'],
25
+ infoBoxTitle: 'Stop watching streaming node',
26
26
  infoBoxBody: dedent `
27
- Accepts a value from a Watch Streaming Output branch, stops future streaming
27
+ Accepts a value from a Watch streaming branch, stops future streaming
28
28
  snapshots, and lets its completed output continue through the ordinary graph.
29
29
  In parallel mode, the first completed branch to reach this node wins.
30
30
  If the stream ends without a value reaching this node, it is shown as Not ran
@@ -38,13 +38,13 @@ export class StopWatchingStreamingOutputNodeImpl extends NodeImpl {
38
38
  async process(inputs, context) {
39
39
  const value = inputs['value'];
40
40
  if (!value) {
41
- throw new Error('Stop Watching Streaming Output requires a value.');
41
+ throw new Error('Stop watching streaming requires a value.');
42
42
  }
43
43
  if (!context.acceptStreamingWatchStop) {
44
- throw new Error('Stop Watching Streaming Output must be downstream of Watch Streaming Output.');
44
+ throw new Error('Stop watching streaming must be downstream of Watch streaming.');
45
45
  }
46
46
  context.acceptStreamingWatchStop();
47
47
  return { ['value']: value };
48
48
  }
49
49
  }
50
- export const stopWatchingStreamingOutputNode = nodeDefinition(StopWatchingStreamingOutputNodeImpl, 'Stop Watching Streaming Output');
50
+ export const stopWatchingStreamingOutputNode = nodeDefinition(StopWatchingStreamingOutputNodeImpl, 'Stop watching streaming');
@@ -0,0 +1,38 @@
1
+ import { nanoid } from 'nanoid/non-secure';
2
+ import { nodeDefinition } from '../NodeDefinition.js';
3
+ import { NodeImpl } from '../NodeImpl.js';
4
+ /** Emits one partial snapshot without changing the ordinary final value. */
5
+ export class StreamValueNodeImpl extends NodeImpl {
6
+ static create() {
7
+ return {
8
+ id: nanoid(),
9
+ type: 'streamValue',
10
+ title: 'Stream value',
11
+ data: {},
12
+ visualData: { x: 0, y: 0, width: 220 },
13
+ };
14
+ }
15
+ getInputDefinitions() {
16
+ return [{ id: 'value', title: 'Value', dataType: 'any', required: true, coerced: false }];
17
+ }
18
+ getOutputDefinitions() {
19
+ return [{ id: 'value', title: 'Value', dataType: 'any' }];
20
+ }
21
+ static getUIData() {
22
+ return {
23
+ contextMenuTitle: 'Stream value',
24
+ group: ['Streaming'],
25
+ infoBoxTitle: 'Stream value node',
26
+ infoBoxBody: 'Emits one streaming update as soon as its input is ready, then passes the same value through normally. Connect directly to Graph Output to send it to a caller before the child graph finishes.',
27
+ };
28
+ }
29
+ async process(inputs, context) {
30
+ const value = inputs['value'];
31
+ if (!value)
32
+ throw new Error('Stream value requires a value.');
33
+ const outputs = { ['value']: value };
34
+ context.onPartialOutputs?.(outputs);
35
+ return outputs;
36
+ }
37
+ }
38
+ export const streamValueNode = nodeDefinition(StreamValueNodeImpl, 'Stream value');