@valerypopoff/rivet2-core 2.1.9 → 2.1.10
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 +3596 -1745
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/cjs/webAppRuntime.cjs +298 -21
- package/dist/cjs/webAppRuntime.cjs.map +4 -4
- package/dist/esm/exports.js +1 -0
- package/dist/esm/model/AgentResponseTrace.js +448 -0
- package/dist/esm/model/ConnectedToolContinuationHost.js +33 -0
- package/dist/esm/model/GraphProcessor.js +151 -74
- package/dist/esm/model/NodeImpl.js +6 -0
- package/dist/esm/model/ProcessContextBuilder.js +3 -1
- package/dist/esm/model/RecordingPlayer.js +164 -22
- package/dist/esm/model/SplitRunProcessor.js +49 -8
- package/dist/esm/model/SubprocessorBridge.js +2 -0
- package/dist/esm/model/ToolCallContinuationCoordinator.js +7 -3
- package/dist/esm/model/UiGraph.js +21 -0
- package/dist/esm/model/UiGraphActionProtocol.js +2 -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/chatV2CallObserver.js +9 -5
- package/dist/esm/model/chat-v2/chatV2EditorCache.js +42 -16
- 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 +61 -146
- package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +8 -2
- 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 +55 -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 +6 -1
- package/dist/esm/model/chat-v2/chatV2Types.js +5 -9
- package/dist/esm/model/chat-v2/chatV2UsageAccounting.js +78 -0
- package/dist/esm/model/chat-v2/customProviderApi.js +42 -0
- package/dist/esm/model/chat-v2/index.js +12 -0
- package/dist/esm/model/chat-v2/llmChatV2Body.js +281 -0
- package/dist/esm/model/chat-v2/llmChatV2CacheBoundary.js +32 -0
- package/dist/esm/model/chat-v2/llmChatV2CachePolicy.js +20 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeData.js +6 -50
- package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +25 -13
- package/dist/esm/model/chat-v2/llmChatV2NodeMigration.js +24 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +121 -193
- 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 +75 -0
- package/dist/esm/model/chat-v2/llmProfile.js +10 -65
- package/dist/esm/model/chat-v2/llmProfileBody.js +183 -0
- package/dist/esm/model/chat-v2/llmProfileFallback.js +55 -99
- package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +67 -0
- package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +3 -0
- 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 +86 -20
- 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/DelegateFunctionCallNode.js +19 -6
- package/dist/esm/model/nodes/LLMChatV2Node.js +112 -229
- package/dist/esm/model/nodes/LLMProfileNode.js +27 -8
- 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/google/google.js +5 -9
- package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +4 -1
- package/dist/esm/recording/ExecutionRecorder.js +13 -5
- 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/exports.d.ts +1 -0
- package/dist/types/model/AgentResponseTrace.d.ts +110 -0
- package/dist/types/model/ConnectedToolContinuationHost.d.ts +34 -0
- package/dist/types/model/ExecutorProtocol.d.ts +25 -7
- package/dist/types/model/GraphProcessor.d.ts +27 -5
- 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 +47 -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 +2 -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/chatV2EditorCache.d.ts +1 -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 +4 -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 +19 -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/chatV2Types.d.ts +20 -10
- package/dist/types/model/chat-v2/chatV2UsageAccounting.d.ts +14 -0
- package/dist/types/model/chat-v2/customProviderApi.d.ts +23 -0
- package/dist/types/model/chat-v2/index.d.ts +12 -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 +10 -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 +18 -0
- package/dist/types/model/chat-v2/llmProfileBody.d.ts +20 -0
- package/dist/types/model/chat-v2/llmProfileFallback.d.ts +17 -49
- package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +189 -0
- package/dist/types/model/chat-v2/llmProfileTypes.d.ts +1 -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 +10 -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/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/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/google/google.d.ts +2 -8
- 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
|
@@ -5,46 +5,19 @@ import { NodeImpl } from '../NodeImpl.js';
|
|
|
5
5
|
import { getCommonChatV2Inputs, getCommonChatV2Outputs } from '../chat-v2/chatV2Shared.js';
|
|
6
6
|
import { getLLMChatV2Editors } from '../chat-v2/llmChatV2NodeEditors.js';
|
|
7
7
|
import { createLLMChatV2NodeData, shouldIncludeLLMChatV2ToolCalls, } from '../chat-v2/llmChatV2NodeData.js';
|
|
8
|
+
import { getLLMChatV2BodySections } from '../chat-v2/llmChatV2Body.js';
|
|
8
9
|
import { isLLMChatV2StructuredResponseFormat } from '../chat-v2/chatV2FeatureCompatibility.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
10
|
+
import { LLMInvocationJournal } from '../chat-v2/llmInvocationJournal.js';
|
|
11
|
+
import { executeLLMInvocation } from '../chat-v2/llmInvocationCoordinator.js';
|
|
12
|
+
import { projectLLMInvocationDiagnostics, projectLLMInvocationResult, } from '../chat-v2/llmInvocationResultProjector.js';
|
|
13
|
+
import { isChatV2PipelineProviderFailureResult } from '../chat-v2/chatV2Pipeline.js';
|
|
14
|
+
import { shouldOutputChatV2RequestBody, shouldOutputChatV2ResponseBody } from '../chat-v2/chatV2Types.js';
|
|
15
|
+
import { buildLLMChatV2EditorCacheKey, resolveLLMChatV2RuntimeConfig, resolveLLMChatV2RuntimeProviderOptions, } from '../chat-v2/llmChatV2NodeRuntime.js';
|
|
16
|
+
import { projectLLMChatV2EditorCacheHit, writeLLMChatV2EditorCache } from '../chat-v2/llmChatV2CacheBoundary.js';
|
|
16
17
|
export { buildLLMChatV2EditorCacheKey, resolveLLMChatV2RuntimeProviderOptions };
|
|
17
18
|
function usesBaseURLInput(data) {
|
|
18
19
|
return data.provider === 'custom' && data.useCustomProviderBaseURLInput;
|
|
19
20
|
}
|
|
20
|
-
function getCustomProviderBaseURLBodyValue(data) {
|
|
21
|
-
if (data.provider !== 'custom') {
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
if (data.useCustomProviderBaseURLInput) {
|
|
25
|
-
return '(Using Input)';
|
|
26
|
-
}
|
|
27
|
-
const baseURL = data.customProviderBaseURL.trim();
|
|
28
|
-
return baseURL || undefined;
|
|
29
|
-
}
|
|
30
|
-
function getOptionLabel(options, value) {
|
|
31
|
-
return options.find((option) => option.value === (value ?? ''))?.label ?? value ?? 'Default';
|
|
32
|
-
}
|
|
33
|
-
function getProviderBodyLabel(data) {
|
|
34
|
-
return data.provider === 'custom' ? 'Custom' : getChatV2ProviderLabel(data.provider);
|
|
35
|
-
}
|
|
36
|
-
function getReasoningEffortBodyValue(data) {
|
|
37
|
-
switch (data.provider) {
|
|
38
|
-
case 'openai':
|
|
39
|
-
return getOptionLabel(openAIReasoningEffortOptions, data.openAIReasoningEffort);
|
|
40
|
-
case 'anthropic':
|
|
41
|
-
return getOptionLabel(anthropicEffortOptions, data.anthropicEffort);
|
|
42
|
-
case 'google':
|
|
43
|
-
return getOptionLabel(googleThinkingLevelOptions, data.googleThinkingLevel);
|
|
44
|
-
case 'custom':
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
21
|
function escapeMarkdownInline(value) {
|
|
49
22
|
return value
|
|
50
23
|
.replace(/\r/g, '\\r')
|
|
@@ -58,20 +31,19 @@ function escapeMarkdownInline(value) {
|
|
|
58
31
|
function getBodyLine(label, value) {
|
|
59
32
|
return `<span style="opacity: 0.55">${label}:</span> ${escapeMarkdownInline(value)}`;
|
|
60
33
|
}
|
|
61
|
-
function
|
|
62
|
-
|
|
63
|
-
return getBodyLine(label, '(Using Input)');
|
|
64
|
-
}
|
|
65
|
-
return value === undefined ? undefined : getBodyLine(label, `${value}`);
|
|
34
|
+
function escapeMarkdownPreformatted(value) {
|
|
35
|
+
return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
66
36
|
}
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
37
|
+
function getBodySectionText(section) {
|
|
38
|
+
return [
|
|
39
|
+
...section.fields.map((field) => getBodyLine(field.label, field.value)),
|
|
40
|
+
...(section.snippet
|
|
41
|
+
? [
|
|
42
|
+
`<span style="opacity: 0.55">${section.snippet.label}:</span>`,
|
|
43
|
+
`<pre>${escapeMarkdownPreformatted(section.snippet.text)}</pre>`,
|
|
44
|
+
]
|
|
45
|
+
: []),
|
|
46
|
+
].join('\n');
|
|
75
47
|
}
|
|
76
48
|
export class LLMChatV2NodeImpl extends NodeImpl {
|
|
77
49
|
static create() {
|
|
@@ -87,6 +59,12 @@ export class LLMChatV2NodeImpl extends NodeImpl {
|
|
|
87
59
|
data: createLLMChatV2NodeData(),
|
|
88
60
|
};
|
|
89
61
|
}
|
|
62
|
+
getRunActivityDescriptor() {
|
|
63
|
+
return {
|
|
64
|
+
category: 'model',
|
|
65
|
+
primaryOutputPortId: 'response',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
90
68
|
getInputDefinitions() {
|
|
91
69
|
const usesProfile = this.data.configurationMode === 'profile';
|
|
92
70
|
const commonInputData = usesProfile
|
|
@@ -211,58 +189,42 @@ export class LLMChatV2NodeImpl extends NodeImpl {
|
|
|
211
189
|
});
|
|
212
190
|
const responseOutput = outputs.find((output) => output.id === 'response');
|
|
213
191
|
if (responseOutput != null && isLLMChatV2StructuredResponseFormat(this.data.responseFormat)) {
|
|
214
|
-
responseOutput.dataType =
|
|
215
|
-
'
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
192
|
+
responseOutput.dataType =
|
|
193
|
+
this.data.responseFormat === 'json_schema'
|
|
194
|
+
? 'object'
|
|
195
|
+
: [
|
|
196
|
+
'object',
|
|
197
|
+
'object[]',
|
|
198
|
+
'any',
|
|
199
|
+
'any[]',
|
|
200
|
+
'string',
|
|
201
|
+
'string[]',
|
|
202
|
+
'number',
|
|
203
|
+
'number[]',
|
|
204
|
+
'boolean',
|
|
205
|
+
'boolean[]',
|
|
206
|
+
];
|
|
226
207
|
}
|
|
227
|
-
if (this.data
|
|
228
|
-
const profileArrayRequestDetails = this.data.configurationMode === 'profile'
|
|
229
|
-
? ['number', 'number[]', 'any']
|
|
230
|
-
: this.data.retryOnNon200
|
|
231
|
-
? 'number[]'
|
|
232
|
-
: 'number';
|
|
208
|
+
if (shouldOutputChatV2RequestBody(this.data)) {
|
|
233
209
|
outputs.push({
|
|
234
|
-
id: '
|
|
235
|
-
title: '
|
|
236
|
-
dataType:
|
|
237
|
-
...(this.data.configurationMode === 'profile'
|
|
238
|
-
? {
|
|
239
|
-
description: 'A scalar profile keeps the normal status shape. An LLM Profile array groups values by profile: one request is a number, retries are a number array.',
|
|
240
|
-
}
|
|
241
|
-
: {}),
|
|
210
|
+
id: 'requestBody',
|
|
211
|
+
title: 'LLM request body',
|
|
212
|
+
dataType: ['object', 'object[]', 'string', 'string[]', 'any', 'any[]'],
|
|
242
213
|
});
|
|
243
214
|
}
|
|
244
|
-
if (
|
|
245
|
-
const profileArrayRequestErrors = this.data.configurationMode === 'profile'
|
|
246
|
-
? ['string', 'string[]', 'any']
|
|
247
|
-
: this.data.retryOnNon200
|
|
248
|
-
? 'string[]'
|
|
249
|
-
: 'string';
|
|
215
|
+
if (shouldOutputChatV2ResponseBody(this.data)) {
|
|
250
216
|
outputs.push({
|
|
251
|
-
id: '
|
|
252
|
-
title: '
|
|
253
|
-
dataType:
|
|
254
|
-
...(this.data.configurationMode === 'profile'
|
|
255
|
-
? {
|
|
256
|
-
description: 'A scalar profile keeps the normal error shape. An LLM Profile array keeps profile positions when errors occur: one error is a string and retries are an array.',
|
|
257
|
-
}
|
|
258
|
-
: {}),
|
|
217
|
+
id: 'responseBody',
|
|
218
|
+
title: 'LLM response body',
|
|
219
|
+
dataType: ['object', 'object[]', 'string', 'string[]', 'any', 'any[]'],
|
|
259
220
|
});
|
|
260
221
|
}
|
|
261
|
-
if (
|
|
222
|
+
if (this.data.outputLLMAttempts) {
|
|
262
223
|
outputs.push({
|
|
263
|
-
id: '
|
|
264
|
-
title: 'LLM
|
|
265
|
-
dataType:
|
|
224
|
+
id: 'llmAttempts',
|
|
225
|
+
title: 'LLM Attempts',
|
|
226
|
+
dataType: 'object[]',
|
|
227
|
+
description: 'Chronological provider configuration, request, and response-validation attempts for this LLM Chat run.',
|
|
266
228
|
});
|
|
267
229
|
}
|
|
268
230
|
if (this.data.configurationMode === 'profile') {
|
|
@@ -271,11 +233,6 @@ export class LLMChatV2NodeImpl extends NodeImpl {
|
|
|
271
233
|
title: 'LLM Profile Summary',
|
|
272
234
|
dataType: 'string',
|
|
273
235
|
description: 'Human-readable profile fallback outcome for this LLM Chat run.',
|
|
274
|
-
}, {
|
|
275
|
-
id: 'llmProfileAttempts',
|
|
276
|
-
title: 'LLM Profile Attempts',
|
|
277
|
-
dataType: 'object[]',
|
|
278
|
-
description: 'Chronological provider/profile attempts for this LLM Chat run.',
|
|
279
236
|
});
|
|
280
237
|
}
|
|
281
238
|
return outputs;
|
|
@@ -297,156 +254,82 @@ export class LLMChatV2NodeImpl extends NodeImpl {
|
|
|
297
254
|
return getLLMChatV2Editors(this.data, context);
|
|
298
255
|
}
|
|
299
256
|
getBody() {
|
|
300
|
-
if (this.data.configurationMode === 'profile') {
|
|
301
|
-
return {
|
|
302
|
-
type: 'markdown',
|
|
303
|
-
disableLinks: true,
|
|
304
|
-
text: [
|
|
305
|
-
getBodyLine('Configuration', 'From LLM Profiles input'),
|
|
306
|
-
...(this.data.useToolCalling ? [getBodyLine('Tools', 'Enabled')] : []),
|
|
307
|
-
...(this.data.responseFormat ? [getBodyLine('Response format', this.data.responseFormat)] : []),
|
|
308
|
-
].join('\n'),
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
const modelInfo = getChatV2ModelInfo(this.data.provider, this.data.model);
|
|
312
|
-
const providerLabel = getProviderBodyLabel(this.data);
|
|
313
|
-
const baseURLValue = getCustomProviderBaseURLBodyValue(this.data);
|
|
314
|
-
const modelLine = modelInfo?.displayName ?? this.data.model;
|
|
315
|
-
const providerDetails = [
|
|
316
|
-
getBodyLine('Provider', providerLabel),
|
|
317
|
-
...(baseURLValue ? [getBodyLine('Base URL', baseURLValue)] : []),
|
|
318
|
-
getBodyLine('Model', modelLine),
|
|
319
|
-
];
|
|
320
|
-
const reasoningEffortValue = getReasoningEffortBodyValue(this.data);
|
|
321
257
|
return {
|
|
322
258
|
type: 'markdown',
|
|
323
259
|
disableLinks: true,
|
|
324
|
-
text:
|
|
325
|
-
...providerDetails,
|
|
326
|
-
...(reasoningEffortValue ? [getBodyLine('Reasoning effort', reasoningEffortValue)] : []),
|
|
327
|
-
getBodyLine('Temperature', this.data.useTemperatureInput ? '(Using Input)' : `${this.data.temperature}`),
|
|
328
|
-
getBodyLine('Max output tokens', this.data.useMaxTokensInput ? '(Using Input)' : `${this.data.maxTokens}`),
|
|
329
|
-
getOptionalNumberBodyLine('Top P', this.data.topP, this.data.useTopPInput),
|
|
330
|
-
getOptionalNumberBodyLine('Top K', this.data.topK, this.data.useTopKInput),
|
|
331
|
-
getOptionalNumberBodyLine('Presence penalty', this.data.presencePenalty, this.data.usePresencePenaltyInput),
|
|
332
|
-
getOptionalNumberBodyLine('Frequency penalty', this.data.frequencyPenalty, this.data.useFrequencyPenaltyInput),
|
|
333
|
-
getStopSequencesBodyLine(this.data),
|
|
334
|
-
getOptionalNumberBodyLine('Seed', this.data.seed, this.data.useSeedInput),
|
|
335
|
-
]
|
|
336
|
-
.filter((line) => line !== undefined)
|
|
337
|
-
.join('\n'),
|
|
260
|
+
text: getLLMChatV2BodySections(this.data).map(getBodySectionText).join('\n\n'),
|
|
338
261
|
};
|
|
339
262
|
}
|
|
340
263
|
async process(inputs, context) {
|
|
264
|
+
const invocationJournal = new LLMInvocationJournal();
|
|
265
|
+
// Retries, fallback profiles, and tool continuation produce several
|
|
266
|
+
// physical provider calls underneath one node invocation. Always observe
|
|
267
|
+
// them locally so every later output projection shares one truthful
|
|
268
|
+
// boundary; whether Usage is exposed remains an output-setting decision.
|
|
269
|
+
const usageTrackingContext = {
|
|
270
|
+
...context,
|
|
271
|
+
onChatV2CallFinished: (event) => {
|
|
272
|
+
try {
|
|
273
|
+
invocationJournal.recordModelCall(event);
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
// Accounting is observational and must never affect a provider call.
|
|
277
|
+
}
|
|
278
|
+
return context.onChatV2CallFinished?.(event);
|
|
279
|
+
},
|
|
280
|
+
};
|
|
341
281
|
const runtime = await resolveLLMChatV2RuntimeConfig({
|
|
342
282
|
data: this.data,
|
|
343
283
|
nodeId: this.chartNode.id,
|
|
344
284
|
inputs,
|
|
345
|
-
context,
|
|
285
|
+
context: usageTrackingContext,
|
|
286
|
+
onLLMAttempt: (attempt) => invocationJournal.recordLLMAttempt(attempt),
|
|
346
287
|
});
|
|
347
288
|
const toolCallContinuation = context.toolCallContinuation;
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
cachedStatus.value = compactLLMProfileRequestStatuses(cachedStatus.value);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
if (runtime.profileChainUsesArray && shouldOutputChatV2RequestError(this.data)) {
|
|
356
|
-
const cachedError = runtime.cachedOutputs['requestError'];
|
|
357
|
-
if (cachedError?.type === 'any' && Array.isArray(cachedError.value)) {
|
|
358
|
-
cachedError.value = compactLLMProfileRequestErrors(cachedError.value);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
// Cached provider output belongs to an earlier invocation, whereas this
|
|
362
|
-
// port is an observability record for physical profile attempts made by
|
|
363
|
-
// the current one. A cache hit made no such attempt.
|
|
364
|
-
if (runtime.profileAttempts != null) {
|
|
365
|
-
runtime.cachedOutputs['llmProfileAttempts'] = {
|
|
366
|
-
type: 'object[]',
|
|
367
|
-
value: [],
|
|
368
|
-
};
|
|
369
|
-
runtime.cachedOutputs['llmProfileSummary'] = {
|
|
370
|
-
type: 'string',
|
|
371
|
-
value: 'Editor cache hit — no LLM Profile calls were made for this run.',
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
return runtime.cachedOutputs;
|
|
289
|
+
const cacheHit = projectLLMChatV2EditorCacheHit(runtime);
|
|
290
|
+
if (cacheHit != null) {
|
|
291
|
+
context.markResultAsEditorCacheHit?.();
|
|
292
|
+
return cacheHit;
|
|
375
293
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
:
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
unknownHandler: undefined,
|
|
396
|
-
autoDelegate: true,
|
|
397
|
-
fallBackToExternalCall: true,
|
|
398
|
-
passthroughErrors: true,
|
|
399
|
-
});
|
|
400
|
-
return {
|
|
401
|
-
type: 'chat-message',
|
|
402
|
-
value: delegated.message,
|
|
403
|
-
delegatedToolCall: delegated.record,
|
|
404
|
-
};
|
|
405
|
-
},
|
|
406
|
-
runPipeline: runtime.runPipeline,
|
|
407
|
-
})
|
|
408
|
-
: await runtime.runPipeline(runtime.runOptions);
|
|
409
|
-
if (runtime.profileAttempts != null) {
|
|
410
|
-
result.commonOutputs['llmProfileAttempts'] = {
|
|
411
|
-
type: 'object[]',
|
|
412
|
-
value: runtime.profileAttempts,
|
|
413
|
-
};
|
|
414
|
-
result.commonOutputs['llmProfileSummary'] = {
|
|
415
|
-
type: 'string',
|
|
416
|
-
value: runtime.getProfileSummary(),
|
|
417
|
-
};
|
|
418
|
-
if (runtime.profileChainUsesArray && runtime.profileChainLength != null) {
|
|
419
|
-
const diagnostics = buildLLMProfileRequestDiagnostics(runtime.profileChainLength, runtime.profileAttempts);
|
|
420
|
-
// Rivet has scalar and one-dimensional array Data Values, but no
|
|
421
|
-
// nested-array Data Type. Keep profile/retry grouping as portable JSON
|
|
422
|
-
// inside Any values. One request or error stays scalar when doing so
|
|
423
|
-
// preserves useful diagnostic information.
|
|
424
|
-
if (this.data.outputRequestStatus) {
|
|
425
|
-
result.commonOutputs['requestStatus'] = {
|
|
426
|
-
type: 'any',
|
|
427
|
-
value: diagnostics.statuses,
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
if (shouldOutputChatV2RequestError(this.data)) {
|
|
431
|
-
result.commonOutputs['requestError'] = {
|
|
432
|
-
type: 'any',
|
|
433
|
-
value: diagnostics.errors,
|
|
434
|
-
};
|
|
294
|
+
let result;
|
|
295
|
+
try {
|
|
296
|
+
result = await executeLLMInvocation({
|
|
297
|
+
context,
|
|
298
|
+
journal: invocationJournal,
|
|
299
|
+
runtime,
|
|
300
|
+
toolCallContinuation,
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
try {
|
|
305
|
+
const diagnostics = projectLLMInvocationDiagnostics({
|
|
306
|
+
runOptions: runtime.runOptions,
|
|
307
|
+
outputLLMAttempts: this.data.outputLLMAttempts,
|
|
308
|
+
llmAttempts: invocationJournal.llmAttempts,
|
|
309
|
+
profileSummary: runtime.getProfileSummary?.(),
|
|
310
|
+
});
|
|
311
|
+
if (Object.keys(diagnostics).length > 0) {
|
|
312
|
+
context.onPartialOutputs?.(diagnostics);
|
|
435
313
|
}
|
|
436
314
|
}
|
|
315
|
+
catch {
|
|
316
|
+
// Developer diagnostics are observational and must never replace the
|
|
317
|
+
// provider/configuration error which caused this node to fail.
|
|
318
|
+
}
|
|
319
|
+
throw error;
|
|
437
320
|
}
|
|
438
|
-
|
|
321
|
+
projectLLMInvocationResult({
|
|
322
|
+
result,
|
|
323
|
+
modelCalls: invocationJournal.modelCalls,
|
|
324
|
+
outputUsage: this.data.outputUsage,
|
|
325
|
+
outputLLMAttempts: this.data.outputLLMAttempts,
|
|
326
|
+
llmAttempts: invocationJournal.llmAttempts,
|
|
327
|
+
profileSummary: runtime.getProfileSummary?.(),
|
|
328
|
+
});
|
|
329
|
+
if (toolCallContinuation && !isChatV2PipelineProviderFailureResult(result) && result.functionCalls.length > 0) {
|
|
439
330
|
toolCallContinuation.release();
|
|
440
331
|
}
|
|
441
|
-
|
|
442
|
-
const cacheOutputs = cloneLLMChatV2EditorCacheOutputs(result.commonOutputs);
|
|
443
|
-
// Attempt history is specific to this execution. Rebuild it as an empty
|
|
444
|
-
// observability value on a later cache hit instead of presenting stale
|
|
445
|
-
// provider calls as if they happened again.
|
|
446
|
-
delete cacheOutputs['llmProfileAttempts'];
|
|
447
|
-
delete cacheOutputs['llmProfileSummary'];
|
|
448
|
-
runtime.editorCache.set(runtime.cacheKey, cacheOutputs);
|
|
449
|
-
}
|
|
332
|
+
writeLLMChatV2EditorCache({ runtime, result });
|
|
450
333
|
return result.commonOutputs;
|
|
451
334
|
}
|
|
452
335
|
}
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import { nanoid } from 'nanoid/non-secure';
|
|
2
|
-
import { dedent } from 'ts-dedent';
|
|
3
2
|
import { nodeDefinition } from '../NodeDefinition.js';
|
|
4
3
|
import { NodeImpl } from '../NodeImpl.js';
|
|
5
4
|
import { getLLMProfileEditors } from '../chat-v2/llmChatV2NodeEditors.js';
|
|
5
|
+
import { getLLMProfileBodySections } from '../chat-v2/llmProfileBody.js';
|
|
6
6
|
import { resolveLLMProfileNodeValue } from '../chat-v2/llmProfileNodeRuntime.js';
|
|
7
7
|
import { createLLMProfileNodeData } from '../chat-v2/llmProfileTypes.js';
|
|
8
|
-
|
|
8
|
+
function escapeMarkdownInline(value) {
|
|
9
|
+
return String(value)
|
|
10
|
+
.replace(/\r/g, '\\r')
|
|
11
|
+
.replace(/\n/g, '\\n')
|
|
12
|
+
.replace(/&/g, '&')
|
|
13
|
+
.replace(/</g, '<')
|
|
14
|
+
.replace(/>/g, '>')
|
|
15
|
+
.replace(/"/g, '"')
|
|
16
|
+
.replace(/([\\`*_[\]{}()#+\-.!|])/g, '\\$1');
|
|
17
|
+
}
|
|
18
|
+
function getBodyLine(label, value) {
|
|
19
|
+
return `<span style="opacity: 0.55">${label}:</span> ${escapeMarkdownInline(value)}`;
|
|
20
|
+
}
|
|
9
21
|
export class LLMProfileNodeImpl extends NodeImpl {
|
|
10
22
|
static create() {
|
|
11
23
|
return {
|
|
@@ -101,12 +113,19 @@ export class LLMProfileNodeImpl extends NodeImpl {
|
|
|
101
113
|
return await getLLMProfileEditors(this.data, context);
|
|
102
114
|
}
|
|
103
115
|
getBody() {
|
|
104
|
-
return
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
116
|
+
return {
|
|
117
|
+
type: 'markdown',
|
|
118
|
+
disableLinks: true,
|
|
119
|
+
text: getLLMProfileBodySections(this.data)
|
|
120
|
+
.map((section) => {
|
|
121
|
+
const fields = section.fields.map((field) => getBodyLine(field.label, field.value));
|
|
122
|
+
const snippet = section.snippet
|
|
123
|
+
? `${getBodyLine(section.snippet.label, '')}\n${escapeMarkdownInline(section.snippet.text)}`
|
|
124
|
+
: undefined;
|
|
125
|
+
return [...fields, ...(snippet ? [snippet] : [])].join('\n');
|
|
126
|
+
})
|
|
127
|
+
.join('\n\n'),
|
|
128
|
+
};
|
|
110
129
|
}
|
|
111
130
|
static getUIData() {
|
|
112
131
|
return {
|
|
@@ -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
|
{
|