dsclaw 0.1.6 → 0.1.8

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/cli/index.js CHANGED
@@ -30,14 +30,15 @@ import pino from "pino";
30
30
  function createLogger(module) {
31
31
  return rootLogger.child({ module });
32
32
  }
33
- var rootLogger;
33
+ var isPkg, rootLogger;
34
34
  var init_logger = __esm({
35
35
  "src/shared/logger.ts"() {
36
36
  "use strict";
37
37
  init_tracer();
38
+ isPkg = typeof process.pkg !== "undefined";
38
39
  rootLogger = pino({
39
40
  level: process.env["LOG_LEVEL"] ?? "info",
40
- transport: process.env["NODE_ENV"] !== "production" ? { target: "pino-pretty", options: { colorize: true } } : void 0,
41
+ transport: !isPkg && process.env["NODE_ENV"] !== "production" ? { target: "pino-pretty", options: { colorize: true } } : void 0,
41
42
  mixin() {
42
43
  const ctx = getTraceContext();
43
44
  return {
@@ -774,18 +775,20 @@ var CANDIDATES = [
774
775
  }
775
776
  }
776
777
  ];
777
- function findChromium() {
778
+ function findAllChromium() {
778
779
  const platform = process.platform;
780
+ const found = [];
779
781
  for (const candidate of CANDIDATES) {
780
782
  const platformPaths = candidate.paths[platform];
781
783
  if (!platformPaths) continue;
782
784
  for (const p of platformPaths) {
783
785
  if (existsSync4(p)) {
784
- return { name: candidate.name, executablePath: p };
786
+ found.push({ name: candidate.name, executablePath: p });
787
+ break;
785
788
  }
786
789
  }
787
790
  }
788
- return null;
791
+ return found;
789
792
  }
790
793
 
791
794
  // src/dsers/browser-auth.ts
@@ -822,15 +825,11 @@ function parseWsUrl(stderrChunk) {
822
825
  const match = stderrChunk.match(/DevTools listening on (ws:\/\/[^\s]+)/);
823
826
  return match?.[1] ?? null;
824
827
  }
825
- function launchBrowser() {
826
- const browser = findChromium();
827
- if (!browser) {
828
- throw new Error("No Chromium-based browser found. Please install Chrome, Edge, or Brave.");
829
- }
828
+ function tryLaunchBrowser(browser) {
830
829
  const tmpDir = mkdtempSync(join4(tmpdir(), "dsclaw-auth-"));
831
830
  activeTmpDir = tmpDir;
832
831
  log6.info({ browser: browser.name }, "Launching browser for DSers auth");
833
- const proc = spawn(browser.executablePath, [
832
+ const args = [
834
833
  `--app=${DSERS_LOGIN_URL}`,
835
834
  "--remote-debugging-port=0",
836
835
  `--user-data-dir=${tmpDir}`,
@@ -839,7 +838,15 @@ function launchBrowser() {
839
838
  "--disable-extensions",
840
839
  "--mute-audio",
841
840
  "--window-size=480,700"
842
- ], {
841
+ ];
842
+ if (process.platform === "win32") {
843
+ args.push(
844
+ "--disable-background-mode",
845
+ "--disable-backgrounding-occluded-windows",
846
+ "--disable-renderer-backgrounding"
847
+ );
848
+ }
849
+ const proc = spawn(browser.executablePath, args, {
843
850
  stdio: ["ignore", "ignore", "pipe"],
844
851
  detached: false
845
852
  });
@@ -958,32 +965,58 @@ function watchLoginResponse(wsUrl) {
958
965
  });
959
966
  });
960
967
  }
968
+ async function attemptLoginWithBrowser(browser) {
969
+ const { proc, wsUrlPromise } = tryLaunchBrowser(browser);
970
+ proc.on("exit", () => {
971
+ activeProcess = null;
972
+ });
973
+ const wsUrl = await wsUrlPromise;
974
+ log6.info({ wsUrl }, "DevTools endpoint acquired");
975
+ const httpUrl = wsUrl.replace("ws://", "http://").replace(/\/devtools\/browser\/.*/, "/json");
976
+ const resp = await fetch(httpUrl);
977
+ const tabs = await resp.json();
978
+ const dsersTab = tabs.find((t2) => t2.url.includes("dsers.com")) ?? tabs[0];
979
+ if (!dsersTab?.webSocketDebuggerUrl) {
980
+ throw new Error("Could not find browser tab");
981
+ }
982
+ log6.info({ tabUrl: dsersTab.url }, "Watching tab for login API response");
983
+ const result = await watchLoginResponse(dsersTab.webSocketDebuggerUrl);
984
+ cleanup();
985
+ return result;
986
+ }
961
987
  async function loginViaCDP() {
962
988
  if (isAuthInProgress()) {
963
989
  throw new Error("Auth already in progress");
964
990
  }
965
- try {
966
- const { proc, wsUrlPromise } = launchBrowser();
967
- proc.on("exit", () => {
968
- activeProcess = null;
969
- });
970
- const wsUrl = await wsUrlPromise;
971
- log6.info({ wsUrl }, "DevTools endpoint acquired");
972
- const httpUrl = wsUrl.replace("ws://", "http://").replace(/\/devtools\/browser\/.*/, "/json");
973
- const resp = await fetch(httpUrl);
974
- const tabs = await resp.json();
975
- const dsersTab = tabs.find((t2) => t2.url.includes("dsers.com")) ?? tabs[0];
976
- if (!dsersTab?.webSocketDebuggerUrl) {
977
- throw new Error("Could not find browser tab");
991
+ const browsers = findAllChromium();
992
+ if (!browsers.length) {
993
+ throw new Error("No Chromium-based browser found. Please install Chrome, Edge, or Brave.");
994
+ }
995
+ for (let i = 0; i < browsers.length; i++) {
996
+ const browser = browsers[i];
997
+ const nextBrowser = browsers[i + 1];
998
+ try {
999
+ return await attemptLoginWithBrowser(browser);
1000
+ } catch (error) {
1001
+ cleanup();
1002
+ const msg = error instanceof Error ? error.message : String(error);
1003
+ const isLaunchFailure = msg.includes("Browser exited before DevTools was ready") || msg.includes("Timed out waiting for Chrome DevTools");
1004
+ if (isLaunchFailure && nextBrowser) {
1005
+ log6.warn(
1006
+ { browser: browser.name, error: msg, fallback: nextBrowser.name },
1007
+ "Browser launch failed, trying next browser"
1008
+ );
1009
+ continue;
1010
+ }
1011
+ if (isLaunchFailure && process.platform === "win32") {
1012
+ throw new Error(
1013
+ `Could not launch browser for DSers login. This usually happens when ${browser.name} is already running. Please close all ${browser.name} windows completely (including the system tray icon) and try again.`
1014
+ );
1015
+ }
1016
+ throw error;
978
1017
  }
979
- log6.info({ tabUrl: dsersTab.url }, "Watching tab for login API response");
980
- const result = await watchLoginResponse(dsersTab.webSocketDebuggerUrl);
981
- cleanup();
982
- return result;
983
- } catch (error) {
984
- cleanup();
985
- throw error;
986
1018
  }
1019
+ throw new Error("All browsers failed to launch for DSers auth.");
987
1020
  }
988
1021
 
989
1022
  // src/agents/core-agent.ts
@@ -4184,7 +4217,7 @@ async function doctorCommand() {
4184
4217
 
4185
4218
  // src/cli/index.ts
4186
4219
  var program = new Command();
4187
- program.name("dsclaw").description("AI-powered dropshipping agent \u2014 chat with your DSers store.").version("0.1.6");
4220
+ program.name("dsclaw").description("AI-powered dropshipping agent \u2014 chat with your DSers store.").version("0.1.8");
4188
4221
  program.action(() => startCommand({}));
4189
4222
  program.command("init").description("Setup wizard \u2014 configure Telegram (optional)").action(initCommand);
4190
4223
  program.command("start").description("Start the DSClaw bot").option("-c, --config <path>", "Path to config file").option("--no-open", "Don't auto-open browser").action(startCommand);