@capyclaw/browser-suite 0.2.38 → 0.2.39
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/composition.lock.json +23 -23
- package/contract/browser-contract.json +1 -1
- package/dsh-suite.json +26 -16
- package/node_modules/@capyclaw/asset-service/dsh-suite.json +1 -1
- package/node_modules/@capyclaw/asset-service/package.json +1 -1
- package/node_modules/@capyclaw/asset-service/src/index.mjs +4 -3
- package/node_modules/@capyclaw/browser-skill-api/contract/browser-contract.json +1 -1
- package/node_modules/@capyclaw/browser-skill-api/package.json +1 -1
- package/node_modules/@capyclaw/browser-skill-api/skills/browser-api/references/tool-contract.md +1 -1
- package/node_modules/@capyclaw/browser-skill-browser/contract/browser-contract.json +1 -1
- package/node_modules/@capyclaw/browser-skill-browser/package.json +1 -1
- package/node_modules/@capyclaw/browser-skill-ops/contract/browser-contract.json +1 -1
- package/node_modules/@capyclaw/browser-skill-ops/package.json +1 -1
- package/node_modules/@capyclaw/browser-workbench/contract/browser-contract.json +1 -1
- package/node_modules/@capyclaw/browser-workbench/package.json +7 -7
- package/node_modules/@capyclaw/browser-workbench/plugin.mjs +13 -1
- package/node_modules/@capyclaw/browser-workbench/server/activate-log.mjs +66 -0
- package/node_modules/@capyclaw/browser-workbench/server/contract.mjs +1 -1
- package/node_modules/@capyclaw/browser-workbench/server/embedded-host.mjs +13 -1
- package/node_modules/@capyclaw/browser-workbench/server/engine.mjs +11 -4
- package/node_modules/@capyclaw/browser-workbench/server/routes/api.mjs +2 -2
- package/node_modules/@capyclaw/browser-workbench/server/shared/SHARED_MANIFEST.json +4 -4
- package/node_modules/@capyclaw/browser-workbench/ui/app.js +87 -10
- package/node_modules/@capyclaw/document-workbench/package.json +6 -3
- package/node_modules/@capyclaw/document-workbench/src/client/index.mjs +56 -3
- package/node_modules/@capyclaw/document-workbench/src/client/visibility.mjs +112 -0
- package/node_modules/@capyclaw/document-workbench/src/model/manifest.mjs +6 -4
- package/node_modules/@capyclaw/document-workbench/src/model/ops.mjs +7 -2
- package/node_modules/@capyclaw/document-workbench/src/session/index.mjs +8 -0
- package/node_modules/@capyclaw/document-workbench/src/store/file-backend.mjs +17 -10
- package/node_modules/@capyclaw/document-workbench/src/store/projection.mjs +39 -0
- package/node_modules/@capyclaw/document-workbench/src/testing/index.mjs +14 -11
- package/node_modules/@capyclaw/foundation/abi/assets.mjs +26 -0
- package/node_modules/@capyclaw/foundation/abi/bridge.mjs +3 -1
- package/node_modules/@capyclaw/foundation/abi/index.mjs +15 -0
- package/node_modules/@capyclaw/foundation/abi/visibility.mjs +90 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +21 -4
- package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +5 -1
- package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +5 -2
- package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +4 -0
- package/node_modules/@capyclaw/foundation/lib/kernel.mjs +13 -3
- package/node_modules/@capyclaw/foundation/package.json +1 -1
- package/node_modules/@capyclaw/plugin-kit/package.json +3 -1
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +5 -2
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat.mjs +26 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/static.mjs +79 -0
- package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +13 -5
- package/node_modules/@capyclaw/portal/package.json +1 -1
- package/node_modules/@capyclaw/service-broker/README.md +1 -1
- package/node_modules/@capyclaw/service-broker/lib/host.mjs +11 -6
- package/node_modules/@capyclaw/service-broker/lib/skills-client.mjs +13 -5
- package/node_modules/@capyclaw/service-broker/package.json +1 -1
- package/node_modules/@capyclaw/service-host/dsh-suite.json +1 -1
- package/node_modules/@capyclaw/service-host/package.json +1 -1
- package/node_modules/@capyclaw/service-host/src/index.mjs +13 -22
- package/node_modules/@capyclaw/tool-host/dsh-suite.json +1 -1
- package/node_modules/@capyclaw/tool-host/lib/host.mjs +15 -4
- package/node_modules/@capyclaw/tool-host/package.json +1 -1
- package/node_modules/@capyclaw/tool-host/src/index.mjs +19 -5
- package/node_modules/@capyclaw/tool-host/src/mode-gate.mjs +71 -3
- package/package.json +12 -12
package/composition.lock.json
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
1
|
{
|
|
2
2
|
"suite": "capyclaw-browser-suite",
|
|
3
|
-
"suiteVersion": "0.2.
|
|
3
|
+
"suiteVersion": "0.2.39",
|
|
4
4
|
"packages": {
|
|
5
5
|
"@capyclaw/asset-service": {
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.6",
|
|
7
7
|
"apiVersion": "1.0.0",
|
|
8
8
|
"path": "..\\..\\..\\..\\..\\..\\C\\packages\\capyclaw-asset-service",
|
|
9
|
-
"sha256": "
|
|
9
|
+
"sha256": "f776c6f40bb3ffb8511e7c471d53779e81efb29a4aa40c14172ea153d4071a9f"
|
|
10
10
|
},
|
|
11
11
|
"@capyclaw/browser-skill-api": {
|
|
12
|
-
"version": "0.2.
|
|
12
|
+
"version": "0.2.5",
|
|
13
13
|
"apiVersion": null,
|
|
14
14
|
"path": "../capyclaw-browser-skill-api",
|
|
15
|
-
"sha256": "
|
|
15
|
+
"sha256": "e783cb5867dd377dde1042972cb42256e8274b7e3f198a98d1a3afe3328314ec"
|
|
16
16
|
},
|
|
17
17
|
"@capyclaw/browser-skill-browser": {
|
|
18
|
-
"version": "0.2.
|
|
18
|
+
"version": "0.2.5",
|
|
19
19
|
"apiVersion": null,
|
|
20
20
|
"path": "../capyclaw-browser-skill-browser",
|
|
21
|
-
"sha256": "
|
|
21
|
+
"sha256": "7bebc9b7b8efbffd00f3ecbcf35f014893312113dad9c9a4b9c871b0aa42d260"
|
|
22
22
|
},
|
|
23
23
|
"@capyclaw/browser-skill-ops": {
|
|
24
|
-
"version": "0.2.
|
|
24
|
+
"version": "0.2.5",
|
|
25
25
|
"apiVersion": null,
|
|
26
26
|
"path": "../capyclaw-browser-skill-ops",
|
|
27
|
-
"sha256": "
|
|
27
|
+
"sha256": "d89b5bfb79eb039bc684e45e502634da189e4f80371f50d16d63b9adce39135a"
|
|
28
28
|
},
|
|
29
29
|
"@capyclaw/browser-workbench": {
|
|
30
|
-
"version": "0.1.
|
|
30
|
+
"version": "0.1.21",
|
|
31
31
|
"apiVersion": null,
|
|
32
32
|
"path": "../capyclaw-browser-workbench",
|
|
33
|
-
"sha256": "
|
|
33
|
+
"sha256": "b71c58349535f3b5b1c10f0e5ec826fdabec73eec111ad80bc0c74ac16fc0317"
|
|
34
34
|
},
|
|
35
35
|
"@capyclaw/document-workbench": {
|
|
36
|
-
"version": "0.2.
|
|
36
|
+
"version": "0.2.4",
|
|
37
37
|
"apiVersion": null,
|
|
38
38
|
"path": "../../../../../../C/packages/capyclaw-document-workbench",
|
|
39
|
-
"sha256": "
|
|
39
|
+
"sha256": "260d66c48617b64dbb7e82b3fb4105695e5d7108464e99b01361c3360180cc30"
|
|
40
40
|
},
|
|
41
41
|
"@capyclaw/foundation": {
|
|
42
|
-
"version": "0.1.
|
|
42
|
+
"version": "0.1.11",
|
|
43
43
|
"apiVersion": "1.0.0",
|
|
44
44
|
"path": "../../../../../../C/packages/capyclaw-foundation",
|
|
45
|
-
"sha256": "
|
|
45
|
+
"sha256": "2b1860bd9081f8ebeade500255bf908fe5d62740d2394c7d0b0f65149a2c82b5"
|
|
46
46
|
},
|
|
47
47
|
"@capyclaw/plugin-kit": {
|
|
48
|
-
"version": "0.2.
|
|
48
|
+
"version": "0.2.8",
|
|
49
49
|
"apiVersion": null,
|
|
50
50
|
"path": "../../../../../../C/packages/capyclaw-plugin-kit",
|
|
51
|
-
"sha256": "
|
|
51
|
+
"sha256": "5b9dd6bdadee6ecb32efcb59b59e7d6bbcd770fdb7762fc8f5aa90eedfee6186"
|
|
52
52
|
},
|
|
53
53
|
"@capyclaw/service-broker": {
|
|
54
|
-
"version": "0.2.
|
|
54
|
+
"version": "0.2.27",
|
|
55
55
|
"apiVersion": "1.0.0",
|
|
56
56
|
"path": "../../../../../../C/packages/capyclaw-service-broker",
|
|
57
|
-
"sha256": "
|
|
57
|
+
"sha256": "75df80d0e2f8df30138937fb601607a2ddade449c64f12e08a45e48cff1712e1"
|
|
58
58
|
},
|
|
59
59
|
"@capyclaw/service-host": {
|
|
60
|
-
"version": "0.1.
|
|
60
|
+
"version": "0.1.7",
|
|
61
61
|
"apiVersion": "1.0.0",
|
|
62
62
|
"path": "..\\..\\..\\..\\..\\..\\C\\packages\\capyclaw-service-host",
|
|
63
|
-
"sha256": "
|
|
63
|
+
"sha256": "be173a38c0087fa6fdb06a10e57356a02afe836ac9994b905eb00abe6516ce45"
|
|
64
64
|
},
|
|
65
65
|
"@capyclaw/tool-host": {
|
|
66
|
-
"version": "0.3.
|
|
66
|
+
"version": "0.3.2",
|
|
67
67
|
"apiVersion": "1.1.0",
|
|
68
68
|
"path": "..\\..\\..\\..\\..\\..\\C\\packages\\capyclaw-tool-host",
|
|
69
|
-
"sha256": "
|
|
69
|
+
"sha256": "2e4927e7281457602a57eadff33ae25ea4b5d60539d319d9819d86c0db92aadd"
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
}
|
package/dsh-suite.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "../../../../../../C/packages/capyclaw-suite-kit/suite.schema.json",
|
|
3
3
|
"name": "capyclaw-browser-suite",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.39",
|
|
5
5
|
"title": "浏览器操控工作台套件",
|
|
6
6
|
"description": "浏览器操控宿主内嵌工作台(挂在 dsh 的 /capyclaw/browser,路由与端口由基建决定;Playwright 引擎、有头可见、登录态持久化)+ 3 个独立 skill 包 + 服务中间件(broker);公共基建(os / toolHost / serviceHost / assets / serviceBroker)由 @capyclaw/core 统一提供,需同一 profile 启用它。",
|
|
7
7
|
"packages": {
|
|
8
8
|
"@capyclaw/browser-skill-api": {
|
|
9
9
|
"role": "skills",
|
|
10
|
-
"version": "^0.2.
|
|
10
|
+
"version": "^0.2.5",
|
|
11
11
|
"path": "./node_modules/@capyclaw/browser-skill-api",
|
|
12
12
|
"requires": {
|
|
13
|
-
"@capyclaw/browser-workbench": "^0.1.
|
|
13
|
+
"@capyclaw/browser-workbench": "^0.1.21",
|
|
14
14
|
"capabilities": {
|
|
15
15
|
"browser.runtime": "^1.3.0"
|
|
16
16
|
}
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
},
|
|
27
27
|
"@capyclaw/browser-skill-browser": {
|
|
28
28
|
"role": "skills",
|
|
29
|
-
"version": "^0.2.
|
|
29
|
+
"version": "^0.2.5",
|
|
30
30
|
"path": "./node_modules/@capyclaw/browser-skill-browser",
|
|
31
31
|
"requires": {
|
|
32
|
-
"@capyclaw/browser-workbench": "^0.1.
|
|
32
|
+
"@capyclaw/browser-workbench": "^0.1.21",
|
|
33
33
|
"capabilities": {
|
|
34
34
|
"browser.runtime": "^1.3.0"
|
|
35
35
|
}
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
},
|
|
46
46
|
"@capyclaw/browser-skill-ops": {
|
|
47
47
|
"role": "skills",
|
|
48
|
-
"version": "^0.2.
|
|
48
|
+
"version": "^0.2.5",
|
|
49
49
|
"path": "./node_modules/@capyclaw/browser-skill-ops",
|
|
50
50
|
"requires": {
|
|
51
|
-
"@capyclaw/browser-workbench": "^0.1.
|
|
51
|
+
"@capyclaw/browser-workbench": "^0.1.21",
|
|
52
52
|
"capabilities": {
|
|
53
53
|
"browser.runtime": "^1.3.0"
|
|
54
54
|
}
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
},
|
|
65
65
|
"@capyclaw/browser-workbench": {
|
|
66
66
|
"role": "runtime",
|
|
67
|
-
"version": "^0.1.
|
|
67
|
+
"version": "^0.1.21",
|
|
68
68
|
"path": "./node_modules/@capyclaw/browser-workbench",
|
|
69
69
|
"requires": {
|
|
70
70
|
"capabilities": {
|
|
@@ -80,28 +80,38 @@
|
|
|
80
80
|
"capabilities": {
|
|
81
81
|
"editor.bridge": "1.0.0",
|
|
82
82
|
"browser.runtime": "1.3.0",
|
|
83
|
-
"browser.tools": "1.3.0"
|
|
83
|
+
"browser.tools": "1.3.0",
|
|
84
|
+
"browser.surfaceLifecycle": "1.0.0"
|
|
84
85
|
}
|
|
86
|
+
},
|
|
87
|
+
"surfaceLifecycle": {
|
|
88
|
+
"hooks": [
|
|
89
|
+
"onVisibility",
|
|
90
|
+
"suspendRender",
|
|
91
|
+
"resumeRender",
|
|
92
|
+
"rehydrate"
|
|
93
|
+
],
|
|
94
|
+
"headlessObservation": true
|
|
85
95
|
}
|
|
86
96
|
},
|
|
87
97
|
"@capyclaw/document-workbench": {
|
|
88
98
|
"role": "support",
|
|
89
|
-
"version": "^0.2.
|
|
99
|
+
"version": "^0.2.4",
|
|
90
100
|
"path": "./node_modules/@capyclaw/document-workbench"
|
|
91
101
|
},
|
|
92
102
|
"@capyclaw/foundation": {
|
|
93
103
|
"role": "runtime",
|
|
94
|
-
"version": "^0.1.
|
|
104
|
+
"version": "^0.1.11",
|
|
95
105
|
"path": "./node_modules/@capyclaw/foundation"
|
|
96
106
|
},
|
|
97
107
|
"@capyclaw/plugin-kit": {
|
|
98
108
|
"role": "support",
|
|
99
|
-
"version": "^0.2.
|
|
109
|
+
"version": "^0.2.8",
|
|
100
110
|
"path": "./node_modules/@capyclaw/plugin-kit"
|
|
101
111
|
},
|
|
102
112
|
"@capyclaw/service-broker": {
|
|
103
113
|
"role": "runtime",
|
|
104
|
-
"version": "^0.2.
|
|
114
|
+
"version": "^0.2.27",
|
|
105
115
|
"path": "./node_modules/@capyclaw/service-broker",
|
|
106
116
|
"provides": {
|
|
107
117
|
"services": [
|
|
@@ -115,7 +125,7 @@
|
|
|
115
125
|
},
|
|
116
126
|
"@capyclaw/service-host": {
|
|
117
127
|
"role": "provider",
|
|
118
|
-
"version": "^0.1.
|
|
128
|
+
"version": "^0.1.7",
|
|
119
129
|
"path": "./node_modules/@capyclaw/service-host",
|
|
120
130
|
"provides": {
|
|
121
131
|
"services": [
|
|
@@ -128,7 +138,7 @@
|
|
|
128
138
|
},
|
|
129
139
|
"@capyclaw/tool-host": {
|
|
130
140
|
"role": "provider",
|
|
131
|
-
"version": "^0.3.
|
|
141
|
+
"version": "^0.3.2",
|
|
132
142
|
"path": "./node_modules/@capyclaw/tool-host",
|
|
133
143
|
"provides": {
|
|
134
144
|
"services": [
|
|
@@ -142,7 +152,7 @@
|
|
|
142
152
|
},
|
|
143
153
|
"@capyclaw/asset-service": {
|
|
144
154
|
"role": "provider",
|
|
145
|
-
"version": "^0.1.
|
|
155
|
+
"version": "^0.1.6",
|
|
146
156
|
"path": "./node_modules/@capyclaw/asset-service",
|
|
147
157
|
"provides": {
|
|
148
158
|
"services": [
|
|
@@ -13,6 +13,7 @@ import fs from 'node:fs'
|
|
|
13
13
|
import path from 'node:path'
|
|
14
14
|
import { send, readBody } from '@capyclaw/plugin-kit/service/http'
|
|
15
15
|
import { createServiceApi } from '@capyclaw/plugin-kit/service/api'
|
|
16
|
+
import { ASSET_URL_PREFIX } from '@capyclaw/foundation/abi'
|
|
16
17
|
|
|
17
18
|
function sha256(buffer) {
|
|
18
19
|
return crypto.createHash('sha256').update(buffer).digest('hex')
|
|
@@ -40,7 +41,7 @@ export function createWorkspaceAssetStore({ storeClient, workId = 'main' } = {})
|
|
|
40
41
|
const id = sha256(buffer)
|
|
41
42
|
const key = `assets/${id}`
|
|
42
43
|
storeClient.put(workId, key, buffer, { contentType })
|
|
43
|
-
return { id, key, url:
|
|
44
|
+
return { id, key, url: `${ASSET_URL_PREFIX}${id}`, size: buffer.length, contentType }
|
|
44
45
|
},
|
|
45
46
|
get(id) {
|
|
46
47
|
if (!validId(id)) return null
|
|
@@ -84,7 +85,7 @@ export function createFileAssetStore({ dir } = {}) {
|
|
|
84
85
|
const metaTmp = `${metaFile}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}`
|
|
85
86
|
fs.writeFileSync(metaTmp, JSON.stringify({ contentType, size: buffer.length }))
|
|
86
87
|
fs.renameSync(metaTmp, metaFile)
|
|
87
|
-
return { id, key: id, url:
|
|
88
|
+
return { id, key: id, url: `${ASSET_URL_PREFIX}${id}`, size: buffer.length, contentType }
|
|
88
89
|
},
|
|
89
90
|
get(id) {
|
|
90
91
|
if (!validId(id)) return null
|
|
@@ -192,7 +193,7 @@ function safeContentType(type) {
|
|
|
192
193
|
*/
|
|
193
194
|
export function createAssetRoutes({ assetStore, basePath = '', maxUploadBytes = 10 * 1024 * 1024 } = {}) {
|
|
194
195
|
const prefix = basePath === '/' ? '' : String(basePath || '').replace(/\/+$/, '')
|
|
195
|
-
const getPrefixes = [
|
|
196
|
+
const getPrefixes = [ASSET_URL_PREFIX, prefix ? `${prefix}${ASSET_URL_PREFIX}` : null].filter(Boolean)
|
|
196
197
|
const postPaths = new Set(['/assets', prefix ? `${prefix}/assets` : null].filter(Boolean))
|
|
197
198
|
return async function assetRoutes(req, res, u) {
|
|
198
199
|
const p = u.pathname
|
package/node_modules/@capyclaw/browser-skill-api/skills/browser-api/references/tool-contract.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Browser Workbench 工具契约
|
|
2
2
|
|
|
3
3
|
- contractVersion: `1.3.0`
|
|
4
|
-
- packageVersion: `0.1.
|
|
4
|
+
- packageVersion: `0.1.21`
|
|
5
5
|
- toolCount: 18
|
|
6
6
|
- features: `browser.contract`, `browser.navigation`, `browser.snapshot`, `browser.interaction`, `browser.tabs`, `browser.screenshot`, `browser.session`, `browser.evaluate`
|
|
7
7
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capyclaw/browser-workbench",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "浏览器操控工作台运行时:18 个 browser_* MCP 工具(导航/快照/点击/填写/按键/下拉/上传/滚动/批量连做/拖拽/标签页/截图)+ Playwright 引擎(有头可见、登录态持久化)+ 可视化工作台。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./plugin.mjs",
|
|
@@ -46,12 +46,12 @@
|
|
|
46
46
|
"license": "MIT",
|
|
47
47
|
"scripts": {},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@capyclaw/asset-service": "^0.1.
|
|
50
|
-
"@capyclaw/document-workbench": "^0.2.
|
|
51
|
-
"@capyclaw/foundation": "^0.1.
|
|
52
|
-
"@capyclaw/plugin-kit": "^0.2.
|
|
53
|
-
"@capyclaw/service-host": "^0.1.
|
|
54
|
-
"@capyclaw/tool-host": "^0.3.
|
|
49
|
+
"@capyclaw/asset-service": "^0.1.6",
|
|
50
|
+
"@capyclaw/document-workbench": "^0.2.4",
|
|
51
|
+
"@capyclaw/foundation": "^0.1.11",
|
|
52
|
+
"@capyclaw/plugin-kit": "^0.2.8",
|
|
53
|
+
"@capyclaw/service-host": "^0.1.7",
|
|
54
|
+
"@capyclaw/tool-host": "^0.3.2",
|
|
55
55
|
"playwright": "^1.64.0"
|
|
56
56
|
},
|
|
57
57
|
"author": {
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* foundation ABI raw@1 wrapper:准入闸扩面后宿主必须走 ABI(见 bridge-build 注释)。
|
|
3
|
+
* raw@1 逃生舱承载多面共生命周期(webServer 路由 + toolHost 工具 + 描述符/表面/portal,
|
|
4
|
+
* 共享 workId/relay);额外 inject 仅 raw@1 可声明。core/os.skills 是套件运行时前提。
|
|
5
|
+
*/
|
|
6
|
+
import { createPlugin, rawPlugin } from '@capyclaw/foundation/abi'
|
|
7
|
+
import { name as hostName, apply as applyHost } from './server/embedded-host.mjs'
|
|
8
|
+
|
|
9
|
+
export const { name, inject, apply } = createPlugin({
|
|
10
|
+
name: hostName,
|
|
11
|
+
inject: ['webServer'],
|
|
12
|
+
implements: [rawPlugin(({ ctx, config }) => applyHost(ctx, config))],
|
|
13
|
+
}, import.meta.url)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 激活失败诊断日志的有界写入(防 activate-error.log 无界增长)。
|
|
3
|
+
*
|
|
4
|
+
* 旧实现直接 fs.appendFileSync 追加完整栈,长期反复激活失败会让日志无限膨胀。
|
|
5
|
+
* 这里改为「读尾部 + 追加 + 超限裁剪 + 整体重写」:
|
|
6
|
+
* - 行数硬上限 ACTIVATE_LOG_MAX_LINES(200):每次追加只保留最近 200 行;
|
|
7
|
+
* - 字节硬上限 ACTIVATE_LOG_MAX_BYTES(256KB):仍超则按字节取尾部并丢掉
|
|
8
|
+
* 首条不完整行,保证不截断出半行乱码。
|
|
9
|
+
* 只读取文件尾部 maxBytes 字节,内存占用有界;失败信息(最近若干条栈)始终可诊断。
|
|
10
|
+
*
|
|
11
|
+
* 本模块不依赖构建期才生成的 ./shared/*,可被 src 直接 import 做回归测试。
|
|
12
|
+
*/
|
|
13
|
+
import fs from 'node:fs'
|
|
14
|
+
|
|
15
|
+
export const ACTIVATE_LOG_MAX_BYTES = 256 * 1024
|
|
16
|
+
export const ACTIVATE_LOG_MAX_LINES = 200
|
|
17
|
+
|
|
18
|
+
/** 只读文件尾部 maxBytes 字节;若从中间读起则丢掉首条不完整行。读失败返回空串。 */
|
|
19
|
+
function readTail(filePath, maxBytes) {
|
|
20
|
+
let fd
|
|
21
|
+
try {
|
|
22
|
+
fd = fs.openSync(filePath, 'r')
|
|
23
|
+
const size = fs.fstatSync(fd).size
|
|
24
|
+
const start = Math.max(0, size - maxBytes)
|
|
25
|
+
const len = size - start
|
|
26
|
+
const buf = Buffer.alloc(len)
|
|
27
|
+
fs.readSync(fd, buf, 0, len, start)
|
|
28
|
+
let text = buf.toString('utf8')
|
|
29
|
+
if (start > 0) {
|
|
30
|
+
const i = text.indexOf('\n')
|
|
31
|
+
text = i >= 0 ? text.slice(i + 1) : ''
|
|
32
|
+
}
|
|
33
|
+
return text
|
|
34
|
+
} catch {
|
|
35
|
+
return ''
|
|
36
|
+
} finally {
|
|
37
|
+
if (fd !== undefined) { try { fs.closeSync(fd) } catch { /* 忽略 */ } }
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 向 filePath 有界追加一条 entry(自动补尾换行)。超限按行/按字节裁剪后整体重写。
|
|
43
|
+
* @param {string} filePath 目标日志文件绝对路径
|
|
44
|
+
* @param {string} entry 要追加的一条诊断文本(通常含时间戳与错误栈)
|
|
45
|
+
* @param {{maxBytes?:number, maxLines?:number}} [opts] 覆盖默认上限
|
|
46
|
+
*/
|
|
47
|
+
export function appendBoundedLog(filePath, entry, opts = {}) {
|
|
48
|
+
const maxBytes = opts.maxBytes ?? ACTIVATE_LOG_MAX_BYTES
|
|
49
|
+
const maxLines = opts.maxLines ?? ACTIVATE_LOG_MAX_LINES
|
|
50
|
+
const line = String(entry)
|
|
51
|
+
const text = line.endsWith('\n') ? line : `${line}\n`
|
|
52
|
+
let combined = readTail(filePath, maxBytes) + text
|
|
53
|
+
/* 行数硬上限:每次追加都只保留最近 maxLines 行(最新一条必在末尾)。 */
|
|
54
|
+
const lines = combined.split('\n').filter((l) => l.length > 0)
|
|
55
|
+
if (lines.length > maxLines) combined = `${lines.slice(-maxLines).join('\n')}\n`
|
|
56
|
+
/* 字节硬上限:仍超则按字节取尾部并丢首条不完整行,避免截出半行乱码。 */
|
|
57
|
+
if (Buffer.byteLength(combined, 'utf8') > maxBytes) {
|
|
58
|
+
let tail = Buffer.from(combined, 'utf8').subarray(-maxBytes).toString('utf8')
|
|
59
|
+
const i = tail.indexOf('\n')
|
|
60
|
+
tail = i >= 0 ? tail.slice(i + 1) : tail
|
|
61
|
+
/* 极端:单条 entry 本身就超过 maxBytes,按字节裁剪可能整条丢空——
|
|
62
|
+
兜底保留 entry 尾部,确保最新失败信息不丢。 */
|
|
63
|
+
combined = tail.length > 0 ? tail : text.slice(-maxBytes)
|
|
64
|
+
}
|
|
65
|
+
fs.writeFileSync(filePath, combined)
|
|
66
|
+
}
|
|
@@ -10,7 +10,7 @@ import { createCapabilityReport } from './shared/tool-host.mjs'
|
|
|
10
10
|
export const CONTRACT_VERSION = '1.3.0'
|
|
11
11
|
|
|
12
12
|
/** 工作台包版本。 */
|
|
13
|
-
export const PACKAGE_VERSION = '0.1.
|
|
13
|
+
export const PACKAGE_VERSION = '0.1.21'
|
|
14
14
|
|
|
15
15
|
/** 生成模型可读的能力报告。 */
|
|
16
16
|
export function capabilityReport(args, workbenchUrl = '', runtime = {}) {
|
|
@@ -15,6 +15,7 @@ import path from 'node:path'
|
|
|
15
15
|
import fs from 'node:fs'
|
|
16
16
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
17
17
|
import { assertServiceApi } from './shared/kit/service/api.mjs'
|
|
18
|
+
import { appendBoundedLog } from './activate-log.mjs'
|
|
18
19
|
|
|
19
20
|
export const name = 'browser-workbench-host'
|
|
20
21
|
/* 依赖倒置:业务等的是「宿主给的 HTTP 路由」,不是端口。 */
|
|
@@ -68,7 +69,8 @@ export async function apply(ctx, config) {
|
|
|
68
69
|
const fallbackDir = path.join(os.homedir(), '.dsh-browser-bridge')
|
|
69
70
|
const hostDir = (config && config.hostDir) || process.env.BROWSER_BRIDGE_HOME || fallbackDir
|
|
70
71
|
fs.mkdirSync(hostDir, { recursive: true })
|
|
71
|
-
|
|
72
|
+
/* 有界写入:防反复激活失败把 activate-error.log 撑到无界(保留最近若干条栈)。 */
|
|
73
|
+
appendBoundedLog(
|
|
72
74
|
path.join(hostDir, 'activate-error.log'),
|
|
73
75
|
`[${new Date().toISOString()}] ${(error && error.stack) || error}\n`,
|
|
74
76
|
)
|
|
@@ -136,6 +138,16 @@ async function activate(ctx, config) {
|
|
|
136
138
|
modeGate.declareTools('browser', registry.TOOLS.map((t) => t.name), 'browser')
|
|
137
139
|
if (toolState.hasTools) modeGate.install(tools)
|
|
138
140
|
}
|
|
141
|
+
/* 感知闸补挂(幂等):锁定会话的系统提示里注入主区工作台感知,让模型知道主区界面
|
|
142
|
+
* 的存在与唯一交付地位(缺这道闸时模型会用内置文件工具绕过主区)。systemPrompt
|
|
143
|
+
* 缺席(老宿主)降级;引用计数 disposer 随本插件卸载释放。 */
|
|
144
|
+
if (modeGate && typeof modeGate.installPrompt === 'function') {
|
|
145
|
+
const systemPrompt = safeGet(ctx, 'systemPrompt')
|
|
146
|
+
if (systemPrompt && typeof systemPrompt.section === 'function') {
|
|
147
|
+
const promptDispose = modeGate.installPrompt(systemPrompt)
|
|
148
|
+
if (typeof promptDispose === 'function') disposers.push(promptDispose)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
139
151
|
const OUTPUT_SCHEMA = { type: 'object', additionalProperties: true }
|
|
140
152
|
|
|
141
153
|
function toolText(value) {
|
|
@@ -1784,6 +1784,8 @@ export async function createBrowserEngine({ hostDir, config, playwright, process
|
|
|
1784
1784
|
const current = caster
|
|
1785
1785
|
if (!current) return
|
|
1786
1786
|
caster = null
|
|
1787
|
+
/* 摘掉 attachCast 注册的 close 监听,否则每次切页/停播都遗留一个 once 闭包。 */
|
|
1788
|
+
try { if (current.closeHandler) current.page.off?.('close', current.closeHandler) } catch { /* 页面已关闭 */ }
|
|
1787
1789
|
try { current.session.removeAllListeners?.('Page.screencastFrame') } catch { /* 已 detach */ }
|
|
1788
1790
|
try { await current.session.send('Page.stopScreencast') } catch { /* 页面已关闭 */ }
|
|
1789
1791
|
try { await current.session.detach() } catch { /* 已断开 */ }
|
|
@@ -1801,7 +1803,10 @@ export async function createBrowserEngine({ hostDir, config, playwright, process
|
|
|
1801
1803
|
await stopCast()
|
|
1802
1804
|
const session = await context.newCDPSession(page)
|
|
1803
1805
|
const tabId = activeTabId
|
|
1804
|
-
|
|
1806
|
+
const closeHandler = () => {
|
|
1807
|
+
if (caster && caster.session === session) stopCast().catch(() => {})
|
|
1808
|
+
}
|
|
1809
|
+
caster = { page, tabId, session, closeHandler }
|
|
1805
1810
|
session.on('Page.screencastFrame', (event) => {
|
|
1806
1811
|
if (!caster || caster.session !== session || !frameSubs.size) return
|
|
1807
1812
|
/* 先 ack 再广播:ack 是「可以给下一帧了」的背压阀,晚 ack 会直接掉帧率。 */
|
|
@@ -1813,9 +1818,7 @@ export async function createBrowserEngine({ hostDir, config, playwright, process
|
|
|
1813
1818
|
height: Number(event.metadata?.deviceHeight) || cfg.viewportHeight,
|
|
1814
1819
|
})
|
|
1815
1820
|
})
|
|
1816
|
-
page.once('close',
|
|
1817
|
-
if (caster && caster.session === session) stopCast().catch(() => {})
|
|
1818
|
-
})
|
|
1821
|
+
page.once('close', closeHandler)
|
|
1819
1822
|
await session.send('Page.startScreencast', {
|
|
1820
1823
|
format: 'jpeg',
|
|
1821
1824
|
quality: Math.max(10, Math.min(Number(cfg.screencastQuality) || 60, 95)),
|
|
@@ -1933,6 +1936,10 @@ export async function createBrowserEngine({ hostDir, config, playwright, process
|
|
|
1933
1936
|
/* 无论是否落盘,都先掐掉防抖计时器:避免关闭后残留计时器再写一次日志。 */
|
|
1934
1937
|
if (journalTimer) { clearTimeout(journalTimer); journalTimer = null }
|
|
1935
1938
|
if (vaultTimer) { clearTimeout(vaultTimer); vaultTimer = null }
|
|
1939
|
+
/* 停播轮询计时器与帧订阅一并清空:stopCast 只摘当前 caster,
|
|
1940
|
+
castTimer 若还在跑会继续 attachCast,frameSubs 残留会让回收后仍以为有观众。 */
|
|
1941
|
+
if (castTimer !== null) { clearInterval(castTimer); castTimer = null }
|
|
1942
|
+
frameSubs.clear()
|
|
1936
1943
|
if (!context) {
|
|
1937
1944
|
if (!persist) { try { fs.rmSync(tabsFile, { force: true }) } catch { /* 忽略 */ } }
|
|
1938
1945
|
return false
|
|
@@ -184,7 +184,7 @@ export function createApiRoutes({ engine: fallbackEngine, getEngine, embedded })
|
|
|
184
184
|
return true
|
|
185
185
|
},
|
|
186
186
|
|
|
187
|
-
/* POST /api/control { action: 'close' | 'headless', value? }
|
|
187
|
+
/* POST /api/control { action: 'close' | 'resume' | 'headless', value? }
|
|
188
188
|
* headless 切完会关掉运行中的浏览器,下次动作按新模式重启(登录态保留)。 */
|
|
189
189
|
async (req, res, u) => {
|
|
190
190
|
if (u.pathname !== '/api/control' || req.method !== 'POST') return false
|
|
@@ -208,7 +208,7 @@ export function createApiRoutes({ engine: fallbackEngine, getEngine, embedded })
|
|
|
208
208
|
}
|
|
209
209
|
send(req, res, 400, {
|
|
210
210
|
ok: false,
|
|
211
|
-
error: { code: 'ARG_INVALID', message: `不支持 ${action || '(空)'}`, hint: '可用:close / headless' },
|
|
211
|
+
error: { code: 'ARG_INVALID', message: `不支持 ${action || '(空)'}`, hint: '可用:close / resume / headless' },
|
|
212
212
|
})
|
|
213
213
|
} catch (error) {
|
|
214
214
|
sendEngineError(req, res, error)
|
|
@@ -4,28 +4,28 @@
|
|
|
4
4
|
"packages": {
|
|
5
5
|
"service-host": {
|
|
6
6
|
"package": "@capyclaw/service-host",
|
|
7
|
-
"version": "0.1.
|
|
7
|
+
"version": "0.1.7",
|
|
8
8
|
"apiVersion": "1.0.0",
|
|
9
9
|
"spec": "@capyclaw/service-host/src",
|
|
10
10
|
"sha256": "af0a57d779bfe6a66dc935320178d591ef799a7e037f7a5823cdfa1fe5878eeb"
|
|
11
11
|
},
|
|
12
12
|
"tool-host": {
|
|
13
13
|
"package": "@capyclaw/tool-host",
|
|
14
|
-
"version": "0.3.
|
|
14
|
+
"version": "0.3.2",
|
|
15
15
|
"apiVersion": "1.1.0",
|
|
16
16
|
"spec": "@capyclaw/tool-host/src",
|
|
17
17
|
"sha256": "23256dbcd5cbee0b96b33c97e4eb4e74d0e169cbdde52f91d4526f2fc0f60d3e"
|
|
18
18
|
},
|
|
19
19
|
"asset-service": {
|
|
20
20
|
"package": "@capyclaw/asset-service",
|
|
21
|
-
"version": "0.1.
|
|
21
|
+
"version": "0.1.6",
|
|
22
22
|
"apiVersion": "1.0.0",
|
|
23
23
|
"spec": "@capyclaw/asset-service/src",
|
|
24
24
|
"sha256": "311a83e95d56dbb69b739d61aced0889b64e85eddd95b883e322e0fa5be8bd6f"
|
|
25
25
|
},
|
|
26
26
|
"editor-host": {
|
|
27
27
|
"package": "@capyclaw/editor-host",
|
|
28
|
-
"version": "0.1.
|
|
28
|
+
"version": "0.1.7",
|
|
29
29
|
"apiVersion": "1.0.0",
|
|
30
30
|
"spec": "@capyclaw/editor-host/src",
|
|
31
31
|
"sha256": "c8b80dbd4f1b2bee9ef9001423a013031a21ea9a3b8897b5536fe6e5687f01b3"
|