@optima-chat/browser-cli 0.14.0 → 0.15.0

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 +51 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -183,11 +183,12 @@ async function requestBinary(path) {
183
183
  return Buffer.from(arrayBuffer);
184
184
  }
185
185
  var BrowserAPI = class {
186
- async createSession(url, force, connector, ziniaoProfileId, bitbrowserProfileId, feikuaProfileId) {
186
+ async createSession(url, force, connector, ziniaoProfileId, bitbrowserProfileId, feikuaProfileId, chromeProfile) {
187
187
  const body = {};
188
188
  if (url) body.url = url;
189
189
  if (force) body.force = true;
190
190
  if (connector) body.connector = connector;
191
+ if (chromeProfile) body.chrome_profile = chromeProfile;
191
192
  if (ziniaoProfileId) body.ziniao_profile_id = ziniaoProfileId;
192
193
  if (bitbrowserProfileId) body.bitbrowser_profile_id = bitbrowserProfileId;
193
194
  if (feikuaProfileId) body.feikua_profile_id = feikuaProfileId;
@@ -211,6 +212,10 @@ var BrowserAPI = class {
211
212
  async getZiNiaoProfiles() {
212
213
  return request("/api/user/ziniao-profiles");
213
214
  }
215
+ // logged_in 缺席 = 没探(未开 check、无 homeUrl 或探测失败),下游按未知处理,别当 false。
216
+ async getChromeProfiles(check) {
217
+ return request(`/api/user/chrome-profiles${check ? "?check=true" : ""}`);
218
+ }
214
219
  async getBitBrowserProfiles() {
215
220
  return request("/api/user/bitbrowser-profiles");
216
221
  }
@@ -370,9 +375,10 @@ var BrowserAPI = class {
370
375
  async deleteScript(name) {
371
376
  await request(`/api/scripts/${encodeURIComponent(name)}`, { method: "DELETE" });
372
377
  }
373
- async runScript(scriptName, params = {}, connector, ziniaoProfileId, bitbrowserProfileId, feikuaProfileId) {
378
+ async runScript(scriptName, params = {}, connector, ziniaoProfileId, bitbrowserProfileId, feikuaProfileId, chromeProfile) {
374
379
  const payload = { params };
375
380
  if (connector) payload.connector = connector;
381
+ if (chromeProfile) payload.chrome_profile = chromeProfile;
376
382
  if (ziniaoProfileId) payload.ziniao_profile_id = ziniaoProfileId;
377
383
  if (bitbrowserProfileId) payload.bitbrowser_profile_id = bitbrowserProfileId;
378
384
  if (feikuaProfileId) payload.feikua_profile_id = feikuaProfileId;
@@ -515,9 +521,9 @@ function formatTabsInline(tabs) {
515
521
 
516
522
  // src/commands/lifecycle.ts
517
523
  function registerLifecycleCommands(program2) {
518
- program2.command("launch").description("Launch a browser session").option("--url <url>", "Navigate to URL after launch").option("--force", "Close existing session before launching").option("--connector <type>", "Browser connector: chrome, ziniao, bitbrowser, or feikua").option("--ziniao-profile <id>", "ZiNiao browser profile ID").option("--bitbrowser-profile <id>", "BitBrowser profile ID").option("--feikua-profile <id>", "Feikua (\u98DE\u8DE8) shop browser instance ID").action(async (opts) => {
524
+ program2.command("launch").description("Launch a browser session").option("--url <url>", "Navigate to URL after launch").option("--force", "Close existing session before launching").option("--connector <type>", "Browser connector: chrome, ziniao, bitbrowser, or feikua").option("--ziniao-profile <id>", "ZiNiao browser profile ID").option("--bitbrowser-profile <id>", "BitBrowser profile ID").option("--feikua-profile <id>", "Feikua (\u98DE\u8DE8) shop browser instance ID").option("--chrome-profile <name>", "Chrome named profile (per-store login state; default: shared profile)").action(async (opts) => {
519
525
  try {
520
- const state = await api.createSession(opts.url, opts.force, opts.connector, opts.ziniaoProfile, opts.bitbrowserProfile, opts.feikuaProfile);
526
+ const state = await api.createSession(opts.url, opts.force, opts.connector, opts.ziniaoProfile, opts.bitbrowserProfile, opts.feikuaProfile, opts.chromeProfile);
521
527
  saveSessionId(state.session_id);
522
528
  console.log(formatLaunch(state));
523
529
  } catch (err) {
@@ -881,7 +887,7 @@ function registerScriptCommands(program2) {
881
887
  process.exit(1);
882
888
  }
883
889
  });
884
- program2.command("runscript").argument("<name>", "Script name").description("Run a script (polls until complete)").option("--param <params...>", "Parameters as key=value").option("--connector <type>", "Browser connector: chrome, ziniao, bitbrowser, or feikua").option("--ziniao-profile <id>", "ZiNiao browser profile ID (with --connector ziniao)").option("--bitbrowser-profile <id>", "BitBrowser profile ID (with --connector bitbrowser)").option("--feikua-profile <id>", "Feikua (\u98DE\u8DE8) shop browser instance ID (with --connector feikua)").option("--out <path>", "Where to write the script's exported file (default: ./<filename>)").option("--no-poll", "Return immediately without polling").action(async (name, opts) => {
890
+ program2.command("runscript").argument("<name>", "Script name").description("Run a script (polls until complete)").option("--param <params...>", "Parameters as key=value").option("--connector <type>", "Browser connector: chrome, ziniao, bitbrowser, or feikua").option("--ziniao-profile <id>", "ZiNiao browser profile ID (with --connector ziniao)").option("--bitbrowser-profile <id>", "BitBrowser profile ID (with --connector bitbrowser)").option("--feikua-profile <id>", "Feikua (\u98DE\u8DE8) shop browser instance ID (with --connector feikua)").option("--chrome-profile <name>", "Chrome named profile (per-store login state, with --connector chrome)").option("--out <path>", "Where to write the script's exported file (default: ./<filename>)").option("--no-poll", "Return immediately without polling").action(async (name, opts) => {
885
891
  try {
886
892
  const params = {};
887
893
  if (opts.param) {
@@ -891,7 +897,7 @@ function registerScriptCommands(program2) {
891
897
  }
892
898
  }
893
899
  if (opts.out) params.out_path = resolve(opts.out);
894
- const task = await api.runScript(name, params, opts.connector, opts.ziniaoProfile, opts.bitbrowserProfile, opts.feikuaProfile);
900
+ const task = await api.runScript(name, params, opts.connector, opts.ziniaoProfile, opts.bitbrowserProfile, opts.feikuaProfile, opts.chromeProfile);
895
901
  console.log(`Script started (task: ${task.id})`);
896
902
  if (!opts.poll) {
897
903
  console.log(`Poll with: browser-cli script-task ${task.id}`);
@@ -1116,6 +1122,44 @@ function registerZiNiaoCommands(program2) {
1116
1122
  });
1117
1123
  }
1118
1124
 
1125
+ // src/commands/chrome.ts
1126
+ function registerChromeCommands(program2) {
1127
+ const chrome = program2.command("chrome").description("Manage Chrome named profiles (per-store login state)");
1128
+ chrome.command("profiles").description("List Chrome named profiles (requires Desktop app online)").option("--check", "Probe login state for profiles with a homeUrl (opens a headed Chrome per profile, ~10s each)").action(async (opts) => {
1129
+ try {
1130
+ const result = await api.getChromeProfiles(opts.check);
1131
+ if (!result.connected) {
1132
+ console.log(formatDesktopNotConnected(result));
1133
+ process.exit(1);
1134
+ }
1135
+ console.log(`Chrome profiles (${result.profiles.length}):
1136
+ `);
1137
+ for (const p of result.profiles) {
1138
+ const label = p.name === "default" ? "\u5171\u4EAB\u9ED8\u8BA4" : p.label ?? "-";
1139
+ const login = p.logged_in === void 0 ? "-" : p.logged_in ? "\u2705" : "\u274C \u9700\u4EBA\u5DE5\u91CD\u767B";
1140
+ const home = p.homeUrl ? ` ${p.homeUrl}` : "";
1141
+ console.log(` ${p.name.padEnd(12)} ${label.padEnd(18)} running: ${p.running ? "yes" : "no"} logged_in: ${login}${home}`);
1142
+ }
1143
+ console.log("\nUse: browser-cli launch --connector chrome --chrome-profile <name> --url <url>");
1144
+ if (!opts.check) console.log("Add --check to probe login state (profiles with a homeUrl only).");
1145
+ } catch (err) {
1146
+ console.error(formatError(err));
1147
+ process.exit(1);
1148
+ }
1149
+ });
1150
+ chrome.command("open").description("Open a named profile's headed Chrome for manual login (the official login entry)").requiredOption("--profile <name>", "Chrome named profile to open (created on first use)").option("--url <url>", "Page to open, e.g. the seller center login page").action(async (opts) => {
1151
+ try {
1152
+ const state = await api.createSession(opts.url, false, "chrome", void 0, void 0, void 0, opts.profile);
1153
+ saveSessionId(state.session_id);
1154
+ console.log(`\u2713 Opened Chrome profile "${opts.profile}"${opts.url ? ` at ${opts.url}` : ""} (session: ${state.session_id})`);
1155
+ console.log("\u5728\u5F39\u51FA\u7684 Chrome \u7A97\u53E3\u91CC\u5B8C\u6210\u767B\u5F55;\u767B\u5F55\u6001\u4F1A\u7559\u5728\u8BE5 profile,\u4E4B\u540E\u5E26 --chrome-profile \u7684\u8C03\u7528\u76F4\u63A5\u590D\u7528\u3002");
1156
+ } catch (err) {
1157
+ console.error(formatError(err));
1158
+ process.exit(1);
1159
+ }
1160
+ });
1161
+ }
1162
+
1119
1163
  // src/commands/recipes.ts
1120
1164
  import { writeFileSync as writeFileSync4 } from "fs";
1121
1165
  import { resolve as resolve2 } from "path";
@@ -1339,6 +1383,7 @@ registerInfoCommands(program);
1339
1383
  registerTabCommands(program);
1340
1384
  registerScriptCommands(program);
1341
1385
  registerZiNiaoCommands(program);
1386
+ registerChromeCommands(program);
1342
1387
  registerRecipeCommands(program);
1343
1388
  registerBitBrowserCommands(program);
1344
1389
  registerFeikuaCommands(program);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optima-chat/browser-cli",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "bin": {