@airongrong/capability 0.0.0-stage → 1.0.0-beta.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 AiToEarn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,61 @@
1
- # Temporary Holding Version
1
+ # @airongrong/capability
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `capability.yaml` 是 AiToEarn 的**能力单一事实源**:一个文件派生出五个表面,避免 GUI / MCP / SDK / OpenAPI / 校验规则各自走各自的实现。
4
+
5
+ ```bash
6
+ pnpm add @airongrong/capability
7
+ ```
8
+
9
+ ## 用法
10
+
11
+ ```ts
12
+ import { loadCapabilityManifest, generateAllSurfaces } from '@airongrong/capability'
13
+
14
+ const manifest = await loadCapabilityManifest('./capability.yaml')
15
+ const surfaces = generateAllSurfaces(manifest)
16
+ // surfaces: { mcp, ui, openapi, sdk, validation }
17
+ ```
18
+
19
+ CLI 侧一行生成五份产物:
20
+
21
+ ```bash
22
+ npx @airongrong/plugin-cli cap --from ./capability.yaml --out ./generated
23
+ ```
24
+
25
+ ## 生成的五个表面
26
+
27
+ | 表面 | 函数 | 用途 |
28
+ | --- | --- | --- |
29
+ | MCP tools | `generateMcpTools()` | Agent(`tools/list`)暴露的工具定义 |
30
+ | GUI forms | `generateUiForms()` | Web/桌面端表单(小白用户轨道) |
31
+ | OpenAPI | `generateOpenApi()` | REST 文档与服务端 stub |
32
+ | SDK types | `generateSdkTypes()` | TS/Python 客户端类型 |
33
+ | Validation | `generateValidationRules()` | 前后端共用校验(写操作护栏复用) |
34
+
35
+ ## capability.yaml 结构
36
+
37
+ ```yaml
38
+ version: 1 # 必填,整数
39
+ actions:
40
+ publish_post:
41
+ summary: 发布图文
42
+ sideEffect: write # read | draft | write
43
+ confirm: required # none | required —— write 必须为 required
44
+ backend: [publishChannelTask] # 契约由哪些宿主工具实现;未实现的占位条目不写
45
+ inputs:
46
+ channelId: { type: channelId, label: 渠道 }
47
+ text: { type: string, maxLength: 1000, label: 正文, ui: textarea }
48
+ dryRun: { type: boolean, default: true, hidden: true }
49
+ returns:
50
+ postId: string
51
+ errors: [AIT-AG-002]
52
+ ```
53
+
54
+ 约定:
55
+
56
+ - **必填 = 没有 `default` 且没有 `hidden: true`**(`generateValidationRules()` 据此产出 `required`),
57
+ 没有单独的 `required` 字段。
58
+ - `type` 可取 `string | number | boolean | url | channelId | array`;`ui` 可取
59
+ `text | textarea | uploader | multi-select | select | switch`。
60
+ - **写操作**(`sideEffect: write`)必须写 `confirm: required`,派生出的 MCP 工具会自动带上
61
+ `dryRun` 默认值,与宿主 `WriteConfirmService` 护栏对齐(错误码 `AIT-AG-002` / `AIT-AG-003`)。
@@ -0,0 +1,60 @@
1
+ import type { CapabilityAction, CapabilityManifest } from './capability-schema';
2
+ import { CapabilityConfirm, CapabilitySideEffect } from './capability-schema';
3
+ export interface McpToolSpec {
4
+ name: string;
5
+ description: string;
6
+ sideEffect: CapabilitySideEffect;
7
+ confirm: CapabilityConfirm;
8
+ inputSchema: Record<string, unknown>;
9
+ errors: string[];
10
+ /** 契约工具对应的后端实现(未实现为 undefined),供 tools/list 过滤与路由 */
11
+ backend?: string[];
12
+ }
13
+ export interface UiFieldSpec {
14
+ name: string;
15
+ widget: string;
16
+ label: string;
17
+ required: boolean;
18
+ advanced: boolean;
19
+ maxLength?: number;
20
+ maxItems?: number;
21
+ }
22
+ export interface UiFormSpec {
23
+ action: string;
24
+ title: string;
25
+ confirmRequired: boolean;
26
+ fields: UiFieldSpec[];
27
+ }
28
+ export interface ValidationRule {
29
+ action: string;
30
+ required: string[];
31
+ maxLength: Record<string, number>;
32
+ maxItems: Record<string, number>;
33
+ formats: Record<string, string>;
34
+ }
35
+ /**
36
+ * 从能力清单生成 MCP 工具定义(§13.2 表面之二)。
37
+ * 写操作自动附加 dry-run 确认语义(§12.2 铁律 3、§12.4)。
38
+ */
39
+ export declare function generateMcpTools(manifest: CapabilityManifest): McpToolSpec[];
40
+ export declare function describeAction(name: string, action: CapabilityAction): string;
41
+ /** 表面之一:GUI 表单描述(§14.2 零代码路径直接消费) */
42
+ export declare function generateUiForms(manifest: CapabilityManifest): UiFormSpec[];
43
+ /** 表面之三:OpenAPI 3.1 paths(供 REST 客户端与网关导入) */
44
+ export declare function generateOpenApi(manifest: CapabilityManifest): Record<string, unknown>;
45
+ /** 表面之四:TS SDK 类型与调用签名 */
46
+ export declare function generateSdkTypes(manifest: CapabilityManifest): string;
47
+ /** 表面之五:发布前校验规则(GUI、MCP、SDK 共用同一份) */
48
+ export declare function generateValidationRules(manifest: CapabilityManifest): ValidationRule[];
49
+ /**
50
+ * 一次性派生全部五种产物,保证"文档有、界面没有、SDK 不认"不再发生。
51
+ * 入口先过一遍 schema:缺省字段(inputs/errors/confirm)自动补默认值,
52
+ * 非法清单抛 PluginError 而不是在生成器深处 TypeError。
53
+ */
54
+ export declare function generateAllSurfaces(manifest: CapabilityManifest): {
55
+ mcp: McpToolSpec[];
56
+ ui: UiFormSpec[];
57
+ openapi: Record<string, unknown>;
58
+ sdk: string;
59
+ validation: ValidationRule[];
60
+ };
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateMcpTools = generateMcpTools;
4
+ exports.describeAction = describeAction;
5
+ exports.generateUiForms = generateUiForms;
6
+ exports.generateOpenApi = generateOpenApi;
7
+ exports.generateSdkTypes = generateSdkTypes;
8
+ exports.generateValidationRules = generateValidationRules;
9
+ exports.generateAllSurfaces = generateAllSurfaces;
10
+ const capability_schema_1 = require("./capability-schema");
11
+ function inputToJsonSchema(input) {
12
+ switch (input.type) {
13
+ case 'url':
14
+ return { type: 'string', format: 'uri' };
15
+ case 'channelId':
16
+ return { type: 'string' };
17
+ case 'boolean':
18
+ return { type: 'boolean', default: input.default };
19
+ case 'number':
20
+ return { type: 'number' };
21
+ case 'array':
22
+ return {
23
+ type: 'array',
24
+ items: input.items === 'url' ? { type: 'string', format: 'uri' } : { type: 'string' },
25
+ maxItems: input.maxItems,
26
+ };
27
+ default:
28
+ return { type: 'string', maxLength: input.maxLength };
29
+ }
30
+ }
31
+ /**
32
+ * 从能力清单生成 MCP 工具定义(§13.2 表面之二)。
33
+ * 写操作自动附加 dry-run 确认语义(§12.2 铁律 3、§12.4)。
34
+ */
35
+ function generateMcpTools(manifest) {
36
+ return Object.entries(manifest.actions).map(([name, action]) => ({
37
+ name,
38
+ description: describeAction(name, action),
39
+ sideEffect: action.sideEffect,
40
+ confirm: action.confirm,
41
+ inputSchema: inputsToJsonSchema(action),
42
+ errors: action.errors,
43
+ backend: action.backend ? (Array.isArray(action.backend) ? action.backend : [action.backend]) : undefined,
44
+ }));
45
+ }
46
+ function describeAction(name, action) {
47
+ const parts = [action.summary];
48
+ if (action.sideEffect === capability_schema_1.CapabilitySideEffect.Write) {
49
+ parts.push('写操作:默认 dryRun 返回将发生的变更,需用户确认后才真正执行');
50
+ }
51
+ else if (action.sideEffect === capability_schema_1.CapabilitySideEffect.Draft) {
52
+ parts.push('产生草稿,不改变线上状态');
53
+ }
54
+ if (action.errors.length > 0) {
55
+ parts.push(`错误码: ${action.errors.join(', ')}`);
56
+ }
57
+ void name;
58
+ return parts.join('。');
59
+ }
60
+ function inputsToJsonSchema(action) {
61
+ const properties = {};
62
+ const required = [];
63
+ for (const [field, input] of Object.entries(action.inputs)) {
64
+ properties[field] = inputToJsonSchema(input);
65
+ if (input.label) {
66
+ properties[field] = { ...properties[field], title: input.label };
67
+ }
68
+ if (input.default !== undefined) {
69
+ properties[field] = { ...properties[field], default: input.default };
70
+ }
71
+ if (input.hidden) {
72
+ properties[field] = { ...properties[field], deprecated: true };
73
+ }
74
+ if (input.default === undefined && !input.hidden) {
75
+ required.push(field);
76
+ }
77
+ }
78
+ return { type: 'object', properties, required };
79
+ }
80
+ /** 表面之一:GUI 表单描述(§14.2 零代码路径直接消费) */
81
+ function generateUiForms(manifest) {
82
+ return Object.entries(manifest.actions).map(([name, action]) => ({
83
+ action: name,
84
+ title: action.summary,
85
+ confirmRequired: action.confirm === capability_schema_1.CapabilityConfirm.Required,
86
+ fields: Object.entries(action.inputs)
87
+ .filter(([, input]) => !input.hidden)
88
+ .map(([field, input]) => ({
89
+ name: field,
90
+ widget: input.ui ?? widgetOf(input),
91
+ label: input.label ?? field,
92
+ required: input.default === undefined,
93
+ advanced: false,
94
+ ...(input.maxLength === undefined ? {} : { maxLength: input.maxLength }),
95
+ ...(input.maxItems === undefined ? {} : { maxItems: input.maxItems }),
96
+ })),
97
+ }));
98
+ }
99
+ function widgetOf(input) {
100
+ if (input.type === 'boolean') {
101
+ return 'switch';
102
+ }
103
+ if (input.type === 'array') {
104
+ return input.items === 'url' ? 'uploader' : 'multi-select';
105
+ }
106
+ if (input.type === 'url') {
107
+ return 'uploader';
108
+ }
109
+ return input.maxLength && input.maxLength > 200 ? 'textarea' : 'text';
110
+ }
111
+ /** 表面之三:OpenAPI 3.1 paths(供 REST 客户端与网关导入) */
112
+ function generateOpenApi(manifest) {
113
+ const paths = {};
114
+ for (const [name, action] of Object.entries(manifest.actions)) {
115
+ paths[`/actions/${name}`] = {
116
+ post: {
117
+ 'operationId': name,
118
+ 'summary': action.summary,
119
+ 'x-side-effect': action.sideEffect,
120
+ 'x-confirm': action.confirm,
121
+ 'requestBody': {
122
+ required: Object.keys(action.inputs).length > 0,
123
+ content: { 'application/json': { schema: inputsToJsonSchema(action) } },
124
+ },
125
+ 'responses': {
126
+ 200: { description: 'OK' },
127
+ ...(action.errors.length > 0
128
+ ? { 409: { description: `业务错误: ${action.errors.join(', ')}` } }
129
+ : {}),
130
+ },
131
+ },
132
+ };
133
+ }
134
+ return {
135
+ openapi: '3.1.0',
136
+ info: { title: 'AiToEarn Capability API', version: `v${manifest.version}` },
137
+ paths,
138
+ };
139
+ }
140
+ /** 表面之四:TS SDK 类型与调用签名 */
141
+ function generateSdkTypes(manifest) {
142
+ const lines = [
143
+ '// 由 capability.yaml 自动生成,请勿手工修改',
144
+ '',
145
+ 'export type CapabilityActionName =',
146
+ ...Object.keys(manifest.actions).map(name => ` | '${name}'`),
147
+ '',
148
+ ];
149
+ for (const [name, action] of Object.entries(manifest.actions)) {
150
+ const pascal = pascalCase(name);
151
+ lines.push(`export interface ${pascal}Input {`);
152
+ for (const [field, input] of Object.entries(action.inputs)) {
153
+ const optional = input.default !== undefined || input.hidden === true;
154
+ lines.push(` ${field}${optional ? '?' : ''}: ${tsTypeOf(input)}`);
155
+ }
156
+ if (!('dryRun' in action.inputs)) {
157
+ lines.push(' dryRun?: boolean');
158
+ }
159
+ lines.push(' confirmToken?: string');
160
+ lines.push('}');
161
+ lines.push(`export interface ${pascal}Result extends Record<string, unknown> {}`);
162
+ lines.push('');
163
+ }
164
+ lines.push('export interface CapabilityClient {');
165
+ for (const name of Object.keys(manifest.actions)) {
166
+ const pascal = pascalCase(name);
167
+ lines.push(` ${name}(input: ${pascal}Input): Promise<${pascal}Result>`);
168
+ }
169
+ lines.push('}');
170
+ lines.push('');
171
+ return lines.join('\n');
172
+ }
173
+ function pascalCase(name) {
174
+ return name
175
+ .split('_')
176
+ .map(part => part.charAt(0).toUpperCase() + part.slice(1))
177
+ .join('');
178
+ }
179
+ function tsTypeOf(input) {
180
+ switch (input.type) {
181
+ case 'boolean':
182
+ return 'boolean';
183
+ case 'number':
184
+ return 'number';
185
+ case 'array':
186
+ return 'string[]';
187
+ default:
188
+ return 'string';
189
+ }
190
+ }
191
+ /** 表面之五:发布前校验规则(GUI、MCP、SDK 共用同一份) */
192
+ function generateValidationRules(manifest) {
193
+ return Object.entries(manifest.actions).map(([name, action]) => {
194
+ const required = [];
195
+ const maxLength = {};
196
+ const maxItems = {};
197
+ const formats = {};
198
+ for (const [field, input] of Object.entries(action.inputs)) {
199
+ if (input.default === undefined && !input.hidden) {
200
+ required.push(field);
201
+ }
202
+ if (input.maxLength !== undefined) {
203
+ maxLength[field] = input.maxLength;
204
+ }
205
+ if (input.maxItems !== undefined) {
206
+ maxItems[field] = input.maxItems;
207
+ }
208
+ if (input.type === 'url' || input.items === 'url') {
209
+ formats[field] = 'uri';
210
+ }
211
+ }
212
+ return { action: name, required, maxLength, maxItems, formats };
213
+ });
214
+ }
215
+ /**
216
+ * 一次性派生全部五种产物,保证"文档有、界面没有、SDK 不认"不再发生。
217
+ * 入口先过一遍 schema:缺省字段(inputs/errors/confirm)自动补默认值,
218
+ * 非法清单抛 PluginError 而不是在生成器深处 TypeError。
219
+ */
220
+ function generateAllSurfaces(manifest) {
221
+ const verified = (0, capability_schema_1.verifyCapabilityManifest)(manifest);
222
+ return {
223
+ mcp: generateMcpTools(verified),
224
+ ui: generateUiForms(verified),
225
+ openapi: generateOpenApi(verified),
226
+ sdk: generateSdkTypes(verified),
227
+ validation: generateValidationRules(verified),
228
+ };
229
+ }
@@ -0,0 +1,3 @@
1
+ import type { CapabilityManifest } from './capability-schema';
2
+ /** 读取并校验 capability.yaml(§13.1 唯一事实源) */
3
+ export declare function loadCapabilityManifest(path: string): Promise<CapabilityManifest>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadCapabilityManifest = loadCapabilityManifest;
4
+ const promises_1 = require("node:fs/promises");
5
+ const yaml_1 = require("yaml");
6
+ const capability_schema_1 = require("./capability-schema");
7
+ /** 读取并校验 capability.yaml(§13.1 唯一事实源) */
8
+ async function loadCapabilityManifest(path) {
9
+ const raw = await (0, promises_1.readFile)(path, 'utf8');
10
+ return (0, capability_schema_1.verifyCapabilityManifest)((0, yaml_1.parse)(raw));
11
+ }
@@ -0,0 +1,139 @@
1
+ import { z } from 'zod';
2
+ export declare enum CapabilitySideEffect {
3
+ Read = "read",
4
+ Draft = "draft",
5
+ Write = "write"
6
+ }
7
+ export declare enum CapabilityConfirm {
8
+ Required = "required",
9
+ None = "none"
10
+ }
11
+ export declare enum CapabilityUi {
12
+ Text = "text",
13
+ Textarea = "textarea",
14
+ Uploader = "uploader",
15
+ MultiSelect = "multi-select",
16
+ Select = "select",
17
+ Switch = "switch"
18
+ }
19
+ export declare const capabilityInputSchema: z.ZodObject<{
20
+ type: z.ZodEnum<{
21
+ string: "string";
22
+ number: "number";
23
+ boolean: "boolean";
24
+ url: "url";
25
+ channelId: "channelId";
26
+ array: "array";
27
+ }>;
28
+ items: z.ZodOptional<z.ZodEnum<{
29
+ string: "string";
30
+ url: "url";
31
+ channelId: "channelId";
32
+ }>>;
33
+ maxLength: z.ZodOptional<z.ZodNumber>;
34
+ maxItems: z.ZodOptional<z.ZodNumber>;
35
+ default: z.ZodOptional<z.ZodUnknown>;
36
+ ui: z.ZodOptional<z.ZodEnum<{
37
+ text: CapabilityUi.Text;
38
+ textarea: CapabilityUi.Textarea;
39
+ uploader: CapabilityUi.Uploader;
40
+ "multi-select": CapabilityUi.MultiSelect;
41
+ select: CapabilityUi.Select;
42
+ switch: CapabilityUi.Switch;
43
+ }>>;
44
+ label: z.ZodOptional<z.ZodString>;
45
+ hidden: z.ZodOptional<z.ZodBoolean>;
46
+ }, z.core.$strip>;
47
+ export declare const capabilityActionSchema: z.ZodObject<{
48
+ summary: z.ZodString;
49
+ sideEffect: z.ZodEnum<{
50
+ read: CapabilitySideEffect.Read;
51
+ draft: CapabilitySideEffect.Draft;
52
+ write: CapabilitySideEffect.Write;
53
+ }>;
54
+ confirm: z.ZodDefault<z.ZodEnum<{
55
+ required: CapabilityConfirm.Required;
56
+ none: CapabilityConfirm.None;
57
+ }>>;
58
+ backend: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
59
+ inputs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
60
+ type: z.ZodEnum<{
61
+ string: "string";
62
+ number: "number";
63
+ boolean: "boolean";
64
+ url: "url";
65
+ channelId: "channelId";
66
+ array: "array";
67
+ }>;
68
+ items: z.ZodOptional<z.ZodEnum<{
69
+ string: "string";
70
+ url: "url";
71
+ channelId: "channelId";
72
+ }>>;
73
+ maxLength: z.ZodOptional<z.ZodNumber>;
74
+ maxItems: z.ZodOptional<z.ZodNumber>;
75
+ default: z.ZodOptional<z.ZodUnknown>;
76
+ ui: z.ZodOptional<z.ZodEnum<{
77
+ text: CapabilityUi.Text;
78
+ textarea: CapabilityUi.Textarea;
79
+ uploader: CapabilityUi.Uploader;
80
+ "multi-select": CapabilityUi.MultiSelect;
81
+ select: CapabilityUi.Select;
82
+ switch: CapabilityUi.Switch;
83
+ }>>;
84
+ label: z.ZodOptional<z.ZodString>;
85
+ hidden: z.ZodOptional<z.ZodBoolean>;
86
+ }, z.core.$strip>>>;
87
+ returns: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
88
+ errors: z.ZodDefault<z.ZodArray<z.ZodString>>;
89
+ }, z.core.$strip>;
90
+ export declare const capabilityManifestSchema: z.ZodObject<{
91
+ version: z.ZodNumber;
92
+ actions: z.ZodRecord<z.ZodString, z.ZodObject<{
93
+ summary: z.ZodString;
94
+ sideEffect: z.ZodEnum<{
95
+ read: CapabilitySideEffect.Read;
96
+ draft: CapabilitySideEffect.Draft;
97
+ write: CapabilitySideEffect.Write;
98
+ }>;
99
+ confirm: z.ZodDefault<z.ZodEnum<{
100
+ required: CapabilityConfirm.Required;
101
+ none: CapabilityConfirm.None;
102
+ }>>;
103
+ backend: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
104
+ inputs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
105
+ type: z.ZodEnum<{
106
+ string: "string";
107
+ number: "number";
108
+ boolean: "boolean";
109
+ url: "url";
110
+ channelId: "channelId";
111
+ array: "array";
112
+ }>;
113
+ items: z.ZodOptional<z.ZodEnum<{
114
+ string: "string";
115
+ url: "url";
116
+ channelId: "channelId";
117
+ }>>;
118
+ maxLength: z.ZodOptional<z.ZodNumber>;
119
+ maxItems: z.ZodOptional<z.ZodNumber>;
120
+ default: z.ZodOptional<z.ZodUnknown>;
121
+ ui: z.ZodOptional<z.ZodEnum<{
122
+ text: CapabilityUi.Text;
123
+ textarea: CapabilityUi.Textarea;
124
+ uploader: CapabilityUi.Uploader;
125
+ "multi-select": CapabilityUi.MultiSelect;
126
+ select: CapabilityUi.Select;
127
+ switch: CapabilityUi.Switch;
128
+ }>>;
129
+ label: z.ZodOptional<z.ZodString>;
130
+ hidden: z.ZodOptional<z.ZodBoolean>;
131
+ }, z.core.$strip>>>;
132
+ returns: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
133
+ errors: z.ZodDefault<z.ZodArray<z.ZodString>>;
134
+ }, z.core.$strip>>;
135
+ }, z.core.$strip>;
136
+ export type CapabilityInput = z.infer<typeof capabilityInputSchema>;
137
+ export type CapabilityAction = z.infer<typeof capabilityActionSchema>;
138
+ export type CapabilityManifest = z.infer<typeof capabilityManifestSchema>;
139
+ export declare function verifyCapabilityManifest(input: unknown): CapabilityManifest;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.capabilityManifestSchema = exports.capabilityActionSchema = exports.capabilityInputSchema = exports.CapabilityUi = exports.CapabilityConfirm = exports.CapabilitySideEffect = void 0;
4
+ exports.verifyCapabilityManifest = verifyCapabilityManifest;
5
+ const plugin_api_1 = require("@airongrong/plugin-api");
6
+ const zod_1 = require("zod");
7
+ var CapabilitySideEffect;
8
+ (function (CapabilitySideEffect) {
9
+ CapabilitySideEffect["Read"] = "read";
10
+ CapabilitySideEffect["Draft"] = "draft";
11
+ CapabilitySideEffect["Write"] = "write";
12
+ })(CapabilitySideEffect || (exports.CapabilitySideEffect = CapabilitySideEffect = {}));
13
+ var CapabilityConfirm;
14
+ (function (CapabilityConfirm) {
15
+ CapabilityConfirm["Required"] = "required";
16
+ CapabilityConfirm["None"] = "none";
17
+ })(CapabilityConfirm || (exports.CapabilityConfirm = CapabilityConfirm = {}));
18
+ var CapabilityUi;
19
+ (function (CapabilityUi) {
20
+ CapabilityUi["Text"] = "text";
21
+ CapabilityUi["Textarea"] = "textarea";
22
+ CapabilityUi["Uploader"] = "uploader";
23
+ CapabilityUi["MultiSelect"] = "multi-select";
24
+ CapabilityUi["Select"] = "select";
25
+ CapabilityUi["Switch"] = "switch";
26
+ })(CapabilityUi || (exports.CapabilityUi = CapabilityUi = {}));
27
+ exports.capabilityInputSchema = zod_1.z.object({
28
+ type: zod_1.z.enum(['string', 'number', 'boolean', 'url', 'channelId', 'array']),
29
+ items: zod_1.z.enum(['url', 'channelId', 'string']).optional(),
30
+ maxLength: zod_1.z.number().int().positive().optional(),
31
+ maxItems: zod_1.z.number().int().positive().optional(),
32
+ default: zod_1.z.unknown().optional(),
33
+ ui: zod_1.z.enum(Object.values(CapabilityUi)).optional(),
34
+ label: zod_1.z.string().min(1).optional(),
35
+ hidden: zod_1.z.boolean().optional(),
36
+ });
37
+ exports.capabilityActionSchema = zod_1.z.object({
38
+ summary: zod_1.z.string().min(1),
39
+ sideEffect: zod_1.z.enum(Object.values(CapabilitySideEffect)),
40
+ confirm: zod_1.z.enum(Object.values(CapabilityConfirm)).default(CapabilityConfirm.None),
41
+ /** 契约工具当前由哪些后端工具实现;未实现的契约条目无此字段 */
42
+ backend: zod_1.z.union([zod_1.z.string().min(1), zod_1.z.array(zod_1.z.string().min(1))]).optional(),
43
+ inputs: zod_1.z.record(zod_1.z.string(), exports.capabilityInputSchema).default({}),
44
+ returns: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).optional(),
45
+ errors: zod_1.z.array(zod_1.z.string().min(1)).default([]),
46
+ });
47
+ exports.capabilityManifestSchema = zod_1.z.object({
48
+ version: zod_1.z.number().int().min(1),
49
+ actions: zod_1.z.record(zod_1.z.string(), exports.capabilityActionSchema),
50
+ });
51
+ function verifyCapabilityManifest(input) {
52
+ const result = exports.capabilityManifestSchema.safeParse(input);
53
+ if (!result.success) {
54
+ const issue = result.error.issues[0];
55
+ throw new plugin_api_1.PluginError(plugin_api_1.PluginErrorCode.InvalidManifest, `capability.yaml 非法: ${issue.path.join('.')} ${issue.message}`, { issues: result.error.issues });
56
+ }
57
+ return result.data;
58
+ }
@@ -0,0 +1,3 @@
1
+ export * from './capability-generate';
2
+ export * from './capability-load';
3
+ export * from './capability-schema';
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./capability-generate"), exports);
18
+ __exportStar(require("./capability-load"), exports);
19
+ __exportStar(require("./capability-schema"), exports);
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
2
  "name": "@airongrong/capability",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0-beta.1",
