@waq666/pneuma 0.0.0-stage → 0.7.0
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/LICENSE +21 -0
- package/README.md +144 -2
- package/bin/dsc.js +91 -0
- package/bin/headless.cjs +40 -0
- package/lib/adapter/core-runtime.d.ts +11 -0
- package/lib/adapter/core-runtime.js +259 -0
- package/lib/adapter/host.d.ts +18 -0
- package/lib/adapter/host.js +14 -0
- package/lib/adapter/runtime.d.ts +15 -0
- package/lib/adapter/runtime.js +290 -0
- package/lib/adapter/transcript.d.ts +184 -0
- package/lib/adapter/transcript.js +605 -0
- package/lib/app/AgentsOverlay.d.ts +18 -0
- package/lib/app/AgentsOverlay.js +63 -0
- package/lib/app/App.d.ts +13 -0
- package/lib/app/App.js +1498 -0
- package/lib/app/ApprovalCard.d.ts +12 -0
- package/lib/app/ApprovalCard.js +76 -0
- package/lib/app/AskCard.d.ts +20 -0
- package/lib/app/AskCard.js +45 -0
- package/lib/app/ChatView.d.ts +32 -0
- package/lib/app/ChatView.js +198 -0
- package/lib/app/Composer.d.ts +50 -0
- package/lib/app/Composer.js +282 -0
- package/lib/app/DiffBlock.d.ts +6 -0
- package/lib/app/DiffBlock.js +37 -0
- package/lib/app/MarkdownView.d.ts +6 -0
- package/lib/app/MarkdownView.js +99 -0
- package/lib/app/ModelPicker.d.ts +7 -0
- package/lib/app/ModelPicker.js +18 -0
- package/lib/app/PlanReviewCard.d.ts +13 -0
- package/lib/app/PlanReviewCard.js +54 -0
- package/lib/app/PresetPicker.d.ts +11 -0
- package/lib/app/PresetPicker.js +19 -0
- package/lib/app/PreviewOverlay.d.ts +14 -0
- package/lib/app/PreviewOverlay.js +22 -0
- package/lib/app/SessionPicker.d.ts +43 -0
- package/lib/app/SessionPicker.js +56 -0
- package/lib/app/SettingsOverlay.d.ts +32 -0
- package/lib/app/SettingsOverlay.js +157 -0
- package/lib/app/SkillsPicker.d.ts +7 -0
- package/lib/app/SkillsPicker.js +19 -0
- package/lib/app/StatusBar.d.ts +22 -0
- package/lib/app/StatusBar.js +272 -0
- package/lib/app/TaskStrips.d.ts +13 -0
- package/lib/app/TaskStrips.js +40 -0
- package/lib/app/ToolCard.d.ts +5 -0
- package/lib/app/ToolCard.js +40 -0
- package/lib/app/TranscriptOverlay.d.ts +12 -0
- package/lib/app/TranscriptOverlay.js +17 -0
- package/lib/app/Welcome.d.ts +6 -0
- package/lib/app/Welcome.js +66 -0
- package/lib/app/attach.d.ts +16 -0
- package/lib/app/attach.js +58 -0
- package/lib/app/click.d.ts +27 -0
- package/lib/app/click.js +89 -0
- package/lib/app/clipboard-image.d.ts +11 -0
- package/lib/app/clipboard-image.js +66 -0
- package/lib/app/cursor.d.ts +4 -0
- package/lib/app/cursor.js +24 -0
- package/lib/app/hello.d.ts +11 -0
- package/lib/app/hello.js +8 -0
- package/lib/app/history-store.d.ts +4 -0
- package/lib/app/history-store.js +41 -0
- package/lib/app/image-blocks.d.ts +12 -0
- package/lib/app/image-blocks.js +125 -0
- package/lib/app/markdown.d.ts +54 -0
- package/lib/app/markdown.js +189 -0
- package/lib/app/settings-model.d.ts +69 -0
- package/lib/app/settings-model.js +114 -0
- package/lib/app/theme.d.ts +166 -0
- package/lib/app/theme.js +141 -0
- package/lib/boot.d.ts +1 -0
- package/lib/boot.js +34 -0
- package/lib/commands.d.ts +49 -0
- package/lib/commands.js +115 -0
- package/lib/contract.d.ts +1973 -0
- package/lib/contract.js +36 -0
- package/lib/core/agent-roles.d.ts +52 -0
- package/lib/core/agent-roles.js +274 -0
- package/lib/core/approval-floor.d.ts +183 -0
- package/lib/core/approval-floor.js +679 -0
- package/lib/core/approval.d.ts +42 -0
- package/lib/core/approval.js +8 -0
- package/lib/core/audit.d.ts +61 -0
- package/lib/core/audit.js +59 -0
- package/lib/core/boot-notices.d.ts +6 -0
- package/lib/core/boot-notices.js +61 -0
- package/lib/core/cdp/actions.d.ts +182 -0
- package/lib/core/cdp/actions.js +649 -0
- package/lib/core/cdp/launch.d.ts +192 -0
- package/lib/core/cdp/launch.js +491 -0
- package/lib/core/cdp/snapshot.d.ts +139 -0
- package/lib/core/cdp/snapshot.js +316 -0
- package/lib/core/cdp/transport.d.ts +160 -0
- package/lib/core/cdp/transport.js +359 -0
- package/lib/core/command-policy.d.ts +108 -0
- package/lib/core/command-policy.js +580 -0
- package/lib/core/commands-completion.d.ts +78 -0
- package/lib/core/commands-completion.js +167 -0
- package/lib/core/compact-anchors.d.ts +76 -0
- package/lib/core/compact-anchors.js +284 -0
- package/lib/core/compact.d.ts +110 -0
- package/lib/core/compact.js +210 -0
- package/lib/core/config-store.d.ts +38 -0
- package/lib/core/config-store.js +307 -0
- package/lib/core/config.d.ts +36 -0
- package/lib/core/config.js +124 -0
- package/lib/core/connection-test.d.ts +60 -0
- package/lib/core/connection-test.js +84 -0
- package/lib/core/desktop-control.d.ts +298 -0
- package/lib/core/desktop-control.js +1311 -0
- package/lib/core/diff-text.d.ts +74 -0
- package/lib/core/diff-text.js +257 -0
- package/lib/core/dock-browser.d.ts +137 -0
- package/lib/core/dock-browser.js +146 -0
- package/lib/core/dock-ops.d.ts +59 -0
- package/lib/core/dock-ops.js +104 -0
- package/lib/core/dock-session.d.ts +39 -0
- package/lib/core/dock-session.js +28 -0
- package/lib/core/dsh-compat/hook.d.ts +18 -0
- package/lib/core/dsh-compat/hook.js +52 -0
- package/lib/core/dsh-compat/resolve-hook.d.ts +5 -0
- package/lib/core/dsh-compat/resolve-hook.js +59 -0
- package/lib/core/dsh-compat/tools-facade.d.ts +47 -0
- package/lib/core/dsh-compat/tools-facade.js +108 -0
- package/lib/core/err-text.d.ts +13 -0
- package/lib/core/err-text.js +15 -0
- package/lib/core/events.d.ts +149 -0
- package/lib/core/events.js +1 -0
- package/lib/core/git-exec.d.ts +23 -0
- package/lib/core/git-exec.js +72 -0
- package/lib/core/git-info.d.ts +47 -0
- package/lib/core/git-info.js +157 -0
- package/lib/core/goal.d.ts +89 -0
- package/lib/core/goal.js +189 -0
- package/lib/core/hooks.d.ts +272 -0
- package/lib/core/hooks.js +818 -0
- package/lib/core/host-browser-link.d.ts +59 -0
- package/lib/core/host-browser-link.js +9 -0
- package/lib/core/host-methods.d.ts +25 -0
- package/lib/core/host-methods.js +103 -0
- package/lib/core/image-diet.d.ts +77 -0
- package/lib/core/image-diet.js +127 -0
- package/lib/core/learnings/ledger.d.ts +73 -0
- package/lib/core/learnings/ledger.js +273 -0
- package/lib/core/learnings/skill-write.d.ts +250 -0
- package/lib/core/learnings/skill-write.js +854 -0
- package/lib/core/learnings/store.d.ts +102 -0
- package/lib/core/learnings/store.js +266 -0
- package/lib/core/lifecycle-hooks.d.ts +189 -0
- package/lib/core/lifecycle-hooks.js +576 -0
- package/lib/core/llm.d.ts +272 -0
- package/lib/core/llm.js +548 -0
- package/lib/core/lockfile.d.ts +17 -0
- package/lib/core/lockfile.js +110 -0
- package/lib/core/loop.d.ts +185 -0
- package/lib/core/loop.js +587 -0
- package/lib/core/lsp/client.d.ts +189 -0
- package/lib/core/lsp/client.js +690 -0
- package/lib/core/lsp/framing.d.ts +84 -0
- package/lib/core/lsp/framing.js +181 -0
- package/lib/core/lsp/line-shift.d.ts +28 -0
- package/lib/core/lsp/line-shift.js +127 -0
- package/lib/core/lsp/manager.d.ts +93 -0
- package/lib/core/lsp/manager.js +418 -0
- package/lib/core/lsp/normalize.d.ts +32 -0
- package/lib/core/lsp/normalize.js +139 -0
- package/lib/core/lsp/servers.d.ts +106 -0
- package/lib/core/lsp/servers.js +352 -0
- package/lib/core/lsp/uri.d.ts +76 -0
- package/lib/core/lsp/uri.js +179 -0
- package/lib/core/market.d.ts +51 -0
- package/lib/core/market.js +358 -0
- package/lib/core/mcp.d.ts +201 -0
- package/lib/core/mcp.js +836 -0
- package/lib/core/memory-eval.d.ts +158 -0
- package/lib/core/memory-eval.js +215 -0
- package/lib/core/memory.d.ts +266 -0
- package/lib/core/memory.js +703 -0
- package/lib/core/mention.d.ts +57 -0
- package/lib/core/mention.js +129 -0
- package/lib/core/microcompact.d.ts +48 -0
- package/lib/core/microcompact.js +79 -0
- package/lib/core/migrate.d.ts +56 -0
- package/lib/core/migrate.js +134 -0
- package/lib/core/model-caps.d.ts +83 -0
- package/lib/core/model-caps.js +150 -0
- package/lib/core/model-discovery.d.ts +19 -0
- package/lib/core/model-discovery.js +69 -0
- package/lib/core/modes.d.ts +72 -0
- package/lib/core/modes.js +152 -0
- package/lib/core/native-bridge.d.ts +135 -0
- package/lib/core/native-bridge.js +563 -0
- package/lib/core/path-policy.d.ts +32 -0
- package/lib/core/path-policy.js +248 -0
- package/lib/core/permission-presets.d.ts +67 -0
- package/lib/core/permission-presets.js +75 -0
- package/lib/core/plugin-loader.d.ts +36 -0
- package/lib/core/plugin-loader.js +294 -0
- package/lib/core/plugin-registry.d.ts +113 -0
- package/lib/core/plugin-registry.js +256 -0
- package/lib/core/prefs.d.ts +82 -0
- package/lib/core/prefs.js +372 -0
- package/lib/core/presets.d.ts +80 -0
- package/lib/core/presets.js +373 -0
- package/lib/core/pricing.d.ts +90 -0
- package/lib/core/pricing.js +126 -0
- package/lib/core/prompt.d.ts +92 -0
- package/lib/core/prompt.js +339 -0
- package/lib/core/ptc.d.ts +66 -0
- package/lib/core/ptc.js +70 -0
- package/lib/core/remote/frames.d.ts +91 -0
- package/lib/core/remote/frames.js +174 -0
- package/lib/core/remote/notify.d.ts +54 -0
- package/lib/core/remote/notify.js +77 -0
- package/lib/core/remote/owner.d.ts +32 -0
- package/lib/core/remote/owner.js +75 -0
- package/lib/core/remote/pairing.d.ts +104 -0
- package/lib/core/remote/pairing.js +261 -0
- package/lib/core/remote/push.d.ts +80 -0
- package/lib/core/remote/push.js +222 -0
- package/lib/core/remote/store.d.ts +18 -0
- package/lib/core/remote/store.js +59 -0
- package/lib/core/remote/tickets.d.ts +20 -0
- package/lib/core/remote/tickets.js +49 -0
- package/lib/core/remote/uploads.d.ts +63 -0
- package/lib/core/remote/uploads.js +161 -0
- package/lib/core/request-attribution.d.ts +26 -0
- package/lib/core/request-attribution.js +86 -0
- package/lib/core/request-invariant.d.ts +61 -0
- package/lib/core/request-invariant.js +199 -0
- package/lib/core/sandbox/backends.d.ts +64 -0
- package/lib/core/sandbox/backends.js +194 -0
- package/lib/core/sandbox/execpolicy.d.ts +93 -0
- package/lib/core/sandbox/execpolicy.js +452 -0
- package/lib/core/sandbox/net-proxy.d.ts +31 -0
- package/lib/core/sandbox/net-proxy.js +162 -0
- package/lib/core/sandbox/policy.d.ts +211 -0
- package/lib/core/sandbox/policy.js +559 -0
- package/lib/core/sandbox/win/abi.d.ts +161 -0
- package/lib/core/sandbox/win/abi.js +169 -0
- package/lib/core/sandbox/win/account.d.ts +71 -0
- package/lib/core/sandbox/win/account.js +206 -0
- package/lib/core/sandbox/win/acl.d.ts +54 -0
- package/lib/core/sandbox/win/acl.js +339 -0
- package/lib/core/sandbox/win/backend.d.ts +61 -0
- package/lib/core/sandbox/win/backend.js +249 -0
- package/lib/core/sandbox/win/doctor.d.ts +24 -0
- package/lib/core/sandbox/win/doctor.js +272 -0
- package/lib/core/sandbox/win/ffi.d.ts +107 -0
- package/lib/core/sandbox/win/ffi.js +166 -0
- package/lib/core/sandbox/win/net-abi.d.ts +154 -0
- package/lib/core/sandbox/win/net-abi.js +316 -0
- package/lib/core/sandbox/win/runner-entry.d.ts +35 -0
- package/lib/core/sandbox/win/runner-entry.js +391 -0
- package/lib/core/sandbox/win/setup.d.ts +60 -0
- package/lib/core/sandbox/win/setup.js +986 -0
- package/lib/core/sandbox/win/token.d.ts +35 -0
- package/lib/core/sandbox/win/token.js +238 -0
- package/lib/core/sandbox/win/wfp.d.ts +41 -0
- package/lib/core/sandbox/win/wfp.js +200 -0
- package/lib/core/sandbox/win/workspace-sid.d.ts +9 -0
- package/lib/core/sandbox/win/workspace-sid.js +45 -0
- package/lib/core/schedule/rule.d.ts +184 -0
- package/lib/core/schedule/rule.js +745 -0
- package/lib/core/schedule/runner.d.ts +185 -0
- package/lib/core/schedule/runner.js +678 -0
- package/lib/core/schedule/store.d.ts +182 -0
- package/lib/core/schedule/store.js +455 -0
- package/lib/core/secrets.d.ts +41 -0
- package/lib/core/secrets.js +150 -0
- package/lib/core/session-export.d.ts +18 -0
- package/lib/core/session-export.js +73 -0
- package/lib/core/session-index.d.ts +159 -0
- package/lib/core/session-index.js +683 -0
- package/lib/core/session-meta.d.ts +41 -0
- package/lib/core/session-meta.js +97 -0
- package/lib/core/session.d.ts +356 -0
- package/lib/core/session.js +998 -0
- package/lib/core/skills.d.ts +60 -0
- package/lib/core/skills.js +171 -0
- package/lib/core/spill.d.ts +159 -0
- package/lib/core/spill.js +329 -0
- package/lib/core/surface-registry.d.ts +45 -0
- package/lib/core/surface-registry.js +67 -0
- package/lib/core/team-board.d.ts +95 -0
- package/lib/core/team-board.js +316 -0
- package/lib/core/throughput.d.ts +46 -0
- package/lib/core/throughput.js +40 -0
- package/lib/core/todo-reminder.d.ts +44 -0
- package/lib/core/todo-reminder.js +55 -0
- package/lib/core/todo.d.ts +81 -0
- package/lib/core/todo.js +222 -0
- package/lib/core/token-estimate.d.ts +55 -0
- package/lib/core/token-estimate.js +82 -0
- package/lib/core/tool-guards.d.ts +103 -0
- package/lib/core/tool-guards.js +77 -0
- package/lib/core/tool-search.d.ts +152 -0
- package/lib/core/tool-search.js +311 -0
- package/lib/core/tools/bash.d.ts +281 -0
- package/lib/core/tools/bash.js +871 -0
- package/lib/core/tools/command-runner.d.ts +84 -0
- package/lib/core/tools/command-runner.js +68 -0
- package/lib/core/tools/fs-tools.d.ts +23 -0
- package/lib/core/tools/fs-tools.js +247 -0
- package/lib/core/tools/index.d.ts +8 -0
- package/lib/core/tools/index.js +4 -0
- package/lib/core/tools/sandbox-args.d.ts +51 -0
- package/lib/core/tools/sandbox-args.js +90 -0
- package/lib/core/tools/search-tools.d.ts +3 -0
- package/lib/core/tools/search-tools.js +153 -0
- package/lib/core/tools.d.ts +96 -0
- package/lib/core/tools.js +53 -0
- package/lib/core/ui-boot-source.d.ts +71 -0
- package/lib/core/ui-boot-source.js +121 -0
- package/lib/core/ui-bundles.d.ts +249 -0
- package/lib/core/ui-bundles.js +830 -0
- package/lib/core/ui-combo.d.ts +49 -0
- package/lib/core/ui-combo.js +55 -0
- package/lib/core/ui-events.d.ts +81 -0
- package/lib/core/ui-events.js +364 -0
- package/lib/core/ui-hmr.d.ts +36 -0
- package/lib/core/ui-hmr.js +128 -0
- package/lib/core/ui-methods.d.ts +69 -0
- package/lib/core/ui-methods.js +341 -0
- package/lib/core/ui-route.d.ts +69 -0
- package/lib/core/ui-route.js +122 -0
- package/lib/core/ui-server.d.ts +75 -0
- package/lib/core/ui-server.js +369 -0
- package/lib/core/ui-trust.d.ts +47 -0
- package/lib/core/ui-trust.js +164 -0
- package/lib/core/untrusted.d.ts +30 -0
- package/lib/core/untrusted.js +48 -0
- package/lib/core/update-check.d.ts +81 -0
- package/lib/core/update-check.js +177 -0
- package/lib/core/usage-log.d.ts +82 -0
- package/lib/core/usage-log.js +306 -0
- package/lib/core/version.d.ts +1 -0
- package/lib/core/version.js +37 -0
- package/lib/core/web-http.d.ts +57 -0
- package/lib/core/web-http.js +137 -0
- package/lib/core/web-static.d.ts +31 -0
- package/lib/core/web-static.js +75 -0
- package/lib/headless.d.ts +1 -0
- package/lib/headless.js +31 -0
- package/lib/host/kernel.d.ts +33 -0
- package/lib/host/kernel.js +451 -0
- package/lib/index.d.ts +41 -0
- package/lib/index.js +35 -0
- package/lib/plugins/agent.d.ts +2 -0
- package/lib/plugins/agent.js +274 -0
- package/lib/plugins/approval-floor.d.ts +2 -0
- package/lib/plugins/approval-floor.js +223 -0
- package/lib/plugins/approval.d.ts +16 -0
- package/lib/plugins/approval.js +674 -0
- package/lib/plugins/ask.d.ts +2 -0
- package/lib/plugins/ask.js +245 -0
- package/lib/plugins/browser.d.ts +68 -0
- package/lib/plugins/browser.js +1341 -0
- package/lib/plugins/commands.d.ts +23 -0
- package/lib/plugins/commands.js +498 -0
- package/lib/plugins/compact.d.ts +21 -0
- package/lib/plugins/compact.js +274 -0
- package/lib/plugins/computer-use.d.ts +47 -0
- package/lib/plugins/computer-use.js +539 -0
- package/lib/plugins/desktop-dock.d.ts +2 -0
- package/lib/plugins/desktop-dock.js +626 -0
- package/lib/plugins/dock-browser.d.ts +34 -0
- package/lib/plugins/dock-browser.js +765 -0
- package/lib/plugins/dsh-compat.d.ts +25 -0
- package/lib/plugins/dsh-compat.js +37 -0
- package/lib/plugins/file-review.d.ts +108 -0
- package/lib/plugins/file-review.js +393 -0
- package/lib/plugins/git.d.ts +26 -0
- package/lib/plugins/git.js +132 -0
- package/lib/plugins/goal.d.ts +20 -0
- package/lib/plugins/goal.js +245 -0
- package/lib/plugins/guards.d.ts +14 -0
- package/lib/plugins/guards.js +18 -0
- package/lib/plugins/hooks.d.ts +19 -0
- package/lib/plugins/hooks.js +583 -0
- package/lib/plugins/host-stdio.d.ts +88 -0
- package/lib/plugins/host-stdio.js +317 -0
- package/lib/plugins/image-diet.d.ts +17 -0
- package/lib/plugins/image-diet.js +85 -0
- package/lib/plugins/lifecycle-hooks.d.ts +26 -0
- package/lib/plugins/lifecycle-hooks.js +338 -0
- package/lib/plugins/llm.d.ts +13 -0
- package/lib/plugins/llm.js +215 -0
- package/lib/plugins/lsp.d.ts +54 -0
- package/lib/plugins/lsp.js +608 -0
- package/lib/plugins/mcp.d.ts +16 -0
- package/lib/plugins/mcp.js +673 -0
- package/lib/plugins/memory.d.ts +17 -0
- package/lib/plugins/memory.js +858 -0
- package/lib/plugins/microcompact.d.ts +18 -0
- package/lib/plugins/microcompact.js +119 -0
- package/lib/plugins/mode.d.ts +18 -0
- package/lib/plugins/mode.js +115 -0
- package/lib/plugins/permission-presets.d.ts +18 -0
- package/lib/plugins/permission-presets.js +135 -0
- package/lib/plugins/plan.d.ts +2 -0
- package/lib/plugins/plan.js +192 -0
- package/lib/plugins/plugin-manager.d.ts +2 -0
- package/lib/plugins/plugin-manager.js +165 -0
- package/lib/plugins/presets.d.ts +2 -0
- package/lib/plugins/presets.js +182 -0
- package/lib/plugins/prompt.d.ts +2 -0
- package/lib/plugins/prompt.js +264 -0
- package/lib/plugins/ptc.d.ts +2 -0
- package/lib/plugins/ptc.js +272 -0
- package/lib/plugins/remote/http.d.ts +11 -0
- package/lib/plugins/remote/http.js +11 -0
- package/lib/plugins/remote/routes.d.ts +24 -0
- package/lib/plugins/remote/routes.js +384 -0
- package/lib/plugins/remote/types.d.ts +135 -0
- package/lib/plugins/remote/types.js +87 -0
- package/lib/plugins/remote.d.ts +17 -0
- package/lib/plugins/remote.js +1028 -0
- package/lib/plugins/runtime-api.d.ts +16 -0
- package/lib/plugins/runtime-api.js +99 -0
- package/lib/plugins/runtime.d.ts +10 -0
- package/lib/plugins/runtime.js +451 -0
- package/lib/plugins/sandbox.d.ts +2 -0
- package/lib/plugins/sandbox.js +761 -0
- package/lib/plugins/schedule.d.ts +26 -0
- package/lib/plugins/schedule.js +538 -0
- package/lib/plugins/self-improve.d.ts +61 -0
- package/lib/plugins/self-improve.js +953 -0
- package/lib/plugins/session-search.d.ts +16 -0
- package/lib/plugins/session-search.js +308 -0
- package/lib/plugins/session-title.d.ts +19 -0
- package/lib/plugins/session-title.js +109 -0
- package/lib/plugins/session.d.ts +7 -0
- package/lib/plugins/session.js +296 -0
- package/lib/plugins/settings.d.ts +3 -0
- package/lib/plugins/settings.js +705 -0
- package/lib/plugins/skills.d.ts +2 -0
- package/lib/plugins/skills.js +360 -0
- package/lib/plugins/spill.d.ts +16 -0
- package/lib/plugins/spill.js +200 -0
- package/lib/plugins/subagent.d.ts +2 -0
- package/lib/plugins/subagent.js +862 -0
- package/lib/plugins/surfaces.d.ts +11 -0
- package/lib/plugins/surfaces.js +20 -0
- package/lib/plugins/team.d.ts +16 -0
- package/lib/plugins/team.js +149 -0
- package/lib/plugins/todo.d.ts +19 -0
- package/lib/plugins/todo.js +188 -0
- package/lib/plugins/tool-search.d.ts +2 -0
- package/lib/plugins/tool-search.js +425 -0
- package/lib/plugins/tools-default.d.ts +12 -0
- package/lib/plugins/tools-default.js +275 -0
- package/lib/plugins/tools.d.ts +16 -0
- package/lib/plugins/tools.js +62 -0
- package/lib/plugins/transcript.d.ts +15 -0
- package/lib/plugins/transcript.js +311 -0
- package/lib/plugins/tui.d.ts +2 -0
- package/lib/plugins/tui.js +98 -0
- package/lib/plugins/waiting.d.ts +12 -0
- package/lib/plugins/waiting.js +34 -0
- package/lib/plugins/web-search.d.ts +14 -0
- package/lib/plugins/web-search.js +263 -0
- package/lib/plugins/webserver.d.ts +48 -0
- package/lib/plugins/webserver.js +228 -0
- package/lib/remote/assets/app-DAcUCOEn.js +14 -0
- package/lib/remote/assets/icon-192.png +0 -0
- package/lib/remote/assets/icon-512.png +0 -0
- package/lib/remote/assets/index.html +34 -0
- package/lib/remote/assets/manifest.json +27 -0
- package/lib/remote/assets/style-DIB6729x.css +1 -0
- package/lib/remote/assets/sw.js +66 -0
- package/lib/services/types.d.ts +1228 -0
- package/lib/services/types.js +1 -0
- package/lib/tools/config-cli.d.ts +1 -0
- package/lib/tools/config-cli.js +89 -0
- package/lib/ui/arrival.d.ts +72 -0
- package/lib/ui/arrival.js +105 -0
- package/lib/ui/assets/app-B70nVIKd.js +69 -0
- package/lib/ui/assets/chunk-2UxHyX5q.js +1 -0
- package/lib/ui/assets/chunk-B1dDrJ26.js +1 -0
- package/lib/ui/assets/chunk-B6aJPvgy.js +1 -0
- package/lib/ui/assets/chunk-BEwlwnbL.js +1 -0
- package/lib/ui/assets/chunk-BGcgwlCI.js +12 -0
- package/lib/ui/assets/chunk-BIGW1oBm.js +1 -0
- package/lib/ui/assets/chunk-BPQ3VLAy.js +1 -0
- package/lib/ui/assets/chunk-BRH0KZbk.js +141 -0
- package/lib/ui/assets/chunk-BX6H_ySx.js +1 -0
- package/lib/ui/assets/chunk-B_P3UbPa.js +1 -0
- package/lib/ui/assets/chunk-B_TYUkTI.js +1 -0
- package/lib/ui/assets/chunk-B_vNuMnf.js +1 -0
- package/lib/ui/assets/chunk-BajyYBss.js +10 -0
- package/lib/ui/assets/chunk-BdnUsdx6.js +1 -0
- package/lib/ui/assets/chunk-Buea-lGh.js +1 -0
- package/lib/ui/assets/chunk-C0PvZCCE.js +1 -0
- package/lib/ui/assets/chunk-C0m74zRD.js +1 -0
- package/lib/ui/assets/chunk-C27-OAKa.js +1 -0
- package/lib/ui/assets/chunk-C2oV4EkX.js +1 -0
- package/lib/ui/assets/chunk-C7zT0LnQ.js +1 -0
- package/lib/ui/assets/chunk-C9GSunVT.js +1 -0
- package/lib/ui/assets/chunk-C9tS-k6U.js +1 -0
- package/lib/ui/assets/chunk-CHLpvVh8.js +1 -0
- package/lib/ui/assets/chunk-CLxacb5B.js +1 -0
- package/lib/ui/assets/chunk-COt5Ahok.js +1 -0
- package/lib/ui/assets/chunk-CPTIWCL2.js +1 -0
- package/lib/ui/assets/chunk-CQLl-L-p.js +1 -0
- package/lib/ui/assets/chunk-CUWRgxuq.js +55 -0
- package/lib/ui/assets/chunk-CWanVSXC.js +1 -0
- package/lib/ui/assets/chunk-Cf5RLm7j.js +1 -0
- package/lib/ui/assets/chunk-CickPsom.js +1 -0
- package/lib/ui/assets/chunk-Cj5Yp3dK.js +1 -0
- package/lib/ui/assets/chunk-Cmh6b_Ma.js +1 -0
- package/lib/ui/assets/chunk-Cp-IABpG.js +1 -0
- package/lib/ui/assets/chunk-CqE71os6.js +1 -0
- package/lib/ui/assets/chunk-CtKP3W-j.js +1 -0
- package/lib/ui/assets/chunk-Cvjx9yec.js +1 -0
- package/lib/ui/assets/chunk-CxGP3dtY.js +1 -0
- package/lib/ui/assets/chunk-CylS5w8V.js +1 -0
- package/lib/ui/assets/chunk-D38fbIBN.js +1 -0
- package/lib/ui/assets/chunk-D97Zzqfu.js +1 -0
- package/lib/ui/assets/chunk-DAi9KRSo.js +1 -0
- package/lib/ui/assets/chunk-DHK4yRfg.js +1 -0
- package/lib/ui/assets/chunk-DJeabLx-.js +1 -0
- package/lib/ui/assets/chunk-DNRxmY5a.js +1 -0
- package/lib/ui/assets/chunk-DNSN1z5r.js +1 -0
- package/lib/ui/assets/chunk-DNasK_ZG.js +1 -0
- package/lib/ui/assets/chunk-DPvrY3IQ.js +1 -0
- package/lib/ui/assets/chunk-DXmwc3jG.js +1 -0
- package/lib/ui/assets/chunk-Dd0kTxKP.js +1 -0
- package/lib/ui/assets/chunk-De0Btta0.js +1 -0
- package/lib/ui/assets/chunk-Des-eS-w.js +1 -0
- package/lib/ui/assets/chunk-Df6bDoY_.js +1 -0
- package/lib/ui/assets/chunk-DijEV5ha.js +1 -0
- package/lib/ui/assets/chunk-DkvoVjww.js +1 -0
- package/lib/ui/assets/chunk-DlC-OlHO.js +1 -0
- package/lib/ui/assets/chunk-DnzrXTVv.js +1 -0
- package/lib/ui/assets/chunk-Dualf0xi.js +1 -0
- package/lib/ui/assets/chunk-EXT84bkm.js +1 -0
- package/lib/ui/assets/chunk-GwR3hkPK.js +1 -0
- package/lib/ui/assets/chunk-P80f7IUj.js +1 -0
- package/lib/ui/assets/chunk-VOosw3JB.js +1 -0
- package/lib/ui/assets/chunk-YQ4lDkt_.js +140 -0
- package/lib/ui/assets/chunk-Yzrsuije.js +1 -0
- package/lib/ui/assets/chunk-Z72CF80r.js +1 -0
- package/lib/ui/assets/chunk-g9-lgVsj.js +1 -0
- package/lib/ui/assets/chunk-vGWfd6FD.js +1 -0
- package/lib/ui/assets/chunk-wDzz0qaB.js +1 -0
- package/lib/ui/assets/chunk-ySF7HWmS.js +1 -0
- package/lib/ui/assets/icon.png +0 -0
- package/lib/ui/assets/index.html +14 -0
- package/lib/ui/assets/pdf.worker.min-CjEcRF4W.mjs +28 -0
- package/lib/ui/assets/style-Bq01xH_b.css +1 -0
- package/lib/ui/frames.d.ts +67 -0
- package/lib/ui/frames.js +146 -0
- package/lib/ui/index.d.ts +59 -0
- package/lib/ui/index.js +50 -0
- package/lib/ui/manifest.d.ts +172 -0
- package/lib/ui/manifest.js +158 -0
- package/lib/ui/plugin.d.ts +161 -0
- package/lib/ui/plugin.js +7 -0
- package/lib/ui/plugins/browser/client.js +290 -0
- package/lib/ui/plugins/browser/icon.png +0 -0
- package/lib/ui/plugins/composer/client.js +1843 -0
- package/lib/ui/plugins/composer/icon.png +0 -0
- package/lib/ui/plugins/files/client.js +646 -0
- package/lib/ui/plugins/files/icon.png +0 -0
- package/lib/ui/plugins/manifest.json +107 -0
- package/lib/ui/plugins/plugins/client.js +682 -0
- package/lib/ui/plugins/plugins/icon.png +0 -0
- package/lib/ui/plugins/preview/client.js +197 -0
- package/lib/ui/plugins/preview/icon.png +0 -0
- package/lib/ui/plugins/prompt/client.js +653 -0
- package/lib/ui/plugins/prompt/icon.png +0 -0
- package/lib/ui/plugins/sessions/client.js +1577 -0
- package/lib/ui/plugins/sessions/icon.png +0 -0
- package/lib/ui/plugins/settings/client.js +5470 -0
- package/lib/ui/plugins/settings/icon.png +0 -0
- package/lib/ui/plugins/skills/client.js +485 -0
- package/lib/ui/plugins/skills/icon.png +0 -0
- package/lib/ui/plugins/status/client.js +1420 -0
- package/lib/ui/plugins/status/icon.png +0 -0
- package/lib/ui/plugins/statusbar/client.js +504 -0
- package/lib/ui/plugins/statusbar/icon.png +0 -0
- package/lib/ui/plugins/tasks/client.js +52 -0
- package/lib/ui/plugins/tasks/icon.png +0 -0
- package/lib/ui/plugins/team/client.js +527 -0
- package/lib/ui/plugins/team/icon.png +0 -0
- package/lib/ui/plugins/terminal/client.js +232 -0
- package/lib/ui/plugins/terminal/icon.png +0 -0
- package/lib/ui/plugins/trace/client.js +1376 -0
- package/lib/ui/plugins/trace/icon.png +0 -0
- package/lib/ui/plugins/transcript/client.js +2661 -0
- package/lib/ui/plugins/transcript/icon.png +0 -0
- package/lib/ui/scoped-slots.d.ts +20 -0
- package/lib/ui/scoped-slots.js +21 -0
- package/lib/ui/sdk/@dsc/ui/index.d.ts +242 -0
- package/lib/ui/sdk/@dsc/ui/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-core/contract.d.ts +1973 -0
- package/lib/ui/sdk/@dsc/ui-core/core/diff-text.d.ts +74 -0
- package/lib/ui/sdk/@dsc/ui-core/core/dock-browser.d.ts +137 -0
- package/lib/ui/sdk/@dsc/ui-core/core/dock-ops.d.ts +59 -0
- package/lib/ui/sdk/@dsc/ui-core/core/model-caps.d.ts +83 -0
- package/lib/ui/sdk/@dsc/ui-core/core/native-bridge.d.ts +135 -0
- package/lib/ui/sdk/@dsc/ui-core/core/token-estimate.d.ts +55 -0
- package/lib/ui/sdk/@dsc/ui-core/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/arrival.d.ts +72 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/frames.d.ts +67 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/index.d.ts +59 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/manifest.d.ts +172 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/plugin.d.ts +161 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/scoped-slots.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/services-react.d.ts +27 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/services.d.ts +63 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/slots-react.d.ts +28 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/slots.d.ts +481 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/store.d.ts +89 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock-model.d.ts +238 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock-state.d.ts +163 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/index.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-layout/app.d.ts +74 -0
- package/lib/ui/sdk/@dsc/ui-layout/appearance.d.ts +70 -0
- package/lib/ui/sdk/@dsc/ui-layout/host-channel.d.ts +112 -0
- package/lib/ui/sdk/@dsc/ui-layout/index.d.ts +34 -0
- package/lib/ui/sdk/@dsc/ui-layout/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-layout/page-state.d.ts +14 -0
- package/lib/ui/sdk/@dsc/ui-layout/review-pane.d.ts +21 -0
- package/lib/ui/sdk/@dsc/ui-layout/runtime-context.d.ts +44 -0
- package/lib/ui/sdk/@dsc/ui-layout/thread-view.d.ts +28 -0
- package/lib/ui/sdk/@dsc/ui-layout/update-button.d.ts +21 -0
- package/lib/ui/sdk/@dsc/ui-primitives/code-file-icon-artwork.d.ts +53 -0
- package/lib/ui/sdk/@dsc/ui-primitives/code-view.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-primitives/compat.d.ts +27 -0
- package/lib/ui/sdk/@dsc/ui-primitives/completion-sound.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-primitives/confirm.d.ts +33 -0
- package/lib/ui/sdk/@dsc/ui-primitives/css.d.ts +47 -0
- package/lib/ui/sdk/@dsc/ui-primitives/diff-rows.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-icons.d.ts +38 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-type-classify.d.ts +66 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-type-icon.d.ts +57 -0
- package/lib/ui/sdk/@dsc/ui-primitives/highlight.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-primitives/hover-delay.d.ts +17 -0
- package/lib/ui/sdk/@dsc/ui-primitives/icons.d.ts +109 -0
- package/lib/ui/sdk/@dsc/ui-primitives/index.d.ts +55 -0
- package/lib/ui/sdk/@dsc/ui-primitives/lang-table.d.ts +10 -0
- package/lib/ui/sdk/@dsc/ui-primitives/markdown.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-primitives/native.d.ts +41 -0
- package/lib/ui/sdk/@dsc/ui-primitives/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-primitives/panels.d.ts +86 -0
- package/lib/ui/sdk/@dsc/ui-primitives/paths.d.ts +11 -0
- package/lib/ui/sdk/@dsc/ui-primitives/pdf-view.d.ts +13 -0
- package/lib/ui/sdk/@dsc/ui-primitives/plugin-text.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-primitives/select.d.ts +35 -0
- package/lib/ui/sdk/@dsc/ui-primitives/table-view.d.ts +23 -0
- package/lib/ui/sdk/@dsc/ui-primitives/thread-resizer.d.ts +22 -0
- package/lib/ui/sdk/@dsc/ui-primitives/time.d.ts +33 -0
- package/lib/ui/sdk/@dsc/ui-primitives/toast.d.ts +16 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tokens.d.ts +14 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tool-args.d.ts +49 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tool-summary.d.ts +64 -0
- package/lib/ui/sdk/@dsc/ui-renderer/boot.d.ts +121 -0
- package/lib/ui/sdk/@dsc/ui-renderer/hmr.d.ts +43 -0
- package/lib/ui/sdk/@dsc/ui-renderer/index.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-renderer/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-slots/index.d.ts +19 -0
- package/lib/ui/sdk/@dsc/ui-slots/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-slots/slots-react.d.ts +48 -0
- package/lib/ui/sdk/@dsc/ui-slots/slots.d.ts +102 -0
- package/lib/ui/services-react.d.ts +27 -0
- package/lib/ui/services-react.js +32 -0
- package/lib/ui/services.d.ts +63 -0
- package/lib/ui/services.js +121 -0
- package/lib/ui/slots-ink.d.ts +26 -0
- package/lib/ui/slots-ink.js +78 -0
- package/lib/ui/slots-react.d.ts +28 -0
- package/lib/ui/slots-react.js +88 -0
- package/lib/ui/slots.d.ts +481 -0
- package/lib/ui/slots.js +550 -0
- package/lib/ui/store.d.ts +89 -0
- package/lib/ui/store.js +62 -0
- package/lib/ui/tui-plugin-api.d.ts +23 -0
- package/lib/ui/tui-plugin-api.js +23 -0
- package/lib/ui/tui-plugins.d.ts +47 -0
- package/lib/ui/tui-plugins.js +220 -0
- package/package.json +58 -6
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { contentText } from './llm.js';
|
|
2
|
+
import { estimateTextTokens } from './token-estimate.js';
|
|
3
|
+
import { spillText } from './spill.js';
|
|
4
|
+
import { buildAnchorIndex, buildReadState, buildRecoveryFooter, collectVerbatimUserMessages, DEFAULT_ANCHOR_BUDGET_CHARS, DEFAULT_READ_STATE_BUDGET_CHARS, DEFAULT_READ_STATE_FILES, DEFAULT_USER_QUOTE_BUDGET_CHARS, SUMMARY_BANNER, } from './compact-anchors.js';
|
|
5
|
+
/** 压缩后保留的最近消息条数的缺省值(compact 插件配置没给 `keepRecent` 时用它)。 */
|
|
6
|
+
export const DEFAULT_KEEP_RECENT = 20;
|
|
7
|
+
/** 前置裁剪的缺省口径。 */
|
|
8
|
+
export const DEFAULT_PRUNE_OPTIONS = { imageBudget: 4, toolResultChars: 2000 };
|
|
9
|
+
/**
|
|
10
|
+
* 历史的前置裁剪(纯消息变换 + spill 落盘):
|
|
11
|
+
* - 超预算的 string 工具结果 → spill 预览(前几行 + 完整路径 + 续读写法)或纯截断说明;
|
|
12
|
+
* - 带图工具结果的图片全部卸载为占位(截图留在历史里等于每轮重发);
|
|
13
|
+
* - 用户消息图片按预算保留,超出的换「图片已卸载」占位。
|
|
14
|
+
*/
|
|
15
|
+
export function pruneRegion(messages, sessionId, options) {
|
|
16
|
+
let spilledTools = 0;
|
|
17
|
+
let offloadedImages = 0;
|
|
18
|
+
let imageBudget = options.imageBudget;
|
|
19
|
+
const region = messages.map((message) => {
|
|
20
|
+
if (message.role === 'tool' && typeof message.content === 'string') {
|
|
21
|
+
if (message.content.length <= options.toolResultChars)
|
|
22
|
+
return message;
|
|
23
|
+
spilledTools += 1;
|
|
24
|
+
let replacement;
|
|
25
|
+
if (options.spill !== undefined) {
|
|
26
|
+
const spilled = spillText(sessionId, message.content, options.spill);
|
|
27
|
+
replacement = spilled.text;
|
|
28
|
+
// 单行巨型输出(一行几万字符的 bundle)会让「前 N 行」的预览照样巨大,
|
|
29
|
+
// 预览超限时按字符再截一刀,指针单独补回去——模型照着路径 read 就能找回全文
|
|
30
|
+
if (replacement.length > options.toolResultChars * 2) {
|
|
31
|
+
replacement = `${replacement.slice(0, options.toolResultChars)}…(预览超限已截)\n[完整输出已落盘:${spilled.written.path}]`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
replacement = `${message.content.slice(0, options.toolResultChars)}\n…(已裁剪,原长 ${message.content.length} 字符)`;
|
|
36
|
+
}
|
|
37
|
+
return { ...message, content: replacement };
|
|
38
|
+
}
|
|
39
|
+
const parts = message.content;
|
|
40
|
+
if (parts === null || typeof parts === 'string')
|
|
41
|
+
return message;
|
|
42
|
+
const hasImage = parts.some((part) => part.type === 'image_url');
|
|
43
|
+
if (!hasImage)
|
|
44
|
+
return message;
|
|
45
|
+
const text = contentText(parts);
|
|
46
|
+
let replaced = false;
|
|
47
|
+
let removedInMessage = 0;
|
|
48
|
+
const nextParts = parts.flatMap((part) => {
|
|
49
|
+
if (part.type !== 'image_url')
|
|
50
|
+
return [part];
|
|
51
|
+
if (message.role === 'user' && imageBudget > 0) {
|
|
52
|
+
imageBudget -= 1;
|
|
53
|
+
return [part];
|
|
54
|
+
}
|
|
55
|
+
replaced = true;
|
|
56
|
+
offloadedImages += 1;
|
|
57
|
+
removedInMessage += 1;
|
|
58
|
+
return [{ type: 'text', text: '(图片已卸载,原文里这里是一张图)' }];
|
|
59
|
+
});
|
|
60
|
+
if (!replaced)
|
|
61
|
+
return message;
|
|
62
|
+
// 工具结果整条收成一句说明(正文 + 卸载注记);用户消息保留剩余部件与占位
|
|
63
|
+
if (message.role === 'tool') {
|
|
64
|
+
return { ...message, content: [{ type: 'text', text: `${text}\n(工具结果里的 ${removedInMessage} 张图已卸载)` }] };
|
|
65
|
+
}
|
|
66
|
+
return { ...message, content: nextParts };
|
|
67
|
+
});
|
|
68
|
+
return { region, spilledTools, offloadedImages };
|
|
69
|
+
}
|
|
70
|
+
/** 各上限的缺省值(compact 插件配置没给时用它)。 */
|
|
71
|
+
export const DEFAULT_COMPACT_LIMITS = {
|
|
72
|
+
keepRecent: DEFAULT_KEEP_RECENT,
|
|
73
|
+
anchorChars: DEFAULT_ANCHOR_BUDGET_CHARS,
|
|
74
|
+
userQuoteChars: DEFAULT_USER_QUOTE_BUDGET_CHARS,
|
|
75
|
+
readStateFiles: DEFAULT_READ_STATE_FILES,
|
|
76
|
+
readStateChars: DEFAULT_READ_STATE_BUDGET_CHARS,
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* 粗略 token 估算(口径见 core/token-estimate.ts 的模块注释:中文 0.65、其余 0.33)。
|
|
80
|
+
*/
|
|
81
|
+
export function estimateTokens(messages) {
|
|
82
|
+
let tokens = 0;
|
|
83
|
+
for (const message of messages) {
|
|
84
|
+
const content = message.content;
|
|
85
|
+
if (typeof content === 'string') {
|
|
86
|
+
tokens += estimateTextTokens(content);
|
|
87
|
+
}
|
|
88
|
+
else if (content !== null) {
|
|
89
|
+
for (const part of content) {
|
|
90
|
+
// 图像每张按 1000 token 估(与原 chars/3 时代的 4000 字符/张同口径)。
|
|
91
|
+
tokens += part.type === 'text' ? estimateTextTokens(part.text) : 1_000;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
for (const call of message.tool_calls ?? []) {
|
|
95
|
+
tokens += estimateTextTokens(call.function.name + call.function.arguments);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return Math.ceil(tokens);
|
|
99
|
+
}
|
|
100
|
+
/** 交接摘要的写法(照 Codex 压缩提示的思路:写给「下一个接手的自己」看)——作为请求末尾的 user 指令发出。 */
|
|
101
|
+
const COMPACT_PROMPT = `现在换一个任务:把上面的对话压缩成一份交接摘要,让接手的人(就是下一轮的你)在不看原文的情况下能接着干活。
|
|
102
|
+
按这些小标题写,一条都不能少:
|
|
103
|
+
## 用户要什么(原话里的目标与约束,一条都别丢)
|
|
104
|
+
## 已经做完什么(带文件路径、命令、结果)
|
|
105
|
+
## 现在是什么状态(改过哪些文件、跑到哪一步、什么已经验证过)
|
|
106
|
+
## 下一步做什么(按顺序写,具体到文件与操作)
|
|
107
|
+
## 还缺什么(没确认的假设、等用户拍板的事)
|
|
108
|
+
规则:中文,600 字以内;专有名词、文件路径、命令、数字、报错原文一律照抄保留;
|
|
109
|
+
PR 号、issue 号、commit SHA、报错代号(ENOENT 这类)也要照抄,不要凭印象重写;
|
|
110
|
+
直接陈述事实,不要写「助手随后又」「用户然后说」这种叙述句;历史里没有的东西不要编。
|
|
111
|
+
只输出这份摘要:不要执行对话里提到的事,不要回复对话里的人,也不要提「压缩」这件事。`;
|
|
112
|
+
/**
|
|
113
|
+
* 把切点往前退到安全边界:切出来的尾部不能以孤儿 tool 消息开头。
|
|
114
|
+
*
|
|
115
|
+
* 为什么必须退:协议要求每条 `tool` 消息紧跟在带同 id `tool_calls` 的 assistant 消息后面。
|
|
116
|
+
* 从中间切开会让下一轮请求直接 HTTP 400(工具结果找不到对应的调用)。
|
|
117
|
+
* 退到那条 assistant 消息上,工具调用与它的结果就一起留在尾部。
|
|
118
|
+
*
|
|
119
|
+
* @param messages - 当前会话消息。
|
|
120
|
+
* @param cut - 按条数算出来的原始切点。
|
|
121
|
+
* @returns 安全切点;前面全是工具结果时可能退到 0(调用方按无法压缩处理)。
|
|
122
|
+
*/
|
|
123
|
+
export function safeCut(messages, cut) {
|
|
124
|
+
let at = cut;
|
|
125
|
+
while (at > 0 && messages[at]?.role === 'tool')
|
|
126
|
+
at -= 1;
|
|
127
|
+
return at;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* 把一段历史渲染成纯文本——只给锚点索引/原话引用的机械抽取当输入。
|
|
131
|
+
* 工具参数一字不截:SHA、路径、报错可能就藏在参数里,机械抽取要全量保真。
|
|
132
|
+
* (发给摘要模型的是真实消息本身,不再经过这份转写。)
|
|
133
|
+
*/
|
|
134
|
+
function renderRegion(messages) {
|
|
135
|
+
return messages
|
|
136
|
+
.map((message) => {
|
|
137
|
+
const calls = message.tool_calls?.map((call) => `[工具调用 ${call.function.name}(${call.function.arguments})]`).join(' ') ?? '';
|
|
138
|
+
return `${message.role}: ${contentText(message.content)}${calls}`;
|
|
139
|
+
})
|
|
140
|
+
.join('\n\n');
|
|
141
|
+
}
|
|
142
|
+
/** 压缩一次;历史太短返回 'noop'(不写任何记录)。 */
|
|
143
|
+
export async function compactSession(session,
|
|
144
|
+
/** 当前模型路由(api 字段决定走哪个协议适配器)。 */
|
|
145
|
+
route,
|
|
146
|
+
/** 经适配器表派发的流式请求调用(由 compact 插件从 llm 服务取)。 */
|
|
147
|
+
stream, signal,
|
|
148
|
+
/** 摘要之外要原样带过去的内容(任务清单、会话目标这类状态,不能被摘要吃掉)。 */
|
|
149
|
+
extra,
|
|
150
|
+
/** 三个上限;compact 插件把它的配置值传进来。 */
|
|
151
|
+
limits,
|
|
152
|
+
/** 爆窗重试用:忽略「历史太短」的 noop 检查直接压一次(切点退到 0 时仍放弃)。 */
|
|
153
|
+
force,
|
|
154
|
+
/** 摘要前置裁剪(T19);不传用缺省口径(不落盘、只按预算截断)。 */
|
|
155
|
+
prune,
|
|
156
|
+
/**
|
|
157
|
+
* 复用主对话前缀的两样东西(摘要调用因此命中服务端 KV 缓存,对齐 dsh summarizer):
|
|
158
|
+
* system = 与主对话一字不差的系统提示词;tools = 主对话那份工具目录(缺省不发)。
|
|
159
|
+
* 必传:没有它摘要调用就是独立形状,缓存的账对不上。
|
|
160
|
+
*/
|
|
161
|
+
context) {
|
|
162
|
+
const caps = limits ?? DEFAULT_COMPACT_LIMITS;
|
|
163
|
+
const messages = session.messages;
|
|
164
|
+
if (force !== true && messages.length <= caps.keepRecent + 2)
|
|
165
|
+
return 'noop';
|
|
166
|
+
const cut = safeCut(messages, messages.length - caps.keepRecent);
|
|
167
|
+
// 切点退到 0 = 整个历史都是工具结果,没有可折的内容(正常历史首条必然是用户消息)
|
|
168
|
+
if (cut === 0)
|
|
169
|
+
return 'noop';
|
|
170
|
+
const raw = messages.slice(0, cut);
|
|
171
|
+
// T19:送摘要模型前先机械瘦身(超长工具结果留 spill 指针、老图卸载);
|
|
172
|
+
// 锚点索引与原话引用仍取自原文——机械抽取要全量保真,不能跟着裁剪走
|
|
173
|
+
const pruned = pruneRegion(raw, session.meta.id, prune ?? { ...DEFAULT_PRUNE_OPTIONS });
|
|
174
|
+
const region = pruned.region;
|
|
175
|
+
// 请求形态(2026-10-03):真实系统提示词 + 被折区间的真实消息 + 末尾一条压缩指令——
|
|
176
|
+
// 整条请求是上一次真实请求的前缀扩展,服务端缓存能一直命中到指令前一个字;
|
|
177
|
+
// 工具目录照发,少一样就不是前缀了。
|
|
178
|
+
const result = await stream(route.api, {
|
|
179
|
+
baseUrl: route.baseUrl,
|
|
180
|
+
apiKey: route.apiKey,
|
|
181
|
+
model: route.model,
|
|
182
|
+
// 摘要是**这条会话**的请求:端点按会话归因时得算在被压的会话头上,
|
|
183
|
+
// 不能算成「当前查看的会话」(后台会话照样会压缩)
|
|
184
|
+
sessionId: session.meta.id,
|
|
185
|
+
maxTokens: route.maxTokens,
|
|
186
|
+
temperature: route.temperature,
|
|
187
|
+
// 压缩请求是上一次真实请求的前缀扩展:端点支持显式缓存时,断点也照打,
|
|
188
|
+
// 不然这条「暖缓存」路径反而比正常请求少一层命中(缺省 false = 完全不变)
|
|
189
|
+
...(route.cacheControl === true ? { cacheControl: true } : {}),
|
|
190
|
+
signal,
|
|
191
|
+
...(context.tools === undefined || context.tools.length === 0 ? {} : { tools: [...context.tools] }),
|
|
192
|
+
messages: [{ role: 'system', content: context.system }, ...region, { role: 'user', content: COMPACT_PROMPT }],
|
|
193
|
+
}, { onDelta() { } });
|
|
194
|
+
if (result.text.trim() === '')
|
|
195
|
+
throw new Error('摘要模型返回为空');
|
|
196
|
+
// 锚点从没裁剪的原文里抽:路径与报错可能整段被裁进了 spill 文件,
|
|
197
|
+
// 锚点索引是模型找回它们的最后一根线,必须全量保真
|
|
198
|
+
const anchors = buildAnchorIndex(renderRegion(raw), caps.anchorChars);
|
|
199
|
+
const quotes = collectVerbatimUserMessages(raw, caps.userQuoteChars);
|
|
200
|
+
// read-state 与锚点一样取自**原文**:它要的是「模型最后读了哪一段」这个事实,
|
|
201
|
+
// 与送摘要模型前的裁剪无关
|
|
202
|
+
const readState = buildReadState(raw, caps.readStateChars, caps.readStateFiles);
|
|
203
|
+
const recovery = buildRecoveryFooter({ regionMessages: region.length, sessionFile: session.filePath });
|
|
204
|
+
const carry = extra === undefined || extra.trim() === '' ? '' : `\n\n${extra.trim()}`;
|
|
205
|
+
// 顺序固定:摘要正文 → 原样带过去的状态 → 用户原话 → 锚点 → read-state → 细节找回
|
|
206
|
+
const summary = `${SUMMARY_BANNER}\n${result.text.trim()}${carry}${quotes}${anchors}${readState}${recovery}`;
|
|
207
|
+
const kept = [{ role: 'user', content: summary }, ...messages.slice(cut)];
|
|
208
|
+
session.replaceWithSummary(summary, kept);
|
|
209
|
+
return 'compacted';
|
|
210
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ModelConfigView, ProviderDraft } from '../contract.js';
|
|
2
|
+
import { type FileConfig } from './migrate.js';
|
|
3
|
+
/** 出厂那份 config.yaml 的绝对路径(没换过配置文件的就用它)。 */
|
|
4
|
+
export declare const DEFAULT_CONFIG_FILE: string;
|
|
5
|
+
/** dsc 凭据库路径。 */
|
|
6
|
+
export declare const CREDENTIALS_FILE: string;
|
|
7
|
+
export declare function activeConfigFile(): string;
|
|
8
|
+
/** 清掉 {@link activeConfigFile} 的缓存(换过配置文件、或外部改过 settings.json 之后调)。 */
|
|
9
|
+
export declare function invalidateActiveConfigFile(): void;
|
|
10
|
+
/** 读配置文件的原始文档(保留未知字段,缺 key 的端点也留着)。 */
|
|
11
|
+
export declare function readConfigDoc(): FileConfig;
|
|
12
|
+
/** 写配置文件(覆盖前备份 .bak)。 */
|
|
13
|
+
export declare function writeConfigDoc(doc: FileConfig): void;
|
|
14
|
+
/** 这个 key 名当前能不能取到值(运行期同一套优先级)。 */
|
|
15
|
+
export declare function keyAvailable(ref: string): boolean;
|
|
16
|
+
/** 设置界面「模型」分区的数据源(读文件,因此缺 key 的端点也在列表里)。 */
|
|
17
|
+
export declare function readModelConfig(): ModelConfigView;
|
|
18
|
+
/**
|
|
19
|
+
* 校验并归一化端点草稿(抛错的消息可直接展示给用户)。
|
|
20
|
+
* 草稿从渲染进程经 IPC 过来,属于跨进程边界,能力字段在这里过一遍枚举。
|
|
21
|
+
*/
|
|
22
|
+
export declare function validateDraft(draft: ProviderDraft): void;
|
|
23
|
+
/**
|
|
24
|
+
* 写入端点新增/编辑/改名(同一 name 覆盖)。
|
|
25
|
+
* @returns 改名后的新名字。
|
|
26
|
+
*/
|
|
27
|
+
export declare function upsertProvider(oldName: string | null, draft: ProviderDraft): string;
|
|
28
|
+
/** 删除端点;默认端点被删时把 default 改指第一个可用端点。 */
|
|
29
|
+
export declare function deleteProvider(name: string): void;
|
|
30
|
+
/** 写默认端点/模型。 */
|
|
31
|
+
export declare function writeDefaultModel(provider: string, model: string): void;
|
|
32
|
+
/** 写采样温度(null = 删除该字段,跟随端点默认)。 */
|
|
33
|
+
export declare function writeTemperature(temperature: number | null): void;
|
|
34
|
+
/**
|
|
35
|
+
* 写入或清除端点的 API key(写 dsc 凭据库,并同步 process.env 让当前进程立即能用)。
|
|
36
|
+
* @returns 给用户看的一句结果说明。
|
|
37
|
+
*/
|
|
38
|
+
export declare function writeProviderKey(ref: string, apiKey: string | null): string;
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 模型配置的读写层:`~/.dsc/config.yaml`(providers + default + temperature)
|
|
3
|
+
* 与 `~/.dsc/credentials.yaml`(API key)。设置界面「模型」分区是唯一写者,
|
|
4
|
+
* headless 启动时读的那份对象由 settings 插件同步更新,所以改完不用重启宿主。
|
|
5
|
+
*
|
|
6
|
+
* 三条硬规矩:
|
|
7
|
+
* - API key 的值只写 credentials.yaml 的 refs,config.yaml 只留 apiKeyEnv 名字;
|
|
8
|
+
* - 写 config.yaml 前先落一份 `.bak`(YAML 重新序列化会丢手写注释);
|
|
9
|
+
* - 读清单时以文件为准,缺 key 的端点也要列出来(运行期配置会把它过滤掉)。
|
|
10
|
+
*
|
|
11
|
+
* @module dsc/core/config-store
|
|
12
|
+
*/
|
|
13
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
14
|
+
import { dirname } from 'node:path';
|
|
15
|
+
import { readPrefs } from './prefs.js';
|
|
16
|
+
import YAML from 'yaml';
|
|
17
|
+
import { DEFAULT_THINKING_LEVELS, DEFAULT_THINKING_PARAM, MODALITIES, THINKING_LEVELS, THINKING_PARAMS, normalizeModalities, readModelCaps, } from './model-caps.js';
|
|
18
|
+
import { DSC_CONFIG_YAML, DSC_CREDENTIALS, DSH_CREDENTIALS, parseTolerantYaml, } from './migrate.js';
|
|
19
|
+
/** 出厂那份 config.yaml 的绝对路径(没换过配置文件的就用它)。 */
|
|
20
|
+
export const DEFAULT_CONFIG_FILE = DSC_CONFIG_YAML;
|
|
21
|
+
/** dsc 凭据库路径。 */
|
|
22
|
+
export const CREDENTIALS_FILE = DSC_CREDENTIALS;
|
|
23
|
+
/**
|
|
24
|
+
* 当前生效的配置文件路径:设置里换过就用那一份,没换过(或那一份已经不在了)用出厂的。
|
|
25
|
+
*
|
|
26
|
+
* 为什么「不在了就回落」而不是报错:配置是启动的必需品,指向一份被删掉的文件时宁可
|
|
27
|
+
* 用出厂的把应用开起来,也别让端点全空。设置页那一行显示的就是这个函数的返回值,
|
|
28
|
+
* 所以回落是看得见的(路径会变回 ~/.dsc/config.yaml)。
|
|
29
|
+
*
|
|
30
|
+
* 读 settings.json 每次调用一次太重(配置读取散在各处),所以记一层进程内缓存;
|
|
31
|
+
* 换文件({@link setActiveConfigFile})时由写入方清掉。
|
|
32
|
+
*/
|
|
33
|
+
let activeCache = null;
|
|
34
|
+
export function activeConfigFile() {
|
|
35
|
+
if (activeCache !== null)
|
|
36
|
+
return activeCache;
|
|
37
|
+
const custom = readPrefs().configFile;
|
|
38
|
+
activeCache = custom !== '' && existsSync(custom) ? custom : DSC_CONFIG_YAML;
|
|
39
|
+
return activeCache;
|
|
40
|
+
}
|
|
41
|
+
/** 清掉 {@link activeConfigFile} 的缓存(换过配置文件、或外部改过 settings.json 之后调)。 */
|
|
42
|
+
export function invalidateActiveConfigFile() {
|
|
43
|
+
activeCache = null;
|
|
44
|
+
}
|
|
45
|
+
/** 读配置文件的原始文档(保留未知字段,缺 key 的端点也留着)。 */
|
|
46
|
+
export function readConfigDoc() {
|
|
47
|
+
const file = activeConfigFile();
|
|
48
|
+
if (!existsSync(file))
|
|
49
|
+
return { providers: {} };
|
|
50
|
+
const doc = parseTolerantYaml(readFileSync(file, 'utf8'));
|
|
51
|
+
if (doc.providers === null || typeof doc.providers !== 'object')
|
|
52
|
+
doc.providers = {};
|
|
53
|
+
return doc;
|
|
54
|
+
}
|
|
55
|
+
/** 写配置文件(覆盖前备份 .bak)。 */
|
|
56
|
+
export function writeConfigDoc(doc) {
|
|
57
|
+
const file = activeConfigFile();
|
|
58
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
59
|
+
if (existsSync(file)) {
|
|
60
|
+
try {
|
|
61
|
+
copyFileSync(file, `${file}.bak`);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// 备份失败不阻塞写入:内容仍由调用方校验过
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const header = '# Pneuma 模型配置(设置界面「模型」分区可直接编辑,也可手改本文件)\n' +
|
|
68
|
+
'# key 来源顺序:apiKeyEnv 环境变量 → ~/.dsc/credentials.yaml → ~/.dsh/.credentials.yaml\n' +
|
|
69
|
+
'# 模型可选字段:thinkingLevels(支持哪些思考档位)、thinkingParam(档位发 thinking 还是 reasoning_effort)、\n' +
|
|
70
|
+
'# effortMap(reasoning_effort 下各档的线上值)、modalities(text/image/video);不写 = 四档 + thinking 开关 + 只吃文本\n';
|
|
71
|
+
writeFileSync(file, `${header}${YAML.stringify(doc)}`, 'utf8');
|
|
72
|
+
}
|
|
73
|
+
/** 凭据库的 refs 段(key 名 → 值)。 */
|
|
74
|
+
function readCredentialRefs() {
|
|
75
|
+
if (!existsSync(DSC_CREDENTIALS))
|
|
76
|
+
return {};
|
|
77
|
+
const doc = parseTolerantYaml(readFileSync(DSC_CREDENTIALS, 'utf8'));
|
|
78
|
+
const refs = {};
|
|
79
|
+
for (const [name, value] of Object.entries(doc.refs ?? {})) {
|
|
80
|
+
if (typeof value === 'string')
|
|
81
|
+
refs[name] = value;
|
|
82
|
+
}
|
|
83
|
+
return refs;
|
|
84
|
+
}
|
|
85
|
+
/** 写凭据库 refs(保留其他条目;mode 600,值不外泄)。 */
|
|
86
|
+
function writeCredentialRef(ref, value) {
|
|
87
|
+
const refs = readCredentialRefs();
|
|
88
|
+
if (value === null)
|
|
89
|
+
delete refs[ref];
|
|
90
|
+
else
|
|
91
|
+
refs[ref] = value;
|
|
92
|
+
mkdirSync(dirname(DSC_CREDENTIALS), { recursive: true });
|
|
93
|
+
writeFileSync(DSC_CREDENTIALS, YAML.stringify({ refs }), { encoding: 'utf8', mode: 0o600 });
|
|
94
|
+
}
|
|
95
|
+
/** dsh 的凭据库里有没有这个 key(只读,dsc 永不修改 dsh 的文件)。 */
|
|
96
|
+
function dshCredentialsHas(ref) {
|
|
97
|
+
if (!existsSync(DSH_CREDENTIALS))
|
|
98
|
+
return false;
|
|
99
|
+
const doc = parseTolerantYaml(readFileSync(DSH_CREDENTIALS, 'utf8'));
|
|
100
|
+
const value = doc.refs?.[ref];
|
|
101
|
+
return typeof value === 'string' && value !== '';
|
|
102
|
+
}
|
|
103
|
+
/** 这个 key 名当前能不能取到值(运行期同一套优先级)。 */
|
|
104
|
+
export function keyAvailable(ref) {
|
|
105
|
+
if (ref === '')
|
|
106
|
+
return false;
|
|
107
|
+
if ((process.env[ref] ?? '') !== '')
|
|
108
|
+
return true;
|
|
109
|
+
if ((readCredentialRefs()[ref] ?? '') !== '')
|
|
110
|
+
return true;
|
|
111
|
+
return dshCredentialsHas(ref);
|
|
112
|
+
}
|
|
113
|
+
function toModelViews(models) {
|
|
114
|
+
return (models ?? []).map((model) => ({
|
|
115
|
+
id: String(model.id ?? ''),
|
|
116
|
+
name: String(model.name ?? model.id ?? ''),
|
|
117
|
+
contextWindow: typeof model.contextWindow === 'number' ? model.contextWindow : 128_000,
|
|
118
|
+
maxTokens: typeof model.maxTokens === 'number' ? model.maxTokens : 8_192,
|
|
119
|
+
...readModelCaps(model),
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
/** 设置界面「模型」分区的数据源(读文件,因此缺 key 的端点也在列表里)。 */
|
|
123
|
+
export function readModelConfig() {
|
|
124
|
+
const doc = readConfigDoc();
|
|
125
|
+
const providers = Object.entries(doc.providers).map(([name, raw]) => {
|
|
126
|
+
const keyRef = typeof raw.apiKeyEnv === 'string' && raw.apiKeyEnv !== '' ? raw.apiKeyEnv : `${name.toUpperCase()}_API_KEY`;
|
|
127
|
+
return {
|
|
128
|
+
name,
|
|
129
|
+
displayName: typeof raw.displayName === 'string' && raw.displayName !== '' ? raw.displayName : name,
|
|
130
|
+
baseUrl: typeof raw.baseURL === 'string' ? raw.baseURL : '',
|
|
131
|
+
keyRef,
|
|
132
|
+
keyConfigured: keyAvailable(keyRef),
|
|
133
|
+
models: toModelViews(raw.models),
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
return {
|
|
137
|
+
providers,
|
|
138
|
+
defaultProvider: doc.default?.provider ?? '',
|
|
139
|
+
defaultModel: doc.default?.model ?? '',
|
|
140
|
+
temperature: typeof doc.temperature === 'number' ? doc.temperature : null,
|
|
141
|
+
configFile: activeConfigFile(),
|
|
142
|
+
credentialsFile: CREDENTIALS_FILE,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
const NAME_PATTERN = /^[a-z0-9][a-z0-9_-]{0,40}$/;
|
|
146
|
+
/**
|
|
147
|
+
* 草稿里的能力字段:旧渲染进程或手拼的调用可能整个不带这些字段,
|
|
148
|
+
* 缺省按 {@link DEFAULT_CAPS} 那套走,不能让校验层因为 undefined 直接崩。
|
|
149
|
+
*/
|
|
150
|
+
function capsOf(model) {
|
|
151
|
+
return {
|
|
152
|
+
thinkingLevels: model.thinkingLevels ?? [...DEFAULT_THINKING_LEVELS],
|
|
153
|
+
thinkingParam: model.thinkingParam ?? DEFAULT_THINKING_PARAM,
|
|
154
|
+
effortMap: model.effortMap ?? {},
|
|
155
|
+
modalities: model.modalities ?? ['text'],
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* 校验并归一化端点草稿(抛错的消息可直接展示给用户)。
|
|
160
|
+
* 草稿从渲染进程经 IPC 过来,属于跨进程边界,能力字段在这里过一遍枚举。
|
|
161
|
+
*/
|
|
162
|
+
export function validateDraft(draft) {
|
|
163
|
+
if (!NAME_PATTERN.test(draft.name)) {
|
|
164
|
+
throw new Error(`端点名「${draft.name}」非法:用小写字母、数字、下划线或短横线,以字母或数字开头`);
|
|
165
|
+
}
|
|
166
|
+
if (!/^https?:\/\/\S+$/.test(draft.baseUrl.trim())) {
|
|
167
|
+
throw new Error(`baseUrl「${draft.baseUrl}」非法:需要完整的 http(s) 地址,中间不能有空格`);
|
|
168
|
+
}
|
|
169
|
+
if (draft.models.length === 0)
|
|
170
|
+
throw new Error('至少填一个模型(模型 id 是请求里发的名字)');
|
|
171
|
+
for (const model of draft.models) {
|
|
172
|
+
if (model.id.trim() === '')
|
|
173
|
+
throw new Error('有模型的 id 是空的');
|
|
174
|
+
if (!Number.isFinite(model.contextWindow) || model.contextWindow <= 0) {
|
|
175
|
+
throw new Error(`模型 ${model.id} 的上下文窗口要是正整数(不知道就填 128000)`);
|
|
176
|
+
}
|
|
177
|
+
const caps = capsOf(model);
|
|
178
|
+
if (!THINKING_PARAMS.includes(caps.thinkingParam)) {
|
|
179
|
+
throw new Error(`模型 ${model.id} 的思考档位字段「${caps.thinkingParam}」不认识`);
|
|
180
|
+
}
|
|
181
|
+
for (const level of caps.thinkingLevels) {
|
|
182
|
+
if (!THINKING_LEVELS.includes(level))
|
|
183
|
+
throw new Error(`模型 ${model.id} 的思考档位「${level}」不认识`);
|
|
184
|
+
}
|
|
185
|
+
if (caps.thinkingParam !== 'none' && caps.thinkingLevels.length === 0) {
|
|
186
|
+
throw new Error(`模型 ${model.id} 没勾任何思考档位:要么勾一档,要么把档位字段选成「不发思考字段」`);
|
|
187
|
+
}
|
|
188
|
+
for (const modality of caps.modalities) {
|
|
189
|
+
if (!MODALITIES.includes(modality))
|
|
190
|
+
throw new Error(`模型 ${model.id} 的输入类型「${modality}」不认识`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/** 能力字段只在偏离缺省时写进 YAML,免得每次编辑都给每个模型挂一串默认值。 */
|
|
195
|
+
function toFileModel(model) {
|
|
196
|
+
const caps = capsOf(model);
|
|
197
|
+
const entry = {
|
|
198
|
+
id: model.id.trim(),
|
|
199
|
+
name: model.name.trim() === '' ? model.id.trim() : model.name.trim(),
|
|
200
|
+
contextWindow: Math.round(model.contextWindow),
|
|
201
|
+
maxTokens: model.maxTokens > 0 ? Math.round(model.maxTokens) : 8_192,
|
|
202
|
+
};
|
|
203
|
+
const levels = THINKING_LEVELS.filter((level) => caps.thinkingLevels.includes(level));
|
|
204
|
+
if (levels.join(',') !== DEFAULT_THINKING_LEVELS.join(','))
|
|
205
|
+
entry.thinkingLevels = levels;
|
|
206
|
+
const param = THINKING_PARAMS.includes(caps.thinkingParam) ? caps.thinkingParam : DEFAULT_THINKING_PARAM;
|
|
207
|
+
if (param !== DEFAULT_THINKING_PARAM)
|
|
208
|
+
entry.thinkingParam = param;
|
|
209
|
+
if (param === 'reasoning-effort') {
|
|
210
|
+
const map = {};
|
|
211
|
+
for (const level of levels) {
|
|
212
|
+
const value = caps.effortMap[level];
|
|
213
|
+
if (value !== undefined)
|
|
214
|
+
map[level] = value;
|
|
215
|
+
}
|
|
216
|
+
if (Object.keys(map).length > 0)
|
|
217
|
+
entry.effortMap = map;
|
|
218
|
+
}
|
|
219
|
+
const modalities = normalizeModalities(caps.modalities);
|
|
220
|
+
if (modalities.length > 1)
|
|
221
|
+
entry.modalities = modalities;
|
|
222
|
+
return entry;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* 写入端点新增/编辑/改名(同一 name 覆盖)。
|
|
226
|
+
* @returns 改名后的新名字。
|
|
227
|
+
*/
|
|
228
|
+
export function upsertProvider(oldName, draft) {
|
|
229
|
+
validateDraft(draft);
|
|
230
|
+
const doc = readConfigDoc();
|
|
231
|
+
const name = draft.name.trim();
|
|
232
|
+
if (oldName !== null && oldName !== name && doc.providers[name] !== undefined) {
|
|
233
|
+
throw new Error(`端点 ${name} 已存在,先改个名字或删除旧的`);
|
|
234
|
+
}
|
|
235
|
+
const existing = oldName === null ? undefined : doc.providers[oldName];
|
|
236
|
+
const keyRef = existing?.apiKeyEnv ?? `${name.toUpperCase()}_API_KEY`;
|
|
237
|
+
const provider = {
|
|
238
|
+
displayName: draft.displayName.trim() === '' ? name : draft.displayName.trim(),
|
|
239
|
+
baseURL: draft.baseUrl.trim().replace(/\/+$/, ''),
|
|
240
|
+
apiKeyEnv: keyRef,
|
|
241
|
+
models: draft.models.map(toFileModel),
|
|
242
|
+
};
|
|
243
|
+
if (oldName !== null && oldName !== name)
|
|
244
|
+
delete doc.providers[oldName];
|
|
245
|
+
doc.providers[name] = provider;
|
|
246
|
+
// 默认端点跟着改名走,否则启动时会退回第一个可用端点
|
|
247
|
+
if (oldName !== null && doc.default?.provider === oldName) {
|
|
248
|
+
doc.default = { provider: name, model: doc.default.model };
|
|
249
|
+
}
|
|
250
|
+
writeConfigDoc(doc);
|
|
251
|
+
return name;
|
|
252
|
+
}
|
|
253
|
+
/** 删除端点;默认端点被删时把 default 改指第一个可用端点。 */
|
|
254
|
+
export function deleteProvider(name) {
|
|
255
|
+
const doc = readConfigDoc();
|
|
256
|
+
if (doc.providers[name] === undefined)
|
|
257
|
+
throw new Error(`没有名为 ${name} 的端点`);
|
|
258
|
+
delete doc.providers[name];
|
|
259
|
+
const first = Object.keys(doc.providers)[0];
|
|
260
|
+
if (doc.default?.provider === name) {
|
|
261
|
+
doc.default =
|
|
262
|
+
first === undefined
|
|
263
|
+
? undefined
|
|
264
|
+
: { provider: first, model: doc.providers[first]?.models[0]?.id ?? '' };
|
|
265
|
+
}
|
|
266
|
+
writeConfigDoc(doc);
|
|
267
|
+
}
|
|
268
|
+
/** 写默认端点/模型。 */
|
|
269
|
+
export function writeDefaultModel(provider, model) {
|
|
270
|
+
const doc = readConfigDoc();
|
|
271
|
+
if (doc.providers[provider] === undefined)
|
|
272
|
+
throw new Error(`没有名为 ${provider} 的端点`);
|
|
273
|
+
if (!toModelViews(doc.providers[provider].models).some((entry) => entry.id === model)) {
|
|
274
|
+
throw new Error(`端点 ${provider} 没有模型 ${model}`);
|
|
275
|
+
}
|
|
276
|
+
doc.default = { provider, model };
|
|
277
|
+
writeConfigDoc(doc);
|
|
278
|
+
}
|
|
279
|
+
/** 写采样温度(null = 删除该字段,跟随端点默认)。 */
|
|
280
|
+
export function writeTemperature(temperature) {
|
|
281
|
+
const doc = readConfigDoc();
|
|
282
|
+
if (temperature === null)
|
|
283
|
+
delete doc.temperature;
|
|
284
|
+
else
|
|
285
|
+
doc.temperature = temperature;
|
|
286
|
+
writeConfigDoc(doc);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* 写入或清除端点的 API key(写 dsc 凭据库,并同步 process.env 让当前进程立即能用)。
|
|
290
|
+
* @returns 给用户看的一句结果说明。
|
|
291
|
+
*/
|
|
292
|
+
export function writeProviderKey(ref, apiKey) {
|
|
293
|
+
if (ref === '')
|
|
294
|
+
throw new Error('该端点没有声明 apiKeyEnv,无法定位 key 名');
|
|
295
|
+
if (apiKey === null) {
|
|
296
|
+
writeCredentialRef(ref, null);
|
|
297
|
+
return keyAvailable(ref)
|
|
298
|
+
? `已从 ${CREDENTIALS_FILE} 清除 ${ref},但本机环境变量仍提供它,运行期不受影响`
|
|
299
|
+
: `已清除 ${ref}`;
|
|
300
|
+
}
|
|
301
|
+
const value = apiKey.trim();
|
|
302
|
+
if (value === '')
|
|
303
|
+
throw new Error('API key 是空的');
|
|
304
|
+
writeCredentialRef(ref, value);
|
|
305
|
+
process.env[ref] = value;
|
|
306
|
+
return `已写入 ${ref}(${CREDENTIALS_FILE})`;
|
|
307
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type ModelCaps } from './model-caps.js';
|
|
2
|
+
/** 一个可对话的模型(能力声明见 core/model-caps.ts)。 */
|
|
3
|
+
export interface ModelInfo extends ModelCaps {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
contextWindow: number;
|
|
7
|
+
maxTokens: number;
|
|
8
|
+
}
|
|
9
|
+
/** 一个模型端点(线上协议由 `api` 选择,缺省 OpenAI 兼容;协议适配器见 llm 插件)。 */
|
|
10
|
+
export interface ProviderConfig {
|
|
11
|
+
name: string;
|
|
12
|
+
displayName: string;
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
apiKey: string;
|
|
15
|
+
/** 协议适配器 id;缺省 openai-completions。 */
|
|
16
|
+
api?: string;
|
|
17
|
+
/**
|
|
18
|
+
* 端点声明支持显式前缀缓存标记(内容块上的 `cache_control`)。
|
|
19
|
+
* 缺省 undefined = 不支持 = 请求体逐字节不变;见 core/llm.ts 的 `applyExplicitCache`。
|
|
20
|
+
*/
|
|
21
|
+
cacheControl?: boolean;
|
|
22
|
+
models: ModelInfo[];
|
|
23
|
+
}
|
|
24
|
+
/** 解析后的核心配置。 */
|
|
25
|
+
export interface DscCoreConfig {
|
|
26
|
+
providers: Record<string, ProviderConfig>;
|
|
27
|
+
defaultProvider: string;
|
|
28
|
+
defaultModel: string;
|
|
29
|
+
/** 采样参数覆盖(缺省用端点默认)。 */
|
|
30
|
+
temperature?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 读配置。缺配置时先尝试从 dsh 迁移;provider 全空时返回空表
|
|
34
|
+
* (boot 会把"没有可用端点"报给 UI,而不是崩溃)。
|
|
35
|
+
*/
|
|
36
|
+
export declare function readConfig(): DscCoreConfig;
|