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
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { existsSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { isUploadDataTooLong, uploadLimitBytes } from "./payload-limits.js";
|
|
4
|
+
import { CLIENT_ID_PATTERN, saveUpload, uploadsRoot } from "./uploads.js";
|
|
5
|
+
import { ENGINE_CATALOG, isNativeCliEngineId } from "./engine-catalog.js";
|
|
6
|
+
import { nativeCliModelLaunch } from "./native-cli-model.js";
|
|
7
|
+
import { resolveCliExecutableLaunch, resolveEngineCliLaunch } from "./engine-cli.js";
|
|
8
|
+
import { isAbsoluteWirePath, wireToAbs } from "./files-service.js";
|
|
9
|
+
const CONTROL_CHARACTERS = /[\x00-\x1f\x7f-\x9f]/;
|
|
10
|
+
export const NATIVE_CLI_ENTRY = "webui/native-cli";
|
|
11
|
+
export function parseNativeCliMetadata(value) {
|
|
12
|
+
const data = value;
|
|
13
|
+
if (data?.version !== 1)
|
|
14
|
+
throw new Error("Unsupported native CLI conversation metadata");
|
|
15
|
+
return validateNativeCliConfig(data.config);
|
|
16
|
+
}
|
|
17
|
+
export function readNativeCliConfig(manager) {
|
|
18
|
+
const entry = [...manager.getEntries()]
|
|
19
|
+
.reverse()
|
|
20
|
+
.find((item) => item.type === "custom" && item.customType === NATIVE_CLI_ENTRY);
|
|
21
|
+
if (!entry || entry.type !== "custom")
|
|
22
|
+
return undefined;
|
|
23
|
+
return parseNativeCliMetadata(entry.data);
|
|
24
|
+
}
|
|
25
|
+
export function persistNativeCliConfig(manager, config, title) {
|
|
26
|
+
manager.appendCustomEntry(NATIVE_CLI_ENTRY, { version: 1, config: validateNativeCliConfig(config) });
|
|
27
|
+
manager.appendSessionInfo(title);
|
|
28
|
+
const path = manager.getSessionFile();
|
|
29
|
+
if (manager.isPersisted() && path && !existsSync(path)) {
|
|
30
|
+
writeFileSync(path, [manager.getHeader(), ...manager.getEntries()].map((entry) => JSON.stringify(entry)).join("\n") + "\n", { encoding: "utf8", flag: "wx" });
|
|
31
|
+
manager.setSessionFile(path);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export const MAX_NATIVE_CLI_PASTE = 64 * 1024 - 12;
|
|
35
|
+
export function validateNativeCliConfig(value) {
|
|
36
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
37
|
+
throw new Error("Invalid native CLI configuration");
|
|
38
|
+
const config = value;
|
|
39
|
+
if (Object.keys(config).some((key) => !["preset", "executable", "args", "model", "keepAlive"].includes(key)))
|
|
40
|
+
throw new Error("Unknown native CLI configuration field");
|
|
41
|
+
if (!isNativeCliEngineId(config.preset) && config.preset !== "custom")
|
|
42
|
+
throw new Error("Invalid native CLI preset");
|
|
43
|
+
if (config.executable !== undefined &&
|
|
44
|
+
(typeof config.executable !== "string" ||
|
|
45
|
+
!config.executable.trim() ||
|
|
46
|
+
config.executable.length > 4096 ||
|
|
47
|
+
CONTROL_CHARACTERS.test(config.executable)))
|
|
48
|
+
throw new Error("Invalid native CLI executable (max 4096 characters, no control characters)");
|
|
49
|
+
if (config.preset === "custom" && !config.executable)
|
|
50
|
+
throw new Error("Custom native CLI requires an executable");
|
|
51
|
+
if (config.keepAlive !== undefined && typeof config.keepAlive !== "boolean")
|
|
52
|
+
throw new Error("Invalid native CLI keep-alive preference");
|
|
53
|
+
if (config.args !== undefined &&
|
|
54
|
+
(!Array.isArray(config.args) ||
|
|
55
|
+
config.args.length > 128 ||
|
|
56
|
+
config.args.some((arg) => typeof arg !== "string" || arg.length > 4096 || CONTROL_CHARACTERS.test(arg))))
|
|
57
|
+
throw new Error("Invalid native CLI arguments (max 128 arguments, 4096 characters each, no control characters)");
|
|
58
|
+
let model;
|
|
59
|
+
if (config.model !== undefined) {
|
|
60
|
+
const selected = config.model;
|
|
61
|
+
if (!selected ||
|
|
62
|
+
typeof selected !== "object" ||
|
|
63
|
+
Array.isArray(selected) ||
|
|
64
|
+
Object.keys(selected).some((key) => key !== "provider" && key !== "id") ||
|
|
65
|
+
[selected.provider, selected.id].some((part) => typeof part !== "string" || !part.trim() || part.length > 4096 || CONTROL_CHARACTERS.test(part)) ||
|
|
66
|
+
config.preset === "custom" ||
|
|
67
|
+
!ENGINE_CATALOG[config.preset].cliModelArgs)
|
|
68
|
+
throw new Error("Invalid native CLI model");
|
|
69
|
+
model = { provider: selected.provider, id: selected.id };
|
|
70
|
+
}
|
|
71
|
+
const args = config.args;
|
|
72
|
+
if (config.preset !== "custom") {
|
|
73
|
+
const engine = ENGINE_CATALOG[config.preset];
|
|
74
|
+
if (!engine.cliCommand)
|
|
75
|
+
throw new Error(`${engine.name} has no standalone CLI`);
|
|
76
|
+
if (engine.cliRequiresArgs && !args?.[0]?.trim())
|
|
77
|
+
throw new Error(`${engine.name} CLI requires a configured terminal profile and its arguments`);
|
|
78
|
+
}
|
|
79
|
+
if (args && args.reduce((size, arg) => size + arg.length + 1, 0) > 32768)
|
|
80
|
+
throw new Error("Native CLI arguments are too long");
|
|
81
|
+
return {
|
|
82
|
+
preset: config.preset,
|
|
83
|
+
...(config.executable !== undefined ? { executable: config.executable } : {}),
|
|
84
|
+
...(args !== undefined ? { args: [...args] } : {}),
|
|
85
|
+
...(config.keepAlive !== undefined ? { keepAlive: config.keepAlive } : {}),
|
|
86
|
+
...(model ? { model } : {}),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export function nativeCliLaunchArgs(config) {
|
|
90
|
+
const args = config.args ?? [];
|
|
91
|
+
if (!config.model || config.preset === "custom")
|
|
92
|
+
return args;
|
|
93
|
+
const flags = args.slice(0, args.indexOf("--") < 0 ? args.length : args.indexOf("--"));
|
|
94
|
+
const hasOption = (...names) => flags.some((arg) => names.some((name) => arg === name || arg.startsWith(`${name}=`)));
|
|
95
|
+
const inherited = [];
|
|
96
|
+
if (ENGINE_CATALOG[config.preset].cliModelArgs === "provider-model" && !hasOption("--provider")) {
|
|
97
|
+
inherited.push("--provider", config.model.provider);
|
|
98
|
+
}
|
|
99
|
+
if (!hasOption("--model", "-m"))
|
|
100
|
+
inherited.push("--model", config.model.id);
|
|
101
|
+
return [...inherited, ...args];
|
|
102
|
+
}
|
|
103
|
+
export function resolveNativeCliLaunch(value, options = {}) {
|
|
104
|
+
const config = validateNativeCliConfig(value);
|
|
105
|
+
if (config.preset === "custom")
|
|
106
|
+
return resolveCliExecutableLaunch(config.executable, config.args, options);
|
|
107
|
+
const inherited = nativeCliModelLaunch(config, options.modelConnection, options.env ?? process.env);
|
|
108
|
+
const launch = resolveEngineCliLaunch(config.preset, {
|
|
109
|
+
...options,
|
|
110
|
+
executablePath: config.executable,
|
|
111
|
+
args: [...inherited.args, ...nativeCliLaunchArgs(config)],
|
|
112
|
+
});
|
|
113
|
+
return { ...launch, ...(inherited.env ? { env: inherited.env } : {}) };
|
|
114
|
+
}
|
|
115
|
+
export function sanitizeNativeCliPaste(text) {
|
|
116
|
+
return text.replace(/\r\n?/g, "\n").replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, "");
|
|
117
|
+
}
|
|
118
|
+
function checkedString(value, label) {
|
|
119
|
+
if (typeof value !== "string" || !value || value.length > 4096 || CONTROL_CHARACTERS.test(value))
|
|
120
|
+
throw new Error(`Invalid native CLI attachment ${label}`);
|
|
121
|
+
return value;
|
|
122
|
+
}
|
|
123
|
+
function assertWithin(root, path) {
|
|
124
|
+
const rel = relative(root, path);
|
|
125
|
+
if (rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel))
|
|
126
|
+
throw new Error("Attachment is outside the allowed directory");
|
|
127
|
+
}
|
|
128
|
+
export function prepareNativeCliPaste(data, attachments, cwd, context) {
|
|
129
|
+
if (typeof data !== "string" || data.length > MAX_NATIVE_CLI_PASTE)
|
|
130
|
+
throw new Error("Native CLI prompt is too long or invalid");
|
|
131
|
+
if (attachments !== undefined && (!Array.isArray(attachments) || attachments.length > 32))
|
|
132
|
+
throw new Error("Invalid native CLI attachments (max 32)");
|
|
133
|
+
if (!CLIENT_ID_PATTERN.test(context.clientId))
|
|
134
|
+
throw new Error("Invalid upload client identity");
|
|
135
|
+
const maxBytes = uploadLimitBytes(context.settings, "chat");
|
|
136
|
+
let uploadBytes = 0;
|
|
137
|
+
const parts = [sanitizeNativeCliPaste(data)];
|
|
138
|
+
for (const att of attachments ?? []) {
|
|
139
|
+
if (!att || typeof att !== "object")
|
|
140
|
+
throw new Error("Invalid native CLI attachment");
|
|
141
|
+
if (att.mode && !["reference", "inline", "lines", "quote"].includes(att.mode))
|
|
142
|
+
throw new Error(`Native CLI does not support attachment mode: ${att.mode}`);
|
|
143
|
+
if (att.mode === "quote") {
|
|
144
|
+
if (typeof att.quote?.text !== "string" || att.quote.text.length > MAX_NATIVE_CLI_PASTE)
|
|
145
|
+
throw new Error("Invalid native CLI text quote");
|
|
146
|
+
parts.push(`Quoted text:\n${sanitizeNativeCliPaste(att.quote.text)}`);
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const sources = [att.fileData, att.imageData, att.uploadPath].filter((source) => source !== undefined);
|
|
150
|
+
if (sources.length > 1)
|
|
151
|
+
throw new Error("Ambiguous native CLI attachment source");
|
|
152
|
+
let abs;
|
|
153
|
+
let pathKind = "File";
|
|
154
|
+
if (att.fileData !== undefined || att.imageData !== undefined) {
|
|
155
|
+
const rawData = att.fileData ?? att.imageData;
|
|
156
|
+
if (typeof rawData !== "string")
|
|
157
|
+
throw new Error("Invalid native CLI upload data");
|
|
158
|
+
const raw = rawData.replace(/^data:[^;,]+;base64,/, "");
|
|
159
|
+
if (isUploadDataTooLong(raw.length, maxBytes - uploadBytes))
|
|
160
|
+
throw new Error("Native CLI uploads exceed the chat upload limit");
|
|
161
|
+
if (raw.length % 4 === 1 || (raw.includes("=") && raw.length % 4 !== 0) || !/^[A-Za-z0-9+/]*={0,2}$/.test(raw))
|
|
162
|
+
throw new Error("Invalid native CLI upload base64");
|
|
163
|
+
const buf = Buffer.from(raw, "base64");
|
|
164
|
+
uploadBytes += buf.length;
|
|
165
|
+
if (uploadBytes > maxBytes)
|
|
166
|
+
throw new Error("Native CLI uploads exceed the chat upload limit");
|
|
167
|
+
const name = att.name === undefined ? (att.imageData !== undefined ? "image.png" : "file") : checkedString(att.name, "name");
|
|
168
|
+
abs = saveUpload(context.clientId, name, buf, context.dataDir).abs;
|
|
169
|
+
}
|
|
170
|
+
else if (att.uploadPath !== undefined) {
|
|
171
|
+
const root = resolve(uploadsRoot(context.dataDir), context.clientId);
|
|
172
|
+
abs = resolve(checkedString(att.uploadPath, "upload path"));
|
|
173
|
+
assertWithin(root, abs);
|
|
174
|
+
assertWithin(realpathSync(root), realpathSync(abs));
|
|
175
|
+
if (!statSync(abs).isFile())
|
|
176
|
+
throw new Error("Uploaded attachment is not a file");
|
|
177
|
+
uploadBytes += statSync(abs).size;
|
|
178
|
+
if (uploadBytes > maxBytes)
|
|
179
|
+
throw new Error("Native CLI uploads exceed the chat upload limit");
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
const reference = checkedString(att.path, "path");
|
|
183
|
+
const absolute = isAbsoluteWirePath(reference);
|
|
184
|
+
abs = realpathSync(absolute ? wireToAbs(reference) : resolve(cwd, reference));
|
|
185
|
+
if (!absolute)
|
|
186
|
+
assertWithin(realpathSync(cwd), abs);
|
|
187
|
+
const stats = statSync(abs);
|
|
188
|
+
if (!stats.isFile() && !stats.isDirectory())
|
|
189
|
+
throw new Error("Native CLI attachment is not a file or directory");
|
|
190
|
+
if (stats.isDirectory())
|
|
191
|
+
pathKind = "Directory";
|
|
192
|
+
}
|
|
193
|
+
let location = JSON.stringify(abs);
|
|
194
|
+
if (att.mode === "lines") {
|
|
195
|
+
if (!Number.isSafeInteger(att.lines?.start) ||
|
|
196
|
+
!Number.isSafeInteger(att.lines?.end) ||
|
|
197
|
+
att.lines.start < 1 ||
|
|
198
|
+
att.lines.end < att.lines.start)
|
|
199
|
+
throw new Error("Invalid native CLI attachment line range");
|
|
200
|
+
location += ` (lines ${att.lines.start}-${att.lines.end})`;
|
|
201
|
+
}
|
|
202
|
+
parts.push(`${pathKind} path: ${location}`);
|
|
203
|
+
}
|
|
204
|
+
const text = parts.filter(Boolean).join("\n\n");
|
|
205
|
+
if (!text.trim())
|
|
206
|
+
throw new Error("Native CLI prompt is empty");
|
|
207
|
+
if (text.length > MAX_NATIVE_CLI_PASTE || Buffer.byteLength(text, "utf8") > MAX_NATIVE_CLI_PASTE)
|
|
208
|
+
throw new Error("Native CLI prompt is too long");
|
|
209
|
+
return text;
|
|
210
|
+
}
|
package/dist/server/net-guard.js
CHANGED
|
@@ -1,29 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* server/net-guard.ts —— 服务端外发 HTTP(S) 请求的统一 SSRF 防护与安全抓取工具 (#602)。
|
|
3
|
-
*
|
|
4
|
-
* 防护分层:
|
|
5
|
-
* 1. URL 语法与协议白名单:仅允许 http: / https:;
|
|
6
|
-
* 2. 主机名与字面量 IP 校验(isBlockedHost):
|
|
7
|
-
* - 拦截 localhost / *.localhost / *.local / *.internal;
|
|
8
|
-
* - 将 IPv6 完整展开为 8×16-bit 组,统一还原 IPv4-mapped (::ffff:0:0/96)、
|
|
9
|
-
* IPv4-translated (::ffff:0:0:0/96)、IPv4-compatible (::/96)、NAT64 (64:ff9b::/96)
|
|
10
|
-
* 内嵌的 32-bit IPv4,彻底杜绝 ::ffff:7f00:1 / ::ffff:0:7f00:1 / 0:0:0:0:0:ffff:... 绕过;
|
|
11
|
-
* - 拦截回环、未指定、RFC1918 私网、CGNAT (100.64/10)、链路本地与云元数据 (169.254/16, fe80::/10)、
|
|
12
|
-
* ULA (fc00::/7)、组播与保留段;
|
|
13
|
-
* 3. DNS 解析后 IP 校验(resolveAndValidateUrl):
|
|
14
|
-
* - 对域名调用 dns.promises.lookup(host, { all: true }),任一 A/AAAA 记录命中内网/元数据 IP 即拒绝,
|
|
15
|
-
* 防御域名解析到 127.0.0.1 / 169.254.169.254 的 DNS rebinding;
|
|
16
|
-
* 4. 重定向逐跳校验(safeFetch):
|
|
17
|
-
* - 强制 redirect: "manual",对每一跳 Location 重新执行 URL + DNS 校验(最多 5 跳),
|
|
18
|
-
* 防止公网 URL 302 跳转到内网/云元数据端点。
|
|
19
|
-
*/
|
|
20
1
|
import { lookup as dnsLookup } from "node:dns/promises";
|
|
21
2
|
import { isIP } from "node:net";
|
|
22
3
|
import { Agent, buildConnector, fetch as undiciFetch } from "undici";
|
|
23
4
|
const defaultLookupAll = async (hostname) => {
|
|
24
5
|
return await dnsLookup(hostname, { all: true, verbatim: true });
|
|
25
6
|
};
|
|
26
|
-
/** 解析点分十进制 IPv4 为 4 个 0..255 字节;非法返回 null。 */
|
|
27
7
|
function parseIpv4Octets(input) {
|
|
28
8
|
const m = input.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
|
|
29
9
|
if (!m)
|
|
@@ -36,30 +16,21 @@ function parseIpv4Octets(input) {
|
|
|
36
16
|
return null;
|
|
37
17
|
return [a, b, c, d];
|
|
38
18
|
}
|
|
39
|
-
/** 判定 4 字节 IPv4 是否属于内网/回环/链路本地/云元数据/保留段。 */
|
|
40
19
|
function isBlockedIpv4Octets([a, b]) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
a ===
|
|
44
|
-
|
|
45
|
-
a ===
|
|
46
|
-
(a ===
|
|
47
|
-
(a ===
|
|
48
|
-
|
|
49
|
-
a >= 224 // 224.0.0.0/4 (multicast) & 240.0.0.0/4 (reserved/broadcast)
|
|
50
|
-
);
|
|
20
|
+
return (a === 0 ||
|
|
21
|
+
a === 10 ||
|
|
22
|
+
(a === 100 && b >= 64 && b <= 127) ||
|
|
23
|
+
a === 127 ||
|
|
24
|
+
(a === 169 && b === 254) ||
|
|
25
|
+
(a === 172 && b >= 16 && b <= 31) ||
|
|
26
|
+
(a === 192 && b === 168) ||
|
|
27
|
+
a >= 224);
|
|
51
28
|
}
|
|
52
|
-
/**
|
|
53
|
-
* 将任意合法 IPv6 字符串(含 :: 压缩及末尾 점分 IPv4)展开为 8 个 16-bit 整数(0..0xffff)。
|
|
54
|
-
* 解析失败返回 null。
|
|
55
|
-
*/
|
|
56
29
|
function expandIpv6Words(rawInput) {
|
|
57
|
-
// 去掉 zone index(如 fe80::1%eth0 或 %25eth0)
|
|
58
30
|
const input = rawInput.split("%")[0].toLowerCase();
|
|
59
31
|
if (!input.includes(":"))
|
|
60
32
|
return null;
|
|
61
33
|
let working = input;
|
|
62
|
-
// 若末尾带点分 IPv4(如 ::ffff:127.0.0.1 或 ::ffff:0:127.0.0.1),先转成两个 16-bit hex 段
|
|
63
34
|
const lastColon = working.lastIndexOf(":");
|
|
64
35
|
const tail = working.slice(lastColon + 1);
|
|
65
36
|
if (tail.includes(".")) {
|
|
@@ -100,13 +71,6 @@ function expandIpv6Words(rawInput) {
|
|
|
100
71
|
return null;
|
|
101
72
|
return full;
|
|
102
73
|
}
|
|
103
|
-
/**
|
|
104
|
-
* 判断 8×16-bit IPv6 地址是否内嵌了 IPv4:
|
|
105
|
-
* - IPv4-mapped: 0:0:0:0:0:ffff:w6:w7
|
|
106
|
-
* - IPv4-translated: 0:0:0:0:ffff:0:w6:w7 (RFC 2765 SIIT)
|
|
107
|
-
* - IPv4-compatible: 0:0:0:0:0:0:w6:w7 (排除 ::0 与 ::1)
|
|
108
|
-
* - NAT64 well-known prefix: 64:ff9b:0:0:0:0:w6:w7 或 64:ff9b:1::/48
|
|
109
|
-
*/
|
|
110
74
|
function extractEmbeddedIpv4(w) {
|
|
111
75
|
const isMapped = w[0] === 0 && w[1] === 0 && w[2] === 0 && w[3] === 0 && w[4] === 0 && w[5] === 0xffff;
|
|
112
76
|
const isTranslated = w[0] === 0 && w[1] === 0 && w[2] === 0 && w[3] === 0 && w[4] === 0xffff && w[5] === 0;
|
|
@@ -123,7 +87,6 @@ function extractEmbeddedIpv4(w) {
|
|
|
123
87
|
}
|
|
124
88
|
return null;
|
|
125
89
|
}
|
|
126
|
-
/** SSRF 收口:内网/回环/链路本地/云元数据地址一律拒绝。 */
|
|
127
90
|
export function isBlockedHost(hostname) {
|
|
128
91
|
const host = hostname
|
|
129
92
|
.trim()
|
|
@@ -135,11 +98,10 @@ export function isBlockedHost(hostname) {
|
|
|
135
98
|
if (host === "localhost" || host.endsWith(".localhost") || host.endsWith(".local") || host.endsWith(".internal")) {
|
|
136
99
|
return true;
|
|
137
100
|
}
|
|
138
|
-
// 1. IPv6 字面量(含 ::ffff:7f00:1 / ::ffff:0:7f00:1 / 0:0:0:0:0:ffff:... 等所有展开或压缩变体)
|
|
139
101
|
if (host.includes(":")) {
|
|
140
102
|
const words = expandIpv6Words(host);
|
|
141
103
|
if (!words)
|
|
142
|
-
return true;
|
|
104
|
+
return true;
|
|
143
105
|
const embeddedV4 = extractEmbeddedIpv4(words);
|
|
144
106
|
if (embeddedV4) {
|
|
145
107
|
return isBlockedIpv4Octets(embeddedV4);
|
|
@@ -151,36 +113,27 @@ export function isBlockedHost(hostname) {
|
|
|
151
113
|
words[4] === 0 &&
|
|
152
114
|
words[5] === 0 &&
|
|
153
115
|
words[6] === 0;
|
|
154
|
-
// :: (unspecified) 或 ::1 (loopback)
|
|
155
116
|
if (allZeroPrefix && (words[7] === 0 || words[7] === 1))
|
|
156
117
|
return true;
|
|
157
|
-
// fe80::/10 (link-local)
|
|
158
118
|
if ((words[0] & 0xffc0) === 0xfe80)
|
|
159
119
|
return true;
|
|
160
|
-
// fc00::/7 (ULA unique local fc00::..fdff::)
|
|
161
120
|
if ((words[0] & 0xfe00) === 0xfc00)
|
|
162
121
|
return true;
|
|
163
|
-
// ff00::/8 (multicast)
|
|
164
122
|
if ((words[0] & 0xff00) === 0xff00)
|
|
165
123
|
return true;
|
|
166
|
-
// 2001:db8::/32 (documentation)
|
|
167
124
|
if (words[0] === 0x2001 && words[1] === 0x0db8)
|
|
168
125
|
return true;
|
|
169
126
|
return false;
|
|
170
127
|
}
|
|
171
|
-
// 2. 标准点分 IPv4
|
|
172
128
|
const v4 = parseIpv4Octets(host);
|
|
173
129
|
if (v4) {
|
|
174
130
|
return isBlockedIpv4Octets(v4);
|
|
175
131
|
}
|
|
176
|
-
// 3. 非常规纯数字/十六进制/八进制单段或多段 IPv4 变形(如 2130706433、0x7f000001、127.1)
|
|
177
|
-
// URL 构造器通常会规范化,若仍有纯数字结尾段则拒绝
|
|
178
132
|
if (/^(?:0x[0-9a-f]+|\d+)(?:\.(?:0x[0-9a-f]+|\d+))*$/i.test(host)) {
|
|
179
133
|
return true;
|
|
180
134
|
}
|
|
181
135
|
return false;
|
|
182
136
|
}
|
|
183
|
-
/** 同步校验一个可抓取地址:只允许 http/https 且 hostname 非内网/回环。 */
|
|
184
137
|
export function validateFetchUrl(raw) {
|
|
185
138
|
let u;
|
|
186
139
|
try {
|
|
@@ -195,13 +148,6 @@ export function validateFetchUrl(raw) {
|
|
|
195
148
|
return { ok: false, reason: "host" };
|
|
196
149
|
return { ok: true, url: u.toString() };
|
|
197
150
|
}
|
|
198
|
-
/**
|
|
199
|
-
* 异步校验 URL + 解析后 IP(防 DNS rebinding 指向 127.0.0.1 / 169.254.169.254 等内网地址)。
|
|
200
|
-
*
|
|
201
|
-
* - 先执行 validateFetchUrl;
|
|
202
|
-
* - 若 hostname 是域名(非 IP 字面量),调用 lookup 解析全部 A/AAAA 记录;
|
|
203
|
-
* - 任一解析出的 IP 命中 isBlockedHost,或解析无结果/报错,均判定为 reason: "host"。
|
|
204
|
-
*/
|
|
205
151
|
export async function resolveAndValidateUrl(raw, opts = {}) {
|
|
206
152
|
const sync = validateFetchUrl(raw);
|
|
207
153
|
if (!sync.ok)
|
|
@@ -232,9 +178,6 @@ export async function resolveAndValidateUrl(raw, opts = {}) {
|
|
|
232
178
|
}
|
|
233
179
|
}
|
|
234
180
|
const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
|
|
235
|
-
/**
|
|
236
|
-
* 带 SSRF 收口(URL 校验 + DNS 解析后 IP 校验 + 重定向逐跳校验)的安全 fetch 封装。
|
|
237
|
-
*/
|
|
238
181
|
export class FetchUrlError extends Error {
|
|
239
182
|
reason;
|
|
240
183
|
constructor(reason, url) {
|
|
@@ -242,7 +185,6 @@ export class FetchUrlError extends Error {
|
|
|
242
185
|
this.reason = reason;
|
|
243
186
|
}
|
|
244
187
|
}
|
|
245
|
-
/** Abort also bounds DNS and injected transports that do not implement signals. */
|
|
246
188
|
export function readBeforeAbort(work, signal) {
|
|
247
189
|
return new Promise((resolve, reject) => {
|
|
248
190
|
const abort = () => {
|
|
@@ -276,8 +218,6 @@ async function pinnedFetch(url, init, addresses) {
|
|
|
276
218
|
callback(null, records[0].address, records[0].family);
|
|
277
219
|
},
|
|
278
220
|
});
|
|
279
|
-
// A private dispatcher prevents proxy/global-dispatcher DNS resolution and cross-hop pooling.
|
|
280
|
-
// Keep the original hostname in the URL and connector for Host, SNI and certificate checks.
|
|
281
221
|
const dispatcher = new Agent({
|
|
282
222
|
connect: (options, callback) => {
|
|
283
223
|
if (options.hostname.replace(/^\[|\]$/g, "") !== hostname) {
|
|
@@ -301,7 +241,6 @@ async function pinnedFetch(url, init, addresses) {
|
|
|
301
241
|
headers: Array.from(headers.entries()),
|
|
302
242
|
dispatcher,
|
|
303
243
|
});
|
|
304
|
-
// Graceful close waits for the response stream; abort/cancel still destroys the connection.
|
|
305
244
|
void dispatcher
|
|
306
245
|
.close()
|
|
307
246
|
.catch(() => dispatcher.destroy())
|
|
@@ -360,7 +299,6 @@ export async function safeFetch(url, init = {}, opts = {}) {
|
|
|
360
299
|
headers.delete(name);
|
|
361
300
|
currentInit = { ...currentInit, headers };
|
|
362
301
|
}
|
|
363
|
-
// 303 或 301/302 POST 重定向按规范退化为 GET
|
|
364
302
|
if (res.status === 303 ||
|
|
365
303
|
((res.status === 301 || res.status === 302) && currentInit.method?.toUpperCase() === "POST")) {
|
|
366
304
|
const headers = new Headers(currentInit.headers);
|
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Office 文档纯文本提取(docx / xlsx / xlsm,csv 由调用方按普通文本处理)。
|
|
3
|
-
*
|
|
4
|
-
* 给「随处可看」用的:文件预览(files-service readFile)、附件等走 file_content
|
|
5
|
-
* 下发 Markdown 文本,前端 FilePreview 按 Markdown 渲染表格/段落,无需改协议。
|
|
6
|
-
*
|
|
7
|
-
* 零依赖:docx / xlsx / pptx 本质是 zip 包,这里用 node:zlib + 手写 zip 中央目录解析
|
|
8
|
-
* 做最小解包(只支持 stored / deflate,Office 写出的文件都是这两种)。
|
|
9
|
-
*/
|
|
10
1
|
import { inflateRawSync } from "node:zlib";
|
|
11
2
|
const OFFICE_EXTS = new Set([".docx", ".xlsx", ".xlsm", ".pptx", ".pptm", ".ppsx", ".potx"]);
|
|
12
|
-
/** 单个文件上限(15MB)。 */
|
|
13
3
|
export const OFFICE_MAX_FILE_BYTES = 15 * 1024 * 1024;
|
|
14
|
-
/** 解包后总量上限(防 zip 炸弹:小包解出巨量内容)。 */
|
|
15
4
|
export const OFFICE_MAX_UNCOMPRESSED_BYTES = 64 * 1024 * 1024;
|
|
16
|
-
/** 下发文本上限(字符;超出截断并置 truncated)。 */
|
|
17
5
|
export const OFFICE_MAX_TEXT_CHARS = 200_000;
|
|
18
|
-
/** 表格上限:每表行数 × 列数(预览首屏口径)。 */
|
|
19
6
|
const MAX_ROWS = 500;
|
|
20
7
|
const MAX_COLS = 20;
|
|
21
8
|
export function isOfficeFile(name) {
|
|
@@ -37,7 +24,6 @@ function findEocd(buf) {
|
|
|
37
24
|
}
|
|
38
25
|
throw new Error("不是有效的 zip 文件(找不到 EOCD)");
|
|
39
26
|
}
|
|
40
|
-
/** 返回 Map<文件名, Buffer>(只解要的文件,其余跳过)。 */
|
|
41
27
|
export function unzipFiles(buf, wanted) {
|
|
42
28
|
const want = new Set(wanted);
|
|
43
29
|
const eocd = findEocd(buf);
|
|
@@ -108,7 +94,6 @@ export function unzipFiles(buf, wanted) {
|
|
|
108
94
|
}
|
|
109
95
|
return out;
|
|
110
96
|
}
|
|
111
|
-
/** 列出 zip 中央目录里的全部条目名(不解压内容,快速探测)。 */
|
|
112
97
|
export function listZipEntries(buf) {
|
|
113
98
|
const eocd = findEocd(buf);
|
|
114
99
|
const cdCount = buf.readUInt16LE(eocd + 10);
|
|
@@ -128,13 +113,6 @@ export function listZipEntries(buf) {
|
|
|
128
113
|
return names;
|
|
129
114
|
}
|
|
130
115
|
const NAMED_ENTITIES = { lt: "<", gt: ">", amp: "&", quot: '"', apos: "'" };
|
|
131
|
-
/**
|
|
132
|
-
* 单轮解码命名实体与十/十六进制数字实体(一次扫描同时匹配三类)。
|
|
133
|
-
*
|
|
134
|
-
* 旧实现分三段 replace:`&#60;` 会先被命名段解码成 `<`、再被数字段
|
|
135
|
-
* 解码成 `<`——双重解码让转义文本"逃出"字面量(可注入标签)。单轮扫描把
|
|
136
|
-
* `&…;` 整体消费、解码产物不参与后续匹配:`&#60;` 正确地得到 `<`。
|
|
137
|
-
*/
|
|
138
116
|
function decodeEntities(s) {
|
|
139
117
|
return String(s ?? "").replace(/&(?:#([0-9]+);|#x([0-9a-fA-F]+);|([a-zA-Z]+);)/g, (_whole, dec, hex, name) => {
|
|
140
118
|
if (dec !== undefined) {
|
|
@@ -153,27 +131,19 @@ function decodeEntities(s) {
|
|
|
153
131
|
return "";
|
|
154
132
|
}
|
|
155
133
|
}
|
|
156
|
-
// 未知的命名实体保留原文(与旧实现一致,不臆造映射)
|
|
157
134
|
return NAMED_ENTITIES[name ?? ""] ?? _whole;
|
|
158
135
|
});
|
|
159
136
|
}
|
|
160
137
|
const stripTags = (s) => decodeEntities(String(s ?? "").replace(/<[^>]+>/g, ""));
|
|
161
|
-
/** document.xml 解压后的字节上限:超大 XML 会让段落正则扫描退化成秒级卡顿(同步事件循环被挂死)。 */
|
|
162
138
|
const DOCX_MAX_XML_BYTES = 20 * 1024 * 1024;
|
|
163
|
-
/** docx → 段落数组。 */
|
|
164
139
|
export function parseDocxParagraphs(buf) {
|
|
165
140
|
const files = unzipFiles(buf, ["word/document.xml"]);
|
|
166
141
|
const xml = files.get("word/document.xml")?.toString("utf8");
|
|
167
142
|
if (!xml)
|
|
168
143
|
throw new Error("docx 里找不到 word/document.xml");
|
|
169
|
-
// 预检 1:解压后过大的 document.xml 在下面的正则扫描里代价爆炸(一次性物化
|
|
170
|
-
// 全部段落、非贪婪匹配最坏回溯到文本末尾),直接友好报错而不是挂住进程。
|
|
171
144
|
if (xml.length > DOCX_MAX_XML_BYTES) {
|
|
172
145
|
throw new Error(`文档内容过大(document.xml 解压后 ${(xml.length / 1048576).toFixed(1)} MB,上限 20 MB),拒绝预览`);
|
|
173
146
|
}
|
|
174
|
-
// 预检 2:正常文档的段落闭合标签与开标签同量级。"只有开标签、没有闭标签"
|
|
175
|
-
// 的恶意结构会让非贪婪正则在每个候选起点都回溯扫描到文本末尾(O(n²)),
|
|
176
|
-
// 同步挂死事件循环——开标签远多于闭标签(>2 倍)且闭标签为 0 时直接报错。
|
|
177
147
|
const opens = xml.match(/<w:p[\s>]/g)?.length ?? 0;
|
|
178
148
|
const closes = xml.match(/<\/w:p>/g)?.length ?? 0;
|
|
179
149
|
if (opens > 0 && closes === 0) {
|
|
@@ -235,7 +205,6 @@ function parseSheet(xml, shared) {
|
|
|
235
205
|
if (!Number.isFinite(rNum) || rNum < 0)
|
|
236
206
|
continue;
|
|
237
207
|
maxRowSeen = Math.max(maxRowSeen, rNum + 1);
|
|
238
|
-
// 防 OOM:巨大行号不进行无边界预分配,仅计入总量
|
|
239
208
|
if (rNum >= MAX_PARSE_ROWS)
|
|
240
209
|
continue;
|
|
241
210
|
while (rows.length <= rNum)
|
|
@@ -249,7 +218,6 @@ function parseSheet(xml, shared) {
|
|
|
249
218
|
if (!pos || pos.col < 0)
|
|
250
219
|
continue;
|
|
251
220
|
maxColSeen = Math.max(maxColSeen, pos.col + 1);
|
|
252
|
-
// 防 OOM:巨大列号不进行无边界空字符串 push
|
|
253
221
|
if (pos.col >= MAX_PARSE_COLS)
|
|
254
222
|
continue;
|
|
255
223
|
const inner = c[2];
|
|
@@ -280,7 +248,6 @@ function parseSheet(xml, shared) {
|
|
|
280
248
|
nCols: Math.max(Math.max(0, ...rows.map((r) => r.length)), maxColSeen),
|
|
281
249
|
};
|
|
282
250
|
}
|
|
283
|
-
/** xlsx/xlsm → sheet 数组(名按 workbook 还原,取不到时回落 sheetN)。 */
|
|
284
251
|
export function parseXlsxSheets(buf) {
|
|
285
252
|
const probe = unzipFiles(buf, ["xl/workbook.xml", "xl/_rels/workbook.xml.rels"]);
|
|
286
253
|
const wbXml = probe.get("xl/workbook.xml")?.toString("utf8") ?? "";
|
|
@@ -330,7 +297,6 @@ export function parseXlsxSheets(buf) {
|
|
|
330
297
|
const mdCell = (s) => String(s ?? "")
|
|
331
298
|
.replace(/\|/g, "\\|")
|
|
332
299
|
.replace(/\r?\n/g, " ");
|
|
333
|
-
/** 列号 → Excel 式列名(0→A,25→Z,26→AA)。 */
|
|
334
300
|
function colName(i) {
|
|
335
301
|
let s = "";
|
|
336
302
|
let n = i;
|
|
@@ -340,7 +306,6 @@ function colName(i) {
|
|
|
340
306
|
} while (n >= 0);
|
|
341
307
|
return s;
|
|
342
308
|
}
|
|
343
|
-
/* ---------------- PPTX 幻灯片解析 ---------------- */
|
|
344
309
|
export const PPTX_MAX_SLIDES = 500;
|
|
345
310
|
function extractShapePlainText(spXml) {
|
|
346
311
|
const parts = [];
|
|
@@ -461,7 +426,6 @@ function slideToMarkdown(slide) {
|
|
|
461
426
|
}
|
|
462
427
|
return `${head}\n\n${bodyParts.join("\n\n")}`;
|
|
463
428
|
}
|
|
464
|
-
/** pptx/pptm/ppsx/potx → 幻灯片数组。 */
|
|
465
429
|
export function parsePptxSlides(buf) {
|
|
466
430
|
const allEntries = new Set(listZipEntries(buf));
|
|
467
431
|
const probeTargets = ["ppt/presentation.xml", "ppt/_rels/presentation.xml.rels"].filter((n) => allEntries.has(n));
|
|
@@ -488,7 +452,6 @@ export function parsePptxSlides(buf) {
|
|
|
488
452
|
.map((rid) => relTarget.get(rid))
|
|
489
453
|
.filter((t) => Boolean(t))
|
|
490
454
|
.map((t) => (t.startsWith("ppt/") ? t : `ppt/${t}`));
|
|
491
|
-
// Fallback 1: presentation.xml.rels 中声明的 slide 关系
|
|
492
455
|
if (slideTargets.length === 0) {
|
|
493
456
|
for (const m of relsXml.matchAll(/<Relationship\b[^>]*>/gi)) {
|
|
494
457
|
const type = /\bType=["']([^"']+)["']/i.exec(m[0])?.[1] ?? "";
|
|
@@ -503,7 +466,6 @@ export function parsePptxSlides(buf) {
|
|
|
503
466
|
}
|
|
504
467
|
slideTargets.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }));
|
|
505
468
|
}
|
|
506
|
-
// Fallback 2: 中央目录扫描 ppt/slides/slideN.xml
|
|
507
469
|
if (slideTargets.length === 0) {
|
|
508
470
|
slideTargets = Array.from(allEntries)
|
|
509
471
|
.filter((name) => /^ppt\/slides\/slide\d+\.xml$/i.test(name))
|
|
@@ -513,7 +475,6 @@ export function parsePptxSlides(buf) {
|
|
|
513
475
|
throw new Error("PPTX 文件中未找到幻灯片内容");
|
|
514
476
|
}
|
|
515
477
|
const cappedSlideTargets = slideTargets.slice(0, PPTX_MAX_SLIDES);
|
|
516
|
-
// 扫描各幻灯片的 .rels 关系(查找图片与演讲者备注)
|
|
517
478
|
const slideRelsMap = new Map();
|
|
518
479
|
const slideToNotes = new Map();
|
|
519
480
|
const slideRelsToFetch = [];
|
|
@@ -569,7 +530,6 @@ export function parsePptxSlides(buf) {
|
|
|
569
530
|
let title = "";
|
|
570
531
|
let titleShapeXml = null;
|
|
571
532
|
let subtitle;
|
|
572
|
-
// 查找标题与副标题占位符
|
|
573
533
|
for (const spMatch of slideXml.matchAll(/<p:sp\b[\s\S]*?<\/p:sp>/g)) {
|
|
574
534
|
const sp = spMatch[0];
|
|
575
535
|
if (!title && /<p:ph\b[^>]*\btype=["'](?:title|ctrTitle)["']/i.test(sp)) {
|
|
@@ -620,7 +580,6 @@ export function parsePptxSlides(buf) {
|
|
|
620
580
|
const tables = [];
|
|
621
581
|
const images = [];
|
|
622
582
|
const rMap = slideRelsMap.get(target);
|
|
623
|
-
// 提取图片(<p:pic>)
|
|
624
583
|
for (const picMatch of slideXml.matchAll(/<p:pic\b[\s\S]*?<\/p:pic>/gi)) {
|
|
625
584
|
const pic = picMatch[0];
|
|
626
585
|
const rEmbed = /<a:blip\b[^>]*r:embed=["']([^"']+)["']/i.exec(pic)?.[1];
|
|
@@ -634,7 +593,6 @@ export function parsePptxSlides(buf) {
|
|
|
634
593
|
}
|
|
635
594
|
}
|
|
636
595
|
}
|
|
637
|
-
// 提取背景色
|
|
638
596
|
let bg;
|
|
639
597
|
const bgPrMatch = /<p:bgPr\b[\s\S]*?<a:srgbClr\b[^>]*val=["']([0-9a-fA-F]{6})["']/i.exec(slideXml);
|
|
640
598
|
if (bgPrMatch) {
|
|
@@ -705,10 +663,6 @@ export function parsePptxSlides(buf) {
|
|
|
705
663
|
}
|
|
706
664
|
return slides;
|
|
707
665
|
}
|
|
708
|
-
/**
|
|
709
|
-
* 表头固定用 A/B/C…(与 Excel 列标一致),而不拿第一行数据冒充表头——
|
|
710
|
-
* 很多表的第一行是通知/标题文字,染成紫色表头又怪又误导。
|
|
711
|
-
*/
|
|
712
666
|
function sheetToMarkdown(sheet) {
|
|
713
667
|
const head = `## ${sheet.name}(${sheet.nRows} 行 × ${sheet.nCols} 列${sheet.truncated ? ",只看前一部分" : ""})`;
|
|
714
668
|
if (sheet.rows.length === 0)
|
|
@@ -724,10 +678,6 @@ function sheetToMarkdown(sheet) {
|
|
|
724
678
|
lines.splice(1, 0, `| ${Array(width).fill("---").join(" | ")} |`);
|
|
725
679
|
return [head, "", ...lines].join("\n");
|
|
726
680
|
}
|
|
727
|
-
/**
|
|
728
|
-
* Office 文件 → Markdown 预览文本(前端 FilePreview 按 Markdown 渲染)。
|
|
729
|
-
* 非 office 扩展名返回 null;zip 损坏/加密等抛错(调用方回落旧的二进制嗅探)。
|
|
730
|
-
*/
|
|
731
681
|
export function extractOfficeText(filename, buf) {
|
|
732
682
|
const dot = String(filename ?? "")
|
|
733
683
|
.toLowerCase()
|
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* orphan-manager — 残留会话认领与同工作区比对工具。
|
|
3
|
-
*
|
|
4
|
-
* 负责:
|
|
5
|
-
* - pickAdoptableOrphan: 选一个断开连接的残留会话给新标签页认领(纯函数)
|
|
6
|
-
* - sameCwd: 跨平台工作区路径一致性比对(纯函数)
|
|
7
|
-
*
|
|
8
|
-
* 从 agent-service.ts 抽出为独立模块。
|
|
9
|
-
*/
|
|
10
1
|
import { normalizePathKey } from "./client-state.js";
|
|
11
|
-
/**
|
|
12
|
-
* 选一个断开的残留会话给新标签认领(纯函数):
|
|
13
|
-
* - 还有别的在线浏览器(非伪客户端且 live)→ 不认领(新标签是第二块屏,
|
|
14
|
-
* issue #10 的隔离必须保留,跑着的对话继续走 elsewhere 只读感知)。
|
|
15
|
-
* - 否则在断开 + 非伪 + 有内容的候选中按(streaming 多 → 最近活跃)取最优;
|
|
16
|
-
* 没有返回 null(调用方走正常新建流程)。
|
|
17
|
-
*/
|
|
18
2
|
export function pickAdoptableOrphan(cands) {
|
|
19
3
|
if (cands.some((c) => !c.pseudo && c.live))
|
|
20
4
|
return null;
|
|
@@ -28,8 +12,6 @@ export function pickAdoptableOrphan(cands) {
|
|
|
28
12
|
}
|
|
29
13
|
return best?.id ?? null;
|
|
30
14
|
}
|
|
31
|
-
/** 同项目判定(纯函数):调度视口回退与 id 唤醒的 cwd 护栏用。
|
|
32
|
-
* Windows 大小写/分隔符差异归一,空串永不相等。 */
|
|
33
15
|
export function sameCwd(a, b) {
|
|
34
16
|
const x = String(a ?? "").trim();
|
|
35
17
|
const y = String(b ?? "").trim();
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
/** Bound native shell output draining without changing shell selection (issue #794). */
|
|
2
1
|
import { registerHooks } from "node:module";
|
|
3
2
|
export const SENTINEL = "// pi-web-ui #794: bounded shell lifecycle v1";
|
|
4
|
-
// Kept as JavaScript source because this compatibility patch runs inside the SDK.
|
|
5
|
-
// The SDK still owns shell discovery, environment, process groups and tree killing.
|
|
6
3
|
export const SHELL_WAIT_SOURCE = `function waitForShellLifecycle(child, { onData, signal, timeout, timeoutMs, kill }) {
|
|
7
4
|
return new Promise((resolve, reject) => {
|
|
8
5
|
let settled = false;
|
|
@@ -106,7 +103,6 @@ export function patchBashProcessSource(source) {
|
|
|
106
103
|
.replace(OLD_LIFECYCLE, REPLACEMENT);
|
|
107
104
|
return { code: `${code}\n${SENTINEL}\n${SHELL_WAIT_SOURCE}\n`, status: "patched" };
|
|
108
105
|
}
|
|
109
|
-
/* SDK sources are transformed in memory before compilation, never on disk. */
|
|
110
106
|
export function registerBashProcessPatch() {
|
|
111
107
|
registerHooks({
|
|
112
108
|
load(url, context, nextLoad) {
|