@evandu/super-pi 0.1.193 → 0.1.195

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 (34) hide show
  1. package/dist/client/.super-pi-client-sources.json +4 -4
  2. package/dist/client/assets/{CodeMirrorEditor-Cmx7-z0f.js → CodeMirrorEditor-U3KDceIT.js} +2 -2
  3. package/dist/client/assets/{dist-C2ltv_8u.js → dist-B3Mq2G-v.js} +1 -1
  4. package/dist/client/assets/{dist-CWlI6qO0.js → dist-BNPrsqKa.js} +1 -1
  5. package/dist/client/assets/{dist-C0PMHwdm.js → dist-BPxhWZry.js} +1 -1
  6. package/dist/client/assets/{dist-WfagMkC4.js → dist-BRsrFxrS.js} +1 -1
  7. package/dist/client/assets/{dist-RHYiODih.js → dist-BVe_Uv1h.js} +1 -1
  8. package/dist/client/assets/{dist-BKx3CpQJ.js → dist-BZvAhJP1.js} +1 -1
  9. package/dist/client/assets/{dist-CDSDxXju.js → dist-BvsEwUNz.js} +1 -1
  10. package/dist/client/assets/{dist-BdiInYmk.js → dist-C8rmoSBN.js} +1 -1
  11. package/dist/client/assets/{dist-akJoBtjs.js → dist-CAbji9OL.js} +1 -1
  12. package/dist/client/assets/{dist-DHFt0Hvo.js → dist-CBJ6RIS3.js} +1 -1
  13. package/dist/client/assets/{dist-BMSVWA_A.js → dist-CGNj_nWe.js} +1 -1
  14. package/dist/client/assets/{dist-D_7x3oZt.js → dist-CHT_b-1Q.js} +1 -1
  15. package/dist/client/assets/{dist-ibsGPa_S.js → dist-CcQPELVv.js} +1 -1
  16. package/dist/client/assets/{dist-Cblc22Ag.js → dist-CnxhfY0a.js} +1 -1
  17. package/dist/client/assets/{dist-CcuBp_Kn.js → dist-D4HLkTu7.js} +1 -1
  18. package/dist/client/assets/{dist-frBiV55p.js → dist-D7SBQneC.js} +1 -1
  19. package/dist/client/assets/{dist-CKZOnuRU.js → dist-DhbOXLqT.js} +1 -1
  20. package/dist/client/assets/{dist-Bq7p17eF.js → dist-Dikq_PJ3.js} +1 -1
  21. package/dist/client/assets/{dist-BzqUlzAf.js → dist-IDDdx_gZ.js} +1 -1
  22. package/dist/client/assets/{dist-B8CAEuXW.js → dist-McDiPyAf.js} +1 -1
  23. package/dist/client/assets/{dist-V27Fcf8p.js → dist-ZcXCK1RB.js} +1 -1
  24. package/dist/client/assets/{dist-CXDhHY7N.js → dist-e4yYl6NS.js} +1 -1
  25. package/dist/client/assets/{index-Dx7HAZ5j.js → index-B2DCZtoX.js} +11 -11
  26. package/dist/client/index.html +1 -1
  27. package/dist/server/model-context-window.d.ts +63 -0
  28. package/dist/server/model-context-window.js +197 -2
  29. package/dist/server/runtime.d.ts +14 -0
  30. package/dist/server/runtime.js +30 -3
  31. package/dist/server/types.d.ts +1 -0
  32. package/dist/shared/model-window-label.d.ts +39 -0
  33. package/dist/shared/model-window-label.js +55 -0
  34. package/package.json +3 -1
@@ -8,7 +8,7 @@
8
8
  <link rel="alternate icon" href="/favicon.ico" />
9
9
  <link rel="apple-touch-icon" href="/favicon.svg" />
10
10
  <title>Super Pi</title>
11
- <script type="module" crossorigin src="/assets/index-Dx7HAZ5j.js"></script>
11
+ <script type="module" crossorigin src="/assets/index-B2DCZtoX.js"></script>
12
12
  <link rel="stylesheet" crossorigin href="/assets/index-BXQjUHV_.css">
13
13
  </head>
14
14
  <body>
