@valerypopoff/rivet2-core 2.0.11 → 2.1.1

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 (75) hide show
  1. package/dist/cjs/bundle.cjs +1657 -158
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/esm/exports.js +4 -0
  4. package/dist/esm/model/GraphBoundaryCache.js +36 -4
  5. package/dist/esm/model/GraphBoundaryEffects.js +32 -0
  6. package/dist/esm/model/GraphPreprocessor.js +6 -4
  7. package/dist/esm/model/GraphProcessor.js +129 -17
  8. package/dist/esm/model/NodeGraph.js +1 -1
  9. package/dist/esm/model/NodePrefabResolver.js +57 -0
  10. package/dist/esm/model/Nodes.js +4 -1
  11. package/dist/esm/model/ProcessContextBuilder.js +3 -1
  12. package/dist/esm/model/UiGraph.js +113 -0
  13. package/dist/esm/model/UiGraphRendererStyles.js +241 -0
  14. package/dist/esm/model/chat/openAIChatRuntime.js +0 -1
  15. package/dist/esm/model/chat-v2/aiSdkBridge.js +100 -2
  16. package/dist/esm/model/chat-v2/chatV2FeatureCompatibility.js +1 -1
  17. package/dist/esm/model/chat-v2/chatV2Outputs.js +11 -2
  18. package/dist/esm/model/chat-v2/chatV2Pipeline.js +38 -31
  19. package/dist/esm/model/chat-v2/chatV2ResponseFormat.js +4 -1
  20. package/dist/esm/model/chat-v2/chatV2Shared.js +2 -2
  21. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +5 -5
  22. package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +8 -2
  23. package/dist/esm/model/chat-v2/providerOptions.js +65 -2
  24. package/dist/esm/model/nodes/CoalesceNode.js +1 -1
  25. package/dist/esm/model/nodes/CompareNode.js +15 -14
  26. package/dist/esm/model/nodes/GraphOutputNode.js +1 -0
  27. package/dist/esm/model/nodes/LLMChatV2Node.js +66 -17
  28. package/dist/esm/model/nodes/NodePrefabInstanceNode.js +39 -0
  29. package/dist/esm/model/nodes/PromptNode.js +2 -1
  30. package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +49 -7
  31. package/dist/esm/model/nodes/SubGraphNode.js +42 -5
  32. package/dist/esm/utils/index.js +2 -0
  33. package/dist/esm/utils/jsonValueToDataValue.js +48 -0
  34. package/dist/esm/utils/projectComparison/connections.js +57 -0
  35. package/dist/esm/utils/projectComparison/graphs.js +60 -0
  36. package/dist/esm/utils/projectComparison/nodes.js +53 -0
  37. package/dist/esm/utils/projectComparison/summaries.js +60 -0
  38. package/dist/esm/utils/projectComparison/values.js +40 -0
  39. package/dist/esm/utils/projectComparison.js +73 -0
  40. package/dist/esm/utils/serialization/serializationHelpers.js +24 -3
  41. package/dist/esm/utils/serialization/serialization_v4.js +30 -0
  42. package/dist/types/exports.d.ts +5 -0
  43. package/dist/types/model/EditorDefinition.d.ts +1 -0
  44. package/dist/types/model/ExecutorProtocol.d.ts +13 -3
  45. package/dist/types/model/GraphBoundaryCache.d.ts +9 -3
  46. package/dist/types/model/GraphBoundaryEffects.d.ts +9 -0
  47. package/dist/types/model/GraphProcessor.d.ts +15 -0
  48. package/dist/types/model/NodeBase.d.ts +5 -0
  49. package/dist/types/model/NodeBodySpec.d.ts +1 -0
  50. package/dist/types/model/NodePrefabResolver.d.ts +13 -0
  51. package/dist/types/model/Nodes.d.ts +5 -4
  52. package/dist/types/model/ProcessContext.d.ts +5 -1
  53. package/dist/types/model/ProcessContextBuilder.d.ts +4 -2
  54. package/dist/types/model/Project.d.ts +9 -0
  55. package/dist/types/model/UiGraph.d.ts +84 -0
  56. package/dist/types/model/UiGraphRendererStyles.d.ts +2 -0
  57. package/dist/types/model/chat-v2/aiSdkBridge.d.ts +1 -0
  58. package/dist/types/model/chat-v2/chatV2FeatureCompatibility.d.ts +1 -1
  59. package/dist/types/model/chat-v2/chatV2Outputs.d.ts +4 -2
  60. package/dist/types/model/chat-v2/chatV2ResponseFormat.d.ts +1 -1
  61. package/dist/types/model/chat-v2/chatV2Types.d.ts +24 -1
  62. package/dist/types/model/chat-v2/providerOptions.d.ts +1 -0
  63. package/dist/types/model/nodes/CompareNode.d.ts +4 -0
  64. package/dist/types/model/nodes/LLMChatV2Node.d.ts +2 -1
  65. package/dist/types/model/nodes/NodePrefabInstanceNode.d.ts +13 -0
  66. package/dist/types/model/nodes/SubGraphNode.d.ts +2 -0
  67. package/dist/types/utils/index.d.ts +2 -0
  68. package/dist/types/utils/jsonValueToDataValue.d.ts +2 -0
  69. package/dist/types/utils/projectComparison/connections.d.ts +5 -0
  70. package/dist/types/utils/projectComparison/graphs.d.ts +3 -0
  71. package/dist/types/utils/projectComparison/nodes.d.ts +5 -0
  72. package/dist/types/utils/projectComparison/summaries.d.ts +4 -0
  73. package/dist/types/utils/projectComparison/values.d.ts +5 -0
  74. package/dist/types/utils/projectComparison.d.ts +77 -0
  75. package/package.json +1 -1
