@capyclaw/browser-workbench 0.0.0-stage → 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 +88 -2
- package/contract/browser-contract.json +1349 -0
- package/demo/form.html +112 -0
- package/lib/host.mjs +1 -0
- 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/node_modules/@capyclaw/document-workbench/src/store/file-backend.mjs +158 -0
- 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 +79 -4
- package/plugin.mjs +1 -0
- package/server/constants.mjs +16 -0
- package/server/contract-snapshots.mjs +81 -0
- package/server/contract.mjs +24 -0
- package/server/embedded-host.mjs +247 -0
- package/server/engine.mjs +2466 -0
- package/server/governor.mjs +189 -0
- package/server/http-utils.mjs +2 -0
- package/server/human.mjs +628 -0
- package/server/infra/http.mjs +2 -0
- package/server/infra/tuning.mjs +2 -0
- package/server/input.mjs +154 -0
- package/server/login-vault.mjs +109 -0
- package/server/mcp/handler.mjs +2 -0
- package/server/mcp/instructions.mjs +31 -0
- package/server/orphans.mjs +163 -0
- package/server/relay.mjs +198 -0
- package/server/routes/api.mjs +233 -0
- package/server/routes/assets.mjs +2 -0
- package/server/routes/mcp.mjs +17 -0
- package/server/routes/workbench.mjs +33 -0
- package/server/session-engines.mjs +184 -0
- package/server/shared/SHARED_MANIFEST.json +70 -0
- package/server/shared/asset-service.mjs +2 -0
- package/server/shared/editor-host.mjs +2 -0
- package/server/shared/kit/editor/lease.mjs +2 -0
- package/server/shared/kit/service/api.mjs +2 -0
- package/server/shared/kit/service/http.mjs +2 -0
- package/server/shared/kit/service/mcp-http.mjs +2 -0
- package/server/shared/kit/tools/validate.mjs +2 -0
- package/server/shared/kit/tuning.mjs +2 -0
- package/server/shared/kit/util/fs-lock.mjs +2 -0
- package/server/shared/service-host.mjs +2 -0
- package/server/shared/tool-host.mjs +2 -0
- package/server/shared/tuning.mjs +2 -0
- package/server/tools/capabilities/contract.mjs +55 -0
- package/server/tools/capabilities/evaluate.mjs +36 -0
- package/server/tools/capabilities/index.mjs +26 -0
- package/server/tools/capabilities/interaction.mjs +215 -0
- package/server/tools/capabilities/navigation.mjs +35 -0
- package/server/tools/capabilities/screenshot.mjs +50 -0
- package/server/tools/capabilities/session.mjs +81 -0
- package/server/tools/capabilities/snapshot.mjs +30 -0
- package/server/tools/capabilities/tabs.mjs +35 -0
- package/server/tools/index.mjs +12 -0
- package/server/tools/kernel/define.mjs +5 -0
- package/server/tools/kernel/output.mjs +30 -0
- package/server/tools/kernel/ports.mjs +59 -0
- package/server/tools/kernel/registry.mjs +17 -0
- package/server/tools.mjs +3 -0
- package/server/workbench-framework.mjs +305 -0
- package/ui/app.js +447 -0
- package/ui/index.html +46 -0
- package/ui/style.css +144 -0
package/demo/form.html
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>演示表单 · 离线练习页</title>
|
|
7
|
+
<style>
|
|
8
|
+
body { font: 15px/1.7 "Segoe UI", "Microsoft YaHei", sans-serif; max-width: 640px; margin: 32px auto; padding: 0 16px; color: #222; }
|
|
9
|
+
fieldset { border: 1px solid #ccd3e0; border-radius: 10px; margin-bottom: 20px; }
|
|
10
|
+
legend { padding: 0 8px; font-weight: 600; }
|
|
11
|
+
label { display: block; margin: 10px 0 4px; font-weight: 600; }
|
|
12
|
+
input[type="text"], input[type="password"], select, textarea {
|
|
13
|
+
width: 100%; padding: 8px 10px; border: 1px solid #ccd3e0; border-radius: 6px; font: inherit;
|
|
14
|
+
}
|
|
15
|
+
.row { display: flex; gap: 16px; align-items: center; margin: 10px 0; }
|
|
16
|
+
button { padding: 9px 18px; border-radius: 6px; border: 1px solid #3a6ee8; background: #3a6ee8; color: #fff; cursor: pointer; font-size: 15px; }
|
|
17
|
+
button.ghost { background: #fff; color: #3a6ee8; }
|
|
18
|
+
#results { background: #f4f7fd; border-radius: 8px; padding: 10px 14px; min-height: 48px; }
|
|
19
|
+
#results li { margin: 4px 0; }
|
|
20
|
+
#count { font-weight: 700; }
|
|
21
|
+
input[type="range"] { width: 60%; vertical-align: middle; }
|
|
22
|
+
.fake-btn { display: inline-block; padding: 9px 18px; border-radius: 6px; background: #eef2fc; color: #27448f; border: 1px dashed #7f9ce0; cursor: pointer; user-select: none; }
|
|
23
|
+
</style>
|
|
24
|
+
</head>
|
|
25
|
+
<body>
|
|
26
|
+
<h1>演示表单</h1>
|
|
27
|
+
<p>内置离线练习页:不依赖外网,供 AI 工具链(browser_navigate → browser_snapshot → browser_fill / browser_select / browser_click)演示与 e2e 冒烟使用。</p>
|
|
28
|
+
|
|
29
|
+
<form id="demo-form">
|
|
30
|
+
<fieldset>
|
|
31
|
+
<legend>注册信息</legend>
|
|
32
|
+
<label for="username">用户名</label>
|
|
33
|
+
<input type="text" id="username" name="username" placeholder="请输入用户名">
|
|
34
|
+
|
|
35
|
+
<label for="password">密码</label>
|
|
36
|
+
<input type="password" id="password" name="password" placeholder="密码会被快照掩码显示">
|
|
37
|
+
|
|
38
|
+
<label for="city">所在城市</label>
|
|
39
|
+
<select id="city" name="city">
|
|
40
|
+
<option value="">— 请选择 —</option>
|
|
41
|
+
<option value="beijing">北京</option>
|
|
42
|
+
<option value="shanghai">上海</option>
|
|
43
|
+
<option value="shenzhen">深圳</option>
|
|
44
|
+
</select>
|
|
45
|
+
|
|
46
|
+
<div class="row">
|
|
47
|
+
<label style="margin:0"><input type="checkbox" id="agree" name="agree"> 我已阅读并同意服务条款</label>
|
|
48
|
+
</div>
|
|
49
|
+
|
|
50
|
+
<label for="note">备注</label>
|
|
51
|
+
<textarea id="note" name="note" rows="3" placeholder="选填"></textarea>
|
|
52
|
+
|
|
53
|
+
<div class="row">
|
|
54
|
+
<button type="submit" id="submit">提交注册</button>
|
|
55
|
+
<button type="button" id="counter" class="ghost">点我计数:<span id="count">0</span></button>
|
|
56
|
+
</div>
|
|
57
|
+
</fieldset>
|
|
58
|
+
|
|
59
|
+
<fieldset>
|
|
60
|
+
<legend>进阶:拖拽 / 无 role 按钮</legend>
|
|
61
|
+
<label for="slider">滑块(用 browser_drag 拖到最右)</label>
|
|
62
|
+
<div class="row">
|
|
63
|
+
<input type="range" id="slider" name="slider" min="0" max="100" value="0" step="1">
|
|
64
|
+
<output id="slider-out">0</output>
|
|
65
|
+
</div>
|
|
66
|
+
|
|
67
|
+
<label>下面这个「下一步」是普通 div,没有 role/tabindex,快照里不会有 ref</label>
|
|
68
|
+
<div class="row">
|
|
69
|
+
<div id="fake-next" class="fake-btn">下一步</div>
|
|
70
|
+
</div>
|
|
71
|
+
</fieldset>
|
|
72
|
+
</form>
|
|
73
|
+
|
|
74
|
+
<h2>操作结果</h2>
|
|
75
|
+
<ul id="results" role="status">
|
|
76
|
+
<li>(还没有操作)</li>
|
|
77
|
+
</ul>
|
|
78
|
+
|
|
79
|
+
<script>
|
|
80
|
+
var results = document.getElementById('results')
|
|
81
|
+
var count = 0
|
|
82
|
+
function log(text) {
|
|
83
|
+
if (results.firstChild && results.firstChild.textContent === '(还没有操作)') results.innerHTML = ''
|
|
84
|
+
var li = document.createElement('li')
|
|
85
|
+
li.textContent = new Date().toLocaleTimeString() + ' — ' + text
|
|
86
|
+
results.insertBefore(li, results.firstChild)
|
|
87
|
+
}
|
|
88
|
+
document.getElementById('demo-form').addEventListener('submit', function (e) {
|
|
89
|
+
e.preventDefault()
|
|
90
|
+
log('已提交注册:username=' + (document.getElementById('username').value || '(空)') +
|
|
91
|
+
',city=' + (document.getElementById('city').value || '(未选)') +
|
|
92
|
+
',agree=' + (document.getElementById('agree').checked ? 'on' : 'off'))
|
|
93
|
+
})
|
|
94
|
+
document.getElementById('counter').addEventListener('click', function () {
|
|
95
|
+
count += 1
|
|
96
|
+
document.getElementById('count').textContent = count
|
|
97
|
+
log('计数按钮第 ' + count + ' 次被点击')
|
|
98
|
+
})
|
|
99
|
+
var slider = document.getElementById('slider')
|
|
100
|
+
var sliderOut = document.getElementById('slider-out')
|
|
101
|
+
slider.addEventListener('input', function () {
|
|
102
|
+
sliderOut.textContent = slider.value
|
|
103
|
+
})
|
|
104
|
+
slider.addEventListener('change', function () {
|
|
105
|
+
log('滑块拖到 ' + slider.value + '(' + (Number(slider.value) >= 100 ? '到最右' : '未到最右') + ')')
|
|
106
|
+
})
|
|
107
|
+
document.getElementById('fake-next').addEventListener('click', function () {
|
|
108
|
+
log('「下一步」(div 假按钮)被点击')
|
|
109
|
+
})
|
|
110
|
+
</script>
|
|
111
|
+
</body>
|
|
112
|
+
</html>
|
package/lib/host.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { name, apply } from '../server/embedded-host.mjs'
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @capyclaw/asset-service
|
|
2
|
+
|
|
3
|
+
DSH 公共资产插件。功能插件通过 `ctx.assets` 获得统一的 sha256 对象仓库和 `/assets` 路由。
|
|
4
|
+
|
|
5
|
+
## 使用
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
export const inject = ['assets']
|
|
9
|
+
|
|
10
|
+
export function apply(ctx) {
|
|
11
|
+
const app = ctx.serviceHost.createApp({ id: 'my-plugin' })
|
|
12
|
+
app.use(ctx.assets.routes())
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// 或在插件内部写入
|
|
16
|
+
const asset = await ctx.assets.put(buffer, 'image/png')
|
|
17
|
+
// { id, key, url: '/assets/<sha256>', size, contentType }
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
独立运行或测试:
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import { createFileAssetStore, createAssetRoutes } from '@capyclaw/asset-service/src'
|
|
24
|
+
const store = createFileAssetStore({ dir: './assets' })
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 路由归属
|
|
28
|
+
|
|
29
|
+
多个插件共用一个 service-host app 时,用 `ctx.assets.mount(app)` 只挂一次 `/assets`:
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
ctx.assets.mount(app, { store: assetStore })
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
重复 mount 会被忽略;不要再手写 `app.use(ctx.assets.routes())`。
|
|
36
|
+
|
|
37
|
+
## 提供什么
|
|
38
|
+
|
|
39
|
+
- `createWorkspaceAssetStore({ storeClient, workId })`:资产归当前 work
|
|
40
|
+
- `createFileAssetStore({ dir })`:本地目录后端
|
|
41
|
+
- `createAssetRoutes({ assetStore, basePath })`:GET/HEAD `/assets/<id>`、POST `<basePath>/assets`
|
|
42
|
+
- `ctx.assets.put/get`:默认 store 快捷方法
|
|
43
|
+
|
|
44
|
+
## 契约
|
|
45
|
+
|
|
46
|
+
- 资产按 sha256 去重,不可变
|
|
47
|
+
- url 固定为 `/assets/<id>`,可长期缓存
|
|
48
|
+
- 内容类型由上传方声明,读取时原样返回
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../capyclaw-suite-kit/suite.schema.json",
|
|
3
|
+
"name": "dsh-asset-service-suite",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"title": "Asset Service",
|
|
6
|
+
"description": "通用对象资产:sha256 仓库、/assets 路由、上传。",
|
|
7
|
+
"packages": {
|
|
8
|
+
"@capyclaw/asset-service": {
|
|
9
|
+
"role": "provider",
|
|
10
|
+
"version": "^0.1.4",
|
|
11
|
+
"path": ".",
|
|
12
|
+
"provides": {
|
|
13
|
+
"services": [
|
|
14
|
+
"assets"
|
|
15
|
+
],
|
|
16
|
+
"capabilities": {
|
|
17
|
+
"assets.store": "1.0.0"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"rows": [
|
|
23
|
+
{
|
|
24
|
+
"id": "asset-service",
|
|
25
|
+
"name": "@capyclaw/asset-service"
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"checks": []
|
|
29
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** @capyclaw/asset-service 插件:向同进程插件提供 ctx.assets。 */
|
|
2
|
+
import { defineDriver } from '@capyclaw/foundation/abi'
|
|
3
|
+
import { createAssetHost } from '../src/index.mjs'
|
|
4
|
+
|
|
5
|
+
export const { name, inject, apply } = defineDriver({
|
|
6
|
+
name: 'asset-service',
|
|
7
|
+
service: 'assets',
|
|
8
|
+
apply(ctx, config = {}) {
|
|
9
|
+
const service = createAssetHost(config)
|
|
10
|
+
const dispose = ctx.provide('assets', service)
|
|
11
|
+
console.log('[asset-service] ready')
|
|
12
|
+
return () => { if (typeof dispose === 'function') dispose() }
|
|
13
|
+
},
|
|
14
|
+
})
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capyclaw/asset-service",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "DSH 公共资产插件:sha256 对象仓库、/assets 路由、base64 上传与 content-type,向插件提供 ctx.assets。",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./lib/host.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./lib/host.mjs",
|
|
9
|
+
"./src": "./src/index.mjs",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=18",
|
|
14
|
+
"dsh": "^0.2.0-rc.2"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"dsh": {
|
|
20
|
+
"bundle": {
|
|
21
|
+
"patch": "./cordis.patch.yml"
|
|
22
|
+
},
|
|
23
|
+
"suite": "./dsh-suite.json",
|
|
24
|
+
"apiVersion": "1.0.0",
|
|
25
|
+
"category": "service",
|
|
26
|
+
"platform": "both",
|
|
27
|
+
"driver": {
|
|
28
|
+
"service": "assets"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"meta": {
|
|
32
|
+
"title": "公共资产服务",
|
|
33
|
+
"description": "sha256 对象仓库、/assets 路由、base64 上传与 content-type,向插件提供 ctx.assets"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"lib/",
|
|
37
|
+
"src/",
|
|
38
|
+
"cordis.patch.yml",
|
|
39
|
+
"dsh-suite.json",
|
|
40
|
+
"README.md"
|
|
41
|
+
],
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"scripts": {
|
|
44
|
+
"test": "node --test test/*.test.mjs"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@capyclaw/plugin-kit": "^0.2.0",
|
|
48
|
+
"@capyclaw/foundation": "^0.1.1"
|
|
49
|
+
},
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "git+https://github.com/Maple496/capyclaw.git",
|
|
53
|
+
"directory": "C/packages/capyclaw-asset-service"
|
|
54
|
+
},
|
|
55
|
+
"bugs": {
|
|
56
|
+
"url": "https://github.com/Maple496/capyclaw/issues"
|
|
57
|
+
},
|
|
58
|
+
"homepage": "https://github.com/Maple496/capyclaw/tree/main/C/packages/capyclaw-asset-service#readme"
|
|
59
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @capyclaw/asset-service —— 通用对象资产仓库。
|
|
3
|
+
*
|
|
4
|
+
* 功能插件不再各自实现 `/assets/<sha256>`、base64 上传、content-type 与缓存头。
|
|
5
|
+
* 资产按 sha256 去重,url 为 `/assets/<id>`。
|
|
6
|
+
*
|
|
7
|
+
* 两种后端:
|
|
8
|
+
* - workspace:storeClient(ctx.workspace 的 scoped client),资产归当前 work;
|
|
9
|
+
* - file:本地目录,适合无 workspace 的独立运行/测试。
|
|
10
|
+
*/
|
|
11
|
+
import crypto from 'node:crypto'
|
|
12
|
+
import fs from 'node:fs'
|
|
13
|
+
import path from 'node:path'
|
|
14
|
+
import { send, readBody } from '@capyclaw/plugin-kit/service/http'
|
|
15
|
+
import { createServiceApi } from '@capyclaw/plugin-kit/service/api'
|
|
16
|
+
|
|
17
|
+
function sha256(buffer) {
|
|
18
|
+
return crypto.createHash('sha256').update(buffer).digest('hex')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const ASSET_ID_RE = /^[a-f0-9]{64}$/
|
|
22
|
+
|
|
23
|
+
function validId(id) {
|
|
24
|
+
return ASSET_ID_RE.test(String(id || ''))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function normalizeBuffer(value) {
|
|
28
|
+
if (Buffer.isBuffer(value)) return value
|
|
29
|
+
if (value instanceof Uint8Array) return Buffer.from(value)
|
|
30
|
+
throw new Error('asset: 数据必须是 Buffer/Uint8Array')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 基于 ctx.workspace 的 scoped WorkspaceClient。 */
|
|
34
|
+
export function createWorkspaceAssetStore({ storeClient, workId = 'main' } = {}) {
|
|
35
|
+
if (!storeClient || typeof storeClient.put !== 'function') throw new Error('createWorkspaceAssetStore 需要 storeClient')
|
|
36
|
+
return {
|
|
37
|
+
kind: 'workspace',
|
|
38
|
+
async put(value, contentType = 'application/octet-stream') {
|
|
39
|
+
const buffer = normalizeBuffer(value)
|
|
40
|
+
const id = sha256(buffer)
|
|
41
|
+
const key = `assets/${id}`
|
|
42
|
+
storeClient.put(workId, key, buffer, { contentType })
|
|
43
|
+
return { id, key, url: `/assets/${id}`, size: buffer.length, contentType }
|
|
44
|
+
},
|
|
45
|
+
get(id) {
|
|
46
|
+
if (!validId(id)) return null
|
|
47
|
+
const key = `assets/${id}`
|
|
48
|
+
try {
|
|
49
|
+
const data = storeClient.get(workId, key)
|
|
50
|
+
if (!data) return null
|
|
51
|
+
const meta = storeClient.list(workId).find((item) => item.key === key)
|
|
52
|
+
return { data, contentType: meta?.contentType || 'application/octet-stream' }
|
|
53
|
+
} catch {
|
|
54
|
+
/* 缺失/权限错误按 404 处理,不能把 500 泄漏给资产路由。 */
|
|
55
|
+
return null
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
has(id) {
|
|
59
|
+
if (!validId(id)) return false
|
|
60
|
+
try { return !!storeClient.get(workId, `assets/${id}`) } catch { return false }
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** 本地目录后端:<dir>/<sha256> + <dir>/<sha256>.meta.json。 */
|
|
66
|
+
export function createFileAssetStore({ dir } = {}) {
|
|
67
|
+
if (!dir) throw new Error('createFileAssetStore 需要 dir')
|
|
68
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
69
|
+
return {
|
|
70
|
+
kind: 'file',
|
|
71
|
+
async put(value, contentType = 'application/octet-stream') {
|
|
72
|
+
const buffer = normalizeBuffer(value)
|
|
73
|
+
const id = sha256(buffer)
|
|
74
|
+
const file = path.join(dir, id)
|
|
75
|
+
const metaFile = file + '.meta.json'
|
|
76
|
+
const existingOk = (() => {
|
|
77
|
+
try { return fs.statSync(file).size === buffer.length } catch { return false }
|
|
78
|
+
})()
|
|
79
|
+
if (!existingOk) {
|
|
80
|
+
const tmp = `${file}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}`
|
|
81
|
+
fs.writeFileSync(tmp, buffer)
|
|
82
|
+
fs.renameSync(tmp, file)
|
|
83
|
+
}
|
|
84
|
+
const metaTmp = `${metaFile}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}`
|
|
85
|
+
fs.writeFileSync(metaTmp, JSON.stringify({ contentType, size: buffer.length }))
|
|
86
|
+
fs.renameSync(metaTmp, metaFile)
|
|
87
|
+
return { id, key: id, url: `/assets/${id}`, size: buffer.length, contentType }
|
|
88
|
+
},
|
|
89
|
+
get(id) {
|
|
90
|
+
if (!validId(id)) return null
|
|
91
|
+
const file = path.join(dir, path.basename(String(id)))
|
|
92
|
+
try {
|
|
93
|
+
const data = fs.readFileSync(file)
|
|
94
|
+
/* 内容寻址仓库必须复核 hash:截断/篡改的对象不能静默返回。 */
|
|
95
|
+
if (sha256(data) !== id) {
|
|
96
|
+
console.error(`[asset-service] 对象校验失败,拒绝返回: ${id}`)
|
|
97
|
+
return null
|
|
98
|
+
}
|
|
99
|
+
let contentType = 'application/octet-stream'
|
|
100
|
+
try { contentType = JSON.parse(fs.readFileSync(file + '.meta.json', 'utf8')).contentType || contentType } catch { /* 默认 */ }
|
|
101
|
+
return { data, contentType }
|
|
102
|
+
} catch {
|
|
103
|
+
return null
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
has(id) {
|
|
107
|
+
if (!validId(id)) return false
|
|
108
|
+
try { return fs.existsSync(path.join(dir, path.basename(String(id)))) } catch { return false }
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** 防止 text/html / svg 在 loopback 同源执行脚本;图片仍按原 MIME 内联。 */
|
|
114
|
+
function safeContentType(type) {
|
|
115
|
+
const base = String(type || '').split(';')[0].trim().toLowerCase() || 'application/octet-stream'
|
|
116
|
+
if (base === 'text/html' || base === 'application/xhtml+xml' || base === 'image/svg+xml') {
|
|
117
|
+
return 'text/plain; charset=utf-8'
|
|
118
|
+
}
|
|
119
|
+
return base
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* service-host 兼容的资产路由。
|
|
124
|
+
* GET/HEAD `/assets/<id>`(同时兼容 `<basePath>/assets/<id>`);
|
|
125
|
+
* POST `/assets` 或 `<basePath>/assets`(JSON: { data: base64, contentType })。
|
|
126
|
+
*/
|
|
127
|
+
export function createAssetRoutes({ assetStore, basePath = '', maxUploadBytes = 10 * 1024 * 1024 } = {}) {
|
|
128
|
+
const prefix = basePath === '/' ? '' : String(basePath || '').replace(/\/+$/, '')
|
|
129
|
+
const getPrefixes = ['/assets/', prefix ? `${prefix}/assets/` : null].filter(Boolean)
|
|
130
|
+
const postPaths = new Set(['/assets', prefix ? `${prefix}/assets` : null].filter(Boolean))
|
|
131
|
+
return async function assetRoutes(req, res, u) {
|
|
132
|
+
const p = u.pathname
|
|
133
|
+
if (req.method === 'GET' || req.method === 'HEAD') {
|
|
134
|
+
const getPrefix = getPrefixes.find((candidate) => p.startsWith(candidate))
|
|
135
|
+
if (getPrefix) {
|
|
136
|
+
if (!assetStore) { send(req, res, 404, { error: 'asset store unavailable' }); return true }
|
|
137
|
+
const id = decodeURIComponent(p.slice(getPrefix.length))
|
|
138
|
+
if (!validId(id)) { send(req, res, 404, { error: 'asset not found' }); return true }
|
|
139
|
+
const asset = assetStore.get(id)
|
|
140
|
+
if (!asset) { send(req, res, 404, { error: 'asset not found' }); return true }
|
|
141
|
+
res.writeHead(200, {
|
|
142
|
+
'content-type': safeContentType(asset.contentType),
|
|
143
|
+
'content-length': asset.data.length,
|
|
144
|
+
'cache-control': 'public, max-age=31536000, immutable',
|
|
145
|
+
'x-content-type-options': 'nosniff',
|
|
146
|
+
'referrer-policy': 'no-referrer',
|
|
147
|
+
})
|
|
148
|
+
res.end(req.method === 'HEAD' ? undefined : asset.data)
|
|
149
|
+
return true
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (postPaths.has(p) && req.method === 'POST') {
|
|
153
|
+
if (!assetStore) { send(req, res, 503, { error: 'asset store unavailable' }); return true }
|
|
154
|
+
let body
|
|
155
|
+
try { body = await readBody(req, maxUploadBytes) } catch (error) {
|
|
156
|
+
const status = error?.code === 'BODY_TOO_LARGE' ? 413 : 400
|
|
157
|
+
send(req, res, status, { error: String(error.message || error) })
|
|
158
|
+
return true
|
|
159
|
+
}
|
|
160
|
+
if (!body || typeof body.data !== 'string' || !body.data) {
|
|
161
|
+
send(req, res, 400, { error: '缺少图片数据' })
|
|
162
|
+
return true
|
|
163
|
+
}
|
|
164
|
+
const buffer = Buffer.from(body.data, 'base64')
|
|
165
|
+
/* 严格 base64:非法字符 / 错误填充 / 非规范编码一律 400,不再宽松解码把损坏
|
|
166
|
+
* 字节静默入库(B 轴 P0-7)。round-trip 比对同时挡住非规范填充位。 */
|
|
167
|
+
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(body.data) || body.data.length % 4 !== 0 || buffer.toString('base64') !== body.data) {
|
|
168
|
+
send(req, res, 400, { error: '图片数据不是合法 base64' })
|
|
169
|
+
return true
|
|
170
|
+
}
|
|
171
|
+
if (!buffer.length) { send(req, res, 400, { error: '图片数据为空' }); return true }
|
|
172
|
+
const asset = await assetStore.put(buffer, body.contentType || 'application/octet-stream')
|
|
173
|
+
send(req, res, 200, { ok: true, ...asset })
|
|
174
|
+
return true
|
|
175
|
+
}
|
|
176
|
+
return false
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function createAssetHost(config = {}) {
|
|
181
|
+
const defaultStore = config.storeClient
|
|
182
|
+
? createWorkspaceAssetStore({ storeClient: config.storeClient, workId: config.workId })
|
|
183
|
+
: config.dir
|
|
184
|
+
? createFileAssetStore({ dir: config.dir })
|
|
185
|
+
: null
|
|
186
|
+
|
|
187
|
+
return {
|
|
188
|
+
api: createServiceApi('assets', '1.0.0', ['workspace-store', 'file-store', 'routes', 'sha256', 'mount']),
|
|
189
|
+
version: '0.1.0',
|
|
190
|
+
createStore: createWorkspaceAssetStore,
|
|
191
|
+
createFileStore: createFileAssetStore,
|
|
192
|
+
routes: createAssetRoutes,
|
|
193
|
+
store: defaultStore,
|
|
194
|
+
/**
|
|
195
|
+
* 每个 service-host app 只挂一次资产路由,避免多个插件重复争抢 /assets。
|
|
196
|
+
* @param {object} hostApp createServiceApp() 返回值
|
|
197
|
+
* @param {{ store?: object, basePath?: string }} options
|
|
198
|
+
*/
|
|
199
|
+
mount(hostApp, { store = defaultStore, basePath = '' } = {}) {
|
|
200
|
+
if (!hostApp || typeof hostApp.use !== 'function') throw new Error('assets.mount 需要 service-host app')
|
|
201
|
+
if (!store) throw new Error('assets.mount: 没有可用 store')
|
|
202
|
+
if (hostApp.__dshAssetsMounted) return () => {}
|
|
203
|
+
hostApp.__dshAssetsMounted = true
|
|
204
|
+
const unuse = hostApp.use(createAssetRoutes({ assetStore: store, basePath }))
|
|
205
|
+
let disposed = false
|
|
206
|
+
return () => {
|
|
207
|
+
if (disposed) return
|
|
208
|
+
disposed = true
|
|
209
|
+
/* 真正卸载路由;否则热重载后旧 store 仍会抢答 /assets。 */
|
|
210
|
+
if (typeof unuse === 'function') unuse()
|
|
211
|
+
hostApp.__dshAssetsMounted = false
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
async put(value, contentType) {
|
|
215
|
+
if (!defaultStore) throw new Error('asset-service: 未配置 storeClient/dir')
|
|
216
|
+
return defaultStore.put(value, contentType)
|
|
217
|
+
},
|
|
218
|
+
get(id) {
|
|
219
|
+
if (!defaultStore) throw new Error('asset-service: 未配置 storeClient/dir')
|
|
220
|
+
return defaultStore.get(id)
|
|
221
|
+
},
|
|
222
|
+
}
|
|
223
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# @capyclaw/document-workbench
|
|
2
|
+
|
|
3
|
+
通用文档工作台框架。它把「文档会话协议」从具体文档插件里抽出来,供 PPT、Canvas、DOCX、XLSX 等编辑器插件复用。
|
|
4
|
+
|
|
5
|
+
它是**纯库**,不是运行时插件:不提供 `ctx.*`,不监听端口,也不生成 service row。HTTP 宿主、工具注册、资产、编辑器托管仍由 `@capyclaw/service-host` / `@capyclaw/tool-host` / `@capyclaw/asset-service` / `@capyclaw/editor-host` 提供;状态持久化(journal/checkpoint/file backend)由本包 `store/file-backend` 承担(原 `@capyclaw/state-service` 已于 2026-11-15 退役)。
|
|
6
|
+
|
|
7
|
+
## 分层
|
|
8
|
+
|
|
9
|
+
| 子路径 | 位置 | 职责 |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| `@capyclaw/document-workbench/session` | Node | `DocumentSession`:seq/命令队列/ack/state/ui/shot/owner lease/checkpoint/recover |
|
|
12
|
+
| `@capyclaw/document-workbench/ops` | Node | `defineOp` / `createOpRegistry`:op 元数据、snapshot 策略、未知指令 |
|
|
13
|
+
| `@capyclaw/document-workbench/bridge` | Node | `createDocumentBridge`:标准 HTTP 端点族 |
|
|
14
|
+
| `@capyclaw/document-workbench/client` | Browser | `createEditorClient`:claim/心跳/长轮询/镜像/应用/截图请求 |
|
|
15
|
+
| `@capyclaw/document-workbench/screenshot` | Browser | `composeContactSheet` / `composeTiles` |
|
|
16
|
+
| `@capyclaw/document-workbench/testing` | Node | 内存 backend、fake adapter,供一致性测试 |
|
|
17
|
+
|
|
18
|
+
浏览器侧只能从 `./client` 与 `./screenshot` 导入;这两个入口不依赖 `node:*`。
|
|
19
|
+
|
|
20
|
+
## 最小接入
|
|
21
|
+
|
|
22
|
+
服务端:
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { DocumentSession } from '@capyclaw/document-workbench/session'
|
|
26
|
+
import { createDocumentBridge } from '@capyclaw/document-workbench/bridge'
|
|
27
|
+
import { createOpRegistry } from '@capyclaw/document-workbench/ops'
|
|
28
|
+
import { createMemoryBackend } from '@capyclaw/document-workbench/testing'
|
|
29
|
+
|
|
30
|
+
const session = new DocumentSession({
|
|
31
|
+
backend,
|
|
32
|
+
initialDoc: { document: { value: 0 } },
|
|
33
|
+
documentKey: 'document',
|
|
34
|
+
summary: (doc) => ({ value: doc.document?.value }),
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const ops = createOpRegistry({
|
|
38
|
+
modules: { counter: { inc: { run: (doc, cmd) => { doc.document.value += cmd.by || 1 } } } },
|
|
39
|
+
snapshot: (doc) => { /* 可选:mutating op 前拍快照 */ },
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const bridge = createDocumentBridge({
|
|
43
|
+
session,
|
|
44
|
+
basePath: '/api/my-doc',
|
|
45
|
+
documentKey: 'document',
|
|
46
|
+
documentPath: '/document',
|
|
47
|
+
apply: (cmd) => ops.apply(session.getDocument(), cmd),
|
|
48
|
+
projectStatus: (doc) => ({ value: doc.document?.value }),
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
for (const route of bridge.routes) app.use(route)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
浏览器侧:
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
import { createEditorClient } from '@capyclaw/document-workbench/client'
|
|
58
|
+
|
|
59
|
+
const client = createEditorClient({
|
|
60
|
+
api,
|
|
61
|
+
clientId: 'tab-1',
|
|
62
|
+
documentKey: 'document',
|
|
63
|
+
documentPath: '/document',
|
|
64
|
+
adapter: {
|
|
65
|
+
isMounted: () => !!editor.mounted,
|
|
66
|
+
load: (doc) => editor.load(doc),
|
|
67
|
+
dump: () => editor.dump(),
|
|
68
|
+
apply: (cmds) => editor.apply(cmds),
|
|
69
|
+
applyUi: (cmds) => editor.applyView(cmds),
|
|
70
|
+
onChange: (fn) => editor.on('change', fn),
|
|
71
|
+
renderScreenshot: () => editor.renderContactSheet(),
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
await client.ensureLinked()
|
|
76
|
+
await client.restore()
|
|
77
|
+
await client.activate()
|
|
78
|
+
client.claimLoop()
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## 协议字段
|
|
82
|
+
|
|
83
|
+
标准信封:
|
|
84
|
+
|
|
85
|
+
```text
|
|
86
|
+
seq, cmds, title, applied_seq, applied, error, updated,
|
|
87
|
+
state_seq, ui_seq, ui, shot_req, shot { req, data }, owner
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
- `seq`:服务端批次号,push 时自增。
|
|
91
|
+
- `applied_seq` / `applied`:当前批次已应用数与回执。
|
|
92
|
+
- `state_seq`:编辑器镜像对应的批次号;旧镜像不会覆盖新文档。
|
|
93
|
+
- `ui_seq` / `ui`:页面级命令(present/select 等),不写文档。
|
|
94
|
+
- `shot_req` / `shot`:截图请求与结果,旧结果会被丢弃。
|
|
95
|
+
- `owner`:文档 owner 租约,默认 TTL 10s。
|
|
96
|
+
|
|
97
|
+
## 实时性与传输(0.2.0)
|
|
98
|
+
|
|
99
|
+
- **变更订阅**:`DocumentSession#subscribe(fn)` / `#waitForChange(timeoutMs)`——
|
|
100
|
+
push/ack/state/ui/shot 的每次状态迁移都会即时唤醒订阅方;长轮询
|
|
101
|
+
`GET /watch` 与工具侧等待不再受轮询粒度影响(`watch.pollMs` 保留为兜底)。
|
|
102
|
+
- **响应轻量化**:`GET /watch` 只回协议字段(`seq/applied_seq/state_seq/error/
|
|
103
|
+
title/shot_req/ui_seq/cmds/ui`),不回领域文档与截图 base64;`POST`(push/
|
|
104
|
+
ack/state/shot-*)响应同理只回回执字段。领域文档只在 `GET` 主端点(编辑器
|
|
105
|
+
restore)与 `GET /doc|/deck` 出全量。
|
|
106
|
+
|
|
107
|
+
## 两种权威模式
|
|
108
|
+
|
|
109
|
+
- `authority: 'server'`:服务端执行命令,编辑器只拉镜像;PPT 使用这种模式。
|
|
110
|
+
- `authority: 'editor'`:服务端只 push,编辑器应用命令后 `POST /ack`;适合 Canvas 这类编辑器权威的模型。
|
|
111
|
+
|
|
112
|
+
## 边界
|
|
113
|
+
|
|
114
|
+
- **不要**把 deck/slide/布局/审计等 PPT 领域逻辑放进本包。
|
|
115
|
+
- **不要**把本包做成 service plugin;它是被功能插件 import 的框架库。
|
|
116
|
+
- `@capyclaw/editor-host` 的 lease 是「浏览器标签页租约」;本包的 `owner` 是「文档归属租约」,两者不要混用。
|
|
117
|
+
- checkpoint 的领域载荷放在 `documentKey` 下(PPT 是 `deck`)。
|
|
118
|
+
|
|
119
|
+
## 测试
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
npm test
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
测试覆盖 session 状态迁移、串行批次、checkpoint/recover、owner lease、watch、sanitizer、op registry、bridge 端点、浏览器客户端以及编辑器权威模式。
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capyclaw/document-workbench",
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"description": "通用文档工作台框架:版本化文档会话、命令注册、桥路由、浏览器编辑器客户端与截图协议。",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.mjs",
|
|
9
|
+
"./session": "./src/session/index.mjs",
|
|
10
|
+
"./session-context": "./src/session/context.mjs",
|
|
11
|
+
"./session-mode": "./src/session/mode.mjs",
|
|
12
|
+
"./model": "./src/model/index.mjs",
|
|
13
|
+
"./ops": "./src/ops/index.mjs",
|
|
14
|
+
"./bridge": "./src/bridge/index.mjs",
|
|
15
|
+
"./client": "./src/client/index.mjs",
|
|
16
|
+
"./screenshot": "./src/client/screenshot.mjs",
|
|
17
|
+
"./testing": "./src/testing/index.mjs",
|
|
18
|
+
"./package.json": "./package.json",
|
|
19
|
+
"./store/file-backend": "./src/store/file-backend.mjs"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@capyclaw/plugin-kit": "^0.2.0"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"src/",
|
|
29
|
+
"README.md"
|
|
30
|
+
],
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"scripts": {
|
|
33
|
+
"test": "node --test test/*.test.mjs"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/Maple496/capyclaw.git",
|
|
38
|
+
"directory": "C/packages/capyclaw-document-workbench"
|
|
39
|
+
},
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/Maple496/capyclaw/issues"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/Maple496/capyclaw/tree/main/C/packages/capyclaw-document-workbench#readme"
|
|
44
|
+
}
|