@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,963 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { randomUUID } from 'crypto';
|
|
4
|
+
import { logger } from '../../core/logger.js';
|
|
5
|
+
import { ensureSession, getSessionForAgent, getSessionInteractionEvents, getSessionUiEvents, getSessionsForAgent, getArchivedSessionsForAgent, getAutomationRunById, getAutomationById, getAutomationState, listAutomationRuns, finalizeRunningAutomationRunForSession, finalizeAutomationRun, clearSessionSdkId, deleteSessionForAgent, archiveSessionForAgent, restoreSessionForAgent, updateAutomationState, updateSessionMetadata, updateSessionStatus, storeMessage, } from '../../core/store.js';
|
|
6
|
+
import { ASSISTANT_NAME, SUPEN_HOME } from '../../core/config.js';
|
|
7
|
+
import { writeJson, writeProtocolError, readJsonBody } from '../response.js';
|
|
8
|
+
import { addClient, broadcastToChat, buildHttpSessionId, removeClient } from '../stream.js';
|
|
9
|
+
import { deriveHttpSenderIdentity } from '../context.js';
|
|
10
|
+
import { readCodexThreadTitleFromStateDb, readCodexThreadTitleFromSessionIndex, } from '../thread-title.js';
|
|
11
|
+
import { buildWorkspaceAttachmentPrompt, extractUserMessageText, persistUserMessageFiles, } from './chat-input.js';
|
|
12
|
+
import { listWebCommands, resolveWebCommandInput } from '../command-catalog.js';
|
|
13
|
+
import { AgentCortex } from '../../core/cortex.js';
|
|
14
|
+
import { runSessionAutonomyPrelude } from '../../autonomy/session-autonomy.js';
|
|
15
|
+
import { recordSessionControlCommand } from '../../core/control-commands.js';
|
|
16
|
+
import { listControlLogEntries } from '../../core/control-log.js';
|
|
17
|
+
import { appendThreadEvent } from '../../core/thread-event-log.js';
|
|
18
|
+
import { projectThreadRuntimeState } from '../../core/thread-runtime-state.js';
|
|
19
|
+
const recentPrewarmAttempts = new Map();
|
|
20
|
+
const PREWARM_COOLDOWN_MS = 15_000;
|
|
21
|
+
function autonomyPreludeTimeoutMs() {
|
|
22
|
+
const raw = Number(process.env.SUPEN_AUTONOMY_PRELUDE_TIMEOUT_MS || 1500);
|
|
23
|
+
return Number.isFinite(raw) && raw >= 0 ? raw : 1500;
|
|
24
|
+
}
|
|
25
|
+
async function runSessionAutonomyPreludeBounded(input) {
|
|
26
|
+
const timeoutMs = autonomyPreludeTimeoutMs();
|
|
27
|
+
if (timeoutMs === 0)
|
|
28
|
+
return null;
|
|
29
|
+
let timeout;
|
|
30
|
+
try {
|
|
31
|
+
return await Promise.race([
|
|
32
|
+
runSessionAutonomyPrelude(input),
|
|
33
|
+
new Promise((resolve) => {
|
|
34
|
+
timeout = setTimeout(() => resolve(null), timeoutMs);
|
|
35
|
+
timeout.unref?.();
|
|
36
|
+
}),
|
|
37
|
+
]);
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
if (timeout)
|
|
41
|
+
clearTimeout(timeout);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export function captureWebUserMessage(input) {
|
|
45
|
+
try {
|
|
46
|
+
appendThreadEvent({
|
|
47
|
+
threadId: input.threadId,
|
|
48
|
+
runtimeThreadId: input.runtimeThreadId || input.threadId,
|
|
49
|
+
source: 'web',
|
|
50
|
+
eventType: 'user_message',
|
|
51
|
+
rawPayload: input.userMessage,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
logger.warn({
|
|
56
|
+
err: error,
|
|
57
|
+
threadId: input.threadId,
|
|
58
|
+
runtimeThreadId: input.runtimeThreadId || input.threadId,
|
|
59
|
+
}, 'Failed to capture web user message');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function serializeTask(session) {
|
|
63
|
+
const { session_id: sessionId, ...rest } = session;
|
|
64
|
+
return {
|
|
65
|
+
...rest,
|
|
66
|
+
task_id: sessionId,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function isNoOpAutomationRun(runId) {
|
|
70
|
+
if (!runId)
|
|
71
|
+
return false;
|
|
72
|
+
const run = getAutomationRunById(runId);
|
|
73
|
+
return Boolean(run?.status === 'succeeded' &&
|
|
74
|
+
run.no_op_detected &&
|
|
75
|
+
!run.notification_sent);
|
|
76
|
+
}
|
|
77
|
+
function getNoOpAutomationTaskIds(messages) {
|
|
78
|
+
const taskIds = new Set();
|
|
79
|
+
for (const message of messages) {
|
|
80
|
+
if (!message.task_id)
|
|
81
|
+
continue;
|
|
82
|
+
if (isNoOpAutomationRun(message.automation_run_id) ||
|
|
83
|
+
isNoOpAutomationRun(message.schedule_run_id)) {
|
|
84
|
+
taskIds.add(message.task_id);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return taskIds;
|
|
88
|
+
}
|
|
89
|
+
function runtimeStateForThread(threadId) {
|
|
90
|
+
return projectThreadRuntimeState(threadId);
|
|
91
|
+
}
|
|
92
|
+
function isRecord(value) {
|
|
93
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
94
|
+
}
|
|
95
|
+
function stringField(record, key) {
|
|
96
|
+
const value = record[key];
|
|
97
|
+
return typeof value === 'string' ? value : undefined;
|
|
98
|
+
}
|
|
99
|
+
function rawAppServerPayloadFromLoggedEvent(event) {
|
|
100
|
+
const rawPayload = event.raw_payload;
|
|
101
|
+
if (!isRecord(rawPayload))
|
|
102
|
+
return rawPayload;
|
|
103
|
+
const data = rawPayload.data;
|
|
104
|
+
if (isRecord(data) && data.raw)
|
|
105
|
+
return data.raw;
|
|
106
|
+
return rawPayload;
|
|
107
|
+
}
|
|
108
|
+
function runtimeThreadIdFromLoggedEvent(event) {
|
|
109
|
+
if (!isRecord(event))
|
|
110
|
+
return null;
|
|
111
|
+
const directRuntimeThreadId = stringField(event, 'runtime_thread_id');
|
|
112
|
+
const rawPayload = rawAppServerPayloadFromLoggedEvent(event);
|
|
113
|
+
const params = isRecord(rawPayload) && isRecord(rawPayload.params)
|
|
114
|
+
? rawPayload.params
|
|
115
|
+
: null;
|
|
116
|
+
const payloadThreadId = params ? stringField(params, 'threadId') : undefined;
|
|
117
|
+
const threadId = payloadThreadId || directRuntimeThreadId;
|
|
118
|
+
return threadId || null;
|
|
119
|
+
}
|
|
120
|
+
function readRuntimeThreadIdsFromJsonl(filePath) {
|
|
121
|
+
if (!fs.existsSync(filePath))
|
|
122
|
+
return [];
|
|
123
|
+
const ids = [];
|
|
124
|
+
const lines = fs
|
|
125
|
+
.readFileSync(filePath, 'utf8')
|
|
126
|
+
.split('\n')
|
|
127
|
+
.filter((line) => line.trim().length > 0)
|
|
128
|
+
.reverse();
|
|
129
|
+
for (const line of lines) {
|
|
130
|
+
try {
|
|
131
|
+
const threadId = runtimeThreadIdFromLoggedEvent(JSON.parse(line));
|
|
132
|
+
if (threadId && !ids.includes(threadId))
|
|
133
|
+
ids.push(threadId);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
// Ignore corrupt event lines; title refresh should be best-effort.
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return ids;
|
|
140
|
+
}
|
|
141
|
+
function runtimeThreadIdCandidatesForThread(threadId) {
|
|
142
|
+
const projectionRuntimeThreadId = runtimeStateForThread(threadId).runtime.runtime_thread_id;
|
|
143
|
+
const candidates = [
|
|
144
|
+
projectionRuntimeThreadId,
|
|
145
|
+
...readRuntimeThreadIdsFromJsonl(path.join(SUPEN_HOME, 'threads', threadId, 'event-log', 'raw-events.jsonl')),
|
|
146
|
+
...readRuntimeThreadIdsFromJsonl(path.join(SUPEN_HOME, 'threads', threadId, 'event-mirror', 'raw-events.jsonl')),
|
|
147
|
+
threadId,
|
|
148
|
+
].filter((value) => Boolean(value));
|
|
149
|
+
return candidates.filter((value, index) => candidates.indexOf(value) === index);
|
|
150
|
+
}
|
|
151
|
+
function readCodexTitleForThread(threadId) {
|
|
152
|
+
for (const candidate of runtimeThreadIdCandidatesForThread(threadId)) {
|
|
153
|
+
const title = readCodexThreadTitleFromSessionIndex(candidate) ||
|
|
154
|
+
readCodexThreadTitleFromStateDb(candidate);
|
|
155
|
+
if (title)
|
|
156
|
+
return title;
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
function shouldReplaceTitle(input) {
|
|
161
|
+
if (!input.currentTitle)
|
|
162
|
+
return true;
|
|
163
|
+
if (input.currentTitle === input.nextTitle)
|
|
164
|
+
return false;
|
|
165
|
+
if (input.force)
|
|
166
|
+
return true;
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
function refreshThreadTitleFromCodexIndex(agentId, threadId, options = {}) {
|
|
170
|
+
const session = getSessionForAgent(agentId, threadId);
|
|
171
|
+
if (!session)
|
|
172
|
+
return { updated: false, title: null, previousTitle: null, reason: 'thread_not_found' };
|
|
173
|
+
const title = readCodexTitleForThread(threadId);
|
|
174
|
+
if (!title) {
|
|
175
|
+
return {
|
|
176
|
+
updated: false,
|
|
177
|
+
title: null,
|
|
178
|
+
previousTitle: session.title || null,
|
|
179
|
+
reason: 'codex_title_not_found',
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
const previousTitle = session.title?.trim() || '';
|
|
183
|
+
if (!shouldReplaceTitle({
|
|
184
|
+
currentTitle: previousTitle,
|
|
185
|
+
nextTitle: title,
|
|
186
|
+
force: options.force === true,
|
|
187
|
+
})) {
|
|
188
|
+
return {
|
|
189
|
+
updated: false,
|
|
190
|
+
title,
|
|
191
|
+
previousTitle: previousTitle || null,
|
|
192
|
+
reason: 'title_preserved',
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
updateSessionMetadata(agentId, threadId, { title });
|
|
196
|
+
broadcastToChat(buildHttpSessionId(agentId, threadId), {
|
|
197
|
+
type: 'session_updated',
|
|
198
|
+
session: { task_id: threadId, title },
|
|
199
|
+
});
|
|
200
|
+
return {
|
|
201
|
+
updated: true,
|
|
202
|
+
title,
|
|
203
|
+
previousTitle: previousTitle || null,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function runtimeStateSummary(projection) {
|
|
207
|
+
return {
|
|
208
|
+
event_log_head: projection.event_log_head,
|
|
209
|
+
projection_version: projection.projection_version,
|
|
210
|
+
event_log: projection.event_log,
|
|
211
|
+
runtime: projection.runtime,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function prewarmSessionInBackground(agentId, sessionId, options) {
|
|
215
|
+
const key = [
|
|
216
|
+
agentId,
|
|
217
|
+
sessionId,
|
|
218
|
+
options?.model || '',
|
|
219
|
+
options?.permissionMode || '',
|
|
220
|
+
options?.networkAccess ? 'network' : '',
|
|
221
|
+
].join(':');
|
|
222
|
+
const now = Date.now();
|
|
223
|
+
const lastAttemptAt = recentPrewarmAttempts.get(key) || 0;
|
|
224
|
+
if (now - lastAttemptAt < PREWARM_COOLDOWN_MS) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
recentPrewarmAttempts.set(key, now);
|
|
228
|
+
const cortex = new AgentCortex(agentId, sessionId);
|
|
229
|
+
void cortex.prewarmNativeSession(options);
|
|
230
|
+
}
|
|
231
|
+
function readRuntimeOptions(body) {
|
|
232
|
+
const model = typeof body?.model === 'string' && body.model.trim()
|
|
233
|
+
? body.model.trim()
|
|
234
|
+
: undefined;
|
|
235
|
+
const effortText = typeof body?.effort === 'string' && body.effort.trim()
|
|
236
|
+
? body.effort.trim().toLowerCase()
|
|
237
|
+
: typeof body?.reasoningEffort === 'string' && body.reasoningEffort.trim()
|
|
238
|
+
? body.reasoningEffort.trim().toLowerCase()
|
|
239
|
+
: undefined;
|
|
240
|
+
const effort = effortText === 'low' ||
|
|
241
|
+
effortText === 'medium' ||
|
|
242
|
+
effortText === 'high' ||
|
|
243
|
+
effortText === 'xhigh'
|
|
244
|
+
? effortText
|
|
245
|
+
: effortText === 'extra-high' || effortText === 'extra_high' || effortText === 'extra high'
|
|
246
|
+
? 'xhigh'
|
|
247
|
+
: undefined;
|
|
248
|
+
const permissionMode = body?.permissionMode === 'default' ||
|
|
249
|
+
body?.permissionMode === 'read-only' ||
|
|
250
|
+
body?.permissionMode === 'workspace-write' ||
|
|
251
|
+
body?.permissionMode === 'full-access' ||
|
|
252
|
+
body?.permissionMode === 'custom'
|
|
253
|
+
? body.permissionMode
|
|
254
|
+
: undefined;
|
|
255
|
+
const networkAccess = body?.networkAccess === true;
|
|
256
|
+
return {
|
|
257
|
+
...(model ? { model } : {}),
|
|
258
|
+
...(effort ? { effort } : {}),
|
|
259
|
+
...(permissionMode ? { permissionMode } : {}),
|
|
260
|
+
...(networkAccess ? { networkAccess } : {}),
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
function resetAutomationRuntimeForSession(sessionId) {
|
|
264
|
+
const automationMatch = sessionId.match(/^sched-(.+)$/);
|
|
265
|
+
if (!automationMatch)
|
|
266
|
+
return null;
|
|
267
|
+
const automationId = automationMatch[1];
|
|
268
|
+
const automation = getAutomationById(automationId);
|
|
269
|
+
const state = getAutomationState(automationId);
|
|
270
|
+
if (!automation || !state) {
|
|
271
|
+
return { automation_id: automationId, status: 'not_found' };
|
|
272
|
+
}
|
|
273
|
+
if (state.execution_status !== 'running' && state.execution_status !== 'claimed') {
|
|
274
|
+
return { automation_id: automationId, status: 'not_running' };
|
|
275
|
+
}
|
|
276
|
+
const now = new Date().toISOString();
|
|
277
|
+
const resetError = 'Automation runtime reset by user';
|
|
278
|
+
const runningRun = listAutomationRuns({
|
|
279
|
+
automation_id: automationId,
|
|
280
|
+
status: 'running',
|
|
281
|
+
limit: 1,
|
|
282
|
+
})[0];
|
|
283
|
+
if (runningRun) {
|
|
284
|
+
const finalized = finalizeAutomationRun(runningRun.run_id, {
|
|
285
|
+
status: 'failed',
|
|
286
|
+
finished_at: now,
|
|
287
|
+
error: resetError,
|
|
288
|
+
notification_sent: false,
|
|
289
|
+
});
|
|
290
|
+
if (finalized) {
|
|
291
|
+
return {
|
|
292
|
+
automation_id: automationId,
|
|
293
|
+
status: 'finalized_run',
|
|
294
|
+
run_id: finalized.run_id,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
updateAutomationState(automationId, {
|
|
299
|
+
execution_status: 'idle',
|
|
300
|
+
claimed_at: null,
|
|
301
|
+
started_at: null,
|
|
302
|
+
last_error: resetError,
|
|
303
|
+
last_run: now,
|
|
304
|
+
failure_count: state.failure_count + 1,
|
|
305
|
+
});
|
|
306
|
+
return { automation_id: automationId, status: 'reset_state' };
|
|
307
|
+
}
|
|
308
|
+
export async function handleSessionsRoutes(req, res, url, pathname, method, adminContext, onMessage, onSessionStop) {
|
|
309
|
+
const sseV1Match = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/sessions\/([^/]+)\/stream$/);
|
|
310
|
+
if (sseV1Match && method === 'GET') {
|
|
311
|
+
const agentId = decodeURIComponent(sseV1Match[1]);
|
|
312
|
+
const sessionId = decodeURIComponent(sseV1Match[2]);
|
|
313
|
+
const session = getSessionForAgent(agentId, sessionId);
|
|
314
|
+
if (!session) {
|
|
315
|
+
writeProtocolError(res, 404, 'input_error', 'session_not_found', `Task "${sessionId}" was not found for agent "${agentId}"`);
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
const chatJid = buildHttpSessionId(agentId, sessionId);
|
|
319
|
+
let clientRegistered = false;
|
|
320
|
+
const cleanup = () => {
|
|
321
|
+
if (!clientRegistered)
|
|
322
|
+
return;
|
|
323
|
+
removeClient(chatJid, res);
|
|
324
|
+
clientRegistered = false;
|
|
325
|
+
};
|
|
326
|
+
res.writeHead(200, {
|
|
327
|
+
'Content-Type': 'text/event-stream; charset=utf-8',
|
|
328
|
+
'Cache-Control': 'no-cache',
|
|
329
|
+
'Connection': 'keep-alive',
|
|
330
|
+
'X-Accel-Buffering': 'no',
|
|
331
|
+
'x-vercel-ai-ui-message-stream': 'v1',
|
|
332
|
+
});
|
|
333
|
+
addClient(chatJid, res);
|
|
334
|
+
clientRegistered = true;
|
|
335
|
+
req.on('close', cleanup);
|
|
336
|
+
res.on('close', cleanup);
|
|
337
|
+
res.flushHeaders?.();
|
|
338
|
+
res.write(': connected\n\n');
|
|
339
|
+
res.flush?.();
|
|
340
|
+
return true;
|
|
341
|
+
}
|
|
342
|
+
const commandsV1Match = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/sessions\/([^/]+)\/commands$/);
|
|
343
|
+
if (commandsV1Match && method === 'GET') {
|
|
344
|
+
const agentId = decodeURIComponent(commandsV1Match[1]);
|
|
345
|
+
const commands = await listWebCommands({ channel: 'web', agentId });
|
|
346
|
+
writeJson(res, 200, { commands });
|
|
347
|
+
return true;
|
|
348
|
+
}
|
|
349
|
+
const agentCommandsV1Match = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/commands$/);
|
|
350
|
+
if (agentCommandsV1Match && method === 'GET') {
|
|
351
|
+
const agentId = decodeURIComponent(agentCommandsV1Match[1]);
|
|
352
|
+
const commands = await listWebCommands({ channel: 'web', agentId });
|
|
353
|
+
writeJson(res, 200, { commands });
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
const resolveCommandsV1Match = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/sessions\/([^/]+)\/commands\/resolve$/);
|
|
357
|
+
if (resolveCommandsV1Match && method === 'POST') {
|
|
358
|
+
const agentId = decodeURIComponent(resolveCommandsV1Match[1]);
|
|
359
|
+
const parsed = await readJsonBody(req);
|
|
360
|
+
const input = typeof parsed?.input === 'string' ? parsed.input : '';
|
|
361
|
+
const channel = typeof parsed?.channel === 'string' ? parsed.channel : 'web';
|
|
362
|
+
if (!input.trim()) {
|
|
363
|
+
writeProtocolError(res, 400, 'input_error', 'content_required', 'input is required');
|
|
364
|
+
return true;
|
|
365
|
+
}
|
|
366
|
+
const resolved = await resolveWebCommandInput(input, { channel, agentId });
|
|
367
|
+
writeJson(res, 200, resolved);
|
|
368
|
+
return true;
|
|
369
|
+
}
|
|
370
|
+
const stopV1Match = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/sessions\/([^/]+)\/stop$/);
|
|
371
|
+
if (stopV1Match && method === 'POST') {
|
|
372
|
+
const agentId = decodeURIComponent(stopV1Match[1]);
|
|
373
|
+
const sessionId = decodeURIComponent(stopV1Match[2]);
|
|
374
|
+
if (!onSessionStop) {
|
|
375
|
+
writeProtocolError(res, 501, 'input_error', 'stop_not_supported', 'Session stop is not supported by this daemon.');
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
const actor = adminContext?.actor || 'http';
|
|
379
|
+
recordSessionControlCommand({
|
|
380
|
+
agentId,
|
|
381
|
+
sessionId,
|
|
382
|
+
surface: 'web',
|
|
383
|
+
commandType: 'session.stop',
|
|
384
|
+
method: 'turn/interrupt',
|
|
385
|
+
actor,
|
|
386
|
+
status: 'received',
|
|
387
|
+
payload: { endpoint: 'stop' },
|
|
388
|
+
});
|
|
389
|
+
const result = onSessionStop(agentId, sessionId, actor);
|
|
390
|
+
if (!result.ok && result.code !== 'session_not_running') {
|
|
391
|
+
writeProtocolError(res, 404, 'input_error', result.code, result.message);
|
|
392
|
+
return true;
|
|
393
|
+
}
|
|
394
|
+
const finalizedAutomationRun = finalizeRunningAutomationRunForSession(agentId, sessionId, {
|
|
395
|
+
actor,
|
|
396
|
+
});
|
|
397
|
+
const automationReset = finalizedAutomationRun
|
|
398
|
+
? {
|
|
399
|
+
automation_id: finalizedAutomationRun.automation_id,
|
|
400
|
+
status: 'finalized_run',
|
|
401
|
+
run_id: finalizedAutomationRun.run_id,
|
|
402
|
+
}
|
|
403
|
+
: resetAutomationRuntimeForSession(sessionId);
|
|
404
|
+
const automationRuntimeReleased = automationReset?.status === 'finalized_run' || automationReset?.status === 'reset_state';
|
|
405
|
+
if (automationRuntimeReleased) {
|
|
406
|
+
updateSessionStatus(agentId, sessionId, 'idle');
|
|
407
|
+
const refreshedSession = getSessionForAgent(agentId, sessionId);
|
|
408
|
+
if (refreshedSession) {
|
|
409
|
+
broadcastToChat(buildHttpSessionId(agentId, sessionId), {
|
|
410
|
+
type: 'session_updated',
|
|
411
|
+
session: refreshedSession,
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
writeJson(res, 200, {
|
|
416
|
+
...result,
|
|
417
|
+
ok: result.ok || automationRuntimeReleased,
|
|
418
|
+
automation_reset: automationReset,
|
|
419
|
+
});
|
|
420
|
+
return true;
|
|
421
|
+
}
|
|
422
|
+
const resetRuntimeV1Match = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/sessions\/([^/]+)\/reset-runtime$/);
|
|
423
|
+
if (resetRuntimeV1Match && method === 'POST') {
|
|
424
|
+
const agentId = decodeURIComponent(resetRuntimeV1Match[1]);
|
|
425
|
+
const sessionId = decodeURIComponent(resetRuntimeV1Match[2]);
|
|
426
|
+
const session = getSessionForAgent(agentId, sessionId);
|
|
427
|
+
if (!session) {
|
|
428
|
+
writeProtocolError(res, 404, 'input_error', 'session_not_found', `Task "${sessionId}" was not found for agent "${agentId}"`);
|
|
429
|
+
return true;
|
|
430
|
+
}
|
|
431
|
+
const clearedSdkSessionId = Boolean(session.sdk_session_id);
|
|
432
|
+
clearSessionSdkId(agentId, sessionId);
|
|
433
|
+
updateSessionStatus(agentId, sessionId, 'idle');
|
|
434
|
+
const automationReset = resetAutomationRuntimeForSession(sessionId);
|
|
435
|
+
const refreshedSession = getSessionForAgent(agentId, sessionId) || {
|
|
436
|
+
...session,
|
|
437
|
+
status: 'idle',
|
|
438
|
+
};
|
|
439
|
+
broadcastToChat(buildHttpSessionId(agentId, sessionId), {
|
|
440
|
+
type: 'session_updated',
|
|
441
|
+
session: serializeTask(refreshedSession),
|
|
442
|
+
});
|
|
443
|
+
writeJson(res, 200, {
|
|
444
|
+
ok: true,
|
|
445
|
+
session: serializeTask(refreshedSession),
|
|
446
|
+
cleared_sdk_session_id: clearedSdkSessionId,
|
|
447
|
+
automation_reset: automationReset,
|
|
448
|
+
});
|
|
449
|
+
return true;
|
|
450
|
+
}
|
|
451
|
+
const prewarmV1Match = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/sessions\/([^/]+)\/prewarm$/);
|
|
452
|
+
if (prewarmV1Match && method === 'POST') {
|
|
453
|
+
const agentId = decodeURIComponent(prewarmV1Match[1]);
|
|
454
|
+
const sessionId = decodeURIComponent(prewarmV1Match[2]);
|
|
455
|
+
const session = getSessionForAgent(agentId, sessionId);
|
|
456
|
+
if (!session) {
|
|
457
|
+
writeProtocolError(res, 404, 'input_error', 'session_not_found', `Task "${sessionId}" was not found for agent "${agentId}"`);
|
|
458
|
+
return true;
|
|
459
|
+
}
|
|
460
|
+
const parsed = await readJsonBody(req).catch(() => ({}));
|
|
461
|
+
const runtimeOptions = readRuntimeOptions(parsed);
|
|
462
|
+
prewarmSessionInBackground(agentId, sessionId, runtimeOptions);
|
|
463
|
+
writeJson(res, 202, { ok: true, task_id: sessionId, prewarming: true });
|
|
464
|
+
return true;
|
|
465
|
+
}
|
|
466
|
+
const chatV1Match = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/sessions\/([^/]+)\/chat$/);
|
|
467
|
+
if (chatV1Match && method === 'POST') {
|
|
468
|
+
const agentId = decodeURIComponent(chatV1Match[1]);
|
|
469
|
+
const sessionId = decodeURIComponent(chatV1Match[2]);
|
|
470
|
+
const parsed = await readJsonBody(req);
|
|
471
|
+
const { messages } = parsed;
|
|
472
|
+
const runtimeOptions = readRuntimeOptions(parsed);
|
|
473
|
+
const model = runtimeOptions.model;
|
|
474
|
+
if (!messages || !Array.isArray(messages)) {
|
|
475
|
+
writeProtocolError(res, 400, 'input_error', 'content_required', 'messages array is required');
|
|
476
|
+
return true;
|
|
477
|
+
}
|
|
478
|
+
const chatJid = buildHttpSessionId(agentId, sessionId);
|
|
479
|
+
ensureSession({ agent_id: agentId, session_id: sessionId, channel: 'http', agent_name: agentId });
|
|
480
|
+
prewarmSessionInBackground(agentId, sessionId, runtimeOptions);
|
|
481
|
+
const senderIdentity = deriveHttpSenderIdentity(adminContext);
|
|
482
|
+
const rawLastUserMsg = messages[messages.length - 1];
|
|
483
|
+
const rawUserText = rawLastUserMsg?.role === 'user' ? extractUserMessageText(rawLastUserMsg) : '';
|
|
484
|
+
const resolvedUserInput = rawLastUserMsg?.role === 'user'
|
|
485
|
+
? await resolveWebCommandInput(rawUserText, { channel: 'web', agentId })
|
|
486
|
+
: null;
|
|
487
|
+
const executionText = resolvedUserInput?.kind === 'chat' || resolvedUserInput?.kind === 'builtin'
|
|
488
|
+
? resolvedUserInput.text
|
|
489
|
+
: rawUserText;
|
|
490
|
+
const displayUserText = resolvedUserInput?.kind === 'chat'
|
|
491
|
+
? resolvedUserInput.rawInput
|
|
492
|
+
: executionText;
|
|
493
|
+
const taskId = randomUUID();
|
|
494
|
+
recordSessionControlCommand({
|
|
495
|
+
agentId,
|
|
496
|
+
sessionId,
|
|
497
|
+
turnId: taskId,
|
|
498
|
+
surface: 'web',
|
|
499
|
+
commandType: 'session.instruct',
|
|
500
|
+
method: 'turn/start',
|
|
501
|
+
actor: senderIdentity.sender,
|
|
502
|
+
status: 'received',
|
|
503
|
+
payload: {
|
|
504
|
+
endpoint: 'chat',
|
|
505
|
+
message_excerpt: (displayUserText || rawUserText || '').slice(0, 240),
|
|
506
|
+
model,
|
|
507
|
+
runtime_options: runtimeOptions,
|
|
508
|
+
},
|
|
509
|
+
});
|
|
510
|
+
const uploadedFiles = rawLastUserMsg?.role === 'user'
|
|
511
|
+
? persistUserMessageFiles(agentId, rawLastUserMsg, { sessionId, taskId })
|
|
512
|
+
: [];
|
|
513
|
+
const attachmentPrompt = buildWorkspaceAttachmentPrompt(uploadedFiles);
|
|
514
|
+
const storedUserContent = [displayUserText, attachmentPrompt].filter(Boolean).join('\n\n').trim();
|
|
515
|
+
let autonomyMetadata = null;
|
|
516
|
+
try {
|
|
517
|
+
const prelude = await runSessionAutonomyPreludeBounded({
|
|
518
|
+
agentId,
|
|
519
|
+
sessionId,
|
|
520
|
+
taskId,
|
|
521
|
+
message: displayUserText || rawUserText || '',
|
|
522
|
+
});
|
|
523
|
+
if (prelude) {
|
|
524
|
+
autonomyMetadata = {
|
|
525
|
+
decision: prelude.decision,
|
|
526
|
+
proof: prelude.proof,
|
|
527
|
+
memoryCandidates: prelude.memoryCandidates,
|
|
528
|
+
activeMemorySignals: prelude.activeMemorySignals,
|
|
529
|
+
executionContext: prelude.executionContext,
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
logger.warn({ agentId, sessionId, timeoutMs: autonomyPreludeTimeoutMs() }, 'autonomy prelude timed out; dispatching chat without autonomy metadata');
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
catch (error) {
|
|
537
|
+
logger.warn({ err: error, agentId, sessionId }, 'autonomy prelude failed');
|
|
538
|
+
}
|
|
539
|
+
const userMessage = {
|
|
540
|
+
id: `http-${Date.now()}-${taskId.slice(0, 8)}`,
|
|
541
|
+
chat_jid: chatJid,
|
|
542
|
+
sender: senderIdentity.sender,
|
|
543
|
+
sender_name: senderIdentity.sender_name,
|
|
544
|
+
content: storedUserContent || '',
|
|
545
|
+
timestamp: new Date().toISOString(),
|
|
546
|
+
is_from_me: false,
|
|
547
|
+
agent_id: agentId,
|
|
548
|
+
session_id: sessionId,
|
|
549
|
+
task_id: taskId,
|
|
550
|
+
attachments: uploadedFiles,
|
|
551
|
+
model,
|
|
552
|
+
metadata: {
|
|
553
|
+
source: 'http-chat',
|
|
554
|
+
runtime_options: runtimeOptions,
|
|
555
|
+
...(autonomyMetadata ? { autonomy: autonomyMetadata } : {}),
|
|
556
|
+
},
|
|
557
|
+
};
|
|
558
|
+
const userContentForTitle = attachmentPrompt || storedUserContent || rawUserText || '';
|
|
559
|
+
const waitMs = 100;
|
|
560
|
+
const timeoutMs = 180_000;
|
|
561
|
+
const waitUntil = Date.now() + timeoutMs;
|
|
562
|
+
let clientRegistered = false;
|
|
563
|
+
const cleanup = () => {
|
|
564
|
+
if (!clientRegistered)
|
|
565
|
+
return;
|
|
566
|
+
removeClient(chatJid, res);
|
|
567
|
+
clientRegistered = false;
|
|
568
|
+
};
|
|
569
|
+
try {
|
|
570
|
+
res.writeHead(200, {
|
|
571
|
+
'Content-Type': 'text/event-stream; charset=utf-8',
|
|
572
|
+
'Cache-Control': 'no-cache',
|
|
573
|
+
'Connection': 'keep-alive',
|
|
574
|
+
'X-Accel-Buffering': 'no',
|
|
575
|
+
'x-vercel-ai-ui-message-stream': 'v1',
|
|
576
|
+
});
|
|
577
|
+
addClient(chatJid, res);
|
|
578
|
+
clientRegistered = true;
|
|
579
|
+
req.on('close', cleanup);
|
|
580
|
+
res.on('close', cleanup);
|
|
581
|
+
res.flushHeaders?.();
|
|
582
|
+
res.write(': ping\n\n');
|
|
583
|
+
res.flush?.();
|
|
584
|
+
captureWebUserMessage({
|
|
585
|
+
threadId: sessionId,
|
|
586
|
+
runtimeThreadId: sessionId,
|
|
587
|
+
userMessage,
|
|
588
|
+
});
|
|
589
|
+
onMessage(chatJid, userMessage);
|
|
590
|
+
recordSessionControlCommand({
|
|
591
|
+
agentId,
|
|
592
|
+
sessionId,
|
|
593
|
+
turnId: taskId,
|
|
594
|
+
surface: 'web',
|
|
595
|
+
commandType: 'session.instruct',
|
|
596
|
+
method: 'turn/start',
|
|
597
|
+
actor: senderIdentity.sender,
|
|
598
|
+
status: 'dispatched',
|
|
599
|
+
payload: {
|
|
600
|
+
endpoint: 'chat',
|
|
601
|
+
message_excerpt: (displayUserText || rawUserText || '').slice(0, 240),
|
|
602
|
+
model,
|
|
603
|
+
runtime_options: runtimeOptions,
|
|
604
|
+
},
|
|
605
|
+
});
|
|
606
|
+
let completed = false;
|
|
607
|
+
let completedWithError = false;
|
|
608
|
+
while (Date.now() < waitUntil) {
|
|
609
|
+
const events = getSessionUiEvents(agentId, sessionId, 80);
|
|
610
|
+
completed = events.some((evt) => {
|
|
611
|
+
return (evt.task_id === taskId &&
|
|
612
|
+
evt.chunk &&
|
|
613
|
+
evt.chunk?.type === 'stream-dispatched');
|
|
614
|
+
});
|
|
615
|
+
completedWithError = events.some((evt) => {
|
|
616
|
+
return (evt.task_id === taskId &&
|
|
617
|
+
evt.chunk &&
|
|
618
|
+
evt.chunk?.type === 'error');
|
|
619
|
+
});
|
|
620
|
+
if (completed || completedWithError)
|
|
621
|
+
break;
|
|
622
|
+
await new Promise((resolve) => setTimeout(resolve, waitMs));
|
|
623
|
+
}
|
|
624
|
+
const finalEvents = getSessionUiEvents(agentId, sessionId, 80);
|
|
625
|
+
const timedOut = !completed && !completedWithError;
|
|
626
|
+
const endedWithError = finalEvents.some((evt) => {
|
|
627
|
+
return (evt.task_id === taskId &&
|
|
628
|
+
evt.chunk &&
|
|
629
|
+
evt.chunk?.type === 'error');
|
|
630
|
+
});
|
|
631
|
+
if (timedOut && !completed && !completedWithError) {
|
|
632
|
+
res.write(`data: ${JSON.stringify({ type: 'error', errorText: 'Message stream timed out' })}\n\n`);
|
|
633
|
+
}
|
|
634
|
+
else if (endedWithError || completedWithError) {
|
|
635
|
+
const payload = JSON.stringify({
|
|
636
|
+
type: 'error',
|
|
637
|
+
errorText: 'Message stream ended with error',
|
|
638
|
+
});
|
|
639
|
+
res.write(`data: ${payload}\n\n`);
|
|
640
|
+
}
|
|
641
|
+
else if (rawLastUserMsg?.role === 'user' && userContentForTitle) {
|
|
642
|
+
await ensureThreadTitleFromBackend(agentId, sessionId);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
catch (err) {
|
|
646
|
+
logger.error({ err, agentId, sessionId }, 'Chat stream failed');
|
|
647
|
+
if (res.headersSent) {
|
|
648
|
+
const payload = JSON.stringify({
|
|
649
|
+
type: 'error',
|
|
650
|
+
errorText: err?.message || 'Chat stream failed',
|
|
651
|
+
});
|
|
652
|
+
res.write(`data: ${payload}\n\n`);
|
|
653
|
+
}
|
|
654
|
+
else {
|
|
655
|
+
writeProtocolError(res, 500, 'internal_error', 'cortex_error', err.message);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
finally {
|
|
659
|
+
cleanup();
|
|
660
|
+
res.end();
|
|
661
|
+
}
|
|
662
|
+
return true;
|
|
663
|
+
}
|
|
664
|
+
// ── List Sessions ──
|
|
665
|
+
const listSessionsMatch = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/sessions$/);
|
|
666
|
+
if (listSessionsMatch && method === 'POST') {
|
|
667
|
+
const agentId = decodeURIComponent(listSessionsMatch[1]);
|
|
668
|
+
const parsed = await readJsonBody(req);
|
|
669
|
+
const requestedSessionId = typeof parsed?.task_id === 'string'
|
|
670
|
+
? parsed.task_id.trim()
|
|
671
|
+
: typeof parsed?.session_id === 'string'
|
|
672
|
+
? parsed.session_id.trim()
|
|
673
|
+
: '';
|
|
674
|
+
const requestedTitle = typeof parsed?.title === 'string' ? parsed.title.trim() : '';
|
|
675
|
+
const requestedKnowledgeId = typeof parsed?.knowledge_id === 'string' ? parsed.knowledge_id.trim() : '';
|
|
676
|
+
const requestedKnowledgeName = typeof parsed?.knowledge_name === 'string' ? parsed.knowledge_name.trim() : '';
|
|
677
|
+
if (requestedSessionId && getSessionForAgent(agentId, requestedSessionId)) {
|
|
678
|
+
writeProtocolError(res, 409, 'input_error', 'session_exists', `Task "${requestedSessionId}" already exists for agent "${agentId}"`);
|
|
679
|
+
return true;
|
|
680
|
+
}
|
|
681
|
+
let sessionId = requestedSessionId;
|
|
682
|
+
if (!sessionId) {
|
|
683
|
+
do {
|
|
684
|
+
sessionId = `session-${Date.now().toString(36)}-${randomUUID().slice(0, 8)}`;
|
|
685
|
+
} while (getSessionForAgent(agentId, sessionId));
|
|
686
|
+
}
|
|
687
|
+
const session = ensureSession({
|
|
688
|
+
agent_id: agentId,
|
|
689
|
+
session_id: sessionId,
|
|
690
|
+
channel: 'http',
|
|
691
|
+
agent_name: agentId,
|
|
692
|
+
source_ref: buildHttpSessionId(agentId, sessionId),
|
|
693
|
+
knowledge_id: requestedKnowledgeId || undefined,
|
|
694
|
+
knowledge_name: requestedKnowledgeName || undefined,
|
|
695
|
+
title: requestedTitle || undefined,
|
|
696
|
+
});
|
|
697
|
+
recordSessionControlCommand({
|
|
698
|
+
agentId,
|
|
699
|
+
sessionId,
|
|
700
|
+
surface: 'web',
|
|
701
|
+
commandType: 'session.start',
|
|
702
|
+
method: 'thread/start',
|
|
703
|
+
actor: adminContext?.actor || 'http',
|
|
704
|
+
status: 'completed',
|
|
705
|
+
payload: {
|
|
706
|
+
requested_task_id: requestedSessionId || null,
|
|
707
|
+
title: requestedTitle || null,
|
|
708
|
+
knowledge_id: requestedKnowledgeId || null,
|
|
709
|
+
knowledge_name: requestedKnowledgeName || null,
|
|
710
|
+
},
|
|
711
|
+
});
|
|
712
|
+
const refreshedSession = getSessionForAgent(agentId, sessionId) || session;
|
|
713
|
+
prewarmSessionInBackground(agentId, sessionId);
|
|
714
|
+
writeJson(res, 200, { session: serializeTask(refreshedSession) });
|
|
715
|
+
return true;
|
|
716
|
+
}
|
|
717
|
+
if (listSessionsMatch && method === 'GET') {
|
|
718
|
+
const agentId = decodeURIComponent(listSessionsMatch[1]);
|
|
719
|
+
const sessions = getSessionsForAgent(agentId).map(serializeTask);
|
|
720
|
+
writeJson(res, 200, { sessions });
|
|
721
|
+
return true;
|
|
722
|
+
}
|
|
723
|
+
const archivedSessionsMatch = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/archived_sessions$/);
|
|
724
|
+
if (archivedSessionsMatch && method === 'GET') {
|
|
725
|
+
const agentId = decodeURIComponent(archivedSessionsMatch[1]);
|
|
726
|
+
const sessions = getArchivedSessionsForAgent(agentId).map(serializeTask);
|
|
727
|
+
writeJson(res, 200, { sessions });
|
|
728
|
+
return true;
|
|
729
|
+
}
|
|
730
|
+
const refreshTitlesMatch = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/threads\/refresh-titles$/);
|
|
731
|
+
if (refreshTitlesMatch && method === 'POST') {
|
|
732
|
+
const agentId = decodeURIComponent(refreshTitlesMatch[1]);
|
|
733
|
+
const parsed = await readJsonBody(req).catch(() => ({}));
|
|
734
|
+
const force = parsed?.force === true;
|
|
735
|
+
const sessions = getSessionsForAgent(agentId);
|
|
736
|
+
const results = sessions.map((session) => {
|
|
737
|
+
const result = refreshThreadTitleFromCodexIndex(agentId, session.session_id, { force });
|
|
738
|
+
return {
|
|
739
|
+
thread_id: session.session_id,
|
|
740
|
+
updated: result.updated,
|
|
741
|
+
title: result.title,
|
|
742
|
+
previous_title: result.previousTitle,
|
|
743
|
+
reason: result.reason || null,
|
|
744
|
+
};
|
|
745
|
+
});
|
|
746
|
+
writeJson(res, 200, {
|
|
747
|
+
ok: true,
|
|
748
|
+
force,
|
|
749
|
+
total: results.length,
|
|
750
|
+
updated: results.filter((result) => result.updated).length,
|
|
751
|
+
results,
|
|
752
|
+
});
|
|
753
|
+
return true;
|
|
754
|
+
}
|
|
755
|
+
const refreshTitleMatch = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/threads\/([^/]+)\/refresh-title$/);
|
|
756
|
+
if (refreshTitleMatch && method === 'POST') {
|
|
757
|
+
const agentId = decodeURIComponent(refreshTitleMatch[1]);
|
|
758
|
+
const threadId = decodeURIComponent(refreshTitleMatch[2]);
|
|
759
|
+
const parsed = await readJsonBody(req).catch(() => ({}));
|
|
760
|
+
const result = refreshThreadTitleFromCodexIndex(agentId, threadId, {
|
|
761
|
+
force: parsed?.force === true,
|
|
762
|
+
});
|
|
763
|
+
if (result.reason === 'thread_not_found') {
|
|
764
|
+
writeProtocolError(res, 404, 'input_error', 'thread_not_found', `Thread "${threadId}" was not found for agent "${agentId}"`);
|
|
765
|
+
return true;
|
|
766
|
+
}
|
|
767
|
+
writeJson(res, 200, {
|
|
768
|
+
ok: true,
|
|
769
|
+
thread_id: threadId,
|
|
770
|
+
updated: result.updated,
|
|
771
|
+
title: result.title,
|
|
772
|
+
previous_title: result.previousTitle,
|
|
773
|
+
reason: result.reason || null,
|
|
774
|
+
});
|
|
775
|
+
return true;
|
|
776
|
+
}
|
|
777
|
+
const sessionLifecycleMatch = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/sessions\/([^/]+)$/);
|
|
778
|
+
if (sessionLifecycleMatch && method === 'PATCH') {
|
|
779
|
+
const agentId = decodeURIComponent(sessionLifecycleMatch[1]);
|
|
780
|
+
const sessionId = decodeURIComponent(sessionLifecycleMatch[2]);
|
|
781
|
+
const parsed = await readJsonBody(req);
|
|
782
|
+
if (parsed?.archived === true) {
|
|
783
|
+
const archived = archiveSessionForAgent(agentId, sessionId);
|
|
784
|
+
if (!archived) {
|
|
785
|
+
writeProtocolError(res, 404, 'input_error', 'session_not_found', `Task "${sessionId}" was not found for agent "${agentId}"`);
|
|
786
|
+
return true;
|
|
787
|
+
}
|
|
788
|
+
writeJson(res, 200, { ok: true, archived: true });
|
|
789
|
+
return true;
|
|
790
|
+
}
|
|
791
|
+
if (parsed?.archived === false) {
|
|
792
|
+
const restored = restoreSessionForAgent(agentId, sessionId);
|
|
793
|
+
if (!restored) {
|
|
794
|
+
writeProtocolError(res, 404, 'input_error', 'session_not_found', `Archived task "${sessionId}" was not found for agent "${agentId}"`);
|
|
795
|
+
return true;
|
|
796
|
+
}
|
|
797
|
+
writeJson(res, 200, {
|
|
798
|
+
ok: true,
|
|
799
|
+
archived: false,
|
|
800
|
+
session: serializeTask(getSessionForAgent(agentId, sessionId)),
|
|
801
|
+
});
|
|
802
|
+
return true;
|
|
803
|
+
}
|
|
804
|
+
if (typeof parsed?.title === 'string') {
|
|
805
|
+
const updated = updateSessionMetadata(agentId, sessionId, {
|
|
806
|
+
title: parsed.title.trim() || undefined,
|
|
807
|
+
});
|
|
808
|
+
if (!updated) {
|
|
809
|
+
writeProtocolError(res, 404, 'input_error', 'session_not_found', `Task "${sessionId}" was not found for agent "${agentId}"`);
|
|
810
|
+
return true;
|
|
811
|
+
}
|
|
812
|
+
const session = getSessionForAgent(agentId, sessionId);
|
|
813
|
+
writeJson(res, 200, { ok: true, session: session ? serializeTask(session) : null });
|
|
814
|
+
return true;
|
|
815
|
+
}
|
|
816
|
+
writeProtocolError(res, 400, 'input_error', 'invalid_session_update', 'Expected archived or title in request body.');
|
|
817
|
+
return true;
|
|
818
|
+
}
|
|
819
|
+
if (sessionLifecycleMatch && method === 'DELETE') {
|
|
820
|
+
const agentId = decodeURIComponent(sessionLifecycleMatch[1]);
|
|
821
|
+
const sessionId = decodeURIComponent(sessionLifecycleMatch[2]);
|
|
822
|
+
const deleted = deleteSessionForAgent(agentId, sessionId) ||
|
|
823
|
+
deleteSessionForAgent(agentId, sessionId, true);
|
|
824
|
+
if (!deleted) {
|
|
825
|
+
writeProtocolError(res, 404, 'input_error', 'session_not_found', `Task "${sessionId}" was not found for agent "${agentId}"`);
|
|
826
|
+
return true;
|
|
827
|
+
}
|
|
828
|
+
writeJson(res, 200, { ok: true });
|
|
829
|
+
return true;
|
|
830
|
+
}
|
|
831
|
+
const runtimeStateMatch = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/sessions\/([^/]+)\/runtime-state$/);
|
|
832
|
+
if (runtimeStateMatch && method === 'GET') {
|
|
833
|
+
const agentId = decodeURIComponent(runtimeStateMatch[1]);
|
|
834
|
+
const sessionId = decodeURIComponent(runtimeStateMatch[2]);
|
|
835
|
+
const session = getSessionForAgent(agentId, sessionId);
|
|
836
|
+
if (!session) {
|
|
837
|
+
writeProtocolError(res, 404, 'input_error', 'session_not_found', `Session "${sessionId}" was not found for agent "${agentId}"`);
|
|
838
|
+
return true;
|
|
839
|
+
}
|
|
840
|
+
const projection = projectThreadRuntimeState(sessionId);
|
|
841
|
+
writeJson(res, 200, {
|
|
842
|
+
session,
|
|
843
|
+
runtimeState: runtimeStateSummary(projection),
|
|
844
|
+
projection,
|
|
845
|
+
});
|
|
846
|
+
return true;
|
|
847
|
+
}
|
|
848
|
+
const sessionMessagesMatch = pathname.match(/^\/api\/computer\/agents\/([^/]+)\/sessions\/([^/]+)\/messages$/);
|
|
849
|
+
if (sessionMessagesMatch && method === 'GET') {
|
|
850
|
+
const agentId = decodeURIComponent(sessionMessagesMatch[1]);
|
|
851
|
+
const sessionId = decodeURIComponent(sessionMessagesMatch[2]);
|
|
852
|
+
const session = getSessionForAgent(agentId, sessionId);
|
|
853
|
+
if (!session) {
|
|
854
|
+
writeProtocolError(res, 404, 'input_error', 'session_not_found', `Task "${sessionId}" was not found for agent "${agentId}"`);
|
|
855
|
+
return true;
|
|
856
|
+
}
|
|
857
|
+
const limit = Math.max(1, parseInt(url.searchParams.get('limit') || '100', 10) || 100);
|
|
858
|
+
const interactionEvents = getSessionInteractionEvents(agentId, sessionId, limit);
|
|
859
|
+
const controlLog = listControlLogEntries(sessionId, limit);
|
|
860
|
+
const runtimeState = runtimeStateForThread(sessionId);
|
|
861
|
+
const responseMessages = runtimeState.messages.slice(-limit);
|
|
862
|
+
const responseEvents = runtimeState.events.slice(-limit);
|
|
863
|
+
writeJson(res, 200, {
|
|
864
|
+
session,
|
|
865
|
+
messages: responseMessages,
|
|
866
|
+
events: responseEvents,
|
|
867
|
+
interaction_events: interactionEvents,
|
|
868
|
+
control_log: controlLog,
|
|
869
|
+
runtimeState: runtimeStateSummary(runtimeState),
|
|
870
|
+
});
|
|
871
|
+
return true;
|
|
872
|
+
}
|
|
873
|
+
if (sessionMessagesMatch && method === 'POST') {
|
|
874
|
+
const agentId = decodeURIComponent(sessionMessagesMatch[1]);
|
|
875
|
+
const sessionId = decodeURIComponent(sessionMessagesMatch[2]);
|
|
876
|
+
const session = getSessionForAgent(agentId, sessionId);
|
|
877
|
+
if (!session) {
|
|
878
|
+
writeProtocolError(res, 404, 'input_error', 'session_not_found', `Task "${sessionId}" was not found for agent "${agentId}"`);
|
|
879
|
+
return true;
|
|
880
|
+
}
|
|
881
|
+
const parsed = await readJsonBody(req);
|
|
882
|
+
const userText = typeof parsed?.user_text === 'string' ? parsed.user_text : '';
|
|
883
|
+
const assistantText = typeof parsed?.assistant_text === 'string' ? parsed.assistant_text : '';
|
|
884
|
+
if (!userText.trim() || !assistantText.trim()) {
|
|
885
|
+
writeProtocolError(res, 400, 'input_error', 'content_required', 'user_text and assistant_text are required non-empty strings');
|
|
886
|
+
return true;
|
|
887
|
+
}
|
|
888
|
+
const chatJid = buildHttpSessionId(agentId, sessionId);
|
|
889
|
+
const senderIdentity = deriveHttpSenderIdentity(adminContext);
|
|
890
|
+
const pairId = randomUUID();
|
|
891
|
+
recordSessionControlCommand({
|
|
892
|
+
agentId,
|
|
893
|
+
sessionId,
|
|
894
|
+
turnId: pairId,
|
|
895
|
+
surface: 'web',
|
|
896
|
+
commandType: 'session.instruct',
|
|
897
|
+
method: 'turn/start',
|
|
898
|
+
actor: senderIdentity.sender,
|
|
899
|
+
status: 'completed',
|
|
900
|
+
payload: {
|
|
901
|
+
endpoint: 'messages',
|
|
902
|
+
source: 'http-slash-command',
|
|
903
|
+
message_excerpt: userText.slice(0, 240),
|
|
904
|
+
},
|
|
905
|
+
});
|
|
906
|
+
const userTs = new Date().toISOString();
|
|
907
|
+
const assistantTs = new Date(Date.now() + 1).toISOString();
|
|
908
|
+
storeMessage({
|
|
909
|
+
id: `http-slash-${pairId}-user`,
|
|
910
|
+
chat_jid: chatJid,
|
|
911
|
+
agent_id: agentId,
|
|
912
|
+
session_id: sessionId,
|
|
913
|
+
sender: senderIdentity.sender,
|
|
914
|
+
sender_name: senderIdentity.sender_name,
|
|
915
|
+
content: userText,
|
|
916
|
+
timestamp: userTs,
|
|
917
|
+
is_from_me: false,
|
|
918
|
+
is_bot_message: false,
|
|
919
|
+
metadata: { source: 'http-slash-command' },
|
|
920
|
+
});
|
|
921
|
+
storeMessage({
|
|
922
|
+
id: `http-slash-${pairId}-assistant`,
|
|
923
|
+
chat_jid: chatJid,
|
|
924
|
+
agent_id: agentId,
|
|
925
|
+
session_id: sessionId,
|
|
926
|
+
sender: ASSISTANT_NAME,
|
|
927
|
+
sender_name: ASSISTANT_NAME,
|
|
928
|
+
content: assistantText,
|
|
929
|
+
timestamp: assistantTs,
|
|
930
|
+
is_from_me: true,
|
|
931
|
+
is_bot_message: true,
|
|
932
|
+
metadata: { source: 'http-slash-command' },
|
|
933
|
+
});
|
|
934
|
+
await ensureThreadTitleFromBackend(agentId, sessionId);
|
|
935
|
+
writeJson(res, 200, { ok: true });
|
|
936
|
+
return true;
|
|
937
|
+
}
|
|
938
|
+
return false;
|
|
939
|
+
}
|
|
940
|
+
async function ensureThreadTitleFromBackend(agentId, threadId) {
|
|
941
|
+
const existingTitle = getSessionForAgent(agentId, threadId)?.title?.trim();
|
|
942
|
+
if (existingTitle)
|
|
943
|
+
return;
|
|
944
|
+
let title = readCodexTitleForThread(threadId);
|
|
945
|
+
if (!title) {
|
|
946
|
+
for (const waitMs of [250, 750, 1500]) {
|
|
947
|
+
await new Promise((resolve) => setTimeout(resolve, waitMs));
|
|
948
|
+
title = readCodexTitleForThread(threadId);
|
|
949
|
+
if (title)
|
|
950
|
+
break;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
if (!title)
|
|
954
|
+
return;
|
|
955
|
+
if (existingTitle === title)
|
|
956
|
+
return;
|
|
957
|
+
updateSessionMetadata(agentId, threadId, { title });
|
|
958
|
+
broadcastToChat(buildHttpSessionId(agentId, threadId), {
|
|
959
|
+
type: 'session_updated',
|
|
960
|
+
session: { task_id: threadId, title },
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
//# sourceMappingURL=sessions.js.map
|