@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
@@ -1,10 +1,11 @@
1
1
  import { coercePromptToChatMessages, prependSystemPrompt } from '../chat/chatMessages.js';
2
2
  import { generateChatV2, streamChatV2 } from './aiSdkBridge.js';
3
+ import { createObservedChatV2CallId, notifyChatV2CallFinished } from './chatV2CallObserver.js';
3
4
  import { chatMessagesToModelMessages } from './messageConverter.js';
4
5
  import { chatV2ToolsToAiSdk } from './toolConverter.js';
5
6
  import { buildChatV2RequestPlan } from './chatV2RequestPlan.js';
6
7
  import { getChatV2ProviderErrorStatusCode, isChatV2ProviderApiCallError, isChatV2ProviderFetchError, normalizeChatV2ProviderError, } from './chatV2Errors.js';
7
- import { waitForLLMChatV2RetryCooldown, } from './chatV2Retry.js';
8
+ import { waitForLLMChatV2RetryCooldown } from './chatV2Retry.js';
8
9
  import { createChatV2CommonOutputs, createChatV2ProviderFailureOutputs, normalizeChatV2Usage, } from './chatV2Outputs.js';
9
10
  class ChatV2RetryFailure extends Error {
10
11
  error;
@@ -22,10 +23,20 @@ function isChatV2RetryFailure(error) {
22
23
  return error instanceof ChatV2RetryFailure;
23
24
  }
24
25
  function getProviderFailureMessage(error) {
25
- if (error instanceof Error) {
26
- return error.message;
26
+ try {
27
+ if (error instanceof Error && typeof error.message === 'string') {
28
+ return error.message;
29
+ }
30
+ }
31
+ catch {
32
+ return 'Provider request failed with unreadable error metadata.';
33
+ }
34
+ try {
35
+ return String(error);
36
+ }
37
+ catch {
38
+ return 'Provider request failed with unreadable error metadata.';
27
39
  }
28
- return String(error);
29
40
  }
30
41
  function buildNon200StatusError(statusCode) {
31
42
  const error = new Error(`Provider request returned non-200 status: ${statusCode}`);
@@ -34,21 +45,52 @@ function buildNon200StatusError(statusCode) {
34
45
  return error;
35
46
  }
36
47
  function normalizeProviderFailureMessage(error, options) {
37
- return getProviderFailureMessage(normalizeChatV2ProviderError(error, {
38
- provider: options.provider,
39
- modelId: options.modelId,
40
- }));
48
+ return getProviderFailureMessage(normalizeProviderFailure(error, options));
49
+ }
50
+ function normalizeProviderFailure(error, options) {
51
+ try {
52
+ return normalizeChatV2ProviderError(error, {
53
+ provider: options.provider,
54
+ modelId: options.modelId,
55
+ });
56
+ }
57
+ catch {
58
+ return error;
59
+ }
41
60
  }
42
61
  function normalizeProviderFailureMessages(errors, options) {
43
62
  return errors.map((error) => normalizeProviderFailureMessage(error, options));
44
63
  }
45
- async function runChatV2WithRetry(chatOptions, retryPlan, signal, transportMode) {
64
+ function notifyProviderAttempt(options, attempt) {
65
+ try {
66
+ options.onProviderAttempt?.(attempt);
67
+ }
68
+ catch {
69
+ // Attempt diagnostics are observational and must never affect the request.
70
+ }
71
+ }
72
+ async function runChatV2WithRetry(options, chatOptions, retryPlan, signal, transportMode) {
46
73
  const requestStatuses = [];
47
74
  const requestErrors = [];
48
75
  for (let attempt = 0;; attempt++) {
76
+ const callId = createObservedChatV2CallId(options);
77
+ let callWasObserved = false;
49
78
  try {
50
79
  const result = transportMode === 'generate' ? await generateChatV2(chatOptions) : await streamChatV2(chatOptions);
51
80
  const statusCode = result.requestStatus ?? 200;
81
+ notifyChatV2CallFinished(options, {
82
+ callId,
83
+ attemptIndex: attempt,
84
+ outcome: statusCode === 200 ? 'success' : 'provider-failure',
85
+ result,
86
+ });
87
+ callWasObserved = true;
88
+ notifyProviderAttempt(options, {
89
+ attemptIndex: attempt,
90
+ outcome: statusCode === 200 ? 'success' : 'provider-failure',
91
+ status: statusCode,
92
+ ...(statusCode === 200 ? {} : { error: buildNon200StatusError(statusCode) }),
93
+ });
52
94
  if (retryPlan.enabled) {
53
95
  requestStatuses.push(statusCode);
54
96
  }
@@ -63,7 +105,21 @@ async function runChatV2WithRetry(chatOptions, retryPlan, signal, transportMode)
63
105
  await waitForLLMChatV2RetryCooldown(retryPlan.cooldownMs, signal);
64
106
  }
65
107
  catch (error) {
108
+ if (!callWasObserved) {
109
+ notifyChatV2CallFinished(options, {
110
+ callId,
111
+ attemptIndex: attempt,
112
+ outcome: signal.aborted ? 'aborted' : 'provider-failure',
113
+ error,
114
+ });
115
+ }
66
116
  const statusCode = getChatV2ProviderErrorStatusCode(error);
117
+ notifyProviderAttempt(options, {
118
+ attemptIndex: attempt,
119
+ outcome: 'provider-failure',
120
+ ...(statusCode == null ? {} : { status: statusCode }),
121
+ error,
122
+ });
67
123
  if (!retryPlan.enabled || statusCode == null || statusCode === 200) {
68
124
  throw error;
69
125
  }
@@ -77,7 +133,7 @@ async function runChatV2WithRetry(chatOptions, retryPlan, signal, transportMode)
77
133
  }
78
134
  }
79
135
  function buildProviderFailureResult(requestMessages, options, plan, normalizedError, rawError, requestStatuses, requestErrors) {
80
- if (!plan.output.outputRequestStatus) {
136
+ if (!plan.output.outputRequestStatus && !plan.output.outputRequestError) {
81
137
  return undefined;
82
138
  }
83
139
  const statusCode = getChatV2ProviderErrorStatusCode(normalizedError);
@@ -102,6 +158,9 @@ function buildProviderFailureResult(requestMessages, options, plan, normalizedEr
102
158
  requestBodies: options.requestBodies,
103
159
  outputUsage: plan.output.outputUsage,
104
160
  outputReasoning: plan.output.outputReasoning,
161
+ outputRequestStatus: plan.output.outputRequestStatus,
162
+ outputRequestError: plan.output.outputRequestError,
163
+ outputRequestBody: plan.output.outputRequestBody,
105
164
  includeFunctionCalls: plan.output.includeFunctionCalls,
106
165
  retryOnNon200: plan.retry.enabled,
107
166
  });
@@ -123,7 +182,13 @@ function buildProviderFailureResult(requestMessages, options, plan, normalizedEr
123
182
  requestStatus: statusCode,
124
183
  };
125
184
  }
126
- export async function runChatV2Pipeline(options) {
185
+ /**
186
+ * Runs one provider/model round without deciding whether a provider failure
187
+ * should become diagnostic outputs or should advance an LLM Profile fallback
188
+ * chain. Shared prompt/schema/tool construction errors deliberately continue
189
+ * to throw: they are graph configuration errors, not a profile failure.
190
+ */
191
+ export async function runChatV2PipelineExecution(options) {
127
192
  const requestMessages = prependSystemPrompt(coercePromptToChatMessages(options.prompt, { requirePrompt: true }), options.systemPrompt);
128
193
  const modelMessages = await chatMessagesToModelMessages(requestMessages, {
129
194
  provider: options.provider,
@@ -141,52 +206,59 @@ export async function runChatV2Pipeline(options) {
141
206
  tools,
142
207
  });
143
208
  const shouldStreamResponse = plan.transportMode === 'stream';
144
- const chatResponse = await runChatV2WithRetry({
145
- ...plan.request,
146
- abortSignal: options.context.signal,
147
- executeStream: options.executeStream,
148
- executeGenerate: options.executeGenerate,
149
- onPartialOutput: !shouldStreamResponse
150
- ? undefined
151
- : ({ text, functionCalls }) => {
152
- options.context.onPartialOutputs?.(createChatV2CommonOutputs({
153
- requestMessages,
154
- response: text,
155
- structuredOutput: undefined,
156
- functionCalls,
157
- usage: undefined,
158
- reasoning: '',
159
- requestStatus: undefined,
160
- responseError: undefined,
161
- requestStatuses: [],
162
- requestErrors: [],
163
- requestBodies: undefined,
164
- outputUsage: false,
165
- outputReasoning: false,
166
- outputRequestStatus: false,
167
- includeFunctionCalls: plan.output.includeFunctionCalls,
168
- functionCallMode: plan.output.functionCallMode,
169
- retryOnNon200: false,
170
- responseFormat: undefined,
171
- }));
172
- },
173
- }, plan.retry, options.context.signal, plan.transportMode).catch((caughtError) => {
209
+ let chatResponse;
210
+ try {
211
+ chatResponse = await runChatV2WithRetry(options, {
212
+ ...plan.request,
213
+ abortSignal: options.context.signal,
214
+ executeStream: options.executeStream,
215
+ executeGenerate: options.executeGenerate,
216
+ onPartialOutput: !shouldStreamResponse
217
+ ? undefined
218
+ : ({ text, functionCalls }) => {
219
+ options.context.onPartialOutputs?.(createChatV2CommonOutputs({
220
+ requestMessages,
221
+ response: text,
222
+ structuredOutput: undefined,
223
+ functionCalls,
224
+ usage: undefined,
225
+ reasoning: '',
226
+ requestStatus: undefined,
227
+ responseError: undefined,
228
+ requestStatuses: [],
229
+ requestErrors: [],
230
+ requestBodies: undefined,
231
+ outputUsage: false,
232
+ outputReasoning: false,
233
+ outputRequestStatus: false,
234
+ outputRequestError: false,
235
+ outputRequestBody: false,
236
+ includeFunctionCalls: plan.output.includeFunctionCalls,
237
+ functionCallMode: plan.output.functionCallMode,
238
+ retryOnNon200: false,
239
+ responseFormat: undefined,
240
+ }));
241
+ },
242
+ }, plan.retry, options.context.signal, plan.transportMode);
243
+ }
244
+ catch (caughtError) {
245
+ if (options.context.signal.aborted) {
246
+ throw caughtError;
247
+ }
174
248
  const retryFailure = isChatV2RetryFailure(caughtError) ? caughtError : undefined;
175
249
  const rawError = retryFailure?.error ?? caughtError;
176
- const normalizedError = normalizeChatV2ProviderError(rawError, {
177
- provider: options.provider,
178
- modelId: options.modelId,
179
- });
180
- const requestStatuses = retryFailure?.requestStatuses ?? [];
181
- const requestErrors = normalizeProviderFailureMessages(retryFailure?.requestErrors ?? [], options);
182
- const failureResult = buildProviderFailureResult(requestMessages, options, plan, normalizedError, rawError, requestStatuses, requestErrors);
183
- if (failureResult) {
184
- return failureResult;
185
- }
186
- throw normalizedError;
187
- });
188
- if ('commonOutputs' in chatResponse) {
189
- return chatResponse;
250
+ return {
251
+ outcome: 'provider-failure',
252
+ failure: {
253
+ requestMessages,
254
+ options,
255
+ plan,
256
+ normalizedError: normalizeProviderFailure(rawError, options),
257
+ rawError,
258
+ requestStatuses: retryFailure?.requestStatuses ?? [],
259
+ requestErrors: normalizeProviderFailureMessages(retryFailure?.requestErrors ?? [], options),
260
+ },
261
+ };
190
262
  }
191
263
  const usage = normalizeChatV2Usage(chatResponse.result.usage, options);
192
264
  const requestStatuses = chatResponse.requestStatuses;
@@ -210,6 +282,8 @@ export async function runChatV2Pipeline(options) {
210
282
  outputUsage: plan.output.outputUsage,
211
283
  outputReasoning: plan.output.outputReasoning,
212
284
  outputRequestStatus: plan.output.outputRequestStatus,
285
+ outputRequestError: plan.output.outputRequestError,
286
+ outputRequestBody: plan.output.outputRequestBody,
213
287
  includeFunctionCalls: plan.output.includeFunctionCalls,
214
288
  functionCallMode: plan.output.functionCallMode,
215
289
  retryOnNon200: plan.retry.enabled,
@@ -219,7 +293,7 @@ export async function runChatV2Pipeline(options) {
219
293
  if (allMessagesOutput?.type !== 'chat-message[]') {
220
294
  throw new Error('Chat v2 pipeline expected all-messages output to be chat-message[].');
221
295
  }
222
- return {
296
+ const result = {
223
297
  commonOutputs,
224
298
  requestMessages,
225
299
  allMessages: allMessagesOutput.value,
@@ -232,4 +306,41 @@ export async function runChatV2Pipeline(options) {
232
306
  providerMetadata: chatResponse.result.providerMetadata,
233
307
  requestStatus,
234
308
  };
309
+ const providerRoundFailure = chatResponse.responseError ?? (requestStatus === 200 ? undefined : buildNon200StatusError(requestStatus));
310
+ if (providerRoundFailure != null) {
311
+ const rawError = providerRoundFailure;
312
+ return {
313
+ outcome: 'provider-failure',
314
+ failure: {
315
+ requestMessages,
316
+ options,
317
+ plan,
318
+ normalizedError: normalizeProviderFailure(rawError, options),
319
+ rawError,
320
+ requestStatuses: chatResponse.requestStatuses,
321
+ requestErrors: normalizeProviderFailureMessages(chatResponse.requestErrors, options),
322
+ diagnosticResult: result,
323
+ },
324
+ };
325
+ }
326
+ return { outcome: 'success', result };
327
+ }
328
+ /**
329
+ * Retains the established single-profile behavior: request-detail mode can
330
+ * turn a provider failure into normal excluded outputs; otherwise it remains
331
+ * a thrown normalized provider error.
332
+ */
333
+ export function materializeChatV2PipelineFailure(failure) {
334
+ if (failure.diagnosticResult != null) {
335
+ return failure.diagnosticResult;
336
+ }
337
+ const failureResult = buildProviderFailureResult(failure.requestMessages, failure.options, failure.plan, failure.normalizedError, failure.rawError, failure.requestStatuses, failure.requestErrors);
338
+ if (failureResult != null) {
339
+ return failureResult;
340
+ }
341
+ throw failure.normalizedError;
342
+ }
343
+ export async function runChatV2Pipeline(options) {
344
+ const execution = await runChatV2PipelineExecution(options);
345
+ return execution.outcome === 'success' ? execution.result : materializeChatV2PipelineFailure(execution.failure);
235
346
  }
@@ -79,6 +79,7 @@ export async function createResolvedChatV2Provider(options) {
79
79
  ...config,
80
80
  apiKey: options.credential.value,
81
81
  onRequestBody: options.onRequestBody,
82
+ transformRequestBody: options.transformRequestBody,
82
83
  });
83
84
  return {
84
85
  profile: {
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,5 @@
1
- import { normalizeLLMChatV2RetryCooldownMs, normalizeLLMChatV2RetryCount, } from './chatV2Retry.js';
1
+ import { normalizeLLMChatV2RetryCooldownMs, normalizeLLMChatV2RetryCount } from './chatV2Retry.js';
2
+ import { shouldOutputChatV2RequestBody, shouldOutputChatV2RequestError } from './chatV2Types.js';
2
3
  export function buildChatV2RequestPlan(options) {
3
4
  const shouldStream = options.emitPartialOutputs !== false;
4
5
  return {
@@ -7,9 +8,7 @@ export function buildChatV2RequestPlan(options) {
7
8
  transportMode: shouldStream ? 'stream' : 'generate',
8
9
  retry: {
9
10
  enabled: options.retryOnNon200 === true,
10
- repeatTimes: options.retryOnNon200
11
- ? normalizeLLMChatV2RetryCount(options.retryOnNon200RepeatTimes)
12
- : 0,
11
+ repeatTimes: options.retryOnNon200 ? normalizeLLMChatV2RetryCount(options.retryOnNon200RepeatTimes) : 0,
13
12
  cooldownMs: normalizeLLMChatV2RetryCooldownMs(options.retryOnNon200CooldownMs),
14
13
  },
15
14
  request: {
@@ -33,7 +32,9 @@ export function buildChatV2RequestPlan(options) {
33
32
  output: {
34
33
  outputUsage: options.outputUsage,
35
34
  outputReasoning: options.outputReasoning,
36
- outputRequestStatus: options.outputRequestStatus,
35
+ outputRequestStatus: options.outputRequestStatus === true,
36
+ outputRequestError: shouldOutputChatV2RequestError(options),
37
+ outputRequestBody: shouldOutputChatV2RequestBody(options),
37
38
  includeFunctionCalls: options.includeFunctionCalls,
38
39
  functionCallMode: options.functionCallMode,
39
40
  },
@@ -48,7 +48,7 @@ function normalizeExtraProviderOptions(value) {
48
48
  }
49
49
  return value;
50
50
  }
51
- function resolveExtraProviderOptions(data, inputs) {
51
+ export function resolveLLMChatV2ExtraProviderOptions(data, inputs) {
52
52
  if (!data.useExtraProviderOptionsInput) {
53
53
  return parseExtraProviderOptionsText(data.extraProviderOptions ?? '');
54
54
  }
@@ -56,7 +56,7 @@ function resolveExtraProviderOptions(data, inputs) {
56
56
  }
57
57
  function resolveProviderOptions(data, inputs) {
58
58
  const providerOptions = {};
59
- const extraProviderOptions = resolveExtraProviderOptions(data, inputs);
59
+ const extraProviderOptions = resolveLLMChatV2ExtraProviderOptions(data, inputs);
60
60
  if (extraProviderOptions) {
61
61
  providerOptions[data.provider] = extraProviderOptions;
62
62
  }
@@ -121,7 +121,7 @@ export function getCommonChatV2Inputs(data, options = {}) {
121
121
  return inputs;
122
122
  }
123
123
  export function getCommonChatV2Outputs(data, options = {}) {
124
- const { responsePortId = 'response', inMessagesPortId = 'in-messages', allMessagesPortId = 'all-messages', functionCallsPortId = 'function-calls', responseTokensPortId = 'responseTokens', usagePortId = 'usage', reasoningPortId = 'reasoning', includeFunctionCalls = data.useToolCalling, includeUsage = data.outputUsage, includeReasoning = data.outputReasoning, } = options;
124
+ const { responsePortId = 'response', inMessagesPortId = 'in-messages', allMessagesPortId = 'all-messages', functionCallsPortId = 'function-calls', usagePortId = 'usage', reasoningPortId = 'reasoning', includeFunctionCalls = data.useToolCalling, includeUsage = data.outputUsage, includeReasoning = data.outputReasoning, } = options;
125
125
  const outputs = [
126
126
  {
127
127
  id: responsePortId,
@@ -138,11 +138,6 @@ export function getCommonChatV2Outputs(data, options = {}) {
138
138
  title: 'All Messages',
139
139
  dataType: 'chat-message[]',
140
140
  },
141
- {
142
- id: responseTokensPortId,
143
- title: 'Response Tokens',
144
- dataType: 'number',
145
- },
146
141
  ];
147
142
  if (includeFunctionCalls) {
148
143
  outputs.push({
@@ -1 +1,11 @@
1
- export {};
1
+ /**
2
+ * Older LLM Chat nodes used Output request details as one switch for status,
3
+ * error, and request body. Keep that saved contract intact while newly saved
4
+ * nodes use the independent controls.
5
+ */
6
+ export function shouldOutputChatV2RequestError(options) {
7
+ return options.outputRequestError ?? options.outputRequestStatus ?? false;
8
+ }
9
+ export function shouldOutputChatV2RequestBody(options) {
10
+ return options.outputRequestBody ?? options.outputRequestStatus ?? false;
11
+ }
@@ -0,0 +1,45 @@
1
+ export function getInstructionMessageRoles(messages) {
2
+ return messages
3
+ .filter((message) => message.type === 'system' || message.type === 'developer')
4
+ .map((message) => message.type);
5
+ }
6
+ /**
7
+ * AI SDK's provider-neutral ModelMessage represents both Rivet system and
8
+ * developer instructions with role `system`. Restore the explicit Rivet roles
9
+ * only at OpenAI-compatible wire boundaries, after the provider has built its
10
+ * request body.
11
+ */
12
+ export function restoreOpenAICompatibleInstructionRoles(body, roles) {
13
+ if (roles.length === 0) {
14
+ return body;
15
+ }
16
+ if (body == null || typeof body !== 'object' || Array.isArray(body)) {
17
+ throw new Error('Could not preserve developer messages: provider request body is not a JSON object.');
18
+ }
19
+ const record = body;
20
+ const listKey = Array.isArray(record.messages) ? 'messages' : Array.isArray(record.input) ? 'input' : undefined;
21
+ if (listKey == null) {
22
+ throw new Error('Could not preserve developer messages: provider request body has no messages or input array.');
23
+ }
24
+ const items = record[listKey];
25
+ const instructionIndexes = items.flatMap((item, index) => item != null &&
26
+ typeof item === 'object' &&
27
+ !Array.isArray(item) &&
28
+ (item.role === 'system' || item.role === 'developer')
29
+ ? [index]
30
+ : []);
31
+ if (instructionIndexes.length !== roles.length) {
32
+ throw new Error(`Could not preserve developer messages: expected ${roles.length} instruction message(s), but the provider request contains ${instructionIndexes.length}.`);
33
+ }
34
+ const rewrittenItems = [...items];
35
+ instructionIndexes.forEach((itemIndex, roleIndex) => {
36
+ rewrittenItems[itemIndex] = {
37
+ ...rewrittenItems[itemIndex],
38
+ role: roles[roleIndex],
39
+ };
40
+ });
41
+ return {
42
+ ...record,
43
+ [listKey]: rewrittenItems,
44
+ };
45
+ }
@@ -6,6 +6,7 @@ export * from './chatV2RequestPlan.js';
6
6
  export * from './chatV2ResponseFormat.js';
7
7
  export * from './chatV2Shared.js';
8
8
  export * from './chatV2Types.js';
9
+ export * from './llmProfileTypes.js';
9
10
  export * from './messageConverter.js';
10
11
  export * from './modelRegistry.js';
11
12
  export * from './providerOptions.js';
@@ -1,10 +1,59 @@
1
1
  import { createChatV2CommonNodeData } from './chatV2Shared.js';
2
2
  import { DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_COOLDOWN_MS, DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_REPEAT_TIMES, } from './chatV2Retry.js';
3
+ export const llmChatV2ProfileDataKeys = [
4
+ 'model',
5
+ 'useModelInput',
6
+ 'temperature',
7
+ 'useTemperatureInput',
8
+ 'topP',
9
+ 'useTopPInput',
10
+ 'topK',
11
+ 'useTopKInput',
12
+ 'presencePenalty',
13
+ 'usePresencePenaltyInput',
14
+ 'frequencyPenalty',
15
+ 'useFrequencyPenaltyInput',
16
+ 'stopSequences',
17
+ 'useStopSequencesInput',
18
+ 'seed',
19
+ 'useSeedInput',
20
+ 'maxTokens',
21
+ 'useMaxTokensInput',
22
+ 'provider',
23
+ 'apiKeySource',
24
+ 'customProviderApiKeyProgrammaticName',
25
+ 'customProviderApiKeyEnvVarName',
26
+ 'customProviderBaseURL',
27
+ 'useCustomProviderBaseURLInput',
28
+ 'headers',
29
+ 'useHeadersInput',
30
+ 'extraProviderOptions',
31
+ 'useExtraProviderOptionsInput',
32
+ 'openAIReasoningEffort',
33
+ 'openAIReasoningSummary',
34
+ 'openAIPreviousResponseId',
35
+ 'useOpenAIPreviousResponseIdInput',
36
+ 'enableOpenAIWebSearch',
37
+ 'openAIWebSearchContextSize',
38
+ 'enableOpenAICodeInterpreter',
39
+ 'anthropicThinkingMode',
40
+ 'anthropicThinkingBudget',
41
+ 'useAnthropicThinkingBudgetInput',
42
+ 'anthropicEffort',
43
+ 'anthropicCacheControlTtl',
44
+ 'googleThinkingBudget',
45
+ 'useGoogleThinkingBudgetInput',
46
+ 'googleThinkingLevel',
47
+ 'googleIncludeThoughts',
48
+ 'enableGoogleSearchGrounding',
49
+ 'enableGoogleUrlContext',
50
+ ];
3
51
  export function createLLMChatV2NodeData() {
4
52
  return {
5
53
  ...createChatV2CommonNodeData({
6
54
  model: 'gpt-5',
7
55
  }),
56
+ configurationMode: 'inline',
8
57
  provider: 'openai',
9
58
  apiKeySource: 'environment',
10
59
  customProviderApiKeyProgrammaticName: '',
@@ -49,9 +98,10 @@ export function createLLMChatV2NodeData() {
49
98
  retryOnNon200RepeatTimes: DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_REPEAT_TIMES,
50
99
  retryOnNon200CooldownMs: DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_COOLDOWN_MS,
51
100
  outputRequestStatus: false,
101
+ outputRequestError: false,
102
+ outputRequestBody: false,
52
103
  };
53
104
  }
54
- export function hasLLMChatV2BuiltInToolsEnabled(data) {
55
- return ((data.provider === 'openai' && (data.enableOpenAIWebSearch || data.enableOpenAICodeInterpreter)) ||
56
- (data.provider === 'google' && (data.enableGoogleSearchGrounding || data.enableGoogleUrlContext)));
105
+ export function shouldIncludeLLMChatV2ToolCalls(data) {
106
+ return data.useToolCalling;
57
107
  }
@@ -246,12 +246,6 @@ function getReasoningEditors() {
246
246
  helperMessage: 'OpenAI-compatible Vercel provider option for reasoning models. Some models only support a subset of effort levels.',
247
247
  hideIf: hideUnlessProvider('openai'),
248
248
  },
249
- {
250
- type: 'toggle',
251
- label: 'Output reasoning',
252
- dataKey: 'outputReasoning',
253
- helperMessage: 'Adds a Reasoning output when the provider/model exposes reasoning or thinking text through the Vercel AI SDK. Some providers only expose token counts or summaries.',
254
- },
255
249
  {
256
250
  type: 'string',
257
251
  label: 'Reasoning summary',
@@ -382,7 +376,8 @@ function getToolEditors() {
382
376
  label: 'Allow parallel toolcalls',
383
377
  dataKey: 'parallelToolCalls',
384
378
  helperMessage: LLM_CHAT_V2_PARALLEL_TOOL_CALLS_HELPER_MESSAGE,
385
- hideIf: (data) => !data.useToolCalling || !supportsLLMChatV2ParallelToolCalls(data.provider),
379
+ hideIf: (data) => !data.useToolCalling ||
380
+ (data.configurationMode !== 'profile' && !supportsLLMChatV2ParallelToolCalls(data.provider)),
386
381
  },
387
382
  {
388
383
  type: 'toggle',
@@ -403,12 +398,30 @@ function getToolEditors() {
403
398
  }
404
399
  function getOutputEditors() {
405
400
  return group('Outputs', [
401
+ {
402
+ type: 'toggle',
403
+ label: 'Output reasoning',
404
+ dataKey: 'outputReasoning',
405
+ helperMessage: 'Adds a Reasoning output when the provider/model exposes reasoning or thinking text through the Vercel AI SDK. Some providers only expose token counts or summaries.',
406
+ },
406
407
  {
407
408
  type: 'toggle',
408
409
  label: 'Output usage details',
409
410
  dataKey: 'outputUsage',
410
411
  helperMessage: 'Adds a Usage output built from Vercel AI SDK usage metadata: prompt, completion, total, cached, reasoning tokens, and estimated cost when available.',
411
412
  },
413
+ {
414
+ type: 'toggle',
415
+ label: 'Output response status',
416
+ dataKey: 'outputRequestStatus',
417
+ helperMessage: 'Adds a Response Status output. Retry mode returns statuses for each physical request. An LLM Profile array groups values by profile, while a profile with one request stays a number.',
418
+ },
419
+ {
420
+ type: 'toggle',
421
+ label: 'Output request body',
422
+ dataKey: 'outputRequestBody',
423
+ helperMessage: 'Adds an LLM request body output. It can contain prompts and non-secret provider options; it never includes authorization headers or API keys.',
424
+ },
412
425
  {
413
426
  type: 'toggle',
414
427
  label: 'Stream response',
@@ -417,9 +430,10 @@ function getOutputEditors() {
417
430
  },
418
431
  {
419
432
  type: 'toggle',
420
- label: 'Cache outputs (editor only)',
433
+ label: 'Cache outputs (editor only) (legacy)',
421
434
  dataKey: 'cache',
422
- helperMessage: "Reuses this node's previous outputs if the input is the same (provider config, prompt and generation settings). The cache persists while the Rivet app is open.",
435
+ helperMessage: "Legacy editor-only cache. It reuses this node's previous outputs for the same input while the Rivet app is open. Turn it off to retire it from this node.",
436
+ hideIf: (data) => data.cache !== true,
423
437
  },
424
438
  ]);
425
439
  }
@@ -444,8 +458,8 @@ function getProviderAdvancedEditors() {
444
458
  },
445
459
  ]);
446
460
  }
447
- function getTechnicalDetailsEditors() {
448
- return group('Technical details', [
461
+ function getErrorBehaviorEditors() {
462
+ return group('Error behavior', [
449
463
  {
450
464
  type: 'toggle',
451
465
  label: 'Retry on non-200',
@@ -476,22 +490,42 @@ function getTechnicalDetailsEditors() {
476
490
  },
477
491
  {
478
492
  type: 'toggle',
479
- label: 'Output request details',
480
- dataKey: 'outputRequestStatus',
481
- helperMessage: 'Adds Response Status, Response Error, and LLM request body outputs. Retry mode changes status/error to per-attempt arrays, and LLM request body becomes an array when multiple provider calls are made.',
493
+ label: 'Output response error',
494
+ dataKey: 'outputRequestError',
495
+ helperMessage: 'Adds a Response Error output. Provider request failures become excluded outputs instead of node errors. Retry mode returns errors for each physical request; an LLM Profile array groups errors by profile.',
482
496
  },
483
497
  ]);
484
498
  }
485
499
  export async function getLLMChatV2Editors(data, context) {
500
+ const usesProfile = data.configurationMode === 'profile';
486
501
  return [
487
- getModelEditors(await getResolvedModelOptions(data, context)),
488
- ...getProviderEditors(),
489
- getParameterEditors(),
490
- getReasoningEditors(),
502
+ {
503
+ type: 'custom',
504
+ label: 'Configuration',
505
+ customEditorId: 'LLMChatV2Configuration',
506
+ },
507
+ ...(!usesProfile
508
+ ? [
509
+ getModelEditors(await getResolvedModelOptions(data, context)),
510
+ ...getProviderEditors(),
511
+ getParameterEditors(),
512
+ ...(data.provider === 'custom' ? [] : [getReasoningEditors()]),
513
+ ]
514
+ : []),
491
515
  getResponseFormatEditors(),
492
516
  getToolEditors(),
493
517
  getOutputEditors(),
518
+ ...(!usesProfile ? [getProviderAdvancedEditors()] : []),
519
+ getErrorBehaviorEditors(),
520
+ ];
521
+ }
522
+ export async function getLLMProfileEditors(data, context) {
523
+ const profileData = data;
524
+ return [
525
+ getModelEditors(await getResolvedModelOptions(profileData, context)),
526
+ ...getProviderEditors(),
527
+ getParameterEditors(),
528
+ ...(profileData.provider === 'custom' ? [] : [getReasoningEditors()]),
494
529
  getProviderAdvancedEditors(),
495
- getTechnicalDetailsEditors(),
496
530
  ];
497
531
  }