@bty/customer-service-cli 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +91 -8
  2. package/dist/bin.js +554 -15
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -65,6 +65,50 @@ cs-cli agent list
65
65
  | `--timeout <ms>` | 请求超时时间(毫秒) | `20000` |
66
66
 
67
67
 
68
+ ## 本地配置 (`.cs-cli.json`)
69
+
70
+ 支持在项目目录下放置 `.cs-cli.json` 文件,为不同项目配置不同的工作空间。
71
+
72
+ ### 工作空间优先级
73
+
74
+ | 优先级 | 来源 | 说明 |
75
+ | --- | ----------------------- | ---------- |
76
+ | 1 | `--workspace <id>` 参数 | 命令行临时覆盖 |
77
+ | 2 | `.cs-cli.json` (本地配置) | 当前目录或祖先目录 |
78
+ | 3 | `~/.cs-cli/config.json` | 全局默认配置 |
79
+
80
+ ### 使用方式
81
+
82
+ ```bash
83
+ # 在项目目录下初始化本地配置
84
+ cs-cli config init
85
+
86
+ # 设置工作空间(自动写入本地 .cs-cli.json)
87
+ cs-cli config set-workspace <workspace_id>
88
+
89
+ # 强制写入全局配置
90
+ cs-cli config set-workspace <workspace_id> --global
91
+ ```
92
+
93
+ CLI 从当前目录向上查找 `.cs-cli.json`,找到第一个即使用其中的 `workspaceId`。
94
+
95
+ `.cs-cli.json` 格式:
96
+
97
+ ```json
98
+ {
99
+ "workspaceId": "ws-abc123",
100
+ "workspaceName": "某客户项目"
101
+ }
102
+ ```
103
+
104
+ ### `set-workspace` 写入规则
105
+
106
+ - 当前目录或祖先目录存在 `.cs-cli.json` → 写入本地配置
107
+ - 不存在 `.cs-cli.json` → 写入全局配置
108
+ - 使用 `--global` → 强制写入全局配置
109
+
110
+ 每次写入后会提示写入的目标路径。
111
+
68
112
  ## 命令速查表
69
113
 
70
114
  ### 认证 (`auth`)
@@ -80,11 +124,12 @@ cs-cli agent list
80
124
  ### 配置 (`config`)
81
125
 
82
126
 
83
- | 命令 | 说明 |
84
- | ----------------------------------------------------------- | --------- |
85
- | `config set --cs-api <url> --auth-api <url> --ai-api <url>` | 设置 API 地址 |
86
- | `config get` | 查看当前配置 |
87
- | `config set-workspace <workspace_id>` | 设置默认工作空间 |
127
+ | 命令 | 说明 |
128
+ | ----------------------------------------------------------- | ---------------------------- |
129
+ | `config set --cs-api <url> --auth-api <url> --ai-api <url>` | 设置 API 地址 |
130
+ | `config get` | 查看当前配置(含全局和本地) |
131
+ | `config init` | 在当前目录初始化本地配置 (`.cs-cli.json`) |
132
+ | `config set-workspace <workspace_id> [--global]` | 设置默认工作空间 |
88
133
 
89
134
 
90
135
  ### 工作空间 (`workspace`)
@@ -157,10 +202,11 @@ cs-cli product update-sku --agent <id> --sku "颜色分类:粉红" --update '{"
157
202
 
158
203
  ### 聊天记录 (`chat-history`)
159
204
 
205
+ 查询客户导入的聊天记录,用于 SA(场景动作)清洗,非 Agent 自身的对话记录。
160
206
 
161
- | 命令 | 说明 |
162
- | ------------------------------------------------------ | ------------- |
163
- | `chat-history --agent <id> [--page N] [--page-size N]` | 查询 Agent 聊天记录 |
207
+ | 命令 | 说明 |
208
+ | ------------------------------------------------------ | --------------- |
209
+ | `chat-history --agent <id> [--page N] [--page-size N]` | 查询客户导入的聊天记录 |
164
210
 
165
211
 
166
212
  ### FAQ 知识库 (`faq`)
@@ -192,6 +238,43 @@ cs-cli product update-sku --agent <id> --sku "颜色分类:粉红" --update '{"
192
238
 
193
239
  `debug ask` 会自动创建调试会话、发送消息、轮询等待 Agent 回复,默认最大等待 30 秒。支持 `--messages` 传入完整消息列表(JSON 或 @文件)重放 issue 对话。
194
240
 
241
+ ### 运营监控 (`monitor`)
242
+
243
+ 直接调用 `/v1/operation` 底层接口,返回原始数据,由调用方决定如何聚合统计。
244
+
245
+ #### Agent 生命周期
246
+
247
+ | 命令 | 说明 |
248
+ | --- | --- |
249
+ | `monitor agents [--page N] [--page-size N]` | Agent 生命周期列表(含构建进度、会话统计等原始数据) |
250
+
251
+ #### 监控工单
252
+
253
+ | 命令 | 说明 |
254
+ | --- | --- |
255
+ | `monitor tickets list [--agent <id>] [--status <状态>] [--severity <级别>]` | 列出监控工单 |
256
+ | `monitor tickets delete <ticket_id>` | 删除监控工单 |
257
+
258
+ #### 监控快照
259
+
260
+ | 命令 | 说明 |
261
+ | --- | --- |
262
+ | `monitor snapshots hourly --agent <id> --start <ISO> --end <ISO>` | 查询小时快照 |
263
+ | `monitor snapshots daily --agent <id> --start <日期> --end <日期>` | 查询日快照 |
264
+ | `monitor snapshots daily-range --agent <id> --start <日期> --end <日期>` | 查询日快照范围(含趋势) |
265
+
266
+ #### Agent 运营统计
267
+
268
+ | 命令 | 说明 |
269
+ | --- | --- |
270
+ | `monitor statistics [--start <ISO> --end <ISO>] [--page N] [--page-size N]` | Agent 运营统计(会话量、转人工率、响应时间等) |
271
+
272
+ #### 运营工作空间
273
+
274
+ | 命令 | 说明 |
275
+ | --- | --- |
276
+ | `monitor workspaces [--has-agent] [--page N] [--page-size N]` | 运营工作空间列表(含合同、客户信息) |
277
+
195
278
  ## 输出格式
196
279
 
197
280
  默认输出 JSON:
package/dist/bin.js CHANGED
@@ -61,6 +61,9 @@ function outputError(code, message) {
61
61
  };
62
62
  process.stdout.write(JSON.stringify(response, null, 2));
63
63
  }
64
+ function outputInfo(message) {
65
+ process.stderr.write(message + "\n");
66
+ }
64
67
 
65
68
  // src/client/auth-api.ts
66
69
  import CryptoJS from "crypto-js";
@@ -73,6 +76,7 @@ import path2 from "path";
73
76
  import fs from "fs";
74
77
  import path from "path";
75
78
  import os from "os";
79
+ var LOCAL_CONFIG_FILENAME = ".cs-cli.json";
76
80
  function getConfigDir() {
77
81
  return process.env.CS_CLI_HOME || path.join(os.homedir(), ".cs-cli");
78
82
  }
@@ -95,6 +99,55 @@ function writeConfig(config) {
95
99
  JSON.stringify(merged, null, 2)
96
100
  );
97
101
  }
