@evandu/super-pi 0.1.194 → 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 (33) 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 +40 -0
  28. package/dist/server/model-context-window.js +168 -7
  29. package/dist/server/runtime.js +1 -1
  30. package/dist/server/types.d.ts +1 -0
  31. package/dist/shared/model-window-label.d.ts +15 -0
  32. package/dist/shared/model-window-label.js +23 -0
  33. 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>
@@ -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,26 @@ 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;
81
119
  /**
82
120
  * THE CATALOG'S WINDOWS, ARBITRATED THE WAY A SESSION'S ARE.
83
121
  *
@@ -100,6 +138,7 @@ export declare function withArbitratedWindows<T extends {
100
138
  provider: string;
101
139
  modelId: string;
102
140
  contextWindow: number;
141
+ maxTokens?: number;
103
142
  }>(options: readonly T[], agentDir: string): T[];
104
143
  /**
105
144
  * THE RESOLVER A LIVE SESSION HANDS ITS MODEL THROUGH.
@@ -133,5 +172,6 @@ export declare function createModelResolver(options: {
133
172
  provider: string;
134
173
  id: string;
135
174
  contextWindow?: number;
175
+ maxTokens?: number;
136
176
  [key: string]: unknown;
137
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,85 @@ 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
+ }
198
337
  /**
199
338
  * THE CATALOG'S WINDOWS, ARBITRATED THE WAY A SESSION'S ARE.
200
339
  *
@@ -217,16 +356,26 @@ export function withArbitratedWindows(options, agentDir) {
217
356
  if (!options.length)
218
357
  return [];
219
358
  const declared = readDeclaredWindows(agentDir);
359
+ const declaredLimits = readDeclaredMaxTokens(agentDir);
220
360
  const catalogue = readStoreWindows(agentDir);
221
361
  return options.map((option) => {
222
362
  const reported = typeof option.contextWindow === "number" && option.contextWindow > 0 ? option.contextWindow : undefined;
223
363
  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)
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)
228
373
  return option;
229
- return { ...option, contextWindow: window };
374
+ return {
375
+ ...option,
376
+ ...(windowChanged ? { contextWindow: window } : {}),
377
+ ...(limitChanged ? { maxTokens } : {}),
378
+ };
230
379
  });
231
380
  }
232
381
  /**
@@ -254,6 +403,7 @@ export function withArbitratedWindows(options, agentDir) {
254
403
  */
255
404
  export function createModelResolver(options) {
256
405
  const declared = readDeclaredWindows(options.agentDir);
406
+ const declaredLimits = readDeclaredMaxTokens(options.agentDir);
257
407
  const catalogue = readStoreWindows(options.agentDir);
258
408
  return (provider, modelId) => {
259
409
  const found = options.modelRuntime.getModel?.(provider, modelId);
@@ -261,8 +411,19 @@ export function createModelResolver(options) {
261
411
  return undefined;
262
412
  const model = found;
263
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);
264
418
  // 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 };
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
+ };
267
428
  };
268
429
  }
@@ -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.195",
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",