@linxiraos/pi-catalog 1.1.8 → 1.1.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 (88) hide show
  1. package/CHANGELOG.md +2 -3
  2. package/package.json +96 -102
  3. package/src/compat/axes.ts +11 -0
  4. package/src/compat/delegation.ts +37 -0
  5. package/src/compat/resolve.ts +2 -0
  6. package/src/compat/rules/README.md +5 -5
  7. package/src/compat/rules/auth/openai-codex.kdl +1 -1
  8. package/src/compat/rules/auth/zai-coding-plan.kdl +7 -3
  9. package/src/compat/rules/classes/openai.kdl +16 -0
  10. package/src/compat/rules/providers/openai-codex.kdl +2 -2
  11. package/src/compat/rules/providers/openai.kdl +1 -1
  12. package/src/compat/rules.json +67 -16
  13. package/src/compat/types.ts +4 -2
  14. package/src/discovery/codex.ts +10 -0
  15. package/src/identity/metrics.ts +165 -0
  16. package/src/identity/reference.ts +7 -1
  17. package/src/model-manager.ts +15 -2
  18. package/src/models.json +4861 -382
  19. package/src/provider-models/openai-compat.ts +4 -0
  20. package/src/provider-models/special.ts +25 -10
  21. package/src/types.ts +17 -0
  22. package/src/wire/codex.ts +23 -2
  23. package/THIRD-PARTY-NOTICES.txt +0 -22909
  24. package/dist/types/build.d.ts +0 -24
  25. package/dist/types/cline-pass-model-id.d.ts +0 -4
  26. package/dist/types/compat/anthropic.d.ts +0 -24
  27. package/dist/types/compat/apply.d.ts +0 -7
  28. package/dist/types/compat/auth-ids.d.ts +0 -4
  29. package/dist/types/compat/auth.d.ts +0 -7
  30. package/dist/types/compat/axes.d.ts +0 -50
  31. package/dist/types/compat/behavior.d.ts +0 -69
  32. package/dist/types/compat/cascade.d.ts +0 -37
  33. package/dist/types/compat/collapse.d.ts +0 -171
  34. package/dist/types/compat/openai.d.ts +0 -9
  35. package/dist/types/compat/resolve.d.ts +0 -15
  36. package/dist/types/compat/revision.d.ts +0 -41
  37. package/dist/types/compat/taxonomy.d.ts +0 -93
  38. package/dist/types/compat/types.d.ts +0 -565
  39. package/dist/types/discovery/antigravity.d.ts +0 -70
  40. package/dist/types/discovery/codex.d.ts +0 -36
  41. package/dist/types/discovery/cursor-proto.d.ts +0 -5368
  42. package/dist/types/discovery/cursor.d.ts +0 -31
  43. package/dist/types/discovery/devin-proto.d.ts +0 -1912
  44. package/dist/types/discovery/devin.d.ts +0 -24
  45. package/dist/types/discovery/gemini-cli.d.ts +0 -33
  46. package/dist/types/discovery/gemini.d.ts +0 -25
  47. package/dist/types/discovery/gitlab-duo-workflow.d.ts +0 -30
  48. package/dist/types/discovery/index.d.ts +0 -7
  49. package/dist/types/discovery/openai-compatible.d.ts +0 -89
  50. package/dist/types/discovery/protobuf.d.ts +0 -102
  51. package/dist/types/effort.d.ts +0 -10
  52. package/dist/types/fireworks-model-id.d.ts +0 -23
  53. package/dist/types/hosts.d.ts +0 -169
  54. package/dist/types/identity/bundled.d.ts +0 -3
  55. package/dist/types/identity/dialect.d.ts +0 -3
  56. package/dist/types/identity/id.d.ts +0 -13
  57. package/dist/types/identity/index.d.ts +0 -8
  58. package/dist/types/identity/priority.d.ts +0 -1
  59. package/dist/types/identity/reference.d.ts +0 -19
  60. package/dist/types/index.d.ts +0 -19
  61. package/dist/types/model-cache.d.ts +0 -23
  62. package/dist/types/model-manager.d.ts +0 -93
  63. package/dist/types/model-thinking.d.ts +0 -63
  64. package/dist/types/model-tokenizer.d.ts +0 -8
  65. package/dist/types/models.d.ts +0 -17
  66. package/dist/types/provider-models/bundled-references.d.ts +0 -13
  67. package/dist/types/provider-models/cache-provider-id.d.ts +0 -11
  68. package/dist/types/provider-models/cline-pass.d.ts +0 -22
  69. package/dist/types/provider-models/descriptor-types.d.ts +0 -76
  70. package/dist/types/provider-models/descriptors.d.ts +0 -543
  71. package/dist/types/provider-models/google.d.ts +0 -29
  72. package/dist/types/provider-models/index.d.ts +0 -7
  73. package/dist/types/provider-models/models-dev-policies.d.ts +0 -9
  74. package/dist/types/provider-models/ollama.d.ts +0 -22
  75. package/dist/types/provider-models/openai-compat.d.ts +0 -716
  76. package/dist/types/provider-models/special.d.ts +0 -74
  77. package/dist/types/types.d.ts +0 -1043
  78. package/dist/types/utils.d.ts +0 -20
  79. package/dist/types/wire/alibaba-token-plan.d.ts +0 -22
  80. package/dist/types/wire/cline-pass.d.ts +0 -21
  81. package/dist/types/wire/cloudflare-ai-gateway.d.ts +0 -18
  82. package/dist/types/wire/codex.d.ts +0 -66
  83. package/dist/types/wire/coreweave.d.ts +0 -12
  84. package/dist/types/wire/devin-proto.d.ts +0 -14
  85. package/dist/types/wire/devin.d.ts +0 -36
  86. package/dist/types/wire/gemini-headers.d.ts +0 -62
  87. package/dist/types/wire/github-copilot.d.ts +0 -66
  88. package/dist/types/wire/image-fetchers.d.ts +0 -76