102
+ function findLocalConfigPath() {
103
+ let dir = process.cwd();
104
+ const root = path.parse(dir).root;
105
+ while (true) {
106
+ const candidate = path.join(dir, LOCAL_CONFIG_FILENAME);
107
+ if (fs.existsSync(candidate)) {
108
+ return candidate;
109
+ }
110
+ const parent = path.dirname(dir);
111
+ if (parent === dir || parent === root) {
112
+ const rootCandidate = path.join(root, LOCAL_CONFIG_FILENAME);
113
+ if (fs.existsSync(rootCandidate)) {
114
+ return rootCandidate;
115
+ }
116
+ return null;
117
+ }
118
+ dir = parent;
119
+ }
120
+ }
121
+ function readLocalConfig() {
122
+ const configPath = findLocalConfigPath();
123
+ if (!configPath) return null;
124
+ try {
125
+ const content = fs.readFileSync(configPath, "utf-8");
126
+ return JSON.parse(content);
127
+ } catch {
128
+ return null;
129
+ }
130
+ }
131
+ function writeLocalConfig(config, targetPath) {
132
+ const filePath = targetPath ?? findLocalConfigPath() ?? path.join(process.cwd(), LOCAL_CONFIG_FILENAME);
133
+ let existing = {};
134
+ try {
135
+ const content = fs.readFileSync(filePath, "utf-8");
136
+ existing = JSON.parse(content);
137
+ } catch {
138
+ }
139
+ const merged = { ...existing, ...config };
140
+ fs.writeFileSync(filePath, JSON.stringify(merged, null, 2) + "\n");
141
+ return filePath;
142
+ }
143
+ function initLocalConfig() {
144
+ const filePath = path.join(process.cwd(), LOCAL_CONFIG_FILENAME);
145
+ if (fs.existsSync(filePath)) {
146
+ return filePath;
147
+ }
148
+ fs.writeFileSync(filePath, JSON.stringify({}, null, 2) + "\n");
149
+ return filePath;
150
+ }
98
151
 
99
152
  // src/utils/credentials.ts
100
153
  function getCredentialsPath() {
@@ -227,12 +280,13 @@ function getAiApiUrl() {
227
280
  return config?.aiApiUrl ?? DEFAULT_AI_API_URL;
228
281
  }
229
282
  function getWorkspaceId(overrideWorkspaceId) {
230
- const config = readConfig();
231
- const wsId = overrideWorkspaceId ?? getRuntimeWorkspaceId() ?? config?.defaultWorkspaceId;
232
- if (!wsId) {
233
- throw new APIError(1, "\u672A\u8BBE\u7F6E\u5DE5\u4F5C\u7A7A\u95F4\uFF0C\u8BF7\u8FD0\u884C: cs-cli config set-workspace <id>");
234
- }
235
- return wsId;
283
+ const runtimeId = overrideWorkspaceId ?? getRuntimeWorkspaceId();
284
+ if (runtimeId) return runtimeId;
285
+ const localConfig = readLocalConfig();
286
+ if (localConfig?.workspaceId) return localConfig.workspaceId;
287
+ const globalConfig = readConfig();
288
+ if (globalConfig?.defaultWorkspaceId) return globalConfig.defaultWorkspaceId;
289
+ throw new APIError(1, "\u672A\u8BBE\u7F6E\u5DE5\u4F5C\u7A7A\u95F4\uFF0C\u8BF7\u8FD0\u884C: cs-cli config set-workspace <id>");
236
290
  }
237
291
 
238
292
  // src/client/auth-api.ts
@@ -346,18 +400,46 @@ function registerConfigCommand(program2) {
346
400
  formatOutput({ success: true, data: readConfig() }, program2.opts().table);
347
401
  });
348
402
  config.command("get").description("\u67E5\u770B\u5F53\u524D\u914D\u7F6E").action(() => {
349
- const cfg = readConfig();
350
- formatOutput({ success: true, data: cfg ?? {} }, program2.opts().table);
403
+ const globalCfg = readConfig() ?? {};
404
+ const localCfg = readLocalConfig();
405
+ const localPath = findLocalConfigPath();
406
+ const data = {
407
+ global: globalCfg,
408
+ local: localCfg ? { path: localPath, config: localCfg } : null
409
+ };
410
+ formatOutput({ success: true, data }, program2.opts().table);
351
411
  });
