openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
603 lines (602 loc) • 23.3 kB
JavaScript
import "./redact-BDinS1q9.js";
import "./errors-BxyFnvP3.js";
import "./unhandled-rejections-CDJ8dOVP.js";
import "./logger-kwZIqwuw.js";
import "./paths-ViKUYWUK.js";
import "./tmp-openclaw-dir-idKIOMmb.js";
import "./theme-CdOoMzRk.js";
import "./globals-DBUMOBZ8.js";
import "./subsystem-DISldKSB.js";
import "./ansi-BEJF8NKS.js";
import "./boolean-C3GkJetE.js";
import "./env-Dnra1IpT.js";
import "./warning-filter-CBhOcgHd.js";
import "./utils-CS0Ikux6.js";
import "./links-8xRhWBQL.js";
import "./paths-C4Oy7wjk.js";
import { m as resolveApiKeyForProfile, n as resolveAuthProfileOrder } from "./auth-profiles-DRuJBw5y.js";
import { a as resolveAgentDir, m as resolveDefaultAgentId, p as resolveAgentWorkspaceDir } from "./agent-scope-bjWqU22i.js";
import "./boundary-path-Dm0QJ7-y.js";
import "./boundary-file-read-DcZxlWD8.js";
import "./logger-BmpSCz93.js";
import "./exec-B5_AYfQG.js";
import { g as resolveDefaultAgentWorkspaceDir } from "./workspace-D4K6QX9X.js";
import "./model-selection-BnFtDmP7.js";
import "./io-y3Az_Onx.js";
import "./shell-env-BOu7XeT_.js";
import "./safe-text-yavot2qw.js";
import "./version-CD3oP1-d.js";
import "./env-substitution-O6uabUmO.js";
import "./includes-Bj3eLUWH.js";
import "./zod-schema.providers-core-COy5nBQ0.js";
import "./legacy-web-search-BB-ZHEhz.js";
import "./registry-C5UkPpaO.js";
import "./config-state-Br0ucqMb.js";
import "./min-host-version-RMBWtIAR.js";
import "./manifest-registry-B5JNQdOM.js";
import "./runtime-guard-PhQ6PwQa.js";
import "./avatar-policy-B5nOfso_.js";
import "./ip-Ce8EDTBZ.js";
import "./zod-schema.agent-runtime-Dtg4Jy6G.js";
import { l as resolveDefaultSecretProviderAlias } from "./ref-contract-D3ri29cK.js";
import "./zod-schema.core-BuVz8Rk7.js";
import "./config-D4zN4BRl.js";
import "./file-lock-DEiVq2ow.js";
import "./audit-fs-DTQIjp2r.js";
import "./resolve-B7S4PlnO.js";
import { t as normalizeOptionalSecretInput } from "./normalize-secret-input-BsX1agd_.js";
import { c as ensureAuthProfileStore } from "./profiles-COPO-hHI.js";
import "./tailscale-CxY-91GZ.js";
import "./tailnet-DHiKSG7V.js";
import "./net-JAg9zL0G.js";
import "./auth-Buq0Niri.js";
import "./credentials-D8pfRimu.js";
import "./message-channel-BliByQBl.js";
import "./store-C5UK26Ce.js";
import "./runtime-Iz8uZ7EU.js";
import "./plugins-B09-vgme.js";
import "./sessions-D9ZgHCHb.js";
import "./paths-rhN9LKM_.js";
import "./session-write-lock-va3qZE6f.js";
import "./method-scopes-BiEi0X2g.js";
import "./call-CQbSO4Fr.js";
import "./prompt-style-C4CV4Y_p.js";
import "./ports-lsof-BLEgL_Gn.js";
import "./restart-stale-pids-BsPvlGJd.js";
import "./ports-FldL_Lhq.js";
import "./logging-CznuqaMu.js";
import "./commands-C6oAw_H-.js";
import "./issue-format-BtLIwOtN.js";
import "./identity-Dp-UIak4.js";
import "./heartbeat-Bdfr_onc.js";
import "./pi-embedded-CbCYZxIb.js";
import "./internal-hooks-CIUghoK4.js";
import "./multimodal-B8yEZcl5.js";
import "./memory-search-B_aq08y5.js";
import "./provider-catalog-rVN7ZbR5.js";
import "./secret-input-DXoOLNgb.js";
import "./bindings-CFudGB9Z.js";
import "./resolve-route-DwFWP4JW.js";
import "./routing-zOQ0wwtV.js";
import "./identity-file-DVLib087.js";
import "./outbound-runtime-m-y0nd6F.js";
import "./provider-env-vars-CpUJqT5v.js";
import { a as normalizeSecretInputModeInput, c as resolveEnvApiKey } from "./provider-auth-input-Bus9W_qh.js";
import "./provider-model-minimax-DSmX4BNO.js";
import "./provider-models-BKjzpTsb.js";
import "./anthropic-vertex-provider-B2x4YywE.js";
import "./provider-catalog-BTgF8VyO.js";
import "./provider-catalog-D0IlX18O.js";
import "./provider-catalog-BTmUX0Mp.js";
import "./provider-catalog-sph_Rl63.js";
import "./provider-catalog-C7tUyBwV.js";
import "./provider-catalog-C8dPZpHW.js";
import "./provider-catalog-BJNff1VI.js";
import "./provider-catalog-IAdymoqT.js";
import "./provider-catalog-Bjc7evzh.js";
import "./models-config.providers.discovery-CjkO08q6.js";
import "./text-runtime-DVXt5xhi.js";
import "./tool-catalog-BjSY4C4F.js";
import "./docker-Bhjg8g2t.js";
import "./sandbox-DTlKNieF.js";
import "./common-zReYuoMM.js";
import "./image-ops-By4YfyWa.js";
import "./thinking-CJoSRIGR.js";
import "./path-alias-guards-CwRM04O1.js";
import "./sandbox-paths-Cn8i8Jxm.js";
import "./channel-actions-fV93bLjV.js";
import "./mime-CsUtzcn2.js";
import "./ssrf-0bPJMoZR.js";
import "./fetch-guard-CYl1q2XH.js";
import { n as enablePluginInConfig } from "./provider-web-search-COZNygbd.js";
import "./manager-Bw8JrihM.js";
import "./config-schema-CPzP2Ds6.js";
import "./channel-plugin-common-ClptUZHU.js";
import "./status-helpers-Cflmo90d.js";
import "./conversation-runtime-nmWgJSXS.js";
import "./runtime-whatsapp-boundary-XjdkYMz_.js";
import "./pairing-store-BGKLrjo6.js";
import "./json-store--JDX3zNL.js";
import "./secret-file-Bif7RlZ-.js";
import "./channel-config-schema-CgpS17zB.js";
import "./setup-binary-C2MYZTCc.js";
import "./archive-pOxyr9r4.js";
import "./fs-safe-DZyOgpPN.js";
import "./signal-cli-install-fVOL9FvX.js";
import "./setup-wizard-proxy-DoOpOF8S.js";
import "./setup-BI3ohdrT.js";
import "./dm-policy-shared-DtcQProI.js";
import "./runtime-env-DQOYrXVl.js";
import "./temp-path-B91lt0LF.js";
import "./diagnostic-CDTtMQBT.js";
import "./logging-CCTKg_fh.js";
import "./config-runtime-BYNizC50.js";
import "./level-overrides-DzIzQ3ZY.js";
import "./exec-approvals-BF_Qfdq8.js";
import "./webhook-ingress-D-H5frou.js";
import "./system-events-BU_NYynX.js";
import "./ssrf-policy-DYINyIKC.js";
import "./hook-runtime-BUYmDbaA.js";
import "./templating-BDXRiJUh.js";
import "./channel-reply-pipeline-BxH4-AP2.js";
import "./reply-history-n7nOPLta.js";
import "./commands-registry.data-BFXJWoqi.js";
import "./commands-registry-Bh9pJ817.js";
import "./frontmatter-CP5371Rm.js";
import "./env-overrides-BNSo89u5.js";
import "./skills-M0AZJeXx.js";
import "./skills-remote-BHxDA4Jw.js";
import "./workspace-dirs-DqDLiRvZ.js";
import "./pairing-token-DAszGmwD.js";
import "./skill-commands-D73dGR_l.js";
import "./config-CLRQPUSt.js";
import "./routes-XT2JfvT-.js";
import "./ssh-tunnel-LM52qY6N.js";
import "./server-middleware-BP59C6FL.js";
import "./provider-auth-ref-CQEp9sp3.js";
import { t as applyAuthProfileConfig } from "./provider-auth-helpers-Do3RFvdi.js";
import { a as createLazyRuntimeSurface } from "./lazy-runtime-CPDBPNrj.js";
import "./provider-api-key-auth-BEeRW3dq.js";
import "./pairing-labels-D27Y4Vv6.js";
import "./directory-runtime-D9Y42mW-.js";
import "./read-only-account-inspect-CJPRBFj7.js";
import "./src-BoNU6eQs.js";
import "./web-media-PKy3RbRG.js";
import "./media-understanding-BDOSvuM9.js";
import "./web-media-CiSbdGPs.js";
import "./state-paths-Dvb3Mfl3.js";
import "./llm-task-Br6Ixjlh.js";
import "./pi-model-discovery-DO3tFksS.js";
import "./exec-inline-eval-CpmxWJsW.js";
import "./target-registry-9OUOvlxj.js";
import "./external-content-DZI9vlJn.js";
import "./brave-onFD06fq.js";
import "./duckduckgo-CZuAOfiQ.js";
import "./exa-5bwgY04k.js";
import "./security-runtime-xlw0Fxx2.js";
import "./provider-usage-ClxTGn5c.js";
import "./provider-models-Bjv0V4OP.js";
import "./media-understanding-provider-DllGbg-v.js";
import "./media-understanding-provider-BDq4rFL-.js";
import { i as applyCloudflareAiGatewayConfig } from "./provider-onboard-CSnPvkMM.js";
import "./onboard-BU8aRvq7.js";
import "./perplexity-web-search-provider-CI38RNUU.js";
import "./perplexity-CMZbsreI.js";
import "./model-definitions-CLagLj0g.js";
import "./onboard-0P7GBI2D.js";
import "./provider-catalog-CKHo9CRM.js";
import "./provider-models-Dmjtw6kn.js";
import "./stream-C-KGzzT0.js";
import "./web-search-CO1hvu_l.js";
import "./stagger-CFqdtCYL.js";
import "./command-secret-targets-DLs8jC2H.js";
import "./delivery-queue-DHURMSqX.js";
import "./channel-summary-Ctrv7moa.js";
import "./follow-redirects-CVAaqIk4.js";
import "./tool-policy-match-DQWWRSN4.js";
import "./runtime-CAdCdG-M.js";
import "./channel-status-BfM90KqH.js";
import "./discord-core-DLbIyXWy.js";
import "./cli-runtime-Cx1v7N7v.js";
import "./config-presence-DA3j8Nmi.js";
import "./query-expansion-BOJBTXsp.js";
import "./search-manager-DNBHwaee.js";
import "./acp-runtime-BHZj-SLU.js";
import "./telegram-core-DD8gCuaX.js";
import "./audit-BI48Fi3j.js";
import "./gateway-runtime-Dn2qAGY7.js";
import "./connection-auth-Nl2a3tDb.js";
import "./mcp-config-CDIWSqVk.js";
import "./provider-auth-choices-CD6TBMmn.js";
import "./auth-choice.apply-helpers-D1SvSUlM.js";
import { a as setCloudflareAiGatewayConfig, i as applyLitellmConfig, o as setLitellmApiKey, r as normalizeApiKeyTokenProviderAuthChoice, t as resolvePreferredProviderForAuthChoice } from "./provider-auth-choice-preference-ButFS2JN.js";
import "./model-picker-BVlPCbxo.js";
import { a as resolveCustomProviderId, n as applyCustomApiConfig, r as parseNonInteractiveCustomApiFlags, t as CustomApiError } from "./onboard-custom-DuIn9R5Y.js";
//#region src/commands/onboard-non-interactive/api-keys.ts
function parseEnvVarNameFromSourceLabel(source) {
if (!source) return;
return /^(?:shell env: |env: )([A-Z][A-Z0-9_]*)$/.exec(source.trim())?.[1];
}
async function resolveApiKeyFromProfiles(params) {
const store = ensureAuthProfileStore(params.agentDir);
const order = resolveAuthProfileOrder({
cfg: params.cfg,
store,
provider: params.provider
});
for (const profileId of order) {
if (store.profiles[profileId]?.type !== "api_key") continue;
const resolved = await resolveApiKeyForProfile({
cfg: params.cfg,
store,
profileId,
agentDir: params.agentDir
});
if (resolved?.apiKey) return resolved.apiKey;
}
return null;
}
async function resolveNonInteractiveApiKey(params) {
const flagKey = normalizeOptionalSecretInput(params.flagValue);
const envResolved = resolveEnvApiKey(params.provider);
const explicitEnvVar = params.envVarName?.trim();
const explicitEnvKey = explicitEnvVar ? normalizeOptionalSecretInput(process.env[explicitEnvVar]) : void 0;
const resolvedEnvKey = envResolved?.apiKey ?? explicitEnvKey;
const resolvedEnvVarName = parseEnvVarNameFromSourceLabel(envResolved?.source) ?? explicitEnvVar;
if (params.secretInputMode === "ref") {
if (!resolvedEnvKey && flagKey) {
params.runtime.error([`${params.flagName} cannot be used with --secret-input-mode ref unless ${params.envVar} is set in env.`, `Set ${params.envVar} in env and omit ${params.flagName}, or use --secret-input-mode plaintext.`].join("\n"));
params.runtime.exit(1);
return null;
}
if (resolvedEnvKey) {
if (!resolvedEnvVarName) {
params.runtime.error([`--secret-input-mode ref requires an explicit environment variable for provider "${params.provider}".`, `Set ${params.envVar} in env and retry, or use --secret-input-mode plaintext.`].join("\n"));
params.runtime.exit(1);
return null;
}
return {
key: resolvedEnvKey,
source: "env",
envVarName: resolvedEnvVarName
};
}
}
if (flagKey) return {
key: flagKey,
source: "flag"
};
if (resolvedEnvKey) return {
key: resolvedEnvKey,
source: "env",
envVarName: resolvedEnvVarName
};
if (params.allowProfile ?? true) {
const profileKey = await resolveApiKeyFromProfiles({
provider: params.provider,
cfg: params.cfg,
agentDir: params.agentDir
});
if (profileKey) return {
key: profileKey,
source: "profile"
};
}
if (params.required === false) return null;
const profileHint = params.allowProfile === false ? "" : `, or existing ${params.provider} API-key profile`;
params.runtime.error(`Missing ${params.flagName} (or ${params.envVar} in env${profileHint}).`);
params.runtime.exit(1);
return null;
}
//#endregion
//#region src/commands/onboard-non-interactive/local/auth-choice.api-key-providers.ts
async function applySimpleNonInteractiveApiKeyChoice(params) {
if (params.authChoice !== "litellm-api-key") return;
const resolved = await params.resolveApiKey({
provider: "litellm",
cfg: params.baseConfig,
flagValue: params.opts.litellmApiKey,
flagName: "--litellm-api-key",
envVar: "LITELLM_API_KEY",
runtime: params.runtime
});
if (!resolved) return null;
if (!await params.maybeSetResolvedApiKey(resolved, (value) => setLitellmApiKey(value, void 0, params.apiKeyStorageOptions))) return null;
return applyLitellmConfig(applyAuthProfileConfig(params.nextConfig, {
profileId: "litellm:default",
provider: "litellm",
mode: "api_key"
}));
}
//#endregion
//#region src/commands/onboard-non-interactive/local/auth-choice.plugin-providers.ts
const PROVIDER_PLUGIN_CHOICE_PREFIX = "provider-plugin:";
async function loadPluginProviderRuntime() {
return import("./auth-choice.plugin-providers.runtime-DI6WcwuK.js");
}
const loadAuthChoicePluginProvidersRuntime = createLazyRuntimeSurface(loadPluginProviderRuntime, ({ authChoicePluginProvidersRuntime }) => authChoicePluginProvidersRuntime);
function buildIsolatedProviderResolutionConfig(cfg, providerId) {
if (!providerId) return cfg;
const allow = new Set(cfg.plugins?.allow ?? []);
allow.add(providerId);
return {
...cfg,
plugins: {
...cfg.plugins,
allow: Array.from(allow),
entries: {
...cfg.plugins?.entries,
[providerId]: {
...cfg.plugins?.entries?.[providerId],
enabled: true
}
}
}
};
}
async function applyNonInteractivePluginProviderChoice(params) {
const agentId = resolveDefaultAgentId(params.nextConfig);
const agentDir = resolveAgentDir(params.nextConfig, agentId);
const workspaceDir = resolveAgentWorkspaceDir(params.nextConfig, agentId) ?? resolveDefaultAgentWorkspaceDir();
const preferredProviderId = (params.authChoice.startsWith(PROVIDER_PLUGIN_CHOICE_PREFIX) ? params.authChoice.slice(16).split(":", 1)[0]?.trim() : void 0) || await resolvePreferredProviderForAuthChoice({
choice: params.authChoice,
config: params.nextConfig,
workspaceDir
});
const resolutionConfig = buildIsolatedProviderResolutionConfig(params.nextConfig, preferredProviderId);
const { resolveOwningPluginIdsForProvider, resolveProviderPluginChoice, resolvePluginProviders } = await loadAuthChoicePluginProvidersRuntime();
const providerChoice = resolveProviderPluginChoice({
providers: resolvePluginProviders({
config: resolutionConfig,
workspaceDir,
onlyPluginIds: preferredProviderId ? resolveOwningPluginIdsForProvider({
provider: preferredProviderId,
config: resolutionConfig,
workspaceDir
}) : void 0,
bundledProviderAllowlistCompat: true,
bundledProviderVitestCompat: true
}),
choice: params.authChoice
});
if (!providerChoice) return;
const enableResult = enablePluginInConfig(params.nextConfig, providerChoice.provider.pluginId ?? providerChoice.provider.id);
if (!enableResult.enabled) {
params.runtime.error(`${providerChoice.provider.label} plugin is disabled (${enableResult.reason ?? "blocked"}).`);
params.runtime.exit(1);
return null;
}
const method = providerChoice.method;
if (!method.runNonInteractive) {
params.runtime.error([`Auth choice "${params.authChoice}" requires interactive mode.`, `The ${providerChoice.provider.label} provider plugin does not implement non-interactive setup.`].join("\n"));
params.runtime.exit(1);
return null;
}
return method.runNonInteractive({
authChoice: params.authChoice,
config: enableResult.config,
baseConfig: params.baseConfig,
opts: params.opts,
runtime: params.runtime,
agentDir,
workspaceDir,
resolveApiKey: params.resolveApiKey,
toApiKeyCredential: params.toApiKeyCredential
});
}
//#endregion
//#region src/commands/onboard-non-interactive/local/auth-choice.ts
async function applyNonInteractiveAuthChoice(params) {
const { opts, runtime, baseConfig } = params;
const authChoice = normalizeApiKeyTokenProviderAuthChoice({
authChoice: params.authChoice,
tokenProvider: opts.tokenProvider,
config: params.nextConfig,
env: process.env
});
let nextConfig = params.nextConfig;
const requestedSecretInputMode = normalizeSecretInputModeInput(opts.secretInputMode);
if (opts.secretInputMode && !requestedSecretInputMode) {
runtime.error("Invalid --secret-input-mode. Use \"plaintext\" or \"ref\".");
runtime.exit(1);
return null;
}
const apiKeyStorageOptions = requestedSecretInputMode ? { secretInputMode: requestedSecretInputMode } : void 0;
const toStoredSecretInput = (resolved) => {
if (requestedSecretInputMode !== "ref") return resolved.key;
if (resolved.source !== "env") return resolved.key;
if (!resolved.envVarName) {
runtime.error([`Unable to determine which environment variable to store as a ref for provider "${authChoice}".`, "Set an explicit provider env var and retry, or use --secret-input-mode plaintext."].join("\n"));
runtime.exit(1);
return null;
}
return {
source: "env",
provider: resolveDefaultSecretProviderAlias(baseConfig, "env", { preferFirstProviderForSource: true }),
id: resolved.envVarName
};
};
const resolveApiKey = (input) => resolveNonInteractiveApiKey({
...input,
secretInputMode: requestedSecretInputMode
});
const toApiKeyCredential = (params) => {
if (requestedSecretInputMode === "ref" && params.resolved.source === "env") {
if (!params.resolved.envVarName) {
runtime.error([`--secret-input-mode ref requires an explicit environment variable for provider "${params.provider}".`, "Set the provider API key env var and retry, or use --secret-input-mode plaintext."].join("\n"));
runtime.exit(1);
return null;
}
return {
type: "api_key",
provider: params.provider,
keyRef: {
source: "env",
provider: resolveDefaultSecretProviderAlias(baseConfig, "env", { preferFirstProviderForSource: true }),
id: params.resolved.envVarName
},
...params.email ? { email: params.email } : {},
...params.metadata ? { metadata: params.metadata } : {}
};
}
return {
type: "api_key",
provider: params.provider,
key: params.resolved.key,
...params.email ? { email: params.email } : {},
...params.metadata ? { metadata: params.metadata } : {}
};
};
const maybeSetResolvedApiKey = async (resolved, setter) => {
if (resolved.source === "profile") return true;
const stored = toStoredSecretInput(resolved);
if (!stored) return false;
await setter(stored);
return true;
};
if (authChoice === "claude-cli" || authChoice === "codex-cli") {
runtime.error([`Auth choice "${authChoice}" is deprecated.`, "Use \"--auth-choice token\" (Anthropic setup-token) or \"--auth-choice openai-codex\"."].join("\n"));
runtime.exit(1);
return null;
}
if (authChoice === "setup-token") {
runtime.error(["Auth choice \"setup-token\" requires interactive mode.", "Use \"--auth-choice token\" with --token and --token-provider anthropic."].join("\n"));
runtime.exit(1);
return null;
}
const pluginProviderChoice = await applyNonInteractivePluginProviderChoice({
nextConfig,
authChoice,
opts,
runtime,
baseConfig,
resolveApiKey: (input) => resolveApiKey({
...input,
cfg: baseConfig,
runtime
}),
toApiKeyCredential
});
if (pluginProviderChoice !== void 0) return pluginProviderChoice;
const simpleApiKeyChoice = await applySimpleNonInteractiveApiKeyChoice({
authChoice,
nextConfig,
baseConfig,
opts,
runtime,
apiKeyStorageOptions,
resolveApiKey,
maybeSetResolvedApiKey
});
if (simpleApiKeyChoice !== void 0) return simpleApiKeyChoice;
if (authChoice === "cloudflare-ai-gateway-api-key") {
const accountId = opts.cloudflareAiGatewayAccountId?.trim() ?? "";
const gatewayId = opts.cloudflareAiGatewayGatewayId?.trim() ?? "";
if (!accountId || !gatewayId) {
runtime.error(["Auth choice \"cloudflare-ai-gateway-api-key\" requires Account ID and Gateway ID.", "Use --cloudflare-ai-gateway-account-id and --cloudflare-ai-gateway-gateway-id."].join("\n"));
runtime.exit(1);
return null;
}
const resolved = await resolveApiKey({
provider: "cloudflare-ai-gateway",
cfg: baseConfig,
flagValue: opts.cloudflareAiGatewayApiKey,
flagName: "--cloudflare-ai-gateway-api-key",
envVar: "CLOUDFLARE_AI_GATEWAY_API_KEY",
runtime
});
if (!resolved) return null;
if (resolved.source !== "profile") {
const stored = toStoredSecretInput(resolved);
if (!stored) return null;
await setCloudflareAiGatewayConfig(accountId, gatewayId, stored, void 0, apiKeyStorageOptions);
}
nextConfig = applyAuthProfileConfig(nextConfig, {
profileId: "cloudflare-ai-gateway:default",
provider: "cloudflare-ai-gateway",
mode: "api_key"
});
return applyCloudflareAiGatewayConfig(nextConfig, {
accountId,
gatewayId
});
}
const REMOVED_MINIMAX_CHOICES = {
minimax: "minimax-global-api",
"minimax-api": "minimax-global-api",
"minimax-cloud": "minimax-global-api",
"minimax-api-lightning": "minimax-global-api",
"minimax-api-key-cn": "minimax-cn-api"
};
if (Object.prototype.hasOwnProperty.call(REMOVED_MINIMAX_CHOICES, authChoice)) {
const replacement = REMOVED_MINIMAX_CHOICES[authChoice];
runtime.error(`"${authChoice}" is no longer supported. Use --auth-choice ${replacement} instead.`);
runtime.exit(1);
return null;
}
if (authChoice === "custom-api-key") try {
const customAuth = parseNonInteractiveCustomApiFlags({
baseUrl: opts.customBaseUrl,
modelId: opts.customModelId,
compatibility: opts.customCompatibility,
apiKey: opts.customApiKey,
providerId: opts.customProviderId
});
const resolvedCustomApiKey = await resolveApiKey({
provider: resolveCustomProviderId({
config: nextConfig,
baseUrl: customAuth.baseUrl,
providerId: customAuth.providerId
}).providerId,
cfg: baseConfig,
flagValue: customAuth.apiKey,
flagName: "--custom-api-key",
envVar: "CUSTOM_API_KEY",
envVarName: "CUSTOM_API_KEY",
runtime,
required: false
});
let customApiKeyInput;
if (resolvedCustomApiKey) if (requestedSecretInputMode === "ref") {
const stored = toStoredSecretInput(resolvedCustomApiKey);
if (!stored) return null;
customApiKeyInput = stored;
} else customApiKeyInput = resolvedCustomApiKey.key;
const result = applyCustomApiConfig({
config: nextConfig,
baseUrl: customAuth.baseUrl,
modelId: customAuth.modelId,
compatibility: customAuth.compatibility,
apiKey: customApiKeyInput,
providerId: customAuth.providerId
});
if (result.providerIdRenamedFrom && result.providerId) runtime.log(`Custom provider ID "${result.providerIdRenamedFrom}" already exists for a different base URL. Using "${result.providerId}".`);
return result.config;
} catch (err) {
if (err instanceof CustomApiError) {
switch (err.code) {
case "missing_required":
case "invalid_compatibility":
runtime.error(err.message);
break;
default:
runtime.error(`Invalid custom provider config: ${err.message}`);
break;
}
runtime.exit(1);
return null;
}
const reason = err instanceof Error ? err.message : String(err);
runtime.error(`Invalid custom provider config: ${reason}`);
runtime.exit(1);
return null;
}
if (authChoice === "oauth" || authChoice === "chutes" || authChoice === "qwen-portal" || authChoice === "minimax-global-oauth" || authChoice === "minimax-cn-oauth") {
runtime.error("OAuth requires interactive mode.");
runtime.exit(1);
return null;
}
return nextConfig;
}
//#endregion
export { applyNonInteractiveAuthChoice };