@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.
Files changed (104) hide show
  1. package/CHANGELOG.md +6 -2
  2. package/README.md +3 -3
  3. package/dist/types/build.d.ts +12 -4
  4. package/dist/types/compat/auth-ids.d.ts +2 -2
  5. package/dist/types/compat/catalog-policy.d.ts +6 -4
  6. package/dist/types/compat/factory-droid.d.ts +7 -1
  7. package/dist/types/compat/provider-ids.d.ts +1 -1
  8. package/dist/types/compat/resolve.d.ts +1 -1
  9. package/dist/types/compat/revision.d.ts +2 -0
  10. package/dist/types/compat/server-side-fallback.d.ts +6 -4
  11. package/dist/types/compat/types.d.ts +6 -2
  12. package/dist/types/discovery/codex.d.ts +4 -5
  13. package/dist/types/discovery/cursor-proto.d.ts +8 -0
  14. package/dist/types/discovery/openai-compatible.d.ts +6 -0
  15. package/dist/types/model-cache.d.ts +8 -0
  16. package/dist/types/model-catalog-format.d.ts +37 -0
  17. package/dist/types/model-manager.d.ts +11 -1
  18. package/dist/types/model-thinking.d.ts +4 -0
  19. package/dist/types/models.d.ts +22 -3
  20. package/dist/types/pricing.d.ts +66 -6
  21. package/dist/types/provider-models/openai-compat.d.ts +18 -13
  22. package/dist/types/types.d.ts +14 -19
  23. package/dist/types/utils.d.ts +8 -0
  24. package/dist/types/wire/codex.d.ts +1 -1
  25. package/package.json +6 -10
  26. package/src/build.d.ts +12 -4
  27. package/src/build.ts +50 -3
  28. package/src/compat/auth-ids.ts +5 -0
  29. package/src/compat/axes.ts +27 -9
  30. package/src/compat/catalog-policy.d.ts +9 -0
  31. package/src/compat/catalog-policy.ts +14 -10
  32. package/src/compat/collapse.ts +1 -1
  33. package/src/compat/factory-droid.d.ts +7 -1
  34. package/src/compat/factory-droid.ts +9 -1
  35. package/src/compat/provider-ids.d.ts +1 -1
  36. package/src/compat/provider-ids.ts +2 -0
  37. package/src/compat/resolve.d.ts +1 -1
  38. package/src/compat/resolve.ts +4 -5
  39. package/src/compat/revision.d.ts +2 -0
  40. package/src/compat/revision.ts +10 -0
  41. package/src/compat/rules/README.md +14 -12
  42. package/src/compat/rules/auth/_order.kdl +1 -1
  43. package/src/compat/rules/auth/mistral.kdl +4 -0
  44. package/src/compat/rules/auth/modular.kdl +9 -0
  45. package/src/compat/rules/auth/scaleway.kdl +17 -0
  46. package/src/compat/rules/auth/typesafe.kdl +2 -1
  47. package/src/compat/rules/classes/anthropic.kdl +5 -0
  48. package/src/compat/rules/classes/deepseek.kdl +3 -2
  49. package/src/compat/rules/classes/gemini.kdl +1 -1
  50. package/src/compat/rules/classes/openai.kdl +2 -2
  51. package/src/compat/rules/classes/xai.kdl +1 -1
  52. package/src/compat/rules/providers/anthropic.kdl +8 -4
  53. package/src/compat/rules/providers/cursor.kdl +10 -0
  54. package/src/compat/rules/providers/deepseek.kdl +2 -2
  55. package/src/compat/rules/providers/factory-droid.kdl +243 -13
  56. package/src/compat/rules/providers/google-vertex.kdl +3 -0
  57. package/src/compat/rules/providers/kimi-code.kdl +6 -0
  58. package/src/compat/rules/providers/mistral.kdl +8 -0
  59. package/src/compat/rules/providers/modular.kdl +35 -0
  60. package/src/compat/rules/providers/openai-codex.kdl +1 -1
  61. package/src/compat/rules/providers/sambanova.kdl +2 -0
  62. package/src/compat/rules/providers/scaleway.kdl +179 -0
  63. package/src/compat/rules/runtime/behavior.kdl +22 -6
  64. package/src/compat/rules.json +1 -1
  65. package/src/compat/server-side-fallback.d.ts +9 -0
  66. package/src/compat/server-side-fallback.ts +7 -5
  67. package/src/compat/types.d.ts +6 -2
  68. package/src/compat/types.ts +6 -2
  69. package/src/discovery/codex.d.ts +4 -5
  70. package/src/discovery/codex.ts +7 -15
  71. package/src/discovery/cursor-proto.d.ts +8 -0
  72. package/src/discovery/cursor-proto.ts +12 -1
  73. package/src/discovery/factory-droid.ts +35 -11
  74. package/src/discovery/openai-compatible.d.ts +6 -0
  75. package/src/discovery/openai-compatible.ts +1 -1
  76. package/src/model-cache.d.ts +8 -0
  77. package/src/model-cache.ts +83 -61
  78. package/src/model-catalog-format.d.ts +37 -0
  79. package/src/model-catalog-format.ts +296 -0
  80. package/src/model-manager.d.ts +11 -1
  81. package/src/model-manager.ts +85 -143
  82. package/src/model-thinking.d.ts +4 -0
  83. package/src/model-thinking.ts +10 -0
  84. package/src/model-tokenizer.ts +13 -12
  85. package/src/models.d.ts +22 -3
  86. package/src/models.json +1 -1
  87. package/src/models.ts +48 -11
  88. package/src/pricing.d.ts +66 -6
  89. package/src/pricing.ts +59 -94
  90. package/src/provider-models/cache-provider-id.ts +23 -6
  91. package/src/provider-models/catalog-snapshot.json.zst +0 -0
  92. package/src/provider-models/catalog-snapshot.json.zst.d.ts +3 -0
  93. package/src/provider-models/descriptors.ts +2 -0
  94. package/src/provider-models/openai-compat.d.ts +18 -13
  95. package/src/provider-models/openai-compat.ts +203 -94
  96. package/src/provider-models/special.ts +5 -6
  97. package/src/types.d.ts +14 -19
  98. package/src/types.ts +11 -18
  99. package/src/utils.d.ts +8 -0
  100. package/src/utils.ts +18 -0
  101. package/src/wire/codex.d.ts +1 -1
  102. package/src/wire/codex.ts +1 -1
  103. package/src/wire/factory-droid.ts +4 -3
  104. package/src/models.json.d.ts +0 -9
