agent-web-os 0.1.7 → 0.1.9

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
@@ -60706,6 +60706,7 @@ var AlmostNodeSession = class {
60706
60706
  registeredBinCommands = /* @__PURE__ */ new Set();
60707
60707
  binCommandRegistrar;
60708
60708
  batchFileLoader;
60709
+ stdoutWriter;
60709
60710
  viteServer;
60710
60711
  vitePort = null;
60711
60712
  vitePreviewUrl = null;
@@ -60722,6 +60723,9 @@ var AlmostNodeSession = class {
60722
60723
  setBatchFileLoader(loader) {
60723
60724
  this.batchFileLoader = loader;
60724
60725
  }
60726
+ setStdoutWriter(writer) {
60727
+ this.stdoutWriter = writer;
60728
+ }
60725
60729
  setVitePreviewListener(listener) {
60726
60730
  this.vitePreviewListener = listener;
60727
60731
  listener?.(this.vitePreviewUrl);
@@ -61100,6 +61104,58 @@ var AlmostNodeSession = class {
61100
61104
  }
61101
61105
  return null;
61102
61106
  }
61107
+ /**
61108
+ * Patch lru-cache installations so the CJS entry doesn't crash in
61109
+ * the browser runtime. lru-cache v11's CJS unconditionally calls
61110
+ * `require("node:diagnostics_channel").tracingChannel()` at the
61111
+ * module scope. If that throws inside the browser WASM sandbox the
61112
+ * entire module fails and `exports.LRUCache` is never assigned,
61113
+ * leading to "TypeError: LRUCache is not a constructor".
61114
+ *
61115
+ * The fix: wrap the `require("node:diagnostics_channel")` call in a
61116
+ * try/catch with a no-op fallback so LRUCache initialises safely.
61117
+ */
61118
+ patchLruCacheInNodeModules(nodeModulesDir) {
61119
+ const patchFile = (filePath) => {
61120
+ if (!this._vfs.existsSync(filePath)) return;
61121
+ const src = this._vfs.readFileSync(filePath, "utf8");
61122
+ if (!src.includes('require("node:diagnostics_channel")')) return;
61123
+ const patched = src.replace(
61124
+ 'require("node:diagnostics_channel")',
61125
+ '(function(){try{var _dc=require("node:diagnostics_channel");var _ch=_dc.channel("lru-cache:_test");if(typeof _dc.tracingChannel==="function")_dc.tracingChannel("lru-cache:_test");return _dc}catch(_e){return{channel:function(){return{hasSubscribers:false,publish:function(){},subscribe:function(){},unsubscribe:function(){}}},tracingChannel:function(){return{hasSubscribers:false,subscribe:function(){},unsubscribe:function(){}}}}}})()'
61126
+ );
61127
+ if (patched !== src) {
61128
+ this._vfs.writeFileSync(filePath, patched);
61129
+ }
61130
+ };
61131
+ const walkNodeModules = (nmDir) => {
61132
+ if (!this._vfs.existsSync(nmDir)) return;
61133
+ for (const entry of this._vfs.readdirSync(nmDir)) {
61134
+ if (entry === "lru-cache") {
61135
+ const cjsEntry = normalizePath(posixPath.join(nmDir, "lru-cache", "dist", "commonjs", "index.min.js"));
61136
+ patchFile(cjsEntry);
61137
+ const cjsIndex = normalizePath(posixPath.join(nmDir, "lru-cache", "dist", "commonjs", "index.js"));
61138
+ patchFile(cjsIndex);
61139
+ }
61140
+ const nestedNm = normalizePath(posixPath.join(nmDir, entry, "node_modules"));
61141
+ if (this._vfs.existsSync(nestedNm)) {
61142
+ walkNodeModules(nestedNm);
61143
+ }
61144
+ if (entry.startsWith("@")) {
61145
+ const scopeDir = normalizePath(posixPath.join(nmDir, entry));
61146
+ if (this._vfs.existsSync(scopeDir)) {
61147
+ for (const scopedEntry of this._vfs.readdirSync(scopeDir)) {
61148
+ const nestedNm2 = normalizePath(posixPath.join(scopeDir, scopedEntry, "node_modules"));
61149
+ if (this._vfs.existsSync(nestedNm2)) {
61150
+ walkNodeModules(nestedNm2);
61151
+ }
61152
+ }
61153
+ }
61154
+ }
61155
+ }
61156
+ };
61157
+ walkNodeModules(nodeModulesDir);
61158
+ }
61103
61159
  async registerGlobalBinCommands(packageName) {
61104
61160
  if (!this.binCommandRegistrar) return;
61105
61161
  const pkgJsonPath = normalizePath(posixPath.join(GLOBAL_NODE_MODULES_ROOT, packageName, "package.json"));
@@ -61607,8 +61663,10 @@ var AlmostNodeSession = class {
61607
61663
  const installResult = await packageManager.install(packageSpec, {
61608
61664
  save: true,
61609
61665
  onProgress: (message) => {
61610
- stdout += `${message}
61666
+ const line = `${message}
61611
61667
  `;
61668
+ stdout += line;
61669
+ this.stdoutWriter?.(line);
61612
61670
  }
61613
61671
  });
61614
61672
  stdout += `added ${installResult.added.length} packages
@@ -61622,6 +61680,7 @@ var AlmostNodeSession = class {
61622
61680
  }
61623
61681
  }
61624
61682
  }
61683
+ this.patchLruCacheInNodeModules(GLOBAL_NODE_MODULES_ROOT);
61625
61684
  result = { stdout, stderr: "", exitCode: 0 };
61626
61685
  } else {
61627
61686
  const packageJsonResult = await this.readPackageJson(cwd);
@@ -61634,8 +61693,10 @@ var AlmostNodeSession = class {
61634
61693
  if (packageSpecs.length === 0) {
61635
61694
  const installResult = await packageManager.installFromPackageJson({
61636
61695
  onProgress: (message) => {
61637
- stdout += `${message}
61696
+ const line = `${message}
61638
61697
  `;
61698
+ stdout += line;
61699
+ this.stdoutWriter?.(line);
61639
61700
  }
61640
61701
  });
61641
61702
  stdout += `added ${installResult.added.length} packages
@@ -61645,14 +61706,18 @@ var AlmostNodeSession = class {
61645
61706
  const installResult = await packageManager.install(packageSpec, {
61646
61707
  save: true,
61647
61708
  onProgress: (message) => {
61648
- stdout += `${message}
61709
+ const line = `${message}
61649
61710
  `;
61711
+ stdout += line;
61712
+ this.stdoutWriter?.(line);
61650
61713
  }
61651
61714
  });
61652
61715
  stdout += `added ${installResult.added.length} packages
61653
61716
  `;
61654
61717
  }
61655
61718
  }
61719
+ const localNodeModules = normalizePath(posixPath.join(cwd, "node_modules"));
61720
+ this.patchLruCacheInNodeModules(localNodeModules);
61656
61721
  result = { stdout, stderr: "", exitCode: 0 };
61657
61722
  }
61658
61723
  } catch (error) {