From 0472dd68f0a87b3fe7ed542353efbe911a48a391 Mon Sep 17 00:00:00 2001 From: gejifeng Date: Wed, 11 Feb 2026 07:53:19 +0000 Subject: [PATCH] fix code review --- src/agents/auth-profiles.ts | 1 + src/agents/auth-profiles/profiles.ts | 14 ++++++++++++++ src/commands/auth-choice.apply.vllm.ts | 4 ++-- src/commands/model-picker.ts | 18 +++++++++++++----- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/agents/auth-profiles.ts b/src/agents/auth-profiles.ts index 9a6c75b10a0..91593f3a6b1 100644 --- a/src/agents/auth-profiles.ts +++ b/src/agents/auth-profiles.ts @@ -9,6 +9,7 @@ export { markAuthProfileGood, setAuthProfileOrder, upsertAuthProfile, + upsertAuthProfileWithLock, } from "./auth-profiles/profiles.js"; export { repairOAuthProfileIdMismatch, diff --git a/src/agents/auth-profiles/profiles.ts b/src/agents/auth-profiles/profiles.ts index 597c2324724..019a611f4a3 100644 --- a/src/agents/auth-profiles/profiles.ts +++ b/src/agents/auth-profiles/profiles.ts @@ -66,6 +66,20 @@ export function upsertAuthProfile(params: { saveAuthProfileStore(store, params.agentDir); } +export async function upsertAuthProfileWithLock(params: { + profileId: string; + credential: AuthProfileCredential; + agentDir?: string; +}): Promise { + return await updateAuthProfileStoreWithLock({ + agentDir: params.agentDir, + updater: (store) => { + store.profiles[params.profileId] = params.credential; + return true; + }, + }); +} + export function listProfilesForProvider(store: AuthProfileStore, provider: string): string[] { const providerKey = normalizeProviderId(provider); return Object.entries(store.profiles) diff --git a/src/commands/auth-choice.apply.vllm.ts b/src/commands/auth-choice.apply.vllm.ts index dc69f720af3..bf741848fa5 100644 --- a/src/commands/auth-choice.apply.vllm.ts +++ b/src/commands/auth-choice.apply.vllm.ts @@ -1,6 +1,6 @@ import type { OpenClawConfig } from "../config/config.js"; import type { ApplyAuthChoiceParams, ApplyAuthChoiceResult } from "./auth-choice.apply.js"; -import { upsertAuthProfile } from "../agents/auth-profiles.js"; +import { upsertAuthProfileWithLock } from "../agents/auth-profiles.js"; const VLLM_DEFAULT_BASE_URL = "http://127.0.0.1:8000/v1"; const VLLM_DEFAULT_CONTEXT_WINDOW = 128000; @@ -65,7 +65,7 @@ export async function applyAuthChoiceVllm( const modelId = String(modelIdRaw ?? "").trim(); const modelRef = `vllm/${modelId}`; - upsertAuthProfile({ + await upsertAuthProfileWithLock({ profileId: "vllm:default", credential: { type: "api_key", provider: "vllm", key: apiKey }, agentDir: params.agentDir, diff --git a/src/commands/model-picker.ts b/src/commands/model-picker.ts index ae1d844d7c4..36bff128eff 100644 --- a/src/commands/model-picker.ts +++ b/src/commands/model-picker.ts @@ -3,7 +3,7 @@ import type { WizardPrompter, WizardSelectOption } from "../wizard/prompts.js"; import { ensureAuthProfileStore, listProfilesForProvider, - upsertAuthProfile, + upsertAuthProfileWithLock, } from "../agents/auth-profiles.js"; import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "../agents/defaults.js"; import { getCustomProviderApiKey, resolveEnvApiKey } from "../agents/model-auth.js"; @@ -200,7 +200,8 @@ export async function promptDefaultModel( models = models.filter((entry) => entry.provider === preferredProvider); } - const authStore = ensureAuthProfileStore(params.agentDir, { + const agentDir = params.agentDir; + const authStore = ensureAuthProfileStore(agentDir, { allowKeychainPrompt: false, }); const authCache = new Map(); @@ -228,7 +229,7 @@ export async function promptDefaultModel( if (includeManual) { options.push({ value: MANUAL_VALUE, label: "Enter model manually" }); } - if (includeVllm) { + if (includeVllm && agentDir) { options.push({ value: VLLM_VALUE, label: "vLLM (custom)", @@ -319,6 +320,13 @@ export async function promptDefaultModel( }); } if (selection === VLLM_VALUE) { + if (!agentDir) { + await params.prompter.note( + "vLLM setup requires an agent directory context.", + "vLLM not available", + ); + return {}; + } const baseUrlRaw = await params.prompter.text({ message: "vLLM base URL", initialValue: VLLM_DEFAULT_BASE_URL, @@ -342,10 +350,10 @@ export async function promptDefaultModel( const apiKey = String(apiKeyRaw ?? "").trim(); const modelId = String(modelIdRaw ?? "").trim(); - upsertAuthProfile({ + await upsertAuthProfileWithLock({ profileId: "vllm:default", credential: { type: "api_key", provider: "vllm", key: apiKey }, - agentDir: params.agentDir, + agentDir, }); const nextConfig: OpenClawConfig = {