pop-agent 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +620 -2
- package/README.zh.md +622 -0
- package/dist/server/approval/read-only.js +107 -0
- package/dist/server/approval/rules.js +73 -0
- package/dist/server/approval/scope.js +164 -0
- package/dist/server/approval/unattended.js +25 -0
- package/dist/server/asr/bridge.js +244 -0
- package/dist/server/asr/install.js +188 -0
- package/dist/server/asr/paths.js +101 -0
- package/dist/server/asr/routes.js +62 -0
- package/dist/server/brand.js +2 -0
- package/dist/server/cli-config.js +65 -0
- package/dist/server/cli-info.js +169 -0
- package/dist/server/cli.js +602 -0
- package/dist/server/computer/apps.js +152 -0
- package/dist/server/computer/cli.js +322 -0
- package/dist/server/computer/framing.js +36 -0
- package/dist/server/computer/helper-client.js +268 -0
- package/dist/server/computer/paths.js +114 -0
- package/dist/server/computer/routes.js +118 -0
- package/dist/server/computer/settings.js +169 -0
- package/dist/server/computer/skill.js +131 -0
- package/dist/server/computer/status.js +134 -0
- package/dist/server/cron/agent-run.js +121 -0
- package/dist/server/cron/index.js +539 -0
- package/dist/server/cron/tool.js +155 -0
- package/dist/server/engine/builtin.js +180 -0
- package/dist/server/engine/catalog-probe.js +34 -0
- package/dist/server/engine/catalog.js +8 -0
- package/dist/server/engine/claude-map.js +297 -0
- package/dist/server/engine/claude-sessions.js +581 -0
- package/dist/server/engine/claude-transport.js +75 -0
- package/dist/server/engine/claude.js +414 -0
- package/dist/server/engine/cli-version.js +119 -0
- package/dist/server/engine/codex-approvals.js +45 -0
- package/dist/server/engine/codex-map.js +298 -0
- package/dist/server/engine/codex-sessions.js +159 -0
- package/dist/server/engine/codex-subagents.js +349 -0
- package/dist/server/engine/codex-transport.js +49 -0
- package/dist/server/engine/codex.js +530 -0
- package/dist/server/engine/dsh-history.js +195 -0
- package/dist/server/engine/dsh-log.js +256 -0
- package/dist/server/engine/dsh-map.js +223 -0
- package/dist/server/engine/dsh-prompt-patch.js +48 -0
- package/dist/server/engine/dsh-sessions.js +206 -0
- package/dist/server/engine/dsh-transport.js +37 -0
- package/dist/server/engine/dsh.js +329 -0
- package/dist/server/engine/engine-install.js +182 -0
- package/dist/server/engine/engine-routes.js +54 -0
- package/dist/server/engine/engine-specs.js +65 -0
- package/dist/server/engine/engine-versions.js +41 -0
- package/dist/server/engine/export-html-tree-patch.js +89 -0
- package/dist/server/engine/fake.js +263 -0
- package/dist/server/engine/jsonrpc-stdio.js +275 -0
- package/dist/server/engine/model-registry-reload.js +115 -0
- package/dist/server/engine/narrate-guidance.js +25 -0
- package/dist/server/engine/opencode-map.js +500 -0
- package/dist/server/engine/opencode-projects.js +61 -0
- package/dist/server/engine/opencode-sessions.js +201 -0
- package/dist/server/engine/opencode-transport.js +48 -0
- package/dist/server/engine/opencode.js +434 -0
- package/dist/server/engine/pi-appearance-tool.js +101 -0
- package/dist/server/engine/pi-canvas-tool.js +181 -0
- package/dist/server/engine/pi-cron-tool.js +196 -0
- package/dist/server/engine/pi-events.js +153 -0
- package/dist/server/engine/pi-plugins.js +312 -0
- package/dist/server/engine/pi-rename.js +14 -0
- package/dist/server/engine/pi-retry.js +124 -0
- package/dist/server/engine/pi-sdk.js +1272 -0
- package/dist/server/engine/pi-session-model.js +23 -0
- package/dist/server/engine/pi-stop.js +28 -0
- package/dist/server/engine/pi-subagent-tool.js +188 -0
- package/dist/server/engine/pi-subagents.js +445 -0
- package/dist/server/engine/pi-thinking.js +34 -0
- package/dist/server/engine/pi-transcript.js +247 -0
- package/dist/server/engine/pi-turn-outcome.js +25 -0
- package/dist/server/engine/pi-version.js +11 -0
- package/dist/server/engine/port.js +1 -0
- package/dist/server/engine/registry.js +61 -0
- package/dist/server/engine/resource-signature.js +55 -0
- package/dist/server/engine/scratch.js +13 -0
- package/dist/server/engine/subagent-guidance.js +22 -0
- package/dist/server/engine/suggestion-guidance.js +24 -0
- package/dist/server/engine/switchable.js +22 -0
- package/dist/server/engine/wiring.js +225 -0
- package/dist/server/files/content-search.js +187 -0
- package/dist/server/files/dir-routes.js +104 -0
- package/dist/server/files/file-search.js +64 -0
- package/dist/server/files/file-service.js +286 -0
- package/dist/server/files/files-routes.js +278 -0
- package/dist/server/files/git-info.js +428 -0
- package/dist/server/files/path-resolve.js +176 -0
- package/dist/server/files/pick-path-routes.js +162 -0
- package/dist/server/http/auth-routes.js +454 -0
- package/dist/server/http/auth.js +306 -0
- package/dist/server/http/aux-routes.js +98 -0
- package/dist/server/http/client-log-routes.js +49 -0
- package/dist/server/http/compress.js +102 -0
- package/dist/server/http/file-headers.js +75 -0
- package/dist/server/http/health-and-static.js +46 -0
- package/dist/server/http/live-routes.js +116 -0
- package/dist/server/http/login-activity.js +76 -0
- package/dist/server/http/login-guard.js +185 -0
- package/dist/server/http/login-page.js +347 -0
- package/dist/server/http/password-store.js +88 -0
- package/dist/server/http/voice-settings-routes.js +30 -0
- package/dist/server/http/ws-routes.js +141 -0
- package/dist/server/index.js +1085 -0
- package/dist/server/markers/actions.js +281 -0
- package/dist/server/mcp/codex-mcp-store.js +190 -0
- package/dist/server/mcp/json-mcp-store.js +276 -0
- package/dist/server/mcp/mcp-auth.js +194 -0
- package/dist/server/mcp/mcp-command.js +137 -0
- package/dist/server/mcp/mcp-engine-shared.js +112 -0
- package/dist/server/mcp/mcp-import.js +289 -0
- package/dist/server/mcp/mcp-market-sources.js +192 -0
- package/dist/server/mcp/mcp-market-types.js +5 -0
- package/dist/server/mcp/mcp-market.js +174 -0
- package/dist/server/mcp/mcp-probe.js +170 -0
- package/dist/server/mcp/mcp-routes.js +71 -0
- package/dist/server/mcp/mcp-store.js +286 -0
- package/dist/server/mcp/none-mcp-store.js +27 -0
- package/dist/server/mcp/pi-mcp-config.js +308 -0
- package/dist/server/pi-gate.js +106 -0
- package/dist/server/plugins/engine-plugin-stores.js +265 -0
- package/dist/server/plugins/plugin-routes.js +22 -0
- package/dist/server/protocol-parse.js +533 -0
- package/dist/server/protocol-settings.js +1 -0
- package/dist/server/protocol.js +8 -0
- package/dist/server/providers/catalog-store.js +89 -0
- package/dist/server/providers/catalog-writes.js +199 -0
- package/dist/server/providers/catalog.js +77 -0
- package/dist/server/providers/codex-models.js +96 -0
- package/dist/server/providers/codex-test.js +124 -0
- package/dist/server/providers/enabled-models.js +110 -0
- package/dist/server/providers/import-models.js +69 -0
- package/dist/server/providers/import-routes.js +266 -0
- package/dist/server/providers/model-kind.js +35 -0
- package/dist/server/providers/model-test.js +113 -0
- package/dist/server/providers/one-shot.js +218 -0
- package/dist/server/providers/probe-routes.js +26 -0
- package/dist/server/providers/probe.js +84 -0
- package/dist/server/providers/provider-handlers.js +240 -0
- package/dist/server/providers/provider-pool.js +63 -0
- package/dist/server/providers/provider-store.js +502 -0
- package/dist/server/providers/request-headers.js +7 -0
- package/dist/server/providers/subscription-routes.js +183 -0
- package/dist/server/providers/validate.js +249 -0
- package/dist/server/push/push-routes.js +171 -0
- package/dist/server/push/push.js +239 -0
- package/dist/server/push/vapid-config.js +179 -0
- package/dist/server/session/appearance.js +79 -0
- package/dist/server/session/approval-bridge.js +119 -0
- package/dist/server/session/attachment-resolve.js +21 -0
- package/dist/server/session/canvas-artifacts.js +108 -0
- package/dist/server/session/canvas-store.js +137 -0
- package/dist/server/session/canvas-suggest.js +70 -0
- package/dist/server/session/canvas.js +323 -0
- package/dist/server/session/client-view.js +82 -0
- package/dist/server/session/close-ephemeral.js +23 -0
- package/dist/server/session/conversation-create.js +87 -0
- package/dist/server/session/cron-prompt-routes.js +25 -0
- package/dist/server/session/cron-prompt.js +59 -0
- package/dist/server/session/delete-session.js +125 -0
- package/dist/server/session/engine-switch.js +118 -0
- package/dist/server/session/fork-session.js +38 -0
- package/dist/server/session/lock.js +82 -0
- package/dist/server/session/model-controller.js +149 -0
- package/dist/server/session/move-session.js +40 -0
- package/dist/server/session/notices.js +33 -0
- package/dist/server/session/one-shot.js +95 -0
- package/dist/server/session/persist-ephemeral.js +48 -0
- package/dist/server/session/pi-opener.js +163 -0
- package/dist/server/session/pi-refresh.js +51 -0
- package/dist/server/session/pi-sessions-provider.js +41 -0
- package/dist/server/session/pi-sessions.js +431 -0
- package/dist/server/session/refresh-actions.js +58 -0
- package/dist/server/session/rename-session.js +23 -0
- package/dist/server/session/runtime-services.js +37 -0
- package/dist/server/session/runtime-types.js +1 -0
- package/dist/server/session/runtime.js +844 -0
- package/dist/server/session/session-stats.js +91 -0
- package/dist/server/session/settings.js +526 -0
- package/dist/server/session/snapshot-for.js +9 -0
- package/dist/server/session/stats-refresher.js +55 -0
- package/dist/server/session/subagents.js +119 -0
- package/dist/server/session/suggest-title.js +33 -0
- package/dist/server/session/switch-conversation.js +111 -0
- package/dist/server/session/template-prompt-routes.js +26 -0
- package/dist/server/session/template-prompt.js +110 -0
- package/dist/server/session/throttle.js +14 -0
- package/dist/server/session/title-prompt.js +128 -0
- package/dist/server/session/turn-events.js +198 -0
- package/dist/server/session/turn-finish.js +97 -0
- package/dist/server/session/turn-markers.js +31 -0
- package/dist/server/session/turn-queue.js +264 -0
- package/dist/server/session/turn-send.js +138 -0
- package/dist/server/session/turn-watchdog.js +77 -0
- package/dist/server/session/voice-settings.js +39 -0
- package/dist/server/sessions/session-routes.js +97 -0
- package/dist/server/skills/skill-install.js +184 -0
- package/dist/server/skills/skill-routes.js +134 -0
- package/dist/server/skills/skill-store.js +163 -0
- package/dist/server/skills/skillhub.js +213 -0
- package/dist/server/skills/zip.js +121 -0
- package/dist/server/snapshot/fan-out.js +12 -0
- package/dist/server/snapshot/messages.js +117 -0
- package/dist/server/snapshot/sender.js +53 -0
- package/dist/server/snapshot/state.js +274 -0
- package/dist/server/subagents/profile-store.js +305 -0
- package/dist/server/terminal/terminal-routes.js +223 -0
- package/dist/server/terminal/terminal-session.js +197 -0
- package/dist/server/tts/edge-worker-source.js +48 -0
- package/dist/server/tts/edge.js +143 -0
- package/dist/server/tts/local-voices.js +35 -0
- package/dist/server/tts/local.js +192 -0
- package/dist/server/tts/routes.js +56 -0
- package/dist/server/tts/service.js +97 -0
- package/dist/server/tts/types.js +7 -0
- package/dist/server/tts/voices.js +21 -0
- package/dist/server/update-check.js +147 -0
- package/dist/server/update-prompt.js +131 -0
- package/dist/server/uploads/upload-routes.js +67 -0
- package/dist/server/uploads/upload-store.js +113 -0
- package/dist/server/util/atomic-write.js +18 -0
- package/dist/server/util/data-dir.js +36 -0
- package/dist/server/util/desktop.js +216 -0
- package/dist/server/util/env.js +202 -0
- package/dist/server/util/file-mode.js +57 -0
- package/dist/server/util/ids.js +28 -0
- package/dist/server/util/json-file.js +38 -0
- package/dist/server/util/log-file.js +67 -0
- package/dist/server/util/log.js +52 -0
- package/dist/server/util/origin.js +117 -0
- package/dist/server/util/paths.js +187 -0
- package/dist/server/util/pricing-index.js +117 -0
- package/dist/server/util/pricing.js +214 -0
- package/dist/server/util/prune-pty.js +72 -0
- package/dist/server/util/spawn-cli.js +147 -0
- package/dist/server/util/startup.js +34 -0
- package/dist/server/util/upstream-version.js +177 -0
- package/dist/server/util/usage.js +19 -0
- package/dist/server/util/version.js +59 -0
- package/dist/server/web-proxy/picker-script.js +495 -0
- package/dist/server/web-proxy/proxy-routes.js +205 -0
- package/dist/server/web-proxy/proxy-url.js +76 -0
- package/dist/server/web-proxy/rewrite.js +98 -0
- package/dist/server/web-proxy/wrapper.js +92 -0
- package/dist/server/ws/handle-message.js +182 -0
- package/dist/server/ws/reply-frame.js +5 -0
- package/helper/asr/Info.plist +24 -0
- package/helper/asr/build.sh +59 -0
- package/helper/asr/main.swift +279 -0
- package/helper/asr/release/ASRBridge.zip +0 -0
- package/package.json +120 -5
- package/web/dist/apple-touch-icon-precomposed.png +0 -0
- package/web/dist/apple-touch-icon.png +0 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_abnfDiagram-WEYOIA3C-Cxf7yoVn.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_architectureDiagram-ZHVYKT53-BtmjGlGq.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_c4Diagram-XDPPPE54-CMVGVtIk.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_cynefinDiagram-WF24UDRP-7i0BPrM8.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_diagram-CBK3MWTC-G70wUrpC.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_diagram-ODIL2UCW-DG5xxpj4.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_diagram-PFBEJUXE-TVSrX2lz.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_diagram-TYUNFSNR-B5kj_W4w.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_ebnfDiagram-V4P3TTPT-CYDlMnIy.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_ishikawaDiagram-HPEHV2GE-Bwle1LQ4.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_mindmap-definition-6OY57UG3-Dp_r4po3.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_pegDiagram-ECIUJNBX-D0XH8M0y.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_railroadDiagram-Y72NRBL7-BYBIBrHp.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_swimlanes-B3ENRKFQ-Bj4-4hK8.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_swimlanesDiagram-AYQRV4AK-Cr0JbDyV.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_usecaseDiagram-WPOLBNNX-BN92OiEn.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_vennDiagram-Q3Y3IDCW--PhbzdU_.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_wardleyDiagram-IVAIDKWA-nObiqZ0S.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_katex_katex-Zojedrce.js +1 -0
- package/web/dist/assets/approval.en-BFhMPNWP.mp3 +0 -0
- package/web/dist/assets/approval.zh-DWqP6Pcu.mp3 +0 -0
- package/web/dist/assets/arc-Dn7mfTUL.js +1 -0
- package/web/dist/assets/architecture-WOLXFQ4H-DwHKr8GA.js +1 -0
- package/web/dist/assets/array-BifhSqXX.js +1 -0
- package/web/dist/assets/blockDiagram-RJAE7QA3-CA2AOM6-.js +140 -0
- package/web/dist/assets/channel-PVcvMEH-.js +1 -0
- package/web/dist/assets/chunk-2Q5K7J3B-C1jixKkw.js +1 -0
- package/web/dist/assets/chunk-55XCU76K-DlITu1ZH.js +1 -0
- package/web/dist/assets/chunk-5VM5RSS4-ZNzvKenW.js +15 -0
- package/web/dist/assets/chunk-7S6XSTFO-DzX1XF3_.js +2 -0
- package/web/dist/assets/chunk-AQDTSKZB-BdEDejS-.js +72 -0
- package/web/dist/assets/chunk-DSNLSHJZ-Chj2PD0m.js +129 -0
- package/web/dist/assets/chunk-DUW6YSOI-Dgx8z5s3.js +1 -0
- package/web/dist/assets/chunk-HNE4Q36P-V3jylrEv.js +1 -0
- package/web/dist/assets/chunk-J5ZVWO5B-oDCd-gWO.js +1 -0
- package/web/dist/assets/chunk-JWPE2WC7-DVXcaiue.js +1 -0
- package/web/dist/assets/chunk-NGNAAXSQ-DuHRe0y2.js +136 -0
- package/web/dist/assets/chunk-VQ5W62QI-BiWZxVe5.js +1 -0
- package/web/dist/assets/chunk-WQQL4CDK-BtyaHLI7.js +10 -0
- package/web/dist/assets/chunk-Y2CYZVJY-DsF7k-Jl.js +1 -0
- package/web/dist/assets/chunk-ZAUX2LTX-DS3wpSTy.js +62 -0
- package/web/dist/assets/chunk-ZCHMQSOR-at82jgqF.js +2 -0
- package/web/dist/assets/classDiagram-v2-4MYWR3UA-CTgR1e3M.js +217 -0
- package/web/dist/assets/cose-bilkent-JH36ORCC-DW-hnOsq.js +1 -0
- package/web/dist/assets/cynefin-EF2NZ3EQ-Pg-c-yVE.js +1 -0
- package/web/dist/assets/dagre-NK4GIZVX-B0Ivt5Pn.js +4 -0
- package/web/dist/assets/diagram-I5XIIV2D-jE6SNlbX.js +24 -0
- package/web/dist/assets/diagram-RJA3I4VV-DQJNgW0u.js +41 -0
- package/web/dist/assets/done.en-s1tZOg6A.mp3 +0 -0
- package/web/dist/assets/done.zh-Dq-Os4NS.mp3 +0 -0
- package/web/dist/assets/elk-QONTBCTQ-KOJVoDyP.js +27 -0
- package/web/dist/assets/erDiagram-KYQIGQAA-DNUqfe2J.js +99 -0
- package/web/dist/assets/error.en-BGPHdZVi.mp3 +0 -0
- package/web/dist/assets/error.zh-DdFp64-u.mp3 +0 -0
- package/web/dist/assets/eventmodeling-K75KTNOO-DnxXCUaf.js +1 -0
- package/web/dist/assets/flowDiagram-IUGLLWBU-CRLc8ozS.js +213 -0
- package/web/dist/assets/ganttDiagram-R7GPNTJY-DDLhSPGT.js +292 -0
- package/web/dist/assets/gitGraph-VSP46ZUC-BjfoZeXP.js +1 -0
- package/web/dist/assets/gitGraphDiagram-PDYL7XHY-6uZGw3lU.js +106 -0
- package/web/dist/assets/graphlib-DS17s2tU.js +1 -0
- package/web/dist/assets/highlight-DMv0JmTA.js +5 -0
- package/web/dist/assets/i18n-en-H5OrSHR5.js +1 -0
- package/web/dist/assets/index-CQ1VhLwx.js +79 -0
- package/web/dist/assets/index-DB6jJFLf.css +1 -0
- package/web/dist/assets/info-OHQRW6UA-BMDHcIvy.js +1 -0
- package/web/dist/assets/infoDiagram-MVDRKAX5-C2d1Uwhn.js +2 -0
- package/web/dist/assets/init-C-OQMol4.js +1 -0
- package/web/dist/assets/journeyDiagram-BOSHW7O7-BAE_nPCd.js +139 -0
- package/web/dist/assets/kanban-definition-FNSA4HC5-C2Z3ejvx.js +89 -0
- package/web/dist/assets/line-DHlXL-f4.js +1 -0
- package/web/dist/assets/linear-B363vzIx.js +1 -0
- package/web/dist/assets/markdown-Bcx45PNe.js +31 -0
- package/web/dist/assets/math-Dh0H2mym.js +1 -0
- package/web/dist/assets/mermaid-parser.core-CxD9DMnU.js +7 -0
- package/web/dist/assets/mermaid.core-CdVzG6_M.js +44 -0
- package/web/dist/assets/ordinal-BDEzSJ7C.js +1 -0
- package/web/dist/assets/packet-JDAUHWVQ-Cx23kBS5.js +1 -0
- package/web/dist/assets/path-fybaL0A-.js +1 -0
- package/web/dist/assets/pie-XZMESJXO-BDdtcaza.js +1 -0
- package/web/dist/assets/pieDiagram-GNMPY74T-DRqt_o8d.js +39 -0
- package/web/dist/assets/quadrantDiagram-D57K4MC3-Cq3-_E3T.js +7 -0
- package/web/dist/assets/radar-ABXABTNO-yJ_gp7Uq.js +1 -0
- package/web/dist/assets/railroad-I3PHUGI6-BFVVDyfL.js +1 -0
- package/web/dist/assets/railroad-abnf-LNEFI6M7-BhhpD6rl.js +1 -0
- package/web/dist/assets/railroad-ebnf-DWYD2UWJ-os_iV6TA.js +1 -0
- package/web/dist/assets/railroad-peg-JR7BVNR7-kex9mDBE.js +1 -0
- package/web/dist/assets/react-TO3cgmuO.js +9 -0
- package/web/dist/assets/requirementDiagram-EQYSW5RA-BnDM54-F.js +84 -0
- package/web/dist/assets/rolldown-runtime-COiEfhsA.js +1 -0
- package/web/dist/assets/sankeyDiagram-SY24JHO5-CMQmL2Tu.js +40 -0
- package/web/dist/assets/sequenceDiagram-BLEHNHQU-Dqhxl46T.js +169 -0
- package/web/dist/assets/sizeCapture-INFHLROL-3uHXrFqA.js +1 -0
- package/web/dist/assets/src-BWF7jMDv.js +1 -0
- package/web/dist/assets/stateDiagram-v2-A6IESKWZ-D1u1qdD7.js +291 -0
- package/web/dist/assets/steer.en-1RIP4K_0.mp3 +0 -0
- package/web/dist/assets/steer.zh-BCINYQs7.mp3 +0 -0
- package/web/dist/assets/stopped.en-CFPMi6oy.mp3 +0 -0
- package/web/dist/assets/stopped.zh-D2CUs-KZ.mp3 +0 -0
- package/web/dist/assets/timeline-definition-JXYKGLGB-DEjsSeWV.js +120 -0
- package/web/dist/assets/treeView-D4JQ5SDB-BXYISxgj.js +1 -0
- package/web/dist/assets/treemap-SAJKECNS-B6BJK2c0.js +1 -0
- package/web/dist/assets/wardley-7MLQ67FV-DsjBYeKs.js +1 -0
- package/web/dist/assets/xterm-BrP-ENHg.css +1 -0
- package/web/dist/assets/xterm-C3-Bm0Yw.js +16 -0
- package/web/dist/assets/xychartDiagram-4URNHDU4-CBbRqTE2.js +7 -0
- package/web/dist/favicon-32.png +0 -0
- package/web/dist/favicon.ico +0 -0
- package/web/dist/favicon.svg +25 -0
- package/web/dist/icons/apple-touch-icon-180.png +0 -0
- package/web/dist/icons/icon-1024.png +0 -0
- package/web/dist/icons/icon-192.png +0 -0
- package/web/dist/icons/icon-512.png +0 -0
- package/web/dist/icons/icon-maskable-512.png +0 -0
- package/web/dist/index.html +62 -0
- package/web/dist/manifest.webmanifest +17 -0
- package/web/dist/maskable.svg +25 -0
- package/web/dist/sw.js +40 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ADR-0047:`/web/p/…` 网页代理 —— 让「拒绝被嵌入」的站点也能在右侧面板里打开。
|
|
3
|
+
*
|
|
4
|
+
* 浏览器拒绝嵌入只看**文档**的响应头(`X-Frame-Options` / `CSP frame-ancestors`)。
|
|
5
|
+
* 我们把这个文档从服务端取回来、把那些头丢掉、用自己的源发出去,页面就能嵌了。
|
|
6
|
+
*
|
|
7
|
+
* 三条边界,写清楚免得以后被当成万能浏览器:
|
|
8
|
+
* 1. **只代理文档与 CSS**(HTML / CSS 要改写根相对地址);图片、字体、脚本等子资源
|
|
9
|
+
* 在镜像路径下由浏览器直连原站,不经过这里 —— 省带宽、也少一层故障点;
|
|
10
|
+
* 2. **不带 cookie 过去、也不把 Set-Cookie 带回来**:这里不做登录态隧道,
|
|
11
|
+
* 要看登录后的页面请用地址栏右边的 ⧉ 跳系统浏览器;
|
|
12
|
+
* 3. **不隐藏来源**:请求带的是浏览器 UA,日志里记一行目标地址 —— 这是本机自用工具,
|
|
13
|
+
* 不是给人做匿名代理的。服务端只监听 loopback 且整站有鉴权(ADR-0031)。
|
|
14
|
+
*/
|
|
15
|
+
import express, {} from "express";
|
|
16
|
+
import { brotliDecompressSync, gunzipSync, inflateSync } from "node:zlib";
|
|
17
|
+
import { MOBILE_PREFIX, proxyPathOf, PROXY_PREFIX, targetOfProxyPath } from "./proxy-url.js";
|
|
18
|
+
import { rewriteCss, rewriteHtml } from "./rewrite.js";
|
|
19
|
+
import { WRAPPER_PATH, wrapperHtml } from "./wrapper.js";
|
|
20
|
+
/** 上游响应最多收多大:一屏网页足够,太大说明是下载链接,那种应该走 ⧉ 跳出去 */
|
|
21
|
+
const MAX_BYTES = 12 * 1024 * 1024;
|
|
22
|
+
const BROWSER_UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36";
|
|
23
|
+
/**
|
|
24
|
+
* 手机模式的 UA(走 `/web/m/` 前缀时用它)。
|
|
25
|
+
*
|
|
26
|
+
* 为什么光收窄 iframe 不够:很多站点(百度是典型)按 **User-Agent** 决定发电脑版还是手机版,
|
|
27
|
+
* 跟视口宽度没关系 —— 只把 iframe 收到 390px,它们照样回电脑版 HTML/CSS,
|
|
28
|
+
* 「手机尺寸预览」看上去就是电脑排版。UA 一换,服务端才会给那一版。
|
|
29
|
+
* 用 iPhone 的 UA(而不是泛泛的 "Mobile"):不少站点对 iOS/Android 走不同的分发逻辑,
|
|
30
|
+
* 报一个具体机型比报一个模糊的手机 UA 更接近真机。
|
|
31
|
+
*/
|
|
32
|
+
const MOBILE_UA = "Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1";
|
|
33
|
+
export function registerWebProxyRoutes(app, deps) {
|
|
34
|
+
/**
|
|
35
|
+
* 同源外壳(见 `wrapper.ts`):`/web/w?u=<原网址>`。
|
|
36
|
+
*
|
|
37
|
+
* 它自己的 HTML 不做任何改写 —— 这是我们的文档,`u` 先过一遍 http(s) 校验再拼进 iframe。
|
|
38
|
+
*/
|
|
39
|
+
app.get(WRAPPER_PATH, (request, response) => {
|
|
40
|
+
const raw = typeof request.query.u === "string" ? request.query.u : "";
|
|
41
|
+
// `m=1`:手机模式。外壳里的那一帧要用手机前缀,否则页面拿到的还是电脑版
|
|
42
|
+
const mobile = request.query.m === "1";
|
|
43
|
+
const proxied = raw ? proxyPathOf(raw, { mobile }) : null;
|
|
44
|
+
if (proxied === null) {
|
|
45
|
+
response.status(400).type("text/plain").send("同源外壳需要一个 http / https 的 ?u= 原网址");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
response.setHeader("cache-control", "no-store");
|
|
49
|
+
response.setHeader("referrer-policy", "no-referrer");
|
|
50
|
+
response.setHeader("x-content-type-options", "nosniff");
|
|
51
|
+
response.type("text/html; charset=utf-8").send(wrapperHtml(proxied, raw));
|
|
52
|
+
});
|
|
53
|
+
// `express.raw` 收原始字节:表单(urlencoded / multipart)要原样转给上游,
|
|
54
|
+
// 交给 `express.json()` 只会得到空对象。挂在这一条路由上,不影响别处的 JSON 解析。
|
|
55
|
+
app.all(/^\/web\/[pm]\//, express.raw({ type: () => true, limit: "8mb" }), (request, response) => {
|
|
56
|
+
void handle(request, response, deps).catch((cause) => {
|
|
57
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
58
|
+
deps.log(`网页代理出错:${message}`);
|
|
59
|
+
if (!response.headersSent)
|
|
60
|
+
response.status(502).type("text/plain").send(`代理失败:${message}`);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/** `content-encoding` 是压缩的还要自己解:我们请求了 identity,但有的站点就是不理 */
|
|
65
|
+
function decodeBody(buffer, encoding) {
|
|
66
|
+
try {
|
|
67
|
+
if (!encoding || encoding === "identity")
|
|
68
|
+
return buffer;
|
|
69
|
+
if (encoding.includes("br"))
|
|
70
|
+
return brotliDecompressSync(buffer);
|
|
71
|
+
if (encoding.includes("gzip"))
|
|
72
|
+
return gunzipSync(buffer);
|
|
73
|
+
if (encoding.includes("deflate"))
|
|
74
|
+
return inflateSync(buffer);
|
|
75
|
+
return buffer;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// 解不开就当原始字节用:总比整页 500 强(表现是乱码,刷新一次通常就好)
|
|
79
|
+
return buffer;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function charsetOf(contentType) {
|
|
83
|
+
const match = /charset=([^;\s]+)/i.exec(contentType);
|
|
84
|
+
return match ? match[1].replace(/["']/g, "") : "utf-8";
|
|
85
|
+
}
|
|
86
|
+
function textOf(buffer, charset) {
|
|
87
|
+
try {
|
|
88
|
+
return new TextDecoder(charset).decode(buffer);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
// 未知 / 拼错的 charset(站点里很常见):退回 utf-8
|
|
92
|
+
return new TextDecoder("utf-8").decode(buffer);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async function handle(request, response, deps) {
|
|
96
|
+
const rawUrl = request.originalUrl;
|
|
97
|
+
const queryAt = rawUrl.indexOf("?");
|
|
98
|
+
const pathname = queryAt < 0 ? rawUrl : rawUrl.slice(0, queryAt);
|
|
99
|
+
const search = queryAt < 0 ? "" : rawUrl.slice(queryAt);
|
|
100
|
+
const target = targetOfProxyPath(pathname, search);
|
|
101
|
+
if (!target) {
|
|
102
|
+
response.status(400).type("text/plain").send("只支持 http / https 网页:/web/p/<http|https>/<host>/<path>");
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
/** 这一页走的是手机模式(`/web/m/`):上游要报手机 UA,改写出来的地址也要留在手机前缀下 */
|
|
106
|
+
const mobile = pathname.startsWith(MOBILE_PREFIX);
|
|
107
|
+
const method = request.method.toUpperCase();
|
|
108
|
+
if (method !== "GET" && method !== "HEAD" && method !== "POST") {
|
|
109
|
+
response.status(405).type("text/plain").send(`网页代理不支持 ${method}`);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const headers = {
|
|
113
|
+
// 伪装成普通浏览器:不少站点对非浏览器 UA 直接回 403 或极简页面
|
|
114
|
+
// (手机模式下换手机 UA —— 站点按它决定发哪一版,见 MOBILE_UA 上那段)
|
|
115
|
+
"user-agent": mobile ? MOBILE_UA : BROWSER_UA,
|
|
116
|
+
accept: String(request.headers.accept ?? "*/*"),
|
|
117
|
+
"accept-language": String(request.headers["accept-language"] ?? "zh-CN,zh;q=0.9,en;q=0.8"),
|
|
118
|
+
// 跟浏览器一样要压缩:改写的对象是**解压后**的明文(decodeBody 负责解)。
|
|
119
|
+
// 别改成 identity —— 未压缩的 HTML 动辄几百 KB,实测 github.com 会慢到 20 秒
|
|
120
|
+
"accept-encoding": "gzip, deflate, br",
|
|
121
|
+
};
|
|
122
|
+
if (typeof request.headers["content-type"] === "string")
|
|
123
|
+
headers["content-type"] = request.headers["content-type"];
|
|
124
|
+
const body = method === "POST" ? request.body : undefined;
|
|
125
|
+
let upstream;
|
|
126
|
+
try {
|
|
127
|
+
upstream = await fetch(target, {
|
|
128
|
+
method,
|
|
129
|
+
headers,
|
|
130
|
+
// 重定向自己处理:跟过去的话文档就不在「镜像路径」下了,页面里的相对地址会全部算错
|
|
131
|
+
redirect: "manual",
|
|
132
|
+
...(body && body.length > 0 ? { body: new Uint8Array(body) } : {}),
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
catch (cause) {
|
|
136
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
137
|
+
deps.log(`网页代理取不到 ${target}:${message}`);
|
|
138
|
+
response.status(502).type("text/plain").send(`打不开这个网址:${message}`);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
// 重定向:换成本地代理地址再 302,浏览器跟过去仍在镜像路径下
|
|
142
|
+
if (upstream.status >= 300 && upstream.status < 400) {
|
|
143
|
+
const location = upstream.headers.get("location");
|
|
144
|
+
if (location) {
|
|
145
|
+
const absolute = new URL(location, target).toString();
|
|
146
|
+
const proxied = proxyPathOf(absolute);
|
|
147
|
+
response.redirect(302, proxied ?? absolute);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const rawType = upstream.headers.get("content-type") ?? "application/octet-stream";
|
|
152
|
+
const mime = rawType.split(";")[0].trim().toLowerCase();
|
|
153
|
+
const declaredLength = Number(upstream.headers.get("content-length") ?? "0");
|
|
154
|
+
if (declaredLength > MAX_BYTES) {
|
|
155
|
+
response.status(413).type("text/plain").send("这个地址不是网页(文件太大):点地址栏右边的 ⧉ 用系统浏览器打开");
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
// `Buffer<ArrayBufferLike>` 与 `Buffer<ArrayBuffer>` 在 @types/node 里是两个类型:
|
|
159
|
+
// 显式标出来,后面 decodeBody 的返回值才赋得回去
|
|
160
|
+
let buffer = Buffer.from(await upstream.arrayBuffer());
|
|
161
|
+
if (buffer.length > MAX_BYTES) {
|
|
162
|
+
response.status(413).type("text/plain").send("这个地址不是网页(文件太大):点地址栏右边的 ⧉ 用系统浏览器打开");
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
buffer = decodeBody(buffer, (upstream.headers.get("content-encoding") ?? "").toLowerCase());
|
|
166
|
+
const scope = {
|
|
167
|
+
scheme: new URL(target).protocol.slice(0, -1),
|
|
168
|
+
host: new URL(target).host,
|
|
169
|
+
// 改写出来的地址要跟前缀一致:手机模式的页里点出来的下一页还得是手机模式
|
|
170
|
+
prefix: mobile ? MOBILE_PREFIX : PROXY_PREFIX,
|
|
171
|
+
};
|
|
172
|
+
// 我们自己说了算的头:不抄上游那些会挡住嵌入的(CSP / XFO / COEP),也不落缓存
|
|
173
|
+
response.setHeader("cache-control", "no-store");
|
|
174
|
+
response.setHeader("referrer-policy", "no-referrer");
|
|
175
|
+
response.setHeader("x-content-type-options", "nosniff");
|
|
176
|
+
response.status(upstream.status);
|
|
177
|
+
if (mime === "text/html" || mime === "application/xhtml+xml") {
|
|
178
|
+
const charset = charsetOf(rawType);
|
|
179
|
+
response.setHeader("content-type", `text/html; charset=${charset}`);
|
|
180
|
+
if (method === "HEAD") {
|
|
181
|
+
response.end();
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
response.end(rewriteHtml(textOf(buffer, charset), scope));
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (mime === "text/css") {
|
|
188
|
+
const charset = charsetOf(rawType);
|
|
189
|
+
response.setHeader("content-type", `text/css; charset=${charset}`);
|
|
190
|
+
if (method === "HEAD") {
|
|
191
|
+
response.end();
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
response.end(rewriteCss(textOf(buffer, charset), scope));
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
// 其它类型(图片 / 字体 / 脚本 / JSON):原样吐出去。我们请求了 identity,
|
|
198
|
+
// 所以这里的内容已经是明文,`content-encoding` 也就不能再声明
|
|
199
|
+
response.setHeader("content-type", rawType);
|
|
200
|
+
if (method === "HEAD") {
|
|
201
|
+
response.end();
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
response.end(buffer);
|
|
205
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ADR-0047:右侧「网页」页的代理地址规则(纯函数)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要代理:GitHub / 百度 / 知乎这类站点一律回 `X-Frame-Options: DENY` 或
|
|
5
|
+
* `CSP frame-ancestors`,浏览器直接拒嵌 —— 前端再怎么写都绕不过去,只能在**我们自己的源**
|
|
6
|
+
* 上把文档取回来再吐出去(响应头由我们说了算)。
|
|
7
|
+
*
|
|
8
|
+
* 地址形状刻意做成「镜像路径」而不是 `?url=` 查询:
|
|
9
|
+
*
|
|
10
|
+
* https://www.baidu.com/s?wd=x → /web/p/https/www.baidu.com/s?wd=x
|
|
11
|
+
*
|
|
12
|
+
* 这样页面里的**相对地址**(`img/a.png`、`./x.css`)由浏览器自己按目录规则解析,
|
|
13
|
+
* 天然落到代理前缀下,不需要我们解析整棵 HTML 依赖树。只有「根相对」(`/img/a.png`)
|
|
14
|
+
* 会跑到我们的根上,那一类由 `rewriteHtml` / `rewriteCss` 改写。
|
|
15
|
+
*
|
|
16
|
+
* 与 `web/src/url-bar.ts` 的 `proxyUrlOf` 是**同一个规则的两处实现**:
|
|
17
|
+
* 服务端要反解、客户端要正拼,两边必须保持一致。
|
|
18
|
+
*/
|
|
19
|
+
/** 代理前缀:不用 `/api` 是为了让页面里的相对地址解析得干净(不做 API 鉴权以外的事情) */
|
|
20
|
+
export const PROXY_PREFIX = "/web/p/";
|
|
21
|
+
/**
|
|
22
|
+
* **手机模式**的前缀:同一套镜像路径,只是换个前缀、上游请求换个手机 User-Agent。
|
|
23
|
+
*
|
|
24
|
+
* 为什么必须换前缀而不是加个查询参数:页面里的**相对地址**(`a/b`、`./c`)由浏览器按目录规则
|
|
25
|
+
* 解析,前缀一换,它们自动落在手机模式下 —— 不用在每个地址后面追一个参数;
|
|
26
|
+
* 而根相对的地址本来就要由 `rewriteHtml` / `rewriteCss` 改写,前缀跟着 scope 走就够了。
|
|
27
|
+
*
|
|
28
|
+
* 为什么需要换 UA:不少站点(百度就是)是按 **User-Agent** 决定发电脑版还是手机版的,
|
|
29
|
+
* 与视口宽度无关。只把 iframe 收窄到 390px,它们照样回电脑版 HTML/CSS ——
|
|
30
|
+
* 「手机尺寸预览」看到的就是电脑排版(用户 2026-11-03 的原话)。
|
|
31
|
+
*/
|
|
32
|
+
export const MOBILE_PREFIX = "/web/m/";
|
|
33
|
+
/** 两个前缀(解析时哪个都认;顺序无关) */
|
|
34
|
+
export const PROXY_PREFIXES = [PROXY_PREFIX, MOBILE_PREFIX];
|
|
35
|
+
const prefixOf = (mobile) => (mobile ? MOBILE_PREFIX : PROXY_PREFIX);
|
|
36
|
+
/** 目标地址 → 代理路径。非 http(s) 返回 null(调用方自己决定怎么报错) */
|
|
37
|
+
export function proxyPathOf(target, options = {}) {
|
|
38
|
+
let parsed;
|
|
39
|
+
try {
|
|
40
|
+
parsed = new URL(target);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:")
|
|
46
|
+
return null;
|
|
47
|
+
const scheme = parsed.protocol.slice(0, -1);
|
|
48
|
+
// host 里可能带端口(`localhost:3000`):路径段里冒号是合法的,不用转义
|
|
49
|
+
return `${prefixOf(options.mobile === true)}${scheme}/${parsed.host}${parsed.pathname}${parsed.search}`;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 代理路径 → 目标地址。
|
|
53
|
+
*
|
|
54
|
+
* 传进来的 `pathname` / `search` 是浏览器原样的(未解码):目标站自己的编码(`%20`、中文)
|
|
55
|
+
* 必须原封不动地带回去,解一次就会把 `%2F` 变成 `/`,那是另一条资源。
|
|
56
|
+
*/
|
|
57
|
+
export function targetOfProxyPath(pathname, search = "") {
|
|
58
|
+
const prefix = PROXY_PREFIXES.find((item) => pathname.startsWith(item));
|
|
59
|
+
if (prefix === undefined)
|
|
60
|
+
return null;
|
|
61
|
+
const rest = pathname.slice(prefix.length);
|
|
62
|
+
const slash = rest.indexOf("/");
|
|
63
|
+
// `https/<host>` 至少要有一个 `/` 把协议与主机分开
|
|
64
|
+
if (slash < 0)
|
|
65
|
+
return null;
|
|
66
|
+
const scheme = rest.slice(0, slash).toLowerCase();
|
|
67
|
+
const afterScheme = rest.slice(slash + 1);
|
|
68
|
+
const nextSlash = afterScheme.indexOf("/");
|
|
69
|
+
const host = nextSlash < 0 ? afterScheme : afterScheme.slice(0, nextSlash);
|
|
70
|
+
const path = nextSlash < 0 ? "/" : afterScheme.slice(nextSlash);
|
|
71
|
+
if (scheme !== "http" && scheme !== "https")
|
|
72
|
+
return null;
|
|
73
|
+
if (!host)
|
|
74
|
+
return null;
|
|
75
|
+
return `${scheme}://${host}${path}${search}`;
|
|
76
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ADR-0047:代理回来的文档要做两件事 —— 把「根相对」地址改写进代理前缀、拦下页面内的跳转。
|
|
3
|
+
*
|
|
4
|
+
* 为什么只改根相对的:地址形状是镜像路径(见 proxy-url.ts),相对地址浏览器自己会算对;
|
|
5
|
+
* 绝对地址(CDN、其它站)直连更省事也更快。真正会跑偏的只有以 `/` 开头的那些,
|
|
6
|
+
* 以及 `//cdn.example/x.js` 这种协议相对的(我们这边可能是 http,直接会 404)。
|
|
7
|
+
*
|
|
8
|
+
* 为什么不解析 DOM:这块只要能「把页面显示出来」,为此引一个 HTML 解析器不值得;
|
|
9
|
+
* 正则只碰 `src / href / action / poster` 这几个属性与 CSS 的 `url()`,改坏了最多是某张图裂开,
|
|
10
|
+
* 而不是整页空白。JS 里动态拼的地址改不到 —— 那类走点击拦截(`NAV_SCRIPT`)兜底。
|
|
11
|
+
*/
|
|
12
|
+
import { PICKER_SCRIPT } from "./picker-script.js";
|
|
13
|
+
import { PROXY_PREFIX } from "./proxy-url.js";
|
|
14
|
+
const PREFIX_OF = (scope) => `${scope.prefix ?? PROXY_PREFIX}${scope.scheme}/${scope.host}`;
|
|
15
|
+
/** 单个引用值要不要改写。返回原值表示「不动」 */
|
|
16
|
+
function toProxied(value, scope) {
|
|
17
|
+
const trimmed = value.trim();
|
|
18
|
+
if (!trimmed)
|
|
19
|
+
return value;
|
|
20
|
+
const prefix = PREFIX_OF(scope);
|
|
21
|
+
if (trimmed.startsWith(prefix))
|
|
22
|
+
return value; // 已经是代理地址(二次注入 / 页面自己拼的)
|
|
23
|
+
if (trimmed.startsWith("//"))
|
|
24
|
+
return `${scope.scheme}:${trimmed}`; // 协议相对 → 补协议直连
|
|
25
|
+
if (trimmed.startsWith("/"))
|
|
26
|
+
return `${prefix}${trimmed}`; // 根相对 → 必须走代理
|
|
27
|
+
// 绝对 `http(s)://`、`data:`、`javascript:`、`#锚点`、纯相对路径:一律原样
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
const ATTR = /(\s(?:src|href|action|poster|data-src|data-href)\s*=\s*)(["'])([^"']*)\2/gi;
|
|
31
|
+
/**
|
|
32
|
+
* 页面里所有页内跳转都改成走代理。
|
|
33
|
+
*
|
|
34
|
+
* 为什么不用 `<base>`:`<base>` 只能改相对地址的解析基准,改不了根相对与绝对地址;
|
|
35
|
+
* 而站点自己拼的绝对链接(搜索结果、分页)也必须代理,否则一点就撞回他们的 DENY。
|
|
36
|
+
* 这里在**捕获阶段**拦 click / submit,把目标换算成代理地址再交给浏览器。
|
|
37
|
+
*/
|
|
38
|
+
function navScript(prefix) {
|
|
39
|
+
return `<script>(function(){
|
|
40
|
+
var PREFIX=${JSON.stringify(prefix)};
|
|
41
|
+
function proxied(href){
|
|
42
|
+
if(!href) return null;
|
|
43
|
+
if(href.indexOf(PREFIX)===0) return href;
|
|
44
|
+
var abs;
|
|
45
|
+
try{ abs=new URL(href, location.href); }catch(e){ return null; }
|
|
46
|
+
if(abs.protocol!=="http:"&&abs.protocol!=="https:") return null;
|
|
47
|
+
return PREFIX+abs.protocol.slice(0,-1)+"/"+abs.host+abs.pathname+abs.search+abs.hash;
|
|
48
|
+
}
|
|
49
|
+
document.addEventListener("click",function(event){
|
|
50
|
+
/* 标注拾取中:点链接是「选这一块」,绝不能把页面导走(拾取脚本会自己画编辑框) */
|
|
51
|
+
if(window.__awPicking) return;
|
|
52
|
+
var node=event.target;
|
|
53
|
+
while(node&&node.nodeType===1&&node.tagName!=="A") node=node.parentElement;
|
|
54
|
+
if(!node||node.tagName!=="A") return;
|
|
55
|
+
if(node.target&&node.target!=="_self") return;
|
|
56
|
+
if(event.metaKey||event.ctrlKey||event.shiftKey||event.button!==0) return;
|
|
57
|
+
var next=proxied(node.getAttribute("href"));
|
|
58
|
+
if(!next) return;
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
location.href=next;
|
|
61
|
+
},true);
|
|
62
|
+
document.addEventListener("submit",function(event){
|
|
63
|
+
/* 拾取中也不要让页面自己提交走(表单通常就藏在按钮旁边) */
|
|
64
|
+
if(window.__awPicking){ event.preventDefault(); return; }
|
|
65
|
+
var form=event.target;
|
|
66
|
+
if(!form||form.tagName!=="FORM") return;
|
|
67
|
+
var next=proxied(form.getAttribute("action")||location.href);
|
|
68
|
+
if(next) form.setAttribute("action",next);
|
|
69
|
+
},true);
|
|
70
|
+
})()</script>`;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 塞进页面的两段脚本(按这一页的代理前缀生成):点击拦截 + 元素拾取。
|
|
74
|
+
* 前缀要跟着走,否则手机模式下页面里点出来的下一页会掉回普通模式(UA 一变,站点又发电脑版)。
|
|
75
|
+
*/
|
|
76
|
+
const injected = (scope) => navScript(scope.prefix ?? PROXY_PREFIX) + PICKER_SCRIPT;
|
|
77
|
+
/** HTML:属性改写 + 把两段脚本塞进 `<head>`(没有 head 就塞在文档最前面) */
|
|
78
|
+
export function rewriteHtml(html, scope) {
|
|
79
|
+
const scripts = injected(scope);
|
|
80
|
+
const rewritten = html.replace(ATTR, (whole, lead, quote, value) => {
|
|
81
|
+
const next = toProxied(value, scope);
|
|
82
|
+
return next === value ? whole : `${lead}${quote}${next}${quote}`;
|
|
83
|
+
});
|
|
84
|
+
const head = /<head[^>]*>/i.exec(rewritten);
|
|
85
|
+
if (head && head.index >= 0) {
|
|
86
|
+
const at = head.index + head[0].length;
|
|
87
|
+
return `${rewritten.slice(0, at)}${scripts}${rewritten.slice(at)}`;
|
|
88
|
+
}
|
|
89
|
+
return scripts + rewritten;
|
|
90
|
+
}
|
|
91
|
+
const CSS_URL = /url\(\s*(["']?)([^"')]+)\1\s*\)/gi;
|
|
92
|
+
/** CSS:只改 `url()` 里的根相对 / 协议相对(背景图、字体) */
|
|
93
|
+
export function rewriteCss(css, scope) {
|
|
94
|
+
return css.replace(CSS_URL, (whole, quote, value) => {
|
|
95
|
+
const next = toProxied(value, scope);
|
|
96
|
+
return next === value ? whole : `url(${quote}${next}${quote})`;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ADR-0047 的补充:**同源外壳**(`/web/w?u=<原网址>`)。
|
|
3
|
+
*
|
|
4
|
+
* 要解决的是一个具体故障:有些页面(映客的 banner 活动页就是)在启动阶段要读
|
|
5
|
+
* `document.cookie` 和 `window.parent.<桥属性>`。面板里的 iframe 是 `sandbox` 且**不带**
|
|
6
|
+
* `allow-same-origin` —— 那是个不透明源,两样都直接抛 SecurityError,页面还没挂载就死了,
|
|
7
|
+
* 只剩它自己的深色底(用户看到的就是「打开一个网页是黑屏」)。
|
|
8
|
+
*
|
|
9
|
+
* 那条 `allow-same-origin` 不敢直接加:代理把别人的页面发在**我们自己的源**上,
|
|
10
|
+
* 给了它就等于把工作台的 localStorage / 会话 cookie / RPC 交给远端 JS。
|
|
11
|
+
*
|
|
12
|
+
* 所以插一层壳:
|
|
13
|
+
*
|
|
14
|
+
* 工作台 (http://127.0.0.1:port) ← 我们的源,页面碰不到
|
|
15
|
+
* └─ 外壳 (http://localhost:port/web/w) ← 这一层是「兄弟回环主机」,与页面同源
|
|
16
|
+
* └─ 页面 (/web/p/https/…) ← 真实源是外壳那个,它读 cookie / parent 都成立
|
|
17
|
+
*
|
|
18
|
+
* 三件事因此同时成立:
|
|
19
|
+
* 1. 页面有一个**真实**的源(cookie / localStorage 不再抛错);
|
|
20
|
+
* 2. 那个源**不是**工作台的源(兄弟主机名,cookie 罐与 origin 都不同)——
|
|
21
|
+
* 读不到工作台的存储,也调不到工作台的接口;
|
|
22
|
+
* 3. 页面读 `window.parent` 拿到的就是同一个源的外壳,不再抛错。
|
|
23
|
+
*
|
|
24
|
+
* 外壳还要**中继消息**:页面里的拾取脚本(`picker-script.ts`)往 `window.parent` 发消息,
|
|
25
|
+
* 现在那个 parent 是外壳而不是工作台 —— 不转一手,📍 标注就静悄悄地没反应了。
|
|
26
|
+
* 两个方向都转,只转带 `__aw: "picker"` 标记的。
|
|
27
|
+
*
|
|
28
|
+
* 只在「本机回环访问」时启用(见 `web/src/url-bar.ts` 的 `wrapperUrlOf`):远程访问没有兄弟
|
|
29
|
+
* 回环主机可用,那时照旧走原来的沙箱(这类页面只能 ⧉ 打开)。
|
|
30
|
+
*/
|
|
31
|
+
/** 外壳路径。放在 `/web/` 下:它和代理是同一件事(让网页能在面板里跑),不掺进 API 路由 */
|
|
32
|
+
export const WRAPPER_PATH = "/web/w";
|
|
33
|
+
function escapeHtml(text) {
|
|
34
|
+
return text.replace(/[&<>"']/g, (ch) => {
|
|
35
|
+
const map = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" };
|
|
36
|
+
return map[ch] ?? ch;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 外壳页面。`proxiedPath` 由调用方用 `proxyPathOf` 算好(原网址先校验过是 http(s))。
|
|
41
|
+
*
|
|
42
|
+
* 顺序有讲究:中继脚本在 `<iframe>` **之前**就挂上监听 —— 页面(尤其缓存命中时)可能在
|
|
43
|
+
* iframe 元素插进 DOM 后立刻发 `ready`,监听晚一步就丢了那一条,标签和编号框的恢复会慢一拍。
|
|
44
|
+
*/
|
|
45
|
+
export function wrapperHtml(proxiedPath, title) {
|
|
46
|
+
return `<!doctype html>
|
|
47
|
+
<html lang="zh">
|
|
48
|
+
<head>
|
|
49
|
+
<meta charset="utf-8">
|
|
50
|
+
<meta name="referrer" content="no-referrer">
|
|
51
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
52
|
+
<title>${escapeHtml(title)}</title>
|
|
53
|
+
<style>
|
|
54
|
+
html, body { margin: 0; height: 100%; background: #fff; }
|
|
55
|
+
iframe { display: block; width: 100%; height: 100%; border: 0; }
|
|
56
|
+
</style>
|
|
57
|
+
<script>
|
|
58
|
+
(function () {
|
|
59
|
+
var MARK = "picker";
|
|
60
|
+
function post(target, message) {
|
|
61
|
+
if (!target) return;
|
|
62
|
+
try { target.postMessage(message, "*"); } catch (error) {}
|
|
63
|
+
}
|
|
64
|
+
/** 页面那一帧:按需取(监听先挂上,元素后到) */
|
|
65
|
+
function inner() {
|
|
66
|
+
var frame = document.getElementById("pop-page");
|
|
67
|
+
return frame ? frame.contentWindow : null;
|
|
68
|
+
}
|
|
69
|
+
/*
|
|
70
|
+
* 两个方向:工作台 → 页面(命令)、页面 → 工作台(ready / note / exit)。
|
|
71
|
+
* 只转带标记的消息:这一层对两边都是同源(页面能读到外壳的 DOM),
|
|
72
|
+
* 所以不能因为「谁发的」就转发任何东西 —— 只认协议里的那条标记。
|
|
73
|
+
*/
|
|
74
|
+
window.addEventListener("message", function (event) {
|
|
75
|
+
var data = event.data;
|
|
76
|
+
if (!data || data.__aw !== MARK) return;
|
|
77
|
+
/* 自己就是顶层(外壳被当页面开在新窗口里):上面没人接,不要再往自己转(会回声) */
|
|
78
|
+
if (window.parent === window) return;
|
|
79
|
+
if (event.source === window.parent) {
|
|
80
|
+
post(inner(), data); // 工作台 → 页面
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (event.source === inner()) post(window.parent, data); // 页面 → 工作台
|
|
84
|
+
}, false);
|
|
85
|
+
})();
|
|
86
|
+
</script>
|
|
87
|
+
</head>
|
|
88
|
+
<body>
|
|
89
|
+
<iframe id="pop-page" src="${escapeHtml(proxiedPath)}"></iframe>
|
|
90
|
+
</body>
|
|
91
|
+
</html>`;
|
|
92
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 客户端请求分发(从 index.ts 抽出来:400 行护栏)。
|
|
3
|
+
*
|
|
4
|
+
* 只做「解析 → 分发 → 回包」;真正的活儿都在 runtime / provider 接线里。
|
|
5
|
+
* 单源:请求形状校验在 protocol-parse.ts(ADR-0002 纪律①)。
|
|
6
|
+
*/
|
|
7
|
+
import { isKnownRequestType, parseClientRequest } from "../protocol-parse.js";
|
|
8
|
+
export async function handleMessage(socket, raw, deps) {
|
|
9
|
+
let parsed;
|
|
10
|
+
try {
|
|
11
|
+
parsed = JSON.parse(raw);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
deps.logger.warn("收到非法 JSON,已忽略");
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const request = parseClientRequest(parsed);
|
|
18
|
+
if (!request) {
|
|
19
|
+
const id = typeof parsed?.id === "string" ? parsed.id : "unknown";
|
|
20
|
+
const type = parsed?.type;
|
|
21
|
+
/**
|
|
22
|
+
* 两种失败要分开报(踩过两次同样的坑):
|
|
23
|
+
* - 类型根本不认识 → 多半是**代码更新了但服务端没重启**,报 bad_payload 会让人去查数据;
|
|
24
|
+
* - 类型认识、载荷不对 → 才是客户端的问题。
|
|
25
|
+
*/
|
|
26
|
+
const error = isKnownRequestType(type)
|
|
27
|
+
? { code: "protocol.bad_payload", message: `请求 ${type} 的载荷不合法` }
|
|
28
|
+
: {
|
|
29
|
+
code: "protocol.unknown_type",
|
|
30
|
+
message: typeof type === "string"
|
|
31
|
+
? `这个服务端版本不认识「${type}」这条请求 —— 多半是代码更新了但服务端没重启,重启一下就好`
|
|
32
|
+
: "无法识别的请求",
|
|
33
|
+
};
|
|
34
|
+
deps.logger.warn("拒绝非法请求", { id, type, code: error.code });
|
|
35
|
+
deps.reply(socket, id, { ok: false, error });
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
switch (request.type) {
|
|
40
|
+
case "send_message": {
|
|
41
|
+
deps.reply(socket, request.id, await deps.runtime.sendMessage(request.payload.text, request.payload.attachments, request.payload.mode, undefined, deps.clientId));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
case "interrupt":
|
|
45
|
+
deps.reply(socket, request.id, await deps.runtime.interrupt(request.payload.conversationId));
|
|
46
|
+
return;
|
|
47
|
+
case "refresh_actions":
|
|
48
|
+
deps.reply(socket, request.id, await deps.runtime.refreshActions(request.payload?.conversationId, request.payload?.count));
|
|
49
|
+
return;
|
|
50
|
+
case "set_engine":
|
|
51
|
+
// 零重启切引擎:项目 / 模型 / 能力都跟着新引擎走(engine-switch.ts)
|
|
52
|
+
deps.reply(socket, request.id, await deps.runtime.setEngine(request.payload.engine));
|
|
53
|
+
return;
|
|
54
|
+
case "approve":
|
|
55
|
+
deps.reply(socket, request.id, deps.runtime.approve(request.payload.requestId, request.payload.decision));
|
|
56
|
+
return;
|
|
57
|
+
case "new_chat": {
|
|
58
|
+
// 临时对话(pi 的 `--no-session`)只在显式要的时候开:不传就是普通会话
|
|
59
|
+
const seed = request.payload?.ephemeral ? { ephemeral: true } : undefined;
|
|
60
|
+
const created = await deps.runtime.newConversation(request.payload?.workspace, deps.clientId, seed);
|
|
61
|
+
/**
|
|
62
|
+
* **载荷要塞进 `result` 里**:`reply()`(server/index.ts)只转发 `result.result`,
|
|
63
|
+
* 扁平地传 `{ ok: true, conversationId }` 会被它当成「没有载荷」丢掉 ——
|
|
64
|
+
* 客户端读 `message.result.conversationId` 就永远是 undefined,
|
|
65
|
+
* 「新建会话顶到侧栏第一位」那条逻辑于是从来没生效过(分叉同理,见下面)。
|
|
66
|
+
*/
|
|
67
|
+
deps.reply(socket, request.id, created.ok ? { ok: true, result: created } : created);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
case "persist_conversation":
|
|
71
|
+
deps.reply(socket, request.id, await deps.runtime.persistConversation(request.payload.conversationId));
|
|
72
|
+
return;
|
|
73
|
+
case "close_ephemeral":
|
|
74
|
+
deps.reply(socket, request.id, deps.runtime.closeEphemeral(request.payload.conversationId));
|
|
75
|
+
return;
|
|
76
|
+
case "fork_session": {
|
|
77
|
+
const forked = await deps.runtime.forkSession(request.payload.conversationId, request.payload.messageId, deps.clientId);
|
|
78
|
+
// 同上:`conversationId` 必须包在 `result` 里,客户端才能把这条新分支顶到侧栏第一位
|
|
79
|
+
deps.reply(socket, request.id, forked.ok ? { ok: true, result: forked } : forked);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
case "rename_session":
|
|
83
|
+
deps.reply(socket, request.id, await deps.runtime.renameSession(request.payload.conversationId, request.payload.title));
|
|
84
|
+
return;
|
|
85
|
+
case "suggest_title": {
|
|
86
|
+
// AI 起名:一次问答 + 改名都在服务端跑完,回包带最终标题(界面拿去做提示)
|
|
87
|
+
// 客户端按 `message.result.ok` / `message.result.error` 读,所以整份塞进 `result`
|
|
88
|
+
const suggested = await deps.runtime.suggestSessionTitle(request.payload.conversationId);
|
|
89
|
+
deps.reply(socket, request.id, suggested.ok ? { ok: true, result: suggested } : suggested);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
case "refresh_resources":
|
|
93
|
+
// 刷新网页时前端喷一次:让引擎把技能 / MCP / AGENTS.md 重读一遒
|
|
94
|
+
deps.reply(socket, request.id, await deps.runtime.refreshConversationResources(request.payload.conversationId, {
|
|
95
|
+
force: request.payload.force === true,
|
|
96
|
+
}));
|
|
97
|
+
return;
|
|
98
|
+
case "move_session":
|
|
99
|
+
deps.reply(socket, request.id, await deps.runtime.moveSession(request.payload.conversationId, request.payload.workspace));
|
|
100
|
+
return;
|
|
101
|
+
case "switch_conversation":
|
|
102
|
+
deps.reply(socket, request.id, await deps.runtime.switchConversation(request.payload.conversationId, deps.clientId));
|
|
103
|
+
return;
|
|
104
|
+
case "list_providers":
|
|
105
|
+
case "upsert_provider":
|
|
106
|
+
case "delete_provider":
|
|
107
|
+
case "test_provider":
|
|
108
|
+
case "update_model":
|
|
109
|
+
case "remove_model":
|
|
110
|
+
case "set_enabled_models":
|
|
111
|
+
await deps.runProviderRequest(request, (result) => deps.reply(socket, request.id, result));
|
|
112
|
+
return;
|
|
113
|
+
case "set_approval_mode": {
|
|
114
|
+
deps.reply(socket, request.id, deps.runtime.setApprovalMode(request.payload.mode, request.payload.conversationId ?? null));
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
case "canvas_set_status":
|
|
118
|
+
deps.reply(socket, request.id, deps.runtime.canvasSetStatus(request.payload.conversationId, request.payload.nodeId, request.payload.status, request.payload.parent ?? null));
|
|
119
|
+
return;
|
|
120
|
+
case "canvas_delete":
|
|
121
|
+
deps.reply(socket, request.id, deps.runtime.canvasDelete(request.payload.conversationId, request.payload.ids, request.payload.parent ?? null));
|
|
122
|
+
return;
|
|
123
|
+
case "canvas_move":
|
|
124
|
+
deps.reply(socket, request.id, deps.runtime.canvasMove(request.payload.conversationId, request.payload.moves, request.payload.parent ?? null));
|
|
125
|
+
return;
|
|
126
|
+
case "canvas_suggest":
|
|
127
|
+
deps.reply(socket, request.id, await deps.runtime.canvasSuggest(request.payload.conversationId, request.payload.nodeIds, request.payload.parent ?? null));
|
|
128
|
+
return;
|
|
129
|
+
case "canvas_update_node":
|
|
130
|
+
deps.reply(socket, request.id, deps.runtime.canvasUpdateNode(request.payload.conversationId, request.payload.nodeId, {
|
|
131
|
+
...(request.payload.title === undefined ? {} : { title: request.payload.title }),
|
|
132
|
+
...(request.payload.detail === undefined ? {} : { detail: request.payload.detail }),
|
|
133
|
+
}, request.payload.parent ?? null));
|
|
134
|
+
return;
|
|
135
|
+
case "canvas_start_node":
|
|
136
|
+
deps.reply(socket, request.id, await deps.runtime.canvasStartNode(request.payload.conversationId, request.payload.nodeId, request.payload.parent ?? null));
|
|
137
|
+
return;
|
|
138
|
+
case "cancel_queued":
|
|
139
|
+
deps.reply(socket, request.id, deps.runtime.cancelQueued(request.payload.queueId));
|
|
140
|
+
return;
|
|
141
|
+
case "set_thinking_level":
|
|
142
|
+
deps.reply(socket, request.id, await deps.runtime.setThinkingLevel(request.payload.level));
|
|
143
|
+
return;
|
|
144
|
+
case "interrupt_subagent":
|
|
145
|
+
deps.reply(socket, request.id, await deps.runtime.interruptSubagent(request.payload.runId));
|
|
146
|
+
return;
|
|
147
|
+
case "save_subagent_profile":
|
|
148
|
+
deps.reply(socket, request.id, await deps.runtime.saveSubagentProfile(request.payload.profile));
|
|
149
|
+
return;
|
|
150
|
+
case "delete_subagent_profile":
|
|
151
|
+
deps.reply(socket, request.id, await deps.runtime.deleteSubagentProfile(request.payload.profileId));
|
|
152
|
+
return;
|
|
153
|
+
case "set_subagent_settings":
|
|
154
|
+
deps.reply(socket, request.id, await deps.runtime.setSubagentSettings(request.payload));
|
|
155
|
+
return;
|
|
156
|
+
case "set_model": {
|
|
157
|
+
deps.reply(socket, request.id, await deps.runtime.setModel(request.payload.modelId, request.payload.conversationId));
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
case "set_settings": {
|
|
161
|
+
deps.reply(socket, request.id, await deps.runtime.applySettings(request.payload));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
case "get_state": {
|
|
165
|
+
// 重连/刷新后的第一件事:拉一份权威快照(ADR-0004 §3);顺便刷一次 pi 会话列表(带 10s 下限)
|
|
166
|
+
await deps.runtime.refreshPiSessions();
|
|
167
|
+
await deps.runtime.refreshProviders();
|
|
168
|
+
// 必须按**这个客户端**生成:用全局快照会让重连的手机拿到电脑的会话
|
|
169
|
+
// (真实症状:电脑上切会话,手机跟着切 —— get_state 是每次重连都会调的)
|
|
170
|
+
deps.sender.pushSnapshot(deps.runtime.snapshotFor(deps.clientId));
|
|
171
|
+
deps.sender.flush(Date.now());
|
|
172
|
+
deps.reply(socket, request.id, { ok: true });
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
179
|
+
deps.logger.error("处理请求失败", { type: request.type, message });
|
|
180
|
+
deps.reply(socket, request.id, { ok: false, error: { code: "protocol.handler_failed", message } });
|
|
181
|
+
}
|
|
182
|
+
}
|