Files
deepseek-harness/packages/experimental/webworker-runtime/src/module-proxies.ts
T
imccyu 93d2ad2d25 feat(webworker): boot the preview from the shipped profile and fetch lazy chunks on demand
The packer images the web template bundles, every optional bundle, and an installation manifest instead of a dumped composition, and the Worker boots that profile through app-boot like dsh web. Package-local lazy client chunks move into content-addressed archives that the VFS fetches on first asynchronous read; client-modules reads chunks asynchronously.

The Worker replaces node-addon-require-builtin with Node v24.18.0 internal-module interfaces and reports Node 24, so plugin metadata, the Cordis Loader, and HMR reach one cascaded loader backed by the Worker loader. Resolution failures carry Node error codes, the empty load cache lets HMR apply profile changes, and every optional bundle switches on and off live. Platform stubs throw ERR_FEATURE_UNAVAILABLE_ON_PLATFORM.
2026-10-15 11:30:45 +08:00

93 lines
5.3 KiB
TypeScript

/**
* The worker bundle's module proxy table: the ONLY platform fork of the host
* tree. Entries replace Node builtins, external npm packages, and the native
* flock subpath; other workspace and vendored modules are mounted as they ship.
*
* The build turns these into bundler aliases, and `node/builtins.ts` turns the
* same modules into the loader's static table — one list, two consumers.
*
* The replacement path states the classification. `./node/builtin_modules/implemented/<module>.ts`
* carries the module's real semantics over a worker-side data source (VFS, the
* tunnel, a wasm codec, a browser primitive); `./node/builtin_modules/mock/<module>.ts` is a
* structural placeholder that mounts silently and reports the missing capability
* when a call finally reaches it. External npm replacements live in
* `./externals/`, named after the package they stand in for.
* @module @deepseek-ai/dsh-experimental-webworker-runtime/src/module-proxies
*/
/**
* Module proxy table — the ONLY platform fork of the worker host. Keys are
* exact module specifiers; the native system package's Landlock entry stays
* unmodified while its flock subpath is replaced.
*/
export const MODULE_PROXIES: Record<string, string> = {
// VFS-backed real implementations.
'node:fs': './node/builtin_modules/implemented/fs.ts',
'fs': './node/builtin_modules/implemented/fs.ts',
'node:fs/promises': './node/builtin_modules/implemented/fs/promises.ts',
'fs/promises': './node/builtin_modules/implemented/fs/promises.ts',
'node:path': './node/builtin_modules/implemented/path.ts',
'path': './node/builtin_modules/implemented/path.ts',
'node:path/posix': './node/builtin_modules/implemented/path.ts',
'node:os': './node/builtin_modules/implemented/os.ts',
'os': './node/builtin_modules/implemented/os.ts',
'node:url': './node/builtin_modules/implemented/url.ts',
'node:module': './node/builtin_modules/implemented/module.ts',
'node:crypto': './node/builtin_modules/implemented/crypto.ts',
'crypto': './node/builtin_modules/implemented/crypto.ts',
// `buffer` itself stays unaliased: the shim is backed by that npm package.
'node:buffer': './node/builtin_modules/implemented/buffer.ts',
// Tunnel request source: fake bind, real route face. `node:process` and
// `process` are absent on purpose — the worker host installs that global
// (`./globals/process.ts`).
'node:http': './node/builtin_modules/implemented/http.ts',
// Sync-stack AsyncLocalStorage semantics.
'node:async_hooks': './node/builtin_modules/implemented/async_hooks.ts',
// Real implementations over browser primitives.
'node:assert/strict': './node/builtin_modules/implemented/assert/strict.ts',
'assert/strict': './node/builtin_modules/implemented/assert/strict.ts',
'node:util': './node/builtin_modules/implemented/util.ts',
'node:util/types': './node/builtin_modules/implemented/util/types.ts',
'node:events': './node/builtin_modules/implemented/events.ts',
'node:timers/promises': './node/builtin_modules/implemented/timers/promises.ts',
'node:perf_hooks': './node/builtin_modules/implemented/perf_hooks.ts',
'node:tty': './node/builtin_modules/implemented/tty.ts',
'tty': './node/builtin_modules/implemented/tty.ts',
// Real zstd codec: session-log appends compress on every write.
'node:zlib': './node/builtin_modules/implemented/zlib.ts',
// The worker's own process layer: `bash -c` and the command table run against
// the VFS, because a browser worker has no processes to fork.
'node:child_process': './node/builtin_modules/implemented/child_process.ts',
// Structural mocks: every symbol exists, every call throws.
'node:https': './node/builtin_modules/mock/https.ts',
'node:dns/promises': './node/builtin_modules/mock/dns/promises.ts',
'dns/promises': './node/builtin_modules/mock/dns/promises.ts',
'node:net': './node/builtin_modules/mock/net.ts',
'node:stream': './node/builtin_modules/implemented/stream.ts',
'node:stream/promises': './node/builtin_modules/implemented/stream/promises.ts',
'stream/promises': './node/builtin_modules/implemented/stream/promises.ts',
'node:vm': './node/builtin_modules/mock/vm.ts',
'node:worker_threads': './node/builtin_modules/mock/worker_threads.ts',
'node:sqlite': './node/builtin_modules/mock/sqlite.ts',
// External npm replacements, named after the package each stands in for.
'@deepseek-ai/libreoffice-kit': './node/external_packages/libreoffice-kit.ts',
'@deepseek-ai/node-addon-system/flock': './node/external_packages/node-addon-system-flock.ts',
'koffi': './node/external_packages/koffi.ts',
'sharp': './node/external_packages/sharp.ts',
'node-pty': './node/external_packages/node-pty.ts',
'execa': './node/external_packages/execa.ts',
'got': './node/external_packages/got.ts',
'@vscode/ripgrep': './node/external_packages/ripgrep.ts',
'@earendil-works/pi-ai': './node/external_packages/pi-ai.ts',
// Node internal modules for callers without `--expose-internals`.
'node-addon-require-builtin': './node/external_packages/node-addon-require-builtin.ts',
// Constructible fakes whose methods are never reached.
'ws': './node/external_packages/ws.ts',
}
/** pi-ai subpaths (`/providers/all`, `/api/*.lazy`) share the one structural stub. */
export const MODULE_PROXY_PREFIXES: Record<string, string> = {
'@earendil-works/pi-ai/': './node/external_packages/pi-ai.ts',
}