@valerypopoff/rivet2-core 2.1.3 → 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 +10138 -5679
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/cjs/webAppRuntime.cjs +1214 -0
- package/dist/cjs/webAppRuntime.cjs.map +7 -0
- package/dist/esm/api/createProcessor.js +8 -1
- package/dist/esm/api/streaming.js +6 -0
- package/dist/esm/exports.js +8 -0
- package/dist/esm/integrations/mcp/MCPBase.js +92 -34
- package/dist/esm/model/GraphBoundaryEffects.js +13 -0
- package/dist/esm/model/GraphProcessor.js +1138 -86
- package/dist/esm/model/GraphProgress.js +15 -0
- package/dist/esm/model/ManagedAsyncBranches.js +28 -0
- package/dist/esm/model/Nodes.js +12 -0
- package/dist/esm/model/ProcessContextBuilder.js +3 -1
- package/dist/esm/model/RecordingPlayer.js +19 -0
- package/dist/esm/model/StoredValueStore.js +226 -0
- package/dist/esm/model/SubprocessorBridge.js +50 -18
- package/dist/esm/model/ToolCallContinuation.js +1 -0
- package/dist/esm/model/UiGraph.js +177 -4
- package/dist/esm/model/UiGraphActionProtocol.js +131 -0
- package/dist/esm/model/UiGraphBindings.js +530 -0
- package/dist/esm/model/UiGraphBrowserRuntime.js +373 -0
- package/dist/esm/model/UiGraphNormalization.js +148 -0
- package/dist/esm/model/UiGraphRendererStyles.js +1108 -42
- package/dist/esm/model/UiGraphRuntimeModel.js +518 -2
- package/dist/esm/model/UiGraphSchema.js +91 -0
- package/dist/esm/model/UiGraphWebAppStatus.js +19 -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/ArrayNode.js +2 -13
- package/dist/esm/model/nodes/AssembleMessageNode.js +2 -13
- package/dist/esm/model/nodes/AssemblePromptNode.js +2 -13
- package/dist/esm/model/nodes/CoalesceNode.js +2 -15
- package/dist/esm/model/nodes/DelayNode.js +3 -14
- package/dist/esm/model/nodes/DelegateFunctionCallNode.js +12 -40
- package/dist/esm/model/nodes/DidRunNode.js +2 -13
- package/dist/esm/model/nodes/GetStoredValueNode.js +109 -0
- package/dist/esm/model/nodes/JoinNode.js +2 -13
- package/dist/esm/model/nodes/LLMChatV2Node.js +17 -1
- package/dist/esm/model/nodes/LoopControllerNode.js +3 -14
- package/dist/esm/model/nodes/MCPDiscoveryNode.js +19 -90
- package/dist/esm/model/nodes/MCPGetPromptNode.js +11 -97
- package/dist/esm/model/nodes/MCPToolCallNode.js +11 -97
- package/dist/esm/model/nodes/MatchNode.js +7 -7
- package/dist/esm/model/nodes/PassthroughNode.js +3 -14
- package/dist/esm/model/nodes/RaceInputsNode.js +2 -13
- package/dist/esm/model/nodes/ReportProgressNode.js +57 -0
- 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/model/nodes/variadicPortIndex.js +32 -0
- package/dist/esm/plugins/anthropic/anthropic.js +1 -1
- package/dist/esm/recording/ExecutionRecorder.js +6 -0
- package/dist/esm/utils/coerceType.js +3 -0
- package/dist/esm/utils/fetchEventSource.js +16 -17
- package/dist/esm/utils/serialization/serialization.js +4 -0
- package/dist/esm/utils/serialization/serializationUtils.js +8 -27
- package/dist/esm/utils/serialization/serialization_v4.js +3 -3
- package/dist/esm/webAppRuntime.js +4 -2
- package/dist/types/api/createProcessor.d.ts +4 -0
- package/dist/types/api/streaming.d.ts +6 -0
- package/dist/types/exports.d.ts +8 -0
- package/dist/types/integrations/mcp/MCPBase.d.ts +26 -3
- package/dist/types/model/EditorDefinition.d.ts +2 -1
- package/dist/types/model/ExecutorProtocol.d.ts +19 -0
- package/dist/types/model/GraphBoundaryEffects.d.ts +9 -1
- package/dist/types/model/GraphProcessor.d.ts +26 -2
- package/dist/types/model/GraphProgress.d.ts +6 -0
- package/dist/types/model/ManagedAsyncBranches.d.ts +6 -0
- package/dist/types/model/Nodes.d.ts +6 -2
- package/dist/types/model/ProcessContext.d.ts +18 -0
- package/dist/types/model/ProcessContextBuilder.d.ts +3 -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 +63 -9
- package/dist/types/model/UiGraphActionProtocol.d.ts +71 -0
- package/dist/types/model/UiGraphBindings.d.ts +45 -0
- package/dist/types/model/UiGraphBrowserRuntime.d.ts +55 -0
- package/dist/types/model/UiGraphNormalization.d.ts +24 -0
- package/dist/types/model/UiGraphRendererStyles.d.ts +2 -2
- package/dist/types/model/UiGraphRuntimeModel.d.ts +97 -6
- package/dist/types/model/UiGraphSchema.d.ts +113 -0
- package/dist/types/model/UiGraphWebAppStatus.d.ts +5 -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/ArrayNode.d.ts +0 -1
- package/dist/types/model/nodes/AssembleMessageNode.d.ts +0 -1
- package/dist/types/model/nodes/AssemblePromptNode.d.ts +0 -1
- package/dist/types/model/nodes/DelayNode.d.ts +0 -1
- package/dist/types/model/nodes/DidRunNode.d.ts +0 -1
- package/dist/types/model/nodes/GetStoredValueNode.d.ts +25 -0
- package/dist/types/model/nodes/JoinNode.d.ts +0 -1
- package/dist/types/model/nodes/LoopControllerNode.d.ts +0 -1
- package/dist/types/model/nodes/PassthroughNode.d.ts +0 -1
- package/dist/types/model/nodes/RaceInputsNode.d.ts +0 -1
- package/dist/types/model/nodes/ReportProgressNode.d.ts +23 -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/model/nodes/variadicPortIndex.d.ts +4 -0
- package/dist/types/recording/RecordedEvents.d.ts +10 -0
- package/dist/types/webAppRuntime.d.ts +8 -3
- package/package.json +2 -2
- package/dist/esm/plugins/anthropic/fetchEventSource.js +0 -107
- package/dist/types/plugins/anthropic/fetchEventSource.d.ts +0 -11
|
@@ -4,6 +4,7 @@ import {} from '../NodeBase.js';
|
|
|
4
4
|
import { nanoid } from 'nanoid/non-secure';
|
|
5
5
|
import {} from '../GraphProcessor.js';
|
|
6
6
|
import { dedent } from 'ts-dedent';
|
|
7
|
+
import { getNextVariadicPortIndex } from './variadicPortIndex.js';
|
|
7
8
|
export class PassthroughNodeImpl extends NodeImpl {
|
|
8
9
|
static create = () => {
|
|
9
10
|
const chartNode = {
|
|
@@ -21,7 +22,7 @@ export class PassthroughNodeImpl extends NodeImpl {
|
|
|
21
22
|
};
|
|
22
23
|
getInputDefinitions(connections) {
|
|
23
24
|
const inputs = [];
|
|
24
|
-
const inputCount =
|
|
25
|
+
const inputCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'input', 'decimal');
|
|
25
26
|
for (let i = 1; i <= inputCount; i++) {
|
|
26
27
|
inputs.push({
|
|
27
28
|
dataType: 'any',
|
|
@@ -33,7 +34,7 @@ export class PassthroughNodeImpl extends NodeImpl {
|
|
|
33
34
|
}
|
|
34
35
|
getOutputDefinitions(connections) {
|
|
35
36
|
const outputs = [];
|
|
36
|
-
const inputCount =
|
|
37
|
+
const inputCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'input', 'decimal');
|
|
37
38
|
for (let i = 1; i <= inputCount - 1; i++) {
|
|
38
39
|
outputs.push({
|
|
39
40
|
dataType: 'any',
|
|
@@ -53,18 +54,6 @@ export class PassthroughNodeImpl extends NodeImpl {
|
|
|
53
54
|
group: ['Logic'],
|
|
54
55
|
};
|
|
55
56
|
}
|
|
56
|
-
#getInputPortCount(connections) {
|
|
57
|
-
const inputNodeId = this.chartNode.id;
|
|
58
|
-
const inputConnections = connections.filter((connection) => connection.inputNodeId === inputNodeId && connection.inputId.startsWith('input'));
|
|
59
|
-
let maxInputNumber = 0;
|
|
60
|
-
for (const connection of inputConnections) {
|
|
61
|
-
const messageNumber = parseInt(connection.inputId.replace('input', ''), 10);
|
|
62
|
-
if (messageNumber > maxInputNumber) {
|
|
63
|
-
maxInputNumber = messageNumber;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return maxInputNumber + 1;
|
|
67
|
-
}
|
|
68
57
|
async process(inputData) {
|
|
69
58
|
const inputCount = Object.keys(inputData).filter((key) => key.startsWith('input')).length;
|
|
70
59
|
const outputs = {};
|
|
@@ -5,6 +5,7 @@ import { nodeDefinition } from '../NodeDefinition.js';
|
|
|
5
5
|
import {} from '../GraphProcessor.js';
|
|
6
6
|
import { dedent } from 'ts-dedent';
|
|
7
7
|
import {} from '../../index.js';
|
|
8
|
+
import { getNextVariadicPortIndex } from './variadicPortIndex.js';
|
|
8
9
|
export class RaceInputsNodeImpl extends NodeImpl {
|
|
9
10
|
static create() {
|
|
10
11
|
const chartNode = {
|
|
@@ -20,21 +21,9 @@ export class RaceInputsNodeImpl extends NodeImpl {
|
|
|
20
21
|
};
|
|
21
22
|
return chartNode;
|
|
22
23
|
}
|
|
23
|
-
#getInputPortCount(connections) {
|
|
24
|
-
const inputNodeId = this.chartNode.id;
|
|
25
|
-
const inputConnections = connections.filter((connection) => connection.inputNodeId === inputNodeId && connection.inputId.startsWith('input'));
|
|
26
|
-
let maxInputNumber = 0;
|
|
27
|
-
for (const connection of inputConnections) {
|
|
28
|
-
const messageNumber = parseInt(connection.inputId.replace('input', ''), 10);
|
|
29
|
-
if (messageNumber > maxInputNumber) {
|
|
30
|
-
maxInputNumber = messageNumber;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return maxInputNumber + 1;
|
|
34
|
-
}
|
|
35
24
|
getInputDefinitions(connections) {
|
|
36
25
|
const inputs = [];
|
|
37
|
-
const inputCount =
|
|
26
|
+
const inputCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'input', 'decimal');
|
|
38
27
|
for (let i = 1; i <= inputCount; i++) {
|
|
39
28
|
inputs.push({
|
|
40
29
|
dataType: 'any',
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { nanoid } from 'nanoid/non-secure';
|
|
2
|
+
import { coerceTypeOptional } from '../../utils/coerceType.js';
|
|
3
|
+
import { nodeDefinition } from '../NodeDefinition.js';
|
|
4
|
+
import { NodeImpl } from '../NodeImpl.js';
|
|
5
|
+
export class ReportProgressNodeImpl extends NodeImpl {
|
|
6
|
+
static create() {
|
|
7
|
+
return {
|
|
8
|
+
id: nanoid(),
|
|
9
|
+
type: 'reportProgress',
|
|
10
|
+
title: 'Report Progress',
|
|
11
|
+
visualData: { x: 0, y: 0, width: 200 },
|
|
12
|
+
data: { message: '', useMessageInput: true, usePercentInput: true },
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
getInputDefinitions() {
|
|
16
|
+
return [
|
|
17
|
+
{ dataType: 'any', id: 'value', required: true, title: 'Value' },
|
|
18
|
+
...(this.data.useMessageInput
|
|
19
|
+
? [{ dataType: 'string', id: 'message', title: 'Message' }]
|
|
20
|
+
: []),
|
|
21
|
+
...(this.data.usePercentInput
|
|
22
|
+
? [{ dataType: 'number', id: 'percent', title: 'Percent' }]
|
|
23
|
+
: []),
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
getOutputDefinitions() {
|
|
27
|
+
return [{ dataType: 'any', id: 'value', title: 'Value' }];
|
|
28
|
+
}
|
|
29
|
+
getEditors() {
|
|
30
|
+
return [
|
|
31
|
+
{ type: 'string', label: 'Message', dataKey: 'message', useInputToggleDataKey: 'useMessageInput' },
|
|
32
|
+
{ type: 'number', label: 'Percent', dataKey: 'percent', useInputToggleDataKey: 'usePercentInput' },
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
getBody() {
|
|
36
|
+
return this.data.message || 'Reports progress to the host';
|
|
37
|
+
}
|
|
38
|
+
static getUIData() {
|
|
39
|
+
return {
|
|
40
|
+
contextMenuTitle: 'Report Progress',
|
|
41
|
+
group: ['Advanced'],
|
|
42
|
+
infoBoxTitle: 'Report Progress',
|
|
43
|
+
infoBoxBody: 'Reports a public status message and/or percentage to progress-aware hosts such as Rivet web apps.',
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
async process(inputs, context) {
|
|
47
|
+
const message = this.data.useMessageInput
|
|
48
|
+
? coerceTypeOptional(inputs['message'], 'string')
|
|
49
|
+
: this.data.message;
|
|
50
|
+
const percent = this.data.usePercentInput
|
|
51
|
+
? coerceTypeOptional(inputs['percent'], 'number')
|
|
52
|
+
: this.data.percent;
|
|
53
|
+
context.reportProgress({ message, percent });
|
|
54
|
+
return { value: inputs['value'] };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export const reportProgressNode = nodeDefinition(ReportProgressNodeImpl, 'Report Progress');
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function getHighestVariadicPortIndex(connections, inputNodeId, prefix, policy) {
|
|
2
|
+
let highestIndex = 0;
|
|
3
|
+
for (const connection of connections) {
|
|
4
|
+
if (connection.inputNodeId !== inputNodeId || !connection.inputId.startsWith(prefix)) {
|
|
5
|
+
continue;
|
|
6
|
+
}
|
|
7
|
+
const index = parseVariadicPortIndex(connection.inputId, prefix, policy);
|
|
8
|
+
if (index != null && index > highestIndex) {
|
|
9
|
+
highestIndex = index;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return highestIndex;
|
|
13
|
+
}
|
|
14
|
+
export function getNextVariadicPortIndex(connections, inputNodeId, prefix, policy) {
|
|
15
|
+
return getHighestVariadicPortIndex(connections, inputNodeId, prefix, policy) + 1;
|
|
16
|
+
}
|
|
17
|
+
function parseVariadicPortIndex(portId, prefix, policy) {
|
|
18
|
+
if (policy === 'legacy') {
|
|
19
|
+
const index = parseInt(portId.replace(prefix, ''));
|
|
20
|
+
return Number.isNaN(index) ? undefined : index;
|
|
21
|
+
}
|
|
22
|
+
if (policy === 'decimal') {
|
|
23
|
+
const index = parseInt(portId.replace(prefix, ''), 10);
|
|
24
|
+
return Number.isNaN(index) ? undefined : index;
|
|
25
|
+
}
|
|
26
|
+
const indexText = portId.slice(prefix.length);
|
|
27
|
+
if (!/^\d+$/.test(indexText)) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const index = Number(indexText);
|
|
31
|
+
return Number.isSafeInteger(index) && index > 0 ? index : undefined;
|
|
32
|
+
}
|
|
@@ -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,
|
|
@@ -65,6 +66,11 @@ const toRecordedEventMap = {
|
|
|
65
66
|
index,
|
|
66
67
|
processId,
|
|
67
68
|
}, execution),
|
|
69
|
+
progress: ({ node, processId, progress, execution }) => withExecution({
|
|
70
|
+
nodeId: node.id,
|
|
71
|
+
processId,
|
|
72
|
+
progress,
|
|
73
|
+
}, execution),
|
|
68
74
|
nodeOutputsCleared: ({ node, processId, execution }) => withExecution({
|
|
69
75
|
nodeId: node.id,
|
|
70
76
|
processId,
|
|
@@ -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;
|
|
@@ -47,28 +47,27 @@ export class EventSourceResponse extends Response {
|
|
|
47
47
|
}
|
|
48
48
|
async raceWithTimeout(promise, timeout) {
|
|
49
49
|
const raceTimeout = timeout ?? DEFAULT_CHAT_NODE_TIMEOUT;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
let timer;
|
|
51
|
+
try {
|
|
52
|
+
return await Promise.race([
|
|
53
|
+
promise,
|
|
54
|
+
new Promise((_resolve, reject) => {
|
|
55
|
+
timer = setTimeout(() => {
|
|
56
|
+
reject(new Error('Timeout: API response took too long.'));
|
|
57
|
+
}, raceTimeout);
|
|
58
|
+
}),
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
if (timer != null) {
|
|
61
63
|
clearTimeout(timer);
|
|
62
|
-
reject(error);
|
|
63
64
|
}
|
|
64
|
-
}
|
|
65
|
+
}
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
export default async function fetchEventSource(url, init, timeout) {
|
|
68
|
-
const headers =
|
|
69
|
-
|
|
70
|
-
accept: 'text/event-stream',
|
|
71
|
-
};
|
|
69
|
+
const headers = new Headers(init?.headers);
|
|
70
|
+
headers.set('accept', 'text/event-stream');
|
|
72
71
|
const response = await fetch(url, {
|
|
73
72
|
...init,
|
|
74
73
|
headers,
|
|
@@ -4,6 +4,7 @@ import { graphV3Deserializer, projectV3Deserializer } from './serialization_v3.j
|
|
|
4
4
|
import { getError } from '../errors.js';
|
|
5
5
|
import { yamlProblem } from './serializationUtils.js';
|
|
6
6
|
import { prepareSerializedInput } from './serializationInput.js';
|
|
7
|
+
import { UiGraphNormalizationError } from '../../model/UiGraphNormalization.js';
|
|
7
8
|
import { datasetV4Deserializer, datasetV4Serializer, graphV4Deserializer, graphV4Serializer, projectV4Deserializer, projectV4Serializer, } from './serialization_v4.js';
|
|
8
9
|
import { graphV2Deserializer, projectV2Deserializer } from './serialization_v2.js';
|
|
9
10
|
import { graphV1Deserializer, projectV1Deserializer } from './serialization_v1.js';
|
|
@@ -26,6 +27,9 @@ export function deserializeProject(serializedProject, path = null) {
|
|
|
26
27
|
yamlProblem(err);
|
|
27
28
|
}
|
|
28
29
|
console.warn(`Failed to deserialize project v${version}: ${errMessage(err)}`);
|
|
30
|
+
if (err instanceof UiGraphNormalizationError) {
|
|
31
|
+
throw new Error(`Could not deserialize project: ${err.message}`, { cause: err });
|
|
32
|
+
}
|
|
29
33
|
throw new Error('Could not deserialize project');
|
|
30
34
|
}
|
|
31
35
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { formatUiGraphNormalizationIssue, normalizeUiGraphRecord, UiGraphNormalizationError, } from '../../model/UiGraphNormalization.js';
|
|
1
2
|
import { prepareSerializedInput } from './serializationInput.js';
|
|
2
3
|
/** Validates a deserialized project structure. Returns errors for structural problems. */
|
|
3
4
|
export function validateProject(project) {
|
|
@@ -69,35 +70,15 @@ export function validateProject(project) {
|
|
|
69
70
|
return { valid: errors.length === 0, errors, warnings };
|
|
70
71
|
}
|
|
71
72
|
function validateUiGraphs(uiGraphs, errors) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return;
|
|
73
|
+
try {
|
|
74
|
+
normalizeUiGraphRecord(uiGraphs, { repairComponentIds: false });
|
|
75
75
|
}
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
errors.push(
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
const components = uiGraph.components;
|
|
82
|
-
if (!Array.isArray(components)) {
|
|
83
|
-
errors.push(`UI graph "${uiGraphId}" components is not an array`);
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
const componentIds = new Set();
|
|
87
|
-
for (const [index, component] of components.entries()) {
|
|
88
|
-
const componentId = component && typeof component === 'object' && !Array.isArray(component)
|
|
89
|
-
? component.id
|
|
90
|
-
: undefined;
|
|
91
|
-
if (typeof componentId !== 'string' || !componentId.trim()) {
|
|
92
|
-
errors.push(`UI graph "${uiGraphId}" component at index ${index} missing id`);
|
|
93
|
-
}
|
|
94
|
-
else if (componentIds.has(componentId)) {
|
|
95
|
-
errors.push(`UI graph "${uiGraphId}" component "${componentId}" has a duplicate id`);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
componentIds.add(componentId);
|
|
99
|
-
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (error instanceof UiGraphNormalizationError) {
|
|
78
|
+
errors.push(...error.issues.map(formatUiGraphNormalizationIssue));
|
|
79
|
+
return;
|
|
100
80
|
}
|
|
81
|
+
throw error;
|
|
101
82
|
}
|
|
102
83
|
}
|
|
103
84
|
/** Quick structural check - throws on invalid project. */
|
|
@@ -2,7 +2,7 @@ import { mapValues } from 'lodash-es';
|
|
|
2
2
|
import { doubleCheckProject } from './serializationUtils.js';
|
|
3
3
|
import { entries } from '../typeSafety.js';
|
|
4
4
|
import {} from '../../model/Project.js';
|
|
5
|
-
import {
|
|
5
|
+
import { normalizeUiGraphRecord } from '../../model/UiGraphNormalization.js';
|
|
6
6
|
import { serializeConnection, deserializeConnection, parseVisualData, packVisualDataV4, wrapInYamlEnvelope, unwrapYamlEnvelope, } from './serializationHelpers.js';
|
|
7
7
|
export function projectV4Deserializer(data) {
|
|
8
8
|
const serializedProject = unwrapYamlEnvelope(data, 4, 'Project v4');
|
|
@@ -32,7 +32,7 @@ function toSerializedProject(project, attachedData) {
|
|
|
32
32
|
id: prefab.id,
|
|
33
33
|
sourceNode: toSerializedIsolatedNode(prefab.sourceNode),
|
|
34
34
|
}));
|
|
35
|
-
const uiGraphs =
|
|
35
|
+
const uiGraphs = normalizeUiGraphRecord(project.uiGraphs === undefined ? {} : project.uiGraphs);
|
|
36
36
|
return {
|
|
37
37
|
metadata: project.metadata,
|
|
38
38
|
graphs: mapValues(project.graphs, (graph) => toSerializedGraph(graph)),
|
|
@@ -48,7 +48,7 @@ function fromSerializedProject(serializedProject) {
|
|
|
48
48
|
id: prefab.id,
|
|
49
49
|
sourceNode: fromSerializedIsolatedNode(prefab.sourceNode),
|
|
50
50
|
}));
|
|
51
|
-
const uiGraphs =
|
|
51
|
+
const uiGraphs = normalizeUiGraphRecord(serializedProject.uiGraphs === undefined ? {} : serializedProject.uiGraphs);
|
|
52
52
|
return [
|
|
53
53
|
{
|
|
54
54
|
metadata: serializedProject.metadata,
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export { getUiGraphActionState } from './model/UiGraph.js';
|
|
2
|
-
export { applyUiGraphStatePatch, 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
|
+
export { parseRivetWebAppClientMessage, parseRivetWebAppServerMessage, RIVET_WEB_APP_ACTION_PROTOCOL_VERSION, } from './model/UiGraphActionProtocol.js';
|
|
4
|
+
export { copyUiGraphText, applyUiGraphWebAppStorageActionPatch, applyUiGraphWebAppStoragePatch, clearUiGraphChatSearchMatches, downloadUiGraphJsonOutput, hasUiGraphChatPersistentStateChanged, getUiGraphChatPersistentState, getUiGraphChatStorageKey, getUiGraphWebAppStorageKey, highlightUiGraphChatSearchMatches, loadUiGraphChatPersistentState, loadUiGraphWebAppStorage, observeUiGraphOutputResizeBounds, revealUiGraphChatElement, revealUiGraphChatSearchMatch, saveUiGraphChatPersistentState, } from './model/UiGraphBrowserRuntime.js';
|
|
@@ -15,6 +15,7 @@ import { GraphProcessor } from '../model/GraphProcessor.js';
|
|
|
15
15
|
import type { Tokenizer } from '../integrations/Tokenizer.js';
|
|
16
16
|
import { type LooseDataValue } from './looseDataValue.js';
|
|
17
17
|
import type { ProjectReferenceLoader } from '../model/ProjectReferenceLoader.js';
|
|
18
|
+
import type { RivetStoredValueStore } from '../model/StoredValueStore.js';
|
|
18
19
|
export type RunGraphOptions = {
|
|
19
20
|
graph?: string;
|
|
20
21
|
inputs?: Record<string, LooseDataValue>;
|
|
@@ -40,6 +41,9 @@ export type RunGraphOptions = {
|
|
|
40
41
|
projectPath?: string;
|
|
41
42
|
projectReferenceLoader?: ProjectReferenceLoader;
|
|
42
43
|
editorExecutionCache?: ProcessContext['editorExecutionCache'];
|
|
44
|
+
storedValueStore?: RivetStoredValueStore;
|
|
45
|
+
/** Return root graph outputs before managed async branches settle. */
|
|
46
|
+
returnWhenGraphOutputsReady?: boolean;
|
|
43
47
|
} & {
|
|
44
48
|
[P in keyof ProcessEvents as `on${PascalCase<P>}`]?: (params: ProcessEvents[P]) => void;
|
|
45
49
|
} & Settings & Record<string, unknown>;
|
|
@@ -10,6 +10,8 @@ export type RivetEventStreamFilterSpec = {
|
|
|
10
10
|
nodeStart?: string[] | true;
|
|
11
11
|
/** Stream node finish events for the specified nodeIDs or node titles. */
|
|
12
12
|
nodeFinish?: string[] | true;
|
|
13
|
+
/** Stream application-level progress reports emitted by graph nodes. */
|
|
14
|
+
progress?: boolean;
|
|
13
15
|
};
|
|
14
16
|
/** Map of all possible event names to their data for streaming events. */
|
|
15
17
|
export type RivetEventStreamEvent = {
|
|
@@ -30,6 +32,10 @@ export type RivetEventStreamEvent = {
|
|
|
30
32
|
outputs: Outputs;
|
|
31
33
|
durationMs?: number;
|
|
32
34
|
};
|
|
35
|
+
progress: {
|
|
36
|
+
message?: string;
|
|
37
|
+
percent?: number;
|
|
38
|
+
};
|
|
33
39
|
done: {
|
|
34
40
|
graphOutput: GraphOutputs;
|
|
35
41
|
};
|