@capyclaw/browser-workbench 0.0.0-stage → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -2
- package/contract/browser-contract.json +1349 -0
- package/demo/form.html +112 -0
- package/lib/host.mjs +1 -0
- package/node_modules/@capyclaw/asset-service/README.md +48 -0
- package/node_modules/@capyclaw/asset-service/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/asset-service/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/asset-service/lib/host.mjs +14 -0
- package/node_modules/@capyclaw/asset-service/package.json +59 -0
- package/node_modules/@capyclaw/asset-service/src/index.mjs +304 -0
- package/node_modules/@capyclaw/document-workbench/README.md +125 -0
- package/node_modules/@capyclaw/document-workbench/package.json +44 -0
- package/node_modules/@capyclaw/document-workbench/src/bridge/index.mjs +321 -0
- package/node_modules/@capyclaw/document-workbench/src/client/index.mjs +625 -0
- package/node_modules/@capyclaw/document-workbench/src/client/screenshot.mjs +98 -0
- package/node_modules/@capyclaw/document-workbench/src/index.mjs +9 -0
- package/node_modules/@capyclaw/document-workbench/src/model/audit.mjs +101 -0
- package/node_modules/@capyclaw/document-workbench/src/model/conformance.mjs +92 -0
- package/node_modules/@capyclaw/document-workbench/src/model/ids.mjs +56 -0
- package/node_modules/@capyclaw/document-workbench/src/model/index.mjs +18 -0
- package/node_modules/@capyclaw/document-workbench/src/model/locate.mjs +118 -0
- package/node_modules/@capyclaw/document-workbench/src/model/manifest.mjs +148 -0
- package/node_modules/@capyclaw/document-workbench/src/model/ops.mjs +160 -0
- package/node_modules/@capyclaw/document-workbench/src/model/validate.mjs +72 -0
- package/node_modules/@capyclaw/document-workbench/src/ops/index.mjs +93 -0
- package/node_modules/@capyclaw/document-workbench/src/session/context.mjs +103 -0
- package/node_modules/@capyclaw/document-workbench/src/session/index.mjs +394 -0
- package/node_modules/@capyclaw/document-workbench/src/session/lease.mjs +105 -0
- package/node_modules/@capyclaw/document-workbench/src/session/mode.mjs +80 -0
- package/node_modules/@capyclaw/document-workbench/src/session/sanitize.mjs +107 -0
- package/node_modules/@capyclaw/document-workbench/src/session/state.mjs +159 -0
- package/node_modules/@capyclaw/document-workbench/src/session/watch.mjs +63 -0
- package/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 +58 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/shadow.mjs +219 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/transport.js +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/index.mjs +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/pack.mjs +230 -0
- package/node_modules/@capyclaw/plugin-kit/src/runtime/context.mjs +128 -0
- package/node_modules/@capyclaw/plugin-kit/src/self-contained.mjs +307 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/api.mjs +45 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/http.mjs +113 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/server.mjs +131 -0
- package/node_modules/@capyclaw/plugin-kit/src/skills/provider.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/blob-store.mjs +109 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/content-store.mjs +17 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/journal-store.mjs +89 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/result.mjs +57 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/validate.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/tuning.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/fs-lock.mjs +132 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/http.mjs +130 -0
- package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +656 -0
- package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +181 -0
- package/node_modules/@capyclaw/service-host/README.md +86 -0
- package/node_modules/@capyclaw/service-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/service-host/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/service-host/lib/host.mjs +22 -0
- package/node_modules/@capyclaw/service-host/package.json +60 -0
- package/node_modules/@capyclaw/service-host/src/index.mjs +571 -0
- package/node_modules/@capyclaw/service-host/src/tuning.mjs +63 -0
- package/node_modules/@capyclaw/tool-host/README.md +56 -0
- package/node_modules/@capyclaw/tool-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/tool-host/dsh-suite.json +30 -0
- package/node_modules/@capyclaw/tool-host/lib/host.mjs +16 -0
- package/node_modules/@capyclaw/tool-host/package.json +59 -0
- package/node_modules/@capyclaw/tool-host/src/descriptors.mjs +166 -0
- package/node_modules/@capyclaw/tool-host/src/index.mjs +416 -0
- package/package.json +77 -4
- package/plugin.mjs +1 -0
- package/server/constants.mjs +16 -0
- package/server/contract-snapshots.mjs +81 -0
- package/server/contract.mjs +24 -0
- package/server/embedded-host.mjs +247 -0
- package/server/engine.mjs +2466 -0
- package/server/governor.mjs +189 -0
- package/server/http-utils.mjs +2 -0
- package/server/human.mjs +628 -0
- package/server/infra/http.mjs +2 -0
- package/server/infra/tuning.mjs +2 -0
- package/server/input.mjs +154 -0
- package/server/login-vault.mjs +109 -0
- package/server/mcp/handler.mjs +2 -0
- package/server/mcp/instructions.mjs +31 -0
- package/server/orphans.mjs +163 -0
- package/server/relay.mjs +198 -0
- package/server/routes/api.mjs +233 -0
- package/server/routes/assets.mjs +2 -0
- package/server/routes/mcp.mjs +17 -0
- package/server/routes/workbench.mjs +33 -0
- package/server/session-engines.mjs +223 -0
- package/server/shared/SHARED_MANIFEST.json +70 -0
- package/server/shared/asset-service.mjs +2 -0
- package/server/shared/editor-host.mjs +2 -0
- package/server/shared/kit/editor/lease.mjs +2 -0
- package/server/shared/kit/service/api.mjs +2 -0
- package/server/shared/kit/service/http.mjs +2 -0
- package/server/shared/kit/service/mcp-http.mjs +2 -0
- package/server/shared/kit/tools/validate.mjs +2 -0
- package/server/shared/kit/tuning.mjs +2 -0
- package/server/shared/kit/util/fs-lock.mjs +2 -0
- package/server/shared/service-host.mjs +2 -0
- package/server/shared/tool-host.mjs +2 -0
- package/server/shared/tuning.mjs +2 -0
- package/server/tools/capabilities/contract.mjs +55 -0
- package/server/tools/capabilities/evaluate.mjs +36 -0
- package/server/tools/capabilities/index.mjs +26 -0
- package/server/tools/capabilities/interaction.mjs +215 -0
- package/server/tools/capabilities/navigation.mjs +35 -0
- package/server/tools/capabilities/screenshot.mjs +50 -0
- package/server/tools/capabilities/session.mjs +81 -0
- package/server/tools/capabilities/snapshot.mjs +30 -0
- package/server/tools/capabilities/tabs.mjs +35 -0
- package/server/tools/index.mjs +12 -0
- package/server/tools/kernel/define.mjs +5 -0
- package/server/tools/kernel/output.mjs +30 -0
- package/server/tools/kernel/ports.mjs +59 -0
- package/server/tools/kernel/registry.mjs +17 -0
- package/server/tools.mjs +3 -0
- package/server/workbench-framework.mjs +305 -0
- package/ui/app.js +447 -0
- package/ui/index.html +46 -0
- package/ui/style.css +144 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../capyclaw-suite-kit/suite.schema.json",
|
|
3
|
+
"name": "dsh-tool-host-suite",
|
|
4
|
+
"version": "0.2.0",
|
|
5
|
+
"title": "Tool Host",
|
|
6
|
+
"description": "通用工具面:能力 DSL、注册表、校验、契约、MCP 壳、跨套件能力描述符注册/发现。",
|
|
7
|
+
"packages": {
|
|
8
|
+
"@capyclaw/tool-host": {
|
|
9
|
+
"role": "provider",
|
|
10
|
+
"version": "^0.2.0",
|
|
11
|
+
"path": ".",
|
|
12
|
+
"provides": {
|
|
13
|
+
"services": [
|
|
14
|
+
"toolHost"
|
|
15
|
+
],
|
|
16
|
+
"capabilities": {
|
|
17
|
+
"tools.registry": "1.0.0",
|
|
18
|
+
"tools.descriptors": "1.1.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"rows": [
|
|
24
|
+
{
|
|
25
|
+
"id": "tool-host",
|
|
26
|
+
"name": "@capyclaw/tool-host"
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"checks": []
|
|
30
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @capyclaw/tool-host 插件:向同进程插件提供 ctx.toolHost。
|
|
3
|
+
*/
|
|
4
|
+
import { defineDriver } from '@capyclaw/foundation/abi'
|
|
5
|
+
import { createToolHost } from '../src/index.mjs'
|
|
6
|
+
|
|
7
|
+
export const { name, inject, apply } = defineDriver({
|
|
8
|
+
name: 'tool-host',
|
|
9
|
+
service: 'toolHost',
|
|
10
|
+
apply(ctx, config = {}) {
|
|
11
|
+
const service = createToolHost(config)
|
|
12
|
+
const dispose = ctx.provide('toolHost', service)
|
|
13
|
+
console.log('[tool-host] ready')
|
|
14
|
+
return () => { if (typeof dispose === 'function') dispose() }
|
|
15
|
+
},
|
|
16
|
+
})
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capyclaw/tool-host",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "DSH 公共工具面插件:能力 DSL、工具注册表、参数校验、契约报告、MCP 协议壳与 instructions 模板,向插件提供 ctx.toolHost。",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./lib/host.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./lib/host.mjs",
|
|
9
|
+
"./src": "./src/index.mjs",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=18",
|
|
14
|
+
"dsh": "^0.2.0-rc.2"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"dsh": {
|
|
20
|
+
"bundle": {
|
|
21
|
+
"patch": "./cordis.patch.yml"
|
|
22
|
+
},
|
|
23
|
+
"suite": "./dsh-suite.json",
|
|
24
|
+
"apiVersion": "1.1.0",
|
|
25
|
+
"category": "service",
|
|
26
|
+
"platform": "both",
|
|
27
|
+
"driver": {
|
|
28
|
+
"service": "toolHost"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"meta": {
|
|
32
|
+
"title": "公共服务工具面",
|
|
33
|
+
"description": "能力 DSL、工具注册表、参数校验、契约报告与 MCP 协议壳,向插件提供 ctx.toolHost"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"lib/",
|
|
37
|
+
"src/",
|
|
38
|
+
"cordis.patch.yml",
|
|
39
|
+
"dsh-suite.json",
|
|
40
|
+
"README.md"
|
|
41
|
+
],
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"scripts": {
|
|
44
|
+
"test": "node --test --test-isolation=none test/*.test.mjs"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@capyclaw/plugin-kit": "^0.2.0",
|
|
48
|
+
"@capyclaw/foundation": "^0.1.1"
|
|
49
|
+
},
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "git+https://github.com/Maple496/capyclaw.git",
|
|
53
|
+
"directory": "C/packages/capyclaw-tool-host"
|
|
54
|
+
},
|
|
55
|
+
"bugs": {
|
|
56
|
+
"url": "https://github.com/Maple496/capyclaw/issues"
|
|
57
|
+
},
|
|
58
|
+
"homepage": "https://github.com/Maple496/capyclaw/tree/main/C/packages/capyclaw-tool-host#readme"
|
|
59
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 能力描述符注册表(互联标准 v0.2 §A.4 / §E「broker 注册发现」的公共落点)。
|
|
3
|
+
*
|
|
4
|
+
* 定位:tool-host 已是公共工具面(defineCapability/createRegistry),这里再补一层
|
|
5
|
+
* 「跨套件能力发现」——每个套件把自己的能力描述符 + 调用地址登记进来,编排器
|
|
6
|
+
* (conductor 这类平级作品)按 produces/consumes/controlMode 动态发现,不硬 import 任何套件。
|
|
7
|
+
*
|
|
8
|
+
* 解耦口径(标准 §1):
|
|
9
|
+
* - 注册表只认「描述符 + 地址」,不认套件实现;套件之间零互依赖。
|
|
10
|
+
* - 描述符的深度校验交给注入的 validate(通常是 @capyclaw/suite-kit/capability 的
|
|
11
|
+
* validateCapabilityDescriptor);本模块只做最小结构兜底,保持零依赖、可单测。
|
|
12
|
+
* - baseUrl 是套件的调用入口(service-host 的 app.url,embedded 模式也有值),
|
|
13
|
+
* 编排器据此走 HTTP MCP tools/call,而不是 ctx.tools.execute(后者需要 Agent scope,太重)。
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const CONTROL_MODES = new Set(['interface', 'browser'])
|
|
17
|
+
const KINDS = new Set(['read', 'write', 'control'])
|
|
18
|
+
|
|
19
|
+
/** 结尾 `/*` 前缀通配:`artifact:image/*` 命中 `artifact:image/png`。 */
|
|
20
|
+
function typeMatches(pattern, type) {
|
|
21
|
+
if (!pattern || !type) return false
|
|
22
|
+
if (pattern === type) return true
|
|
23
|
+
if (pattern.endsWith('/*')) return type.startsWith(pattern.slice(0, -1))
|
|
24
|
+
return false
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function anyTypeMatches(patterns, type) {
|
|
28
|
+
return (patterns || []).some((p) => typeMatches(p, type))
|
|
29
|
+
}
|
|
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
|
+
|
|
47
|
+
/** 最小结构兜底:name/suite/controlMode/kind 必须在场且合法。深度校验走注入的 validate。 */
|
|
48
|
+
function structuralCheck(descriptor) {
|
|
49
|
+
const errors = []
|
|
50
|
+
if (!descriptor || typeof descriptor !== 'object') return ['descriptor 必须是对象']
|
|
51
|
+
if (!descriptor.name || typeof descriptor.name !== 'string') errors.push('缺少 name')
|
|
52
|
+
if (!descriptor.suite || typeof descriptor.suite !== 'string') errors.push('缺少 suite')
|
|
53
|
+
if (!descriptor.capability || typeof descriptor.capability !== 'string') errors.push('缺少 capability(能力语义)')
|
|
54
|
+
if (!CONTROL_MODES.has(descriptor.controlMode)) errors.push(`controlMode 必须是 interface|browser,收到 ${descriptor.controlMode}`)
|
|
55
|
+
if (!KINDS.has(descriptor.kind)) errors.push(`kind 必须是 read|write|control,收到 ${descriptor.kind}`)
|
|
56
|
+
return errors
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {{ validate?: (d:object)=>{ok:boolean,errors?:string[]} }} [options]
|
|
61
|
+
* validate 可选注入(suite-kit 的深度校验器)。缺省只做结构兜底。
|
|
62
|
+
*/
|
|
63
|
+
export function createDescriptorRegistry({ validate } = {}) {
|
|
64
|
+
/** @type {Map<string, {descriptor:object, suite:string, baseUrl:string, registeredAt:number}>} */
|
|
65
|
+
const entries = new Map()
|
|
66
|
+
|
|
67
|
+
function register(descriptor, { suite, baseUrl = '', force = false } = {}) {
|
|
68
|
+
const merged = { ...descriptor, suite: descriptor?.suite || suite }
|
|
69
|
+
const errors = structuralCheck(merged)
|
|
70
|
+
if (errors.length) {
|
|
71
|
+
const err = new Error(`能力描述符不合法: ${errors.join('; ')}`)
|
|
72
|
+
err.code = 'DESCRIPTOR_INVALID'
|
|
73
|
+
throw err
|
|
74
|
+
}
|
|
75
|
+
if (typeof validate === 'function') {
|
|
76
|
+
const verdict = validate(merged)
|
|
77
|
+
if (verdict && verdict.ok === false) {
|
|
78
|
+
const err = new Error(`能力描述符不合法: ${(verdict.errors || []).join('; ')}`)
|
|
79
|
+
err.code = 'DESCRIPTOR_INVALID'
|
|
80
|
+
throw err
|
|
81
|
+
}
|
|
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
|
+
}
|
|
91
|
+
const entry = Object.freeze({
|
|
92
|
+
descriptor: deepFreeze({ ...merged }),
|
|
93
|
+
suite: merged.suite,
|
|
94
|
+
baseUrl: String(baseUrl || ''),
|
|
95
|
+
registeredAt: Date.now(),
|
|
96
|
+
})
|
|
97
|
+
// 同名幂等覆盖:套件热重载/重新激活时直接刷新,不产生重复。
|
|
98
|
+
entries.set(merged.name, entry)
|
|
99
|
+
return entry
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function unregister(name) {
|
|
103
|
+
return entries.delete(name)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 按条件发现。produces/consumes 用类型词表匹配(含 `/*` 通配)。
|
|
108
|
+
* @param {{ name?:string, suite?:string, controlMode?:string, kind?:string,
|
|
109
|
+
* produces?:string, consumes?:string }} [query]
|
|
110
|
+
*/
|
|
111
|
+
function discover(query = {}) {
|
|
112
|
+
const out = []
|
|
113
|
+
for (const entry of entries.values()) {
|
|
114
|
+
const d = entry.descriptor
|
|
115
|
+
if (query.name && d.name !== query.name) continue
|
|
116
|
+
if (query.suite && entry.suite !== query.suite) continue
|
|
117
|
+
if (query.controlMode && d.controlMode !== query.controlMode) continue
|
|
118
|
+
if (query.kind && d.kind !== query.kind) continue
|
|
119
|
+
if (query.produces && !typesOverlap(d.produces, query.produces)) continue
|
|
120
|
+
if (query.consumes && !typesOverlap(d.consumes, query.consumes)) continue
|
|
121
|
+
out.push(entry)
|
|
122
|
+
}
|
|
123
|
+
return out
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function catalog() {
|
|
127
|
+
return [...entries.values()]
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 表面投影(互联标准 v0.3 §C.7 / 单一真源):把描述符里的 surface 声明聚合成
|
|
132
|
+
* 「工作台候选」,一扇挂载路径一行。portal-hud/展示墙与编排器读的是**同一个**注册表,
|
|
133
|
+
* 因此「注册了一个带 surface 的能力」必然自动上墙,不会出现能力加了表上没有。
|
|
134
|
+
*
|
|
135
|
+
* 只认 surface.embedPath(以 / 开头);同路径去重(一个套件多个工具共享一扇窗)。
|
|
136
|
+
* 返回行形状与 portal-hud 注册行兼容:{id,title,path,suite,lastAt:''}。
|
|
137
|
+
*/
|
|
138
|
+
function listSurfaces() {
|
|
139
|
+
const byPath = new Map()
|
|
140
|
+
for (const entry of entries.values()) {
|
|
141
|
+
const surface = entry.descriptor && entry.descriptor.surface
|
|
142
|
+
const embedPath = surface && typeof surface.embedPath === 'string' ? surface.embedPath : ''
|
|
143
|
+
if (!embedPath || !embedPath.startsWith('/')) continue
|
|
144
|
+
if (surface.embeddable === false && surface.standalone === false) continue
|
|
145
|
+
if (byPath.has(embedPath)) continue
|
|
146
|
+
const suite = entry.suite
|
|
147
|
+
byPath.set(embedPath, {
|
|
148
|
+
id: `${suite}-workbench`,
|
|
149
|
+
title: String(surface.title || '') || `${suite} 工作台`,
|
|
150
|
+
path: embedPath.endsWith('/') ? embedPath : `${embedPath}/`,
|
|
151
|
+
suite,
|
|
152
|
+
lastAt: '',
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
return [...byPath.values()]
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
register,
|
|
160
|
+
unregister,
|
|
161
|
+
discover,
|
|
162
|
+
catalog,
|
|
163
|
+
listSurfaces,
|
|
164
|
+
get size() { return entries.size },
|
|
165
|
+
}
|
|
166
|
+
}
|