@evandu/super-pi 0.1.193 → 0.1.194

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 +3 -3
  2. package/dist/client/assets/{CodeMirrorEditor-Cmx7-z0f.js → CodeMirrorEditor-Q1Yw7L2W.js} +2 -2
  3. package/dist/client/assets/{dist-frBiV55p.js → dist-B6R1PTDe.js} +1 -1
  4. package/dist/client/assets/{dist-BzqUlzAf.js → dist-BXd_hxZC.js} +1 -1
  5. package/dist/client/assets/{dist-BKx3CpQJ.js → dist-BxiObY5p.js} +1 -1
  6. package/dist/client/assets/{dist-CDSDxXju.js → dist-BzTFldVl.js} +1 -1
  7. package/dist/client/assets/{dist-C0PMHwdm.js → dist-BzZeOpW9.js} +1 -1
  8. package/dist/client/assets/{dist-CKZOnuRU.js → dist-C3HWN2LG.js} +1 -1
  9. package/dist/client/assets/{dist-V27Fcf8p.js → dist-C60JfnoU.js} +1 -1
  10. package/dist/client/assets/{dist-akJoBtjs.js → dist-CBOvaGIi.js} +1 -1
  11. package/dist/client/assets/{dist-DHFt0Hvo.js → dist-CCu0IPPb.js} +1 -1
  12. package/dist/client/assets/{dist-CXDhHY7N.js → dist-CUvVj4X7.js} +1 -1
  13. package/dist/client/assets/{dist-C2ltv_8u.js → dist-CXirFx2P.js} +1 -1
  14. package/dist/client/assets/{dist-CWlI6qO0.js → dist-CrbCG3on.js} +1 -1
  15. package/dist/client/assets/{dist-D_7x3oZt.js → dist-D7dAoVBM.js} +1 -1
  16. package/dist/client/assets/{dist-Cblc22Ag.js → dist-DRUh6SDZ.js} +1 -1
  17. package/dist/client/assets/{dist-BdiInYmk.js → dist-DS1w-SLi.js} +1 -1
  18. package/dist/client/assets/{dist-RHYiODih.js → dist-DSn8NhPW.js} +1 -1
  19. package/dist/client/assets/{dist-Bq7p17eF.js → dist-DjWvWd-O.js} +1 -1
  20. package/dist/client/assets/{dist-B8CAEuXW.js → dist-Dn_eko3s.js} +1 -1
  21. package/dist/client/assets/{dist-ibsGPa_S.js → dist-EQ3ztI-3.js} +1 -1
  22. package/dist/client/assets/{dist-CcuBp_Kn.js → dist-f8Zhwj7K.js} +1 -1
  23. package/dist/client/assets/{dist-WfagMkC4.js → dist-gABF84ho.js} +1 -1
  24. package/dist/client/assets/{dist-BMSVWA_A.js → dist-hWnJl8_S.js} +1 -1
  25. package/dist/client/assets/{index-Dx7HAZ5j.js → index-BT6YQtrd.js} +11 -11
  26. package/dist/client/index.html +1 -1
  27. package/dist/server/model-context-window.d.ts +23 -0
  28. package/dist/server/model-context-window.js +34 -0
  29. package/dist/server/runtime.d.ts +14 -0
  30. package/dist/server/runtime.js +29 -2
  31. package/dist/shared/model-window-label.d.ts +24 -0
  32. package/dist/shared/model-window-label.js +32 -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-Dx7HAZ5j.js"></script>
11
+ <script type="module" crossorigin src="/assets/index-BT6YQtrd.js"></script>
12
12
  <link rel="stylesheet" crossorigin href="/assets/index-BXQjUHV_.css">
13
13
  </head>
14
14
  <body>
@@ -78,6 +78,29 @@ export declare function readStoreWindows(agentDir: string): ModelStore;
78
78
  * taking the smallest is exactly how a million-token model ended up believing it had 128,000.
79
79
  */
80
80
  export declare function arbitrateContextWindow(declared: Map<string, number>, store: ModelStore, provider: string, modelId: string, reported?: number): number | undefined;
