@bty/customer-service-cli 0.1.24 → 0.1.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/bin.js +70 -14
  2. package/package.json +1 -1
package/dist/bin.js CHANGED
@@ -1373,6 +1373,7 @@ function registerConversationCommand(program2) {
1373
1373
  }
1374
1374
 
1375
1375
  // src/client/debug-api.ts
1376
+ var DEFAULT_FLOW_WORKSPACE_ID = "531c14d1ece047cbaec22914e1f1364d";
1376
1377
  async function createDebugConversation(opts) {
1377
1378
  const request = createRequest();
1378
1379
  return request(getCustomerServiceUrl(), "/v1/chat/conversation", {
@@ -1462,20 +1463,10 @@ function recordsToMsgList(records) {
1462
1463
  const offset = nowSec - maxOriginal;
1463
1464
  return records.map((r, i) => {
1464
1465
  const context = r.context ?? {};
1465
- const text = context.text ?? "";
1466
- const imageUrl = context.image_url ?? context.image;
1467
- const url = context.url;
1468
1466
  const content = {
1469
- text,
1470
- input: text,
1471
- email: `${r.conversation_id}@gmail.com`
1467
+ ...context,
1468
+ email: context.email || `${r.conversation_id}@gmail.com`
1472
1469
  };
1473
- if (url) {
1474
- content.url = url;
1475
- }
1476
- if (imageUrl) {
1477
- content.image = imageUrl;
1478
- }
1479
1470
  const timestamp = originalTimestamps[i] + offset;
1480
1471
  return {
1481
1472
  match_id: r.record_id ?? `match_${timestamp}_${Math.floor(Math.random() * 100)}`,
@@ -1494,6 +1485,42 @@ async function getRecordDebugInfo(recordId) {
1494
1485
  const flowInfo = data.flow_infos?.[0] ?? null;
1495
1486
  return { record_id: data.record_id, flow_info: flowInfo, transfer_to_human: data.transfer_to_human, trace_id: flowInfo?.trace_id };
1496
1487
  }
1488
+ async function getFlowExecuteLog(opts) {
1489
+ const creds = readCredentials();
1490
+ if (!creds) throw new APIError(2, "\u672A\u767B\u5F55\uFF0C\u8BF7\u8FD0\u884C: cs-cli auth login");
1491
+ const workspaceId = opts.workspaceId ?? DEFAULT_FLOW_WORKSPACE_ID;
1492
+ const url = `${getAiApiUrl()}/v1/flow/execute_log/${opts.flowId}/${opts.taskId}`;
1493
+ const res = await fetch(url, {
1494
+ method: "GET",
1495
+ headers: {
1496
+ "Authorization": `Bearer ${creds.accessToken}`,
1497
+ "application-id": opts.flowId,
1498
+ "workspace-id": workspaceId,
1499
+ "Content-Type": "application/json",
1500
+ "Origin": "BetterYeah AI"
1501
+ }
1502
+ });
1503
+ if (!res.ok) {
1504
+ const text = await res.text().catch(() => "");
1505
+ throw new APIError(res.status, `flow execute_log API error ${res.status}: ${text}`);
1506
+ }
1507
+ const json = await res.json();
1508
+ if (json.code != null && json.code !== 200 && json.code !== 0) {
1509
+ throw new APIError(json.code, json.message ?? `Business error: ${json.code}`);
1510
+ }
1511
+ const executeLog = json.data ?? json;
1512
+ const logUrl = executeLog?.log_url;
1513
+ if (!logUrl || typeof logUrl !== "string") {
1514
+ throw new APIError(1, "execute_log \u54CD\u5E94\u4E2D\u672A\u627E\u5230 log_url");
1515
+ }
1516
+ const logRes = await fetch(logUrl, { method: "GET" });
1517
+ if (!logRes.ok) {
1518
+ const text = await logRes.text().catch(() => "");
1519
+ throw new APIError(logRes.status, `log_url fetch \u5931\u8D25 ${logRes.status}: ${text}`);
1520
+ }
1521
+ const log = await logRes.json();
1522
+ return { executeLog, log };
1523
+ }
1497
1524
  async function getLangfuseTrace(traceId) {
1498
1525
  const { host, publicKey, secretKey } = getLangfuseConfig();
1499
1526
  const url = `${host}/api/public/traces/${traceId}`;
@@ -1573,10 +1600,39 @@ function registerDebugCommand(program2) {
1573
1600
  process.exit(toExitCode(error));
1574
1601
  }
1575
1602
  });
1576
- debug.command("record").description("\u83B7\u53D6\u67D0\u6761\u56DE\u590D\u7684\u5185\u90E8\u63A8\u7406\u94FE\u8DEF\uFF08flow_info\uFF09\uFF0C\u7528\u4E8E\u8BCA\u65AD Agent \u4E3A\u4F55\u7ED9\u51FA\u7279\u5B9A\u56DE\u590D").argument("<record_id>", "\u56DE\u590D\u8BB0\u5F55 ID\uFF08\u4ECE debug ask \u8FD4\u56DE\u7684 reply[].record_id \u83B7\u53D6\uFF09").action(async (recordId) => {
1603
+ debug.command("record").description("\u83B7\u53D6\u67D0\u6761\u56DE\u590D\u7684\u5185\u90E8\u63A8\u7406\u94FE\u8DEF\uFF08flow_info\uFF09\uFF0C\u7528\u4E8E\u8BCA\u65AD Agent \u4E3A\u4F55\u7ED9\u51FA\u7279\u5B9A\u56DE\u590D").argument("<record_id>", "\u56DE\u590D\u8BB0\u5F55 ID\uFF08\u4ECE debug ask \u8FD4\u56DE\u7684 reply[].record_id \u83B7\u53D6\uFF09").option(
1604
+ "--deep",
1605
+ "\u6DF1\u5EA6\u89E3\u6790\uFF1A\u989D\u5916\u8C03\u7528 ai-api \u7684 flow execute_log \u63A5\u53E3\uFF0C\u62C9\u53D6 flow_info.flow_id + task_id \u5BF9\u5E94\u7684\u5B8C\u6574\u6267\u884C\u65E5\u5FD7\uFF08log_url \u5185\u5BB9\uFF09\uFF0C\u7528\u4E8E\u6392\u67E5\u8282\u70B9\u7EA7\u8F93\u5165\u8F93\u51FA",
1606
+ false
1607
+ ).option(
1608
+ "--flow-workspace <id>",
1609
+ "flow \u6240\u5728 workspace ID\uFF08--deep \u65F6\u4F7F\u7528\uFF0C\u9ED8\u8BA4\u4F7F\u7528\u5185\u7F6E\u56FA\u5B9A\u503C\uFF09"
1610
+ ).action(async (recordId, opts) => {
1577
1611
  try {
1578
1612
  const data = await getRecordDebugInfo(recordId);
1579
- formatOutput({ success: true, data }, program2.opts().table);
1613
+ let deep;
1614
+ if (opts.deep) {
1615
+ const flowInfo = data.flow_info;
1616
+ const flowId = flowInfo?.flow_id;
1617
+ const taskId = flowInfo?.task_id;
1618
+ if (!flowId || !taskId) {
1619
+ deep = { error: "flow_info \u4E2D\u7F3A\u5C11 flow_id \u6216 task_id\uFF0C\u65E0\u6CD5\u6DF1\u5EA6\u89E3\u6790" };
1620
+ } else {
1621
+ try {
1622
+ deep = await getFlowExecuteLog({
1623
+ flowId,
1624
+ taskId,
1625
+ workspaceId: opts.flowWorkspace
1626
+ });
1627
+ } catch (err) {
1628
+ deep = { error: err.message };
1629
+ }
1630
+ }
1631
+ }
1632
+ formatOutput(
1633
+ { success: true, data: opts.deep ? { ...data, deep } : data },
1634
+ program2.opts().table
1635
+ );
1580
1636
  } catch (error) {
1581
1637
  outputError(error.statusCode ?? 1, error.message);
1582
1638
  process.exit(toExitCode(error));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bty/customer-service-cli",
3
- "version": "0.1.24",
3
+ "version": "0.1.26",
4
4
  "description": "AI Customer Service CLI - Agent friendly",
5
5
  "type": "module",
6
6
  "main": "./dist/bin.js",