@valerypopoff/rivet2-core 2.1.8 → 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 +4457 -1809
- 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 +152 -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 +68 -18
- package/dist/esm/model/SubprocessorBridge.js +2 -0
- package/dist/esm/model/ToolCallContinuationCoordinator.js +13 -4
- 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/aiSdkMessages.js +8 -0
- package/dist/esm/model/chat/aiSdkTools.js +3 -2
- package/dist/esm/model/chat-v2/chatV2CallObserver.js +11 -5
- package/dist/esm/model/chat-v2/chatV2EditorCache.js +58 -10
- 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 +56 -106
- package/dist/esm/model/chat-v2/chatV2Pipeline.js +142 -149
- package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +9 -2
- package/dist/esm/model/chat-v2/chatV2ProviderRegistry.js +9 -0
- package/dist/esm/model/chat-v2/chatV2RequestPlan.js +5 -5
- 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/chatV2Shared.js +1 -6
- package/dist/esm/model/chat-v2/chatV2Types.js +7 -1
- 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/developerMessageRoles.js +45 -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 +8 -54
- package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +41 -20
- package/dist/esm/model/chat-v2/llmChatV2NodeMigration.js +24 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +178 -94
- 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 +31 -65
- package/dist/esm/model/chat-v2/llmProfileBody.js +183 -0
- package/dist/esm/model/chat-v2/llmProfileFallback.js +244 -0
- 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/messageConverter.js +14 -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 +120 -21
- 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 -39
- 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/AssembleMessageNode.js +6 -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 +26 -1
- package/dist/esm/model/nodes/LLMChatV2Node.js +131 -144
- package/dist/esm/model/nodes/LLMProfileNode.js +27 -8
- package/dist/esm/model/nodes/PromptNode.js +16 -2
- package/dist/esm/model/nodes/ToolNode.js +7 -0
- package/dist/esm/model/nodes/toolCallDelegation.js +193 -110
- package/dist/esm/plugins/anthropic/anthropic.js +4 -4
- package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +29 -28
- package/dist/esm/plugins/google/google.js +25 -18
- package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +21 -7
- package/dist/esm/recording/ExecutionRecorder.js +13 -5
- package/dist/esm/utils/chatMessageToOpenAIChatCompletionMessage.js +4 -0
- package/dist/esm/utils/emitDetached.js +6 -3
- package/dist/esm/utils/openai.js +60 -16
- package/dist/esm/utils/serialization/serialization.js +2 -0
- 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/DataValue.d.ts +7 -1
- package/dist/types/model/ExecutorProtocol.d.ts +25 -7
- package/dist/types/model/GraphProcessor.d.ts +27 -5
- package/dist/types/model/NodeBase.d.ts +6 -0
- 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 +51 -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 +11 -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 +3 -1
- package/dist/types/model/chat-v2/chatV2Outputs.d.ts +7 -17
- package/dist/types/model/chat-v2/chatV2Pipeline.d.ts +29 -0
- package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +5 -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/chatV2Shared.d.ts +0 -1
- package/dist/types/model/chat-v2/chatV2Types.d.ts +35 -1
- 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/developerMessageRoles.d.ts +10 -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 +13 -3
- package/dist/types/model/chat-v2/llmChatV2NodeMigration.d.ts +8 -0
- package/dist/types/model/chat-v2/llmChatV2NodeRuntime.d.ts +18 -4
- 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/llmProfile.d.ts +7 -0
- package/dist/types/model/chat-v2/llmProfileBody.d.ts +20 -0
- package/dist/types/model/chat-v2/llmProfileFallback.d.ts +47 -0
- 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 +11 -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/AssembleMessageNode.d.ts +2 -1
- 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 +6 -3
- 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 +14 -9
- package/dist/types/plugins/google/nodes/ChatGoogleNode.d.ts +2 -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
|
@@ -9,10 +9,6 @@ const STATUS_TEXT = {
|
|
|
9
9
|
422: 'Unprocessable Entity',
|
|
10
10
|
429: 'Rate Limited',
|
|
11
11
|
};
|
|
12
|
-
function compact(value, maxLength = 500) {
|
|
13
|
-
const normalized = value.replace(/\s+/g, ' ').trim();
|
|
14
|
-
return normalized.length > maxLength ? `${normalized.slice(0, maxLength - 3)}...` : normalized;
|
|
15
|
-
}
|
|
16
12
|
function isRecord(value) {
|
|
17
13
|
if (value == null || typeof value !== 'object') {
|
|
18
14
|
return false;
|
|
@@ -37,13 +33,13 @@ function stringifyProviderValue(value) {
|
|
|
37
33
|
return undefined;
|
|
38
34
|
}
|
|
39
35
|
if (typeof value === 'string') {
|
|
40
|
-
return
|
|
36
|
+
return value;
|
|
41
37
|
}
|
|
42
38
|
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
43
39
|
return String(value);
|
|
44
40
|
}
|
|
45
41
|
try {
|
|
46
|
-
return
|
|
42
|
+
return JSON.stringify(value);
|
|
47
43
|
}
|
|
48
44
|
catch {
|
|
49
45
|
return undefined;
|
|
@@ -71,7 +67,7 @@ function parseResponseBodyMessage(responseBody) {
|
|
|
71
67
|
return findProviderMessage(JSON.parse(responseBody));
|
|
72
68
|
}
|
|
73
69
|
catch {
|
|
74
|
-
return
|
|
70
|
+
return responseBody;
|
|
75
71
|
}
|
|
76
72
|
}
|
|
77
73
|
function getProviderMessage(error, seen = new Set()) {
|
|
@@ -108,15 +104,7 @@ function getProviderMessage(error, seen = new Set()) {
|
|
|
108
104
|
return findProviderMessage(error);
|
|
109
105
|
}
|
|
110
106
|
function formatEndpoint(url) {
|
|
111
|
-
|
|
112
|
-
const parsed = new URL(url);
|
|
113
|
-
parsed.search = '';
|
|
114
|
-
parsed.hash = '';
|
|
115
|
-
return parsed.toString();
|
|
116
|
-
}
|
|
117
|
-
catch {
|
|
118
|
-
return compact(url.split(/[?#]/, 1)[0] ?? url);
|
|
119
|
-
}
|
|
107
|
+
return url;
|
|
120
108
|
}
|
|
121
109
|
function getApiCallRecommendation(statusCode, context) {
|
|
122
110
|
switch (statusCode) {
|
|
@@ -224,7 +212,7 @@ function formatProviderFetchError(error, context) {
|
|
|
224
212
|
`Model: ${context.modelId}`,
|
|
225
213
|
'The browser/runtime fetch layer hid the provider response. In Browser executor mode this commonly happens because of CORS or a provider-side request rejection.',
|
|
226
214
|
'Check the API key source, provider URL, and network access. Use the Node executor when you need the exact provider HTTP status.',
|
|
227
|
-
|
|
215
|
+
error.message,
|
|
228
216
|
].join('\n');
|
|
229
217
|
}
|
|
230
218
|
function formatApiCallError(error, context) {
|
|
@@ -259,7 +247,7 @@ function formatKnownSdkError(error, context) {
|
|
|
259
247
|
'LLM API key could not be loaded.',
|
|
260
248
|
`Provider: ${getChatV2ProviderLabel(context.provider)}`,
|
|
261
249
|
'Check the API key source and configured provider credentials.',
|
|
262
|
-
|
|
250
|
+
error.message,
|
|
263
251
|
].join('\n');
|
|
264
252
|
}
|
|
265
253
|
if (hasSdkErrorName(error, 'UnsupportedFunctionalityError')) {
|
|
@@ -277,7 +265,7 @@ function formatKnownSdkError(error, context) {
|
|
|
277
265
|
`Provider: ${getChatV2ProviderLabel(context.provider)}`,
|
|
278
266
|
`Model: ${context.modelId}`,
|
|
279
267
|
'Check the response format settings and provider response.',
|
|
280
|
-
|
|
268
|
+
error.message,
|
|
281
269
|
].join('\n');
|
|
282
270
|
}
|
|
283
271
|
return undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isChatV2StructuredResponseFormat
|
|
1
|
+
import { isChatV2StructuredResponseFormat } from './chatV2ResponseFormat.js';
|
|
2
2
|
export const LLM_CHAT_V2_TOOL_RESPONSE_FORMAT_CONFLICT_COPY = {
|
|
3
3
|
title: '"Tool use" conflicts with "Structured outputs"',
|
|
4
4
|
paragraphs: [
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { inferType } from '../../utils/coerceType.js';
|
|
2
2
|
import { createAssistantMessagesOutput } from '../chat/streamChatResponse.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import { materializeLLMResponse } from './llmResponseMaterializer.js';
|
|
4
|
+
import { calculateChatV2UsageCost } from './modelRegistry.js';
|
|
5
|
+
import { isChatV2FiniteNonNegativeNumber } from './chatV2UsageAccounting.js';
|
|
6
|
+
import { shouldOutputChatV2RequestBody, shouldOutputChatV2ResponseBody, } from './chatV2Types.js';
|
|
7
7
|
const CHAT_V2_REQUEST_BODY_PORT_ID = 'requestBody';
|
|
8
|
+
const CHAT_V2_RESPONSE_BODY_PORT_ID = 'responseBody';
|
|
8
9
|
function toFunctionCallOutputValue(functionCall) {
|
|
9
10
|
let argumentsValue = functionCall.lastParsedArguments;
|
|
10
11
|
if (argumentsValue == null) {
|
|
@@ -31,34 +32,38 @@ export function normalizeChatV2Usage(usage, options) {
|
|
|
31
32
|
if (usage == null) {
|
|
32
33
|
return undefined;
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
const
|
|
35
|
+
// Provider usage metadata crosses a runtime boundary and can be malformed.
|
|
36
|
+
// Keep the node's portable Usage output aligned with the physical-call
|
|
37
|
+
// observer: only finite, non-negative token counts are meaningful.
|
|
38
|
+
const promptTokens = isChatV2FiniteNonNegativeNumber(usage.inputTokens) ? usage.inputTokens : 0;
|
|
39
|
+
const completionTokens = isChatV2FiniteNonNegativeNumber(usage.outputTokens) ? usage.outputTokens : 0;
|
|
40
|
+
const totalTokens = isChatV2FiniteNonNegativeNumber(usage.totalTokens)
|
|
41
|
+
? usage.totalTokens
|
|
42
|
+
: promptTokens + completionTokens;
|
|
43
|
+
const cachedTokens = (isChatV2FiniteNonNegativeNumber(usage.inputTokenDetails?.cacheReadTokens)
|
|
44
|
+
? usage.inputTokenDetails.cacheReadTokens
|
|
45
|
+
: 0) +
|
|
46
|
+
(isChatV2FiniteNonNegativeNumber(usage.inputTokenDetails?.cacheWriteTokens)
|
|
47
|
+
? usage.inputTokenDetails.cacheWriteTokens
|
|
48
|
+
: 0);
|
|
49
|
+
const reasoningTokens = isChatV2FiniteNonNegativeNumber(usage.outputTokenDetails?.reasoningTokens)
|
|
50
|
+
? usage.outputTokenDetails.reasoningTokens
|
|
51
|
+
: 0;
|
|
39
52
|
return {
|
|
40
53
|
promptTokens,
|
|
41
54
|
completionTokens,
|
|
42
55
|
totalTokens,
|
|
43
56
|
cachedTokens,
|
|
44
57
|
reasoningTokens,
|
|
45
|
-
totalCost:
|
|
58
|
+
totalCost: calculateChatV2UsageCost(options.provider, options.modelId, usage),
|
|
46
59
|
};
|
|
47
60
|
}
|
|
48
|
-
function
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
function createChatV2ResponseOutput(response, structuredOutput, responseFormat) {
|
|
57
|
-
if (!isChatV2StructuredResponseFormat(responseFormat)) {
|
|
58
|
-
return { type: 'string', value: response };
|
|
59
|
-
}
|
|
60
|
-
const parsedOutput = structuredOutput !== undefined ? structuredOutput : tryParseStructuredResponseText(response);
|
|
61
|
-
return parsedOutput !== undefined ? inferType(parsedOutput) : { type: 'string', value: response };
|
|
61
|
+
export function createChatV2ResponseOutput(response, structuredOutput, responseFormat) {
|
|
62
|
+
return materializeLLMResponse({
|
|
63
|
+
rawText: response,
|
|
64
|
+
structuredOutput,
|
|
65
|
+
responseFormat,
|
|
66
|
+
}).value;
|
|
62
67
|
}
|
|
63
68
|
function createChatV2ReasoningOutput(reasoning) {
|
|
64
69
|
if (Array.isArray(reasoning)) {
|
|
@@ -78,37 +83,38 @@ function createChatV2ReasoningOutput(reasoning) {
|
|
|
78
83
|
}
|
|
79
84
|
: createControlFlowExcludedOutput();
|
|
80
85
|
}
|
|
81
|
-
function
|
|
82
|
-
if (
|
|
86
|
+
function createChatV2CapturedBodiesOutput(bodies) {
|
|
87
|
+
if (bodies == null || bodies.length === 0) {
|
|
83
88
|
return createControlFlowExcludedOutput();
|
|
84
89
|
}
|
|
85
|
-
return inferType(
|
|
90
|
+
return inferType(bodies.length === 1 ? bodies[0] : bodies);
|
|
86
91
|
}
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
export function createChatV2CapturedBodyOutputs(options) {
|
|
93
|
+
const outputs = {};
|
|
94
|
+
if (shouldOutputChatV2RequestBody(options)) {
|
|
95
|
+
outputs[CHAT_V2_REQUEST_BODY_PORT_ID] = createChatV2CapturedBodiesOutput(options.requestBodies);
|
|
96
|
+
}
|
|
97
|
+
if (shouldOutputChatV2ResponseBody(options)) {
|
|
98
|
+
outputs[CHAT_V2_RESPONSE_BODY_PORT_ID] = createChatV2CapturedBodiesOutput(options.responseBodies);
|
|
99
|
+
}
|
|
100
|
+
return outputs;
|
|
94
101
|
}
|
|
95
|
-
export function createChatV2CommonOutputs({ requestMessages, response, structuredOutput, functionCalls, usage, reasoning,
|
|
102
|
+
export function createChatV2CommonOutputs({ requestMessages, response, structuredOutput, functionCalls, usage, reasoning, requestBodies, responseBodies, outputUsage, outputReasoning, outputRequestBody, outputResponseBody, includeFunctionCalls, functionCallMode, responseFormat, }) {
|
|
96
103
|
const outputs = {
|
|
97
104
|
['response']: createChatV2ResponseOutput(response, structuredOutput, responseFormat),
|
|
98
105
|
['in-messages']: { type: 'chat-message[]', value: requestMessages },
|
|
99
106
|
['all-messages']: createAssistantMessagesOutput(requestMessages, response, functionCalls, {
|
|
100
107
|
functionCallMode,
|
|
101
108
|
}),
|
|
102
|
-
['responseTokens']: { type: 'number', value: usage?.completionTokens ?? 0 },
|
|
103
109
|
};
|
|
104
|
-
if (
|
|
105
|
-
outputs['function-calls'] =
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
if (includeFunctionCalls) {
|
|
111
|
+
outputs['function-calls'] =
|
|
112
|
+
functionCalls.length > 0
|
|
113
|
+
? {
|
|
114
|
+
type: 'object[]',
|
|
115
|
+
value: functionCalls.map(toFunctionCallOutputValue),
|
|
116
|
+
}
|
|
117
|
+
: createControlFlowExcludedOutput();
|
|
112
118
|
}
|
|
113
119
|
if (outputUsage) {
|
|
114
120
|
outputs['usage'] = {
|
|
@@ -126,67 +132,11 @@ export function createChatV2CommonOutputs({ requestMessages, response, structure
|
|
|
126
132
|
if (outputReasoning) {
|
|
127
133
|
outputs['reasoning'] = createChatV2ReasoningOutput(reasoning);
|
|
128
134
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
outputs[CHAT_V2_REQUEST_STATUS_PORT_ID] = {
|
|
136
|
-
type: 'number',
|
|
137
|
-
value: requestStatus ?? 200,
|
|
138
|
-
};
|
|
139
|
-
outputs[CHAT_V2_REQUEST_ERROR_PORT_ID] =
|
|
140
|
-
responseError != null
|
|
141
|
-
? {
|
|
142
|
-
type: 'string',
|
|
143
|
-
value: responseError,
|
|
144
|
-
}
|
|
145
|
-
: createControlFlowExcludedOutput();
|
|
146
|
-
}
|
|
147
|
-
outputs[CHAT_V2_REQUEST_BODY_PORT_ID] = createChatV2RequestBodyOutput(requestBodies);
|
|
148
|
-
}
|
|
149
|
-
return outputs;
|
|
150
|
-
}
|
|
151
|
-
export function createChatV2ProviderFailureOutputs({ requestMessages, responseStatus, responseError, requestStatuses, requestErrors, requestBodies, outputUsage, outputReasoning, includeFunctionCalls, retryOnNon200, }) {
|
|
152
|
-
const outputs = {
|
|
153
|
-
[CHAT_V2_REQUEST_ERROR_PORT_ID]: retryOnNon200
|
|
154
|
-
? createChatV2RetryAttemptOutput('string[]', requestErrors)
|
|
155
|
-
: {
|
|
156
|
-
type: 'string',
|
|
157
|
-
value: responseError,
|
|
158
|
-
},
|
|
159
|
-
[CHAT_V2_REQUEST_STATUS_PORT_ID]: retryOnNon200
|
|
160
|
-
? createChatV2RetryAttemptOutput('number[]', requestStatuses)
|
|
161
|
-
: responseStatus == null
|
|
162
|
-
? {
|
|
163
|
-
type: 'control-flow-excluded',
|
|
164
|
-
value: undefined,
|
|
165
|
-
}
|
|
166
|
-
: {
|
|
167
|
-
type: 'number',
|
|
168
|
-
value: responseStatus,
|
|
169
|
-
},
|
|
170
|
-
['response']: createControlFlowExcludedOutput(),
|
|
171
|
-
['in-messages']: {
|
|
172
|
-
type: 'chat-message[]',
|
|
173
|
-
value: requestMessages,
|
|
174
|
-
},
|
|
175
|
-
['all-messages']: {
|
|
176
|
-
type: 'chat-message[]',
|
|
177
|
-
value: requestMessages,
|
|
178
|
-
},
|
|
179
|
-
['responseTokens']: createControlFlowExcludedOutput(),
|
|
180
|
-
};
|
|
181
|
-
outputs[CHAT_V2_REQUEST_BODY_PORT_ID] = createChatV2RequestBodyOutput(requestBodies);
|
|
182
|
-
if (includeFunctionCalls) {
|
|
183
|
-
outputs['function-calls'] = createControlFlowExcludedOutput();
|
|
184
|
-
}
|
|
185
|
-
if (outputUsage) {
|
|
186
|
-
outputs['usage'] = createControlFlowExcludedOutput();
|
|
187
|
-
}
|
|
188
|
-
if (outputReasoning) {
|
|
189
|
-
outputs['reasoning'] = createControlFlowExcludedOutput();
|
|
190
|
-
}
|
|
135
|
+
Object.assign(outputs, createChatV2CapturedBodyOutputs({
|
|
136
|
+
requestBodies,
|
|
137
|
+
responseBodies,
|
|
138
|
+
outputRequestBody,
|
|
139
|
+
outputResponseBody,
|
|
140
|
+
}));
|
|
191
141
|
return outputs;
|
|
192
142
|
}
|