@valerypopoff/rivet2-core 2.1.9 → 2.3.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/README.md +1 -1
- package/dist/cjs/bundle.cjs +5618 -2533
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/cjs/webAppRuntime.cjs +333 -22
- package/dist/cjs/webAppRuntime.cjs.map +4 -4
- package/dist/esm/api/createProcessor.js +2 -0
- package/dist/esm/exports.js +1 -0
- package/dist/esm/integrations/CodeRunner.js +2 -7
- package/dist/esm/integrations/CodeRunnerOptions.js +7 -0
- package/dist/esm/model/AgentResponseTrace.js +558 -0
- package/dist/esm/model/ConnectedToolContinuationHost.js +33 -0
- package/dist/esm/model/GraphProcessor.js +165 -74
- package/dist/esm/model/NodeImpl.js +6 -0
- package/dist/esm/model/ProcessContextBuilder.js +3 -1
- package/dist/esm/model/RecordingPlayer.js +212 -25
- package/dist/esm/model/SplitRunProcessor.js +49 -8
- package/dist/esm/model/SubprocessorBridge.js +3 -0
- package/dist/esm/model/ToolCallContinuationCoordinator.js +7 -3
- package/dist/esm/model/UiGraph.js +21 -0
- package/dist/esm/model/UiGraphActionProtocol.js +3 -0
- package/dist/esm/model/UiGraphBrowserRuntime.js +133 -4
- package/dist/esm/model/UiGraphRendererStyles.js +221 -0
- package/dist/esm/model/UiGraphRuntimeModel.js +9 -3
- package/dist/esm/model/UiGraphSchema.js +7 -1
- package/dist/esm/model/chat/aiSdkTools.js +3 -2
- package/dist/esm/model/chat-v2/aiSdkBridge.js +146 -14
- package/dist/esm/model/chat-v2/chatV2CallObserver.js +11 -5
- package/dist/esm/model/chat-v2/chatV2CredentialNames.js +93 -0
- package/dist/esm/model/chat-v2/chatV2EditorCache.js +47 -20
- package/dist/esm/model/chat-v2/chatV2Errors.js +7 -19
- package/dist/esm/model/chat-v2/chatV2FeatureCompatibility.js +1 -1
- package/dist/esm/model/chat-v2/chatV2Outputs.js +48 -108
- package/dist/esm/model/chat-v2/chatV2Pipeline.js +101 -149
- package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +39 -4
- package/dist/esm/model/chat-v2/chatV2ProviderRegistry.js +9 -0
- package/dist/esm/model/chat-v2/chatV2RequestPlan.js +2 -3
- package/dist/esm/model/chat-v2/chatV2ResponseBodyCapture.js +63 -0
- package/dist/esm/model/chat-v2/chatV2ResponseFormat.js +8 -4
- package/dist/esm/model/chat-v2/chatV2Retry.js +4 -3
- package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +7 -7
- package/dist/esm/model/chat-v2/chatV2Shared.js +1 -1
- package/dist/esm/model/chat-v2/chatV2Types.js +20 -8
- package/dist/esm/model/chat-v2/chatV2UsageAccounting.js +78 -0
- package/dist/esm/model/chat-v2/customProviderApi.js +40 -0
- package/dist/esm/model/chat-v2/index.js +15 -0
- package/dist/esm/model/chat-v2/llmChatV2Body.js +289 -0
- package/dist/esm/model/chat-v2/llmChatV2CacheBoundary.js +32 -0
- package/dist/esm/model/chat-v2/llmChatV2CachePolicy.js +25 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeData.js +13 -50
- package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +117 -24
- package/dist/esm/model/chat-v2/llmChatV2NodeMigration.js +24 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +150 -199
- package/dist/esm/model/chat-v2/llmInvocationCoordinator.js +60 -0
- package/dist/esm/model/chat-v2/llmInvocationDecision.js +11 -0
- package/dist/esm/model/chat-v2/llmInvocationJournal.js +43 -0
- package/dist/esm/model/chat-v2/llmInvocationPlan.js +68 -0
- package/dist/esm/model/chat-v2/llmInvocationProjections.js +5 -0
- package/dist/esm/model/chat-v2/llmInvocationResultProjector.js +48 -0
- package/dist/esm/model/chat-v2/llmModelCandidate.js +79 -0
- package/dist/esm/model/chat-v2/llmProfile.js +52 -65
- package/dist/esm/model/chat-v2/llmProfileBody.js +193 -0
- package/dist/esm/model/chat-v2/llmProfileFallback.js +442 -100
- package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +74 -0
- package/dist/esm/model/chat-v2/llmProfileHealthStore.js +326 -0
- package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +55 -33
- package/dist/esm/model/chat-v2/llmProfileTypes.js +1 -18
- package/dist/esm/model/chat-v2/llmResponseMaterializer.js +42 -0
- package/dist/esm/model/chat-v2/modelRegistry.js +54 -4
- package/dist/esm/model/chat-v2/parallelToolCalls.js +9 -2
- package/dist/esm/model/chat-v2/providerOptions.js +116 -24
- package/dist/esm/model/chat-v2/rivetToolRegistry.js +9 -0
- package/dist/esm/model/chat-v2/toolCallCodec.js +52 -0
- package/dist/esm/model/chat-v2/toolContinuation.js +72 -35
- package/dist/esm/model/chat-v2/toolHandlerResolver.js +23 -0
- package/dist/esm/model/chat-v2/toolRoundExecutor.js +12 -0
- package/dist/esm/model/nodes/ChatNode.js +6 -0
- package/dist/esm/model/nodes/ChatNodeBase.js +1 -0
- package/dist/esm/model/nodes/CodeNewNode.js +5 -47
- package/dist/esm/model/nodes/CodeNode.js +4 -46
- package/dist/esm/model/nodes/DelegateFunctionCallNode.js +19 -6
- package/dist/esm/model/nodes/ExpressionNode.js +5 -8
- package/dist/esm/model/nodes/LLMChatV2Node.js +121 -229
- package/dist/esm/model/nodes/LLMProfileNode.js +27 -8
- package/dist/esm/model/nodes/MatchNode.js +86 -41
- package/dist/esm/model/nodes/PromptNode.js +7 -0
- package/dist/esm/model/nodes/ToolNode.js +7 -0
- package/dist/esm/model/nodes/toolCallDelegation.js +177 -110
- package/dist/esm/plugins/anthropic/anthropic.js +4 -4
- package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +7 -0
- package/dist/esm/plugins/gentrace/gentraceSdk.js +0 -1
- package/dist/esm/plugins/gentrace/index.js +0 -1
- package/dist/esm/plugins/gentrace/plugin.js +61 -179
- package/dist/esm/plugins/google/google.js +5 -9
- package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +4 -1
- package/dist/esm/plugins.js +1 -2
- package/dist/esm/recording/ExecutionRecorder.js +62 -13
- package/dist/esm/utils/emitDetached.js +6 -3
- package/dist/esm/utils/openai.js +60 -16
- package/dist/esm/utils/serialization/serialization.js +2 -19
- package/dist/esm/webAppRuntime.js +3 -2
- package/dist/types/api/createProcessor.d.ts +3 -0
- package/dist/types/exports.d.ts +1 -0
- package/dist/types/integrations/CodeRunner.d.ts +10 -7
- package/dist/types/integrations/CodeRunnerOptions.d.ts +15 -0
- package/dist/types/model/AgentResponseTrace.d.ts +123 -0
- package/dist/types/model/ConnectedToolContinuationHost.d.ts +34 -0
- package/dist/types/model/EditorDefinition.d.ts +16 -0
- package/dist/types/model/ExecutorProtocol.d.ts +32 -11
- package/dist/types/model/GraphProcessor.d.ts +41 -9
- package/dist/types/model/NodeBase.d.ts +0 -10
- package/dist/types/model/NodeImpl.d.ts +18 -1
- package/dist/types/model/Nodes.d.ts +2 -2
- package/dist/types/model/ProcessContext.d.ts +99 -0
- package/dist/types/model/ProcessContextBuilder.d.ts +3 -1
- package/dist/types/model/RecordingPlayer.d.ts +6 -0
- package/dist/types/model/SplitRunProcessor.d.ts +10 -3
- package/dist/types/model/UiGraph.d.ts +8 -0
- package/dist/types/model/UiGraphActionProtocol.d.ts +3 -0
- package/dist/types/model/UiGraphBrowserRuntime.d.ts +11 -2
- package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
- package/dist/types/model/UiGraphRuntimeModel.d.ts +2 -0
- package/dist/types/model/UiGraphSchema.d.ts +1 -0
- package/dist/types/model/chat-v2/chatV2CallObserver.d.ts +2 -0
- package/dist/types/model/chat-v2/chatV2CredentialNames.d.ts +30 -0
- package/dist/types/model/chat-v2/chatV2EditorCache.d.ts +2 -3
- package/dist/types/model/chat-v2/chatV2Outputs.d.ts +6 -16
- package/dist/types/model/chat-v2/chatV2Pipeline.d.ts +13 -17
- package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +7 -0
- package/dist/types/model/chat-v2/chatV2ProviderRegistry.d.ts +8 -0
- package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +2 -2
- package/dist/types/model/chat-v2/chatV2ResponseBodyCapture.d.ts +25 -0
- package/dist/types/model/chat-v2/chatV2ResponseFormat.d.ts +3 -2
- package/dist/types/model/chat-v2/chatV2Retry.d.ts +2 -0
- package/dist/types/model/chat-v2/chatV2RuntimeOptions.d.ts +3 -8
- package/dist/types/model/chat-v2/chatV2Types.d.ts +44 -10
- package/dist/types/model/chat-v2/chatV2UsageAccounting.d.ts +14 -0
- package/dist/types/model/chat-v2/customProviderApi.d.ts +22 -0
- package/dist/types/model/chat-v2/index.d.ts +15 -0
- package/dist/types/model/chat-v2/llmChatV2Body.d.ts +24 -0
- package/dist/types/model/chat-v2/llmChatV2CacheBoundary.d.ts +10 -0
- package/dist/types/model/chat-v2/llmChatV2CachePolicy.d.ts +13 -0
- package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +19 -3
- package/dist/types/model/chat-v2/llmChatV2NodeMigration.d.ts +8 -0
- package/dist/types/model/chat-v2/llmChatV2NodeRuntime.d.ts +14 -16
- package/dist/types/model/chat-v2/llmInvocationCoordinator.d.ts +16 -0
- package/dist/types/model/chat-v2/llmInvocationDecision.d.ts +21 -0
- package/dist/types/model/chat-v2/llmInvocationJournal.d.ts +38 -0
- package/dist/types/model/chat-v2/llmInvocationPlan.d.ts +41 -0
- package/dist/types/model/chat-v2/llmInvocationProjections.d.ts +3 -0
- package/dist/types/model/chat-v2/llmInvocationResultProjector.d.ts +26 -0
- package/dist/types/model/chat-v2/llmModelCandidate.d.ts +20 -0
- package/dist/types/model/chat-v2/llmProfile.d.ts +14 -0
- package/dist/types/model/chat-v2/llmProfileBody.d.ts +20 -0
- package/dist/types/model/chat-v2/llmProfileFallback.d.ts +36 -49
- package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +209 -0
- package/dist/types/model/chat-v2/llmProfileHealthStore.d.ts +111 -0
- package/dist/types/model/chat-v2/llmProfileNodeRuntime.d.ts +1 -1
- package/dist/types/model/chat-v2/llmProfileTypes.d.ts +4 -1
- package/dist/types/model/chat-v2/llmResponseMaterializer.d.ts +20 -0
- package/dist/types/model/chat-v2/modelRegistry.d.ts +17 -187
- package/dist/types/model/chat-v2/parallelToolCalls.d.ts +3 -1
- package/dist/types/model/chat-v2/providerOptions.d.ts +12 -0
- package/dist/types/model/chat-v2/rivetToolRegistry.d.ts +11 -0
- package/dist/types/model/chat-v2/toolCallCodec.d.ts +7 -0
- package/dist/types/model/chat-v2/toolContinuation.d.ts +3 -3
- package/dist/types/model/chat-v2/toolHandlerResolver.d.ts +25 -0
- package/dist/types/model/chat-v2/toolRoundExecutor.d.ts +18 -0
- package/dist/types/model/nodes/ChatNode.d.ts +2 -1
- package/dist/types/model/nodes/CodeNewNode.d.ts +0 -5
- package/dist/types/model/nodes/CodeNode.d.ts +0 -5
- package/dist/types/model/nodes/DelegateFunctionCallNode.d.ts +2 -1
- package/dist/types/model/nodes/LLMChatV2Node.d.ts +2 -1
- package/dist/types/model/nodes/LLMProfileNode.d.ts +2 -1
- package/dist/types/model/nodes/MatchNode.d.ts +6 -0
- package/dist/types/model/nodes/PromptNode.d.ts +4 -1
- package/dist/types/model/nodes/ToolNode.d.ts +2 -1
- package/dist/types/model/nodes/toolCallDelegation.d.ts +10 -3
- package/dist/types/plugins/anthropic/anthropic.d.ts +1 -0
- package/dist/types/plugins/gentrace/gentraceSdk.d.ts +0 -1
- package/dist/types/plugins/gentrace/plugin.d.ts +55 -9
- package/dist/types/plugins/google/google.d.ts +2 -8
- package/dist/types/plugins.d.ts +1 -1
- package/dist/types/recording/ExecutionRecorder.d.ts +7 -1
- package/dist/types/recording/RecordedEvents.d.ts +6 -0
- package/dist/types/utils/emitDetached.d.ts +3 -2
- package/dist/types/utils/openai.d.ts +49 -0
- package/dist/types/webAppRuntime.d.ts +4 -2
- package/package.json +2 -2
|
@@ -21,6 +21,7 @@ export class MatchNodeImpl extends NodeImpl {
|
|
|
21
21
|
data: {
|
|
22
22
|
cases: ['YES', 'NO'],
|
|
23
23
|
casePortIds: [nanoid(), nanoid()],
|
|
24
|
+
valueInputMode: 'shared',
|
|
24
25
|
},
|
|
25
26
|
};
|
|
26
27
|
return chartNode;
|
|
@@ -34,57 +35,86 @@ export class MatchNodeImpl extends NodeImpl {
|
|
|
34
35
|
required: true,
|
|
35
36
|
description: 'The value that will be tested against each of the cases.',
|
|
36
37
|
},
|
|
37
|
-
|
|
38
|
+
];
|
|
39
|
+
if (this.getValueInputMode() === 'shared') {
|
|
40
|
+
inputs.push({
|
|
38
41
|
id: 'value',
|
|
39
|
-
title: '
|
|
42
|
+
title: 'Custom value',
|
|
40
43
|
dataType: 'any',
|
|
41
|
-
description: 'The value passed through to
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
+
description: 'The optional value passed through to every matching output. If unconnected, the Test value is passed through.',
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const portIds = this.getCasePortIds();
|
|
49
|
+
this.data.cases.forEach((caseValue, index) => {
|
|
50
|
+
inputs.push({
|
|
51
|
+
id: this.getCaseValueInputId(portIds[index]),
|
|
52
|
+
title: this.getCaseTitle(caseValue, index),
|
|
53
|
+
dataType: 'any',
|
|
54
|
+
description: `The optional custom value emitted when /${caseValue}/ matches the Test value. If unconnected, Test is passed through.`,
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
inputs.push({
|
|
58
|
+
id: 'value-unmatched',
|
|
59
|
+
title: 'Unmatched',
|
|
60
|
+
dataType: 'any',
|
|
61
|
+
description: 'The optional custom value emitted when no regular expression matches the Test value. If unconnected, Test is passed through.',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
44
64
|
return inputs;
|
|
45
65
|
}
|
|
46
66
|
getOutputDefinitions() {
|
|
47
67
|
const outputs = [];
|
|
48
|
-
const portIds =
|
|
49
|
-
kind: 'prefix',
|
|
50
|
-
prefix: 'case',
|
|
51
|
-
startIndex: 1,
|
|
52
|
-
});
|
|
68
|
+
const portIds = this.getCasePortIds();
|
|
53
69
|
for (let i = 0; i < this.data.cases.length; i++) {
|
|
54
70
|
outputs.push({
|
|
55
71
|
id: portIds[i],
|
|
56
|
-
title: this.
|
|
57
|
-
dataType: '
|
|
58
|
-
description:
|
|
59
|
-
.data.cases[i]}
|
|
72
|
+
title: this.getCaseTitle(this.data.cases[i], i),
|
|
73
|
+
dataType: 'any',
|
|
74
|
+
description: this.getValueInputMode() === 'shared'
|
|
75
|
+
? `The shared Custom value (or Test if Custom value is unconnected) passed through if the test value matches /${this.data.cases[i]}/.`
|
|
76
|
+
: `The corresponding ${this.getCaseTitle(this.data.cases[i], i)} custom value (or Test if it is unconnected) passed through if the test value matches /${this.data.cases[i]}/.`,
|
|
60
77
|
});
|
|
61
78
|
}
|
|
62
79
|
outputs.push({
|
|
63
80
|
id: 'unmatched',
|
|
64
81
|
title: 'Unmatched',
|
|
65
|
-
dataType: '
|
|
66
|
-
description:
|
|
82
|
+
dataType: 'any',
|
|
83
|
+
description: this.getValueInputMode() === 'shared'
|
|
84
|
+
? 'The shared Custom value (or Test if Custom value is unconnected) passed through if no regexes match.'
|
|
85
|
+
: 'The Unmatched custom value (or Test if it is unconnected) passed through if no regexes match.',
|
|
67
86
|
});
|
|
68
87
|
return outputs;
|
|
69
88
|
}
|
|
70
89
|
getBody() {
|
|
71
|
-
return
|
|
72
|
-
${this.data.exclusive ? 'First Matching Case' : 'All Matching Cases'}
|
|
73
|
-
${this.data.cases.length} Cases
|
|
74
|
-
`;
|
|
90
|
+
return this.data.exclusive ? 'Trigger the first matching case only' : 'Trigger all matching cases';
|
|
75
91
|
}
|
|
76
92
|
getEditors() {
|
|
77
93
|
return [
|
|
78
94
|
{
|
|
79
|
-
type: '
|
|
95
|
+
type: 'segmented',
|
|
96
|
+
label: 'Matching cases to trigger',
|
|
80
97
|
dataKey: 'exclusive',
|
|
81
|
-
|
|
82
|
-
|
|
98
|
+
defaultValue: false,
|
|
99
|
+
options: [
|
|
100
|
+
{ value: false, label: 'Trigger all matching cases' },
|
|
101
|
+
{ value: true, label: 'Trigger first only' },
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
type: 'segmented',
|
|
106
|
+
label: 'Custom case values',
|
|
107
|
+
dataKey: 'valueInputMode',
|
|
108
|
+
defaultValue: 'shared',
|
|
109
|
+
options: [
|
|
110
|
+
{ value: 'shared', label: 'One shared custom value' },
|
|
111
|
+
{ value: 'per-output', label: 'Custom values per case' },
|
|
112
|
+
],
|
|
83
113
|
},
|
|
84
114
|
{
|
|
85
115
|
type: 'stringList',
|
|
86
116
|
dataKey: 'cases',
|
|
87
|
-
label: 'Cases',
|
|
117
|
+
label: 'Cases (regular expressions)',
|
|
88
118
|
placeholder: 'Case (regular expression)',
|
|
89
119
|
reorderable: true,
|
|
90
120
|
portBinding: {
|
|
@@ -96,15 +126,15 @@ export class MatchNodeImpl extends NodeImpl {
|
|
|
96
126
|
prefix: 'case',
|
|
97
127
|
startIndex: 1,
|
|
98
128
|
},
|
|
129
|
+
companionBindings: [{ side: 'input', prefix: 'value-' }],
|
|
99
130
|
},
|
|
100
|
-
helperMessage: '(Regular expressions)',
|
|
101
131
|
},
|
|
102
132
|
];
|
|
103
133
|
}
|
|
104
134
|
static getUIData() {
|
|
105
135
|
return {
|
|
106
136
|
infoBoxBody: dedent `
|
|
107
|
-
|
|
137
|
+
Configure any number of regular expressions, each corresponding to an output. Trigger all matched outputs by default, or choose Trigger first matching case. One shared custom value passes one optional value to every active output, while Custom values per case gives each case and Unmatched output its own optional custom value input.
|
|
108
138
|
`,
|
|
109
139
|
infoBoxTitle: 'Regex Match Node',
|
|
110
140
|
contextMenuTitle: 'Regex Match',
|
|
@@ -114,14 +144,19 @@ export class MatchNodeImpl extends NodeImpl {
|
|
|
114
144
|
async process(inputs) {
|
|
115
145
|
const inputValue = inputs['input'];
|
|
116
146
|
const inputString = inputValue?.value == null ? undefined : coerceType(inputValue, 'string');
|
|
117
|
-
const
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
147
|
+
const portIds = this.getCasePortIds();
|
|
148
|
+
const sharedValue = inputs['value'];
|
|
149
|
+
const getTestOutputValue = () => ({
|
|
150
|
+
type: 'string',
|
|
151
|
+
value: inputString,
|
|
122
152
|
});
|
|
123
|
-
const
|
|
124
|
-
const
|
|
153
|
+
const getSharedOutputValue = () => sharedValue ?? getTestOutputValue();
|
|
154
|
+
const getOutputValue = (portId) => this.getValueInputMode() === 'shared'
|
|
155
|
+
? getSharedOutputValue()
|
|
156
|
+
: inputs[this.getCaseValueInputId(portId)] ?? getTestOutputValue();
|
|
157
|
+
const getUnmatchedOutputValue = () => this.getValueInputMode() === 'shared'
|
|
158
|
+
? getSharedOutputValue()
|
|
159
|
+
: inputs['value-unmatched'] ?? getTestOutputValue();
|
|
125
160
|
const cases = this.data.cases;
|
|
126
161
|
let matched = false;
|
|
127
162
|
const output = {};
|
|
@@ -130,10 +165,7 @@ export class MatchNodeImpl extends NodeImpl {
|
|
|
130
165
|
const canMatch = !this.data.exclusive || !matched;
|
|
131
166
|
if (match && canMatch) {
|
|
132
167
|
matched = true;
|
|
133
|
-
output[portIds[i]] =
|
|
134
|
-
type: outputType,
|
|
135
|
-
value: outputValue,
|
|
136
|
-
};
|
|
168
|
+
output[portIds[i]] = getOutputValue(portIds[i]);
|
|
137
169
|
}
|
|
138
170
|
else {
|
|
139
171
|
output[portIds[i]] = {
|
|
@@ -143,10 +175,7 @@ export class MatchNodeImpl extends NodeImpl {
|
|
|
143
175
|
}
|
|
144
176
|
}
|
|
145
177
|
if (!matched) {
|
|
146
|
-
output['unmatched'] =
|
|
147
|
-
type: outputType,
|
|
148
|
-
value: outputValue,
|
|
149
|
-
};
|
|
178
|
+
output['unmatched'] = getUnmatchedOutputValue();
|
|
150
179
|
}
|
|
151
180
|
else {
|
|
152
181
|
output['unmatched'] = {
|
|
@@ -156,5 +185,21 @@ export class MatchNodeImpl extends NodeImpl {
|
|
|
156
185
|
}
|
|
157
186
|
return output;
|
|
158
187
|
}
|
|
188
|
+
getValueInputMode() {
|
|
189
|
+
return this.data.valueInputMode === 'per-output' ? 'per-output' : 'shared';
|
|
190
|
+
}
|
|
191
|
+
getCasePortIds() {
|
|
192
|
+
return resolveStoredOrderedPortIds(this.data.cases.length, this.data.casePortIds, {
|
|
193
|
+
kind: 'prefix',
|
|
194
|
+
prefix: 'case',
|
|
195
|
+
startIndex: 1,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
getCaseTitle(caseValue, index) {
|
|
199
|
+
return caseValue?.trim() ? caseValue : `Case ${index + 1}`;
|
|
200
|
+
}
|
|
201
|
+
getCaseValueInputId(portId) {
|
|
202
|
+
return `value-${portId}`;
|
|
203
|
+
}
|
|
159
204
|
}
|
|
160
205
|
export const matchNode = nodeDefinition(MatchNodeImpl, 'Regex Match');
|
|
@@ -90,6 +90,13 @@ export class PromptNodeImpl extends NodeImpl {
|
|
|
90
90
|
}
|
|
91
91
|
return outputs;
|
|
92
92
|
}
|
|
93
|
+
getRunActivityDescriptor() {
|
|
94
|
+
// A Prompt can additionally emit a token count, but its user-visible
|
|
95
|
+
// result is always the generated chat-message on `output`.
|
|
96
|
+
return {
|
|
97
|
+
primaryOutputPortId: 'output',
|
|
98
|
+
};
|
|
99
|
+
}
|
|
93
100
|
getEditors() {
|
|
94
101
|
return [
|
|
95
102
|
{
|
|
@@ -84,6 +84,13 @@ export class GptFunctionNodeImpl extends NodeImpl {
|
|
|
84
84
|
},
|
|
85
85
|
];
|
|
86
86
|
}
|
|
87
|
+
getRunActivityDescriptor() {
|
|
88
|
+
return {
|
|
89
|
+
category: 'tool',
|
|
90
|
+
primaryOutputPortId: 'function',
|
|
91
|
+
fullOutputActionLabel: 'Open tool definition',
|
|
92
|
+
};
|
|
93
|
+
}
|
|
87
94
|
getEditors() {
|
|
88
95
|
return [
|
|
89
96
|
{
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { omit } from 'lodash-es';
|
|
2
2
|
import { coerceTypeOptional } from '../../utils/coerceType.js';
|
|
3
3
|
import { getError } from '../../utils/errors.js';
|
|
4
|
+
import { createDelegatedToolCallRecord, createToolResultMessage, normalizeToolCall, stringifyToolResult, } from '../chat-v2/toolCallCodec.js';
|
|
5
|
+
import { findAutoDelegateGraphCandidate, resolveToolHandler } from '../chat-v2/toolHandlerResolver.js';
|
|
6
|
+
/**
|
|
7
|
+
* Reserved inputs belong to Rivet's tool invocation envelope. Model-produced
|
|
8
|
+
* arguments must never replace them, otherwise a handler can observe a tool
|
|
9
|
+
* name or argument object that does not match the invocation being delegated.
|
|
10
|
+
*/
|
|
11
|
+
const RIVET_TOOL_CALL_INPUT_IDS = new Set(['_function_name', '_arguments', '_rivet_tool_call']);
|
|
4
12
|
/**
|
|
5
13
|
* Finds an Auto Delegate handler from an ordered set of graph-like candidates.
|
|
6
14
|
*
|
|
@@ -9,10 +17,7 @@ import { getError } from '../../utils/errors.js';
|
|
|
9
17
|
* entries and uses their map keys. Keeping that distinction here preserves the
|
|
10
18
|
* existing behavior for malformed projects where those identities disagree.
|
|
11
19
|
*/
|
|
12
|
-
export
|
|
13
|
-
return (candidates.find((candidate) => getGraphName(candidate) === toolName) ??
|
|
14
|
-
candidates.find((candidate) => getGraphName(candidate)?.includes(toolName)));
|
|
15
|
-
}
|
|
20
|
+
export { findAutoDelegateGraphCandidate };
|
|
16
21
|
export function isDelegatedToolCallRecord(input) {
|
|
17
22
|
const maybeRecord = input;
|
|
18
23
|
const maybeMessage = maybeRecord?.message;
|
|
@@ -41,9 +46,26 @@ export function buildDelegatedToolCallOutputs(records, preToolMessage, cost) {
|
|
|
41
46
|
type: 'string',
|
|
42
47
|
value: preToolMessage,
|
|
43
48
|
};
|
|
49
|
+
const executionTimesSeconds = records.map((record) => {
|
|
50
|
+
const executionTimeMs = getExecutionTimeMs(record);
|
|
51
|
+
return executionTimeMs == null ? undefined : executionTimeMs / 1_000;
|
|
52
|
+
});
|
|
53
|
+
const executionTimeOutput = executionTimesSeconds.every((executionTimeSeconds) => executionTimeSeconds != null)
|
|
54
|
+
? records.length === 1
|
|
55
|
+
? {
|
|
56
|
+
type: 'number',
|
|
57
|
+
value: executionTimesSeconds[0],
|
|
58
|
+
}
|
|
59
|
+
: {
|
|
60
|
+
type: 'number[]',
|
|
61
|
+
value: executionTimesSeconds,
|
|
62
|
+
}
|
|
63
|
+
: {
|
|
64
|
+
type: 'control-flow-excluded',
|
|
65
|
+
value: undefined,
|
|
66
|
+
};
|
|
44
67
|
const outputs = records.length === 1
|
|
45
68
|
? {
|
|
46
|
-
['assistant-message']: preToolMessageOutput,
|
|
47
69
|
['tool-name']: {
|
|
48
70
|
type: 'string',
|
|
49
71
|
value: records[0].name,
|
|
@@ -52,17 +74,18 @@ export function buildDelegatedToolCallOutputs(records, preToolMessage, cost) {
|
|
|
52
74
|
type: 'object',
|
|
53
75
|
value: records[0].arguments,
|
|
54
76
|
},
|
|
77
|
+
['assistant-message']: preToolMessageOutput,
|
|
55
78
|
['output']: {
|
|
56
79
|
type: 'string',
|
|
57
80
|
value: records[0].output,
|
|
58
81
|
},
|
|
82
|
+
['execution-time']: executionTimeOutput,
|
|
59
83
|
['message']: {
|
|
60
84
|
type: 'chat-message',
|
|
61
85
|
value: records[0].message,
|
|
62
86
|
},
|
|
63
87
|
}
|
|
64
88
|
: {
|
|
65
|
-
['assistant-message']: preToolMessageOutput,
|
|
66
89
|
['tool-name']: {
|
|
67
90
|
type: 'string[]',
|
|
68
91
|
value: records.map((record) => record.name),
|
|
@@ -71,10 +94,12 @@ export function buildDelegatedToolCallOutputs(records, preToolMessage, cost) {
|
|
|
71
94
|
type: 'object[]',
|
|
72
95
|
value: records.map((record) => record.arguments),
|
|
73
96
|
},
|
|
97
|
+
['assistant-message']: preToolMessageOutput,
|
|
74
98
|
['output']: {
|
|
75
99
|
type: 'string[]',
|
|
76
100
|
value: records.map((record) => record.output),
|
|
77
101
|
},
|
|
102
|
+
['execution-time']: executionTimeOutput,
|
|
78
103
|
['message']: {
|
|
79
104
|
type: 'chat-message[]',
|
|
80
105
|
value: records.map((record) => record.message),
|
|
@@ -85,112 +110,108 @@ export function buildDelegatedToolCallOutputs(records, preToolMessage, cost) {
|
|
|
85
110
|
}
|
|
86
111
|
return outputs;
|
|
87
112
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
throw new Error(`Delegate Tool Call expected "${name}" arguments to be a JSON object.`);
|
|
113
|
+
/** @deprecated Use normalizeToolCall from the canonical chat-v2 codec. */
|
|
114
|
+
export const normalizeFunctionCallInput = normalizeToolCall;
|
|
115
|
+
export async function delegateToolCall(rawFunctionCall, context, config) {
|
|
116
|
+
const functionCall = normalizeToolCall(rawFunctionCall);
|
|
117
|
+
const source = context.toolCallTraceSource ?? {
|
|
118
|
+
nodeId: context.node?.id ?? 'unknown',
|
|
119
|
+
processId: context.processId ?? 'unknown',
|
|
120
|
+
};
|
|
121
|
+
// A connected continuation changes the trace *source* to the LLM Chat, but
|
|
122
|
+
// the Delegate invocation still owns the persisted result. Carry that exact
|
|
123
|
+
// pointer so observers can navigate to the result without matching tool
|
|
124
|
+
// names or scanning potentially evicted input values.
|
|
125
|
+
const resultOwner = getToolCallResultOwner(context);
|
|
126
|
+
const startedAt = Date.now();
|
|
127
|
+
const timingStart = getCurrentTimeMs();
|
|
128
|
+
const trace = { handlerKind: 'unknown' };
|
|
129
|
+
try {
|
|
130
|
+
const result = await delegateResolvedToolCall(functionCall, context, config, trace);
|
|
131
|
+
notifyToolCallFinished(context, {
|
|
132
|
+
...(functionCall.id == null ? {} : { toolCallId: functionCall.id }),
|
|
133
|
+
toolName: functionCall.name,
|
|
134
|
+
sourceNodeId: source.nodeId,
|
|
135
|
+
sourceProcessId: source.processId,
|
|
136
|
+
...(resultOwner == null ? {} : { resultOwner }),
|
|
137
|
+
...trace,
|
|
138
|
+
outcome: result.traceOutcome ?? 'success',
|
|
139
|
+
startedAt,
|
|
140
|
+
durationMs: Math.max(0, getCurrentTimeMs() - timingStart),
|
|
141
|
+
});
|
|
142
|
+
return result;
|
|
119
143
|
}
|
|
120
|
-
|
|
121
|
-
|
|
144
|
+
catch (error) {
|
|
145
|
+
notifyToolCallFinished(context, {
|
|
146
|
+
...(functionCall.id == null ? {} : { toolCallId: functionCall.id }),
|
|
147
|
+
toolName: functionCall.name,
|
|
148
|
+
sourceNodeId: source.nodeId,
|
|
149
|
+
sourceProcessId: source.processId,
|
|
150
|
+
...trace,
|
|
151
|
+
outcome: context.signal.aborted ? 'aborted' : 'failure',
|
|
152
|
+
startedAt,
|
|
153
|
+
durationMs: Math.max(0, getCurrentTimeMs() - timingStart),
|
|
154
|
+
});
|
|
155
|
+
throw error;
|
|
122
156
|
}
|
|
123
|
-
throw new Error(`Delegate Tool Call expected "${name}" arguments to be an object.`);
|
|
124
157
|
}
|
|
125
|
-
function
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
toolName: functionCall.name,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
function buildDelegatedToolCallRecord(functionCall, outputString) {
|
|
158
|
+
function getToolCallResultOwner(context) {
|
|
159
|
+
const node = context.node;
|
|
160
|
+
if (node?.type !== 'delegateFunctionCall' || typeof node.id !== 'string' || typeof context.processId !== 'string') {
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
134
163
|
return {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
id: functionCall.id,
|
|
139
|
-
output: outputString,
|
|
140
|
-
message: buildToolResultMessage(functionCall, outputString),
|
|
164
|
+
nodeId: node.id,
|
|
165
|
+
processId: context.processId,
|
|
166
|
+
outputPortId: 'output',
|
|
141
167
|
};
|
|
142
168
|
}
|
|
143
|
-
function
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const functionCall = normalizeFunctionCallInput(rawFunctionCall);
|
|
169
|
+
async function delegateResolvedToolCall(functionCall, context, config, trace) {
|
|
170
|
+
const resolvedHandler = resolveToolHandler({
|
|
171
|
+
project: context.project,
|
|
172
|
+
toolName: functionCall.name,
|
|
173
|
+
config,
|
|
174
|
+
hasExternalFunction: context.externalFunctions[functionCall.name] != null,
|
|
175
|
+
});
|
|
151
176
|
let handler;
|
|
152
|
-
if (
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
177
|
+
if (resolvedHandler?.kind === 'external') {
|
|
178
|
+
const externalFunction = context.externalFunctions[functionCall.name];
|
|
179
|
+
if (externalFunction) {
|
|
180
|
+
trace.handlerKind = 'external';
|
|
181
|
+
trace.handlerName = functionCall.name;
|
|
182
|
+
const executionStart = getCurrentTimeMs();
|
|
183
|
+
try {
|
|
184
|
+
const externalContext = omit(context, ['setGlobal']);
|
|
185
|
+
const result = await externalFunction(externalContext, functionCall.arguments ?? {});
|
|
186
|
+
const outputString = stringifyToolResult(result);
|
|
187
|
+
const executionTimeMs = getCurrentTimeMs() - executionStart;
|
|
188
|
+
return {
|
|
189
|
+
outputString,
|
|
190
|
+
message: createToolResultMessage(functionCall, outputString),
|
|
191
|
+
record: createDelegatedToolCallRecord(functionCall, outputString, executionTimeMs),
|
|
192
|
+
cost: result.cost,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
if (config.passthroughErrors) {
|
|
197
|
+
const outputString = `Error: ${getError(error).message}`;
|
|
198
|
+
const executionTimeMs = getCurrentTimeMs() - executionStart;
|
|
170
199
|
return {
|
|
171
200
|
outputString,
|
|
172
|
-
message:
|
|
173
|
-
record:
|
|
174
|
-
|
|
201
|
+
message: createToolResultMessage(functionCall, outputString),
|
|
202
|
+
record: createDelegatedToolCallRecord(functionCall, outputString, executionTimeMs),
|
|
203
|
+
traceOutcome: 'passthrough-error',
|
|
175
204
|
};
|
|
176
205
|
}
|
|
177
|
-
|
|
178
|
-
if (config.passthroughErrors) {
|
|
179
|
-
const outputString = `Error: ${getError(error).message}`;
|
|
180
|
-
return {
|
|
181
|
-
outputString,
|
|
182
|
-
message: buildToolResultMessage(functionCall, outputString),
|
|
183
|
-
record: buildDelegatedToolCallRecord(functionCall, outputString),
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
throw new Error(`External function call failed for ${functionCall.name}: ${getError(error).message}`);
|
|
187
|
-
}
|
|
206
|
+
throw new Error(`External function call failed for ${functionCall.name}: ${getError(error).message}`);
|
|
188
207
|
}
|
|
189
208
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
209
|
+
}
|
|
210
|
+
if (resolvedHandler?.kind === 'graph' || resolvedHandler?.kind === 'unknown') {
|
|
211
|
+
handler = { value: resolvedHandler.graphId };
|
|
212
|
+
}
|
|
213
|
+
if (!handler) {
|
|
214
|
+
if (config.autoDelegate) {
|
|
194
215
|
const errorMessage = config.fallBackToExternalCall
|
|
195
216
|
? `No handler found for tool call: ${functionCall.name}, no graph containing the name "${functionCall.name}" was found, and no external function with that name was registered.`
|
|
196
217
|
: `No handler found for tool call: ${functionCall.name}, no graph containing the name "${functionCall.name}" was found.`;
|
|
@@ -200,30 +221,76 @@ export async function delegateToolCall(rawFunctionCall, context, config) {
|
|
|
200
221
|
throw new Error(`No handler found for tool call: ${functionCall.name}`);
|
|
201
222
|
}
|
|
202
223
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
224
|
+
// A null-prototype map prevents model arguments such as `__proto__` from
|
|
225
|
+
// changing the input map's prototype. Retain the legacy top-level argument
|
|
226
|
+
// inputs for existing handler graphs, while also providing one namespaced
|
|
227
|
+
// invocation envelope for new graphs.
|
|
228
|
+
const subgraphInputs = Object.create(null);
|
|
229
|
+
subgraphInputs._function_name = {
|
|
230
|
+
type: 'string',
|
|
231
|
+
value: functionCall.name,
|
|
232
|
+
};
|
|
233
|
+
subgraphInputs._arguments = {
|
|
234
|
+
type: 'object',
|
|
235
|
+
value: functionCall.arguments,
|
|
236
|
+
};
|
|
237
|
+
subgraphInputs._rivet_tool_call = {
|
|
238
|
+
type: 'object',
|
|
239
|
+
value: {
|
|
240
|
+
id: functionCall.id,
|
|
241
|
+
name: functionCall.name,
|
|
242
|
+
arguments: functionCall.arguments,
|
|
211
243
|
},
|
|
212
244
|
};
|
|
245
|
+
trace.handlerKind = 'graph';
|
|
246
|
+
trace.handlerGraphId = handler.value;
|
|
247
|
+
const handlerName = context.project.graphs[handler.value]?.metadata?.name;
|
|
248
|
+
if (handlerName != null) {
|
|
249
|
+
trace.handlerName = handlerName;
|
|
250
|
+
}
|
|
213
251
|
for (const [argName, argument] of Object.entries(functionCall.arguments ?? {})) {
|
|
252
|
+
if (RIVET_TOOL_CALL_INPUT_IDS.has(argName)) {
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
214
255
|
subgraphInputs[argName] = {
|
|
215
256
|
type: 'any',
|
|
216
257
|
value: argument,
|
|
217
258
|
};
|
|
218
259
|
}
|
|
219
260
|
const subprocessor = context.createSubProcessor(handler.value, { signal: context.signal });
|
|
261
|
+
const executionStart = getCurrentTimeMs();
|
|
220
262
|
const outputs = await subprocessor.processGraph(context, subgraphInputs, context.contextValues);
|
|
221
|
-
const
|
|
263
|
+
const executionTimeMs = getCurrentTimeMs() - executionStart;
|
|
264
|
+
const outputValue = outputs['output'];
|
|
265
|
+
if (outputValue == null) {
|
|
266
|
+
throw new Error(`Tool handler graph "${handlerName ?? handler.value}" must return a string Graph Output named "output".`);
|
|
267
|
+
}
|
|
268
|
+
const outputString = coerceTypeOptional(outputValue, 'string');
|
|
269
|
+
if (outputString == null) {
|
|
270
|
+
throw new Error(`Tool handler graph "${handlerName ?? handler.value}" returned an invalid Graph Output named "output". It must resolve to a string.`);
|
|
271
|
+
}
|
|
222
272
|
const cost = coerceTypeOptional(outputs['cost'], 'number');
|
|
223
273
|
return {
|
|
224
274
|
outputString,
|
|
225
|
-
message:
|
|
226
|
-
record:
|
|
275
|
+
message: createToolResultMessage(functionCall, outputString),
|
|
276
|
+
record: createDelegatedToolCallRecord(functionCall, outputString, executionTimeMs),
|
|
227
277
|
cost,
|
|
228
278
|
};
|
|
229
279
|
}
|
|
280
|
+
function notifyToolCallFinished(context, event) {
|
|
281
|
+
try {
|
|
282
|
+
context.onToolCallFinished?.(event);
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
// Trace observers must never change tool execution behavior.
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function getCurrentTimeMs() {
|
|
289
|
+
return globalThis.performance?.now?.() ?? Date.now();
|
|
290
|
+
}
|
|
291
|
+
function getExecutionTimeMs(record) {
|
|
292
|
+
const { executionTimeMs } = record;
|
|
293
|
+
return typeof executionTimeMs === 'number' && Number.isFinite(executionTimeMs) && executionTimeMs >= 0
|
|
294
|
+
? executionTimeMs
|
|
295
|
+
: undefined;
|
|
296
|
+
}
|
|
@@ -4,8 +4,8 @@ export const anthropicModels = {
|
|
|
4
4
|
'claude-instant-1': {
|
|
5
5
|
maxTokens: 100_000,
|
|
6
6
|
cost: {
|
|
7
|
-
prompt:
|
|
8
|
-
completion:
|
|
7
|
+
prompt: 1.63e-6,
|
|
8
|
+
completion: 5.51e-6,
|
|
9
9
|
},
|
|
10
10
|
displayName: 'Claude Instant',
|
|
11
11
|
},
|
|
@@ -85,7 +85,7 @@ export const anthropicModels = {
|
|
|
85
85
|
maxTokens: 200_000,
|
|
86
86
|
cost: {
|
|
87
87
|
prompt: 3e-6,
|
|
88
|
-
completion:
|
|
88
|
+
completion: 15e-6,
|
|
89
89
|
},
|
|
90
90
|
displayName: 'Claude Sonnet 4',
|
|
91
91
|
},
|
|
@@ -93,7 +93,7 @@ export const anthropicModels = {
|
|
|
93
93
|
maxTokens: 200_000,
|
|
94
94
|
cost: {
|
|
95
95
|
prompt: 15e-6,
|
|
96
|
-
completion:
|
|
96
|
+
completion: 75e-6,
|
|
97
97
|
},
|
|
98
98
|
displayName: 'Claude Opus 4',
|
|
99
99
|
},
|