@evandu/super-pi 0.1.194 → 0.1.196

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-Q1Yw7L2W.js → CodeMirrorEditor-U3KDceIT.js} +2 -2
  3. package/dist/client/assets/{dist-CXirFx2P.js → dist-B3Mq2G-v.js} +1 -1
  4. package/dist/client/assets/{dist-CrbCG3on.js → dist-BNPrsqKa.js} +1 -1
  5. package/dist/client/assets/{dist-BzZeOpW9.js → dist-BPxhWZry.js} +1 -1
  6. package/dist/client/assets/{dist-gABF84ho.js → dist-BRsrFxrS.js} +1 -1
  7. package/dist/client/assets/{dist-DSn8NhPW.js → dist-BVe_Uv1h.js} +1 -1
  8. package/dist/client/assets/{dist-BxiObY5p.js → dist-BZvAhJP1.js} +1 -1
  9. package/dist/client/assets/{dist-BzTFldVl.js → dist-BvsEwUNz.js} +1 -1
  10. package/dist/client/assets/{dist-DS1w-SLi.js → dist-C8rmoSBN.js} +1 -1
  11. package/dist/client/assets/{dist-CBOvaGIi.js → dist-CAbji9OL.js} +1 -1
  12. package/dist/client/assets/{dist-CCu0IPPb.js → dist-CBJ6RIS3.js} +1 -1
  13. package/dist/client/assets/{dist-hWnJl8_S.js → dist-CGNj_nWe.js} +1 -1
  14. package/dist/client/assets/{dist-D7dAoVBM.js → dist-CHT_b-1Q.js} +1 -1
  15. package/dist/client/assets/{dist-EQ3ztI-3.js → dist-CcQPELVv.js} +1 -1
  16. package/dist/client/assets/{dist-DRUh6SDZ.js → dist-CnxhfY0a.js} +1 -1
  17. package/dist/client/assets/{dist-f8Zhwj7K.js → dist-D4HLkTu7.js} +1 -1
  18. package/dist/client/assets/{dist-B6R1PTDe.js → dist-D7SBQneC.js} +1 -1
  19. package/dist/client/assets/{dist-C3HWN2LG.js → dist-DhbOXLqT.js} +1 -1
  20. package/dist/client/assets/{dist-DjWvWd-O.js → dist-Dikq_PJ3.js} +1 -1
  21. package/dist/client/assets/{dist-BXd_hxZC.js → dist-IDDdx_gZ.js} +1 -1
  22. package/dist/client/assets/{dist-Dn_eko3s.js → dist-McDiPyAf.js} +1 -1
  23. package/dist/client/assets/{dist-C60JfnoU.js → dist-ZcXCK1RB.js} +1 -1
  24. package/dist/client/assets/{dist-CUvVj4X7.js → dist-e4yYl6NS.js} +1 -1
  25. package/dist/client/assets/{index-BT6YQtrd.js → index-B2DCZtoX.js} +11 -11
  26. package/dist/client/index.html +1 -1
  27. package/dist/server/model-context-window.d.ts +49 -0
  28. package/dist/server/model-context-window.js +183 -7
  29. package/dist/server/providers.js +10 -2
  30. package/dist/server/runtime.js +1 -1
  31. package/dist/server/types.d.ts +1 -0
  32. package/dist/shared/model-window-label.d.ts +15 -0
  33. package/dist/shared/model-window-label.js +23 -0
  34. package/package.json +2 -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-BT6YQtrd.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>
@@ -6,6 +6,15 @@ import { type ModelStore } from "./models-store.js";
6
6
  */
7
7
  export declare const SUPER_PI_DEFAULT_CONTEXT_WINDOW = 128000;
8
8
  export declare const SUPER_PI_DEFAULT_MAX_TOKENS = 16384;
9
+ /**
10
+ * THE OUTPUT LIMIT SUPER PI GUESSES FOR A MODEL THAT THINKS.
11
+ *
12
+ * A reasoning model is given a bigger answer budget than an ordinary one, and 32768 is that guess.
13
+ * **It is a GUESS, and a guess is not a decision** — exactly like the 128000 above. When the
14
+ * provider publishes the real figure, that figure wins; and when the guess is what ends up in the
15
+ * person's file, the arbitration must not later read it as something somebody typed.
16
+ */
17
+ export declare const SUPER_PI_GUESSED_MAX_TOKENS = 32768;
9
18
  /** One model's declared window, as the person's file states it. */
