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.d.cts CHANGED
@@ -104,6 +104,7 @@ declare class AlmostNodeSession {
104
104
  private registeredBinCommands;
105
105
  private binCommandRegistrar?;
106
106
  private batchFileLoader?;
107
+ private stdoutWriter?;
107
108
  private viteServer?;
108
109
  private vitePort;
109
110
  private vitePreviewUrl;
@@ -114,6 +115,7 @@ declare class AlmostNodeSession {
114
115
  dispose(): void;
115
116
  setBinCommandRegistrar(registrar: BinCommandRegistrar): void;
116
117
  setBatchFileLoader(loader: BatchFileLoader): void;
118
+ setStdoutWriter(writer: ((data: string) => void) | undefined): void;
117
119
  setVitePreviewListener(listener: VitePreviewListener | undefined): void;
118
120
  setViteHmrTarget(target: Window | null): void;
119
121
  /**
@@ -163,6 +165,18 @@ declare class AlmostNodeSession {
163
165
  private resolveBinFromPackageJson;
164
166
  private resolveNpmBinPath;
165
167
  private resolveGlobalBinPath;
168
+ /**
169
+ * Patch lru-cache installations so the CJS entry doesn't crash in
170
+ * the browser runtime. lru-cache v11's CJS unconditionally calls
171
+ * `require("node:diagnostics_channel").tracingChannel()` at the
172
+ * module scope. If that throws inside the browser WASM sandbox the
173
+ * entire module fails and `exports.LRUCache` is never assigned,
174
+ * leading to "TypeError: LRUCache is not a constructor".
175
+ *
176
+ * The fix: wrap the `require("node:diagnostics_channel")` call in a
177
+ * try/catch with a no-op fallback so LRUCache initialises safely.
178
+ */
179
+ private patchLruCacheInNodeModules;
166
180
  private registerGlobalBinCommands;
167
181
  private resolveAndRegisterBinCommands;
168
182
  private trackOperation;
package/dist/index.d.ts CHANGED
@@ -104,6 +104,7 @@ declare class AlmostNodeSession {
104
104
  private registeredBinCommands;
105
105
  private binCommandRegistrar?;
106
106
  private batchFileLoader?;
107
+ private stdoutWriter?;
107
108
  private viteServer?;
108
109
  private vitePort;
109
110
  private vitePreviewUrl;
@@ -114,6 +115,7 @@ declare class AlmostNodeSession {
114
115
  dispose(): void;
115
116
  setBinCommandRegistrar(registrar: BinCommandRegistrar): void;
116
117
  setBatchFileLoader(loader: BatchFileLoader): void;
118
+ setStdoutWriter(writer: ((data: string) => void) | undefined): void;
117
119
  setVitePreviewListener(listener: VitePreviewListener | undefined): void;
118
120
  setViteHmrTarget(target: Window | null): void;
119
121
  /**
@@ -163,6 +165,18 @@ declare class AlmostNodeSession {
163
165
  private resolveBinFromPackageJson;
164
166
  private resolveNpmBinPath;
165
167
  private resolveGlobalBinPath;
168
+ /**
169
+ * Patch lru-cache installations so the CJS entry doesn't crash in
170
+ * the browser runtime. lru-cache v11's CJS unconditionally calls
171
+ * `require("node:diagnostics_channel").tracingChannel()` at the
172
+ * module scope. If that throws inside the browser WASM sandbox the
173
+ * entire module fails and `exports.LRUCache` is never assigned,
174
+ * leading to "TypeError: LRUCache is not a constructor".
175
+ *
176
+ * The fix: wrap the `require("node:diagnostics_channel")` call in a
177
+ * try/catch with a no-op fallback so LRUCache initialises safely.
178
+ */
179
+ private patchLruCacheInNodeModules;
166
180
  private registerGlobalBinCommands;
167
181
  private resolveAndRegisterBinCommands;
168
182
  private trackOperation;
package/dist/index.js CHANGED
@@ -54889,6 +54889,7 @@ var AlmostNodeSession = class {
54889
54889
  registeredBinCommands = /* @__PURE__ */ new Set();
54890
54890
  binCommandRegistrar;
54891
54891
  batchFileLoader;
54892
+ stdoutWriter;
54892
54893
  viteServer;
54893
54894
  vitePort = null;
54894
54895
  vitePreviewUrl = null;
@@ -54905,6 +54906,9 @@ var AlmostNodeSession = class {
54905
54906
  setBatchFileLoader(loader) {
54906
54907
  this.batchFileLoader = loader;
54907
54908
  }
54909
+ setStdoutWriter(writer) {
54910
+ this.stdoutWriter = writer;
54911
+ }
54908
54912
  setVitePreviewListener(listener) {
54909
54913
  this.vitePreviewListener = listener;
54910
54914
  listener?.(this.vitePreviewUrl);
@@ -55283,6 +55287,58 @@ var AlmostNodeSession = class {
55283
55287
  }
55284
55288
  return null;
55285
55289
  }
55290
+ /**
55291
+ * Patch lru-cache installations so the CJS entry doesn't crash in
55292
+ * the browser runtime. lru-cache v11's CJS unconditionally calls
55293
+ * `require("node:diagnostics_channel").tracingChannel()` at the
55294
+ * module scope. If that throws inside the browser WASM sandbox the
55295
+ * entire module fails and `exports.LRUCache` is never assigned,
55296
+ * leading to "TypeError: LRUCache is not a constructor".
55297
+ *
55298
+ * The fix: wrap the `require("node:diagnostics_channel")` call in a
55299
+ * try/catch with a no-op fallback so LRUCache initialises safely.
55300
+ */
55301
+ patchLruCacheInNodeModules(nodeModulesDir) {
55302
+ const patchFile = (filePath) => {
55303
+ if (!this._vfs.existsSync(filePath)) return;
55304
+ const src = this._vfs.readFileSync(filePath, "utf8");
55305
+ if (!src.includes('require("node:diagnostics_channel")')) return;
55306
+ const patched = src.replace(
55307
+ 'require("node:diagnostics_channel")',
55308
+ '(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(){}}}}}})()'
55309
+ );
55310
+ if (patched !== src) {
55311
+ this._vfs.writeFileSync(filePath, patched);
55312
+ }
55313
+ };
55314
+ const walkNodeModules = (nmDir) => {
55315
+ if (!this._vfs.existsSync(nmDir)) return;
55316
+ for (const entry of this._vfs.readdirSync(nmDir)) {
55317
+ if (entry === "lru-cache") {
55318
+ const cjsEntry = normalizePath(posixPath.join(nmDir, "lru-cache", "dist", "commonjs", "index.min.js"));
55319
+ patchFile(cjsEntry);
55320
+ const cjsIndex = normalizePath(posixPath.join(nmDir, "lru-cache", "dist", "commonjs", "index.js"));
55321
+ patchFile(cjsIndex);
55322
+ }
55323
+ const nestedNm = normalizePath(posixPath.join(nmDir, entry, "node_modules"));
55324
+ if (this._vfs.existsSync(nestedNm)) {
55325
+ walkNodeModules(nestedNm);
55326
+ }
55327
+ if (entry.startsWith("@")) {
55328
+ const scopeDir = normalizePath(posixPath.join(nmDir, entry));
55329
+ if (this._vfs.existsSync(scopeDir)) {
55330
+ for (const scopedEntry of this._vfs.readdirSync(scopeDir)) {
55331
+ const nestedNm2 = normalizePath(posixPath.join(scopeDir, scopedEntry, "node_modules"));
55332
+ if (this._vfs.existsSync(nestedNm2)) {
55333
+ walkNodeModules(nestedNm2);
55334
+ }
55335
+ }
55336
+ }
55337
+ }
55338
+ }
55339
+ };
55340
+ walkNodeModules(nodeModulesDir);
55341
+ }
55286
55342
  async registerGlobalBinCommands(packageName) {
55287
55343
  if (!this.binCommandRegistrar) return;
55288
55344
  const pkgJsonPath = normalizePath(posixPath.join(GLOBAL_NODE_MODULES_ROOT, packageName, "package.json"));
@@ -55790,8 +55846,10 @@ var AlmostNodeSession = class {
55790
55846
  const installResult = await packageManager.install(packageSpec, {
55791
55847
  save: true,
55792
55848
  onProgress: (message) => {
55793
- stdout += `${message}
55849
+ const line = `${message}
55794
55850
  `;
55851
+ stdout += line;
55852
+ this.stdoutWriter?.(line);
55795
55853
  }
55796
55854
  });
55797
55855
  stdout += `added ${installResult.added.length} packages
@@ -55805,6 +55863,7 @@ var AlmostNodeSession = class {
55805
55863
  }
55806
55864
  }
55807
55865
  }
55866
+ this.patchLruCacheInNodeModules(GLOBAL_NODE_MODULES_ROOT);
55808
55867
  result = { stdout, stderr: "", exitCode: 0 };
55809
55868
  } else {
55810
55869
  const packageJsonResult = await this.readPackageJson(cwd);
@@ -55817,8 +55876,10 @@ var AlmostNodeSession = class {
55817
55876
  if (packageSpecs.length === 0) {
55818
55877
  const installResult = await packageManager.installFromPackageJson({
55819
55878
  onProgress: (message) => {
55820
- stdout += `${message}
55879
+ const line = `${message}
55821
55880
  `;
55881
+ stdout += line;
55882
+ this.stdoutWriter?.(line);
55822
55883
  }
55823
55884
  });
55824
55885
  stdout += `added ${installResult.added.length} packages
@@ -55828,14 +55889,18 @@ var AlmostNodeSession = class {
55828
55889
  const installResult = await packageManager.install(packageSpec, {
55829
55890
  save: true,
55830
55891
  onProgress: (message) => {
55831
- stdout += `${message}
55892
+ const line = `${message}
55832
55893
  `;
55894
+ stdout += line;
55895
+ this.stdoutWriter?.(line);
55833
55896
  }
55834
55897
  });
55835
55898
  stdout += `added ${installResult.added.length} packages
55836
55899
  `;
55837
55900
  }
55838
55901
  }
55902
+ const localNodeModules = normalizePath(posixPath.join(cwd, "node_modules"));
55903
+ this.patchLruCacheInNodeModules(localNodeModules);
55839
55904
  result = { stdout, stderr: "", exitCode: 0 };
55840
55905
  }
55841
55906
  } catch (error) {