2026-01-20 07:53:25 +00:00
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
|
|
|
|
|
|
import { buildInlineProviderModels } from "./model.js";
|
|
|
|
|
|
|
|
|
|
const makeModel = (id: string) => ({
|
|
|
|
|
id,
|
|
|
|
|
name: id,
|
|
|
|
|
reasoning: false,
|
|
|
|
|
input: ["text"] as const,
|
|
|
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
|
|
|
contextWindow: 1,
|
|
|
|
|
maxTokens: 1,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("buildInlineProviderModels", () => {
|
|
|
|
|
it("attaches provider ids to inline models", () => {
|
|
|
|
|
const providers = {
|
|
|
|
|
" alpha ": { models: [makeModel("alpha-model")] },
|
|
|
|
|
beta: { models: [makeModel("beta-model")] },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const result = buildInlineProviderModels(providers);
|
|
|
|
|
|
|
|
|
|
expect(result).toEqual([
|
2026-01-27 19:08:35 +07:00
|
|
|
{ ...makeModel("alpha-model"), provider: "alpha", baseUrl: undefined, api: undefined },
|
|
|
|
|
{ ...makeModel("beta-model"), provider: "beta", baseUrl: undefined, api: undefined },
|
2026-01-20 07:53:25 +00:00
|
|
|
]);
|
|
|
|
|
});
|
2026-01-27 19:08:35 +07:00
|
|
|
|
|
|
|
|
it("inherits baseUrl from provider when model does not specify it", () => {
|
|
|
|
|
const providers = {
|
|
|
|
|
custom: {
|
|
|
|
|
baseUrl: "http://localhost:8000",
|
|
|
|
|
models: [makeModel("custom-model")],
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const result = buildInlineProviderModels(providers);
|
|
|
|
|
|
|
|
|
|
expect(result).toHaveLength(1);
|
|
|
|
|
expect(result[0].baseUrl).toBe("http://localhost:8000");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("inherits api from provider when model does not specify it", () => {
|
|
|
|
|
const providers = {
|
|
|
|
|
custom: {
|
|
|
|
|
api: "anthropic-messages",
|
|
|
|
|
models: [makeModel("custom-model")],
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const result = buildInlineProviderModels(providers);
|
|
|
|
|
|
|
|
|
|
expect(result).toHaveLength(1);
|
|
|
|
|
expect(result[0].api).toBe("anthropic-messages");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("model-level api takes precedence over provider-level api", () => {
|
|
|
|
|
const providers = {
|
|
|
|
|
custom: {
|
|
|
|
|
api: "openai-chat",
|
|
|
|
|
models: [{ ...makeModel("custom-model"), api: "anthropic-messages" as const }],
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const result = buildInlineProviderModels(providers);
|
|
|
|
|
|
|
|
|
|
expect(result).toHaveLength(1);
|
|
|
|
|
expect(result[0].api).toBe("anthropic-messages");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("inherits both baseUrl and api from provider config", () => {
|
|
|
|
|
const providers = {
|
|
|
|
|
custom: {
|
|
|
|
|
baseUrl: "http://localhost:10000",
|
|
|
|
|
api: "anthropic-messages",
|
|
|
|
|
models: [makeModel("claude-opus-4.5")],
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const result = buildInlineProviderModels(providers);
|
|
|
|
|
|
|
|
|
|
expect(result).toHaveLength(1);
|
|
|
|
|
expect(result[0]).toMatchObject({
|
|
|
|
|
provider: "custom",
|
|
|
|
|
baseUrl: "http://localhost:10000",
|
|
|
|
|
api: "anthropic-messages",
|
|
|
|
|
name: "claude-opus-4.5",
|
|
|
|
|
});
|
|
|
|
|
});
|
2026-01-20 07:53:25 +00:00
|
|
|
});
|