@@ -0,0 +1,241 @@
1
+ export const RIVET_WEB_APP_RENDERER_CSS = `
2
+ .rivet-web-app-root {
3
+ --rivet-web-app-background: var(--grey-dark-colorish, #1c222b);
4
+ --rivet-web-app-foreground: var(--foreground, #ffffff);
5
+ --rivet-web-app-card-background: color-mix(in srgb, var(--modal-surface-bg, #252b34) 88%, var(--foreground, #ffffff) 4%);
6
+ --rivet-web-app-card-border: var(--foldable-section-border, rgba(255, 255, 255, 0.04));
7
+ --rivet-web-app-control-background: var(--form-control-bg, #20252d);
8
+ --rivet-web-app-control-border: var(--form-control-border, rgba(255, 255, 255, 0.14));
9
+ --rivet-web-app-button-radius: var(--rivet-web-app-host-button-radius, 6px);
10
+ --rivet-web-app-button-background: var(--success, #3ba85b);
11
+ --rivet-web-app-button-foreground: var(--grey-lightest, #ffffff);
12
+ --rivet-web-app-output-title: var(--rivet-web-app-foreground, #ffffff);
13
+ --rivet-web-app-error-color: var(--error, #ff6b5f);
14
+ --rivet-web-app-font-size: var(--rivet-web-app-host-font-size, 15px);
15
+ box-sizing: border-box;
16
+ height: 100%;
17
+ background: var(--rivet-web-app-background);
18
+ color: var(--rivet-web-app-foreground);
19
+ overflow: auto;
20
+ font-family: Inter, system-ui, sans-serif;
21
+ font-size: var(--rivet-web-app-font-size);
22
+ line-height: 1.4;
23
+ }
24
+
25
+ .rivet-web-app-root *,
26
+ .rivet-web-app-root *::before,
27
+ .rivet-web-app-root *::after {
28
+ box-sizing: border-box;
29
+ }
30
+
31
+ .rivet-web-app-surface {
32
+ display: grid;
33
+ gap: 16px;
34
+ margin: 0 auto;
35
+ max-width: 760px;
36
+ padding: 48px 20px;
37
+ }
38
+
39
+ .rivet-web-app-card,
40
+ .rivet-web-app-field {
41
+ border: 1px solid var(--rivet-web-app-card-border);
42
+ border-radius: 10px;
43
+ background: var(--rivet-web-app-card-background);
44
+ padding: 16px;
45
+ }
46
+
47
+ .rivet-web-app-component-frame {
48
+ border-radius: 12px;
49
+ margin: -5px;
50
+ padding: 4px;
51
+ }
52
+
53
+ .rivet-web-app-component-frame.active {
54
+ background: color-mix(in srgb, var(--modal-surface-bg, #252b34) 75%, var(--primary, #ff9e2c) 16%);
55
+ }
56
+
57
+ .rivet-web-app-field {
58
+ display: grid;
59
+ gap: 8px;
60
+ color: var(--rivet-web-app-foreground);
61
+ font-size: inherit;
62
+ font-weight: 600;
63
+ }
64
+
65
+ .rivet-web-app-field input,
66
+ .rivet-web-app-field textarea {
67
+ appearance: none;
68
+ width: 100%;
69
+ box-sizing: border-box;
70
+ border: 1px solid var(--rivet-web-app-control-border);
71
+ border-radius: 8px;
72
+ background: var(--rivet-web-app-control-background);
73
+ color: var(--rivet-web-app-foreground);
74
+ font: inherit;
75
+ font-weight: 400;
76
+ padding: 10px 12px;
77
+ }
78
+
79
+ .rivet-web-app-field textarea {
80
+ min-height: 110px;
81
+ resize: vertical;
82
+ }
83
+
84
+ .rivet-web-app-button {
85
+ width: fit-content;
86
+ border: 0;
87
+ border-radius: var(--rivet-web-app-button-radius);
88
+ background: var(--rivet-web-app-button-background);
89
+ color: var(--rivet-web-app-button-foreground);
90
+ cursor: pointer;
91
+ font: inherit;
92
+ font-weight: 700;
93
+ padding: 10px 16px;
94
+ }
95
+
96
+ .rivet-web-app-button:disabled {
97
+ cursor: wait;
98
+ opacity: 0.72;
99
+ }
100
+
101
+ .rivet-web-app-output {
102
+ display: grid;
103
+ gap: 8px;
104
+ }
105
+
106
+ .rivet-web-app-output-title {
107
+ color: var(--rivet-web-app-output-title);
108
+ font-weight: 700;
109
+ }
110
+
111
+ .rivet-web-app-output pre {
112
+ margin: 0;
113
+ background: transparent;
114
+ border-radius: 0;
115
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
116
+ font-size: inherit;
117
+ padding: 0;
118
+ white-space: pre-wrap;
119
+ word-break: break-word;
120
+ }
121
+
122
+ .rivet-web-app-markdown,
123
+ .rivet-web-app-output-markdown {
124
+ word-break: break-word;
125
+ }
126
+
127
+ .rivet-web-app-markdown.markdown-body {
128
+ background: var(--rivet-web-app-card-background);
129
+ font-family: inherit;
130
+ min-width: 0;
131
+ }
132
+
133
+ .rivet-web-app-output-markdown.markdown-body {
134
+ background: transparent;
135
+ font-family: inherit;
136
+ min-width: 0;
137
+ }
138
+
139
+ .rivet-web-app-markdown h1,
140
+ .rivet-web-app-output-markdown h1 {
141
+ margin: 0 0 12px;
142
+ padding-bottom: 8px;
143
+ border-bottom: 1px solid var(--rivet-web-app-card-border);
144
+ font-size: 24px;
145
+ line-height: 1.22;
146
+ }
147
+
148
+ .rivet-web-app-markdown h2,
149
+ .rivet-web-app-output-markdown h2 {
150
+ margin: 0 0 10px;
151
+ font-size: 20px;
152
+ line-height: 1.25;
153
+ }
154
+
155
+ .rivet-web-app-markdown p,
156
+ .rivet-web-app-output-markdown p,
157
+ .rivet-web-app-markdown ul,
158
+ .rivet-web-app-output-markdown ul {
159
+ margin: 0 0 12px;
160
+ }
161
+
162
+ .rivet-web-app-markdown.markdown-body code,
163
+ .rivet-web-app-output-markdown.markdown-body code {
164
+ border-radius: 4px;
165
+ background: color-mix(in srgb, var(--rivet-web-app-control-background) 70%, var(--rivet-web-app-foreground) 6%);
166
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
167
+ padding: 1px 4px;
168
+ }
169
+
170
+ .rivet-web-app-markdown.markdown-body pre,
171
+ .rivet-web-app-output-markdown.markdown-body pre {
172
+ background: transparent;
173
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
174
+ padding: 0;
175
+ white-space: pre-wrap;
176
+ }
177
+
178
+ .rivet-web-app-markdown > :first-child,
179
+ .rivet-web-app-output-markdown > :first-child {
180
+ margin-top: 0;
181
+ }
182
+
183
+ .rivet-web-app-markdown > :last-child,
184
+ .rivet-web-app-output-markdown > :last-child {
185
+ margin-bottom: 0;
186
+ }
187
+
188
+ .rivet-web-app-error {
189
+ color: var(--rivet-web-app-error-color);
190
+ font-weight: 700;
191
+ }
192
+
193
+ .rivet-web-app-modal-backdrop {
194
+ position: fixed;
195
+ inset: 0;
196
+ z-index: 1000;
197
+ display: grid;
198
+ place-items: center;
199
+ background: rgba(0, 0, 0, 0.46);
200
+ background: color-mix(in srgb, var(--rivet-web-app-background) 78%, transparent);
201
+ padding: 20px;
202
+ }
203
+
204
+ .rivet-web-app-modal {
205
+ display: grid;
206
+ gap: 18px;
207
+ width: min(420px, 100%);
208
+ border: 1px solid var(--rivet-web-app-card-border);
209
+ border-radius: 12px;
210
+ background: var(--rivet-web-app-card-background);
211
+ box-shadow: 0 18px 60px rgba(0, 0, 0, 0.32);
212
+ color: var(--rivet-web-app-foreground);
213
+ padding: 22px;
214
+ }
215
+
216
+ .rivet-web-app-modal-message {
217
+ font-size: 18px;
218
+ font-weight: 700;
219
+ line-height: 1.3;
220
+ }
221
+
222
+ .rivet-web-app-modal-button {
223
+ justify-self: start;
224
+ }
225
+ `;
226
+ export const RIVET_WEB_APP_DOCUMENT_CSS = `
227
+ html,
228
+ body {
229
+ height: 100%;
230
+ margin: 0;
231
+ }
232
+
233
+ body {
234
+ min-height: 100vh;
235
+ background: #1c222b;
236
+ }
237
+
238
+ #app {
239
+ min-height: 100vh;
240
+ }
241
+ `;
@@ -153,7 +153,6 @@ export async function applyOpenAIStreamingResponse(params) {
153
153
  };