@@ -110,6 +110,13 @@ export interface CodexModelDiscoveryOptions {
110
110
  export interface CodexModelDiscoveryResult {
111
111
  models: ModelSpec<"openai-codex-responses">[];
112
112
  etag?: string;
113
+ /**
114
+ * Set when the backend rejected the credential itself (401/403, e.g.
115
+ * `token_revoked`); `models` is empty. A definitive per-account denial,
116
+ * unlike the `null` result for transport/parse failures, so multi-account
117
+ * discovery can skip the account instead of aborting.
118
+ */
119
+ rejectedStatus?: 401 | 403;
113
120
  }
114
121
 
115
122
  /**
@@ -139,6 +146,9 @@ export async function fetchCodexModels(options: CodexModelDiscoveryOptions): Pro
139
146
  continue;
140
147
  }
141
148
 
149
+ if (response.status === 401 || response.status === 403) {
150
+ return { models: [], rejectedStatus: response.status };
151
+ }
142
152
  if (!response.ok) {
143
153
  continue;
144
154
  }
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Catalog metric lookup (intelligence / speed scores) across provider id
3
+ * dialects. The shared catalog scores a model once under its vendor id
4
+ * (`claude-fable-5-1`); hosts re-spell it (`anthropic/claude-fable-5.1`,
5
+ * `global.anthropic.claude-fable-5-1`, `claude-fable-5-1-high`, `k3`), so an
6
+ * index keyed by exact id leaves most of the picker blank.
7
+ *
8
+ * Resolution order, first hit wins:
9
+ * 1. exact lowercased id;
10
+ * 2. candidate ids derived from the wire id (namespace and dotted vendor/region
11
+ * prefixes, bracket affixes, date/`vN:0` suffixes, declared markers, the
12
+ * taxonomy logical id) compared on a dot/colon-folded bare name, accepted
13
+ * only when the classified identities agree.
14
+ *
15
+ * Identity alone (class/family/revision) is deliberately not a key: it
16
+ * conflates `gpt-5.5` with `gpt-5.5-pro` and every Llama with the one that
17
+ * happens to be scored.
18
+ */
19
+ import type { ModelIdentity } from "../compat/types";
20
+ import type { Api, Model } from "../types";
21
+ import { bareModelId } from "./id";
22
+ import { getReferenceCandidateIds } from "./reference";
23
+
24
+ /** Catalog-delivered intelligence score and output speed for one model. */
25
+ export interface CatalogMetrics {
26
+ int?: number;
27
+ tps?: number;
28
+ }
29
+
30
+ interface ScoredEntry extends CatalogMetrics {
31
+ identity: ModelIdentity;
32
+ }
33
+
34
+ /** Trailing tokens Bedrock-style ids append without changing the model: `-v1:0`, `-v2`, `:0`, `-20251001`, `-2026-04-23`. */
35
+ const STRIPPABLE_SUFFIX_PATTERN = /(?:-v\d+(?::\d+)?|:\d+|-\d{2,})$/;
36
+ /** Leading alphabetic dotted namespaces: `global.anthropic.`, `us-gov.`, `openai.`. */
37
+ const DOTTED_PREFIX_PATTERN = /^[a-z][a-z-]*\./;
38
+
39
+ function canonicalKey(id: string): string {
40
+ return bareModelId(id).toLowerCase().replace(/[.:]/g, "-");
41
+ }
42
+
43
+ /** Whether two classified identities may describe the same scored model. Unset ranks on either side are not evidence. */
44
+ function identitiesAgree(left: ModelIdentity, right: ModelIdentity): boolean {
45
+ if (left.class !== right.class || left.class === "unknown") return false;
46
+ if (left.family !== undefined && right.family !== undefined && left.family !== right.family) return false;
47
+ if (left.revision !== undefined && right.revision !== undefined && left.revision !== right.revision) return false;
48
+ if (left.effort !== undefined && right.effort !== undefined && left.effort !== right.effort) return false;
49
+ return (left.thinkingVariant ?? false) === (right.thinkingVariant ?? false);
50
+ }
51
+
52
+ /** The catalog metrics a model carries, or undefined when it reports none. A zero speed is "unmeasured", not a score. */
53
+ export function catalogMetricsOf(model: Model<Api>): CatalogMetrics | undefined {
54
+ const int = model.int != null && Number.isFinite(model.int) ? model.int : undefined;
55
+ const tps = model.tps != null && Number.isFinite(model.tps) && model.tps > 0 ? model.tps : undefined;
56
+ if (int === undefined && tps === undefined) return undefined;
57
+ return { ...(int !== undefined ? { int } : {}), ...(tps !== undefined ? { tps } : {}) };
58
+ }
59
+
60
+ // Wire ids form a bounded set (bundled + discovered), so no eviction is needed.
61
+ const candidateCache = new Map<string, string[]>();
62
+
63
+ /** Candidate ids for `modelId`, least-stripped first, each already canonical-keyed. */
64
+ function metricCandidateKeys(modelId: string): string[] {
65
+ const cached = candidateCache.get(modelId);
66
+ if (cached) return cached;
67
+ const keys: string[] = [];
68
+ const seen = new Set<string>();
69
+ const queue = getReferenceCandidateIds(modelId);
70
+ for (let index = 0; index < queue.length; index++) {
71
+ const candidate = queue[index].toLowerCase();
72
+ const key = canonicalKey(candidate);
73
+ if (!seen.has(key)) {
74
+ seen.add(key);
75
+ keys.push(key);
76
+ }
77
+ const bare = bareModelId(candidate);
78
+ const withoutPrefix = bare.replace(DOTTED_PREFIX_PATTERN, "");
79
+ if (withoutPrefix !== bare && withoutPrefix.length > 0) queue.push(withoutPrefix);
80
+ const withoutSuffix = bare.replace(STRIPPABLE_SUFFIX_PATTERN, "");
81
+ if (withoutSuffix !== bare && withoutSuffix.length > 0) queue.push(withoutSuffix);
82
+ }
83
+ candidateCache.set(modelId, keys);
84
+ return keys;
85
+ }
86
+
87
+ /**
88
+ * Index of catalog metrics over every scored model seen so far. Built once per
89
+ * discovery cycle by the model registry and per provider by the model manager;
90
+ * `add` accumulates across providers so a proxy id resolves against any host's
91
+ * scored row.
92
+ */
93
+ export class CatalogMetricsIndex {
94
+ #exact = new Map<string, CatalogMetrics>();
95
+ #canonical = new Map<string, ScoredEntry>();
96
+
97
+ constructor(models?: Iterable<Model<Api>>) {
98
+ if (models) this.add(models);
99
+ }
100
+
101
+ get isEmpty(): boolean {
102
+ return this.#exact.size === 0;
103
+ }
104
+
105
+ /** Record the metrics of every scored model; later rows fill fields earlier rows left unset. */
106
+ add(models: Iterable<Model<Api>>): void {
107
+ for (const model of models) {
108
+ const metrics = catalogMetricsOf(model);
109
+ if (!metrics) continue;
110
+ const exactKey = model.id.toLowerCase();
111
+ const existing = this.#exact.get(exactKey);
112
+ this.#exact.set(exactKey, existing ? { ...metrics, ...existing } : metrics);
113
+
114
+ const canonical = canonicalKey(model.id);
115
+ const scored = this.#canonical.get(canonical);
116
+ if (!scored) this.#canonical.set(canonical, { ...metrics, identity: model.identity });
117
+ else if (scored.int === undefined || scored.tps === undefined) {
118
+ this.#canonical.set(canonical, { ...metrics, ...scored });
119
+ }
120
+ }
121
+ }
122
+
123
+ /** Metrics for `model` by exact id, else by dialect-normalized id when the classified identities agree. */
124
+ resolve(model: Model<Api>): CatalogMetrics | undefined {
125
+ const exact = this.#exact.get(model.id.toLowerCase());
126
+ if (exact) return exact;
127
+ const identity = model.identity;
128
+ const ids = identity.logicalId ? [model.id, identity.logicalId] : [model.id];
129
+ for (const id of ids) {
130
+ for (const key of metricCandidateKeys(id)) {
131
+ const scored = this.#canonical.get(key);
132
+ if (scored && identitiesAgree(identity, scored.identity)) return scored;
133
+ }
134
+ }
135
+ return undefined;
136
+ }
137
+ }
138
+
139
+ /**
140
+ * Fill each model's `int`/`tps` from `index`. Returns the input array when no
141
+ * model changed so callers can keep identity-based caches.
142
+ */
143
+ export function applyCatalogMetrics<TApi extends Api>(
144
+ models: Model<TApi>[],
145
+ index: CatalogMetricsIndex,
146
+ ): Model<TApi>[] {
147
+ if (index.isEmpty) return models;
148
+ let changed: Model<TApi>[] | undefined;
149
+ for (let position = 0; position < models.length; position++) {
150
+ const model = models[position];
151
+ if (model.int != null && model.tps != null) continue;
152
+ const metrics = index.resolve(model);
153
+ if (!metrics) continue;
154
+ const int = metrics.int ?? model.int;
155
+ const tps = metrics.tps ?? model.tps;
156
+ if (int === model.int && tps === model.tps) continue;
157
+ changed ??= [...models];
158
+ changed[position] = {
159
+ ...model,
160
+ ...(int != null ? { int } : {}),
161
+ ...(tps != null ? { tps } : {}),
162
+ };
163
+ }
164
+ return changed ?? models;
165
+ }
@@ -119,7 +119,13 @@ function stripReferenceTrailingMarker(candidate: string): string | undefined {
119
119
  return suffixLength > 0 && suffixLength < candidate.length ? candidate.slice(0, -suffixLength) : undefined;
120
120
  }
121
121
 
122
- function getReferenceCandidateIds(modelId: string): string[] {
122
+ /**
123
+ * Expand a proxied/affixed model id into the ids it may be catalogued under,
124
+ * least-stripped first: bracket affixes, model-like segments, `:cloud`,
125
+ * namespace prefix, `:`→`-`, lowercase, and declared trailing markers.
126
+ * Shared by reference recovery and catalog-metric matching (`./metrics`).
127
+ */
128
+ export function getReferenceCandidateIds(modelId: string): string[] {
123
129
  const candidates = new Set<string>();
124
130
  const queue = [modelId];
125
131
  for (let index = 0; index < queue.length; index += 1) {
@@ -1,5 +1,6 @@
1
1
  import { buildModel } from "./build";
2
2
  import { collapseBuiltVariants } from "./compat/collapse";
3
+ import { applyCatalogMetrics, CatalogMetricsIndex } from "./identity/metrics";
3
4
  import { readModelCache, writeModelCache } from "./model-cache";
4
5
  import { type GeneratedProvider, getBundledModels } from "./models";
5
6
  import type { Api, Model, ModelCost, ModelSpec, Provider, TokenCost } from "./types";
@@ -257,7 +258,7 @@ export async function resolveProviderModels<TApi extends Api = Api, TModelsDevPa
257
258
  ? restoredCache.models.filter(model => !additiveStaticModelIds.has(model.id))
258
259
  : restoredCache.models;
259
260
  const cachedModels = additiveStaticModelIds
260
- ? mergeDynamicModels(staticModels, cacheContribution)
261
+ ? mergeCatalogMetrics(mergeDynamicModels(staticModels, cacheContribution), restoredCache.models)
261
262
  : restoredCache.models;
262
263
  const source: ModelResolutionSource = cacheContribution.length > 0 ? "cache" : "bundled";
263
264
  return {
@@ -312,7 +313,11 @@ export async function resolveProviderModels<TApi extends Api = Api, TModelsDevPa
312
313
  : modelsDevFetchSucceeded;
313
314
  const mergedWithCache = mergeDynamicModels(staticModels, cacheModels);
314
315
  const mergedWithModelsDev = mergeDynamicModels(mergedWithCache, modelsDevModels);
315
- const mergedModels = mergeDynamicModels(mergedWithModelsDev, dynamicModels);
316
+ const catalogMetricsSource = modelsDevFetchSucceeded ? normalizedModelsDevModels : preparedCacheModels;
317
+ const mergedWithCatalogMetrics = additiveStaticModelIds
318
+ ? mergeCatalogMetrics(mergedWithModelsDev, catalogMetricsSource)
319
+ : mergedWithModelsDev;
320
+ const mergedModels = mergeDynamicModels(mergedWithCatalogMetrics, dynamicModels);
316
321
  const models = collapseBuiltVariants(
317
322
  authoritativeDynamicFetchSucceeded ? retainModelIds(mergedModels, dynamicModels) : mergedModels,
318
323
  );
@@ -467,6 +472,14 @@ function prepareCacheModelsForStaticMismatch<TApi extends Api>(
467
472
  return sanitizedModels;
468
473
  }
469
474
 
475
+ function mergeCatalogMetrics<TApi extends Api>(
476
+ models: Model<TApi>[],
477
+ catalogModels: readonly Model<TApi>[],
478
+ ): Model<TApi>[] {
479
+ if (models.length === 0 || catalogModels.length === 0) return models;
480
+ return applyCatalogMetrics(models, new CatalogMetricsIndex(catalogModels));
481
+ }
482
+
470
483
  function mergeDynamicModels<TApi extends Api>(
471
484
  baseModels: readonly Model<TApi>[],
472
485
  dynamicModels: readonly Model<TApi>[],