@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,916 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { randomUUID } from 'crypto';
|
|
4
|
+
import { ACP_ENABLED, ACP_RELAY_URL } from '../core/config.js';
|
|
5
|
+
import { ensureSession } from '../core/store.js';
|
|
6
|
+
import { logger } from '../core/logger.js';
|
|
7
|
+
import { validateOutboundEndpoint } from '../core/security.js';
|
|
8
|
+
import { submitTask } from '../task-executor.js';
|
|
9
|
+
import { ACPClient } from '../acp-client.js';
|
|
10
|
+
import { registerChannel } from './registry.js';
|
|
11
|
+
// NOTE: This ACP channel is the external transport surface for ACP clients that
|
|
12
|
+
// talk to Supen as a daemon/channel endpoint. It is intentionally separate from
|
|
13
|
+
// the Agent SDK's backend-driver work (for example acpx-backed Codex/Claude
|
|
14
|
+
// adapters). We should not collapse coding-agent backends into a "channel"
|
|
15
|
+
// abstraction here.
|
|
16
|
+
const ACP_JID_PREFIX = 'acp:';
|
|
17
|
+
const MAX_SESSION_MESSAGES = 200;
|
|
18
|
+
let runtimeOpts = null;
|
|
19
|
+
let defaultClient = null;
|
|
20
|
+
const sessionsById = new Map();
|
|
21
|
+
const sessionIdByChatJid = new Map();
|
|
22
|
+
function nowIso() {
|
|
23
|
+
return new Date().toISOString();
|
|
24
|
+
}
|
|
25
|
+
function buildThreadId(agentId, sessionId) {
|
|
26
|
+
return `${encodeURIComponent(agentId)}:${encodeURIComponent(sessionId)}`;
|
|
27
|
+
}
|
|
28
|
+
function parseThreadId(threadId) {
|
|
29
|
+
const parts = threadId.split(':');
|
|
30
|
+
if (parts.length < 2)
|
|
31
|
+
return null;
|
|
32
|
+
try {
|
|
33
|
+
return {
|
|
34
|
+
agent_id: decodeURIComponent(parts[0]),
|
|
35
|
+
session_id: decodeURIComponent(parts[1]),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function buildAcpChatJid(agentId, sessionId) {
|
|
43
|
+
return `${ACP_JID_PREFIX}${buildThreadId(agentId, sessionId)}`;
|
|
44
|
+
}
|
|
45
|
+
function readJsonBody(req) {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
let body = '';
|
|
48
|
+
req.setEncoding('utf-8');
|
|
49
|
+
req.on('data', (chunk) => {
|
|
50
|
+
body += chunk;
|
|
51
|
+
});
|
|
52
|
+
req.on('end', () => {
|
|
53
|
+
if (!body.trim()) {
|
|
54
|
+
resolve({});
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
resolve(JSON.parse(body));
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
reject(new Error('Invalid JSON body'));
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
req.on('error', reject);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function writeJson(res, statusCode, payload) {
|
|
68
|
+
res.writeHead(statusCode, {
|
|
69
|
+
'Content-Type': 'application/json',
|
|
70
|
+
});
|
|
71
|
+
res.end(JSON.stringify(payload));
|
|
72
|
+
}
|
|
73
|
+
function writeProtocolError(res, statusCode, code, message, details) {
|
|
74
|
+
writeJson(res, statusCode, {
|
|
75
|
+
error: {
|
|
76
|
+
code,
|
|
77
|
+
message,
|
|
78
|
+
...(details ? { details } : {}),
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function wantsSse(req, url) {
|
|
83
|
+
if (url.searchParams.get('stream') === '1')
|
|
84
|
+
return true;
|
|
85
|
+
const accept = req.headers.accept;
|
|
86
|
+
return typeof accept === 'string' && accept.includes('text/event-stream');
|
|
87
|
+
}
|
|
88
|
+
function inferMimeType(filePath) {
|
|
89
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
90
|
+
if (ext === '.md')
|
|
91
|
+
return 'text/markdown';
|
|
92
|
+
if (ext === '.base')
|
|
93
|
+
return 'text/yaml';
|
|
94
|
+
if (ext === '.txt' || ext === '.log' || ext === '.jsonl')
|
|
95
|
+
return 'text/plain';
|
|
96
|
+
if (ext === '.json')
|
|
97
|
+
return 'application/json';
|
|
98
|
+
if (ext === '.png')
|
|
99
|
+
return 'image/png';
|
|
100
|
+
if (ext === '.jpg' || ext === '.jpeg')
|
|
101
|
+
return 'image/jpeg';
|
|
102
|
+
if (ext === '.webp')
|
|
103
|
+
return 'image/webp';
|
|
104
|
+
if (ext === '.pdf')
|
|
105
|
+
return 'application/pdf';
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
function normalizeContentPart(part) {
|
|
109
|
+
if (!part)
|
|
110
|
+
return null;
|
|
111
|
+
if (typeof part === 'string') {
|
|
112
|
+
return { type: 'text', text: part };
|
|
113
|
+
}
|
|
114
|
+
if (typeof part !== 'object')
|
|
115
|
+
return null;
|
|
116
|
+
const value = part;
|
|
117
|
+
const type = value.type;
|
|
118
|
+
if ((type === 'text' || type === 'markdown') &&
|
|
119
|
+
typeof value.text === 'string') {
|
|
120
|
+
return { type, text: value.text };
|
|
121
|
+
}
|
|
122
|
+
if (type === 'artifact') {
|
|
123
|
+
return {
|
|
124
|
+
type: 'artifact',
|
|
125
|
+
name: typeof value.name === 'string' ? value.name : undefined,
|
|
126
|
+
mime_type: typeof value.mime_type === 'string' ? value.mime_type : undefined,
|
|
127
|
+
uri: typeof value.uri === 'string' ? value.uri : undefined,
|
|
128
|
+
path: typeof value.path === 'string' ? value.path : undefined,
|
|
129
|
+
description: typeof value.description === 'string' ? value.description : undefined,
|
|
130
|
+
data: typeof value.data === 'string' ? value.data : undefined,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
function normalizeContent(content) {
|
|
136
|
+
if (typeof content === 'string') {
|
|
137
|
+
return content.trim() ? [{ type: 'text', text: content }] : [];
|
|
138
|
+
}
|
|
139
|
+
if (Array.isArray(content)) {
|
|
140
|
+
return content
|
|
141
|
+
.map((part) => normalizeContentPart(part))
|
|
142
|
+
.filter((part) => !!part);
|
|
143
|
+
}
|
|
144
|
+
if (content && typeof content === 'object') {
|
|
145
|
+
const single = normalizeContentPart(content);
|
|
146
|
+
return single ? [single] : [];
|
|
147
|
+
}
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
function normalizeToolCall(toolCall) {
|
|
151
|
+
if (!toolCall || typeof toolCall !== 'object')
|
|
152
|
+
return null;
|
|
153
|
+
const value = toolCall;
|
|
154
|
+
const name = typeof value.name === 'string'
|
|
155
|
+
? value.name
|
|
156
|
+
: typeof value.tool_name === 'string'
|
|
157
|
+
? value.tool_name
|
|
158
|
+
: null;
|
|
159
|
+
if (!name)
|
|
160
|
+
return null;
|
|
161
|
+
return {
|
|
162
|
+
id: typeof value.id === 'string' && value.id
|
|
163
|
+
? value.id
|
|
164
|
+
: typeof value.tool_call_id === 'string' && value.tool_call_id
|
|
165
|
+
? value.tool_call_id
|
|
166
|
+
: randomUUID(),
|
|
167
|
+
name,
|
|
168
|
+
arguments: value.arguments && typeof value.arguments === 'object'
|
|
169
|
+
? value.arguments
|
|
170
|
+
: value.input && typeof value.input === 'object'
|
|
171
|
+
? value.input
|
|
172
|
+
: undefined,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function normalizeToolResult(toolResult) {
|
|
176
|
+
if (!toolResult || typeof toolResult !== 'object')
|
|
177
|
+
return null;
|
|
178
|
+
const value = toolResult;
|
|
179
|
+
const toolCallId = typeof value.tool_call_id === 'string'
|
|
180
|
+
? value.tool_call_id
|
|
181
|
+
: typeof value.id === 'string'
|
|
182
|
+
? value.id
|
|
183
|
+
: null;
|
|
184
|
+
if (!toolCallId)
|
|
185
|
+
return null;
|
|
186
|
+
return {
|
|
187
|
+
tool_call_id: toolCallId,
|
|
188
|
+
name: typeof value.name === 'string' ? value.name : undefined,
|
|
189
|
+
result: value.result ?? value.output ?? value.content,
|
|
190
|
+
is_error: typeof value.is_error === 'boolean'
|
|
191
|
+
? value.is_error
|
|
192
|
+
: typeof value.error === 'boolean'
|
|
193
|
+
? value.error
|
|
194
|
+
: false,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
export function normalizeAcpEnvelope(input, fallbackRole = 'user') {
|
|
198
|
+
const raw = input && typeof input === 'object' && 'message' in input
|
|
199
|
+
? input.message
|
|
200
|
+
: input;
|
|
201
|
+
const value = raw && typeof raw === 'object' ? raw : {};
|
|
202
|
+
const role = value.role === 'system' ||
|
|
203
|
+
value.role === 'user' ||
|
|
204
|
+
value.role === 'assistant' ||
|
|
205
|
+
value.role === 'tool'
|
|
206
|
+
? value.role
|
|
207
|
+
: fallbackRole;
|
|
208
|
+
const content = normalizeContent(value.content ?? value.parts ?? value.text ?? value.prompt ?? '');
|
|
209
|
+
const toolCalls = Array.isArray(value.tool_calls)
|
|
210
|
+
? value.tool_calls
|
|
211
|
+
.map((toolCall) => normalizeToolCall(toolCall))
|
|
212
|
+
.filter((toolCall) => !!toolCall)
|
|
213
|
+
: [];
|
|
214
|
+
const toolResults = Array.isArray(value.tool_results)
|
|
215
|
+
? value.tool_results
|
|
216
|
+
.map((toolResult) => normalizeToolResult(toolResult))
|
|
217
|
+
.filter((toolResult) => !!toolResult)
|
|
218
|
+
: [];
|
|
219
|
+
return {
|
|
220
|
+
id: typeof value.id === 'string' && value.id ? value.id : randomUUID(),
|
|
221
|
+
role,
|
|
222
|
+
content,
|
|
223
|
+
...(toolCalls.length ? { tool_calls: toolCalls } : {}),
|
|
224
|
+
...(toolResults.length ? { tool_results: toolResults } : {}),
|
|
225
|
+
...(value.metadata && typeof value.metadata === 'object'
|
|
226
|
+
? { metadata: value.metadata }
|
|
227
|
+
: {}),
|
|
228
|
+
created_at: typeof value.created_at === 'string' && value.created_at
|
|
229
|
+
? value.created_at
|
|
230
|
+
: nowIso(),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function renderContentForPrompt(content) {
|
|
234
|
+
return content
|
|
235
|
+
.map((part) => {
|
|
236
|
+
if (part.type === 'artifact') {
|
|
237
|
+
return [
|
|
238
|
+
'[Artifact]',
|
|
239
|
+
part.name ? `name: ${part.name}` : null,
|
|
240
|
+
part.path ? `path: ${part.path}` : null,
|
|
241
|
+
part.uri ? `uri: ${part.uri}` : null,
|
|
242
|
+
part.description ? `description: ${part.description}` : null,
|
|
243
|
+
]
|
|
244
|
+
.filter(Boolean)
|
|
245
|
+
.join('\n');
|
|
246
|
+
}
|
|
247
|
+
return part.text;
|
|
248
|
+
})
|
|
249
|
+
.filter(Boolean)
|
|
250
|
+
.join('\n\n');
|
|
251
|
+
}
|
|
252
|
+
function buildPromptFromEnvelope(envelope, mode = 'message') {
|
|
253
|
+
const parts = [];
|
|
254
|
+
if (mode === 'tools' && envelope.tool_calls?.length) {
|
|
255
|
+
parts.push('Execute the requested tool calls and return the results clearly. Include any errors inline.');
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
parts.push(`ACP ${envelope.role} message:`);
|
|
259
|
+
}
|
|
260
|
+
const renderedContent = renderContentForPrompt(envelope.content);
|
|
261
|
+
if (renderedContent)
|
|
262
|
+
parts.push(renderedContent);
|
|
263
|
+
if (envelope.tool_calls?.length) {
|
|
264
|
+
parts.push(`[ACP tool calls]\n${JSON.stringify(envelope.tool_calls, null, 2)}`);
|
|
265
|
+
}
|
|
266
|
+
if (envelope.tool_results?.length) {
|
|
267
|
+
parts.push(`[ACP tool results]\n${JSON.stringify(envelope.tool_results, null, 2)}`);
|
|
268
|
+
}
|
|
269
|
+
return parts.join('\n\n').trim();
|
|
270
|
+
}
|
|
271
|
+
function isExecutableEnvelope(envelope) {
|
|
272
|
+
if (envelope.tool_calls?.length)
|
|
273
|
+
return true;
|
|
274
|
+
return envelope.content.some((part) => part.type === 'artifact' ? true : !!part.text.trim());
|
|
275
|
+
}
|
|
276
|
+
function serializeSession(session) {
|
|
277
|
+
return {
|
|
278
|
+
id: session.id,
|
|
279
|
+
thread_id: session.thread_id,
|
|
280
|
+
agent_id: session.agent_id,
|
|
281
|
+
session_id: session.session_id,
|
|
282
|
+
chat_jid: session.chat_jid,
|
|
283
|
+
created_at: session.created_at,
|
|
284
|
+
updated_at: session.updated_at,
|
|
285
|
+
stream_url: session.stream_url,
|
|
286
|
+
message_url: session.message_url,
|
|
287
|
+
tools_url: session.tools_url,
|
|
288
|
+
last_task_id: session.last_task_id || null,
|
|
289
|
+
metadata: session.metadata || null,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
function writeSseEvent(res, event, eventName) {
|
|
293
|
+
if (eventName) {
|
|
294
|
+
res.write(`event: ${eventName}\n`);
|
|
295
|
+
}
|
|
296
|
+
res.write(`data: ${JSON.stringify(event)}\n\n`);
|
|
297
|
+
}
|
|
298
|
+
function broadcastSessionEvent(session, event, eventName) {
|
|
299
|
+
for (const client of [...session.clients]) {
|
|
300
|
+
try {
|
|
301
|
+
writeSseEvent(client, event, eventName);
|
|
302
|
+
}
|
|
303
|
+
catch {
|
|
304
|
+
session.clients.delete(client);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function appendMessage(session, envelope) {
|
|
309
|
+
session.messages.push(envelope);
|
|
310
|
+
if (session.messages.length > MAX_SESSION_MESSAGES) {
|
|
311
|
+
session.messages.splice(0, session.messages.length - MAX_SESSION_MESSAGES);
|
|
312
|
+
}
|
|
313
|
+
session.updated_at = nowIso();
|
|
314
|
+
}
|
|
315
|
+
function listAgentManifests() {
|
|
316
|
+
const opts = runtimeOpts;
|
|
317
|
+
const uniqueAgents = new Map();
|
|
318
|
+
for (const project of Object.values(opts?.registeredProjects() || {})) {
|
|
319
|
+
const agentId = project.agent_id || project.folder;
|
|
320
|
+
uniqueAgents.set(agentId, agentId);
|
|
321
|
+
}
|
|
322
|
+
if (uniqueAgents.size === 0) {
|
|
323
|
+
uniqueAgents.set('default', 'default');
|
|
324
|
+
}
|
|
325
|
+
return [...uniqueAgents.keys()].map((agentId) => ({
|
|
326
|
+
id: buildThreadId(agentId, agentId),
|
|
327
|
+
protocol: 'acp',
|
|
328
|
+
name: `Supen ${agentId}`,
|
|
329
|
+
description: 'Supen ACP-compatible agent endpoint',
|
|
330
|
+
version: '1.0.0',
|
|
331
|
+
agent_id: agentId,
|
|
332
|
+
endpoints: {
|
|
333
|
+
agents: '/acp/agents',
|
|
334
|
+
sessions: '/acp/sessions',
|
|
335
|
+
},
|
|
336
|
+
capabilities: {
|
|
337
|
+
streaming: true,
|
|
338
|
+
inbound: true,
|
|
339
|
+
outbound: true,
|
|
340
|
+
tool_calls: true,
|
|
341
|
+
tool_results: true,
|
|
342
|
+
content_types: ['text', 'markdown', 'artifact'],
|
|
343
|
+
},
|
|
344
|
+
}));
|
|
345
|
+
}
|
|
346
|
+
function ensureRegisteredProject(agentId, chatJid, timestamp) {
|
|
347
|
+
const opts = runtimeOpts;
|
|
348
|
+
if (!opts)
|
|
349
|
+
return;
|
|
350
|
+
const projects = opts.registeredProjects();
|
|
351
|
+
if (!projects[chatJid] && opts.onGroupRegistered) {
|
|
352
|
+
const project = {
|
|
353
|
+
name: agentId,
|
|
354
|
+
folder: agentId,
|
|
355
|
+
agent_id: agentId,
|
|
356
|
+
trigger: '',
|
|
357
|
+
added_at: timestamp,
|
|
358
|
+
requiresTrigger: false,
|
|
359
|
+
isMain: false,
|
|
360
|
+
};
|
|
361
|
+
opts.onGroupRegistered(chatJid, project);
|
|
362
|
+
}
|
|
363
|
+
opts.onChatMetadata(chatJid, timestamp, undefined, 'acp', false);
|
|
364
|
+
}
|
|
365
|
+
function ensureRelaySync(session) {
|
|
366
|
+
if (!defaultClient || session.relay_sync_started)
|
|
367
|
+
return;
|
|
368
|
+
session.relay_sync_started = true;
|
|
369
|
+
void defaultClient
|
|
370
|
+
.createSession({
|
|
371
|
+
agent_id: session.agent_id,
|
|
372
|
+
session_id: session.session_id,
|
|
373
|
+
thread_id: session.thread_id,
|
|
374
|
+
metadata: {
|
|
375
|
+
origin: 'supen',
|
|
376
|
+
local_session_id: session.id,
|
|
377
|
+
},
|
|
378
|
+
})
|
|
379
|
+
.then(({ session: remoteSession }) => {
|
|
380
|
+
session.relay_session_id = remoteSession.id;
|
|
381
|
+
session.relay_abort = new AbortController();
|
|
382
|
+
return defaultClient.streamSession(remoteSession.id, {
|
|
383
|
+
onEvent: async (event) => {
|
|
384
|
+
await handleRelayEvent(session, event);
|
|
385
|
+
},
|
|
386
|
+
}, session.relay_abort.signal);
|
|
387
|
+
})
|
|
388
|
+
.catch((err) => {
|
|
389
|
+
logger.warn({ err, session_id: session.id, relay_url: ACP_RELAY_URL }, 'ACP relay sync unavailable');
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
async function syncEnvelopeToRelay(session, envelope) {
|
|
393
|
+
if (!defaultClient || !session.relay_session_id)
|
|
394
|
+
return;
|
|
395
|
+
try {
|
|
396
|
+
await defaultClient.sendMessage(session.relay_session_id, {
|
|
397
|
+
message: {
|
|
398
|
+
...envelope,
|
|
399
|
+
metadata: {
|
|
400
|
+
...(envelope.metadata || {}),
|
|
401
|
+
origin: 'supen',
|
|
402
|
+
local_session_id: session.id,
|
|
403
|
+
},
|
|
404
|
+
},
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
catch (err) {
|
|
408
|
+
logger.warn({ err, session_id: session.id }, 'Failed to sync ACP message');
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
async function syncToolCallsToRelay(session, toolCalls) {
|
|
412
|
+
if (!defaultClient || !session.relay_session_id || toolCalls.length === 0)
|
|
413
|
+
return;
|
|
414
|
+
try {
|
|
415
|
+
await defaultClient.sendToolCalls(session.relay_session_id, {
|
|
416
|
+
tool_calls: toolCalls,
|
|
417
|
+
metadata: {
|
|
418
|
+
origin: 'supen',
|
|
419
|
+
local_session_id: session.id,
|
|
420
|
+
},
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
catch (err) {
|
|
424
|
+
logger.warn({ err, session_id: session.id }, 'Failed to sync ACP tool calls');
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
async function handleRelayEvent(session, event) {
|
|
428
|
+
const origin = event.message?.metadata && typeof event.message.metadata.origin === 'string'
|
|
429
|
+
? event.message.metadata.origin
|
|
430
|
+
: undefined;
|
|
431
|
+
if (origin === 'supen')
|
|
432
|
+
return;
|
|
433
|
+
if (event.type === 'message' && event.message) {
|
|
434
|
+
appendMessage(session, event.message);
|
|
435
|
+
broadcastSessionEvent(session, {
|
|
436
|
+
type: 'message',
|
|
437
|
+
session_id: session.id,
|
|
438
|
+
task_id: session.last_task_id,
|
|
439
|
+
message: event.message,
|
|
440
|
+
});
|
|
441
|
+
if (event.message.role !== 'assistant' ||
|
|
442
|
+
event.message.tool_calls?.length) {
|
|
443
|
+
await submitEnvelope(session, event.message, 'acp-relay', 'message', false);
|
|
444
|
+
}
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
if (event.type === 'tool_call' && event.tool_calls?.length) {
|
|
448
|
+
const envelope = {
|
|
449
|
+
id: randomUUID(),
|
|
450
|
+
role: 'user',
|
|
451
|
+
content: [],
|
|
452
|
+
tool_calls: event.tool_calls,
|
|
453
|
+
created_at: nowIso(),
|
|
454
|
+
metadata: { origin: 'acp-relay' },
|
|
455
|
+
};
|
|
456
|
+
await submitEnvelope(session, envelope, 'acp-relay', 'tools', false);
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
if (event.type === 'tool_result' && event.tool_results?.length) {
|
|
460
|
+
const envelope = {
|
|
461
|
+
id: randomUUID(),
|
|
462
|
+
role: 'tool',
|
|
463
|
+
content: [],
|
|
464
|
+
tool_results: event.tool_results,
|
|
465
|
+
created_at: nowIso(),
|
|
466
|
+
metadata: { origin: 'acp-relay' },
|
|
467
|
+
};
|
|
468
|
+
appendMessage(session, envelope);
|
|
469
|
+
broadcastSessionEvent(session, {
|
|
470
|
+
type: 'tool_result',
|
|
471
|
+
session_id: session.id,
|
|
472
|
+
task_id: session.last_task_id,
|
|
473
|
+
tool_results: event.tool_results,
|
|
474
|
+
message: envelope,
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
function ensureAcpSessionState(input) {
|
|
479
|
+
const parsedThread = input.thread_id ? parseThreadId(input.thread_id) : null;
|
|
480
|
+
const agentId = parsedThread?.agent_id || input.agent_id;
|
|
481
|
+
const sessionId = parsedThread?.session_id ||
|
|
482
|
+
input.session_id ||
|
|
483
|
+
input.thread_id ||
|
|
484
|
+
randomUUID();
|
|
485
|
+
const threadId = buildThreadId(agentId, sessionId);
|
|
486
|
+
const existing = sessionsById.get(threadId);
|
|
487
|
+
if (existing) {
|
|
488
|
+
if (input.metadata) {
|
|
489
|
+
existing.metadata = {
|
|
490
|
+
...(existing.metadata || {}),
|
|
491
|
+
...input.metadata,
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
existing.updated_at = nowIso();
|
|
495
|
+
return existing;
|
|
496
|
+
}
|
|
497
|
+
const chatJid = buildAcpChatJid(agentId, sessionId);
|
|
498
|
+
const timestamp = nowIso();
|
|
499
|
+
ensureRegisteredProject(agentId, chatJid, timestamp);
|
|
500
|
+
ensureSession({
|
|
501
|
+
agent_id: agentId,
|
|
502
|
+
session_id: sessionId,
|
|
503
|
+
channel: 'acp',
|
|
504
|
+
agent_name: agentId,
|
|
505
|
+
});
|
|
506
|
+
const session = {
|
|
507
|
+
id: threadId,
|
|
508
|
+
thread_id: threadId,
|
|
509
|
+
agent_id: agentId,
|
|
510
|
+
session_id: sessionId,
|
|
511
|
+
chat_jid: chatJid,
|
|
512
|
+
created_at: timestamp,
|
|
513
|
+
updated_at: timestamp,
|
|
514
|
+
stream_url: `/acp/sessions/${encodeURIComponent(threadId)}?stream=1`,
|
|
515
|
+
message_url: `/acp/sessions/${encodeURIComponent(threadId)}`,
|
|
516
|
+
tools_url: `/acp/sessions/${encodeURIComponent(threadId)}/tools`,
|
|
517
|
+
metadata: input.metadata,
|
|
518
|
+
messages: [],
|
|
519
|
+
clients: new Set(),
|
|
520
|
+
};
|
|
521
|
+
sessionsById.set(threadId, session);
|
|
522
|
+
sessionIdByChatJid.set(chatJid, threadId);
|
|
523
|
+
ensureRelaySync(session);
|
|
524
|
+
return session;
|
|
525
|
+
}
|
|
526
|
+
function getSessionByRouteId(id) {
|
|
527
|
+
const decoded = decodeURIComponent(id);
|
|
528
|
+
const existing = sessionsById.get(decoded);
|
|
529
|
+
if (existing)
|
|
530
|
+
return existing;
|
|
531
|
+
const parsed = parseThreadId(decoded);
|
|
532
|
+
if (!parsed)
|
|
533
|
+
return null;
|
|
534
|
+
return ensureAcpSessionState(parsed);
|
|
535
|
+
}
|
|
536
|
+
async function submitEnvelope(session, envelope, actorId, mode = 'message', syncToHub = true) {
|
|
537
|
+
appendMessage(session, envelope);
|
|
538
|
+
broadcastSessionEvent(session, {
|
|
539
|
+
type: 'message',
|
|
540
|
+
session_id: session.id,
|
|
541
|
+
task_id: session.last_task_id,
|
|
542
|
+
message: envelope,
|
|
543
|
+
});
|
|
544
|
+
if (syncToHub) {
|
|
545
|
+
await syncEnvelopeToRelay(session, envelope);
|
|
546
|
+
}
|
|
547
|
+
if (!isExecutableEnvelope(envelope)) {
|
|
548
|
+
return { accepted: false };
|
|
549
|
+
}
|
|
550
|
+
const task = submitTask({
|
|
551
|
+
agent_id: session.agent_id,
|
|
552
|
+
session_id: session.session_id,
|
|
553
|
+
prompt: buildPromptFromEnvelope(envelope, mode),
|
|
554
|
+
source: 'acp',
|
|
555
|
+
submitted_by: actorId,
|
|
556
|
+
submitter_type: 'api_key',
|
|
557
|
+
metadata: {
|
|
558
|
+
protocol: 'acp',
|
|
559
|
+
mode,
|
|
560
|
+
envelope,
|
|
561
|
+
},
|
|
562
|
+
});
|
|
563
|
+
session.last_task_id = task.id;
|
|
564
|
+
session.updated_at = nowIso();
|
|
565
|
+
broadcastSessionEvent(session, {
|
|
566
|
+
type: 'task',
|
|
567
|
+
session_id: session.id,
|
|
568
|
+
task_id: task.id,
|
|
569
|
+
data: {
|
|
570
|
+
phase: 'queued',
|
|
571
|
+
agent_id: session.agent_id,
|
|
572
|
+
session_id: session.session_id,
|
|
573
|
+
},
|
|
574
|
+
});
|
|
575
|
+
return {
|
|
576
|
+
accepted: true,
|
|
577
|
+
task_id: task.id,
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
export async function publishAcpTaskEvent(chatJid, event) {
|
|
581
|
+
const sessionId = sessionIdByChatJid.get(chatJid);
|
|
582
|
+
if (!sessionId)
|
|
583
|
+
return;
|
|
584
|
+
const session = sessionsById.get(sessionId);
|
|
585
|
+
if (!session)
|
|
586
|
+
return;
|
|
587
|
+
const phase = typeof event.phase === 'string' ? event.phase : 'activity';
|
|
588
|
+
const payload = {
|
|
589
|
+
type: 'task',
|
|
590
|
+
session_id: session.id,
|
|
591
|
+
task_id: typeof event.task_id === 'string' ? event.task_id : session.last_task_id,
|
|
592
|
+
data: event,
|
|
593
|
+
};
|
|
594
|
+
if (phase === 'message_delta') {
|
|
595
|
+
broadcastSessionEvent(session, {
|
|
596
|
+
type: 'message.delta',
|
|
597
|
+
session_id: session.id,
|
|
598
|
+
task_id: payload.task_id,
|
|
599
|
+
data: event,
|
|
600
|
+
});
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
if (phase === 'tool_call' && Array.isArray(event.tool_calls)) {
|
|
604
|
+
const toolCalls = event.tool_calls;
|
|
605
|
+
broadcastSessionEvent(session, {
|
|
606
|
+
type: 'tool_call',
|
|
607
|
+
session_id: session.id,
|
|
608
|
+
task_id: payload.task_id,
|
|
609
|
+
tool_calls: toolCalls,
|
|
610
|
+
data: event,
|
|
611
|
+
});
|
|
612
|
+
await syncToolCallsToRelay(session, toolCalls);
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
if (phase === 'tool_result' && Array.isArray(event.tool_results)) {
|
|
616
|
+
broadcastSessionEvent(session, {
|
|
617
|
+
type: 'tool_result',
|
|
618
|
+
session_id: session.id,
|
|
619
|
+
task_id: payload.task_id,
|
|
620
|
+
tool_results: event.tool_results,
|
|
621
|
+
data: event,
|
|
622
|
+
});
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
if (phase === 'failed' || phase === 'timeout' || phase === 'canceled') {
|
|
626
|
+
broadcastSessionEvent(session, {
|
|
627
|
+
type: 'error',
|
|
628
|
+
session_id: session.id,
|
|
629
|
+
task_id: payload.task_id,
|
|
630
|
+
error: {
|
|
631
|
+
code: event.error &&
|
|
632
|
+
typeof event.error === 'object' &&
|
|
633
|
+
typeof event.error.code === 'string'
|
|
634
|
+
? event.error.code
|
|
635
|
+
: phase,
|
|
636
|
+
message: event.error &&
|
|
637
|
+
typeof event.error === 'object' &&
|
|
638
|
+
typeof event.error.message === 'string'
|
|
639
|
+
? event.error.message
|
|
640
|
+
: `Task ${phase}`,
|
|
641
|
+
},
|
|
642
|
+
data: event,
|
|
643
|
+
});
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
broadcastSessionEvent(session, payload);
|
|
647
|
+
}
|
|
648
|
+
export async function maybeHandleAcpRequest(req, res, url) {
|
|
649
|
+
if (!url.pathname.startsWith('/acp'))
|
|
650
|
+
return false;
|
|
651
|
+
if (!ACP_ENABLED) {
|
|
652
|
+
writeProtocolError(res, 503, 'acp_disabled', 'ACP channel is disabled');
|
|
653
|
+
return true;
|
|
654
|
+
}
|
|
655
|
+
try {
|
|
656
|
+
if (url.pathname === '/acp/agents' && req.method === 'GET') {
|
|
657
|
+
writeJson(res, 200, {
|
|
658
|
+
protocol: 'acp',
|
|
659
|
+
agents: listAgentManifests(),
|
|
660
|
+
});
|
|
661
|
+
return true;
|
|
662
|
+
}
|
|
663
|
+
if (url.pathname === '/acp/sessions' && req.method === 'POST') {
|
|
664
|
+
const parsed = await readJsonBody(req);
|
|
665
|
+
const agentId = typeof parsed.agent_id === 'string' && parsed.agent_id.trim()
|
|
666
|
+
? parsed.agent_id.trim()
|
|
667
|
+
: '';
|
|
668
|
+
if (!agentId) {
|
|
669
|
+
writeProtocolError(res, 400, 'agent_id_required', 'agent_id is required');
|
|
670
|
+
return true;
|
|
671
|
+
}
|
|
672
|
+
const session = ensureAcpSessionState({
|
|
673
|
+
agent_id: agentId,
|
|
674
|
+
session_id: typeof parsed.session_id === 'string' ? parsed.session_id : undefined,
|
|
675
|
+
thread_id: typeof parsed.thread_id === 'string' ? parsed.thread_id : undefined,
|
|
676
|
+
metadata: parsed.metadata && typeof parsed.metadata === 'object'
|
|
677
|
+
? parsed.metadata
|
|
678
|
+
: undefined,
|
|
679
|
+
});
|
|
680
|
+
let taskId;
|
|
681
|
+
if (parsed.message) {
|
|
682
|
+
const envelope = normalizeAcpEnvelope(parsed.message);
|
|
683
|
+
const result = await submitEnvelope(session, envelope, 'acp');
|
|
684
|
+
taskId = result.task_id;
|
|
685
|
+
}
|
|
686
|
+
writeJson(res, taskId ? 202 : 201, {
|
|
687
|
+
session: serializeSession(session),
|
|
688
|
+
task_id: taskId || null,
|
|
689
|
+
});
|
|
690
|
+
return true;
|
|
691
|
+
}
|
|
692
|
+
const sessionToolsMatch = url.pathname.match(/^\/acp\/sessions\/([^/]+)\/tools$/);
|
|
693
|
+
if (sessionToolsMatch && req.method === 'POST') {
|
|
694
|
+
const session = getSessionByRouteId(sessionToolsMatch[1]);
|
|
695
|
+
if (!session) {
|
|
696
|
+
writeProtocolError(res, 404, 'session_not_found', 'ACP session not found');
|
|
697
|
+
return true;
|
|
698
|
+
}
|
|
699
|
+
const parsed = await readJsonBody(req);
|
|
700
|
+
const toolCalls = Array.isArray(parsed.tool_calls)
|
|
701
|
+
? parsed.tool_calls
|
|
702
|
+
.map((toolCall) => normalizeToolCall(toolCall))
|
|
703
|
+
.filter((toolCall) => !!toolCall)
|
|
704
|
+
: [];
|
|
705
|
+
if (toolCalls.length === 0) {
|
|
706
|
+
writeProtocolError(res, 400, 'tool_calls_required', 'tool_calls must contain at least one tool call');
|
|
707
|
+
return true;
|
|
708
|
+
}
|
|
709
|
+
const envelope = {
|
|
710
|
+
id: randomUUID(),
|
|
711
|
+
role: 'user',
|
|
712
|
+
content: normalizeContent(parsed.content ?? parsed.prompt ?? ''),
|
|
713
|
+
tool_calls: toolCalls,
|
|
714
|
+
created_at: nowIso(),
|
|
715
|
+
...(parsed.metadata && typeof parsed.metadata === 'object'
|
|
716
|
+
? { metadata: parsed.metadata }
|
|
717
|
+
: {}),
|
|
718
|
+
};
|
|
719
|
+
const result = await submitEnvelope(session, envelope, 'acp', 'tools');
|
|
720
|
+
writeJson(res, 202, {
|
|
721
|
+
session: serializeSession(session),
|
|
722
|
+
task_id: result.task_id || null,
|
|
723
|
+
message: envelope,
|
|
724
|
+
});
|
|
725
|
+
return true;
|
|
726
|
+
}
|
|
727
|
+
const sessionMatch = url.pathname.match(/^\/acp\/sessions\/([^/]+)$/);
|
|
728
|
+
if (sessionMatch) {
|
|
729
|
+
const session = getSessionByRouteId(sessionMatch[1]);
|
|
730
|
+
if (!session) {
|
|
731
|
+
writeProtocolError(res, 404, 'session_not_found', 'ACP session not found');
|
|
732
|
+
return true;
|
|
733
|
+
}
|
|
734
|
+
if (req.method === 'GET') {
|
|
735
|
+
if (wantsSse(req, url)) {
|
|
736
|
+
res.writeHead(200, {
|
|
737
|
+
'Content-Type': 'text/event-stream',
|
|
738
|
+
'Cache-Control': 'no-cache',
|
|
739
|
+
Connection: 'keep-alive',
|
|
740
|
+
'X-Accel-Buffering': 'no',
|
|
741
|
+
});
|
|
742
|
+
session.clients.add(res);
|
|
743
|
+
writeSseEvent(res, {
|
|
744
|
+
type: 'session',
|
|
745
|
+
session_id: session.id,
|
|
746
|
+
task_id: session.last_task_id,
|
|
747
|
+
data: {
|
|
748
|
+
session: serializeSession(session),
|
|
749
|
+
messages: session.messages.slice(-20),
|
|
750
|
+
},
|
|
751
|
+
}, 'session');
|
|
752
|
+
const heartbeat = setInterval(() => {
|
|
753
|
+
try {
|
|
754
|
+
res.write(': ping\n\n');
|
|
755
|
+
}
|
|
756
|
+
catch {
|
|
757
|
+
clearInterval(heartbeat);
|
|
758
|
+
}
|
|
759
|
+
}, 20_000);
|
|
760
|
+
req.on('close', () => {
|
|
761
|
+
clearInterval(heartbeat);
|
|
762
|
+
session.clients.delete(res);
|
|
763
|
+
});
|
|
764
|
+
return true;
|
|
765
|
+
}
|
|
766
|
+
writeJson(res, 200, {
|
|
767
|
+
session: serializeSession(session),
|
|
768
|
+
messages: session.messages,
|
|
769
|
+
});
|
|
770
|
+
return true;
|
|
771
|
+
}
|
|
772
|
+
if (req.method === 'POST') {
|
|
773
|
+
const parsed = await readJsonBody(req);
|
|
774
|
+
const envelope = normalizeAcpEnvelope(parsed, 'user');
|
|
775
|
+
const result = await submitEnvelope(session, envelope, 'acp');
|
|
776
|
+
writeJson(res, result.task_id ? 202 : 200, {
|
|
777
|
+
session: serializeSession(session),
|
|
778
|
+
task_id: result.task_id || null,
|
|
779
|
+
message: envelope,
|
|
780
|
+
});
|
|
781
|
+
return true;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
catch (err) {
|
|
786
|
+
const statusCode = err && typeof err === 'object' && 'statusCode' in err
|
|
787
|
+
? Number(err.statusCode) || 500
|
|
788
|
+
: 500;
|
|
789
|
+
const code = err && typeof err === 'object' && 'code' in err
|
|
790
|
+
? String(err.code)
|
|
791
|
+
: 'internal_error';
|
|
792
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
793
|
+
logger.error({ err, pathname: url.pathname }, 'ACP request failed');
|
|
794
|
+
writeProtocolError(res, statusCode, code, message);
|
|
795
|
+
return true;
|
|
796
|
+
}
|
|
797
|
+
return false;
|
|
798
|
+
}
|
|
799
|
+
export class AcpChannel {
|
|
800
|
+
name = 'acp';
|
|
801
|
+
opts;
|
|
802
|
+
connected = false;
|
|
803
|
+
constructor(opts) {
|
|
804
|
+
this.opts = opts;
|
|
805
|
+
runtimeOpts = opts;
|
|
806
|
+
if (ACP_RELAY_URL) {
|
|
807
|
+
try {
|
|
808
|
+
const trustedEndpoint = validateOutboundEndpoint(ACP_RELAY_URL, {
|
|
809
|
+
allowedProtocols: ['http:', 'https:'],
|
|
810
|
+
label: 'ACP_RELAY_URL',
|
|
811
|
+
});
|
|
812
|
+
defaultClient = new ACPClient({
|
|
813
|
+
baseUrl: trustedEndpoint.toString(),
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
catch (err) {
|
|
817
|
+
logger.error({ err: err.message, acp_relay_url: ACP_RELAY_URL }, 'ACP channel disabled remote sync due to endpoint security policy');
|
|
818
|
+
defaultClient = null;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
async connect() {
|
|
823
|
+
this.connected = true;
|
|
824
|
+
logger.info({
|
|
825
|
+
relay_url: ACP_RELAY_URL || null,
|
|
826
|
+
}, 'ACP channel ready');
|
|
827
|
+
}
|
|
828
|
+
async sendMessage(jid, text, _options) {
|
|
829
|
+
const sessionId = sessionIdByChatJid.get(jid);
|
|
830
|
+
if (!sessionId)
|
|
831
|
+
return;
|
|
832
|
+
const session = sessionsById.get(sessionId);
|
|
833
|
+
if (!session || !text.trim())
|
|
834
|
+
return;
|
|
835
|
+
const envelope = {
|
|
836
|
+
id: randomUUID(),
|
|
837
|
+
role: 'assistant',
|
|
838
|
+
content: [{ type: 'markdown', text }],
|
|
839
|
+
created_at: nowIso(),
|
|
840
|
+
};
|
|
841
|
+
appendMessage(session, envelope);
|
|
842
|
+
broadcastSessionEvent(session, {
|
|
843
|
+
type: 'message',
|
|
844
|
+
session_id: session.id,
|
|
845
|
+
task_id: session.last_task_id,
|
|
846
|
+
message: envelope,
|
|
847
|
+
});
|
|
848
|
+
await syncEnvelopeToRelay(session, envelope);
|
|
849
|
+
}
|
|
850
|
+
async sendFile(jid, filePath, caption) {
|
|
851
|
+
const sessionId = sessionIdByChatJid.get(jid);
|
|
852
|
+
if (!sessionId)
|
|
853
|
+
return;
|
|
854
|
+
const session = sessionsById.get(sessionId);
|
|
855
|
+
if (!session)
|
|
856
|
+
return;
|
|
857
|
+
const artifactPart = {
|
|
858
|
+
type: 'artifact',
|
|
859
|
+
name: path.basename(filePath),
|
|
860
|
+
path: filePath,
|
|
861
|
+
mime_type: inferMimeType(filePath),
|
|
862
|
+
description: caption,
|
|
863
|
+
};
|
|
864
|
+
if (fs.existsSync(filePath)) {
|
|
865
|
+
artifactPart.uri = filePath;
|
|
866
|
+
}
|
|
867
|
+
const envelope = {
|
|
868
|
+
id: randomUUID(),
|
|
869
|
+
role: 'assistant',
|
|
870
|
+
content: [
|
|
871
|
+
...(caption ? [{ type: 'markdown', text: caption }] : []),
|
|
872
|
+
artifactPart,
|
|
873
|
+
],
|
|
874
|
+
created_at: nowIso(),
|
|
875
|
+
};
|
|
876
|
+
appendMessage(session, envelope);
|
|
877
|
+
broadcastSessionEvent(session, {
|
|
878
|
+
type: 'message',
|
|
879
|
+
session_id: session.id,
|
|
880
|
+
task_id: session.last_task_id,
|
|
881
|
+
message: envelope,
|
|
882
|
+
});
|
|
883
|
+
await syncEnvelopeToRelay(session, envelope);
|
|
884
|
+
}
|
|
885
|
+
isConnected() {
|
|
886
|
+
return this.connected;
|
|
887
|
+
}
|
|
888
|
+
ownsJid(jid) {
|
|
889
|
+
return jid.startsWith(ACP_JID_PREFIX);
|
|
890
|
+
}
|
|
891
|
+
async disconnect() {
|
|
892
|
+
this.connected = false;
|
|
893
|
+
for (const session of sessionsById.values()) {
|
|
894
|
+
session.relay_abort?.abort();
|
|
895
|
+
for (const client of session.clients) {
|
|
896
|
+
try {
|
|
897
|
+
client.end();
|
|
898
|
+
}
|
|
899
|
+
catch {
|
|
900
|
+
/* ignore */
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
session.clients.clear();
|
|
904
|
+
}
|
|
905
|
+
logger.info('ACP channel disconnected');
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
function createAcpChannel(opts) {
|
|
909
|
+
if (!ACP_ENABLED) {
|
|
910
|
+
logger.debug('ACP channel disabled (ACP_ENABLED=false)');
|
|
911
|
+
return null;
|
|
912
|
+
}
|
|
913
|
+
return new AcpChannel(opts);
|
|
914
|
+
}
|
|
915
|
+
registerChannel('acp', createAcpChannel);
|
|
916
|
+
//# sourceMappingURL=acp.js.map
|