@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,99 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 宿主信息 API:类似 Bukkit 的 PluginManager。
|
|
3
|
+
* 插件通过 getHost() 获取宿主状态、插件列表、OS 与路径。
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { release as osRelease } from "node:os"
|
|
7
|
+
|
|
8
|
+
import type { PlatformName } from "../../platform/os.ts"
|
|
9
|
+
import { getHostBridge } from "../../sandbox/bridge-state.ts"
|
|
10
|
+
import type { ResolvedPaths } from "../../platform/path.ts"
|
|
11
|
+
import type { PluginStatus } from "./plugin.ts"
|
|
12
|
+
|
|
13
|
+
export type HostStatus = "starting" | "running" | "stopping" | "stopped"
|
|
14
|
+
export type HostPluginStatus = PluginStatus | "disabled"
|
|
15
|
+
|
|
16
|
+
export interface HostOSInfo {
|
|
17
|
+
readonly platform: PlatformName
|
|
18
|
+
readonly arch: string
|
|
19
|
+
readonly release: string
|
|
20
|
+
readonly node: string
|
|
21
|
+
readonly cwd: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface HostPlugin {
|
|
25
|
+
readonly id: string
|
|
26
|
+
readonly name: string
|
|
27
|
+
readonly version: string
|
|
28
|
+
readonly deps: readonly string[]
|
|
29
|
+
readonly commands: readonly string[]
|
|
30
|
+
getStatus(): HostPluginStatus
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface Host {
|
|
34
|
+
getPlugins(): readonly HostPlugin[]
|
|
35
|
+
getOS(): HostOSInfo
|
|
36
|
+
getPaths(): ResolvedPaths
|
|
37
|
+
getStatus(): HostStatus
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface HostState {
|
|
41
|
+
status: HostStatus
|
|
42
|
+
paths: ResolvedPaths | null
|
|
43
|
+
os: HostOSInfo
|
|
44
|
+
plugins: HostPlugin[]
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const state: HostState = {
|
|
48
|
+
status: "starting",
|
|
49
|
+
paths: null,
|
|
50
|
+
os: {
|
|
51
|
+
platform: "linux",
|
|
52
|
+
arch: process.arch,
|
|
53
|
+
release: osRelease(),
|
|
54
|
+
node: process.version,
|
|
55
|
+
cwd: process.cwd(),
|
|
56
|
+
},
|
|
57
|
+
plugins: [],
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** 平台内部:初始化宿主信息 */
|
|
61
|
+
export function configureHost(options: {
|
|
62
|
+
readonly paths?: ResolvedPaths
|
|
63
|
+
readonly os?: Partial<HostOSInfo>
|
|
64
|
+
}): void {
|
|
65
|
+
if (options.paths !== undefined) {
|
|
66
|
+
state.paths = options.paths
|
|
67
|
+
}
|
|
68
|
+
if (options.os !== undefined) {
|
|
69
|
+
state.os = { ...state.os, ...options.os }
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** 平台内部:更新宿主生命周期状态 */
|
|
74
|
+
export function setHostStatus(status: HostStatus): void {
|
|
75
|
+
state.status = status
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** 平台内部:更新插件列表 */
|
|
79
|
+
export function setHostPlugins(plugins: readonly HostPlugin[]): void {
|
|
80
|
+
state.plugins = [...plugins]
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function getHost(): Host {
|
|
84
|
+
const bridge = getHostBridge()
|
|
85
|
+
if (bridge !== null) {
|
|
86
|
+
return bridge.getHostSnapshot()
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
getPlugins: () => [...state.plugins],
|
|
90
|
+
getOS: () => ({ ...state.os }),
|
|
91
|
+
getPaths: () => {
|
|
92
|
+
if (state.paths === null) {
|
|
93
|
+
throw new Error("宿主路径尚未初始化")
|
|
94
|
+
}
|
|
95
|
+
return state.paths
|
|
96
|
+
},
|
|
97
|
+
getStatus: () => state.status,
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 插件 HTTP 宿主能力。
|
|
3
|
+
* 插件在 sandbox 内,宿主负责监听端口,请求通过 RPC 交给插件 handler。
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface HttpRequest {
|
|
7
|
+
readonly method: string
|
|
8
|
+
readonly url: string
|
|
9
|
+
readonly headers: Record<string, string>
|
|
10
|
+
/** base64 编码的请求体 */
|
|
11
|
+
readonly body: string
|
|
12
|
+
readonly remoteAddress: string | null
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface HttpResponse {
|
|
16
|
+
readonly status?: number
|
|
17
|
+
readonly headers?: Record<string, string>
|
|
18
|
+
/** utf8 或 base64;默认 utf8 */
|
|
19
|
+
readonly body?: string
|
|
20
|
+
readonly bodyEncoding?: "utf8" | "base64"
|
|
21
|
+
/** true 时保持连接,后续通过 stream 写出 */
|
|
22
|
+
readonly stream?: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface HttpStreamContext {
|
|
26
|
+
write(chunk: string): void
|
|
27
|
+
end(): void
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type HttpHandler = (
|
|
31
|
+
request: HttpRequest,
|
|
32
|
+
stream: HttpStreamContext,
|
|
33
|
+
) => HttpResponse | Promise<HttpResponse>
|
|
34
|
+
|
|
35
|
+
export interface PluginWebSocket {
|
|
36
|
+
readonly connectionId: string
|
|
37
|
+
send(data: string): Promise<void>
|
|
38
|
+
close(code?: number, reason?: string): Promise<void>
|
|
39
|
+
onMessage(handler: (data: string) => void): void
|
|
40
|
+
onClose(handler: (code: number, reason: string) => void): void
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type WebSocketHandler = (
|
|
44
|
+
socket: PluginWebSocket,
|
|
45
|
+
request: HttpRequest,
|
|
46
|
+
) => void | Promise<void>
|
|
47
|
+
|
|
48
|
+
export interface HttpTlsOptions {
|
|
49
|
+
/** PEM 格式证书 */
|
|
50
|
+
readonly cert: string
|
|
51
|
+
/** PEM 格式私钥 */
|
|
52
|
+
readonly key: string
|
|
53
|
+
/** 可选 CA 链 */
|
|
54
|
+
readonly ca?: string
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface HttpServerOptions {
|
|
58
|
+
/** 默认 127.0.0.1 */
|
|
59
|
+
readonly host?: string
|
|
60
|
+
/** 默认 0(随机端口) */
|
|
61
|
+
readonly port?: number
|
|
62
|
+
/** 提供时启动 HTTPS */
|
|
63
|
+
readonly tls?: HttpTlsOptions
|
|
64
|
+
/** 提供时启用 WebSocket */
|
|
65
|
+
readonly websocket?: WebSocketHandler
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface HttpServerHandle {
|
|
69
|
+
readonly serverId: string
|
|
70
|
+
readonly host: string
|
|
71
|
+
readonly port: number
|
|
72
|
+
close(): Promise<void>
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface HostHttpApi {
|
|
76
|
+
createServer(options: HttpServerOptions, handler: HttpHandler): Promise<HttpServerHandle>
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const HTTP_MAX_BODY_BYTES = 16 * 1024 * 1024
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 宿主 API 入口。
|
|
3
|
+
* 插件可以 import { onMessage, getHost, ... } from "wellspring/api/host/index.ts"。
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export * from "./agent.ts"
|
|
7
|
+
export * from "./events.ts"
|
|
8
|
+
export * from "./exec.ts"
|
|
9
|
+
export * from "./fs.ts"
|
|
10
|
+
export * from "./http.ts"
|
|
11
|
+
export * from "./models.ts"
|
|
12
|
+
export * from "./network.ts"
|
|
13
|
+
export * from "./hooks.ts"
|
|
14
|
+
export * from "./host.ts"
|
|
15
|
+
export * from "./plugin.ts"
|
|
16
|
+
export * from "./plugins.ts"
|
|
17
|
+
export * from "./pty.ts"
|
|
18
|
+
export * from "./session.ts"
|
|
19
|
+
export * from "./version.ts"
|
|
20
|
+
export * from "./workspace.ts"
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 宿主模型 API:给插件(Web 设置界面)管理自定义供应商与模型切换。
|
|
3
|
+
*
|
|
4
|
+
* 供应商配置写回 app-setting.json 的 models 节;每个供应商的 Key 单独存凭据文件。
|
|
5
|
+
* 状态里只给掩码,读不到明文。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** 一个供应商的展示信息(含 Key 状态,不含明文) */
|
|
9
|
+
export interface HostModelProvider {
|
|
10
|
+
readonly id: string
|
|
11
|
+
readonly name: string
|
|
12
|
+
readonly baseUrl: string | null
|
|
13
|
+
readonly models: readonly string[]
|
|
14
|
+
readonly defaultModel: string | null
|
|
15
|
+
readonly apiKeyEnv: string | null
|
|
16
|
+
/** 内置供应商(由 openai.* 描述)不能删除 */
|
|
17
|
+
readonly builtin: boolean
|
|
18
|
+
readonly keyConfigured: boolean
|
|
19
|
+
readonly keySource: "env" | "credentials" | null
|
|
20
|
+
readonly keyMasked: string | null
|
|
21
|
+
/** 该供应商可用的环境变量名(内置为 OPENAI_API_KEY) */
|
|
22
|
+
readonly envVar: string | null
|
|
23
|
+
/** 本地凭据文件里是否有 Key(即使被环境变量覆盖) */
|
|
24
|
+
readonly keyStored: boolean
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface HostModelsState {
|
|
28
|
+
readonly providers: readonly HostModelProvider[]
|
|
29
|
+
readonly activeProvider: string
|
|
30
|
+
readonly activeModel: string | null
|
|
31
|
+
/** 当前推理强度:off / low / high / max */
|
|
32
|
+
readonly activeReasoning: string
|
|
33
|
+
/** 支持的推理强度(界面用) */
|
|
34
|
+
readonly reasoningLevels: readonly string[]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 新增/修改供应商;id 为空时按 name 生成或新增 */
|
|
38
|
+
export interface HostModelProviderInput {
|
|
39
|
+
readonly id?: string | null
|
|
40
|
+
readonly name: string
|
|
41
|
+
readonly baseUrl?: string | null
|
|
42
|
+
readonly models?: readonly string[]
|
|
43
|
+
readonly defaultModel?: string | null
|
|
44
|
+
readonly apiKeyEnv?: string | null
|
|
45
|
+
/** 可选:一起保存该供应商的 API Key(明文只写不读) */
|
|
46
|
+
readonly apiKey?: string | null
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface HostModelsStateResult {
|
|
50
|
+
readonly ok: boolean
|
|
51
|
+
/** ok=false 时的错误码,例如 config.invalid */
|
|
52
|
+
readonly code?: string
|
|
53
|
+
readonly state: HostModelsState
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface HostModelsFetchResult {
|
|
57
|
+
readonly ok: boolean
|
|
58
|
+
readonly code?: string
|
|
59
|
+
readonly models?: readonly string[]
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface HostModelsApi {
|
|
63
|
+
/** 供应商列表、当前供应商与模型 */
|
|
64
|
+
state(): Promise<HostModelsState>
|
|
65
|
+
/** 切换当前供应商、模型与推理强度;model/reasoning 为 null 时保持缺省 */
|
|
66
|
+
setActive(
|
|
67
|
+
providerId: string,
|
|
68
|
+
model: string | null,
|
|
69
|
+
reasoning?: string | null,
|
|
70
|
+
): Promise<HostModelsState>
|
|
71
|
+
/** 新增或更新自定义供应商 */
|
|
72
|
+
saveProvider(input: HostModelProviderInput): Promise<HostModelsStateResult>
|
|
73
|
+
/** 删除自定义供应商(内置 openai 不可删) */
|
|
74
|
+
removeProvider(id: string): Promise<HostModelsStateResult>
|
|
75
|
+
/** 从供应商接口拉取模型列表(候选 key 优先,其次用已保存的) */
|
|
76
|
+
fetchModels(id: string, apiKey?: string): Promise<HostModelsFetchResult>
|
|
77
|
+
/** 保存某个供应商的 API Key */
|
|
78
|
+
saveKey(id: string, apiKey: string): Promise<HostModelsStateResult>
|
|
79
|
+
/** 清除某个供应商的本地 API Key */
|
|
80
|
+
clearKey(id: string): Promise<HostModelsState>
|
|
81
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 宿主网络配置:给插件(例如网页设置页)读写 app-setting.json 的 network.proxy。
|
|
3
|
+
*
|
|
4
|
+
* 只处理出站 HTTP/HTTPS 代理;保存后下一轮模型调用、模型列表拉取与网页搜索都会使用新配置。
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ProxySetting } from "../../config/types.ts"
|
|
8
|
+
|
|
9
|
+
/** 保存代理:url 为空 / null 表示直连 */
|
|
10
|
+
export interface HostNetworkProxyInput {
|
|
11
|
+
readonly url: string | null
|
|
12
|
+
/** 不走代理的主机后缀,例如 localhost、.internal */
|
|
13
|
+
readonly noProxy?: readonly string[]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface HostNetworkState {
|
|
17
|
+
/** null 表示直连 */
|
|
18
|
+
readonly proxy: ProxySetting | null
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface HostNetworkResult {
|
|
22
|
+
readonly ok: boolean
|
|
23
|
+
/** ok=false 时的错误码,例如 config.invalid:network.proxy.url */
|
|
24
|
+
readonly code?: string
|
|
25
|
+
readonly state: HostNetworkState
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface HostNetworkApi {
|
|
29
|
+
state(): Promise<HostNetworkState>
|
|
30
|
+
/** 写入 app-setting.json;校验失败时不落盘 */
|
|
31
|
+
saveProxy(input: HostNetworkProxyInput): Promise<HostNetworkResult>
|
|
32
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 宿主契约:平台暴露给插件与外部调用方的稳定接口。
|
|
3
|
+
* 实现放在各模块,api/host 只放类型、版本与钩子注册入口。
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Logger } from "pino"
|
|
7
|
+
|
|
8
|
+
import type { HostFileApi } from "./fs.ts"
|
|
9
|
+
import type { HostModelsApi } from "./models.ts"
|
|
10
|
+
import type { HostNetworkApi } from "./network.ts"
|
|
11
|
+
import type { HostExecApi } from "./exec.ts"
|
|
12
|
+
import type { HostPtyApi } from "./pty.ts"
|
|
13
|
+
|
|
14
|
+
import type { AppSetting } from "../../config/types.ts"
|
|
15
|
+
import type { ResolvedPaths } from "../../platform/path.ts"
|
|
16
|
+
import { HOST_API_VERSION } from "./version.ts"
|
|
17
|
+
|
|
18
|
+
/** 插件自报状态 */
|
|
19
|
+
export type PluginStatus = "ok" | "failed"
|
|
20
|
+
|
|
21
|
+
/** 插件自己的 JSON 配置(<configDir>/plugins/<id>.json) */
|
|
22
|
+
export type PluginConfig = Readonly<Record<string, unknown>>
|
|
23
|
+
|
|
24
|
+
/** 插件可用的终端输出;human 模式下由 elog4js 渲染 */
|
|
25
|
+
export interface HostOutput {
|
|
26
|
+
info(text: string): void
|
|
27
|
+
warn(text: string): void
|
|
28
|
+
error(text: string): void
|
|
29
|
+
print(text?: string): void
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface PluginCommandContext {
|
|
33
|
+
/** 命令名之后的原始参数,平台不解析 */
|
|
34
|
+
readonly argv: readonly string[]
|
|
35
|
+
readonly env: NodeJS.ProcessEnv
|
|
36
|
+
readonly paths: ResolvedPaths
|
|
37
|
+
readonly config: AppSetting
|
|
38
|
+
readonly logger: Logger
|
|
39
|
+
readonly output: HostOutput
|
|
40
|
+
/** 插件专属数据目录,已创建 */
|
|
41
|
+
readonly pluginDataDir: string
|
|
42
|
+
/** 插件专属配置,文件不存在时为空对象 */
|
|
43
|
+
readonly pluginConfig: PluginConfig
|
|
44
|
+
/** 插件数据目录内的文件操作 */
|
|
45
|
+
readonly fs: HostFileApi
|
|
46
|
+
/** 当前工作目录内的文件操作 */
|
|
47
|
+
readonly workspaceFs: HostFileApi
|
|
48
|
+
readonly cwd: string
|
|
49
|
+
readonly json: boolean
|
|
50
|
+
readonly stdin: NodeJS.ReadableStream
|
|
51
|
+
readonly stdout: NodeJS.WritableStream
|
|
52
|
+
readonly stderr: NodeJS.WritableStream
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface PluginCommand {
|
|
56
|
+
readonly name: string
|
|
57
|
+
readonly summary: string
|
|
58
|
+
readonly usage?: string
|
|
59
|
+
readonly aliases?: readonly string[]
|
|
60
|
+
readonly run: (context: PluginCommandContext) => number | void | Promise<number | void>
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface AgentToolParam {
|
|
64
|
+
readonly type?: "string" | "number" | "integer" | "boolean" | "array" | "object"
|
|
65
|
+
readonly description?: string
|
|
66
|
+
readonly enum?: readonly string[]
|
|
67
|
+
readonly optional?: boolean
|
|
68
|
+
readonly items?: { readonly type: "string" | "number" | "integer" | "boolean" }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** string 作为简写,等价于 { type: "string", description } */
|
|
72
|
+
export type AgentToolParamSpec = string | AgentToolParam
|
|
73
|
+
|
|
74
|
+
export interface AgentToolIntroduction {
|
|
75
|
+
/** 参数名 → 类型与说明 */
|
|
76
|
+
readonly params: Record<string, AgentToolParamSpec>
|
|
77
|
+
/** 工具用途说明,作为 tool description 下发给模型 */
|
|
78
|
+
readonly content: string
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface AgentCallToolResult {
|
|
82
|
+
readonly success: boolean
|
|
83
|
+
readonly data: Record<string, unknown>
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
import type { HostAgentApi } from "./agent.ts"
|
|
87
|
+
import type { HostCapabilities } from "../../plugin/capabilities.ts"
|
|
88
|
+
import type { HostHttpApi } from "./http.ts"
|
|
89
|
+
import type { HostPluginsApi } from "./plugins.ts"
|
|
90
|
+
import type { HostWorkspacesApi } from "./workspace.ts"
|
|
91
|
+
|
|
92
|
+
export interface AgentTool {
|
|
93
|
+
readonly name: string
|
|
94
|
+
readonly introduction: AgentToolIntroduction
|
|
95
|
+
readonly call: (...args: unknown[]) => AgentCallToolResult | Promise<AgentCallToolResult>
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface WellspringPluginInfo {
|
|
99
|
+
readonly id: string
|
|
100
|
+
readonly name: string
|
|
101
|
+
readonly version: string
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** setup() 返回的插件描述与扩展 */
|
|
105
|
+
export interface WellspringPlugin extends WellspringPluginInfo {
|
|
106
|
+
/** 插件自检状态,必须提供 */
|
|
107
|
+
readonly status: PluginStatus
|
|
108
|
+
readonly description?: string
|
|
109
|
+
/** 依赖的插件 id,仅用于元信息与展示 */
|
|
110
|
+
readonly deps?: readonly string[]
|
|
111
|
+
/** 插件注册的命令;也可以在 init(api) 里调用 api.registerCommand */
|
|
112
|
+
readonly commands?: readonly PluginCommand[]
|
|
113
|
+
/** 插件提供的 Agent 工具;重名会导致后加载插件停用 */
|
|
114
|
+
readonly agentTools?: readonly AgentTool[]
|
|
115
|
+
/** 可选初始化:拿到宿主能力后再注册命令或做启动检查 */
|
|
116
|
+
readonly init?: (api: PluginApi) => void | Promise<void>
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export type PluginSetup = () => WellspringPlugin | Promise<WellspringPlugin>
|
|
120
|
+
|
|
121
|
+
export interface PluginApi {
|
|
122
|
+
readonly apiVersion: typeof HOST_API_VERSION
|
|
123
|
+
readonly plugin: WellspringPluginInfo
|
|
124
|
+
readonly paths: ResolvedPaths
|
|
125
|
+
readonly config: AppSetting
|
|
126
|
+
readonly logger: Logger
|
|
127
|
+
readonly output: HostOutput
|
|
128
|
+
/** 插件专属数据目录,已创建 */
|
|
129
|
+
readonly pluginDataDir: string
|
|
130
|
+
/** 插件专属配置,文件不存在时为空对象 */
|
|
131
|
+
readonly pluginConfig: PluginConfig
|
|
132
|
+
/** 插件数据目录内的文件操作 */
|
|
133
|
+
readonly fs: HostFileApi
|
|
134
|
+
/** 当前工作目录内的文件操作 */
|
|
135
|
+
readonly workspaceFs: HostFileApi
|
|
136
|
+
registerCommand(command: PluginCommand): void
|
|
137
|
+
registerAgentTool?(tool: AgentTool): void
|
|
138
|
+
/** 依赖链上的插件 data 目录;无权限返回 null */
|
|
139
|
+
pluginData(pluginId: string): Promise<HostFileApi | null>
|
|
140
|
+
/** 宿主能力:代码执行、网页搜索/抓取 */
|
|
141
|
+
capabilities: HostCapabilities
|
|
142
|
+
/** 宿主 HTTP 服务 */
|
|
143
|
+
http: HostHttpApi
|
|
144
|
+
/** 与 Agent 会话交互 */
|
|
145
|
+
agent: HostAgentApi
|
|
146
|
+
/** 宿主进程执行(需 hostApi: exec 权限) */
|
|
147
|
+
exec: HostExecApi
|
|
148
|
+
/** 宿主伪终端(需 hostApi: pty 权限;依赖可选的 node-pty) */
|
|
149
|
+
pty: HostPtyApi
|
|
150
|
+
/** 自定义供应商与模型切换(需 hostApi: models 权限) */
|
|
151
|
+
models: HostModelsApi
|
|
152
|
+
/** 出站 HTTP/HTTPS 代理配置(需 hostApi: network 权限) */
|
|
153
|
+
network: HostNetworkApi
|
|
154
|
+
/** 插件安装 / 卸载 / 启用 / 禁用(需 hostApi: plugins 权限) */
|
|
155
|
+
plugins: HostPluginsApi
|
|
156
|
+
/** 宿主级工作区注册表(需 hostApi: workspaces 权限) */
|
|
157
|
+
workspaces: HostWorkspacesApi
|
|
158
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 宿主插件管理:列出已安装插件,安装 / 卸载 / 启用 / 禁用。
|
|
3
|
+
* 所有改动都在下次启动时生效;运行期不热加载插件。
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type HostPluginEntryStatus = "ok" | "failed" | "disabled" | "unknown"
|
|
7
|
+
|
|
8
|
+
export interface HostPluginEntry {
|
|
9
|
+
readonly id: string
|
|
10
|
+
readonly name: string
|
|
11
|
+
readonly version: string
|
|
12
|
+
readonly status: HostPluginEntryStatus
|
|
13
|
+
readonly enabled: boolean
|
|
14
|
+
/** 依赖的其它插件 id */
|
|
15
|
+
readonly deps: readonly string[]
|
|
16
|
+
readonly commands: readonly string[]
|
|
17
|
+
/** 插件根目录下的目录名 */
|
|
18
|
+
readonly dir: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface HostPluginListResult {
|
|
22
|
+
readonly plugins: readonly HostPluginEntry[]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface HostPluginInstallInput {
|
|
26
|
+
/** 原始文件名,必须是 .zip */
|
|
27
|
+
readonly filename: string
|
|
28
|
+
/** zip 包的 base64 编码 */
|
|
29
|
+
readonly dataBase64: string
|
|
30
|
+
/** 允许覆盖同名插件 */
|
|
31
|
+
readonly force?: boolean
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface HostPluginMutationResult {
|
|
35
|
+
readonly ok: boolean
|
|
36
|
+
readonly id: string
|
|
37
|
+
readonly restartRequired: boolean
|
|
38
|
+
/** true 表示已即时生效,不需要重启 */
|
|
39
|
+
readonly hot?: boolean
|
|
40
|
+
readonly changed?: boolean
|
|
41
|
+
/** 依赖目标插件的其它插件;禁用/卸载时要提示 */
|
|
42
|
+
readonly dependents?: readonly string[]
|
|
43
|
+
/** 安装时实际使用的包管理器(没有安装依赖时为 null) */
|
|
44
|
+
readonly packageManager?: string | null
|
|
45
|
+
/** 安装时是否自动安装了依赖 */
|
|
46
|
+
readonly dependenciesInstalled?: boolean
|
|
47
|
+
readonly error?: string
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface HostPluginsApi {
|
|
51
|
+
/** 列出插件根目录下的全部插件(含禁用与加载失败的) */
|
|
52
|
+
list(): Promise<HostPluginListResult>
|
|
53
|
+
/** 从 zip 安装或覆盖插件 */
|
|
54
|
+
install(input: HostPluginInstallInput): Promise<HostPluginMutationResult>
|
|
55
|
+
/** 删除插件目录;运行中的进程不受影响,重启后不再加载 */
|
|
56
|
+
remove(id: string): Promise<HostPluginMutationResult>
|
|
57
|
+
enable(id: string): Promise<HostPluginMutationResult>
|
|
58
|
+
disable(id: string): Promise<HostPluginMutationResult>
|
|
59
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 宿主伪终端(PTY)API。
|
|
3
|
+
*
|
|
4
|
+
* 需要 node-pty 提供真正的 tty:只有 tty 才有行编辑、颜色、进度条与全屏程序。
|
|
5
|
+
* node-pty 是原生模块,可能装不上(无编译器 / 无预编译包),所以它按可选依赖处理,
|
|
6
|
+
* 拿不到时 available() 返回 false,调用方退回普通管道执行。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export interface HostPtySpawnOptions {
|
|
10
|
+
/** 可执行文件,默认取登录 shell */
|
|
11
|
+
readonly file?: string
|
|
12
|
+
readonly args?: readonly string[]
|
|
13
|
+
readonly cwd: string
|
|
14
|
+
readonly env?: Record<string, string>
|
|
15
|
+
readonly cols?: number
|
|
16
|
+
readonly rows?: number
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface HostPtySession {
|
|
20
|
+
readonly sessionId: string
|
|
21
|
+
readonly pid: number
|
|
22
|
+
readonly file: string
|
|
23
|
+
readonly cwd: string
|
|
24
|
+
readonly cols: number
|
|
25
|
+
readonly rows: number
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface HostPtyChunk {
|
|
29
|
+
/** 自上次 poll 之后新增的输出,含 ANSI 控制序列 */
|
|
30
|
+
readonly chunk: string
|
|
31
|
+
readonly done: boolean
|
|
32
|
+
readonly exitCode: number | null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** PTY 后端:node-pty 原生模块,或 python3 自建的 pty */
|
|
36
|
+
export type HostPtyBackend = "node-pty" | "python-pty"
|
|
37
|
+
|
|
38
|
+
export interface HostPtyAvailability {
|
|
39
|
+
readonly available: boolean
|
|
40
|
+
/** 实际使用的后端 */
|
|
41
|
+
readonly backend?: HostPtyBackend
|
|
42
|
+
/** 不可用时的原因,便于排查(未安装 / 原生模块加载失败) */
|
|
43
|
+
readonly reason?: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface HostPtyApi {
|
|
47
|
+
/** node-pty 是否可用,以及不可用的原因 */
|
|
48
|
+
available(): Promise<HostPtyAvailability>
|
|
49
|
+
spawn(options: HostPtySpawnOptions): Promise<HostPtySession>
|
|
50
|
+
poll(sessionId: string): Promise<HostPtyChunk>
|
|
51
|
+
/** 原样写入键盘输入 */
|
|
52
|
+
write(sessionId: string, data: string): Promise<void>
|
|
53
|
+
resize(sessionId: string, cols: number, rows: number): Promise<void>
|
|
54
|
+
kill(sessionId: string): Promise<void>
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** 单会话输出缓冲上限,超出后丢弃最旧的输出 */
|
|
58
|
+
export const HOST_PTY_MAX_OUTPUT_CHARS = 512 * 1024
|
|
59
|
+
|
|
60
|
+
/** 同时保留的 PTY 会话数 */
|
|
61
|
+
export const HOST_PTY_MAX_SESSIONS = 8
|
|
62
|
+
|
|
63
|
+
/** 单次 poll 最多返回的字符数 */
|
|
64
|
+
export const HOST_PTY_MAX_POLL_CHARS = 128 * 1024
|
|
65
|
+
|
|
66
|
+
export const HOST_PTY_DEFAULT_COLS = 100
|
|
67
|
+
export const HOST_PTY_DEFAULT_ROWS = 28
|
|
68
|
+
|
|
69
|
+
/** 尺寸的合理范围:列不能太窄,行数允许缩到很小(终端面板可以拖得很矮) */
|
|
70
|
+
export const HOST_PTY_MIN_COLS = 20
|
|
71
|
+
export const HOST_PTY_MAX_COLS = 400
|
|
72
|
+
export const HOST_PTY_MIN_ROWS = 2
|
|
73
|
+
export const HOST_PTY_MAX_ROWS = 200
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// 宿主会话 API
|
|
2
|
+
|
|
3
|
+
import { getHostBridge } from "../../sandbox/bridge-state.ts"
|
|
4
|
+
import { getSession as findSession } from "../../session/registry.ts"
|
|
5
|
+
import { Session, SessionMessage } from "../../session/session.ts"
|
|
6
|
+
import type { SessionData } from "../../session/store.ts"
|
|
7
|
+
import type { SessionMeta } from "../../session/types.ts"
|
|
8
|
+
|
|
9
|
+
export { Session, SessionMessage } from "../../session/session.ts"
|
|
10
|
+
export { Workspace } from "../../workspace/index.ts"
|
|
11
|
+
|
|
12
|
+
class RemoteSession extends Session {
|
|
13
|
+
constructor(id: string) {
|
|
14
|
+
const meta: SessionMeta = {
|
|
15
|
+
type: "session",
|
|
16
|
+
version: 1,
|
|
17
|
+
id,
|
|
18
|
+
createdAt: 0,
|
|
19
|
+
cwd: "",
|
|
20
|
+
workspace: "",
|
|
21
|
+
metadata: {},
|
|
22
|
+
app: "wellspring",
|
|
23
|
+
appVersion: "1.0.0",
|
|
24
|
+
model: "",
|
|
25
|
+
}
|
|
26
|
+
const data: SessionData = {
|
|
27
|
+
meta,
|
|
28
|
+
header: { type: "session", metadata: {}, workspace: "" },
|
|
29
|
+
dir: "",
|
|
30
|
+
events: [],
|
|
31
|
+
turns: [],
|
|
32
|
+
}
|
|
33
|
+
super(data)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
override async message(
|
|
37
|
+
content: string | readonly string[],
|
|
38
|
+
type = "message",
|
|
39
|
+
): Promise<SessionMessage> {
|
|
40
|
+
const bridge = getHostBridge()
|
|
41
|
+
if (bridge === null) {
|
|
42
|
+
return await super.message(content, type)
|
|
43
|
+
}
|
|
44
|
+
await bridge.request("host.session.message", {
|
|
45
|
+
id: this.id,
|
|
46
|
+
content: typeof content === "string" ? [content] : [...content],
|
|
47
|
+
type,
|
|
48
|
+
})
|
|
49
|
+
return new SessionMessage({ sessionId: this.id, content, type })
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** 获取活跃会话;sandbox 插件通过 bridge 访问宿主注册表 */
|
|
54
|
+
export async function getSession(id: string): Promise<Session | null> {
|
|
55
|
+
const bridge = getHostBridge()
|
|
56
|
+
if (bridge === null) {
|
|
57
|
+
return findSession(id)
|
|
58
|
+
}
|
|
59
|
+
const exists = (await bridge.request("host.session.exists", { id })) as boolean
|
|
60
|
+
return exists ? new RemoteSession(id) : null
|
|
61
|
+
}
|