@ours.network/fleet 1.2.0-nightly.5 → 1.2.0-nightly.51
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 +263 -53
- package/dist/account-origin.d.ts +2 -0
- package/dist/account-origin.js +6 -0
- package/dist/agent-ours/bridge.js +9 -0
- package/dist/agent-ours/correspondence.d.ts +10 -0
- package/dist/agent-ours/correspondence.js +1 -0
- package/dist/agent-ours/harness.js +8 -0
- package/dist/agent-ours/runtime.d.ts +6 -0
- package/dist/agent-ours/runtime.js +36 -0
- package/dist/agent-ours/service.js +33 -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 +25 -0
- package/dist/application/conversation-history.js +189 -0
- package/dist/application/fleet-query-service.d.ts +1 -1
- package/dist/application/fleet-query-service.js +2 -2
- package/dist/application/legacy-supervisor-identity.d.ts +7 -0
- package/dist/application/legacy-supervisor-identity.js +43 -0
- 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/role-creation-service.js +1 -1
- package/dist/application/role-removal-service.js +2 -0
- package/dist/application/role-repository.js +2 -2
- 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 +30 -0
- package/dist/application/session-control.js +72 -3
- package/dist/application/supervisor-ours-tools.d.ts +159 -0
- package/dist/application/supervisor-ours-tools.js +113 -0
- package/dist/application/task-layouts.d.ts +91 -0
- package/dist/application/task-layouts.js +249 -0
- package/dist/application/task-room-service.d.ts +99 -3
- package/dist/application/task-room-service.js +296 -31
- package/dist/atomic-file.d.ts +5 -0
- package/dist/atomic-file.js +62 -1
- package/dist/briefing.d.ts +2 -0
- package/dist/briefing.js +8 -1
- package/dist/build-info.json +7 -4
- package/dist/capabilities.d.ts +6 -1
- package/dist/capabilities.js +8 -0
- package/dist/cli.js +376 -34
- package/dist/client-profile.d.ts +5 -17
- package/dist/client-profile.js +4 -127
- package/dist/config.d.ts +28 -0
- package/dist/config.js +41 -6
- package/dist/creation.js +2 -2
- package/dist/daemon-recovery.d.ts +1 -8
- package/dist/daemon-recovery.js +8 -113
- package/dist/docs.d.ts +3 -3
- package/dist/docs.js +126 -22
- package/dist/doctor.d.ts +1 -1
- package/dist/doctor.js +55 -60
- package/dist/erased-resources.d.ts +9 -0
- package/dist/erased-resources.js +87 -0
- package/dist/fleet-command-audit.d.ts +7 -0
- package/dist/fleet-command-audit.js +26 -9
- package/dist/harness/claude-code.js +9 -1
- 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.d.ts +3 -2
- package/dist/harness/codex.js +20 -11
- package/dist/init-wizard.d.ts +2 -0
- package/dist/init-wizard.js +38 -19
- package/dist/isolation/policy.js +2 -0
- 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/minimal-setup.d.ts +2 -0
- package/dist/minimal-setup.js +44 -0
- package/dist/monitor.d.ts +1 -34
- package/dist/monitor.js +24 -151
- package/dist/notifications/fleet-producer.d.ts +19 -0
- package/dist/notifications/fleet-producer.js +208 -0
- package/dist/notifications/outbox.d.ts +46 -0
- package/dist/notifications/outbox.js +158 -0
- package/dist/notifications/target-cleanup.d.ts +8 -0
- package/dist/notifications/target-cleanup.js +41 -0
- package/dist/ops.js +5 -1
- package/dist/owner-channel/channel.d.ts +3 -0
- package/dist/owner-channel/channel.js +34 -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 +2 -0
- package/dist/paths.js +2 -0
- package/dist/preset-migration.js +25 -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 +83 -0
- package/dist/rooms-tasks/archived-absence.d.ts +8 -0
- package/dist/rooms-tasks/archived-absence.js +48 -0
- package/dist/rooms-tasks/cli.js +34 -5
- package/dist/rooms-tasks/close.d.ts +5 -2
- package/dist/rooms-tasks/close.js +208 -28
- 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 +6 -4
- package/dist/rooms-tasks/cowork-adapter.js +8 -121
- package/dist/rooms-tasks/deletion.d.ts +1 -1
- package/dist/rooms-tasks/deletion.js +74 -5
- package/dist/rooms-tasks/erasure.d.ts +6 -0
- package/dist/rooms-tasks/erasure.js +169 -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-service.d.ts +42 -0
- package/dist/rooms-tasks/layout-service.js +185 -0
- package/dist/rooms-tasks/layout.d.ts +114 -0
- package/dist/rooms-tasks/layout.js +250 -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-startup.d.ts +1 -0
- package/dist/rooms-tasks/member-startup.js +2 -0
- package/dist/rooms-tasks/provision.d.ts +14 -0
- package/dist/rooms-tasks/provision.js +173 -46
- package/dist/rooms-tasks/room-state.d.ts +4 -2
- package/dist/rooms-tasks/room-state.js +53 -8
- package/dist/rooms-tasks/task-state.d.ts +42 -7
- package/dist/rooms-tasks/task-state.js +153 -23
- package/dist/rooms-tasks/types.d.ts +28 -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 +26 -0
- package/dist/rooms-tasks/workspace.js +195 -0
- package/dist/runner.d.ts +19 -3
- package/dist/runner.js +128 -45
- package/dist/session/acp.d.ts +9 -1
- package/dist/session/acp.js +31 -6
- package/dist/session/arbiter.d.ts +5 -0
- package/dist/session/arbiter.js +28 -2
- package/dist/session/codex-app-server.d.ts +5 -0
- package/dist/session/codex-app-server.js +36 -3
- package/dist/session/control.d.ts +12 -1
- package/dist/session/control.js +68 -3
- package/dist/session/conversation-normalizer.d.ts +2 -1
- package/dist/session/conversation-normalizer.js +1 -1
- package/dist/session/conversation-store.d.ts +1 -1
- package/dist/session/conversation-store.js +7 -11
- package/dist/session/conversation-types.d.ts +7 -3
- package/dist/session/task-notice.d.ts +14 -0
- package/dist/session/task-notice.js +13 -0
- package/dist/session/types.d.ts +6 -0
- 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.js +8 -1
- package/dist/startup-readiness.d.ts +13 -0
- package/dist/startup-readiness.js +38 -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 +75 -0
- package/dist/subscriptions/login.js +182 -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 +140 -0
- package/dist/supervisor/launchd.js +2 -1
- package/dist/supervisor/systemd.js +9 -23
- package/dist/temp-idle.d.ts +17 -0
- package/dist/temp-idle.js +42 -0
- package/dist/temp-lifecycle.d.ts +6 -1
- package/dist/temp-lifecycle.js +29 -13
- 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 +124 -0
- package/dist/web/agent-attachments.d.ts +29 -0
- package/dist/web/agent-attachments.js +162 -0
- package/dist/web/auth.d.ts +29 -1
- package/dist/web/auth.js +82 -7
- 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/fleet-config-service.d.ts +4 -1
- package/dist/web/fleet-config-service.js +46 -15
- package/dist/web/prefix-gateway.d.ts +32 -0
- package/dist/web/prefix-gateway.js +234 -0
- package/dist/web/runtime.d.ts +3 -1
- package/dist/web/runtime.js +116 -31
- package/dist/web/server.d.ts +16 -0
- package/dist/web/server.js +592 -53
- package/dist/web/service.d.ts +11 -2
- package/dist/web/service.js +30 -4
- package/dist/web/workspace-devices.d.ts +36 -0
- package/dist/web/workspace-devices.js +101 -0
- package/dist/web/workspace-tunnel.d.ts +1 -0
- package/dist/web/workspace-tunnel.js +34 -0
- package/dist/workspace-enrollment.d.ts +82 -0
- package/dist/workspace-enrollment.js +566 -0
- package/dist/workspace-replacement.d.ts +66 -0
- package/dist/workspace-replacement.js +220 -0
- package/docs/live-voice.md +13 -0
- package/docs/room-layouts.md +227 -0
- package/docs/task-workspaces.md +130 -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 +15 -18
- 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 +1 -1
- 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 +34 -11
- package/presets/fleet/roles/Engineer.yaml +40 -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,8 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { WorkspaceDeviceAuthError } from './workspace-devices.js';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { packagedPresetRoot } from '../preset-bootstrap.js';
|
|
4
|
+
import { validateCatalog } from '../init-wizard.js';
|
|
5
|
+
import { getAdapter } from '../harness/registry.js';
|
|
6
|
+
import { storeAgentAttachment, attachmentPrompt, MAX_ATTACHMENT_BODY, readAgentAttachment, prepareAttachmentPresentation, presentAttachmentEvent } from './agent-attachments.js';
|
|
7
|
+
import { readChatIdle } from '../temp-idle.js';
|
|
8
|
+
import { agentDir } from '../paths.js';
|
|
9
|
+
import { SupervisorOursTools } from '../application/supervisor-ours-tools.js';
|
|
10
|
+
import { join } from 'node:path';
|
|
4
11
|
import Fastify from 'fastify';
|
|
5
|
-
import fastifyStatic from '@fastify/static';
|
|
6
12
|
import fastifyWebsocket from '@fastify/websocket';
|
|
7
13
|
import { createHmac, randomBytes } from 'node:crypto';
|
|
8
14
|
import { FleetError, normalizeError } from '../application/errors.js';
|
|
@@ -13,6 +19,8 @@ import { FleetEventBus } from './events.js';
|
|
|
13
19
|
import { ROLE_NAME_RE } from '../config.js';
|
|
14
20
|
import { TaskListError } from '../rooms-tasks/task-lists.js';
|
|
15
21
|
import { TaskStateError } from '../rooms-tasks/task-state.js';
|
|
22
|
+
import { isProvider } from '../subscriptions/store.js';
|
|
23
|
+
const ONBOARDING_WORK = ['coordination', 'development', 'review'];
|
|
16
24
|
const statusFor = (code) => ({
|
|
17
25
|
role_not_found: 404, resource_not_found: 404, unauthorized: 401, forbidden: 403, conflict: 409,
|
|
18
26
|
idempotency_conflict: 409, stale_state: 409, rate_limited: 429,
|
|
@@ -33,29 +41,49 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
33
41
|
app.addHook('onRequest', async (request, reply) => {
|
|
34
42
|
reply.header('X-Content-Type-Options', 'nosniff');
|
|
35
43
|
reply.header('Referrer-Policy', 'no-referrer');
|
|
36
|
-
reply.header('Permissions-Policy', 'camera=(), microphone=(), geolocation=(), payment=()');
|
|
37
|
-
|
|
38
|
-
reply.header('Content-Security-Policy',
|
|
39
|
-
`connect-src 'self' ${auth.secureCookies ? 'wss' : 'ws'}://${auth.host}; object-src 'none'; base-uri 'none'; ` +
|
|
40
|
-
`frame-ancestors 'none'; form-action 'self'; manifest-src 'self'; worker-src 'self'`);
|
|
44
|
+
reply.header('Permissions-Policy', 'camera=(), microphone=(self), geolocation=(), payment=()');
|
|
45
|
+
// Fleet serves an API only: nothing it returns may run, load or be framed as a page.
|
|
46
|
+
reply.header('Content-Security-Policy', "default-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'");
|
|
41
47
|
if (request.url.startsWith('/api/'))
|
|
42
48
|
reply.header('Cache-Control', 'no-store');
|
|
43
|
-
|
|
44
|
-
auth.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
if (request.headers.origin === auth.appOrigin && request.url.startsWith('/api/')) {
|
|
50
|
+
reply.header('Access-Control-Allow-Origin', auth.appOrigin).header('Vary', 'Origin');
|
|
51
|
+
reply.header('Access-Control-Allow-Methods', 'GET,POST,PUT,PATCH,DELETE,OPTIONS');
|
|
52
|
+
reply.header('Access-Control-Expose-Headers', 'X-Ours-Workspace-Auth, X-Ours-Request-Id');
|
|
53
|
+
reply.header('Access-Control-Allow-Headers', 'Authorization,Content-Type,X-CSRF-Token,Idempotency-Key');
|
|
54
|
+
if (request.method === 'OPTIONS') {
|
|
55
|
+
auth.validateBoundary(request, false);
|
|
56
|
+
return reply.code(204).send();
|
|
57
|
+
}
|
|
51
58
|
}
|
|
59
|
+
auth.validateBoundary(request, false);
|
|
60
|
+
});
|
|
61
|
+
app.post('/api/v1/layout-bindings/:id/control', async (request) => {
|
|
62
|
+
// Initial support is direct same-host Fleet-to-Fleet transport.
|
|
63
|
+
const forwarded = Object.keys(request.headers).some(name => name === 'forwarded' || name.startsWith('x-forwarded-') || name === 'x-real-ip' || name === 'via');
|
|
64
|
+
if (!['127.0.0.1', '::1', '::ffff:127.0.0.1'].includes(request.ip) || forwarded)
|
|
65
|
+
throw new FleetError('forbidden', 'layout bindings require direct loopback access');
|
|
66
|
+
// Machine credentials cannot authenticate browser or lifecycle routes.
|
|
67
|
+
if (request.headers.origin)
|
|
68
|
+
auth.validateBoundary(request, true);
|
|
69
|
+
if (!services.layoutBindings)
|
|
70
|
+
throw new FleetError('capability_unavailable', 'layout bindings unavailable');
|
|
71
|
+
return services.layoutBindings.control(request.params.id, request.headers.authorization, request.body);
|
|
52
72
|
});
|
|
53
73
|
app.setErrorHandler(async (error, request, reply) => {
|
|
54
|
-
const
|
|
74
|
+
const privateToolParseError = ['/api/v1/roles/:id/ours/call', '/api/v1/layout-bindings/:id/control'].includes(request.routeOptions.url ?? '')
|
|
75
|
+
&& error instanceof Error && 'code' in error
|
|
76
|
+
&& typeof error.code === 'string' && error.code.startsWith('FST_ERR_CTP_');
|
|
77
|
+
const fleetError = normalizeError(privateToolParseError
|
|
78
|
+
? new FleetError('invalid_request', 'expected a valid JSON tool request') : error, request.id);
|
|
55
79
|
await audit.record({
|
|
56
80
|
requestId: request.id, action: `${request.method} ${request.routeOptions.url ?? request.url}`,
|
|
57
81
|
result: 'rejected', errorCode: fleetError.code,
|
|
58
82
|
});
|
|
83
|
+
if (error instanceof WorkspaceDeviceAuthError)
|
|
84
|
+
reply.header('X-Ours-Workspace-Auth', 'rejected');
|
|
85
|
+
if (fleetError.code === 'unauthorized')
|
|
86
|
+
reply.header('X-Ours-Request-Id', request.id);
|
|
59
87
|
reply.code(statusFor(fleetError.code)).send({ error: fleetError.toJSON() });
|
|
60
88
|
});
|
|
61
89
|
app.post('/api/v1/auth/exchange', async (request, reply) => {
|
|
@@ -96,6 +124,20 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
96
124
|
const session = auth.authenticate(request);
|
|
97
125
|
return { csrfToken: session.csrf, expiresAt: new Date(session.absoluteExpiresAt).toISOString() };
|
|
98
126
|
});
|
|
127
|
+
app.get('/api/v1/workspace/identity', async () => auth.workspaceIdentity());
|
|
128
|
+
app.post('/api/v1/devices/enroll', async (request, reply) => {
|
|
129
|
+
reply.header('Cache-Control', 'no-store');
|
|
130
|
+
const input = request.body;
|
|
131
|
+
if (!input)
|
|
132
|
+
throw new FleetError('invalid_request', 'device enrollment body required');
|
|
133
|
+
return auth.enrollWorkspace(request, input);
|
|
134
|
+
});
|
|
135
|
+
app.post('/api/v1/devices/link', async (request) => {
|
|
136
|
+
const session = auth.authenticate(request, true);
|
|
137
|
+
return { version: 1, origin: auth.origin, ...auth.workspaceEnrollment(session.id) };
|
|
138
|
+
});
|
|
139
|
+
app.get('/api/v1/devices', async (request) => { auth.authenticate(request); return { devices: auth.listWorkspaceDevices() }; });
|
|
140
|
+
app.delete('/api/v1/devices/:id', async (request) => { auth.authenticate(request, true); auth.revokeWorkspaceDevice(request.params.id); return { revoked: true }; });
|
|
99
141
|
app.get('/api/v1/meta', async (request) => {
|
|
100
142
|
auth.authenticate(request);
|
|
101
143
|
return {
|
|
@@ -106,6 +148,83 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
106
148
|
auditDegraded: audit.degraded,
|
|
107
149
|
};
|
|
108
150
|
});
|
|
151
|
+
app.get('/api/v1/onboarding', async (request) => {
|
|
152
|
+
auth.authenticate(request);
|
|
153
|
+
// Opening an existing workspace needs configuration state, not CLI/account discovery.
|
|
154
|
+
// Keep the full report for the setup screens and older App clients.
|
|
155
|
+
if (request.query.view === 'state')
|
|
156
|
+
return { configured: onboardingConfigured() };
|
|
157
|
+
const harnesses = await Promise.all(['codex', 'claude-code'].map(async (harness) => {
|
|
158
|
+
try {
|
|
159
|
+
return { harness, ...await getAdapter(harness).checkPrereqs() };
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return { harness, ok: false, checks: [{ name: 'availability', ok: false, detail: 'Harness checks unavailable' }] };
|
|
163
|
+
}
|
|
164
|
+
}));
|
|
165
|
+
const catalog = validateCatalog(JSON.parse(readFileSync(join(packagedPresetRoot(), 'brain-catalog.json'), 'utf8')));
|
|
166
|
+
// Codex models are offered only when the runtime itself listed them for the active account.
|
|
167
|
+
// When it could not be asked, none is offered and the reason is reported.
|
|
168
|
+
const codexModels = services.codexModels ? await services.codexModels() : undefined;
|
|
169
|
+
const offered = (model) => model.harness !== 'codex' || !codexModels || (codexModels.state === 'known' && codexModels.models.includes(model.model));
|
|
170
|
+
return { 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() };
|
|
171
|
+
});
|
|
172
|
+
// First-time setup is what creates the persistent coordinator. A configuration that loads and
|
|
173
|
+
// has it is set up, whatever its brains are called; its models are then changed by editing it.
|
|
174
|
+
const onboardingConfigured = () => {
|
|
175
|
+
if (!services.configuration)
|
|
176
|
+
return false;
|
|
177
|
+
try {
|
|
178
|
+
return Boolean(services.configuration.read(false).model.agents.FleetCoordinator);
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
let onboardingSetupQueue = Promise.resolve();
|
|
185
|
+
app.post('/api/v1/onboarding/setup', async (request) => {
|
|
186
|
+
auth.authenticate(request, true);
|
|
187
|
+
if (!services.configuration || !services.onboardingSetup)
|
|
188
|
+
throw new FleetError('capability_unavailable', 'first-time Fleet setup is unavailable');
|
|
189
|
+
const requested = request.body?.models;
|
|
190
|
+
const codexModels = services.codexModels ? await services.codexModels() : undefined;
|
|
191
|
+
const supported = validateCatalog(JSON.parse(readFileSync(join(packagedPresetRoot(), 'brain-catalog.json'), 'utf8'))).models
|
|
192
|
+
.filter(model => model.harness !== 'codex' || !codexModels || (codexModels.state === 'known' && codexModels.models.includes(model.model)));
|
|
193
|
+
const models = {};
|
|
194
|
+
for (const work of ONBOARDING_WORK) {
|
|
195
|
+
const matches = supported.filter(model => model.harness === requested?.[work]?.harness && model.model === requested?.[work]?.model);
|
|
196
|
+
if (matches.length !== 1)
|
|
197
|
+
throw new FleetError('invalid_request', `choose a supported model for ${work}`);
|
|
198
|
+
models[work] = matches[0];
|
|
199
|
+
}
|
|
200
|
+
const chosen = Object.values(models);
|
|
201
|
+
const subscriptions = [...new Set(chosen.map(model => model.harness === 'codex' ? 'codex' : 'claude'))];
|
|
202
|
+
const oneModel = new Set(chosen.map(model => `${model.harness}\0${model.model}`)).size === 1;
|
|
203
|
+
const configuration = services.configuration, setup = services.onboardingSetup;
|
|
204
|
+
// One setup at a time: the first-time check and the publication it guards must not interleave.
|
|
205
|
+
const run = onboardingSetupQueue.then(async () => {
|
|
206
|
+
if (onboardingConfigured())
|
|
207
|
+
throw new FleetError('conflict', 'Fleet is already set up; change its models in the configuration');
|
|
208
|
+
try {
|
|
209
|
+
await setup({ subscriptions, assignmentStrategy: oneModel ? 'one-model' : 'per-job', models, reasoning: 'balanced' });
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
throw new FleetError('backend_failure', `Fleet setup did not complete: ${error.message}`);
|
|
213
|
+
}
|
|
214
|
+
// Setup preserves files it finds, so confirm the published models are the ones this request chose.
|
|
215
|
+
// The prepared agents reference packaged Brain presets, so resolve what each of them now points at:
|
|
216
|
+
// a preserved file of a packaged name may hold another model, session or reasoning than its name says.
|
|
217
|
+
const published = configuration.read(true).model, brains = published.brains ?? {};
|
|
218
|
+
const brainOf = (holder) => brains[String(holder?.brain?.ref ?? '')];
|
|
219
|
+
const assigned = { coordination: brainOf(published.agents.FleetCoordinator), development: brainOf(published.agent_templates?.Developer), review: brainOf(published.agent_templates?.Critic) };
|
|
220
|
+
for (const work of ONBOARDING_WORK)
|
|
221
|
+
if (assigned[work]?.harness !== models[work].harness || assigned[work]?.model !== models[work].model || assigned[work]?.session !== models[work].session || assigned[work]?.effort !== 'medium')
|
|
222
|
+
throw new FleetError('conflict', 'Fleet was set up with different models; review its configuration');
|
|
223
|
+
return { configured: true };
|
|
224
|
+
});
|
|
225
|
+
onboardingSetupQueue = run.catch(() => { });
|
|
226
|
+
return run;
|
|
227
|
+
});
|
|
109
228
|
app.get('/api/v1/creation-capabilities', async (request) => {
|
|
110
229
|
auth.authenticate(request);
|
|
111
230
|
return services.creation.capabilities();
|
|
@@ -128,7 +247,8 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
128
247
|
});
|
|
129
248
|
app.get('/api/v1/roles', async (request) => {
|
|
130
249
|
auth.authenticate(request);
|
|
131
|
-
|
|
250
|
+
const query = request.query;
|
|
251
|
+
return { roles: await services.query.list(query.includeTemporary === 'true') };
|
|
132
252
|
});
|
|
133
253
|
const taskApi = async (fn) => {
|
|
134
254
|
try {
|
|
@@ -141,6 +261,8 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
141
261
|
? 'conflict' : 'invalid_request';
|
|
142
262
|
throw new FleetError(code, error.message);
|
|
143
263
|
}
|
|
264
|
+
if (error instanceof TaskStateError && 'accepted' in error && error.accepted === false)
|
|
265
|
+
return Promise.reject(Object.assign(new FleetError('invalid_request', error.message), { memberNotAccepted: true }));
|
|
144
266
|
if (error instanceof TaskStateError) {
|
|
145
267
|
throw new FleetError(error.message.startsWith('task not found:') ? 'resource_not_found' : 'conflict', error.message);
|
|
146
268
|
}
|
|
@@ -188,9 +310,10 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
188
310
|
const state = query.state && query.state !== 'all' ? query.state : undefined;
|
|
189
311
|
const filter = { ...(state ? { state } : {}), ...(query.list ? { list: query.list } : {}),
|
|
190
312
|
...(query.includeDeleting === 'true' ? { includeDeleting: true } : {}) };
|
|
313
|
+
const api = requireTaskRooms();
|
|
191
314
|
return taskApi(() => query.groupByList === 'true'
|
|
192
|
-
? { groups:
|
|
193
|
-
: { tasks:
|
|
315
|
+
? { groups: api.groupedTasks(filter).map(group => ({ ...group, tasks: group.tasks.map(task => api.withLayoutRooms(task)) })) }
|
|
316
|
+
: { tasks: api.listTasks(filter).map(task => api.withLayoutRooms(task)) });
|
|
194
317
|
});
|
|
195
318
|
app.delete('/api/v1/tasks/:id', async (request, reply) => {
|
|
196
319
|
auth.authenticate(request, true);
|
|
@@ -221,12 +344,17 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
221
344
|
const body = request.body;
|
|
222
345
|
if (typeof body?.title !== 'string' || !body.title)
|
|
223
346
|
throw new FleetError('invalid_request', 'title is required');
|
|
347
|
+
// Every task runs a saved Room Layout; rooms are never defined inline or from room templates here.
|
|
348
|
+
if (typeof body.layout !== 'string' || !body.layout)
|
|
349
|
+
throw new FleetError('invalid_request', 'layout is required: choose a room layout from Settings › Room layouts');
|
|
350
|
+
if (body.template !== undefined || body.noRoom !== undefined)
|
|
351
|
+
throw new FleetError('invalid_request', 'tasks use room layouts; template and noRoom are not accepted');
|
|
224
352
|
const task = await taskApi(() => requireTaskRooms().createTask({
|
|
225
353
|
actor: { kind: 'local_control', surface: 'web' }, title: body.title,
|
|
226
354
|
brief: typeof body.brief === 'string' ? body.brief : undefined,
|
|
227
|
-
|
|
228
|
-
backlog: body.backlog === true, noRoom: body.noRoom === true,
|
|
355
|
+
backlog: body.backlog === true,
|
|
229
356
|
list: typeof body.list === 'string' ? body.list : undefined,
|
|
357
|
+
layout: body.layout,
|
|
230
358
|
idempotencyKey: typeof request.headers['idempotency-key'] === 'string'
|
|
231
359
|
? request.headers['idempotency-key'] : undefined,
|
|
232
360
|
origin: { type: 'web' },
|
|
@@ -240,11 +368,162 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
240
368
|
const list = String(request.body?.list ?? '');
|
|
241
369
|
return { task: await taskApi(() => requireTaskRooms().moveTask({ actor: { kind: 'local_control', surface: 'web' }, taskId, list })) };
|
|
242
370
|
});
|
|
371
|
+
app.patch('/api/v1/tasks/:id/description', async (request) => {
|
|
372
|
+
auth.authenticate(request, true);
|
|
373
|
+
const body = request.body;
|
|
374
|
+
if (typeof body?.brief !== 'string' || typeof body.expectedBrief !== 'string' || body.brief.length > 100_000)
|
|
375
|
+
throw new FleetError('invalid_request', 'brief and expectedBrief must be strings; brief maximum is 100000 characters');
|
|
376
|
+
return { task: await taskApi(() => requireTaskRooms().editTaskDescription({
|
|
377
|
+
actor: { kind: 'local_control', surface: 'web' }, taskId: request.params.id,
|
|
378
|
+
brief: body.brief, expectedBrief: body.expectedBrief,
|
|
379
|
+
})) };
|
|
380
|
+
});
|
|
381
|
+
app.get('/api/v1/tasks/:id', async (request) => {
|
|
382
|
+
auth.authenticate(request);
|
|
383
|
+
return taskApi(() => requireTaskRooms().getTask(request.params.id));
|
|
384
|
+
});
|
|
385
|
+
app.post('/api/v1/tasks/:id/members', async (request, reply) => {
|
|
386
|
+
auth.authenticate(request, true);
|
|
387
|
+
const body = request.body;
|
|
388
|
+
try {
|
|
389
|
+
const result = await taskApi(() => requireTaskRooms().addMember(request.params.id, body));
|
|
390
|
+
reply.code(result.state === 'running' ? 202 : 200);
|
|
391
|
+
return result;
|
|
392
|
+
}
|
|
393
|
+
catch (error) {
|
|
394
|
+
if (error instanceof Error && 'memberNotAccepted' in error)
|
|
395
|
+
return reply.code(409).send({ error: { code: 'member_not_accepted', message: error.message }, accepted: false });
|
|
396
|
+
throw error;
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
app.get('/api/v1/tasks/:id/member-additions/:requestId', async (request) => {
|
|
400
|
+
auth.authenticate(request);
|
|
401
|
+
const { id, requestId } = request.params;
|
|
402
|
+
return taskApi(() => requireTaskRooms().memberAddition(id, requestId));
|
|
403
|
+
});
|
|
404
|
+
app.patch('/api/v1/tasks/:id/layout', async (request) => {
|
|
405
|
+
const session = auth.authenticate(request, true);
|
|
406
|
+
const body = request.body;
|
|
407
|
+
const name = (v) => typeof v === 'string' && v.length > 0;
|
|
408
|
+
if (!name(body?.layout) || !(body.expectedLayout === null || name(body.expectedLayout)))
|
|
409
|
+
throw new FleetError('invalid_request', 'layout must be a layout name; expectedLayout a layout name or null');
|
|
410
|
+
const task = await taskApi(() => requireTaskRooms().setTaskLayout({ actor: { kind: 'local_control', surface: 'web' },
|
|
411
|
+
taskId: request.params.id, layout: body.layout, expectedLayout: body.expectedLayout }));
|
|
412
|
+
await audit.record({ requestId: request.id, browser: session.id, action: 'task.layout.set', result: 'succeeded' });
|
|
413
|
+
return { task: requireTaskRooms().withLayoutRooms(task) };
|
|
414
|
+
});
|
|
415
|
+
app.get('/api/v1/tasks/:id/layout', async (request) => {
|
|
416
|
+
auth.authenticate(request);
|
|
417
|
+
return { layout: await taskApi(async () => requireTaskRooms().taskLayout(request.params.id)) };
|
|
418
|
+
});
|
|
419
|
+
for (const operation of ['open', 'close']) {
|
|
420
|
+
app.post(`/api/v1/tasks/:id/layout/rooms/:room/${operation}`, async (request, reply) => {
|
|
421
|
+
const session = auth.authenticate(request, true);
|
|
422
|
+
const { id, room } = request.params;
|
|
423
|
+
const accepted = await taskApi(() => requireTaskRooms().launchTaskLayoutOperation({
|
|
424
|
+
actor: { kind: 'local_control', surface: 'web' }, taskId: id, room,
|
|
425
|
+
operation: operation === 'open' ? 'open' : 'close-room',
|
|
426
|
+
}));
|
|
427
|
+
await audit.record({ requestId: request.id, browser: session.id, action: `task.layout.${operation}`, result: 'succeeded' });
|
|
428
|
+
reply.code(202);
|
|
429
|
+
return { operation: accepted };
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
app.post('/api/v1/tasks/:id/layout/cleanup', async (request, reply) => {
|
|
433
|
+
auth.authenticate(request, true);
|
|
434
|
+
const accepted = await taskApi(() => requireTaskRooms().retryTaskLayoutCleanup({
|
|
435
|
+
actor: { kind: 'local_control', surface: 'web' }, taskId: request.params.id,
|
|
436
|
+
}));
|
|
437
|
+
reply.code(202);
|
|
438
|
+
return { operation: accepted };
|
|
439
|
+
});
|
|
440
|
+
app.get('/api/v1/task-templates', async (request) => {
|
|
441
|
+
auth.authenticate(request);
|
|
442
|
+
return { templates: requireTaskRooms().listTemplates() };
|
|
443
|
+
});
|
|
444
|
+
const layouts = () => {
|
|
445
|
+
if (!services.roomLayouts)
|
|
446
|
+
throw new FleetError('capability_unavailable', 'room layout editing is unavailable');
|
|
447
|
+
return services.roomLayouts;
|
|
448
|
+
};
|
|
449
|
+
app.get('/api/v1/room-layouts', async (request) => {
|
|
450
|
+
auth.authenticate(request);
|
|
451
|
+
const list = layouts().list(), defaultLayout = layouts().defaultLayout(list);
|
|
452
|
+
return { layouts: list, ...(defaultLayout ? { default_layout: defaultLayout } : {}) };
|
|
453
|
+
});
|
|
454
|
+
app.post('/api/v1/room-layouts/validate', async (request) => {
|
|
455
|
+
auth.authenticate(request, true);
|
|
456
|
+
return layouts().validate(request.body?.definition);
|
|
457
|
+
});
|
|
458
|
+
app.put('/api/v1/room-layouts/:name', async (request) => {
|
|
459
|
+
const session = auth.authenticate(request, true);
|
|
460
|
+
const body = request.body;
|
|
461
|
+
if (typeof body?.revision !== 'string')
|
|
462
|
+
throw new FleetError('invalid_request', 'revision is required');
|
|
463
|
+
const result = await layouts().save(request.params.name, body.revision, body.definition);
|
|
464
|
+
events.publish('room_layouts.changed', { name: result.name, revision: result.revision });
|
|
465
|
+
await audit.record({ requestId: request.id, browser: session.id, action: 'room_layout.save', result: 'succeeded' });
|
|
466
|
+
return result;
|
|
467
|
+
});
|
|
468
|
+
app.delete('/api/v1/room-layouts/:name', async (request) => {
|
|
469
|
+
const session = auth.authenticate(request, true);
|
|
470
|
+
const revision = request.query.revision;
|
|
471
|
+
if (typeof revision !== 'string' || !revision)
|
|
472
|
+
throw new FleetError('invalid_request', 'revision is required');
|
|
473
|
+
const result = await layouts().remove(request.params.name, revision);
|
|
474
|
+
events.publish('room_layouts.changed', { name: result.name });
|
|
475
|
+
await audit.record({ requestId: request.id, browser: session.id, action: 'room_layout.delete', result: 'succeeded' });
|
|
476
|
+
return result;
|
|
477
|
+
});
|
|
478
|
+
for (const action of ['start', 'block', 'unblock', 'review', 'finish', 'cancel']) {
|
|
479
|
+
app.post(`/api/v1/tasks/:id/${action}`, async (request, reply) => {
|
|
480
|
+
auth.authenticate(request, true);
|
|
481
|
+
const taskId = request.params.id;
|
|
482
|
+
const body = (request.body ?? {});
|
|
483
|
+
const input = { actor: { kind: 'local_control', surface: 'web' }, taskId };
|
|
484
|
+
const api = requireTaskRooms();
|
|
485
|
+
return taskApi(async () => {
|
|
486
|
+
switch (action) {
|
|
487
|
+
case 'start': {
|
|
488
|
+
// A task's layout can be chosen or changed but never removed, so this check cannot go stale.
|
|
489
|
+
if (!api.getTask(taskId).task.layout)
|
|
490
|
+
throw new FleetError('conflict', 'choose a room layout for this task before starting it');
|
|
491
|
+
const task = await api.startTask(input);
|
|
492
|
+
const provisioning = await api.launchTaskProvisioning(taskId);
|
|
493
|
+
if (provisioning.kind !== 'ready')
|
|
494
|
+
reply.code(202);
|
|
495
|
+
return { task, provisioning };
|
|
496
|
+
}
|
|
497
|
+
case 'block':
|
|
498
|
+
if (typeof body.reason !== 'string' || !body.reason.trim())
|
|
499
|
+
throw new FleetError('invalid_request', 'reason is required');
|
|
500
|
+
return { task: api.blockTask({ ...input, reason: body.reason }) };
|
|
501
|
+
case 'unblock': return { task: api.unblockTask(input) };
|
|
502
|
+
case 'review': return { task: api.reviewTask(input) };
|
|
503
|
+
case 'finish':
|
|
504
|
+
case 'cancel': {
|
|
505
|
+
const plan = action === 'finish' ? await api.finishTask(input) : await api.cancelTask(input);
|
|
506
|
+
const task = plan.settlementRequired ? await api.launchTaskSettlement(taskId) : plan.task;
|
|
507
|
+
const pending = task.terminal_intent?.status === 'pending';
|
|
508
|
+
if (pending)
|
|
509
|
+
reply.code(202);
|
|
510
|
+
return { task, pending };
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
app.get('/api/v1/configuration/provenance', async (request) => {
|
|
517
|
+
auth.authenticate(request);
|
|
518
|
+
if (!services.presetProvenance)
|
|
519
|
+
throw new FleetError('capability_unavailable', 'preset provenance is unavailable');
|
|
520
|
+
return { provenance: services.presetProvenance.read() };
|
|
521
|
+
});
|
|
243
522
|
app.get('/api/v1/configuration', async (request) => {
|
|
244
523
|
auth.authenticate(request);
|
|
245
524
|
if (!services.configuration)
|
|
246
525
|
throw new FleetError('capability_unavailable', 'fleet configuration editing is unavailable');
|
|
247
|
-
return services.configuration.read();
|
|
526
|
+
return services.configuration.read(request.query.includeDefinitions === 'true');
|
|
248
527
|
});
|
|
249
528
|
app.post('/api/v1/configuration/preview', async (request) => {
|
|
250
529
|
auth.authenticate(request, true);
|
|
@@ -265,6 +544,86 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
265
544
|
});
|
|
266
545
|
return result;
|
|
267
546
|
});
|
|
547
|
+
// Claude Code / Codex subscription profiles. Responses carry account metadata
|
|
548
|
+
// only; token values never leave the CLI-owned credential files.
|
|
549
|
+
const subscriptions = () => {
|
|
550
|
+
if (!services.subscriptions)
|
|
551
|
+
throw new FleetError('capability_unavailable', 'subscription management is unavailable');
|
|
552
|
+
return services.subscriptions;
|
|
553
|
+
};
|
|
554
|
+
const provider = (raw) => {
|
|
555
|
+
if (!isProvider(raw))
|
|
556
|
+
throw new FleetError('invalid_request', 'unknown subscription provider');
|
|
557
|
+
return raw;
|
|
558
|
+
};
|
|
559
|
+
const subscriptionsChanged = () => events.publish('subscription.changed', {});
|
|
560
|
+
app.get('/api/v1/subscriptions', async (request) => {
|
|
561
|
+
auth.authenticate(request);
|
|
562
|
+
return { providers: await subscriptions().list() };
|
|
563
|
+
});
|
|
564
|
+
app.post('/api/v1/subscriptions/:provider/logins', async (request, reply) => {
|
|
565
|
+
const session = auth.authenticate(request, true);
|
|
566
|
+
const login = await subscriptions().startLogin(provider(request.params.provider), session.id);
|
|
567
|
+
await audit.record({ requestId: request.id, browser: session.id, action: `subscription.login.${request.params.provider}`, result: login.state });
|
|
568
|
+
reply.code(201);
|
|
569
|
+
return login;
|
|
570
|
+
});
|
|
571
|
+
app.get('/api/v1/subscriptions/:provider/logins/:loginId', async (request) => {
|
|
572
|
+
const session = auth.authenticate(request);
|
|
573
|
+
return subscriptions().login(request.params.loginId, session.id).view();
|
|
574
|
+
});
|
|
575
|
+
app.post('/api/v1/subscriptions/:provider/logins/:loginId/code', async (request) => {
|
|
576
|
+
const session = auth.authenticate(request, true);
|
|
577
|
+
const code = request.body?.code;
|
|
578
|
+
if (typeof code !== 'string')
|
|
579
|
+
throw new FleetError('invalid_request', 'code is required');
|
|
580
|
+
const login = subscriptions().login(request.params.loginId, session.id);
|
|
581
|
+
login.submitCode(code.trim());
|
|
582
|
+
await audit.record({ requestId: request.id, browser: session.id, action: `subscription.login.code.${request.params.provider}`, result: 'submitted' });
|
|
583
|
+
return login.view();
|
|
584
|
+
});
|
|
585
|
+
app.delete('/api/v1/subscriptions/:provider/logins/:loginId', async (request) => {
|
|
586
|
+
const session = auth.authenticate(request, true);
|
|
587
|
+
const login = subscriptions().login(request.params.loginId, session.id);
|
|
588
|
+
login.cancel();
|
|
589
|
+
return login.view();
|
|
590
|
+
});
|
|
591
|
+
app.post('/api/v1/subscriptions/:provider/active', async (request) => {
|
|
592
|
+
const session = auth.authenticate(request, true);
|
|
593
|
+
const profileId = request.body?.profileId;
|
|
594
|
+
if (typeof profileId !== 'string')
|
|
595
|
+
throw new FleetError('invalid_request', 'profileId is required');
|
|
596
|
+
const view = await subscriptions().setActive(provider(request.params.provider), profileId);
|
|
597
|
+
subscriptionsChanged();
|
|
598
|
+
await audit.record({ requestId: request.id, browser: session.id, action: `subscription.activate.${request.params.provider}`, result: 'succeeded' });
|
|
599
|
+
return view;
|
|
600
|
+
});
|
|
601
|
+
app.post('/api/v1/subscriptions/:provider/profiles/:profileId/check', async (request) => {
|
|
602
|
+
auth.authenticate(request, true);
|
|
603
|
+
return subscriptions().check(provider(request.params.provider), request.params.profileId);
|
|
604
|
+
});
|
|
605
|
+
app.post('/api/v1/subscriptions/claude/profiles/:profileId/probe', async (request) => {
|
|
606
|
+
const session = auth.authenticate(request, true);
|
|
607
|
+
const usage = await subscriptions().probeClaudeUsage(request.params.profileId);
|
|
608
|
+
await audit.record({ requestId: request.id, browser: session.id, action: 'subscription.usage.probe.claude', result: usage.source });
|
|
609
|
+
return { usage };
|
|
610
|
+
});
|
|
611
|
+
app.patch('/api/v1/subscriptions/:provider/profiles/:profileId', async (request) => {
|
|
612
|
+
auth.authenticate(request, true);
|
|
613
|
+
const label = request.body?.label;
|
|
614
|
+
if (typeof label !== 'string')
|
|
615
|
+
throw new FleetError('invalid_request', 'label is required');
|
|
616
|
+
await subscriptions().rename(provider(request.params.provider), request.params.profileId, label);
|
|
617
|
+
subscriptionsChanged();
|
|
618
|
+
return { ok: true };
|
|
619
|
+
});
|
|
620
|
+
app.delete('/api/v1/subscriptions/:provider/profiles/:profileId', async (request) => {
|
|
621
|
+
const session = auth.authenticate(request, true);
|
|
622
|
+
await subscriptions().remove(provider(request.params.provider), request.params.profileId);
|
|
623
|
+
subscriptionsChanged();
|
|
624
|
+
await audit.record({ requestId: request.id, browser: session.id, action: `subscription.remove.${request.params.provider}`, result: 'succeeded' });
|
|
625
|
+
return { ok: true };
|
|
626
|
+
});
|
|
268
627
|
app.get('/api/v1/topology', async (request) => {
|
|
269
628
|
auth.authenticate(request);
|
|
270
629
|
if (!services.topology)
|
|
@@ -311,9 +670,41 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
311
670
|
});
|
|
312
671
|
return result;
|
|
313
672
|
});
|
|
673
|
+
const oursTools = services.oursTools ?? new SupervisorOursTools();
|
|
674
|
+
app.get('/api/v1/roles/:id/contacts', async (request) => {
|
|
675
|
+
auth.authenticate(request);
|
|
676
|
+
const control = await services.session(request.params.id);
|
|
677
|
+
if (!control.agentContacts)
|
|
678
|
+
throw new FleetError('capability_unavailable', 'Supervisor contacts API is unavailable');
|
|
679
|
+
return control.agentContacts();
|
|
680
|
+
});
|
|
681
|
+
app.get('/api/v1/roles/:id/messages', async (request) => {
|
|
682
|
+
auth.authenticate(request);
|
|
683
|
+
const control = await services.session(request.params.id);
|
|
684
|
+
if (!control.agentHistory)
|
|
685
|
+
throw new FleetError('capability_unavailable', 'Supervisor history API is unavailable');
|
|
686
|
+
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) } : {}) });
|
|
687
|
+
});
|
|
688
|
+
app.get('/api/v1/roles/:id/ours/tools', async (request) => {
|
|
689
|
+
auth.authenticate(request);
|
|
690
|
+
return oursTools.list(request.params.id);
|
|
691
|
+
});
|
|
692
|
+
app.post('/api/v1/roles/:id/ours/call', async (request) => {
|
|
693
|
+
const session = auth.authenticate(request, true);
|
|
694
|
+
const result = await oursTools.call(request.params.id, request.body);
|
|
695
|
+
await audit.record({ requestId: request.id, browser: session.id,
|
|
696
|
+
action: 'ours.call', result: result.result.isError === true ? 'tool_error' : 'succeeded' });
|
|
697
|
+
return result;
|
|
698
|
+
});
|
|
314
699
|
app.get('/api/v1/roles/:id', async (request) => {
|
|
315
700
|
auth.authenticate(request);
|
|
316
|
-
|
|
701
|
+
const detail = await services.query.detail(request.params.id);
|
|
702
|
+
return { ...detail, chatIdle: detail.role.lifetime === 'temporary' ? readChatIdle(agentDir(request.params.id, true)) ?? null : null };
|
|
703
|
+
});
|
|
704
|
+
app.get('/api/v1/roles/:id/voice-capabilities', async (request) => {
|
|
705
|
+
auth.authenticate(request);
|
|
706
|
+
const descriptor = await (await services.session(request.params.id)).describe();
|
|
707
|
+
return { supported: ['generation_bound_prompts', 'idle_bound_prompts', 'targeted_voice_interrupt'].every(f => descriptor.features.includes(f)) };
|
|
317
708
|
});
|
|
318
709
|
app.get('/api/v1/roles/:id/removal-preview', async (request) => {
|
|
319
710
|
auth.authenticate(request);
|
|
@@ -348,15 +739,81 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
348
739
|
const control = await services.session(request.params.id);
|
|
349
740
|
if (!control.conversationPage)
|
|
350
741
|
throw new FleetError('capability_unavailable', 'this role has no conversation ledger');
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
742
|
+
const limit = request.query.limit ? Number(request.query.limit) : undefined;
|
|
743
|
+
// `latest` / `before` page backwards from the newest event; `after` pages forward for live updates.
|
|
744
|
+
const backward = request.query.latest === '1' || request.query.before !== undefined;
|
|
745
|
+
if (backward && request.query.after !== undefined)
|
|
746
|
+
throw new FleetError('invalid_request', 'after cannot be combined with latest or before');
|
|
747
|
+
if (backward && !control.conversationTail)
|
|
748
|
+
throw new FleetError('capability_unavailable', 'this role cannot page its conversation backwards');
|
|
749
|
+
const role = await services.repository.get(request.params.id);
|
|
750
|
+
const stateDir = role ? services.repository.stateDir(role) : undefined;
|
|
751
|
+
const present = (event) => presentAttachmentEvent(stateDir, request.params.id, event);
|
|
752
|
+
if (backward) {
|
|
753
|
+
const page = await control.conversationTail({ before: request.query.before, limit });
|
|
754
|
+
return { ...page, events: page.events.map(present), context: page.context.map(present) };
|
|
755
|
+
}
|
|
756
|
+
const page = await control.conversationPage({ after: request.query.after, limit });
|
|
757
|
+
return { ...page, events: page.events.map(present) };
|
|
758
|
+
});
|
|
759
|
+
app.get('/api/v1/roles/:id/attachments/:attachmentId', async (request, reply) => {
|
|
760
|
+
auth.authenticate(request);
|
|
761
|
+
const role = await services.repository.get(request.params.id);
|
|
762
|
+
if (!role)
|
|
763
|
+
throw new FleetError('role_not_found', 'Agent not found');
|
|
764
|
+
const stateDir = services.repository.stateDir(role);
|
|
765
|
+
if (!stateDir)
|
|
766
|
+
throw new FleetError('capability_unavailable', 'Agent file storage is unavailable');
|
|
767
|
+
const { record, bytes } = readAgentAttachment(stateDir, request.params.attachmentId);
|
|
768
|
+
const image = /^image\/(png|jpeg|gif|webp|avif)$/.test(record.mimeType);
|
|
769
|
+
reply.header('Cache-Control', 'private, no-store');
|
|
770
|
+
reply.header('X-Content-Type-Options', 'nosniff');
|
|
771
|
+
reply.header('Content-Security-Policy', "default-src 'none'; sandbox");
|
|
772
|
+
reply.header('Content-Disposition', `${image ? 'inline' : 'attachment'}; filename*=UTF-8''${encodeURIComponent(record.name).replace(/'/g, '%27')}`);
|
|
773
|
+
return reply.type(image ? record.mimeType : 'application/octet-stream').send(bytes);
|
|
774
|
+
});
|
|
775
|
+
app.post('/api/v1/roles/:id/attachments', { bodyLimit: MAX_ATTACHMENT_BODY }, async (request) => {
|
|
776
|
+
auth.authenticate(request, true);
|
|
777
|
+
const role = await services.repository.get(request.params.id);
|
|
778
|
+
if (!role)
|
|
779
|
+
throw new FleetError('role_not_found', 'Agent not found');
|
|
780
|
+
const stateDir = services.repository.stateDir(role);
|
|
781
|
+
if (!stateDir)
|
|
782
|
+
throw new FleetError('capability_unavailable', 'Agent file storage is unavailable');
|
|
783
|
+
const body = request.body;
|
|
784
|
+
if (typeof body?.expectedSessionGeneration !== 'string' || !body.expectedSessionGeneration.trim())
|
|
785
|
+
throw new FleetError('invalid_request', 'expectedSessionGeneration is required for attachments');
|
|
786
|
+
const control = await services.session(request.params.id);
|
|
787
|
+
if (!control.conversationPage || !control.submitPromptV2)
|
|
788
|
+
throw new FleetError('capability_unavailable', 'Session-bound attachments are unavailable');
|
|
789
|
+
const page = await control.conversationPage({ limit: 1 });
|
|
790
|
+
if (page.snapshot.sessionGeneration !== body.expectedSessionGeneration)
|
|
791
|
+
throw new FleetError('stale_state', 'Agent session changed. Select the files again.');
|
|
792
|
+
return storeAgentAttachment(stateDir, body.expectedSessionGeneration, request.body);
|
|
355
793
|
});
|
|
356
794
|
app.post('/api/v1/roles/:id/input', async (request, reply) => {
|
|
357
795
|
const session = auth.authenticate(request, true);
|
|
358
796
|
const body = request.body;
|
|
359
|
-
|
|
797
|
+
if (body?.expectedSessionGeneration !== undefined && (typeof body.expectedSessionGeneration !== 'string' || !body.expectedSessionGeneration.trim()))
|
|
798
|
+
throw new FleetError('invalid_request', 'expectedSessionGeneration must be a nonempty string');
|
|
799
|
+
if (body?.requireIdle !== undefined && typeof body.requireIdle !== 'boolean')
|
|
800
|
+
throw new FleetError('invalid_request', 'requireIdle must be boolean');
|
|
801
|
+
let text = String(body?.text ?? '');
|
|
802
|
+
if (body?.attachments !== undefined) {
|
|
803
|
+
if (typeof body.commandId !== 'string' || !body.commandId.trim())
|
|
804
|
+
throw new FleetError('invalid_request', 'commandId is required for attachments');
|
|
805
|
+
if (typeof body.expectedSessionGeneration !== 'string' || !body.expectedSessionGeneration.trim())
|
|
806
|
+
throw new FleetError('invalid_request', 'expectedSessionGeneration is required for attachments');
|
|
807
|
+
const role = await services.repository.get(request.params.id);
|
|
808
|
+
if (!role)
|
|
809
|
+
throw new FleetError('role_not_found', 'Agent not found');
|
|
810
|
+
const stateDir = services.repository.stateDir(role);
|
|
811
|
+
if (!stateDir)
|
|
812
|
+
throw new FleetError('capability_unavailable', 'Agent file storage is unavailable');
|
|
813
|
+
const originalText = text;
|
|
814
|
+
text = attachmentPrompt(stateDir, body.expectedSessionGeneration, body.attachments, text);
|
|
815
|
+
prepareAttachmentPresentation(stateDir, body.expectedSessionGeneration, body.commandId, body.attachments, originalText, text);
|
|
816
|
+
}
|
|
360
817
|
const commandId = typeof body?.commandId === 'string' && body.commandId.trim()
|
|
361
818
|
? body.commandId : undefined;
|
|
362
819
|
const control = await services.session(request.params.id);
|
|
@@ -367,6 +824,7 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
367
824
|
const admittedCommandId = commandId ?? randomBytes(16).toString('hex');
|
|
368
825
|
const receipt = await control.submitPromptV2({
|
|
369
826
|
commandId: admittedCommandId, text, source: 'owner_admin_console',
|
|
827
|
+
expectedSessionGeneration: body.expectedSessionGeneration, requireIdle: body.requireIdle === true,
|
|
370
828
|
actorBrowserSession: createHmac('sha256', digestKey).update(session.id).digest('hex').slice(0, 24),
|
|
371
829
|
});
|
|
372
830
|
await audit.record({
|
|
@@ -378,6 +836,8 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
378
836
|
reply.code(202);
|
|
379
837
|
return receipt;
|
|
380
838
|
}
|
|
839
|
+
if (body.expectedSessionGeneration !== undefined || body.requireIdle)
|
|
840
|
+
throw new FleetError('capability_unavailable', 'session-bound voice input is unavailable for this role');
|
|
381
841
|
const receipt = await control.sendText(text);
|
|
382
842
|
await audit.record({
|
|
383
843
|
requestId: request.id, browser: session.id, roleId: request.params.id,
|
|
@@ -393,6 +853,16 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
393
853
|
const commandId = typeof body?.commandId === 'string' && body.commandId.trim()
|
|
394
854
|
? body.commandId : undefined;
|
|
395
855
|
const control = await services.session(request.params.id);
|
|
856
|
+
if (body?.expectedSessionGeneration !== undefined || body?.promptId !== undefined) {
|
|
857
|
+
if (!commandId || typeof body.expectedSessionGeneration !== 'string' || !body.expectedSessionGeneration.trim() || typeof body.promptId !== 'string' || !body.promptId.trim())
|
|
858
|
+
throw new FleetError('invalid_request', 'Targeted interrupt requires commandId, expectedSessionGeneration and promptId');
|
|
859
|
+
if (!control.interruptPromptV2)
|
|
860
|
+
throw new FleetError('capability_unavailable', 'Targeted voice interrupt is unavailable');
|
|
861
|
+
const receipt = await control.interruptPromptV2({ commandId, expectedSessionGeneration: body.expectedSessionGeneration, promptId: body.promptId });
|
|
862
|
+
await audit.record({ requestId: request.id, browser: session.id, roleId: request.params.id, action: 'session.interrupt_voice', result: 'accepted' });
|
|
863
|
+
reply.code(202);
|
|
864
|
+
return receipt;
|
|
865
|
+
}
|
|
396
866
|
if (commandId && control.interruptV2) {
|
|
397
867
|
const receipt = await control.interruptV2(commandId);
|
|
398
868
|
await audit.record({
|
|
@@ -443,10 +913,22 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
443
913
|
const body = request.body;
|
|
444
914
|
if (!body.action || !['start', 'stop', 'restart_resume', 'restart_fresh'].includes(body.action))
|
|
445
915
|
throw new FleetError('invalid_request', 'invalid lifecycle action');
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
916
|
+
let receipt;
|
|
917
|
+
try {
|
|
918
|
+
receipt = await services.commands.execute({
|
|
919
|
+
roleId: request.params.id, action: body.action,
|
|
920
|
+
actionId: body.actionId, confirmation: body.confirmation,
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
catch (error) {
|
|
924
|
+
// An existing receipt always wins: a conflicting/repeated action is not a
|
|
925
|
+
// proof that the original operation was never admitted.
|
|
926
|
+
if (typeof body.actionId === 'string' && !services.commands.get(body.actionId)) {
|
|
927
|
+
const normalized = normalizeError(error);
|
|
928
|
+
return reply.code(409).send({ error: { code: 'action_not_accepted', message: normalized.message }, accepted: false });
|
|
929
|
+
}
|
|
930
|
+
throw error;
|
|
931
|
+
}
|
|
450
932
|
events.publish('action.changed', receipt, request.params.id);
|
|
451
933
|
reply.code(202);
|
|
452
934
|
return receipt;
|
|
@@ -465,6 +947,70 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
465
947
|
throw new FleetError('role_not_found', 'creation action not found');
|
|
466
948
|
return action;
|
|
467
949
|
});
|
|
950
|
+
// A fetch stream works through the same authenticated workspace transport as
|
|
951
|
+
// ordinary requests, and owns one ACP controller until its browser disconnects.
|
|
952
|
+
app.post('/api/v1/roles/:id/live-presence', async (request, reply) => {
|
|
953
|
+
const browser = auth.authenticate(request, true);
|
|
954
|
+
const generation = request.body?.expectedSessionGeneration;
|
|
955
|
+
if (typeof generation !== 'string' || !generation.trim())
|
|
956
|
+
throw new FleetError('invalid_request', 'expectedSessionGeneration is required');
|
|
957
|
+
const control = await services.session(request.params.id);
|
|
958
|
+
if (!control.followConversation || !control.conversationPage)
|
|
959
|
+
throw new FleetError('capability_unavailable', 'Live voice requires a conversation controller');
|
|
960
|
+
const page = await control.conversationPage({ limit: 1 });
|
|
961
|
+
if (page.snapshot.sessionGeneration !== generation)
|
|
962
|
+
throw new FleetError('stale_state', 'Agent session changed. Start live voice again.');
|
|
963
|
+
// Session/page discovery can await I/O; recheck revocation before attaching.
|
|
964
|
+
auth.authenticate(request, true);
|
|
965
|
+
if (reply.raw.destroyed)
|
|
966
|
+
return;
|
|
967
|
+
reply.hijack();
|
|
968
|
+
for (const [name, value] of Object.entries(reply.getHeaders()))
|
|
969
|
+
if (value !== undefined)
|
|
970
|
+
reply.raw.setHeader(name, Array.isArray(value) ? value : String(value));
|
|
971
|
+
reply.raw.writeHead(200, { 'Content-Type': 'application/x-ndjson', 'Cache-Control': 'no-store', 'X-Accel-Buffering': 'no' });
|
|
972
|
+
let ended = false;
|
|
973
|
+
let follow;
|
|
974
|
+
let heartbeat;
|
|
975
|
+
let unbind;
|
|
976
|
+
const close = () => { if (ended)
|
|
977
|
+
return; ended = true; unbind?.(); if (heartbeat)
|
|
978
|
+
clearInterval(heartbeat); follow?.close(); reply.raw.end(); };
|
|
979
|
+
const write = (value) => { if (!ended && !reply.raw.write(JSON.stringify(value) + '\n'))
|
|
980
|
+
close(); };
|
|
981
|
+
reply.raw.once('close', close);
|
|
982
|
+
unbind = auth.bindTransport(browser.id, close);
|
|
983
|
+
try {
|
|
984
|
+
follow = await control.followConversation({
|
|
985
|
+
after: page.nextCursor,
|
|
986
|
+
onPage: current => { if (current.snapshot.sessionGeneration !== generation) {
|
|
987
|
+
write({ error: 'Agent session changed. Start live voice again.' });
|
|
988
|
+
close();
|
|
989
|
+
}
|
|
990
|
+
else
|
|
991
|
+
write({ ready: true }); },
|
|
992
|
+
onEvent: event => { if (event.sessionGeneration !== generation) {
|
|
993
|
+
write({ error: 'Agent session changed. Start live voice again.' });
|
|
994
|
+
close();
|
|
995
|
+
} },
|
|
996
|
+
onClose: () => close(),
|
|
997
|
+
});
|
|
998
|
+
if (ended)
|
|
999
|
+
follow.close();
|
|
1000
|
+
else
|
|
1001
|
+
heartbeat = setInterval(() => { try {
|
|
1002
|
+
auth.authenticate(request);
|
|
1003
|
+
write({ heartbeat: true });
|
|
1004
|
+
}
|
|
1005
|
+
catch {
|
|
1006
|
+
close();
|
|
1007
|
+
} }, 10_000);
|
|
1008
|
+
}
|
|
1009
|
+
catch {
|
|
1010
|
+
write({ error: 'Agent controller connection failed.' });
|
|
1011
|
+
close();
|
|
1012
|
+
}
|
|
1013
|
+
});
|
|
468
1014
|
app.post('/api/v1/ws-tickets', async (request) => {
|
|
469
1015
|
const body = request.body;
|
|
470
1016
|
if (!body?.purpose || !['events', 'conversation'].includes(body.purpose))
|
|
@@ -534,6 +1080,9 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
534
1080
|
}
|
|
535
1081
|
socket.send(JSON.stringify(payload));
|
|
536
1082
|
};
|
|
1083
|
+
const role = await services.repository.get(request.params.id);
|
|
1084
|
+
const stateDir = role ? services.repository.stateDir(role) : undefined;
|
|
1085
|
+
const present = (event) => presentAttachmentEvent(stateDir, request.params.id, event);
|
|
537
1086
|
const follow = await control.followConversation({
|
|
538
1087
|
after,
|
|
539
1088
|
onPage: page => {
|
|
@@ -544,11 +1093,11 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
544
1093
|
lastCursor: page.nextCursor ?? after,
|
|
545
1094
|
});
|
|
546
1095
|
if (page.events.length)
|
|
547
|
-
guardedSend({ type: 'events', events: page.events });
|
|
1096
|
+
guardedSend({ type: 'events', events: page.events.map(present) });
|
|
548
1097
|
if (page.hasMore)
|
|
549
1098
|
guardedSend({ type: 'resync.required' });
|
|
550
1099
|
},
|
|
551
|
-
onEvent: event => guardedSend({ type: 'events', events: [event] }),
|
|
1100
|
+
onEvent: event => guardedSend({ type: 'events', events: [present(event)] }),
|
|
552
1101
|
onClose: reason => {
|
|
553
1102
|
if (socket.readyState === socket.OPEN)
|
|
554
1103
|
socket.close(4409, (reason ?? 'conversation stream ended').slice(0, 120));
|
|
@@ -561,15 +1110,8 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
561
1110
|
socket.on('close', () => { clearInterval(heartbeat); follow.close(); });
|
|
562
1111
|
});
|
|
563
1112
|
});
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
await app.register(fastifyStatic, { root: staticRoot, prefix: '/' });
|
|
567
|
-
app.setNotFoundHandler((request, reply) => {
|
|
568
|
-
if (request.url.startsWith('/api/'))
|
|
569
|
-
return reply.code(404).send({ error: 'not found' });
|
|
570
|
-
return reply.sendFile('index.html');
|
|
571
|
-
});
|
|
572
|
-
}
|
|
1113
|
+
// Fleet has no pages of its own; every screen belongs to the App.
|
|
1114
|
+
app.setNotFoundHandler((_request, reply) => reply.code(404).send({ error: 'not found' }));
|
|
573
1115
|
return {
|
|
574
1116
|
app, auth, audit, events,
|
|
575
1117
|
async close() {
|
|
@@ -582,17 +1124,17 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
582
1124
|
function setAuthCookies(reply, session, device, secure = false) {
|
|
583
1125
|
const suffix = secure ? '; Secure' : '';
|
|
584
1126
|
reply.header('Set-Cookie', [
|
|
585
|
-
`ofs_session=${encodeURIComponent(session)}; HttpOnly; SameSite=Strict; Path
|
|
586
|
-
`ofs_device=${encodeURIComponent(device)}; HttpOnly; SameSite=Strict; Path
|
|
1127
|
+
`ofs_session=${encodeURIComponent(session)}; HttpOnly; SameSite=Strict; Path=/; Max-Age=28800${suffix}`,
|
|
1128
|
+
`ofs_device=${encodeURIComponent(device)}; HttpOnly; SameSite=Strict; Path=/; Max-Age=2592000${suffix}`,
|
|
587
1129
|
]);
|
|
588
1130
|
}
|
|
589
1131
|
function setSessionCookie(reply, session, secure = false) {
|
|
590
|
-
reply.header('Set-Cookie', `ofs_session=${encodeURIComponent(session)}; HttpOnly; SameSite=Strict; Path
|
|
1132
|
+
reply.header('Set-Cookie', `ofs_session=${encodeURIComponent(session)}; HttpOnly; SameSite=Strict; Path=/; Max-Age=28800${secure ? '; Secure' : ''}`);
|
|
591
1133
|
}
|
|
592
1134
|
function clearAuthCookies(reply) {
|
|
593
1135
|
reply.header('Set-Cookie', [
|
|
594
|
-
'ofs_session=; HttpOnly; SameSite=Strict; Path
|
|
595
|
-
'ofs_device=; HttpOnly; SameSite=Strict; Path
|
|
1136
|
+
'ofs_session=; HttpOnly; SameSite=Strict; Path=/; Max-Age=0',
|
|
1137
|
+
'ofs_device=; HttpOnly; SameSite=Strict; Path=/; Max-Age=0',
|
|
596
1138
|
]);
|
|
597
1139
|
}
|
|
598
1140
|
function promoteRequest(body) {
|
|
@@ -606,9 +1148,6 @@ function promoteRequest(body) {
|
|
|
606
1148
|
};
|
|
607
1149
|
}
|
|
608
1150
|
function cryptoRandomId() { return randomBytes(12).toString('hex'); }
|
|
609
|
-
function escapeHtml(value) {
|
|
610
|
-
return value.replace(/[&<>"']/g, char => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[char]));
|
|
611
|
-
}
|
|
612
1151
|
function requireSubprotocol(request, expected) {
|
|
613
1152
|
const protocols = String(request.headers['sec-websocket-protocol'] ?? '')
|
|
614
1153
|
.split(',').map(value => value.trim());
|