openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
37 lines (36 loc) • 1.44 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-1VuiLaaR.mjs";
import { a as resolveProviderOnboardAuthFlags } from "./provider-auth-choices-DMYmVIgL.mjs";
//#region src/commands/onboard-non-interactive/local/auth-choice-inference.ts
/**
* Infers a non-interactive auth choice from explicit CLI flags.
*
* This keeps setup deterministic when users provide API-key flags without also
* passing `--auth`, including plugin-defined provider auth flags.
*/
function hasStringValue(value) {
return typeof value === "string" ? Boolean(normalizeOptionalString(value)) : Boolean(value);
}
/** Infers auth choice from plugin and custom provider API-key flags. */
function inferAuthChoiceFromFlags(opts, params) {
const matches = resolveProviderOnboardAuthFlags({
config: params?.config,
workspaceDir: params?.workspaceDir,
env: params?.env,
includeUntrustedWorkspacePlugins: false
}).filter(({ optionKey }) => hasStringValue(opts[optionKey])).map((flag) => ({
optionKey: flag.optionKey,
authChoice: flag.authChoice,
label: flag.cliFlag
}));
if (hasStringValue(opts.customBaseUrl) || hasStringValue(opts.customModelId) || hasStringValue(opts.customApiKey)) matches.push({
optionKey: "customBaseUrl",
authChoice: "custom-api-key",
label: "--custom-base-url/--custom-model-id/--custom-api-key"
});
return {
choice: matches[0]?.authChoice,
matches
};
}
//#endregion
export { inferAuthChoiceFromFlags as t };