@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
|
@@ -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,63 @@
|
|
|
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
|
+
const publishSettledBodies = () => {
|
|
19
|
+
bodies.splice(0, bodies.length, ...entries.filter((entry) => entry.captured).map((entry) => entry.value));
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
bodies,
|
|
23
|
+
capture(response) {
|
|
24
|
+
const entry = {
|
|
25
|
+
captured: false,
|
|
26
|
+
value: undefined,
|
|
27
|
+
settled: Promise.resolve(),
|
|
28
|
+
};
|
|
29
|
+
entries.push(entry);
|
|
30
|
+
try {
|
|
31
|
+
const responseClone = response.clone();
|
|
32
|
+
entry.settled = responseClone
|
|
33
|
+
.text()
|
|
34
|
+
.then((text) => {
|
|
35
|
+
entry.value = parseResponseBody(text);
|
|
36
|
+
entry.captured = true;
|
|
37
|
+
publishSettledBodies();
|
|
38
|
+
})
|
|
39
|
+
.catch(() => {
|
|
40
|
+
// The original response remains owned by the provider SDK.
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// A malformed or already-consumed Response has no safe diagnostic body.
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
async flush(options = {}) {
|
|
48
|
+
if (options.waitForPending === false) {
|
|
49
|
+
publishSettledBodies();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
// New fetches are normally sequential, but continue until no capture was
|
|
53
|
+
// added while an earlier clone was settling.
|
|
54
|
+
let observedEntryCount = 0;
|
|
55
|
+
while (observedEntryCount < entries.length) {
|
|
56
|
+
const pending = entries.slice(observedEntryCount);
|
|
57
|
+
observedEntryCount = entries.length;
|
|
58
|
+
await Promise.allSettled(pending.map((entry) => entry.settled));
|
|
59
|
+
}
|
|
60
|
+
publishSettledBodies();
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -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();
|
|
@@ -2,6 +2,7 @@ import { createGoogleGenerativeAI } from '@ai-sdk/google';
|
|
|
2
2
|
import { createOpenAI } from '@ai-sdk/openai';
|
|
3
3
|
import { coerceTypeOptional } from '../../utils/coerceType.js';
|
|
4
4
|
import { cleanHeaders, getInputOrData } from '../../utils/inputs.js';
|
|
5
|
+
import { cloneRivetStoredValue } from '../StoredValueStore.js';
|
|
5
6
|
import { resolveChatV2Credential } from './chatV2ProviderProfile.js';
|
|
6
7
|
import { applyLLMChatV2ParallelToolCallProviderOptions } from './parallelToolCalls.js';
|
|
7
8
|
export function resolveLLMChatV2Headers(data, inputs) {
|
|
@@ -17,6 +18,7 @@ export function resolveLLMChatV2ApiKey(data, inputs, context) {
|
|
|
17
18
|
context,
|
|
18
19
|
apiKeySource: data.apiKeySource === 'input' ? 'input' : 'configured',
|
|
19
20
|
inputs,
|
|
21
|
+
providerApiKeyNames: data.providerApiKeyNames,
|
|
20
22
|
customProgrammaticName: data.customProviderApiKeyProgrammaticName,
|
|
21
23
|
customEnvironmentName: data.customProviderApiKeyEnvVarName,
|
|
22
24
|
}).value;
|
|
@@ -37,16 +39,17 @@ function parseExtraProviderOptionsText(rawText) {
|
|
|
37
39
|
return normalizeExtraProviderOptions(parsed);
|
|
38
40
|
}
|
|
39
41
|
function normalizeExtraProviderOptions(value) {
|
|
40
|
-
if (value
|
|
42
|
+
if (value === undefined) {
|
|
41
43
|
return undefined;
|
|
42
44
|
}
|
|
43
45
|
if (typeof value === 'string') {
|
|
44
46
|
return parseExtraProviderOptionsText(value);
|
|
45
47
|
}
|
|
46
|
-
|
|
48
|
+
const cloned = cloneRivetStoredValue(value, 'Extra provider options');
|
|
49
|
+
if (cloned === null || typeof cloned !== 'object' || Array.isArray(cloned)) {
|
|
47
50
|
throw new Error('Extra provider options must be a JSON object.');
|
|
48
51
|
}
|
|
49
|
-
return
|
|
52
|
+
return cloned;
|
|
50
53
|
}
|
|
51
54
|
export function resolveLLMChatV2ExtraProviderOptions(data, inputs) {
|
|
52
55
|
if (!data.useExtraProviderOptionsInput) {
|
|
@@ -56,10 +59,6 @@ export function resolveLLMChatV2ExtraProviderOptions(data, inputs) {
|
|
|
56
59
|
}
|
|
57
60
|
function resolveProviderOptions(data, inputs) {
|
|
58
61
|
const providerOptions = {};
|
|
59
|
-
const extraProviderOptions = resolveLLMChatV2ExtraProviderOptions(data, inputs);
|
|
60
|
-
if (extraProviderOptions) {
|
|
61
|
-
providerOptions[data.provider] = extraProviderOptions;
|
|
62
|
-
}
|
|
63
62
|
if (data.provider === 'openai') {
|
|
64
63
|
const previousResponseId = data.useOpenAIPreviousResponseIdInput && inputs['previousResponseId'] != null
|
|
65
64
|
? coerceTypeOptional(inputs['previousResponseId'], 'string')
|
|
@@ -128,6 +127,7 @@ export function resolveLLMChatV2RuntimeProviderOptions(data, inputs) {
|
|
|
128
127
|
provider: data.provider,
|
|
129
128
|
useToolCalling: data.useToolCalling,
|
|
130
129
|
parallelToolCalls: data.parallelToolCalls,
|
|
130
|
+
customProviderApi: data.customProviderApi,
|
|
131
131
|
providerOptions: resolveProviderOptions(data, inputs),
|
|
132
132
|
});
|
|
133
133
|
return providerOptions != null && Object.keys(providerOptions).length > 0 ? providerOptions : undefined;
|
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export class ChatV2ProviderTimeoutError extends Error {
|
|
2
|
+
timeoutKind;
|
|
3
|
+
timeoutMs;
|
|
4
|
+
code = 'RIVET_LLM_PROVIDER_TIMEOUT';
|
|
5
|
+
constructor(timeoutKind, timeoutMs) {
|
|
6
|
+
super(timeoutKind === 'first-output'
|
|
7
|
+
? `LLM provider did not produce a useful response within ${timeoutMs} ms.`
|
|
8
|
+
: `LLM provider stream produced no activity for ${timeoutMs} ms.`);
|
|
9
|
+
this.timeoutKind = timeoutKind;
|
|
10
|
+
this.timeoutMs = timeoutMs;
|
|
11
|
+
this.name = 'ChatV2ProviderTimeoutError';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function isChatV2ProviderTimeoutError(error) {
|
|
15
|
+
return error instanceof ChatV2ProviderTimeoutError;
|
|
8
16
|
}
|
|
9
17
|
export function shouldOutputChatV2RequestBody(options) {
|
|
10
|
-
return options.outputRequestBody
|
|
18
|
+
return options.outputRequestBody === true;
|
|
19
|
+
}
|
|
20
|
+
/** New diagnostics are opt-in; old status-detail nodes never expose responses. */
|
|
21
|
+
export function shouldOutputChatV2ResponseBody(options) {
|
|
22
|
+
return options.outputResponseBody === true;
|
|
11
23
|
}
|
|
@@ -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,40 @@
|
|
|
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
|
+
endpointPath: '/chat/completions',
|
|
10
|
+
label: 'Custom Completions',
|
|
11
|
+
structuredOutput: 'raw-response-format',
|
|
12
|
+
parallelToolCalls: 'enabled-only-raw-field',
|
|
13
|
+
},
|
|
14
|
+
responses: {
|
|
15
|
+
api: 'responses',
|
|
16
|
+
adapter: 'openai-responses',
|
|
17
|
+
endpointPath: '/responses',
|
|
18
|
+
label: 'Custom Responses',
|
|
19
|
+
structuredOutput: 'sdk-output',
|
|
20
|
+
parallelToolCalls: 'openai-option',
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Keep legacy nodes on Chat Completions while rejecting corrupt/API-authored
|
|
25
|
+
* values before a provider request is created.
|
|
26
|
+
*/
|
|
27
|
+
export function parseCustomProviderApi(value) {
|
|
28
|
+
switch (value) {
|
|
29
|
+
case undefined:
|
|
30
|
+
case 'completions':
|
|
31
|
+
return 'completions';
|
|
32
|
+
case 'responses':
|
|
33
|
+
return 'responses';
|
|
34
|
+
default:
|
|
35
|
+
throw new Error(`Unsupported Custom provider API: ${String(value)}.`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function getCustomProviderApiContract(value) {
|
|
39
|
+
return customProviderApiContracts[parseCustomProviderApi(value)];
|
|
40
|
+
}
|
|
@@ -2,13 +2,28 @@ export * from './aiSdkBridge.js';
|
|
|
2
2
|
export * from './chatV2FeatureCompatibility.js';
|
|
3
3
|
export * from './chatV2Pipeline.js';
|
|
4
4
|
export * from './chatV2ProviderProfile.js';
|
|
5
|
+
export * from './chatV2CredentialNames.js';
|
|
5
6
|
export * from './chatV2RequestPlan.js';
|
|
6
7
|
export * from './chatV2ResponseFormat.js';
|
|
7
8
|
export * from './chatV2Shared.js';
|
|
8
9
|
export * from './chatV2Types.js';
|
|
9
10
|
export * from './llmProfileTypes.js';
|
|
11
|
+
export * from './llmProfileHealthStore.js';
|
|
12
|
+
export * from './llmProfileBody.js';
|
|
13
|
+
export * from './llmChatV2Body.js';
|
|
10
14
|
export * from './messageConverter.js';
|
|
11
15
|
export * from './modelRegistry.js';
|
|
12
16
|
export * from './providerOptions.js';
|
|
13
17
|
export * from './toolConverter.js';
|
|
14
18
|
export * from './toolContinuationConnection.js';
|
|
19
|
+
export * from './chatV2ProviderRegistry.js';
|
|
20
|
+
export * from './llmChatV2NodeMigration.js';
|
|
21
|
+
export * from './llmChatV2NodeData.js';
|
|
22
|
+
export * from './llmInvocationCoordinator.js';
|
|
23
|
+
export * from './llmInvocationProjections.js';
|
|
24
|
+
export * from './llmInvocationDecision.js';
|
|
25
|
+
export * from './llmChatV2CacheBoundary.js';
|
|
26
|
+
export * from './llmResponseMaterializer.js';
|
|
27
|
+
export * from './toolCallCodec.js';
|
|
28
|
+
export * from './toolHandlerResolver.js';
|
|
29
|
+
export * from './toolRoundExecutor.js';
|