@valerypopoff/rivet2-core 2.1.10 → 2.4.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/README.md +1 -1
  2. package/dist/cjs/bundle.cjs +2604 -949
  3. package/dist/cjs/bundle.cjs.map +4 -4
  4. package/dist/cjs/webAppRuntime.cjs +1549 -99
  5. package/dist/cjs/webAppRuntime.cjs.map +4 -4
  6. package/dist/esm/api/createProcessor.js +4 -0
  7. package/dist/esm/exports.js +2 -0
  8. package/dist/esm/integrations/CodeRunner.js +2 -7
  9. package/dist/esm/integrations/CodeRunnerOptions.js +7 -0
  10. package/dist/esm/model/AgentResponseTrace.js +137 -11
  11. package/dist/esm/model/GraphProcessor.js +28 -0
  12. package/dist/esm/model/NodeExclusionPolicy.js +9 -1
  13. package/dist/esm/model/ProcessContextBuilder.js +2 -1
  14. package/dist/esm/model/RecordingPlayer.js +58 -5
  15. package/dist/esm/model/SubprocessorBridge.js +2 -0
  16. package/dist/esm/model/UiGraphActionProtocol.js +47 -4
  17. package/dist/esm/model/UiGraphBrowserRuntime.js +15 -1
  18. package/dist/esm/model/UiGraphIndexedDbPersistence.js +523 -0
  19. package/dist/esm/model/UiGraphRendererStyles.js +14 -0
  20. package/dist/esm/model/WebAppBrowserStorage.js +653 -0
  21. package/dist/esm/model/WebAppBrowserStorageRpc.js +200 -0
  22. package/dist/esm/model/chat-v2/aiSdkBridge.js +146 -14
  23. package/dist/esm/model/chat-v2/chatV2CallObserver.js +3 -0
  24. package/dist/esm/model/chat-v2/chatV2CredentialNames.js +93 -0
  25. package/dist/esm/model/chat-v2/chatV2EditorCache.js +8 -38
  26. package/dist/esm/model/chat-v2/chatV2Pipeline.js +41 -4
  27. package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +31 -2
  28. package/dist/esm/model/chat-v2/chatV2ResponseBodyCapture.js +10 -2
  29. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +6 -11
  30. package/dist/esm/model/chat-v2/chatV2Shared.js +1 -1
  31. package/dist/esm/model/chat-v2/chatV2Types.js +16 -0
  32. package/dist/esm/model/chat-v2/customProviderApi.js +0 -2
  33. package/dist/esm/model/chat-v2/index.js +3 -0
  34. package/dist/esm/model/chat-v2/llmChatV2Body.js +9 -1
  35. package/dist/esm/model/chat-v2/llmChatV2CachePolicy.js +5 -0
  36. package/dist/esm/model/chat-v2/llmChatV2NodeData.js +7 -0
  37. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +95 -14
  38. package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +33 -9
  39. package/dist/esm/model/chat-v2/llmChatV2OutputClone.js +42 -0
  40. package/dist/esm/model/chat-v2/llmInvocationCoordinator.js +31 -2
  41. package/dist/esm/model/chat-v2/llmModelCandidate.js +5 -1
  42. package/dist/esm/model/chat-v2/llmProfile.js +58 -0
  43. package/dist/esm/model/chat-v2/llmProfileBody.js +10 -0
  44. package/dist/esm/model/chat-v2/llmProfileFallback.js +406 -8
  45. package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +7 -0
  46. package/dist/esm/model/chat-v2/llmProfileHealthStore.js +328 -0
  47. package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +57 -34
  48. package/dist/esm/model/chat-v2/providerOptions.js +33 -7
  49. package/dist/esm/model/chat-v2/toolContinuation.js +27 -1
  50. package/dist/esm/model/nodes/CodeNewNode.js +5 -47
  51. package/dist/esm/model/nodes/CodeNode.js +4 -46
  52. package/dist/esm/model/nodes/ExpressionNode.js +5 -8
  53. package/dist/esm/model/nodes/LLMChatV2Node.js +31 -3
  54. package/dist/esm/model/nodes/MatchNode.js +86 -41
  55. package/dist/esm/plugins/gentrace/gentraceSdk.js +0 -1
  56. package/dist/esm/plugins/gentrace/index.js +0 -1
  57. package/dist/esm/plugins/gentrace/plugin.js +61 -179
  58. package/dist/esm/plugins.js +1 -2
  59. package/dist/esm/recording/ExecutionRecorder.js +50 -8
  60. package/dist/esm/webAppRuntime.js +5 -2
  61. package/dist/types/api/createProcessor.d.ts +5 -0
  62. package/dist/types/exports.d.ts +2 -0
  63. package/dist/types/integrations/CodeRunner.d.ts +10 -7
  64. package/dist/types/integrations/CodeRunnerOptions.d.ts +15 -0
  65. package/dist/types/model/AgentResponseTrace.d.ts +15 -1
  66. package/dist/types/model/EditorDefinition.d.ts +16 -0
  67. package/dist/types/model/ExecutorProtocol.d.ts +17 -6
  68. package/dist/types/model/GraphProcessor.d.ts +17 -5
  69. package/dist/types/model/NodeBase.d.ts +0 -10
  70. package/dist/types/model/NodeExclusionPolicy.d.ts +6 -0
  71. package/dist/types/model/Nodes.d.ts +2 -2
  72. package/dist/types/model/ProcessContext.d.ts +85 -0
  73. package/dist/types/model/ProcessContextBuilder.d.ts +2 -1
  74. package/dist/types/model/UiGraphActionProtocol.d.ts +9 -3
  75. package/dist/types/model/UiGraphBrowserRuntime.d.ts +6 -0
  76. package/dist/types/model/UiGraphIndexedDbPersistence.d.ts +50 -0
  77. package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
  78. package/dist/types/model/WebAppBrowserStorage.d.ts +90 -0
  79. package/dist/types/model/WebAppBrowserStorageRpc.d.ts +85 -0
  80. package/dist/types/model/chat-v2/chatV2CredentialNames.d.ts +30 -0
  81. package/dist/types/model/chat-v2/chatV2EditorCache.d.ts +1 -0
  82. package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +3 -0
  83. package/dist/types/model/chat-v2/chatV2ResponseBodyCapture.d.ts +8 -2
  84. package/dist/types/model/chat-v2/chatV2RuntimeOptions.d.ts +3 -8
  85. package/dist/types/model/chat-v2/chatV2Types.d.ts +27 -1
  86. package/dist/types/model/chat-v2/customProviderApi.d.ts +0 -1
  87. package/dist/types/model/chat-v2/index.d.ts +3 -0
  88. package/dist/types/model/chat-v2/llmChatV2CachePolicy.d.ts +1 -1
  89. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +10 -1
  90. package/dist/types/model/chat-v2/llmChatV2OutputClone.d.ts +3 -0
  91. package/dist/types/model/chat-v2/llmInvocationCoordinator.d.ts +5 -1
  92. package/dist/types/model/chat-v2/llmModelCandidate.d.ts +2 -0
  93. package/dist/types/model/chat-v2/llmProfile.d.ts +14 -0
  94. package/dist/types/model/chat-v2/llmProfileBody.d.ts +1 -1
  95. package/dist/types/model/chat-v2/llmProfileFallback.d.ts +25 -2
  96. package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +26 -6
  97. package/dist/types/model/chat-v2/llmProfileHealthStore.d.ts +121 -0
  98. package/dist/types/model/chat-v2/llmProfileNodeRuntime.d.ts +1 -1
  99. package/dist/types/model/chat-v2/llmProfileTypes.d.ts +9 -0
  100. package/dist/types/model/chat-v2/providerOptions.d.ts +2 -0
  101. package/dist/types/model/chat-v2/toolContinuation.d.ts +14 -0
  102. package/dist/types/model/nodes/CodeNewNode.d.ts +0 -5
  103. package/dist/types/model/nodes/CodeNode.d.ts +0 -5
  104. package/dist/types/model/nodes/MatchNode.d.ts +6 -0
  105. package/dist/types/plugins/gentrace/gentraceSdk.d.ts +0 -1
  106. package/dist/types/plugins/gentrace/plugin.d.ts +55 -9
  107. package/dist/types/plugins.d.ts +1 -1
  108. package/dist/types/recording/ExecutionRecorder.d.ts +7 -1
  109. package/dist/types/recording/RecordedEvents.d.ts +11 -0
  110. package/dist/types/webAppRuntime.d.ts +8 -2
  111. package/package.json +2 -2
