@waq666/pneuma 0.0.0-stage → 0.7.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 +144 -2
- package/bin/dsc.js +91 -0
- package/bin/headless.cjs +40 -0
- package/lib/adapter/core-runtime.d.ts +11 -0
- package/lib/adapter/core-runtime.js +259 -0
- package/lib/adapter/host.d.ts +18 -0
- package/lib/adapter/host.js +14 -0
- package/lib/adapter/runtime.d.ts +15 -0
- package/lib/adapter/runtime.js +290 -0
- package/lib/adapter/transcript.d.ts +184 -0
- package/lib/adapter/transcript.js +605 -0
- package/lib/app/AgentsOverlay.d.ts +18 -0
- package/lib/app/AgentsOverlay.js +63 -0
- package/lib/app/App.d.ts +13 -0
- package/lib/app/App.js +1498 -0
- package/lib/app/ApprovalCard.d.ts +12 -0
- package/lib/app/ApprovalCard.js +76 -0
- package/lib/app/AskCard.d.ts +20 -0
- package/lib/app/AskCard.js +45 -0
- package/lib/app/ChatView.d.ts +32 -0
- package/lib/app/ChatView.js +198 -0
- package/lib/app/Composer.d.ts +50 -0
- package/lib/app/Composer.js +282 -0
- package/lib/app/DiffBlock.d.ts +6 -0
- package/lib/app/DiffBlock.js +37 -0
- package/lib/app/MarkdownView.d.ts +6 -0
- package/lib/app/MarkdownView.js +99 -0
- package/lib/app/ModelPicker.d.ts +7 -0
- package/lib/app/ModelPicker.js +18 -0
- package/lib/app/PlanReviewCard.d.ts +13 -0
- package/lib/app/PlanReviewCard.js +54 -0
- package/lib/app/PresetPicker.d.ts +11 -0
- package/lib/app/PresetPicker.js +19 -0
- package/lib/app/PreviewOverlay.d.ts +14 -0
- package/lib/app/PreviewOverlay.js +22 -0
- package/lib/app/SessionPicker.d.ts +43 -0
- package/lib/app/SessionPicker.js +56 -0
- package/lib/app/SettingsOverlay.d.ts +32 -0
- package/lib/app/SettingsOverlay.js +157 -0
- package/lib/app/SkillsPicker.d.ts +7 -0
- package/lib/app/SkillsPicker.js +19 -0
- package/lib/app/StatusBar.d.ts +22 -0
- package/lib/app/StatusBar.js +272 -0
- package/lib/app/TaskStrips.d.ts +13 -0
- package/lib/app/TaskStrips.js +40 -0
- package/lib/app/ToolCard.d.ts +5 -0
- package/lib/app/ToolCard.js +40 -0
- package/lib/app/TranscriptOverlay.d.ts +12 -0
- package/lib/app/TranscriptOverlay.js +17 -0
- package/lib/app/Welcome.d.ts +6 -0
- package/lib/app/Welcome.js +66 -0
- package/lib/app/attach.d.ts +16 -0
- package/lib/app/attach.js +58 -0
- package/lib/app/click.d.ts +27 -0
- package/lib/app/click.js +89 -0
- package/lib/app/clipboard-image.d.ts +11 -0
- package/lib/app/clipboard-image.js +66 -0
- package/lib/app/cursor.d.ts +4 -0
- package/lib/app/cursor.js +24 -0
- package/lib/app/hello.d.ts +11 -0
- package/lib/app/hello.js +8 -0
- package/lib/app/history-store.d.ts +4 -0
- package/lib/app/history-store.js +41 -0
- package/lib/app/image-blocks.d.ts +12 -0
- package/lib/app/image-blocks.js +125 -0
- package/lib/app/markdown.d.ts +54 -0
- package/lib/app/markdown.js +189 -0
- package/lib/app/settings-model.d.ts +69 -0
- package/lib/app/settings-model.js +114 -0
- package/lib/app/theme.d.ts +166 -0
- package/lib/app/theme.js +141 -0
- package/lib/boot.d.ts +1 -0
- package/lib/boot.js +34 -0
- package/lib/commands.d.ts +49 -0
- package/lib/commands.js +115 -0
- package/lib/contract.d.ts +1973 -0
- package/lib/contract.js +36 -0
- package/lib/core/agent-roles.d.ts +52 -0
- package/lib/core/agent-roles.js +274 -0
- package/lib/core/approval-floor.d.ts +183 -0
- package/lib/core/approval-floor.js +679 -0
- package/lib/core/approval.d.ts +42 -0
- package/lib/core/approval.js +8 -0
- package/lib/core/audit.d.ts +61 -0
- package/lib/core/audit.js +59 -0
- package/lib/core/boot-notices.d.ts +6 -0
- package/lib/core/boot-notices.js +61 -0
- package/lib/core/cdp/actions.d.ts +182 -0
- package/lib/core/cdp/actions.js +649 -0
- package/lib/core/cdp/launch.d.ts +192 -0
- package/lib/core/cdp/launch.js +491 -0
- package/lib/core/cdp/snapshot.d.ts +139 -0
- package/lib/core/cdp/snapshot.js +316 -0
- package/lib/core/cdp/transport.d.ts +160 -0
- package/lib/core/cdp/transport.js +359 -0
- package/lib/core/command-policy.d.ts +108 -0
- package/lib/core/command-policy.js +580 -0
- package/lib/core/commands-completion.d.ts +78 -0
- package/lib/core/commands-completion.js +167 -0
- package/lib/core/compact-anchors.d.ts +76 -0
- package/lib/core/compact-anchors.js +284 -0
- package/lib/core/compact.d.ts +110 -0
- package/lib/core/compact.js +210 -0
- package/lib/core/config-store.d.ts +38 -0
- package/lib/core/config-store.js +307 -0
- package/lib/core/config.d.ts +36 -0
- package/lib/core/config.js +124 -0
- package/lib/core/connection-test.d.ts +60 -0
- package/lib/core/connection-test.js +84 -0
- package/lib/core/desktop-control.d.ts +298 -0
- package/lib/core/desktop-control.js +1311 -0
- package/lib/core/diff-text.d.ts +74 -0
- package/lib/core/diff-text.js +257 -0
- package/lib/core/dock-browser.d.ts +137 -0
- package/lib/core/dock-browser.js +146 -0
- package/lib/core/dock-ops.d.ts +59 -0
- package/lib/core/dock-ops.js +104 -0
- package/lib/core/dock-session.d.ts +39 -0
- package/lib/core/dock-session.js +28 -0
- package/lib/core/dsh-compat/hook.d.ts +18 -0
- package/lib/core/dsh-compat/hook.js +52 -0
- package/lib/core/dsh-compat/resolve-hook.d.ts +5 -0
- package/lib/core/dsh-compat/resolve-hook.js +59 -0
- package/lib/core/dsh-compat/tools-facade.d.ts +47 -0
- package/lib/core/dsh-compat/tools-facade.js +108 -0
- package/lib/core/err-text.d.ts +13 -0
- package/lib/core/err-text.js +15 -0
- package/lib/core/events.d.ts +149 -0
- package/lib/core/events.js +1 -0
- package/lib/core/git-exec.d.ts +23 -0
- package/lib/core/git-exec.js +72 -0
- package/lib/core/git-info.d.ts +47 -0
- package/lib/core/git-info.js +157 -0
- package/lib/core/goal.d.ts +89 -0
- package/lib/core/goal.js +189 -0
- package/lib/core/hooks.d.ts +272 -0
- package/lib/core/hooks.js +818 -0
- package/lib/core/host-browser-link.d.ts +59 -0
- package/lib/core/host-browser-link.js +9 -0
- package/lib/core/host-methods.d.ts +25 -0
- package/lib/core/host-methods.js +103 -0
- package/lib/core/image-diet.d.ts +77 -0
- package/lib/core/image-diet.js +127 -0
- package/lib/core/learnings/ledger.d.ts +73 -0
- package/lib/core/learnings/ledger.js +273 -0
- package/lib/core/learnings/skill-write.d.ts +250 -0
- package/lib/core/learnings/skill-write.js +854 -0
- package/lib/core/learnings/store.d.ts +102 -0
- package/lib/core/learnings/store.js +266 -0
- package/lib/core/lifecycle-hooks.d.ts +189 -0
- package/lib/core/lifecycle-hooks.js +576 -0
- package/lib/core/llm.d.ts +272 -0
- package/lib/core/llm.js +548 -0
- package/lib/core/lockfile.d.ts +17 -0
- package/lib/core/lockfile.js +110 -0
- package/lib/core/loop.d.ts +185 -0
- package/lib/core/loop.js +587 -0
- package/lib/core/lsp/client.d.ts +189 -0
- package/lib/core/lsp/client.js +690 -0
- package/lib/core/lsp/framing.d.ts +84 -0
- package/lib/core/lsp/framing.js +181 -0
- package/lib/core/lsp/line-shift.d.ts +28 -0
- package/lib/core/lsp/line-shift.js +127 -0
- package/lib/core/lsp/manager.d.ts +93 -0
- package/lib/core/lsp/manager.js +418 -0
- package/lib/core/lsp/normalize.d.ts +32 -0
- package/lib/core/lsp/normalize.js +139 -0
- package/lib/core/lsp/servers.d.ts +106 -0
- package/lib/core/lsp/servers.js +352 -0
- package/lib/core/lsp/uri.d.ts +76 -0
- package/lib/core/lsp/uri.js +179 -0
- package/lib/core/market.d.ts +51 -0
- package/lib/core/market.js +358 -0
- package/lib/core/mcp.d.ts +201 -0
- package/lib/core/mcp.js +836 -0
- package/lib/core/memory-eval.d.ts +158 -0
- package/lib/core/memory-eval.js +215 -0
- package/lib/core/memory.d.ts +266 -0
- package/lib/core/memory.js +703 -0
- package/lib/core/mention.d.ts +57 -0
- package/lib/core/mention.js +129 -0
- package/lib/core/microcompact.d.ts +48 -0
- package/lib/core/microcompact.js +79 -0
- package/lib/core/migrate.d.ts +56 -0
- package/lib/core/migrate.js +134 -0
- package/lib/core/model-caps.d.ts +83 -0
- package/lib/core/model-caps.js +150 -0
- package/lib/core/model-discovery.d.ts +19 -0
- package/lib/core/model-discovery.js +69 -0
- package/lib/core/modes.d.ts +72 -0
- package/lib/core/modes.js +152 -0
- package/lib/core/native-bridge.d.ts +135 -0
- package/lib/core/native-bridge.js +563 -0
- package/lib/core/path-policy.d.ts +32 -0
- package/lib/core/path-policy.js +248 -0
- package/lib/core/permission-presets.d.ts +67 -0
- package/lib/core/permission-presets.js +75 -0
- package/lib/core/plugin-loader.d.ts +36 -0
- package/lib/core/plugin-loader.js +294 -0
- package/lib/core/plugin-registry.d.ts +113 -0
- package/lib/core/plugin-registry.js +256 -0
- package/lib/core/prefs.d.ts +82 -0
- package/lib/core/prefs.js +372 -0
- package/lib/core/presets.d.ts +80 -0
- package/lib/core/presets.js +373 -0
- package/lib/core/pricing.d.ts +90 -0
- package/lib/core/pricing.js +126 -0
- package/lib/core/prompt.d.ts +92 -0
- package/lib/core/prompt.js +339 -0
- package/lib/core/ptc.d.ts +66 -0
- package/lib/core/ptc.js +70 -0
- package/lib/core/remote/frames.d.ts +91 -0
- package/lib/core/remote/frames.js +174 -0
- package/lib/core/remote/notify.d.ts +54 -0
- package/lib/core/remote/notify.js +77 -0
- package/lib/core/remote/owner.d.ts +32 -0
- package/lib/core/remote/owner.js +75 -0
- package/lib/core/remote/pairing.d.ts +104 -0
- package/lib/core/remote/pairing.js +261 -0
- package/lib/core/remote/push.d.ts +80 -0
- package/lib/core/remote/push.js +222 -0
- package/lib/core/remote/store.d.ts +18 -0
- package/lib/core/remote/store.js +59 -0
- package/lib/core/remote/tickets.d.ts +20 -0
- package/lib/core/remote/tickets.js +49 -0
- package/lib/core/remote/uploads.d.ts +63 -0
- package/lib/core/remote/uploads.js +161 -0
- package/lib/core/request-attribution.d.ts +26 -0
- package/lib/core/request-attribution.js +86 -0
- package/lib/core/request-invariant.d.ts +61 -0
- package/lib/core/request-invariant.js +199 -0
- package/lib/core/sandbox/backends.d.ts +64 -0
- package/lib/core/sandbox/backends.js +194 -0
- package/lib/core/sandbox/execpolicy.d.ts +93 -0
- package/lib/core/sandbox/execpolicy.js +452 -0
- package/lib/core/sandbox/net-proxy.d.ts +31 -0
- package/lib/core/sandbox/net-proxy.js +162 -0
- package/lib/core/sandbox/policy.d.ts +211 -0
- package/lib/core/sandbox/policy.js +559 -0
- package/lib/core/sandbox/win/abi.d.ts +161 -0
- package/lib/core/sandbox/win/abi.js +169 -0
- package/lib/core/sandbox/win/account.d.ts +71 -0
- package/lib/core/sandbox/win/account.js +206 -0
- package/lib/core/sandbox/win/acl.d.ts +54 -0
- package/lib/core/sandbox/win/acl.js +339 -0
- package/lib/core/sandbox/win/backend.d.ts +61 -0
- package/lib/core/sandbox/win/backend.js +249 -0
- package/lib/core/sandbox/win/doctor.d.ts +24 -0
- package/lib/core/sandbox/win/doctor.js +272 -0
- package/lib/core/sandbox/win/ffi.d.ts +107 -0
- package/lib/core/sandbox/win/ffi.js +166 -0
- package/lib/core/sandbox/win/net-abi.d.ts +154 -0
- package/lib/core/sandbox/win/net-abi.js +316 -0
- package/lib/core/sandbox/win/runner-entry.d.ts +35 -0
- package/lib/core/sandbox/win/runner-entry.js +391 -0
- package/lib/core/sandbox/win/setup.d.ts +60 -0
- package/lib/core/sandbox/win/setup.js +986 -0
- package/lib/core/sandbox/win/token.d.ts +35 -0
- package/lib/core/sandbox/win/token.js +238 -0
- package/lib/core/sandbox/win/wfp.d.ts +41 -0
- package/lib/core/sandbox/win/wfp.js +200 -0
- package/lib/core/sandbox/win/workspace-sid.d.ts +9 -0
- package/lib/core/sandbox/win/workspace-sid.js +45 -0
- package/lib/core/schedule/rule.d.ts +184 -0
- package/lib/core/schedule/rule.js +745 -0
- package/lib/core/schedule/runner.d.ts +185 -0
- package/lib/core/schedule/runner.js +678 -0
- package/lib/core/schedule/store.d.ts +182 -0
- package/lib/core/schedule/store.js +455 -0
- package/lib/core/secrets.d.ts +41 -0
- package/lib/core/secrets.js +150 -0
- package/lib/core/session-export.d.ts +18 -0
- package/lib/core/session-export.js +73 -0
- package/lib/core/session-index.d.ts +159 -0
- package/lib/core/session-index.js +683 -0
- package/lib/core/session-meta.d.ts +41 -0
- package/lib/core/session-meta.js +97 -0
- package/lib/core/session.d.ts +356 -0
- package/lib/core/session.js +998 -0
- package/lib/core/skills.d.ts +60 -0
- package/lib/core/skills.js +171 -0
- package/lib/core/spill.d.ts +159 -0
- package/lib/core/spill.js +329 -0
- package/lib/core/surface-registry.d.ts +45 -0
- package/lib/core/surface-registry.js +67 -0
- package/lib/core/team-board.d.ts +95 -0
- package/lib/core/team-board.js +316 -0
- package/lib/core/throughput.d.ts +46 -0
- package/lib/core/throughput.js +40 -0
- package/lib/core/todo-reminder.d.ts +44 -0
- package/lib/core/todo-reminder.js +55 -0
- package/lib/core/todo.d.ts +81 -0
- package/lib/core/todo.js +222 -0
- package/lib/core/token-estimate.d.ts +55 -0
- package/lib/core/token-estimate.js +82 -0
- package/lib/core/tool-guards.d.ts +103 -0
- package/lib/core/tool-guards.js +77 -0
- package/lib/core/tool-search.d.ts +152 -0
- package/lib/core/tool-search.js +311 -0
- package/lib/core/tools/bash.d.ts +281 -0
- package/lib/core/tools/bash.js +871 -0
- package/lib/core/tools/command-runner.d.ts +84 -0
- package/lib/core/tools/command-runner.js +68 -0
- package/lib/core/tools/fs-tools.d.ts +23 -0
- package/lib/core/tools/fs-tools.js +247 -0
- package/lib/core/tools/index.d.ts +8 -0
- package/lib/core/tools/index.js +4 -0
- package/lib/core/tools/sandbox-args.d.ts +51 -0
- package/lib/core/tools/sandbox-args.js +90 -0
- package/lib/core/tools/search-tools.d.ts +3 -0
- package/lib/core/tools/search-tools.js +153 -0
- package/lib/core/tools.d.ts +96 -0
- package/lib/core/tools.js +53 -0
- package/lib/core/ui-boot-source.d.ts +71 -0
- package/lib/core/ui-boot-source.js +121 -0
- package/lib/core/ui-bundles.d.ts +249 -0
- package/lib/core/ui-bundles.js +830 -0
- package/lib/core/ui-combo.d.ts +49 -0
- package/lib/core/ui-combo.js +55 -0
- package/lib/core/ui-events.d.ts +81 -0
- package/lib/core/ui-events.js +364 -0
- package/lib/core/ui-hmr.d.ts +36 -0
- package/lib/core/ui-hmr.js +128 -0
- package/lib/core/ui-methods.d.ts +69 -0
- package/lib/core/ui-methods.js +341 -0
- package/lib/core/ui-route.d.ts +69 -0
- package/lib/core/ui-route.js +122 -0
- package/lib/core/ui-server.d.ts +75 -0
- package/lib/core/ui-server.js +369 -0
- package/lib/core/ui-trust.d.ts +47 -0
- package/lib/core/ui-trust.js +164 -0
- package/lib/core/untrusted.d.ts +30 -0
- package/lib/core/untrusted.js +48 -0
- package/lib/core/update-check.d.ts +81 -0
- package/lib/core/update-check.js +177 -0
- package/lib/core/usage-log.d.ts +82 -0
- package/lib/core/usage-log.js +306 -0
- package/lib/core/version.d.ts +1 -0
- package/lib/core/version.js +37 -0
- package/lib/core/web-http.d.ts +57 -0
- package/lib/core/web-http.js +137 -0
- package/lib/core/web-static.d.ts +31 -0
- package/lib/core/web-static.js +75 -0
- package/lib/headless.d.ts +1 -0
- package/lib/headless.js +31 -0
- package/lib/host/kernel.d.ts +33 -0
- package/lib/host/kernel.js +451 -0
- package/lib/index.d.ts +41 -0
- package/lib/index.js +35 -0
- package/lib/plugins/agent.d.ts +2 -0
- package/lib/plugins/agent.js +274 -0
- package/lib/plugins/approval-floor.d.ts +2 -0
- package/lib/plugins/approval-floor.js +223 -0
- package/lib/plugins/approval.d.ts +16 -0
- package/lib/plugins/approval.js +674 -0
- package/lib/plugins/ask.d.ts +2 -0
- package/lib/plugins/ask.js +245 -0
- package/lib/plugins/browser.d.ts +68 -0
- package/lib/plugins/browser.js +1341 -0
- package/lib/plugins/commands.d.ts +23 -0
- package/lib/plugins/commands.js +498 -0
- package/lib/plugins/compact.d.ts +21 -0
- package/lib/plugins/compact.js +274 -0
- package/lib/plugins/computer-use.d.ts +47 -0
- package/lib/plugins/computer-use.js +539 -0
- package/lib/plugins/desktop-dock.d.ts +2 -0
- package/lib/plugins/desktop-dock.js +626 -0
- package/lib/plugins/dock-browser.d.ts +34 -0
- package/lib/plugins/dock-browser.js +765 -0
- package/lib/plugins/dsh-compat.d.ts +25 -0
- package/lib/plugins/dsh-compat.js +37 -0
- package/lib/plugins/file-review.d.ts +108 -0
- package/lib/plugins/file-review.js +393 -0
- package/lib/plugins/git.d.ts +26 -0
- package/lib/plugins/git.js +132 -0
- package/lib/plugins/goal.d.ts +20 -0
- package/lib/plugins/goal.js +245 -0
- package/lib/plugins/guards.d.ts +14 -0
- package/lib/plugins/guards.js +18 -0
- package/lib/plugins/hooks.d.ts +19 -0
- package/lib/plugins/hooks.js +583 -0
- package/lib/plugins/host-stdio.d.ts +88 -0
- package/lib/plugins/host-stdio.js +317 -0
- package/lib/plugins/image-diet.d.ts +17 -0
- package/lib/plugins/image-diet.js +85 -0
- package/lib/plugins/lifecycle-hooks.d.ts +26 -0
- package/lib/plugins/lifecycle-hooks.js +338 -0
- package/lib/plugins/llm.d.ts +13 -0
- package/lib/plugins/llm.js +215 -0
- package/lib/plugins/lsp.d.ts +54 -0
- package/lib/plugins/lsp.js +608 -0
- package/lib/plugins/mcp.d.ts +16 -0
- package/lib/plugins/mcp.js +673 -0
- package/lib/plugins/memory.d.ts +17 -0
- package/lib/plugins/memory.js +858 -0
- package/lib/plugins/microcompact.d.ts +18 -0
- package/lib/plugins/microcompact.js +119 -0
- package/lib/plugins/mode.d.ts +18 -0
- package/lib/plugins/mode.js +115 -0
- package/lib/plugins/permission-presets.d.ts +18 -0
- package/lib/plugins/permission-presets.js +135 -0
- package/lib/plugins/plan.d.ts +2 -0
- package/lib/plugins/plan.js +192 -0
- package/lib/plugins/plugin-manager.d.ts +2 -0
- package/lib/plugins/plugin-manager.js +165 -0
- package/lib/plugins/presets.d.ts +2 -0
- package/lib/plugins/presets.js +182 -0
- package/lib/plugins/prompt.d.ts +2 -0
- package/lib/plugins/prompt.js +264 -0
- package/lib/plugins/ptc.d.ts +2 -0
- package/lib/plugins/ptc.js +272 -0
- package/lib/plugins/remote/http.d.ts +11 -0
- package/lib/plugins/remote/http.js +11 -0
- package/lib/plugins/remote/routes.d.ts +24 -0
- package/lib/plugins/remote/routes.js +384 -0
- package/lib/plugins/remote/types.d.ts +135 -0
- package/lib/plugins/remote/types.js +87 -0
- package/lib/plugins/remote.d.ts +17 -0
- package/lib/plugins/remote.js +1028 -0
- package/lib/plugins/runtime-api.d.ts +16 -0
- package/lib/plugins/runtime-api.js +99 -0
- package/lib/plugins/runtime.d.ts +10 -0
- package/lib/plugins/runtime.js +451 -0
- package/lib/plugins/sandbox.d.ts +2 -0
- package/lib/plugins/sandbox.js +761 -0
- package/lib/plugins/schedule.d.ts +26 -0
- package/lib/plugins/schedule.js +538 -0
- package/lib/plugins/self-improve.d.ts +61 -0
- package/lib/plugins/self-improve.js +953 -0
- package/lib/plugins/session-search.d.ts +16 -0
- package/lib/plugins/session-search.js +308 -0
- package/lib/plugins/session-title.d.ts +19 -0
- package/lib/plugins/session-title.js +109 -0
- package/lib/plugins/session.d.ts +7 -0
- package/lib/plugins/session.js +296 -0
- package/lib/plugins/settings.d.ts +3 -0
- package/lib/plugins/settings.js +705 -0
- package/lib/plugins/skills.d.ts +2 -0
- package/lib/plugins/skills.js +360 -0
- package/lib/plugins/spill.d.ts +16 -0
- package/lib/plugins/spill.js +200 -0
- package/lib/plugins/subagent.d.ts +2 -0
- package/lib/plugins/subagent.js +862 -0
- package/lib/plugins/surfaces.d.ts +11 -0
- package/lib/plugins/surfaces.js +20 -0
- package/lib/plugins/team.d.ts +16 -0
- package/lib/plugins/team.js +149 -0
- package/lib/plugins/todo.d.ts +19 -0
- package/lib/plugins/todo.js +188 -0
- package/lib/plugins/tool-search.d.ts +2 -0
- package/lib/plugins/tool-search.js +425 -0
- package/lib/plugins/tools-default.d.ts +12 -0
- package/lib/plugins/tools-default.js +275 -0
- package/lib/plugins/tools.d.ts +16 -0
- package/lib/plugins/tools.js +62 -0
- package/lib/plugins/transcript.d.ts +15 -0
- package/lib/plugins/transcript.js +311 -0
- package/lib/plugins/tui.d.ts +2 -0
- package/lib/plugins/tui.js +98 -0
- package/lib/plugins/waiting.d.ts +12 -0
- package/lib/plugins/waiting.js +34 -0
- package/lib/plugins/web-search.d.ts +14 -0
- package/lib/plugins/web-search.js +263 -0
- package/lib/plugins/webserver.d.ts +48 -0
- package/lib/plugins/webserver.js +228 -0
- package/lib/remote/assets/app-DAcUCOEn.js +14 -0
- package/lib/remote/assets/icon-192.png +0 -0
- package/lib/remote/assets/icon-512.png +0 -0
- package/lib/remote/assets/index.html +34 -0
- package/lib/remote/assets/manifest.json +27 -0
- package/lib/remote/assets/style-DIB6729x.css +1 -0
- package/lib/remote/assets/sw.js +66 -0
- package/lib/services/types.d.ts +1228 -0
- package/lib/services/types.js +1 -0
- package/lib/tools/config-cli.d.ts +1 -0
- package/lib/tools/config-cli.js +89 -0
- package/lib/ui/arrival.d.ts +72 -0
- package/lib/ui/arrival.js +105 -0
- package/lib/ui/assets/app-B70nVIKd.js +69 -0
- package/lib/ui/assets/chunk-2UxHyX5q.js +1 -0
- package/lib/ui/assets/chunk-B1dDrJ26.js +1 -0
- package/lib/ui/assets/chunk-B6aJPvgy.js +1 -0
- package/lib/ui/assets/chunk-BEwlwnbL.js +1 -0
- package/lib/ui/assets/chunk-BGcgwlCI.js +12 -0
- package/lib/ui/assets/chunk-BIGW1oBm.js +1 -0
- package/lib/ui/assets/chunk-BPQ3VLAy.js +1 -0
- package/lib/ui/assets/chunk-BRH0KZbk.js +141 -0
- package/lib/ui/assets/chunk-BX6H_ySx.js +1 -0
- package/lib/ui/assets/chunk-B_P3UbPa.js +1 -0
- package/lib/ui/assets/chunk-B_TYUkTI.js +1 -0
- package/lib/ui/assets/chunk-B_vNuMnf.js +1 -0
- package/lib/ui/assets/chunk-BajyYBss.js +10 -0
- package/lib/ui/assets/chunk-BdnUsdx6.js +1 -0
- package/lib/ui/assets/chunk-Buea-lGh.js +1 -0
- package/lib/ui/assets/chunk-C0PvZCCE.js +1 -0
- package/lib/ui/assets/chunk-C0m74zRD.js +1 -0
- package/lib/ui/assets/chunk-C27-OAKa.js +1 -0
- package/lib/ui/assets/chunk-C2oV4EkX.js +1 -0
- package/lib/ui/assets/chunk-C7zT0LnQ.js +1 -0
- package/lib/ui/assets/chunk-C9GSunVT.js +1 -0
- package/lib/ui/assets/chunk-C9tS-k6U.js +1 -0
- package/lib/ui/assets/chunk-CHLpvVh8.js +1 -0
- package/lib/ui/assets/chunk-CLxacb5B.js +1 -0
- package/lib/ui/assets/chunk-COt5Ahok.js +1 -0
- package/lib/ui/assets/chunk-CPTIWCL2.js +1 -0
- package/lib/ui/assets/chunk-CQLl-L-p.js +1 -0
- package/lib/ui/assets/chunk-CUWRgxuq.js +55 -0
- package/lib/ui/assets/chunk-CWanVSXC.js +1 -0
- package/lib/ui/assets/chunk-Cf5RLm7j.js +1 -0
- package/lib/ui/assets/chunk-CickPsom.js +1 -0
- package/lib/ui/assets/chunk-Cj5Yp3dK.js +1 -0
- package/lib/ui/assets/chunk-Cmh6b_Ma.js +1 -0
- package/lib/ui/assets/chunk-Cp-IABpG.js +1 -0
- package/lib/ui/assets/chunk-CqE71os6.js +1 -0
- package/lib/ui/assets/chunk-CtKP3W-j.js +1 -0
- package/lib/ui/assets/chunk-Cvjx9yec.js +1 -0
- package/lib/ui/assets/chunk-CxGP3dtY.js +1 -0
- package/lib/ui/assets/chunk-CylS5w8V.js +1 -0
- package/lib/ui/assets/chunk-D38fbIBN.js +1 -0
- package/lib/ui/assets/chunk-D97Zzqfu.js +1 -0
- package/lib/ui/assets/chunk-DAi9KRSo.js +1 -0
- package/lib/ui/assets/chunk-DHK4yRfg.js +1 -0
- package/lib/ui/assets/chunk-DJeabLx-.js +1 -0
- package/lib/ui/assets/chunk-DNRxmY5a.js +1 -0
- package/lib/ui/assets/chunk-DNSN1z5r.js +1 -0
- package/lib/ui/assets/chunk-DNasK_ZG.js +1 -0
- package/lib/ui/assets/chunk-DPvrY3IQ.js +1 -0
- package/lib/ui/assets/chunk-DXmwc3jG.js +1 -0
- package/lib/ui/assets/chunk-Dd0kTxKP.js +1 -0
- package/lib/ui/assets/chunk-De0Btta0.js +1 -0
- package/lib/ui/assets/chunk-Des-eS-w.js +1 -0
- package/lib/ui/assets/chunk-Df6bDoY_.js +1 -0
- package/lib/ui/assets/chunk-DijEV5ha.js +1 -0
- package/lib/ui/assets/chunk-DkvoVjww.js +1 -0
- package/lib/ui/assets/chunk-DlC-OlHO.js +1 -0
- package/lib/ui/assets/chunk-DnzrXTVv.js +1 -0
- package/lib/ui/assets/chunk-Dualf0xi.js +1 -0
- package/lib/ui/assets/chunk-EXT84bkm.js +1 -0
- package/lib/ui/assets/chunk-GwR3hkPK.js +1 -0
- package/lib/ui/assets/chunk-P80f7IUj.js +1 -0
- package/lib/ui/assets/chunk-VOosw3JB.js +1 -0
- package/lib/ui/assets/chunk-YQ4lDkt_.js +140 -0
- package/lib/ui/assets/chunk-Yzrsuije.js +1 -0
- package/lib/ui/assets/chunk-Z72CF80r.js +1 -0
- package/lib/ui/assets/chunk-g9-lgVsj.js +1 -0
- package/lib/ui/assets/chunk-vGWfd6FD.js +1 -0
- package/lib/ui/assets/chunk-wDzz0qaB.js +1 -0
- package/lib/ui/assets/chunk-ySF7HWmS.js +1 -0
- package/lib/ui/assets/icon.png +0 -0
- package/lib/ui/assets/index.html +14 -0
- package/lib/ui/assets/pdf.worker.min-CjEcRF4W.mjs +28 -0
- package/lib/ui/assets/style-Bq01xH_b.css +1 -0
- package/lib/ui/frames.d.ts +67 -0
- package/lib/ui/frames.js +146 -0
- package/lib/ui/index.d.ts +59 -0
- package/lib/ui/index.js +50 -0
- package/lib/ui/manifest.d.ts +172 -0
- package/lib/ui/manifest.js +158 -0
- package/lib/ui/plugin.d.ts +161 -0
- package/lib/ui/plugin.js +7 -0
- package/lib/ui/plugins/browser/client.js +290 -0
- package/lib/ui/plugins/browser/icon.png +0 -0
- package/lib/ui/plugins/composer/client.js +1843 -0
- package/lib/ui/plugins/composer/icon.png +0 -0
- package/lib/ui/plugins/files/client.js +646 -0
- package/lib/ui/plugins/files/icon.png +0 -0
- package/lib/ui/plugins/manifest.json +107 -0
- package/lib/ui/plugins/plugins/client.js +682 -0
- package/lib/ui/plugins/plugins/icon.png +0 -0
- package/lib/ui/plugins/preview/client.js +197 -0
- package/lib/ui/plugins/preview/icon.png +0 -0
- package/lib/ui/plugins/prompt/client.js +653 -0
- package/lib/ui/plugins/prompt/icon.png +0 -0
- package/lib/ui/plugins/sessions/client.js +1577 -0
- package/lib/ui/plugins/sessions/icon.png +0 -0
- package/lib/ui/plugins/settings/client.js +5470 -0
- package/lib/ui/plugins/settings/icon.png +0 -0
- package/lib/ui/plugins/skills/client.js +485 -0
- package/lib/ui/plugins/skills/icon.png +0 -0
- package/lib/ui/plugins/status/client.js +1420 -0
- package/lib/ui/plugins/status/icon.png +0 -0
- package/lib/ui/plugins/statusbar/client.js +504 -0
- package/lib/ui/plugins/statusbar/icon.png +0 -0
- package/lib/ui/plugins/tasks/client.js +52 -0
- package/lib/ui/plugins/tasks/icon.png +0 -0
- package/lib/ui/plugins/team/client.js +527 -0
- package/lib/ui/plugins/team/icon.png +0 -0
- package/lib/ui/plugins/terminal/client.js +232 -0
- package/lib/ui/plugins/terminal/icon.png +0 -0
- package/lib/ui/plugins/trace/client.js +1376 -0
- package/lib/ui/plugins/trace/icon.png +0 -0
- package/lib/ui/plugins/transcript/client.js +2661 -0
- package/lib/ui/plugins/transcript/icon.png +0 -0
- package/lib/ui/scoped-slots.d.ts +20 -0
- package/lib/ui/scoped-slots.js +21 -0
- package/lib/ui/sdk/@dsc/ui/index.d.ts +242 -0
- package/lib/ui/sdk/@dsc/ui/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-core/contract.d.ts +1973 -0
- package/lib/ui/sdk/@dsc/ui-core/core/diff-text.d.ts +74 -0
- package/lib/ui/sdk/@dsc/ui-core/core/dock-browser.d.ts +137 -0
- package/lib/ui/sdk/@dsc/ui-core/core/dock-ops.d.ts +59 -0
- package/lib/ui/sdk/@dsc/ui-core/core/model-caps.d.ts +83 -0
- package/lib/ui/sdk/@dsc/ui-core/core/native-bridge.d.ts +135 -0
- package/lib/ui/sdk/@dsc/ui-core/core/token-estimate.d.ts +55 -0
- package/lib/ui/sdk/@dsc/ui-core/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/arrival.d.ts +72 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/frames.d.ts +67 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/index.d.ts +59 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/manifest.d.ts +172 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/plugin.d.ts +161 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/scoped-slots.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/services-react.d.ts +27 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/services.d.ts +63 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/slots-react.d.ts +28 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/slots.d.ts +481 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/store.d.ts +89 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock-model.d.ts +238 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock-state.d.ts +163 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/index.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-layout/app.d.ts +74 -0
- package/lib/ui/sdk/@dsc/ui-layout/appearance.d.ts +70 -0
- package/lib/ui/sdk/@dsc/ui-layout/host-channel.d.ts +112 -0
- package/lib/ui/sdk/@dsc/ui-layout/index.d.ts +34 -0
- package/lib/ui/sdk/@dsc/ui-layout/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-layout/page-state.d.ts +14 -0
- package/lib/ui/sdk/@dsc/ui-layout/review-pane.d.ts +21 -0
- package/lib/ui/sdk/@dsc/ui-layout/runtime-context.d.ts +44 -0
- package/lib/ui/sdk/@dsc/ui-layout/thread-view.d.ts +28 -0
- package/lib/ui/sdk/@dsc/ui-layout/update-button.d.ts +21 -0
- package/lib/ui/sdk/@dsc/ui-primitives/code-file-icon-artwork.d.ts +53 -0
- package/lib/ui/sdk/@dsc/ui-primitives/code-view.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-primitives/compat.d.ts +27 -0
- package/lib/ui/sdk/@dsc/ui-primitives/completion-sound.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-primitives/confirm.d.ts +33 -0
- package/lib/ui/sdk/@dsc/ui-primitives/css.d.ts +47 -0
- package/lib/ui/sdk/@dsc/ui-primitives/diff-rows.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-icons.d.ts +38 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-type-classify.d.ts +66 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-type-icon.d.ts +57 -0
- package/lib/ui/sdk/@dsc/ui-primitives/highlight.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-primitives/hover-delay.d.ts +17 -0
- package/lib/ui/sdk/@dsc/ui-primitives/icons.d.ts +109 -0
- package/lib/ui/sdk/@dsc/ui-primitives/index.d.ts +55 -0
- package/lib/ui/sdk/@dsc/ui-primitives/lang-table.d.ts +10 -0
- package/lib/ui/sdk/@dsc/ui-primitives/markdown.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-primitives/native.d.ts +41 -0
- package/lib/ui/sdk/@dsc/ui-primitives/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-primitives/panels.d.ts +86 -0
- package/lib/ui/sdk/@dsc/ui-primitives/paths.d.ts +11 -0
- package/lib/ui/sdk/@dsc/ui-primitives/pdf-view.d.ts +13 -0
- package/lib/ui/sdk/@dsc/ui-primitives/plugin-text.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-primitives/select.d.ts +35 -0
- package/lib/ui/sdk/@dsc/ui-primitives/table-view.d.ts +23 -0
- package/lib/ui/sdk/@dsc/ui-primitives/thread-resizer.d.ts +22 -0
- package/lib/ui/sdk/@dsc/ui-primitives/time.d.ts +33 -0
- package/lib/ui/sdk/@dsc/ui-primitives/toast.d.ts +16 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tokens.d.ts +14 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tool-args.d.ts +49 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tool-summary.d.ts +64 -0
- package/lib/ui/sdk/@dsc/ui-renderer/boot.d.ts +121 -0
- package/lib/ui/sdk/@dsc/ui-renderer/hmr.d.ts +43 -0
- package/lib/ui/sdk/@dsc/ui-renderer/index.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-renderer/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-slots/index.d.ts +19 -0
- package/lib/ui/sdk/@dsc/ui-slots/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-slots/slots-react.d.ts +48 -0
- package/lib/ui/sdk/@dsc/ui-slots/slots.d.ts +102 -0
- package/lib/ui/services-react.d.ts +27 -0
- package/lib/ui/services-react.js +32 -0
- package/lib/ui/services.d.ts +63 -0
- package/lib/ui/services.js +121 -0
- package/lib/ui/slots-ink.d.ts +26 -0
- package/lib/ui/slots-ink.js +78 -0
- package/lib/ui/slots-react.d.ts +28 -0
- package/lib/ui/slots-react.js +88 -0
- package/lib/ui/slots.d.ts +481 -0
- package/lib/ui/slots.js +550 -0
- package/lib/ui/store.d.ts +89 -0
- package/lib/ui/store.js +62 -0
- package/lib/ui/tui-plugin-api.d.ts +23 -0
- package/lib/ui/tui-plugin-api.js +23 -0
- package/lib/ui/tui-plugins.d.ts +47 -0
- package/lib/ui/tui-plugins.js +220 -0
- package/package.json +58 -6
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 无障碍树快照:`Accessibility.getFullAXTree` → 给模型看的文本树 + 行内 ref。
|
|
3
|
+
*
|
|
4
|
+
* 为什么用无障碍树而不是自己遍历 DOM:
|
|
5
|
+
* 1. role / name / checked / expanded 这些「这个东西是什么、叫什么、什么状态」
|
|
6
|
+
* 浏览器已经按 W3C 的规范算好了(含 `aria-*`、`<label for>`、`<button>` 的隐式角色)。
|
|
7
|
+
* 自己写等于重抄一份几千行的 accname 规范,抄不对还会算错;
|
|
8
|
+
* 2. 文本树天然是给模型看的形状——元素少、层级清楚、没有 style 噪音;
|
|
9
|
+
* 3. 每个节点带 `backendDOMNodeId`,这个号能直接喂给 `DOM.getBoxModel` /
|
|
10
|
+
* `DOM.setFileInputFiles` / `Input.*`,于是「模型只给 ref、我们负责落到像素」成立。
|
|
11
|
+
*
|
|
12
|
+
* ref 的两条规矩(这是与「截图 + 坐标」最大的差别):
|
|
13
|
+
* - **只给能动手的东西发 ref**:默认 compact 视图只列可交互角色(button/link/textbox/…),
|
|
14
|
+
* 模型拿到的每个 ref 都是能点能填的,不会去点一个装饰性的 div;
|
|
15
|
+
* - **ref 带代际**:每次快照递增 generation,动作前既核对 ref 属于本次快照,
|
|
16
|
+
* 又用 `DOM.describeNode` + `Accessibility.getPartialAXTree` 复核这个后端节点还在、
|
|
17
|
+
* role/name 没变(页面自己改了 DOM 而模型还照着旧快照动手,就靠这一步拦下来)。
|
|
18
|
+
*
|
|
19
|
+
* @module dsc/core/cdp/snapshot
|
|
20
|
+
*/
|
|
21
|
+
/** 无障碍树里的一个值(type + value 两步取值是协议的规定形状)。 */
|
|
22
|
+
export interface AxValue<T> {
|
|
23
|
+
type?: string;
|
|
24
|
+
value?: T;
|
|
25
|
+
}
|
|
26
|
+
/** `Accessibility.getFullAXTree` 返回的一个节点(只声明我们用得到的字段)。 */
|
|
27
|
+
export interface AxNode {
|
|
28
|
+
nodeId?: string;
|
|
29
|
+
parentId?: string;
|
|
30
|
+
childIds?: string[];
|
|
31
|
+
ignored?: boolean;
|
|
32
|
+
role?: AxValue<string>;
|
|
33
|
+
name?: AxValue<string>;
|
|
34
|
+
description?: AxValue<string>;
|
|
35
|
+
value?: AxValue<unknown>;
|
|
36
|
+
backendDOMNodeId?: number;
|
|
37
|
+
properties?: Array<{
|
|
38
|
+
name?: string;
|
|
39
|
+
value?: AxValue<unknown>;
|
|
40
|
+
}>;
|
|
41
|
+
}
|
|
42
|
+
/** 一次快照里的树。 */
|
|
43
|
+
export interface AxTree {
|
|
44
|
+
nodes?: AxNode[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 可交互角色白名单(小写比较)。
|
|
48
|
+
* 这些角色要么能点(button/link/menuitem/tab)、要么能填(textbox/combobox/checkbox/…)、
|
|
49
|
+
* 要么能拖(slider)。不在名单里的(heading/paragraph/generic/StaticText…)只做上下文,
|
|
50
|
+
* 默认视图不列,也不发 ref。
|
|
51
|
+
*/
|
|
52
|
+
export declare const INTERACTIVE_ROLES: ReadonlySet<string>;
|
|
53
|
+
/** 快照里一个 ref 的来历。 */
|
|
54
|
+
export interface SnapshotRef {
|
|
55
|
+
/** 模型看到的编号,形如 `e5`。 */
|
|
56
|
+
ref: string;
|
|
57
|
+
/** 后端节点号(喂给 DOM 域用)。 */
|
|
58
|
+
backendNodeId: number;
|
|
59
|
+
/** 发 ref 那一刻的 role。 */
|
|
60
|
+
role: string;
|
|
61
|
+
/** 发 ref 那一刻的可访问名(空串表示无名)。 */
|
|
62
|
+
name: string;
|
|
63
|
+
/** 发 ref 时的快照代际。 */
|
|
64
|
+
generation: number;
|
|
65
|
+
}
|
|
66
|
+
/** {@link serializeAxTree} 的入参。 */
|
|
67
|
+
export interface SerializeOptions {
|
|
68
|
+
/** true = 完整树(含标题、段落这类上下文);false = 只列可交互元素。 */
|
|
69
|
+
full: boolean;
|
|
70
|
+
/** 本次快照的代际,写进每个 ref。 */
|
|
71
|
+
generation: number;
|
|
72
|
+
}
|
|
73
|
+
/** 文本化结果。 */
|
|
74
|
+
export interface SerializedSnapshot {
|
|
75
|
+
/** 树文本(不含页眉页脚,围栏与截断由调用方处理)。 */
|
|
76
|
+
text: string;
|
|
77
|
+
/** ref → 记录(只含本视图里出现过的 ref)。 */
|
|
78
|
+
refs: Map<string, SnapshotRef>;
|
|
79
|
+
/** 发放的 ref 个数。 */
|
|
80
|
+
refCount: number;
|
|
81
|
+
/** 本视图里可交互节点个数(含没拿到 backendDOMNodeId 的)。 */
|
|
82
|
+
interactiveCount: number;
|
|
83
|
+
/** 树文本行数(未截断时)。 */
|
|
84
|
+
lineCount: number;
|
|
85
|
+
}
|
|
86
|
+
/** 按行截断的结果。 */
|
|
87
|
+
export interface LineTruncation {
|
|
88
|
+
text: string;
|
|
89
|
+
truncated: boolean;
|
|
90
|
+
/** 保留了几行。 */
|
|
91
|
+
shownLines: number;
|
|
92
|
+
/** 原本几行。 */
|
|
93
|
+
totalLines: number;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* 把一棵无障碍树文本化。
|
|
97
|
+
*
|
|
98
|
+
* 视图规则:
|
|
99
|
+
* - compact(`full: false`):只列可交互角色;容器与文本角色不列,但**继续遍历它们的子节点**,
|
|
100
|
+
* 所以 `<div><button>存</button></div>` 里的按钮不会丢;
|
|
101
|
+
* - full:额外列 heading/paragraph/link 之外的结构节点,缩进反映层级,作为「这页长什么样」的上下文。
|
|
102
|
+
*
|
|
103
|
+
* ref 规则:compact 只给可交互节点发;full 给所有成行节点发
|
|
104
|
+
* (需求里给的样例形状就是 `- heading "Hello" [ref=e1]`——全量视图下连标题也能被点名)。
|
|
105
|
+
* 两种视图下 ref 都从 e1 起编,代际写进 {@link SnapshotRef}。
|
|
106
|
+
*/
|
|
107
|
+
export declare function serializeAxTree(tree: AxTree, options: SerializeOptions): SerializedSnapshot;
|
|
108
|
+
/**
|
|
109
|
+
* 按行截断,**绝不切到元素中间**。
|
|
110
|
+
*
|
|
111
|
+
* 超限时的做法:尽量多留整行,末尾补一句说明还剩几行(调用方决定那句话怎么写)。
|
|
112
|
+
* 上限小到连一行都放不下时,宁可留整行超一点点,也不把一行劈成两半——
|
|
113
|
+
* 半行 `- button [ref=e1` 会让模型编出一个不存在的 ref。
|
|
114
|
+
*/
|
|
115
|
+
export declare function truncateByLines(text: string, maxChars: number, note: (remaining: number) => string): LineTruncation;
|
|
116
|
+
/**
|
|
117
|
+
* 复核一个 ref 指向的节点是不是还和发 ref 时一样。
|
|
118
|
+
*
|
|
119
|
+
* 三个都算「页面已变」:节点没了、变成了 ignored(被藏起来)、role 或可访问名变了。
|
|
120
|
+
* 这一层是纯函数,CDP 取数据那部分在 `actions.ts` 的 `verifyRef` 里。
|
|
121
|
+
*/
|
|
122
|
+
export declare function refRecordMatches(record: SnapshotRef, node: AxNode | undefined): boolean;
|
|
123
|
+
/** {@link lookupSnapshotRef} 的结果。 */
|
|
124
|
+
export type RefLookup = {
|
|
125
|
+
ok: true;
|
|
126
|
+
ref: SnapshotRef;
|
|
127
|
+
} | {
|
|
128
|
+
ok: false;
|
|
129
|
+
reason: string;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* 从当前 ref 表里取一个 ref,顺带做**代际校验**。
|
|
133
|
+
*
|
|
134
|
+
* 三条拒绝理由分开写,是因为模型看到的东西不一样、该做的事也不一样:
|
|
135
|
+
* - 压根没给 ref → 让它先快照;
|
|
136
|
+
* - 不认识 / 被作废(导航过、换过目标)→ 带上作废原因,再让它快照;
|
|
137
|
+
* - 认识但属于上一代 → 明说「属于上一次快照」,而不是含糊的「失效」。
|
|
138
|
+
*/
|
|
139
|
+
export declare function lookupSnapshotRef(refs: ReadonlyMap<string, SnapshotRef>, ref: string, generation: number, invalidReason?: string): RefLookup;
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 无障碍树快照:`Accessibility.getFullAXTree` → 给模型看的文本树 + 行内 ref。
|
|
3
|
+
*
|
|
4
|
+
* 为什么用无障碍树而不是自己遍历 DOM:
|
|
5
|
+
* 1. role / name / checked / expanded 这些「这个东西是什么、叫什么、什么状态」
|
|
6
|
+
* 浏览器已经按 W3C 的规范算好了(含 `aria-*`、`<label for>`、`<button>` 的隐式角色)。
|
|
7
|
+
* 自己写等于重抄一份几千行的 accname 规范,抄不对还会算错;
|
|
8
|
+
* 2. 文本树天然是给模型看的形状——元素少、层级清楚、没有 style 噪音;
|
|
9
|
+
* 3. 每个节点带 `backendDOMNodeId`,这个号能直接喂给 `DOM.getBoxModel` /
|
|
10
|
+
* `DOM.setFileInputFiles` / `Input.*`,于是「模型只给 ref、我们负责落到像素」成立。
|
|
11
|
+
*
|
|
12
|
+
* ref 的两条规矩(这是与「截图 + 坐标」最大的差别):
|
|
13
|
+
* - **只给能动手的东西发 ref**:默认 compact 视图只列可交互角色(button/link/textbox/…),
|
|
14
|
+
* 模型拿到的每个 ref 都是能点能填的,不会去点一个装饰性的 div;
|
|
15
|
+
* - **ref 带代际**:每次快照递增 generation,动作前既核对 ref 属于本次快照,
|
|
16
|
+
* 又用 `DOM.describeNode` + `Accessibility.getPartialAXTree` 复核这个后端节点还在、
|
|
17
|
+
* role/name 没变(页面自己改了 DOM 而模型还照着旧快照动手,就靠这一步拦下来)。
|
|
18
|
+
*
|
|
19
|
+
* @module dsc/core/cdp/snapshot
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* 可交互角色白名单(小写比较)。
|
|
23
|
+
* 这些角色要么能点(button/link/menuitem/tab)、要么能填(textbox/combobox/checkbox/…)、
|
|
24
|
+
* 要么能拖(slider)。不在名单里的(heading/paragraph/generic/StaticText…)只做上下文,
|
|
25
|
+
* 默认视图不列,也不发 ref。
|
|
26
|
+
*/
|
|
27
|
+
export const INTERACTIVE_ROLES = new Set([
|
|
28
|
+
'button',
|
|
29
|
+
'link',
|
|
30
|
+
'textbox',
|
|
31
|
+
'searchbox',
|
|
32
|
+
'checkbox',
|
|
33
|
+
'radio',
|
|
34
|
+
'combobox',
|
|
35
|
+
'listbox',
|
|
36
|
+
'option',
|
|
37
|
+
'menuitem',
|
|
38
|
+
'menuitemcheckbox',
|
|
39
|
+
'menuitemradio',
|
|
40
|
+
'menulist',
|
|
41
|
+
'menulistoption',
|
|
42
|
+
'popupbutton',
|
|
43
|
+
'togglebutton',
|
|
44
|
+
'tab',
|
|
45
|
+
'switch',
|
|
46
|
+
'slider',
|
|
47
|
+
'spinbutton',
|
|
48
|
+
'treeitem',
|
|
49
|
+
]);
|
|
50
|
+
/** 纯文本角色:内容折进父节点的 `: 文本` 里,自己不成行(否则一页多出几百行噪音)。 */
|
|
51
|
+
const TEXT_ROLES = new Set(['statictext', 'inlinetextbox']);
|
|
52
|
+
/** 结构容器角色:全量视图也不单独成行,但**继续往下走**——可交互后代不能丢。 */
|
|
53
|
+
const CONTAINER_ROLES = new Set(['generic', 'none', 'presentation', 'rootwebarea']);
|
|
54
|
+
/** 值比名字更能说明现状的角色(输入框里填了什么,比它的 label 重要)。 */
|
|
55
|
+
const VALUE_FIRST_ROLES = new Set(['textbox', 'searchbox', 'spinbutton', 'slider', 'combobox']);
|
|
56
|
+
/** 一行里名字/文本最长多少字符(再长就是整段正文塞进一行)。 */
|
|
57
|
+
const MAX_INLINE_CHARS = 160;
|
|
58
|
+
/** 取无障碍值里的 value。 */
|
|
59
|
+
function axValue(field) {
|
|
60
|
+
return field === undefined ? undefined : field.value;
|
|
61
|
+
}
|
|
62
|
+
/** 节点的 role(小写;没有就空串)。 */
|
|
63
|
+
function roleOf(node) {
|
|
64
|
+
const value = axValue(node.role);
|
|
65
|
+
return typeof value === 'string' ? value.toLowerCase() : '';
|
|
66
|
+
}
|
|
67
|
+
/** 角色的显示名(保留浏览器给的原始大小写,`MenuListOption` 比 `menulistoption` 好读)。 */
|
|
68
|
+
function roleLabel(node) {
|
|
69
|
+
const value = axValue(node.role);
|
|
70
|
+
return typeof value === 'string' ? value : 'unknown';
|
|
71
|
+
}
|
|
72
|
+
/** 压成一行并截断(快照是一行一个元素,绝不能带换行)。 */
|
|
73
|
+
function oneLine(text) {
|
|
74
|
+
const flat = text.replace(/\s+/g, ' ').trim();
|
|
75
|
+
return flat.length > MAX_INLINE_CHARS ? `${flat.slice(0, MAX_INLINE_CHARS)}…` : flat;
|
|
76
|
+
}
|
|
77
|
+
/** 节点的可访问名(浏览器算好的,直接抄)。 */
|
|
78
|
+
function nameOf(node) {
|
|
79
|
+
const value = axValue(node.name);
|
|
80
|
+
return typeof value === 'string' ? oneLine(value) : '';
|
|
81
|
+
}
|
|
82
|
+
/** 节点的当前值(输入框里填的内容)。 */
|
|
83
|
+
function valueOf(node) {
|
|
84
|
+
const value = axValue(node.value);
|
|
85
|
+
if (typeof value === 'string')
|
|
86
|
+
return oneLine(value);
|
|
87
|
+
if (typeof value === 'number' || typeof value === 'boolean')
|
|
88
|
+
return String(value);
|
|
89
|
+
return '';
|
|
90
|
+
}
|
|
91
|
+
/** 属性表:`checked` / `disabled` / `expanded` 这些状态都在这里。 */
|
|
92
|
+
function propertiesOf(node) {
|
|
93
|
+
const map = new Map();
|
|
94
|
+
for (const property of node.properties ?? []) {
|
|
95
|
+
if (typeof property.name !== 'string')
|
|
96
|
+
continue;
|
|
97
|
+
map.set(property.name.toLowerCase(), axValue(property.value));
|
|
98
|
+
}
|
|
99
|
+
return map;
|
|
100
|
+
}
|
|
101
|
+
/** 状态后缀:一行里把「禁用/勾上/展开/几级标题」直接写出来,模型不用再问一次。 */
|
|
102
|
+
function flagsOf(node) {
|
|
103
|
+
const props = propertiesOf(node);
|
|
104
|
+
const flags = [];
|
|
105
|
+
const strict = (value, positive, negative) => {
|
|
106
|
+
if (value === true || value === 'true')
|
|
107
|
+
flags.push(` [${positive}]`);
|
|
108
|
+
else if (negative !== undefined && (value === false || value === 'false'))
|
|
109
|
+
flags.push(` [${negative}]`);
|
|
110
|
+
};
|
|
111
|
+
strict(props.get('checked'), 'checked', 'not-checked');
|
|
112
|
+
strict(props.get('disabled'), 'disabled');
|
|
113
|
+
strict(props.get('readonly') ?? props.get('readOnly'), 'readonly');
|
|
114
|
+
strict(props.get('required'), 'required');
|
|
115
|
+
strict(props.get('expanded'), 'expanded', 'collapsed');
|
|
116
|
+
strict(props.get('selected'), 'selected');
|
|
117
|
+
strict(props.get('pressed'), 'pressed');
|
|
118
|
+
strict(props.get('hidden'), 'hidden');
|
|
119
|
+
strict(props.get('invalid'), 'invalid');
|
|
120
|
+
const level = props.get('level');
|
|
121
|
+
if (typeof level === 'number' && level > 0)
|
|
122
|
+
flags.push(` [level=${level}]`);
|
|
123
|
+
const popup = props.get('haspopup');
|
|
124
|
+
if (typeof popup === 'string' && popup !== '' && popup !== 'false')
|
|
125
|
+
flags.push(` [popup=${popup}]`);
|
|
126
|
+
return flags.join('');
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 把一棵无障碍树文本化。
|
|
130
|
+
*
|
|
131
|
+
* 视图规则:
|
|
132
|
+
* - compact(`full: false`):只列可交互角色;容器与文本角色不列,但**继续遍历它们的子节点**,
|
|
133
|
+
* 所以 `<div><button>存</button></div>` 里的按钮不会丢;
|
|
134
|
+
* - full:额外列 heading/paragraph/link 之外的结构节点,缩进反映层级,作为「这页长什么样」的上下文。
|
|
135
|
+
*
|
|
136
|
+
* ref 规则:compact 只给可交互节点发;full 给所有成行节点发
|
|
137
|
+
* (需求里给的样例形状就是 `- heading "Hello" [ref=e1]`——全量视图下连标题也能被点名)。
|
|
138
|
+
* 两种视图下 ref 都从 e1 起编,代际写进 {@link SnapshotRef}。
|
|
139
|
+
*/
|
|
140
|
+
export function serializeAxTree(tree, options) {
|
|
141
|
+
const nodes = tree.nodes ?? [];
|
|
142
|
+
const byId = new Map();
|
|
143
|
+
for (const node of nodes) {
|
|
144
|
+
if (typeof node.nodeId === 'string')
|
|
145
|
+
byId.set(node.nodeId, node);
|
|
146
|
+
}
|
|
147
|
+
// 找根:谁都没被当成孩子(getFullAXTree 通常只有一个根)
|
|
148
|
+
const childSet = new Set();
|
|
149
|
+
for (const node of nodes) {
|
|
150
|
+
for (const child of node.childIds ?? [])
|
|
151
|
+
childSet.add(child);
|
|
152
|
+
}
|
|
153
|
+
const roots = nodes.filter((node) => typeof node.nodeId !== 'string' || !childSet.has(node.nodeId));
|
|
154
|
+
const lines = [];
|
|
155
|
+
const refs = new Map();
|
|
156
|
+
const refOfBackend = new Map();
|
|
157
|
+
let refSeq = 0;
|
|
158
|
+
let interactiveCount = 0;
|
|
159
|
+
const refFor = (node, interactive) => {
|
|
160
|
+
const backendNodeId = node.backendDOMNodeId;
|
|
161
|
+
if (typeof backendNodeId !== 'number' || backendNodeId <= 0)
|
|
162
|
+
return '';
|
|
163
|
+
if (!interactive && !options.full)
|
|
164
|
+
return '';
|
|
165
|
+
const existing = refOfBackend.get(backendNodeId);
|
|
166
|
+
if (existing !== undefined)
|
|
167
|
+
return existing;
|
|
168
|
+
refSeq += 1;
|
|
169
|
+
const ref = `e${refSeq}`;
|
|
170
|
+
refs.set(ref, { ref, backendNodeId, role: roleLabel(node), name: nameOf(node), generation: options.generation });
|
|
171
|
+
refOfBackend.set(backendNodeId, ref);
|
|
172
|
+
return ref;
|
|
173
|
+
};
|
|
174
|
+
const walk = (node, depth, visited) => {
|
|
175
|
+
const nodeId = node.nodeId;
|
|
176
|
+
if (typeof nodeId === 'string') {
|
|
177
|
+
if (visited.has(nodeId))
|
|
178
|
+
return; // 协议不该有环,真出现了也别转死
|
|
179
|
+
visited.add(nodeId);
|
|
180
|
+
}
|
|
181
|
+
const role = roleOf(node);
|
|
182
|
+
const interactive = INTERACTIVE_ROLES.has(role);
|
|
183
|
+
const children = (node.childIds ?? []).map((id) => byId.get(id)).filter((child) => child !== undefined);
|
|
184
|
+
// 文本:直接/隔着一层容器包着的 StaticText 折进来
|
|
185
|
+
const inline = collectText(node, children, byId, 0);
|
|
186
|
+
const ignored = node.ignored === true;
|
|
187
|
+
// 计数只算真正露出来的可交互节点:ignored 的那些模型根本看不到,不该算进「本页有几个可点」
|
|
188
|
+
if (interactive && !ignored)
|
|
189
|
+
interactiveCount += 1;
|
|
190
|
+
const printable = !ignored && !TEXT_ROLES.has(role) && (interactive || (options.full && !CONTAINER_ROLES.has(role)));
|
|
191
|
+
let nextDepth = depth;
|
|
192
|
+
if (printable) {
|
|
193
|
+
const name = nameOf(node);
|
|
194
|
+
const valueText = valueOf(node);
|
|
195
|
+
const text = (VALUE_FIRST_ROLES.has(role) && valueText !== '' ? valueText : inline !== '' ? inline : valueText);
|
|
196
|
+
const ref = refFor(node, interactive);
|
|
197
|
+
const label = name === '' ? '' : ` "${name}"`;
|
|
198
|
+
const suffix = text === '' || name.includes(text) ? '' : `: ${text}`;
|
|
199
|
+
const indent = options.full ? ' '.repeat(Math.min(depth, 12)) : '';
|
|
200
|
+
const refPart = ref === '' ? '' : ` [ref=${ref}]`;
|
|
201
|
+
lines.push(`${indent}- ${roleLabel(node)}${label}${refPart}${flagsOf(node)}${suffix}`);
|
|
202
|
+
nextDepth = depth + 1;
|
|
203
|
+
}
|
|
204
|
+
for (const child of children)
|
|
205
|
+
walk(child, nextDepth, visited);
|
|
206
|
+
};
|
|
207
|
+
for (const root of roots)
|
|
208
|
+
walk(root, 0, new Set());
|
|
209
|
+
return {
|
|
210
|
+
text: lines.join('\n'),
|
|
211
|
+
refs,
|
|
212
|
+
refCount: refs.size,
|
|
213
|
+
interactiveCount,
|
|
214
|
+
lineCount: lines.length,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* 折下层文本:只穿 `StaticText`/`InlineTextBox` 和容器角色,遇到别的角色就停。
|
|
219
|
+
* 停在别的角色上是关键——不能让一个按钮的文本把整页正文都吸进来。
|
|
220
|
+
*/
|
|
221
|
+
function collectText(node, children, byId, depth) {
|
|
222
|
+
if (depth > 6)
|
|
223
|
+
return '';
|
|
224
|
+
const role = roleOf(node);
|
|
225
|
+
const parts = [];
|
|
226
|
+
if (TEXT_ROLES.has(role)) {
|
|
227
|
+
const value = axValue(node.name) ?? axValue(node.value);
|
|
228
|
+
if (typeof value === 'string' && value.trim() !== '')
|
|
229
|
+
parts.push(oneLine(value));
|
|
230
|
+
}
|
|
231
|
+
for (const child of children) {
|
|
232
|
+
const childRole = roleOf(child);
|
|
233
|
+
if (!TEXT_ROLES.has(childRole) && !CONTAINER_ROLES.has(childRole) && child.ignored !== true)
|
|
234
|
+
continue;
|
|
235
|
+
const grandChildren = (child.childIds ?? []).map((id) => byId.get(id)).filter((item) => item !== undefined);
|
|
236
|
+
const nested = collectText(child, grandChildren, byId, depth + 1);
|
|
237
|
+
if (nested !== '')
|
|
238
|
+
parts.push(nested);
|
|
239
|
+
}
|
|
240
|
+
return oneLine(parts.join(' '));
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* 按行截断,**绝不切到元素中间**。
|
|
244
|
+
*
|
|
245
|
+
* 超限时的做法:尽量多留整行,末尾补一句说明还剩几行(调用方决定那句话怎么写)。
|
|
246
|
+
* 上限小到连一行都放不下时,宁可留整行超一点点,也不把一行劈成两半——
|
|
247
|
+
* 半行 `- button [ref=e1` 会让模型编出一个不存在的 ref。
|
|
248
|
+
*/
|
|
249
|
+
export function truncateByLines(text, maxChars, note) {
|
|
250
|
+
const lines = text.split('\n');
|
|
251
|
+
if (text.length <= maxChars) {
|
|
252
|
+
return { text, truncated: false, shownLines: lines.length, totalLines: lines.length };
|
|
253
|
+
}
|
|
254
|
+
const reserve = Math.min(note(lines.length).length + 1, Math.max(1, Math.floor(maxChars / 3)));
|
|
255
|
+
const keep = [];
|
|
256
|
+
let used = 0;
|
|
257
|
+
for (const line of lines) {
|
|
258
|
+
if (used + line.length + 1 > maxChars - reserve)
|
|
259
|
+
break;
|
|
260
|
+
keep.push(line);
|
|
261
|
+
used += line.length + 1;
|
|
262
|
+
}
|
|
263
|
+
if (keep.length === 0)
|
|
264
|
+
keep.push(lines[0] ?? '');
|
|
265
|
+
const remaining = lines.length - keep.length;
|
|
266
|
+
return {
|
|
267
|
+
text: [...keep, note(remaining)].join('\n'),
|
|
268
|
+
truncated: true,
|
|
269
|
+
shownLines: keep.length,
|
|
270
|
+
totalLines: lines.length,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* 复核一个 ref 指向的节点是不是还和发 ref 时一样。
|
|
275
|
+
*
|
|
276
|
+
* 三个都算「页面已变」:节点没了、变成了 ignored(被藏起来)、role 或可访问名变了。
|
|
277
|
+
* 这一层是纯函数,CDP 取数据那部分在 `actions.ts` 的 `verifyRef` 里。
|
|
278
|
+
*/
|
|
279
|
+
export function refRecordMatches(record, node) {
|
|
280
|
+
if (node === undefined)
|
|
281
|
+
return false;
|
|
282
|
+
if (node.ignored === true)
|
|
283
|
+
return false;
|
|
284
|
+
if (typeof node.backendDOMNodeId === 'number' && node.backendDOMNodeId !== record.backendNodeId)
|
|
285
|
+
return false;
|
|
286
|
+
const role = roleLabel(node);
|
|
287
|
+
if (role !== 'unknown' && role.toLowerCase() !== record.role.toLowerCase())
|
|
288
|
+
return false;
|
|
289
|
+
return nameOf(node) === record.name;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* 从当前 ref 表里取一个 ref,顺带做**代际校验**。
|
|
293
|
+
*
|
|
294
|
+
* 三条拒绝理由分开写,是因为模型看到的东西不一样、该做的事也不一样:
|
|
295
|
+
* - 压根没给 ref → 让它先快照;
|
|
296
|
+
* - 不认识 / 被作废(导航过、换过目标)→ 带上作废原因,再让它快照;
|
|
297
|
+
* - 认识但属于上一代 → 明说「属于上一次快照」,而不是含糊的「失效」。
|
|
298
|
+
*/
|
|
299
|
+
export function lookupSnapshotRef(refs, ref, generation, invalidReason = '') {
|
|
300
|
+
const name = ref.trim();
|
|
301
|
+
if (name === '') {
|
|
302
|
+
return { ok: false, reason: '这次动作要一个 ref(形如 e5)。先 browser_look action=snapshot 拿一份快照' };
|
|
303
|
+
}
|
|
304
|
+
const record = refs.get(name);
|
|
305
|
+
if (record === undefined) {
|
|
306
|
+
const why = invalidReason === '' ? '' : `${invalidReason};`;
|
|
307
|
+
return { ok: false, reason: `不认识 ref「${name}」:${why}请先 browser_look action=snapshot 拿一份新快照` };
|
|
308
|
+
}
|
|
309
|
+
if (record.generation !== generation) {
|
|
310
|
+
return {
|
|
311
|
+
ok: false,
|
|
312
|
+
reason: `ref「${name}」属于上一次快照:页面已变,请重新 snapshot(browser_look action=snapshot)再动手`,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
return { ok: true, ref: record };
|
|
316
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CDP(Chrome DevTools Protocol)消息层:连接、命令应答、事件分发、session 路由。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单独一层:`examples/plugins/browser-control.js` 那种写法只有「id 配对 + pending Map」,
|
|
5
|
+
* 收帧时但凡没有 id 就整条丢掉——对话框(`Page.javascriptDialogOpening`)、
|
|
6
|
+
* 控制台(`Runtime.consoleAPICalled`)、网络(`Network.responseReceived`)、
|
|
7
|
+
* 页面跳转(`Page.frameNavigated`)全都是**没有 id 的事件**,靠那条路一个都拿不到,
|
|
8
|
+
* 于是「页面弹了确认框」这件事模型永远不知道,动作会一直卡到超时。
|
|
9
|
+
* 这里把事件订阅补上,并且显式分成两级:
|
|
10
|
+
* - 浏览器级连接(`--remote-debugging-port` 直连的那个 WebSocket):管 Target 域,
|
|
11
|
+
* 事件不带 `sessionId`;
|
|
12
|
+
* - 页面/框架级 session(`Target.attachToTarget { flatten: true }` 拿到的 sessionId):
|
|
13
|
+
* 管 Page/Runtime/DOM/Accessibility 域,事件带 `sessionId`。
|
|
14
|
+
* 两者复用同一条 WebSocket,靠 `sessionId` 字段区分——这正是本层必须做的事:
|
|
15
|
+
* 发命令时按 session 打标,收应答时核对 sessionId,收事件时按 sessionId 投递。
|
|
16
|
+
*
|
|
17
|
+
* 不引第三方包:WebSocket 用 Node 内置全局(Node ≥ 22.19 有)。
|
|
18
|
+
*
|
|
19
|
+
* @module dsc/core/cdp/transport
|
|
20
|
+
*/
|
|
21
|
+
/** 收到的一条 CDP 事件(没有 id 的帧)。 */
|
|
22
|
+
export interface CdpEvent {
|
|
23
|
+
method: string;
|
|
24
|
+
params: Record<string, unknown>;
|
|
25
|
+
/** undefined = 浏览器级事件;否则是某个页面/框架 session 的事件。 */
|
|
26
|
+
sessionId: string | undefined;
|
|
27
|
+
}
|
|
28
|
+
/** 事件处理器:第二参带 sessionId,方便只关心某一页的调用方自己过滤。 */
|
|
29
|
+
export type CdpEventHandler = (params: Record<string, unknown>, sessionId: string | undefined) => void;
|
|
30
|
+
/**
|
|
31
|
+
* 我们用到的那部分 WebSocket 形状。
|
|
32
|
+
* 刻意不写 `declare global` 引用 Node 的 WebSocket 类型:内置 WebSocket 的
|
|
33
|
+
* 环境类型随 Node 小版本变过,这里只声明自己用到的四个回调,运行时缺了就在
|
|
34
|
+
* {@link CdpTransport.open} 里报一句人话。
|
|
35
|
+
*/
|
|
36
|
+
export interface CdpSocket {
|
|
37
|
+
readyState: number;
|
|
38
|
+
send(data: string): void;
|
|
39
|
+
close(): void;
|
|
40
|
+
onopen: ((event: unknown) => void) | null;
|
|
41
|
+
onmessage: ((event: {
|
|
42
|
+
data: unknown;
|
|
43
|
+
}) => void) | null;
|
|
44
|
+
onclose: ((event: unknown) => void) | null;
|
|
45
|
+
onerror: ((event: unknown) => void) | null;
|
|
46
|
+
}
|
|
47
|
+
/** 一条命令的可选参数。 */
|
|
48
|
+
export interface CdpCommandOptions {
|
|
49
|
+
/** 目标 session;不给 = 浏览器级命令(Target 域)。 */
|
|
50
|
+
sessionId?: string;
|
|
51
|
+
/** 超时毫秒;<= 0 表示不设超时。 */
|
|
52
|
+
timeoutMs?: number;
|
|
53
|
+
/** 取消信号(用户打断时用来立刻结束等待)。 */
|
|
54
|
+
signal?: AbortSignal;
|
|
55
|
+
}
|
|
56
|
+
/** 传输层构造参数。 */
|
|
57
|
+
export interface CdpTransportOptions {
|
|
58
|
+
/** 单条命令的默认超时(缺省 20s:导航、录音这类命令本来就慢)。 */
|
|
59
|
+
defaultTimeoutMs?: number;
|
|
60
|
+
/** 建连超时(缺省 10s)。 */
|
|
61
|
+
openTimeoutMs?: number;
|
|
62
|
+
/** 假 socket 注入点(自检用);缺省用 Node 内置 WebSocket。 */
|
|
63
|
+
socketFactory?: (url: string) => CdpSocket;
|
|
64
|
+
/** 出错信息里的标签,例如「浏览器级」/「页面」;只影响可读性。 */
|
|
65
|
+
label?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 一条 CDP 连接。
|
|
69
|
+
*
|
|
70
|
+
* 生命周期:{@link CdpTransport.open} 建连 → `send` 发命令 / `on` 订事件 → `close` 收尾。
|
|
71
|
+
* 连接断开后本对象不可复用(要重连就新建一个),断线时所有挂着的命令会立刻被拒——
|
|
72
|
+
* 等 20 秒超时再报错会让人以为是页面慢,其实是连接没了。
|
|
73
|
+
*/
|
|
74
|
+
export declare class CdpTransport {
|
|
75
|
+
private readonly socket;
|
|
76
|
+
private readonly defaultTimeoutMs;
|
|
77
|
+
private readonly label;
|
|
78
|
+
private readonly pending;
|
|
79
|
+
private readonly handlers;
|
|
80
|
+
private readonly anyHandlers;
|
|
81
|
+
private readonly closeHandlers;
|
|
82
|
+
private nextId;
|
|
83
|
+
private closedFlag;
|
|
84
|
+
/** 断开原因:给重连逻辑判断「是浏览器死了还是我们主动关的」。 */
|
|
85
|
+
private closeReason;
|
|
86
|
+
private constructor();
|
|
87
|
+
/**
|
|
88
|
+
* 连上一个 WebSocket 端点并等握手完成。
|
|
89
|
+
*
|
|
90
|
+
* @param url - CDP 端点(`ws://127.0.0.1:PORT/devtools/browser/<uuid>`)。
|
|
91
|
+
* @param options - 见 {@link CdpTransportOptions}。
|
|
92
|
+
* @param signal - 取消信号:用户在握手期间按打断时立刻失败。
|
|
93
|
+
*/
|
|
94
|
+
static open(url: string, options?: CdpTransportOptions, signal?: AbortSignal): Promise<CdpTransport>;
|
|
95
|
+
/** 这条连接是不是已经断了(断了就不能再发命令)。 */
|
|
96
|
+
get closed(): boolean;
|
|
97
|
+
/** 断开原因(我们主动关的是「主动关闭」,否则是底层给的原文)。 */
|
|
98
|
+
get reason(): string;
|
|
99
|
+
/** 还挂着等应答的命令条数(诊断与自检用)。 */
|
|
100
|
+
get pendingCount(): number;
|
|
101
|
+
/**
|
|
102
|
+
* 发一条命令并等它的应答。
|
|
103
|
+
*
|
|
104
|
+
* @param method - CDP 方法名,例如 `Page.navigate`。
|
|
105
|
+
* @param params - 参数对象(缺省空对象)。
|
|
106
|
+
* @param options - sessionId / 超时 / 取消信号。
|
|
107
|
+
*/
|
|
108
|
+
send<T = unknown>(method: string, params?: Record<string, unknown>, options?: CdpCommandOptions): Promise<T>;
|
|
109
|
+
/**
|
|
110
|
+
* 订一条事件。返回退订函数。
|
|
111
|
+
*
|
|
112
|
+
* @param method - 事件名,例如 `Page.javascriptDialogOpening`。
|
|
113
|
+
* @param handler - 收到时调用;参数是事件 params,第二参是 sessionId。
|
|
114
|
+
*/
|
|
115
|
+
on(method: string, handler: CdpEventHandler): () => void;
|
|
116
|
+
/** 订「全部事件」(调试与自检用)。返回退订函数。 */
|
|
117
|
+
onAny(handler: (event: CdpEvent) => void): () => void;
|
|
118
|
+
/**
|
|
119
|
+
* 订「连接断了」。返回退订函数。
|
|
120
|
+
* 崩溃重连靠它:浏览器被杀、页面被关、CDP 主动断,都会走到这里。
|
|
121
|
+
*/
|
|
122
|
+
onClose(handler: (reason: string) => void): () => void;
|
|
123
|
+
/** 主动关闭:挂着的命令会以「连接已关闭」被拒。 */
|
|
124
|
+
close(): void;
|
|
125
|
+
/** 取某个 session 的视图(命令自动带 sessionId,事件按 sessionId 过滤)。 */
|
|
126
|
+
session(sessionId: string): CdpSessionView;
|
|
127
|
+
/** 收帧:先看是不是应答,再看是不是事件。 */
|
|
128
|
+
private acceptFrame;
|
|
129
|
+
/** 应答投递:核对 sessionId(发出了带 session 的命令,应答也必须带同一个 session)。 */
|
|
130
|
+
private deliverResponse;
|
|
131
|
+
/** 断开:先给挂着的命令一个明确死因,再通知重连方。 */
|
|
132
|
+
private handleClose;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* 「能执行 CDP 命令的那点东西」——快照层与动作层真正依赖的形状。
|
|
136
|
+
*
|
|
137
|
+
* 为什么单独抽这一层:`CdpSessionView` 是一条 WebSocket 连接上的一个 session,
|
|
138
|
+
* 而 dock 视图(侧栏里那台浏览器)没有 WebSocket——命令经宿主协议转给桌面主进程,
|
|
139
|
+
* 由那边的 `webContents.debugger` 执行。抽成结构类型之后,`src/core/cdp/` 里那套
|
|
140
|
+
* 快照与动作两条后端共用一份,不必各写一遍,也不必为了「长得像」去伪造一个连接对象。
|
|
141
|
+
*/
|
|
142
|
+
export interface CdpCommandTarget {
|
|
143
|
+
readonly sessionId: string;
|
|
144
|
+
/** 发一条命令。 */
|
|
145
|
+
send<T = unknown>(method: string, params?: Record<string, unknown>, options?: Omit<CdpCommandOptions, 'sessionId'>): Promise<T>;
|
|
146
|
+
/** 订事件(没有 session 概念的实现自己按视图过滤)。 */
|
|
147
|
+
on(method: string, handler: (params: Record<string, unknown>) => void): () => void;
|
|
148
|
+
}
|
|
149
|
+
/** 一个 session 上的便利视图:省得每次发命令都手写 sessionId。 */
|
|
150
|
+
export declare class CdpSessionView implements CdpCommandTarget {
|
|
151
|
+
readonly sessionId: string;
|
|
152
|
+
private readonly transport;
|
|
153
|
+
constructor(transport: CdpTransport, sessionId: string);
|
|
154
|
+
/** 发一条属于这个 session 的命令。 */
|
|
155
|
+
send<T = unknown>(method: string, params?: Record<string, unknown>, options?: Omit<CdpCommandOptions, 'sessionId'>): Promise<T>;
|
|
156
|
+
/** 订这个 session 的事件(浏览器级事件不会投到这里)。返回退订函数。 */
|
|
157
|
+
on(method: string, handler: (params: Record<string, unknown>) => void): () => void;
|
|
158
|
+
/** 这条 session 所在的连接(重连判断与关浏览器时要用)。 */
|
|
159
|
+
get connection(): CdpTransport;
|
|
160
|
+
}
|