agent-web-os 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/index.d.cts CHANGED
@@ -163,6 +163,18 @@ declare class AlmostNodeSession {
163
163
  private resolveBinFromPackageJson;
164
164
  private resolveNpmBinPath;
165
165
  private resolveGlobalBinPath;
166
+ /**
167
+ * Patch lru-cache installations so the CJS entry doesn't crash in
168
+ * the browser runtime. lru-cache v11's CJS unconditionally calls
169
+ * `require("node:diagnostics_channel").tracingChannel()` at the
170
+ * module scope. If that throws inside the browser WASM sandbox the
171
+ * entire module fails and `exports.LRUCache` is never assigned,
172
+ * leading to "TypeError: LRUCache is not a constructor".
173
+ *
174
+ * The fix: wrap the `require("node:diagnostics_channel")` call in a
175
+ * try/catch with a no-op fallback so LRUCache initialises safely.
176
+ */
177
+ private patchLruCacheInNodeModules;
166
178
  private registerGlobalBinCommands;
167
179
  private resolveAndRegisterBinCommands;
168
180
  private trackOperation;
package/dist/index.d.ts CHANGED
@@ -163,6 +163,18 @@ declare class AlmostNodeSession {
163
163
  private resolveBinFromPackageJson;
164
164
  private resolveNpmBinPath;
165
165
  private resolveGlobalBinPath;
166
+ /**
167
+ * Patch lru-cache installations so the CJS entry doesn't crash in
168
+ * the browser runtime. lru-cache v11's CJS unconditionally calls
169
+ * `require("node:diagnostics_channel").tracingChannel()` at the
170
+ * module scope. If that throws inside the browser WASM sandbox the
171
+ * entire module fails and `exports.LRUCache` is never assigned,
172
+ * leading to "TypeError: LRUCache is not a constructor".
173
+ *
174
+ * The fix: wrap the `require("node:diagnostics_channel")` call in a
175
+ * try/catch with a no-op fallback so LRUCache initialises safely.
176
+ */
177
+ private patchLruCacheInNodeModules;
166
178
  private registerGlobalBinCommands;
167
179
  private resolveAndRegisterBinCommands;
168
180
  private trackOperation;
package/dist/index.js CHANGED
@@ -54834,6 +54834,29 @@ var AlmostNodeSession = class {
54834
54834
  "/node_modules/stream/promises/index.js",
54835
54835
  "var stream = require('stream');\nmodule.exports = stream.promises || {};"
54836
54836
  );
54837
+ this._vfs.mkdirSync("/node_modules/stream/web", { recursive: true });
54838
+ this._vfs.writeFileSync("/node_modules/stream/web/package.json", JSON.stringify({
54839
+ name: "stream-web",
54840
+ version: "0.0.1",
54841
+ main: "index.js"
54842
+ }));
54843
+ this._vfs.writeFileSync("/node_modules/stream/web/index.js", [
54844
+ "// Web Streams API shim \u2014 re-exports browser globals",
54845
+ "module.exports = {",
54846
+ " ReadableStream: typeof ReadableStream !== 'undefined' ? ReadableStream : undefined,",
54847
+ " ReadableStreamDefaultReader: typeof ReadableStreamDefaultReader !== 'undefined' ? ReadableStreamDefaultReader : undefined,",
54848
+ " ReadableStreamBYOBReader: typeof ReadableStreamBYOBReader !== 'undefined' ? ReadableStreamBYOBReader : undefined,",
54849
+ " ReadableStreamDefaultController: typeof ReadableStreamDefaultController !== 'undefined' ? ReadableStreamDefaultController : undefined,",
54850
+ " ReadableByteStreamController: typeof ReadableByteStreamController !== 'undefined' ? ReadableByteStreamController : undefined,",
54851
+ " WritableStream: typeof WritableStream !== 'undefined' ? WritableStream : undefined,",
54852
+ " WritableStreamDefaultWriter: typeof WritableStreamDefaultWriter !== 'undefined' ? WritableStreamDefaultWriter : undefined,",
54853
+ " WritableStreamDefaultController: typeof WritableStreamDefaultController !== 'undefined' ? WritableStreamDefaultController : undefined,",
54854
+ " TransformStream: typeof TransformStream !== 'undefined' ? TransformStream : undefined,",
54855
+ " TransformStreamDefaultController: typeof TransformStreamDefaultController !== 'undefined' ? TransformStreamDefaultController : undefined,",
54856
+ " ByteLengthQueuingStrategy: typeof ByteLengthQueuingStrategy !== 'undefined' ? ByteLengthQueuingStrategy : undefined,",
54857
+ " CountQueuingStrategy: typeof CountQueuingStrategy !== 'undefined' ? CountQueuingStrategy : undefined,",
54858
+ "};"
54859
+ ].join("\n"));
54837
54860
  this.disposeObservableSubscription = this.fs.subscribe((event) => {
54838
54861
  void this.trackOperation((async () => {
54839
54862
  if (!this.initialized || this.suppressObservableMirrorCount > 0) {
@@ -55260,6 +55283,58 @@ var AlmostNodeSession = class {
55260
55283
  }
55261
55284
  return null;
55262
55285
  }
55286
+ /**
55287
+ * Patch lru-cache installations so the CJS entry doesn't crash in
55288
+ * the browser runtime. lru-cache v11's CJS unconditionally calls
55289
+ * `require("node:diagnostics_channel").tracingChannel()` at the
55290
+ * module scope. If that throws inside the browser WASM sandbox the
55291
+ * entire module fails and `exports.LRUCache` is never assigned,
55292
+ * leading to "TypeError: LRUCache is not a constructor".
55293
+ *
55294
+ * The fix: wrap the `require("node:diagnostics_channel")` call in a
55295
+ * try/catch with a no-op fallback so LRUCache initialises safely.
55296
+ */
55297
+ patchLruCacheInNodeModules(nodeModulesDir) {
55298
+ const patchFile = (filePath) => {
55299
+ if (!this._vfs.existsSync(filePath)) return;
55300
+ const src = this._vfs.readFileSync(filePath, "utf8");
55301
+ if (!src.includes('require("node:diagnostics_channel")')) return;
55302
+ const patched = src.replace(
55303
+ 'require("node:diagnostics_channel")',
55304
+ '(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(){}}}}}})()'
55305
+ );
55306
+ if (patched !== src) {
55307
+ this._vfs.writeFileSync(filePath, patched);
55308
+ }
55309
+ };
55310
+ const walkNodeModules = (nmDir) => {
55311
+ if (!this._vfs.existsSync(nmDir)) return;
55312
+ for (const entry of this._vfs.readdirSync(nmDir)) {
55313
+ if (entry === "lru-cache") {
55314
+ const cjsEntry = normalizePath(posixPath.join(nmDir, "lru-cache", "dist", "commonjs", "index.min.js"));
55315
+ patchFile(cjsEntry);
55316
+ const cjsIndex = normalizePath(posixPath.join(nmDir, "lru-cache", "dist", "commonjs", "index.js"));
55317
+ patchFile(cjsIndex);
55318
+ }
55319
+ const nestedNm = normalizePath(posixPath.join(nmDir, entry, "node_modules"));
55320
+ if (this._vfs.existsSync(nestedNm)) {
55321
+ walkNodeModules(nestedNm);
55322
+ }
55323
+ if (entry.startsWith("@")) {
55324
+ const scopeDir = normalizePath(posixPath.join(nmDir, entry));
55325
+ if (this._vfs.existsSync(scopeDir)) {
55326
+ for (const scopedEntry of this._vfs.readdirSync(scopeDir)) {
55327
+ const nestedNm2 = normalizePath(posixPath.join(scopeDir, scopedEntry, "node_modules"));
55328
+ if (this._vfs.existsSync(nestedNm2)) {
55329
+ walkNodeModules(nestedNm2);
55330
+ }
55331
+ }
55332
+ }
55333
+ }
55334
+ }
55335
+ };
55336
+ walkNodeModules(nodeModulesDir);
55337
+ }
55263
55338
  async registerGlobalBinCommands(packageName) {
55264
55339
  if (!this.binCommandRegistrar) return;
55265
55340
  const pkgJsonPath = normalizePath(posixPath.join(GLOBAL_NODE_MODULES_ROOT, packageName, "package.json"));
@@ -55782,6 +55857,7 @@ var AlmostNodeSession = class {
55782
55857
  }
55783
55858
  }
55784
55859
  }
55860
+ this.patchLruCacheInNodeModules(GLOBAL_NODE_MODULES_ROOT);
55785
55861
  result = { stdout, stderr: "", exitCode: 0 };
55786
55862
  } else {
55787
55863
  const packageJsonResult = await this.readPackageJson(cwd);
@@ -55813,6 +55889,8 @@ var AlmostNodeSession = class {
55813
55889
  `;
55814
55890
  }
55815
55891
  }
55892
+ const localNodeModules = normalizePath(posixPath.join(cwd, "node_modules"));
55893
+ this.patchLruCacheInNodeModules(localNodeModules);
55816
55894
  result = { stdout, stderr: "", exitCode: 0 };
55817
55895
  }
55818
55896
  } catch (error) {