@thinkingai/ae-cli 6.1.17 → 6.1.19

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 (126) hide show
  1. package/README.md +2 -0
  2. package/README.zh.md +6 -0
  3. package/dist/{auth-77BUFLGC.js → auth-QPEVVBKT.js} +20 -15
  4. package/dist/auth-UMJAA72O.js +15 -0
  5. package/dist/{capability-72DTW5M2.js → capability-ASI62I4A.js} +53 -15
  6. package/dist/{chunk-UW5UN47B.js → chunk-533JK3YX.js} +2 -0
  7. package/dist/{chunk-UOUS37JQ.js → chunk-6QK7SYYY.js} +5 -4
  8. package/dist/{chunk-TUKQZTMI.js → chunk-7K24F7T2.js} +2 -0
  9. package/dist/{chunk-OO6XR6LK.js → chunk-AMBFK2K3.js} +2 -0
  10. package/dist/{sync-DAVKYVMW.js → chunk-B5HMQAOM.js} +31 -540
  11. package/dist/{chunk-VR3LCBHW.js → chunk-DKEXH6Q5.js} +6 -5
  12. package/dist/{chunk-VTWMIC5L.js → chunk-E2JKXMVO.js} +2 -0
  13. package/dist/{chunk-LYVNONC4.js → chunk-FR2EDAQM.js} +36 -0
  14. package/dist/{chunk-ILIU36SU.js → chunk-GJXRF7Y6.js} +6 -5
  15. package/dist/{chunk-DWO43OIB.js → chunk-JQ3ENZZH.js} +2 -0
  16. package/dist/chunk-JYMGHGCE.js +191 -0
  17. package/dist/{chunk-GT46FPXN.js → chunk-KEWVSO64.js} +18 -8
  18. package/dist/chunk-KZ6ZHF5J.js +294 -0
  19. package/dist/chunk-O6K2ODUE.js +318 -0
  20. package/dist/chunk-QL6R6TSK.js +25215 -0
  21. package/dist/{chunk-4SGZG4XY.js → chunk-RWXIXOZG.js} +28 -13
  22. package/dist/{chunk-YA6SMTXG.js → chunk-S5PONFBM.js} +5 -4
  23. package/dist/{chunk-4NN5IWVN.js → chunk-T6OSFQZD.js} +2 -0
  24. package/dist/{chunk-PTE56QPL.js → chunk-TKHSULJT.js} +6 -0
  25. package/dist/{chunk-6EIJSNBD.js → chunk-Y74WTIKJ.js} +2 -0
  26. package/dist/{client-TKG4WBHN.js → client-N7NGZUNI.js} +6 -4
  27. package/dist/{community-report-client-FI4LNVYS.js → community-report-client-6OL6GBQW.js} +3 -3
  28. package/dist/{config-RE6CMGPK.js → config-XNMACCKX.js} +10 -8
  29. package/dist/{data-integration-XQYB4X4F.js → data-integration-4NZGZ45E.js} +2502 -272
  30. package/dist/index.js +137 -1245
  31. package/dist/{local-data-upload-client-BWHSUQQK.js → local-data-upload-client-EFHDLXFG.js} +3 -3
  32. package/dist/{memory-YK33G4T7.js → memory-HBJQ2GC5.js} +8 -7
  33. package/dist/{metadata-UILXHBWF.js → metadata-62EWBEIG.js} +12 -11
  34. package/dist/{model-NR3JHFSJ.js → model-BHLJ2QMT.js} +10 -9
  35. package/dist/personal-semantic-preference-JBVMAI7L.js +240 -0
  36. package/dist/project-semantic-BQ4MPUS5.js +1115 -0
  37. package/dist/sync-MUWPRM5I.js +522 -0
  38. package/dist/{te-agent-4BKBODMF.js → te-agent-WQZTMEK4.js} +12 -10
  39. package/dist/{te-analysis-O6DCO6BS.js → te-analysis-MNCG65LU.js} +534 -48
  40. package/dist/{te-community-HLC43QKH.js → te-community-BNE6KREL.js} +8 -7
  41. package/dist/{te-dataops-EJP56W3K.js → te-dataops-TXLKM2W6.js} +469 -68
  42. package/dist/{te-engage-FGBGQ4IY.js → te-engage-TPKLRVTL.js} +84 -10
  43. package/dist/{te-experiment-SO5MPDMJ.js → te-experiment-6BYKTCY7.js} +303 -12
  44. package/dist/{te-kb-SQCLHG6X.js → te-kb-BUD6N3NI.js} +312 -25
  45. package/dist/{te-system-YARIK4S5.js → te-system-44LZJDTQ.js} +573 -37
  46. package/dist/{te-team-EFKWYKMK.js → te-team-XMP47YXE.js} +10 -7
  47. package/dist/{update-OGPSZM5A.js → update-UODFOZ4P.js} +9 -7
  48. package/package.json +18 -9
  49. package/skills/ae-agent/SKILL.md +3 -4
  50. package/skills/ae-agent/references/edit-skill.md +3 -0
  51. package/skills/ae-agent/references/get-skill-content.md +1 -1
  52. package/skills/ae-agent/references/rescan-skills.md +15 -13
  53. package/skills/ae-agent/references/upload-skill.md +7 -4
  54. package/skills/ae-analysis/SKILL.md +45 -4
  55. package/skills/ae-analysis/metadata_resolution.md +38 -4
  56. package/skills/ae-analysis/references/analysis_data_retrieval.md +29 -0
  57. package/skills/ae-analysis/references/analysis_gateway_assets.md +1 -1
  58. package/skills/ae-analysis/references/asset_authentication_export.md +22 -0
  59. package/skills/ae-analysis/references/asset_authentication_list.md +18 -14
  60. package/skills/ae-analysis/references/asset_authentication_update.md +29 -14
  61. package/skills/ae-analysis/references/audience_models.md +18 -0
  62. package/skills/ae-analysis/references/command_index.md +19 -11
  63. package/skills/ae-analysis/references/dashboard_get.md +18 -1
  64. package/skills/ae-analysis/references/dashboard_update.md +3 -0
  65. package/skills/ae-analysis/references/personal_semantic_preference_add.md +23 -0
  66. package/skills/ae-analysis/references/personal_semantic_preference_delete.md +17 -0
  67. package/skills/ae-analysis/references/personal_semantic_preference_get.md +19 -0
  68. package/skills/ae-analysis/references/personal_semantic_preference_list.md +21 -0
  69. package/skills/ae-analysis/references/personal_semantic_preference_update.md +19 -0
  70. package/skills/ae-analysis/references/project_timezone_update.md +13 -4
  71. package/skills/ae-analysis/references/property_create.md +2 -0
  72. package/skills/ae-analysis/references/super_metadata_batch_create.md +2 -0
  73. package/skills/ae-analysis/references/user_cluster_models.md +2 -0
  74. package/skills/ae-analysis/references/user_cluster_update.md +8 -4
  75. package/skills/ae-analysis/references/user_tag_create.md +7 -1
  76. package/skills/ae-analysis/references/user_tag_models.md +8 -2
  77. package/skills/ae-data-integration/SKILL.md +24 -4
  78. package/skills/ae-data-integration/references/custom-layer.md +93 -0
  79. package/skills/ae-data-integration/references/error-handling.md +145 -0
  80. package/skills/ae-data-integration/references/handoff.md +77 -18
  81. package/skills/ae-data-integration/references/local-analysis.md +1 -1
  82. package/skills/ae-data-integration/references/reuse.md +9 -5
  83. package/skills/ae-data-integration/references/sink-upload.md +1 -1
  84. package/skills/ae-data-integration/references/source-inspect.md +35 -13
  85. package/skills/ae-data-integration/references/tracking-plan.md +7 -5
  86. package/skills/ae-data-integration/references/transform.md +12 -10
  87. package/skills/ae-data-integration/references/ue-mapping.md +33 -11
  88. package/skills/ae-data-integration/references/ue-routing.md +23 -0
  89. package/skills/ae-dataops/SKILL.md +11 -1
  90. package/skills/ae-dataops/references/dataops-backfill.md +135 -0
  91. package/skills/ae-engage/SKILL.md +5 -0
  92. package/skills/ae-engage/references/build-task-save-guide.md +14 -1
  93. package/skills/ae-engage/references/save-flow.md +37 -1
  94. package/skills/ae-engage/references/save-task.md +88 -0
  95. package/skills/ae-experiment/SKILL.md +14 -4
  96. package/skills/ae-experiment/references/manage_feature_whitelist.md +66 -0
  97. package/skills/ae-experiment/references/manage_guardrail_metrics.md +26 -0
  98. package/skills/ae-experiment/references/save_experiment.md +1 -1
  99. package/skills/ae-experiment/references/save_metric.md +20 -8
  100. package/skills/ae-kb/SKILL.md +121 -10
  101. package/skills/ae-project-semantic/SKILL.md +193 -0
  102. package/skills/ae-project-semantic/references/query-routing-v5.md +165 -0
  103. package/skills/ae-project-semantic/references/recommendation-quality.md +68 -0
  104. package/skills/ae-system/SKILL.md +28 -30
  105. package/skills/ae-system/references/channel-management.md +303 -0
  106. package/dist/auth-2WTQOP77.js +0 -14
  107. package/dist/capability-PJHNI4GJ.js +0 -315
  108. package/dist/chunk-4KVPKXFX.js +0 -98
  109. package/dist/chunk-C4MGVGJW.js +0 -13
  110. package/dist/chunk-P3FGXJTU.js +0 -349
  111. package/dist/chunk-QGM4M3NI.js +0 -37
  112. package/dist/chunk-RGKJGKT7.js +0 -71
  113. package/dist/chunk-SAU3QFIQ.js +0 -556
  114. package/dist/chunk-VPKZ7I72.js +0 -509
  115. package/dist/chunk-ZZUOD757.js +0 -598
  116. package/dist/memory-CHRU2F7W.js +0 -893
  117. package/dist/metadata-XXR34N5P.js +0 -339
  118. package/dist/model-K3KLWIW6.js +0 -139
  119. package/dist/sync-FCKOVWWS.js +0 -10261
  120. package/dist/te-agent-HLW4VTQK.js +0 -3893
  121. package/dist/te-analysis-ZMNGOVNW.js +0 -8958
  122. package/dist/te-community-6HPBWJUZ.js +0 -1859
  123. package/dist/te-dataops-HDRUXY4K.js +0 -2208
  124. package/dist/te-engage-RAK5PESW.js +0 -4898
  125. package/dist/te-experiment-VZF7BT6G.js +0 -770
  126. package/dist/te-system-Z77IKZFN.js +0 -2213
