@valerypopoff/rivet2-core 2.1.2 → 2.1.4

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 (112) hide show
  1. package/dist/cjs/bundle.cjs +3373 -1208
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/cjs/webAppRuntime.cjs +625 -0
  4. package/dist/cjs/webAppRuntime.cjs.map +7 -0
  5. package/dist/esm/api/createProcessor.js +3 -0
  6. package/dist/esm/api/processSettings.js +5 -0
  7. package/dist/esm/api/streaming.js +6 -0
  8. package/dist/esm/exports.js +7 -0
  9. package/dist/esm/integrations/mcp/MCPBase.js +92 -34
  10. package/dist/esm/model/GraphProcessor.js +35 -49
  11. package/dist/esm/model/GraphProgress.js +15 -0
  12. package/dist/esm/model/GraphRunLifecycle.js +67 -0
  13. package/dist/esm/model/MarkdownSanitizationPolicy.js +38 -0
  14. package/dist/esm/model/Nodes.js +3 -0
  15. package/dist/esm/model/ProcessContextBuilder.js +2 -1
  16. package/dist/esm/model/RecordingPlayer.js +10 -0
  17. package/dist/esm/model/SubprocessorBridge.js +1 -0
  18. package/dist/esm/model/UiGraph.js +181 -1
  19. package/dist/esm/model/UiGraphActionProtocol.js +122 -0
  20. package/dist/esm/model/UiGraphBindings.js +530 -0
  21. package/dist/esm/model/UiGraphBrowserRuntime.js +40 -0
  22. package/dist/esm/model/UiGraphNormalization.js +298 -0
  23. package/dist/esm/model/UiGraphRendererStyles.js +456 -6
  24. package/dist/esm/model/UiGraphRuntimeModel.js +371 -0
  25. package/dist/esm/model/UiGraphWebAppStatus.js +19 -0
  26. package/dist/esm/model/chat-v2/aiSdkBridge.js +1 -1
  27. package/dist/esm/model/chat-v2/chatV2EditorCache.js +2 -2
  28. package/dist/esm/model/chat-v2/chatV2Pipeline.js +35 -48
  29. package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +98 -0
  30. package/dist/esm/model/chat-v2/chatV2RequestPlan.js +64 -0
  31. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +11 -39
  32. package/dist/esm/model/chat-v2/index.js +2 -0
  33. package/dist/esm/model/chat-v2/llmChatV2NodeData.js +1 -0
  34. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +31 -11
  35. package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +21 -9
  36. package/dist/esm/model/chat-v2/providerOptions.js +9 -35
  37. package/dist/esm/model/nodes/ArrayNode.js +2 -13
  38. package/dist/esm/model/nodes/AssembleMessageNode.js +2 -13
  39. package/dist/esm/model/nodes/AssemblePromptNode.js +2 -13
  40. package/dist/esm/model/nodes/CoalesceNode.js +2 -15
  41. package/dist/esm/model/nodes/DelayNode.js +3 -14
  42. package/dist/esm/model/nodes/DidRunNode.js +2 -13
  43. package/dist/esm/model/nodes/JoinNode.js +2 -13
  44. package/dist/esm/model/nodes/LLMChatV2Node.js +3 -3
  45. package/dist/esm/model/nodes/LoopControllerNode.js +3 -14
  46. package/dist/esm/model/nodes/MCPDiscoveryNode.js +19 -90
  47. package/dist/esm/model/nodes/MCPGetPromptNode.js +11 -97
  48. package/dist/esm/model/nodes/MCPToolCallNode.js +11 -97
  49. package/dist/esm/model/nodes/PassthroughNode.js +3 -14
  50. package/dist/esm/model/nodes/RaceInputsNode.js +2 -13
  51. package/dist/esm/model/nodes/ReportProgressNode.js +57 -0
  52. package/dist/esm/model/nodes/variadicPortIndex.js +32 -0
  53. package/dist/esm/plugins/anthropic/anthropic.js +1 -1
  54. package/dist/esm/plugins/autoevals/AutoEvalsNode.js +3 -1
  55. package/dist/esm/plugins/gentrace/gentraceSdk.js +8 -0
  56. package/dist/esm/plugins/gentrace/plugin.js +5 -4
  57. package/dist/esm/plugins/google/google.js +9 -7
  58. package/dist/esm/recording/ExecutionRecorder.js +5 -0
  59. package/dist/esm/utils/fetchEventSource.js +16 -17
  60. package/dist/esm/utils/pQueueCompat.js +1 -1
  61. package/dist/esm/utils/serialization/serialization.js +4 -0
  62. package/dist/esm/utils/serialization/serializationUtils.js +16 -0
  63. package/dist/esm/utils/serialization/serialization_v4.js +5 -4
  64. package/dist/esm/webAppRuntime.js +4 -0
  65. package/dist/types/api/createProcessor.d.ts +1 -1
  66. package/dist/types/api/processSettings.d.ts +3 -4
  67. package/dist/types/api/streaming.d.ts +6 -0
  68. package/dist/types/exports.d.ts +7 -0
  69. package/dist/types/integrations/mcp/MCPBase.d.ts +26 -3
  70. package/dist/types/model/ExecutorProtocol.d.ts +7 -0
  71. package/dist/types/model/GraphProcessor.d.ts +7 -0
  72. package/dist/types/model/GraphProgress.d.ts +6 -0
  73. package/dist/types/model/GraphRunLifecycle.d.ts +22 -0
  74. package/dist/types/model/MarkdownSanitizationPolicy.d.ts +9 -0
  75. package/dist/types/model/Nodes.d.ts +3 -2
  76. package/dist/types/model/ProcessContext.d.ts +5 -2
  77. package/dist/types/model/ProcessContextBuilder.d.ts +2 -1
  78. package/dist/types/model/Settings.d.ts +1 -0
  79. package/dist/types/model/UiGraph.d.ts +50 -5
  80. package/dist/types/model/UiGraphActionProtocol.d.ts +69 -0
  81. package/dist/types/model/UiGraphBindings.d.ts +45 -0
  82. package/dist/types/model/UiGraphBrowserRuntime.d.ts +4 -0
  83. package/dist/types/model/UiGraphNormalization.d.ts +24 -0
  84. package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
  85. package/dist/types/model/UiGraphRuntimeModel.d.ts +124 -0
  86. package/dist/types/model/UiGraphWebAppStatus.d.ts +5 -0
  87. package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +46 -0
  88. package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +42 -0
  89. package/dist/types/model/chat-v2/chatV2Types.d.ts +1 -0
  90. package/dist/types/model/chat-v2/index.d.ts +2 -0
  91. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +1 -0
  92. package/dist/types/model/chat-v2/llmChatV2NodeRuntime.d.ts +2 -0
  93. package/dist/types/model/chat-v2/providerOptions.d.ts +2 -2
  94. package/dist/types/model/nodes/ArrayNode.d.ts +0 -1
  95. package/dist/types/model/nodes/AssembleMessageNode.d.ts +0 -1
  96. package/dist/types/model/nodes/AssemblePromptNode.d.ts +0 -1
  97. package/dist/types/model/nodes/DelayNode.d.ts +0 -1
  98. package/dist/types/model/nodes/DidRunNode.d.ts +0 -1
  99. package/dist/types/model/nodes/JoinNode.d.ts +0 -1
  100. package/dist/types/model/nodes/LoopControllerNode.d.ts +0 -1
  101. package/dist/types/model/nodes/PassthroughNode.d.ts +0 -1
  102. package/dist/types/model/nodes/RaceInputsNode.d.ts +0 -1
  103. package/dist/types/model/nodes/ReportProgressNode.d.ts +23 -0
  104. package/dist/types/model/nodes/variadicPortIndex.d.ts +4 -0
  105. package/dist/types/plugins/gentrace/gentraceSdk.d.ts +5 -0
  106. package/dist/types/plugins/gentrace/plugin.d.ts +1 -1
  107. package/dist/types/recording/RecordedEvents.d.ts +5 -0
  108. package/dist/types/utils/pQueueCompat.d.ts +1 -1
  109. package/dist/types/webAppRuntime.d.ts +9 -0
  110. package/package.json +15 -9
  111. package/dist/esm/plugins/anthropic/fetchEventSource.js +0 -107
  112. package/dist/types/plugins/anthropic/fetchEventSource.d.ts +0 -11
