@capyclaw/browser-suite 0.1.2 → 0.2.37
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 +304 -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 +223 -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 +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/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 +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/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 +166 -0
- package/node_modules/@capyclaw/tool-host/src/index.mjs +416 -0
- package/package.json +31 -14
- package/services.json +1 -21
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>演示表单 · 离线练习页</title>
|
|
7
|
+
<style>
|
|
8
|
+
body { font: 15px/1.7 "Segoe UI", "Microsoft YaHei", sans-serif; max-width: 640px; margin: 32px auto; padding: 0 16px; color: #222; }
|
|
9
|
+
fieldset { border: 1px solid #ccd3e0; border-radius: 10px; margin-bottom: 20px; }
|
|
10
|
+
legend { padding: 0 8px; font-weight: 600; }
|
|
11
|
+
label { display: block; margin: 10px 0 4px; font-weight: 600; }
|
|
12
|
+
input[type="text"], input[type="password"], select, textarea {
|
|
13
|
+
width: 100%; padding: 8px 10px; border: 1px solid #ccd3e0; border-radius: 6px; font: inherit;
|
|
14
|
+
}
|
|
15
|
+
.row { display: flex; gap: 16px; align-items: center; margin: 10px 0; }
|
|
16
|
+
button { padding: 9px 18px; border-radius: 6px; border: 1px solid #3a6ee8; background: #3a6ee8; color: #fff; cursor: pointer; font-size: 15px; }
|
|
17
|
+
button.ghost { background: #fff; color: #3a6ee8; }
|
|
18
|
+
#results { background: #f4f7fd; border-radius: 8px; padding: 10px 14px; min-height: 48px; }
|
|
19
|
+
#results li { margin: 4px 0; }
|
|
20
|
+
#count { font-weight: 700; }
|
|
21
|
+
input[type="range"] { width: 60%; vertical-align: middle; }
|
|
22
|
+
.fake-btn { display: inline-block; padding: 9px 18px; border-radius: 6px; background: #eef2fc; color: #27448f; border: 1px dashed #7f9ce0; cursor: pointer; user-select: none; }
|
|
23
|
+
</style>
|
|
24
|
+
</head>
|
|
25
|
+
<body>
|
|
26
|
+
<h1>演示表单</h1>
|
|
27
|
+
<p>内置离线练习页:不依赖外网,供 AI 工具链(browser_navigate → browser_snapshot → browser_fill / browser_select / browser_click)演示与 e2e 冒烟使用。</p>
|
|
28
|
+
|
|
29
|
+
<form id="demo-form">
|
|
30
|
+
<fieldset>
|
|
31
|
+
<legend>注册信息</legend>
|
|
32
|
+
<label for="username">用户名</label>
|
|
33
|
+
<input type="text" id="username" name="username" placeholder="请输入用户名">
|
|
34
|
+
|
|
35
|
+
<label for="password">密码</label>
|
|
36
|
+
<input type="password" id="password" name="password" placeholder="密码会被快照掩码显示">
|
|
37
|
+
|
|
38
|
+
<label for="city">所在城市</label>
|
|
39
|
+
<select id="city" name="city">
|
|
40
|
+
<option value="">— 请选择 —</option>
|
|
41
|
+
<option value="beijing">北京</option>
|
|
42
|
+
<option value="shanghai">上海</option>
|
|
43
|
+
<option value="shenzhen">深圳</option>
|
|
44
|
+
</select>
|
|
45
|
+
|
|
46
|
+
<div class="row">
|
|
47
|
+
<label style="margin:0"><input type="checkbox" id="agree" name="agree"> 我已阅读并同意服务条款</label>
|
|
48
|
+
</div>
|
|
49
|
+
|
|
50
|
+
<label for="note">备注</label>
|
|
51
|
+
<textarea id="note" name="note" rows="3" placeholder="选填"></textarea>
|
|
52
|
+
|
|
53
|
+
<div class="row">
|
|
54
|
+
<button type="submit" id="submit">提交注册</button>
|
|
55
|
+
<button type="button" id="counter" class="ghost">点我计数:<span id="count">0</span></button>
|
|
56
|
+
</div>
|
|
57
|
+
</fieldset>
|
|
58
|
+
|
|
59
|
+
<fieldset>
|
|
60
|
+
<legend>进阶:拖拽 / 无 role 按钮</legend>
|
|
61
|
+
<label for="slider">滑块(用 browser_drag 拖到最右)</label>
|
|
62
|
+
<div class="row">
|
|
63
|
+
<input type="range" id="slider" name="slider" min="0" max="100" value="0" step="1">
|
|
64
|
+
<output id="slider-out">0</output>
|
|
65
|
+
</div>
|
|
66
|
+
|
|
67
|
+
<label>下面这个「下一步」是普通 div,没有 role/tabindex,快照里不会有 ref</label>
|
|
68
|
+
<div class="row">
|
|
69
|
+
<div id="fake-next" class="fake-btn">下一步</div>
|
|
70
|
+
</div>
|
|
71
|
+
</fieldset>
|
|
72
|
+
</form>
|
|
73
|
+
|
|
74
|
+
<h2>操作结果</h2>
|
|
75
|
+
<ul id="results" role="status">
|
|
76
|
+
<li>(还没有操作)</li>
|
|
77
|
+
</ul>
|
|
78
|
+
|
|
79
|
+
<script>
|
|
80
|
+
var results = document.getElementById('results')
|
|
81
|
+
var count = 0
|
|
82
|
+
function log(text) {
|
|
83
|
+
if (results.firstChild && results.firstChild.textContent === '(还没有操作)') results.innerHTML = ''
|
|
84
|
+
var li = document.createElement('li')
|
|
85
|
+
li.textContent = new Date().toLocaleTimeString() + ' — ' + text
|
|
86
|
+
results.insertBefore(li, results.firstChild)
|
|
87
|
+
}
|
|
88
|
+
document.getElementById('demo-form').addEventListener('submit', function (e) {
|
|
89
|
+
e.preventDefault()
|
|
90
|
+
log('已提交注册:username=' + (document.getElementById('username').value || '(空)') +
|
|
91
|
+
',city=' + (document.getElementById('city').value || '(未选)') +
|
|
92
|
+
',agree=' + (document.getElementById('agree').checked ? 'on' : 'off'))
|
|
93
|
+
})
|
|
94
|
+
document.getElementById('counter').addEventListener('click', function () {
|
|
95
|
+
count += 1
|
|
96
|
+
document.getElementById('count').textContent = count
|
|
97
|
+
log('计数按钮第 ' + count + ' 次被点击')
|
|
98
|
+
})
|
|
99
|
+
var slider = document.getElementById('slider')
|
|
100
|
+
var sliderOut = document.getElementById('slider-out')
|
|
101
|
+
slider.addEventListener('input', function () {
|
|
102
|
+
sliderOut.textContent = slider.value
|
|
103
|
+
})
|
|
104
|
+
slider.addEventListener('change', function () {
|
|
105
|
+
log('滑块拖到 ' + slider.value + '(' + (Number(slider.value) >= 100 ? '到最右' : '未到最右') + ')')
|
|
106
|
+
})
|
|
107
|
+
document.getElementById('fake-next').addEventListener('click', function () {
|
|
108
|
+
log('「下一步」(div 假按钮)被点击')
|
|
109
|
+
})
|
|
110
|
+
</script>
|
|
111
|
+
</body>
|
|
112
|
+
</html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { name, apply } from '../server/embedded-host.mjs'
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capyclaw/browser-workbench",
|
|
3
|
+
"version": "0.1.18",
|
|
4
|
+
"description": "浏览器操控工作台运行时:18 个 browser_* MCP 工具(导航/快照/点击/填写/按键/下拉/上传/滚动/批量连做/拖拽/标签页/截图)+ Playwright 引擎(有头可见、登录态持久化)+ 可视化工作台。",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./plugin.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./plugin.mjs",
|
|
9
|
+
"./package.json": "./package.json"
|
|
10
|
+
},
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=18",
|
|
13
|
+
"dsh": "^0.2.0-rc.2"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"dsh": {
|
|
19
|
+
"member": true,
|
|
20
|
+
"category": "service",
|
|
21
|
+
"platform": "both",
|
|
22
|
+
"capabilities": {
|
|
23
|
+
"source": "server/tools/capabilities",
|
|
24
|
+
"manifest": "capabilities.json"
|
|
25
|
+
},
|
|
26
|
+
"requires": {
|
|
27
|
+
"capabilities": {
|
|
28
|
+
"os.proc": "^1.0.0"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"meta": {
|
|
33
|
+
"title": "浏览器操控工作台运行时",
|
|
34
|
+
"description": "AI 直接操控浏览器完成互联网上的点击/打字工作:18 个 browser_* 工具 + 可视化工作台(挂在 dsh 的 /capyclaw/browser,端口由 dsh 决定)"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"plugin.mjs",
|
|
38
|
+
"lib/",
|
|
39
|
+
"server/",
|
|
40
|
+
"ui/",
|
|
41
|
+
"demo/",
|
|
42
|
+
"!server/.relay-instance.lock",
|
|
43
|
+
"contract/",
|
|
44
|
+
"README.md"
|
|
45
|
+
],
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"scripts": {},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@capyclaw/asset-service": "^0.1.4",
|
|
50
|
+
"@capyclaw/document-workbench": "^0.2.2",
|
|
51
|
+
"@capyclaw/foundation": "^0.1.9",
|
|
52
|
+
"@capyclaw/plugin-kit": "^0.2.6",
|
|
53
|
+
"@capyclaw/service-host": "^0.1.5",
|
|
54
|
+
"@capyclaw/tool-host": "^0.2.0",
|
|
55
|
+
"playwright": "^1.64.0"
|
|
56
|
+
},
|
|
57
|
+
"author": {
|
|
58
|
+
"name": "CapyClaw",
|
|
59
|
+
"url": "https://github.com/capyclaw",
|
|
60
|
+
"email": "support@capyclaw.dev"
|
|
61
|
+
},
|
|
62
|
+
"repository": {
|
|
63
|
+
"type": "git",
|
|
64
|
+
"url": "git+https://github.com/Maple496/capyclaw.git",
|
|
65
|
+
"directory": "A/projects/browser/artifacts/plugin/capyclaw-browser-workbench"
|
|
66
|
+
},
|
|
67
|
+
"bugs": {
|
|
68
|
+
"url": "https://github.com/Maple496/capyclaw/issues"
|
|
69
|
+
},
|
|
70
|
+
"homepage": "https://github.com/Maple496/capyclaw/tree/main/A/projects/browser/artifacts/plugin/capyclaw-browser-workbench#readme"
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { name, inject, apply } from './server/embedded-host.mjs'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** 桥的稳定常量(relay/routes/tests 共用,避免循环 import)。 */
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_PORT = 39315
|
|
4
|
+
|
|
5
|
+
/** 工作台静态页(白名单,杜绝路径穿越;相对 ui/)。 */
|
|
6
|
+
export const WORKBENCH_FILES = {
|
|
7
|
+
'/': ['index.html', 'text/html; charset=utf-8'],
|
|
8
|
+
'/index.html': ['index.html', 'text/html; charset=utf-8'],
|
|
9
|
+
'/app.js': ['app.js', 'text/javascript; charset=utf-8'],
|
|
10
|
+
'/style.css': ['style.css', 'text/css; charset=utf-8'],
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** 内置离线演示页(相对 demo/)。 */
|
|
14
|
+
export const DEMO_FILES = {
|
|
15
|
+
'/demo/form.html': ['form.html', 'text/html; charset=utf-8'],
|
|
16
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 契约快照校验:workbench 与同目录 skill 包的 contract/browser-contract.json
|
|
3
|
+
* major 不一致时,MCP 工具调用被拒绝(browser_capabilities 除外,便于诊断)。
|
|
4
|
+
*
|
|
5
|
+
* 开发态(plugin/)和发布态里 skill 包都是 workbench 的兄弟目录。
|
|
6
|
+
* 机制与 canvas-bridge 的 contract-snapshots 相同,只换前缀与契约文件名。
|
|
7
|
+
*/
|
|
8
|
+
import fs from 'node:fs'
|
|
9
|
+
import path from 'node:path'
|
|
10
|
+
|
|
11
|
+
const SKILL_PREFIX = 'capyclaw-browser-skill-'
|
|
12
|
+
const SCOPED_SKILL_PREFIX = 'browser-skill-'
|
|
13
|
+
const CONTRACT_FILE = 'browser-contract.json'
|
|
14
|
+
const SCOPE_DIR = '@capyclaw'
|
|
15
|
+
|
|
16
|
+
function majorOf(version) {
|
|
17
|
+
return String(version || '').split('.')[0]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function inspectContractSnapshots(packageDir, contractVersion) {
|
|
21
|
+
const expectedMajor = majorOf(contractVersion)
|
|
22
|
+
const report = { expected: contractVersion || '', checked: 0, ok: true, mismatched: [] }
|
|
23
|
+
const parent = path.dirname(packageDir)
|
|
24
|
+
|
|
25
|
+
const candidates = []
|
|
26
|
+
let entries
|
|
27
|
+
try {
|
|
28
|
+
entries = fs.readdirSync(parent, { withFileTypes: true })
|
|
29
|
+
} catch {
|
|
30
|
+
return report
|
|
31
|
+
}
|
|
32
|
+
const inScope = path.basename(parent) === SCOPE_DIR
|
|
33
|
+
for (const entry of entries) {
|
|
34
|
+
if (entry.name.startsWith(SKILL_PREFIX)) {
|
|
35
|
+
candidates.push({ name: entry.name, dir: path.join(parent, entry.name) })
|
|
36
|
+
} else if (inScope && entry.name.startsWith(SCOPED_SKILL_PREFIX)) {
|
|
37
|
+
candidates.push({ name: entry.name, dir: path.join(parent, entry.name) })
|
|
38
|
+
} else if (entry.name === SCOPE_DIR) {
|
|
39
|
+
let scoped
|
|
40
|
+
try {
|
|
41
|
+
scoped = fs.readdirSync(path.join(parent, entry.name), { withFileTypes: true })
|
|
42
|
+
} catch { continue }
|
|
43
|
+
for (const s of scoped) {
|
|
44
|
+
if (s.name.startsWith(SCOPED_SKILL_PREFIX)) {
|
|
45
|
+
candidates.push({ name: `${SCOPE_DIR}/${s.name}`, dir: path.join(parent, entry.name, s.name) })
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
for (const { name, dir } of candidates) {
|
|
52
|
+
try {
|
|
53
|
+
if (!fs.statSync(dir).isDirectory()) continue
|
|
54
|
+
} catch {
|
|
55
|
+
continue
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
report.checked++
|
|
59
|
+
const file = path.join(dir, 'contract', CONTRACT_FILE)
|
|
60
|
+
let snapshot = null
|
|
61
|
+
try {
|
|
62
|
+
snapshot = JSON.parse(fs.readFileSync(file, 'utf8'))
|
|
63
|
+
} catch {
|
|
64
|
+
report.mismatched.push({ package: name, expected: contractVersion, actual: null })
|
|
65
|
+
continue
|
|
66
|
+
}
|
|
67
|
+
const actualMajor = majorOf(snapshot.contractVersion)
|
|
68
|
+
if (actualMajor !== expectedMajor) {
|
|
69
|
+
report.mismatched.push({ package: name, expected: contractVersion, actual: snapshot.contractVersion || null })
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
report.ok = report.mismatched.length === 0
|
|
74
|
+
return report
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function describeMismatch(report) {
|
|
78
|
+
return report.mismatched
|
|
79
|
+
.map((item) => `${item.package}(snapshot=${item.actual || 'missing'}, runtime=${item.expected})`)
|
|
80
|
+
.join(';')
|
|
81
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP 工具契约的唯一真源(版本 + 报告格式)。
|
|
3
|
+
*
|
|
4
|
+
* 工具/能力清单由 capabilities → registry 派生;报告结构来自 @capyclaw/tool-host。
|
|
5
|
+
* 新增能力只改 tools/capabilities/index.mjs。
|
|
6
|
+
*/
|
|
7
|
+
import { createCapabilityReport } from './shared/tool-host.mjs'
|
|
8
|
+
|
|
9
|
+
/** 工具契约版本:工具名、参数、返回结构发生不兼容变化时升 major。 */
|
|
10
|
+
export const CONTRACT_VERSION = '1.3.0'
|
|
11
|
+
|
|
12
|
+
/** 工作台包版本。 */
|
|
13
|
+
export const PACKAGE_VERSION = '0.1.18'
|
|
14
|
+
|
|
15
|
+
/** 生成模型可读的能力报告。 */
|
|
16
|
+
export function capabilityReport(args, workbenchUrl = '', runtime = {}) {
|
|
17
|
+
return createCapabilityReport({
|
|
18
|
+
...args,
|
|
19
|
+
contractVersion: CONTRACT_VERSION,
|
|
20
|
+
packageVersion: PACKAGE_VERSION,
|
|
21
|
+
editorUrl: workbenchUrl,
|
|
22
|
+
runtime,
|
|
23
|
+
})
|
|
24
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @capyclaw/browser-workbench 宿主插件(cordis 入口,loader 经包名加载本模块)。
|
|
3
|
+
*
|
|
4
|
+
* 承载形态由**基建**决定,业务插件不选端口:
|
|
5
|
+
* - 有 ctx.webServer(生产):挂到宿主 HTTP 路由前缀下,不监听任何端口,
|
|
6
|
+
* 生命周期随 DSH 启停;前缀由基建给(默认 /capyclaw/browser)。
|
|
7
|
+
* - 没有 webServer(开发/测试):才退回独立 loopback 端口。
|
|
8
|
+
* 工具面也在这里注册:relay 的工具注册表直接进 ctx.tools,不再经过 MCP 桥。
|
|
9
|
+
*
|
|
10
|
+
* 与 ppt/canvas 的公共 host 模板不同,本文件为手写精简版:浏览器工作台没有
|
|
11
|
+
* 文档 store/journal/workspace 依赖,装配面只有公共服务契约 + 引擎透传配置。
|
|
12
|
+
*/
|
|
13
|
+
import os from 'node:os'
|
|
14
|
+
import path from 'node:path'
|
|
15
|
+
import fs from 'node:fs'
|
|
16
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
17
|
+
import { assertServiceApi } from './shared/kit/service/api.mjs'
|
|
18
|
+
|
|
19
|
+
export const name = 'browser-workbench-host'
|
|
20
|
+
/* 依赖倒置:业务等的是「宿主给的 HTTP 路由」,不是端口。 */
|
|
21
|
+
export const inject = ['webServer']
|
|
22
|
+
|
|
23
|
+
function safeGet(ctx, serviceName) {
|
|
24
|
+
// 原生插件里 ctx.get(name) 只对已 inject 的服务放行;可选依赖用 reflect.get
|
|
25
|
+
// 才不会因为「没在 inject 列表里」被拒绝(core 也是这么取依赖的)。
|
|
26
|
+
try {
|
|
27
|
+
if (ctx && ctx.reflect && typeof ctx.reflect.get === 'function') return ctx.reflect.get(serviceName)
|
|
28
|
+
return ctx?.get ? ctx.get(serviceName) : null
|
|
29
|
+
} catch { return null }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function requireApi(service, name) {
|
|
33
|
+
if (service) assertServiceApi(service, { name, major: 1 })
|
|
34
|
+
return service
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 基建依赖(@capyclaw/portal)不保证在工作台包的依赖树里,按约定位置兜底解析。 */
|
|
38
|
+
async function loadPortal() {
|
|
39
|
+
try {
|
|
40
|
+
return await import('@capyclaw/portal')
|
|
41
|
+
} catch { /* 落到 profile 扫描 */ }
|
|
42
|
+
const home = process.env.DSH_HOME || path.join(os.homedir(), '.dsh')
|
|
43
|
+
const roots = []
|
|
44
|
+
try {
|
|
45
|
+
for (const dir of fs.readdirSync(path.join(home, 'profiles'))) roots.push(path.join(home, 'profiles', dir, 'node_modules'))
|
|
46
|
+
} catch { /* 没有 profiles 目录 */ }
|
|
47
|
+
for (const root of roots) {
|
|
48
|
+
for (const scope of ['core', 'ppt-suite', 'canvas-suite', 'browser-suite']) {
|
|
49
|
+
const file = path.join(root, '@capyclaw', scope, 'node_modules', '@capyclaw', 'portal', 'lib', 'index.mjs')
|
|
50
|
+
if (!fs.existsSync(file)) continue
|
|
51
|
+
try {
|
|
52
|
+
return await import(pathToFileURL(file).href)
|
|
53
|
+
} catch { /* 试下一个 */ }
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return null
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 激活失败的完整栈只留在宿主日志里,插件管理器/Web UI 只显示第一行;
|
|
61
|
+
* 这里把栈落到 hostDir,下次「1 entry did not activate」时能直接看到根因。
|
|
62
|
+
*/
|
|
63
|
+
export async function apply(ctx, config) {
|
|
64
|
+
try {
|
|
65
|
+
return await activate(ctx, config)
|
|
66
|
+
} catch (error) {
|
|
67
|
+
try {
|
|
68
|
+
const fallbackDir = path.join(os.homedir(), '.dsh-browser-bridge')
|
|
69
|
+
const hostDir = (config && config.hostDir) || process.env.BROWSER_BRIDGE_HOME || fallbackDir
|
|
70
|
+
fs.mkdirSync(hostDir, { recursive: true })
|
|
71
|
+
fs.appendFileSync(
|
|
72
|
+
path.join(hostDir, 'activate-error.log'),
|
|
73
|
+
`[${new Date().toISOString()}] ${(error && error.stack) || error}\n`,
|
|
74
|
+
)
|
|
75
|
+
} catch { /* 诊断写盘失败不能覆盖真正的激活错误 */ }
|
|
76
|
+
throw error
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function activate(ctx, config) {
|
|
81
|
+
const packageDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
82
|
+
const { startRelay } = await import('./relay.mjs')
|
|
83
|
+
const hostDir = (config && config.hostDir)
|
|
84
|
+
|| process.env.BROWSER_BRIDGE_HOME
|
|
85
|
+
|| path.join(os.homedir(), '.dsh-browser-bridge')
|
|
86
|
+
/* 公共插件 API 契约:存在则校验 major,避免静默不兼容。 */
|
|
87
|
+
const serviceHost = requireApi(safeGet(ctx, 'serviceHost'), 'serviceHost')
|
|
88
|
+
const toolHost = requireApi(safeGet(ctx, 'toolHost'), 'toolHost')
|
|
89
|
+
const assetService = requireApi(safeGet(ctx, 'assets'), 'assets')
|
|
90
|
+
let assetStore = null
|
|
91
|
+
if (assetService?.createFileStore) {
|
|
92
|
+
assetStore = assetService.createFileStore({ dir: path.join(hostDir, 'assets') })
|
|
93
|
+
}
|
|
94
|
+
/* cordis 配置透传引擎项(headless / allowEvaluate / channel / 超时…),
|
|
95
|
+
* 环境变量(DSH_BROWSER_*)与默认值由 relay 内 resolveEngineConfig 兜底。 */
|
|
96
|
+
const engineConfig = (config && config.engine) || null
|
|
97
|
+
|
|
98
|
+
const webServer = safeGet(ctx, 'webServer')
|
|
99
|
+
const mountPath = (config && config.mountPath) || '/capyclaw/browser'
|
|
100
|
+
const relayOptions = {
|
|
101
|
+
packageDir,
|
|
102
|
+
hostDir,
|
|
103
|
+
assetStore,
|
|
104
|
+
assetService,
|
|
105
|
+
engineConfig,
|
|
106
|
+
serviceHost,
|
|
107
|
+
toolHost,
|
|
108
|
+
strictPort: config?.strictPort != null ? !!config.strictPort : false,
|
|
109
|
+
allowReuse: config?.allowReuse != null ? !!config.allowReuse : true,
|
|
110
|
+
/* F3 会话模式锁的底座懒解析器(works.db 单一真源);底座缺席时守卫自动跳过。 */
|
|
111
|
+
getWorkStore: () => safeGet(ctx, 'workStore'),
|
|
112
|
+
}
|
|
113
|
+
if (webServer) {
|
|
114
|
+
relayOptions.webServer = webServer
|
|
115
|
+
relayOptions.mountPrefix = mountPath
|
|
116
|
+
} else {
|
|
117
|
+
/* 仅开发/测试:没有宿主路由时才自己听一个 loopback 端口。
|
|
118
|
+
端口写 0 = 交给操作系统分配;真实地址由 relay listen 之后给出。 */
|
|
119
|
+
relayOptions.port = (config && Number(config.port)) || 0
|
|
120
|
+
}
|
|
121
|
+
const relay = await startRelay(relayOptions)
|
|
122
|
+
|
|
123
|
+
/* 工具面:注册进宿主原生工具注册表,名字保持 browser_*(不再有 mcp__browser__ 前缀)。
|
|
124
|
+
DSH 的 ToolDefinition 是 name / description / parameters(JSON Schema) /
|
|
125
|
+
output { schema, render } / execute;缺 output 时 register 直接抛 TypeError。
|
|
126
|
+
逐个 try,一个工具不被支持时不影响其余工具。 */
|
|
127
|
+
const disposers = []
|
|
128
|
+
const registry = relay.tools
|
|
129
|
+
const tools = safeGet(ctx, 'tools')
|
|
130
|
+
const toolState = { registered: [], errors: [], hasTools: !!(tools && typeof tools.register === 'function') }
|
|
131
|
+
const OUTPUT_SCHEMA = { type: 'object', additionalProperties: true }
|
|
132
|
+
|
|
133
|
+
function toolText(value) {
|
|
134
|
+
if (value == null) return 'ok'
|
|
135
|
+
if (typeof value === 'string') return value
|
|
136
|
+
if (Array.isArray(value && value.content)) {
|
|
137
|
+
const parts = value.content
|
|
138
|
+
.filter((part) => part && part.type === 'text' && typeof part.text === 'string')
|
|
139
|
+
.map((part) => part.text)
|
|
140
|
+
if (parts.length) return parts.join('\n')
|
|
141
|
+
}
|
|
142
|
+
if (value && typeof value.text === 'string') return value.text
|
|
143
|
+
try { return JSON.stringify(value, null, 2) } catch { return String(value) }
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (registry && Array.isArray(registry.TOOLS) && toolState.hasTools) {
|
|
147
|
+
for (const tool of registry.TOOLS) {
|
|
148
|
+
try {
|
|
149
|
+
const dispose = tools.register({
|
|
150
|
+
name: tool.name,
|
|
151
|
+
description: tool.description,
|
|
152
|
+
parameters: tool.inputSchema,
|
|
153
|
+
output: {
|
|
154
|
+
schema: OUTPUT_SCHEMA,
|
|
155
|
+
render: (_args, value) => [{ type: 'text', text: toolText(value) }],
|
|
156
|
+
},
|
|
157
|
+
/* 第二个参数是 DSH 的 exec(含 exec.agent.session.id):工具靠它知道是哪个
|
|
158
|
+
* 会话在调用,多会话工作台才能把读写落到调用者自己那份文档上。 */
|
|
159
|
+
execute: async (args, exec) => registry.TOOL_IMPL[tool.name](args || {}, exec),
|
|
160
|
+
})
|
|
161
|
+
if (typeof dispose === 'function') disposers.push(dispose)
|
|
162
|
+
toolState.registered.push(tool.name)
|
|
163
|
+
} catch (error) {
|
|
164
|
+
toolState.errors.push(`${tool.name}: ${error && error.message ? error.message : String(error)}`)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (toolState.errors.length) console.warn(`[browser-workbench] 工具注册失败 ${toolState.errors.length} 个: ${toolState.errors.join(' | ')}`)
|
|
168
|
+
} else if (registry) {
|
|
169
|
+
console.log('[browser-workbench] 提示:宿主没有 tools 服务,工具面未注册(只提供工作台页面)')
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/* 能力描述符注册(互联标准 v0.3 单一真源):把工具面带 surface 注册进 tool-host
|
|
173
|
+
* 描述符注册表——展示墙 / 编排器 / AI 读的是同一个注册表,注册了带 surface 的能力
|
|
174
|
+
* 必然自动上墙,卸载即下墙。老宿主没有描述符面时优雅降级,不影响工具面与页面。 */
|
|
175
|
+
const descriptorState = { registered: 0, available: !!(toolHost && typeof toolHost.registerCapabilityDescriptor === 'function') }
|
|
176
|
+
if (registry && Array.isArray(registry.TOOLS) && descriptorState.available) {
|
|
177
|
+
const surface = { standalone: true, embeddable: true, embedPath: mountPath, title: (config && config.title) || '浏览器工作台' }
|
|
178
|
+
for (const tool of registry.TOOLS) {
|
|
179
|
+
try {
|
|
180
|
+
toolHost.registerCapabilityDescriptor({
|
|
181
|
+
name: tool.name,
|
|
182
|
+
suite: 'browser',
|
|
183
|
+
capability: tool.name,
|
|
184
|
+
tool: tool.name,
|
|
185
|
+
controlMode: 'browser',
|
|
186
|
+
kind: tool.kind || 'write',
|
|
187
|
+
produces: [],
|
|
188
|
+
consumes: [],
|
|
189
|
+
surface,
|
|
190
|
+
}, { baseUrl: relay.url })
|
|
191
|
+
descriptorState.registered += 1
|
|
192
|
+
disposers.push(() => { try { toolHost.unregisterCapabilityDescriptor(tool.name) } catch { /* 忽略 */ } })
|
|
193
|
+
} catch (error) {
|
|
194
|
+
console.warn(`[browser-workbench] 描述符注册失败 ${tool.name}: ${error && error.message ? error.message : String(error)}`)
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/* 自检端点:GET <前缀>/__host__ 直接看工具注册结果,不用翻宿主日志。 */
|
|
200
|
+
if (webServer && typeof webServer.register === 'function') {
|
|
201
|
+
const dispose = webServer.register({
|
|
202
|
+
kind: 'exact',
|
|
203
|
+
path: `${mountPath}/__host__`,
|
|
204
|
+
handler: (req, res) => {
|
|
205
|
+
const body = JSON.stringify({
|
|
206
|
+
workbench: 'browser',
|
|
207
|
+
mode: relay.mode,
|
|
208
|
+
url: relay.url,
|
|
209
|
+
editorUrl: relay.editorUrl,
|
|
210
|
+
mountPath,
|
|
211
|
+
tools: toolState,
|
|
212
|
+
descriptors: descriptorState,
|
|
213
|
+
}, null, 2)
|
|
214
|
+
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
215
|
+
res.end(body)
|
|
216
|
+
},
|
|
217
|
+
})
|
|
218
|
+
if (typeof dispose === 'function') disposers.push(dispose)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/* 活动台账:embedded 形态没有端口,记 url 即可。台账只供主区舞台
|
|
222
|
+
* (@capyclaw/portal-hud)补标题/最近使用时间,开不开窗由舞台的内容闸决定。 */
|
|
223
|
+
try {
|
|
224
|
+
const portal = await loadPortal()
|
|
225
|
+
if (portal && typeof portal.recordActivity === 'function') {
|
|
226
|
+
portal.recordActivity({
|
|
227
|
+
id: 'browser-workbench',
|
|
228
|
+
url: relay.editorUrl,
|
|
229
|
+
title: (config && config.title) || '浏览器工作台',
|
|
230
|
+
kind: 'service',
|
|
231
|
+
})
|
|
232
|
+
}
|
|
233
|
+
} catch { /* 台账失败不影响服务 */ }
|
|
234
|
+
|
|
235
|
+
console.log(relay.reused
|
|
236
|
+
? `[browser-workbench] 复用已运行的桥: ${relay.url}`
|
|
237
|
+
: `[browser-workbench] 桥已就绪: ${relay.url}`)
|
|
238
|
+
console.log(`[browser-workbench] 工作台: ${relay.editorUrl}(${relay.mode === 'embedded' ? '挂在宿主路由,无端口' : '独立端口'})`)
|
|
239
|
+
|
|
240
|
+
return async () => {
|
|
241
|
+
for (const dispose of disposers) {
|
|
242
|
+
try { dispose() } catch { /* 忽略 */ }
|
|
243
|
+
}
|
|
244
|
+
await relay.stop()
|
|
245
|
+
console.log('[browser-workbench] 桥已停止')
|
|
246
|
+
}
|
|
247
|
+
}
|