@valerypopoff/rivet2-core 2.11.0 → 2.13.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.
- package/dist/cjs/bundle.cjs +1419 -676
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/esm/exports.js +1 -0
- package/dist/esm/model/GraphInputStream.js +70 -0
- package/dist/esm/model/GraphProcessor.js +257 -16
- package/dist/esm/model/NodeExecutionPlanner.js +4 -4
- package/dist/esm/model/Nodes.js +6 -0
- package/dist/esm/model/ProcessContextBuilder.js +2 -1
- package/dist/esm/model/StreamingOutputWatch.js +5 -0
- package/dist/esm/model/StreamingWatchTopology.js +191 -0
- package/dist/esm/model/nodes/AssembleMessageNode.js +2 -2
- package/dist/esm/model/nodes/AssemblePromptNode.js +46 -17
- package/dist/esm/model/nodes/CoalesceNewNode.js +1 -1
- package/dist/esm/model/nodes/CoalesceNode.js +1 -1
- package/dist/esm/model/nodes/GraphInputNode.js +15 -19
- package/dist/esm/model/nodes/MatchCaseNode.js +132 -0
- package/dist/esm/model/nodes/MatchCaseNodeBase.js +237 -0
- package/dist/esm/model/nodes/MatchNode.js +24 -177
- package/dist/esm/model/nodes/ProjectNameNode.js +37 -0
- package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +1 -0
- package/dist/esm/model/nodes/SubGraphNode.js +1 -0
- package/dist/esm/model/nodes/variadicPortIndex.js +1 -1
- package/dist/types/exports.d.ts +2 -0
- package/dist/types/model/EditorDefinition.d.ts +2 -0
- package/dist/types/model/GraphInputStream.d.ts +23 -0
- package/dist/types/model/GraphProcessor.d.ts +3 -0
- package/dist/types/model/NodeExecutionPlanner.d.ts +1 -1
- package/dist/types/model/Nodes.d.ts +4 -2
- package/dist/types/model/ProcessContext.d.ts +3 -0
- package/dist/types/model/ProcessContextBuilder.d.ts +2 -1
- package/dist/types/model/StreamingOutputWatch.d.ts +2 -0
- package/dist/types/model/StreamingWatchTopology.d.ts +20 -0
- package/dist/types/model/nodes/AssemblePromptNode.d.ts +4 -3
- package/dist/types/model/nodes/GraphInputNode.d.ts +2 -0
- package/dist/types/model/nodes/MatchCaseNode.d.ts +43 -0
- package/dist/types/model/nodes/MatchCaseNodeBase.d.ts +52 -0
- package/dist/types/model/nodes/MatchNode.d.ts +13 -21
- package/dist/types/model/nodes/ProjectNameNode.d.ts +12 -0
- package/dist/types/model/nodes/variadicPortIndex.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import {} from '../DataValue.js';
|
|
2
|
+
import {} from '../EditorDefinition.js';
|
|
3
|
+
import {} from '../GraphProcessor.js';
|
|
4
|
+
import { NodeImpl } from '../NodeImpl.js';
|
|
5
|
+
import {} from '../NodeBase.js';
|
|
6
|
+
import { coerceType } from '../../utils/coerceType.js';
|
|
7
|
+
import { resolveStoredOrderedPortIds } from '../../utils/orderedStringPortIds.js';
|
|
8
|
+
/**
|
|
9
|
+
* Shared ports, custom-value routing, and case-output handling for the current
|
|
10
|
+
* Match case node and the regex-only compatibility node. Each subclass owns
|
|
11
|
+
* only its matching semantics and editor wording.
|
|
12
|
+
*/
|
|
13
|
+
export class MatchCaseNodeBase extends NodeImpl {
|
|
14
|
+
casesEditorPlacement = 'after-custom-values';
|
|
15
|
+
customCaseValuesEditorLabel = 'Custom case values';
|
|
16
|
+
defaultExclusive = false;
|
|
17
|
+
firstMatchingBodyValue = 'First matching case only';
|
|
18
|
+
inputTitle = 'Test';
|
|
19
|
+
matchingCasesToTriggerOptions = [
|
|
20
|
+
{ value: false, label: 'Trigger all matching cases' },
|
|
21
|
+
{ value: true, label: 'Trigger first only' },
|
|
22
|
+
];
|
|
23
|
+
sharedCustomValueInputTitle = 'Custom value';
|
|
24
|
+
triggerEditorLabel = 'Matching cases to trigger';
|
|
25
|
+
getReturnValueMode() {
|
|
26
|
+
return 'custom';
|
|
27
|
+
}
|
|
28
|
+
getEditorsAfterTrigger() {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
shouldHideCustomCaseValues(_data) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
getInputDefinitions() {
|
|
35
|
+
const inputs = [
|
|
36
|
+
{
|
|
37
|
+
id: 'input',
|
|
38
|
+
title: this.inputTitle,
|
|
39
|
+
dataType: 'string',
|
|
40
|
+
required: true,
|
|
41
|
+
description: `The ${this.inputTitle} value tested against each case.`,
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
if (this.getReturnValueMode() !== 'custom') {
|
|
45
|
+
return inputs;
|
|
46
|
+
}
|
|
47
|
+
if (this.getValueInputMode() === 'shared') {
|
|
48
|
+
inputs.push({
|
|
49
|
+
id: 'value',
|
|
50
|
+
title: this.sharedCustomValueInputTitle,
|
|
51
|
+
dataType: 'any',
|
|
52
|
+
description: `The optional value passed through to every matching output. If unconnected, the ${this.inputTitle} value is passed through.`,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const portIds = this.getCasePortIds();
|
|
57
|
+
this.data.cases.forEach((caseValue, index) => {
|
|
58
|
+
inputs.push({
|
|
59
|
+
id: this.getCaseValueInputId(portIds[index]),
|
|
60
|
+
title: this.getCaseTitle(caseValue, index),
|
|
61
|
+
dataType: 'any',
|
|
62
|
+
description: `The optional custom value emitted when ${this.describeCaseMatch(caseValue)}. If unconnected, ${this.inputTitle} is passed through.`,
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
inputs.push({
|
|
66
|
+
id: 'value-unmatched',
|
|
67
|
+
title: 'Unmatched',
|
|
68
|
+
dataType: 'any',
|
|
69
|
+
description: `The optional custom value emitted when ${this.describeNoCaseMatches()}. If unconnected, ${this.inputTitle} is passed through.`,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return inputs;
|
|
73
|
+
}
|
|
74
|
+
getOutputDefinitions() {
|
|
75
|
+
const outputs = [];
|
|
76
|
+
const portIds = this.getCasePortIds();
|
|
77
|
+
const returnValueMode = this.getReturnValueMode();
|
|
78
|
+
const dataType = returnValueMode === 'true' ? 'boolean' : returnValueMode === 'testValue' ? 'string' : 'any';
|
|
79
|
+
for (let index = 0; index < this.data.cases.length; index++) {
|
|
80
|
+
const caseValue = this.data.cases[index];
|
|
81
|
+
const title = this.getCaseTitle(caseValue, index);
|
|
82
|
+
outputs.push({
|
|
83
|
+
id: portIds[index],
|
|
84
|
+
title,
|
|
85
|
+
dataType,
|
|
86
|
+
description: this.getMatchingOutputDescription(caseValue, title),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
outputs.push({
|
|
90
|
+
id: 'unmatched',
|
|
91
|
+
title: 'Unmatched',
|
|
92
|
+
dataType,
|
|
93
|
+
description: this.getUnmatchedOutputDescription(),
|
|
94
|
+
});
|
|
95
|
+
return outputs;
|
|
96
|
+
}
|
|
97
|
+
getBody() {
|
|
98
|
+
return this.getExclusive() ? `Trigger: ${this.firstMatchingBodyValue}` : 'Trigger: All matching cases';
|
|
99
|
+
}
|
|
100
|
+
getEditors() {
|
|
101
|
+
const casesEditor = {
|
|
102
|
+
type: 'stringList',
|
|
103
|
+
dataKey: 'cases',
|
|
104
|
+
label: this.caseEditorLabel,
|
|
105
|
+
placeholder: this.caseEditorPlaceholder,
|
|
106
|
+
reorderable: true,
|
|
107
|
+
portBinding: {
|
|
108
|
+
side: 'output',
|
|
109
|
+
identity: 'stored-stable-id',
|
|
110
|
+
idDataKey: 'casePortIds',
|
|
111
|
+
legacyPortIdPattern: {
|
|
112
|
+
kind: 'prefix',
|
|
113
|
+
prefix: 'case',
|
|
114
|
+
startIndex: 1,
|
|
115
|
+
},
|
|
116
|
+
companionBindings: [{ side: 'input', prefix: 'value-' }],
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
return [
|
|
120
|
+
...(this.casesEditorPlacement === 'before-trigger' ? [casesEditor] : []),
|
|
121
|
+
{
|
|
122
|
+
type: 'segmented',
|
|
123
|
+
label: this.triggerEditorLabel,
|
|
124
|
+
dataKey: 'exclusive',
|
|
125
|
+
defaultValue: this.defaultExclusive,
|
|
126
|
+
options: this.matchingCasesToTriggerOptions,
|
|
127
|
+
},
|
|
128
|
+
...this.getEditorsAfterTrigger(),
|
|
129
|
+
{
|
|
130
|
+
type: 'segmented',
|
|
131
|
+
label: this.customCaseValuesEditorLabel,
|
|
132
|
+
ariaLabel: 'Custom case values',
|
|
133
|
+
dataKey: 'valueInputMode',
|
|
134
|
+
defaultValue: 'shared',
|
|
135
|
+
hideIf: (data) => this.shouldHideCustomCaseValues(data),
|
|
136
|
+
options: [
|
|
137
|
+
{ value: 'shared', label: 'One shared custom value' },
|
|
138
|
+
{ value: 'per-output', label: 'Custom values per case' },
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
...(this.casesEditorPlacement === 'after-custom-values' ? [casesEditor] : []),
|
|
142
|
+
];
|
|
143
|
+
}
|
|
144
|
+
async process(inputs) {
|
|
145
|
+
const inputValue = inputs['input'];
|
|
146
|
+
const inputString = inputValue?.value == null ? undefined : coerceType(inputValue, 'string');
|
|
147
|
+
const portIds = this.getCasePortIds();
|
|
148
|
+
const sharedValue = inputs['value'];
|
|
149
|
+
const returnValueMode = this.getReturnValueMode();
|
|
150
|
+
const getInputOutputValue = () => ({
|
|
151
|
+
type: 'string',
|
|
152
|
+
value: inputString,
|
|
153
|
+
});
|
|
154
|
+
const getSharedOutputValue = () => sharedValue ?? getInputOutputValue();
|
|
155
|
+
const getConfiguredOutputValue = (customValueInputId) => {
|
|
156
|
+
if (returnValueMode === 'true') {
|
|
157
|
+
return { type: 'boolean', value: true };
|
|
158
|
+
}
|
|
159
|
+
if (returnValueMode === 'testValue') {
|
|
160
|
+
return getInputOutputValue();
|
|
161
|
+
}
|
|
162
|
+
return this.getValueInputMode() === 'shared'
|
|
163
|
+
? getSharedOutputValue()
|
|
164
|
+
: inputs[customValueInputId] ?? getInputOutputValue();
|
|
165
|
+
};
|
|
166
|
+
const getOutputValue = (portId) => getConfiguredOutputValue(this.getCaseValueInputId(portId));
|
|
167
|
+
const getUnmatchedOutputValue = () => getConfiguredOutputValue('value-unmatched');
|
|
168
|
+
let matched = false;
|
|
169
|
+
const output = {};
|
|
170
|
+
for (let index = 0; index < this.data.cases.length; index++) {
|
|
171
|
+
const caseValue = this.data.cases[index];
|
|
172
|
+
const matches = inputString !== undefined && this.matchesCase(inputString, caseValue);
|
|
173
|
+
const canMatch = !this.getExclusive() || !matched;
|
|
174
|
+
const portId = portIds[index];
|
|
175
|
+
if (matches && canMatch) {
|
|
176
|
+
matched = true;
|
|
177
|
+
output[portId] = getOutputValue(portId);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
output[portId] = {
|
|
181
|
+
type: 'control-flow-excluded',
|
|
182
|
+
value: undefined,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
output['unmatched'] = matched
|
|
187
|
+
? {
|
|
188
|
+
type: 'control-flow-excluded',
|
|
189
|
+
value: undefined,
|
|
190
|
+
}
|
|
191
|
+
: getUnmatchedOutputValue();
|
|
192
|
+
return output;
|
|
193
|
+
}
|
|
194
|
+
getValueInputMode() {
|
|
195
|
+
return this.data.valueInputMode === 'per-output' ? 'per-output' : 'shared';
|
|
196
|
+
}
|
|
197
|
+
getExclusive() {
|
|
198
|
+
return this.data.exclusive ?? this.defaultExclusive;
|
|
199
|
+
}
|
|
200
|
+
getMatchingOutputDescription(caseValue, title) {
|
|
201
|
+
const condition = this.describeCaseMatch(caseValue);
|
|
202
|
+
if (this.getReturnValueMode() === 'true') {
|
|
203
|
+
return `True if ${condition}.`;
|
|
204
|
+
}
|
|
205
|
+
if (this.getReturnValueMode() === 'testValue') {
|
|
206
|
+
return `The ${this.inputTitle} value passed through if ${condition}.`;
|
|
207
|
+
}
|
|
208
|
+
return this.getValueInputMode() === 'shared'
|
|
209
|
+
? `The shared ${this.sharedCustomValueInputTitle} (or ${this.inputTitle} if it is unconnected) passed through if ${condition}.`
|
|
210
|
+
: `The corresponding ${title} custom value (or ${this.inputTitle} if it is unconnected) passed through if ${condition}.`;
|
|
211
|
+
}
|
|
212
|
+
getUnmatchedOutputDescription() {
|
|
213
|
+
const condition = this.describeNoCaseMatches();
|
|
214
|
+
if (this.getReturnValueMode() === 'true') {
|
|
215
|
+
return `True if ${condition}.`;
|
|
216
|
+
}
|
|
217
|
+
if (this.getReturnValueMode() === 'testValue') {
|
|
218
|
+
return `The ${this.inputTitle} value passed through if ${condition}.`;
|
|
219
|
+
}
|
|
220
|
+
return this.getValueInputMode() === 'shared'
|
|
221
|
+
? `The shared ${this.sharedCustomValueInputTitle} (or ${this.inputTitle} if it is unconnected) passed through if ${condition}.`
|
|
222
|
+
: `The Unmatched custom value (or ${this.inputTitle} if it is unconnected) passed through if ${condition}.`;
|
|
223
|
+
}
|
|
224
|
+
getCasePortIds() {
|
|
225
|
+
return resolveStoredOrderedPortIds(this.data.cases.length, this.data.casePortIds, {
|
|
226
|
+
kind: 'prefix',
|
|
227
|
+
prefix: 'case',
|
|
228
|
+
startIndex: 1,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
getCaseTitle(caseValue, index) {
|
|
232
|
+
return caseValue?.trim() ? caseValue : `Case ${index + 1}`;
|
|
233
|
+
}
|
|
234
|
+
getCaseValueInputId(portId) {
|
|
235
|
+
return `value-${portId}`;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import {} from '../NodeBase.js';
|
|
2
1
|
import { nanoid } from 'nanoid/non-secure';
|
|
3
|
-
import { NodeImpl } from '../NodeImpl.js';
|
|
4
|
-
import { nodeDefinition } from '../NodeDefinition.js';
|
|
5
|
-
import {} from '../DataValue.js';
|
|
6
|
-
import {} from '../../index.js';
|
|
7
2
|
import { dedent } from 'ts-dedent';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
3
|
+
import { nodeDefinition } from '../NodeDefinition.js';
|
|
4
|
+
import {} from '../NodeImpl.js';
|
|
5
|
+
import {} from '../NodeBase.js';
|
|
6
|
+
import { MatchCaseNodeBase } from './MatchCaseNodeBase.js';
|
|
7
|
+
/** Display-only label; the persisted `match` type remains available for existing graphs. */
|
|
8
|
+
export const regexMatchLegacyDisplayName = 'Regex Match (legacy)';
|
|
9
|
+
/** The persisted `match` type stays regex-only for backwards compatibility. */
|
|
10
|
+
export class MatchNodeImpl extends MatchCaseNodeBase {
|
|
11
|
+
caseEditorLabel = 'Cases (regular expressions)';
|
|
12
|
+
caseEditorPlaceholder = 'Case (regular expression)';
|
|
11
13
|
static create() {
|
|
12
|
-
|
|
14
|
+
return {
|
|
13
15
|
type: 'match',
|
|
14
|
-
title:
|
|
16
|
+
title: regexMatchLegacyDisplayName,
|
|
15
17
|
id: nanoid(),
|
|
16
18
|
visualData: {
|
|
17
19
|
x: 0,
|
|
@@ -24,182 +26,27 @@ export class MatchNodeImpl extends NodeImpl {
|
|
|
24
26
|
valueInputMode: 'shared',
|
|
25
27
|
},
|
|
26
28
|
};
|
|
27
|
-
return chartNode;
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
{
|
|
32
|
-
id: 'input',
|
|
33
|
-
title: 'Test',
|
|
34
|
-
dataType: 'string',
|
|
35
|
-
required: true,
|
|
36
|
-
description: 'The value that will be tested against each of the cases.',
|
|
37
|
-
},
|
|
38
|
-
];
|
|
39
|
-
if (this.getValueInputMode() === 'shared') {
|
|
40
|
-
inputs.push({
|
|
41
|
-
id: 'value',
|
|
42
|
-
title: 'Custom value',
|
|
43
|
-
dataType: 'any',
|
|
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
|
-
}
|
|
64
|
-
return inputs;
|
|
30
|
+
matchesCase(input, caseValue) {
|
|
31
|
+
return new RegExp(caseValue).test(input);
|
|
65
32
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const portIds = this.getCasePortIds();
|
|
69
|
-
for (let i = 0; i < this.data.cases.length; i++) {
|
|
70
|
-
outputs.push({
|
|
71
|
-
id: portIds[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]}/.`,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
outputs.push({
|
|
80
|
-
id: 'unmatched',
|
|
81
|
-
title: 'Unmatched',
|
|
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.',
|
|
86
|
-
});
|
|
87
|
-
return outputs;
|
|
33
|
+
describeCaseMatch(caseValue) {
|
|
34
|
+
return `/${caseValue}/ matches the Test value`;
|
|
88
35
|
}
|
|
89
|
-
|
|
90
|
-
return
|
|
91
|
-
}
|
|
92
|
-
getEditors() {
|
|
93
|
-
return [
|
|
94
|
-
{
|
|
95
|
-
type: 'segmented',
|
|
96
|
-
label: 'Matching cases to trigger',
|
|
97
|
-
dataKey: 'exclusive',
|
|
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
|
-
],
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
type: 'stringList',
|
|
116
|
-
dataKey: 'cases',
|
|
117
|
-
label: 'Cases (regular expressions)',
|
|
118
|
-
placeholder: 'Case (regular expression)',
|
|
119
|
-
reorderable: true,
|
|
120
|
-
portBinding: {
|
|
121
|
-
side: 'output',
|
|
122
|
-
identity: 'stored-stable-id',
|
|
123
|
-
idDataKey: 'casePortIds',
|
|
124
|
-
legacyPortIdPattern: {
|
|
125
|
-
kind: 'prefix',
|
|
126
|
-
prefix: 'case',
|
|
127
|
-
startIndex: 1,
|
|
128
|
-
},
|
|
129
|
-
companionBindings: [{ side: 'input', prefix: 'value-' }],
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
];
|
|
36
|
+
describeNoCaseMatches() {
|
|
37
|
+
return 'no regular expression matches the Test value';
|
|
133
38
|
}
|
|
134
39
|
static getUIData() {
|
|
135
40
|
return {
|
|
136
41
|
infoBoxBody: dedent `
|
|
137
|
-
|
|
42
|
+
Legacy regex-only routing node. Existing graphs keep their current behavior.
|
|
43
|
+
|
|
44
|
+
For new graphs, use Match case. It supports exact plain-text cases by default and optional regular-expression matching.
|
|
138
45
|
`,
|
|
139
|
-
infoBoxTitle:
|
|
140
|
-
contextMenuTitle:
|
|
46
|
+
infoBoxTitle: `${regexMatchLegacyDisplayName} Node`,
|
|
47
|
+
contextMenuTitle: regexMatchLegacyDisplayName,
|
|
141
48
|
group: ['Logic'],
|
|
142
49
|
};
|
|
143
50
|
}
|
|
144
|
-
async process(inputs) {
|
|
145
|
-
const inputValue = inputs['input'];
|
|
146
|
-
const inputString = inputValue?.value == null ? undefined : coerceType(inputValue, 'string');
|
|
147
|
-
const portIds = this.getCasePortIds();
|
|
148
|
-
const sharedValue = inputs['value'];
|
|
149
|
-
const getTestOutputValue = () => ({
|
|
150
|
-
type: 'string',
|
|
151
|
-
value: inputString,
|
|
152
|
-
});
|
|
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();
|
|
160
|
-
const cases = this.data.cases;
|
|
161
|
-
let matched = false;
|
|
162
|
-
const output = {};
|
|
163
|
-
for (let i = 0; i < cases.length; i++) {
|
|
164
|
-
const match = inputString !== undefined && new RegExp(cases[i]).test(inputString);
|
|
165
|
-
const canMatch = !this.data.exclusive || !matched;
|
|
166
|
-
if (match && canMatch) {
|
|
167
|
-
matched = true;
|
|
168
|
-
output[portIds[i]] = getOutputValue(portIds[i]);
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
output[portIds[i]] = {
|
|
172
|
-
type: 'control-flow-excluded',
|
|
173
|
-
value: undefined,
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (!matched) {
|
|
178
|
-
output['unmatched'] = getUnmatchedOutputValue();
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
output['unmatched'] = {
|
|
182
|
-
type: 'control-flow-excluded',
|
|
183
|
-
value: undefined,
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
return output;
|
|
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
|
-
}
|
|
204
51
|
}
|
|
205
|
-
export const matchNode = nodeDefinition(MatchNodeImpl,
|
|
52
|
+
export const matchNode = nodeDefinition(MatchNodeImpl, regexMatchLegacyDisplayName);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { newId } from '../../utils/index.js';
|
|
2
|
+
import { nodeDefinition } from '../NodeDefinition.js';
|
|
3
|
+
import { NodeImpl } from '../NodeImpl.js';
|
|
4
|
+
export class ProjectNameNodeImpl extends NodeImpl {
|
|
5
|
+
static create() {
|
|
6
|
+
return {
|
|
7
|
+
id: newId(),
|
|
8
|
+
type: 'projectName',
|
|
9
|
+
title: 'Project Name',
|
|
10
|
+
visualData: { x: 0, y: 0, width: 250 },
|
|
11
|
+
data: {},
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
getInputDefinitions() {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
getOutputDefinitions() {
|
|
18
|
+
return [{ id: 'projectName', title: 'Project Name', dataType: 'string' }];
|
|
19
|
+
}
|
|
20
|
+
getEditors() {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
static getUIData() {
|
|
24
|
+
return {
|
|
25
|
+
contextMenuTitle: 'Project Name',
|
|
26
|
+
infoBoxTitle: 'Project Name',
|
|
27
|
+
infoBoxBody: "Returns the name of the project that owns the graph currently being executed. A graph called from a referenced project returns that referenced project's name.",
|
|
28
|
+
group: ['Debug'],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async process(_inputs, context) {
|
|
32
|
+
return {
|
|
33
|
+
['projectName']: { type: 'string', value: context.project.metadata.title },
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export const projectNameNode = nodeDefinition(ProjectNameNodeImpl, 'Project Name');
|
|
@@ -125,6 +125,7 @@ export class ReferencedGraphAliasNodeImpl extends NodeImpl {
|
|
|
125
125
|
try {
|
|
126
126
|
const startTime = Date.now();
|
|
127
127
|
const outputs = await subGraphProcessor.processGraph(context, inputData, context.contextValues, {
|
|
128
|
+
graphInputStreams: context.graphInputStreams,
|
|
128
129
|
// This node preserves the referenced graph's named boundary ports,
|
|
129
130
|
// so it may relay their direct producer partials to a parent Watch.
|
|
130
131
|
// An Error-output alias can replace normal ports with exclusions,
|
|
@@ -127,6 +127,7 @@ export class SubGraphNodeImpl extends NodeImpl {
|
|
|
127
127
|
const startTime = Date.now();
|
|
128
128
|
const graphOutputs = await subGraphProcessor.processGraph(context, inputData, context.contextValues, {
|
|
129
129
|
...(requestedGraphOutputIds ? { requestedGraphOutputIds } : {}),
|
|
130
|
+
graphInputStreams: context.graphInputStreams,
|
|
130
131
|
// A child Graph Output can relay a direct producer's partial value
|
|
131
132
|
// under the public boundary port ID. An Error-output Subgraph may
|
|
132
133
|
// later replace that same normal output with an exclusion, so it is
|
|
@@ -14,7 +14,7 @@ export function getHighestVariadicPortIndex(connections, inputNodeId, prefix, po
|
|
|
14
14
|
export function getNextVariadicPortIndex(connections, inputNodeId, prefix, policy) {
|
|
15
15
|
return getHighestVariadicPortIndex(connections, inputNodeId, prefix, policy) + 1;
|
|
16
16
|
}
|
|
17
|
-
function parseVariadicPortIndex(portId, prefix, policy) {
|
|
17
|
+
export function parseVariadicPortIndex(portId, prefix, policy) {
|
|
18
18
|
if (policy === 'legacy') {
|
|
19
19
|
const index = parseInt(portId.replace(prefix, ''));
|
|
20
20
|
return Number.isNaN(index) ? undefined : index;
|
package/dist/types/exports.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export * from './model/DataValue.js';
|
|
|
5
5
|
export * from './model/NodeBase.js';
|
|
6
6
|
export * from './model/NodeGraph.js';
|
|
7
7
|
export * from './model/NodePrefabResolver.js';
|
|
8
|
+
export * from './model/StreamingWatchTopology.js';
|
|
9
|
+
export type { GraphInputStream } from './model/GraphInputStream.js';
|
|
8
10
|
export { getGraphBoundary } from './model/GraphBoundaryCache.js';
|
|
9
11
|
export type { GraphBoundary } from './model/GraphBoundaryCache.js';
|
|
10
12
|
export * from './model/UiGraph.js';
|
|
@@ -30,6 +30,8 @@ export type StringEditorDefinition<T extends ChartNode> = SharedEditorDefinition
|
|
|
30
30
|
export type ToggleEditorDefinition<T extends ChartNode> = SharedEditorDefinitionProps<T> & {
|
|
31
31
|
type: 'toggle';
|
|
32
32
|
dataKey: DataOfType<T, boolean>;
|
|
33
|
+
/** Value rendered when an older node omits this optional boolean setting. */
|
|
34
|
+
defaultValue?: boolean;
|
|
33
35
|
useInputToggleDataKey?: DataOfType<T, boolean>;
|
|
34
36
|
turnOffDataKeysWhenEnabled?: DataOfType<T, boolean>[];
|
|
35
37
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { DataValue } from './DataValue.js';
|
|
2
|
+
export type GraphInputStreamResult = {
|
|
3
|
+
value: DataValue;
|
|
4
|
+
error?: never;
|
|
5
|
+
} | {
|
|
6
|
+
error: Error;
|
|
7
|
+
value?: never;
|
|
8
|
+
};
|
|
9
|
+
export type GraphInputStream = {
|
|
10
|
+
readonly result: GraphInputStreamResult | undefined;
|
|
11
|
+
readonly settled: Promise<GraphInputStreamResult>;
|
|
12
|
+
subscribe(listener: (value: DataValue, coalesced: number) => void): () => void;
|
|
13
|
+
};
|
|
14
|
+
/** One invocation/port, one subscriber, bounded pre-start snapshot, one terminal. */
|
|
15
|
+
export declare class GraphInputStreamRelay implements GraphInputStream {
|
|
16
|
+
#private;
|
|
17
|
+
result: GraphInputStreamResult | undefined;
|
|
18
|
+
readonly settled: Promise<GraphInputStreamResult>;
|
|
19
|
+
constructor();
|
|
20
|
+
publish(value: DataValue, coalesced?: number): void;
|
|
21
|
+
finish(result: GraphInputStreamResult): void;
|
|
22
|
+
subscribe(listener: (value: DataValue, coalesced: number) => void): () => void;
|
|
23
|
+
}
|
|
@@ -13,6 +13,7 @@ import { type GraphBoundaryCache } from './GraphBoundaryCache.js';
|
|
|
13
13
|
import { type GraphProgress } from './GraphProgress.js';
|
|
14
14
|
import { type RivetStoredValueStore } from './StoredValueStore.js';
|
|
15
15
|
import { type StreamingOutputWatchHistorySummary } from './StreamingOutputWatchHistory.js';
|
|
16
|
+
import { type GraphInputStream } from './GraphInputStream.js';
|
|
16
17
|
import type { RivetKnowledgeStoreRegistry } from '../integrations/KnowledgeStore.js';
|
|
17
18
|
/**
|
|
18
19
|
* Provenance attached only while RecordingPlayer re-emits a historical event.
|
|
@@ -359,6 +360,8 @@ export declare class GraphProcessor {
|
|
|
359
360
|
* event protocol.
|
|
360
361
|
*/
|
|
361
362
|
onGraphOutputPartial?: GraphOutputPartialListener;
|
|
363
|
+
/** Internal, invocation-scoped live named inputs. Not a serialized value. */
|
|
364
|
+
graphInputStreams?: Readonly<Record<string, GraphInputStream>>;
|
|
362
365
|
}): Promise<GraphOutputs>;
|
|
363
366
|
getRootProcessor(): GraphProcessor;
|
|
364
367
|
/** Raise a user event on the processor, all subprocessors, and their children. */
|
|
@@ -20,4 +20,4 @@ export declare function getInputNodesTo(state: ExecutionState, node: ChartNode):
|
|
|
20
20
|
export declare function getOutputNodesFrom(state: ExecutionState, node: ChartNode): OutputNodeResult;
|
|
21
21
|
export declare function hasErroredInputNode(state: ExecutionState, node: ChartNode, inputNodes: ChartNode[], onTrace?: (message: string) => void): boolean;
|
|
22
22
|
export declare function getMissingRequiredInputs(state: ExecutionState, node: ChartNode): NodeInputDefinition[];
|
|
23
|
-
export declare function getWaitingForInputNode(state: ExecutionState, node: ChartNode, inputNodes: ChartNode[], inputValues: Inputs):
|
|
23
|
+
export declare function getWaitingForInputNode(state: ExecutionState, node: ChartNode, inputNodes: ChartNode[], inputValues: Inputs): ChartNode | undefined;
|