@valerypopoff/rivet2-core 2.1.1 → 2.1.2
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.
- package/dist/cjs/bundle.cjs +42 -20
- package/dist/cjs/bundle.cjs.map +2 -2
- package/dist/esm/api/processSettings.js +6 -1
- package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +19 -14
- package/dist/esm/model/chat-v2/providerOptions.js +3 -3
- package/dist/esm/utils/getPluginConfig.js +15 -3
- package/dist/types/api/processSettings.d.ts +1 -1
- package/dist/types/model/Settings.d.ts +4 -0
- package/package.json +1 -1
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { DEFAULT_CHAT_NODE_TIMEOUT } from '../utils/defaults.js';
|
|
2
2
|
export function resolveProcessSettings(settings = {}, fallbacks = {}) {
|
|
3
|
+
const openAiApiKey = settings.openAiApiKey || settings.openAiKey || fallbacks.openAiApiKey || fallbacks.openAiKey || '';
|
|
3
4
|
return {
|
|
4
|
-
|
|
5
|
+
openAiApiKey,
|
|
6
|
+
openAiKey: openAiApiKey,
|
|
7
|
+
anthropicApiKey: settings.anthropicApiKey || fallbacks.anthropicApiKey || '',
|
|
8
|
+
googleApiKey: settings.googleApiKey || fallbacks.googleApiKey || '',
|
|
9
|
+
customAiApiKey: settings.customAiApiKey || fallbacks.customAiApiKey || '',
|
|
5
10
|
openAiOrganization: settings.openAiOrganization ?? fallbacks.openAiOrganization ?? '',
|
|
6
11
|
openAiEndpoint: settings.openAiEndpoint ?? fallbacks.openAiEndpoint ?? '',
|
|
7
12
|
pluginEnv: settings.pluginEnv ?? fallbacks.pluginEnv ?? {},
|
|
@@ -12,24 +12,29 @@ export function resolveLLMChatV2Headers(data, inputs) {
|
|
|
12
12
|
function resolveConfiguredProviderApiKey(data, context) {
|
|
13
13
|
switch (data.provider) {
|
|
14
14
|
case 'openai':
|
|
15
|
-
return context.settings.openAiKey || undefined;
|
|
15
|
+
return context.settings.openAiApiKey || context.settings.openAiKey || undefined;
|
|
16
16
|
case 'anthropic':
|
|
17
|
-
return context.getPluginConfig('anthropicApiKey') || undefined;
|
|
17
|
+
return context.settings.anthropicApiKey || context.getPluginConfig('anthropicApiKey') || undefined;
|
|
18
18
|
case 'google':
|
|
19
|
-
return context.getPluginConfig('googleApiKey') || undefined;
|
|
19
|
+
return context.settings.googleApiKey || context.getPluginConfig('googleApiKey') || undefined;
|
|
20
20
|
case 'custom': {
|
|
21
21
|
const envVarName = data.customProviderApiKeyEnvVarName?.trim();
|
|
22
|
-
if (
|
|
23
|
-
|
|
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
|
+
}
|
|
24
30
|
}
|
|
25
|
-
|
|
26
|
-
|
|
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
|
+
if (context.settings.customAiApiKey) {
|
|
32
|
+
return context.settings.customAiApiKey;
|
|
31
33
|
}
|
|
32
|
-
|
|
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;
|
|
33
38
|
}
|
|
34
39
|
}
|
|
35
40
|
}
|
|
@@ -200,7 +205,7 @@ export function resolveLLMChatV2BuiltInTools(data, context, config, apiKey) {
|
|
|
200
205
|
return undefined;
|
|
201
206
|
}
|
|
202
207
|
const provider = createOpenAI({
|
|
203
|
-
apiKey: apiKey || context.settings.openAiKey || undefined,
|
|
208
|
+
apiKey: apiKey || context.settings.openAiApiKey || context.settings.openAiKey || undefined,
|
|
204
209
|
organization: context.settings.openAiOrganization || undefined,
|
|
205
210
|
baseURL: config.baseURL,
|
|
206
211
|
headers: config.headers,
|
|
@@ -221,7 +226,7 @@ export function resolveLLMChatV2BuiltInTools(data, context, config, apiKey) {
|
|
|
221
226
|
return undefined;
|
|
222
227
|
}
|
|
223
228
|
const provider = createGoogleGenerativeAI({
|
|
224
|
-
apiKey: apiKey || context.getPluginConfig('googleApiKey') || undefined,
|
|
229
|
+
apiKey: apiKey || context.settings.googleApiKey || context.getPluginConfig('googleApiKey') || undefined,
|
|
225
230
|
baseURL: config.baseURL,
|
|
226
231
|
headers: config.headers,
|
|
227
232
|
});
|
|
@@ -217,7 +217,7 @@ export function createChatV2Model(provider, modelId, context, options = {}) {
|
|
|
217
217
|
switch (provider) {
|
|
218
218
|
case 'openai': {
|
|
219
219
|
const providerInstance = createOpenAI({
|
|
220
|
-
apiKey: options.apiKey || context.settings.openAiKey || undefined,
|
|
220
|
+
apiKey: options.apiKey || context.settings.openAiApiKey || context.settings.openAiKey || undefined,
|
|
221
221
|
organization: context.settings.openAiOrganization || undefined,
|
|
222
222
|
baseURL: options.baseURL || undefined,
|
|
223
223
|
headers: options.headers,
|
|
@@ -227,7 +227,7 @@ export function createChatV2Model(provider, modelId, context, options = {}) {
|
|
|
227
227
|
}
|
|
228
228
|
case 'anthropic': {
|
|
229
229
|
const providerInstance = createAnthropic({
|
|
230
|
-
apiKey: options.apiKey || context.getPluginConfig('anthropicApiKey') || undefined,
|
|
230
|
+
apiKey: options.apiKey || context.settings.anthropicApiKey || context.getPluginConfig('anthropicApiKey') || undefined,
|
|
231
231
|
baseURL: options.baseURL || context.getPluginConfig('anthropicApiEndpoint') || undefined,
|
|
232
232
|
headers: options.headers,
|
|
233
233
|
fetch: maybeCreateRequestBodyCapturingFetch(options),
|
|
@@ -236,7 +236,7 @@ export function createChatV2Model(provider, modelId, context, options = {}) {
|
|
|
236
236
|
}
|
|
237
237
|
case 'google': {
|
|
238
238
|
const providerInstance = createGoogleGenerativeAI({
|
|
239
|
-
apiKey: options.apiKey || context.getPluginConfig('googleApiKey') || undefined,
|
|
239
|
+
apiKey: options.apiKey || context.settings.googleApiKey || context.getPluginConfig('googleApiKey') || undefined,
|
|
240
240
|
baseURL: options.baseURL || undefined,
|
|
241
241
|
headers: options.headers,
|
|
242
242
|
fetch: maybeCreateRequestBodyCapturingFetch(options),
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
function getSharedLlmPluginConfig(plugin, settings, name) {
|
|
2
|
+
if (plugin.id === 'anthropic' && name === 'anthropicApiKey') {
|
|
3
|
+
return settings.anthropicApiKey;
|
|
4
|
+
}
|
|
5
|
+
if (plugin.id === 'google' && name === 'googleApiKey') {
|
|
6
|
+
return settings.googleApiKey;
|
|
7
|
+
}
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
1
10
|
export function getPluginConfig(plugin, settings, name) {
|
|
2
11
|
if (!plugin) {
|
|
3
12
|
return undefined;
|
|
@@ -9,10 +18,13 @@ export function getPluginConfig(plugin, settings, name) {
|
|
|
9
18
|
const pluginSettings = settings.pluginSettings?.[plugin.id];
|
|
10
19
|
if (pluginSettings) {
|
|
11
20
|
const value = pluginSettings[name];
|
|
12
|
-
if (
|
|
13
|
-
return
|
|
21
|
+
if (value && typeof value === 'string') {
|
|
22
|
+
return value;
|
|
14
23
|
}
|
|
15
|
-
|
|
24
|
+
}
|
|
25
|
+
const sharedLlmValue = getSharedLlmPluginConfig(plugin, settings, name);
|
|
26
|
+
if (sharedLlmValue) {
|
|
27
|
+
return sharedLlmValue;
|
|
16
28
|
}
|
|
17
29
|
const envFallback = configSpec.pullEnvironmentVariable;
|
|
18
30
|
const envFallbackName = envFallback === true ? name : envFallback;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Settings } from '../model/Settings.js';
|
|
2
|
-
type ProcessSettingsFallbacks = Pick<Settings, 'openAiKey' | 'openAiOrganization' | 'openAiEndpoint' | 'pluginEnv'>;
|
|
2
|
+
type ProcessSettingsFallbacks = Pick<Settings, 'openAiApiKey' | 'openAiKey' | 'anthropicApiKey' | 'googleApiKey' | 'customAiApiKey' | 'openAiOrganization' | 'openAiEndpoint' | 'pluginEnv'>;
|
|
3
3
|
export declare function resolveProcessSettings(settings?: Settings, fallbacks?: Partial<ProcessSettingsFallbacks>): Required<Settings>;
|
|
4
4
|
export {};
|
|
@@ -10,7 +10,11 @@ export interface Settings<PluginSettings = Record<string, Record<string, unknown
|
|
|
10
10
|
pluginEnv?: {
|
|
11
11
|
[key: string]: string | undefined;
|
|
12
12
|
};
|
|
13
|
+
openAiApiKey?: string;
|
|
13
14
|
openAiKey?: string;
|
|
15
|
+
anthropicApiKey?: string;
|
|
16
|
+
googleApiKey?: string;
|
|
17
|
+
customAiApiKey?: string;
|
|
14
18
|
openAiOrganization?: string;
|
|
15
19
|
openAiEndpoint?: string;
|
|
16
20
|
/** Timeout in milliseconds before retrying a chat node call. */
|