@optima-chat/browser-cli 0.9.1 → 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.
- package/dist/index.js +46 -17
- 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
|
-
|
|
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 &&
|
|
63
|
+
if (browserEnv && isBrowserEnv(browserEnv)) {
|
|
55
64
|
return browserEnv;
|
|
56
65
|
}
|
|
57
66
|
const optimaEnv = process.env.OPTIMA_ENV;
|
|
58
|
-
if (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:
|
|
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";
|
|
@@ -346,6 +355,12 @@ var BrowserAPI = class {
|
|
|
346
355
|
async getScriptTask(taskId) {
|
|
347
356
|
return request(`/api/script-tasks/${taskId}`);
|
|
348
357
|
}
|
|
358
|
+
async sendFile(src, dest) {
|
|
359
|
+
return request("/api/files/send", {
|
|
360
|
+
method: "POST",
|
|
361
|
+
body: JSON.stringify({ src, dest })
|
|
362
|
+
});
|
|
363
|
+
}
|
|
349
364
|
};
|
|
350
365
|
var api = new BrowserAPI();
|
|
351
366
|
|
|
@@ -1098,6 +1113,19 @@ function registerBitBrowserCommands(program2) {
|
|
|
1098
1113
|
});
|
|
1099
1114
|
}
|
|
1100
1115
|
|
|
1116
|
+
// src/commands/files.ts
|
|
1117
|
+
function registerFileCommands(program2) {
|
|
1118
|
+
program2.command("send-file").description("Send a file from your workspace to your local download folder").requiredOption("--src <path>", "Source path in your workspace (e.g. ~/output/report.pdf)").requiredOption("--dest <path>", "Destination path relative to the download folder").action(async (opts) => {
|
|
1119
|
+
try {
|
|
1120
|
+
const result = await api.sendFile(opts.src, opts.dest);
|
|
1121
|
+
console.log(result.local_path);
|
|
1122
|
+
} catch (err) {
|
|
1123
|
+
console.error(formatError(err));
|
|
1124
|
+
process.exit(1);
|
|
1125
|
+
}
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1101
1129
|
// src/index.ts
|
|
1102
1130
|
var require2 = createRequire(import.meta.url);
|
|
1103
1131
|
var { version } = require2("../package.json");
|
|
@@ -1118,4 +1146,5 @@ registerScriptCommands(program);
|
|
|
1118
1146
|
registerZiNiaoCommands(program);
|
|
1119
1147
|
registerRecipeCommands(program);
|
|
1120
1148
|
registerBitBrowserCommands(program);
|
|
1149
|
+
registerFileCommands(program);
|
|
1121
1150
|
program.parse();
|