@linxiraos/pi-catalog 1.4.4 → 1.4.7
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 +31 -0
- package/README.md +3 -3
- package/dist/types/build.d.ts +12 -4
- package/dist/types/compat/anthropic.d.ts +20 -0
- package/dist/types/compat/behavior.d.ts +2 -0
- package/dist/types/compat/catalog-policy.d.ts +2 -2
- package/dist/types/compat/collapse.d.ts +10 -0
- package/dist/types/compat/factory-droid.d.ts +2 -0
- package/dist/types/compat/resolve.d.ts +2 -2
- package/dist/types/compat/types.d.ts +5 -1
- package/dist/types/discovery/antigravity.d.ts +7 -2
- package/dist/types/discovery/codex.d.ts +4 -5
- package/dist/types/discovery/devin.d.ts +1 -1
- package/dist/types/model-cache.d.ts +8 -0
- package/dist/types/model-catalog-format.d.ts +37 -0
- package/dist/types/models.d.ts +6 -3
- package/dist/types/provider-models/google.d.ts +2 -0
- package/dist/types/provider-models/openai-compat.d.ts +16 -3
- package/dist/types/types.d.ts +58 -3
- package/dist/types/wire/codex.d.ts +1 -1
- package/dist/types/wire/devin.d.ts +2 -2
- package/dist/types/wire/gemini-headers.d.ts +41 -22
- package/dist/types/wire/xiaomi-token-plan.d.ts +2 -0
- package/package.json +6 -10
- package/src/build.d.ts +12 -4
- package/src/build.ts +97 -4
- package/src/compat/anthropic.d.ts +20 -0
- package/src/compat/anthropic.ts +47 -0
- package/src/compat/axes.ts +16 -3
- package/src/compat/behavior.d.ts +2 -0
- package/src/compat/behavior.ts +5 -0
- package/src/compat/catalog-policy.ts +10 -8
- package/src/compat/collapse.d.ts +10 -0
- package/src/compat/collapse.ts +63 -2
- package/src/compat/factory-droid.d.ts +2 -0
- package/src/compat/factory-droid.ts +3 -0
- package/src/compat/resolve.d.ts +2 -2
- package/src/compat/resolve.ts +7 -5
- package/src/compat/rules/README.md +24 -16
- package/src/compat/rules/auth/google-antigravity.kdl +2 -1
- package/src/compat/rules/auth/llama.cpp.kdl +1 -1
- package/src/compat/rules/auth/typesafe.kdl +2 -1
- package/src/compat/rules/auth/xiaomi-token-plan-ams.kdl +1 -1
- package/src/compat/rules/auth/xiaomi-token-plan-cn.kdl +1 -1
- package/src/compat/rules/auth/xiaomi-token-plan-sgp.kdl +1 -1
- package/src/compat/rules/classes/anthropic.kdl +6 -1
- package/src/compat/rules/classes/deepseek.kdl +2 -1
- package/src/compat/rules/classes/minimax.kdl +10 -0
- package/src/compat/rules/classes/openai.kdl +2 -2
- package/src/compat/rules/providers/anthropic.kdl +15 -1
- package/src/compat/rules/providers/deepseek.kdl +13 -10
- package/src/compat/rules/providers/factory-droid.kdl +72 -0
- package/src/compat/rules/providers/google-antigravity.kdl +7 -0
- package/src/compat/rules/providers/google-vertex.kdl +3 -0
- package/src/compat/rules/providers/kimi-code.kdl +26 -0
- package/src/compat/rules/providers/mistral.kdl +8 -0
- package/src/compat/rules/providers/moonshot.kdl +25 -0
- package/src/compat/rules/providers/muse-code.kdl +1 -1
- package/src/compat/rules/providers/openai-codex.kdl +17 -4
- package/src/compat/rules/providers/openai.kdl +23 -2
- package/src/compat/rules/providers/opencode-go.kdl +38 -3
- package/src/compat/rules/providers/opencode-zen.kdl +7 -0
- package/src/compat/rules/providers/xiaomi-token-plan-ams.kdl +1 -1
- package/src/compat/rules/providers/xiaomi-token-plan-cn.kdl +1 -1
- package/src/compat/rules/providers/xiaomi-token-plan-sgp.kdl +1 -1
- package/src/compat/rules/providers/xiaomi.kdl +1 -1
- package/src/compat/rules/runtime/behavior.kdl +39 -20
- package/src/compat/rules/taxonomy/kimi.kdl +7 -0
- package/src/compat/rules.json +1 -1
- package/src/compat/types.d.ts +5 -1
- package/src/compat/types.ts +5 -1
- package/src/discovery/antigravity.d.ts +7 -2
- package/src/discovery/antigravity.ts +41 -6
- package/src/discovery/codex.d.ts +4 -5
- package/src/discovery/codex.ts +5 -6
- package/src/discovery/cursor.ts +0 -6
- package/src/discovery/devin.d.ts +1 -1
- package/src/discovery/devin.ts +9 -3
- package/src/discovery/factory-droid.ts +38 -6
- package/src/model-cache.d.ts +8 -0
- package/src/model-cache.ts +55 -5
- package/src/model-catalog-format.d.ts +37 -0
- package/src/model-catalog-format.ts +299 -0
- package/src/models.d.ts +6 -3
- package/src/models.json +1 -1
- package/src/models.ts +16 -10
- package/src/provider-models/cache-provider-id.ts +26 -6
- package/src/provider-models/google.d.ts +2 -0
- package/src/provider-models/google.ts +13 -1
- package/src/provider-models/openai-compat.d.ts +16 -3
- package/src/provider-models/openai-compat.ts +207 -58
- package/src/provider-models/special.ts +5 -6
- package/src/types.d.ts +58 -3
- package/src/types.ts +63 -1
- package/src/wire/codex.d.ts +1 -1
- package/src/wire/codex.ts +1 -1
- package/src/wire/devin.d.ts +2 -2
- package/src/wire/devin.ts +2 -2
- package/src/wire/gemini-headers.d.ts +41 -22
- package/src/wire/gemini-headers.ts +68 -24
- package/src/wire/xiaomi-token-plan.d.ts +2 -0
- package/src/wire/xiaomi-token-plan.ts +4 -0
- package/src/models.json.d.ts +0 -9
package/src/models.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { classifyModel } from "./compat/taxonomy";
|
|
2
|
-
import
|
|
2
|
+
import { getCatalogProvider, getCatalogProviders, openModelCatalog } from "./model-catalog-format";
|
|
3
|
+
import modelsData from "./models.json" with { type: "json" };
|
|
3
4
|
import { dueEffectiveRate } from "./pricing";
|
|
4
5
|
import type {
|
|
5
6
|
Api,
|
|
@@ -21,20 +22,21 @@ import type {
|
|
|
21
22
|
*
|
|
22
23
|
* For runtime-aware resolution, use `createModelManager()` / `resolveProviderModels()`.
|
|
23
24
|
*/
|
|
25
|
+
const catalog = openModelCatalog(modelsData);
|
|
26
|
+
const bundledProviders: readonly KnownProvider[] = Object.freeze(getCatalogProviders(catalog) as KnownProvider[]);
|
|
27
|
+
const bundledProviderSet = new Set<string>(bundledProviders);
|
|
24
28
|
const modelRegistry = new Map<string, Map<string, Model<Api>>>();
|
|
25
29
|
|
|
26
30
|
/** Return one provider's bundled models, materialized by the generator. */
|
|
27
31
|
function getProviderModels(provider: string): Map<string, Model<Api>> | undefined {
|
|
28
32
|
const cachedModels = modelRegistry.get(provider);
|
|
29
33
|
if (cachedModels !== undefined) return cachedModels;
|
|
30
|
-
|
|
34
|
+
const rawModels = getCatalogProvider(catalog, provider);
|
|
35
|
+
if (!rawModels) return undefined;
|
|
31
36
|
|
|
32
37
|
const providerModels = new Map<string, Model<Api>>();
|
|
33
|
-
const rawModels = MODELS[provider as keyof typeof MODELS];
|
|
34
38
|
for (const id in rawModels) {
|
|
35
|
-
|
|
36
|
-
// consuming them verbatim keeps startup allocation-free.
|
|
37
|
-
const row = rawModels[id as keyof typeof rawModels] as unknown as Model<Api>;
|
|
39
|
+
const row = rawModels[id];
|
|
38
40
|
// Rows baked before the compat engine (and stale cache snapshots) lack
|
|
39
41
|
// `identity`; classify lazily so consumers can rely on the field.
|
|
40
42
|
row.identity ??= classifyModel(provider, id, { lenient: true });
|
|
@@ -44,22 +46,26 @@ function getProviderModels(provider: string): Map<string, Model<Api>> | undefine
|
|
|
44
46
|
return providerModels;
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
/** Provider identifier accepted by the bundled model registry. */
|
|
50
|
+
export type GeneratedProvider = string;
|
|
48
51
|
|
|
49
52
|
/** Whether `provider` has bundled rows in models.json (e.g. a provider id authored in KDL). */
|
|
50
53
|
export function isGeneratedProvider(provider: string): provider is GeneratedProvider {
|
|
51
|
-
return
|
|
54
|
+
return bundledProviderSet.has(provider);
|
|
52
55
|
}
|
|
53
56
|
|
|
57
|
+
/** Look up a bundled model; nested catalog values are shared and must not be mutated. */
|
|
54
58
|
export function getBundledModel<TApi extends Api = Api>(provider: GeneratedProvider, modelId: string): Model<TApi> {
|
|
55
59
|
const providerModels = getProviderModels(provider);
|
|
56
60
|
return providerModels?.get(modelId) as Model<TApi>;
|
|
57
61
|
}
|
|
58
62
|
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
/** List providers with bundled rows; the array is shared and frozen. */
|
|
64
|
+
export function getBundledProviders(): readonly KnownProvider[] {
|
|
65
|
+
return bundledProviders;
|
|
61
66
|
}
|
|
62
67
|
|
|
68
|
+
/** List a provider's bundled models; nested catalog values are shared and must not be mutated. */
|
|
63
69
|
export function getBundledModels(provider: GeneratedProvider): Model<Api>[] {
|
|
64
70
|
const models = getProviderModels(provider);
|
|
65
71
|
return models ? (Array.from(models.values()) as Model<Api>[]) : [];
|
|
@@ -26,6 +26,9 @@ const CREDENTIAL_SCOPED_MODEL_CACHE_PROVIDERS: Readonly<Record<string, true>> =
|
|
|
26
26
|
// than from the synchronous, credential-less startup read.
|
|
27
27
|
"singularityapi-dev": true,
|
|
28
28
|
"singularityapi-tech": true,
|
|
29
|
+
// Kimi Code's roster is plan-gated and discovery is authoritative, so a
|
|
30
|
+
// shared namespace would serve one plan's ids to another plan's credential.
|
|
31
|
+
"kimi-code": true,
|
|
29
32
|
};
|
|
30
33
|
|
|
31
34
|
/** Whether a provider's model-cache namespace requires its resolved credential. */
|
|
@@ -37,6 +40,8 @@ export function getDefaultModelDiscoveryBaseUrl(providerId: string): string | un
|
|
|
37
40
|
switch (providerId) {
|
|
38
41
|
case "charm-hyper":
|
|
39
42
|
return CHARM_HYPER_API_BASE_URL;
|
|
43
|
+
case "kimi-code":
|
|
44
|
+
return "https://api.kimi.com/coding/v1";
|
|
40
45
|
case "meta":
|
|
41
46
|
case "muse-code":
|
|
42
47
|
return "https://api.meta.ai/v1";
|
|
@@ -71,11 +76,11 @@ export function resolveOllamaModelCacheProviderId(providerId: string, baseUrl?:
|
|
|
71
76
|
}
|
|
72
77
|
|
|
73
78
|
/**
|
|
74
|
-
* The `sub` claim of a
|
|
75
|
-
* that
|
|
79
|
+
* The `sub` claim of a JWT access token. Cursor and Kimi Code access tokens
|
|
80
|
+
* are JWTs that refresh rotates (new `exp`/`iat`/`jti`) for the same account,
|
|
76
81
|
* so the subject is the stable account scope. Non-JWT keys return undefined.
|
|
77
82
|
*/
|
|
78
|
-
function
|
|
83
|
+
function jwtCredentialSubject(apiKey: string): string | undefined {
|
|
79
84
|
const parts = apiKey.split(".");
|
|
80
85
|
if (parts.length !== 3 || !parts[1]) return undefined;
|
|
81
86
|
try {
|
|
@@ -112,7 +117,7 @@ export function resolveModelCacheProviderId(providerId: string, options: ModelCa
|
|
|
112
117
|
// mark the account default `isProviderDefault`, which startup now honors.
|
|
113
118
|
const baseUrl = (options.baseUrl ?? CURSOR_DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
114
119
|
const apiKey = options.apiKey ?? "";
|
|
115
|
-
const scope = `${
|
|
120
|
+
const scope = `${jwtCredentialSubject(apiKey) ?? apiKey}\u0000${baseUrl}`;
|
|
116
121
|
return `cursor:rich-models-v5:${Bun.hash(scope).toString(36)}`;
|
|
117
122
|
}
|
|
118
123
|
case "charm-hyper": {
|
|
@@ -132,6 +137,17 @@ export function resolveModelCacheProviderId(providerId: string, options: ModelCa
|
|
|
132
137
|
// `/v1`-suffixed one; both must land on one namespace.
|
|
133
138
|
return `charm-hyper:models-v1:${Bun.hash(normalizeCharmHyperBaseUrl(options.baseUrl)).toString(36)}`;
|
|
134
139
|
}
|
|
140
|
+
case "kimi-code": {
|
|
141
|
+
// The `/coding/v1/models` roster depends on the subscription plan behind
|
|
142
|
+
// the credential, and discovery is authoritative: a namespace without the
|
|
143
|
+
// credential would serve the previous plan's roster for the full TTL,
|
|
144
|
+
// including ids the current plan cannot call. OAuth access tokens rotate on
|
|
145
|
+
// refresh, so the scope is the token's account subject, not the token.
|
|
146
|
+
const baseUrl = options.baseUrl ?? getDefaultModelDiscoveryBaseUrl(providerId)!;
|
|
147
|
+
const apiKey = options.apiKey ?? "";
|
|
148
|
+
const scope = `${jwtCredentialSubject(apiKey) ?? apiKey}\u0000${baseUrl}`;
|
|
149
|
+
return `kimi-code:models-v1:${Bun.hash(scope).toString(36)}`;
|
|
150
|
+
}
|
|
135
151
|
case "muse-code": {
|
|
136
152
|
const baseUrl = options.baseUrl ?? getDefaultModelDiscoveryBaseUrl(providerId)!;
|
|
137
153
|
const scope = `${options.apiKey ?? ""}\u0000${baseUrl}`;
|
|
@@ -160,6 +176,8 @@ export function resolveModelCacheProviderId(providerId: string, options: ModelCa
|
|
|
160
176
|
}
|
|
161
177
|
case "litellm": {
|
|
162
178
|
const baseUrl = options.baseUrl ?? getDefaultModelDiscoveryBaseUrl(providerId)!;
|
|
179
|
+
// rich-v14 fetches every /v2/model/info page rather than caching only
|
|
180
|
+
// its first 50 models. rich-v13 moves `mode: decisions` groups off chat.
|
|
163
181
|
// rich-v12 invalidates namespaced ids that missed bare catalog references.
|
|
164
182
|
// rich-v11 excluded ClinePass gateway metadata (issue #10932). rich-v10
|
|
165
183
|
// filtered known non-conversational LiteLLM modes, unioned compat across
|
|
@@ -167,7 +185,7 @@ export function resolveModelCacheProviderId(providerId: string, options: ModelCa
|
|
|
167
185
|
// declaration into it; earlier versions invalidated rows whose
|
|
168
186
|
// `compatConfig` retained a colliding bundled model's provider-specific
|
|
169
187
|
// transport (e.g. Fireworks `wireModelIdMode`) (issue #9938).
|
|
170
|
-
return `litellm:rich-
|
|
188
|
+
return `litellm:rich-v14:${Bun.hash(baseUrl).toString(36)}`;
|
|
171
189
|
}
|
|
172
190
|
case "gmi-cloud":
|
|
173
191
|
case "siliconflow":
|
|
@@ -211,7 +229,9 @@ export function resolveModelCacheProviderId(providerId: string, options: ModelCa
|
|
|
211
229
|
// v2: rows cached before Fusion pairings carried their lead uid as
|
|
212
230
|
// `requestModelId` send the composite uid and fail with
|
|
213
231
|
// `permission_denied: no API providers are available`.
|
|
214
|
-
|
|
232
|
+
// v3: rows cached before discovery read `ModelInfo.maxTokens` hold a
|
|
233
|
+
// 200K window on every model.
|
|
234
|
+
return "devin:models-v3";
|
|
215
235
|
default:
|
|
216
236
|
return providerId;
|
|
217
237
|
}
|
|
@@ -21,6 +21,8 @@ export interface GoogleAntigravityAccount {
|
|
|
21
21
|
* When any account lacks one, no model records per-account access.
|
|
22
22
|
*/
|
|
23
23
|
accountKey?: string;
|
|
24
|
+
/** Cloud Code Assist project of the credential, sent with roster discovery like the native client. */
|
|
25
|
+
projectId?: string;
|
|
24
26
|
}
|
|
25
27
|
export interface GoogleAntigravityModelManagerConfig {
|
|
26
28
|
/**
|
|
@@ -33,6 +33,8 @@ export interface GoogleAntigravityAccount {
|
|
|
33
33
|
* When any account lacks one, no model records per-account access.
|
|
34
34
|
*/
|
|
35
35
|
accountKey?: string;
|
|
36
|
+
/** Cloud Code Assist project of the credential, sent with roster discovery like the native client. */
|
|
37
|
+
projectId?: string;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
export interface GoogleAntigravityModelManagerConfig {
|
|
@@ -113,6 +115,7 @@ export function googleAntigravityModelManagerOptions(
|
|
|
113
115
|
result: await fetchAntigravityDiscoveryModels({
|
|
114
116
|
token: account.accessToken,
|
|
115
117
|
endpoint: config?.endpoint,
|
|
118
|
+
projectId: account.projectId,
|
|
116
119
|
fetcher,
|
|
117
120
|
}),
|
|
118
121
|
})),
|
|
@@ -140,7 +143,15 @@ export function googleAntigravityModelManagerOptions(
|
|
|
140
143
|
return unionAccountCatalogs(
|
|
141
144
|
catalogs.map(({ accountKey, models }) =>
|
|
142
145
|
tagAccess && accountKey !== undefined
|
|
143
|
-
? models.map(model => ({
|
|
146
|
+
? models.map(model => ({
|
|
147
|
+
...model,
|
|
148
|
+
accountAccess: {
|
|
149
|
+
[accountKey]:
|
|
150
|
+
model.antigravityWireProfiles === undefined
|
|
151
|
+
? {}
|
|
152
|
+
: { antigravityWireProfiles: model.antigravityWireProfiles },
|
|
153
|
+
},
|
|
154
|
+
}))
|
|
144
155
|
: models,
|
|
145
156
|
),
|
|
146
157
|
);
|
|
@@ -167,6 +178,7 @@ export function googleGeminiCliModelManagerOptions(
|
|
|
167
178
|
}
|
|
168
179
|
const result = await fetchAntigravityDiscoveryModels({
|
|
169
180
|
token,
|
|
181
|
+
projectId: config?.projectId,
|
|
170
182
|
fetcher,
|
|
171
183
|
collapseTable,
|
|
172
184
|
});
|
|
@@ -377,24 +377,32 @@ export declare const KIMI_CODE_DEFAULT_MAX_TOKENS = 32000;
|
|
|
377
377
|
export declare function kimiCodeMaxTokens(modelId: string, fallback?: number): number;
|
|
378
378
|
export declare function kimiCodeMaxTokens(modelId: string, fallback: number | null): number | null;
|
|
379
379
|
export declare function kimiCodeModelManagerOptions(config?: KimiCodeModelManagerConfig): ModelManagerOptions<"openai-completions">;
|
|
380
|
-
/** Native LM Studio metadata keyed by model id from `/api/v0/models`. */
|
|
380
|
+
/** Native LM Studio metadata keyed by model id from `/api/v0/models` and `/api/v1/models`. */
|
|
381
381
|
export interface LmStudioNativeModelMetadata {
|
|
382
382
|
input: ("text" | "image")[];
|
|
383
383
|
contextWindow?: number;
|
|
384
|
+
/**
|
|
385
|
+
* LM Studio reports a decision model (`type: "decision"`): it answers typed
|
|
386
|
+
* questions on `/v1/decisions` and rejects chat completions.
|
|
387
|
+
*/
|
|
388
|
+
decision?: true;
|
|
384
389
|
}
|
|
385
390
|
/** Options for LM Studio's optional native metadata probe. */
|
|
386
391
|
export interface LmStudioNativeModelMetadataOptions {
|
|
387
392
|
headers?: Record<string, string>;
|
|
388
393
|
signal?: AbortSignal;
|
|
389
394
|
}
|
|
390
|
-
/**
|
|
395
|
+
/**
|
|
396
|
+
* Fetches LM Studio native model metadata used to mark VLM models as
|
|
397
|
+
* image-capable and decision models as judges.
|
|
398
|
+
*/
|
|
391
399
|
export declare function fetchLmStudioNativeModelMetadata(baseUrl: string, fetchImpl?: FetchImpl, options?: LmStudioNativeModelMetadataOptions): Promise<Map<string, LmStudioNativeModelMetadata> | null>;
|
|
392
400
|
export interface LmStudioModelManagerConfig {
|
|
393
401
|
apiKey?: string;
|
|
394
402
|
baseUrl?: string;
|
|
395
403
|
fetch?: FetchImpl;
|
|
396
404
|
}
|
|
397
|
-
export declare function lmStudioModelManagerOptions(config?: LmStudioModelManagerConfig): ModelManagerOptions<
|
|
405
|
+
export declare function lmStudioModelManagerOptions(config?: LmStudioModelManagerConfig): ModelManagerOptions<Api>;
|
|
398
406
|
export interface SyntheticModelManagerConfig {
|
|
399
407
|
apiKey?: string;
|
|
400
408
|
baseUrl?: string;
|
|
@@ -560,6 +568,11 @@ export declare const OPENAI_COMPAT_DISCOVERY_DEFAULT_MAX_TOKENS = 32768;
|
|
|
560
568
|
/** Exclude only known non-conversational modes; unknown and non-string modes remain selectable for aliases. */
|
|
561
569
|
export declare function isSelectableLiteLLMModelMode(mode: unknown): boolean;
|
|
562
570
|
export declare function normalizeLiteLLMManagementBaseUrl(baseUrl: string): string;
|
|
571
|
+
/**
|
|
572
|
+
* Transport for a LiteLLM model group: `mode: "decisions"` answers only on the
|
|
573
|
+
* proxy's `/v1/decisions` route, OpenAI-backed groups use Responses, and every
|
|
574
|
+
* other group uses `fallbackApi`.
|
|
575
|
+
*/
|
|
563
576
|
export declare function resolveLiteLLMApi(entry: Record<string, unknown> | undefined, id: string, fallbackApi?: Api): Api;
|
|
564
577
|
export declare function fetchLiteLLMRichModels<TApi extends Api>(options: FetchLiteLLMRichModelsOptions<TApi>): Promise<ModelSpec<TApi>[] | null>;
|
|
565
578
|
export declare function litellmModelManagerOptions(config?: LiteLLMModelManagerConfig): ModelManagerOptions<Api>;
|