81
+ /**
82
+ * THE CATALOG'S WINDOWS, ARBITRATED THE WAY A SESSION'S ARE.
83
+ *
84
+ * WHY THE CATALOG NEEDS THIS AT ALL. There are two ways Super Pi can read the model list, and they
85
+ * do not agree: Pi's SDK hands over whole model objects (window included), while a spawned Pi in
86
+ * RPC mode answers with a reduced list that has no window on it at all. So the number the reader is
87
+ * shown depends on WHICH PATH the machine happened to take - and the path that drops it is the one
88
+ * this machine takes. A picker that silently omits the window is a picker that cannot answer the
89
+ * one question it exists to answer: can this model hold a long task?
90
+ *
91
+ * WHY THE SAME ARBITRATION. The number printed has to be the number the session will run on, or it
92
+ * is a decoration. The session's window is decided by `arbitrateContextWindow` over the person's
93
+ * file and the provider's catalogue, so the catalogue is arbitrated the same way - one rule, one
94
+ * answer, and the label a reader sees is the limit their session really has.
95
+ *
96
+ * A window of 0 means "this source did not say", not "this model has no window": it is passed on
97
+ * as absent so the arbitration can go on to the sources that do know.
98
+ */
99
+ export declare function withArbitratedWindows<T extends {
100
+ provider: string;
101
+ modelId: string;
102
+ contextWindow: number;
103
+ }>(options: readonly T[], agentDir: string): T[];
81
104
  /**
82
105
  * THE RESOLVER A LIVE SESSION HANDS ITS MODEL THROUGH.
83
106
  *
@@ -195,6 +195,40 @@ export function arbitrateContextWindow(declared, store, provider, modelId, repor
195
195
  return reported;
196
196
  return exact ?? deliberate ?? storeEntry?.contextWindow ?? reported;
197
197
  }
198
+ /**
199
+ * THE CATALOG'S WINDOWS, ARBITRATED THE WAY A SESSION'S ARE.
200
+ *
201
+ * WHY THE CATALOG NEEDS THIS AT ALL. There are two ways Super Pi can read the model list, and they
202
+ * do not agree: Pi's SDK hands over whole model objects (window included), while a spawned Pi in
203
+ * RPC mode answers with a reduced list that has no window on it at all. So the number the reader is
204
+ * shown depends on WHICH PATH the machine happened to take - and the path that drops it is the one
205
+ * this machine takes. A picker that silently omits the window is a picker that cannot answer the
206
+ * one question it exists to answer: can this model hold a long task?
207
+ *
208
+ * WHY THE SAME ARBITRATION. The number printed has to be the number the session will run on, or it
209
+ * is a decoration. The session's window is decided by `arbitrateContextWindow` over the person's
210
+ * file and the provider's catalogue, so the catalogue is arbitrated the same way - one rule, one
211
+ * answer, and the label a reader sees is the limit their session really has.
212
+ *
213
+ * A window of 0 means "this source did not say", not "this model has no window": it is passed on
214
+ * as absent so the arbitration can go on to the sources that do know.
215
+ */
216
+ export function withArbitratedWindows(options, agentDir) {
217
+ if (!options.length)
218
+ return [];
219
+ const declared = readDeclaredWindows(agentDir);
220
+ const catalogue = readStoreWindows(agentDir);
221
+ return options.map((option) => {
222
+ const reported = typeof option.contextWindow === "number" && option.contextWindow > 0 ? option.contextWindow : undefined;
223
+ 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)
228
+ return option;
229
+ return { ...option, contextWindow: window };
230
+ });
231
+ }
198
232
  /**
199
233
  * THE RESOLVER A LIVE SESSION HANDS ITS MODEL THROUGH.
200
234
  *
@@ -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.
@@ -0,0 +1,24 @@
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;
@@ -0,0 +1,32 @@
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
+ }
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.194",
4
4
  "description": "Web control plane and companion for Pi",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -129,6 +129,7 @@
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",
132
133
  "scripts/update-ui-contract.test.mjs",
133
134
  "scripts/stopping-marker.test.mjs",
134
135
  "scripts/update-button-state.test.mjs",