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
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* universal-session.ts — 通用 Agent 会话控制器(实现 DispatchSession)。
|
|
3
|
-
*
|
|
4
|
-
* 职责:
|
|
5
|
-
* 1. 桥接 BaseAgentDriver 与 Web 前端 Wire 协议;
|
|
6
|
-
* 2. 自动维护严格线性的 UiMessage[] 历史与流式 streamingMessage;
|
|
7
|
-
* 3. 60ms 节流下发 snapshot / message_delta,实现高帧率低开销的前端流式渲染;
|
|
8
|
-
* 4. 无缝复用宿主 FilesService(文件树/预览/SCM/上传)、TerminalManager(终端)与 BgServerTracker(后台服务)。
|
|
9
|
-
*/
|
|
10
1
|
import { startTurnTiming, finishTurnTiming } from "../turn-timing.js";
|
|
11
2
|
import { normalizeQuickAskSettings } from "../quick-ask-settings.js";
|
|
3
|
+
import { captureQuickAskConversation } from "../quick-ask-context.js";
|
|
12
4
|
import { randomUUID } from "node:crypto";
|
|
13
5
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
14
6
|
import { homedir } from "node:os";
|
|
@@ -89,8 +81,6 @@ export class UniversalSession {
|
|
|
89
81
|
activeConvId;
|
|
90
82
|
conversations = new Map();
|
|
91
83
|
isStreaming = false;
|
|
92
|
-
/** 在途回合归属的会话 id(#700/#701):prompt 开始时锚定,finalizeTurn 收尾时消费并清空。
|
|
93
|
-
* 会话切换/回滚不再让流式回写与回合收尾锚错会话,避免跨对话内容污染落盘。 */
|
|
94
84
|
turnConvId = null;
|
|
95
85
|
turn = null;
|
|
96
86
|
projectGeneration = 0;
|
|
@@ -293,13 +283,11 @@ export class UniversalSession {
|
|
|
293
283
|
else {
|
|
294
284
|
this.currentModel = opts.driver.currentModel ?? "default";
|
|
295
285
|
}
|
|
296
|
-
// 恢复上次使用的模型(按引擎独立记录:项目记忆优先 > 全局默认)
|
|
297
286
|
const savedModel = opts.stateStore?.getProjectModel(opts.clientId, opts.cwd, this.engine) ??
|
|
298
287
|
opts.stateStore?.getDefaultModel(this.engine);
|
|
299
288
|
if (savedModel) {
|
|
300
289
|
this.currentModel = savedModel;
|
|
301
290
|
}
|
|
302
|
-
// 恢复思考强度记忆:模型专属记忆 > 全局默认 > 既有默认
|
|
303
291
|
const rememberedThinking = getModelThinkingLevelFromSettings(this.currentModel, this.agentDir);
|
|
304
292
|
if (rememberedThinking) {
|
|
305
293
|
this.thinkingLevel = rememberedThinking;
|
|
@@ -336,7 +324,6 @@ export class UniversalSession {
|
|
|
336
324
|
cleanupMinutes: () => 0,
|
|
337
325
|
workspaceCwd: () => this.cwd,
|
|
338
326
|
});
|
|
339
|
-
// 加载现有会话或创建初始会话
|
|
340
327
|
const existing = this.store.listConversations(this.cwd);
|
|
341
328
|
if (existing.length > 0) {
|
|
342
329
|
for (const conv of existing) {
|
|
@@ -350,7 +337,6 @@ export class UniversalSession {
|
|
|
350
337
|
this.conversations.set(initialConv.id, initialConv);
|
|
351
338
|
this.store.saveConversation(this.cwd, initialConv);
|
|
352
339
|
}
|
|
353
|
-
// 记录当前客户端访问的工作区
|
|
354
340
|
if (typeof this.stateStore?.remember === "function" && this.cwd) {
|
|
355
341
|
this.stateStore.remember(this.clientId, this.cwd);
|
|
356
342
|
}
|
|
@@ -362,7 +348,6 @@ export class UniversalSession {
|
|
|
362
348
|
})
|
|
363
349
|
.catch(() => { });
|
|
364
350
|
}
|
|
365
|
-
// 若驱动为 Claude Code,异步探测环境并下发安装指引
|
|
366
351
|
if (this.driver instanceof ClaudeCodeDriver) {
|
|
367
352
|
void probeClaudeCode().then((probe) => {
|
|
368
353
|
if (!probe.installed && !this.disposed) {
|
|
@@ -502,9 +487,7 @@ export class UniversalSession {
|
|
|
502
487
|
try {
|
|
503
488
|
sink(msg);
|
|
504
489
|
}
|
|
505
|
-
catch {
|
|
506
|
-
/* ignore send error on broken pipe */
|
|
507
|
-
}
|
|
490
|
+
catch { }
|
|
508
491
|
}
|
|
509
492
|
}
|
|
510
493
|
flushSnapshot(_forceFull = false) {
|
|
@@ -537,7 +520,6 @@ export class UniversalSession {
|
|
|
537
520
|
messages: this.turnConvId === conv.id && this.pendingToolResults.length > 0
|
|
538
521
|
? [...conv.messages, ...this.pendingToolResults]
|
|
539
522
|
: conv.messages,
|
|
540
|
-
// 回合归属会话才携带流式态:切走后的前台会话快照不再混入后台回合内容(#701)
|
|
541
523
|
streamingMessage: !this.turnConvId || this.turnConvId === conv.id ? this.streamingMessage : null,
|
|
542
524
|
isStreaming: !this.turnConvId || this.turnConvId === conv.id ? this.isStreaming : false,
|
|
543
525
|
turnTiming: conv.turnTiming ?? null,
|
|
@@ -591,9 +573,6 @@ export class UniversalSession {
|
|
|
591
573
|
this.flushSnapshot();
|
|
592
574
|
}, SNAPSHOT_INTERVAL_MS);
|
|
593
575
|
}
|
|
594
|
-
// ---------------------------------------------------------------------------
|
|
595
|
-
// 核心 Prompt 流程
|
|
596
|
-
// ---------------------------------------------------------------------------
|
|
597
576
|
static isDefaultTitle(title) {
|
|
598
577
|
const t = (title ?? "").trim();
|
|
599
578
|
return !t || t === "新对话" || t === "New chat" || t === "New Chat" || t === "对话" || t === "Chat";
|
|
@@ -614,11 +593,9 @@ export class UniversalSession {
|
|
|
614
593
|
this.emitNotice("info", "已加入排队,将在当前回复生成完成后自动发送", "Queued — will send after current response settles");
|
|
615
594
|
return;
|
|
616
595
|
}
|
|
617
|
-
// 插队(steer):中断当前轮次并提交新问题
|
|
618
596
|
this.emitNotice("info", "正在插队,中断当前生成并提交新问题...", "Steering: aborting current turn and submitting prompt...");
|
|
619
597
|
await this.abort();
|
|
620
598
|
}
|
|
621
|
-
// 1. 拦截与执行斜杠命令(内置 / 插件 / 驱动扩展 / 技能指令 / 子代理命令)
|
|
622
599
|
const slash = parseSlash(text);
|
|
623
600
|
if (slash) {
|
|
624
601
|
if (slash.name === "subagent" || slash.name.startsWith("subagent:")) {
|
|
@@ -667,7 +644,6 @@ export class UniversalSession {
|
|
|
667
644
|
const isCurrent = () => this.turn === turn && !this.disposed;
|
|
668
645
|
this.turnConvId = conv.id;
|
|
669
646
|
const now = Date.now();
|
|
670
|
-
// 2. 扫描用户文本中的 @ 提及(文件路径与技能指令)
|
|
671
647
|
try {
|
|
672
648
|
const availableSkills = await this.collectUniversalSkills();
|
|
673
649
|
if (!isCurrent())
|
|
@@ -675,7 +651,6 @@ export class UniversalSession {
|
|
|
675
651
|
const scanResult = scanAtMentions(text, turn.cwd, availableSkills, attachments ?? []);
|
|
676
652
|
const effectiveAttachments = [...(attachments ?? []), ...scanResult.detectedAttachments];
|
|
677
653
|
const finalPrompt = formatPromptWithSkills(text, scanResult.detectedSkills);
|
|
678
|
-
// 3. 自动根据首条提问为新会话命名(首条提问立即刷新左侧栏运行与历史列表)
|
|
679
654
|
const hasNoUserMessages = !conv.messages.some((m) => m.role === "user");
|
|
680
655
|
if (UniversalSession.isDefaultTitle(conv.title) && hasNoUserMessages && text.trim()) {
|
|
681
656
|
const trimmed = text.trim().replace(/\s+/g, " ");
|
|
@@ -689,7 +664,6 @@ export class UniversalSession {
|
|
|
689
664
|
}
|
|
690
665
|
void this.refreshSessions();
|
|
691
666
|
}
|
|
692
|
-
// 4. 插入用户消息以及附件卡片(保证 Web UI 附件卡片折叠呈现与历史复原)
|
|
693
667
|
const userMsg = {
|
|
694
668
|
id: `u-${now}-${randomUUID().slice(0, 6)}`,
|
|
695
669
|
role: "user",
|
|
@@ -707,9 +681,7 @@ export class UniversalSession {
|
|
|
707
681
|
if (!conv.isEphemeral) {
|
|
708
682
|
this.store.saveConversation(this.cwd, conv);
|
|
709
683
|
}
|
|
710
|
-
// 用户发送了提示词,消费并清除当前会话的草稿
|
|
711
684
|
this.sessionDrafts.delete(conv.id);
|
|
712
|
-
// 确保底层驱动与当前对话的 driverSessionId 上下文同步(保证多轮对话连续且新建对话隔离)
|
|
713
685
|
if (conv.driverSessionId) {
|
|
714
686
|
await this.driver.resumeSession(conv.driverSessionId);
|
|
715
687
|
if (!isCurrent())
|
|
@@ -724,7 +696,6 @@ export class UniversalSession {
|
|
|
724
696
|
this.store.saveConversation(turn.cwd, conv);
|
|
725
697
|
}
|
|
726
698
|
}
|
|
727
|
-
// 3. 准备助手流式消息
|
|
728
699
|
const assistantMsgId = `a-${now}-${randomUUID().slice(0, 6)}`;
|
|
729
700
|
this.streamingThinking = "";
|
|
730
701
|
this.streamingText = "";
|
|
@@ -736,7 +707,6 @@ export class UniversalSession {
|
|
|
736
707
|
model: this.currentModel,
|
|
737
708
|
};
|
|
738
709
|
this.flushSnapshot();
|
|
739
|
-
// 4. 构建 AgentEventSink(时序保真:思考 -> 前置正文 -> 工具调用 -> 总结正文)
|
|
740
710
|
const sink = {
|
|
741
711
|
onSessionStarted: (sessionId) => {
|
|
742
712
|
conv.driverSessionId = sessionId;
|
|
@@ -779,8 +749,6 @@ export class UniversalSession {
|
|
|
779
749
|
argumentsText: JSON.stringify(args, null, 2),
|
|
780
750
|
};
|
|
781
751
|
this.streamingMessage.content.push(toolBlock);
|
|
782
|
-
// Publish the structural boundary before a following text/thinking delta.
|
|
783
|
-
// Otherwise the reducer can merge it into the block preceding this tool.
|
|
784
752
|
this.flushSnapshot();
|
|
785
753
|
},
|
|
786
754
|
onToolEnd: (callId, result) => {
|
|
@@ -838,7 +806,6 @@ export class UniversalSession {
|
|
|
838
806
|
if (this.streamingText) {
|
|
839
807
|
content.push({ type: "text", text: this.streamingText });
|
|
840
808
|
}
|
|
841
|
-
// 保留之前追加的 toolCall blocks
|
|
842
809
|
for (const b of this.streamingMessage.content) {
|
|
843
810
|
if (b.type === "toolCall") {
|
|
844
811
|
content.push(b);
|
|
@@ -877,7 +844,6 @@ export class UniversalSession {
|
|
|
877
844
|
conv.messages.push(...this.pendingToolResults);
|
|
878
845
|
this.pendingToolResults = [];
|
|
879
846
|
}
|
|
880
|
-
// 累计会话统计与上下文占用(底座统一驱动底栏上下文环、Token 计数、缓存命中率与累计成本)
|
|
881
847
|
if (!conv.stats) {
|
|
882
848
|
conv.stats = {
|
|
883
849
|
tokens: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
@@ -904,7 +870,6 @@ export class UniversalSession {
|
|
|
904
870
|
percent: totalCtx !== null && win > 0 ? Math.min(100, Math.round((totalCtx / win) * 100)) : null,
|
|
905
871
|
};
|
|
906
872
|
}
|
|
907
|
-
// 回写 Claude 分配的 session ID(保证多轮上下文连续)
|
|
908
873
|
if (typeof this.driver.getActiveSessionId === "function") {
|
|
909
874
|
const activeSid = this.driver.getActiveSessionId();
|
|
910
875
|
if (activeSid && conv.driverSessionId !== activeSid) {
|
|
@@ -914,23 +879,18 @@ export class UniversalSession {
|
|
|
914
879
|
finishTurnTiming(conv);
|
|
915
880
|
this.isStreaming = false;
|
|
916
881
|
this.streamingThinking = "";
|
|
917
|
-
// 先取本轮全文再清空:内联标记解析在清空之后读 streamingText,
|
|
918
|
-
// 条件恒为 false,[[conv:rename]]/[[action:suggest]] 在 universal
|
|
919
|
-
// 引擎(claude/durable 等驱动)下从不被解析。
|
|
920
882
|
const finalText = this.streamingText;
|
|
921
883
|
this.streamingText = "";
|
|
922
884
|
conv.updatedAt = Date.now();
|
|
923
885
|
if (!conv.isEphemeral) {
|
|
924
886
|
this.store.saveConversation(turn.cwd, conv);
|
|
925
887
|
}
|
|
926
|
-
// 解析本轮生成的内联标记(如 [[conv:rename:...]] / [[action:suggest:...]])
|
|
927
888
|
if (finalText && finalText.includes("[[")) {
|
|
928
889
|
this.markerOrigins.set(conv.id, turn);
|
|
929
890
|
void this.markerSvc.handleAssistantText(conv.id, finalText);
|
|
930
891
|
}
|
|
931
892
|
this.flushSnapshot();
|
|
932
893
|
void this.refreshSessions();
|
|
933
|
-
// 检查排队消息并自动处理
|
|
934
894
|
if (!this.switchingProject && !this.disposed && this.followUpQueue.length > 0) {
|
|
935
895
|
const next = this.followUpQueue.shift();
|
|
936
896
|
this.flushSnapshot(true);
|
|
@@ -942,7 +902,6 @@ export class UniversalSession {
|
|
|
942
902
|
return this.abortPromise;
|
|
943
903
|
if (!this.isStreaming)
|
|
944
904
|
return;
|
|
945
|
-
// Install the gate before finalizeTurn can dispatch a queued prompt.
|
|
946
905
|
this.abortPromise = Promise.resolve().then(async () => {
|
|
947
906
|
this.finalizeTurn();
|
|
948
907
|
await this.driver.abort();
|
|
@@ -960,7 +919,6 @@ export class UniversalSession {
|
|
|
960
919
|
}
|
|
961
920
|
async retryLast() {
|
|
962
921
|
const conv = this.activeConv;
|
|
963
|
-
// 找到最后一条 user 消息重新发送
|
|
964
922
|
for (let i = conv.messages.length - 1; i >= 0; i--) {
|
|
965
923
|
const m = conv.messages[i];
|
|
966
924
|
if (m.role === "user") {
|
|
@@ -981,9 +939,6 @@ export class UniversalSession {
|
|
|
981
939
|
}
|
|
982
940
|
}
|
|
983
941
|
}
|
|
984
|
-
// ---------------------------------------------------------------------------
|
|
985
|
-
// 对话生命周期
|
|
986
|
-
// ---------------------------------------------------------------------------
|
|
987
942
|
async newChat(_preset, ephemeral = false, onReady) {
|
|
988
943
|
const newConv = this.createEmptyConversation("新对话", Boolean(ephemeral));
|
|
989
944
|
this.conversations.set(newConv.id, newConv);
|
|
@@ -996,6 +951,16 @@ export class UniversalSession {
|
|
|
996
951
|
onReady?.(newConv.id);
|
|
997
952
|
return true;
|
|
998
953
|
}
|
|
954
|
+
async readQuickAskConversation(source, signal) {
|
|
955
|
+
signal.throwIfAborted();
|
|
956
|
+
const id = source.conversationId ?? source.sessionFile;
|
|
957
|
+
if (!id ||
|
|
958
|
+
!/^[a-zA-Z0-9_-]+$/.test(id) ||
|
|
959
|
+
(source.conversationId && source.sessionFile && source.conversationId !== source.sessionFile))
|
|
960
|
+
return undefined;
|
|
961
|
+
const conv = this.conversations.get(id) ?? this.store.loadConversation(this.cwd, id);
|
|
962
|
+
return conv ? captureQuickAskConversation(conv.title, conv.id, conv.messages, this.cwd) : undefined;
|
|
963
|
+
}
|
|
999
964
|
async switchConversation(id) {
|
|
1000
965
|
assertEngineWorkspaceSupported(this.sandboxes, this.cwd, this.engine);
|
|
1001
966
|
let conv = this.conversations.get(id);
|
|
@@ -1006,7 +971,6 @@ export class UniversalSession {
|
|
|
1006
971
|
}
|
|
1007
972
|
if (conv) {
|
|
1008
973
|
this.activeConvId = conv.id;
|
|
1009
|
-
// 同步底层驱动会话上下文(若存在)
|
|
1010
974
|
if (conv.driverSessionId) {
|
|
1011
975
|
await this.driver.resumeSession(conv.driverSessionId).catch(() => { });
|
|
1012
976
|
}
|
|
@@ -1071,9 +1035,7 @@ export class UniversalSession {
|
|
|
1071
1035
|
}
|
|
1072
1036
|
async deleteSession(path) {
|
|
1073
1037
|
const targetId = path.trim() || this.activeConvId;
|
|
1074
|
-
// 1. 从磁盘删除持久化会话记录
|
|
1075
1038
|
this.store.deleteConversation(this.cwd, targetId);
|
|
1076
|
-
// 2. 若内存中存在该会话,将其从内存中移除
|
|
1077
1039
|
if (this.conversations.has(targetId)) {
|
|
1078
1040
|
await this.dismissConversation(targetId, true, true);
|
|
1079
1041
|
}
|
|
@@ -1086,18 +1048,15 @@ export class UniversalSession {
|
|
|
1086
1048
|
const conv = this.conversations.get(id);
|
|
1087
1049
|
if (!conv)
|
|
1088
1050
|
return;
|
|
1089
|
-
// 若指定 withFinishedSubagents,级联清理该父会话下的已结束子代理
|
|
1090
1051
|
if (withFinishedSubagents) {
|
|
1091
1052
|
const kids = Array.from(this.conversations.values()).filter((c) => c.isSubagent && c.subagentParentId === id && !c.subagentStreaming);
|
|
1092
1053
|
for (const kid of kids) {
|
|
1093
1054
|
await this.dismissConversation(kid.id, false, force);
|
|
1094
1055
|
}
|
|
1095
1056
|
}
|
|
1096
|
-
// 若清理的本身是运行中的子代理,立即中止并清理其驱动
|
|
1097
1057
|
if (conv.isSubagent && conv.subagentStreaming) {
|
|
1098
1058
|
await this.stopSubagent(id);
|
|
1099
1059
|
}
|
|
1100
|
-
// 仅从运行中会话映射与草稿中移除,保留磁盘持久化记录(供历史面板随时回溯打开)
|
|
1101
1060
|
this.conversations.delete(id);
|
|
1102
1061
|
this.sessionDrafts.delete(id);
|
|
1103
1062
|
if (this.activeConvId === id) {
|
|
@@ -1158,7 +1117,6 @@ export class UniversalSession {
|
|
|
1158
1117
|
if (!targetConv) {
|
|
1159
1118
|
targetConv = this.activeConv;
|
|
1160
1119
|
}
|
|
1161
|
-
// 回滚与在途回合互斥:先落定在途回合再截断,否则 finalize 与 slice 交错导致截断/错位(#700)
|
|
1162
1120
|
if (targetConv.id === this.activeConvId && (this.isStreaming || this.streamingMessage)) {
|
|
1163
1121
|
await this.abort();
|
|
1164
1122
|
targetConv = this.activeConv;
|
|
@@ -1169,7 +1127,6 @@ export class UniversalSession {
|
|
|
1169
1127
|
this.flushSnapshot();
|
|
1170
1128
|
return;
|
|
1171
1129
|
}
|
|
1172
|
-
// 回滚截断到该消息之前
|
|
1173
1130
|
targetConv.messages = targetConv.messages.slice(0, idx);
|
|
1174
1131
|
targetConv.updatedAt = Date.now();
|
|
1175
1132
|
if (!targetConv.isEphemeral) {
|
|
@@ -1216,7 +1173,6 @@ export class UniversalSession {
|
|
|
1216
1173
|
if (forkedMessages.length > 0) {
|
|
1217
1174
|
forkedConv.updatedAt = Date.now();
|
|
1218
1175
|
}
|
|
1219
|
-
// 若底层驱动支持原生会话分叉(如 Durable 引擎的原生 CoW 分叉),保持事务级上下文关联
|
|
1220
1176
|
if (targetConv.driverSessionId && typeof this.driver.forkSession === "function") {
|
|
1221
1177
|
try {
|
|
1222
1178
|
const forkedSid = await this.driver.forkSession(targetConv.driverSessionId);
|
|
@@ -1224,9 +1180,7 @@ export class UniversalSession {
|
|
|
1224
1180
|
forkedConv.driverSessionId = forkedSid;
|
|
1225
1181
|
}
|
|
1226
1182
|
}
|
|
1227
|
-
catch {
|
|
1228
|
-
/* fallback */
|
|
1229
|
-
}
|
|
1183
|
+
catch { }
|
|
1230
1184
|
}
|
|
1231
1185
|
this.conversations.set(forkedConv.id, forkedConv);
|
|
1232
1186
|
if (!forkedConv.isEphemeral) {
|
|
@@ -1256,7 +1210,6 @@ export class UniversalSession {
|
|
|
1256
1210
|
this.flushSnapshot();
|
|
1257
1211
|
return;
|
|
1258
1212
|
}
|
|
1259
|
-
// Remove the question, its file asides and the abandoned suffix in place.
|
|
1260
1213
|
let cutIdx = idx;
|
|
1261
1214
|
while (cutIdx > 0 &&
|
|
1262
1215
|
conv.messages[cutIdx - 1]?.role === "custom" &&
|
|
@@ -1264,8 +1217,6 @@ export class UniversalSession {
|
|
|
1264
1217
|
cutIdx--;
|
|
1265
1218
|
}
|
|
1266
1219
|
conv.messages.splice(cutIdx);
|
|
1267
|
-
// Drivers expose no in-place history replacement. A fresh backend handle
|
|
1268
|
-
// prevents resume from restoring the discarded suffix; the UI identity stays.
|
|
1269
1220
|
conv.driverSessionId = undefined;
|
|
1270
1221
|
const context = conv.messages.map((m) => `[${m.role}] ${messageTextWithQuotes(m)}`).join("\n");
|
|
1271
1222
|
conv.updatedAt = Date.now();
|
|
@@ -1275,7 +1226,6 @@ export class UniversalSession {
|
|
|
1275
1226
|
}
|
|
1276
1227
|
this.flushSnapshot(true);
|
|
1277
1228
|
void this.refreshSessions();
|
|
1278
|
-
// Capture the destination before any asynchronous slash/skill lookup.
|
|
1279
1229
|
await this.prompt(text, attachments, undefined, conv, context ? `Previous conversation context:\n${context}` : "");
|
|
1280
1230
|
}
|
|
1281
1231
|
async refreshSessions() {
|
|
@@ -1316,7 +1266,6 @@ export class UniversalSession {
|
|
|
1316
1266
|
isEphemeral: Boolean(c.isEphemeral),
|
|
1317
1267
|
}));
|
|
1318
1268
|
this.send({ type: "conversations", conversations: convs, activeId: this.activeConvId });
|
|
1319
|
-
// 左侧栏历史对话读取的是 sessions 消息(轻量临时子代理不污染长期历史列表):
|
|
1320
1269
|
const sessionSummaries = allList
|
|
1321
1270
|
.filter((c) => !c.isSubagent || !c.isEphemeral)
|
|
1322
1271
|
.map((c) => {
|
|
@@ -1339,7 +1288,6 @@ export class UniversalSession {
|
|
|
1339
1288
|
});
|
|
1340
1289
|
this.send({ type: "sessions", sessions: sessionSummaries });
|
|
1341
1290
|
}
|
|
1342
|
-
/** 引擎自属的会话展示名解析回调(定制 Universal/Claude 的首条截断 + 自定义命名策略) */
|
|
1343
1291
|
resolveSessionDisplayName(conv, firstMsg) {
|
|
1344
1292
|
if (conv.title && !UniversalSession.isDefaultTitle(conv.title)) {
|
|
1345
1293
|
return conv.title;
|
|
@@ -1432,9 +1380,6 @@ export class UniversalSession {
|
|
|
1432
1380
|
this.send({ type: "session_search_results", reqId, query, ok: false, results: [] });
|
|
1433
1381
|
}
|
|
1434
1382
|
}
|
|
1435
|
-
// ---------------------------------------------------------------------------
|
|
1436
|
-
// 文件、终端与 Git SCM 委托
|
|
1437
|
-
// ---------------------------------------------------------------------------
|
|
1438
1383
|
async listFiles(path) {
|
|
1439
1384
|
await this.files.listFiles(path);
|
|
1440
1385
|
}
|
|
@@ -1485,9 +1430,6 @@ export class UniversalSession {
|
|
|
1485
1430
|
getTerminalCwd() {
|
|
1486
1431
|
return this.cwd;
|
|
1487
1432
|
}
|
|
1488
|
-
// ---------------------------------------------------------------------------
|
|
1489
|
-
// 后台服务生命周期委托
|
|
1490
|
-
// ---------------------------------------------------------------------------
|
|
1491
1433
|
async killBackgroundServer(port, _taskId) {
|
|
1492
1434
|
if (port === undefined)
|
|
1493
1435
|
return false;
|
|
@@ -1512,9 +1454,6 @@ export class UniversalSession {
|
|
|
1512
1454
|
const minutes = Number.isFinite(override) && override > 0 ? override : 30;
|
|
1513
1455
|
return this.bg.cleanStale(minutes * 60_000, { manual: true });
|
|
1514
1456
|
}
|
|
1515
|
-
// ---------------------------------------------------------------------------
|
|
1516
|
-
// 模型与偏好控制
|
|
1517
|
-
// ---------------------------------------------------------------------------
|
|
1518
1457
|
async listModels() {
|
|
1519
1458
|
if (this.driver.listModels) {
|
|
1520
1459
|
const models = await this.driver.listModels();
|
|
@@ -1554,12 +1493,10 @@ export class UniversalSession {
|
|
|
1554
1493
|
if (this.driver.setModel) {
|
|
1555
1494
|
await this.driver.setModel(modelId);
|
|
1556
1495
|
}
|
|
1557
|
-
// 优先恢复该模型的全局思考强度记忆或全局默认强度
|
|
1558
1496
|
const remembered = getModelThinkingLevelFromSettings(modelId, this.agentDir);
|
|
1559
1497
|
if (remembered) {
|
|
1560
1498
|
this.thinkingLevel = remembered;
|
|
1561
1499
|
}
|
|
1562
|
-
// 校验并平滑适应新模型支持的思考强度
|
|
1563
1500
|
if (typeof this.driver.getSupportedThinkingLevels === "function") {
|
|
1564
1501
|
const supported = this.driver.getSupportedThinkingLevels(modelId);
|
|
1565
1502
|
if (supported.length > 0 && !supported.includes(this.thinkingLevel)) {
|
|
@@ -1595,7 +1532,6 @@ export class UniversalSession {
|
|
|
1595
1532
|
if (typeof this.driver.setThinkingLevel === "function") {
|
|
1596
1533
|
this.driver.setThinkingLevel(level);
|
|
1597
1534
|
}
|
|
1598
|
-
// 同步持久化至全局 settings.json 的 modelThinkingLevels
|
|
1599
1535
|
if (this.currentModel) {
|
|
1600
1536
|
saveModelThinkingLevelToSettings(this.currentModel, level, this.agentDir);
|
|
1601
1537
|
}
|
|
@@ -1607,7 +1543,6 @@ export class UniversalSession {
|
|
|
1607
1543
|
throw new Error("Workspace switch already in progress");
|
|
1608
1544
|
this.switchingProject = true;
|
|
1609
1545
|
try {
|
|
1610
|
-
// Finish the captured old turn before replacing the driver's workspace.
|
|
1611
1546
|
this.followUpQueue = [];
|
|
1612
1547
|
await this.abort();
|
|
1613
1548
|
for (const id of this.subagentDrivers.keys())
|
|
@@ -1615,7 +1550,6 @@ export class UniversalSession {
|
|
|
1615
1550
|
this.projectGeneration++;
|
|
1616
1551
|
this.cwd = path;
|
|
1617
1552
|
this.driver.setCwd(path);
|
|
1618
|
-
// 切换工作区 CWD:清空旧目录会话缓存与草稿,并加载属于新目录的会话
|
|
1619
1553
|
this.conversations.clear();
|
|
1620
1554
|
this.sessionDrafts.clear();
|
|
1621
1555
|
const existing = this.store.listConversations(this.cwd);
|
|
@@ -1637,7 +1571,6 @@ export class UniversalSession {
|
|
|
1637
1571
|
this.stateStore.remember(this.clientId, path);
|
|
1638
1572
|
}
|
|
1639
1573
|
void this.pushProjects();
|
|
1640
|
-
// 切换目录后恢复该目录按引擎隔离的项目记忆模型
|
|
1641
1574
|
const savedModel = this.stateStore?.getProjectModel(this.clientId, path, this.engine) ??
|
|
1642
1575
|
this.stateStore?.getDefaultModel(this.engine);
|
|
1643
1576
|
if (savedModel && savedModel !== this.currentModel) {
|
|
@@ -1663,11 +1596,9 @@ export class UniversalSession {
|
|
|
1663
1596
|
this.worktreeInfo = info;
|
|
1664
1597
|
this.flushSnapshot();
|
|
1665
1598
|
}
|
|
1666
|
-
/** 获取通用底座持有的持久终端交互工具集 */
|
|
1667
1599
|
getTerminalTools() {
|
|
1668
1600
|
return makePersistentTerminalTools(this.terminals, this.cwd, () => this.lang);
|
|
1669
1601
|
}
|
|
1670
|
-
/** 执行通用底座持久终端工具(供外部驱动或模型调用) */
|
|
1671
1602
|
async execTerminalTool(name, args, signal) {
|
|
1672
1603
|
const tools = this.getTerminalTools();
|
|
1673
1604
|
const tool = tools.find((t) => t.name === name);
|
|
@@ -1882,9 +1813,6 @@ export class UniversalSession {
|
|
|
1882
1813
|
async makeDir(path) {
|
|
1883
1814
|
await this.files.makeDir(path);
|
|
1884
1815
|
}
|
|
1885
|
-
// ---------------------------------------------------------------------------
|
|
1886
|
-
// 辅助方法与空实现
|
|
1887
|
-
// ---------------------------------------------------------------------------
|
|
1888
1816
|
emitNotice(level, text, textEn) {
|
|
1889
1817
|
this.send({ type: "notice", level, text, textEn });
|
|
1890
1818
|
}
|
|
@@ -1919,9 +1847,7 @@ export class UniversalSession {
|
|
|
1919
1847
|
}
|
|
1920
1848
|
}
|
|
1921
1849
|
}
|
|
1922
|
-
catch {
|
|
1923
|
-
/* ignore driver model query error */
|
|
1924
|
-
}
|
|
1850
|
+
catch { }
|
|
1925
1851
|
}
|
|
1926
1852
|
return out;
|
|
1927
1853
|
}
|
|
@@ -1942,9 +1868,7 @@ export class UniversalSession {
|
|
|
1942
1868
|
}
|
|
1943
1869
|
}
|
|
1944
1870
|
}
|
|
1945
|
-
catch {
|
|
1946
|
-
/* ignore driver skills query error */
|
|
1947
|
-
}
|
|
1871
|
+
catch { }
|
|
1948
1872
|
}
|
|
1949
1873
|
this.skillsCache = out;
|
|
1950
1874
|
return out;
|
|
@@ -1985,9 +1909,7 @@ export class UniversalSession {
|
|
|
1985
1909
|
async listCommands() {
|
|
1986
1910
|
this.send({ type: "commands", commands: [], path: "" });
|
|
1987
1911
|
}
|
|
1988
|
-
async saveCommands(_commands) {
|
|
1989
|
-
/* no-op */
|
|
1990
|
-
}
|
|
1912
|
+
async saveCommands(_commands) { }
|
|
1991
1913
|
refreshSettings() {
|
|
1992
1914
|
this.pushSettings();
|
|
1993
1915
|
}
|
|
@@ -2003,6 +1925,7 @@ export class UniversalSession {
|
|
|
2003
1925
|
disabledExtensions: s?.disabledExtensions ?? [],
|
|
2004
1926
|
disabledAgentTools: [],
|
|
2005
1927
|
disabledPluginTools: [],
|
|
1928
|
+
nativeCliInheritModel: { ...s?.nativeCliInheritModel },
|
|
2006
1929
|
terminalToolsEnabled: s?.terminalToolsEnabled ?? true,
|
|
2007
1930
|
terminalBash: s?.terminalBash ?? true,
|
|
2008
1931
|
terminalBashIdleMs: s?.terminalBashIdleMs ?? 3000,
|
|
@@ -2010,7 +1933,6 @@ export class UniversalSession {
|
|
|
2010
1933
|
toolWatchdogTimeoutMs: s?.toolWatchdogTimeoutMs ?? 1200000,
|
|
2011
1934
|
readDirEnabled: true,
|
|
2012
1935
|
bgAutoCleanupMin: s?.bgAutoCleanupMin ?? 0,
|
|
2013
|
-
// 同一字段的含义在本引擎不适用(无 pi 工具注册面):恒为 false 占位,保协议完整。
|
|
2014
1936
|
toolLazyLoading: false,
|
|
2015
1937
|
codemodeMode: "on",
|
|
2016
1938
|
codemodeInlineBudget: 3000,
|
|
@@ -2093,15 +2015,9 @@ export class UniversalSession {
|
|
|
2093
2015
|
}
|
|
2094
2016
|
this.pushSettings();
|
|
2095
2017
|
}
|
|
2096
|
-
async reloadExtensions() {
|
|
2097
|
-
|
|
2098
|
-
}
|
|
2099
|
-
async checkUpdate() {
|
|
2100
|
-
/* no-op */
|
|
2101
|
-
}
|
|
2102
|
-
async checkUpdatesAll() {
|
|
2103
|
-
/* no-op */
|
|
2104
|
-
}
|
|
2018
|
+
async reloadExtensions() { }
|
|
2019
|
+
async checkUpdate() { }
|
|
2020
|
+
async checkUpdatesAll() { }
|
|
2105
2021
|
resolveDialog(id, value) {
|
|
2106
2022
|
this.webUi.resolveDialog(id, value);
|
|
2107
2023
|
}
|
|
@@ -2115,7 +2031,6 @@ export class UniversalSession {
|
|
|
2115
2031
|
this.webUi.handleTuiOverlayCancel(id);
|
|
2116
2032
|
}
|
|
2117
2033
|
installPiAgent() {
|
|
2118
|
-
/* no-op */
|
|
2119
2034
|
return Promise.resolve();
|
|
2120
2035
|
}
|
|
2121
2036
|
setProviderApiKey(provider, apiKey) {
|
|
@@ -2195,15 +2110,12 @@ export class UniversalSession {
|
|
|
2195
2110
|
return Promise.resolve();
|
|
2196
2111
|
}
|
|
2197
2112
|
clearGoal() {
|
|
2198
|
-
/* no-op */
|
|
2199
2113
|
return Promise.resolve();
|
|
2200
2114
|
}
|
|
2201
2115
|
startGoalWizard() {
|
|
2202
|
-
/* no-op */
|
|
2203
2116
|
return Promise.resolve();
|
|
2204
2117
|
}
|
|
2205
2118
|
setGoalPrefs() {
|
|
2206
|
-
/* no-op */
|
|
2207
2119
|
return Promise.resolve();
|
|
2208
2120
|
}
|
|
2209
2121
|
async savePreset(name) {
|
|
@@ -2241,7 +2153,6 @@ export class UniversalSession {
|
|
|
2241
2153
|
this.emitNotice("error", `未找到名为「${name}」的设置预设`, `Settings preset "${name}" not found`);
|
|
2242
2154
|
return;
|
|
2243
2155
|
}
|
|
2244
|
-
// Missing settings retain their current values; metadata never enters settings.
|
|
2245
2156
|
const { settings } = sanitizePresetSettings(found);
|
|
2246
2157
|
this.stateStore.saveSettings(this.clientId, settings);
|
|
2247
2158
|
this.pushSettings();
|
|
@@ -2441,10 +2352,6 @@ export class UniversalSession {
|
|
|
2441
2352
|
error: res.error,
|
|
2442
2353
|
});
|
|
2443
2354
|
}
|
|
2444
|
-
// ---------------------------------------------------------------------------
|
|
2445
|
-
// 通用底座第一方子代理(Subagent)生命周期与调度管理
|
|
2446
|
-
// ---------------------------------------------------------------------------
|
|
2447
|
-
/** 统计当前活跃(流式运行中)的子代理数量 */
|
|
2448
2355
|
getLiveSubagentsCount() {
|
|
2449
2356
|
let count = 0;
|
|
2450
2357
|
for (const conv of this.conversations.values()) {
|
|
@@ -2454,7 +2361,6 @@ export class UniversalSession {
|
|
|
2454
2361
|
}
|
|
2455
2362
|
return count;
|
|
2456
2363
|
}
|
|
2457
|
-
/** 创建并启动一个子代理会话 */
|
|
2458
2364
|
async spawnSubagent(prompt, type, cwd, templateName, model, parentId, persist = false, title, _thinking, _notifyOnDone) {
|
|
2459
2365
|
if (_notifyOnDone === "manual") {
|
|
2460
2366
|
throw new Error("notifyOnDone=manual is only supported by the pi engine.");
|
|
@@ -2468,7 +2374,6 @@ export class UniversalSession {
|
|
|
2468
2374
|
if (liveCount >= maxSubagents) {
|
|
2469
2375
|
throw new Error(pick(this.lang, `同时运行的子代理数量已达上限(${maxSubagents} 个),请先用 wait 等一部分完成、或用 stop 停掉不需要的再派发`, `Active subagent limit reached (${maxSubagents} live). Wait for some with wait_all or stop unneeded ones with stop before spawning more`));
|
|
2470
2376
|
}
|
|
2471
|
-
// 检查并解析模板
|
|
2472
2377
|
let template;
|
|
2473
2378
|
let effectivePrompt = prompt;
|
|
2474
2379
|
if (templateName) {
|
|
@@ -2525,7 +2430,6 @@ export class UniversalSession {
|
|
|
2525
2430
|
}
|
|
2526
2431
|
this.flushSnapshot();
|
|
2527
2432
|
void this.refreshSessions();
|
|
2528
|
-
// 为该子代理创建独立的 Driver 实例
|
|
2529
2433
|
let subDriver;
|
|
2530
2434
|
if (this.driverFactory) {
|
|
2531
2435
|
subDriver = this.driverFactory(targetCwd);
|
|
@@ -2542,22 +2446,17 @@ export class UniversalSession {
|
|
|
2542
2446
|
subDriver = this.driver;
|
|
2543
2447
|
}
|
|
2544
2448
|
this.subagentDrivers.set(convId, subDriver);
|
|
2545
|
-
// 若驱动支持 setModel,应用子代理指定的模型
|
|
2546
2449
|
if (effectiveModel && subDriver.setModel) {
|
|
2547
2450
|
try {
|
|
2548
2451
|
await subDriver.setModel(effectiveModel);
|
|
2549
2452
|
}
|
|
2550
|
-
catch {
|
|
2551
|
-
// 驱动不支持或模型设置失败时平滑降级
|
|
2552
|
-
}
|
|
2453
|
+
catch { }
|
|
2553
2454
|
}
|
|
2554
2455
|
if (this.disposed || generation !== this.projectGeneration || this.subagentDrivers.get(convId) !== subDriver)
|
|
2555
2456
|
return { convId };
|
|
2556
|
-
// 异步启动子代理执行流程
|
|
2557
2457
|
void this.runSubagent(convId, subDriver, effectivePrompt, targetCwd);
|
|
2558
2458
|
return { convId };
|
|
2559
2459
|
}
|
|
2560
|
-
/** 后台异步执行子代理 Prompt */
|
|
2561
2460
|
async runSubagent(convId, subDriver, prompt, cwd) {
|
|
2562
2461
|
const conv = this.conversations.get(convId);
|
|
2563
2462
|
if (!conv)
|
|
@@ -2590,7 +2489,6 @@ export class UniversalSession {
|
|
|
2590
2489
|
assistantMsg.content.push({ type: "thinking", thinking: delta });
|
|
2591
2490
|
}
|
|
2592
2491
|
if (this.activeConvId === convId) {
|
|
2593
|
-
// Subagents stream through conv.messages snapshots, not the main turn's message.
|
|
2594
2492
|
this.scheduleThrottledSnapshot();
|
|
2595
2493
|
}
|
|
2596
2494
|
},
|
|
@@ -2654,9 +2552,7 @@ export class UniversalSession {
|
|
|
2654
2552
|
try {
|
|
2655
2553
|
void subDriver.dispose();
|
|
2656
2554
|
}
|
|
2657
|
-
catch {
|
|
2658
|
-
// 忽略 dispose 异常
|
|
2659
|
-
}
|
|
2555
|
+
catch { }
|
|
2660
2556
|
this.notifySubagentWaitListeners();
|
|
2661
2557
|
this.flushSnapshot();
|
|
2662
2558
|
void this.refreshSessions();
|
|
@@ -2674,9 +2570,7 @@ export class UniversalSession {
|
|
|
2674
2570
|
try {
|
|
2675
2571
|
void subDriver.dispose();
|
|
2676
2572
|
}
|
|
2677
|
-
catch {
|
|
2678
|
-
// 忽略 dispose 异常
|
|
2679
|
-
}
|
|
2573
|
+
catch { }
|
|
2680
2574
|
this.notifySubagentWaitListeners();
|
|
2681
2575
|
this.flushSnapshot();
|
|
2682
2576
|
void this.refreshSessions();
|
|
@@ -2705,7 +2599,6 @@ export class UniversalSession {
|
|
|
2705
2599
|
sink.onError(msg);
|
|
2706
2600
|
}
|
|
2707
2601
|
}
|
|
2708
|
-
/** 获取单个子代理运行态快照结果 */
|
|
2709
2602
|
async getSubagentResult(convId) {
|
|
2710
2603
|
const conv = this.conversations.get(convId);
|
|
2711
2604
|
if (!conv || !conv.isSubagent) {
|
|
@@ -2713,7 +2606,6 @@ export class UniversalSession {
|
|
|
2713
2606
|
}
|
|
2714
2607
|
return this.subagentToSnapshot(conv);
|
|
2715
2608
|
}
|
|
2716
|
-
/** 提取子代理会话的最终 assistant 正文输出 */
|
|
2717
2609
|
extractSubagentOutput(conv) {
|
|
2718
2610
|
const assistantMsgs = conv.messages.filter((m) => m.role === "assistant");
|
|
2719
2611
|
const pieces = [];
|
|
@@ -2726,7 +2618,6 @@ export class UniversalSession {
|
|
|
2726
2618
|
}
|
|
2727
2619
|
return pieces.join("\n").trim();
|
|
2728
2620
|
}
|
|
2729
|
-
/** 将 UniversalConversation 转换成标准 SubagentSnapshot */
|
|
2730
2621
|
subagentToSnapshot(conv) {
|
|
2731
2622
|
const output = this.extractSubagentOutput(conv);
|
|
2732
2623
|
const state = conv.subagentState ?? (conv.subagentStreaming ? "running" : conv.subagentCanceled ? "canceled" : "done");
|
|
@@ -2748,7 +2639,6 @@ export class UniversalSession {
|
|
|
2748
2639
|
handoffFrom: conv.subagentHandoffFrom ? [...conv.subagentHandoffFrom] : undefined,
|
|
2749
2640
|
};
|
|
2750
2641
|
}
|
|
2751
|
-
/** 停止指定的子代理运行 */
|
|
2752
2642
|
async stopSubagent(convId) {
|
|
2753
2643
|
const conv = this.conversations.get(convId);
|
|
2754
2644
|
if (!conv)
|
|
@@ -2764,15 +2654,12 @@ export class UniversalSession {
|
|
|
2764
2654
|
await driver.abort();
|
|
2765
2655
|
void driver.dispose();
|
|
2766
2656
|
}
|
|
2767
|
-
catch {
|
|
2768
|
-
// 忽略驱动中止失败
|
|
2769
|
-
}
|
|
2657
|
+
catch { }
|
|
2770
2658
|
}
|
|
2771
2659
|
this.notifySubagentWaitListeners();
|
|
2772
2660
|
this.flushSnapshot();
|
|
2773
2661
|
void this.refreshSessions();
|
|
2774
2662
|
}
|
|
2775
|
-
/** 等待指定的子代理到达终态 */
|
|
2776
2663
|
async waitSubagents(timeoutSeconds, runIds, callerId) {
|
|
2777
2664
|
const waitCapMs = computeWaitCapMs();
|
|
2778
2665
|
const requestedMs = typeof timeoutSeconds === "number" && timeoutSeconds > 0 ? Math.floor(timeoutSeconds * 1000) : waitCapMs;
|
|
@@ -2825,18 +2712,14 @@ export class UniversalSession {
|
|
|
2825
2712
|
this.subagentWaitListeners.add(onUpdate);
|
|
2826
2713
|
});
|
|
2827
2714
|
}
|
|
2828
|
-
/** 唤醒所有等待中的子代理监听者 */
|
|
2829
2715
|
notifySubagentWaitListeners() {
|
|
2830
2716
|
for (const listener of this.subagentWaitListeners) {
|
|
2831
2717
|
try {
|
|
2832
2718
|
listener();
|
|
2833
2719
|
}
|
|
2834
|
-
catch {
|
|
2835
|
-
// 忽略监听者异常
|
|
2836
|
-
}
|
|
2720
|
+
catch { }
|
|
2837
2721
|
}
|
|
2838
2722
|
}
|
|
2839
|
-
/** 列出子代理快照列表 */
|
|
2840
2723
|
listSubagents(scope = "all") {
|
|
2841
2724
|
const snaps = [];
|
|
2842
2725
|
for (const conv of this.conversations.values()) {
|
|
@@ -2850,7 +2733,6 @@ export class UniversalSession {
|
|
|
2850
2733
|
}
|
|
2851
2734
|
return snaps;
|
|
2852
2735
|
}
|
|
2853
|
-
/** 向指定子代理发送引导/追加消息 */
|
|
2854
2736
|
async steerSubagent(convId, message) {
|
|
2855
2737
|
const conv = this.conversations.get(convId);
|
|
2856
2738
|
if (!conv || !conv.isSubagent) {
|
|
@@ -2865,7 +2747,6 @@ export class UniversalSession {
|
|
|
2865
2747
|
conv.updatedAt = Date.now();
|
|
2866
2748
|
this.flushSnapshot();
|
|
2867
2749
|
}
|
|
2868
|
-
/** 跨代理协作交接 */
|
|
2869
2750
|
async handoffSubagent(fromRunId, toRunId, payload) {
|
|
2870
2751
|
const fromConv = this.conversations.get(fromRunId);
|
|
2871
2752
|
const toConv = this.conversations.get(toRunId);
|
|
@@ -2882,7 +2763,6 @@ export class UniversalSession {
|
|
|
2882
2763
|
timestamp: Date.now(),
|
|
2883
2764
|
};
|
|
2884
2765
|
this.subagentHandoffs = recordSubagentHandoff(this.subagentHandoffs, record, 50);
|
|
2885
|
-
// 向目标子代理注入交接卡片消息
|
|
2886
2766
|
const now = Date.now();
|
|
2887
2767
|
const fromType = fromConv?.subagentType ?? "peer";
|
|
2888
2768
|
toConv.messages.push({
|
|
@@ -2907,9 +2787,7 @@ export class UniversalSession {
|
|
|
2907
2787
|
void driver.abort();
|
|
2908
2788
|
void driver.dispose();
|
|
2909
2789
|
}
|
|
2910
|
-
catch {
|
|
2911
|
-
// 忽略驱动释放异常
|
|
2912
|
-
}
|
|
2790
|
+
catch { }
|
|
2913
2791
|
}
|
|
2914
2792
|
this.subagentDrivers.clear();
|
|
2915
2793
|
this.subagentWaitListeners.clear();
|