@valerypopoff/rivet2-core 2.1.8 → 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 (55) hide show
  1. package/dist/cjs/bundle.cjs +1922 -1125
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/esm/model/GraphProcessor.js +1 -0
  4. package/dist/esm/model/SplitRunProcessor.js +19 -10
  5. package/dist/esm/model/ToolCallContinuationCoordinator.js +6 -1
  6. package/dist/esm/model/chat/aiSdkMessages.js +8 -0
  7. package/dist/esm/model/chat-v2/chatV2CallObserver.js +2 -0
  8. package/dist/esm/model/chat-v2/chatV2EditorCache.js +22 -0
  9. package/dist/esm/model/chat-v2/chatV2Outputs.js +41 -31
  10. package/dist/esm/model/chat-v2/chatV2Pipeline.js +122 -44
  11. package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +1 -0
  12. package/dist/esm/model/chat-v2/chatV2RequestPlan.js +6 -5
  13. package/dist/esm/model/chat-v2/chatV2Shared.js +1 -6
  14. package/dist/esm/model/chat-v2/chatV2Types.js +11 -1
  15. package/dist/esm/model/chat-v2/developerMessageRoles.js +45 -0
  16. package/dist/esm/model/chat-v2/llmChatV2NodeData.js +3 -5
  17. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +22 -13
  18. package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +224 -68
  19. package/dist/esm/model/chat-v2/llmProfile.js +21 -0
  20. package/dist/esm/model/chat-v2/llmProfileFallback.js +288 -0
  21. package/dist/esm/model/chat-v2/messageConverter.js +14 -0
  22. package/dist/esm/model/chat-v2/providerOptions.js +44 -11
  23. package/dist/esm/model/chat-v2/toolContinuation.js +0 -4
  24. package/dist/esm/model/nodes/AssembleMessageNode.js +6 -0
  25. package/dist/esm/model/nodes/DelegateFunctionCallNode.js +12 -0
  26. package/dist/esm/model/nodes/LLMChatV2Node.js +115 -11
  27. package/dist/esm/model/nodes/PromptNode.js +9 -2
  28. package/dist/esm/model/nodes/toolCallDelegation.js +18 -2
  29. package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +22 -28
  30. package/dist/esm/plugins/google/google.js +20 -9
  31. package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +17 -6
  32. package/dist/esm/utils/chatMessageToOpenAIChatCompletionMessage.js +4 -0
  33. package/dist/esm/utils/serialization/serialization.js +19 -0
  34. package/dist/types/model/DataValue.d.ts +7 -1
  35. package/dist/types/model/NodeBase.d.ts +6 -0
  36. package/dist/types/model/ProcessContext.d.ts +4 -0
  37. package/dist/types/model/SplitRunProcessor.d.ts +2 -1
  38. package/dist/types/model/chat-v2/chatV2EditorCache.d.ts +4 -0
  39. package/dist/types/model/chat-v2/chatV2Outputs.d.ts +5 -5
  40. package/dist/types/model/chat-v2/chatV2Pipeline.d.ts +33 -0
  41. package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +1 -0
  42. package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +2 -2
  43. package/dist/types/model/chat-v2/chatV2Shared.d.ts +0 -1
  44. package/dist/types/model/chat-v2/chatV2Types.d.ts +24 -0
  45. package/dist/types/model/chat-v2/developerMessageRoles.d.ts +10 -0
  46. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +4 -1
  47. package/dist/types/model/chat-v2/llmChatV2NodeRuntime.d.ts +18 -2
  48. package/dist/types/model/chat-v2/llmProfile.d.ts +7 -0
  49. package/dist/types/model/chat-v2/llmProfileFallback.d.ts +79 -0
  50. package/dist/types/model/chat-v2/providerOptions.d.ts +1 -0
  51. package/dist/types/model/nodes/AssembleMessageNode.d.ts +2 -1
  52. package/dist/types/model/nodes/PromptNode.d.ts +2 -2
  53. package/dist/types/plugins/google/google.d.ts +12 -1
  54. package/dist/types/plugins/google/nodes/ChatGoogleNode.d.ts +2 -1
  55. package/package.json +1 -1