@@ -7,6 +7,8 @@ import {} from '../NodeBodySpec.js';
7
7
  import { nodeDefinition } from '../NodeDefinition.js';
8
8
  import { resolveUniqueValueDerivedPortIds } from '../../utils/orderedStringPortIds.js';
9
9
  import { appendCodeNodeSourceUrl, buildCodeNodeSourceUrl, enrichCodeNodeErrorWithLocation, } from './codeNodeErrorDiagnostics.js';
10
+ import { ALL_CODE_RUNNER_OPTIONS } from '../../integrations/CodeRunnerOptions.js';
11
+ const CODE_RUNTIME_HELPER_MESSAGE = 'Node execution also provides "require" and "process". Browser execution provides "fetch", "console", and "Rivet".';
10
12
  export class CodeNodeImpl extends NodeImpl {
11
13
  static create() {
12
14
  const chartNode = {
@@ -32,11 +34,6 @@ export class CodeNodeImpl extends NodeImpl {
32
34
  `,
33
35
  inputNames: 'input1',
34
36
  outputNames: 'output1',
35
- allowFetch: false,
36
- allowRequire: false,
37
- allowRivet: false,
38
- allowProcess: false,
39
- allowConsole: false,
40
37
  },
41
38
  };
42
39
  return chartNode;
@@ -81,6 +78,7 @@ export class CodeNodeImpl extends NodeImpl {
81
78
  {
82
79
  type: 'code',
83
80
  label: '',
81
+ helperMessage: CODE_RUNTIME_HELPER_MESSAGE,
84
82
  dataKey: 'code',
85
83
  language: 'javascript',
86
84
  enableFolding: true,
@@ -107,40 +105,6 @@ export class CodeNodeImpl extends NodeImpl {
107
105
  valueToPortId: 'sanitize-identifier',
108
106
  },
109
107
  },
110
- {
111
- type: 'group',
112
- label: 'Runtime permissions',
113
- defaultOpen: true,
114
- editors: [
115
- {
116
- type: 'toggle',
117
- label: 'Allow "fetch"',
118
- dataKey: 'allowFetch',
119
- },
120
- {
121
- type: 'toggle',
122
- label: 'Allow "Rivet"',
123
- dataKey: 'allowRivet',
124
- },
125
- {
126
- type: 'toggle',
127
- label: 'Allow "console"',
128
- dataKey: 'allowConsole',
129
- },
130
- {
131
- type: 'toggle',
132
- label: 'Allow "require"',
133
- dataKey: 'allowRequire',
134
- helperMessage: 'Only available with the Node executor',
135
- },
136
- {
137
- type: 'toggle',
138
- label: 'Allow "process"',
139
- dataKey: 'allowProcess',
140
- helperMessage: 'Only available with the Node executor',
141
- },
142
- ],
143
- },
144
108
  ];
145
109
  }
146
110
  getBody() {
@@ -167,13 +131,7 @@ export class CodeNodeImpl extends NodeImpl {
167
131
  const sourceUrl = buildCodeNodeSourceUrl(this.chartNode.id);
168
132
  let outputs;
169
133
  try {
170
- outputs = await context.codeRunner.runCode(appendCodeNodeSourceUrl(this.data.code, sourceUrl), inputs, {
171
- includeFetch: this.data.allowFetch ?? false,
172
- includeRequire: this.data.allowRequire ?? false,
173
- includeRivet: this.data.allowRivet ?? false,
174
- includeProcess: this.data.allowProcess ?? false,
175
- includeConsole: this.data.allowConsole ?? false,
176
- }, context.graphInputNodeValues, context.contextValues);
134
+ outputs = await context.codeRunner.runCode(appendCodeNodeSourceUrl(this.data.code, sourceUrl), inputs, ALL_CODE_RUNNER_OPTIONS, context.graphInputNodeValues, context.contextValues);
177
135
  }
178
136
  catch (error) {
179
137
  throw await enrichCodeNodeErrorWithLocation({
@@ -5,6 +5,8 @@ import {} from '../../index.js';
5
5
  import { dedent } from 'ts-dedent';
6
6
  import { nodeDefinition } from '../NodeDefinition.js';
7
7
  import { buildJsValueInterpolatedSource, buildJsValueInputsInitializer, buildJsValuePreview, getJsValueInterpolationInputDefinitions, getJsValueInterpolationRuntimeContext, interpolateJsValuePreviewSource, sanitizeGeneratedJsValueError, } from './jsValueInterpolation.js';
8
+ import { ALL_CODE_RUNNER_OPTIONS } from '../../integrations/CodeRunnerOptions.js';
9
+ const CODE_RUNTIME_HELPER_MESSAGE = 'Node execution also provides "require" and "process". Browser execution provides "fetch", "console", and "Rivet".';
8
10
  const DEFAULT_EXPRESSION = '{{a}} == "123" ? {{b}} : {{c}}';
9
11
  const MAX_BODY_PREVIEW_LINES = 15;
10
12
  const EXPRESSION_INPUTS_IDENTIFIER = '__expressionInputs';
@@ -77,7 +79,8 @@ export class ExpressionNodeImpl extends NodeImpl {
77
79
  {
78
80
  type: 'code',
79
81
  label: 'Expression',
80
- helperMessage: 'Use {{var}} to create input ports. Interpolated variables evaluate as the connected values.',
82
+ helperMessage: 'Use {{var}} to create input ports. Interpolated variables evaluate as the connected values. ' +
83
+ CODE_RUNTIME_HELPER_MESSAGE,
81
84
  dataKey: 'expression',
82
85
  language: 'javascript',
83
86
  interpolationSyntax: 'js-value',
@@ -111,13 +114,7 @@ export class ExpressionNodeImpl extends NodeImpl {
111
114
  const { inputNames, inputsIdentifier } = interpolationContext;
112
115
  const source = buildExpressionWrapper(this.data.expression, interpolationContext);
113
116
  try {
114
- return await context.codeRunner.runCode(source, inputs, {
115
- includeFetch: false,
116
- includeRequire: false,
117
- includeRivet: false,
118
- includeProcess: false,
119
- includeConsole: false,
120
- }, context.graphInputNodeValues, context.contextValues);
117
+ return await context.codeRunner.runCode(source, inputs, ALL_CODE_RUNNER_OPTIONS, context.graphInputNodeValues, context.contextValues);
121
118
  }
122
119
  catch (error) {
123
120
  throw sanitizeExpressionError(error, inputNames, inputsIdentifier);
@@ -14,6 +14,7 @@ import { isChatV2PipelineProviderFailureResult } from '../chat-v2/chatV2Pipeline
14
14
  import { shouldOutputChatV2RequestBody, shouldOutputChatV2ResponseBody } from '../chat-v2/chatV2Types.js';
15
15
  import { buildLLMChatV2EditorCacheKey, resolveLLMChatV2RuntimeConfig, resolveLLMChatV2RuntimeProviderOptions, } from '../chat-v2/llmChatV2NodeRuntime.js';
16
16
  import { projectLLMChatV2EditorCacheHit, writeLLMChatV2EditorCache } from '../chat-v2/llmChatV2CacheBoundary.js';
17
+ import { cloneLLMChatV2Outputs } from '../chat-v2/llmChatV2OutputClone.js';
17
18
  export { buildLLMChatV2EditorCacheKey, resolveLLMChatV2RuntimeProviderOptions };
18
19
  function usesBaseURLInput(data) {
19
20
  return data.provider === 'custom' && data.useCustomProviderBaseURLInput;
@@ -262,6 +263,7 @@ export class LLMChatV2NodeImpl extends NodeImpl {
262
263
  }
263
264
  async process(inputs, context) {
264
265
  const invocationJournal = new LLMInvocationJournal();
266
+ let profileAttemptSequence = 0;
265
267
  // Retries, fallback profiles, and tool continuation produce several
266
268
  // physical provider calls underneath one node invocation. Always observe
267
269
  // them locally so every later output projection shares one truthful
@@ -283,7 +285,15 @@ export class LLMChatV2NodeImpl extends NodeImpl {
283
285
  nodeId: this.chartNode.id,
284
286
  inputs,
285
287
  context: usageTrackingContext,
286
- onLLMAttempt: (attempt) => invocationJournal.recordLLMAttempt(attempt),
288
+ onLLMAttempt: (attempt) => {
289
+ invocationJournal.recordLLMAttempt(attempt);
290
+ context.onLLMProfileAttempt?.({
291
+ ...attempt,
292
+ eventId: `${context.processId}:llm-profile-attempt:${profileAttemptSequence++}`,
293
+ nodeId: context.node.id,
294
+ processId: context.processId,
295
+ });
296
+ },
287
297
  });
288
298
  const toolCallContinuation = context.toolCallContinuation;
289
299
  const cacheHit = projectLLMChatV2EditorCacheHit(runtime);
@@ -291,9 +301,9 @@ export class LLMChatV2NodeImpl extends NodeImpl {
291
301
  context.markResultAsEditorCacheHit?.();
292
302
  return cacheHit;
293
303
  }
294
- let result;
304
+ let invocation;
295
305
  try {
296
- result = await executeLLMInvocation({
306
+ invocation = await executeLLMInvocation({
297
307
  context,
298
308
  journal: invocationJournal,
299
309
  runtime,
@@ -318,6 +328,7 @@ export class LLMChatV2NodeImpl extends NodeImpl {
318
328
  }
319
329
  throw error;
320
330
  }
331
+ const { result, terminalSnapshot } = invocation;
321
332
  projectLLMInvocationResult({
322
333
  result,
323
334
  modelCalls: invocationJournal.modelCalls,
@@ -326,6 +337,23 @@ export class LLMChatV2NodeImpl extends NodeImpl {
326
337
  llmAttempts: invocationJournal.llmAttempts,
327
338
  profileSummary: runtime.getProfileSummary?.(),
328
339
  });
340
+ // The final display page is taken after result projection, so it exactly
341
+ // matches the one graph-semantic output map returned below.
342
+ if (terminalSnapshot != null) {
343
+ try {
344
+ const observerResult = context.onLLMChatOutputSnapshot?.({
345
+ ...terminalSnapshot,
346
+ nodeId: context.node.id,
347
+ processId: context.processId,
348
+ splitIndex: context.splitIndex ?? 0,
349
+ outputs: cloneLLMChatV2Outputs(result.commonOutputs),
350
+ });
351
+ void Promise.resolve(observerResult).catch(() => undefined);
352
+ }
353
+ catch {
354
+ // Display history is never allowed to affect graph execution.
355
+ }
356
+ }
329
357
  if (toolCallContinuation && !isChatV2PipelineProviderFailureResult(result) && result.functionCalls.length > 0) {
330
358
  toolCallContinuation.release();
331
359
  }
@@ -21,6 +21,7 @@ export class MatchNodeImpl extends NodeImpl {
21
21
  data: {
22
22
  cases: ['YES', 'NO'],
23
23
  casePortIds: [nanoid(), nanoid()],
24
+ valueInputMode: 'shared',
24
25
  },
25
26
  };
26
27
  return chartNode;
@@ -34,57 +35,86 @@ export class MatchNodeImpl extends NodeImpl {
34
35
  required: true,
35
36
  description: 'The value that will be tested against each of the cases.',
36
37
  },
37
- {
38
+ ];
39
+ if (this.getValueInputMode() === 'shared') {
40
+ inputs.push({
38
41
  id: 'value',
39
- title: 'Value',
42
+ title: 'Custom value',
40
43
  dataType: 'any',
41
- description: 'The value passed through to the output port that matches. If unconnected, the test value will be passed through.',
42
- },
43
- ];
44
+ description: 'The optional value passed through to every matching output. If unconnected, the Test value is passed through.',
45
+ });
46
+ }
47
+ else {
48
+ const portIds = this.getCasePortIds();
49
+ this.data.cases.forEach((caseValue, index) => {
50
+ inputs.push({
51
+ id: this.getCaseValueInputId(portIds[index]),
52
+ title: this.getCaseTitle(caseValue, index),
53
+ dataType: 'any',
54
+ description: `The optional custom value emitted when /${caseValue}/ matches the Test value. If unconnected, Test is passed through.`,
55
+ });
56
+ });
57
+ inputs.push({
58
+ id: 'value-unmatched',
59
+ title: 'Unmatched',
60
+ dataType: 'any',
61
+ description: 'The optional custom value emitted when no regular expression matches the Test value. If unconnected, Test is passed through.',
62
+ });
63
+ }
44
64
  return inputs;
45
65
  }
46
66
  getOutputDefinitions() {
47
67
  const outputs = [];
48
- const portIds = resolveStoredOrderedPortIds(this.data.cases.length, this.data.casePortIds, {
49
- kind: 'prefix',
50
- prefix: 'case',
51
- startIndex: 1,
52
- });
68
+ const portIds = this.getCasePortIds();
53
69
  for (let i = 0; i < this.data.cases.length; i++) {
54
70
  outputs.push({
55
71
  id: portIds[i],
56
- title: this.data.cases[i]?.trim() ? this.data.cases[i] : `Case ${i + 1}`,
57
- dataType: 'string',
58
- description: `The 'value' (or 'test' if value is unconnected) passed through if the test value matches this regex: /${this
59
- .data.cases[i]}/`,
72
+ title: this.getCaseTitle(this.data.cases[i], i),
73
+ dataType: 'any',
74
+ description: this.getValueInputMode() === 'shared'
75
+ ? `The shared Custom value (or Test if Custom value is unconnected) passed through if the test value matches /${this.data.cases[i]}/.`
76
+ : `The corresponding ${this.getCaseTitle(this.data.cases[i], i)} custom value (or Test if it is unconnected) passed through if the test value matches /${this.data.cases[i]}/.`,
60
77
  });
61
78
  }
62
79
  outputs.push({
63
80
  id: 'unmatched',
64
81
  title: 'Unmatched',
65
- dataType: 'string',
66
- description: 'The value (or test if value is unconnected) passed through if no regexes match.',
82
+ dataType: 'any',
83
+ description: this.getValueInputMode() === 'shared'
84
+ ? 'The shared Custom value (or Test if Custom value is unconnected) passed through if no regexes match.'
85
+ : 'The Unmatched custom value (or Test if it is unconnected) passed through if no regexes match.',
67
86
  });
68
87
  return outputs;
69
88
  }
70
89
  getBody() {
71
- return dedent `
72
- ${this.data.exclusive ? 'First Matching Case' : 'All Matching Cases'}
73
- ${this.data.cases.length} Cases
74
- `;
90
+ return this.data.exclusive ? 'Trigger the first matching case only' : 'Trigger all matching cases';
75
91
  }
76
92
  getEditors() {
77
93
  return [
78
94
  {
79
- type: 'toggle',
95
+ type: 'segmented',
96
+ label: 'Matching cases to trigger',
80
97
  dataKey: 'exclusive',
81
- label: 'Exclusive',
82
- helperMessage: 'If enabled, only the first matching branch will be ran.',
98
+ defaultValue: false,
99
+ options: [
100
+ { value: false, label: 'Trigger all matching cases' },
101
+ { value: true, label: 'Trigger first only' },
102
+ ],
103
+ },
104
+ {
105
+ type: 'segmented',
106
+ label: 'Custom case values',
107
+ dataKey: 'valueInputMode',
108
+ defaultValue: 'shared',
109
+ options: [
110
+ { value: 'shared', label: 'One shared custom value' },
111
+ { value: 'per-output', label: 'Custom values per case' },
112
+ ],
83
113
  },
84
114
  {
85
115
  type: 'stringList',
86
116
  dataKey: 'cases',
87
- label: 'Cases',
117
+ label: 'Cases (regular expressions)',
88
118
  placeholder: 'Case (regular expression)',
89
119
  reorderable: true,
90
120
  portBinding: {
@@ -96,15 +126,15 @@ export class MatchNodeImpl extends NodeImpl {
96
126
  prefix: 'case',
97
127
  startIndex: 1,
98
128
  },
129
+ companionBindings: [{ side: 'input', prefix: 'value-' }],
99
130
  },
100
- helperMessage: '(Regular expressions)',
101
131
  },
102
132
  ];
103
133
  }
104
134
  static getUIData() {
105
135
  return {
106
136
  infoBoxBody: dedent `
107
- Any number of regular expressions can be configured, each corresponding to an output of the node. The output port of the first matching regex will be ran, and all other output ports will not be ran.
137
+ Configure any number of regular expressions, each corresponding to an output. Trigger all matched outputs by default, or choose Trigger first matching case. One shared custom value passes one optional value to every active output, while Custom values per case gives each case and Unmatched output its own optional custom value input.
108
138
  `,
109
139
  infoBoxTitle: 'Regex Match Node',
110
140
  contextMenuTitle: 'Regex Match',
@@ -114,14 +144,19 @@ export class MatchNodeImpl extends NodeImpl {
114
144
  async process(inputs) {
115
145
  const inputValue = inputs['input'];
116
146
  const inputString = inputValue?.value == null ? undefined : coerceType(inputValue, 'string');
117
- const value = inputs['value'];
118
- const portIds = resolveStoredOrderedPortIds(this.data.cases.length, this.data.casePortIds, {
119
- kind: 'prefix',
120
- prefix: 'case',
121
- startIndex: 1,
147
+ const portIds = this.getCasePortIds();
148
+ const sharedValue = inputs['value'];
149
+ const getTestOutputValue = () => ({
150
+ type: 'string',
151
+ value: inputString,
122
152
  });
123
- const outputType = value === undefined ? 'string' : value.type;
124
- const outputValue = value === undefined ? inputString : value.value;
153
+ const getSharedOutputValue = () => sharedValue ?? getTestOutputValue();
154
+ const getOutputValue = (portId) => this.getValueInputMode() === 'shared'
155
+ ? getSharedOutputValue()
156
+ : inputs[this.getCaseValueInputId(portId)] ?? getTestOutputValue();
157
+ const getUnmatchedOutputValue = () => this.getValueInputMode() === 'shared'
158
+ ? getSharedOutputValue()
159
+ : inputs['value-unmatched'] ?? getTestOutputValue();
125
160
  const cases = this.data.cases;
126
161
  let matched = false;
127
162
  const output = {};
@@ -130,10 +165,7 @@ export class MatchNodeImpl extends NodeImpl {
130
165
  const canMatch = !this.data.exclusive || !matched;
131
166
  if (match && canMatch) {
132
167
  matched = true;
133
- output[portIds[i]] = {
134
- type: outputType,
135
- value: outputValue,
136
- };
168
+ output[portIds[i]] = getOutputValue(portIds[i]);
137
169
  }
138
170
  else {
139
171
  output[portIds[i]] = {
@@ -143,10 +175,7 @@ export class MatchNodeImpl extends NodeImpl {
143
175
  }
144
176
  }
145
177
  if (!matched) {
146
- output['unmatched'] = {
147
- type: outputType,
148
- value: outputValue,
149
- };
178
+ output['unmatched'] = getUnmatchedOutputValue();
150
179
  }
151
180
  else {
152
181
  output['unmatched'] = {
@@ -156,5 +185,21 @@ export class MatchNodeImpl extends NodeImpl {
156
185
  }
157
186
  return output;
158
187
  }
188
+ getValueInputMode() {
189
+ return this.data.valueInputMode === 'per-output' ? 'per-output' : 'shared';
190
+ }
191
+ getCasePortIds() {
192
+ return resolveStoredOrderedPortIds(this.data.cases.length, this.data.casePortIds, {
193
+ kind: 'prefix',
194
+ prefix: 'case',
195
+ startIndex: 1,
196
+ });
197
+ }
198
+ getCaseTitle(caseValue, index) {
199
+ return caseValue?.trim() ? caseValue : `Case ${index + 1}`;
200
+ }
201
+ getCaseValueInputId(portId) {
202
+ return `value-${portId}`;
203
+ }
159
204
  }
160
205
  export const matchNode = nodeDefinition(MatchNodeImpl, 'Regex Match');
@@ -4,5 +4,4 @@
4
4
  export { init } from '@gentrace/core/dist/providers/init.mjs';
5
5
  export { getPipelines } from '@gentrace/core/dist/providers/pipeline-methods.mjs';
6
6
  export { Pipeline } from '@gentrace/core/dist/providers/pipeline.mjs';
7
- export { runTest } from '@gentrace/core/dist/providers/run-test.mjs';
8
7
  export { StepRun } from '@gentrace/core/dist/providers/step-run.mjs';
@@ -1,3 +1,2 @@
1
- // eslint-disable-next-line import/no-cycle -- The plugin implementation uses GraphProcessor to execute local Gentrace tests.
2
1
  import { gentracePlugin } from './plugin.js';
3
2
  export default gentracePlugin;