@@ -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,44 +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.openAiApiKey || context.settings.openAiKey || undefined;
16
- case 'anthropic':
17
- return context.settings.anthropicApiKey || context.getPluginConfig('anthropicApiKey') || undefined;
18
- case 'google':
19
- return context.settings.googleApiKey || context.getPluginConfig('googleApiKey') || undefined;
20
- case 'custom': {
21
- const envVarName = data.customProviderApiKeyEnvVarName?.trim();
22
- if (envVarName) {
23
- const pluginEnvValue = context.settings.pluginEnv?.[envVarName];
24
- const processEnv = globalThis
25
- .process?.env;
26
- const apiKey = pluginEnvValue || processEnv?.[envVarName];
27
- if (apiKey) {
28
- return apiKey;
29
- }
30
- }
31
- if (context.settings.customAiApiKey) {
32
- return context.settings.customAiApiKey;
33
- }
34
- if (envVarName) {
35
- throw new Error(`Custom provider API key env var ${envVarName} is not set. Use Input port, configure Settings > LLM, or configure the environment variable.`);
36
- }
37
- return undefined;
38
- }
39
- }
40
- }
41
13
  export function resolveLLMChatV2ApiKey(data, inputs, context) {
42
- if (data.apiKeySource !== 'input') {
43
- return resolveConfiguredProviderApiKey(data, context);
44
- }
45
- const apiKey = coerceTypeOptional(inputs['apiKey'], 'string')?.trim();
46
- if (!apiKey) {
47
- throw new Error('API Key input is required when API key source is Input port.');
48
- }
49
- 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;
50
22
  }
