@valerypopoff/rivet2-core 2.1.7 → 2.1.9

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 (115) hide show
  1. package/dist/cjs/bundle.cjs +4911 -2546
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/esm/api/createProcessor.js +45 -4
  4. package/dist/esm/exports.js +2 -0
  5. package/dist/esm/integrations/KnowledgeStoreFieldPolicy.js +216 -0
  6. package/dist/esm/integrations/KnowledgeStoreProvider.js +14 -90
  7. package/dist/esm/integrations/ManagedKnowledgeStore.js +0 -8
  8. package/dist/esm/model/DataBusPorts.js +26 -0
  9. package/dist/esm/model/DataBusTopology.js +207 -0
  10. package/dist/esm/model/DataValue.js +22 -7
  11. package/dist/esm/model/GraphPreprocessor.js +9 -3
  12. package/dist/esm/model/GraphProcessor.js +164 -366
  13. package/dist/esm/model/NodeIO.js +1 -0
  14. package/dist/esm/model/NodePrefabResolver.js +16 -0
  15. package/dist/esm/model/Nodes.js +7 -0
  16. package/dist/esm/model/SplitRunProcessor.js +19 -10
  17. package/dist/esm/model/ToolCallContinuationBranchPlanner.js +165 -0
  18. package/dist/esm/model/ToolCallContinuationCoordinator.js +206 -0
  19. package/dist/esm/model/chat/aiSdkMessages.js +8 -0
  20. package/dist/esm/model/chat-v2/chatV2CallObserver.js +142 -0
  21. package/dist/esm/model/chat-v2/chatV2EditorCache.js +22 -0
  22. package/dist/esm/model/chat-v2/chatV2Errors.js +23 -6
  23. package/dist/esm/model/chat-v2/chatV2Outputs.js +41 -31
  24. package/dist/esm/model/chat-v2/chatV2Pipeline.js +167 -56
  25. package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +1 -0
  26. package/dist/esm/model/chat-v2/chatV2ProviderTypes.js +1 -0
  27. package/dist/esm/model/chat-v2/chatV2RequestPlan.js +6 -5
  28. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +2 -2
  29. package/dist/esm/model/chat-v2/chatV2Shared.js +1 -6
  30. package/dist/esm/model/chat-v2/chatV2Types.js +11 -1
  31. package/dist/esm/model/chat-v2/developerMessageRoles.js +45 -0
  32. package/dist/esm/model/chat-v2/index.js +1 -0
  33. package/dist/esm/model/chat-v2/llmChatV2NodeData.js +53 -3
  34. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +53 -19
  35. package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +232 -68
  36. package/dist/esm/model/chat-v2/llmProfile.js +212 -0
  37. package/dist/esm/model/chat-v2/llmProfileFallback.js +288 -0
  38. package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +73 -0
  39. package/dist/esm/model/chat-v2/llmProfileTypes.js +45 -0
  40. package/dist/esm/model/chat-v2/messageConverter.js +14 -0
  41. package/dist/esm/model/chat-v2/providerOptions.js +44 -11
  42. package/dist/esm/model/chat-v2/toolContinuation.js +0 -4
  43. package/dist/esm/model/nodes/AssembleMessageNode.js +6 -0
  44. package/dist/esm/model/nodes/DataBusNode.js +81 -0
  45. package/dist/esm/model/nodes/DelegateFunctionCallNode.js +12 -0
  46. package/dist/esm/model/nodes/GetGlobalNode.js +7 -11
  47. package/dist/esm/model/nodes/GetKnowledgeSourceStatusNode.js +1 -1
  48. package/dist/esm/model/nodes/LLMChatV2Node.js +156 -18
  49. package/dist/esm/model/nodes/LLMProfileNode.js +132 -0
  50. package/dist/esm/model/nodes/PassthroughNode.js +1 -11
  51. package/dist/esm/model/nodes/PromptNode.js +9 -2
  52. package/dist/esm/model/nodes/SearchKnowledgeNode.js +1 -1
  53. package/dist/esm/model/nodes/SetGlobalNode.js +6 -6
  54. package/dist/esm/model/nodes/SyncKnowledgeSourceNode.js +0 -1
  55. package/dist/esm/model/nodes/toolCallDelegation.js +31 -4
  56. package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +22 -28
  57. package/dist/esm/plugins/google/google.js +20 -9
  58. package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +17 -6
  59. package/dist/esm/plugins/pinecone/PineconeKnowledgeStore.js +0 -4
  60. package/dist/esm/plugins/pinecone/plugin.js +1 -1
  61. package/dist/esm/utils/chatMessageToOpenAIChatCompletionMessage.js +4 -0
  62. package/dist/esm/utils/coerceType.js +84 -41
  63. package/dist/esm/utils/expectType.js +45 -8
  64. package/dist/esm/utils/fetchEventSource.js +18 -0
  65. package/dist/esm/utils/serialization/serialization.js +37 -7
  66. package/dist/esm/vendor/fnv1a.js +6 -3
  67. package/dist/types/api/createProcessor.d.ts +2 -0
  68. package/dist/types/exports.d.ts +2 -0
  69. package/dist/types/integrations/KnowledgeStore.d.ts +0 -2
  70. package/dist/types/integrations/KnowledgeStoreFieldPolicy.d.ts +38 -0
  71. package/dist/types/integrations/KnowledgeStoreProvider.d.ts +6 -3
  72. package/dist/types/model/DataBusPorts.d.ts +6 -0
  73. package/dist/types/model/DataBusTopology.d.ts +16 -0
  74. package/dist/types/model/DataValue.d.ts +22 -6
  75. package/dist/types/model/GraphPreprocessor.d.ts +2 -1
  76. package/dist/types/model/GraphProcessor.d.ts +4 -3
  77. package/dist/types/model/NodeBase.d.ts +6 -0
  78. package/dist/types/model/NodeIO.d.ts +5 -0
  79. package/dist/types/model/NodePrefabResolver.d.ts +9 -0
  80. package/dist/types/model/Nodes.d.ts +5 -2
  81. package/dist/types/model/ProcessContext.d.ts +64 -0
  82. package/dist/types/model/SplitRunProcessor.d.ts +2 -1
  83. package/dist/types/model/ToolCallContinuationBranchPlanner.d.ts +43 -0
  84. package/dist/types/model/ToolCallContinuationCoordinator.d.ts +70 -0
  85. package/dist/types/model/chat-v2/chatV2CallObserver.d.ts +10 -0
  86. package/dist/types/model/chat-v2/chatV2EditorCache.d.ts +4 -0
  87. package/dist/types/model/chat-v2/chatV2Outputs.d.ts +5 -5
  88. package/dist/types/model/chat-v2/chatV2Pipeline.d.ts +33 -0
  89. package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +1 -0
  90. package/dist/types/model/chat-v2/chatV2ProviderTypes.d.ts +1 -0
  91. package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +2 -2
  92. package/dist/types/model/chat-v2/chatV2RuntimeOptions.d.ts +8 -0
  93. package/dist/types/model/chat-v2/chatV2Shared.d.ts +0 -1
  94. package/dist/types/model/chat-v2/chatV2Types.d.ts +27 -3
  95. package/dist/types/model/chat-v2/developerMessageRoles.d.ts +10 -0
  96. package/dist/types/model/chat-v2/index.d.ts +1 -0
  97. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +10 -1
  98. package/dist/types/model/chat-v2/llmChatV2NodeEditors.d.ts +5 -1
  99. package/dist/types/model/chat-v2/llmChatV2NodeRuntime.d.ts +18 -2
  100. package/dist/types/model/chat-v2/llmProfile.d.ts +10 -0
  101. package/dist/types/model/chat-v2/llmProfileFallback.d.ts +79 -0
  102. package/dist/types/model/chat-v2/llmProfileNodeRuntime.d.ts +9 -0
  103. package/dist/types/model/chat-v2/llmProfileTypes.d.ts +18 -0
  104. package/dist/types/model/chat-v2/providerOptions.d.ts +1 -0
  105. package/dist/types/model/nodes/AssembleMessageNode.d.ts +2 -1
  106. package/dist/types/model/nodes/DataBusNode.d.ts +19 -0
  107. package/dist/types/model/nodes/LLMProfileNode.d.ts +20 -0
  108. package/dist/types/model/nodes/PassthroughNode.d.ts +2 -15
  109. package/dist/types/model/nodes/PromptNode.d.ts +2 -2
  110. package/dist/types/model/nodes/SetGlobalNode.d.ts +2 -2
  111. package/dist/types/model/nodes/toolCallDelegation.d.ts +9 -0
  112. package/dist/types/plugins/google/google.d.ts +12 -1
  113. package/dist/types/plugins/google/nodes/ChatGoogleNode.d.ts +2 -1
  114. package/dist/types/vendor/fnv1a.d.ts +5 -5
  115. package/package.json +1 -1
