@capyclaw/browser-suite 0.1.2 → 0.2.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +9 -5
- package/composition.lock.json +37 -25
- package/contract/browser-contract.json +484 -25
- package/cordis.patch.yml +3 -9
- package/dsh-suite.json +110 -82
- package/lib/index.mjs +1 -1
- 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/browser-skill-api/README.md +3 -0
- package/node_modules/@capyclaw/browser-skill-api/contract/browser-contract.json +1349 -0
- package/node_modules/@capyclaw/browser-skill-api/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/browser-skill-api/package.json +49 -0
- package/node_modules/@capyclaw/browser-skill-api/plugin.mjs +15 -0
- package/node_modules/@capyclaw/browser-skill-api/skills/browser-api/SKILL.md +85 -0
- package/node_modules/@capyclaw/browser-skill-api/skills/browser-api/references/tool-contract.md +692 -0
- package/node_modules/@capyclaw/browser-skill-browser/README.md +3 -0
- package/node_modules/@capyclaw/browser-skill-browser/contract/browser-contract.json +1349 -0
- package/node_modules/@capyclaw/browser-skill-browser/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/browser-skill-browser/package.json +49 -0
- package/node_modules/@capyclaw/browser-skill-browser/plugin.mjs +15 -0
- package/node_modules/@capyclaw/browser-skill-browser/skills/browser/SKILL.md +27 -0
- package/node_modules/@capyclaw/browser-skill-ops/README.md +3 -0
- package/node_modules/@capyclaw/browser-skill-ops/contract/browser-contract.json +1349 -0
- package/node_modules/@capyclaw/browser-skill-ops/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/browser-skill-ops/package.json +49 -0
- package/node_modules/@capyclaw/browser-skill-ops/plugin.mjs +15 -0
- package/node_modules/@capyclaw/browser-skill-ops/skills/browser-ops/SKILL.md +63 -0
- package/node_modules/@capyclaw/browser-workbench/README.md +89 -0
- package/node_modules/@capyclaw/browser-workbench/contract/browser-contract.json +1349 -0
- package/node_modules/@capyclaw/browser-workbench/demo/form.html +112 -0
- package/node_modules/@capyclaw/browser-workbench/lib/host.mjs +1 -0
- package/node_modules/@capyclaw/browser-workbench/package.json +71 -0
- package/node_modules/@capyclaw/browser-workbench/plugin.mjs +1 -0
- package/node_modules/@capyclaw/browser-workbench/server/constants.mjs +16 -0
- package/node_modules/@capyclaw/browser-workbench/server/contract-snapshots.mjs +81 -0
- package/node_modules/@capyclaw/browser-workbench/server/contract.mjs +24 -0
- package/node_modules/@capyclaw/browser-workbench/server/embedded-host.mjs +247 -0
- package/node_modules/@capyclaw/browser-workbench/server/engine.mjs +2466 -0
- package/node_modules/@capyclaw/browser-workbench/server/governor.mjs +189 -0
- package/node_modules/@capyclaw/browser-workbench/server/http-utils.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/human.mjs +628 -0
- package/node_modules/@capyclaw/browser-workbench/server/infra/http.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/infra/tuning.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/input.mjs +154 -0
- package/node_modules/@capyclaw/browser-workbench/server/login-vault.mjs +109 -0
- package/node_modules/@capyclaw/browser-workbench/server/mcp/handler.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/mcp/instructions.mjs +31 -0
- package/node_modules/@capyclaw/browser-workbench/server/orphans.mjs +163 -0
- package/node_modules/@capyclaw/browser-workbench/server/relay.mjs +198 -0
- package/node_modules/@capyclaw/browser-workbench/server/routes/api.mjs +233 -0
- package/node_modules/@capyclaw/browser-workbench/server/routes/assets.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/routes/mcp.mjs +17 -0
- package/node_modules/@capyclaw/browser-workbench/server/routes/workbench.mjs +33 -0
- package/node_modules/@capyclaw/browser-workbench/server/session-engines.mjs +184 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/SHARED_MANIFEST.json +70 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/asset-service.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/editor-host.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/kit/editor/lease.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/kit/service/api.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/kit/service/http.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/kit/service/mcp-http.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/kit/tools/validate.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/kit/tuning.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/kit/util/fs-lock.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/service-host.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/tool-host.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/shared/tuning.mjs +2 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/contract.mjs +55 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/evaluate.mjs +36 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/index.mjs +26 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/interaction.mjs +215 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/navigation.mjs +35 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/screenshot.mjs +50 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/session.mjs +81 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/snapshot.mjs +30 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/tabs.mjs +35 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/index.mjs +12 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/kernel/define.mjs +5 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/kernel/output.mjs +30 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/kernel/ports.mjs +59 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools/kernel/registry.mjs +17 -0
- package/node_modules/@capyclaw/browser-workbench/server/tools.mjs +3 -0
- package/node_modules/@capyclaw/browser-workbench/server/workbench-framework.mjs +305 -0
- package/node_modules/@capyclaw/browser-workbench/ui/app.js +447 -0
- package/node_modules/@capyclaw/browser-workbench/ui/index.html +46 -0
- package/node_modules/@capyclaw/browser-workbench/ui/style.css +144 -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/portal/README.md +70 -0
- package/node_modules/@capyclaw/portal/lib/index.mjs +387 -0
- package/node_modules/@capyclaw/portal/lib/ledger.mjs +194 -0
- package/node_modules/@capyclaw/portal/lib/portal-agent.ps1 +811 -0
- package/node_modules/@capyclaw/portal/lib/portal-darwin.mjs +183 -0
- package/node_modules/@capyclaw/portal/package.json +40 -0
- package/node_modules/@capyclaw/service-broker/README.md +104 -0
- package/node_modules/@capyclaw/service-broker/cordis.patch.yml +8 -0
- package/node_modules/@capyclaw/service-broker/dsh-suite.json +21 -0
- package/node_modules/@capyclaw/service-broker/lib/control.mjs +193 -0
- package/node_modules/@capyclaw/service-broker/lib/discovery.mjs +109 -0
- package/node_modules/@capyclaw/service-broker/lib/engine.mjs +1236 -0
- package/node_modules/@capyclaw/service-broker/lib/host.mjs +182 -0
- package/node_modules/@capyclaw/service-broker/lib/manifest.mjs +249 -0
- package/node_modules/@capyclaw/service-broker/lib/recovery.mjs +325 -0
- package/node_modules/@capyclaw/service-broker/lib/skills-client.mjs +28 -0
- package/node_modules/@capyclaw/service-broker/lib/spec.mjs +78 -0
- package/node_modules/@capyclaw/service-broker/package.json +65 -0
- package/node_modules/@capyclaw/service-broker/server.mjs +81 -0
- package/node_modules/@capyclaw/service-broker/service.schema.json +62 -0
- package/node_modules/@capyclaw/service-broker/services.json +3 -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 +32 -14
- package/services.json +1 -21
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 版本化文档会话:把协议白名单、状态迁移、持久化、journal、checkpoint、
|
|
3
|
+
* owner 租约组合成稳定的 DocumentSession API。
|
|
4
|
+
*
|
|
5
|
+
* 领域文档放在 documentKey 下;summary/onApplied 由调用方提供。
|
|
6
|
+
*/
|
|
7
|
+
import {
|
|
8
|
+
applyAck, applyPush, applyServer, applyShotRequest, applyShotResult,
|
|
9
|
+
applyState, applyUi, createSessionState, pendingOf,
|
|
10
|
+
} from './state.mjs'
|
|
11
|
+
import {
|
|
12
|
+
claimOwner, isOwnerLive, isShadowOwner, OWNER_TTL, ownerState, ownerStatus, releaseOwner,
|
|
13
|
+
} from './lease.mjs'
|
|
14
|
+
|
|
15
|
+
export * from './state.mjs'
|
|
16
|
+
export * from './sanitize.mjs'
|
|
17
|
+
export * from './watch.mjs'
|
|
18
|
+
export {
|
|
19
|
+
claimOwner, isOwnerLive, isShadowOwner, OWNER_TTL, ownerState, ownerStatus, releaseOwner,
|
|
20
|
+
} from './lease.mjs'
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 未回执批次的默认过期时间:超过它还没人 ack,说明编辑器长期不在线。
|
|
24
|
+
* 过期批次不会被重放(旧命令在新页面上重放 = 文档被“历史操作”砸中)。
|
|
25
|
+
*/
|
|
26
|
+
export const PENDING_TTL = 120
|
|
27
|
+
|
|
28
|
+
export function checkpointName(name) {
|
|
29
|
+
const safe = String(name || '')
|
|
30
|
+
if (!/^[a-zA-Z0-9._-]{1,64}$/.test(safe)) throw new Error('checkpoint 名称必须是 1-64 位字母/数字/._-')
|
|
31
|
+
return safe
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class DocumentSession {
|
|
35
|
+
constructor({
|
|
36
|
+
backend,
|
|
37
|
+
initialDoc = {},
|
|
38
|
+
documentKey = 'document',
|
|
39
|
+
summary = () => ({}),
|
|
40
|
+
onApplied = null,
|
|
41
|
+
checkpointDocument = null,
|
|
42
|
+
stateCompact = true,
|
|
43
|
+
pendingTtl = PENDING_TTL,
|
|
44
|
+
} = {}) {
|
|
45
|
+
if (!backend) throw new Error('DocumentSession 需要 backend')
|
|
46
|
+
this.backend = backend
|
|
47
|
+
this.documentKey = documentKey
|
|
48
|
+
this.initialDoc = initialDoc
|
|
49
|
+
this.summary = summary
|
|
50
|
+
this.onApplied = onApplied
|
|
51
|
+
this.checkpointDocument = checkpointDocument
|
|
52
|
+
this.stateCompact = stateCompact !== false
|
|
53
|
+
this.pendingTtl = Number(pendingTtl) || PENDING_TTL
|
|
54
|
+
this.dir = backend.dir || ''
|
|
55
|
+
this.file = backend.file || ''
|
|
56
|
+
this.journalFile = backend.journalFile || ''
|
|
57
|
+
this.checkpointDir = backend.checkpointDir || ''
|
|
58
|
+
this._tail = Promise.resolve()
|
|
59
|
+
this.doc = this._load()
|
|
60
|
+
this._waiters = new Set()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 串行队列:前一个任务失败不会阻断后续任务。 */
|
|
64
|
+
enqueue(task) {
|
|
65
|
+
const run = this._tail.then(task, task)
|
|
66
|
+
this._tail = run.then(() => undefined, () => undefined)
|
|
67
|
+
return run
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* ---- 变更订阅:长轮询 / 工具等待即时唤醒(轮询兜底仍在) ---- */
|
|
71
|
+
|
|
72
|
+
/** 订阅会话变更;返回退订函数。notify 在每次状态迁移后同步触发。 */
|
|
73
|
+
subscribe(fn) {
|
|
74
|
+
this._waiters.add(fn)
|
|
75
|
+
return () => { this._waiters.delete(fn) }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
_notify() {
|
|
79
|
+
for (const fn of [...this._waiters]) {
|
|
80
|
+
try { fn() } catch { /* 订阅方异常不阻塞状态迁移 */ }
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** 等下一次变更或超时(事件先到即返回):把「轮询粒度」从等待延迟里消掉。 */
|
|
85
|
+
waitForChange(timeoutMs = 100) {
|
|
86
|
+
return new Promise((resolve) => {
|
|
87
|
+
let done = false
|
|
88
|
+
const off = this.subscribe(() => {
|
|
89
|
+
if (done) return
|
|
90
|
+
done = true
|
|
91
|
+
clearTimeout(timer)
|
|
92
|
+
off()
|
|
93
|
+
resolve()
|
|
94
|
+
})
|
|
95
|
+
const timer = setTimeout(() => {
|
|
96
|
+
if (done) return
|
|
97
|
+
done = true
|
|
98
|
+
off()
|
|
99
|
+
resolve()
|
|
100
|
+
}, Math.max(0, Number(timeoutMs) || 0))
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
_journal(event) {
|
|
105
|
+
try { this.backend.appendJournal?.(event) } catch { /* journal 失败不阻塞主状态 */ }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
_journalTail(limit = 8) {
|
|
109
|
+
try { return this.backend.journalTail?.(limit) || [] } catch { return [] }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
_load() {
|
|
113
|
+
let state = null
|
|
114
|
+
try { state = this.backend.readState() } catch (error) {
|
|
115
|
+
this.backend.lastStateError = { code: 'STATE_IO', message: error.message }
|
|
116
|
+
}
|
|
117
|
+
if (state) return createSessionState({ ...this.initialDoc, ...state })
|
|
118
|
+
|
|
119
|
+
/* state 损坏时尝试从最新 checkpoint 恢复,而不是静默清空文档。 */
|
|
120
|
+
if (this.backend.lastStateError?.code === 'STATE_CORRUPT'
|
|
121
|
+
&& typeof this.backend.listCheckpoints === 'function') {
|
|
122
|
+
try {
|
|
123
|
+
const latest = this.backend.listCheckpoints()[0]
|
|
124
|
+
if (latest) {
|
|
125
|
+
const payload = this.backend.readCheckpoint(latest.name)
|
|
126
|
+
const value = payload?.[this.documentKey]
|
|
127
|
+
if (payload && value) {
|
|
128
|
+
const doc = createSessionState(this.initialDoc)
|
|
129
|
+
doc[this.documentKey] = value
|
|
130
|
+
doc.title = payload.title || doc.title || ''
|
|
131
|
+
doc.seq = payload.seq | 0
|
|
132
|
+
doc.applied_seq = payload.seq | 0
|
|
133
|
+
doc.state_seq = payload.seq | 0
|
|
134
|
+
console.error(`[document-workbench] state 损坏,已从 checkpoint ${latest.name} 恢复(seq=${payload.seq})`)
|
|
135
|
+
return doc
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
} catch (error) {
|
|
139
|
+
console.error('[document-workbench] checkpoint 恢复失败:', error.message)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return createSessionState(this.initialDoc)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
_save() {
|
|
146
|
+
this.backend.writeState(this.doc)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
get() { return this.doc }
|
|
150
|
+
|
|
151
|
+
getDocument() { return this.doc[this.documentKey] ?? null }
|
|
152
|
+
|
|
153
|
+
push(cmds, title) {
|
|
154
|
+
applyPush(this.doc, cmds, title)
|
|
155
|
+
this._save()
|
|
156
|
+
this._journal({ type: 'push', seq: this.doc.seq, title, cmdCount: cmds.length, status: 'pending' })
|
|
157
|
+
this._notify()
|
|
158
|
+
return this.doc
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* 服务端权威批次:push → 逐条 apply → view 命令交给 UI → applyServer。
|
|
163
|
+
* 整批在串行队列内执行,并发 push 不会交叉改写 seq/document。
|
|
164
|
+
*/
|
|
165
|
+
runBatch({ cmds, title, apply, isViewOp = () => false }) {
|
|
166
|
+
return this.enqueue(async () => {
|
|
167
|
+
const doc = this.push(cmds, title)
|
|
168
|
+
const seq = doc.seq
|
|
169
|
+
let applied = 0
|
|
170
|
+
let error = ''
|
|
171
|
+
const viewCmds = []
|
|
172
|
+
for (const cmd of cmds) {
|
|
173
|
+
if (isViewOp(cmd)) {
|
|
174
|
+
viewCmds.push(cmd)
|
|
175
|
+
applied++
|
|
176
|
+
continue
|
|
177
|
+
}
|
|
178
|
+
try {
|
|
179
|
+
await apply(cmd)
|
|
180
|
+
applied++
|
|
181
|
+
} catch (caught) {
|
|
182
|
+
error = String((caught && caught.message) || caught)
|
|
183
|
+
break
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (viewCmds.length) this.uiCommand(viewCmds)
|
|
187
|
+
this.applyServer(seq, applied, error)
|
|
188
|
+
return this.get()
|
|
189
|
+
})
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
applyServer(seq, applied, error) {
|
|
193
|
+
applyServer(this.doc, seq, applied, error, {
|
|
194
|
+
onApplied: this.onApplied,
|
|
195
|
+
stateCompact: this.stateCompact,
|
|
196
|
+
})
|
|
197
|
+
this._save()
|
|
198
|
+
this._journal({ type: 'applied', seq, applied, error: error || '' })
|
|
199
|
+
this._notify()
|
|
200
|
+
return this.doc
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
uiCommand(cmds) {
|
|
204
|
+
applyUi(this.doc, cmds)
|
|
205
|
+
this._save()
|
|
206
|
+
this._journal({ type: 'ui', uiSeq: this.doc.ui_seq, cmdCount: cmds.length })
|
|
207
|
+
this._notify()
|
|
208
|
+
return this.doc
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
ack(seq, applied, error, epoch = null) {
|
|
212
|
+
if ((this.doc.seq | 0) !== (seq | 0)) return this.doc
|
|
213
|
+
/* fencing:换了 owner 之后,旧 owner 的回执不能再改状态。 */
|
|
214
|
+
const currentEpoch = (this.doc.owner && this.doc.owner.epoch) | 0
|
|
215
|
+
if (epoch != null && (epoch | 0) !== currentEpoch) return this.doc
|
|
216
|
+
applyAck(this.doc, seq, applied, error)
|
|
217
|
+
this._save()
|
|
218
|
+
this._notify()
|
|
219
|
+
return this.doc
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
state(value, seq, meta = null) {
|
|
223
|
+
applyState(this.doc, value, seq, { documentKey: this.documentKey })
|
|
224
|
+
this._save()
|
|
225
|
+
/* UI 写路径留痕:镜像回推也是一次写入,必须进 journal(与 push/applied/ui
|
|
226
|
+
* 同一本账)。纯审计事件,不改状态迁移——旧 seq 镜像被 applyState 丢弃时
|
|
227
|
+
* 也记一条,便于诊断「为什么镜像没生效」。
|
|
228
|
+
* E:meta 可选携带 clientId/origin,让账本能区分「谁在什么时候镜像了什么」。 */
|
|
229
|
+
const m = meta && typeof meta === 'object' ? meta : {}
|
|
230
|
+
this._journal({
|
|
231
|
+
type: 'state',
|
|
232
|
+
seq: this.doc.seq | 0,
|
|
233
|
+
stateSeq: this.doc.state_seq | 0,
|
|
234
|
+
...(m.clientId ? { clientId: String(m.clientId) } : {}),
|
|
235
|
+
...(m.origin ? { origin: String(m.origin) } : {}),
|
|
236
|
+
})
|
|
237
|
+
this._notify()
|
|
238
|
+
return this.doc
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
pending() {
|
|
242
|
+
return pendingOf(this.doc)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
checkpoint(name, meta = {}) {
|
|
246
|
+
const safe = checkpointName(name)
|
|
247
|
+
const pending = (this.doc.seq | 0) > (this.doc.applied_seq | 0)
|
|
248
|
+
const summary = this.summary(this.doc) || {}
|
|
249
|
+
const payload = {
|
|
250
|
+
name: safe,
|
|
251
|
+
seq: this.doc.seq | 0,
|
|
252
|
+
appliedSeq: this.doc.applied_seq | 0,
|
|
253
|
+
pending,
|
|
254
|
+
...summary,
|
|
255
|
+
title: this.doc.title || summary.title || '',
|
|
256
|
+
[this.documentKey]: this.doc[this.documentKey]
|
|
257
|
+
?? (this.checkpointDocument ? this.checkpointDocument(this.doc) : null),
|
|
258
|
+
meta: meta && typeof meta === 'object' ? meta : {},
|
|
259
|
+
createdAt: new Date().toISOString(),
|
|
260
|
+
}
|
|
261
|
+
this.backend.writeCheckpoint(payload.name, payload)
|
|
262
|
+
this._journal({ type: 'checkpoint', name: payload.name, seq: payload.seq, pending: payload.pending })
|
|
263
|
+
const { [this.documentKey]: _document, ...view } = payload
|
|
264
|
+
return view
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
listCheckpoints() {
|
|
268
|
+
return this.backend.listCheckpoints?.() || []
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
readCheckpoint(name) {
|
|
272
|
+
const safe = checkpointName(name)
|
|
273
|
+
const payload = this.backend.readCheckpoint?.(safe)
|
|
274
|
+
if (!payload || !(this.documentKey in payload)) {
|
|
275
|
+
throw new Error('checkpoint 内容损坏: ' + safe)
|
|
276
|
+
}
|
|
277
|
+
return payload
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
taskStatus() {
|
|
281
|
+
const pending = this.pending()
|
|
282
|
+
const checkpoints = this.listCheckpoints()
|
|
283
|
+
const summary = this.summary(this.doc) || {}
|
|
284
|
+
const now = Date.now() / 1000
|
|
285
|
+
return {
|
|
286
|
+
seq: this.doc.seq | 0,
|
|
287
|
+
appliedSeq: this.doc.applied_seq | 0,
|
|
288
|
+
stateSeq: this.doc.state_seq | 0,
|
|
289
|
+
...summary,
|
|
290
|
+
title: this.doc.title || summary.title || '未命名',
|
|
291
|
+
pending: !!pending,
|
|
292
|
+
pendingCmds: pending ? pending.cmds.length : 0,
|
|
293
|
+
pendingAge: this.pendingAge(now),
|
|
294
|
+
editor: ownerStatus(this.doc, now, OWNER_TTL),
|
|
295
|
+
editorState: this.editorState(now),
|
|
296
|
+
lastError: this.doc.error || '',
|
|
297
|
+
lastCheckpoint: checkpoints[0] || null,
|
|
298
|
+
checkpoints: checkpoints.length,
|
|
299
|
+
journal: this._journalTail(8),
|
|
300
|
+
updated: this.doc.updated || 0,
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** 截图请求:opts 是渲染选项(如 {indices:[2], width:1200}),随请求一起给编辑器。 */
|
|
305
|
+
shotRequest(opts = null) {
|
|
306
|
+
applyShotRequest(this.doc, opts)
|
|
307
|
+
this._save()
|
|
308
|
+
this._notify()
|
|
309
|
+
return this.doc
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
shotResult(req, data) {
|
|
313
|
+
applyShotResult(this.doc, req, data)
|
|
314
|
+
this._save()
|
|
315
|
+
this._notify()
|
|
316
|
+
return this.doc
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
claim(id, force = false, meta = null) {
|
|
320
|
+
const result = claimOwner(this.doc, id, force, meta)
|
|
321
|
+
if (result.changed) {
|
|
322
|
+
/* 新 owner 接管时先作废旧批次:46 小时前排队、无人回执的命令不能被重放。 */
|
|
323
|
+
const expired = this.expirePending()
|
|
324
|
+
this._save()
|
|
325
|
+
this._notify()
|
|
326
|
+
return { ok: result.ok, owner: result.owner, epoch: result.epoch | 0, ...(expired ? { expired } : {}) }
|
|
327
|
+
}
|
|
328
|
+
return { ok: result.ok, owner: result.owner, epoch: result.epoch | 0 }
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* 未回执批次过期:超过 pendingTtl 还没 ack,说明编辑器长期不在线。
|
|
333
|
+
* 过期批次直接作废(不再重放),并在 error 里留下可读原因。
|
|
334
|
+
*/
|
|
335
|
+
expirePending(now = Date.now() / 1000) {
|
|
336
|
+
const pending = pendingOf(this.doc)
|
|
337
|
+
if (!pending) return null
|
|
338
|
+
const since = this.doc.pending_since || this.doc.updated || 0
|
|
339
|
+
if (!since || now - since <= this.pendingTtl) return null
|
|
340
|
+
const ageS = Math.round(now - since)
|
|
341
|
+
this.doc.cmds = []
|
|
342
|
+
this.doc.applied = 0
|
|
343
|
+
this.doc.applied_seq = this.doc.seq | 0
|
|
344
|
+
this.doc.error = `批次 seq ${pending.seq} 已过期(${ageS}s 未回执),已丢弃`
|
|
345
|
+
this.doc.pending_since = 0
|
|
346
|
+
this.doc.updated = now
|
|
347
|
+
this._journal({ type: 'pending-expired', seq: pending.seq, ageS })
|
|
348
|
+
return { seq: pending.seq, ageS }
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** 未回执批次的年龄(秒);没有 pending 时返回 0。 */
|
|
352
|
+
pendingAge(now = Date.now() / 1000) {
|
|
353
|
+
const pending = pendingOf(this.doc)
|
|
354
|
+
if (!pending) return 0
|
|
355
|
+
const since = this.doc.pending_since || this.doc.updated || 0
|
|
356
|
+
return since ? Math.max(0, Math.round(now - since)) : 0
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** 编辑器租约状态机:unclaimed / live / stale(跨 suite 同一套语义)。 */
|
|
360
|
+
editorState(now = Date.now() / 1000) {
|
|
361
|
+
return ownerState(this.doc, now, OWNER_TTL)
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
release(id) {
|
|
365
|
+
if (releaseOwner(this.doc, id)) {
|
|
366
|
+
this._save()
|
|
367
|
+
this._notify()
|
|
368
|
+
}
|
|
369
|
+
return { ok: true }
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* 崩溃恢复:把未完成批次交给 apply 重放,然后回执。
|
|
374
|
+
* 调用方应放在 enqueue 内,保证恢复期间的新 push 排队。
|
|
375
|
+
*/
|
|
376
|
+
async recover({ apply, isViewOp = () => false } = {}) {
|
|
377
|
+
const item = this.pending()
|
|
378
|
+
if (!item) return { recovered: 0, seq: 0, error: '' }
|
|
379
|
+
let recovered = 0
|
|
380
|
+
let error = ''
|
|
381
|
+
for (const cmd of item.cmds || []) {
|
|
382
|
+
try {
|
|
383
|
+
if (isViewOp(cmd)) this.uiCommand([cmd])
|
|
384
|
+
else await apply(cmd)
|
|
385
|
+
recovered++
|
|
386
|
+
} catch (caught) {
|
|
387
|
+
error = String((caught && caught.message) || caught)
|
|
388
|
+
break
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
this.applyServer(item.seq, recovered, error)
|
|
392
|
+
return { seq: item.seq, recovered, error }
|
|
393
|
+
}
|
|
394
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文档 owner 租约:心跳由客户端定期 claim 续约,默认 TTL 10s。
|
|
3
|
+
*
|
|
4
|
+
* 标准语义(所有桥共用):
|
|
5
|
+
* - epoch:每次所有权换人 +1;回执可带 epoch,旧 owner 的回执被丢弃(fencing)。
|
|
6
|
+
* - state:unclaimed / live / stale,status 直接给人看,不要求调用方自己算 age。
|
|
7
|
+
* - stale 的 owner 允许新页面直接抢占,不需要等旧页面 release。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const OWNER_TTL = 10
|
|
11
|
+
|
|
12
|
+
export function nowSeconds() {
|
|
13
|
+
return Date.now() / 1000
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** 当前 owner 是否还活着(没有 owner / 超过 TTL 都不算)。 */
|
|
17
|
+
export function isOwnerLive(doc, now = nowSeconds(), ttl = OWNER_TTL) {
|
|
18
|
+
const owner = doc && doc.owner
|
|
19
|
+
return !!(owner && owner.id && now - (owner.ts || 0) <= ttl)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** 当前 owner 是否是影子显示器(兜底无头渲染),而非真实用户窗口。
|
|
23
|
+
* 影子礼貌 claim、不写单例键;真实窗口 force 抢占后影子经 'lost' 让位。 */
|
|
24
|
+
export function isShadowOwner(doc) {
|
|
25
|
+
const owner = doc && doc.owner
|
|
26
|
+
return !!(owner && owner.meta && owner.meta.shadow === true)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 编辑器租约状态机:unclaimed(从未连)→ live(心跳有效)→ stale(心跳过期)。
|
|
31
|
+
* 桥的 healthz / status 直接暴露它,调用方不必自己数 applied_seq 猜“桥断没断”。
|
|
32
|
+
*/
|
|
33
|
+
export function ownerState(doc, now = nowSeconds(), ttl = OWNER_TTL) {
|
|
34
|
+
const owner = doc && doc.owner
|
|
35
|
+
if (!owner || !owner.id) return 'unclaimed'
|
|
36
|
+
return now - (owner.ts || 0) <= ttl ? 'live' : 'stale'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function claimOwner(doc, id, force = false, meta = null, now = nowSeconds(), ttl = OWNER_TTL) {
|
|
40
|
+
const current = doc.owner
|
|
41
|
+
const incomingMeta = meta && typeof meta === 'object' && !Array.isArray(meta) && Object.keys(meta).length
|
|
42
|
+
? meta
|
|
43
|
+
: null
|
|
44
|
+
const currentMeta = current && current.meta && typeof current.meta === 'object' ? current.meta : null
|
|
45
|
+
const stale = !current || now - (current.ts || 0) > ttl
|
|
46
|
+
|
|
47
|
+
/* 真实窗口 > 影子显示器:影子只是兜底无头渲染,真实用户窗口一旦回来就应拿回所有权。
|
|
48
|
+
* 否则「真实窗口 firstClaim 耗尽 → 睡眠超 TTL 被影子礼貌抢占 → 醒来只剩礼貌 claim
|
|
49
|
+
* 永远被活影子拒绝 → 永久待命、本地编辑不回推」。这里把「活影子 + 上报能力的真实窗口」
|
|
50
|
+
* 的礼貌 claim 视同 force:换人 epoch+1,影子经 fencing/'lost' 让位。
|
|
51
|
+
* 仅对「上报 meta 且非 shadow」的来者生效——旧页面(无 meta)与影子互抢不触发。 */
|
|
52
|
+
const currentIsShadow = !!(currentMeta && currentMeta.shadow === true)
|
|
53
|
+
const incomingIsReal = !!(incomingMeta && incomingMeta.shadow !== true)
|
|
54
|
+
const realReclaimsShadow = !force && !!current && current.id !== id && !stale && currentIsShadow && incomingIsReal
|
|
55
|
+
|
|
56
|
+
/* 旧页面(不报 meta/能力)不能用 force 抢走已上报能力的页面;
|
|
57
|
+
* 否则多个残留 tab 会轮流覆盖新编辑器的 state。 */
|
|
58
|
+
if (force && current && current.id !== id && currentMeta && !incomingMeta && !stale) {
|
|
59
|
+
return { ok: false, owner: current.id, changed: false, epoch: current.epoch | 0 }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (force || realReclaimsShadow || !current || !current.id || current.id === id || stale) {
|
|
63
|
+
const sameOwner = !!(current && current.id === id)
|
|
64
|
+
/* 换人(或被 stale 抢占)→ epoch +1;同一人续约 epoch 不变。 */
|
|
65
|
+
const epoch = (current && current.epoch ? current.epoch | 0 : 0) + (sameOwner ? 0 : 1)
|
|
66
|
+
const next = { id, ts: now, epoch }
|
|
67
|
+
/* 编辑器能力/版本随 claim 上报:工具可以据此判断“旧页面不支持某 op”。
|
|
68
|
+
* 心跳 worker 只发 {id} 不带 meta,同人续约时必须保留已上报的能力。 */
|
|
69
|
+
const nextMeta = incomingMeta || (sameOwner ? current.meta : null)
|
|
70
|
+
if (nextMeta && typeof nextMeta === 'object' && !Array.isArray(nextMeta)) next.meta = nextMeta
|
|
71
|
+
doc.owner = next
|
|
72
|
+
return { ok: true, owner: id, changed: true, epoch }
|
|
73
|
+
}
|
|
74
|
+
return { ok: false, owner: current.id, changed: false, epoch: current.epoch | 0 }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function releaseOwner(doc, id) {
|
|
78
|
+
if (doc.owner && doc.owner.id === id) {
|
|
79
|
+
delete doc.owner
|
|
80
|
+
return true
|
|
81
|
+
}
|
|
82
|
+
return false
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* owner 状态投影。保留 id/age/meta 的旧字段,叠加 epoch/state/live:
|
|
87
|
+
* - state:unclaimed / live / stale
|
|
88
|
+
* - live:布尔便捷位(等价 state === 'live')
|
|
89
|
+
* - ttl:本桥的租约时长,便于调用方判断“多久没心跳算掉线”
|
|
90
|
+
*/
|
|
91
|
+
export function ownerStatus(doc, now = nowSeconds(), ttl = OWNER_TTL) {
|
|
92
|
+
const owner = doc && doc.owner
|
|
93
|
+
if (!owner || !owner.id) return null
|
|
94
|
+
const age = Math.round((now - (owner.ts || 0)) * 100) / 100
|
|
95
|
+
return {
|
|
96
|
+
id: owner.id,
|
|
97
|
+
age,
|
|
98
|
+
epoch: owner.epoch | 0,
|
|
99
|
+
live: age <= ttl,
|
|
100
|
+
state: age <= ttl ? 'live' : 'stale',
|
|
101
|
+
ttl,
|
|
102
|
+
shadow: !!(owner.meta && owner.meta.shadow === true),
|
|
103
|
+
...(owner.meta ? { meta: owner.meta } : {}),
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 会话模式守卫(F 单一真源):一个会话只有一次认领工作台种类的机会,认领后终生固化。
|
|
3
|
+
*
|
|
4
|
+
* 存储真源在 @capyclaw/work-store 的 claimSessionMode/getSessionMode(works.db 会话级
|
|
5
|
+
* 记录,tx 原子)。本模块只做「接线」:把存储能力包成各 bridge 共用的守卫——
|
|
6
|
+
* - 工具写闸:非 read 工具执行前认领本种类,异种类硬拒;
|
|
7
|
+
* - 编辑器认领闸:/claim 前认领本种类。
|
|
8
|
+
* 读不受限;无会话身份(standalone default)或无作品底座时跳过(不启用)。
|
|
9
|
+
*
|
|
10
|
+
* 三个 bridge 共用本模块,各自只传自己的 kind 与底座解析器,不为某个特例单开接口。
|
|
11
|
+
*/
|
|
12
|
+
import { currentSession } from './context.mjs'
|
|
13
|
+
|
|
14
|
+
/** 把底座懒解析器包成守卫用的 registry:底座缺席 → skipped(不启用)。 */
|
|
15
|
+
export function createSessionModeRegistry(getWorkStore) {
|
|
16
|
+
return {
|
|
17
|
+
claim(sessionId, kind, claimedBy = '') {
|
|
18
|
+
const ws = typeof getWorkStore === 'function' ? getWorkStore() : getWorkStore
|
|
19
|
+
if (!ws || typeof ws.claimSessionMode !== 'function') return { ok: true, skipped: true }
|
|
20
|
+
return ws.claimSessionMode(sessionId, kind, claimedBy)
|
|
21
|
+
},
|
|
22
|
+
get(sessionId) {
|
|
23
|
+
const ws = typeof getWorkStore === 'function' ? getWorkStore() : getWorkStore
|
|
24
|
+
if (!ws || typeof ws.getSessionMode !== 'function') return null
|
|
25
|
+
return ws.getSessionMode(sessionId)
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 硬拒时的统一文案:指明已固化种类 + 请新开会话。 */
|
|
31
|
+
export function sessionModeMessage(result) {
|
|
32
|
+
return `本会话已固化为「${result.lockedTo}」工作台,不能在这里写入/认领「${result.kind}」。`
|
|
33
|
+
+ `要使用 ${result.kind},请新开一个会话。`
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 认领/校验(不抛):registry 缺席或无会话身份 → {ok:true,skipped:true}。 */
|
|
37
|
+
export function claimSessionMode(sessionId, kind, registry) {
|
|
38
|
+
if (!registry || typeof registry.claim !== 'function') return { ok: true, skipped: true }
|
|
39
|
+
const sid = String(sessionId || '')
|
|
40
|
+
if (!sid) return { ok: true, skipped: true }
|
|
41
|
+
return registry.claim(sid, kind)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 认领/校验(抛):异种类硬拒,错误带 code=SESSION_MODE_LOCKED 与 lockedTo。 */
|
|
45
|
+
export function assertSessionMode(sessionId, kind, registry) {
|
|
46
|
+
const r = claimSessionMode(sessionId, kind, registry)
|
|
47
|
+
if (!r.ok) {
|
|
48
|
+
const err = new Error(sessionModeMessage(r))
|
|
49
|
+
err.code = 'SESSION_MODE_LOCKED'
|
|
50
|
+
err.lockedTo = r.lockedTo
|
|
51
|
+
throw err
|
|
52
|
+
}
|
|
53
|
+
return r
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 工具写闸:把非 read 工具包一层,执行前在「调用者会话」上下文里认领本种类。
|
|
58
|
+
*
|
|
59
|
+
* 必须在 bindToolsToCallerSession **之前**调用:那样会话缝入包在最外层,本守卫
|
|
60
|
+
* 跑在 ALS 上下文里,currentSession() 才是调用者会话。read 工具不包(读不受限)。
|
|
61
|
+
* isWrite 缺省按 TOOL_META.kind !== 'read' 判定;registry 缺席则原样返回。
|
|
62
|
+
*/
|
|
63
|
+
export function bindToolsToSessionMode(registry, { kind, modeRegistry, isWrite }) {
|
|
64
|
+
const impls = registry && registry.TOOL_IMPL
|
|
65
|
+
const meta = (registry && registry.TOOL_META) || {}
|
|
66
|
+
if (!impls || !modeRegistry) return registry
|
|
67
|
+
const write = typeof isWrite === 'function' ? isWrite : (name) => (meta[name] && meta[name].kind) !== 'read'
|
|
68
|
+
for (const name of Object.keys(impls)) {
|
|
69
|
+
const impl = impls[name]
|
|
70
|
+
if (typeof impl !== 'function' || impl.__modeBound) continue
|
|
71
|
+
if (!write(name, meta[name])) continue
|
|
72
|
+
const bound = async (args, exec) => {
|
|
73
|
+
assertSessionMode(currentSession(), kind, modeRegistry)
|
|
74
|
+
return impl(args, exec)
|
|
75
|
+
}
|
|
76
|
+
bound.__modeBound = true
|
|
77
|
+
impls[name] = bound
|
|
78
|
+
}
|
|
79
|
+
return registry
|
|
80
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/** 桥协议白名单:畸形请求一律返回 null → HTTP 400。 */
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_LIMITS = Object.freeze({
|
|
4
|
+
maxCmds: 100,
|
|
5
|
+
maxTotal: 8 * 1024 * 1024,
|
|
6
|
+
maxShot: 4 * 1024 * 1024,
|
|
7
|
+
maxTitle: 120,
|
|
8
|
+
maxError: 2000,
|
|
9
|
+
maxId: 64,
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
const isInt = (v) => typeof v === 'number' && Number.isInteger(v)
|
|
13
|
+
const isCount = (v) => isInt(v) && v >= 0
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 生成一套通用桥请求校验器。documentKey 决定 /state 请求里领域文档的字段名:
|
|
17
|
+
* PPT 用 deck,Canvas 用 document/doc。
|
|
18
|
+
*/
|
|
19
|
+
export function createSessionSanitizers({
|
|
20
|
+
documentKey = 'document',
|
|
21
|
+
maxCmds = DEFAULT_LIMITS.maxCmds,
|
|
22
|
+
maxTotal = DEFAULT_LIMITS.maxTotal,
|
|
23
|
+
maxShot = DEFAULT_LIMITS.maxShot,
|
|
24
|
+
maxTitle = DEFAULT_LIMITS.maxTitle,
|
|
25
|
+
maxError = DEFAULT_LIMITS.maxError,
|
|
26
|
+
maxId = DEFAULT_LIMITS.maxId,
|
|
27
|
+
/* 全量镜像(/state)天然比单队指令大:缺省与 maxTotal 同口径,宿主可按需放宽。 */
|
|
28
|
+
maxState = maxTotal,
|
|
29
|
+
} = {}) {
|
|
30
|
+
function sanitizePush(body) {
|
|
31
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) return null
|
|
32
|
+
const cmds = body.cmds
|
|
33
|
+
if (!Array.isArray(cmds) || cmds.length > maxCmds) return null
|
|
34
|
+
let total = 0
|
|
35
|
+
for (const c of cmds) {
|
|
36
|
+
if (!c || typeof c !== 'object' || Array.isArray(c)) return null
|
|
37
|
+
total += JSON.stringify(c).length
|
|
38
|
+
if (total > maxTotal) return null
|
|
39
|
+
}
|
|
40
|
+
const title = body.title
|
|
41
|
+
if (title != null && (typeof title !== 'string' || title.length > maxTitle)) return null
|
|
42
|
+
if (!cmds.length && !title) return null
|
|
43
|
+
return { cmds, title: title || '' }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function sanitizeAck(body) {
|
|
47
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) return null
|
|
48
|
+
const out = {}
|
|
49
|
+
for (const field of ['seq', 'applied']) {
|
|
50
|
+
if (!isCount(body[field])) return null
|
|
51
|
+
out[field] = body[field]
|
|
52
|
+
}
|
|
53
|
+
const error = body.error
|
|
54
|
+
if (error != null && (typeof error !== 'string' || error.length > maxError)) return null
|
|
55
|
+
out.error = error || ''
|
|
56
|
+
/* epoch 可选:新编辑器回执带 epoch,旧 owner 的回执会被 fencing 丢弃。 */
|
|
57
|
+
if (body.epoch != null) {
|
|
58
|
+
if (!isCount(body.epoch)) return null
|
|
59
|
+
out.epoch = body.epoch
|
|
60
|
+
}
|
|
61
|
+
return out
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function sanitizeState(body) {
|
|
65
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) return null
|
|
66
|
+
const value = body[documentKey]
|
|
67
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null
|
|
68
|
+
if (JSON.stringify(value).length > maxState) return null
|
|
69
|
+
const seq = body.seq
|
|
70
|
+
if (seq != null && !isCount(seq)) return null
|
|
71
|
+
/* E:可选携带客户端身份与会话声明——供 journal 留痕与 validateState 校验。
|
|
72
|
+
* 旧客户端不带这两个字段也完全合法(向后兼容)。 */
|
|
73
|
+
const clientId = body.clientId
|
|
74
|
+
if (clientId != null && (typeof clientId !== 'string' || clientId.length > maxId)) return null
|
|
75
|
+
const sessionId = body.sessionId
|
|
76
|
+
if (sessionId != null && (typeof sessionId !== 'string' || sessionId.length > 128)) return null
|
|
77
|
+
return { value, seq: seq ?? null, clientId: clientId || '', sessionId: sessionId || '' }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function sanitizeShotResult(body) {
|
|
81
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) return null
|
|
82
|
+
if (!isCount(body.req)) return null
|
|
83
|
+
const data = body.data
|
|
84
|
+
if (typeof data !== 'string' || data.length > maxShot) return null
|
|
85
|
+
if (data && !data.startsWith('data:image/')) return null
|
|
86
|
+
return { req: body.req, data }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function sanitizeClaim(body) {
|
|
90
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) return null
|
|
91
|
+
const id = body.id
|
|
92
|
+
if (typeof id !== 'string' || id.length < 1 || id.length > maxId) return null
|
|
93
|
+
let meta = null
|
|
94
|
+
if (body.meta != null) {
|
|
95
|
+
if (typeof body.meta !== 'object' || Array.isArray(body.meta)) return null
|
|
96
|
+
try {
|
|
97
|
+
if (JSON.stringify(body.meta).length > 4096) return null
|
|
98
|
+
} catch {
|
|
99
|
+
return null
|
|
100
|
+
}
|
|
101
|
+
meta = body.meta
|
|
102
|
+
}
|
|
103
|
+
return { id, force: body.force === true, ...(meta ? { meta } : {}) }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return { sanitizePush, sanitizeAck, sanitizeState, sanitizeShotResult, sanitizeClaim }
|
|
107
|
+
}
|