@bty/customer-service-cli 0.2.1 → 0.3.1

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 +18 -7
  2. package/dist/bin.js +22 -11
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -26,13 +26,14 @@ pnpm build
26
26
  安装后即可使用,无需额外配置 API 地址。内置默认地址:
27
27
 
28
28
 
29
- | 服务 | 默认地址 |
30
- | ------ | --------------------------------------------- |
31
- | 客服 API | `https://customer-servhub-api.betteryeah.com` |
32
- | 认证 API | `https://ai-api.betteryeah.com` |
33
- | AI API | `https://ai-api.betteryeah.com` |
34
- | Langfuse | `http://192.168.40.10:3000` |
29
+ | 服务 | 默认地址 |
30
+ | -------------- | --------------------------------------------- |
31
+ | 客服 API | `https://customer-servhub-api.betteryeah.com` |
32
+ | AI API | `https://ai-api.betteryeah.com` |
33
+ | Customer Agent | `https://customer-agent.bantouyan.com` |
34
+ | Langfuse | `http://192.168.40.10:3000` |
35
35
 
36
+ > AI API 同时服务于登录认证(`auth login` / `auth whoami`),不再区分独立的 "认证 API" 字段。
36
37
 
37
38
  如需覆盖,可通过 `cs-cli config set` 修改:
38
39
 
@@ -40,6 +41,16 @@ pnpm build
40
41
  cs-cli config set --cs-api https://your-api.example.com
41
42
  ```
42
43
 
44
+ ### API 地址优先级
45
+
46
+ 每个 API 地址的读取顺序为 `环境变量 > config.json > 内置默认值`。环境变量为 `undefined` 或空字符串 `""` 都视为未设置,继续向下 fallback。
47
+
48
+ | 环境变量 | 覆盖字段 | 默认值 |
49
+ | ----------------------- | ------------------- | --------------------------------------------- |
50
+ | `CS_CS_API_URL` | `customerServiceApiUrl` | `https://customer-servhub-api.betteryeah.com` |
51
+ | `CS_AI_API_URL` | `aiApiUrl`(同时服务 auth 调用) | `https://ai-api.betteryeah.com` |
52
+ | `CS_CUSTOMER_AGENT_URL` | `customerAgentApiUrl` | `https://customer-agent.bantouyan.com` |
53
+
43
54
  ## 快速开始
44
55
 
