ability-cli 0.3.0 → 0.3.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.
Files changed (2) hide show
  1. package/dist/index.js +47 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -278,13 +278,19 @@ function registerRawCommand(program2) {
278
278
  const res = await apiGet(ctx, agentPath.abilityList, params);
279
279
  handleApiResponse(res, opts.json, (data) => printAbilityTable(data));
280
280
  });
281
- raw.command("app-info").description("GET \u5E94\u7528\u4FE1\u606F").requiredOption("--package-name <pkg>", "\u5E94\u7528\u5305\u540D").option("--json", "JSON \u8F93\u51FA").action(async (opts) => {
281
+ raw.command("app-info").description("GET \u5E94\u7528\u4FE1\u606F").addHelpText(
282
+ "after",
283
+ "\n\u63D0\u793A\uFF1A\u9009\u9879\u8BF4\u660E\u4E2D\u4EE5\u300C\u3010\u5FC5\u586B\u3011\u300D\u5F00\u5934\u7684\u5FC5\u987B\u63D0\u4F9B\uFF0C\u5176\u4F59\u5747\u4E3A\u53EF\u9009\u3002\n"
284
+ ).requiredOption("--package-name <pkg>", "\u3010\u5FC5\u586B\u3011\u5E94\u7528\u5305\u540D").option("--json", "JSON \u8F93\u51FA").action(async (opts) => {
282
285
  const merged = { ...program2.opts(), ...opts };
283
286
  const ctx = buildAgentRequestContext(merged);
284
287
  const res = await apiGet(ctx, agentPath.appInfo, { packageName: opts.packageName });
285
288
  handleApiResponse(res, opts.json, (data) => printJson(data));
286
289
  });
287
- raw.command("ability-info").description("GET \u80FD\u529B\u8BE6\u60C5").requiredOption("--ability-id <id>", "\u80FD\u529BID").option("--device-id <id>", "\u8BBE\u5907 ID\uFF1B\u7AEF\u4FA7\u80FD\u529B\u5EFA\u8BAE\u586B\u5199").option("--json", "JSON \u8F93\u51FA").action(async (opts) => {
290
+ raw.command("ability-info").description("GET \u80FD\u529B\u8BE6\u60C5").addHelpText(
291
+ "after",
292
+ "\n\u63D0\u793A\uFF1A\u9009\u9879\u8BF4\u660E\u4E2D\u4EE5\u300C\u3010\u5FC5\u586B\u3011\u300D\u5F00\u5934\u7684\u5FC5\u987B\u63D0\u4F9B\uFF0C\u5176\u4F59\u5747\u4E3A\u53EF\u9009\u3002\n"
293
+ ).requiredOption("--ability-id <id>", "\u3010\u5FC5\u586B\u3011\u80FD\u529B ID").option("--device-id <id>", "\u8BBE\u5907 ID\uFF1B\u7AEF\u4FA7\u80FD\u529B\u5EFA\u8BAE\u586B\u5199").option("--json", "JSON \u8F93\u51FA").action(async (opts) => {
288
294
  const merged = { ...program2.opts(), ...opts };
289
295
  const ctx = buildAgentRequestContext(merged);
290
296
  const params = { abilityId: opts.abilityId };
@@ -292,7 +298,10 @@ function registerRawCommand(program2) {
292
298
  const res = await apiGet(ctx, agentPath.abilityInfo, params);
293
299
  handleApiResponse(res, opts.json, (data) => printJson(data));
294
300
  });
295
- raw.command("call").description("POST \u6267\u884C\u80FD\u529B\uFF08Agent API\uFF09").requiredOption("--file <path>", "\u8BF7\u6C42\u4F53 JSON \u6587\u4EF6\u8DEF\u5F84").option("--json", "JSON \u8F93\u51FA").action(async (opts) => {
301
+ raw.command("call").description("POST \u6267\u884C\u80FD\u529B\uFF08Agent API\uFF09").addHelpText(
302
+ "after",
303
+ "\n\u63D0\u793A\uFF1A\u9009\u9879\u8BF4\u660E\u4E2D\u4EE5\u300C\u3010\u5FC5\u586B\u3011\u300D\u5F00\u5934\u7684\u5FC5\u987B\u63D0\u4F9B\uFF0C\u5176\u4F59\u5747\u4E3A\u53EF\u9009\u3002\n"
304
+ ).requiredOption("--file <path>", "\u3010\u5FC5\u586B\u3011\u8BF7\u6C42\u4F53 JSON \u6587\u4EF6\u8DEF\u5F84").option("--json", "JSON \u8F93\u51FA").action(async (opts) => {
296
305
  const merged = { ...program2.opts(), ...opts };
297
306
  const ctx = buildAgentRequestContext(merged);
298
307
  const data = JSON.parse(fs2.readFileSync(opts.file, "utf-8"));
@@ -358,7 +367,10 @@ function generateTemplate(schema) {
358
367
  return result;
359
368
  }
360
369
  function registerInspectCommand(program2) {
361
- 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\u7AEF\u4FA7\u80FD\u529B\u5EFA\u8BAE\u586B\u5199").option("--gen-template", "\u751F\u6210\u53C2\u6570\u6A21\u677F JSON").option("--json", "JSON \u8F93\u51FA").action(async (opts) => {
370
+ program2.command("inspect").description("\u67E5\u770B\u80FD\u529B\u8BE6\u60C5\u4E0E inputSchema").addHelpText(
371
+ "after",
372
+ "\n\u63D0\u793A\uFF1A\u9009\u9879\u8BF4\u660E\u4E2D\u4EE5\u300C\u3010\u5FC5\u586B\u3011\u300D\u5F00\u5934\u7684\u5FC5\u987B\u63D0\u4F9B\uFF0C\u5176\u4F59\u5747\u4E3A\u53EF\u9009\u3002\n"
373
+ ).requiredOption("--ability-id <id>", "\u3010\u5FC5\u586B\u3011\u80FD\u529B ID").option("--device-id <id>", "\u8BBE\u5907 ID\uFF1B\u7AEF\u4FA7\u80FD\u529B\u5EFA\u8BAE\u586B\u5199").option("--gen-template", "\u751F\u6210\u53C2\u6570\u6A21\u677F JSON").option("--json", "JSON \u8F93\u51FA").action(async (opts) => {
362
374
  const merged = { ...program2.opts(), ...opts };
363
375
  const ctx = buildAgentRequestContext(merged);
364
376
  const params = { abilityId: opts.abilityId };
@@ -377,8 +389,33 @@ function registerInspectCommand(program2) {
377
389
  // src/commands/exec.ts
378
390
  import { randomUUID } from "crypto";
379
391
  import fs3 from "fs";
392
+
393
+ // src/parse-cli-json.ts
394
+ function parseCliJsonString(raw, label) {
395
+ const s = raw.replace(/^\uFEFF/, "").trim();
396
+ if (!s) return {};
397
+ try {
398
+ return JSON.parse(s);
399
+ } catch (e) {
400
+ const msg = e instanceof Error ? e.message : String(e);
401
+ let hint = "";
402
+ if (/^\s*\{\s*'/.test(s)) {
403
+ hint = " JSON \u952E\u540D\u987B\u7528\u82F1\u6587\u53CC\u5F15\u53F7\uFF1B\u5F53\u524D\u5185\u5BB9\u5728 { \u540E\u51FA\u73B0\u4E86\u5355\u5F15\u53F7\u3002\u6700\u7A33\u59A5\uFF1A\u5C06 JSON \u5B58\u4E3A params.json\uFF08UTF-8\uFF09\uFF0C\u518D\u4F7F\u7528 --params params.json\u3002";
404
+ } else if (/[\u201c\u201d\u2018\u2019]/.test(s)) {
405
+ hint = ' \u68C0\u6D4B\u5230\u5F2F\u5F15\u53F7\uFF08\u201C \u201D \u2018 \u2019\uFF09\u3002\u8BF7\u6539\u4E3A ASCII \u53CC\u5F15\u53F7 " \u3002';
406
+ }
407
+ const preview = s.length > 160 ? `${s.slice(0, 160)}\u2026` : s;
408
+ throw new Error(`${label} \u89E3\u6790\u5931\u8D25\uFF1A${msg}.${hint}
409
+ \u5B9E\u9645\u6536\u5230\u7684\u5F00\u5934\uFF1A${JSON.stringify(preview.slice(0, 80))}`);
410
+ }
411
+ }
412
+
413
+ // src/commands/exec.ts
380
414
  function registerExecCommand(program2) {
381
- program2.command("exec").description("\u6267\u884C\u80FD\u529B").requiredOption("--ability-id <id>", "\u80FD\u529BID").option("--params <json>", "\u53C2\u6570 JSON \u5B57\u7B26\u4E32\u6216\u6587\u4EF6\u8DEF\u5F84").option("--device-id <id>", "\u8BBE\u5907ID").option("--message-id <id>", "messageId").option("--trace-id <id>", "traceId").option("--timeout <ms>", "\u8D85\u65F6\uFF08\u6BEB\u79D2\uFF09\uFF1B\u4E0D\u4F20\u5219\u7528\u914D\u7F6E\u6587\u4EF6 defaults.timeout\uFF0C\u9ED8\u8BA4 30000").option("--response-type <type>", "\u8FD4\u56DE\u503C\u5904\u7406\u65B9\u5F0F: NONE | MCP | CONVERT").option("--json", "JSON \u8F93\u51FA").action(async (opts) => {
415
+ program2.command("exec").description("\u6267\u884C\u80FD\u529B").addHelpText(
416
+ "after",
417
+ "\n\u63D0\u793A\uFF1A\u9009\u9879\u8BF4\u660E\u4E2D\u4EE5\u300C\u3010\u5FC5\u586B\u3011\u300D\u5F00\u5934\u7684\u5FC5\u987B\u63D0\u4F9B\uFF0C\u5176\u4F59\u5747\u4E3A\u53EF\u9009\u3002\n"
418
+ ).requiredOption("--ability-id <id>", "\u3010\u5FC5\u586B\u3011\u80FD\u529B ID").option("--params <json>", "\u53C2\u6570 JSON \u5B57\u7B26\u4E32\u6216\u6587\u4EF6\u8DEF\u5F84").option("--device-id <id>", "\u8BBE\u5907ID").option("--message-id <id>", "messageId").option("--trace-id <id>", "traceId").option("--timeout <ms>", "\u8D85\u65F6\uFF08\u6BEB\u79D2\uFF09\uFF1B\u4E0D\u4F20\u5219\u7528\u914D\u7F6E\u6587\u4EF6 defaults.timeout\uFF0C\u9ED8\u8BA4 30000").option("--response-type <type>", "\u8FD4\u56DE\u503C\u5904\u7406\u65B9\u5F0F: NONE | MCP | CONVERT").option("--json", "JSON \u8F93\u51FA").action(async (opts) => {
382
419
  const merged = { ...program2.opts(), ...opts };
383
420
  const ctx = buildAgentRequestContext(merged);
384
421
  const cliCfg = loadConfig();
@@ -386,9 +423,10 @@ function registerExecCommand(program2) {
386
423
  let params = {};
387
424
  if (opts.params) {
388
425
  if (fs3.existsSync(opts.params)) {
389
- params = JSON.parse(fs3.readFileSync(opts.params, "utf-8"));
426
+ const text = fs3.readFileSync(opts.params, "utf-8");
427
+ params = parseCliJsonString(text, "\u53C2\u6570\u6587\u4EF6");
390
428
  } else {
391
- params = JSON.parse(opts.params);
429
+ params = parseCliJsonString(opts.params, "--params");
392
430
  }
393
431
  }
394
432
  const body = {
@@ -462,9 +500,10 @@ function registerDoctorCommand(program2) {
462
500
  console.log(chalk3.bold.cyan("\n\u2500\u2500 CLI \u5065\u5EB7\u68C0\u67E5 \u2500\u2500\n"));
463
501
  const configPath = getDefaultConfigPath();
464
502
  const config = loadConfig();
503
+ const effectiveEnv = process.env.ABILITY_CLI_ENV ?? merged.env ?? config.env;
465
504
  const checks = [
466
505
  ["\u914D\u7F6E\u6587\u4EF6", configPath, true],
467
- ["\u5F53\u524D\u73AF\u5883", config.env, true],
506
+ ["\u5F53\u524D\u73AF\u5883", effectiveEnv, true],
468
507
  ["baseUrl", ctx.baseUrl || "(\u7A7A)", !!ctx.baseUrl],
469
508
  ["Authorization(sk)", ctx.authToken ? "******" : "(\u7A7A)", !!ctx.authToken],
470
509
  ["zy-device-id", ctx.deviceId || "(\u7A7A)", !!ctx.deviceId]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ability-cli",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "原子能力平台 CLI 工具",
5
5
  "repository": {
6
6
  "type": "git",