@ours.network/fleet 1.2.0-nightly.8 → 1.2.0-nightly.80
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 +279 -68
- package/dist/account-origin.d.ts +5 -0
- package/dist/account-origin.js +31 -0
- package/dist/agent-ours/bridge.js +26 -9
- package/dist/agent-ours/correspondence.d.ts +10 -0
- package/dist/agent-ours/correspondence.js +1 -0
- package/dist/agent-ours/file-rpc.d.ts +12 -0
- package/dist/agent-ours/file-rpc.js +18 -4
- package/dist/agent-ours/harness.js +9 -1
- package/dist/agent-ours/mcp-endpoint.d.ts +19 -0
- package/dist/agent-ours/mcp-endpoint.js +98 -25
- package/dist/agent-ours/runtime.d.ts +9 -1
- package/dist/agent-ours/runtime.js +50 -2
- package/dist/agent-ours/service.d.ts +24 -1
- package/dist/agent-ours/service.js +97 -13
- package/dist/application/codex-models.d.ts +15 -0
- package/dist/application/codex-models.js +56 -0
- package/dist/application/conversation-history.d.ts +34 -0
- package/dist/application/conversation-history.js +294 -0
- package/dist/application/conversation-role-observer.d.ts +62 -0
- package/dist/application/conversation-role-observer.js +206 -0
- package/dist/application/fleet-query-service.d.ts +1 -1
- package/dist/application/fleet-query-service.js +3 -3
- package/dist/application/log-service.js +8 -8
- package/dist/application/model-catalog.d.ts +1 -1
- package/dist/application/model-catalog.js +5 -2
- package/dist/application/preset-provenance.d.ts +19 -0
- package/dist/application/preset-provenance.js +59 -0
- package/dist/application/resource-observer.d.ts +43 -0
- package/dist/application/resource-observer.js +323 -0
- package/dist/application/role-creation-service.js +3 -2
- package/dist/application/role-removal-service.js +17 -3
- package/dist/application/role-repository.d.ts +1 -1
- package/dist/application/role-repository.js +30 -7
- package/dist/application/room-layout-definitions.d.ts +45 -0
- package/dist/application/room-layout-definitions.js +130 -0
- package/dist/application/session-control.d.ts +63 -17
- package/dist/application/session-control.js +221 -23
- package/dist/application/supervisor-ours-tools.js +5 -11
- package/dist/application/task-layouts.d.ts +91 -0
- package/dist/application/task-layouts.js +261 -0
- package/dist/application/task-room-service.d.ts +101 -3
- package/dist/application/task-room-service.js +286 -33
- package/dist/application/types.d.ts +2 -0
- package/dist/atomic-file.d.ts +34 -1
- package/dist/atomic-file.js +161 -18
- package/dist/briefing.d.ts +3 -1
- package/dist/briefing.js +97 -31
- package/dist/build-info.json +9 -4
- package/dist/capabilities.d.ts +9 -1
- package/dist/capabilities.js +13 -0
- package/dist/cli.js +400 -37
- package/dist/client-profile.d.ts +5 -17
- package/dist/client-profile.js +4 -127
- package/dist/config.d.ts +45 -0
- package/dist/config.js +57 -6
- package/dist/creation.d.ts +1 -1
- package/dist/creation.js +4 -4
- package/dist/daemon-recovery.d.ts +14 -9
- package/dist/daemon-recovery.js +124 -115
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +207 -19
- package/dist/doctor.d.ts +4 -1
- package/dist/doctor.js +75 -60
- package/dist/erased-resources.d.ts +9 -0
- package/dist/erased-resources.js +87 -0
- package/dist/file-delivery/reader.d.ts +15 -0
- package/dist/file-delivery/reader.js +63 -0
- package/dist/file-delivery/store.d.ts +15 -0
- package/dist/file-delivery/store.js +124 -0
- package/dist/file-delivery/types.d.ts +19 -0
- package/dist/file-delivery/types.js +1 -0
- package/dist/fleet-command-audit.d.ts +7 -0
- package/dist/fleet-command-audit.js +24 -8
- package/dist/harness/agent-session.d.ts +4 -0
- package/dist/harness/claude-code-session.js +1 -1
- package/dist/harness/claude-code.js +21 -11
- package/dist/harness/claude-runtime.d.ts +12 -0
- package/dist/harness/claude-runtime.js +43 -0
- package/dist/harness/codex-app-server-proxy.d.ts +4 -1
- package/dist/harness/codex-app-server-proxy.js +41 -5
- package/dist/harness/codex-reasoning.d.ts +5 -0
- package/dist/harness/codex-reasoning.js +12 -0
- package/dist/harness/codex-runtime.d.ts +11 -1
- package/dist/harness/codex-runtime.js +31 -4
- package/dist/harness/codex-session.js +2 -2
- package/dist/harness/codex.js +24 -12
- package/dist/init-wizard.d.ts +2 -0
- package/dist/init-wizard.js +38 -19
- package/dist/isolation/policy.js +6 -1
- package/dist/isolation/types.d.ts +5 -0
- package/dist/managed-cli.d.ts +253 -0
- package/dist/managed-cli.js +923 -0
- package/dist/managed-recovery.d.ts +13 -0
- package/dist/managed-recovery.js +31 -0
- package/dist/minimal-setup.d.ts +2 -0
- package/dist/minimal-setup.js +44 -0
- package/dist/monitor.d.ts +9 -34
- package/dist/monitor.js +90 -153
- package/dist/notifications/fleet-producer.d.ts +31 -0
- package/dist/notifications/fleet-producer.js +351 -0
- package/dist/notifications/outbox.d.ts +59 -0
- package/dist/notifications/outbox.js +199 -0
- package/dist/notifications/target-cleanup.d.ts +16 -0
- package/dist/notifications/target-cleanup.js +75 -0
- package/dist/notifications/task-producer.d.ts +20 -0
- package/dist/notifications/task-producer.js +100 -0
- package/dist/ops.d.ts +2 -0
- package/dist/ops.js +20 -3
- package/dist/owner-channel/channel.js +17 -6
- package/dist/owner-channel/commands.d.ts +4 -0
- package/dist/owner-channel/commands.js +8 -0
- package/dist/owner-channel/lifecycle-outbox.js +4 -3
- package/dist/owner-channel/ours-client.js +2 -17
- package/dist/paths.d.ts +5 -0
- package/dist/paths.js +5 -0
- package/dist/preset-migration.js +43 -0
- package/dist/process-incarnation.d.ts +23 -0
- package/dist/process-incarnation.js +42 -0
- package/dist/reminders/manager.d.ts +75 -0
- package/dist/reminders/manager.js +278 -0
- package/dist/reminders/runtime.d.ts +27 -0
- package/dist/reminders/runtime.js +32 -0
- package/dist/reminders/schedule.d.ts +37 -0
- package/dist/reminders/schedule.js +104 -0
- package/dist/reminders/store.d.ts +341 -0
- package/dist/reminders/store.js +762 -0
- package/dist/reminders/tools.d.ts +20 -0
- package/dist/reminders/tools.js +114 -0
- package/dist/resolved-plan.js +1 -0
- package/dist/rooms-tasks/add-member.d.ts +48 -0
- package/dist/rooms-tasks/add-member.js +84 -0
- package/dist/rooms-tasks/archived-absence.d.ts +4 -0
- package/dist/rooms-tasks/archived-absence.js +11 -0
- package/dist/rooms-tasks/cli.js +65 -5
- package/dist/rooms-tasks/close.d.ts +5 -2
- package/dist/rooms-tasks/close.js +224 -36
- package/dist/rooms-tasks/config.d.ts +1 -1
- package/dist/rooms-tasks/config.js +11 -4
- package/dist/rooms-tasks/cowork-adapter.d.ts +12 -5
- package/dist/rooms-tasks/cowork-adapter.js +15 -121
- package/dist/rooms-tasks/cowork-http.js +56 -6
- package/dist/rooms-tasks/deletion.d.ts +1 -1
- package/dist/rooms-tasks/deletion.js +63 -10
- package/dist/rooms-tasks/erasure.d.ts +6 -0
- package/dist/rooms-tasks/erasure.js +173 -0
- package/dist/rooms-tasks/external-worker.d.ts +1 -1
- package/dist/rooms-tasks/external-worker.js +3 -4
- package/dist/rooms-tasks/layout-binding-client.d.ts +11 -0
- package/dist/rooms-tasks/layout-binding-client.js +56 -0
- package/dist/rooms-tasks/layout-binding-grants.d.ts +21 -0
- package/dist/rooms-tasks/layout-binding-grants.js +128 -0
- package/dist/rooms-tasks/layout-cli.d.ts +4 -0
- package/dist/rooms-tasks/layout-cli.js +107 -0
- package/dist/rooms-tasks/layout-config.d.ts +11 -0
- package/dist/rooms-tasks/layout-config.js +89 -0
- package/dist/rooms-tasks/layout-control.d.ts +21 -0
- package/dist/rooms-tasks/layout-control.js +52 -0
- package/dist/rooms-tasks/layout-member-retirement.d.ts +10 -0
- package/dist/rooms-tasks/layout-member-retirement.js +90 -0
- package/dist/rooms-tasks/layout-service.d.ts +43 -0
- package/dist/rooms-tasks/layout-service.js +203 -0
- package/dist/rooms-tasks/layout.d.ts +121 -0
- package/dist/rooms-tasks/layout.js +286 -0
- package/dist/rooms-tasks/legacy-task-member.d.ts +19 -0
- package/dist/rooms-tasks/legacy-task-member.js +116 -0
- package/dist/rooms-tasks/live-readiness.d.ts +18 -0
- package/dist/rooms-tasks/live-readiness.js +85 -0
- package/dist/rooms-tasks/member-ownership.d.ts +5 -0
- package/dist/rooms-tasks/member-ownership.js +40 -0
- package/dist/rooms-tasks/member-startup.d.ts +1 -0
- package/dist/rooms-tasks/member-startup.js +2 -0
- package/dist/rooms-tasks/provision.d.ts +3 -0
- package/dist/rooms-tasks/provision.js +101 -49
- package/dist/rooms-tasks/recovery.d.ts +19 -0
- package/dist/rooms-tasks/recovery.js +110 -0
- package/dist/rooms-tasks/room-state.d.ts +4 -2
- package/dist/rooms-tasks/room-state.js +47 -8
- package/dist/rooms-tasks/task-service-retirement.d.ts +11 -0
- package/dist/rooms-tasks/task-service-retirement.js +21 -0
- package/dist/rooms-tasks/task-state.d.ts +43 -5
- package/dist/rooms-tasks/task-state.js +244 -22
- package/dist/rooms-tasks/types.d.ts +35 -0
- package/dist/rooms-tasks/workspace-artifacts.d.ts +6 -0
- package/dist/rooms-tasks/workspace-artifacts.js +93 -0
- package/dist/rooms-tasks/workspace.d.ts +35 -0
- package/dist/rooms-tasks/workspace.js +325 -0
- package/dist/runner.d.ts +33 -4
- package/dist/runner.js +410 -62
- package/dist/session/acp.d.ts +75 -2
- package/dist/session/acp.js +345 -82
- package/dist/session/arbiter.d.ts +98 -0
- package/dist/session/arbiter.js +272 -3
- package/dist/session/codex-app-server.d.ts +45 -1
- package/dist/session/codex-app-server.js +225 -32
- package/dist/session/control.d.ts +17 -3
- package/dist/session/control.js +219 -23
- package/dist/session/conversation-normalizer.d.ts +2 -1
- package/dist/session/conversation-normalizer.js +1 -1
- package/dist/session/conversation-observation.d.ts +25 -0
- package/dist/session/conversation-observation.js +100 -0
- package/dist/session/conversation-replay.d.ts +50 -0
- package/dist/session/conversation-replay.js +203 -0
- package/dist/session/conversation-store.d.ts +15 -1
- package/dist/session/conversation-store.js +213 -26
- package/dist/session/conversation-types.d.ts +57 -4
- package/dist/session/prompt-batch.d.ts +79 -0
- package/dist/session/prompt-batch.js +120 -0
- package/dist/session/task-notice.d.ts +14 -0
- package/dist/session/task-notice.js +13 -0
- package/dist/session/types.d.ts +42 -1
- package/dist/setup-tunnel-preflight.d.ts +34 -0
- package/dist/setup-tunnel-preflight.js +62 -0
- package/dist/socket-path.d.ts +2 -0
- package/dist/socket-path.js +22 -0
- package/dist/spawn.d.ts +5 -1
- package/dist/spawn.js +40 -4
- package/dist/startup-prompt.d.ts +15 -0
- package/dist/startup-prompt.js +71 -0
- package/dist/startup-readiness.d.ts +32 -0
- package/dist/startup-readiness.js +101 -0
- package/dist/startup-telemetry.d.ts +16 -0
- package/dist/startup-telemetry.js +46 -0
- package/dist/subscriptions/cli.d.ts +91 -0
- package/dist/subscriptions/cli.js +223 -0
- package/dist/subscriptions/launch.d.ts +37 -0
- package/dist/subscriptions/launch.js +93 -0
- package/dist/subscriptions/login.d.ts +77 -0
- package/dist/subscriptions/login.js +215 -0
- package/dist/subscriptions/observed.d.ts +7 -0
- package/dist/subscriptions/observed.js +44 -0
- package/dist/subscriptions/probe.d.ts +10 -0
- package/dist/subscriptions/probe.js +73 -0
- package/dist/subscriptions/service.d.ts +102 -0
- package/dist/subscriptions/service.js +364 -0
- package/dist/subscriptions/store.d.ts +71 -0
- package/dist/subscriptions/store.js +143 -0
- package/dist/supervisor/adoption.d.ts +8 -0
- package/dist/supervisor/adoption.js +78 -0
- package/dist/supervisor/catalog.d.ts +62 -0
- package/dist/supervisor/catalog.js +254 -0
- package/dist/supervisor/fleet.d.ts +8 -0
- package/dist/supervisor/fleet.js +89 -0
- package/dist/supervisor/index.js +3 -6
- package/dist/supervisor/launchd.d.ts +1 -1
- package/dist/supervisor/launchd.js +26 -13
- package/dist/supervisor/legacy.d.ts +35 -0
- package/dist/supervisor/legacy.js +524 -0
- package/dist/supervisor/manager.d.ts +15 -0
- package/dist/supervisor/manager.js +270 -0
- package/dist/supervisor/registration-refresh.d.ts +45 -0
- package/dist/supervisor/registration-refresh.js +266 -0
- package/dist/supervisor/scope.d.ts +4 -0
- package/dist/supervisor/scope.js +10 -0
- package/dist/supervisor/systemd.d.ts +2 -2
- package/dist/supervisor/systemd.js +19 -33
- package/dist/task-supervision.d.ts +9 -0
- package/dist/task-supervision.js +145 -0
- package/dist/temp-idle.d.ts +17 -0
- package/dist/temp-idle.js +42 -0
- package/dist/temp-lifecycle.d.ts +23 -8
- package/dist/temp-lifecycle.js +123 -66
- package/dist/temp-supervisor-recovery.d.ts +1 -1
- package/dist/temp-supervisor-recovery.js +2 -2
- package/dist/tunnel-setup-completion.d.ts +7 -0
- package/dist/tunnel-setup-completion.js +13 -0
- package/dist/tunnel-setup-input.d.ts +19 -0
- package/dist/tunnel-setup-input.js +130 -0
- package/dist/watchdog/query.d.ts +3 -1
- package/dist/watchdog/query.js +2 -1
- package/dist/web/agent-attachments.d.ts +29 -0
- package/dist/web/agent-attachments.js +162 -0
- package/dist/web/auth.d.ts +65 -2
- package/dist/web/auth.js +201 -11
- package/dist/web/available-port.d.ts +2 -0
- package/dist/web/available-port.js +23 -0
- package/dist/web/control.d.ts +3 -3
- package/dist/web/control.js +10 -8
- package/dist/web/conversation-stream-codec.d.ts +23 -0
- package/dist/web/conversation-stream-codec.js +110 -0
- package/dist/web/conversation-stream.d.ts +26 -0
- package/dist/web/conversation-stream.js +239 -0
- package/dist/web/events.d.ts +2 -0
- package/dist/web/events.js +9 -0
- package/dist/web/fleet-config-service.d.ts +7 -1
- package/dist/web/fleet-config-service.js +61 -16
- package/dist/web/prefix-gateway.d.ts +32 -0
- package/dist/web/prefix-gateway.js +248 -0
- package/dist/web/resource-views.d.ts +135 -0
- package/dist/web/resource-views.js +486 -0
- package/dist/web/runtime.d.ts +3 -1
- package/dist/web/runtime.js +132 -34
- package/dist/web/server.d.ts +19 -0
- package/dist/web/server.js +821 -68
- package/dist/web/service.d.ts +11 -2
- package/dist/web/service.js +30 -4
- package/dist/web/workspace-devices.d.ts +107 -0
- package/dist/web/workspace-devices.js +277 -0
- package/dist/web/workspace-tunnel.d.ts +1 -0
- package/dist/web/workspace-tunnel.js +34 -0
- package/dist/workspace-enrollment.d.ts +83 -0
- package/dist/workspace-enrollment.js +605 -0
- package/dist/workspace-replacement.d.ts +66 -0
- package/dist/workspace-replacement.js +238 -0
- package/docs/acp-files.md +146 -0
- package/docs/conversation-stream.md +216 -0
- package/docs/fleet-migration.md +54 -0
- package/docs/live-voice.md +13 -0
- package/docs/room-layouts.md +227 -0
- package/docs/self-reminders.md +374 -0
- package/docs/task-workspaces.md +225 -0
- package/docs/validation/managed-cli-permissions.md +421 -0
- package/examples/room-layouts/fresh.yaml +27 -0
- package/examples/room-layouts/scoped.yaml +21 -0
- package/examples/room-layouts/shared.yaml +19 -0
- package/package.json +24 -20
- package/presets/README.md +78 -0
- package/presets/brain-catalog.json +8 -2
- package/presets/fleet/agent_templates/Critic.yaml +1 -1
- package/presets/fleet/agent_templates/Developer.yaml +1 -1
- package/presets/fleet/agent_templates/Engineer.yaml +5 -0
- package/presets/fleet/agent_templates/LocalCoordinator.yaml +4 -2
- package/presets/fleet/agents/FleetCoordinator.yaml +1 -1
- package/presets/fleet/brains/claude-fable-5-1-high.yaml +5 -0
- package/presets/fleet/brains/claude-fable-5-1-low.yaml +5 -0
- package/presets/fleet/brains/claude-fable-5-1-max.yaml +5 -0
- package/presets/fleet/brains/claude-fable-5-1-medium.yaml +5 -0
- package/presets/fleet/brains/claude-fable-5-1-xhigh.yaml +5 -0
- package/presets/fleet/brains/claude-fable-5-high.yaml +1 -1
- package/presets/fleet/brains/claude-fable-5-low.yaml +1 -1
- package/presets/fleet/brains/claude-fable-5-max.yaml +1 -1
- package/presets/fleet/brains/claude-fable-5-medium.yaml +1 -1
- package/presets/fleet/brains/claude-fable-5-xhigh.yaml +1 -1
- package/presets/fleet/brains/claude-haiku-4-5-20251001-default.yaml +4 -0
- package/presets/fleet/brains/claude-opus-5-5-high.yaml +5 -0
- package/presets/fleet/brains/claude-opus-5-5-low.yaml +5 -0
- package/presets/fleet/brains/claude-opus-5-5-max.yaml +5 -0
- package/presets/fleet/brains/claude-opus-5-5-medium.yaml +5 -0
- package/presets/fleet/brains/claude-opus-5-5-xhigh.yaml +5 -0
- package/presets/fleet/brains/claude-opus-5-high.yaml +1 -1
- package/presets/fleet/brains/claude-opus-5-low.yaml +1 -1
- package/presets/fleet/brains/claude-opus-5-max.yaml +1 -1
- package/presets/fleet/brains/claude-opus-5-medium.yaml +1 -1
- package/presets/fleet/brains/claude-opus-5-xhigh.yaml +1 -1
- package/presets/fleet/brains/claude-sonnet-5-high.yaml +1 -1
- package/presets/fleet/brains/claude-sonnet-5-low.yaml +1 -1
- package/presets/fleet/brains/claude-sonnet-5-max.yaml +1 -1
- package/presets/fleet/brains/claude-sonnet-5-medium.yaml +1 -1
- package/presets/fleet/brains/claude-sonnet-5-xhigh.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-3-codex-spark-high.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-3-codex-spark-low.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-3-codex-spark-medium.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-3-codex-spark-xhigh.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-4-high.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-4-low.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-4-medium.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-4-mini-high.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-4-mini-low.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-4-mini-medium.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-4-mini-xhigh.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-4-xhigh.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-5-high.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-5-low.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-5-medium.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-5-xhigh.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-luna-high.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-luna-low.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-luna-max.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-luna-medium.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-luna-xhigh.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-sol-high.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-sol-low.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-sol-max.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-sol-medium.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-sol-ultra.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-sol-xhigh.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-terra-high.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-terra-low.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-terra-max.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-terra-medium.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-terra-ultra.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-terra-xhigh.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-6-1-sol-high.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-1-sol-low.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-1-sol-max.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-1-sol-medium.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-1-sol-ultra.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-1-sol-xhigh.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-astra-high.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-6-astra-low.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-6-astra-max.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-6-astra-medium.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-6-astra-ultra.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-6-astra-xhigh.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-6-luna-high.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-luna-low.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-luna-max.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-luna-medium.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-luna-xhigh.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-sol-high.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-sol-low.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-sol-max.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-sol-medium.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-sol-ultra.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-sol-xhigh.yaml +5 -0
- package/presets/fleet/roles/Coordinator.yaml +12 -11
- package/presets/fleet/roles/Critic.yaml +13 -0
- package/presets/fleet/roles/Developer.yaml +13 -0
- package/presets/fleet/roles/Engineer.yaml +53 -0
- package/presets/fleet/room_layouts/engineering.yaml +25 -0
- package/presets/fleet/room_layouts/pair.yaml +24 -0
- package/presets/fleet/room_layouts/single.yaml +17 -0
- package/presets/fleet/room_layouts/team.yaml +30 -0
- package/presets/fleet/room_templates/engineering.yaml +19 -0
- package/presets/manifest.json +2 -2
- package/dist/web-app/assets/index-59GF-gsZ.css +0 -1
- package/dist/web-app/assets/index-C0h3ALvs.js +0 -10
- package/dist/web-app/icons/ours-fleet-maskable.svg +0 -4
- package/dist/web-app/icons/ours-fleet.svg +0 -4
- package/dist/web-app/index.html +0 -17
- package/dist/web-app/manifest.webmanifest +0 -15
- package/dist/web-app/offline.html +0 -18
- package/dist/web-app/sw.js +0 -51
package/dist/web/server.js
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
|
+
import { FleetResourceViews, ResourceBindingError, canonicalResourceDescriptor } from './resource-views.js';
|
|
2
|
+
import { publishFleetResourceCommit } from '../application/resource-observer.js';
|
|
3
|
+
import { stateRoot, defaultConfigPath } from '../paths.js';
|
|
4
|
+
import { conversationPreview } from '../application/conversation-history.js';
|
|
5
|
+
import { registerConversationStream } from './conversation-stream.js';
|
|
6
|
+
import { conversationHasAttachment } from '../application/conversation-history.js';
|
|
7
|
+
import { readDeliveredFile } from '../file-delivery/store.js';
|
|
8
|
+
import { WorkspaceDeviceAuthError } from './workspace-devices.js';
|
|
9
|
+
import { readFileSync } from 'node:fs';
|
|
10
|
+
import { packagedPresetRoot } from '../preset-bootstrap.js';
|
|
11
|
+
import { validateCatalog } from '../init-wizard.js';
|
|
12
|
+
import { getAdapter } from '../harness/registry.js';
|
|
13
|
+
import { storeAgentAttachment, attachmentPrompt, MAX_ATTACHMENT_BODY, readAgentAttachment, prepareAttachmentPresentation, presentAttachmentEvent } from './agent-attachments.js';
|
|
14
|
+
import { readChatIdle } from '../temp-idle.js';
|
|
15
|
+
import { agentDir } from '../paths.js';
|
|
1
16
|
import { SupervisorOursTools } from '../application/supervisor-ours-tools.js';
|
|
2
|
-
import {
|
|
3
|
-
import { dirname, join } from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
17
|
+
import { join } from 'node:path';
|
|
5
18
|
import Fastify from 'fastify';
|
|
6
|
-
import fastifyStatic from '@fastify/static';
|
|
7
19
|
import fastifyWebsocket from '@fastify/websocket';
|
|
8
20
|
import { createHmac, randomBytes } from 'node:crypto';
|
|
9
21
|
import { FleetError, normalizeError } from '../application/errors.js';
|
|
@@ -14,6 +26,8 @@ import { FleetEventBus } from './events.js';
|
|
|
14
26
|
import { ROLE_NAME_RE } from '../config.js';
|
|
15
27
|
import { TaskListError } from '../rooms-tasks/task-lists.js';
|
|
16
28
|
import { TaskStateError } from '../rooms-tasks/task-state.js';
|
|
29
|
+
import { isProvider } from '../subscriptions/store.js';
|
|
30
|
+
const ONBOARDING_WORK = ['coordination', 'development', 'review'];
|
|
17
31
|
const statusFor = (code) => ({
|
|
18
32
|
role_not_found: 404, resource_not_found: 404, unauthorized: 401, forbidden: 403, conflict: 409,
|
|
19
33
|
idempotency_conflict: 409, stale_state: 409, rate_limited: 429,
|
|
@@ -34,25 +48,46 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
34
48
|
app.addHook('onRequest', async (request, reply) => {
|
|
35
49
|
reply.header('X-Content-Type-Options', 'nosniff');
|
|
36
50
|
reply.header('Referrer-Policy', 'no-referrer');
|
|
37
|
-
reply.header('Permissions-Policy', 'camera=(), microphone=(), geolocation=(), payment=()');
|
|
38
|
-
|
|
39
|
-
reply.header('Content-Security-Policy',
|
|
40
|
-
`connect-src 'self' ${auth.secureCookies ? 'wss' : 'ws'}://${auth.host}; object-src 'none'; base-uri 'none'; ` +
|
|
41
|
-
`frame-ancestors 'none'; form-action 'self'; manifest-src 'self'; worker-src 'self'`);
|
|
51
|
+
reply.header('Permissions-Policy', 'camera=(), microphone=(self), geolocation=(), payment=()');
|
|
52
|
+
// Fleet serves an API only: nothing it returns may run, load or be framed as a page.
|
|
53
|
+
reply.header('Content-Security-Policy', "default-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'");
|
|
42
54
|
if (request.url.startsWith('/api/'))
|
|
43
55
|
reply.header('Cache-Control', 'no-store');
|
|
44
|
-
|
|
45
|
-
auth.
|
|
56
|
+
if (auth.appOrigin && request.headers.origin === auth.appOrigin && request.url.startsWith('/api/')) {
|
|
57
|
+
reply.header('Access-Control-Allow-Origin', auth.appOrigin).header('Vary', 'Origin');
|
|
58
|
+
reply.header('Access-Control-Allow-Methods', 'GET,POST,PUT,PATCH,DELETE,OPTIONS');
|
|
59
|
+
// The App binds resource reads by these headers; it must be able to send and read them cross-origin.
|
|
60
|
+
reply.header('Access-Control-Expose-Headers', 'X-Ours-Workspace-Auth, X-Ours-Request-Id, X-Resource-Producer, X-Resource-Revision, X-Resource-Source-Generation, X-Resource-Source-Position, X-Resource-Connection, X-Resource-View, X-Resource-Epoch, X-Resource-Baseline');
|
|
61
|
+
reply.header('Access-Control-Allow-Headers', 'Authorization,Content-Type,X-CSRF-Token,Idempotency-Key,X-Ours-Messenger-CSRF,X-Resource-Connection,X-Resource-View,X-Resource-Epoch,X-Resource-Baseline');
|
|
62
|
+
if (request.method === 'OPTIONS') {
|
|
63
|
+
auth.validateBoundary(request, false);
|
|
64
|
+
return reply.code(204).send();
|
|
65
|
+
}
|
|
46
66
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
67
|
+
auth.validateBoundary(request, false);
|
|
68
|
+
});
|
|
69
|
+
app.addHook('onResponse', async (request, reply) => {
|
|
70
|
+
if (reply.statusCode < 400 && ['POST', 'PUT', 'PATCH', 'DELETE'].includes(request.method) && !request.url.includes('/resource-subscriptions')) {
|
|
71
|
+
publishFleetResourceCommit(services.configuration?.path ?? defaultConfigPath());
|
|
72
|
+
publishFleetResourceCommit(stateRoot());
|
|
52
73
|
}
|
|
53
74
|
});
|
|
75
|
+
app.post('/api/v1/layout-bindings/:id/control', async (request) => {
|
|
76
|
+
// Initial support is direct same-host Fleet-to-Fleet transport.
|
|
77
|
+
const forwarded = Object.keys(request.headers).some(name => name === 'forwarded' || name.startsWith('x-forwarded-') || name === 'x-real-ip' || name === 'via');
|
|
78
|
+
if (!['127.0.0.1', '::1', '::ffff:127.0.0.1'].includes(request.ip) || forwarded)
|
|
79
|
+
throw new FleetError('forbidden', 'layout bindings require direct loopback access');
|
|
80
|
+
// Machine credentials cannot authenticate browser or lifecycle routes.
|
|
81
|
+
if (request.headers.origin)
|
|
82
|
+
auth.validateBoundary(request, true);
|
|
83
|
+
if (!services.layoutBindings)
|
|
84
|
+
throw new FleetError('capability_unavailable', 'layout bindings unavailable');
|
|
85
|
+
return services.layoutBindings.control(request.params.id, request.headers.authorization, request.body);
|
|
86
|
+
});
|
|
54
87
|
app.setErrorHandler(async (error, request, reply) => {
|
|
55
|
-
|
|
88
|
+
if (error instanceof ResourceBindingError)
|
|
89
|
+
return reply.code(error.status).send({ error: { code: 'resource_binding', message: error.message } });
|
|
90
|
+
const privateToolParseError = ['/api/v1/roles/:id/ours/call', '/api/v1/layout-bindings/:id/control'].includes(request.routeOptions.url ?? '')
|
|
56
91
|
&& error instanceof Error && 'code' in error
|
|
57
92
|
&& typeof error.code === 'string' && error.code.startsWith('FST_ERR_CTP_');
|
|
58
93
|
const fleetError = normalizeError(privateToolParseError
|
|
@@ -61,8 +96,13 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
61
96
|
requestId: request.id, action: `${request.method} ${request.routeOptions.url ?? request.url}`,
|
|
62
97
|
result: 'rejected', errorCode: fleetError.code,
|
|
63
98
|
});
|
|
99
|
+
if (error instanceof WorkspaceDeviceAuthError)
|
|
100
|
+
reply.header('X-Ours-Workspace-Auth', 'rejected');
|
|
101
|
+
if (fleetError.code === 'unauthorized')
|
|
102
|
+
reply.header('X-Ours-Request-Id', request.id);
|
|
64
103
|
reply.code(statusFor(fleetError.code)).send({ error: fleetError.toJSON() });
|
|
65
104
|
});
|
|
105
|
+
registerConversationStream(app, services, auth);
|
|
66
106
|
app.post('/api/v1/auth/exchange', async (request, reply) => {
|
|
67
107
|
const { session, device } = auth.exchange(request);
|
|
68
108
|
setAuthCookies(reply, session.id, device.token, auth.secureCookies);
|
|
@@ -101,6 +141,51 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
101
141
|
const session = auth.authenticate(request);
|
|
102
142
|
return { csrfToken: session.csrf, expiresAt: new Date(session.absoluteExpiresAt).toISOString() };
|
|
103
143
|
});
|
|
144
|
+
app.get('/api/v1/workspace/identity', async () => auth.workspaceIdentity());
|
|
145
|
+
app.post('/api/v1/devices/enroll', async (request, reply) => {
|
|
146
|
+
reply.header('Cache-Control', 'no-store');
|
|
147
|
+
const input = request.body;
|
|
148
|
+
if (!input)
|
|
149
|
+
throw new FleetError('invalid_request', 'device enrollment body required');
|
|
150
|
+
return auth.enrollWorkspace(request, input);
|
|
151
|
+
});
|
|
152
|
+
// Refresh credentials travel between the account server and this host; these routes refuse browsers.
|
|
153
|
+
const refreshInput = (request, name) => {
|
|
154
|
+
const value = request.body?.[name];
|
|
155
|
+
if (typeof value !== 'string')
|
|
156
|
+
throw new FleetError('invalid_request', `${name} is required`);
|
|
157
|
+
return value;
|
|
158
|
+
};
|
|
159
|
+
app.post('/api/v1/devices/refresh', async (request, reply) => {
|
|
160
|
+
reply.header('Cache-Control', 'no-store');
|
|
161
|
+
return auth.refreshWorkspace(request, refreshInput(request, 'refreshToken'));
|
|
162
|
+
});
|
|
163
|
+
app.post('/api/v1/devices/exchange', async (request, reply) => {
|
|
164
|
+
reply.header('Cache-Control', 'no-store');
|
|
165
|
+
return auth.exchangeWorkspace(request);
|
|
166
|
+
});
|
|
167
|
+
app.post('/api/v1/devices/revoke', async (request) => ({ revoked: auth.revokeWorkspaceRefresh(request, refreshInput(request, 'refreshHash')) }));
|
|
168
|
+
app.post('/api/v1/devices/link', async (request, reply) => {
|
|
169
|
+
const proof = request.body?.refreshToken;
|
|
170
|
+
if (proof !== undefined) {
|
|
171
|
+
reply.header('Cache-Control', 'no-store');
|
|
172
|
+
const { enrollment, enrollmentExpiresAt, ...credentials } = auth.linkWorkspaceDevice(request, refreshInput(request, 'refreshToken'));
|
|
173
|
+
return { ...credentials, code: { version: 1, origin: auth.origin, enrollment, workspaceId: credentials.workspaceId, expiresAt: enrollmentExpiresAt } };
|
|
174
|
+
}
|
|
175
|
+
const session = auth.authenticate(request, true);
|
|
176
|
+
// A short-lived access credential must not be able to create a lasting one.
|
|
177
|
+
if (session.rotating)
|
|
178
|
+
throw new FleetError('forbidden', 'linking another device requires this link\'s refresh credential');
|
|
179
|
+
return { version: 1, origin: auth.origin, ...auth.workspaceEnrollment(session.id) };
|
|
180
|
+
});
|
|
181
|
+
app.get('/api/v1/devices/current', async (request) => {
|
|
182
|
+
const session = auth.authenticate(request);
|
|
183
|
+
if (!session.id.startsWith('workspace:'))
|
|
184
|
+
throw new FleetError('resource_not_found', 'no workspace device');
|
|
185
|
+
return { deviceId: session.id.slice(10), authorizedUntil: session.absoluteExpiresAt };
|
|
186
|
+
});
|
|
187
|
+
app.get('/api/v1/devices', async (request) => { auth.authenticate(request); return { devices: auth.listWorkspaceDevices() }; });
|
|
188
|
+
app.delete('/api/v1/devices/:id', async (request) => { auth.authenticate(request, true); auth.revokeWorkspaceDevice(request.params.id); return { revoked: true }; });
|
|
104
189
|
app.get('/api/v1/meta', async (request) => {
|
|
105
190
|
auth.authenticate(request);
|
|
106
191
|
return {
|
|
@@ -111,6 +196,90 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
111
196
|
auditDegraded: audit.degraded,
|
|
112
197
|
};
|
|
113
198
|
});
|
|
199
|
+
let onboardingObserved;
|
|
200
|
+
app.get('/api/v1/onboarding', async (request) => {
|
|
201
|
+
const browser = auth.authenticate(request);
|
|
202
|
+
const revision = services.configuration?.read().revision;
|
|
203
|
+
// Opening an existing workspace needs configuration state, not CLI/account discovery.
|
|
204
|
+
// Keep the full report for the setup screens and older App clients.
|
|
205
|
+
if (request.query.view === 'state')
|
|
206
|
+
return { configured: onboardingConfigured() };
|
|
207
|
+
const harnesses = await Promise.all(['codex', 'claude-code'].map(async (harness) => {
|
|
208
|
+
try {
|
|
209
|
+
return { harness, ...await getAdapter(harness).checkPrereqs() };
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
return { harness, ok: false, checks: [{ name: 'availability', ok: false, detail: 'Harness checks unavailable' }] };
|
|
213
|
+
}
|
|
214
|
+
}));
|
|
215
|
+
const catalog = validateCatalog(JSON.parse(readFileSync(join(packagedPresetRoot(), 'brain-catalog.json'), 'utf8')));
|
|
216
|
+
// Codex models are offered only when the runtime itself listed them for the active account.
|
|
217
|
+
// When it could not be asked, none is offered and the reason is reported.
|
|
218
|
+
const codexModels = services.codexModels ? await services.codexModels() : undefined;
|
|
219
|
+
const offered = (model) => model.harness !== 'codex' || !codexModels || (codexModels.state === 'known' && codexModels.models.includes(model.model));
|
|
220
|
+
const payload = { harnesses, catalog: catalog.models.filter(offered), ...(codexModels ? { codexModels: codexModels.state === 'known' ? { state: 'known' } : codexModels } : {}), providers: services.subscriptions ? await services.subscriptions.list() : [], coordinator: 'FleetCoordinator', configured: onboardingConfigured() };
|
|
221
|
+
if (revision === services.configuration?.read().revision) {
|
|
222
|
+
onboardingObserved = { owner: browser.id, revision, payload };
|
|
223
|
+
events.publish('onboarding.changed', {});
|
|
224
|
+
}
|
|
225
|
+
return payload;
|
|
226
|
+
});
|
|
227
|
+
// First-time setup is what creates the persistent coordinator. A configuration that loads and
|
|
228
|
+
// has it is set up, whatever its brains are called; its models are then changed by editing it.
|
|
229
|
+
const onboardingConfigured = () => {
|
|
230
|
+
if (!services.configuration)
|
|
231
|
+
return false;
|
|
232
|
+
try {
|
|
233
|
+
return Boolean(services.configuration.read(false).model.agents.FleetCoordinator);
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
let onboardingSetupQueue = Promise.resolve();
|
|
240
|
+
app.post('/api/v1/onboarding/setup', async (request) => {
|
|
241
|
+
auth.authenticate(request, true);
|
|
242
|
+
if (!services.configuration || !services.onboardingSetup)
|
|
243
|
+
throw new FleetError('capability_unavailable', 'first-time Fleet setup is unavailable');
|
|
244
|
+
const requested = request.body?.models;
|
|
245
|
+
const codexModels = services.codexModels ? await services.codexModels() : undefined;
|
|
246
|
+
const supported = validateCatalog(JSON.parse(readFileSync(join(packagedPresetRoot(), 'brain-catalog.json'), 'utf8'))).models
|
|
247
|
+
.filter(model => model.harness !== 'codex' || !codexModels || (codexModels.state === 'known' && codexModels.models.includes(model.model)));
|
|
248
|
+
const models = {};
|
|
249
|
+
for (const work of ONBOARDING_WORK) {
|
|
250
|
+
const matches = supported.filter(model => model.harness === requested?.[work]?.harness && model.model === requested?.[work]?.model);
|
|
251
|
+
if (matches.length !== 1)
|
|
252
|
+
throw new FleetError('invalid_request', `choose a supported model for ${work}`);
|
|
253
|
+
models[work] = matches[0];
|
|
254
|
+
}
|
|
255
|
+
const chosen = Object.values(models);
|
|
256
|
+
const subscriptions = [...new Set(chosen.map(model => model.harness === 'codex' ? 'codex' : 'claude'))];
|
|
257
|
+
const oneModel = new Set(chosen.map(model => `${model.harness}\0${model.model}`)).size === 1;
|
|
258
|
+
const configuration = services.configuration, setup = services.onboardingSetup;
|
|
259
|
+
// One setup at a time: the first-time check and the publication it guards must not interleave.
|
|
260
|
+
const run = onboardingSetupQueue.then(async () => {
|
|
261
|
+
if (onboardingConfigured())
|
|
262
|
+
throw new FleetError('conflict', 'Fleet is already set up; change its models in the configuration');
|
|
263
|
+
try {
|
|
264
|
+
await setup({ subscriptions, assignmentStrategy: oneModel ? 'one-model' : 'per-job', models, reasoning: 'balanced' });
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
throw new FleetError('backend_failure', `Fleet setup did not complete: ${error.message}`);
|
|
268
|
+
}
|
|
269
|
+
// Setup preserves files it finds, so confirm the published models are the ones this request chose.
|
|
270
|
+
// The prepared agents reference packaged Brain presets, so resolve what each of them now points at:
|
|
271
|
+
// a preserved file of a packaged name may hold another model, session or reasoning than its name says.
|
|
272
|
+
const published = configuration.read(true).model, brains = published.brains ?? {};
|
|
273
|
+
const brainOf = (holder) => brains[String(holder?.brain?.ref ?? '')];
|
|
274
|
+
const assigned = { coordination: brainOf(published.agents.FleetCoordinator), development: brainOf(published.agent_templates?.Developer), review: brainOf(published.agent_templates?.Critic) };
|
|
275
|
+
for (const work of ONBOARDING_WORK)
|
|
276
|
+
if (assigned[work]?.harness !== models[work].harness || assigned[work]?.model !== models[work].model || assigned[work]?.session !== models[work].session || assigned[work]?.effort !== 'medium')
|
|
277
|
+
throw new FleetError('conflict', 'Fleet was set up with different models; review its configuration');
|
|
278
|
+
return { configured: true };
|
|
279
|
+
});
|
|
280
|
+
onboardingSetupQueue = run.catch(() => { });
|
|
281
|
+
return run;
|
|
282
|
+
});
|
|
114
283
|
app.get('/api/v1/creation-capabilities', async (request) => {
|
|
115
284
|
auth.authenticate(request);
|
|
116
285
|
return services.creation.capabilities();
|
|
@@ -133,7 +302,11 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
133
302
|
});
|
|
134
303
|
app.get('/api/v1/roles', async (request) => {
|
|
135
304
|
auth.authenticate(request);
|
|
136
|
-
|
|
305
|
+
const query = request.query;
|
|
306
|
+
// Unbound REST retains the existing problem-bearing inventory. Bound reads
|
|
307
|
+
// are handled by the strict resource preHandler before this route.
|
|
308
|
+
services.invalidateResourceCaches?.();
|
|
309
|
+
return { roles: await services.query.list(query.includeTemporary === 'true') };
|
|
137
310
|
});
|
|
138
311
|
const taskApi = async (fn) => {
|
|
139
312
|
try {
|
|
@@ -146,6 +319,8 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
146
319
|
? 'conflict' : 'invalid_request';
|
|
147
320
|
throw new FleetError(code, error.message);
|
|
148
321
|
}
|
|
322
|
+
if (error instanceof TaskStateError && 'accepted' in error && error.accepted === false)
|
|
323
|
+
return Promise.reject(Object.assign(new FleetError('invalid_request', error.message), { memberNotAccepted: true }));
|
|
149
324
|
if (error instanceof TaskStateError) {
|
|
150
325
|
throw new FleetError(error.message.startsWith('task not found:') ? 'resource_not_found' : 'conflict', error.message);
|
|
151
326
|
}
|
|
@@ -157,9 +332,156 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
157
332
|
throw new FleetError('capability_unavailable', 'task operations are unavailable');
|
|
158
333
|
return services.taskRooms;
|
|
159
334
|
};
|
|
335
|
+
const projectTasks = async (query, strict = true) => {
|
|
336
|
+
const states = ['backlog', 'provisioning', 'active', 'review', 'done', 'cancelled', 'failed'];
|
|
337
|
+
if (query.state && query.state !== 'all' && !states.includes(query.state))
|
|
338
|
+
throw new FleetError('invalid_request', 'invalid task state filter');
|
|
339
|
+
if (query.groupByList !== undefined && !['true', 'false'].includes(query.groupByList))
|
|
340
|
+
throw new FleetError('invalid_request', 'groupByList must be true or false');
|
|
341
|
+
if (query.includeDeleting !== undefined && !['true', 'false'].includes(query.includeDeleting))
|
|
342
|
+
throw new FleetError('invalid_request', 'includeDeleting must be true or false');
|
|
343
|
+
const state = query.state && query.state !== 'all' ? query.state : undefined;
|
|
344
|
+
const filter = { strict, ...(state ? { state } : {}), ...(query.list ? { list: query.list } : {}),
|
|
345
|
+
...(query.includeDeleting === 'true' ? { includeDeleting: true } : {}) };
|
|
346
|
+
const api = requireTaskRooms();
|
|
347
|
+
return taskApi(() => query.groupByList === 'true'
|
|
348
|
+
? { groups: api.groupedTasks(filter).map(group => ({ ...group, tasks: group.tasks.map(task => api.withLayoutRooms(task)) })) }
|
|
349
|
+
: { tasks: api.listTasks(filter).map(task => api.withLayoutRooms(task)) });
|
|
350
|
+
};
|
|
351
|
+
const project = async (descriptor, signal, owner = '') => {
|
|
352
|
+
signal.throwIfAborted();
|
|
353
|
+
services.invalidateResourceCaches?.();
|
|
354
|
+
switch (descriptor.resource) {
|
|
355
|
+
case 'task-layout':
|
|
356
|
+
try {
|
|
357
|
+
return { layout: await taskApi(() => requireTaskRooms().taskLayout(descriptor.entityId)) };
|
|
358
|
+
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
if (error?.code === 'task_not_found' || error?.code === 'resource_not_found')
|
|
361
|
+
return { deleted: true, id: descriptor.entityId };
|
|
362
|
+
throw error;
|
|
363
|
+
}
|
|
364
|
+
case 'creation-action': return services.creation.get(descriptor.entityId) ?? { deleted: true, id: descriptor.entityId };
|
|
365
|
+
case 'action': return services.commands.get(descriptor.entityId) ?? { deleted: true, id: descriptor.entityId };
|
|
366
|
+
case 'member-addition':
|
|
367
|
+
try {
|
|
368
|
+
return await taskApi(() => requireTaskRooms().memberAddition(descriptor.entityId, descriptor.receiptId));
|
|
369
|
+
}
|
|
370
|
+
catch (error) {
|
|
371
|
+
if (['task_not_found', 'resource_not_found'].includes(error?.code) || error?.message === 'Member request not found')
|
|
372
|
+
return { deleted: true, id: descriptor.receiptId };
|
|
373
|
+
throw error;
|
|
374
|
+
}
|
|
375
|
+
case 'login':
|
|
376
|
+
// A foreign login must never be delivered, including its URL/device code.
|
|
377
|
+
try {
|
|
378
|
+
return subscriptions().login(descriptor.entityId, owner).view();
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
if (error?.code === 'resource_not_found')
|
|
382
|
+
return { deleted: true, id: descriptor.entityId };
|
|
383
|
+
throw error;
|
|
384
|
+
}
|
|
385
|
+
case 'subscriptions': return { providers: await subscriptions().list(true) };
|
|
386
|
+
case 'onboarding-health': {
|
|
387
|
+
const revision = services.configuration?.read().revision;
|
|
388
|
+
if (onboardingObserved && onboardingObserved.revision !== revision)
|
|
389
|
+
onboardingObserved = undefined;
|
|
390
|
+
const observed = onboardingObserved?.owner === owner ? onboardingObserved : undefined;
|
|
391
|
+
return { ...observed?.payload, observationCurrent: !!observed, configured: onboardingConfigured(), providers: services.subscriptions ? await services.subscriptions.list(true) : [] };
|
|
392
|
+
}
|
|
393
|
+
case 'roles': return { roles: await services.query.list(descriptor.includeTemporary ?? false, true) };
|
|
394
|
+
case 'tasks': return projectTasks({ state: descriptor.state, list: descriptor.list, groupByList: String(descriptor.groupByList ?? false), includeDeleting: String(descriptor.includeDeleting ?? false) });
|
|
395
|
+
case 'task-lists': return { lists: requireTaskRooms().listTaskLists() };
|
|
396
|
+
case 'configuration':
|
|
397
|
+
if (!services.configuration)
|
|
398
|
+
throw new FleetError('capability_unavailable', 'fleet configuration editing is unavailable');
|
|
399
|
+
return { ...services.configuration.read(descriptor.includeDefinitions ?? false), provenance: services.presetProvenance?.read() ?? null };
|
|
400
|
+
case 'directory': {
|
|
401
|
+
const [roles, tasks] = await Promise.all([services.query.list(true, true), projectTasks({})]);
|
|
402
|
+
return { roles, tasks: tasks.tasks, lists: requireTaskRooms().listTaskLists() };
|
|
403
|
+
}
|
|
404
|
+
case 'previews': {
|
|
405
|
+
const roles = await services.repository.list(true), selected = new Map(roles.map(role => [role.id, role]));
|
|
406
|
+
const previews = {};
|
|
407
|
+
for (const id of descriptor.ids ?? []) {
|
|
408
|
+
signal.throwIfAborted();
|
|
409
|
+
const role = selected.get(id), dir = role && services.repository.stateDir(role);
|
|
410
|
+
if (!role)
|
|
411
|
+
continue;
|
|
412
|
+
try {
|
|
413
|
+
previews[id] = dir ? await conversationPreview(dir, signal) : { text: 'No recent agent output', at: '' };
|
|
414
|
+
}
|
|
415
|
+
catch {
|
|
416
|
+
signal.throwIfAborted();
|
|
417
|
+
// A damaged/unreadable ledger is unavailable, not empty or removed.
|
|
418
|
+
// Keep this selected row observable so a repair can refresh it,
|
|
419
|
+
// without retiring previews for the other selected roles.
|
|
420
|
+
previews[id] = { text: 'Preview unavailable', at: '', unavailable: true };
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return { previews };
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
const resources = new FleetResourceViews(services.resourceScope ?? {}, project, () => services.configuration?.resourceValidationInputs?.() ?? []);
|
|
428
|
+
app.addHook('preClose', async () => resources.close());
|
|
429
|
+
app.get('/api/v1/resource-events', async (request, reply) => {
|
|
430
|
+
const browser = auth.authenticate(request);
|
|
431
|
+
reply.hijack();
|
|
432
|
+
// A hijacked reply bypasses Fastify headers: keep the exact-origin CORS and security headers.
|
|
433
|
+
for (const [name, value] of Object.entries(reply.getHeaders()))
|
|
434
|
+
if (value !== undefined)
|
|
435
|
+
reply.raw.setHeader(name, Array.isArray(value) ? value : String(value));
|
|
436
|
+
reply.raw.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache, no-transform', Connection: 'keep-alive', 'X-Accel-Buffering': 'no' });
|
|
437
|
+
reply.raw.flushHeaders();
|
|
438
|
+
const opened = resources.open(reply.raw, browser.id, () => auth.sessionValid(browser));
|
|
439
|
+
const binding = auth.bindTransport(browser, opened.close);
|
|
440
|
+
reply.raw.once('close', () => binding());
|
|
441
|
+
});
|
|
442
|
+
app.post('/api/v1/resource-subscriptions', async (request, reply) => {
|
|
443
|
+
const browser = auth.authenticate(request, true), body = request.body;
|
|
444
|
+
const binding = resources.register(browser.id, String(body?.connectionId ?? ''), String(body?.viewId ?? ''), body?.subscriptionEpoch, body?.descriptor);
|
|
445
|
+
const retire = () => {
|
|
446
|
+
if (reply.raw.writableFinished)
|
|
447
|
+
return;
|
|
448
|
+
try {
|
|
449
|
+
resources.remove(browser.id, String(body.connectionId), String(body.viewId), body.subscriptionEpoch);
|
|
450
|
+
}
|
|
451
|
+
catch { /* Connection may already be closed. */ }
|
|
452
|
+
};
|
|
453
|
+
reply.raw.once('close', retire);
|
|
454
|
+
reply.raw.once('finish', () => reply.raw.off('close', retire));
|
|
455
|
+
if (reply.raw.destroyed)
|
|
456
|
+
retire();
|
|
457
|
+
return binding;
|
|
458
|
+
});
|
|
459
|
+
app.delete('/api/v1/resource-subscriptions', async (request) => {
|
|
460
|
+
const browser = auth.authenticate(request, true), body = request.body;
|
|
461
|
+
resources.remove(browser.id, String(body?.connectionId ?? ''), String(body?.viewId ?? ''), body?.subscriptionEpoch);
|
|
462
|
+
return { removed: true };
|
|
463
|
+
});
|
|
464
|
+
// Bound reads return precisely the registered initial capture, never an unrelated GET.
|
|
465
|
+
app.addHook('preHandler', async (request, reply) => {
|
|
466
|
+
if (request.method !== 'GET' || !request.headers['x-resource-connection'])
|
|
467
|
+
return;
|
|
468
|
+
const browser = auth.authenticate(request), headers = request.headers;
|
|
469
|
+
const baseline = await resources.bound(browser.id, String(headers['x-resource-connection']), String(headers['x-resource-view']), Number(headers['x-resource-epoch']), String(headers['x-resource-baseline']));
|
|
470
|
+
const expected = '/api/v1/' + baseline.descriptor.resource;
|
|
471
|
+
if (request.url.split('?')[0] !== expected)
|
|
472
|
+
throw new ResourceBindingError(409, 'resource route mismatch');
|
|
473
|
+
for (const name of ['Connection', 'View', 'Epoch', 'Baseline'])
|
|
474
|
+
reply.header('X-Resource-' + name, String(headers['x-resource-' + name.toLowerCase()]));
|
|
475
|
+
reply.header('X-Resource-Producer', baseline.producerGeneration).header('X-Resource-Revision', baseline.revision).header('X-Resource-Source-Generation', baseline.source.producerGeneration).header('X-Resource-Source-Position', baseline.source.position);
|
|
476
|
+
return reply.send(baseline.payload);
|
|
477
|
+
});
|
|
478
|
+
for (const resource of ['task-layout', 'creation-action', 'action', 'member-addition', 'login', 'onboarding-health'])
|
|
479
|
+
app.get('/api/v1/' + resource, async () => { throw new ResourceBindingError(409, 'resource binding required'); });
|
|
480
|
+
app.get('/api/v1/directory', async (request) => { auth.authenticate(request); return project({ viewId: 'read', resource: 'directory' }, new AbortController().signal); });
|
|
481
|
+
app.get('/api/v1/previews', async (request) => { auth.authenticate(request); const ids = String(request.query.ids ?? '').split(',').filter(Boolean); return project(canonicalResourceDescriptor({ viewId: 'read', resource: 'previews', ids }), new AbortController().signal); });
|
|
160
482
|
app.get('/api/v1/task-lists', async (request) => {
|
|
161
483
|
auth.authenticate(request);
|
|
162
|
-
return {
|
|
484
|
+
return project({ viewId: 'read', resource: 'task-lists' }, new AbortController().signal);
|
|
163
485
|
});
|
|
164
486
|
app.post('/api/v1/task-lists', async (request, reply) => {
|
|
165
487
|
auth.authenticate(request, true);
|
|
@@ -182,20 +504,7 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
182
504
|
});
|
|
183
505
|
app.get('/api/v1/tasks', async (request) => {
|
|
184
506
|
auth.authenticate(request);
|
|
185
|
-
|
|
186
|
-
const states = ['backlog', 'provisioning', 'active', 'review', 'done', 'cancelled', 'failed'];
|
|
187
|
-
if (query.state && query.state !== 'all' && !states.includes(query.state))
|
|
188
|
-
throw new FleetError('invalid_request', 'invalid task state filter');
|
|
189
|
-
if (query.groupByList !== undefined && !['true', 'false'].includes(query.groupByList))
|
|
190
|
-
throw new FleetError('invalid_request', 'groupByList must be true or false');
|
|
191
|
-
if (query.includeDeleting !== undefined && !['true', 'false'].includes(query.includeDeleting))
|
|
192
|
-
throw new FleetError('invalid_request', 'includeDeleting must be true or false');
|
|
193
|
-
const state = query.state && query.state !== 'all' ? query.state : undefined;
|
|
194
|
-
const filter = { ...(state ? { state } : {}), ...(query.list ? { list: query.list } : {}),
|
|
195
|
-
...(query.includeDeleting === 'true' ? { includeDeleting: true } : {}) };
|
|
196
|
-
return taskApi(() => query.groupByList === 'true'
|
|
197
|
-
? { groups: requireTaskRooms().groupedTasks(filter) }
|
|
198
|
-
: { tasks: requireTaskRooms().listTasks(filter) });
|
|
507
|
+
return projectTasks(request.query, false);
|
|
199
508
|
});
|
|
200
509
|
app.delete('/api/v1/tasks/:id', async (request, reply) => {
|
|
201
510
|
auth.authenticate(request, true);
|
|
@@ -226,12 +535,17 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
226
535
|
const body = request.body;
|
|
227
536
|
if (typeof body?.title !== 'string' || !body.title)
|
|
228
537
|
throw new FleetError('invalid_request', 'title is required');
|
|
538
|
+
// Every task runs a saved Room Layout; rooms are never defined inline or from room templates here.
|
|
539
|
+
if (typeof body.layout !== 'string' || !body.layout)
|
|
540
|
+
throw new FleetError('invalid_request', 'layout is required: choose a room layout from Settings › Room layouts');
|
|
541
|
+
if (body.template !== undefined || body.noRoom !== undefined)
|
|
542
|
+
throw new FleetError('invalid_request', 'tasks use room layouts; template and noRoom are not accepted');
|
|
229
543
|
const task = await taskApi(() => requireTaskRooms().createTask({
|
|
230
544
|
actor: { kind: 'local_control', surface: 'web' }, title: body.title,
|
|
231
545
|
brief: typeof body.brief === 'string' ? body.brief : undefined,
|
|
232
|
-
|
|
233
|
-
backlog: body.backlog === true, noRoom: body.noRoom === true,
|
|
546
|
+
backlog: body.backlog === true,
|
|
234
547
|
list: typeof body.list === 'string' ? body.list : undefined,
|
|
548
|
+
layout: body.layout,
|
|
235
549
|
idempotencyKey: typeof request.headers['idempotency-key'] === 'string'
|
|
236
550
|
? request.headers['idempotency-key'] : undefined,
|
|
237
551
|
origin: { type: 'web' },
|
|
@@ -245,11 +559,162 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
245
559
|
const list = String(request.body?.list ?? '');
|
|
246
560
|
return { task: await taskApi(() => requireTaskRooms().moveTask({ actor: { kind: 'local_control', surface: 'web' }, taskId, list })) };
|
|
247
561
|
});
|
|
562
|
+
app.patch('/api/v1/tasks/:id/description', async (request) => {
|
|
563
|
+
auth.authenticate(request, true);
|
|
564
|
+
const body = request.body;
|
|
565
|
+
if (typeof body?.brief !== 'string' || typeof body.expectedBrief !== 'string' || body.brief.length > 100_000)
|
|
566
|
+
throw new FleetError('invalid_request', 'brief and expectedBrief must be strings; brief maximum is 100000 characters');
|
|
567
|
+
return { task: await taskApi(() => requireTaskRooms().editTaskDescription({
|
|
568
|
+
actor: { kind: 'local_control', surface: 'web' }, taskId: request.params.id,
|
|
569
|
+
brief: body.brief, expectedBrief: body.expectedBrief,
|
|
570
|
+
})) };
|
|
571
|
+
});
|
|
572
|
+
app.get('/api/v1/tasks/:id', async (request) => {
|
|
573
|
+
auth.authenticate(request);
|
|
574
|
+
return taskApi(() => requireTaskRooms().getTask(request.params.id));
|
|
575
|
+
});
|
|
576
|
+
app.post('/api/v1/tasks/:id/members', async (request, reply) => {
|
|
577
|
+
auth.authenticate(request, true);
|
|
578
|
+
const body = request.body;
|
|
579
|
+
try {
|
|
580
|
+
const result = await taskApi(() => requireTaskRooms().addMember(request.params.id, body));
|
|
581
|
+
reply.code(result.state === 'running' ? 202 : 200);
|
|
582
|
+
return result;
|
|
583
|
+
}
|
|
584
|
+
catch (error) {
|
|
585
|
+
if (error instanceof Error && 'memberNotAccepted' in error)
|
|
586
|
+
return reply.code(409).send({ error: { code: 'member_not_accepted', message: error.message }, accepted: false });
|
|
587
|
+
throw error;
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
app.get('/api/v1/tasks/:id/member-additions/:requestId', async (request) => {
|
|
591
|
+
auth.authenticate(request);
|
|
592
|
+
const { id, requestId } = request.params;
|
|
593
|
+
return taskApi(() => requireTaskRooms().memberAddition(id, requestId));
|
|
594
|
+
});
|
|
595
|
+
app.patch('/api/v1/tasks/:id/layout', async (request) => {
|
|
596
|
+
const session = auth.authenticate(request, true);
|
|
597
|
+
const body = request.body;
|
|
598
|
+
const name = (v) => typeof v === 'string' && v.length > 0;
|
|
599
|
+
if (!name(body?.layout) || !(body.expectedLayout === null || name(body.expectedLayout)))
|
|
600
|
+
throw new FleetError('invalid_request', 'layout must be a layout name; expectedLayout a layout name or null');
|
|
601
|
+
const task = await taskApi(() => requireTaskRooms().setTaskLayout({ actor: { kind: 'local_control', surface: 'web' },
|
|
602
|
+
taskId: request.params.id, layout: body.layout, expectedLayout: body.expectedLayout }));
|
|
603
|
+
await audit.record({ requestId: request.id, browser: session.id, action: 'task.layout.set', result: 'succeeded' });
|
|
604
|
+
return { task: requireTaskRooms().withLayoutRooms(task) };
|
|
605
|
+
});
|
|
606
|
+
app.get('/api/v1/tasks/:id/layout', async (request) => {
|
|
607
|
+
auth.authenticate(request);
|
|
608
|
+
return { layout: await taskApi(async () => requireTaskRooms().taskLayout(request.params.id)) };
|
|
609
|
+
});
|
|
610
|
+
for (const operation of ['open', 'close']) {
|
|
611
|
+
app.post(`/api/v1/tasks/:id/layout/rooms/:room/${operation}`, async (request, reply) => {
|
|
612
|
+
const session = auth.authenticate(request, true);
|
|
613
|
+
const { id, room } = request.params;
|
|
614
|
+
const accepted = await taskApi(() => requireTaskRooms().launchTaskLayoutOperation({
|
|
615
|
+
actor: { kind: 'local_control', surface: 'web' }, taskId: id, room,
|
|
616
|
+
operation: operation === 'open' ? 'open' : 'close-room',
|
|
617
|
+
}));
|
|
618
|
+
await audit.record({ requestId: request.id, browser: session.id, action: `task.layout.${operation}`, result: 'succeeded' });
|
|
619
|
+
reply.code(202);
|
|
620
|
+
return { operation: accepted };
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
app.post('/api/v1/tasks/:id/layout/cleanup', async (request, reply) => {
|
|
624
|
+
auth.authenticate(request, true);
|
|
625
|
+
const accepted = await taskApi(() => requireTaskRooms().retryTaskLayoutCleanup({
|
|
626
|
+
actor: { kind: 'local_control', surface: 'web' }, taskId: request.params.id,
|
|
627
|
+
}));
|
|
628
|
+
reply.code(202);
|
|
629
|
+
return { operation: accepted };
|
|
630
|
+
});
|
|
631
|
+
app.get('/api/v1/task-templates', async (request) => {
|
|
632
|
+
auth.authenticate(request);
|
|
633
|
+
return { templates: requireTaskRooms().listTemplates() };
|
|
634
|
+
});
|
|
635
|
+
const layouts = () => {
|
|
636
|
+
if (!services.roomLayouts)
|
|
637
|
+
throw new FleetError('capability_unavailable', 'room layout editing is unavailable');
|
|
638
|
+
return services.roomLayouts;
|
|
639
|
+
};
|
|
640
|
+
app.get('/api/v1/room-layouts', async (request) => {
|
|
641
|
+
auth.authenticate(request);
|
|
642
|
+
const list = layouts().list(), defaultLayout = layouts().defaultLayout(list);
|
|
643
|
+
return { layouts: list, ...(defaultLayout ? { default_layout: defaultLayout } : {}) };
|
|
644
|
+
});
|
|
645
|
+
app.post('/api/v1/room-layouts/validate', async (request) => {
|
|
646
|
+
auth.authenticate(request, true);
|
|
647
|
+
return layouts().validate(request.body?.definition);
|
|
648
|
+
});
|
|
649
|
+
app.put('/api/v1/room-layouts/:name', async (request) => {
|
|
650
|
+
const session = auth.authenticate(request, true);
|
|
651
|
+
const body = request.body;
|
|
652
|
+
if (typeof body?.revision !== 'string')
|
|
653
|
+
throw new FleetError('invalid_request', 'revision is required');
|
|
654
|
+
const result = await layouts().save(request.params.name, body.revision, body.definition);
|
|
655
|
+
events.publish('room_layouts.changed', { name: result.name, revision: result.revision });
|
|
656
|
+
await audit.record({ requestId: request.id, browser: session.id, action: 'room_layout.save', result: 'succeeded' });
|
|
657
|
+
return result;
|
|
658
|
+
});
|
|
659
|
+
app.delete('/api/v1/room-layouts/:name', async (request) => {
|
|
660
|
+
const session = auth.authenticate(request, true);
|
|
661
|
+
const revision = request.query.revision;
|
|
662
|
+
if (typeof revision !== 'string' || !revision)
|
|
663
|
+
throw new FleetError('invalid_request', 'revision is required');
|
|
664
|
+
const result = await layouts().remove(request.params.name, revision);
|
|
665
|
+
events.publish('room_layouts.changed', { name: result.name });
|
|
666
|
+
await audit.record({ requestId: request.id, browser: session.id, action: 'room_layout.delete', result: 'succeeded' });
|
|
667
|
+
return result;
|
|
668
|
+
});
|
|
669
|
+
for (const action of ['start', 'block', 'unblock', 'review', 'finish', 'cancel']) {
|
|
670
|
+
app.post(`/api/v1/tasks/:id/${action}`, async (request, reply) => {
|
|
671
|
+
auth.authenticate(request, true);
|
|
672
|
+
const taskId = request.params.id;
|
|
673
|
+
const body = (request.body ?? {});
|
|
674
|
+
const input = { actor: { kind: 'local_control', surface: 'web' }, taskId };
|
|
675
|
+
const api = requireTaskRooms();
|
|
676
|
+
return taskApi(async () => {
|
|
677
|
+
switch (action) {
|
|
678
|
+
case 'start': {
|
|
679
|
+
// A task's layout can be chosen or changed but never removed, so this check cannot go stale.
|
|
680
|
+
if (!api.getTask(taskId).task.layout)
|
|
681
|
+
throw new FleetError('conflict', 'choose a room layout for this task before starting it');
|
|
682
|
+
const task = await api.startTask(input);
|
|
683
|
+
const provisioning = await api.launchTaskProvisioning(taskId);
|
|
684
|
+
if (provisioning.kind !== 'ready')
|
|
685
|
+
reply.code(202);
|
|
686
|
+
return { task, provisioning };
|
|
687
|
+
}
|
|
688
|
+
case 'block':
|
|
689
|
+
if (typeof body.reason !== 'string' || !body.reason.trim())
|
|
690
|
+
throw new FleetError('invalid_request', 'reason is required');
|
|
691
|
+
return { task: api.blockTask({ ...input, reason: body.reason }) };
|
|
692
|
+
case 'unblock': return { task: api.unblockTask(input) };
|
|
693
|
+
case 'review': return { task: api.reviewTask(input) };
|
|
694
|
+
case 'finish':
|
|
695
|
+
case 'cancel': {
|
|
696
|
+
const plan = action === 'finish' ? await api.finishTask(input) : await api.cancelTask(input);
|
|
697
|
+
const task = plan.settlementRequired ? await api.launchTaskSettlement(taskId) : plan.task;
|
|
698
|
+
const pending = task.terminal_intent?.status === 'pending';
|
|
699
|
+
if (pending)
|
|
700
|
+
reply.code(202);
|
|
701
|
+
return { task, pending };
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
app.get('/api/v1/configuration/provenance', async (request) => {
|
|
708
|
+
auth.authenticate(request);
|
|
709
|
+
if (!services.presetProvenance)
|
|
710
|
+
throw new FleetError('capability_unavailable', 'preset provenance is unavailable');
|
|
711
|
+
return { provenance: services.presetProvenance.read() };
|
|
712
|
+
});
|
|
248
713
|
app.get('/api/v1/configuration', async (request) => {
|
|
249
714
|
auth.authenticate(request);
|
|
250
715
|
if (!services.configuration)
|
|
251
716
|
throw new FleetError('capability_unavailable', 'fleet configuration editing is unavailable');
|
|
252
|
-
return
|
|
717
|
+
return project({ viewId: 'read', resource: 'configuration', includeDefinitions: request.query.includeDefinitions === 'true' }, new AbortController().signal);
|
|
253
718
|
});
|
|
254
719
|
app.post('/api/v1/configuration/preview', async (request) => {
|
|
255
720
|
auth.authenticate(request, true);
|
|
@@ -270,6 +735,86 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
270
735
|
});
|
|
271
736
|
return result;
|
|
272
737
|
});
|
|
738
|
+
// Claude Code / Codex subscription profiles. Responses carry account metadata
|
|
739
|
+
// only; token values never leave the CLI-owned credential files.
|
|
740
|
+
const subscriptions = () => {
|
|
741
|
+
if (!services.subscriptions)
|
|
742
|
+
throw new FleetError('capability_unavailable', 'subscription management is unavailable');
|
|
743
|
+
return services.subscriptions;
|
|
744
|
+
};
|
|
745
|
+
const provider = (raw) => {
|
|
746
|
+
if (!isProvider(raw))
|
|
747
|
+
throw new FleetError('invalid_request', 'unknown subscription provider');
|
|
748
|
+
return raw;
|
|
749
|
+
};
|
|
750
|
+
const subscriptionsChanged = () => events.publish('subscription.changed', {});
|
|
751
|
+
app.get('/api/v1/subscriptions', async (request) => {
|
|
752
|
+
auth.authenticate(request);
|
|
753
|
+
return { providers: await subscriptions().list() };
|
|
754
|
+
});
|
|
755
|
+
app.post('/api/v1/subscriptions/:provider/logins', async (request, reply) => {
|
|
756
|
+
const session = auth.authenticate(request, true);
|
|
757
|
+
const login = await subscriptions().startLogin(provider(request.params.provider), session.id);
|
|
758
|
+
await audit.record({ requestId: request.id, browser: session.id, action: `subscription.login.${request.params.provider}`, result: login.state });
|
|
759
|
+
reply.code(201);
|
|
760
|
+
return login;
|
|
761
|
+
});
|
|
762
|
+
app.get('/api/v1/subscriptions/:provider/logins/:loginId', async (request) => {
|
|
763
|
+
const session = auth.authenticate(request);
|
|
764
|
+
return subscriptions().login(request.params.loginId, session.id).view();
|
|
765
|
+
});
|
|
766
|
+
app.post('/api/v1/subscriptions/:provider/logins/:loginId/code', async (request) => {
|
|
767
|
+
const session = auth.authenticate(request, true);
|
|
768
|
+
const code = request.body?.code;
|
|
769
|
+
if (typeof code !== 'string')
|
|
770
|
+
throw new FleetError('invalid_request', 'code is required');
|
|
771
|
+
const login = subscriptions().login(request.params.loginId, session.id);
|
|
772
|
+
login.submitCode(code.trim());
|
|
773
|
+
await audit.record({ requestId: request.id, browser: session.id, action: `subscription.login.code.${request.params.provider}`, result: 'submitted' });
|
|
774
|
+
return login.view();
|
|
775
|
+
});
|
|
776
|
+
app.delete('/api/v1/subscriptions/:provider/logins/:loginId', async (request) => {
|
|
777
|
+
const session = auth.authenticate(request, true);
|
|
778
|
+
const login = subscriptions().login(request.params.loginId, session.id);
|
|
779
|
+
login.cancel();
|
|
780
|
+
return login.view();
|
|
781
|
+
});
|
|
782
|
+
app.post('/api/v1/subscriptions/:provider/active', async (request) => {
|
|
783
|
+
const session = auth.authenticate(request, true);
|
|
784
|
+
const profileId = request.body?.profileId;
|
|
785
|
+
if (typeof profileId !== 'string')
|
|
786
|
+
throw new FleetError('invalid_request', 'profileId is required');
|
|
787
|
+
const view = await subscriptions().setActive(provider(request.params.provider), profileId);
|
|
788
|
+
subscriptionsChanged();
|
|
789
|
+
await audit.record({ requestId: request.id, browser: session.id, action: `subscription.activate.${request.params.provider}`, result: 'succeeded' });
|
|
790
|
+
return view;
|
|
791
|
+
});
|
|
792
|
+
app.post('/api/v1/subscriptions/:provider/profiles/:profileId/check', async (request) => {
|
|
793
|
+
auth.authenticate(request, true);
|
|
794
|
+
return subscriptions().check(provider(request.params.provider), request.params.profileId);
|
|
795
|
+
});
|
|
796
|
+
app.post('/api/v1/subscriptions/claude/profiles/:profileId/probe', async (request) => {
|
|
797
|
+
const session = auth.authenticate(request, true);
|
|
798
|
+
const usage = await subscriptions().probeClaudeUsage(request.params.profileId);
|
|
799
|
+
await audit.record({ requestId: request.id, browser: session.id, action: 'subscription.usage.probe.claude', result: usage.source });
|
|
800
|
+
return { usage };
|
|
801
|
+
});
|
|
802
|
+
app.patch('/api/v1/subscriptions/:provider/profiles/:profileId', async (request) => {
|
|
803
|
+
auth.authenticate(request, true);
|
|
804
|
+
const label = request.body?.label;
|
|
805
|
+
if (typeof label !== 'string')
|
|
806
|
+
throw new FleetError('invalid_request', 'label is required');
|
|
807
|
+
await subscriptions().rename(provider(request.params.provider), request.params.profileId, label);
|
|
808
|
+
subscriptionsChanged();
|
|
809
|
+
return { ok: true };
|
|
810
|
+
});
|
|
811
|
+
app.delete('/api/v1/subscriptions/:provider/profiles/:profileId', async (request) => {
|
|
812
|
+
const session = auth.authenticate(request, true);
|
|
813
|
+
await subscriptions().remove(provider(request.params.provider), request.params.profileId);
|
|
814
|
+
subscriptionsChanged();
|
|
815
|
+
await audit.record({ requestId: request.id, browser: session.id, action: `subscription.remove.${request.params.provider}`, result: 'succeeded' });
|
|
816
|
+
return { ok: true };
|
|
817
|
+
});
|
|
273
818
|
app.get('/api/v1/topology', async (request) => {
|
|
274
819
|
auth.authenticate(request);
|
|
275
820
|
if (!services.topology)
|
|
@@ -317,6 +862,20 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
317
862
|
return result;
|
|
318
863
|
});
|
|
319
864
|
const oursTools = services.oursTools ?? new SupervisorOursTools();
|
|
865
|
+
app.get('/api/v1/roles/:id/contacts', async (request) => {
|
|
866
|
+
auth.authenticate(request);
|
|
867
|
+
const control = await services.session(request.params.id);
|
|
868
|
+
if (!control.agentContacts)
|
|
869
|
+
throw new FleetError('capability_unavailable', 'Supervisor contacts API is unavailable');
|
|
870
|
+
return control.agentContacts();
|
|
871
|
+
});
|
|
872
|
+
app.get('/api/v1/roles/:id/messages', async (request) => {
|
|
873
|
+
auth.authenticate(request);
|
|
874
|
+
const control = await services.session(request.params.id);
|
|
875
|
+
if (!control.agentHistory)
|
|
876
|
+
throw new FleetError('capability_unavailable', 'Supervisor history API is unavailable');
|
|
877
|
+
return control.agentHistory({ peer_cid: request.query.peer_cid, ...(request.query.limit !== undefined ? { limit: Number(request.query.limit) } : {}), ...(request.query.before_seq !== undefined ? { before_seq: Number(request.query.before_seq) } : {}) });
|
|
878
|
+
});
|
|
320
879
|
app.get('/api/v1/roles/:id/ours/tools', async (request) => {
|
|
321
880
|
auth.authenticate(request);
|
|
322
881
|
return oursTools.list(request.params.id);
|
|
@@ -330,7 +889,13 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
330
889
|
});
|
|
331
890
|
app.get('/api/v1/roles/:id', async (request) => {
|
|
332
891
|
auth.authenticate(request);
|
|
333
|
-
|
|
892
|
+
const detail = await services.query.detail(request.params.id);
|
|
893
|
+
return { ...detail, chatIdle: detail.role.lifetime === 'temporary' ? readChatIdle(agentDir(request.params.id, true)) ?? null : null };
|
|
894
|
+
});
|
|
895
|
+
app.get('/api/v1/roles/:id/voice-capabilities', async (request) => {
|
|
896
|
+
auth.authenticate(request);
|
|
897
|
+
const descriptor = await (await services.session(request.params.id)).describe();
|
|
898
|
+
return { supported: ['generation_bound_prompts', 'idle_bound_prompts', 'targeted_voice_interrupt'].every(f => descriptor.features.includes(f)) };
|
|
334
899
|
});
|
|
335
900
|
app.get('/api/v1/roles/:id/removal-preview', async (request) => {
|
|
336
901
|
auth.authenticate(request);
|
|
@@ -360,20 +925,121 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
360
925
|
limit: request.query.limit ? Number(request.query.limit) : undefined,
|
|
361
926
|
});
|
|
362
927
|
});
|
|
363
|
-
app.get('/api/v1/roles/:id/conversation', async (request) => {
|
|
928
|
+
app.get('/api/v1/roles/:id/conversation', async (request, reply) => {
|
|
364
929
|
auth.authenticate(request);
|
|
365
930
|
const control = await services.session(request.params.id);
|
|
366
931
|
if (!control.conversationPage)
|
|
367
932
|
throw new FleetError('capability_unavailable', 'this role has no conversation ledger');
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
933
|
+
const limit = request.query.limit ? Number(request.query.limit) : undefined;
|
|
934
|
+
// `latest` / `before` page backwards from the newest event; `after` pages forward for live updates.
|
|
935
|
+
const backward = request.query.latest === '1' || request.query.before !== undefined;
|
|
936
|
+
if (backward && request.query.after !== undefined)
|
|
937
|
+
throw new FleetError('invalid_request', 'after cannot be combined with latest or before');
|
|
938
|
+
if (backward && !control.conversationTail)
|
|
939
|
+
throw new FleetError('capability_unavailable', 'this role cannot page its conversation backwards');
|
|
940
|
+
const role = await services.repository.get(request.params.id);
|
|
941
|
+
const stateDir = role ? services.repository.stateDir(role) : undefined;
|
|
942
|
+
const present = (event) => presentAttachmentEvent(stateDir, request.params.id, event);
|
|
943
|
+
if (backward) {
|
|
944
|
+
const owner = new AbortController();
|
|
945
|
+
const cancel = () => owner.abort();
|
|
946
|
+
request.raw.once('aborted', cancel);
|
|
947
|
+
reply.raw.once('close', cancel);
|
|
948
|
+
if (request.raw.aborted || reply.raw.destroyed)
|
|
949
|
+
cancel();
|
|
950
|
+
try {
|
|
951
|
+
const page = await control.conversationTail({ before: request.query.before, limit, signal: owner.signal });
|
|
952
|
+
owner.signal.throwIfAborted();
|
|
953
|
+
return { ...page, events: page.events.map(present), context: page.context.map(present) };
|
|
954
|
+
}
|
|
955
|
+
finally {
|
|
956
|
+
request.raw.off('aborted', cancel);
|
|
957
|
+
reply.raw.off('close', cancel);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
const page = await control.conversationPage({ after: request.query.after, limit });
|
|
961
|
+
return { ...page, events: page.events.map(present) };
|
|
962
|
+
});
|
|
963
|
+
app.get('/api/v1/roles/:id/artifacts/:artifactId', async (request, reply) => {
|
|
964
|
+
auth.authenticate(request);
|
|
965
|
+
const role = await services.repository.get(request.params.id);
|
|
966
|
+
if (!role)
|
|
967
|
+
throw new FleetError('role_not_found', 'Agent not found');
|
|
968
|
+
const stateDir = services.repository.stateDir(role);
|
|
969
|
+
if (!stateDir)
|
|
970
|
+
throw new FleetError('resource_not_found', 'Agent file not found');
|
|
971
|
+
try {
|
|
972
|
+
const { record, bytes } = await readDeliveredFile(stateDir, request.params.artifactId);
|
|
973
|
+
if (!await conversationHasAttachment(stateDir, record))
|
|
974
|
+
throw Error('ARTIFACT_NOT_PUBLISHED');
|
|
975
|
+
reply.header('Cache-Control', 'private, no-store');
|
|
976
|
+
reply.header('X-Content-Type-Options', 'nosniff');
|
|
977
|
+
reply.header('Content-Security-Policy', "default-src 'none'; sandbox");
|
|
978
|
+
reply.header('Content-Disposition', `attachment; filename*=UTF-8''${encodeURIComponent(record.name).replace(/'/g, '%27')}`);
|
|
979
|
+
return reply.type('application/octet-stream').send(bytes);
|
|
980
|
+
}
|
|
981
|
+
catch {
|
|
982
|
+
throw new FleetError('resource_not_found', 'Agent file unavailable');
|
|
983
|
+
}
|
|
984
|
+
});
|
|
985
|
+
app.get('/api/v1/roles/:id/attachments/:attachmentId', async (request, reply) => {
|
|
986
|
+
auth.authenticate(request);
|
|
987
|
+
const role = await services.repository.get(request.params.id);
|
|
988
|
+
if (!role)
|
|
989
|
+
throw new FleetError('role_not_found', 'Agent not found');
|
|
990
|
+
const stateDir = services.repository.stateDir(role);
|
|
991
|
+
if (!stateDir)
|
|
992
|
+
throw new FleetError('capability_unavailable', 'Agent file storage is unavailable');
|
|
993
|
+
const { record, bytes } = readAgentAttachment(stateDir, request.params.attachmentId);
|
|
994
|
+
const image = /^image\/(png|jpeg|gif|webp|avif)$/.test(record.mimeType);
|
|
995
|
+
reply.header('Cache-Control', 'private, no-store');
|
|
996
|
+
reply.header('X-Content-Type-Options', 'nosniff');
|
|
997
|
+
reply.header('Content-Security-Policy', "default-src 'none'; sandbox");
|
|
998
|
+
reply.header('Content-Disposition', `${image ? 'inline' : 'attachment'}; filename*=UTF-8''${encodeURIComponent(record.name).replace(/'/g, '%27')}`);
|
|
999
|
+
return reply.type(image ? record.mimeType : 'application/octet-stream').send(bytes);
|
|
1000
|
+
});
|
|
1001
|
+
app.post('/api/v1/roles/:id/attachments', { bodyLimit: MAX_ATTACHMENT_BODY }, async (request) => {
|
|
1002
|
+
auth.authenticate(request, true);
|
|
1003
|
+
const role = await services.repository.get(request.params.id);
|
|
1004
|
+
if (!role)
|
|
1005
|
+
throw new FleetError('role_not_found', 'Agent not found');
|
|
1006
|
+
const stateDir = services.repository.stateDir(role);
|
|
1007
|
+
if (!stateDir)
|
|
1008
|
+
throw new FleetError('capability_unavailable', 'Agent file storage is unavailable');
|
|
1009
|
+
const body = request.body;
|
|
1010
|
+
if (typeof body?.expectedSessionGeneration !== 'string' || !body.expectedSessionGeneration.trim())
|
|
1011
|
+
throw new FleetError('invalid_request', 'expectedSessionGeneration is required for attachments');
|
|
1012
|
+
const control = await services.session(request.params.id);
|
|
1013
|
+
if (!control.conversationPage || !control.submitPromptV2)
|
|
1014
|
+
throw new FleetError('capability_unavailable', 'Session-bound attachments are unavailable');
|
|
1015
|
+
const page = await control.conversationPage({ limit: 1 });
|
|
1016
|
+
if (page.snapshot.sessionGeneration !== body.expectedSessionGeneration)
|
|
1017
|
+
throw new FleetError('stale_state', 'Agent session changed. Select the files again.');
|
|
1018
|
+
return storeAgentAttachment(stateDir, body.expectedSessionGeneration, request.body);
|
|
372
1019
|
});
|
|
373
1020
|
app.post('/api/v1/roles/:id/input', async (request, reply) => {
|
|
374
1021
|
const session = auth.authenticate(request, true);
|
|
375
1022
|
const body = request.body;
|
|
376
|
-
|
|
1023
|
+
if (body?.expectedSessionGeneration !== undefined && (typeof body.expectedSessionGeneration !== 'string' || !body.expectedSessionGeneration.trim()))
|
|
1024
|
+
throw new FleetError('invalid_request', 'expectedSessionGeneration must be a nonempty string');
|
|
1025
|
+
if (body?.requireIdle !== undefined && typeof body.requireIdle !== 'boolean')
|
|
1026
|
+
throw new FleetError('invalid_request', 'requireIdle must be boolean');
|
|
1027
|
+
let text = String(body?.text ?? '');
|
|
1028
|
+
if (body?.attachments !== undefined) {
|
|
1029
|
+
if (typeof body.commandId !== 'string' || !body.commandId.trim())
|
|
1030
|
+
throw new FleetError('invalid_request', 'commandId is required for attachments');
|
|
1031
|
+
if (typeof body.expectedSessionGeneration !== 'string' || !body.expectedSessionGeneration.trim())
|
|
1032
|
+
throw new FleetError('invalid_request', 'expectedSessionGeneration is required for attachments');
|
|
1033
|
+
const role = await services.repository.get(request.params.id);
|
|
1034
|
+
if (!role)
|
|
1035
|
+
throw new FleetError('role_not_found', 'Agent not found');
|
|
1036
|
+
const stateDir = services.repository.stateDir(role);
|
|
1037
|
+
if (!stateDir)
|
|
1038
|
+
throw new FleetError('capability_unavailable', 'Agent file storage is unavailable');
|
|
1039
|
+
const originalText = text;
|
|
1040
|
+
text = attachmentPrompt(stateDir, body.expectedSessionGeneration, body.attachments, text);
|
|
1041
|
+
prepareAttachmentPresentation(stateDir, body.expectedSessionGeneration, body.commandId, body.attachments, originalText, text);
|
|
1042
|
+
}
|
|
377
1043
|
const commandId = typeof body?.commandId === 'string' && body.commandId.trim()
|
|
378
1044
|
? body.commandId : undefined;
|
|
379
1045
|
const control = await services.session(request.params.id);
|
|
@@ -384,6 +1050,7 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
384
1050
|
const admittedCommandId = commandId ?? randomBytes(16).toString('hex');
|
|
385
1051
|
const receipt = await control.submitPromptV2({
|
|
386
1052
|
commandId: admittedCommandId, text, source: 'owner_admin_console',
|
|
1053
|
+
expectedSessionGeneration: body.expectedSessionGeneration, requireIdle: body.requireIdle === true,
|
|
387
1054
|
actorBrowserSession: createHmac('sha256', digestKey).update(session.id).digest('hex').slice(0, 24),
|
|
388
1055
|
});
|
|
389
1056
|
await audit.record({
|
|
@@ -395,6 +1062,8 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
395
1062
|
reply.code(202);
|
|
396
1063
|
return receipt;
|
|
397
1064
|
}
|
|
1065
|
+
if (body.expectedSessionGeneration !== undefined || body.requireIdle)
|
|
1066
|
+
throw new FleetError('capability_unavailable', 'session-bound voice input is unavailable for this role');
|
|
398
1067
|
const receipt = await control.sendText(text);
|
|
399
1068
|
await audit.record({
|
|
400
1069
|
requestId: request.id, browser: session.id, roleId: request.params.id,
|
|
@@ -410,6 +1079,16 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
410
1079
|
const commandId = typeof body?.commandId === 'string' && body.commandId.trim()
|
|
411
1080
|
? body.commandId : undefined;
|
|
412
1081
|
const control = await services.session(request.params.id);
|
|
1082
|
+
if (body?.expectedSessionGeneration !== undefined || body?.promptId !== undefined) {
|
|
1083
|
+
if (!commandId || typeof body.expectedSessionGeneration !== 'string' || !body.expectedSessionGeneration.trim() || typeof body.promptId !== 'string' || !body.promptId.trim())
|
|
1084
|
+
throw new FleetError('invalid_request', 'Targeted interrupt requires commandId, expectedSessionGeneration and promptId');
|
|
1085
|
+
if (!control.interruptPromptV2)
|
|
1086
|
+
throw new FleetError('capability_unavailable', 'Targeted voice interrupt is unavailable');
|
|
1087
|
+
const receipt = await control.interruptPromptV2({ commandId, expectedSessionGeneration: body.expectedSessionGeneration, promptId: body.promptId });
|
|
1088
|
+
await audit.record({ requestId: request.id, browser: session.id, roleId: request.params.id, action: 'session.interrupt_voice', result: 'accepted' });
|
|
1089
|
+
reply.code(202);
|
|
1090
|
+
return receipt;
|
|
1091
|
+
}
|
|
413
1092
|
if (commandId && control.interruptV2) {
|
|
414
1093
|
const receipt = await control.interruptV2(commandId);
|
|
415
1094
|
await audit.record({
|
|
@@ -460,10 +1139,22 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
460
1139
|
const body = request.body;
|
|
461
1140
|
if (!body.action || !['start', 'stop', 'restart_resume', 'restart_fresh'].includes(body.action))
|
|
462
1141
|
throw new FleetError('invalid_request', 'invalid lifecycle action');
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
1142
|
+
let receipt;
|
|
1143
|
+
try {
|
|
1144
|
+
receipt = await services.commands.execute({
|
|
1145
|
+
roleId: request.params.id, action: body.action,
|
|
1146
|
+
actionId: body.actionId, confirmation: body.confirmation,
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1149
|
+
catch (error) {
|
|
1150
|
+
// An existing receipt always wins: a conflicting/repeated action is not a
|
|
1151
|
+
// proof that the original operation was never admitted.
|
|
1152
|
+
if (typeof body.actionId === 'string' && !services.commands.get(body.actionId)) {
|
|
1153
|
+
const normalized = normalizeError(error);
|
|
1154
|
+
return reply.code(409).send({ error: { code: 'action_not_accepted', message: normalized.message }, accepted: false });
|
|
1155
|
+
}
|
|
1156
|
+
throw error;
|
|
1157
|
+
}
|
|
467
1158
|
events.publish('action.changed', receipt, request.params.id);
|
|
468
1159
|
reply.code(202);
|
|
469
1160
|
return receipt;
|
|
@@ -482,6 +1173,75 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
482
1173
|
throw new FleetError('role_not_found', 'creation action not found');
|
|
483
1174
|
return action;
|
|
484
1175
|
});
|
|
1176
|
+
// A fetch stream works through the same authenticated workspace transport as
|
|
1177
|
+
// ordinary requests, and owns one ACP controller until its browser disconnects.
|
|
1178
|
+
app.post('/api/v1/roles/:id/live-presence', async (request, reply) => {
|
|
1179
|
+
const browser = auth.authenticate(request, true);
|
|
1180
|
+
const generation = request.body?.expectedSessionGeneration;
|
|
1181
|
+
if (typeof generation !== 'string' || !generation.trim())
|
|
1182
|
+
throw new FleetError('invalid_request', 'expectedSessionGeneration is required');
|
|
1183
|
+
const control = await services.session(request.params.id);
|
|
1184
|
+
if (!control.followConversation || !control.conversationPage)
|
|
1185
|
+
throw new FleetError('capability_unavailable', 'Live voice requires a conversation controller');
|
|
1186
|
+
const page = await control.conversationPage({ limit: 1 });
|
|
1187
|
+
if (page.snapshot.sessionGeneration !== generation)
|
|
1188
|
+
throw new FleetError('stale_state', 'Agent session changed. Start live voice again.');
|
|
1189
|
+
// Session/page discovery can await I/O; recheck revocation before attaching.
|
|
1190
|
+
auth.authenticate(request, true);
|
|
1191
|
+
if (reply.raw.destroyed)
|
|
1192
|
+
return;
|
|
1193
|
+
reply.hijack();
|
|
1194
|
+
for (const [name, value] of Object.entries(reply.getHeaders()))
|
|
1195
|
+
if (value !== undefined)
|
|
1196
|
+
reply.raw.setHeader(name, Array.isArray(value) ? value : String(value));
|
|
1197
|
+
reply.raw.writeHead(200, { 'Content-Type': 'application/x-ndjson', 'Cache-Control': 'no-store', 'X-Accel-Buffering': 'no' });
|
|
1198
|
+
let ended = false;
|
|
1199
|
+
let follow;
|
|
1200
|
+
let heartbeat;
|
|
1201
|
+
let unbind;
|
|
1202
|
+
const close = () => { if (ended)
|
|
1203
|
+
return; ended = true; unbind?.(); if (heartbeat)
|
|
1204
|
+
clearInterval(heartbeat); follow?.close(); reply.raw.end(); };
|
|
1205
|
+
const write = (value) => { if (!ended && !reply.raw.write(JSON.stringify(value) + '\n'))
|
|
1206
|
+
close(); };
|
|
1207
|
+
reply.raw.once('close', close);
|
|
1208
|
+
// A voice session outlives one access credential; its page renews this stream by name.
|
|
1209
|
+
const renewal = browser.rotating ? randomBytes(32).toString('base64url') : undefined;
|
|
1210
|
+
unbind = auth.bindTransport(browser, close, renewal);
|
|
1211
|
+
try {
|
|
1212
|
+
follow = await control.followConversation({
|
|
1213
|
+
after: page.nextCursor,
|
|
1214
|
+
onPage: current => { if (current.snapshot.sessionGeneration !== generation) {
|
|
1215
|
+
write({ error: 'Agent session changed. Start live voice again.' });
|
|
1216
|
+
close();
|
|
1217
|
+
}
|
|
1218
|
+
else
|
|
1219
|
+
write({ ready: true, ...(renewal ? { renewal } : {}) }); },
|
|
1220
|
+
onEvent: event => { if (event.sessionGeneration !== generation) {
|
|
1221
|
+
write({ error: 'Agent session changed. Start live voice again.' });
|
|
1222
|
+
close();
|
|
1223
|
+
} },
|
|
1224
|
+
onClose: () => close(),
|
|
1225
|
+
});
|
|
1226
|
+
if (ended)
|
|
1227
|
+
follow.close();
|
|
1228
|
+
// A renewable stream is ended by its own deadline and by revocation, not by the first credential's expiry.
|
|
1229
|
+
else
|
|
1230
|
+
heartbeat = setInterval(() => { try {
|
|
1231
|
+
if (!renewal)
|
|
1232
|
+
auth.authenticate(request);
|
|
1233
|
+
write({ heartbeat: true });
|
|
1234
|
+
}
|
|
1235
|
+
catch {
|
|
1236
|
+
close();
|
|
1237
|
+
} }, 10_000);
|
|
1238
|
+
}
|
|
1239
|
+
catch {
|
|
1240
|
+
write({ error: 'Agent controller connection failed.' });
|
|
1241
|
+
close();
|
|
1242
|
+
}
|
|
1243
|
+
});
|
|
1244
|
+
app.post('/api/v1/transports/:id/renew', async (request) => auth.renewTransport(request, request.params.id));
|
|
485
1245
|
app.post('/api/v1/ws-tickets', async (request) => {
|
|
486
1246
|
const body = request.body;
|
|
487
1247
|
if (!body?.purpose || !['events', 'conversation'].includes(body.purpose))
|
|
@@ -516,7 +1276,7 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
516
1276
|
requireSubprotocol(request, 'ours-fleet-events.v1');
|
|
517
1277
|
authorizeSocket(socket, request, async (hello) => {
|
|
518
1278
|
const session = auth.consumeTicket(request, String(hello.ticket ?? ''), 'events');
|
|
519
|
-
auth.bindSocket(session
|
|
1279
|
+
auth.bindSocket(session, socket);
|
|
520
1280
|
const detach = events.attach(socket, typeof hello.lastEventId === 'string' ? hello.lastEventId : undefined);
|
|
521
1281
|
socket.on('close', detach);
|
|
522
1282
|
socket.send(JSON.stringify({ kind: 'ready', at: new Date().toISOString() }));
|
|
@@ -526,7 +1286,7 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
526
1286
|
requireSubprotocol(request, 'ours-fleet-conversation.v1');
|
|
527
1287
|
authorizeSocket(socket, request, async (hello) => {
|
|
528
1288
|
const session = auth.consumeTicket(request, String(hello.ticket ?? ''), 'conversation', request.params.id);
|
|
529
|
-
auth.bindSocket(session
|
|
1289
|
+
auth.bindSocket(session, socket);
|
|
530
1290
|
const control = await services.session(request.params.id);
|
|
531
1291
|
if (!control.followConversation)
|
|
532
1292
|
throw new FleetError('capability_unavailable', 'this role has no conversation ledger');
|
|
@@ -551,6 +1311,9 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
551
1311
|
}
|
|
552
1312
|
socket.send(JSON.stringify(payload));
|
|
553
1313
|
};
|
|
1314
|
+
const role = await services.repository.get(request.params.id);
|
|
1315
|
+
const stateDir = role ? services.repository.stateDir(role) : undefined;
|
|
1316
|
+
const present = (event) => presentAttachmentEvent(stateDir, request.params.id, event);
|
|
554
1317
|
const follow = await control.followConversation({
|
|
555
1318
|
after,
|
|
556
1319
|
onPage: page => {
|
|
@@ -561,11 +1324,11 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
561
1324
|
lastCursor: page.nextCursor ?? after,
|
|
562
1325
|
});
|
|
563
1326
|
if (page.events.length)
|
|
564
|
-
guardedSend({ type: 'events', events: page.events });
|
|
1327
|
+
guardedSend({ type: 'events', events: page.events.map(present) });
|
|
565
1328
|
if (page.hasMore)
|
|
566
1329
|
guardedSend({ type: 'resync.required' });
|
|
567
1330
|
},
|
|
568
|
-
onEvent: event => guardedSend({ type: 'events', events: [event] }),
|
|
1331
|
+
onEvent: event => guardedSend({ type: 'events', events: [present(event)] }),
|
|
569
1332
|
onClose: reason => {
|
|
570
1333
|
if (socket.readyState === socket.OPEN)
|
|
571
1334
|
socket.close(4409, (reason ?? 'conversation stream ended').slice(0, 120));
|
|
@@ -578,15 +1341,8 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
578
1341
|
socket.on('close', () => { clearInterval(heartbeat); follow.close(); });
|
|
579
1342
|
});
|
|
580
1343
|
});
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
await app.register(fastifyStatic, { root: staticRoot, prefix: '/' });
|
|
584
|
-
app.setNotFoundHandler((request, reply) => {
|
|
585
|
-
if (request.url.startsWith('/api/'))
|
|
586
|
-
return reply.code(404).send({ error: 'not found' });
|
|
587
|
-
return reply.sendFile('index.html');
|
|
588
|
-
});
|
|
589
|
-
}
|
|
1344
|
+
// Fleet has no pages of its own; every screen belongs to the App.
|
|
1345
|
+
app.setNotFoundHandler((_request, reply) => reply.code(404).send({ error: 'not found' }));
|
|
590
1346
|
return {
|
|
591
1347
|
app, auth, audit, events,
|
|
592
1348
|
async close() {
|
|
@@ -599,17 +1355,17 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
599
1355
|
function setAuthCookies(reply, session, device, secure = false) {
|
|
600
1356
|
const suffix = secure ? '; Secure' : '';
|
|
601
1357
|
reply.header('Set-Cookie', [
|
|
602
|
-
`ofs_session=${encodeURIComponent(session)}; HttpOnly; SameSite=Strict; Path
|
|
603
|
-
`ofs_device=${encodeURIComponent(device)}; HttpOnly; SameSite=Strict; Path
|
|
1358
|
+
`ofs_session=${encodeURIComponent(session)}; HttpOnly; SameSite=Strict; Path=/; Max-Age=28800${suffix}`,
|
|
1359
|
+
`ofs_device=${encodeURIComponent(device)}; HttpOnly; SameSite=Strict; Path=/; Max-Age=2592000${suffix}`,
|
|
604
1360
|
]);
|
|
605
1361
|
}
|
|
606
1362
|
function setSessionCookie(reply, session, secure = false) {
|
|
607
|
-
reply.header('Set-Cookie', `ofs_session=${encodeURIComponent(session)}; HttpOnly; SameSite=Strict; Path
|
|
1363
|
+
reply.header('Set-Cookie', `ofs_session=${encodeURIComponent(session)}; HttpOnly; SameSite=Strict; Path=/; Max-Age=28800${secure ? '; Secure' : ''}`);
|
|
608
1364
|
}
|
|
609
1365
|
function clearAuthCookies(reply) {
|
|
610
1366
|
reply.header('Set-Cookie', [
|
|
611
|
-
'ofs_session=; HttpOnly; SameSite=Strict; Path
|
|
612
|
-
'ofs_device=; HttpOnly; SameSite=Strict; Path
|
|
1367
|
+
'ofs_session=; HttpOnly; SameSite=Strict; Path=/; Max-Age=0',
|
|
1368
|
+
'ofs_device=; HttpOnly; SameSite=Strict; Path=/; Max-Age=0',
|
|
613
1369
|
]);
|
|
614
1370
|
}
|
|
615
1371
|
function promoteRequest(body) {
|
|
@@ -623,9 +1379,6 @@ function promoteRequest(body) {
|
|
|
623
1379
|
};
|
|
624
1380
|
}
|
|
625
1381
|
function cryptoRandomId() { return randomBytes(12).toString('hex'); }
|
|
626
|
-
function escapeHtml(value) {
|
|
627
|
-
return value.replace(/[&<>"']/g, char => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[char]));
|
|
628
|
-
}
|
|
629
1382
|
function requireSubprotocol(request, expected) {
|
|
630
1383
|
const protocols = String(request.headers['sec-websocket-protocol'] ?? '')
|
|
631
1384
|
.split(',').map(value => value.trim());
|