51
23
  function parseExtraProviderOptionsText(rawText) {
52
24
  const raw = rawText.trim();
@@ -207,7 +179,7 @@ export function resolveLLMChatV2BuiltInTools(data, context, config, apiKey) {
207
179
  const provider = createOpenAI({
208
180
  apiKey: apiKey || context.settings.openAiApiKey || context.settings.openAiKey || undefined,
209
181
  organization: context.settings.openAiOrganization || undefined,
210
- baseURL: config.baseURL,
182
+ baseURL: undefined,
211
183
  headers: config.headers,
212
184
  });
213
185
  const tools = {};
@@ -227,7 +199,7 @@ export function resolveLLMChatV2BuiltInTools(data, context, config, apiKey) {
227
199
  }
228
200
  const provider = createGoogleGenerativeAI({
229
201
  apiKey: apiKey || context.settings.googleApiKey || context.getPluginConfig('googleApiKey') || undefined,
230
- baseURL: config.baseURL,
202
+ baseURL: undefined,
231
203
  headers: config.headers,
232
204
  });
233
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,
@@ -2,7 +2,6 @@ import { createAnthropic } from '@ai-sdk/anthropic';
2
2
  import { createGoogleGenerativeAI } from '@ai-sdk/google';
3
3
  import { createOpenAI } from '@ai-sdk/openai';
4
4
  import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
5
- import { DEFAULT_CHAT_ENDPOINT } from '../../utils/defaults.js';
6
5
  import { cleanHeaders } from '../../utils/inputs.js';
7
6
  import { getChatV2ModelRegistry } from './modelRegistry.js';
8
7
  export const chatV2ProviderOptions = [
@@ -100,17 +99,6 @@ function openAIEndpointToBaseURL(endpoint) {
100
99
  export function openAICompatibleEndpointToBaseURL(endpoint) {
101
100
  return openAIEndpointToBaseURL(endpoint);
102
101
  }
103
- function openAIBaseURLToEndpoint(baseURL) {
104
- const normalizedBaseURL = removeTrailingSlash(baseURL);
105
- try {
106
- const url = new URL(normalizedBaseURL);
107
- url.pathname = `${url.pathname.replace(/\/$/, '')}/chat/completions`;
108
- return url.toString();
109
- }
110
- catch {
111
- return `${normalizedBaseURL}/chat/completions`;
112
- }
113
- }
114
102
  function parseBodyText(text) {
115
103
  try {
116
104
  return JSON.parse(text);
@@ -166,39 +154,25 @@ function createRequestBodyCapturingFetch(onRequestBody) {
166
154
  function maybeCreateRequestBodyCapturingFetch(options) {
167
155
  return options.onRequestBody == null ? undefined : createRequestBodyCapturingFetch(options.onRequestBody);
168
156
  }
169
- export async function resolveChatV2ProviderConfig(provider, modelId, context, options = {}) {
157
+ export async function resolveChatV2ProviderConfig(provider, _modelId, context, options = {}) {
170
158
  const headers = cleanHeaders({
171
159
  ...context.settings.chatNodeHeaders,
172
160
  ...options.headers,
173
161
  });
174
162
  switch (provider) {
175
- case 'openai': {
176
- const configuredBaseURL = options.baseURL
177
- ? options.baseURL
178
- : openAIEndpointToBaseURL(context.settings.openAiEndpoint || DEFAULT_CHAT_ENDPOINT);
179
- if (context.getChatNodeEndpoint == null) {
180
- return {
181
- baseURL: configuredBaseURL,
182
- headers: Object.keys(headers).length > 0 ? headers : undefined,
183
- };
184
- }
185
- const resolved = await context.getChatNodeEndpoint(openAIBaseURLToEndpoint(configuredBaseURL), modelId);
163
+ case 'openai':
186
164
  return {
187
- baseURL: openAIEndpointToBaseURL(resolved.endpoint),
188
- headers: cleanHeaders({
189
- ...headers,
190
- ...resolved.headers,
191
- }),
165
+ baseURL: undefined,
166
+ headers: Object.keys(headers).length > 0 ? headers : undefined,
192
167
  };
193
- }
194
168
  case 'anthropic':
195
169
  return {
196
- baseURL: options.baseURL || context.getPluginConfig('anthropicApiEndpoint') || undefined,
170
+ baseURL: undefined,
197
171
  headers: Object.keys(headers).length > 0 ? headers : undefined,
198
172
  };
199
173
  case 'google':
200
174
  return {
201
- baseURL: options.baseURL || undefined,
175
+ baseURL: undefined,
202
176
  headers: Object.keys(headers).length > 0 ? headers : undefined,
203
177
  };
204
178
  case 'custom': {
@@ -219,7 +193,7 @@ export function createChatV2Model(provider, modelId, context, options = {}) {
219
193
  const providerInstance = createOpenAI({
220
194
  apiKey: options.apiKey || context.settings.openAiApiKey || context.settings.openAiKey || undefined,
221
195
  organization: context.settings.openAiOrganization || undefined,
222
- baseURL: options.baseURL || undefined,
196
+ baseURL: undefined,
223
197
  headers: options.headers,
224
198
  fetch: maybeCreateRequestBodyCapturingFetch(options),
225
199
  });
@@ -228,7 +202,7 @@ export function createChatV2Model(provider, modelId, context, options = {}) {
228
202
  case 'anthropic': {
229
203
  const providerInstance = createAnthropic({
230
204
  apiKey: options.apiKey || context.settings.anthropicApiKey || context.getPluginConfig('anthropicApiKey') || undefined,
231
- baseURL: options.baseURL || context.getPluginConfig('anthropicApiEndpoint') || undefined,
205
+ baseURL: undefined,
232
206
  headers: options.headers,
233
207
  fetch: maybeCreateRequestBodyCapturingFetch(options),
234
208
  });
@@ -237,7 +211,7 @@ export function createChatV2Model(provider, modelId, context, options = {}) {
237
211
  case 'google': {
238
212
  const providerInstance = createGoogleGenerativeAI({
239
213
  apiKey: options.apiKey || context.settings.googleApiKey || context.getPluginConfig('googleApiKey') || undefined,
240
- baseURL: options.baseURL || undefined,
214
+ baseURL: undefined,
241
215
  headers: options.headers,
242
216
  fetch: maybeCreateRequestBodyCapturingFetch(options),
243
217
  });
@@ -7,6 +7,7 @@ import { flattenDeep } from 'lodash-es';
7
7
  import { dedent } from 'ts-dedent';
8
8
  import {} from '../EditorDefinition.js';
9
9
  import { nodeDefinition } from '../NodeDefinition.js';
10
+ import { getNextVariadicPortIndex } from './variadicPortIndex.js';
10
11
  export class ArrayNodeImpl extends NodeImpl {
11
12
  static create() {
12
13
  const chartNode = {
@@ -27,7 +28,7 @@ export class ArrayNodeImpl extends NodeImpl {
27
28
  }
28
29
  getInputDefinitions(connections) {
29
30
  const inputs = [];
30
- const inputCount = this.#getInputPortCount(connections);
31
+ const inputCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'input', 'legacy');
31
32
  for (let i = 1; i <= inputCount; i++) {
32
33
  inputs.push({
33
34
  dataType: 'any',
@@ -70,18 +71,6 @@ export class ArrayNodeImpl extends NodeImpl {
70
71
  },
71
72
  ];
72
73
  }
73
- #getInputPortCount(connections) {
74
- const inputNodeId = this.chartNode.id;
75
- const inputConnections = connections.filter((connection) => connection.inputNodeId === inputNodeId && connection.inputId.startsWith('input'));
76
- let maxInputNumber = 0;
77
- for (const connection of inputConnections) {
78
- const inputNumber = parseInt(connection.inputId.replace('input', ''));
79
- if (inputNumber > maxInputNumber) {
80
- maxInputNumber = inputNumber;
81
- }
82
- }
83
- return maxInputNumber + 1;
84
- }
85
74
  static getUIData() {
86
75
  return {
87
76
  infoBoxBody: dedent `
@@ -7,6 +7,7 @@ import { orderBy } from 'lodash-es';
7
7
  import { coerceTypeOptional, dedent, getInputOrData } from '../../utils/index.js';
8
8
  import { nodeDefinition } from '../NodeDefinition.js';
9
9
  import { match } from 'ts-pattern';
10
+ import { getNextVariadicPortIndex } from './variadicPortIndex.js';
10
11
  const messageTypeToTitle = {
11
12
  assistant: 'Assistant',
12
13
  function: 'Function Tool Call',
@@ -35,7 +36,7 @@ export class AssembleMessageNodeImpl extends NodeImpl {
35
36
  }
36
37
  getInputDefinitions(connections) {
37
38
  const inputs = [];
38
- const messageCount = this.#getInputPortCount(connections);
39
+ const messageCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'part', 'legacy');
39
40
  if (this.data.useTypeInput) {
40
41
  inputs.push({
41
42
  dataType: 'string',
@@ -96,18 +97,6 @@ export class AssembleMessageNodeImpl extends NodeImpl {
96
97
  },
97
98
  ];
98
99
  }
99
- #getInputPortCount(connections) {
100
- const inputNodeId = this.chartNode.id;
101
- const messageConnections = connections.filter((connection) => connection.inputNodeId === inputNodeId && connection.inputId.startsWith('part'));
102
- let maxMessageNumber = 0;
103
- for (const connection of messageConnections) {
104
- const messageNumber = parseInt(connection.inputId.replace('part', ''));
105
- if (messageNumber > maxMessageNumber) {
106
- maxMessageNumber = messageNumber;
107
- }
108
- }
109
- return maxMessageNumber + 1;
110
- }
111
100
  static getUIData() {
112
101
  return {
113
102
  infoBoxBody: dedent `
@@ -8,6 +8,7 @@ import { orderBy } from 'lodash-es';
8
8
  import { dedent } from 'ts-dedent';
9
9
  import { nodeDefinition } from '../NodeDefinition.js';
10
10
  import { getInputOrData } from '../../utils/inputs.js';
11
+ import { getNextVariadicPortIndex } from './variadicPortIndex.js';
11
12
  export class AssemblePromptNodeImpl extends NodeImpl {
12
13
  static create() {
13
14
  const chartNode = {
@@ -25,7 +26,7 @@ export class AssemblePromptNodeImpl extends NodeImpl {
25
26
  }
26
27
  getInputDefinitions(connections) {
27
28
  const inputs = [];
28
- const messageCount = this.#getMessagePortCount(connections);
29
+ const messageCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'message', 'legacy');
29
30
  if (this.data.useIsLastMessageCacheBreakpointInput) {
30
31
  inputs.push({
31
32
  dataType: 'boolean',
@@ -63,18 +64,6 @@ export class AssemblePromptNodeImpl extends NodeImpl {
63
64
  }
64
65
  return outputs;
65
66
  }
66
- #getMessagePortCount(connections) {
67
- const inputNodeId = this.chartNode.id;
68
- const messageConnections = connections.filter((connection) => connection.inputNodeId === inputNodeId && connection.inputId.startsWith('message'));
69
- let maxMessageNumber = 0;
70
- for (const connection of messageConnections) {
71
- const messageNumber = parseInt(connection.inputId.replace('message', ''));
72
- if (messageNumber > maxMessageNumber) {
73
- maxMessageNumber = messageNumber;
74
- }
75
- }
76
- return maxMessageNumber + 1;
77
- }
78
67
  static getUIData() {
79
68
  return {
80
69
  infoBoxBody: dedent `
@@ -6,6 +6,7 @@ import {} from '../GraphProcessor.js';
6
6
  import { dedent } from 'ts-dedent';
7
7
  import { nodeDefinition } from '../NodeDefinition.js';
8
8
  import {} from '../EditorDefinition.js';
9
+ import { getNextVariadicPortIndex } from './variadicPortIndex.js';
9
10
  const INPUT_PORT_ID_PATTERN = /^input(\d+)$/;
10
11
  const IGNORE_NULL_LABEL = "Ignore 'null'";
11
12
  const IGNORE_UNDEFINED_LABEL = "Ignore 'undefined'";
@@ -29,7 +30,7 @@ export class CoalesceNodeImpl extends NodeImpl {
29
30
  };
30
31
  getInputDefinitions(connections) {
31
32
  const inputs = [];
32
- const inputCount = this.#getInputPortCount(connections);
33
+ const inputCount = getNextVariadicPortIndex(connections, this.chartNode.id, 'input', 'strict-positive');
33
34
  inputs.push({
34
35
  dataType: 'boolean',
35
36
  id: 'conditional',
@@ -89,20 +90,6 @@ export class CoalesceNodeImpl extends NodeImpl {
89
90
  group: ['Logic'],
90
91
  };
91
92
  }
92
- #getInputPortCount(connections) {
93
- const inputNodeId = this.chartNode.id;
94
- let maxInputNumber = 0;
95
- for (const connection of connections) {
96
- if (connection.inputNodeId !== inputNodeId) {
97
- continue;
98
- }
99
- const inputNumber = this.#getInputPortNumber(connection.inputId);
100
- if (inputNumber && inputNumber > maxInputNumber) {
101
- maxInputNumber = inputNumber;
102
- }
103
- }
104
- return maxInputNumber + 1;
105
- }
106
93
  async process(inputData) {
107
94
  const conditional = inputData['conditional'];
108
95
  // This lets the coalesce actually be control-flow-excluded itself, because otherwise