@valerypopoff/rivet2-core 2.1.1 → 2.1.3

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 (53) hide show
  1. package/dist/cjs/bundle.cjs +925 -433
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/esm/api/processSettings.js +11 -1
  4. package/dist/esm/exports.js +2 -0
  5. package/dist/esm/model/GraphProcessor.js +24 -45
  6. package/dist/esm/model/GraphRunLifecycle.js +67 -0
  7. package/dist/esm/model/MarkdownSanitizationPolicy.js +38 -0
  8. package/dist/esm/model/UiGraph.js +57 -0
  9. package/dist/esm/model/UiGraphRendererStyles.js +82 -0
  10. package/dist/esm/model/UiGraphRuntimeModel.js +71 -0
  11. package/dist/esm/model/chat-v2/aiSdkBridge.js +1 -1
  12. package/dist/esm/model/chat-v2/chatV2EditorCache.js +2 -2
  13. package/dist/esm/model/chat-v2/chatV2Pipeline.js +35 -48
  14. package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +98 -0
  15. package/dist/esm/model/chat-v2/chatV2RequestPlan.js +64 -0
  16. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +13 -36
  17. package/dist/esm/model/chat-v2/index.js +2 -0
  18. package/dist/esm/model/chat-v2/llmChatV2NodeData.js +1 -0
  19. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +31 -11
  20. package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +21 -9
  21. package/dist/esm/model/chat-v2/providerOptions.js +12 -38
  22. package/dist/esm/model/nodes/LLMChatV2Node.js +3 -3
  23. package/dist/esm/plugins/autoevals/AutoEvalsNode.js +3 -1
  24. package/dist/esm/plugins/gentrace/gentraceSdk.js +8 -0
  25. package/dist/esm/plugins/gentrace/plugin.js +5 -4
  26. package/dist/esm/plugins/google/google.js +9 -7
  27. package/dist/esm/utils/getPluginConfig.js +15 -3
  28. package/dist/esm/utils/pQueueCompat.js +1 -1
  29. package/dist/esm/utils/serialization/serializationUtils.js +35 -0
  30. package/dist/esm/utils/serialization/serialization_v4.js +5 -4
  31. package/dist/esm/webAppRuntime.js +2 -0
  32. package/dist/types/api/createProcessor.d.ts +1 -1
  33. package/dist/types/api/processSettings.d.ts +3 -4
  34. package/dist/types/exports.d.ts +2 -0
  35. package/dist/types/model/GraphRunLifecycle.d.ts +22 -0
  36. package/dist/types/model/MarkdownSanitizationPolicy.d.ts +9 -0
  37. package/dist/types/model/ProcessContext.d.ts +2 -2
  38. package/dist/types/model/Settings.d.ts +5 -0
  39. package/dist/types/model/UiGraph.d.ts +12 -0
  40. package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
  41. package/dist/types/model/UiGraphRuntimeModel.d.ts +52 -0
  42. package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +46 -0
  43. package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +42 -0
  44. package/dist/types/model/chat-v2/chatV2Types.d.ts +1 -0
  45. package/dist/types/model/chat-v2/index.d.ts +2 -0
  46. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +1 -0
  47. package/dist/types/model/chat-v2/llmChatV2NodeRuntime.d.ts +2 -0
  48. package/dist/types/model/chat-v2/providerOptions.d.ts +2 -2
  49. package/dist/types/plugins/gentrace/gentraceSdk.d.ts +5 -0
  50. package/dist/types/plugins/gentrace/plugin.d.ts +1 -1
  51. package/dist/types/utils/pQueueCompat.d.ts +1 -1
  52. package/dist/types/webAppRuntime.d.ts +4 -0
  53. package/package.json +15 -9
@@ -2,8 +2,9 @@ import { coercePromptToChatMessages, prependSystemPrompt } from '../chat/chatMes
2
2
  import { generateChatV2, streamChatV2 } from './aiSdkBridge.js';
3
3
  import { chatMessagesToModelMessages } from './messageConverter.js';
4
4
  import { chatV2ToolsToAiSdk } from './toolConverter.js';
5
+ import { buildChatV2RequestPlan } from './chatV2RequestPlan.js';
5
6
  import { getChatV2ProviderErrorStatusCode, isChatV2ProviderApiCallError, isChatV2ProviderFetchError, normalizeChatV2ProviderError, } from './chatV2Errors.js';