@@ -20,6 +20,24 @@ export type DeclaredWindow = {
20
20
  * a zero would be a claim ("this model has no window") rather than an absence.
21
21
  */
22
22
  export declare function declaredWindows(modelsJson: unknown): Map<string, number>;
23
+ /**
24
+ * The OUTPUT LIMITS the person's `models.json` declares, keyed by `provider/modelId`.
25
+ *
26
+ * THE SIBLING OF `declaredWindows`, AND DELIBERATELY A SEPARATE MAP. The window and the output limit
27
+ * are two different numbers about the same model, and a model can declare one of them and not the
28
+ * other: a hand-written entry that sets `contextWindow` says nothing about how long one answer may
29
+ * be. Putting both numbers in one map would make "declared" mean "declared one of two things", and
30
+ * the arbitration could not tell an absent output limit from an absent window.
31
+ */
32
+ export declare function declaredMaxTokens(modelsJson: unknown): Map<string, number>;
33
+ /**
34
+ * Reads the person's `models.json` and returns its declared output limits.
35
+ *
36
+ * A missing or unreadable file is an empty map, for the same reason `readDeclaredWindows` treats one
37
+ * that way: Super Pi has no opinion about a model somebody else configured, and inventing one would
38
+ * be the same mistake in the other direction.
39
+ */
40
+ export declare function readDeclaredMaxTokens(agentDir: string): Map<string, number>;
23
41
  /**
24
42
  * The window to USE for a model, given what the person's file says.
25
43
  *
@@ -78,6 +96,50 @@ export declare function readStoreWindows(agentDir: string): ModelStore;
78
96
  * taking the smallest is exactly how a million-token model ended up believing it had 128,000.
79
97
  */
80
98
  export declare function arbitrateContextWindow(declared: Map<string, number>, store: ModelStore, provider: string, modelId: string, reported?: number): number | undefined;
99
+ /**
100
+ * THE OUTPUT LIMIT A MODEL REALLY GETS, arbitrated across the sources that each claim to know it.
101
+ *
102
+ * THE SAME PRECEDENCE AS THE CONTEXT WINDOW, ON PURPOSE. The window was fixed by reading the
103
+ * provider's catalogue instead of Super Pi's own stamped placeholder, and the output limit is the
104
+ * same hole one number over: `MiniMax-M3` really answers in 512,000 tokens, and Super Pi stamped
105
+ * 16,384 on every model the provider did not describe. 16,384 is a length cap on ONE answer, so the
106
+ * long report a sub-session was asked to write comes back cut off, and the turn is wasted - which is
107
+ * exactly why a sub-session that has to produce a long report dies while a short chatty one does not.
108
+ *
109
+ * PRECEDENCE, HIGHEST FIRST:
110
+ *
111
+ * 1. A NON-DEFAULT value in the person's `models.json` - somebody typed it, so it is a decision.
112
+ * 2. The CATALOGUE (`models-store.json`) - the provider's self-report.
113
+ * 3. The `reported` value the model object already carries, then nothing (`undefined`).
114
+ *
115
+ * `undefined` MEANS "SAY NOTHING". It is not 0: zero would be a claim ("this model may not answer
116
+ * at all"), and a model nobody describes simply has no known limit, so the caller's own value stands.
117
+ */
118
+ export declare function arbitrateMaxTokens(declared: Map<string, number>, store: ModelStore, provider: string, modelId: string, reported?: number): number | undefined;
119
+ /**
120
+ * THE CATALOG'S WINDOWS, ARBITRATED THE WAY A SESSION'S ARE.
121
+ *
122
+ * WHY THE CATALOG NEEDS THIS AT ALL. There are two ways Super Pi can read the model list, and they
123
+ * do not agree: Pi's SDK hands over whole model objects (window included), while a spawned Pi in
124
+ * RPC mode answers with a reduced list that has no window on it at all. So the number the reader is
125
+ * shown depends on WHICH PATH the machine happened to take - and the path that drops it is the one
126
+ * this machine takes. A picker that silently omits the window is a picker that cannot answer the
127
+ * one question it exists to answer: can this model hold a long task?
128
+ *
129
+ * WHY THE SAME ARBITRATION. The number printed has to be the number the session will run on, or it
130
+ * is a decoration. The session's window is decided by `arbitrateContextWindow` over the person's
131
+ * file and the provider's catalogue, so the catalogue is arbitrated the same way - one rule, one
132
+ * answer, and the label a reader sees is the limit their session really has.
133
+ *
134
+ * A window of 0 means "this source did not say", not "this model has no window": it is passed on
135
+ * as absent so the arbitration can go on to the sources that do know.
136
+ */
137
+ export declare function withArbitratedWindows<T extends {
138
+ provider: string;
139
+ modelId: string;
140
+ contextWindow: number;
141
+ maxTokens?: number;
142
+ }>(options: readonly T[], agentDir: string): T[];
81
143
  /**
82
144
  * THE RESOLVER A LIVE SESSION HANDS ITS MODEL THROUGH.
83
145
  *
@@ -110,5 +172,6 @@ export declare function createModelResolver(options: {
110
172
  provider: string;
111
173
  id: string;
112
174
  contextWindow?: number;
175
+ maxTokens?: number;
113
176
  [key: string]: unknown;
114
177
  } | undefined);
@@ -29,6 +29,14 @@
29
29
  * This module is deliberately narrow: it reads the person's file, and it says what the model
30
30
  * window SHOULD be. It does not touch Pi, does not decide anything else, and is a pure function of
31
31
  * two plain objects so it can be tested without a server, a socket, a browser or a model.
32
+ *
33
+ * THE SAME RULE, ONE NUMBER OVER: THE OUTPUT LIMIT. A model has two limits that decide whether a
34
+ * long turn can finish - the context window (how much conversation fits) and the output limit (how
35
+ * long ONE answer may be). Super Pi stamped its own placeholder on both, and the placeholder for
36
+ * the output limit (16384) truncates the long report a sub-session was asked to write. So the same
37
+ * arbitration runs for the second number, over the same three sources, with the same precedence.
38
+ * The two numbers are looked up in SEPARATE maps, because a person can declare one of them and not
39
+ * the other.
32
40
  */
33
41
  import { readFileSync } from "node:fs";
34
42
  import { join } from "node:path";
@@ -74,6 +82,58 @@ export function declaredWindows(modelsJson) {
74
82
  }
75
83
  return out;
76
84
  }
