ability-cli 0.1.0 → 0.2.2

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.
Files changed (3) hide show
  1. package/README.md +26 -15
  2. package/dist/index.js +28 -5
  3. package/package.json +53 -47
package/README.md CHANGED
@@ -13,6 +13,18 @@
13
13
 
14
14
  ## 2. 安装
15
15
 
16
+ ### 从 npm 安装(推荐)
17
+
18
+ ```bash
19
+ npm install -g ability-cli
20
+ # 或
21
+ pnpm add -g ability-cli
22
+ ```
23
+
24
+ 安装完成后在终端执行 `ability-cli --help` 即可。若提示找不到命令,请确认 npm / pnpm 的全局 bin 目录已加入 `PATH`(可先执行一次 `pnpm setup` 配置 pnpm 的全局目录)。
25
+
26
+ ### 从源码安装
27
+
16
28
  ```bash
17
29
  # 克隆仓库
18
30
  git clone <repo-url>
@@ -24,11 +36,12 @@ pnpm install
24
36
  # 构建
25
37
  pnpm build
26
38
 
27
- # 全局链接(可选,Windows 推荐)
28
- npm link
39
+ # 全局链接(开发调试)
40
+ pnpm link --global
41
+ # 或 npm link
29
42
  ```
30
43
 
31
- 构建完成后,可通过 `ability-cli`(或 `node dist/index.js`)运行。若使用全局链接,请确保 `pnpm` 的全局 bin 目录在 `PATH` 中。
44
+ 构建完成后,可通过 `ability-cli`(或 `node dist/index.js`)运行。
32
45
 
33
46
  ---
34
47
 
@@ -41,8 +54,8 @@ ability-cli config set --app-id <your-app-id> --app-secret <your-secret>
41
54
  # 搜索能力
42
55
  ability-cli search "帮我导航回家" --device-id abc123
43
56
 
44
- # 查看能力详情
45
- ability-cli inspect --ability-id 20001
57
+ # 查看能力详情(端侧能力需带设备 ID,也可用 config 里的 defaults.deviceId)
58
+ ability-cli inspect --ability-id 20001 --device-id <device-id>
46
59
 
47
60
  # 生成参数模板
48
61
  ability-cli inspect --ability-id 20001 --gen-template > params.json
@@ -80,11 +93,11 @@ ability-cli doctor
80
93
 
81
94
  | 选项 | 说明 |
82
95
  |------|------|
83
- | `[query]` | 自然语言检索,映射为查询参数 `nl` |
96
+ | `[query]` | 自然语言检索;与 `--natural-lang` 二选一或组合(`--natural-lang` 优先) |
84
97
  | `--device-id <id>` | 设备 ID;未指定时使用配置文件 `defaults.deviceId` |
85
98
  | `--app-name <name>` | 应用名称 |
86
- | `--type <type>` | 能力二级分类 |
87
- | `--capability-type <ct>` | 能力三级分类 |
99
+ | `--category <category>` | 三级分类 |
100
+ | `--natural-lang <text>` | 自然语言(优先于 `[query]`) |
88
101
  | `--json` | 仅输出 JSON(`data` 部分) |
89
102
 
90
103
  #### `inspect`
@@ -94,6 +107,7 @@ ability-cli doctor
94
107
  | 选项 | 说明 |
95
108
  |------|------|
96
109
  | `--ability-id <id>` | **必填**,能力 ID |
110
+ | `--device-id <id>` | 设备 ID;**端侧能力**查询详情时通常必填;未指定时可使用 `defaults.deviceId` |
97
111
  | `--gen-template` | 根据 `inputSchema` 生成参数模板 JSON 并输出 |
98
112
  | `--json` | 仅输出 JSON(`data` 部分) |
99
113
 
@@ -126,9 +140,8 @@ GET 能力列表。
126
140
  |------|------|
127
141
  | `--device-id <id>` | 设备 ID |
128
142
  | `--app-name <name>` | 应用名称 |
