dhalsim 2.0.0 → 2.1.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.cjs CHANGED
@@ -46,6 +46,9 @@ __export(index_exports, {
46
46
  module.exports = __toCommonJS(index_exports);
47
47
 
48
48
  // src/session/manager.ts
49
+ var fs = __toESM(require("fs"), 1);
50
+ var path = __toESM(require("path"), 1);
51
+ var os = __toESM(require("os"), 1);
49
52
  var import_llmist = require("llmist");
50
53
  var CamoufoxModule = null;
51
54
  async function loadCamoufox() {
@@ -54,6 +57,57 @@ async function loadCamoufox() {
54
57
  }
55
58
  return CamoufoxModule.Camoufox;
56
59
  }
60
+ function getCamoufoxCacheDir() {
61
+ const platform2 = os.platform();
62
+ if (platform2 === "win32") {
63
+ return path.join(os.homedir(), "AppData", "Local", "camoufox", "camoufox", "Cache");
64
+ } else if (platform2 === "darwin") {
65
+ return path.join(os.homedir(), "Library", "Caches", "camoufox");
66
+ } else {
67
+ return path.join(os.homedir(), ".cache", "camoufox");
68
+ }
69
+ }
70
+ function isCamoufoxInstalled() {
71
+ const cacheDir = getCamoufoxCacheDir();
72
+ const versionFile = path.join(cacheDir, "version.json");
73
+ return fs.existsSync(versionFile);
74
+ }
75
+ var browserInstallPromise = null;
76
+ async function ensureCamoufoxInstalled(logger13) {
77
+ if (browserInstallPromise) {
78
+ return browserInstallPromise;
79
+ }
80
+ if (isCamoufoxInstalled()) {
81
+ logger13.debug?.("[dhalsim] Camoufox browser already installed");
82
+ return;
83
+ }
84
+ browserInstallPromise = performCamoufoxInstall(logger13);
85
+ try {
86
+ await browserInstallPromise;
87
+ } finally {
88
+ browserInstallPromise = null;
89
+ }
90
+ }
91
+ async function performCamoufoxInstall(logger13) {
92
+ const warn = logger13.warn ?? logger13.info ?? console.warn;
93
+ warn.call(logger13, "[dhalsim] ============================================");
94
+ warn.call(logger13, "[dhalsim] Camoufox browser not found. Starting download...");
95
+ warn.call(logger13, "[dhalsim] This is a one-time download (~1.3GB)");
96
+ warn.call(logger13, "[dhalsim] Future browser sessions will start immediately.");
97
+ warn.call(logger13, "[dhalsim] ============================================");
98
+ try {
99
+ const { CamoufoxFetcher } = await import("camoufox-js/dist/pkgman.js");
100
+ const fetcher = new CamoufoxFetcher();
101
+ await fetcher.install();
102
+ logger13.debug?.("[dhalsim] Camoufox browser installed successfully");
103
+ } catch (error46) {
104
+ const errorMessage = error46 instanceof Error ? error46.message : String(error46);
105
+ throw new Error(
106
+ `Failed to download Camoufox browser: ${errorMessage}
107
+ You can manually install by running: npx camoufox fetch`
108
+ );
109
+ }
110
+ }
57
111
  var BrowserSessionManager = class {
58
112
  browsers = /* @__PURE__ */ new Map();
59
113
  pages = /* @__PURE__ */ new Map();
@@ -72,6 +126,7 @@ var BrowserSessionManager = class {
72
126
  async startBrowser(options = {}) {
73
127
  this.logger.debug(`[BrowserSessionManager] startBrowser headless=${options.headless ?? true} url=${options.url ?? "none"}`);
74
128
  const { headless = true, url: url2, proxy, geoip = false, disableCache = false, navigationTimeoutMs = 6e4 } = options;
129
+ await ensureCamoufoxInstalled(this.logger);
75
130
  const BROWSER_LAUNCH_TIMEOUT = 3e4;
76
131
  const MAX_RETRIES = 2;
77
132
  const RETRY_DELAY = 1e3;
@@ -1174,10 +1229,10 @@ function mergeDefs(...defs) {
1174
1229
  function cloneDef(schema) {
1175
1230
  return mergeDefs(schema._zod.def);
1176
1231
  }
1177
- function getElementAtPath(obj, path) {
1178
- if (!path)
1232
+ function getElementAtPath(obj, path2) {
1233
+ if (!path2)
1179
1234
  return obj;
1180
- return path.reduce((acc, key) => acc?.[key], obj);
1235
+ return path2.reduce((acc, key) => acc?.[key], obj);
1181
1236
  }
1182
1237
  function promiseAllObject(promisesObj) {
1183
1238
  const keys = Object.keys(promisesObj);
@@ -1543,11 +1598,11 @@ function aborted(x, startIndex = 0) {
1543
1598
  }
1544
1599
  return false;
1545
1600
  }
1546
- function prefixIssues(path, issues) {
1601
+ function prefixIssues(path2, issues) {
1547
1602
  return issues.map((iss) => {
1548
1603
  var _a2;
1549
1604
  (_a2 = iss).path ?? (_a2.path = []);
1550
- iss.path.unshift(path);
1605
+ iss.path.unshift(path2);
1551
1606
  return iss;
1552
1607
  });
1553
1608
  }
@@ -1709,7 +1764,7 @@ function formatError(error46, mapper = (issue2) => issue2.message) {
1709
1764
  }
1710
1765
  function treeifyError(error46, mapper = (issue2) => issue2.message) {
1711
1766
  const result = { errors: [] };
1712
- const processError = (error47, path = []) => {
1767
+ const processError = (error47, path2 = []) => {
1713
1768
  var _a2, _b;
1714
1769
  for (const issue2 of error47.issues) {
1715
1770
  if (issue2.code === "invalid_union" && issue2.errors.length) {
@@ -1719,7 +1774,7 @@ function treeifyError(error46, mapper = (issue2) => issue2.message) {
1719
1774
  } else if (issue2.code === "invalid_element") {
1720
1775
  processError({ issues: issue2.issues }, issue2.path);
1721
1776
  } else {
1722
- const fullpath = [...path, ...issue2.path];
1777
+ const fullpath = [...path2, ...issue2.path];
1723
1778
  if (fullpath.length === 0) {
1724
1779
  result.errors.push(mapper(issue2));
1725
1780
  continue;
@@ -1751,8 +1806,8 @@ function treeifyError(error46, mapper = (issue2) => issue2.message) {
1751
1806
  }
1752
1807
  function toDotPath(_path) {
1753
1808
  const segs = [];
1754
- const path = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1755
- for (const seg of path) {
1809
+ const path2 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1810
+ for (const seg of path2) {
1756
1811
  if (typeof seg === "number")
1757
1812
  segs.push(`[${seg}]`);
1758
1813
  else if (typeof seg === "symbol")
@@ -13552,13 +13607,13 @@ function resolveRef(ref, ctx) {
13552
13607
  if (!ref.startsWith("#")) {
13553
13608
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
13554
13609
  }
13555
- const path = ref.slice(1).split("/").filter(Boolean);
13556
- if (path.length === 0) {
13610
+ const path2 = ref.slice(1).split("/").filter(Boolean);
13611
+ if (path2.length === 0) {
13557
13612
  return ctx.rootSchema;
13558
13613
  }
13559
13614
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
13560
- if (path[0] === defsKey) {
13561
- const key = path[1];
13615
+ if (path2[0] === defsKey) {
13616
+ const key = path2[1];
13562
13617
  if (!key || !ctx.defs[key]) {
13563
13618
  throw new Error(`Reference not found: ${ref}`);
13564
13619
  }