@linxiraos/pi-catalog 1.4.7 → 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 +4 -23
- 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 +3 -1
- package/dist/types/discovery/cursor-proto.d.ts +8 -0
- package/dist/types/discovery/openai-compatible.d.ts +6 -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 +16 -0
- 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/package.json +4 -4
- package/src/compat/auth-ids.ts +5 -0
- package/src/compat/axes.ts +21 -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 +3 -1
- 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/classes/anthropic.kdl +5 -0
- package/src/compat/rules/classes/deepseek.kdl +1 -1
- package/src/compat/rules/classes/gemini.kdl +1 -1
- 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 +219 -13
- 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 +13 -0
- 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 +3 -1
- package/src/compat/types.ts +3 -1
- package/src/discovery/codex.ts +2 -9
- 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.ts +32 -58
- package/src/model-catalog-format.ts +5 -8
- 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 +16 -0
- package/src/models.json +1 -1
- package/src/models.ts +32 -1
- package/src/pricing.d.ts +66 -6
- package/src/pricing.ts +59 -94
- 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 +120 -71
- 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/factory-droid.ts +4 -3
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CatalogPolicyInputs } from "../types";
|
|
2
|
+
import type { ResolveRoute } from "./resolve";
|
|
3
|
+
/**
|
|
4
|
+
* Ordered model ids for Anthropic's server-side refusal `fallbacks` chain,
|
|
5
|
+
* authored on the `server-side-fallback-models` catalog axis, on `route`'s
|
|
6
|
+
* upstream when it names one. Empty when no rule assigns a chain (the model,
|
|
7
|
+
* host or upstream does not support the feature).
|
|
8
|
+
*/
|
|
9
|
+
export declare function serverSideFallbackModels(model: CatalogPolicyInputs, route?: ResolveRoute): readonly string[];
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CatalogPolicyInputs } from "../types";
|
|
2
2
|
import { resolveCatalogPolicy } from "./catalog-policy";
|
|
3
|
+
import type { ResolveRoute } from "./resolve";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Ordered model ids for Anthropic's server-side refusal `fallbacks` chain,
|
|
6
|
-
* authored on the `server-side-fallback-models` catalog axis
|
|
7
|
-
*
|
|
7
|
+
* authored on the `server-side-fallback-models` catalog axis, on `route`'s
|
|
8
|
+
* upstream when it names one. Empty when no rule assigns a chain (the model,
|
|
9
|
+
* host or upstream does not support the feature).
|
|
8
10
|
*/
|
|
9
|
-
export function serverSideFallbackModels(model:
|
|
10
|
-
const value = resolveCatalogPolicy(model).serverSideFallbackModels;
|
|
11
|
+
export function serverSideFallbackModels(model: CatalogPolicyInputs, route?: ResolveRoute): readonly string[] {
|
|
12
|
+
const value = resolveCatalogPolicy(model, route).serverSideFallbackModels;
|
|
11
13
|
if (!Array.isArray(value)) return [];
|
|
12
14
|
return value.filter((entry): entry is string => typeof entry === "string");
|
|
13
15
|
}
|
package/src/compat/types.d.ts
CHANGED
|
@@ -714,6 +714,8 @@ export interface ResolvedAxes {
|
|
|
714
714
|
export interface RequestPolicy {
|
|
715
715
|
completionsReasoningMode?: "none" | "effort" | "opt-in" | "forced-on";
|
|
716
716
|
completionsReasoningHistory?: "omit" | "preserved" | "interleaved";
|
|
717
|
+
/** Send `allow_missing_thinking` with the effort so tool-call turns may arrive without reasoning. */
|
|
718
|
+
completionsAllowMissingThinking?: boolean;
|
|
717
719
|
anthropicThinking?: "adaptive" | "adaptive-summarized" | "budget-interleaved" | "budget-effort";
|
|
718
720
|
/** Advertise `fine-grained-tool-streaming-2025-05-14` on requests that carry tools. */
|
|
719
721
|
anthropicToolStreamingBeta?: boolean;
|
|
@@ -721,7 +723,7 @@ export interface RequestPolicy {
|
|
|
721
723
|
openaiPlatformHeader?: string;
|
|
722
724
|
responsesCacheRetention?: boolean;
|
|
723
725
|
responsesVerbosity?: "low";
|
|
724
|
-
responsesServiceTier?: "priority";
|
|
726
|
+
responsesServiceTier?: "priority" | "ultrafast";
|
|
725
727
|
responsesParallelToolCalls?: boolean;
|
|
726
728
|
responsesSafetyIdentifier?: boolean;
|
|
727
729
|
/** Default `tool_choice` to `auto` when the request carries tools and the caller picks none. */
|
package/src/compat/types.ts
CHANGED
|
@@ -753,6 +753,8 @@ export interface ResolvedAxes {
|
|
|
753
753
|
export interface RequestPolicy {
|
|
754
754
|
completionsReasoningMode?: "none" | "effort" | "opt-in" | "forced-on";
|
|
755
755
|
completionsReasoningHistory?: "omit" | "preserved" | "interleaved";
|
|
756
|
+
/** Send `allow_missing_thinking` with the effort so tool-call turns may arrive without reasoning. */
|
|
757
|
+
completionsAllowMissingThinking?: boolean;
|
|
756
758
|
anthropicThinking?: "adaptive" | "adaptive-summarized" | "budget-interleaved" | "budget-effort";
|
|
757
759
|
/** Advertise `fine-grained-tool-streaming-2025-05-14` on requests that carry tools. */
|
|
758
760
|
anthropicToolStreamingBeta?: boolean;
|
|
@@ -760,7 +762,7 @@ export interface RequestPolicy {
|
|
|
760
762
|
openaiPlatformHeader?: string;
|
|
761
763
|
responsesCacheRetention?: boolean;
|
|
762
764
|
responsesVerbosity?: "low";
|
|
763
|
-
responsesServiceTier?: "priority";
|
|
765
|
+
responsesServiceTier?: "priority" | "ultrafast";
|
|
764
766
|
responsesParallelToolCalls?: boolean;
|
|
765
767
|
responsesSafetyIdentifier?: boolean;
|
|
766
768
|
/** Default `tool_choice` to `auto` when the request carries tools and the caller picks none. */
|
package/src/discovery/codex.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { compareRevision, parseRevision } from "../compat/revision";
|
|
|
3
3
|
import { classifyModel } from "../compat/taxonomy";
|
|
4
4
|
import { getBundledModels } from "../models";
|
|
5
5
|
import type { FetchImpl, ModelSpec } from "../types";
|
|
6
|
-
import { discoveryFetch } from "../utils";
|
|
6
|
+
import { discoveryFetch, parseServiceTierIds } from "../utils";
|
|
7
7
|
import { CODEX_BASE_URL, CODEX_CLIENT_VERSION, OPENAI_HEADER_VALUES, OPENAI_HEADERS } from "../wire/codex";
|
|
8
8
|
|
|
9
9
|
const DEFAULT_MODEL_LIST_PATHS = ["/codex/models", "/models"] as const;
|
|
@@ -334,14 +334,7 @@ function parseCodexModelEntry(entry: unknown): ParsedCodexModelEntry | null {
|
|
|
334
334
|
|
|
335
335
|
// codex-rs `ModelServiceTier { id, name, description }`; only the id reaches the wire.
|
|
336
336
|
// An explicit empty array is kept: it means the model offers no optional tier.
|
|
337
|
-
|
|
338
|
-
if (Array.isArray(payload.service_tiers)) {
|
|
339
|
-
serviceTiers = [];
|
|
340
|
-
for (const tier of payload.service_tiers) {
|
|
341
|
-
const id = tier !== null && typeof tier === "object" && "id" in tier ? toNonEmptyString(tier.id) : null;
|
|
342
|
-
if (id && !serviceTiers.includes(id)) serviceTiers.push(id);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
337
|
+
const serviceTiers = parseServiceTierIds(payload.service_tiers);
|
|
345
338
|
|
|
346
339
|
return {
|
|
347
340
|
slug,
|
|
@@ -2514,6 +2514,9 @@ export interface InteractionUpdate extends ProtoMessage {
|
|
|
2514
2514
|
} | {
|
|
2515
2515
|
case: "stepCompleted";
|
|
2516
2516
|
value: StepCompletedUpdate;
|
|
2517
|
+
} | {
|
|
2518
|
+
case: "toolRequestsListed";
|
|
2519
|
+
value: ToolRequestsListedUpdate;
|
|
2517
2520
|
};
|
|
2518
2521
|
}
|
|
2519
2522
|
export declare const InteractionUpdateSchema: MessageCodec<InteractionUpdate>;
|
|
@@ -5318,6 +5321,11 @@ export interface ToolCallStartedUpdate extends ProtoMessage {
|
|
|
5318
5321
|
modelCallId: string;
|
|
5319
5322
|
}
|
|
5320
5323
|
export declare const ToolCallStartedUpdateSchema: MessageCodec<ToolCallStartedUpdate>;
|
|
5324
|
+
/** Cursor agent message agent.v1.ToolRequestsListedUpdate. */
|
|
5325
|
+
export interface ToolRequestsListedUpdate extends ProtoMessage {
|
|
5326
|
+
callCount: number;
|
|
5327
|
+
}
|
|
5328
|
+
export declare const ToolRequestsListedUpdateSchema: MessageCodec<ToolRequestsListedUpdate>;
|
|
5321
5329
|
/** Cursor agent message agent.v1.TruncatedToolCall. */
|
|
5322
5330
|
export interface TruncatedToolCall extends ProtoMessage {
|
|
5323
5331
|
originalStepBlobId: Uint8Array;
|
|
@@ -3662,7 +3662,8 @@ export interface InteractionUpdate extends ProtoMessage {
|
|
|
3662
3662
|
| { case: "heartbeat"; value: HeartbeatUpdate }
|
|
3663
3663
|
| { case: "turnEnded"; value: TurnEndedUpdate }
|
|
3664
3664
|
| { case: "stepStarted"; value: StepStartedUpdate }
|
|
3665
|
-
| { case: "stepCompleted"; value: StepCompletedUpdate }
|
|
3665
|
+
| { case: "stepCompleted"; value: StepCompletedUpdate }
|
|
3666
|
+
| { case: "toolRequestsListed"; value: ToolRequestsListedUpdate };
|
|
3666
3667
|
}
|
|
3667
3668
|
|
|
3668
3669
|
export const InteractionUpdateSchema: MessageCodec<InteractionUpdate> = pb<InteractionUpdate>("agent.v1.InteractionUpdate", [
|
|
@@ -3687,6 +3688,7 @@ export const InteractionUpdateSchema: MessageCodec<InteractionUpdate> = pb<Inter
|
|
|
3687
3688
|
{ no: 14, name: "turnEnded", kind: "message", T: () => TurnEndedUpdateSchema },
|
|
3688
3689
|
{ no: 16, name: "stepStarted", kind: "message", T: () => StepStartedUpdateSchema },
|
|
3689
3690
|
{ no: 17, name: "stepCompleted", kind: "message", T: () => StepCompletedUpdateSchema },
|
|
3691
|
+
{ no: 27, name: "toolRequestsListed", kind: "message", T: () => ToolRequestsListedUpdateSchema },
|
|
3690
3692
|
],
|
|
3691
3693
|
},
|
|
3692
3694
|
]);
|
|
@@ -8251,6 +8253,15 @@ export const ToolCallStartedUpdateSchema: MessageCodec<ToolCallStartedUpdate> =
|
|
|
8251
8253
|
{ no: 3, name: "modelCallId", kind: "string" },
|
|
8252
8254
|
]);
|
|
8253
8255
|
|
|
8256
|
+
/** Cursor agent message agent.v1.ToolRequestsListedUpdate. */
|
|
8257
|
+
export interface ToolRequestsListedUpdate extends ProtoMessage {
|
|
8258
|
+
callCount: number;
|
|
8259
|
+
}
|
|
8260
|
+
|
|
8261
|
+
export const ToolRequestsListedUpdateSchema: MessageCodec<ToolRequestsListedUpdate> = pb<ToolRequestsListedUpdate>("agent.v1.ToolRequestsListedUpdate", [
|
|
8262
|
+
{ no: 1, name: "callCount", kind: "uint32" },
|
|
8263
|
+
]);
|
|
8264
|
+
|
|
8254
8265
|
/** Cursor agent message agent.v1.TruncatedToolCall. */
|
|
8255
8266
|
export interface TruncatedToolCall extends ProtoMessage {
|
|
8256
8267
|
originalStepBlobId: Uint8Array;
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
resolveFactoryDroidRotation,
|
|
7
7
|
} from "../compat/factory-droid";
|
|
8
8
|
import { hasModelScopedEffortLadder, resolveModelPolicy } from "../compat/resolve";
|
|
9
|
+
import { serverSideFallbackModels } from "../compat/server-side-fallback";
|
|
9
10
|
import type { RequestPolicy } from "../compat/types";
|
|
10
11
|
import { getBundledModel, isGeneratedProvider } from "../models";
|
|
11
12
|
import type { FetchImpl, ModelSpec, ThinkingConfig, ThinkingControlMode } from "../types";
|
|
@@ -166,16 +167,35 @@ export interface FactoryDroidModelDiscoveryOptions extends AccountScope {
|
|
|
166
167
|
*/
|
|
167
168
|
export function factoryDroidSeedModels(scope: AccountScope): ModelSpec<"factory-droid-agent">[] {
|
|
168
169
|
const inferenceRegion = resolveFactoryDroidInferenceRegion(scope);
|
|
169
|
-
return
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
170
|
+
return withAvailableRefusalFallbacks(
|
|
171
|
+
factoryDroidRegistry()
|
|
172
|
+
.filter(model => isModelAvailable(model, {}, null, inferenceRegion, null))
|
|
173
|
+
.map(model =>
|
|
174
|
+
buildFactoryDroidModel(model, {
|
|
175
|
+
region: scope.region,
|
|
176
|
+
inferenceRegion,
|
|
177
|
+
orgId: scope.orgId,
|
|
178
|
+
apiProviders: resolveFactoryDroidRotation(model.policy, inferenceRegion),
|
|
179
|
+
}),
|
|
180
|
+
),
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Native offers a server-side refusal fallback only when the account can run
|
|
186
|
+
* that model, so each model keeps the fallbacks its upstreams name that are
|
|
187
|
+
* themselves in the account's roster.
|
|
188
|
+
*/
|
|
189
|
+
function withAvailableRefusalFallbacks(models: ModelSpec<"factory-droid-agent">[]): ModelSpec<"factory-droid-agent">[] {
|
|
190
|
+
const available = new Set(models.map(model => model.id));
|
|
191
|
+
for (const model of models) {
|
|
192
|
+
const named = new Set<string>();
|
|
193
|
+
for (const upstream of model.factoryDroidApiProviders ?? []) {
|
|
194
|
+
for (const id of serverSideFallbackModels(model, { upstream })) named.add(id);
|
|
195
|
+
}
|
|
196
|
+
if (named.size > 0) model.factoryDroidRefusalFallbacks = [...named].filter(id => available.has(id));
|
|
197
|
+
}
|
|
198
|
+
return models;
|
|
179
199
|
}
|
|
180
200
|
|
|
181
201
|
/**
|
|
@@ -219,7 +239,7 @@ export async function fetchFactoryDroidModels(
|
|
|
219
239
|
} catch {
|
|
220
240
|
return null;
|
|
221
241
|
}
|
|
222
|
-
|
|
242
|
+
const models = factoryDroidRegistry().flatMap(model => {
|
|
223
243
|
if (!isModelAvailable(model, flags, policy, servingRegion, images)) return [];
|
|
224
244
|
const { id } = model.spec;
|
|
225
245
|
const family = model.policy.routingFamily;
|
|
@@ -236,6 +256,7 @@ export async function fetchFactoryDroidModels(
|
|
|
236
256
|
if (routed !== undefined) spec.factoryDroidRoutingSource = "configured_order";
|
|
237
257
|
return [spec];
|
|
238
258
|
});
|
|
259
|
+
return withAvailableRefusalFallbacks(models);
|
|
239
260
|
}
|
|
240
261
|
|
|
241
262
|
/**
|
|
@@ -282,6 +303,9 @@ export function buildFactoryDroidModel(
|
|
|
282
303
|
...factoryDroidRegionalLimits(policy, resolveFactoryDroidInferenceRegion(options)),
|
|
283
304
|
...(options.orgId ? { factoryDroidOrgId: options.orgId } : {}),
|
|
284
305
|
...(policy.creditRates ? { factoryDroidCredits: policy.creditRates.input } : {}),
|
|
306
|
+
...(policy.creditRates?.effectiveRates
|
|
307
|
+
? { factoryDroidCreditCards: policy.creditRates.effectiveRates.map(card => ({ ...card })) }
|
|
308
|
+
: {}),
|
|
285
309
|
...(options.apiProviders?.length ? { factoryDroidApiProviders: [...options.apiProviders] } : {}),
|
|
286
310
|
};
|
|
287
311
|
const resolved = resolveModelPolicy(model);
|
|
@@ -10,6 +10,12 @@ import type { Api, FetchImpl, ModelSpec, Provider } from "../types";
|
|
|
10
10
|
* (issue #8315). 10s matches the coding-agent's remote-discovery budget.
|
|
11
11
|
*/
|
|
12
12
|
export declare const DEFAULT_OPENAI_COMPATIBLE_DISCOVERY_TIMEOUT_MS = 10000;
|
|
13
|
+
/**
|
|
14
|
+
* Uses a cancellable timer rather than the native abort-timeout helper so
|
|
15
|
+
* successful fast discovery requests do not leave armed timeout signals for
|
|
16
|
+
* concurrent GC to trip over later.
|
|
17
|
+
*/
|
|
18
|
+
export declare function withOpenAICompatibleDiscoveryTimeout<T>(timeoutMs: number, run: (signal: AbortSignal) => Promise<T>): Promise<T>;
|
|
13
19
|
/**
|
|
14
20
|
* Minimal OpenAI-style model entry shape consumed by discovery.
|
|
15
21
|
*
|
|
@@ -21,7 +21,7 @@ export const DEFAULT_OPENAI_COMPATIBLE_DISCOVERY_TIMEOUT_MS = 10_000;
|
|
|
21
21
|
* successful fast discovery requests do not leave armed timeout signals for
|
|
22
22
|
* concurrent GC to trip over later.
|
|
23
23
|
*/
|
|
24
|
-
async function withOpenAICompatibleDiscoveryTimeout<T>(
|
|
24
|
+
export async function withOpenAICompatibleDiscoveryTimeout<T>(
|
|
25
25
|
timeoutMs: number,
|
|
26
26
|
run: (signal: AbortSignal) => Promise<T>,
|
|
27
27
|
): Promise<T> {
|
package/src/model-cache.ts
CHANGED
|
@@ -4,15 +4,17 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { Database } from "bun:sqlite";
|
|
6
6
|
import * as path from "node:path";
|
|
7
|
+
import { type } from "@linxiraos/pi-omptype";
|
|
7
8
|
import { getModelDbPath, isSqliteCorruptionError, logger, openSqliteDatabaseSync, VERSION } from "@linxiraos/pi-utils";
|
|
8
9
|
import RULES from "./compat/rules.json" with { type: "json" };
|
|
9
10
|
import type { Api, Model } from "./types";
|
|
10
11
|
|
|
11
12
|
// Rows persist fully materialized Models so compatible warm-cache reads do not
|
|
12
13
|
// rerun the compat cascade. Request headers are intentionally omitted:
|
|
13
|
-
// arbitrary provider-defined header names can carry credentials.
|
|
14
|
-
// invalidates
|
|
15
|
-
//
|
|
14
|
+
// arbitrary provider-defined header names can carry credentials. v15
|
|
15
|
+
// invalidates unbundled OpenAI-compatible rows that ignored provider-reported
|
|
16
|
+
// token limits. v14 invalidates Antigravity rows predating per-SKU
|
|
17
|
+
// `antigravityWireProfiles` (model_enum label, output cap, SKU thinking). v13 replaces
|
|
16
18
|
// sparse ModelSpec rows with materialized rows and records the exact app/rules/
|
|
17
19
|
// builder policy that produced them. v12 invalidated Kimi Code rows carrying the blanket
|
|
18
20
|
// maxTokens: 32000 that predate per-family output caps (k3/k3-256k -> 131072,
|
|
@@ -27,7 +29,7 @@ import type { Api, Model } from "./types";
|
|
|
27
29
|
// retired unknown-limit sentinels (222222/8888); v5 invalidated rows predating
|
|
28
30
|
// effort-tier variant collapsing (raw `-low`/`-high`/`-thinking` member ids);
|
|
29
31
|
// v4 dropped the pre-efforts ThinkingConfig shape.
|
|
30
|
-
const CACHE_SCHEMA_VERSION =
|
|
32
|
+
const CACHE_SCHEMA_VERSION = 15;
|
|
31
33
|
/** Oldest schema whose rows are guaranteed never to carry request headers. */
|
|
32
34
|
const FIRST_HEADERLESS_SCHEMA_VERSION = 11;
|
|
33
35
|
const HEADER_RESTORE_VERSION = 1;
|
|
@@ -444,61 +446,33 @@ function migrateCacheSchema(db: Database): void {
|
|
|
444
446
|
}
|
|
445
447
|
}
|
|
446
448
|
|
|
449
|
+
/**
|
|
450
|
+
* A cacheable materialized model. Also checked on the write side against
|
|
451
|
+
* in-memory models, so optional keys may be present as `undefined`.
|
|
452
|
+
*/
|
|
453
|
+
const MaterializedModel = type({
|
|
454
|
+
id: "string > 0",
|
|
455
|
+
name: "string > 0",
|
|
456
|
+
api: "string > 0",
|
|
457
|
+
provider: "string > 0",
|
|
458
|
+
// Empty is legitimate: Azure-style providers resolve the endpoint from
|
|
459
|
+
// configuration at request time, and their bundled rows carry "".
|
|
460
|
+
baseUrl: "string",
|
|
461
|
+
reasoning: "boolean",
|
|
462
|
+
input: "('text' | 'image')[] > 0",
|
|
463
|
+
"headers?": "undefined",
|
|
464
|
+
supportsComputerUseConfig: "boolean | null",
|
|
465
|
+
contextWindow: "number > 0 | null",
|
|
466
|
+
maxTokens: "number > 0 | null",
|
|
467
|
+
identity: { class: "string" },
|
|
468
|
+
"compat?": type("object")
|
|
469
|
+
.narrow(compat => !Array.isArray(compat))
|
|
470
|
+
.or("undefined"),
|
|
471
|
+
cost: { input: "number", output: "number", cacheRead: "number", cacheWrite: "number" },
|
|
472
|
+
});
|
|
473
|
+
|
|
447
474
|
function isMaterializedModel(value: unknown): value is PersistedModel<Api> {
|
|
448
|
-
|
|
449
|
-
const model = value as Partial<PersistedModel<Api>>;
|
|
450
|
-
if (
|
|
451
|
-
typeof model.id !== "string" ||
|
|
452
|
-
model.id.length === 0 ||
|
|
453
|
-
typeof model.name !== "string" ||
|
|
454
|
-
model.name.length === 0 ||
|
|
455
|
-
typeof model.api !== "string" ||
|
|
456
|
-
model.api.length === 0 ||
|
|
457
|
-
typeof model.provider !== "string" ||
|
|
458
|
-
model.provider.length === 0 ||
|
|
459
|
-
// Empty is legitimate: Azure-style providers resolve the endpoint from
|
|
460
|
-
// configuration at request time, and their bundled rows carry "".
|
|
461
|
-
typeof model.baseUrl !== "string" ||
|
|
462
|
-
typeof model.reasoning !== "boolean" ||
|
|
463
|
-
!Array.isArray(model.input) ||
|
|
464
|
-
model.input.length === 0 ||
|
|
465
|
-
model.input.some(input => input !== "text" && input !== "image") ||
|
|
466
|
-
model.headers !== undefined ||
|
|
467
|
-
!Object.hasOwn(model, "supportsComputerUseConfig") ||
|
|
468
|
-
(model.supportsComputerUseConfig !== null && typeof model.supportsComputerUseConfig !== "boolean")
|
|
469
|
-
) {
|
|
470
|
-
return false;
|
|
471
|
-
}
|
|
472
|
-
const contextWindow = model.contextWindow;
|
|
473
|
-
const maxTokens = model.maxTokens;
|
|
474
|
-
if (
|
|
475
|
-
(contextWindow !== null &&
|
|
476
|
-
(typeof contextWindow !== "number" || !Number.isFinite(contextWindow) || contextWindow <= 0)) ||
|
|
477
|
-
(maxTokens !== null && (typeof maxTokens !== "number" || !Number.isFinite(maxTokens) || maxTokens <= 0))
|
|
478
|
-
) {
|
|
479
|
-
return false;
|
|
480
|
-
}
|
|
481
|
-
if (
|
|
482
|
-
model.identity === null ||
|
|
483
|
-
typeof model.identity !== "object" ||
|
|
484
|
-
typeof model.identity.class !== "string" ||
|
|
485
|
-
(model.compat !== undefined &&
|
|
486
|
-
(model.compat === null || typeof model.compat !== "object" || Array.isArray(model.compat)))
|
|
487
|
-
) {
|
|
488
|
-
return false;
|
|
489
|
-
}
|
|
490
|
-
if (model.cost === null || typeof model.cost !== "object") return false;
|
|
491
|
-
const cost = model.cost as Partial<Model<Api>["cost"]>;
|
|
492
|
-
return (
|
|
493
|
-
typeof cost.input === "number" &&
|
|
494
|
-
Number.isFinite(cost.input) &&
|
|
495
|
-
typeof cost.output === "number" &&
|
|
496
|
-
Number.isFinite(cost.output) &&
|
|
497
|
-
typeof cost.cacheRead === "number" &&
|
|
498
|
-
Number.isFinite(cost.cacheRead) &&
|
|
499
|
-
typeof cost.cacheWrite === "number" &&
|
|
500
|
-
Number.isFinite(cost.cacheWrite)
|
|
501
|
-
);
|
|
475
|
+
return MaterializedModel.allows(value);
|
|
502
476
|
}
|
|
503
477
|
|
|
504
478
|
function parseMaterializedModels<TApi extends Api>(serialized: string): Model<TApi>[] | null {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Api, Model } from "./types";
|
|
2
|
+
import { isRecord } from "./utils";
|
|
2
3
|
|
|
3
4
|
// References are distinguished from JSON scalar values by their one-element array.
|
|
4
5
|
// -1 represents an explicitly present undefined value.
|
|
@@ -32,16 +33,12 @@ export interface ModelCatalog {
|
|
|
32
33
|
readonly compatValues: Map<string, Map<number, Map<string, Record<string, unknown>>>>;
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
function isObject(value: unknown): value is Record<string, unknown> {
|
|
36
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
36
|
// JSON serialization with sorted object keys gives both deterministic ordering
|
|
40
37
|
// and value-based interning, independent of the input objects' insertion order.
|
|
41
38
|
function canonical(value: unknown): string {
|
|
42
39
|
if (value === undefined) return "u";
|
|
43
40
|
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
44
|
-
if (
|
|
41
|
+
if (isRecord(value)) {
|
|
45
42
|
return `{${Object.keys(value)
|
|
46
43
|
.sort()
|
|
47
44
|
.map(key => `${JSON.stringify(key)}:${canonical(value[key])}`)
|
|
@@ -80,7 +77,7 @@ export function encodeModelCatalog(models: Record<string, Record<string, Model<A
|
|
|
80
77
|
let node: Node;
|
|
81
78
|
if (Array.isArray(value)) {
|
|
82
79
|
node = [1, value.map(encode)];
|
|
83
|
-
} else if (
|
|
80
|
+
} else if (isRecord(value)) {
|
|
84
81
|
const properties: EncodedValue[] = [];
|
|
85
82
|
const boolKeys: number[] = [];
|
|
86
83
|
const masks: number[] = [];
|
|
@@ -119,7 +116,7 @@ export function encodeModelCatalog(models: Record<string, Record<string, Model<A
|
|
|
119
116
|
for (const provider of Object.keys(models).sort()) {
|
|
120
117
|
for (const id of Object.keys(models[provider]).sort()) {
|
|
121
118
|
const model = models[provider][id];
|
|
122
|
-
if (typeof model.api !== "string" || !
|
|
119
|
+
if (typeof model.api !== "string" || !isRecord(model.compat)) continue;
|
|
123
120
|
let counts = compatCounts.get(model.api);
|
|
124
121
|
if (!counts) compatCounts.set(model.api, (counts = new Map()));
|
|
125
122
|
const signature = canonical(model.compat);
|
|
@@ -161,7 +158,7 @@ export function encodeModelCatalog(models: Record<string, Record<string, Model<A
|
|
|
161
158
|
const rest: Record<string, unknown> = Object.create(null);
|
|
162
159
|
const source = model as unknown as Record<string, unknown>;
|
|
163
160
|
const base = typeof model.api === "string" ? bases.get(model.api) : undefined;
|
|
164
|
-
const useBase = base !== undefined &&
|
|
161
|
+
const useBase = base !== undefined && isRecord(model.compat);
|
|
165
162
|
for (const key of Object.keys(source).sort()) {
|
|
166
163
|
if (Object.hasOwn(constants, key) || (key === "id" && source.id === id) || (key === "compat" && useBase))
|
|
167
164
|
continue;
|
package/src/model-manager.d.ts
CHANGED
|
@@ -129,9 +129,19 @@ export declare function createModelManager<TApi extends Api = Api, TModelsDevPay
|
|
|
129
129
|
* when at least one configured remote source did not refresh successfully.
|
|
130
130
|
*/
|
|
131
131
|
export declare function resolveProviderModels<TApi extends Api = Api, TModelsDevPayload = unknown>(options: ModelManagerOptions<TApi, TModelsDevPayload>, strategy?: ModelRefreshStrategy): Promise<ModelResolutionResult<TApi>>;
|
|
132
|
+
/**
|
|
133
|
+
* Merge policy that is part of a cache's identity in
|
|
134
|
+
* {@link fingerprintStaticModels}: `authoritative` when dynamic discovery owns
|
|
135
|
+
* the catalog, `additive` when the shared catalog may only add ids. The flags
|
|
136
|
+
* compose; snapshots written under different policies never match.
|
|
137
|
+
*/
|
|
138
|
+
export interface StaticFingerprintPolicy {
|
|
139
|
+
authoritative?: boolean;
|
|
140
|
+
additive?: boolean;
|
|
141
|
+
}
|
|
132
142
|
/**
|
|
133
143
|
* Return the versioned content identity for a static provider slice. Callers
|
|
134
144
|
* may mutate or freeze their arrays, so every call observes current content
|
|
135
145
|
* and never attaches a stale sidecar fingerprint to caller-owned data.
|
|
136
146
|
*/
|
|
137
|
-
export declare function fingerprintStaticModels<TApi extends Api>(models: readonly (ModelSpec<TApi> | Model<TApi>)[],
|
|
147
|
+
export declare function fingerprintStaticModels<TApi extends Api>(models: readonly (ModelSpec<TApi> | Model<TApi>)[], policy?: StaticFingerprintPolicy): string;
|