@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.
Files changed (168) hide show
  1. package/dist/cjs/bundle.cjs +4457 -1809
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/cjs/webAppRuntime.cjs +298 -21
  4. package/dist/cjs/webAppRuntime.cjs.map +4 -4
  5. package/dist/esm/exports.js +1 -0
  6. package/dist/esm/model/AgentResponseTrace.js +448 -0
  7. package/dist/esm/model/ConnectedToolContinuationHost.js +33 -0
  8. package/dist/esm/model/GraphProcessor.js +152 -74
  9. package/dist/esm/model/NodeImpl.js +6 -0
  10. package/dist/esm/model/ProcessContextBuilder.js +3 -1
  11. package/dist/esm/model/RecordingPlayer.js +164 -22
  12. package/dist/esm/model/SplitRunProcessor.js +68 -18
  13. package/dist/esm/model/SubprocessorBridge.js +2 -0
  14. package/dist/esm/model/ToolCallContinuationCoordinator.js +13 -4
  15. package/dist/esm/model/UiGraph.js +21 -0
  16. package/dist/esm/model/UiGraphActionProtocol.js +2 -0
  17. package/dist/esm/model/UiGraphBrowserRuntime.js +133 -4
  18. package/dist/esm/model/UiGraphRendererStyles.js +221 -0
  19. package/dist/esm/model/UiGraphRuntimeModel.js +9 -3
  20. package/dist/esm/model/UiGraphSchema.js +7 -1
  21. package/dist/esm/model/chat/aiSdkMessages.js +8 -0
  22. package/dist/esm/model/chat/aiSdkTools.js +3 -2
  23. package/dist/esm/model/chat-v2/chatV2CallObserver.js +11 -5
  24. package/dist/esm/model/chat-v2/chatV2EditorCache.js +58 -10
  25. package/dist/esm/model/chat-v2/chatV2Errors.js +7 -19
  26. package/dist/esm/model/chat-v2/chatV2FeatureCompatibility.js +1 -1
  27. package/dist/esm/model/chat-v2/chatV2Outputs.js +56 -106
  28. package/dist/esm/model/chat-v2/chatV2Pipeline.js +142 -149
  29. package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +9 -2
  30. package/dist/esm/model/chat-v2/chatV2ProviderRegistry.js +9 -0
  31. package/dist/esm/model/chat-v2/chatV2RequestPlan.js +5 -5
  32. package/dist/esm/model/chat-v2/chatV2ResponseBodyCapture.js +55 -0
  33. package/dist/esm/model/chat-v2/chatV2ResponseFormat.js +8 -4
  34. package/dist/esm/model/chat-v2/chatV2Retry.js +4 -3
  35. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +6 -1
  36. package/dist/esm/model/chat-v2/chatV2Shared.js +1 -6
  37. package/dist/esm/model/chat-v2/chatV2Types.js +7 -1
  38. package/dist/esm/model/chat-v2/chatV2UsageAccounting.js +78 -0
  39. package/dist/esm/model/chat-v2/customProviderApi.js +42 -0
  40. package/dist/esm/model/chat-v2/developerMessageRoles.js +45 -0
  41. package/dist/esm/model/chat-v2/index.js +12 -0
  42. package/dist/esm/model/chat-v2/llmChatV2Body.js +281 -0
  43. package/dist/esm/model/chat-v2/llmChatV2CacheBoundary.js +32 -0
  44. package/dist/esm/model/chat-v2/llmChatV2CachePolicy.js +20 -0
  45. package/dist/esm/model/chat-v2/llmChatV2NodeData.js +8 -54
  46. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +41 -20
  47. package/dist/esm/model/chat-v2/llmChatV2NodeMigration.js +24 -0
  48. package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +178 -94
  49. package/dist/esm/model/chat-v2/llmInvocationCoordinator.js +60 -0
  50. package/dist/esm/model/chat-v2/llmInvocationDecision.js +11 -0
  51. package/dist/esm/model/chat-v2/llmInvocationJournal.js +43 -0
  52. package/dist/esm/model/chat-v2/llmInvocationPlan.js +68 -0
  53. package/dist/esm/model/chat-v2/llmInvocationProjections.js +5 -0
  54. package/dist/esm/model/chat-v2/llmInvocationResultProjector.js +48 -0
  55. package/dist/esm/model/chat-v2/llmModelCandidate.js +75 -0
  56. package/dist/esm/model/chat-v2/llmProfile.js +31 -65
  57. package/dist/esm/model/chat-v2/llmProfileBody.js +183 -0
  58. package/dist/esm/model/chat-v2/llmProfileFallback.js +244 -0
  59. package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +67 -0
  60. package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +3 -0
  61. package/dist/esm/model/chat-v2/llmProfileTypes.js +1 -18
  62. package/dist/esm/model/chat-v2/llmResponseMaterializer.js +42 -0
  63. package/dist/esm/model/chat-v2/messageConverter.js +14 -0
  64. package/dist/esm/model/chat-v2/modelRegistry.js +54 -4
  65. package/dist/esm/model/chat-v2/parallelToolCalls.js +9 -2
  66. package/dist/esm/model/chat-v2/providerOptions.js +120 -21
  67. package/dist/esm/model/chat-v2/rivetToolRegistry.js +9 -0
  68. package/dist/esm/model/chat-v2/toolCallCodec.js +52 -0
  69. package/dist/esm/model/chat-v2/toolContinuation.js +72 -39
  70. package/dist/esm/model/chat-v2/toolHandlerResolver.js +23 -0
  71. package/dist/esm/model/chat-v2/toolRoundExecutor.js +12 -0
  72. package/dist/esm/model/nodes/AssembleMessageNode.js +6 -0
  73. package/dist/esm/model/nodes/ChatNode.js +6 -0
  74. package/dist/esm/model/nodes/ChatNodeBase.js +1 -0
  75. package/dist/esm/model/nodes/DelegateFunctionCallNode.js +26 -1
  76. package/dist/esm/model/nodes/LLMChatV2Node.js +131 -144
  77. package/dist/esm/model/nodes/LLMProfileNode.js +27 -8
  78. package/dist/esm/model/nodes/PromptNode.js +16 -2
  79. package/dist/esm/model/nodes/ToolNode.js +7 -0
  80. package/dist/esm/model/nodes/toolCallDelegation.js +193 -110
  81. package/dist/esm/plugins/anthropic/anthropic.js +4 -4
  82. package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +29 -28
  83. package/dist/esm/plugins/google/google.js +25 -18
  84. package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +21 -7
  85. package/dist/esm/recording/ExecutionRecorder.js +13 -5
  86. package/dist/esm/utils/chatMessageToOpenAIChatCompletionMessage.js +4 -0
  87. package/dist/esm/utils/emitDetached.js +6 -3
  88. package/dist/esm/utils/openai.js +60 -16
  89. package/dist/esm/utils/serialization/serialization.js +2 -0
  90. package/dist/esm/webAppRuntime.js +3 -2
  91. package/dist/types/exports.d.ts +1 -0
  92. package/dist/types/model/AgentResponseTrace.d.ts +110 -0
  93. package/dist/types/model/ConnectedToolContinuationHost.d.ts +34 -0
  94. package/dist/types/model/DataValue.d.ts +7 -1
  95. package/dist/types/model/ExecutorProtocol.d.ts +25 -7
  96. package/dist/types/model/GraphProcessor.d.ts +27 -5
  97. package/dist/types/model/NodeBase.d.ts +6 -0
  98. package/dist/types/model/NodeImpl.d.ts +18 -1
  99. package/dist/types/model/Nodes.d.ts +2 -2
  100. package/dist/types/model/ProcessContext.d.ts +51 -0
  101. package/dist/types/model/ProcessContextBuilder.d.ts +3 -1
  102. package/dist/types/model/RecordingPlayer.d.ts +6 -0
  103. package/dist/types/model/SplitRunProcessor.d.ts +11 -3
  104. package/dist/types/model/UiGraph.d.ts +8 -0
  105. package/dist/types/model/UiGraphActionProtocol.d.ts +2 -0
  106. package/dist/types/model/UiGraphBrowserRuntime.d.ts +11 -2
  107. package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
  108. package/dist/types/model/UiGraphRuntimeModel.d.ts +2 -0
  109. package/dist/types/model/UiGraphSchema.d.ts +1 -0
  110. package/dist/types/model/chat-v2/chatV2CallObserver.d.ts +2 -0
  111. package/dist/types/model/chat-v2/chatV2EditorCache.d.ts +3 -1
  112. package/dist/types/model/chat-v2/chatV2Outputs.d.ts +7 -17
  113. package/dist/types/model/chat-v2/chatV2Pipeline.d.ts +29 -0
  114. package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +5 -0
  115. package/dist/types/model/chat-v2/chatV2ProviderRegistry.d.ts +8 -0
  116. package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +2 -2
  117. package/dist/types/model/chat-v2/chatV2ResponseBodyCapture.d.ts +19 -0
  118. package/dist/types/model/chat-v2/chatV2ResponseFormat.d.ts +3 -2
  119. package/dist/types/model/chat-v2/chatV2Retry.d.ts +2 -0
  120. package/dist/types/model/chat-v2/chatV2Shared.d.ts +0 -1
  121. package/dist/types/model/chat-v2/chatV2Types.d.ts +35 -1
  122. package/dist/types/model/chat-v2/chatV2UsageAccounting.d.ts +14 -0
  123. package/dist/types/model/chat-v2/customProviderApi.d.ts +23 -0
  124. package/dist/types/model/chat-v2/developerMessageRoles.d.ts +10 -0
  125. package/dist/types/model/chat-v2/index.d.ts +12 -0
  126. package/dist/types/model/chat-v2/llmChatV2Body.d.ts +24 -0
  127. package/dist/types/model/chat-v2/llmChatV2CacheBoundary.d.ts +10 -0
  128. package/dist/types/model/chat-v2/llmChatV2CachePolicy.d.ts +13 -0
  129. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +13 -3
  130. package/dist/types/model/chat-v2/llmChatV2NodeMigration.d.ts +8 -0
  131. package/dist/types/model/chat-v2/llmChatV2NodeRuntime.d.ts +18 -4
  132. package/dist/types/model/chat-v2/llmInvocationCoordinator.d.ts +16 -0
  133. package/dist/types/model/chat-v2/llmInvocationDecision.d.ts +21 -0
  134. package/dist/types/model/chat-v2/llmInvocationJournal.d.ts +38 -0
  135. package/dist/types/model/chat-v2/llmInvocationPlan.d.ts +41 -0
  136. package/dist/types/model/chat-v2/llmInvocationProjections.d.ts +3 -0
  137. package/dist/types/model/chat-v2/llmInvocationResultProjector.d.ts +26 -0
  138. package/dist/types/model/chat-v2/llmModelCandidate.d.ts +18 -0
  139. package/dist/types/model/chat-v2/llmProfile.d.ts +7 -0
  140. package/dist/types/model/chat-v2/llmProfileBody.d.ts +20 -0
  141. package/dist/types/model/chat-v2/llmProfileFallback.d.ts +47 -0
  142. package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +189 -0
  143. package/dist/types/model/chat-v2/llmProfileTypes.d.ts +1 -1
  144. package/dist/types/model/chat-v2/llmResponseMaterializer.d.ts +20 -0
  145. package/dist/types/model/chat-v2/modelRegistry.d.ts +17 -187
  146. package/dist/types/model/chat-v2/parallelToolCalls.d.ts +3 -1
  147. package/dist/types/model/chat-v2/providerOptions.d.ts +11 -0
  148. package/dist/types/model/chat-v2/rivetToolRegistry.d.ts +11 -0
  149. package/dist/types/model/chat-v2/toolCallCodec.d.ts +7 -0
  150. package/dist/types/model/chat-v2/toolContinuation.d.ts +3 -3
  151. package/dist/types/model/chat-v2/toolHandlerResolver.d.ts +25 -0
  152. package/dist/types/model/chat-v2/toolRoundExecutor.d.ts +18 -0
  153. package/dist/types/model/nodes/AssembleMessageNode.d.ts +2 -1
  154. package/dist/types/model/nodes/ChatNode.d.ts +2 -1
  155. package/dist/types/model/nodes/DelegateFunctionCallNode.d.ts +2 -1
  156. package/dist/types/model/nodes/LLMChatV2Node.d.ts +2 -1
  157. package/dist/types/model/nodes/LLMProfileNode.d.ts +2 -1
  158. package/dist/types/model/nodes/PromptNode.d.ts +6 -3
  159. package/dist/types/model/nodes/ToolNode.d.ts +2 -1
  160. package/dist/types/model/nodes/toolCallDelegation.d.ts +10 -3
  161. package/dist/types/plugins/anthropic/anthropic.d.ts +1 -0
  162. package/dist/types/plugins/google/google.d.ts +14 -9
  163. package/dist/types/plugins/google/nodes/ChatGoogleNode.d.ts +2 -1
  164. package/dist/types/recording/RecordedEvents.d.ts +6 -0
  165. package/dist/types/utils/emitDetached.d.ts +3 -2
  166. package/dist/types/utils/openai.d.ts +49 -0
  167. package/dist/types/webAppRuntime.d.ts +4 -2
  168. 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 compact(value);
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 compact(JSON.stringify(value));
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 compact(responseBody);
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
- try {
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
- compact(error.message),
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
- compact(error.message),
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
- compact(error.message),
268
+ error.message,
281
269
  ].join('\n');
