@capyclaw/browser-workbench 0.1.0 → 0.1.17
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/README.md +29 -7
- package/contract/browser-contract.json +484 -25
- package/demo/form.html +27 -0
- package/lib/host.mjs +1 -68
- package/node_modules/@capyclaw/asset-service/README.md +48 -0
- package/node_modules/@capyclaw/asset-service/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/asset-service/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/asset-service/lib/host.mjs +14 -0
- package/node_modules/@capyclaw/asset-service/package.json +59 -0
- package/node_modules/@capyclaw/asset-service/src/index.mjs +223 -0
- package/node_modules/@capyclaw/document-workbench/README.md +125 -0
- package/node_modules/@capyclaw/document-workbench/package.json +44 -0
- package/node_modules/@capyclaw/document-workbench/src/bridge/index.mjs +321 -0
- package/node_modules/@capyclaw/document-workbench/src/client/index.mjs +625 -0
- package/node_modules/@capyclaw/document-workbench/src/client/screenshot.mjs +98 -0
- package/node_modules/@capyclaw/document-workbench/src/index.mjs +9 -0
- package/node_modules/@capyclaw/document-workbench/src/model/audit.mjs +101 -0
- package/node_modules/@capyclaw/document-workbench/src/model/conformance.mjs +92 -0
- package/node_modules/@capyclaw/document-workbench/src/model/ids.mjs +56 -0
- package/node_modules/@capyclaw/document-workbench/src/model/index.mjs +18 -0
- package/node_modules/@capyclaw/document-workbench/src/model/locate.mjs +118 -0
- package/node_modules/@capyclaw/document-workbench/src/model/manifest.mjs +148 -0
- package/node_modules/@capyclaw/document-workbench/src/model/ops.mjs +160 -0
- package/node_modules/@capyclaw/document-workbench/src/model/validate.mjs +72 -0
- package/node_modules/@capyclaw/document-workbench/src/ops/index.mjs +93 -0
- package/node_modules/@capyclaw/document-workbench/src/session/context.mjs +91 -0
- package/node_modules/@capyclaw/document-workbench/src/session/index.mjs +394 -0
- package/node_modules/@capyclaw/document-workbench/src/session/lease.mjs +105 -0
- package/node_modules/@capyclaw/document-workbench/src/session/mode.mjs +80 -0
- package/node_modules/@capyclaw/document-workbench/src/session/sanitize.mjs +107 -0
- package/node_modules/@capyclaw/document-workbench/src/session/state.mjs +159 -0
- package/node_modules/@capyclaw/document-workbench/src/session/watch.mjs +63 -0
- package/{server/shared/state-service.mjs → node_modules/@capyclaw/document-workbench/src/store/file-backend.mjs} +6 -97
- package/node_modules/@capyclaw/document-workbench/src/testing/index.mjs +75 -0
- package/node_modules/@capyclaw/foundation/README.md +51 -0
- package/node_modules/@capyclaw/foundation/abi/bridge.mjs +86 -0
- package/node_modules/@capyclaw/foundation/abi/errors.mjs +63 -0
- package/node_modules/@capyclaw/foundation/abi/index.mjs +35 -0
- package/node_modules/@capyclaw/foundation/abi/kinds.mjs +271 -0
- package/node_modules/@capyclaw/foundation/abi/loader.mjs +345 -0
- package/node_modules/@capyclaw/foundation/abi/schema.mjs +98 -0
- package/node_modules/@capyclaw/foundation/abi/spec.mjs +255 -0
- package/node_modules/@capyclaw/foundation/abi/validate.mjs +24 -0
- package/node_modules/@capyclaw/foundation/abi/version.mjs +82 -0
- package/node_modules/@capyclaw/foundation/cordis.patch.yml +5 -0
- package/node_modules/@capyclaw/foundation/kit/index.mjs +6 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/client-panel.mjs +98 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/host-event.mjs +35 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/http-router.mjs +69 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +55 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/own-server.mjs +113 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +68 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +113 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/service-provider.mjs +77 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/skill-provider.mjs +56 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/tool-provider.mjs +50 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/ui-panel.mjs +64 -0
- package/node_modules/@capyclaw/foundation/lib/ctx-service.mjs +42 -0
- package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +34 -0
- package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +85 -0
- package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +50 -0
- package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +160 -0
- package/node_modules/@capyclaw/foundation/lib/host.mjs +23 -0
- package/node_modules/@capyclaw/foundation/lib/kernel.mjs +185 -0
- package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +87 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/events.mjs +60 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/log.mjs +51 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +188 -0
- package/node_modules/@capyclaw/foundation/package.json +53 -0
- package/node_modules/@capyclaw/foundation/runtime/index.mjs +20 -0
- package/node_modules/@capyclaw/plugin-kit/INTEGRATION.md +100 -0
- package/node_modules/@capyclaw/plugin-kit/README.md +70 -0
- package/node_modules/@capyclaw/plugin-kit/bin/sync.mjs +103 -0
- package/node_modules/@capyclaw/plugin-kit/package.json +69 -0
- package/node_modules/@capyclaw/plugin-kit/src/cli.mjs +56 -0
- package/node_modules/@capyclaw/plugin-kit/src/config.mjs +142 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +129 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +139 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/shadow.mjs +219 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/transport.js +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/index.mjs +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/pack.mjs +230 -0
- package/node_modules/@capyclaw/plugin-kit/src/runtime/context.mjs +128 -0
- package/node_modules/@capyclaw/plugin-kit/src/self-contained.mjs +307 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/api.mjs +45 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/http.mjs +113 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +143 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/server.mjs +131 -0
- package/node_modules/@capyclaw/plugin-kit/src/skills/provider.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/blob-store.mjs +109 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/content-store.mjs +17 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/journal-store.mjs +89 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/result.mjs +41 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/validate.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/tuning.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/fs-lock.mjs +132 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/http.mjs +130 -0
- package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +656 -0
- package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +181 -0
- package/node_modules/@capyclaw/service-host/README.md +86 -0
- package/node_modules/@capyclaw/service-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/service-host/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/service-host/lib/host.mjs +22 -0
- package/node_modules/@capyclaw/service-host/package.json +60 -0
- package/node_modules/@capyclaw/service-host/src/index.mjs +571 -0
- package/node_modules/@capyclaw/service-host/src/tuning.mjs +63 -0
- package/node_modules/@capyclaw/tool-host/README.md +56 -0
- package/node_modules/@capyclaw/tool-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/tool-host/dsh-suite.json +30 -0
- package/node_modules/@capyclaw/tool-host/lib/host.mjs +16 -0
- package/node_modules/@capyclaw/tool-host/package.json +59 -0
- package/node_modules/@capyclaw/tool-host/src/descriptors.mjs +142 -0
- package/node_modules/@capyclaw/tool-host/src/index.mjs +390 -0
- package/node_modules/playwright/LICENSE +202 -0
- package/node_modules/playwright/NOTICE +5 -0
- package/node_modules/playwright/README.md +318 -0
- package/node_modules/playwright/ThirdPartyNotices.txt +14 -0
- package/node_modules/playwright/cli.js +19 -0
- package/node_modules/playwright/index.d.ts +17 -0
- package/node_modules/playwright/index.js +17 -0
- package/node_modules/playwright/index.mjs +18 -0
- package/node_modules/playwright/lib/agents/agentParser.js +89 -0
- package/node_modules/playwright/lib/agents/copilot-setup-steps.yml +34 -0
- package/node_modules/playwright/lib/agents/generateAgents.js +395 -0
- package/node_modules/playwright/lib/agents/playwright-test-coverage.prompt.md +31 -0
- package/node_modules/playwright/lib/agents/playwright-test-generate.prompt.md +8 -0
- package/node_modules/playwright/lib/agents/playwright-test-generator.agent.md +88 -0
- package/node_modules/playwright/lib/agents/playwright-test-heal.prompt.md +6 -0
- package/node_modules/playwright/lib/agents/playwright-test-healer.agent.md +56 -0
- package/node_modules/playwright/lib/agents/playwright-test-plan.prompt.md +9 -0
- package/node_modules/playwright/lib/agents/playwright-test-planner.agent.md +74 -0
- package/node_modules/playwright/lib/cli/reportActions.js +78 -0
- package/node_modules/playwright/lib/cli/testActions.js +217 -0
- package/node_modules/playwright/lib/common/index.js +2937 -0
- package/node_modules/playwright/lib/common/index.js.txt +33 -0
- package/node_modules/playwright/lib/errorContext.js +129 -0
- package/node_modules/playwright/lib/globals.js +58 -0
- package/node_modules/playwright/lib/index.js +827 -0
- package/node_modules/playwright/lib/isomorphic.js +260 -0
- package/node_modules/playwright/lib/isomorphic.js.txt +9 -0
- package/node_modules/playwright/lib/loader/loaderProcessEntry.js +34 -0
- package/node_modules/playwright/lib/loader/loaderProcessEntry.js.txt +9 -0
- package/node_modules/playwright/lib/matchers/expect.js +13496 -0
- package/node_modules/playwright/lib/matchers/expect.js.LICENSE +640 -0
- package/node_modules/playwright/lib/matchers/expect.js.txt +67 -0
- package/node_modules/playwright/lib/package.js +47 -0
- package/node_modules/playwright/lib/program.js +242 -0
- package/node_modules/playwright/lib/runner/index.js +8721 -0
- package/node_modules/playwright/lib/runner/index.js.txt +62 -0
- package/node_modules/playwright/lib/transform/babelBundle.js +72490 -0
- package/node_modules/playwright/lib/transform/babelBundle.js.LICENSE +2384 -0
- package/node_modules/playwright/lib/transform/babelBundle.js.txt +328 -0
- package/node_modules/playwright/lib/transform/esmLoader.js +8066 -0
- package/node_modules/playwright/lib/transform/esmLoader.js.LICENSE +355 -0
- package/node_modules/playwright/lib/transform/esmLoader.js.txt +60 -0
- package/node_modules/playwright/lib/util.js +373 -0
- package/node_modules/playwright/lib/worker/workerProcessEntry.js +1860 -0
- package/node_modules/playwright/lib/worker/workerProcessEntry.js.txt +19 -0
- package/node_modules/playwright/package.json +50 -0
- package/node_modules/playwright/test.d.ts +18 -0
- package/node_modules/playwright/test.js +24 -0
- package/node_modules/playwright/test.mjs +35 -0
- package/node_modules/playwright/types/test.d.ts +11191 -0
- package/node_modules/playwright/types/testReporter.d.ts +950 -0
- package/node_modules/playwright-core/LICENSE +202 -0
- package/node_modules/playwright-core/NOTICE +5 -0
- package/node_modules/playwright-core/README.md +3 -0
- package/node_modules/playwright-core/ThirdPartyNotices.txt +13 -0
- package/node_modules/playwright-core/bin/install_media_pack.ps1 +5 -0
- package/node_modules/playwright-core/bin/install_webkit_wsl.ps1 +33 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_beta_linux.sh +42 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_beta_mac.sh +13 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_beta_win.ps1 +24 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_stable_linux.sh +42 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_stable_mac.sh +12 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_stable_win.ps1 +24 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_beta_linux.sh +48 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_beta_mac.sh +11 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_beta_win.ps1 +23 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_dev_linux.sh +48 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_dev_mac.sh +11 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_dev_win.ps1 +23 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_stable_linux.sh +48 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_stable_mac.sh +11 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_stable_win.ps1 +24 -0
- package/node_modules/playwright-core/browsers.json +52 -0
- package/node_modules/playwright-core/cli.js +22 -0
- package/node_modules/playwright-core/index.d.ts +17 -0
- package/node_modules/playwright-core/index.js +17 -0
- package/node_modules/playwright-core/index.mjs +28 -0
- package/node_modules/playwright-core/lib/bootstrap.js +149 -0
- package/node_modules/playwright-core/lib/coreBundle.js +78041 -0
- package/node_modules/playwright-core/lib/entry/cliDaemon.js +5 -0
- package/node_modules/playwright-core/lib/entry/dashboardApp.js +3 -0
- package/node_modules/playwright-core/lib/entry/mcp.js +10 -0
- package/node_modules/playwright-core/lib/entry/oopBrowserDownload.js +3 -0
- package/node_modules/playwright-core/lib/package.js +50 -0
- package/node_modules/playwright-core/lib/server/chromium/appIcon.png +0 -0
- package/node_modules/playwright-core/lib/server/electron/loader.js +123 -0
- package/node_modules/playwright-core/lib/serverRegistry.js +1939 -0
- package/node_modules/playwright-core/lib/serverRegistry.js.LICENSE +65 -0
- package/node_modules/playwright-core/lib/tools/cli-client/channelSessions.js +141 -0
- package/node_modules/playwright-core/lib/tools/cli-client/cli.js +7 -0
- package/node_modules/playwright-core/lib/tools/cli-client/help.json +808 -0
- package/node_modules/playwright-core/lib/tools/cli-client/minimist.js +128 -0
- package/node_modules/playwright-core/lib/tools/cli-client/output.js +352 -0
- package/node_modules/playwright-core/lib/tools/cli-client/program.js +422 -0
- package/node_modules/playwright-core/lib/tools/cli-client/registry.js +180 -0
- package/node_modules/playwright-core/lib/tools/cli-client/session.js +261 -0
- package/node_modules/playwright-core/lib/tools/dashboard/appIcon.png +0 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/SKILL.md +493 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/element-attributes.md +23 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/playwright-tests.md +39 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/pr-attachments.md +60 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/request-mocking.md +87 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/running-code.md +245 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/session-management.md +227 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/storage-state.md +275 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/test-generation.md +433 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/tracing.md +139 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/video-recording.md +216 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/SKILL.md +136 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/gallery-spec.md +144 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/migration.md +89 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/react.md +69 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/typing.md +173 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/vue.md +77 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-trace/SKILL.md +174 -0
- package/node_modules/playwright-core/lib/tools/utils/extension.js +112 -0
- package/node_modules/playwright-core/lib/tools/utils/socketConnection.js +108 -0
- package/node_modules/playwright-core/lib/utilsBundle.js +86078 -0
- package/node_modules/playwright-core/lib/utilsBundle.js.LICENSE +1890 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/codeMirrorModule--QdMvsKi.css +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/codeMirrorModule-CQ8RZGBm.js +32 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/codicon-DCmgc-ay.ttf +0 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/firefox-1bWoP6pv.svg +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/firefox-beta-k3eOH_eK.svg +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/firefox-nightly-Cp5nfeDT.svg +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/index-AwgwcYie.css +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/index-hRvO4yU2.js +12 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/safari-na3_-uQk.svg +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/index.html +29 -0
- package/node_modules/playwright-core/lib/vite/dashboard/playwright-logo.svg +24 -0
- package/node_modules/playwright-core/lib/vite/htmlReport/index.html +16 -0
- package/node_modules/playwright-core/lib/vite/htmlReport/report.css +2 -0
- package/node_modules/playwright-core/lib/vite/htmlReport/report.js +32 -0
- package/node_modules/playwright-core/lib/vite/recorder/assets/codeMirrorModule--QdMvsKi.css +1 -0
- package/node_modules/playwright-core/lib/vite/recorder/assets/codeMirrorModule-DK72OMRi.js +32 -0
- package/node_modules/playwright-core/lib/vite/recorder/assets/codicon-DCmgc-ay.ttf +0 -0
- package/node_modules/playwright-core/lib/vite/recorder/assets/index-BZpYJZ-P.css +1 -0
- package/node_modules/playwright-core/lib/vite/recorder/assets/index-Cn0mmDuv.js +129 -0
- package/node_modules/playwright-core/lib/vite/recorder/index.html +29 -0
- package/node_modules/playwright-core/lib/vite/recorder/playwright-logo.svg +9 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/assets/codeMirrorModule-BEB2e8M3.js +32 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/assets/defaultSettingsView-D-g2vrvf.js +184 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/assets/urlMatch-L3liM589.js +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/assets/xtermModule-B794rD2Z.js +7 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/codeMirrorModule.-QdMvsKi.css +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/defaultSettingsView.C8BeHuxd.css +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/index.B_TqY17P.css +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/index.html +44 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/index.oNry3Hjv.js +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/manifest.webmanifest +16 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/playwright-logo.svg +9 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/snapshot.B_Jk1wbt.js +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/snapshot.html +10 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/sw.bundle.js +4 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/uiMode.CYwC_gH1.js +5 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/uiMode.CyMfwkXJ.css +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/uiMode.html +18 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/xtermModule.kHJ-D0s7.css +1 -0
- package/node_modules/playwright-core/lib/webp_codec.LICENSE +173 -0
- package/node_modules/playwright-core/lib/webp_codec.wasm +0 -0
- package/node_modules/playwright-core/lib/xdg-open +1267 -0
- package/node_modules/playwright-core/package.json +34 -0
- package/node_modules/playwright-core/types/protocol.d.ts +24776 -0
- package/node_modules/playwright-core/types/structs.d.ts +52 -0
- package/node_modules/playwright-core/types/types.d.ts +27167 -0
- package/package.json +30 -12
- package/plugin.mjs +1 -0
- package/server/contract.mjs +3 -3
- package/server/embedded-host.mjs +247 -0
- package/server/engine.mjs +1906 -115
- package/server/governor.mjs +189 -0
- package/server/http-utils.mjs +1 -1
- package/server/human.mjs +628 -0
- package/server/infra/http.mjs +2 -113
- package/server/infra/tuning.mjs +2 -82
- package/server/input.mjs +154 -0
- package/server/login-vault.mjs +109 -0
- package/server/mcp/handler.mjs +1 -1
- package/server/mcp/instructions.mjs +5 -2
- package/server/orphans.mjs +163 -0
- package/server/relay.mjs +160 -188
- package/server/routes/api.mjs +126 -13
- package/server/routes/assets.mjs +1 -1
- package/server/session-engines.mjs +184 -0
- package/server/shared/SHARED_MANIFEST.json +47 -24
- package/server/shared/asset-service.mjs +2 -217
- package/server/shared/editor-host.mjs +2 -125
- package/server/shared/kit/editor/lease.mjs +2 -139
- package/server/shared/kit/service/api.mjs +2 -45
- package/server/shared/kit/service/http.mjs +2 -113
- package/server/shared/kit/service/mcp-http.mjs +2 -142
- package/server/shared/kit/tools/validate.mjs +2 -115
- package/server/shared/kit/tuning.mjs +2 -82
- package/server/shared/kit/util/fs-lock.mjs +2 -132
- package/server/shared/service-host.mjs +2 -511
- package/server/shared/tool-host.mjs +2 -341
- package/server/shared/tuning.mjs +2 -63
- package/server/tools/capabilities/contract.mjs +25 -5
- package/server/tools/capabilities/interaction.mjs +113 -9
- package/server/tools/capabilities/navigation.mjs +5 -2
- package/server/tools/capabilities/screenshot.mjs +25 -8
- package/server/tools/capabilities/session.mjs +13 -7
- package/server/tools/capabilities/snapshot.mjs +1 -1
- package/server/tools/capabilities/tabs.mjs +2 -2
- package/server/tools/kernel/define.mjs +1 -1
- package/server/tools/kernel/output.mjs +8 -0
- package/server/tools/kernel/ports.mjs +12 -7
- package/server/tools/kernel/registry.mjs +1 -1
- package/server/workbench-framework.mjs +305 -0
- package/ui/app.js +409 -119
- package/ui/index.html +29 -39
- package/ui/style.css +131 -63
- package/cordis.patch.yml +0 -25
package/ui/app.js
CHANGED
|
@@ -1,157 +1,447 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 浏览器工作台前端(无框架无构建)——真实浏览器外观:标签栏 + 地址栏 + 整幅画面。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* 两条数据通道:
|
|
5
|
+
* 1. /api/live(SSE)推当前活动页的 JPEG 帧 —— 画面是「真」的,不是 1.2s 轮询截图;
|
|
6
|
+
* 2. /api/input(POST)把画面里的鼠标/滚轮/键盘回放成页面里的真实输入。
|
|
7
|
+
* 其余(状态、标签页、导航、历史)都走 /api/*,与 AI 的 browser_* 工具共用同一引擎实例。
|
|
8
|
+
*
|
|
9
|
+
* 窄栏(DSH 右侧边栏)与宽窗口共用同一份布局:@media 只在细节上收边。
|
|
7
10
|
*/
|
|
8
11
|
(function () {
|
|
9
12
|
'use strict'
|
|
10
13
|
|
|
11
14
|
var $ = function (id) { return document.getElementById(id) }
|
|
12
15
|
var els = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
tabs: $('tabs'), newTab: $('btn-newtab'),
|
|
17
|
+
stage: $('stage'), frame: $('frame'), placeholder: $('placeholder'), hint: $('hint'),
|
|
18
|
+
wall: $('wall'), wallText: $('wall-text'),
|
|
19
|
+
urlInput: $('url-input'), kbd: $('kbd'),
|
|
20
|
+
btnBack: $('btn-back'), btnForward: $('btn-forward'), btnReload: $('btn-reload'),
|
|
17
21
|
}
|
|
18
|
-
var running = false
|
|
19
|
-
var shotBusy = false
|
|
20
|
-
var statusBusy = false
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
var state = {
|
|
24
|
+
running: false,
|
|
25
|
+
frameW: 1280,
|
|
26
|
+
frameH: 800,
|
|
27
|
+
lastFrameAt: 0,
|
|
28
|
+
hasFrame: false,
|
|
29
|
+
fallbackTimer: null,
|
|
30
|
+
statusBusy: false,
|
|
31
|
+
tabsSig: null,
|
|
25
32
|
}
|
|
26
33
|
|
|
27
|
-
|
|
28
|
-
var st = data.status || {}
|
|
29
|
-
running = !!st.running
|
|
30
|
-
els.engine.textContent = running
|
|
31
|
-
? (st.launching ? '浏览器启动中…' : '浏览器运行中 · ' + (st.channel || 'chromium'))
|
|
32
|
-
: '浏览器未启动'
|
|
33
|
-
els.engine.className = 'badge ' + (running ? 'on' : 'off')
|
|
34
|
-
els.mode.hidden = !running
|
|
35
|
-
els.mode.textContent = st.headless ? '无头' : '有头'
|
|
36
|
-
els.counters.textContent = st.counters
|
|
37
|
-
? '动作 ' + st.counters.actions + ' · 失败 ' + st.counters.errors + ' · 快照 ' + st.counters.snapshots
|
|
38
|
-
: ''
|
|
39
|
-
/* 标签页 */
|
|
40
|
-
els.tabs.innerHTML = ''
|
|
41
|
-
var tabs = st.tabs || []
|
|
42
|
-
if (tabs.length > 1 || (tabs.length && !running)) {
|
|
43
|
-
tabs.forEach(function (tab) {
|
|
44
|
-
var el = document.createElement('span')
|
|
45
|
-
el.className = 'tab' + (tab.active ? ' active' : '')
|
|
46
|
-
el.textContent = (tab.id || '?') + ' ' + fmtUrl(tab.url)
|
|
47
|
-
el.title = tab.url
|
|
48
|
-
el.onclick = function () { post('/api/tabs', { action: 'select', tab: tab.id }) }
|
|
49
|
-
els.tabs.appendChild(el)
|
|
50
|
-
})
|
|
51
|
-
}
|
|
52
|
-
/* 动作日志 */
|
|
53
|
-
var actions = data.actions || []
|
|
54
|
-
if (actions.length) {
|
|
55
|
-
els.log.innerHTML = ''
|
|
56
|
-
actions.forEach(function (a) {
|
|
57
|
-
var li = document.createElement('li')
|
|
58
|
-
var t = document.createElement('span')
|
|
59
|
-
t.className = 't'
|
|
60
|
-
t.textContent = (a.at || '').slice(11, 19)
|
|
61
|
-
var name = document.createElement('span')
|
|
62
|
-
name.className = a.ok ? 'ok' : 'fail'
|
|
63
|
-
name.textContent = (a.ok ? '✓ ' : '✗ ') + a.tool + (a.detail ? ' · ' + a.detail : '')
|
|
64
|
-
if (!a.ok && a.error) name.title = a.error
|
|
65
|
-
var ms = document.createElement('span')
|
|
66
|
-
ms.className = 'ms'
|
|
67
|
-
ms.textContent = a.ms + 'ms'
|
|
68
|
-
li.appendChild(t); li.appendChild(name); li.appendChild(ms)
|
|
69
|
-
els.log.appendChild(li)
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
}
|
|
34
|
+
/* ---------- 基础请求 ---------- */
|
|
73
35
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
function
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
var img = els.view.querySelector('img')
|
|
90
|
-
if (!img) {
|
|
91
|
-
els.view.innerHTML = ''
|
|
92
|
-
img = document.createElement('img')
|
|
93
|
-
img.alt = '当前页面实时画面'
|
|
94
|
-
els.view.appendChild(img)
|
|
95
|
-
}
|
|
96
|
-
var url = URL.createObjectURL(blob)
|
|
97
|
-
var prev = img.src
|
|
98
|
-
img.src = url
|
|
99
|
-
if (prev && prev.startsWith('blob:')) URL.revokeObjectURL(prev)
|
|
100
|
-
}).catch(function () { /* 引擎未运行/页面关闭 */ }).finally(function () { shotBusy = false })
|
|
36
|
+
/* 端点跟着页面走:embedded 在 /capyclaw/browser/,standalone 在 /,
|
|
37
|
+
* 同一份 UI 不用知道基建把服务放在哪。 */
|
|
38
|
+
var API_ROOT = new URL('.', document.baseURI).pathname
|
|
39
|
+
function apiPath(path) { return API_ROOT + String(path).replace(/^\//, '') }
|
|
40
|
+
|
|
41
|
+
/* 内联提示条:替代 alert()。alert 是同步模态,会冻住整个工作台 JS(轮询/SSE 全停),
|
|
42
|
+
一次失败就把界面卡死;toast 非阻塞,6s 自动消失,轮询照常。 */
|
|
43
|
+
var toastTimer = null
|
|
44
|
+
function toast(msg) {
|
|
45
|
+
var el = document.getElementById('toast')
|
|
46
|
+
if (!el) return
|
|
47
|
+
el.textContent = msg
|
|
48
|
+
el.hidden = false
|
|
49
|
+
if (toastTimer) clearTimeout(toastTimer)
|
|
50
|
+
toastTimer = setTimeout(function () { el.hidden = true }, 6000)
|
|
101
51
|
}
|
|
102
52
|
|
|
103
53
|
function post(path, body) {
|
|
104
54
|
return fetch(path, {
|
|
105
55
|
method: 'POST',
|
|
106
56
|
headers: { 'content-type': 'application/json' },
|
|
107
|
-
body: JSON.stringify(body),
|
|
57
|
+
body: JSON.stringify(body || {}),
|
|
108
58
|
}).then(function (r) { return r.json() }).then(function (data) {
|
|
109
|
-
pollStatus()
|
|
110
59
|
if (data && data.ok === false && data.error) {
|
|
111
|
-
|
|
112
|
-
(data.error.hint ? '
|
|
60
|
+
toast('[' + (data.error.code || 'ERROR') + '] ' + data.error.message +
|
|
61
|
+
(data.error.hint ? ' ' + data.error.hint : ''))
|
|
113
62
|
}
|
|
114
63
|
return data
|
|
115
|
-
}).catch(function (e) {
|
|
64
|
+
}).catch(function (e) { toast('请求失败: ' + e.message) })
|
|
116
65
|
}
|
|
117
66
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
67
|
+
/** 输入是高频通道:失败静默(画面照常,下一次事件会补上)。 */
|
|
68
|
+
function sendInput(payload) {
|
|
69
|
+
return fetch(apiPath('/api/input'), {
|
|
70
|
+
method: 'POST',
|
|
71
|
+
headers: { 'content-type': 'application/json' },
|
|
72
|
+
body: JSON.stringify(payload),
|
|
73
|
+
}).catch(function () {})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/* ---------- 实时画面 ---------- */
|
|
77
|
+
|
|
78
|
+
function showFrame() {
|
|
79
|
+
if (state.hasFrame) return
|
|
80
|
+
state.hasFrame = true
|
|
81
|
+
els.placeholder.hidden = true
|
|
82
|
+
els.frame.classList.add('on')
|
|
83
|
+
els.hint.hidden = false
|
|
84
|
+
/* 提示只在第一帧后露 5 秒,之后让位给画面本身。 */
|
|
85
|
+
setTimeout(function () { els.hint.hidden = true }, 5000)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function hideFrame() {
|
|
89
|
+
state.hasFrame = false
|
|
90
|
+
els.frame.classList.remove('on')
|
|
91
|
+
els.frame.removeAttribute('src')
|
|
92
|
+
els.placeholder.hidden = false
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function drawFrame(msg) {
|
|
96
|
+
if (!msg || !msg.img) return
|
|
97
|
+
if (msg.w) state.frameW = msg.w
|
|
98
|
+
if (msg.h) state.frameH = msg.h
|
|
99
|
+
els.frame.width = state.frameW
|
|
100
|
+
els.frame.height = state.frameH
|
|
101
|
+
els.frame.src = 'data:image/jpeg;base64,' + msg.img
|
|
102
|
+
state.lastFrameAt = Date.now()
|
|
103
|
+
showFrame()
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
var live = null
|
|
107
|
+
|
|
108
|
+
function connectLive() {
|
|
109
|
+
if (live) return
|
|
110
|
+
if (typeof EventSource !== 'function') { startFallback(); return }
|
|
111
|
+
try {
|
|
112
|
+
live = new EventSource(apiPath('/api/live'))
|
|
113
|
+
} catch (e) {
|
|
114
|
+
live = null
|
|
115
|
+
startFallback()
|
|
116
|
+
return
|
|
117
|
+
}
|
|
118
|
+
live.onmessage = function (event) {
|
|
119
|
+
stopFallback()
|
|
120
|
+
try { drawFrame(JSON.parse(event.data)) } catch (e) { /* 坏帧直接丢 */ }
|
|
121
|
+
}
|
|
122
|
+
/* EventSource 自己会重连;这里只在长时间没有帧时退到轮询兜底。 */
|
|
123
|
+
live.onerror = function () { /* 由 watchdog 决定是否兜底 */ }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/* SSE 被中间层吃掉(或桌面 webview 不支持)时,退回 1.2s 截图,至少还能看。 */
|
|
127
|
+
function startFallback() {
|
|
128
|
+
if (state.fallbackTimer !== null) return
|
|
129
|
+
state.fallbackTimer = setInterval(function () {
|
|
130
|
+
if (!state.running) return
|
|
131
|
+
fetch(apiPath('/api/screenshot')).then(function (r) {
|
|
132
|
+
if (!r.ok) throw new Error('shot ' + r.status)
|
|
133
|
+
return r.blob()
|
|
134
|
+
}).then(function (blob) {
|
|
135
|
+
var url = URL.createObjectURL(blob)
|
|
136
|
+
var prev = els.frame.getAttribute('src') || ''
|
|
137
|
+
els.frame.src = url
|
|
138
|
+
if (prev.indexOf('blob:') === 0) URL.revokeObjectURL(prev)
|
|
139
|
+
state.lastFrameAt = Date.now()
|
|
140
|
+
showFrame()
|
|
141
|
+
}).catch(function () { /* 引擎未运行 / 页面关闭 */ })
|
|
142
|
+
}, 1200)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function stopFallback() {
|
|
146
|
+
if (state.fallbackTimer === null) return
|
|
147
|
+
clearInterval(state.fallbackTimer)
|
|
148
|
+
state.fallbackTimer = null
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/* ---------- 坐标映射与输入回放 ---------- */
|
|
152
|
+
|
|
153
|
+
/** object-fit: contain 的内容框 → 页面 CSS 像素坐标。 */
|
|
154
|
+
function toPage(clientX, clientY) {
|
|
155
|
+
var rect = els.frame.getBoundingClientRect()
|
|
156
|
+
if (!rect.width || !rect.height) return { x: 0, y: 0 }
|
|
157
|
+
var scale = Math.min(rect.width / state.frameW, rect.height / state.frameH)
|
|
158
|
+
var dispW = state.frameW * scale
|
|
159
|
+
var dispH = state.frameH * scale
|
|
160
|
+
var ox = rect.left + (rect.width - dispW) / 2
|
|
161
|
+
var oy = rect.top + (rect.height - dispH) / 2
|
|
162
|
+
return {
|
|
163
|
+
x: Math.round((clientX - ox) / scale),
|
|
164
|
+
y: Math.round((clientY - oy) / scale),
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function buttonName(button) {
|
|
169
|
+
if (button === 2) return 'right'
|
|
170
|
+
if (button === 1) return 'middle'
|
|
171
|
+
return 'left'
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
var pointerDown = false
|
|
175
|
+
var lastMoveAt = 0
|
|
176
|
+
var queuedMove = null
|
|
177
|
+
|
|
178
|
+
function flushMove() {
|
|
179
|
+
if (!queuedMove) return
|
|
180
|
+
var point = queuedMove
|
|
181
|
+
queuedMove = null
|
|
182
|
+
sendInput({ type: 'pointer', kind: 'move', x: point.x, y: point.y })
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
els.frame.addEventListener('pointerdown', function (event) {
|
|
186
|
+
if (!state.running) return
|
|
187
|
+
event.preventDefault()
|
|
188
|
+
els.frame.focus()
|
|
189
|
+
els.hint.hidden = true
|
|
190
|
+
if (els.kbd) els.kbd.focus({ preventScroll: true })
|
|
191
|
+
pointerDown = true
|
|
192
|
+
try { els.frame.setPointerCapture(event.pointerId) } catch (e) { /* 老 webview */ }
|
|
193
|
+
var point = toPage(event.clientX, event.clientY)
|
|
194
|
+
sendInput({ type: 'pointer', kind: 'down', x: point.x, y: point.y, button: buttonName(event.button) })
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
els.frame.addEventListener('pointermove', function (event) {
|
|
198
|
+
if (!state.running) return
|
|
199
|
+
var point = toPage(event.clientX, event.clientY)
|
|
200
|
+
queuedMove = point
|
|
201
|
+
/* 移动节流到 ~40fps:报文太多会把 loopback 和 CDP 都拖慢。 */
|
|
202
|
+
if (Date.now() - lastMoveAt < 24) return
|
|
203
|
+
lastMoveAt = Date.now()
|
|
204
|
+
flushMove()
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
els.frame.addEventListener('pointerup', function (event) {
|
|
208
|
+
if (!state.running) return
|
|
209
|
+
event.preventDefault()
|
|
210
|
+
pointerDown = false
|
|
211
|
+
try { els.frame.releasePointerCapture(event.pointerId) } catch (e) { /* 忽略 */ }
|
|
212
|
+
var point = toPage(event.clientX, event.clientY)
|
|
213
|
+
sendInput({ type: 'pointer', kind: 'up', x: point.x, y: point.y, button: buttonName(event.button) })
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
els.frame.addEventListener('pointercancel', function () {
|
|
217
|
+
if (!pointerDown) return
|
|
218
|
+
pointerDown = false
|
|
219
|
+
sendInput({ type: 'pointer', kind: 'up', x: 0, y: 0, button: 'left' })
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
els.frame.addEventListener('contextmenu', function (event) { event.preventDefault() })
|
|
223
|
+
|
|
224
|
+
els.frame.addEventListener('wheel', function (event) {
|
|
225
|
+
if (!state.running) return
|
|
226
|
+
event.preventDefault()
|
|
227
|
+
var point = toPage(event.clientX, event.clientY)
|
|
228
|
+
sendInput({
|
|
229
|
+
type: 'pointer', kind: 'wheel',
|
|
230
|
+
x: point.x, y: point.y,
|
|
231
|
+
deltaX: Math.round(event.deltaX), deltaY: Math.round(event.deltaY),
|
|
232
|
+
})
|
|
233
|
+
}, { passive: false })
|
|
234
|
+
|
|
235
|
+
/* 键盘:隐藏 textarea 负责接收,特殊键走 press,可打印字符走 text(中文走 insertText)。 */
|
|
236
|
+
var SPECIAL_KEYS = {
|
|
237
|
+
Enter: 'Enter', Tab: 'Tab', Backspace: 'Backspace', Delete: 'Delete', Escape: 'Escape',
|
|
238
|
+
ArrowUp: 'ArrowUp', ArrowDown: 'ArrowDown', ArrowLeft: 'ArrowLeft', ArrowRight: 'ArrowRight',
|
|
239
|
+
Home: 'Home', End: 'End', PageUp: 'PageUp', PageDown: 'PageDown', Insert: 'Insert',
|
|
240
|
+
}
|
|
241
|
+
var composing = false
|
|
242
|
+
|
|
243
|
+
function resetKbd() { if (els.kbd) els.kbd.value = '' }
|
|
244
|
+
|
|
245
|
+
els.kbd.addEventListener('keydown', function (event) {
|
|
246
|
+
if (event.isComposing || composing) return
|
|
247
|
+
if (event.ctrlKey || event.metaKey) {
|
|
248
|
+
var base = event.key.length === 1 ? event.key.toLowerCase() : event.key
|
|
249
|
+
event.preventDefault()
|
|
250
|
+
sendInput({ type: 'key', kind: 'press', key: (event.ctrlKey ? 'Control+' : 'Meta+') + base })
|
|
251
|
+
return
|
|
252
|
+
}
|
|
253
|
+
var special = SPECIAL_KEYS[event.key]
|
|
254
|
+
if (special) {
|
|
255
|
+
event.preventDefault()
|
|
256
|
+
sendInput({ type: 'key', kind: 'press', key: special })
|
|
257
|
+
}
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
els.kbd.addEventListener('beforeinput', function (event) {
|
|
261
|
+
if (composing) return
|
|
262
|
+
if (event.inputType === 'insertText' && event.data) {
|
|
263
|
+
event.preventDefault()
|
|
264
|
+
sendInput({ type: 'key', kind: 'text', text: event.data })
|
|
265
|
+
resetKbd()
|
|
266
|
+
return
|
|
267
|
+
}
|
|
268
|
+
if (event.inputType === 'insertLineBreak' || event.inputType === 'insertParagraph') {
|
|
269
|
+
event.preventDefault()
|
|
270
|
+
sendInput({ type: 'key', kind: 'press', key: 'Enter' })
|
|
271
|
+
resetKbd()
|
|
272
|
+
}
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
els.kbd.addEventListener('compositionstart', function () { composing = true })
|
|
276
|
+
els.kbd.addEventListener('compositionend', function (event) {
|
|
277
|
+
composing = false
|
|
278
|
+
if (event.data) sendInput({ type: 'key', kind: 'text', text: event.data })
|
|
279
|
+
resetKbd()
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
/* 粘贴:textarea 的 paste 不会走 beforeinput.insertText,单独接一次。 */
|
|
283
|
+
els.kbd.addEventListener('paste', function (event) {
|
|
284
|
+
var data = event.clipboardData || window.clipboardData
|
|
285
|
+
var text = data ? data.getData('text') : ''
|
|
286
|
+
if (!text) return
|
|
287
|
+
event.preventDefault()
|
|
288
|
+
sendInput({ type: 'key', kind: 'text', text: text })
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
/* ---------- 状态与标签页 ---------- */
|
|
292
|
+
|
|
293
|
+
function tabLabel(tab) {
|
|
294
|
+
if (tab.title) return tab.title.slice(0, 30)
|
|
295
|
+
var url = tab.url
|
|
296
|
+
if (!url || url === 'about:blank') return '新标签页'
|
|
297
|
+
return url.replace(/^https?:\/\//, '').slice(0, 30)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/* 标签栏像真实浏览器:始终可见,单击切换、× 关闭、+ 新建。
|
|
301
|
+
* 引擎还没标签时放一个「新标签页」占位标签,点它聚焦地址栏。
|
|
302
|
+
* 签名不变就不重建 DOM:否则 2s 轮询会在用户点击途中换掉节点,丢掉 click。 */
|
|
303
|
+
function renderTabs(tabs) {
|
|
304
|
+
var sig = tabs.map(function (t) { return t.id + '|' + (t.url || '') + '|' + (t.title || '') + '|' + (t.active ? 1 : 0) }).join(',')
|
|
305
|
+
if (sig === state.tabsSig) return
|
|
306
|
+
state.tabsSig = sig
|
|
307
|
+
els.tabs.innerHTML = ''
|
|
308
|
+
if (!tabs.length) {
|
|
309
|
+
var ghost = document.createElement('span')
|
|
310
|
+
ghost.className = 'tab active'
|
|
311
|
+
ghost.title = '在地址栏输入网址,回车打开'
|
|
312
|
+
var gl = document.createElement('span')
|
|
313
|
+
gl.className = 'tab-label'
|
|
314
|
+
gl.textContent = '新标签页'
|
|
315
|
+
ghost.appendChild(gl)
|
|
316
|
+
ghost.onclick = function () { els.urlInput.focus(); els.urlInput.select() }
|
|
317
|
+
els.tabs.appendChild(ghost)
|
|
318
|
+
return
|
|
319
|
+
}
|
|
320
|
+
tabs.forEach(function (tab) {
|
|
321
|
+
var el = document.createElement('span')
|
|
322
|
+
el.className = 'tab' + (tab.active ? ' active' : '')
|
|
323
|
+
el.title = (tab.title ? tab.title + '\n' : '') + (tab.url || 'about:blank')
|
|
324
|
+
var label = document.createElement('span')
|
|
325
|
+
label.className = 'tab-label'
|
|
326
|
+
label.textContent = tabLabel(tab)
|
|
327
|
+
el.appendChild(label)
|
|
328
|
+
var close = document.createElement('button')
|
|
329
|
+
close.type = 'button'
|
|
330
|
+
close.className = 'tab-close'
|
|
331
|
+
close.title = '关闭标签页'
|
|
332
|
+
close.textContent = '×'
|
|
333
|
+
close.onclick = function (event) {
|
|
334
|
+
event.stopPropagation()
|
|
335
|
+
post(apiPath('/api/tabs'), { action: 'close', tab: tab.id }).then(pollStatus)
|
|
336
|
+
}
|
|
337
|
+
el.appendChild(close)
|
|
338
|
+
el.onclick = function () { post(apiPath('/api/tabs'), { action: 'select', tab: tab.id }).then(pollStatus) }
|
|
339
|
+
els.tabs.appendChild(el)
|
|
123
340
|
})
|
|
124
341
|
}
|
|
125
342
|
|
|
126
|
-
|
|
127
|
-
var
|
|
343
|
+
function renderStatus(data) {
|
|
344
|
+
var st = data.status || {}
|
|
345
|
+
var wasRunning = state.running
|
|
346
|
+
state.running = !!st.running
|
|
347
|
+
state.restorable = !!st.restorable
|
|
348
|
+
if (st.viewport && st.viewport.width) {
|
|
349
|
+
state.frameW = st.viewport.width
|
|
350
|
+
state.frameH = st.viewport.height
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/* 活动页停在 DSH Web 自身 401 鉴权页:盖解释层,藏掉「点画面」提示。 */
|
|
354
|
+
var wall = st.authWall || ''
|
|
355
|
+
els.wall.hidden = !wall
|
|
356
|
+
if (wall) { els.wallText.textContent = wall; els.hint.hidden = true }
|
|
357
|
+
|
|
358
|
+
if (!state.running && wasRunning) hideFrame()
|
|
359
|
+
if (state.running && !state.hasFrame) connectLive()
|
|
360
|
+
|
|
361
|
+
renderTabs(st.tabs || [])
|
|
362
|
+
|
|
363
|
+
var active = (st.tabs || []).filter(function (t) { return t.active })[0]
|
|
364
|
+
if (active && document.activeElement !== els.urlInput && active.url && active.url !== 'about:blank') {
|
|
365
|
+
els.urlInput.value = active.url
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function pollStatus() {
|
|
370
|
+
if (state.statusBusy) return Promise.resolve()
|
|
371
|
+
state.statusBusy = true
|
|
372
|
+
return fetch(apiPath('/api/status')).then(function (r) { return r.json() }).then(function (data) {
|
|
373
|
+
renderStatus(data)
|
|
374
|
+
}).catch(function () { /* 服务重启间隙 */ }).finally(function () { state.statusBusy = false })
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/* ---------- 地址栏与历史 ---------- */
|
|
378
|
+
|
|
379
|
+
function openUrl(url) {
|
|
128
380
|
if (!url) return
|
|
129
381
|
if (!/^https?:\/\//i.test(url)) url = 'https://' + url
|
|
130
|
-
|
|
382
|
+
post(apiPath('/api/navigate'), { url: url }).then(function (data) {
|
|
383
|
+
if (data && data.ok !== false) connectLive()
|
|
384
|
+
}).finally(function () {
|
|
385
|
+
pollStatus()
|
|
386
|
+
})
|
|
131
387
|
}
|
|
132
|
-
|
|
133
|
-
|
|
388
|
+
|
|
389
|
+
$('nav').addEventListener('submit', function (event) {
|
|
390
|
+
event.preventDefault()
|
|
391
|
+
openUrl(els.urlInput.value.trim())
|
|
392
|
+
els.urlInput.blur()
|
|
134
393
|
})
|
|
135
|
-
|
|
136
|
-
els.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
394
|
+
|
|
395
|
+
els.btnBack.onclick = function () { historyAction('back') }
|
|
396
|
+
els.btnForward.onclick = function () { historyAction('forward') }
|
|
397
|
+
els.btnReload.onclick = function () { historyAction('reload') }
|
|
398
|
+
|
|
399
|
+
/* 后退/前进/刷新走一条与 browser_history 同引擎的最小接口。 */
|
|
400
|
+
function historyAction(action) {
|
|
401
|
+
fetch(apiPath('/api/history'), {
|
|
402
|
+
method: 'POST',
|
|
403
|
+
headers: { 'content-type': 'application/json' },
|
|
404
|
+
body: JSON.stringify({ action: action }),
|
|
405
|
+
}).then(function (r) { return r.json() }).then(function (data) {
|
|
406
|
+
if (data && data.ok === false && data.error) toast('[' + data.error.code + '] ' + data.error.message)
|
|
407
|
+
pollStatus()
|
|
408
|
+
}).catch(function () { /* 忽略 */ })
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/* 新建标签页:与 browser_tabs(action=new) 同源;开完聚焦地址栏,像真实浏览器。 */
|
|
412
|
+
els.newTab.onclick = function () {
|
|
413
|
+
post(apiPath('/api/tabs'), { action: 'new' }).then(function (data) {
|
|
414
|
+
if (data && data.ok !== false) {
|
|
415
|
+
connectLive()
|
|
416
|
+
els.urlInput.value = ''
|
|
417
|
+
els.urlInput.focus()
|
|
141
418
|
}
|
|
142
|
-
|
|
143
|
-
'# ' + (data.title || '(无标题)') + '\n' + data.url + '(' + data.elements + ' 个元素' +
|
|
144
|
-
(data.truncated ? ',已截断' : '') + ')\n\n' + data.text
|
|
145
|
-
}).catch(function (e) { els.snapshot.textContent = '快照失败: ' + e.message })
|
|
146
|
-
}
|
|
147
|
-
els.btnClose.onclick = function () {
|
|
148
|
-
if (!confirm('关闭浏览器?登录态会持久化,下次打开网址自动重启。')) return
|
|
149
|
-
post('/api/control', { action: 'close' }).then(function () {
|
|
150
|
-
els.view.innerHTML = '<div class="placeholder"><p>浏览器已关闭。</p><p>登录态已持久化;下次打开网址时自动重启。</p></div>'
|
|
419
|
+
pollStatus()
|
|
151
420
|
})
|
|
152
421
|
}
|
|
153
422
|
|
|
154
|
-
|
|
423
|
+
/* ---------- 启动 ---------- */
|
|
424
|
+
|
|
425
|
+
/* 先读一次状态:若浏览器已被空闲回收/停服挂起,但留有上次的标签页,
|
|
426
|
+
就自动恢复一次(resume = 懒启动 + 标签恢复,不附带新导航),
|
|
427
|
+
于是「重开这个会话还能看到上次的页面」。只在打开工作台时触发一次;
|
|
428
|
+
面板开着时实时帧订阅(watching>0)会保护浏览器不被空闲回收。 */
|
|
429
|
+
pollStatus().then(function () {
|
|
430
|
+
if (!state.running && state.restorable) {
|
|
431
|
+
post(apiPath('/api/control'), { action: 'resume' })
|
|
432
|
+
.then(function () { pollStatus() })
|
|
433
|
+
.catch(function () { /* 恢复失败不阻塞工作台 */ })
|
|
434
|
+
}
|
|
435
|
+
})
|
|
155
436
|
setInterval(pollStatus, 2000)
|
|
156
|
-
|
|
437
|
+
/* watchdog:SSE 断流超过 3s 且浏览器在跑 → 退回截图轮询。 */
|
|
438
|
+
setInterval(function () {
|
|
439
|
+
if (!state.running) { stopFallback(); return }
|
|
440
|
+
if (state.fallbackTimer !== null) return
|
|
441
|
+
if (Date.now() - state.lastFrameAt > 3000) startFallback()
|
|
442
|
+
}, 2000)
|
|
443
|
+
|
|
444
|
+
connectLive()
|
|
445
|
+
// 提示条:画面出现后第一次点击就藏起来
|
|
446
|
+
els.frame.addEventListener('focus', function () { els.hint.hidden = true }, { once: true })
|
|
157
447
|
})()
|
package/ui/index.html
CHANGED
|
@@ -3,54 +3,44 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
-
<title>DSH
|
|
7
|
-
<link rel="stylesheet" href="
|
|
6
|
+
<title>DSH 浏览器</title>
|
|
7
|
+
<link rel="stylesheet" href="style.css">
|
|
8
8
|
</head>
|
|
9
9
|
<body>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
<div class="
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
</header>
|
|
10
|
+
<!-- 标签栏:像真实浏览器一样始终在顶部,可切换、可新建、可关闭 -->
|
|
11
|
+
<div class="tabstrip">
|
|
12
|
+
<div id="tabs" class="tabs"></div>
|
|
13
|
+
<button type="button" id="btn-newtab" class="newtab" title="新建标签页">+</button>
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
<!-- 工具栏:后退 / 前进 / 刷新 + 地址栏(回车打开) -->
|
|
17
|
+
<form id="nav" class="toolbar" autocomplete="off">
|
|
18
|
+
<button type="button" id="btn-back" class="icon" title="后退">←</button>
|
|
19
|
+
<button type="button" id="btn-forward" class="icon" title="前进">→</button>
|
|
20
|
+
<button type="button" id="btn-reload" class="icon" title="刷新">⟳</button>
|
|
21
|
+
<input id="url-input" type="text" placeholder="输入网址,回车打开" spellcheck="false" autocomplete="off">
|
|
22
|
+
</form>
|
|
24
23
|
|
|
25
24
|
<main>
|
|
26
|
-
<section id="
|
|
27
|
-
<
|
|
28
|
-
|
|
29
|
-
<
|
|
25
|
+
<section id="stage" class="stage">
|
|
26
|
+
<img id="frame" alt="当前页面实时画面(可直接点击、滚动、打字)" tabindex="0">
|
|
27
|
+
<div id="placeholder" class="placeholder">
|
|
28
|
+
<p>在地址栏输入网址,回车打开。</p>
|
|
29
|
+
<p class="muted">AI 调用 <code>browser_navigate</code> 时,这里也会实时跟上。</p>
|
|
30
30
|
</div>
|
|
31
|
-
<div id="
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
<
|
|
31
|
+
<div id="hint" class="hint" hidden>点一下画面即可点击 / 输入</div>
|
|
32
|
+
<div id="wall" class="wall" hidden>
|
|
33
|
+
<div class="wall-card">
|
|
34
|
+
<h2>这是 DSH Web 的鉴权页,不是目标网站</h2>
|
|
35
|
+
<p id="wall-text"></p>
|
|
36
|
+
<p class="muted">受控浏览器与宿主浏览器登录态独立。要看 DSH 界面请用宿主浏览器;这里继续做互联网任务。</p>
|
|
35
37
|
</div>
|
|
36
38
|
</div>
|
|
37
39
|
</section>
|
|
38
|
-
|
|
39
|
-
<section id="log-panel" class="panel">
|
|
40
|
-
<div class="panel-head"><h2>动作日志</h2><span id="counters" class="muted"></span></div>
|
|
41
|
-
<ul id="log" class="log"><li class="muted">暂无动作。AI 或人工操作后这里按时间倒序显示。</li></ul>
|
|
42
|
-
</section>
|
|
43
|
-
|
|
44
|
-
<section id="snapshot-panel" class="panel">
|
|
45
|
-
<div class="panel-head"><h2>元素快照</h2><span class="muted">与 browser_snapshot 同源 · ref 可直接用于工具</span></div>
|
|
46
|
-
<pre id="snapshot" class="snapshot">点「快照」观察当前页面。</pre>
|
|
47
|
-
</section>
|
|
48
40
|
</main>
|
|
49
41
|
|
|
50
|
-
<
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
<script src="/app.js"></script>
|
|
42
|
+
<textarea id="kbd" aria-hidden="true" tabindex="-1"></textarea>
|
|
43
|
+
<div id="toast" class="toast" role="status" hidden></div>
|
|
44
|
+
<script src="app.js"></script>
|
|
55
45
|
</body>
|
|
56
46
|
</html>
|