@capyclaw/capyclaw-workbench 0.0.0-stage → 0.1.1
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 +56 -2
- package/contract/capabilities.json +178 -0
- package/lib/descriptors.mjs +33 -0
- package/lib/host.mjs +106 -0
- package/lib/session-port.mjs +178 -0
- package/lib/session-watch.mjs +82 -0
- package/lib/tools.mjs +166 -0
- package/lib/workbench.mjs +133 -0
- package/lib/workspace-attach.mjs +147 -0
- package/node_modules/@capyclaw/foundation/README.md +51 -0
- package/node_modules/@capyclaw/foundation/abi/assets.mjs +26 -0
- package/node_modules/@capyclaw/foundation/abi/bridge.mjs +88 -0
- package/node_modules/@capyclaw/foundation/abi/errors.mjs +63 -0
- package/node_modules/@capyclaw/foundation/abi/index.mjs +50 -0
- package/node_modules/@capyclaw/foundation/abi/kinds.mjs +271 -0
- package/node_modules/@capyclaw/foundation/abi/loader.mjs +352 -0
- package/node_modules/@capyclaw/foundation/abi/schema.mjs +98 -0
- package/node_modules/@capyclaw/foundation/abi/spec.mjs +258 -0
- package/node_modules/@capyclaw/foundation/abi/validate.mjs +24 -0
- package/node_modules/@capyclaw/foundation/abi/version.mjs +140 -0
- package/node_modules/@capyclaw/foundation/abi/visibility.mjs +90 -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 +72 -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 +38 -0
- package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +88 -0
- package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +54 -0
- package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +187 -0
- package/node_modules/@capyclaw/foundation/lib/host.mjs +23 -0
- package/node_modules/@capyclaw/foundation/lib/kernel.mjs +195 -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 +198 -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 +71 -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 +132 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat.mjs +26 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +60 -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/service/static.mjs +79 -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 +664 -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 +570 -0
- package/node_modules/@capyclaw/service-host/src/tuning.mjs +63 -0
- package/node_modules/@capyclaw/suite-kit/README.md +289 -0
- package/node_modules/@capyclaw/suite-kit/bin/dsh-domain.mjs +98 -0
- package/node_modules/@capyclaw/suite-kit/bin/dsh-suite.mjs +174 -0
- package/node_modules/@capyclaw/suite-kit/client/embed.js +35 -0
- package/node_modules/@capyclaw/suite-kit/domain.schema.json +129 -0
- package/node_modules/@capyclaw/suite-kit/package.json +58 -0
- package/node_modules/@capyclaw/suite-kit/src/activation-registry.mjs +184 -0
- package/node_modules/@capyclaw/suite-kit/src/artifacts.mjs +131 -0
- package/node_modules/@capyclaw/suite-kit/src/capability.mjs +181 -0
- package/node_modules/@capyclaw/suite-kit/src/compose.mjs +201 -0
- package/node_modules/@capyclaw/suite-kit/src/domain.mjs +138 -0
- package/node_modules/@capyclaw/suite-kit/src/embed.mjs +81 -0
- package/node_modules/@capyclaw/suite-kit/src/host.mjs +230 -0
- package/node_modules/@capyclaw/suite-kit/src/index.mjs +24 -0
- package/node_modules/@capyclaw/suite-kit/src/manifest.mjs +263 -0
- package/node_modules/@capyclaw/suite-kit/src/orchestration.mjs +100 -0
- package/node_modules/@capyclaw/suite-kit/src/profile.mjs +584 -0
- package/node_modules/@capyclaw/suite-kit/src/surface.mjs +28 -0
- package/node_modules/@capyclaw/suite-kit/suite.schema.json +128 -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 +46 -0
- package/node_modules/@capyclaw/tool-host/package.json +59 -0
- package/node_modules/@capyclaw/tool-host/src/admit-images.mjs +80 -0
- package/node_modules/@capyclaw/tool-host/src/caller-session.mjs +25 -0
- package/node_modules/@capyclaw/tool-host/src/descriptors.mjs +166 -0
- package/node_modules/@capyclaw/tool-host/src/index.mjs +461 -0
- package/node_modules/@capyclaw/tool-host/src/mode-gate.mjs +272 -0
- package/package.json +68 -4
- package/plugin.mjs +17 -0
- package/ui/app.js +114 -0
- package/ui/index.html +64 -0
- package/ui/style.css +54 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ABI 错误模型:稳定的错误码 + 结构化 detail。
|
|
3
|
+
*
|
|
4
|
+
* 约定:
|
|
5
|
+
* - 应用插件按 code 分支,不解析 message 文案;
|
|
6
|
+
* - message 面向人,detail 面向程序;
|
|
7
|
+
* - 所有加载期失败都必须是 AbiError,不允许裸 Error 穿透。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** 稳定错误码。新增只能追加,不得改语义。 */
|
|
11
|
+
export const ERROR_CODES = Object.freeze({
|
|
12
|
+
/** 插件入口形状不对:缺 name / 没有 implements / 导出了 apply 等。 */
|
|
13
|
+
E_PLUGIN_SHAPE: 'E_PLUGIN_SHAPE',
|
|
14
|
+
/** 插件声明的 ABI 主版本与内核不兼容。 */
|
|
15
|
+
E_ABI_MISMATCH: 'E_ABI_MISMATCH',
|
|
16
|
+
/** 描述符的 kind 不在内核认识的接口表里。 */
|
|
17
|
+
E_KIND_UNKNOWN: 'E_KIND_UNKNOWN',
|
|
18
|
+
/** 描述符字段不满足接口 schema。 */
|
|
19
|
+
E_SCHEMA: 'E_SCHEMA',
|
|
20
|
+
/** 内核没有提供该能力(通常是 os.* 子系统缺失)。 */
|
|
21
|
+
E_CAP_MISSING: 'E_CAP_MISSING',
|
|
22
|
+
/** 唯一性接口被第二个插件实现(例如同 id 的 runtime-driver)。 */
|
|
23
|
+
E_DUP_INTERFACE: 'E_DUP_INTERFACE',
|
|
24
|
+
/** 同名插件被重复挂载。 */
|
|
25
|
+
E_DUP_PLUGIN: 'E_DUP_PLUGIN',
|
|
26
|
+
/** 内核没有为这个 kind 注册适配器(接口定义存在但实现未就绪)。 */
|
|
27
|
+
E_KIND_UNAVAILABLE: 'E_KIND_UNAVAILABLE',
|
|
28
|
+
/** 适配器在编译期抛错。 */
|
|
29
|
+
E_ADAPTER_THREW: 'E_ADAPTER_THREW',
|
|
30
|
+
/** 插件入口没有拿到 baseUrl,相对路径无法解析。 */
|
|
31
|
+
E_BASE_URL_MISSING: 'E_BASE_URL_MISSING',
|
|
32
|
+
/** 运行时没有 ctx.os:foundation 未安装或未启用。 */
|
|
33
|
+
E_KERNEL_MISSING: 'E_KERNEL_MISSING',
|
|
34
|
+
E_KERNEL_CLOSED: 'E_KERNEL_CLOSED',
|
|
35
|
+
E_NOT_READY: 'E_NOT_READY',
|
|
36
|
+
E_CAP_RESERVED: 'E_CAP_RESERVED',
|
|
37
|
+
E_CAP_CONFLICT: 'E_CAP_CONFLICT',
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
export class AbiError extends Error {
|
|
41
|
+
/**
|
|
42
|
+
* @param {string} code ERROR_CODES 中的一项
|
|
43
|
+
* @param {string} message 面向人的说明
|
|
44
|
+
* @param {Record<string, unknown>} [detail] 面向程序的结构化信息
|
|
45
|
+
*/
|
|
46
|
+
constructor(code, message, detail = {}) {
|
|
47
|
+
super(`[${code}] ${message}`)
|
|
48
|
+
this.name = 'AbiError'
|
|
49
|
+
this.code = code
|
|
50
|
+
this.detail = detail
|
|
51
|
+
if (detail.cause instanceof Error) this.cause = detail.cause
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function isAbiError(error) {
|
|
56
|
+
return error instanceof AbiError
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 把任意异常归一成 AbiError(已归一的原样返回)。 */
|
|
60
|
+
export function toAbiError(error, code = ERROR_CODES.E_ADAPTER_THREW, detail = {}) {
|
|
61
|
+
if (error instanceof AbiError) return error
|
|
62
|
+
return new AbiError(code, error?.message || String(error), { ...detail, cause: error })
|
|
63
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** 接口 ABI 的唯一入口:应用插件只需要 import 这个模块。 */
|
|
2
|
+
export { ABI_MAJOR, INTERFACE_KINDS, INTERFACE_KIND_NAMES, getInterfaceKind } from './kinds.mjs'
|
|
3
|
+
export {
|
|
4
|
+
defineInterface,
|
|
5
|
+
definePlugin,
|
|
6
|
+
createPlugin,
|
|
7
|
+
skillProvider,
|
|
8
|
+
toolProvider,
|
|
9
|
+
runtimeDriver,
|
|
10
|
+
httpRouter,
|
|
11
|
+
uiPanel,
|
|
12
|
+
lifecycleHook,
|
|
13
|
+
hostEvent,
|
|
14
|
+
clientPanel,
|
|
15
|
+
ownServer,
|
|
16
|
+
serviceProvider,
|
|
17
|
+
defineDriver,
|
|
18
|
+
rawPlugin,
|
|
19
|
+
} from './spec.mjs'
|
|
20
|
+
/* createLoader 是宿主/测试侧装配 API(内核 createKernel 与一致性测试用),虽从 abi 导出,
|
|
21
|
+
* 应用插件不应直接调用——应用只用 createPlugin + 接口 builders(见 plugin-abi.md §二)。 */
|
|
22
|
+
export { createLoader } from './loader.mjs'
|
|
23
|
+
export {
|
|
24
|
+
BRIDGE_CAPABILITY,
|
|
25
|
+
BRIDGE_INFO_FIELD,
|
|
26
|
+
BRIDGE_PROTOCOL_VERSION,
|
|
27
|
+
DOC_MODEL_CAPABILITY,
|
|
28
|
+
DOC_MODEL_VERSION,
|
|
29
|
+
assertBridgeRuntime,
|
|
30
|
+
bridgeCapabilities,
|
|
31
|
+
bridgeConsumerRequirements,
|
|
32
|
+
declareBridge,
|
|
33
|
+
} from './bridge.mjs'
|
|
34
|
+
export {
|
|
35
|
+
SURFACE_LIFECYCLE_VERSION,
|
|
36
|
+
SURFACE_LIFECYCLE_CAPABILITY_SUFFIX,
|
|
37
|
+
VISIBILITY_ACK_MESSAGE,
|
|
38
|
+
VISIBILITY_DEFAULTS,
|
|
39
|
+
VISIBILITY_MESSAGE,
|
|
40
|
+
VISIBILITY_STATES,
|
|
41
|
+
assertSurfaceLifecycle,
|
|
42
|
+
isVisibilityState,
|
|
43
|
+
normalizeVisibilityState,
|
|
44
|
+
surfaceLifecycleCapability,
|
|
45
|
+
} from './visibility.mjs'
|
|
46
|
+
export { ASSET_URL_PREFIX, ASSET_REF_PREFIX, assetUrl, assetRef } from './assets.mjs'
|
|
47
|
+
export { validateInterface } from './validate.mjs'
|
|
48
|
+
export { AbiError, ERROR_CODES, isAbiError, toAbiError } from './errors.mjs'
|
|
49
|
+
export { validateSchema } from './schema.mjs'
|
|
50
|
+
export { parseVersion, compareVersions, satisfies } from './version.mjs'
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 接口种类表:定义「插件可以是什么」。
|
|
3
|
+
*
|
|
4
|
+
* 一条记录 = 一种插件形状。应用插件不写装配代码,只产出这里的描述符;
|
|
5
|
+
* 生命周期、注册、健康检查、日志包裹由内核的适配器统一完成。
|
|
6
|
+
*
|
|
7
|
+
* 版本规则:
|
|
8
|
+
* - 主版本写在 kind 后缀里(`skill-provider@1`),主版本不同就是不同接口;
|
|
9
|
+
* - 次版本只做增量字段,内核按主版本注册适配器;
|
|
10
|
+
* - 破坏性变更 = 新 kind(@2)+ 旧 kind 至少并存一个大版本。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const nonEmpty = { type: 'string', minLength: 1 }
|
|
14
|
+
const kebab = { type: 'string', pattern: '^[a-z0-9]+(?:-[a-z0-9]+)*$' }
|
|
15
|
+
|
|
16
|
+
export const ABI_MAJOR = 1
|
|
17
|
+
|
|
18
|
+
export const INTERFACE_KINDS = Object.freeze({
|
|
19
|
+
'skill-provider@1': Object.freeze({
|
|
20
|
+
kind: 'skill-provider@1',
|
|
21
|
+
major: 1,
|
|
22
|
+
title: '技能提供者',
|
|
23
|
+
summary: '把一个 SKILL.md 目录注册进 dsh skills 服务,可选附带契约快照与契约注记。',
|
|
24
|
+
unique: false,
|
|
25
|
+
schema: Object.freeze({
|
|
26
|
+
type: 'object',
|
|
27
|
+
required: ['skill'],
|
|
28
|
+
additionalProperties: false,
|
|
29
|
+
properties: {
|
|
30
|
+
name: kebab,
|
|
31
|
+
skill: nonEmpty,
|
|
32
|
+
contract: nonEmpty,
|
|
33
|
+
rank: { type: 'number', min: 0, max: 1000 },
|
|
34
|
+
note: { type: 'function' },
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
}),
|
|
38
|
+
|
|
39
|
+
'tool-provider@1': Object.freeze({
|
|
40
|
+
kind: 'tool-provider@1',
|
|
41
|
+
major: 1,
|
|
42
|
+
title: '工具提供者',
|
|
43
|
+
summary: '声明一组工具并注册到工具面(注册表 / MCP 壳 / 能力报告)。',
|
|
44
|
+
unique: false,
|
|
45
|
+
schema: Object.freeze({
|
|
46
|
+
type: 'object',
|
|
47
|
+
required: ['namespace', 'provide'],
|
|
48
|
+
additionalProperties: false,
|
|
49
|
+
properties: {
|
|
50
|
+
namespace: kebab,
|
|
51
|
+
prefixNamespace: { type: 'boolean' },
|
|
52
|
+
provide: { type: 'function' },
|
|
53
|
+
instructions: nonEmpty,
|
|
54
|
+
capabilities: { type: 'object' },
|
|
55
|
+
},
|
|
56
|
+
}),
|
|
57
|
+
}),
|
|
58
|
+
|
|
59
|
+
'runtime-driver@1': Object.freeze({
|
|
60
|
+
kind: 'runtime-driver@1',
|
|
61
|
+
major: 1,
|
|
62
|
+
title: '运行时驱动',
|
|
63
|
+
summary: '一个长驻进程的启动、就绪、健康与回收;端口由内核分配,应用不自己 spawn。',
|
|
64
|
+
unique: true,
|
|
65
|
+
uniqueBy: 'id',
|
|
66
|
+
schema: Object.freeze({
|
|
67
|
+
type: 'object',
|
|
68
|
+
required: ['id', 'entry'],
|
|
69
|
+
additionalProperties: false,
|
|
70
|
+
properties: {
|
|
71
|
+
id: kebab,
|
|
72
|
+
entry: nonEmpty,
|
|
73
|
+
when: { type: 'function' },
|
|
74
|
+
args: { type: 'array', items: { type: 'string' } },
|
|
75
|
+
port: { type: ['number', 'string', 'function'] },
|
|
76
|
+
portArg: nonEmpty,
|
|
77
|
+
dir: nonEmpty,
|
|
78
|
+
env: { type: 'function' },
|
|
79
|
+
health: {
|
|
80
|
+
type: 'object',
|
|
81
|
+
required: ['path'],
|
|
82
|
+
additionalProperties: false,
|
|
83
|
+
properties: {
|
|
84
|
+
path: nonEmpty,
|
|
85
|
+
expect: { type: 'object' },
|
|
86
|
+
timeoutMs: { type: 'number', min: 1 },
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
restart: {
|
|
90
|
+
type: 'object',
|
|
91
|
+
additionalProperties: false,
|
|
92
|
+
properties: {
|
|
93
|
+
max: { type: 'integer', min: 0 },
|
|
94
|
+
backoffMs: { type: 'number', min: 0 },
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
}),
|
|
99
|
+
}),
|
|
100
|
+
|
|
101
|
+
'http-router@1': Object.freeze({
|
|
102
|
+
kind: 'http-router@1',
|
|
103
|
+
major: 1,
|
|
104
|
+
title: '路由挂载者',
|
|
105
|
+
summary: '把一组 HTTP 路由挂到内核的共享宿主上,前缀冲突由内核检测。',
|
|
106
|
+
unique: false,
|
|
107
|
+
schema: Object.freeze({
|
|
108
|
+
type: 'object',
|
|
109
|
+
required: ['mount', 'routes'],
|
|
110
|
+
additionalProperties: false,
|
|
111
|
+
properties: {
|
|
112
|
+
mount: { type: 'string', pattern: '^/' },
|
|
113
|
+
routes: { type: 'function' },
|
|
114
|
+
host: { type: 'string', enum: ['shared', 'own'] },
|
|
115
|
+
},
|
|
116
|
+
}),
|
|
117
|
+
}),
|
|
118
|
+
|
|
119
|
+
'ui-panel@1': Object.freeze({
|
|
120
|
+
kind: 'ui-panel@1',
|
|
121
|
+
major: 1,
|
|
122
|
+
title: '界面面板',
|
|
123
|
+
summary: '把静态资源目录挂到挂载点,缓存头与 404 兜底由内核处理。',
|
|
124
|
+
unique: false,
|
|
125
|
+
schema: Object.freeze({
|
|
126
|
+
type: 'object',
|
|
127
|
+
required: ['mount', 'root'],
|
|
128
|
+
additionalProperties: false,
|
|
129
|
+
properties: {
|
|
130
|
+
mount: { type: 'string', pattern: '^/' },
|
|
131
|
+
root: nonEmpty,
|
|
132
|
+
index: nonEmpty,
|
|
133
|
+
cache: { type: 'string', enum: ['no-store', 'revalidate', 'immutable'] },
|
|
134
|
+
},
|
|
135
|
+
}),
|
|
136
|
+
}),
|
|
137
|
+
|
|
138
|
+
'lifecycle-hook@1': Object.freeze({
|
|
139
|
+
kind: 'lifecycle-hook@1',
|
|
140
|
+
major: 1,
|
|
141
|
+
title: '生命周期钩子',
|
|
142
|
+
summary: '在安装 / 启动 / 停止 / 升级四个时点插入行为,时序与幂等由内核保证。',
|
|
143
|
+
unique: false,
|
|
144
|
+
schema: Object.freeze({
|
|
145
|
+
type: 'object',
|
|
146
|
+
additionalProperties: false,
|
|
147
|
+
properties: {
|
|
148
|
+
onInstall: { type: 'function' },
|
|
149
|
+
onStart: { type: 'function' },
|
|
150
|
+
onStop: { type: 'function' },
|
|
151
|
+
onUpgrade: { type: 'function' },
|
|
152
|
+
},
|
|
153
|
+
}),
|
|
154
|
+
/** schema 表达不了「至少一个钩子」,用额外校验补。 */
|
|
155
|
+
extra(impl, errors) {
|
|
156
|
+
const hooks = ['onInstall', 'onStart', 'onStop', 'onUpgrade'].filter((key) => typeof impl[key] === 'function')
|
|
157
|
+
if (!hooks.length) errors.push('$ 至少需要实现一个钩子(onInstall/onStart/onStop/onUpgrade)')
|
|
158
|
+
},
|
|
159
|
+
}),
|
|
160
|
+
|
|
161
|
+
'host-event@1': Object.freeze({
|
|
162
|
+
kind: 'host-event@1',
|
|
163
|
+
major: 1,
|
|
164
|
+
title: '宿主事件订阅',
|
|
165
|
+
summary: '订阅宿主生命周期/界面注入事件;适配器负责在插件自己的 ctx 上注册与注销。',
|
|
166
|
+
unique: false,
|
|
167
|
+
schema: Object.freeze({
|
|
168
|
+
type: 'object',
|
|
169
|
+
required: ['event', 'handler'],
|
|
170
|
+
additionalProperties: false,
|
|
171
|
+
properties: {
|
|
172
|
+
event: nonEmpty,
|
|
173
|
+
handler: { type: 'function' },
|
|
174
|
+
},
|
|
175
|
+
}),
|
|
176
|
+
}),
|
|
177
|
+
|
|
178
|
+
'client-panel@1': Object.freeze({
|
|
179
|
+
kind: 'client-panel@1',
|
|
180
|
+
major: 1,
|
|
181
|
+
title: '客户端面板',
|
|
182
|
+
summary: '声明页面开机全局变量与可选静态目录;适配器负责 webserver/index-inject 注入与静态挂载。',
|
|
183
|
+
unique: false,
|
|
184
|
+
schema: Object.freeze({
|
|
185
|
+
type: 'object',
|
|
186
|
+
additionalProperties: false,
|
|
187
|
+
properties: {
|
|
188
|
+
mount: { type: 'string', pattern: '^/' },
|
|
189
|
+
root: nonEmpty,
|
|
190
|
+
index: nonEmpty,
|
|
191
|
+
prepare: { type: 'function' },
|
|
192
|
+
bootGlobals: { type: 'function' },
|
|
193
|
+
},
|
|
194
|
+
}),
|
|
195
|
+
extra(impl, errors) {
|
|
196
|
+
if (!impl.root && !impl.prepare && !impl.bootGlobals) {
|
|
197
|
+
errors.push('$ 至少需要 root / prepare / bootGlobals 之一')
|
|
198
|
+
}
|
|
199
|
+
if (impl.root && !impl.mount) errors.push('$ 提供 root 时必须同时提供 mount')
|
|
200
|
+
},
|
|
201
|
+
}),
|
|
202
|
+
|
|
203
|
+
'own-server@1': Object.freeze({
|
|
204
|
+
kind: 'own-server@1',
|
|
205
|
+
major: 1,
|
|
206
|
+
title: '自有 HTTP 面',
|
|
207
|
+
summary: '宿主有网页端口时挂到该端口的前缀下(不新起端口),否则由 service-host 托管独立 loopback origin。',
|
|
208
|
+
unique: true,
|
|
209
|
+
uniqueBy: 'id',
|
|
210
|
+
schema: Object.freeze({
|
|
211
|
+
type: 'object',
|
|
212
|
+
required: ['id', 'handler'],
|
|
213
|
+
additionalProperties: false,
|
|
214
|
+
properties: {
|
|
215
|
+
id: kebab,
|
|
216
|
+
mount: { type: 'string', pattern: '^/' },
|
|
217
|
+
port: { type: ['number', 'string', 'function'] },
|
|
218
|
+
host: nonEmpty,
|
|
219
|
+
handler: { type: 'function' },
|
|
220
|
+
start: { type: 'function' },
|
|
221
|
+
stop: { type: 'function' },
|
|
222
|
+
},
|
|
223
|
+
}),
|
|
224
|
+
}),
|
|
225
|
+
|
|
226
|
+
'service-provider@1': Object.freeze({
|
|
227
|
+
kind: 'service-provider@1',
|
|
228
|
+
major: 1,
|
|
229
|
+
title: '宿主服务提供者',
|
|
230
|
+
summary: '向宿主 ctx 提供一个具名服务;服务工厂必须同步,异步启动放在 start 钩子里。',
|
|
231
|
+
unique: true,
|
|
232
|
+
uniqueBy: 'service',
|
|
233
|
+
schema: Object.freeze({
|
|
234
|
+
type: 'object',
|
|
235
|
+
required: ['service', 'provide'],
|
|
236
|
+
additionalProperties: false,
|
|
237
|
+
properties: {
|
|
238
|
+
service: nonEmpty,
|
|
239
|
+
provide: { type: 'function' },
|
|
240
|
+
when: { type: 'function' },
|
|
241
|
+
start: { type: 'function' },
|
|
242
|
+
stop: { type: 'function' },
|
|
243
|
+
},
|
|
244
|
+
}),
|
|
245
|
+
}),
|
|
246
|
+
|
|
247
|
+
'raw@1': Object.freeze({
|
|
248
|
+
kind: 'raw@1',
|
|
249
|
+
major: 1,
|
|
250
|
+
title: '原生插件(逃生舱)',
|
|
251
|
+
summary: '极少数需要自定义装配的插件;必须在 meta/foundation.allowlist.json 登记,且不得与其他接口混用。',
|
|
252
|
+
unique: false,
|
|
253
|
+
exclusive: true,
|
|
254
|
+
schema: Object.freeze({
|
|
255
|
+
type: 'object',
|
|
256
|
+
required: ['apply'],
|
|
257
|
+
additionalProperties: false,
|
|
258
|
+
properties: {
|
|
259
|
+
apply: { type: 'function' },
|
|
260
|
+
},
|
|
261
|
+
}),
|
|
262
|
+
}),
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
/** 内核当前认识的 kind 列表(供错误信息与文档生成)。 */
|
|
266
|
+
export const INTERFACE_KIND_NAMES = Object.freeze(Object.keys(INTERFACE_KINDS))
|
|
267
|
+
|
|
268
|
+
/** 取接口定义;未知 kind 返回 undefined,由调用方转成 E_KIND_UNKNOWN。 */
|
|
269
|
+
export function getInterfaceKind(kind) {
|
|
270
|
+
return INTERFACE_KINDS[kind]
|
|
271
|
+
}
|