@deepseek-ai/dsh-experimental-webworker-runtime 0.1.6-alpha.1

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.
Files changed (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.i18n.yaml +6 -0
  3. package/README.md +75 -0
  4. package/README.zh.md +75 -0
  5. package/lib/client.js +854 -0
  6. package/lib/index.js +3506 -0
  7. package/lib/types/client/apply-injections.d.ts +15 -0
  8. package/lib/types/client/client.d.ts +102 -0
  9. package/lib/types/client/index.d.ts +66 -0
  10. package/lib/types/client/source-chooser.d.ts +8 -0
  11. package/lib/types/compile/transform.d.ts +39 -0
  12. package/lib/types/fixture-manifest.d.ts +26 -0
  13. package/lib/types/image-layout.d.ts +43 -0
  14. package/lib/types/index.d.ts +23 -0
  15. package/lib/types/module-proxies.d.ts +25 -0
  16. package/lib/types/module-system/module-loader.d.ts +177 -0
  17. package/lib/types/module-system/posix-path.d.ts +98 -0
  18. package/lib/types/node/builtin_modules/implemented/abort-error.d.ts +11 -0
  19. package/lib/types/node/builtin_modules/implemented/async_hooks.d.ts +174 -0
  20. package/lib/types/node/builtin_modules/implemented/buffer.d.ts +28 -0
  21. package/lib/types/node/builtin_modules/implemented/child_process.d.ts +178 -0
  22. package/lib/types/node/builtin_modules/implemented/crypto.d.ts +53 -0
  23. package/lib/types/node/builtin_modules/implemented/events.d.ts +84 -0
  24. package/lib/types/node/builtin_modules/implemented/fs/promises.d.ts +39 -0
  25. package/lib/types/node/builtin_modules/implemented/fs-watch.d.ts +119 -0
  26. package/lib/types/node/builtin_modules/implemented/fs.d.ts +502 -0
  27. package/lib/types/node/builtin_modules/implemented/http.d.ts +113 -0
  28. package/lib/types/node/builtin_modules/implemented/module.d.ts +50 -0
  29. package/lib/types/node/builtin_modules/implemented/os.d.ts +115 -0
  30. package/lib/types/node/builtin_modules/implemented/path.d.ts +138 -0
  31. package/lib/types/node/builtin_modules/implemented/perf_hooks.d.ts +13 -0
  32. package/lib/types/node/builtin_modules/implemented/stream.d.ts +22 -0
  33. package/lib/types/node/builtin_modules/implemented/timers/promises.d.ts +36 -0
  34. package/lib/types/node/builtin_modules/implemented/tty.d.ts +18 -0
  35. package/lib/types/node/builtin_modules/implemented/url.d.ts +61 -0
  36. package/lib/types/node/builtin_modules/implemented/util/types.d.ts +12 -0
  37. package/lib/types/node/builtin_modules/implemented/util.d.ts +95 -0
  38. package/lib/types/node/builtin_modules/implemented/zlib.d.ts +65 -0
  39. package/lib/types/node/builtin_modules/mock/dns/promises.d.ts +10 -0
  40. package/lib/types/node/builtin_modules/mock/net.d.ts +61 -0
  41. package/lib/types/node/builtin_modules/mock/sqlite.d.ts +19 -0
  42. package/lib/types/node/builtin_modules/mock/vm.d.ts +25 -0
  43. package/lib/types/node/builtin_modules/mock/worker_threads.d.ts +34 -0
  44. package/lib/types/node/builtins.d.ts +13 -0
  45. package/lib/types/node/external_packages/koffi.d.ts +63 -0
  46. package/lib/types/node/external_packages/node-addon-system-flock.d.ts +19 -0
  47. package/lib/types/node/external_packages/node-pty.d.ts +13 -0
  48. package/lib/types/node/external_packages/pi-ai.d.ts +51 -0
  49. package/lib/types/node/external_packages/replaced-externals.d.ts +9 -0
  50. package/lib/types/node/external_packages/ripgrep.d.ts +16 -0
  51. package/lib/types/node/external_packages/sharp.d.ts +6 -0
  52. package/lib/types/node/external_packages/ws.d.ts +38 -0
  53. package/lib/types/node/globals/crypto.d.ts +3 -0
  54. package/lib/types/node/globals/process.d.ts +78 -0
  55. package/lib/types/node/globals/timers.d.ts +10 -0
  56. package/lib/types/node/notImplementedFail.d.ts +34 -0
  57. package/lib/types/node/process-table.d.ts +50 -0
  58. package/lib/types/polyfill/async-context/als-runtime.d.ts +45 -0
  59. package/lib/types/polyfill/async-context/async-context-hooks.d.ts +6 -0
  60. package/lib/types/shell/ast.d.ts +23 -0
  61. package/lib/types/shell/expand.d.ts +65 -0
  62. package/lib/types/shell/fs-access.d.ts +43 -0
  63. package/lib/types/shell/interpret.d.ts +54 -0
  64. package/lib/types/shell/process/child.d.ts +26 -0
  65. package/lib/types/shell/process/host.d.ts +58 -0
  66. package/lib/types/shell/process/landlock.d.ts +33 -0
  67. package/lib/types/shell/process/protocol.d.ts +74 -0
  68. package/lib/types/shell/process/virtual-executables.d.ts +49 -0
  69. package/lib/types/shell/programs/builtins.d.ts +9 -0
  70. package/lib/types/shell/programs/files.d.ts +11 -0
  71. package/lib/types/shell/programs/index.d.ts +14 -0
  72. package/lib/types/shell/programs/options.d.ts +40 -0
  73. package/lib/types/shell/programs/text.d.ts +9 -0
  74. package/lib/types/shell/types.d.ts +138 -0
  75. package/lib/types/storage/active.d.ts +18 -0
  76. package/lib/types/storage/image-gzip.d.ts +39 -0
  77. package/lib/types/storage/memory.d.ts +308 -0
  78. package/lib/types/storage/paths.d.ts +18 -0
  79. package/lib/types/storage/tar.d.ts +41 -0
  80. package/lib/types/storage/types.d.ts +279 -0
  81. package/lib/types/transport/frames.d.ts +108 -0
  82. package/lib/types/transport/synthetic-http.d.ts +50 -0
  83. package/lib/types/transport/tunnel.d.ts +132 -0
  84. package/lib/types/worker-host.d.ts +165 -0
  85. package/lib/types/worker.d.ts +2 -0
  86. package/lib/worker.js +21879 -0
  87. package/package.json +73 -0
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Page-side interpreter for the structured index injection table. The served
3
+ * form renders the same rows into index.html text; a static worker page has
4
+ * no served HTML, so it executes the table directly. Rows execute strictly in
5
+ * table order, so a global row lands before the scripts that read it.
6
+ */
7
+ import type { IndexInjection } from '@deepseek-ai/dsh-host-webserver';
8
+ /**
9
+ * Execute every row in table order.
10
+ * @param rows - Injection table from the boot payload.
11
+ * @param loadScript - Executes one script-src row; the tunnel's `loadBundle`,
12
+ * because the row URLs (`/plugins/...`) resolve only through the worker.
13
+ */
14
+ export declare function applyIndexInjections(rows: readonly IndexInjection[], loadScript: (src: string) => Promise<void>): Promise<void>;
15
+ //# sourceMappingURL=apply-injections.d.ts.map
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Page half of the postMessage tunnel. It
3
+ * turns fetch-shaped calls into `req` frames and rebuilds Responses from the
4
+ * worker's `res` / `res-head`+`res-chunk`+`res-end` frames, so every consumer
5
+ * (boot payload, bundle transport, ApiClient, Typert RPC) speaks plain HTTP.
6
+ */
7
+ import type { IndexInjection } from '@deepseek-ai/dsh-host-webserver';
8
+ /** Boot payload of the tunnel bootstrap route. */
9
+ export interface BootPayload {
10
+ /** Structured index injection table, executed by the page interpreter. */
11
+ injections: IndexInjection[];
12
+ }
13
+ /** Fetch-shaped transport the client tree consumes. */
14
+ export type TunnelFetch = (input: URL | string, init?: RequestInit) => Promise<Response>;
15
+ /** The page half of the tunnel: one `fetch`-shaped face over `postMessage`. */
16
+ export declare class WorkerTunnel {
17
+ private readonly worker;
18
+ private nextId;
19
+ private readonly unary;
20
+ private readonly bodyStreams;
21
+ private readonly logicalStreams;
22
+ /**
23
+ * In-flight request descriptions, so a refusal names what was refused.
24
+ *
25
+ * A tunnel failure and a failure inside the host tree look identical from the
26
+ * page — both surface as one rejected fetch — and the acceptance run keeps the
27
+ * page console but not the frames. Warning here separates the two without
28
+ * recording anything on the normal path, where no refusal frame ever arrives.
29
+ */
30
+ private readonly inFlight;
31
+ /** Body-phase abort listeners, released when their stream settles. */
32
+ private readonly releases;
33
+ /**
34
+ * Attach to a spawned worker and start consuming response frames.
35
+ * @param worker - the host worker.
36
+ */
37
+ constructor(worker: Worker);
38
+ /**
39
+ * Open the tunnel: the worker assembles its host from this frame.
40
+ * @param image - VFS image URL the worker fetches.
41
+ * @param overlays - Ordered data overlay URLs applied before boot.
42
+ */
43
+ init(image: string, overlays?: readonly string[]): void;
44
+ /** Fetch-shaped entry: one request frame, one Response (streamed when the worker streams). */
45
+ readonly fetch: TunnelFetch;
46
+ /**
47
+ * Open one decoded Gateway Remote stream over the worker-local carrier.
48
+ * @param endpoint - canonical Gateway Remote endpoint.
49
+ * @param payload - decoded endpoint payload.
50
+ * @param signal - logical-stream cancellation.
51
+ * @returns decoded stream values from the worker Host.
52
+ */
53
+ open(endpoint: string, payload: unknown, signal: AbortSignal): AsyncGenerator;
54
+ /**
55
+ * Read the pre-cordis boot payload (the injection table).
56
+ * @returns The payload the page applies before the client tree loads.
57
+ */
58
+ bootPayload(): Promise<BootPayload>;
59
+ /**
60
+ * `loadBundle` seam: take one client bundle through the tunnel and execute it
61
+ * as a classic script, exactly like the shell's same-origin `<script src>`.
62
+ * The image packs each bundle with a trailing `sourceURL` naming its image
63
+ * path, so the blob shows under that name in the debugger instead of as an
64
+ * anonymous blob entry.
65
+ * @param url - Graph combo URL (`/plugins/??<id>/client.js&rev=...`).
66
+ */
67
+ loadBundle(url: string): Promise<void>;
68
+ private rejectOnAbort;
69
+ /**
70
+ * Tear down one request the page abandoned: the maps forget it, the worker
71
+ * is told, and a live body stream errors for its reader.
72
+ * @param id - request id being abandoned.
73
+ * @returns The abort error the caller surfaces.
74
+ */
75
+ private abortRequest;
76
+ /**
77
+ * Hold the caller's signal over the body phase: the head settled, so
78
+ * {@link rejectOnAbort}'s listener is about to go, but a stop must still
79
+ * end the stream. Released when the stream settles.
80
+ * @param id - request id whose body is still crossing.
81
+ * @param signal - the caller's signal.
82
+ */
83
+ private observeStreamAbort;
84
+ /** Release a body-phase abort listener a settled stream no longer needs. */
85
+ private releaseSignal;
86
+ /** Cancel a stream the consumer stopped reading (the head already resolved). */
87
+ private cancelStream;
88
+ /** Best-effort cancellation: a failed worker cannot receive the frame anyway. */
89
+ private abortWorkerOperation;
90
+ /**
91
+ * Report a refusal on the page console, where the acceptance run already keeps it.
92
+ *
93
+ * The prefix names the reporter, not the culprit: a 5xx can equally come from a
94
+ * handler inside the host tree. The message text decides — the worker expands
95
+ * nested causes into it, and its deepest layer is where the failure was thrown.
96
+ * @param id - request id the frame answers.
97
+ * @param outcome - what came back instead of a reply.
98
+ */
99
+ private warnRefusal;
100
+ private receive;
101
+ }
102
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1,66 @@
1
+ import { WorkerTunnel } from './client.ts';
2
+ export { WorkerTunnel, type TunnelFetch } from './client.ts';
3
+ export { applyIndexInjections } from './apply-injections.ts';
4
+ export { IMAGE_FILE_NAME } from '../image-layout.ts';
5
+ export { parsePreviewFixtureManifest, PREVIEW_FIXTURE_MANIFEST_FILE, PREVIEW_FIXTURE_MANIFEST_VERSION, type PreviewFixtureManifest, type PreviewFixtureManifestEntry, } from '../fixture-manifest.ts';
6
+ /** Inputs for {@link connectWorkerHost}. */
7
+ export interface WorkerHostConnectOptions {
8
+ /**
9
+ * VFS image URL, the one deployment-shaped input. Defaults to
10
+ * {@link IMAGE_FILE_NAME} beside the page; a deployment that packs the
11
+ * image elsewhere passes its own URL. Data overlays are independent.
12
+ */
13
+ readonly image?: string | URL;
14
+ /** Ordered data overlay URLs, resolved against the page like the base image. */
15
+ readonly overlays?: readonly (string | URL)[];
16
+ }
17
+ /** Inputs for the optional pre-boot filesystem-source chooser. */
18
+ export interface WorkerHostSourceOptions {
19
+ /** Base VFS image URL; defaults to {@link IMAGE_FILE_NAME} beside the page. */
20
+ readonly image?: string | URL;
21
+ /** Fixture catalog URL; defaults to {@link PREVIEW_FIXTURE_MANIFEST_FILE} beside the image. */
22
+ readonly fixtureManifest?: string | URL;
23
+ }
24
+ /** Filesystem inputs selected before {@link connectWorkerHost}. */
25
+ export interface WorkerHostSource {
26
+ /** Ordered data overlays to pass through unchanged to the Host connection. */
27
+ readonly overlays: readonly URL[];
28
+ }
29
+ /** A page connected to a worker-hosted harness, ready to run a shell entry. */
30
+ export interface WorkerHostConnection {
31
+ readonly worker: Worker;
32
+ readonly tunnel: WorkerTunnel;
33
+ /** Bundle transport for the shell's boot seam. */
34
+ loadBundle(url: string): Promise<void>;
35
+ }
36
+ /**
37
+ * Run the optional pre-boot source-selection stage. Calling this stage holds
38
+ * the stock shell until the caller passes its result to {@link connectWorkerHost};
39
+ * callers that need no chooser call `connectWorkerHost` directly and receive
40
+ * the base image with an empty overlay list.
41
+ * @param options - Base image and optional fixture-catalog locations.
42
+ * @returns The ordered overlays selected by the user.
43
+ */
44
+ export declare function chooseWorkerHostSource(options?: WorkerHostSourceOptions): Promise<WorkerHostSource>;
45
+ /**
46
+ * Connect a spawned host worker and complete the pre-Cordis handshake.
47
+ *
48
+ * The caller constructs the Worker so its bundler resolves the bundle URL
49
+ * statically; the opening `init` frame then carries the base image and ordered
50
+ * overlay locations.
51
+ *
52
+ * Order is fixed by the web boot protocol: the transport global must exist
53
+ * before any bundle executes; the injection table then reproduces the served
54
+ * boot rows — the `__ModuleLoader__` registration queue, the parser-preload
55
+ * bundles, `__DSH_BOOT__`, the theme bootstrap — in table order. The
56
+ * boot-readiness deferred (`__DSH_BOOT_READY__`) is installed before the
57
+ * first await and settles with the handshake, so a client entry evaluating
58
+ * concurrently in the same document holds at its pre-boot await until every
59
+ * row has taken effect, and surfaces a failed handshake instead of
60
+ * proceeding on missing globals.
61
+ * @param worker - The host worker.
62
+ * @param options - Base-image and overlay location overrides.
63
+ * @returns The connection; hand `loadBundle` to the shell entry's boot seam.
64
+ */
65
+ export declare function connectWorkerHost(worker: Worker, options?: WorkerHostConnectOptions): Promise<WorkerHostConnection>;
66
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,8 @@
1
+ /** Pre-boot filesystem-source chooser for static WebWorker previews. */
2
+ /**
3
+ * Render the source chooser and wait for an enabled selection.
4
+ * @param manifestUrl - Built-in fixture catalog URL.
5
+ * @returns Ordered overlay URLs selected for the Worker mount.
6
+ */
7
+ export declare function choosePreviewSource(manifestUrl: URL): Promise<readonly URL[]>;
8
+ //# sourceMappingURL=source-chooser.d.ts.map
@@ -0,0 +1,39 @@
1
+ /** One module the collector considered. */
2
+ export interface LoweredModule {
3
+ /** Transformed body, or the input unchanged when nothing needed lowering. */
4
+ readonly code: string;
5
+ /** False means the entry may be packed as it is. */
6
+ readonly lowered: boolean;
7
+ /**
8
+ * Static module requests the body makes: import and re-export sources,
9
+ * literal dynamic imports and calls through `require`, plus module-scope
10
+ * direct literal calls through an imported `createRequire(import.meta.url)`.
11
+ * Computed and rebased requests resolve (and fail loud) at runtime only.
12
+ */
13
+ readonly moduleRequests: readonly string[];
14
+ /**
15
+ * Literal `import.meta.resolve()` requests. These are URL mappings, not
16
+ * loads: the pack sweep keeps a resolvable target and tolerates a missing
17
+ * one, and the loader answers or throws at the call site.
18
+ */
19
+ readonly metaResolveRequests: readonly string[];
20
+ }
21
+ /**
22
+ * Lower one module at image-pack time.
23
+ *
24
+ * The collector calls this for every JavaScript entry it packs and records
25
+ * `LOWERING_VERSION` in the image manifest; the loader then wraps those entries
26
+ * without parsing them. `lowered: false` reports that the transform would have
27
+ * returned the input verbatim (already CommonJS, no suspension point), so the
28
+ * entry may be packed as it is.
29
+ *
30
+ * Throwing is the intended failure mode: a module this transform cannot express
31
+ * must fail the build rather than ship an image that breaks at load.
32
+ * @param options - Virtual path inside the image and the module source.
33
+ * @returns The code to pack and whether it changed.
34
+ */
35
+ export declare function lowerModuleSource(options: {
36
+ readonly filename: string;
37
+ readonly source: string;
38
+ }): LoweredModule;
39
+ //# sourceMappingURL=transform.d.ts.map
@@ -0,0 +1,26 @@
1
+ /** Browser-readable catalog of built-in Preview filesystem overlays. */
2
+ /** Manifest format version emitted beside the base VFS image. */
3
+ export declare const PREVIEW_FIXTURE_MANIFEST_VERSION = 1;
4
+ /** Leaf name resolved beside the base image. */
5
+ export declare const PREVIEW_FIXTURE_MANIFEST_FILE = "fixtures.json";
6
+ /** One selectable built-in fixture and its ordered overlay archives. */
7
+ export interface PreviewFixtureManifestEntry {
8
+ readonly id: string;
9
+ readonly label: string;
10
+ readonly description: string;
11
+ readonly overlays: readonly string[];
12
+ }
13
+ /** Complete built-in fixture catalog consumed before Worker startup. */
14
+ export interface PreviewFixtureManifest {
15
+ readonly version: number;
16
+ /** Required default fixture id, or null when the chooser should default to an empty overlay. */
17
+ readonly defaultFixture: string | null;
18
+ readonly fixtures: readonly PreviewFixtureManifestEntry[];
19
+ }
20
+ /**
21
+ * Validate the static fixture catalog before it controls Worker fetches.
22
+ * @param value - Parsed JSON response.
23
+ * @returns A detached manifest with unique ids and non-empty overlay lists.
24
+ */
25
+ export declare function parsePreviewFixtureManifest(value: unknown): PreviewFixtureManifest;
26
+ //# sourceMappingURL=fixture-manifest.d.ts.map
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Image layout contract shared by the packer and the worker host: the virtual
3
+ * root, where the composed config and the manifest sit inside the image, and
4
+ * the working directories every image carries empty. One definition, two
5
+ * consumers — the packer writes this layout, the worker host mounts it.
6
+ */
7
+ /** Default virtual root; the runtime mounts the image here unless told otherwise. */
8
+ export declare const DEFAULT_ROOT = "/dsh";
9
+ /**
10
+ * Leaf name of the packed base image: one gzip member holding the ustar archive.
11
+ * The app build writes it beside the page and the page's boot fetches it from
12
+ * there, so the extension is part of what a deployment serves.
13
+ */
14
+ export declare const IMAGE_FILE_NAME = "vfs-image.tar.gz";
15
+ /** Image path the composed profile is written to; the runtime's Loader reads it. */
16
+ export declare const IMAGE_CONFIG_PATH = "config/cordis.yml";
17
+ /** Image path of the manifest the runtime reads before it wraps a single module. */
18
+ export declare const IMAGE_MANIFEST_PATH = "config/vfs-manifest.json";
19
+ /** Home directory under the root; the process shim's `DSH_HOME`/`HOME` default. */
20
+ export declare const IMAGE_HOME_DIRECTORY = "home";
21
+ /** Working directories the host tree expects to exist, empty. */
22
+ export declare const IMAGE_EMPTY_DIRECTORIES: readonly string[];
23
+ /**
24
+ * Top-level directories an overlay archive may populate. Runtime code,
25
+ * configuration, and the lowering manifest remain owned by the base image.
26
+ */
27
+ export declare const IMAGE_OVERLAY_DIRECTORIES: readonly string[];
28
+ /**
29
+ * Identity of the lowered code shape, recorded in the image manifest by the
30
+ * packer and required by the worker host: an image lowered by an older transform
31
+ * would otherwise run against newer wrapper semantics. Bump on any change to
32
+ * emitted code or to {@link WRAPPER_PARAMS}.
33
+ */
34
+ export declare const LOWERING_VERSION = "dsh-worker-transform/1";
35
+ /**
36
+ * Free variables a lowered body expects from its wrapper, in order.
37
+ *
38
+ * Part of the image layout rather than of the transform, because the loader
39
+ * wraps bodies it never parses: the packer emits against these names and the
40
+ * worker binds them, with no compiler in the worker bundle to agree with.
41
+ */
42
+ export declare const WRAPPER_PARAMS: readonly ["exports", "require", "module", "__filename", "__dirname", "__dsh$meta", "__als"];
43
+ //# sourceMappingURL=image-layout.d.ts.map
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Browser-only host runtime: the harness Cordis tree inside a dedicated Web Worker.
3
+ * @module @deepseek-ai/dsh-experimental-webworker-runtime
4
+ */
5
+ export { createAlsRuntime, type AlsCausality, type AlsRuntime, type AlsSnapshot, type AlsToken, } from './polyfill/async-context/als-runtime.ts';
6
+ export { parseInboundFrame, type TunnelAbortFrame, type TunnelInboundFrame, type TunnelOutboundFrame, type TunnelRequestFrame, type TunnelRequestId, type TunnelResponseChunkFrame, type TunnelResponseEndFrame, type TunnelResponseErrorFrame, type TunnelResponseFrame, type TunnelResponseHeadFrame, type TunnelStreamEndFrame, type TunnelStreamErrorFrame, type TunnelStreamItemFrame, type TunnelStreamOpenFrame, } from './transport/frames.ts';
7
+ export { DEFAULT_CONDITIONS, requireActiveModuleLoader, setActiveModuleLoader, WorkerModuleLoader, type Resolution, type StaticModuleFactory, type WorkerModuleLoaderOptions, type WorkerRequire, } from './module-system/module-loader.ts';
8
+ export * as posixPath from './module-system/posix-path.ts';
9
+ export { MODULE_PROXIES, MODULE_PROXY_PREFIXES } from './module-proxies.ts';
10
+ export { REPLACED_EXTERNAL_PACKAGES } from './node/external_packages/replaced-externals.ts';
11
+ export { createSyntheticExchange, type RequestListener, type ResponseSink, type SyntheticExchange, } from './transport/synthetic-http.ts';
12
+ export { lowerModuleSource, type LoweredModule } from './compile/transform.ts';
13
+ export { API_PREFIX, SYNTHETIC_HOST, TunnelServer, type TunnelPort, type TunnelSeams, type TunnelServerOptions, } from './transport/tunnel.ts';
14
+ export { installProcessGlobal, type ProcessShim, type ProcessShimOptions } from './node/globals/process.ts';
15
+ export { createWorkerHost, type WorkerHost, type WorkerHostOptions, } from './worker-host.ts';
16
+ export { DEFAULT_ROOT, IMAGE_CONFIG_PATH, IMAGE_EMPTY_DIRECTORIES, IMAGE_FILE_NAME, IMAGE_HOME_DIRECTORY, IMAGE_MANIFEST_PATH, IMAGE_OVERLAY_DIRECTORIES, LOWERING_VERSION, WRAPPER_PARAMS, } from './image-layout.ts';
17
+ export { parsePreviewFixtureManifest, PREVIEW_FIXTURE_MANIFEST_FILE, PREVIEW_FIXTURE_MANIFEST_VERSION, type PreviewFixtureManifest, type PreviewFixtureManifestEntry, } from './fixture-manifest.ts';
18
+ export { loadVfsImage, loadVfsOverlay, MemoryVfs } from './storage/memory.ts';
19
+ export { inflateImage, inflateImageStream } from './storage/image-gzip.ts';
20
+ export { packTar, parseTar, type TarEntry } from './storage/tar.ts';
21
+ export { requireActiveVfs, setActiveVfs } from './storage/active.ts';
22
+ export { type VfsDir, type VfsDirent, type VfsEncoding, type VfsError, type VfsFileHandle, type VfsReadOptions, type VfsStats, type VfsWriteOptions, } from './storage/types.ts';
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The worker bundle's module proxy table: the ONLY platform fork of the host
3
+ * tree. Entries replace Node builtins, external npm packages, and the native
4
+ * flock subpath; other workspace and vendored modules are 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. Keys are
19
+ * exact module specifiers; the native system package's Landlock entry stays
20
+ * unmodified while its flock subpath is replaced.
21
+ */
22
+ export declare const MODULE_PROXIES: Record<string, string>;
23
+ /** pi-ai subpaths (`/providers/all`, `/api/*.lazy`) share the one structural stub. */
24
+ export declare const MODULE_PROXY_PREFIXES: Record<string, string>;
25
+ //# sourceMappingURL=module-proxies.d.ts.map
@@ -0,0 +1,177 @@
1
+ /**
2
+ * CommonJS module loader over the worker VFS. It fills the `loader.internal`
3
+ * seam Cordis uses for every entry import, and backs the `node:module`
4
+ * `createRequire` proxy that `typert-loader`, `client-modules`, and the plugin
5
+ * package inventory resolve package metadata through.
6
+ *
7
+ * Resolution is a narrowed Node `require` algorithm: `exports` walk with a
8
+ * fixed condition order, extension probing, and one cache keyed by resolved
9
+ * absolute path. Module bodies are wrapped as the image holds them: lowering is
10
+ * the packer's job, so nothing here parses JavaScript.
11
+ * @module @deepseek-ai/dsh-experimental-webworker-runtime/src/module-system/module-loader
12
+ */
13
+ import { type AlsCausality } from '../polyfill/async-context/als-runtime.ts';
14
+ import type { MemoryVfs } from '../storage/memory.ts';
15
+ /** Condition keys honoured in `exports`, in order; `node` is deliberately absent. */
16
+ export declare const DEFAULT_CONDITIONS: readonly ["browser", "require", "import", "default"];
17
+ /**
18
+ * One entry of the static-module table. The loader calls it when a `require`
19
+ * names that specifier and never before, so resolution alone — `require.resolve`
20
+ * or `import.meta.resolve` — evaluates nothing. Repeated requires of one
21
+ * specifier must answer the same module instance: callers depend on class
22
+ * identity across requires (`instanceof EventEmitter`, `Buffer.isBuffer`), so a
23
+ * factory that builds its value has to memoize it.
24
+ * @returns The module object served for that specifier.
25
+ */
26
+ export type StaticModuleFactory = () => unknown;
27
+ /** Where a specifier resolved to. */
28
+ export type Resolution = {
29
+ readonly kind: 'static';
30
+ readonly specifier: string;
31
+ readonly factory: StaticModuleFactory;
32
+ } | {
33
+ readonly kind: 'file';
34
+ readonly path: string;
35
+ };
36
+ /** Node-loader-compatible resolution returned through the Cordis internal seam. */
37
+ export interface WorkerInternalResolution {
38
+ readonly format: 'builtin' | 'commonjs' | 'json';
39
+ /** File URL for VFS modules; the original bare specifier for builtins. */
40
+ readonly url: string;
41
+ }
42
+ /** Resolution helpers carried by a Worker-backed CommonJS require. */
43
+ export interface WorkerRequireResolve {
44
+ /**
45
+ * Resolve one specifier without evaluating its module.
46
+ * @param specifier - Module request relative to the require base.
47
+ * @returns Static or VFS-backed module identity.
48
+ */
49
+ (specifier: string): string;
50
+ /**
51
+ * Return the directories this loader's Node-style package discovery searches.
52
+ * @param specifier - Module request whose lookup roots are requested.
53
+ * @returns Search roots, or null for a Worker-provided module.
54
+ */
55
+ paths(specifier: string): string[] | null;
56
+ }
57
+ /** The `require` function shape the roster consumes through `createRequire`. */
58
+ export interface WorkerRequire {
59
+ (specifier: string): unknown;
60
+ readonly resolve: WorkerRequireResolve;
61
+ }
62
+ /** Construction inputs for {@link WorkerModuleLoader}. */
63
+ export interface WorkerModuleLoaderOptions {
64
+ /** Filesystem holding package metadata and module sources. */
65
+ readonly vfs: MemoryVfs;
66
+ /** Virtual root whose `node_modules` bare specifiers resolve against. */
67
+ readonly root?: string;
68
+ /**
69
+ * Modules served from the worker bundle instead of the VFS: `node:*` proxies
70
+ * and the loud stubs for excluded npm packages, each behind a
71
+ * {@link StaticModuleFactory}.
72
+ */
73
+ readonly staticModules: Readonly<Record<string, StaticModuleFactory>>;
74
+ /**
75
+ * Prefix-matched proxies for packages whose subpaths are open-ended: a
76
+ * specifier starting with the key resolves to its module. Exact keys win, and
77
+ * the longest matching prefix wins among prefixes.
78
+ */
79
+ readonly staticModulePrefixes?: Readonly<Record<string, StaticModuleFactory>>;
80
+ /** Overrides {@link DEFAULT_CONDITIONS}. */
81
+ readonly conditions?: readonly string[];
82
+ /**
83
+ * Ambient-store snapshot face for the suspended `rewrite-await` route; it is
84
+ * read only when that route is the configured {@link lowering}.
85
+ */
86
+ readonly alsCausality?: AlsCausality;
87
+ }
88
+ /** Loader for one VFS mount; construct once per worker. */
89
+ export declare class WorkerModuleLoader {
90
+ private readonly vfs;
91
+ private readonly root;
92
+ private readonly staticModules;
93
+ private readonly staticPrefixes;
94
+ private readonly conditions;
95
+ private readonly als;
96
+ private readonly modules;
97
+ private readonly manifests;
98
+ private readonly stack;
99
+ /**
100
+ * The Cordis module seam. `parentURL` positions relative specifiers;
101
+ * import attributes are ignored, as the client implementation does.
102
+ */
103
+ readonly internal: {
104
+ readonly version: 'worker';
105
+ import(specifier: string, parentURL?: string, attributes?: unknown): Promise<unknown>;
106
+ resolve(specifier: string, parentURL?: string, attributes?: unknown): Promise<WorkerInternalResolution>;
107
+ resolveSync(specifier: string, parentURL?: string, attributes?: unknown): WorkerInternalResolution;
108
+ };
109
+ constructor(options: WorkerModuleLoaderOptions);
110
+ private fail;
111
+ /** @returns Directory a base path or URL resolves specifiers from. */
112
+ private baseDirectoryOf;
113
+ private manifestOf;
114
+ /** Walk one `exports` value against the condition set and requested subpath. */
115
+ private selectExport;
116
+ /** Pick the first condition branch this runtime satisfies. */
117
+ private selectCondition;
118
+ /** Extension and directory probing for a concrete path. */
119
+ private probe;
120
+ /** @returns The Worker-provided implementation of a static specifier. */
121
+ private staticModule;
122
+ /**
123
+ * Resolve a specifier the way the module that requested it would.
124
+ * @param specifier - Bare name, relative path, absolute path, or file URL.
125
+ * @param fromDirectory - Directory of the requesting module.
126
+ * @returns Static module or the resolved VFS path.
127
+ */
128
+ resolve(specifier: string, fromDirectory: string): Resolution;
129
+ /**
130
+ * Load a resolved module, reusing the cache and tolerating cycles with
131
+ * CommonJS partial-export semantics.
132
+ * @param resolution - Result of {@link resolve}.
133
+ * @returns The module's exports.
134
+ */
135
+ load(resolution: Resolution): unknown;
136
+ /**
137
+ * Compile a body the image already lowered.
138
+ *
139
+ * Module syntax reaching here means the image was packed by something other
140
+ * than the packer, or its collector missed the entry. The worker carries no
141
+ * transform to recover with, so it names the image as the thing to rebuild.
142
+ * @param code - Module body as the image holds it.
143
+ * @param path - Resolved VFS path.
144
+ * @returns The wrapper factory.
145
+ */
146
+ private compile;
147
+ /**
148
+ * Build a `require` bound to a directory.
149
+ * @param fromDirectory - Directory relative specifiers resolve against.
150
+ * @returns Callable require with `resolve`.
151
+ */
152
+ requireFrom(fromDirectory: string): WorkerRequire;
153
+ /**
154
+ * `node:module` `createRequire` for the VFS.
155
+ * @param base - Module path, directory path, or `file:` URL.
156
+ * @returns Require bound to that base.
157
+ */
158
+ createRequire(base: string | URL): WorkerRequire;
159
+ /**
160
+ * Report what this loader has done, for the host's boot diagnostics.
161
+ * @returns How many module bodies it has run.
162
+ */
163
+ usage(): {
164
+ modules: number;
165
+ };
166
+ }
167
+ /**
168
+ * Publish the loader the `node:module` proxy resolves through.
169
+ * @param loader - Loader built by the worker entry.
170
+ */
171
+ export declare function setActiveModuleLoader(loader: WorkerModuleLoader): void;
172
+ /**
173
+ * Read the published loader.
174
+ * @returns The active loader.
175
+ */
176
+ export declare function requireActiveModuleLoader(): WorkerModuleLoader;
177
+ //# sourceMappingURL=module-loader.d.ts.map
@@ -0,0 +1,98 @@
1
+ /**
2
+ * POSIX path helpers for the worker VFS: one absolute root, no drive letters,
3
+ * no symlinks.
4
+ *
5
+ * **Not a `node:path` substitute.** {@link dirname}, {@link basename}, and
6
+ * {@link parse} normalize first, because every caller here hands the result to
7
+ * the VFS, which keys files by normalized absolute path — `dirname('/a/b/..')`
8
+ * answers `/`, the directory that actually holds the entry. Node's three are
9
+ * purely lexical and answer `/a/b`. A `node:path` proxy owes callers Node's
10
+ * literal answers, so it needs its own port of Node's implementation rather than
11
+ * a facade over this module; measured over ~200 cases, the normalizing and
12
+ * lexical forms diverge in 45, all in these three functions. The Node-facing
13
+ * port is pinned separately by `../../tests/node/path-diff.spec.ts`.
14
+ * @module @deepseek-ai/dsh-experimental-webworker-runtime/src/module-system/posix-path
15
+ */
16
+ /** Path separator of the virtual filesystem. */
17
+ export declare const SEP = "/";
18
+ /**
19
+ * Collapse `.` and `..` segments.
20
+ * @param path - Path with any number of separators.
21
+ * @returns Normalized path; a relative input keeps leading `..` segments.
22
+ */
23
+ export declare function normalize(path: string): string;
24
+ /**
25
+ * Join segments and normalize the result.
26
+ * @param segments - Path segments.
27
+ * @returns Joined path, `.` when nothing remains.
28
+ */
29
+ export declare function join(...segments: string[]): string;
30
+ /**
31
+ * Resolve segments right to left against a base directory.
32
+ * @param segments - Path segments; the first absolute one wins.
33
+ * @returns Absolute normalized path.
34
+ */
35
+ export declare function resolve(...segments: string[]): string;
36
+ /**
37
+ * Directory part of a path, after normalization (see the module note).
38
+ * @param path - Path to inspect.
39
+ * @returns Parent path; `/` for root children and `.` for bare names.
40
+ */
41
+ export declare function dirname(path: string): string;
42
+ /**
43
+ * Last segment of a path, after normalization (see the module note).
44
+ * @param path - Path to inspect.
45
+ * @param suffix - Optional suffix to strip.
46
+ * @returns Final segment.
47
+ */
48
+ export declare function basename(path: string, suffix?: string): string;
49
+ /**
50
+ * Extension of the last segment, dot included.
51
+ * @param path - Path to inspect.
52
+ * @returns Extension, or an empty string when there is none.
53
+ */
54
+ export declare function extname(path: string): string;
55
+ /**
56
+ * Report whether a path starts at the root.
57
+ * @param path - Path to inspect.
58
+ * @returns True for absolute paths.
59
+ */
60
+ export declare function isAbsolute(path: string): boolean;
61
+ /**
62
+ * Relative path from one absolute path to another.
63
+ * @param from - Source directory.
64
+ * @param to - Target path.
65
+ * @returns Relative path using `..` segments.
66
+ */
67
+ export declare function relative(from: string, to: string): string;
68
+ /**
69
+ * Split a path into components, after normalization (see the module note).
70
+ * @param path - Path to split.
71
+ * @returns Root, directory, base name, extension, and stem.
72
+ */
73
+ export declare function parse(path: string): {
74
+ root: string;
75
+ dir: string;
76
+ base: string;
77
+ ext: string;
78
+ name: string;
79
+ };
80
+ /**
81
+ * Node's Windows-only namespaced-path conversion.
82
+ * @param path - the path to convert.
83
+ * @returns The path unchanged; namespaced paths are a Windows concept.
84
+ */
85
+ export declare function toNamespacedPath(path: string): string;
86
+ /**
87
+ * Convert a VFS path into a `file:` URL string.
88
+ * @param path - Absolute VFS path.
89
+ * @returns URL text with each segment percent-encoded.
90
+ */
91
+ export declare function pathToFileUrl(path: string): string;
92
+ /**
93
+ * Convert a `file:` URL back into a VFS path.
94
+ * @param url - URL text or URL instance.
95
+ * @returns Absolute VFS path.
96
+ */
97
+ export declare function fileUrlToPath(url: string | URL): string;
98
+ //# sourceMappingURL=posix-path.d.ts.map
@@ -0,0 +1,11 @@
1
+ /** Build the Node-style cancellation error shared by abortable builtin APIs. */
2
+ /**
3
+ * Create an `AbortError` carrying Node's stable error code.
4
+ * @param reason - Optional AbortSignal reason exposed as the error cause.
5
+ * @returns A Node-compatible abort error.
6
+ */
7
+ export declare function abortError(reason?: unknown): Error & {
8
+ code: string;
9
+ cause?: unknown;
10
+ };
11
+ //# sourceMappingURL=abort-error.d.ts.map