85
+ /**
86
+ * The OUTPUT LIMITS the person's `models.json` declares, keyed by `provider/modelId`.
87
+ *
88
+ * THE SIBLING OF `declaredWindows`, AND DELIBERATELY A SEPARATE MAP. The window and the output limit
89
+ * are two different numbers about the same model, and a model can declare one of them and not the
90
+ * other: a hand-written entry that sets `contextWindow` says nothing about how long one answer may
91
+ * be. Putting both numbers in one map would make "declared" mean "declared one of two things", and
92
+ * the arbitration could not tell an absent output limit from an absent window.
93
+ */
94
+ export function declaredMaxTokens(modelsJson) {
95
+ const out = new Map();
96
+ if (!modelsJson || typeof modelsJson !== "object")
97
+ return out;
98
+ const providers = modelsJson.providers;
99
+ if (!providers || typeof providers !== "object")
100
+ return out;
101
+ for (const [providerId, provider] of Object.entries(providers)) {
102
+ if (!provider || typeof provider !== "object")
103
+ continue;
104
+ const models = provider.models;
105
+ if (!Array.isArray(models))
106
+ continue;
107
+ for (const model of models) {
108
+ if (!model || typeof model !== "object")
109
+ continue;
110
+ const id = model.id;
111
+ const maxTokens = model.maxTokens;
112
+ if (typeof id !== "string" || !id.trim())
113
+ continue;
114
+ if (typeof maxTokens !== "number" || !Number.isSafeInteger(maxTokens) || maxTokens <= 0)
115
+ continue;
116
+ out.set(`${providerId}/${id}`, maxTokens);
117
+ }
118
+ }
119
+ return out;
120
+ }
121
+ /**
122
+ * Reads the person's `models.json` and returns its declared output limits.
123
+ *
124
+ * A missing or unreadable file is an empty map, for the same reason `readDeclaredWindows` treats one
125
+ * that way: Super Pi has no opinion about a model somebody else configured, and inventing one would
126
+ * be the same mistake in the other direction.
127
+ */
128
+ export function readDeclaredMaxTokens(agentDir) {
129
+ try {
130
+ const raw = readFileSync(join(agentDir, "models.json"), "utf8");
131
+ return declaredMaxTokens(JSON.parse(raw));
132
+ }
133
+ catch {
134
+ return new Map();
135
+ }
136
+ }
77
137
  /**
78
138
  * The window to USE for a model, given what the person's file says.
79
139
  *
@@ -195,6 +255,129 @@ export function arbitrateContextWindow(declared, store, provider, modelId, repor
195
255
  return reported;
196
256
  return exact ?? deliberate ?? storeEntry?.contextWindow ?? reported;
197
257
  }
258
+ /**
259
+ * Is a `models.json` output limit a PERSON's decision, or just Super Pi's own default stamped at import?
260
+ *
261
+ * The same question as `isDeliberateWindow`, asked of the other number. The value Super Pi writes
262
+ * when the provider said nothing (16384) is a placeholder, and a placeholder never outranks the
263
+ * catalogue's real figure.
264
+ */
265
+ function isDeliberateMaxTokens(maxTokens) {
266
+ return maxTokens !== undefined && maxTokens !== SUPER_PI_DEFAULT_MAX_TOKENS;
267
+ }
268
+ /**
269
+ * What the catalogue says about how long ONE ANSWER of this model may be.
270
+ *
271
+ * The provider's own entry wins, and when the catalogue holds the same model under two provider ids,
272
+ * the LARGEST limit is the model's real one - the same rule the window follows, and for the same
273
+ * reason: a smaller duplicate is an older or narrower copy of the same truth.
274
+ */
275
+ function storeMaxTokensFor(store, modelId, provider) {
276
+ const scoped = storeWindowFor(store, modelId, provider)?.maxTokens;
277
+ if (scoped !== undefined)
278
+ return scoped;
279
+ const key = modelId.trim().toLowerCase();
280
+ if (!key)
281
+ return undefined;
282
+ let largest;
283
+ for (const [storeKey, entry] of store.byProviderModel) {
284
+ const slash = storeKey.indexOf("/");
285
+ if (slash < 0 || storeKey.slice(slash + 1) !== key)
286
+ continue;
287
+ if (entry.maxTokens === undefined)
288
+ continue;
289
+ if (largest === undefined || entry.maxTokens > largest)
290
+ largest = entry.maxTokens;
291
+ }
292
+ return largest;
293
+ }
294
+ /**
295
+ * THE OUTPUT LIMIT A MODEL REALLY GETS, arbitrated across the sources that each claim to know it.
296
+ *
297
+ * THE SAME PRECEDENCE AS THE CONTEXT WINDOW, ON PURPOSE. The window was fixed by reading the
298
+ * provider's catalogue instead of Super Pi's own stamped placeholder, and the output limit is the
299
+ * same hole one number over: `MiniMax-M3` really answers in 512,000 tokens, and Super Pi stamped
300
+ * 16,384 on every model the provider did not describe. 16,384 is a length cap on ONE answer, so the
301
+ * long report a sub-session was asked to write comes back cut off, and the turn is wasted - which is
302
+ * exactly why a sub-session that has to produce a long report dies while a short chatty one does not.
303
+ *
304
+ * PRECEDENCE, HIGHEST FIRST:
305
+ *
306
+ * 1. A NON-DEFAULT value in the person's `models.json` - somebody typed it, so it is a decision.
307
+ * 2. The CATALOGUE (`models-store.json`) - the provider's self-report.
308
+ * 3. The `reported` value the model object already carries, then nothing (`undefined`).
309
+ *
310
+ * `undefined` MEANS "SAY NOTHING". It is not 0: zero would be a claim ("this model may not answer
311
+ * at all"), and a model nobody describes simply has no known limit, so the caller's own value stands.
312
+ */
313
+ export function arbitrateMaxTokens(declared, store, provider, modelId, reported) {
314
+ const exact = declared.get(`${provider}/${modelId}`);
315
+ if (isDeliberateMaxTokens(exact))
316
+ return exact;
317
+ // A deliberate cross-provider declaration still wins over the catalogue.
318
+ let deliberate;
319
+ for (const [key, maxTokens] of declared) {
320
+ const slash = key.indexOf("/");
321
+ if (slash < 0 || key.slice(slash + 1) !== modelId)
322
+ continue;
323
+ if (!isDeliberateMaxTokens(maxTokens))
324
+ continue;
325
+ if (deliberate === undefined || maxTokens > deliberate)
326
+ deliberate = maxTokens;
327
+ }
328
+ if (deliberate !== undefined)
329
+ return deliberate;
330
+ const fromStore = storeMaxTokensFor(store, modelId, provider);
331
+ if (fromStore !== undefined)
332
+ return fromStore;
333
+ if (isDeliberateMaxTokens(reported))
334
+ return reported;
335
+ return undefined;
336
+ }
337
+ /**
338
+ * THE CATALOG'S WINDOWS, ARBITRATED THE WAY A SESSION'S ARE.
339
+ *
340
+ * WHY THE CATALOG NEEDS THIS AT ALL. There are two ways Super Pi can read the model list, and they
341
+ * do not agree: Pi's SDK hands over whole model objects (window included), while a spawned Pi in
342
+ * RPC mode answers with a reduced list that has no window on it at all. So the number the reader is
343
+ * shown depends on WHICH PATH the machine happened to take - and the path that drops it is the one
344
+ * this machine takes. A picker that silently omits the window is a picker that cannot answer the
345
+ * one question it exists to answer: can this model hold a long task?
346
+ *
347
+ * WHY THE SAME ARBITRATION. The number printed has to be the number the session will run on, or it
348
+ * is a decoration. The session's window is decided by `arbitrateContextWindow` over the person's
349
+ * file and the provider's catalogue, so the catalogue is arbitrated the same way - one rule, one
350
+ * answer, and the label a reader sees is the limit their session really has.
351
+ *
352
+ * A window of 0 means "this source did not say", not "this model has no window": it is passed on
353
+ * as absent so the arbitration can go on to the sources that do know.
354
+ */
355
+ export function withArbitratedWindows(options, agentDir) {
356
+ if (!options.length)
357
+ return [];
358
+ const declared = readDeclaredWindows(agentDir);
359
+ const declaredLimits = readDeclaredMaxTokens(agentDir);
360
+ const catalogue = readStoreWindows(agentDir);
361
+ return options.map((option) => {
362
+ const reported = typeof option.contextWindow === "number" && option.contextWindow > 0 ? option.contextWindow : undefined;
363
+ const window = arbitrateContextWindow(declared, catalogue, option.provider, option.modelId, reported);
364
+ // THE OUTPUT LIMIT IS ARBITRATED BY THE SAME RULE, ON THE SAME SOURCES. The two numbers are
365
+ // looked up in their own maps, because a model can declare one of them and not the other.
366
+ const reportedLimit = typeof option.maxTokens === "number" && option.maxTokens > 0 ? option.maxTokens : undefined;
367
+ const maxTokens = arbitrateMaxTokens(declaredLimits, catalogue, option.provider, option.modelId, reportedLimit);
368
+ const windowChanged = window !== undefined && window !== option.contextWindow;
369
+ const limitChanged = maxTokens !== undefined && maxTokens !== option.maxTokens;
370
+ // THE SAME OBJECT WHEN NOTHING CHANGED. A caller that holds the list it was given and compares
371
+ // it with the next read is asking "did the answer change", and an allocation is not an answer.
372
+ if (!windowChanged && !limitChanged)
373
+ return option;
374
+ return {
375
+ ...option,
376
+ ...(windowChanged ? { contextWindow: window } : {}),
377
+ ...(limitChanged ? { maxTokens } : {}),
378
+ };
379
+ });
380
+ }
198
381
  /**
199
382
  * THE RESOLVER A LIVE SESSION HANDS ITS MODEL THROUGH.
200
383
  *
@@ -220,6 +403,7 @@ export function arbitrateContextWindow(declared, store, provider, modelId, repor
220
403
  */
