@valerypopoff/rivet2-core 2.1.4 → 2.1.5
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 +3733 -969
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/cjs/webAppRuntime.cjs +605 -16
- package/dist/cjs/webAppRuntime.cjs.map +3 -3
- package/dist/esm/api/createProcessor.js +5 -1
- package/dist/esm/exports.js +3 -0
- package/dist/esm/model/GraphBoundaryEffects.js +13 -0
- package/dist/esm/model/GraphProcessor.js +1127 -82
- package/dist/esm/model/ManagedAsyncBranches.js +28 -0
- package/dist/esm/model/Nodes.js +9 -0
- package/dist/esm/model/ProcessContextBuilder.js +2 -1
- package/dist/esm/model/RecordingPlayer.js +9 -0
- package/dist/esm/model/StoredValueStore.js +226 -0
- package/dist/esm/model/SubprocessorBridge.js +50 -19
- package/dist/esm/model/ToolCallContinuation.js +1 -0
- package/dist/esm/model/UiGraph.js +50 -0
- package/dist/esm/model/UiGraphActionProtocol.js +10 -1
- package/dist/esm/model/UiGraphBrowserRuntime.js +333 -0
- package/dist/esm/model/UiGraphNormalization.js +35 -185
- package/dist/esm/model/UiGraphRendererStyles.js +772 -74
- package/dist/esm/model/UiGraphRuntimeModel.js +230 -14
- package/dist/esm/model/UiGraphSchema.js +91 -0
- package/dist/esm/model/UiGraphWebAppStorage.js +1 -0
- package/dist/esm/model/chat/chatMessages.js +5 -9
- package/dist/esm/model/chat-v2/chatV2Errors.js +36 -3
- package/dist/esm/model/chat-v2/index.js +1 -0
- package/dist/esm/model/chat-v2/toolContinuation.js +6 -8
- package/dist/esm/model/chat-v2/toolContinuationConnection.js +68 -0
- package/dist/esm/model/nodes/DelegateFunctionCallNode.js +12 -40
- package/dist/esm/model/nodes/GetStoredValueNode.js +109 -0
- package/dist/esm/model/nodes/LLMChatV2Node.js +17 -1
- package/dist/esm/model/nodes/MatchNode.js +7 -7
- package/dist/esm/model/nodes/SetStoredValueNode.js +84 -0
- package/dist/esm/model/nodes/StartBackgroundBranchNode.js +59 -0
- package/dist/esm/model/nodes/StoredValueNodeUtils.js +47 -0
- package/dist/esm/model/nodes/toolCallDelegation.js +44 -1
- package/dist/esm/recording/ExecutionRecorder.js +1 -0
- package/dist/esm/utils/coerceType.js +3 -0
- package/dist/esm/webAppRuntime.js +3 -3
- package/dist/types/api/createProcessor.d.ts +4 -0
- package/dist/types/exports.d.ts +3 -0
- package/dist/types/model/EditorDefinition.d.ts +2 -1
- package/dist/types/model/ExecutorProtocol.d.ts +12 -0
- package/dist/types/model/GraphBoundaryEffects.d.ts +9 -1
- package/dist/types/model/GraphProcessor.d.ts +19 -2
- package/dist/types/model/ManagedAsyncBranches.d.ts +6 -0
- package/dist/types/model/Nodes.d.ts +5 -2
- package/dist/types/model/ProcessContext.d.ts +15 -0
- package/dist/types/model/ProcessContextBuilder.d.ts +2 -1
- package/dist/types/model/StoredValueStore.d.ts +55 -0
- package/dist/types/model/SubprocessorBridge.d.ts +4 -2
- package/dist/types/model/ToolCallContinuation.d.ts +13 -0
- package/dist/types/model/UiGraph.d.ts +21 -0
- package/dist/types/model/UiGraphActionProtocol.d.ts +2 -0
- package/dist/types/model/UiGraphBrowserRuntime.d.ts +51 -0
- package/dist/types/model/UiGraphRendererStyles.d.ts +2 -2
- package/dist/types/model/UiGraphRuntimeModel.d.ts +22 -3
- package/dist/types/model/UiGraphSchema.d.ts +113 -0
- package/dist/types/model/UiGraphWebAppStorage.d.ts +3 -0
- package/dist/types/model/chat-v2/index.d.ts +1 -0
- package/dist/types/model/chat-v2/toolContinuation.d.ts +1 -0
- package/dist/types/model/chat-v2/toolContinuationConnection.d.ts +28 -0
- package/dist/types/model/nodes/GetStoredValueNode.d.ts +25 -0
- package/dist/types/model/nodes/SetStoredValueNode.d.ts +23 -0
- package/dist/types/model/nodes/StartBackgroundBranchNode.d.ts +14 -0
- package/dist/types/model/nodes/StoredValueNodeUtils.d.ts +5 -0
- package/dist/types/model/nodes/toolCallDelegation.d.ts +4 -0
- package/dist/types/recording/RecordedEvents.d.ts +5 -0
- package/dist/types/webAppRuntime.d.ts +4 -4
- package/package.json +1 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export const LLM_CHAT_V2_TOOL_CALLS_OUTPUT_ID = 'function-calls';
|
|
2
|
+
export const DELEGATE_TOOL_CALL_INPUT_ID = 'function-call';
|
|
3
|
+
/**
|
|
4
|
+
* Resolves every special request/response relationship formed by an
|
|
5
|
+
* auto-continuing LLM Chat node and an effective Delegate Tool Call input.
|
|
6
|
+
* Callers that inspect a whole graph should reuse this single pass.
|
|
7
|
+
*/
|
|
8
|
+
export function resolveToolContinuationConnections(graph) {
|
|
9
|
+
const nodesById = new Map(graph.nodes.map((node) => [node.id, node]));
|
|
10
|
+
const firstConnectionByInput = new Map();
|
|
11
|
+
for (const connection of graph.connections) {
|
|
12
|
+
if (!nodesById.has(connection.outputNodeId) || !nodesById.has(connection.inputNodeId)) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
const inputKey = `${connection.inputNodeId}\u0000${connection.inputId}`;
|
|
16
|
+
if (!firstConnectionByInput.has(inputKey)) {
|
|
17
|
+
firstConnectionByInput.set(inputKey, connection);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const candidatesByLLMNodeId = new Map();
|
|
21
|
+
for (const connection of graph.connections) {
|
|
22
|
+
if (connection.outputId !== LLM_CHAT_V2_TOOL_CALLS_OUTPUT_ID ||
|
|
23
|
+
connection.inputId !== DELEGATE_TOOL_CALL_INPUT_ID) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const llmNode = nodesById.get(connection.outputNodeId);
|
|
27
|
+
const delegateNode = nodesById.get(connection.inputNodeId);
|
|
28
|
+
if (!isEligibleLLMChatV2Node(llmNode) || !isEligibleDelegateToolCallNode(delegateNode)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const inputKey = `${connection.inputNodeId}\u0000${connection.inputId}`;
|
|
32
|
+
if (firstConnectionByInput.get(inputKey) !== connection) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const candidates = candidatesByLLMNodeId.get(llmNode.id);
|
|
36
|
+
const candidate = { connection, delegateNode };
|
|
37
|
+
if (candidates) {
|
|
38
|
+
candidates.push(candidate);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
candidatesByLLMNodeId.set(llmNode.id, [candidate]);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const resolutions = new Map();
|
|
45
|
+
for (const [llmNodeId, candidates] of candidatesByLLMNodeId) {
|
|
46
|
+
if (candidates.length === 1) {
|
|
47
|
+
resolutions.set(llmNodeId, { kind: 'connected', ...candidates[0] });
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
resolutions.set(llmNodeId, { kind: 'ambiguous', candidates });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return resolutions;
|
|
54
|
+
}
|
|
55
|
+
/** Resolves one LLM node while preserving the convenient `none` result. */
|
|
56
|
+
export function resolveToolContinuationConnection(graph, llmNodeId) {
|
|
57
|
+
return resolveToolContinuationConnections(graph).get(llmNodeId) ?? { kind: 'none' };
|
|
58
|
+
}
|
|
59
|
+
function isEligibleLLMChatV2Node(node) {
|
|
60
|
+
if (!node || node.disabled || node.isSplitRun || node.type !== 'llmChatV2') {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const data = node.data;
|
|
64
|
+
return data.useToolCalling === true && data.autoContinueToolCalls === true;
|
|
65
|
+
}
|
|
66
|
+
function isEligibleDelegateToolCallNode(node) {
|
|
67
|
+
return node?.type === 'delegateFunctionCall' && !node.disabled;
|
|
68
|
+
}
|
|
@@ -3,7 +3,7 @@ import { NodeImpl } from '../NodeImpl.js';
|
|
|
3
3
|
import { dedent } from 'ts-dedent';
|
|
4
4
|
import { nodeDefinition } from '../NodeDefinition.js';
|
|
5
5
|
import { coerceType } from '../../utils/coerceType.js';
|
|
6
|
-
import { delegateToolCall, isDelegatedToolCallRecord } from './toolCallDelegation.js';
|
|
6
|
+
import { buildDelegatedToolCallOutputs, delegateToolCall, isDelegatedToolCallRecord, } from './toolCallDelegation.js';
|
|
7
7
|
export class DelegateFunctionCallNodeImpl extends NodeImpl {
|
|
8
8
|
static create() {
|
|
9
9
|
const chartNode = {
|
|
@@ -29,7 +29,7 @@ export class DelegateFunctionCallNodeImpl extends NodeImpl {
|
|
|
29
29
|
const inputs = [];
|
|
30
30
|
inputs.push({
|
|
31
31
|
id: 'function-call',
|
|
32
|
-
dataType: 'object',
|
|
32
|
+
dataType: ['object', 'object[]'],
|
|
33
33
|
title: 'Tool Call',
|
|
34
34
|
coerced: true,
|
|
35
35
|
required: true,
|
|
@@ -39,6 +39,12 @@ export class DelegateFunctionCallNodeImpl extends NodeImpl {
|
|
|
39
39
|
}
|
|
40
40
|
getOutputDefinitions() {
|
|
41
41
|
const outputs = [];
|
|
42
|
+
outputs.push({
|
|
43
|
+
id: 'assistant-message',
|
|
44
|
+
dataType: 'string',
|
|
45
|
+
title: 'Message (fires before tool call invocation)',
|
|
46
|
+
description: 'Nonblank text the assistant emitted alongside a connected tool-call round. This output fires before the tools are invoked.',
|
|
47
|
+
});
|
|
42
48
|
outputs.push({
|
|
43
49
|
id: 'output',
|
|
44
50
|
dataType: ['string', 'string[]'],
|
|
@@ -48,8 +54,8 @@ export class DelegateFunctionCallNodeImpl extends NodeImpl {
|
|
|
48
54
|
outputs.push({
|
|
49
55
|
id: 'message',
|
|
50
56
|
dataType: ['chat-message', 'chat-message[]', 'object', 'object[]'],
|
|
51
|
-
title: 'Message
|
|
52
|
-
description: 'Maps the
|
|
57
|
+
title: 'Tool Result Message',
|
|
58
|
+
description: 'Maps the tool result into a chat message for a later LLM request.',
|
|
53
59
|
});
|
|
54
60
|
return outputs;
|
|
55
61
|
}
|
|
@@ -69,7 +75,7 @@ export class DelegateFunctionCallNodeImpl extends NodeImpl {
|
|
|
69
75
|
type: 'toggle',
|
|
70
76
|
label: 'Auto Delegate',
|
|
71
77
|
dataKey: 'autoDelegate',
|
|
72
|
-
helperMessage: '
|
|
78
|
+
helperMessage: 'Prefers a subgraph whose name exactly matches the tool, then falls back to the first name containing it.',
|
|
73
79
|
},
|
|
74
80
|
{
|
|
75
81
|
type: 'toggle',
|
|
@@ -129,16 +135,7 @@ export class DelegateFunctionCallNodeImpl extends NodeImpl {
|
|
|
129
135
|
return buildDelegatedToolCallOutputs(delegatedRecords);
|
|
130
136
|
}
|
|
131
137
|
const result = await delegateToolCall(functionCallInput, context, this.data);
|
|
132
|
-
return
|
|
133
|
-
['output']: {
|
|
134
|
-
type: 'string',
|
|
135
|
-
value: result.outputString,
|
|
136
|
-
},
|
|
137
|
-
['message']: {
|
|
138
|
-
type: 'chat-message',
|
|
139
|
-
value: result.message,
|
|
140
|
-
},
|
|
141
|
-
};
|
|
138
|
+
return buildDelegatedToolCallOutputs([result.record], undefined, result.cost);
|
|
142
139
|
}
|
|
143
140
|
}
|
|
144
141
|
function getDelegatedToolCallRecords(input) {
|
|
@@ -147,29 +144,4 @@ function getDelegatedToolCallRecords(input) {
|
|
|
147
144
|
}
|
|
148
145
|
return isDelegatedToolCallRecord(input) ? [input] : [];
|
|
149
146
|
}
|
|
150
|
-
function buildDelegatedToolCallOutputs(records) {
|
|
151
|
-
if (records.length === 1) {
|
|
152
|
-
const [record] = records;
|
|
153
|
-
return {
|
|
154
|
-
['output']: {
|
|
155
|
-
type: 'string',
|
|
156
|
-
value: record.output,
|
|
157
|
-
},
|
|
158
|
-
['message']: {
|
|
159
|
-
type: 'chat-message',
|
|
160
|
-
value: record.message,
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
return {
|
|
165
|
-
['output']: {
|
|
166
|
-
type: 'string[]',
|
|
167
|
-
value: records.map((record) => record.output),
|
|
168
|
-
},
|
|
169
|
-
['message']: {
|
|
170
|
-
type: 'chat-message[]',
|
|
171
|
-
value: records.map((record) => record.message),
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
147
|
export const delegateFunctionCallNode = nodeDefinition(DelegateFunctionCallNodeImpl, 'Delegate Tool Call');
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { nanoid } from 'nanoid/non-secure';
|
|
2
|
+
import { dedent } from 'ts-dedent';
|
|
3
|
+
import { nodeDefinition } from '../NodeDefinition.js';
|
|
4
|
+
import { NodeImpl } from '../NodeImpl.js';
|
|
5
|
+
import { coerceType } from '../../utils/coerceType.js';
|
|
6
|
+
import { missingStoredValueDataValue, portableStoredValueScalarTypes, storedValueToDataValue, } from './StoredValueNodeUtils.js';
|
|
7
|
+
export class GetStoredValueNodeImpl extends NodeImpl {
|
|
8
|
+
static create() {
|
|
9
|
+
return {
|
|
10
|
+
type: 'getStoredValue',
|
|
11
|
+
title: 'Get Stored Value',
|
|
12
|
+
id: nanoid(),
|
|
13
|
+
visualData: { x: 0, y: 0, width: 220 },
|
|
14
|
+
data: { dataType: 'string', key: 'key', onDemand: false, useKeyInput: false, wait: false },
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
getInputDefinitions() {
|
|
18
|
+
return this.data.useKeyInput ? [{ id: 'key', title: 'Key', dataType: 'string' }] : [];
|
|
19
|
+
}
|
|
20
|
+
getOutputDefinitions() {
|
|
21
|
+
return [
|
|
22
|
+
{
|
|
23
|
+
id: 'value',
|
|
24
|
+
title: 'Value',
|
|
25
|
+
dataType: this.data.onDemand ? `fn<${this.data.dataType}>` : this.data.dataType,
|
|
26
|
+
},
|
|
27
|
+
{ id: 'found', title: 'Found', dataType: 'boolean' },
|
|
28
|
+
{ id: 'key', title: 'Key', dataType: 'string' },
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
getEditors() {
|
|
32
|
+
return [
|
|
33
|
+
{
|
|
34
|
+
type: 'custom',
|
|
35
|
+
label: 'Search Stored Values',
|
|
36
|
+
customEditorId: 'GetStoredValueSelector',
|
|
37
|
+
autoFocus: true,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: 'string',
|
|
41
|
+
dataKey: 'key',
|
|
42
|
+
useInputToggleDataKey: 'useKeyInput',
|
|
43
|
+
label: 'Key',
|
|
44
|
+
includeInGraphSearch: true,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: 'dataTypeSelector',
|
|
48
|
+
dataKey: 'dataType',
|
|
49
|
+
label: 'Data Type',
|
|
50
|
+
allowedDataTypes: portableStoredValueScalarTypes,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: 'toggle',
|
|
54
|
+
dataKey: 'onDemand',
|
|
55
|
+
label: 'On Demand',
|
|
56
|
+
turnOffDataKeysWhenEnabled: ['wait'],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: 'toggle',
|
|
60
|
+
dataKey: 'wait',
|
|
61
|
+
label: 'Wait',
|
|
62
|
+
turnOffDataKeysWhenEnabled: ['onDemand'],
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
getBody() {
|
|
67
|
+
return dedent `
|
|
68
|
+
${this.data.useKeyInput ? '(Key from input)' : this.data.key}
|
|
69
|
+
Type: ${this.data.dataType}
|
|
70
|
+
${this.data.wait ? 'Waits for an in-run Set' : ''}
|
|
71
|
+
`;
|
|
72
|
+
}
|
|
73
|
+
static getUIData() {
|
|
74
|
+
return {
|
|
75
|
+
infoBoxBody: 'Loads a portable JSON value from the root-run cache or the host persistence store. Missing keys return the selected type default.',
|
|
76
|
+
infoBoxTitle: 'Get Stored Value Node',
|
|
77
|
+
contextMenuTitle: 'Get Stored Value',
|
|
78
|
+
group: ['Advanced'],
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
async process(inputs, context) {
|
|
82
|
+
if (this.data.onDemand && this.data.wait)
|
|
83
|
+
throw new Error('Cannot use On Demand and Wait together');
|
|
84
|
+
const key = this.data.useKeyInput ? coerceType(inputs['key'], 'string') : this.data.key;
|
|
85
|
+
let result = await context.getStoredValue(key);
|
|
86
|
+
if (!result.found && this.data.wait) {
|
|
87
|
+
result = { found: true, value: await context.waitForStoredValue(key, context.signal) };
|
|
88
|
+
}
|
|
89
|
+
const value = this.data.onDemand
|
|
90
|
+
? {
|
|
91
|
+
type: `fn<${this.data.dataType}>`,
|
|
92
|
+
value: () => {
|
|
93
|
+
const cached = context.getCachedStoredValue(key);
|
|
94
|
+
return cached.found
|
|
95
|
+
? storedValueToDataValue(cached.value, this.data.dataType).value
|
|
96
|
+
: missingStoredValueDataValue(this.data.dataType).value;
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
: result.found
|
|
100
|
+
? storedValueToDataValue(result.value, this.data.dataType)
|
|
101
|
+
: missingStoredValueDataValue(this.data.dataType);
|
|
102
|
+
return {
|
|
103
|
+
['value']: value,
|
|
104
|
+
['found']: { type: 'boolean', value: result.found },
|
|
105
|
+
['key']: { type: 'string', value: key },
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export const getStoredValueNode = nodeDefinition(GetStoredValueNodeImpl, 'Get Stored Value');
|
|
@@ -255,7 +255,9 @@ export class LLMChatV2NodeImpl extends NodeImpl {
|
|
|
255
255
|
getOptionalNumberBodyLine('Frequency penalty', this.data.frequencyPenalty, this.data.useFrequencyPenaltyInput),
|
|
256
256
|
getStopSequencesBodyLine(this.data),
|
|
257
257
|
getOptionalNumberBodyLine('Seed', this.data.seed, this.data.useSeedInput),
|
|
258
|
-
]
|
|
258
|
+
]
|
|
259
|
+
.filter((line) => line !== undefined)
|
|
260
|
+
.join('\n'),
|
|
259
261
|
};
|
|
260
262
|
}
|
|
261
263
|
async process(inputs, context) {
|
|
@@ -265,6 +267,7 @@ export class LLMChatV2NodeImpl extends NodeImpl {
|
|
|
265
267
|
inputs,
|
|
266
268
|
context,
|
|
267
269
|
});
|
|
270
|
+
const toolCallContinuation = context.toolCallContinuation;
|
|
268
271
|
if (runtime.cachedOutputs != null) {
|
|
269
272
|
return runtime.cachedOutputs;
|
|
270
273
|
}
|
|
@@ -274,6 +277,16 @@ export class LLMChatV2NodeImpl extends NodeImpl {
|
|
|
274
277
|
autoContinue: true,
|
|
275
278
|
maxToolRounds: runtime.maxToolRounds,
|
|
276
279
|
functions: runtime.functions,
|
|
280
|
+
delegateToolCallRound: toolCallContinuation
|
|
281
|
+
? async (toolCalls, preToolMessage) => {
|
|
282
|
+
const results = await toolCallContinuation.run(toolCalls, preToolMessage);
|
|
283
|
+
return results.map((result) => ({
|
|
284
|
+
type: 'chat-message',
|
|
285
|
+
value: result.message,
|
|
286
|
+
delegatedToolCall: result.record,
|
|
287
|
+
}));
|
|
288
|
+
}
|
|
289
|
+
: undefined,
|
|
277
290
|
delegateToolCall: async (toolCall) => {
|
|
278
291
|
const delegated = await delegateToolCall(toolCall, context, {
|
|
279
292
|
handlers: [],
|
|
@@ -290,6 +303,9 @@ export class LLMChatV2NodeImpl extends NodeImpl {
|
|
|
290
303
|
},
|
|
291
304
|
})
|
|
292
305
|
: await runChatV2Pipeline(runtime.runOptions);
|
|
306
|
+
if (toolCallContinuation && result.functionCalls.length > 0) {
|
|
307
|
+
toolCallContinuation.release();
|
|
308
|
+
}
|
|
293
309
|
if (runtime.cacheKey != null && runtime.editorCache != null) {
|
|
294
310
|
runtime.editorCache.set(runtime.cacheKey, cloneLLMChatV2EditorCacheOutputs(result.commonOutputs));
|
|
295
311
|
}
|
|
@@ -11,7 +11,7 @@ export class MatchNodeImpl extends NodeImpl {
|
|
|
11
11
|
static create() {
|
|
12
12
|
const chartNode = {
|
|
13
13
|
type: 'match',
|
|
14
|
-
title: 'Match',
|
|
14
|
+
title: 'Regex Match',
|
|
15
15
|
id: nanoid(),
|
|
16
16
|
visualData: {
|
|
17
17
|
x: 0,
|
|
@@ -106,13 +106,14 @@ export class MatchNodeImpl extends NodeImpl {
|
|
|
106
106
|
infoBoxBody: dedent `
|
|
107
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.
|
|
108
108
|
`,
|
|
109
|
-
infoBoxTitle: 'Match Node',
|
|
110
|
-
contextMenuTitle: 'Match',
|
|
109
|
+
infoBoxTitle: 'Regex Match Node',
|
|
110
|
+
contextMenuTitle: 'Regex Match',
|
|
111
111
|
group: ['Logic'],
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
114
|
async process(inputs) {
|
|
115
|
-
const
|
|
115
|
+
const inputValue = inputs['input'];
|
|
116
|
+
const inputString = inputValue?.value == null ? undefined : coerceType(inputValue, 'string');
|
|
116
117
|
const value = inputs['value'];
|
|
117
118
|
const portIds = resolveStoredOrderedPortIds(this.data.cases.length, this.data.casePortIds, {
|
|
118
119
|
kind: 'prefix',
|
|
@@ -125,8 +126,7 @@ export class MatchNodeImpl extends NodeImpl {
|
|
|
125
126
|
let matched = false;
|
|
126
127
|
const output = {};
|
|
127
128
|
for (let i = 0; i < cases.length; i++) {
|
|
128
|
-
const
|
|
129
|
-
const match = regExp.test(inputString);
|
|
129
|
+
const match = inputString !== undefined && new RegExp(cases[i]).test(inputString);
|
|
130
130
|
const canMatch = !this.data.exclusive || !matched;
|
|
131
131
|
if (match && canMatch) {
|
|
132
132
|
matched = true;
|
|
@@ -157,4 +157,4 @@ export class MatchNodeImpl extends NodeImpl {
|
|
|
157
157
|
return output;
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
-
export const matchNode = nodeDefinition(MatchNodeImpl, 'Match');
|
|
160
|
+
export const matchNode = nodeDefinition(MatchNodeImpl, 'Regex Match');
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { nanoid } from 'nanoid/non-secure';
|
|
2
|
+
import { dedent } from 'ts-dedent';
|
|
3
|
+
import { unwrapDataValue } from '../DataValue.js';
|
|
4
|
+
import { nodeDefinition } from '../NodeDefinition.js';
|
|
5
|
+
import { NodeImpl } from '../NodeImpl.js';
|
|
6
|
+
import { cloneRivetStoredValue } from '../StoredValueStore.js';
|
|
7
|
+
import { coerceType } from '../../utils/coerceType.js';
|
|
8
|
+
import { missingStoredValueDataValue, portableStoredValueScalarTypes, storedValueToDataValue, } from './StoredValueNodeUtils.js';
|
|
9
|
+
export class SetStoredValueNodeImpl extends NodeImpl {
|
|
10
|
+
static create() {
|
|
11
|
+
return {
|
|
12
|
+
type: 'setStoredValue',
|
|
13
|
+
title: 'Set Stored Value',
|
|
14
|
+
id: nanoid(),
|
|
15
|
+
visualData: { x: 0, y: 0, width: 220 },
|
|
16
|
+
data: { dataType: 'string', key: 'key', useKeyInput: false },
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
getInputDefinitions() {
|
|
20
|
+
const inputs = [];
|
|
21
|
+
if (this.data.useKeyInput) {
|
|
22
|
+
inputs.push({ id: 'key', title: 'Key', dataType: 'string' });
|
|
23
|
+
}
|
|
24
|
+
inputs.push({ id: 'value', title: 'Value', dataType: this.data.dataType });
|
|
25
|
+
return inputs;
|
|
26
|
+
}
|
|
27
|
+
getOutputDefinitions() {
|
|
28
|
+
return [
|
|
29
|
+
{ id: 'saved-value', title: 'Saved Value', dataType: this.data.dataType },
|
|
30
|
+
{ id: 'previous-value', title: 'Previous Value', dataType: this.data.dataType },
|
|
31
|
+
{ id: 'had-previous-value', title: 'Had Previous Value', dataType: 'boolean' },
|
|
32
|
+
{ id: 'key', title: 'Key', dataType: 'string' },
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
getEditors() {
|
|
36
|
+
return [
|
|
37
|
+
{
|
|
38
|
+
type: 'string',
|
|
39
|
+
dataKey: 'key',
|
|
40
|
+
useInputToggleDataKey: 'useKeyInput',
|
|
41
|
+
label: 'Key',
|
|
42
|
+
includeInGraphSearch: true,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: 'dataTypeSelector',
|
|
46
|
+
dataKey: 'dataType',
|
|
47
|
+
label: 'Data Type',
|
|
48
|
+
allowedDataTypes: portableStoredValueScalarTypes,
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
getBody() {
|
|
53
|
+
return dedent `
|
|
54
|
+
${this.data.useKeyInput ? '(Key from input)' : this.data.key}
|
|
55
|
+
Type: ${this.data.dataType}
|
|
56
|
+
`;
|
|
57
|
+
}
|
|
58
|
+
static getUIData() {
|
|
59
|
+
return {
|
|
60
|
+
infoBoxBody: 'Stores a portable JSON value in the current root run and, when the host supplies persistence, across later runs.',
|
|
61
|
+
infoBoxTitle: 'Set Stored Value Node',
|
|
62
|
+
contextMenuTitle: 'Set Stored Value',
|
|
63
|
+
group: ['Advanced'],
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
async process(inputs, context) {
|
|
67
|
+
const inputValue = inputs['value'];
|
|
68
|
+
if (!inputValue)
|
|
69
|
+
throw new Error('Missing stored value');
|
|
70
|
+
const key = this.data.useKeyInput ? coerceType(inputs['key'], 'string') : this.data.key;
|
|
71
|
+
const coercedValue = this.data.dataType === 'any' ? unwrapDataValue(inputValue).value : coerceType(inputValue, this.data.dataType);
|
|
72
|
+
const storedValue = cloneRivetStoredValue(coercedValue, 'Stored Value node input');
|
|
73
|
+
const result = await context.setStoredValue(key, storedValue);
|
|
74
|
+
return {
|
|
75
|
+
['saved-value']: storedValueToDataValue(result.savedValue, this.data.dataType),
|
|
76
|
+
['previous-value']: result.hadPreviousValue
|
|
77
|
+
? storedValueToDataValue(result.previousValue, this.data.dataType)
|
|
78
|
+
: missingStoredValueDataValue(this.data.dataType),
|
|
79
|
+
['had-previous-value']: { type: 'boolean', value: result.hadPreviousValue },
|
|
80
|
+
['key']: { type: 'string', value: key },
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export const setStoredValueNode = nodeDefinition(SetStoredValueNodeImpl, 'Set Stored Value');
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { nanoid } from 'nanoid/non-secure';
|
|
2
|
+
import { dedent } from 'ts-dedent';
|
|
3
|
+
import {} from '../NodeBase.js';
|
|
4
|
+
import { nodeDefinition } from '../NodeDefinition.js';
|
|
5
|
+
import { NodeImpl } from '../NodeImpl.js';
|
|
6
|
+
import { getNextVariadicPortIndex } from './variadicPortIndex.js';
|
|
7
|
+
export class StartBackgroundBranchNodeImpl extends NodeImpl {
|
|
8
|
+
static create = () => ({
|
|
9
|
+
type: 'startBackgroundBranch',
|
|
10
|
+
title: 'Start Async Branch',
|
|
11
|
+
id: nanoid(),
|
|
12
|
+
data: {},
|
|
13
|
+
visualData: {
|
|
14
|
+
x: 0,
|
|
15
|
+
y: 0,
|
|
16
|
+
width: 200,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
getInputDefinitions(connections) {
|
|
20
|
+
const inputCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'input', 'decimal');
|
|
21
|
+
return Array.from({ length: inputCount }, (_, index) => ({
|
|
22
|
+
dataType: 'any',
|
|
23
|
+
id: `input${index + 1}`,
|
|
24
|
+
title: `Async Input ${index + 1}`,
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
getOutputDefinitions(connections) {
|
|
28
|
+
const inputCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'input', 'decimal');
|
|
29
|
+
return Array.from({ length: Math.max(0, inputCount - 1) }, (_, index) => ({
|
|
30
|
+
dataType: 'any',
|
|
31
|
+
id: `output${index + 1}`,
|
|
32
|
+
title: `Async Output ${index + 1}`,
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
static getUIData() {
|
|
36
|
+
return {
|
|
37
|
+
infoBoxBody: dedent `
|
|
38
|
+
Starts its downstream branch asynchronously. The foreground graph continues immediately, while the root run waits for the async branch before it ends.
|
|
39
|
+
`,
|
|
40
|
+
infoBoxTitle: 'Start Async Branch Node',
|
|
41
|
+
contextMenuTitle: 'Start Async Branch',
|
|
42
|
+
group: ['Logic'],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
getBody() {
|
|
46
|
+
return 'Starts downstream asynchronously; the root run still waits';
|
|
47
|
+
}
|
|
48
|
+
async process(inputData) {
|
|
49
|
+
const outputs = {};
|
|
50
|
+
for (const [inputId, value] of Object.entries(inputData)) {
|
|
51
|
+
const match = /^input([1-9]\d*)$/.exec(inputId);
|
|
52
|
+
if (match && value != null) {
|
|
53
|
+
outputs[`output${match[1]}`] = value;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return outputs;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export const startBackgroundBranchNode = nodeDefinition(StartBackgroundBranchNodeImpl, 'Start Async Branch');
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { getDefaultValue, getScalarTypeOf, isArrayDataType, } from '../DataValue.js';
|
|
2
|
+
export const portableStoredValueScalarTypes = [
|
|
3
|
+
'any',
|
|
4
|
+
'boolean',
|
|
5
|
+
'string',
|
|
6
|
+
'number',
|
|
7
|
+
'date',
|
|
8
|
+
'time',
|
|
9
|
+
'datetime',
|
|
10
|
+
'object',
|
|
11
|
+
'vector',
|
|
12
|
+
];
|
|
13
|
+
export function storedValueToDataValue(value, dataType) {
|
|
14
|
+
const outputValue = isStoredValueCompatibleWithDataType(value, dataType) ? value : getDefaultValue(dataType);
|
|
15
|
+
return { type: dataType, value: outputValue };
|
|
16
|
+
}
|
|
17
|
+
export function missingStoredValueDataValue(dataType) {
|
|
18
|
+
return { type: dataType, value: getDefaultValue(dataType) };
|
|
19
|
+
}
|
|
20
|
+
function isStoredValueCompatibleWithDataType(value, dataType) {
|
|
21
|
+
if (isArrayDataType(dataType)) {
|
|
22
|
+
return (Array.isArray(value) &&
|
|
23
|
+
value.every((item) => isStoredValueCompatibleWithScalarType(item, getScalarTypeOf(dataType))));
|
|
24
|
+
}
|
|
25
|
+
return isStoredValueCompatibleWithScalarType(value, dataType);
|
|
26
|
+
}
|
|
27
|
+
function isStoredValueCompatibleWithScalarType(value, dataType) {
|
|
28
|
+
switch (dataType) {
|
|
29
|
+
case 'any':
|
|
30
|
+
return true;
|
|
31
|
+
case 'boolean':
|
|
32
|
+
return typeof value === 'boolean';
|
|
33
|
+
case 'string':
|
|
34
|
+
case 'date':
|
|
35
|
+
case 'time':
|
|
36
|
+
case 'datetime':
|
|
37
|
+
return typeof value === 'string';
|
|
38
|
+
case 'number':
|
|
39
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
40
|
+
case 'object':
|
|
41
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
42
|
+
case 'vector':
|
|
43
|
+
return Array.isArray(value) && value.every((item) => typeof item === 'number' && Number.isFinite(item));
|
|
44
|
+
default:
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -19,6 +19,44 @@ export function isDelegatedToolCallRecord(input) {
|
|
|
19
19
|
typeof maybeMessage.name === 'string' &&
|
|
20
20
|
(maybeMessage.toolName == null || typeof maybeMessage.toolName === 'string'));
|
|
21
21
|
}
|
|
22
|
+
export function buildDelegatedToolCallOutputs(records, preToolMessage, cost) {
|
|
23
|
+
const preToolMessageOutput = preToolMessage == null
|
|
24
|
+
? {
|
|
25
|
+
type: 'control-flow-excluded',
|
|
26
|
+
value: undefined,
|
|
27
|
+
}
|
|
28
|
+
: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
value: preToolMessage,
|
|
31
|
+
};
|
|
32
|
+
const outputs = records.length === 1
|
|
33
|
+
? {
|
|
34
|
+
['output']: {
|
|
35
|
+
type: 'string',
|
|
36
|
+
value: records[0].output,
|
|
37
|
+
},
|
|
38
|
+
['message']: {
|
|
39
|
+
type: 'chat-message',
|
|
40
|
+
value: records[0].message,
|
|
41
|
+
},
|
|
42
|
+
['assistant-message']: preToolMessageOutput,
|
|
43
|
+
}
|
|
44
|
+
: {
|
|
45
|
+
['output']: {
|
|
46
|
+
type: 'string[]',
|
|
47
|
+
value: records.map((record) => record.output),
|
|
48
|
+
},
|
|
49
|
+
['message']: {
|
|
50
|
+
type: 'chat-message[]',
|
|
51
|
+
value: records.map((record) => record.message),
|
|
52
|
+
},
|
|
53
|
+
['assistant-message']: preToolMessageOutput,
|
|
54
|
+
};
|
|
55
|
+
if (cost != null) {
|
|
56
|
+
outputs['cost'] = { type: 'number', value: cost };
|
|
57
|
+
}
|
|
58
|
+
return outputs;
|
|
59
|
+
}
|
|
22
60
|
export function normalizeFunctionCallInput(input) {
|
|
23
61
|
if (Array.isArray(input)) {
|
|
24
62
|
if (input.length !== 1) {
|
|
@@ -84,7 +122,9 @@ export async function delegateToolCall(rawFunctionCall, context, config) {
|
|
|
84
122
|
const functionCall = normalizeFunctionCallInput(rawFunctionCall);
|
|
85
123
|
let handler;
|
|
86
124
|
if (config.autoDelegate) {
|
|
87
|
-
const
|
|
125
|
+
const graphs = Object.values(context.project.graphs);
|
|
126
|
+
const matchingGraph = graphs.find((graph) => graph.metadata?.name === functionCall.name) ??
|
|
127
|
+
graphs.find((graph) => graph.metadata?.name?.includes(functionCall.name));
|
|
88
128
|
if (matchingGraph) {
|
|
89
129
|
handler = { key: undefined, value: matchingGraph.metadata.id };
|
|
90
130
|
}
|
|
@@ -104,6 +144,7 @@ export async function delegateToolCall(rawFunctionCall, context, config) {
|
|
|
104
144
|
outputString,
|
|
105
145
|
message: buildToolResultMessage(functionCall, outputString),
|
|
106
146
|
record: buildDelegatedToolCallRecord(functionCall, outputString),
|
|
147
|
+
cost: result.cost,
|
|
107
148
|
};
|
|
108
149
|
}
|
|
109
150
|
catch (error) {
|
|
@@ -151,9 +192,11 @@ export async function delegateToolCall(rawFunctionCall, context, config) {
|
|
|
151
192
|
const subprocessor = context.createSubProcessor(handler.value, { signal: context.signal });
|
|
152
193
|
const outputs = await subprocessor.processGraph(context, subgraphInputs, context.contextValues);
|
|
153
194
|
const outputString = coerceTypeOptional(outputs['output'], 'string') ?? '';
|
|
195
|
+
const cost = coerceTypeOptional(outputs['cost'], 'number');
|
|
154
196
|
return {
|
|
155
197
|
outputString,
|
|
156
198
|
message: buildToolResultMessage(functionCall, outputString),
|
|
157
199
|
record: buildDelegatedToolCallRecord(functionCall, outputString),
|
|
200
|
+
cost,
|
|
158
201
|
};
|
|
159
202
|
}
|
|
@@ -19,6 +19,7 @@ function withDuration(base, durationMs, splitRunDurationMs) {
|
|
|
19
19
|
const toRecordedEventMap = {
|
|
20
20
|
graphStart: ({ graph, inputs, execution }) => withExecution({ graphId: graph.metadata.id, inputs }, execution),
|
|
21
21
|
graphFinish: ({ graph, outputs, execution }) => withExecution({ graphId: graph.metadata.id, outputs }, execution),
|
|
22
|
+
graphOutputsReady: ({ graph, outputs, execution }) => withExecution({ graphId: graph.metadata.id, outputs }, execution),
|
|
22
23
|
graphError: ({ graph, error, execution }) => withExecution({
|
|
23
24
|
graphId: graph.metadata.id,
|
|
24
25
|
error: typeof error === 'string' ? error : error.stack,
|
|
@@ -243,6 +243,9 @@ function coerceToNumber(value) {
|
|
|
243
243
|
}
|
|
244
244
|
if (value.type === 'any' || value.type === 'object') {
|
|
245
245
|
const inferred = inferType(value.value);
|
|
246
|
+
if (inferred.type === 'any' || inferred.type === 'object') {
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
246
249
|
return coerceTypeOptional(inferred, 'number');
|
|
247
250
|
}
|
|
248
251
|
return undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { createUiGraphChatSubmissionStatePatch, getUiGraphActionState, getUiGraphChatDraftStateKey, } from './model/UiGraph.js';
|
|
2
|
-
export { applyUiGraphStatePatch, createUiGraphActionExecutionController, createUiGraphInteractionController, getUiGraphComponentRenderModel, getUiGraphJsonOutputFilename, } from './model/UiGraphRuntimeModel.js';
|
|
1
|
+
export { createUiGraphChatHistoryFlushStatePatch, createUiGraphChatPinStatePatch, createUiGraphChatSubmissionStatePatch, getUiGraphActionState, getUiGraphChatDraftStateKey, getUiGraphChatMessagesStateKey, } from './model/UiGraph.js';
|
|
2
|
+
export { applyUiGraphStatePatch, createUiGraphActionExecutionController, createUiGraphInteractionController, getUiGraphComponentRenderModel, getUiGraphJsonOutputFilename, getUiGraphProgressiveJsonOutputChunks, } from './model/UiGraphRuntimeModel.js';
|
|
3
3
|
export { parseRivetWebAppClientMessage, parseRivetWebAppServerMessage, RIVET_WEB_APP_ACTION_PROTOCOL_VERSION, } from './model/UiGraphActionProtocol.js';
|
|
4
|
-
export { copyUiGraphText, downloadUiGraphJsonOutput } from './model/UiGraphBrowserRuntime.js';
|
|
4
|
+
export { copyUiGraphText, applyUiGraphWebAppStorageActionPatch, applyUiGraphWebAppStoragePatch, clearUiGraphChatSearchMatches, downloadUiGraphJsonOutput, hasUiGraphChatPersistentStateChanged, getUiGraphChatPersistentState, getUiGraphChatStorageKey, getUiGraphWebAppStorageKey, highlightUiGraphChatSearchMatches, loadUiGraphChatPersistentState, loadUiGraphWebAppStorage, observeUiGraphOutputResizeBounds, revealUiGraphChatElement, revealUiGraphChatSearchMatch, saveUiGraphChatPersistentState, } from './model/UiGraphBrowserRuntime.js';
|