@@ -1,4 +1,6 @@
1
+ import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
1
2
  import {
3
+ TeAgentApiError,
2
4
  deleteFromMainApp,
3
5
  downloadFromMainApp,
4
6
  getFromMainApp,
@@ -7,25 +9,30 @@ import {
7
9
  putToMainApp,
8
10
  tryLoadTeAgentSandboxCredentials,
9
11
  uploadToMainApp
10
- } from "./chunk-UOUS37JQ.js";
11
- import "./chunk-C4MGVGJW.js";
12
- import "./chunk-4SGZG4XY.js";
12
+ } from "./chunk-6QK7SYYY.js";
13
+ import "./chunk-Y74WTIKJ.js";
14
+ import "./chunk-RWXIXOZG.js";
15
+ import "./chunk-O6K2ODUE.js";
13
16
  import {
14
17
  safeJsonParse
15
- } from "./chunk-ZZUOD757.js";
18
+ } from "./chunk-KZ6ZHF5J.js";
16
19
  import {
17
- CliValidationError
18
- } from "./chunk-UW5UN47B.js";
19
- import "./chunk-LYVNONC4.js";
20
- import "./chunk-QGM4M3NI.js";
20
+ CliValidationError,
21
+ PermissionError
22
+ } from "./chunk-533JK3YX.js";
23
+ import "./chunk-FR2EDAQM.js";
21
24
 
