mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 09:47:40 +00:00
108 lines
3.6 KiB
TypeScript
108 lines
3.6 KiB
TypeScript
import fs from "node:fs/promises";
|
|
import path from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import type { OpenClawConfig } from "../config/config.js";
|
|
import { resolveOpenClawAgentDir } from "./agent-paths.js";
|
|
import {
|
|
CUSTOM_PROXY_MODELS_CONFIG,
|
|
installModelsConfigTestHooks,
|
|
withModelsTempHome as withTempHome,
|
|
} from "./models-config.e2e-harness.js";
|
|
import { ensureOpenClawModelsJson } from "./models-config.js";
|
|
|
|
installModelsConfigTestHooks();
|
|
|
|
describe("models-config", () => {
|
|
it("fills missing provider.apiKey from env var name when models exist", async () => {
|
|
await withTempHome(async () => {
|
|
const prevKey = process.env.MINIMAX_API_KEY;
|
|
process.env.MINIMAX_API_KEY = "sk-minimax-test";
|
|
try {
|
|
const cfg: OpenClawConfig = {
|
|
models: {
|
|
providers: {
|
|
minimax: {
|
|
baseUrl: "https://api.minimax.io/anthropic",
|
|
api: "anthropic-messages",
|
|
models: [
|
|
{
|
|
id: "MiniMax-M2.1",
|
|
name: "MiniMax M2.1",
|
|
reasoning: false,
|
|
input: ["text"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 200000,
|
|
maxTokens: 8192,
|
|
},
|
|
],
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
await ensureOpenClawModelsJson(cfg);
|
|
|
|
const modelPath = path.join(resolveOpenClawAgentDir(), "models.json");
|
|
const raw = await fs.readFile(modelPath, "utf8");
|
|
const parsed = JSON.parse(raw) as {
|
|
providers: Record<string, { apiKey?: string; models?: Array<{ id: string }> }>;
|
|
};
|
|
expect(parsed.providers.minimax?.apiKey).toBe("MINIMAX_API_KEY");
|
|
const ids = parsed.providers.minimax?.models?.map((model) => model.id);
|
|
expect(ids).toContain("MiniMax-VL-01");
|
|
} finally {
|
|
if (prevKey === undefined) {
|
|
delete process.env.MINIMAX_API_KEY;
|
|
} else {
|
|
process.env.MINIMAX_API_KEY = prevKey;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
it("merges providers by default", async () => {
|
|
await withTempHome(async () => {
|
|
const agentDir = resolveOpenClawAgentDir();
|
|
await fs.mkdir(agentDir, { recursive: true });
|
|
await fs.writeFile(
|
|
path.join(agentDir, "models.json"),
|
|
JSON.stringify(
|
|
{
|
|
providers: {
|
|
existing: {
|
|
baseUrl: "http://localhost:1234/v1",
|
|
apiKey: "EXISTING_KEY",
|
|
api: "openai-completions",
|
|
models: [
|
|
{
|
|
id: "existing-model",
|
|
name: "Existing",
|
|
api: "openai-completions",
|
|
reasoning: false,
|
|
input: ["text"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 8192,
|
|
maxTokens: 2048,
|
|
},
|
|
],
|
|
},
|
|
},
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
"utf8",
|
|
);
|
|
|
|
await ensureOpenClawModelsJson(CUSTOM_PROXY_MODELS_CONFIG);
|
|
|
|
const raw = await fs.readFile(path.join(agentDir, "models.json"), "utf8");
|
|
const parsed = JSON.parse(raw) as {
|
|
providers: Record<string, { baseUrl?: string }>;
|
|
};
|
|
|
|
expect(parsed.providers.existing?.baseUrl).toBe("http://localhost:1234/v1");
|
|
expect(parsed.providers["custom-proxy"]?.baseUrl).toBe("http://localhost:4000/v1");
|
|
});
|
|
});
|
|
});
|