pi-web-ui 0.116.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 +83 -3
- 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 +163 -36
- 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 +184 -504
- 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 +203 -371
- package/dist/server/agent-service.js +1281 -3030
- 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 +42 -114
- 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 +36 -214
- 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 +38 -92
- 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 +142 -68
- 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 +48 -9
- 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 +27 -11
- package/dist/server/device-center/collab-tool.js +393 -27
- package/dist/server/device-center/connector.js +128 -48
- package/dist/server/device-center/delivery-authority.js +95 -0
- package/dist/server/device-center/delivery-subject.js +29 -0
- 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 +452 -208
- 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 +15 -6
- 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 +46 -31
- 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 +13 -15
- package/dist/server/device-center/hub-deliveries.js +119 -15
- package/dist/server/device-center/hub-integration.js +647 -334
- 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 +28 -9
- package/dist/server/device-center/hub-setup.js +23 -7
- package/dist/server/device-center/hub-transaction-log.js +175 -0
- 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 +946 -404
- 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 +111 -0
- package/dist/server/device-center/local-hub.js +6 -4
- package/dist/server/device-center/local-publication.js +416 -0
- package/dist/server/device-center/local-verification-job.js +95 -0
- package/dist/server/device-center/local-verification.js +273 -0
- package/dist/server/device-center/local.js +341 -18
- package/dist/server/device-center/main.js +18 -2
- 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 +52 -46
- package/dist/server/device-center/path-portal.js +42 -12
- package/dist/server/device-center/publication-journal.js +305 -0
- package/dist/server/device-center/publish-intent.js +374 -0
- package/dist/server/device-center/relay.js +217 -52
- package/dist/server/device-center/report-upload.js +0 -1
- package/dist/server/device-center/runtime.js +419 -52
- package/dist/server/device-center/store.js +223 -65
- 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 +68 -0
- 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 +569 -227
- 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 +335 -0
- package/dist/server/device-center/task-state.js +0 -12
- package/dist/server/device-center/task-workspace.js +393 -0
- 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 +9 -0
- package/dist/server/device-center/work-contract.js +923 -0
- 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 +202 -29
- package/dist/server/dispatch-plugin-handlers.js +2 -19
- package/dist/server/dsh/dsh-agent-service.js +78 -601
- 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 +199 -677
- 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 +6 -45
- package/dist/server/patch-remote-catalog.js +4 -34
- 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 +24 -61
- package/dist/server/preset-plugin-dependencies.js +0 -2
- package/dist/server/preset-share.js +4 -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 +61 -0
- package/dist/server/quick-ask.js +260 -0
- 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 +55 -31
- 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 +32 -56
- 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 +215 -0
- package/dist/server/session-open.js +69 -0
- package/dist/server/session-parser.js +4 -54
- package/dist/server/session-scan.js +81 -45
- package/dist/server/session-search.js +0 -56
- package/dist/server/settings-service.js +19 -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 +3 -40
- 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 +55 -0
- 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 +98 -194
- 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 +30 -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 +373 -0
- 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 +55 -6
- package/docs/device-center.md +57 -23
- 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 +9 -6
- package/plugin-sdk/README.md +22 -8
- package/plugin-sdk/client-utils.mjs +0 -7
- package/plugin-sdk/client.d.ts +26 -0
- package/plugin-sdk/client.mjs +52 -0
- package/plugin-sdk/import-check.mjs +4 -51
- package/plugin-sdk/index.d.ts +128 -117
- package/plugin-sdk/index.mjs +2 -687
- package/plugin-sdk/package.json +15 -4
- package/plugin-sdk/ssh-host-trust.mjs +0 -12
- package/plugin-sdk/testing.d.ts +9 -0
- package/plugin-sdk/testing.mjs +511 -0
- 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 +160 -0
- package/themes/flow-ink.css +160 -0
- package/themes/flow-light.css +1 -10
- package/themes/flow-obsidian.css +160 -0
- package/themes/flow-zurich.css +160 -0
- 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-BDoOpj-F.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-C4LIhshN.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-c6d0TJoh.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-BmMrrgB9.js → PiSetupModal-DZKY5Wiw.js} +1 -1
- package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +1 -0
- package/web/dist/assets/SCMPanel-CuEgzAlO.js +2 -0
- 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-CfYSMEZg.js → remote-ssh-client-Cdf-cTUe.js} +1 -1
- package/web/dist/assets/theme-DGL7hLUs.js +1 -0
- package/web/dist/index.html +12 -11
- package/web/dist/sw.js +15 -61
- package/web/public/sw.js +14 -60
- package/dist/gh-comment-781.md +0 -5
- package/dist/server/device-center/local-page.js +0 -17
- package/dist/server/device-center/smoke-preview.js +0 -3
- package/dist/server/durable/durable-capabilities.js +0 -11
- package/dist/server/markers/builtins/services.js +0 -123
- package/dist/server/markers/builtins/todo.js +0 -189
- package/dist/server/markers-list-tool.js +0 -34
- package/dist/server/orchestrator.js +0 -109
- package/dist/server/patch-turn-end-boundary.js +0 -77
- package/dist/server/system-prompt-soul.js +0 -41
- package/dist/server/univer-service.js +0 -448
- package/dist/server/universal/drivers/dsh-driver.js +0 -379
- package/dist/test-artifact.md +0 -9
- package/dist/test-preview-modal.md +0 -11
- package/dist/test-report.html +0 -20
- package/web/dist/assets/BgTasksModal-C0i3O1FT.js +0 -1
- package/web/dist/assets/CanvasStudio-B8thymBN.js +0 -1579
- package/web/dist/assets/CanvasStudio-zSxyIx1R.js +0 -1579
- package/web/dist/assets/DeviceCenter-DfAHKcid.js +0 -3
- package/web/dist/assets/DeviceCenter-ydvOTlzE.js +0 -3
- package/web/dist/assets/DeviceExecutionSettings-q5Ik8oXg.js +0 -1
- package/web/dist/assets/DeviceGroups-CI14_SRb.js +0 -1
- package/web/dist/assets/DeviceGroups-DvsB5IEU.js +0 -1
- package/web/dist/assets/FilePreview-BgGongmv.js +0 -2
- package/web/dist/assets/FilePreview-D4NrhF-U.js +0 -2
- package/web/dist/assets/GlobalSearchModal-BWgU8yPd.js +0 -1
- package/web/dist/assets/GlobalSearchModal-F7fNimKk.js +0 -1
- package/web/dist/assets/GroupConversation-Dh71Pdb-.js +0 -17
- package/web/dist/assets/GroupConversation-ZK3nRmNm.js +0 -17
- package/web/dist/assets/ModelConfigModal-YVEgyy34.js +0 -2
- package/web/dist/assets/ModelConfigModal-vWtg3srp.js +0 -2
- package/web/dist/assets/ProviderOAuthControls-BGSBIKD7.js +0 -1
- package/web/dist/assets/SCMPanel-B8_EDxNr.js +0 -2
- package/web/dist/assets/SCMPanel-BU58qk3T.js +0 -2
- package/web/dist/assets/SettingsModal-CMUybq3J.js +0 -32
- package/web/dist/assets/SettingsModal-OBmGTh-5.js +0 -32
- package/web/dist/assets/TerminalPanel-0CYvD72B.js +0 -3
- package/web/dist/assets/TerminalPanel-DDavKvFr.js +0 -3
- package/web/dist/assets/TuiOverlayModal-BsA-QTvN.js +0 -1
- package/web/dist/assets/TuiOverlayModal-DzoVQBuG.js +0 -1
- package/web/dist/assets/app-globals-CZxzGvIo.js +0 -123
- package/web/dist/assets/canvas-client-CUnXlQYX.js +0 -1
- package/web/dist/assets/desktop-aAKpvKJV.js +0 -1
- package/web/dist/assets/index-C6DwztqE.css +0 -1
- package/web/dist/assets/index-CuN802Sj.js +0 -93
- package/web/dist/assets/index-EH5Fw9fa.js +0 -93
- package/web/dist/assets/plugin-host-BRWib9DF.js +0 -1
- package/web/dist/assets/theme-D2l_mLNo.js +0 -1
|
@@ -1,28 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP 工具桥 —— 把外部 Model Context Protocol(stdio)服务器暴露的工具接入
|
|
3
|
-
* pi 会话,让 AI 能调用真实的第三方工具(文件、数据库、GitHub…)。
|
|
4
|
-
*
|
|
5
|
-
* 约定(MCP 规范流式子集):
|
|
6
|
-
* - stdio 传输 = stdin/stdout 上换行分隔的 JSON-RPC 2.0(NDJSON),不依赖任何
|
|
7
|
-
* 第三方包;stderr 是自由日志通道。
|
|
8
|
-
* - 握手:initialize(带 protocolVersion)→ notifications/initialized →
|
|
9
|
-
* tools/list → tools/call。
|
|
10
|
-
* - 工具工具入会:本模块把每个远端工具适配成 PluginAgentTool,经
|
|
11
|
-
* pluginToolsProvider 走与插件工具完全相同的 customTools 管线。
|
|
12
|
-
*
|
|
13
|
-
* 配置:<PI_WEB_DATA_DIR>/mcp.json,形如
|
|
14
|
-
* { "servers": { "gitserv": { "command": "node", "args": ["mcp.js"], "cwd": "/x" } } }
|
|
15
|
-
*/
|
|
16
1
|
import { spawn } from "node:child_process";
|
|
17
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
18
3
|
import { homedir } from "node:os";
|
|
19
4
|
import { join } from "node:path";
|
|
20
5
|
import { getMcpAccessToken, refreshMcpAccessToken } from "./mcp-oauth.js";
|
|
21
|
-
/** 展开字符串中的 ${VAR_NAME} 环境变量占位符。 */
|
|
22
6
|
export function expandEnvVars(val) {
|
|
23
7
|
return val.replace(/\$\{([^}]+)\}/g, (_, k) => process.env[k] ?? "");
|
|
24
8
|
}
|
|
25
|
-
/** 获取全局 MCP 配置文件路径 */
|
|
26
9
|
export function getGlobalMcpPath(agentDir, dataDir) {
|
|
27
10
|
if (agentDir) {
|
|
28
11
|
const agentPath = join(agentDir, "mcp.json");
|
|
@@ -46,27 +29,14 @@ export function getGlobalMcpPath(agentDir, dataDir) {
|
|
|
46
29
|
const defaultAgentDir = join(homedir(), ".pi", "agent");
|
|
47
30
|
return join(defaultAgentDir, "mcp.json");
|
|
48
31
|
}
|
|
49
|
-
/** 获取项目级 MCP 配置文件路径 */
|
|
50
32
|
export function getProjectMcpPath(cwd) {
|
|
51
33
|
const activeCwd = cwd || process.cwd();
|
|
52
34
|
return join(activeCwd, ".pi", "mcp.json");
|
|
53
35
|
}
|
|
54
|
-
const PROTOCOL_VERSION = "2025-03-26";
|
|
55
|
-
/** 单行(一条 JSON-RPC 消息)的长度上限(1MB):失控服务器一行永不换行会顶爆内存。 */
|
|
36
|
+
const PROTOCOL_VERSION = "2025-03-26";
|
|
56
37
|
const MCP_MAX_LINE_CHARS = 1024 * 1024;
|
|
57
|
-
/** 未换行数据的总缓冲上限(4MB):服务器只吐垃圾不吐换行时按协议错误杀进程。
|
|
58
|
-
* 上限按 JS 字符串长度计(UTF-16 码元 ≤ UTF-8 字节),内存放大有界。 */
|
|
59
38
|
const MCP_MAX_BUFFER_CHARS = 4 * 1024 * 1024;
|
|
60
39
|
let rpcSeq = 0;
|
|
61
|
-
/**
|
|
62
|
-
* 单个 MCP 服务器的客户端:管理子进程或 HTTP 传输、请求/响应按 id 关联、握手与工具调用。
|
|
63
|
-
* 传输支持:
|
|
64
|
-
* - stdio:通过 child_process.spawn 与 NDJSON 交互
|
|
65
|
-
* - streamable-http / http:通过原生 fetch 发送 JSON-RPC POST 请求,支持 Mcp-Session-Id 与 SSE 流式响应
|
|
66
|
-
* 线程模型:无需并发控制(MCP 允许乱序 + 我们按请求 id 匹配响应)。
|
|
67
|
-
* 自愈:子进程意外退出(崩溃/被杀)或 HTTP 会话失效后不永久失效 —— 下一次工具调用会惰性重启并
|
|
68
|
-
* 重新握手、重新拉取工具列表;显式 close() 之后才永久停用。
|
|
69
|
-
*/
|
|
70
40
|
export class McpClient {
|
|
71
41
|
spec;
|
|
72
42
|
clientOpts;
|
|
@@ -75,26 +45,15 @@ export class McpClient {
|
|
|
75
45
|
pending = new Map();
|
|
76
46
|
log;
|
|
77
47
|
name;
|
|
78
|
-
/** 已握手的工具列表(tools/list 结果缓存)。 */
|
|
79
48
|
tools = [];
|
|
80
49
|
shuttingDown = false;
|
|
81
|
-
/** 进行中的启动/重启(并发调用共享同一次重连)。 */
|
|
82
50
|
starting = null;
|
|
83
|
-
/** 已启动次数(含自愈重启;诊断/测试用)。 */
|
|
84
51
|
startedCount = 0;
|
|
85
|
-
/** HTTP 会话 ID(服务端返回 Mcp-Session-Id 时记录)。 */
|
|
86
52
|
sessionId = null;
|
|
87
|
-
/** 是否已成功握手(HTTP 模式无 child,以 initialized 标志为准)。 */
|
|
88
53
|
initialized = false;
|
|
89
|
-
/** 工具列表动态更新回调(收到 notifications/tools/list_changed 时触发)。 */
|
|
90
54
|
onToolsChanged;
|
|
91
|
-
/** HTTP notifications have no pending RPC response, but still belong to this client. */
|
|
92
55
|
notificationControllers = new Set();
|
|
93
|
-
constructor(name,
|
|
94
|
-
/** 启动规格;热加载按它判断「这个服务器要不要重启」(见 McpBridge.reload)。 */
|
|
95
|
-
spec, log,
|
|
96
|
-
/** OAuth:`agentDir` 指向 pi 的凭据库(`mcp-auth.json`),见 mcp-oauth.ts 与 Issue #786。 */
|
|
97
|
-
clientOpts = {}) {
|
|
56
|
+
constructor(name, spec, log, clientOpts = {}) {
|
|
98
57
|
this.spec = spec;
|
|
99
58
|
this.clientOpts = clientOpts;
|
|
100
59
|
this.name = name;
|
|
@@ -103,15 +62,10 @@ export class McpClient {
|
|
|
103
62
|
get isHttp() {
|
|
104
63
|
return !this.spec.command && !!this.spec.url;
|
|
105
64
|
}
|
|
106
|
-
/** 显式配置了 Authorization 头 → 用配置的静态凭据,不碰 OAuth 凭据库。 */
|
|
107
65
|
hasStaticAuthorization() {
|
|
108
66
|
const headers = this.spec.headers ?? {};
|
|
109
67
|
return Object.keys(headers).some((k) => k.toLowerCase() === "authorization");
|
|
110
68
|
}
|
|
111
|
-
/**
|
|
112
|
-
* 该服务器要发的 `Authorization` 值(OAuth 保护的远端服务器用),没有凭据时返回 null。
|
|
113
|
-
* `isRetry` = 上一次请求收到 401:强制刷新一次(凭据库里的 access token 可能没过期但已被吊销)。
|
|
114
|
-
*/
|
|
115
69
|
async resolveAuthHeader(isRetry, signal, staleToken) {
|
|
116
70
|
if (!this.isHttp || !this.spec.url || this.hasStaticAuthorization())
|
|
117
71
|
return null;
|
|
@@ -126,16 +80,13 @@ export class McpClient {
|
|
|
126
80
|
}
|
|
127
81
|
catch (err) {
|
|
128
82
|
signal?.throwIfAborted();
|
|
129
|
-
// 刷新失败不该让请求烂在这里:照旧发出去,由服务端的 401 给出最终结论(或失败原因)。
|
|
130
83
|
this.log(`[mcp:${this.name}] oauth:`, err instanceof Error ? err.message : err);
|
|
131
84
|
return null;
|
|
132
85
|
}
|
|
133
86
|
}
|
|
134
|
-
/** 401 的可操作错误:告诉用户这一台服务器需要登录,以及怎么登录。 */
|
|
135
87
|
signInRequiredError(detail) {
|
|
136
88
|
return new Error(`MCP_OAUTH_SIGN_IN_REQUIRED: HTTP 401: ${detail || "unauthorized"} — OAuth sign-in is missing or has expired; run \`pi mcp login ${this.name}\` and try again`);
|
|
137
89
|
}
|
|
138
|
-
/** 启动子进程或 HTTP 连接 + 握手 + 拉取工具列表。可安全重入:退出后再次调用即全新启动。 */
|
|
139
90
|
async start(timeoutMs = 8000) {
|
|
140
91
|
if (this.isHttp) {
|
|
141
92
|
if (this.initialized)
|
|
@@ -167,7 +118,6 @@ export class McpClient {
|
|
|
167
118
|
windowsHide: true,
|
|
168
119
|
});
|
|
169
120
|
this.child = child;
|
|
170
|
-
// 进程退出后向 stdin 写请求会触发 EPIPE —— 静默忽略(send 也会判 child 存活)。
|
|
171
121
|
child.stdin?.on("error", () => { });
|
|
172
122
|
child.stderr.on("data", (d) => this.log(`[mcp:${this.name}] stderr:`, d.toString().trimEnd()));
|
|
173
123
|
child.on("error", (err) => this.rejectAll(new Error(`[mcp:${this.name}] spawn error: ${err.message}`)));
|
|
@@ -183,40 +133,31 @@ export class McpClient {
|
|
|
183
133
|
child.stdout.on("data", (chunk) => this.onData(chunk));
|
|
184
134
|
this.startedCount++;
|
|
185
135
|
try {
|
|
186
|
-
// 握手
|
|
187
136
|
const handshake = await this.request("initialize", {
|
|
188
137
|
protocolVersion: this.spec.protocolVersion ?? PROTOCOL_VERSION,
|
|
189
138
|
capabilities: {},
|
|
190
139
|
clientInfo: { name: "pi-web-ui", version: "0.41.0" },
|
|
191
140
|
}, timeoutMs);
|
|
192
141
|
const version = handshake?.protocolVersion ?? this.spec.protocolVersion ?? PROTOCOL_VERSION;
|
|
193
|
-
// 通知 initialized(无 id 的 notification)
|
|
194
142
|
this.send({ jsonrpc: "2.0", method: "notifications/initialized" });
|
|
195
|
-
// 仍以协商协议版本调用 tools(多数服务器对新版本容忍,这里用协商结果)
|
|
196
143
|
void version;
|
|
197
144
|
const listed = ((await this.request("tools/list", {}, timeoutMs)) ?? {});
|
|
198
145
|
this.tools = Array.isArray(listed.tools) ? listed.tools : [];
|
|
199
146
|
this.log(`[mcp:${this.name}] ready, ${this.tools.length} tools`);
|
|
200
|
-
// 若重启过程中被显式 close(),趁机回收刚启动的子进程,不留孤儿。
|
|
201
147
|
if (this.shuttingDown) {
|
|
202
148
|
try {
|
|
203
149
|
child.kill();
|
|
204
150
|
}
|
|
205
|
-
catch {
|
|
206
|
-
/* 已退出 */
|
|
207
|
-
}
|
|
151
|
+
catch { }
|
|
208
152
|
if (this.child === child)
|
|
209
153
|
this.child = null;
|
|
210
154
|
}
|
|
211
155
|
}
|
|
212
156
|
catch (err) {
|
|
213
|
-
// 启动/握手失败:回收本次子进程,避免泄漏;调用方可安全重试(自愈会再试)。
|
|
214
157
|
try {
|
|
215
158
|
child.kill();
|
|
216
159
|
}
|
|
217
|
-
catch {
|
|
218
|
-
/* 已退出 */
|
|
219
|
-
}
|
|
160
|
+
catch { }
|
|
220
161
|
if (this.child === child)
|
|
221
162
|
this.child = null;
|
|
222
163
|
throw err;
|
|
@@ -238,7 +179,6 @@ export class McpClient {
|
|
|
238
179
|
}, timeoutMs);
|
|
239
180
|
const version = handshake?.protocolVersion ?? this.spec.protocolVersion ?? PROTOCOL_VERSION;
|
|
240
181
|
void version;
|
|
241
|
-
// 通知 initialized(无 id 的 notification)
|
|
242
182
|
await this.sendHttpNotification("notifications/initialized", {});
|
|
243
183
|
const listed = ((await this.requestHttp("tools/list", {}, timeoutMs)) ?? {});
|
|
244
184
|
this.tools = Array.isArray(listed?.tools) ? listed.tools : [];
|
|
@@ -251,14 +191,9 @@ export class McpClient {
|
|
|
251
191
|
throw err;
|
|
252
192
|
}
|
|
253
193
|
}
|
|
254
|
-
/** 已启动次数(含自愈重启;诊断/测试用)。 */
|
|
255
194
|
get startCount() {
|
|
256
195
|
return this.startedCount;
|
|
257
196
|
}
|
|
258
|
-
/**
|
|
259
|
-
* 保活:连接存活就直接返回;已意外退出则惰性重启(并发调用共享同一次重连)。
|
|
260
|
-
* 显式 close() 后抛错,绝不复活。
|
|
261
|
-
*/
|
|
262
197
|
async ensureStarted(timeoutMs) {
|
|
263
198
|
if (this.shuttingDown)
|
|
264
199
|
throw new Error(`[mcp:${this.name}] 客户端已关闭,不会重启`);
|
|
@@ -277,13 +212,9 @@ export class McpClient {
|
|
|
277
212
|
});
|
|
278
213
|
await this.starting;
|
|
279
214
|
}
|
|
280
|
-
/** 已发现工具。 */
|
|
281
215
|
getTools() {
|
|
282
216
|
return this.tools.map((t) => ({ ...t }));
|
|
283
217
|
}
|
|
284
|
-
/**
|
|
285
|
-
* 刷新工具列表(收到 notifications/tools/list_changed 或手动刷新用)。
|
|
286
|
-
*/
|
|
287
218
|
async refreshTools(timeoutMs = 8000) {
|
|
288
219
|
const listed = ((await this.request("tools/list", {}, timeoutMs)) ?? {});
|
|
289
220
|
this.tools = Array.isArray(listed.tools) ? listed.tools : [];
|
|
@@ -291,17 +222,11 @@ export class McpClient {
|
|
|
291
222
|
this.onToolsChanged?.();
|
|
292
223
|
return this.tools;
|
|
293
224
|
}
|
|
294
|
-
/**
|
|
295
|
-
* 调用一个工具,返回其结果。
|
|
296
|
-
* 纯文本块拼接成字符串(向后兼容);出现非文本块(image/resource/audio 等)时按序透传或退化提示,不再静默丢弃。
|
|
297
|
-
* 超时遵循 spec.timeout(秒,默认 60s),收到 progress 通知会自动重置超时计时器。
|
|
298
|
-
*/
|
|
299
225
|
async call(name, args, timeoutMs, signal) {
|
|
300
226
|
if (this.shuttingDown)
|
|
301
227
|
throw new Error(`[mcp:${this.name}] 客户端已关闭,不会重启`);
|
|
302
228
|
const effectiveTimeoutMs = timeoutMs ?? (this.spec.timeout && this.spec.timeout > 0 ? this.spec.timeout * 1000 : 60000);
|
|
303
229
|
try {
|
|
304
|
-
// 自愈:已断开或退出(非主动关闭)→ 先惰性重启/重新握手;失败给出明确错误。
|
|
305
230
|
await this.ensureStarted(8000);
|
|
306
231
|
}
|
|
307
232
|
catch (err) {
|
|
@@ -312,7 +237,6 @@ export class McpClient {
|
|
|
312
237
|
return await this.executeCall(name, args, effectiveTimeoutMs, signal);
|
|
313
238
|
}
|
|
314
239
|
catch (err) {
|
|
315
|
-
// HTTP 模式下的会话失效自愈:若远端提示会话过期,重新握手并重试一次
|
|
316
240
|
if (this.isHttp && err instanceof Error && err.message.includes("MCP_SESSION_EXPIRED")) {
|
|
317
241
|
this.log(`[mcp:${this.name}] 会话已失效,重新握手重试调用...`);
|
|
318
242
|
this.sessionId = null;
|
|
@@ -332,30 +256,22 @@ export class McpClient {
|
|
|
332
256
|
.trim() || "MCP 工具错误";
|
|
333
257
|
throw new Error(msg);
|
|
334
258
|
}
|
|
335
|
-
// 结构化结果优先,其次内容块。
|
|
336
259
|
if (res?.structuredContent !== undefined)
|
|
337
260
|
return res.structuredContent;
|
|
338
261
|
const blocks = [];
|
|
339
262
|
let hasNonText = false;
|
|
340
263
|
for (const c of res.content ?? []) {
|
|
341
264
|
if (c.type === "image" && typeof c.data === "string" && c.data) {
|
|
342
|
-
// MCP image 块字段(type/data/mimeType)与 SDK 的 ImageContent 完全一致,原样透传;
|
|
343
|
-
// 超大图由 SDK 的 normalizeToolResultImages 统一缩放(afterToolCall 钩子,默认 autoResize)。
|
|
344
265
|
blocks.push({ type: "image", data: c.data, mimeType: c.mimeType?.trim() || "image/png" });
|
|
345
266
|
hasNonText = true;
|
|
346
267
|
continue;
|
|
347
268
|
}
|
|
348
269
|
if (c.type && c.type !== "text") {
|
|
349
270
|
const r = typeof c.resource === "object" && c.resource !== null ? c.resource : {};
|
|
350
|
-
// MCP 的 EmbeddedResource 有两种承载:TextResourceContents(resource.text)与
|
|
351
|
-
// BlobResourceContents(resource.blob)。文本型带真实正文(filesystem 类 MCP 的
|
|
352
|
-
// read_text_file 就走这条),当文本透传 —— 退化成「已跳过」等于把文件内容吞掉。
|
|
353
271
|
if (typeof r.text === "string" && r.text) {
|
|
354
272
|
blocks.push({ type: "text", text: r.text });
|
|
355
273
|
continue;
|
|
356
274
|
}
|
|
357
|
-
// resource(blob)/audio 等块在 SDK 内容联合里没有载体(只有 text|image|thinking|toolCall),
|
|
358
|
-
// 退化为文本提示,让模型至少知道工具返回了什么,而不是看到一个空串。
|
|
359
275
|
const mime = (c.mimeType ?? r.mimeType ?? "").trim();
|
|
360
276
|
const blob = typeof r.blob === "string" && r.blob ? r.blob : c.data;
|
|
361
277
|
const size = typeof blob === "string" && blob ? `,约 ${Math.max(1, Math.round((blob.length * 3) / 4))} 字节` : "";
|
|
@@ -371,12 +287,10 @@ export class McpClient {
|
|
|
371
287
|
blocks.push({ type: "text", text });
|
|
372
288
|
}
|
|
373
289
|
if (!hasNonText) {
|
|
374
|
-
// 纯文本结果保持旧形状(拼接字符串),不破坏既有调用方。
|
|
375
290
|
return { content: blocks.map((b) => (b.type === "text" ? b.text : "")).join("\n"), isError: !!res.isError };
|
|
376
291
|
}
|
|
377
292
|
return { content: blocks, isError: !!res.isError };
|
|
378
293
|
}
|
|
379
|
-
/** 关闭:kill 子进程或注销 HTTP 会话,拒绝所有在途请求。 */
|
|
380
294
|
close() {
|
|
381
295
|
this.shuttingDown = true;
|
|
382
296
|
this.initialized = false;
|
|
@@ -387,9 +301,7 @@ export class McpClient {
|
|
|
387
301
|
try {
|
|
388
302
|
this.child.kill();
|
|
389
303
|
}
|
|
390
|
-
catch {
|
|
391
|
-
/* 已退出 */
|
|
392
|
-
}
|
|
304
|
+
catch { }
|
|
393
305
|
this.child = null;
|
|
394
306
|
}
|
|
395
307
|
if (this.isHttp && this.sessionId && this.spec.url) {
|
|
@@ -402,7 +314,6 @@ export class McpClient {
|
|
|
402
314
|
}).catch(() => { });
|
|
403
315
|
}
|
|
404
316
|
}
|
|
405
|
-
// -- 内部 -------------------------------------------------------------
|
|
406
317
|
send(msg) {
|
|
407
318
|
const stdin = this.child?.stdin;
|
|
408
319
|
if (!stdin || !stdin.writable)
|
|
@@ -513,7 +424,6 @@ export class McpClient {
|
|
|
513
424
|
progressToken: outId,
|
|
514
425
|
abortController,
|
|
515
426
|
});
|
|
516
|
-
// Return the result promise immediately: timeout/close must settle even during auth.
|
|
517
427
|
void (async () => {
|
|
518
428
|
try {
|
|
519
429
|
const authHeader = await this.resolveAuthHeader(false, abortController.signal);
|
|
@@ -528,7 +438,6 @@ export class McpClient {
|
|
|
528
438
|
signal: abortController.signal,
|
|
529
439
|
});
|
|
530
440
|
abortController.signal.throwIfAborted();
|
|
531
|
-
// 401 → 凭据库里的 token 可能已被吊销/轮换:强制刷新一次再重试同一请求(OAuth 保护的服务器)。
|
|
532
441
|
if (res.status === 401 && !this.hasStaticAuthorization()) {
|
|
533
442
|
const retriedHeader = await this.resolveAuthHeader(true, abortController.signal, authHeader?.slice("Bearer ".length));
|
|
534
443
|
abortController.signal.throwIfAborted();
|
|
@@ -722,8 +631,6 @@ export class McpClient {
|
|
|
722
631
|
}
|
|
723
632
|
onData(chunk) {
|
|
724
633
|
this.buffer += chunk;
|
|
725
|
-
// 总缓冲上限:服务器一直输出却不换行(或极慢地换行)时,缓冲会无限涨,
|
|
726
|
-
// 宿主内存被一个失控子进程吃光。超限按协议错误处理:杀进程 + 拒绝在途请求。
|
|
727
634
|
if (this.buffer.length > MCP_MAX_BUFFER_CHARS) {
|
|
728
635
|
this.killForProtocolError(new Error(`[mcp:${this.name}] stdout 缓冲超过 ${Math.round(MCP_MAX_BUFFER_CHARS / 1024 / 1024)}MB 上限,按协议错误关闭`));
|
|
729
636
|
return;
|
|
@@ -749,9 +656,6 @@ export class McpClient {
|
|
|
749
656
|
this.handleMessage(msg);
|
|
750
657
|
}
|
|
751
658
|
}
|
|
752
|
-
/** 协议错误(stdout 缓冲超限):杀掉子进程、拒绝全部在途请求、清空缓冲。
|
|
753
|
-
* 与进程自然退出共用自愈语义 —— 下一次工具调用会重新拉起并重新握手
|
|
754
|
-
* (失控服务器重启后再次超限就再次杀,不会永久占用宿主内存)。 */
|
|
755
659
|
killForProtocolError(err) {
|
|
756
660
|
this.log(err.message);
|
|
757
661
|
this.buffer = "";
|
|
@@ -762,9 +666,7 @@ export class McpClient {
|
|
|
762
666
|
try {
|
|
763
667
|
child.kill();
|
|
764
668
|
}
|
|
765
|
-
catch {
|
|
766
|
-
/* 已退出 */
|
|
767
|
-
}
|
|
669
|
+
catch { }
|
|
768
670
|
}
|
|
769
671
|
}
|
|
770
672
|
handleProgress(params) {
|
|
@@ -800,7 +702,6 @@ export class McpClient {
|
|
|
800
702
|
pending.resolve(msg.result);
|
|
801
703
|
return;
|
|
802
704
|
}
|
|
803
|
-
// 服务端主动通知(progress / tools/list_changed / message 等)
|
|
804
705
|
if (msg.method === "notifications/progress") {
|
|
805
706
|
this.handleProgress(msg.params);
|
|
806
707
|
return;
|
|
@@ -826,11 +727,6 @@ export class McpClient {
|
|
|
826
727
|
this.pending.clear();
|
|
827
728
|
}
|
|
828
729
|
}
|
|
829
|
-
/**
|
|
830
|
-
* 解析 <dataDir>/mcp.json 的文本 → 规范化服务器清单。
|
|
831
|
-
* `null` = 不是合法 JSON 对象(**与「没有服务器」区分开**:热加载遇到坏配置要保留在跑的
|
|
832
|
-
* 服务器,而 `{ "servers": {} }` 或删掉文件是「确实没有服务器」的明确意图)。
|
|
833
|
-
*/
|
|
834
730
|
export function parseMcpConfig(text) {
|
|
835
731
|
let parsed;
|
|
836
732
|
try {
|
|
@@ -869,7 +765,6 @@ export function parseMcpConfig(text) {
|
|
|
869
765
|
}
|
|
870
766
|
return { servers };
|
|
871
767
|
}
|
|
872
|
-
/** 读取 <dataDir>/mcp.json 里的服务器清单(尽力而为)。 */
|
|
873
768
|
export function readMcpConfig(dataDir) {
|
|
874
769
|
try {
|
|
875
770
|
return parseMcpConfig(readFileSync(join(dataDir, "mcp.json"), "utf8")) ?? { servers: {} };
|
|
@@ -878,11 +773,6 @@ export function readMcpConfig(dataDir) {
|
|
|
878
773
|
return { servers: {} };
|
|
879
774
|
}
|
|
880
775
|
}
|
|
881
|
-
/**
|
|
882
|
-
* 服务器的规范化快照:只保留影响行为的字段,env 键序无关。
|
|
883
|
-
* 热加载的「配置变了吗」与「这个服务器要不要重启」都按它比较 —— 改缩进、重排键名、加尾随
|
|
884
|
-
* 换行都不算变更,不该重启任何子进程。
|
|
885
|
-
*/
|
|
886
776
|
export function mcpServerSnapshot(spec) {
|
|
887
777
|
const env = {};
|
|
888
778
|
for (const k of Object.keys(spec.env ?? {}).sort())
|
|
@@ -904,16 +794,10 @@ export function mcpServerSnapshot(spec) {
|
|
|
904
794
|
protocolVersion: spec.protocolVersion ?? null,
|
|
905
795
|
};
|
|
906
796
|
}
|
|
907
|
-
/** 两个规格是否等价(等价 = 该服务器的子进程不必重启)。 */
|
|
908
797
|
function sameMcpSpec(a, b) {
|
|
909
798
|
return JSON.stringify(mcpServerSnapshot(a)) === JSON.stringify(mcpServerSnapshot(b));
|
|
910
799
|
}
|
|
911
|
-
/**
|
|
912
|
-
* 整个 MCP 管理器的工具适配:把每个 MCP 工具变成 PluginAgentTool。
|
|
913
|
-
* getAllToolsTool(name, callFn) 生成 execute → 转发到对应 McpClient.call。
|
|
914
|
-
*/
|
|
915
800
|
const mcpToolServers = new WeakMap();
|
|
916
|
-
/** Trusted provenance keyed by the bridge-owned tool object, never by its label. */
|
|
917
801
|
export function getMcpToolServer(tool) {
|
|
918
802
|
return mcpToolServers.get(tool);
|
|
919
803
|
}
|
|
@@ -923,9 +807,6 @@ function adaptMcpTool(serverName, mcpTool, client) {
|
|
|
923
807
|
name,
|
|
924
808
|
label: `${serverName} · ${mcpTool.name}`,
|
|
925
809
|
description: mcpTool.description ?? `Tool ${mcpTool.name} provided by MCP server "${serverName}"`,
|
|
926
|
-
// 无 snippet 的工具不会进系统提示词的「Available tools」清单(SDK 只列有
|
|
927
|
-
// snippet 的工具),MCP 工具会变成 schema-only:模型读清单以为自己没有
|
|
928
|
-
// 这个能力(#403)。这里从 description 提取首句做极简 snippet。
|
|
929
810
|
promptSnippet: firstSentenceSnippet(mcpTool.description) ?? `MCP tool ${mcpTool.name} (server: ${serverName})`,
|
|
930
811
|
parameters: mcpTool.inputSchema ?? {},
|
|
931
812
|
execute: async (_toolCallId, params, signal) => {
|
|
@@ -935,7 +816,6 @@ function adaptMcpTool(serverName, mcpTool, client) {
|
|
|
935
816
|
mcpToolServers.set(adapted, serverName);
|
|
936
817
|
return adapted;
|
|
937
818
|
}
|
|
938
|
-
/** 从 MCP 工具 description 提取首句做 promptSnippet(≤100 字符);空描述返回 undefined。 */
|
|
939
819
|
function firstSentenceSnippet(description) {
|
|
940
820
|
const text = (description ?? "").replace(/\s+/g, " ").trim();
|
|
941
821
|
if (!text)
|
|
@@ -944,12 +824,10 @@ function firstSentenceSnippet(description) {
|
|
|
944
824
|
const head = cut > 0 ? text.slice(0, cut + 1) : text;
|
|
945
825
|
return head.length > 100 ? `${head.slice(0, 99)}…` : head;
|
|
946
826
|
}
|
|
947
|
-
/** 工具名必须是 [A-Za-z0-9_-]+(与插件工具同规则),MCP 可能含冒号/斜杠 — 归一化。 */
|
|
948
827
|
function sanitizeToolName(name) {
|
|
949
828
|
const cleaned = (name || "").replace(/[^A-Za-z0-9_-]/g, "_");
|
|
950
829
|
return cleaned || "mcp_tool";
|
|
951
830
|
}
|
|
952
|
-
/** MCP 服务器管理器:自管多服务器生命周期 + 聚合工具。 */
|
|
953
831
|
export class McpBridge {
|
|
954
832
|
dataDir;
|
|
955
833
|
log;
|
|
@@ -959,7 +837,6 @@ export class McpBridge {
|
|
|
959
837
|
disposed = false;
|
|
960
838
|
tools = [];
|
|
961
839
|
serverErrors = new Map();
|
|
962
|
-
/** reload 串行化链:重入的 reload 排在前一个之后,杜绝交叠留下的孤儿进程。 */
|
|
963
840
|
reloadChain = Promise.resolve();
|
|
964
841
|
agentDir;
|
|
965
842
|
cwd;
|
|
@@ -998,7 +875,6 @@ export class McpBridge {
|
|
|
998
875
|
}
|
|
999
876
|
return { status: "stopped", tools: [] };
|
|
1000
877
|
}
|
|
1001
|
-
/** 读取配置并启动全部服务器(顺序 fail-fast:单个失败记日志不拖垮其它)。 */
|
|
1002
878
|
async load() {
|
|
1003
879
|
if (this.disposed)
|
|
1004
880
|
return;
|
|
@@ -1019,7 +895,6 @@ export class McpBridge {
|
|
|
1019
895
|
this.tools.push(adaptMcpTool(name, t, client));
|
|
1020
896
|
}));
|
|
1021
897
|
}
|
|
1022
|
-
/** 启动单个服务器:失败只记日志并返回 null(load / reload 共用)。 */
|
|
1023
898
|
async startOne(name, spec) {
|
|
1024
899
|
if (this.disposed)
|
|
1025
900
|
return null;
|
|
@@ -1059,9 +934,6 @@ export class McpBridge {
|
|
|
1059
934
|
}
|
|
1060
935
|
this.opts.onToolsChanged?.();
|
|
1061
936
|
}
|
|
1062
|
-
/**
|
|
1063
|
-
* 按磁盘上的最新配置**整体换入**服务器集合(`mcp.json` 热加载用),可重复调用。
|
|
1064
|
-
*/
|
|
1065
937
|
async reload() {
|
|
1066
938
|
const run = this.reloadChain.then(() => this.reloadOnce(), () => this.reloadOnce());
|
|
1067
939
|
this.reloadChain = run.then(() => undefined, () => undefined);
|
|
@@ -1094,7 +966,6 @@ export class McpBridge {
|
|
|
1094
966
|
return;
|
|
1095
967
|
}
|
|
1096
968
|
failed++;
|
|
1097
|
-
// 新规格没起来:留住旧实例,别把还能用的服务器一起下线。
|
|
1098
969
|
if (previous) {
|
|
1099
970
|
next.set(name, previous);
|
|
1100
971
|
kept++;
|
|
@@ -1157,7 +1028,6 @@ function optsOverrideOrRead(opts, dataDir) {
|
|
|
1157
1028
|
servers[o.name] = o.spec;
|
|
1158
1029
|
return { servers };
|
|
1159
1030
|
}
|
|
1160
|
-
// 1. 全局配置:agentDir 或 dataDir 兜底
|
|
1161
1031
|
const globalPath = getGlobalMcpPath(opts?.agentDir, dataDir);
|
|
1162
1032
|
let globalCfg = readMcpConfigByPath(globalPath);
|
|
1163
1033
|
if (Object.keys(globalCfg.servers).length === 0 && dataDir) {
|
|
@@ -1166,13 +1036,11 @@ function optsOverrideOrRead(opts, dataDir) {
|
|
|
1166
1036
|
globalCfg = dataDirCfg;
|
|
1167
1037
|
}
|
|
1168
1038
|
}
|
|
1169
|
-
// 2. 项目级配置:cwd/.pi/mcp.json
|
|
1170
1039
|
let projectCfg = { servers: {} };
|
|
1171
1040
|
if (opts?.cwd) {
|
|
1172
1041
|
const projectPath = getProjectMcpPath(opts.cwd);
|
|
1173
1042
|
projectCfg = readMcpConfigByPath(projectPath);
|
|
1174
1043
|
}
|
|
1175
|
-
// 3. 项目级覆盖全局
|
|
1176
1044
|
const merged = { ...globalCfg.servers };
|
|
1177
1045
|
for (const [name, projSpec] of Object.entries(projectCfg.servers)) {
|
|
1178
1046
|
if (!projSpec.command && !projSpec.url && projSpec.enabled !== undefined && merged[name]) {
|
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `mcp.json` 热加载 —— 改完文件即生效,不必再重启 pi-web-ui。
|
|
3
|
-
*
|
|
4
|
-
* 为什么是「盯文件」而不是加协议消息 / 设置面板按钮:`mcp.json` 是用文本编辑器手改的
|
|
5
|
-
* 外部文件(README 一直写着「改完要重启」),没有任何 UI 参与保存;监视文件是唯一不需要
|
|
6
|
-
* 新增协议字段与多语言文案的形态(对照 `reload_models_config`:它有设置面板按钮,所以走协议)。
|
|
7
|
-
*
|
|
8
|
-
* 三条不变量(都有回归用例):
|
|
9
|
-
* 1. **内容没变就不动任何子进程**:指纹按「规范化后的服务器集合」算(服务器顺序无关、
|
|
10
|
-
* 只看影响行为的字段)—— 编辑器保存、重排键、改缩进都不触发重启;
|
|
11
|
-
* 2. **配置写坏不停掉在跑的服务器**:JSON 解析失败只记日志 + 提示一次,绝不碰现有实例
|
|
12
|
-
* (保存过程中的半写状态很常见);
|
|
13
|
-
* 3. **删掉文件 = 清空配置**:与「坏配置」区分开 —— 用户删掉 `mcp.json` 是有意关掉全部
|
|
14
|
-
* MCP 服务器,照常应用。
|
|
15
|
-
*/
|
|
16
1
|
import { readFileSync, watch } from "node:fs";
|
|
17
2
|
import { dirname, join } from "node:path";
|
|
18
3
|
import { getGlobalMcpPath, getProjectMcpPath, mcpServerSnapshot, parseMcpConfig, } from "./mcp-bridge.js";
|
|
19
|
-
/** 规范化指纹:只含影响行为的字段、服务器顺序无关 —— 「内容变了吗」的判据。 */
|
|
20
4
|
function fingerprint(servers) {
|
|
21
5
|
const names = Object.keys(servers).sort();
|
|
22
6
|
return JSON.stringify(names.map((n) => [n, mcpServerSnapshot(servers[n])]));
|
|
@@ -28,7 +12,6 @@ export function createMcpHotReload(deps) {
|
|
|
28
12
|
const log = deps.log ?? (() => { });
|
|
29
13
|
const debounceMs = deps.debounceMs ?? 300;
|
|
30
14
|
const pollIntervalMs = deps.pollIntervalMs ?? 2000;
|
|
31
|
-
/** 上次应用到运行时的内容指纹;null = 还没播种。 */
|
|
32
15
|
let applied = null;
|
|
33
16
|
let disposed = false;
|
|
34
17
|
let applyTail = Promise.resolve();
|
|
@@ -52,15 +35,10 @@ export function createMcpHotReload(deps) {
|
|
|
52
35
|
return { fp: `invalid:${raw}`, servers: null };
|
|
53
36
|
return { fp: `ok:${fingerprint(parsed.servers)}`, servers: parsed.servers };
|
|
54
37
|
}
|
|
55
|
-
/** 读全部配置文件(全局 + 项目)并合并指纹 */
|
|
56
38
|
function readOnce() {
|
|
57
39
|
const g = readOneFile(globalFile);
|
|
58
40
|
let globalServers = g.servers;
|
|
59
41
|
let gFp = g.fp;
|
|
60
|
-
// 与 mcp-bridge 的启动加载同口径:全局文件**不存在或存在但 0 个服务器**都
|
|
61
|
-
// 回退 dataDir legacy 配置。只判「文件不存在」时,「全局空配置 + legacy 有
|
|
62
|
-
// 服务」的部署里启动用 legacy 起服务、热加载却跳过 legacy——改 legacy 的
|
|
63
|
-
// 增删在重启前永不生效。
|
|
64
42
|
const globalHasNoServers = g.servers !== null && Object.keys(g.servers).length === 0;
|
|
65
43
|
if ((g.fp === "empty" || globalHasNoServers) && legacyFile !== globalFile) {
|
|
66
44
|
const leg = readOneFile(legacyFile);
|
|
@@ -105,7 +83,6 @@ export function createMcpHotReload(deps) {
|
|
|
105
83
|
const { fp, servers } = readOnce();
|
|
106
84
|
if (fp === applied)
|
|
107
85
|
return "unchanged";
|
|
108
|
-
// 先记账再动手:同一个坏文件不反复刷屏,配置没再变也不重试。
|
|
109
86
|
applied = fp;
|
|
110
87
|
if (!servers) {
|
|
111
88
|
log("[mcp] mcp.json 解析失败,保留在跑的 MCP 服务器");
|
|
@@ -149,7 +126,6 @@ export function createMcpHotReload(deps) {
|
|
|
149
126
|
run();
|
|
150
127
|
}, debounceMs);
|
|
151
128
|
}
|
|
152
|
-
/** fs.watch 用不了(目录还不存在、网络盘、容器)→ 回落到轮询:单文件不值得上更重的机制。 */
|
|
153
129
|
function fallBackToPolling() {
|
|
154
130
|
if (disposed)
|
|
155
131
|
return;
|
|
@@ -169,7 +145,6 @@ export function createMcpHotReload(deps) {
|
|
|
169
145
|
function start() {
|
|
170
146
|
if (disposed || watchers.length > 0 || poller)
|
|
171
147
|
return;
|
|
172
|
-
// 播种:启动时 load() 已按同一份文件启动过服务器,别在第一个事件里白重载一次。
|
|
173
148
|
applied = readOnce().fp;
|
|
174
149
|
const dirsToWatch = new Set();
|
|
175
150
|
dirsToWatch.add(deps.dataDir);
|