@capyclaw/browser-suite 0.2.38 → 0.2.40
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 +164 -122
- 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 +4 -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/ledger.mjs +151 -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 +2 -2
- package/node_modules/@capyclaw/service-host/src/index.mjs +45 -27
- 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.40",
|
|
4
4
|
"packages": {
|
|
5
5
|
"@capyclaw/asset-service": {
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.7",
|
|
7
7
|
"apiVersion": "1.0.0",
|
|
8
8
|
"path": "..\\..\\..\\..\\..\\..\\C\\packages\\capyclaw-asset-service",
|
|
9
|
-
"sha256": "
|
|
9
|
+
"sha256": "8124a609fb6acdf649fde1023dcbe1ba9dcc149945e9b8ee329ca0f28b5c9cf2"
|
|
10
10
|
},
|
|
11
11
|
"@capyclaw/browser-skill-api": {
|
|
12
|
-
"version": "0.2.
|
|
12
|
+
"version": "0.2.6",
|
|
13
13
|
"apiVersion": null,
|
|
14
14
|
"path": "../capyclaw-browser-skill-api",
|
|
15
|
-
"sha256": "
|
|
15
|
+
"sha256": "33b532d4b9329cf079fd22ad613e1348545952919842e633307e829c8ebbb342"
|
|
16
16
|
},
|
|
17
17
|
"@capyclaw/browser-skill-browser": {
|
|
18
|
-
"version": "0.2.
|
|
18
|
+
"version": "0.2.6",
|
|
19
19
|
"apiVersion": null,
|
|
20
20
|
"path": "../capyclaw-browser-skill-browser",
|
|
21
|
-
"sha256": "
|
|
21
|
+
"sha256": "9502741127daf0420a363e6340f35432f658195a457a435fdfc4a201c529394f"
|
|
22
22
|
},
|
|
23
23
|
"@capyclaw/browser-skill-ops": {
|
|
24
|
-
"version": "0.2.
|
|
24
|
+
"version": "0.2.6",
|
|
25
25
|
"apiVersion": null,
|
|
26
26
|
"path": "../capyclaw-browser-skill-ops",
|
|
27
|
-
"sha256": "
|
|
27
|
+
"sha256": "d3c9a6c873f1294cb48cd1642afd4482f543fb8226c0743e751f0016ff6ad811"
|
|
28
28
|
},
|
|
29
29
|
"@capyclaw/browser-workbench": {
|
|
30
|
-
"version": "0.1.
|
|
30
|
+
"version": "0.1.22",
|
|
31
31
|
"apiVersion": null,
|
|
32
32
|
"path": "../capyclaw-browser-workbench",
|
|
33
|
-
"sha256": "
|
|
33
|
+
"sha256": "98d37b89893c86e3bcd67b3cf9043cd850e7b43da52044605c5be04908b6f65d"
|
|
34
34
|
},
|
|
35
35
|
"@capyclaw/document-workbench": {
|
|
36
|
-
"version": "0.2.
|
|
36
|
+
"version": "0.2.5",
|
|
37
37
|
"apiVersion": null,
|
|
38
38
|
"path": "../../../../../../C/packages/capyclaw-document-workbench",
|
|
39
|
-
"sha256": "
|
|
39
|
+
"sha256": "cf2a14df68fc22dafd55eba2cffaa81cebbf94ad622b3a083fffdedecd123c4c"
|
|
40
40
|
},
|
|
41
41
|
"@capyclaw/foundation": {
|
|
42
|
-
"version": "0.1.
|
|
42
|
+
"version": "0.1.12",
|
|
43
43
|
"apiVersion": "1.0.0",
|
|
44
44
|
"path": "../../../../../../C/packages/capyclaw-foundation",
|
|
45
|
-
"sha256": "
|
|
45
|
+
"sha256": "9925018e8eea5157b4e4ebc74f273a0009adb168273a323bcb1f7ef0957de8a3"
|
|
46
46
|
},
|
|
47
47
|
"@capyclaw/plugin-kit": {
|
|
48
|
-
"version": "0.2.
|
|
48
|
+
"version": "0.2.10",
|
|
49
49
|
"apiVersion": null,
|
|
50
50
|
"path": "../../../../../../C/packages/capyclaw-plugin-kit",
|
|
51
|
-
"sha256": "
|
|
51
|
+
"sha256": "e7851844a09c71e226a2884ef4211dfeb383f07a0609d994b20cb88c1da404ff"
|
|
52
52
|
},
|
|
53
53
|
"@capyclaw/service-broker": {
|
|
54
|
-
"version": "0.2.
|
|
54
|
+
"version": "0.2.28",
|
|
55
55
|
"apiVersion": "1.0.0",
|
|
56
56
|
"path": "../../../../../../C/packages/capyclaw-service-broker",
|
|
57
|
-
"sha256": "
|
|
57
|
+
"sha256": "b24032d9c92be7bdad1adbf54089e33f7f989f9b03bec04bfc1b50644e929dce"
|
|
58
58
|
},
|
|
59
59
|
"@capyclaw/service-host": {
|
|
60
|
-
"version": "0.1.
|
|
60
|
+
"version": "0.1.9",
|
|
61
61
|
"apiVersion": "1.0.0",
|
|
62
62
|
"path": "..\\..\\..\\..\\..\\..\\C\\packages\\capyclaw-service-host",
|
|
63
|
-
"sha256": "
|
|
63
|
+
"sha256": "eb25c8b72eefddf31ddc46b4b582f24e6def461eba2d6ddc51525e18789cd7ec"
|
|
64
64
|
},
|
|
65
65
|
"@capyclaw/tool-host": {
|
|
66
|
-
"version": "0.3.
|
|
66
|
+
"version": "0.3.3",
|
|
67
67
|
"apiVersion": "1.1.0",
|
|
68
68
|
"path": "..\\..\\..\\..\\..\\..\\C\\packages\\capyclaw-tool-host",
|
|
69
|
-
"sha256": "
|
|
69
|
+
"sha256": "9c078b66b7006206e0b97bc2393676fe428631765ca279181d815c86f0c4db13"
|
|
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.40",
|
|
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.6",
|
|
11
11
|
"path": "./node_modules/@capyclaw/browser-skill-api",
|
|
12
12
|
"requires": {
|
|
13
|
-
"@capyclaw/browser-workbench": "^0.1.
|
|
13
|
+
"@capyclaw/browser-workbench": "^0.1.22",
|
|
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.6",
|
|
30
30
|
"path": "./node_modules/@capyclaw/browser-skill-browser",
|
|
31
31
|
"requires": {
|
|
32
|
-
"@capyclaw/browser-workbench": "^0.1.
|
|
32
|
+
"@capyclaw/browser-workbench": "^0.1.22",
|
|
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.6",
|
|
49
49
|
"path": "./node_modules/@capyclaw/browser-skill-ops",
|
|
50
50
|
"requires": {
|
|
51
|
-
"@capyclaw/browser-workbench": "^0.1.
|
|
51
|
+
"@capyclaw/browser-workbench": "^0.1.22",
|
|
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.22",
|
|
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.5",
|
|
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.12",
|
|
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.10",
|
|
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.28",
|
|
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.9",
|
|
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.3",
|
|
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.7",
|
|
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.22`
|
|
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.22",
|
|
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.7",
|
|
50
|
+
"@capyclaw/document-workbench": "^0.2.5",
|
|
51
|
+
"@capyclaw/foundation": "^0.1.12",
|
|
52
|
+
"@capyclaw/plugin-kit": "^0.2.10",
|
|
53
|
+
"@capyclaw/service-host": "^0.1.9",
|
|
54
|
+
"@capyclaw/tool-host": "^0.3.3",
|
|
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.22'
|
|
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) {
|