package/src/models.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { classifyModel } from "./compat/taxonomy";
2
- import MODELS from "./models.json" with { type: "json" };
3
- import { dueEffectiveRate } from "./pricing";
2
+ import { getCatalogProvider, getCatalogProviders, openModelCatalog } from "./model-catalog-format";
3
+ import modelsData from "./models.json" with { type: "json" };
4
+ import { dueDatedCard, dueEffectiveRate } from "./pricing";
4
5
  import type {
5
6
  Api,
6
7
  EffectiveTokenCost,
@@ -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
- if (!Object.hasOwn(MODELS, provider)) return undefined;
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
- // models.json rows are complete Models emitted by generate-models.ts;
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
- export type GeneratedProvider = keyof typeof MODELS;
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 Object.hasOwn(MODELS, provider);
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
- export function getBundledProviders(): KnownProvider[] {
60
- return Object.keys(MODELS) as KnownProvider[];
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>[]) : [];
@@ -71,6 +77,37 @@ export function getModelPricingStatus(model: Pick<Model<Api>, "cost" | "pricingS
71
77
  return model.pricingStatus ?? "unknown";
72
78
  }
73
79
 
80
+ /** Factory Droid credit rate in force at a time, and the next dated change to it. */
81
+ export interface FactoryDroidCreditRate {
82
+ rate: number;
83
+ /** The earliest later `credit-rates` card that changes `rate`: the rate it sets and when (Unix ms). */
84
+ next?: { rate: number; at: number };
85
+ }
86
+
87
+ /**
88
+ * Factory Droid Standard Credits rate at `timestamp` (Unix ms, default now):
89
+ * the `input` of the `credit-rates` card due then (the latest at or before
90
+ * it, as for cost cards), else the base rate. Undefined for models without a
91
+ * credit rate.
92
+ */
93
+ export function getFactoryDroidCreditRate(
94
+ model: Pick<Model, "factoryDroidCredits" | "factoryDroidCreditCards">,
95
+ timestamp = Date.now(),
96
+ ): FactoryDroidCreditRate | undefined {
97
+ const base = model.factoryDroidCredits;
98
+ if (base === undefined) return undefined;
99
+ const cards = model.factoryDroidCreditCards ?? [];
100
+ const rate = dueDatedCard(cards, timestamp)?.input ?? base;
101
+ let next: FactoryDroidCreditRate["next"];
102
+ for (const card of cards) {
103
+ const cardRate = card.input ?? base;
104
+ if (card.effectiveFrom > timestamp && cardRate !== rate && !(next && next.at <= card.effectiveFrom)) {
105
+ next = { rate: cardRate, at: card.effectiveFrom };
106
+ }
107
+ }
108
+ return next ? { rate, next } : { rate };
109
+ }
110
+
74
111
  /**
75
112
  * The base token card in force at `timestamp` (Unix ms, default now): the
76
113
  * latest due `timeBased` effective rate, else the row's own legs. Price
package/src/pricing.d.ts CHANGED
@@ -1,24 +1,84 @@
1
1
  import type { EffectiveTokenCost, ModelCost, TimeBasedCost, TokenCost } from "./types";
2
+ /** Serialized time-based pricing schedule, as cached model rows carry it. */
3
+ export declare const TimeBasedCostShape: import("@linxiraos/pi-omptype").FluentType<{
4
+ effectiveRates?: ({
5
+ cacheRead: number;
6
+ cacheWrite: number;
7
+ input: number;
8
+ output: number;
9
+ } & {
10
+ effectiveFrom: number;
11
+ longContext?: ({
12
+ cacheRead: number;
13
+ cacheWrite: number;
14
+ input: number;
15
+ output: number;
16
+ } & {
17
+ inputThreshold: number;
18
+ inputThresholdInclusive?: boolean | undefined;
19
+ }) | undefined;
20
+ })[] | undefined;
21
+ offPeakMultiplier: number;
22
+ peakWindows: {
23
+ endMinute: number;
24
+ startMinute: number;
25
+ weekdays: number[];
26
+ }[];
27
+ }, {
28
+ effectiveRates?: ({
29
+ cacheRead: number;
30
+ cacheWrite: number;
31
+ input: number;
32
+ output: number;
33
+ } & {
34
+ effectiveFrom: number;
35
+ longContext?: ({
36
+ cacheRead: number;
37
+ cacheWrite: number;
38
+ input: number;
39
+ output: number;
40
+ } & {
41
+ inputThreshold: number;
42
+ inputThresholdInclusive?: boolean | undefined;
43
+ }) | undefined;
44
+ })[] | undefined;
45
+ offPeakMultiplier: number;
46
+ peakWindows: {
47
+ endMinute: number;
48
+ startMinute: number;
49
+ weekdays: number[];
50
+ }[];
51
+ }>;
2
52
  /** Validate serialized schedules before admitting cached model rows. */
3
53
  export declare function isTimeBasedCost(value: unknown): value is TimeBasedCost;
4
54
  /** KDL object children are named records; normalize them once while constructing the model. */
5
55
  export declare function materializeTimeBasedCost(value: unknown): TimeBasedCost;
56
+ /**
57
+ * The dated card due at `timestamp`: the one with the latest `effectiveFrom`
58
+ * at or before it, in any order, or undefined before the first card.
59
+ */
60
+ export declare function dueDatedCard<T extends {
61
+ effectiveFrom: number;
62
+ }>(cards: readonly T[], timestamp: number): T | undefined;
6
63
  /**
7
64
  * The latest `effectiveRates` card of a materialized schedule due at
8
65
  * `timestamp`, or undefined before the first one (or without a schedule).
9
66
  */
10
67
  export declare function dueEffectiveRate(schedule: TimeBasedCost | undefined, timestamp: number): EffectiveTokenCost | undefined;
11
- /** A `cost-patch`/`cost-fallback` dated card: the legs it overwrites from `effectiveFrom` (Unix ms). */
68
+ /**
69
+ * A dated `effective-rates` card of a `cost-patch`, `cost-fallback` or
70
+ * `credit-rates` rule: the legs it overwrites from `effectiveFrom` (Unix ms).
71
+ */
12
72
  export interface DatedCostCard extends Partial<TokenCost> {
13
73
  effectiveFrom: number;
14
74
  }
15
75
  /**
16
- * Parse the compiled `effective-rates` block of a `cost-patch` or
17
- * `cost-fallback` payload into dated cards, ascending by date. Throws on a
18
- * malformed card, so a typo in a rule fails the build instead of silently
19
- * leaving the old price in force.
76
+ * Parse the compiled `effective-rates` block of a `cost-patch`,
77
+ * `cost-fallback` or Factory Droid `credit-rates` payload into dated cards,
78
+ * ascending by date. Throws on a malformed card, so a typo in a rule fails the
79
+ * build instead of silently leaving the old price in force.
20
80
  */
21
- export declare function parseDatedCostCards(costAxis: unknown, axis: "cost-patch" | "cost-fallback"): DatedCostCard[];
81
+ export declare function parseDatedCostCards(costAxis: unknown, axis: "cost-patch" | "cost-fallback" | "credit-rates"): DatedCostCard[];
22
82
  /**
23
83
  * Earliest instant a rate card can name (the `Date` range minimum). A leading
24
84
  * card from here holds the price in force before the first dated change.
package/src/pricing.ts CHANGED
@@ -1,84 +1,35 @@
1
- import type {
2
- EffectiveTokenCost,
3
- LongContextTokenCost,
4
- ModelCost,
5
- PeakPricingWindow,
6
- TimeBasedCost,
7
- TokenCost,
8
- } from "./types";
1
+ import { type } from "@linxiraos/pi-omptype";
2
+ import type { EffectiveTokenCost, ModelCost, TimeBasedCost, TokenCost } from "./types";
9
3
  import { isRecord } from "./utils";
10
4
 
11
- function nonnegative(value: unknown): value is number {
12
- return typeof value === "number" && Number.isFinite(value) && value >= 0;
13
- }
14
-
15
- function isRates(value: unknown): value is TokenCost {
16
- return (
17
- isRecord(value) &&
18
- nonnegative(value.input) &&
19
- nonnegative(value.output) &&
20
- nonnegative(value.cacheRead) &&
21
- nonnegative(value.cacheWrite)
22
- );
23
- }
24
-
25
- function isLongContext(value: unknown): value is LongContextTokenCost {
26
- return (
27
- isRecord(value) &&
28
- isRates(value) &&
29
- typeof value.inputThreshold === "number" &&
30
- Number.isFinite(value.inputThreshold) &&
31
- value.inputThreshold > 0 &&
32
- (value.inputThresholdInclusive === undefined || typeof value.inputThresholdInclusive === "boolean")
33
- );
34
- }
35
-
36
- function isPeakWindow(value: unknown): value is PeakPricingWindow {
37
- return (
38
- isRecord(value) &&
39
- Array.isArray(value.weekdays) &&
40
- value.weekdays.length > 0 &&
41
- value.weekdays.every(day => Number.isInteger(day) && day >= 0 && day <= 6) &&
42
- new Set(value.weekdays).size === value.weekdays.length &&
43
- typeof value.startMinute === "number" &&
44
- Number.isInteger(value.startMinute) &&
45
- typeof value.endMinute === "number" &&
46
- Number.isInteger(value.endMinute) &&
47
- value.startMinute >= 0 &&
48
- value.endMinute <= 1440 &&
49
- value.startMinute < value.endMinute
50
- );
51
- }
52
-
53
- function isEffectiveRate(value: unknown): value is EffectiveTokenCost {
54
- return (
55
- isRecord(value) &&
56
- isRates(value) &&
57
- typeof value.effectiveFrom === "number" &&
58
- Number.isSafeInteger(value.effectiveFrom) &&
59
- Math.abs(value.effectiveFrom) <= 8_640_000_000_000_000 &&
60
- (value.longContext === undefined || isLongContext(value.longContext))
61
- );
62
- }
5
+ // Schedules are also checked on in-memory discovery output, where absent optionals may be explicit `undefined`.
6
+ const Rate = type("number >= 0");
7
+ const Rates = type({ input: Rate, output: Rate, cacheRead: Rate, cacheWrite: Rate });
8
+ const LongContext = Rates.and({ inputThreshold: "number > 0", "inputThresholdInclusive?": "boolean | undefined" });
9
+ const PeakWindow = type({
10
+ weekdays: type("0 <= number.integer <= 6").array().atLeastLength(1),
11
+ startMinute: "number.integer >= 0",
12
+ endMinute: "number.integer <= 1440",
13
+ }).narrow(window => new Set(window.weekdays).size === window.weekdays.length && window.startMinute < window.endMinute);
14
+ const EffectiveRate = Rates.and({
15
+ // The `Date` range.
16
+ effectiveFrom: "-8640000000000000 <= number.integer <= 8640000000000000",
17
+ "longContext?": LongContext.or("undefined"),
18
+ });
19
+ /** Serialized time-based pricing schedule, as cached model rows carry it. */
20
+ export const TimeBasedCostShape = type({
21
+ offPeakMultiplier: Rate,
22
+ peakWindows: PeakWindow.array(),
23
+ "effectiveRates?": EffectiveRate.array().or("undefined"),
24
+ }).narrow(
25
+ cost =>
26
+ cost.effectiveRates === undefined ||
27
+ new Set(cost.effectiveRates.map(rate => rate.effectiveFrom)).size === cost.effectiveRates.length,
28
+ );
63
29
 
64
30
  /** Validate serialized schedules before admitting cached model rows. */
65
31
  export function isTimeBasedCost(value: unknown): value is TimeBasedCost {
66
- if (
67
- !isRecord(value) ||
68
- !nonnegative(value.offPeakMultiplier) ||
69
- !Array.isArray(value.peakWindows) ||
70
- !value.peakWindows.every(isPeakWindow)
71
- ) {
72
- return false;
73
- }
74
- if (value.effectiveRates === undefined) return true;
75
- if (!Array.isArray(value.effectiveRates) || !value.effectiveRates.every(isEffectiveRate)) return false;
76
- const dates = new Set<number>();
77
- for (const rate of value.effectiveRates) {
78
- if (dates.has(rate.effectiveFrom)) return false;
79
- dates.add(rate.effectiveFrom);
80
- }
81
- return true;
32
+ return TimeBasedCostShape.allows(value);
82
33
  }
83
34
 
84
35
  function payload(value: unknown, keys: readonly string[], field: string): Record<string, unknown> {
@@ -148,15 +99,15 @@ export function materializeTimeBasedCost(value: unknown): TimeBasedCost {
148
99
  }
149
100
 
150
101
  /**
151
- * The latest `effectiveRates` card of a materialized schedule due at
152
- * `timestamp`, or undefined before the first one (or without a schedule).
102
+ * The dated card due at `timestamp`: the one with the latest `effectiveFrom`
103
+ * at or before it, in any order, or undefined before the first card.
153
104
  */
154
- export function dueEffectiveRate(
155
- schedule: TimeBasedCost | undefined,
105
+ export function dueDatedCard<T extends { effectiveFrom: number }>(
106
+ cards: readonly T[],
156
107
  timestamp: number,
157
- ): EffectiveTokenCost | undefined {
158
- let due: EffectiveTokenCost | undefined;
159
- for (const candidate of schedule?.effectiveRates ?? []) {
108
+ ): T | undefined {
109
+ let due: T | undefined;
110
+ for (const candidate of cards) {
160
111
  if (candidate.effectiveFrom <= timestamp && (due === undefined || candidate.effectiveFrom > due.effectiveFrom)) {
161
112
  due = candidate;
162
113
  }
@@ -164,21 +115,38 @@ export function dueEffectiveRate(
164
115
  return due;
165
116
  }
166
117
 
118
+ /**
119
+ * The latest `effectiveRates` card of a materialized schedule due at
120
+ * `timestamp`, or undefined before the first one (or without a schedule).
121
+ */
122
+ export function dueEffectiveRate(
123
+ schedule: TimeBasedCost | undefined,
124
+ timestamp: number,
125
+ ): EffectiveTokenCost | undefined {
126
+ return dueDatedCard(schedule?.effectiveRates ?? [], timestamp);
127
+ }
128
+
167
129
  const TOKEN_COST_LEGS = ["input", "output", "cacheRead", "cacheWrite"] as const;
168
130
  const DATED_CARD_KEYS: readonly string[] = ["effectiveFrom", ...TOKEN_COST_LEGS];
169
131
 
170
- /** A `cost-patch`/`cost-fallback` dated card: the legs it overwrites from `effectiveFrom` (Unix ms). */
132
+ /**
133
+ * A dated `effective-rates` card of a `cost-patch`, `cost-fallback` or
134
+ * `credit-rates` rule: the legs it overwrites from `effectiveFrom` (Unix ms).
135
+ */
171
136
  export interface DatedCostCard extends Partial<TokenCost> {
172
137
  effectiveFrom: number;
173
138
  }
174
139
 
175
140
  /**
176
- * Parse the compiled `effective-rates` block of a `cost-patch` or
177
- * `cost-fallback` payload into dated cards, ascending by date. Throws on a
178
- * malformed card, so a typo in a rule fails the build instead of silently
179
- * leaving the old price in force.
141
+ * Parse the compiled `effective-rates` block of a `cost-patch`,
142
+ * `cost-fallback` or Factory Droid `credit-rates` payload into dated cards,
143
+ * ascending by date. Throws on a malformed card, so a typo in a rule fails the
144
+ * build instead of silently leaving the old price in force.
180
145
  */
181
- export function parseDatedCostCards(costAxis: unknown, axis: "cost-patch" | "cost-fallback"): DatedCostCard[] {
146
+ export function parseDatedCostCards(
147
+ costAxis: unknown,
148
+ axis: "cost-patch" | "cost-fallback" | "credit-rates",
149
+ ): DatedCostCard[] {
182
150
  const effectiveRates = isRecord(costAxis) ? costAxis.effectiveRates : undefined;
183
151
  if (effectiveRates === undefined) return [];
184
152
  if (!isRecord(effectiveRates)) throw new Error(`Invalid ${axis} effective-rates: expected named objects`);
@@ -190,7 +158,7 @@ export function parseDatedCostCards(costAxis: unknown, axis: "cost-patch" | "cos
190
158
  for (const leg of TOKEN_COST_LEGS) {
191
159
  const value = entry[leg];
192
160
  if (value === undefined) continue;
193
- if (!nonnegative(value))
161
+ if (!Rate.allows(value))
194
162
  throw new Error(`Invalid ${axis} effective-rate ${leg}: expected a nonnegative number`);
195
163
  card[leg] = value;
196
164
  }
@@ -235,10 +203,7 @@ export function datedCost(base: TokenCost, cards: readonly DatedCostCard[], now
235
203
  * `cost` unchanged before the first card.
236
204
  */
237
205
  export function applyDueDatedCostCard(cost: TokenCost, cards: readonly DatedCostCard[], now = Date.now()): void {
238
- let due: DatedCostCard | undefined;
239
- for (const card of cards) {
240
- if (card.effectiveFrom <= now) due = card;
241
- }
206
+ const due = dueDatedCard(cards, now);
242
207
  if (due === undefined) return;
243
208
  for (const leg of TOKEN_COST_LEGS) {
244
209
  const value = due[leg];
@@ -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 Cursor access token. Cursor access tokens are JWTs
75
- * that `refreshCursorToken` rotates (new `exp`/`iat`) for the same account,
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 cursorCredentialSubject(apiKey: string): string | undefined {
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 = `${cursorCredentialSubject(apiKey) ?? apiKey}\u0000${baseUrl}`;
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,7 +176,8 @@ export function resolveModelCacheProviderId(providerId: string, options: ModelCa
160
176
  }
161
177
  case "litellm": {
162
178
  const baseUrl = options.baseUrl ?? getDefaultModelDiscoveryBaseUrl(providerId)!;
163
- // rich-v13 moves `mode: decisions` groups off chat onto the Decisions runner.
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.
164
181
  // rich-v12 invalidates namespaced ids that missed bare catalog references.
165
182
  // rich-v11 excluded ClinePass gateway metadata (issue #10932). rich-v10
166
183
  // filtered known non-conversational LiteLLM modes, unioned compat across
@@ -168,7 +185,7 @@ export function resolveModelCacheProviderId(providerId: string, options: ModelCa
168
185
  // declaration into it; earlier versions invalidated rows whose
169
186
  // `compatConfig` retained a colliding bundled model's provider-specific
170
187
  // transport (e.g. Fireworks `wireModelIdMode`) (issue #9938).
171
- return `litellm:rich-v13:${Bun.hash(baseUrl).toString(36)}`;
188
+ return `litellm:rich-v14:${Bun.hash(baseUrl).toString(36)}`;
172
189
  }
173
190
  case "gmi-cloud":
174
191
  case "siliconflow":
@@ -0,0 +1,3 @@
1
+ /** Bundled asset path (imported `with { type: "file" }`). */
2
+ declare const path: string;
3
+ export default path;
@@ -61,6 +61,7 @@ import {
61
61
  qwenPortalModelManagerOptions,
62
62
  sakanaModelManagerOptions,
63
63
  sambanovaModelManagerOptions,
64
+ scalewayModelManagerOptions,
64
65
  siliconflowCnModelManagerOptions,
65
66
  siliconflowModelManagerOptions,
66
67
  singularityApiDevModelManagerOptions,
@@ -150,6 +151,7 @@ const MODEL_MANAGER_FACTORIES: Readonly<Partial<Record<KnownProvider, ModelManag
150
151
  "qwen-portal": config => qwenPortalModelManagerOptions(config),
151
152
  sakana: config => sakanaModelManagerOptions(config),
152
153
  sambanova: config => sambanovaModelManagerOptions(config),
154
+ scaleway: config => scalewayModelManagerOptions(config),
153
155
  siliconflow: config => siliconflowModelManagerOptions(config),
154
156
  "siliconflow-cn": config => siliconflowCnModelManagerOptions(config),
155
157
  "singularityapi-dev": config => singularityApiDevModelManagerOptions(config),
@@ -36,19 +36,6 @@ export interface ModelsDevModel {
36
36
  int?: number;
37
37
  tps?: number;
38
38
  }
39
- /**
40
- * Fetches the models.dev catalog via catalog.stencil.so, which serves a
41
- * field-pruned copy precompressed as a zstd blob (~93 KB vs ~3.3 MB raw).
42
- * The frame magic is sniffed rather than trusting content-type so plain-JSON
43
- * responses (test stubs, fallback mirrors) parse identically.
44
- *
45
- * Fetched fully once per fetch context: concurrent callers sharing a fetch
46
- * implementation reuse one transport request, while repeat callers send a
47
- * conditional GET that the server answers with `304`. Each subscriber may stop
48
- * waiting independently; the shared transport retains its own hard deadline.
49
- * Transient failures reuse the last in-memory payload for callers that only
50
- * need best-effort metadata.
51
- */
52
39
  export declare function fetchWellKnownModels(fetchImpl?: FetchImpl, signal?: AbortSignal): Promise<unknown>;
53
40
  type SimpleProviderDiscoveryHeaders = Record<string, string> | (() => Record<string, string> | undefined);
54
41
  type SimpleProviderConfig = {
@@ -740,3 +727,21 @@ export declare function singularityApiDevModelManagerOptions(config?: Singularit
740
727
  * reviewed KDL rules own the wire shape, limits patch, and effort ladder.
741
728
  */
742
729
  export declare function singularityApiTechModelManagerOptions(config?: SingularityApiModelManagerConfig): ModelManagerOptions<Api>;
730
+ /**
731
+ * Scaleway discovery configuration: the API key plus optional base-URL and
732
+ * fetch overrides. Consumed by {@link scalewayModelManagerOptions}, and
733
+ * exported for extensions and tests that construct the manager directly.
734
+ */
735
+ export interface ScalewayModelManagerConfig {
736
+ apiKey?: string;
737
+ baseUrl?: string;
738
+ fetch?: FetchImpl;
739
+ }
740
+ /**
741
+ * Scaleway model manager: plain OpenAI-compatible chat completions at
742
+ * `api.scaleway.ai/v1` (fr-par serverless Generative APIs). `/v1/models`
743
+ * returns bare ids, so the authored seed in `providers/scaleway.kdl` is the
744
+ * reference each live row merges names, modalities, prices, and limits from;
745
+ * a successful fetch is the complete roster and prunes retired rows.
746
+ */
747
+ export declare function scalewayModelManagerOptions(config?: ScalewayModelManagerConfig): ModelManagerOptions<"openai-completions">;