mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 21:01:43 +03:00
fix code review
This commit is contained in:
committed by
Peter Steinberger
parent
e73d881c50
commit
0472dd68f0
@@ -9,6 +9,7 @@ export {
|
|||||||
markAuthProfileGood,
|
markAuthProfileGood,
|
||||||
setAuthProfileOrder,
|
setAuthProfileOrder,
|
||||||
upsertAuthProfile,
|
upsertAuthProfile,
|
||||||
|
upsertAuthProfileWithLock,
|
||||||
} from "./auth-profiles/profiles.js";
|
} from "./auth-profiles/profiles.js";
|
||||||
export {
|
export {
|
||||||
repairOAuthProfileIdMismatch,
|
repairOAuthProfileIdMismatch,
|
||||||
|
|||||||
@@ -66,6 +66,20 @@ export function upsertAuthProfile(params: {
|
|||||||
saveAuthProfileStore(store, params.agentDir);
|
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[] {
|
export function listProfilesForProvider(store: AuthProfileStore, provider: string): string[] {
|
||||||
const providerKey = normalizeProviderId(provider);
|
const providerKey = normalizeProviderId(provider);
|
||||||
return Object.entries(store.profiles)
|
return Object.entries(store.profiles)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { OpenClawConfig } from "../config/config.js";
|
import type { OpenClawConfig } from "../config/config.js";
|
||||||
import type { ApplyAuthChoiceParams, ApplyAuthChoiceResult } from "./auth-choice.apply.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_BASE_URL = "http://127.0.0.1:8000/v1";
|
||||||
const VLLM_DEFAULT_CONTEXT_WINDOW = 128000;
|
const VLLM_DEFAULT_CONTEXT_WINDOW = 128000;
|
||||||
@@ -65,7 +65,7 @@ export async function applyAuthChoiceVllm(
|
|||||||
const modelId = String(modelIdRaw ?? "").trim();
|
const modelId = String(modelIdRaw ?? "").trim();
|
||||||
const modelRef = `vllm/${modelId}`;
|
const modelRef = `vllm/${modelId}`;
|
||||||
|
|
||||||
upsertAuthProfile({
|
await upsertAuthProfileWithLock({
|
||||||
profileId: "vllm:default",
|
profileId: "vllm:default",
|
||||||
credential: { type: "api_key", provider: "vllm", key: apiKey },
|
credential: { type: "api_key", provider: "vllm", key: apiKey },
|
||||||
agentDir: params.agentDir,
|
agentDir: params.agentDir,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import type { WizardPrompter, WizardSelectOption } from "../wizard/prompts.js";
|
|||||||
import {
|
import {
|
||||||
ensureAuthProfileStore,
|
ensureAuthProfileStore,
|
||||||
listProfilesForProvider,
|
listProfilesForProvider,
|
||||||
upsertAuthProfile,
|
upsertAuthProfileWithLock,
|
||||||
} from "../agents/auth-profiles.js";
|
} from "../agents/auth-profiles.js";
|
||||||
import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "../agents/defaults.js";
|
import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "../agents/defaults.js";
|
||||||
import { getCustomProviderApiKey, resolveEnvApiKey } from "../agents/model-auth.js";
|
import { getCustomProviderApiKey, resolveEnvApiKey } from "../agents/model-auth.js";
|
||||||
@@ -200,7 +200,8 @@ export async function promptDefaultModel(
|
|||||||
models = models.filter((entry) => entry.provider === preferredProvider);
|
models = models.filter((entry) => entry.provider === preferredProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
const authStore = ensureAuthProfileStore(params.agentDir, {
|
const agentDir = params.agentDir;
|
||||||
|
const authStore = ensureAuthProfileStore(agentDir, {
|
||||||
allowKeychainPrompt: false,
|
allowKeychainPrompt: false,
|
||||||
});
|
});
|
||||||
const authCache = new Map<string, boolean>();
|
const authCache = new Map<string, boolean>();
|
||||||
@@ -228,7 +229,7 @@ export async function promptDefaultModel(
|
|||||||
if (includeManual) {
|
if (includeManual) {
|
||||||
options.push({ value: MANUAL_VALUE, label: "Enter model manually" });
|
options.push({ value: MANUAL_VALUE, label: "Enter model manually" });
|
||||||
}
|
}
|
||||||
if (includeVllm) {
|
if (includeVllm && agentDir) {
|
||||||
options.push({
|
options.push({
|
||||||
value: VLLM_VALUE,
|
value: VLLM_VALUE,
|
||||||
label: "vLLM (custom)",
|
label: "vLLM (custom)",
|
||||||
@@ -319,6 +320,13 @@ export async function promptDefaultModel(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (selection === VLLM_VALUE) {
|
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({
|
const baseUrlRaw = await params.prompter.text({
|
||||||
message: "vLLM base URL",
|
message: "vLLM base URL",
|
||||||
initialValue: VLLM_DEFAULT_BASE_URL,
|
initialValue: VLLM_DEFAULT_BASE_URL,
|
||||||
@@ -342,10 +350,10 @@ export async function promptDefaultModel(
|
|||||||
const apiKey = String(apiKeyRaw ?? "").trim();
|
const apiKey = String(apiKeyRaw ?? "").trim();
|
||||||
const modelId = String(modelIdRaw ?? "").trim();
|
const modelId = String(modelIdRaw ?? "").trim();
|
||||||
|
|
||||||
upsertAuthProfile({
|
await upsertAuthProfileWithLock({
|
||||||
profileId: "vllm:default",
|
profileId: "vllm:default",
|
||||||
credential: { type: "api_key", provider: "vllm", key: apiKey },
|
credential: { type: "api_key", provider: "vllm", key: apiKey },
|
||||||
agentDir: params.agentDir,
|
agentDir,
|
||||||
});
|
});
|
||||||
|
|
||||||
const nextConfig: OpenClawConfig = {
|
const nextConfig: OpenClawConfig = {
|
||||||
|
|||||||
Reference in New Issue
Block a user