| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- import { describe, expect, it } from "vitest";
- import { BUILTIN_MODEL_PROVIDER_IDS } from "@zcode/shared";
- import type { ModelSelectionView } from "@zcode/services";
- import { buildRegistryModelSelectGroups } from "../src/lib/modelSelectionGroups.js";
- describe("model selection groups", () => {
- it.each([
- [{ type: "zhipu-account", accountType: "zai", mode: "individual-coding-plan" }, false],
- [{ type: "zhipu-account", accountType: "bigmodel", mode: "team-coding-plan" }, false],
- [{ type: "zhipu-coding-plan-api-key" }, false],
- [{ type: "zhipu-account", accountType: "zai", mode: "start-plan" }, false],
- [{ type: "zhipu-account", accountType: "bigmodel", mode: "start-plan" }, false],
- [{ type: "zhipu-account", accountType: "bigmodel", mode: "off-peak" }, true],
- [{ type: "api-key" }, true],
- ])("仅套餐 GLM-5.3 隐藏视觉标,不影响 Flash/真实能力:%j", (access, expected) => {
- const view: ModelSelectionView = {
- revision: 1,
- providers: [
- {
- providerId: "fixture",
- config: {
- access: access as ModelSelectionView["providers"][number]["config"]["access"],
- api: { type: "anthropic-messages" },
- },
- models: ["GLM-5.3", "GLM-5.3-Flash", "GLM-4.7"].map((modelId) => ({
- modelId,
- config: { properties: { inputFormat: { supportsImage: true } } },
- })),
- },
- ],
- };
- const items = buildRegistryModelSelectGroups("glm", view)[0]!.items;
- expect(items[0]!.supportsVisionInput === true).toBe(expected);
- expect(items[1]!.supportsVisionInput).toBe(true);
- expect(items[2]!.supportsVisionInput).toBe(true);
- expect(view.providers[0]!.models[0]!.config.properties?.inputFormat?.supportsImage).toBe(true);
- });
- it("保留带前缀和多段斜杠的精确模型 ID;不从名称推断视觉能力", () => {
- const modelId = "upstream/family/vision-preview";
- const view: ModelSelectionView = {
- revision: 1,
- providers: [
- {
- providerId: "aggregator",
- config: { api: { type: "openai-chat-completions", baseUrl: "https://example.test/v1" } },
- models: [{ modelId, config: { properties: { inputFormat: { supportsImage: true } } } }],
- },
- ],
- };
- expect(buildRegistryModelSelectGroups("glm", view)[0]?.items).toEqual([
- {
- key: `registry-provider:aggregator:${modelId}`,
- value: "custom:aggregator:upstream%2Ffamily%2Fvision-preview",
- name: modelId,
- supportsVisionInput: true,
- },
- ]);
- view.providers[0]!.models[0]!.config = {};
- expect(buildRegistryModelSelectGroups("glm", view)[0]?.items[0]).not.toHaveProperty(
- "supportsVisionInput",
- );
- });
- it("直接把 Registry API Provider 投影为有序模型组", () => {
- const selectionView: ModelSelectionView = {
- revision: 7,
- providers: [
- {
- providerId: "anthropic-api",
- providerName: "Anthropic API",
- config: {
- access: { type: "api-key", apiKey: "secret" },
- api: {
- type: "anthropic-messages",
- baseUrl: "https://example.com/anthropic",
- },
- models: ["claude-a", "claude-b"],
- },
- models: [
- {
- modelId: "claude-a",
- config: { properties: { inputFormat: { supportsImage: true } } },
- },
- { modelId: "claude-b", config: {} },
- ],
- },
- {
- providerId: "openai-api",
- providerName: "OpenAI API",
- config: {
- access: { type: "api-key", apiKey: "secret" },
- api: {
- type: "openai-responses",
- baseUrl: "https://example.com/openai",
- },
- models: ["model-a"],
- },
- models: [{ modelId: "model-a", config: {} }],
- },
- ],
- };
- expect(buildRegistryModelSelectGroups("glm", selectionView)).toEqual([
- {
- key: "registry-provider:anthropic-api",
- label: "Anthropic API",
- items: [
- {
- key: "registry-provider:anthropic-api:claude-a",
- value: "custom:anthropic-api:claude-a",
- name: "claude-a",
- supportsVisionInput: true,
- },
- {
- key: "registry-provider:anthropic-api:claude-b",
- value: "custom:anthropic-api:claude-b",
- name: "claude-b",
- },
- ],
- },
- {
- key: "registry-provider:openai-api",
- label: "OpenAI API",
- items: [
- {
- key: "registry-provider:openai-api:model-a",
- value: "custom:openai-api:model-a",
- name: "model-a",
- },
- ],
- },
- ]);
- });
- it("直接把 Registry Account Provider 投影为已选连接,不重新裁决 Family", () => {
- const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan;
- const selectionView: ModelSelectionView = {
- revision: 8,
- providers: [
- {
- providerId,
- providerName: "BigModel Coding Plan",
- config: {
- access: {
- type: "zhipu-account",
- accountType: "bigmodel",
- mode: "team-coding-plan",
- entitled: true,
- },
- api: {
- type: "anthropic-messages",
- baseUrl: "https://example.com/anthropic",
- },
- models: ["GLM-5.2"],
- },
- models: [{ modelId: "GLM-5.2", config: {} }],
- },
- ],
- };
- expect(buildRegistryModelSelectGroups("glm", selectionView)).toEqual([
- {
- key: `registry-provider:${providerId}`,
- label: "BigModel",
- labelBadge: "Team",
- directItems: true,
- items: [
- {
- key: `registry-provider:${providerId}:GLM-5.2`,
- value: "custom:account%3Abigmodel-team-coding-plan:GLM-5.2",
- name: "GLM-5.2",
- },
- ],
- },
- ]);
- });
- });
|