352
- config.command("set-workspace").description("\u8BBE\u7F6E\u9ED8\u8BA4\u5DE5\u4F5C\u7A7A\u95F4").argument("<workspace_id>", "\u5DE5\u4F5C\u7A7A\u95F4 ID").action(async (workspaceId) => {
412
+ config.command("init").description("\u5728\u5F53\u524D\u76EE\u5F55\u521D\u59CB\u5316\u672C\u5730\u914D\u7F6E (.cs-cli.json)").action(() => {
413
+ const filePath = initLocalConfig();
414
+ outputInfo(`\u672C\u5730\u914D\u7F6E\u5DF2\u521D\u59CB\u5316: ${filePath}`);
415
+ formatOutput({ success: true, data: { path: filePath } }, program2.opts().table);
416
+ });
417
+ config.command("set-workspace").description("\u8BBE\u7F6E\u9ED8\u8BA4\u5DE5\u4F5C\u7A7A\u95F4").argument("<workspace_id>", "\u5DE5\u4F5C\u7A7A\u95F4 ID").option("--global", "\u5F3A\u5236\u5199\u5165\u5168\u5C40\u914D\u7F6E").action(async (workspaceId, opts) => {
418
+ const useLocal = !opts.global && findLocalConfigPath() !== null;
353
419
  try {
354
- const workspaces = await listWorkspaces();
355
- const matched = workspaces.find((ws) => ws.id === workspaceId);
420
+ const workspaces2 = await listWorkspaces();
421
+ const matched = workspaces2.find((ws) => ws.id === workspaceId);
356
422
  const name = matched?.name;
357
- writeConfig({ defaultWorkspaceId: workspaceId, defaultWorkspaceName: name });
358
- formatOutput({ success: true, data: { defaultWorkspaceId: workspaceId, defaultWorkspaceName: name ?? "(unknown)" } }, program2.opts().table);
423
+ if (useLocal) {
424
+ const writtenPath = writeLocalConfig({ workspaceId, workspaceName: name });
425
+ outputInfo(`\u5DE5\u4F5C\u7A7A\u95F4\u5DF2\u8BBE\u7F6E: ${name ?? workspaceId}
426
+ \u2192 \u5199\u5165: ${writtenPath}`);
427
+ } else {
428
+ writeConfig({ defaultWorkspaceId: workspaceId, defaultWorkspaceName: name });
429
+ outputInfo(`\u5DE5\u4F5C\u7A7A\u95F4\u5DF2\u8BBE\u7F6E: ${name ?? workspaceId}
430
+ \u2192 \u5199\u5165: \u5168\u5C40\u914D\u7F6E`);
431
+ }
432
+ formatOutput({ success: true, data: { workspaceId, workspaceName: name ?? "(unknown)", target: useLocal ? "local" : "global" } }, program2.opts().table);
359
433
  } catch (err) {
360
- writeConfig({ defaultWorkspaceId: workspaceId });
434
+ if (useLocal) {
435
+ const writtenPath = writeLocalConfig({ workspaceId });
436
+ outputInfo(`\u5DE5\u4F5C\u7A7A\u95F4\u5DF2\u8BBE\u7F6E: ${workspaceId}
437
+ \u2192 \u5199\u5165: ${writtenPath}`);
438
+ } else {
439
+ writeConfig({ defaultWorkspaceId: workspaceId });
440
+ outputInfo(`\u5DE5\u4F5C\u7A7A\u95F4\u5DF2\u8BBE\u7F6E: ${workspaceId}
441
+ \u2192 \u5199\u5165: \u5168\u5C40\u914D\u7F6E`);
442
+ }
361
443
  outputError(err.statusCode ?? 1, err.message);
362
444
  process.exit(toExitCode(err));
363
445
  }
@@ -901,7 +983,7 @@ async function listChatHistory(opts) {
901
983
 
902
984
  // src/commands/chat-history.ts
903
985
  function registerChatHistoryCommand(program2) {
904
- program2.command("chat-history").description("\u67E5\u8BE2 Agent \u804A\u5929\u8BB0\u5F55").requiredOption("--agent <config_id>", "Agent \u914D\u7F6E ID").option("--page <number>", "\u9875\u7801", "1").option("--page-size <number>", "\u6BCF\u9875\u6570\u91CF", "20").action(async (opts) => {
986
+ program2.command("chat-history").description("\u67E5\u8BE2\u5BA2\u6237\u5BFC\u5165\u7684\u804A\u5929\u8BB0\u5F55\uFF08\u7528\u4E8E SA \u6E05\u6D17\uFF09").requiredOption("--agent <config_id>", "Agent \u914D\u7F6E ID").option("--page <number>", "\u9875\u7801", "1").option("--page-size <number>", "\u6BCF\u9875\u6570\u91CF", "20").action(async (opts) => {
905
987
  try {
906
988
  const data = await listChatHistory({
907
989
  agentConfigId: opts.agent,
@@ -1206,6 +1288,462 @@ function registerDebugCommand(program2) {
1206
1288
  });
1207
1289
  }
1208
1290
 
1291
+ // src/client/monitor-api.ts
1292
+ var MONITOR_PATH_PREFIX = "/v1/operation";
1293
+ async function listAgentLifecycle(opts) {
1294
+ const request = createRequest();
1295
+ return request(getCustomerServiceUrl(), `${MONITOR_PATH_PREFIX}/agent-lifecycle`, {
1296
+ method: "GET",
1297
+ query: { page: opts.page ?? 1, page_size: opts.pageSize ?? 200 }
1298
+ });
1299
+ }
1300
+ async function listTickets(opts) {
1301
+ const request = createRequest();
1302
+ const query = {
1303
+ page: opts.page ?? 1,
1304
+ page_size: opts.pageSize ?? 200
1305
+ };
1306
+ if (opts.status) query.status = opts.status;
1307
+ if (opts.severity) query.severity = opts.severity;
1308
+ if (opts.agentId) query.config_id = opts.agentId;
1309
+ return request(getCustomerServiceUrl(), `${MONITOR_PATH_PREFIX}/tickets`, {
1310
+ method: "GET",
1311
+ query
1312
+ });
1313
+ }
1314
+ async function deleteTicket(ticketId) {
1315
+ const request = createRequest();
1316
+ return request(getCustomerServiceUrl(), `${MONITOR_PATH_PREFIX}/tickets/${ticketId}`, {
1317
+ method: "DELETE"
1318
+ });
1319
+ }
1320
+ async function listHourlySnapshots(opts) {
1321
+ const request = createRequest();
1322
+ const query = {};
1323
+ if (opts.workspaceId) query.workspace_id = opts.workspaceId;
1324
+ if (opts.agentId) query.agent_id = opts.agentId;
1325
+ if (opts.startTime) query.start_time = opts.startTime;
1326
+ if (opts.endTime) query.end_time = opts.endTime;
1327
+ if (opts.page) query.page = opts.page;
1328
+ if (opts.pageSize) query.page_size = opts.pageSize;
1329
+ return request(getCustomerServiceUrl(), `${MONITOR_PATH_PREFIX}/snapshots/hourly`, {
1330
+ method: "GET",
1331
+ query
1332
+ });
1333
+ }
1334
+ async function listDailySnapshots(opts) {
1335
+ const request = createRequest();
1336
+ const query = {};
1337
+ if (opts.workspaceId) query.workspace_id = opts.workspaceId;
1338
+ if (opts.agentId) query.agent_id = opts.agentId;
1339
+ if (opts.startDate) query.start_date = opts.startDate;
1340
+ if (opts.endDate) query.end_date = opts.endDate;
1341
+ return request(getCustomerServiceUrl(), `${MONITOR_PATH_PREFIX}/snapshots/daily`, {
1342
+ method: "GET",
1343
+ query
1344
+ });
1345
+ }
1346
+ async function listDailySnapshotsRange(opts) {
1347
+ const request = createRequest();
1348
+ const query = {};
1349
+ if (opts.workspaceId) query.workspace_id = opts.workspaceId;
1350
+ if (opts.agentId) query.agent_id = opts.agentId;
1351
+ if (opts.startDate) query.start_date = opts.startDate;
1352
+ if (opts.endDate) query.end_date = opts.endDate;
1353
+ if (opts.page) query.page = opts.page;
1354
+ if (opts.pageSize) query.page_size = opts.pageSize ?? 200;
1355
+ return request(getCustomerServiceUrl(), `${MONITOR_PATH_PREFIX}/snapshots/daily/range`, {
1356
+ method: "GET",
1357
+ query
1358
+ });
1359
+ }
1360
+ async function listAgentStatistics(opts) {
1361
+ const request = createRequest();
1362
+ const query = {
1363
+ page: opts.page ?? 1,
1364
+ page_size: opts.pageSize ?? 100
1365
+ };
1366
+ if (opts.startDate) query.start_date = opts.startDate;
1367
+ if (opts.endDate) query.end_date = opts.endDate;
1368
+ return request(getCustomerServiceUrl(), `${MONITOR_PATH_PREFIX}/customer-agents/statistics`, {
1369
+ method: "GET",
1370
+ query
1371
+ });
1372
+ }
1373
+ async function listOperationWorkspaces(opts) {
1374
+ const request = createRequest();
1375
+ const query = {
1376
+ page: opts.page ?? 1,
1377
+ page_size: opts.pageSize ?? 200
1378
+ };
1379
+ if (opts.hasAgent !== void 0) query.has_agent = String(opts.hasAgent);
1380
+ return request(getCustomerServiceUrl(), `${MONITOR_PATH_PREFIX}/workspaces/list`, {
1381
+ method: "GET",
1382
+ query
1383
+ });
1384
+ }
1385
+
1386
+ // src/lib/monitor-field-defs.ts
1387
+ var agents = {
1388
+ resource: "agents",
1389
+ command: "monitor agents",
1390
+ apiPath: "/v1/operation/agent-lifecycle",
1391
+ description: "Agent \u751F\u547D\u5468\u671F\u5217\u8868\uFF0C\u5305\u542B\u6784\u5EFA\u8FDB\u5EA6\u3001\u4F1A\u8BDD\u7EDF\u8BA1\u3001\u5546\u54C1\u5B66\u4E60\u72B6\u6001\u7B49\u5168\u91CF\u6570\u636E",
1392
+ fields: [
1393
+ { field: "config_id", type: "string", description: "Agent \u914D\u7F6E ID" },
1394
+ { field: "config_name", type: "string", description: "Agent \u540D\u79F0" },
1395
+ { field: "workspace_id", type: "string", description: "\u5DE5\u4F5C\u7A7A\u95F4 ID" },
1396
+ { field: "workspace.workspace_name", type: "string", description: "\u5DE5\u4F5C\u7A7A\u95F4\u540D\u79F0" },
1397
+ { field: "workspace.user_name", type: "string", description: "\u7528\u6237\u540D" },
1398
+ { field: "workspace.phone", type: "string", description: "\u624B\u673A\u53F7" },
1399
+ { field: "workspace.industry", type: "string", description: "\u884C\u4E1A" },
1400
+ { field: "workspace.shop_name", type: "string", description: "\u5E97\u94FA\u540D" },
1401
+ { field: "workspace.expired_time", type: "string", description: "\u5DE5\u4F5C\u7A7A\u95F4\u8FC7\u671F\u65F6\u95F4" },
1402
+ { field: "workspace.activate_time", type: "string", description: "\u5DE5\u4F5C\u7A7A\u95F4\u6FC0\u6D3B\u65F6\u95F4" },
1403
+ { field: "workspace.status", type: "string", description: "\u5DE5\u4F5C\u7A7A\u95F4\u72B6\u6001" },
1404
+ { field: "workspace.sales_channel", type: "string", description: "\u9500\u552E\u6E20\u9053" },
1405
+ { field: "channel", type: "string", description: "\u63A5\u5165\u6E20\u9053\uFF08qianniu/pinduoduo/jingdong/douyin\uFF09" },
1406
+ { field: "industry", type: "string", description: "\u884C\u4E1A\u5206\u7C7B\uFF08fashion/digital/home/baby/health/sports \u7B49\uFF09" },
1407
+ { field: "current_phase", type: "string", description: "\u5F53\u524D\u751F\u547D\u5468\u671F\u9636\u6BB5\uFF08agent_creation/learning/plugin_sync/evaluation/operating\uFF09" },
1408
+ { field: "phase_status", type: "string", description: "\u9636\u6BB5\u72B6\u6001\uFF08success/failed/processing/pending\uFF09" },
1409
+ { field: "phase_entered_at", type: "string", description: "\u8FDB\u5165\u5F53\u524D\u9636\u6BB5\u7684\u65F6\u95F4" },
1410
+ { field: "created_at", type: "string", description: "Agent \u521B\u5EFA\u65F6\u95F4" },
1411
+ { field: "updated_at", type: "string", description: "\u6700\u540E\u66F4\u65B0\u65F6\u95F4" },
1412
+ { field: "stats_synced_at", type: "string", description: "\u7EDF\u8BA1\u6570\u636E\u540C\u6B65\u65F6\u95F4" },
1413
+ { field: "chat_history_stats.has_chat_history", type: "boolean", description: "\u662F\u5426\u5DF2\u5BFC\u5165\u804A\u5929\u8BB0\u5F55" },
1414
+ { field: "chat_history_stats.latest_chat_record_count", type: "number", description: "\u5BFC\u5165\u7684\u804A\u5929\u8BB0\u5F55\u6570\u91CF" },
1415
+ { field: "product_stats.total_count", type: "number", description: "\u5546\u54C1\u603B\u6570" },
1416
+ { field: "product_stats.basic_count", type: "number", description: "\u57FA\u7840\u5B66\u4E60\u5B8C\u6210\u7684\u5546\u54C1\u6570" },
1417
+ { field: "product_stats.deep_count", type: "number", description: "\u6DF1\u5EA6\u5B66\u4E60\u5B8C\u6210\u7684\u5546\u54C1\u6570" },
1418
+ { field: "product_stats.failed_count", type: "number", description: "\u5B66\u4E60\u5931\u8D25\u7684\u5546\u54C1\u6570" },
1419
+ { field: "product_stats.has_product", type: "boolean", description: "\u662F\u5426\u6709\u5546\u54C1\u6570\u636E" },
1420
+ { field: "situation_action_stats.count", type: "number", description: "\u573A\u666F\u52A8\u4F5C(SA)\u6570\u91CF" },
1421
+ { field: "qa_stats.segment_count", type: "number", description: "FAQ \u6761\u76EE\u6570\u91CF" },
1422
+ { field: "chat_conversation_stats.total_conversations", type: "number", description: "\u7D2F\u8BA1\u4F1A\u8BDD\u603B\u6570" },
1423
+ { field: "chat_conversation_stats.daily_avg_conversations", type: "number", description: "\u4ECA\u65E5\u4F1A\u8BDD\u6570" },
1424
+ { field: "chat_conversation_stats.manual_takeover_rate", type: "number", description: "\u8F6C\u4EBA\u5DE5\u7387\uFF080~1 \u7684\u6BD4\u7387\uFF09" },
1425
+ { field: "chat_record_stats.agent_response_count", type: "number", description: "Agent \u56DE\u590D\u6D88\u606F\u603B\u6570" },
1426
+ { field: "issue_stats.total_count", type: "number", description: "\u5DE5\u5355\u603B\u6570" },
1427
+ { field: "issue_stats.open_count", type: "number", description: "\u672A\u5173\u95ED\u5DE5\u5355\u6570" },
1428
+ { field: "issue_stats.latest_created_at", type: "string|null", description: "\u6700\u65B0\u5DE5\u5355\u521B\u5EFA\u65F6\u95F4" },
1429
+ { field: "robot_stats.robot_count", type: "number", description: "\u673A\u5668\u4EBA\u603B\u6570" },
1430
+ { field: "robot_stats.running_count", type: "number", description: "\u8FD0\u884C\u4E2D\u7684\u673A\u5668\u4EBA\u6570" },
1431
+ { field: "shop_id", type: "string", description: "\u5E97\u94FA ID" },
1432
+ { field: "return_phase", type: "string|null", description: "\u56DE\u9000\u9636\u6BB5\uFF08\u5982\u6709\uFF09" },
1433
+ { field: "phase_enter_counts", type: "object", description: "\u5404\u9636\u6BB5\u8FDB\u5165\u6B21\u6570\uFF08key \u4E3A\u9636\u6BB5\u540D\uFF0Cvalue \u4E3A\u6B21\u6570\uFF09" },
1434
+ { field: "checkpoints", type: "object", description: "\u5404\u9636\u6BB5\u68C0\u67E5\u70B9\u72B6\u6001\uFF08\u542B last_status/ticket_emitted \u7B49\uFF09" }
1435
+ ]
1436
+ };
1437
+ var tickets = {
1438
+ resource: "tickets",
1439
+ command: "monitor tickets list",
1440
+ apiPath: "/v1/operation/tickets",
1441
+ description: "\u76D1\u63A7\u5DE5\u5355\u5217\u8868\uFF0C\u7531\u5F02\u5E38\u68C0\u6D4B\u89C4\u5219\u81EA\u52A8\u751F\u6210",
1442
+ fields: [
1443
+ { field: "ticket_id", type: "string", description: "\u5DE5\u5355 ID" },
1444
+ { field: "id", type: "number", description: "\u5DE5\u5355\u5E8F\u53F7" },
1445
+ { field: "config_id", type: "string", description: "Agent \u914D\u7F6E ID" },
1446
+ { field: "workspace_id", type: "string", description: "\u5DE5\u4F5C\u7A7A\u95F4 ID" },
1447
+ { field: "title", type: "string", description: "\u5DE5\u5355\u6807\u9898" },
1448
+ { field: "status", type: "string", description: "\u72B6\u6001\uFF08open/in_progress/resolved/closed\uFF09" },
1449
+ { field: "priority", type: "string", description: "\u4F18\u5148\u7EA7\uFF08P0/P1/P2/P3\uFF09" },
1450
+ { field: "phase", type: "string", description: "\u6240\u5C5E\u9636\u6BB5" },
1451
+ { field: "phase_status", type: "string|null", description: "\u9636\u6BB5\u72B6\u6001" },
1452
+ { field: "assignee", type: "string|null", description: "\u6307\u6D3E\u4EBA" },
1453
+ { field: "assignee_type", type: "string|null", description: "\u6307\u6D3E\u4EBA\u7C7B\u578B" },
1454
+ { field: "solution", type: "string|null", description: "\u89E3\u51B3\u65B9\u6848" },
1455
+ { field: "created_at", type: "string", description: "\u521B\u5EFA\u65F6\u95F4" },
1456
+ { field: "updated_at", type: "string", description: "\u66F4\u65B0\u65F6\u95F4" },
1457
+ { field: "expected_completion_time", type: "string|null", description: "\u9884\u8BA1\u5B8C\u6210\u65F6\u95F4" },
1458
+ { field: "actual_completion_time", type: "string|null", description: "\u5B9E\u9645\u5B8C\u6210\u65F6\u95F4" },
1459
+ { field: "payload.category", type: "string", description: "\u5DE5\u5355\u5206\u7C7B\uFF08\u6784\u5EFA\u671F/\u8FD0\u8425\u671F\uFF09" },
1460
+ { field: "payload.severity", type: "string", description: "\u4E25\u91CD\u7EA7\u522B\uFF08critical/high/medium/low\uFF09" },
1461
+ { field: "payload.ticket_key", type: "string", description: "\u5DE5\u5355\u53BB\u91CD key" },
1462
+ { field: "payload.checks", type: "array", description: "\u89E6\u53D1\u7684\u68C0\u67E5\u9879\u5217\u8868" },
1463
+ { field: "payload.agent", type: "object", description: "\u5173\u8054\u7684 Agent \u5FEB\u7167\u4FE1\u606F" }
1464
+ ]
1465
+ };
1466
+ var statistics = {
1467
+ resource: "statistics",
1468
+ command: "monitor statistics",
1469
+ apiPath: "/v1/operation/customer-agents/statistics",
1470
+ description: "Agent \u8FD0\u8425\u7EDF\u8BA1\uFF0C\u542B\u4F1A\u8BDD\u91CF\u3001\u8F6C\u4EBA\u5DE5\u7387\u3001\u54CD\u5E94\u65F6\u95F4\u7B49\u6838\u5FC3\u6307\u6807",
1471
+ fields: [
1472
+ { field: "config_id", type: "string", description: "Agent \u914D\u7F6E ID" },
1473
+ { field: "config_name", type: "string", description: "Agent \u540D\u79F0" },
1474
+ { field: "workspace_id", type: "string", description: "\u5DE5\u4F5C\u7A7A\u95F4 ID" },
1475
+ { field: "workspace_name", type: "string", description: "\u5DE5\u4F5C\u7A7A\u95F4\u540D\u79F0" },
1476
+ { field: "total_conversations", type: "number", description: "\u65F6\u95F4\u8303\u56F4\u5185\u603B\u4F1A\u8BDD\u6570" },
1477
+ { field: "manual_takeover_conversations", type: "number", description: "\u8F6C\u4EBA\u5DE5\u4F1A\u8BDD\u6570" },
1478
+ { field: "manual_takeover_rate", type: "number", description: "\u8F6C\u4EBA\u5DE5\u7387\uFF080~1\uFF09" },
1479
+ { field: "avg_response_time", type: "number", description: "\u5E73\u5747\u54CD\u5E94\u65F6\u95F4\uFF08\u79D2\uFF09" },
1480
+ { field: "chat_record_count", type: "number", description: "\u804A\u5929\u8BB0\u5F55\u6570" },
1481
+ { field: "avg_conversation_rounds", type: "number", description: "\u5E73\u5747\u5BF9\u8BDD\u8F6E\u6B21" },
1482
+ { field: "issue_count", type: "number", description: "\u5DE5\u5355\u603B\u6570" },
1483
+ { field: "issue_resolved_count", type: "number", description: "\u5DF2\u89E3\u51B3\u5DE5\u5355\u6570" },
1484
+ { field: "issue_unresolved_count", type: "number", description: "\u672A\u89E3\u51B3\u5DE5\u5355\u6570" },
1485
+ { field: "exist_chat_history", type: "boolean", description: "\u662F\u5426\u6709\u804A\u5929\u8BB0\u5F55" },
1486
+ { field: "exist_product_deep", type: "boolean", description: "\u662F\u5426\u6709\u6DF1\u5EA6\u5B66\u4E60\u5546\u54C1" },
1487
+ { field: "exist_robot", type: "boolean", description: "\u662F\u5426\u914D\u7F6E\u4E86\u673A\u5668\u4EBA" },
1488
+ { field: "exist_running_robot", type: "boolean", description: "\u662F\u5426\u6709\u8FD0\u884C\u4E2D\u7684\u673A\u5668\u4EBA" },
1489
+ { field: "run_mode", type: "string", description: "\u8FD0\u884C\u6A21\u5F0F" },
1490
+ { field: "robot_stats.robot_count", type: "number", description: "\u673A\u5668\u4EBA\u603B\u6570" },
1491
+ { field: "robot_stats.running_count", type: "number", description: "\u8FD0\u884C\u4E2D\u673A\u5668\u4EBA\u6570" },
1492
+ { field: "robot_stats.robots", type: "array", description: "\u673A\u5668\u4EBA\u8BE6\u60C5\u5217\u8868" },
1493
+ { field: "icon", type: "string", description: "Agent \u56FE\u6807 URL" },
1494
+ { field: "created_at", type: "string", description: "\u521B\u5EFA\u65F6\u95F4" }
1495
+ ]
1496
+ };
1497
+ var hourly = {
1498
+ resource: "hourly",
1499
+ command: "monitor snapshots hourly",
1500
+ apiPath: "/v1/operation/snapshots/hourly",
1501
+ description: "\u5C0F\u65F6\u7EA7\u76D1\u63A7\u5FEB\u7167\uFF0C\u8BB0\u5F55\u6BCF\u5C0F\u65F6\u7684\u4F1A\u8BDD\u91CF\u3001\u8F6C\u4EBA\u5DE5\u3001\u9519\u8BEF\u7B49\u6307\u6807",
1502
+ fields: [
1503
+ { field: "workspace_id", type: "string", description: "\u5DE5\u4F5C\u7A7A\u95F4 ID" },
1504
+ { field: "agent_id", type: "string", description: "Agent ID" },
1505
+ { field: "hour_start", type: "string", description: "\u5C0F\u65F6\u8D77\u59CB\u65F6\u95F4\uFF08ISO\uFF09" },
1506
+ { field: "session_count", type: "number", description: "\u8BE5\u5C0F\u65F6\u4F1A\u8BDD\u6570" },
1507
+ { field: "active_user_count", type: "number|null", description: "\u6D3B\u8DC3\u7528\u6237\u6570" },
1508
+ { field: "agent_reply_count", type: "number", description: "Agent \u56DE\u590D\u6570" },
1509
+ { field: "transfer_to_human_count", type: "number", description: "\u8F6C\u4EBA\u5DE5\u6B21\u6570" },
1510
+ { field: "transfer_to_human_rate", type: "number", description: "\u8F6C\u4EBA\u5DE5\u7387\uFF080~1\uFF09" },
1511
+ { field: "fallback_count", type: "number|null", description: "\u515C\u5E95\u56DE\u590D\u6B21\u6570" },
1512
+ { field: "fallback_rate", type: "number|null", description: "\u515C\u5E95\u7387\uFF080~1\uFF09" },
1513
+ { field: "avg_turns", type: "number", description: "\u5E73\u5747\u5BF9\u8BDD\u8F6E\u6B21" },
1514
+ { field: "error_count", type: "number", description: "\u9519\u8BEF\u6B21\u6570" },
1515
+ { field: "avg_response_time_ms", type: "number", description: "\u5E73\u5747\u54CD\u5E94\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09" },
1516
+ { field: "timeout_count", type: "number", description: "\u8D85\u65F6\u6B21\u6570" },
1517
+ { field: "data_completeness", type: "number", description: "\u6570\u636E\u5B8C\u6574\u5EA6\uFF080~1\uFF09" }
1518
+ ]
1519
+ };
1520
+ var daily = {
1521
+ resource: "daily",
1522
+ command: "monitor snapshots daily",
1523
+ apiPath: "/v1/operation/snapshots/daily",
1524
+ description: "\u65E5\u7EA7\u76D1\u63A7\u5FEB\u7167\uFF0C\u805A\u5408\u6BCF\u65E5\u6307\u6807\u5E76\u8BA1\u7B97\u5065\u5EB7\u5206\u6570\u548C\u8D8B\u52BF",
1525
+ fields: [
1526
+ { field: "workspace_id", type: "string", description: "\u5DE5\u4F5C\u7A7A\u95F4 ID" },
1527
+ { field: "agent_id", type: "string", description: "Agent ID" },
1528
+ { field: "date", type: "string", description: "\u65E5\u671F\uFF08YYYY-MM-DD\uFF09" },
1529
+ { field: "daily_session_count", type: "number", description: "\u5F53\u65E5\u4F1A\u8BDD\u603B\u6570" },
1530
+ { field: "daily_active_users", type: "number|null", description: "\u5F53\u65E5\u6D3B\u8DC3\u7528\u6237\u6570" },
1531
+ { field: "daily_agent_reply_count", type: "number", description: "\u5F53\u65E5 Agent \u56DE\u590D\u6570" },
1532
+ { field: "daily_transfer_count", type: "number", description: "\u5F53\u65E5\u8F6C\u4EBA\u5DE5\u6B21\u6570" },
1533
+ { field: "daily_transfer_rate", type: "number", description: "\u5F53\u65E5\u8F6C\u4EBA\u5DE5\u7387\uFF080~1\uFF09" },
1534
+ { field: "daily_error_count", type: "number", description: "\u5F53\u65E5\u9519\u8BEF\u6B21\u6570" },
1535
+ { field: "daily_avg_turns", type: "number", description: "\u5F53\u65E5\u5E73\u5747\u5BF9\u8BDD\u8F6E\u6B21" },
1536
+ { field: "daily_avg_response_ms", type: "number", description: "\u5F53\u65E5\u5E73\u5747\u54CD\u5E94\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09" },
1537
+ { field: "daily_new_issue_count", type: "number|null", description: "\u5F53\u65E5\u65B0\u589E\u5DE5\u5355\u6570" },
1538
+ { field: "daily_resolved_issue_count", type: "number|null", description: "\u5F53\u65E5\u89E3\u51B3\u5DE5\u5355\u6570" },
1539
+ { field: "open_issue_count", type: "number|null", description: "\u5F53\u65E5\u672A\u5173\u95ED\u5DE5\u5355\u6570" },
1540
+ { field: "peak_hour_sessions", type: "number|null", description: "\u5CF0\u503C\u5C0F\u65F6\u4F1A\u8BDD\u6570" },
1541
+ { field: "zero_session_hours", type: "number|null", description: "\u96F6\u4F1A\u8BDD\u5C0F\u65F6\u6570" },
1542
+ { field: "consecutive_zero_days", type: "number|null", description: "\u8FDE\u7EED\u96F6\u4F1A\u8BDD\u5929\u6570" },
1543
+ { field: "daily_health_score", type: "number|null", description: "\u5F53\u65E5\u5065\u5EB7\u5206\u6570\uFF080~100\uFF09" },
1544
+ { field: "health_grade", type: "string|null", description: "\u5065\u5EB7\u7B49\u7EA7\uFF08A/B/C/D/F\uFF09" },
1545
+ { field: "health_analysis_summary", type: "string|null", description: "LLM \u751F\u6210\u7684\u5065\u5EB7\u5206\u6790\u6458\u8981" },
1546
+ { field: "session_change_vs_yesterday", type: "number|null", description: "\u4F1A\u8BDD\u91CF\u65E5\u73AF\u6BD4\u53D8\u5316\u7387" },
1547
+ { field: "transfer_rate_change_vs_yesterday", type: "number|null", description: "\u8F6C\u4EBA\u5DE5\u7387\u65E5\u73AF\u6BD4\u53D8\u5316\u7387" },
1548
+ { field: "session_change_vs_last_week", type: "number|null", description: "\u4F1A\u8BDD\u91CF\u5468\u73AF\u6BD4\u53D8\u5316\u7387" },
1549
+ { field: "transfer_rate_change_vs_last_week", type: "number|null", description: "\u8F6C\u4EBA\u5DE5\u7387\u5468\u73AF\u6BD4\u53D8\u5316\u7387" },
1550
+ { field: "session_ma7", type: "number|null", description: "7 \u65E5\u4F1A\u8BDD\u79FB\u52A8\u5E73\u5747" },
1551
+ { field: "session_ma30", type: "number|null", description: "30 \u65E5\u4F1A\u8BDD\u79FB\u52A8\u5E73\u5747" },
1552
+ { field: "trend_direction", type: "string|null", description: "\u8D8B\u52BF\u65B9\u5411\uFF08up/down/stable\uFF09" },
1553
+ { field: "data_quality_flag", type: "string", description: "\u6570\u636E\u8D28\u91CF\u6807\u8BB0" }
1554
+ ]
1555
+ };
1556
+ var workspaces = {
1557
+ resource: "workspaces",
1558
+ command: "monitor workspaces",
1559
+ apiPath: "/v1/operation/workspaces/list",
1560
+ description: "\u8FD0\u8425\u5DE5\u4F5C\u7A7A\u95F4\u5217\u8868\uFF0C\u542B\u5BA2\u6237\u4FE1\u606F\u3001\u5408\u540C\u72B6\u6001\u3001\u76D1\u63A7\u9608\u503C\u914D\u7F6E",
1561
+ fields: [
1562
+ { field: "workspace_id", type: "string", description: "\u5DE5\u4F5C\u7A7A\u95F4 ID" },
1563
+ { field: "workspace_name", type: "string", description: "\u5DE5\u4F5C\u7A7A\u95F4\u540D\u79F0" },
1564
+ { field: "user_id", type: "string", description: "\u7528\u6237 ID" },
1565
+ { field: "user_name", type: "string", description: "\u7528\u6237\u540D" },
1566
+ { field: "phone", type: "string", description: "\u624B\u673A\u53F7" },
1567
+ { field: "industry", type: "string", description: "\u884C\u4E1A" },
1568
+ { field: "shop_name", type: "string", description: "\u5E97\u94FA\u540D" },
1569
+ { field: "status", type: "string", description: "\u72B6\u6001" },
1570
+ { field: "account_id", type: "string", description: "\u8D26\u6237 ID" },
1571
+ { field: "account_type", type: "string", description: "\u8D26\u6237\u7C7B\u578B" },
1572
+ { field: "activate_time", type: "string", description: "\u6FC0\u6D3B\u65F6\u95F4" },
1573
+ { field: "expired_time", type: "string", description: "\u8FC7\u671F\u65F6\u95F4" },
1574
+ { field: "sales_channel", type: "string", description: "\u9500\u552E\u6E20\u9053" },
1575
+ { field: "agent_count", type: "number", description: "Agent \u6570\u91CF" },
1576
+ { field: "customer_agent_count", type: "number", description: "\u5BA2\u670D Agent \u6570\u91CF" },
1577
+ { field: "customer_name", type: "string|null", description: "\u5BA2\u6237\u540D\u79F0" },
1578
+ { field: "customer_level", type: "string|null", description: "\u5BA2\u6237\u7B49\u7EA7" },
1579
+ { field: "customer_description", type: "string|null", description: "\u5BA2\u6237\u63CF\u8FF0" },
1580
+ { field: "customer_detail", type: "string|null", description: "\u5BA2\u6237\u8BE6\u60C5" },
1581
+ { field: "customer_staff_count", type: "number|null", description: "\u5BA2\u6237\u5458\u5DE5\u6570" },
1582
+ { field: "customer_platforms", type: "array", description: "\u5BA2\u6237\u4F7F\u7528\u7684\u5E73\u53F0\u5217\u8868" },
1583
+ { field: "contract_status", type: "string|null", description: "\u5408\u540C\u72B6\u6001" },
1584
+ { field: "contract_sign_date", type: "string|null", description: "\u5408\u540C\u7B7E\u7EA6\u65E5\u671F" },
1585
+ { field: "contract_expire_time", type: "string|null", description: "\u5408\u540C\u5230\u671F\u65F6\u95F4" },
1586
+ { field: "contract_amount", type: "number|null", description: "\u5408\u540C\u91D1\u989D" },
1587
+ { field: "contract_renewal_risk", type: "string|null", description: "\u7EED\u7EA6\u98CE\u9669" },
1588
+ { field: "service_team_info", type: "object|null", description: "\u670D\u52A1\u56E2\u961F\u4FE1\u606F" },
1589
+ { field: "workspace_config.monitor_v6_thresholds.transfer_rate_warn", type: "number", description: "\u8F6C\u4EBA\u5DE5\u7387\u9884\u8B66\u9608\u503C\uFF080~1\uFF09" },
1590
+ { field: "workspace_config.monitor_v6_thresholds.transfer_rate_alert", type: "number", description: "\u8F6C\u4EBA\u5DE5\u7387\u544A\u8B66\u9608\u503C\uFF080~1\uFF09" },
1591
+ { field: "workspace_config.monitor_v6_thresholds.transfer_rate_trial_warn", type: "number", description: "\u8BD5\u7528\u671F\u8F6C\u4EBA\u5DE5\u7387\u9884\u8B66\u9608\u503C" },
1592
+ { field: "workspace_config.monitor_v6_thresholds.session_drop_warn", type: "number", description: "\u4F1A\u8BDD\u91CF\u4E0B\u964D\u9884\u8B66\u9608\u503C" },
1593
+ { field: "workspace_config.monitor_v6_thresholds.min_valid_sessions", type: "number", description: "\u6700\u5C0F\u6709\u6548\u4F1A\u8BDD\u6570\uFF08\u4F4E\u4E8E\u6B64\u503C\u4E0D\u89E6\u53D1\u89C4\u5219\uFF09" },
1594
+ { field: "workspace_config.monitor_v6_thresholds.zero_session_alert_days", type: "number", description: "\u96F6\u4F1A\u8BDD\u5929\u6570\u544A\u8B66\u9608\u503C" },
1595
+ { field: "workspace_config.monitor_v6_thresholds.no_session_alert_days", type: "number", description: "\u4ECE\u672A\u6709\u4F1A\u8BDD\u544A\u8B66\u5929\u6570" },
1596
+ { field: "workspace_config.monitor_v6_thresholds.issue_close_rate_warn", type: "number", description: "Issue \u5173\u95ED\u7387\u9884\u8B66\u9608\u503C" },
1597
+ { field: "workspace_config.monitor_v6_thresholds.auto_calibrate_enabled", type: "boolean", description: "\u662F\u5426\u5F00\u542F\u81EA\u52A8\u9608\u503C\u6821\u51C6" },
1598
+ { field: "workspace_config.monitor_v6_thresholds.config_source", type: "string", description: "\u9608\u503C\u6765\u6E90\uFF08default/industry/manual/auto\uFF09" }
1599
+ ]
1600
+ };
1601
+ var RESOURCE_DEFS = {
1602
+ agents,
1603
+ tickets,
1604
+ statistics,
1605
+ hourly,
1606
+ daily,
1607
+ workspaces
1608
+ };
1609
+ var RESOURCE_NAMES = Object.keys(RESOURCE_DEFS);
1610
+
1611
+ // src/commands/monitor.ts
1612
+ function registerMonitorCommand(program2) {
1613
+ const monitor = program2.command("monitor").description("\u8FD0\u8425\u76D1\u63A7\uFF08/v1/operation \u63A5\u53E3\uFF09");
1614
+ monitor.command("fields [resource]").description(`\u67E5\u770B\u63A5\u53E3\u8FD4\u56DE\u5B57\u6BB5\u542B\u4E49\uFF08\u53EF\u9009: ${RESOURCE_NAMES.join(", ")}\uFF09`).action((resource) => {
1615
+ if (!resource) {
1616
+ formatOutput({
1617
+ success: true,
1618
+ data: Object.values(RESOURCE_DEFS).map((r) => ({
1619
+ resource: r.resource,
1620
+ command: r.command,
1621
+ description: r.description,
1622
+ fieldCount: r.fields.length
1623
+ }))
1624
+ }, program2.opts().table);
1625
+ return;
1626
+ }
1627
+ const def = RESOURCE_DEFS[resource];
1628
+ if (!def) {
1629
+ outputError(1, `\u672A\u77E5\u8D44\u6E90: ${resource}\uFF0C\u53EF\u9009: ${RESOURCE_NAMES.join(", ")}`);
1630
+ process.exit(1);
1631
+ }
1632
+ formatOutput({ success: true, data: def }, program2.opts().table);
1633
+ });
1634
+ monitor.command("agents").description("Agent \u751F\u547D\u5468\u671F\u5217\u8868").option("--page <number>", "\u9875\u7801", "1").option("--page-size <number>", "\u6BCF\u9875\u6570\u91CF", "200").action(async (opts) => {
1635
+ try {
1636
+ const data = await listAgentLifecycle({
1637
+ page: Number(opts.page),
1638
+ pageSize: Number(opts.pageSize)
1639
+ });
1640
+ formatOutput({ success: true, data }, program2.opts().table);
1641
+ } catch (err) {
1642
+ outputError(err.statusCode ?? 1, err.message);
1643
+ process.exit(toExitCode(err));
1644
+ }
1645
+ });
1646
+ const tickets2 = monitor.command("tickets").description("\u76D1\u63A7\u5DE5\u5355");
1647
+ tickets2.command("list").description("\u5217\u51FA\u76D1\u63A7\u5DE5\u5355").option("--agent <config_id>", "Agent ID").option("--status <status>", "\u5DE5\u5355\u72B6\u6001").option("--severity <severity>", "\u4E25\u91CD\u7EA7\u522B: critical | high | medium | low").option("--page <number>", "\u9875\u7801", "1").option("--page-size <number>", "\u6BCF\u9875\u6570\u91CF", "200").action(async (opts) => {
1648
+ try {
1649
+ const data = await listTickets({
1650
+ agentId: opts.agent,
1651
+ status: opts.status,
1652
+ severity: opts.severity,
1653
+ page: Number(opts.page),
1654
+ pageSize: Number(opts.pageSize)
1655
+ });
1656
+ formatOutput({ success: true, data }, program2.opts().table);
1657
+ } catch (err) {
1658
+ outputError(err.statusCode ?? 1, err.message);
1659
+ process.exit(toExitCode(err));
1660
+ }
1661
+ });
1662
+ tickets2.command("delete <ticket_id>").description("\u5220\u9664\u76D1\u63A7\u5DE5\u5355").action(async (ticketId) => {
1663
+ try {
1664
+ const data = await deleteTicket(ticketId);
1665
+ formatOutput({ success: true, data }, program2.opts().table);
1666
+ } catch (err) {
1667
+ outputError(err.statusCode ?? 1, err.message);
1668
+ process.exit(toExitCode(err));
1669
+ }
1670
+ });
1671
+ const snapshots = monitor.command("snapshots").description("\u76D1\u63A7\u5FEB\u7167");
1672
+ snapshots.command("hourly").description("\u67E5\u8BE2\u5C0F\u65F6\u5FEB\u7167").option("--agent <config_id>", "Agent ID").option("--workspace-id <id>", "\u5DE5\u4F5C\u7A7A\u95F4 ID").option("--start <datetime>", "\u5F00\u59CB\u65F6\u95F4 (ISO)").option("--end <datetime>", "\u7ED3\u675F\u65F6\u95F4 (ISO)").option("--page <number>", "\u9875\u7801").option("--page-size <number>", "\u6BCF\u9875\u6570\u91CF").action(async (opts) => {
1673
+ try {
1674
+ const data = await listHourlySnapshots({
1675
+ agentId: opts.agent,
1676
+ workspaceId: opts.workspaceId,
1677
+ startTime: opts.start,
1678
+ endTime: opts.end,
1679
+ page: opts.page ? Number(opts.page) : void 0,
1680
+ pageSize: opts.pageSize ? Number(opts.pageSize) : void 0
1681
+ });
1682
+ formatOutput({ success: true, data }, program2.opts().table);
1683
+ } catch (err) {
1684
+ outputError(err.statusCode ?? 1, err.message);
1685
+ process.exit(toExitCode(err));
1686
+ }
1687
+ });
1688
+ snapshots.command("daily").description("\u67E5\u8BE2\u65E5\u5FEB\u7167").option("--agent <config_id>", "Agent ID").option("--workspace-id <id>", "\u5DE5\u4F5C\u7A7A\u95F4 ID").option("--start <date>", "\u5F00\u59CB\u65E5\u671F (YYYY-MM-DD)").option("--end <date>", "\u7ED3\u675F\u65E5\u671F (YYYY-MM-DD)").action(async (opts) => {
1689
+ try {
1690
+ const data = await listDailySnapshots({
1691
+ agentId: opts.agent,
1692
+ workspaceId: opts.workspaceId,
1693
+ startDate: opts.start,
1694
+ endDate: opts.end
1695
+ });
1696
+ formatOutput({ success: true, data }, program2.opts().table);
1697
+ } catch (err) {
1698
+ outputError(err.statusCode ?? 1, err.message);
1699
+ process.exit(toExitCode(err));
1700
+ }
1701
+ });
1702
+ snapshots.command("daily-range").description("\u67E5\u8BE2\u65E5\u5FEB\u7167\uFF08\u8303\u56F4\uFF0C\u542B\u8D8B\u52BF\uFF09").option("--agent <config_id>", "Agent ID").option("--workspace-id <id>", "\u5DE5\u4F5C\u7A7A\u95F4 ID").option("--start <date>", "\u5F00\u59CB\u65E5\u671F (YYYY-MM-DD)").option("--end <date>", "\u7ED3\u675F\u65E5\u671F (YYYY-MM-DD)").option("--page <number>", "\u9875\u7801").option("--page-size <number>", "\u6BCF\u9875\u6570\u91CF", "200").action(async (opts) => {
1703
+ try {
1704
+ const data = await listDailySnapshotsRange({
1705
+ agentId: opts.agent,
1706
+ workspaceId: opts.workspaceId,
1707
+ startDate: opts.start,
1708
+ endDate: opts.end,
1709
+ page: opts.page ? Number(opts.page) : void 0,
1710
+ pageSize: Number(opts.pageSize)
1711
+ });
1712
+ formatOutput({ success: true, data }, program2.opts().table);
1713
+ } catch (err) {
1714
+ outputError(err.statusCode ?? 1, err.message);
1715
+ process.exit(toExitCode(err));
1716
+ }
1717
+ });
1718
+ monitor.command("statistics").description("Agent \u8FD0\u8425\u7EDF\u8BA1").option("--start <date>", "\u5F00\u59CB\u65E5\u671F (ISO)").option("--end <date>", "\u7ED3\u675F\u65E5\u671F (ISO)").option("--page <number>", "\u9875\u7801", "1").option("--page-size <number>", "\u6BCF\u9875\u6570\u91CF", "100").action(async (opts) => {
1719
+ try {
1720
+ const data = await listAgentStatistics({
1721
+ startDate: opts.start,
1722
+ endDate: opts.end,
1723
+ page: Number(opts.page),
1724
+ pageSize: Number(opts.pageSize)
1725
+ });
1726
+ formatOutput({ success: true, data }, program2.opts().table);
1727
+ } catch (err) {
1728
+ outputError(err.statusCode ?? 1, err.message);
1729
+ process.exit(toExitCode(err));
1730
+ }
1731
+ });
1732
+ monitor.command("workspaces").description("\u8FD0\u8425\u5DE5\u4F5C\u7A7A\u95F4\u5217\u8868").option("--page <number>", "\u9875\u7801", "1").option("--page-size <number>", "\u6BCF\u9875\u6570\u91CF", "200").option("--has-agent", "\u4EC5\u663E\u793A\u6709 Agent \u7684\u5DE5\u4F5C\u7A7A\u95F4").action(async (opts) => {
1733
+ try {
1734
+ const data = await listOperationWorkspaces({
1735
+ page: Number(opts.page),
1736
+ pageSize: Number(opts.pageSize),
1737
+ hasAgent: opts.hasAgent ?? void 0
1738
+ });
1739
+ formatOutput({ success: true, data }, program2.opts().table);
1740
+ } catch (err) {
1741
+ outputError(err.statusCode ?? 1, err.message);
1742
+ process.exit(toExitCode(err));
1743
+ }
1744
+ });
1745
+ }
1746
+
1209
1747
  // src/bin.ts
1210
1748
  var program = new Command();
1211
1749
  program.name("cs-cli").description("AI \u5BA2\u670D CLI - Agent \u53CB\u597D").version("0.1.0").option("--table", "\u4EE5\u8868\u683C\u5F62\u5F0F\u8F93\u51FA\uFF08\u9ED8\u8BA4 JSON\uFF09", false).option("--workspace <id>", "\u8986\u76D6\u9ED8\u8BA4\u5DE5\u4F5C\u7A7A\u95F4 ID").option("--timeout <ms>", "\u8BF7\u6C42\u8D85\u65F6\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09", "20000");
@@ -1226,6 +1764,7 @@ registerChatHistoryCommand(program);
1226
1764
  registerFaqCommand(program);
1227
1765
  registerConversationCommand(program);
1228
1766
  registerDebugCommand(program);
1767
+ registerMonitorCommand(program);
1229
1768
  process.on("uncaughtException", (err) => {
1230
1769
  outputError(3, err.message);
1231
1770
  process.exit(3);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bty/customer-service-cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "AI Customer Service CLI - Agent friendly",
5
5
  "type": "module",
6
6
  "main": "./dist/bin.js",