45
56
  ```bash
@@ -157,7 +168,7 @@ cs-cli --workspace ws-other agent list # ❌ 报错:CS_WORKSPACE_ID 已被
157
168
 
158
169
  | 命令 | 说明 |
159
170
  | ----------------------------------------------------------- | ---------------------------- |
160
- | `config set --cs-api <url> --auth-api <url> --ai-api <url>` | 设置 API 地址 |
171
+ | `config set --cs-api <url> --ai-api <url>` | 设置 API 地址 |
161
172
  | `config get` | 查看当前配置(含全局和本地) |
162
173
  | `config init` | 在当前目录初始化本地配置 (`.cs-cli.json`) |
163
174
  | `config set-workspace <workspace_id> [--global]` | 设置默认工作空间 |
package/dist/bin.js CHANGED
@@ -12,6 +12,13 @@ function setRuntimeWorkspaceId(id) {
12
12
  function getRuntimeWorkspaceId() {
13
13
  return runtimeWorkspaceId;
14
14
  }
15
+ var runtimeRequestTimeoutMs;
16
+ function setRuntimeRequestTimeoutMs(ms) {
17
+ runtimeRequestTimeoutMs = ms;
18
+ }
19
+ function getRuntimeRequestTimeoutMs() {
20
+ return runtimeRequestTimeoutMs;
21
+ }
15
22
 
16
23
  // src/utils/output.ts
17
24
  import Table from "cli-table3";
@@ -308,7 +315,7 @@ function createRequest(globalTimeout) {
308
315
  const qs = params.toString();
309
316
  if (qs) url += `?${qs}`;
310
317
  }
311
- const timeout = options.timeout ?? globalTimeout ?? 2e4;
318
+ const timeout = options.timeout ?? globalTimeout ?? getRuntimeRequestTimeoutMs() ?? 6e4;
312
319
  const init = {
313
320
  method: options.method,
314
321
  headers,
@@ -428,25 +435,26 @@ function isTokenExpired(expiresAt) {
428
435
 
429
436
  // src/client/helpers.ts
430
437
  var DEFAULT_CS_API_URL = "https://customer-servhub-api.betteryeah.com";
431
- var DEFAULT_AUTH_API_URL = "https://ai-api.betteryeah.com";
432
438
  var DEFAULT_AI_API_URL = "https://ai-api.betteryeah.com";
433
439
  var DEFAULT_CUSTOMER_AGENT_API_URL = "https://customer-agent.bantouyan.com";
434
440
  var DEFAULT_LANGFUSE_HOST = "http://192.168.40.10:3000";
435
441
  var DEFAULT_LANGFUSE_PUBLIC_KEY = "pk-lf-1b3aece4-021a-4a81-be4a-abd6334c5929";
436
442
  var DEFAULT_LANGFUSE_SECRET_KEY = "sk-lf-edc22ac8-5d0a-4f72-b285-6556adfa8f71";
437
443
  function getCustomerServiceUrl() {
444
+ const envUrl = process.env.CS_CS_API_URL;
445
+ if (envUrl) return envUrl;
438
446
  const config = readConfig();
439
447
  return config?.customerServiceApiUrl ?? DEFAULT_CS_API_URL;
440
448
  }
441
- function getAuthUrl() {
442
- const config = readConfig();
443
- return config?.authApiUrl ?? DEFAULT_AUTH_API_URL;
444
- }
445
449
  function getAiApiUrl() {
450
+ const envUrl = process.env.CS_AI_API_URL;
451
+ if (envUrl) return envUrl;
446
452
  const config = readConfig();
447
453
  return config?.aiApiUrl ?? DEFAULT_AI_API_URL;
448
454
  }
449
455
  function getCustomerAgentUrl() {
456
+ const envUrl = process.env.CS_CUSTOMER_AGENT_URL;
457
+ if (envUrl) return envUrl;
450
458
  const config = readConfig();
451
459
  return config?.customerAgentApiUrl ?? DEFAULT_CUSTOMER_AGENT_API_URL;
452
460
  }
@@ -599,7 +607,7 @@ function encryptPassword(password) {
599
607
  return CryptoJS.enc.Base64.stringify(result);
600
608
  }
601
609
  async function login(phone, password) {
602
- const authApiUrl = getAuthUrl();
610
+ const authApiUrl = getAiApiUrl();
603
611
  const encryptedPassword = encryptPassword(password);
604
612
  const formData = new FormData();
605
613
  formData.append("phone", phone);
@@ -644,7 +652,7 @@ async function login(phone, password) {
644
652
  }
645
653
  async function whoami() {
646
654
  const request = createRequest();
647
- return request(getAuthUrl(), "/v1/users/me", { method: "GET" });
655
+ return request(getAiApiUrl(), "/v1/users/me", { method: "GET" });
648
656
  }
649
657
 
650
658
  // src/commands/auth.ts
@@ -731,10 +739,9 @@ function registerConfigCommand(program2) {
731
739
  const config = program2.command("config").description(
732
740
  "\u914D\u7F6E\u7BA1\u7406 \u2014\u2014 API \u5730\u5740\u3001\u9ED8\u8BA4\u5DE5\u4F5C\u7A7A\u95F4\u7B49\u6301\u4E45\u5316\u8BBE\u7F6E\u3002\u652F\u6301\u5168\u5C40\u914D\u7F6E\u548C\u76EE\u5F55\u7EA7\u672C\u5730\u914D\u7F6E\uFF08.cs-cli.json\uFF09"
733
741
  );
734
- config.command("set").description("\u8BBE\u7F6E API \u5730\u5740").option("--cs-api <url>", "\u5BA2\u670D API \u5730\u5740").option("--auth-api <url>", "\u8BA4\u8BC1 API \u5730\u5740").option("--ai-api <url>", "AI API \u5730\u5740").option("--agent-api <url>", "Customer Agent API \u5730\u5740").option("--langfuse-host <url>", "Langfuse \u5730\u5740").option("--langfuse-public-key <key>", "Langfuse Public Key").option("--langfuse-secret-key <key>", "Langfuse Secret Key").action((opts) => {
742
+ config.command("set").description("\u8BBE\u7F6E API \u5730\u5740").option("--cs-api <url>", "\u5BA2\u670D API \u5730\u5740").option("--ai-api <url>", "AI API \u5730\u5740").option("--agent-api <url>", "Customer Agent API \u5730\u5740").option("--langfuse-host <url>", "Langfuse \u5730\u5740").option("--langfuse-public-key <key>", "Langfuse Public Key").option("--langfuse-secret-key <key>", "Langfuse Secret Key").action((opts) => {
735
743
  const updates = {};
736
744
  if (opts.csApi) updates.customerServiceApiUrl = opts.csApi;
737
- if (opts.authApi) updates.authApiUrl = opts.authApi;
738
745
  if (opts.aiApi) updates.aiApiUrl = opts.aiApi;
739
746
  if (opts.agentApi) updates.customerAgentApiUrl = opts.agentApi;
740
747
  if (opts.langfuseHost) updates.langfuseHost = opts.langfuseHost;
@@ -3078,12 +3085,16 @@ var { version } = require2("../package.json");
3078
3085
  var program = new Command();
3079
3086
  program.name("cs-cli").description(
3080
3087
  "BetterYeah AI \u5BA2\u670D\u5E73\u53F0 CLI\u3002\u6838\u5FC3\u6982\u5FF5\uFF1Aworkspace\uFF08\u5DE5\u4F5C\u7A7A\u95F4\uFF09\u2192 agent\uFF08AI \u5BA2\u670D\u673A\u5668\u4EBA\uFF09\u2192 SA/product/FAQ\uFF08\u77E5\u8BC6\u914D\u7F6E\uFF09\u2192 issue\uFF08\u5DE5\u5355\uFF09\u2192 debug\uFF08\u8C03\u8BD5\u9A8C\u8BC1\uFF09\u2192 monitor\uFF08\u8FD0\u8425\u76D1\u63A7\uFF09\u2192 repair-record\uFF08\u4FEE\u590D\u5BA1\u8BA1\uFF09\u3002\u6240\u6709\u547D\u4EE4\u9ED8\u8BA4\u8F93\u51FA JSON\uFF0C\u8FFD\u52A0 --table \u53EF\u5207\u6362\u4E3A\u4EBA\u7C7B\u53EF\u8BFB\u8868\u683C"
3081
- ).version(version).option("--table", "\u4EE5\u8868\u683C\u5F62\u5F0F\u8F93\u51FA\uFF08\u9ED8\u8BA4 JSON\uFF09\u3002\u4EBA\u5DE5\u67E5\u770B\u65F6\u4F7F\u7528", false).option("--workspace <id>", "\u4E34\u65F6\u8986\u76D6\u9ED8\u8BA4\u5DE5\u4F5C\u7A7A\u95F4 ID\uFF0C\u4E0D\u4FEE\u6539\u6301\u4E45\u5316\u914D\u7F6E").option("--timeout <ms>", "\u8BF7\u6C42\u8D85\u65F6\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09\uFF0C\u590D\u6742 Agent \u56DE\u590D\u5EFA\u8BAE\u8C03\u9AD8", "20000");
3088
+ ).version(version).option("--table", "\u4EE5\u8868\u683C\u5F62\u5F0F\u8F93\u51FA\uFF08\u9ED8\u8BA4 JSON\uFF09\u3002\u4EBA\u5DE5\u67E5\u770B\u65F6\u4F7F\u7528", false).option("--workspace <id>", "\u4E34\u65F6\u8986\u76D6\u9ED8\u8BA4\u5DE5\u4F5C\u7A7A\u95F4 ID\uFF0C\u4E0D\u4FEE\u6539\u6301\u4E45\u5316\u914D\u7F6E").option("--timeout <ms>", "\u8BF7\u6C42\u8D85\u65F6\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09\uFF0C\u590D\u6742 Agent \u56DE\u590D\u5EFA\u8BAE\u8C03\u9AD8", "60000");
3082
3089
  program.hook("preAction", (thisCommand) => {
3083
3090
  const opts = thisCommand.opts();
3084
3091
  if (opts.workspace) {
3085
3092
  setRuntimeWorkspaceId(opts.workspace);
3086
3093
  }
3094
+ const timeoutMs = Number(opts.timeout);
3095
+ if (Number.isFinite(timeoutMs) && timeoutMs > 0) {
3096
+ setRuntimeRequestTimeoutMs(timeoutMs);
3097
+ }
3087
3098
  });
3088
3099
  program.hook("postAction", async () => {
3089
3100
  const message = await checkForUpdate(version);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bty/customer-service-cli",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "description": "AI Customer Service CLI - Agent friendly",
5
5
  "type": "module",
6
6
  "main": "./dist/bin.js",