fix code review

This commit is contained in:
gejifeng
2026-02-11 07:53:19 +00:00
committed by Peter Steinberger
parent e73d881c50
commit 0472dd68f0
4 changed files with 30 additions and 7 deletions

View File

@@ -9,6 +9,7 @@ export {
markAuthProfileGood,
setAuthProfileOrder,
upsertAuthProfile,
upsertAuthProfileWithLock,
} from "./auth-profiles/profiles.js";
export {
repairOAuthProfileIdMismatch,

View File

@@ -66,6 +66,20 @@ export function upsertAuthProfile(params: {
saveAuthProfileStore(store, params.agentDir);
}
export async function upsertAuthProfileWithLock(params: {
profileId: string;
credential: AuthProfileCredential;
agentDir?: string;
}): Promise<AuthProfileStore | null> {
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)

View File

@@ -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,

View File

@@ -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<string, boolean>();
@@ -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 = {