mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 14:41:12 +00:00
onboard: support custom provider in non-interactive flow (#14223)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 5b98d6514e
Co-authored-by: ENCHIGO <38551565+ENCHIGO@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
@@ -46,6 +46,12 @@ import {
|
||||
setXiaomiApiKey,
|
||||
setZaiApiKey,
|
||||
} from "../../onboard-auth.js";
|
||||
import {
|
||||
applyCustomApiConfig,
|
||||
CustomApiError,
|
||||
parseNonInteractiveCustomApiFlags,
|
||||
resolveCustomProviderId,
|
||||
} from "../../onboard-custom.js";
|
||||
import { applyOpenAIConfig } from "../../openai-model-default.js";
|
||||
import { resolveNonInteractiveApiKey } from "../api-keys.js";
|
||||
|
||||
@@ -594,6 +600,65 @@ export async function applyNonInteractiveAuthChoice(params: {
|
||||
return applyTogetherConfig(nextConfig);
|
||||
}
|
||||
|
||||
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 resolvedProviderId = resolveCustomProviderId({
|
||||
config: nextConfig,
|
||||
baseUrl: customAuth.baseUrl,
|
||||
providerId: customAuth.providerId,
|
||||
});
|
||||
const resolvedCustomApiKey = await resolveNonInteractiveApiKey({
|
||||
provider: resolvedProviderId.providerId,
|
||||
cfg: baseConfig,
|
||||
flagValue: customAuth.apiKey,
|
||||
flagName: "--custom-api-key",
|
||||
envVar: "CUSTOM_API_KEY",
|
||||
envVarName: "CUSTOM_API_KEY",
|
||||
runtime,
|
||||
required: false,
|
||||
});
|
||||
const result = applyCustomApiConfig({
|
||||
config: nextConfig,
|
||||
baseUrl: customAuth.baseUrl,
|
||||
modelId: customAuth.modelId,
|
||||
compatibility: customAuth.compatibility,
|
||||
apiKey: resolvedCustomApiKey?.key,
|
||||
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" ||
|
||||
|
||||
Reference in New Issue
Block a user