module-proxies.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * The worker bundle's module proxy table: the ONLY platform fork of the host
  3. * tree. Every entry replaces a Node builtin or an external npm package;
  4. * workspace and vendored modules are always mounted as they ship.
  5. *
  6. * The build turns these into bundler aliases, and `node/builtins.ts` turns the
  7. * same modules into the loader's static table — one list, two consumers.
  8. *
  9. * The replacement path states the classification. `./node/builtin_modules/implemented/<module>.ts`
  10. * carries the module's real semantics over a worker-side data source (VFS, the
  11. * tunnel, a wasm codec, a browser primitive); `./node/builtin_modules/mock/<module>.ts` is a
  12. * structural placeholder that mounts silently and reports the missing capability
  13. * when a call finally reaches it. External npm replacements live in
  14. * `./externals/`, named after the package they stand in for.
  15. * @module @deepseek-ai/dsh-experimental-webworker-runtime/src/module-proxies
  16. */
  17. /**
  18. * Module proxy table — the ONLY platform fork of the worker host. Every entry
  19. * replaces a Node builtin or an external npm package; workspace and vendored
  20. * modules are always mounted as-is. Keys are exact module specifiers.
  21. */
  22. export const MODULE_PROXIES: Record<string, string> = {
  23. // VFS-backed real implementations.
  24. 'node:fs': './node/builtin_modules/implemented/fs.ts',
  25. 'fs': './node/builtin_modules/implemented/fs.ts',
  26. 'node:fs/promises': './node/builtin_modules/implemented/fs/promises.ts',
  27. 'fs/promises': './node/builtin_modules/implemented/fs/promises.ts',
  28. 'node:path': './node/builtin_modules/implemented/path.ts',
  29. 'path': './node/builtin_modules/implemented/path.ts',
  30. 'node:path/posix': './node/builtin_modules/implemented/path.ts',
  31. 'node:os': './node/builtin_modules/implemented/os.ts',
  32. 'os': './node/builtin_modules/implemented/os.ts',
  33. 'node:url': './node/builtin_modules/implemented/url.ts',
  34. 'node:module': './node/builtin_modules/implemented/module.ts',
  35. 'node:crypto': './node/builtin_modules/implemented/crypto.ts',
  36. 'crypto': './node/builtin_modules/implemented/crypto.ts',
  37. // `buffer` itself stays unaliased: the shim is backed by that npm package.
  38. 'node:buffer': './node/builtin_modules/implemented/buffer.ts',
  39. // Tunnel request source: fake bind, real route face. `node:process` and
  40. // `process` are absent on purpose — the worker host installs that global
  41. // (`./globals/process.ts`).
  42. 'node:http': './node/builtin_modules/implemented/http.ts',
  43. // Sync-stack AsyncLocalStorage semantics.
  44. 'node:async_hooks': './node/builtin_modules/implemented/async_hooks.ts',
  45. // Real implementations over browser primitives.
  46. 'node:util': './node/builtin_modules/implemented/util.ts',
  47. 'node:util/types': './node/builtin_modules/implemented/util/types.ts',
  48. 'node:events': './node/builtin_modules/implemented/events.ts',
  49. 'node:timers/promises': './node/builtin_modules/implemented/timers/promises.ts',
  50. 'node:perf_hooks': './node/builtin_modules/implemented/perf_hooks.ts',
  51. 'node:tty': './node/builtin_modules/implemented/tty.ts',
  52. 'tty': './node/builtin_modules/implemented/tty.ts',
  53. // Real zstd codec: session-log appends compress on every write.
  54. 'node:zlib': './node/builtin_modules/implemented/zlib.ts',
  55. // The worker's own process layer: `bash -c` and the command table run against
  56. // the VFS, because a browser worker has no processes to fork.
  57. 'node:child_process': './node/builtin_modules/implemented/child_process.ts',
  58. // Structural mocks: every symbol exists, every call throws.
  59. 'node:dns/promises': './node/builtin_modules/mock/dns/promises.ts',
  60. 'dns/promises': './node/builtin_modules/mock/dns/promises.ts',
  61. 'node:net': './node/builtin_modules/mock/net.ts',
  62. 'node:stream': './node/builtin_modules/implemented/stream.ts',
  63. 'node:vm': './node/builtin_modules/mock/vm.ts',
  64. 'node:worker_threads': './node/builtin_modules/mock/worker_threads.ts',
  65. 'node:sqlite': './node/builtin_modules/mock/sqlite.ts',
  66. // External npm replacements, named after the package each stands in for.
  67. 'koffi': './node/external_packages/koffi.ts',
  68. 'sharp': './node/external_packages/sharp.ts',
  69. 'node-pty': './node/external_packages/node-pty.ts',
  70. '@vscode/ripgrep': './node/external_packages/ripgrep.ts',
  71. '@earendil-works/pi-ai': './node/external_packages/pi-ai.ts',
  72. // Constructible fakes whose methods are never reached.
  73. 'ws': './node/external_packages/ws.ts',
  74. }
  75. /** pi-ai subpaths (`/providers/all`, `/api/*.lazy`) share the one structural stub. */
  76. export const MODULE_PROXY_PREFIXES: Record<string, string> = {
  77. '@earendil-works/pi-ai/': './node/external_packages/pi-ai.ts',
  78. }