154
154
  }
155
155
  output['cost'] = { type: 'number', value: totalCost };
156
- output['__hidden_token_count'] = { type: 'number', value: inputTokenCount + outputTokenCount };
157
156
  }
158
157
  export function handleOpenAIRetryableFailure(params) {
159
158
  const { originalError, context } = params;
@@ -1,4 +1,4 @@
1
- import { streamText } from 'ai';
1
+ import { generateText, NoObjectGeneratedError, streamText } from 'ai';
2
2
  import { consumeAiSdkStream } from '../chat/aiSdkStreaming.js';
3
3
  import { isChatV2StructuredResponseFormat } from './chatV2ResponseFormat.js';
4
4
  function keepPromiseHandled(value) {
@@ -35,6 +35,9 @@ function defaultStreamExecutor(args) {
35
35
  : undefined,
36
36
  };
37
37
  }
38
+ async function defaultGenerateExecutor(args) {
39
+ return (await generateText(args));
40
+ }
38
41
  async function resolveOptionalValue(value) {
39
42
  return value == null ? undefined : await value;
40
43
  }
@@ -49,6 +52,52 @@ async function resolveOptionalStructuredOutput(value) {
49
52
  return undefined;
50
53
  }
51
54
  }
55
+ async function resolveGenerateStructuredOutput(result, responseOutput, finishReason) {
56
+ if (responseOutput == null || (finishReason != null && finishReason !== 'stop')) {
57
+ return undefined;
58
+ }
59
+ try {
60
+ return await resolveOptionalStructuredOutput(result.output);
61
+ }
62
+ catch {
63
+ return undefined;
64
+ }
65
+ }
66
+ function recoverGenerateStructuredOutputError(error, options, toolCalls) {
67
+ if (options.responseOutput == null || !isChatV2StructuredResponseFormat(options.responseFormat)) {
68
+ return undefined;
69
+ }
70
+ if (!NoObjectGeneratedError.isInstance(error)) {
71
+ return undefined;
72
+ }
73
+ if (typeof error.text !== 'string') {
74
+ return undefined;
75
+ }
76
+ const rawText = error.text;
77
+ const responseText = collapseRepeatedStructuredJsonText(rawText);
78
+ return {
79
+ responseText,
80
+ structuredOutput: undefined,
81
+ functionCalls: toStreamedFunctionCalls(toolCalls),
82
+ usage: error.usage,
83
+ reasoning: '',
84
+ finishReason: error.finishReason == null ? undefined : String(error.finishReason),
85
+ providerMetadata: undefined,
86
+ requestStatus: undefined,
87
+ };
88
+ }
89
+ function attachGenerateStepToolCallCollector(args) {
90
+ const toolCalls = [];
91
+ const previousOnStepFinish = args.onStepFinish;
92
+ args.onStepFinish = async (event) => {
93
+ const stepToolCalls = event.toolCalls;
94
+ if (stepToolCalls != null) {
95
+ toolCalls.push(...stepToolCalls);
96
+ }
97
+ await previousOnStepFinish?.(event);
98
+ };
99
+ return toolCalls;
100
+ }
52
101
  function collapseRepeatedStructuredJsonText(responseText) {
53
102
  if (responseText.length === 0 || responseText.length % 2 !== 0) {
54
103
  return responseText;
@@ -70,10 +119,11 @@ function collapseRepeatedStructuredJsonText(responseText) {
70
119
  return responseText;
71
120
  }
72
121
  }
73
- async function executeStream(options, executor) {
122
+ function buildTextArgs(options) {
74
123
  const args = {
75
124
  model: options.model,
76
125
  messages: options.messages,
126
+ maxRetries: 0,
77
127
  };
78
128
  if (options.tools !== undefined)
79
129
  args.tools = options.tools;
@@ -101,6 +151,26 @@ async function executeStream(options, executor) {
101
151
  args.toolChoice = options.toolChoice;
102
152
  if (options.abortSignal !== undefined)
103
153
  args.abortSignal = options.abortSignal;
154
+ return args;
155
+ }
156
+ function toStreamedFunctionCalls(toolCalls) {
157
+ return (toolCalls ?? []).map((toolCall) => ({
158
+ type: 'function',
159
+ id: toolCall.toolCallId,
160
+ name: toolCall.toolName,
161
+ arguments: JSON.stringify(toolCall.input),
162
+ lastParsedArguments: toolCall.input,
163
+ }));
164
+ }
165
+ async function resolveGenerateReasoning(result) {
166
+ const reasoningText = await resolveOptionalValue(result.reasoningText);
167
+ if (reasoningText != null && reasoningText.trim().length > 0) {
168
+ return reasoningText;
169
+ }
170
+ return (await resolveOptionalValue(result.reasoning))?.map((part) => part.text).join('') ?? '';
171
+ }
172
+ async function executeStream(options, executor) {
173
+ const args = buildTextArgs(options);
104
174
  const handle = await executor(args);
105
175
  markOptionalPromiseHandled(handle.finishReason);
106
176
  markOptionalPromiseHandled(handle.output);
@@ -133,3 +203,31 @@ async function executeStream(options, executor) {
133
203
  export async function streamChatV2(options) {
134
204
  return executeStream(options, options.executeStream ?? defaultStreamExecutor);
135
205
  }
206
+ export async function generateChatV2(options) {
207
+ const args = buildTextArgs(options);
208
+ const stepToolCalls = attachGenerateStepToolCallCollector(args);
209
+ let result;
210
+ try {
211
+ result = await (options.executeGenerate ?? defaultGenerateExecutor)(args);
212
+ }
213
+ catch (error) {
214
+ const recovered = recoverGenerateStructuredOutputError(error, options, stepToolCalls);
215
+ if (recovered != null) {
216
+ return recovered;
217
+ }
218
+ throw error;
219
+ }
220
+ const isStructuredOutput = isChatV2StructuredResponseFormat(options.responseFormat);
221
+ const responseText = isStructuredOutput ? collapseRepeatedStructuredJsonText(result.text) : result.text;
222
+ const finishReason = await resolveOptionalValue(result.finishReason);
223
+ return {
224
+ responseText,
225
+ structuredOutput: await resolveGenerateStructuredOutput(result, options.responseOutput, finishReason),
226
+ functionCalls: toStreamedFunctionCalls(result.toolCalls != null && result.toolCalls.length > 0 ? result.toolCalls : stepToolCalls),
227
+ usage: (await resolveOptionalValue(result.totalUsage)) ?? (await resolveOptionalValue(result.usage)),
228
+ reasoning: await resolveGenerateReasoning(result),
229
+ finishReason,
230
+ providerMetadata: await resolveOptionalValue(result.providerMetadata),
231
+ requestStatus: await resolveOptionalValue(result.requestStatus),
232
+ };
233
+ }
@@ -3,7 +3,7 @@ export const LLM_CHAT_V2_TOOL_RESPONSE_FORMAT_CONFLICT_COPY = {
3
3
  title: '"Tool use" conflicts with "Structured outputs"',
4
4
  paragraphs: [
5
5
  '"Tool use" and "Structured outputs" cannot be used at the same time.',
6
- 'Use "Tool use" with Default/Text response format, or turn "Tool use" off before choosing JSON/JSON schema.',
6
+ 'Use "Tool use" with Default/Text response format, or turn "Tool use" off before choosing JSON object/JSON schema.',
7
7
  ],
8
8
  };
9
9
  export function isLLMChatV2StructuredResponseFormat(responseFormat) {
@@ -4,6 +4,7 @@ import { isChatV2StructuredResponseFormat } from './chatV2ResponseFormat.js';
4
4
  import { calculateChatV2Cost } from './modelRegistry.js';
5
5
  const CHAT_V2_REQUEST_STATUS_PORT_ID = 'requestStatus';
6
6
  const CHAT_V2_REQUEST_ERROR_PORT_ID = 'requestError';
7
+ const CHAT_V2_REQUEST_BODY_PORT_ID = 'requestBody';
7
8
  function toFunctionCallOutputValue(functionCall) {
8
9
  let argumentsValue = functionCall.lastParsedArguments;
9
10
  if (argumentsValue == null) {
@@ -77,6 +78,12 @@ function createChatV2ReasoningOutput(reasoning) {
77
78
  }
78
79
  : createControlFlowExcludedOutput();
79
80
  }
81
+ function createChatV2RequestBodyOutput(requestBodies) {
82
+ if (requestBodies == null || requestBodies.length === 0) {
83
+ return createControlFlowExcludedOutput();
84
+ }
85
+ return inferType(requestBodies.length === 1 ? requestBodies[0] : requestBodies);
86
+ }
80
87
  function createChatV2RetryAttemptOutput(type, values) {
81
88
  return values.length > 0
82
89
  ? {
@@ -85,7 +92,7 @@ function createChatV2RetryAttemptOutput(type, values) {
85
92
  }
86
93
  : createControlFlowExcludedOutput();
87
94
  }
88
- export function createChatV2CommonOutputs({ requestMessages, response, structuredOutput, functionCalls, usage, reasoning, requestStatus, responseError, requestStatuses, requestErrors, outputUsage, outputReasoning, outputRequestStatus, includeFunctionCalls, functionCallMode, retryOnNon200, responseFormat, }) {
95
+ export function createChatV2CommonOutputs({ requestMessages, response, structuredOutput, functionCalls, usage, reasoning, requestStatus, responseError, requestStatuses, requestErrors, requestBodies, outputUsage, outputReasoning, outputRequestStatus, includeFunctionCalls, functionCallMode, retryOnNon200, responseFormat, }) {
89
96
  const outputs = {
90
97
  ['response']: createChatV2ResponseOutput(response, structuredOutput, responseFormat),
91
98
  ['in-messages']: { type: 'chat-message[]', value: requestMessages },
@@ -137,10 +144,11 @@ export function createChatV2CommonOutputs({ requestMessages, response, structure
137
144
  }
138
145
  : createControlFlowExcludedOutput();
139
146
  }
147
+ outputs[CHAT_V2_REQUEST_BODY_PORT_ID] = createChatV2RequestBodyOutput(requestBodies);
140
148
  }
141
149
  return outputs;
142
150
  }
143
- export function createChatV2ProviderFailureOutputs({ requestMessages, responseStatus, responseError, requestStatuses, requestErrors, outputUsage, outputReasoning, includeFunctionCalls, retryOnNon200, }) {
151
+ export function createChatV2ProviderFailureOutputs({ requestMessages, responseStatus, responseError, requestStatuses, requestErrors, requestBodies, outputUsage, outputReasoning, includeFunctionCalls, retryOnNon200, }) {
144
152
  const outputs = {
145
153
  [CHAT_V2_REQUEST_ERROR_PORT_ID]: retryOnNon200
146
154
  ? createChatV2RetryAttemptOutput('string[]', requestErrors)
@@ -170,6 +178,7 @@ export function createChatV2ProviderFailureOutputs({ requestMessages, responseSt
170
178
  },
171
179
  ['responseTokens']: createControlFlowExcludedOutput(),
172
180
  };
181
+ outputs[CHAT_V2_REQUEST_BODY_PORT_ID] = createChatV2RequestBodyOutput(requestBodies);
173
182
  if (includeFunctionCalls) {
174
183
  outputs['function-calls'] = createControlFlowExcludedOutput();
175
184
  }
@@ -1,11 +1,11 @@
1
1
  import { coercePromptToChatMessages, prependSystemPrompt } from '../chat/chatMessages.js';
2
- import { streamChatV2 } from './aiSdkBridge.js';
2
+ import { generateChatV2, streamChatV2 } from './aiSdkBridge.js';
3
3
  import { chatMessagesToModelMessages } from './messageConverter.js';
4
4
  import { chatV2ToolsToAiSdk } from './toolConverter.js';
5
5
  import { getChatV2ProviderErrorStatusCode, isChatV2ProviderApiCallError, isChatV2ProviderFetchError, normalizeChatV2ProviderError, } from './chatV2Errors.js';
6
6
  import { normalizeLLMChatV2RetryCooldownMs, normalizeLLMChatV2RetryCount, waitForLLMChatV2RetryCooldown, } from './chatV2Retry.js';
7
7
  import { createChatV2CommonOutputs, createChatV2ProviderFailureOutputs, normalizeChatV2Usage, } from './chatV2Outputs.js';
8
- class StreamChatV2RetryFailure extends Error {
8
+ class ChatV2RetryFailure extends Error {
9
9
  error;
10
10
  requestStatuses;
11
11
  requestErrors;
@@ -14,11 +14,11 @@ class StreamChatV2RetryFailure extends Error {
14
14
  this.error = error;
15
15
  this.requestStatuses = requestStatuses;
16
16
  this.requestErrors = requestErrors;
17
- this.name = 'StreamChatV2RetryFailure';
17
+ this.name = 'ChatV2RetryFailure';
18
18
  }
19
19
  }
20
- function isStreamChatV2RetryFailure(error) {
21
- return error instanceof StreamChatV2RetryFailure;
20
+ function isChatV2RetryFailure(error) {
21
+ return error instanceof ChatV2RetryFailure;
22
22
  }
23
23
  function getProviderFailureMessage(error) {
24
24
  if (error instanceof Error) {
@@ -41,7 +41,7 @@ function normalizeProviderFailureMessage(error, options) {
41
41
  function normalizeProviderFailureMessages(errors, options) {
42
42
  return errors.map((error) => normalizeProviderFailureMessage(error, options));
43
43
  }
44
- async function streamChatV2WithRetry(streamOptions, retryOptions) {
44
+ async function runChatV2WithRetry(chatOptions, retryOptions, transportMode) {
45
45
  const repeatTimes = retryOptions.retryOnNon200
46
46
  ? normalizeLLMChatV2RetryCount(retryOptions.retryOnNon200RepeatTimes)
47
47
  : 0;
@@ -50,7 +50,7 @@ async function streamChatV2WithRetry(streamOptions, retryOptions) {
50
50
  const requestErrors = [];
51
51
  for (let attempt = 0;; attempt++) {
52
52
  try {
53
- const result = await streamChatV2(streamOptions);
53
+ const result = transportMode === 'generate' ? await generateChatV2(chatOptions) : await streamChatV2(chatOptions);
54
54
  const statusCode = result.requestStatus ?? 200;
55
55
  if (retryOptions.retryOnNon200) {
56
56
  requestStatuses.push(statusCode);
@@ -73,7 +73,7 @@ async function streamChatV2WithRetry(streamOptions, retryOptions) {
73
73
  requestStatuses.push(statusCode);
74
74
  requestErrors.push(error);
75
75
  if (attempt >= repeatTimes) {
76
- throw new StreamChatV2RetryFailure(error, requestStatuses, requestErrors);
76
+ throw new ChatV2RetryFailure(error, requestStatuses, requestErrors);
77
77
  }
78
78
  await waitForLLMChatV2RetryCooldown(cooldownMs, retryOptions.context.signal);
79
79
  }
@@ -102,6 +102,7 @@ function buildProviderFailureResult(requestMessages, options, normalizedError, r
102
102
  responseError,
103
103
  requestStatuses: retryRequestStatuses,
104
104
  requestErrors: retryRequestErrors,
105
+ requestBodies: options.requestBodies,
105
106
  outputUsage: options.outputUsage,
106
107
  outputReasoning: options.outputReasoning,
107
108
  includeFunctionCalls: options.includeFunctionCalls,
@@ -137,7 +138,9 @@ export async function runChatV2Pipeline(options) {
137
138
  : options.additionalTools == null
138
139
  ? functionTools
139
140
  : { ...functionTools, ...options.additionalTools };
140
- const streamed = await streamChatV2WithRetry({
141
+ const shouldStreamResponse = options.emitPartialOutputs !== false;
142
+ const transportMode = shouldStreamResponse ? 'stream' : 'generate';
143
+ const chatResponse = await runChatV2WithRetry({
141
144
  model: options.model,
142
145
  messages: modelMessages,
143
146
  tools,
@@ -155,7 +158,8 @@ export async function runChatV2Pipeline(options) {
155
158
  toolChoice: options.toolChoice,
156
159
  abortSignal: options.context.signal,
157
160
  executeStream: options.executeStream,
158
- onPartialOutput: options.emitPartialOutputs === false
161
+ executeGenerate: options.executeGenerate,
162
+ onPartialOutput: !shouldStreamResponse
159
163
  ? undefined
160
164
  : ({ text, functionCalls }) => {
161
165
  options.context.onPartialOutputs?.(createChatV2CommonOutputs({
@@ -169,6 +173,7 @@ export async function runChatV2Pipeline(options) {
169
173
  responseError: undefined,
170
174
  requestStatuses: [],
171
175
  requestErrors: [],
176
+ requestBodies: undefined,
172
177
  outputUsage: false,
173
178
  outputReasoning: false,
174
179
  outputRequestStatus: false,
@@ -178,8 +183,8 @@ export async function runChatV2Pipeline(options) {
178
183
  responseFormat: undefined,
179
184
  }));
180
185
  },
181
- }, options).catch((caughtError) => {
182
- const retryFailure = isStreamChatV2RetryFailure(caughtError) ? caughtError : undefined;
186
+ }, options, transportMode).catch((caughtError) => {
187
+ const retryFailure = isChatV2RetryFailure(caughtError) ? caughtError : undefined;
183
188
  const rawError = retryFailure?.error ?? caughtError;
184
189
  const normalizedError = normalizeChatV2ProviderError(rawError, {
185
190
  provider: options.provider,
@@ -193,26 +198,28 @@ export async function runChatV2Pipeline(options) {
193
198
  }
194
199
  throw normalizedError;
195
200
  });
196
- if ('commonOutputs' in streamed) {
197
- return streamed;
201
+ if ('commonOutputs' in chatResponse) {
202
+ return chatResponse;
198
203
  }
199
- const usage = normalizeChatV2Usage(streamed.result.usage, options);
200
- const requestStatuses = streamed.requestStatuses;
201
- const requestErrors = normalizeProviderFailureMessages(streamed.requestErrors, options);
202
- const responseError = streamed.responseError
203
- ? normalizeProviderFailureMessage(streamed.responseError, options)
204
+ const usage = normalizeChatV2Usage(chatResponse.result.usage, options);
205
+ const requestStatuses = chatResponse.requestStatuses;
206
+ const requestStatus = chatResponse.result.requestStatus ?? 200;
207
+ const requestErrors = normalizeProviderFailureMessages(chatResponse.requestErrors, options);
208
+ const responseError = chatResponse.responseError
209
+ ? normalizeProviderFailureMessage(chatResponse.responseError, options)
204
210
  : undefined;
205
211
  const commonOutputs = createChatV2CommonOutputs({
206
212
  requestMessages,
207
- response: streamed.result.responseText,
208
- structuredOutput: streamed.result.structuredOutput,
209
- functionCalls: streamed.result.functionCalls,
213
+ response: chatResponse.result.responseText,
214
+ structuredOutput: chatResponse.result.structuredOutput,
215
+ functionCalls: chatResponse.result.functionCalls,
210
216
  usage,
211
- reasoning: streamed.result.reasoning,
212
- requestStatus: streamed.result.requestStatus,
217
+ reasoning: chatResponse.result.reasoning,
218
+ requestStatus,
213
219
  responseError,
214
220
  requestStatuses,
215
221
  requestErrors,
222
+ requestBodies: options.requestBodies,
216
223
  outputUsage: options.outputUsage,
217
224
  outputReasoning: options.outputReasoning,
218
225
  outputRequestStatus: options.outputRequestStatus,
@@ -229,13 +236,13 @@ export async function runChatV2Pipeline(options) {
229
236
  commonOutputs,
230
237
  requestMessages,
231
238
  allMessages: allMessagesOutput.value,
232
- response: streamed.result.responseText,
233
- functionCalls: streamed.result.functionCalls,
234
- reasoning: streamed.result.reasoning,
239
+ response: chatResponse.result.responseText,
240
+ functionCalls: chatResponse.result.functionCalls,
241
+ reasoning: chatResponse.result.reasoning,
235
242
  usage,
236
- rawUsage: streamed.result.usage,
237
- finishReason: streamed.result.finishReason,
238
- providerMetadata: streamed.result.providerMetadata,
239
- requestStatus: streamed.result.requestStatus ?? 200,
243
+ rawUsage: chatResponse.result.usage,
244
+ finishReason: chatResponse.result.finishReason,
245
+ providerMetadata: chatResponse.result.providerMetadata,
246
+ requestStatus,
240
247
  };
241
248
  }
@@ -73,7 +73,7 @@ export function resolveChatV2ResponseFormatParameters(data, inputs) {
73
73
  schemaDescription,
74
74
  };
75
75
  }
76
- export function createChatV2ResponseOutput(parameters) {
76
+ export function createChatV2ResponseOutput(parameters, provider) {
77
77
  if (parameters == null) {
78
78
  return undefined;
79
79
  }
@@ -81,6 +81,9 @@ export function createChatV2ResponseOutput(parameters) {
81
81
  return Output.text();
82
82
  }
83
83
  if (parameters.responseFormat === 'json') {
84
+ if (provider === 'custom') {
85
+ return undefined;
86
+ }
84
87
  return Output.json({
85
88
  name: parameters.schemaName,
86
89
  description: parameters.schemaDescription,
@@ -4,7 +4,7 @@ export function createChatV2CommonNodeData(overrides = {}) {
4
4
  useModelInput: false,
5
5
  temperature: 0.5,
6
6
  useTemperatureInput: false,
7
- topP: 1,
7
+ topP: undefined,
8
8
  useTopPInput: false,
9
9
  topK: undefined,
10
10
  useTopKInput: false,
@@ -147,7 +147,7 @@ export function getCommonChatV2Outputs(data, options = {}) {
147
147
  if (includeFunctionCalls) {
148
148
  outputs.push({
149
149
  id: functionCallsPortId,
150
- title: 'Function Calls',
150
+ title: 'Tool Calls',
151
151
  dataType: 'object[]',
152
152
  });
153
153
  }