


























@@ -1,3 +1,4 @@
1+/** Commands for adding, pasting, and logging into provider model auth profiles. */
12import {
23cancel,
34confirm as clackConfirm,
@@ -193,6 +194,8 @@ function validateOpenAICodexApiKeyInput(value: string): string | undefined {
193194return undefined;
194195}
195196if (looksLikeJwtToken(trimmed) || looksLikeStructuredCredential(trimmed)) {
197+// OAuth/token material belongs in token profiles; storing it as an API key
198+// would make provider auth fail later with misleading model errors.
196199return `That looks like token or OAuth material, not an OpenAI API key. Use ${formatCliCommand("openclaw models auth paste-token --provider openai")} for token auth material.`;
197200}
198201return "That does not look like an OpenAI API key.";
@@ -583,6 +586,7 @@ async function runProviderAuthMethod(params: {
583586});
584587}
585588589+/** Runs an interactive provider setup-token auth flow. */
586590export async function modelsAuthSetupTokenCommand(
587591opts: { provider?: string; yes?: boolean; agent?: string },
588592runtime: RuntimeEnv,
@@ -639,6 +643,7 @@ export async function modelsAuthSetupTokenCommand(
639643});
640644}
641645646+/** Reads a pasted bearer/setup token and stores it as an auth profile. */
642647export async function modelsAuthPasteTokenCommand(
643648opts: {
644649provider?: string;
@@ -706,6 +711,7 @@ export async function modelsAuthPasteTokenCommand(
706711}
707712}
708713714+/** Reads a pasted API key and stores it as an auth profile. */
709715export async function modelsAuthPasteApiKeyCommand(
710716opts: {
711717provider?: string;
@@ -767,6 +773,7 @@ async function upsertAuthProfileWithLockOrThrow(params: UpsertAuthProfileParams)
767773}
768774}
769775776+/** Interactive helper for adding token auth profiles, with provider/method prompts. */
770777export async function modelsAuthAddCommand(opts: { agent?: string }, runtime: RuntimeEnv) {
771778const { config, agentDir, workspaceDir, providers } = await resolveModelsAuthContext({
772779rawAgentId: opts.agent,
@@ -906,6 +913,7 @@ async function clearStaleProfileLockouts(provider: string, agentDir: string): Pr
906913}
907914}
908915916+/** Resolves a requested login provider or throws with available provider details. */
909917export function resolveRequestedLoginProviderOrThrow(
910918providers: ProviderPlugin[],
911919rawProvider?: string,
@@ -923,6 +931,7 @@ function credentialMode(credential: AuthProfileCredential): "api_key" | "oauth"
923931return "oauth";
924932}
925933934+/** Applies an optional profile-id override to a single returned login profile. */
926935export function resolveLoginProfiles(params: {
927936result: ProviderAuthResult;
928937requestedProfileId?: string;
@@ -951,6 +960,7 @@ function maybeLogOpenAICodexNativeSearchTip(runtime: RuntimeEnv, providerId: str
951960);
952961}
953962963+/** Runs interactive provider auth login and persists returned profiles. */
954964export async function modelsAuthLoginCommand(opts: LoginOptions, runtime: RuntimeEnv) {
955965if (!process.stdin.isTTY) {
956966throw new Error(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。