@coze-arch/cli 0.0.36-alpha.a7a716 → 0.0.36-alpha.af24fb

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 (109) hide show
  1. package/README.md +65 -114
  2. package/docs/deploy.md +10 -2
  3. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +74 -18
  4. package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +1 -1
  5. package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +1 -1
  6. package/lib/__templates__/expo/client/metro.config.js +3 -1
  7. package/lib/__templates__/expo/pnpm-lock.yaml +5 -5
  8. package/lib/__templates__/expo/server/package.json +2 -2
  9. package/lib/__templates__/expo/server/src/index.ts +1 -1
  10. package/lib/__templates__/expo/template.config.js +11 -2
  11. package/lib/__templates__/native-static/.coze +2 -0
  12. package/lib/__templates__/native-static/scripts/serve.ps1 +7 -0
  13. package/lib/__templates__/nextjs/.coze +5 -0
  14. package/lib/__templates__/nextjs/package.json +1 -1
  15. package/lib/__templates__/nextjs/pnpm-lock.yaml +5 -5
  16. package/lib/__templates__/nextjs/scripts/build.ps1 +16 -0
  17. package/lib/__templates__/nextjs/scripts/dev.ps1 +63 -0
  18. package/lib/__templates__/nextjs/scripts/dev.sh +83 -2
  19. package/lib/__templates__/nextjs/scripts/prepare.ps1 +18 -0
  20. package/lib/__templates__/nextjs/scripts/start.ps1 +11 -0
  21. package/lib/__templates__/nextjs/scripts/validate.ps1 +8 -0
  22. package/lib/__templates__/nextjs/template.config.js +1 -1
  23. package/lib/__templates__/nuxt-vue/.coze +5 -0
  24. package/lib/__templates__/nuxt-vue/package.json +1 -1
  25. package/lib/__templates__/nuxt-vue/pnpm-lock.yaml +5 -5
  26. package/lib/__templates__/nuxt-vue/scripts/build.ps1 +12 -0
  27. package/lib/__templates__/nuxt-vue/scripts/dev.ps1 +63 -0
  28. package/lib/__templates__/nuxt-vue/scripts/dev.sh +82 -1
  29. package/lib/__templates__/nuxt-vue/scripts/prepare.ps1 +12 -0
  30. package/lib/__templates__/nuxt-vue/scripts/start.ps1 +11 -0
  31. package/lib/__templates__/nuxt-vue/scripts/validate.ps1 +8 -0
  32. package/lib/__templates__/phaser/.coze +5 -0
  33. package/lib/__templates__/phaser/README.md +8 -0
  34. package/lib/__templates__/phaser/scripts/build.ps1 +12 -0
  35. package/lib/__templates__/phaser/scripts/dev.ps1 +49 -0
  36. package/lib/__templates__/phaser/scripts/prepare.ps1 +8 -0
  37. package/lib/__templates__/phaser/scripts/start.ps1 +49 -0
  38. package/lib/__templates__/phaser/scripts/validate.ps1 +7 -0
  39. package/lib/__templates__/phaser/src/global.d.ts +3 -0
  40. package/lib/__templates__/phaser/src/scene/BootScene.ts +4 -0
  41. package/lib/__templates__/phaser/src/scene/DevLoadingScene.ts +3 -0
  42. package/lib/__templates__/phaser/src/utils/mark-editable.ts +8 -1
  43. package/lib/__templates__/phaser/vite.config.ts +1 -1
  44. package/lib/__templates__/phaser-static/.coze +15 -0
  45. package/lib/__templates__/phaser-static/README.md +40 -0
  46. package/lib/__templates__/phaser-static/_gitignore +6 -0
  47. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0001.png +0 -0
  48. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0002.png +0 -0
  49. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0003.png +0 -0
  50. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0004.png +0 -0
  51. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0005.png +0 -0
  52. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0006.png +0 -0
  53. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0007.png +0 -0
  54. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0008.png +0 -0
  55. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0009.png +0 -0
  56. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0010.png +0 -0
  57. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0011.png +0 -0
  58. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0012.png +0 -0
  59. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0013.png +0 -0
  60. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0014.png +0 -0
  61. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0015.png +0 -0
  62. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0016.png +0 -0
  63. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0017.png +0 -0
  64. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0018.png +0 -0
  65. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0019.png +0 -0
  66. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0020.png +0 -0
  67. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0021.png +0 -0
  68. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0022.png +0 -0
  69. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0023.png +0 -0
  70. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0024.png +0 -0
  71. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/manifest.json +11 -0
  72. package/lib/__templates__/phaser-static/debug-runtime/flow-graph.json +20 -0
  73. package/lib/__templates__/phaser-static/index.html +17 -0
  74. package/lib/__templates__/phaser-static/scripts/serve.ps1 +7 -0
  75. package/lib/__templates__/phaser-static/src/assets.js +15 -0
  76. package/lib/__templates__/phaser-static/src/main.js +26 -0
  77. package/lib/__templates__/phaser-static/src/phaser.js +7 -0
  78. package/lib/__templates__/phaser-static/src/scene/BootScene.js +205 -0
  79. package/lib/__templates__/phaser-static/src/scene/DevLoadingScene.js +67 -0
  80. package/lib/__templates__/phaser-static/src/style.css +28 -0
  81. package/lib/__templates__/phaser-static/src/utils/asset-loader.js +267 -0
  82. package/lib/__templates__/phaser-static/src/utils/index.js +2 -0
  83. package/lib/__templates__/phaser-static/src/utils/mark-editable.js +3 -0
  84. package/lib/__templates__/phaser-static/template.config.js +35 -0
  85. package/lib/__templates__/pi-agent/package.json +1 -1
  86. package/lib/__templates__/pi-agent/pnpm-lock.yaml +5 -5
  87. package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +1 -1
  88. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +150 -68
  89. package/lib/__templates__/taro/AGENTS.md +11 -7
  90. package/lib/__templates__/taro/README.md +4 -4
  91. package/lib/__templates__/taro/config/index.ts +10 -2
  92. package/lib/__templates__/taro/pnpm-lock.yaml +5 -5
  93. package/lib/__templates__/taro/server/package.json +1 -1
  94. package/lib/__templates__/taro/server/src/main.ts +8 -2
  95. package/lib/__templates__/templates.json +26 -1
  96. package/lib/__templates__/vite/.coze +5 -0
  97. package/lib/__templates__/vite/package.json +1 -1
  98. package/lib/__templates__/vite/pnpm-lock.yaml +5 -5
  99. package/lib/__templates__/vite/scripts/build.ps1 +16 -0
  100. package/lib/__templates__/vite/scripts/dev.ps1 +63 -0
  101. package/lib/__templates__/vite/scripts/dev.sh +82 -1
  102. package/lib/__templates__/vite/scripts/prepare.ps1 +18 -0
  103. package/lib/__templates__/vite/scripts/start.ps1 +11 -0
  104. package/lib/__templates__/vite/scripts/validate.ps1 +8 -0
  105. package/lib/__templates__/vite/template.config.js +1 -1
  106. package/lib/cli.js +435 -88
  107. package/lib/deploy/package-project.js +22 -4
  108. package/lib/deploy/package-project.py +18 -3
  109. package/package.json +1 -1
