mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-17 20:21:13 +00:00
refactor: remove redundant model auth conversions
This commit is contained in:
@@ -192,7 +192,7 @@ async function pickProviderAuthMethod(params: {
|
||||
hint: method.hint,
|
||||
})),
|
||||
})
|
||||
.then((id) => params.provider.auth.find((method) => method.id === String(id)) ?? null);
|
||||
.then((id) => params.provider.auth.find((method) => method.id === id) ?? null);
|
||||
}
|
||||
|
||||
async function pickProviderTokenMethod(params: {
|
||||
@@ -224,7 +224,7 @@ async function pickProviderTokenMethod(params: {
|
||||
hint: method.hint,
|
||||
})),
|
||||
})
|
||||
.then((id) => tokenMethods.find((method) => method.id === String(id)) ?? null);
|
||||
.then((id) => tokenMethods.find((method) => method.id === id) ?? null);
|
||||
}
|
||||
|
||||
async function persistProviderAuthResult(params: {
|
||||
@@ -399,9 +399,7 @@ export async function modelsAuthPasteTokenCommand(
|
||||
});
|
||||
const token =
|
||||
provider === "anthropic"
|
||||
? String(tokenInput ?? "")
|
||||
.replaceAll(/\s+/g, "")
|
||||
.trim()
|
||||
? tokenInput.replaceAll(/\s+/g, "").trim()
|
||||
: (normalizeOptionalString(tokenInput) ?? "");
|
||||
|
||||
const expires = normalizeStringifiedOptionalString(opts.expiresIn)
|
||||
@@ -452,12 +450,10 @@ export async function modelsAuthAddCommand(_opts: Record<string, never>, runtime
|
||||
const providerId =
|
||||
provider === "custom"
|
||||
? normalizeProviderId(
|
||||
String(
|
||||
await text({
|
||||
message: "Provider id",
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
),
|
||||
await text({
|
||||
message: "Provider id",
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
)
|
||||
: provider;
|
||||
|
||||
@@ -483,7 +479,7 @@ export async function modelsAuthAddCommand(_opts: Record<string, never>, runtime
|
||||
const prompter = createClackPrompter();
|
||||
const method = tokenMethods.find((candidate) => candidate.id === methodId);
|
||||
if (!method) {
|
||||
throw new Error(`Unknown token auth method "${String(methodId)}".`);
|
||||
throw new Error(`Unknown token auth method "${methodId}".`);
|
||||
}
|
||||
await runProviderAuthMethod({
|
||||
config,
|
||||
@@ -499,12 +495,12 @@ export async function modelsAuthAddCommand(_opts: Record<string, never>, runtime
|
||||
}
|
||||
|
||||
const profileIdDefault = resolveDefaultTokenProfileId(providerId);
|
||||
const profileId = String(
|
||||
const profileId = (
|
||||
await text({
|
||||
message: "Profile id",
|
||||
initialValue: profileIdDefault,
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
})
|
||||
).trim();
|
||||
|
||||
const wantsExpiry = await confirm({
|
||||
@@ -512,19 +508,19 @@ export async function modelsAuthAddCommand(_opts: Record<string, never>, runtime
|
||||
initialValue: false,
|
||||
});
|
||||
const expiresIn = wantsExpiry
|
||||
? String(
|
||||
? (
|
||||
await text({
|
||||
message: "Expires in (duration)",
|
||||
initialValue: "365d",
|
||||
validate: (value) => {
|
||||
try {
|
||||
parseDurationMs(String(value ?? ""), { defaultUnit: "d" });
|
||||
parseDurationMs(value ?? "", { defaultUnit: "d" });
|
||||
return undefined;
|
||||
} catch {
|
||||
return "Invalid duration (e.g. 365d, 12h, 30m)";
|
||||
}
|
||||
},
|
||||
}),
|
||||
})
|
||||
).trim()
|
||||
: undefined;
|
||||
|
||||
@@ -609,7 +605,7 @@ export async function modelsAuthLoginCommand(opts: LoginOptions, runtime: Runtim
|
||||
hint: provider.docsPath ? `Docs: ${provider.docsPath}` : undefined,
|
||||
})),
|
||||
})
|
||||
.then((id) => resolveProviderMatch(authProviders, String(id))));
|
||||
.then((id) => resolveProviderMatch(authProviders, id)));
|
||||
|
||||
if (!selectedProvider) {
|
||||
throw new Error("Unknown provider. Use --provider <id> to pick a provider plugin.");
|
||||
|
||||
Reference in New Issue
Block a user