@nimbus-sh/worker 0.2.3 → 0.4.0

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 (146) hide show
  1. package/dist/_shared/session-router.d.ts +8 -0
  2. package/dist/_shared/session-router.d.ts.map +1 -1
  3. package/dist/_shared/session-router.js +8 -0
  4. package/dist/esbuild-wasm-bundle.generated.d.ts +1 -1
  5. package/dist/esbuild-wasm-bundle.generated.js +1 -1
  6. package/dist/facets/cirrus-real.js +1 -1
  7. package/dist/facets/manager.d.ts +43 -129
  8. package/dist/facets/manager.d.ts.map +1 -1
  9. package/dist/facets/manager.js +107 -318
  10. package/dist/facets/opencode-staging.d.ts +1 -1
  11. package/dist/facets/opencode-staging.d.ts.map +1 -1
  12. package/dist/facets/opencode-staging.js +3 -0
  13. package/dist/facets/real-vite-hmr.js +1 -1
  14. package/dist/facets/vite-dev-server.d.ts +4 -4
  15. package/dist/facets/vite-dev-server.js +5 -5
  16. package/dist/git/commands.d.ts +8 -0
  17. package/dist/git/commands.d.ts.map +1 -1
  18. package/dist/git/commands.js +41 -9
  19. package/dist/git/network-facet.d.ts +1 -1
  20. package/dist/git/network-facet.d.ts.map +1 -1
  21. package/dist/git/network-facet.js +39 -15
  22. package/dist/git-bundle.generated.d.ts +2 -2
  23. package/dist/git-bundle.generated.d.ts.map +1 -1
  24. package/dist/git-bundle.generated.js +3 -3
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +9 -1
  27. package/dist/loaders/child-process/spawn-facet.js +1 -1
  28. package/dist/loaders/child-process/spawn-pool.d.ts.map +1 -1
  29. package/dist/loaders/child-process/spawn-pool.js +2 -2
  30. package/dist/loaders/generated-workers.d.ts +2 -2
  31. package/dist/loaders/generated-workers.d.ts.map +1 -1
  32. package/dist/loaders/generated-workers.js +3 -3
  33. package/dist/loaders/npm-resolve-preamble.d.ts +3 -3
  34. package/dist/loaders/npm-resolve-preamble.js +3 -3
  35. package/dist/loaders/pre-bundle-preamble.d.ts +5 -5
  36. package/dist/loaders/pre-bundle-preamble.js +6 -6
  37. package/dist/loaders/process-host.d.ts +6 -107
  38. package/dist/loaders/process-host.d.ts.map +1 -1
  39. package/dist/loaders/process-host.js +6 -405
  40. package/dist/npm/install-batch-facet.d.ts +1 -1
  41. package/dist/npm/install-batch-facet.js +1 -1
  42. package/dist/npm/installer.d.ts +6 -6
  43. package/dist/npm/installer.d.ts.map +1 -1
  44. package/dist/npm/installer.js +28 -27
  45. package/dist/npm/pre-bundle-facet.d.ts +2 -2
  46. package/dist/npm/pre-bundle-facet.js +5 -5
  47. package/dist/npm/r2-cache.d.ts +1 -1
  48. package/dist/npm/resolve-facet.d.ts +1 -1
  49. package/dist/npm/resolve-facet.js +1 -1
  50. package/dist/npm/resolve-one-facet.d.ts +5 -5
  51. package/dist/npm/resolve-one-facet.js +5 -5
  52. package/dist/router/index.js +2 -2
  53. package/dist/router/remote-api.js +9 -1
  54. package/dist/runtime/bun-repl.d.ts +1 -1
  55. package/dist/runtime/bun-repl.js +3 -3
  56. package/dist/runtime/esbuild-wasm-bytes.js +1 -1
  57. package/dist/runtime/facet-loader-host.d.ts +5 -8
  58. package/dist/runtime/facet-loader-host.d.ts.map +1 -1
  59. package/dist/runtime/facet-loader-host.js +7 -11
  60. package/dist/runtime/node-repl.js +2 -2
  61. package/dist/runtime/node-shims-artifact.js +1 -1
  62. package/dist/runtime/node-shims.js +2 -1
  63. package/dist/runtime/opencode-artifact.js +1 -1
  64. package/dist/runtime/opentui-wasm-bytes.js +1 -1
  65. package/dist/runtime/python-repl.js +3 -3
  66. package/dist/runtime/ruby-repl.js +2 -2
  67. package/dist/runtime/ruby-resident.js +1 -1
  68. package/dist/runtime/sqlite-wasm-bytes.js +1 -1
  69. package/dist/session/diag.js +1 -1
  70. package/dist/session/hibernation.d.ts +20 -53
  71. package/dist/session/hibernation.d.ts.map +1 -1
  72. package/dist/session/hibernation.js +57 -194
  73. package/dist/session/init-phases.d.ts +2 -3
  74. package/dist/session/init-phases.d.ts.map +1 -1
  75. package/dist/session/init-phases.js +3 -2
  76. package/dist/session/init.d.ts.map +1 -1
  77. package/dist/session/init.js +8 -4
  78. package/dist/session/keys.d.ts +14 -37
  79. package/dist/session/keys.d.ts.map +1 -1
  80. package/dist/session/keys.js +18 -37
  81. package/dist/session/nimbus-session.d.ts +10 -15
  82. package/dist/session/nimbus-session.d.ts.map +1 -1
  83. package/dist/session/nimbus-session.js +28 -31
  84. package/dist/session/port-capability.d.ts +43 -0
  85. package/dist/session/port-capability.d.ts.map +1 -0
  86. package/dist/session/port-capability.js +49 -0
  87. package/dist/session/programmatic.d.ts +39 -5
  88. package/dist/session/programmatic.d.ts.map +1 -1
  89. package/dist/session/programmatic.js +150 -19
  90. package/dist/session/routes.d.ts +2 -0
  91. package/dist/session/routes.d.ts.map +1 -1
  92. package/dist/session/routes.js +96 -20
  93. package/dist/session/rpc.d.ts +36 -9
  94. package/dist/session/rpc.d.ts.map +1 -1
  95. package/dist/session/rpc.js +84 -24
  96. package/dist/session/start-real-vite.d.ts.map +1 -1
  97. package/dist/session/start-real-vite.js +3 -1
  98. package/dist/session/state-store.d.ts +3 -2
  99. package/dist/session/state-store.d.ts.map +1 -1
  100. package/dist/session/state-store.js +3 -2
  101. package/dist/session/supervisor-rpc.d.ts.map +1 -1
  102. package/dist/session/supervisor-rpc.js +7 -4
  103. package/dist/session/ws.d.ts +1 -3
  104. package/dist/session/ws.d.ts.map +1 -1
  105. package/dist/session/ws.js +4 -3
  106. package/dist/wrangler/nimbus-wrangler.js +1 -1
  107. package/package.json +4 -2
  108. package/scripts/bundle-esbuild-wasm.mjs +2 -2
  109. package/scripts/bundle-facet-workers.mjs +5 -7
  110. package/scripts/bundle-sqlite-wasm.mjs +1 -1
  111. package/dist/facets/inner-do-registry.d.ts +0 -41
  112. package/dist/facets/inner-do-registry.d.ts.map +0 -1
  113. package/dist/facets/inner-do-registry.js +0 -51
  114. package/dist/facets/launch-pacer.d.ts +0 -111
  115. package/dist/facets/launch-pacer.d.ts.map +0 -1
  116. package/dist/facets/launch-pacer.js +0 -130
  117. package/dist/loaders/fanout-pool.d.ts +0 -207
  118. package/dist/loaders/fanout-pool.d.ts.map +0 -1
  119. package/dist/loaders/fanout-pool.js +0 -363
  120. package/dist/loaders/loader-pool.d.ts +0 -294
  121. package/dist/loaders/loader-pool.d.ts.map +0 -1
  122. package/dist/loaders/loader-pool.js +0 -642
  123. package/dist/loaders/process-fabric.d.ts +0 -509
  124. package/dist/loaders/process-fabric.d.ts.map +0 -1
  125. package/dist/loaders/process-fabric.js +0 -360
  126. package/dist/loaders/vendor/errors.d.ts +0 -24
  127. package/dist/loaders/vendor/errors.d.ts.map +0 -1
  128. package/dist/loaders/vendor/errors.js +0 -46
  129. package/dist/loaders/vendor/serialize.d.ts +0 -3
  130. package/dist/loaders/vendor/serialize.d.ts.map +0 -1
  131. package/dist/loaders/vendor/serialize.js +0 -25
  132. package/dist/loaders/vendor/types.d.ts +0 -69
  133. package/dist/loaders/vendor/types.d.ts.map +0 -1
  134. package/dist/loaders/vendor/types.js +0 -4
  135. package/dist/loaders/workerd-facet-host.d.ts +0 -141
  136. package/dist/loaders/workerd-facet-host.d.ts.map +0 -1
  137. package/dist/loaders/workerd-facet-host.js +0 -284
  138. package/dist/session/bindings.d.ts +0 -209
  139. package/dist/session/bindings.d.ts.map +0 -1
  140. package/dist/session/bindings.js +0 -680
  141. package/dist/session/ctx-exports.d.ts +0 -16
  142. package/dist/session/ctx-exports.d.ts.map +0 -1
  143. package/dist/session/ctx-exports.js +0 -22
  144. package/dist/session/ws-hibernation-config.d.ts +0 -64
  145. package/dist/session/ws-hibernation-config.d.ts.map +0 -1
  146. package/dist/session/ws-hibernation-config.js +0 -89
