refactor(providers): remove stale primary model helper

This commit is contained in:
Vincent Koc
2026-06-19 05:10:15 +08:00
parent d5a27b0b96
commit fdb042b9ce
2 changed files with 0 additions and 79 deletions
-33
View File
@@ -4,7 +4,6 @@ import os from "node:os";
import path from "node:path";
import { describe, expect, it, test, vi } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import { applyAgentDefaultPrimaryModel } from "../plugins/provider-model-primary.js";
import type { RuntimeEnv } from "../runtime.js";
import { withEnvAsync } from "../test-utils/env.js";
import {
@@ -70,38 +69,6 @@ describe("buildCleanupPlan", () => {
});
});
describe("applyAgentDefaultPrimaryModel", () => {
it("does not mutate when already set", () => {
const cfg = { agents: { defaults: { model: { primary: "a/b" } } } } as OpenClawConfig;
const result = applyAgentDefaultPrimaryModel({ cfg, model: "a/b" });
expect(result.changed).toBe(false);
expect(result.next).toBe(cfg);
});
it("normalizes legacy models", () => {
const cfg = { agents: { defaults: { model: { primary: "legacy" } } } } as OpenClawConfig;
const result = applyAgentDefaultPrimaryModel({
cfg,
model: "a/b",
legacyModels: new Set(["legacy"]),
});
expect(result.changed).toBe(false);
expect(result.next).toBe(cfg);
});
it("normalizes retired Google Gemini primary models before writing config", () => {
const cfg = { agents: { defaults: {} } } as OpenClawConfig;
const result = applyAgentDefaultPrimaryModel({
cfg,
model: "google/gemini-3-pro-preview",
});
expect(result.changed).toBe(true);
expect(result.next.agents?.defaults?.model).toEqual({
primary: "google/gemini-3.1-pro-preview",
});
});
});
describe("cleanup path removals", () => {
function createRuntimeMock() {
return {
-46
View File
@@ -3,54 +3,8 @@ import {
normalizeAgentModelMapForConfig,
normalizeAgentModelRefForConfig,
} from "../config/model-input.js";
import type { AgentModelListConfig } from "../config/types.js";
import type { OpenClawConfig } from "../config/types.openclaw.js";
function resolvePrimaryModel(model?: AgentModelListConfig | string): string | undefined {
if (typeof model === "string") {
return model;
}
if (model && typeof model === "object" && typeof model.primary === "string") {
return model.primary;
}
return undefined;
}
/** Applies an agent default primary model and reports whether config changed. */
export function applyAgentDefaultPrimaryModel(params: {
cfg: OpenClawConfig;
model: string;
legacyModels?: Set<string>;
}): { next: OpenClawConfig; changed: boolean } {
const model = normalizeAgentModelRefForConfig(params.model);
const current = resolvePrimaryModel(params.cfg.agents?.defaults?.model)?.trim();
const normalizedCurrent = current && params.legacyModels?.has(current) ? model : current;
if (normalizedCurrent === model) {
return { next: params.cfg, changed: false };
}
return {
next: {
...params.cfg,
agents: {
...params.cfg.agents,
defaults: {
...params.cfg.agents?.defaults,
model:
params.cfg.agents?.defaults?.model &&
typeof params.cfg.agents.defaults.model === "object"
? {
...params.cfg.agents.defaults.model,
primary: model,
}
: { primary: model },
},
},
},
changed: true,
};
}
/** Applies a primary model to agent defaults while preserving model fallback metadata. */
export function applyPrimaryModel(cfg: OpenClawConfig, model: string): OpenClawConfig {
const normalizedModel = normalizeAgentModelRefForConfig(model);