@xyit/wellspring 0.0.0-stage → 1.1.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 +853 -2
- package/dist/agent/pending-asks.d.ts +20 -0
- package/dist/agent/pending-asks.js +70 -0
- package/dist/agent/pending-asks.js.map +1 -0
- package/dist/agent/task-registry.d.ts +14 -0
- package/dist/agent/task-registry.js +80 -0
- package/dist/agent/task-registry.js.map +1 -0
- package/dist/agent/tool-context.d.ts +30 -0
- package/dist/agent/tool-context.js +10 -0
- package/dist/agent/tool-context.js.map +1 -0
- package/dist/agent/usage.d.ts +40 -0
- package/dist/agent/usage.js +122 -0
- package/dist/agent/usage.js.map +1 -0
- package/dist/api/host/agent.d.ts +165 -0
- package/dist/api/host/agent.js +5 -0
- package/dist/api/host/agent.js.map +1 -0
- package/dist/api/host/events.d.ts +2 -0
- package/dist/api/host/events.js +6 -0
- package/dist/api/host/events.js.map +1 -0
- package/dist/api/host/exec.d.ts +36 -0
- package/dist/api/host/exec.js +10 -0
- package/dist/api/host/exec.js.map +1 -0
- package/dist/api/host/fs.d.ts +24 -0
- package/dist/api/host/fs.js +7 -0
- package/dist/api/host/fs.js.map +1 -0
- package/dist/api/host/hooks.d.ts +210 -0
- package/dist/api/host/hooks.js +401 -0
- package/dist/api/host/hooks.js.map +1 -0
- package/dist/api/host/host.d.ts +36 -0
- package/dist/api/host/host.js +53 -0
- package/dist/api/host/host.js.map +1 -0
- package/dist/api/host/http.d.ts +58 -0
- package/dist/api/host/http.js +6 -0
- package/dist/api/host/http.js.map +1 -0
- package/dist/api/host/index.d.ts +15 -0
- package/dist/api/host/index.js +20 -0
- package/dist/api/host/index.js.map +1 -0
- package/dist/api/host/models.d.ts +65 -0
- package/dist/api/host/models.js +8 -0
- package/dist/api/host/models.js.map +1 -0
- package/dist/api/host/network.d.ts +22 -0
- package/dist/api/host/network.js +7 -0
- package/dist/api/host/network.js.map +1 -0
- package/dist/api/host/plugin.d.ts +138 -0
- package/dist/api/host/plugin.js +6 -0
- package/dist/api/host/plugin.js.map +1 -0
- package/dist/api/host/plugins.d.ts +49 -0
- package/dist/api/host/plugins.js +6 -0
- package/dist/api/host/plugins.js.map +1 -0
- package/dist/api/host/pty.d.ts +55 -0
- package/dist/api/host/pty.js +21 -0
- package/dist/api/host/pty.js.map +1 -0
- package/dist/api/host/session.d.ts +5 -0
- package/dist/api/host/session.js +52 -0
- package/dist/api/host/session.js.map +1 -0
- package/dist/api/host/version.d.ts +2 -0
- package/dist/api/host/version.js +3 -0
- package/dist/api/host/version.js.map +1 -0
- package/dist/api/host/workspace.d.ts +38 -0
- package/dist/api/host/workspace.js +9 -0
- package/dist/api/host/workspace.js.map +1 -0
- package/dist/api/plugin/http-client.d.ts +42 -0
- package/dist/api/plugin/http-client.js +364 -0
- package/dist/api/plugin/http-client.js.map +1 -0
- package/dist/api/plugin/http-protocol.d.ts +152 -0
- package/dist/api/plugin/http-protocol.js +49 -0
- package/dist/api/plugin/http-protocol.js.map +1 -0
- package/dist/api/result/result.d.ts +16 -0
- package/dist/api/result/result.js +43 -0
- package/dist/api/result/result.js.map +1 -0
- package/dist/commands/agent-turn.d.ts +63 -0
- package/dist/commands/agent-turn.js +687 -0
- package/dist/commands/agent-turn.js.map +1 -0
- package/dist/commands/ask-prompt.d.ts +6 -0
- package/dist/commands/ask-prompt.js +49 -0
- package/dist/commands/ask-prompt.js.map +1 -0
- package/dist/commands/config.d.ts +2 -0
- package/dist/commands/config.js +283 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/conversation.d.ts +51 -0
- package/dist/commands/conversation.js +630 -0
- package/dist/commands/conversation.js.map +1 -0
- package/dist/commands/doctor.d.ts +2 -0
- package/dist/commands/doctor.js +77 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/exec-approval.d.ts +3 -0
- package/dist/commands/exec-approval.js +80 -0
- package/dist/commands/exec-approval.js.map +1 -0
- package/dist/commands/help.d.ts +2 -0
- package/dist/commands/help.js +35 -0
- package/dist/commands/help.js.map +1 -0
- package/dist/commands/key.d.ts +2 -0
- package/dist/commands/key.js +226 -0
- package/dist/commands/key.js.map +1 -0
- package/dist/commands/plugin.d.ts +2 -0
- package/dist/commands/plugin.js +190 -0
- package/dist/commands/plugin.js.map +1 -0
- package/dist/commands/session.d.ts +2 -0
- package/dist/commands/session.js +167 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/commands/shared.d.ts +35 -0
- package/dist/commands/shared.js +66 -0
- package/dist/commands/shared.js.map +1 -0
- package/dist/commands/start.d.ts +2 -0
- package/dist/commands/start.js +75 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/stop.d.ts +2 -0
- package/dist/commands/stop.js +24 -0
- package/dist/commands/stop.js.map +1 -0
- package/dist/commands/version.d.ts +2 -0
- package/dist/commands/version.js +33 -0
- package/dist/commands/version.js.map +1 -0
- package/dist/config/codes.d.ts +13 -0
- package/dist/config/codes.js +15 -0
- package/dist/config/codes.js.map +1 -0
- package/dist/config/credentials.d.ts +67 -0
- package/dist/config/credentials.js +214 -0
- package/dist/config/credentials.js.map +1 -0
- package/dist/config/defaults.d.ts +5 -0
- package/dist/config/defaults.js +31 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.js +10 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +10 -0
- package/dist/config/loader.js +68 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/providers.d.ts +30 -0
- package/dist/config/providers.js +97 -0
- package/dist/config/providers.js.map +1 -0
- package/dist/config/types.d.ts +75 -0
- package/dist/config/types.js +4 -0
- package/dist/config/types.js.map +1 -0
- package/dist/config/validate.d.ts +4 -0
- package/dist/config/validate.js +391 -0
- package/dist/config/validate.js.map +1 -0
- package/dist/display/markdown.d.ts +7 -0
- package/dist/display/markdown.js +116 -0
- package/dist/display/markdown.js.map +1 -0
- package/dist/display/tool-label.d.ts +6 -0
- package/dist/display/tool-label.js +81 -0
- package/dist/display/tool-label.js.map +1 -0
- package/dist/event/event.d.ts +27 -0
- package/dist/event/event.js +152 -0
- package/dist/event/event.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +308 -0
- package/dist/index.js.map +1 -0
- package/dist/input/codes.d.ts +15 -0
- package/dist/input/codes.js +20 -0
- package/dist/input/codes.js.map +1 -0
- package/dist/input/commands.d.ts +10 -0
- package/dist/input/commands.js +65 -0
- package/dist/input/commands.js.map +1 -0
- package/dist/input/help.d.ts +8 -0
- package/dist/input/help.js +51 -0
- package/dist/input/help.js.map +1 -0
- package/dist/input/index.d.ts +6 -0
- package/dist/input/index.js +10 -0
- package/dist/input/index.js.map +1 -0
- package/dist/input/parse-options.d.ts +11 -0
- package/dist/input/parse-options.js +51 -0
- package/dist/input/parse-options.js.map +1 -0
- package/dist/input/parse.d.ts +3 -0
- package/dist/input/parse.js +119 -0
- package/dist/input/parse.js.map +1 -0
- package/dist/input/types.d.ts +17 -0
- package/dist/input/types.js +2 -0
- package/dist/input/types.js.map +1 -0
- package/dist/logger/elog4js.d.ts +65 -0
- package/dist/logger/elog4js.js +305 -0
- package/dist/logger/elog4js.js.map +1 -0
- package/dist/logger/logger.d.ts +37 -0
- package/dist/logger/logger.js +196 -0
- package/dist/logger/logger.js.map +1 -0
- package/dist/network/index.d.ts +2 -0
- package/dist/network/index.js +6 -0
- package/dist/network/index.js.map +1 -0
- package/dist/network/openai.d.ts +117 -0
- package/dist/network/openai.js +443 -0
- package/dist/network/openai.js.map +1 -0
- package/dist/network/proxy.d.ts +9 -0
- package/dist/network/proxy.js +72 -0
- package/dist/network/proxy.js.map +1 -0
- package/dist/network/web.d.ts +34 -0
- package/dist/network/web.js +152 -0
- package/dist/network/web.js.map +1 -0
- package/dist/platform/clipboard.d.ts +15 -0
- package/dist/platform/clipboard.js +82 -0
- package/dist/platform/clipboard.js.map +1 -0
- package/dist/platform/exec.d.ts +28 -0
- package/dist/platform/exec.js +95 -0
- package/dist/platform/exec.js.map +1 -0
- package/dist/platform/file.d.ts +38 -0
- package/dist/platform/file.js +197 -0
- package/dist/platform/file.js.map +1 -0
- package/dist/platform/index.d.ts +7 -0
- package/dist/platform/index.js +12 -0
- package/dist/platform/index.js.map +1 -0
- package/dist/platform/notification.d.ts +14 -0
- package/dist/platform/notification.js +82 -0
- package/dist/platform/notification.js.map +1 -0
- package/dist/platform/open-external.d.ts +10 -0
- package/dist/platform/open-external.js +105 -0
- package/dist/platform/open-external.js.map +1 -0
- package/dist/platform/os.d.ts +20 -0
- package/dist/platform/os.js +86 -0
- package/dist/platform/os.js.map +1 -0
- package/dist/platform/path.d.ts +32 -0
- package/dist/platform/path.js +154 -0
- package/dist/platform/path.js.map +1 -0
- package/dist/plugin/access-guard.d.ts +1 -0
- package/dist/plugin/access-guard.js +40 -0
- package/dist/plugin/access-guard.js.map +1 -0
- package/dist/plugin/agent-service.d.ts +25 -0
- package/dist/plugin/agent-service.js +809 -0
- package/dist/plugin/agent-service.js.map +1 -0
- package/dist/plugin/agent-tools.d.ts +12 -0
- package/dist/plugin/agent-tools.js +31 -0
- package/dist/plugin/agent-tools.js.map +1 -0
- package/dist/plugin/capabilities.d.ts +26 -0
- package/dist/plugin/capabilities.js +192 -0
- package/dist/plugin/capabilities.js.map +1 -0
- package/dist/plugin/console-guard.d.ts +2 -0
- package/dist/plugin/console-guard.js +52 -0
- package/dist/plugin/console-guard.js.map +1 -0
- package/dist/plugin/data-access.d.ts +15 -0
- package/dist/plugin/data-access.js +57 -0
- package/dist/plugin/data-access.js.map +1 -0
- package/dist/plugin/fs.d.ts +3 -0
- package/dist/plugin/fs.js +93 -0
- package/dist/plugin/fs.js.map +1 -0
- package/dist/plugin/host-alias.d.ts +2 -0
- package/dist/plugin/host-alias.js +57 -0
- package/dist/plugin/host-alias.js.map +1 -0
- package/dist/plugin/index.d.ts +7 -0
- package/dist/plugin/index.js +11 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/install.d.ts +17 -0
- package/dist/plugin/install.js +163 -0
- package/dist/plugin/install.js.map +1 -0
- package/dist/plugin/loader.d.ts +45 -0
- package/dist/plugin/loader.js +739 -0
- package/dist/plugin/loader.js.map +1 -0
- package/dist/plugin/manage.d.ts +31 -0
- package/dist/plugin/manage.js +271 -0
- package/dist/plugin/manage.js.map +1 -0
- package/dist/plugin/models-service.d.ts +15 -0
- package/dist/plugin/models-service.js +317 -0
- package/dist/plugin/models-service.js.map +1 -0
- package/dist/plugin/network-service.d.ts +10 -0
- package/dist/plugin/network-service.js +87 -0
- package/dist/plugin/network-service.js.map +1 -0
- package/dist/plugin/package-manager.d.ts +46 -0
- package/dist/plugin/package-manager.js +148 -0
- package/dist/plugin/package-manager.js.map +1 -0
- package/dist/plugin/paths.d.ts +6 -0
- package/dist/plugin/paths.js +15 -0
- package/dist/plugin/paths.js.map +1 -0
- package/dist/plugin/registry.d.ts +17 -0
- package/dist/plugin/registry.js +82 -0
- package/dist/plugin/registry.js.map +1 -0
- package/dist/plugin/runtime.d.ts +9 -0
- package/dist/plugin/runtime.js +43 -0
- package/dist/plugin/runtime.js.map +1 -0
- package/dist/plugin/scaffold.d.ts +13 -0
- package/dist/plugin/scaffold.js +132 -0
- package/dist/plugin/scaffold.js.map +1 -0
- package/dist/plugin/state.d.ts +6 -0
- package/dist/plugin/state.js +38 -0
- package/dist/plugin/state.js.map +1 -0
- package/dist/plugin/zip.d.ts +7 -0
- package/dist/plugin/zip.js +138 -0
- package/dist/plugin/zip.js.map +1 -0
- package/dist/sandbox/audit.d.ts +12 -0
- package/dist/sandbox/audit.js +20 -0
- package/dist/sandbox/audit.js.map +1 -0
- package/dist/sandbox/backends/bwrap.d.ts +28 -0
- package/dist/sandbox/backends/bwrap.js +197 -0
- package/dist/sandbox/backends/bwrap.js.map +1 -0
- package/dist/sandbox/backends/direct.d.ts +7 -0
- package/dist/sandbox/backends/direct.js +32 -0
- package/dist/sandbox/backends/direct.js.map +1 -0
- package/dist/sandbox/bridge-state.d.ts +13 -0
- package/dist/sandbox/bridge-state.js +12 -0
- package/dist/sandbox/bridge-state.js.map +1 -0
- package/dist/sandbox/index.d.ts +5 -0
- package/dist/sandbox/index.js +6 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/manager.d.ts +8 -0
- package/dist/sandbox/manager.js +325 -0
- package/dist/sandbox/manager.js.map +1 -0
- package/dist/sandbox/memory-limit.d.ts +44 -0
- package/dist/sandbox/memory-limit.js +193 -0
- package/dist/sandbox/memory-limit.js.map +1 -0
- package/dist/sandbox/plugin-client.d.ts +80 -0
- package/dist/sandbox/plugin-client.js +1601 -0
- package/dist/sandbox/plugin-client.js.map +1 -0
- package/dist/sandbox/plugin-host.d.ts +1 -0
- package/dist/sandbox/plugin-host.js +1001 -0
- package/dist/sandbox/plugin-host.js.map +1 -0
- package/dist/sandbox/protocol.d.ts +43 -0
- package/dist/sandbox/protocol.js +96 -0
- package/dist/sandbox/protocol.js.map +1 -0
- package/dist/sandbox/rpc-timeouts.d.ts +28 -0
- package/dist/sandbox/rpc-timeouts.js +15 -0
- package/dist/sandbox/rpc-timeouts.js.map +1 -0
- package/dist/sandbox/supervisor.d.ts +31 -0
- package/dist/sandbox/supervisor.js +114 -0
- package/dist/sandbox/supervisor.js.map +1 -0
- package/dist/sandbox/types.d.ts +124 -0
- package/dist/sandbox/types.js +17 -0
- package/dist/sandbox/types.js.map +1 -0
- package/dist/service/control.d.ts +32 -0
- package/dist/service/control.js +117 -0
- package/dist/service/control.js.map +1 -0
- package/dist/session/compress.d.ts +3 -0
- package/dist/session/compress.js +42 -0
- package/dist/session/compress.js.map +1 -0
- package/dist/session/index.d.ts +4 -0
- package/dist/session/index.js +8 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/registry.d.ts +4 -0
- package/dist/session/registry.js +12 -0
- package/dist/session/registry.js.map +1 -0
- package/dist/session/replay.d.ts +10 -0
- package/dist/session/replay.js +109 -0
- package/dist/session/replay.js.map +1 -0
- package/dist/session/session.d.ts +40 -0
- package/dist/session/session.js +108 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/store.d.ts +58 -0
- package/dist/session/store.js +382 -0
- package/dist/session/store.js.map +1 -0
- package/dist/session/types.d.ts +56 -0
- package/dist/session/types.js +3 -0
- package/dist/session/types.js.map +1 -0
- package/dist/workspace/index.d.ts +7 -0
- package/dist/workspace/index.js +17 -0
- package/dist/workspace/index.js.map +1 -0
- package/dist/workspace/registry.d.ts +25 -0
- package/dist/workspace/registry.js +293 -0
- package/dist/workspace/registry.js.map +1 -0
- package/package.json +73 -5
- package/scripts/build-node-pty.mjs +55 -0
- package/scripts/rewrite-dts.mjs +36 -0
- package/scripts/run-tests.mjs +41 -0
- package/scripts/verify-sandbox.ts +98 -0
- package/src/agent/pending-asks.ts +88 -0
- package/src/agent/task-registry.ts +108 -0
- package/src/agent/tool-context.ts +47 -0
- package/src/agent/usage.ts +170 -0
- package/src/api/host/agent.ts +162 -0
- package/src/api/host/events.ts +7 -0
- package/src/api/host/exec.ts +47 -0
- package/src/api/host/fs.ts +33 -0
- package/src/api/host/hooks.ts +635 -0
- package/src/api/host/host.ts +99 -0
- package/src/api/host/http.ts +79 -0
- package/src/api/host/index.ts +20 -0
- package/src/api/host/models.ts +81 -0
- package/src/api/host/network.ts +32 -0
- package/src/api/host/plugin.ts +158 -0
- package/src/api/host/plugins.ts +59 -0
- package/src/api/host/pty.ts +73 -0
- package/src/api/host/session.ts +61 -0
- package/src/api/host/version.ts +2 -0
- package/src/api/host/workspace.ts +51 -0
- package/src/api/plugin/http-client.ts +492 -0
- package/src/api/plugin/http-protocol.ts +231 -0
- package/src/api/result/result.ts +52 -0
- package/src/commands/agent-turn.ts +817 -0
- package/src/commands/ask-prompt.ts +52 -0
- package/src/commands/config.ts +306 -0
- package/src/commands/conversation.ts +777 -0
- package/src/commands/doctor.ts +92 -0
- package/src/commands/exec-approval.ts +91 -0
- package/src/commands/help.ts +41 -0
- package/src/commands/key.ts +281 -0
- package/src/commands/plugin.ts +222 -0
- package/src/commands/session.ts +179 -0
- package/src/commands/shared.ts +103 -0
- package/src/commands/start.ts +88 -0
- package/src/commands/stop.ts +24 -0
- package/src/commands/version.ts +40 -0
- package/src/config/codes.ts +17 -0
- package/src/config/credentials.ts +302 -0
- package/src/config/defaults.ts +32 -0
- package/src/config/index.ts +10 -0
- package/src/config/loader.ts +80 -0
- package/src/config/providers.ts +133 -0
- package/src/config/types.ts +88 -0
- package/src/config/validate.ts +458 -0
- package/src/display/markdown.ts +137 -0
- package/src/display/tool-label.ts +87 -0
- package/src/event/event.ts +171 -0
- package/src/index.ts +344 -0
- package/src/input/codes.ts +21 -0
- package/src/input/commands.ts +76 -0
- package/src/input/help.ts +60 -0
- package/src/input/index.ts +10 -0
- package/src/input/parse-options.ts +66 -0
- package/src/input/parse.ts +138 -0
- package/src/input/types.ts +19 -0
- package/src/logger/elog4js.ts +366 -0
- package/src/logger/logger.ts +251 -0
- package/src/network/index.ts +6 -0
- package/src/network/openai.ts +571 -0
- package/src/network/proxy.ts +80 -0
- package/src/network/web.ts +206 -0
- package/src/platform/clipboard.ts +107 -0
- package/src/platform/exec.ts +128 -0
- package/src/platform/file.ts +235 -0
- package/src/platform/index.ts +12 -0
- package/src/platform/notification.ts +108 -0
- package/src/platform/open-external.ts +132 -0
- package/src/platform/os.ts +101 -0
- package/src/platform/path.ts +214 -0
- package/src/plugin/access-guard.ts +46 -0
- package/src/plugin/agent-service.ts +969 -0
- package/src/plugin/agent-tools.ts +43 -0
- package/src/plugin/capabilities.ts +240 -0
- package/src/plugin/console-guard.ts +66 -0
- package/src/plugin/data-access.ts +70 -0
- package/src/plugin/fs.ts +109 -0
- package/src/plugin/host-alias.ts +61 -0
- package/src/plugin/index.ts +11 -0
- package/src/plugin/install.ts +213 -0
- package/src/plugin/loader.ts +952 -0
- package/src/plugin/manage.ts +338 -0
- package/src/plugin/models-service.ts +383 -0
- package/src/plugin/network-service.ts +102 -0
- package/src/plugin/package-manager.ts +214 -0
- package/src/plugin/paths.ts +19 -0
- package/src/plugin/registry.ts +103 -0
- package/src/plugin/runtime.ts +57 -0
- package/src/plugin/scaffold.ts +158 -0
- package/src/plugin/state.ts +52 -0
- package/src/plugin/zip.ts +156 -0
- package/src/sandbox/audit.ts +38 -0
- package/src/sandbox/backends/bwrap.ts +251 -0
- package/src/sandbox/backends/direct.ts +43 -0
- package/src/sandbox/bridge-state.ts +29 -0
- package/src/sandbox/index.ts +5 -0
- package/src/sandbox/manager.ts +406 -0
- package/src/sandbox/memory-limit.ts +245 -0
- package/src/sandbox/plugin-client.ts +1881 -0
- package/src/sandbox/plugin-host.ts +1282 -0
- package/src/sandbox/protocol.ts +142 -0
- package/src/sandbox/pty-bridge.py +154 -0
- package/src/sandbox/rpc-timeouts.ts +43 -0
- package/src/sandbox/supervisor.ts +172 -0
- package/src/sandbox/types.ts +149 -0
- package/src/service/control.ts +155 -0
- package/src/session/compress.ts +47 -0
- package/src/session/index.ts +8 -0
- package/src/session/registry.ts +17 -0
- package/src/session/replay.ts +132 -0
- package/src/session/session.ts +134 -0
- package/src/session/store.ts +468 -0
- package/src/session/types.ts +61 -0
- package/src/workspace/index.ts +21 -0
- package/src/workspace/registry.ts +356 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* doctor:环境与配置诊断。
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { existsSync } from "node:fs"
|
|
6
|
+
|
|
7
|
+
import { apiKeyStatusSync, credentialsFile } from "../config/credentials.ts"
|
|
8
|
+
import { describePaths, platform } from "../platform/index.ts"
|
|
9
|
+
import { SandboxManager } from "../sandbox/manager.ts"
|
|
10
|
+
import { success, type CommandContext, type CommandOutcome } from "./shared.ts"
|
|
11
|
+
|
|
12
|
+
interface Check {
|
|
13
|
+
readonly name: string
|
|
14
|
+
readonly ok: boolean
|
|
15
|
+
readonly detail: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function runDoctorCommand(ctx: CommandContext): Promise<CommandOutcome> {
|
|
19
|
+
const checks: Check[] = []
|
|
20
|
+
const major = Number(process.versions.node.split(".")[0])
|
|
21
|
+
checks.push({ name: "node", ok: major >= 24, detail: process.versions.node })
|
|
22
|
+
checks.push({ name: "platform", ok: true, detail: platform })
|
|
23
|
+
checks.push({
|
|
24
|
+
name: "paths",
|
|
25
|
+
ok: true,
|
|
26
|
+
detail: describePaths(ctx.paths).replaceAll("\n", " | "),
|
|
27
|
+
})
|
|
28
|
+
checks.push({
|
|
29
|
+
name: "config",
|
|
30
|
+
ok: ctx.configCode === null,
|
|
31
|
+
detail: ctx.configCode ?? ctx.settingsFile,
|
|
32
|
+
})
|
|
33
|
+
const keyStatus = apiKeyStatusSync(credentialsFile(ctx.paths.configDir))
|
|
34
|
+
const keySource =
|
|
35
|
+
keyStatus.source === "env"
|
|
36
|
+
? "OPENAI_API_KEY"
|
|
37
|
+
: keyStatus.source === "credentials"
|
|
38
|
+
? keyStatus.file
|
|
39
|
+
: null
|
|
40
|
+
checks.push({
|
|
41
|
+
name: "openai-key",
|
|
42
|
+
ok: keyStatus.configured,
|
|
43
|
+
detail:
|
|
44
|
+
keySource === null
|
|
45
|
+
? "未配置(wellspring key set 或 OPENAI_API_KEY)"
|
|
46
|
+
: `${keySource} ${keyStatus.masked ?? ""}`.trim(),
|
|
47
|
+
})
|
|
48
|
+
checks.push({
|
|
49
|
+
name: "openai",
|
|
50
|
+
ok: ctx.openai !== null,
|
|
51
|
+
detail:
|
|
52
|
+
ctx.openai === null
|
|
53
|
+
? "客户端未就绪"
|
|
54
|
+
: `${ctx.activeProvider ?? "openai"} / ${ctx.activeModel ?? ctx.settings.openai.model}`,
|
|
55
|
+
})
|
|
56
|
+
checks.push({
|
|
57
|
+
name: "proxy",
|
|
58
|
+
ok: true,
|
|
59
|
+
detail: ctx.settings.network.proxy?.url ?? "直连",
|
|
60
|
+
})
|
|
61
|
+
checks.push({
|
|
62
|
+
name: "log-file",
|
|
63
|
+
ok: existsSync(ctx.paths.logDir),
|
|
64
|
+
detail: ctx.paths.logDir,
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
const sandboxProbe = await new SandboxManager({
|
|
68
|
+
settings: ctx.settings.sandbox,
|
|
69
|
+
paths: ctx.paths,
|
|
70
|
+
}).probe()
|
|
71
|
+
const sandboxOk = ctx.settings.sandbox.mode !== "strict" || sandboxProbe.available
|
|
72
|
+
checks.push({
|
|
73
|
+
name: "sandbox",
|
|
74
|
+
ok: sandboxOk,
|
|
75
|
+
detail: `${ctx.settings.sandbox.mode}/${sandboxProbe.backend}/${ctx.settings.sandbox.access}${sandboxProbe.available ? "" : `:${sandboxProbe.reason ?? "不可用"}`}`,
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
const plugins = await ctx.loadPlugins()
|
|
79
|
+
const disabled = plugins.filter((plugin) => plugin.status === "disabled").length
|
|
80
|
+
checks.push({
|
|
81
|
+
name: "plugins",
|
|
82
|
+
ok: plugins.every((plugin) => plugin.status !== "failed"),
|
|
83
|
+
detail: `${plugins.length} 个${disabled > 0 ? `(禁用 ${disabled})` : ""}`,
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
for (const check of checks) {
|
|
87
|
+
const tag = check.ok ? "[ OK ]" : "[FAIL ]"
|
|
88
|
+
ctx.elog.print(`${tag} ${check.name.padEnd(10)} ${check.detail}`)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return success({ checks })
|
|
92
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// execute_code 交互审批
|
|
2
|
+
|
|
3
|
+
import { emitKeypressEvents } from "node:readline"
|
|
4
|
+
|
|
5
|
+
import type { ExecApprovalRequest } from "./agent-turn.ts"
|
|
6
|
+
|
|
7
|
+
// 是否批准
|
|
8
|
+
export function isExecApprovalYes(answer: string): boolean {
|
|
9
|
+
const text = answer.trim().toLowerCase()
|
|
10
|
+
return text === "y" || text === "yes"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// 选项渲染
|
|
14
|
+
function renderChoice(selected: number): void {
|
|
15
|
+
const options = ["[允许]", "[拒绝]"]
|
|
16
|
+
const color =
|
|
17
|
+
process.stdout.isTTY === true &&
|
|
18
|
+
process.env["NO_COLOR"] === undefined &&
|
|
19
|
+
process.env["TERM"] !== "dumb"
|
|
20
|
+
const rendered = options
|
|
21
|
+
.map((option, index) => {
|
|
22
|
+
if (index !== selected) {
|
|
23
|
+
return option
|
|
24
|
+
}
|
|
25
|
+
return color ? `\x1b[7m${option}\x1b[0m` : `>${option}`
|
|
26
|
+
})
|
|
27
|
+
.join(" ")
|
|
28
|
+
process.stdout.write(`\r\x1b[2K是否允许?${rendered} ←/→ 切换 · Enter 确认`)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 终端逐次审批
|
|
32
|
+
export async function promptExecApproval(_request: ExecApprovalRequest): Promise<boolean> {
|
|
33
|
+
if (process.stdin.isTTY !== true || process.stdout.isTTY !== true) {
|
|
34
|
+
return false
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const stdin = process.stdin
|
|
38
|
+
const wasRaw = stdin.isRaw === true
|
|
39
|
+
stdin.setRawMode(true)
|
|
40
|
+
stdin.resume()
|
|
41
|
+
emitKeypressEvents(stdin)
|
|
42
|
+
|
|
43
|
+
let selected = 1
|
|
44
|
+
renderChoice(selected)
|
|
45
|
+
|
|
46
|
+
return await new Promise<boolean>((resolve) => {
|
|
47
|
+
const finish = (value: boolean): void => {
|
|
48
|
+
stdin.off("keypress", onKeypress)
|
|
49
|
+
if (!wasRaw) {
|
|
50
|
+
stdin.setRawMode(false)
|
|
51
|
+
}
|
|
52
|
+
stdin.pause()
|
|
53
|
+
process.stdout.write("\n")
|
|
54
|
+
resolve(value)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const onKeypress = (_text: string, key: { name?: string; ctrl?: boolean }): void => {
|
|
58
|
+
switch (key.name) {
|
|
59
|
+
case "left":
|
|
60
|
+
case "right":
|
|
61
|
+
case "tab":
|
|
62
|
+
selected = selected === 0 ? 1 : 0
|
|
63
|
+
renderChoice(selected)
|
|
64
|
+
return
|
|
65
|
+
case "return":
|
|
66
|
+
case "enter":
|
|
67
|
+
finish(selected === 0)
|
|
68
|
+
return
|
|
69
|
+
case "escape":
|
|
70
|
+
finish(false)
|
|
71
|
+
return
|
|
72
|
+
case "y":
|
|
73
|
+
selected = 0
|
|
74
|
+
renderChoice(selected)
|
|
75
|
+
finish(true)
|
|
76
|
+
return
|
|
77
|
+
case "n":
|
|
78
|
+
selected = 1
|
|
79
|
+
renderChoice(selected)
|
|
80
|
+
finish(false)
|
|
81
|
+
return
|
|
82
|
+
default:
|
|
83
|
+
if (key.ctrl === true && key.name === "c") {
|
|
84
|
+
finish(false)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
stdin.on("keypress", onKeypress)
|
|
90
|
+
})
|
|
91
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* help:内置命令 + 已注册插件命令。
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Result } from "../api/result/result.ts"
|
|
6
|
+
import { USAGE_CODES } from "../input/codes.ts"
|
|
7
|
+
import { BUILTIN_COMMANDS } from "../input/commands.ts"
|
|
8
|
+
import { formatCommandHelp, formatGlobalHelp, type HelpPluginCommand } from "../input/help.ts"
|
|
9
|
+
import { failure, success, type CommandContext, type CommandOutcome } from "./shared.ts"
|
|
10
|
+
|
|
11
|
+
export async function runHelpCommand(
|
|
12
|
+
ctx: CommandContext,
|
|
13
|
+
argv: readonly string[],
|
|
14
|
+
): Promise<CommandOutcome> {
|
|
15
|
+
await ctx.loadPlugins()
|
|
16
|
+
const pluginCommands: HelpPluginCommand[] = ctx.registry.list().map((record) => ({
|
|
17
|
+
name: record.command.name,
|
|
18
|
+
summary: record.command.summary,
|
|
19
|
+
usage: record.command.usage ?? `wellspring ${record.command.name}`,
|
|
20
|
+
plugin: record.pluginName,
|
|
21
|
+
}))
|
|
22
|
+
|
|
23
|
+
const builtins = BUILTIN_COMMANDS.map((spec) => ({
|
|
24
|
+
name: spec.name,
|
|
25
|
+
summary: spec.summary,
|
|
26
|
+
usage: spec.usage,
|
|
27
|
+
}))
|
|
28
|
+
const target = argv[0]
|
|
29
|
+
if (target === undefined) {
|
|
30
|
+
ctx.elog.print(formatGlobalHelp(pluginCommands))
|
|
31
|
+
return success({ builtins, plugins: pluginCommands })
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const plugin = pluginCommands.find((command) => command.name === target)
|
|
35
|
+
const text = formatCommandHelp(target, plugin)
|
|
36
|
+
if (text === null) {
|
|
37
|
+
return failure(`${USAGE_CODES.unknownCommand}:${target}`)
|
|
38
|
+
}
|
|
39
|
+
ctx.elog.print(text)
|
|
40
|
+
return success({ command: target })
|
|
41
|
+
}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* key 命令:查看 / 设置 / 清除 / 测试模型供应商的 API Key。
|
|
3
|
+
*
|
|
4
|
+
* 默认操作当前生效供应商;--provider 可指定其他供应商。
|
|
5
|
+
* 明文 key 只写入 <configDir>/credentials.json(0600),输出一律用掩码;
|
|
6
|
+
* 无参数时交互式输入或从 stdin 读取,避免进 shell 历史。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { Result } from "../api/result/result.ts"
|
|
10
|
+
import { CONFIG_CODES } from "../config/codes.ts"
|
|
11
|
+
import {
|
|
12
|
+
clearProviderApiKey,
|
|
13
|
+
credentialsFile,
|
|
14
|
+
normalizeApiKey,
|
|
15
|
+
providerKeyStatusSync,
|
|
16
|
+
resolveProviderApiKeySync,
|
|
17
|
+
saveProviderApiKey,
|
|
18
|
+
type ProviderKeyStatus,
|
|
19
|
+
} from "../config/credentials.ts"
|
|
20
|
+
import {
|
|
21
|
+
activeModelProvider,
|
|
22
|
+
findModelProvider,
|
|
23
|
+
providerOpenAISettings,
|
|
24
|
+
type ResolvedModelProvider,
|
|
25
|
+
} from "../config/providers.ts"
|
|
26
|
+
import { USAGE_CODES } from "../input/codes.ts"
|
|
27
|
+
import { parseCommandArgs } from "../input/parse-options.ts"
|
|
28
|
+
import { OpenAIClient } from "../network/openai.ts"
|
|
29
|
+
import { createProxyFetch } from "../network/proxy.ts"
|
|
30
|
+
import { failure, success, type CommandContext, type CommandOutcome } from "./shared.ts"
|
|
31
|
+
|
|
32
|
+
const MAX_STDIN_CHARS = 8192
|
|
33
|
+
|
|
34
|
+
function sourceLabel(status: ProviderKeyStatus): string {
|
|
35
|
+
if (status.source === "env") {
|
|
36
|
+
return `环境变量 ${status.envVar ?? ""}`.trim()
|
|
37
|
+
}
|
|
38
|
+
if (status.source === "credentials") {
|
|
39
|
+
return `本地凭据 ${status.file}`
|
|
40
|
+
}
|
|
41
|
+
return "未配置"
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function printStatus(
|
|
45
|
+
ctx: CommandContext,
|
|
46
|
+
provider: ResolvedModelProvider,
|
|
47
|
+
status: ProviderKeyStatus,
|
|
48
|
+
): void {
|
|
49
|
+
ctx.elog.print(`供应商: ${provider.name}(${provider.id})`)
|
|
50
|
+
ctx.elog.print(`来源: ${sourceLabel(status)}`)
|
|
51
|
+
if (status.masked !== null) {
|
|
52
|
+
ctx.elog.print(`Key: ${status.masked}`)
|
|
53
|
+
}
|
|
54
|
+
if (status.source === "env") {
|
|
55
|
+
ctx.elog.print(`提示: 环境变量 ${status.envVar ?? ""} 优先生效,本地保存的 key 会被忽略`)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** key 默认操作当前生效供应商 */
|
|
60
|
+
function targetProvider(
|
|
61
|
+
ctx: CommandContext,
|
|
62
|
+
providerId: string | undefined,
|
|
63
|
+
): ResolvedModelProvider {
|
|
64
|
+
if (providerId === undefined || providerId.trim() === "") {
|
|
65
|
+
return activeModelProvider(ctx.settings)
|
|
66
|
+
}
|
|
67
|
+
const found = findModelProvider(ctx.settings, providerId.trim())
|
|
68
|
+
if (found === null) {
|
|
69
|
+
throw new Error(`models.provider-not-found:${providerId}`)
|
|
70
|
+
}
|
|
71
|
+
return found
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** 管道 / 重定向:从 stdin 读 key,适合脚本与 CI */
|
|
75
|
+
async function readKeyFromStdin(): Promise<string | null> {
|
|
76
|
+
if (process.stdin.isTTY === true) {
|
|
77
|
+
return null
|
|
78
|
+
}
|
|
79
|
+
process.stdin.setEncoding("utf8")
|
|
80
|
+
let text = ""
|
|
81
|
+
for await (const chunk of process.stdin) {
|
|
82
|
+
text += String(chunk)
|
|
83
|
+
if (text.length > MAX_STDIN_CHARS) {
|
|
84
|
+
break
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return text.trim()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** 交互式隐藏输入:只回显星号,避免明文留在终端回滚与 shell 历史 */
|
|
91
|
+
function promptHiddenApiKey(prompt: string): Promise<string | null> {
|
|
92
|
+
const stdin = process.stdin
|
|
93
|
+
if (stdin.isTTY !== true) {
|
|
94
|
+
return Promise.resolve(null)
|
|
95
|
+
}
|
|
96
|
+
const wasRaw = stdin.isRaw === true
|
|
97
|
+
process.stderr.write(prompt)
|
|
98
|
+
stdin.setRawMode(true)
|
|
99
|
+
stdin.resume()
|
|
100
|
+
stdin.setEncoding("utf8")
|
|
101
|
+
return new Promise((resolvePromise) => {
|
|
102
|
+
let text = ""
|
|
103
|
+
let settled = false
|
|
104
|
+
const finish = (value: string | null): void => {
|
|
105
|
+
if (settled) {
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
settled = true
|
|
109
|
+
stdin.off("data", onData)
|
|
110
|
+
if (wasRaw !== true) {
|
|
111
|
+
stdin.setRawMode(false)
|
|
112
|
+
}
|
|
113
|
+
stdin.pause()
|
|
114
|
+
process.stderr.write("\n")
|
|
115
|
+
resolvePromise(value)
|
|
116
|
+
}
|
|
117
|
+
const onData = (chunk: string): void => {
|
|
118
|
+
for (const char of chunk) {
|
|
119
|
+
if (char === "\r" || char === "\n") {
|
|
120
|
+
finish(text.trim() === "" ? null : text.trim())
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
if (char === "\u0003" || char === "\u0004") {
|
|
124
|
+
finish(null)
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
if (char === "\u007f" || char === "\b") {
|
|
128
|
+
if (text.length > 0) {
|
|
129
|
+
text = text.slice(0, -1)
|
|
130
|
+
process.stderr.write("\b \b")
|
|
131
|
+
}
|
|
132
|
+
continue
|
|
133
|
+
}
|
|
134
|
+
text += char
|
|
135
|
+
process.stderr.write("*")
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
stdin.on("data", onData)
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function keyStatusOf(ctx: CommandContext, provider: ResolvedModelProvider): ProviderKeyStatus {
|
|
143
|
+
return providerKeyStatusSync(
|
|
144
|
+
{ id: provider.id, apiKeyEnv: provider.apiKeyEnv },
|
|
145
|
+
credentialsFile(ctx.paths.configDir),
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function runTest(
|
|
150
|
+
ctx: CommandContext,
|
|
151
|
+
provider: ResolvedModelProvider,
|
|
152
|
+
candidate: string | undefined,
|
|
153
|
+
): Promise<CommandOutcome> {
|
|
154
|
+
const file = credentialsFile(ctx.paths.configDir)
|
|
155
|
+
let apiKey: string | undefined
|
|
156
|
+
if (candidate !== undefined) {
|
|
157
|
+
const normalized = normalizeApiKey(candidate)
|
|
158
|
+
if (normalized === null) {
|
|
159
|
+
return failure(CONFIG_CODES.invalidApiKey)
|
|
160
|
+
}
|
|
161
|
+
apiKey = normalized
|
|
162
|
+
} else {
|
|
163
|
+
const resolved = resolveProviderApiKeySync(
|
|
164
|
+
{ id: provider.id, apiKeyEnv: provider.apiKeyEnv },
|
|
165
|
+
file,
|
|
166
|
+
)
|
|
167
|
+
if (resolved === null) {
|
|
168
|
+
return failure("openai.missing-api-key")
|
|
169
|
+
}
|
|
170
|
+
apiKey = resolved.apiKey
|
|
171
|
+
}
|
|
172
|
+
let fetch: ReturnType<typeof createProxyFetch> | undefined
|
|
173
|
+
try {
|
|
174
|
+
fetch = createProxyFetch(ctx.settings.network.proxy)
|
|
175
|
+
} catch {
|
|
176
|
+
fetch = undefined
|
|
177
|
+
}
|
|
178
|
+
const created = OpenAIClient.create({
|
|
179
|
+
settings: providerOpenAISettings(ctx.settings, provider),
|
|
180
|
+
apiKey,
|
|
181
|
+
credentialsFile: file,
|
|
182
|
+
logger: ctx.logger.child({ module: "openai" }),
|
|
183
|
+
fetch,
|
|
184
|
+
})
|
|
185
|
+
const client = created.getData()
|
|
186
|
+
if (!created.isSuccess() || client === null) {
|
|
187
|
+
return failure(created.getCode() ?? "openai.request-failed")
|
|
188
|
+
}
|
|
189
|
+
const tested = await client.testConnection()
|
|
190
|
+
const data = tested.getData()
|
|
191
|
+
if (!tested.isSuccess() || data === null) {
|
|
192
|
+
return failure(tested.getCode() ?? "openai.request-failed")
|
|
193
|
+
}
|
|
194
|
+
const model = provider.defaultModel ?? provider.models[0] ?? ctx.settings.openai.model
|
|
195
|
+
ctx.elog.print(`连接正常: ${provider.name} 可见模型 ${data.models} 个,缺省模型 ${model}`)
|
|
196
|
+
return success({ models: data.models, model, provider: provider.id })
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export async function runKeyCommand(
|
|
200
|
+
ctx: CommandContext,
|
|
201
|
+
argv: readonly string[],
|
|
202
|
+
): Promise<CommandOutcome> {
|
|
203
|
+
const [subcommand = "status", ...rest] = argv
|
|
204
|
+
const parsed = parseCommandArgs(rest, { provider: { type: "string" } })
|
|
205
|
+
if (!parsed.isSuccess()) {
|
|
206
|
+
return { result: Result.error<unknown>(parsed.getCode() ?? USAGE_CODES.invalidValue) }
|
|
207
|
+
}
|
|
208
|
+
const line = parsed.getData()
|
|
209
|
+
if (line === null) {
|
|
210
|
+
return failure(USAGE_CODES.invalidValue)
|
|
211
|
+
}
|
|
212
|
+
const rawProviderOption = line.values["provider"]
|
|
213
|
+
let provider: ResolvedModelProvider
|
|
214
|
+
try {
|
|
215
|
+
provider = targetProvider(
|
|
216
|
+
ctx,
|
|
217
|
+
typeof rawProviderOption === "string" ? rawProviderOption : undefined,
|
|
218
|
+
)
|
|
219
|
+
} catch (error) {
|
|
220
|
+
return failure(error instanceof Error ? error.message : "models.provider-not-found")
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
switch (subcommand) {
|
|
224
|
+
case "status": {
|
|
225
|
+
const status = keyStatusOf(ctx, provider)
|
|
226
|
+
printStatus(ctx, provider, status)
|
|
227
|
+
return success(status)
|
|
228
|
+
}
|
|
229
|
+
case "path": {
|
|
230
|
+
const file = credentialsFile(ctx.paths.configDir)
|
|
231
|
+
ctx.elog.print(file)
|
|
232
|
+
return success({ path: file })
|
|
233
|
+
}
|
|
234
|
+
case "set": {
|
|
235
|
+
const raw =
|
|
236
|
+
line.positionals[0] ??
|
|
237
|
+
(await readKeyFromStdin()) ??
|
|
238
|
+
(await promptHiddenApiKey("粘贴 API Key(输入不回显,回车确认): "))
|
|
239
|
+
if (raw === null || raw === undefined || raw === "") {
|
|
240
|
+
return failure(`${USAGE_CODES.missingValue}:key`)
|
|
241
|
+
}
|
|
242
|
+
const saved = await saveProviderApiKey(
|
|
243
|
+
provider.id,
|
|
244
|
+
raw,
|
|
245
|
+
credentialsFile(ctx.paths.configDir),
|
|
246
|
+
)
|
|
247
|
+
if (!saved.isSuccess()) {
|
|
248
|
+
return failure(saved.getCode() ?? CONFIG_CODES.credentialsWriteFailed)
|
|
249
|
+
}
|
|
250
|
+
const status = keyStatusOf(ctx, provider)
|
|
251
|
+
ctx.elog.print(`已保存 ${provider.name}: ${status.masked ?? ""} -> ${status.file}`)
|
|
252
|
+
if (status.source === "env") {
|
|
253
|
+
ctx.elog.print(
|
|
254
|
+
`注意: 环境变量 ${status.envVar ?? ""} 优先,实际请求仍用环境变量里的 key`,
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
return success(status)
|
|
258
|
+
}
|
|
259
|
+
case "clear": {
|
|
260
|
+
const cleared = await clearProviderApiKey(
|
|
261
|
+
provider.id,
|
|
262
|
+
credentialsFile(ctx.paths.configDir),
|
|
263
|
+
)
|
|
264
|
+
if (!cleared.isSuccess()) {
|
|
265
|
+
return failure(cleared.getCode() ?? CONFIG_CODES.credentialsWriteFailed)
|
|
266
|
+
}
|
|
267
|
+
const status = keyStatusOf(ctx, provider)
|
|
268
|
+
ctx.elog.print(
|
|
269
|
+
status.envOverride
|
|
270
|
+
? `本地凭据已清除;环境变量 ${status.envVar ?? ""} 仍然生效`
|
|
271
|
+
: "本地凭据已清除",
|
|
272
|
+
)
|
|
273
|
+
return success(status)
|
|
274
|
+
}
|
|
275
|
+
case "test": {
|
|
276
|
+
return await runTest(ctx, provider, line.positionals[0])
|
|
277
|
+
}
|
|
278
|
+
default:
|
|
279
|
+
return failure(`${USAGE_CODES.unknownSubcommand}:${subcommand}`)
|
|
280
|
+
}
|
|
281
|
+
}
|