@@ -1,16 +0,0 @@
1
- /**
2
- * ctx-exports.ts — leaf module holding the ctx.exports reference.
3
- *
4
- * Isolated from src/index.ts so helpers (notably src/loaders/loader-pool.ts)
5
- * can read `ctx.exports` without transitively importing the Durable Object
6
- * classes. Keeping this a leaf (no imports) lets the pool be unit-tested in
7
- * a plain Node/Bun process.
8
- *
9
- * The fetch handler in src/index.ts calls `setCtxExports(ctx.exports)` on
10
- * the first request; callers like NimbusLoaderPool read via `getCtxExports()`.
11
- * If the pool is constructed before the first fetch (unlikely) it just gets
12
- * null — the caller decides how to degrade.
13
- */
14
- export declare function setCtxExports(value: any): void;
15
- export declare function getCtxExports(): any;
16
- //# sourceMappingURL=ctx-exports.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ctx-exports.d.ts","sourceRoot":"","sources":["../../src/session/ctx-exports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,wBAAgB,aAAa,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI,CAG9C;AAED,wBAAgB,aAAa,IAAI,GAAG,CAEnC"}
@@ -1,22 +0,0 @@
1
- /**
2
- * ctx-exports.ts — leaf module holding the ctx.exports reference.
3
- *
4
- * Isolated from src/index.ts so helpers (notably src/loaders/loader-pool.ts)
5
- * can read `ctx.exports` without transitively importing the Durable Object
6
- * classes. Keeping this a leaf (no imports) lets the pool be unit-tested in
7
- * a plain Node/Bun process.
8
- *
9
- * The fetch handler in src/index.ts calls `setCtxExports(ctx.exports)` on
10
- * the first request; callers like NimbusLoaderPool read via `getCtxExports()`.
11
- * If the pool is constructed before the first fetch (unlikely) it just gets
12
- * null — the caller decides how to degrade.
13
- */
14
- let _ctxExports = null;
15
- export function setCtxExports(value) {
16
- if (_ctxExports)
17
- return; // first-write-wins, same as the prior inline impl
18
- _ctxExports = value;
19
- }
20
- export function getCtxExports() {
21
- return _ctxExports;
22
- }
@@ -1,64 +0,0 @@
1
- /**
2
- * ws-hibernation-config.ts — W9 (CF research §C.3 + §C.4) configuration
3
- * for setWebSocketAutoResponse + setHibernatableWebSocketEventTimeout.
4
- *
5
- * Why a dedicated module:
6
- * - NimbusSession's constructor is already crowded; the calls have
7
- * specific failure modes (workerd version dependence, optional
8
- * globals) that deserve isolation.
9
- * - Unit-testable in Node by passing a mock ctx — the constructor
10
- * itself can't be (it pulls cloudflare:workers).
11
- *
12
- * What this does, in order:
13
- * 1. setWebSocketAutoResponse(WebSocketRequestResponsePair('ping','pong'))
14
- * — vite HMR clients ping every 30s and idle xterm tabs ping per
15
- * minute. Without auto-response, every ping wakes the actor from
16
- * hibernation: ~2880 wakes/day per idle tab. After this, zero
17
- * billable wakes for matched ping/pong frames. Auto-response config
18
- * survives hibernation per the STOR/Durable Objects WebSocket
19
- * Primer (wiki page id 1372566651).
20
- * 2. setHibernatableWebSocketEventTimeout(5000) — bound a single
21
- * hibernation message handler. Long-running work runs in facets
22
- * with their own CPU budget; the supervisor's WS handlers should
23
- * enqueue then return. 5 s recommended in CF research §C.3.
24
- *
25
- * Both calls are gated on try/catch:
26
- * - workerd builds before mid-2024 don't expose either method.
27
- * - WebSocketRequestResponsePair is a workerd global; absent in Node.
28
- * Failure is reported honestly via the return value so /api/_diag/memory
29
- * can show whether the runtime supported the configuration.
30
- */
31
- /**
32
- * Recommended hibernation event timeout (ms). 5 s per CF research §C.3
33
- * — long enough for the heaviest non-facet WS message handler observed
34
- * in W5 telemetry (~120 ms p99 for a heavy autocomplete request), short
35
- * enough to bound a runaway handler before it pins the actor.
36
- */
37
- export declare const NIMBUS_HIBERNATION_EVENT_TIMEOUT_MS = 5000;
38
- /** Public ping/pong contract — clients send `ping`, receive `pong`. */
39
- export declare const WS_AUTO_RESPONSE_REQUEST = "ping";
40
- export declare const WS_AUTO_RESPONSE_RESPONSE = "pong";
41
- export interface WsHibernationConfigResult {
42
- /** True iff `setWebSocketAutoResponse` ran without throwing. */
43
- autoResponseConfigured: boolean;
44
- /**
45
- * The timeout (in ms) we successfully set, or null if the call wasn't
46
- * available / threw. Reported separately from autoResponseConfigured
47
- * so a partial-support workerd shows the partial truth.
48
- */
49
- timeoutSetMs: number | null;
50
- /** Optional error message — human-readable, never thrown. */
51
- autoResponseError?: string;
52
- timeoutError?: string;
53
- }
54
- /**
55
- * Configure WS hibernation behaviours on a DurableObjectState. Idempotent
56
- * — safe to call multiple times. Returns a result that NimbusSession
57
- * surfaces via /api/_diag/memory under the `hib` key.
58
- *
59
- * The `ctx` parameter is structurally typed (anything with the right
60
- * methods works) so this module stays Node-testable. In production the
61
- * caller passes the real `this.ctx` from NimbusSession's constructor.
62
- */
63
- export declare function configureWsHibernation(ctx: any): WsHibernationConfigResult;
64
- //# sourceMappingURL=ws-hibernation-config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ws-hibernation-config.d.ts","sourceRoot":"","sources":["../../src/session/ws-hibernation-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,mCAAmC,OAAO,CAAC;AAExD,uEAAuE;AACvE,eAAO,MAAM,wBAAwB,SAAS,CAAC;AAC/C,eAAO,MAAM,yBAAyB,SAAS,CAAC;AAEhD,MAAM,WAAW,yBAAyB;IACxC,gEAAgE;IAChE,sBAAsB,EAAE,OAAO,CAAC;IAChC;;;;OAIG;IACH,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,6DAA6D;IAC7D,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,GAAG,GACP,yBAAyB,CAqC3B"}
@@ -1,89 +0,0 @@
1
- /**
2
- * ws-hibernation-config.ts — W9 (CF research §C.3 + §C.4) configuration
3
- * for setWebSocketAutoResponse + setHibernatableWebSocketEventTimeout.
4
- *
5
- * Why a dedicated module:
6
- * - NimbusSession's constructor is already crowded; the calls have
7
- * specific failure modes (workerd version dependence, optional
8
- * globals) that deserve isolation.
9
- * - Unit-testable in Node by passing a mock ctx — the constructor
10
- * itself can't be (it pulls cloudflare:workers).
11
- *
12
- * What this does, in order:
13
- * 1. setWebSocketAutoResponse(WebSocketRequestResponsePair('ping','pong'))
14
- * — vite HMR clients ping every 30s and idle xterm tabs ping per
15
- * minute. Without auto-response, every ping wakes the actor from
16
- * hibernation: ~2880 wakes/day per idle tab. After this, zero
17
- * billable wakes for matched ping/pong frames. Auto-response config
18
- * survives hibernation per the STOR/Durable Objects WebSocket
19
- * Primer (wiki page id 1372566651).
20
- * 2. setHibernatableWebSocketEventTimeout(5000) — bound a single
21
- * hibernation message handler. Long-running work runs in facets
22
- * with their own CPU budget; the supervisor's WS handlers should
23
- * enqueue then return. 5 s recommended in CF research §C.3.
24
- *
25
- * Both calls are gated on try/catch:
26
- * - workerd builds before mid-2024 don't expose either method.
27
- * - WebSocketRequestResponsePair is a workerd global; absent in Node.
28
- * Failure is reported honestly via the return value so /api/_diag/memory
29
- * can show whether the runtime supported the configuration.
30
- */
31
- /**
32
- * Recommended hibernation event timeout (ms). 5 s per CF research §C.3
33
- * — long enough for the heaviest non-facet WS message handler observed
34
- * in W5 telemetry (~120 ms p99 for a heavy autocomplete request), short
35
- * enough to bound a runaway handler before it pins the actor.
36
- */
37
- export const NIMBUS_HIBERNATION_EVENT_TIMEOUT_MS = 5000;
38
- /** Public ping/pong contract — clients send `ping`, receive `pong`. */
39
- export const WS_AUTO_RESPONSE_REQUEST = 'ping';
40
- export const WS_AUTO_RESPONSE_RESPONSE = 'pong';
41
- /**
42
- * Configure WS hibernation behaviours on a DurableObjectState. Idempotent
43
- * — safe to call multiple times. Returns a result that NimbusSession
44
- * surfaces via /api/_diag/memory under the `hib` key.
45
- *
46
- * The `ctx` parameter is structurally typed (anything with the right
47
- * methods works) so this module stays Node-testable. In production the
48
- * caller passes the real `this.ctx` from NimbusSession's constructor.
49
- */
50
- export function configureWsHibernation(ctx) {
51
- const result = {
52
- autoResponseConfigured: false,
53
- timeoutSetMs: null,
54
- };
55
- // Step 1: auto-response.
56
- const Pair = globalThis.WebSocketRequestResponsePair;
57
- if (typeof ctx?.setWebSocketAutoResponse === 'function' && typeof Pair === 'function') {
58
- try {
59
- const pair = new Pair(WS_AUTO_RESPONSE_REQUEST, WS_AUTO_RESPONSE_RESPONSE);
60
- ctx.setWebSocketAutoResponse(pair);
61
- result.autoResponseConfigured = true;
62
- }
63
- catch (e) {
64
- result.autoResponseError = e?.message || String(e);
65
- }
66
- }
67
- else if (typeof Pair !== 'function') {
68
- result.autoResponseError = 'WebSocketRequestResponsePair global not available';
69
- }
70
- else {
71
- result.autoResponseError = 'ctx.setWebSocketAutoResponse not available';
72
- }
73
- // Step 2: hibernation event timeout. Independent of auto-response —
74
- // a workerd that lacks the global may still support the timeout
75
- // method, and vice versa.
76
- if (typeof ctx?.setHibernatableWebSocketEventTimeout === 'function') {
77
- try {
78
- ctx.setHibernatableWebSocketEventTimeout(NIMBUS_HIBERNATION_EVENT_TIMEOUT_MS);
79
- result.timeoutSetMs = NIMBUS_HIBERNATION_EVENT_TIMEOUT_MS;
80
- }
81
- catch (e) {
82
- result.timeoutError = e?.message || String(e);
83
- }
84
- }
85
- else {
86
- result.timeoutError = 'ctx.setHibernatableWebSocketEventTimeout not available';
87
- }
88
- return result;
89
- }