@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,191 @@
|
|
|
1
|
+
import { canRenderDataBusNode, getDataBusInputChannelIndex, getDataBusOutputChannelIndex } from './DataBusTopology.js';
|
|
2
|
+
import { resolveNodePrefabInstance } from './NodePrefabResolver.js';
|
|
3
|
+
import { createGraphOutputSelection } from './GraphOutputSelection.js';
|
|
4
|
+
export function canStreamThroughGraphCaller(node) {
|
|
5
|
+
return ((node.type === 'subGraph' || node.type === 'referencedGraphAlias') &&
|
|
6
|
+
!node.disabled &&
|
|
7
|
+
!node.isConditional &&
|
|
8
|
+
!node.isSplitRun &&
|
|
9
|
+
!node.data.useErrorOutput);
|
|
10
|
+
}
|
|
11
|
+
export function canStreamThroughGraphInput(node) {
|
|
12
|
+
return (node.type === 'graphInput' &&
|
|
13
|
+
!node.disabled &&
|
|
14
|
+
!node.isConditional &&
|
|
15
|
+
!node.isSplitRun &&
|
|
16
|
+
!node.data.useDefaultValueInput);
|
|
17
|
+
}
|
|
18
|
+
/** Trace Watch demand through named boundaries without making ordinary nodes repeatable. */
|
|
19
|
+
export function getProjectStreamingOutputWatchConnections({ project, graph, referencedProjects, registry, frozenNodeOutputs = {}, isNodeFrozen, fullGraphCallers, }) {
|
|
20
|
+
// Unsaved active graph edits must take precedence over the stored project graph.
|
|
21
|
+
const currentProject = {
|
|
22
|
+
...project,
|
|
23
|
+
graphs: { ...project.graphs, ...(graph.metadata?.id ? { [graph.metadata.id]: graph } : {}) },
|
|
24
|
+
};
|
|
25
|
+
const projects = { ...referencedProjects, [project.metadata.id]: currentProject };
|
|
26
|
+
const contexts = new Map();
|
|
27
|
+
const isFrozen = (owner, candidate, node) => isNodeFrozen?.(owner, candidate, node) ??
|
|
28
|
+
(owner === currentProject &&
|
|
29
|
+
!!(candidate.metadata?.id && frozenNodeOutputs[candidate.metadata.id]?.[node.id]?.length));
|
|
30
|
+
for (const owner of Object.values(projects)) {
|
|
31
|
+
for (const candidate of Object.values(owner.graphs)) {
|
|
32
|
+
const nodes = Object.fromEntries(candidate.nodes.map((node) => [node.id, resolveNodePrefabInstance(owner, node)]));
|
|
33
|
+
const connectionsByNode = new Map();
|
|
34
|
+
for (const edge of candidate.connections) {
|
|
35
|
+
for (const id of new Set([edge.inputNodeId, edge.outputNodeId])) {
|
|
36
|
+
const edges = connectionsByNode.get(id) ?? [];
|
|
37
|
+
edges.push(edge);
|
|
38
|
+
connectionsByNode.set(id, edges);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const ports = new Map();
|
|
42
|
+
const getPorts = (nodeId) => {
|
|
43
|
+
const cached = ports.get(nodeId);
|
|
44
|
+
if (cached)
|
|
45
|
+
return cached;
|
|
46
|
+
const node = nodes[nodeId];
|
|
47
|
+
let definitions = { inputs: new Set(), outputs: new Set() };
|
|
48
|
+
try {
|
|
49
|
+
if (!node)
|
|
50
|
+
return definitions;
|
|
51
|
+
const impl = registry.createDynamicImpl(node);
|
|
52
|
+
const connections = connectionsByNode.get(node.id) ?? [];
|
|
53
|
+
definitions = {
|
|
54
|
+
inputs: new Set(impl.getInputDefinitionsIncludingBuiltIn(connections, nodes, owner, projects).map((port) => port.id)),
|
|
55
|
+
outputs: new Set(impl.getOutputDefinitions(connections, nodes, owner, projects).map((port) => port.id)),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// Missing plugins or incomplete definitions cannot establish a stream route.
|
|
60
|
+
}
|
|
61
|
+
ports.set(nodeId, definitions);
|
|
62
|
+
return definitions;
|
|
63
|
+
};
|
|
64
|
+
// Resolve definitions only on visited routes, including failed plugin lookups.
|
|
65
|
+
const incomingByNode = new Map();
|
|
66
|
+
const incoming = (nodeId) => {
|
|
67
|
+
let edges = incomingByNode.get(nodeId);
|
|
68
|
+
if (!edges) {
|
|
69
|
+
edges = (connectionsByNode.get(nodeId) ?? []).filter((edge) => edge.inputNodeId === nodeId &&
|
|
70
|
+
getPorts(nodeId).inputs.has(edge.inputId) &&
|
|
71
|
+
getPorts(edge.outputNodeId).outputs.has(edge.outputId));
|
|
72
|
+
incomingByNode.set(nodeId, edges);
|
|
73
|
+
}
|
|
74
|
+
return edges;
|
|
75
|
+
};
|
|
76
|
+
contexts.set(candidate, { project: owner, nodes, incoming, marked: new Set() });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Index callers by the actual target graph, not graph/node IDs (which are local).
|
|
80
|
+
const callers = new Map();
|
|
81
|
+
for (const [parent, context] of contexts) {
|
|
82
|
+
for (const node of Object.values(context.nodes)) {
|
|
83
|
+
if (node.disabled || isFrozen(context.project, parent, node) || !canStreamThroughGraphCaller(node))
|
|
84
|
+
continue;
|
|
85
|
+
const caller = node;
|
|
86
|
+
const owner = caller.type === 'subGraph' ? context.project : projects[caller.data.projectId];
|
|
87
|
+
const child = owner?.graphs[caller.data.graphId];
|
|
88
|
+
if (!child)
|
|
89
|
+
continue;
|
|
90
|
+
let selected;
|
|
91
|
+
if (caller.type === 'subGraph' &&
|
|
92
|
+
caller.data.skipUnusedOutputs &&
|
|
93
|
+
!caller.data.useAsGraphPartialOutput &&
|
|
94
|
+
!(parent === graph && fullGraphCallers?.has(caller.id))) {
|
|
95
|
+
const childContext = contexts.get(child);
|
|
96
|
+
const outputNames = new Set(Object.values(childContext.nodes)
|
|
97
|
+
.filter((node) => node.type === 'graphOutput')
|
|
98
|
+
.map((node) => node.data.id));
|
|
99
|
+
const outputs = parent.connections
|
|
100
|
+
.filter((edge) => edge.outputNodeId === caller.id)
|
|
101
|
+
.map((edge) => edge.outputId)
|
|
102
|
+
.filter((id) => outputNames.has(id));
|
|
103
|
+
try {
|
|
104
|
+
selected = createGraphOutputSelection({ ...child, nodes: Object.values(childContext.nodes) }, outputs, (node) => childContext.incoming(node.id).map((edge) => childContext.nodes[edge.outputNodeId])).nodeIds;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const entries = callers.get(child) ?? [];
|
|
111
|
+
entries.push({ graph: parent, node, selected });
|
|
112
|
+
callers.set(child, entries);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const pending = [];
|
|
116
|
+
for (const [candidate, context] of contexts) {
|
|
117
|
+
for (const node of Object.values(context.nodes)) {
|
|
118
|
+
if (node.type !== 'watchStreamingOutput' || node.disabled || isFrozen(context.project, candidate, node))
|
|
119
|
+
continue;
|
|
120
|
+
const inputs = context.incoming(node.id).filter((edge) => edge.inputId === 'stream');
|
|
121
|
+
// Multiple providers are rejected by the Watch scheduler, not multiple streams.
|
|
122
|
+
if (inputs.length === 1)
|
|
123
|
+
pending.push({ graph: candidate, edge: inputs[0] });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
while (pending.length) {
|
|
127
|
+
const { graph: candidate, edge } = pending.pop();
|
|
128
|
+
const context = contexts.get(candidate);
|
|
129
|
+
if (context.marked.has(edge))
|
|
130
|
+
continue;
|
|
131
|
+
const route = new Set([edge]);
|
|
132
|
+
let producerEdge = edge;
|
|
133
|
+
let source = context.nodes[producerEdge.outputNodeId];
|
|
134
|
+
while (source && canRenderDataBusNode(source)) {
|
|
135
|
+
const channel = getDataBusOutputChannelIndex(producerEdge.outputId);
|
|
136
|
+
const providers = context
|
|
137
|
+
.incoming(source.id)
|
|
138
|
+
.filter((input) => getDataBusInputChannelIndex(input.inputId) === channel);
|
|
139
|
+
if (channel == null || providers.length !== 1 || route.has(providers[0])) {
|
|
140
|
+
source = undefined;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
producerEdge = providers[0];
|
|
144
|
+
route.add(producerEdge);
|
|
145
|
+
source = context.nodes[producerEdge.outputNodeId];
|
|
146
|
+
}
|
|
147
|
+
if (!source || source.disabled || source.type === 'dataBus')
|
|
148
|
+
continue;
|
|
149
|
+
if (context.nodes[edge.inputNodeId]?.type === 'graphOutput' && source.isSplitRun)
|
|
150
|
+
continue;
|
|
151
|
+
for (const segment of route)
|
|
152
|
+
context.marked.add(segment);
|
|
153
|
+
if (source.isSplitRun || isFrozen(context.project, candidate, source))
|
|
154
|
+
continue;
|
|
155
|
+
if (source.type === 'graphInput' && producerEdge.outputId === 'data') {
|
|
156
|
+
if (!canStreamThroughGraphInput(source))
|
|
157
|
+
continue;
|
|
158
|
+
const inputName = source.data.id;
|
|
159
|
+
for (const parent of callers.get(candidate) ?? []) {
|
|
160
|
+
if (parent.selected && !parent.selected.has(edge.inputNodeId))
|
|
161
|
+
continue;
|
|
162
|
+
for (const input of contexts.get(parent.graph).incoming(parent.node.id)) {
|
|
163
|
+
if (input.inputId === inputName)
|
|
164
|
+
pending.push({ graph: parent.graph, edge: input });
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (!canStreamThroughGraphCaller(source))
|
|
170
|
+
continue;
|
|
171
|
+
const caller = source;
|
|
172
|
+
const childProject = caller.type === 'subGraph' ? context.project : projects[caller.data.projectId];
|
|
173
|
+
const child = childProject?.graphs[caller.data.graphId];
|
|
174
|
+
const childContext = child && contexts.get(child);
|
|
175
|
+
if (!child || !childContext)
|
|
176
|
+
continue;
|
|
177
|
+
const outputs = Object.values(childContext.nodes).filter((node) => node.type === 'graphOutput' && !node.disabled && node.data.id === producerEdge.outputId);
|
|
178
|
+
// Duplicate names have first-final-winner semantics, so cannot relay partials.
|
|
179
|
+
if (outputs.length !== 1)
|
|
180
|
+
continue;
|
|
181
|
+
const output = outputs[0];
|
|
182
|
+
if (output.isConditional || output.isSplitRun || isFrozen(childProject, child, output))
|
|
183
|
+
continue;
|
|
184
|
+
for (const input of childContext.incoming(output.id)) {
|
|
185
|
+
if (input.inputId === 'value' && !childContext.nodes[input.outputNodeId]?.isSplitRun) {
|
|
186
|
+
pending.push({ graph: child, edge: input });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return contexts.get(graph)?.marked ?? new Set();
|
|
191
|
+
}
|
|
@@ -7,7 +7,7 @@ import { orderBy } from 'lodash-es';
|
|
|
7
7
|
import { coerceTypeOptional, dedent, getInputOrData } from '../../utils/index.js';
|
|
8
8
|
import { nodeDefinition } from '../NodeDefinition.js';
|
|
9
9
|
import { match } from 'ts-pattern';
|
|
10
|
-
import { getNextVariadicPortIndex } from './variadicPortIndex.js';
|
|
10
|
+
import { getNextVariadicPortIndex, parseVariadicPortIndex } from './variadicPortIndex.js';
|
|
11
11
|
const messageTypeToTitle = {
|
|
12
12
|
assistant: 'Assistant',
|
|
13
13
|
developer: 'Developer',
|
|
@@ -148,7 +148,7 @@ export class AssembleMessageNodeImpl extends NodeImpl {
|
|
|
148
148
|
.otherwise(() => {
|
|
149
149
|
throw new Error(`Invalid type: ${type}`);
|
|
150
150
|
});
|
|
151
|
-
const inputParts = orderBy(Object.entries(inputs).filter(([key]) => key.startsWith('part')), ([key]) => key, 'asc');
|
|
151
|
+
const inputParts = orderBy(Object.entries(inputs).filter(([key]) => key.startsWith('part')), ([key]) => parseVariadicPortIndex(key, 'part', 'legacy'), 'asc');
|
|
152
152
|
for (const [, inputPart] of inputParts) {
|
|
153
153
|
if (!inputPart || inputPart.type === 'control-flow-excluded' || !inputPart.value) {
|
|
154
154
|
continue;
|
|
@@ -8,7 +8,18 @@ import { orderBy } from 'lodash-es';
|
|
|
8
8
|
import { dedent } from 'ts-dedent';
|
|
9
9
|
import { nodeDefinition } from '../NodeDefinition.js';
|
|
10
10
|
import { getInputOrData } from '../../utils/inputs.js';
|
|
11
|
-
import { getNextVariadicPortIndex } from './variadicPortIndex.js';
|
|
11
|
+
import { getNextVariadicPortIndex, parseVariadicPortIndex } from './variadicPortIndex.js';
|
|
12
|
+
function isEmptyPromptMessage(message) {
|
|
13
|
+
// Tool protocol messages remain meaningful even when their textual content is empty.
|
|
14
|
+
if (message.type === 'function') {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if (message.type === 'assistant' && (message.function_call != null || (message.function_calls?.length ?? 0) > 0)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const parts = Array.isArray(message.message) ? message.message : [message.message];
|
|
21
|
+
return !parts.some((part) => typeof part !== 'string' || part.trim().length > 0);
|
|
22
|
+
}
|
|
12
23
|
export class AssemblePromptNodeImpl extends NodeImpl {
|
|
13
24
|
static create() {
|
|
14
25
|
const chartNode = {
|
|
@@ -20,7 +31,9 @@ export class AssemblePromptNodeImpl extends NodeImpl {
|
|
|
20
31
|
y: 0,
|
|
21
32
|
width: 250,
|
|
22
33
|
},
|
|
23
|
-
data: {
|
|
34
|
+
data: {
|
|
35
|
+
filterEmptyPrompts: false,
|
|
36
|
+
},
|
|
24
37
|
};
|
|
25
38
|
return chartNode;
|
|
26
39
|
}
|
|
@@ -32,7 +45,7 @@ export class AssemblePromptNodeImpl extends NodeImpl {
|
|
|
32
45
|
dataType: 'boolean',
|
|
33
46
|
id: 'isLastMessageCacheBreakpoint',
|
|
34
47
|
title: 'Is Last Message Cache Breakpoint',
|
|
35
|
-
description: 'Whether the last message in
|
|
48
|
+
description: 'Whether the last message in a multi-message prompt should be a cache breakpoint.',
|
|
36
49
|
});
|
|
37
50
|
}
|
|
38
51
|
for (let i = 1; i <= messageCount; i++) {
|
|
@@ -78,48 +91,64 @@ export class AssemblePromptNodeImpl extends NodeImpl {
|
|
|
78
91
|
group: ['AI'],
|
|
79
92
|
};
|
|
80
93
|
}
|
|
81
|
-
getEditors(
|
|
94
|
+
getEditors() {
|
|
82
95
|
return [
|
|
83
96
|
{
|
|
84
97
|
type: 'toggle',
|
|
85
98
|
label: 'Compute Token Count',
|
|
86
99
|
dataKey: 'computeTokenCount',
|
|
87
100
|
},
|
|
101
|
+
{
|
|
102
|
+
type: 'toggle',
|
|
103
|
+
label: 'Filter empty prompts',
|
|
104
|
+
dataKey: 'filterEmptyPrompts',
|
|
105
|
+
defaultValue: false,
|
|
106
|
+
helperMessage: 'Removes text-only messages whose content is empty or whitespace. Rich-content and tool-protocol messages are preserved.',
|
|
107
|
+
},
|
|
88
108
|
{
|
|
89
109
|
type: 'toggle',
|
|
90
110
|
label: 'Is Last Message Cache Breakpoint',
|
|
91
111
|
dataKey: 'isLastMessageCacheBreakpoint',
|
|
92
|
-
|
|
112
|
+
useInputToggleDataKey: 'useIsLastMessageCacheBreakpointInput',
|
|
113
|
+
helperMessage: 'For Anthropic, marks the last message in a prompt containing at least two messages as a cache breakpoint. This message and every message before it will be cached using Prompt Caching.',
|
|
93
114
|
},
|
|
94
115
|
];
|
|
95
116
|
}
|
|
96
|
-
getBody(
|
|
97
|
-
return
|
|
117
|
+
getBody() {
|
|
118
|
+
return [
|
|
119
|
+
this.data.filterEmptyPrompts ? 'Filter empty prompts: Enabled' : '',
|
|
120
|
+
this.data.useIsLastMessageCacheBreakpointInput
|
|
121
|
+
? 'Last message cache breakpoint: From input'
|
|
122
|
+
: this.data.isLastMessageCacheBreakpoint
|
|
123
|
+
? 'Last message is cache breakpoint'
|
|
124
|
+
: '',
|
|
125
|
+
]
|
|
126
|
+
.filter(Boolean)
|
|
127
|
+
.join('\n');
|
|
98
128
|
}
|
|
99
129
|
async process(inputs, context) {
|
|
100
130
|
const output = {};
|
|
101
131
|
const isLastMessageCacheBreakpoint = getInputOrData(this.data, inputs, 'isLastMessageCacheBreakpoint', 'boolean');
|
|
102
132
|
const outMessages = [];
|
|
103
|
-
const inputMessages = orderBy(Object.entries(inputs).filter(([key]) => key.startsWith('message')), ([key]) => key, 'asc');
|
|
133
|
+
const inputMessages = orderBy(Object.entries(inputs).filter(([key]) => key.startsWith('message')), ([key]) => parseVariadicPortIndex(key, 'message', 'legacy'), 'asc');
|
|
104
134
|
for (const [, inputMessage] of inputMessages) {
|
|
105
135
|
if (!inputMessage || inputMessage.type === 'control-flow-excluded' || !inputMessage.value) {
|
|
106
136
|
continue;
|
|
107
137
|
}
|
|
108
138
|
const inMessages = arrayizeDataValue(unwrapDataValue(inputMessage));
|
|
109
139
|
for (const message of inMessages) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
else {
|
|
114
|
-
const coerced = coerceType(message, 'chat-message');
|
|
115
|
-
if (coerced) {
|
|
116
|
-
outMessages.push(coerced);
|
|
117
|
-
}
|
|
140
|
+
const outMessage = message.type === 'chat-message' ? message.value : coerceType(message, 'chat-message');
|
|
141
|
+
if (this.data.filterEmptyPrompts && isEmptyPromptMessage(outMessage)) {
|
|
142
|
+
continue;
|
|
118
143
|
}
|
|
144
|
+
outMessages.push(outMessage);
|
|
119
145
|
}
|
|
120
146
|
}
|
|
121
147
|
if (isLastMessageCacheBreakpoint && outMessages.length > 1) {
|
|
122
|
-
outMessages.
|
|
148
|
+
outMessages[outMessages.length - 1] = {
|
|
149
|
+
...outMessages[outMessages.length - 1],
|
|
150
|
+
isCacheBreakpoint: true,
|
|
151
|
+
};
|
|
123
152
|
}
|
|
124
153
|
output['prompt'] = {
|
|
125
154
|
type: 'chat-message[]',
|
|
@@ -9,7 +9,7 @@ export class CoalesceNewNodeImpl extends CoalesceNodeBase {
|
|
|
9
9
|
static getUIData() {
|
|
10
10
|
return {
|
|
11
11
|
infoBoxBody: dedent `
|
|
12
|
-
Takes in any number of inputs and outputs the first value that is not "Not Ran". Useful for consolidating branches after a Match node.
|
|
12
|
+
Takes in any number of inputs and outputs the first value that is not "Not Ran". Useful for consolidating branches after a Match case node.
|
|
13
13
|
|
|
14
14
|
Null and undefined input values are emitted by default, but the node can be configured to skip either value and continue checking later inputs.
|
|
15
15
|
`,
|
|
@@ -12,7 +12,7 @@ export class CoalesceNodeImpl extends CoalesceNodeBase {
|
|
|
12
12
|
static getUIData() {
|
|
13
13
|
return {
|
|
14
14
|
infoBoxBody: dedent `
|
|
15
|
-
Legacy Coalesce node. Takes in any number of inputs and outputs the first value that is not "Not Ran". Useful for consolidating branches after a Match node.
|
|
15
|
+
Legacy Coalesce node. Takes in any number of inputs and outputs the first value that is not "Not Ran". Useful for consolidating branches after a Match case node.
|
|
16
16
|
|
|
17
17
|
Its Conditional input can exclude the node itself. New graphs should use Coalesce instead, which has the same fallback behavior without that port.
|
|
18
18
|
`,
|
|
@@ -105,28 +105,24 @@ export class GraphInputNodeImpl extends NodeImpl {
|
|
|
105
105
|
};
|
|
106
106
|
}
|
|
107
107
|
async process(inputs, context) {
|
|
108
|
-
|
|
109
|
-
? undefined
|
|
110
|
-
: coerceTypeOptional(context.graphInputs[this.data.id], this.data.dataType);
|
|
111
|
-
if (inputValue == null && this.data.useDefaultValueInput) {
|
|
112
|
-
inputValue = coerceTypeOptional(inputs['default'], this.data.dataType);
|
|
113
|
-
}
|
|
114
|
-
if (inputValue == null) {
|
|
115
|
-
inputValue =
|
|
116
|
-
coerceTypeOptional(inferType(this.data.defaultValue), this.data.dataType) ||
|
|
117
|
-
getDefaultValue(this.data.dataType);
|
|
118
|
-
}
|
|
119
|
-
// Resolve undefined for array inputs to empty array
|
|
120
|
-
if (inputValue == null && isArrayDataType(this.data.dataType)) {
|
|
121
|
-
inputValue = { type: this.data.dataType, value: [] };
|
|
122
|
-
}
|
|
123
|
-
const value = {
|
|
124
|
-
type: this.data.dataType,
|
|
125
|
-
value: inputValue,
|
|
126
|
-
};
|
|
108
|
+
const value = resolveGraphInputValue(this.data, context.graphInputs[this.data.id], inputs);
|
|
127
109
|
// Store the resolved value in the context for access by other nodes
|
|
128
110
|
context.graphInputNodeValues[this.data.id] = value;
|
|
129
111
|
return { ['data']: value };
|
|
130
112
|
}
|
|
131
113
|
}
|
|
114
|
+
/** One coercion/default policy for ordinary and live graph inputs. */
|
|
115
|
+
export function resolveGraphInputValue(data, input, inputs = {}) {
|
|
116
|
+
let inputValue = input == null ? undefined : coerceTypeOptional(input, data.dataType);
|
|
117
|
+
if (inputValue == null && data.useDefaultValueInput) {
|
|
118
|
+
inputValue = coerceTypeOptional(inputs['default'], data.dataType);
|
|
119
|
+
}
|
|
120
|
+
if (inputValue == null) {
|
|
121
|
+
inputValue = coerceTypeOptional(inferType(data.defaultValue), data.dataType) || getDefaultValue(data.dataType);
|
|
122
|
+
}
|
|
123
|
+
if (inputValue == null && isArrayDataType(data.dataType)) {
|
|
124
|
+
inputValue = { type: data.dataType, value: [] };
|
|
125
|
+
}
|
|
126
|
+
return { type: data.dataType, value: inputValue };
|
|
127
|
+
}
|
|
132
128
|
export const graphInputNode = nodeDefinition(GraphInputNodeImpl, 'Graph Input');
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { nanoid } from 'nanoid/non-secure';
|
|
2
|
+
import { dedent } from 'ts-dedent';
|
|
3
|
+
import { nodeDefinition } from '../NodeDefinition.js';
|
|
4
|
+
import {} from '../NodeImpl.js';
|
|
5
|
+
import {} from '../NodeBase.js';
|
|
6
|
+
import {} from '../EditorDefinition.js';
|
|
7
|
+
import { MatchCaseNodeBase, } from './MatchCaseNodeBase.js';
|
|
8
|
+
/** Match case is the current routing node; legacy `match` remains regex-only. */
|
|
9
|
+
export class MatchCaseNodeImpl extends MatchCaseNodeBase {
|
|
10
|
+
caseEditorLabel = 'Cases';
|
|
11
|
+
caseEditorPlaceholder = 'Case';
|
|
12
|
+
casesEditorPlacement = 'before-trigger';
|
|
13
|
+
customCaseValuesEditorLabel = '';
|
|
14
|
+
defaultExclusive = true;
|
|
15
|
+
firstMatchingBodyValue = 'First matching case';
|
|
16
|
+
inputTitle = 'Input';
|
|
17
|
+
matchingCasesToTriggerOptions = [
|
|
18
|
+
{ value: true, label: 'First matching case' },
|
|
19
|
+
{ value: false, label: 'All matching cases' },
|
|
20
|
+
];
|
|
21
|
+
sharedCustomValueInputTitle = 'Output value';
|
|
22
|
+
triggerEditorLabel = 'Trigger';
|
|
23
|
+
static create() {
|
|
24
|
+
return {
|
|
25
|
+
type: 'matchCase',
|
|
26
|
+
title: 'Match case',
|
|
27
|
+
id: nanoid(),
|
|
28
|
+
visualData: {
|
|
29
|
+
x: 0,
|
|
30
|
+
y: 0,
|
|
31
|
+
width: 250,
|
|
32
|
+
},
|
|
33
|
+
data: {
|
|
34
|
+
cases: ['YES', 'NO'],
|
|
35
|
+
casePortIds: [nanoid(), nanoid()],
|
|
36
|
+
valueInputMode: 'shared',
|
|
37
|
+
matchMode: 'plainText',
|
|
38
|
+
caseSensitive: true,
|
|
39
|
+
exclusive: true,
|
|
40
|
+
returnValue: 'true',
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
matchesCase(input, caseValue) {
|
|
45
|
+
if (this.getMatchMode() === 'regex') {
|
|
46
|
+
return new RegExp(caseValue).test(input);
|
|
47
|
+
}
|
|
48
|
+
if (this.getCaseSensitive()) {
|
|
49
|
+
return input === caseValue;
|
|
50
|
+
}
|
|
51
|
+
return input.toLowerCase() === caseValue.toLowerCase();
|
|
52
|
+
}
|
|
53
|
+
describeCaseMatch(caseValue) {
|
|
54
|
+
return this.getMatchMode() === 'plainText'
|
|
55
|
+
? this.getCaseSensitive()
|
|
56
|
+
? `the Input value exactly equals ${JSON.stringify(caseValue)}`
|
|
57
|
+
: `the Input value equals ${JSON.stringify(caseValue)} without regard to case`
|
|
58
|
+
: `/${caseValue}/ matches the Input value`;
|
|
59
|
+
}
|
|
60
|
+
describeNoCaseMatches() {
|
|
61
|
+
if (this.getMatchMode() === 'regex') {
|
|
62
|
+
return 'no regular expression matches the Input value';
|
|
63
|
+
}
|
|
64
|
+
return this.getCaseSensitive()
|
|
65
|
+
? 'no case exactly equals the Input value'
|
|
66
|
+
: 'no case equals the Input value without regard to case';
|
|
67
|
+
}
|
|
68
|
+
getReturnValueMode() {
|
|
69
|
+
return this.data.returnValue === 'testValue' || this.data.returnValue === 'custom'
|
|
70
|
+
? this.data.returnValue
|
|
71
|
+
: 'true';
|
|
72
|
+
}
|
|
73
|
+
getEditorsAfterTrigger() {
|
|
74
|
+
return [
|
|
75
|
+
{
|
|
76
|
+
type: 'segmented',
|
|
77
|
+
label: 'Output value',
|
|
78
|
+
dataKey: 'returnValue',
|
|
79
|
+
defaultValue: 'true',
|
|
80
|
+
options: [
|
|
81
|
+
{ value: 'true', label: 'True' },
|
|
82
|
+
{ value: 'testValue', label: 'Input value' },
|
|
83
|
+
{ value: 'custom', label: 'Custom' },
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
shouldHideCustomCaseValues(data) {
|
|
89
|
+
return (data.returnValue ?? 'true') !== 'custom';
|
|
90
|
+
}
|
|
91
|
+
getEditors() {
|
|
92
|
+
return [
|
|
93
|
+
{
|
|
94
|
+
type: 'segmented',
|
|
95
|
+
label: 'Match mode',
|
|
96
|
+
dataKey: 'matchMode',
|
|
97
|
+
defaultValue: 'plainText',
|
|
98
|
+
options: [
|
|
99
|
+
{ value: 'plainText', label: 'Plain text' },
|
|
100
|
+
{ value: 'regex', label: 'Regular expression' },
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
type: 'toggle',
|
|
105
|
+
label: 'Case sensitive',
|
|
106
|
+
dataKey: 'caseSensitive',
|
|
107
|
+
defaultValue: true,
|
|
108
|
+
hideIf: (data) => data.matchMode === 'regex',
|
|
109
|
+
},
|
|
110
|
+
...super.getEditors(),
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
static getUIData() {
|
|
114
|
+
return {
|
|
115
|
+
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.
|
|
117
|
+
|
|
118
|
+
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
|
+
`,
|
|
120
|
+
infoBoxTitle: 'Match case Node',
|
|
121
|
+
contextMenuTitle: 'Match case',
|
|
122
|
+
group: ['Logic'],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
getMatchMode() {
|
|
126
|
+
return this.data.matchMode === 'regex' ? 'regex' : 'plainText';
|
|
127
|
+
}
|
|
128
|
+
getCaseSensitive() {
|
|
129
|
+
return this.data.caseSensitive !== false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
export const matchCaseNode = nodeDefinition(MatchCaseNodeImpl, 'Match case');
|