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
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import { randomBytes, constants } from "node:crypto";
|
|
2
|
+
import http, {} from "node:http";
|
|
3
|
+
import https from "node:https";
|
|
4
|
+
import { isIPv4 } from "node:net";
|
|
5
|
+
import { networkInterfaces } from "node:os";
|
|
6
|
+
import { Transform } from "node:stream";
|
|
7
|
+
import { cleanHeaders, safePath, RELAY_LIMITS, WS_MESSAGE_BYTES } from "./relay.js";
|
|
8
|
+
import { WebSocket, WebSocketServer } from "ws";
|
|
9
|
+
const CIPHER = "PSK-AES128-GCM-SHA256";
|
|
10
|
+
const TTL = 30 * 60_000;
|
|
11
|
+
const INPUT = 16 * 1024;
|
|
12
|
+
const OUTPUT = 4 * 1024 * 1024;
|
|
13
|
+
const STATUS = "/api/health";
|
|
14
|
+
const TLS_OPTIONS = {
|
|
15
|
+
minVersion: "TLSv1.2",
|
|
16
|
+
maxVersion: "TLSv1.2",
|
|
17
|
+
ciphers: CIPHER,
|
|
18
|
+
secureOptions: constants.SSL_OP_NO_TICKET,
|
|
19
|
+
};
|
|
20
|
+
function privateAddress(address, allowLoopback = false) {
|
|
21
|
+
if (typeof address !== "string" || !isIPv4(address))
|
|
22
|
+
return false;
|
|
23
|
+
const [a, b] = address.split(".").map(Number);
|
|
24
|
+
return a === 10 || (a === 172 && b >= 16 && b <= 31) || (a === 192 && b === 168) || (allowLoopback && a === 127);
|
|
25
|
+
}
|
|
26
|
+
function addresses() {
|
|
27
|
+
return [
|
|
28
|
+
...new Set(Object.values(networkInterfaces()).flatMap((entries) => (entries ?? [])
|
|
29
|
+
.filter((entry) => !entry.internal && privateAddress(entry.address))
|
|
30
|
+
.map((entry) => entry.address))),
|
|
31
|
+
].slice(0, 16);
|
|
32
|
+
}
|
|
33
|
+
function validGrant(value, allowLoopback) {
|
|
34
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
35
|
+
return false;
|
|
36
|
+
const g = value;
|
|
37
|
+
return (Object.keys(g).length === 5 &&
|
|
38
|
+
Array.isArray(g.addresses) &&
|
|
39
|
+
g.addresses.length > 0 &&
|
|
40
|
+
g.addresses.length <= 16 &&
|
|
41
|
+
g.addresses.every((a) => privateAddress(a, allowLoopback)) &&
|
|
42
|
+
new Set(g.addresses).size === g.addresses.length &&
|
|
43
|
+
Number.isInteger(g.port) &&
|
|
44
|
+
g.port > 0 &&
|
|
45
|
+
g.port <= 65535 &&
|
|
46
|
+
typeof g.identity === "string" &&
|
|
47
|
+
/^[A-Za-z0-9_-]{22,64}$/.test(g.identity) &&
|
|
48
|
+
typeof g.key === "string" &&
|
|
49
|
+
/^[A-Za-z0-9_-]{43}$/.test(g.key) &&
|
|
50
|
+
Buffer.from(g.key, "base64url").toString("base64url") === g.key &&
|
|
51
|
+
Number.isSafeInteger(g.expiresAt) &&
|
|
52
|
+
g.expiresAt > Date.now() &&
|
|
53
|
+
g.expiresAt <= Date.now() + TTL);
|
|
54
|
+
}
|
|
55
|
+
function httpPath(req) {
|
|
56
|
+
return safePath(req.url, req.method);
|
|
57
|
+
}
|
|
58
|
+
function wsPath(req) {
|
|
59
|
+
return req.method === "GET" && safePath(req.url, "GET");
|
|
60
|
+
}
|
|
61
|
+
function bodyLimit(limit) {
|
|
62
|
+
let bytes = 0;
|
|
63
|
+
return new Transform({
|
|
64
|
+
highWaterMark: RELAY_LIMITS.chunk,
|
|
65
|
+
transform(chunk, _encoding, callback) {
|
|
66
|
+
bytes += chunk.length;
|
|
67
|
+
if (bytes > limit)
|
|
68
|
+
callback(new Error("LAN body limit exceeded"));
|
|
69
|
+
else
|
|
70
|
+
callback(null, chunk);
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function byteLength(data) {
|
|
75
|
+
return Array.isArray(data) ? data.reduce((n, chunk) => n + chunk.length, 0) : data.byteLength;
|
|
76
|
+
}
|
|
77
|
+
export function createDeviceLanServer(options) {
|
|
78
|
+
const local = new URL(options.localOrigin);
|
|
79
|
+
if (!["http:", "https:"].includes(local.protocol) ||
|
|
80
|
+
!["localhost", "127.0.0.1", "[::1]"].includes(local.hostname) ||
|
|
81
|
+
local.username ||
|
|
82
|
+
local.password ||
|
|
83
|
+
local.pathname !== "/" ||
|
|
84
|
+
local.search ||
|
|
85
|
+
local.hash) {
|
|
86
|
+
throw new Error("Device LAN requires a fixed loopback origin");
|
|
87
|
+
}
|
|
88
|
+
const hostname = local.hostname === "[::1]" ? "::1" : "127.0.0.1";
|
|
89
|
+
if (options.localAuthToken && /[\r\n]/.test(options.localAuthToken))
|
|
90
|
+
throw new Error("Invalid local token");
|
|
91
|
+
const headers = (incoming = {}) => ({
|
|
92
|
+
...cleanHeaders(incoming),
|
|
93
|
+
host: local.host,
|
|
94
|
+
origin: local.origin,
|
|
95
|
+
...(options.localAuthToken ? { authorization: `Bearer ${options.localAuthToken}` } : {}),
|
|
96
|
+
});
|
|
97
|
+
const localRequest = local.protocol === "https:" ? https.request : http.request;
|
|
98
|
+
let state;
|
|
99
|
+
let generation = 0;
|
|
100
|
+
const checking = new Set();
|
|
101
|
+
function revoke(s, entry) {
|
|
102
|
+
s.grants.delete(entry.grant.identity);
|
|
103
|
+
entry.key.fill(0);
|
|
104
|
+
for (const socket of entry.sockets)
|
|
105
|
+
socket.destroy();
|
|
106
|
+
}
|
|
107
|
+
function schedule(s) {
|
|
108
|
+
clearTimeout(s.timer);
|
|
109
|
+
for (const entry of s.grants.values())
|
|
110
|
+
if (entry.grant.expiresAt <= Date.now())
|
|
111
|
+
revoke(s, entry);
|
|
112
|
+
if (!s.grants.size)
|
|
113
|
+
return;
|
|
114
|
+
const next = Math.min(...[...s.grants.values()].map((e) => e.grant.expiresAt));
|
|
115
|
+
s.timer = setTimeout(() => schedule(s), Math.max(1, next - Date.now()));
|
|
116
|
+
s.timer.unref();
|
|
117
|
+
}
|
|
118
|
+
function authorized(s, req) {
|
|
119
|
+
const entry = s.authenticated.get(req.socket);
|
|
120
|
+
return state === s && entry && s.grants.get(entry.grant.identity) === entry && entry.grant.expiresAt > Date.now();
|
|
121
|
+
}
|
|
122
|
+
function start() {
|
|
123
|
+
const s = {
|
|
124
|
+
server: undefined,
|
|
125
|
+
wss: new WebSocketServer({ noServer: true, maxPayload: WS_MESSAGE_BYTES, perMessageDeflate: false }),
|
|
126
|
+
desktopWss: new WebSocketServer({ noServer: true, maxPayload: INPUT, perMessageDeflate: false }),
|
|
127
|
+
grants: new Map(),
|
|
128
|
+
authenticated: new WeakMap(),
|
|
129
|
+
sockets: new Set(),
|
|
130
|
+
tasks: new Set(),
|
|
131
|
+
ready: Promise.resolve(false),
|
|
132
|
+
};
|
|
133
|
+
s.server = https.createServer({
|
|
134
|
+
...TLS_OPTIONS,
|
|
135
|
+
handshakeTimeout: 3000,
|
|
136
|
+
maxHeaderSize: INPUT,
|
|
137
|
+
pskCallback(socket, identity) {
|
|
138
|
+
const entry = s.grants.get(identity);
|
|
139
|
+
if (!entry || entry.grant.expiresAt <= Date.now() || state !== s)
|
|
140
|
+
return null;
|
|
141
|
+
s.authenticated.set(socket, entry);
|
|
142
|
+
entry.sockets.add(socket);
|
|
143
|
+
socket.once("close", () => entry.sockets.delete(socket));
|
|
144
|
+
return entry.key;
|
|
145
|
+
},
|
|
146
|
+
}, (req, res) => {
|
|
147
|
+
res.setHeader("Cache-Control", "no-store");
|
|
148
|
+
if (!authorized(s, req) || !httpPath(req)) {
|
|
149
|
+
res.writeHead(403).end();
|
|
150
|
+
req.resume();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const desktop = req.url?.startsWith("/api/device-desktop/");
|
|
154
|
+
const limit = desktop ? INPUT : RELAY_LIMITS.body;
|
|
155
|
+
if (s.tasks.size >= RELAY_LIMITS.streams || Number(req.headers["content-length"] ?? 0) > limit) {
|
|
156
|
+
res.setHeader("Connection", "close");
|
|
157
|
+
res.writeHead(s.tasks.size >= RELAY_LIMITS.streams ? 503 : 413).end();
|
|
158
|
+
req.resume();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const input = bodyLimit(limit);
|
|
162
|
+
const output = bodyLimit(RELAY_LIMITS.body);
|
|
163
|
+
let stopped = false;
|
|
164
|
+
const timer = setTimeout(() => cleanup(), 60_000);
|
|
165
|
+
const upstream = localRequest({
|
|
166
|
+
protocol: local.protocol,
|
|
167
|
+
hostname,
|
|
168
|
+
port: local.port || undefined,
|
|
169
|
+
method: req.method,
|
|
170
|
+
path: req.url,
|
|
171
|
+
agent: false,
|
|
172
|
+
headers: headers(req.headers),
|
|
173
|
+
}, (reply) => {
|
|
174
|
+
reply.on("error", () => cleanup());
|
|
175
|
+
res.writeHead(reply.statusCode ?? 502, cleanHeaders(reply.headers));
|
|
176
|
+
reply.pipe(output).pipe(res);
|
|
177
|
+
});
|
|
178
|
+
const cleanup = () => {
|
|
179
|
+
if (stopped)
|
|
180
|
+
return;
|
|
181
|
+
stopped = true;
|
|
182
|
+
clearTimeout(timer);
|
|
183
|
+
s.tasks.delete(cleanup);
|
|
184
|
+
req.unpipe(input);
|
|
185
|
+
input.destroy();
|
|
186
|
+
output.destroy();
|
|
187
|
+
upstream.destroy();
|
|
188
|
+
if (!res.writableEnded)
|
|
189
|
+
res.destroy();
|
|
190
|
+
};
|
|
191
|
+
s.tasks.add(cleanup);
|
|
192
|
+
res.once("close", cleanup);
|
|
193
|
+
req.on("error", cleanup);
|
|
194
|
+
input.on("error", () => {
|
|
195
|
+
if (!res.headersSent)
|
|
196
|
+
res.writeHead(413, { Connection: "close" }).end();
|
|
197
|
+
cleanup();
|
|
198
|
+
});
|
|
199
|
+
output.on("error", cleanup);
|
|
200
|
+
upstream.on("error", () => {
|
|
201
|
+
if (!res.headersSent)
|
|
202
|
+
res.writeHead(502).end();
|
|
203
|
+
cleanup();
|
|
204
|
+
});
|
|
205
|
+
req.pipe(input).pipe(upstream);
|
|
206
|
+
});
|
|
207
|
+
s.server.requestTimeout = 60_000;
|
|
208
|
+
s.server.headersTimeout = 5000;
|
|
209
|
+
s.server.keepAliveTimeout = 5000;
|
|
210
|
+
s.server.maxConnections = 64;
|
|
211
|
+
s.server.on("connection", (socket) => {
|
|
212
|
+
s.sockets.add(socket);
|
|
213
|
+
socket.once("close", () => s.sockets.delete(socket));
|
|
214
|
+
});
|
|
215
|
+
s.server.on("tlsClientError", (_error, socket) => socket.destroy());
|
|
216
|
+
s.server.on("secureConnection", (socket) => {
|
|
217
|
+
if (!s.authenticated.has(socket) || socket.getCipher().name !== CIPHER)
|
|
218
|
+
socket.destroy();
|
|
219
|
+
});
|
|
220
|
+
s.server.on("upgrade", (req, socket, head) => {
|
|
221
|
+
if (!authorized(s, req) || !wsPath(req) || s.tasks.size >= RELAY_LIMITS.streams) {
|
|
222
|
+
socket.destroy();
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const target = new URL(req.url, local);
|
|
226
|
+
const desktop = target.pathname === "/desktop-ws";
|
|
227
|
+
if (target.hash || (desktop && s.desktopWss.clients.size >= 4)) {
|
|
228
|
+
socket.destroy();
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
target.protocol = local.protocol === "https:" ? "wss:" : "ws:";
|
|
232
|
+
target.hostname = hostname === "::1" ? "[::1]" : hostname;
|
|
233
|
+
(desktop ? s.desktopWss : s.wss).handleUpgrade(req, socket, head, (ws) => {
|
|
234
|
+
const inputLimit = desktop ? INPUT : WS_MESSAGE_BYTES;
|
|
235
|
+
const outputLimit = desktop ? OUTPUT : WS_MESSAGE_BYTES;
|
|
236
|
+
const upstream = new WebSocket(target, {
|
|
237
|
+
headers: headers(req.headers),
|
|
238
|
+
maxPayload: outputLimit,
|
|
239
|
+
perMessageDeflate: false,
|
|
240
|
+
handshakeTimeout: 5000,
|
|
241
|
+
});
|
|
242
|
+
let stopped = false;
|
|
243
|
+
let pendingBytes = 0;
|
|
244
|
+
const pending = [];
|
|
245
|
+
const cleanup = () => {
|
|
246
|
+
if (stopped)
|
|
247
|
+
return;
|
|
248
|
+
stopped = true;
|
|
249
|
+
pending.length = 0;
|
|
250
|
+
s.tasks.delete(cleanup);
|
|
251
|
+
ws.terminate();
|
|
252
|
+
upstream.terminate();
|
|
253
|
+
};
|
|
254
|
+
const send = (to, data, binary, limit) => {
|
|
255
|
+
if (to.readyState !== WebSocket.OPEN || to.bufferedAmount + byteLength(data) > limit)
|
|
256
|
+
return cleanup();
|
|
257
|
+
to.send(data, { binary }, (error) => {
|
|
258
|
+
if (error)
|
|
259
|
+
cleanup();
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
s.tasks.add(cleanup);
|
|
263
|
+
ws.on("error", cleanup);
|
|
264
|
+
upstream.on("error", cleanup);
|
|
265
|
+
ws.on("close", cleanup);
|
|
266
|
+
upstream.on("close", cleanup);
|
|
267
|
+
ws.on("message", (data, binary) => {
|
|
268
|
+
if (byteLength(data) > inputLimit)
|
|
269
|
+
return cleanup();
|
|
270
|
+
if (upstream.readyState === WebSocket.CONNECTING) {
|
|
271
|
+
pendingBytes += byteLength(data);
|
|
272
|
+
if (pendingBytes > inputLimit || pending.length >= 128)
|
|
273
|
+
return cleanup();
|
|
274
|
+
pending.push({ data, binary });
|
|
275
|
+
}
|
|
276
|
+
else
|
|
277
|
+
send(upstream, data, binary, desktop ? INPUT : 2 * WS_MESSAGE_BYTES);
|
|
278
|
+
});
|
|
279
|
+
upstream.on("open", () => {
|
|
280
|
+
for (const { data, binary } of pending)
|
|
281
|
+
send(upstream, data, binary, desktop ? INPUT : 2 * WS_MESSAGE_BYTES);
|
|
282
|
+
pending.length = 0;
|
|
283
|
+
pendingBytes = 0;
|
|
284
|
+
});
|
|
285
|
+
upstream.on("message", (data, binary) => send(ws, data, binary, desktop ? OUTPUT : 2 * WS_MESSAGE_BYTES));
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
state = s;
|
|
289
|
+
s.ready = new Promise((resolve) => {
|
|
290
|
+
s.server.once("error", () => {
|
|
291
|
+
if (state === s)
|
|
292
|
+
close();
|
|
293
|
+
resolve(false);
|
|
294
|
+
});
|
|
295
|
+
s.server.once("close", () => resolve(false));
|
|
296
|
+
s.server.listen(0, "0.0.0.0", () => {
|
|
297
|
+
if (state !== s) {
|
|
298
|
+
s.server.close();
|
|
299
|
+
resolve(false);
|
|
300
|
+
}
|
|
301
|
+
else
|
|
302
|
+
resolve(true);
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
return s;
|
|
306
|
+
}
|
|
307
|
+
async function available() {
|
|
308
|
+
return new Promise((resolve) => {
|
|
309
|
+
let finished = false;
|
|
310
|
+
const request = localRequest({
|
|
311
|
+
protocol: local.protocol,
|
|
312
|
+
hostname,
|
|
313
|
+
port: local.port || undefined,
|
|
314
|
+
path: STATUS,
|
|
315
|
+
headers: headers(),
|
|
316
|
+
agent: false,
|
|
317
|
+
}, (res) => {
|
|
318
|
+
let size = 0;
|
|
319
|
+
res.on("data", (chunk) => {
|
|
320
|
+
size += chunk.length;
|
|
321
|
+
if (size > INPUT)
|
|
322
|
+
finish(false);
|
|
323
|
+
});
|
|
324
|
+
res.on("error", () => finish(false));
|
|
325
|
+
res.on("end", () => finish(res.statusCode === 200));
|
|
326
|
+
});
|
|
327
|
+
const timer = setTimeout(() => finish(false), 800);
|
|
328
|
+
const cancel = () => finish(false);
|
|
329
|
+
const finish = (ok) => {
|
|
330
|
+
if (finished)
|
|
331
|
+
return;
|
|
332
|
+
finished = true;
|
|
333
|
+
clearTimeout(timer);
|
|
334
|
+
checking.delete(cancel);
|
|
335
|
+
request.destroy();
|
|
336
|
+
resolve(ok);
|
|
337
|
+
};
|
|
338
|
+
checking.add(cancel);
|
|
339
|
+
request.on("error", () => finish(false));
|
|
340
|
+
request.end();
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
async function issueGrant() {
|
|
344
|
+
const issuedGeneration = generation;
|
|
345
|
+
try {
|
|
346
|
+
if (checking.size >= 16)
|
|
347
|
+
return null;
|
|
348
|
+
if (!(await (options.enabled ? options.enabled() : available())) || issuedGeneration !== generation)
|
|
349
|
+
return null;
|
|
350
|
+
const candidates = [...new Set((options.addresses ?? addresses)())];
|
|
351
|
+
if (!candidates.length ||
|
|
352
|
+
candidates.length > 16 ||
|
|
353
|
+
candidates.some((a) => !privateAddress(a, !!options.addresses)))
|
|
354
|
+
return null;
|
|
355
|
+
const s = state ?? start();
|
|
356
|
+
if (!(await s.ready) || state !== s || issuedGeneration !== generation)
|
|
357
|
+
return null;
|
|
358
|
+
schedule(s);
|
|
359
|
+
while (s.grants.size >= 16)
|
|
360
|
+
revoke(s, s.grants.values().next().value);
|
|
361
|
+
const key = randomBytes(32);
|
|
362
|
+
const grant = {
|
|
363
|
+
addresses: candidates,
|
|
364
|
+
port: s.server.address().port,
|
|
365
|
+
identity: randomBytes(24).toString("base64url"),
|
|
366
|
+
key: key.toString("base64url"),
|
|
367
|
+
expiresAt: Date.now() + TTL,
|
|
368
|
+
};
|
|
369
|
+
s.grants.set(grant.identity, { grant: { ...grant, addresses: [...candidates] }, key, sockets: new Set() });
|
|
370
|
+
schedule(s);
|
|
371
|
+
return grant;
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
function close() {
|
|
378
|
+
generation++;
|
|
379
|
+
for (const cancel of checking)
|
|
380
|
+
cancel();
|
|
381
|
+
const s = state;
|
|
382
|
+
state = undefined;
|
|
383
|
+
if (!s)
|
|
384
|
+
return;
|
|
385
|
+
clearTimeout(s.timer);
|
|
386
|
+
for (const entry of s.grants.values())
|
|
387
|
+
revoke(s, entry);
|
|
388
|
+
for (const cleanup of s.tasks)
|
|
389
|
+
cleanup();
|
|
390
|
+
for (const socket of s.sockets)
|
|
391
|
+
socket.destroy();
|
|
392
|
+
s.wss.close();
|
|
393
|
+
s.desktopWss.close();
|
|
394
|
+
s.server.close();
|
|
395
|
+
}
|
|
396
|
+
return {
|
|
397
|
+
issueGrant,
|
|
398
|
+
revoke(identity) {
|
|
399
|
+
if (!state)
|
|
400
|
+
return;
|
|
401
|
+
const entry = state.grants.get(identity);
|
|
402
|
+
if (entry) {
|
|
403
|
+
revoke(state, entry);
|
|
404
|
+
schedule(state);
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
close,
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
export async function probeDeviceLan(grant, options = {}) {
|
|
411
|
+
if (!validGrant(grant, options.allowLoopback === true) || options.signal?.aborted)
|
|
412
|
+
return null;
|
|
413
|
+
const timeout = options.timeoutMs ?? 800;
|
|
414
|
+
if (!Number.isFinite(timeout) || timeout <= 0 || timeout > 30_000)
|
|
415
|
+
return null;
|
|
416
|
+
return new Promise((resolve) => {
|
|
417
|
+
let settled = false;
|
|
418
|
+
let remaining = grant.addresses.length;
|
|
419
|
+
const candidates = new Set();
|
|
420
|
+
const finish = (winner) => {
|
|
421
|
+
if (settled)
|
|
422
|
+
return;
|
|
423
|
+
settled = true;
|
|
424
|
+
options.signal?.removeEventListener("abort", abort);
|
|
425
|
+
for (const candidate of candidates)
|
|
426
|
+
if (candidate.agent !== winner?.agent)
|
|
427
|
+
candidate.cancel();
|
|
428
|
+
resolve(winner);
|
|
429
|
+
};
|
|
430
|
+
const abort = () => finish(null);
|
|
431
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
432
|
+
for (const address of grant.addresses) {
|
|
433
|
+
const agent = new https.Agent({
|
|
434
|
+
...TLS_OPTIONS,
|
|
435
|
+
keepAlive: true,
|
|
436
|
+
maxSockets: 4,
|
|
437
|
+
maxFreeSockets: 1,
|
|
438
|
+
maxCachedSessions: 0,
|
|
439
|
+
pskCallback: () => ({ identity: grant.identity, psk: Buffer.from(grant.key, "base64url") }),
|
|
440
|
+
checkServerIdentity: () => undefined,
|
|
441
|
+
});
|
|
442
|
+
const origin = `https://${address}:${grant.port}`;
|
|
443
|
+
let finished = false;
|
|
444
|
+
const fail = () => {
|
|
445
|
+
if (finished)
|
|
446
|
+
return;
|
|
447
|
+
finished = true;
|
|
448
|
+
clearTimeout(timer);
|
|
449
|
+
request.destroy();
|
|
450
|
+
agent.destroy();
|
|
451
|
+
candidates.delete(candidate);
|
|
452
|
+
if (--remaining === 0)
|
|
453
|
+
finish(null);
|
|
454
|
+
};
|
|
455
|
+
const request = https.get(`${origin}${STATUS}`, { agent }, (res) => {
|
|
456
|
+
let size = 0;
|
|
457
|
+
res.on("data", (chunk) => {
|
|
458
|
+
size += chunk.length;
|
|
459
|
+
if (size > INPUT)
|
|
460
|
+
fail();
|
|
461
|
+
});
|
|
462
|
+
res.on("error", fail);
|
|
463
|
+
res.on("end", () => {
|
|
464
|
+
if (finished || settled)
|
|
465
|
+
return;
|
|
466
|
+
try {
|
|
467
|
+
if (res.statusCode !== 200 || grant.expiresAt <= Date.now())
|
|
468
|
+
return fail();
|
|
469
|
+
finished = true;
|
|
470
|
+
clearTimeout(timer);
|
|
471
|
+
finish({ origin, agent, close: () => agent.destroy() });
|
|
472
|
+
}
|
|
473
|
+
catch {
|
|
474
|
+
fail();
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
});
|
|
478
|
+
const candidate = { agent, cancel: fail };
|
|
479
|
+
candidates.add(candidate);
|
|
480
|
+
const timer = setTimeout(fail, Math.min(timeout, grant.expiresAt - Date.now()));
|
|
481
|
+
request.on("error", fail);
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
}
|
|
@@ -35,7 +35,6 @@ function validAlias(value) {
|
|
|
35
35
|
function validId(value) {
|
|
36
36
|
return typeof value === "string" && value.trim().length > 0 && value.length <= 256 && !/[\x00-\x1f\x7f]/.test(value);
|
|
37
37
|
}
|
|
38
|
-
/** Comma-separated decimal ports; empty configuration disables portal allocation. */
|
|
39
38
|
export function parsePortalPorts(value) {
|
|
40
39
|
if (value === undefined || value.trim() === "")
|
|
41
40
|
return [];
|
|
@@ -47,7 +46,6 @@ export function parsePortalPorts(value) {
|
|
|
47
46
|
fail(400, "Invalid portal ports");
|
|
48
47
|
return ports;
|
|
49
48
|
}
|
|
50
|
-
/** Single-process registry. Allocations are published only after atomic replacement succeeds. */
|
|
51
49
|
export class DevicePortals {
|
|
52
50
|
path;
|
|
53
51
|
state;
|
|
@@ -149,7 +147,6 @@ export class DevicePortals {
|
|
|
149
147
|
const entry = this.state.allocations.find((item) => !item.retired && item.alias === alias);
|
|
150
148
|
return entry ? { deviceId: entry.deviceId, accountId: entry.accountId } : undefined;
|
|
151
149
|
}
|
|
152
|
-
/** Detached legacy origins only; path access must not enter the relay origin map. */
|
|
153
150
|
origins() {
|
|
154
151
|
const origins = new Map();
|
|
155
152
|
if (this.pathAccess)
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { DeviceTaskError } from "./task-error.js";
|
|
2
|
-
// Only fixed vocabulary crosses the device boundary. Never redact arbitrary provider
|
|
3
|
-
// prose and then publish the remainder: credentials can appear in any shape or field.
|
|
4
2
|
const reasons = {
|
|
5
3
|
model_missing: "Configured Bot model is unavailable; check the Bot model and local model catalog.",
|
|
6
4
|
model_auth: "Model authentication failed; check credentials on the target device.",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** Locally owned procedure text. Never interpolate task, history, configuration or remote content. */
|
|
2
1
|
export const EXECUTION_GUIDE_TOPICS = ["coordination", "code", "delivery", "review"];
|
|
3
2
|
export const EXECUTION_GUIDE_MAX_BYTES = 8192;
|
|
4
3
|
export const LOCAL_EXECUTION_GUIDES = Object.freeze({
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** Stable local execution policy. Never interpolate task, history or Bot configuration here. */
|
|
2
1
|
export function getBotExecutionInstructions(primary) {
|
|
3
2
|
return [
|
|
4
3
|
"Follow the existing local agent approval policy. Never enable auto-approval or change safety settings on behalf of a remote task.",
|
|
@@ -133,7 +133,6 @@ export function validateExecutionSettings(input) {
|
|
|
133
133
|
return { valid: false, error: "Settings must be an object" };
|
|
134
134
|
}
|
|
135
135
|
const candidate = input;
|
|
136
|
-
// Strict rejection of unknown/extra keys to prevent spelling mistakes
|
|
137
136
|
for (const key of Object.keys(candidate)) {
|
|
138
137
|
if (!ALLOWED_KEYS.has(key)) {
|
|
139
138
|
return { valid: false, error: `Unknown configuration key: ${key}` };
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { splitAgentStartPrompt } from "../persona-chain.js";
|
|
2
2
|
const ownedSections = ["device_bot", "device_execution"];
|
|
3
|
-
/** Keep execution authority in SDK sections, including when a renderer forces opaque text. */
|
|
4
3
|
export function prepareBotExecutionSystemPrompt(event, execution) {
|
|
5
|
-
// Split before adding sections: earlier extensions wrapped the previous SDK baseline.
|
|
6
4
|
const { pre, core, post } = splitAgentStartPrompt(event);
|
|
7
5
|
if (!execution)
|
|
8
6
|
return { core, rewrap: (next) => pre + next + post };
|
|
@@ -30,7 +28,6 @@ export function prepareBotExecutionSystemPrompt(event, execution) {
|
|
|
30
28
|
const wrapped = stripOwnedSections(pre + next + post);
|
|
31
29
|
return rendered ? `${wrapped.trimEnd()}\n\n${rendered}` : wrapped;
|
|
32
30
|
};
|
|
33
|
-
// SDK ignores sections when an earlier extension has already forced the prompt.
|
|
34
31
|
if (typeof event.systemPromptOptions?.forceSystemPrompt === "string") {
|
|
35
32
|
event.systemPromptOptions.forceSystemPrompt = rewrap(core);
|
|
36
33
|
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { realpathSync } from "node:fs";
|
|
2
2
|
import { isAbsolute, relative, resolve } from "node:path";
|
|
3
|
-
/** Canonical roots prevent symlink aliases from bypassing execution isolation. */
|
|
4
3
|
export function executionRoot(path) {
|
|
5
4
|
let root = resolve(path);
|
|
6
5
|
try {
|
|
7
6
|
root = realpathSync.native(root);
|
|
8
7
|
}
|
|
9
|
-
catch {
|
|
10
|
-
/* Admission validates missing roots separately. */
|
|
11
|
-
}
|
|
8
|
+
catch { }
|
|
12
9
|
return process.platform === "win32" ? root.toLowerCase() : root;
|
|
13
10
|
}
|
|
14
11
|
export function executionRootsOverlap(left, right) {
|
|
@@ -10,8 +10,6 @@ import { selectTaskContext } from "./task-context-budget.js";
|
|
|
10
10
|
import { registerBotExecution } from "./bot-execution.js";
|
|
11
11
|
import { DeviceExecutionError, executionFailure } from "./execution-failure.js";
|
|
12
12
|
import { projectToolLifecycle } from "./task-progress.js";
|
|
13
|
-
// Process-local guards survive executor replacement. They deliberately never retry an
|
|
14
|
-
// uncertain attempt. Durable delivery must additionally deduplicate in its task store.
|
|
15
13
|
const attempted = new Set();
|
|
16
14
|
const busyExecutions = new Set();
|
|
17
15
|
const TIMEOUT_MS = 20 * 60 * 1000;
|
|
@@ -36,7 +34,6 @@ function samePath(a, b) {
|
|
|
36
34
|
export function taskPrompt(task) {
|
|
37
35
|
const context = task.taskState ? selectTaskContext(task.taskState) : undefined;
|
|
38
36
|
const isCode = (task.executionMode ?? task.contract?.executionMode) === "code";
|
|
39
|
-
// In code mode, contract.goal is the authoritative executable instruction binding
|
|
40
37
|
const effectiveText = isCode && task.contract?.goal ? task.contract.goal : task.text;
|
|
41
38
|
const contractInfo = task.contract
|
|
42
39
|
? {
|
|
@@ -72,12 +69,6 @@ export function taskPrompt(task) {
|
|
|
72
69
|
}),
|
|
73
70
|
].join("\n\n");
|
|
74
71
|
}
|
|
75
|
-
/** Connects as an independent client; never changes approval settings or retries.
|
|
76
|
-
* close() cancels only this client's locked task conversation. Failures reject with
|
|
77
|
-
* a bounded report; completed sessions remain persisted for local inspection.
|
|
78
|
-
* close() is permanent: after a disconnect, create a fresh executor and explicitly
|
|
79
|
-
* create a new task. Reconnection does not resume or retry an interrupted task.
|
|
80
|
-
*/
|
|
81
72
|
export function createDeviceTaskExecutor(options) {
|
|
82
73
|
const origin = originUrl(options.localOrigin);
|
|
83
74
|
if (!isAbsolute(options.cwd))
|
|
@@ -169,8 +160,6 @@ export function createDeviceTaskExecutor(options) {
|
|
|
169
160
|
let idleConfirmed = false;
|
|
170
161
|
let stopUnconfirmed = false;
|
|
171
162
|
let interactions;
|
|
172
|
-
// Immediate notifications can precede snapshots. Keep them until an
|
|
173
|
-
// explicit resolution or a snapshot-observed wait has disappeared.
|
|
174
163
|
const humanWaits = new Set();
|
|
175
164
|
let snapshotWaits = new Set();
|
|
176
165
|
let queuedQuestions = new Set();
|
|
@@ -237,12 +226,6 @@ export function createDeviceTaskExecutor(options) {
|
|
|
237
226
|
options.registerInteractionAnswer?.(undefined);
|
|
238
227
|
activeSend = undefined;
|
|
239
228
|
capability.revoke();
|
|
240
|
-
// 锁的语义是「这个 bot/root 上还有一条任务在跑」,而 run 一旦 settle(capability
|
|
241
|
-
// 已撤销、不再有任何写入路径),它就不再是在跑。旧实现只在连接 close 时才放锁:
|
|
242
|
-
// ① 用户/守护重试一条刚结束的任务,在 close 到达前一律被判「本地执行器忙」;
|
|
243
|
-
// ② 单测里上一条 run 的 close 还没到,下一条就被误判 busy(CI 随机红)。
|
|
244
|
-
// 这里在 settle 时就放锁(幂等,后面 confirmStopped 的 delete 变成 no-op);
|
|
245
|
-
// 同 workspace 并发写的护栏仍然是 capability.revoke() + 新的 bot lease。
|
|
246
229
|
busyExecutions.delete(lock);
|
|
247
230
|
try {
|
|
248
231
|
if (sessionBound)
|
|
@@ -255,8 +238,6 @@ export function createDeviceTaskExecutor(options) {
|
|
|
255
238
|
sessionBound = false;
|
|
256
239
|
}
|
|
257
240
|
clearTimeout(timer);
|
|
258
|
-
// abort has no conversationId in the wire protocol. Only send while
|
|
259
|
-
// the private connection still points at the conversation we prompted.
|
|
260
241
|
cancel = undefined;
|
|
261
242
|
if (!prompted || idleConfirmed)
|
|
262
243
|
confirmStopped();
|
|
@@ -505,8 +486,6 @@ export function createDeviceTaskExecutor(options) {
|
|
|
505
486
|
confirmStopped();
|
|
506
487
|
return;
|
|
507
488
|
}
|
|
508
|
-
// Initialization/new_chat failures can arrive as snapshots before a
|
|
509
|
-
// task conversation exists. Do not wait for a successful transition.
|
|
510
489
|
const snapshotError = Reflect.get(state, "error");
|
|
511
490
|
if (state.errorMessage || (typeof snapshotError === "string" && snapshotError)) {
|
|
512
491
|
finish(state.errorMessage || snapshotError);
|
|
@@ -548,8 +527,6 @@ export function createDeviceTaskExecutor(options) {
|
|
|
548
527
|
finish("New session requires local human input");
|
|
549
528
|
return;
|
|
550
529
|
}
|
|
551
|
-
// AgentSession.sessionId delegates to sessionManager.getSessionId(),
|
|
552
|
-
// the same SDK identifier captured by device_collab tool context.
|
|
553
530
|
if (!state.sessionId) {
|
|
554
531
|
finish("Task session has no SDK session ID");
|
|
555
532
|
return;
|
|
@@ -567,7 +544,6 @@ export function createDeviceTaskExecutor(options) {
|
|
|
567
544
|
finish("Task session ownership registration failed");
|
|
568
545
|
return;
|
|
569
546
|
}
|
|
570
|
-
// A callback may synchronously close the executor.
|
|
571
547
|
if (settled)
|
|
572
548
|
return;
|
|
573
549
|
priorMessageIds = new Set(state.messages.map((m) => m.id));
|
|
@@ -588,7 +564,6 @@ export function createDeviceTaskExecutor(options) {
|
|
|
588
564
|
conversationId: conversationId,
|
|
589
565
|
isCurrent: () => !settled && currentId === conversationId && state?.sessionId === sdkSessionId,
|
|
590
566
|
send: (message) => {
|
|
591
|
-
// The bridge has validated task/attempt/conversation and consumed the request ID.
|
|
592
567
|
binding.authorizeInteractionReply(message);
|
|
593
568
|
send(message);
|
|
594
569
|
},
|
|
@@ -626,8 +601,6 @@ export function createDeviceTaskExecutor(options) {
|
|
|
626
601
|
return;
|
|
627
602
|
}
|
|
628
603
|
}
|
|
629
|
-
// Revisions, get_state responses, transport heartbeats and usage-only
|
|
630
|
-
// snapshots are not evidence that the task is making progress.
|
|
631
604
|
const fingerprint = createHash("sha256")
|
|
632
605
|
.update(JSON.stringify([state.messages.map((m) => [m.id, m.content]), state.streamingMessage?.content]))
|
|
633
606
|
.digest("hex");
|