129
- | `--type <type>` | 能力二级分类 |
130
- | `--capability-type <ct>` | 能力三级分类 |
131
- | `--nl <text>` | 自然语言筛选 |
143
+ | `--category <category>` | 三级分类 |
144
+ | `--natural-lang <text>` | 自然语言筛选 |
132
145
  | `--json` | JSON 输出 |
133
146
 
134
147
  #### `raw ability-record`
@@ -156,6 +169,7 @@ GET 能力详情。
156
169
  | 选项 | 说明 |
157
170
  |------|------|
158
171
  | `--ability-id <id>` | **必填**,能力 ID |
172
+ | `--device-id <id>` | 设备 ID;**端侧能力**时通常必填;未指定时可使用 `defaults.deviceId` |
159
173
  | `--json` | JSON 输出 |
160
174
 
161
175
  #### `raw call-tool`
@@ -290,10 +304,7 @@ pnpm test # 运行测试(Vitest)
290
304
 
291
305
  ### 首次发布
292
306
 
293
- 1. `package.json` 中把占位符替换为真实地址:
294
- - `repository.url`
295
- - `homepage`
296
- - `bugs.url`
307
+ 1. (可选)在 `package.json` 中填写真实仓库地址:`repository`、`homepage`、`bugs`。
297
308
  2. 登录 npm:
298
309
 
