connect-api-cli 1.1.4 → 1.1.6

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/dist/cli.js CHANGED
@@ -40,8 +40,8 @@ function printResult(result) {
40
40
 
41
41
  // src/cli/index.ts
42
42
  var import_commander = require("commander");
43
- var fs8 = __toESM(require("fs"));
44
- var import_path6 = __toESM(require("path"));
43
+ var fs9 = __toESM(require("fs"));
44
+ var import_path7 = __toESM(require("path"));
45
45
 
46
46
  // src/core/private-file.ts
47
47
  var import_fs = __toESM(require("fs"));
@@ -550,6 +550,181 @@ function openBrowser(url) {
550
550
 
551
551
  // src/core/http.ts
552
552
  var import_axios3 = __toESM(require("axios"));
553
+
554
+ // src/core/request-source.ts
555
+ var import_fs5 = __toESM(require("fs"));
556
+ var import_path4 = __toESM(require("path"));
557
+ var REQUEST_SOURCE_HEADER = "Request-Source";
558
+ var SOURCE_TOOL_NAME_HEADER = "Source-Tool-Name";
559
+ var SKILL_CHANNEL = "skill";
560
+ var CLI_CHANNEL = "cli";
561
+ var SKILL_TOOL_NAME = "hmos-connect-api-skill";
562
+ var CLI_TOOL_NAME = "connect-api-cli";
563
+ var TOOL_SPECIFIC_AGENTS = [
564
+ {
565
+ name: "codebuddy",
566
+ match: (env) => nonempty(env.CODEBUDDY) || nonempty(env.CODEBUDDY_SESSION_ID) || nonempty(env.CODEBUDDY_PROJECT_DIR)
567
+ },
568
+ {
569
+ name: "cursor",
570
+ match: (env) => nonempty(env.CURSOR_AGENT) || env.CURSOR_EXTENSION_HOST_ROLE === "agent-exec" || nonempty(env.CURSOR_SANDBOX)
571
+ },
572
+ {
573
+ // ZCode(智谱):桌面/CLI Agent 会注入 ZCODE_*(如 ZCODE_APP_VERSION、ZCODE_ENV);
574
+ // 通常不设 AI_AGENT,需靠 Tool-specific 指纹识别。
575
+ name: "zcode",
576
+ match: (env) => looksLikeZcode(env)
577
+ },
578
+ {
579
+ // TRAE:官方 Hook/Agent 文档常见 TRAE_PROJECT_DIR / TRAE_ENV_FILE;
580
+ // TRAE_AI_SHELL_ID 仅为部分检测库记录,实测 Agent 终端不一定注入。
581
+ name: "trae",
582
+ match: (env) => looksLikeTrae(env)
583
+ },
584
+ {
585
+ // 华为云码道 CodeArts Agent(OpenCode 定制分支):常只露出 OPENCODE_*,
586
+ // 需结合 codeartsdoer 路径 / 家目录,避免被后面的 opencode 抢走。
587
+ // 不把 CODEARTS_CLI_AK/SK 等鉴权变量当作身份。
588
+ name: "codearts",
589
+ match: (env) => looksLikeCodeArts(env)
590
+ },
591
+ {
592
+ name: "claude-code",
593
+ match: (env) => nonempty(env.CLAUDECODE) || nonempty(env.CLAUDE_CODE_ENTRYPOINT) || nonempty(env.CLAUDE_CODE_SESSION_ID) || nonempty(env.CLAUDE_CODE_EXECPATH)
594
+ },
595
+ {
596
+ name: "copilot",
597
+ match: (env) => nonempty(env.COPILOT_AGENT) || nonempty(env.COPILOT_CLI) || nonempty(env.COPILOT_AGENT_SESSION_ID) || nonempty(env.VSCODE_AGENT)
598
+ },
599
+ {
600
+ name: "gemini-cli",
601
+ match: (env) => nonempty(env.GEMINI_CLI)
602
+ },
603
+ {
604
+ name: "codex",
605
+ match: (env) => nonempty(env.CODEX_THREAD_ID) || nonempty(env.CODEX_SANDBOX) || nonempty(env.CODEX_CI)
606
+ },
607
+ {
608
+ // 原生 OpenCode:有 OPENCODE_* 且不像码道时才认
609
+ name: "opencode",
610
+ match: (env) => hasOpenCodeSignals(env) && !looksLikeCodeArts(env)
611
+ }
612
+ ];
613
+ function injected(value) {
614
+ return typeof value === "string" ? value : "";
615
+ }
616
+ function nonempty(value) {
617
+ return typeof value === "string" && value.trim().length > 0;
618
+ }
619
+ function isUnnamedAgentValue(value) {
620
+ return ["0", "false", "no", "off", "1", "true"].includes(value);
621
+ }
622
+ function envValueContains(env, pattern) {
623
+ for (const value of Object.values(env)) {
624
+ if (typeof value === "string" && pattern.test(value)) return true;
625
+ }
626
+ return false;
627
+ }
628
+ function hasOpenCodeSignals(env) {
629
+ return nonempty(env.OPENCODE) || nonempty(env.OPENCODE_PID) || nonempty(env.OPENCODE_BIN_PATH) || nonempty(env.OPENCODE_SERVER) || nonempty(env.OPENCODE_APP_INFO) || nonempty(env.OPENCODE_CLIENT) || nonempty(env.OPENCODE_MODES);
630
+ }
631
+ function looksLikeZcode(env = process.env) {
632
+ if (nonempty(env.ZCODE_APP_VERSION) || nonempty(env.ZCODE_ENV) || nonempty(env.ZCODE_RUNTIME_ENV) || nonempty(env.ZCODE_BASE_URL) || nonempty(env.ZCODE_WINDOWS_APP_INSTALL_DIR) || nonempty(env.ZCODE_PROCESS_LABEL) || nonempty(env.ZCODE_SERVER_WORKSPACE) || nonempty(env.ZCODE_DATA_BASE_DIR)) {
633
+ return true;
634
+ }
635
+ for (const [key, value] of Object.entries(env)) {
636
+ if (/^ZCODE[_-]/i.test(key) && nonempty(value)) return true;
637
+ }
638
+ if (envValueContains(env, /(?:^|[\\/])ZCode(?:[\\/]|$)/)) return true;
639
+ if (envValueContains(env, /(?:^|[\\/])\.zcode(?:[\\/]|$)/)) return true;
640
+ if (env.TERM_PROGRAM && /zcode/i.test(env.TERM_PROGRAM)) return true;
641
+ return false;
642
+ }
643
+ function looksLikeTrae(env = process.env) {
644
+ if (nonempty(env.TRAE_AI_SHELL_ID) || nonempty(env.TRAE_PROJECT_DIR) || nonempty(env.TRAE_ENV_FILE)) {
645
+ return true;
646
+ }
647
+ for (const [key, value] of Object.entries(env)) {
648
+ if (/^TRAE[_-]/i.test(key) && nonempty(value)) return true;
649
+ }
650
+ if (envValueContains(env, /(?:^|[\\/])Trae(?:[\\/]|$)/i)) return true;
651
+ if (env.TERM_PROGRAM && /trae/i.test(env.TERM_PROGRAM)) return true;
652
+ return false;
653
+ }
654
+ function looksLikeCodeArts(env = process.env) {
655
+ if (nonempty(env.CODEARTS_AGENT) || nonempty(env.CODEARTS_SESSION_ID) || nonempty(env.CODEARTS_DOER) || nonempty(env.CODEARTSDOER)) {
656
+ return true;
657
+ }
658
+ if (envValueContains(env, /codeartsdoer|codearts[-_]?agent/i)) return true;
659
+ return false;
660
+ }
661
+ function normalizeAgentSlug(raw) {
662
+ const v = raw.trim().toLowerCase();
663
+ if (!v || isUnnamedAgentValue(v)) return void 0;
664
+ let slug = v.replace(/_agent$/i, "");
665
+ const versionCut = slug.match(/^([a-z][a-z0-9_-]*?)(?:_\d)/);
666
+ if (versionCut) slug = versionCut[1];
667
+ slug = slug.replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "");
668
+ if (!slug) return void 0;
669
+ if (/^(?:codearts[-_]?agent|madao)$/.test(slug)) return "codearts";
670
+ return slug;
671
+ }
672
+ function detectAgentName(env = process.env) {
673
+ for (const key of ["AI_AGENT", "AGENT"]) {
674
+ const raw = env[key];
675
+ if (!nonempty(raw)) continue;
676
+ const trimmed = raw.trim();
677
+ if (isUnnamedAgentValue(trimmed.toLowerCase())) continue;
678
+ const slug = normalizeAgentSlug(trimmed);
679
+ if (slug) return slug;
680
+ }
681
+ for (const agent of TOOL_SPECIFIC_AGENTS) {
682
+ if (agent.match(env)) return agent.name;
683
+ }
684
+ return void 0;
685
+ }
686
+ function getSourceChannel() {
687
+ const raw = injected(true ? "cli" : void 0);
688
+ return raw === SKILL_CHANNEL ? SKILL_CHANNEL : CLI_CHANNEL;
689
+ }
690
+ function getRequestSource() {
691
+ if (getSourceChannel() !== SKILL_CHANNEL) return CLI_CHANNEL;
692
+ const agent = detectAgentName();
693
+ return agent ? `${agent}-skill` : SKILL_CHANNEL;
694
+ }
695
+ function readVersion() {
696
+ const fromBuild = injected(true ? "1.1.6" : void 0);
697
+ if (fromBuild) return fromBuild;
698
+ const candidates = [
699
+ import_path4.default.join(__dirname, "..", "..", "package.json"),
700
+ import_path4.default.join(__dirname, "..", "package.json")
701
+ ];
702
+ for (const pkgPath of candidates) {
703
+ try {
704
+ const pkg = JSON.parse(import_fs5.default.readFileSync(pkgPath, "utf8"));
705
+ if (pkg.version) return pkg.version;
706
+ } catch {
707
+ }
708
+ }
709
+ return "0.0.0";
710
+ }
711
+ function getSourceToolName() {
712
+ const base = getSourceChannel() === SKILL_CHANNEL ? SKILL_TOOL_NAME : CLI_TOOL_NAME;
713
+ return `${base}-${readVersion()}`;
714
+ }
715
+ function applySourceHeaders(headers) {
716
+ const source = getRequestSource();
717
+ const toolName = getSourceToolName();
718
+ if (typeof headers?.set === "function") {
719
+ headers.set(REQUEST_SOURCE_HEADER, source);
720
+ headers.set(SOURCE_TOOL_NAME_HEADER, toolName);
721
+ return;
722
+ }
723
+ headers[REQUEST_SOURCE_HEADER] = source;
724
+ headers[SOURCE_TOOL_NAME_HEADER] = toolName;
725
+ }
726
+
727
+ // src/core/http.ts
553
728
  var agcClient = import_axios3.default.create({ maxRedirects: 0 });
554
729
  function setHeader(headers, name, value) {
555
730
  if (typeof headers?.set === "function") {
@@ -595,6 +770,7 @@ agcClient.interceptors.request.use(async (config2) => {
595
770
  if (!config2.headers) {
596
771
  config2.headers = {};
597
772
  }
773
+ applySourceHeaders(config2.headers);
598
774
  applyAuthHeaders(config2.headers, token, cfg);
599
775
  if (cfg.authMode === "oauth" && !getHeader(config2.headers, "teamId")) {
600
776
  const teamId = await resolveOAuthTeamId(cfg, token);
@@ -657,17 +833,19 @@ var PublishService = class {
657
833
  });
658
834
  return response.data;
659
835
  }
660
- /** 创建应用或元服务(projectId 为 query 参数) */
836
+ /**
837
+ * 创建应用或元服务。
838
+ * projectId 为可选 query:不传时服务端先创建与应用同名的项目,再创建应用。
839
+ */
661
840
  static async createApp(req) {
662
841
  const { projectId, packageName, ...rest } = req;
663
842
  const body = { ...rest };
664
843
  if (req.installationFree === 0 && packageName) {
665
844
  body.packageName = packageName;
666
845
  }
667
- const response = await agcClient.post(
668
- `/api/publish/v3/app?projectId=${encodeURIComponent(projectId)}`,
669
- body
670
- );
846
+ const response = projectId ? await agcClient.post("/api/publish/v3/app", body, {
847
+ params: { projectId }
848
+ }) : await agcClient.post("/api/publish/v3/app", body);
671
849
  return response.data;
672
850
  }
673
851
  /** 查询团队账号下的成员角色列表 */
@@ -747,7 +925,7 @@ var PublishService = class {
747
925
  );
748
926
  return response.data;
749
927
  }
750
- /** 更新应用软件包信息(OBS 上传后上报,AGC 控制台才会出现记录) */
928
+ /** 更新应用软件包信息(OBS 上传后上报,HarmonyOS 开发者中心才会出现记录) */
751
929
  static async updateAppPackageInfo(req) {
752
930
  const { appId, releaseType, releasePhase, fileName, objectId } = req;
753
931
  const response = await agcClient.put(
@@ -1095,8 +1273,8 @@ var ProvisionService = class {
1095
1273
 
1096
1274
  // src/services/upload.ts
1097
1275
  var import_axios4 = __toESM(require("axios"));
1098
- var import_fs5 = __toESM(require("fs"));
1099
- var import_path4 = __toESM(require("path"));
1276
+ var import_fs6 = __toESM(require("fs"));
1277
+ var import_path5 = __toESM(require("path"));
1100
1278
  function pickObjectId(res) {
1101
1279
  return res.urlInfo?.objectId || res.objectId;
1102
1280
  }
@@ -1132,11 +1310,11 @@ var UploadService = class {
1132
1310
  /**
1133
1311
  * 封装好的上传文件核心流程(支持根据文件大小自动单文件或分片上传)
1134
1312
  * 文件大小 < 5MB 时使用单文件上传,否则使用分片上传。
1135
- * 仅完成 OBS 落盘;HarmonyOS `.app` 还须调用更新应用软件包信息,AGC 控制台才会有记录。
1313
+ * 仅完成 OBS 落盘;HarmonyOS `.app` 还须调用更新应用软件包信息,HarmonyOS 开发者中心才会有记录。
1136
1314
  */
1137
1315
  static async uploadFile(options) {
1138
- const stat = import_fs5.default.statSync(options.filePath);
1139
- const fileName = import_path4.default.basename(options.filePath) || "unknown";
1316
+ const stat = import_fs6.default.statSync(options.filePath);
1317
+ const fileName = import_path5.default.basename(options.filePath) || "unknown";
1140
1318
  if (stat.size < 5 * 1024 * 1024) {
1141
1319
  return this.uploadSingleFile(options, fileName, stat.size);
1142
1320
  }
@@ -1177,7 +1355,7 @@ var UploadService = class {
1177
1355
  );
1178
1356
  }
1179
1357
  const { url, headers } = urlRes.urlInfo;
1180
- const fileStream = import_fs5.default.createReadStream(options.filePath);
1358
+ const fileStream = import_fs6.default.createReadStream(options.filePath);
1181
1359
  await import_axios4.default.put(url, fileStream, {
1182
1360
  headers: this.buildObsPutHeaders(headers, contentLength),
1183
1361
  maxBodyLength: Infinity,
@@ -1218,7 +1396,7 @@ var UploadService = class {
1218
1396
  if (!uploadInfoMap) {
1219
1397
  throw new Error(`Failed to get parts upload URL: ${JSON.stringify(partsRes.ret)}`);
1220
1398
  }
1221
- const fd = import_fs5.default.openSync(options.filePath, "r");
1399
+ const fd = import_fs6.default.openSync(options.filePath, "r");
1222
1400
  const composeReqBody = {};
1223
1401
  for (let i = 1; i <= partsCount; i++) {
1224
1402
  const propKey = `additionalProp${i}`;
@@ -1227,7 +1405,7 @@ var UploadService = class {
1227
1405
  const end = Math.min(start + partSize, fileSize);
1228
1406
  const length = end - start;
1229
1407
  const buffer = Buffer.alloc(length);
1230
- import_fs5.default.readSync(fd, buffer, 0, length, start);
1408
+ import_fs6.default.readSync(fd, buffer, 0, length, start);
1231
1409
  const res = await import_axios4.default.put(uploadInfo.url, buffer, {
1232
1410
  headers: this.buildObsPutHeaders(uploadInfo.headers, length),
1233
1411
  maxBodyLength: Infinity,
@@ -1239,7 +1417,7 @@ var UploadService = class {
1239
1417
  etag
1240
1418
  };
1241
1419
  }
1242
- import_fs5.default.closeSync(fd);
1420
+ import_fs6.default.closeSync(fd);
1243
1421
  await this.composeMultipart({
1244
1422
  objectId,
1245
1423
  nspUploadId,
@@ -1250,7 +1428,7 @@ var UploadService = class {
1250
1428
  };
1251
1429
 
1252
1430
  // src/services/domain.ts
1253
- var import_fs6 = __toESM(require("fs"));
1431
+ var import_fs7 = __toESM(require("fs"));
1254
1432
  var DomainService = class {
1255
1433
  /**
1256
1434
  * 查询元服务的域名配置信息
@@ -1303,7 +1481,7 @@ var DomainService = class {
1303
1481
  }
1304
1482
  );
1305
1483
  return new Promise((resolve, reject) => {
1306
- const writer = import_fs6.default.createWriteStream(outputPath);
1484
+ const writer = import_fs7.default.createWriteStream(outputPath);
1307
1485
  response.data.pipe(writer);
1308
1486
  let error = null;
1309
1487
  writer.on("error", (err) => {
@@ -1334,8 +1512,8 @@ var DomainService = class {
1334
1512
  };
1335
1513
 
1336
1514
  // src/services/sign.ts
1337
- var import_fs7 = __toESM(require("fs"));
1338
- var import_path5 = __toESM(require("path"));
1515
+ var import_fs8 = __toESM(require("fs"));
1516
+ var import_path6 = __toESM(require("path"));
1339
1517
  var import_child_process2 = require("child_process");
1340
1518
  var import_crypto = __toESM(require("crypto"));
1341
1519
  var DEFAULT_SIGN_OUT_DIR = ".certs";
@@ -1347,11 +1525,11 @@ var SIGN_FILE_PREFIX = {
1347
1525
  };
1348
1526
  var SignService = class {
1349
1527
  static resolveSignOutputLayout(options) {
1350
- const rootDir = options.outDir ? import_path5.default.resolve(options.outDir) : import_path5.default.join(process.cwd(), DEFAULT_SIGN_OUT_DIR);
1528
+ const rootDir = options.outDir ? import_path6.default.resolve(options.outDir) : import_path6.default.join(process.cwd(), DEFAULT_SIGN_OUT_DIR);
1351
1529
  const signId = options.filename || this.createSignDefaultId();
1352
1530
  return {
1353
1531
  rootDir,
1354
- bundleDir: import_path5.default.join(rootDir, signId),
1532
+ bundleDir: import_path6.default.join(rootDir, signId),
1355
1533
  filename: signId
1356
1534
  };
1357
1535
  }
@@ -1368,12 +1546,16 @@ var SignService = class {
1368
1546
  /** 仅检查 `DEVECO_HOME` 本身及其 `Contents/`,找不到就返回 undefined */
1369
1547
  static sdkPathFromDevEcoHome(home) {
1370
1548
  if (!home) return void 0;
1371
- for (const sdk of [import_path5.default.join(home, "sdk"), import_path5.default.join(home, "Contents", "sdk")]) {
1372
- if (import_fs7.default.existsSync(import_path5.default.join(sdk, ...this.HAP_SIGN_TOOL_REL))) return sdk;
1549
+ for (const sdk of [import_path6.default.join(home, "sdk"), import_path6.default.join(home, "Contents", "sdk")]) {
1550
+ if (import_fs8.default.existsSync(import_path6.default.join(sdk, ...this.HAP_SIGN_TOOL_REL))) return sdk;
1373
1551
  }
1374
1552
  return void 0;
1375
1553
  }
1376
1554
  static async createSignP12AndCsr(options) {
1555
+ const pwd = options.pwd;
1556
+ if (!pwd) {
1557
+ throw new Error("pwd is required. Ask the user for the keystore password and pass --pwd.");
1558
+ }
1377
1559
  const javaPath = options.javaPath || "java";
1378
1560
  const sdkPath = this.resolveHarmonySdkPath(options.sdkPath);
1379
1561
  if (!sdkPath) {
@@ -1386,24 +1568,23 @@ var SignService = class {
1386
1568
  "sdkPath is required. Provide it via --sdk-path or DEVECO_HOME in .env."
1387
1569
  );
1388
1570
  }
1389
- const signToolPath = import_path5.default.join(sdkPath, "default", "openharmony", "toolchains", "lib", "hap-sign-tool.jar");
1390
- if (!import_fs7.default.existsSync(signToolPath)) {
1571
+ const signToolPath = import_path6.default.join(sdkPath, "default", "openharmony", "toolchains", "lib", "hap-sign-tool.jar");
1572
+ if (!import_fs8.default.existsSync(signToolPath)) {
1391
1573
  throw new Error(`hap-sign-tool.jar not found at ${signToolPath}`);
1392
1574
  }
1393
1575
  const { rootDir, bundleDir, filename } = this.resolveSignOutputLayout(options);
1394
- const createdBundleDir = !import_fs7.default.existsSync(bundleDir);
1395
- if (!import_fs7.default.existsSync(rootDir)) {
1396
- import_fs7.default.mkdirSync(rootDir, { recursive: true });
1576
+ const createdBundleDir = !import_fs8.default.existsSync(bundleDir);
1577
+ if (!import_fs8.default.existsSync(rootDir)) {
1578
+ import_fs8.default.mkdirSync(rootDir, { recursive: true });
1397
1579
  }
1398
- import_fs7.default.mkdirSync(bundleDir, { recursive: true });
1399
- const p12FilePath = import_path5.default.join(bundleDir, this.signFileName(filename, "p12"));
1400
- const csrFilePath = import_path5.default.join(bundleDir, this.signFileName(filename, "csr"));
1580
+ import_fs8.default.mkdirSync(bundleDir, { recursive: true });
1581
+ const p12FilePath = import_path6.default.join(bundleDir, this.signFileName(filename, "p12"));
1582
+ const csrFilePath = import_path6.default.join(bundleDir, this.signFileName(filename, "csr"));
1401
1583
  const alias = options.alias;
1402
- const pwd = options.pwd || this.createSignDefaultPassword();
1403
1584
  try {
1404
1585
  this.doCreateSignFileP12(javaPath, signToolPath, alias, pwd, p12FilePath);
1405
1586
  this.doCreateSignFileCsr(javaPath, signToolPath, alias, pwd, p12FilePath, csrFilePath);
1406
- const csrContent = import_fs7.default.readFileSync(csrFilePath, "utf8");
1587
+ const csrContent = import_fs8.default.readFileSync(csrFilePath, "utf8");
1407
1588
  const materialPath = this.placeMaterialBesideStore(bundleDir);
1408
1589
  return {
1409
1590
  alias,
@@ -1413,13 +1594,13 @@ var SignService = class {
1413
1594
  csrPath: csrFilePath,
1414
1595
  csrContent,
1415
1596
  storePath: bundleDir,
1416
- cerPath: import_path5.default.join(bundleDir, this.signFileName(filename, "cer")),
1417
- p7bPath: import_path5.default.join(bundleDir, this.signFileName(filename, "p7b")),
1597
+ cerPath: import_path6.default.join(bundleDir, this.signFileName(filename, "cer")),
1598
+ p7bPath: import_path6.default.join(bundleDir, this.signFileName(filename, "p7b")),
1418
1599
  ...materialPath ? { materialPath } : {}
1419
1600
  };
1420
1601
  } catch (err) {
1421
1602
  if (createdBundleDir) {
1422
- import_fs7.default.rmSync(bundleDir, { recursive: true, force: true });
1603
+ import_fs8.default.rmSync(bundleDir, { recursive: true, force: true });
1423
1604
  }
1424
1605
  throw err;
1425
1606
  }
@@ -1441,19 +1622,19 @@ var SignService = class {
1441
1622
  * 避免签名文件被拷到工程根目录才能编过。
1442
1623
  */
1443
1624
  static placeMaterialBesideStore(bundleDir, configDir) {
1444
- const dest = import_path5.default.join(bundleDir, "material");
1445
- if (import_fs7.default.existsSync(dest)) {
1625
+ const dest = import_path6.default.join(bundleDir, "material");
1626
+ if (import_fs8.default.existsSync(dest)) {
1446
1627
  return dest;
1447
1628
  }
1448
1629
  const home = process.env.HOME || process.env.USERPROFILE || "";
1449
- const src = import_path5.default.resolve(configDir || import_path5.default.join(home, ".ohos", "config"), "material");
1450
- if (!import_fs7.default.existsSync(src)) {
1630
+ const src = import_path6.default.resolve(configDir || import_path6.default.join(home, ".ohos", "config"), "material");
1631
+ if (!import_fs8.default.existsSync(src)) {
1451
1632
  return void 0;
1452
1633
  }
1453
1634
  try {
1454
- import_fs7.default.symlinkSync(src, dest, process.platform === "win32" ? "junction" : "dir");
1635
+ import_fs8.default.symlinkSync(src, dest, process.platform === "win32" ? "junction" : "dir");
1455
1636
  } catch {
1456
- import_fs7.default.cpSync(src, dest, { recursive: true });
1637
+ import_fs8.default.cpSync(src, dest, { recursive: true });
1457
1638
  }
1458
1639
  return dest;
1459
1640
  }
@@ -1515,12 +1696,12 @@ var SignService = class {
1515
1696
  }
1516
1697
  static COMPONENT = new Int8Array([49, 243, 9, 115, 214, 175, 91, 184, 211, 190, 177, 88, 101, 131, 192, 119]);
1517
1698
  static readDirBytes(dirPath) {
1518
- const entries = import_fs7.default.readdirSync(dirPath).filter((f) => f !== ".DS_Store");
1519
- return new Int8Array(import_fs7.default.readFileSync(import_path5.default.resolve(dirPath, entries[0])));
1699
+ const entries = import_fs8.default.readdirSync(dirPath).filter((f) => f !== ".DS_Store");
1700
+ return new Int8Array(import_fs8.default.readFileSync(import_path6.default.resolve(dirPath, entries[0])));
1520
1701
  }
1521
1702
  static readFd(materialPath) {
1522
- const fdDir = import_path5.default.resolve(materialPath, "fd");
1523
- return import_fs7.default.readdirSync(fdDir).filter((f) => f !== ".DS_Store").map((e) => this.readDirBytes(import_path5.default.resolve(fdDir, e)));
1703
+ const fdDir = import_path6.default.resolve(materialPath, "fd");
1704
+ return import_fs8.default.readdirSync(fdDir).filter((f) => f !== ".DS_Store").map((e) => this.readDirBytes(import_path6.default.resolve(fdDir, e)));
1524
1705
  }
1525
1706
  static xorBuffers(a, b) {
1526
1707
  const result = new Int8Array(a.byteLength);
@@ -1551,22 +1732,22 @@ var SignService = class {
1551
1732
  return Buffer.concat([header, iv, enc, tag]).toString("hex").toUpperCase();
1552
1733
  }
1553
1734
  static deriveEncryptionKey(configDir) {
1554
- const materialDir = import_path5.default.resolve(configDir, "material");
1735
+ const materialDir = import_path6.default.resolve(configDir, "material");
1555
1736
  const fd = this.readFd(materialDir);
1556
- const salt = this.readDirBytes(import_path5.default.resolve(materialDir, "ac"));
1737
+ const salt = this.readDirBytes(import_path6.default.resolve(materialDir, "ac"));
1557
1738
  const rawKey = new Int8Array(
1558
1739
  import_crypto.default.pbkdf2Sync(this.xorAll(fd.concat(this.COMPONENT)).toString(), salt, 1e4, 16, "sha256")
1559
1740
  );
1560
- return new Int8Array(this.aesDecrypt(rawKey, this.readDirBytes(import_path5.default.resolve(materialDir, "ce"))));
1741
+ return new Int8Array(this.aesDecrypt(rawKey, this.readDirBytes(import_path6.default.resolve(materialDir, "ce"))));
1561
1742
  }
1562
1743
  /**
1563
1744
  * 使用 DevEco Studio 的加密密钥对密码进行 AES-128-GCM 加密,
1564
1745
  * 生成 build-profile.json5 中 signingConfigs 所需的加密密码。
1565
1746
  */
1566
1747
  static encryptPassword(password, configDir) {
1567
- const dir = configDir || import_path5.default.join(process.env.HOME || "", ".ohos", "config");
1568
- if (!import_fs7.default.existsSync(import_path5.default.resolve(dir, "material"))) {
1569
- throw new Error(`\u672A\u627E\u5230\u52A0\u5BC6\u5BC6\u94A5\u76EE\u5F55: ${import_path5.default.resolve(dir, "material")}\u3002\u8BF7\u786E\u8BA4 DevEco Studio \u5DF2\u5B89\u88C5\u5E76\u751F\u6210\u8FC7\u7B7E\u540D\u914D\u7F6E\u3002`);
1748
+ const dir = configDir || import_path6.default.join(process.env.HOME || "", ".ohos", "config");
1749
+ if (!import_fs8.default.existsSync(import_path6.default.resolve(dir, "material"))) {
1750
+ throw new Error(`\u672A\u627E\u5230\u52A0\u5BC6\u5BC6\u94A5\u76EE\u5F55: ${import_path6.default.resolve(dir, "material")}\u3002\u8BF7\u786E\u8BA4 DevEco Studio \u5DF2\u5B89\u88C5\u5E76\u751F\u6210\u8FC7\u7B7E\u540D\u914D\u7F6E\u3002`);
1570
1751
  }
1571
1752
  const key = this.deriveEncryptionKey(dir);
1572
1753
  return {
@@ -1714,15 +1895,16 @@ var TestingService = class {
1714
1895
  }
1715
1896
  /** 查询测试群组成员 */
1716
1897
  static async listGroupUsers(req) {
1717
- const params = {
1718
- groupId: req.groupId,
1719
- appId: req.appId
1720
- };
1898
+ const params = {};
1721
1899
  if (req.current !== void 0) params.current = req.current;
1722
1900
  if (req.pageSize !== void 0) params.pageSize = req.pageSize;
1723
1901
  const response = await agcClient.get(
1724
1902
  "/api/app-test/v1/test-user",
1725
- { params, headers: appIdHeaders2(req.appId) }
1903
+ {
1904
+ params,
1905
+ // Connect 网关要求 groupId 走 header,query 会 400 Parameter is required
1906
+ headers: { ...appIdHeaders2(req.appId), groupId: req.groupId }
1907
+ }
1726
1908
  );
1727
1909
  return response.data;
1728
1910
  }
@@ -1749,7 +1931,7 @@ var TestingService = class {
1749
1931
  static async notifyUsers(req) {
1750
1932
  const { appId, ...body } = req;
1751
1933
  const response = await agcClient.post(
1752
- "/api/publish/v1/test/user/action/notify",
1934
+ "/api/publish/v2/test/user/action/notify",
1753
1935
  body,
1754
1936
  { headers: appIdHeaders2(appId) }
1755
1937
  );
@@ -1852,80 +2034,21 @@ var TestingService = class {
1852
2034
  }
1853
2035
  };
1854
2036
 
1855
- // src/cli/project-pick.ts
1856
- var readline = __toESM(require("readline"));
1857
- async function resolveProjectId(explicit) {
1858
- if (explicit) return explicit;
1859
- const res = await ProjectService.listProjects();
1860
- if (res.ret?.code !== 0) {
1861
- console.error(
1862
- `Failed to list projects: ret.code=${res.ret?.code} msg=${res.ret?.msg ?? "(none)"}`
1863
- );
1864
- return void 0;
1865
- }
1866
- const list = res.projectList ?? [];
1867
- if (list.length === 0) {
1868
- console.error("No projects found. Create a project in AppGallery Connect first.");
1869
- return void 0;
1870
- }
1871
- printProjectChoices(list);
1872
- if (!process.stdin.isTTY) {
1873
- console.error(
1874
- "Non-interactive mode: pass --project-id <id> (from project list)."
1875
- );
1876
- return void 0;
1877
- }
1878
- const answer = (await promptStderr("Select project by number or paste projectId: ")).trim();
1879
- if (!answer) {
1880
- console.error("No project selected.");
1881
- return void 0;
1882
- }
1883
- const byIndex = Number(answer);
1884
- if (Number.isInteger(byIndex) && byIndex >= 1 && byIndex <= list.length) {
1885
- const chosen = list[byIndex - 1];
1886
- console.error(`Using projectId=${chosen.projectId} (${chosen.name ?? ""})`);
1887
- return chosen.projectId;
1888
- }
1889
- const byId = list.find((p) => p.projectId === answer);
1890
- if (byId) {
1891
- console.error(`Using projectId=${byId.projectId} (${byId.name ?? ""})`);
1892
- return byId.projectId;
1893
- }
1894
- console.error(`Invalid selection: ${answer}`);
1895
- return void 0;
1896
- }
1897
- function printProjectChoices(list) {
1898
- console.error("Available projects (use projectId for app-create --project-id):");
1899
- list.forEach((p, i) => {
1900
- const name = p.name ? ` ${p.name}` : "";
1901
- console.error(` [${i + 1}] ${p.projectId}${name}`);
1902
- });
1903
- }
1904
- function promptStderr(question) {
1905
- const rl = readline.createInterface({ input: process.stdin, output: process.stderr });
1906
- return new Promise((resolve) => {
1907
- rl.question(question, (answer) => {
1908
- rl.close();
1909
- resolve(answer);
1910
- });
1911
- });
1912
- }
1913
-
1914
2037
  // src/cli/index.ts
1915
2038
  var program = new import_commander.Command();
1916
2039
  function readCliVersion() {
1917
- if ("1.1.4") {
1918
- return "1.1.4";
2040
+ if ("1.1.6") {
2041
+ return "1.1.6";
1919
2042
  }
1920
2043
  try {
1921
- const pkgPath = import_path6.default.join(__dirname, "..", "package.json");
1922
- const pkg = JSON.parse(fs8.readFileSync(pkgPath, "utf8"));
2044
+ const pkgPath = import_path7.default.join(__dirname, "..", "package.json");
2045
+ const pkg = JSON.parse(fs9.readFileSync(pkgPath, "utf8"));
1923
2046
  if (pkg.version) return pkg.version;
1924
2047
  } catch {
1925
2048
  }
1926
2049
  return "0.0.0";
1927
2050
  }
1928
- program.name("connect-api-cli").description("AppGallery Connect API CLI Tool").version(readCliVersion());
2051
+ program.name("connect-api-cli").description("HarmonyOS \u5F00\u53D1\u8005\u4E2D\u5FC3 API CLI Tool").version(readCliVersion());
1929
2052
  var authCmd = program.command("auth").description("Authentication management");
1930
2053
  authCmd.command("login").description("Login and cache token (client_credentials / service_account JWT / OAuth browser)").action(async () => {
1931
2054
  try {
@@ -1979,7 +2102,7 @@ authCmd.command("logout").description("Logout and clear cached access token").ac
1979
2102
  });
1980
2103
  var publishCmd = program.command("publish").description("Publishing API commands");
1981
2104
  function readJsonFile(filePath) {
1982
- return JSON.parse(fs8.readFileSync(filePath, "utf8"));
2105
+ return JSON.parse(fs9.readFileSync(filePath, "utf8"));
1983
2106
  }
1984
2107
  publishCmd.command("app-id").description("Get App ID by package name").requiredOption("-p, --package-name <packageName>", "Package name (comma-separated, max 50)").option("--package-types <packageTypes>", "Optional package types filter").action(async (options) => {
1985
2108
  try {
@@ -1989,7 +2112,10 @@ publishCmd.command("app-id").description("Get App ID by package name").requiredO
1989
2112
  reportFailure("Request failed:", e.message);
1990
2113
  }
1991
2114
  });
1992
- publishCmd.command("app-create").description("Create an app or meta-service (omit --project-id to pick from project list)").option("--project-id <projectId>", "AGC project ID (interactive pick if omitted)").requiredOption("--app-name <appName>", "App / meta-service name").option("-p, --package-name <packageName>", "Package name (required for app; omit for meta-service)").requiredOption(
2115
+ publishCmd.command("app-create").description("Create an app or meta-service (omit --project-id to let the server create a same-named project)").option(
2116
+ "--project-id <projectId>",
2117
+ "Existing project ID; omit so the server creates a project named after the app"
2118
+ ).requiredOption("--app-name <appName>", "App / meta-service name").option("-p, --package-name <packageName>", "Package name (required for app; omit for meta-service)").requiredOption(
1993
2119
  "--parent-type <parentType>",
1994
2120
  "Primary category: 2 game, 13 app"
1995
2121
  ).requiredOption(
@@ -2011,13 +2137,8 @@ publishCmd.command("app-create").description("Create an app or meta-service (omi
2011
2137
  reportFailure("Missing -p/--package-name: required when creating an app (installation-free=0)");
2012
2138
  return;
2013
2139
  }
2014
- const projectId = await resolveProjectId(options.projectId);
2015
- if (!projectId) {
2016
- process.exitCode = 1;
2017
- return;
2018
- }
2019
2140
  const res = await PublishService.createApp({
2020
- projectId,
2141
+ ...options.projectId ? { projectId: options.projectId } : {},
2021
2142
  appName: options.appName,
2022
2143
  ...options.packageName ? { packageName: options.packageName } : {},
2023
2144
  parentType,
@@ -2107,7 +2228,7 @@ publishCmd.command("file-info-update").description("Update app file info (icons/
2107
2228
  reportFailure("Request failed:", e.message);
2108
2229
  }
2109
2230
  });
2110
- publishCmd.command("package-update").description("Report uploaded package to AGC (call after OBS upload if upload file used --no-bind)").requiredOption("-a, --app-id <appId>", "App ID").requiredOption("--file-name <fileName>", "Uploaded file name").requiredOption("--object-id <objectId>", "Uploaded object ID").option("-r, --release-type <releaseType>", "Release type").option("--release-phase <releasePhase>", "Release phase").action(async (options) => {
2231
+ publishCmd.command("package-update").description("Report uploaded package to HarmonyOS \u5F00\u53D1\u8005\u4E2D\u5FC3 (call after OBS upload if upload file used --no-bind)").requiredOption("-a, --app-id <appId>", "App ID").requiredOption("--file-name <fileName>", "Uploaded file name").requiredOption("--object-id <objectId>", "Uploaded object ID").option("-r, --release-type <releaseType>", "Release type").option("--release-phase <releasePhase>", "Release phase").action(async (options) => {
2111
2232
  try {
2112
2233
  const res = await PublishService.updateAppPackageInfo({
2113
2234
  appId: options.appId,
@@ -2336,7 +2457,7 @@ publishCmd.command("shelf-off").description("Take app off shelf").requiredOption
2336
2457
  }
2337
2458
  });
2338
2459
  var projectCmd = program.command("project").description("Project Management API commands");
2339
- projectCmd.command("list").description("List AGC projects (projectId for publish app-create)").action(async () => {
2460
+ projectCmd.command("list").description("List HarmonyOS \u5F00\u53D1\u8005\u4E2D\u5FC3 projects (optional --project-id for publish app-create)").action(async () => {
2340
2461
  try {
2341
2462
  const res = await ProjectService.listProjects();
2342
2463
  printResult(res);
@@ -2352,7 +2473,7 @@ projectCmd.command("list").description("List AGC projects (projectId for publish
2352
2473
  }
2353
2474
  });
2354
2475
  var uploadCmd = program.command("upload").description("Upload Management API commands");
2355
- uploadCmd.command("file").description("Upload a file (APP, APK, images, etc.); .app is reported to AGC unless --no-bind or -r 6").requiredOption("-a, --app-id <appId>", "App ID").requiredOption("-f, --file-path <filePath>", "Path to the local file to upload").option("-r, --release-type <releaseType>", "Release type: 1 for Full, 6 for HarmonyOS Test").option("-c, --chinese-mainland <flag>", "Chinese mainland flag: 0 or 1").option("--no-bind", "OBS upload only; skip reporting the package so it will not appear in AGC").action(async (options) => {
2476
+ uploadCmd.command("file").description("Upload a file (APP, APK, images, etc.); .app is reported to HarmonyOS \u5F00\u53D1\u8005\u4E2D\u5FC3 unless --no-bind or -r 6").requiredOption("-a, --app-id <appId>", "App ID").requiredOption("-f, --file-path <filePath>", "Path to the local file to upload").option("-r, --release-type <releaseType>", "Release type: 1 for Full, 6 for HarmonyOS Test").option("-c, --chinese-mainland <flag>", "Chinese mainland flag: 0 or 1").option("--no-bind", "OBS upload only; skip reporting the package so it will not appear in HarmonyOS \u5F00\u53D1\u8005\u4E2D\u5FC3").action(async (options) => {
2356
2477
  try {
2357
2478
  console.error(`Uploading file ${options.filePath}...`);
2358
2479
  const releaseType = options.releaseType ? Number(options.releaseType) : void 0;
@@ -2362,7 +2483,7 @@ uploadCmd.command("file").description("Upload a file (APP, APK, images, etc.); .
2362
2483
  releaseType,
2363
2484
  chineseMainlandFlag: options.chineseMainland ? Number(options.chineseMainland) : void 0
2364
2485
  });
2365
- const ext = import_path6.default.extname(uploaded.fileName).toLowerCase();
2486
+ const ext = import_path7.default.extname(uploaded.fileName).toLowerCase();
2366
2487
  const shouldBind = options.bind !== false && ext === ".app" && releaseType !== 6;
2367
2488
  if (!shouldBind) {
2368
2489
  console.log(JSON.stringify({
@@ -2373,7 +2494,7 @@ uploadCmd.command("file").description("Upload a file (APP, APK, images, etc.); .
2373
2494
  }, null, 2));
2374
2495
  return;
2375
2496
  }
2376
- console.error("Reporting package to AGC...");
2497
+ console.error("Reporting package to HarmonyOS \u5F00\u53D1\u8005\u4E2D\u5FC3...");
2377
2498
  const bindRes = await PublishService.updateAppPackageInfo({
2378
2499
  appId: options.appId,
2379
2500
  fileName: uploaded.fileName,
@@ -2388,7 +2509,7 @@ uploadCmd.command("file").description("Upload a file (APP, APK, images, etc.); .
2388
2509
  }, null, 2));
2389
2510
  if (bindRes.ret?.code !== 0) {
2390
2511
  reportFailure(
2391
- "Package report failed (file is on OBS but AGC has no record):",
2512
+ "Package report failed (file is on OBS but HarmonyOS \u5F00\u53D1\u8005\u4E2D\u5FC3 has no record):",
2392
2513
  bindRes.ret?.msg || JSON.stringify(bindRes.ret)
2393
2514
  );
2394
2515
  }
@@ -2397,7 +2518,7 @@ uploadCmd.command("file").description("Upload a file (APP, APK, images, etc.); .
2397
2518
  }
2398
2519
  });
2399
2520
  var provisionCmd = program.command("provision").description("Provisioning API commands");
2400
- provisionCmd.command("csr-generate").description("Generate a new keypair and CSR file").requiredOption("--alias <alias>", "Key alias").option("--pwd <pwd>", "Key password (default: CSPRNG hex, returned as .pwd; not written to disk)").option("--out-dir <outDir>", "Root output directory (default: ./.certs; each run adds a CSPRNG subdirectory)").option("--filename <filename>", "Shared random id for the cert subdirectory (files get key_/cert_/profile_ prefixes)").option("--sdk-path <sdkPath>", "Path to HarmonyOS SDK (or DEVECO_HOME in .env)").option("--java-path <javaPath>", "Path to java executable (default: java)").action(async (options) => {
2521
+ provisionCmd.command("csr-generate").description("Generate a new keypair and CSR file").requiredOption("--alias <alias>", "Key alias").requiredOption("--pwd <pwd>", "Key password entered by the user").option("--out-dir <outDir>", "Root output directory (default: ./.certs; each run adds a CSPRNG subdirectory)").option("--filename <filename>", "Shared random id for the cert subdirectory (files get key_/cert_/profile_ prefixes)").option("--sdk-path <sdkPath>", "Path to HarmonyOS SDK (or DEVECO_HOME in .env)").option("--java-path <javaPath>", "Path to java executable (default: java)").action(async (options) => {
2401
2522
  try {
2402
2523
  const res = await SignService.createSignP12AndCsr({
2403
2524
  alias: options.alias,
@@ -2423,7 +2544,7 @@ provisionCmd.command("encrypt-pwd").description("\u52A0\u5BC6 P12 \u5BC6\u7801\u
2423
2544
  });
2424
2545
  provisionCmd.command("cert-create").description("Create a certificate").requiredOption("--csr <csrFile>", "Path to CSR file").requiredOption("--cert-name <certName>", "Certificate name").requiredOption("--cert-type <certType>", "Certificate type (1: debug, 2: release, 3: in-house, 4: binary)").action(async (options) => {
2425
2546
  try {
2426
- const csrContent = fs8.readFileSync(options.csr, "utf8");
2547
+ const csrContent = fs9.readFileSync(options.csr, "utf8");
2427
2548
  const res = await ProvisionService.createCert({
2428
2549
  csr: csrContent,
2429
2550
  certName: options.certName,
@@ -2457,7 +2578,7 @@ provisionCmd.command("cert-delete").description("Delete certificates").requiredO
2457
2578
  });
2458
2579
  provisionCmd.command("device-add").description("Add new devices").requiredOption("--devices <devicesFile>", 'Path to JSON file containing devices array [{"deviceName":"name","udid":"udid","deviceType":1}]').action(async (options) => {
2459
2580
  try {
2460
- const fileContent = fs8.readFileSync(options.devices, "utf8");
2581
+ const fileContent = fs9.readFileSync(options.devices, "utf8");
2461
2582
  const deviceList = JSON.parse(fileContent);
2462
2583
  const res = await ProvisionService.addDevice({ deviceList });
2463
2584
  printResult(res);
@@ -2580,7 +2701,7 @@ provisionCmd.command("acl-eligible").description("List eligible ACL permissions
2580
2701
  });
2581
2702
  provisionCmd.command("acl-apply").description("Apply for restricted ACL permissions").requiredOption("-a, --app-id <appId>", "App ID").requiredOption("--acls <aclsFile>", 'Path to JSON file containing ACL permissions [{"name":"name","reason":"reason"}]').option("--attachment <attachment>", "Attachment object ID").action(async (options) => {
2582
2703
  try {
2583
- const fileContent = fs8.readFileSync(options.acls, "utf8");
2704
+ const fileContent = fs9.readFileSync(options.acls, "utf8");
2584
2705
  const aclPermissionList = JSON.parse(fileContent);
2585
2706
  const req = { appId: options.appId, aclPermissionList };
2586
2707
  if (options.attachment) req.attachment = options.attachment;
@@ -2620,7 +2741,7 @@ domainCmd.command("query").description("Query domain configuration").requiredOpt
2620
2741
  });
2621
2742
  domainCmd.command("update").description("Add or update domain configuration").requiredOption("-a, --app-id <appId>", "App ID").requiredOption("-c, --category <category>", "Category: server or business").requiredOption("--domains <domainsFile>", 'Path to JSON file containing domains array [{"type":"httpRequest","value":"https://..."}]').action(async (options) => {
2622
2743
  try {
2623
- const fileContent = fs8.readFileSync(options.domains, "utf8");
2744
+ const fileContent = fs9.readFileSync(options.domains, "utf8");
2624
2745
  const domains = JSON.parse(fileContent);
2625
2746
  const res = await DomainService.updateDomain({
2626
2747
  appId: options.appId,
@@ -2655,7 +2776,7 @@ domainCmd.command("verify-file").description("Download domain verify file").requ
2655
2776
  });
2656
2777
  domainCmd.command("pre-check").description("Pre-check business domain configuration").requiredOption("-a, --app-id <appId>", "App ID").requiredOption("--domain <domainFile>", 'Path to JSON file containing domain object {"type":"webView","value":"https://..."}').action(async (options) => {
2657
2778
  try {
2658
- const fileContent = fs8.readFileSync(options.domain, "utf8");
2779
+ const fileContent = fs9.readFileSync(options.domain, "utf8");
2659
2780
  const domain = JSON.parse(fileContent);
2660
2781
  const res = await DomainService.preCheckDomain({
2661
2782
  appId: options.appId,