@optima-chat/browser-cli 0.10.0 → 0.10.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 (2) hide show
  1. package/dist/index.js +26 -17
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -22,24 +22,33 @@ var ENV_CONFIG = {
22
22
  // alicloud/stacks/cn-prod-ingress-sae/main.tf 的 yzsgo_sub=browser-api)。
23
23
  "cn-prod": {
24
24
  apiUrl: "https://browser-api.yzsgo.com"
25
+ },
26
+ // 阿里云 cn-stage 预发(独立于 AWS stage 的 .optima.onl;权威映射见 optima-terraform
27
+ // alicloud/stacks/cn-stage-ingress-sae/main.tf:browser-backend → sub=browser-api,
28
+ // 通配证书 *.stage.optima.chat 覆盖)。
29
+ // 漏这一档的后果:cn-stage 容器 OPTIMA_ENV=cn-stage → agent-runtime 写
30
+ // token.json.env="cn-stage" → 下面 fail-loud 抛 Unknown environment,而那句 throw
31
+ // 在模块加载期就执行,browser-cli 在任何子命令跑起来之前直接死掉。
32
+ // optima-scout 撞过同一个 bug(optima-gateway#1384 P0-2)。
33
+ "cn-stage": {
34
+ apiUrl: "https://browser-api.stage.optima.chat"
25
35
  }
26
36
  };
37
+ function isBrowserEnv(value) {
38
+ return Object.prototype.hasOwnProperty.call(ENV_CONFIG, value);
39
+ }
40
+ var TOKEN_ENV_MAP = {
41
+ prod: "production",
42
+ production: "production",
43
+ stage: "stage",
44
+ ci: "development",
45
+ development: "development",
46
+ "cn-prod": "cn-prod",
47
+ "cn-stage": "cn-stage"
48
+ };
27
49
  var OPTIMA_TOKEN_FILE = join(homedir(), ".optima", "token.json");
28
50
  function tokenEnvToBrowserEnv(tokenEnv) {
29
- switch (tokenEnv) {
30
- case "prod":
31
- case "production":
32
- return "production";
33
- case "stage":
34
- return "stage";
35
- case "ci":
36
- case "development":
37
- return "development";
38
- case "cn-prod":
39
- return "cn-prod";
40
- default:
41
- return null;
42
- }
51
+ return Object.prototype.hasOwnProperty.call(TOKEN_ENV_MAP, tokenEnv) ? TOKEN_ENV_MAP[tokenEnv] : null;
43
52
  }
44
53
  function readOptimaToken() {
45
54
  if (!existsSync(OPTIMA_TOKEN_FILE)) return null;
@@ -51,11 +60,11 @@ function readOptimaToken() {
51
60
  }
52
61
  function getCurrentEnv() {
53
62
  const browserEnv = process.env.BROWSER_ENV;
54
- if (browserEnv && ["production", "stage", "development", "cn-prod"].includes(browserEnv)) {
63
+ if (browserEnv && isBrowserEnv(browserEnv)) {
55
64
  return browserEnv;
56
65
  }
57
66
  const optimaEnv = process.env.OPTIMA_ENV;
58
- if (optimaEnv && ["production", "stage", "development", "cn-prod"].includes(optimaEnv)) {
67
+ if (optimaEnv && isBrowserEnv(optimaEnv)) {
59
68
  return optimaEnv;
60
69
  }
61
70
  const optimaToken = readOptimaToken();
@@ -63,7 +72,7 @@ function getCurrentEnv() {
63
72
  const mapped = tokenEnvToBrowserEnv(optimaToken.env);
64
73
  if (mapped) return mapped;
65
74
  throw new Error(
66
- `Unknown environment "${optimaToken.env}" in ~/.optima/token.json. Known environments: prod, stage, ci, cn-prod. Upgrade browser-cli to a version that knows this environment, or set BROWSER_API_URL to override the endpoint explicitly.`
75
+ `Unknown environment "${optimaToken.env}" in ~/.optima/token.json. Known environments: ${Object.keys(TOKEN_ENV_MAP).join(", ")}. Upgrade browser-cli to a version that knows this environment, or set BROWSER_API_URL to override the endpoint explicitly.`
67
76
  );
68
77
  }
69
78
  return "development";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optima-chat/browser-cli",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "bin": {