@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
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 编辑计划:定位器 + 补丁 → 规范化 op 列表(id/path 都已解析)。
|
|
3
|
+
*
|
|
4
|
+
* 分层原则:
|
|
5
|
+
* - 本模块只产出「要改哪个节点、改什么」,不假设引擎命令名;
|
|
6
|
+
* - 插件可以拿 plan 去映射自己的 exec 命令(setValue / updateById / patchElement…),
|
|
7
|
+
* 也可以直接用 applyPlan 做纯树改写(工具侧无引擎也能跑,便于测试)。
|
|
8
|
+
*/
|
|
9
|
+
import { locate } from './locate.mjs'
|
|
10
|
+
|
|
11
|
+
const isObj = (value) => !!value && typeof value === 'object' && !Array.isArray(value)
|
|
12
|
+
|
|
13
|
+
function parsePath(path) {
|
|
14
|
+
const m = /^p(\d+)\/n(\d+)((?:\/c\d+)*)$/.exec(String(path || ''))
|
|
15
|
+
if (!m) return null
|
|
16
|
+
const children = (m[3] || '').split('/').filter(Boolean).map((seg) => Number(seg.slice(1)))
|
|
17
|
+
return { page: Number(m[1]), node: Number(m[2]), children }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function targetOf(manifest, locator) {
|
|
21
|
+
const hit = locate(manifest, locator)
|
|
22
|
+
return { id: hit.id, path: hit.path, page: hit.page, index: hit.index, role: hit.role, type: hit.type }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {object} manifest buildManifest 的结果
|
|
27
|
+
* @param {Array<{
|
|
28
|
+
* op?: 'update'|'remove'|'move'|'insert',
|
|
29
|
+
* locate?: object|string,
|
|
30
|
+
* patch?: object,
|
|
31
|
+
* page?: number,
|
|
32
|
+
* index?: number,
|
|
33
|
+
* node?: object,
|
|
34
|
+
* }>} edits
|
|
35
|
+
*/
|
|
36
|
+
export function planEdit(manifest, edits) {
|
|
37
|
+
const list = Array.isArray(edits) ? edits : [edits]
|
|
38
|
+
return list.map((edit, i) => {
|
|
39
|
+
if (!isObj(edit)) throw new Error(`第 ${i} 条编辑不是对象`)
|
|
40
|
+
const op = edit.op || 'update'
|
|
41
|
+
if (op === 'insert') {
|
|
42
|
+
if (!Number.isInteger(edit.page)) throw new Error(`第 ${i} 条 insert 缺少 page`)
|
|
43
|
+
return { op, page: edit.page, index: Number.isInteger(edit.index) ? edit.index : null, node: edit.node || {} }
|
|
44
|
+
}
|
|
45
|
+
const target = targetOf(manifest, edit.locate ?? edit.target ?? edit.id)
|
|
46
|
+
if (op === 'update') {
|
|
47
|
+
if (!isObj(edit.patch) || !Object.keys(edit.patch).length) throw new Error(`第 ${i} 条 update 缺少 patch`)
|
|
48
|
+
return { op, target, patch: edit.patch }
|
|
49
|
+
}
|
|
50
|
+
if (op === 'remove') return { op, target }
|
|
51
|
+
if (op === 'move') {
|
|
52
|
+
if (!Number.isInteger(edit.page)) throw new Error(`第 ${i} 条 move 缺少目标 page`)
|
|
53
|
+
return { op, target, page: edit.page, index: Number.isInteger(edit.index) ? edit.index : null }
|
|
54
|
+
}
|
|
55
|
+
throw new Error(`第 ${i} 条编辑的 op 不支持:${op}`)
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function listAt(doc, schema, path) {
|
|
60
|
+
const parsed = parsePath(path)
|
|
61
|
+
if (!parsed) return null
|
|
62
|
+
const pagesOf = schema.pages || ((d) => (Array.isArray(d?.pages) ? d.pages : Array.isArray(d?.slides) ? d.slides : d?.deck?.slides || [d]))
|
|
63
|
+
const nodesOf = schema.nodes || ((p) => (Array.isArray(p?.elements) ? p.elements : Array.isArray(p?.children) ? p.children : []))
|
|
64
|
+
const childrenOf = typeof schema.children === 'function' ? schema.children : () => null
|
|
65
|
+
const page = pagesOf(doc)?.[parsed.page]
|
|
66
|
+
if (!page) return null
|
|
67
|
+
let list = nodesOf(page, parsed.page)
|
|
68
|
+
let node = list?.[parsed.node]
|
|
69
|
+
for (const childIndex of parsed.children) {
|
|
70
|
+
if (!node) return null
|
|
71
|
+
list = childrenOf(node)
|
|
72
|
+
node = list?.[childIndex]
|
|
73
|
+
}
|
|
74
|
+
return { list, node, page, parsed }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function setText(node, text, schema) {
|
|
78
|
+
if (typeof schema.setText === 'function') {
|
|
79
|
+
schema.setText(node, text)
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
if ('value' in node && !('content' in node)) node.value = text
|
|
83
|
+
else if ('content' in node) node.content = text
|
|
84
|
+
else node.text = text
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function setBox(node, box) {
|
|
88
|
+
if (!isObj(box)) return
|
|
89
|
+
const { x, y, w, h } = box
|
|
90
|
+
if ('left' in node || 'top' in node) {
|
|
91
|
+
if (Number.isFinite(x)) node.left = x
|
|
92
|
+
if (Number.isFinite(y)) node.top = y
|
|
93
|
+
if (Number.isFinite(w)) node.width = w
|
|
94
|
+
if (Number.isFinite(h)) node.height = h
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
if (Number.isFinite(x)) node.x = x
|
|
98
|
+
if (Number.isFinite(y)) node.y = y
|
|
99
|
+
if (Number.isFinite(w)) node.w = w
|
|
100
|
+
if (Number.isFinite(h)) node.h = h
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function applyPatch(node, patch, schema) {
|
|
104
|
+
if (patch.text !== undefined) setText(node, patch.text, schema)
|
|
105
|
+
if (patch.box !== undefined) setBox(node, patch.box)
|
|
106
|
+
if (isObj(patch.style)) Object.assign(node, patch.style)
|
|
107
|
+
if (isObj(patch.attrs)) Object.assign(node, patch.attrs)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 纯树改写:不抛“找不到”(默认记 skipped),便于批量编辑一次返回全部问题。
|
|
112
|
+
* @returns {{ doc: object, applied: Array, skipped: Array }}
|
|
113
|
+
*/
|
|
114
|
+
export function applyPlan(doc, plan, schema = {}) {
|
|
115
|
+
const next = structuredClone(doc)
|
|
116
|
+
const applied = []
|
|
117
|
+
const skipped = []
|
|
118
|
+
for (const op of plan) {
|
|
119
|
+
if (op.op === 'insert') {
|
|
120
|
+
const pagesOf = schema.pages || ((d) => (Array.isArray(d?.pages) ? d.pages : Array.isArray(d?.slides) ? d.slides : d?.deck?.slides))
|
|
121
|
+
const nodesOf = schema.nodes || ((p) => (Array.isArray(p?.elements) ? p.elements : p.children || []))
|
|
122
|
+
const page = pagesOf(next)?.[op.page]
|
|
123
|
+
if (!page) { skipped.push({ op, reason: 'NO_PAGE' }); continue }
|
|
124
|
+
const list = nodesOf(page, op.page)
|
|
125
|
+
if (!Array.isArray(list)) { skipped.push({ op, reason: 'NO_NODE_LIST' }); continue }
|
|
126
|
+
const at = op.index === null || op.index === undefined ? list.length : Math.max(0, Math.min(op.index, list.length))
|
|
127
|
+
list.splice(at, 0, structuredClone(op.node))
|
|
128
|
+
applied.push(op)
|
|
129
|
+
continue
|
|
130
|
+
}
|
|
131
|
+
const hit = listAt(next, schema, op.target.path)
|
|
132
|
+
if (!hit || !hit.node) { skipped.push({ op, reason: 'NOT_FOUND' }); continue }
|
|
133
|
+
if (op.op === 'update') {
|
|
134
|
+
applyPatch(hit.node, op.patch, schema)
|
|
135
|
+
applied.push(op)
|
|
136
|
+
} else if (op.op === 'remove') {
|
|
137
|
+
hit.list.splice(hit.parsed.children.length ? hit.list.indexOf(hit.node) : hit.parsed.node, 1)
|
|
138
|
+
applied.push(op)
|
|
139
|
+
} else if (op.op === 'move') {
|
|
140
|
+
const raw = hit.list.splice(hit.parsed.children.length ? hit.list.indexOf(hit.node) : hit.parsed.node, 1)[0]
|
|
141
|
+
const dest = listAt(next, schema, `p${op.page}/n0`)
|
|
142
|
+
if (!dest || !Array.isArray(dest.list)) { skipped.push({ op, reason: 'NO_PAGE' }); continue }
|
|
143
|
+
const at = op.index === null || op.index === undefined ? dest.list.length : Math.max(0, Math.min(op.index, dest.list.length))
|
|
144
|
+
dest.list.splice(at, 0, raw)
|
|
145
|
+
applied.push(op)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (isObj(next)) next.rev = (next.rev | 0) + (applied.length ? 1 : 0)
|
|
149
|
+
return { doc: next, applied, skipped }
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** 便利:一次「定位 + 打补丁」(最常用的编辑形态)。 */
|
|
153
|
+
export function patchAt(manifest, locator, patch) {
|
|
154
|
+
const hit = locate(manifest, locator)
|
|
155
|
+
return {
|
|
156
|
+
op: 'update',
|
|
157
|
+
target: { id: hit.id, path: hit.path, page: hit.page, index: hit.index, role: hit.role, type: hit.type },
|
|
158
|
+
patch,
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 模型校验:把「能不能安全地按 ID 编辑」变成机器可判定的检查。
|
|
3
|
+
*
|
|
4
|
+
* 检查项(与 generate-then-edit 的工作流直接相关):
|
|
5
|
+
* ID_DUPLICATE 同一 ID 出现两次 → 寻址会指错元素
|
|
6
|
+
* ID_MISSING 节点没有 ID → 只能按路径改,移动后就断
|
|
7
|
+
* PAGE_EMPTY 空页 → 通常是生成失败
|
|
8
|
+
* BOX_OUT_OF_PAGE 元素越界 → 排版问题(需要 pageSize)
|
|
9
|
+
* TEXT_TOO_LONG 单节点文本超限 → 版面溢出
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const isObj = (value) => !!value && typeof value === 'object' && !Array.isArray(value)
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {ReturnType<import('./manifest.mjs').buildManifest>} manifest
|
|
16
|
+
* @param {{ pageSize?: (pageIndex:number)=> {w:number,h:number}|null, maxChars?: number, allowMissingIds?: boolean }} options
|
|
17
|
+
*/
|
|
18
|
+
export function validateManifest(manifest, options = {}) {
|
|
19
|
+
const issues = []
|
|
20
|
+
const seen = new Map()
|
|
21
|
+
const maxChars = Number(options.maxChars) || 0
|
|
22
|
+
const checkPageEmpty = options.pageEmpty !== false
|
|
23
|
+
|
|
24
|
+
for (const node of manifest.nodes) {
|
|
25
|
+
if (!node.id) {
|
|
26
|
+
if (!options.allowMissingIds) issues.push({ code: 'ID_MISSING', path: node.path, message: '元素缺少稳定 ID' })
|
|
27
|
+
continue
|
|
28
|
+
}
|
|
29
|
+
if (seen.has(node.id)) {
|
|
30
|
+
issues.push({ code: 'ID_DUPLICATE', path: node.path, message: `ID 重复:${node.id}(另一处 ${seen.get(node.id)})` })
|
|
31
|
+
} else {
|
|
32
|
+
seen.set(node.id, node.path)
|
|
33
|
+
}
|
|
34
|
+
if (maxChars && node.charCount > maxChars) {
|
|
35
|
+
issues.push({ code: 'TEXT_TOO_LONG', path: node.path, message: `${node.id} 文本 ${node.charCount} 字,超过 ${maxChars}` })
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (typeof options.pageSize === 'function') {
|
|
40
|
+
for (const page of manifest.pages) {
|
|
41
|
+
const size = options.pageSize(page.index)
|
|
42
|
+
if (!size || !Number.isFinite(size.w) || !Number.isFinite(size.h)) continue
|
|
43
|
+
for (const node of manifest.nodes.filter((n) => n.page === page.index)) {
|
|
44
|
+
if (!node.box) continue
|
|
45
|
+
const { x, y, w, h } = node.box
|
|
46
|
+
if (x < -1 || y < -1 || x + w > size.w + 1 || y + h > size.h + 1) {
|
|
47
|
+
issues.push({
|
|
48
|
+
code: 'BOX_OUT_OF_PAGE',
|
|
49
|
+
path: node.path,
|
|
50
|
+
message: `${node.id} 越界:(${x},${y}) ${w}×${h} 超出页面 ${size.w}×${size.h}`,
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
for (const page of manifest.pages) {
|
|
58
|
+
if (checkPageEmpty && !page.count) {
|
|
59
|
+
issues.push({ code: 'PAGE_EMPTY', path: `p${page.index}`, message: `第 ${page.index} 页没有任何元素` })
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return { ok: issues.length === 0, issues }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 把校验结果压成给模型看的一行摘要。 */
|
|
67
|
+
export function describeIssues(result, limit = 6) {
|
|
68
|
+
if (result.ok) return '模型校验通过'
|
|
69
|
+
const head = result.issues.slice(0, limit).map((issue) => `${issue.code} ${issue.path}:${issue.message}`)
|
|
70
|
+
const more = result.issues.length > limit ? `…(共 ${result.issues.length} 条)` : ''
|
|
71
|
+
return head.join('\n') + (more ? '\n' + more : '')
|
|
72
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文档 op 注册与分发:把「查表 + snapshot 策略 + 未知指令」收敛到一处。
|
|
3
|
+
* op 实现按域放在调用方,注册表只提供统一元数据与分发。
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export function defineOp({ name, run, apply, mutates = true, view = false, description = '' } = {}) {
|
|
7
|
+
if (!name || typeof name !== 'string') throw new Error('defineOp 需要 name')
|
|
8
|
+
const fn = run || apply
|
|
9
|
+
if (typeof fn !== 'function') throw new Error(`op "${name}" 需要 run 函数`)
|
|
10
|
+
return {
|
|
11
|
+
name,
|
|
12
|
+
run: fn,
|
|
13
|
+
mutates: mutates !== false,
|
|
14
|
+
view: view === true,
|
|
15
|
+
description,
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function normalizeDefinition(name, raw) {
|
|
20
|
+
if (!raw || typeof raw !== 'object') throw new Error(`op "${name}" 定义不合法`)
|
|
21
|
+
const fn = raw.run || raw.apply
|
|
22
|
+
if (typeof fn !== 'function') throw new Error(`op "${name}" 需要 run 函数`)
|
|
23
|
+
return {
|
|
24
|
+
...raw,
|
|
25
|
+
name,
|
|
26
|
+
run: fn,
|
|
27
|
+
mutates: raw.mutates !== false,
|
|
28
|
+
view: raw.view === true,
|
|
29
|
+
description: raw.description || '',
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 把 { domain: { opName: definition } } 摊平成一张 op 表。 */
|
|
34
|
+
export function mergeOpModules(modules = {}) {
|
|
35
|
+
const out = {}
|
|
36
|
+
for (const table of Object.values(modules)) {
|
|
37
|
+
Object.assign(out, table)
|
|
38
|
+
}
|
|
39
|
+
return out
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function createOpRegistry({
|
|
43
|
+
ops = {},
|
|
44
|
+
modules = null,
|
|
45
|
+
snapshot = null,
|
|
46
|
+
assertReady = null,
|
|
47
|
+
unknownMessage = null,
|
|
48
|
+
} = {}) {
|
|
49
|
+
const source = modules ? mergeOpModules(modules) : ops
|
|
50
|
+
const definitions = {}
|
|
51
|
+
for (const [name, raw] of Object.entries(source)) {
|
|
52
|
+
if (Object.hasOwn(definitions, name)) throw new Error(`重复的 op: ${name}`)
|
|
53
|
+
definitions[name] = normalizeDefinition(name, raw)
|
|
54
|
+
}
|
|
55
|
+
const names = Object.keys(definitions)
|
|
56
|
+
const viewNames = names.filter((name) => definitions[name].view)
|
|
57
|
+
|
|
58
|
+
async function apply(target, cmd, ctx = {}) {
|
|
59
|
+
if (assertReady) assertReady(target)
|
|
60
|
+
else if (target && typeof target.isMounted === 'function' && !target.isMounted()) {
|
|
61
|
+
throw new Error('编辑器未就绪')
|
|
62
|
+
}
|
|
63
|
+
const name = cmd && cmd.op
|
|
64
|
+
const def = definitions[name]
|
|
65
|
+
if (!def) {
|
|
66
|
+
const detail = unknownMessage
|
|
67
|
+
? unknownMessage(name)
|
|
68
|
+
: '未知指令: ' + String(name || JSON.stringify(cmd).slice(0, 40))
|
|
69
|
+
throw new Error(detail)
|
|
70
|
+
}
|
|
71
|
+
if (def.mutates && snapshot) snapshot(target)
|
|
72
|
+
return def.run(target, cmd || {}, ctx)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function isViewOp(cmdOrName) {
|
|
76
|
+
const name = typeof cmdOrName === 'string' ? cmdOrName : cmdOrName && cmdOrName.op
|
|
77
|
+
return !!(name && definitions[name] && definitions[name].view)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
definitions,
|
|
82
|
+
names,
|
|
83
|
+
viewNames,
|
|
84
|
+
has: (name) => Object.hasOwn(definitions, name),
|
|
85
|
+
isViewOp,
|
|
86
|
+
apply,
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** 兼容旧调用:用 definitions 建一个 applyOp。 */
|
|
91
|
+
export function createOpDispatcher(definitions, options = {}) {
|
|
92
|
+
return createOpRegistry({ ops: definitions, ...options }).apply
|
|
93
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 会话上下文(共享单一真源):把「这次请求属于哪个会话」带到不经过 HTTP 的深处。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要它:工作台不再是一份全局 store,而是每会话一份。路由在装配时
|
|
5
|
+
* 只拿到 store 门面,真正用哪一份必须等到**请求发生时**才知道;而桥 / 稿件 /
|
|
6
|
+
* 导入 / 领域 shim 之间的调用链全在同一个请求里。AsyncLocalStorage 让这条链上
|
|
7
|
+
* 的每一层都能读到同一个会话 id,不需要把 sid 逐层透传。
|
|
8
|
+
*
|
|
9
|
+
* 除 HTTP 之外还有一个入口:工具调用。DSH 同进程注册的工具会拿到执行上下文
|
|
10
|
+
* (`exec.agent.session.id`),`bindToolsToCallerSession` 就借它把「调用者会话」
|
|
11
|
+
* 缝进来——工具永远改调用它的那个会话,而不是"用户此刻在看的那个窗口"。
|
|
12
|
+
* 只有在拿不到执行上下文(MCP 传输形态)时,才回落到最近聚焦的窗口。
|
|
13
|
+
*
|
|
14
|
+
* 三个 bridge(ppt/canvas/browser)共用本模块:embedded 形态同进程,ALS 单例
|
|
15
|
+
* 天然按异步链隔离各自的会话上下文,互不串扰。
|
|
16
|
+
*/
|
|
17
|
+
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
18
|
+
|
|
19
|
+
const storage = new AsyncLocalStorage()
|
|
20
|
+
|
|
21
|
+
/** 在指定会话的上下文里跑一段逻辑(await 链与定时器都会继承)。 */
|
|
22
|
+
export function runWithSession(sessionId, fn) {
|
|
23
|
+
return storage.run(String(sessionId || ''), fn)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** 当前请求所属的会话 id;不在请求里时返回空串。 */
|
|
27
|
+
export function currentSession() {
|
|
28
|
+
const value = storage.getStore()
|
|
29
|
+
return typeof value === 'string' ? value : ''
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 从原生工具调用的执行上下文里取「调用者会话」。
|
|
34
|
+
*
|
|
35
|
+
* DSH 同进程注册的工具会拿到 `exec`(`ctx.tools.register({ execute(args, exec) })`),
|
|
36
|
+
* 其中 `exec.agent.session.id` 就是发起这次工具调用的会话。有了它,工具写入不再
|
|
37
|
+
* 依赖「用户此刻在看哪个窗口」,而是落到**调用它的那个会话**自己的文档上。
|
|
38
|
+
*
|
|
39
|
+
* 拿不到(MCP 传输形态、旧宿主)返回空串,由 store 门面回落到最近聚焦的窗口。
|
|
40
|
+
*/
|
|
41
|
+
export function sessionFromExec(exec) {
|
|
42
|
+
const sid = exec && exec.agent && exec.agent.session ? exec.agent.session.id : ''
|
|
43
|
+
return typeof sid === 'string' ? sid.trim() : ''
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 把工具实现包一层:有调用者会话就在它的上下文里跑,没有就按原样跑。
|
|
48
|
+
*
|
|
49
|
+
* 为什么包在实现层而不是路由层:工具不经过 HTTP,store 门面拿不到 `req.sessionId`,
|
|
50
|
+
* 只能靠 ALS 把会话缝进去。包装后所有工具都不用改签名。
|
|
51
|
+
*/
|
|
52
|
+
export function bindToolsToCallerSession(registry) {
|
|
53
|
+
const impls = registry && registry.TOOL_IMPL
|
|
54
|
+
if (!impls || typeof impls !== 'object') return registry
|
|
55
|
+
for (const name of Object.keys(impls)) {
|
|
56
|
+
const impl = impls[name]
|
|
57
|
+
if (typeof impl !== 'function' || impl.__sessionBound) continue
|
|
58
|
+
const bound = (args, exec) => {
|
|
59
|
+
const sid = sessionFromExec(exec)
|
|
60
|
+
/* exec 原样透传:今天的实现体只用 args,但未来若有工具要执行上下文
|
|
61
|
+
* (进度/中止等),不能在这层被静默丢掉。 */
|
|
62
|
+
return sid ? runWithSession(sid, () => impl(args, exec)) : impl(args, exec)
|
|
63
|
+
}
|
|
64
|
+
bound.__sessionBound = true
|
|
65
|
+
impls[name] = bound
|
|
66
|
+
}
|
|
67
|
+
return registry
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 把所有路由包成一条:先定会话,再按原顺序跑到第一个接手的路由。
|
|
72
|
+
*
|
|
73
|
+
* 顺序必须保持(mcp → assets → editor → import → manuscript → bridge),
|
|
74
|
+
* 否则 bridge 会先把 POST 当桥协议读走。
|
|
75
|
+
*/
|
|
76
|
+
export function createSessionDispatch(handlers, stores) {
|
|
77
|
+
return async function dispatchSession(req, res, u) {
|
|
78
|
+
const sessionId = String((req && req.sessionId) || (u && u.sessionId) || '')
|
|
79
|
+
/* 打开/刷新某会话的编辑器页面本身就是「用户现在在这个会话里」的信号。
|
|
80
|
+
* 轮询(/watch)不参与,否则两扇窗会互相抢「当前会话」。 */
|
|
81
|
+
if (sessionId && stores && (u.pathname === '/' || u.pathname === '/index.html')) {
|
|
82
|
+
stores.setActive(sessionId)
|
|
83
|
+
}
|
|
84
|
+
return runWithSession(sessionId, async () => {
|
|
85
|
+
for (const handler of handlers) {
|
|
86
|
+
if (await handler(req, res, u)) return true
|
|
87
|
+
}
|
|
88
|
+
return false
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
}
|