282
270
  }
283
271
  return undefined;
@@ -1,4 +1,4 @@
1
- import { isChatV2StructuredResponseFormat, } from './chatV2ResponseFormat.js';
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 { isChatV2StructuredResponseFormat } from './chatV2ResponseFormat.js';
4
- import { calculateChatV2Cost } from './modelRegistry.js';
5
- const CHAT_V2_REQUEST_STATUS_PORT_ID = 'requestStatus';
6
- const CHAT_V2_REQUEST_ERROR_PORT_ID = 'requestError';
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
- const promptTokens = usage.inputTokens ?? 0;
35
- const completionTokens = usage.outputTokens ?? 0;
36
- const totalTokens = usage.totalTokens ?? promptTokens + completionTokens;
37
- const cachedTokens = (usage.inputTokenDetails?.cacheReadTokens ?? 0) + (usage.inputTokenDetails?.cacheWriteTokens ?? 0);
38
- const reasoningTokens = usage.outputTokenDetails?.reasoningTokens ?? 0;
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: calculateChatV2Cost(options.provider, options.modelId, promptTokens, completionTokens),
58
+ totalCost: calculateChatV2UsageCost(options.provider, options.modelId, usage),
46
59
  };
47
60
  }
48
- function tryParseStructuredResponseText(response) {
49
- try {
50
- return JSON.parse(response);
51
- }
52
- catch {
53
- return undefined;
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 createChatV2RequestBodyOutput(requestBodies) {
82
- if (requestBodies == null || requestBodies.length === 0) {
86
+ function createChatV2CapturedBodiesOutput(bodies) {
87
+ if (bodies == null || bodies.length === 0) {
83
88
  return createControlFlowExcludedOutput();
84
89
  }
85
- return inferType(requestBodies.length === 1 ? requestBodies[0] : requestBodies);
90
+ return inferType(bodies.length === 1 ? bodies[0] : bodies);
86
91
  }
87
- function createChatV2RetryAttemptOutput(type, values) {
88
- return values.length > 0
89
- ? {
90
- type,
91
- value: values,
92
- }
93
- : createControlFlowExcludedOutput();
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, requestStatus, responseError, requestStatuses, requestErrors, requestBodies, outputUsage, outputReasoning, outputRequestStatus, includeFunctionCalls, functionCallMode, retryOnNon200, responseFormat, }) {
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 (functionCalls.length > 0) {
105
- outputs['function-calls'] = {
106
- type: 'object[]',
107
- value: functionCalls.map(toFunctionCallOutputValue),
108
- };
109
- }
110
- else if (includeFunctionCalls) {
111
- outputs['function-calls'] = createControlFlowExcludedOutput();
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
- if (outputRequestStatus) {
130
- if (retryOnNon200) {
131
- outputs[CHAT_V2_REQUEST_STATUS_PORT_ID] = createChatV2RetryAttemptOutput('number[]', requestStatuses.length > 0 ? requestStatuses : [requestStatus ?? 200]);
132
- outputs[CHAT_V2_REQUEST_ERROR_PORT_ID] = createChatV2RetryAttemptOutput('string[]', requestErrors);
133
- }
134
- else {
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
  }