@capyclaw/wall-suite 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +20 -2
- package/composition.lock.json +48 -0
- package/contract/wall-contract.json +8 -0
- package/cordis.patch.yml +6 -0
- package/dsh-suite.json +118 -0
- package/lib/index.mjs +6 -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 +223 -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 +68 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +113 -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 +87 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/events.mjs +60 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/log.mjs +51 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +188 -0
- package/node_modules/@capyclaw/foundation/package.json +53 -0
- package/node_modules/@capyclaw/foundation/runtime/index.mjs +20 -0
- package/node_modules/@capyclaw/plugin-kit/INTEGRATION.md +100 -0
- package/node_modules/@capyclaw/plugin-kit/README.md +70 -0
- package/node_modules/@capyclaw/plugin-kit/bin/sync.mjs +103 -0
- package/node_modules/@capyclaw/plugin-kit/package.json +69 -0
- package/node_modules/@capyclaw/plugin-kit/src/cli.mjs +56 -0
- package/node_modules/@capyclaw/plugin-kit/src/config.mjs +142 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +129 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +139 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/shadow.mjs +219 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/transport.js +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/index.mjs +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/pack.mjs +230 -0
- package/node_modules/@capyclaw/plugin-kit/src/runtime/context.mjs +128 -0
- package/node_modules/@capyclaw/plugin-kit/src/self-contained.mjs +307 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/api.mjs +45 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/http.mjs +113 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +143 -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 +41 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/validate.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/tuning.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/fs-lock.mjs +132 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/http.mjs +130 -0
- package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +656 -0
- package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +181 -0
- package/node_modules/@capyclaw/portal/README.md +70 -0
- package/node_modules/@capyclaw/portal/lib/index.mjs +387 -0
- package/node_modules/@capyclaw/portal/lib/ledger.mjs +194 -0
- package/node_modules/@capyclaw/portal/lib/portal-agent.ps1 +811 -0
- package/node_modules/@capyclaw/portal/lib/portal-darwin.mjs +183 -0
- package/node_modules/@capyclaw/portal/package.json +40 -0
- package/node_modules/@capyclaw/service-broker/README.md +104 -0
- package/node_modules/@capyclaw/service-broker/cordis.patch.yml +8 -0
- package/node_modules/@capyclaw/service-broker/dsh-suite.json +21 -0
- package/node_modules/@capyclaw/service-broker/lib/control.mjs +193 -0
- package/node_modules/@capyclaw/service-broker/lib/discovery.mjs +109 -0
- package/node_modules/@capyclaw/service-broker/lib/engine.mjs +1236 -0
- package/node_modules/@capyclaw/service-broker/lib/host.mjs +182 -0
- package/node_modules/@capyclaw/service-broker/lib/manifest.mjs +249 -0
- package/node_modules/@capyclaw/service-broker/lib/recovery.mjs +325 -0
- package/node_modules/@capyclaw/service-broker/lib/skills-client.mjs +28 -0
- package/node_modules/@capyclaw/service-broker/lib/spec.mjs +78 -0
- package/node_modules/@capyclaw/service-broker/package.json +65 -0
- package/node_modules/@capyclaw/service-broker/server.mjs +81 -0
- package/node_modules/@capyclaw/service-broker/service.schema.json +62 -0
- package/node_modules/@capyclaw/service-broker/services.json +3 -0
- package/node_modules/@capyclaw/service-host/README.md +86 -0
- package/node_modules/@capyclaw/service-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/service-host/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/service-host/lib/host.mjs +22 -0
- package/node_modules/@capyclaw/service-host/package.json +60 -0
- package/node_modules/@capyclaw/service-host/src/index.mjs +571 -0
- package/node_modules/@capyclaw/service-host/src/tuning.mjs +63 -0
- package/node_modules/@capyclaw/tool-host/README.md +56 -0
- package/node_modules/@capyclaw/tool-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/tool-host/dsh-suite.json +30 -0
- package/node_modules/@capyclaw/tool-host/lib/host.mjs +16 -0
- package/node_modules/@capyclaw/tool-host/package.json +59 -0
- package/node_modules/@capyclaw/tool-host/src/descriptors.mjs +142 -0
- package/node_modules/@capyclaw/tool-host/src/index.mjs +390 -0
- package/node_modules/@capyclaw/wall-workbench/README.md +58 -0
- package/node_modules/@capyclaw/wall-workbench/contract/wall-contract.json +8 -0
- package/node_modules/@capyclaw/wall-workbench/lib/host.mjs +1 -0
- package/node_modules/@capyclaw/wall-workbench/package.json +63 -0
- package/node_modules/@capyclaw/wall-workbench/plugin.mjs +1 -0
- package/node_modules/@capyclaw/wall-workbench/server/constants.mjs +12 -0
- package/node_modules/@capyclaw/wall-workbench/server/contract.mjs +12 -0
- package/node_modules/@capyclaw/wall-workbench/server/embedded-host.mjs +160 -0
- package/node_modules/@capyclaw/wall-workbench/server/infra/http.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/infra/tuning.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/relay.mjs +68 -0
- package/node_modules/@capyclaw/wall-workbench/server/routes/claim.mjs +46 -0
- package/node_modules/@capyclaw/wall-workbench/server/routes/workbench.mjs +29 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/SHARED_MANIFEST.json +70 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/asset-service.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/editor-host.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/editor/lease.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/service/api.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/service/http.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/service/mcp-http.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/tools/validate.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/tuning.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/util/fs-lock.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/service-host.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/tool-host.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/tuning.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/tools/capabilities/index.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/tools/index.mjs +12 -0
- package/node_modules/@capyclaw/wall-workbench/server/tools.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/workbench-framework.mjs +305 -0
- package/node_modules/@capyclaw/wall-workbench/ui/app.js +142 -0
- package/node_modules/@capyclaw/wall-workbench/ui/index.html +20 -0
- package/node_modules/@capyclaw/wall-workbench/ui/style.css +74 -0
- package/package.json +72 -4
- package/services.json +3 -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,142 @@
|
|
|
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
|
+
/** 最小结构兜底:name/suite/controlMode/kind 必须在场且合法。深度校验走注入的 validate。 */
|
|
32
|
+
function structuralCheck(descriptor) {
|
|
33
|
+
const errors = []
|
|
34
|
+
if (!descriptor || typeof descriptor !== 'object') return ['descriptor 必须是对象']
|
|
35
|
+
if (!descriptor.name || typeof descriptor.name !== 'string') errors.push('缺少 name')
|
|
36
|
+
if (!descriptor.suite || typeof descriptor.suite !== 'string') errors.push('缺少 suite')
|
|
37
|
+
if (!descriptor.capability || typeof descriptor.capability !== 'string') errors.push('缺少 capability(能力语义)')
|
|
38
|
+
if (!CONTROL_MODES.has(descriptor.controlMode)) errors.push(`controlMode 必须是 interface|browser,收到 ${descriptor.controlMode}`)
|
|
39
|
+
if (!KINDS.has(descriptor.kind)) errors.push(`kind 必须是 read|write|control,收到 ${descriptor.kind}`)
|
|
40
|
+
return errors
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {{ validate?: (d:object)=>{ok:boolean,errors?:string[]} }} [options]
|
|
45
|
+
* validate 可选注入(suite-kit 的深度校验器)。缺省只做结构兜底。
|
|
46
|
+
*/
|
|
47
|
+
export function createDescriptorRegistry({ validate } = {}) {
|
|
48
|
+
/** @type {Map<string, {descriptor:object, suite:string, baseUrl:string, registeredAt:number}>} */
|
|
49
|
+
const entries = new Map()
|
|
50
|
+
|
|
51
|
+
function register(descriptor, { suite, baseUrl = '' } = {}) {
|
|
52
|
+
const merged = { ...descriptor, suite: descriptor?.suite || suite }
|
|
53
|
+
const errors = structuralCheck(merged)
|
|
54
|
+
if (errors.length) {
|
|
55
|
+
const err = new Error(`能力描述符不合法: ${errors.join('; ')}`)
|
|
56
|
+
err.code = 'DESCRIPTOR_INVALID'
|
|
57
|
+
throw err
|
|
58
|
+
}
|
|
59
|
+
if (typeof validate === 'function') {
|
|
60
|
+
const verdict = validate(merged)
|
|
61
|
+
if (verdict && verdict.ok === false) {
|
|
62
|
+
const err = new Error(`能力描述符不合法: ${(verdict.errors || []).join('; ')}`)
|
|
63
|
+
err.code = 'DESCRIPTOR_INVALID'
|
|
64
|
+
throw err
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const entry = Object.freeze({
|
|
68
|
+
descriptor: Object.freeze({ ...merged }),
|
|
69
|
+
suite: merged.suite,
|
|
70
|
+
baseUrl: String(baseUrl || ''),
|
|
71
|
+
registeredAt: Date.now(),
|
|
72
|
+
})
|
|
73
|
+
// 同名幂等覆盖:套件热重载/重新激活时直接刷新,不产生重复。
|
|
74
|
+
entries.set(merged.name, entry)
|
|
75
|
+
return entry
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function unregister(name) {
|
|
79
|
+
return entries.delete(name)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 按条件发现。produces/consumes 用类型词表匹配(含 `/*` 通配)。
|
|
84
|
+
* @param {{ name?:string, suite?:string, controlMode?:string, kind?:string,
|
|
85
|
+
* produces?:string, consumes?:string }} [query]
|
|
86
|
+
*/
|
|
87
|
+
function discover(query = {}) {
|
|
88
|
+
const out = []
|
|
89
|
+
for (const entry of entries.values()) {
|
|
90
|
+
const d = entry.descriptor
|
|
91
|
+
if (query.name && d.name !== query.name) continue
|
|
92
|
+
if (query.suite && entry.suite !== query.suite) continue
|
|
93
|
+
if (query.controlMode && d.controlMode !== query.controlMode) continue
|
|
94
|
+
if (query.kind && d.kind !== query.kind) continue
|
|
95
|
+
if (query.produces && !anyTypeMatches(d.produces, query.produces)) continue
|
|
96
|
+
if (query.consumes && !anyTypeMatches(d.consumes, query.consumes)) continue
|
|
97
|
+
out.push(entry)
|
|
98
|
+
}
|
|
99
|
+
return out
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function catalog() {
|
|
103
|
+
return [...entries.values()]
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 表面投影(互联标准 v0.3 §C.7 / 单一真源):把描述符里的 surface 声明聚合成
|
|
108
|
+
* 「工作台候选」,一扇挂载路径一行。portal-hud/展示墙与编排器读的是**同一个**注册表,
|
|
109
|
+
* 因此「注册了一个带 surface 的能力」必然自动上墙,不会出现能力加了表上没有。
|
|
110
|
+
*
|
|
111
|
+
* 只认 surface.embedPath(以 / 开头);同路径去重(一个套件多个工具共享一扇窗)。
|
|
112
|
+
* 返回行形状与 portal-hud 注册行兼容:{id,title,path,suite,lastAt:''}。
|
|
113
|
+
*/
|
|
114
|
+
function listSurfaces() {
|
|
115
|
+
const byPath = new Map()
|
|
116
|
+
for (const entry of entries.values()) {
|
|
117
|
+
const surface = entry.descriptor && entry.descriptor.surface
|
|
118
|
+
const embedPath = surface && typeof surface.embedPath === 'string' ? surface.embedPath : ''
|
|
119
|
+
if (!embedPath || !embedPath.startsWith('/')) continue
|
|
120
|
+
if (surface.embeddable === false && surface.standalone === false) continue
|
|
121
|
+
if (byPath.has(embedPath)) continue
|
|
122
|
+
const suite = entry.suite
|
|
123
|
+
byPath.set(embedPath, {
|
|
124
|
+
id: `${suite}-workbench`,
|
|
125
|
+
title: String(surface.title || '') || `${suite} 工作台`,
|
|
126
|
+
path: embedPath.endsWith('/') ? embedPath : `${embedPath}/`,
|
|
127
|
+
suite,
|
|
128
|
+
lastAt: '',
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
return [...byPath.values()]
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
register,
|
|
136
|
+
unregister,
|
|
137
|
+
discover,
|
|
138
|
+
catalog,
|
|
139
|
+
listSurfaces,
|
|
140
|
+
get size() { return entries.size },
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @capyclaw/tool-host —— 工具面标准件。
|
|
3
|
+
*
|
|
4
|
+
* 把“能力声明 → 注册表 → 工具 schema/实现 → 契约报告 → MCP 协议壳”收成一套:
|
|
5
|
+
* defineTool / defineCapability / createRegistry / createMcpHandler /
|
|
6
|
+
* createCapabilityReport / buildInstructions
|
|
7
|
+
*
|
|
8
|
+
* 功能插件只写业务能力,不再复制 kernel/registry/dispatch/validate/contract。
|
|
9
|
+
*/
|
|
10
|
+
import { createMcpHandler as createKitMcpHandler } from '@capyclaw/plugin-kit/service/mcp-http'
|
|
11
|
+
import { validateToolArguments } from '@capyclaw/plugin-kit/tools/validate'
|
|
12
|
+
import { normalizeToolResult, resultText } from '@capyclaw/plugin-kit/tools/result'
|
|
13
|
+
import { createServiceApi } from '@capyclaw/plugin-kit/service/api'
|
|
14
|
+
import { createDescriptorRegistry } from './descriptors.mjs'
|
|
15
|
+
|
|
16
|
+
export { createDescriptorRegistry } from './descriptors.mjs'
|
|
17
|
+
|
|
18
|
+
const KINDS = new Set(['read', 'write', 'control'])
|
|
19
|
+
|
|
20
|
+
export function defineTool({
|
|
21
|
+
name,
|
|
22
|
+
description = '',
|
|
23
|
+
inputSchema = { type: 'object', properties: {}, additionalProperties: false },
|
|
24
|
+
kind = 'write',
|
|
25
|
+
since = '1.0.0',
|
|
26
|
+
handler,
|
|
27
|
+
} = {}) {
|
|
28
|
+
if (!name || typeof name !== 'string') throw new Error('defineTool 需要 name')
|
|
29
|
+
if (typeof handler !== 'function') throw new Error(`工具 ${name} 需要 handler`)
|
|
30
|
+
if (!KINDS.has(kind)) throw new Error(`工具 ${name} 的 kind 非法: ${kind}`)
|
|
31
|
+
return Object.freeze({ name, description, inputSchema, kind, since, handler })
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function defineCapability({
|
|
35
|
+
id,
|
|
36
|
+
title,
|
|
37
|
+
description = '',
|
|
38
|
+
tags = [],
|
|
39
|
+
requires = [],
|
|
40
|
+
dependsOn = [],
|
|
41
|
+
provides = {},
|
|
42
|
+
features = [],
|
|
43
|
+
tools = [],
|
|
44
|
+
} = {}) {
|
|
45
|
+
if (!id || typeof id !== 'string') throw new Error('defineCapability 需要 id')
|
|
46
|
+
if (!Array.isArray(tools) || !tools.length) throw new Error(`能力 ${id} 至少需要一个工具`)
|
|
47
|
+
return Object.freeze({
|
|
48
|
+
id,
|
|
49
|
+
title: title || id,
|
|
50
|
+
description,
|
|
51
|
+
tags: Object.freeze([...tags]),
|
|
52
|
+
requires: Object.freeze([...requires]),
|
|
53
|
+
dependsOn: Object.freeze([...dependsOn]),
|
|
54
|
+
provides: Object.freeze({ ...provides }),
|
|
55
|
+
features: Object.freeze([...features]),
|
|
56
|
+
tools: Object.freeze([...tools]),
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function validateCapabilities(capabilities) {
|
|
61
|
+
const ids = new Set()
|
|
62
|
+
const toolNames = new Set()
|
|
63
|
+
for (const cap of capabilities) {
|
|
64
|
+
if (ids.has(cap.id)) throw new Error(`重复的 capability id: ${cap.id}`)
|
|
65
|
+
ids.add(cap.id)
|
|
66
|
+
for (const tool of cap.tools) {
|
|
67
|
+
if (toolNames.has(tool.name)) throw new Error(`重复的工具名: ${tool.name}`)
|
|
68
|
+
toolNames.add(tool.name)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
for (const cap of capabilities) {
|
|
72
|
+
for (const dep of cap.dependsOn) {
|
|
73
|
+
if (!ids.has(dep)) throw new Error(`能力 ${cap.id} 依赖不存在的能力: ${dep}`)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function selectCapabilities(capabilities, enabled) {
|
|
79
|
+
if (!enabled || !enabled.length) return capabilities
|
|
80
|
+
const byId = new Map(capabilities.map((cap) => [cap.id, cap]))
|
|
81
|
+
for (const id of enabled) {
|
|
82
|
+
if (!byId.has(id)) throw new Error(`enabled 里有未知能力: ${id}`)
|
|
83
|
+
}
|
|
84
|
+
const ids = new Set(enabled)
|
|
85
|
+
let changed = true
|
|
86
|
+
while (changed) {
|
|
87
|
+
changed = false
|
|
88
|
+
for (const cap of capabilities) {
|
|
89
|
+
if (!ids.has(cap.id)) continue
|
|
90
|
+
for (const dep of cap.dependsOn) {
|
|
91
|
+
if (!ids.has(dep)) { ids.add(dep); changed = true }
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return capabilities.filter((cap) => ids.has(cap.id))
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @param {Array} capabilities
|
|
100
|
+
* @param {{ enabled?: string[], ports?: object, report?: Function, reserved?: string[] }} options
|
|
101
|
+
*/
|
|
102
|
+
export function createRegistry(capabilities, { enabled = null, ports = null, report = null, reserved = [] } = {}) {
|
|
103
|
+
validateCapabilities(capabilities)
|
|
104
|
+
const selected = selectCapabilities(capabilities, enabled)
|
|
105
|
+
|
|
106
|
+
const kernelPorts = { ...(ports || {}) }
|
|
107
|
+
const reservedNames = new Set([...(reserved || []), 'contract'])
|
|
108
|
+
const providers = new Map()
|
|
109
|
+
for (const cap of selected) {
|
|
110
|
+
for (const [ns, api] of Object.entries(cap.provides || {})) {
|
|
111
|
+
if (reservedNames.has(ns)) throw new Error(`能力 ${cap.id} 不能覆盖内核端口: ${ns}`)
|
|
112
|
+
if (providers.has(ns)) throw new Error(`服务命名空间重复: ${ns}(${providers.get(ns).cap.id} / ${cap.id})`)
|
|
113
|
+
providers.set(ns, { cap, api })
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const available = new Set([...Object.keys(kernelPorts), ...reservedNames, ...providers.keys()])
|
|
118
|
+
for (const cap of selected) {
|
|
119
|
+
for (const req of cap.requires) {
|
|
120
|
+
if (!available.has(req)) throw new Error(`能力 ${cap.id} 需要未提供的端口/服务: ${req}`)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const ctx = { ...kernelPorts }
|
|
125
|
+
for (const [ns, { api }] of providers) {
|
|
126
|
+
ctx[ns] = {}
|
|
127
|
+
for (const [method, fn] of Object.entries(api)) {
|
|
128
|
+
if (typeof fn !== 'function') throw new Error(`服务 ${ns}.${method} 必须是函数`)
|
|
129
|
+
ctx[ns][method] = (...args) => fn(ctx, ...args)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const TOOLS = []
|
|
134
|
+
const TOOL_IMPL = {}
|
|
135
|
+
const TOOL_META = {}
|
|
136
|
+
const FEATURES = []
|
|
137
|
+
const CAPABILITIES = []
|
|
138
|
+
|
|
139
|
+
for (const cap of selected) {
|
|
140
|
+
for (const feature of cap.features) {
|
|
141
|
+
if (!FEATURES.includes(feature)) FEATURES.push(feature)
|
|
142
|
+
}
|
|
143
|
+
CAPABILITIES.push({
|
|
144
|
+
id: cap.id,
|
|
145
|
+
title: cap.title,
|
|
146
|
+
description: cap.description,
|
|
147
|
+
tags: [...cap.tags],
|
|
148
|
+
tools: cap.tools.map((tool) => tool.name),
|
|
149
|
+
})
|
|
150
|
+
for (const tool of cap.tools) {
|
|
151
|
+
TOOLS.push({ name: tool.name, description: tool.description, inputSchema: tool.inputSchema })
|
|
152
|
+
TOOL_META[tool.name] = { kind: tool.kind, since: tool.since, capability: cap.id }
|
|
153
|
+
TOOL_IMPL[tool.name] = (args) => tool.handler(args || {}, ctx)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const reportFn = report || createCapabilityReport
|
|
158
|
+
ctx.contract = {
|
|
159
|
+
report: (editorUrl = '', runtime = {}) => reportFn({
|
|
160
|
+
tools: TOOLS,
|
|
161
|
+
toolMeta: TOOL_META,
|
|
162
|
+
features: FEATURES,
|
|
163
|
+
capabilities: CAPABILITIES,
|
|
164
|
+
editorUrl,
|
|
165
|
+
runtime,
|
|
166
|
+
}),
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return { TOOLS, TOOL_IMPL, TOOL_META, FEATURES, CAPABILITIES, ctx }
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** 与 MCP 工具面解耦:调用前统一校验。 */
|
|
173
|
+
export function createToolDispatcher({ tools, callTool }) {
|
|
174
|
+
const toolMap = new Map((tools || []).map((tool) => [tool.name, tool]))
|
|
175
|
+
return {
|
|
176
|
+
listTools() {
|
|
177
|
+
return { tools }
|
|
178
|
+
},
|
|
179
|
+
async callTool(name, args = {}) {
|
|
180
|
+
const tool = toolMap.get(name)
|
|
181
|
+
if (!tool) {
|
|
182
|
+
return { content: [{ type: 'text', text: `未知工具: ${String(name)}` }], isError: true }
|
|
183
|
+
}
|
|
184
|
+
const check = validateToolArguments(tool, args)
|
|
185
|
+
if (!check.ok) {
|
|
186
|
+
return { content: [{ type: 'text', text: '参数不合法:' + check.errors.join(';') }], isError: true }
|
|
187
|
+
}
|
|
188
|
+
const out = await callTool(name, args)
|
|
189
|
+
/* 与 MCP 面同一归一化:保留纯字符串/空 text/对象,不丢成 'ok'(B 轴 P0-5)。 */
|
|
190
|
+
return normalizeToolResult(out)
|
|
191
|
+
},
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* MCP Streamable HTTP 处理器。registry 可直接传 createRegistry 的返回值。
|
|
197
|
+
* 兼容两种调用:
|
|
198
|
+
* { registry } 或 { tools, toolImpl }
|
|
199
|
+
* { tools, callTool }(旧 relay 形态)
|
|
200
|
+
* @param {{ registry?: object, tools?: Array, toolImpl?: object, callTool?: Function, serverInfo?: object, instructions?: string }} options
|
|
201
|
+
*/
|
|
202
|
+
export function createMcpHandler({ registry, tools, toolImpl, callTool, serverInfo, instructions } = {}) {
|
|
203
|
+
const list = tools || registry?.TOOLS || []
|
|
204
|
+
const impl = toolImpl || registry?.TOOL_IMPL || null
|
|
205
|
+
if (!Array.isArray(list) || !list.length) throw new Error('createMcpHandler: 没有工具可暴露')
|
|
206
|
+
if (!impl && typeof callTool !== 'function') throw new Error('createMcpHandler: 需要 toolImpl 或 callTool')
|
|
207
|
+
return createKitMcpHandler({
|
|
208
|
+
tools: list,
|
|
209
|
+
callTool: (name, args, context) => {
|
|
210
|
+
if (typeof callTool === 'function' && !impl) return callTool(name, args, context)
|
|
211
|
+
const fn = impl[name]
|
|
212
|
+
if (!fn) throw new Error(`未知工具: ${name}`)
|
|
213
|
+
return fn(args, context)
|
|
214
|
+
},
|
|
215
|
+
serverInfo: serverInfo || { name: 'dsh-tool-host', version: '0.1.0' },
|
|
216
|
+
instructions,
|
|
217
|
+
})
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** 把绝对地址收成同源相对路径:给人看的地址不带端口,端口是宿主的内部细节。 */
|
|
221
|
+
function sameOriginPath(url) {
|
|
222
|
+
const raw = String(url || '').trim()
|
|
223
|
+
if (!raw) return ''
|
|
224
|
+
if (raw.startsWith('/')) return raw
|
|
225
|
+
try {
|
|
226
|
+
const { pathname } = new URL(raw)
|
|
227
|
+
return pathname.endsWith('/') ? pathname : `${pathname}/`
|
|
228
|
+
} catch {
|
|
229
|
+
return ''
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export function createCapabilityReport({
|
|
234
|
+
tools = [],
|
|
235
|
+
toolMeta = {},
|
|
236
|
+
features = [],
|
|
237
|
+
capabilities = [],
|
|
238
|
+
contractVersion = '1.0.0',
|
|
239
|
+
packageVersion = '0.0.0',
|
|
240
|
+
editorUrl = '',
|
|
241
|
+
runtime = {},
|
|
242
|
+
} = {}) {
|
|
243
|
+
return {
|
|
244
|
+
contractVersion,
|
|
245
|
+
packageVersion,
|
|
246
|
+
editorUrl,
|
|
247
|
+
editorPath: sameOriginPath(editorUrl),
|
|
248
|
+
...runtime,
|
|
249
|
+
toolCount: tools.length,
|
|
250
|
+
tools: tools.map((tool) => ({
|
|
251
|
+
name: tool.name,
|
|
252
|
+
kind: toolMeta[tool.name]?.kind ?? 'write',
|
|
253
|
+
since: toolMeta[tool.name]?.since ?? '1.0.0',
|
|
254
|
+
capability: toolMeta[tool.name]?.capability ?? '',
|
|
255
|
+
})),
|
|
256
|
+
features,
|
|
257
|
+
capabilities: capabilities.map((cap) => ({
|
|
258
|
+
id: cap.id,
|
|
259
|
+
title: cap.title,
|
|
260
|
+
description: cap.description || '',
|
|
261
|
+
tags: cap.tags || [],
|
|
262
|
+
tools: cap.tools || [],
|
|
263
|
+
})),
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* 生成 MCP server instructions(≤32KB)。业务只提供数据,不再手写排版。
|
|
269
|
+
*/
|
|
270
|
+
export function buildInstructions({
|
|
271
|
+
title = '',
|
|
272
|
+
intro = '',
|
|
273
|
+
startup = [],
|
|
274
|
+
capabilities = [],
|
|
275
|
+
tools = [],
|
|
276
|
+
rules = [],
|
|
277
|
+
output = [],
|
|
278
|
+
} = {}) {
|
|
279
|
+
const rows = capabilities.length
|
|
280
|
+
? capabilities.map((cap) => `| ${cap.title} | ${cap.tools.map((name) => `\`${name}\``).join(', ')} | ${cap.description || ''} |`)
|
|
281
|
+
: [{
|
|
282
|
+
title: '工具',
|
|
283
|
+
tools: tools.map((tool) => tool.name),
|
|
284
|
+
description: '',
|
|
285
|
+
}].map((cap) => `| ${cap.title} | ${cap.tools.map((name) => `\`${name}\``).join(', ')} | |`)
|
|
286
|
+
|
|
287
|
+
const lines = []
|
|
288
|
+
if (title) lines.push(`# ${title}`, '')
|
|
289
|
+
if (intro) lines.push(intro, '')
|
|
290
|
+
if (startup.length) {
|
|
291
|
+
lines.push('## 启动检查')
|
|
292
|
+
startup.forEach((line, index) => lines.push(`${index + 1}. ${line}`))
|
|
293
|
+
lines.push('')
|
|
294
|
+
}
|
|
295
|
+
lines.push('## 能力面', '| 能力 | 工具 | 用途 |', '|---|---|---|', ...rows, '')
|
|
296
|
+
if (rules.length) {
|
|
297
|
+
lines.push('## 硬规则')
|
|
298
|
+
rules.forEach((line) => lines.push(`- ${line}`))
|
|
299
|
+
lines.push('')
|
|
300
|
+
}
|
|
301
|
+
if (output.length) {
|
|
302
|
+
lines.push('## 输出')
|
|
303
|
+
output.forEach((line) => lines.push(`- ${line}`))
|
|
304
|
+
}
|
|
305
|
+
return lines.join('\n')
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* 把能力注册表直接注册到 DSH 的 ctx.tools(同进程原生工具面)。
|
|
310
|
+
* 注册后不再需要单独的 loopback /mcp 端口和 @deepseek-ai/dsh-mcp-client row。
|
|
311
|
+
*
|
|
312
|
+
* `execute(args, exec)` 的第二个参数是 DSH 的调用上下文,`exec.agent.session.id`
|
|
313
|
+
* 是「哪个会话调用了这个工具」——多会话工作台要靠它把写入落到调用者的那份文档上。
|
|
314
|
+
* 以前这里写成 `(args) => impl(args)`,把它丢了,于是工具只能退化成"猜用户在看哪个窗口"。
|
|
315
|
+
*
|
|
316
|
+
* @param {object} ctx DSH cordis context
|
|
317
|
+
* @param {object} registry createRegistry() 的返回值
|
|
318
|
+
* @param {{ namespace?: string }} options
|
|
319
|
+
* @returns {() => void} 反注册全部工具
|
|
320
|
+
*/
|
|
321
|
+
export function registerWithDsh(ctx, registry, { namespace = '' } = {}) {
|
|
322
|
+
if (!ctx?.tools?.register) throw new Error('registerWithDsh: 当前 DSH 没有 ctx.tools.register')
|
|
323
|
+
const disposers = []
|
|
324
|
+
try {
|
|
325
|
+
for (const tool of registry?.TOOLS || []) {
|
|
326
|
+
const impl = registry.TOOL_IMPL?.[tool.name]
|
|
327
|
+
if (typeof impl !== 'function') throw new Error(`registerWithDsh: 工具缺少实现 ${tool.name}`)
|
|
328
|
+
const name = namespace ? `${namespace}_${tool.name}` : tool.name
|
|
329
|
+
disposers.push(ctx.tools.register({
|
|
330
|
+
name,
|
|
331
|
+
description: tool.description || '',
|
|
332
|
+
parameters: tool.inputSchema || { type: 'object', properties: {}, additionalProperties: false },
|
|
333
|
+
output: {
|
|
334
|
+
/* execute 恒返回归一化 {content:[...]} object,故此 object schema 恒满足,
|
|
335
|
+
* 不再与 string/{text}/undefined 返回冲突(B 轴 P0-2)。 */
|
|
336
|
+
schema: { type: 'object', additionalProperties: true },
|
|
337
|
+
render: (args, value) => (value && Array.isArray(value.content)
|
|
338
|
+
? value.content
|
|
339
|
+
: normalizeToolResult(value).content),
|
|
340
|
+
},
|
|
341
|
+
execute: async (args, exec) => {
|
|
342
|
+
const normalized = normalizeToolResult(await impl(args, exec))
|
|
343
|
+
/* DSH 原生面成功恒 isError:false,失败必须 throw 才走错误路径(B 轴 P0-1)。
|
|
344
|
+
* 把工具自报的 isError:true 转成 throw,与 MCP 面的失败语义对齐。 */
|
|
345
|
+
if (normalized.isError === true) {
|
|
346
|
+
throw new Error(resultText(normalized) || `工具 ${name} 执行失败`)
|
|
347
|
+
}
|
|
348
|
+
return normalized
|
|
349
|
+
},
|
|
350
|
+
}))
|
|
351
|
+
}
|
|
352
|
+
} catch (error) {
|
|
353
|
+
/* 全有或全无:任一工具注册失败,逆序释放已注册的,避免部分注册泄漏(B 轴 P0-6)。 */
|
|
354
|
+
for (let i = disposers.length - 1; i >= 0; i--) {
|
|
355
|
+
try { disposers[i]() } catch { /* 忽略释放失败 */ }
|
|
356
|
+
}
|
|
357
|
+
throw error
|
|
358
|
+
}
|
|
359
|
+
return () => {
|
|
360
|
+
for (const dispose of disposers) {
|
|
361
|
+
try { dispose() } catch { /* 忽略重复释放 */ }
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export function createToolHost(config = {}) {
|
|
367
|
+
// 跨套件能力发现注册表(互联标准 §A.4/§E)。深度校验器可选注入(suite-kit)。
|
|
368
|
+
const descriptors = createDescriptorRegistry({ validate: config.validateDescriptor })
|
|
369
|
+
return {
|
|
370
|
+
api: createServiceApi('toolHost', '1.1.0', ['dsl', 'registry', 'validate', 'contract', 'mcp', 'instructions', 'native-tools', 'descriptors']),
|
|
371
|
+
version: '0.2.0',
|
|
372
|
+
defineTool,
|
|
373
|
+
defineCapability,
|
|
374
|
+
createRegistry: (capabilities, options = {}) => createRegistry(capabilities, { ...config, ...options }),
|
|
375
|
+
createMcpHandler,
|
|
376
|
+
createToolDispatcher,
|
|
377
|
+
createCapabilityReport,
|
|
378
|
+
buildInstructions,
|
|
379
|
+
registerWithDsh,
|
|
380
|
+
validateToolArguments,
|
|
381
|
+
// 能力描述符注册/发现(编排器按类型动态发现,套件零互依赖)。
|
|
382
|
+
registerCapabilityDescriptor: (descriptor, options) => descriptors.register(descriptor, options),
|
|
383
|
+
unregisterCapabilityDescriptor: (name) => descriptors.unregister(name),
|
|
384
|
+
discoverCapabilities: (query) => descriptors.discover(query),
|
|
385
|
+
capabilityCatalog: () => descriptors.catalog(),
|
|
386
|
+
listSurfaces: () => descriptors.listSurfaces(),
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export { validateToolArguments }
|