Context-meter amendment: CONTEXT_LIMITS dies — pi's live catalog is the only limit source

Owner ruling (2026-09-23, amendment to 04e336d): no hardcoded fallback
exists anywhere. contextWindow(record, limits) resolves the denominator
ONLY from the live index (provider:id -> contextWindow straight from
pi's catalog); a model missing from it (historical session, package
update, failed fetch) reads limit null and the meter renders
usage-only — the honest-render precedent, never a fake window.

- src/core/prices.ts: the 1354-entry CONTEXT_LIMITS table (65KB) and its
  generation apparatus deleted; the fold returns limit: number | null.
  PRICES untouched (regen verified byte-identical via the reworked
  sync-pricing script).
- scripts/sync-pricing.ts: generates PRICES only; contextWindow leaves
  the priced map, the guard, and the template.
- The dock meter's owner-selected treatment: the activity feed carries
  the limit server-side. catalogContextLimits() (server/model-catalog.ts)
  builds the index over the same keyed providers the picker federates;
  activityFeed() joins it onto every running job (ActivityJob.contextLimit,
  null when the model is missing — the dock reads it off the feed, no
  client-side table, no regression while the UI's catalog-join chunk lands).
- components/activity-dock.tsx: toBlobs reads job.contextLimit (import
  of CONTEXT_LIMITS gone); stats-bar renders usage-only on null limit
  (mechanical interim — UI stream's join chunk follows).
- tests: usage.test.ts pins the no-fallback contract (index hit / absent
  / empty / missing-model -> null); activity-feed.test.ts pins the
  server join (catalog model -> 1048576, unknown -> null, no-usage ->
  null); render pins updated to the interim usage-only render.
This commit is contained in:
amosblomqvist
2026-09-24 02:10:06 +03:00
parent b68a16fdb4
commit 4ded547cb5
11 changed files with 200 additions and 1450 deletions
+8 -13
View File
@@ -37,13 +37,12 @@ interface CatalogModel {
id: string;
name: string;
cost: { input: number; output: number; cacheRead: number; cacheWrite: number };
contextWindow: number;
}
function main(): void {
// Every data file is {api: {modelId: entry}} — ids are per-provider
// namespaced already (openrouter's are slugs, native ones plain).
const priced = new Map<string, { cost: CatalogModel["cost"]; contextWindow: number }>();
const priced = new Map<string, { cost: CatalogModel["cost"] }>();
for (const file of fs.readdirSync(DATA_DIR).filter((f) => f.endsWith(".json"))) {
const provider = file.slice(0, -".json".length);
const catalog = JSON.parse(fs.readFileSync(path.join(DATA_DIR, file), "utf-8")) as Record<
@@ -52,13 +51,13 @@ function main(): void {
>;
for (const models of Object.values(catalog)) {
for (const [id, m] of Object.entries(models)) {
// A catalog entry without pricing/limit data gets no key at all
// (cost renders "—", never zero; the limit renders unknown).
if (!m.cost || m.contextWindow === undefined) continue;
// A catalog entry without pricing data gets no key at all
// (cost renders "—", never zero).
if (!m.cost) continue;
// First writer wins (an id can appear under two apis within one
// file with identical pricing; cross-file collisions cannot
// happen — keys are provider-qualified).
priced.set(`${provider}:${id}`, { cost: m.cost, contextWindow: m.contextWindow });
priced.set(`${provider}:${id}`, { cost: m.cost });
}
}
}
@@ -68,25 +67,21 @@ function main(): void {
.sort(([a], [b]) => a.localeCompare(b))
.map(([key, m]) => ({
price: `\t${JSON.stringify(key)}: { input: ${m.cost.input}, output: ${m.cost.output}, cacheRead: ${m.cost.cacheRead}, cacheWrite: ${m.cost.cacheWrite} },`,
limit: `\t${JSON.stringify(key)}: ${m.contextWindow},`,
}));
const tables = `/** Token prices, USD per 1M tokens. A missing model makes cost render
* as absent ("—"), never zero. Keys are provider-qualified ("provider:id")
* since the model slots wave; openrouter ids ALSO appear under their bare
* slug (the legacy stamp format, kept so pre-wave records keep pricing).
* Context-window limits are NOT a table (owner amendment, 2026-09-23):
* every meter's denominator reads pi's LIVE catalog (GET /api/models /
* the activity feed's server-side join) — missing model, usage-only.
* Refresh: bump @earendil-works/pi-ai, then npx tsx scripts/sync-pricing.ts
* (reads pi-ai's shipped catalogs — the same source the engine and the
* picker use). */
export const PRICES: Record<string, ModelPrice> = {
${rows.map((r) => r.price).join("\n")}
};
/** Context-window limits (tokens) per model — generated alongside PRICES,
* same key families. */
export const CONTEXT_LIMITS: Record<string, number> = {
${rows.map((r) => r.limit).join("\n")}
};
`;
const src = fs.readFileSync(OUT, "utf-8");