@evandu/super-pi-server 0.0.0-stage → 0.1.260
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.
- package/README.md +250 -3
- package/agents/code-auditor.md +64 -0
- package/agents/code-designer.md +64 -0
- package/agents/coder.md +24 -0
- package/agents/critic.md +24 -0
- package/agents/document-organizer.md +48 -0
- package/agents/patcher.md +27 -0
- package/agents/planner.md +30 -0
- package/agents/project-leader.md +28 -0
- package/agents/reviewer.md +27 -0
- package/agents/scout.md +27 -0
- package/agents/solution-designer.md +62 -0
- package/agents/super-pi-documents/index.ts +92 -0
- package/agents/super-pi-feishu/index.ts +88 -0
- package/agents/super-pi-knowledge/index.ts +70 -0
- package/agents/super-pi-managed-model/index.ts +9 -0
- package/agents/super-pi-memory/index.ts +75 -0
- package/agents/super-pi-native-tools/index.ts +1 -0
- package/agents/super-pi-task/core.ts +2262 -0
- package/agents/super-pi-task/index.ts +814 -0
- package/agents/super-pi-task/workflow-schema.ts +34 -0
- package/agents/super-pi-web/index.ts +32 -0
- package/agents/verifier.md +25 -0
- package/assets/fonts/LICENSE +92 -0
- package/assets/fonts/NotoSansSC-Bold.otf +0 -0
- package/assets/fonts/NotoSansSC-Regular.otf +0 -0
- package/assets/knowledge-model/README.md +37 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/config.json +31 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/onnx/model_quantized.onnx +0 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/special_tokens_map.json +7 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/tokenizer.json +21278 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/tokenizer_config.json +15 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/vocab.txt +21128 -0
- package/bin/npm-prefix.d.ts +1 -0
- package/bin/npm-prefix.js +10 -0
- package/bin/super-pi.js +349 -0
- package/dist/client/.super-pi-client-sources.json +82 -0
- package/dist/client/assets/CodeMirrorEditor-mi9rGUce.js +2 -0
- package/dist/client/assets/GitDiffEditor-CpoDDQrA.css +1 -0
- package/dist/client/assets/GitDiffEditor-FQBfGxOY.js +29 -0
- package/dist/client/assets/diff-ChtP43wD.js +1 -0
- package/dist/client/assets/dist-AW5lyI3I.js +1 -0
- package/dist/client/assets/dist-B3-a6uF0.js +7 -0
- package/dist/client/assets/dist-BGxkyh6e.js +1 -0
- package/dist/client/assets/dist-BJxfd7yb.js +11 -0
- package/dist/client/assets/dist-BRVQKlcp.js +1 -0
- package/dist/client/assets/dist-BV64A9Ji.js +1 -0
- package/dist/client/assets/dist-BXAOrsjq.js +1 -0
- package/dist/client/assets/dist-CKF2Jksy.js +1 -0
- package/dist/client/assets/dist-CX_Hm4GS.js +1 -0
- package/dist/client/assets/dist-Cus6_oaF.js +2 -0
- package/dist/client/assets/dist-Cx00EZKR.js +23 -0
- package/dist/client/assets/dist-D71y2EI1.js +1 -0
- package/dist/client/assets/dist-D978o95T.js +5 -0
- package/dist/client/assets/dist-Dc1MBGAG.js +1 -0
- package/dist/client/assets/dist-Dds-qLxY.js +9 -0
- package/dist/client/assets/dist-DeD9copn.js +1 -0
- package/dist/client/assets/dist-DuvGReu-.js +6 -0
- package/dist/client/assets/dist-Dvb0SqcK.js +2 -0
- package/dist/client/assets/dist-J6XWqRpB.js +3 -0
- package/dist/client/assets/dist-QzbOCAU6.js +1 -0
- package/dist/client/assets/dist-moiMRpw_.js +1 -0
- package/dist/client/assets/dist-scBkrwv-.js +2 -0
- package/dist/client/assets/dockerfile-BDePf5PZ.js +1 -0
- package/dist/client/assets/index-Cn7hdrDw.js +350 -0
- package/dist/client/assets/index-UfzqdECL.css +1 -0
- package/dist/client/assets/powershell-D8WpQPaX.js +1 -0
- package/dist/client/assets/properties-C357ku5U.js +1 -0
- package/dist/client/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- package/dist/client/assets/ruby-ChfNwlCY.js +1 -0
- package/dist/client/assets/shell-DwuoZtxw.js +1 -0
- package/dist/client/assets/swift-DKB6_1j6.js +1 -0
- package/dist/client/assets/toml-BPTmHmyx.js +1 -0
- package/dist/client/favicon.ico +0 -0
- package/dist/client/favicon.png +0 -0
- package/dist/client/favicon.svg +10 -0
- package/dist/client/index.html +18 -0
- package/dist/extension.d.ts +15 -0
- package/dist/extension.js +126 -0
- package/dist/server/active-memory.d.ts +247 -0
- package/dist/server/active-memory.js +669 -0
- package/dist/server/agents.d.ts +245 -0
- package/dist/server/agents.js +701 -0
- package/dist/server/application/catalog-service.d.ts +98 -0
- package/dist/server/application/catalog-service.js +245 -0
- package/dist/server/application/conversation-service.d.ts +245 -0
- package/dist/server/application/conversation-service.js +654 -0
- package/dist/server/application/document-service.d.ts +68 -0
- package/dist/server/application/document-service.js +120 -0
- package/dist/server/application/extension-ui-service.d.ts +44 -0
- package/dist/server/application/extension-ui-service.js +135 -0
- package/dist/server/application/feishu-service.d.ts +179 -0
- package/dist/server/application/feishu-service.js +358 -0
- package/dist/server/application/group-chat-service.d.ts +75 -0
- package/dist/server/application/group-chat-service.js +953 -0
- package/dist/server/application/group-execution.d.ts +15 -0
- package/dist/server/application/group-execution.js +77 -0
- package/dist/server/application/project-service.d.ts +464 -0
- package/dist/server/application/project-service.js +2523 -0
- package/dist/server/application/provider-service.d.ts +174 -0
- package/dist/server/application/provider-service.js +510 -0
- package/dist/server/application/run-service.d.ts +547 -0
- package/dist/server/application/run-service.js +2683 -0
- package/dist/server/application/scheduled-task-service.d.ts +184 -0
- package/dist/server/application/scheduled-task-service.js +391 -0
- package/dist/server/application/session-orchestrator-service.d.ts +388 -0
- package/dist/server/application/session-orchestrator-service.js +1146 -0
- package/dist/server/application/session-reminder-service.d.ts +59 -0
- package/dist/server/application/session-reminder-service.js +141 -0
- package/dist/server/application/session-watchdog.d.ts +171 -0
- package/dist/server/application/session-watchdog.js +284 -0
- package/dist/server/application/workspace-service.d.ts +52 -0
- package/dist/server/application/workspace-service.js +186 -0
- package/dist/server/application/worktree-service.d.ts +13 -0
- package/dist/server/application/worktree-service.js +76 -0
- package/dist/server/browser-access.d.ts +34 -0
- package/dist/server/browser-access.js +89 -0
- package/dist/server/capability.d.ts +105 -0
- package/dist/server/capability.js +170 -0
- package/dist/server/command-handler.d.ts +93 -0
- package/dist/server/command-handler.js +540 -0
- package/dist/server/content-search.d.ts +16 -0
- package/dist/server/content-search.js +235 -0
- package/dist/server/conversation-usage.d.ts +22 -0
- package/dist/server/conversation-usage.js +43 -0
- package/dist/server/documents.d.ts +152 -0
- package/dist/server/documents.js +998 -0
- package/dist/server/engineering-learning.d.ts +30 -0
- package/dist/server/engineering-learning.js +106 -0
- package/dist/server/exec-service.d.ts +45 -0
- package/dist/server/exec-service.js +167 -0
- package/dist/server/explicit-file-open.d.ts +34 -0
- package/dist/server/explicit-file-open.js +105 -0
- package/dist/server/failure-text.d.ts +18 -0
- package/dist/server/failure-text.js +44 -0
- package/dist/server/feishu-cli.d.ts +223 -0
- package/dist/server/feishu-cli.js +464 -0
- package/dist/server/file-changes.d.ts +119 -0
- package/dist/server/file-changes.js +280 -0
- package/dist/server/file-diff.d.ts +41 -0
- package/dist/server/file-diff.js +97 -0
- package/dist/server/file-index.d.ts +100 -0
- package/dist/server/file-index.js +296 -0
- package/dist/server/file-name-index.d.ts +160 -0
- package/dist/server/file-name-index.js +411 -0
- package/dist/server/files.d.ts +269 -0
- package/dist/server/files.js +748 -0
- package/dist/server/git.d.ts +245 -0
- package/dist/server/git.js +903 -0
- package/dist/server/http-server.d.ts +45 -0
- package/dist/server/http-server.js +3830 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +485 -0
- package/dist/server/inline-thinking.d.ts +90 -0
- package/dist/server/inline-thinking.js +181 -0
- package/dist/server/json-comments.d.ts +14 -0
- package/dist/server/json-comments.js +71 -0
- package/dist/server/knowledge-embedding-worker.d.ts +1 -0
- package/dist/server/knowledge-embedding-worker.js +27 -0
- package/dist/server/knowledge-vectors.d.ts +150 -0
- package/dist/server/knowledge-vectors.js +385 -0
- package/dist/server/knowledge.d.ts +273 -0
- package/dist/server/knowledge.js +848 -0
- package/dist/server/length-continuation.d.ts +83 -0
- package/dist/server/length-continuation.js +118 -0
- package/dist/server/logging.d.ts +32 -0
- package/dist/server/logging.js +185 -0
- package/dist/server/managed-http-tunnel.d.ts +6 -0
- package/dist/server/managed-http-tunnel.js +85 -0
- package/dist/server/managed-http.d.ts +4 -0
- package/dist/server/managed-http.js +85 -0
- package/dist/server/managed-model-adapter.d.ts +17 -0
- package/dist/server/managed-model-adapter.js +75 -0
- package/dist/server/managed-model-gateway.d.ts +49 -0
- package/dist/server/managed-model-gateway.js +73 -0
- package/dist/server/managed-servers.d.ts +55 -0
- package/dist/server/managed-servers.js +396 -0
- package/dist/server/managed-ssh.d.ts +26 -0
- package/dist/server/managed-ssh.js +73 -0
- package/dist/server/manager-vault.d.ts +11 -0
- package/dist/server/manager-vault.js +67 -0
- package/dist/server/memory-recall.d.ts +25 -0
- package/dist/server/memory-recall.js +45 -0
- package/dist/server/memory.d.ts +67 -0
- package/dist/server/memory.js +216 -0
- package/dist/server/message-media.d.ts +7 -0
- package/dist/server/message-media.js +54 -0
- package/dist/server/model-context-window.d.ts +186 -0
- package/dist/server/model-context-window.js +444 -0
- package/dist/server/model-filter.d.ts +23 -0
- package/dist/server/model-filter.js +48 -0
- package/dist/server/models-store.d.ts +36 -0
- package/dist/server/models-store.js +132 -0
- package/dist/server/native-tool-settings.d.ts +25 -0
- package/dist/server/native-tool-settings.js +41 -0
- package/dist/server/native-tools-extension.d.ts +2 -0
- package/dist/server/native-tools-extension.js +39 -0
- package/dist/server/native-tools-service.d.ts +39 -0
- package/dist/server/native-tools-service.js +240 -0
- package/dist/server/persistence/app-state-repository.d.ts +65 -0
- package/dist/server/persistence/app-state-repository.js +1 -0
- package/dist/server/persistence/json-state-repository.d.ts +14 -0
- package/dist/server/persistence/json-state-repository.js +43 -0
- package/dist/server/persistence/open-state-store.d.ts +3 -0
- package/dist/server/persistence/open-state-store.js +35 -0
- package/dist/server/persistence/rename.d.ts +22 -0
- package/dist/server/persistence/rename.js +44 -0
- package/dist/server/persistence/sqlite-state-repository.d.ts +12 -0
- package/dist/server/persistence/sqlite-state-repository.js +264 -0
- package/dist/server/pi-command.d.ts +94 -0
- package/dist/server/pi-command.js +265 -0
- package/dist/server/pi-native.d.ts +12 -0
- package/dist/server/pi-native.js +16 -0
- package/dist/server/pi-session-events.d.ts +158 -0
- package/dist/server/pi-session-events.js +373 -0
- package/dist/server/pi-session-pool.d.ts +233 -0
- package/dist/server/pi-session-pool.js +382 -0
- package/dist/server/pi-session.d.ts +642 -0
- package/dist/server/pi-session.js +655 -0
- package/dist/server/presentations/schema.d.ts +120 -0
- package/dist/server/presentations/schema.js +128 -0
- package/dist/server/provider-network.d.ts +16 -0
- package/dist/server/provider-network.js +106 -0
- package/dist/server/provider-proxy.d.ts +18 -0
- package/dist/server/provider-proxy.js +200 -0
- package/dist/server/providers.d.ts +333 -0
- package/dist/server/providers.js +989 -0
- package/dist/server/remote-bootstrap.d.ts +17 -0
- package/dist/server/remote-bootstrap.js +119 -0
- package/dist/server/rpc-channel.d.ts +131 -0
- package/dist/server/rpc-channel.js +135 -0
- package/dist/server/runtime.d.ts +1393 -0
- package/dist/server/runtime.js +3286 -0
- package/dist/server/scheduled-tasks.d.ts +101 -0
- package/dist/server/scheduled-tasks.js +138 -0
- package/dist/server/server-context.d.ts +119 -0
- package/dist/server/server-context.js +1 -0
- package/dist/server/session-cwd.d.ts +19 -0
- package/dist/server/session-cwd.js +58 -0
- package/dist/server/session-ledger.d.ts +67 -0
- package/dist/server/session-ledger.js +76 -0
- package/dist/server/session-memory-scope.d.ts +4 -0
- package/dist/server/session-memory-scope.js +30 -0
- package/dist/server/session-repository.d.ts +100 -0
- package/dist/server/session-repository.js +246 -0
- package/dist/server/session-tree-scope.d.ts +125 -0
- package/dist/server/session-tree-scope.js +337 -0
- package/dist/server/skills.d.ts +23 -0
- package/dist/server/skills.js +190 -0
- package/dist/server/store.d.ts +1062 -0
- package/dist/server/store.js +3305 -0
- package/dist/server/subagent-runs.d.ts +185 -0
- package/dist/server/subagent-runs.js +383 -0
- package/dist/server/subagents.d.ts +200 -0
- package/dist/server/subagents.js +619 -0
- package/dist/server/task-tool.d.ts +282 -0
- package/dist/server/task-tool.js +507 -0
- package/dist/server/tavily.d.ts +32 -0
- package/dist/server/tavily.js +136 -0
- package/dist/server/team-context.d.ts +12 -0
- package/dist/server/team-context.js +180 -0
- package/dist/server/terminal.d.ts +163 -0
- package/dist/server/terminal.js +557 -0
- package/dist/server/thinking-level-discovery.d.ts +38 -0
- package/dist/server/thinking-level-discovery.js +183 -0
- package/dist/server/time-zone.d.ts +20 -0
- package/dist/server/time-zone.js +32 -0
- package/dist/server/tool-calls.d.ts +130 -0
- package/dist/server/tool-calls.js +341 -0
- package/dist/server/tool-llm.d.ts +72 -0
- package/dist/server/tool-llm.js +146 -0
- package/dist/server/tool-registry.d.ts +129 -0
- package/dist/server/tool-registry.js +249 -0
- package/dist/server/tool-runner.d.ts +112 -0
- package/dist/server/tool-runner.js +306 -0
- package/dist/server/turn-failure.d.ts +48 -0
- package/dist/server/turn-failure.js +148 -0
- package/dist/server/types.d.ts +2315 -0
- package/dist/server/types.js +11 -0
- package/dist/server/update-status.d.ts +14 -0
- package/dist/server/update-status.js +69 -0
- package/dist/server/update.d.ts +46 -0
- package/dist/server/update.js +104 -0
- package/dist/server/upload.d.ts +35 -0
- package/dist/server/upload.js +177 -0
- package/dist/server/version.d.ts +33 -0
- package/dist/server/version.js +111 -0
- package/dist/server/web.d.ts +27 -0
- package/dist/server/web.js +183 -0
- package/dist/server/workflow-engine.d.ts +47 -0
- package/dist/server/workflow-engine.js +255 -0
- package/dist/server/workflow.d.ts +329 -0
- package/dist/server/workflow.js +469 -0
- package/dist/server/workspace-file-indexes.d.ts +2 -0
- package/dist/server/workspace-file-indexes.js +61 -0
- package/dist/server/workspace-file-operations.d.ts +36 -0
- package/dist/server/workspace-file-operations.js +281 -0
- package/dist/server/workspace-file-response.d.ts +7 -0
- package/dist/server/workspace-file-response.js +79 -0
- package/dist/server/ws-server.d.ts +149 -0
- package/dist/server/ws-server.js +640 -0
- package/dist/shared/agent-order.d.ts +44 -0
- package/dist/shared/agent-order.js +50 -0
- package/dist/shared/archive-decisions.d.ts +44 -0
- package/dist/shared/archive-decisions.js +98 -0
- package/dist/shared/background-task.d.ts +25 -0
- package/dist/shared/background-task.js +183 -0
- package/dist/shared/child-session-lock.d.ts +37 -0
- package/dist/shared/child-session-lock.js +59 -0
- package/dist/shared/content-search.d.ts +22 -0
- package/dist/shared/content-search.js +1 -0
- package/dist/shared/conversation-title.d.ts +4 -0
- package/dist/shared/conversation-title.js +4 -0
- package/dist/shared/file-mentions.d.ts +17 -0
- package/dist/shared/file-mentions.js +91 -0
- package/dist/shared/git-commit.d.ts +11 -0
- package/dist/shared/git-commit.js +1 -0
- package/dist/shared/git-graph.d.ts +42 -0
- package/dist/shared/git-graph.js +30 -0
- package/dist/shared/group-chat.d.ts +132 -0
- package/dist/shared/group-chat.js +6 -0
- package/dist/shared/managed-servers.d.ts +36 -0
- package/dist/shared/managed-servers.js +1 -0
- package/dist/shared/message-media.d.ts +12 -0
- package/dist/shared/message-media.js +27 -0
- package/dist/shared/model-window-label.d.ts +39 -0
- package/dist/shared/model-window-label.js +55 -0
- package/dist/shared/native-tools.d.ts +43 -0
- package/dist/shared/native-tools.js +1 -0
- package/dist/shared/pi-cache-warming.d.ts +9 -0
- package/dist/shared/pi-cache-warming.js +4 -0
- package/dist/shared/project-overview.d.ts +107 -0
- package/dist/shared/project-overview.js +92 -0
- package/dist/shared/project-presentation.d.ts +55 -0
- package/dist/shared/project-presentation.js +111 -0
- package/dist/shared/provider-network.d.ts +30 -0
- package/dist/shared/provider-network.js +1 -0
- package/dist/shared/session-reporting.d.ts +40 -0
- package/dist/shared/session-reporting.js +97 -0
- package/dist/shared/session-search.d.ts +14 -0
- package/dist/shared/session-search.js +1 -0
- package/dist/shared/team-context-view.d.ts +33 -0
- package/dist/shared/team-context-view.js +49 -0
- package/dist/shared/team-context.d.ts +59 -0
- package/dist/shared/team-context.js +3 -0
- package/dist/shared/terminal-protocol.d.ts +71 -0
- package/dist/shared/terminal-protocol.js +1 -0
- package/dist/shared/thinking-levels.d.ts +53 -0
- package/dist/shared/thinking-levels.js +85 -0
- package/dist/shared/tool-glyph.d.ts +7 -0
- package/dist/shared/tool-glyph.js +19 -0
- package/dist/shared/transcript-order.d.ts +7 -0
- package/dist/shared/transcript-order.js +12 -0
- package/dist/shared/update-status.d.ts +28 -0
- package/dist/shared/update-status.js +1 -0
- package/dist/shared/workspace-file-preview.d.ts +4 -0
- package/dist/shared/workspace-file-preview.js +28 -0
- package/package.json +450 -4
- package/scripts/diagnose.mjs +603 -0
- package/scripts/patch-brace-expansion.mjs +260 -0
- package/scripts/restart-server.mjs +104 -0
- package/skills/presentation/SKILL.md +30 -0
- package/skills/presentation/references/data.md +10 -0
- package/skills/presentation/references/quality.md +12 -0
- package/skills/presentation/references/story.md +12 -0
- package/skills/presentation/references/templates-and-editing.md +11 -0
- package/skills/presentation/references/visual-system.md +10 -0
- package/skills/super-pi-agent-development/SKILL.md +25 -0
- package/skills/super-pi-development/SKILL.md +31 -0
- package/skills/super-pi-tool-development/SKILL.md +39 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { type ModelStore } from "./models-store.js";
|
|
2
|
+
/**
|
|
3
|
+
* THE DEFAULTS SUPER PI STAMPS WHEN IT DISCOVERS A MODEL. `providers.ts` writes these into
|
|
4
|
+
* `models.json` for every model the provider did not describe, and they are NOT a person's decision
|
|
5
|
+
* - they are a placeholder. The store's real number must outrank them.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SUPER_PI_DEFAULT_CONTEXT_WINDOW = 128000;
|
|
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;
|
|
18
|
+
/** One model's declared window, as the person's file states it. */
|
|
19
|
+
export type DeclaredWindow = {
|
|
20
|
+
provider: string;
|
|
21
|
+
modelId: string;
|
|
22
|
+
contextWindow: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The windows the person's `models.json` declares, keyed by `provider/modelId`.
|
|
26
|
+
*
|
|
27
|
+
* Pi's file shape is `{ providers: { <providerId>: { models: [{ id, contextWindow, ... }] } } }`,
|
|
28
|
+
* and a model without a `contextWindow` is simply not declared - it does not become a zero, because
|
|
29
|
+
* a zero would be a claim ("this model has no window") rather than an absence.
|
|
30
|
+
*/
|
|
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>;
|
|
50
|
+
/**
|
|
51
|
+
* The window to USE for a model, given what the person's file says.
|
|
52
|
+
*
|
|
53
|
+
* `undefined` means "say nothing" - the caller keeps whatever Pi believes. That is the honest
|
|
54
|
+
* answer for a model the person's file does not mention: Super Pi has no opinion about a model
|
|
55
|
+
* somebody else configured, and inventing one would be the same mistake in the other direction.
|
|
56
|
+
*
|
|
57
|
+
* TWO LOOKUPS, AND THE SECOND ONE IS THE ONE THAT MATTERS:
|
|
58
|
+
*
|
|
59
|
+
* 1. `provider/modelId` - the exact pair. This is the common case.
|
|
60
|
+
* 2. `modelId` ALONE, across every provider the person's file declares.
|
|
61
|
+
*
|
|
62
|
+
* The second lookup exists because a CONTEXT WINDOW IS A PROPERTY OF THE MODEL, NOT OF THE
|
|
63
|
+
* ENDPOINT. Measured on this machine: the person's `models.json` declares the model `MiniMax-M3`
|
|
64
|
+
* under the provider id `minimax` (the OpenAI-compatible endpoint) with `contextWindow: 128000`,
|
|
65
|
+
* while Pi's remote catalogue declares the SAME model under a DIFFERENT provider id,
|
|
66
|
+
* `minimax-cn` (the Anthropic-compatible endpoint), with `contextWindow: 1000000`. The session runs
|
|
67
|
+
* on `minimax-cn`, so the exact-pair lookup finds nothing and the bogus number survives.
|
|
68
|
+
*
|
|
69
|
+
* When several providers declare the same model with DIFFERENT windows, the SMALLEST wins: a model
|
|
70
|
+
* can never really have more context than its own limit, and a window that is too large is exactly
|
|
71
|
+
* the failure this exists to prevent - it pushes compaction past the point where the model refuses.
|
|
72
|
+
*/
|
|
73
|
+
export declare function effectiveContextWindow(declared: Map<string, number>, provider: string, modelId: string, reported?: number): number | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Reads the person's `models.json` and returns its declared windows.
|
|
76
|
+
*
|
|
77
|
+
* A missing or unreadable file is an empty map, not a throw: Super Pi must not refuse to start
|
|
78
|
+
* because a person has not configured a custom provider, and the consequence of an empty map is
|
|
79
|
+
* simply "Super Pi has no opinion about this model's window" - which is where it started.
|
|
80
|
+
*/
|
|
81
|
+
export declare function readDeclaredWindows(agentDir: string): Map<string, number>;
|
|
82
|
+
/** The windows the catalogue (`models-store.json`) declares, keyed the same way as `declared`. */
|
|
83
|
+
export declare function storeWindows(store: ModelStore): Map<string, number>;
|
|
84
|
+
/**
|
|
85
|
+
* Read the catalogue's declared windows, alongside the person's.
|
|
86
|
+
*
|
|
87
|
+
* The catalogue is the truth the provider self-reports; it is re-read only when the file changes.
|
|
88
|
+
*/
|
|
89
|
+
export declare function readStoreWindows(agentDir: string): ModelStore;
|
|
90
|
+
/**
|
|
91
|
+
* THE WINDOW A MODEL REALLY GETS, arbitrated across the three sources that each claim to know it.
|
|
92
|
+
*
|
|
93
|
+
* PRECEDENCE, HIGHEST FIRST:
|
|
94
|
+
*
|
|
95
|
+
* 1. A NON-DEFAULT value in the person's `models.json` — somebody typed it, so it is a decision.
|
|
96
|
+
* (This is the original rule, unchanged.)
|
|
97
|
+
* 2. The CATALOGUE (`models-store.json`) — the provider's self-report. This is the truth for a
|
|
98
|
+
* model Super Pi only knows from its own default. `MiniMax-M3` is the case in point: the
|
|
99
|
+
* catalogue says 1,000,000 while every `models.json` entry Super Pi wrote says the default
|
|
100
|
+
* 128,000.
|
|
101
|
+
* 3. The `reported` value the model object already carries, then nothing (`undefined`).
|
|
102
|
+
*
|
|
103
|
+
* THE OLD "SAME MODEL TAKE THE SMALLEST" RULE IS GONE. It was written for a catalogue that lies
|
|
104
|
+
* big; on this machine the catalogue is right and the stamped default is what was too small, so
|
|
105
|
+
* taking the smallest is exactly how a million-token model ended up believing it had 128,000.
|
|
106
|
+
*/
|
|
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;
|
|
128
|
+
/**
|
|
129
|
+
* THE CATALOG'S WINDOWS, ARBITRATED THE WAY A SESSION'S ARE.
|
|
130
|
+
*
|
|
131
|
+
* WHY THE CATALOG NEEDS THIS AT ALL. There are two ways Super Pi can read the model list, and they
|
|
132
|
+
* do not agree: Pi's SDK hands over whole model objects (window included), while a spawned Pi in
|
|
133
|
+
* RPC mode answers with a reduced list that has no window on it at all. So the number the reader is
|
|
134
|
+
* shown depends on WHICH PATH the machine happened to take - and the path that drops it is the one
|
|
135
|
+
* this machine takes. A picker that silently omits the window is a picker that cannot answer the
|
|
136
|
+
* one question it exists to answer: can this model hold a long task?
|
|
137
|
+
*
|
|
138
|
+
* WHY THE SAME ARBITRATION. The number printed has to be the number the session will run on, or it
|
|
139
|
+
* is a decoration. The session's window is decided by `arbitrateContextWindow` over the person's
|
|
140
|
+
* file and the provider's catalogue, so the catalogue is arbitrated the same way - one rule, one
|
|
141
|
+
* answer, and the label a reader sees is the limit their session really has.
|
|
142
|
+
*
|
|
143
|
+
* A window of 0 means "this source did not say", not "this model has no window": it is passed on
|
|
144
|
+
* as absent so the arbitration can go on to the sources that do know.
|
|
145
|
+
*/
|
|
146
|
+
export declare function withArbitratedWindows<T extends {
|
|
147
|
+
provider: string;
|
|
148
|
+
modelId: string;
|
|
149
|
+
contextWindow: number;
|
|
150
|
+
maxTokens?: number;
|
|
151
|
+
}>(options: readonly T[], agentDir: string): T[];
|
|
152
|
+
/**
|
|
153
|
+
* THE RESOLVER A LIVE SESSION HANDS ITS MODEL THROUGH.
|
|
154
|
+
*
|
|
155
|
+
* WHY THIS IS A FUNCTION AND NOT A CLOSURE. The rule above is a pure function, and it has had a gate
|
|
156
|
+
* for a while - but the rule is only HALF of the runtime path. The other half is the code that reads
|
|
157
|
+
* the two files, asks the model runtime for the whole model object, and hands that object to Pi.
|
|
158
|
+
* That half lived inside `pi-session.ts` as an inline closure, where nothing could reach it: the pure
|
|
159
|
+
* function was tested, and the code that actually decides what window a session runs on was not.
|
|
160
|
+
*
|
|
161
|
+
* This is that code, extracted, so it can be driven with a temporary directory and a fake model
|
|
162
|
+
* runtime - no server, no socket, no browser, no model.
|
|
163
|
+
*
|
|
164
|
+
* WHAT IT DOES, IN ORDER:
|
|
165
|
+
*
|
|
166
|
+
* 1. Reads the person's `models.json` and the provider's catalogue `models-store.json`.
|
|
167
|
+
* 2. Asks the model runtime for the WHOLE model object for `(provider, modelId)`.
|
|
168
|
+
* 3. Arbitrates the window across the three sources.
|
|
169
|
+
* 4. Hands the WHOLE model back, carrying the arbitrated window.
|
|
170
|
+
*
|
|
171
|
+
* THE FILES ARE READ ONCE, WHEN THE RESOLVER IS CREATED - which is where the session used to read
|
|
172
|
+
* them. A live session therefore keeps the windows it started with, exactly as it did before, and a
|
|
173
|
+
* person editing `models.json` mid-turn does not silently change the window of a running session.
|
|
174
|
+
*/
|
|
175
|
+
export declare function createModelResolver(options: {
|
|
176
|
+
agentDir: string;
|
|
177
|
+
modelRuntime: {
|
|
178
|
+
getModel?: (provider: string, modelId: string) => unknown;
|
|
179
|
+
};
|
|
180
|
+
}): (provider: string, modelId: string) => ({
|
|
181
|
+
provider: string;
|
|
182
|
+
id: string;
|
|
183
|
+
contextWindow?: number;
|
|
184
|
+
maxTokens?: number;
|
|
185
|
+
[key: string]: unknown;
|
|
186
|
+
} | undefined);
|
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE CONTEXT WINDOW A MODEL REALLY HAS.
|
|
3
|
+
*
|
|
4
|
+
* Pi reads its model list from two places and one of them wins:
|
|
5
|
+
*
|
|
6
|
+
* - `~/.pi/agent/models.json` - the file a PERSON writes, or that Super Pi writes from its own
|
|
7
|
+
* registry. Its `contextWindow` is a deliberate statement about the model.
|
|
8
|
+
* - `~/.pi/agent/models-store.json` - the REMOTE CATALOGUE Pi fetches from the provider, with
|
|
9
|
+
* an etag and a timestamp. Its `contextWindow` is the PROVIDER'S SELF-REPORT.
|
|
10
|
+
*
|
|
11
|
+
* Pi's own merge lets the remote catalogue overwrite the person's file (`merged[index] = model`),
|
|
12
|
+
* so a provider that reports a generous window wins over the one the person configured.
|
|
13
|
+
*
|
|
14
|
+
* WHY THAT MATTERS, AND HOW IT BREAKS A SESSION:
|
|
15
|
+
*
|
|
16
|
+
* Pi's auto-compaction is `shouldCompact(contextTokens, contextWindow, settings)`, i.e.
|
|
17
|
+
* `contextTokens > contextWindow - reserveTokens`. With `reserveTokens = 16384` and a reported
|
|
18
|
+
* window of 1,000,000, compaction waits for 983,616 tokens. The real window of that model is
|
|
19
|
+
* 128,000. So the model refuses the request at 128K, and the OVERFLOW RECOVERY - which asks the
|
|
20
|
+
* SAME model to summarise the same too-long conversation - fails the same way. The session is
|
|
21
|
+
* then a session that cannot answer anything, and the reader sees a dead conversation.
|
|
22
|
+
*
|
|
23
|
+
* Measured on this machine: `models.json` says `MiniMax-M3` has `contextWindow: 128000`; the
|
|
24
|
+
* remote catalogue says `1000000`; Pi ends up believing 1,000,000.
|
|
25
|
+
*
|
|
26
|
+
* SO: THE PERSON'S FILE WINS. A number somebody typed is a decision; a number a catalogue fetched
|
|
27
|
+
* is a claim, and a claim that is too generous does not fail loudly - it fails by never compacting.
|
|
28
|
+
*
|
|
29
|
+
* This module is deliberately narrow: it reads the person's file, and it says what the model
|
|
30
|
+
* window SHOULD be. It does not touch Pi, does not decide anything else, and is a pure function of
|
|
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.
|
|
40
|
+
*/
|
|
41
|
+
import { readFileSync } from "node:fs";
|
|
42
|
+
import { join } from "node:path";
|
|
43
|
+
import { readModelStore, storeWindowFor } from "./models-store.js";
|
|
44
|
+
/**
|
|
45
|
+
* THE DEFAULTS SUPER PI STAMPS WHEN IT DISCOVERS A MODEL. `providers.ts` writes these into
|
|
46
|
+
* `models.json` for every model the provider did not describe, and they are NOT a person's decision
|
|
47
|
+
* - they are a placeholder. The store's real number must outrank them.
|
|
48
|
+
*/
|
|
49
|
+
export const SUPER_PI_DEFAULT_CONTEXT_WINDOW = 128000;
|
|
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;
|
|
60
|
+
/**
|
|
61
|
+
* The windows the person's `models.json` declares, keyed by `provider/modelId`.
|
|
62
|
+
*
|
|
63
|
+
* Pi's file shape is `{ providers: { <providerId>: { models: [{ id, contextWindow, ... }] } } }`,
|
|
64
|
+
* and a model without a `contextWindow` is simply not declared - it does not become a zero, because
|
|
65
|
+
* a zero would be a claim ("this model has no window") rather than an absence.
|
|
66
|
+
*/
|
|
67
|
+
export function declaredWindows(modelsJson) {
|
|
68
|
+
const out = new Map();
|
|
69
|
+
if (!modelsJson || typeof modelsJson !== "object")
|
|
70
|
+
return out;
|
|
71
|
+
const providers = modelsJson.providers;
|
|
72
|
+
if (!providers || typeof providers !== "object")
|
|
73
|
+
return out;
|
|
74
|
+
for (const [providerId, provider] of Object.entries(providers)) {
|
|
75
|
+
if (!provider || typeof provider !== "object")
|
|
76
|
+
continue;
|
|
77
|
+
const models = provider.models;
|
|
78
|
+
if (!Array.isArray(models))
|
|
79
|
+
continue;
|
|
80
|
+
for (const model of models) {
|
|
81
|
+
if (!model || typeof model !== "object")
|
|
82
|
+
continue;
|
|
83
|
+
const id = model.id;
|
|
84
|
+
const window = model.contextWindow;
|
|
85
|
+
if (typeof id !== "string" || !id.trim())
|
|
86
|
+
continue;
|
|
87
|
+
if (typeof window !== "number" || !Number.isSafeInteger(window) || window <= 0)
|
|
88
|
+
continue;
|
|
89
|
+
out.set(`${providerId}/${id}`, window);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return out;
|
|
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
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The window to USE for a model, given what the person's file says.
|
|
148
|
+
*
|
|
149
|
+
* `undefined` means "say nothing" - the caller keeps whatever Pi believes. That is the honest
|
|
150
|
+
* answer for a model the person's file does not mention: Super Pi has no opinion about a model
|
|
151
|
+
* somebody else configured, and inventing one would be the same mistake in the other direction.
|
|
152
|
+
*
|
|
153
|
+
* TWO LOOKUPS, AND THE SECOND ONE IS THE ONE THAT MATTERS:
|
|
154
|
+
*
|
|
155
|
+
* 1. `provider/modelId` - the exact pair. This is the common case.
|
|
156
|
+
* 2. `modelId` ALONE, across every provider the person's file declares.
|
|
157
|
+
*
|
|
158
|
+
* The second lookup exists because a CONTEXT WINDOW IS A PROPERTY OF THE MODEL, NOT OF THE
|
|
159
|
+
* ENDPOINT. Measured on this machine: the person's `models.json` declares the model `MiniMax-M3`
|
|
160
|
+
* under the provider id `minimax` (the OpenAI-compatible endpoint) with `contextWindow: 128000`,
|
|
161
|
+
* while Pi's remote catalogue declares the SAME model under a DIFFERENT provider id,
|
|
162
|
+
* `minimax-cn` (the Anthropic-compatible endpoint), with `contextWindow: 1000000`. The session runs
|
|
163
|
+
* on `minimax-cn`, so the exact-pair lookup finds nothing and the bogus number survives.
|
|
164
|
+
*
|
|
165
|
+
* When several providers declare the same model with DIFFERENT windows, the SMALLEST wins: a model
|
|
166
|
+
* can never really have more context than its own limit, and a window that is too large is exactly
|
|
167
|
+
* the failure this exists to prevent - it pushes compaction past the point where the model refuses.
|
|
168
|
+
*/
|
|
169
|
+
export function effectiveContextWindow(declared, provider, modelId, reported) {
|
|
170
|
+
const exact = declared.get(`${provider}/${modelId}`);
|
|
171
|
+
if (exact !== undefined)
|
|
172
|
+
return exact;
|
|
173
|
+
let smallest;
|
|
174
|
+
for (const [key, window] of declared) {
|
|
175
|
+
const slash = key.indexOf("/");
|
|
176
|
+
if (slash < 0 || key.slice(slash + 1) !== modelId)
|
|
177
|
+
continue;
|
|
178
|
+
if (smallest === undefined || window < smallest)
|
|
179
|
+
smallest = window;
|
|
180
|
+
}
|
|
181
|
+
return smallest;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Reads the person's `models.json` and returns its declared windows.
|
|
185
|
+
*
|
|
186
|
+
* A missing or unreadable file is an empty map, not a throw: Super Pi must not refuse to start
|
|
187
|
+
* because a person has not configured a custom provider, and the consequence of an empty map is
|
|
188
|
+
* simply "Super Pi has no opinion about this model's window" - which is where it started.
|
|
189
|
+
*/
|
|
190
|
+
export function readDeclaredWindows(agentDir) {
|
|
191
|
+
try {
|
|
192
|
+
const raw = readFileSync(join(agentDir, "models.json"), "utf8");
|
|
193
|
+
return declaredWindows(JSON.parse(raw));
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return new Map();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/** The windows the catalogue (`models-store.json`) declares, keyed the same way as `declared`. */
|
|
200
|
+
export function storeWindows(store) {
|
|
201
|
+
const out = new Map();
|
|
202
|
+
for (const [key, entry] of store.byProviderModel) {
|
|
203
|
+
if (entry.contextWindow !== undefined)
|
|
204
|
+
out.set(key, entry.contextWindow);
|
|
205
|
+
}
|
|
206
|
+
return out;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Read the catalogue's declared windows, alongside the person's.
|
|
210
|
+
*
|
|
211
|
+
* The catalogue is the truth the provider self-reports; it is re-read only when the file changes.
|
|
212
|
+
*/
|
|
213
|
+
export function readStoreWindows(agentDir) {
|
|
214
|
+
return readModelStore(agentDir);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Is a `models.json` window a PERSON's decision, or just Super Pi's own default stamped at import?
|
|
218
|
+
*
|
|
219
|
+
* Only a number somebody actually typed is authoritative. The value Super Pi writes when the
|
|
220
|
+
* provider said nothing (128000 / 16384) is a placeholder, and a placeholder never outranks the
|
|
221
|
+
* catalogue's real figure.
|
|
222
|
+
*/
|
|
223
|
+
function isDeliberateWindow(window) {
|
|
224
|
+
return window !== undefined && window !== SUPER_PI_DEFAULT_CONTEXT_WINDOW;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* THE WINDOW A MODEL REALLY GETS, arbitrated across the three sources that each claim to know it.
|
|
228
|
+
*
|
|
229
|
+
* PRECEDENCE, HIGHEST FIRST:
|
|
230
|
+
*
|
|
231
|
+
* 1. A NON-DEFAULT value in the person's `models.json` — somebody typed it, so it is a decision.
|
|
232
|
+
* (This is the original rule, unchanged.)
|
|
233
|
+
* 2. The CATALOGUE (`models-store.json`) — the provider's self-report. This is the truth for a
|
|
234
|
+
* model Super Pi only knows from its own default. `MiniMax-M3` is the case in point: the
|
|
235
|
+
* catalogue says 1,000,000 while every `models.json` entry Super Pi wrote says the default
|
|
236
|
+
* 128,000.
|
|
237
|
+
* 3. The `reported` value the model object already carries, then nothing (`undefined`).
|
|
238
|
+
*
|
|
239
|
+
* THE OLD "SAME MODEL TAKE THE SMALLEST" RULE IS GONE. It was written for a catalogue that lies
|
|
240
|
+
* big; on this machine the catalogue is right and the stamped default is what was too small, so
|
|
241
|
+
* taking the smallest is exactly how a million-token model ended up believing it had 128,000.
|
|
242
|
+
*/
|
|
243
|
+
export function arbitrateContextWindow(declared, store, provider, modelId, reported) {
|
|
244
|
+
const exact = declared.get(`${provider}/${modelId}`);
|
|
245
|
+
if (isDeliberateWindow(exact))
|
|
246
|
+
return exact;
|
|
247
|
+
// A deliberate cross-provider declaration still wins over the catalogue.
|
|
248
|
+
let deliberate;
|
|
249
|
+
for (const [key, window] of declared) {
|
|
250
|
+
const slash = key.indexOf("/");
|
|
251
|
+
if (slash < 0 || key.slice(slash + 1) !== modelId)
|
|
252
|
+
continue;
|
|
253
|
+
if (!isDeliberateWindow(window))
|
|
254
|
+
continue;
|
|
255
|
+
if (deliberate === undefined || window > deliberate)
|
|
256
|
+
deliberate = window;
|
|
257
|
+
}
|
|
258
|
+
if (deliberate !== undefined)
|
|
259
|
+
return deliberate;
|
|
260
|
+
const storeEntry = storeWindowFor(store, modelId, provider);
|
|
261
|
+
if (storeEntry?.contextWindow !== undefined)
|
|
262
|
+
return storeEntry.contextWindow;
|
|
263
|
+
if (isDeliberateWindow(reported))
|
|
264
|
+
return reported;
|
|
265
|
+
return exact ?? deliberate ?? storeEntry?.contextWindow ?? reported;
|
|
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
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* THE CATALOG'S WINDOWS, ARBITRATED THE WAY A SESSION'S ARE.
|
|
354
|
+
*
|
|
355
|
+
* WHY THE CATALOG NEEDS THIS AT ALL. There are two ways Super Pi can read the model list, and they
|
|
356
|
+
* do not agree: Pi's SDK hands over whole model objects (window included), while a spawned Pi in
|
|
357
|
+
* RPC mode answers with a reduced list that has no window on it at all. So the number the reader is
|
|
358
|
+
* shown depends on WHICH PATH the machine happened to take - and the path that drops it is the one
|
|
359
|
+
* this machine takes. A picker that silently omits the window is a picker that cannot answer the
|
|
360
|
+
* one question it exists to answer: can this model hold a long task?
|
|
361
|
+
*
|
|
362
|
+
* WHY THE SAME ARBITRATION. The number printed has to be the number the session will run on, or it
|
|
363
|
+
* is a decoration. The session's window is decided by `arbitrateContextWindow` over the person's
|
|
364
|
+
* file and the provider's catalogue, so the catalogue is arbitrated the same way - one rule, one
|
|
365
|
+
* answer, and the label a reader sees is the limit their session really has.
|
|
366
|
+
*
|
|
367
|
+
* A window of 0 means "this source did not say", not "this model has no window": it is passed on
|
|
368
|
+
* as absent so the arbitration can go on to the sources that do know.
|
|
369
|
+
*/
|
|
370
|
+
export function withArbitratedWindows(options, agentDir) {
|
|
371
|
+
if (!options.length)
|
|
372
|
+
return [];
|
|
373
|
+
const declared = readDeclaredWindows(agentDir);
|
|
374
|
+
const declaredLimits = readDeclaredMaxTokens(agentDir);
|
|
375
|
+
const catalogue = readStoreWindows(agentDir);
|
|
376
|
+
return options.map((option) => {
|
|
377
|
+
const reported = typeof option.contextWindow === "number" && option.contextWindow > 0 ? option.contextWindow : undefined;
|
|
378
|
+
const window = arbitrateContextWindow(declared, catalogue, option.provider, option.modelId, reported);
|
|
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)
|
|
388
|
+
return option;
|
|
389
|
+
return {
|
|
390
|
+
...option,
|
|
391
|
+
...(windowChanged ? { contextWindow: window } : {}),
|
|
392
|
+
...(limitChanged ? { maxTokens } : {}),
|
|
393
|
+
};
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* THE RESOLVER A LIVE SESSION HANDS ITS MODEL THROUGH.
|
|
398
|
+
*
|
|
399
|
+
* WHY THIS IS A FUNCTION AND NOT A CLOSURE. The rule above is a pure function, and it has had a gate
|
|
400
|
+
* for a while - but the rule is only HALF of the runtime path. The other half is the code that reads
|
|
401
|
+
* the two files, asks the model runtime for the whole model object, and hands that object to Pi.
|
|
402
|
+
* That half lived inside `pi-session.ts` as an inline closure, where nothing could reach it: the pure
|
|
403
|
+
* function was tested, and the code that actually decides what window a session runs on was not.
|
|
404
|
+
*
|
|
405
|
+
* This is that code, extracted, so it can be driven with a temporary directory and a fake model
|
|
406
|
+
* runtime - no server, no socket, no browser, no model.
|
|
407
|
+
*
|
|
408
|
+
* WHAT IT DOES, IN ORDER:
|
|
409
|
+
*
|
|
410
|
+
* 1. Reads the person's `models.json` and the provider's catalogue `models-store.json`.
|
|
411
|
+
* 2. Asks the model runtime for the WHOLE model object for `(provider, modelId)`.
|
|
412
|
+
* 3. Arbitrates the window across the three sources.
|
|
413
|
+
* 4. Hands the WHOLE model back, carrying the arbitrated window.
|
|
414
|
+
*
|
|
415
|
+
* THE FILES ARE READ ONCE, WHEN THE RESOLVER IS CREATED - which is where the session used to read
|
|
416
|
+
* them. A live session therefore keeps the windows it started with, exactly as it did before, and a
|
|
417
|
+
* person editing `models.json` mid-turn does not silently change the window of a running session.
|
|
418
|
+
*/
|
|
419
|
+
export function createModelResolver(options) {
|
|
420
|
+
const declared = readDeclaredWindows(options.agentDir);
|
|
421
|
+
const declaredLimits = readDeclaredMaxTokens(options.agentDir);
|
|
422
|
+
const catalogue = readStoreWindows(options.agentDir);
|
|
423
|
+
return (provider, modelId) => {
|
|
424
|
+
const found = options.modelRuntime.getModel?.(provider, modelId);
|
|
425
|
+
if (!found || typeof found !== "object")
|
|
426
|
+
return undefined;
|
|
427
|
+
const model = found;
|
|
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);
|
|
433
|
+
// The model is handed to Pi WHOLE - it is what the agent runs on - so this is where the
|
|
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
|
+
};
|
|
443
|
+
};
|
|
444
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AppState, ModelFilterRule, ModelSelection, Workspace } from "./types.js";
|
|
2
|
+
export declare function applicableRules(rules: ModelFilterRule[] | undefined, workspace: Workspace): {
|
|
3
|
+
rule: ModelFilterRule;
|
|
4
|
+
modelRegex: RegExp;
|
|
5
|
+
}[];
|
|
6
|
+
export declare function assertModelAllowed(rules: ModelFilterRule[] | undefined, workspace: Workspace, model: ModelSelection | undefined): void;
|
|
7
|
+
export declare function conversationWorkspace(state: AppState, conversationId: string): Workspace;
|
|
8
|
+
/** Resolve Pi's actual global default when no model was selected; never guess a permitted replacement. */
|
|
9
|
+
/**
|
|
10
|
+
* THE STORE READS THIS NEEDS, AND NOTHING ELSE.
|
|
11
|
+
*
|
|
12
|
+
* The check wants two things: the rules, and the workspace the conversation is in. Both now have a
|
|
13
|
+
* narrow reader on the store (`modelFilterRules()` / `workspaceForConversation()`), so this path
|
|
14
|
+
* clones NOTHING - it used to deep-clone the whole application three times over, on the way to
|
|
15
|
+
* sending a message.
|
|
16
|
+
*/
|
|
17
|
+
export interface ModelFilterStore {
|
|
18
|
+
modelFilterRules(): import("./types.js").ModelFilterRule[];
|
|
19
|
+
workspaceForConversation(conversationId: string): Workspace | undefined;
|
|
20
|
+
}
|
|
21
|
+
export declare function validateConversationModel(store: ModelFilterStore, runtime: {
|
|
22
|
+
catalog(selection?: ModelSelection): Promise<import("./types.js").ModelCatalog>;
|
|
23
|
+
}, conversationId: string, selection?: ModelSelection): Promise<void>;
|