@capyclaw/browser-suite 0.2.36 → 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/composition.lock.json +3 -3
- package/contract/browser-contract.json +1 -1
- package/dsh-suite.json +5 -5
- package/node_modules/@capyclaw/asset-service/src/index.mjs +86 -5
- package/node_modules/@capyclaw/browser-skill-api/contract/browser-contract.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-ops/contract/browser-contract.json +1 -1
- package/node_modules/@capyclaw/browser-workbench/contract/browser-contract.json +1 -1
- package/node_modules/@capyclaw/browser-workbench/package.json +1 -1
- package/node_modules/@capyclaw/browser-workbench/server/contract.mjs +1 -1
- package/node_modules/@capyclaw/browser-workbench/server/session-engines.mjs +39 -0
- package/node_modules/@capyclaw/document-workbench/src/session/context.mjs +17 -5
- package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +11 -10
- package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +8 -1
- package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +31 -3
- package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +13 -6
- package/node_modules/@capyclaw/plugin-kit/src/tools/result.mjs +31 -15
- package/node_modules/@capyclaw/tool-host/src/descriptors.mjs +28 -4
- package/node_modules/@capyclaw/tool-host/src/index.mjs +32 -6
- package/package.json +5 -6
- package/node_modules/playwright/LICENSE +0 -202
- package/node_modules/playwright/NOTICE +0 -5
- package/node_modules/playwright/README.md +0 -318
- package/node_modules/playwright/ThirdPartyNotices.txt +0 -14
- package/node_modules/playwright/cli.js +0 -19
- package/node_modules/playwright/index.d.ts +0 -17
- package/node_modules/playwright/index.js +0 -17
- package/node_modules/playwright/index.mjs +0 -18
- package/node_modules/playwright/lib/agents/agentParser.js +0 -89
- package/node_modules/playwright/lib/agents/copilot-setup-steps.yml +0 -34
- package/node_modules/playwright/lib/agents/generateAgents.js +0 -395
- package/node_modules/playwright/lib/agents/playwright-test-coverage.prompt.md +0 -31
- package/node_modules/playwright/lib/agents/playwright-test-generate.prompt.md +0 -8
- package/node_modules/playwright/lib/agents/playwright-test-generator.agent.md +0 -88
- package/node_modules/playwright/lib/agents/playwright-test-heal.prompt.md +0 -6
- package/node_modules/playwright/lib/agents/playwright-test-healer.agent.md +0 -56
- package/node_modules/playwright/lib/agents/playwright-test-plan.prompt.md +0 -9
- package/node_modules/playwright/lib/agents/playwright-test-planner.agent.md +0 -74
- package/node_modules/playwright/lib/cli/reportActions.js +0 -78
- package/node_modules/playwright/lib/cli/testActions.js +0 -217
- package/node_modules/playwright/lib/common/index.js +0 -2937
- package/node_modules/playwright/lib/common/index.js.txt +0 -33
- package/node_modules/playwright/lib/errorContext.js +0 -129
- package/node_modules/playwright/lib/globals.js +0 -58
- package/node_modules/playwright/lib/index.js +0 -827
- package/node_modules/playwright/lib/isomorphic.js +0 -260
- package/node_modules/playwright/lib/isomorphic.js.txt +0 -9
- package/node_modules/playwright/lib/loader/loaderProcessEntry.js +0 -34
- package/node_modules/playwright/lib/loader/loaderProcessEntry.js.txt +0 -9
- package/node_modules/playwright/lib/matchers/expect.js +0 -13496
- package/node_modules/playwright/lib/matchers/expect.js.LICENSE +0 -640
- package/node_modules/playwright/lib/matchers/expect.js.txt +0 -67
- package/node_modules/playwright/lib/package.js +0 -47
- package/node_modules/playwright/lib/program.js +0 -242
- package/node_modules/playwright/lib/runner/index.js +0 -8721
- package/node_modules/playwright/lib/runner/index.js.txt +0 -62
- package/node_modules/playwright/lib/transform/babelBundle.js +0 -72490
- package/node_modules/playwright/lib/transform/babelBundle.js.LICENSE +0 -2384
- package/node_modules/playwright/lib/transform/babelBundle.js.txt +0 -328
- package/node_modules/playwright/lib/transform/esmLoader.js +0 -8066
- package/node_modules/playwright/lib/transform/esmLoader.js.LICENSE +0 -355
- package/node_modules/playwright/lib/transform/esmLoader.js.txt +0 -60
- package/node_modules/playwright/lib/util.js +0 -373
- package/node_modules/playwright/lib/worker/workerProcessEntry.js +0 -1860
- package/node_modules/playwright/lib/worker/workerProcessEntry.js.txt +0 -19
- package/node_modules/playwright/package.json +0 -50
- package/node_modules/playwright/test.d.ts +0 -18
- package/node_modules/playwright/test.js +0 -24
- package/node_modules/playwright/test.mjs +0 -35
- package/node_modules/playwright/types/test.d.ts +0 -11191
- package/node_modules/playwright/types/testReporter.d.ts +0 -950
- package/node_modules/playwright-core/LICENSE +0 -202
- package/node_modules/playwright-core/NOTICE +0 -5
- package/node_modules/playwright-core/README.md +0 -3
- package/node_modules/playwright-core/ThirdPartyNotices.txt +0 -13
- package/node_modules/playwright-core/bin/install_media_pack.ps1 +0 -5
- package/node_modules/playwright-core/bin/install_webkit_wsl.ps1 +0 -33
- package/node_modules/playwright-core/bin/reinstall_chrome_beta_linux.sh +0 -42
- package/node_modules/playwright-core/bin/reinstall_chrome_beta_mac.sh +0 -13
- package/node_modules/playwright-core/bin/reinstall_chrome_beta_win.ps1 +0 -24
- package/node_modules/playwright-core/bin/reinstall_chrome_stable_linux.sh +0 -42
- package/node_modules/playwright-core/bin/reinstall_chrome_stable_mac.sh +0 -12
- package/node_modules/playwright-core/bin/reinstall_chrome_stable_win.ps1 +0 -24
- package/node_modules/playwright-core/bin/reinstall_msedge_beta_linux.sh +0 -48
- package/node_modules/playwright-core/bin/reinstall_msedge_beta_mac.sh +0 -11
- package/node_modules/playwright-core/bin/reinstall_msedge_beta_win.ps1 +0 -23
- package/node_modules/playwright-core/bin/reinstall_msedge_dev_linux.sh +0 -48
- package/node_modules/playwright-core/bin/reinstall_msedge_dev_mac.sh +0 -11
- package/node_modules/playwright-core/bin/reinstall_msedge_dev_win.ps1 +0 -23
- package/node_modules/playwright-core/bin/reinstall_msedge_stable_linux.sh +0 -48
- package/node_modules/playwright-core/bin/reinstall_msedge_stable_mac.sh +0 -11
- package/node_modules/playwright-core/bin/reinstall_msedge_stable_win.ps1 +0 -24
- package/node_modules/playwright-core/browsers.json +0 -52
- package/node_modules/playwright-core/cli.js +0 -22
- package/node_modules/playwright-core/index.d.ts +0 -17
- package/node_modules/playwright-core/index.js +0 -17
- package/node_modules/playwright-core/index.mjs +0 -28
- package/node_modules/playwright-core/lib/bootstrap.js +0 -149
- package/node_modules/playwright-core/lib/coreBundle.js +0 -78041
- package/node_modules/playwright-core/lib/entry/cliDaemon.js +0 -5
- package/node_modules/playwright-core/lib/entry/dashboardApp.js +0 -3
- package/node_modules/playwright-core/lib/entry/mcp.js +0 -10
- package/node_modules/playwright-core/lib/entry/oopBrowserDownload.js +0 -3
- package/node_modules/playwright-core/lib/package.js +0 -50
- package/node_modules/playwright-core/lib/server/chromium/appIcon.png +0 -0
- package/node_modules/playwright-core/lib/server/electron/loader.js +0 -123
- package/node_modules/playwright-core/lib/serverRegistry.js +0 -1939
- package/node_modules/playwright-core/lib/serverRegistry.js.LICENSE +0 -65
- package/node_modules/playwright-core/lib/tools/cli-client/channelSessions.js +0 -141
- package/node_modules/playwright-core/lib/tools/cli-client/cli.js +0 -7
- package/node_modules/playwright-core/lib/tools/cli-client/help.json +0 -808
- package/node_modules/playwright-core/lib/tools/cli-client/minimist.js +0 -128
- package/node_modules/playwright-core/lib/tools/cli-client/output.js +0 -352
- package/node_modules/playwright-core/lib/tools/cli-client/program.js +0 -422
- package/node_modules/playwright-core/lib/tools/cli-client/registry.js +0 -180
- package/node_modules/playwright-core/lib/tools/cli-client/session.js +0 -261
- package/node_modules/playwright-core/lib/tools/dashboard/appIcon.png +0 -0
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/SKILL.md +0 -493
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/element-attributes.md +0 -23
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/playwright-tests.md +0 -39
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/pr-attachments.md +0 -60
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/request-mocking.md +0 -87
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/running-code.md +0 -245
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/session-management.md +0 -227
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/storage-state.md +0 -275
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/test-generation.md +0 -433
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/tracing.md +0 -139
- package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/video-recording.md +0 -216
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/SKILL.md +0 -136
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/gallery-spec.md +0 -144
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/migration.md +0 -89
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/react.md +0 -69
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/typing.md +0 -173
- package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/vue.md +0 -77
- package/node_modules/playwright-core/lib/tools/skills/playwright-trace/SKILL.md +0 -174
- package/node_modules/playwright-core/lib/tools/utils/extension.js +0 -112
- package/node_modules/playwright-core/lib/tools/utils/socketConnection.js +0 -108
- package/node_modules/playwright-core/lib/utilsBundle.js +0 -86078
- package/node_modules/playwright-core/lib/utilsBundle.js.LICENSE +0 -1890
- package/node_modules/playwright-core/lib/vite/dashboard/assets/codeMirrorModule--QdMvsKi.css +0 -1
- package/node_modules/playwright-core/lib/vite/dashboard/assets/codeMirrorModule-CQ8RZGBm.js +0 -32
- 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 +0 -1
- package/node_modules/playwright-core/lib/vite/dashboard/assets/firefox-beta-k3eOH_eK.svg +0 -1
- package/node_modules/playwright-core/lib/vite/dashboard/assets/firefox-nightly-Cp5nfeDT.svg +0 -1
- package/node_modules/playwright-core/lib/vite/dashboard/assets/index-AwgwcYie.css +0 -1
- package/node_modules/playwright-core/lib/vite/dashboard/assets/index-hRvO4yU2.js +0 -12
- package/node_modules/playwright-core/lib/vite/dashboard/assets/safari-na3_-uQk.svg +0 -1
- package/node_modules/playwright-core/lib/vite/dashboard/index.html +0 -29
- package/node_modules/playwright-core/lib/vite/dashboard/playwright-logo.svg +0 -24
- package/node_modules/playwright-core/lib/vite/htmlReport/index.html +0 -16
- package/node_modules/playwright-core/lib/vite/htmlReport/report.css +0 -2
- package/node_modules/playwright-core/lib/vite/htmlReport/report.js +0 -32
- package/node_modules/playwright-core/lib/vite/recorder/assets/codeMirrorModule--QdMvsKi.css +0 -1
- package/node_modules/playwright-core/lib/vite/recorder/assets/codeMirrorModule-DK72OMRi.js +0 -32
- 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 +0 -1
- package/node_modules/playwright-core/lib/vite/recorder/assets/index-Cn0mmDuv.js +0 -129
- package/node_modules/playwright-core/lib/vite/recorder/index.html +0 -29
- package/node_modules/playwright-core/lib/vite/recorder/playwright-logo.svg +0 -9
- package/node_modules/playwright-core/lib/vite/traceViewer/assets/codeMirrorModule-BEB2e8M3.js +0 -32
- package/node_modules/playwright-core/lib/vite/traceViewer/assets/defaultSettingsView-D-g2vrvf.js +0 -184
- package/node_modules/playwright-core/lib/vite/traceViewer/assets/urlMatch-L3liM589.js +0 -1
- package/node_modules/playwright-core/lib/vite/traceViewer/assets/xtermModule-B794rD2Z.js +0 -7
- package/node_modules/playwright-core/lib/vite/traceViewer/codeMirrorModule.-QdMvsKi.css +0 -1
- 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 +0 -1
- package/node_modules/playwright-core/lib/vite/traceViewer/index.B_TqY17P.css +0 -1
- package/node_modules/playwright-core/lib/vite/traceViewer/index.html +0 -44
- package/node_modules/playwright-core/lib/vite/traceViewer/index.oNry3Hjv.js +0 -1
- package/node_modules/playwright-core/lib/vite/traceViewer/manifest.webmanifest +0 -16
- package/node_modules/playwright-core/lib/vite/traceViewer/playwright-logo.svg +0 -9
- package/node_modules/playwright-core/lib/vite/traceViewer/snapshot.B_Jk1wbt.js +0 -1
- package/node_modules/playwright-core/lib/vite/traceViewer/snapshot.html +0 -10
- package/node_modules/playwright-core/lib/vite/traceViewer/sw.bundle.js +0 -4
- package/node_modules/playwright-core/lib/vite/traceViewer/uiMode.CYwC_gH1.js +0 -5
- package/node_modules/playwright-core/lib/vite/traceViewer/uiMode.CyMfwkXJ.css +0 -1
- package/node_modules/playwright-core/lib/vite/traceViewer/uiMode.html +0 -18
- package/node_modules/playwright-core/lib/vite/traceViewer/xtermModule.kHJ-D0s7.css +0 -1
- package/node_modules/playwright-core/lib/webp_codec.LICENSE +0 -173
- package/node_modules/playwright-core/lib/webp_codec.wasm +0 -0
- package/node_modules/playwright-core/lib/xdg-open +0 -1267
- package/node_modules/playwright-core/package.json +0 -34
- package/node_modules/playwright-core/types/protocol.d.ts +0 -24776
- package/node_modules/playwright-core/types/structs.d.ts +0 -52
- package/node_modules/playwright-core/types/types.d.ts +0 -27167
package/composition.lock.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"suite": "capyclaw-browser-suite",
|
|
3
|
-
"suiteVersion": "0.2.
|
|
3
|
+
"suiteVersion": "0.2.37",
|
|
4
4
|
"packages": {
|
|
5
5
|
"@capyclaw/asset-service": {
|
|
6
6
|
"version": "0.1.4",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"sha256": "9d4da0304feca10046bf7a4891e3413b7beabcac7425cf2939bb86baabb84284"
|
|
28
28
|
},
|
|
29
29
|
"@capyclaw/browser-workbench": {
|
|
30
|
-
"version": "0.1.
|
|
30
|
+
"version": "0.1.18",
|
|
31
31
|
"apiVersion": null,
|
|
32
32
|
"path": "../capyclaw-browser-workbench",
|
|
33
|
-
"sha256": "
|
|
33
|
+
"sha256": "fbeb2949b84302cc6b8f5484ec8b1d86821a928381415b78051243e8afdb95b1"
|
|
34
34
|
},
|
|
35
35
|
"@capyclaw/document-workbench": {
|
|
36
36
|
"version": "0.2.2",
|
package/dsh-suite.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.37",
|
|
5
5
|
"title": "浏览器操控工作台套件",
|
|
6
6
|
"description": "浏览器操控宿主内嵌工作台(挂在 dsh 的 /capyclaw/browser,路由与端口由基建决定;Playwright 引擎、有头可见、登录态持久化)+ 3 个独立 skill 包 + 服务中间件(broker);公共基建(os / toolHost / serviceHost / assets / serviceBroker)由 @capyclaw/core 统一提供,需同一 profile 启用它。",
|
|
7
7
|
"packages": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"version": "^0.2.4",
|
|
11
11
|
"path": "./node_modules/@capyclaw/browser-skill-api",
|
|
12
12
|
"requires": {
|
|
13
|
-
"@capyclaw/browser-workbench": "^0.1.
|
|
13
|
+
"@capyclaw/browser-workbench": "^0.1.18",
|
|
14
14
|
"capabilities": {
|
|
15
15
|
"browser.runtime": "^1.3.0"
|
|
16
16
|
}
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"version": "^0.2.4",
|
|
30
30
|
"path": "./node_modules/@capyclaw/browser-skill-browser",
|
|
31
31
|
"requires": {
|
|
32
|
-
"@capyclaw/browser-workbench": "^0.1.
|
|
32
|
+
"@capyclaw/browser-workbench": "^0.1.18",
|
|
33
33
|
"capabilities": {
|
|
34
34
|
"browser.runtime": "^1.3.0"
|
|
35
35
|
}
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"version": "^0.2.4",
|
|
49
49
|
"path": "./node_modules/@capyclaw/browser-skill-ops",
|
|
50
50
|
"requires": {
|
|
51
|
-
"@capyclaw/browser-workbench": "^0.1.
|
|
51
|
+
"@capyclaw/browser-workbench": "^0.1.18",
|
|
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.18",
|
|
68
68
|
"path": "./node_modules/@capyclaw/browser-workbench",
|
|
69
69
|
"requires": {
|
|
70
70
|
"capabilities": {
|
|
@@ -107,16 +107,82 @@ export function createFileAssetStore({ dir } = {}) {
|
|
|
107
107
|
if (!validId(id)) return false
|
|
108
108
|
try { return fs.existsSync(path.join(dir, path.basename(String(id)))) } catch { return false }
|
|
109
109
|
},
|
|
110
|
+
/** 删除单个对象(data + meta)。内容寻址仓库此前只增不删,磁盘无界增长。 */
|
|
111
|
+
async delete(id) {
|
|
112
|
+
if (!validId(id)) return false
|
|
113
|
+
const file = path.join(dir, path.basename(String(id)))
|
|
114
|
+
let existed = false
|
|
115
|
+
try {
|
|
116
|
+
existed = fs.existsSync(file)
|
|
117
|
+
fs.rmSync(file, { force: true })
|
|
118
|
+
fs.rmSync(file + '.meta.json', { force: true })
|
|
119
|
+
} catch { /* 尽力删除 */ }
|
|
120
|
+
return existed
|
|
121
|
+
},
|
|
122
|
+
/**
|
|
123
|
+
* 垃圾回收:清崩溃残留的孤儿 .tmp、按 mtime 龄淘汰、按总量 LRU 淘汰。
|
|
124
|
+
* keepIds 里的对象(仍被引用)永不删。返回 {removed, freedBytes, orphanTmpRemoved}。
|
|
125
|
+
*/
|
|
126
|
+
async gc({ maxAgeMs = 0, maxBytes = 0, keepIds = [] } = {}) {
|
|
127
|
+
const keep = new Set(keepIds)
|
|
128
|
+
const now = Date.now()
|
|
129
|
+
let removed = 0
|
|
130
|
+
let freedBytes = 0
|
|
131
|
+
let orphanTmpRemoved = 0
|
|
132
|
+
let names
|
|
133
|
+
try { names = fs.readdirSync(dir) } catch { return { removed, freedBytes, orphanTmpRemoved } }
|
|
134
|
+
/* 孤儿 tmp:put 中途崩溃留下的半成品,超过 1h 宽限才清(避免误删在途写入)。 */
|
|
135
|
+
for (const name of names) {
|
|
136
|
+
if (!name.includes('.tmp-')) continue
|
|
137
|
+
const full = path.join(dir, name)
|
|
138
|
+
try {
|
|
139
|
+
const st = fs.statSync(full)
|
|
140
|
+
if (now - st.mtimeMs > 3600000) { fs.rmSync(full, { force: true }); orphanTmpRemoved += 1 }
|
|
141
|
+
} catch { /* 忽略 */ }
|
|
142
|
+
}
|
|
143
|
+
const objects = []
|
|
144
|
+
for (const name of fs.readdirSync(dir)) {
|
|
145
|
+
if (!validId(name)) continue
|
|
146
|
+
const full = path.join(dir, name)
|
|
147
|
+
try { const st = fs.statSync(full); objects.push({ id: name, full, size: st.size, mtime: st.mtimeMs }) } catch { /* 忽略 */ }
|
|
148
|
+
}
|
|
149
|
+
const removeObject = (o) => {
|
|
150
|
+
try {
|
|
151
|
+
fs.rmSync(o.full, { force: true })
|
|
152
|
+
fs.rmSync(o.full + '.meta.json', { force: true })
|
|
153
|
+
removed += 1
|
|
154
|
+
freedBytes += o.size
|
|
155
|
+
} catch { /* 忽略 */ }
|
|
156
|
+
}
|
|
157
|
+
if (maxAgeMs > 0) {
|
|
158
|
+
for (const o of objects) {
|
|
159
|
+
if (!keep.has(o.id) && now - o.mtime > maxAgeMs) removeObject(o)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (maxBytes > 0) {
|
|
163
|
+
const alive = objects.filter((o) => fs.existsSync(o.full)).sort((a, b) => a.mtime - b.mtime)
|
|
164
|
+
let total = alive.reduce((sum, o) => sum + o.size, 0)
|
|
165
|
+
for (const o of alive) {
|
|
166
|
+
if (total <= maxBytes) break
|
|
167
|
+
if (keep.has(o.id)) continue
|
|
168
|
+
removeObject(o)
|
|
169
|
+
total -= o.size
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return { removed, freedBytes, orphanTmpRemoved }
|
|
173
|
+
},
|
|
110
174
|
}
|
|
111
175
|
}
|
|
112
176
|
|
|
113
|
-
/** 防止 text/html / svg 在 loopback 同源执行脚本;图片仍按原 MIME 内联。
|
|
177
|
+
/** 防止 text/html / svg 在 loopback 同源执行脚本;图片仍按原 MIME 内联。
|
|
178
|
+
* 安全类型保留原始参数(charset 等),不再一刀切剥掉——否则文本资产 charset 丢失。 */
|
|
114
179
|
function safeContentType(type) {
|
|
115
|
-
const
|
|
180
|
+
const raw = String(type || '').replace(/[\r\n]/g, '').trim()
|
|
181
|
+
const base = raw.split(';')[0].trim().toLowerCase() || 'application/octet-stream'
|
|
116
182
|
if (base === 'text/html' || base === 'application/xhtml+xml' || base === 'image/svg+xml') {
|
|
117
183
|
return 'text/plain; charset=utf-8'
|
|
118
184
|
}
|
|
119
|
-
return
|
|
185
|
+
return raw || 'application/octet-stream'
|
|
120
186
|
}
|
|
121
187
|
|
|
122
188
|
/**
|
|
@@ -170,7 +236,8 @@ export function createAssetRoutes({ assetStore, basePath = '', maxUploadBytes =
|
|
|
170
236
|
}
|
|
171
237
|
if (!buffer.length) { send(req, res, 400, { error: '图片数据为空' }); return true }
|
|
172
238
|
const asset = await assetStore.put(buffer, body.contentType || 'application/octet-stream')
|
|
173
|
-
|
|
239
|
+
/* 回给与 GET 一致的 sanitized content-type(保留 charset、script 类转 text/plain)。 */
|
|
240
|
+
send(req, res, 200, { ok: true, ...asset, contentType: safeContentType(asset.contentType) })
|
|
174
241
|
return true
|
|
175
242
|
}
|
|
176
243
|
return false
|
|
@@ -184,8 +251,14 @@ export function createAssetHost(config = {}) {
|
|
|
184
251
|
? createFileAssetStore({ dir: config.dir })
|
|
185
252
|
: null
|
|
186
253
|
|
|
254
|
+
/* 能力标签如实申报:gc/delete 仅当底层 store 支持时才 advertise(file store 有,
|
|
255
|
+
* workspace store 无),避免「声明满足、活实例缺方法」。 */
|
|
256
|
+
const tags = ['workspace-store', 'file-store', 'routes', 'sha256', 'mount']
|
|
257
|
+
if (typeof defaultStore?.gc === 'function') tags.push('gc')
|
|
258
|
+
if (typeof defaultStore?.delete === 'function') tags.push('delete')
|
|
259
|
+
|
|
187
260
|
return {
|
|
188
|
-
api: createServiceApi('assets', '1.0.0',
|
|
261
|
+
api: createServiceApi('assets', '1.0.0', tags),
|
|
189
262
|
version: '0.1.0',
|
|
190
263
|
createStore: createWorkspaceAssetStore,
|
|
191
264
|
createFileStore: createFileAssetStore,
|
|
@@ -219,5 +292,13 @@ export function createAssetHost(config = {}) {
|
|
|
219
292
|
if (!defaultStore) throw new Error('asset-service: 未配置 storeClient/dir')
|
|
220
293
|
return defaultStore.get(id)
|
|
221
294
|
},
|
|
295
|
+
async delete(id) {
|
|
296
|
+
if (typeof defaultStore?.delete !== 'function') throw new Error('asset-service: 当前 store 不支持 delete')
|
|
297
|
+
return defaultStore.delete(id)
|
|
298
|
+
},
|
|
299
|
+
async gc(options) {
|
|
300
|
+
if (typeof defaultStore?.gc !== 'function') throw new Error('asset-service: 当前 store 不支持 gc')
|
|
301
|
+
return defaultStore.gc(options)
|
|
302
|
+
},
|
|
222
303
|
}
|
|
223
304
|
}
|
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.18`
|
|
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
|
|
|
@@ -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.18'
|
|
14
14
|
|
|
15
15
|
/** 生成模型可读的能力报告。 */
|
|
16
16
|
export function capabilityReport(args, workbenchUrl = '', runtime = {}) {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
* 缓存的是 Promise<engine>:并发首请求共享同一次创建,不会重复拉起。
|
|
18
18
|
*/
|
|
19
19
|
import path from 'node:path'
|
|
20
|
+
import fs from 'node:fs'
|
|
20
21
|
import { currentSession } from '@capyclaw/document-workbench/session-context'
|
|
21
22
|
|
|
22
23
|
const DEFAULT_SESSION = 'default'
|
|
@@ -140,6 +141,41 @@ export function createSessionEngines({ hostDir, config, createEngine }) {
|
|
|
140
141
|
reapTimer.unref?.()
|
|
141
142
|
}
|
|
142
143
|
|
|
144
|
+
/* ---- 磁盘回收:会话 profile 目录 TTL 清理 ----
|
|
145
|
+
* 进程回收(reap)只挂起浏览器,<hostDir>/sessions/<sid>/ 的 profile 目录从不删,
|
|
146
|
+
* 跨宿主重启越积越多(实测约 40 个陈旧目录)。这里按 mtime TTL 清理「不在本进程
|
|
147
|
+
* 缓存里」的陈旧会话目录——本进程用过的会话常驻 cache,受保护不会被误删;
|
|
148
|
+
* default / login-vault 是共享登录态,永不删。启动即扫一次清历史,之后慢周期巡检。 */
|
|
149
|
+
const sessionDirTtlMs = Number.isFinite(cfg.sessionDirTtlMs) ? cfg.sessionDirTtlMs : 7 * 24 * 3600 * 1000
|
|
150
|
+
const PROTECTED_DIRS = new Set([DEFAULT_SESSION, 'login-vault'])
|
|
151
|
+
async function cleanupSessionDirs() {
|
|
152
|
+
if (sessionDirTtlMs <= 0) return { removed: 0 }
|
|
153
|
+
const sessionsRoot = path.join(hostDir, 'sessions')
|
|
154
|
+
let names
|
|
155
|
+
try { names = fs.readdirSync(sessionsRoot) } catch { return { removed: 0 } }
|
|
156
|
+
const now = Date.now()
|
|
157
|
+
let removed = 0
|
|
158
|
+
for (const name of names) {
|
|
159
|
+
if (PROTECTED_DIRS.has(name) || cache.has(name) || !SID_RE.test(name)) continue
|
|
160
|
+
const full = path.join(sessionsRoot, name)
|
|
161
|
+
try {
|
|
162
|
+
const st = fs.statSync(full)
|
|
163
|
+
if (!st.isDirectory()) continue
|
|
164
|
+
if (now - st.mtimeMs > sessionDirTtlMs) {
|
|
165
|
+
fs.rmSync(full, { recursive: true, force: true })
|
|
166
|
+
removed += 1
|
|
167
|
+
}
|
|
168
|
+
} catch { /* 忽略单个目录失败 */ }
|
|
169
|
+
}
|
|
170
|
+
return { removed }
|
|
171
|
+
}
|
|
172
|
+
let dirCleanupTimer = null
|
|
173
|
+
if (sessionDirTtlMs > 0) {
|
|
174
|
+
cleanupSessionDirs().catch(() => {})
|
|
175
|
+
dirCleanupTimer = setInterval(() => { cleanupSessionDirs().catch(() => {}) }, 3600000)
|
|
176
|
+
dirCleanupTimer.unref?.()
|
|
177
|
+
}
|
|
178
|
+
|
|
143
179
|
/** 停服前挂起所有已创建的引擎(保留标签日志供下次恢复),避免僵尸浏览器进程。
|
|
144
180
|
* 停服竞态:框架先调 beforeStop 再关 HTTP,await 期间仍可能有请求进来重建引擎。
|
|
145
181
|
* 用 drain 循环把「await 期间新创建的」也扫掉(最多 5 轮,防持续流量下无限循环);
|
|
@@ -150,6 +186,7 @@ export function createSessionEngines({ hostDir, config, createEngine }) {
|
|
|
150
186
|
closingPromise = (async () => {
|
|
151
187
|
try {
|
|
152
188
|
if (reapTimer) { clearInterval(reapTimer); reapTimer = null }
|
|
189
|
+
if (dirCleanupTimer) { clearInterval(dirCleanupTimer); dirCleanupTimer = null }
|
|
153
190
|
for (let pass = 0; pass < 5; pass += 1) {
|
|
154
191
|
const pending = [...cache.values()]
|
|
155
192
|
cache.clear()
|
|
@@ -180,5 +217,7 @@ export function createSessionEngines({ hostDir, config, createEngine }) {
|
|
|
180
217
|
sessions: () => [...cache.keys()],
|
|
181
218
|
/* 手动触发一次回收巡检(测试用;生产由定时器驱动)。 */
|
|
182
219
|
reapNow: () => reap(),
|
|
220
|
+
/* 手动触发一次会话目录磁盘清理(测试用;生产启动+慢周期驱动)。 */
|
|
221
|
+
cleanupSessionDirsNow: () => cleanupSessionDirs(),
|
|
183
222
|
}
|
|
184
223
|
}
|
|
@@ -18,15 +18,25 @@ import { AsyncLocalStorage } from 'node:async_hooks'
|
|
|
18
18
|
|
|
19
19
|
const storage = new AsyncLocalStorage()
|
|
20
20
|
|
|
21
|
-
/** 在指定会话的上下文里跑一段逻辑(await 链与定时器都会继承)。
|
|
21
|
+
/** 在指定会话的上下文里跑一段逻辑(await 链与定时器都会继承)。
|
|
22
|
+
* payload 是对象而非裸字符串:除会话 id 外还携带一个「本请求已钉住的 store」槽位,
|
|
23
|
+
* 让 store 门面在请求内首次访问时解析一次并复用,避免请求中途 active 被别的窗口
|
|
24
|
+
* /activate 翻转后,同一请求的后续写入改向到另一个会话(跨会话写)。 */
|
|
22
25
|
export function runWithSession(sessionId, fn) {
|
|
23
|
-
return storage.run(String(sessionId || ''), fn)
|
|
26
|
+
return storage.run({ sid: String(sessionId || ''), pinned: null }, fn)
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
/** 当前请求所属的会话 id;不在请求里时返回空串。 */
|
|
27
30
|
export function currentSession() {
|
|
28
31
|
const value = storage.getStore()
|
|
29
|
-
return typeof value === 'string' ? value : ''
|
|
32
|
+
return value && typeof value.sid === 'string' ? value.sid : ''
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 当前请求的会话上下文对象({sid, pinned});不在请求里时返回 null。
|
|
36
|
+
* store 门面用它把「本请求用哪一份 store」钉住一次,整个请求复用。 */
|
|
37
|
+
export function sessionContext() {
|
|
38
|
+
const value = storage.getStore()
|
|
39
|
+
return value && typeof value === 'object' ? value : null
|
|
30
40
|
}
|
|
31
41
|
|
|
32
42
|
/**
|
|
@@ -58,8 +68,10 @@ export function bindToolsToCallerSession(registry) {
|
|
|
58
68
|
const bound = (args, exec) => {
|
|
59
69
|
const sid = sessionFromExec(exec)
|
|
60
70
|
/* exec 原样透传:今天的实现体只用 args,但未来若有工具要执行上下文
|
|
61
|
-
* (进度/中止等),不能在这层被静默丢掉。
|
|
62
|
-
|
|
71
|
+
* (进度/中止等),不能在这层被静默丢掉。
|
|
72
|
+
* 即使拿不到调用者会话(MCP 传输形态)也建立上下文:store 门面会在本次调用
|
|
73
|
+
* 首次访问时把「最近聚焦窗口」钉住,整个工具执行期间不再随 active 翻转改向。 */
|
|
74
|
+
return runWithSession(sid, () => impl(args, exec))
|
|
63
75
|
}
|
|
64
76
|
bound.__sessionBound = true
|
|
65
77
|
impls[name] = bound
|
|
@@ -44,18 +44,19 @@ export function createRawAdapter({ log }) {
|
|
|
44
44
|
|
|
45
45
|
if (thenable(result)) {
|
|
46
46
|
let instance = {}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
})
|
|
47
|
+
/* apply 结算只做归一化,绝不在此 eagerly 跑 instance.start()——旧实现
|
|
48
|
+
* 在 compile 返回的 promise resolve 时就启动,绕过 loader 的 start 阶段与
|
|
49
|
+
* stopRequested:loader 正在回滚/已请求卸载时 raw 仍会起进程/监听。
|
|
50
|
+
* start 交给 loader 在 start 阶段显式触发(此时才尊重 stopRequested)。 */
|
|
51
|
+
const ready = Promise.resolve(result).then((value) => { instance = normalize(value) })
|
|
53
52
|
return {
|
|
54
|
-
start: () =>
|
|
53
|
+
start: async ({ signal } = {}) => {
|
|
54
|
+
await ready
|
|
55
|
+
/* 转发 loader 的卸载 signal,让 raw 实例的 start 也能感知取消。 */
|
|
56
|
+
return instance.start ? instance.start({ signal }) : undefined
|
|
57
|
+
},
|
|
55
58
|
dispose: async () => {
|
|
56
|
-
|
|
57
|
-
try { await started } catch { /* start 失败由 loader 记录 */ }
|
|
58
|
-
}
|
|
59
|
+
try { await ready } catch { /* apply 失败由 loader 记录 */ }
|
|
59
60
|
if (typeof instance.dispose === 'function') return instance.dispose()
|
|
60
61
|
},
|
|
61
62
|
}
|
|
@@ -62,14 +62,21 @@ export function createRuntimeDriverAdapter({ host, config, log }) {
|
|
|
62
62
|
...(impl.args || []),
|
|
63
63
|
]
|
|
64
64
|
|
|
65
|
+
/* keepAlive 由声明推导:restart.max===0 表示「不要自动重启」,对应 keepAlive:false。
|
|
66
|
+
* 旧实现恒 true,应用声明 restart:{max:0} 仍被 broker 拉起,切换/回收行为与声明不符。 */
|
|
67
|
+
const keepAlive = !(impl.restart && impl.restart.max === 0)
|
|
65
68
|
const serviceSpec = {
|
|
66
69
|
id: impl.id,
|
|
67
70
|
cmd,
|
|
68
71
|
ports: { main: port },
|
|
69
72
|
url: 'http://127.0.0.1:${PORT}/',
|
|
70
|
-
keepAlive
|
|
73
|
+
keepAlive,
|
|
71
74
|
}
|
|
72
75
|
if (impl.health?.path) serviceSpec.healthPath = impl.health.path
|
|
76
|
+
/* 声明的健康期望/超时与重启策略必须透传给 broker,不能被静默丢弃。 */
|
|
77
|
+
if (impl.health?.expect && typeof impl.health.expect === 'object') serviceSpec.expect = impl.health.expect
|
|
78
|
+
if (impl.health?.timeoutMs) serviceSpec.waitMs = impl.health.timeoutMs
|
|
79
|
+
if (impl.restart) serviceSpec.restart = impl.restart
|
|
73
80
|
if (impl.dir) {
|
|
74
81
|
serviceSpec.cwd = fileURLToPath(new URL(impl.dir, mountContext.context.baseUrl))
|
|
75
82
|
}
|
|
@@ -13,12 +13,40 @@ const NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
|
|
|
13
13
|
const DEFAULT_RANK = 600
|
|
14
14
|
|
|
15
15
|
export function parseSkill(raw, path) {
|
|
16
|
+
/* BOM 会让 /^---/ 匹配不到 frontmatter,误报「缺少 YAML frontmatter」。先剥掉。 */
|
|
17
|
+
raw = raw.replace(/^\uFEFF/, '')
|
|
16
18
|
const frontmatter = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/u.exec(raw)
|
|
17
19
|
if (!frontmatter?.[1]) throw new Error(`skill ${path} 缺少 YAML frontmatter`)
|
|
18
20
|
const meta = {}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
const lines = frontmatter[1].split(/\r?\n/)
|
|
22
|
+
for (let i = 0; i < lines.length; i++) {
|
|
23
|
+
const match = /^([A-Za-z0-9_-]+):\s*(.*)$/.exec(lines[i])
|
|
24
|
+
if (!match) continue
|
|
25
|
+
const key = match[1]
|
|
26
|
+
let value = match[2].trim()
|
|
27
|
+
/* 块标量 description: | / > :旧实现把 '|' 本身当成描述直达 LLM,多行正文全丢。
|
|
28
|
+
* 这里聚合后续缩进行,| 保留换行、> 折叠为空格,按 chomping 处理尾部空白。 */
|
|
29
|
+
const block = /^([|>])([+-]?)$/.exec(value)
|
|
30
|
+
if (block) {
|
|
31
|
+
const body = []
|
|
32
|
+
let j = i + 1
|
|
33
|
+
for (; j < lines.length; j++) {
|
|
34
|
+
const ln = lines[j]
|
|
35
|
+
if (ln.trim() === '') { body.push(''); continue }
|
|
36
|
+
if (/^\s/.test(ln)) body.push(ln)
|
|
37
|
+
else break
|
|
38
|
+
}
|
|
39
|
+
i = j - 1
|
|
40
|
+
const nonEmpty = body.filter((l) => l.trim() !== '')
|
|
41
|
+
const minIndent = nonEmpty.length ? Math.min(...nonEmpty.map((l) => /^\s*/.exec(l)[0].length)) : 0
|
|
42
|
+
const stripped = body.map((l) => l.slice(minIndent))
|
|
43
|
+
let text = stripped.join(block[1] === '>' ? ' ' : '\n')
|
|
44
|
+
if (block[2] !== '+') text = text.replace(/\s+$/, '')
|
|
45
|
+
value = text
|
|
46
|
+
} else {
|
|
47
|
+
value = value.replace(/^['"]|['"]$/g, '').trim()
|
|
48
|
+
}
|
|
49
|
+
meta[key] = value
|
|
22
50
|
}
|
|
23
51
|
if (!meta.name || !meta.description) throw new Error(`skill ${path} 缺少 name/description`)
|
|
24
52
|
if (!NAME_RE.test(meta.name)) throw new Error(`skill ${path} name 必须是 kebab-case`)
|
|
@@ -22,12 +22,19 @@ function reply(id, result) {
|
|
|
22
22
|
|
|
23
23
|
export function createMcpHandler({
|
|
24
24
|
tools = [], callTool, serverInfo, instructions,
|
|
25
|
-
maxBodyBytes = 10 * 1024 * 1024, maxBatch = 100,
|
|
25
|
+
maxBodyBytes = 10 * 1024 * 1024, maxBatch = 100, listChanged = false,
|
|
26
26
|
} = {}) {
|
|
27
|
-
|
|
27
|
+
/* tools 可以是静态数组,或一个返回当前数组的函数(活引用)。活引用让
|
|
28
|
+
* tools/list 每次读到最新工具集——registry 动态增删工具后无需重建 handler。 */
|
|
29
|
+
const liveProvider = typeof tools === 'function' ? tools : null
|
|
30
|
+
if (!liveProvider && !Array.isArray(tools)) throw new Error('createMcpHandler: tools 必须是数组或返回数组的函数')
|
|
28
31
|
if (typeof callTool !== 'function') throw new Error('createMcpHandler: callTool 必须是函数')
|
|
29
32
|
|
|
30
|
-
const
|
|
33
|
+
const currentTools = () => {
|
|
34
|
+
const list = liveProvider ? liveProvider() : tools
|
|
35
|
+
return Array.isArray(list) ? list : []
|
|
36
|
+
}
|
|
37
|
+
const toolMapNow = () => new Map(currentTools().map((tool) => [tool.name, tool]))
|
|
31
38
|
|
|
32
39
|
return async function handle(req, res) {
|
|
33
40
|
/* 长工具调用(如截图)期间客户端可能超时断连;socket 的 'error' 事件
|
|
@@ -89,7 +96,7 @@ export function createMcpHandler({
|
|
|
89
96
|
if (method === 'initialize') {
|
|
90
97
|
const result = {
|
|
91
98
|
protocolVersion: String(params?.protocolVersion || DEFAULT_PROTOCOL),
|
|
92
|
-
capabilities: { tools: { listChanged:
|
|
99
|
+
capabilities: { tools: { listChanged: !!listChanged } },
|
|
93
100
|
serverInfo: serverInfo || { name: 'dsh-plugin', version: '0.0.0' },
|
|
94
101
|
}
|
|
95
102
|
if (typeof instructions === 'string' && instructions) result.instructions = instructions
|
|
@@ -101,13 +108,13 @@ export function createMcpHandler({
|
|
|
101
108
|
if (method === 'ping') return isNotification ? null : reply(id, {})
|
|
102
109
|
|
|
103
110
|
if (method === 'tools/list') {
|
|
104
|
-
return isNotification ? null : reply(id, { tools })
|
|
111
|
+
return isNotification ? null : reply(id, { tools: currentTools() })
|
|
105
112
|
}
|
|
106
113
|
|
|
107
114
|
if (method === 'tools/call') {
|
|
108
115
|
const name = params?.name
|
|
109
116
|
const args = params?.arguments && typeof params.arguments === 'object' ? params.arguments : {}
|
|
110
|
-
const tool =
|
|
117
|
+
const tool = toolMapNow().get(name)
|
|
111
118
|
if (!tool) {
|
|
112
119
|
if (isNotification) return null
|
|
113
120
|
return reply(id, {
|
|
@@ -14,24 +14,40 @@
|
|
|
14
14
|
* 返回恒为 {content:[...]}(object),因此 DSH 原生面 output.schema 用 object 恒满足。
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
export
|
|
17
|
+
/** 单个 text 块的默认上限:防 base64/大输出撑爆 LLM 上下文。image 块不受影响。 */
|
|
18
|
+
export const DEFAULT_MAX_TEXT_BYTES = 256 * 1024
|
|
19
|
+
|
|
20
|
+
function capText(text, max) {
|
|
21
|
+
if (!max || max <= 0 || typeof text !== 'string' || text.length <= max) return text
|
|
22
|
+
return `${text.slice(0, max)}\n…[truncated: original ${text.length} chars, limit ${max}]`
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function capContent(content, max) {
|
|
26
|
+
return content.map((block) => (
|
|
27
|
+
block && block.type === 'text' && typeof block.text === 'string'
|
|
28
|
+
? { ...block, text: capText(block.text, max) }
|
|
29
|
+
: block
|
|
30
|
+
))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 把任意工具返回值归一为 MCP content 形态(并对超限 text 块截断+提示)。 */
|
|
34
|
+
export function normalizeToolResult(out, { maxTextBytes = DEFAULT_MAX_TEXT_BYTES } = {}) {
|
|
19
35
|
const isError = out && typeof out.isError === 'boolean' ? { isError: out.isError } : {}
|
|
36
|
+
let content
|
|
20
37
|
if (out && Array.isArray(out.content)) {
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
38
|
+
content = out.content
|
|
39
|
+
} else if (out && typeof out.text === 'string') {
|
|
40
|
+
content = [{ type: 'text', text: out.text }]
|
|
41
|
+
} else if (typeof out === 'string') {
|
|
42
|
+
content = [{ type: 'text', text: out }]
|
|
43
|
+
} else if (out === undefined || out === null) {
|
|
44
|
+
content = [{ type: 'text', text: '' }]
|
|
45
|
+
} else {
|
|
46
|
+
let text
|
|
47
|
+
try { text = JSON.stringify(out) } catch { text = String(out) }
|
|
48
|
+
content = [{ type: 'text', text: text ?? String(out) }]
|
|
31
49
|
}
|
|
32
|
-
|
|
33
|
-
try { text = JSON.stringify(out) } catch { text = String(out) }
|
|
34
|
-
return { content: [{ type: 'text', text: text ?? String(out) }] }
|
|
50
|
+
return { content: capContent(content, maxTextBytes), ...isError }
|
|
35
51
|
}
|
|
36
52
|
|
|
37
53
|
/** 从归一化结果提取纯文本(用于把失败内容拼成 Error.message)。 */
|
|
@@ -28,6 +28,22 @@ function anyTypeMatches(patterns, type) {
|
|
|
28
28
|
return (patterns || []).some((p) => typeMatches(p, type))
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/** 双向通配匹配:声明侧或查询侧任一带 `/*` 通配都要能命中。
|
|
32
|
+
* 旧实现只把声明当 pattern、查询当 type,查询侧通配(conductor 问「谁产出
|
|
33
|
+
* artifact:image/*」)永远不命中具体类型。 */
|
|
34
|
+
function typesOverlap(declPatterns, queryType) {
|
|
35
|
+
return (declPatterns || []).some((p) => typeMatches(p, queryType) || typeMatches(queryType, p))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 深冻结:描述符的 produces/consumes/surface/provides 等嵌套结构也要不可变,
|
|
39
|
+
* 否则注册后仍能被外部改写,注册表的「单一真源」失真。 */
|
|
40
|
+
function deepFreeze(value) {
|
|
41
|
+
if (!value || typeof value !== 'object' || Object.isFrozen(value)) return value
|
|
42
|
+
Object.freeze(value)
|
|
43
|
+
for (const key of Object.keys(value)) deepFreeze(value[key])
|
|
44
|
+
return value
|
|
45
|
+
}
|
|
46
|
+
|
|
31
47
|
/** 最小结构兜底:name/suite/controlMode/kind 必须在场且合法。深度校验走注入的 validate。 */
|
|
32
48
|
function structuralCheck(descriptor) {
|
|
33
49
|
const errors = []
|
|
@@ -48,7 +64,7 @@ export function createDescriptorRegistry({ validate } = {}) {
|
|
|
48
64
|
/** @type {Map<string, {descriptor:object, suite:string, baseUrl:string, registeredAt:number}>} */
|
|
49
65
|
const entries = new Map()
|
|
50
66
|
|
|
51
|
-
function register(descriptor, { suite, baseUrl = '' } = {}) {
|
|
67
|
+
function register(descriptor, { suite, baseUrl = '', force = false } = {}) {
|
|
52
68
|
const merged = { ...descriptor, suite: descriptor?.suite || suite }
|
|
53
69
|
const errors = structuralCheck(merged)
|
|
54
70
|
if (errors.length) {
|
|
@@ -64,8 +80,16 @@ export function createDescriptorRegistry({ validate } = {}) {
|
|
|
64
80
|
throw err
|
|
65
81
|
}
|
|
66
82
|
}
|
|
83
|
+
/* owner 校验:同名描述符已属另一套件时拒绝静默覆盖(防跨套件抢占);
|
|
84
|
+
* 同套件热重载刷新放行,确需跨套件替换须显式 force。 */
|
|
85
|
+
const existing = entries.get(merged.name)
|
|
86
|
+
if (existing && existing.suite !== merged.suite && !force) {
|
|
87
|
+
const err = new Error(`能力描述符 ${merged.name} 已属套件 ${existing.suite},套件 ${merged.suite} 不能覆盖(如确需替换请传 force)`)
|
|
88
|
+
err.code = 'DESCRIPTOR_OWNER_CONFLICT'
|
|
89
|
+
throw err
|
|
90
|
+
}
|
|
67
91
|
const entry = Object.freeze({
|
|
68
|
-
descriptor:
|
|
92
|
+
descriptor: deepFreeze({ ...merged }),
|
|
69
93
|
suite: merged.suite,
|
|
70
94
|
baseUrl: String(baseUrl || ''),
|
|
71
95
|
registeredAt: Date.now(),
|
|
@@ -92,8 +116,8 @@ export function createDescriptorRegistry({ validate } = {}) {
|
|
|
92
116
|
if (query.suite && entry.suite !== query.suite) continue
|
|
93
117
|
if (query.controlMode && d.controlMode !== query.controlMode) continue
|
|
94
118
|
if (query.kind && d.kind !== query.kind) continue
|
|
95
|
-
if (query.produces && !
|
|
96
|
-
if (query.consumes && !
|
|
119
|
+
if (query.produces && !typesOverlap(d.produces, query.produces)) continue
|
|
120
|
+
if (query.consumes && !typesOverlap(d.consumes, query.consumes)) continue
|
|
97
121
|
out.push(entry)
|
|
98
122
|
}
|
|
99
123
|
return out
|