diff --git a/src/canvas/ModelServiceForm.tsx b/src/canvas/ModelServiceForm.tsx index 91da74e1..cd339fc3 100644 --- a/src/canvas/ModelServiceForm.tsx +++ b/src/canvas/ModelServiceForm.tsx @@ -17,8 +17,11 @@ import { } from "../backend/rules.ts"; import { ModelCapabilityCard } from "./ModelCapabilityCard"; import { + LOCAL_OMNI_PRESET_ID, PROVIDER_PRESETS, matchingConnections, + presetProtocol, + presetStages, providerPresetFor, } from "./providerPresets"; import { CanvasIcon } from "./CanvasIcon"; @@ -68,33 +71,40 @@ export function ModelServiceForm({ const t = useT(); const connectionFieldId = useId(); const [connection, setConnection] = useState(existing); - const [presetId, setPresetId] = useState( - existing - ? providerPresetFor(existing) - : kind === "video" - ? "vllm-omni-video" - : kind === "image" - ? "vllm-omni-image" - : kind === "audio" - ? "vllm-omni-speech" - : "custom", + const initialPresetId = existing + ? providerPresetFor(existing) + : kind === "video" || kind === "image" || kind === "audio" + ? LOCAL_OMNI_PRESET_ID + : "custom"; + const initialPreset = PROVIDER_PRESETS.find( + (item) => item.id === initialPresetId, ); + // The custom preset shows a sample hosted endpoint; leave it empty so the + // user enters their own service. Self-hosted presets carry real defaults. + const initialDefaults = + initialPreset?.connectionType === "self_hosted" ? initialPreset : undefined; + const [presetId, setPresetId] = useState(initialPresetId); const [modelOptions, setModelOptions] = useState< Record >({}); const [modelErrors, setModelErrors] = useState>({}); const [value, setValue] = useState({ kind, - url: existing?.url ?? "", + url: existing?.url ?? initialDefaults?.url ?? "", modelId: existing?.modelId ?? "", apiKey: "", - connectionType: existing?.connectionType ?? "self_hosted", + connectionType: + existing?.connectionType ?? + initialDefaults?.connectionType ?? + "self_hosted", capabilityAutoCheck: existing?.capabilityAutoCheck, protocol: existing && isSegmentationModel(existing) ? "vllm_omni_segmentation" - : (existing?.protocol ?? PROTOCOLS[kind][0][0]), - authMode: existing?.authMode ?? "none", + : (existing?.protocol ?? + presetProtocol(initialDefaults, kind) ?? + PROTOCOLS[kind][0][0]), + authMode: existing?.authMode ?? initialDefaults?.authMode ?? "none", proxyMode: existing ? (existing.proxyMode ?? "system") : "direct", videoAdapter: existing?.videoAdapter ?? "auto", inputModalities: @@ -127,6 +137,17 @@ export function ModelServiceForm({ const segmentation = value.protocol === "vllm_omni_segmentation"; const depth = value.protocol === "vllm_omni_depth"; const score = value.protocol === "vllm_omni_score"; + const selectedPreset = PROVIDER_PRESETS.find((item) => item.id === presetId); + const stages = presetStages(selectedPreset, kind); + const activeStage = stages.find( + (stage) => stage.protocol === value.protocol, + ); + const protocolLabel = (protocol: ModelConfigInput["protocol"]) => { + const option = PROTOCOLS[kind].find( + ([candidate]) => candidate === protocol, + ); + return option ? t(option[1]) : protocol; + }; const hasSavedKey = Boolean( connection && connection.authMode === "bearer" && @@ -269,7 +290,7 @@ export function ModelServiceForm({ apiKey: "", videoAdapter: "auto", url: preset?.url ?? "", - protocol: preset?.protocol ?? PROTOCOLS[kind][0][0], + protocol: presetProtocol(preset, kind) ?? PROTOCOLS[kind][0][0], connectionType: preset?.connectionType ?? "self_hosted", authMode: preset?.authMode ?? "none", proxyMode: "direct", @@ -358,6 +379,41 @@ export function ModelServiceForm({ disabled={locked} onChange={chooseProvider} /> + {stages.length > 1 && ( +
+
+ + {activeStage && ( +

+ {t("models.service.stageEndpoints", { + paths: activeStage.paths.join(", "), + })} +

+ )} +
+
+ )} {!connection && connections.length > 0 && (
{t("models.service.existingConnections")} diff --git a/src/canvas/model-settings.css b/src/canvas/model-settings.css index 0be4112d..d1f30ecd 100644 --- a/src/canvas/model-settings.css +++ b/src/canvas/model-settings.css @@ -660,6 +660,7 @@ .cw-model-picker.has-capability-cards .cw-model-options { max-height: none; } .cw-model-editor-scroll > .cw-model-connection-details { margin: 0 0 16px; } +.cw-model-editor-scroll > .cw-provider-stage { margin: 0 0 16px; } .cw-model-editor-scroll > .cw-provider-key { margin: 0 0 18px; } .cw-model-availability { padding: 12px 0; font-size: var(--settings-label-size, 13px); } diff --git a/src/canvas/providerPresets.ts b/src/canvas/providerPresets.ts index 8760e32d..33f0f790 100644 --- a/src/canvas/providerPresets.ts +++ b/src/canvas/providerPresets.ts @@ -16,23 +16,11 @@ const EN_NAMES: Record = { "MiniMax 官方语音": "MiniMax Official Speech", "MOSS 开放平台": "MOSS Open Platform", "火山方舟 / Agent Plan": "Volcano Ark / Agent Plan", - "vLLM-Omni 图片接口": "vLLM-Omni image API", - "vLLM-Omni 语音合成接口": "vLLM-Omni speech synthesis API", - "vLLM-Omni 音乐生成接口": "vLLM-Omni music generation API", - "vLLM-Omni 扒谱接口": "vLLM-Omni transcription API", - "vLLM-Omni 视频接口": "vLLM-Omni video API", - "vLLM-Omni 分割接口": "vLLM-Omni segmentation API", - "vLLM-Omni 深度接口": "vLLM-Omni depth API", + "vLLM-Omni 本地服务": "vLLM-Omni local service", }; const EN_OPTION_LABELS: Record = { - 图片接口: "Image API", - 语音合成接口: "Speech synthesis API", - 音乐生成接口: "Music generation API", - 扒谱接口: "Transcription API", - 视频接口: "Video API", - 分割接口: "Segmentation API", - 深度接口: "Depth API", + 本地服务: "Local service", }; const EN_GROUPS: Record = { @@ -55,6 +43,13 @@ function groupLabel(value: string | undefined): string | undefined { return getActiveLocale() === "en-US" ? (EN_GROUPS[value] ?? value) : value; } +/** One stage of a multi-stage self-hosted service: the endpoints it serves. */ +export interface ProviderStage { + /** Endpoint paths appended to the connection URL, e.g. `/images/generations`. */ + paths: readonly string[]; + protocol: ModelConfigInput["protocol"]; +} + export interface ProviderPreset { id: string; name: string; @@ -68,6 +63,13 @@ export interface ProviderPreset { connectionType: ModelConfigInput["connectionType"]; authMode: ModelConfigInput["authMode"]; modelsByKind?: Partial>; + /** + * Per-kind stages of a service that serves several endpoints behind one + * connection. The first stage is the kind's default. Absent for + * single-purpose presets, where `url` + `protocol` describe the whole + * connection. + */ + stages?: Partial>; } export const PROVIDER_PRESETS: ProviderPreset[] = [ @@ -257,40 +259,96 @@ export const PROVIDER_PRESETS: ProviderPreset[] = [ connectionType: "api", authMode: "bearer", }, - ...( - [ - ["vllm-omni-image", "vLLM-Omni 图片接口", "openai", ["image"]], - ["vllm-omni-speech", "vLLM-Omni 语音合成接口", "openai", ["audio"]], - [ - "vllm-omni-music", - "vLLM-Omni 音乐生成接口", - "vllm_omni_music", - ["audio"], + { + id: "vllm-omni-local", + logoOrganization: "vllm-project", + name: "vLLM-Omni 本地服务", + optionLabel: "本地服务", + group: "vLLM-Omni", + kinds: ["agent", "image", "video", "audio", "vision"], + url: "http://127.0.0.1:8000/v1", + protocol: "vllm_omni", + connectionType: "self_hosted", + authMode: "none", + // One localhost service serves several stages; each stage keeps the + // protocol its adapter expects, so a single connection is enough. The + // first stage of each kind is the default. + // + // ASR is deliberately absent: vllm-omni does not serve + // /audio/transcriptions yet (S1 in #10007) and this application has no ASR + // adapter. SheetSage2 score shares the path with its own protocol. + stages: { + agent: [{ paths: ["/chat/completions"], protocol: "openai" }], + image: [ + { paths: ["/images/generations", "/images/edits"], protocol: "openai" }, + { + paths: ["/images/segmentations", "/videos/segmentations"], + protocol: "vllm_omni_segmentation", + }, ], - ["vllm-omni-score", "vLLM-Omni 扒谱接口", "vllm_omni_score", ["audio"]], - ["vllm-omni-video", "vLLM-Omni 视频接口", "vllm_omni", ["video"]], - [ - "vllm-omni-segmentation", - "vLLM-Omni 分割接口", - "vllm_omni_segmentation", - ["image", "video", "vision"], + video: [ + { paths: ["/videos"], protocol: "vllm_omni" }, + { + paths: ["/images/segmentations", "/videos/segmentations"], + protocol: "vllm_omni_segmentation", + }, + { paths: ["/videos/depth"], protocol: "vllm_omni_depth" }, ], - ["vllm-omni-depth", "vLLM-Omni 深度接口", "vllm_omni_depth", ["video"]], - ] as const - ).map(([id, name, protocol, kinds]) => ({ - id, - name, - group: "vLLM-Omni", - logoOrganization: "vllm-project", - optionLabel: name.replace("vLLM-Omni ", ""), - protocol, - kinds: [...kinds], - url: "", - connectionType: "self_hosted" as const, - authMode: "none" as const, - })), + audio: [ + { paths: ["/audio/speech"], protocol: "openai" }, + { paths: ["/audio/speech"], protocol: "vllm_omni_music" }, + { paths: ["/audio/transcriptions"], protocol: "vllm_omni_score" }, + ], + vision: [ + { + paths: ["/images/segmentations", "/videos/segmentations"], + protocol: "vllm_omni_segmentation", + }, + ], + }, + }, ]; +export const LOCAL_OMNI_PRESET_ID = "vllm-omni-local"; + +/** The stages a preset serves for one kind; empty for single-purpose presets. */ +export function presetStages( + preset: ProviderPreset | undefined, + kind: ModelKind, +): readonly ProviderStage[] { + return preset?.stages?.[kind] ?? []; +} + +/** + * The protocol a connection uses for one kind. A protocol that names one of + * the preset's stages is kept, so reopening a saved specialized connection + * does not silently switch it back to the kind's default stage. + */ +export function presetProtocol( + preset: ProviderPreset | undefined, + kind: ModelKind, + protocol?: ModelConfigInput["protocol"] | null, +): ModelConfigInput["protocol"] | undefined { + const stages = presetStages(preset, kind); + if (protocol && stages.some((stage) => stage.protocol === protocol)) + return protocol; + return stages[0]?.protocol ?? preset?.protocol; +} + +/** + * `openai` is shared by generic self-hosted services, so it identifies this + * preset only at the documented loopback default. The specialized vLLM-Omni + * protocols are unique and need no URL rule. + */ +function isLoopbackUrl(value: string): boolean { + try { + const host = new URL(value).hostname.replace(/^\[|\]$/g, ""); + return host === "localhost" || host === "127.0.0.1" || host === "::1"; + } catch { + return false; + } +} + export function providerPresetFor(model: ModelConfig): string { const explicit = PROVIDER_PRESETS.find( (preset) => @@ -300,6 +358,16 @@ export function providerPresetFor(model: ModelConfig): string { preset.kinds.includes(model.kind), ); if (explicit) return explicit.id; + const staged = PROVIDER_PRESETS.find( + (preset) => + model.connectionType === "self_hosted" && + preset.kinds.includes(model.kind) && + presetStages(preset, model.kind).some( + (stage) => stage.protocol === model.protocol, + ) && + (model.protocol !== "openai" || isLoopbackUrl(model.url)), + ); + if (staged) return staged.id; const deployed = PROVIDER_PRESETS.find( (preset) => preset.connectionType === "self_hosted" && diff --git a/src/i18n/messages/en-US/models.ts b/src/i18n/messages/en-US/models.ts index 1cbeb068..dde69006 100644 --- a/src/i18n/messages/en-US/models.ts +++ b/src/i18n/messages/en-US/models.ts @@ -129,6 +129,8 @@ export const models = { "models.service.saving": "Saving…", "models.service.cancel": "Cancel", "models.service.advancedConnection": "Advanced connection settings", + "models.service.stage": "Stage", + "models.service.stageEndpoints": "Endpoints: {paths}", "models.service.existingConnections": "Connections with the same address", "models.service.reuseConnection": "Reuse saved connection · {model}", diff --git a/src/i18n/messages/zh-CN/models.ts b/src/i18n/messages/zh-CN/models.ts index 75a63878..0aa9a04c 100644 --- a/src/i18n/messages/zh-CN/models.ts +++ b/src/i18n/messages/zh-CN/models.ts @@ -107,6 +107,8 @@ export const models = { "models.service.saving": "保存中…", "models.service.cancel": "取消", "models.service.advancedConnection": "高级连接设置", + "models.service.stage": "接口阶段", + "models.service.stageEndpoints": "接口路径:{paths}", "models.service.existingConnections": "已有相同地址的连接", "models.service.reuseConnection": "复用已保存连接 · {model}", "models.service.reuseHint": "不复用则保存为独立连接。", diff --git a/tests/browser/capability_discovery.mjs b/tests/browser/capability_discovery.mjs index 554f6f05..9a0ec968 100644 --- a/tests/browser/capability_discovery.mjs +++ b/tests/browser/capability_discovery.mjs @@ -778,7 +778,11 @@ try { .getByText("Fixture catalogue unavailable", { exact: true }).waitFor(); await page.unroute("**/api/model-configs"); await page.getByRole("button", { name: "Close settings", exact: true }).click(); - await page.locator(`.react-flow__node[data-id="${itemId}"]`).click(); + const canvasNode = page.locator( + `.react-flow__node[data-id="${itemId}"]`, + ); + await canvasNode.waitFor({ timeout: 30000 }); + await canvasNode.click(); assert.equal(await page.locator(".cw-generation-composer button.cw-run-button").isEnabled(), true); assert.match(await page.locator(".cw-generation-composer").innerText(), /Preserve this prompt/); await page.getByRole("button", { name: "Settings", exact: true }).click(); diff --git a/tests/browser/kling_video.mjs b/tests/browser/kling_video.mjs index 7b9518c2..b9e3adc9 100644 --- a/tests/browser/kling_video.mjs +++ b/tests/browser/kling_video.mjs @@ -49,7 +49,7 @@ const copy = { video: "Video", add: "Add service", provider: "Provider", - defaultProvider: "vLLM-Omni video API", + defaultProvider: "vLLM-Omni local service", kling: "Kling official video", url: "Service URL (Base URL)", save: "Save service", @@ -69,7 +69,7 @@ const copy = { video: "视频", add: "添加服务", provider: "提供商", - defaultProvider: "vLLM-Omni 视频接口", + defaultProvider: "vLLM-Omni 本地服务", kling: "可灵官方视频", url: "服务地址(Base URL)", save: "保存服务", diff --git a/tests/browser/moss_provider.mjs b/tests/browser/moss_provider.mjs index b3cab056..e14a143e 100644 --- a/tests/browser/moss_provider.mjs +++ b/tests/browser/moss_provider.mjs @@ -51,14 +51,14 @@ const copy = { settings: "设置", models: "模型接入", imageOverview: "图片模型", image: "图片", audio: "音频", add: "添加服务", provider: "提供商", moss: "MOSS 开放平台", url: "服务地址(Base URL)", reload: "载入支持的模型", save: "保存服务", cancel: "取消", manage: "管理", close: "关闭设置", - general: "通用", language: "语言", defaultImage: "vLLM-Omni 图片接口", defaultAudio: "vLLM-Omni 语音合成接口", + general: "通用", language: "语言", defaultImage: "vLLM-Omni 本地服务", defaultAudio: "vLLM-Omni 本地服务", custom: "OpenAI 兼容", fetch: "获取模型", discoveryError: "服务返回 HTTP 401,请检查 API Key。", }, "en-US": { settings: "Settings", models: "Model connections", imageOverview: "Image model", image: "Image", audio: "Audio", add: "Add service", provider: "Provider", moss: "MOSS Open Platform", url: "Service URL (Base URL)", reload: "Load supported models", save: "Save service", cancel: "Cancel", manage: "Manage", close: "Close settings", - general: "General", language: "Language", defaultImage: "vLLM-Omni image API", defaultAudio: "vLLM-Omni speech synthesis API", + general: "General", language: "Language", defaultImage: "vLLM-Omni local service", defaultAudio: "vLLM-Omni local service", custom: "OpenAI compatible", fetch: "Fetch models", discoveryError: "Service returned HTTP 401. Check the API Key.", }, }; diff --git a/tests/browser/provider_settings.mjs b/tests/browser/provider_settings.mjs index 5cd8f904..60fa2b78 100644 --- a/tests/browser/provider_settings.mjs +++ b/tests/browser/provider_settings.mjs @@ -23,6 +23,9 @@ await page.addInitScript(() => { }); page.setDefaultTimeout(15000); const calls = []; +const initialModelIds = new Set( + (await call("/api/model-configs")).map((model) => model.id), +); page.on("request", (request) => calls.push(request.url())); try { const projectId = crypto.randomUUID(); @@ -36,19 +39,29 @@ try { await page.getByRole("button", { name: "Settings", exact: true }).click(); await page.getByRole("button", { name: "Model connections", exact: true }).click(); await page.locator(".cw-model-setup-row").filter({ hasText: "Image model" }).getByRole("button").click(); - for (const [category, interfaces] of [ - ["Image", ["vLLM-Omni image API", "vLLM-Omni segmentation API"]], - ["Audio", ["vLLM-Omni speech synthesis API", "vLLM-Omni music generation API", "vLLM-Omni transcription API"]], - ["Chat", ["OpenAI compatible"]], + for (const [category, stageCount, defaultStage, endpoints] of [ + ["Image", 2, "OpenAI-compatible API (including gpt-image and vLLM-Omni Z-Image-Turbo)", "Endpoints: /images/generations, /images/edits"], + ["Audio", 3, "OpenAI-compatible speech synthesis (including vLLM-Omni TTS)", "Endpoints: /audio/speech"], + ["Chat", 0, null, null], ]) { await page.getByRole("button", { name: category, exact: true }).click(); await page.getByRole("button", { name: "Add service", exact: true }).click(); - for (const name of interfaces) { - await page.getByRole("combobox", { name: "Provider", exact: true }).click(); - assert.equal(await page.getByRole("listbox", { name: "Provider", exact: true }).getByRole("option").first().getAttribute("aria-label"), "OpenAI compatible"); - assert.equal(await page.getByRole("option", { name: "Custom service", exact: true }).count(), 0); - await page.getByRole("option", { name, exact: true }).click(); - assert.equal(await page.getByText("API protocol", { exact: true }).count(), 0); + await page.getByRole("combobox", { name: "Provider", exact: true }).click(); + assert.equal(await page.getByRole("listbox", { name: "Provider", exact: true }).getByRole("option").first().getAttribute("aria-label"), "OpenAI compatible"); + assert.equal(await page.getByRole("option", { name: "Custom service", exact: true }).count(), 0); + await page.getByRole("option", { name: "vLLM-Omni local service", exact: true }).click(); + assert.equal(await page.getByText("API protocol", { exact: true }).count(), 0); + assert.equal( + await page.getByLabel("Service URL (Base URL)", { exact: true }).inputValue(), + "http://127.0.0.1:8000/v1", + ); + const stage = page.getByRole("combobox", { name: "Stage", exact: true }); + if (stageCount) { + assert.equal(await stage.locator("option").count(), stageCount); + assert.equal(await stage.locator("option:checked").innerText(), defaultStage); + assert.equal(await page.getByText(endpoints, { exact: true }).count(), 1); + } else { + assert.equal(await stage.count(), 0); } await page.screenshot({ path: `/tmp/provider-${category}.png` }); await page.getByRole("button", { name: "Cancel", exact: true }).click(); @@ -57,13 +70,24 @@ try { await page.getByRole("button", { name: "Add service", exact: true }).click(); await page.getByRole("combobox", { name: "Provider", exact: true }).click(); assert.equal(await page.getByRole("option", { name: "Custom service", exact: true }).count(), 0); - assert.equal(await page.getByRole("group", { name: "vLLM-Omni compatible", exact: true }).getByRole("option").count(), 3); - for (const name of ["vLLM-Omni video API", "vLLM-Omni segmentation API", "vLLM-Omni depth API"]) { - await page.getByRole("option", { name, exact: true }).click(); - assert.equal(await page.getByText("API protocol", { exact: true }).count(), 0); - assert.equal(await page.getByRole("combobox", { name: "Provider", exact: true }).innerText(), name); - await page.getByRole("combobox", { name: "Provider", exact: true }).click(); + const omniGroup = page.getByRole("group", { name: "vLLM-Omni compatible", exact: true }); + assert.equal(await omniGroup.getByRole("option").count(), 1); + assert.equal(await omniGroup.getByRole("option").first().getAttribute("aria-label"), "vLLM-Omni local service"); + await page.getByRole("option", { name: "vLLM-Omni local service", exact: true }).click(); + assert.equal(await page.getByText("API protocol", { exact: true }).count(), 0); + assert.equal(await page.getByRole("combobox", { name: "Provider", exact: true }).innerText(), "vLLM-Omni local service"); + const videoStage = page.getByRole("combobox", { name: "Stage", exact: true }); + assert.equal(await videoStage.locator("option").count(), 3); + for (const [label, endpoints] of [ + ["Async /videos API (including vLLM-Omni)", "Endpoints: /videos"], + ["vLLM-Omni segmentation API (SAM 3)", "Endpoints: /images/segmentations, /videos/segmentations"], + ["vLLM-Omni depth API (Video Depth Anything)", "Endpoints: /videos/depth"], + ]) { + await videoStage.selectOption({ label }); + assert.equal(await page.getByText(endpoints, { exact: true }).count(), 1); } + await videoStage.selectOption({ label: "Async /videos API (including vLLM-Omni)" }); + await page.getByRole("combobox", { name: "Provider", exact: true }).click(); await page.getByRole("textbox", { name: "Search Provider" }).fill("MiniMax"); assert.equal(await page.getByRole("listbox", { name: "Provider", exact: true }).getByRole("option").count(), 1); await page.keyboard.press("Escape"); @@ -213,4 +237,12 @@ try { throw error; } finally { await browser.close(); + // Leave the shared fixture catalogue as this workflow found it so later + // browser workflows do not inherit its saved services. + for (const model of await call("/api/model-configs").catch(() => [])) { + if (!initialModelIds.has(model.id)) + await call(`/api/model-configs/${model.id}`, undefined, "DELETE").catch( + () => {}, + ); + } } diff --git a/tests/providerPresets.test.ts b/tests/providerPresets.test.ts index 39d5bcf8..aa310a09 100644 --- a/tests/providerPresets.test.ts +++ b/tests/providerPresets.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert/strict"; import test from "node:test"; -import { PROVIDER_PRESETS, matchingConnections, providerOptions, providerPresetFor } from "../src/canvas/providerPresets.ts"; +import { LOCAL_OMNI_PRESET_ID, PROVIDER_PRESETS, matchingConnections, presetProtocol, providerOptions, providerPresetFor } from "../src/canvas/providerPresets.ts"; import type { ModelConfig } from "../src/backend/rules.ts"; import { modelDescription } from "../src/canvas/modelDescriptions.ts"; import { getActiveLocale, setActiveLocale } from "../src/i18n/messages.ts"; @@ -63,7 +63,7 @@ test("provider presets separate official protocol from self-hosted model names", assert.deepEqual(official.modelsByKind?.video, ["MiniMax-H3", "MiniMax-H3-Highspeed", "MiniMax-H3-Lite", "MiniMax-H3-Max"]); const model: ModelConfig = { ...official, id: "one", kind: "video", modelId: "MiniMax-H3", inputRules: { profile: "", allowedKinds: [], maxImages: 0, maxVideos: 0, maxAudios: 0, videoModes: [] } }; assert.equal(providerPresetFor(model), "minimax-video"); - assert.equal(providerPresetFor({ ...model, connectionType: "self_hosted", protocol: "vllm_omni" }), "vllm-omni-video"); + assert.equal(providerPresetFor({ ...model, connectionType: "self_hosted", protocol: "vllm_omni" }), "vllm-omni-local"); assert.deepEqual(matchingConnections([{ ...model, providerId: "shared" }, { ...model, id: "two", providerId: "shared" }, { ...model, id: "three", providerId: "other" }], "video", { ...model, protocol: "minimax_video_v2", authMode: "bearer", apiKey: "" }).map((item) => item.id), ["one", "three"]); }); @@ -397,3 +397,103 @@ test("a saved Zhipu GLM-TTS connection reopens with its provider identity", () = assert.equal(providerPresetFor(model), "zhipu"); assert.equal(providerPresetFor({ ...model, url: "https://other.test/v1" }), "custom"); }); + +test("vLLM-Omni is one local service with an endpoint per stage", () => { + const preset = PROVIDER_PRESETS.find((item) => item.id === LOCAL_OMNI_PRESET_ID)!; + assert.equal(preset.url, "http://127.0.0.1:8000/v1"); + assert.equal(preset.connectionType, "self_hosted"); + assert.equal(preset.authMode, "none"); + assert.deepEqual(preset.kinds, ["agent", "image", "video", "audio", "vision"]); + assert.deepEqual(preset.stages, { + agent: [{ paths: ["/chat/completions"], protocol: "openai" }], + image: [ + { paths: ["/images/generations", "/images/edits"], protocol: "openai" }, + { + paths: ["/images/segmentations", "/videos/segmentations"], + protocol: "vllm_omni_segmentation", + }, + ], + video: [ + { paths: ["/videos"], protocol: "vllm_omni" }, + { + paths: ["/images/segmentations", "/videos/segmentations"], + protocol: "vllm_omni_segmentation", + }, + { paths: ["/videos/depth"], protocol: "vllm_omni_depth" }, + ], + audio: [ + { paths: ["/audio/speech"], protocol: "openai" }, + { paths: ["/audio/speech"], protocol: "vllm_omni_music" }, + { paths: ["/audio/transcriptions"], protocol: "vllm_omni_score" }, + ], + vision: [ + { + paths: ["/images/segmentations", "/videos/segmentations"], + protocol: "vllm_omni_segmentation", + }, + ], + }); + for (const kind of ["agent", "image", "video", "audio", "vision"] as const) { + assert.equal(presetProtocol(preset, kind), preset.stages![kind]![0]!.protocol); + } + // A saved specialized stage keeps its protocol; only an unknown one falls + // back to the kind's first stage. + assert.equal(presetProtocol(preset, "audio", "vllm_omni_music"), "vllm_omni_music"); + assert.equal(presetProtocol(preset, "audio", "vllm_omni_depth"), "openai"); + // The retired per-stage presets leave exactly one entry per kind behind. + for (const kind of ["agent", "image", "video", "audio", "vision"] as const) { + const omni = providerOptions(kind).filter((item) => item.id.startsWith("vllm-omni")); + assert.deepEqual(omni.map((item) => item.id), [LOCAL_OMNI_PRESET_ID]); + assert.equal(omni[0]?.group, getActiveLocale() === "en-US" ? "vLLM-Omni compatible" : "vLLM-Omni 兼容"); + } +}); + +test("saved self-hosted vLLM-Omni connections resolve to the local service", () => { + const preset = PROVIDER_PRESETS.find((item) => item.id === LOCAL_OMNI_PRESET_ID)!; + const saved = (protocol: ModelConfig["protocol"], kind: ModelConfig["kind"]): ModelConfig => ({ + ...preset, id: `saved-${protocol}`, kind, protocol, modelId: "m", + inputRules: { profile: "", allowedKinds: [], maxImages: 0, maxVideos: 0, maxAudios: 0, videoModes: [] }, + }); + // Every protocol the retired per-stage presets wrote must keep its name. + for (const [protocol, kind] of [ + ["vllm_omni", "video"], + ["vllm_omni_music", "audio"], + ["vllm_omni_score", "audio"], + ["vllm_omni_depth", "video"], + ["vllm_omni_segmentation", "image"], + ["vllm_omni_segmentation", "video"], + ["vllm_omni_segmentation", "vision"], + ] as const) { + assert.equal(providerPresetFor(saved(protocol, kind)), LOCAL_OMNI_PRESET_ID); + } + // `openai` is shared with generic local services, so it only identifies the + // preset at a loopback address. + for (const kind of ["agent", "image", "audio"] as const) { + assert.equal(providerPresetFor(saved("openai", kind)), LOCAL_OMNI_PRESET_ID); + } + for (const url of ["http://192.168.1.5:8000/v1", "https://local.example/v1"]) { + assert.equal(providerPresetFor({ ...saved("openai", "audio"), url }), "custom"); + } + // A hosted connection with another URL keeps reading as custom; the same + // localhost URL still resolves to the local service. + assert.equal(providerPresetFor({ ...saved("vllm_omni", "video"), connectionType: "api", url: "https://elsewhere.test/v1" }), "custom"); + assert.equal(providerPresetFor({ ...saved("vllm_omni", "video"), connectionType: "api" }), LOCAL_OMNI_PRESET_ID); +}); + +test("the local vLLM-Omni service reads in both languages", () => { + const preset = PROVIDER_PRESETS.find((item) => item.id === LOCAL_OMNI_PRESET_ID)!; + const previous = getActiveLocale(); + try { + for (const [locale, name, label] of [ + ["zh-CN", "vLLM-Omni 本地服务", "本地服务"], + ["en-US", "vLLM-Omni local service", "Local service"], + ] as const) { + setActiveLocale(locale); + const option = providerOptions("video").find((item) => item.id === preset.id); + assert.equal(option?.name, name); + assert.equal(option?.optionLabel, label); + } + } finally { + setActiveLocale(previous); + } +});