@@ -0,0 +1,142 @@
1
+ import { nanoid } from 'nanoid/non-secure';
2
+ import { calculateChatV2Cost, getChatV2ModelInfo } from './modelRegistry.js';
3
+ function toUsageNumber(value) {
4
+ return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : undefined;
5
+ }
6
+ function copyRawUsage(usage) {
7
+ if (usage == null) {
8
+ return undefined;
9
+ }
10
+ const inputTokens = toUsageNumber(usage.inputTokens);
11
+ const outputTokens = toUsageNumber(usage.outputTokens);
12
+ const totalTokens = toUsageNumber(usage.totalTokens);
13
+ const cacheReadTokens = toUsageNumber(usage.inputTokenDetails?.cacheReadTokens);
14
+ const cacheWriteTokens = toUsageNumber(usage.inputTokenDetails?.cacheWriteTokens);
15
+ const noCacheTokens = toUsageNumber(usage.inputTokenDetails?.noCacheTokens);
16
+ const reasoningTokens = toUsageNumber(usage.outputTokenDetails?.reasoningTokens);
17
+ const textTokens = toUsageNumber(usage.outputTokenDetails?.textTokens);
18
+ const inputTokenDetails = {
19
+ ...(cacheReadTokens == null ? {} : { cacheReadTokens }),
20
+ ...(cacheWriteTokens == null ? {} : { cacheWriteTokens }),
21
+ ...(noCacheTokens == null ? {} : { noCacheTokens }),
22
+ };
23
+ const outputTokenDetails = {
24
+ ...(reasoningTokens == null ? {} : { reasoningTokens }),
25
+ ...(textTokens == null ? {} : { textTokens }),
26
+ };
27
+ const copied = {
28
+ ...(inputTokens == null ? {} : { inputTokens }),
29
+ ...(outputTokens == null ? {} : { outputTokens }),
30
+ ...(totalTokens == null ? {} : { totalTokens }),
31
+ ...(Object.keys(inputTokenDetails).length === 0 ? {} : { inputTokenDetails }),
32
+ ...(Object.keys(outputTokenDetails).length === 0 ? {} : { outputTokenDetails }),
33
+ };
34
+ return Object.keys(copied).length === 0 ? undefined : copied;
35
+ }
36
+ function normalizeObservedUsage(rawUsage) {
37
+ if (rawUsage == null) {
38
+ return undefined;
39
+ }
40
+ const promptTokens = rawUsage.inputTokens;
41
+ const completionTokens = rawUsage.outputTokens;
42
+ const totalTokens = rawUsage.totalTokens ??
43
+ (promptTokens != null && completionTokens != null ? promptTokens + completionTokens : undefined);
44
+ const cacheReadTokens = rawUsage.inputTokenDetails?.cacheReadTokens;
45
+ const cacheWriteTokens = rawUsage.inputTokenDetails?.cacheWriteTokens;
46
+ const cachedTokens = cacheReadTokens != null && cacheWriteTokens != null ? cacheReadTokens + cacheWriteTokens : undefined;
47
+ const reasoningTokens = rawUsage.outputTokenDetails?.reasoningTokens;
48
+ const normalized = {
49
+ ...(promptTokens == null ? {} : { promptTokens }),
50
+ ...(completionTokens == null ? {} : { completionTokens }),
51
+ ...(totalTokens == null ? {} : { totalTokens }),
52
+ ...(cachedTokens == null ? {} : { cachedTokens }),
53
+ ...(reasoningTokens == null ? {} : { reasoningTokens }),
54
+ };
55
+ return Object.keys(normalized).length === 0 ? undefined : normalized;
56
+ }
57
+ function getErrorProperty(error, key, guard) {
58
+ if (error == null || (typeof error !== 'object' && typeof error !== 'function')) {
59
+ return undefined;
60
+ }
61
+ try {
62
+ const value = error[key];
63
+ return guard(value) ? value : undefined;
64
+ }
65
+ catch {
66
+ return undefined;
67
+ }
68
+ }
69
+ function safelyRead(read) {
70
+ try {
71
+ return read();
72
+ }
73
+ catch {
74
+ return undefined;
75
+ }
76
+ }
77
+ function containUnexpectedObserverPromise(value) {
78
+ if (value == null || (typeof value !== 'object' && typeof value !== 'function')) {
79
+ return;
80
+ }
81
+ try {
82
+ if (typeof value.then === 'function') {
83
+ void Promise.resolve(value).catch(() => undefined);
84
+ }
85
+ }
86
+ catch {
87
+ // Accessing a malformed thenable must not change graph behavior either.
88
+ }
89
+ }
90
+ function isUsage(value) {
91
+ return value != null && typeof value === 'object';
92
+ }
93
+ export function createObservedChatV2CallId(options) {
94
+ return options.context.onChatV2CallFinished != null &&
95
+ options.context.node?.id != null &&
96
+ options.context.processId != null
97
+ ? nanoid()
98
+ : undefined;
99
+ }
100
+ export function notifyChatV2CallFinished(options, params) {
101
+ const observer = options.context.onChatV2CallFinished;
102
+ const nodeId = options.context.node?.id;
103
+ const processId = options.context.processId;
104
+ if (observer == null || nodeId == null || processId == null || params.callId == null) {
105
+ return;
106
+ }
107
+ const resultUsage = safelyRead(() => params.result?.usage);
108
+ const errorUsage = getErrorProperty(params.error, 'usage', isUsage);
109
+ const rawUsage = safelyRead(() => copyRawUsage(resultUsage ?? errorUsage));
110
+ const normalizedUsage = safelyRead(() => normalizeObservedUsage(rawUsage));
111
+ const modelInfo = safelyRead(() => getChatV2ModelInfo(options.provider, options.modelId));
112
+ const calculatedCost = modelInfo != null && normalizedUsage?.promptTokens != null && normalizedUsage.completionTokens != null
113
+ ? safelyRead(() => calculateChatV2Cost(options.provider, options.modelId, normalizedUsage.promptTokens, normalizedUsage.completionTokens))
114
+ : undefined;
115
+ const costUsd = toUsageNumber(calculatedCost);
116
+ const finishReason = safelyRead(() => params.result?.finishReason) ??
117
+ getErrorProperty(params.error, 'finishReason', (value) => typeof value === 'string');
118
+ const event = {
119
+ callId: params.callId,
120
+ attemptIndex: params.attemptIndex,
121
+ ...(options.profileIndex == null ? {} : { profileIndex: options.profileIndex }),
122
+ ...(options.roundIndex == null ? {} : { roundIndex: options.roundIndex }),
123
+ nodeId,
124
+ processId,
125
+ provider: options.provider,
126
+ model: options.modelId,
127
+ outcome: params.outcome,
128
+ ...(finishReason == null ? {} : { finishReason }),
129
+ ...(rawUsage == null ? {} : { rawUsage }),
130
+ ...(normalizedUsage == null ? {} : { normalizedUsage }),
131
+ pricing: {
132
+ status: modelInfo == null ? 'unknown' : 'known',
133
+ ...(costUsd == null ? {} : { costUsd }),
134
+ },
135
+ };
136
+ try {
137
+ containUnexpectedObserverPromise(observer(event));
138
+ }
139
+ catch {
140
+ // Host observers must never change graph behavior.
141
+ }
142
+ }
@@ -78,6 +78,22 @@ function fingerprintProviderOptionsForCache(providerOptions) {
78
78
  }