@@ -98,12 +98,10 @@ export function createLLMChatV2NodeData() {
98
98
  retryOnNon200RepeatTimes: DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_REPEAT_TIMES,
99
99
  retryOnNon200CooldownMs: DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_COOLDOWN_MS,
100
100
  outputRequestStatus: false,
101
+ outputRequestError: false,
102
+ outputRequestBody: false,
101
103
  };
102
104
  }
103
- export function hasLLMChatV2BuiltInToolsEnabled(data) {
104
- return ((data.provider === 'openai' && (data.enableOpenAIWebSearch || data.enableOpenAICodeInterpreter)) ||
105
- (data.provider === 'google' && (data.enableGoogleSearchGrounding || data.enableGoogleUrlContext)));
106
- }
107
105
  export function shouldIncludeLLMChatV2ToolCalls(data) {
108
- return data.configurationMode === 'profile' || data.useToolCalling || hasLLMChatV2BuiltInToolsEnabled(data);
106
+ return data.useToolCalling;
109
107
  }
@@ -103,11 +103,7 @@ function getModelEditors(modelOptions) {
103
103
  ], true);
104
104
  }
105
105
  function getProviderEditors() {
106
- return [
107
- getOpenAIProviderEditors(),
108
- getAnthropicProviderEditors(),
109
- getGoogleProviderEditors(),
110
- ];
106
+ return [getOpenAIProviderEditors(), getAnthropicProviderEditors(), getGoogleProviderEditors()];
111
107
  }
112
108
  function getOpenAIProviderEditors() {
113
109
  return providerGroup('openai', 'OpenAI', [
@@ -414,6 +410,18 @@ function getOutputEditors() {
414
410
  dataKey: 'outputUsage',
415
411
  helperMessage: 'Adds a Usage output built from Vercel AI SDK usage metadata: prompt, completion, total, cached, reasoning tokens, and estimated cost when available.',
416
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
+ },
417
425
  {
418
426
  type: 'toggle',
419
427
  label: 'Stream response',
@@ -422,9 +430,10 @@ function getOutputEditors() {
422
430
  },
423
431
  {
424
432
  type: 'toggle',
425
- label: 'Cache outputs (editor only)',
433
+ label: 'Cache outputs (editor only) (legacy)',
426
434
  dataKey: 'cache',
427
- 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,
428
437
  },
429
438
  ]);
430
439
  }
@@ -449,8 +458,8 @@ function getProviderAdvancedEditors() {
449
458
  },
450
459
  ]);
451
460
  }
