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,27 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 排队消息(插队 steer / 排队 followUp)纯函数 —— 独立成模块是为了可单测
|
|
3
|
-
* (`AgentService` 依赖 SDK 与运行时,不适合在单测里 import)。
|
|
4
|
-
*
|
|
5
|
-
* 背景:pi SDK 没有「按条操作队列」的 API,服务端移除一条排队消息的做法是
|
|
6
|
-
* `clearQueue()` 之后把幸存者按原顺序重新入队(见 `AgentService.removeQueued`)。
|
|
7
|
-
* 重建时若用值过滤(`list.filter((t) => t !== text)`),会把**所有**同文本项一起删掉;
|
|
8
|
-
* 而气泡上的 ✕ 只对应一条消息、本地显示镜像也只移除一条 → 同一条文本被排队两次时
|
|
9
|
-
* 「点一次 ✕ 删两条」,且显示与真实队列在下次 `queue_update` 之前不一致。
|
|
10
|
-
* 因此统一按「只移除第一处匹配」处理。
|
|
11
|
-
*/
|
|
12
|
-
/** 移除列表中第一处等于 `text` 的项;找不到时返回入参的拷贝(不修改入参)。 */
|
|
13
1
|
export function removeFirstOccurrence(list, text) {
|
|
14
2
|
const index = list.indexOf(text);
|
|
15
3
|
if (index < 0)
|
|
16
4
|
return [...list];
|
|
17
5
|
return [...list.slice(0, index), ...list.slice(index + 1)];
|
|
18
6
|
}
|
|
19
|
-
/**
|
|
20
|
-
* 按气泡下标移除一条排队消息(✕ 对应的是「第几个气泡」,不是「哪段文本」)。
|
|
21
|
-
* `index` 越界、非整数、或该位置文本与 `text` 对不上(点击与执行之间队列
|
|
22
|
-
* 已变化——有条消息刚送达或新入队)时,回落到 `removeFirstOccurrence` 的文本匹配,
|
|
23
|
-
* 保持旧客户端(只发 text)行为不变。不修改入参。
|
|
24
|
-
*/
|
|
25
7
|
export function removeQueuedByIndexOrText(list, text, index) {
|
|
26
8
|
if (typeof index === "number" &&
|
|
27
9
|
Number.isInteger(index) &&
|
|
@@ -45,12 +27,6 @@ export function createQueuedEntry(text, opts) {
|
|
|
45
27
|
createdAt: opts?.createdAt ?? Date.now(),
|
|
46
28
|
};
|
|
47
29
|
}
|
|
48
|
-
/**
|
|
49
|
-
* 跨端/跨引擎统一剔除排队条目:
|
|
50
|
-
* 1. 优先按 `query.id` 绝对精准匹配(免疫并发下标漂移与同文本覆盖);
|
|
51
|
-
* 2. 其次按 `query.index`(需校验文本相符);
|
|
52
|
-
* 3. 兜底按 `query.text` 匹配首处项(兼容旧客户端)。
|
|
53
|
-
*/
|
|
54
30
|
export function removeQueuedEntry(list, query) {
|
|
55
31
|
if (query.id) {
|
|
56
32
|
const idx = list.findIndex((e) => e.id === query.id);
|
|
@@ -73,15 +49,9 @@ export function removeQueuedEntry(list, query) {
|
|
|
73
49
|
}
|
|
74
50
|
return [...list];
|
|
75
51
|
}
|
|
76
|
-
/**
|
|
77
|
-
* 按气泡下标移除一个排队条目(兼容历史调用签名)。
|
|
78
|
-
*/
|
|
79
52
|
export function removeQueuedEntryByIndexOrText(list, text, index) {
|
|
80
53
|
return removeQueuedEntry(list, { text, index });
|
|
81
54
|
}
|
|
82
|
-
/**
|
|
83
|
-
* 入队 prompt 抛错时的快速回滚:从末尾向前查找第一个匹配文本的条目并弹出(issue #718)。
|
|
84
|
-
*/
|
|
85
55
|
export function rollbackQueuedEntry(list, text) {
|
|
86
56
|
for (let i = list.length - 1; i >= 0; i--) {
|
|
87
57
|
if (list[i]?.text === text) {
|
|
@@ -90,11 +60,6 @@ export function rollbackQueuedEntry(list, text) {
|
|
|
90
60
|
}
|
|
91
61
|
return [...list];
|
|
92
62
|
}
|
|
93
|
-
/**
|
|
94
|
-
* 将本地条目列表与 SDK 权威的 `newTexts` 队列文本对账(issue #718)。
|
|
95
|
-
* 遵循 SDK 先进先出(FIFO)头部出队机制,优先保留尾部幸存者的完整条目元数据;
|
|
96
|
-
* 保证对账后返回的条目数量与顺序与 `newTexts` 严格一致。
|
|
97
|
-
*/
|
|
98
63
|
export function reconcileQueuedEntries(currentEntries, newTexts) {
|
|
99
64
|
if (!newTexts || newTexts.length === 0) {
|
|
100
65
|
return [];
|
|
@@ -102,7 +67,6 @@ export function reconcileQueuedEntries(currentEntries, newTexts) {
|
|
|
102
67
|
if (!currentEntries || currentEntries.length === 0) {
|
|
103
68
|
return newTexts.map((text) => createQueuedEntry(text));
|
|
104
69
|
}
|
|
105
|
-
// 1. 长度一致且文本逐项吻合
|
|
106
70
|
if (currentEntries.length === newTexts.length) {
|
|
107
71
|
let allMatch = true;
|
|
108
72
|
for (let i = 0; i < newTexts.length; i++) {
|
|
@@ -115,7 +79,6 @@ export function reconcileQueuedEntries(currentEntries, newTexts) {
|
|
|
115
79
|
return [...currentEntries];
|
|
116
80
|
}
|
|
117
81
|
}
|
|
118
|
-
// 2. 队列缩短(常见场景:SDK 头部 FIFO 出队消费一条或多条消息)
|
|
119
82
|
if (currentEntries.length > newTexts.length) {
|
|
120
83
|
const dropCount = currentEntries.length - newTexts.length;
|
|
121
84
|
const headDropped = currentEntries.slice(dropCount);
|
|
@@ -130,7 +93,6 @@ export function reconcileQueuedEntries(currentEntries, newTexts) {
|
|
|
130
93
|
return headDropped;
|
|
131
94
|
}
|
|
132
95
|
}
|
|
133
|
-
// 3. 队列增长(常见场景:前缀保持,尾部追加)
|
|
134
96
|
if (currentEntries.length < newTexts.length) {
|
|
135
97
|
let prefixMatch = true;
|
|
136
98
|
for (let i = 0; i < currentEntries.length; i++) {
|
|
@@ -147,8 +109,6 @@ export function reconcileQueuedEntries(currentEntries, newTexts) {
|
|
|
147
109
|
return res;
|
|
148
110
|
}
|
|
149
111
|
}
|
|
150
|
-
// 4. 容错通用对齐(例如中间删除或非对齐位移):
|
|
151
|
-
// 倒序优先匹配尾部幸存条目(排队为追加写入,尾部条目存活概率更高)
|
|
152
112
|
const available = currentEntries.map((e, idx) => ({ ...e, idx, used: false }));
|
|
153
113
|
const result = new Array(newTexts.length);
|
|
154
114
|
for (let i = newTexts.length - 1; i >= 0; i--) {
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { constants } from "node:fs";
|
|
3
|
+
import { open, opendir, realpath, lstat } from "node:fs/promises";
|
|
4
|
+
import { basename, join, resolve } from "node:path";
|
|
5
|
+
import { isAbsoluteWirePath, wireToAbs, workspacePath } from "./files-service.js";
|
|
6
|
+
import { isSameOrSubpath } from "./sandbox-service.js";
|
|
7
|
+
import { isRemoteWorkspaceUri } from "./remote-ssh-service.js";
|
|
8
|
+
import { decodeText, looksLikeText, sniffImageMime } from "./text-sniff.js";
|
|
9
|
+
import { createConversationReadHost } from "./tool-host-factories.js";
|
|
10
|
+
import { normalizePathKey } from "./client-state.js";
|
|
11
|
+
export const MAX_QUICK_ASK_ATTACHMENTS = 8;
|
|
12
|
+
export const MAX_QUICK_ASK_ATTACHMENT_TEXT = 32_768;
|
|
13
|
+
export const MAX_QUICK_ASK_IMAGE_BYTES = 2 * 1024 * 1024;
|
|
14
|
+
export const MAX_QUICK_ASK_TOTAL_IMAGE_BYTES = 6 * 1024 * 1024;
|
|
15
|
+
export const QUICK_ASK_CONTEXT_TIMEOUT_MS = 15_000;
|
|
16
|
+
const MAX_DIRECTORY_ENTRIES = 100;
|
|
17
|
+
const MAX_DIRECTORY_DEPTH = 2;
|
|
18
|
+
const MAX_DIRECTORY_BYTES = 2 * 1024 * 1024;
|
|
19
|
+
const IMAGE_MIMES = new Set(["image/png", "image/jpeg", "image/gif", "image/webp"]);
|
|
20
|
+
const TRUNCATED = "\n[Snapshot truncated at the reference limit]";
|
|
21
|
+
function attachmentId(kind, ...source) {
|
|
22
|
+
return `qa-${kind}-${createHash("sha256").update(JSON.stringify(source)).digest("hex")}`;
|
|
23
|
+
}
|
|
24
|
+
export class QuickAskError extends Error {
|
|
25
|
+
status;
|
|
26
|
+
constructor(status, message) {
|
|
27
|
+
super(message);
|
|
28
|
+
this.status = status;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function captureQuickAskConversation(name, path, messages, cwd) {
|
|
32
|
+
const captured = [];
|
|
33
|
+
for (const message of messages) {
|
|
34
|
+
if (message.role !== "user" && message.role !== "assistant")
|
|
35
|
+
continue;
|
|
36
|
+
const content = typeof message.content === "string"
|
|
37
|
+
? message.content
|
|
38
|
+
: Array.isArray(message.content)
|
|
39
|
+
? message.content
|
|
40
|
+
.filter((block) => block?.type === "text" && typeof block.text === "string")
|
|
41
|
+
.map((block) => block.text)
|
|
42
|
+
.join("\n")
|
|
43
|
+
: "";
|
|
44
|
+
if (content.trim())
|
|
45
|
+
captured.push({ role: message.role, content });
|
|
46
|
+
}
|
|
47
|
+
return { name, ...(path ? { path } : {}), ...(cwd ? { cwd } : {}), messages: captured };
|
|
48
|
+
}
|
|
49
|
+
export async function readQuickAskHistoryConversation(source, signal) {
|
|
50
|
+
if (!source.sessionFile || source.conversationId)
|
|
51
|
+
return undefined;
|
|
52
|
+
signal.throwIfAborted();
|
|
53
|
+
const host = createConversationReadHost({
|
|
54
|
+
getConversations: () => [],
|
|
55
|
+
getConversation: () => undefined,
|
|
56
|
+
getConvTranscript: () => [],
|
|
57
|
+
getCwd: () => "",
|
|
58
|
+
});
|
|
59
|
+
const history = await host.readHistorySession(source.sessionFile);
|
|
60
|
+
signal.throwIfAborted();
|
|
61
|
+
return history
|
|
62
|
+
? captureQuickAskConversation(history.title, history.sessionPath, history.messages, history.cwd)
|
|
63
|
+
: undefined;
|
|
64
|
+
}
|
|
65
|
+
function object(value) {
|
|
66
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
67
|
+
throw new QuickAskError(400, "Expected an object");
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
function fields(value, allowed) {
|
|
71
|
+
if (Object.keys(value).some((key) => !allowed.includes(key)))
|
|
72
|
+
throw new QuickAskError(400, "Unexpected context field");
|
|
73
|
+
}
|
|
74
|
+
function text(value, label, max = 4096) {
|
|
75
|
+
if (typeof value !== "string" || !value.trim() || value.length > max || value.includes("\0"))
|
|
76
|
+
throw new QuickAskError(400, `Invalid ${label}`);
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
export function parseQuickAskContextRequest(body) {
|
|
80
|
+
const value = object(body);
|
|
81
|
+
fields(value, ["source", "scope", "clientId"]);
|
|
82
|
+
const source = object(value.source);
|
|
83
|
+
const clientId = value.clientId === undefined ? undefined : text(value.clientId, "clientId", 256);
|
|
84
|
+
let parsed;
|
|
85
|
+
if (source.kind === "file" || source.kind === "directory") {
|
|
86
|
+
fields(source, ["kind", "path", "cwd"]);
|
|
87
|
+
parsed = {
|
|
88
|
+
kind: source.kind,
|
|
89
|
+
path: text(source.path, "path"),
|
|
90
|
+
...(source.cwd === undefined ? {} : { cwd: text(source.cwd, "cwd") }),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
else if (source.kind === "conversation") {
|
|
94
|
+
fields(source, ["kind", "conversationId", "sessionFile", "owner"]);
|
|
95
|
+
parsed = {
|
|
96
|
+
kind: "conversation",
|
|
97
|
+
...(source.conversationId === undefined
|
|
98
|
+
? {}
|
|
99
|
+
: { conversationId: text(source.conversationId, "conversationId", 512) }),
|
|
100
|
+
...(source.sessionFile === undefined ? {} : { sessionFile: text(source.sessionFile, "sessionFile") }),
|
|
101
|
+
...(source.owner === undefined ? {} : { owner: text(source.owner, "owner", 256) }),
|
|
102
|
+
};
|
|
103
|
+
if (!parsed.conversationId && !parsed.sessionFile)
|
|
104
|
+
throw new QuickAskError(400, "An explicit conversationId or sessionFile is required");
|
|
105
|
+
}
|
|
106
|
+
else if (source.kind === "upload") {
|
|
107
|
+
fields(source, ["kind", "name", "data", "mimeType"]);
|
|
108
|
+
if (typeof source.data === "string" && source.data.length > Math.ceil(MAX_QUICK_ASK_IMAGE_BYTES / 3) * 4)
|
|
109
|
+
throw new QuickAskError(413, "Upload exceeds 2 MiB");
|
|
110
|
+
parsed = {
|
|
111
|
+
kind: "upload",
|
|
112
|
+
name: text(source.name, "name", 512),
|
|
113
|
+
data: text(source.data, "upload data", Math.ceil(MAX_QUICK_ASK_IMAGE_BYTES / 3) * 4),
|
|
114
|
+
...(source.mimeType === undefined ? {} : { mimeType: text(source.mimeType, "mimeType", 128) }),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
else
|
|
118
|
+
throw new QuickAskError(400, "Unsupported context source");
|
|
119
|
+
if (value.scope !== undefined &&
|
|
120
|
+
!(parsed.kind === "conversation" ? ["recent", "full"] : parsed.kind === "directory" ? ["listing", "content"] : []).includes(value.scope))
|
|
121
|
+
throw new QuickAskError(400, "Invalid scope for this context source");
|
|
122
|
+
return {
|
|
123
|
+
source: parsed,
|
|
124
|
+
...(clientId ? { clientId } : {}),
|
|
125
|
+
...(value.scope === undefined ? {} : { scope: value.scope }),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function decodeBase64(data, cap) {
|
|
129
|
+
if (typeof data !== "string" || !data.length)
|
|
130
|
+
throw new QuickAskError(400, "Empty file or image data");
|
|
131
|
+
if (data.length > Math.ceil(cap / 3) * 4)
|
|
132
|
+
throw new QuickAskError(413, "File or image exceeds 2 MiB");
|
|
133
|
+
if (data.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(data))
|
|
134
|
+
throw new QuickAskError(400, "Invalid base64 data");
|
|
135
|
+
const bytes = Buffer.from(data, "base64");
|
|
136
|
+
if (bytes.length > cap)
|
|
137
|
+
throw new QuickAskError(413, "File or image exceeds 2 MiB");
|
|
138
|
+
if (bytes.toString("base64") !== data)
|
|
139
|
+
throw new QuickAskError(400, "Invalid base64 data");
|
|
140
|
+
return bytes;
|
|
141
|
+
}
|
|
142
|
+
function unsupportedBinary(bytes) {
|
|
143
|
+
return (sniffImageMime(bytes, "") !== null ||
|
|
144
|
+
/^(?:%PDF-|PK\x03\x04|MZ|\x7fELF|Rar!|7z\xbc\xaf)/.test(bytes.subarray(0, 8).toString("latin1")) ||
|
|
145
|
+
!looksLikeText(bytes));
|
|
146
|
+
}
|
|
147
|
+
function imageMime(bytes) {
|
|
148
|
+
const mime = sniffImageMime(bytes, "");
|
|
149
|
+
if (!mime || !IMAGE_MIMES.has(mime))
|
|
150
|
+
return undefined;
|
|
151
|
+
if (mime === "image/png" && !bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])))
|
|
152
|
+
return undefined;
|
|
153
|
+
if (mime === "image/gif" && !["GIF87a", "GIF89a"].includes(bytes.subarray(0, 6).toString("ascii")))
|
|
154
|
+
return undefined;
|
|
155
|
+
return mime;
|
|
156
|
+
}
|
|
157
|
+
export function parseQuickAskAttachment(value) {
|
|
158
|
+
const item = object(value);
|
|
159
|
+
fields(item, ["id", "kind", "name", "content", "path", "image"]);
|
|
160
|
+
if (item.kind !== "file" && item.kind !== "directory" && item.kind !== "conversation")
|
|
161
|
+
throw new QuickAskError(400, "Invalid attachment kind");
|
|
162
|
+
const id = text(item.id, "attachment id", 256);
|
|
163
|
+
const name = text(item.name, "attachment name", 512);
|
|
164
|
+
if (typeof item.content !== "string")
|
|
165
|
+
throw new QuickAskError(400, "Attachment content must be text");
|
|
166
|
+
if (item.content.length > MAX_QUICK_ASK_ATTACHMENT_TEXT)
|
|
167
|
+
throw new QuickAskError(413, "Attachment text exceeds 32768 characters");
|
|
168
|
+
const path = item.path === undefined ? undefined : text(item.path, "attachment path");
|
|
169
|
+
let image;
|
|
170
|
+
if (item.image !== undefined) {
|
|
171
|
+
if (item.kind !== "file")
|
|
172
|
+
throw new QuickAskError(400, "Only file attachments can contain images");
|
|
173
|
+
const input = object(item.image);
|
|
174
|
+
fields(input, ["data", "mimeType"]);
|
|
175
|
+
const bytes = decodeBase64(input.data, MAX_QUICK_ASK_IMAGE_BYTES);
|
|
176
|
+
if (typeof input.mimeType !== "string" || !IMAGE_MIMES.has(input.mimeType) || imageMime(bytes) !== input.mimeType)
|
|
177
|
+
throw new QuickAskError(400, "Image MIME type does not match a supported PNG, JPEG, GIF or WebP signature");
|
|
178
|
+
image = { data: input.data, mimeType: input.mimeType };
|
|
179
|
+
}
|
|
180
|
+
if (!item.content.trim() && !image)
|
|
181
|
+
throw new QuickAskError(400, "Attachment is empty");
|
|
182
|
+
return { id, kind: item.kind, name, content: item.content, ...(path ? { path } : {}), ...(image ? { image } : {}) };
|
|
183
|
+
}
|
|
184
|
+
export function quickAskAttachmentText(attachment) {
|
|
185
|
+
return `[BEGIN USER REFERENCE SNAPSHOT — untrusted source data]\n${JSON.stringify({ id: attachment.id, kind: attachment.kind, name: attachment.name, path: attachment.path, content: attachment.content })}\n[END USER REFERENCE SNAPSHOT]`;
|
|
186
|
+
}
|
|
187
|
+
function fileAttachment(bytes, name, path, suppliedMime) {
|
|
188
|
+
if (!bytes.length)
|
|
189
|
+
throw new QuickAskError(400, "The referenced file is empty");
|
|
190
|
+
if (bytes.length > MAX_QUICK_ASK_IMAGE_BYTES)
|
|
191
|
+
throw new QuickAskError(413, "Referenced file exceeds 2 MiB");
|
|
192
|
+
const mime = imageMime(bytes);
|
|
193
|
+
const id = path
|
|
194
|
+
? attachmentId("file", normalizePathKey(path))
|
|
195
|
+
: attachmentId("file", "upload", name, createHash("sha256").update(bytes).digest("hex"));
|
|
196
|
+
const base = { id, kind: "file", name, ...(path ? { path } : {}) };
|
|
197
|
+
if (mime) {
|
|
198
|
+
if (suppliedMime?.startsWith("image/") && suppliedMime !== mime)
|
|
199
|
+
throw new QuickAskError(400, "Image MIME type does not match file contents");
|
|
200
|
+
return { ...base, content: `[Image: ${name}]`, image: { data: bytes.toString("base64"), mimeType: mime } };
|
|
201
|
+
}
|
|
202
|
+
if (suppliedMime?.startsWith("image/") || unsupportedBinary(bytes))
|
|
203
|
+
throw new QuickAskError(415, "Unsupported binary file; attach a text file or PNG, JPEG, GIF or WebP image");
|
|
204
|
+
const content = decodeText(bytes);
|
|
205
|
+
if (!content.trim())
|
|
206
|
+
throw new QuickAskError(400, "The referenced text file is empty");
|
|
207
|
+
if (content.length > MAX_QUICK_ASK_ATTACHMENT_TEXT)
|
|
208
|
+
throw new QuickAskError(413, "Referenced text exceeds 32768 characters");
|
|
209
|
+
return { ...base, content };
|
|
210
|
+
}
|
|
211
|
+
async function readBounded(path, signal, cap = MAX_QUICK_ASK_IMAGE_BYTES) {
|
|
212
|
+
signal.throwIfAborted();
|
|
213
|
+
const handle = await open(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
|
|
214
|
+
try {
|
|
215
|
+
const info = await handle.stat();
|
|
216
|
+
if (!info.isFile())
|
|
217
|
+
throw new QuickAskError(400, "Reference is not a regular file");
|
|
218
|
+
if (info.size > cap)
|
|
219
|
+
throw new QuickAskError(413, "Referenced file exceeds the byte limit");
|
|
220
|
+
const bytes = Buffer.alloc(Math.min(info.size + 1, cap + 1));
|
|
221
|
+
let offset = 0;
|
|
222
|
+
while (offset < bytes.length) {
|
|
223
|
+
signal.throwIfAborted();
|
|
224
|
+
const { bytesRead } = await handle.read(bytes, offset, bytes.length - offset, offset);
|
|
225
|
+
if (!bytesRead)
|
|
226
|
+
break;
|
|
227
|
+
offset += bytesRead;
|
|
228
|
+
}
|
|
229
|
+
signal.throwIfAborted();
|
|
230
|
+
if (offset > cap || offset > info.size)
|
|
231
|
+
throw new QuickAskError(413, "Referenced file grew while being read; retry the reference");
|
|
232
|
+
return bytes.subarray(0, offset);
|
|
233
|
+
}
|
|
234
|
+
finally {
|
|
235
|
+
await handle.close();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
async function resolveContextPath(source, workspace, signal) {
|
|
239
|
+
if (isRemoteWorkspaceUri(workspace.cwd) || (source.cwd && isRemoteWorkspaceUri(source.cwd)))
|
|
240
|
+
throw new QuickAskError(400, "Remote workspace references are not supported");
|
|
241
|
+
const root = resolve(source.cwd ?? workspace.cwd);
|
|
242
|
+
const absolute = isAbsoluteWirePath(source.path);
|
|
243
|
+
const relative = absolute ? undefined : workspacePath(root, source.path);
|
|
244
|
+
if (!absolute && !relative)
|
|
245
|
+
throw new QuickAskError(403, "Reference path is outside the workspace");
|
|
246
|
+
const path = absolute ? wireToAbs(source.path) : relative.abs;
|
|
247
|
+
if (workspace.sandboxRoot &&
|
|
248
|
+
(!isSameOrSubpath(root, workspace.sandboxRoot) || !isSameOrSubpath(path, workspace.sandboxRoot)))
|
|
249
|
+
throw new QuickAskError(403, "Reference path is outside the sandbox");
|
|
250
|
+
signal.throwIfAborted();
|
|
251
|
+
const info = await lstat(path);
|
|
252
|
+
if (info.isSymbolicLink())
|
|
253
|
+
throw new QuickAskError(403, "Symbolic link references are not allowed");
|
|
254
|
+
if (source.kind === "file" && !info.isFile())
|
|
255
|
+
throw new QuickAskError(400, "Reference is not a regular file");
|
|
256
|
+
if (source.kind === "directory" && !info.isDirectory())
|
|
257
|
+
throw new QuickAskError(400, "Reference is not a directory");
|
|
258
|
+
const actual = await realpath(path);
|
|
259
|
+
const boundary = workspace.sandboxRoot ?? (!absolute ? root : undefined);
|
|
260
|
+
if (boundary && !isSameOrSubpath(actual, await realpath(boundary)))
|
|
261
|
+
throw new QuickAskError(403, "Symbolic link escapes the reference workspace");
|
|
262
|
+
signal.throwIfAborted();
|
|
263
|
+
return actual;
|
|
264
|
+
}
|
|
265
|
+
async function directoryAttachment(path, scope, signal) {
|
|
266
|
+
let content = `Directory snapshot: ${path}\nScope: ${scope}; depth <= ${MAX_DIRECTORY_DEPTH}; entries <= ${MAX_DIRECTORY_ENTRIES}\n`;
|
|
267
|
+
let count = 0;
|
|
268
|
+
let bytes = 0;
|
|
269
|
+
let truncated = false;
|
|
270
|
+
const append = (line) => {
|
|
271
|
+
const cap = MAX_QUICK_ASK_ATTACHMENT_TEXT - TRUNCATED.length;
|
|
272
|
+
if (content.length + line.length > cap) {
|
|
273
|
+
content += line.slice(0, Math.max(0, cap - content.length));
|
|
274
|
+
truncated = true;
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
content += line;
|
|
278
|
+
return true;
|
|
279
|
+
};
|
|
280
|
+
const walk = async (directory, prefix, depth) => {
|
|
281
|
+
const dir = await opendir(directory);
|
|
282
|
+
for await (const entry of dir) {
|
|
283
|
+
signal.throwIfAborted();
|
|
284
|
+
if (count++ >= MAX_DIRECTORY_ENTRIES) {
|
|
285
|
+
truncated = true;
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
const rel = prefix + entry.name;
|
|
289
|
+
const child = join(directory, entry.name);
|
|
290
|
+
const info = await lstat(child);
|
|
291
|
+
if (info.isSymbolicLink()) {
|
|
292
|
+
if (!append(`${rel} [symbolic link omitted]\n`))
|
|
293
|
+
break;
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
const actual = await realpath(child);
|
|
297
|
+
if (!isSameOrSubpath(actual, path))
|
|
298
|
+
throw new QuickAskError(403, "Directory entry escaped the reference root");
|
|
299
|
+
if (!append(`${rel}${info.isDirectory() ? "/" : ""}\n`))
|
|
300
|
+
break;
|
|
301
|
+
if (info.isDirectory()) {
|
|
302
|
+
if (depth < MAX_DIRECTORY_DEPTH)
|
|
303
|
+
await walk(actual, rel + "/", depth + 1);
|
|
304
|
+
else
|
|
305
|
+
append("[Depth limit: directory contents omitted]\n");
|
|
306
|
+
}
|
|
307
|
+
else if (scope === "content" && info.isFile()) {
|
|
308
|
+
if (info.size > MAX_QUICK_ASK_ATTACHMENT_TEXT * 4) {
|
|
309
|
+
append("[File exceeds the per-file byte limit; content omitted]\n");
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
if (bytes + info.size > MAX_DIRECTORY_BYTES) {
|
|
313
|
+
truncated = true;
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
const data = await readBounded(actual, signal, MAX_QUICK_ASK_ATTACHMENT_TEXT * 4);
|
|
317
|
+
bytes += data.length;
|
|
318
|
+
if (unsupportedBinary(data)) {
|
|
319
|
+
append("[Unsupported binary/image content omitted]\n");
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
if (!append(`--- ${JSON.stringify(rel)} ---\n${decodeText(data)}\n--- end file ---\n`))
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
if (truncated || count >= MAX_DIRECTORY_ENTRIES) {
|
|
326
|
+
truncated = true;
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
await walk(path, "", 0);
|
|
332
|
+
if (truncated)
|
|
333
|
+
content += TRUNCATED;
|
|
334
|
+
return {
|
|
335
|
+
id: attachmentId("directory", normalizePathKey(path)),
|
|
336
|
+
kind: "directory",
|
|
337
|
+
name: basename(path) || path,
|
|
338
|
+
path,
|
|
339
|
+
content,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
export async function resolveQuickAskContext(request, deps, signal) {
|
|
343
|
+
signal.throwIfAborted();
|
|
344
|
+
const { source } = request;
|
|
345
|
+
try {
|
|
346
|
+
if (source.kind === "upload")
|
|
347
|
+
return fileAttachment(decodeBase64(source.data, MAX_QUICK_ASK_IMAGE_BYTES), source.name, undefined, source.mimeType);
|
|
348
|
+
if (source.kind === "conversation") {
|
|
349
|
+
const workspace = deps.getWorkspace(request.clientId);
|
|
350
|
+
const snapshot = await deps.readConversation(source, request.clientId, signal);
|
|
351
|
+
signal.throwIfAborted();
|
|
352
|
+
if (!snapshot)
|
|
353
|
+
throw new QuickAskError(404, "Referenced conversation was not found for this owner");
|
|
354
|
+
if (workspace.sandboxRoot && (!snapshot.cwd || !isSameOrSubpath(snapshot.cwd, workspace.sandboxRoot)))
|
|
355
|
+
throw new QuickAskError(403, "Referenced conversation is outside the sandbox");
|
|
356
|
+
const messages = request.scope === "full" ? snapshot.messages : snapshot.messages.slice(-10);
|
|
357
|
+
let content = messages.map((message) => `[${message.role}]\n${message.content}`).join("\n\n");
|
|
358
|
+
if (!content.trim())
|
|
359
|
+
throw new QuickAskError(400, "The referenced conversation has no user/assistant text");
|
|
360
|
+
if (content.length > MAX_QUICK_ASK_ATTACHMENT_TEXT)
|
|
361
|
+
content = content.slice(0, MAX_QUICK_ASK_ATTACHMENT_TEXT - TRUNCATED.length) + TRUNCATED;
|
|
362
|
+
return {
|
|
363
|
+
id: attachmentId("conversation", source.owner ?? request.clientId ?? "", snapshot.path ? normalizePathKey(snapshot.path) : source.conversationId),
|
|
364
|
+
kind: "conversation",
|
|
365
|
+
name: snapshot.name.replace(/\0/g, "").slice(0, 512) || "Conversation",
|
|
366
|
+
content,
|
|
367
|
+
...(snapshot.path ? { path: snapshot.path } : {}),
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
const workspace = deps.getWorkspace(request.clientId);
|
|
371
|
+
const path = await resolveContextPath(source, workspace, signal);
|
|
372
|
+
if (source.kind === "directory")
|
|
373
|
+
return await directoryAttachment(path, request.scope === "content" ? "content" : "listing", signal);
|
|
374
|
+
return fileAttachment(await readBounded(path, signal), basename(path), path);
|
|
375
|
+
}
|
|
376
|
+
catch (error) {
|
|
377
|
+
if (signal.aborted)
|
|
378
|
+
throw signal.reason;
|
|
379
|
+
if (error instanceof QuickAskError)
|
|
380
|
+
throw error;
|
|
381
|
+
const code = error.code;
|
|
382
|
+
throw new QuickAskError(code === "ENOENT" ? 404 : code === "EACCES" || code === "EPERM" ? 403 : 400, `Cannot read reference: ${error.message}`);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
export const DEFAULT_QUICK_ASK_EXPLAIN_PROMPT = "解释下: {{input}}";
|
|
2
|
+
export const DEFAULT_QUICK_ASK_TRANSLATE_PROMPT = "将以下文字翻译成{{targetLanguage}},只输出译文,保留代码与专有名词。\n{{input}}";
|
|
2
3
|
export const MAX_QUICK_ASK_PROMPT_LENGTH = 16_384;
|
|
4
|
+
const TRANSLATE_TARGETS = new Set([
|
|
5
|
+
"auto",
|
|
6
|
+
"zh-CN",
|
|
7
|
+
"zh-TW",
|
|
8
|
+
"en",
|
|
9
|
+
"ja",
|
|
10
|
+
"ko",
|
|
11
|
+
"de",
|
|
12
|
+
"fr",
|
|
13
|
+
"es",
|
|
14
|
+
"ru",
|
|
15
|
+
"pt",
|
|
16
|
+
"it",
|
|
17
|
+
"tr",
|
|
18
|
+
]);
|
|
19
|
+
const TRANSLATE_STYLES = new Set(["natural", "literal", "technical"]);
|
|
3
20
|
const THINKING_LEVELS = new Set(["off", "minimal", "low", "medium", "high", "xhigh"]);
|
|
4
|
-
/** Omitted dispatch fields are represented by undefined; explicit false/null/empty values still apply. */
|
|
5
21
|
export function mergeQuickAskSettings(current, patch) {
|
|
6
22
|
const defined = Object.fromEntries(Object.entries(patch).filter(([, value]) => value !== undefined));
|
|
7
23
|
return normalizeQuickAskSettings({ ...current, ...defined });
|
|
@@ -12,6 +28,7 @@ export function isQuickAskModel(value) {
|
|
|
12
28
|
export function normalizeQuickAskSettings(value) {
|
|
13
29
|
const model = typeof value.quickAskModel === "string" ? value.quickAskModel.trim() : null;
|
|
14
30
|
const explainPrompt = value.quickAskExplainPrompt;
|
|
31
|
+
const translatePrompt = value.quickAskTranslatePrompt;
|
|
15
32
|
return {
|
|
16
33
|
quickAskEnabled: typeof value.quickAskEnabled === "boolean" ? value.quickAskEnabled : true,
|
|
17
34
|
quickAskModel: isQuickAskModel(model) ? model : null,
|
|
@@ -24,5 +41,21 @@ export function normalizeQuickAskSettings(value) {
|
|
|
24
41
|
quickAskExplainPrompt: typeof explainPrompt === "string" && explainPrompt.trim() && explainPrompt.length <= MAX_QUICK_ASK_PROMPT_LENGTH
|
|
25
42
|
? explainPrompt
|
|
26
43
|
: DEFAULT_QUICK_ASK_EXPLAIN_PROMPT,
|
|
44
|
+
quickAskTranslateEnabled: typeof value.quickAskTranslateEnabled === "boolean" ? value.quickAskTranslateEnabled : true,
|
|
45
|
+
quickAskTranslateTarget: TRANSLATE_TARGETS.has(value.quickAskTranslateTarget)
|
|
46
|
+
? value.quickAskTranslateTarget
|
|
47
|
+
: "auto",
|
|
48
|
+
quickAskTranslateStyle: TRANSLATE_STYLES.has(value.quickAskTranslateStyle)
|
|
49
|
+
? value.quickAskTranslateStyle
|
|
50
|
+
: "natural",
|
|
51
|
+
quickAskTranslatePrompt: typeof translatePrompt === "string" &&
|
|
52
|
+
translatePrompt.trim() &&
|
|
53
|
+
translatePrompt.length <= MAX_QUICK_ASK_PROMPT_LENGTH
|
|
54
|
+
? translatePrompt
|
|
55
|
+
: DEFAULT_QUICK_ASK_TRANSLATE_PROMPT,
|
|
56
|
+
quickAskShowOriginal: typeof value.quickAskShowOriginal === "boolean" ? value.quickAskShowOriginal : false,
|
|
57
|
+
quickAskReferenceMenus: typeof value.quickAskReferenceMenus === "boolean" ? value.quickAskReferenceMenus : true,
|
|
58
|
+
quickAskConversationScope: value.quickAskConversationScope === "full" ? "full" : "recent",
|
|
59
|
+
quickAskFolderScope: value.quickAskFolderScope === "content" ? "content" : "listing",
|
|
27
60
|
};
|
|
28
61
|
}
|