@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,52 @@
|
|
|
1
|
+
// ask 工具的终端提问
|
|
2
|
+
|
|
3
|
+
import { createInterface } from "node:readline"
|
|
4
|
+
|
|
5
|
+
import type { HostAgentAskRequest } from "../api/host/agent.ts"
|
|
6
|
+
|
|
7
|
+
/** 选项序号 → 选项文本;非序号返回 null */
|
|
8
|
+
function optionByIndex(input: string, request: HostAgentAskRequest): string | null {
|
|
9
|
+
const options = request.options ?? []
|
|
10
|
+
if (!/^\d+$/.test(input)) {
|
|
11
|
+
return null
|
|
12
|
+
}
|
|
13
|
+
const index = Number(input) - 1
|
|
14
|
+
return index >= 0 && index < options.length ? (options[index] ?? null) : null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 终端里回答 Agent 的提问。
|
|
19
|
+
* 返回答案文本;null 表示取消(SIGINT 等),空串表示跳过。
|
|
20
|
+
*/
|
|
21
|
+
export async function promptAgentAsk(request: HostAgentAskRequest): Promise<string | null> {
|
|
22
|
+
if (process.stdin.isTTY !== true || process.stdout.isTTY !== true) {
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
const out = process.stdout
|
|
26
|
+
out.write(`\n[Agent 提问] ${request.question}\n`)
|
|
27
|
+
const options = request.options ?? []
|
|
28
|
+
for (let index = 0; index < options.length; index += 1) {
|
|
29
|
+
out.write(` ${index + 1}. ${options[index] ?? ""}\n`)
|
|
30
|
+
}
|
|
31
|
+
const rl = createInterface({ input: process.stdin, output: out, terminal: false })
|
|
32
|
+
try {
|
|
33
|
+
const line = await new Promise<string | null>((resolvePromise) => {
|
|
34
|
+
let settled = false
|
|
35
|
+
const finish = (value: string | null): void => {
|
|
36
|
+
if (settled) {
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
settled = true
|
|
40
|
+
resolvePromise(value)
|
|
41
|
+
}
|
|
42
|
+
rl.once("SIGINT", () => finish(null))
|
|
43
|
+
rl.question("回答(序号或文字,直接回车跳过)> ", (answer) => finish(answer))
|
|
44
|
+
})
|
|
45
|
+
if (line === null) {
|
|
46
|
+
return null
|
|
47
|
+
}
|
|
48
|
+
return optionByIndex(line.trim(), request) ?? line
|
|
49
|
+
} finally {
|
|
50
|
+
rl.close()
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* config 命令:path / show / get / set。
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Result } from "../api/result/result.ts"
|
|
6
|
+
import { CONFIG_CODES } from "../config/codes.ts"
|
|
7
|
+
import { saveSettings } from "../config/loader.ts"
|
|
8
|
+
import { modelsSetting } from "../config/providers.ts"
|
|
9
|
+
import type { AppSetting } from "../config/types.ts"
|
|
10
|
+
import { readJsonIfExists, writeJsonAtomic } from "../platform/file.ts"
|
|
11
|
+
import { PLUGIN_NAME } from "../plugin/paths.ts"
|
|
12
|
+
import { pluginConfigFile } from "../plugin/runtime.ts"
|
|
13
|
+
import { USAGE_CODES } from "../input/codes.ts"
|
|
14
|
+
import { parseCommandArgs } from "../input/parse-options.ts"
|
|
15
|
+
import { failure, success, type CommandContext, type CommandOutcome } from "./shared.ts"
|
|
16
|
+
|
|
17
|
+
const KEYS = [
|
|
18
|
+
"logger.level",
|
|
19
|
+
"openai.model",
|
|
20
|
+
"openai.baseUrl",
|
|
21
|
+
"openai.timeoutMs",
|
|
22
|
+
"openai.maxRetries",
|
|
23
|
+
"models.activeProvider",
|
|
24
|
+
"models.activeModel",
|
|
25
|
+
"models.activeReasoning",
|
|
26
|
+
"network.proxy",
|
|
27
|
+
"network.noProxy",
|
|
28
|
+
] as const
|
|
29
|
+
|
|
30
|
+
type ConfigKey = (typeof KEYS)[number]
|
|
31
|
+
|
|
32
|
+
function modelsOf(settings: AppSetting) {
|
|
33
|
+
return modelsSetting(settings)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isKey(value: string): value is ConfigKey {
|
|
37
|
+
return (KEYS as readonly string[]).includes(value)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const PLUGIN_CONFIG_DPIREFIX = "plugins."
|
|
41
|
+
const PLUGIN_CONFIG_FIELD = /^[A-Za-z0-9_-]+$/
|
|
42
|
+
|
|
43
|
+
interface PluginConfigRef {
|
|
44
|
+
readonly pluginId: string
|
|
45
|
+
/** 插件配置里的顶层字段;省略表示整份配置 */
|
|
46
|
+
readonly field: string | null
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* `plugins.<id>.<field>`:读写插件自己的 <configDir>/plugins/<id>.json。
|
|
51
|
+
* 插件 id 本身允许点号的情况极少,因此按“最后一个点”切分字段;
|
|
52
|
+
* 没有点时表示整份配置。
|
|
53
|
+
*/
|
|
54
|
+
function parsePluginKey(key: string): PluginConfigRef | null {
|
|
55
|
+
if (!key.startsWith(PLUGIN_CONFIG_DPIREFIX)) {
|
|
56
|
+
return null
|
|
57
|
+
}
|
|
58
|
+
const rest = key.slice(PLUGIN_CONFIG_DPIREFIX.length)
|
|
59
|
+
const dot = rest.lastIndexOf(".")
|
|
60
|
+
if (dot > 0) {
|
|
61
|
+
const pluginId = rest.slice(0, dot)
|
|
62
|
+
const field = rest.slice(dot + 1)
|
|
63
|
+
if (PLUGIN_NAME.test(pluginId) && PLUGIN_CONFIG_FIELD.test(field)) {
|
|
64
|
+
return { pluginId, field }
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (PLUGIN_NAME.test(rest)) {
|
|
68
|
+
return { pluginId: rest, field: null }
|
|
69
|
+
}
|
|
70
|
+
return null
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function readPluginConfig(
|
|
74
|
+
ctx: CommandContext,
|
|
75
|
+
pluginId: string,
|
|
76
|
+
): Promise<Record<string, unknown> | string> {
|
|
77
|
+
const file = pluginConfigFile(pluginId, ctx.paths)
|
|
78
|
+
try {
|
|
79
|
+
const value = await readJsonIfExists<unknown>(file)
|
|
80
|
+
if (value === null) {
|
|
81
|
+
return {}
|
|
82
|
+
}
|
|
83
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
84
|
+
return `${CONFIG_CODES.invalid}:${file}(插件配置必须是 JSON 对象)`
|
|
85
|
+
}
|
|
86
|
+
return { ...(value as Record<string, unknown>) }
|
|
87
|
+
} catch {
|
|
88
|
+
return `${CONFIG_CODES.parseFailed}:${file}`
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** 先按 JSON 解析,失败就当裸字符串;这样 port 能存成数字、host 仍是字符串 */
|
|
93
|
+
function parsePluginValue(raw: string): unknown {
|
|
94
|
+
try {
|
|
95
|
+
return JSON.parse(raw)
|
|
96
|
+
} catch {
|
|
97
|
+
return raw
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function readValue(settings: AppSetting, key: ConfigKey): unknown {
|
|
102
|
+
switch (key) {
|
|
103
|
+
case "logger.level":
|
|
104
|
+
return settings.logger.level
|
|
105
|
+
case "openai.model":
|
|
106
|
+
return settings.openai.model
|
|
107
|
+
case "openai.baseUrl":
|
|
108
|
+
return settings.openai.baseUrl
|
|
109
|
+
case "openai.timeoutMs":
|
|
110
|
+
return settings.openai.timeoutMs
|
|
111
|
+
case "openai.maxRetries":
|
|
112
|
+
return settings.openai.maxRetries
|
|
113
|
+
case "models.activeProvider":
|
|
114
|
+
return modelsOf(settings).activeProvider
|
|
115
|
+
case "models.activeModel":
|
|
116
|
+
return modelsOf(settings).activeModel
|
|
117
|
+
case "models.activeReasoning":
|
|
118
|
+
return modelsOf(settings).activeReasoning
|
|
119
|
+
case "network.proxy":
|
|
120
|
+
return settings.network.proxy
|
|
121
|
+
case "network.noProxy":
|
|
122
|
+
return settings.network.proxy?.noProxy ?? []
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** CLI 里接受 none/null/off/空串表示直连;其余按 http(s) URL 校验 */
|
|
127
|
+
function normalizeProxyUrl(raw: string): string | null | string {
|
|
128
|
+
const value = raw.trim()
|
|
129
|
+
if (value === "" || value === "none" || value === "null" || value === "off") {
|
|
130
|
+
return null
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
const url = new URL(value)
|
|
134
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
135
|
+
return `${USAGE_CODES.invalidValue}:network.proxy(只支持 http/https)`
|
|
136
|
+
}
|
|
137
|
+
} catch {
|
|
138
|
+
return `${USAGE_CODES.invalidValue}:network.proxy`
|
|
139
|
+
}
|
|
140
|
+
return value
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function splitNoProxy(raw: string): string[] {
|
|
144
|
+
const result: string[] = []
|
|
145
|
+
for (const item of raw.split(/[,,\s]+/)) {
|
|
146
|
+
const value = item.trim()
|
|
147
|
+
if (value !== "" && !result.includes(value)) result.push(value)
|
|
148
|
+
}
|
|
149
|
+
return result
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function writeValue(settings: AppSetting, key: ConfigKey, raw: string): AppSetting | string {
|
|
153
|
+
switch (key) {
|
|
154
|
+
case "logger.level":
|
|
155
|
+
return { ...settings, logger: { level: raw as AppSetting["logger"]["level"] } }
|
|
156
|
+
case "openai.model":
|
|
157
|
+
return { ...settings, openai: { ...settings.openai, model: raw } }
|
|
158
|
+
case "openai.baseUrl": {
|
|
159
|
+
const baseUrl = raw === "null" || raw === "none" ? null : raw
|
|
160
|
+
return { ...settings, openai: { ...settings.openai, baseUrl } }
|
|
161
|
+
}
|
|
162
|
+
case "openai.timeoutMs": {
|
|
163
|
+
const value = Number(raw)
|
|
164
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
165
|
+
return `${USAGE_CODES.invalidValue}:openai.timeoutMs`
|
|
166
|
+
}
|
|
167
|
+
return { ...settings, openai: { ...settings.openai, timeoutMs: value } }
|
|
168
|
+
}
|
|
169
|
+
case "openai.maxRetries": {
|
|
170
|
+
const value = Number(raw)
|
|
171
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
172
|
+
return `${USAGE_CODES.invalidValue}:openai.maxRetries`
|
|
173
|
+
}
|
|
174
|
+
return { ...settings, openai: { ...settings.openai, maxRetries: value } }
|
|
175
|
+
}
|
|
176
|
+
case "models.activeProvider": {
|
|
177
|
+
const next = modelsOf(settings)
|
|
178
|
+
return { ...settings, models: { ...next, activeProvider: raw } }
|
|
179
|
+
}
|
|
180
|
+
case "models.activeModel": {
|
|
181
|
+
const next = modelsOf(settings)
|
|
182
|
+
const value = raw === "null" || raw === "none" || raw === "" ? null : raw
|
|
183
|
+
return { ...settings, models: { ...next, activeModel: value } }
|
|
184
|
+
}
|
|
185
|
+
case "models.activeReasoning": {
|
|
186
|
+
if (raw !== "off" && raw !== "low" && raw !== "high" && raw !== "max") {
|
|
187
|
+
return `${USAGE_CODES.invalidValue}:models.activeReasoning`
|
|
188
|
+
}
|
|
189
|
+
const next = modelsOf(settings)
|
|
190
|
+
return { ...settings, models: { ...next, activeReasoning: raw } }
|
|
191
|
+
}
|
|
192
|
+
case "network.proxy": {
|
|
193
|
+
const url = normalizeProxyUrl(raw)
|
|
194
|
+
if (typeof url === "string" && url.startsWith(USAGE_CODES.invalidValue)) {
|
|
195
|
+
return url
|
|
196
|
+
}
|
|
197
|
+
const noProxy = settings.network.proxy?.noProxy ?? []
|
|
198
|
+
return {
|
|
199
|
+
...settings,
|
|
200
|
+
network: { proxy: url === null ? null : { type: "http", url, noProxy } },
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
case "network.noProxy": {
|
|
204
|
+
const noProxy = splitNoProxy(raw)
|
|
205
|
+
const current = settings.network.proxy
|
|
206
|
+
if (current === null && noProxy.length > 0) {
|
|
207
|
+
return `${USAGE_CODES.invalidValue}:network.noProxy(先设置 network.proxy)`
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
...settings,
|
|
211
|
+
network: {
|
|
212
|
+
proxy: current === null ? null : { ...current, noProxy },
|
|
213
|
+
},
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export async function runConfigCommand(
|
|
220
|
+
ctx: CommandContext,
|
|
221
|
+
argv: readonly string[],
|
|
222
|
+
): Promise<CommandOutcome> {
|
|
223
|
+
const [subcommand, ...rest] = argv
|
|
224
|
+
const parsed = parseCommandArgs(rest, {})
|
|
225
|
+
if (!parsed.isSuccess()) {
|
|
226
|
+
return { result: Result.error<unknown>(parsed.getCode() ?? USAGE_CODES.invalidValue) }
|
|
227
|
+
}
|
|
228
|
+
const line = parsed.getData()
|
|
229
|
+
if (line === null) {
|
|
230
|
+
return failure(USAGE_CODES.invalidValue)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
switch (subcommand) {
|
|
234
|
+
case "path": {
|
|
235
|
+
ctx.elog.print(ctx.settingsFile)
|
|
236
|
+
return success({ path: ctx.settingsFile })
|
|
237
|
+
}
|
|
238
|
+
case "show": {
|
|
239
|
+
ctx.elog.print(JSON.stringify(ctx.settings, null, 4))
|
|
240
|
+
return success(ctx.settings)
|
|
241
|
+
}
|
|
242
|
+
case "get": {
|
|
243
|
+
const key = line.positionals[0]
|
|
244
|
+
if (key === undefined) {
|
|
245
|
+
return failure(`${USAGE_CODES.missingValue}:key`)
|
|
246
|
+
}
|
|
247
|
+
const pluginRef = parsePluginKey(key)
|
|
248
|
+
if (pluginRef !== null) {
|
|
249
|
+
const config = await readPluginConfig(ctx, pluginRef.pluginId)
|
|
250
|
+
if (typeof config === "string") {
|
|
251
|
+
return failure(config)
|
|
252
|
+
}
|
|
253
|
+
const value = pluginRef.field === null ? config : (config[pluginRef.field] ?? null)
|
|
254
|
+
ctx.elog.print(value === null ? "null" : JSON.stringify(value))
|
|
255
|
+
return success({ key, value })
|
|
256
|
+
}
|
|
257
|
+
if (!isKey(key)) {
|
|
258
|
+
return failure(`${USAGE_CODES.unknownConfigKey}:${key}`)
|
|
259
|
+
}
|
|
260
|
+
const value = readValue(ctx.settings, key)
|
|
261
|
+
ctx.elog.print(value === null ? "null" : JSON.stringify(value))
|
|
262
|
+
return success({ key, value })
|
|
263
|
+
}
|
|
264
|
+
case "set": {
|
|
265
|
+
const key = line.positionals[0]
|
|
266
|
+
const raw = line.positionals[1]
|
|
267
|
+
if (key === undefined || raw === undefined) {
|
|
268
|
+
return failure(`${USAGE_CODES.missingValue}:key value`)
|
|
269
|
+
}
|
|
270
|
+
const pluginRef = parsePluginKey(key)
|
|
271
|
+
if (pluginRef !== null) {
|
|
272
|
+
const config = await readPluginConfig(ctx, pluginRef.pluginId)
|
|
273
|
+
if (typeof config === "string") {
|
|
274
|
+
return failure(config)
|
|
275
|
+
}
|
|
276
|
+
const value = parsePluginValue(raw)
|
|
277
|
+
if (pluginRef.field === null) {
|
|
278
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
279
|
+
return failure(`${CONFIG_CODES.invalid}:${key}(整份配置需要 JSON 对象)`)
|
|
280
|
+
}
|
|
281
|
+
await writeJsonAtomic(pluginConfigFile(pluginRef.pluginId, ctx.paths), value)
|
|
282
|
+
} else {
|
|
283
|
+
config[pluginRef.field] = value
|
|
284
|
+
await writeJsonAtomic(pluginConfigFile(pluginRef.pluginId, ctx.paths), config)
|
|
285
|
+
}
|
|
286
|
+
ctx.elog.info(`已更新 ${key}(重启服务后生效)`)
|
|
287
|
+
return success({ key, value })
|
|
288
|
+
}
|
|
289
|
+
if (!isKey(key)) {
|
|
290
|
+
return failure(`${USAGE_CODES.unknownConfigKey}:${key}`)
|
|
291
|
+
}
|
|
292
|
+
const next = writeValue(ctx.settings, key, raw)
|
|
293
|
+
if (typeof next === "string") {
|
|
294
|
+
return failure(next)
|
|
295
|
+
}
|
|
296
|
+
const saved = await saveSettings(next, ctx.settingsFile)
|
|
297
|
+
if (!saved.isSuccess()) {
|
|
298
|
+
return failure(saved.getCode() ?? "config.write-failed")
|
|
299
|
+
}
|
|
300
|
+
ctx.elog.info(`已更新 ${key}`)
|
|
301
|
+
return success({ key, value: readValue(next, key) })
|
|
302
|
+
}
|
|
303
|
+
default:
|
|
304
|
+
return failure(`${USAGE_CODES.unknownSubcommand}:config ${subcommand ?? ""}`)
|
|
305
|
+
}
|
|
306
|
+
}
|