Files
OmniRoute/open-sse/services/dashscopeTextModels.ts
Praveen K Palaniswamy 65e81158ab fix(ollama): route models by advertised capability (#11088)
Landed with the design call resolved per the owner's pick — **option 1**: the synced store is now endpoint-agnostic (persistDiscoveredModels and managedModelImport no longer drop non-chat models at write time), and chat selectability moved to read time (auto-pool expansion in autoStrategy applies filterChatSelectableModels; the models-route projection already had its chatOnly filter). Your discovery test now passes end-to-end (3/3): /api/show capabilities persist per connection and image/embedding requests route through the advertising host.

Reconciliation notes: conflicted areas merged onto the current tip (adobe discovery import, requestedModel preflight signature, resolvedProvider fast-path coexists with the synced-route override — explicit resolution wins); carried base-red drains (#10055 memoization, #11071 test variants) dropped as already-landed; the managed-model-import exclusion test was propagated to the new contract (image/video models persist; the read filter still hides them from chat pickers — pinned by a new assertion). Full battery: 205/206 focused (the one red is a confirmed periodic-timer timing flake on the loaded devbox — 20/20 isolated), autoCombo vitest 30/30, combo suites 46/46, gates + typecheck clean.

Thank you @yourspraveen — the capability probe + routing design was right; it just needed the store contract opened up. Fixes #11087.
2026-08-23 11:45:01 -03:00

110 lines
4.0 KiB
TypeScript

/**
* @file dashscopeTextModels.ts
* @description DashScope / Alibaba Model Studio text and vision model ID heuristics.
*
* @changes
* - [2026-07-25] [Composer] - Add alibabafree text combo name detection for strict allowlist routing
* - [2026-07-25] [Composer] - Add multimodal and audio model detection for free-tier combos
* - [2026-07-25] [Composer] - Add vision/media model detection for alibabafreevision
* - [2026-07-25] [Composer] - Extract DashScope text-model filter for open-sse consumers
*/
const DASHSCOPE_TEXT_MODEL_PREFIXES = [
"qwen",
"qwq-",
"deepseek-",
"glm-",
"kimi-",
"minimax-",
] as const;
const DASHSCOPE_VISION_MODEL_PREFIXES = ["wan", "qwen-image", "happyhorse", "z-image"] as const;
const DASHSCOPE_NON_TEXT_MODEL_TOKEN =
/(?:^|[-_.\/])(?:asr|audio|captioner|embedding|image|livetranslate|omni|ocr|realtime|rerank|s2s|speech|tts|video|vl)(?:$|[-_.\/])/i;
const DASHSCOPE_VISION_MODEL_TOKEN =
/(?:^|[-_.\/])(?:i2v|t2v|r2v|vace|kf2v|videoedit|animate|image-edit)(?:$|[-_.\/])/i;
export function isDashscopeTextModelId(value: unknown): boolean {
if (typeof value !== "string") return false;
const modelId = value.trim().toLowerCase();
if (!modelId || DASHSCOPE_NON_TEXT_MODEL_TOKEN.test(modelId)) return false;
return DASHSCOPE_TEXT_MODEL_PREFIXES.some((prefix) => modelId.startsWith(prefix));
}
export function isDashscopeVisionModelId(value: unknown): value is string {
if (typeof value !== "string") return false;
const modelId = value.trim().toLowerCase();
if (!modelId || isDashscopeTextModelId(modelId)) return false;
return (
DASHSCOPE_VISION_MODEL_PREFIXES.some((prefix) => modelId.startsWith(prefix)) ||
DASHSCOPE_VISION_MODEL_TOKEN.test(modelId)
);
}
const DASHSCOPE_AUDIO_PREFIXES = [
"cosyvoice",
"fun-asr",
"qwen-audio",
"qwen-voice",
"voice-enrollment",
] as const;
const DASHSCOPE_AUDIO_MODEL_TOKEN =
/(?:^|[-_.\/])(?:asr|tts|livetranslate|captioner|speech|voice-design|voice-enrollment)(?:$|[-_.\/])/i;
const DASHSCOPE_MULTIMODAL_MODEL_TOKEN = /(?:^|[-_.\/])omni(?:$|[-_.\/])/i;
export function isDashscopeAudioModelId(value: unknown): value is string {
if (typeof value !== "string") return false;
const modelId = value.trim().toLowerCase();
if (!modelId) return false;
return (
DASHSCOPE_AUDIO_PREFIXES.some((prefix) => modelId.startsWith(prefix)) ||
DASHSCOPE_AUDIO_MODEL_TOKEN.test(modelId)
);
}
export function isDashscopeMultimodalModelId(value: unknown): value is string {
if (typeof value !== "string") return false;
const modelId = value.trim().toLowerCase();
if (!modelId || isDashscopeAudioModelId(modelId) || isDashscopeVisionModelId(modelId)) {
return false;
}
return DASHSCOPE_MULTIMODAL_MODEL_TOKEN.test(modelId);
}
export function isAlibabaFreeTierTextComboName(comboName: string | null | undefined): boolean {
if (!comboName) return false;
const normalized = comboName.trim().toLowerCase();
if (
isAlibabaFreeTierVisionComboName(normalized) ||
isAlibabaFreeTierMultimodalComboName(normalized) ||
isAlibabaFreeTierAudioComboName(normalized)
) {
return false;
}
return normalized === "alibabafree" || normalized.endsWith("alibabafree");
}
export function isAlibabaFreeTierVisionComboName(comboName: string | null | undefined): boolean {
if (!comboName) return false;
const normalized = comboName.trim().toLowerCase();
return normalized === "alibabafreevision" || normalized.endsWith("freevision");
}
export function isAlibabaFreeTierMultimodalComboName(
comboName: string | null | undefined
): boolean {
if (!comboName) return false;
const normalized = comboName.trim().toLowerCase();
return normalized === "alibabafreemultimodal" || normalized.endsWith("freemultimodal");
}
export function isAlibabaFreeTierAudioComboName(comboName: string | null | undefined): boolean {
if (!comboName) return false;
const normalized = comboName.trim().toLowerCase();
return normalized === "alibabafreeaudio" || normalized.endsWith("freeaudio");
}