10
19
  export type DeclaredWindow = {
11
20
  provider: string;
@@ -20,6 +29,24 @@ export type DeclaredWindow = {
20
29
  * a zero would be a claim ("this model has no window") rather than an absence.
21
30
  */
22
31
  export declare function declaredWindows(modelsJson: unknown): Map<string, number>;
32
+ /**
33
+ * The OUTPUT LIMITS the person's `models.json` declares, keyed by `provider/modelId`.
34
+ *
35
+ * THE SIBLING OF `declaredWindows`, AND DELIBERATELY A SEPARATE MAP. The window and the output limit
36
+ * are two different numbers about the same model, and a model can declare one of them and not the
37
+ * other: a hand-written entry that sets `contextWindow` says nothing about how long one answer may
38
+ * be. Putting both numbers in one map would make "declared" mean "declared one of two things", and
39
+ * the arbitration could not tell an absent output limit from an absent window.
40
+ */
41
+ export declare function declaredMaxTokens(modelsJson: unknown): Map<string, number>;
42
+ /**
43
+ * Reads the person's `models.json` and returns its declared output limits.
44
+ *
45
+ * A missing or unreadable file is an empty map, for the same reason `readDeclaredWindows` treats one
46
+ * that way: Super Pi has no opinion about a model somebody else configured, and inventing one would
47
+ * be the same mistake in the other direction.
48
+ */
49
+ export declare function readDeclaredMaxTokens(agentDir: string): Map<string, number>;
23
50
  /**
24
51
  * The window to USE for a model, given what the person's file says.
25
52
  *
@@ -78,6 +105,26 @@ export declare function readStoreWindows(agentDir: string): ModelStore;
78
105
  * taking the smallest is exactly how a million-token model ended up believing it had 128,000.
79
106
  */
80
107
  export declare function arbitrateContextWindow(declared: Map<string, number>, store: ModelStore, provider: string, modelId: string, reported?: number): number | undefined;
108
+ /**
109
+ * THE OUTPUT LIMIT A MODEL REALLY GETS, arbitrated across the sources that each claim to know it.
110
+ *
111
+ * THE SAME PRECEDENCE AS THE CONTEXT WINDOW, ON PURPOSE. The window was fixed by reading the
112
+ * provider's catalogue instead of Super Pi's own stamped placeholder, and the output limit is the
113
+ * same hole one number over: `MiniMax-M3` really answers in 512,000 tokens, and Super Pi stamped
114
+ * 16,384 on every model the provider did not describe. 16,384 is a length cap on ONE answer, so the
115
+ * long report a sub-session was asked to write comes back cut off, and the turn is wasted - which is
116
+ * exactly why a sub-session that has to produce a long report dies while a short chatty one does not.
117
+ *
118
+ * PRECEDENCE, HIGHEST FIRST:
119
+ *
120
+ * 1. A NON-DEFAULT value in the person's `models.json` - somebody typed it, so it is a decision.
121
+ * 2. The CATALOGUE (`models-store.json`) - the provider's self-report.
122
+ * 3. The `reported` value the model object already carries, then nothing (`undefined`).
123
+ *
124
+ * `undefined` MEANS "SAY NOTHING". It is not 0: zero would be a claim ("this model may not answer
125
+ * at all"), and a model nobody describes simply has no known limit, so the caller's own value stands.
126
+ */
127
+ export declare function arbitrateMaxTokens(declared: Map<string, number>, store: ModelStore, provider: string, modelId: string, reported?: number): number | undefined;
81
128
  /**
82
129
  * THE CATALOG'S WINDOWS, ARBITRATED THE WAY A SESSION'S ARE.
83
130
  *
@@ -100,6 +147,7 @@ export declare function withArbitratedWindows<T extends {
100
147
  provider: string;
101
148
  modelId: string;
102
149
  contextWindow: number;
150
+ maxTokens?: number;
103
151
  }>(options: readonly T[], agentDir: string): T[];
104
152
  /**
105
153
  * THE RESOLVER A LIVE SESSION HANDS ITS MODEL THROUGH.
@@ -133,5 +181,6 @@ export declare function createModelResolver(options: {
133
181
  provider: string;
134
182
  id: string;
135
183
  contextWindow?: number;
184
+ maxTokens?: number;
136
185
  [key: string]: unknown;
137
186
  } | 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";
@@ -40,6 +48,15 @@ import { readModelStore, storeWindowFor } from "./models-store.js";
40
48
  */
41
49
  export const SUPER_PI_DEFAULT_CONTEXT_WINDOW = 128000;
42
50
  export const SUPER_PI_DEFAULT_MAX_TOKENS = 16384;
51
+ /**
52
+ * THE OUTPUT LIMIT SUPER PI GUESSES FOR A MODEL THAT THINKS.
53
+ *
54
+ * A reasoning model is given a bigger answer budget than an ordinary one, and 32768 is that guess.
55
+ * **It is a GUESS, and a guess is not a decision** — exactly like the 128000 above. When the
56
+ * provider publishes the real figure, that figure wins; and when the guess is what ends up in the
57
+ * person's file, the arbitration must not later read it as something somebody typed.
58
+ */
59
+ export const SUPER_PI_GUESSED_MAX_TOKENS = 32768;
43
60
  /**
44
61
  * The windows the person's `models.json` declares, keyed by `provider/modelId`.
45
62
  *
@@ -74,6 +91,58 @@ export function declaredWindows(modelsJson) {
74
91
  }
75
92
  return out;
76
93
  }
94
+ /**
95
+ * The OUTPUT LIMITS the person's `models.json` declares, keyed by `provider/modelId`.
96
+ *
97
+ * THE SIBLING OF `declaredWindows`, AND DELIBERATELY A SEPARATE MAP. The window and the output limit
98
+ * are two different numbers about the same model, and a model can declare one of them and not the
99
+ * other: a hand-written entry that sets `contextWindow` says nothing about how long one answer may
100
+ * be. Putting both numbers in one map would make "declared" mean "declared one of two things", and
101
+ * the arbitration could not tell an absent output limit from an absent window.
102
+ */
103
+ export function declaredMaxTokens(modelsJson) {
104
+ const out = new Map();
105
+ if (!modelsJson || typeof modelsJson !== "object")
106
+ return out;
107
+ const providers = modelsJson.providers;
108
+ if (!providers || typeof providers !== "object")
109
+ return out;
110
+ for (const [providerId, provider] of Object.entries(providers)) {
111
+ if (!provider || typeof provider !== "object")
112
+ continue;
113
+ const models = provider.models;
114
+ if (!Array.isArray(models))
115
+ continue;
116
+ for (const model of models) {
117
+ if (!model || typeof model !== "object")
118
+ continue;
119
+ const id = model.id;
120
+ const maxTokens = model.maxTokens;
121
+ if (typeof id !== "string" || !id.trim())
122
+ continue;
123
+ if (typeof maxTokens !== "number" || !Number.isSafeInteger(maxTokens) || maxTokens <= 0)
124
+ continue;
125
+ out.set(`${providerId}/${id}`, maxTokens);
126
+ }
127
+ }
128
+ return out;
129
+ }
130
+ /**
131
+ * Reads the person's `models.json` and returns its declared output limits.
132
+ *
133
+ * A missing or unreadable file is an empty map, for the same reason `readDeclaredWindows` treats one
134
+ * that way: Super Pi has no opinion about a model somebody else configured, and inventing one would
135
+ * be the same mistake in the other direction.
136
+ */
137
+ export function readDeclaredMaxTokens(agentDir) {
138
+ try {
139
+ const raw = readFileSync(join(agentDir, "models.json"), "utf8");
140
+ return declaredMaxTokens(JSON.parse(raw));
141
+ }
142
+ catch {
143
+ return new Map();
144
+ }
145
+ }
77
146
  /**
78
147
  * The window to USE for a model, given what the person's file says.
79
148
  *
@@ -195,6 +264,91 @@ export function arbitrateContextWindow(declared, store, provider, modelId, repor
195
264
  return reported;
196
265
  return exact ?? deliberate ?? storeEntry?.contextWindow ?? reported;
197
266
  }
267
+ /**
268
+ * Is a `models.json` output limit a PERSON's decision, or just Super Pi's own default stamped at import?
269
+ *
270
+ * The same question as `isDeliberateWindow`, asked of the other number. The value Super Pi writes
271
+ * when the provider said nothing (16384) is a placeholder, and a placeholder never outranks the
272
+ * catalogue's real figure.
273
+ */
274
+ function isDeliberateMaxTokens(maxTokens) {
275
+ // BOTH OF SUPER PI'S OWN NUMBERS ARE PLACEHOLDERS, NOT DECISIONS. 16384 is the default it stamps
276
+ // on every model the provider did not describe, and 32768 is the bigger budget it guesses for a
277
+ // model that thinks. A value equal to either of them is Super Pi's own guess coming back from
278
+ // the file it was written to - and a guess must never outrank the catalogue's real figure.
279
+ return (maxTokens !== undefined &&
280
+ maxTokens !== SUPER_PI_DEFAULT_MAX_TOKENS &&
281
+ maxTokens !== SUPER_PI_GUESSED_MAX_TOKENS);
282
+ }
283
+ /**
284
+ * What the catalogue says about how long ONE ANSWER of this model may be.
285
+ *
286
+ * The provider's own entry wins, and when the catalogue holds the same model under two provider ids,
287
+ * the LARGEST limit is the model's real one - the same rule the window follows, and for the same
288
+ * reason: a smaller duplicate is an older or narrower copy of the same truth.
289
+ */
290
+ function storeMaxTokensFor(store, modelId, provider) {
291
+ const scoped = storeWindowFor(store, modelId, provider)?.maxTokens;
292
+ if (scoped !== undefined)
293
+ return scoped;
294
+ const key = modelId.trim().toLowerCase();
295
+ if (!key)
296
+ return undefined;
297
+ let largest;
298
+ for (const [storeKey, entry] of store.byProviderModel) {
299
+ const slash = storeKey.indexOf("/");
300
+ if (slash < 0 || storeKey.slice(slash + 1) !== key)
301
+ continue;
302
+ if (entry.maxTokens === undefined)
303
+ continue;
304
+ if (largest === undefined || entry.maxTokens > largest)
305
+ largest = entry.maxTokens;
306
+ }
307
+ return largest;
308
+ }
309
+ /**
310
+ * THE OUTPUT LIMIT A MODEL REALLY GETS, arbitrated across the sources that each claim to know it.
311
+ *
312
+ * THE SAME PRECEDENCE AS THE CONTEXT WINDOW, ON PURPOSE. The window was fixed by reading the
313
+ * provider's catalogue instead of Super Pi's own stamped placeholder, and the output limit is the
314
+ * same hole one number over: `MiniMax-M3` really answers in 512,000 tokens, and Super Pi stamped
315
+ * 16,384 on every model the provider did not describe. 16,384 is a length cap on ONE answer, so the
316
+ * long report a sub-session was asked to write comes back cut off, and the turn is wasted - which is
317
+ * exactly why a sub-session that has to produce a long report dies while a short chatty one does not.
318
+ *
319
+ * PRECEDENCE, HIGHEST FIRST:
320
+ *
321
+ * 1. A NON-DEFAULT value in the person's `models.json` - somebody typed it, so it is a decision.
322
+ * 2. The CATALOGUE (`models-store.json`) - the provider's self-report.
323
+ * 3. The `reported` value the model object already carries, then nothing (`undefined`).
324
+ *
325
+ * `undefined` MEANS "SAY NOTHING". It is not 0: zero would be a claim ("this model may not answer
326
+ * at all"), and a model nobody describes simply has no known limit, so the caller's own value stands.
327
+ */
328
+ export function arbitrateMaxTokens(declared, store, provider, modelId, reported) {
329
+ const exact = declared.get(`${provider}/${modelId}`);
330
+ if (isDeliberateMaxTokens(exact))
331
+ return exact;
332
+ // A deliberate cross-provider declaration still wins over the catalogue.
333
+ let deliberate;
334
+ for (const [key, maxTokens] of declared) {
335
+ const slash = key.indexOf("/");
336
+ if (slash < 0 || key.slice(slash + 1) !== modelId)
337
+ continue;
338
+ if (!isDeliberateMaxTokens(maxTokens))
339
+ continue;
340
+ if (deliberate === undefined || maxTokens > deliberate)
341
+ deliberate = maxTokens;
342
+ }
343
+ if (deliberate !== undefined)
344
+ return deliberate;
345
+ const fromStore = storeMaxTokensFor(store, modelId, provider);
346
+ if (fromStore !== undefined)
347
+ return fromStore;
348
+ if (isDeliberateMaxTokens(reported))
349
+ return reported;
350
+ return undefined;
351
+ }
198
352
  /**
199
353
  * THE CATALOG'S WINDOWS, ARBITRATED THE WAY A SESSION'S ARE.
200
354
  *
@@ -217,16 +371,26 @@ export function withArbitratedWindows(options, agentDir) {
217
371
  if (!options.length)
218
372
  return [];
219
373
  const declared = readDeclaredWindows(agentDir);
374
+ const declaredLimits = readDeclaredMaxTokens(agentDir);
220
375
  const catalogue = readStoreWindows(agentDir);
221
376
  return options.map((option) => {
222
377
  const reported = typeof option.contextWindow === "number" && option.contextWindow > 0 ? option.contextWindow : undefined;
223
378
  const window = arbitrateContextWindow(declared, catalogue, option.provider, option.modelId, reported);
224
- // THE SAME OBJECT WHEN THE WINDOW DID NOT CHANGE. A caller that holds the list it was given
225
- // and compares it with the next read is asking "did the answer change", and an allocation is
226
- // not an answer.
227
- if (window === undefined || window === option.contextWindow)
379
+ // THE OUTPUT LIMIT IS ARBITRATED BY THE SAME RULE, ON THE SAME SOURCES. The two numbers are
380
+ // looked up in their own maps, because a model can declare one of them and not the other.
381
+ const reportedLimit = typeof option.maxTokens === "number" && option.maxTokens > 0 ? option.maxTokens : undefined;
382
+ const maxTokens = arbitrateMaxTokens(declaredLimits, catalogue, option.provider, option.modelId, reportedLimit);
383
+ const windowChanged = window !== undefined && window !== option.contextWindow;
384
+ const limitChanged = maxTokens !== undefined && maxTokens !== option.maxTokens;
385
+ // THE SAME OBJECT WHEN NOTHING CHANGED. A caller that holds the list it was given and compares
386
+ // it with the next read is asking "did the answer change", and an allocation is not an answer.
387
+ if (!windowChanged && !limitChanged)
228
388
  return option;
229
- return { ...option, contextWindow: window };
389
+ return {
390
+ ...option,
391
+ ...(windowChanged ? { contextWindow: window } : {}),
392
+ ...(limitChanged ? { maxTokens } : {}),
393
+ };
230
394
  });
231
395
  }
232
396
  /**
@@ -254,6 +418,7 @@ export function withArbitratedWindows(options, agentDir) {
254
418
  */
255
419
  export function createModelResolver(options) {
256
420
  const declared = readDeclaredWindows(options.agentDir);
421
+ const declaredLimits = readDeclaredMaxTokens(options.agentDir);
257
422
  const catalogue = readStoreWindows(options.agentDir);
258
423
  return (provider, modelId) => {
259
424
  const found = options.modelRuntime.getModel?.(provider, modelId);
@@ -261,8 +426,19 @@ export function createModelResolver(options) {
261
426
  return undefined;
262
427
  const model = found;
263
428
  const window = arbitrateContextWindow(declared, catalogue, provider, modelId, model.contextWindow);
429
+ // The OUTPUT LIMIT IS ARBITRATED THE SAME WAY, AND WRITTEN ONLY WHEN THERE IS ONE. A model
430
+ // Super Pi has no opinion about keeps the limit Pi gave it; a limit of 0 would be a claim
431
+ // ("this model may not answer at all") rather than an absence.
432
+ const maxTokens = arbitrateMaxTokens(declaredLimits, catalogue, provider, modelId, model.maxTokens);
264
433
  // The model is handed to Pi WHOLE - it is what the agent runs on - so this is where the
265
- // corrected window has to be. A model Super Pi has no opinion about is handed over untouched.
266
- return window === undefined ? model : { ...model, contextWindow: window };
434
+ // corrected window and the corrected output limit have to be. A model Super Pi has no opinion
435
+ // about is handed over untouched.
436
+ if (window === undefined && maxTokens === undefined)
437
+ return model;
438
+ return {
439
+ ...model,
440
+ ...(window === undefined ? {} : { contextWindow: window }),
441
+ ...(maxTokens === undefined ? {} : { maxTokens }),
442
+ };
267
443
  };
268
444
  }
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
2
2
  import { mkdir, readFile, rename, stat, writeFile } from "node:fs/promises";
3
3
  import { dirname, join } from "node:path";
4
4
  import { readModelStore, storeWindowFor } from "./models-store.js";
5
+ import { SUPER_PI_DEFAULT_MAX_TOKENS, SUPER_PI_GUESSED_MAX_TOKENS as GUESSED_MAX_TOKENS } from "./model-context-window.js";
5
6
  /**
6
7
  * The API adapters Pi ships, as the ids a provider may name.
7
8
  *
@@ -25,7 +26,9 @@ export const KNOWN_APIS = [
25
26
  /** The context window a model gets when the form does not say. Pi's own default. */
26
27
  const DEFAULT_CONTEXT_WINDOW = 128000;
27
28
  /** The output budget a model gets when the form does not say. Pi's own default. */
28
- const DEFAULT_MAX_TOKENS = 16384;
29
+ // THE SAME NUMBER AS `SUPER_PI_DEFAULT_MAX_TOKENS`, READ FROM THERE: the placeholder Super Pi
30
+ // stamps is the placeholder the arbitration must recognise later, so they cannot be two literals.
31
+ const DEFAULT_MAX_TOKENS = SUPER_PI_DEFAULT_MAX_TOKENS;
29
32
  /**
30
33
  * Pi's global configuration directory - where `models.json` and `auth.json` live.
31
34
  *
@@ -820,7 +823,12 @@ export function parseRemoteModels(payload) {
820
823
  const contextWindow = typeof rec.context_window === "number"
821
824
  ? rec.context_window
822
825
  : catalogue?.contextWindow ?? DEFAULT_CONTEXT_WINDOW;
823
- const maxTokens = reasoning ? 32768 : catalogue?.maxTokens ?? DEFAULT_MAX_TOKENS;
826
+ // THE CATALOGUE OUTRANKS THE REASONING GUESS, AND THE ORDER IS THE WHOLE POINT. A reasoning
827
+ // model used to be stamped with 32768 BEFORE the catalogue was consulted, so a model whose
828
+ // provider publishes a bigger answer limit got a smaller one - the same hole as the window
829
+ // one number over, with the same consequence: the limit Super Pi invented is the limit the
830
+ // session runs on. The guess is what is left when nobody knows better.
831
+ const maxTokens = catalogue?.maxTokens ?? (reasoning ? GUESSED_MAX_TOKENS : DEFAULT_MAX_TOKENS);
824
832
  discovered.push({
825
833
  id,
826
834
  name: id,
@@ -3023,7 +3023,7 @@ export function describeModel(value) {
3023
3023
  // check is here because this runs against a field read off the wire from a process that does no
3024
3024
  // validation of its own.
3025
3025
  const input = Array.isArray(model.input) ? model.input.filter((value) => typeof value === "string") : [];
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, 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") };
3027
3027
  }
3028
3028
  export function describeModels(value) {
3029
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
  /**
@@ -22,3 +22,18 @@
22
22
  * believe.
23
23
  */
24
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;
@@ -30,3 +30,26 @@ export function formatModelWindow(window) {
30
30
  return `${Math.round(window / 1000)}K`;
31
31
  return String(window);
32
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.194",
3
+ "version": "0.1.196",
4
4
  "description": "Web control plane and companion for Pi",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -130,6 +130,7 @@
130
130
  "scripts/model-context-window.test.mjs",
131
131
  "scripts/run-gate.test.mjs",
132
132
  "scripts/model-window-label.test.mjs",
133
+ "scripts/model-output-limit.test.mjs",
133
134
  "scripts/update-ui-contract.test.mjs",
134
135
  "scripts/stopping-marker.test.mjs",
135
136
  "scripts/update-button-state.test.mjs",