package/lib/cli.js CHANGED
@@ -28,6 +28,7 @@ var node_os = require('node:os');
28
28
  var promises = require('node:fs/promises');
29
29
  var node_child_process = require('node:child_process');
30
30
  var node_util = require('node:util');
31
+ var tar = require('tar');
31
32
  var node_stream = require('node:stream');
32
33
 
33
34
  /**
@@ -2113,7 +2114,7 @@ const EventBuilder = {
2113
2114
  };
2114
2115
 
2115
2116
  var name = "@coze-arch/cli";
2116
- var version = "0.0.36-alpha.a7a716";
2117
+ var version = "0.0.36-alpha.af24fb";
2117
2118
  var description = "coze coding devtools cli";
2118
2119
  var license = "MIT";
2119
2120
  var author = "fanwenjie.fe@bytedance.com";
@@ -5961,35 +5962,66 @@ const saveProjectPatchState = async (
5961
5962
  await saveTomlCozeConfig(config, projectPath);
5962
5963
  };
5963
5964
 
5964
- /**
5965
- * 获取指定命令的配置
5966
- *
5967
- * @param config - .coze 配置对象
5968
- * @param commandName - 命令名称 (dev/build/start)
5969
- * @returns 命令配置数组
5970
- */
5971
- const getCommandConfig = (
5965
+
5966
+
5967
+ const getDefaultCommandConfig = (
5972
5968
  config,
5973
5969
  commandName,
5974
5970
  ) => {
5975
- let commandConfig;
5971
+ switch (commandName) {
5972
+ case 'dev':
5973
+ return _optionalChain$k([config, 'access', _ => _.dev, 'optionalAccess', _2 => _2.run]);
5974
+ case 'build':
5975
+ return _optionalChain$k([config, 'access', _3 => _3.deploy, 'optionalAccess', _4 => _4.build]);
5976
+ case 'start':
5977
+ return _optionalChain$k([config, 'access', _5 => _5.deploy, 'optionalAccess', _6 => _6.run]);
5978
+ case 'validate':
5979
+ return _optionalChain$k([config, 'access', _7 => _7.dev, 'optionalAccess', _8 => _8.validate]);
5980
+ default:
5981
+ throw new Error(`Unknown command: ${commandName}`);
5982
+ }
5983
+ };
5976
5984
 
5985
+ const getWindowsCommandConfig = (
5986
+ config,
5987
+ commandName,
5988
+ ) => {
5977
5989
  switch (commandName) {
5978
5990
  case 'dev':
5979
- commandConfig = _optionalChain$k([config, 'access', _ => _.dev, 'optionalAccess', _2 => _2.run]);
5980
- break;
5991
+ return _optionalChain$k([config, 'access', _9 => _9.dev, 'optionalAccess', _10 => _10.run_win]);
5981
5992
  case 'build':
5982
- commandConfig = _optionalChain$k([config, 'access', _3 => _3.deploy, 'optionalAccess', _4 => _4.build]);
5983
- break;
5993
+ return _optionalChain$k([config, 'access', _11 => _11.deploy, 'optionalAccess', _12 => _12.build_win]);
5984
5994
  case 'start':
5985
- commandConfig = _optionalChain$k([config, 'access', _5 => _5.deploy, 'optionalAccess', _6 => _6.run]);
5986
- break;
5995
+ return _optionalChain$k([config, 'access', _13 => _13.deploy, 'optionalAccess', _14 => _14.run_win]);
5987
5996
  case 'validate':
5988
- commandConfig = _optionalChain$k([config, 'access', _7 => _7.dev, 'optionalAccess', _8 => _8.validate]);
5989
- break;
5997
+ return _optionalChain$k([config, 'access', _15 => _15.dev, 'optionalAccess', _16 => _16.validate_win]);
5990
5998
  default:
5991
5999
  throw new Error(`Unknown command: ${commandName}`);
5992
6000
  }
6001
+ };
6002
+
6003
+ /**
6004
+ * 获取指定命令的配置
6005
+ *
6006
+ * Windows 优先使用非空的 *_win 配置;其他平台(包括 WSL)始终使用默认配置。
6007
+ *
6008
+ * @param config - .coze 配置对象
6009
+ * @param commandName - 命令名称 (dev/build/start)
6010
+ * @returns 命令配置数组
6011
+ */
6012
+ const getCommandConfig = (
6013
+ config,
6014
+ commandName,
6015
+ platform = process.platform,
6016
+ ) => {
6017
+ const defaultCommandConfig = getDefaultCommandConfig(config, commandName);
6018
+ const windowsCommandConfig =
6019
+ platform === 'win32'
6020
+ ? getWindowsCommandConfig(config, commandName)
6021
+ : undefined;
6022
+ const commandConfig = _optionalChain$k([windowsCommandConfig, 'optionalAccess', _17 => _17.length])
6023
+ ? windowsCommandConfig
6024
+ : defaultCommandConfig;
5993
6025
 
5994
6026
  if (!commandConfig || commandConfig.length === 0) {
5995
6027
  throw new Error(
@@ -10484,11 +10516,15 @@ const loadConfig = async (options = {}) => {
10484
10516
  }
10485
10517
  : {}),
10486
10518
  ...(process.env.COZE_ORG_ID ? { organizationId: process.env.COZE_ORG_ID } : {}),
10519
+ ...(process.env.COZE_ACCOUNT_ID ? { cozeAccountId: process.env.COZE_ACCOUNT_ID } : {}),
10487
10520
  ...(process.env.COZE_SPACE_ID ? { spaceId: process.env.COZE_SPACE_ID } : {}),
10488
10521
  ...(process.env.COZE_PROJECT_ID ? { projectId: process.env.COZE_PROJECT_ID } : {}),
10489
10522
  ...(options.orgId ? { organizationId: options.orgId } : {}),
10490
10523
  ...(options.spaceId ? { spaceId: options.spaceId } : {}),
10491
10524
  ...(options.apiBaseUrl ? { apiBaseUrl: options.apiBaseUrl } : {}),
10525
+ // Runtime-only trust decision: a value persisted in config.json must never enable
10526
+ // project-secret injection for an OAuth access token.
10527
+ injectApiToken: Boolean(environmentAccessToken),
10492
10528
  };
10493
10529
  return config;
10494
10530
  };
@@ -10932,8 +10968,20 @@ class DeployApiClient {
10932
10968
  'agw-js-conv': 'str',
10933
10969
  'x-request-from-coze-cli': '1',
10934
10970
  };
10935
- if (this.config.organizationId) {
10936
- headers['x-coze-account'] = this.config.organizationId;
10971
+ // Only an explicit environment credential may become a project runtime secret.
10972
+ // OAuth credentials loaded from config.json remain authentication-only.
10973
+ if (
10974
+ this.config.injectApiToken &&
10975
+ path === '/deploy_history/create' &&
10976
+ useApiPrefix
10977
+ ) {
10978
+ headers['x-coze-deploy-inject-api-token'] = 'true';
10979
+ }
10980
+ // Coze account id: an explicit COZE_ACCOUNT_ID (config.cozeAccountId) always wins;
10981
+ // otherwise fall back to the organization id resolved from login/config.
10982
+ const cozeAccount = this.config.cozeAccountId || this.config.organizationId;
10983
+ if (cozeAccount) {
10984
+ headers['x-coze-account'] = cozeAccount;
10937
10985
  }
10938
10986
  const lane = _optionalChain$9([this, 'access', _4 => _4.globalOptions, 'access', _5 => _5.lane, 'optionalAccess', _6 => _6.trim, 'call', _7 => _7()]) || _optionalChain$9([this, 'access', _8 => _8.config, 'access', _9 => _9.xTTEnv, 'optionalAccess', _10 => _10.trim, 'call', _11 => _11()]);
10939
10987
  if (lane) {
@@ -10999,6 +11047,17 @@ class DeployApiClient {
10999
11047
  );
11000
11048
  }
11001
11049
 
11050
+ // 回读当前登录态对应的 Coze 账号 id。无入参:账号由服务端从登录态解析(X-Coze-Account →
11051
+ // access token → 兜底登录用户),客户端传什么都只有「等于登录态」一种合法取值。
11052
+ // 只在建 Project 前用一次,用来定这个 Project 下应用的账号归属。
11053
+ getCozeAccount() {
11054
+ return this.post(
11055
+ '/account/get',
11056
+ {},
11057
+ 'coze_account_id',
11058
+ );
11059
+ }
11060
+
11002
11061
  listSpaces(body
11003
11062
 
11004
11063
 
@@ -11171,6 +11230,35 @@ class DeployApiClient {
11171
11230
  );
11172
11231
  }
11173
11232
 
11233
+ authorizeMiniProgram(body
11234
+
11235
+
11236
+
11237
+
11238
+
11239
+
11240
+ ) {
11241
+ return this.post
11242
+
11243
+
11244
+
11245
+ ('/mini_program/auth', body);
11246
+ }
11247
+
11248
+ createMiniProgramPreview(body
11249
+
11250
+
11251
+
11252
+
11253
+ ) {
11254
+ return this.post
11255
+
11256
+
11257
+
11258
+
11259
+ ('/mini_program/preview', body);
11260
+ }
11261
+
11174
11262
  listDomains(appId, unitType) {
11175
11263
  return this.post(
11176
11264
  '/domain/list', {
@@ -11442,6 +11530,59 @@ const getDeployAppIdOption = (
11442
11530
  command,
11443
11531
  ) => options.appId || getDeployParentOptions(command).appId;
11444
11532
 
11533
+ function _optionalChain$7(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } async function _asyncOptionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
11534
+
11535
+ const isAccountId = (value) => /^[1-9]\d*$/u.test(value);
11536
+
11537
+ /**
11538
+ * 定出这个 Project 下的应用该归属哪个 Coze 账号,写进 project_settings.extra.coze_account_id。
11539
+ *
11540
+ * 优先级(与 api-client 里 x-coze-account 的取值顺序一致,不另立一套口径):
11541
+ * 1. COZE_ACCOUNT_ID(config.cozeAccountId)—— 用户显式指定
11542
+ * 2. COZE_ORG_ID / --org-id(config.organizationId)—— 用户显式指定组织
11543
+ * 3. 登录态回读(deploy v2 account/get)
11544
+ *
11545
+ * ⚠️ 1、2 命中时**不打接口**:本地已经知道账号了,再问一次服务端只是多一个 RTT 和一个失败点。
11546
+ *
11547
+ * 拿不到就返回 undefined(不写 extra),部署照常继续:服务端在 deploy_history/create 里仍会
11548
+ * 按同一条阶梯解析账号,结果与不加这段逻辑时完全一致 —— 只是无登录态的预览初始化那条链路
11549
+ * 少了 Project 上这份归属记录。这是一个辅助接口,不该成为首次部署的单点。
11550
+ */
11551
+ const resolveCozeAccountId = async (
11552
+ runtime,
11553
+ ) => {
11554
+ const configured =
11555
+ _optionalChain$7([runtime, 'access', _ => _.config, 'access', _2 => _2.cozeAccountId, 'optionalAccess', _3 => _3.trim, 'call', _4 => _4()]) || _optionalChain$7([runtime, 'access', _5 => _5.config, 'access', _6 => _6.organizationId, 'optionalAccess', _7 => _7.trim, 'call', _8 => _8()]);
11556
+ if (configured) {
11557
+ if (!isAccountId(configured)) {
11558
+ // 不把非法值写进 Project —— 它会被服务端当成「明确但损坏的归属」直接报错。
11559
+ // 该值仍会作为 x-coze-account 发出去,由服务端给出明确的参数错误。
11560
+ runtime.output.debug(
11561
+ `[deploy] Ignoring malformed Coze account id for project settings: ${configured}`,
11562
+ );
11563
+ return undefined;
11564
+ }
11565
+ runtime.output.debug(`[deploy] Using configured Coze account ${configured}`);
11566
+ return configured;
11567
+ }
11568
+ try {
11569
+ const accountId = await _asyncOptionalChain$1([(await runtime.client.getCozeAccount()), 'access', async _9 => _9.coze_account_id, 'optionalAccess', async _10 => _10.trim, 'call', async _11 => _11()]);
11570
+ if (!accountId || !isAccountId(accountId)) {
11571
+ runtime.output.debug(
11572
+ `[deploy] Deployment API returned no usable Coze account id: ${String(accountId)}`,
11573
+ );
11574
+ return undefined;
11575
+ }
11576
+ runtime.output.debug(`[deploy] Resolved Coze account ${accountId} from the current login`);
11577
+ return accountId;
11578
+ } catch (error) {
11579
+ runtime.output.warn(
11580
+ `Unable to resolve the Coze account from the current login; the project will be created without an explicit account: ${String(error)}`,
11581
+ );
11582
+ return undefined;
11583
+ }
11584
+ };
11585
+
11445
11586
  const getCreateDeployConfig = (config) => ({
11446
11587
  deploy_config: {
11447
11588
  cpu: config.deploy_config.cpu,
@@ -11485,10 +11626,10 @@ const TERMINAL_STATUSES = new Set([
11485
11626
  const getDeployStatusText = (status) =>
11486
11627
  status ? STATUS_NAMES[status] || 'Unknown' : 'Unknown';
11487
11628
 
11488
- function _optionalChain$7(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
11629
+ function _optionalChain$6(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
11489
11630
 
11490
11631
  const formatDeployDetails = (history) =>
11491
- (_optionalChain$7([history, 'optionalAccess', _ => _.deploy_detail]) || []).map(detail => ({
11632
+ (_optionalChain$6([history, 'optionalAccess', _ => _.deploy_detail]) || []).map(detail => ({
11492
11633
  target: detail.target,
11493
11634
  status: getDeployStatusText(detail.status),
11494
11635
  deploy_log_key: detail.deploy_log_key,
@@ -11498,7 +11639,7 @@ const formatDeployDetails = (history) =>
11498
11639
  const getDeployLogKeys = (history) =>
11499
11640
  [...new Set(
11500
11641
  (history.deploy_detail || [])
11501
- .map(detail => _optionalChain$7([detail, 'access', _2 => _2.deploy_log_key, 'optionalAccess', _3 => _3.trim, 'call', _4 => _4()]))
11642
+ .map(detail => _optionalChain$6([detail, 'access', _2 => _2.deploy_log_key, 'optionalAccess', _3 => _3.trim, 'call', _4 => _4()]))
11502
11643
  .filter((key) => Boolean(key)),
11503
11644
  )];
11504
11645
 
@@ -11513,7 +11654,7 @@ const resolveDeployHistoryId = (
11513
11654
  ) =>
11514
11655
  normalizePositiveId(deployHistoryId) || normalizePositiveId(previousDeployHistoryId);
11515
11656
 
11516
- function _optionalChain$6(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
11657
+ function _optionalChain$5(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
11517
11658
 
11518
11659
  const SOURCE_SNAPSHOT_BYTES = 20;
11519
11660
  const PROJECT_METADATA_FILE_MODE = 0o644;
@@ -11523,7 +11664,7 @@ const isId = (value) =>
11523
11664
 
11524
11665
 
11525
11666
  const resolveAppId = async (cwd, appId) => {
11526
- const explicit = _optionalChain$6([appId, 'optionalAccess', _ => _.trim, 'call', _2 => _2()]);
11667
+ const explicit = _optionalChain$5([appId, 'optionalAccess', _ => _.trim, 'call', _2 => _2()]);
11527
11668
  if (explicit) {
11528
11669
  return explicit;
11529
11670
  }
@@ -11569,11 +11710,11 @@ const readProjectMetadata = async (
11569
11710
  }
11570
11711
  throw error;
11571
11712
  }
11572
- const projectSection = _optionalChain$6([cozeFileContent, 'access', _3 => _3.match, 'call', _4 => _4(
11713
+ const projectSection = _optionalChain$5([cozeFileContent, 'access', _3 => _3.match, 'call', _4 => _4(
11573
11714
  /^\s*\[project\]\s*(?:#.*)?$([\s\S]*?)(?=^\s*\[[^\]]+\]\s*(?:#.*)?$|(?![\s\S]))/mu,
11574
11715
  ), 'optionalAccess', _5 => _5[1]]);
11575
11716
  const readProjectString = (key) =>
11576
- _optionalChain$6([projectSection
11717
+ _optionalChain$5([projectSection
11577
11718
  , 'optionalAccess', _6 => _6.match, 'call', _7 => _7(new RegExp(`^\\s*${key}\\s*=\\s*["']([^"']+)["']`, 'mu')), 'optionalAccess', _8 => _8[1]
11578
11719
  , 'optionalAccess', _9 => _9.trim, 'call', _10 => _10()]);
11579
11720
  const name = readProjectString('name');
@@ -11581,7 +11722,7 @@ const readProjectMetadata = async (
11581
11722
  const projectId = readProjectString('project_id');
11582
11723
  const appId = readProjectString('app_id');
11583
11724
  const hasUnquotedId = (key) =>
11584
- Boolean(_optionalChain$6([projectSection, 'optionalAccess', _11 => _11.match, 'call', _12 => _12(new RegExp(`^\\s*${key}\\s*=\\s*(?!["'])\\S+`, 'mu'))]));
11725
+ Boolean(_optionalChain$5([projectSection, 'optionalAccess', _11 => _11.match, 'call', _12 => _12(new RegExp(`^\\s*${key}\\s*=\\s*(?!["'])\\S+`, 'mu'))]));
11585
11726
  if (hasUnquotedId('project_id') || hasUnquotedId('app_id')) {
11586
11727
  throw new CliError(
11587
11728
  '.coze [project].project_id and app_id must be quoted decimal strings.',
@@ -11606,7 +11747,7 @@ const updateProjectValue = (content, key, value) => {
11606
11747
  const sectionStart = sectionMatch.index + sectionMatch[0].length;
11607
11748
  const following = content.slice(sectionStart);
11608
11749
  const nextSection = /^\s*\[[^\]]+\]\s*(?:#.*)?$/mu.exec(following);
11609
- const sectionEnd = _optionalChain$6([nextSection, 'optionalAccess', _13 => _13.index]) === undefined
11750
+ const sectionEnd = _optionalChain$5([nextSection, 'optionalAccess', _13 => _13.index]) === undefined
11610
11751
  ? content.length
11611
11752
  : sectionStart + nextSection.index;
11612
11753
  const before = content.slice(0, sectionStart);
@@ -11660,8 +11801,8 @@ const ensureProjectMetadata = async (
11660
11801
  throw error;
11661
11802
  }
11662
11803
  }
11663
- const name = _optionalChain$6([options, 'access', _14 => _14.name, 'optionalAccess', _15 => _15.trim, 'call', _16 => _16()]) || 'Pages application';
11664
- const projectType = _optionalChain$6([options, 'access', _17 => _17.projectType, 'optionalAccess', _18 => _18.trim, 'call', _19 => _19()]) || 'web';
11804
+ const name = _optionalChain$5([options, 'access', _14 => _14.name, 'optionalAccess', _15 => _15.trim, 'call', _16 => _16()]) || 'Pages application';
11805
+ const projectType = _optionalChain$5([options, 'access', _17 => _17.projectType, 'optionalAccess', _18 => _18.trim, 'call', _19 => _19()]) || 'web';
11665
11806
  await promises.writeFile(
11666
11807
  node_path.join(sourceRoot, '.coze'),
11667
11808
  `[project]\nname = ${JSON.stringify(name)}\nproject_type = ${JSON.stringify(projectType)}\n`,
@@ -11671,7 +11812,7 @@ const ensureProjectMetadata = async (
11671
11812
  return readProjectMetadata(sourceRoot);
11672
11813
  };
11673
11814
 
11674
- function _optionalChain$5(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
11815
+ function _optionalChain$4(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
11675
11816
  const isFile = async (path) => {
11676
11817
  try {
11677
11818
  return (await promises.stat(path)).isFile();
@@ -11701,14 +11842,14 @@ const validatePagesSource = async (
11701
11842
  );
11702
11843
  }
11703
11844
  const project = config.project ;
11704
- if (typeof _optionalChain$5([project, 'optionalAccess', _ => _.template]) !== 'string' || project.template.trim().toLowerCase() !== 'nextjs') {
11845
+ if (typeof _optionalChain$4([project, 'optionalAccess', _ => _.template]) !== 'string' || project.template.trim().toLowerCase() !== 'nextjs') {
11705
11846
  throw new CliError(
11706
11847
  'Pages source contains no index.html; .coze project.template must be "nextjs".',
11707
11848
  'PAGES_BUILD_CONFIG_REQUIRED',
11708
11849
  );
11709
11850
  }
11710
11851
  const deploy = config.deploy ;
11711
- const build = _optionalChain$5([deploy, 'optionalAccess', _2 => _2.build]);
11852
+ const build = _optionalChain$4([deploy, 'optionalAccess', _2 => _2.build]);
11712
11853
  if (!Array.isArray(build) || build.length === 0 || !build.every(part => typeof part === 'string' && part.length > 0)) {
11713
11854
  throw new CliError(
11714
11855
  'Pages source contains no index.html; .coze deploy.build must be a non-empty string array.',
@@ -11860,6 +12001,7 @@ const registerDeployReadCommands = (deploy) => {
11860
12001
  deploy_history_id: deployHistoryId,
11861
12002
  status: getDeployStatusText(history.status),
11862
12003
  commit_hash: history.commit_hash,
12004
+ commit_message: history.commit_message,
11863
12005
  domains: history.domain_list || [],
11864
12006
  error_analysis: history.error_analysis,
11865
12007
  deploy_detail: formatDeployDetails(history),
@@ -11889,6 +12031,7 @@ const registerDeployReadCommands = (deploy) => {
11889
12031
  deploy_history_id: item.deploy_history_id,
11890
12032
  status: getDeployStatusText(item.status),
11891
12033
  commit_hash: item.commit_hash_short || item.commit_hash,
12034
+ commit_message: item.commit_message,
11892
12035
  created_at: item.created_at,
11893
12036
  can_rollback: item.can_rollback,
11894
12037
  deploy_detail: formatDeployDetails(item),
@@ -11914,6 +12057,7 @@ const registerDeployReadCommands = (deploy) => {
11914
12057
  deploy_history_id: item.deploy_history_id,
11915
12058
  status: getDeployStatusText(item.status),
11916
12059
  commit_hash: item.commit_hash_short || item.commit_hash,
12060
+ commit_message: item.commit_message,
11917
12061
  created_at: item.created_at,
11918
12062
  deploy_detail: formatDeployDetails(item),
11919
12063
  domains: item.domain_list || [],
@@ -11979,12 +12123,107 @@ const registerEnv = (code) => {
11979
12123
  });
11980
12124
  };
11981
12125
 
11982
- function _nullishCoalesce$1(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$4(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
12126
+ /* eslint-disable security/detect-non-literal-fs-filename -- validated project-local build output paths */
12127
+
12128
+ const BUILD_OUTPUT_DIRS = new Set(['dist', 'dist-tt']);
12129
+ const EXCLUDED_PARTS = new Set([
12130
+ '.git',
12131
+ '.env',
12132
+ 'node_modules',
12133
+ ]);
12134
+ const REPRODUCIBLE_ARCHIVE_MTIME = new Date(0);
12135
+
12136
+ const validateBuildOutput = async (
12137
+ sourceRoot,
12138
+ buildOutputDir,
12139
+ ) => {
12140
+ if (!BUILD_OUTPUT_DIRS.has(buildOutputDir)) {
12141
+ throw new CliError(
12142
+ `Unsupported Mini-program build output directory: ${buildOutputDir}.`,
12143
+ 'SOURCE_PACKAGE_FAILED',
12144
+ );
12145
+ }
12146
+ const buildOutputRoot = node_path.resolve(sourceRoot, buildOutputDir);
12147
+ try {
12148
+ const info = await promises.lstat(buildOutputRoot);
12149
+ if (info.isSymbolicLink() || !info.isDirectory()) {
12150
+ throw new Error('build output must be a regular directory');
12151
+ }
12152
+ const realSourceRoot = await promises.realpath(sourceRoot);
12153
+ const realBuildOutputRoot = await promises.realpath(buildOutputRoot);
12154
+ const relativeOutput = node_path.relative(realSourceRoot, realBuildOutputRoot);
12155
+ if (!relativeOutput || relativeOutput.startsWith('..')) {
12156
+ throw new Error('build output must be inside the source root');
12157
+ }
12158
+ } catch (error) {
12159
+ throw new CliError(
12160
+ `Invalid Mini-program build output ${buildOutputRoot}: ${error instanceof Error ? error.message : String(error)}`,
12161
+ 'SOURCE_PACKAGE_FAILED',
12162
+ );
12163
+ }
12164
+ };
12165
+
12166
+ const shouldInclude = (
12167
+ archivePath,
12168
+ entry,
12169
+ ) => {
12170
+ if ('isSymbolicLink' in entry && entry.isSymbolicLink()) {
12171
+ return false;
12172
+ }
12173
+ return !archivePath.split(/[\\/]/u).some(part =>
12174
+ EXCLUDED_PARTS.has(part) || part.startsWith('.git'),
12175
+ );
12176
+ };
12177
+
12178
+ const createMiniProgramPackage = async (
12179
+ sourceRoot,
12180
+ buildOutputDir,
12181
+ ) => {
12182
+ const resolvedSourceRoot = node_path.resolve(sourceRoot);
12183
+ await validateBuildOutput(resolvedSourceRoot, buildOutputDir);
12184
+ const tempDirectory = await promises.mkdtemp(node_path.join(node_os.tmpdir(), 'coze-mini-program-source-'));
12185
+ const outputPath = node_path.join(tempDirectory, 'source.tar.gz');
12186
+ try {
12187
+ await tar.create(
12188
+ {
12189
+ cwd: resolvedSourceRoot,
12190
+ file: outputPath,
12191
+ filter: shouldInclude,
12192
+ gzip: true,
12193
+ mtime: REPRODUCIBLE_ARCHIVE_MTIME,
12194
+ portable: true,
12195
+ },
12196
+ [buildOutputDir],
12197
+ );
12198
+ const info = await promises.stat(outputPath);
12199
+ if (info.size === 0) {
12200
+ throw new Error('source archive is empty');
12201
+ }
12202
+ return {
12203
+ path: outputPath,
12204
+ sizeBytes: info.size,
12205
+ cleanup: () => promises.rm(tempDirectory, { recursive: true, force: true }),
12206
+ };
12207
+ } catch (error) {
12208
+ await promises.rm(tempDirectory, { recursive: true, force: true });
12209
+ throw new CliError(
12210
+ `Unable to package Mini-program build output: ${error instanceof Error ? error.message : String(error)}`,
12211
+ 'SOURCE_PACKAGE_FAILED',
12212
+ );
12213
+ }
12214
+ };
12215
+
12216
+ function _nullishCoalesce$1(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$3(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
11983
12217
  const CONNECTOR_IDS = {
11984
12218
  wechat: '10000127',
11985
12219
  douyin: '10000126',
11986
12220
  } ;
11987
12221
 
12222
+ const MINI_PROGRAM_BUILD_OUTPUT_DIRS = {
12223
+ wechat: 'dist',
12224
+ douyin: 'dist-tt',
12225
+ } ;
12226
+
11988
12227
 
11989
12228
 
11990
12229
 
@@ -12009,11 +12248,23 @@ const resolveConnectorId = (platform) => {
12009
12248
  return connectorId;
12010
12249
  };
12011
12250
 
12251
+ const resolveBuildOutputDir = (platform) => {
12252
+ const outputDir =
12253
+ MINI_PROGRAM_BUILD_OUTPUT_DIRS[platform ];
12254
+ if (!outputDir) {
12255
+ throw new CliError(
12256
+ `Unsupported Mini-program platform ${String(platform)}; expected wechat or douyin.`,
12257
+ 'INVALID_MINIPROGRAM_PLATFORM',
12258
+ );
12259
+ }
12260
+ return outputDir;
12261
+ };
12262
+
12012
12263
  const resolveProjectId = async (
12013
12264
  command,
12014
12265
  options,
12015
12266
  ) => {
12016
- if (_optionalChain$4([options, 'access', _ => _.projectId, 'optionalAccess', _2 => _2.trim, 'call', _3 => _3()])) {
12267
+ if (_optionalChain$3([options, 'access', _ => _.projectId, 'optionalAccess', _2 => _2.trim, 'call', _3 => _3()])) {
12017
12268
  return options.projectId.trim();
12018
12269
  }
12019
12270
  const runtime = await getRuntime(command);
@@ -12028,6 +12279,137 @@ const resolveProjectId = async (
12028
12279
  return metadata.projectId;
12029
12280
  };
12030
12281
 
12282
+ const MINI_PROGRAM_AUTH_STATUS = {
12283
+ authorized: 1,
12284
+ needAuthorize: 2,
12285
+ boundToOtherUser: 3,
12286
+ } ;
12287
+
12288
+ const getBoundToOtherUserMessage = (platform) => {
12289
+ const platformName = platform === 'wechat' ? 'WeChat' : 'Douyin';
12290
+ const platformConsole =
12291
+ platform === 'wechat' ? 'WeChat Public Platform' : 'Douyin Open Platform';
12292
+ return [
12293
+ `This ${platformName} Mini-program AppID is authorized by another Coze user.`,
12294
+ `If this is an AppID you manage, revoke Coze's previous third-party platform authorization in the ${platformConsole}, then rerun this auth command. The CLI will recheck the AppID and authorize it for your current Coze account.`,
12295
+ 'If this is not your AppID, change --mini-app-id to an AppID for which you have administrator permission, then rerun this auth command.',
12296
+ ].join(' ');
12297
+ };
12298
+
12299
+ const getAuthRequiredMessage = () =>
12300
+ 'This Mini-program AppID is not authorized for the current Coze user. Run `coze-dev deploy code mini-program auth` first.';
12301
+
12302
+ const getPreviewFailureMessage = (data
12303
+
12304
+
12305
+ ) =>
12306
+ _optionalChain$3([data, 'access', _4 => _4.stderr, 'optionalAccess', _5 => _5.trim, 'call', _6 => _6()]) || _optionalChain$3([data, 'access', _7 => _7.stdout, 'optionalAccess', _8 => _8.trim, 'call', _9 => _9()]) || 'Mini-program preview failed.';
12307
+
12308
+ const registerAuthorizationCommand = (miniProgram) => {
12309
+ miniProgram
12310
+ .command('auth')
12311
+ .description('Authorize a Mini-program AppID for the current Coze user')
12312
+ .requiredOption('--platform <platform>', 'wechat or douyin')
12313
+ .requiredOption('--mini-app-id <miniAppId>', 'Mini-program AppID')
12314
+ .option('--project-id <projectId>', 'Deployment Project ID')
12315
+ .option('--source-root <sourceRoot>', 'Directory containing .coze', '.')
12316
+ .action(async (options, command) => {
12317
+ const runtime = await getRuntime(command);
12318
+ const projectId = await resolveProjectId(command, options);
12319
+ const authorization = await runtime.client.authorizeMiniProgram({
12320
+ project_id: projectId,
12321
+ app_id: options.miniAppId || '',
12322
+ connector_id: resolveConnectorId(options.platform),
12323
+ redirect_url: 'https://code.coze.cn/coding/auth/callback/miniprogram',
12324
+ });
12325
+ if (authorization.status === MINI_PROGRAM_AUTH_STATUS.needAuthorize) {
12326
+ runtime.output.print({
12327
+ project_id: projectId,
12328
+ mini_app_id: options.miniAppId,
12329
+ platform: options.platform,
12330
+ authorization_required: true,
12331
+ auth_url: authorization.auth_url,
12332
+ });
12333
+ return;
12334
+ }
12335
+ if (authorization.status === MINI_PROGRAM_AUTH_STATUS.boundToOtherUser) {
12336
+ throw new CliError(
12337
+ getBoundToOtherUserMessage(options.platform),
12338
+ 'MINIPROGRAM_AUTHORIZED_BY_OTHER_USER',
12339
+ );
12340
+ }
12341
+ if (authorization.status !== MINI_PROGRAM_AUTH_STATUS.authorized) {
12342
+ throw new CliError(
12343
+ `Unexpected Mini-program authorization status: ${String(authorization.status)}.`,
12344
+ 'INVALID_RESPONSE',
12345
+ );
12346
+ }
12347
+ runtime.output.print({
12348
+ project_id: projectId,
12349
+ mini_app_id: options.miniAppId,
12350
+ platform: options.platform,
12351
+ authorized: true,
12352
+ });
12353
+ });
12354
+ };
12355
+
12356
+ const registerPreviewCommand = (miniProgram) => {
12357
+ miniProgram
12358
+ .command('preview')
12359
+ .description('Create a Mini-program preview QR code from the local build artifact')
12360
+ .requiredOption('--platform <platform>', 'wechat or douyin')
12361
+ .requiredOption('--mini-app-id <miniAppId>', 'Mini-program AppID')
12362
+ .option('--project-id <projectId>', 'Deployment Project ID')
12363
+ .option('--source-root <sourceRoot>', 'Directory containing dist or dist-tt', '.')
12364
+ .action(async (options, command) => {
12365
+ const runtime = await getRuntime(command);
12366
+ const projectId = await resolveProjectId(command, options);
12367
+ const authorization = await runtime.client.getMiniProgramAuthStatus({
12368
+ project_id: projectId,
12369
+ connector_id: resolveConnectorId(options.platform),
12370
+ });
12371
+ if (
12372
+ !authorization.is_authorized ||
12373
+ authorization.bound_related_id !== options.miniAppId
12374
+ ) {
12375
+ throw new CliError(
12376
+ getAuthRequiredMessage(),
12377
+ 'MINIPROGRAM_AUTH_REQUIRED',
12378
+ );
12379
+ }
12380
+ const sourceRoot = node_path.resolve(runtime.cwd, options.sourceRoot || '.');
12381
+ const buildOutputDir = resolveBuildOutputDir(options.platform);
12382
+ const sourcePackage = await createMiniProgramPackage(
12383
+ sourceRoot,
12384
+ buildOutputDir,
12385
+ );
12386
+ try {
12387
+ const content = await promises.readFile(sourcePackage.path);
12388
+ const data = await runtime.client.createMiniProgramPreview({
12389
+ project_id: projectId,
12390
+ app_id: options.miniAppId || '',
12391
+ connector_id: resolveConnectorId(options.platform),
12392
+ source_package_base64: content.toString('base64'),
12393
+ });
12394
+ if (data.failed) {
12395
+ throw new CliError(
12396
+ getPreviewFailureMessage(data),
12397
+ 'MINIPROGRAM_PREVIEW_FAILED',
12398
+ );
12399
+ }
12400
+ runtime.output.print({
12401
+ project_id: projectId,
12402
+ mini_app_id: options.miniAppId,
12403
+ platform: options.platform,
12404
+ source_package_size_bytes: sourcePackage.sizeBytes,
12405
+ ...data,
12406
+ });
12407
+ } finally {
12408
+ await sourcePackage.cleanup();
12409
+ }
12410
+ });
12411
+ };
12412
+
12031
12413
  const registerMiniProgram = (code) => {
12032
12414
  const miniProgram = code
12033
12415
  .command('mini-program')
@@ -12112,9 +12494,12 @@ const registerMiniProgram = (code) => {
12112
12494
  });
12113
12495
  runtime.output.print({ project_id: projectId, platform: options.platform, unbound: true });
12114
12496
  });
12497
+
12498
+ registerAuthorizationCommand(miniProgram);
12499
+ registerPreviewCommand(miniProgram);
12115
12500
  };
12116
12501
 
12117
- function _optionalChain$3(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
12502
+ function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
12118
12503
 
12119
12504
  const POLL_INTERVAL_MS = 3000;
12120
12505
  const MAX_CONSECUTIVE_RETRIES = 5;
@@ -12126,7 +12511,7 @@ const wait = async () =>
12126
12511
  const isRetryablePollError = (error) =>
12127
12512
  error instanceof CliError &&
12128
12513
  error.code === 'API_REJECTED' &&
12129
- Number(_optionalChain$3([error, 'access', _ => _.details, 'optionalAccess', _2 => _2.business_code])) === TRANSIENT_RPC_ERROR_CODE;
12514
+ Number(_optionalChain$2([error, 'access', _ => _.details, 'optionalAccess', _2 => _2.business_code])) === TRANSIENT_RPC_ERROR_CODE;
12130
12515
 
12131
12516
  const pollHistory = async (
12132
12517
  command,
@@ -12505,52 +12890,6 @@ const registerDomain = (code) => {
12505
12890
  });
12506
12891
  };
12507
12892
 
12508
- function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
12509
-
12510
- const firstPage = { page: 1, size: 1 };
12511
-
12512
- const listSpaceRequest = (runtime) => ({
12513
- ...(runtime.config.organizationId
12514
- ? { organization_id: runtime.config.organizationId }
12515
- : {}),
12516
- ...(runtime.config.enterpriseId
12517
- ? { enterprise_id: runtime.config.enterpriseId }
12518
- : {}),
12519
- });
12520
-
12521
- const resolveDeploymentSpaceId = async (runtime) => {
12522
- const configuredSpaceId = _optionalChain$2([runtime, 'access', _ => _.config, 'access', _2 => _2.spaceId, 'optionalAccess', _3 => _3.trim, 'call', _4 => _4()]);
12523
- const request = listSpaceRequest(runtime);
12524
- if (configuredSpaceId) {
12525
- const data = await runtime.client.listSpaces(request);
12526
- if (!data.bot_space_list.some(space => space.id === configuredSpaceId)) {
12527
- throw new CliError(
12528
- `Space ID ${configuredSpaceId} is invalid or is not available to the current account.`,
12529
- 'INVALID_SPACE_ID',
12530
- );
12531
- }
12532
- return configuredSpaceId;
12533
- }
12534
-
12535
- const data = await runtime.client.listSpaces({ ...request, ...firstPage });
12536
- const space = data.bot_space_list.find(item => item.id);
12537
- if (!space) {
12538
- throw new CliError(
12539
- 'No available Space was found for the current account. Create or join a Space before deploying.',
12540
- 'SPACE_NOT_FOUND',
12541
- );
12542
- }
12543
-
12544
- runtime.config.spaceId = space.id;
12545
- try {
12546
- await saveSharedConfig({ spaceId: space.id }, runtime.globalOptions);
12547
- } catch (error) {
12548
- runtime.output.warn(`Unable to save the auto-selected Space: ${String(error)}`);
12549
- }
12550
- runtime.output.debug(`Auto-selected Space: ${space.name || space.id} (${space.id})`);
12551
- return space.id;
12552
- };
12553
-
12554
12893
  const PACKAGE_SCRIPT_CANDIDATES = [
12555
12894
  node_path.resolve(__dirname, 'deploy/package-project.js'),
12556
12895
  node_path.resolve(__dirname, '../../../scripts/deploy/package-project.js'),
@@ -12922,14 +13261,21 @@ const registerDeploy = (code) => {
12922
13261
  }
12923
13262
  }
12924
13263
  if (!projectId) {
12925
- runtime.output.debug('[deploy] Creating a dedicated deployment project...');
12926
- const spaceId = await resolveDeploymentSpaceId(runtime);
13264
+ runtime.output.debug(
13265
+ '[deploy] Creating a dedicated deployment project in personal space...',
13266
+ );
13267
+ // 账号归属只在建 Project 这一次定死:写进 project_settings.extra 之后,有登录态的首次
13268
+ // 部署和无登录态的预览初始化读到的是同一个账号。本地已经知道账号就不打这次接口。
13269
+ const cozeAccountId = await resolveCozeAccountId(runtime);
12927
13270
  const project = await runtime.client.createDeploymentProject({
12928
- space_id: spaceId,
13271
+ space_id: '0',
12929
13272
  user_query: deploymentName || 'CLI deployment project',
12930
13273
  project_type: resolveCreationProjectType(metadata.projectType),
12931
13274
  create_source: 'cli',
12932
- project_settings: { project_symbol: 'v3.5' },
13275
+ project_settings: {
13276
+ project_symbol: 'v3.5',
13277
+ ...(cozeAccountId ? { extra: { coze_account_id: cozeAccountId } } : {}),
13278
+ },
12933
13279
  });
12934
13280
  projectId = project.project_id;
12935
13281
  projectCreated = true;
@@ -13018,6 +13364,7 @@ const registerDeploy = (code) => {
13018
13364
  ...(appId ? { app_id: appId } : { project_id: projectId }),
13019
13365
  application_type: applicationType,
13020
13366
  commit_hash: commitHash,
13367
+ ...(options.message ? { commit_message: options.message } : {}),
13021
13368
  ...(!appId
13022
13369
  ? { name: deploymentName, source_root: sourceRoot }
13023
13370
  : {}),