jeopi-catalog 16.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +523 -0
- package/README.md +43 -0
- package/dist/types/build.d.ts +3 -0
- package/dist/types/compat/anthropic.d.ts +11 -0
- package/dist/types/compat/apply.d.ts +7 -0
- package/dist/types/compat/devin.d.ts +9 -0
- package/dist/types/compat/openai.d.ts +28 -0
- package/dist/types/discovery/antigravity.d.ts +70 -0
- package/dist/types/discovery/codex.d.ts +38 -0
- package/dist/types/discovery/cursor-gen/agent_pb.d.ts +13022 -0
- package/dist/types/discovery/cursor.d.ts +23 -0
- package/dist/types/discovery/devin-gen/buf/validate/validate_pb.d.ts +1715 -0
- package/dist/types/discovery/devin-gen/exa/analytics_pb/analytics_pb.d.ts +693 -0
- package/dist/types/discovery/devin-gen/exa/api_server_pb/api_server_pb.d.ts +9158 -0
- package/dist/types/discovery/devin-gen/exa/auth_pb/auth_pb.d.ts +52 -0
- package/dist/types/discovery/devin-gen/exa/auto_cascade_common_pb/auto_cascade_common_pb.d.ts +276 -0
- package/dist/types/discovery/devin-gen/exa/bug_checker_pb/bug_checker_pb.d.ts +78 -0
- package/dist/types/discovery/devin-gen/exa/cascade_plugins_pb/cascade_plugins_pb.d.ts +999 -0
- package/dist/types/discovery/devin-gen/exa/chat_pb/chat_pb.d.ts +1704 -0
- package/dist/types/discovery/devin-gen/exa/code_edit/code_edit_pb/code_edit_pb.d.ts +656 -0
- package/dist/types/discovery/devin-gen/exa/codeium_common_pb/codeium_common_pb.d.ts +15014 -0
- package/dist/types/discovery/devin-gen/exa/context_module_pb/context_module_pb.d.ts +607 -0
- package/dist/types/discovery/devin-gen/exa/cortex_pb/cortex_pb.d.ts +11830 -0
- package/dist/types/discovery/devin-gen/exa/diff_action_pb/diff_action_pb.d.ts +248 -0
- package/dist/types/discovery/devin-gen/exa/index_pb/index_pb.d.ts +1747 -0
- package/dist/types/discovery/devin-gen/exa/knowledge_base_pb/knowledge_base_pb.d.ts +509 -0
- package/dist/types/discovery/devin-gen/exa/language_server_pb/language_server_pb.d.ts +9048 -0
- package/dist/types/discovery/devin-gen/exa/opensearch_clients_pb/opensearch_clients_pb.d.ts +1760 -0
- package/dist/types/discovery/devin-gen/exa/prompt_pb/prompt_pb.d.ts +286 -0
- package/dist/types/discovery/devin-gen/exa/reactive_component_pb/reactive_component_pb.d.ts +405 -0
- package/dist/types/discovery/devin-gen/exa/trust_pb/trust_pb.d.ts +582 -0
- package/dist/types/discovery/devin.d.ts +24 -0
- package/dist/types/discovery/gemini.d.ts +25 -0
- package/dist/types/discovery/gitlab-duo-workflow.d.ts +30 -0
- package/dist/types/discovery/index.d.ts +5 -0
- package/dist/types/discovery/openai-compatible.d.ts +74 -0
- package/dist/types/effort.d.ts +9 -0
- package/dist/types/fireworks-model-id.d.ts +23 -0
- package/dist/types/hosts.d.ts +137 -0
- package/dist/types/identity/bundled.d.ts +3 -0
- package/dist/types/identity/classify.d.ts +69 -0
- package/dist/types/identity/dialect.d.ts +3 -0
- package/dist/types/identity/family.d.ts +139 -0
- package/dist/types/identity/id.d.ts +12 -0
- package/dist/types/identity/index.d.ts +8 -0
- package/dist/types/identity/markers.d.ts +4 -0
- package/dist/types/identity/priority.d.ts +1 -0
- package/dist/types/identity/reference.d.ts +23 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/model-cache.d.ts +17 -0
- package/dist/types/model-manager.d.ts +68 -0
- package/dist/types/model-thinking.d.ts +79 -0
- package/dist/types/models.d.ts +12 -0
- package/dist/types/provider-models/bundled-references.d.ts +11 -0
- package/dist/types/provider-models/descriptor-types.d.ts +74 -0
- package/dist/types/provider-models/descriptors.d.ts +427 -0
- package/dist/types/provider-models/google.d.ts +27 -0
- package/dist/types/provider-models/index.d.ts +6 -0
- package/dist/types/provider-models/ollama.d.ts +9 -0
- package/dist/types/provider-models/openai-compat.d.ts +450 -0
- package/dist/types/provider-models/special.d.ts +33 -0
- package/dist/types/types.d.ts +656 -0
- package/dist/types/utils.d.ts +20 -0
- package/dist/types/variant-collapse.d.ts +133 -0
- package/dist/types/wire/codex.d.ts +26 -0
- package/dist/types/wire/coreweave.d.ts +12 -0
- package/dist/types/wire/gemini-headers.d.ts +37 -0
- package/dist/types/wire/github-copilot.d.ts +45 -0
- package/package.json +101 -0
- package/src/build.ts +47 -0
- package/src/compat/anthropic.ts +93 -0
- package/src/compat/apply.ts +15 -0
- package/src/compat/devin.ts +12 -0
- package/src/compat/openai.ts +689 -0
- package/src/discovery/antigravity.ts +253 -0
- package/src/discovery/codex.ts +371 -0
- package/src/discovery/cursor-gen/agent_pb.ts +15274 -0
- package/src/discovery/cursor.ts +314 -0
- package/src/discovery/devin-gen/buf/validate/validate_pb.ts +1862 -0
- package/src/discovery/devin-gen/exa/analytics_pb/analytics_pb.ts +871 -0
- package/src/discovery/devin-gen/exa/api_server_pb/api_server_pb.ts +11083 -0
- package/src/discovery/devin-gen/exa/auth_pb/auth_pb.ts +71 -0
- package/src/discovery/devin-gen/exa/auto_cascade_common_pb/auto_cascade_common_pb.ts +348 -0
- package/src/discovery/devin-gen/exa/bug_checker_pb/bug_checker_pb.ts +103 -0
- package/src/discovery/devin-gen/exa/cascade_plugins_pb/cascade_plugins_pb.ts +1198 -0
- package/src/discovery/devin-gen/exa/chat_pb/chat_pb.ts +2063 -0
- package/src/discovery/devin-gen/exa/code_edit/code_edit_pb/code_edit_pb.ts +810 -0
- package/src/discovery/devin-gen/exa/codeium_common_pb/codeium_common_pb.ts +18354 -0
- package/src/discovery/devin-gen/exa/context_module_pb/context_module_pb.ts +732 -0
- package/src/discovery/devin-gen/exa/cortex_pb/cortex_pb.ts +14277 -0
- package/src/discovery/devin-gen/exa/diff_action_pb/diff_action_pb.ts +312 -0
- package/src/discovery/devin-gen/exa/index_pb/index_pb.ts +2106 -0
- package/src/discovery/devin-gen/exa/knowledge_base_pb/knowledge_base_pb.ts +623 -0
- package/src/discovery/devin-gen/exa/language_server_pb/language_server_pb.ts +10918 -0
- package/src/discovery/devin-gen/exa/opensearch_clients_pb/opensearch_clients_pb.ts +2125 -0
- package/src/discovery/devin-gen/exa/prompt_pb/prompt_pb.ts +361 -0
- package/src/discovery/devin-gen/exa/reactive_component_pb/reactive_component_pb.ts +450 -0
- package/src/discovery/devin-gen/exa/trust_pb/trust_pb.ts +712 -0
- package/src/discovery/devin.ts +151 -0
- package/src/discovery/gemini.ts +260 -0
- package/src/discovery/gitlab-duo-workflow.ts +855 -0
- package/src/discovery/index.ts +5 -0
- package/src/discovery/openai-compatible.ts +249 -0
- package/src/effort.ts +16 -0
- package/src/fireworks-model-id.ts +50 -0
- package/src/hosts.ts +129 -0
- package/src/identity/bundled.ts +28 -0
- package/src/identity/classify.ts +214 -0
- package/src/identity/dialect.ts +42 -0
- package/src/identity/family.ts +296 -0
- package/src/identity/id.ts +81 -0
- package/src/identity/index.ts +8 -0
- package/src/identity/markers.ts +49 -0
- package/src/identity/priority.ts +57 -0
- package/src/identity/reference.ts +148 -0
- package/src/index.ts +17 -0
- package/src/model-cache.ts +171 -0
- package/src/model-manager.ts +520 -0
- package/src/model-thinking.ts +760 -0
- package/src/models.json +88898 -0
- package/src/models.json.d.ts +9 -0
- package/src/models.ts +64 -0
- package/src/provider-models/bundled-references.ts +58 -0
- package/src/provider-models/descriptor-types.ts +79 -0
- package/src/provider-models/descriptors.ts +503 -0
- package/src/provider-models/google.ts +107 -0
- package/src/provider-models/index.ts +6 -0
- package/src/provider-models/ollama.ts +172 -0
- package/src/provider-models/openai-compat.ts +4283 -0
- package/src/provider-models/special.ts +159 -0
- package/src/types.ts +786 -0
- package/src/utils.ts +69 -0
- package/src/variant-collapse.ts +1065 -0
- package/src/wire/codex.ts +43 -0
- package/src/wire/coreweave.ts +51 -0
- package/src/wire/gemini-headers.ts +74 -0
- package/src/wire/github-copilot.ts +121 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { modelFamilyToken } from "./family";
|
|
2
|
+
|
|
3
|
+
export type Dialect =
|
|
4
|
+
| "glm"
|
|
5
|
+
| "hermes"
|
|
6
|
+
| "kimi"
|
|
7
|
+
| "xml"
|
|
8
|
+
| "anthropic"
|
|
9
|
+
| "deepseek"
|
|
10
|
+
| "harmony"
|
|
11
|
+
| "qwen3"
|
|
12
|
+
| "gemini"
|
|
13
|
+
| "gemma"
|
|
14
|
+
| "minimax";
|
|
15
|
+
|
|
16
|
+
export const FALLBACK_DIALECT: Dialect = "xml";
|
|
17
|
+
|
|
18
|
+
export function preferredDialect(modelId: string): Dialect {
|
|
19
|
+
switch (modelFamilyToken(modelId)) {
|
|
20
|
+
case "anthropic":
|
|
21
|
+
return "anthropic";
|
|
22
|
+
case "glm":
|
|
23
|
+
return "glm";
|
|
24
|
+
case "gemini":
|
|
25
|
+
return "gemini";
|
|
26
|
+
case "gemma":
|
|
27
|
+
return "gemma";
|
|
28
|
+
case "kimi":
|
|
29
|
+
return "kimi";
|
|
30
|
+
case "qwen":
|
|
31
|
+
return "qwen3";
|
|
32
|
+
case "deepseek":
|
|
33
|
+
return "deepseek";
|
|
34
|
+
case "minimax":
|
|
35
|
+
return "minimax";
|
|
36
|
+
case "openai":
|
|
37
|
+
case "gpt-oss":
|
|
38
|
+
return "harmony";
|
|
39
|
+
default:
|
|
40
|
+
return FALLBACK_DIALECT;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-family id predicates: the shared vocabulary for "is this id a member
|
|
3
|
+
* of family X" checks that gate wire-level behavior across hosts (a Kimi or
|
|
4
|
+
* DeepSeek model keeps its quirks no matter which OpenAI-compatible proxy
|
|
5
|
+
* serves it). Looser per-feature heuristics (e.g. stream-markup healing)
|
|
6
|
+
* deliberately keep their own patterns — only provably-shared matchers live
|
|
7
|
+
* here.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
bareModelId,
|
|
12
|
+
isAnthropicAdaptiveGenAtLeast,
|
|
13
|
+
isFableOrMythos,
|
|
14
|
+
parseAnthropicModel,
|
|
15
|
+
parseGlmModel,
|
|
16
|
+
parseKnownModel,
|
|
17
|
+
parseOpenAIModel,
|
|
18
|
+
semverGte,
|
|
19
|
+
} from "./classify";
|
|
20
|
+
|
|
21
|
+
/** Bounded process-lifetime cache memo helper. */
|
|
22
|
+
function memo<T>(fn: (modelId: string) => T): (modelId: string) => T {
|
|
23
|
+
const cache = new Map<string, T>();
|
|
24
|
+
return (modelId: string) => {
|
|
25
|
+
if (cache.has(modelId)) {
|
|
26
|
+
return cache.get(modelId) as T;
|
|
27
|
+
}
|
|
28
|
+
const result = fn(modelId);
|
|
29
|
+
cache.set(modelId, result);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Kimi family ids in any namespace form (`moonshotai/kimi-*`, `kimi-k2.6`, `vendor/kimi.x`). */
|
|
35
|
+
export const isKimiModelId = memo((modelId: string): boolean => {
|
|
36
|
+
return modelId.includes("moonshotai/kimi") || /(^|\/)kimi[-.]/i.test(modelId);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/** Kimi K2.6 specifically, including router ids that spell the version `k2p6`. */
|
|
40
|
+
export const isKimiK26ModelId = memo((modelId: string): boolean => {
|
|
41
|
+
return /(^|\/)kimi-k2(?:\.6|p6)(?:[-:]|$)/i.test(modelId);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/** Claude ids in any namespace form (`claude-*`, `vendor/claude.x`). */
|
|
45
|
+
export const isClaudeModelId = memo((modelId: string): boolean => {
|
|
46
|
+
return /(^|\/)claude[-.]/i.test(modelId);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
/** `anthropic/`-namespaced ids (aggregator catalogs like OpenRouter). */
|
|
50
|
+
export const isAnthropicNamespacedModelId = memo((modelId: string): boolean => {
|
|
51
|
+
return /(^|\/)anthropic\//i.test(modelId);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
/** Qwen family ids (substring match — Qwen SKUs have no stable prefix shape). */
|
|
55
|
+
export const isQwenModelId = memo((modelId: string): boolean => {
|
|
56
|
+
return modelId.toLowerCase().includes("qwen");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/** Gemma open-weights family (`gemma-3-27b-it`, `google/gemma-4-E2B-it`, `gemma2-9b`). */
|
|
60
|
+
export const isGemmaModelId = memo((modelId: string): boolean => {
|
|
61
|
+
return /(^|\/)gemma[-.]?\d/i.test(modelId);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
/** DeepSeek family by id or display name (proxies often rename the id but keep the name). */
|
|
65
|
+
export const isDeepseekModelIdOrName = memo((value: string): boolean => {
|
|
66
|
+
return value.toLowerCase().includes("deepseek");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
/** Xiaomi MiMo family by id or display name. */
|
|
70
|
+
export const isMimoModelIdOrName = memo((value: string): boolean => {
|
|
71
|
+
return value.toLowerCase().includes("mimo");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const GROK_EFFORT_CAPABLE_PREFIXES = ["grok-3-mini", "grok-4.20-multi-agent", "grok-4.3"] as const;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Grok SKUs that expose the wire `reasoning.effort` dial. Other Grok reasoners
|
|
78
|
+
* (e.g. `grok-build`, `grok-4.20-0309-reasoning`) think natively but reject the
|
|
79
|
+
* param, so callers must omit reasoning effort for them.
|
|
80
|
+
*/
|
|
81
|
+
export const isGrokReasoningEffortCapable = memo((modelId: string): boolean => {
|
|
82
|
+
const bare = bareModelId(modelId).trim().toLowerCase();
|
|
83
|
+
if (!bare) return false;
|
|
84
|
+
return GROK_EFFORT_CAPABLE_PREFIXES.some(prefix => bare.startsWith(prefix));
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* MiniMax M2-generation family (M2, M2.1, M2.5, M2.7, including `-highspeed`/
|
|
89
|
+
* `-lightning`/`-her`/`-turbo` variants, dotless aliases like `minimax-m21`,
|
|
90
|
+
* and short `minimax/m2-…` ids on aggregator hosts). Underlying model accepts
|
|
91
|
+
* only `low|medium|high` for `reasoning_effort` and 400s on `minimal`,
|
|
92
|
+
* `xhigh`, or `none` — so hosts whose default effort map otherwise lowers
|
|
93
|
+
* `minimal` to `none` (Fireworks) or expects the full 5-tier scale must
|
|
94
|
+
* clamp instead. Excludes M1, M3, MiniMax-Text-01, music, hailuo, voice ids.
|
|
95
|
+
*/
|
|
96
|
+
export const isMinimaxM2FamilyModelId = memo((modelId: string): boolean => {
|
|
97
|
+
const lower = modelId.toLowerCase();
|
|
98
|
+
if (!lower.includes("minimax")) return false;
|
|
99
|
+
// Boundary-delimited `m2` token followed by zero or more digits (dotless
|
|
100
|
+
// variants like `m21`/`m25`/`m27`) and an optional dotted minor version.
|
|
101
|
+
return /(?:^|[/.-])m2\d*(?:[.-]\d+)?(?:[-.:_]|$)/i.test(lower);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
/** MiniMax M3 family ids in bundled/default and aggregator namespace forms. */
|
|
105
|
+
export const isMinimaxM3FamilyModelId = memo((modelId: string): boolean => {
|
|
106
|
+
const lower = modelId.toLowerCase();
|
|
107
|
+
if (!lower.includes("minimax")) return false;
|
|
108
|
+
return /(?:^|[/._-])(?:minimax[/._-])?m3(?:[-.:_]|$)/i.test(lower);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* OpenAI gpt-oss family (`gpt-oss-20b`, `gpt-oss-120b`, `gpt-oss:120b`,
|
|
113
|
+
* `vendor/gpt-oss-…`). The Harmony reasoning format only accepts
|
|
114
|
+
* `low|medium|high` for `reasoning_effort` and rejects `minimal`, `xhigh`,
|
|
115
|
+
* and `none`.
|
|
116
|
+
*/
|
|
117
|
+
export const isOpenAIGptOssModelId = memo((modelId: string): boolean => {
|
|
118
|
+
return /(^|\/)gpt-oss[-:]/i.test(modelId);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
/** OpenAI model ids (gpt-*, o1-*, o3-*, o4-*, or prefixed with openai/). */
|
|
122
|
+
export const isOpenAIModelId = memo((modelId: string): boolean => {
|
|
123
|
+
return /(^|\/)(gpt|o1|o3|o4)[-.]/i.test(modelId) || modelId.toLowerCase().includes("openai/");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
/** OpenAI models at or above the gpt-5.4 wire generation, keyed off the parsed version. */
|
|
127
|
+
const isOpenAIWireGen54Plus = memo((modelId: string): boolean => {
|
|
128
|
+
const parsed = parseOpenAIModel(bareModelId(modelId));
|
|
129
|
+
if (!parsed) return false;
|
|
130
|
+
return semverGte(parsed.version, "5.4");
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* OpenAI Codex models that honor `reasoning.context: "all_turns"` (full
|
|
135
|
+
* cross-turn reasoning replay). The `reasoning.context` field itself exists for
|
|
136
|
+
* the whole gpt-5/o-series family, but the `all_turns` value is only accepted
|
|
137
|
+
* from gpt-5.4 onward; earlier ids (`gpt-5.1-codex`, `gpt-5.3-codex`, and
|
|
138
|
+
* `gpt-5.3-codex-spark`) reject it with
|
|
139
|
+
* `Unsupported value: 'all_turns' is not supported with this model`. Version
|
|
140
|
+
* floor (not an allowlist) so 5.6/6.x inherit support automatically. Callers
|
|
141
|
+
* fall back to omitting `context`, letting the server default to `current_turn`.
|
|
142
|
+
*/
|
|
143
|
+
export const supportsAllTurnsReasoningContext = isOpenAIWireGen54Plus;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* OpenAI Codex models that accept `reasoning.summary`. Shares the gpt-5.4 wire
|
|
147
|
+
* floor with {@link supportsAllTurnsReasoningContext}: earlier Codex ids
|
|
148
|
+
* (`gpt-5.1-codex`, `gpt-5.3-codex`, `gpt-5.3-codex-spark`) reject the field
|
|
149
|
+
* with `Unsupported parameter: 'reasoning.summary' is not supported with this
|
|
150
|
+
* model`. Callers omit `summary` for unsupported ids, letting the server skip
|
|
151
|
+
* the human-readable summary stream.
|
|
152
|
+
*/
|
|
153
|
+
export const supportsCodexReasoningSummary = isOpenAIWireGen54Plus;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Reasoning-capable GLM coding SKUs: glm-4.5 and up on the base / `-air` /
|
|
157
|
+
* `-turbo` lines. Excludes the vision (`…v`) shape, the non-reasoning
|
|
158
|
+
* `-flash`/`-flashx`/`-preview` variants, and pre-4.5 ids. Matching the family
|
|
159
|
+
* keeps newly-bumped integers (`glm-5.3`, `glm-6`, …) covered without a per-id
|
|
160
|
+
* allowlist.
|
|
161
|
+
*/
|
|
162
|
+
export const isReasoningGlmModelId = memo((modelId: string): boolean => {
|
|
163
|
+
const glm = parseGlmModel(bareModelId(modelId));
|
|
164
|
+
if (!glm || glm.vision) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
if (glm.variant !== "base" && glm.variant !== "air" && glm.variant !== "turbo") {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
return semverGte(glm.version, "4.5");
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
/** GLM-5.2+ coding SKUs accept `reasoning_effort` in addition to binary thinking. */
|
|
174
|
+
export const isGlm52ReasoningEffortModelId = memo((modelId: string): boolean => {
|
|
175
|
+
const glm = parseGlmModel(bareModelId(modelId));
|
|
176
|
+
if (!glm || glm.vision) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
if (glm.variant !== "base" && glm.variant !== "air" && glm.variant !== "turbo") {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
return semverGte(glm.version, "5.2");
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
/** GLM vision SKUs — the `v` that attaches to the version (`glm-4v`, `glm-4.5v`). */
|
|
186
|
+
export const isGlmVisionModelId = memo((modelId: string): boolean => {
|
|
187
|
+
return parseGlmModel(bareModelId(modelId))?.vision === true;
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Coarse vendor-lineage token for "are two models the same family?" checks
|
|
192
|
+
* (e.g. picking a cross-family reviewer). All Claude point releases share a token,
|
|
193
|
+
* Claude and GPT differ; namespace prefixes and aggregator mirrors fold onto the
|
|
194
|
+
* lineage via {@link parseKnownModel}'s `bareModelId` normalization. Opaque and
|
|
195
|
+
* comparison-only — not a stable key to persist, since the vocabulary tracks new
|
|
196
|
+
* releases. Returns `""` for ids it cannot classify; callers fall back to the provider.
|
|
197
|
+
*
|
|
198
|
+
* Vendor-only by design: a model's kind/variant (opus vs sonnet, codex vs base) is
|
|
199
|
+
* collapsed onto the single vendor token; use {@link parseKnownModel} for finer breakdowns.
|
|
200
|
+
*/
|
|
201
|
+
export const modelFamilyToken = memo((modelId: string): string => {
|
|
202
|
+
const parsed = parseKnownModel(modelId);
|
|
203
|
+
if (parsed.family !== "unknown") return parsed.family;
|
|
204
|
+
if (isClaudeModelId(modelId) || isAnthropicNamespacedModelId(modelId)) return "anthropic";
|
|
205
|
+
if (isOpenAIModelId(modelId)) return "openai";
|
|
206
|
+
if (isKimiModelId(modelId)) return "kimi";
|
|
207
|
+
if (isQwenModelId(modelId)) return "qwen";
|
|
208
|
+
if (isMinimaxM2FamilyModelId(modelId) || isMinimaxM3FamilyModelId(modelId)) return "minimax";
|
|
209
|
+
if (isOpenAIGptOssModelId(modelId)) return "gpt-oss";
|
|
210
|
+
if (isDeepseekModelIdOrName(modelId)) return "deepseek";
|
|
211
|
+
if (isMimoModelIdOrName(modelId)) return "mimo";
|
|
212
|
+
if (isGemmaModelId(modelId)) return "gemma";
|
|
213
|
+
if (parseGlmModel(bareModelId(modelId))) return "glm";
|
|
214
|
+
return "";
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Adaptive thinking `display` is supported starting with Claude Opus 4.7+,
|
|
219
|
+
* Sonnet 5+, and the Claude Fable/Mythos 5 generation. Older adaptive-thinking
|
|
220
|
+
* models (Opus 4.6, Sonnet 4.6) reject the field. Classifier-based, so dotted
|
|
221
|
+
* and dashed version forms both match while bare dated ids
|
|
222
|
+
* (`claude-opus-4-20250514` = Opus 4.0) stay excluded.
|
|
223
|
+
*/
|
|
224
|
+
export const supportsAdaptiveThinkingDisplay = memo((modelId: string): boolean => {
|
|
225
|
+
const parsed = parseAnthropicModel(bareModelId(modelId));
|
|
226
|
+
return parsed !== null && isAnthropicAdaptiveGenAtLeast(parsed, "4.7");
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Returns true for Anthropic models with Opus 4.7+, Sonnet 5+, and Fable/Mythos 5+
|
|
231
|
+
* API restrictions:
|
|
232
|
+
* - Sampling parameters (temperature/top_p/top_k) return 400 error
|
|
233
|
+
* - Thinking content is omitted by default (needs display: "summarized")
|
|
234
|
+
*/
|
|
235
|
+
export const hasOpus47ApiRestrictions = memo((modelId: string): boolean => {
|
|
236
|
+
const parsed = parseAnthropicModel(bareModelId(modelId));
|
|
237
|
+
return parsed !== null && isAnthropicAdaptiveGenAtLeast(parsed, "4.7");
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Mid-conversation `role: "system"` messages (system instructions appended at
|
|
242
|
+
* non-first positions in the `messages` array) are supported starting with
|
|
243
|
+
* Claude Opus 4.8+, Sonnet 5+, and the Claude Fable/Mythos 5 generation.
|
|
244
|
+
* Earlier Claude models reject the role.
|
|
245
|
+
* @see https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages
|
|
246
|
+
*/
|
|
247
|
+
export const supportsMidConversationSystemMessages = memo((modelId: string): boolean => {
|
|
248
|
+
const parsed = parseAnthropicModel(bareModelId(modelId));
|
|
249
|
+
return parsed !== null && isAnthropicAdaptiveGenAtLeast(parsed, "4.8");
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
export const isAnthropicFableOrMythosModel = memo((modelId: string): boolean => {
|
|
253
|
+
const parsed = parseAnthropicModel(bareModelId(modelId));
|
|
254
|
+
return parsed !== null && isFableOrMythos(parsed.kind);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
/** Thinking-variant token location inside a model id. */
|
|
258
|
+
export interface ThinkingVariantToken {
|
|
259
|
+
index: number;
|
|
260
|
+
length: number;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const THINKING_VARIANT_TOKEN_RE = /-(?:thinking|reasoner|reasoning)(?=$|[^a-z0-9])/gi;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Locates the first thinking-variant token (`-thinking`, `-reasoner`,
|
|
267
|
+
* `-reasoning`; trailing or infix) in a model id. The token ends at the id
|
|
268
|
+
* end or any non-alphanumeric boundary, and negated forms (`non-thinking`,
|
|
269
|
+
* `no-thinking`) never match — those name the NON-thinking SKU.
|
|
270
|
+
*/
|
|
271
|
+
export function findThinkingVariantToken(modelId: string): ThinkingVariantToken | undefined {
|
|
272
|
+
THINKING_VARIANT_TOKEN_RE.lastIndex = 0;
|
|
273
|
+
let match = THINKING_VARIANT_TOKEN_RE.exec(modelId);
|
|
274
|
+
while (match !== null) {
|
|
275
|
+
const preceding = /([a-z0-9]+)$/i.exec(modelId.slice(0, match.index))?.[1]?.toLowerCase();
|
|
276
|
+
if (preceding !== "non" && preceding !== "no") {
|
|
277
|
+
return { index: match.index, length: match[0].length };
|
|
278
|
+
}
|
|
279
|
+
match = THINKING_VARIANT_TOKEN_RE.exec(modelId);
|
|
280
|
+
}
|
|
281
|
+
return undefined;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Removes the located thinking-variant token: `kimi-k2-thinking` → `kimi-k2`,
|
|
286
|
+
* `mimo-v2-flash-thinking-original` → `mimo-v2-flash-original`,
|
|
287
|
+
* `grok-4.1-fast-reasoning` → `grok-4.1-fast`. Returns `undefined` when no
|
|
288
|
+
* token exists or nothing would remain. Callers MUST verify the result names
|
|
289
|
+
* a live model.
|
|
290
|
+
*/
|
|
291
|
+
export const stripThinkingVariantToken = memo((modelId: string): string | undefined => {
|
|
292
|
+
const token = findThinkingVariantToken(modelId);
|
|
293
|
+
if (!token) return undefined;
|
|
294
|
+
const stripped = modelId.slice(0, token.index) + modelId.slice(token.index + token.length);
|
|
295
|
+
return stripped.length > 0 ? stripped : undefined;
|
|
296
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const LEADING_BRACKETED_AFFIX_PATTERN = /^(?:\s*(?:\[|【)[^\]】]+(?:\]|】)\s*)+/u;
|
|
2
|
+
const TRAILING_BRACKETED_AFFIX_PATTERN = /(?:\s*(?:\[|【)[^\]】]+(?:\]|】)\s*)+$/u;
|
|
3
|
+
const MODEL_ID_SEGMENT_PATTERN = /[a-z0-9.:-]+/g;
|
|
4
|
+
const MODEL_FAMILY_PREFIX_PATTERN =
|
|
5
|
+
/^(claude|gemini|gpt|grok|glm|qwen|deepseek|kimi|mimo|doubao|ernie|gpt-oss|gemma|minimax|step|command|jamba|llama|o[1345])/i;
|
|
6
|
+
|
|
7
|
+
function normalizeModelIdWhitespace(value: string): string {
|
|
8
|
+
return value.trim().replace(/\s+/g, " ");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Ordering for model-like segments: longest first, ties broken lexicographically. */
|
|
12
|
+
function compareSegmentPreference(left: string, right: string): number {
|
|
13
|
+
return left.length !== right.length ? right.length - left.length : left.localeCompare(right);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getModelLikeIdSegments(modelId: string): string[] {
|
|
17
|
+
const matches = normalizeModelIdWhitespace(modelId).toLowerCase().match(MODEL_ID_SEGMENT_PATTERN);
|
|
18
|
+
if (!matches) return [];
|
|
19
|
+
const segments = new Set<string>();
|
|
20
|
+
for (const segment of matches) {
|
|
21
|
+
if (MODEL_FAMILY_PREFIX_PATTERN.test(segment) && /\d/.test(segment)) segments.add(segment);
|
|
22
|
+
}
|
|
23
|
+
return [...segments].sort(compareSegmentPreference);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getLongestModelLikeIdSegment(modelId: string): string | undefined {
|
|
27
|
+
const matches = normalizeModelIdWhitespace(modelId).toLowerCase().match(MODEL_ID_SEGMENT_PATTERN);
|
|
28
|
+
if (!matches) return undefined;
|
|
29
|
+
let best: string | undefined;
|
|
30
|
+
for (const segment of matches) {
|
|
31
|
+
if (
|
|
32
|
+
MODEL_FAMILY_PREFIX_PATTERN.test(segment) &&
|
|
33
|
+
/\d/.test(segment) &&
|
|
34
|
+
(best === undefined || compareSegmentPreference(segment, best) < 0)
|
|
35
|
+
) {
|
|
36
|
+
best = segment;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return best;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function hasBracketAffixMarker(value: string): boolean {
|
|
43
|
+
for (let index = 0; index < value.length; index++) {
|
|
44
|
+
const code = value.charCodeAt(index);
|
|
45
|
+
if (code === 91 || code === 93 || code === 0x3010 || code === 0x3011) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Strip reseller / wrapper tags that are injected as bracketed affixes around an
|
|
54
|
+
* upstream model id, e.g.
|
|
55
|
+
* "[Kiro] claude-opus-4-8" -> "claude-opus-4-8"
|
|
56
|
+
* "[gcli转] gemini-3.1-pro-preview [假流]" -> "gemini-3.1-pro-preview"
|
|
57
|
+
*
|
|
58
|
+
* Candidates are returned most-stripped first: both ends, then leading-only, then trailing-only.
|
|
59
|
+
*/
|
|
60
|
+
export function getBracketStrippedModelIdCandidates(modelId: string): string[] {
|
|
61
|
+
if (!hasBracketAffixMarker(modelId)) return [];
|
|
62
|
+
const normalized = normalizeModelIdWhitespace(modelId);
|
|
63
|
+
if (!normalized) return [];
|
|
64
|
+
|
|
65
|
+
const strippedLeading = normalized.replace(LEADING_BRACKETED_AFFIX_PATTERN, "");
|
|
66
|
+
const withoutLeading = normalizeModelIdWhitespace(strippedLeading);
|
|
67
|
+
const withoutTrailing = normalizeModelIdWhitespace(normalized.replace(TRAILING_BRACKETED_AFFIX_PATTERN, ""));
|
|
68
|
+
const withoutBoth = normalizeModelIdWhitespace(strippedLeading.replace(TRAILING_BRACKETED_AFFIX_PATTERN, ""));
|
|
69
|
+
|
|
70
|
+
const candidates = new Set<string>();
|
|
71
|
+
for (const candidate of [withoutBoth, withoutLeading, withoutTrailing]) {
|
|
72
|
+
if (candidate && candidate !== normalized) {
|
|
73
|
+
candidates.add(candidate);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return [...candidates];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function stripBracketedModelIdAffixes(modelId: string): string | undefined {
|
|
80
|
+
return getBracketStrippedModelIdCandidates(modelId)[0];
|
|
81
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trailing-marker vocabulary shared by canonical-id resolution and
|
|
3
|
+
* proxy-reference lookup. A "marker" is a routing/quantization/effort suffix
|
|
4
|
+
* a reseller or aggregator appends to an upstream model id
|
|
5
|
+
* (`-thinking`, `:nitro`, `-fp8`, …) that does not change model identity.
|
|
6
|
+
*/
|
|
7
|
+
const TRAILING_MARKERS = [
|
|
8
|
+
"thinking",
|
|
9
|
+
"customtools",
|
|
10
|
+
"high",
|
|
11
|
+
"low",
|
|
12
|
+
"medium",
|
|
13
|
+
"minimal",
|
|
14
|
+
"xhigh",
|
|
15
|
+
"free",
|
|
16
|
+
"cloud",
|
|
17
|
+
"exacto",
|
|
18
|
+
"nitro",
|
|
19
|
+
"original",
|
|
20
|
+
"optimized",
|
|
21
|
+
"nvfp4",
|
|
22
|
+
"fp8",
|
|
23
|
+
"fp4",
|
|
24
|
+
"bf16",
|
|
25
|
+
"int8",
|
|
26
|
+
"int4",
|
|
27
|
+
] as const;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Markers treated as identity-preserving ONLY when recovering bundled metadata
|
|
31
|
+
* for a proxied model id, never during canonical-id coalescing: Perplexity's
|
|
32
|
+
* `sonar-pro-search` is a distinct model from `sonar-pro`, so canonical
|
|
33
|
+
* resolution must not strip `search`, while a proxy id like
|
|
34
|
+
* `claude-opus-4-6-search` should still inherit the upstream pricing/limits.
|
|
35
|
+
*/
|
|
36
|
+
const REFERENCE_ONLY_TRAILING_MARKERS = ["search"] as const;
|
|
37
|
+
|
|
38
|
+
function buildTrailingMarkerPattern(markers: readonly string[]): RegExp {
|
|
39
|
+
return new RegExp(`[-:](?:${markers.join("|")})$`, "i");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Marker pattern used by canonical-id resolution (`search` excluded). */
|
|
43
|
+
export const CANONICAL_TRAILING_MARKER_PATTERN = buildTrailingMarkerPattern(TRAILING_MARKERS);
|
|
44
|
+
|
|
45
|
+
/** Marker pattern used by proxy-reference lookup (`search` included). */
|
|
46
|
+
export const REFERENCE_TRAILING_MARKER_PATTERN = buildTrailingMarkerPattern([
|
|
47
|
+
...TRAILING_MARKERS,
|
|
48
|
+
...REFERENCE_ONLY_TRAILING_MARKERS,
|
|
49
|
+
]);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const DEFAULT_MODEL_PROVIDER_ORDER = [
|
|
2
|
+
// First-party / native account providers. Prefer these over relays when the
|
|
3
|
+
// same upstream model is available in more than one place.
|
|
4
|
+
"openai-codex",
|
|
5
|
+
"anthropic",
|
|
6
|
+
"openai",
|
|
7
|
+
"google-gemini-cli",
|
|
8
|
+
"google",
|
|
9
|
+
"google-vertex",
|
|
10
|
+
"kimi-code",
|
|
11
|
+
"moonshot",
|
|
12
|
+
"qwen-portal",
|
|
13
|
+
"zai",
|
|
14
|
+
"xai-oauth",
|
|
15
|
+
"xai",
|
|
16
|
+
"mistral",
|
|
17
|
+
"deepseek",
|
|
18
|
+
"groq",
|
|
19
|
+
|
|
20
|
+
// High-quality aggregators / hosted inference providers.
|
|
21
|
+
"fireworks",
|
|
22
|
+
"cerebras",
|
|
23
|
+
"openrouter",
|
|
24
|
+
"aimlapi",
|
|
25
|
+
"together",
|
|
26
|
+
|
|
27
|
+
// Generic gateways and editor/proxy providers. These are useful when picked
|
|
28
|
+
// explicitly, but should not win ambiguous automatic role selection.
|
|
29
|
+
"alibaba-coding-plan",
|
|
30
|
+
"umans",
|
|
31
|
+
"google-antigravity",
|
|
32
|
+
"opencode-zen",
|
|
33
|
+
"gitlab-duo",
|
|
34
|
+
"opencode-go",
|
|
35
|
+
"kilo",
|
|
36
|
+
"vercel-ai-gateway",
|
|
37
|
+
"cloudflare-ai-gateway",
|
|
38
|
+
"nanogpt",
|
|
39
|
+
"github-copilot",
|
|
40
|
+
] as const;
|
|
41
|
+
|
|
42
|
+
function addProviderRank(rank: Map<string, number>, provider: string): void {
|
|
43
|
+
const normalized = provider.trim().toLowerCase();
|
|
44
|
+
if (!normalized || rank.has(normalized)) return;
|
|
45
|
+
rank.set(normalized, rank.size);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function buildModelProviderPriorityRank(configuredProviderOrder?: readonly string[]): Map<string, number> {
|
|
49
|
+
const rank = new Map<string, number>();
|
|
50
|
+
for (const provider of configuredProviderOrder ?? []) {
|
|
51
|
+
addProviderRank(rank, provider);
|
|
52
|
+
}
|
|
53
|
+
for (const provider of DEFAULT_MODEL_PROVIDER_ORDER) {
|
|
54
|
+
addProviderRank(rank, provider);
|
|
55
|
+
}
|
|
56
|
+
return rank;
|
|
57
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxy/reseller reference lookup: given a custom model id served through a
|
|
3
|
+
* proxy (`[Kiro] claude-opus-4-8`, `gpt-5.4:cloud`, `vendor/claude-sonnet-4-6-thinking`),
|
|
4
|
+
* find the bundled upstream model so missing pricing/capability metadata can be
|
|
5
|
+
* inherited while keeping the custom transport.
|
|
6
|
+
*
|
|
7
|
+
* Kept separate from canonical-id resolution (`./equivalence`): this lookup
|
|
8
|
+
* may strip `search`-style markers and prefers cache-pricing-complete
|
|
9
|
+
* references, both of which would be wrong for canonical coalescing.
|
|
10
|
+
*/
|
|
11
|
+
import type { Api, Model } from "../types";
|
|
12
|
+
import { getBracketStrippedModelIdCandidates, getLongestModelLikeIdSegment, getModelLikeIdSegments } from "./id";
|
|
13
|
+
import { REFERENCE_TRAILING_MARKER_PATTERN } from "./markers";
|
|
14
|
+
|
|
15
|
+
export interface ModelReferenceIndex {
|
|
16
|
+
exact: Map<string, Model<Api>>;
|
|
17
|
+
suffixAlias: Map<string, Model<Api>>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// xai-oauth subscription entries carry zero public pricing and inflated maxTokens;
|
|
21
|
+
// keep them provider-local so they cannot outrank paid/public Grok references.
|
|
22
|
+
export function isZeroCostXaiOAuthReference(candidate: Model<Api>): boolean {
|
|
23
|
+
return (
|
|
24
|
+
candidate.provider === "xai-oauth" &&
|
|
25
|
+
candidate.cost.input === 0 &&
|
|
26
|
+
candidate.cost.output === 0 &&
|
|
27
|
+
candidate.cost.cacheRead === 0 &&
|
|
28
|
+
candidate.cost.cacheWrite === 0
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Prefer the reference with the largest limits and complete cache pricing, then
|
|
33
|
+
// first-party OpenAI entries.
|
|
34
|
+
function shouldReplaceReference(existing: Model<Api> | undefined, candidate: Model<Api>): boolean {
|
|
35
|
+
if (!existing) return true;
|
|
36
|
+
if (candidate.contextWindow !== existing.contextWindow) {
|
|
37
|
+
return (candidate.contextWindow ?? 0) > (existing.contextWindow ?? 0);
|
|
38
|
+
}
|
|
39
|
+
if (candidate.maxTokens !== existing.maxTokens) {
|
|
40
|
+
return (candidate.maxTokens ?? 0) > (existing.maxTokens ?? 0);
|
|
41
|
+
}
|
|
42
|
+
const existingHasCachePricing = existing.cost.cacheRead > 0 || existing.cost.cacheWrite > 0;
|
|
43
|
+
const candidateHasCachePricing = candidate.cost.cacheRead > 0 || candidate.cost.cacheWrite > 0;
|
|
44
|
+
if (candidateHasCachePricing !== existingHasCachePricing) {
|
|
45
|
+
return candidateHasCachePricing;
|
|
46
|
+
}
|
|
47
|
+
return existing.provider !== "openai" && candidate.provider === "openai";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function normalizeReferenceKey(value: string): string {
|
|
51
|
+
return value.trim().toLowerCase();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Build a reference index from a model catalog (typically the bundled models).
|
|
56
|
+
* Pure: callers are responsible for memoizing the result.
|
|
57
|
+
*/
|
|
58
|
+
export function buildModelReferenceIndex(models: Iterable<Model<Api>>): ModelReferenceIndex {
|
|
59
|
+
const exact = new Map<string, Model<Api>>();
|
|
60
|
+
for (const candidate of models) {
|
|
61
|
+
if (isZeroCostXaiOAuthReference(candidate)) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const key = normalizeReferenceKey(candidate.id);
|
|
65
|
+
if (shouldReplaceReference(exact.get(key), candidate)) {
|
|
66
|
+
exact.set(key, candidate);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return { exact, suffixAlias: buildSuffixAliasMap(exact) };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function buildSuffixAliasMap(exactReferences: ReadonlyMap<string, Model<Api>>): Map<string, Model<Api>> {
|
|
73
|
+
const aliases = new Map<string, Model<Api>>();
|
|
74
|
+
for (const reference of exactReferences.values()) {
|
|
75
|
+
const slashIndex = reference.id.lastIndexOf("/");
|
|
76
|
+
if (slashIndex === -1) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const suffix = reference.id.slice(slashIndex + 1);
|
|
80
|
+
const alias = getLongestModelLikeIdSegment(suffix);
|
|
81
|
+
if (!alias) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (shouldReplaceReference(aliases.get(alias), reference)) {
|
|
85
|
+
aliases.set(alias, reference);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return aliases;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function stripReferenceTrailingMarker(candidate: string): string | undefined {
|
|
92
|
+
const match = REFERENCE_TRAILING_MARKER_PATTERN.exec(candidate);
|
|
93
|
+
return match ? candidate.slice(0, match.index) : undefined;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function getReferenceCandidateIds(modelId: string): string[] {
|
|
97
|
+
const candidates = new Set<string>();
|
|
98
|
+
const queue = [modelId];
|
|
99
|
+
for (let index = 0; index < queue.length; index += 1) {
|
|
100
|
+
const candidate = queue[index]?.trim();
|
|
101
|
+
if (!candidate || candidates.has(candidate)) continue;
|
|
102
|
+
candidates.add(candidate);
|
|
103
|
+
|
|
104
|
+
for (const stripped of getBracketStrippedModelIdCandidates(candidate)) {
|
|
105
|
+
queue.push(stripped);
|
|
106
|
+
}
|
|
107
|
+
for (const segment of getModelLikeIdSegments(candidate)) {
|
|
108
|
+
queue.push(segment);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
for (const suffix of [":cloud", "-cloud"] as const) {
|
|
112
|
+
if (candidate.toLowerCase().endsWith(suffix)) {
|
|
113
|
+
queue.push(candidate.slice(0, -suffix.length));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const slashIndex = candidate.lastIndexOf("/");
|
|
118
|
+
if (slashIndex !== -1) {
|
|
119
|
+
queue.push(candidate.slice(slashIndex + 1));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const colonToDash = candidate.replace(/:/g, "-");
|
|
123
|
+
if (colonToDash !== candidate) {
|
|
124
|
+
queue.push(colonToDash);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const lowercased = candidate.toLowerCase();
|
|
128
|
+
if (lowercased !== candidate) {
|
|
129
|
+
queue.push(lowercased);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const strippedMarker = stripReferenceTrailingMarker(candidate);
|
|
133
|
+
if (strippedMarker) {
|
|
134
|
+
queue.push(strippedMarker);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return [...candidates];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Resolve a (possibly proxied/affixed) model id to its bundled upstream reference. */
|
|
141
|
+
export function resolveModelReference(modelId: string, index: ModelReferenceIndex): Model<Api> | undefined {
|
|
142
|
+
for (const candidate of getReferenceCandidateIds(modelId)) {
|
|
143
|
+
const key = normalizeReferenceKey(candidate);
|
|
144
|
+
const reference = index.exact.get(key) ?? index.suffixAlias.get(key);
|
|
145
|
+
if (reference) return reference;
|
|
146
|
+
}
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|