






















@@ -379,6 +379,7 @@ async function pickProviderTokenMethod(params: {
379379380380async function persistProviderAuthResult(params: {
381381result: ProviderAuthResult;
382+profiles?: ProviderAuthResult["profiles"];
382383agentDir: string;
383384runtime: RuntimeEnv;
384385prompter: ReturnType<typeof createClackPrompter>;
@@ -387,7 +388,9 @@ async function persistProviderAuthResult(params: {
387388const defaultModel = params.result.defaultModel
388389 ? normalizeAgentModelRefForConfig(params.result.defaultModel)
389390 : undefined;
390-for (const profile of params.result.profiles) {
391+const profiles = params.profiles ?? params.result.profiles;
392+393+for (const profile of profiles) {
391394await upsertAuthProfileWithLockOrThrow({
392395profileId: profile.profileId,
393396credential: profile.credential,
@@ -408,7 +411,7 @@ async function persistProviderAuthResult(params: {
408411replaceDefaultModels: params.result.replaceDefaultModels,
409412});
410413}
411-for (const profile of params.result.profiles) {
414+for (const profile of profiles) {
412415next = applyAuthProfileConfig(next, {
413416profileId: profile.profileId,
414417provider: profile.credential.provider,
@@ -436,7 +439,7 @@ async function persistProviderAuthResult(params: {
436439}
437440438441logConfigUpdated(params.runtime);
439-for (const profile of params.result.profiles) {
442+for (const profile of profiles) {
440443params.runtime.log(
441444`Auth profile: ${profile.profileId} (${profile.credential.provider}/${credentialMode(profile.credential)})`,
442445);
@@ -461,6 +464,7 @@ async function runProviderAuthMethod(params: {
461464method: ProviderAuthMethod;
462465runtime: RuntimeEnv;
463466prompter: ReturnType<typeof createClackPrompter>;
467+profileId?: string;
464468setDefault?: boolean;
465469}) {
466470const selectedProviderId = normalizeProviderId(params.provider.id);
@@ -492,8 +496,14 @@ async function runProviderAuthMethod(params: {
492496}
493497}
494498499+const profiles = resolveLoginProfiles({
500+ result,
501+requestedProfileId: params.profileId,
502+});
503+495504await persistProviderAuthResult({
496505 result,
506+ profiles,
497507agentDir: params.agentDir,
498508runtime: params.runtime,
499509prompter: params.prompter,
@@ -795,6 +805,7 @@ export async function modelsAuthAddCommand(opts: { agent?: string }, runtime: Ru
795805type LoginOptions = {
796806provider?: string;
797807method?: string;
808+profileId?: string;
798809setDefault?: boolean;
799810yes?: boolean;
800811agent?: string;
@@ -837,6 +848,25 @@ function credentialMode(credential: AuthProfileCredential): "api_key" | "oauth"
837848return "oauth";
838849}
839850851+export function resolveLoginProfiles(params: {
852+result: ProviderAuthResult;
853+requestedProfileId?: string;
854+}): ProviderAuthResult["profiles"] {
855+const requestedProfileId = params.requestedProfileId?.trim();
856+if (!requestedProfileId) {
857+return params.result.profiles;
858+}
859+860+if (params.result.profiles.length !== 1) {
861+throw new Error(
862+"--profile-id requires exactly one returned auth profile from the selected auth method.",
863+);
864+}
865+866+const [profile] = params.result.profiles;
867+return [{ ...profile, profileId: requestedProfileId }];
868+}
869+840870function maybeLogOpenAICodexNativeSearchTip(runtime: RuntimeEnv, providerId: string) {
841871if (providerId !== "openai-codex") {
842872return;
@@ -845,6 +875,7 @@ function maybeLogOpenAICodexNativeSearchTip(runtime: RuntimeEnv, providerId: str
845875"Tip: Codex-capable models can use native Codex web search. Enable it with openclaw configure --section web (recommended mode: cached). Docs: https://docs.openclaw.ai/tools/web",
846876);
847877}
878+848879export async function modelsAuthLoginCommand(opts: LoginOptions, runtime: RuntimeEnv) {
849880if (!process.stdin.isTTY) {
850881throw new Error(
@@ -903,6 +934,7 @@ export async function modelsAuthLoginCommand(opts: LoginOptions, runtime: Runtim
903934method: chosenMethod,
904935 runtime,
905936 prompter,
937+profileId: opts.profileId,
906938setDefault: opts.setDefault,
907939});
908940maybeLogOpenAICodexNativeSearchTip(runtime, selectedProvider.id);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。