@supen-ai/cli 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +235 -0
- package/daemon/dist/acp-client.d.ts +42 -0
- package/daemon/dist/acp-client.d.ts.map +1 -0
- package/daemon/dist/acp-client.js +149 -0
- package/daemon/dist/acp-client.js.map +1 -0
- package/daemon/dist/acp-types.d.ts +98 -0
- package/daemon/dist/acp-types.d.ts.map +1 -0
- package/daemon/dist/acp-types.js +2 -0
- package/daemon/dist/acp-types.js.map +1 -0
- package/daemon/dist/agent-sdk/app-server-approvals.d.ts +24 -0
- package/daemon/dist/agent-sdk/app-server-approvals.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/app-server-approvals.js +99 -0
- package/daemon/dist/agent-sdk/app-server-approvals.js.map +1 -0
- package/daemon/dist/agent-sdk/app-server-stream.d.ts +8 -0
- package/daemon/dist/agent-sdk/app-server-stream.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/app-server-stream.js +328 -0
- package/daemon/dist/agent-sdk/app-server-stream.js.map +1 -0
- package/daemon/dist/agent-sdk/driver-output-ui.d.ts +9 -0
- package/daemon/dist/agent-sdk/driver-output-ui.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/driver-output-ui.js +290 -0
- package/daemon/dist/agent-sdk/driver-output-ui.js.map +1 -0
- package/daemon/dist/agent-sdk/drivers/acpx-driver.d.ts +21 -0
- package/daemon/dist/agent-sdk/drivers/acpx-driver.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/drivers/acpx-driver.js +488 -0
- package/daemon/dist/agent-sdk/drivers/acpx-driver.js.map +1 -0
- package/daemon/dist/agent-sdk/drivers/claude-acpx-driver.d.ts +5 -0
- package/daemon/dist/agent-sdk/drivers/claude-acpx-driver.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/drivers/claude-acpx-driver.js +7 -0
- package/daemon/dist/agent-sdk/drivers/claude-acpx-driver.js.map +1 -0
- package/daemon/dist/agent-sdk/drivers/claude-cli-direct-driver.d.ts +20 -0
- package/daemon/dist/agent-sdk/drivers/claude-cli-direct-driver.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/drivers/claude-cli-direct-driver.js +264 -0
- package/daemon/dist/agent-sdk/drivers/claude-cli-direct-driver.js.map +1 -0
- package/daemon/dist/agent-sdk/drivers/claude-code-driver.d.ts +29 -0
- package/daemon/dist/agent-sdk/drivers/claude-code-driver.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/drivers/claude-code-driver.js +24 -0
- package/daemon/dist/agent-sdk/drivers/claude-code-driver.js.map +1 -0
- package/daemon/dist/agent-sdk/drivers/claude-code-events.d.ts +25 -0
- package/daemon/dist/agent-sdk/drivers/claude-code-events.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/drivers/claude-code-events.js +58 -0
- package/daemon/dist/agent-sdk/drivers/claude-code-events.js.map +1 -0
- package/daemon/dist/agent-sdk/drivers/claude-code-items.d.ts +41 -0
- package/daemon/dist/agent-sdk/drivers/claude-code-items.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/drivers/claude-code-items.js +77 -0
- package/daemon/dist/agent-sdk/drivers/claude-code-items.js.map +1 -0
- package/daemon/dist/agent-sdk/drivers/codex-acpx-driver.d.ts +5 -0
- package/daemon/dist/agent-sdk/drivers/codex-acpx-driver.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/drivers/codex-acpx-driver.js +7 -0
- package/daemon/dist/agent-sdk/drivers/codex-acpx-driver.js.map +1 -0
- package/daemon/dist/agent-sdk/drivers/codex-app-server-driver.d.ts +12 -0
- package/daemon/dist/agent-sdk/drivers/codex-app-server-driver.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/drivers/codex-app-server-driver.js +484 -0
- package/daemon/dist/agent-sdk/drivers/codex-app-server-driver.js.map +1 -0
- package/daemon/dist/agent-sdk/drivers/codex-exec-driver.d.ts +28 -0
- package/daemon/dist/agent-sdk/drivers/codex-exec-driver.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/drivers/codex-exec-driver.js +219 -0
- package/daemon/dist/agent-sdk/drivers/codex-exec-driver.js.map +1 -0
- package/daemon/dist/agent-sdk/drivers/codex-exec-events.d.ts +9 -0
- package/daemon/dist/agent-sdk/drivers/codex-exec-events.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/drivers/codex-exec-events.js +82 -0
- package/daemon/dist/agent-sdk/drivers/codex-exec-events.js.map +1 -0
- package/daemon/dist/agent-sdk/drivers/codex-exec-items.d.ts +9 -0
- package/daemon/dist/agent-sdk/drivers/codex-exec-items.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/drivers/codex-exec-items.js +86 -0
- package/daemon/dist/agent-sdk/drivers/codex-exec-items.js.map +1 -0
- package/daemon/dist/agent-sdk/drivers/driver.d.ts +60 -0
- package/daemon/dist/agent-sdk/drivers/driver.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/drivers/driver.js +2 -0
- package/daemon/dist/agent-sdk/drivers/driver.js.map +1 -0
- package/daemon/dist/agent-sdk/drivers/gemini-cli-driver.d.ts +17 -0
- package/daemon/dist/agent-sdk/drivers/gemini-cli-driver.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/drivers/gemini-cli-driver.js +255 -0
- package/daemon/dist/agent-sdk/drivers/gemini-cli-driver.js.map +1 -0
- package/daemon/dist/agent-sdk/drivers/registry.d.ts +21 -0
- package/daemon/dist/agent-sdk/drivers/registry.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/drivers/registry.js +167 -0
- package/daemon/dist/agent-sdk/drivers/registry.js.map +1 -0
- package/daemon/dist/agent-sdk/index.d.ts +24 -0
- package/daemon/dist/agent-sdk/index.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/index.js +19 -0
- package/daemon/dist/agent-sdk/index.js.map +1 -0
- package/daemon/dist/agent-sdk/intelligence/contracts.d.ts +17 -0
- package/daemon/dist/agent-sdk/intelligence/contracts.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/intelligence/contracts.js +2 -0
- package/daemon/dist/agent-sdk/intelligence/contracts.js.map +1 -0
- package/daemon/dist/agent-sdk/memory/filesystem.d.ts +7 -0
- package/daemon/dist/agent-sdk/memory/filesystem.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/memory/filesystem.js +133 -0
- package/daemon/dist/agent-sdk/memory/filesystem.js.map +1 -0
- package/daemon/dist/agent-sdk/memory/subsystem.d.ts +54 -0
- package/daemon/dist/agent-sdk/memory/subsystem.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/memory/subsystem.js +106 -0
- package/daemon/dist/agent-sdk/memory/subsystem.js.map +1 -0
- package/daemon/dist/agent-sdk/session-events.d.ts +59 -0
- package/daemon/dist/agent-sdk/session-events.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/session-events.js +104 -0
- package/daemon/dist/agent-sdk/session-events.js.map +1 -0
- package/daemon/dist/agent-sdk/session-manager.d.ts +28 -0
- package/daemon/dist/agent-sdk/session-manager.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/session-manager.js +54 -0
- package/daemon/dist/agent-sdk/session-manager.js.map +1 -0
- package/daemon/dist/agent-sdk/types.d.ts +110 -0
- package/daemon/dist/agent-sdk/types.d.ts.map +1 -0
- package/daemon/dist/agent-sdk/types.js +2 -0
- package/daemon/dist/agent-sdk/types.js.map +1 -0
- package/daemon/dist/automation-event-listener.d.ts +27 -0
- package/daemon/dist/automation-event-listener.d.ts.map +1 -0
- package/daemon/dist/automation-event-listener.js +342 -0
- package/daemon/dist/automation-event-listener.js.map +1 -0
- package/daemon/dist/automation-runner.d.ts +17 -0
- package/daemon/dist/automation-runner.d.ts.map +1 -0
- package/daemon/dist/automation-runner.js +592 -0
- package/daemon/dist/automation-runner.js.map +1 -0
- package/daemon/dist/autonomy/feedback-memory.d.ts +8 -0
- package/daemon/dist/autonomy/feedback-memory.d.ts.map +1 -0
- package/daemon/dist/autonomy/feedback-memory.js +23 -0
- package/daemon/dist/autonomy/feedback-memory.js.map +1 -0
- package/daemon/dist/autonomy/intent-router.d.ts +10 -0
- package/daemon/dist/autonomy/intent-router.d.ts.map +1 -0
- package/daemon/dist/autonomy/intent-router.js +72 -0
- package/daemon/dist/autonomy/intent-router.js.map +1 -0
- package/daemon/dist/autonomy/memory-rules.d.ts +35 -0
- package/daemon/dist/autonomy/memory-rules.d.ts.map +1 -0
- package/daemon/dist/autonomy/memory-rules.js +117 -0
- package/daemon/dist/autonomy/memory-rules.js.map +1 -0
- package/daemon/dist/autonomy/proof-packet.d.ts +17 -0
- package/daemon/dist/autonomy/proof-packet.d.ts.map +1 -0
- package/daemon/dist/autonomy/proof-packet.js +28 -0
- package/daemon/dist/autonomy/proof-packet.js.map +1 -0
- package/daemon/dist/autonomy/session-autonomy.d.ts +18 -0
- package/daemon/dist/autonomy/session-autonomy.d.ts.map +1 -0
- package/daemon/dist/autonomy/session-autonomy.js +71 -0
- package/daemon/dist/autonomy/session-autonomy.js.map +1 -0
- package/daemon/dist/autonomy/source-inventory.d.ts +3 -0
- package/daemon/dist/autonomy/source-inventory.d.ts.map +1 -0
- package/daemon/dist/autonomy/source-inventory.js +84 -0
- package/daemon/dist/autonomy/source-inventory.js.map +1 -0
- package/daemon/dist/autonomy/types.d.ts +20 -0
- package/daemon/dist/autonomy/types.d.ts.map +1 -0
- package/daemon/dist/autonomy/types.js +2 -0
- package/daemon/dist/autonomy/types.js.map +1 -0
- package/daemon/dist/bin/mcp-os.d.ts +3 -0
- package/daemon/dist/bin/mcp-os.d.ts.map +1 -0
- package/daemon/dist/bin/mcp-os.js +63 -0
- package/daemon/dist/bin/mcp-os.js.map +1 -0
- package/daemon/dist/bin/mcp-scheduler.d.ts +3 -0
- package/daemon/dist/bin/mcp-scheduler.d.ts.map +1 -0
- package/daemon/dist/bin/mcp-scheduler.js +90 -0
- package/daemon/dist/bin/mcp-scheduler.js.map +1 -0
- package/daemon/dist/bin/supen-sys.d.ts +3 -0
- package/daemon/dist/bin/supen-sys.d.ts.map +1 -0
- package/daemon/dist/bin/supen-sys.js +38 -0
- package/daemon/dist/bin/supen-sys.js.map +1 -0
- package/daemon/dist/bootstrap/hub-bootstrap.d.ts +2 -0
- package/daemon/dist/bootstrap/hub-bootstrap.d.ts.map +1 -0
- package/daemon/dist/bootstrap/hub-bootstrap.js +409 -0
- package/daemon/dist/bootstrap/hub-bootstrap.js.map +1 -0
- package/daemon/dist/bootstrap/skill-bootstrap.d.ts +2 -0
- package/daemon/dist/bootstrap/skill-bootstrap.d.ts.map +1 -0
- package/daemon/dist/bootstrap/skill-bootstrap.js +92 -0
- package/daemon/dist/bootstrap/skill-bootstrap.js.map +1 -0
- package/daemon/dist/channels/acp.d.ts +23 -0
- package/daemon/dist/channels/acp.d.ts.map +1 -0
- package/daemon/dist/channels/acp.js +916 -0
- package/daemon/dist/channels/acp.js.map +1 -0
- package/daemon/dist/channels/base.d.ts +38 -0
- package/daemon/dist/channels/base.d.ts.map +1 -0
- package/daemon/dist/channels/base.js +56 -0
- package/daemon/dist/channels/base.js.map +1 -0
- package/daemon/dist/channels/http-routes.d.ts +44 -0
- package/daemon/dist/channels/http-routes.d.ts.map +1 -0
- package/daemon/dist/channels/http-routes.js +688 -0
- package/daemon/dist/channels/http-routes.js.map +1 -0
- package/daemon/dist/channels/http.d.ts +16 -0
- package/daemon/dist/channels/http.d.ts.map +1 -0
- package/daemon/dist/channels/http.js +84 -0
- package/daemon/dist/channels/http.js.map +1 -0
- package/daemon/dist/channels/index.d.ts +3 -0
- package/daemon/dist/channels/index.d.ts.map +1 -0
- package/daemon/dist/channels/index.js +7 -0
- package/daemon/dist/channels/index.js.map +1 -0
- package/daemon/dist/channels/registry.d.ts +18 -0
- package/daemon/dist/channels/registry.d.ts.map +1 -0
- package/daemon/dist/channels/registry.js +11 -0
- package/daemon/dist/channels/registry.js.map +1 -0
- package/daemon/dist/commands/builtin.d.ts +7 -0
- package/daemon/dist/commands/builtin.d.ts.map +1 -0
- package/daemon/dist/commands/builtin.js +111 -0
- package/daemon/dist/commands/builtin.js.map +1 -0
- package/daemon/dist/commands/catalog.d.ts +47 -0
- package/daemon/dist/commands/catalog.d.ts.map +1 -0
- package/daemon/dist/commands/catalog.js +487 -0
- package/daemon/dist/commands/catalog.js.map +1 -0
- package/daemon/dist/core/app.d.ts +18 -0
- package/daemon/dist/core/app.d.ts.map +1 -0
- package/daemon/dist/core/app.js +49 -0
- package/daemon/dist/core/app.js.map +1 -0
- package/daemon/dist/core/automation-timing.d.ts +10 -0
- package/daemon/dist/core/automation-timing.d.ts.map +1 -0
- package/daemon/dist/core/automation-timing.js +211 -0
- package/daemon/dist/core/automation-timing.js.map +1 -0
- package/daemon/dist/core/codex-subscription.d.ts +8 -0
- package/daemon/dist/core/codex-subscription.d.ts.map +1 -0
- package/daemon/dist/core/codex-subscription.js +150 -0
- package/daemon/dist/core/codex-subscription.js.map +1 -0
- package/daemon/dist/core/command-hub.d.ts +22 -0
- package/daemon/dist/core/command-hub.d.ts.map +1 -0
- package/daemon/dist/core/command-hub.js +59 -0
- package/daemon/dist/core/command-hub.js.map +1 -0
- package/daemon/dist/core/config.d.ts +146 -0
- package/daemon/dist/core/config.d.ts.map +1 -0
- package/daemon/dist/core/config.js +663 -0
- package/daemon/dist/core/config.js.map +1 -0
- package/daemon/dist/core/control-commands.d.ts +17 -0
- package/daemon/dist/core/control-commands.d.ts.map +1 -0
- package/daemon/dist/core/control-commands.js +35 -0
- package/daemon/dist/core/control-commands.js.map +1 -0
- package/daemon/dist/core/control-log.d.ts +17 -0
- package/daemon/dist/core/control-log.d.ts.map +1 -0
- package/daemon/dist/core/control-log.js +67 -0
- package/daemon/dist/core/control-log.js.map +1 -0
- package/daemon/dist/core/cortex.d.ts +53 -0
- package/daemon/dist/core/cortex.d.ts.map +1 -0
- package/daemon/dist/core/cortex.js +1690 -0
- package/daemon/dist/core/cortex.js.map +1 -0
- package/daemon/dist/core/daemon-lock.d.ts +16 -0
- package/daemon/dist/core/daemon-lock.d.ts.map +1 -0
- package/daemon/dist/core/daemon-lock.js +285 -0
- package/daemon/dist/core/daemon-lock.js.map +1 -0
- package/daemon/dist/core/dispatcher.d.ts +42 -0
- package/daemon/dist/core/dispatcher.d.ts.map +1 -0
- package/daemon/dist/core/dispatcher.js +173 -0
- package/daemon/dist/core/dispatcher.js.map +1 -0
- package/daemon/dist/core/enrollment.d.ts +41 -0
- package/daemon/dist/core/enrollment.d.ts.map +1 -0
- package/daemon/dist/core/enrollment.js +195 -0
- package/daemon/dist/core/enrollment.js.map +1 -0
- package/daemon/dist/core/env.d.ts +109 -0
- package/daemon/dist/core/env.d.ts.map +1 -0
- package/daemon/dist/core/env.js +329 -0
- package/daemon/dist/core/env.js.map +1 -0
- package/daemon/dist/core/gateway-config.d.ts +16 -0
- package/daemon/dist/core/gateway-config.d.ts.map +1 -0
- package/daemon/dist/core/gateway-config.js +103 -0
- package/daemon/dist/core/gateway-config.js.map +1 -0
- package/daemon/dist/core/gateway-protocol.d.ts +80 -0
- package/daemon/dist/core/gateway-protocol.d.ts.map +1 -0
- package/daemon/dist/core/gateway-protocol.js +2 -0
- package/daemon/dist/core/gateway-protocol.js.map +1 -0
- package/daemon/dist/core/gateway-routing-config.d.ts +21 -0
- package/daemon/dist/core/gateway-routing-config.d.ts.map +1 -0
- package/daemon/dist/core/gateway-routing-config.js +56 -0
- package/daemon/dist/core/gateway-routing-config.js.map +1 -0
- package/daemon/dist/core/gateway.d.ts +124 -0
- package/daemon/dist/core/gateway.d.ts.map +1 -0
- package/daemon/dist/core/gateway.js +887 -0
- package/daemon/dist/core/gateway.js.map +1 -0
- package/daemon/dist/core/hub-snapshot.d.ts +42 -0
- package/daemon/dist/core/hub-snapshot.d.ts.map +1 -0
- package/daemon/dist/core/hub-snapshot.js +125 -0
- package/daemon/dist/core/hub-snapshot.js.map +1 -0
- package/daemon/dist/core/interrupts.d.ts +7 -0
- package/daemon/dist/core/interrupts.d.ts.map +1 -0
- package/daemon/dist/core/interrupts.js +28 -0
- package/daemon/dist/core/interrupts.js.map +1 -0
- package/daemon/dist/core/logger.d.ts +3 -0
- package/daemon/dist/core/logger.d.ts.map +1 -0
- package/daemon/dist/core/logger.js +91 -0
- package/daemon/dist/core/logger.js.map +1 -0
- package/daemon/dist/core/loop-guard.d.ts +27 -0
- package/daemon/dist/core/loop-guard.d.ts.map +1 -0
- package/daemon/dist/core/loop-guard.js +47 -0
- package/daemon/dist/core/loop-guard.js.map +1 -0
- package/daemon/dist/core/observable-logging.d.ts +43 -0
- package/daemon/dist/core/observable-logging.d.ts.map +1 -0
- package/daemon/dist/core/observable-logging.js +77 -0
- package/daemon/dist/core/observable-logging.js.map +1 -0
- package/daemon/dist/core/pairing.d.ts +51 -0
- package/daemon/dist/core/pairing.d.ts.map +1 -0
- package/daemon/dist/core/pairing.js +207 -0
- package/daemon/dist/core/pairing.js.map +1 -0
- package/daemon/dist/core/progress.d.ts +32 -0
- package/daemon/dist/core/progress.d.ts.map +1 -0
- package/daemon/dist/core/progress.js +145 -0
- package/daemon/dist/core/progress.js.map +1 -0
- package/daemon/dist/core/protocol-adapter.d.ts +14 -0
- package/daemon/dist/core/protocol-adapter.d.ts.map +1 -0
- package/daemon/dist/core/protocol-adapter.js +472 -0
- package/daemon/dist/core/protocol-adapter.js.map +1 -0
- package/daemon/dist/core/sdk-wrapper.d.ts +36 -0
- package/daemon/dist/core/sdk-wrapper.d.ts.map +1 -0
- package/daemon/dist/core/sdk-wrapper.js +533 -0
- package/daemon/dist/core/sdk-wrapper.js.map +1 -0
- package/daemon/dist/core/security.d.ts +10 -0
- package/daemon/dist/core/security.d.ts.map +1 -0
- package/daemon/dist/core/security.js +95 -0
- package/daemon/dist/core/security.js.map +1 -0
- package/daemon/dist/core/space-env.d.ts +15 -0
- package/daemon/dist/core/space-env.d.ts.map +1 -0
- package/daemon/dist/core/space-env.js +182 -0
- package/daemon/dist/core/space-env.js.map +1 -0
- package/daemon/dist/core/status-inspector.d.ts +31 -0
- package/daemon/dist/core/status-inspector.d.ts.map +1 -0
- package/daemon/dist/core/status-inspector.js +35 -0
- package/daemon/dist/core/status-inspector.js.map +1 -0
- package/daemon/dist/core/storage-paths.d.ts +30 -0
- package/daemon/dist/core/storage-paths.d.ts.map +1 -0
- package/daemon/dist/core/storage-paths.js +84 -0
- package/daemon/dist/core/storage-paths.js.map +1 -0
- package/daemon/dist/core/store.d.ts +256 -0
- package/daemon/dist/core/store.d.ts.map +1 -0
- package/daemon/dist/core/store.js +2956 -0
- package/daemon/dist/core/store.js.map +1 -0
- package/daemon/dist/core/streaming.d.ts +24 -0
- package/daemon/dist/core/streaming.d.ts.map +1 -0
- package/daemon/dist/core/streaming.js +57 -0
- package/daemon/dist/core/streaming.js.map +1 -0
- package/daemon/dist/core/task-artifacts.d.ts +17 -0
- package/daemon/dist/core/task-artifacts.d.ts.map +1 -0
- package/daemon/dist/core/task-artifacts.js +104 -0
- package/daemon/dist/core/task-artifacts.js.map +1 -0
- package/daemon/dist/core/thread-event-log.d.ts +54 -0
- package/daemon/dist/core/thread-event-log.d.ts.map +1 -0
- package/daemon/dist/core/thread-event-log.js +218 -0
- package/daemon/dist/core/thread-event-log.js.map +1 -0
- package/daemon/dist/core/thread-runtime-state.d.ts +53 -0
- package/daemon/dist/core/thread-runtime-state.d.ts.map +1 -0
- package/daemon/dist/core/thread-runtime-state.js +271 -0
- package/daemon/dist/core/thread-runtime-state.js.map +1 -0
- package/daemon/dist/core/types.d.ts +552 -0
- package/daemon/dist/core/types.d.ts.map +1 -0
- package/daemon/dist/core/types.js +2 -0
- package/daemon/dist/core/types.js.map +1 -0
- package/daemon/dist/core/utils.d.ts +5 -0
- package/daemon/dist/core/utils.d.ts.map +1 -0
- package/daemon/dist/core/utils.js +35 -0
- package/daemon/dist/core/utils.js.map +1 -0
- package/daemon/dist/http/command-catalog.d.ts +3 -0
- package/daemon/dist/http/command-catalog.d.ts.map +1 -0
- package/daemon/dist/http/command-catalog.js +2 -0
- package/daemon/dist/http/command-catalog.js.map +1 -0
- package/daemon/dist/http/context.d.ts +18 -0
- package/daemon/dist/http/context.d.ts.map +1 -0
- package/daemon/dist/http/context.js +121 -0
- package/daemon/dist/http/context.js.map +1 -0
- package/daemon/dist/http/office-preview.d.ts +10 -0
- package/daemon/dist/http/office-preview.d.ts.map +1 -0
- package/daemon/dist/http/office-preview.js +234 -0
- package/daemon/dist/http/office-preview.js.map +1 -0
- package/daemon/dist/http/response.d.ts +5 -0
- package/daemon/dist/http/response.d.ts.map +1 -0
- package/daemon/dist/http/response.js +37 -0
- package/daemon/dist/http/response.js.map +1 -0
- package/daemon/dist/http/router.d.ts +4 -0
- package/daemon/dist/http/router.d.ts.map +1 -0
- package/daemon/dist/http/router.js +57 -0
- package/daemon/dist/http/router.js.map +1 -0
- package/daemon/dist/http/routes/agents.d.ts +4 -0
- package/daemon/dist/http/routes/agents.d.ts.map +1 -0
- package/daemon/dist/http/routes/agents.js +747 -0
- package/daemon/dist/http/routes/agents.js.map +1 -0
- package/daemon/dist/http/routes/automations.d.ts +6 -0
- package/daemon/dist/http/routes/automations.d.ts.map +1 -0
- package/daemon/dist/http/routes/automations.js +530 -0
- package/daemon/dist/http/routes/automations.js.map +1 -0
- package/daemon/dist/http/routes/autonomy.d.ts +4 -0
- package/daemon/dist/http/routes/autonomy.d.ts.map +1 -0
- package/daemon/dist/http/routes/autonomy.js +78 -0
- package/daemon/dist/http/routes/autonomy.js.map +1 -0
- package/daemon/dist/http/routes/chat-input.d.ts +18 -0
- package/daemon/dist/http/routes/chat-input.d.ts.map +1 -0
- package/daemon/dist/http/routes/chat-input.js +122 -0
- package/daemon/dist/http/routes/chat-input.js.map +1 -0
- package/daemon/dist/http/routes/plugins.d.ts +5 -0
- package/daemon/dist/http/routes/plugins.d.ts.map +1 -0
- package/daemon/dist/http/routes/plugins.js +221 -0
- package/daemon/dist/http/routes/plugins.js.map +1 -0
- package/daemon/dist/http/routes/rpc.d.ts +28 -0
- package/daemon/dist/http/routes/rpc.d.ts.map +1 -0
- package/daemon/dist/http/routes/rpc.js +790 -0
- package/daemon/dist/http/routes/rpc.js.map +1 -0
- package/daemon/dist/http/routes/sessions.d.ts +11 -0
- package/daemon/dist/http/routes/sessions.d.ts.map +1 -0
- package/daemon/dist/http/routes/sessions.js +963 -0
- package/daemon/dist/http/routes/sessions.js.map +1 -0
- package/daemon/dist/http/routes/skills.d.ts +5 -0
- package/daemon/dist/http/routes/skills.d.ts.map +1 -0
- package/daemon/dist/http/routes/skills.js +420 -0
- package/daemon/dist/http/routes/skills.js.map +1 -0
- package/daemon/dist/http/routes/system.d.ts +64 -0
- package/daemon/dist/http/routes/system.d.ts.map +1 -0
- package/daemon/dist/http/routes/system.js +2676 -0
- package/daemon/dist/http/routes/system.js.map +1 -0
- package/daemon/dist/http/stream.d.ts +11 -0
- package/daemon/dist/http/stream.d.ts.map +1 -0
- package/daemon/dist/http/stream.js +100 -0
- package/daemon/dist/http/stream.js.map +1 -0
- package/daemon/dist/http/thread-stream.d.ts +10 -0
- package/daemon/dist/http/thread-stream.d.ts.map +1 -0
- package/daemon/dist/http/thread-stream.js +50 -0
- package/daemon/dist/http/thread-stream.js.map +1 -0
- package/daemon/dist/http/thread-title.d.ts +12 -0
- package/daemon/dist/http/thread-title.d.ts.map +1 -0
- package/daemon/dist/http/thread-title.js +122 -0
- package/daemon/dist/http/thread-title.js.map +1 -0
- package/daemon/dist/http/utils.d.ts +2 -0
- package/daemon/dist/http/utils.d.ts.map +1 -0
- package/daemon/dist/http/utils.js +18 -0
- package/daemon/dist/http/utils.js.map +1 -0
- package/daemon/dist/http/websocket.d.ts +5 -0
- package/daemon/dist/http/websocket.d.ts.map +1 -0
- package/daemon/dist/http/websocket.js +100 -0
- package/daemon/dist/http/websocket.js.map +1 -0
- package/daemon/dist/index.d.ts +35 -0
- package/daemon/dist/index.d.ts.map +1 -0
- package/daemon/dist/index.js +1582 -0
- package/daemon/dist/index.js.map +1 -0
- package/daemon/dist/mcp/aggregate-config.d.ts +16 -0
- package/daemon/dist/mcp/aggregate-config.d.ts.map +1 -0
- package/daemon/dist/mcp/aggregate-config.js +97 -0
- package/daemon/dist/mcp/aggregate-config.js.map +1 -0
- package/daemon/dist/mcp/client.d.ts +94 -0
- package/daemon/dist/mcp/client.d.ts.map +1 -0
- package/daemon/dist/mcp/client.js +207 -0
- package/daemon/dist/mcp/client.js.map +1 -0
- package/daemon/dist/mcp/default-servers.d.ts +35 -0
- package/daemon/dist/mcp/default-servers.d.ts.map +1 -0
- package/daemon/dist/mcp/default-servers.js +209 -0
- package/daemon/dist/mcp/default-servers.js.map +1 -0
- package/daemon/dist/mcp/gateway-client.d.ts +58 -0
- package/daemon/dist/mcp/gateway-client.d.ts.map +1 -0
- package/daemon/dist/mcp/gateway-client.js +181 -0
- package/daemon/dist/mcp/gateway-client.js.map +1 -0
- package/daemon/dist/mcp/index.d.ts +26 -0
- package/daemon/dist/mcp/index.d.ts.map +1 -0
- package/daemon/dist/mcp/index.js +50 -0
- package/daemon/dist/mcp/index.js.map +1 -0
- package/daemon/dist/mcp/settings.d.ts +3 -0
- package/daemon/dist/mcp/settings.d.ts.map +1 -0
- package/daemon/dist/mcp/settings.js +60 -0
- package/daemon/dist/mcp/settings.js.map +1 -0
- package/daemon/dist/mcp/tools.d.ts +21 -0
- package/daemon/dist/mcp/tools.d.ts.map +1 -0
- package/daemon/dist/mcp/tools.js +136 -0
- package/daemon/dist/mcp/tools.js.map +1 -0
- package/daemon/dist/plugins/catalog.d.ts +10 -0
- package/daemon/dist/plugins/catalog.d.ts.map +1 -0
- package/daemon/dist/plugins/catalog.js +304 -0
- package/daemon/dist/plugins/catalog.js.map +1 -0
- package/daemon/dist/plugins/hub.d.ts +42 -0
- package/daemon/dist/plugins/hub.d.ts.map +1 -0
- package/daemon/dist/plugins/hub.js +812 -0
- package/daemon/dist/plugins/hub.js.map +1 -0
- package/daemon/dist/plugins/types.d.ts +144 -0
- package/daemon/dist/plugins/types.d.ts.map +1 -0
- package/daemon/dist/plugins/types.js +2 -0
- package/daemon/dist/plugins/types.js.map +1 -0
- package/daemon/dist/router.d.ts +13 -0
- package/daemon/dist/router.d.ts.map +1 -0
- package/daemon/dist/router.js +43 -0
- package/daemon/dist/router.js.map +1 -0
- package/daemon/dist/skills/adapter.d.ts +4 -0
- package/daemon/dist/skills/adapter.d.ts.map +1 -0
- package/daemon/dist/skills/adapter.js +141 -0
- package/daemon/dist/skills/adapter.js.map +1 -0
- package/daemon/dist/skills/allowlist.d.ts +20 -0
- package/daemon/dist/skills/allowlist.d.ts.map +1 -0
- package/daemon/dist/skills/allowlist.js +52 -0
- package/daemon/dist/skills/allowlist.js.map +1 -0
- package/daemon/dist/skills/catalog.d.ts +26 -0
- package/daemon/dist/skills/catalog.d.ts.map +1 -0
- package/daemon/dist/skills/catalog.js +274 -0
- package/daemon/dist/skills/catalog.js.map +1 -0
- package/daemon/dist/skills/claude_code.d.ts +25 -0
- package/daemon/dist/skills/claude_code.d.ts.map +1 -0
- package/daemon/dist/skills/claude_code.js +49 -0
- package/daemon/dist/skills/claude_code.js.map +1 -0
- package/daemon/dist/skills/commands.d.ts +3 -0
- package/daemon/dist/skills/commands.d.ts.map +1 -0
- package/daemon/dist/skills/commands.js +689 -0
- package/daemon/dist/skills/commands.js.map +1 -0
- package/daemon/dist/skills/enabled.d.ts +7 -0
- package/daemon/dist/skills/enabled.d.ts.map +1 -0
- package/daemon/dist/skills/enabled.js +37 -0
- package/daemon/dist/skills/enabled.js.map +1 -0
- package/daemon/dist/skills/hub.d.ts +35 -0
- package/daemon/dist/skills/hub.d.ts.map +1 -0
- package/daemon/dist/skills/hub.js +574 -0
- package/daemon/dist/skills/hub.js.map +1 -0
- package/daemon/dist/skills/loader.d.ts +24 -0
- package/daemon/dist/skills/loader.d.ts.map +1 -0
- package/daemon/dist/skills/loader.js +693 -0
- package/daemon/dist/skills/loader.js.map +1 -0
- package/daemon/dist/skills/mcp-config.d.ts +8 -0
- package/daemon/dist/skills/mcp-config.d.ts.map +1 -0
- package/daemon/dist/skills/mcp-config.js +110 -0
- package/daemon/dist/skills/mcp-config.js.map +1 -0
- package/daemon/dist/skills/parser.d.ts +3 -0
- package/daemon/dist/skills/parser.d.ts.map +1 -0
- package/daemon/dist/skills/parser.js +279 -0
- package/daemon/dist/skills/parser.js.map +1 -0
- package/daemon/dist/skills/registry.d.ts +2 -0
- package/daemon/dist/skills/registry.d.ts.map +1 -0
- package/daemon/dist/skills/registry.js +2 -0
- package/daemon/dist/skills/registry.js.map +1 -0
- package/daemon/dist/skills/runtime-contract.d.ts +3 -0
- package/daemon/dist/skills/runtime-contract.d.ts.map +1 -0
- package/daemon/dist/skills/runtime-contract.js +92 -0
- package/daemon/dist/skills/runtime-contract.js.map +1 -0
- package/daemon/dist/skills/runtime.d.ts +28 -0
- package/daemon/dist/skills/runtime.d.ts.map +1 -0
- package/daemon/dist/skills/runtime.js +286 -0
- package/daemon/dist/skills/runtime.js.map +1 -0
- package/daemon/dist/skills/types.d.ts +228 -0
- package/daemon/dist/skills/types.d.ts.map +1 -0
- package/daemon/dist/skills/types.js +2 -0
- package/daemon/dist/skills/types.js.map +1 -0
- package/daemon/dist/start.d.ts +6 -0
- package/daemon/dist/start.d.ts.map +1 -0
- package/daemon/dist/start.js +19 -0
- package/daemon/dist/start.js.map +1 -0
- package/daemon/dist/sub-agent.d.ts +46 -0
- package/daemon/dist/sub-agent.d.ts.map +1 -0
- package/daemon/dist/sub-agent.js +120 -0
- package/daemon/dist/sub-agent.js.map +1 -0
- package/daemon/dist/sync/supabase-sync.d.ts +16 -0
- package/daemon/dist/sync/supabase-sync.d.ts.map +1 -0
- package/daemon/dist/sync/supabase-sync.js +240 -0
- package/daemon/dist/sync/supabase-sync.js.map +1 -0
- package/daemon/dist/task-executor.d.ts +6 -0
- package/daemon/dist/task-executor.d.ts.map +1 -0
- package/daemon/dist/task-executor.js +31 -0
- package/daemon/dist/task-executor.js.map +1 -0
- package/daemon/dist/tools/automations.d.ts +57 -0
- package/daemon/dist/tools/automations.d.ts.map +1 -0
- package/daemon/dist/tools/automations.js +94 -0
- package/daemon/dist/tools/automations.js.map +1 -0
- package/daemon/dist/tools/built-ins.d.ts +112 -0
- package/daemon/dist/tools/built-ins.d.ts.map +1 -0
- package/daemon/dist/tools/built-ins.js +251 -0
- package/daemon/dist/tools/built-ins.js.map +1 -0
- package/daemon/dist/tools/index.d.ts +287 -0
- package/daemon/dist/tools/index.d.ts.map +1 -0
- package/daemon/dist/tools/index.js +86 -0
- package/daemon/dist/tools/index.js.map +1 -0
- package/daemon/dist/tools/shell.d.ts +15 -0
- package/daemon/dist/tools/shell.d.ts.map +1 -0
- package/daemon/dist/tools/shell.js +46 -0
- package/daemon/dist/tools/shell.js.map +1 -0
- package/daemon/dist/tools/skill-tools.d.ts +23 -0
- package/daemon/dist/tools/skill-tools.d.ts.map +1 -0
- package/daemon/dist/tools/skill-tools.js +64 -0
- package/daemon/dist/tools/skill-tools.js.map +1 -0
- package/daemon/dist/tools/system.d.ts +36 -0
- package/daemon/dist/tools/system.d.ts.map +1 -0
- package/daemon/dist/tools/system.js +54 -0
- package/daemon/dist/tools/system.js.map +1 -0
- package/daemon/dist/tools/types.d.ts +11 -0
- package/daemon/dist/tools/types.d.ts.map +1 -0
- package/daemon/dist/tools/types.js +2 -0
- package/daemon/dist/tools/types.js.map +1 -0
- package/daemon/scripts/browser-smoke.mjs +125 -0
- package/daemon/scripts/supen-daemon.js +15 -0
- package/dist/agent.d.ts +11 -0
- package/dist/agent.js +159 -0
- package/dist/agent.js.map +1 -0
- package/dist/auth/login.d.ts +20 -0
- package/dist/auth/login.js +151 -0
- package/dist/auth/login.js.map +1 -0
- package/dist/auth/logout.d.ts +5 -0
- package/dist/auth/logout.js +19 -0
- package/dist/auth/logout.js.map +1 -0
- package/dist/auth/store.d.ts +37 -0
- package/dist/auth/store.js +80 -0
- package/dist/auth/store.js.map +1 -0
- package/dist/auth/whoami.d.ts +5 -0
- package/dist/auth/whoami.js +24 -0
- package/dist/auth/whoami.js.map +1 -0
- package/dist/backend.d.ts +8 -0
- package/dist/backend.js +148 -0
- package/dist/backend.js.map +1 -0
- package/dist/bootstrap.d.ts +13 -0
- package/dist/bootstrap.js +230 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/chat.d.ts +13 -0
- package/dist/chat.js +255 -0
- package/dist/chat.js.map +1 -0
- package/dist/commands.d.ts +48 -0
- package/dist/commands.js +273 -0
- package/dist/commands.js.map +1 -0
- package/dist/computer.d.ts +2 -0
- package/dist/computer.js +510 -0
- package/dist/computer.js.map +1 -0
- package/dist/config.d.ts +11 -0
- package/dist/config.js +149 -0
- package/dist/config.js.map +1 -0
- package/dist/daemon-manage.d.ts +29 -0
- package/dist/daemon-manage.js +255 -0
- package/dist/daemon-manage.js.map +1 -0
- package/dist/daemon.d.ts +15 -0
- package/dist/daemon.js +205 -0
- package/dist/daemon.js.map +1 -0
- package/dist/doctor.d.ts +13 -0
- package/dist/doctor.js +323 -0
- package/dist/doctor.js.map +1 -0
- package/dist/enroll.d.ts +7 -0
- package/dist/enroll.js +154 -0
- package/dist/enroll.js.map +1 -0
- package/dist/env.d.ts +10 -0
- package/dist/env.js +363 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.js +141 -0
- package/dist/index.js.map +1 -0
- package/dist/knowledge.d.ts +3 -0
- package/dist/knowledge.js +1581 -0
- package/dist/knowledge.js.map +1 -0
- package/dist/mcp.d.ts +11 -0
- package/dist/mcp.js +137 -0
- package/dist/mcp.js.map +1 -0
- package/dist/model.d.ts +8 -0
- package/dist/model.js +192 -0
- package/dist/model.js.map +1 -0
- package/dist/pairing.d.ts +21 -0
- package/dist/pairing.js +376 -0
- package/dist/pairing.js.map +1 -0
- package/dist/repl-events.d.ts +60 -0
- package/dist/repl-events.js +89 -0
- package/dist/repl-events.js.map +1 -0
- package/dist/repl-renderer.d.ts +37 -0
- package/dist/repl-renderer.js +140 -0
- package/dist/repl-renderer.js.map +1 -0
- package/dist/repl.d.ts +52 -0
- package/dist/repl.js +624 -0
- package/dist/repl.js.map +1 -0
- package/dist/service.d.ts +8 -0
- package/dist/service.js +238 -0
- package/dist/service.js.map +1 -0
- package/dist/skills.d.ts +14 -0
- package/dist/skills.js +423 -0
- package/dist/skills.js.map +1 -0
- package/dist/sse.d.ts +15 -0
- package/dist/sse.js +166 -0
- package/dist/sse.js.map +1 -0
- package/dist/thread.d.ts +9 -0
- package/dist/thread.js +152 -0
- package/dist/thread.js.map +1 -0
- package/dist/transport/computer-api.d.ts +1 -0
- package/dist/transport/computer-api.js +20 -0
- package/dist/transport/computer-api.js.map +1 -0
- package/dist/transport/gateway.d.ts +23 -0
- package/dist/transport/gateway.js +161 -0
- package/dist/transport/gateway.js.map +1 -0
- package/dist/transport/index.d.ts +27 -0
- package/dist/transport/index.js +77 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/local.d.ts +20 -0
- package/dist/transport/local.js +138 -0
- package/dist/transport/local.js.map +1 -0
- package/dist/transport/types.d.ts +42 -0
- package/dist/transport/types.js +11 -0
- package/dist/transport/types.js.map +1 -0
- package/dist/ui/app.d.ts +7 -0
- package/dist/ui/app.js +192 -0
- package/dist/ui/app.js.map +1 -0
- package/dist/ui/history-item.d.ts +9 -0
- package/dist/ui/history-item.js +35 -0
- package/dist/ui/history-item.js.map +1 -0
- package/dist/ui/input-bar.d.ts +17 -0
- package/dist/ui/input-bar.js +67 -0
- package/dist/ui/input-bar.js.map +1 -0
- package/dist/ui/streaming-view.d.ts +6 -0
- package/dist/ui/streaming-view.js +6 -0
- package/dist/ui/streaming-view.js.map +1 -0
- package/dist/ui/thread-input-history.d.ts +18 -0
- package/dist/ui/thread-input-history.js +67 -0
- package/dist/ui/thread-input-history.js.map +1 -0
- package/dist/utils.d.ts +17 -0
- package/dist/utils.js +80 -0
- package/dist/utils.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,747 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { randomUUID } from 'crypto';
|
|
4
|
+
import { ONLYOFFICE_SOURCE_BASE_URL, agentPaths, resolveSpaceKnowledgeRoot } from '../../core/config.js';
|
|
5
|
+
import { spacePaths } from '../../core/storage-paths.js';
|
|
6
|
+
import { logger } from '../../core/logger.js';
|
|
7
|
+
import { assertSafePathSegment, isPathWithin } from '../../core/security.js';
|
|
8
|
+
import { createAgent, deleteAgent, getAllAgents, getAgent, getAgentStorage, updateAgent, } from '../../core/store.js';
|
|
9
|
+
import { writeJson, writeProtocolError, readJsonBody, } from '../response.js';
|
|
10
|
+
import { inferMimeType } from '../utils.js';
|
|
11
|
+
import { diskAllowlistForConfig, normalizeAgentSkillsConfig } from '../../skills/allowlist.js';
|
|
12
|
+
import { ensureOfficePreviewPdf, ensureSpreadsheetPreviewXlsx, isOfficePreviewPath, issuePreviewToken, resolvePreviewToken, } from '../office-preview.js';
|
|
13
|
+
const OS_METADATA_FILENAMES = new Set([
|
|
14
|
+
'.DS_Store',
|
|
15
|
+
'Thumbs.db',
|
|
16
|
+
'desktop.ini',
|
|
17
|
+
]);
|
|
18
|
+
function isOsMetadataFile(name) {
|
|
19
|
+
return OS_METADATA_FILENAMES.has(name);
|
|
20
|
+
}
|
|
21
|
+
const TASK_INTERNAL_ENTRIES = new Set(['.claude', '.supen', 'knowledge']);
|
|
22
|
+
function isHiddenWorkspaceEntry(root, name) {
|
|
23
|
+
if (isOsMetadataFile(name))
|
|
24
|
+
return true;
|
|
25
|
+
return root === 'tasks' && TASK_INTERNAL_ENTRIES.has(name);
|
|
26
|
+
}
|
|
27
|
+
const WORKSPACE_ROOT_CATEGORIES = new Set([
|
|
28
|
+
'knowledge',
|
|
29
|
+
'uploads',
|
|
30
|
+
'outputs',
|
|
31
|
+
'tasks',
|
|
32
|
+
'runs',
|
|
33
|
+
]);
|
|
34
|
+
function parseWorkspaceRootCategory(value) {
|
|
35
|
+
if (value == null || value === '')
|
|
36
|
+
return 'knowledge';
|
|
37
|
+
if (typeof value !== 'string')
|
|
38
|
+
return null;
|
|
39
|
+
const normalized = value.trim().toLowerCase();
|
|
40
|
+
if (normalized === 'drive')
|
|
41
|
+
return 'knowledge';
|
|
42
|
+
if (normalized === 'inbox')
|
|
43
|
+
return 'uploads';
|
|
44
|
+
if (normalized === 'artifacts')
|
|
45
|
+
return 'outputs';
|
|
46
|
+
if (WORKSPACE_ROOT_CATEGORIES.has(normalized)) {
|
|
47
|
+
return normalized;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
function agentSpaceId(agentId) {
|
|
52
|
+
const record = getAgent(agentId);
|
|
53
|
+
const recordSpaceId = typeof record?.space_id === 'string' ? record.space_id.trim() : '';
|
|
54
|
+
return recordSpaceId || process.env.SUPEN_SPACE_ID || 'local';
|
|
55
|
+
}
|
|
56
|
+
function workspaceRootForAgent(agentId, root, knowledgeId) {
|
|
57
|
+
if (root === 'knowledge') {
|
|
58
|
+
if (knowledgeId) {
|
|
59
|
+
return resolveSpaceKnowledgeRoot(agentSpaceId(agentId), knowledgeId).root;
|
|
60
|
+
}
|
|
61
|
+
return agentPaths(agentId).workspace;
|
|
62
|
+
}
|
|
63
|
+
const space = spacePaths(agentSpaceId(agentId));
|
|
64
|
+
if (root === 'uploads')
|
|
65
|
+
return space.uploads;
|
|
66
|
+
if (root === 'outputs')
|
|
67
|
+
return space.outputs;
|
|
68
|
+
if (root === 'tasks')
|
|
69
|
+
return space.tasks;
|
|
70
|
+
return space.runtime;
|
|
71
|
+
}
|
|
72
|
+
function writeInvalidWorkspaceRoot(res) {
|
|
73
|
+
writeProtocolError(res, 400, 'input_error', 'invalid_workspace_root', 'root must be one of: knowledge, uploads, outputs, tasks.');
|
|
74
|
+
}
|
|
75
|
+
function buildSpaceLocalPath(req, tail) {
|
|
76
|
+
const spaceId = typeof req.headers['x-computer-id'] === 'string'
|
|
77
|
+
? req.headers['x-computer-id'].trim()
|
|
78
|
+
: '';
|
|
79
|
+
const normalizedTail = tail.startsWith('/') ? tail : `/${tail}`;
|
|
80
|
+
return spaceId
|
|
81
|
+
? `/api/computers/${encodeURIComponent(spaceId)}${normalizedTail}`
|
|
82
|
+
: `/api/computers/local${normalizedTail}`;
|
|
83
|
+
}
|
|
84
|
+
function buildRequestAbsoluteUrl(req, localPath) {
|
|
85
|
+
const configuredBaseUrl = ONLYOFFICE_SOURCE_BASE_URL.trim().replace(/\/+$/, '');
|
|
86
|
+
if (configuredBaseUrl)
|
|
87
|
+
return `${configuredBaseUrl}${localPath}`;
|
|
88
|
+
const forwardedProto = typeof req.headers['x-forwarded-proto'] === 'string'
|
|
89
|
+
? req.headers['x-forwarded-proto'].split(',')[0]?.trim()
|
|
90
|
+
: '';
|
|
91
|
+
const proto = forwardedProto || (req.socket.encrypted ? 'https' : 'http');
|
|
92
|
+
const host = typeof req.headers['x-forwarded-host'] === 'string'
|
|
93
|
+
? req.headers['x-forwarded-host'].split(',')[0]?.trim()
|
|
94
|
+
: req.headers.host;
|
|
95
|
+
if (!host)
|
|
96
|
+
throw new Error('Unable to build an absolute source URL for OnlyOffice conversion.');
|
|
97
|
+
return `${proto}://${host}${localPath}`;
|
|
98
|
+
}
|
|
99
|
+
export async function handleAgentsRoutes(req, res, url, pathname, method) {
|
|
100
|
+
const previewSessionMatch = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/artifacts\/preview-session$/);
|
|
101
|
+
if (previewSessionMatch && method === 'POST') {
|
|
102
|
+
const agentId = decodeURIComponent(previewSessionMatch[1]);
|
|
103
|
+
const body = await readJsonBody(req);
|
|
104
|
+
const relPath = typeof body?.path === 'string' ? decodeURIComponent(body.path) : '';
|
|
105
|
+
const rootCategory = parseWorkspaceRootCategory(body?.root ?? url.searchParams.get('root'));
|
|
106
|
+
const knowledgeId = typeof body?.knowledge_id === 'string' ? body.knowledge_id : url.searchParams.get('knowledge_id');
|
|
107
|
+
if (!rootCategory) {
|
|
108
|
+
writeInvalidWorkspaceRoot(res);
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
if (!relPath) {
|
|
112
|
+
writeProtocolError(res, 400, 'input_error', 'path_required', 'path is required.');
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
const normalized = path.normalize(relPath);
|
|
116
|
+
if (normalized.startsWith('..') || path.isAbsolute(normalized)) {
|
|
117
|
+
writeProtocolError(res, 400, 'input_error', 'invalid_path', 'Invalid artifact path.');
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
const workspace = workspaceRootForAgent(agentId, rootCategory, knowledgeId);
|
|
121
|
+
const filePath = path.join(workspace, normalized);
|
|
122
|
+
if (!isPathWithin(workspace, filePath)) {
|
|
123
|
+
writeProtocolError(res, 403, 'input_error', 'path_outside_workspace', 'Path outside workspace.');
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
if (!fs.existsSync(filePath) || fs.statSync(filePath).isDirectory()) {
|
|
127
|
+
writeProtocolError(res, 404, 'input_error', 'not_found', 'Artifact file not found.');
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
if (!isOfficePreviewPath(filePath)) {
|
|
131
|
+
writeProtocolError(res, 400, 'input_error', 'unsupported_preview_type', 'Only Office files can use the office preview session.');
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
const requestedKind = typeof body?.kind === 'string' ? body.kind : url.searchParams.get('kind');
|
|
135
|
+
const extension = path.extname(filePath).slice(1).toLowerCase();
|
|
136
|
+
try {
|
|
137
|
+
if (requestedKind === 'spreadsheet' && extension === 'xls') {
|
|
138
|
+
const xlsxPath = await ensureSpreadsheetPreviewXlsx(agentId, `${rootCategory}:${normalized}`, filePath);
|
|
139
|
+
const token = issuePreviewToken(xlsxPath);
|
|
140
|
+
writeJson(res, 200, {
|
|
141
|
+
kind: 'xlsx',
|
|
142
|
+
previewUrl: buildSpaceLocalPath(req, `/agents/${encodeURIComponent(agentId)}/artifacts/preview-file?token=${encodeURIComponent(token)}`),
|
|
143
|
+
});
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
const sourceToken = issuePreviewToken(filePath);
|
|
147
|
+
const sourceLocalPath = buildSpaceLocalPath(req, `/agents/${encodeURIComponent(agentId)}/artifacts/preview-file?token=${encodeURIComponent(sourceToken)}`);
|
|
148
|
+
const sourceUrl = buildRequestAbsoluteUrl(req, sourceLocalPath);
|
|
149
|
+
const pdfPath = await ensureOfficePreviewPdf(agentId, `${rootCategory}:${normalized}`, filePath, sourceUrl);
|
|
150
|
+
const token = issuePreviewToken(pdfPath);
|
|
151
|
+
writeJson(res, 200, {
|
|
152
|
+
kind: 'pdf',
|
|
153
|
+
previewUrl: buildSpaceLocalPath(req, `/agents/${encodeURIComponent(agentId)}/artifacts/preview-file?token=${encodeURIComponent(token)}`),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
writeProtocolError(res, 503, 'internal_error', 'office_preview_unavailable', error?.message || 'Office preview is unavailable.');
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
const previewFileMatch = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/artifacts\/preview-file$/);
|
|
162
|
+
if (previewFileMatch && (method === 'GET' || method === 'HEAD')) {
|
|
163
|
+
const token = url.searchParams.get('token') || '';
|
|
164
|
+
const resolved = resolvePreviewToken(token);
|
|
165
|
+
if (!resolved || !fs.existsSync(resolved.filePath)) {
|
|
166
|
+
writeProtocolError(res, 404, 'input_error', 'preview_not_found', 'Preview file not found or expired.');
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
const stat = fs.statSync(resolved.filePath);
|
|
170
|
+
const basename = path.basename(resolved.filePath);
|
|
171
|
+
res.writeHead(200, {
|
|
172
|
+
'Content-Type': resolved.mimeType,
|
|
173
|
+
'Content-Length': stat.size,
|
|
174
|
+
'Last-Modified': stat.mtime.toUTCString(),
|
|
175
|
+
'Cache-Control': 'no-store, no-cache, must-revalidate, proxy-revalidate',
|
|
176
|
+
'Pragma': 'no-cache',
|
|
177
|
+
'Expires': '0',
|
|
178
|
+
'Content-Disposition': `inline; filename="${basename}"`,
|
|
179
|
+
});
|
|
180
|
+
if (method === 'HEAD') {
|
|
181
|
+
res.end();
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
fs.createReadStream(resolved.filePath).pipe(res);
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
// ── Agents: List/Create ──
|
|
188
|
+
if (pathname === '/api/computer/agents' && method === 'GET') {
|
|
189
|
+
const agents = getAllAgents();
|
|
190
|
+
writeJson(res, 200, { agents });
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
if (pathname === '/api/computer/agents' && method === 'POST') {
|
|
194
|
+
const body = await readJsonBody(req);
|
|
195
|
+
const payload = (body && typeof body === 'object' && !Array.isArray(body) ? body : {});
|
|
196
|
+
const requestedId = typeof payload.agent_id === 'string'
|
|
197
|
+
? payload.agent_id.trim()
|
|
198
|
+
: typeof payload.id === 'string'
|
|
199
|
+
? payload.id.trim()
|
|
200
|
+
: '';
|
|
201
|
+
const requestedName = typeof payload.name === 'string' ? payload.name.trim() : '';
|
|
202
|
+
if (!requestedId && !requestedName) {
|
|
203
|
+
writeProtocolError(res, 400, 'input_error', 'missing_agent_id', 'Either "agent_id", "id", or "name" is required.');
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
let agentId = requestedId || slugifyAgentId(requestedName);
|
|
207
|
+
if (!agentId) {
|
|
208
|
+
writeProtocolError(res, 400, 'input_error', 'invalid_agent_id', 'Could not derive a valid agent_id from the provided payload.');
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
agentId = ensurePathSafeAgentId(agentId);
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
writeProtocolError(res, 400, 'input_error', 'invalid_agent_id', 'agent_id contains invalid characters.');
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
const safeSpaceId = 'local';
|
|
219
|
+
const normalizedChannels = normalizeAgentChannels(payload.channels);
|
|
220
|
+
if (normalizedChannels === null) {
|
|
221
|
+
writeProtocolError(res, 400, 'input_error', 'invalid_channels', 'channels must be a mapping from channel name to boolean or string map.');
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
if (requestedId && getAgent(agentId)) {
|
|
225
|
+
writeProtocolError(res, 409, 'input_error', 'agent_exists', `Agent "${agentId}" already exists.`);
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
if (!requestedId) {
|
|
229
|
+
let suffix = 1;
|
|
230
|
+
while (getAgent(agentId)) {
|
|
231
|
+
suffix += 1;
|
|
232
|
+
try {
|
|
233
|
+
agentId = ensurePathSafeAgentId(`${slugifyAgentId(requestedName)}-${suffix}`);
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
agentId = `agent-${Date.now()}-${suffix}`;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const defaultSkillsConfig = normalizeAgentSkillsConfig('all', ['*']);
|
|
241
|
+
const created = createAgent({
|
|
242
|
+
agent_id: agentId,
|
|
243
|
+
space_id: safeSpaceId,
|
|
244
|
+
name: requestedName || agentId,
|
|
245
|
+
tags: Array.isArray(payload.tags)
|
|
246
|
+
? payload.tags.filter((item) => typeof item === 'string')
|
|
247
|
+
: undefined,
|
|
248
|
+
channels: normalizedChannels,
|
|
249
|
+
skills: defaultSkillsConfig,
|
|
250
|
+
});
|
|
251
|
+
writeAgentSkillsAllowlist(agentId, diskAllowlistForConfig(defaultSkillsConfig));
|
|
252
|
+
writeJson(res, 200, { agent: created });
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
// ── Agents: Single Agent Operations ──
|
|
256
|
+
const agentMatch = pathname.match(/^\/api\/computer\/agents\/([^/]+)$/);
|
|
257
|
+
if (agentMatch) {
|
|
258
|
+
const agentId = decodeURIComponent(agentMatch[1]);
|
|
259
|
+
if (method === 'GET') {
|
|
260
|
+
const agent = getAgent(agentId);
|
|
261
|
+
if (!agent) {
|
|
262
|
+
writeProtocolError(res, 404, 'input_error', 'agent_not_found', `Agent "${agentId}" was not found.`);
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
writeJson(res, 200, { agent });
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
if (method === 'PATCH') {
|
|
269
|
+
const body = await readJsonBody(req);
|
|
270
|
+
const payload = (body && typeof body === 'object' && !Array.isArray(body)
|
|
271
|
+
? body
|
|
272
|
+
: {});
|
|
273
|
+
if (Object.keys(payload).length === 0) {
|
|
274
|
+
writeProtocolError(res, 400, 'input_error', 'empty_payload', 'Payload is required for PATCH.');
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
if (payload.agent_id) {
|
|
278
|
+
writeProtocolError(res, 400, 'input_error', 'immutable_agent_id', 'agent_id is immutable.');
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
if (Object.prototype.hasOwnProperty.call(payload, 'space_id')) {
|
|
282
|
+
writeProtocolError(res, 400, 'input_error', 'immutable_space_id', 'space_id is immutable.');
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
const updates = {
|
|
286
|
+
...payload,
|
|
287
|
+
};
|
|
288
|
+
if (Object.prototype.hasOwnProperty.call(payload, 'name')) {
|
|
289
|
+
if (typeof payload.name !== 'string' || !payload.name.trim()) {
|
|
290
|
+
writeProtocolError(res, 400, 'input_error', 'invalid_agent_name', 'name must be a non-empty string.');
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
updates.name = payload.name.trim();
|
|
294
|
+
}
|
|
295
|
+
if (Object.prototype.hasOwnProperty.call(payload, 'tags')) {
|
|
296
|
+
if (!Array.isArray(payload.tags) || payload.tags.some((tag) => typeof tag !== 'string')) {
|
|
297
|
+
writeProtocolError(res, 400, 'input_error', 'invalid_tags', 'tags must be an array of strings.');
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
updates.tags = payload.tags;
|
|
301
|
+
}
|
|
302
|
+
if (Object.prototype.hasOwnProperty.call(payload, 'channels')) {
|
|
303
|
+
const normalizedChannels = normalizeAgentChannels(payload.channels);
|
|
304
|
+
if (normalizedChannels === null) {
|
|
305
|
+
writeProtocolError(res, 400, 'input_error', 'invalid_channels', 'channels must be a mapping from channel name to boolean or string map.');
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
updates.channels = normalizedChannels;
|
|
309
|
+
}
|
|
310
|
+
const updated = updateAgent(agentId, updates);
|
|
311
|
+
if (!updated) {
|
|
312
|
+
writeProtocolError(res, 404, 'input_error', 'agent_not_found', `Agent "${agentId}" was not found.`);
|
|
313
|
+
return true;
|
|
314
|
+
}
|
|
315
|
+
writeJson(res, 200, { agent: updated });
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
if (method === 'DELETE') {
|
|
319
|
+
const removed = deleteAgent(agentId);
|
|
320
|
+
if (!removed) {
|
|
321
|
+
writeProtocolError(res, 404, 'input_error', 'agent_not_found', `Agent "${agentId}" was not found.`);
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
writeJson(res, 200, { ok: true, deleted: agentId });
|
|
325
|
+
return true;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
// ── Agent Skills Assignment ──
|
|
329
|
+
const agentSkillsMatch = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/skills$/);
|
|
330
|
+
if (agentSkillsMatch && method === 'POST') {
|
|
331
|
+
const agentId = decodeURIComponent(agentSkillsMatch[1]);
|
|
332
|
+
const existingAgent = getAgent(agentId);
|
|
333
|
+
if (!existingAgent) {
|
|
334
|
+
writeProtocolError(res, 404, 'input_error', 'agent_not_found', `Agent "${agentId}" was not found.`);
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
const body = await readJsonBody(req);
|
|
338
|
+
const payload = (body && typeof body === 'object' && !Array.isArray(body)
|
|
339
|
+
? body
|
|
340
|
+
: {});
|
|
341
|
+
const modeRaw = typeof payload.mode === 'string' ? payload.mode.trim() : 'all';
|
|
342
|
+
const mode = modeRaw === 'all' || modeRaw === 'none' || modeRaw === 'custom'
|
|
343
|
+
? modeRaw
|
|
344
|
+
: null;
|
|
345
|
+
if (!mode) {
|
|
346
|
+
writeProtocolError(res, 400, 'input_error', 'invalid_mode', 'mode must be one of: all, none, custom.');
|
|
347
|
+
return true;
|
|
348
|
+
}
|
|
349
|
+
const skillsConfig = normalizeAgentSkillsConfig(mode, payload.skills);
|
|
350
|
+
const updatedAgent = updateAgent(agentId, { skills: skillsConfig });
|
|
351
|
+
if (!updatedAgent) {
|
|
352
|
+
writeProtocolError(res, 404, 'input_error', 'agent_not_found', `Agent "${agentId}" was not found.`);
|
|
353
|
+
return true;
|
|
354
|
+
}
|
|
355
|
+
const agentBaseDir = getAgentBaseDir(agentId);
|
|
356
|
+
if (!agentBaseDir) {
|
|
357
|
+
writeProtocolError(res, 404, 'input_error', 'agent_not_found', `Agent "${agentId}" was not found.`);
|
|
358
|
+
return true;
|
|
359
|
+
}
|
|
360
|
+
writeAgentSkillsAllowlist(agentId, diskAllowlistForConfig(skillsConfig));
|
|
361
|
+
writeJson(res, 200, { ok: true, agent: updatedAgent });
|
|
362
|
+
return true;
|
|
363
|
+
}
|
|
364
|
+
const knowledgeRootsMatch = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/workspace\/knowledge-roots$/);
|
|
365
|
+
if (knowledgeRootsMatch && method === 'GET') {
|
|
366
|
+
const agentId = decodeURIComponent(knowledgeRootsMatch[1]);
|
|
367
|
+
const space = spacePaths(agentSpaceId(agentId));
|
|
368
|
+
writeJson(res, 200, {
|
|
369
|
+
defaultId: space.knowledgeRoots.find((root) => root.isDefault)?.id ?? space.knowledgeRoots[0]?.id ?? null,
|
|
370
|
+
roots: space.knowledgeRoots.map((root) => ({
|
|
371
|
+
id: root.id,
|
|
372
|
+
name: root.name,
|
|
373
|
+
isDefault: root.isDefault,
|
|
374
|
+
mode: root.mode,
|
|
375
|
+
path: root.root,
|
|
376
|
+
})),
|
|
377
|
+
});
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
// ── Workspace file access ──
|
|
381
|
+
const workspaceV1Match = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/workspace(?:\/(.*))?$/);
|
|
382
|
+
if (workspaceV1Match && (method === 'GET' || method === 'HEAD' || method === 'PATCH' || method === 'DELETE')) {
|
|
383
|
+
const agentId = decodeURIComponent(workspaceV1Match[1]);
|
|
384
|
+
const relRaw = workspaceV1Match[2] ?? '.';
|
|
385
|
+
const relPath = decodeURIComponent(relRaw || '.') || '.';
|
|
386
|
+
const rootCategory = parseWorkspaceRootCategory(url.searchParams.get('root'));
|
|
387
|
+
const knowledgeId = url.searchParams.get('knowledge_id');
|
|
388
|
+
if (!rootCategory) {
|
|
389
|
+
writeInvalidWorkspaceRoot(res);
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
const normalized = path.normalize(relPath);
|
|
393
|
+
if (normalized.startsWith('..') || path.isAbsolute(normalized)) {
|
|
394
|
+
writeProtocolError(res, 400, 'input_error', 'invalid_path', 'Invalid path.');
|
|
395
|
+
return true;
|
|
396
|
+
}
|
|
397
|
+
const workspace = workspaceRootForAgent(agentId, rootCategory, knowledgeId);
|
|
398
|
+
fs.mkdirSync(workspace, { recursive: true });
|
|
399
|
+
const filePath = path.join(workspace, normalized);
|
|
400
|
+
if (!isPathWithin(workspace, filePath)) {
|
|
401
|
+
writeProtocolError(res, 403, 'input_error', 'path_outside_workspace', 'Path outside workspace.');
|
|
402
|
+
return true;
|
|
403
|
+
}
|
|
404
|
+
// Handle Deletion (PATCH with action: delete OR direct DELETE)
|
|
405
|
+
if (method === 'DELETE' || (method === 'PATCH')) {
|
|
406
|
+
const body = method === 'PATCH' ? await readJsonBody(req) : null;
|
|
407
|
+
const action = body?.action || (method === 'DELETE' ? 'delete' : null);
|
|
408
|
+
if (action === 'delete') {
|
|
409
|
+
if (!fs.existsSync(filePath)) {
|
|
410
|
+
writeProtocolError(res, 404, 'input_error', 'not_found', 'Item not found.');
|
|
411
|
+
return true;
|
|
412
|
+
}
|
|
413
|
+
try {
|
|
414
|
+
fs.rmSync(filePath, { recursive: true, force: true });
|
|
415
|
+
writeJson(res, 200, { ok: true, deleted: relPath });
|
|
416
|
+
}
|
|
417
|
+
catch (err) {
|
|
418
|
+
writeProtocolError(res, 500, 'internal_error', 'delete_failed', err.message);
|
|
419
|
+
}
|
|
420
|
+
return true;
|
|
421
|
+
}
|
|
422
|
+
if (action === 'mkdir') {
|
|
423
|
+
try {
|
|
424
|
+
fs.mkdirSync(filePath, { recursive: true });
|
|
425
|
+
writeJson(res, 200, { ok: true, created: relPath });
|
|
426
|
+
}
|
|
427
|
+
catch (err) {
|
|
428
|
+
writeProtocolError(res, 500, 'internal_error', 'mkdir_failed', err.message);
|
|
429
|
+
}
|
|
430
|
+
return true;
|
|
431
|
+
}
|
|
432
|
+
if (action === 'rename' || action === 'move') {
|
|
433
|
+
const nextName = body?.nextName;
|
|
434
|
+
if (!nextName) {
|
|
435
|
+
writeProtocolError(res, 400, 'input_error', 'next_name_required', 'nextName is required.');
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
const nextRelPath = path.normalize(nextName);
|
|
439
|
+
if (nextRelPath.startsWith('..') || path.isAbsolute(nextRelPath)) {
|
|
440
|
+
writeProtocolError(res, 400, 'input_error', 'invalid_destination_path', 'Invalid destination path.');
|
|
441
|
+
return true;
|
|
442
|
+
}
|
|
443
|
+
const destPath = path.join(workspace, nextRelPath);
|
|
444
|
+
if (!isPathWithin(workspace, destPath)) {
|
|
445
|
+
writeProtocolError(res, 403, 'input_error', 'destination_outside_workspace', 'Destination outside workspace.');
|
|
446
|
+
return true;
|
|
447
|
+
}
|
|
448
|
+
try {
|
|
449
|
+
if (!fs.existsSync(filePath)) {
|
|
450
|
+
writeProtocolError(res, 404, 'input_error', 'not_found', 'Source not found.');
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
453
|
+
// Ensure directory exists for destination if moving
|
|
454
|
+
fs.mkdirSync(path.dirname(destPath), { recursive: true });
|
|
455
|
+
fs.renameSync(filePath, destPath);
|
|
456
|
+
writeJson(res, 200, { ok: true, from: relPath, to: nextRelPath });
|
|
457
|
+
}
|
|
458
|
+
catch (err) {
|
|
459
|
+
writeProtocolError(res, 500, 'internal_error', 'rename_failed', err.message);
|
|
460
|
+
}
|
|
461
|
+
return true;
|
|
462
|
+
}
|
|
463
|
+
if (method === 'PATCH') {
|
|
464
|
+
writeProtocolError(res, 400, 'input_error', 'invalid_action', `Unknown action: ${action}`);
|
|
465
|
+
return true;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
if (!fs.existsSync(filePath)) {
|
|
469
|
+
writeProtocolError(res, 404, 'input_error', 'not_found', 'File not found.');
|
|
470
|
+
return true;
|
|
471
|
+
}
|
|
472
|
+
const stat = fs.statSync(filePath);
|
|
473
|
+
if (stat.isDirectory()) {
|
|
474
|
+
const entries = fs.readdirSync(filePath)
|
|
475
|
+
.filter((name) => !isHiddenWorkspaceEntry(rootCategory, name))
|
|
476
|
+
.map((name) => {
|
|
477
|
+
const entryPath = path.join(filePath, name);
|
|
478
|
+
const entryStat = fs.statSync(entryPath);
|
|
479
|
+
return {
|
|
480
|
+
name,
|
|
481
|
+
type: entryStat.isDirectory() ? 'directory' : 'file',
|
|
482
|
+
size: entryStat.isDirectory() ? undefined : entryStat.size,
|
|
483
|
+
modified: entryStat.mtime.toISOString(),
|
|
484
|
+
};
|
|
485
|
+
});
|
|
486
|
+
writeJson(res, 200, { path: relPath, root: rootCategory, entries });
|
|
487
|
+
return true;
|
|
488
|
+
}
|
|
489
|
+
const mime = inferMimeType(filePath);
|
|
490
|
+
const basename = path.basename(filePath);
|
|
491
|
+
const asciiName = basename.replace(/[^\x20-\x7E]/g, '_');
|
|
492
|
+
const encodedName = encodeURIComponent(basename).replace(/'/g, '%27');
|
|
493
|
+
const disposition = mime === 'application/octet-stream'
|
|
494
|
+
? `attachment; filename="${asciiName}"; filename*=UTF-8''${encodedName}`
|
|
495
|
+
: 'inline';
|
|
496
|
+
res.writeHead(200, {
|
|
497
|
+
'Content-Type': mime,
|
|
498
|
+
'Content-Length': stat.size,
|
|
499
|
+
'Last-Modified': stat.mtime.toUTCString(),
|
|
500
|
+
'Cache-Control': 'no-store, no-cache, must-revalidate, proxy-revalidate',
|
|
501
|
+
'Pragma': 'no-cache',
|
|
502
|
+
'Expires': '0',
|
|
503
|
+
'Content-Disposition': disposition,
|
|
504
|
+
});
|
|
505
|
+
if (method === 'HEAD') {
|
|
506
|
+
res.end();
|
|
507
|
+
return true;
|
|
508
|
+
}
|
|
509
|
+
fs.createReadStream(filePath).pipe(res);
|
|
510
|
+
return true;
|
|
511
|
+
}
|
|
512
|
+
// ── Workspace file upload ──
|
|
513
|
+
const uploadV1Match = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/workspace\/upload$/);
|
|
514
|
+
if (uploadV1Match && method === 'POST') {
|
|
515
|
+
const agentId = decodeURIComponent(uploadV1Match[1]);
|
|
516
|
+
const reqBody = await readJsonBody(req);
|
|
517
|
+
if (!reqBody?.files || !Array.isArray(reqBody.files)) {
|
|
518
|
+
writeProtocolError(res, 400, 'input_error', 'files_required', 'Request body must contain files array.');
|
|
519
|
+
return true;
|
|
520
|
+
}
|
|
521
|
+
const rootCategory = parseWorkspaceRootCategory(reqBody?.root ?? url.searchParams.get('root'));
|
|
522
|
+
const knowledgeId = typeof reqBody?.knowledge_id === 'string' ? reqBody.knowledge_id : url.searchParams.get('knowledge_id');
|
|
523
|
+
if (!rootCategory) {
|
|
524
|
+
writeInvalidWorkspaceRoot(res);
|
|
525
|
+
return true;
|
|
526
|
+
}
|
|
527
|
+
const workspace = workspaceRootForAgent(agentId, rootCategory, knowledgeId);
|
|
528
|
+
const targetPath = reqBody.path ? path.normalize(reqBody.path) : '';
|
|
529
|
+
if (targetPath.startsWith('..') || path.isAbsolute(targetPath)) {
|
|
530
|
+
writeProtocolError(res, 400, 'input_error', 'invalid_upload_path', 'Invalid upload path.');
|
|
531
|
+
return true;
|
|
532
|
+
}
|
|
533
|
+
const uploadDir = path.join(workspace, targetPath || '.uploads');
|
|
534
|
+
const resolvedWorkspace = path.resolve(workspace);
|
|
535
|
+
const resolvedUploadDir = path.resolve(uploadDir);
|
|
536
|
+
if (resolvedUploadDir !== resolvedWorkspace && !resolvedUploadDir.startsWith(`${resolvedWorkspace}${path.sep}`)) {
|
|
537
|
+
writeProtocolError(res, 403, 'input_error', 'upload_path_outside_workspace', 'Upload path outside workspace.');
|
|
538
|
+
return true;
|
|
539
|
+
}
|
|
540
|
+
fs.mkdirSync(uploadDir, { recursive: true });
|
|
541
|
+
const uploadedFiles = [];
|
|
542
|
+
for (const file of reqBody.files) {
|
|
543
|
+
if (!file.name || !file.data)
|
|
544
|
+
continue;
|
|
545
|
+
const originalName = path.basename(file.name);
|
|
546
|
+
const content = Buffer.from(file.data, 'base64');
|
|
547
|
+
if (content.length > 50 * 1024 * 1024)
|
|
548
|
+
continue;
|
|
549
|
+
// If uploading to .uploads, we still use the UUID prefix to prevent collisions
|
|
550
|
+
// If uploading to a specific path, we might want to overwrite or prevent collision
|
|
551
|
+
// For now, let's keep consistency for .uploads, and use original name for custom paths
|
|
552
|
+
const destName = targetPath ? originalName : `${randomUUID().slice(0, 8)}-${originalName}`;
|
|
553
|
+
const destPath = path.join(uploadDir, destName);
|
|
554
|
+
fs.writeFileSync(destPath, content);
|
|
555
|
+
const supenPath = targetPath ? path.join(targetPath, destName) : `.uploads/${destName}`;
|
|
556
|
+
uploadedFiles.push({
|
|
557
|
+
name: originalName,
|
|
558
|
+
path: supenPath,
|
|
559
|
+
supenUrl: rootCategory === 'knowledge'
|
|
560
|
+
? `supen://workspace/${agentId}/${supenPath.replace(/\\/g, '/')}`
|
|
561
|
+
: `supen://workspace/${agentId}/${rootCategory}/${supenPath.replace(/\\/g, '/')}`,
|
|
562
|
+
size: content.length,
|
|
563
|
+
});
|
|
564
|
+
logger.info({ agentId, root: rootCategory, destName, targetPath }, 'File uploaded to workspace');
|
|
565
|
+
}
|
|
566
|
+
writeJson(res, 200, { files: uploadedFiles });
|
|
567
|
+
return true;
|
|
568
|
+
}
|
|
569
|
+
// ── Mind Files ──
|
|
570
|
+
const mindFilesMatch = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/mind$/);
|
|
571
|
+
if (mindFilesMatch && method === 'GET') {
|
|
572
|
+
const agentId = decodeURIComponent(mindFilesMatch[1]);
|
|
573
|
+
const baseDir = getAgentBaseDir(agentId);
|
|
574
|
+
if (!baseDir) {
|
|
575
|
+
writeProtocolError(res, 404, 'input_error', 'agent_not_found', `Agent "${agentId}" was not found.`);
|
|
576
|
+
return true;
|
|
577
|
+
}
|
|
578
|
+
const MIND_FILES = ['SOUL.md', 'MEMORY.md', 'IDENTITY.md', 'USER.md'];
|
|
579
|
+
const files = {};
|
|
580
|
+
for (const name of MIND_FILES) {
|
|
581
|
+
const filePath = path.join(baseDir, name);
|
|
582
|
+
if (fs.existsSync(filePath)) {
|
|
583
|
+
files[name] = {
|
|
584
|
+
content: fs.readFileSync(filePath, 'utf-8'),
|
|
585
|
+
mtimeMs: fs.statSync(filePath).mtimeMs,
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
writeJson(res, 200, { files });
|
|
590
|
+
return true;
|
|
591
|
+
}
|
|
592
|
+
// ── Memory Roll ──
|
|
593
|
+
const memoryMatch = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/memory$/);
|
|
594
|
+
if (memoryMatch && method === 'GET') {
|
|
595
|
+
const agentId = decodeURIComponent(memoryMatch[1]);
|
|
596
|
+
const baseDir = getAgentBaseDir(agentId);
|
|
597
|
+
if (!baseDir) {
|
|
598
|
+
writeProtocolError(res, 404, 'input_error', 'agent_not_found', `Agent "${agentId}" was not found.`);
|
|
599
|
+
return true;
|
|
600
|
+
}
|
|
601
|
+
const memoryPath = path.join(baseDir, 'MEMORY.md');
|
|
602
|
+
const memoryDir = path.join(baseDir, 'memory');
|
|
603
|
+
const coreMemory = fs.existsSync(memoryPath)
|
|
604
|
+
? {
|
|
605
|
+
content: fs.readFileSync(memoryPath, 'utf-8'),
|
|
606
|
+
mtimeMs: fs.statSync(memoryPath).mtimeMs,
|
|
607
|
+
}
|
|
608
|
+
: null;
|
|
609
|
+
const roll = fs.existsSync(memoryDir)
|
|
610
|
+
? fs
|
|
611
|
+
.readdirSync(memoryDir)
|
|
612
|
+
.filter((name) => name.endsWith('.md'))
|
|
613
|
+
.sort((a, b) => b.localeCompare(a))
|
|
614
|
+
.map((name) => {
|
|
615
|
+
const filePath = path.join(memoryDir, name);
|
|
616
|
+
const stat = fs.statSync(filePath);
|
|
617
|
+
return {
|
|
618
|
+
id: name.slice(0, -3),
|
|
619
|
+
content: fs.readFileSync(filePath, 'utf-8'),
|
|
620
|
+
mtimeMs: stat.mtimeMs,
|
|
621
|
+
};
|
|
622
|
+
})
|
|
623
|
+
: [];
|
|
624
|
+
writeJson(res, 200, { core_memory: coreMemory, roll });
|
|
625
|
+
return true;
|
|
626
|
+
}
|
|
627
|
+
const memoryEntryMatch = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/memory\/([^/]+)$/);
|
|
628
|
+
if (memoryEntryMatch && method === 'PUT') {
|
|
629
|
+
const agentId = decodeURIComponent(memoryEntryMatch[1]);
|
|
630
|
+
const entryId = assertSafePathSegment(decodeURIComponent(memoryEntryMatch[2]), 'memory_id');
|
|
631
|
+
const body = await readJsonBody(req);
|
|
632
|
+
const payload = (body && typeof body === 'object' && !Array.isArray(body)
|
|
633
|
+
? body
|
|
634
|
+
: {});
|
|
635
|
+
const content = typeof payload.content === 'string' ? payload.content : null;
|
|
636
|
+
if (content === null) {
|
|
637
|
+
writeProtocolError(res, 400, 'input_error', 'invalid_content', 'content must be a string.');
|
|
638
|
+
return true;
|
|
639
|
+
}
|
|
640
|
+
const baseDir = getAgentBaseDir(agentId);
|
|
641
|
+
if (!baseDir) {
|
|
642
|
+
writeProtocolError(res, 404, 'input_error', 'agent_not_found', `Agent "${agentId}" was not found.`);
|
|
643
|
+
return true;
|
|
644
|
+
}
|
|
645
|
+
const targetPath = entryId === 'core'
|
|
646
|
+
? path.join(baseDir, 'MEMORY.md')
|
|
647
|
+
: path.join(baseDir, 'memory', `${entryId}.md`);
|
|
648
|
+
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
649
|
+
fs.writeFileSync(targetPath, content, 'utf-8');
|
|
650
|
+
const stat = fs.statSync(targetPath);
|
|
651
|
+
writeJson(res, 200, {
|
|
652
|
+
ok: true,
|
|
653
|
+
entry: {
|
|
654
|
+
id: entryId,
|
|
655
|
+
content,
|
|
656
|
+
mtimeMs: stat.mtimeMs,
|
|
657
|
+
},
|
|
658
|
+
});
|
|
659
|
+
return true;
|
|
660
|
+
}
|
|
661
|
+
// ── Artifacts ──
|
|
662
|
+
const artifactsMatch = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/artifacts$/);
|
|
663
|
+
if (artifactsMatch && method === 'GET') {
|
|
664
|
+
const agentId = decodeURIComponent(artifactsMatch[1]);
|
|
665
|
+
const baseDir = getAgentBaseDir(agentId);
|
|
666
|
+
if (!baseDir) {
|
|
667
|
+
writeProtocolError(res, 404, 'input_error', 'agent_not_found', `Agent "${agentId}" was not found.`);
|
|
668
|
+
return true;
|
|
669
|
+
}
|
|
670
|
+
const artifacts = {};
|
|
671
|
+
const walk = (dir) => {
|
|
672
|
+
if (!fs.existsSync(dir))
|
|
673
|
+
return;
|
|
674
|
+
for (const item of fs.readdirSync(dir)) {
|
|
675
|
+
if (isOsMetadataFile(item))
|
|
676
|
+
continue;
|
|
677
|
+
const fp = path.join(dir, item);
|
|
678
|
+
if (fs.statSync(fp).isDirectory()) {
|
|
679
|
+
if (item !== '.git' && item !== 'node_modules')
|
|
680
|
+
walk(fp);
|
|
681
|
+
}
|
|
682
|
+
else {
|
|
683
|
+
const rel = path.relative(baseDir, fp);
|
|
684
|
+
const s = fs.statSync(fp);
|
|
685
|
+
artifacts[rel] = { mime_type: inferMimeType(fp), size: s.size, mtimeMs: s.mtimeMs };
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
walk(baseDir);
|
|
690
|
+
writeJson(res, 200, { artifacts });
|
|
691
|
+
return true;
|
|
692
|
+
}
|
|
693
|
+
return false;
|
|
694
|
+
}
|
|
695
|
+
function ensurePathSafeAgentId(agentId) {
|
|
696
|
+
return assertSafePathSegment(agentId, 'agent_id');
|
|
697
|
+
}
|
|
698
|
+
function getAgentBaseDir(agentId) {
|
|
699
|
+
const storage = getAgentStorage(agentId);
|
|
700
|
+
if (!storage)
|
|
701
|
+
return null;
|
|
702
|
+
return storage.baseDir;
|
|
703
|
+
}
|
|
704
|
+
function slugifyAgentId(name) {
|
|
705
|
+
const slug = name
|
|
706
|
+
.trim()
|
|
707
|
+
.toLowerCase()
|
|
708
|
+
.replace(/\s+/g, '-')
|
|
709
|
+
.replace(/[^a-z0-9._-]+/g, '-')
|
|
710
|
+
.replace(/[-._]{2,}/g, '-')
|
|
711
|
+
.replace(/^[-._]+|[-._]+$/g, '');
|
|
712
|
+
return slug || 'agent';
|
|
713
|
+
}
|
|
714
|
+
function normalizeAgentChannels(input) {
|
|
715
|
+
if (input === undefined)
|
|
716
|
+
return undefined;
|
|
717
|
+
if (!input || typeof input !== 'object' || Array.isArray(input))
|
|
718
|
+
return null;
|
|
719
|
+
const result = {};
|
|
720
|
+
for (const [channel, cfg] of Object.entries(input)) {
|
|
721
|
+
if (typeof channel !== 'string' || !channel.trim())
|
|
722
|
+
return null;
|
|
723
|
+
if (typeof cfg === 'boolean') {
|
|
724
|
+
result[channel] = cfg;
|
|
725
|
+
continue;
|
|
726
|
+
}
|
|
727
|
+
if (!cfg || typeof cfg !== 'object' || Array.isArray(cfg))
|
|
728
|
+
return null;
|
|
729
|
+
const nested = {};
|
|
730
|
+
for (const [k, v] of Object.entries(cfg)) {
|
|
731
|
+
if (typeof v === 'string' || typeof v === 'boolean') {
|
|
732
|
+
nested[k] = v;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
result[channel] = nested;
|
|
736
|
+
}
|
|
737
|
+
return result;
|
|
738
|
+
}
|
|
739
|
+
function writeAgentSkillsAllowlist(agentId, diskSkills) {
|
|
740
|
+
const agentBaseDir = getAgentBaseDir(agentId);
|
|
741
|
+
if (!agentBaseDir)
|
|
742
|
+
return;
|
|
743
|
+
const skillsPath = path.join(agentBaseDir, 'skills.json');
|
|
744
|
+
fs.mkdirSync(path.dirname(skillsPath), { recursive: true });
|
|
745
|
+
fs.writeFileSync(skillsPath, `${JSON.stringify(diskSkills, null, 2)}\n`, 'utf-8');
|
|
746
|
+
}
|
|
747
|
+
//# sourceMappingURL=agents.js.map
|