22
25
  // src/commands/te-system/shared.ts
23
26
  import { readFileSync } from "fs";
24
27
  var SECRET_KEYS = /* @__PURE__ */ new Set([
25
28
  "appsecret",
26
29
  "bottoken",
30
+ "botsecret",
27
31
  "apptoken",
28
32
  "clientsecret",
33
+ "corpsecret",
34
+ "serviceaccountjson",
35
+ "privatekey",
29
36
  "apikey",
30
37
  "secret",
31
38
  "token"
@@ -34,6 +41,12 @@ function assertAdminPath(path3) {
34
41
  if (path3 === "/api/admin" || path3.startsWith("/api/admin/")) return;
35
42
  throw new CliValidationError("System commands may only call /api/admin endpoints");
36
43
  }
44
+ function assertCliChannelPath(path3) {
45
+ if (path3 === "/api/cli/channel/v1" || path3.startsWith("/api/cli/channel/v1/")) return;
46
+ throw new CliValidationError(
47
+ "Channel commands may only call /api/cli/channel/v1 endpoints"
48
+ );
49
+ }
37
50
  async function getAdmin(path3, host) {
38
51
  assertAdminPath(path3);
39
52
  return getFromMainApp(path3, host);
@@ -46,8 +59,8 @@ async function downloadAdmin(path3, outputPath, host) {
46
59
  assertAdminPath(path3);
47
60
  return downloadFromMainApp(path3, outputPath, host);
48
61
  }
49
- async function executeAdminRequest(ctx, request) {
50
- assertAdminPath(request.path);
62
+ async function executeSignedRequest(ctx, request, assertPath) {
63
+ assertPath(request.path);
51
64
  const host = ctx.host();
52
65
  switch (request.method) {
53
66
  case "GET":
@@ -62,9 +75,10 @@ async function executeAdminRequest(ctx, request) {
62
75
  return deleteFromMainApp(request.path, host);
63
76
  }
64
77
  }
65
- function createAdminCommand(config) {
78
+ function createSignedCommand(config, assertPath) {
66
79
  return {
67
80
  service: "system",
81
+ ...config.resource ? { resource: config.resource } : {},
68
82
  command: config.command,
69
83
  description: config.description,
70
84
  flags: config.flags,
@@ -73,20 +87,36 @@ function createAdminCommand(config) {
73
87
  validate: config.validate,
74
88
  preflight: config.risk === "high-risk-write" ? (ctx) => {
75
89
  const request = config.prepare(ctx);
76
- assertAdminPath(request.path);
90
+ assertPath(request.path);
77
91
  } : void 0,
78
92
  dryRun: (ctx) => {
79
93
  const request = config.prepare(ctx);
80
- assertAdminPath(request.path);
94
+ assertPath(request.path);
81
95
  return {
82
96
  method: request.method,
83
97
  url: request.path,
84
98
  ...request.body === void 0 ? {} : { body: config.redactDryRun ? redactSecrets(request.body) : request.body }
85
99
  };
86
100
  },
87
- execute: async (ctx) => executeAdminRequest(ctx, config.prepare(ctx))
101
+ execute: async (ctx) => executeSignedRequest(ctx, config.prepare(ctx), assertPath)
102
+ };
103
+ }
104
+ function createAdminCommand(config) {
105
+ return createSignedCommand(config, assertAdminPath);
106
+ }
107
+ function createCliChannelCommand(config) {
108
+ const command = createSignedCommand(config, assertCliChannelPath);
109
+ const execute = command.execute;
110
+ return {
111
+ ...command,
112
+ execute: async (ctx) => unwrapCliChannelResponse(await execute(ctx))
88
113
  };
89
114
  }
115
+ function unwrapCliChannelResponse(value) {
116
+ if (!value || typeof value !== "object" || Array.isArray(value)) return value;
117
+ const envelope = value;
118
+ return envelope.ok === true && "data" in envelope ? envelope.data : value;
119
+ }
90
120
  function createAdminDownloadCommand(config) {
91
121
  return {
92
122
  service: "system",
@@ -199,7 +229,7 @@ function redactSecrets(value) {
199
229
  return Object.fromEntries(
200
230
  Object.entries(value).map(([key, item]) => [
201
231
  key,
202
- SECRET_KEYS.has(key.toLowerCase()) ? "***" : redactSecrets(item)
232
+ SECRET_KEYS.has(key.toLowerCase().replace(/[^a-z0-9]/g, "")) ? "***" : redactSecrets(item)
203
233
  ])
204
234
  );
205
235
  }
@@ -1131,47 +1161,137 @@ var costControlCommands = [
1131
1161
  ];
1132
1162
 
1133
1163
  // src/commands/te-system/channels.ts
1134
- var CHANNEL_TYPES = /* @__PURE__ */ new Set(["feishu", "slack", "lark"]);
1164
+ var CHANNEL_TYPES = /* @__PURE__ */ new Set([
1165
+ "feishu",
1166
+ "lark",
1167
+ "slack",
1168
+ "discord",
1169
+ "dingtalk",
1170
+ "wecom",
1171
+ "mattermost",
1172
+ "google_chat",
1173
+ "whatsapp"
1174
+ ]);
1175
+ var REQUIRED_CONFIG_KEYS = {
1176
+ feishu: ["app_id", "app_secret"],
1177
+ lark: ["app_id", "app_secret"],
1178
+ slack: ["bot_token", "app_token"],
1179
+ discord: ["bot_token"],
1180
+ dingtalk: ["client_id", "client_secret", "corp_id"],
1181
+ wecom: ["bot_id", "bot_secret"],
1182
+ mattermost: ["server_url", "bot_token"],
1183
+ google_chat: ["service_account_json"],
1184
+ whatsapp: []
1185
+ };
1186
+ var OAUTH_REQUIRED_CONFIG_KEYS = {
1187
+ wecom: ["corp_id", "corp_secret", "agent_id"],
1188
+ mattermost: ["client_id", "client_secret"],
1189
+ google_chat: ["client_id", "client_secret"]
1190
+ };
1191
+ var CONFIG_KEY_ALIASES = {
1192
+ appId: "app_id",
1193
+ appSecret: "app_secret",
1194
+ botToken: "bot_token",
1195
+ appToken: "app_token",
1196
+ clientId: "client_id",
1197
+ clientSecret: "client_secret",
1198
+ corpId: "corp_id",
1199
+ corpSecret: "corp_secret",
1200
+ botId: "bot_id",
1201
+ botSecret: "bot_secret",
1202
+ agentId: "agent_id",
1203
+ oauthEnabled: "oauth_enabled",
1204
+ interactionCardTemplateId: "interaction_card_template_id",
1205
+ serverUrl: "server_url",
1206
+ serviceAccountJson: "service_account_json",
1207
+ workspaceAddonServiceAccountEmail: "workspace_addon_service_account_email"
1208
+ };
1209
+ function normalizeKeys(value, aliases) {
1210
+ return Object.fromEntries(
1211
+ Object.entries(value).map(([key, item]) => [aliases[key] ?? key, item])
1212
+ );
1213
+ }
1214
+ function normalizeChannelBody(channel) {
1215
+ const normalized = normalizeKeys(channel, {
1216
+ systemPrompt: "system_prompt",
1217
+ unbindUsers: "unbind_users"
1218
+ });
1219
+ if (normalized.config && typeof normalized.config === "object" && !Array.isArray(normalized.config)) {
1220
+ normalized.config = normalizeKeys(
1221
+ normalized.config,
1222
+ CONFIG_KEY_ALIASES
1223
+ );
1224
+ }
1225
+ return normalized;
1226
+ }
1135
1227
  function createChannelBody(ctx) {
1136
- const channel = requireJsonObject(ctx, "channel");
1228
+ const channel = normalizeChannelBody(requireJsonObject(ctx, "channel"));
1137
1229
  if (typeof channel.name !== "string" || !channel.name.trim()) {
1138
1230
  throw new CliValidationError("--channel.name is required");
1139
1231
  }
1140
1232
  if (typeof channel.type !== "string" || !CHANNEL_TYPES.has(channel.type)) {
1141
- throw new CliValidationError("--channel.type must be one of: feishu, slack, lark");
1233
+ throw new CliValidationError(
1234
+ `--channel.type must be one of: ${Array.from(CHANNEL_TYPES).join(", ")}`
1235
+ );
1236
+ }
1237
+ if (channel.config === void 0 && channel.type === "whatsapp") {
1238
+ channel.config = {};
1142
1239
  }
1143
1240
  if (!channel.config || typeof channel.config !== "object" || Array.isArray(channel.config)) {
1144
1241
  throw new CliValidationError("--channel.config must be a JSON object");
1145
1242
  }
1146
1243
  const config = channel.config;
1147
- const requiredConfigKeys = channel.type === "slack" ? ["botToken", "appToken"] : ["appId", "appSecret"];
1148
- for (const key of requiredConfigKeys) {
1244
+ for (const key of REQUIRED_CONFIG_KEYS[channel.type] ?? []) {
1149
1245
  if (typeof config[key] !== "string" || !config[key].trim()) {
1150
1246
  throw new CliValidationError(`--channel.config.${key} is required for ${channel.type}`);
1151
1247
  }
1152
1248
  }
1249
+ if (config.oauth_enabled === true) {
1250
+ for (const key of OAUTH_REQUIRED_CONFIG_KEYS[channel.type] ?? []) {
1251
+ if (typeof config[key] !== "string" || !config[key].trim()) {
1252
+ throw new CliValidationError(
1253
+ `--channel.config.${key} is required when oauth_enabled is true for ${channel.type}`
1254
+ );
1255
+ }
1256
+ }
1257
+ }
1153
1258
  return channel;
1154
1259
  }
1155
1260
  function updateChannelBody(ctx) {
1156
- const channel = requireJsonObject(ctx, "channel");
1261
+ const channel = normalizeChannelBody(requireJsonObject(ctx, "channel"));
1157
1262
  if (Object.keys(channel).length === 0) {
1158
1263
  throw new CliValidationError("--channel must contain at least one update field");
1159
1264
  }
1160
- if ("type" in channel) {
1161
- throw new CliValidationError("--channel.type cannot be changed after channel creation");
1265
+ if (channel.type !== void 0 && (typeof channel.type !== "string" || !CHANNEL_TYPES.has(channel.type))) {
1266
+ throw new CliValidationError(
1267
+ `--channel.type must be one of: ${Array.from(CHANNEL_TYPES).join(", ")}`
1268
+ );
1162
1269
  }
1163
1270
  return channel;
1164
1271
  }
1165
- var listChannels = createAdminCommand({
1272
+ var listChannels = createCliChannelCommand({
1166
1273
  command: "+list-channels",
1167
- description: "List configured Feishu, Lark, and Slack channels",
1274
+ description: "List configured channels",
1168
1275
  flags: [],
1169
1276
  risk: "read",
1170
- prepare: () => ({ method: "GET", path: "/api/admin/channels" })
1277
+ prepare: () => ({ method: "GET", path: "/api/cli/channel/v1/channels" })
1171
1278
  });
1172
- var createChannel = createAdminCommand({
1279
+ var getChannel = createCliChannelCommand({
1280
+ resource: "channel",
1281
+ command: "get",
1282
+ description: "Get one configured channel",
1283
+ flags: [
1284
+ { name: "id", type: "string", required: true, desc: "Channel ID from +list-channels" }
1285
+ ],
1286
+ risk: "read",
1287
+ prepare: (ctx) => ({
1288
+ method: "GET",
1289
+ path: `/api/cli/channel/v1/channels/${encodeId(ctx.str("id"))}`
1290
+ })
1291
+ });
1292
+ var createChannel = createCliChannelCommand({
1173
1293
  command: "+create-channel",
1174
- description: "Create a Feishu, Lark, or Slack channel",
1294
+ description: "Create a managed channel",
1175
1295
  flags: [
1176
1296
  {
1177
1297
  name: "channel",
@@ -1185,11 +1305,11 @@ var createChannel = createAdminCommand({
1185
1305
  redactDryRun: true,
1186
1306
  prepare: (ctx) => ({
1187
1307
  method: "POST",
1188
- path: "/api/admin/channels",
1308
+ path: "/api/cli/channel/v1/channels",
1189
1309
  body: createChannelBody(ctx)
1190
1310
  })
1191
1311
  });
1192
- var updateChannel = createAdminCommand({
1312
+ var updateChannel = createCliChannelCommand({
1193
1313
  command: "+update-channel",
1194
1314
  description: "Update channel settings, credentials, model, prompt, or enabled state",
1195
1315
  flags: [
@@ -1205,12 +1325,12 @@ var updateChannel = createAdminCommand({
1205
1325
  risk: "write",
1206
1326
  redactDryRun: true,
1207
1327
  prepare: (ctx) => ({
1208
- method: "PUT",
1209
- path: `/api/admin/channels/${encodeId(ctx.str("id"))}`,
1328
+ method: "PATCH",
1329
+ path: `/api/cli/channel/v1/channels/${encodeId(ctx.str("id"))}`,
1210
1330
  body: updateChannelBody(ctx)
1211
1331
  })
1212
1332
  });
1213
- var removeChannel = createAdminCommand({
1333
+ var removeChannel = createCliChannelCommand({
1214
1334
  command: "+remove-channel",
1215
1335
  description: "Delete a channel, unbind its users, and stop its runtime connection",
1216
1336
  flags: [
@@ -1219,14 +1339,427 @@ var removeChannel = createAdminCommand({
1219
1339
  risk: "high-risk-write",
1220
1340
  prepare: (ctx) => ({
1221
1341
  method: "DELETE",
1222
- path: `/api/admin/channels/${encodeId(ctx.str("id"))}`
1342
+ path: `/api/cli/channel/v1/channels/${encodeId(ctx.str("id"))}`
1343
+ })
1344
+ });
1345
+ var verifyChannel = createCliChannelCommand({
1346
+ resource: "channel",
1347
+ command: "verify",
1348
+ description: "Verify channel credentials and discover endpoints",
1349
+ flags: [
1350
+ { name: "id", type: "string", required: true, desc: "Channel ID from +list-channels" }
1351
+ ],
1352
+ risk: "write",
1353
+ prepare: (ctx) => ({
1354
+ method: "POST",
1355
+ path: `/api/cli/channel/v1/channels/${encodeId(ctx.str("id"))}/verify`
1223
1356
  })
1224
1357
  });
1225
1358
  var channelCommands = [
1226
1359
  listChannels,
1360
+ getChannel,
1227
1361
  createChannel,
1228
1362
  updateChannel,
1229
- removeChannel
1363
+ removeChannel,
1364
+ verifyChannel
1365
+ ];
1366
+
1367
+ // src/commands/te-system/channel-routing.ts
1368
+ function routingBody(ctx) {
1369
+ const routing = requireJsonObject(ctx, "routing");
1370
+ if (routing.status !== "enabled" && routing.status !== "disabled") {
1371
+ throw new CliValidationError("--routing.status must be one of: enabled, disabled");
1372
+ }
1373
+ if (!("default_handler" in routing)) {
1374
+ throw new CliValidationError("--routing.default_handler is required and may be null");
1375
+ }
1376
+ if (!Array.isArray(routing.targets)) {
1377
+ throw new CliValidationError("--routing.targets must be a JSON array");
1378
+ }
1379
+ if (routing.targets.length > 19) {
1380
+ throw new CliValidationError("--routing.targets may contain at most 19 items");
1381
+ }
1382
+ return routing;
1383
+ }
1384
+ var getChannelRouting = createCliChannelCommand({
1385
+ resource: "channel routing",
1386
+ command: "get",
1387
+ description: "Get group message routing for one channel endpoint",
1388
+ flags: [
1389
+ {
1390
+ name: "endpoint-id",
1391
+ type: "string",
1392
+ required: true,
1393
+ desc: "Endpoint ID returned by channel get or channel verify"
1394
+ }
1395
+ ],
1396
+ risk: "read",
1397
+ prepare: (ctx) => ({
1398
+ method: "GET",
1399
+ path: `/api/cli/channel/v1/endpoints/${encodeId(ctx.str("endpoint-id"))}/routing`
1400
+ })
1401
+ });
1402
+ var setChannelRouting = createCliChannelCommand({
1403
+ resource: "channel routing",
1404
+ command: "set",
1405
+ description: "Replace group message routing for one channel endpoint",
1406
+ flags: [
1407
+ {
1408
+ name: "endpoint-id",
1409
+ type: "string",
1410
+ required: true,
1411
+ desc: "Endpoint ID returned by channel get or channel verify"
1412
+ },
1413
+ {
1414
+ name: "routing",
1415
+ type: "string",
1416
+ required: true,
1417
+ desc: "Routing JSON object, @file, or stdin (-)"
1418
+ }
1419
+ ],
1420
+ risk: "write",
1421
+ prepare: (ctx) => ({
1422
+ method: "PUT",
1423
+ path: `/api/cli/channel/v1/endpoints/${encodeId(ctx.str("endpoint-id"))}/routing`,
1424
+ body: routingBody(ctx)
1425
+ })
1426
+ });
1427
+ var channelRoutingCommands = [getChannelRouting, setChannelRouting];
1428
+
1429
+ // src/commands/te-system/channel-whatsapp.ts
1430
+ function whatsappWebPath(channelId) {
1431
+ return `/api/cli/channel/v1/channels/${encodeId(channelId)}/whatsapp-web`;
1432
+ }
1433
+ var getWhatsAppWebStatus = createCliChannelCommand({
1434
+ resource: "channel whatsapp-web",
1435
+ command: "status",
1436
+ description: "Get the WhatsApp Web link status for one channel",
1437
+ flags: [
1438
+ { name: "id", type: "string", required: true, desc: "WhatsApp channel ID" }
1439
+ ],
1440
+ risk: "read",
1441
+ prepare: (ctx) => ({ method: "GET", path: whatsappWebPath(ctx.str("id")) })
1442
+ });
1443
+ var startWhatsAppWebLink = createCliChannelCommand({
1444
+ resource: "channel whatsapp-web",
1445
+ command: "start",
1446
+ description: "Start or resume WhatsApp Web QR linking",
1447
+ flags: [
1448
+ { name: "id", type: "string", required: true, desc: "WhatsApp channel ID" }
1449
+ ],
1450
+ risk: "write",
1451
+ prepare: (ctx) => ({ method: "POST", path: whatsappWebPath(ctx.str("id")) })
1452
+ });
1453
+ var unlinkWhatsAppWeb = createCliChannelCommand({
1454
+ resource: "channel whatsapp-web",
1455
+ command: "unlink",
1456
+ description: "Unlink WhatsApp Web and remove its stored credentials",
1457
+ flags: [
1458
+ { name: "id", type: "string", required: true, desc: "WhatsApp channel ID" }
1459
+ ],
1460
+ risk: "high-risk-write",
1461
+ prepare: (ctx) => ({ method: "DELETE", path: whatsappWebPath(ctx.str("id")) })
1462
+ });
1463
+ var channelWhatsAppCommands = [
1464
+ getWhatsAppWebStatus,
1465
+ startWhatsAppWebLink,
1466
+ unlinkWhatsAppWeb
1467
+ ];
1468
+
1469
+ // src/commands/te-system/channel-bindings.ts
1470
+ var BATCH_BINDING_KEYS = /* @__PURE__ */ new Set(["te_user_id", "open_id", "union_id", "agent_id"]);
1471
+ function requiredBatchString(item, key, index) {
1472
+ const value = item[key];
1473
+ if (typeof value !== "string" || !value.trim()) {
1474
+ throw new CliValidationError(`--bindings[${index}].${key} is required`);
1475
+ }
1476
+ return value.trim();
1477
+ }
1478
+ function optionalBatchString(item, key, index) {
1479
+ if (item[key] === void 0) return void 0;
1480
+ return requiredBatchString(item, key, index);
1481
+ }
1482
+ function batchBindingPlan(ctx) {
1483
+ const input = requireJsonArray(ctx, "bindings");
1484
+ if (input.length < 1 || input.length > 100) {
1485
+ throw new CliValidationError("--bindings must contain between 1 and 100 items");
1486
+ }
1487
+ const endpointId = optionalString(ctx, "endpoint-id");
1488
+ const privateOnly = ctx.bool("private-only");
1489
+ if (privateOnly && endpointId) {
1490
+ throw new CliValidationError("--private-only cannot be combined with --endpoint-id");
1491
+ }
1492
+ if (!privateOnly && !endpointId) {
1493
+ throw new CliValidationError("--endpoint-id is required unless --private-only is true");
1494
+ }
1495
+ const bindings = input.map((raw, index) => {
1496
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
1497
+ throw new CliValidationError(`--bindings[${index}] must be a JSON object`);
1498
+ }
1499
+ const item = raw;
1500
+ const unknownKey = Object.keys(item).find((key) => !BATCH_BINDING_KEYS.has(key));
1501
+ if (unknownKey) {
1502
+ throw new CliValidationError(`--bindings[${index}].${unknownKey} is not supported`);
1503
+ }
1504
+ const unionId = optionalBatchString(item, "union_id", index);
1505
+ if (privateOnly && unionId) {
1506
+ throw new CliValidationError(
1507
+ `--bindings[${index}].union_id is not allowed with --private-only`
1508
+ );
1509
+ }
1510
+ if (!privateOnly && !unionId) {
1511
+ throw new CliValidationError(
1512
+ `--bindings[${index}].union_id is required unless --private-only is true`
1513
+ );
1514
+ }
1515
+ const agentId = optionalBatchString(item, "agent_id", index);
1516
+ return {
1517
+ te_user_id: requiredBatchString(item, "te_user_id", index),
1518
+ open_id: requiredBatchString(item, "open_id", index),
1519
+ ...unionId ? { union_id: unionId } : {},
1520
+ ...agentId ? { agent_id: agentId } : {}
1521
+ };
1522
+ });
1523
+ const defaultAgentId = optionalString(ctx, "default-agent-id");
1524
+ return {
1525
+ channelId: ctx.str("channel-id"),
1526
+ ...endpointId ? { endpointId } : {},
1527
+ privateOnly,
1528
+ ...defaultAgentId ? { defaultAgentId } : {},
1529
+ bindings
1530
+ };
1531
+ }
1532
+ function batchDryRunBody(plan) {
1533
+ return {
1534
+ channel_id: plan.channelId,
1535
+ ...plan.endpointId ? { endpoint_id: plan.endpointId } : {},
1536
+ private_only: plan.privateOnly,
1537
+ ...plan.defaultAgentId ? { default_agent_id: plan.defaultAgentId } : {},
1538
+ bindings: plan.bindings.map((binding) => ({
1539
+ ...binding,
1540
+ ...binding.agent_id || plan.defaultAgentId ? { agent_id: binding.agent_id ?? plan.defaultAgentId } : {}
1541
+ }))
1542
+ };
1543
+ }
1544
+ function batchError(error) {
1545
+ const value = error && typeof error === "object" ? error : {};
1546
+ return {
1547
+ message: typeof value.message === "string" ? value.message : String(error),
1548
+ ...typeof value.code === "string" ? { code: value.code } : {},
1549
+ ...typeof value.status === "number" ? { status: value.status } : {}
1550
+ };
1551
+ }
1552
+ function feishuBindingBody(ctx) {
1553
+ const unionId = optionalString(ctx, "union-id");
1554
+ const endpointId = optionalString(ctx, "endpoint-id");
1555
+ const privateOnly = ctx.bool("private-only");
1556
+ if (privateOnly && (unionId || endpointId)) {
1557
+ throw new CliValidationError(
1558
+ "--private-only cannot be combined with --union-id or --endpoint-id"
1559
+ );
1560
+ }
1561
+ if (!privateOnly && (!unionId || !endpointId)) {
1562
+ throw new CliValidationError(
1563
+ "--union-id and --endpoint-id are required unless --private-only is true"
1564
+ );
1565
+ }
1566
+ return {
1567
+ channel_id: ctx.str("channel-id"),
1568
+ te_user_id: ctx.str("te-user-id"),
1569
+ open_id: ctx.str("open-id"),
1570
+ ...unionId && endpointId ? { union_id: unionId, endpoint_id: endpointId } : {}
1571
+ };
1572
+ }
1573
+ var listChannelBindings = createCliChannelCommand({
1574
+ resource: "channel binding",
1575
+ command: "list",
1576
+ description: "List channel user bindings",
1577
+ flags: [
1578
+ { name: "channel-id", type: "string", desc: "Filter by channel ID" },
1579
+ { name: "te-user-id", type: "string", desc: "Filter by AE user ID" },
1580
+ { name: "open-id", type: "string", desc: "Filter by channel open ID" }
1581
+ ],
1582
+ risk: "read",
1583
+ prepare: (ctx) => ({
1584
+ method: "GET",
1585
+ path: withQuery("/api/cli/channel/v1/bindings", {
1586
+ channel_id: optionalString(ctx, "channel-id"),
1587
+ te_user_id: optionalString(ctx, "te-user-id"),
1588
+ open_id: optionalString(ctx, "open-id")
1589
+ })
1590
+ })
1591
+ });
1592
+ var bindFeishuUser = createCliChannelCommand({
1593
+ resource: "channel binding",
1594
+ command: "bind-feishu",
1595
+ description: "Bind one Feishu user to a managed Feishu channel",
1596
+ flags: [
1597
+ { name: "channel-id", type: "string", required: true, desc: "Feishu channel ID" },
1598
+ { name: "te-user-id", type: "string", required: true, desc: "AE user ID to bind" },
1599
+ { name: "open-id", type: "string", required: true, desc: "Feishu open_id" },
1600
+ { name: "union-id", type: "string", desc: "Feishu union_id for group chat readiness" },
1601
+ { name: "endpoint-id", type: "string", desc: "Verified Feishu endpoint ID" },
1602
+ {
1603
+ name: "private-only",
1604
+ type: "boolean",
1605
+ default: false,
1606
+ desc: "Create a private-chat-only binding without union_id or endpoint_id"
1607
+ }
1608
+ ],
1609
+ risk: "write",
1610
+ prepare: (ctx) => ({
1611
+ method: "PUT",
1612
+ path: "/api/cli/channel/v1/bindings/feishu",
1613
+ body: feishuBindingBody(ctx)
1614
+ })
1615
+ });
1616
+ function createBindFeishuUsersCommand(dependencies = { put: putToMainApp }) {
1617
+ return {
1618
+ service: "system",
1619
+ command: "+bind-feishu-users",
1620
+ description: "Bind 1 to 100 Feishu users and optionally assign default Agents",
1621
+ flags: [
1622
+ { name: "channel-id", type: "string", required: true, desc: "Feishu channel ID" },
1623
+ {
1624
+ name: "endpoint-id",
1625
+ type: "string",
1626
+ desc: "Verified Feishu endpoint ID shared by all group-ready bindings"
1627
+ },
1628
+ {
1629
+ name: "bindings",
1630
+ type: "string",
1631
+ required: true,
1632
+ sensitive: true,
1633
+ desc: "Array of 1 to 100 binding objects as JSON, @file, or stdin (-)"
1634
+ },
1635
+ {
1636
+ name: "default-agent-id",
1637
+ type: "string",
1638
+ desc: "Agent ID used when a binding does not provide agent_id"
1639
+ },
1640
+ {
1641
+ name: "private-only",
1642
+ type: "boolean",
1643
+ default: false,
1644
+ desc: "Create private-chat-only bindings without union_id or endpoint_id"
1645
+ }
1646
+ ],
1647
+ risk: "write",
1648
+ dryRun: (ctx) => ({
1649
+ method: "PUT",
1650
+ url: "/api/cli/channel/v1/bindings/feishu",
1651
+ body: batchDryRunBody(batchBindingPlan(ctx))
1652
+ }),
1653
+ execute: async (ctx) => {
1654
+ const plan = batchBindingPlan(ctx);
1655
+ const host = ctx.host();
1656
+ const results = [];
1657
+ for (const [index, binding] of plan.bindings.entries()) {
1658
+ let bindingId;
1659
+ try {
1660
+ const path3 = "/api/cli/channel/v1/bindings/feishu";
1661
+ assertCliChannelPath(path3);
1662
+ const raw = await dependencies.put(
1663
+ path3,
1664
+ {
1665
+ channel_id: plan.channelId,
1666
+ te_user_id: binding.te_user_id,
1667
+ open_id: binding.open_id,
1668
+ ...binding.union_id && plan.endpointId ? { union_id: binding.union_id, endpoint_id: plan.endpointId } : {}
1669
+ },
1670
+ host
1671
+ );
1672
+ const created = unwrapCliChannelResponse(raw);
1673
+ if (typeof created?.binding_id !== "string" || !created.binding_id) {
1674
+ throw new Error("Feishu binding response did not include binding_id");
1675
+ }
1676
+ bindingId = created.binding_id;
1677
+ const agentId = binding.agent_id ?? plan.defaultAgentId;
1678
+ if (agentId) {
1679
+ const agentPath = `/api/cli/channel/v1/bindings/${encodeId(bindingId)}/agent`;
1680
+ assertCliChannelPath(agentPath);
1681
+ await dependencies.put(agentPath, { agent_id: agentId }, host);
1682
+ }
1683
+ results.push({
1684
+ index,
1685
+ te_user_id: binding.te_user_id,
1686
+ status: "succeeded",
1687
+ binding_id: bindingId,
1688
+ group_routing_ready: created.group_routing_ready === true,
1689
+ ...agentId ? { agent_id: agentId } : {}
1690
+ });
1691
+ } catch (error) {
1692
+ if (error instanceof PermissionError || error instanceof TeAgentApiError && error.status === 401) {
1693
+ throw error;
1694
+ }
1695
+ results.push({
1696
+ index,
1697
+ te_user_id: binding.te_user_id,
1698
+ status: "failed",
1699
+ stage: bindingId ? "agent_assignment" : "binding",
1700
+ ...bindingId ? { binding_id: bindingId } : {},
1701
+ error: batchError(error)
1702
+ });
1703
+ }
1704
+ }
1705
+ const succeeded = results.filter((result) => result.status === "succeeded").length;
1706
+ return {
1707
+ total: results.length,
1708
+ succeeded,
1709
+ failed: results.length - succeeded,
1710
+ results
1711
+ };
1712
+ }
1713
+ };
1714
+ }
1715
+ var bindFeishuUsers = createBindFeishuUsersCommand();
1716
+ var unbindChannelUser = createCliChannelCommand({
1717
+ resource: "channel binding",
1718
+ command: "unbind",
1719
+ description: "Delete one channel user binding",
1720
+ flags: [
1721
+ { name: "binding-id", type: "string", required: true, desc: "Binding ID" }
1722
+ ],
1723
+ risk: "high-risk-write",
1724
+ prepare: (ctx) => ({
1725
+ method: "DELETE",
1726
+ path: `/api/cli/channel/v1/bindings/${encodeId(ctx.str("binding-id"))}`
1727
+ })
1728
+ });
1729
+ var setChannelUserAgent = createCliChannelCommand({
1730
+ resource: "channel binding",
1731
+ command: "set-agent",
1732
+ description: "Set the private-chat default Agent for one channel user binding",
1733
+ flags: [
1734
+ { name: "binding-id", type: "string", required: true, desc: "Binding ID" },
1735
+ { name: "agent-id", type: "string", desc: "Agent ID to assign" },
1736
+ {
1737
+ name: "clear",
1738
+ type: "boolean",
1739
+ default: false,
1740
+ desc: "Clear the binding Agent and restore system-default resolution"
1741
+ }
1742
+ ],
1743
+ risk: "write",
1744
+ prepare: (ctx) => {
1745
+ const agentId = optionalString(ctx, "agent-id");
1746
+ const clear = ctx.bool("clear");
1747
+ if (Boolean(agentId) === clear) {
1748
+ throw new CliValidationError("Pass exactly one of --agent-id or --clear");
1749
+ }
1750
+ return {
1751
+ method: "PUT",
1752
+ path: `/api/cli/channel/v1/bindings/${encodeId(ctx.str("binding-id"))}/agent`,
1753
+ body: { agent_id: clear ? null : agentId }
1754
+ };
1755
+ }
1756
+ });
1757
+ var channelBindingCommands = [
1758
+ listChannelBindings,
1759
+ bindFeishuUser,
1760
+ bindFeishuUsers,
1761
+ unbindChannelUser,
1762
+ setChannelUserAgent
1230
1763
  ];
1231
1764
 
1232
1765
  // src/commands/te-system/sandbox-tools.ts
@@ -1250,7 +1783,7 @@ import {
1250
1783
  } from "fs/promises";
1251
1784
  import { tmpdir } from "os";
1252
1785
  import path from "path";
1253
- import archiver from "archiver";
1786
+ import { ZipArchive } from "archiver";
1254
1787
  var TOOL_UPLOAD_LIMITS = {
1255
1788
  maxArchiveBytes: 50 * 1024 * 1024,
1256
1789
  maxUnpackedBytes: 500 * 1024 * 1024,
@@ -1641,7 +2174,7 @@ async function collectArchiveEntries(root, manifestSourcePath) {
1641
2174
  async function writeArchive(archivePath, manifest, entries) {
1642
2175
  await new Promise((resolvePromise, rejectPromise) => {
1643
2176
  const output = createWriteStream(archivePath, { mode: 384 });
1644
- const zip = archiver("zip", { zlib: { level: 9 } });
2177
+ const zip = new ZipArchive({ zlib: { level: 9 } });
1645
2178
  output.on("close", resolvePromise);
1646
2179
  output.on("error", rejectPromise);
1647
2180
  zip.on("error", rejectPromise);
@@ -2205,6 +2738,9 @@ var commands = [
2205
2738
  ...usageCommands,
2206
2739
  ...costControlCommands,
2207
2740
  ...channelCommands,
2741
+ ...channelRoutingCommands,
2742
+ ...channelWhatsAppCommands,
2743
+ ...channelBindingCommands,
2208
2744
  ...sandboxToolCommands
2209
2745
  ];
2210
2746
  var te_system_default = commands;