79
79
  return fingerprintSecret(stableStringify(providerOptions) ?? '');
80
80
  }
81
+ function fingerprintProfileChainForCache(data, profiles) {
82
+ if (profiles == null) {
83
+ return undefined;
84
+ }
85
+ return profiles.map((profile) => ({
86
+ configuration: fingerprintNodeDataForCache({
87
+ ...data,
88
+ ...profile.configuration,
89
+ configurationMode: 'profile',
90
+ }),
91
+ credential: {
92
+ reference: profile.credential.reference,
93
+ value: fingerprintSecret(profile.credential.value),
94
+ },
95
+ }));
96
+ }
81
97
  export function resolveLLMChatV2EditorCache(params) {
82
98
  const { editorCache } = params;
83
99
  if (editorCache == null) {
@@ -97,6 +113,12 @@ export function resolveLLMChatV2EditorCache(params) {
97
113
  responseFormatParameters: params.responseFormatParameters,
98
114
  providerOptions: fingerprintProviderOptionsForCache(params.providerOptions),
99
115
  toolChoice: params.toolChoice,
116
+ profileChain: params.profileChain == null
117
+ ? undefined
118
+ : {
119
+ inputWasArray: params.profileChainUsesArray ?? false,
120
+ profiles: fingerprintProfileChainForCache(params.data, params.profileChain),
121
+ },
100
122
  });
101
123
  return {
102
124
  cacheKey,
@@ -14,7 +14,23 @@ function compact(value, maxLength = 500) {
14
14
  return normalized.length > maxLength ? `${normalized.slice(0, maxLength - 3)}...` : normalized;
15
15
  }
16
16
  function isRecord(value) {
17
- return value != null && typeof value === 'object' && !Array.isArray(value);
17
+ if (value == null || typeof value !== 'object') {
18
+ return false;
19
+ }
20
+ try {
21
+ return !Array.isArray(value);
22
+ }
23
+ catch {
24
+ return false;
25
+ }
26
+ }
27
+ function getRecordProperty(record, key) {
28
+ try {
29
+ return record[key];
30
+ }
31
+ catch {
32
+ return undefined;
33
+ }
18
34
  }
19
35
  function stringifyProviderValue(value) {
20
36
  if (value == null) {
@@ -163,7 +179,8 @@ function coerceHttpStatusCode(value) {
163
179
  return undefined;
164
180
  }
165
181
  function getRecordStatusCode(record) {
166
- return coerceHttpStatusCode(record.statusCode) ?? coerceHttpStatusCode(record.status);
182
+ return (coerceHttpStatusCode(getRecordProperty(record, 'statusCode')) ??
183
+ coerceHttpStatusCode(getRecordProperty(record, 'status')));
167
184
  }
168
185
  export function getChatV2ProviderErrorStatusCode(error, seen = new Set()) {
169
186
  if (!isRecord(error)) {
@@ -177,20 +194,20 @@ export function getChatV2ProviderErrorStatusCode(error, seen = new Set()) {
177
194
  if (directStatusCode != null) {
178
195
  return directStatusCode;
179
196
  }
180
- const response = error.response;
197
+ const response = getRecordProperty(error, 'response');
181
198
  if (isRecord(response)) {
182
199
  const responseStatusCode = getRecordStatusCode(response);
183
200
  if (responseStatusCode != null) {
184
201
  return responseStatusCode;
185
202
  }
186
203
  }
187
- const data = error.data;
204
+ const data = getRecordProperty(error, 'data');
188
205
  if (isRecord(data)) {
189
206
  const dataStatusCode = getRecordStatusCode(data);
190
207
  if (dataStatusCode != null) {
191
208
  return dataStatusCode;
192
209
  }
193
- const dataError = data.error;
210
+ const dataError = getRecordProperty(data, 'error');
194
211
  if (isRecord(dataError)) {
195
212
  const dataErrorStatusCode = getRecordStatusCode(dataError);
196
213
  if (dataErrorStatusCode != null) {
@@ -198,7 +215,7 @@ export function getChatV2ProviderErrorStatusCode(error, seen = new Set()) {
198
215
  }
199
216
  }
200
217
  }
201
- return getChatV2ProviderErrorStatusCode(error.cause, seen);
218
+ return getChatV2ProviderErrorStatusCode(getRecordProperty(error, 'cause'), seen);
202
219
  }
203
220
  function formatProviderFetchError(error, context) {
204
221
  return [
@@ -2,6 +2,7 @@ import { inferType } from '../../utils/coerceType.js';
2
2
  import { createAssistantMessagesOutput } from '../chat/streamChatResponse.js';
3
3
  import { isChatV2StructuredResponseFormat } from './chatV2ResponseFormat.js';
4
4
  import { calculateChatV2Cost } from './modelRegistry.js';
5
+ import { shouldOutputChatV2RequestBody, shouldOutputChatV2RequestError, } from './chatV2Types.js';
5
6
  const CHAT_V2_REQUEST_STATUS_PORT_ID = 'requestStatus';
6
7
  const CHAT_V2_REQUEST_ERROR_PORT_ID = 'requestError';
7
8
  const CHAT_V2_REQUEST_BODY_PORT_ID = 'requestBody';
@@ -92,23 +93,22 @@ function createChatV2RetryAttemptOutput(type, values) {
92
93
  }
93
94
  : createControlFlowExcludedOutput();
94
95
  }
95
- export function createChatV2CommonOutputs({ requestMessages, response, structuredOutput, functionCalls, usage, reasoning, requestStatus, responseError, requestStatuses, requestErrors, requestBodies, outputUsage, outputReasoning, outputRequestStatus, includeFunctionCalls, functionCallMode, retryOnNon200, responseFormat, }) {
96
+ export function createChatV2CommonOutputs({ requestMessages, response, structuredOutput, functionCalls, usage, reasoning, requestStatus, responseError, requestStatuses, requestErrors, requestBodies, outputUsage, outputReasoning, outputRequestStatus, outputRequestError, outputRequestBody, includeFunctionCalls, functionCallMode, retryOnNon200, responseFormat, }) {
96
97
  const outputs = {
97
98
  ['response']: createChatV2ResponseOutput(response, structuredOutput, responseFormat),
98
99
  ['in-messages']: { type: 'chat-message[]', value: requestMessages },
99
100
  ['all-messages']: createAssistantMessagesOutput(requestMessages, response, functionCalls, {
100
101
  functionCallMode,
101
102
  }),
102
- ['responseTokens']: { type: 'number', value: usage?.completionTokens ?? 0 },
103
103
  };
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();
104
+ if (includeFunctionCalls) {
105
+ outputs['function-calls'] =
106
+ functionCalls.length > 0
107
+ ? {
108
+ type: 'object[]',
109
+ value: functionCalls.map(toFunctionCallOutputValue),
110
+ }
111
+ : createControlFlowExcludedOutput();
112
112
  }
113
113
  if (outputUsage) {
114
114
  outputs['usage'] = {
@@ -129,13 +129,19 @@ export function createChatV2CommonOutputs({ requestMessages, response, structure
129
129
  if (outputRequestStatus) {
130
130
  if (retryOnNon200) {
131
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
132
  }
134
133
  else {
135
134
  outputs[CHAT_V2_REQUEST_STATUS_PORT_ID] = {
136
135
  type: 'number',
137
136
  value: requestStatus ?? 200,
138
137
  };
138
+ }
139
+ }
140
+ if (shouldOutputChatV2RequestError({ outputRequestStatus, outputRequestError })) {
141
+ if (retryOnNon200) {
142
+ outputs[CHAT_V2_REQUEST_ERROR_PORT_ID] = createChatV2RetryAttemptOutput('string[]', requestErrors);
143
+ }
144
+ else {
139
145
  outputs[CHAT_V2_REQUEST_ERROR_PORT_ID] =
140
146
  responseError != null
141
147
  ? {
@@ -144,29 +150,14 @@ export function createChatV2CommonOutputs({ requestMessages, response, structure
144
150
  }
145
151
  : createControlFlowExcludedOutput();
146
152
  }
153
+ }
154
+ if (shouldOutputChatV2RequestBody({ outputRequestStatus, outputRequestBody })) {
147
155
  outputs[CHAT_V2_REQUEST_BODY_PORT_ID] = createChatV2RequestBodyOutput(requestBodies);
148
156
  }
149
157
  return outputs;
150
158
  }
151
- export function createChatV2ProviderFailureOutputs({ requestMessages, responseStatus, responseError, requestStatuses, requestErrors, requestBodies, outputUsage, outputReasoning, includeFunctionCalls, retryOnNon200, }) {
159
+ export function createChatV2ProviderFailureOutputs({ requestMessages, responseStatus, responseError, requestStatuses, requestErrors, requestBodies, outputUsage, outputReasoning, outputRequestStatus, outputRequestError, outputRequestBody, includeFunctionCalls, retryOnNon200, }) {
152
160
  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
161
  ['response']: createControlFlowExcludedOutput(),
171
162
  ['in-messages']: {
172
163
  type: 'chat-message[]',
@@ -176,9 +167,28 @@ export function createChatV2ProviderFailureOutputs({ requestMessages, responseSt
176
167
  type: 'chat-message[]',
177
168
  value: requestMessages,
178
169
  },
179
- ['responseTokens']: createControlFlowExcludedOutput(),
180
170
  };
181
- outputs[CHAT_V2_REQUEST_BODY_PORT_ID] = createChatV2RequestBodyOutput(requestBodies);
171
+ if (outputRequestStatus) {
172
+ outputs[CHAT_V2_REQUEST_STATUS_PORT_ID] = retryOnNon200
173
+ ? createChatV2RetryAttemptOutput('number[]', requestStatuses)
174
+ : responseStatus == null
175
+ ? createControlFlowExcludedOutput()
176
+ : {
177
+ type: 'number',
178
+ value: responseStatus,
179
+ };
180
+ }
181
+ if (shouldOutputChatV2RequestError({ outputRequestStatus, outputRequestError })) {
182
+ outputs[CHAT_V2_REQUEST_ERROR_PORT_ID] = retryOnNon200
183
+ ? createChatV2RetryAttemptOutput('string[]', requestErrors)
184
+ : {
185
+ type: 'string',
186
+ value: responseError,
187
+ };
188
+ }
189
+ if (shouldOutputChatV2RequestBody({ outputRequestStatus, outputRequestBody })) {
190
+ outputs[CHAT_V2_REQUEST_BODY_PORT_ID] = createChatV2RequestBodyOutput(requestBodies);
191
+ }
182
192
  if (includeFunctionCalls) {
183
193
  outputs['function-calls'] = createControlFlowExcludedOutput();
184
194
  }