pi-web-ui 0.117.0 → 0.118.0
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/CHANGELOG.md +48 -2
- package/README.md +69 -138
- package/README.zh-CN.md +70 -179
- package/README.zh-TW.md +3 -1
- package/bin/device-hub-cli.mjs +147 -43
- package/bin/frp-manager.mjs +4 -80
- package/bin/hub-upgrade.mjs +561 -0
- package/bin/pi-device-hub.mjs +0 -1
- package/bin/pi-web-ui.mjs +56 -444
- package/deploy/nginx-subpath.conf +0 -33
- package/deploy/pi-web-ui.service +0 -20
- package/dist/server/agent-formatters.js +4 -38
- package/dist/server/agent-service-daemon.js +160 -374
- package/dist/server/agent-service.js +875 -2978
- package/dist/server/approval-audit.js +2 -23
- package/dist/server/approval-default-rules.js +0 -6
- package/dist/server/approval-rules.js +7 -105
- package/dist/server/ask-user-question-tool.js +1 -12
- package/dist/server/atomic-file.js +33 -5
- package/dist/server/attachment-store.js +0 -36
- package/dist/server/attachments.js +3 -112
- package/dist/server/auth-cookie.js +0 -21
- package/dist/server/bash-tool.js +1 -32
- package/dist/server/bg-servers.js +0 -96
- package/dist/server/browser-page-tool.js +11 -62
- package/dist/server/builtin-modules.js +7 -0
- package/dist/server/canvas/canvas-agent-tool.js +58 -47
- package/dist/server/canvas/canvas-cards.js +0 -14
- package/dist/server/canvas/canvas-dispatch.js +7 -4
- package/dist/server/canvas/canvas-orchestrator.js +167 -181
- package/dist/server/canvas/canvas-runtime-messages.js +30 -0
- package/dist/server/canvas/canvas-scheduled-task.js +0 -3
- package/dist/server/canvas/canvas-scheduler.js +5 -7
- package/dist/server/canvas/canvas-store.js +24 -35
- package/dist/server/canvas/canvas-validation.js +17 -14
- package/dist/server/canvas/canvas-workspace.js +26 -30
- package/dist/server/canvas/pstack-skills-data.js +0 -5
- package/dist/server/claim-files-tool.js +1 -15
- package/dist/server/claim-store.js +5 -49
- package/dist/server/client-id-utils.js +0 -16
- package/dist/server/client-state.js +6 -213
- package/dist/server/communicate-tool.js +0 -3
- package/dist/server/compact-context-tool.js +0 -30
- package/dist/server/compacted-history.js +0 -35
- package/dist/server/compaction-instructions.js +0 -13
- package/dist/server/compaction-markers.js +3 -76
- package/dist/server/compaction-state.js +0 -21
- package/dist/server/composer-drafts.js +0 -34
- package/dist/server/context-budget-runner.js +0 -11
- package/dist/server/context-budget.js +1 -70
- package/dist/server/context-evidence.js +0 -14
- package/dist/server/context-usage.js +0 -12
- package/dist/server/control-socket.js +4 -48
- package/dist/server/conversation-communication.js +0 -10
- package/dist/server/conversation-identity.js +0 -1
- package/dist/server/conversation-read-tool.js +0 -58
- package/dist/server/conversation-tool-names.js +0 -1
- package/dist/server/conversation-tool.js +0 -1
- package/dist/server/conversation-touches.js +4 -75
- package/dist/server/dangling-tools.js +0 -82
- package/dist/server/delegate-mode.js +0 -36
- package/dist/server/delegate-task.js +2 -28
- package/dist/server/device-center/approval-summary.js +0 -1
- package/dist/server/device-center/bot-catalog.js +0 -3
- package/dist/server/device-center/bot-execution.js +0 -8
- package/dist/server/device-center/bot-presets.js +0 -1
- package/dist/server/device-center/bots.js +0 -1
- package/dist/server/device-center/collab-service.js +1 -3
- package/dist/server/device-center/collab-tool.js +0 -10
- package/dist/server/device-center/connector.js +21 -11
- package/dist/server/device-center/delivery-authority.js +0 -3
- package/dist/server/device-center/delivery-subject.js +0 -1
- package/dist/server/device-center/desktop-linux.js +3 -15
- package/dist/server/device-center/desktop-native.js +1 -10
- package/dist/server/device-center/desktop-page.js +2 -3
- package/dist/server/device-center/desktop-setup.js +1 -3
- package/dist/server/device-center/desktop.js +1 -7
- package/dist/server/device-center/device-integration.js +1 -27
- package/dist/server/device-center/device-lan-access.js +403 -0
- package/dist/server/device-center/device-lan.js +484 -0
- package/dist/server/device-center/device-portals.js +0 -3
- package/dist/server/device-center/execution-failure.js +0 -2
- package/dist/server/device-center/execution-guides.js +0 -1
- package/dist/server/device-center/execution-instructions.js +0 -1
- package/dist/server/device-center/execution-settings.js +0 -1
- package/dist/server/device-center/execution-system-prompt.js +0 -3
- package/dist/server/device-center/execution-workspace.js +1 -4
- package/dist/server/device-center/executor.js +0 -27
- package/dist/server/device-center/file-sync-paths.js +0 -5
- package/dist/server/device-center/file-sync.js +0 -10
- package/dist/server/device-center/group-context-delta.js +0 -8
- package/dist/server/device-center/group-context-message.js +0 -14
- package/dist/server/device-center/group-context.js +0 -19
- package/dist/server/device-center/group-events.js +0 -2
- package/dist/server/device-center/group-plan-guard.js +1 -35
- package/dist/server/device-center/group-router-runtime.js +182 -0
- package/dist/server/device-center/group-router-worker.js +178 -0
- package/dist/server/device-center/group-router.js +359 -0
- package/dist/server/device-center/hub-auth.js +24 -2
- package/dist/server/device-center/hub-conversations.js +0 -12
- package/dist/server/device-center/hub-deliveries.js +0 -1
- package/dist/server/device-center/hub-integration.js +0 -8
- package/dist/server/device-center/hub-locks.js +1 -5
- package/dist/server/device-center/hub-mobile.js +147 -0
- package/dist/server/device-center/hub-orchestration.js +400 -0
- package/dist/server/device-center/hub-page.js +25 -7
- package/dist/server/device-center/hub-setup.js +0 -6
- package/dist/server/device-center/hub-transaction-log.js +0 -22
- package/dist/server/device-center/hub-upgrade.js +162 -0
- package/dist/server/device-center/hub-webhooks.js +1 -3
- package/dist/server/device-center/hub.js +210 -86
- package/dist/server/device-center/human-interaction.js +1 -4
- package/dist/server/device-center/integration-errors.js +0 -2
- package/dist/server/device-center/integration-verification.js +0 -2
- package/dist/server/device-center/local-hub.js +0 -2
- package/dist/server/device-center/local-publication.js +1 -8
- package/dist/server/device-center/local-verification-job.js +0 -2
- package/dist/server/device-center/local-verification.js +0 -1
- package/dist/server/device-center/local.js +267 -39
- package/dist/server/device-center/main.js +14 -1
- package/dist/server/device-center/mobile-notification-forwarder.js +292 -0
- package/dist/server/device-center/native-desktop/macos.js +0 -1
- package/dist/server/device-center/native-desktop/windows.js +0 -1
- package/dist/server/device-center/partition-log.js +0 -31
- package/dist/server/device-center/path-portal.js +42 -12
- package/dist/server/device-center/publication-journal.js +0 -7
- package/dist/server/device-center/publish-intent.js +0 -5
- package/dist/server/device-center/relay.js +85 -30
- package/dist/server/device-center/report-upload.js +0 -1
- package/dist/server/device-center/runtime.js +1 -18
- package/dist/server/device-center/store.js +13 -33
- package/dist/server/device-center/task-context-budget.js +0 -3
- package/dist/server/device-center/task-error.js +0 -1
- package/dist/server/device-center/task-journal.js +6 -23
- package/dist/server/device-center/task-outcome.js +0 -13
- package/dist/server/device-center/task-plan.js +0 -1
- package/dist/server/device-center/task-progress.js +0 -16
- package/dist/server/device-center/task-recovery.js +5 -88
- package/dist/server/device-center/task-report-outbox.js +0 -4
- package/dist/server/device-center/task-report.js +2 -10
- package/dist/server/device-center/task-scheduler.js +1 -35
- package/dist/server/device-center/task-settlement.js +0 -18
- package/dist/server/device-center/task-state.js +0 -12
- package/dist/server/device-center/task-workspace.js +0 -50
- package/dist/server/device-center/transfer-stream.js +5 -45
- package/dist/server/device-center/transfers.js +2 -10
- package/dist/server/device-center/verification-limits.js +0 -1
- package/dist/server/device-center/work-contract.js +1 -73
- package/dist/server/device-center/work-items.js +317 -0
- package/dist/server/device-center/workspaces.js +0 -1
- package/dist/server/dispatch-domain-handlers.js +190 -32
- package/dist/server/dispatch-plugin-handlers.js +2 -19
- package/dist/server/dsh/dsh-agent-service.js +69 -599
- package/dist/server/dsh/dsh-client.js +7 -111
- package/dist/server/dsh/dsh-market-service.js +4 -25
- package/dist/server/dsh/dsh-serialize.js +0 -49
- package/dist/server/dsh/dsh-sessions.js +0 -37
- package/dist/server/dsh/dsh-usage.js +0 -37
- package/dist/server/dsh/preset-clones.js +1 -65
- package/dist/server/dsh/runtime/custom-prompt.mjs +0 -14
- package/dist/server/dsh/runtime/goal-rpc.mjs +7 -176
- package/dist/server/dsh/runtime/launcher.mjs +2 -53
- package/dist/server/dsh/runtime/override.patch.yml +0 -29
- package/dist/server/dsh/runtime/runtime-root.mjs +0 -54
- package/dist/server/durable/durable-agent-service.js +5 -23
- package/dist/server/durable/durable-driver.js +12 -73
- package/dist/server/durable/durable-event-projector.js +1 -50
- package/dist/server/durable/durable-loader.js +0 -12
- package/dist/server/durable/durable-models.js +11 -80
- package/dist/server/durable/durable-storage.js +1 -17
- package/dist/server/durable/durable-tools.js +2 -20
- package/dist/server/durable/index.js +0 -3
- package/dist/server/edit-soft-tool.js +2 -81
- package/dist/server/engine-capabilities.js +0 -13
- package/dist/server/engine-catalog.js +74 -0
- package/dist/server/engine-cli.js +89 -0
- package/dist/server/engine-probe.js +35 -217
- package/dist/server/ensure-bash.js +2 -28
- package/dist/server/eval-tool.js +1 -50
- package/dist/server/evidence-tool-hooks.js +0 -2
- package/dist/server/file-archives.js +0 -10
- package/dist/server/file-save.js +1 -12
- package/dist/server/file-transfer-routes.js +0 -11
- package/dist/server/files-service.js +18 -271
- package/dist/server/global-loader.js +9 -89
- package/dist/server/goal-evidence.js +1 -35
- package/dist/server/goal-review-gate.js +0 -58
- package/dist/server/goal-service.js +19 -422
- package/dist/server/hashline-engine.js +8 -112
- package/dist/server/host-guard.js +0 -24
- package/dist/server/host-metrics.js +0 -6
- package/dist/server/http-proxy.js +1 -7
- package/dist/server/i18n.js +5 -72
- package/dist/server/icon-svg.js +0 -15
- package/dist/server/index.js +177 -680
- package/dist/server/json-utils.js +0 -12
- package/dist/server/launch-origin.js +0 -44
- package/dist/server/left-panel-running.js +0 -9
- package/dist/server/load-timing.js +1 -4
- package/dist/server/load-tools-tool.js +0 -20
- package/dist/server/locales.js +1 -46
- package/dist/server/lsp-tool.js +13 -126
- package/dist/server/managed.js +0 -48
- package/dist/server/marker-service.js +1 -22
- package/dist/server/markers/builtins/action.js +0 -19
- package/dist/server/markers/builtins/notify.js +1 -9
- package/dist/server/markers/builtins/rename.js +0 -13
- package/dist/server/markers/index.js +0 -3
- package/dist/server/markers/marker.js +0 -13
- package/dist/server/markers/registry.js +0 -3
- package/dist/server/markers/store.js +1 -12
- package/dist/server/market-service.js +7 -43
- package/dist/server/mcp-agent-tool.js +0 -10
- package/dist/server/mcp-bridge.js +6 -138
- package/dist/server/mcp-hot-reload.js +0 -25
- package/dist/server/mcp-manager.js +2 -44
- package/dist/server/mcp-oauth-login.js +0 -2
- package/dist/server/mcp-oauth-ui.js +1 -4
- package/dist/server/mcp-oauth.js +5 -79
- package/dist/server/mcp-project-runtime.js +0 -4
- package/dist/server/message-deletion.js +0 -2
- package/dist/server/message-entry-resolver.js +0 -8
- package/dist/server/message-window.js +0 -71
- package/dist/server/mobile-notification-events.js +16 -0
- package/dist/server/mobile-origin.js +79 -0
- package/dist/server/mobile-push.js +523 -0
- package/dist/server/model-admin.js +19 -358
- package/dist/server/model-enrich.js +0 -19
- package/dist/server/model-resolver.js +2 -61
- package/dist/server/native-cli-discovery.js +115 -0
- package/dist/server/native-cli-model.js +71 -0
- package/dist/server/native-cli-references.js +214 -0
- package/dist/server/native-cli-remote-cleanup.js +58 -0
- package/dist/server/native-cli-remote-files.js +282 -0
- package/dist/server/native-cli-routes.js +68 -0
- package/dist/server/native-cli-runtime.js +1 -0
- package/dist/server/native-cli-session-hooks.js +170 -0
- package/dist/server/native-cli-session.js +585 -0
- package/dist/server/native-cli-state.js +82 -0
- package/dist/server/native-cli.js +210 -0
- package/dist/server/net-guard.js +9 -71
- package/dist/server/office-parse.js +0 -50
- package/dist/server/orphan-manager.js +0 -18
- package/dist/server/patch-bash-process.js +0 -4
- package/dist/server/patch-executable-lookup.js +0 -77
- package/dist/server/patch-node-pty.js +3 -43
- package/dist/server/patch-remote-catalog.js +1 -32
- package/dist/server/patch-tool.js +0 -15
- package/dist/server/payload-limits.js +0 -5
- package/dist/server/pending-question.js +0 -5
- package/dist/server/permission-preset.js +4 -33
- package/dist/server/persona-chain.js +0 -26
- package/dist/server/pkg-info.js +1 -17
- package/dist/server/plan-manager.js +2 -49
- package/dist/server/plan-mode.js +0 -97
- package/dist/server/plan-update-tool.js +1 -15
- package/dist/server/plugin-api-catalog.js +6 -4
- package/dist/server/plugin-assets.js +1 -35
- package/dist/server/plugin-bundled.js +68 -0
- package/dist/server/plugin-catalog-sync.js +0 -37
- package/dist/server/plugin-catalog.js +13 -67
- package/dist/server/plugin-chat-attachments.js +0 -1
- package/dist/server/plugin-conversation-view.js +0 -20
- package/dist/server/plugin-dom.js +1 -23
- package/dist/server/plugin-facilities.js +4 -115
- package/dist/server/plugin-grants.js +2 -90
- package/dist/server/plugin-install-spec.js +0 -43
- package/dist/server/plugin-installer.js +34 -75
- package/dist/server/plugin-llm.js +4 -38
- package/dist/server/plugin-manifest-validate.js +0 -31
- package/dist/server/plugin-permissions.js +1 -24
- package/dist/server/plugin-project.js +7 -129
- package/dist/server/plugin-removal.js +1 -8
- package/dist/server/plugin-schedule.js +1 -38
- package/dist/server/plugin-secrets.js +3 -16
- package/dist/server/plugin-tool-guard.js +1 -28
- package/dist/server/plugin-ui-slots.js +0 -4
- package/dist/server/plugin-updater.js +15 -90
- package/dist/server/plugins.js +71 -619
- package/dist/server/present-files-tool.js +0 -57
- package/dist/server/preset-fields.js +9 -62
- package/dist/server/preset-plugin-dependencies.js +0 -2
- package/dist/server/preset-share.js +3 -172
- package/dist/server/process-utils.js +4 -80
- package/dist/server/prompt-assembler.js +2 -30
- package/dist/server/prompt-base-store.js +0 -47
- package/dist/server/prompt-composer.js +21 -98
- package/dist/server/prompt-templates.js +0 -2
- package/dist/server/protocol-version.js +1 -11
- package/dist/server/protocol.js +0 -5
- package/dist/server/queue-modes.js +0 -3
- package/dist/server/queue-utils.js +0 -40
- package/dist/server/quick-ask-context.js +384 -0
- package/dist/server/quick-ask-settings.js +34 -1
- package/dist/server/quick-ask.js +123 -27
- package/dist/server/read-tool.js +0 -65
- package/dist/server/reasoning-registry.js +1 -29
- package/dist/server/remote-cli-persistence.js +373 -0
- package/dist/server/remote-native-cli.js +78 -0
- package/dist/server/remote-ssh-service.js +481 -190
- package/dist/server/request-context.js +0 -9
- package/dist/server/resolve-global-sdk.js +0 -26
- package/dist/server/sandbox-data.js +0 -1
- package/dist/server/sandbox-engines.js +0 -1
- package/dist/server/sandbox-runtime-gate.js +0 -3
- package/dist/server/sandbox-service.js +0 -41
- package/dist/server/sandbox-tool.js +0 -20
- package/dist/server/schedule-agent-tool.js +2 -31
- package/dist/server/scheduler-tasks.js +3 -54
- package/dist/server/scm-commitmsg.js +0 -53
- package/dist/server/scm.js +3 -48
- package/dist/server/sdk-builtin-extensions.js +2 -29
- package/dist/server/sdk-origin.js +0 -45
- package/dist/server/serialize.js +2 -92
- package/dist/server/server-config.js +0 -11
- package/dist/server/session-branch.js +1 -87
- package/dist/server/session-list-scan.js +17 -25
- package/dist/server/session-open.js +2 -26
- package/dist/server/session-parser.js +1 -55
- package/dist/server/session-scan.js +1 -17
- package/dist/server/session-search.js +0 -56
- package/dist/server/settings-service.js +11 -126
- package/dist/server/setup-config.js +0 -2
- package/dist/server/setup-page.js +0 -9
- package/dist/server/skill-content-filler.js +0 -17
- package/dist/server/skill-discovery.js +5 -92
- package/dist/server/skill-maintenance.js +1 -28
- package/dist/server/skill-tool.js +0 -30
- package/dist/server/slash-commands.js +5 -50
- package/dist/server/soft-cap.js +0 -42
- package/dist/server/startup-banner.js +0 -8
- package/dist/server/subagent-handoff.js +0 -11
- package/dist/server/subagent-helpers.js +2 -17
- package/dist/server/subagent-notify.js +0 -19
- package/dist/server/subagent-security-gate.js +0 -50
- package/dist/server/subagent-task.js +0 -9
- package/dist/server/subagent-templates-hant.js +0 -10
- package/dist/server/subagent-templates.js +3 -103
- package/dist/server/subagents.js +1 -87
- package/dist/server/system-screenshot-windows.js +259 -0
- package/dist/server/system-screenshot.js +77 -0
- package/dist/server/tabs.js +3 -48
- package/dist/server/terminals.js +559 -586
- package/dist/server/text-quote.js +0 -12
- package/dist/server/text-sniff.js +2 -52
- package/dist/server/themes.js +2 -41
- package/dist/server/tool-approval.js +0 -47
- package/dist/server/tool-guards.js +0 -90
- package/dist/server/tool-host-factories.js +1 -16
- package/dist/server/tool-info.js +0 -13
- package/dist/server/tool-manager.js +1 -229
- package/dist/server/tool-overrides.js +1 -46
- package/dist/server/tool-prompt-overrides.js +1 -30
- package/dist/server/tool-prompts.js +0 -14
- package/dist/server/tool-signature.js +0 -25
- package/dist/server/transcript-prepare.js +1 -19
- package/dist/server/tts-routes.js +58 -0
- package/dist/server/tts-service.js +106 -0
- package/dist/server/tts-system.js +160 -0
- package/dist/server/turn-timing.js +0 -1
- package/dist/server/unauthorized-page.js +0 -8
- package/dist/server/universal/driver-base.js +2 -31
- package/dist/server/universal/drivers/claude-code.js +12 -172
- package/dist/server/universal/drivers/codex.js +12 -35
- package/dist/server/universal/drivers/mock-driver.js +1 -11
- package/dist/server/universal/index.js +0 -3
- package/dist/server/universal/session-store.js +4 -21
- package/dist/server/universal/universal-attachments.js +2 -36
- package/dist/server/universal/universal-service.js +5 -24
- package/dist/server/universal/universal-session.js +26 -148
- package/dist/server/universal/universal-types.js +0 -3
- package/dist/server/update-check.js +6 -182
- package/dist/server/uploads.js +4 -43
- package/dist/server/virtual-tui.js +2 -27
- package/dist/server/vision-bridge.js +0 -27
- package/dist/server/wait-subscription-scan.js +13 -115
- package/dist/server/webui-context.js +2 -87
- package/dist/server/workspace-handle.js +1 -56
- package/dist/server/workspace-snapshot.js +7 -113
- package/dist/server/worktree-service.js +2 -53
- package/dist/server/worktree-tool.js +0 -11
- package/dist/server/ws-client-id.js +0 -18
- package/dist/server/ws-pending-queue.js +0 -7
- package/dist/server/ws-unknown-types.js +0 -17
- package/docs/README.md +24 -17
- package/docs/architecture-plugins.md +37 -1
- package/docs/device-center.md +28 -2
- package/docs/device-desktop.md +3 -3
- package/docs/group-orchestration.md +142 -0
- package/docs/hub-upgrade-release-testing.md +46 -0
- package/extensions/webui.ts +3 -74
- package/package.json +7 -3
- package/plugin-sdk/README.md +6 -0
- package/plugin-sdk/client-utils.mjs +0 -7
- package/plugin-sdk/client.d.ts +0 -1
- package/plugin-sdk/client.mjs +1 -31
- package/plugin-sdk/import-check.mjs +4 -51
- package/plugin-sdk/index.d.ts +120 -119
- package/plugin-sdk/index.mjs +0 -6
- package/plugin-sdk/ssh-host-trust.mjs +0 -12
- package/plugin-sdk/testing.d.ts +0 -1
- package/plugin-sdk/testing.mjs +31 -86
- package/plugins/catalog.json +52 -4
- package/plugins/superagent/README.md +110 -0
- package/plugins/superagent/client/entry.mjs +21 -0
- package/plugins/superagent/index.mjs +8 -0
- package/plugins/superagent/main.mjs +218 -0
- package/plugins/superagent/manifest.json +15 -0
- package/plugins/superagent/server.mjs +572 -0
- package/plugins/superagent/style.css +167 -0
- package/themes/aetheris.css +1 -31
- package/themes/ayu-light.css +0 -1
- package/themes/bases/flow-base.css +2 -83
- package/themes/bases/obsidian-base.css +2 -37
- package/themes/bases/statusbar-flat-base.css +0 -1
- package/themes/bases/zhujian-base.css +0 -63
- package/themes/bases/zhupi-base.css +0 -64
- package/themes/catppuccin-latte.css +0 -1
- package/themes/catppuccin.css +0 -1
- package/themes/claude-code-dark.css +0 -1
- package/themes/codex.css +0 -1
- package/themes/dark-teal.css +22 -54
- package/themes/everforest-light.css +0 -1
- package/themes/flow-cristallo.css +1 -9
- package/themes/flow-ink.css +1 -10
- package/themes/flow-light.css +1 -10
- package/themes/flow-obsidian.css +1 -10
- package/themes/flow-zurich.css +1 -10
- package/themes/flow.css +1 -9
- package/themes/geist.css +0 -1
- package/themes/gruvbox-light.css +0 -1
- package/themes/kanagawa-lotus.css +0 -1
- package/themes/md-preview.css +1 -2
- package/themes/mist.css +0 -1
- package/themes/nord.css +0 -1
- package/themes/one-dark.css +0 -1
- package/themes/paper.css +0 -1
- package/themes/rose-pine-dawn.css +0 -1
- package/themes/sakura.css +0 -1
- package/themes/solarized-light.css +0 -1
- package/themes/tokyo-night.css +0 -1
- package/themes/translucent.css +4 -35
- package/themes/transparent.css +4 -41
- package/themes/vs-code-dark.css +0 -1
- package/themes/wallpaper-flow.css +3 -17
- package/themes/wallpaper-obsidian.css +1 -4
- package/themes/white.css +0 -1
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/{BgTasksModal-BjNRIUIc.js → BgTasksModal-D-x7kA63.js} +1 -1
- package/web/dist/assets/CanvasStudio-CAWcs9tm.js +1579 -0
- package/web/dist/assets/DeviceCenter-Dc0whRcu.js +3 -0
- package/web/dist/assets/DeviceExecutionSettings-BoX7-0h7.js +1 -0
- package/web/dist/assets/DeviceGroups-C_fZMNeK.js +1 -0
- package/web/dist/assets/{Dropdown-CQtstPGv.js → Dropdown-CTgVLUbp.js} +1 -1
- package/web/dist/assets/FilePreview-C6W0PvaK.js +2 -0
- package/web/dist/assets/GlobalSearchModal-HR9LSspC.js +1 -0
- package/web/dist/assets/GroupConversation-C81YjF2C.js +61 -0
- package/web/dist/assets/GroupWorkItems-BIvZtr10.js +1 -0
- package/web/dist/assets/{HintTip-ChTW8o1m.js → HintTip-Da6qc566.js} +1 -1
- package/web/dist/assets/ModelConfigModal-DhSyuIuV.js +2 -0
- package/web/dist/assets/NativeCliPanel-CU1rZmyu.js +5 -0
- package/web/dist/assets/{PiSetupModal-BX5rUuoI.js → PiSetupModal-DZKY5Wiw.js} +1 -1
- package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +1 -0
- package/web/dist/assets/{SCMPanel-DPAyY2sW.js → SCMPanel-CuEgzAlO.js} +2 -2
- package/web/dist/assets/SettingsModal-Cdu5h29p.js +33 -0
- package/web/dist/assets/TermXterm-Bt5WKAxP.js +3 -0
- package/web/dist/assets/TerminalPanel-BCIBV8se.js +1 -0
- package/web/dist/assets/TuiOverlayModal-3NDd9T97.js +1 -0
- package/web/dist/assets/app-globals-CZjFtI4F.js +129 -0
- package/web/dist/assets/canvas-client-WkhM55mR.js +1 -0
- package/web/dist/assets/composer-bridge-CImnjDHq.js +1 -0
- package/web/dist/assets/desktop-B8NZ3KW-.js +1 -0
- package/web/dist/assets/index-CQc3VrWa.css +1 -0
- package/web/dist/assets/index-D_AGu4Zv.js +404 -0
- package/web/dist/assets/plugin-host-uqZGpvCs.js +1 -0
- package/web/dist/assets/{remote-ssh-client-Dzi-eEyE.js → remote-ssh-client-Cdf-cTUe.js} +1 -1
- package/web/dist/assets/theme-DGL7hLUs.js +1 -0
- package/web/dist/index.html +11 -10
- package/web/dist/sw.js +15 -61
- package/web/public/sw.js +14 -60
- package/web/dist/assets/BgTasksModal-C0zuU8FE.js +0 -1
- package/web/dist/assets/CanvasStudio-BWvdmJ0M.js +0 -1579
- package/web/dist/assets/CanvasStudio-VQFjmTGq.js +0 -1579
- package/web/dist/assets/DeviceCenter-DI9_0aBB.js +0 -3
- package/web/dist/assets/DeviceCenter-DsNtXqzY.js +0 -3
- package/web/dist/assets/DeviceExecutionSettings-BLP1Su5G.js +0 -1
- package/web/dist/assets/DeviceGroups-2Pvk0Cds.js +0 -1
- package/web/dist/assets/DeviceGroups-CP7CcyPD.js +0 -1
- package/web/dist/assets/FilePreview-BMB2tNyT.js +0 -2
- package/web/dist/assets/FilePreview-RGFQUbJo.js +0 -2
- package/web/dist/assets/GlobalSearchModal-BM5wxiqU.js +0 -1
- package/web/dist/assets/GlobalSearchModal-DGv_WINq.js +0 -1
- package/web/dist/assets/GroupConversation-B7SnuXj1.js +0 -61
- package/web/dist/assets/GroupConversation-Dda69q-2.js +0 -61
- package/web/dist/assets/ModelConfigModal-C-0Z4hUZ.js +0 -2
- package/web/dist/assets/ModelConfigModal-yqeadyab.js +0 -2
- package/web/dist/assets/ProviderOAuthControls-DY4SCfXg.js +0 -1
- package/web/dist/assets/SCMPanel-C4KbQvvK.js +0 -2
- package/web/dist/assets/SettingsModal-DxZp6D_g.js +0 -32
- package/web/dist/assets/SettingsModal-WhQzaOPt.js +0 -32
- package/web/dist/assets/TerminalPanel-D4By_RVc.js +0 -3
- package/web/dist/assets/TerminalPanel-lZw8-i3j.js +0 -3
- package/web/dist/assets/TuiOverlayModal-C3pAVuC8.js +0 -1
- package/web/dist/assets/TuiOverlayModal-D7_rEXcJ.js +0 -1
- package/web/dist/assets/app-globals-KqOVtmp1.js +0 -123
- package/web/dist/assets/canvas-client-BY6ojmle.js +0 -1
- package/web/dist/assets/desktop-CV6KKp9R.js +0 -1
- package/web/dist/assets/index-BawF7ZP5.js +0 -397
- package/web/dist/assets/index-BoGCoq5X.js +0 -397
- package/web/dist/assets/index-CVW9FoY2.css +0 -1
- package/web/dist/assets/plugin-host-Dn8Dd6SC.js +0 -1
- package/web/dist/assets/theme-D_bihpdN.js +0 -1
|
@@ -26,6 +26,11 @@ import { establishConversation, advanceConversationTask, recordConversationTurn,
|
|
|
26
26
|
import { DEFAULT_EXECUTION_SETTINGS } from "./execution-settings.js";
|
|
27
27
|
import { hasTaskLease, isRecoveringTask, recordTaskOutcome, settleTaskDependencies, settleTaskTerminalOutcome, rescanReadyTasksOnRecovery, sweepExpiredRecoveryLeases, } from "./task-settlement.js";
|
|
28
28
|
import { RELAY_LIMITS } from "./relay.js";
|
|
29
|
+
import { createHubMobileApp, acceptMobileNotification } from "./hub-mobile.js";
|
|
30
|
+
import { createMobilePushService } from "../mobile-push.js";
|
|
31
|
+
import { HubUpgradeError } from "./hub-upgrade.js";
|
|
32
|
+
import { installHubOrchestration } from "./hub-orchestration.js";
|
|
33
|
+
import { queueRouterJob, nextRouterAction } from "./group-router.js";
|
|
29
34
|
class HttpError extends Error {
|
|
30
35
|
status;
|
|
31
36
|
constructor(status, message) {
|
|
@@ -121,6 +126,21 @@ export async function createDeviceHub(options) {
|
|
|
121
126
|
};
|
|
122
127
|
const app = express();
|
|
123
128
|
app.disable("x-powered-by");
|
|
129
|
+
const loginLimit = new HubRateLimiter(10, 60000);
|
|
130
|
+
const mobilePush = createMobilePushService({ dataDir: options.dataDir });
|
|
131
|
+
const mobileApp = createHubMobileApp({
|
|
132
|
+
store,
|
|
133
|
+
publicUrl: options.publicUrl,
|
|
134
|
+
loginLimit,
|
|
135
|
+
mobilePush,
|
|
136
|
+
isOnline: (id) => options.isOnline?.(id) ?? false,
|
|
137
|
+
createCapability: (request) => options.relay?.createNativeCapability?.(request) ?? Promise.resolve(null),
|
|
138
|
+
});
|
|
139
|
+
app.use((req, res, next) => {
|
|
140
|
+
if (/^\/api\/(?:mobile-hub|mobile-push)(?:\/|$)/.test(req.path))
|
|
141
|
+
return mobileApp(req, res, next);
|
|
142
|
+
next();
|
|
143
|
+
});
|
|
124
144
|
app.use((req, _res, next) => {
|
|
125
145
|
if (!req.path.startsWith("/api/device-user/"))
|
|
126
146
|
return next();
|
|
@@ -138,6 +158,13 @@ export async function createDeviceHub(options) {
|
|
|
138
158
|
const suffix = req.path.slice("/api/device-user".length);
|
|
139
159
|
const conversationRoute = /^\/rooms\/[^/]+\/conversations(?:\/[^/]+(?:\/(?:messages|stop|deliveries|reviews|task-state|evidence|integrations(?:\/[^/]+(?:\/(?:verify|apply|cancel|reconcile|resume))?)?))?)?$/.test(suffix);
|
|
140
160
|
const taskRoute = /^\/rooms\/[^/]+\/tasks\/[^/]+(?:\/(?:journal|report))?$/.test(suffix);
|
|
161
|
+
const orchestrationRoute = /^\/(?:router-models|work-items(?:\/[^/]+)?|work-item-deliveries\/(?:claim|[^/]+\/(?:complete|fail))|rooms\/[^/]+\/(?:work-items(?:\/[^/]+)?|router\/jobs\/[^/]+\/retry))$/.test(suffix);
|
|
162
|
+
if ((orchestrationRoute && ["GET", "POST", "PATCH"].includes(req.method)) ||
|
|
163
|
+
(req.method === "POST" && /^\/rooms\/[^/]+$/.test(suffix))) {
|
|
164
|
+
users.set(req, { device, account: { id: owner.id, username: owner.username } });
|
|
165
|
+
req.url = req.url.replace("/api/device-user/", "/api/");
|
|
166
|
+
return next();
|
|
167
|
+
}
|
|
141
168
|
const webhookRoute = /^\/rooms\/[^/]+\/(?:webhooks(?:\/[^/]+(?:\/(?:delete|regenerate-token|test))?)?|hub-relay)$/.test(suffix);
|
|
142
169
|
if (!((req.method === "GET" &&
|
|
143
170
|
(conversationRoute ||
|
|
@@ -145,10 +172,11 @@ export async function createDeviceHub(options) {
|
|
|
145
172
|
webhookRoute ||
|
|
146
173
|
/^\/rooms\/[^/]+\/(?:events|interactions|transfers|locks|blackboard)$/.test(suffix) ||
|
|
147
174
|
/^\/rooms\/[^/]+\/transfers\/[^/]+\/preview$/.test(suffix) ||
|
|
148
|
-
["/devices", "/bots", "/rooms"].includes(suffix) ||
|
|
175
|
+
["/devices", "/bots", "/rooms", "/system/upgrade"].includes(suffix) ||
|
|
149
176
|
/^\/rooms\/[^/]+$/.test(suffix))) ||
|
|
150
177
|
(["POST", "PUT"].includes(req.method) &&
|
|
151
178
|
(suffix === "/rooms" ||
|
|
179
|
+
suffix === "/system/upgrade" ||
|
|
152
180
|
conversationRoute ||
|
|
153
181
|
webhookRoute ||
|
|
154
182
|
/^\/rooms\/[^/]+\/(messages|rename|members|clear|delete|interactions|canvas|blackboard(?:\/sections\/[^/]+)?)$/.test(suffix) ||
|
|
@@ -171,6 +199,11 @@ export async function createDeviceHub(options) {
|
|
|
171
199
|
fail(429, "Too many device writes");
|
|
172
200
|
agents.set(req, agent);
|
|
173
201
|
const suffix = req.path.slice("/api/agent".length);
|
|
202
|
+
if ((req.method === "GET" && suffix === "/router/jobs/next") ||
|
|
203
|
+
(req.method === "POST" && /^\/router\/jobs\/[^/]+\/(?:complete|renew|fail)$/.test(suffix))) {
|
|
204
|
+
req.url = req.url.replace("/api/agent/", "/api/");
|
|
205
|
+
return next();
|
|
206
|
+
}
|
|
174
207
|
if ((req.method === "GET" &&
|
|
175
208
|
(["/devices", "/bots", "/rooms"].includes(suffix) ||
|
|
176
209
|
/^\/rooms\/[^/]+(?:\/(?:history|locks|blackboard(?:\/sections\/[^/]+)?))?$/.test(suffix) ||
|
|
@@ -181,7 +214,9 @@ export async function createDeviceHub(options) {
|
|
|
181
214
|
/^\/rooms\/[^/]+\/(?:messages|blackboard|conversations(?:\/[^/]+\/(?:messages|stop|deliveries|reviews|attention|task-state|integrations(?:\/[^/]+(?:\/(?:verify|apply|cancel|reconcile|resume))?)?))?)$/.test(suffix))) ||
|
|
182
215
|
(req.method === "PUT" && /^\/rooms\/[^/]+\/blackboard(?:\/sections\/[^/]+)?$/.test(suffix)))
|
|
183
216
|
req.url = req.url.replace("/api/agent/", "/api/");
|
|
184
|
-
else if (!((suffix === "/transfers" && req.method === "POST") ||
|
|
217
|
+
else if (!((suffix === "/transfers" && req.method === "POST") ||
|
|
218
|
+
(suffix === "/bots" && req.method === "PUT") ||
|
|
219
|
+
(suffix === "/mobile-notifications" && req.method === "POST")))
|
|
185
220
|
fail(404, "Agent route missing");
|
|
186
221
|
next();
|
|
187
222
|
});
|
|
@@ -204,6 +239,9 @@ export async function createDeviceHub(options) {
|
|
|
204
239
|
app.use((req, res, next) => {
|
|
205
240
|
if (agents.has(req) && req.path === "/api/agent/transfers")
|
|
206
241
|
return next();
|
|
242
|
+
if (req.method === "POST" &&
|
|
243
|
+
(req.path === "/api/work-items/ingest" || /^\/api\/router\/jobs\/[^/]+\/complete$/.test(req.path)))
|
|
244
|
+
return contractJson(req, res, next);
|
|
207
245
|
if (req.method === "POST" &&
|
|
208
246
|
/^\/api\/rooms\/[^/]+\/(?:messages|tasks|conversations(?:\/[^/]+\/messages)?)$/.test(req.path))
|
|
209
247
|
return contractJson(req, res, next);
|
|
@@ -218,7 +256,14 @@ export async function createDeviceHub(options) {
|
|
|
218
256
|
}
|
|
219
257
|
json(req, res, next);
|
|
220
258
|
});
|
|
221
|
-
|
|
259
|
+
app.post("/api/agent/mobile-notifications", async (req, res) => {
|
|
260
|
+
const agent = agents.get(req);
|
|
261
|
+
if (store.getDeviceOwner(agent.device.id) !== agent.account.id)
|
|
262
|
+
fail(401, "Device revoked");
|
|
263
|
+
const device = store.getDevice(agent.device.id);
|
|
264
|
+
await acceptMobileNotification(req.body, device, mobilePush);
|
|
265
|
+
res.json({ ok: true });
|
|
266
|
+
});
|
|
222
267
|
const pairLimit = new HubRateLimiter(20, 60000);
|
|
223
268
|
const pairs = new Map();
|
|
224
269
|
const sweepPairs = () => {
|
|
@@ -244,8 +289,12 @@ export async function createDeviceHub(options) {
|
|
|
244
289
|
(options.deviceDomain ? `${origin.protocol}//${device.id}.${options.deviceDomain}` : null),
|
|
245
290
|
alias: options.portals?.getAlias(device.id) ?? null,
|
|
246
291
|
});
|
|
292
|
+
const publicAccount = (current) => ({
|
|
293
|
+
...current,
|
|
294
|
+
canUpgradeHub: store.snapshot().accounts[0]?.id === current.id,
|
|
295
|
+
});
|
|
247
296
|
for (const route of ["/api/me", "/api/auth/me"])
|
|
248
|
-
app.get(route, (req, res) => res.json({ account: account(req) }));
|
|
297
|
+
app.get(route, (req, res) => res.json({ account: publicAccount(account(req)) }));
|
|
249
298
|
app.post("/api/auth/register", async (req, res) => {
|
|
250
299
|
if (!loginLimit.allow(ip(req)))
|
|
251
300
|
fail(429, "Too many attempts");
|
|
@@ -271,7 +320,7 @@ export async function createDeviceHub(options) {
|
|
|
271
320
|
return { id: entry.id, username };
|
|
272
321
|
});
|
|
273
322
|
res.setHeader("Set-Cookie", auth.cookie(sessionToken));
|
|
274
|
-
res.status(201).json({ account: created });
|
|
323
|
+
res.status(201).json({ account: publicAccount(created) });
|
|
275
324
|
});
|
|
276
325
|
app.post("/api/auth/login", async (req, res) => {
|
|
277
326
|
if (!loginLimit.allow(ip(req)))
|
|
@@ -279,7 +328,6 @@ export async function createDeviceHub(options) {
|
|
|
279
328
|
const username = text(req.body?.username, 64).trim().toLowerCase();
|
|
280
329
|
const password = text(req.body?.["pass" + "word"], 1024);
|
|
281
330
|
const entry = store.snapshot().accounts.find((item) => item.username === username);
|
|
282
|
-
// Run the same KDF for missing accounts, avoiding a cheap username oracle.
|
|
283
331
|
if (!(await verifyPassword(password, entry?.passwordHash ?? `scrypt:${"0".repeat(32)}:${"0".repeat(128)}`)) ||
|
|
284
332
|
!entry)
|
|
285
333
|
fail(401, "Invalid credentials");
|
|
@@ -291,7 +339,7 @@ export async function createDeviceHub(options) {
|
|
|
291
339
|
draft.sessions.push({ accountId: entry.id, hash: hashSecret(sessionToken), expiresAt: Date.now() + SESSION_TTL });
|
|
292
340
|
});
|
|
293
341
|
res.setHeader("Set-Cookie", auth.cookie(sessionToken));
|
|
294
|
-
res.json({ account: { id: entry.id, username: entry.username } });
|
|
342
|
+
res.json({ account: publicAccount({ id: entry.id, username: entry.username }) });
|
|
295
343
|
});
|
|
296
344
|
app.post("/api/auth/logout", async (req, res) => {
|
|
297
345
|
const value = auth.getToken(req);
|
|
@@ -301,36 +349,39 @@ export async function createDeviceHub(options) {
|
|
|
301
349
|
res.setHeader("Set-Cookie", auth.cookie("", true));
|
|
302
350
|
res.json({ ok: true });
|
|
303
351
|
});
|
|
352
|
+
const upgradeOwner = (req) => {
|
|
353
|
+
const current = account(req);
|
|
354
|
+
if (store.snapshot().accounts[0]?.id !== current.id)
|
|
355
|
+
fail(403, "Only the Hub owner can upgrade the service");
|
|
356
|
+
return current;
|
|
357
|
+
};
|
|
304
358
|
app.post("/api/system/upgrade", async (req, res) => {
|
|
305
|
-
|
|
359
|
+
const current = upgradeOwner(req);
|
|
360
|
+
if (!options.upgradeManager)
|
|
361
|
+
fail(409, "Hub updates require an installed standalone service");
|
|
306
362
|
try {
|
|
307
|
-
|
|
363
|
+
const job = await options.upgradeManager.start(current.id);
|
|
364
|
+
res.setHeader("Cache-Control", "no-store");
|
|
365
|
+
res.status(202).json({ ok: true, job });
|
|
366
|
+
}
|
|
367
|
+
catch (error) {
|
|
368
|
+
if (error instanceof HubUpgradeError)
|
|
369
|
+
return res.status(error.status).json({ error: error.message });
|
|
370
|
+
throw error;
|
|
308
371
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const cliPath = join(getPkgRoot(), "bin", "pi-web-ui.mjs");
|
|
323
|
-
const child = spawn(process.execPath, [cliPath, "hub", "update"], {
|
|
324
|
-
detached: true,
|
|
325
|
-
stdio: "ignore",
|
|
326
|
-
windowsHide: true,
|
|
327
|
-
});
|
|
328
|
-
child.unref();
|
|
329
|
-
}
|
|
330
|
-
catch {
|
|
331
|
-
/* ignore */
|
|
332
|
-
}
|
|
333
|
-
}, 500);
|
|
372
|
+
});
|
|
373
|
+
app.get("/api/system/upgrade", async (req, res) => {
|
|
374
|
+
upgradeOwner(req);
|
|
375
|
+
if (!options.upgradeManager)
|
|
376
|
+
fail(409, "Hub updates require an installed standalone service");
|
|
377
|
+
const id = typeof req.query.id === "string" ? req.query.id : undefined;
|
|
378
|
+
if (id && !/^[a-f0-9-]{36}$/.test(id))
|
|
379
|
+
fail(400, "Invalid upgrade job ID");
|
|
380
|
+
const job = await options.upgradeManager.status(id);
|
|
381
|
+
res.setHeader("Cache-Control", "no-store");
|
|
382
|
+
if (!job)
|
|
383
|
+
return res.status(404).json({ error: "Hub upgrade job not found" });
|
|
384
|
+
res.json({ ok: true, job });
|
|
334
385
|
});
|
|
335
386
|
app.post("/api/pair/start", (req, res) => {
|
|
336
387
|
if (!pairLimit.allow(ip(req)))
|
|
@@ -433,8 +484,6 @@ export async function createDeviceHub(options) {
|
|
|
433
484
|
if (room.primaryBotId && removedBots.has(room.primaryBotId))
|
|
434
485
|
delete room.primaryBotId;
|
|
435
486
|
}
|
|
436
|
-
// A revoked device can no longer continue its conversations: close them now so the next turn
|
|
437
|
-
// reports a reason instead of a late 409 against a Bot that no longer exists.
|
|
438
487
|
for (const conversation of draft.conversations)
|
|
439
488
|
if (!conversation.closed && removedBots.has(conversation.botId)) {
|
|
440
489
|
conversation.closed = true;
|
|
@@ -953,7 +1002,6 @@ export async function createDeviceHub(options) {
|
|
|
953
1002
|
};
|
|
954
1003
|
app.put("/api/rooms/:id/blackboard/sections/:sectionId", handleBlackboardSectionUpdate);
|
|
955
1004
|
app.post("/api/rooms/:id/blackboard/sections/:sectionId", handleBlackboardSectionUpdate);
|
|
956
|
-
// === Group Webhooks ===
|
|
957
1005
|
app.get("/api/rooms/:id/webhooks", (req, res) => {
|
|
958
1006
|
const owner = account(req);
|
|
959
1007
|
if (agents.has(req))
|
|
@@ -1188,7 +1236,7 @@ export async function createDeviceHub(options) {
|
|
|
1188
1236
|
if (settings.allowBotMentions) {
|
|
1189
1237
|
targets.push(...groupMentionTargets(content, activeRoom, draft.bots, settings.botMentionBudgetPerTurn));
|
|
1190
1238
|
}
|
|
1191
|
-
if (!targets.length && activeRoom.primaryBotId) {
|
|
1239
|
+
if (!targets.length && !activeRoom.router?.enabled && activeRoom.primaryBotId) {
|
|
1192
1240
|
if (activeRoom.botIds.includes(activeRoom.primaryBotId) &&
|
|
1193
1241
|
validBot(draft, activeRoom.primaryBotId, activeRoom.accountId)) {
|
|
1194
1242
|
targets.push(activeRoom.primaryBotId);
|
|
@@ -1265,6 +1313,14 @@ export async function createDeviceHub(options) {
|
|
|
1265
1313
|
: undefined;
|
|
1266
1314
|
draft.tasks.push(...tasks);
|
|
1267
1315
|
draft.messages.push(message);
|
|
1316
|
+
if (allowTrigger && !targets.length)
|
|
1317
|
+
queueRouterJob(draft, {
|
|
1318
|
+
accountId: activeRoom.accountId,
|
|
1319
|
+
roomId: activeRoom.id,
|
|
1320
|
+
eventKey: `webhook:${message.id}`,
|
|
1321
|
+
trigger: { type: "webhook_message", messageId: message.id },
|
|
1322
|
+
text: content,
|
|
1323
|
+
}, now);
|
|
1268
1324
|
draft.receipts.push({
|
|
1269
1325
|
accountId: activeRoom.accountId,
|
|
1270
1326
|
roomId: activeRoom.id,
|
|
@@ -1281,6 +1337,7 @@ export async function createDeviceHub(options) {
|
|
|
1281
1337
|
.filter((t) => t.roomId === activeRoom.id &&
|
|
1282
1338
|
isTerminal(t.status) &&
|
|
1283
1339
|
!taskHasImmutableEvidence(t) &&
|
|
1340
|
+
!draft.workItems.some((w) => w.taskIds.includes(t.id)) &&
|
|
1284
1341
|
!draft.conversations.some((c) => c.rootTaskId === t.id || c.id === t.conversationId))
|
|
1285
1342
|
.slice(0, -getHistoryLimit())
|
|
1286
1343
|
.map((t) => t.id));
|
|
@@ -1301,7 +1358,6 @@ export async function createDeviceHub(options) {
|
|
|
1301
1358
|
tasks: result.tasks.map(publicTask),
|
|
1302
1359
|
});
|
|
1303
1360
|
});
|
|
1304
|
-
// === Task Details, Journal, and Reports ===
|
|
1305
1361
|
app.get("/api/rooms/:id/tasks/:taskId", (req, res) => {
|
|
1306
1362
|
const acc = account(req);
|
|
1307
1363
|
const state = store.snapshot();
|
|
@@ -1523,9 +1579,6 @@ export async function createDeviceHub(options) {
|
|
|
1523
1579
|
const limit = typeof req.query.limit === "string" ? parseInt(req.query.limit, 10) : undefined;
|
|
1524
1580
|
const direction = req.query.direction === "backward" ? "backward" : "forward";
|
|
1525
1581
|
const page = await taskJournalManager.getPage(task.id, acc.id, room.id, { cursor, limit, direction });
|
|
1526
|
-
// The task exists but never wrote a journal segment (queued, failed before the first progress
|
|
1527
|
-
// event, or created before the journal existed). An empty audit trail is a valid state, not a
|
|
1528
|
-
// missing resource: 404 here made every such task render as a broken panel in the UI.
|
|
1529
1582
|
if (!page)
|
|
1530
1583
|
return res.json({
|
|
1531
1584
|
taskId: task.id,
|
|
@@ -1685,8 +1738,23 @@ export async function createDeviceHub(options) {
|
|
|
1685
1738
|
status: 409,
|
|
1686
1739
|
code: "ACTIVE_TASKS",
|
|
1687
1740
|
});
|
|
1688
|
-
if (operation === "delete")
|
|
1741
|
+
if (operation === "delete") {
|
|
1689
1742
|
draft.rooms = draft.rooms.filter((r) => r.id !== room.id);
|
|
1743
|
+
draft.workItems = draft.workItems.filter((w) => w.roomId !== room.id);
|
|
1744
|
+
draft.workItemEvents = draft.workItemEvents.filter((w) => w.roomId !== room.id);
|
|
1745
|
+
draft.workItemOutbox = draft.workItemOutbox.filter((w) => w.roomId !== room.id);
|
|
1746
|
+
draft.routerJobs = draft.routerJobs.filter((j) => j.roomId !== room.id);
|
|
1747
|
+
}
|
|
1748
|
+
else {
|
|
1749
|
+
room.routerRevision = (room.routerRevision ?? 0) + 1;
|
|
1750
|
+
for (const job of draft.routerJobs.filter((j) => j.roomId === room.id && (j.status === "queued" || j.status === "running"))) {
|
|
1751
|
+
job.status = "failed";
|
|
1752
|
+
job.error = "Group history cleared";
|
|
1753
|
+
job.updatedAt = Date.now();
|
|
1754
|
+
delete job.leaseToken;
|
|
1755
|
+
delete job.leaseExpiresAt;
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1690
1758
|
draft.messages = draft.messages.filter((m) => m.roomId !== room.id);
|
|
1691
1759
|
draft.tasks = draft.tasks.filter((t) => t.roomId !== room.id);
|
|
1692
1760
|
draft.receipts = draft.receipts.filter((r) => r.roomId !== room.id);
|
|
@@ -1766,7 +1834,6 @@ export async function createDeviceHub(options) {
|
|
|
1766
1834
|
app.post("/api/rooms/:id/conversations/:conversationId/integrations/:integrationId/reconcile", async (req, res) => {
|
|
1767
1835
|
const owner = account(req);
|
|
1768
1836
|
const agent = agents.get(req);
|
|
1769
|
-
// Historical queries keep the authenticated Bot identity even after its registry entry is disabled/deleted.
|
|
1770
1837
|
const actor = {
|
|
1771
1838
|
accountId: owner.id,
|
|
1772
1839
|
...(agent
|
|
@@ -1883,7 +1950,6 @@ export async function createDeviceHub(options) {
|
|
|
1883
1950
|
status: 409,
|
|
1884
1951
|
code: "ACTIVE_TASKS",
|
|
1885
1952
|
});
|
|
1886
|
-
// Delivery/review records are the audit trail; deleting them is a separate, explicit decision.
|
|
1887
1953
|
if (conversationHasAuditRecords(draft, conversation.id))
|
|
1888
1954
|
fail(409, "Conversation has delivery history; audit records are retained");
|
|
1889
1955
|
dropConversationRecords(draft, conversation.id);
|
|
@@ -2275,13 +2341,10 @@ export async function createDeviceHub(options) {
|
|
|
2275
2341
|
...deliveryHistory(state, conversation.id),
|
|
2276
2342
|
});
|
|
2277
2343
|
});
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
"/api/rooms/:id/tasks",
|
|
2281
|
-
"/api/rooms/:id/conversations",
|
|
2282
|
-
"/api/rooms/:id/conversations/:conversationId/messages",
|
|
2283
|
-
], async (req, res) => {
|
|
2344
|
+
const routerSources = new WeakMap();
|
|
2345
|
+
const postRoomMessage = async (req, res) => {
|
|
2284
2346
|
const owner = account(req);
|
|
2347
|
+
const routerSource = routerSources.get(req);
|
|
2285
2348
|
const content = text(req.body?.text);
|
|
2286
2349
|
const conversationApi = req.path.includes("/conversations");
|
|
2287
2350
|
const conversationId = req.params.conversationId;
|
|
@@ -2361,10 +2424,9 @@ export async function createDeviceHub(options) {
|
|
|
2361
2424
|
contractRevision: contract?.revision,
|
|
2362
2425
|
sourceDeviceId: (agents.get(req) ?? users.get(req))?.device.id,
|
|
2363
2426
|
sourceBotId: agents.has(req) ? req.body?.sourceBotId : undefined,
|
|
2364
|
-
senderType: agents.has(req) ? "bot" : "human",
|
|
2427
|
+
senderType: routerSource ? "router" : agents.has(req) ? "bot" : "human",
|
|
2365
2428
|
};
|
|
2366
2429
|
const fingerprint = hashSecret(JSON.stringify(fingerprintFields));
|
|
2367
|
-
// v45 chat receipts predate the optional execution contract fields.
|
|
2368
2430
|
const legacyFingerprint = executionMode === "chat" && !contract
|
|
2369
2431
|
? hashSecret(JSON.stringify({ ...fingerprintFields, executionMode: undefined }))
|
|
2370
2432
|
: undefined;
|
|
@@ -2373,6 +2435,13 @@ export async function createDeviceHub(options) {
|
|
|
2373
2435
|
const room = draft.rooms.find((r) => r.id === req.params.id && r.accountId === owner.id);
|
|
2374
2436
|
if (!room)
|
|
2375
2437
|
fail(404, "Room missing");
|
|
2438
|
+
if (routerSource)
|
|
2439
|
+
nextRouterAction(draft, {
|
|
2440
|
+
accountId: owner.id,
|
|
2441
|
+
jobId: routerSource.id,
|
|
2442
|
+
deviceId: routerSource.deviceId,
|
|
2443
|
+
leaseToken: routerSource.leaseToken,
|
|
2444
|
+
}, Date.now());
|
|
2376
2445
|
const source = ownBot(req, draft);
|
|
2377
2446
|
const userSource = users.get(req)?.device;
|
|
2378
2447
|
let conversation = conversationId
|
|
@@ -2396,9 +2465,7 @@ export async function createDeviceHub(options) {
|
|
|
2396
2465
|
fail(400, "Dependency target task is not in this room");
|
|
2397
2466
|
const depTask = dependsOnTaskId ? draft.tasks.find((t) => t.id === dependsOnTaskId) : undefined;
|
|
2398
2467
|
const dependencyActive = Boolean(depTask);
|
|
2399
|
-
|
|
2400
|
-
// silently fall back to the primary Bot just because a client did not pre-resolve the mentions.
|
|
2401
|
-
const canParseMentions = (!source || settings.allowBotMentions) && !conversationApi && !conversation && !targets.length;
|
|
2468
|
+
const canParseMentions = !routerSource && (!source || settings.allowBotMentions) && !conversationApi && !conversation && !targets.length;
|
|
2402
2469
|
if (canParseMentions)
|
|
2403
2470
|
targets.push(...groupMentionTargets(content, room, draft.bots, settings.botMentionBudgetPerTurn));
|
|
2404
2471
|
if (targets.some((id) => !room.botIds.includes(id) || !validBot(draft, id, owner.id)))
|
|
@@ -2457,7 +2524,6 @@ export async function createDeviceHub(options) {
|
|
|
2457
2524
|
const existingTasks = draft.tasks.filter((t) => t.roomId === room.id && t.accountId === owner.id && t.contract?.id === contract.id);
|
|
2458
2525
|
if (existingTasks.some((t) => t.contract.revision === contract.revision && t.contract.digest !== contract.digest))
|
|
2459
2526
|
fail(409, "Contract id and revision already bind different content");
|
|
2460
|
-
// Queued leases and recovery represent live work. Replace only settled versions.
|
|
2461
2527
|
if (existingTasks.some((t) => t.contract.revision < contract.revision && (!isTerminal(t.status) || isRecoveringTask(t, Date.now()))))
|
|
2462
2528
|
fail(409, "Cannot advance contract revision while an older revision is active");
|
|
2463
2529
|
if (depTask?.contract?.id === contract.id && depTask.contract.revision !== contract.revision)
|
|
@@ -2468,8 +2534,12 @@ export async function createDeviceHub(options) {
|
|
|
2468
2534
|
}
|
|
2469
2535
|
}
|
|
2470
2536
|
}
|
|
2471
|
-
|
|
2472
|
-
|
|
2537
|
+
if (!source &&
|
|
2538
|
+
!routerSource &&
|
|
2539
|
+
!conversationApi &&
|
|
2540
|
+
!targets.length &&
|
|
2541
|
+
!room.router?.enabled &&
|
|
2542
|
+
room.primaryBotId) {
|
|
2473
2543
|
if (!room.botIds.includes(room.primaryBotId) || !validBot(draft, room.primaryBotId, owner.id))
|
|
2474
2544
|
fail(400, "Primary Bot is unavailable");
|
|
2475
2545
|
targets.push(room.primaryBotId);
|
|
@@ -2523,11 +2593,18 @@ export async function createDeviceHub(options) {
|
|
|
2523
2593
|
const parent = parentTaskId ? draft.tasks.find((t) => t.id === parentTaskId) : undefined;
|
|
2524
2594
|
if (source && targets.length && (!parent || parent.botId !== source.id))
|
|
2525
2595
|
fail(400, "Device dispatch requires its own running or terminal parent task");
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2596
|
+
const priorRouterTaskId = routerSource
|
|
2597
|
+
? draft.messages.find((m) => m.routerJobId === routerSource.id && m.taskIds?.length)?.taskIds?.[0]
|
|
2598
|
+
: undefined;
|
|
2599
|
+
const priorRouterTask = priorRouterTaskId ? draft.tasks.find((t) => t.id === priorRouterTaskId) : undefined;
|
|
2600
|
+
const root = parent
|
|
2601
|
+
? draft.tasks.find((t) => t.id === (parent.rootTaskId ?? parent.id))
|
|
2602
|
+
: priorRouterTask
|
|
2603
|
+
? draft.tasks.find((t) => t.id === (priorRouterTask.rootTaskId ?? priorRouterTask.id))
|
|
2604
|
+
: undefined;
|
|
2605
|
+
if ((parent || priorRouterTaskId) && targets.length && !root)
|
|
2529
2606
|
fail(409, "Dispatch root expired");
|
|
2530
|
-
const depth = parent ? (parent.dispatchDepth ?? 0) + 1 : 0;
|
|
2607
|
+
const depth = parent ? (parent.dispatchDepth ?? 0) + 1 : (priorRouterTask?.dispatchDepth ?? 0);
|
|
2531
2608
|
if (planOnly && targets.some((id) => !validBot(draft, id, owner.id)?.tools?.includes("plan_update")))
|
|
2532
2609
|
fail(409, "Planning requires plan_update authorization in each Bot tool allowlist");
|
|
2533
2610
|
if (targets.length && depth > settings.maxDispatchDepth)
|
|
@@ -2536,12 +2613,10 @@ export async function createDeviceHub(options) {
|
|
|
2536
2613
|
fail(409, "Dispatch budget exhausted");
|
|
2537
2614
|
if (root && targets.length)
|
|
2538
2615
|
root.dispatchCount = (root.dispatchCount ?? 0) + targets.length;
|
|
2539
|
-
if (draft.tasks.filter((t) => t.roomId === room.id && taskPending(t)).length + targets.length >
|
|
2540
|
-
getHistoryLimit())
|
|
2616
|
+
if (draft.tasks.filter((t) => t.roomId === room.id && taskPending(t)).length + targets.length > getHistoryLimit())
|
|
2541
2617
|
fail(409, "Too many active tasks");
|
|
2542
2618
|
if (!conversation &&
|
|
2543
|
-
draft.conversations.filter((c) => c.roomId === room.id && !c.closed).length + targets.length >
|
|
2544
|
-
getHistoryLimit())
|
|
2619
|
+
draft.conversations.filter((c) => c.roomId === room.id && !c.closed).length + targets.length > getHistoryLimit())
|
|
2545
2620
|
fail(409, "Too many open conversations; stop or delete conversations to free capacity");
|
|
2546
2621
|
const now = Date.now();
|
|
2547
2622
|
const rootId = root?.id ?? randomUUID();
|
|
@@ -2647,14 +2722,17 @@ export async function createDeviceHub(options) {
|
|
|
2647
2722
|
roomId: room.id,
|
|
2648
2723
|
accountId: owner.id,
|
|
2649
2724
|
text: messageText,
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
: {
|
|
2653
|
-
|
|
2654
|
-
id:
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2725
|
+
...(routerSource ? { routerJobId: routerSource.id } : {}),
|
|
2726
|
+
sender: routerSource
|
|
2727
|
+
? { type: "router", id: `router:${room.id}`, name: "群组 AI", sourceDeviceId: routerSource.deviceId }
|
|
2728
|
+
: source
|
|
2729
|
+
? { type: "bot", id: source.id, name: source.name, sourceDeviceId: source.deviceId }
|
|
2730
|
+
: {
|
|
2731
|
+
type: "human",
|
|
2732
|
+
id: owner.id,
|
|
2733
|
+
name: userSource ? `${owner.username} · ${userSource.name}` : owner.username,
|
|
2734
|
+
...(userSource ? { sourceDeviceId: userSource.id } : {}),
|
|
2735
|
+
},
|
|
2658
2736
|
createdAt: now,
|
|
2659
2737
|
taskIds: tasks.map((t) => t.id),
|
|
2660
2738
|
targetBotIds: targets,
|
|
@@ -2662,12 +2740,19 @@ export async function createDeviceHub(options) {
|
|
|
2662
2740
|
...(tasks.length === 1 ? { conversationId: tasks[0].conversationId } : {}),
|
|
2663
2741
|
...(tasks.length ? { conversationIds: tasks.map((task) => task.conversationId) } : {}),
|
|
2664
2742
|
};
|
|
2665
|
-
// Freeze shared context before any recipient starts. Parallel answers cannot leak into siblings.
|
|
2666
2743
|
const context = tasks.length
|
|
2667
2744
|
? groupTaskContext(room, draft.bots, draft.messages, settings.groupContextBytes)
|
|
2668
2745
|
: undefined;
|
|
2669
2746
|
draft.tasks.push(...tasks);
|
|
2670
2747
|
draft.messages.push(message);
|
|
2748
|
+
if (!source && !routerSource && !targets.length)
|
|
2749
|
+
queueRouterJob(draft, {
|
|
2750
|
+
accountId: owner.id,
|
|
2751
|
+
roomId: room.id,
|
|
2752
|
+
eventKey: `message:${message.id}`,
|
|
2753
|
+
trigger: { type: "human_message", messageId: message.id },
|
|
2754
|
+
text: content,
|
|
2755
|
+
}, now);
|
|
2671
2756
|
draft.receipts.push({
|
|
2672
2757
|
accountId: owner.id,
|
|
2673
2758
|
roomId: room.id,
|
|
@@ -2678,13 +2763,13 @@ export async function createDeviceHub(options) {
|
|
|
2678
2763
|
});
|
|
2679
2764
|
const oldMessages = draft.messages.filter((m) => m.roomId === room.id).slice(0, -getHistoryLimit());
|
|
2680
2765
|
const removed = new Set(oldMessages.map((m) => m.id));
|
|
2681
|
-
// Retention evicts messages, never the replay guard: a retry must not re-dispatch evicted work.
|
|
2682
2766
|
draft.messages = draft.messages.filter((m) => !removed.has(m.id));
|
|
2683
2767
|
trimRoomReceipts(draft, room.id);
|
|
2684
2768
|
const oldTasks = new Set(draft.tasks
|
|
2685
2769
|
.filter((t) => t.roomId === room.id &&
|
|
2686
2770
|
isTerminal(t.status) &&
|
|
2687
2771
|
!taskHasImmutableEvidence(t) &&
|
|
2772
|
+
!draft.workItems.some((w) => w.taskIds.includes(t.id)) &&
|
|
2688
2773
|
!draft.conversations.some((c) => c.rootTaskId === t.id || c.id === t.conversationId))
|
|
2689
2774
|
.slice(0, -getHistoryLimit())
|
|
2690
2775
|
.map((t) => t.id));
|
|
@@ -2716,6 +2801,52 @@ export async function createDeviceHub(options) {
|
|
|
2716
2801
|
message: result.message,
|
|
2717
2802
|
tasks: result.tasks.map((task) => publicTask(state.tasks.find((entry) => entry.id === task.id && entry.attemptId === task.attemptId) ?? task)),
|
|
2718
2803
|
});
|
|
2804
|
+
};
|
|
2805
|
+
app.post([
|
|
2806
|
+
"/api/rooms/:id/messages",
|
|
2807
|
+
"/api/rooms/:id/tasks",
|
|
2808
|
+
"/api/rooms/:id/conversations",
|
|
2809
|
+
"/api/rooms/:id/conversations/:conversationId/messages",
|
|
2810
|
+
], postRoomMessage);
|
|
2811
|
+
installHubOrchestration({
|
|
2812
|
+
app,
|
|
2813
|
+
store,
|
|
2814
|
+
actor(req) {
|
|
2815
|
+
const owner = account(req);
|
|
2816
|
+
return { accountId: owner.id, deviceId: (agents.get(req) ?? users.get(req))?.device.id, human: !agents.has(req) };
|
|
2817
|
+
},
|
|
2818
|
+
async getModels(_req, deviceId) {
|
|
2819
|
+
if (!options.relay?.callDevice)
|
|
2820
|
+
fail(503, "Device relay unavailable");
|
|
2821
|
+
const result = await options.relay.callDevice(deviceId, "group_router_models", {});
|
|
2822
|
+
return { deviceId, models: Array.isArray(result) ? result : (result?.models ?? []) };
|
|
2823
|
+
},
|
|
2824
|
+
async sendMessage(job, action, key) {
|
|
2825
|
+
const state = store.snapshot(), owner = state.accounts.find((a) => a.id === job.accountId), device = state.devices.find((d) => d.id === job.deviceId && d.accountId === job.accountId);
|
|
2826
|
+
if (!owner || !device)
|
|
2827
|
+
fail(403, "Router device revoked");
|
|
2828
|
+
const parentId = action.type === "dispatch" && job.trigger.type === "task_result" ? job.trigger.taskId : undefined;
|
|
2829
|
+
const request = {
|
|
2830
|
+
params: { id: job.roomId },
|
|
2831
|
+
path: `/api/rooms/${job.roomId}/messages`,
|
|
2832
|
+
body: {
|
|
2833
|
+
text: action.text,
|
|
2834
|
+
targetBotIds: action.type === "dispatch" ? [action.botId] : [],
|
|
2835
|
+
idempotencyKey: key,
|
|
2836
|
+
...(parentId ? { parentTaskId: parentId } : {}),
|
|
2837
|
+
...(action.type === "dispatch" ? { executionMode: action.executionMode, contract: action.contract } : {}),
|
|
2838
|
+
},
|
|
2839
|
+
};
|
|
2840
|
+
users.set(request, { device, account: { id: owner.id, username: owner.username } });
|
|
2841
|
+
routerSources.set(request, job);
|
|
2842
|
+
let response;
|
|
2843
|
+
await postRoomMessage(request, {
|
|
2844
|
+
json: (value) => {
|
|
2845
|
+
response = value;
|
|
2846
|
+
},
|
|
2847
|
+
});
|
|
2848
|
+
return response;
|
|
2849
|
+
},
|
|
2719
2850
|
});
|
|
2720
2851
|
app.post("/api/devices/:id/remark", async (req, res) => {
|
|
2721
2852
|
const owner = account(req);
|
|
@@ -2815,9 +2946,8 @@ export async function createDeviceHub(options) {
|
|
|
2815
2946
|
req.headers.origin = origin.origin;
|
|
2816
2947
|
if (!options.relay?.handleOpen)
|
|
2817
2948
|
fail(503, "Relay unavailable");
|
|
2818
|
-
await options.relay.handleOpen(req, res, String(req.params.id));
|
|
2949
|
+
await options.relay.handleOpen(req, res, String(req.params.id), false, users.has(req) && req.body?.preferLan === true);
|
|
2819
2950
|
});
|
|
2820
|
-
// No catch-all: the runner mounts the UI after creation.
|
|
2821
2951
|
app.use((error, _req, res, _next) => {
|
|
2822
2952
|
res.status(error.status ?? 500).json({
|
|
2823
2953
|
error: error.status && error.status < 500 ? error.message : "Storage or internal error",
|
|
@@ -2830,7 +2960,6 @@ export async function createDeviceHub(options) {
|
|
|
2830
2960
|
return;
|
|
2831
2961
|
app(req, res);
|
|
2832
2962
|
});
|
|
2833
|
-
// Accepted queued tasks remain in flight until a terminal event, including asynchronous relay delivery.
|
|
2834
2963
|
const deliveredTasks = new Set();
|
|
2835
2964
|
async function releaseLocksAndWake(roomId, taskId) {
|
|
2836
2965
|
const promoted = lockManager.releaseLocks(roomId, taskId);
|
|
@@ -3035,8 +3164,6 @@ export async function createDeviceHub(options) {
|
|
|
3035
3164
|
const taskState = committed.conversations.find((entry) => entry.id === task.conversationId)?.taskState;
|
|
3036
3165
|
const wire = {
|
|
3037
3166
|
...task,
|
|
3038
|
-
// Runtime consumes sealed snapshots directly. Legacy copies would count
|
|
3039
|
-
// their serialized size twice and can exceed the relay frame ceiling.
|
|
3040
3167
|
...(task.contextManifest ? {} : { context, taskState }),
|
|
3041
3168
|
executionMode: task.executionMode ?? task.contract?.executionMode ?? "chat",
|
|
3042
3169
|
};
|
|
@@ -3098,8 +3225,6 @@ export async function createDeviceHub(options) {
|
|
|
3098
3225
|
entry.deviceId === deviceId &&
|
|
3099
3226
|
entry.botId === event.botId &&
|
|
3100
3227
|
entry.accountId === device?.accountId);
|
|
3101
|
-
// Settle identity and durable terminal conflicts first, so an obsolete
|
|
3102
|
-
// artifact can receive a bound permanent rejection rather than retry forever.
|
|
3103
3228
|
const settled = settleTaskTerminalOutcome(draft, deviceId, { ...event, type: "task_event", reportMetadata }, settlementContext());
|
|
3104
3229
|
if (!settled.accepted)
|
|
3105
3230
|
throw Object.assign(new HttpError(settled.statusCode ?? 409, settled.reason ?? "Outcome rejected"), {
|
|
@@ -3166,7 +3291,6 @@ export async function createDeviceHub(options) {
|
|
|
3166
3291
|
}
|
|
3167
3292
|
return result.task;
|
|
3168
3293
|
}
|
|
3169
|
-
// Recover unissued work; outstanding leases must first claim within the recovery window.
|
|
3170
3294
|
const recovery = await store.transact((draft) => rescanReadyTasksOnRecovery(draft, Date.now(), 60_000, settlementContext()));
|
|
3171
3295
|
await publishSettlementEffects(recovery, false);
|
|
3172
3296
|
async function resumeQueuedTasks(deviceId) {
|
|
@@ -3406,7 +3530,6 @@ export async function createDeviceHub(options) {
|
|
|
3406
3530
|
const room = state.rooms.find((r) => r.id === task.roomId && r.accountId === task.accountId);
|
|
3407
3531
|
if (!room)
|
|
3408
3532
|
return;
|
|
3409
|
-
// Deduplicate and enforce monotonic sequence if provided
|
|
3410
3533
|
if (typeof frame.sequence === "number" && Number.isSafeInteger(frame.sequence)) {
|
|
3411
3534
|
const seqKey = `${task.id}:${task.attemptId}`;
|
|
3412
3535
|
const prevSeq = toolLifecycleSeqs.get(seqKey);
|
|
@@ -3507,6 +3630,7 @@ export async function createDeviceHub(options) {
|
|
|
3507
3630
|
void reconcilePendingPublications();
|
|
3508
3631
|
},
|
|
3509
3632
|
async close() {
|
|
3633
|
+
await mobilePush.dispose();
|
|
3510
3634
|
clearInterval(recoverySweepTimer);
|
|
3511
3635
|
lockManager.close();
|
|
3512
3636
|
await groupEvents.close();
|
|
@@ -97,7 +97,6 @@ export function validInteractionProjection(value, binding) {
|
|
|
97
97
|
? validQuestions(v.questions)
|
|
98
98
|
: v.kind === "approval" && typeof v.toolName === "string" && typeof v.paramsPreview === "string")));
|
|
99
99
|
}
|
|
100
|
-
/** Holds native IDs locally. Neither Hub nor browser can supply a native WS frame. */
|
|
101
100
|
export function createHumanInteractionBridge(binding, options) {
|
|
102
101
|
const pending = new Map();
|
|
103
102
|
const consumed = new Set();
|
|
@@ -120,13 +119,11 @@ export function createHumanInteractionBridge(binding, options) {
|
|
|
120
119
|
}
|
|
121
120
|
if (message.type !== "question_pending" && message.type !== "tool_approval_pending")
|
|
122
121
|
return;
|
|
123
|
-
// Missing conversation/foreign owner/global asks must stay local.
|
|
124
122
|
if (message.conversationId !== options.conversationId || message.global || message.owner)
|
|
125
123
|
return;
|
|
126
124
|
const kind = message.type === "question_pending" ? "question" : "approval";
|
|
127
125
|
if (consumed.has(`${kind}:${message.id}`))
|
|
128
126
|
return;
|
|
129
|
-
// Stop projection after the per-execution consumption budget instead of forgetting tombstones.
|
|
130
127
|
if (consumed.size >= 256)
|
|
131
128
|
return;
|
|
132
129
|
if ([...pending.values()].some((v) => v.nativeId === message.id && v.item.kind === kind))
|
|
@@ -216,7 +213,7 @@ export function createHumanInteractionBridge(binding, options) {
|
|
|
216
213
|
};
|
|
217
214
|
}
|
|
218
215
|
consumed.add(`${v.item.kind}:${v.nativeId}`);
|
|
219
|
-
pending.delete(value.interactionId);
|
|
216
|
+
pending.delete(value.interactionId);
|
|
220
217
|
options.send(frame);
|
|
221
218
|
publish();
|
|
222
219
|
return true;
|