mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 19:41:23 +00:00
revert: fix models set catalog validation (#19194)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 7e3b2ff7af
Co-authored-by: sebslight <19554889+sebslight@users.noreply.github.com>
Co-authored-by: sebslight <19554889+sebslight@users.noreply.github.com>
Reviewed-by: @sebslight
This commit is contained in:
@@ -32,8 +32,8 @@ function createOAuthFetchFn(params: {
|
||||
refreshToken: string;
|
||||
username: string;
|
||||
passthrough?: boolean;
|
||||
}): typeof fetch {
|
||||
return withFetchPreconnect(async (input, init) => {
|
||||
}) {
|
||||
return withFetchPreconnect(async (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
const url = urlToString(input);
|
||||
if (url === CHUTES_TOKEN_ENDPOINT) {
|
||||
return new Response(
|
||||
|
||||
@@ -1,46 +1,12 @@
|
||||
import { loadModelCatalog } from "../../agents/model-catalog.js";
|
||||
import { modelKey } from "../../agents/model-selection.js";
|
||||
import { readConfigFileSnapshot } from "../../config/config.js";
|
||||
import { logConfigUpdated } from "../../config/logging.js";
|
||||
import type { RuntimeEnv } from "../../runtime.js";
|
||||
import { applyDefaultModelPrimaryUpdate, resolveModelTarget, updateConfig } from "./shared.js";
|
||||
import { applyDefaultModelPrimaryUpdate, updateConfig } from "./shared.js";
|
||||
|
||||
export async function modelsSetCommand(modelRaw: string, runtime: RuntimeEnv) {
|
||||
// 1. Read config and resolve the model reference
|
||||
const snapshot = await readConfigFileSnapshot();
|
||||
if (!snapshot.valid) {
|
||||
const issues = snapshot.issues.map((i) => `- ${i.path}: ${i.message}`).join("\n");
|
||||
throw new Error(`Invalid config at ${snapshot.path}\n${issues}`);
|
||||
}
|
||||
const cfg = snapshot.config;
|
||||
const resolved = resolveModelTarget({ raw: modelRaw, cfg });
|
||||
const key = `${resolved.provider}/${resolved.model}`;
|
||||
|
||||
// 2. Validate against catalog (skip when catalog is empty — initial setup)
|
||||
const catalog = await loadModelCatalog({ config: cfg });
|
||||
if (catalog.length > 0) {
|
||||
const catalogKeys = new Set(catalog.map((e) => modelKey(e.provider, e.id)));
|
||||
if (!catalogKeys.has(key)) {
|
||||
throw new Error(
|
||||
`Unknown model: ${key}\nModel not found in catalog. Run "openclaw models list" to see available models.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Track whether this is a new entry
|
||||
const isNewEntry = !cfg.agents?.defaults?.models?.[key];
|
||||
|
||||
// 4. Update config (using upstream's helper for the actual mutation)
|
||||
const updated = await updateConfig((c) => {
|
||||
return applyDefaultModelPrimaryUpdate({ cfg: c, modelRaw, field: "model" });
|
||||
const updated = await updateConfig((cfg) => {
|
||||
return applyDefaultModelPrimaryUpdate({ cfg, modelRaw, field: "model" });
|
||||
});
|
||||
|
||||
// 5. Warn and log
|
||||
if (isNewEntry) {
|
||||
runtime.log(
|
||||
`Warning: "${key}" had no entry in models config. Added with empty config (no provider routing).`,
|
||||
);
|
||||
}
|
||||
logConfigUpdated(runtime);
|
||||
runtime.log(`Default model: ${updated.agents?.defaults?.model?.primary ?? modelRaw}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user