@capyclaw/browser-workbench 0.1.0 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -7
- package/contract/browser-contract.json +484 -25
- package/demo/form.html +27 -0
- package/lib/host.mjs +1 -68
- package/node_modules/@capyclaw/asset-service/README.md +48 -0
- package/node_modules/@capyclaw/asset-service/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/asset-service/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/asset-service/lib/host.mjs +14 -0
- package/node_modules/@capyclaw/asset-service/package.json +59 -0
- package/node_modules/@capyclaw/asset-service/src/index.mjs +304 -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 +103 -0
- package/node_modules/@capyclaw/document-workbench/src/session/index.mjs +394 -0
- package/node_modules/@capyclaw/document-workbench/src/session/lease.mjs +105 -0
- package/node_modules/@capyclaw/document-workbench/src/session/mode.mjs +80 -0
- package/node_modules/@capyclaw/document-workbench/src/session/sanitize.mjs +107 -0
- package/node_modules/@capyclaw/document-workbench/src/session/state.mjs +159 -0
- package/node_modules/@capyclaw/document-workbench/src/session/watch.mjs +63 -0
- package/{server/shared/state-service.mjs → node_modules/@capyclaw/document-workbench/src/store/file-backend.mjs} +6 -97
- package/node_modules/@capyclaw/document-workbench/src/testing/index.mjs +75 -0
- package/node_modules/@capyclaw/foundation/README.md +51 -0
- package/node_modules/@capyclaw/foundation/abi/bridge.mjs +86 -0
- package/node_modules/@capyclaw/foundation/abi/errors.mjs +63 -0
- package/node_modules/@capyclaw/foundation/abi/index.mjs +35 -0
- package/node_modules/@capyclaw/foundation/abi/kinds.mjs +271 -0
- package/node_modules/@capyclaw/foundation/abi/loader.mjs +345 -0
- package/node_modules/@capyclaw/foundation/abi/schema.mjs +98 -0
- package/node_modules/@capyclaw/foundation/abi/spec.mjs +255 -0
- package/node_modules/@capyclaw/foundation/abi/validate.mjs +24 -0
- package/node_modules/@capyclaw/foundation/abi/version.mjs +82 -0
- package/node_modules/@capyclaw/foundation/cordis.patch.yml +5 -0
- package/node_modules/@capyclaw/foundation/kit/index.mjs +6 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/client-panel.mjs +98 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/host-event.mjs +35 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/http-router.mjs +69 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +55 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/own-server.mjs +113 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +69 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +120 -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 +115 -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 +150 -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 +57 -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 +166 -0
- package/node_modules/@capyclaw/tool-host/src/index.mjs +416 -0
- package/node_modules/playwright/LICENSE +202 -0
- package/node_modules/playwright/NOTICE +5 -0
- package/node_modules/playwright/README.md +318 -0
- package/node_modules/playwright/ThirdPartyNotices.txt +14 -0
- package/node_modules/playwright/cli.js +19 -0
- package/node_modules/playwright/index.d.ts +17 -0
- package/node_modules/playwright/index.js +17 -0
- package/node_modules/playwright/index.mjs +18 -0
- package/node_modules/playwright/lib/agents/agentParser.js +89 -0
- package/node_modules/playwright/lib/agents/copilot-setup-steps.yml +34 -0
- package/node_modules/playwright/lib/agents/generateAgents.js +395 -0
- package/node_modules/playwright/lib/agents/playwright-test-coverage.prompt.md +31 -0
- package/node_modules/playwright/lib/agents/playwright-test-generate.prompt.md +8 -0
- package/node_modules/playwright/lib/agents/playwright-test-generator.agent.md +88 -0
- package/node_modules/playwright/lib/agents/playwright-test-heal.prompt.md +6 -0
- package/node_modules/playwright/lib/agents/playwright-test-healer.agent.md +56 -0
- package/node_modules/playwright/lib/agents/playwright-test-plan.prompt.md +9 -0
- package/node_modules/playwright/lib/agents/playwright-test-planner.agent.md +74 -0
- package/node_modules/playwright/lib/cli/reportActions.js +78 -0
- package/node_modules/playwright/lib/cli/testActions.js +217 -0
- package/node_modules/playwright/lib/common/index.js +2937 -0
- package/node_modules/playwright/lib/common/index.js.txt +33 -0
- package/node_modules/playwright/lib/errorContext.js +129 -0
- package/node_modules/playwright/lib/globals.js +58 -0
- package/node_modules/playwright/lib/index.js +827 -0
- package/node_modules/playwright/lib/isomorphic.js +260 -0
- package/node_modules/playwright/lib/isomorphic.js.txt +9 -0
- package/node_modules/playwright/lib/loader/loaderProcessEntry.js +34 -0
- package/node_modules/playwright/lib/loader/loaderProcessEntry.js.txt +9 -0
- package/node_modules/playwright/lib/matchers/expect.js +13496 -0
- package/node_modules/playwright/lib/matchers/expect.js.LICENSE +640 -0
- package/node_modules/playwright/lib/matchers/expect.js.txt +67 -0
- package/node_modules/playwright/lib/package.js +47 -0
- package/node_modules/playwright/lib/program.js +242 -0
- package/node_modules/playwright/lib/runner/index.js +8721 -0
- package/node_modules/playwright/lib/runner/index.js.txt +62 -0
- package/node_modules/playwright/lib/transform/babelBundle.js +72490 -0
- package/node_modules/playwright/lib/transform/babelBundle.js.LICENSE +2384 -0
- package/node_modules/playwright/lib/transform/babelBundle.js.txt +328 -0
- package/node_modules/playwright/lib/transform/esmLoader.js +8066 -0
- package/node_modules/playwright/lib/transform/esmLoader.js.LICENSE +355 -0
- package/node_modules/playwright/lib/transform/esmLoader.js.txt +60 -0
- package/node_modules/playwright/lib/util.js +373 -0
- package/node_modules/playwright/lib/worker/workerProcessEntry.js +1860 -0
- package/node_modules/playwright/lib/worker/workerProcessEntry.js.txt +19 -0
- package/node_modules/playwright/package.json +50 -0
- package/node_modules/playwright/test.d.ts +18 -0
- package/node_modules/playwright/test.js +24 -0
- package/node_modules/playwright/test.mjs +35 -0
- package/node_modules/playwright/types/test.d.ts +11191 -0
- package/node_modules/playwright/types/testReporter.d.ts +950 -0
- package/node_modules/playwright-core/LICENSE +202 -0
- package/node_modules/playwright-core/NOTICE +5 -0
- package/node_modules/playwright-core/README.md +3 -0
- package/node_modules/playwright-core/ThirdPartyNotices.txt +13 -0
- package/node_modules/playwright-core/bin/install_media_pack.ps1 +5 -0
- package/node_modules/playwright-core/bin/install_webkit_wsl.ps1 +33 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_beta_linux.sh +42 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_beta_mac.sh +13 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_beta_win.ps1 +24 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_stable_linux.sh +42 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_stable_mac.sh +12 -0
- package/node_modules/playwright-core/bin/reinstall_chrome_stable_win.ps1 +24 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_beta_linux.sh +48 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_beta_mac.sh +11 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_beta_win.ps1 +23 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_dev_linux.sh +48 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_dev_mac.sh +11 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_dev_win.ps1 +23 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_stable_linux.sh +48 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_stable_mac.sh +11 -0
- package/node_modules/playwright-core/bin/reinstall_msedge_stable_win.ps1 +24 -0
- package/node_modules/playwright-core/browsers.json +52 -0
- package/node_modules/playwright-core/cli.js +22 -0
- package/node_modules/playwright-core/index.d.ts +17 -0
- package/node_modules/playwright-core/index.js +17 -0
- package/node_modules/playwright-core/index.mjs +28 -0
- package/node_modules/playwright-core/lib/bootstrap.js +149 -0
- package/node_modules/playwright-core/lib/coreBundle.js +78041 -0
- package/node_modules/playwright-core/lib/entry/cliDaemon.js +5 -0
- package/node_modules/playwright-core/lib/entry/dashboardApp.js +3 -0
- package/node_modules/playwright-core/lib/entry/mcp.js +10 -0
- package/node_modules/playwright-core/lib/entry/oopBrowserDownload.js +3 -0
- package/node_modules/playwright-core/lib/package.js +50 -0
- package/node_modules/playwright-core/lib/server/chromium/appIcon.png +0 -0
- package/node_modules/playwright-core/lib/server/electron/loader.js +123 -0
- package/node_modules/playwright-core/lib/serverRegistry.js +1939 -0
- package/node_modules/playwright-core/lib/serverRegistry.js.LICENSE +65 -0
- package/node_modules/playwright-core/lib/tools/cli-client/channelSessions.js +141 -0
- package/node_modules/playwright-core/lib/tools/cli-client/cli.js +7 -0
- package/node_modules/playwright-core/lib/tools/cli-client/help.json +808 -0
- package/node_modules/playwright-core/lib/tools/cli-client/minimist.js +128 -0
- package/node_modules/playwright-core/lib/tools/cli-client/output.js +352 -0
- package/node_modules/playwright-core/lib/tools/cli-client/program.js +422 -0
- package/node_modules/playwright-core/lib/tools/cli-client/registry.js +180 -0
- package/node_modules/playwright-core/lib/tools/cli-client/session.js +261 -0
- package/node_modules/playwright-core/lib/tools/dashboard/appIcon.png +0 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/SKILL.md +493 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/element-attributes.md +23 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/playwright-tests.md +39 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/pr-attachments.md +60 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/request-mocking.md +87 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/running-code.md +245 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/session-management.md +227 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/storage-state.md +275 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/test-generation.md +433 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/tracing.md +139 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/video-recording.md +216 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/SKILL.md +136 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/gallery-spec.md +144 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/migration.md +89 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/react.md +69 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/typing.md +173 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/vue.md +77 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-trace/SKILL.md +174 -0
- package/node_modules/playwright-core/lib/tools/utils/extension.js +112 -0
- package/node_modules/playwright-core/lib/tools/utils/socketConnection.js +108 -0
- package/node_modules/playwright-core/lib/utilsBundle.js +86078 -0
- package/node_modules/playwright-core/lib/utilsBundle.js.LICENSE +1890 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/codeMirrorModule--QdMvsKi.css +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/codeMirrorModule-CQ8RZGBm.js +32 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/codicon-DCmgc-ay.ttf +0 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/firefox-1bWoP6pv.svg +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/firefox-beta-k3eOH_eK.svg +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/firefox-nightly-Cp5nfeDT.svg +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/index-AwgwcYie.css +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/index-hRvO4yU2.js +12 -0
- package/node_modules/playwright-core/lib/vite/dashboard/assets/safari-na3_-uQk.svg +1 -0
- package/node_modules/playwright-core/lib/vite/dashboard/index.html +29 -0
- package/node_modules/playwright-core/lib/vite/dashboard/playwright-logo.svg +24 -0
- package/node_modules/playwright-core/lib/vite/htmlReport/index.html +16 -0
- package/node_modules/playwright-core/lib/vite/htmlReport/report.css +2 -0
- package/node_modules/playwright-core/lib/vite/htmlReport/report.js +32 -0
- package/node_modules/playwright-core/lib/vite/recorder/assets/codeMirrorModule--QdMvsKi.css +1 -0
- package/node_modules/playwright-core/lib/vite/recorder/assets/codeMirrorModule-DK72OMRi.js +32 -0
- package/node_modules/playwright-core/lib/vite/recorder/assets/codicon-DCmgc-ay.ttf +0 -0
- package/node_modules/playwright-core/lib/vite/recorder/assets/index-BZpYJZ-P.css +1 -0
- package/node_modules/playwright-core/lib/vite/recorder/assets/index-Cn0mmDuv.js +129 -0
- package/node_modules/playwright-core/lib/vite/recorder/index.html +29 -0
- package/node_modules/playwright-core/lib/vite/recorder/playwright-logo.svg +9 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/assets/codeMirrorModule-BEB2e8M3.js +32 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/assets/defaultSettingsView-D-g2vrvf.js +184 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/assets/urlMatch-L3liM589.js +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/assets/xtermModule-B794rD2Z.js +7 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/codeMirrorModule.-QdMvsKi.css +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/defaultSettingsView.C8BeHuxd.css +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/index.B_TqY17P.css +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/index.html +44 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/index.oNry3Hjv.js +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/manifest.webmanifest +16 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/playwright-logo.svg +9 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/snapshot.B_Jk1wbt.js +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/snapshot.html +10 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/sw.bundle.js +4 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/uiMode.CYwC_gH1.js +5 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/uiMode.CyMfwkXJ.css +1 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/uiMode.html +18 -0
- package/node_modules/playwright-core/lib/vite/traceViewer/xtermModule.kHJ-D0s7.css +1 -0
- package/node_modules/playwright-core/lib/webp_codec.LICENSE +173 -0
- package/node_modules/playwright-core/lib/webp_codec.wasm +0 -0
- package/node_modules/playwright-core/lib/xdg-open +1267 -0
- package/node_modules/playwright-core/package.json +34 -0
- package/node_modules/playwright-core/types/protocol.d.ts +24776 -0
- package/node_modules/playwright-core/types/structs.d.ts +52 -0
- package/node_modules/playwright-core/types/types.d.ts +27167 -0
- package/package.json +30 -12
- package/plugin.mjs +1 -0
- package/server/contract.mjs +3 -3
- package/server/embedded-host.mjs +247 -0
- package/server/engine.mjs +1906 -115
- package/server/governor.mjs +189 -0
- package/server/http-utils.mjs +1 -1
- package/server/human.mjs +628 -0
- package/server/infra/http.mjs +2 -113
- package/server/infra/tuning.mjs +2 -82
- package/server/input.mjs +154 -0
- package/server/login-vault.mjs +109 -0
- package/server/mcp/handler.mjs +1 -1
- package/server/mcp/instructions.mjs +5 -2
- package/server/orphans.mjs +163 -0
- package/server/relay.mjs +160 -188
- package/server/routes/api.mjs +126 -13
- package/server/routes/assets.mjs +1 -1
- package/server/session-engines.mjs +223 -0
- package/server/shared/SHARED_MANIFEST.json +47 -24
- package/server/shared/asset-service.mjs +2 -217
- package/server/shared/editor-host.mjs +2 -125
- package/server/shared/kit/editor/lease.mjs +2 -139
- package/server/shared/kit/service/api.mjs +2 -45
- package/server/shared/kit/service/http.mjs +2 -113
- package/server/shared/kit/service/mcp-http.mjs +2 -142
- package/server/shared/kit/tools/validate.mjs +2 -115
- package/server/shared/kit/tuning.mjs +2 -82
- package/server/shared/kit/util/fs-lock.mjs +2 -132
- package/server/shared/service-host.mjs +2 -511
- package/server/shared/tool-host.mjs +2 -341
- package/server/shared/tuning.mjs +2 -63
- package/server/tools/capabilities/contract.mjs +25 -5
- package/server/tools/capabilities/interaction.mjs +113 -9
- package/server/tools/capabilities/navigation.mjs +5 -2
- package/server/tools/capabilities/screenshot.mjs +25 -8
- package/server/tools/capabilities/session.mjs +13 -7
- package/server/tools/capabilities/snapshot.mjs +1 -1
- package/server/tools/capabilities/tabs.mjs +2 -2
- package/server/tools/kernel/define.mjs +1 -1
- package/server/tools/kernel/output.mjs +8 -0
- package/server/tools/kernel/ports.mjs +12 -7
- package/server/tools/kernel/registry.mjs +1 -1
- package/server/workbench-framework.mjs +305 -0
- package/ui/app.js +409 -119
- package/ui/index.html +29 -39
- package/ui/style.css +131 -63
- package/cordis.patch.yml +0 -25
|
@@ -1,139 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* 活动权(claim)只存在于内部仲裁;不要把它渲染成 UI 状态。
|
|
5
|
-
* 新打开的窗口强制抢占,旧窗口静默转入待命。
|
|
6
|
-
*/
|
|
7
|
-
import { tuning } from '../tuning.mjs'
|
|
8
|
-
|
|
9
|
-
const DEFAULT_TTL = 15 // 秒
|
|
10
|
-
const DEFAULT_HEARTBEAT = 3 // 秒(心跳间隔应小于 TTL)
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 创建编辑器租约仲裁器。
|
|
14
|
-
* @param {{ ttl?: number }} [opts]
|
|
15
|
-
*/
|
|
16
|
-
export function createEditorLease(opts = {}) {
|
|
17
|
-
const ttl = Number(opts.ttl) || DEFAULT_TTL
|
|
18
|
-
let owner = null // { id, ts }
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
claim(id, force = false) {
|
|
22
|
-
const now = Date.now() / 1000
|
|
23
|
-
if (force || !owner || owner.id === id || now - owner.ts > ttl) {
|
|
24
|
-
owner = { id, ts: now }
|
|
25
|
-
return { ok: true, owner: id }
|
|
26
|
-
}
|
|
27
|
-
return { ok: false, owner: owner.id }
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
release(id) {
|
|
31
|
-
if (owner && owner.id === id) owner = null
|
|
32
|
-
return { ok: true }
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
isLive() {
|
|
36
|
-
return !!owner && Date.now() / 1000 - owner.ts <= ttl
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
status() {
|
|
40
|
-
return owner
|
|
41
|
-
? { owner: owner.id, age: Math.round((Date.now() / 1000 - owner.ts) * 100) / 100 }
|
|
42
|
-
: null
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
async wait(o = {}) {
|
|
46
|
-
const { leaseWaitPollMs: pollMs, leaseWaitTimeoutMs: defaultTimeoutMs } = tuning()
|
|
47
|
-
const deadline = Date.now() + (o.timeoutMs || defaultTimeoutMs)
|
|
48
|
-
while (true) {
|
|
49
|
-
if (this.isLive()) return this.status()
|
|
50
|
-
if (Date.now() >= deadline) {
|
|
51
|
-
const hint = o.openHint ? `(打开 ${o.openHint})` : ''
|
|
52
|
-
const panel = o.panelHint || '编辑器面板'
|
|
53
|
-
throw new Error(`${panel}尚未连接${hint}。页面加载后会自动连接,无需其他操作。`)
|
|
54
|
-
}
|
|
55
|
-
await new Promise((resolve) => setTimeout(resolve, pollMs))
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* 编辑器端自动挂接循环。
|
|
63
|
-
* 首次 claim 强制抢占(后打开者赢),之后静默心跳。
|
|
64
|
-
* @param {{
|
|
65
|
-
* clientId: string,
|
|
66
|
-
* claim: (force: boolean) => Promise<boolean>,
|
|
67
|
-
* release?: () => void,
|
|
68
|
-
* onActive?: () => void,
|
|
69
|
-
* onStandby?: () => void,
|
|
70
|
-
* retryMs?: number,
|
|
71
|
-
* heartbeatMs?: number,
|
|
72
|
-
* setInterval?: (cb: () => void) => any,
|
|
73
|
-
* clearInterval?: (handle: any) => void
|
|
74
|
-
* }} o
|
|
75
|
-
*/
|
|
76
|
-
export function startAutoAttach(o) {
|
|
77
|
-
if (!o || !o.clientId) throw new Error('startAutoAttach: clientId 必填')
|
|
78
|
-
if (typeof o.claim !== 'function') throw new Error('startAutoAttach: claim 必须是函数')
|
|
79
|
-
|
|
80
|
-
const retryMs = o.retryMs || 1000
|
|
81
|
-
const heartbeatMs = o.heartbeatMs || DEFAULT_HEARTBEAT * 1000
|
|
82
|
-
const setI = o.setInterval || ((cb) => setInterval(cb, heartbeatMs))
|
|
83
|
-
const clearI = o.clearInterval || ((handle) => clearInterval(handle))
|
|
84
|
-
|
|
85
|
-
let active = false
|
|
86
|
-
let heartbeat = null
|
|
87
|
-
let disposed = false
|
|
88
|
-
|
|
89
|
-
async function tryClaim(force) {
|
|
90
|
-
try {
|
|
91
|
-
return await o.claim(force)
|
|
92
|
-
} catch {
|
|
93
|
-
return false
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function goActive() {
|
|
98
|
-
if (active) return
|
|
99
|
-
active = true
|
|
100
|
-
try { o.onActive && o.onActive() } catch { /* 用户回调失败不阻塞挂接 */ }
|
|
101
|
-
heartbeat = setI(async () => {
|
|
102
|
-
if (disposed) return
|
|
103
|
-
const ok = await tryClaim(false)
|
|
104
|
-
if (!ok) goStandby()
|
|
105
|
-
})
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function goStandby() {
|
|
109
|
-
if (!active) return
|
|
110
|
-
active = false
|
|
111
|
-
if (heartbeat != null) {
|
|
112
|
-
clearI(heartbeat)
|
|
113
|
-
heartbeat = null
|
|
114
|
-
}
|
|
115
|
-
try { o.onStandby && o.onStandby() } catch { /* 静默 */ }
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
;(async () => {
|
|
119
|
-
let first = true
|
|
120
|
-
while (!disposed) {
|
|
121
|
-
const ok = await tryClaim(first)
|
|
122
|
-
first = false
|
|
123
|
-
if (ok) {
|
|
124
|
-
goActive()
|
|
125
|
-
return
|
|
126
|
-
}
|
|
127
|
-
await new Promise((resolve) => setTimeout(resolve, retryMs))
|
|
128
|
-
}
|
|
129
|
-
})()
|
|
130
|
-
|
|
131
|
-
return {
|
|
132
|
-
get active() { return active },
|
|
133
|
-
dispose() {
|
|
134
|
-
disposed = true
|
|
135
|
-
goStandby()
|
|
136
|
-
try { o.release && o.release() } catch { /* 释放失败不阻塞退出 */ }
|
|
137
|
-
},
|
|
138
|
-
}
|
|
139
|
-
}
|
|
1
|
+
/** 由 build/sync-shared.mjs 生成:实现只存在于 @capyclaw/plugin-kit/editor/lease,此处零拷贝。 */
|
|
2
|
+
export * from '@capyclaw/plugin-kit/editor/lease'
|
|
@@ -1,45 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {string} name 服务名(ctx.<name>)
|
|
5
|
-
* @param {string} version API 版本(semver;major 变化 = 不兼容)
|
|
6
|
-
* @param {string[]} capabilities 能力标签
|
|
7
|
-
*/
|
|
8
|
-
export function createServiceApi(name, version = '1.0.0', capabilities = []) {
|
|
9
|
-
if (!name) throw new Error('createServiceApi 需要 name')
|
|
10
|
-
return Object.freeze({
|
|
11
|
-
name,
|
|
12
|
-
version,
|
|
13
|
-
capabilities: Object.freeze([...capabilities]),
|
|
14
|
-
})
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 断言一个已注入的服务对象满足消费者要求。
|
|
19
|
-
* 缺失服务或 major 不一致时抛出明确错误,避免“看起来能跑”的静默不兼容。
|
|
20
|
-
* @param {object} service
|
|
21
|
-
* @param {{ name: string, major?: number|string, version?: string }} expected
|
|
22
|
-
*/
|
|
23
|
-
export function assertServiceApi(service, expected = {}) {
|
|
24
|
-
const name = expected.name
|
|
25
|
-
if (!name) throw new Error('assertServiceApi 需要 expected.name')
|
|
26
|
-
const major = String(expected.major ?? String(expected.version || '1').split('.')[0])
|
|
27
|
-
if (!service) throw new Error(`缺少公共服务: ctx.${name}`)
|
|
28
|
-
const api = service.api
|
|
29
|
-
if (!api || typeof api !== 'object') {
|
|
30
|
-
throw new Error(`服务 ctx.${name} 没有声明 api 契约;请升级提供方插件`)
|
|
31
|
-
}
|
|
32
|
-
if (api.name !== name) {
|
|
33
|
-
throw new Error(`服务 ctx.${name} 的 api.name=${api.name},与消费者期望的 ${name} 不一致`)
|
|
34
|
-
}
|
|
35
|
-
const gotMajor = String(api.version || '').split('.')[0]
|
|
36
|
-
if (gotMajor !== major) {
|
|
37
|
-
throw new Error(`服务 ctx.${name} API major=${gotMajor},消费者要求 major=${major}(提供方版本 ${api.version})`)
|
|
38
|
-
}
|
|
39
|
-
return api
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function serviceApiSummary(service) {
|
|
43
|
-
const api = service?.api
|
|
44
|
-
return api ? { name: api.name, version: api.version, capabilities: [...(api.capabilities || [])] } : null
|
|
45
|
-
}
|
|
1
|
+
/** 由 build/sync-shared.mjs 生成:实现只存在于 @capyclaw/plugin-kit/service/api,此处零拷贝。 */
|
|
2
|
+
export * from '@capyclaw/plugin-kit/service/api'
|
|
@@ -1,113 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
import { tuning } from '../tuning.mjs'
|
|
4
|
-
|
|
5
|
-
export const SECURITY_HEADERS = {
|
|
6
|
-
'x-content-type-options': 'nosniff',
|
|
7
|
-
'referrer-policy': 'no-referrer',
|
|
8
|
-
'cache-control': 'no-store, no-cache, must-revalidate',
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/** 客户端已断开时放弃写入:长请求(截图/长轮询)在 handler 完成前客户端超时
|
|
12
|
-
* 断连是常态,写已销毁的 socket 会触发无人监听的 'error' 事件打崩进程。 */
|
|
13
|
-
function resDead(res) {
|
|
14
|
-
return res.destroyed || res.writableEnded
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function send(req, res, code, obj, extraHeaders = {}) {
|
|
18
|
-
if (resDead(res)) return
|
|
19
|
-
const body = obj === undefined ? '' : JSON.stringify(obj)
|
|
20
|
-
try {
|
|
21
|
-
res.writeHead(code, {
|
|
22
|
-
'content-type': 'application/json',
|
|
23
|
-
'content-length': Buffer.byteLength(body),
|
|
24
|
-
...SECURITY_HEADERS,
|
|
25
|
-
...extraHeaders,
|
|
26
|
-
})
|
|
27
|
-
res.end(req.method === 'HEAD' ? undefined : body)
|
|
28
|
-
} catch { /* socket 已死:响应无人接收,静默放弃 */ }
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function sendText(req, res, code, text, contentType = 'text/plain; charset=utf-8', extraHeaders = {}) {
|
|
32
|
-
if (resDead(res)) return
|
|
33
|
-
const body = text === undefined || text === null ? '' : String(text)
|
|
34
|
-
try {
|
|
35
|
-
res.writeHead(code, {
|
|
36
|
-
'content-type': contentType,
|
|
37
|
-
'content-length': Buffer.byteLength(body),
|
|
38
|
-
...SECURITY_HEADERS,
|
|
39
|
-
...extraHeaders,
|
|
40
|
-
})
|
|
41
|
-
res.end(req.method === 'HEAD' ? undefined : body)
|
|
42
|
-
} catch { /* socket 已死:响应无人接收,静默放弃 */ }
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function bodyError(code, message) {
|
|
46
|
-
const error = new Error(message)
|
|
47
|
-
error.code = code
|
|
48
|
-
return error
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function readBody(req, limit = 10 * 1024 * 1024) {
|
|
52
|
-
return new Promise((resolve, reject) => {
|
|
53
|
-
let size = 0
|
|
54
|
-
const chunks = []
|
|
55
|
-
let settled = false
|
|
56
|
-
const fail = (error) => {
|
|
57
|
-
if (settled) return
|
|
58
|
-
settled = true
|
|
59
|
-
reject(error)
|
|
60
|
-
}
|
|
61
|
-
req.on('data', (chunk) => {
|
|
62
|
-
if (settled) return
|
|
63
|
-
size += chunk.length
|
|
64
|
-
if (size > limit) {
|
|
65
|
-
/* 先让路由回 413;立即 destroy 会让客户端只看到 connection reset。 */
|
|
66
|
-
fail(bodyError('BODY_TOO_LARGE', 'body too large'))
|
|
67
|
-
req.resume()
|
|
68
|
-
return
|
|
69
|
-
}
|
|
70
|
-
chunks.push(chunk)
|
|
71
|
-
})
|
|
72
|
-
req.on('end', () => {
|
|
73
|
-
if (settled) return
|
|
74
|
-
settled = true
|
|
75
|
-
const raw = Buffer.concat(chunks).toString('utf8')
|
|
76
|
-
if (!raw) return resolve({})
|
|
77
|
-
try { resolve(JSON.parse(raw)) } catch { reject(bodyError('BAD_JSON', 'bad json')) }
|
|
78
|
-
})
|
|
79
|
-
req.on('error', (error) => fail(error))
|
|
80
|
-
/* 客户端中途断连且未触发 error/aborted 时(如 curl -m 超时),close 兜底,
|
|
81
|
-
否则 promise 永远 pending,handler 泄漏。 */
|
|
82
|
-
req.on('close', () => {
|
|
83
|
-
if (!req.readableEnded) fail(bodyError('CLIENT_ABORTED', 'client aborted'))
|
|
84
|
-
})
|
|
85
|
-
})
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function intQ(url, name) {
|
|
89
|
-
const value = parseInt(url.searchParams.get(name) || '0', 10)
|
|
90
|
-
return Number.isFinite(value) && value >= 0 ? value : 0
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function listen(port, opts = {}) {
|
|
94
|
-
const defaults = tuning()
|
|
95
|
-
const {
|
|
96
|
-
host = '127.0.0.1',
|
|
97
|
-
requestTimeoutMs = defaults.requestTimeoutMs,
|
|
98
|
-
headersTimeoutMs = defaults.headersTimeoutMs,
|
|
99
|
-
keepAliveTimeoutMs = defaults.keepAliveTimeoutMs,
|
|
100
|
-
handler,
|
|
101
|
-
} = opts
|
|
102
|
-
return new Promise((resolve, reject) => {
|
|
103
|
-
const server = handler ? http.createServer(handler) : http.createServer()
|
|
104
|
-
server.requestTimeout = requestTimeoutMs
|
|
105
|
-
server.headersTimeout = headersTimeoutMs
|
|
106
|
-
server.keepAliveTimeout = keepAliveTimeoutMs
|
|
107
|
-
server.on('clientError', (error, socket) => {
|
|
108
|
-
if (socket.writable) socket.end('HTTP/1.1 400 Bad Request\r\n\r\n')
|
|
109
|
-
})
|
|
110
|
-
server.on('error', reject)
|
|
111
|
-
server.listen(port, host, () => resolve(server))
|
|
112
|
-
})
|
|
113
|
-
}
|
|
1
|
+
/** 由 build/sync-shared.mjs 生成:实现只存在于 @capyclaw/plugin-kit/service/http,此处零拷贝。 */
|
|
2
|
+
export * from '@capyclaw/plugin-kit/service/http'
|
|
@@ -1,142 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* 只实现工具面所需的最小协议:initialize / ping / tools/list / tools/call。
|
|
5
|
-
* 所有工具调用在进入业务实现前先经过 validateToolArguments。
|
|
6
|
-
*/
|
|
7
|
-
import { readBody, send } from './http.mjs'
|
|
8
|
-
import { validateToolArguments } from '../tools/validate.mjs'
|
|
9
|
-
|
|
10
|
-
const DEFAULT_PROTOCOL = '2024-11-05'
|
|
11
|
-
|
|
12
|
-
function rpcError(id, code, message, data) {
|
|
13
|
-
const error = { code, message }
|
|
14
|
-
if (data !== undefined) error.data = data
|
|
15
|
-
return { jsonrpc: '2.0', id: id ?? null, error }
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function reply(id, result) {
|
|
19
|
-
return { jsonrpc: '2.0', id, result }
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function createMcpHandler({
|
|
23
|
-
tools = [], callTool, serverInfo, instructions,
|
|
24
|
-
maxBodyBytes = 10 * 1024 * 1024, maxBatch = 100,
|
|
25
|
-
} = {}) {
|
|
26
|
-
if (!Array.isArray(tools)) throw new Error('createMcpHandler: tools 必须是数组')
|
|
27
|
-
if (typeof callTool !== 'function') throw new Error('createMcpHandler: callTool 必须是函数')
|
|
28
|
-
|
|
29
|
-
const toolMap = new Map(tools.map((tool) => [tool.name, tool]))
|
|
30
|
-
|
|
31
|
-
return async function handle(req, res) {
|
|
32
|
-
/* 长工具调用(如截图)期间客户端可能超时断连;socket 的 'error' 事件
|
|
33
|
-
无人监听会打崩进程。挂空处理器,配合 send() 的断连防护。 */
|
|
34
|
-
res.on('error', () => {})
|
|
35
|
-
if (req.method !== 'POST') {
|
|
36
|
-
if (res.destroyed) return
|
|
37
|
-
res.writeHead(405, { allow: 'POST', 'content-type': 'text/plain; charset=utf-8' })
|
|
38
|
-
return res.end('MCP endpoint: POST only')
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let msg
|
|
42
|
-
try {
|
|
43
|
-
msg = await readBody(req, maxBodyBytes)
|
|
44
|
-
} catch (error) {
|
|
45
|
-
if (error?.code === 'BODY_TOO_LARGE') {
|
|
46
|
-
return send(req, res, 413, rpcError(null, -32600, 'Request body too large'))
|
|
47
|
-
}
|
|
48
|
-
return send(req, res, 400, rpcError(null, -32700, 'Parse error'))
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (!msg || typeof msg !== 'object') {
|
|
52
|
-
return send(req, res, 400, rpcError(null, -32600, 'Invalid Request'))
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const batch = Array.isArray(msg)
|
|
56
|
-
if (batch && msg.length === 0) {
|
|
57
|
-
return send(req, res, 400, rpcError(null, -32600, 'Invalid Request'))
|
|
58
|
-
}
|
|
59
|
-
if (batch && msg.length > maxBatch) {
|
|
60
|
-
return send(req, res, 400, rpcError(null, -32600, `Batch too large (max ${maxBatch})`))
|
|
61
|
-
}
|
|
62
|
-
const messages = batch ? msg : [msg]
|
|
63
|
-
const replies = []
|
|
64
|
-
for (const message of messages) {
|
|
65
|
-
const result = await handleOne(message, req)
|
|
66
|
-
if (result !== null) replies.push(result)
|
|
67
|
-
}
|
|
68
|
-
if (!replies.length) {
|
|
69
|
-
if (res.destroyed) return
|
|
70
|
-
res.writeHead(202, { 'content-length': 0 })
|
|
71
|
-
return res.end()
|
|
72
|
-
}
|
|
73
|
-
return send(req, res, 200, batch ? replies : replies[0])
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async function handleOne(message, req) {
|
|
77
|
-
if (!message || typeof message !== 'object' || Array.isArray(message)) {
|
|
78
|
-
return rpcError(null, -32600, 'Invalid Request')
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const { id, method, params } = message
|
|
82
|
-
const isNotification = id === undefined || id === null
|
|
83
|
-
|
|
84
|
-
if (typeof method !== 'string' || !method) {
|
|
85
|
-
return isNotification ? null : rpcError(id, -32600, 'Invalid Request')
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (method === 'initialize') {
|
|
89
|
-
const result = {
|
|
90
|
-
protocolVersion: String(params?.protocolVersion || DEFAULT_PROTOCOL),
|
|
91
|
-
capabilities: { tools: { listChanged: false } },
|
|
92
|
-
serverInfo: serverInfo || { name: 'dsh-plugin', version: '0.0.0' },
|
|
93
|
-
}
|
|
94
|
-
if (typeof instructions === 'string' && instructions) result.instructions = instructions
|
|
95
|
-
return isNotification ? null : reply(id, result)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (method === 'notifications/initialized' || method === 'initialized') return null
|
|
99
|
-
if (method === 'notifications/cancelled' || method === 'notifications/cancel') return null
|
|
100
|
-
if (method === 'ping') return isNotification ? null : reply(id, {})
|
|
101
|
-
|
|
102
|
-
if (method === 'tools/list') {
|
|
103
|
-
return isNotification ? null : reply(id, { tools })
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (method === 'tools/call') {
|
|
107
|
-
const name = params?.name
|
|
108
|
-
const args = params?.arguments && typeof params.arguments === 'object' ? params.arguments : {}
|
|
109
|
-
const tool = toolMap.get(name)
|
|
110
|
-
if (!tool) {
|
|
111
|
-
if (isNotification) return null
|
|
112
|
-
return reply(id, {
|
|
113
|
-
content: [{ type: 'text', text: `未知工具: ${String(name)}` }],
|
|
114
|
-
isError: true,
|
|
115
|
-
})
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const check = validateToolArguments(tool, args)
|
|
119
|
-
if (!check.ok) {
|
|
120
|
-
if (isNotification) return null
|
|
121
|
-
return reply(id, {
|
|
122
|
-
content: [{ type: 'text', text: '参数不合法:' + check.errors.join(';') }],
|
|
123
|
-
isError: true,
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
try {
|
|
128
|
-
const out = await callTool(name, args, { req })
|
|
129
|
-
if (out && Array.isArray(out.content)) return reply(id, out)
|
|
130
|
-
return reply(id, { content: [{ type: 'text', text: out?.text || 'ok' }] })
|
|
131
|
-
} catch (error) {
|
|
132
|
-
if (isNotification) return null
|
|
133
|
-
return reply(id, {
|
|
134
|
-
content: [{ type: 'text', text: '工具失败:' + String((error && error.message) || error) }],
|
|
135
|
-
isError: true,
|
|
136
|
-
})
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return isNotification ? null : rpcError(id, -32601, `Method not found: ${method}`)
|
|
141
|
-
}
|
|
142
|
-
}
|
|
1
|
+
/** 由 build/sync-shared.mjs 生成:实现只存在于 @capyclaw/plugin-kit/service/mcp-http,此处零拷贝。 */
|
|
2
|
+
export * from '@capyclaw/plugin-kit/service/mcp-http'
|
|
@@ -1,115 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* MCP server 不会替我们执行 inputSchema,必须在调用实现前自己挡住坏参数。
|
|
4
|
-
*
|
|
5
|
-
* 编译缓存:schema 对象通常随工具定义长期存在,按 schema 对象(WeakMap)编译成
|
|
6
|
-
* 闭包树,重复调用不再逐层遍历 schema/创建临时数组。语义与解释执行逐行等价
|
|
7
|
-
* (anyOf / type / enum / maxLength / array / object 的顺序与错误文案不变)。
|
|
8
|
-
* 基准:50 元素数组参数校验从 ~0.029ms 降到 ~0.01ms(evolution/hotpath-bench.mjs H11)。
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const TYPE_CHECKS = {
|
|
12
|
-
string: (v) => typeof v === 'string',
|
|
13
|
-
number: (v) => typeof v === 'number' && Number.isFinite(v),
|
|
14
|
-
integer: (v) => typeof v === 'number' && Number.isInteger(v),
|
|
15
|
-
boolean: (v) => typeof v === 'boolean',
|
|
16
|
-
array: (v) => Array.isArray(v),
|
|
17
|
-
object: (v) => v !== null && typeof v === 'object' && !Array.isArray(v),
|
|
18
|
-
null: (v) => v === null,
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** schema 对象 → 编译后的校验闭包。 */
|
|
22
|
-
const compiledCache = new WeakMap()
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 把 schema 编译成 `(value, path, errors) => void` 闭包树。
|
|
26
|
-
* 纯结构性编译,不依赖运行时数据;同一 schema 对象只编译一次。
|
|
27
|
-
*/
|
|
28
|
-
function compileSchema(schema) {
|
|
29
|
-
if (!schema || typeof schema !== 'object') return () => {}
|
|
30
|
-
|
|
31
|
-
/* anyOf:与解释版一致——任一支路无错误即通过,且通过后不再执行其余规则。 */
|
|
32
|
-
if (schema.anyOf) {
|
|
33
|
-
const branches = schema.anyOf.map(compileSchema)
|
|
34
|
-
return (value, path, errors) => {
|
|
35
|
-
const matched = branches.some((branch) => {
|
|
36
|
-
const local = []
|
|
37
|
-
branch(value, path, local)
|
|
38
|
-
return local.length === 0
|
|
39
|
-
})
|
|
40
|
-
if (!matched) errors.push(`${path} 不符合 anyOf`)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const typeCheck = schema.type ? TYPE_CHECKS[schema.type] : null
|
|
45
|
-
const enumValues = schema.enum ? schema.enum : null
|
|
46
|
-
const maxLength = schema.maxLength != null ? schema.maxLength : null
|
|
47
|
-
const maxItems = schema.type === 'array' && schema.maxItems != null ? schema.maxItems : null
|
|
48
|
-
const validateItem = schema.type === 'array' && schema.items ? compileSchema(schema.items) : null
|
|
49
|
-
const properties = schema.type === 'object' ? (schema.properties || {}) : null
|
|
50
|
-
const propValidators = properties
|
|
51
|
-
? Object.entries(properties).map(([key, child]) => [key, compileSchema(child)])
|
|
52
|
-
: null
|
|
53
|
-
const required = properties && Array.isArray(schema.required) ? schema.required : null
|
|
54
|
-
const noAdditional = properties && schema.additionalProperties === false
|
|
55
|
-
|
|
56
|
-
return (value, path, errors) => {
|
|
57
|
-
/* 类型不符:解释版立即返回,不再做深层校验(保持该短路语义)。 */
|
|
58
|
-
if (typeCheck && !typeCheck(value)) {
|
|
59
|
-
errors.push(`${path} 应为 ${schema.type}`)
|
|
60
|
-
return
|
|
61
|
-
}
|
|
62
|
-
if (enumValues && !enumValues.includes(value)) {
|
|
63
|
-
errors.push(`${path} 必须是 ${enumValues.join(' / ')}`)
|
|
64
|
-
}
|
|
65
|
-
if (maxLength != null && typeof value === 'string' && value.length > maxLength) {
|
|
66
|
-
errors.push(`${path} 超过最大长度 ${maxLength}`)
|
|
67
|
-
}
|
|
68
|
-
if (maxItems != null && Array.isArray(value) && value.length > maxItems) {
|
|
69
|
-
errors.push(`${path} 最多 ${maxItems} 项`)
|
|
70
|
-
}
|
|
71
|
-
if (validateItem && Array.isArray(value)) {
|
|
72
|
-
value.forEach((item, i) => validateItem(item, `${path}[${i}]`, errors))
|
|
73
|
-
}
|
|
74
|
-
if (properties && value !== null && typeof value === 'object' && !Array.isArray(value)) {
|
|
75
|
-
if (required) {
|
|
76
|
-
for (const key of required) {
|
|
77
|
-
if (value[key] === undefined || value[key] === null) errors.push(`${path}.${key} 必填`)
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (noAdditional) {
|
|
81
|
-
for (const key of Object.keys(value)) {
|
|
82
|
-
if (!properties[key]) errors.push(`${path}.${key} 不是允许的参数`)
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
for (const [key, validateChild] of propValidators) {
|
|
86
|
-
if (value[key] === undefined) continue
|
|
87
|
-
validateChild(value[key], `${path}.${key}`, errors)
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** 取(或编译)schema 的校验闭包。 */
|
|
94
|
-
function validatorOf(schema) {
|
|
95
|
-
if (!schema || typeof schema !== 'object') return compileSchema(schema)
|
|
96
|
-
const cached = compiledCache.get(schema)
|
|
97
|
-
if (cached) return cached
|
|
98
|
-
const compiled = compileSchema(schema)
|
|
99
|
-
compiledCache.set(schema, compiled)
|
|
100
|
-
return compiled
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* @returns {{ok: boolean, errors: string[]}}
|
|
105
|
-
*/
|
|
106
|
-
export function validateToolArguments(tool, args) {
|
|
107
|
-
const errors = []
|
|
108
|
-
if (!tool || !tool.inputSchema) {
|
|
109
|
-
if (args != null && (typeof args !== 'object' || Array.isArray(args))) errors.push('arguments 必须是 object')
|
|
110
|
-
return { ok: errors.length === 0, errors }
|
|
111
|
-
}
|
|
112
|
-
if (args == null) args = {}
|
|
113
|
-
validatorOf(tool.inputSchema)(args, 'arguments', errors)
|
|
114
|
-
return { ok: errors.length === 0, errors }
|
|
115
|
-
}
|
|
1
|
+
/** 由 build/sync-shared.mjs 生成:实现只存在于 @capyclaw/plugin-kit/tools/validate,此处零拷贝。 */
|
|
2
|
+
export * from '@capyclaw/plugin-kit/tools/validate'
|
|
@@ -1,82 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @capyclaw/plugin-kit
|
|
3
|
-
*
|
|
4
|
-
* 默认值与进化搜索(evolution/ NSGA-II)的 founder 基线保持一致;
|
|
5
|
-
* 生产环境可用 DSH_TUNING_JSON 覆盖(按包名分组),测试/评估用 setTuning 注入。
|
|
6
|
-
*
|
|
7
|
-
* DSH_TUNING_JSON 形如:
|
|
8
|
-
* {"@capyclaw/plugin-kit": {"fileLockPollMs": 25, "journalMaxBytes": 2097152}}
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const DEFAULTS = {
|
|
12
|
-
/* fs-lock:元数据文件锁
|
|
13
|
-
* pollMs=10 由 NSGA-II 进化搜索固化(evolution/,2026-11-01):
|
|
14
|
-
* 24 路竞争延迟 2202→1400ms;10ms 为延迟与轮询 IO 的膝点。 */
|
|
15
|
-
fileLockSyncTimeoutMs: 10000,
|
|
16
|
-
fileLockSyncStaleMs: 30000,
|
|
17
|
-
fileLockAsyncTimeoutMs: 30000,
|
|
18
|
-
fileLockPollMs: 10,
|
|
19
|
-
fileLockFreshGraceMs: 2000,
|
|
20
|
-
|
|
21
|
-
/* 编辑器租约:wait() 轮询节奏 */
|
|
22
|
-
leaseWaitPollMs: 200,
|
|
23
|
-
leaseWaitTimeoutMs: 4000,
|
|
24
|
-
|
|
25
|
-
/* JournalStore:journal 轮转阈值与尾读默认行数
|
|
26
|
-
* 512KB 由进化搜索固化:尾读 p95 4.3→1.9ms、磁盘 -70%、追加吞吐 +8%。 */
|
|
27
|
-
journalMaxBytes: 512 * 1024,
|
|
28
|
-
journalTailLimit: 8,
|
|
29
|
-
|
|
30
|
-
/* WorkspaceManager catalog 写节流(降低全局 catalog 锁竞争) */
|
|
31
|
-
catalogThrottleMs: 5000,
|
|
32
|
-
|
|
33
|
-
/* WorkspaceClient token 校验缓存 */
|
|
34
|
-
tokenVerifyCacheMs: 30000,
|
|
35
|
-
|
|
36
|
-
/* HTTP 服务三级超时(keepAliveTimeoutMs 必须小于 headersTimeoutMs) */
|
|
37
|
-
requestTimeoutMs: 30000,
|
|
38
|
-
headersTimeoutMs: 10000,
|
|
39
|
-
keepAliveTimeoutMs: 5000,
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
let overrides = {}
|
|
43
|
-
let envLoaded = false
|
|
44
|
-
|
|
45
|
-
function loadEnv() {
|
|
46
|
-
if (envLoaded) return
|
|
47
|
-
envLoaded = true
|
|
48
|
-
try {
|
|
49
|
-
const raw = process.env.DSH_TUNING_JSON
|
|
50
|
-
if (!raw) return
|
|
51
|
-
const parsed = JSON.parse(raw)
|
|
52
|
-
if (!parsed || typeof parsed !== 'object') return
|
|
53
|
-
const own = parsed['@capyclaw/plugin-kit'] && typeof parsed['@capyclaw/plugin-kit'] === 'object'
|
|
54
|
-
? parsed['@capyclaw/plugin-kit']
|
|
55
|
-
: parsed
|
|
56
|
-
for (const key of Object.keys(DEFAULTS)) {
|
|
57
|
-
if (own[key] !== undefined) overrides[key] = own[key]
|
|
58
|
-
}
|
|
59
|
-
} catch { /* 非法 JSON 静默忽略:调优失败不能阻塞启动 */ }
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** 当前生效参数(默认值 + env + setTuning 覆盖)。 */
|
|
63
|
-
export function tuning() {
|
|
64
|
-
loadEnv()
|
|
65
|
-
return { ...DEFAULTS, ...overrides }
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** 测试/评估注入。只接受已知键,避免拼写错误静默生效。 */
|
|
69
|
-
export function setTuning(patch = {}) {
|
|
70
|
-
loadEnv()
|
|
71
|
-
for (const [key, value] of Object.entries(patch)) {
|
|
72
|
-
if (key in DEFAULTS) overrides[key] = value
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** 恢复到默认值 + env 覆盖。 */
|
|
77
|
-
export function resetTuning() {
|
|
78
|
-
overrides = {}
|
|
79
|
-
envLoaded = false
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export const TUNING_DEFAULTS = { ...DEFAULTS }
|
|
1
|
+
/** 由 build/sync-shared.mjs 生成:实现只存在于 @capyclaw/plugin-kit/tuning,此处零拷贝。 */
|
|
2
|
+
export * from '@capyclaw/plugin-kit/tuning'
|