452
- function getTechnicalDetailsEditors() {
453
- return group('Technical details', [
461
+ function getErrorBehaviorEditors() {
462
+ return group('Error behavior', [
454
463
  {
455
464
  type: 'toggle',
456
465
  label: 'Retry on non-200',
@@ -481,9 +490,9 @@ function getTechnicalDetailsEditors() {
481
490
  },
482
491
  {
483
492
  type: 'toggle',
484
- label: 'Output request details',
485
- dataKey: 'outputRequestStatus',
486
- 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.',
487
496
  },
488
497
  ]);
489
498
  }
@@ -507,7 +516,7 @@ export async function getLLMChatV2Editors(data, context) {
507
516
  getToolEditors(),
508
517
  getOutputEditors(),
509
518
  ...(!usesProfile ? [getProviderAdvancedEditors()] : []),
510
- getTechnicalDetailsEditors(),
519
+ getErrorBehaviorEditors(),
511
520
  ];
512
521
  }
513
522
  export async function getLLMProfileEditors(data, context) {
@@ -1,13 +1,18 @@
1
1
  import { coerceTypeOptional } from '../../utils/coerceType.js';
2
- import { getInputOrData } from '../../utils/inputs.js';
2
+ import { cleanHeaders, getInputOrData } from '../../utils/inputs.js';
3
+ import { coercePromptToChatMessages, prependSystemPrompt } from '../chat/chatMessages.js';
4
+ import { getInstructionMessageRoles, restoreOpenAICompatibleInstructionRoles } from './developerMessageRoles.js';
3
5
  import { createChatV2ResponseOutput, mergeCustomProviderResponseFormatOptions, resolveChatV2ResponseFormatParameters, } from './chatV2ResponseFormat.js';
4
6
  import { hasLLMChatV2ToolResponseFormatConflict, LLM_CHAT_V2_TOOL_RESPONSE_FORMAT_CONFLICT_COPY, } from './chatV2FeatureCompatibility.js';
5
- import { parseChatV2Provider } from './providerOptions.js';
7
+ import { createLLMProfileFallbackRunner } from './llmProfileFallback.js';
8
+ import { applyLLMProfileToNodeData, normalizeLLMProfileChainInput } from './llmProfile.js';
9
+ import { parseChatV2Provider, resolveChatV2ProviderConfig } from './providerOptions.js';
6
10
  import { createResolvedChatV2Provider, resolveChatV2Credential } from './chatV2ProviderProfile.js';
7
- import { applyLLMProfileToNodeData, normalizeLLMProfileValue } from './llmProfile.js';
11
+ import { shouldOutputChatV2RequestBody, shouldOutputChatV2RequestError, } from './chatV2Types.js';
8
12
  import { buildLLMChatV2EditorCacheKey, cloneLLMChatV2EditorCacheOutputs, resolveLLMChatV2EditorCache, } from './chatV2EditorCache.js';
9
13
  import { resolveLLMChatV2BuiltInTools, resolveLLMChatV2GenerationParameters, resolveLLMChatV2Headers, resolveLLMChatV2RuntimeProviderOptions, resolveLLMChatV2ToolChoice, } from './chatV2RuntimeOptions.js';
10
14
  import { shouldIncludeLLMChatV2ToolCalls, } from './llmChatV2NodeData.js';
15
+ import { runChatV2Pipeline } from './chatV2Pipeline.js';
11
16
  export { buildLLMChatV2EditorCacheKey, cloneLLMChatV2EditorCacheOutputs };
12
17
  export { resolveLLMChatV2RuntimeProviderOptions } from './chatV2RuntimeOptions.js';
13
18
  function resolveLLMChatV2BaseURL(data, inputs) {
@@ -16,102 +21,253 @@ function resolveLLMChatV2BaseURL(data, inputs) {
16
21
  undefined
17
22
  : undefined;
18
23
  }
19
- export async function resolveLLMChatV2RuntimeConfig(params) {
20
- const { data, nodeId, inputs, context } = params;
21
- const profileInput = inputs['llmProfile'];
22
- if (data.configurationMode === 'profile' && profileInput == null) {
23
- throw new Error('LLM Profile input is required when Configuration is From profile.');
24
- }
25
- const profile = data.configurationMode === 'profile' ? normalizeLLMProfileValue(profileInput?.value) : undefined;
26
- const effectiveData = profile ? applyLLMProfileToNodeData(data, profile) : data;
24
+ function createSharedRunOptions(params) {
25
+ const { shared, provider, modelId } = params;
26
+ return {
27
+ provider,
28
+ // From profile mode replaces this before a provider request. Keeping the
29
+ // field populated preserves the established Tool Continuation contract.
30
+ model: undefined,
31
+ modelId,
32
+ prompt: shared.prompt,
33
+ systemPrompt: shared.systemPrompt,
34
+ functions: shared.functions,
35
+ responseOutput: createChatV2ResponseOutput(shared.responseFormatParameters, provider),
36
+ responseFormat: shared.responseFormatParameters?.responseFormat,
37
+ outputUsage: shared.data.outputUsage,
38
+ outputReasoning: shared.data.outputReasoning,
39
+ outputRequestStatus: shared.data.outputRequestStatus,
40
+ outputRequestError: shouldOutputChatV2RequestError(shared.data),
41
+ outputRequestBody: shouldOutputChatV2RequestBody(shared.data),
42
+ includeFunctionCalls: shouldIncludeLLMChatV2ToolCalls(shared.data),
43
+ emitPartialOutputs: shared.data.useAsGraphPartialOutput,
44
+ toolChoice: shared.toolChoice,
45
+ requestBodies: shared.requestBodies,
46
+ retryOnNon200: shared.data.retryOnNon200,
47
+ retryOnNon200RepeatTimes: shared.data.retryOnNon200RepeatTimes,
48
+ retryOnNon200CooldownMs: shared.data.retryOnNon200CooldownMs,
49
+ context: shared.context,
50
+ };
51
+ }
52
+ function createRuntimeProviderProfile(params) {
53
+ const provider = parseChatV2Provider(params.data.provider);
54
+ return {
55
+ provider,
56
+ modelId: getInputOrData(params.data, params.inputs, 'model', 'string'),
57
+ baseURL: resolveLLMChatV2BaseURL(params.data, params.inputs),
58
+ hasCustomHeaders: Object.keys(resolveLLMChatV2Headers(params.data, params.inputs) ?? {}).length > 0,
59
+ credential: params.credential.reference,
60
+ capabilities: {
61
+ builtInTools: provider === 'openai' || provider === 'google',
62
+ structuredOutput: true,
63
+ },
64
+ };
65
+ }
66
+ async function resolveCandidateRunOptions(params) {
67
+ const { shared, profile, roundOptions } = params;
68
+ const effectiveData = profile ? applyLLMProfileToNodeData(shared.data, profile) : shared.data;
27
69
  if (hasLLMChatV2ToolResponseFormatConflict(effectiveData)) {
28
70
  throw new Error(LLM_CHAT_V2_TOOL_RESPONSE_FORMAT_CONFLICT_COPY.paragraphs[0]);
29
71
  }
30
72
  const provider = parseChatV2Provider(effectiveData.provider);
31
- const modelId = getInputOrData(effectiveData, inputs, 'model', 'string');
32
- const baseURL = resolveLLMChatV2BaseURL(effectiveData, inputs);
33
- const nodeHeaders = resolveLLMChatV2Headers(effectiveData, inputs);
73
+ const modelId = getInputOrData(effectiveData, shared.inputs, 'model', 'string');
74
+ const baseURL = resolveLLMChatV2BaseURL(effectiveData, shared.inputs);
75
+ const headers = resolveLLMChatV2Headers(effectiveData, shared.inputs);
34
76
  const credential = profile?.credential ??
35
77
  resolveChatV2Credential({
36
78
  provider,
37
- context,
79
+ context: shared.context,
38
80
  apiKeySource: effectiveData.apiKeySource === 'input' ? 'input' : 'configured',
39
- inputs,
81
+ inputs: shared.inputs,
40
82
  customProgrammaticName: effectiveData.customProviderApiKeyProgrammaticName,
41
83
  customEnvironmentName: effectiveData.customProviderApiKeyEnvVarName,
42
84
  });
43
- const apiKey = credential.value;
44
- const requestBodies = effectiveData.outputRequestStatus ? [] : undefined;
85
+ const transformRequestBody = (provider === 'openai' || provider === 'custom') && shared.instructionRoles.includes('developer')
86
+ ? (body) => restoreOpenAICompatibleInstructionRoles(body, shared.instructionRoles)
87
+ : undefined;
45
88
  const resolvedProvider = await createResolvedChatV2Provider({
46
89
  provider,
47
90
  modelId,
48
- context,
91
+ context: shared.context,
49
92
  baseURL,
50
- headers: nodeHeaders,
93
+ headers,
51
94
  credential,
52
- onRequestBody: requestBodies == null ? undefined : (body) => requestBodies.push(body),
95
+ onRequestBody: shared.requestBodies == null ? undefined : (body) => shared.requestBodies.push(body),
96
+ transformRequestBody,
53
97
  });
54
- const providerConfig = resolvedProvider.config;
55
- const model = resolvedProvider.model;
56
- const prompt = inputs['prompt'];
57
- const systemPrompt = inputs['systemPrompt'];
58
- const functions = effectiveData.useToolCalling && inputs['functions'] != null
59
- ? coerceTypeOptional(inputs['functions'], 'gpt-function[]')
60
- : undefined;
61
- const toolChoice = resolveLLMChatV2ToolChoice(effectiveData);
62
- const responseFormatParameters = resolveChatV2ResponseFormatParameters(effectiveData, inputs);
63
- const providerOptions = mergeCustomProviderResponseFormatOptions(provider, resolveLLMChatV2RuntimeProviderOptions(effectiveData, inputs), responseFormatParameters);
64
- const generationParameters = resolveLLMChatV2GenerationParameters(effectiveData, inputs);
65
- const runOptions = {
98
+ const generationParameters = resolveLLMChatV2GenerationParameters(effectiveData, shared.inputs);
99
+ const providerOptions = mergeCustomProviderResponseFormatOptions(provider, resolveLLMChatV2RuntimeProviderOptions(effectiveData, shared.inputs), shared.responseFormatParameters);
100
+ return {
101
+ ...roundOptions,
66
102
  provider,
67
- model,
103
+ model: resolvedProvider.model,
68
104
  modelId,
69
- prompt,
70
- systemPrompt,
71
- functions,
72
- additionalTools: resolveLLMChatV2BuiltInTools(effectiveData, context, providerConfig, apiKey),
105
+ additionalTools: resolveLLMChatV2BuiltInTools(effectiveData, shared.context, resolvedProvider.config, credential.value),
73
106
  ...generationParameters,
74
- responseOutput: createChatV2ResponseOutput(responseFormatParameters, provider),
75
- responseFormat: responseFormatParameters?.responseFormat,
76
- outputUsage: effectiveData.outputUsage,
77
- outputReasoning: effectiveData.outputReasoning,
78
- outputRequestStatus: effectiveData.outputRequestStatus,
79
- includeFunctionCalls: shouldIncludeLLMChatV2ToolCalls(effectiveData),
80
- emitPartialOutputs: effectiveData.useAsGraphPartialOutput,
107
+ responseOutput: createChatV2ResponseOutput(shared.responseFormatParameters, provider),
108
+ responseFormat: shared.responseFormatParameters?.responseFormat,
81
109
  providerOptions,
82
- toolChoice,
83
110
  anthropicCacheControlTtl: provider === 'anthropic' ? effectiveData.anthropicCacheControlTtl || undefined : undefined,
84
- requestBodies,
85
- retryOnNon200: effectiveData.retryOnNon200,
86
- retryOnNon200RepeatTimes: effectiveData.retryOnNon200RepeatTimes,
87
- retryOnNon200CooldownMs: effectiveData.retryOnNon200CooldownMs,
111
+ requestBodies: shared.requestBodies,
112
+ };
113
+ }
114
+ function createSharedRuntimeValues(params) {
115
+ const { data, inputs, context } = params;
116
+ const prompt = inputs['prompt'];
117
+ const systemPrompt = inputs['systemPrompt'];
118
+ return {
119
+ data,
120
+ inputs,
88
121
  context,
122
+ prompt,
123
+ systemPrompt,
124
+ functions: data.useToolCalling && inputs['functions'] != null
125
+ ? coerceTypeOptional(inputs['functions'], 'gpt-function[]')
126
+ : undefined,
127
+ responseFormatParameters: resolveChatV2ResponseFormatParameters(data, inputs),
128
+ toolChoice: resolveLLMChatV2ToolChoice(data),
129
+ requestBodies: shouldOutputChatV2RequestBody(data) ? [] : undefined,
130
+ instructionRoles: getInstructionMessageRoles(prependSystemPrompt(coercePromptToChatMessages(prompt), systemPrompt)),
89
131
  };
90
- const editorCache = effectiveData.cache ? context.editorExecutionCache : undefined;
132
+ }
133
+ export async function resolveLLMChatV2RuntimeConfig(params) {
134
+ const { data, nodeId, inputs, context } = params;
135
+ const profileInput = inputs['llmProfile'];
136
+ if (data.configurationMode === 'profile' && profileInput == null) {
137
+ throw new Error('LLM Profile input is required when Configuration is From profile.');
138
+ }
139
+ const shared = createSharedRuntimeValues({ data, inputs, context });
140
+ const editorCache = data.cache ? context.editorExecutionCache : undefined;
141
+ if (data.configurationMode !== 'profile') {
142
+ const inlineRunOptions = await resolveCandidateRunOptions({
143
+ shared,
144
+ profile: undefined,
145
+ roundOptions: createSharedRunOptions({
146
+ shared,
147
+ provider: parseChatV2Provider(data.provider),
148
+ modelId: data.model,
149
+ }),
150
+ });
151
+ const generationParameters = resolveLLMChatV2GenerationParameters(data, inputs);
152
+ const inlineCredential = resolveChatV2Credential({
153
+ provider: inlineRunOptions.provider,
154
+ context,
155
+ apiKeySource: data.apiKeySource === 'input' ? 'input' : 'configured',
156
+ inputs,
157
+ customProgrammaticName: data.customProviderApiKeyProgrammaticName,
158
+ customEnvironmentName: data.customProviderApiKeyEnvVarName,
159
+ });
160
+ const inlineProviderConfig = await resolveChatV2ProviderConfig(inlineRunOptions.provider, inlineRunOptions.modelId, context, {
161
+ baseURL: resolveLLMChatV2BaseURL(data, inputs),
162
+ headers: resolveLLMChatV2Headers(data, inputs),
163
+ });
164
+ const { cacheKey, cachedOutputs } = resolveLLMChatV2EditorCache({
165
+ apiKey: inlineCredential.value,
166
+ data,
167
+ editorCache,
168
+ functions: shared.functions,
169
+ generationParameters,
170
+ modelId: inlineRunOptions.modelId,
171
+ nodeId,
172
+ prompt: shared.prompt,
173
+ provider: inlineRunOptions.provider,
174
+ providerConfig: inlineProviderConfig,
175
+ providerOptions: inlineRunOptions.providerOptions,
176
+ responseFormatParameters: shared.responseFormatParameters,
177
+ systemPrompt: shared.systemPrompt,
178
+ toolChoice: shared.toolChoice,
179
+ });
180
+ return {
181
+ runOptions: inlineRunOptions,
182
+ providerProfile: createRuntimeProviderProfile({
183
+ data,
184
+ inputs,
185
+ credential: inlineCredential,
186
+ }),
187
+ runPipeline: runChatV2Pipeline,
188
+ functions: shared.functions,
189
+ cacheKey,
190
+ cachedOutputs,
191
+ editorCache,
192
+ shouldAutoContinueToolCalls: !!data.autoContinueToolCalls && data.useToolCalling,
193
+ maxToolRounds: data.maxToolRounds ?? 3,
194
+ profileAttempts: undefined,
195
+ profileChainUsesArray: false,
196
+ profileChainLength: undefined,
197
+ getProfileSummary: undefined,
198
+ isProfileFallbackExhausted: () => false,
199
+ };
200
+ }
201
+ const profiles = normalizeLLMProfileChainInput(profileInput?.value);
202
+ const firstProfile = profiles[0];
203
+ const firstProvider = parseChatV2Provider(firstProfile.configuration.provider);
204
+ const profileRunOptions = createSharedRunOptions({
205
+ shared,
206
+ provider: firstProvider,
207
+ modelId: firstProfile.configuration.model,
208
+ });
209
+ const firstProfileData = applyLLMProfileToNodeData(data, firstProfile);
210
+ Object.assign(profileRunOptions, {
211
+ ...resolveLLMChatV2GenerationParameters(firstProfileData, inputs),
212
+ providerOptions: mergeCustomProviderResponseFormatOptions(firstProvider, resolveLLMChatV2RuntimeProviderOptions(firstProfileData, inputs), shared.responseFormatParameters),
213
+ anthropicCacheControlTtl: firstProvider === 'anthropic' ? firstProfileData.anthropicCacheControlTtl || undefined : undefined,
214
+ });
215
+ const fallbackRunner = createLLMProfileFallbackRunner({
216
+ candidates: profiles.map((profile) => ({
217
+ provider: parseChatV2Provider(profile.configuration.provider),
218
+ model: profile.configuration.model,
219
+ credential: profile.credential.value,
220
+ redactionValues: [
221
+ ...profile.configuration.headers.map((header) => header.value),
222
+ ...Object.values(cleanHeaders(context.settings?.chatNodeHeaders ?? {})),
223
+ ],
224
+ })),
225
+ resolveCandidate: (profileIndex, roundOptions) => resolveCandidateRunOptions({
226
+ shared,
227
+ profile: profiles[profileIndex],
228
+ roundOptions,
229
+ }),
230
+ });
91
231
  const { cacheKey, cachedOutputs } = resolveLLMChatV2EditorCache({
92
- apiKey,
93
- data: effectiveData,
232
+ apiKey: undefined,
233
+ data: firstProfileData,
94
234
  editorCache,
95
- functions,
96
- generationParameters,
97
- modelId,
235
+ functions: shared.functions,
236
+ generationParameters: undefined,
237
+ modelId: firstProfile.configuration.model,
98
238
  nodeId,
99
- prompt,
100
- provider,
101
- providerConfig,
102
- providerOptions,
103
- responseFormatParameters,
104
- systemPrompt,
105
- toolChoice,
239
+ prompt: shared.prompt,
240
+ provider: firstProvider,
241
+ // Profile headers are part of the individual profile fingerprints, but
242
+ // provider resolution also merges project-wide Chat headers. Include those
243
+ // values through the existing redacted provider-config fingerprint so a
244
+ // global-header edit cannot reuse a stale profile-mode editor cache entry.
245
+ providerConfig: { headers: cleanHeaders(context.settings?.chatNodeHeaders ?? {}) },
246
+ providerOptions: undefined,
247
+ responseFormatParameters: shared.responseFormatParameters,
248
+ systemPrompt: shared.systemPrompt,
249
+ toolChoice: shared.toolChoice,
250
+ profileChain: profiles,
251
+ profileChainUsesArray: Array.isArray(profileInput?.value),
106
252
  });
107
253
  return {
108
- providerProfile: resolvedProvider.profile,
109
- runOptions,
110
- functions,
254
+ runOptions: profileRunOptions,
255
+ providerProfile: createRuntimeProviderProfile({
256
+ data: firstProfileData,
257
+ inputs,
258
+ credential: firstProfile.credential,
259
+ }),
260
+ runPipeline: fallbackRunner.run,
261
+ functions: shared.functions,
111
262
  cacheKey,
112
263
  cachedOutputs,
113
264
  editorCache,
114
- shouldAutoContinueToolCalls: !!effectiveData.autoContinueToolCalls && effectiveData.useToolCalling,
115
- maxToolRounds: effectiveData.maxToolRounds ?? 3,
265
+ shouldAutoContinueToolCalls: !!data.autoContinueToolCalls && data.useToolCalling,
266
+ maxToolRounds: data.maxToolRounds ?? 3,
267
+ profileAttempts: fallbackRunner.attempts,
268
+ profileChainUsesArray: Array.isArray(profileInput?.value),
269
+ profileChainLength: profiles.length,
270
+ getProfileSummary: fallbackRunner.summary,
271
+ isProfileFallbackExhausted: fallbackRunner.wasExhausted,
116
272
  };
117
273
  }
@@ -98,6 +98,27 @@ export function normalizeLLMProfileValue(value) {
98
98
  credential,
99
99
  };
100
100
  }
101
+ /**
102
+ * Normalizes the single LLM Profile or ordered fallback chain accepted by
103
+ * LLM Chat's From profile input. We validate every member here rather than
104
+ * trusting a same-type `llm-config[]` wrapper: arrays can otherwise carry
105
+ * malformed values without re-entering scalar coercion.
106
+ */
107
+ export function normalizeLLMProfileChainInput(value) {
108
+ const rawProfiles = Array.isArray(value) ? value : [value];
109
+ if (rawProfiles.length === 0) {
110
+ throw new Error('LLM Profiles input must contain at least one LLM Profile.');
111
+ }
112
+ return rawProfiles.map((profile, index) => {
113
+ try {
114
+ return normalizeLLMProfileValue(profile);
115
+ }
116
+ catch (error) {
117
+ const message = error instanceof Error ? error.message : String(error);
118
+ throw new Error(`LLM Profiles input item ${index} is invalid: ${message}`);
119
+ }
120
+ });
121
+ }
101
122
  function normalizeConfiguration(data) {
102
123
  for (const field of stringFields) {
103
124
  if (typeof data[field] !== 'string') {