299
310
  ```bash
package/dist/index.js CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  // src/index.ts
4
4
  import { Command } from "commander";
5
+ import { readFileSync } from "fs";
6
+ import { dirname, join } from "path";
7
+ import { fileURLToPath } from "url";
5
8
 
6
9
  // src/config.ts
7
10
  import fs from "fs";
@@ -260,9 +263,13 @@ function registerRawCommand(program2) {
260
263
  const res = await apiGet(ctx, "/ability-service/api/v1/ability/appInfo", { packageName: opts.packageName });
261
264
  handleApiResponse(res, opts.json, (data) => printJson(data));
262
265
  });
263
- raw.command("ability-info").description("GET \u80FD\u529B\u8BE6\u60C5").requiredOption("--ability-id <id>", "\u80FD\u529BID").option("--json", "JSON \u8F93\u51FA").action(async (opts) => {
266
+ raw.command("ability-info").description("GET \u80FD\u529B\u8BE6\u60C5").requiredOption("--ability-id <id>", "\u80FD\u529BID").option("--device-id <id>", "\u8BBE\u5907 ID\uFF1B\u5F53\u80FD\u529B\u4E3A\u7AEF\u4FA7\u80FD\u529B\u65F6\u5FC5\u586B").option("--json", "JSON \u8F93\u51FA").action(async (opts) => {
264
267
  const ctx = buildContext(program2.opts());
265
- const res = await apiGet(ctx, "/ability-service/api/v1/ability/abilityInfo", { abilityId: opts.abilityId });
268
+ const defaults = getDefaults();
269
+ const params = { abilityId: opts.abilityId };
270
+ const deviceId = opts.deviceId ?? defaults.deviceId;
271
+ if (deviceId) params.deviceId = deviceId;
272
+ const res = await apiGet(ctx, "/ability-service/api/v1/ability/abilityInfo", params);
266
273
  handleApiResponse(res, opts.json, (data) => printJson(data));
267
274
  });
268
275
  raw.command("call-tool").description("POST \u6267\u884C\u80FD\u529B").requiredOption("--file <path>", "JSON \u6587\u4EF6\u8DEF\u5F84").option("--json", "JSON \u8F93\u51FA").action(async (opts) => {
@@ -271,6 +278,12 @@ function registerRawCommand(program2) {
271
278
  const res = await apiPost(ctx, "/ability-service/api/mcp/async/call-tool", data);
272
279
  handleApiResponse(res, opts.json, (data2) => printJson(data2));
273
280
  });
281
+ raw.command("ability-callback").description("POST \u4E0A\u62A5\u80FD\u529B\u6267\u884C\u7ED3\u679C").requiredOption("--file <path>", "JSON \u6587\u4EF6\u8DEF\u5F84\uFF0C\u9700\u5305\u542B requestId\uFF0Cbody \u53EF\u9009").option("--json", "JSON \u8F93\u51FA").action(async (opts) => {
282
+ const ctx = buildContext(program2.opts());
283
+ const data = JSON.parse(fs2.readFileSync(opts.file, "utf-8"));
284
+ const res = await apiPost(ctx, "/ability-service/api/v1/ability/callback", data);
285
+ handleApiResponse(res, opts.json, (data2) => printJson(data2));
286
+ });
274
287
  raw.command("category-list").description("GET \u5168\u91CF\u5206\u7C7B").option("--json", "JSON \u8F93\u51FA").action(async (opts) => {
275
288
  const ctx = buildContext(program2.opts());
276
289
  const res = await apiGet(ctx, "/ability-service/api/v1/ability/category");
@@ -330,9 +343,13 @@ function generateTemplate(schema) {
330
343
  return result;
331
344
  }
332
345
  function registerInspectCommand(program2) {
333
- program2.command("inspect").description("\u67E5\u770B\u80FD\u529B\u8BE6\u60C5\u4E0E inputSchema").requiredOption("--ability-id <id>", "\u80FD\u529BID").option("--gen-template", "\u751F\u6210\u53C2\u6570\u6A21\u677F JSON").option("--json", "JSON \u8F93\u51FA").action(async (opts) => {
346
+ program2.command("inspect").description("\u67E5\u770B\u80FD\u529B\u8BE6\u60C5\u4E0E inputSchema").requiredOption("--ability-id <id>", "\u80FD\u529BID").option("--device-id <id>", "\u8BBE\u5907 ID\uFF1B\u5F53\u80FD\u529B\u4E3A\u7AEF\u4FA7\u80FD\u529B\u65F6\u5FC5\u586B").option("--gen-template", "\u751F\u6210\u53C2\u6570\u6A21\u677F JSON").option("--json", "JSON \u8F93\u51FA").action(async (opts) => {
334
347
  const ctx = buildContext(program2.opts());
335
- const res = await apiGet(ctx, "/ability-service/api/v1/ability/abilityInfo", { abilityId: opts.abilityId });
348
+ const defaults = getDefaults();
349
+ const params = { abilityId: opts.abilityId };
350
+ const deviceId = opts.deviceId ?? defaults.deviceId;
351
+ if (deviceId) params.deviceId = deviceId;
352
+ const res = await apiGet(ctx, "/ability-service/api/v1/ability/abilityInfo", params);
336
353
  handleApiResponse(res, opts.json, (data) => {
337
354
  if (opts.genTemplate && data.inputSchema) {
338
355
  printJson(generateTemplate(data.inputSchema));
@@ -448,7 +465,13 @@ function registerDoctorCommand(program2) {
448
465
 
449
466
  // src/index.ts
450
467
  var program = new Command();
451
- program.name("ability-cli").description("\u539F\u5B50\u80FD\u529B\u5E73\u53F0 CLI \u5DE5\u5177").version("0.1.0").option("--env <env>", "\u73AF\u5883 (test/prod)").option("--app-id <id>", "zy-app-id").option("--app-secret <secret>", "appSecret").option("--auth-token <token>", "Authorization").option("--base-url <url>", "\u7F51\u5173\u5730\u5740").option("--magic-sign", "\u6D4B\u8BD5\u73AF\u5883\u8DF3\u8FC7\u9A8C\u7B7E").option("-v, --verbose", "\u8BE6\u7EC6\u8F93\u51FA");
468
+ function readPackageVersion() {
469
+ const here = dirname(fileURLToPath(import.meta.url));
470
+ const pkgPath = join(here, "..", "package.json");
471
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
472
+ return pkg.version ?? "0.0.0";
473
+ }
474
+ program.name("ability-cli").description("\u539F\u5B50\u80FD\u529B\u5E73\u53F0 CLI \u5DE5\u5177").version(readPackageVersion()).option("--env <env>", "\u73AF\u5883 (test/prod)").option("--app-id <id>", "zy-app-id").option("--app-secret <secret>", "appSecret").option("--auth-token <token>", "Authorization").option("--base-url <url>", "\u7F51\u5173\u5730\u5740").option("--magic-sign", "\u6D4B\u8BD5\u73AF\u5883\u8DF3\u8FC7\u9A8C\u7B7E").option("-v, --verbose", "\u8BE6\u7EC6\u8F93\u51FA");
452
475
  registerConfigCommand(program);
453
476
  registerRawCommand(program);
454
477
  registerSearchCommand(program);
package/package.json CHANGED
@@ -1,47 +1,53 @@
1
- {
2
- "name": "ability-cli",
3
- "version": "0.1.0",
4
- "description": "原子能力平台 CLI 工具",
5
- "repository": {
6
- "type": "git",
7
- "url": "<repo-url>"
8
- },
9
- "homepage": "<repo-url>",
10
- "bugs": {
11
- "url": "<repo-url>/issues"
12
- },
13
- "type": "module",
14
- "bin": {
15
- "ability-cli": "./dist/index.js"
16
- },
17
- "files": [
18
- "dist",
19
- "README.md",
20
- "LICENSE"
21
- ],
22
- "scripts": {
23
- "build": "tsup src/index.ts --format esm --dts --clean",
24
- "dev": "tsup src/index.ts --format esm --watch",
25
- "test": "vitest run",
26
- "test:watch": "vitest",
27
- "prepublishOnly": "pnpm build && pnpm test"
28
- },
29
- "keywords": [],
30
- "author": "",
31
- "license": "ISC",
32
- "packageManager": "pnpm@10.28.2",
33
- "dependencies": {
34
- "chalk": "^5.6.2",
35
- "cli-table3": "^0.6.5",
36
- "commander": "^14.0.3"
37
- },
38
- "pnpm": {
39
- "onlyBuiltDependencies": ["esbuild"]
40
- },
41
- "devDependencies": {
42
- "@types/node": "^25.5.2",
43
- "tsup": "^8.5.1",
44
- "typescript": "^6.0.2",
45
- "vitest": "^4.1.3"
46
- }
47
- }
1
+ {
2
+ "name": "ability-cli",
3
+ "version": "0.2.2",
4
+ "description": "原子能力平台 CLI 工具",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "<repo-url>"
8
+ },
9
+ "homepage": "<repo-url>",
10
+ "bugs": {
11
+ "url": "<repo-url>/issues"
12
+ },
13
+ "type": "module",
14
+ "bin": {
15
+ "ability-cli": "./dist/index.js"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "scripts": {
23
+ "build": "tsup src/index.ts --format esm --dts --clean",
24
+ "dev": "tsup src/index.ts --format esm --watch",
25
+ "test": "vitest run",
26
+ "test:watch": "vitest",
27
+ "prepublishOnly": "npm run build && npm test"
28
+ },
29
+ "keywords": [
30
+ "ability",
31
+ "cli",
32
+ "atomic-ability",
33
+ "mcp",
34
+ "zyql"
35
+ ],
36
+ "author": "",
37
+ "license": "ISC",
38
+ "packageManager": "pnpm@10.28.2",
39
+ "dependencies": {
40
+ "chalk": "^5.6.2",
41
+ "cli-table3": "^0.6.5",
42
+ "commander": "^14.0.3"
43
+ },
44
+ "pnpm": {
45
+ "onlyBuiltDependencies": ["esbuild"]
46
+ },
47
+ "devDependencies": {
48
+ "@types/node": "^25.5.2",
49
+ "tsup": "^8.5.1",
50
+ "typescript": "^6.0.2",
51
+ "vitest": "^4.1.3"
52
+ }
53
+ }