@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/server/relay.mjs
CHANGED
|
@@ -1,226 +1,198 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Browser 桥 relay
|
|
3
|
-
* 1) MCP Streamable HTTP(/mcp)→ tool-host createMcpHandler
|
|
4
|
-
* 2) 工作台静态页(/、/app.js、/style.css)与内置演示页(/demo/form.html)
|
|
5
|
-
* 3) 工作台 API(/api/status|screenshot|snapshot|navigate|tabs|control)
|
|
2
|
+
* Browser 桥 relay:**业务装配**(HTTP/MCP/锁/发现/独立入口由 server/workbench-framework.mjs 提供)。
|
|
6
3
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
4
|
+
* 本文件只回答「浏览器工作台对外提供什么」:
|
|
5
|
+
* - 引擎:Playwright(懒启动、登录态持久化;生命周期归本进程)
|
|
6
|
+
* - 路由:MCP / 工作台静态页 / 演示页 / 工作台 API(status|screenshot|snapshot|navigate|tabs|control)
|
|
7
|
+
* - 工具:tools.mjs 的 CAPABILITIES → registry(注入引擎与 serverBaseUrl)
|
|
8
|
+
* - 健康与指标:engine / tabs / actions 等浏览器语义字段
|
|
10
9
|
*
|
|
11
10
|
* 也可脱离 dsh 独立运行:node server/relay.mjs [--port 39315] [--dir <hostDir>]
|
|
12
11
|
*/
|
|
13
|
-
import fs from 'node:fs'
|
|
14
|
-
import os from 'node:os'
|
|
15
12
|
import path from 'node:path'
|
|
16
|
-
import
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
13
|
+
import fs from 'node:fs'
|
|
14
|
+
import { declareBridge } from '@capyclaw/foundation/abi'
|
|
15
|
+
import { createSessionDispatch, bindToolsToCallerSession } from '@capyclaw/document-workbench/session-context'
|
|
16
|
+
import { createSessionModeRegistry, bindToolsToSessionMode } from '@capyclaw/document-workbench/session-mode'
|
|
17
|
+
import { createBrowserEngine, readEnginePrefs, resolveEngineConfig, resolveHeadlessPolicy } from './engine.mjs'
|
|
18
|
+
import { createProcessOps, reapOrphanBrowsers } from './orphans.mjs'
|
|
19
|
+
import { createSessionEngines } from './session-engines.mjs'
|
|
20
20
|
import { CONTRACT_VERSION, PACKAGE_VERSION } from './contract.mjs'
|
|
21
21
|
import { DEFAULT_PORT } from './constants.mjs'
|
|
22
22
|
import { createMcpRoutes } from './routes/mcp.mjs'
|
|
23
23
|
import { createWorkbenchRoutes } from './routes/workbench.mjs'
|
|
24
24
|
import { createApiRoutes } from './routes/api.mjs'
|
|
25
25
|
import { createAssetRoutes, createFileAssetStore } from './shared/asset-service.mjs'
|
|
26
|
-
import {
|
|
26
|
+
import { serverInstructions } from './mcp/instructions.mjs'
|
|
27
27
|
import { inspectContractSnapshots, describeMismatch } from './contract-snapshots.mjs'
|
|
28
|
-
import {
|
|
28
|
+
import { runIfMain, createWorkbench } from './workbench-framework.mjs'
|
|
29
29
|
|
|
30
30
|
export { DEFAULT_PORT }
|
|
31
31
|
|
|
32
|
-
const
|
|
32
|
+
export const startRelay = createWorkbench({
|
|
33
|
+
id: 'browser-workbench',
|
|
34
|
+
title: 'Browser Workbench',
|
|
35
|
+
packageVersion: PACKAGE_VERSION,
|
|
36
|
+
contractVersion: CONTRACT_VERSION,
|
|
37
|
+
/* 浏览器工作台是桥,但不提供文档模型(没有稳定元素寻址需求)。 */
|
|
38
|
+
bridge: declareBridge({ id: 'browser-workbench', model: null }),
|
|
39
|
+
/* 端口不再由业务决定:embedded 形态挂宿主路由,standalone(仅开发)才用 options.port。 */
|
|
40
|
+
basePath: '',
|
|
41
|
+
homeEnv: 'BROWSER_BRIDGE_HOME',
|
|
42
|
+
defaultHome: '.dsh-browser-bridge',
|
|
43
|
+
contract: { version: CONTRACT_VERSION, inspect: inspectContractSnapshots, describe: describeMismatch },
|
|
33
44
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
hostDir = process.env.BROWSER_BRIDGE_HOME
|
|
37
|
-
|| path.join(process.env.USERPROFILE || process.env.HOME || os.homedir(), '.dsh-browser-bridge'),
|
|
38
|
-
packageDir = PKG_ROOT,
|
|
39
|
-
lockFile,
|
|
40
|
-
strictPort = false,
|
|
41
|
-
allowReuse = true,
|
|
42
|
-
assetStore = null,
|
|
43
|
-
assetService = null,
|
|
44
|
-
capabilities = null,
|
|
45
|
-
engineConfig = null,
|
|
46
|
-
engine = null,
|
|
47
|
-
serviceHost = null,
|
|
48
|
-
toolHost = null,
|
|
49
|
-
} = {}) {
|
|
50
|
-
const contractSnapshots = inspectContractSnapshots(packageDir, CONTRACT_VERSION)
|
|
51
|
-
if (!contractSnapshots.ok) {
|
|
52
|
-
console.error('[browser-workbench] 契约快照不一致,工具调用将被拒绝:', describeMismatch(contractSnapshots))
|
|
53
|
-
}
|
|
54
|
-
const eng = engine || await createBrowserEngine({ hostDir, config: resolveEngineConfig(process.env, engineConfig) })
|
|
55
|
-
/* 独立运行(无 dsh)也要有对象仓库:截图等二进制落 hostDir/assets。 */
|
|
56
|
-
if (!assetStore && !assetService) {
|
|
57
|
-
try {
|
|
58
|
-
assetStore = createFileAssetStore({ dir: path.join(hostDir, 'assets') })
|
|
59
|
-
} catch { /* 对象仓库不可用不影响核心浏览功能 */ }
|
|
60
|
-
}
|
|
45
|
+
createStore: () => ({}),
|
|
46
|
+
createAssetStore: ({ hostDir }) => createFileAssetStore({ dir: path.join(hostDir, 'assets') }),
|
|
61
47
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
let mcpHandler = null
|
|
111
|
-
for (const route of createMcpRoutes({ getMcpHandler: () => mcpHandler })) app.use(route)
|
|
112
|
-
if (assetService?.mount) assetService.mount(app, { store: assetStore })
|
|
113
|
-
else if (assetStore) app.use(createAssetRoutes({ assetStore }))
|
|
114
|
-
for (const route of createWorkbenchRoutes({ packageDir })) app.use(route)
|
|
115
|
-
for (const route of createApiRoutes({ engine: eng })) app.use(route)
|
|
116
|
-
|
|
117
|
-
const info = await app.listen({
|
|
118
|
-
port,
|
|
119
|
-
hostDir,
|
|
120
|
-
lockFile: lockFile || path.join(hostDir, '.relay-instance.lock'),
|
|
121
|
-
strictPort,
|
|
122
|
-
allowReuse,
|
|
123
|
-
discoveryFile: '',
|
|
124
|
-
})
|
|
48
|
+
/* 引擎是业务资源:懒启动、登录态持久化。
|
|
49
|
+
有头/无头裁决见 engine.mjs resolveHeadlessPolicy:嵌入式(有 serviceHost,挂主区)
|
|
50
|
+
**强制无头**——用户契约「浏览器只在主区镜像、不弹外部窗口」;有头偏好
|
|
51
|
+
(<hostDir>/engine.json)在嵌入式不再生效,登录/验证码走主区镜像 + /api/input 回放。
|
|
52
|
+
显式环境变量 DSH_BROWSER_HEADLESS 是两种形态的调试逃生口。
|
|
53
|
+
standalone(开发/调试,无 serviceHost)保持旧优先级:偏好 > cordis 配置 > 默认有头。
|
|
54
|
+
F2 每会话隔离:每个会话各持一个引擎(独立 profile/标签页/动作队列),
|
|
55
|
+
会话身份由 createSessionDispatch(HTTP)/ bindToolsToCallerSession(工具)缝入 ALS。 */
|
|
56
|
+
prepare: async (ctx) => {
|
|
57
|
+
const config = resolveEngineConfig(process.env, ctx.engineConfig)
|
|
58
|
+
config.headless = resolveHeadlessPolicy({
|
|
59
|
+
env: process.env,
|
|
60
|
+
serviceHost: ctx.serviceHost || null,
|
|
61
|
+
engineConfig: ctx.engineConfig || null,
|
|
62
|
+
prefs: readEnginePrefs(ctx.hostDir),
|
|
63
|
+
})
|
|
64
|
+
/* 注入引擎(测试/旧装配)时全会话共享该实例,避免测试真起浏览器。 */
|
|
65
|
+
const injected = ctx.engine || null
|
|
66
|
+
/* 孤儿兜底(服务级):上次宿主崩溃/被强杀时,各会话的浏览器可能还活着并占着
|
|
67
|
+
profile 锁。启动后延时扫一遍各会话 profile 的「真孤儿」(父进程已死)。
|
|
68
|
+
只杀真孤儿,不碰别的活宿主;注入引擎的测试形态跳过。best-effort。 */
|
|
69
|
+
if (config.reapOrphans && !injected) {
|
|
70
|
+
/* 放后台且不 await:Windows 枚举一次进程约 800ms,不能拖慢服务就绪;
|
|
71
|
+
真撞 profile 锁时引擎启动路径会强制清扫并重试,这里只做顺手清理。 */
|
|
72
|
+
setTimeout(async () => {
|
|
73
|
+
try {
|
|
74
|
+
const sessionsDir = path.join(ctx.hostDir, 'sessions')
|
|
75
|
+
const profileDirs = fs.existsSync(sessionsDir)
|
|
76
|
+
? fs.readdirSync(sessionsDir, { withFileTypes: true })
|
|
77
|
+
.filter((d) => d.isDirectory())
|
|
78
|
+
.map((d) => path.join(sessionsDir, d.name, 'profile'))
|
|
79
|
+
: []
|
|
80
|
+
const swept = await reapOrphanBrowsers({ profileDirs, processOps: ctx.processOps || createProcessOps() })
|
|
81
|
+
if (swept.killed.length) console.log(`[browser-workbench] 清理孤儿浏览器进程 ${swept.killed.length} 个(上次宿主未正常退出)`)
|
|
82
|
+
} catch { /* 枚举失败不影响服务 */ }
|
|
83
|
+
}, 2000).unref?.()
|
|
84
|
+
}
|
|
85
|
+
const sessionEngines = createSessionEngines({
|
|
86
|
+
hostDir: ctx.hostDir,
|
|
87
|
+
config,
|
|
88
|
+
createEngine: injected ? () => injected : createBrowserEngine,
|
|
89
|
+
})
|
|
90
|
+
/* 兼容句柄:health/metrics/resultExtras 等进程级诊断仍拿一个引擎实例(default 会话)。 */
|
|
91
|
+
const engine = injected || await sessionEngines.forSession('default')
|
|
92
|
+
return { sessionEngines, engine }
|
|
93
|
+
},
|
|
125
94
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
95
|
+
routes: (ctx) => {
|
|
96
|
+
const many = (value) => (Array.isArray(value) ? value : [value])
|
|
97
|
+
const out = [...many(createMcpRoutes({ getMcpHandler: () => ctx.getMcpHandler?.() }))]
|
|
98
|
+
if (ctx.assetService?.mount) out.push(...many(ctx.assetService.mount(ctx.app, { store: ctx.assetStore })))
|
|
99
|
+
else if (ctx.assetStore) out.push(...many(createAssetRoutes({ assetStore: ctx.assetStore })))
|
|
100
|
+
out.push(...many(createWorkbenchRoutes({ packageDir: ctx.packageDir })))
|
|
101
|
+
out.push(...many(createApiRoutes({ getEngine: (req) => ctx.sessionEngines.forSession(req.sessionId || ''), embedded: !!ctx.serviceHost })))
|
|
102
|
+
/* 外层只做一件事:从 URL 的 /s/<sid> 段定下这次请求属于哪个会话(ALS),
|
|
103
|
+
* 内层路由/引擎解析都在该会话上下文里跑。browser 无文档 store,stores 传 null。 */
|
|
104
|
+
return [createSessionDispatch(out, null)]
|
|
105
|
+
},
|
|
129
106
|
|
|
130
|
-
|
|
131
|
-
let registry = null
|
|
107
|
+
tools: async (ctx) => {
|
|
132
108
|
try {
|
|
133
109
|
const tools = await import('./tools.mjs')
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
110
|
+
/* F2:绑定解析器而非实例——每次工具调用现场按调用者会话(ALS)解析引擎。 */
|
|
111
|
+
tools.setEngine(() => ctx.sessionEngines.current())
|
|
112
|
+
const registry = tools.createRegistry(tools.CAPABILITIES, {
|
|
113
|
+
enabled: ctx.capabilities,
|
|
114
|
+
toolHost: ctx.toolHost,
|
|
115
|
+
serverBaseUrl: ctx.editorUrl,
|
|
139
116
|
})
|
|
117
|
+
ctx.capabilitiesList = registry.CAPABILITIES || []
|
|
118
|
+
/* F3:工具写闸——非 read 工具执行前认领本会话为 browser(已固化为别的工作台则硬拒)。
|
|
119
|
+
* 必须在会话缝入之前包:那样守卫跑在调用者会话的 ALS 上下文里。 */
|
|
120
|
+
bindToolsToSessionMode(registry, { kind: 'browser', modeRegistry: createSessionModeRegistry(ctx.getWorkStore) })
|
|
121
|
+
/* 工具调用不经过 HTTP:会话身份从执行上下文(exec.agent.session.id)来,
|
|
122
|
+
* 这样会话 A 的工具只会动 A 的那个浏览器,不受「谁在最前面」影响。 */
|
|
123
|
+
return { ...bindToolsToCallerSession(registry), exemptTool: (name) => name === 'browser_capabilities' }
|
|
140
124
|
} catch (e) {
|
|
141
|
-
|
|
125
|
+
/* 工具面装不上就别装作健康:服务起、/healthz 绿、tools/list 空是最难查的一种坏。 */
|
|
126
|
+
console.error('[browser-workbench] 工具面装载失败(先跑 npm run build 生成 artifacts):', e.message)
|
|
127
|
+
throw new Error(`browser-workbench 工具面装载失败:${e.message}(先跑 npm run build 生成 artifacts)`)
|
|
142
128
|
}
|
|
143
|
-
|
|
144
|
-
const TOOL_IMPL = registry?.TOOL_IMPL || {}
|
|
145
|
-
const CAPABILITIES = registry?.CAPABILITIES || []
|
|
146
|
-
mcpHandler = createMcpHandler({
|
|
147
|
-
tools: TOOLS,
|
|
148
|
-
callTool: (name, args) => {
|
|
149
|
-
if (!contractSnapshots.ok && name !== 'browser_capabilities') {
|
|
150
|
-
throw new Error(
|
|
151
|
-
`契约快照与运行时 major 不一致,已拒绝 ${name}:${describeMismatch(contractSnapshots)}。` +
|
|
152
|
-
'请重装/升级 browser 套件后重试。',
|
|
153
|
-
)
|
|
154
|
-
}
|
|
155
|
-
const impl = TOOL_IMPL[name]
|
|
156
|
-
if (!impl) throw new Error('未知工具: ' + name)
|
|
157
|
-
return impl(args)
|
|
158
|
-
},
|
|
159
|
-
serverInfo: { name: 'browser-workbench', version: PACKAGE_VERSION },
|
|
160
|
-
instructions: serverInstructions(`http://127.0.0.1:${info.port}/`, { tools: TOOLS, capabilities: CAPABILITIES }),
|
|
161
|
-
})
|
|
129
|
+
},
|
|
162
130
|
|
|
163
|
-
|
|
131
|
+
instructions: (ctx) => serverInstructions(ctx.editorUrl, {
|
|
132
|
+
tools: ctx.tools || [],
|
|
133
|
+
capabilities: ctx.capabilitiesList || [],
|
|
134
|
+
}),
|
|
135
|
+
|
|
136
|
+
health: (ctx) => {
|
|
137
|
+
const status = ctx.engine.status()
|
|
164
138
|
return {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
139
|
+
bridge: 'browser-workbench',
|
|
140
|
+
workbench: ctx.editorUrl,
|
|
141
|
+
engine: {
|
|
142
|
+
running: status.running,
|
|
143
|
+
launching: status.launching,
|
|
144
|
+
headless: status.headless,
|
|
145
|
+
channel: status.channel,
|
|
146
|
+
tabs: status.tabs.length,
|
|
147
|
+
},
|
|
148
|
+
capabilities: {
|
|
149
|
+
engine: 'playwright',
|
|
150
|
+
headless: status.headless,
|
|
151
|
+
evaluate: status.evaluateEnabled,
|
|
152
|
+
persistentProfile: true,
|
|
153
|
+
},
|
|
154
|
+
actions: status.counters.actions,
|
|
155
|
+
errors: status.counters.errors,
|
|
156
|
+
injected: {
|
|
157
|
+
serviceHost: !!ctx.serviceHost,
|
|
158
|
+
toolHost: !!ctx.toolHost,
|
|
159
|
+
assets: !!ctx.assetStore,
|
|
175
160
|
},
|
|
176
161
|
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
metrics: (ctx) => {
|
|
165
|
+
const status = ctx.engine.status()
|
|
166
|
+
return [
|
|
167
|
+
['browser_workbench_engine_running', status.running ? 1 : 0],
|
|
168
|
+
['browser_workbench_tabs', status.tabs.length],
|
|
169
|
+
['browser_workbench_actions_total', status.counters.actions],
|
|
170
|
+
['browser_workbench_errors_total', status.counters.errors],
|
|
171
|
+
['browser_workbench_snapshots_total', status.counters.snapshots],
|
|
172
|
+
['browser_workbench_memory_rss_bytes', process.memoryUsage().rss],
|
|
173
|
+
]
|
|
174
|
+
},
|
|
185
175
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
} catch { /* 发现文件写失败不影响服务 */ }
|
|
193
|
-
}
|
|
176
|
+
/* 历史返回形状:工作台 URL / MCP URL / 引擎句柄。 */
|
|
177
|
+
resultExtras: (ctx) => ({
|
|
178
|
+
workbenchUrl: ctx.editorUrl,
|
|
179
|
+
mcpUrl: `${ctx.url || ctx.editorUrl}mcp`,
|
|
180
|
+
engine: ctx.engine,
|
|
181
|
+
}),
|
|
194
182
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
} catch { /* 不存在或不是本进程写的 */ }
|
|
201
|
-
}
|
|
183
|
+
/* 停服前先关掉所有会话的浏览器,避免僵尸进程。 */
|
|
184
|
+
beforeStop: async (ctx) => {
|
|
185
|
+
try { await ctx.sessionEngines.closeAll() } catch { /* 浏览器已退出时忽略 */ }
|
|
186
|
+
},
|
|
187
|
+
})
|
|
202
188
|
|
|
203
189
|
/* ---- 独立运行入口(无 dsh 也可手动拉起,供调试/演示)---- */
|
|
204
|
-
|
|
205
|
-
* import.meta.url 是真实路径,字符串直比会漏判(静默不启动)。 */
|
|
206
|
-
function isMainEntry() {
|
|
207
|
-
if (!process.argv[1]) return false
|
|
208
|
-
try {
|
|
209
|
-
return fs.realpathSync(path.resolve(process.argv[1])) === fileURLToPath(import.meta.url)
|
|
210
|
-
} catch {
|
|
211
|
-
return path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
if (isMainEntry()) {
|
|
215
|
-
const arg = (name, dflt) => {
|
|
216
|
-
const i = process.argv.indexOf(name)
|
|
217
|
-
return i >= 0 && process.argv[i + 1] ? process.argv[i + 1] : dflt
|
|
218
|
-
}
|
|
190
|
+
runIfMain(import.meta.url, async ({ port, dir }) => {
|
|
219
191
|
const relay = await startRelay({
|
|
220
|
-
port:
|
|
221
|
-
hostDir:
|
|
192
|
+
port: port || DEFAULT_PORT,
|
|
193
|
+
hostDir: dir || process.env.BROWSER_BRIDGE_HOME || undefined,
|
|
222
194
|
})
|
|
223
195
|
console.log('[browser-workbench] 工作台:', relay.workbenchUrl, '(浏览器打开即用)')
|
|
224
196
|
console.log('[browser-workbench] MCP 端点:', relay.mcpUrl)
|
|
225
197
|
console.log('[browser-workbench] 引擎: Playwright', relay.engine.config.headless ? '(无头)' : '(有头可见,首次导航时启动)')
|
|
226
|
-
}
|
|
198
|
+
})
|
package/server/routes/api.mjs
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 工作台 API(/api/*):可视化工作台的数据面。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* F2 每会话隔离:getEngine(req) 按请求所属会话(/s/<sid> 段,由 createSessionDispatch
|
|
5
|
+
* 缝入 req.sessionId)现场解析到那个会话自己的引擎;兼容旧 {engine} 单实例注入。
|
|
6
|
+
* 只暴露观察、实时画面与轻控制:状态 / 实时帧(SSE)/ 快照 / 标签页 / 导航 / 远端输入 / 关闭。
|
|
7
|
+
*
|
|
8
|
+
* /api/live 是本轮新增的关键一条:它把当前活动页的 JPEG 帧用 SSE 推给侧栏,
|
|
9
|
+
* 侧栏再把鼠标键盘经 /api/input 回放成真实输入——于是「浏览器在 DSH 侧栏里」
|
|
10
|
+
* 是真的可交互,不再是一张 1.2s 刷新一次的截图。
|
|
7
11
|
*/
|
|
8
12
|
import { readBody, send } from '../http-utils.mjs'
|
|
9
13
|
|
|
@@ -15,22 +19,99 @@ function sendEngineError(req, res, error) {
|
|
|
15
19
|
})
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
/** SSE 一条消息:JS 里的 JSON,避免帧里出现裸换行把事件流切坏。 */
|
|
23
|
+
function sseFrame(frame) {
|
|
24
|
+
return `data: ${JSON.stringify({ t: frame.tab, w: frame.width, h: frame.height, img: frame.data })}\n\n`
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function createApiRoutes({ engine: fallbackEngine, getEngine, embedded }) {
|
|
28
|
+
/* 每请求解析引擎:getEngine 缺省回落到注入的单实例(兼容旧装配/测试)。 */
|
|
29
|
+
const resolveEngine = typeof getEngine === 'function' ? getEngine : () => fallbackEngine
|
|
19
30
|
return [
|
|
20
31
|
/* GET /api/status —— 引擎状态 + 最近动作(工作台轮询数据源)。 */
|
|
21
32
|
async (req, res, u) => {
|
|
22
33
|
if (u.pathname !== '/api/status' || req.method !== 'GET') return false
|
|
23
34
|
try {
|
|
24
|
-
|
|
35
|
+
const engine = await resolveEngine(req)
|
|
36
|
+
/* embedded 旗标给 UI:嵌入式强制无头(见 engine.mjs resolveHeadlessPolicy),
|
|
37
|
+
* 「切到有头」按钮在嵌入式隐藏,避免承诺一个不会发生的弹窗。 */
|
|
38
|
+
send(req, res, 200, { ok: true, status: { ...engine.status(), embedded: !!embedded }, actions: engine.actionLog().slice(0, 20) })
|
|
39
|
+
} catch (error) {
|
|
40
|
+
sendEngineError(req, res, error)
|
|
41
|
+
}
|
|
42
|
+
return true
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
/* GET /api/live —— 活动页实时帧(text/event-stream)。
|
|
46
|
+
* 客户端一断开就退订,引擎随即停掉 screencast,不会在没人看时白烧 CPU。 */
|
|
47
|
+
async (req, res, u) => {
|
|
48
|
+
if (u.pathname !== '/api/live' || req.method !== 'GET') return false
|
|
49
|
+
/* 引擎解析(可能触发懒创建/启动)必须包在 try 里:失败时回结构化错误,
|
|
50
|
+
而不是让拒绝冒泡成未处理异常把整个服务进程打崩。 */
|
|
51
|
+
let engine
|
|
52
|
+
try { engine = await resolveEngine(req) } catch (error) { sendEngineError(req, res, error); return true }
|
|
53
|
+
res.writeHead(200, {
|
|
54
|
+
'content-type': 'text/event-stream; charset=utf-8',
|
|
55
|
+
'cache-control': 'no-store, no-cache, must-revalidate',
|
|
56
|
+
'x-content-type-options': 'nosniff',
|
|
57
|
+
'x-accel-buffering': 'no',
|
|
58
|
+
connection: 'keep-alive',
|
|
59
|
+
})
|
|
60
|
+
res.write(': live\n\n')
|
|
61
|
+
|
|
62
|
+
/* 背压:上一次写没冲干净就丢掉这一帧(视频流丢帧不丢语义)。 */
|
|
63
|
+
let blocked = false
|
|
64
|
+
const onFrame = (frame) => {
|
|
65
|
+
if (blocked || res.writableEnded || res.destroyed) return
|
|
66
|
+
blocked = true
|
|
67
|
+
try {
|
|
68
|
+
if (res.write(sseFrame(frame))) blocked = false
|
|
69
|
+
else res.once('drain', () => { blocked = false })
|
|
70
|
+
} catch {
|
|
71
|
+
blocked = true
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const unwatch = engine.watchFrames(onFrame)
|
|
76
|
+
/* 心跳:切到后台标签页时浏览器会节流,长连接需要定期有字节,否则被判定空闲。 */
|
|
77
|
+
const heartbeat = setInterval(() => {
|
|
78
|
+
if (res.writableEnded || res.destroyed) return
|
|
79
|
+
try { res.write(': ping\n\n') } catch { /* 已断开 */ }
|
|
80
|
+
}, 15000)
|
|
81
|
+
heartbeat.unref?.()
|
|
82
|
+
|
|
83
|
+
let closed = false
|
|
84
|
+
const stop = () => {
|
|
85
|
+
if (closed) return
|
|
86
|
+
closed = true
|
|
87
|
+
clearInterval(heartbeat)
|
|
88
|
+
try { unwatch() } catch { /* 已退订 */ }
|
|
89
|
+
}
|
|
90
|
+
req.on('close', stop)
|
|
91
|
+
res.on('close', stop)
|
|
92
|
+
res.on('error', stop) /* 写失败(客户端硬断)也要退订,别留着 screencast 白烧 CPU */
|
|
93
|
+
return true
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
/* POST /api/input —— 远端输入回放:{ type: 'pointer'|'key', ... } */
|
|
97
|
+
async (req, res, u) => {
|
|
98
|
+
if (u.pathname !== '/api/input' || req.method !== 'POST') return false
|
|
99
|
+
try {
|
|
100
|
+
const engine = await resolveEngine(req)
|
|
101
|
+
const body = await readBody(req, 64 * 1024)
|
|
102
|
+
const out = await engine.input(body)
|
|
103
|
+
send(req, res, 200, { ok: true, ...out })
|
|
25
104
|
} catch (error) {
|
|
26
105
|
sendEngineError(req, res, error)
|
|
27
106
|
}
|
|
28
107
|
return true
|
|
29
108
|
},
|
|
30
109
|
|
|
31
|
-
/* GET /api/screenshot ——
|
|
110
|
+
/* GET /api/screenshot —— 单张实时画面(PNG,不落盘)。SSE 不可用时的兜底。 */
|
|
32
111
|
async (req, res, u) => {
|
|
33
112
|
if (u.pathname !== '/api/screenshot' || req.method !== 'GET') return false
|
|
113
|
+
let engine
|
|
114
|
+
try { engine = await resolveEngine(req) } catch (error) { sendEngineError(req, res, error); return true }
|
|
34
115
|
if (!engine.status().running) {
|
|
35
116
|
send(req, res, 503, {
|
|
36
117
|
ok: false,
|
|
@@ -52,6 +133,7 @@ export function createApiRoutes({ engine }) {
|
|
|
52
133
|
async (req, res, u) => {
|
|
53
134
|
if (u.pathname !== '/api/snapshot' || req.method !== 'GET') return false
|
|
54
135
|
try {
|
|
136
|
+
const engine = await resolveEngine(req)
|
|
55
137
|
const out = await engine.snapshot({})
|
|
56
138
|
send(req, res, 200, { ok: true, ...out })
|
|
57
139
|
} catch (error) {
|
|
@@ -64,9 +146,10 @@ export function createApiRoutes({ engine }) {
|
|
|
64
146
|
async (req, res, u) => {
|
|
65
147
|
if (u.pathname !== '/api/navigate' || req.method !== 'POST') return false
|
|
66
148
|
try {
|
|
149
|
+
const engine = await resolveEngine(req)
|
|
67
150
|
const body = await readBody(req, 64 * 1024)
|
|
68
151
|
const out = await engine.navigate({ url: String(body.url || '') })
|
|
69
|
-
send(req, res, 200, { ok: true, tab: out.tab, url: out.url, title: out.title })
|
|
152
|
+
send(req, res, 200, { ok: true, tab: out.tab, url: out.url, title: out.title, note: out.note || '', authWall: !!out.authWall })
|
|
70
153
|
} catch (error) {
|
|
71
154
|
sendEngineError(req, res, error)
|
|
72
155
|
}
|
|
@@ -77,6 +160,7 @@ export function createApiRoutes({ engine }) {
|
|
|
77
160
|
async (req, res, u) => {
|
|
78
161
|
if (u.pathname !== '/api/tabs' || req.method !== 'POST') return false
|
|
79
162
|
try {
|
|
163
|
+
const engine = await resolveEngine(req)
|
|
80
164
|
const body = await readBody(req, 64 * 1024)
|
|
81
165
|
const out = await engine.tabsAction({ action: body.action || 'list', tab: body.tab, url: body.url })
|
|
82
166
|
send(req, res, 200, { ok: true, ...out })
|
|
@@ -86,17 +170,46 @@ export function createApiRoutes({ engine }) {
|
|
|
86
170
|
return true
|
|
87
171
|
},
|
|
88
172
|
|
|
89
|
-
/* POST /api/
|
|
173
|
+
/* POST /api/history { action } —— 工作台的后退/前进/刷新(与 browser_history 同源)。 */
|
|
174
|
+
async (req, res, u) => {
|
|
175
|
+
if (u.pathname !== '/api/history' || req.method !== 'POST') return false
|
|
176
|
+
try {
|
|
177
|
+
const engine = await resolveEngine(req)
|
|
178
|
+
const body = await readBody(req, 64 * 1024)
|
|
179
|
+
const out = await engine.history({ action: String(body.action || 'back') })
|
|
180
|
+
send(req, res, 200, { ok: true, action: out.action, url: out.url, tab: out.tab, note: out.note || '', authWall: !!out.authWall })
|
|
181
|
+
} catch (error) {
|
|
182
|
+
sendEngineError(req, res, error)
|
|
183
|
+
}
|
|
184
|
+
return true
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
/* POST /api/control { action: 'close' | 'headless', value? }
|
|
188
|
+
* headless 切完会关掉运行中的浏览器,下次动作按新模式重启(登录态保留)。 */
|
|
90
189
|
async (req, res, u) => {
|
|
91
190
|
if (u.pathname !== '/api/control' || req.method !== 'POST') return false
|
|
92
191
|
try {
|
|
192
|
+
const engine = await resolveEngine(req)
|
|
93
193
|
const body = await readBody(req, 64 * 1024)
|
|
94
|
-
|
|
95
|
-
|
|
194
|
+
const action = String(body.action || '')
|
|
195
|
+
if (action === 'close') {
|
|
196
|
+
send(req, res, 200, { ok: true, ...(await engine.close()) })
|
|
96
197
|
return true
|
|
97
198
|
}
|
|
98
|
-
|
|
99
|
-
|
|
199
|
+
if (action === 'resume') {
|
|
200
|
+
/* 重开工作台时恢复上次浏览器(懒启动 + 标签页恢复,不附带新导航)。 */
|
|
201
|
+
send(req, res, 200, { ok: true, ...(await engine.resume()) })
|
|
202
|
+
return true
|
|
203
|
+
}
|
|
204
|
+
if (action === 'headless') {
|
|
205
|
+
const out = await engine.setHeadless(!!body.value)
|
|
206
|
+
send(req, res, 200, { ok: true, ...out })
|
|
207
|
+
return true
|
|
208
|
+
}
|
|
209
|
+
send(req, res, 400, {
|
|
210
|
+
ok: false,
|
|
211
|
+
error: { code: 'ARG_INVALID', message: `不支持 ${action || '(空)'}`, hint: '可用:close / headless' },
|
|
212
|
+
})
|
|
100
213
|
} catch (error) {
|
|
101
214
|
sendEngineError(req, res, error)
|
|
102
215
|
}
|
|
@@ -111,7 +224,7 @@ export function createApiRoutes({ engine }) {
|
|
|
111
224
|
error: {
|
|
112
225
|
code: 'NOT_FOUND',
|
|
113
226
|
message: `未知接口 ${u.pathname}`,
|
|
114
|
-
hint: '可用:GET /api/status、GET /api/screenshot、GET /api/snapshot、POST /api/navigate、POST /api/tabs、POST /api/control',
|
|
227
|
+
hint: '可用:GET /api/status、GET /api/live、GET /api/screenshot、GET /api/snapshot、POST /api/navigate、POST /api/input、POST /api/tabs、POST /api/control',
|
|
115
228
|
},
|
|
116
229
|
})
|
|
117
230
|
return true
|
package/server/routes/assets.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/** 对象仓库路由统一来自
|
|
1
|
+
/** 对象仓库路由统一来自 @capyclaw/asset-service 公共插件。 */
|
|
2
2
|
export { createAssetRoutes } from '../shared/asset-service.mjs'
|