4
+ "description": "AiToEarn capability manifest: single source of truth and generators for MCP tools, GUI forms, SDK clients, OpenAPI and validation rules",
5
+ "license": "MIT",
6
+ "type": "commonjs",
7
+ "sideEffects": false,
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "engines": {
22
+ "node": ">=20"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/yikart/aitoearn-sdk.git",
30
+ "directory": "packages/capability"
31
+ },
32
+ "homepage": "https://github.com/yikart/aitoearn-sdk/tree/main/packages/capability#readme",
33
+ "bugs": {
34
+ "url": "https://github.com/yikart/aitoearn-sdk/issues"
35
+ },
36
+ "keywords": [
37
+ "aitoearn",
38
+ "capability",
39
+ "mcp",
40
+ "codegen",
41
+ "openapi"
42
+ ],
43
+ "scripts": {
44
+ "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
45
+ "clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
46
+ "test": "vitest run",
47
+ "typecheck": "tsc -p tsconfig.json --noEmit",
48
+ "prepublishOnly": "node ../../scripts/prepublish-guard.mjs"
49
+ },
50
+ "dependencies": {
51
+ "@airongrong/plugin-api": "1.0.0-beta.0",
52
+ "yaml": "^2.8.3",
53
+ "zod": "^4.3.6"
54
+ }
55
+ }