@linxiraos/pi-catalog 1.4.6 → 1.4.9
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 +6 -2
- package/README.md +3 -3
- package/dist/types/build.d.ts +12 -4
- package/dist/types/compat/auth-ids.d.ts +2 -2
- package/dist/types/compat/catalog-policy.d.ts +6 -4
- package/dist/types/compat/factory-droid.d.ts +7 -1
- package/dist/types/compat/provider-ids.d.ts +1 -1
- package/dist/types/compat/resolve.d.ts +1 -1
- package/dist/types/compat/revision.d.ts +2 -0
- package/dist/types/compat/server-side-fallback.d.ts +6 -4
- package/dist/types/compat/types.d.ts +6 -2
- package/dist/types/discovery/codex.d.ts +4 -5
- package/dist/types/discovery/cursor-proto.d.ts +8 -0
- package/dist/types/discovery/openai-compatible.d.ts +6 -0
- package/dist/types/model-cache.d.ts +8 -0
- package/dist/types/model-catalog-format.d.ts +37 -0
- package/dist/types/model-manager.d.ts +11 -1
- package/dist/types/model-thinking.d.ts +4 -0
- package/dist/types/models.d.ts +22 -3
- package/dist/types/pricing.d.ts +66 -6
- package/dist/types/provider-models/openai-compat.d.ts +18 -13
- package/dist/types/types.d.ts +14 -19
- package/dist/types/utils.d.ts +8 -0
- package/dist/types/wire/codex.d.ts +1 -1
- package/package.json +6 -10
- package/src/build.d.ts +12 -4
- package/src/build.ts +50 -3
- package/src/compat/auth-ids.ts +5 -0
- package/src/compat/axes.ts +27 -9
- package/src/compat/catalog-policy.d.ts +9 -0
- package/src/compat/catalog-policy.ts +14 -10
- package/src/compat/collapse.ts +1 -1
- package/src/compat/factory-droid.d.ts +7 -1
- package/src/compat/factory-droid.ts +9 -1
- package/src/compat/provider-ids.d.ts +1 -1
- package/src/compat/provider-ids.ts +2 -0
- package/src/compat/resolve.d.ts +1 -1
- package/src/compat/resolve.ts +4 -5
- package/src/compat/revision.d.ts +2 -0
- package/src/compat/revision.ts +10 -0
- package/src/compat/rules/README.md +14 -12
- package/src/compat/rules/auth/_order.kdl +1 -1
- package/src/compat/rules/auth/mistral.kdl +4 -0
- package/src/compat/rules/auth/modular.kdl +9 -0
- package/src/compat/rules/auth/scaleway.kdl +17 -0
- package/src/compat/rules/auth/typesafe.kdl +2 -1
- package/src/compat/rules/classes/anthropic.kdl +5 -0
- package/src/compat/rules/classes/deepseek.kdl +3 -2
- package/src/compat/rules/classes/gemini.kdl +1 -1
- package/src/compat/rules/classes/openai.kdl +2 -2
- package/src/compat/rules/classes/xai.kdl +1 -1
- package/src/compat/rules/providers/anthropic.kdl +8 -4
- package/src/compat/rules/providers/cursor.kdl +10 -0
- package/src/compat/rules/providers/deepseek.kdl +2 -2
- package/src/compat/rules/providers/factory-droid.kdl +243 -13
- package/src/compat/rules/providers/google-vertex.kdl +3 -0
- package/src/compat/rules/providers/kimi-code.kdl +6 -0
- package/src/compat/rules/providers/mistral.kdl +8 -0
- package/src/compat/rules/providers/modular.kdl +35 -0
- package/src/compat/rules/providers/openai-codex.kdl +1 -1
- package/src/compat/rules/providers/sambanova.kdl +2 -0
- package/src/compat/rules/providers/scaleway.kdl +179 -0
- package/src/compat/rules/runtime/behavior.kdl +22 -6
- package/src/compat/rules.json +1 -1
- package/src/compat/server-side-fallback.d.ts +9 -0
- package/src/compat/server-side-fallback.ts +7 -5
- package/src/compat/types.d.ts +6 -2
- package/src/compat/types.ts +6 -2
- package/src/discovery/codex.d.ts +4 -5
- package/src/discovery/codex.ts +7 -15
- package/src/discovery/cursor-proto.d.ts +8 -0
- package/src/discovery/cursor-proto.ts +12 -1
- package/src/discovery/factory-droid.ts +35 -11
- package/src/discovery/openai-compatible.d.ts +6 -0
- package/src/discovery/openai-compatible.ts +1 -1
- package/src/model-cache.d.ts +8 -0
- package/src/model-cache.ts +83 -61
- package/src/model-catalog-format.d.ts +37 -0
- package/src/model-catalog-format.ts +296 -0
- package/src/model-manager.d.ts +11 -1
- package/src/model-manager.ts +85 -143
- package/src/model-thinking.d.ts +4 -0
- package/src/model-thinking.ts +10 -0
- package/src/model-tokenizer.ts +13 -12
- package/src/models.d.ts +22 -3
- package/src/models.json +1 -1
- package/src/models.ts +48 -11
- package/src/pricing.d.ts +66 -6
- package/src/pricing.ts +59 -94
- package/src/provider-models/cache-provider-id.ts +23 -6
- package/src/provider-models/catalog-snapshot.json.zst +0 -0
- package/src/provider-models/catalog-snapshot.json.zst.d.ts +3 -0
- package/src/provider-models/descriptors.ts +2 -0
- package/src/provider-models/openai-compat.d.ts +18 -13
- package/src/provider-models/openai-compat.ts +203 -94
- package/src/provider-models/special.ts +5 -6
- package/src/types.d.ts +14 -19
- package/src/types.ts +11 -18
- package/src/utils.d.ts +8 -0
- package/src/utils.ts +18 -0
- package/src/wire/codex.d.ts +1 -1
- package/src/wire/codex.ts +1 -1
- package/src/wire/factory-droid.ts +4 -3
- package/src/models.json.d.ts +0 -9
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { USER_AGENT, getInstallId } from "@linxiraos/pi-utils";
|
|
2
2
|
import * as logger from "@linxiraos/pi-utils/logger";
|
|
3
3
|
import { toClinePassPublicModelId } from "../cline-pass-model-id";
|
|
4
4
|
import {
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
import { resolveAnthropicApiVersion } from "../compat/anthropic";
|
|
14
14
|
import { xaiResponsesReasoningEffortMap } from "../compat/openai";
|
|
15
15
|
import { hasModelScopedEffortLadder, resolveModelPolicy } from "../compat/resolve";
|
|
16
|
-
import { compareRevision, parseRevision } from "../compat/revision";
|
|
16
|
+
import { compareRevision, parseRevision, revisionAtLeast } from "../compat/revision";
|
|
17
17
|
import { providerEntries, seedModels } from "../compat/providers";
|
|
18
18
|
import { billingVariantPlain, classifyModel, discoveryVocabulary } from "../compat/taxonomy";
|
|
19
19
|
import {
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
fetchOpenAICompatibleModels,
|
|
22
22
|
type OpenAICompatibleModelMapperContext,
|
|
23
23
|
type OpenAICompatibleModelRecord,
|
|
24
|
+
withOpenAICompatibleDiscoveryTimeout,
|
|
24
25
|
} from "../discovery/openai-compatible";
|
|
25
26
|
import { Effort, THINKING_EFFORTS } from "../effort";
|
|
26
27
|
import { FIREWORKS_FAST_SUFFIX, toFireworksPublicModelId } from "../fireworks-model-id";
|
|
@@ -43,15 +44,7 @@ import {
|
|
|
43
44
|
type TokenCost,
|
|
44
45
|
runnerApiKind,
|
|
45
46
|
} from "../types";
|
|
46
|
-
import {
|
|
47
|
-
discoveryFetch,
|
|
48
|
-
isAnthropicOAuthToken,
|
|
49
|
-
isRecord,
|
|
50
|
-
toBoolean,
|
|
51
|
-
toNumber,
|
|
52
|
-
toPositiveNumber,
|
|
53
|
-
toPositiveNumberOrNull,
|
|
54
|
-
} from "../utils";
|
|
47
|
+
import { discoveryFetch, isAnthropicOAuthToken, isRecord, toBoolean, toNumber, toPositiveNumber } from "../utils";
|
|
55
48
|
import { ALIBABA_TOKEN_PLAN_BASE_URL, parseAlibabaTokenPlanCredential } from "../wire/alibaba-token-plan";
|
|
56
49
|
import { normalizeCharmHyperBaseUrl } from "../wire/charm-hyper";
|
|
57
50
|
import { CLINEPASS_API_BASE_URL, clinePassClientHeaders } from "../wire/cline-pass";
|
|
@@ -73,20 +66,12 @@ import {
|
|
|
73
66
|
} from "../wire/singularityapi";
|
|
74
67
|
import { isXiaomiTokenPlanKey } from "../wire/xiaomi-token-plan";
|
|
75
68
|
import { createBundledReferenceMap, createReferenceResolver, toModelSpec } from "./bundled-references";
|
|
69
|
+
import catalogSnapshotPath from "./catalog-snapshot.json.zst" with { type: "file" };
|
|
76
70
|
import { getDefaultModelDiscoveryBaseUrl, resolveModelCacheProviderId } from "./cache-provider-id";
|
|
77
71
|
import { getClinePassModelMetadata } from "./cline-pass";
|
|
78
72
|
import type { ModelManagerConfig } from "./descriptor-types";
|
|
79
73
|
import { filterModelsDevCatalogRows } from "./models-dev-policies";
|
|
80
74
|
|
|
81
|
-
function revisionAtLeast(revision: string | undefined, floor: string): boolean {
|
|
82
|
-
if (revision === undefined) return false;
|
|
83
|
-
const parsedRevision = parseRevision(revision);
|
|
84
|
-
const parsedFloor = parseRevision(floor);
|
|
85
|
-
return (
|
|
86
|
-
parsedRevision !== undefined && parsedFloor !== undefined && compareRevision(parsedRevision, parsedFloor) >= 0
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
75
|
function isGlmReasoningIdentity(provider: string, modelId: string, floor: string): boolean {
|
|
91
76
|
const identity = classifyModel(provider, modelId, { lenient: true });
|
|
92
77
|
if (identity.class !== "glm" || !revisionAtLeast(identity.revision, floor)) return false;
|
|
@@ -99,24 +84,6 @@ const MODELS_DEV_URL = "https://catalog.stencil.so/models.json.zstd";
|
|
|
99
84
|
/** Little-endian magic number opening every zstd frame (RFC 8878). */
|
|
100
85
|
const ZSTD_MAGIC = 0xfd2fb528;
|
|
101
86
|
|
|
102
|
-
/**
|
|
103
|
-
* Uses a cancellable timer rather than the native abort-timeout helper so
|
|
104
|
-
* successful fast discovery requests do not leave armed timeout signals for
|
|
105
|
-
* concurrent GC to trip over later.
|
|
106
|
-
*/
|
|
107
|
-
async function withCatalogDiscoveryTimeout<T>(timeoutMs: number, run: (signal: AbortSignal) => Promise<T>): Promise<T> {
|
|
108
|
-
const controller = new AbortController();
|
|
109
|
-
const timer = setTimeout(
|
|
110
|
-
() => controller.abort(new DOMException("The operation timed out.", "TimeoutError")),
|
|
111
|
-
timeoutMs,
|
|
112
|
-
);
|
|
113
|
-
try {
|
|
114
|
-
return await run(controller.signal);
|
|
115
|
-
} finally {
|
|
116
|
-
clearTimeout(timer);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
87
|
const ANTHROPIC_BASE_URL = "https://api.anthropic.com/v1";
|
|
121
88
|
const ANTHROPIC_OAUTH_BETA =
|
|
122
89
|
"claude-code-20250219,oauth-2025-04-20,interleaved-thinking-2025-05-14,redact-thinking-2026-02-12,context-management-2025-06-27,prompt-caching-scope-2026-01-05,mid-conversation-system-2026-04-07,advanced-tool-use-2025-11-20,effort-2025-11-24,extended-cache-ttl-2025-04-11";
|
|
@@ -215,7 +182,37 @@ const CATALOG_USER_AGENT = USER_AGENT;
|
|
|
215
182
|
* Transient failures reuse the last in-memory payload for callers that only
|
|
216
183
|
* need best-effort metadata.
|
|
217
184
|
*/
|
|
185
|
+
async function parseCatalogBytes(bytes: Uint8Array): Promise<unknown> {
|
|
186
|
+
const isZstd = bytes.length >= 4 && new DataView(bytes.buffer, bytes.byteOffset).getUint32(0, true) === ZSTD_MAGIC;
|
|
187
|
+
const text = new TextDecoder().decode(isZstd ? await Bun.zstdDecompress(bytes) : bytes);
|
|
188
|
+
return JSON.parse(text);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The committed snapshot, decompressed once per process.
|
|
193
|
+
*
|
|
194
|
+
* `gen:models` writes the exact payload shape this function returns, so the
|
|
195
|
+
* offline source and the live source are interchangeable downstream. A
|
|
196
|
+
* snapshot that fails to parse is reported, not cached, so the next caller
|
|
197
|
+
* retries instead of inheriting a poisoned cache.
|
|
198
|
+
*/
|
|
199
|
+
let catalogSnapshot: unknown;
|
|
200
|
+
let catalogSnapshotInflight: Promise<unknown> | undefined;
|
|
201
|
+
|
|
202
|
+
function readCatalogSnapshot(): Promise<unknown> {
|
|
203
|
+
if (catalogSnapshot !== undefined) return Promise.resolve(catalogSnapshot);
|
|
204
|
+
catalogSnapshotInflight ??= (async () => {
|
|
205
|
+
const bytes = new Uint8Array(await Bun.file(catalogSnapshotPath).arrayBuffer());
|
|
206
|
+
catalogSnapshot = await parseCatalogBytes(bytes);
|
|
207
|
+
return catalogSnapshot;
|
|
208
|
+
})().finally(() => {
|
|
209
|
+
catalogSnapshotInflight = undefined;
|
|
210
|
+
});
|
|
211
|
+
return catalogSnapshotInflight;
|
|
212
|
+
}
|
|
213
|
+
|
|
218
214
|
export function fetchWellKnownModels(fetchImpl?: FetchImpl, signal?: AbortSignal): Promise<unknown> {
|
|
215
|
+
if (!fetchImpl) return waitForCatalogRequest(readCatalogSnapshot(), signal);
|
|
219
216
|
const session = getCatalogSession(fetchImpl);
|
|
220
217
|
return fetchRevalidatedWellKnownModels(fetchImpl, signal).catch(error => {
|
|
221
218
|
if (session.hasPayload) return session.payload;
|
|
@@ -226,8 +223,9 @@ export function fetchWellKnownModels(fetchImpl?: FetchImpl, signal?: AbortSignal
|
|
|
226
223
|
function fetchRevalidatedWellKnownModels(fetchImpl?: FetchImpl, signal?: AbortSignal): Promise<unknown> {
|
|
227
224
|
const session = getCatalogSession(fetchImpl);
|
|
228
225
|
if (!session.inflight) {
|
|
229
|
-
session.inflight =
|
|
230
|
-
|
|
226
|
+
session.inflight = withOpenAICompatibleDiscoveryTimeout(
|
|
227
|
+
DEFAULT_OPENAI_COMPATIBLE_DISCOVERY_TIMEOUT_MS,
|
|
228
|
+
transportSignal => fetchCatalogPayload(fetchImpl ?? discoveryFetch(), session, transportSignal),
|
|
231
229
|
).finally(() => {
|
|
232
230
|
session.inflight = null;
|
|
233
231
|
});
|
|
@@ -239,7 +237,9 @@ function fetchRevalidatedWellKnownModelsWithTimeout(
|
|
|
239
237
|
fetchImpl?: FetchImpl,
|
|
240
238
|
timeoutMs = DEFAULT_OPENAI_COMPATIBLE_DISCOVERY_TIMEOUT_MS,
|
|
241
239
|
): Promise<unknown> {
|
|
242
|
-
|
|
240
|
+
// Same source rule as {@link fetchWellKnownModels}: no transport, no network.
|
|
241
|
+
if (!fetchImpl) return readCatalogSnapshot();
|
|
242
|
+
return withOpenAICompatibleDiscoveryTimeout(timeoutMs, signal => fetchRevalidatedWellKnownModels(fetchImpl, signal));
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
async function fetchCatalogPayload(
|
|
@@ -545,6 +545,8 @@ function mapWithBundledReference<TApi extends Api>(
|
|
|
545
545
|
return {
|
|
546
546
|
...defaults,
|
|
547
547
|
name,
|
|
548
|
+
contextWindow: toPositiveNumber(entry.context_length, defaults.contextWindow),
|
|
549
|
+
maxTokens: toPositiveNumber(entry.max_completion_tokens, defaults.maxTokens),
|
|
548
550
|
};
|
|
549
551
|
}
|
|
550
552
|
// Generic `/models` rows describe the chat roster. Do not make a bundled
|
|
@@ -672,7 +674,7 @@ async function fetchOllamaNativeModels(
|
|
|
672
674
|
* Ollama's cloud catalog reports for stock models.
|
|
673
675
|
*/
|
|
674
676
|
const OLLAMA_FALLBACK_CONTEXT_WINDOW = 128_000;
|
|
675
|
-
/** Cap max output tokens at a value that matches
|
|
677
|
+
/** Cap max output tokens at a value that matches OMP's other openai-responses defaults. */
|
|
676
678
|
const OLLAMA_DEFAULT_MAX_TOKENS = 8192;
|
|
677
679
|
|
|
678
680
|
interface OllamaResolvedMetadata {
|
|
@@ -1594,13 +1596,12 @@ export function novitaModelManagerOptions(
|
|
|
1594
1596
|
export const DEEPINFRA_BASE_URL = "https://api.deepinfra.com/v1/openai";
|
|
1595
1597
|
/**
|
|
1596
1598
|
* `filter=with_meta` attaches per-model `metadata` (limits, pricing, tags);
|
|
1597
|
-
* `sort_by=
|
|
1598
|
-
* (upstream-negotiated API key; never rebrand this outbound value)
|
|
1599
|
+
* `sort_by=zeta` asks DeepInfra to return models in zeta-priority order
|
|
1599
1600
|
* (earlier = better). The mapper does not stamp `priority` yet — see
|
|
1600
1601
|
* `mapDeepinfraModel` — but the params are sent so discovery picks the
|
|
1601
1602
|
* ordering up as soon as the server honors it.
|
|
1602
1603
|
*/
|
|
1603
|
-
const DEEPINFRA_MODELS_QUERY = "?filter=with_meta&sort_by=
|
|
1604
|
+
const DEEPINFRA_MODELS_QUERY = "?filter=with_meta&sort_by=zeta";
|
|
1604
1605
|
const DEEPINFRA_EFFORTS = [Effort.Low, Effort.Medium, Effort.High] as const;
|
|
1605
1606
|
|
|
1606
1607
|
/** DeepInfra OpenAI-compatible discovery configuration. */
|
|
@@ -1710,7 +1711,7 @@ function mapDeepinfraModel(
|
|
|
1710
1711
|
* Bespoke fetch instead of `fetchOpenAICompatibleModels`: the shared helper
|
|
1711
1712
|
* cannot carry the `filter`/`sort_by` query params and re-sorts results by id,
|
|
1712
1713
|
* which would destroy DeepInfra's priority ordering once the server honors
|
|
1713
|
-
* `sort_by=
|
|
1714
|
+
* `sort_by=zeta`. Response order is preserved (dedupe keeps the first, i.e.
|
|
1714
1715
|
* highest-priority, occurrence).
|
|
1715
1716
|
*/
|
|
1716
1717
|
async function fetchDeepinfraModels(options: {
|
|
@@ -1726,8 +1727,9 @@ async function fetchDeepinfraModels(options: {
|
|
|
1726
1727
|
const fetchImpl = discoveryFetch(options.fetch);
|
|
1727
1728
|
let payload: unknown;
|
|
1728
1729
|
try {
|
|
1729
|
-
const response = await
|
|
1730
|
-
|
|
1730
|
+
const response = await withOpenAICompatibleDiscoveryTimeout(
|
|
1731
|
+
DEFAULT_OPENAI_COMPATIBLE_DISCOVERY_TIMEOUT_MS,
|
|
1732
|
+
signal => fetchImpl(`${options.baseUrl}/models${DEEPINFRA_MODELS_QUERY}`, { method: "GET", headers, signal }),
|
|
1731
1733
|
);
|
|
1732
1734
|
if (!response.ok) {
|
|
1733
1735
|
return null;
|
|
@@ -2285,7 +2287,7 @@ async function loadSiliconFlowModelsDevReferences(
|
|
|
2285
2287
|
try {
|
|
2286
2288
|
// Bounded: this enrichment is optional, so a stalled models.dev must not
|
|
2287
2289
|
// hold back the authoritative endpoint request that runs after it.
|
|
2288
|
-
const payload = await
|
|
2290
|
+
const payload = await withOpenAICompatibleDiscoveryTimeout(SILICONFLOW_MODELS_DEV_REFERENCE_TIMEOUT_MS, signal =>
|
|
2289
2291
|
fetchWellKnownModels(fetchImpl, signal),
|
|
2290
2292
|
);
|
|
2291
2293
|
return createModelsDevReferenceMap<"openai-completions">(
|
|
@@ -2829,7 +2831,7 @@ const CLINE_PASS_LIVE_CATALOG_URL = "https://openrouter.ai/api/v1/models";
|
|
|
2829
2831
|
/** Enrichment tier, never authoritative: any failure degrades to the bundled path. */
|
|
2830
2832
|
async function fetchClinePassLiveCatalog(fetchImpl: FetchImpl): Promise<ClinePassLiveCatalog | undefined> {
|
|
2831
2833
|
try {
|
|
2832
|
-
const response = await
|
|
2834
|
+
const response = await withOpenAICompatibleDiscoveryTimeout(5_000, signal =>
|
|
2833
2835
|
fetchImpl(CLINE_PASS_LIVE_CATALOG_URL, { signal }),
|
|
2834
2836
|
);
|
|
2835
2837
|
if (!response.ok) return undefined;
|
|
@@ -3008,7 +3010,7 @@ async function fetchClinePassModels(
|
|
|
3008
3010
|
// The roster is authoritative for ids; the live reference catalog is a pure
|
|
3009
3011
|
// enrichment tier fetched alongside and tolerated away (offline → bundle).
|
|
3010
3012
|
const [response, liveCatalog] = await Promise.all([
|
|
3011
|
-
|
|
3013
|
+
withOpenAICompatibleDiscoveryTimeout(5_000, signal =>
|
|
3012
3014
|
fetchImpl(CLINEPASS_MODELS_URL, { signal, headers: clinePassClientHeaders() }),
|
|
3013
3015
|
),
|
|
3014
3016
|
fetchClinePassLiveCatalog(fetchImpl),
|
|
@@ -4222,9 +4224,11 @@ export function kimiCodeModelManagerOptions(
|
|
|
4222
4224
|
config?: KimiCodeModelManagerConfig,
|
|
4223
4225
|
): ModelManagerOptions<"openai-completions"> {
|
|
4224
4226
|
const apiKey = config?.apiKey;
|
|
4225
|
-
const baseUrl = config?.baseUrl ?? "
|
|
4227
|
+
const baseUrl = config?.baseUrl ?? getDefaultModelDiscoveryBaseUrl("kimi-code")!;
|
|
4226
4228
|
return {
|
|
4227
4229
|
providerId: "kimi-code",
|
|
4230
|
+
cacheProviderId: resolveModelCacheProviderId("kimi-code", { apiKey, baseUrl }),
|
|
4231
|
+
dynamicModelsAuthoritative: true,
|
|
4228
4232
|
...(apiKey && {
|
|
4229
4233
|
fetchDynamicModels: () =>
|
|
4230
4234
|
fetchOpenAICompatibleModels({
|
|
@@ -4421,7 +4425,7 @@ export async function fetchLmStudioNativeModelMetadata(
|
|
|
4421
4425
|
if (options?.signal !== undefined) {
|
|
4422
4426
|
return fetchMetadata(options.signal);
|
|
4423
4427
|
}
|
|
4424
|
-
return
|
|
4428
|
+
return withOpenAICompatibleDiscoveryTimeout(LM_STUDIO_NATIVE_METADATA_TIMEOUT_MS, fetchMetadata);
|
|
4425
4429
|
}
|
|
4426
4430
|
|
|
4427
4431
|
export interface LmStudioModelManagerConfig {
|
|
@@ -4514,7 +4518,7 @@ function toSyntheticStringList(value: unknown): readonly string[] {
|
|
|
4514
4518
|
|
|
4515
4519
|
/**
|
|
4516
4520
|
* Translate Synthetic's per-model `reasoning_effort` vocabulary into an effort
|
|
4517
|
-
* ladder. Every advertised value that names an
|
|
4521
|
+
* ladder. Every advertised value that names an OMP tier maps verbatim; `none`
|
|
4518
4522
|
* is the thinking-off state rather than a tier of its own, so it backs the
|
|
4519
4523
|
* `minimal` selector through the wire map (same shape as the Fireworks
|
|
4520
4524
|
* `minimal → none` map) and gives these routes a real no-thinking tier.
|
|
@@ -4713,9 +4717,9 @@ export interface BasetenModelManagerConfig {
|
|
|
4713
4717
|
fetch?: FetchImpl;
|
|
4714
4718
|
}
|
|
4715
4719
|
|
|
4716
|
-
// A previous version of
|
|
4720
|
+
// A previous version of OMP shipped these models without reasoning levels.
|
|
4717
4721
|
// We've since fixed that (V4-generation whitelist). This const lets us bust
|
|
4718
|
-
// the cache so that users on that version of
|
|
4722
|
+
// the cache so that users on that version of OMP pick up the reasoning levels
|
|
4719
4723
|
// immediately.
|
|
4720
4724
|
const BASETEN_CACHE_MIGRATION_MODEL_IDS = [
|
|
4721
4725
|
"zai-org/GLM-5.3",
|
|
@@ -4745,10 +4749,10 @@ export function basetenModelManagerOptions(
|
|
|
4745
4749
|
const features = Array.isArray(raw.supported_features) ? raw.supported_features : [];
|
|
4746
4750
|
const modalities = Array.isArray(raw.input_modalities) ? raw.input_modalities : [];
|
|
4747
4751
|
|
|
4748
|
-
// Baseten's discovery flags are not enough to enable
|
|
4752
|
+
// Baseten's discovery flags are not enough to enable OMP reasoning for every
|
|
4749
4753
|
// model. Only models with a verified Baseten reasoning policy are enabled
|
|
4750
4754
|
// here; an unknown model may use a different reasoning wire shape or effort
|
|
4751
|
-
// vocabulary, which
|
|
4755
|
+
// vocabulary, which OMP must not guess.
|
|
4752
4756
|
const identity = classifyModel("baseten", defaults.id, { lenient: true });
|
|
4753
4757
|
const isSupportedBasetenReasoningModel =
|
|
4754
4758
|
(identity.class === "kimi" && identity.family === "k3") ||
|
|
@@ -4769,8 +4773,6 @@ export function basetenModelManagerOptions(
|
|
|
4769
4773
|
cacheWrite: 0,
|
|
4770
4774
|
};
|
|
4771
4775
|
|
|
4772
|
-
const contextWindow = toPositiveNumber(raw.context_length, reference?.contextWindow ?? defaults.contextWindow);
|
|
4773
|
-
const maxTokens = toPositiveNumber(raw.max_completion_tokens, reference?.maxTokens ?? defaults.maxTokens);
|
|
4774
4776
|
const baseModel = mapWithBundledReference(entry, defaults, reference);
|
|
4775
4777
|
|
|
4776
4778
|
return {
|
|
@@ -4778,8 +4780,6 @@ export function basetenModelManagerOptions(
|
|
|
4778
4780
|
reasoning,
|
|
4779
4781
|
input: vision ? ["text", "image"] : ["text"],
|
|
4780
4782
|
cost,
|
|
4781
|
-
contextWindow,
|
|
4782
|
-
maxTokens,
|
|
4783
4783
|
...(supportsTools === false ? { supportsTools } : {}),
|
|
4784
4784
|
};
|
|
4785
4785
|
},
|
|
@@ -5444,7 +5444,7 @@ interface StepfunModelRecord extends OpenAICompatibleModelRecord {
|
|
|
5444
5444
|
|
|
5445
5445
|
/**
|
|
5446
5446
|
* Translate StepFun's per-model `reasoning_effort_support_list` into a ladder.
|
|
5447
|
-
* Every advertised value that names an
|
|
5447
|
+
* Every advertised value that names an OMP tier maps verbatim, in OMP's tier
|
|
5448
5448
|
* order; a row advertising nothing (or only tiers this client does not know)
|
|
5449
5449
|
* resolves to no thinking, so the wire path never sends a `reasoning_effort`
|
|
5450
5450
|
* the endpoint rejects. Same shape as `mapOpenRouterThinking` for OpenRouter's
|
|
@@ -5679,7 +5679,7 @@ type LiteLLMRichEndpointModel<TApi extends Api> = {
|
|
|
5679
5679
|
};
|
|
5680
5680
|
type LiteLLMRichEndpointFailure = {
|
|
5681
5681
|
endpoint: string;
|
|
5682
|
-
reason: "http-status" | "invalid-json" | "network-error";
|
|
5682
|
+
reason: "http-status" | "invalid-json" | "invalid-pagination" | "network-error";
|
|
5683
5683
|
status?: number;
|
|
5684
5684
|
error?: unknown;
|
|
5685
5685
|
};
|
|
@@ -5692,6 +5692,8 @@ type LiteLLMRichEndpointResult<TApi extends Api> =
|
|
|
5692
5692
|
| { failure: LiteLLMRichEndpointFailure };
|
|
5693
5693
|
|
|
5694
5694
|
const LITELLM_RICH_ENDPOINTS = ["/model_group/info", "/v2/model/info", "/model/info", "/v1/model/info"] as const;
|
|
5695
|
+
// Bound paginated management responses before trusting their advertised page count.
|
|
5696
|
+
const LITELLM_MAX_RICH_PAGES = 100;
|
|
5695
5697
|
export const OPENAI_COMPAT_DISCOVERY_DEFAULT_CONTEXT_WINDOW = 128_000;
|
|
5696
5698
|
export const OPENAI_COMPAT_DISCOVERY_DEFAULT_MAX_TOKENS = 32_768;
|
|
5697
5699
|
const UNKNOWN_PROXY_COST = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } as const;
|
|
@@ -6171,29 +6173,83 @@ async function fetchLiteLLMRichEndpoint<TApi extends Api>(
|
|
|
6171
6173
|
if (options.apiKey) {
|
|
6172
6174
|
requestHeaders.Authorization = `Bearer ${options.apiKey}`;
|
|
6173
6175
|
}
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6176
|
+
const fetchPage = async (
|
|
6177
|
+
page?: number,
|
|
6178
|
+
): Promise<{ payload: unknown; status: number } | { failure: LiteLLMRichEndpointFailure } | null> => {
|
|
6179
|
+
let response: Response;
|
|
6180
|
+
try {
|
|
6181
|
+
response = await fetchImpl(`${managementBaseUrl}${endpoint}${page === undefined ? "" : `?page=${page}`}`, {
|
|
6182
|
+
method: "GET",
|
|
6183
|
+
headers: requestHeaders,
|
|
6184
|
+
signal,
|
|
6185
|
+
});
|
|
6186
|
+
} catch (error) {
|
|
6187
|
+
return { failure: { endpoint, reason: "network-error", error } };
|
|
6188
|
+
}
|
|
6189
|
+
if (!response.ok) {
|
|
6190
|
+
return response.status === 404 && page === undefined
|
|
6191
|
+
? null
|
|
6192
|
+
: { failure: { endpoint, reason: "http-status", status: response.status } };
|
|
6193
|
+
}
|
|
6194
|
+
try {
|
|
6195
|
+
return { payload: await response.json(), status: response.status };
|
|
6196
|
+
} catch (error) {
|
|
6197
|
+
return { failure: { endpoint, reason: "invalid-json", status: response.status, error } };
|
|
6198
|
+
}
|
|
6199
|
+
};
|
|
6200
|
+
const firstPage = await fetchPage();
|
|
6201
|
+
if (!firstPage || "failure" in firstPage) {
|
|
6202
|
+
return firstPage;
|
|
6192
6203
|
}
|
|
6193
|
-
const entries = extractLiteLLMRichEntries(payload);
|
|
6204
|
+
const entries = extractLiteLLMRichEntries(firstPage.payload);
|
|
6194
6205
|
if (!entries || entries.length === 0) {
|
|
6195
6206
|
return null;
|
|
6196
6207
|
}
|
|
6208
|
+
// /v2/model/info returns {current_page, total_pages, data}; older
|
|
6209
|
+
// endpoints and unpaginated /v2 proxies must keep their existing behavior.
|
|
6210
|
+
if (
|
|
6211
|
+
endpoint === "/v2/model/info" &&
|
|
6212
|
+
isRecord(firstPage.payload) &&
|
|
6213
|
+
("current_page" in firstPage.payload || "total_pages" in firstPage.payload)
|
|
6214
|
+
) {
|
|
6215
|
+
const { current_page: currentPage, total_pages: totalPages, total_count: totalCount } = firstPage.payload;
|
|
6216
|
+
const invalidPage = (status: number): LiteLLMRichEndpointResult<TApi> => ({
|
|
6217
|
+
failure: { endpoint, reason: "invalid-pagination", status },
|
|
6218
|
+
});
|
|
6219
|
+
if (
|
|
6220
|
+
currentPage !== 1 ||
|
|
6221
|
+
typeof totalPages !== "number" ||
|
|
6222
|
+
!Number.isSafeInteger(totalPages) ||
|
|
6223
|
+
totalPages < 1 ||
|
|
6224
|
+
totalPages > LITELLM_MAX_RICH_PAGES ||
|
|
6225
|
+
(totalCount !== undefined &&
|
|
6226
|
+
(typeof totalCount !== "number" || !Number.isSafeInteger(totalCount) || totalCount < entries.length))
|
|
6227
|
+
) {
|
|
6228
|
+
return invalidPage(firstPage.status);
|
|
6229
|
+
}
|
|
6230
|
+
const remainingPages = await Promise.all(
|
|
6231
|
+
Array.from({ length: totalPages - 1 }, (_, index) => fetchPage(index + 2)),
|
|
6232
|
+
);
|
|
6233
|
+
for (const [index, nextPage] of remainingPages.entries()) {
|
|
6234
|
+
if (!nextPage || "failure" in nextPage) {
|
|
6235
|
+
return nextPage ?? invalidPage(firstPage.status);
|
|
6236
|
+
}
|
|
6237
|
+
const nextEntries = extractLiteLLMRichEntries(nextPage.payload);
|
|
6238
|
+
if (
|
|
6239
|
+
!isRecord(nextPage.payload) ||
|
|
6240
|
+
nextPage.payload.current_page !== index + 2 ||
|
|
6241
|
+
nextPage.payload.total_pages !== totalPages ||
|
|
6242
|
+
(totalCount !== undefined && nextPage.payload.total_count !== totalCount) ||
|
|
6243
|
+
!nextEntries?.length
|
|
6244
|
+
) {
|
|
6245
|
+
return invalidPage(nextPage.status);
|
|
6246
|
+
}
|
|
6247
|
+
entries.push(...nextEntries);
|
|
6248
|
+
}
|
|
6249
|
+
if (totalCount !== undefined && entries.length !== totalCount) {
|
|
6250
|
+
return invalidPage(firstPage.status);
|
|
6251
|
+
}
|
|
6252
|
+
}
|
|
6197
6253
|
const deduped = new Map<string, LiteLLMRichEndpointModel<TApi>>();
|
|
6198
6254
|
const excludedModelIds = new Set<string>();
|
|
6199
6255
|
for (const entry of entries) {
|
|
@@ -6336,7 +6392,9 @@ async function fetchLiteLLMRichModelsInternal<TApi extends Api>(
|
|
|
6336
6392
|
if (options.signal !== undefined) {
|
|
6337
6393
|
return fetchModels(options.signal);
|
|
6338
6394
|
}
|
|
6339
|
-
return options.timeoutMs !== undefined
|
|
6395
|
+
return options.timeoutMs !== undefined
|
|
6396
|
+
? withOpenAICompatibleDiscoveryTimeout(options.timeoutMs, fetchModels)
|
|
6397
|
+
: fetchModels();
|
|
6340
6398
|
}
|
|
6341
6399
|
|
|
6342
6400
|
export async function fetchLiteLLMRichModels<TApi extends Api>(
|
|
@@ -6350,8 +6408,10 @@ export function litellmModelManagerOptions(config?: LiteLLMModelManagerConfig):
|
|
|
6350
6408
|
const baseUrl = config?.baseUrl ?? getDefaultModelDiscoveryBaseUrl("litellm")!;
|
|
6351
6409
|
return {
|
|
6352
6410
|
providerId: "litellm",
|
|
6353
|
-
// rich-
|
|
6354
|
-
//
|
|
6411
|
+
// rich-v14 fetches all /v2/model/info pages so cached proxy rosters
|
|
6412
|
+
// include models beyond page one. rich-v13 routes `mode: decisions`
|
|
6413
|
+
// groups to the Decisions runner as judge rows.
|
|
6414
|
+
// rich-v12 invalidates namespaced proxy ids that missed bare catalog
|
|
6355
6415
|
// references. rich-v11 excluded ClinePass gateway metadata (issue #10932).
|
|
6356
6416
|
// rich-v10 filtered known non-conversational LiteLLM modes, keyed the
|
|
6357
6417
|
// deployment's `supports_vision` declaration into cached compat, and
|
|
@@ -6485,13 +6545,7 @@ export function nanoGptModelManagerOptions(
|
|
|
6485
6545
|
const maxOutputTokens = entry.max_output_tokens ?? entry.max_completion_tokens;
|
|
6486
6546
|
const mapped = mapWithBundledReference(
|
|
6487
6547
|
{ ...entry, max_completion_tokens: maxOutputTokens },
|
|
6488
|
-
|
|
6489
|
-
? defaults
|
|
6490
|
-
: {
|
|
6491
|
-
...defaults,
|
|
6492
|
-
contextWindow: toPositiveNumberOrNull(entry.context_length),
|
|
6493
|
-
maxTokens: toPositiveNumberOrNull(maxOutputTokens),
|
|
6494
|
-
},
|
|
6548
|
+
defaults,
|
|
6495
6549
|
reference,
|
|
6496
6550
|
);
|
|
6497
6551
|
return {
|
|
@@ -6724,7 +6778,7 @@ export function githubCopilotModelManagerOptions(config?: GithubCopilotModelMana
|
|
|
6724
6778
|
fetchDynamicModels: async () => {
|
|
6725
6779
|
const fetchImpl = discoveryFetch(config?.fetch);
|
|
6726
6780
|
const requestBaseUrl = isPersonalGitHubCopilotBaseUrl(baseUrl)
|
|
6727
|
-
? ((await
|
|
6781
|
+
? ((await withOpenAICompatibleDiscoveryTimeout(DEFAULT_OPENAI_COMPATIBLE_DISCOVERY_TIMEOUT_MS, signal =>
|
|
6728
6782
|
discoverGitHubCopilotApiEndpoint(apiKey, fetchImpl, signal),
|
|
6729
6783
|
)) ?? baseUrl)
|
|
6730
6784
|
: baseUrl;
|
|
@@ -6866,6 +6920,22 @@ export function githubCopilotModelManagerOptions(config?: GithubCopilotModelMana
|
|
|
6866
6920
|
}
|
|
6867
6921
|
: {}),
|
|
6868
6922
|
};
|
|
6923
|
+
// Cross-provider fallback references (e.g. a Cursor
|
|
6924
|
+
// collapsed family for an enterprise-only sibling id)
|
|
6925
|
+
// carry provider-specific wire routing that must not
|
|
6926
|
+
// transfer: the off-tier `requestModelId` pin would send
|
|
6927
|
+
// every Copilot request under the `-none` sibling id
|
|
6928
|
+
// regardless of thinking level.
|
|
6929
|
+
if (reference && reference.provider !== "github-copilot") {
|
|
6930
|
+
delete base.requestModelId;
|
|
6931
|
+
if (base.thinking) {
|
|
6932
|
+
// `base` is a shallow copy of the shared global
|
|
6933
|
+
// reference: clone before deleting or the bundled
|
|
6934
|
+
// entry loses its routing process-wide.
|
|
6935
|
+
base.thinking = { ...base.thinking };
|
|
6936
|
+
delete base.thinking.effortRouting;
|
|
6937
|
+
}
|
|
6938
|
+
}
|
|
6869
6939
|
const defaultCost = copilotTierCost(tokenPrices.defaultTier);
|
|
6870
6940
|
if (defaultCost) {
|
|
6871
6941
|
// Cache writes are not reported per tier; retain the bundled provider rate.
|
|
@@ -7719,6 +7789,8 @@ const MODELS_DEV_PROVIDER_DESCRIPTORS_SPECIALIZED: readonly ModelsDevProviderDes
|
|
|
7719
7789
|
return { api: "openai-completions" as const, baseUrl: ZENMUX_OPENAI_BASE_URL };
|
|
7720
7790
|
},
|
|
7721
7791
|
}),
|
|
7792
|
+
// --- Modular ---
|
|
7793
|
+
openAiCompletionsDescriptor("modular", "modular", "https://api.modular.com/v1"),
|
|
7722
7794
|
];
|
|
7723
7795
|
/** All provider descriptors for models.dev data mapping in generate-models.ts. */
|
|
7724
7796
|
export const MODELS_DEV_PROVIDER_DESCRIPTORS: readonly ModelsDevProviderDescriptor[] = [
|
|
@@ -8163,3 +8235,40 @@ export function singularityApiTechModelManagerOptions(
|
|
|
8163
8235
|
): ModelManagerOptions<Api> {
|
|
8164
8236
|
return singularityApiModelManagerOptions("singularityapi-tech", SINGULARITYAPI_TECH_API_BASE_URL, config);
|
|
8165
8237
|
}
|
|
8238
|
+
|
|
8239
|
+
// ---------------------------------------------------------------------------
|
|
8240
|
+
// Scaleway
|
|
8241
|
+
// ---------------------------------------------------------------------------
|
|
8242
|
+
|
|
8243
|
+
/**
|
|
8244
|
+
* Scaleway discovery configuration: the API key plus optional base-URL and
|
|
8245
|
+
* fetch overrides. Consumed by {@link scalewayModelManagerOptions}, and
|
|
8246
|
+
* exported for extensions and tests that construct the manager directly.
|
|
8247
|
+
*/
|
|
8248
|
+
export interface ScalewayModelManagerConfig {
|
|
8249
|
+
apiKey?: string;
|
|
8250
|
+
baseUrl?: string;
|
|
8251
|
+
fetch?: FetchImpl;
|
|
8252
|
+
}
|
|
8253
|
+
|
|
8254
|
+
/**
|
|
8255
|
+
* Scaleway model manager: plain OpenAI-compatible chat completions at
|
|
8256
|
+
* `api.scaleway.ai/v1` (fr-par serverless Generative APIs). `/v1/models`
|
|
8257
|
+
* returns bare ids, so the authored seed in `providers/scaleway.kdl` is the
|
|
8258
|
+
* reference each live row merges names, modalities, prices, and limits from;
|
|
8259
|
+
* a successful fetch is the complete roster and prunes retired rows.
|
|
8260
|
+
*/
|
|
8261
|
+
export function scalewayModelManagerOptions(
|
|
8262
|
+
config?: ScalewayModelManagerConfig,
|
|
8263
|
+
): ModelManagerOptions<"openai-completions"> {
|
|
8264
|
+
return createOpenAICompatibleModelManagerOptions({
|
|
8265
|
+
api: "openai-completions",
|
|
8266
|
+
providerId: "scaleway",
|
|
8267
|
+
defaultBaseUrl: "https://api.scaleway.ai/v1",
|
|
8268
|
+
config,
|
|
8269
|
+
dynamicModelsAuthoritative: true,
|
|
8270
|
+
requireApiKey: true,
|
|
8271
|
+
filterModel: (_entry, model) => !isExcludedModel("scaleway", model.id),
|
|
8272
|
+
mapModel: mapWithBundledReference,
|
|
8273
|
+
});
|
|
8274
|
+
}
|
|
@@ -94,11 +94,10 @@ export function openaiCodexModelManagerOptions(
|
|
|
94
94
|
* {@link unionAccountCatalogs}.
|
|
95
95
|
*
|
|
96
96
|
* Returns `null` when any account's fetch failed transiently, so a partial list
|
|
97
|
-
* cannot replace the previous or bundled authoritative catalog.
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* produced a catalog, discovery aborts the same way.
|
|
97
|
+
* cannot replace the previous or bundled authoritative catalog. A definitive
|
|
98
|
+
* account denial (401/403 auth or 402 payment) contributes nothing and is skipped
|
|
99
|
+
* instead: it would otherwise veto every sibling account's models until the
|
|
100
|
+
* account recovers. If no account produced a catalog, discovery aborts.
|
|
102
101
|
*/
|
|
103
102
|
function unionCodexModels(
|
|
104
103
|
results: readonly { accountId: string | undefined; result: CodexModelDiscoveryResult | null }[],
|
|
@@ -107,7 +106,7 @@ function unionCodexModels(
|
|
|
107
106
|
for (const { accountId, result } of results) {
|
|
108
107
|
if (!result) return null;
|
|
109
108
|
if (result.rejectedStatus !== undefined) {
|
|
110
|
-
logger.warn("Codex model discovery skipped an account
|
|
109
|
+
logger.warn("Codex model discovery skipped an account denied by the backend", {
|
|
111
110
|
accountId,
|
|
112
111
|
status: result.rejectedStatus,
|
|
113
112
|
});
|