221
404
  export function createModelResolver(options) {
222
405
  const declared = readDeclaredWindows(options.agentDir);
406
+ const declaredLimits = readDeclaredMaxTokens(options.agentDir);
223
407
  const catalogue = readStoreWindows(options.agentDir);
224
408
  return (provider, modelId) => {
225
409
  const found = options.modelRuntime.getModel?.(provider, modelId);
@@ -227,8 +411,19 @@ export function createModelResolver(options) {
227
411
  return undefined;
228
412
  const model = found;
229
413
  const window = arbitrateContextWindow(declared, catalogue, provider, modelId, model.contextWindow);
414
+ // The OUTPUT LIMIT IS ARBITRATED THE SAME WAY, AND WRITTEN ONLY WHEN THERE IS ONE. A model
415
+ // Super Pi has no opinion about keeps the limit Pi gave it; a limit of 0 would be a claim
416
+ // ("this model may not answer at all") rather than an absence.
417
+ const maxTokens = arbitrateMaxTokens(declaredLimits, catalogue, provider, modelId, model.maxTokens);
230
418
  // The model is handed to Pi WHOLE - it is what the agent runs on - so this is where the
231
- // corrected window has to be. A model Super Pi has no opinion about is handed over untouched.
232
- return window === undefined ? model : { ...model, contextWindow: window };
419
+ // corrected window and the corrected output limit have to be. A model Super Pi has no opinion
420
+ // about is handed over untouched.
421
+ if (window === undefined && maxTokens === undefined)
422
+ return model;
423
+ return {
424
+ ...model,
425
+ ...(window === undefined ? {} : { contextWindow: window }),
426
+ ...(maxTokens === undefined ? {} : { maxTokens }),
427
+ };
233
428
  };
234
429
  }
@@ -1262,6 +1262,20 @@ export declare class PiRpcRuntime implements AgentRuntime {
1262
1262
  * killed as soon as it has answered - no long-lived process to keep warm.
1263
1263
  */
1264
1264
  catalog(selection?: ModelSelection): Promise<ModelCatalog>;
1265
+ /**
1266
+ * THE CATALOG, WITH THE WINDOW EACH MODEL REALLY HAS.
1267
+ *
1268
+ * WHY THIS IS HERE AND NOT IN THE READ. There are two ways Super Pi can read the model list: Pi's
1269
+ * SDK hands over whole model objects (window included), while a spawned Pi in RPC mode answers
1270
+ * with a reduced list that has no window on it at all. So whether the reader is shown a model's
1271
+ * window depends on WHICH PATH the machine took - and the path that drops it is the one this
1272
+ * machine takes. The window is filled in here, on the way out, so both paths end up answering the
1273
+ * same way.
1274
+ *
1275
+ * The number is the one a session will really run on, because it comes from the same arbitration
1276
+ * the session's own resolver uses (`model-context-window.ts` explains the rule).
1277
+ */
1278
+ private withRealWindows;
1265
1279
  /**
1266
1280
  * Reads the model catalog WITHOUT starting a Pi process, and falls back to a spawned Pi only when
1267
1281
  * the SDK is not available.
@@ -9,6 +9,7 @@ import { WEB_FETCH_TOOL_NAME, WEB_SEARCH_TOOL_NAME } from "./web.js";
9
9
  import { existsSync } from "node:fs";
10
10
  import { ConversationUsageCollector } from "./conversation-usage.js";
11
11
  import { defaultAgentDir } from "./pi-session.js";
12
+ import { withArbitratedWindows } from "./model-context-window.js";
12
13
  import { mkdir, stat } from "node:fs/promises";
13
14
  import { forkSessionFile, truncateSessionFile } from "./session-repository.js";
14
15
  export { forkSessionFile, truncateSessionFile } from "./session-repository.js";
@@ -2727,7 +2728,7 @@ export class PiRpcRuntime {
2727
2728
  if (cached && Date.now() - cached.at < ttl) {
2728
2729
  if (process.env.SUPER_PI_TRACE_LATENCY === "1")
2729
2730
  console.warn(`[super-pi latency] catalog key=${key} phase=catalog.cache-hit`);
2730
- return cached.value;
2731
+ return this.withRealWindows(cached.value);
2731
2732
  }
2732
2733
  const inFlight = this.pendingCatalogs.get(key);
2733
2734
  if (inFlight) {
@@ -2737,10 +2738,36 @@ export class PiRpcRuntime {
2737
2738
  }
2738
2739
  if (process.env.SUPER_PI_TRACE_LATENCY === "1")
2739
2740
  console.warn(`[super-pi latency] catalog key=${key} phase=catalog.read-begin`);
2740
- const pending = this.readCatalog(selection, key).finally(() => this.pendingCatalogs.delete(key));
2741
+ const pending = this.readCatalog(selection, key)
2742
+ .then((catalog) => this.withRealWindows(catalog))
2743
+ .finally(() => this.pendingCatalogs.delete(key));
2741
2744
  this.pendingCatalogs.set(key, pending);
2742
2745
  return pending;
2743
2746
  }
2747
+ /**
2748
+ * THE CATALOG, WITH THE WINDOW EACH MODEL REALLY HAS.
2749
+ *
2750
+ * WHY THIS IS HERE AND NOT IN THE READ. There are two ways Super Pi can read the model list: Pi's
2751
+ * SDK hands over whole model objects (window included), while a spawned Pi in RPC mode answers
2752
+ * with a reduced list that has no window on it at all. So whether the reader is shown a model's
2753
+ * window depends on WHICH PATH the machine took - and the path that drops it is the one this
2754
+ * machine takes. The window is filled in here, on the way out, so both paths end up answering the
2755
+ * same way.
2756
+ *
2757
+ * The number is the one a session will really run on, because it comes from the same arbitration
2758
+ * the session's own resolver uses (`model-context-window.ts` explains the rule).
2759
+ */
2760
+ withRealWindows(catalog) {
2761
+ if (!catalog.models.length)
2762
+ return catalog;
2763
+ const filled = withArbitratedWindows(catalog.models, defaultAgentDir());
2764
+ // THE CATALOG ITSELF WHEN NOTHING CHANGED. A cached catalog is handed out by reference, and
2765
+ // a caller that compares two reads of the same cache entry is asking "did the answer change",
2766
+ // not "did the plumbing allocate". `scripts/pi-model-switch.test.mjs` pins this.
2767
+ if (filled.every((model, index) => model === catalog.models[index]))
2768
+ return catalog;
2769
+ return { ...catalog, models: filled };
2770
+ }
2744
2771
  /**
2745
2772
  * Reads the model catalog WITHOUT starting a Pi process, and falls back to a spawned Pi only when
2746
2773
  * the SDK is not available.
@@ -2996,7 +3023,7 @@ export function describeModel(value) {
2996
3023
  // check is here because this runs against a field read off the wire from a process that does no
2997
3024
  // validation of its own.
2998
3025
  const input = Array.isArray(model.input) ? model.input.filter((value) => typeof value === "string") : [];
2999
- return { provider: model.provider, modelId: model.id, label, detail: `${model.provider}/${model.id}`, reasoning: model.reasoning === true, contextWindow: typeof model.contextWindow === "number" ? model.contextWindow : 0, imageInput: input.includes("image") };
3026
+ return { provider: model.provider, modelId: model.id, label, detail: `${model.provider}/${model.id}`, reasoning: model.reasoning === true, contextWindow: typeof model.contextWindow === "number" ? model.contextWindow : 0, maxTokens: typeof model.maxTokens === "number" ? model.maxTokens : 0, imageInput: input.includes("image") };
3000
3027
  }
3001
3028
  export function describeModels(value) {
3002
3029
  if (!Array.isArray(value))
@@ -384,6 +384,7 @@ export type ModelOption = ModelSelection & {
384
384
  detail: string;
385
385
  reasoning: boolean;
386
386
  contextWindow: number;
387
+ maxTokens: number;
387
388
  imageInput: boolean;
388
389
  };
389
390
  /**
@@ -0,0 +1,39 @@
1
+ /**
2
+ * How big a model's context window is, in the words a reader uses: 「1M」, 「205K」, 「128K」.
3
+ *
4
+ * WHY THIS IS A SEPARATE FILE. The window of a model is the one number that decides whether a long
5
+ * task can finish at all, and it is the one number a reader cannot see. A model that really has a
6
+ * million tokens and one that really has a hundred and twenty-eight thousand are the same line of
7
+ * text in a picker, so the reader picks the second one and then watches a two-hundred-thousand-token
8
+ * session report 156%. The number was already in the data - `ModelOption.contextWindow` carries the
9
+ * value the session will actually be measured against - so all this does is put it in front of the
10
+ * reader where they choose the model.
11
+ *
12
+ * WHY THE ROUNDING IS DECIMAL. People say 「128k」 and 「1M」, and the sizes that show up here are
13
+ * written that way: 128000, 512000, 1000000. 204800 is the awkward one - it is 200 of the binary
14
+ * unit and 204.8 of the decimal one - and it is printed as 「205K」, because a label that is off by
15
+ * one percent is a label that is honest. A picker is not where rounding gets to be pretty.
16
+ */
17
+ /**
18
+ * The window size as a reader-facing label, or the empty string when there is no window to show.
19
+ *
20
+ * The empty string is a real case, not a defensive one: a model the provider never published a
21
+ * window for has no window to print, and printing 「0 上下文」 would be a fact the reader would
22
+ * believe.
23
+ */
24
+ export declare function formatModelWindow(window: number): string;
25
+ /**
26
+ * How long a SINGLE answer may be, in the same words as the window: 「512K」, 「16K」, 「1M」.
27
+ *
28
+ * WHY THIS IS A SECOND NUMBER. The window is how much conversation fits; the output limit is how much
29
+ * one answer may be. They are different facts about the same model, and they fail differently: a
30
+ * window that is too small compacts the conversation, while an output limit that is too small TRUNCATES
31
+ * THE ANSWER - the long report comes back cut off at the limit, and the turn is wasted. So a model
32
+ * whose output limit was stamped with Super Pi's own 16,384 placeholder can never produce the long
33
+ * report it was asked for.
34
+ *
35
+ * THE ROUNDING IS THE SAME RULE, ON PURPOSE. A reader who has learned 「128K」 for a window has
36
+ * learned one scale, and a second scale for the other number on the same line would be a puzzle
37
+ * rather than a fact.
38
+ */
39
+ export declare function formatModelOutput(maxTokens: number): string;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * How big a model's context window is, in the words a reader uses: 「1M」, 「205K」, 「128K」.
3
+ *
4
+ * WHY THIS IS A SEPARATE FILE. The window of a model is the one number that decides whether a long
5
+ * task can finish at all, and it is the one number a reader cannot see. A model that really has a
6
+ * million tokens and one that really has a hundred and twenty-eight thousand are the same line of
7
+ * text in a picker, so the reader picks the second one and then watches a two-hundred-thousand-token
8
+ * session report 156%. The number was already in the data - `ModelOption.contextWindow` carries the
9
+ * value the session will actually be measured against - so all this does is put it in front of the
10
+ * reader where they choose the model.
11
+ *
12
+ * WHY THE ROUNDING IS DECIMAL. People say 「128k」 and 「1M」, and the sizes that show up here are
13
+ * written that way: 128000, 512000, 1000000. 204800 is the awkward one - it is 200 of the binary
14
+ * unit and 204.8 of the decimal one - and it is printed as 「205K」, because a label that is off by
15
+ * one percent is a label that is honest. A picker is not where rounding gets to be pretty.
16
+ */
17
+ /**
18
+ * The window size as a reader-facing label, or the empty string when there is no window to show.
19
+ *
20
+ * The empty string is a real case, not a defensive one: a model the provider never published a
21
+ * window for has no window to print, and printing 「0 上下文」 would be a fact the reader would
22
+ * believe.
23
+ */
24
+ export function formatModelWindow(window) {
25
+ if (!Number.isFinite(window) || window <= 0)
26
+ return "";
27
+ if (window >= 1_000_000)
28
+ return `${Math.round(window / 1_000_000)}M`;
29
+ if (window >= 1000)
30
+ return `${Math.round(window / 1000)}K`;
31
+ return String(window);
32
+ }
33
+ /**
34
+ * How long a SINGLE answer may be, in the same words as the window: 「512K」, 「16K」, 「1M」.
35
+ *
36
+ * WHY THIS IS A SECOND NUMBER. The window is how much conversation fits; the output limit is how much
37
+ * one answer may be. They are different facts about the same model, and they fail differently: a
38
+ * window that is too small compacts the conversation, while an output limit that is too small TRUNCATES
39
+ * THE ANSWER - the long report comes back cut off at the limit, and the turn is wasted. So a model
40
+ * whose output limit was stamped with Super Pi's own 16,384 placeholder can never produce the long
41
+ * report it was asked for.
42
+ *
43
+ * THE ROUNDING IS THE SAME RULE, ON PURPOSE. A reader who has learned 「128K」 for a window has
44
+ * learned one scale, and a second scale for the other number on the same line would be a puzzle
45
+ * rather than a fact.
46
+ */
47
+ export function formatModelOutput(maxTokens) {
48
+ if (!Number.isFinite(maxTokens) || maxTokens <= 0)
49
+ return "";
50
+ if (maxTokens >= 1_000_000)
51
+ return `${Math.round(maxTokens / 1_000_000)}M`;
52
+ if (maxTokens >= 1000)
53
+ return `${Math.round(maxTokens / 1000)}K`;
54
+ return String(maxTokens);
55
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evandu/super-pi",
3
- "version": "0.1.193",
3
+ "version": "0.1.195",
4
4
  "description": "Web control plane and companion for Pi",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -129,6 +129,8 @@
129
129
  "scripts/turn-failure-marks-failed.test.mjs",
130
130
  "scripts/model-context-window.test.mjs",
131
131
  "scripts/run-gate.test.mjs",
132
+ "scripts/model-window-label.test.mjs",
133
+ "scripts/model-output-limit.test.mjs",
132
134
  "scripts/update-ui-contract.test.mjs",
133
135
  "scripts/stopping-marker.test.mjs",
134
136
  "scripts/update-button-state.test.mjs",