@nimbus-sh/worker 0.10.0 → 0.11.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.
- package/NOTICE.md +5 -0
- package/README.md +10 -0
- package/dist/_shared/session-router.d.ts +7 -0
- package/dist/_shared/session-router.d.ts.map +1 -1
- package/dist/_shared/session-router.js +7 -0
- package/dist/bindings/body.d.ts +6 -0
- package/dist/bindings/body.d.ts.map +1 -0
- package/dist/bindings/body.js +37 -0
- package/dist/bindings/kv.d.ts +0 -2
- package/dist/bindings/kv.d.ts.map +1 -1
- package/dist/bindings/kv.js +3 -42
- package/dist/bindings/r2.d.ts +0 -2
- package/dist/bindings/r2.d.ts.map +1 -1
- package/dist/bindings/r2.js +4 -44
- package/dist/esbuild-cli-artifact.generated.d.ts +18 -0
- package/dist/esbuild-cli-artifact.generated.d.ts.map +1 -0
- package/dist/esbuild-cli-artifact.generated.js +17 -0
- package/dist/facets/cirrus-real.d.ts.map +1 -1
- package/dist/facets/cirrus-real.js +9 -4
- package/dist/facets/compose.d.ts +11 -7
- package/dist/facets/compose.d.ts.map +1 -1
- package/dist/facets/compose.js +8 -38
- package/dist/facets/data-plan.d.ts +79 -0
- package/dist/facets/data-plan.d.ts.map +1 -0
- package/dist/facets/data-plan.js +477 -0
- package/dist/facets/esbuild-transform.d.ts +36 -10
- package/dist/facets/esbuild-transform.d.ts.map +1 -1
- package/dist/facets/esbuild-transform.js +216 -20
- package/dist/facets/exec-telemetry.d.ts +7 -3
- package/dist/facets/exec-telemetry.d.ts.map +1 -1
- package/dist/facets/manager.d.ts +179 -78
- package/dist/facets/manager.d.ts.map +1 -1
- package/dist/facets/manager.js +1221 -649
- package/dist/facets/opencode-staging.d.ts +0 -2
- package/dist/facets/opencode-staging.d.ts.map +1 -1
- package/dist/facets/opencode-staging.js +5 -11
- package/dist/facets/process.d.ts +4 -0
- package/dist/facets/process.d.ts.map +1 -1
- package/dist/facets/process.js +3 -0
- package/dist/facets/read-profile.d.ts +149 -0
- package/dist/facets/read-profile.d.ts.map +1 -0
- package/dist/facets/read-profile.js +483 -0
- package/dist/facets/resident-identity.d.ts +0 -1
- package/dist/facets/resident-identity.d.ts.map +1 -1
- package/dist/facets/resident-identity.js +0 -3
- package/dist/facets/wasm-swap-registry.d.ts +34 -25
- package/dist/facets/wasm-swap-registry.d.ts.map +1 -1
- package/dist/facets/wasm-swap-registry.js +62 -56
- package/dist/facets/ws-terminal.d.ts +4 -4
- package/dist/facets/ws-terminal.d.ts.map +1 -1
- package/dist/facets/ws-terminal.js +4 -5
- package/dist/git/commands.d.ts +16 -9
- package/dist/git/commands.d.ts.map +1 -1
- package/dist/git/commands.js +1818 -188
- package/dist/git/network-facet.d.ts +10 -2
- package/dist/git/network-facet.d.ts.map +1 -1
- package/dist/git/network-facet.js +62 -16
- package/dist/git/unified-diff.d.ts +74 -0
- package/dist/git/unified-diff.d.ts.map +1 -0
- package/dist/git/unified-diff.js +676 -0
- package/dist/git-bundle.generated.d.ts +7 -11
- package/dist/git-bundle.generated.d.ts.map +1 -1
- package/dist/git-bundle.generated.js +7 -11
- package/dist/hosted/commands.d.ts.map +1 -1
- package/dist/hosted/commands.js +62 -243
- package/dist/hosted/runtime.d.ts +19 -13
- package/dist/hosted/runtime.d.ts.map +1 -1
- package/dist/hosted/runtime.js +71 -14
- package/dist/hosted/services.d.ts +6 -7
- package/dist/hosted/services.d.ts.map +1 -1
- package/dist/hosted/services.js +10 -14
- package/dist/hosted/session.d.ts +165 -0
- package/dist/hosted/session.d.ts.map +1 -0
- package/dist/hosted/session.js +132 -0
- package/dist/loaders/generated-workers.d.ts +5 -2
- package/dist/loaders/generated-workers.d.ts.map +1 -1
- package/dist/loaders/generated-workers.js +6 -3
- package/dist/loaders/npm-resolve-preamble.d.ts.map +1 -1
- package/dist/loaders/npm-resolve-preamble.js +0 -27
- package/dist/node-shims-artifact.generated.d.ts +13 -4
- package/dist/node-shims-artifact.generated.d.ts.map +1 -1
- package/dist/node-shims-artifact.generated.js +16 -7
- package/dist/npm/bin-links.d.ts +3 -1
- package/dist/npm/bin-links.d.ts.map +1 -1
- package/dist/npm/bin-links.js +32 -8
- package/dist/npm/cache.d.ts +5 -0
- package/dist/npm/cache.d.ts.map +1 -1
- package/dist/npm/cache.js +13 -1
- package/dist/npm/install-batch-facet.d.ts +2 -2
- package/dist/npm/install-batch-facet.js +3 -3
- package/dist/npm/installer.d.ts +17 -1
- package/dist/npm/installer.d.ts.map +1 -1
- package/dist/npm/installer.js +159 -20
- package/dist/npm/package-lock.d.ts +32 -0
- package/dist/npm/package-lock.d.ts.map +1 -0
- package/dist/npm/package-lock.js +65 -0
- package/dist/npm/pre-bundle-facet.d.ts +1 -30
- package/dist/npm/pre-bundle-facet.d.ts.map +1 -1
- package/dist/npm/pre-bundle-facet.js +3 -5
- package/dist/npm/r2-cache.d.ts +2 -0
- package/dist/npm/r2-cache.d.ts.map +1 -1
- package/dist/npm/r2-cache.js +2 -0
- package/dist/npm/resolve-one-facet.d.ts.map +1 -1
- package/dist/npm/resolve-one-facet.js +14 -3
- package/dist/npm/resolver.d.ts +0 -7
- package/dist/npm/resolver.d.ts.map +1 -1
- package/dist/npm/resolver.js +0 -22
- package/dist/opencode-artifact.generated.js +2 -2
- package/dist/replica/routing.d.ts +2 -38
- package/dist/replica/routing.d.ts.map +1 -1
- package/dist/replica/routing.js +3 -55
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +15 -2
- package/dist/router/public-directory.d.ts +18 -0
- package/dist/router/public-directory.d.ts.map +1 -1
- package/dist/router/public-directory.js +1 -1
- package/dist/router/remote-api.d.ts +3 -1
- package/dist/router/remote-api.d.ts.map +1 -1
- package/dist/router/remote-api.js +42 -79
- package/dist/runtime/bash-repl.js +2 -2
- package/dist/runtime/bun-repl.d.ts.map +1 -1
- package/dist/runtime/bun-repl.js +2 -13
- package/dist/runtime/esbuild-wasm-bytes.d.ts +17 -5
- package/dist/runtime/esbuild-wasm-bytes.d.ts.map +1 -1
- package/dist/runtime/esbuild-wasm-bytes.js +43 -94
- package/dist/runtime/git-bundle-artifact.d.ts +17 -0
- package/dist/runtime/git-bundle-artifact.d.ts.map +1 -0
- package/dist/runtime/git-bundle-artifact.js +25 -0
- package/dist/runtime/node-repl.d.ts.map +1 -1
- package/dist/runtime/node-repl.js +2 -13
- package/dist/runtime/node-shims-artifact.d.ts +22 -23
- package/dist/runtime/node-shims-artifact.d.ts.map +1 -1
- package/dist/runtime/node-shims-artifact.js +48 -78
- package/dist/runtime/node-shims.d.ts.map +1 -1
- package/dist/runtime/node-shims.js +1567 -864
- package/dist/runtime/opencode-artifact.d.ts.map +1 -1
- package/dist/runtime/opencode-artifact.js +17 -53
- package/dist/runtime/opencode-facet-runner.d.ts +3 -6
- package/dist/runtime/opencode-facet-runner.d.ts.map +1 -1
- package/dist/runtime/opencode-facet-runner.js +45 -10
- package/dist/runtime/opentui-wasm-bytes.d.ts.map +1 -1
- package/dist/runtime/opentui-wasm-bytes.js +16 -49
- package/dist/runtime/package-manager.d.ts +0 -2
- package/dist/runtime/package-manager.d.ts.map +1 -1
- package/dist/runtime/package-manager.js +0 -3
- package/dist/runtime/python-repl.d.ts.map +1 -1
- package/dist/runtime/python-repl.js +2 -2
- package/dist/runtime/repl-session.d.ts +10 -0
- package/dist/runtime/repl-session.d.ts.map +1 -1
- package/dist/runtime/repl-session.js +7 -0
- package/dist/runtime/ruby-repl.d.ts.map +1 -1
- package/dist/runtime/ruby-repl.js +2 -2
- package/dist/runtime/ruby-resident.d.ts.map +1 -1
- package/dist/runtime/ruby-resident.js +36 -35
- package/dist/runtime/runtime-catalog.d.ts +10 -3
- package/dist/runtime/runtime-catalog.d.ts.map +1 -1
- package/dist/runtime/runtime-catalog.js +125 -15
- package/dist/runtime/sqlite-wasm-bytes.d.ts +4 -4
- package/dist/runtime/sqlite-wasm-bytes.d.ts.map +1 -1
- package/dist/runtime/sqlite-wasm-bytes.js +21 -57
- package/dist/runtime/staged-source.d.ts +67 -0
- package/dist/runtime/staged-source.d.ts.map +1 -0
- package/dist/runtime/staged-source.js +113 -0
- package/dist/runtime/wasi/preamble.d.ts.map +1 -1
- package/dist/runtime/wasi/preamble.js +0 -24
- package/dist/runtime-catalog.generated.js +1 -1
- package/dist/session/agent.d.ts +14 -2
- package/dist/session/agent.d.ts.map +1 -1
- package/dist/session/agent.js +57 -19
- package/dist/session/ai.d.ts +0 -11
- package/dist/session/ai.d.ts.map +1 -1
- package/dist/session/ai.js +0 -4
- package/dist/session/fs-watch.d.ts +0 -11
- package/dist/session/fs-watch.d.ts.map +1 -1
- package/dist/session/fs-watch.js +0 -21
- package/dist/session/hibernation.d.ts +34 -11
- package/dist/session/hibernation.d.ts.map +1 -1
- package/dist/session/hibernation.js +46 -29
- package/dist/session/init-phases.d.ts +1 -2
- package/dist/session/init-phases.d.ts.map +1 -1
- package/dist/session/init-phases.js +1 -2
- package/dist/session/init.d.ts.map +1 -1
- package/dist/session/init.js +7 -20
- package/dist/session/keys.d.ts +0 -3
- package/dist/session/keys.d.ts.map +1 -1
- package/dist/session/keys.js +0 -3
- package/dist/session/legacy-reset.d.ts +11 -0
- package/dist/session/legacy-reset.d.ts.map +1 -0
- package/dist/session/legacy-reset.js +16 -0
- package/dist/session/nimbus-session.d.ts +41 -15
- package/dist/session/nimbus-session.d.ts.map +1 -1
- package/dist/session/nimbus-session.js +64 -70
- package/dist/session/npm-install-port.d.ts.map +1 -1
- package/dist/session/npm-install-port.js +1 -0
- package/dist/session/programmatic.d.ts +13 -18
- package/dist/session/programmatic.d.ts.map +1 -1
- package/dist/session/programmatic.js +53 -39
- package/dist/session/replica-routes.d.ts +2 -3
- package/dist/session/replica-routes.d.ts.map +1 -1
- package/dist/session/replica-routes.js +3 -10
- package/dist/session/routes.d.ts.map +1 -1
- package/dist/session/routes.js +7 -10
- package/dist/session/rpc.d.ts +104 -20
- package/dist/session/rpc.d.ts.map +1 -1
- package/dist/session/rpc.js +184 -37
- package/dist/session/start-real-vite.js +2 -2
- package/dist/session/state-store.d.ts +1 -17
- package/dist/session/state-store.d.ts.map +1 -1
- package/dist/session/state-store.js +3 -53
- package/dist/session/supervisor-op.d.ts +7 -0
- package/dist/session/supervisor-op.d.ts.map +1 -1
- package/dist/session/supervisor-op.js +6 -1
- package/dist/session/supervisor-rpc.d.ts +104 -15
- package/dist/session/supervisor-rpc.d.ts.map +1 -1
- package/dist/session/supervisor-rpc.js +188 -71
- package/dist/session/vite-command.d.ts.map +1 -1
- package/dist/session/vite-command.js +17 -14
- package/dist/session/ws.d.ts.map +1 -1
- package/dist/session/ws.js +20 -8
- package/dist/shell/npm-bin-entrypoints.d.ts.map +1 -1
- package/dist/shell/npm-bin-entrypoints.js +30 -5
- package/dist/vfs/facet-resident-limits.d.ts +33 -0
- package/dist/vfs/facet-resident-limits.d.ts.map +1 -0
- package/dist/vfs/facet-resident-limits.js +33 -0
- package/dist/vfs/facet-resident-store.d.ts +2 -10
- package/dist/vfs/facet-resident-store.d.ts.map +1 -1
- package/dist/vfs/facet-resident-store.js +1594 -219
- package/dist/workspace-host.d.ts +2 -0
- package/dist/workspace-host.d.ts.map +1 -1
- package/dist/workspace-host.js +2 -0
- package/dist/wrangler/nimbus-wrangler.d.ts +0 -2
- package/dist/wrangler/nimbus-wrangler.d.ts.map +1 -1
- package/dist/wrangler/nimbus-wrangler.js +5 -22
- package/package.json +8 -7
- package/public/_assets/opencode/1.16.2/index-attach.js +2 -2
- package/public/_assets/runtime/esbuild-cli-c4fda380d52befc1.js +6892 -0
- package/public/_assets/runtime/git-de3e60c9f3ff006a.js +103 -0
- package/public/_assets/runtime/{node-shims-7b4dd7a76d95d21e.js → node-shims-06565b121555c194.js} +2089 -861
- package/public/_assets/runtime/resident-store-6ffb1939c53d982f.js +2264 -0
- package/public/_assets/runtime/vfs-write-ledger-e501e8fc793bc2c1.js +889 -0
- package/scripts/build-opencode-attach-entry.mjs +51 -1
- package/scripts/bundle-facet-workers.mjs +114 -3
- package/scripts/bundle-git.mjs +88 -27
- package/scripts/bundle-node-shims.mjs +72 -46
- package/scripts/bundle-runtime.mjs +18 -421
- package/scripts/cf-git-patch.mjs +137 -0
- package/scripts/patch-install-deps.mjs +49 -96
- package/scripts/runtime-specs.mjs +435 -0
- package/vendor/git-http.generated.d.ts +82 -0
- package/vendor/git-upstream.generated.d.ts +4378 -0
- package/vendor/git.LICENSE +7 -0
- package/vendor/git.generated.d.mts +21 -0
- package/vendor/git.generated.mjs +103 -0
- package/dist/replica/suspension.d.ts +0 -36
- package/dist/replica/suspension.d.ts.map +0 -1
- package/dist/replica/suspension.js +0 -49
- package/dist/runtime/static-server.d.ts +0 -3
- package/dist/runtime/static-server.d.ts.map +0 -1
- package/dist/runtime/static-server.js +0 -133
- package/scripts/clean-dist.mjs +0 -7
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* replica
|
|
2
|
+
* replica/routing.ts — W12 — DO read replica routing primitives.
|
|
3
3
|
*
|
|
4
4
|
* Pure module (no `cloudflare:workers` import) so it can be unit-tested
|
|
5
5
|
* under Bun. NimbusSession wraps these helpers in its constructor and
|
|
@@ -28,10 +28,7 @@
|
|
|
28
28
|
* pins it near the DO; RPC into the DO is unaffected. DOs themselves
|
|
29
29
|
* don't move.
|
|
30
30
|
*
|
|
31
|
-
|
|
32
|
-
* "Network connection lost" during high-volume writes. Mitigation:
|
|
33
|
-
* suspend replicas during npm install / git clone bursts (the
|
|
34
|
-
* suspension state lives in `replica-suspension.ts`).
|
|
31
|
+
|
|
35
32
|
*/
|
|
36
33
|
/** Result of `classifyReplicaPolicy(pathname, method)`. */
|
|
37
34
|
export type ReplicaPolicy =
|
|
@@ -45,34 +42,12 @@ export type ReplicaPolicy =
|
|
|
45
42
|
* not subscribe its own hibernation handler to a stream the primary
|
|
46
43
|
* appends to. */
|
|
47
44
|
| 'primary-only-ws';
|
|
48
|
-
/** Eventual-consistency tolerance in ms (replica-eligible routes only). */
|
|
49
|
-
export interface RoutePolicy {
|
|
50
|
-
policy: ReplicaPolicy;
|
|
51
|
-
/** Max acceptable replication lag for this route, in ms. `null` for
|
|
52
|
-
* primary-only routes (not replicable). */
|
|
53
|
-
toleranceMs: number | null;
|
|
54
|
-
}
|
|
55
45
|
/**
|
|
56
46
|
* Pure routing decision. Mirrors the route table in W12-plan §2.
|
|
57
47
|
* Methods other than GET/HEAD on a replica-eligible route escape to
|
|
58
48
|
* primary-only — read replicas only make sense for reads.
|
|
59
49
|
*/
|
|
60
50
|
export declare function classifyReplicaPolicy(pathname: string, method: string): ReplicaPolicy;
|
|
61
|
-
/**
|
|
62
|
-
* Eventual-consistency tolerance per route (in ms).
|
|
63
|
-
*
|
|
64
|
-
* Returns `null` for primary-only routes (not replicable) and a numeric
|
|
65
|
-
* tolerance for replica-eligible routes. The probe
|
|
66
|
-
* `eventual-consistency-window-ms.mjs` enforces that every eligible route
|
|
67
|
-
* has a tolerance ≤ 2000ms.
|
|
68
|
-
*
|
|
69
|
-
* The 2-second budget aligns with D1 read-replication best practice
|
|
70
|
-
* (D1 docs § "Replica lag and consistency model"); DO replicas are
|
|
71
|
-
* the same architectural pattern.
|
|
72
|
-
*/
|
|
73
|
-
export declare function getEventualConsistencyToleranceMs(pathname: string): number | null;
|
|
74
|
-
/** Tolerance lookup table (for diagnostics / observability surfaces). */
|
|
75
|
-
export declare const REPLICA_POLICIES: Record<string, RoutePolicy>;
|
|
76
51
|
export type ReplicasState = 'enabled' | 'enabled-via-configure' | 'unsupported' | 'error';
|
|
77
52
|
export interface TryEnableReplicasResult {
|
|
78
53
|
state: ReplicasState;
|
|
@@ -103,17 +78,6 @@ export interface ReplicaStateInspect {
|
|
|
103
78
|
* when the SPEC's `waitForBookmark` lands.
|
|
104
79
|
*/
|
|
105
80
|
export declare function inspectReplicaState(ctx: any): ReplicaStateInspect;
|
|
106
|
-
/**
|
|
107
|
-
* Capture the current bookmark immediately after a write completes on
|
|
108
|
-
* the primary. The caller (e.g. /api/write-file) can stash the result in
|
|
109
|
-
* a response header / cookie so the next read-your-writes call from the
|
|
110
|
-
* same client can wait for the replica to catch up before responding.
|
|
111
|
-
*
|
|
112
|
-
* Phase 1 of W12 surfaces this as observability only (visible via
|
|
113
|
-
* /api/_diag/memory.replica.bookmark). Phase 2 (W12.5 if measured demand)
|
|
114
|
-
* wires the wait-for-bookmark contract end-to-end.
|
|
115
|
-
*/
|
|
116
|
-
export declare function captureBookmarkAfterWrite(ctx: any): string | null;
|
|
117
81
|
export interface DelegationInputs {
|
|
118
82
|
isReplica: boolean;
|
|
119
83
|
policy: ReplicaPolicy;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/replica/routing.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/replica/routing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,2DAA2D;AAC3D,MAAM,MAAM,aAAa;AACvB,iEAAiE;AAC/D,YAAY;AACd,wEAAwE;GACtE,mBAAmB;AACrB,uCAAuC;GACrC,cAAc;AAChB;;kBAEkB;GAChB,iBAAiB,CAAC;AAStB;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,aAAa,CAkDf;AAcD,MAAM,MAAM,aAAa,GACrB,SAAS,GACT,uBAAuB,GACvB,aAAa,GACb,OAAO,CAAC;AAEZ,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,aAAa,CAAC;IACrB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,GAAG,uBAAuB,CAgBnE;AAED,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,GAAG,GAAG,IAAI,CAAC;IACpB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,GAAG,GAAG,mBAAmB,CAgBjE;AAQD,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,aAAa,CAAC;IACtB;oEACgE;IAChE,MAAM,EAAE,OAAO,CAAC;IAChB;2DACuD;IACvD,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAoBzE;AAED,0CAA0C;AAC1C,MAAM,WAAW,eAAe;IAC9B;;qBAEiB;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB;yCACqC;IACrC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC1B,oEAAoE;IACpE,QAAQ,EAAE,gBAAgB,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CACnE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,GAC7C,OAAO,CAAC,eAAe,CAAC,CA6B1B"}
|
package/dist/replica/routing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* replica
|
|
2
|
+
* replica/routing.ts — W12 — DO read replica routing primitives.
|
|
3
3
|
*
|
|
4
4
|
* Pure module (no `cloudflare:workers` import) so it can be unit-tested
|
|
5
5
|
* under Bun. NimbusSession wraps these helpers in its constructor and
|
|
@@ -28,14 +28,11 @@
|
|
|
28
28
|
* pins it near the DO; RPC into the DO is unaffected. DOs themselves
|
|
29
29
|
* don't move.
|
|
30
30
|
*
|
|
31
|
-
|
|
32
|
-
* "Network connection lost" during high-volume writes. Mitigation:
|
|
33
|
-
* suspend replicas during npm install / git clone bursts (the
|
|
34
|
-
* suspension state lives in `replica-suspension.ts`).
|
|
31
|
+
|
|
35
32
|
*/
|
|
33
|
+
/** Eventual-consistency tolerance in ms (replica-eligible routes only). */
|
|
36
34
|
const PROCESSES_LOGS_RE = /^\/api\/processes\/\d+\/logs$/;
|
|
37
35
|
const PORT_RE = /^\/port\/\d+(\/.*)?$/;
|
|
38
|
-
const TWO_SECONDS = 2000;
|
|
39
36
|
/**
|
|
40
37
|
* Pure routing decision. Mirrors the route table in W12-plan §2.
|
|
41
38
|
* Methods other than GET/HEAD on a replica-eligible route escape to
|
|
@@ -105,42 +102,6 @@ export function classifyReplicaPolicy(pathname, method) {
|
|
|
105
102
|
function isReadMethod(method) {
|
|
106
103
|
return method === 'GET' || method === 'HEAD';
|
|
107
104
|
}
|
|
108
|
-
/**
|
|
109
|
-
* Eventual-consistency tolerance per route (in ms).
|
|
110
|
-
*
|
|
111
|
-
* Returns `null` for primary-only routes (not replicable) and a numeric
|
|
112
|
-
* tolerance for replica-eligible routes. The probe
|
|
113
|
-
* `eventual-consistency-window-ms.mjs` enforces that every eligible route
|
|
114
|
-
* has a tolerance ≤ 2000ms.
|
|
115
|
-
*
|
|
116
|
-
* The 2-second budget aligns with D1 read-replication best practice
|
|
117
|
-
* (D1 docs § "Replica lag and consistency model"); DO replicas are
|
|
118
|
-
* the same architectural pattern.
|
|
119
|
-
*/
|
|
120
|
-
export function getEventualConsistencyToleranceMs(pathname) {
|
|
121
|
-
// Re-classify with a synthetic GET to figure out replica eligibility.
|
|
122
|
-
const policy = classifyReplicaPolicy(pathname, 'GET');
|
|
123
|
-
if (policy === 'replica-ok')
|
|
124
|
-
return TWO_SECONDS;
|
|
125
|
-
if (policy === 'replica-warm-only')
|
|
126
|
-
return TWO_SECONDS;
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
/** Tolerance lookup table (for diagnostics / observability surfaces). */
|
|
130
|
-
export const REPLICA_POLICIES = {
|
|
131
|
-
'/api/memory': { policy: 'replica-ok', toleranceMs: TWO_SECONDS },
|
|
132
|
-
'/api/_diag/memory': { policy: 'replica-ok', toleranceMs: TWO_SECONDS },
|
|
133
|
-
'/api/processes': { policy: 'replica-ok', toleranceMs: TWO_SECONDS },
|
|
134
|
-
'/api/stats': { policy: 'replica-ok', toleranceMs: TWO_SECONDS },
|
|
135
|
-
'/preview/': { policy: 'replica-warm-only', toleranceMs: TWO_SECONDS },
|
|
136
|
-
'/ws': { policy: 'primary-only-ws', toleranceMs: null },
|
|
137
|
-
'/api/write-file': { policy: 'primary-only', toleranceMs: null },
|
|
138
|
-
'/api/mkdir': { policy: 'primary-only', toleranceMs: null },
|
|
139
|
-
'/api/start-vite': { policy: 'primary-only', toleranceMs: null },
|
|
140
|
-
'/api/supervisor-rpc': { policy: 'primary-only', toleranceMs: null },
|
|
141
|
-
'/worker/': { policy: 'primary-only', toleranceMs: null },
|
|
142
|
-
'/__nimbus/worker/': { policy: 'primary-only', toleranceMs: null },
|
|
143
|
-
};
|
|
144
105
|
/**
|
|
145
106
|
* Best-effort: enable read replicas on this DO instance. Safe to call from
|
|
146
107
|
* the constructor — pre-GA runtimes that lack the API surface no-op.
|
|
@@ -198,19 +159,6 @@ export function inspectReplicaState(ctx) {
|
|
|
198
159
|
catch { /* best-effort */ }
|
|
199
160
|
return { isReplica, primary: isReplica ? s.primary : null, bookmark };
|
|
200
161
|
}
|
|
201
|
-
/**
|
|
202
|
-
* Capture the current bookmark immediately after a write completes on
|
|
203
|
-
* the primary. The caller (e.g. /api/write-file) can stash the result in
|
|
204
|
-
* a response header / cookie so the next read-your-writes call from the
|
|
205
|
-
* same client can wait for the replica to catch up before responding.
|
|
206
|
-
*
|
|
207
|
-
* Phase 1 of W12 surfaces this as observability only (visible via
|
|
208
|
-
* /api/_diag/memory.replica.bookmark). Phase 2 (W12.5 if measured demand)
|
|
209
|
-
* wires the wait-for-bookmark contract end-to-end.
|
|
210
|
-
*/
|
|
211
|
-
export function captureBookmarkAfterWrite(ctx) {
|
|
212
|
-
return inspectReplicaState(ctx).bookmark;
|
|
213
|
-
}
|
|
214
162
|
/**
|
|
215
163
|
* Pure decision: should this isolate forward the Request to the primary
|
|
216
164
|
* via `ctx.storage.primary.fetch(request)`?
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/router/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAuCH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/router/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAuCH,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,iBAAiB,CAAC;AA+CzB,YAAY,EACV,YAAY,IAAI,eAAe,EAC/B,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAEzB;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,oDAAoD;IACpD,aAAa,EAAE,MAAM,CAAC;IACtB,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,kFAAkF;IAClF,OAAO,EAAE,OAAO,CAAC;IACjB,oBAAoB;IACpB,GAAG,EAAE,GAAG,CAAC;CACV;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;;OAMG;IACH,cAAc,CAAC,CAAC,GAAG,EAAE,iBAAiB,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9D;;;OAGG;IACH,YAAY,CAAC,CAAC,GAAG,EAAE,iBAAiB,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7D;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC;AAErD,0CAA0C;AAC1C,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,CACzB,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,gBAAgB,KAClB,QAAQ,GAAG,IAAI,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;AAEhD,+CAA+C;AAC/C,MAAM,WAAW,0BAA0B;IACzC,oCAAoC;IACpC,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,qDAAqD;IACrD,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,4CAA4C;IAC5C,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,yEAAyE;IACzE,GAAG,CAAC,EAAE,qBAAqB,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC7E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,0BAA+B,GACvC,aAAa,CAiXf"}
|
package/dist/router/index.js
CHANGED
|
@@ -36,7 +36,7 @@ import { buildPreviewHost, isPreviewHostSafeSid, parsePreviewHost, readPreviewHo
|
|
|
36
36
|
import { parseSessionRoute, forwardToSession, renderInvalidSessionHtml, SESSION_ROUTE_PREFIX, LEGACY_PUBLIC_DO_SEGMENT, PREVIEW_CAPABILITY_HEADER, PUBLIC_BEARER_HEADER, } from '../_shared/session-router.js';
|
|
37
37
|
import { issueNimbusToken, verifyNimbusToken, verifyRequestToken, requireScopes, requireSessionPin, authErrorResponse, setNimbusTokenCookie, NIMBUS_TOKEN_QUERY, NimbusAuthError, NimbusBootstrapConsumedError, NimbusTokenClaimsError, DEFAULT_TOKEN_TTL_MS, ATTACH_BOOTSTRAP_TTL_MS, } from '../auth/index.js';
|
|
38
38
|
import { adoptCtxExports } from '@nimbus-sh/fabric/composition.js';
|
|
39
|
-
import { handleNimbusRemoteApi, } from './remote-api.js';
|
|
39
|
+
import { handleNimbusRemoteApi, remoteApiEnabled, } from './remote-api.js';
|
|
40
40
|
import { parseAgentOAuthStateParam } from '../session/agent.js';
|
|
41
41
|
import { publicDirectoryStub } from './public-directory.js';
|
|
42
42
|
/**
|
|
@@ -231,7 +231,9 @@ export function createNimbusHandler(options = {}) {
|
|
|
231
231
|
if (sdkResponse)
|
|
232
232
|
return sdkResponse;
|
|
233
233
|
if (url.pathname === '/api/nimbus/oauth/callback') {
|
|
234
|
-
|
|
234
|
+
// Signed by the session that started the flow: a state this deployment
|
|
235
|
+
// did not sign never reaches a Durable Object.
|
|
236
|
+
const payload = await parseAgentOAuthStateParam(url.searchParams.get('state'), env);
|
|
235
237
|
if (!payload || !isValidSessionId(payload.sessionId)) {
|
|
236
238
|
return new Response('Invalid OAuth state', { status: 400 });
|
|
237
239
|
}
|
|
@@ -344,7 +346,18 @@ export function createNimbusHandler(options = {}) {
|
|
|
344
346
|
return Response.json({ url: previewUrl }, { headers: { 'Cache-Control': 'no-store' } });
|
|
345
347
|
}
|
|
346
348
|
// `/s/<id>` and `/s/<id>/` (no inner path) → serve the xterm UI shell.
|
|
349
|
+
// Only to GET and HEAD: a root DELETE is the SDK's destroy, answered by
|
|
350
|
+
// handleNimbusRemoteApi above when the remote API is enabled.
|
|
347
351
|
if (route.innerPath === '/' || route.innerPath === '') {
|
|
352
|
+
if (request.method !== 'GET' && request.method !== 'HEAD') {
|
|
353
|
+
return new Response('Method not allowed', {
|
|
354
|
+
status: 405,
|
|
355
|
+
headers: {
|
|
356
|
+
Allow: remoteApiEnabled(options.sdk) ? 'GET, HEAD, DELETE' : 'GET, HEAD',
|
|
357
|
+
'Cache-Control': 'no-store',
|
|
358
|
+
},
|
|
359
|
+
});
|
|
360
|
+
}
|
|
348
361
|
if (env.ASSETS) {
|
|
349
362
|
const shellUrl = new URL('/s/index.html', url.origin);
|
|
350
363
|
return env.ASSETS.fetch(new Request(shellUrl.toString(), {
|
|
@@ -47,6 +47,24 @@ export declare function publicDirectoryStub(env: unknown): {
|
|
|
47
47
|
unbind(capability: string): Promise<void>;
|
|
48
48
|
resolve(capability: string): Promise<PublicDirectoryEntry | null>;
|
|
49
49
|
} | null;
|
|
50
|
+
/**
|
|
51
|
+
* `{ tenantSegment, sid }` for the session DO this host is, read off its own
|
|
52
|
+
* DO name — `tn:sub:sid` (or `legacy:public:_:sid`), no request header
|
|
53
|
+
* needed. A host without a DO id (a unit-test stub) may carry the fields on
|
|
54
|
+
* itself.
|
|
55
|
+
*/
|
|
56
|
+
export declare function sessionIdentity(host: {
|
|
57
|
+
ctx?: {
|
|
58
|
+
id?: {
|
|
59
|
+
name?: unknown;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
tenantSegment?: string;
|
|
63
|
+
sessionId?: string;
|
|
64
|
+
}): {
|
|
65
|
+
tenantSegment: string;
|
|
66
|
+
sid: string;
|
|
67
|
+
} | null;
|
|
50
68
|
/**
|
|
51
69
|
* Publish a public port's capability to the routing directory. A legacy-
|
|
52
70
|
* public deployment needs no directory — its DO name is already the one
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public-directory.d.ts","sourceRoot":"","sources":["../../src/router/public-directory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;yEACqE;IACrE,QA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 @@ import { LEGACY_PUBLIC_DO_SEGMENT } from '../_shared/session-router.js';
|
|
|
70
70
|
* needed. A host without a DO id (a unit-test stub) may carry the fields on
|
|
71
71
|
* itself.
|
|
72
72
|
*/
|
|
73
|
-
function sessionIdentity(host) {
|
|
73
|
+
export function sessionIdentity(host) {
|
|
74
74
|
const name = host.ctx?.id?.name;
|
|
75
75
|
if (typeof name === 'string' && name.length > 0) {
|
|
76
76
|
const cut = name.lastIndexOf(':');
|
|
@@ -48,7 +48,7 @@ interface NimbusSessionRpcStub {
|
|
|
48
48
|
preinstall?: string[];
|
|
49
49
|
}): Promise<unknown>;
|
|
50
50
|
_rpcBootProbe(): Promise<unknown>;
|
|
51
|
-
|
|
51
|
+
_rpcExecStream(command: string, options?: Record<string, unknown>): Promise<ReadableStream<Uint8Array>>;
|
|
52
52
|
_rpcStartProcess(command: string, options?: Record<string, unknown>): Promise<unknown>;
|
|
53
53
|
_rpcRunCode(code: string, options?: Record<string, unknown>): Promise<unknown>;
|
|
54
54
|
_rpcReadFile(path: string): Promise<unknown>;
|
|
@@ -119,5 +119,7 @@ interface NimbusRemoteEnv extends Partial<NimbusAuthEnv> {
|
|
|
119
119
|
NIMBUS_SESSION?: NimbusSessionNamespace;
|
|
120
120
|
}
|
|
121
121
|
export declare function handleNimbusRemoteApi(request: Request, env: NimbusRemoteEnv, sdk: NimbusSdkRouterConfig | undefined): Promise<Response | null>;
|
|
122
|
+
/** Whether the remote API (and with it `DELETE /s/<id>/`) is served. */
|
|
123
|
+
export declare function remoteApiEnabled(sdk: NimbusSdkRouterConfig | undefined): boolean;
|
|
122
124
|
export {};
|
|
123
125
|
//# sourceMappingURL=remote-api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-api.d.ts","sourceRoot":"","sources":["../../src/router/remote-api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"remote-api.d.ts","sourceRoot":"","sources":["../../src/router/remote-api.ts"],"names":[],"mappings":"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,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACjD,WAAW,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAClE;AAED,4FAA4F;AAC5F,KAAK,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnH,UAAU,sBAAsB;IAC9B,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC;IAC1C,GAAG,CAAC,EAAE,EAAE,eAAe,GAAG,oBAAoB,CAAC;CAChD;AAED,UAAU,eAAgB,SAAQ,OAAO,CAAC,aAAa,CAAC;IACtD,cAAc,CAAC,EAAE,sBAAsB,CAAC;CACzC;AAgCD,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,qBAAqB,GAAG,SAAS,GACrC,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CA6F1B;AAED,wEAAwE;AACxE,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,qBAAqB,GAAG,SAAS,GAAG,OAAO,CAEhF"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { LEGACY_PUBLIC_DO_SEGMENT, } from '../_shared/session-router.js';
|
|
1
|
+
import { LEGACY_PUBLIC_DO_SEGMENT, parseSessionRoute, } from '../_shared/session-router.js';
|
|
2
|
+
import { isValidSessionId } from '../_shared/session-id.js';
|
|
2
3
|
import { z } from 'zod/v4';
|
|
4
|
+
import { WireEncoder, WireDecoder } from '@nimbus-sh/core/_shared/wire-codec.js';
|
|
3
5
|
import { requireScopes, requireSessionPin, verifyRequestToken, NimbusAuthError, isNimbusIdComponent, } from '../auth/index.js';
|
|
4
6
|
import { useRpcResource } from '@nimbus-sh/platform/rpc-dispose.js';
|
|
7
|
+
import { EXEC_STREAM_CONTENT_TYPE, collectExecStream, decodeExecStream } from '@nimbus-sh/core/runtime/exec-stream.js';
|
|
5
8
|
const DEFAULT_REMOTE_BASE_PATH = '/api/nimbus/v1';
|
|
6
9
|
const RemoteRpcBodySchema = z.object({
|
|
7
10
|
profile: z.string().optional(),
|
|
@@ -11,35 +14,43 @@ const RemoteRpcBodySchema = z.object({
|
|
|
11
14
|
op: z.string().optional(),
|
|
12
15
|
args: z.array(z.unknown()).optional(),
|
|
13
16
|
}).passthrough();
|
|
14
|
-
const WireBytesSchema = z.object({
|
|
15
|
-
__nimbusWireType: z.literal('bytes'),
|
|
16
|
-
base64: z.string(),
|
|
17
|
-
}).passthrough();
|
|
18
17
|
export async function handleNimbusRemoteApi(request, env, sdk) {
|
|
19
18
|
const remote = normalizeRemoteConfig(sdk?.remote);
|
|
20
19
|
if (!remote.enabled)
|
|
21
20
|
return null;
|
|
22
21
|
const url = new URL(request.url);
|
|
23
|
-
|
|
22
|
+
// `DELETE /s/<id>/` is the session's own address for `box.destroy()`: the
|
|
23
|
+
// same operation, under the same authorization, as the RPC below.
|
|
24
|
+
const sessionRoot = request.method === 'DELETE' ? parseSessionRoute(url.pathname) : null;
|
|
25
|
+
const destroyingRoot = sessionRoot !== null && sessionRoot.innerPath === '/';
|
|
26
|
+
const match = destroyingRoot ? { sandboxId: sessionRoot.sessionId } : matchRemoteRpc(url.pathname, remote.basePath);
|
|
24
27
|
if (!match)
|
|
25
28
|
return null;
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
if (!destroyingRoot) {
|
|
30
|
+
if (request.method === 'OPTIONS')
|
|
31
|
+
return corsResponse(null, 204);
|
|
32
|
+
if (request.method !== 'POST') {
|
|
33
|
+
return remoteJson({ ok: false, error: 'Method not allowed', code: 'E_METHOD_NOT_ALLOWED' }, 405);
|
|
34
|
+
}
|
|
30
35
|
}
|
|
31
36
|
if (!env?.NIMBUS_SESSION) {
|
|
32
37
|
return remoteJson({ ok: false, error: 'NIMBUS_SESSION binding is missing', code: 'E_NIMBUS_BINDING_MISSING' }, 500);
|
|
33
38
|
}
|
|
34
|
-
if (!isNimbusIdComponent(match.sandboxId)) {
|
|
39
|
+
if (!isNimbusIdComponent(match.sandboxId) || (destroyingRoot && !isValidSessionId(match.sandboxId))) {
|
|
35
40
|
return remoteJson({ ok: false, error: 'Invalid sandbox id', code: 'E_SANDBOX_ID' }, 400);
|
|
36
41
|
}
|
|
37
42
|
let body;
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
if (destroyingRoot) {
|
|
44
|
+
const reason = request.headers.get('X-Nimbus-Cleanup-Reason');
|
|
45
|
+
body = { op: 'destroy', args: [reason === null ? {} : { reason }] };
|
|
40
46
|
}
|
|
41
|
-
|
|
42
|
-
|
|
47
|
+
else {
|
|
48
|
+
try {
|
|
49
|
+
body = RemoteRpcBodySchema.parse(WireDecoder.parse(await request.json()));
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
return remoteJson({ ok: false, error: `Invalid JSON body: ${errorMessage(e)}`, code: 'E_BAD_JSON' }, 400);
|
|
53
|
+
}
|
|
43
54
|
}
|
|
44
55
|
const remoteAuth = await resolveRemoteAuth(request, env, remote, match.sandboxId);
|
|
45
56
|
if (remoteAuth instanceof Response)
|
|
@@ -70,6 +81,13 @@ export async function handleNimbusRemoteApi(request, env, sdk) {
|
|
|
70
81
|
// `rpcMs` only when the caller sets `diag`, so the normal SDK envelope
|
|
71
82
|
// is unchanged.
|
|
72
83
|
const wantDiag = body.diag === true;
|
|
84
|
+
// The one op whose answer is a stream: the body is the encoded exec
|
|
85
|
+
// stream itself, so output flows under the client's own backpressure.
|
|
86
|
+
if (body.op === 'execStream') {
|
|
87
|
+
const args = body.args ?? [];
|
|
88
|
+
const wire = await ctx.stub._rpcExecStream(stringArg(args[0], 'command'), execOptions(ctx, args[1]));
|
|
89
|
+
return corsResponse(wire, 200, { 'Content-Type': EXEC_STREAM_CONTENT_TYPE });
|
|
90
|
+
}
|
|
73
91
|
const t0 = Date.now();
|
|
74
92
|
return await useRpcResource(dispatchRemoteRpc(ctx), (result) => remoteJson(wantDiag ? { ok: true, result, rpcMs: Date.now() - t0 } : { ok: true, result }));
|
|
75
93
|
}
|
|
@@ -82,6 +100,10 @@ export async function handleNimbusRemoteApi(request, env, sdk) {
|
|
|
82
100
|
}, err.httpStatus);
|
|
83
101
|
}
|
|
84
102
|
}
|
|
103
|
+
/** Whether the remote API (and with it `DELETE /s/<id>/`) is served. */
|
|
104
|
+
export function remoteApiEnabled(sdk) {
|
|
105
|
+
return normalizeRemoteConfig(sdk?.remote).enabled;
|
|
106
|
+
}
|
|
85
107
|
function normalizeRemoteConfig(remote) {
|
|
86
108
|
const value = typeof remote === 'object' ? remote : {};
|
|
87
109
|
return {
|
|
@@ -154,7 +176,7 @@ async function dispatchRemoteRpc(ctx) {
|
|
|
154
176
|
case 'bootProbe':
|
|
155
177
|
return ctx.stub._rpcBootProbe();
|
|
156
178
|
case 'exec':
|
|
157
|
-
return ctx.stub.
|
|
179
|
+
return collectExecStream(decodeExecStream(await ctx.stub._rpcExecStream(stringArg(args[0], 'command'), execOptions(ctx, args[1]))));
|
|
158
180
|
case 'startProcess':
|
|
159
181
|
return ctx.stub._rpcStartProcess(stringArg(args[0], 'command'), execOptions(ctx, args[1]));
|
|
160
182
|
case 'runCode': {
|
|
@@ -311,6 +333,9 @@ function execOptions(ctx, value) {
|
|
|
311
333
|
if (options.cred !== undefined) {
|
|
312
334
|
throw apiError('cred is not accepted over the remote API', 'E_ARG_SHAPE', 400);
|
|
313
335
|
}
|
|
336
|
+
// A named shell owns its cwd; defaulting one here reset it on every call.
|
|
337
|
+
if (options.shellId !== undefined && options.cwd === undefined)
|
|
338
|
+
return options;
|
|
314
339
|
return {
|
|
315
340
|
...options,
|
|
316
341
|
cwd: typeof options.cwd === 'string' ? options.cwd : ctx.root,
|
|
@@ -433,7 +458,7 @@ function trimSlashes(value) {
|
|
|
433
458
|
return value.slice(start, end);
|
|
434
459
|
}
|
|
435
460
|
function remoteJson(value, status = 200) {
|
|
436
|
-
return corsResponse(JSON.stringify(
|
|
461
|
+
return corsResponse(JSON.stringify(WireEncoder.parse(value)), status, {
|
|
437
462
|
'Content-Type': 'application/json',
|
|
438
463
|
});
|
|
439
464
|
}
|
|
@@ -449,65 +474,3 @@ function corsResponse(body, status, headers = {}) {
|
|
|
449
474
|
},
|
|
450
475
|
});
|
|
451
476
|
}
|
|
452
|
-
function encodeWire(value) {
|
|
453
|
-
if (value instanceof Uint8Array) {
|
|
454
|
-
return {
|
|
455
|
-
__nimbusWireType: 'bytes',
|
|
456
|
-
base64: bytesToBase64(value),
|
|
457
|
-
};
|
|
458
|
-
}
|
|
459
|
-
if (value instanceof ArrayBuffer) {
|
|
460
|
-
return {
|
|
461
|
-
__nimbusWireType: 'bytes',
|
|
462
|
-
base64: bytesToBase64(new Uint8Array(value)),
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
if (ArrayBuffer.isView(value)) {
|
|
466
|
-
const view = value;
|
|
467
|
-
return {
|
|
468
|
-
__nimbusWireType: 'bytes',
|
|
469
|
-
base64: bytesToBase64(new Uint8Array(view.buffer, view.byteOffset, view.byteLength)),
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
if (Array.isArray(value))
|
|
473
|
-
return value.map(encodeWire);
|
|
474
|
-
if (value && typeof value === 'object') {
|
|
475
|
-
const out = {};
|
|
476
|
-
for (const [key, item] of Object.entries(value)) {
|
|
477
|
-
if (item !== undefined)
|
|
478
|
-
out[key] = encodeWire(item);
|
|
479
|
-
}
|
|
480
|
-
return out;
|
|
481
|
-
}
|
|
482
|
-
return value;
|
|
483
|
-
}
|
|
484
|
-
function decodeWire(value) {
|
|
485
|
-
const bytes = WireBytesSchema.safeParse(value);
|
|
486
|
-
if (bytes.success)
|
|
487
|
-
return base64ToBytes(bytes.data.base64);
|
|
488
|
-
if (Array.isArray(value))
|
|
489
|
-
return value.map(decodeWire);
|
|
490
|
-
if (value && typeof value === 'object') {
|
|
491
|
-
const out = {};
|
|
492
|
-
for (const [key, item] of Object.entries(value)) {
|
|
493
|
-
out[key] = decodeWire(item);
|
|
494
|
-
}
|
|
495
|
-
return out;
|
|
496
|
-
}
|
|
497
|
-
return value;
|
|
498
|
-
}
|
|
499
|
-
function bytesToBase64(bytes) {
|
|
500
|
-
let binary = '';
|
|
501
|
-
const chunk = 0x8000;
|
|
502
|
-
for (let i = 0; i < bytes.length; i += chunk) {
|
|
503
|
-
binary += String.fromCharCode(...bytes.subarray(i, i + chunk));
|
|
504
|
-
}
|
|
505
|
-
return btoa(binary);
|
|
506
|
-
}
|
|
507
|
-
function base64ToBytes(base64) {
|
|
508
|
-
const binary = atob(base64);
|
|
509
|
-
const bytes = new Uint8Array(binary.length);
|
|
510
|
-
for (let i = 0; i < binary.length; i++)
|
|
511
|
-
bytes[i] = binary.charCodeAt(i);
|
|
512
|
-
return bytes;
|
|
513
|
-
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { formatShellPrompt } from '@nimbus-sh/core/substrate/lifo/shell/Shell.js';
|
|
2
2
|
import { CRED_KERNEL } from '@nimbus-sh/core/runtime/os-contracts.js';
|
|
3
|
-
import {
|
|
3
|
+
import { withHostView } from '@nimbus-sh/core/runtime/process-files.js';
|
|
4
4
|
import { createBashFacetSession } from '@nimbus-sh/core/runtime/bash-runner.js';
|
|
5
5
|
import { facetHostForManager } from './facet-loader-host.js';
|
|
6
6
|
import { ReplSession, } from './repl-session.js';
|
|
@@ -84,7 +84,7 @@ class BashReplAdapter {
|
|
|
84
84
|
async ensureSession(signal) {
|
|
85
85
|
if (this.session)
|
|
86
86
|
return null;
|
|
87
|
-
this.session = await
|
|
87
|
+
this.session = await withHostView(this.deps.authority, CRED_KERNEL, (artifacts) => createBashFacetSession({
|
|
88
88
|
facets: facetHostForManager(this.deps.facetMgr),
|
|
89
89
|
artifacts,
|
|
90
90
|
filesystem: this.deps.filesystem,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bun-repl.d.ts","sourceRoot":"","sources":["../../src/runtime/bun-repl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAKlE,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,YAAY,CAAC;IACvB,QAAQ,EAAE,iBAAiB,CAAC;CAC7B;
|
|
1
|
+
{"version":3,"file":"bun-repl.d.ts","sourceRoot":"","sources":["../../src/runtime/bun-repl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAKlE,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,YAAY,CAAC;IACvB,QAAQ,EAAE,iBAAiB,CAAC;CAC7B;AA6RD;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAInE"}
|
package/dist/runtime/bun-repl.js
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* thrown by vm bubble up; we surface them as stderr via the runtime
|
|
32
32
|
* stderr capture.
|
|
33
33
|
*/
|
|
34
|
-
import { ReplSession } from './repl-session.js';
|
|
34
|
+
import { ReplSession, replPushResult } from './repl-session.js';
|
|
35
35
|
import { BUN_SHIM_PREAMBLE, BUN_VERSION } from './bun-runner.js';
|
|
36
36
|
class BunReplAdapter {
|
|
37
37
|
pool = null;
|
|
@@ -93,18 +93,7 @@ class BunReplAdapter {
|
|
|
93
93
|
catch (e) {
|
|
94
94
|
return { kind: 'error', stderr: `[bun-repl] push dispatch failed: ${e?.message || e}\n` };
|
|
95
95
|
}
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
kind: 'exit',
|
|
99
|
-
exitCode: result.exitCode || 0,
|
|
100
|
-
stdout: result.stdout,
|
|
101
|
-
stderr: result.stderr,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
if (result.incomplete) {
|
|
105
|
-
return { kind: 'incomplete' };
|
|
106
|
-
}
|
|
107
|
-
return { kind: 'output', stdout: result.stdout || '', stderr: result.stderr || '' };
|
|
96
|
+
return replPushResult(result);
|
|
108
97
|
}
|
|
109
98
|
async close() {
|
|
110
99
|
if (this.pool) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* esbuild-wasm-bytes.ts — supervisor-side fetcher for the
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* (env.ASSETS); this module hands them to the caller when
|
|
2
|
+
* esbuild-wasm-bytes.ts — supervisor-side fetcher for the artifacts the
|
|
3
|
+
* esbuild facet is built from: the wasm binary, the JS adapter that drives
|
|
4
|
+
* it, and the runner of the `esbuild` command. All three live in the
|
|
5
|
+
* static-assets layer (env.ASSETS); this module hands them to the caller when
|
|
6
|
+
* needed.
|
|
6
7
|
*
|
|
7
8
|
* Cache strategy
|
|
8
9
|
* ──────────────
|
|
@@ -32,7 +33,10 @@
|
|
|
32
33
|
* The JS adapter followed the wasm for the same reason at a smaller
|
|
33
34
|
* scale: the supervisor already imports esbuild-wasm's browser build as a
|
|
34
35
|
* module for its own transforms, so carrying the same 117 KiB again as a
|
|
35
|
-
* string literal for facets doubled it in the Worker bundle.
|
|
36
|
+
* string literal for facets doubled it in the Worker bundle. The CLI runner
|
|
37
|
+
* (32 KiB of Go glue and fs shim) only ever runs in the facet, so it is
|
|
38
|
+
* staged too; its name carries a prefix of its digest, because unlike the
|
|
39
|
+
* other two it changes without an esbuild upgrade.
|
|
36
40
|
*
|
|
37
41
|
* Each call to `fetchEsbuildWasmBytes(env)` now does:
|
|
38
42
|
* - one `caches.default.match()` — sub-millisecond on hit
|
|
@@ -71,6 +75,8 @@ export interface EsbuildWasmFetchEnv {
|
|
|
71
75
|
*/
|
|
72
76
|
export declare const ESBUILD_WASM_L2_KEY: string;
|
|
73
77
|
export declare const ESBUILD_JS_L2_KEY: string;
|
|
78
|
+
/** The CLI runner's key names its build id, so each rebuild lands a fresh entry. */
|
|
79
|
+
export declare const ESBUILD_CLI_L2_KEY: string;
|
|
74
80
|
/**
|
|
75
81
|
* Fetch the esbuild-wasm bytes from the static-assets layer.
|
|
76
82
|
*
|
|
@@ -91,4 +97,10 @@ export declare function fetchEsbuildWasmBytes(env: EsbuildWasmFetchEnv): Promise
|
|
|
91
97
|
* splice it in verbatim, so it is verified like the wasm it drives.
|
|
92
98
|
*/
|
|
93
99
|
export declare function fetchEsbuildJsFnBody(env: EsbuildWasmFetchEnv): Promise<string>;
|
|
100
|
+
/**
|
|
101
|
+
* Fetch the `esbuild` command's runner: Go's wasm_exec.js and the typed fs
|
|
102
|
+
* shim, a script that installs `globalThis.__esbuildCliRun` when the esbuild
|
|
103
|
+
* facet evaluates it. Verified like the adapter it sits beside.
|
|
104
|
+
*/
|
|
105
|
+
export declare function fetchEsbuildCliRunner(env: EsbuildWasmFetchEnv): Promise<string>;
|
|
94
106
|
//# sourceMappingURL=esbuild-wasm-bytes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esbuild-wasm-bytes.d.ts","sourceRoot":"","sources":["../../src/runtime/esbuild-wasm-bytes.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"esbuild-wasm-bytes.d.ts","sourceRoot":"","sources":["../../src/runtime/esbuild-wasm-bytes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAWH;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE;QAAE,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;KAAE,CAAC;CACpD;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,QAA2D,CAAC;AAC5F,eAAO,MAAM,iBAAiB,QAAyD,CAAC;AACxF,oFAAoF;AACpF,eAAO,MAAM,kBAAkB,QAA0D,CAAC;AAmC1F;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,CAAC,CAEpF;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,CAE9E;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,CAE/E"}
|