@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { normalizeLLMChatV2RetryCooldownMs, normalizeLLMChatV2RetryCount } from './chatV2Retry.js';
|
|
2
|
-
import { shouldOutputChatV2RequestBody,
|
|
2
|
+
import { shouldOutputChatV2RequestBody, shouldOutputChatV2ResponseBody, } from './chatV2Types.js';
|
|
3
3
|
export function buildChatV2RequestPlan(options) {
|
|
4
4
|
const shouldStream = options.emitPartialOutputs !== false;
|
|
5
5
|
return {
|
|
@@ -32,9 +32,8 @@ export function buildChatV2RequestPlan(options) {
|
|
|
32
32
|
output: {
|
|
33
33
|
outputUsage: options.outputUsage,
|
|
34
34
|
outputReasoning: options.outputReasoning,
|
|
35
|
-
outputRequestStatus: options.outputRequestStatus === true,
|
|
36
|
-
outputRequestError: shouldOutputChatV2RequestError(options),
|
|
37
35
|
outputRequestBody: shouldOutputChatV2RequestBody(options),
|
|
36
|
+
outputResponseBody: shouldOutputChatV2ResponseBody(options),
|
|
38
37
|
includeFunctionCalls: options.includeFunctionCalls,
|
|
39
38
|
functionCallMode: options.functionCallMode,
|
|
40
39
|
},
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
function parseResponseBody(text) {
|
|
2
|
+
try {
|
|
3
|
+
return JSON.parse(text);
|
|
4
|
+
}
|
|
5
|
+
catch {
|
|
6
|
+
return text;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A failed clone is intentionally omitted instead of changing provider
|
|
11
|
+
* behavior. Captured diagnostics do not redact or truncate provider content.
|
|
12
|
+
* JSON is parsed only to make it inspectable as structured output; all other
|
|
13
|
+
* bodies remain their original text.
|
|
14
|
+
*/
|
|
15
|
+
export function createChatV2ResponseBodyCapture() {
|
|
16
|
+
const entries = [];
|
|
17
|
+
const bodies = [];
|
|
18
|
+
return {
|
|
19
|
+
bodies,
|
|
20
|
+
capture(response) {
|
|
21
|
+
const entry = {
|
|
22
|
+
captured: false,
|
|
23
|
+
value: undefined,
|
|
24
|
+
settled: Promise.resolve(),
|
|
25
|
+
};
|
|
26
|
+
entries.push(entry);
|
|
27
|
+
try {
|
|
28
|
+
const responseClone = response.clone();
|
|
29
|
+
entry.settled = responseClone
|
|
30
|
+
.text()
|
|
31
|
+
.then((text) => {
|
|
32
|
+
entry.value = parseResponseBody(text);
|
|
33
|
+
entry.captured = true;
|
|
34
|
+
})
|
|
35
|
+
.catch(() => {
|
|
36
|
+
// The original response remains owned by the provider SDK.
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// A malformed or already-consumed Response has no safe diagnostic body.
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
async flush() {
|
|
44
|
+
// New fetches are normally sequential, but continue until no capture was
|
|
45
|
+
// added while an earlier clone was settling.
|
|
46
|
+
let observedEntryCount = 0;
|
|
47
|
+
while (observedEntryCount < entries.length) {
|
|
48
|
+
const pending = entries.slice(observedEntryCount);
|
|
49
|
+
observedEntryCount = entries.length;
|
|
50
|
+
await Promise.allSettled(pending.map((entry) => entry.settled));
|
|
51
|
+
}
|
|
52
|
+
bodies.splice(0, bodies.length, ...entries.filter((entry) => entry.captured).map((entry) => entry.value));
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Output, jsonSchema } from 'ai';
|
|
2
2
|
import { coerceTypeOptional } from '../../utils/coerceType.js';
|
|
3
3
|
import { getInputOrData } from '../../utils/inputs.js';
|
|
4
|
+
import { getCustomProviderApiContract } from './customProviderApi.js';
|
|
4
5
|
export function isChatV2StructuredResponseFormat(responseFormat) {
|
|
5
6
|
return responseFormat === 'json' || responseFormat === 'json_schema';
|
|
6
7
|
}
|
|
@@ -73,7 +74,7 @@ export function resolveChatV2ResponseFormatParameters(data, inputs) {
|
|
|
73
74
|
schemaDescription,
|
|
74
75
|
};
|
|
75
76
|
}
|
|
76
|
-
export function createChatV2ResponseOutput(parameters, provider) {
|
|
77
|
+
export function createChatV2ResponseOutput(parameters, provider, customProviderApi = 'completions') {
|
|
77
78
|
if (parameters == null) {
|
|
78
79
|
return undefined;
|
|
79
80
|
}
|
|
@@ -81,7 +82,8 @@ export function createChatV2ResponseOutput(parameters, provider) {
|
|
|
81
82
|
return Output.text();
|
|
82
83
|
}
|
|
83
84
|
if (parameters.responseFormat === 'json') {
|
|
84
|
-
if (provider === 'custom'
|
|
85
|
+
if (provider === 'custom' &&
|
|
86
|
+
getCustomProviderApiContract(customProviderApi).structuredOutput === 'raw-response-format') {
|
|
85
87
|
return undefined;
|
|
86
88
|
}
|
|
87
89
|
return Output.json({
|
|
@@ -95,8 +97,10 @@ export function createChatV2ResponseOutput(parameters, provider) {
|
|
|
95
97
|
description: parameters.schemaDescription,
|
|
96
98
|
});
|
|
97
99
|
}
|
|
98
|
-
export function mergeCustomProviderResponseFormatOptions(provider, providerOptions, parameters) {
|
|
99
|
-
if (provider !== 'custom' ||
|
|
100
|
+
export function mergeCustomProviderResponseFormatOptions(provider, providerOptions, parameters, customProviderApi = 'completions') {
|
|
101
|
+
if (provider !== 'custom' ||
|
|
102
|
+
getCustomProviderApiContract(customProviderApi).structuredOutput === 'sdk-output' ||
|
|
103
|
+
parameters == null) {
|
|
100
104
|
return providerOptions;
|
|
101
105
|
}
|
|
102
106
|
const customOptions = providerOptions?.custom ?? {};
|
|
@@ -8,14 +8,15 @@ export function normalizeLLMChatV2RetryCooldownMs(value) {
|
|
|
8
8
|
const cooldownMs = typeof value === 'number' && Number.isFinite(value) ? value : DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_COOLDOWN_MS;
|
|
9
9
|
return Math.max(0, Math.floor(cooldownMs));
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
/** Keeps cancellation identity consistent before and during a retry cooldown. */
|
|
12
|
+
export function createLLMChatV2RetryAbortError() {
|
|
12
13
|
const error = new Error('Aborted');
|
|
13
14
|
error.name = 'AbortError';
|
|
14
15
|
return error;
|
|
15
16
|
}
|
|
16
17
|
export async function waitForLLMChatV2RetryCooldown(cooldownMs, signal) {
|
|
17
18
|
if (signal.aborted) {
|
|
18
|
-
throw
|
|
19
|
+
throw createLLMChatV2RetryAbortError();
|
|
19
20
|
}
|
|
20
21
|
if (cooldownMs <= 0) {
|
|
21
22
|
return;
|
|
@@ -27,7 +28,7 @@ export async function waitForLLMChatV2RetryCooldown(cooldownMs, signal) {
|
|
|
27
28
|
};
|
|
28
29
|
const onAbort = () => {
|
|
29
30
|
cleanup();
|
|
30
|
-
reject(
|
|
31
|
+
reject(createLLMChatV2RetryAbortError());
|
|
31
32
|
};
|
|
32
33
|
const timeout = setTimeout(() => {
|
|
33
34
|
cleanup();
|
|
@@ -4,6 +4,7 @@ import { coerceTypeOptional } from '../../utils/coerceType.js';
|
|
|
4
4
|
import { cleanHeaders, getInputOrData } from '../../utils/inputs.js';
|
|
5
5
|
import { resolveChatV2Credential } from './chatV2ProviderProfile.js';
|
|
6
6
|
import { applyLLMChatV2ParallelToolCallProviderOptions } from './parallelToolCalls.js';
|
|
7
|
+
import { getCustomProviderApiContract } from './customProviderApi.js';
|
|
7
8
|
export function resolveLLMChatV2Headers(data, inputs) {
|
|
8
9
|
const resolvedHeaders = data.useHeadersInput && inputs['headers'] != null
|
|
9
10
|
? coerceTypeOptional(inputs['headers'], 'object')
|
|
@@ -57,8 +58,11 @@ export function resolveLLMChatV2ExtraProviderOptions(data, inputs) {
|
|
|
57
58
|
function resolveProviderOptions(data, inputs) {
|
|
58
59
|
const providerOptions = {};
|
|
59
60
|
const extraProviderOptions = resolveLLMChatV2ExtraProviderOptions(data, inputs);
|
|
61
|
+
const providerOptionsKey = data.provider === 'custom'
|
|
62
|
+
? getCustomProviderApiContract(data.customProviderApi).providerOptionsKey
|
|
63
|
+
: data.provider;
|
|
60
64
|
if (extraProviderOptions) {
|
|
61
|
-
providerOptions[
|
|
65
|
+
providerOptions[providerOptionsKey] = extraProviderOptions;
|
|
62
66
|
}
|
|
63
67
|
if (data.provider === 'openai') {
|
|
64
68
|
const previousResponseId = data.useOpenAIPreviousResponseIdInput && inputs['previousResponseId'] != null
|
|
@@ -128,6 +132,7 @@ export function resolveLLMChatV2RuntimeProviderOptions(data, inputs) {
|
|
|
128
132
|
provider: data.provider,
|
|
129
133
|
useToolCalling: data.useToolCalling,
|
|
130
134
|
parallelToolCalls: data.parallelToolCalls,
|
|
135
|
+
customProviderApi: data.customProviderApi,
|
|
131
136
|
providerOptions: resolveProviderOptions(data, inputs),
|
|
132
137
|
});
|
|
133
138
|
return providerOptions != null && Object.keys(providerOptions).length > 0 ? providerOptions : undefined;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Older LLM Chat nodes used Output request details as one switch for status,
|
|
3
|
-
* error, and request body. Keep that saved contract intact while newly saved
|
|
4
|
-
* nodes use the independent controls.
|
|
5
|
-
*/
|
|
6
|
-
export function shouldOutputChatV2RequestError(options) {
|
|
7
|
-
return options.outputRequestError ?? options.outputRequestStatus ?? false;
|
|
8
|
-
}
|
|
9
1
|
export function shouldOutputChatV2RequestBody(options) {
|
|
10
|
-
return options.outputRequestBody
|
|
2
|
+
return options.outputRequestBody === true;
|
|
3
|
+
}
|
|
4
|
+
/** New diagnostics are opt-in; old status-detail nodes never expose responses. */
|
|
5
|
+
export function shouldOutputChatV2ResponseBody(options) {
|
|
6
|
+
return options.outputResponseBody === true;
|
|
11
7
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The provider-neutral numeric contract shared by LLM Chat V2 usage consumers.
|
|
3
|
+
* Provider metadata is untrusted, so callers must not treat negative, NaN, or
|
|
4
|
+
* infinite token counts as real usage.
|
|
5
|
+
*/
|
|
6
|
+
export function isChatV2FiniteNonNegativeNumber(value) {
|
|
7
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Aggregates one node invocation's physical provider calls into its portable
|
|
11
|
+
* Usage output. The call id is a stable transport identity, so a redelivered
|
|
12
|
+
* lifecycle event replaces prior metadata instead of inflating totals.
|
|
13
|
+
*/
|
|
14
|
+
export function summarizeChatV2PhysicalCallUsage(events) {
|
|
15
|
+
const eventsByCallId = new Map();
|
|
16
|
+
const callIdsInOrder = [];
|
|
17
|
+
for (const event of events) {
|
|
18
|
+
const callId = event.callId;
|
|
19
|
+
if (!eventsByCallId.has(callId)) {
|
|
20
|
+
callIdsInOrder.push(callId);
|
|
21
|
+
}
|
|
22
|
+
eventsByCallId.set(callId, event);
|
|
23
|
+
}
|
|
24
|
+
let promptTokens = 0;
|
|
25
|
+
let completionTokens = 0;
|
|
26
|
+
let totalTokens = 0;
|
|
27
|
+
let cachedTokens = 0;
|
|
28
|
+
let reasoningTokens = 0;
|
|
29
|
+
let hasUsage = false;
|
|
30
|
+
let totalCost = 0;
|
|
31
|
+
let hasExactCost = callIdsInOrder.length > 0;
|
|
32
|
+
for (const callId of callIdsInOrder) {
|
|
33
|
+
const event = eventsByCallId.get(callId);
|
|
34
|
+
const usage = event.normalizedUsage;
|
|
35
|
+
const safePromptTokens = isChatV2FiniteNonNegativeNumber(usage?.promptTokens) ? usage.promptTokens : undefined;
|
|
36
|
+
const safeCompletionTokens = isChatV2FiniteNonNegativeNumber(usage?.completionTokens)
|
|
37
|
+
? usage.completionTokens
|
|
38
|
+
: undefined;
|
|
39
|
+
const safeTotalTokens = isChatV2FiniteNonNegativeNumber(usage?.totalTokens) ? usage.totalTokens : undefined;
|
|
40
|
+
const safeCachedTokens = isChatV2FiniteNonNegativeNumber(usage?.cachedTokens) ? usage.cachedTokens : undefined;
|
|
41
|
+
const safeReasoningTokens = isChatV2FiniteNonNegativeNumber(usage?.reasoningTokens)
|
|
42
|
+
? usage.reasoningTokens
|
|
43
|
+
: undefined;
|
|
44
|
+
// Physical-call traces preserve omitted fields rather than manufacturing
|
|
45
|
+
// zeros. The node-level Usage contract, however, has always exposed a
|
|
46
|
+
// total; retain that contract when a provider reports only input or output
|
|
47
|
+
// tokens by deriving a total from the safe fields that are present.
|
|
48
|
+
const totalTokensForCall = safeTotalTokens ?? (safePromptTokens ?? 0) + (safeCompletionTokens ?? 0);
|
|
49
|
+
if (safePromptTokens != null ||
|
|
50
|
+
safeCompletionTokens != null ||
|
|
51
|
+
safeTotalTokens != null ||
|
|
52
|
+
safeCachedTokens != null ||
|
|
53
|
+
safeReasoningTokens != null) {
|
|
54
|
+
hasUsage = true;
|
|
55
|
+
promptTokens += safePromptTokens ?? 0;
|
|
56
|
+
completionTokens += safeCompletionTokens ?? 0;
|
|
57
|
+
totalTokens += totalTokensForCall;
|
|
58
|
+
cachedTokens += safeCachedTokens ?? 0;
|
|
59
|
+
reasoningTokens += safeReasoningTokens ?? 0;
|
|
60
|
+
}
|
|
61
|
+
if (event.pricing.status === 'known' && isChatV2FiniteNonNegativeNumber(event.pricing.costUsd)) {
|
|
62
|
+
totalCost += event.pricing.costUsd;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
hasExactCost = false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return hasUsage
|
|
69
|
+
? {
|
|
70
|
+
promptTokens,
|
|
71
|
+
completionTokens,
|
|
72
|
+
totalTokens,
|
|
73
|
+
cachedTokens,
|
|
74
|
+
reasoningTokens,
|
|
75
|
+
totalCost: hasExactCost ? totalCost : undefined,
|
|
76
|
+
}
|
|
77
|
+
: undefined;
|
|
78
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export const customProviderApiOptions = [
|
|
2
|
+
{ value: 'completions', label: 'Completions' },
|
|
3
|
+
{ value: 'responses', label: 'Responses' },
|
|
4
|
+
];
|
|
5
|
+
const customProviderApiContracts = {
|
|
6
|
+
completions: {
|
|
7
|
+
api: 'completions',
|
|
8
|
+
adapter: 'openai-compatible',
|
|
9
|
+
providerOptionsKey: 'custom',
|
|
10
|
+
endpointPath: '/chat/completions',
|
|
11
|
+
label: 'Custom Completions',
|
|
12
|
+
structuredOutput: 'raw-response-format',
|
|
13
|
+
parallelToolCalls: 'enabled-only-raw-field',
|
|
14
|
+
},
|
|
15
|
+
responses: {
|
|
16
|
+
api: 'responses',
|
|
17
|
+
adapter: 'openai-responses',
|
|
18
|
+
providerOptionsKey: 'openai',
|
|
19
|
+
endpointPath: '/responses',
|
|
20
|
+
label: 'Custom Responses',
|
|
21
|
+
structuredOutput: 'sdk-output',
|
|
22
|
+
parallelToolCalls: 'openai-option',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Keep legacy nodes on Chat Completions while rejecting corrupt/API-authored
|
|
27
|
+
* values before a provider request is created.
|
|
28
|
+
*/
|
|
29
|
+
export function parseCustomProviderApi(value) {
|
|
30
|
+
switch (value) {
|
|
31
|
+
case undefined:
|
|
32
|
+
case 'completions':
|
|
33
|
+
return 'completions';
|
|
34
|
+
case 'responses':
|
|
35
|
+
return 'responses';
|
|
36
|
+
default:
|
|
37
|
+
throw new Error(`Unsupported Custom provider API: ${String(value)}.`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function getCustomProviderApiContract(value) {
|
|
41
|
+
return customProviderApiContracts[parseCustomProviderApi(value)];
|
|
42
|
+
}
|
|
@@ -7,8 +7,20 @@ export * from './chatV2ResponseFormat.js';
|
|
|
7
7
|
export * from './chatV2Shared.js';
|
|
8
8
|
export * from './chatV2Types.js';
|
|
9
9
|
export * from './llmProfileTypes.js';
|
|
10
|
+
export * from './llmProfileBody.js';
|
|
11
|
+
export * from './llmChatV2Body.js';
|
|
10
12
|
export * from './messageConverter.js';
|
|
11
13
|
export * from './modelRegistry.js';
|
|
12
14
|
export * from './providerOptions.js';
|
|
13
15
|
export * from './toolConverter.js';
|
|
14
16
|
export * from './toolContinuationConnection.js';
|
|
17
|
+
export * from './chatV2ProviderRegistry.js';
|
|
18
|
+
export * from './llmChatV2NodeMigration.js';
|
|
19
|
+
export * from './llmInvocationCoordinator.js';
|
|
20
|
+
export * from './llmInvocationProjections.js';
|
|
21
|
+
export * from './llmInvocationDecision.js';
|
|
22
|
+
export * from './llmChatV2CacheBoundary.js';
|
|
23
|
+
export * from './llmResponseMaterializer.js';
|
|
24
|
+
export * from './toolCallCodec.js';
|
|
25
|
+
export * from './toolHandlerResolver.js';
|
|
26
|
+
export * from './toolRoundExecutor.js';
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_COOLDOWN_MS, DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_REPEAT_TIMES, } from './chatV2Retry.js';
|
|
2
|
+
import { getChatV2ModelInfo } from './modelRegistry.js';
|
|
3
|
+
import { anthropicCacheControlTtlOptions, anthropicEffortOptions, anthropicThinkingModeOptions, getChatV2ProviderLabel, getCustomProviderApiContract, googleThinkingLevelOptions, openAIReasoningEffortOptions, openAIWebSearchContextSizeOptions, } from './providerOptions.js';
|
|
4
|
+
function getOptionLabel(options, value) {
|
|
5
|
+
const optionValue = typeof value === 'string' ? value : '';
|
|
6
|
+
return options.find((option) => option.value === optionValue)?.label ?? (optionValue || 'Default');
|
|
7
|
+
}
|
|
8
|
+
function getProviderBodyLabel(data) {
|
|
9
|
+
return data.provider === 'custom' ? 'Custom' : getChatV2ProviderLabel(data.provider);
|
|
10
|
+
}
|
|
11
|
+
function getModelBodyValue(data) {
|
|
12
|
+
if (data.useModelInput) {
|
|
13
|
+
return '(Using Input)';
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
return getChatV2ModelInfo(data.provider, data.model)?.displayName ?? data.model;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// Hand-authored/corrupt projects should remain inspectable on the canvas.
|
|
20
|
+
return data.model;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function getCustomProviderBaseURLBodyValue(data) {
|
|
24
|
+
if (data.provider !== 'custom') {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
if (data.useCustomProviderBaseURLInput) {
|
|
28
|
+
return '(Using Input)';
|
|
29
|
+
}
|
|
30
|
+
const baseURL = typeof data.customProviderBaseURL === 'string' ? data.customProviderBaseURL.trim() : '';
|
|
31
|
+
return baseURL || undefined;
|
|
32
|
+
}
|
|
33
|
+
function getCustomProviderApiBodyField(data) {
|
|
34
|
+
if (data.provider !== 'custom') {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const api = getCustomProviderApiContract(data.customProviderApi);
|
|
39
|
+
return api.api === 'completions' ? undefined : { label: 'API', value: api.label };
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return { label: 'API', value: `Unsupported (${String(data.customProviderApi)})` };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function getOptionalNumberBodyField(label, value, usesInput) {
|
|
46
|
+
if (usesInput) {
|
|
47
|
+
return { label, value: '(Using Input)' };
|
|
48
|
+
}
|
|
49
|
+
return value === undefined ? undefined : { label, value: `${value}` };
|
|
50
|
+
}
|
|
51
|
+
function getOptionalStringBodyField(label, value, usesInput) {
|
|
52
|
+
if (usesInput) {
|
|
53
|
+
return { label, value: '(Using Input)' };
|
|
54
|
+
}
|
|
55
|
+
return typeof value === 'string' && value.trim().length > 0 ? { label, value } : undefined;
|
|
56
|
+
}
|
|
57
|
+
function getStopSequencesBodyField(data) {
|
|
58
|
+
if (data.useStopSequencesInput) {
|
|
59
|
+
return { label: 'Stop sequences', value: '(Using Input)' };
|
|
60
|
+
}
|
|
61
|
+
const stopSequences = Array.isArray(data.stopSequences)
|
|
62
|
+
? data.stopSequences.filter((sequence) => typeof sequence === 'string' && sequence.length > 0)
|
|
63
|
+
: [];
|
|
64
|
+
return stopSequences.length === 0
|
|
65
|
+
? undefined
|
|
66
|
+
: { label: 'Stop sequences', value: stopSequences.map((sequence) => JSON.stringify(sequence)).join(', ') };
|
|
67
|
+
}
|
|
68
|
+
function getHeadersBodyField(data) {
|
|
69
|
+
if (data.useHeadersInput) {
|
|
70
|
+
return { label: 'Headers', value: '(Using Input)' };
|
|
71
|
+
}
|
|
72
|
+
const headers = Array.isArray(data.headers)
|
|
73
|
+
? data.headers.filter((header) => typeof header?.key === 'string' && header.key.trim().length > 0 && typeof header.value === 'string')
|
|
74
|
+
: [];
|
|
75
|
+
return headers.length > 0
|
|
76
|
+
? { label: 'Headers', value: headers.map(({ key, value }) => `${key}: ${value}`).join(', ') }
|
|
77
|
+
: undefined;
|
|
78
|
+
}
|
|
79
|
+
function getProviderBodyFields(data) {
|
|
80
|
+
switch (data.provider) {
|
|
81
|
+
case 'openai':
|
|
82
|
+
return [
|
|
83
|
+
getOptionalStringBodyField('Previous response ID', data.openAIPreviousResponseId, data.useOpenAIPreviousResponseIdInput),
|
|
84
|
+
...(data.openAIReasoningSummary ? [{ label: 'Reasoning summary', value: data.openAIReasoningSummary }] : []),
|
|
85
|
+
...(data.enableOpenAIWebSearch
|
|
86
|
+
? [
|
|
87
|
+
{
|
|
88
|
+
label: 'Web search',
|
|
89
|
+
value: `Enabled (${getOptionLabel(openAIWebSearchContextSizeOptions, data.openAIWebSearchContextSize)})`,
|
|
90
|
+
},
|
|
91
|
+
]
|
|
92
|
+
: []),
|
|
93
|
+
...(data.enableOpenAICodeInterpreter ? [{ label: 'Code interpreter', value: 'Enabled' }] : []),
|
|
94
|
+
].filter((field) => field !== undefined);
|
|
95
|
+
case 'anthropic':
|
|
96
|
+
return [
|
|
97
|
+
...(data.anthropicThinkingMode
|
|
98
|
+
? [
|
|
99
|
+
{
|
|
100
|
+
label: 'Thinking mode',
|
|
101
|
+
value: getOptionLabel(anthropicThinkingModeOptions, data.anthropicThinkingMode),
|
|
102
|
+
},
|
|
103
|
+
]
|
|
104
|
+
: []),
|
|
105
|
+
getOptionalNumberBodyField('Thinking budget', data.anthropicThinkingBudget, data.useAnthropicThinkingBudgetInput),
|
|
106
|
+
...(data.anthropicCacheControlTtl
|
|
107
|
+
? [
|
|
108
|
+
{
|
|
109
|
+
label: 'Cache breakpoint TTL',
|
|
110
|
+
value: getOptionLabel(anthropicCacheControlTtlOptions, data.anthropicCacheControlTtl),
|
|
111
|
+
},
|
|
112
|
+
]
|
|
113
|
+
: []),
|
|
114
|
+
].filter((field) => field !== undefined);
|
|
115
|
+
case 'google':
|
|
116
|
+
return [
|
|
117
|
+
getOptionalNumberBodyField('Thinking budget', data.googleThinkingBudget, data.useGoogleThinkingBudgetInput),
|
|
118
|
+
...(data.googleIncludeThoughts ? [{ label: 'Include thoughts', value: 'Enabled' }] : []),
|
|
119
|
+
...(data.enableGoogleSearchGrounding ? [{ label: 'Google search grounding', value: 'Enabled' }] : []),
|
|
120
|
+
...(data.enableGoogleUrlContext ? [{ label: 'URL context', value: 'Enabled' }] : []),
|
|
121
|
+
].filter((field) => field !== undefined);
|
|
122
|
+
case 'custom':
|
|
123
|
+
default:
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function getResponseFormatBodyFields(data) {
|
|
128
|
+
if (!data.responseFormat) {
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
const responseFormatLabel = data.responseFormat === 'json_schema' ? 'JSON schema' : data.responseFormat === 'json' ? 'JSON object' : 'Text';
|
|
132
|
+
const hasSchemaMetadata = data.responseFormat === 'json' || data.responseFormat === 'json_schema';
|
|
133
|
+
return [
|
|
134
|
+
{ label: 'Response format', value: responseFormatLabel },
|
|
135
|
+
...(hasSchemaMetadata
|
|
136
|
+
? [
|
|
137
|
+
getOptionalStringBodyField('Schema name', data.responseSchemaName, !!data.useResponseSchemaNameInput),
|
|
138
|
+
getOptionalStringBodyField('Schema description', data.responseSchemaDescription, !!data.useResponseSchemaDescriptionInput),
|
|
139
|
+
]
|
|
140
|
+
: []),
|
|
141
|
+
].filter((field) => field !== undefined);
|
|
142
|
+
}
|
|
143
|
+
function getToolBodyFields(data) {
|
|
144
|
+
if (!data.useToolCalling) {
|
|
145
|
+
return [];
|
|
146
|
+
}
|
|
147
|
+
return [
|
|
148
|
+
{ label: 'Tool use', value: 'Enabled' },
|
|
149
|
+
...(data.toolChoice
|
|
150
|
+
? [
|
|
151
|
+
{
|
|
152
|
+
label: 'Tool choice',
|
|
153
|
+
value: data.toolChoice === 'function'
|
|
154
|
+
? data.toolChoiceFunction?.trim()
|
|
155
|
+
? `Specific tool (${data.toolChoiceFunction})`
|
|
156
|
+
: 'Specific tool'
|
|
157
|
+
: data.toolChoice === 'required'
|
|
158
|
+
? 'Required'
|
|
159
|
+
: 'Auto',
|
|
160
|
+
},
|
|
161
|
+
]
|
|
162
|
+
: []),
|
|
163
|
+
...(data.parallelToolCalls ? [{ label: 'Parallel toolcalls', value: 'Enabled' }] : []),
|
|
164
|
+
...(data.autoContinueToolCalls
|
|
165
|
+
? [
|
|
166
|
+
{ label: 'Auto-continue toolcalls', value: 'Enabled' },
|
|
167
|
+
{ label: 'Maximum tool rounds', value: `${data.maxToolRounds ?? 3}` },
|
|
168
|
+
]
|
|
169
|
+
: []),
|
|
170
|
+
];
|
|
171
|
+
}
|
|
172
|
+
function getBehaviorBodyFields(data) {
|
|
173
|
+
return [
|
|
174
|
+
...(data.useAsGraphPartialOutput === false ? [{ label: 'Stream response', value: 'Disabled' }] : []),
|
|
175
|
+
...(data.cache ? [{ label: 'Editor cache (legacy)', value: 'Enabled' }] : []),
|
|
176
|
+
];
|
|
177
|
+
}
|
|
178
|
+
function getErrorBodyFields(data) {
|
|
179
|
+
if (!data.retryOnNon200) {
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
const repeatTimes = data.retryOnNon200RepeatTimes ?? DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_REPEAT_TIMES;
|
|
183
|
+
const cooldownMs = data.retryOnNon200CooldownMs ?? DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_COOLDOWN_MS;
|
|
184
|
+
return [
|
|
185
|
+
{ label: 'Retry on non-200', value: 'Enabled' },
|
|
186
|
+
{ label: 'Repeat times', value: `${repeatTimes}` },
|
|
187
|
+
{ label: 'Cooldown, ms', value: `${cooldownMs}` },
|
|
188
|
+
];
|
|
189
|
+
}
|
|
190
|
+
function getAdvancedBodySection(data) {
|
|
191
|
+
const extraProviderOptions = !data.useExtraProviderOptionsInput &&
|
|
192
|
+
typeof data.extraProviderOptions === 'string' &&
|
|
193
|
+
data.extraProviderOptions.trim().length > 0
|
|
194
|
+
? { label: 'Extra provider options', text: data.extraProviderOptions }
|
|
195
|
+
: undefined;
|
|
196
|
+
return {
|
|
197
|
+
id: 'advanced',
|
|
198
|
+
fields: [
|
|
199
|
+
getHeadersBodyField(data),
|
|
200
|
+
...(data.useExtraProviderOptionsInput ? [{ label: 'Extra provider options', value: '(Using Input)' }] : []),
|
|
201
|
+
].filter((field) => field !== undefined),
|
|
202
|
+
snippet: extraProviderOptions,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
function getInlineModelBodyFields(data) {
|
|
206
|
+
const customBaseURL = getCustomProviderBaseURLBodyValue(data);
|
|
207
|
+
return [
|
|
208
|
+
{ label: 'Provider', value: getProviderBodyLabel(data) },
|
|
209
|
+
getCustomProviderApiBodyField(data),
|
|
210
|
+
customBaseURL ? { label: 'Base URL', value: customBaseURL } : undefined,
|
|
211
|
+
{ label: 'Model', value: getModelBodyValue(data) },
|
|
212
|
+
...(data.apiKeySource === 'input' ? [{ label: 'API key source', value: 'Input port' }] : []),
|
|
213
|
+
...(data.provider === 'custom' && data.apiKeySource !== 'input'
|
|
214
|
+
? [
|
|
215
|
+
data.customProviderApiKeyProgrammaticName?.trim()
|
|
216
|
+
? { label: 'Alternative programmatic key', value: data.customProviderApiKeyProgrammaticName }
|
|
217
|
+
: undefined,
|
|
218
|
+
data.customProviderApiKeyEnvVarName?.trim() &&
|
|
219
|
+
data.customProviderApiKeyEnvVarName !== 'CUSTOM_PROVIDER_API_KEY'
|
|
220
|
+
? { label: 'Alternative API key env var', value: data.customProviderApiKeyEnvVarName }
|
|
221
|
+
: undefined,
|
|
222
|
+
]
|
|
223
|
+
: []),
|
|
224
|
+
].filter((field) => field !== undefined);
|
|
225
|
+
}
|
|
226
|
+
function getParameterBodyFields(data) {
|
|
227
|
+
const reasoningEffort = data.provider === 'openai'
|
|
228
|
+
? getOptionLabel(openAIReasoningEffortOptions, data.openAIReasoningEffort)
|
|
229
|
+
: data.provider === 'anthropic'
|
|
230
|
+
? getOptionLabel(anthropicEffortOptions, data.anthropicEffort)
|
|
231
|
+
: data.provider === 'google'
|
|
232
|
+
? getOptionLabel(googleThinkingLevelOptions, data.googleThinkingLevel)
|
|
233
|
+
: undefined;
|
|
234
|
+
return [
|
|
235
|
+
...(reasoningEffort ? [{ label: 'Reasoning effort', value: reasoningEffort }] : []),
|
|
236
|
+
{ label: 'Temperature', value: data.useTemperatureInput ? '(Using Input)' : `${data.temperature}` },
|
|
237
|
+
{ label: 'Max output tokens', value: data.useMaxTokensInput ? '(Using Input)' : `${data.maxTokens}` },
|
|
238
|
+
getOptionalNumberBodyField('Top P', data.topP, data.useTopPInput),
|
|
239
|
+
getOptionalNumberBodyField('Top K', data.topK, data.useTopKInput),
|
|
240
|
+
getOptionalNumberBodyField('Presence penalty', data.presencePenalty, data.usePresencePenaltyInput),
|
|
241
|
+
getOptionalNumberBodyField('Frequency penalty', data.frequencyPenalty, data.useFrequencyPenaltyInput),
|
|
242
|
+
getStopSequencesBodyField(data),
|
|
243
|
+
getOptionalNumberBodyField('Seed', data.seed, data.useSeedInput),
|
|
244
|
+
].filter((field) => field !== undefined);
|
|
245
|
+
}
|
|
246
|
+
function getInvocationSections(data) {
|
|
247
|
+
const sections = [
|
|
248
|
+
{ id: 'response-format', fields: getResponseFormatBodyFields(data) },
|
|
249
|
+
{ id: 'tools', fields: getToolBodyFields(data) },
|
|
250
|
+
{ id: 'behavior', fields: getBehaviorBodyFields(data) },
|
|
251
|
+
{ id: 'error', fields: getErrorBodyFields(data) },
|
|
252
|
+
];
|
|
253
|
+
return sections.filter((section) => section.fields.length > 0);
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Stable canvas presentation data for LLM Chat configuration.
|
|
257
|
+
*
|
|
258
|
+
* Inline mode exposes its local model/provider settings plus every active
|
|
259
|
+
* invocation setting. Profile mode deliberately exposes only invocation-owned
|
|
260
|
+
* settings because provider configuration comes from the connected LLM Profile
|
|
261
|
+
* value at runtime. Output toggles are intentionally omitted: their ports are
|
|
262
|
+
* already the canonical canvas indication that an output is enabled.
|
|
263
|
+
*/
|
|
264
|
+
export function getLLMChatV2BodySections(data) {
|
|
265
|
+
if (data.configurationMode === 'profile') {
|
|
266
|
+
const sections = [
|
|
267
|
+
{ id: 'configuration', fields: [{ label: 'Configuration', value: 'From LLM Profiles input' }] },
|
|
268
|
+
...getInvocationSections(data),
|
|
269
|
+
];
|
|
270
|
+
return sections;
|
|
271
|
+
}
|
|
272
|
+
const advancedSection = getAdvancedBodySection(data);
|
|
273
|
+
const sections = [
|
|
274
|
+
{ id: 'model', fields: getInlineModelBodyFields(data) },
|
|
275
|
+
{ id: 'parameters', fields: getParameterBodyFields(data) },
|
|
276
|
+
{ id: 'provider', fields: getProviderBodyFields(data) },
|
|
277
|
+
...getInvocationSections(data),
|
|
278
|
+
advancedSection,
|
|
279
|
+
];
|
|
280
|
+
return sections.filter((section) => section.fields.length > 0 || section.snippet !== undefined);
|
|
281
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { isChatV2PipelineProviderFailureResult } from './chatV2Pipeline.js';
|
|
2
|
+
import { cloneLLMChatV2EditorCacheOutputs } from './chatV2EditorCache.js';
|
|
3
|
+
/** Projects cache hits as current-run output without inventing provider work. */
|
|
4
|
+
export function projectLLMChatV2EditorCacheHit(runtime) {
|
|
5
|
+
const outputs = runtime.cachedOutputs;
|
|
6
|
+
if (outputs == null)
|
|
7
|
+
return undefined;
|
|
8
|
+
if (runtime.getProfileSummary != null) {
|
|
9
|
+
outputs['llmProfileSummary'] = {
|
|
10
|
+
type: 'string',
|
|
11
|
+
value: 'Editor cache hit — no LLM Profile calls were made for this run.',
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
if (runtime.outputLLMAttempts) {
|
|
15
|
+
outputs['llmAttempts'] = { type: 'object[]', value: [] };
|
|
16
|
+
}
|
|
17
|
+
return outputs;
|
|
18
|
+
}
|
|
19
|
+
/** Caches only final model answers; failed invocations never reach this boundary. */
|
|
20
|
+
export function writeLLMChatV2EditorCache(params) {
|
|
21
|
+
const { runtime, result } = params;
|
|
22
|
+
if (runtime.cacheKey == null ||
|
|
23
|
+
runtime.editorCache == null ||
|
|
24
|
+
runtime.isProfileFallbackExhausted() ||
|
|
25
|
+
isChatV2PipelineProviderFailureResult(result)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const cacheOutputs = cloneLLMChatV2EditorCacheOutputs(result.commonOutputs);
|
|
29
|
+
delete cacheOutputs['llmAttempts'];
|
|
30
|
+
delete cacheOutputs['llmProfileSummary'];
|
|
31
|
+
runtime.editorCache.set(runtime.cacheKey, cacheOutputs);
|
|
32
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Editor-cache replay is safe only for ordinary deterministic model calls.
|
|
3
|
+
* Tool-capable calls can have side effects or live Delegate run shapes that a
|
|
4
|
+
* cached final output cannot reproduce.
|
|
5
|
+
*/
|
|
6
|
+
export function getLLMChatV2EditorCacheEligibility(data) {
|
|
7
|
+
if (!data.cache) {
|
|
8
|
+
return { eligible: false, reason: 'disabled' };
|
|
9
|
+
}
|
|
10
|
+
if (data.useToolCalling) {
|
|
11
|
+
return { eligible: false, reason: 'rivet-tools' };
|
|
12
|
+
}
|
|
13
|
+
if (data.enableOpenAIWebSearch ||
|
|
14
|
+
data.enableOpenAICodeInterpreter ||
|
|
15
|
+
data.enableGoogleSearchGrounding ||
|
|
16
|
+
data.enableGoogleUrlContext) {
|
|
17
|
+
return { eligible: false, reason: 'provider-native-tools' };
|
|
18
|
+
}
|
|
19
|
+
return { eligible: true };
|
|
20
|
+
}
|