@ours.network/fleet 1.2.0-nightly.5 → 1.2.0-nightly.50
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 +588 -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,79 @@ 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
|
+
const harnesses = await Promise.all(['codex', 'claude-code'].map(async (harness) => {
|
|
154
|
+
try {
|
|
155
|
+
return { harness, ...await getAdapter(harness).checkPrereqs() };
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return { harness, ok: false, checks: [{ name: 'availability', ok: false, detail: 'Harness checks unavailable' }] };
|
|
159
|
+
}
|
|
160
|
+
}));
|
|
161
|
+
const catalog = validateCatalog(JSON.parse(readFileSync(join(packagedPresetRoot(), 'brain-catalog.json'), 'utf8')));
|
|
162
|
+
// Codex models are offered only when the runtime itself listed them for the active account.
|
|
163
|
+
// When it could not be asked, none is offered and the reason is reported.
|
|
164
|
+
const codexModels = services.codexModels ? await services.codexModels() : undefined;
|
|
165
|
+
const offered = (model) => model.harness !== 'codex' || !codexModels || (codexModels.state === 'known' && codexModels.models.includes(model.model));
|
|
166
|
+
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() };
|
|
167
|
+
});
|
|
168
|
+
// First-time setup is what creates the persistent coordinator. A configuration that loads and
|
|
169
|
+
// has it is set up, whatever its brains are called; its models are then changed by editing it.
|
|
170
|
+
const onboardingConfigured = () => {
|
|
171
|
+
if (!services.configuration)
|
|
172
|
+
return false;
|
|
173
|
+
try {
|
|
174
|
+
return Boolean(services.configuration.read(false).model.agents.FleetCoordinator);
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
let onboardingSetupQueue = Promise.resolve();
|
|
181
|
+
app.post('/api/v1/onboarding/setup', async (request) => {
|
|
182
|
+
auth.authenticate(request, true);
|
|
183
|
+
if (!services.configuration || !services.onboardingSetup)
|
|
184
|
+
throw new FleetError('capability_unavailable', 'first-time Fleet setup is unavailable');
|
|
185
|
+
const requested = request.body?.models;
|
|
186
|
+
const codexModels = services.codexModels ? await services.codexModels() : undefined;
|
|
187
|
+
const supported = validateCatalog(JSON.parse(readFileSync(join(packagedPresetRoot(), 'brain-catalog.json'), 'utf8'))).models
|
|
188
|
+
.filter(model => model.harness !== 'codex' || !codexModels || (codexModels.state === 'known' && codexModels.models.includes(model.model)));
|
|
189
|
+
const models = {};
|
|
190
|
+
for (const work of ONBOARDING_WORK) {
|
|
191
|
+
const matches = supported.filter(model => model.harness === requested?.[work]?.harness && model.model === requested?.[work]?.model);
|
|
192
|
+
if (matches.length !== 1)
|
|
193
|
+
throw new FleetError('invalid_request', `choose a supported model for ${work}`);
|
|
194
|
+
models[work] = matches[0];
|
|
195
|
+
}
|
|
196
|
+
const chosen = Object.values(models);
|
|
197
|
+
const subscriptions = [...new Set(chosen.map(model => model.harness === 'codex' ? 'codex' : 'claude'))];
|
|
198
|
+
const oneModel = new Set(chosen.map(model => `${model.harness}\0${model.model}`)).size === 1;
|
|
199
|
+
const configuration = services.configuration, setup = services.onboardingSetup;
|
|
200
|
+
// One setup at a time: the first-time check and the publication it guards must not interleave.
|
|
201
|
+
const run = onboardingSetupQueue.then(async () => {
|
|
202
|
+
if (onboardingConfigured())
|
|
203
|
+
throw new FleetError('conflict', 'Fleet is already set up; change its models in the configuration');
|
|
204
|
+
try {
|
|
205
|
+
await setup({ subscriptions, assignmentStrategy: oneModel ? 'one-model' : 'per-job', models, reasoning: 'balanced' });
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
throw new FleetError('backend_failure', `Fleet setup did not complete: ${error.message}`);
|
|
209
|
+
}
|
|
210
|
+
// Setup preserves files it finds, so confirm the published models are the ones this request chose.
|
|
211
|
+
// The prepared agents reference packaged Brain presets, so resolve what each of them now points at:
|
|
212
|
+
// a preserved file of a packaged name may hold another model, session or reasoning than its name says.
|
|
213
|
+
const published = configuration.read(true).model, brains = published.brains ?? {};
|
|
214
|
+
const brainOf = (holder) => brains[String(holder?.brain?.ref ?? '')];
|
|
215
|
+
const assigned = { coordination: brainOf(published.agents.FleetCoordinator), development: brainOf(published.agent_templates?.Developer), review: brainOf(published.agent_templates?.Critic) };
|
|
216
|
+
for (const work of ONBOARDING_WORK)
|
|
217
|
+
if (assigned[work]?.harness !== models[work].harness || assigned[work]?.model !== models[work].model || assigned[work]?.session !== models[work].session || assigned[work]?.effort !== 'medium')
|
|
218
|
+
throw new FleetError('conflict', 'Fleet was set up with different models; review its configuration');
|
|
219
|
+
return { configured: true };
|
|
220
|
+
});
|
|
221
|
+
onboardingSetupQueue = run.catch(() => { });
|
|
222
|
+
return run;
|
|
223
|
+
});
|
|
109
224
|
app.get('/api/v1/creation-capabilities', async (request) => {
|
|
110
225
|
auth.authenticate(request);
|
|
111
226
|
return services.creation.capabilities();
|
|
@@ -128,7 +243,8 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
128
243
|
});
|
|
129
244
|
app.get('/api/v1/roles', async (request) => {
|
|
130
245
|
auth.authenticate(request);
|
|
131
|
-
|
|
246
|
+
const query = request.query;
|
|
247
|
+
return { roles: await services.query.list(query.includeTemporary === 'true') };
|
|
132
248
|
});
|
|
133
249
|
const taskApi = async (fn) => {
|
|
134
250
|
try {
|
|
@@ -141,6 +257,8 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
141
257
|
? 'conflict' : 'invalid_request';
|
|
142
258
|
throw new FleetError(code, error.message);
|
|
143
259
|
}
|
|
260
|
+
if (error instanceof TaskStateError && 'accepted' in error && error.accepted === false)
|
|
261
|
+
return Promise.reject(Object.assign(new FleetError('invalid_request', error.message), { memberNotAccepted: true }));
|
|
144
262
|
if (error instanceof TaskStateError) {
|
|
145
263
|
throw new FleetError(error.message.startsWith('task not found:') ? 'resource_not_found' : 'conflict', error.message);
|
|
146
264
|
}
|
|
@@ -188,9 +306,10 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
188
306
|
const state = query.state && query.state !== 'all' ? query.state : undefined;
|
|
189
307
|
const filter = { ...(state ? { state } : {}), ...(query.list ? { list: query.list } : {}),
|
|
190
308
|
...(query.includeDeleting === 'true' ? { includeDeleting: true } : {}) };
|
|
309
|
+
const api = requireTaskRooms();
|
|
191
310
|
return taskApi(() => query.groupByList === 'true'
|
|
192
|
-
? { groups:
|
|
193
|
-
: { tasks:
|
|
311
|
+
? { groups: api.groupedTasks(filter).map(group => ({ ...group, tasks: group.tasks.map(task => api.withLayoutRooms(task)) })) }
|
|
312
|
+
: { tasks: api.listTasks(filter).map(task => api.withLayoutRooms(task)) });
|
|
194
313
|
});
|
|
195
314
|
app.delete('/api/v1/tasks/:id', async (request, reply) => {
|
|
196
315
|
auth.authenticate(request, true);
|
|
@@ -221,12 +340,17 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
221
340
|
const body = request.body;
|
|
222
341
|
if (typeof body?.title !== 'string' || !body.title)
|
|
223
342
|
throw new FleetError('invalid_request', 'title is required');
|
|
343
|
+
// Every task runs a saved Room Layout; rooms are never defined inline or from room templates here.
|
|
344
|
+
if (typeof body.layout !== 'string' || !body.layout)
|
|
345
|
+
throw new FleetError('invalid_request', 'layout is required: choose a room layout from Settings › Room layouts');
|
|
346
|
+
if (body.template !== undefined || body.noRoom !== undefined)
|
|
347
|
+
throw new FleetError('invalid_request', 'tasks use room layouts; template and noRoom are not accepted');
|
|
224
348
|
const task = await taskApi(() => requireTaskRooms().createTask({
|
|
225
349
|
actor: { kind: 'local_control', surface: 'web' }, title: body.title,
|
|
226
350
|
brief: typeof body.brief === 'string' ? body.brief : undefined,
|
|
227
|
-
|
|
228
|
-
backlog: body.backlog === true, noRoom: body.noRoom === true,
|
|
351
|
+
backlog: body.backlog === true,
|
|
229
352
|
list: typeof body.list === 'string' ? body.list : undefined,
|
|
353
|
+
layout: body.layout,
|
|
230
354
|
idempotencyKey: typeof request.headers['idempotency-key'] === 'string'
|
|
231
355
|
? request.headers['idempotency-key'] : undefined,
|
|
232
356
|
origin: { type: 'web' },
|
|
@@ -240,11 +364,162 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
240
364
|
const list = String(request.body?.list ?? '');
|
|
241
365
|
return { task: await taskApi(() => requireTaskRooms().moveTask({ actor: { kind: 'local_control', surface: 'web' }, taskId, list })) };
|
|
242
366
|
});
|
|
367
|
+
app.patch('/api/v1/tasks/:id/description', async (request) => {
|
|
368
|
+
auth.authenticate(request, true);
|
|
369
|
+
const body = request.body;
|
|
370
|
+
if (typeof body?.brief !== 'string' || typeof body.expectedBrief !== 'string' || body.brief.length > 100_000)
|
|
371
|
+
throw new FleetError('invalid_request', 'brief and expectedBrief must be strings; brief maximum is 100000 characters');
|
|
372
|
+
return { task: await taskApi(() => requireTaskRooms().editTaskDescription({
|
|
373
|
+
actor: { kind: 'local_control', surface: 'web' }, taskId: request.params.id,
|
|
374
|
+
brief: body.brief, expectedBrief: body.expectedBrief,
|
|
375
|
+
})) };
|
|
376
|
+
});
|
|
377
|
+
app.get('/api/v1/tasks/:id', async (request) => {
|
|
378
|
+
auth.authenticate(request);
|
|
379
|
+
return taskApi(() => requireTaskRooms().getTask(request.params.id));
|
|
380
|
+
});
|
|
381
|
+
app.post('/api/v1/tasks/:id/members', async (request, reply) => {
|
|
382
|
+
auth.authenticate(request, true);
|
|
383
|
+
const body = request.body;
|
|
384
|
+
try {
|
|
385
|
+
const result = await taskApi(() => requireTaskRooms().addMember(request.params.id, body));
|
|
386
|
+
reply.code(result.state === 'running' ? 202 : 200);
|
|
387
|
+
return result;
|
|
388
|
+
}
|
|
389
|
+
catch (error) {
|
|
390
|
+
if (error instanceof Error && 'memberNotAccepted' in error)
|
|
391
|
+
return reply.code(409).send({ error: { code: 'member_not_accepted', message: error.message }, accepted: false });
|
|
392
|
+
throw error;
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
app.get('/api/v1/tasks/:id/member-additions/:requestId', async (request) => {
|
|
396
|
+
auth.authenticate(request);
|
|
397
|
+
const { id, requestId } = request.params;
|
|
398
|
+
return taskApi(() => requireTaskRooms().memberAddition(id, requestId));
|
|
399
|
+
});
|
|
400
|
+
app.patch('/api/v1/tasks/:id/layout', async (request) => {
|
|
401
|
+
const session = auth.authenticate(request, true);
|
|
402
|
+
const body = request.body;
|
|
403
|
+
const name = (v) => typeof v === 'string' && v.length > 0;
|
|
404
|
+
if (!name(body?.layout) || !(body.expectedLayout === null || name(body.expectedLayout)))
|
|
405
|
+
throw new FleetError('invalid_request', 'layout must be a layout name; expectedLayout a layout name or null');
|
|
406
|
+
const task = await taskApi(() => requireTaskRooms().setTaskLayout({ actor: { kind: 'local_control', surface: 'web' },
|
|
407
|
+
taskId: request.params.id, layout: body.layout, expectedLayout: body.expectedLayout }));
|
|
408
|
+
await audit.record({ requestId: request.id, browser: session.id, action: 'task.layout.set', result: 'succeeded' });
|
|
409
|
+
return { task: requireTaskRooms().withLayoutRooms(task) };
|
|
410
|
+
});
|
|
411
|
+
app.get('/api/v1/tasks/:id/layout', async (request) => {
|
|
412
|
+
auth.authenticate(request);
|
|
413
|
+
return { layout: await taskApi(async () => requireTaskRooms().taskLayout(request.params.id)) };
|
|
414
|
+
});
|
|
415
|
+
for (const operation of ['open', 'close']) {
|
|
416
|
+
app.post(`/api/v1/tasks/:id/layout/rooms/:room/${operation}`, async (request, reply) => {
|
|
417
|
+
const session = auth.authenticate(request, true);
|
|
418
|
+
const { id, room } = request.params;
|
|
419
|
+
const accepted = await taskApi(() => requireTaskRooms().launchTaskLayoutOperation({
|
|
420
|
+
actor: { kind: 'local_control', surface: 'web' }, taskId: id, room,
|
|
421
|
+
operation: operation === 'open' ? 'open' : 'close-room',
|
|
422
|
+
}));
|
|
423
|
+
await audit.record({ requestId: request.id, browser: session.id, action: `task.layout.${operation}`, result: 'succeeded' });
|
|
424
|
+
reply.code(202);
|
|
425
|
+
return { operation: accepted };
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
app.post('/api/v1/tasks/:id/layout/cleanup', async (request, reply) => {
|
|
429
|
+
auth.authenticate(request, true);
|
|
430
|
+
const accepted = await taskApi(() => requireTaskRooms().retryTaskLayoutCleanup({
|
|
431
|
+
actor: { kind: 'local_control', surface: 'web' }, taskId: request.params.id,
|
|
432
|
+
}));
|
|
433
|
+
reply.code(202);
|
|
434
|
+
return { operation: accepted };
|
|
435
|
+
});
|
|
436
|
+
app.get('/api/v1/task-templates', async (request) => {
|
|
437
|
+
auth.authenticate(request);
|
|
438
|
+
return { templates: requireTaskRooms().listTemplates() };
|
|
439
|
+
});
|
|
440
|
+
const layouts = () => {
|
|
441
|
+
if (!services.roomLayouts)
|
|
442
|
+
throw new FleetError('capability_unavailable', 'room layout editing is unavailable');
|
|
443
|
+
return services.roomLayouts;
|
|
444
|
+
};
|
|
445
|
+
app.get('/api/v1/room-layouts', async (request) => {
|
|
446
|
+
auth.authenticate(request);
|
|
447
|
+
const list = layouts().list(), defaultLayout = layouts().defaultLayout(list);
|
|
448
|
+
return { layouts: list, ...(defaultLayout ? { default_layout: defaultLayout } : {}) };
|
|
449
|
+
});
|
|
450
|
+
app.post('/api/v1/room-layouts/validate', async (request) => {
|
|
451
|
+
auth.authenticate(request, true);
|
|
452
|
+
return layouts().validate(request.body?.definition);
|
|
453
|
+
});
|
|
454
|
+
app.put('/api/v1/room-layouts/:name', async (request) => {
|
|
455
|
+
const session = auth.authenticate(request, true);
|
|
456
|
+
const body = request.body;
|
|
457
|
+
if (typeof body?.revision !== 'string')
|
|
458
|
+
throw new FleetError('invalid_request', 'revision is required');
|
|
459
|
+
const result = await layouts().save(request.params.name, body.revision, body.definition);
|
|
460
|
+
events.publish('room_layouts.changed', { name: result.name, revision: result.revision });
|
|
461
|
+
await audit.record({ requestId: request.id, browser: session.id, action: 'room_layout.save', result: 'succeeded' });
|
|
462
|
+
return result;
|
|
463
|
+
});
|
|
464
|
+
app.delete('/api/v1/room-layouts/:name', async (request) => {
|
|
465
|
+
const session = auth.authenticate(request, true);
|
|
466
|
+
const revision = request.query.revision;
|
|
467
|
+
if (typeof revision !== 'string' || !revision)
|
|
468
|
+
throw new FleetError('invalid_request', 'revision is required');
|
|
469
|
+
const result = await layouts().remove(request.params.name, revision);
|
|
470
|
+
events.publish('room_layouts.changed', { name: result.name });
|
|
471
|
+
await audit.record({ requestId: request.id, browser: session.id, action: 'room_layout.delete', result: 'succeeded' });
|
|
472
|
+
return result;
|
|
473
|
+
});
|
|
474
|
+
for (const action of ['start', 'block', 'unblock', 'review', 'finish', 'cancel']) {
|
|
475
|
+
app.post(`/api/v1/tasks/:id/${action}`, async (request, reply) => {
|
|
476
|
+
auth.authenticate(request, true);
|
|
477
|
+
const taskId = request.params.id;
|
|
478
|
+
const body = (request.body ?? {});
|
|
479
|
+
const input = { actor: { kind: 'local_control', surface: 'web' }, taskId };
|
|
480
|
+
const api = requireTaskRooms();
|
|
481
|
+
return taskApi(async () => {
|
|
482
|
+
switch (action) {
|
|
483
|
+
case 'start': {
|
|
484
|
+
// A task's layout can be chosen or changed but never removed, so this check cannot go stale.
|
|
485
|
+
if (!api.getTask(taskId).task.layout)
|
|
486
|
+
throw new FleetError('conflict', 'choose a room layout for this task before starting it');
|
|
487
|
+
const task = await api.startTask(input);
|
|
488
|
+
const provisioning = await api.launchTaskProvisioning(taskId);
|
|
489
|
+
if (provisioning.kind !== 'ready')
|
|
490
|
+
reply.code(202);
|
|
491
|
+
return { task, provisioning };
|
|
492
|
+
}
|
|
493
|
+
case 'block':
|
|
494
|
+
if (typeof body.reason !== 'string' || !body.reason.trim())
|
|
495
|
+
throw new FleetError('invalid_request', 'reason is required');
|
|
496
|
+
return { task: api.blockTask({ ...input, reason: body.reason }) };
|
|
497
|
+
case 'unblock': return { task: api.unblockTask(input) };
|
|
498
|
+
case 'review': return { task: api.reviewTask(input) };
|
|
499
|
+
case 'finish':
|
|
500
|
+
case 'cancel': {
|
|
501
|
+
const plan = action === 'finish' ? await api.finishTask(input) : await api.cancelTask(input);
|
|
502
|
+
const task = plan.settlementRequired ? await api.launchTaskSettlement(taskId) : plan.task;
|
|
503
|
+
const pending = task.terminal_intent?.status === 'pending';
|
|
504
|
+
if (pending)
|
|
505
|
+
reply.code(202);
|
|
506
|
+
return { task, pending };
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
app.get('/api/v1/configuration/provenance', async (request) => {
|
|
513
|
+
auth.authenticate(request);
|
|
514
|
+
if (!services.presetProvenance)
|
|
515
|
+
throw new FleetError('capability_unavailable', 'preset provenance is unavailable');
|
|
516
|
+
return { provenance: services.presetProvenance.read() };
|
|
517
|
+
});
|
|
243
518
|
app.get('/api/v1/configuration', async (request) => {
|
|
244
519
|
auth.authenticate(request);
|
|
245
520
|
if (!services.configuration)
|
|
246
521
|
throw new FleetError('capability_unavailable', 'fleet configuration editing is unavailable');
|
|
247
|
-
return services.configuration.read();
|
|
522
|
+
return services.configuration.read(request.query.includeDefinitions === 'true');
|
|
248
523
|
});
|
|
249
524
|
app.post('/api/v1/configuration/preview', async (request) => {
|
|
250
525
|
auth.authenticate(request, true);
|
|
@@ -265,6 +540,86 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
265
540
|
});
|
|
266
541
|
return result;
|
|
267
542
|
});
|
|
543
|
+
// Claude Code / Codex subscription profiles. Responses carry account metadata
|
|
544
|
+
// only; token values never leave the CLI-owned credential files.
|
|
545
|
+
const subscriptions = () => {
|
|
546
|
+
if (!services.subscriptions)
|
|
547
|
+
throw new FleetError('capability_unavailable', 'subscription management is unavailable');
|
|
548
|
+
return services.subscriptions;
|
|
549
|
+
};
|
|
550
|
+
const provider = (raw) => {
|
|
551
|
+
if (!isProvider(raw))
|
|
552
|
+
throw new FleetError('invalid_request', 'unknown subscription provider');
|
|
553
|
+
return raw;
|
|
554
|
+
};
|
|
555
|
+
const subscriptionsChanged = () => events.publish('subscription.changed', {});
|
|
556
|
+
app.get('/api/v1/subscriptions', async (request) => {
|
|
557
|
+
auth.authenticate(request);
|
|
558
|
+
return { providers: await subscriptions().list() };
|
|
559
|
+
});
|
|
560
|
+
app.post('/api/v1/subscriptions/:provider/logins', async (request, reply) => {
|
|
561
|
+
const session = auth.authenticate(request, true);
|
|
562
|
+
const login = await subscriptions().startLogin(provider(request.params.provider), session.id);
|
|
563
|
+
await audit.record({ requestId: request.id, browser: session.id, action: `subscription.login.${request.params.provider}`, result: login.state });
|
|
564
|
+
reply.code(201);
|
|
565
|
+
return login;
|
|
566
|
+
});
|
|
567
|
+
app.get('/api/v1/subscriptions/:provider/logins/:loginId', async (request) => {
|
|
568
|
+
const session = auth.authenticate(request);
|
|
569
|
+
return subscriptions().login(request.params.loginId, session.id).view();
|
|
570
|
+
});
|
|
571
|
+
app.post('/api/v1/subscriptions/:provider/logins/:loginId/code', async (request) => {
|
|
572
|
+
const session = auth.authenticate(request, true);
|
|
573
|
+
const code = request.body?.code;
|
|
574
|
+
if (typeof code !== 'string')
|
|
575
|
+
throw new FleetError('invalid_request', 'code is required');
|
|
576
|
+
const login = subscriptions().login(request.params.loginId, session.id);
|
|
577
|
+
login.submitCode(code.trim());
|
|
578
|
+
await audit.record({ requestId: request.id, browser: session.id, action: `subscription.login.code.${request.params.provider}`, result: 'submitted' });
|
|
579
|
+
return login.view();
|
|
580
|
+
});
|
|
581
|
+
app.delete('/api/v1/subscriptions/:provider/logins/:loginId', async (request) => {
|
|
582
|
+
const session = auth.authenticate(request, true);
|
|
583
|
+
const login = subscriptions().login(request.params.loginId, session.id);
|
|
584
|
+
login.cancel();
|
|
585
|
+
return login.view();
|
|
586
|
+
});
|
|
587
|
+
app.post('/api/v1/subscriptions/:provider/active', async (request) => {
|
|
588
|
+
const session = auth.authenticate(request, true);
|
|
589
|
+
const profileId = request.body?.profileId;
|
|
590
|
+
if (typeof profileId !== 'string')
|
|
591
|
+
throw new FleetError('invalid_request', 'profileId is required');
|
|
592
|
+
const view = await subscriptions().setActive(provider(request.params.provider), profileId);
|
|
593
|
+
subscriptionsChanged();
|
|
594
|
+
await audit.record({ requestId: request.id, browser: session.id, action: `subscription.activate.${request.params.provider}`, result: 'succeeded' });
|
|
595
|
+
return view;
|
|
596
|
+
});
|
|
597
|
+
app.post('/api/v1/subscriptions/:provider/profiles/:profileId/check', async (request) => {
|
|
598
|
+
auth.authenticate(request, true);
|
|
599
|
+
return subscriptions().check(provider(request.params.provider), request.params.profileId);
|
|
600
|
+
});
|
|
601
|
+
app.post('/api/v1/subscriptions/claude/profiles/:profileId/probe', async (request) => {
|
|
602
|
+
const session = auth.authenticate(request, true);
|
|
603
|
+
const usage = await subscriptions().probeClaudeUsage(request.params.profileId);
|
|
604
|
+
await audit.record({ requestId: request.id, browser: session.id, action: 'subscription.usage.probe.claude', result: usage.source });
|
|
605
|
+
return { usage };
|
|
606
|
+
});
|
|
607
|
+
app.patch('/api/v1/subscriptions/:provider/profiles/:profileId', async (request) => {
|
|
608
|
+
auth.authenticate(request, true);
|
|
609
|
+
const label = request.body?.label;
|
|
610
|
+
if (typeof label !== 'string')
|
|
611
|
+
throw new FleetError('invalid_request', 'label is required');
|
|
612
|
+
await subscriptions().rename(provider(request.params.provider), request.params.profileId, label);
|
|
613
|
+
subscriptionsChanged();
|
|
614
|
+
return { ok: true };
|
|
615
|
+
});
|
|
616
|
+
app.delete('/api/v1/subscriptions/:provider/profiles/:profileId', async (request) => {
|
|
617
|
+
const session = auth.authenticate(request, true);
|
|
618
|
+
await subscriptions().remove(provider(request.params.provider), request.params.profileId);
|
|
619
|
+
subscriptionsChanged();
|
|
620
|
+
await audit.record({ requestId: request.id, browser: session.id, action: `subscription.remove.${request.params.provider}`, result: 'succeeded' });
|
|
621
|
+
return { ok: true };
|
|
622
|
+
});
|
|
268
623
|
app.get('/api/v1/topology', async (request) => {
|
|
269
624
|
auth.authenticate(request);
|
|
270
625
|
if (!services.topology)
|
|
@@ -311,9 +666,41 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
311
666
|
});
|
|
312
667
|
return result;
|
|
313
668
|
});
|
|
669
|
+
const oursTools = services.oursTools ?? new SupervisorOursTools();
|
|
670
|
+
app.get('/api/v1/roles/:id/contacts', async (request) => {
|
|
671
|
+
auth.authenticate(request);
|
|
672
|
+
const control = await services.session(request.params.id);
|
|
673
|
+
if (!control.agentContacts)
|
|
674
|
+
throw new FleetError('capability_unavailable', 'Supervisor contacts API is unavailable');
|
|
675
|
+
return control.agentContacts();
|
|
676
|
+
});
|
|
677
|
+
app.get('/api/v1/roles/:id/messages', async (request) => {
|
|
678
|
+
auth.authenticate(request);
|
|
679
|
+
const control = await services.session(request.params.id);
|
|
680
|
+
if (!control.agentHistory)
|
|
681
|
+
throw new FleetError('capability_unavailable', 'Supervisor history API is unavailable');
|
|
682
|
+
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) } : {}) });
|
|
683
|
+
});
|
|
684
|
+
app.get('/api/v1/roles/:id/ours/tools', async (request) => {
|
|
685
|
+
auth.authenticate(request);
|
|
686
|
+
return oursTools.list(request.params.id);
|
|
687
|
+
});
|
|
688
|
+
app.post('/api/v1/roles/:id/ours/call', async (request) => {
|
|
689
|
+
const session = auth.authenticate(request, true);
|
|
690
|
+
const result = await oursTools.call(request.params.id, request.body);
|
|
691
|
+
await audit.record({ requestId: request.id, browser: session.id,
|
|
692
|
+
action: 'ours.call', result: result.result.isError === true ? 'tool_error' : 'succeeded' });
|
|
693
|
+
return result;
|
|
694
|
+
});
|
|
314
695
|
app.get('/api/v1/roles/:id', async (request) => {
|
|
315
696
|
auth.authenticate(request);
|
|
316
|
-
|
|
697
|
+
const detail = await services.query.detail(request.params.id);
|
|
698
|
+
return { ...detail, chatIdle: detail.role.lifetime === 'temporary' ? readChatIdle(agentDir(request.params.id, true)) ?? null : null };
|
|
699
|
+
});
|
|
700
|
+
app.get('/api/v1/roles/:id/voice-capabilities', async (request) => {
|
|
701
|
+
auth.authenticate(request);
|
|
702
|
+
const descriptor = await (await services.session(request.params.id)).describe();
|
|
703
|
+
return { supported: ['generation_bound_prompts', 'idle_bound_prompts', 'targeted_voice_interrupt'].every(f => descriptor.features.includes(f)) };
|
|
317
704
|
});
|
|
318
705
|
app.get('/api/v1/roles/:id/removal-preview', async (request) => {
|
|
319
706
|
auth.authenticate(request);
|
|
@@ -348,15 +735,81 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
348
735
|
const control = await services.session(request.params.id);
|
|
349
736
|
if (!control.conversationPage)
|
|
350
737
|
throw new FleetError('capability_unavailable', 'this role has no conversation ledger');
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
738
|
+
const limit = request.query.limit ? Number(request.query.limit) : undefined;
|
|
739
|
+
// `latest` / `before` page backwards from the newest event; `after` pages forward for live updates.
|
|
740
|
+
const backward = request.query.latest === '1' || request.query.before !== undefined;
|
|
741
|
+
if (backward && request.query.after !== undefined)
|
|
742
|
+
throw new FleetError('invalid_request', 'after cannot be combined with latest or before');
|
|
743
|
+
if (backward && !control.conversationTail)
|
|
744
|
+
throw new FleetError('capability_unavailable', 'this role cannot page its conversation backwards');
|
|
745
|
+
const role = await services.repository.get(request.params.id);
|
|
746
|
+
const stateDir = role ? services.repository.stateDir(role) : undefined;
|
|
747
|
+
const present = (event) => presentAttachmentEvent(stateDir, request.params.id, event);
|
|
748
|
+
if (backward) {
|
|
749
|
+
const page = await control.conversationTail({ before: request.query.before, limit });
|
|
750
|
+
return { ...page, events: page.events.map(present), context: page.context.map(present) };
|
|
751
|
+
}
|
|
752
|
+
const page = await control.conversationPage({ after: request.query.after, limit });
|
|
753
|
+
return { ...page, events: page.events.map(present) };
|
|
754
|
+
});
|
|
755
|
+
app.get('/api/v1/roles/:id/attachments/:attachmentId', async (request, reply) => {
|
|
756
|
+
auth.authenticate(request);
|
|
757
|
+
const role = await services.repository.get(request.params.id);
|
|
758
|
+
if (!role)
|
|
759
|
+
throw new FleetError('role_not_found', 'Agent not found');
|
|
760
|
+
const stateDir = services.repository.stateDir(role);
|
|
761
|
+
if (!stateDir)
|
|
762
|
+
throw new FleetError('capability_unavailable', 'Agent file storage is unavailable');
|
|
763
|
+
const { record, bytes } = readAgentAttachment(stateDir, request.params.attachmentId);
|
|
764
|
+
const image = /^image\/(png|jpeg|gif|webp|avif)$/.test(record.mimeType);
|
|
765
|
+
reply.header('Cache-Control', 'private, no-store');
|
|
766
|
+
reply.header('X-Content-Type-Options', 'nosniff');
|
|
767
|
+
reply.header('Content-Security-Policy', "default-src 'none'; sandbox");
|
|
768
|
+
reply.header('Content-Disposition', `${image ? 'inline' : 'attachment'}; filename*=UTF-8''${encodeURIComponent(record.name).replace(/'/g, '%27')}`);
|
|
769
|
+
return reply.type(image ? record.mimeType : 'application/octet-stream').send(bytes);
|
|
770
|
+
});
|
|
771
|
+
app.post('/api/v1/roles/:id/attachments', { bodyLimit: MAX_ATTACHMENT_BODY }, async (request) => {
|
|
772
|
+
auth.authenticate(request, true);
|
|
773
|
+
const role = await services.repository.get(request.params.id);
|
|
774
|
+
if (!role)
|
|
775
|
+
throw new FleetError('role_not_found', 'Agent not found');
|
|
776
|
+
const stateDir = services.repository.stateDir(role);
|
|
777
|
+
if (!stateDir)
|
|
778
|
+
throw new FleetError('capability_unavailable', 'Agent file storage is unavailable');
|
|
779
|
+
const body = request.body;
|
|
780
|
+
if (typeof body?.expectedSessionGeneration !== 'string' || !body.expectedSessionGeneration.trim())
|
|
781
|
+
throw new FleetError('invalid_request', 'expectedSessionGeneration is required for attachments');
|
|
782
|
+
const control = await services.session(request.params.id);
|
|
783
|
+
if (!control.conversationPage || !control.submitPromptV2)
|
|
784
|
+
throw new FleetError('capability_unavailable', 'Session-bound attachments are unavailable');
|
|
785
|
+
const page = await control.conversationPage({ limit: 1 });
|
|
786
|
+
if (page.snapshot.sessionGeneration !== body.expectedSessionGeneration)
|
|
787
|
+
throw new FleetError('stale_state', 'Agent session changed. Select the files again.');
|
|
788
|
+
return storeAgentAttachment(stateDir, body.expectedSessionGeneration, request.body);
|
|
355
789
|
});
|
|
356
790
|
app.post('/api/v1/roles/:id/input', async (request, reply) => {
|
|
357
791
|
const session = auth.authenticate(request, true);
|
|
358
792
|
const body = request.body;
|
|
359
|
-
|
|
793
|
+
if (body?.expectedSessionGeneration !== undefined && (typeof body.expectedSessionGeneration !== 'string' || !body.expectedSessionGeneration.trim()))
|
|
794
|
+
throw new FleetError('invalid_request', 'expectedSessionGeneration must be a nonempty string');
|
|
795
|
+
if (body?.requireIdle !== undefined && typeof body.requireIdle !== 'boolean')
|
|
796
|
+
throw new FleetError('invalid_request', 'requireIdle must be boolean');
|
|
797
|
+
let text = String(body?.text ?? '');
|
|
798
|
+
if (body?.attachments !== undefined) {
|
|
799
|
+
if (typeof body.commandId !== 'string' || !body.commandId.trim())
|
|
800
|
+
throw new FleetError('invalid_request', 'commandId is required for attachments');
|
|
801
|
+
if (typeof body.expectedSessionGeneration !== 'string' || !body.expectedSessionGeneration.trim())
|
|
802
|
+
throw new FleetError('invalid_request', 'expectedSessionGeneration is required for attachments');
|
|
803
|
+
const role = await services.repository.get(request.params.id);
|
|
804
|
+
if (!role)
|
|
805
|
+
throw new FleetError('role_not_found', 'Agent not found');
|
|
806
|
+
const stateDir = services.repository.stateDir(role);
|
|
807
|
+
if (!stateDir)
|
|
808
|
+
throw new FleetError('capability_unavailable', 'Agent file storage is unavailable');
|
|
809
|
+
const originalText = text;
|
|
810
|
+
text = attachmentPrompt(stateDir, body.expectedSessionGeneration, body.attachments, text);
|
|
811
|
+
prepareAttachmentPresentation(stateDir, body.expectedSessionGeneration, body.commandId, body.attachments, originalText, text);
|
|
812
|
+
}
|
|
360
813
|
const commandId = typeof body?.commandId === 'string' && body.commandId.trim()
|
|
361
814
|
? body.commandId : undefined;
|
|
362
815
|
const control = await services.session(request.params.id);
|
|
@@ -367,6 +820,7 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
367
820
|
const admittedCommandId = commandId ?? randomBytes(16).toString('hex');
|
|
368
821
|
const receipt = await control.submitPromptV2({
|
|
369
822
|
commandId: admittedCommandId, text, source: 'owner_admin_console',
|
|
823
|
+
expectedSessionGeneration: body.expectedSessionGeneration, requireIdle: body.requireIdle === true,
|
|
370
824
|
actorBrowserSession: createHmac('sha256', digestKey).update(session.id).digest('hex').slice(0, 24),
|
|
371
825
|
});
|
|
372
826
|
await audit.record({
|
|
@@ -378,6 +832,8 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
378
832
|
reply.code(202);
|
|
379
833
|
return receipt;
|
|
380
834
|
}
|
|
835
|
+
if (body.expectedSessionGeneration !== undefined || body.requireIdle)
|
|
836
|
+
throw new FleetError('capability_unavailable', 'session-bound voice input is unavailable for this role');
|
|
381
837
|
const receipt = await control.sendText(text);
|
|
382
838
|
await audit.record({
|
|
383
839
|
requestId: request.id, browser: session.id, roleId: request.params.id,
|
|
@@ -393,6 +849,16 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
393
849
|
const commandId = typeof body?.commandId === 'string' && body.commandId.trim()
|
|
394
850
|
? body.commandId : undefined;
|
|
395
851
|
const control = await services.session(request.params.id);
|
|
852
|
+
if (body?.expectedSessionGeneration !== undefined || body?.promptId !== undefined) {
|
|
853
|
+
if (!commandId || typeof body.expectedSessionGeneration !== 'string' || !body.expectedSessionGeneration.trim() || typeof body.promptId !== 'string' || !body.promptId.trim())
|
|
854
|
+
throw new FleetError('invalid_request', 'Targeted interrupt requires commandId, expectedSessionGeneration and promptId');
|
|
855
|
+
if (!control.interruptPromptV2)
|
|
856
|
+
throw new FleetError('capability_unavailable', 'Targeted voice interrupt is unavailable');
|
|
857
|
+
const receipt = await control.interruptPromptV2({ commandId, expectedSessionGeneration: body.expectedSessionGeneration, promptId: body.promptId });
|
|
858
|
+
await audit.record({ requestId: request.id, browser: session.id, roleId: request.params.id, action: 'session.interrupt_voice', result: 'accepted' });
|
|
859
|
+
reply.code(202);
|
|
860
|
+
return receipt;
|
|
861
|
+
}
|
|
396
862
|
if (commandId && control.interruptV2) {
|
|
397
863
|
const receipt = await control.interruptV2(commandId);
|
|
398
864
|
await audit.record({
|
|
@@ -443,10 +909,22 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
443
909
|
const body = request.body;
|
|
444
910
|
if (!body.action || !['start', 'stop', 'restart_resume', 'restart_fresh'].includes(body.action))
|
|
445
911
|
throw new FleetError('invalid_request', 'invalid lifecycle action');
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
912
|
+
let receipt;
|
|
913
|
+
try {
|
|
914
|
+
receipt = await services.commands.execute({
|
|
915
|
+
roleId: request.params.id, action: body.action,
|
|
916
|
+
actionId: body.actionId, confirmation: body.confirmation,
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
catch (error) {
|
|
920
|
+
// An existing receipt always wins: a conflicting/repeated action is not a
|
|
921
|
+
// proof that the original operation was never admitted.
|
|
922
|
+
if (typeof body.actionId === 'string' && !services.commands.get(body.actionId)) {
|
|
923
|
+
const normalized = normalizeError(error);
|
|
924
|
+
return reply.code(409).send({ error: { code: 'action_not_accepted', message: normalized.message }, accepted: false });
|
|
925
|
+
}
|
|
926
|
+
throw error;
|
|
927
|
+
}
|
|
450
928
|
events.publish('action.changed', receipt, request.params.id);
|
|
451
929
|
reply.code(202);
|
|
452
930
|
return receipt;
|
|
@@ -465,6 +943,70 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
465
943
|
throw new FleetError('role_not_found', 'creation action not found');
|
|
466
944
|
return action;
|
|
467
945
|
});
|
|
946
|
+
// A fetch stream works through the same authenticated workspace transport as
|
|
947
|
+
// ordinary requests, and owns one ACP controller until its browser disconnects.
|
|
948
|
+
app.post('/api/v1/roles/:id/live-presence', async (request, reply) => {
|
|
949
|
+
const browser = auth.authenticate(request, true);
|
|
950
|
+
const generation = request.body?.expectedSessionGeneration;
|
|
951
|
+
if (typeof generation !== 'string' || !generation.trim())
|
|
952
|
+
throw new FleetError('invalid_request', 'expectedSessionGeneration is required');
|
|
953
|
+
const control = await services.session(request.params.id);
|
|
954
|
+
if (!control.followConversation || !control.conversationPage)
|
|
955
|
+
throw new FleetError('capability_unavailable', 'Live voice requires a conversation controller');
|
|
956
|
+
const page = await control.conversationPage({ limit: 1 });
|
|
957
|
+
if (page.snapshot.sessionGeneration !== generation)
|
|
958
|
+
throw new FleetError('stale_state', 'Agent session changed. Start live voice again.');
|
|
959
|
+
// Session/page discovery can await I/O; recheck revocation before attaching.
|
|
960
|
+
auth.authenticate(request, true);
|
|
961
|
+
if (reply.raw.destroyed)
|
|
962
|
+
return;
|
|
963
|
+
reply.hijack();
|
|
964
|
+
for (const [name, value] of Object.entries(reply.getHeaders()))
|
|
965
|
+
if (value !== undefined)
|
|
966
|
+
reply.raw.setHeader(name, Array.isArray(value) ? value : String(value));
|
|
967
|
+
reply.raw.writeHead(200, { 'Content-Type': 'application/x-ndjson', 'Cache-Control': 'no-store', 'X-Accel-Buffering': 'no' });
|
|
968
|
+
let ended = false;
|
|
969
|
+
let follow;
|
|
970
|
+
let heartbeat;
|
|
971
|
+
let unbind;
|
|
972
|
+
const close = () => { if (ended)
|
|
973
|
+
return; ended = true; unbind?.(); if (heartbeat)
|
|
974
|
+
clearInterval(heartbeat); follow?.close(); reply.raw.end(); };
|
|
975
|
+
const write = (value) => { if (!ended && !reply.raw.write(JSON.stringify(value) + '\n'))
|
|
976
|
+
close(); };
|
|
977
|
+
reply.raw.once('close', close);
|
|
978
|
+
unbind = auth.bindTransport(browser.id, close);
|
|
979
|
+
try {
|
|
980
|
+
follow = await control.followConversation({
|
|
981
|
+
after: page.nextCursor,
|
|
982
|
+
onPage: current => { if (current.snapshot.sessionGeneration !== generation) {
|
|
983
|
+
write({ error: 'Agent session changed. Start live voice again.' });
|
|
984
|
+
close();
|
|
985
|
+
}
|
|
986
|
+
else
|
|
987
|
+
write({ ready: true }); },
|
|
988
|
+
onEvent: event => { if (event.sessionGeneration !== generation) {
|
|
989
|
+
write({ error: 'Agent session changed. Start live voice again.' });
|
|
990
|
+
close();
|
|
991
|
+
} },
|
|
992
|
+
onClose: () => close(),
|
|
993
|
+
});
|
|
994
|
+
if (ended)
|
|
995
|
+
follow.close();
|
|
996
|
+
else
|
|
997
|
+
heartbeat = setInterval(() => { try {
|
|
998
|
+
auth.authenticate(request);
|
|
999
|
+
write({ heartbeat: true });
|
|
1000
|
+
}
|
|
1001
|
+
catch {
|
|
1002
|
+
close();
|
|
1003
|
+
} }, 10_000);
|
|
1004
|
+
}
|
|
1005
|
+
catch {
|
|
1006
|
+
write({ error: 'Agent controller connection failed.' });
|
|
1007
|
+
close();
|
|
1008
|
+
}
|
|
1009
|
+
});
|
|
468
1010
|
app.post('/api/v1/ws-tickets', async (request) => {
|
|
469
1011
|
const body = request.body;
|
|
470
1012
|
if (!body?.purpose || !['events', 'conversation'].includes(body.purpose))
|
|
@@ -534,6 +1076,9 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
534
1076
|
}
|
|
535
1077
|
socket.send(JSON.stringify(payload));
|
|
536
1078
|
};
|
|
1079
|
+
const role = await services.repository.get(request.params.id);
|
|
1080
|
+
const stateDir = role ? services.repository.stateDir(role) : undefined;
|
|
1081
|
+
const present = (event) => presentAttachmentEvent(stateDir, request.params.id, event);
|
|
537
1082
|
const follow = await control.followConversation({
|
|
538
1083
|
after,
|
|
539
1084
|
onPage: page => {
|
|
@@ -544,11 +1089,11 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
544
1089
|
lastCursor: page.nextCursor ?? after,
|
|
545
1090
|
});
|
|
546
1091
|
if (page.events.length)
|
|
547
|
-
guardedSend({ type: 'events', events: page.events });
|
|
1092
|
+
guardedSend({ type: 'events', events: page.events.map(present) });
|
|
548
1093
|
if (page.hasMore)
|
|
549
1094
|
guardedSend({ type: 'resync.required' });
|
|
550
1095
|
},
|
|
551
|
-
onEvent: event => guardedSend({ type: 'events', events: [event] }),
|
|
1096
|
+
onEvent: event => guardedSend({ type: 'events', events: [present(event)] }),
|
|
552
1097
|
onClose: reason => {
|
|
553
1098
|
if (socket.readyState === socket.OPEN)
|
|
554
1099
|
socket.close(4409, (reason ?? 'conversation stream ended').slice(0, 120));
|
|
@@ -561,15 +1106,8 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
561
1106
|
socket.on('close', () => { clearInterval(heartbeat); follow.close(); });
|
|
562
1107
|
});
|
|
563
1108
|
});
|
|
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
|
-
}
|
|
1109
|
+
// Fleet has no pages of its own; every screen belongs to the App.
|
|
1110
|
+
app.setNotFoundHandler((_request, reply) => reply.code(404).send({ error: 'not found' }));
|
|
573
1111
|
return {
|
|
574
1112
|
app, auth, audit, events,
|
|
575
1113
|
async close() {
|
|
@@ -582,17 +1120,17 @@ export async function buildWebServer(services, boundary, options = {}) {
|
|
|
582
1120
|
function setAuthCookies(reply, session, device, secure = false) {
|
|
583
1121
|
const suffix = secure ? '; Secure' : '';
|
|
584
1122
|
reply.header('Set-Cookie', [
|
|
585
|
-
`ofs_session=${encodeURIComponent(session)}; HttpOnly; SameSite=Strict; Path
|
|
586
|
-
`ofs_device=${encodeURIComponent(device)}; HttpOnly; SameSite=Strict; Path
|
|
1123
|
+
`ofs_session=${encodeURIComponent(session)}; HttpOnly; SameSite=Strict; Path=/; Max-Age=28800${suffix}`,
|
|
1124
|
+
`ofs_device=${encodeURIComponent(device)}; HttpOnly; SameSite=Strict; Path=/; Max-Age=2592000${suffix}`,
|
|
587
1125
|
]);
|
|
588
1126
|
}
|
|
589
1127
|
function setSessionCookie(reply, session, secure = false) {
|
|
590
|
-
reply.header('Set-Cookie', `ofs_session=${encodeURIComponent(session)}; HttpOnly; SameSite=Strict; Path
|
|
1128
|
+
reply.header('Set-Cookie', `ofs_session=${encodeURIComponent(session)}; HttpOnly; SameSite=Strict; Path=/; Max-Age=28800${secure ? '; Secure' : ''}`);
|
|
591
1129
|
}
|
|
592
1130
|
function clearAuthCookies(reply) {
|
|
593
1131
|
reply.header('Set-Cookie', [
|
|
594
|
-
'ofs_session=; HttpOnly; SameSite=Strict; Path
|
|
595
|
-
'ofs_device=; HttpOnly; SameSite=Strict; Path
|
|
1132
|
+
'ofs_session=; HttpOnly; SameSite=Strict; Path=/; Max-Age=0',
|
|
1133
|
+
'ofs_device=; HttpOnly; SameSite=Strict; Path=/; Max-Age=0',
|
|
596
1134
|
]);
|
|
597
1135
|
}
|
|
598
1136
|
function promoteRequest(body) {
|
|
@@ -606,9 +1144,6 @@ function promoteRequest(body) {
|
|
|
606
1144
|
};
|
|
607
1145
|
}
|
|
608
1146
|
function cryptoRandomId() { return randomBytes(12).toString('hex'); }
|
|
609
|
-
function escapeHtml(value) {
|
|
610
|
-
return value.replace(/[&<>"']/g, char => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[char]));
|
|
611
|
-
}
|
|
612
1147
|
function requireSubprotocol(request, expected) {
|
|
613
1148
|
const protocols = String(request.headers['sec-websocket-protocol'] ?? '')
|
|
614
1149
|
.split(',').map(value => value.trim());
|