6
- import { normalizeLLMChatV2RetryCooldownMs, normalizeLLMChatV2RetryCount, waitForLLMChatV2RetryCooldown, } from './chatV2Retry.js';
7
+ import { waitForLLMChatV2RetryCooldown, } from './chatV2Retry.js';
7
8
  import { createChatV2CommonOutputs, createChatV2ProviderFailureOutputs, normalizeChatV2Usage, } from './chatV2Outputs.js';
8
9
  class ChatV2RetryFailure extends Error {
9
10
  error;
@@ -41,46 +42,42 @@ function normalizeProviderFailureMessage(error, options) {
41
42
  function normalizeProviderFailureMessages(errors, options) {
42
43
  return errors.map((error) => normalizeProviderFailureMessage(error, options));
43
44
  }
44
- async function runChatV2WithRetry(chatOptions, retryOptions, transportMode) {
45
- const repeatTimes = retryOptions.retryOnNon200
46
- ? normalizeLLMChatV2RetryCount(retryOptions.retryOnNon200RepeatTimes)
47
- : 0;
48
- const cooldownMs = normalizeLLMChatV2RetryCooldownMs(retryOptions.retryOnNon200CooldownMs);
45
+ async function runChatV2WithRetry(chatOptions, retryPlan, signal, transportMode) {
49
46
  const requestStatuses = [];
50
47
  const requestErrors = [];
51
48
  for (let attempt = 0;; attempt++) {
52
49
  try {
53
50
  const result = transportMode === 'generate' ? await generateChatV2(chatOptions) : await streamChatV2(chatOptions);
54
51
  const statusCode = result.requestStatus ?? 200;
55
- if (retryOptions.retryOnNon200) {
52
+ if (retryPlan.enabled) {
56
53
  requestStatuses.push(statusCode);
57
54
  }
58
- if (!retryOptions.retryOnNon200 || statusCode === 200) {
55
+ if (!retryPlan.enabled || statusCode === 200) {
59
56
  return { result, requestStatuses, requestErrors };
60
57
  }
61
58
  const responseError = buildNon200StatusError(statusCode);
62
59
  requestErrors.push(responseError);
63
- if (attempt >= repeatTimes) {
60
+ if (attempt >= retryPlan.repeatTimes) {
64
61
  return { result, requestStatuses, requestErrors, responseError };
65
62
  }
66
- await waitForLLMChatV2RetryCooldown(cooldownMs, retryOptions.context.signal);
63
+ await waitForLLMChatV2RetryCooldown(retryPlan.cooldownMs, signal);
67
64
  }
68
65
  catch (error) {
69
66
  const statusCode = getChatV2ProviderErrorStatusCode(error);
70
- if (!retryOptions.retryOnNon200 || statusCode == null || statusCode === 200) {
67
+ if (!retryPlan.enabled || statusCode == null || statusCode === 200) {
71
68
  throw error;
72
69
  }
73
70
  requestStatuses.push(statusCode);
74
71
  requestErrors.push(error);
75
- if (attempt >= repeatTimes) {
72
+ if (attempt >= retryPlan.repeatTimes) {
76
73
  throw new ChatV2RetryFailure(error, requestStatuses, requestErrors);
77
74
  }
78
- await waitForLLMChatV2RetryCooldown(cooldownMs, retryOptions.context.signal);
75
+ await waitForLLMChatV2RetryCooldown(retryPlan.cooldownMs, signal);
79
76
  }
80
77
  }
81
78
  }
82
- function buildProviderFailureResult(requestMessages, options, normalizedError, rawError, requestStatuses, requestErrors) {
83
- if (!options.outputRequestStatus) {
79
+ function buildProviderFailureResult(requestMessages, options, plan, normalizedError, rawError, requestStatuses, requestErrors) {
80
+ if (!plan.output.outputRequestStatus) {
84
81
  return undefined;
85
82
  }
86
83
  const statusCode = getChatV2ProviderErrorStatusCode(normalizedError);
@@ -88,14 +85,14 @@ function buildProviderFailureResult(requestMessages, options, normalizedError, r
88
85
  return undefined;
89
86
  }
90
87
  const responseError = getProviderFailureMessage(normalizedError);
91
- const retryRequestStatuses = options.retryOnNon200
88
+ const retryRequestStatuses = plan.retry.enabled
92
89
  ? requestStatuses.length > 0
93
90
  ? requestStatuses
94
91
  : statusCode == null
95
92
  ? []
96
93
  : [statusCode]
97
94
  : [];
98
- const retryRequestErrors = options.retryOnNon200 ? (requestErrors.length > 0 ? requestErrors : [responseError]) : [];
95
+ const retryRequestErrors = plan.retry.enabled ? (requestErrors.length > 0 ? requestErrors : [responseError]) : [];
99
96
  const commonOutputs = createChatV2ProviderFailureOutputs({
100
97
  requestMessages,
101
98
  responseStatus: statusCode,
@@ -103,10 +100,10 @@ function buildProviderFailureResult(requestMessages, options, normalizedError, r
103
100
  requestStatuses: retryRequestStatuses,
104
101
  requestErrors: retryRequestErrors,
105
102
  requestBodies: options.requestBodies,
106
- outputUsage: options.outputUsage,
107
- outputReasoning: options.outputReasoning,
108
- includeFunctionCalls: options.includeFunctionCalls,
109
- retryOnNon200: options.retryOnNon200,
103
+ outputUsage: plan.output.outputUsage,
104
+ outputReasoning: plan.output.outputReasoning,
105
+ includeFunctionCalls: plan.output.includeFunctionCalls,
106
+ retryOnNon200: plan.retry.enabled,
110
107
  });
111
108
  const allMessagesOutput = commonOutputs['all-messages'];
112
109
  if (allMessagesOutput?.type !== 'chat-message[]') {
@@ -138,24 +135,14 @@ export async function runChatV2Pipeline(options) {
138
135
  : options.additionalTools == null
139
136
  ? functionTools
140
137
  : { ...functionTools, ...options.additionalTools };
141
- const shouldStreamResponse = options.emitPartialOutputs !== false;
142
- const transportMode = shouldStreamResponse ? 'stream' : 'generate';
143
- const chatResponse = await runChatV2WithRetry({
144
- model: options.model,
138
+ const plan = buildChatV2RequestPlan({
139
+ ...options,
145
140
  messages: modelMessages,
146
141
  tools,
147
- maxTokens: options.maxTokens,
148
- temperature: options.temperature,
149
- topP: options.topP,
150
- topK: options.topK,
151
- presencePenalty: options.presencePenalty,
152
- frequencyPenalty: options.frequencyPenalty,
153
- stopSequences: options.stopSequences,
154
- seed: options.seed,
155
- responseOutput: options.responseOutput,
156
- responseFormat: options.responseFormat,
157
- providerOptions: options.providerOptions,
158
- toolChoice: options.toolChoice,
142
+ });
143
+ const shouldStreamResponse = plan.transportMode === 'stream';
144
+ const chatResponse = await runChatV2WithRetry({
145
+ ...plan.request,
159
146
  abortSignal: options.context.signal,
160
147
  executeStream: options.executeStream,
161
148
  executeGenerate: options.executeGenerate,
@@ -177,13 +164,13 @@ export async function runChatV2Pipeline(options) {
177
164
  outputUsage: false,
178
165
  outputReasoning: false,
179
166
  outputRequestStatus: false,
180
- includeFunctionCalls: options.includeFunctionCalls,
181
- functionCallMode: options.functionCallMode,
167
+ includeFunctionCalls: plan.output.includeFunctionCalls,
168
+ functionCallMode: plan.output.functionCallMode,
182
169
  retryOnNon200: false,
183
170
  responseFormat: undefined,
184
171
  }));
185
172
  },
186
- }, options, transportMode).catch((caughtError) => {
173
+ }, plan.retry, options.context.signal, plan.transportMode).catch((caughtError) => {
187
174
  const retryFailure = isChatV2RetryFailure(caughtError) ? caughtError : undefined;
188
175
  const rawError = retryFailure?.error ?? caughtError;
189
176
  const normalizedError = normalizeChatV2ProviderError(rawError, {
@@ -192,7 +179,7 @@ export async function runChatV2Pipeline(options) {
192
179
  });
193
180
  const requestStatuses = retryFailure?.requestStatuses ?? [];
194
181
  const requestErrors = normalizeProviderFailureMessages(retryFailure?.requestErrors ?? [], options);
195
- const failureResult = buildProviderFailureResult(requestMessages, options, normalizedError, rawError, requestStatuses, requestErrors);
182
+ const failureResult = buildProviderFailureResult(requestMessages, options, plan, normalizedError, rawError, requestStatuses, requestErrors);
196
183
  if (failureResult) {
197
184
  return failureResult;
198
185
  }
@@ -220,13 +207,13 @@ export async function runChatV2Pipeline(options) {
220
207
  requestStatuses,
221
208
  requestErrors,
222
209
  requestBodies: options.requestBodies,
223
- outputUsage: options.outputUsage,
224
- outputReasoning: options.outputReasoning,
225
- outputRequestStatus: options.outputRequestStatus,
226
- includeFunctionCalls: options.includeFunctionCalls,
227
- functionCallMode: options.functionCallMode,
228
- retryOnNon200: options.retryOnNon200,
229
- responseFormat: options.responseFormat,
210
+ outputUsage: plan.output.outputUsage,
211
+ outputReasoning: plan.output.outputReasoning,
212
+ outputRequestStatus: plan.output.outputRequestStatus,
213
+ includeFunctionCalls: plan.output.includeFunctionCalls,
214
+ functionCallMode: plan.output.functionCallMode,
215
+ retryOnNon200: plan.retry.enabled,
216
+ responseFormat: plan.request.responseFormat,
230
217
  });
231
218
  const allMessagesOutput = commonOutputs['all-messages'];
232
219
  if (allMessagesOutput?.type !== 'chat-message[]') {
@@ -0,0 +1,98 @@
1
+ import { coerceTypeOptional } from '../../utils/coerceType.js';
2
+ import { createChatV2Model, resolveChatV2ProviderConfig, } from './providerOptions.js';
3
+ function getStringSetting(settings, key) {
4
+ const value = settings[key];
5
+ return typeof value === 'string' && value.trim() ? value : undefined;
6
+ }
7
+ function resolveConfiguredCredential(provider, context, options) {
8
+ switch (provider) {
9
+ case 'openai': {
10
+ const value = context.settings.openAiApiKey || context.settings.openAiKey || undefined;
11
+ return { value, reference: { source: value ? 'settings' : 'none' } };
12
+ }
13
+ case 'anthropic': {
14
+ const settingsValue = context.settings.anthropicApiKey || undefined;
15
+ if (settingsValue)
16
+ return { value: settingsValue, reference: { source: 'settings' } };
17
+ const pluginValue = context.getPluginConfig('anthropicApiKey') || undefined;
18
+ return { value: pluginValue, reference: { source: pluginValue ? 'plugin' : 'none' } };
19
+ }
20
+ case 'google': {
21
+ const settingsValue = context.settings.googleApiKey || undefined;
22
+ if (settingsValue)
23
+ return { value: settingsValue, reference: { source: 'settings' } };
24
+ const pluginValue = context.getPluginConfig('googleApiKey') || undefined;
25
+ return { value: pluginValue, reference: { source: pluginValue ? 'plugin' : 'none' } };
26
+ }
27
+ case 'custom': {
28
+ const programmaticName = options.customProgrammaticName?.trim();
29
+ const environmentName = options.customEnvironmentName?.trim();
30
+ const programmaticValue = programmaticName ? getStringSetting(context.settings, programmaticName) : undefined;
31
+ if (programmaticValue) {
32
+ return {
33
+ value: programmaticValue,
34
+ reference: { source: 'programmatic', name: programmaticName },
35
+ };
36
+ }
37
+ if (environmentName) {
38
+ const pluginEnvValue = context.settings.pluginEnv?.[environmentName];
39
+ if (pluginEnvValue) {
40
+ return { value: pluginEnvValue, reference: { source: 'environment', name: environmentName } };
41
+ }
42
+ const processValue = globalThis.process?.env?.[environmentName];
43
+ if (processValue) {
44
+ return { value: processValue, reference: { source: 'environment', name: environmentName } };
45
+ }
46
+ }
47
+ const value = context.settings.customAiApiKey || undefined;
48
+ if (value)
49
+ return { value, reference: { source: 'settings' } };
50
+ const missing = [
51
+ programmaticName ? `programmatic key ${programmaticName}` : undefined,
52
+ environmentName ? `env var ${environmentName}` : undefined,
53
+ ].filter(Boolean);
54
+ if (missing.length > 0) {
55
+ const hint = programmaticName
56
+ ? `pass ${programmaticName}`
57
+ : 'set Alternative programmatic key name and pass that named run option';
58
+ throw new Error(`Custom provider API key ${missing.join(' and ')} is not set. Use Input port, configure Settings > LLM, ${hint}, or configure the environment variable.`);
59
+ }
60
+ return { reference: { source: 'none' } };
61
+ }
62
+ }
63
+ }
64
+ export function resolveChatV2Credential(options) {
65
+ if (options.apiKeySource === 'input') {
66
+ const value = coerceTypeOptional(options.inputs?.['apiKey'], 'string')?.trim();
67
+ if (!value)
68
+ throw new Error('API Key input is required when API key source is Input port.');
69
+ return { value, reference: { source: 'input' } };
70
+ }
71
+ return resolveConfiguredCredential(options.provider, options.context, options);
72
+ }
73
+ export async function createResolvedChatV2Provider(options) {
74
+ const config = await resolveChatV2ProviderConfig(options.provider, options.modelId, options.context, {
75
+ baseURL: options.baseURL,
76
+ headers: options.headers,
77
+ });
78
+ const model = createChatV2Model(options.provider, options.modelId, options.context, {
79
+ ...config,
80
+ apiKey: options.credential.value,
81
+ onRequestBody: options.onRequestBody,
82
+ });
83
+ return {
84
+ profile: {
85
+ provider: options.provider,
86
+ modelId: options.modelId,
87
+ baseURL: config.baseURL,
88
+ hasCustomHeaders: Object.keys(config.headers ?? {}).length > 0,
89
+ credential: options.credential.reference,
90
+ capabilities: {
91
+ builtInTools: options.provider === 'openai' || options.provider === 'google',
92
+ structuredOutput: true,
93
+ },
94
+ },
95
+ model,
96
+ config,
97
+ };
98
+ }
@@ -0,0 +1,64 @@
1
+ import { normalizeLLMChatV2RetryCooldownMs, normalizeLLMChatV2RetryCount, } from './chatV2Retry.js';
2
+ export function buildChatV2RequestPlan(options) {
3
+ const shouldStream = options.emitPartialOutputs !== false;
4
+ return {
5
+ provider: options.provider,
6
+ modelId: options.modelId,
7
+ transportMode: shouldStream ? 'stream' : 'generate',
8
+ retry: {
9
+ enabled: options.retryOnNon200 === true,
10
+ repeatTimes: options.retryOnNon200
11
+ ? normalizeLLMChatV2RetryCount(options.retryOnNon200RepeatTimes)
12
+ : 0,
13
+ cooldownMs: normalizeLLMChatV2RetryCooldownMs(options.retryOnNon200CooldownMs),
14
+ },
15
+ request: {
16
+ model: options.model,
17
+ messages: options.messages,
18
+ maxRetries: 0,
19
+ tools: options.tools,
20
+ maxTokens: options.maxTokens,
21
+ temperature: options.temperature,
22
+ topP: options.topP,
23
+ topK: options.topK,
24
+ presencePenalty: options.presencePenalty,
25
+ frequencyPenalty: options.frequencyPenalty,
26
+ stopSequences: options.stopSequences,
27
+ seed: options.seed,
28
+ responseOutput: options.responseOutput,
29
+ responseFormat: options.responseFormat,
30
+ providerOptions: options.providerOptions,
31
+ toolChoice: options.toolChoice,
32
+ },
33
+ output: {
34
+ outputUsage: options.outputUsage,
35
+ outputReasoning: options.outputReasoning,
36
+ outputRequestStatus: options.outputRequestStatus,
37
+ includeFunctionCalls: options.includeFunctionCalls,
38
+ functionCallMode: options.functionCallMode,
39
+ },
40
+ };
41
+ }
42
+ export function summarizeChatV2RequestPlan(plan) {
43
+ return {
44
+ provider: plan.provider,
45
+ modelId: plan.modelId,
46
+ transportMode: plan.transportMode,
47
+ sdkMaxRetries: plan.request.maxRetries ?? 0,
48
+ retry: { ...plan.retry },
49
+ messageCount: plan.request.messages.length,
50
+ toolNames: Object.keys(plan.request.tools ?? {}).sort(),
51
+ responseFormat: plan.request.responseFormat,
52
+ generation: {
53
+ maxTokens: plan.request.maxTokens,
54
+ temperature: plan.request.temperature,
55
+ topP: plan.request.topP,
56
+ topK: plan.request.topK,
57
+ presencePenalty: plan.request.presencePenalty,
58
+ frequencyPenalty: plan.request.frequencyPenalty,
59
+ stopSequences: plan.request.stopSequences,
60
+ seed: plan.request.seed,
61
+ },
62
+ output: { ...plan.output },
63
+ };
64
+ }
@@ -2,6 +2,7 @@ import { createGoogleGenerativeAI } from '@ai-sdk/google';
2
2
  import { createOpenAI } from '@ai-sdk/openai';
3
3
  import { coerceTypeOptional } from '../../utils/coerceType.js';
4
4
  import { cleanHeaders, getInputOrData } from '../../utils/inputs.js';
5
+ import { resolveChatV2Credential } from './chatV2ProviderProfile.js';
5
6
  export function resolveLLMChatV2Headers(data, inputs) {
6
7
  const resolvedHeaders = data.useHeadersInput && inputs['headers'] != null
7
8
  ? coerceTypeOptional(inputs['headers'], 'object')
@@ -9,39 +10,15 @@ export function resolveLLMChatV2Headers(data, inputs) {
9
10
  const cleaned = cleanHeaders(resolvedHeaders ?? {});
10
11
  return Object.keys(cleaned).length > 0 ? cleaned : undefined;
11
12
  }
12
- function resolveConfiguredProviderApiKey(data, context) {
13
- switch (data.provider) {
14
- case 'openai':
15
- return context.settings.openAiKey || undefined;
16
- case 'anthropic':
17
- return context.getPluginConfig('anthropicApiKey') || undefined;
18
- case 'google':
19
- return context.getPluginConfig('googleApiKey') || undefined;
20
- case 'custom': {
21
- const envVarName = data.customProviderApiKeyEnvVarName?.trim();
22
- if (!envVarName) {
23
- return undefined;
24
- }
25
- const pluginEnvValue = context.settings.pluginEnv?.[envVarName];
26
- const processEnv = globalThis
27
- .process?.env;
28
- const apiKey = pluginEnvValue || processEnv?.[envVarName];
29
- if (!apiKey) {
30
- throw new Error(`Custom provider API key env var ${envVarName} is not set. Use Input port or configure the environment variable.`);
31
- }
32
- return apiKey;
33
- }
34
- }
35
- }
36
13
  export function resolveLLMChatV2ApiKey(data, inputs, context) {
37
- if (data.apiKeySource !== 'input') {
38
- return resolveConfiguredProviderApiKey(data, context);
39
- }
40
- const apiKey = coerceTypeOptional(inputs['apiKey'], 'string')?.trim();
41
- if (!apiKey) {
42
- throw new Error('API Key input is required when API key source is Input port.');
43
- }
44
- return apiKey;
14
+ return resolveChatV2Credential({
15
+ provider: data.provider,
16
+ context,
17
+ apiKeySource: data.apiKeySource === 'input' ? 'input' : 'configured',
18
+ inputs,
19
+ customProgrammaticName: data.customProviderApiKeyProgrammaticName,
20
+ customEnvironmentName: data.customProviderApiKeyEnvVarName,
21
+ }).value;
45
22
  }
46
23
  function parseExtraProviderOptionsText(rawText) {
47
24
  const raw = rawText.trim();
@@ -200,9 +177,9 @@ export function resolveLLMChatV2BuiltInTools(data, context, config, apiKey) {
200
177
  return undefined;
201
178
  }
202
179
  const provider = createOpenAI({
203
- apiKey: apiKey || context.settings.openAiKey || undefined,
180
+ apiKey: apiKey || context.settings.openAiApiKey || context.settings.openAiKey || undefined,
204
181
  organization: context.settings.openAiOrganization || undefined,
205
- baseURL: config.baseURL,
182
+ baseURL: undefined,
206
183
  headers: config.headers,
207
184
  });
208
185
  const tools = {};
@@ -221,8 +198,8 @@ export function resolveLLMChatV2BuiltInTools(data, context, config, apiKey) {
221
198
  return undefined;
222
199
  }
223
200
  const provider = createGoogleGenerativeAI({
224
- apiKey: apiKey || context.getPluginConfig('googleApiKey') || undefined,
225
- baseURL: config.baseURL,
201
+ apiKey: apiKey || context.settings.googleApiKey || context.getPluginConfig('googleApiKey') || undefined,
202
+ baseURL: undefined,
226
203
  headers: config.headers,
227
204
  });
228
205
  const tools = {};
@@ -1,6 +1,8 @@
1
1
  export * from './aiSdkBridge.js';
2
2
  export * from './chatV2FeatureCompatibility.js';
3
3
  export * from './chatV2Pipeline.js';
4
+ export * from './chatV2ProviderProfile.js';
5
+ export * from './chatV2RequestPlan.js';
4
6
  export * from './chatV2ResponseFormat.js';
5
7
  export * from './chatV2Shared.js';
6
8
  export * from './chatV2Types.js';
@@ -7,6 +7,7 @@ export function createLLMChatV2NodeData() {
7
7
  }),
8
8
  provider: 'openai',
9
9
  apiKeySource: 'environment',
10
+ customProviderApiKeyProgrammaticName: '',
10
11
  customProviderApiKeyEnvVarName: 'CUSTOM_PROVIDER_API_KEY',
11
12
  customProviderBaseURL: '',
12
13
  useCustomProviderBaseURLInput: false,
@@ -26,6 +26,26 @@ async function getResolvedModelOptions(data, context) {
26
26
  ? modelOptions
27
27
  : [{ value: data.model, label: `${data.model} (Current)` }, ...modelOptions];
28
28
  }
29
+ function getApiKeySourceHelperMessage(data) {
30
+ if (data.apiKeySource === 'input') {
31
+ return 'Uses the API Key input port instead of a configured provider key.';
32
+ }
33
+ switch (data.provider) {
34
+ case 'openai':
35
+ return 'Configured key uses Settings > LLM > OpenAI API Key in the Rivet editor, with OPENAI_API_KEY as a desktop/Node fallback. Programmatic runs can pass openAiApiKey or set OPENAI_API_KEY.';
36
+ case 'anthropic':
37
+ return 'Configured key uses Settings > LLM > Anthropic API Key in the Rivet editor, with ANTHROPIC_API_KEY as a desktop/Node fallback. Programmatic runs can pass anthropicApiKey or set ANTHROPIC_API_KEY.';
38
+ case 'google':
39
+ return 'Configured key uses Settings > LLM > Google API Key in the Rivet editor, with GOOGLE_GENERATIVE_AI_API_KEY as a desktop/Node fallback. Programmatic runs can pass googleApiKey or set GOOGLE_GENERATIVE_AI_API_KEY.';
40
+ case 'custom': {
41
+ const programmaticName = data.customProviderApiKeyProgrammaticName?.trim();
42
+ const envVarName = data.customProviderApiKeyEnvVarName?.trim() || 'CUSTOM_PROVIDER_API_KEY';
43
+ return programmaticName
44
+ ? `Configured key checks ${programmaticName}, then ${envVarName} env var, then Settings > LLM > Custom provider API key.`
45
+ : `Configured key checks ${envVarName} env var, then Settings > LLM > Custom provider API key. Programmatic runs can pass the shared customAiApiKey.`;
46
+ }
47
+ }
48
+ }
29
49
  function getModelEditors(modelOptions) {
30
50
  return group('Model', [
31
51
  {
@@ -61,14 +81,22 @@ function getModelEditors(modelOptions) {
61
81
  { value: 'environment', label: 'Configured key' },
62
82
  { value: 'input', label: 'Input port' },
63
83
  ],
64
- helperMessage: 'Whether to use the configured provider API key or get one through an input port.',
84
+ helperMessage: getApiKeySourceHelperMessage,
85
+ },
86
+ {
87
+ type: 'string',
88
+ label: 'Alternative programmatic key name',
89
+ dataKey: 'customProviderApiKeyProgrammaticName',
90
+ placeholder: 'cerebrasApiKey',
91
+ helperMessage: 'If set, programmatic runs read this named run option instead of the shared customAiApiKey.',
92
+ hideIf: (data) => data.provider !== 'custom' || data.apiKeySource === 'input',
65
93
  },
66
94
  {
67
95
  type: 'string',
68
- label: 'API key env var name',
96
+ label: 'Alternative API key env var',
69
97
  dataKey: 'customProviderApiKeyEnvVarName',
70
98
  placeholder: 'CUSTOM_PROVIDER_API_KEY',
71
- helperMessage: 'Only used for Custom provider when API key source is Configured key.',
99
+ helperMessage: 'If set, this env var is used instead of CUSTOM_PROVIDER_API_KEY.',
72
100
  hideIf: (data) => data.provider !== 'custom' || data.apiKeySource === 'input',
73
101
  },
74
102
  ], true);
@@ -395,14 +423,6 @@ function getOutputEditors() {
395
423
  }
396
424
  function getProviderAdvancedEditors() {
397
425
  return group('Provider Advanced', [
398
- {
399
- type: 'string',
400
- label: 'Base URL',
401
- dataKey: 'baseURL',
402
- useInputToggleDataKey: 'useBaseURLInput',
403
- placeholder: 'Optional provider base URL override',
404
- hideIf: (data) => data.provider === 'custom',
405
- },
406
426
  {
407
427
  type: 'keyValuePair',
408
428
  label: 'Headers',
@@ -2,9 +2,10 @@ import { coerceTypeOptional } from '../../utils/coerceType.js';
2
2
  import { getInputOrData } from '../../utils/inputs.js';
3
3
  import { createChatV2ResponseOutput, mergeCustomProviderResponseFormatOptions, resolveChatV2ResponseFormatParameters, } from './chatV2ResponseFormat.js';
4
4
  import { hasLLMChatV2ToolResponseFormatConflict, LLM_CHAT_V2_TOOL_RESPONSE_FORMAT_CONFLICT_COPY, } from './chatV2FeatureCompatibility.js';
5
- import { createChatV2Model, parseChatV2Provider, resolveChatV2ProviderConfig } from './providerOptions.js';
5
+ import { parseChatV2Provider } from './providerOptions.js';
6
+ import { createResolvedChatV2Provider, resolveChatV2Credential } from './chatV2ProviderProfile.js';
6
7
  import { buildLLMChatV2EditorCacheKey, cloneLLMChatV2EditorCacheOutputs, resolveLLMChatV2EditorCache, } from './chatV2EditorCache.js';
7
- import { resolveLLMChatV2ApiKey, resolveLLMChatV2BuiltInTools, resolveLLMChatV2GenerationParameters, resolveLLMChatV2Headers, resolveLLMChatV2RuntimeProviderOptions, resolveLLMChatV2ToolChoice, } from './chatV2RuntimeOptions.js';
8
+ import { resolveLLMChatV2BuiltInTools, resolveLLMChatV2GenerationParameters, resolveLLMChatV2Headers, resolveLLMChatV2RuntimeProviderOptions, resolveLLMChatV2ToolChoice, } from './chatV2RuntimeOptions.js';
8
9
  import { hasLLMChatV2BuiltInToolsEnabled, } from './llmChatV2NodeData.js';
9
10
  export { buildLLMChatV2EditorCacheKey, cloneLLMChatV2EditorCacheOutputs };
10
11
  export { resolveLLMChatV2RuntimeProviderOptions } from './chatV2RuntimeOptions.js';
@@ -12,7 +13,7 @@ function resolveLLMChatV2BaseURL(data, inputs) {
12
13
  return data.provider === 'custom'
13
14
  ? getInputOrData(data, inputs, 'customProviderBaseURL', 'string', 'useCustomProviderBaseURLInput')?.trim() ||
14
15
  undefined
15
- : getInputOrData(data, inputs, 'baseURL', 'string', 'useBaseURLInput')?.trim() || undefined;
16
+ : undefined;
16
17
  }
17
18
  export async function resolveLLMChatV2RuntimeConfig(params) {
18
19
  const { data, nodeId, inputs, context } = params;
@@ -23,17 +24,27 @@ export async function resolveLLMChatV2RuntimeConfig(params) {
23
24
  const modelId = getInputOrData(data, inputs, 'model', 'string');
24
25
  const baseURL = resolveLLMChatV2BaseURL(data, inputs);
25
26
  const nodeHeaders = resolveLLMChatV2Headers(data, inputs);
26
- const apiKey = resolveLLMChatV2ApiKey(data, inputs, context);
27
+ const credential = resolveChatV2Credential({
28
+ provider,
29
+ context,
30
+ apiKeySource: data.apiKeySource === 'input' ? 'input' : 'configured',
31
+ inputs,
32
+ customProgrammaticName: data.customProviderApiKeyProgrammaticName,
33
+ customEnvironmentName: data.customProviderApiKeyEnvVarName,
34
+ });
35
+ const apiKey = credential.value;
27
36
  const requestBodies = data.outputRequestStatus ? [] : undefined;
28
- const providerConfig = await resolveChatV2ProviderConfig(provider, modelId, context, {
37
+ const resolvedProvider = await createResolvedChatV2Provider({
38
+ provider,
39
+ modelId,
40
+ context,
29
41
  baseURL,
30
42
  headers: nodeHeaders,
31
- });
32
- const model = createChatV2Model(provider, modelId, context, {
33
- ...providerConfig,
34
- apiKey,
43
+ credential,
35
44
  onRequestBody: requestBodies == null ? undefined : (body) => requestBodies.push(body),
36
45
  });
46
+ const providerConfig = resolvedProvider.config;
47
+ const model = resolvedProvider.model;
37
48
  const prompt = inputs['prompt'];
38
49
  const systemPrompt = inputs['systemPrompt'];
39
50
  const functions = data.useToolCalling && inputs['functions'] != null
@@ -86,6 +97,7 @@ export async function resolveLLMChatV2RuntimeConfig(params) {
86
97
  toolChoice,
87
98
  });
88
99
  return {
100
+ providerProfile: resolvedProvider.profile,
89
101
  runOptions,
90
102
  functions,
91
103
  cacheKey,