@nimbus-sh/sdk 0.1.5 → 0.2.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/README.md +13 -3
- package/dist/sandbox.d.ts +240 -11
- package/dist/sandbox.d.ts.map +1 -1
- package/dist/sandbox.js +427 -65
- package/dist/worker.d.ts +2 -2
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +1 -1
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -161,6 +161,10 @@ Worker verifies the JWT, enforces `sid` pins and `sandbox:use` scope, applies
|
|
|
161
161
|
the configured runtime policy, and delegates to the same `NimbusSession` RPC
|
|
162
162
|
methods used by `Nimbus.fromEnv()`.
|
|
163
163
|
|
|
164
|
+
Sandbox destruction is a separate lifecycle operation. Tokens that call
|
|
165
|
+
`box.destroy()` must include `session:destroy` or `session:admin` in addition
|
|
166
|
+
to the normal sandbox scope.
|
|
167
|
+
|
|
164
168
|
## Flue connector
|
|
165
169
|
|
|
166
170
|
Use `@nimbus-sh/sdk/flue` when an agent runtime expects Flue's sandbox
|
|
@@ -199,14 +203,20 @@ const box = nimbus.sandbox('session-or-job-id', {
|
|
|
199
203
|
|
|
200
204
|
await box.ready();
|
|
201
205
|
await box.exec('node -e "console.log(2 + 2)"');
|
|
202
|
-
await box.startProcess('node --watch /home/user/app/server.js');
|
|
206
|
+
const proc = await box.startProcess('node --watch /home/user/app/server.js');
|
|
207
|
+
// returns immediately with proc.pid; poll box.processes.logs(proc.pid) for
|
|
208
|
+
// output and the exit record, or box.processes.kill(proc.pid) to stop it
|
|
203
209
|
await box.runCode('print(2 + 2)', { language: 'python', install: 'ifMissing' });
|
|
204
210
|
|
|
205
211
|
await box.files.write('/home/user/app/a.txt', 'hello');
|
|
206
212
|
await box.files.read('/home/user/app/a.txt');
|
|
207
213
|
await box.files.list('/home/user/app');
|
|
208
214
|
await box.files.stat('/home/user/app/a.txt');
|
|
209
|
-
await box.files.
|
|
215
|
+
await box.files.lstat('/home/user/app/link');
|
|
216
|
+
await box.files.rename('/home/user/app/a.txt', '/home/user/app/b.txt');
|
|
217
|
+
await box.files.chmod('/home/user/app/b.txt', 0o755);
|
|
218
|
+
await box.files.readRange('/home/user/app/b.txt', 0, 64);
|
|
219
|
+
await box.files.delete('/home/user/app/b.txt');
|
|
210
220
|
|
|
211
221
|
await box.runtimes.available();
|
|
212
222
|
await box.runtimes.installed();
|
|
@@ -240,7 +250,7 @@ object with `tools.exec.execute`, `runCode`, `readFile`, `writeFile`,
|
|
|
240
250
|
`provider.capabilities` is intentionally honest: Nimbus claims shell,
|
|
241
251
|
JavaScript/TypeScript, npm, git, owned filesystem, outbound fetch, inbound
|
|
242
252
|
HTTP-like port routing, process spawn/long-running processes, Python/Ruby
|
|
243
|
-
when allowed, and clang
|
|
253
|
+
when allowed, and clang-backed WASI/WebAssembly execution. It does not claim Docker, apt, GPU,
|
|
244
254
|
custom Linux images, native Linux ELF execution, or raw TCP listeners.
|
|
245
255
|
|
|
246
256
|
## Quickstart — mint a session token
|
package/dist/sandbox.d.ts
CHANGED
|
@@ -22,6 +22,14 @@ export interface NimbusSandboxProfile {
|
|
|
22
22
|
}
|
|
23
23
|
export interface NimbusConfig {
|
|
24
24
|
endpoint?: string;
|
|
25
|
+
/**
|
|
26
|
+
* The deployment's `NIMBUS_PREVIEW_HOST_SUFFIX`, enabling the
|
|
27
|
+
* `<port>--<sid>.<suffix>` preview origin. `Nimbus.fromEnv` reads it off
|
|
28
|
+
* the bindings, so in-Worker callers never restate it; remote clients
|
|
29
|
+
* (`Nimbus.connect`) have no bindings and must supply it to get host-form
|
|
30
|
+
* preview URLs.
|
|
31
|
+
*/
|
|
32
|
+
previewHostSuffix?: string;
|
|
25
33
|
sandboxes?: Record<string, NimbusSandboxProfile>;
|
|
26
34
|
}
|
|
27
35
|
export interface NimbusFromEnvOptions {
|
|
@@ -64,6 +72,10 @@ export interface NimbusExecResult {
|
|
|
64
72
|
duration: number;
|
|
65
73
|
timestamp: number;
|
|
66
74
|
}
|
|
75
|
+
export interface NimbusTerminalSize {
|
|
76
|
+
columns: number;
|
|
77
|
+
rows: number;
|
|
78
|
+
}
|
|
67
79
|
export interface NimbusDestroyOptions {
|
|
68
80
|
reason?: string;
|
|
69
81
|
}
|
|
@@ -73,10 +85,18 @@ export interface NimbusDestroyResult {
|
|
|
73
85
|
destroyedAt: number;
|
|
74
86
|
reason: string | null;
|
|
75
87
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
88
|
+
/**
|
|
89
|
+
* A started background process. It is still running when `startProcess`
|
|
90
|
+
* returns, so there is no exit code or captured output here — poll
|
|
91
|
+
* `processes.logs(pid)` (which carries the exit record once it lands),
|
|
92
|
+
* `processes.list()`, or `processes.attach(pid)`.
|
|
93
|
+
*/
|
|
94
|
+
export interface NimbusStartResult {
|
|
95
|
+
command: string;
|
|
96
|
+
pid: number;
|
|
97
|
+
process: NimbusProcess;
|
|
79
98
|
ports: NimbusPort[];
|
|
99
|
+
startedAt: number;
|
|
80
100
|
}
|
|
81
101
|
export interface NimbusProcess {
|
|
82
102
|
pid: number;
|
|
@@ -88,6 +108,38 @@ export interface NimbusProcess {
|
|
|
88
108
|
startTime: number;
|
|
89
109
|
endTime: number | null;
|
|
90
110
|
longRunning: boolean;
|
|
111
|
+
attachedTty: boolean;
|
|
112
|
+
}
|
|
113
|
+
export interface NimbusProcessLogChunk {
|
|
114
|
+
seq: number;
|
|
115
|
+
ts: number;
|
|
116
|
+
stream: 'stdout' | 'stderr';
|
|
117
|
+
data: string;
|
|
118
|
+
binary?: boolean;
|
|
119
|
+
}
|
|
120
|
+
export interface NimbusProcessExitInfo {
|
|
121
|
+
code: number;
|
|
122
|
+
at: number;
|
|
123
|
+
reason?: string;
|
|
124
|
+
}
|
|
125
|
+
export interface NimbusProcessLogsOptions {
|
|
126
|
+
cursor?: number;
|
|
127
|
+
lines?: number;
|
|
128
|
+
bytes?: number;
|
|
129
|
+
}
|
|
130
|
+
export interface NimbusProcessLogsResult {
|
|
131
|
+
pid: number;
|
|
132
|
+
chunks: NimbusProcessLogChunk[];
|
|
133
|
+
text: string;
|
|
134
|
+
cursor: number;
|
|
135
|
+
truncated: boolean;
|
|
136
|
+
exit: NimbusProcessExitInfo | null;
|
|
137
|
+
}
|
|
138
|
+
export interface NimbusProcessAttachOptions {
|
|
139
|
+
pollIntervalMs?: number;
|
|
140
|
+
lines?: number;
|
|
141
|
+
bytes?: number;
|
|
142
|
+
signal?: AbortSignal;
|
|
91
143
|
}
|
|
92
144
|
export interface NimbusPort {
|
|
93
145
|
port: number;
|
|
@@ -105,12 +157,14 @@ export interface NimbusRuntimeSummary {
|
|
|
105
157
|
name: string;
|
|
106
158
|
version: string;
|
|
107
159
|
root: string;
|
|
160
|
+
abi: string;
|
|
108
161
|
bins: string[];
|
|
109
162
|
sizeBytes: number;
|
|
110
163
|
license: string;
|
|
111
164
|
}
|
|
112
165
|
export interface NimbusAvailableRuntime {
|
|
113
166
|
name: string;
|
|
167
|
+
abi: string;
|
|
114
168
|
defaultVersion: string;
|
|
115
169
|
versions: Array<{
|
|
116
170
|
version: string;
|
|
@@ -118,7 +172,82 @@ export interface NimbusAvailableRuntime {
|
|
|
118
172
|
license: string;
|
|
119
173
|
}>;
|
|
120
174
|
}
|
|
121
|
-
|
|
175
|
+
interface NimbusSessionStub {
|
|
176
|
+
_rpcReady(options?: {
|
|
177
|
+
preinstall?: string[];
|
|
178
|
+
}): Promise<{
|
|
179
|
+
ok: true;
|
|
180
|
+
preinstalled: string[];
|
|
181
|
+
}>;
|
|
182
|
+
_rpcExec(command: string, options?: Record<string, unknown>): Promise<NimbusExecResult>;
|
|
183
|
+
_rpcStartProcess(command: string, options?: Record<string, unknown>): Promise<NimbusStartResult>;
|
|
184
|
+
_rpcRunCode(code: string, options?: Record<string, unknown>): Promise<NimbusExecResult>;
|
|
185
|
+
_rpcReadFile(path: string): Promise<string | null>;
|
|
186
|
+
_rpcReadFileBytes(path: string): Promise<Uint8Array | null>;
|
|
187
|
+
_rpcWriteFile(path: string, content: string | Uint8Array): Promise<void>;
|
|
188
|
+
_rpcStat(path: string): Promise<NimbusFileStat | null>;
|
|
189
|
+
_rpcLstat(path: string): Promise<NimbusFileStat | null>;
|
|
190
|
+
_rpcReaddir(path: string): Promise<{
|
|
191
|
+
name: string;
|
|
192
|
+
type: string;
|
|
193
|
+
}[]>;
|
|
194
|
+
_rpcRename(from: string, to: string): Promise<void>;
|
|
195
|
+
_rpcChmod(path: string, mode: number): Promise<void>;
|
|
196
|
+
_rpcFsReadRange(path: string, offset: number, length: number): Promise<Uint8Array | null>;
|
|
197
|
+
_rpcExists(path: string): Promise<boolean>;
|
|
198
|
+
_rpcMkdir(path: string): Promise<void>;
|
|
199
|
+
_rpcDeleteFile(path: string, options?: {
|
|
200
|
+
recursive?: boolean;
|
|
201
|
+
}): Promise<void>;
|
|
202
|
+
_rpcInstallRuntime(spec: string, options?: {
|
|
203
|
+
force?: boolean;
|
|
204
|
+
}): Promise<unknown>;
|
|
205
|
+
_rpcEnsureRuntimes(specs: string[], options?: {
|
|
206
|
+
force?: boolean;
|
|
207
|
+
}): Promise<unknown>;
|
|
208
|
+
_rpcListRuntimes(): Promise<{
|
|
209
|
+
installed: NimbusRuntimeSummary[];
|
|
210
|
+
available: NimbusAvailableRuntime[];
|
|
211
|
+
}>;
|
|
212
|
+
_rpcListProcesses(): Promise<NimbusProcess[]>;
|
|
213
|
+
_rpcKillProcess(pid: number): Promise<{
|
|
214
|
+
ok: boolean;
|
|
215
|
+
pid: number;
|
|
216
|
+
}>;
|
|
217
|
+
_rpcWriteProcessInput(pid: number, data: string): Promise<{
|
|
218
|
+
ok: boolean;
|
|
219
|
+
pid: number;
|
|
220
|
+
}>;
|
|
221
|
+
_rpcEndProcessInput(pid: number): Promise<{
|
|
222
|
+
ok: boolean;
|
|
223
|
+
pid: number;
|
|
224
|
+
}>;
|
|
225
|
+
_rpcResizeProcess(pid: number, size: NimbusTerminalSize): Promise<{
|
|
226
|
+
ok: boolean;
|
|
227
|
+
pid: number;
|
|
228
|
+
}>;
|
|
229
|
+
_rpcSignalProcess(pid: number, signal: string): Promise<{
|
|
230
|
+
ok: boolean;
|
|
231
|
+
pid: number;
|
|
232
|
+
}>;
|
|
233
|
+
_rpcProcessLogs(pid: number, options?: NimbusProcessLogsOptions): Promise<NimbusProcessLogsResult>;
|
|
234
|
+
_rpcListPorts(): Promise<NimbusPort[]>;
|
|
235
|
+
_rpcExposePort(port: number): Promise<{
|
|
236
|
+
port: number;
|
|
237
|
+
listening: boolean;
|
|
238
|
+
pid: number | null;
|
|
239
|
+
registeredAt: number | null;
|
|
240
|
+
}>;
|
|
241
|
+
_rpcUnexposePort(port: number): Promise<{
|
|
242
|
+
port: number;
|
|
243
|
+
ok: boolean;
|
|
244
|
+
}>;
|
|
245
|
+
_rpcDestroy(options?: NimbusDestroyOptions): Promise<NimbusDestroyResult>;
|
|
246
|
+
}
|
|
247
|
+
interface NimbusSessionNamespace {
|
|
248
|
+
idFromName(name: string): DurableObjectId;
|
|
249
|
+
get(id: DurableObjectId): NimbusSessionStub;
|
|
250
|
+
}
|
|
122
251
|
type NimbusTarget = {
|
|
123
252
|
kind: 'binding';
|
|
124
253
|
namespace: NimbusSessionNamespace;
|
|
@@ -165,6 +294,10 @@ export declare class NimbusSandbox {
|
|
|
165
294
|
private remoteRpc;
|
|
166
295
|
ready(): Promise<void>;
|
|
167
296
|
exec(command: string, options?: NimbusExecOptions): Promise<NimbusExecResult>;
|
|
297
|
+
/**
|
|
298
|
+
* Start a command in the background. Returns as soon as the process has a
|
|
299
|
+
* pid — it does not wait for the command to finish.
|
|
300
|
+
*/
|
|
168
301
|
startProcess(command: string, options?: NimbusExecOptions): Promise<NimbusStartResult>;
|
|
169
302
|
runCode(code: string, options?: NimbusExecOptions & {
|
|
170
303
|
language?: 'javascript' | 'typescript' | 'python' | 'ruby' | 'shell';
|
|
@@ -176,6 +309,12 @@ export declare class NimbusSandbox {
|
|
|
176
309
|
readBytes: (path: string) => Promise<Uint8Array | null>;
|
|
177
310
|
write: (path: string, content: string | Uint8Array) => Promise<void>;
|
|
178
311
|
stat: (path: string) => Promise<NimbusFileStat | null>;
|
|
312
|
+
/** stat without following a symlink leaf. */
|
|
313
|
+
lstat: (path: string) => Promise<NimbusFileStat | null>;
|
|
314
|
+
rename: (from: string, to: string) => Promise<void>;
|
|
315
|
+
chmod: (path: string, mode: number) => Promise<void>;
|
|
316
|
+
/** Read `length` bytes at `offset` without materializing the whole file. */
|
|
317
|
+
readRange: (path: string, offset: number, length: number) => Promise<Uint8Array | null>;
|
|
179
318
|
list: (path?: string) => Promise<{
|
|
180
319
|
name: string;
|
|
181
320
|
type: string;
|
|
@@ -206,10 +345,24 @@ export declare class NimbusSandbox {
|
|
|
206
345
|
ok: boolean;
|
|
207
346
|
pid: number;
|
|
208
347
|
}>;
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
348
|
+
write: (pid: number, data: string) => Promise<{
|
|
349
|
+
ok: boolean;
|
|
350
|
+
pid: number;
|
|
351
|
+
}>;
|
|
352
|
+
endInput: (pid: number) => Promise<{
|
|
353
|
+
ok: boolean;
|
|
354
|
+
pid: number;
|
|
355
|
+
}>;
|
|
356
|
+
resize: (pid: number, size: NimbusTerminalSize) => Promise<{
|
|
357
|
+
ok: boolean;
|
|
358
|
+
pid: number;
|
|
359
|
+
}>;
|
|
360
|
+
signal: (pid: number, signal: string) => Promise<{
|
|
361
|
+
ok: boolean;
|
|
362
|
+
pid: number;
|
|
363
|
+
}>;
|
|
364
|
+
logs: (pid: number, options?: NimbusProcessLogsOptions) => Promise<NimbusProcessLogsResult>;
|
|
365
|
+
attach: (pid: number, options?: NimbusProcessAttachOptions) => NimbusProcessAttachment;
|
|
213
366
|
};
|
|
214
367
|
ports: {
|
|
215
368
|
list: () => Promise<NimbusPort[]>;
|
|
@@ -248,7 +401,7 @@ export declare class NimbusSandbox {
|
|
|
248
401
|
execute: (input: unknown) => Promise<string | null>;
|
|
249
402
|
};
|
|
250
403
|
writeFile: {
|
|
251
|
-
execute: (input:
|
|
404
|
+
execute: (input: unknown) => Promise<void>;
|
|
252
405
|
};
|
|
253
406
|
listFiles: {
|
|
254
407
|
execute: (input?: unknown) => Promise<{
|
|
@@ -263,7 +416,7 @@ export declare class NimbusSandbox {
|
|
|
263
416
|
}[]>;
|
|
264
417
|
};
|
|
265
418
|
deleteFile: {
|
|
266
|
-
execute: (input:
|
|
419
|
+
execute: (input: unknown) => Promise<void>;
|
|
267
420
|
};
|
|
268
421
|
exists: {
|
|
269
422
|
execute: (input: unknown) => Promise<boolean>;
|
|
@@ -279,12 +432,48 @@ export declare class NimbusSandbox {
|
|
|
279
432
|
pid: number;
|
|
280
433
|
}>;
|
|
281
434
|
};
|
|
435
|
+
writeProcessInput: {
|
|
436
|
+
execute: (input: {
|
|
437
|
+
pid: number;
|
|
438
|
+
data: string;
|
|
439
|
+
}) => Promise<{
|
|
440
|
+
ok: boolean;
|
|
441
|
+
pid: number;
|
|
442
|
+
}>;
|
|
443
|
+
};
|
|
444
|
+
endProcessInput: {
|
|
445
|
+
execute: (input: number | {
|
|
446
|
+
pid: number;
|
|
447
|
+
}) => Promise<{
|
|
448
|
+
ok: boolean;
|
|
449
|
+
pid: number;
|
|
450
|
+
}>;
|
|
451
|
+
};
|
|
452
|
+
resizeProcess: {
|
|
453
|
+
execute: (input: {
|
|
454
|
+
pid: number;
|
|
455
|
+
columns: number;
|
|
456
|
+
rows: number;
|
|
457
|
+
}) => Promise<{
|
|
458
|
+
ok: boolean;
|
|
459
|
+
pid: number;
|
|
460
|
+
}>;
|
|
461
|
+
};
|
|
462
|
+
signalProcess: {
|
|
463
|
+
execute: (input: {
|
|
464
|
+
pid: number;
|
|
465
|
+
signal: string;
|
|
466
|
+
}) => Promise<{
|
|
467
|
+
ok: boolean;
|
|
468
|
+
pid: number;
|
|
469
|
+
}>;
|
|
470
|
+
};
|
|
282
471
|
logs: {
|
|
283
472
|
execute: (input: number | {
|
|
284
473
|
pid: number;
|
|
285
474
|
lines?: number;
|
|
286
475
|
bytes?: number;
|
|
287
|
-
}) => Promise<
|
|
476
|
+
}) => Promise<NimbusProcessLogsResult>;
|
|
288
477
|
};
|
|
289
478
|
exposePort: {
|
|
290
479
|
execute: (input: number | {
|
|
@@ -322,7 +511,47 @@ export declare class NimbusSandbox {
|
|
|
322
511
|
capabilities(): string[];
|
|
323
512
|
private execOptions;
|
|
324
513
|
private assertRuntimeAllowed;
|
|
514
|
+
/**
|
|
515
|
+
* Browser-facing URL for an exposed port, or undefined when the deployment
|
|
516
|
+
* is not addressable (no `endpoint`, no configured preview base).
|
|
517
|
+
*
|
|
518
|
+
* The URL carries NO credential. On a deployment with auth enforced it is
|
|
519
|
+
* the destination, not the ticket: the session mints a single-use attach
|
|
520
|
+
* token for it at `GET /s/<id>/api/preview-url?port=<n>`, which is what the
|
|
521
|
+
* session shell opens and what an embedder should hand to a browser.
|
|
522
|
+
*/
|
|
325
523
|
private portUrl;
|
|
524
|
+
private rpc;
|
|
525
|
+
}
|
|
526
|
+
export declare class NimbusProcessAttachment implements AsyncIterable<NimbusProcessLogChunk> {
|
|
527
|
+
private readonly sandbox;
|
|
528
|
+
readonly pid: number;
|
|
529
|
+
private readonly options;
|
|
530
|
+
private cursor;
|
|
531
|
+
constructor(sandbox: NimbusSandbox, pid: number, options?: NimbusProcessAttachOptions);
|
|
532
|
+
write(data: string): Promise<{
|
|
533
|
+
ok: boolean;
|
|
534
|
+
pid: number;
|
|
535
|
+
}>;
|
|
536
|
+
endInput(): Promise<{
|
|
537
|
+
ok: boolean;
|
|
538
|
+
pid: number;
|
|
539
|
+
}>;
|
|
540
|
+
resize(size: NimbusTerminalSize): Promise<{
|
|
541
|
+
ok: boolean;
|
|
542
|
+
pid: number;
|
|
543
|
+
}>;
|
|
544
|
+
signal(signal: string): Promise<{
|
|
545
|
+
ok: boolean;
|
|
546
|
+
pid: number;
|
|
547
|
+
}>;
|
|
548
|
+
kill(): Promise<{
|
|
549
|
+
ok: boolean;
|
|
550
|
+
pid: number;
|
|
551
|
+
}>;
|
|
552
|
+
logs(options?: NimbusProcessLogsOptions): Promise<NimbusProcessLogsResult>;
|
|
553
|
+
stream(options?: NimbusProcessAttachOptions): AsyncIterable<NimbusProcessLogChunk>;
|
|
554
|
+
[Symbol.asyncIterator](): AsyncIterator<NimbusProcessLogChunk>;
|
|
326
555
|
}
|
|
327
556
|
export {};
|
|
328
557
|
//# sourceMappingURL=sandbox.d.ts.map
|
package/dist/sandbox.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AACjC,MAAM,MAAM,WAAW,GACnB,MAAM,GACN,KAAK,GACL,KAAK,GACL,KAAK,GACL,QAAQ,GACR,MAAM,GACN,OAAO,GACP,OAAO,GACP,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAElB,MAAM,WAAW,mBAAmB;IAClC,UAAU,CAAC,EAAE,WAAW,EAAE,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAC/B,KAAK,CAAC,EAAE;QACN,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IACF,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,OAAO,CAAC;KACrB,CAAC;CACH;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CA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AAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IAI7D,IAAI,IAAI,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IAI7C,IAAI,CAAC,OAAO,GAAE,wBAA6B,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAMpF,MAAM,CAAC,OAAO,GAAE,0BAA+B,GAAG,aAAa,CAAC,qBAAqB,CAAC;IAkCtF,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,qBAAqB,CAAC;CAG/D"}
|
package/dist/sandbox.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @nimbus-sh/sdk/sandbox - programmatic Nimbus sandbox handle.
|
|
3
3
|
*/
|
|
4
|
+
import { buildPreviewHost, isPreviewHostSafeSid, readPreviewHostSuffix, } from '@nimbus-sh/worker/preview-host';
|
|
5
|
+
import { z } from 'zod/v4';
|
|
4
6
|
export class NimbusRemoteError extends Error {
|
|
5
7
|
status;
|
|
6
8
|
code;
|
|
@@ -13,6 +15,150 @@ export class NimbusRemoteError extends Error {
|
|
|
13
15
|
this.body = options.body;
|
|
14
16
|
}
|
|
15
17
|
}
|
|
18
|
+
const RemoteRpcSuccessSchema = z.object({
|
|
19
|
+
ok: z.literal(true),
|
|
20
|
+
result: z.unknown().optional(),
|
|
21
|
+
}).passthrough();
|
|
22
|
+
const RemoteRpcFailureSchema = z.object({
|
|
23
|
+
ok: z.boolean().optional(),
|
|
24
|
+
error: z.string().optional(),
|
|
25
|
+
message: z.string().optional(),
|
|
26
|
+
code: z.string().optional(),
|
|
27
|
+
}).passthrough();
|
|
28
|
+
const WireBytesSchema = z.object({
|
|
29
|
+
__nimbusWireType: z.literal('bytes'),
|
|
30
|
+
base64: z.string(),
|
|
31
|
+
}).passthrough();
|
|
32
|
+
const UndefinedResultSchema = z.undefined();
|
|
33
|
+
const UnknownResultSchema = z.unknown();
|
|
34
|
+
/** `_rpcWriteFile` answers with the byte count the VFS wrote. */
|
|
35
|
+
const WriteFileResultSchema = z.number();
|
|
36
|
+
const StringOrNullSchema = z.string().nullable();
|
|
37
|
+
const Uint8ArrayOrNullSchema = z.instanceof(Uint8Array).nullable();
|
|
38
|
+
const BooleanResultSchema = z.boolean();
|
|
39
|
+
const ReadyResultSchema = z.object({
|
|
40
|
+
ok: z.literal(true),
|
|
41
|
+
preinstalled: z.array(z.string()),
|
|
42
|
+
});
|
|
43
|
+
const ExecResultSchema = z.object({
|
|
44
|
+
command: z.string(),
|
|
45
|
+
exitCode: z.number(),
|
|
46
|
+
success: z.boolean(),
|
|
47
|
+
stdout: z.string(),
|
|
48
|
+
stderr: z.string(),
|
|
49
|
+
duration: z.number(),
|
|
50
|
+
timestamp: z.number(),
|
|
51
|
+
});
|
|
52
|
+
const ProcessSchema = z.object({
|
|
53
|
+
pid: z.number(),
|
|
54
|
+
command: z.string(),
|
|
55
|
+
argv: z.array(z.string()),
|
|
56
|
+
cwd: z.string(),
|
|
57
|
+
state: z.string(),
|
|
58
|
+
exitCode: z.number().nullable(),
|
|
59
|
+
startTime: z.number(),
|
|
60
|
+
endTime: z.number().nullable(),
|
|
61
|
+
longRunning: z.boolean(),
|
|
62
|
+
attachedTty: z.boolean().optional().default(false),
|
|
63
|
+
});
|
|
64
|
+
const PortSchema = z.object({
|
|
65
|
+
port: z.number(),
|
|
66
|
+
pid: z.number(),
|
|
67
|
+
registeredAt: z.number(),
|
|
68
|
+
});
|
|
69
|
+
const StartResultSchema = z.object({
|
|
70
|
+
command: z.string(),
|
|
71
|
+
pid: z.number(),
|
|
72
|
+
process: ProcessSchema,
|
|
73
|
+
ports: z.array(PortSchema),
|
|
74
|
+
startedAt: z.number(),
|
|
75
|
+
});
|
|
76
|
+
const FileStatSchema = z.object({
|
|
77
|
+
type: z.string(),
|
|
78
|
+
size: z.number(),
|
|
79
|
+
ctime: z.number().optional(),
|
|
80
|
+
mtime: z.number(),
|
|
81
|
+
mode: z.number(),
|
|
82
|
+
});
|
|
83
|
+
const DirectoryEntrySchema = z.object({
|
|
84
|
+
name: z.string(),
|
|
85
|
+
type: z.string(),
|
|
86
|
+
});
|
|
87
|
+
const RuntimeSummarySchema = z.object({
|
|
88
|
+
name: z.string(),
|
|
89
|
+
version: z.string(),
|
|
90
|
+
root: z.string(),
|
|
91
|
+
abi: z.string(),
|
|
92
|
+
bins: z.array(z.string()),
|
|
93
|
+
sizeBytes: z.number(),
|
|
94
|
+
license: z.string(),
|
|
95
|
+
});
|
|
96
|
+
const AvailableRuntimeSchema = z.object({
|
|
97
|
+
name: z.string(),
|
|
98
|
+
abi: z.string(),
|
|
99
|
+
defaultVersion: z.string(),
|
|
100
|
+
versions: z.array(z.object({
|
|
101
|
+
version: z.string(),
|
|
102
|
+
sizeBytes: z.number(),
|
|
103
|
+
license: z.string(),
|
|
104
|
+
})),
|
|
105
|
+
});
|
|
106
|
+
const RuntimeListSchema = z.object({
|
|
107
|
+
installed: z.array(RuntimeSummarySchema),
|
|
108
|
+
available: z.array(AvailableRuntimeSchema),
|
|
109
|
+
});
|
|
110
|
+
const ProcessControlResultSchema = z.object({
|
|
111
|
+
ok: z.boolean(),
|
|
112
|
+
pid: z.number(),
|
|
113
|
+
});
|
|
114
|
+
const ProcessLogChunkSchema = z.object({
|
|
115
|
+
seq: z.number(),
|
|
116
|
+
ts: z.number(),
|
|
117
|
+
stream: z.enum(['stdout', 'stderr']),
|
|
118
|
+
data: z.string(),
|
|
119
|
+
binary: z.boolean().optional(),
|
|
120
|
+
});
|
|
121
|
+
const ProcessExitInfoSchema = z.object({
|
|
122
|
+
code: z.number(),
|
|
123
|
+
at: z.number(),
|
|
124
|
+
reason: z.string().optional(),
|
|
125
|
+
});
|
|
126
|
+
const ProcessLogsResultSchema = z.object({
|
|
127
|
+
pid: z.number(),
|
|
128
|
+
chunks: z.array(ProcessLogChunkSchema),
|
|
129
|
+
text: z.string(),
|
|
130
|
+
cursor: z.number(),
|
|
131
|
+
truncated: z.boolean(),
|
|
132
|
+
exit: ProcessExitInfoSchema.nullable(),
|
|
133
|
+
});
|
|
134
|
+
const ExposedPortSchema = z.object({
|
|
135
|
+
port: z.number(),
|
|
136
|
+
listening: z.boolean(),
|
|
137
|
+
pid: z.number().nullable(),
|
|
138
|
+
registeredAt: z.number().nullable(),
|
|
139
|
+
});
|
|
140
|
+
const UnexposedPortSchema = z.object({
|
|
141
|
+
port: z.number(),
|
|
142
|
+
ok: z.boolean(),
|
|
143
|
+
});
|
|
144
|
+
const DestroyResultSchema = z.object({
|
|
145
|
+
ok: z.literal(true),
|
|
146
|
+
killed: z.number(),
|
|
147
|
+
destroyedAt: z.number(),
|
|
148
|
+
reason: z.string().nullable(),
|
|
149
|
+
});
|
|
150
|
+
const ToolPathInputSchema = z.object({
|
|
151
|
+
path: z.string().optional(),
|
|
152
|
+
}).passthrough();
|
|
153
|
+
const ToolWriteFileInputSchema = z.object({
|
|
154
|
+
path: z.string().optional(),
|
|
155
|
+
content: z.union([z.string(), z.instanceof(Uint8Array)]).optional(),
|
|
156
|
+
data: z.union([z.string(), z.instanceof(Uint8Array)]).optional(),
|
|
157
|
+
}).passthrough();
|
|
158
|
+
const ToolDeleteFileInputSchema = z.object({
|
|
159
|
+
path: z.string().optional(),
|
|
160
|
+
recursive: z.boolean().optional(),
|
|
161
|
+
}).passthrough();
|
|
16
162
|
export class Nimbus {
|
|
17
163
|
config;
|
|
18
164
|
static fromEnv(env, config = {}, options = {}) {
|
|
@@ -24,6 +170,9 @@ export class Nimbus {
|
|
|
24
170
|
return new Nimbus({ kind: 'binding', namespace: binding }, {
|
|
25
171
|
...config,
|
|
26
172
|
endpoint: options.endpoint ?? config.endpoint,
|
|
173
|
+
// The binding is the deployment's own answer for whether port previews
|
|
174
|
+
// have a host suffix, so in-Worker callers never restate it in config.
|
|
175
|
+
previewHostSuffix: readPreviewHostSuffix(env) ?? config.previewHostSuffix,
|
|
27
176
|
});
|
|
28
177
|
}
|
|
29
178
|
static connect(options) {
|
|
@@ -88,37 +237,49 @@ export class NimbusSandbox {
|
|
|
88
237
|
stub() {
|
|
89
238
|
if (this.target.kind === 'remote')
|
|
90
239
|
return this.remoteStub();
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
return namespace.get(id);
|
|
240
|
+
const id = this.target.namespace.idFromName(this.doName);
|
|
241
|
+
return this.target.namespace.get(id);
|
|
94
242
|
}
|
|
95
243
|
remoteStub() {
|
|
96
244
|
return {
|
|
97
|
-
_rpcReady: (options) => this.remoteRpc('ready', [options]),
|
|
98
|
-
_rpcExec: (command, options) => this.remoteRpc('exec', [command, options]),
|
|
99
|
-
_rpcStartProcess: (command, options) => this.remoteRpc('startProcess', [command, options]),
|
|
100
|
-
_rpcRunCode: (code, options) => this.remoteRpc('runCode', [code, options]),
|
|
101
|
-
_rpcReadFile: (path) => this.remoteRpc('readFile', [path]),
|
|
102
|
-
_rpcReadFileBytes: (path) => this.remoteRpc('readFileBytes', [path]),
|
|
103
|
-
_rpcWriteFile: (path, content) =>
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
245
|
+
_rpcReady: (options) => this.remoteRpc('ready', [options], ReadyResultSchema),
|
|
246
|
+
_rpcExec: (command, options) => this.remoteRpc('exec', [command, options], ExecResultSchema),
|
|
247
|
+
_rpcStartProcess: (command, options) => this.remoteRpc('startProcess', [command, options], StartResultSchema),
|
|
248
|
+
_rpcRunCode: (code, options) => this.remoteRpc('runCode', [code, options], ExecResultSchema),
|
|
249
|
+
_rpcReadFile: (path) => this.remoteRpc('readFile', [path], StringOrNullSchema),
|
|
250
|
+
_rpcReadFileBytes: (path) => this.remoteRpc('readFileBytes', [path], Uint8ArrayOrNullSchema),
|
|
251
|
+
_rpcWriteFile: async (path, content) => {
|
|
252
|
+
// The byte count is the wire contract but not part of the public
|
|
253
|
+
// `files.write` surface, so it is validated and dropped. Declaring
|
|
254
|
+
// this `undefined` made every remote write throw after succeeding.
|
|
255
|
+
await this.remoteRpc('writeFile', [path, content], WriteFileResultSchema);
|
|
256
|
+
},
|
|
257
|
+
_rpcStat: (path) => this.remoteRpc('stat', [path], FileStatSchema.nullable()),
|
|
258
|
+
_rpcLstat: (path) => this.remoteRpc('lstat', [path], FileStatSchema.nullable()),
|
|
259
|
+
_rpcRename: (from, to) => this.remoteRpc('rename', [from, to], UndefinedResultSchema),
|
|
260
|
+
_rpcChmod: (path, mode) => this.remoteRpc('chmod', [path, mode], UndefinedResultSchema),
|
|
261
|
+
_rpcFsReadRange: (path, offset, length) => this.remoteRpc('readRange', [path, offset, length], Uint8ArrayOrNullSchema),
|
|
262
|
+
_rpcReaddir: (path) => this.remoteRpc('readdir', [path], z.array(DirectoryEntrySchema)),
|
|
263
|
+
_rpcExists: (path) => this.remoteRpc('exists', [path], BooleanResultSchema),
|
|
264
|
+
_rpcMkdir: (path) => this.remoteRpc('mkdir', [path], UndefinedResultSchema),
|
|
265
|
+
_rpcDeleteFile: (path, options) => this.remoteRpc('deleteFile', [path, options], UndefinedResultSchema),
|
|
266
|
+
_rpcInstallRuntime: (spec, options) => this.remoteRpc('installRuntime', [spec, options], UnknownResultSchema),
|
|
267
|
+
_rpcEnsureRuntimes: (specs, options) => this.remoteRpc('ensureRuntimes', [specs, options], UnknownResultSchema),
|
|
268
|
+
_rpcListRuntimes: () => this.remoteRpc('listRuntimes', [], RuntimeListSchema),
|
|
269
|
+
_rpcListProcesses: () => this.remoteRpc('listProcesses', [], z.array(ProcessSchema)),
|
|
270
|
+
_rpcKillProcess: (pid) => this.remoteRpc('killProcess', [pid], ProcessControlResultSchema),
|
|
271
|
+
_rpcWriteProcessInput: (pid, data) => this.remoteRpc('writeProcessInput', [pid, data], ProcessControlResultSchema),
|
|
272
|
+
_rpcEndProcessInput: (pid) => this.remoteRpc('endProcessInput', [pid], ProcessControlResultSchema),
|
|
273
|
+
_rpcResizeProcess: (pid, size) => this.remoteRpc('resizeProcess', [pid, size], ProcessControlResultSchema),
|
|
274
|
+
_rpcSignalProcess: (pid, signal) => this.remoteRpc('signalProcess', [pid, signal], ProcessControlResultSchema),
|
|
275
|
+
_rpcProcessLogs: (pid, options) => this.remoteRpc('processLogs', [pid, options], ProcessLogsResultSchema),
|
|
276
|
+
_rpcListPorts: () => this.remoteRpc('listPorts', [], z.array(PortSchema)),
|
|
277
|
+
_rpcExposePort: (port) => this.remoteRpc('exposePort', [port], ExposedPortSchema),
|
|
278
|
+
_rpcUnexposePort: (port) => this.remoteRpc('unexposePort', [port], UnexposedPortSchema),
|
|
279
|
+
_rpcDestroy: (options) => this.remoteRpc('destroy', [options], DestroyResultSchema),
|
|
119
280
|
};
|
|
120
281
|
}
|
|
121
|
-
async remoteRpc(op, args) {
|
|
282
|
+
async remoteRpc(op, args, resultSchema) {
|
|
122
283
|
if (this.target.kind !== 'remote') {
|
|
123
284
|
throw new Error('Nimbus internal error: remoteRpc called on non-remote target');
|
|
124
285
|
}
|
|
@@ -153,32 +314,40 @@ export class NimbusSandbox {
|
|
|
153
314
|
});
|
|
154
315
|
}
|
|
155
316
|
}
|
|
156
|
-
|
|
157
|
-
|
|
317
|
+
const success = RemoteRpcSuccessSchema.safeParse(payload);
|
|
318
|
+
if (!response.ok || !success.success) {
|
|
319
|
+
const failure = RemoteRpcFailureSchema.safeParse(payload);
|
|
320
|
+
const message = failure.success
|
|
321
|
+
? failure.data.error ?? failure.data.message ?? `Nimbus remote API request failed (${response.status})`
|
|
322
|
+
: `Nimbus remote API request failed (${response.status})`;
|
|
158
323
|
throw new NimbusRemoteError(message, {
|
|
159
324
|
status: response.status,
|
|
160
|
-
code:
|
|
325
|
+
code: failure.success ? failure.data.code : undefined,
|
|
161
326
|
body: payload,
|
|
162
327
|
});
|
|
163
328
|
}
|
|
164
|
-
return decodeWire(
|
|
329
|
+
return resultSchema.parse(decodeWire(success.data.result));
|
|
165
330
|
}
|
|
166
331
|
async ready() {
|
|
167
332
|
if (!this.readyPromise) {
|
|
168
333
|
const preinstall = this.profile.runtimes?.preinstall ?? [];
|
|
169
334
|
for (const spec of preinstall)
|
|
170
335
|
this.assertRuntimeAllowed(spec, 'preinstall');
|
|
171
|
-
this.readyPromise = this.stub()._rpcReady({ preinstall }).then(() => undefined);
|
|
336
|
+
this.readyPromise = this.rpc(this.stub()._rpcReady({ preinstall })).then(() => undefined);
|
|
172
337
|
}
|
|
173
338
|
return this.readyPromise;
|
|
174
339
|
}
|
|
175
340
|
async exec(command, options = {}) {
|
|
176
341
|
await this.ready();
|
|
177
|
-
return this.stub()._rpcExec(command, this.execOptions(options));
|
|
342
|
+
return this.rpc(this.stub()._rpcExec(command, this.execOptions(options)));
|
|
178
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* Start a command in the background. Returns as soon as the process has a
|
|
346
|
+
* pid — it does not wait for the command to finish.
|
|
347
|
+
*/
|
|
179
348
|
async startProcess(command, options = {}) {
|
|
180
349
|
await this.ready();
|
|
181
|
-
return this.stub()._rpcStartProcess(command, this.execOptions(options));
|
|
350
|
+
return this.rpc(this.stub()._rpcStartProcess(command, this.execOptions(options)));
|
|
182
351
|
}
|
|
183
352
|
async runCode(code, options = {}) {
|
|
184
353
|
const language = options.language ?? 'javascript';
|
|
@@ -186,110 +355,164 @@ export class NimbusSandbox {
|
|
|
186
355
|
this.assertRuntimeAllowed(language, options.install === 'ifMissing' ? 'onDemand' : 'use');
|
|
187
356
|
}
|
|
188
357
|
await this.ready();
|
|
189
|
-
return this.stub()._rpcRunCode(code, {
|
|
358
|
+
return this.rpc(this.stub()._rpcRunCode(code, {
|
|
190
359
|
...this.execOptions(options),
|
|
191
360
|
language,
|
|
192
361
|
install: options.install ?? 'never',
|
|
193
|
-
});
|
|
362
|
+
}));
|
|
194
363
|
}
|
|
195
364
|
async destroy(options = {}) {
|
|
196
365
|
this.readyPromise = null;
|
|
197
|
-
return this.stub()._rpcDestroy(options);
|
|
366
|
+
return this.rpc(this.stub()._rpcDestroy(options));
|
|
198
367
|
}
|
|
199
368
|
files = {
|
|
200
369
|
read: async (path) => {
|
|
201
370
|
await this.ready();
|
|
202
|
-
return this.stub()._rpcReadFile(path);
|
|
371
|
+
return this.rpc(this.stub()._rpcReadFile(path));
|
|
203
372
|
},
|
|
204
373
|
readBytes: async (path) => {
|
|
205
374
|
await this.ready();
|
|
206
|
-
return this.stub()._rpcReadFileBytes(path);
|
|
375
|
+
return this.rpc(this.stub()._rpcReadFileBytes(path));
|
|
207
376
|
},
|
|
208
377
|
write: async (path, content) => {
|
|
209
378
|
await this.ready();
|
|
210
|
-
return this.stub()._rpcWriteFile(path, content);
|
|
379
|
+
return this.rpc(this.stub()._rpcWriteFile(path, content));
|
|
211
380
|
},
|
|
212
381
|
stat: async (path) => {
|
|
213
382
|
await this.ready();
|
|
214
|
-
return this.stub()._rpcStat(path);
|
|
383
|
+
return this.rpc(this.stub()._rpcStat(path));
|
|
384
|
+
},
|
|
385
|
+
/** stat without following a symlink leaf. */
|
|
386
|
+
lstat: async (path) => {
|
|
387
|
+
await this.ready();
|
|
388
|
+
return this.rpc(this.stub()._rpcLstat(path));
|
|
389
|
+
},
|
|
390
|
+
rename: async (from, to) => {
|
|
391
|
+
await this.ready();
|
|
392
|
+
return this.rpc(this.stub()._rpcRename(from, to));
|
|
393
|
+
},
|
|
394
|
+
chmod: async (path, mode) => {
|
|
395
|
+
await this.ready();
|
|
396
|
+
return this.rpc(this.stub()._rpcChmod(path, mode));
|
|
397
|
+
},
|
|
398
|
+
/** Read `length` bytes at `offset` without materializing the whole file. */
|
|
399
|
+
readRange: async (path, offset, length) => {
|
|
400
|
+
await this.ready();
|
|
401
|
+
return this.rpc(this.stub()._rpcFsReadRange(path, offset, length));
|
|
215
402
|
},
|
|
216
403
|
list: async (path = this.root) => {
|
|
217
404
|
await this.ready();
|
|
218
|
-
return this.stub()._rpcReaddir(path);
|
|
405
|
+
return this.rpc(this.stub()._rpcReaddir(path));
|
|
219
406
|
},
|
|
220
407
|
mkdir: async (path) => {
|
|
221
408
|
await this.ready();
|
|
222
|
-
return this.stub()._rpcMkdir(path);
|
|
409
|
+
return this.rpc(this.stub()._rpcMkdir(path));
|
|
223
410
|
},
|
|
224
411
|
exists: async (path) => {
|
|
225
412
|
await this.ready();
|
|
226
|
-
return this.stub()._rpcExists(path);
|
|
413
|
+
return this.rpc(this.stub()._rpcExists(path));
|
|
227
414
|
},
|
|
228
415
|
delete: async (path, options = {}) => {
|
|
229
416
|
await this.ready();
|
|
230
|
-
return this.stub()._rpcDeleteFile(path, options);
|
|
417
|
+
return this.rpc(this.stub()._rpcDeleteFile(path, options));
|
|
231
418
|
},
|
|
232
419
|
};
|
|
233
420
|
runtimes = {
|
|
234
421
|
available: async () => {
|
|
235
422
|
await this.ready();
|
|
236
|
-
return (await this.stub()._rpcListRuntimes()).available;
|
|
423
|
+
return (await this.rpc(this.stub()._rpcListRuntimes())).available;
|
|
237
424
|
},
|
|
238
425
|
installed: async () => {
|
|
239
426
|
await this.ready();
|
|
240
|
-
return (await this.stub()._rpcListRuntimes()).installed;
|
|
427
|
+
return (await this.rpc(this.stub()._rpcListRuntimes())).installed;
|
|
241
428
|
},
|
|
242
429
|
list: async () => {
|
|
243
430
|
await this.ready();
|
|
244
|
-
return this.stub()._rpcListRuntimes();
|
|
431
|
+
return this.rpc(this.stub()._rpcListRuntimes());
|
|
245
432
|
},
|
|
246
433
|
install: async (spec, options = {}) => {
|
|
247
434
|
this.assertRuntimeAllowed(spec, 'onDemand');
|
|
248
435
|
await this.ready();
|
|
249
|
-
return this.stub()._rpcInstallRuntime(spec, options);
|
|
436
|
+
return this.rpc(this.stub()._rpcInstallRuntime(spec, options));
|
|
250
437
|
},
|
|
251
438
|
ensure: async (specs, options = {}) => {
|
|
252
439
|
const list = Array.isArray(specs) ? specs : [specs];
|
|
253
440
|
for (const spec of list)
|
|
254
441
|
this.assertRuntimeAllowed(spec, 'onDemand');
|
|
255
442
|
await this.ready();
|
|
256
|
-
return this.stub()._rpcEnsureRuntimes(list, options);
|
|
443
|
+
return this.rpc(this.stub()._rpcEnsureRuntimes(list, options));
|
|
257
444
|
},
|
|
258
445
|
};
|
|
259
446
|
processes = {
|
|
260
447
|
list: async () => {
|
|
261
448
|
await this.ready();
|
|
262
|
-
return this.stub()._rpcListProcesses();
|
|
449
|
+
return this.rpc(this.stub()._rpcListProcesses());
|
|
263
450
|
},
|
|
264
451
|
kill: async (pid) => {
|
|
265
452
|
await this.ready();
|
|
266
|
-
return this.stub()._rpcKillProcess(pid);
|
|
453
|
+
return this.rpc(this.stub()._rpcKillProcess(pid));
|
|
454
|
+
},
|
|
455
|
+
write: async (pid, data) => {
|
|
456
|
+
await this.ready();
|
|
457
|
+
return this.rpc(this.stub()._rpcWriteProcessInput(pid, data));
|
|
458
|
+
},
|
|
459
|
+
endInput: async (pid) => {
|
|
460
|
+
await this.ready();
|
|
461
|
+
return this.rpc(this.stub()._rpcEndProcessInput(pid));
|
|
462
|
+
},
|
|
463
|
+
resize: async (pid, size) => {
|
|
464
|
+
await this.ready();
|
|
465
|
+
return this.rpc(this.stub()._rpcResizeProcess(pid, size));
|
|
466
|
+
},
|
|
467
|
+
signal: async (pid, signal) => {
|
|
468
|
+
await this.ready();
|
|
469
|
+
return this.rpc(this.stub()._rpcSignalProcess(pid, signal));
|
|
267
470
|
},
|
|
268
471
|
logs: async (pid, options = {}) => {
|
|
269
472
|
await this.ready();
|
|
270
|
-
return this.stub()._rpcProcessLogs(pid, options);
|
|
473
|
+
return this.rpc(this.stub()._rpcProcessLogs(pid, options));
|
|
474
|
+
},
|
|
475
|
+
attach: (pid, options = {}) => {
|
|
476
|
+
return new NimbusProcessAttachment(this, pid, options);
|
|
271
477
|
},
|
|
272
478
|
};
|
|
273
479
|
ports = {
|
|
274
480
|
list: async () => {
|
|
275
481
|
await this.ready();
|
|
276
|
-
return this.stub()._rpcListPorts();
|
|
482
|
+
return this.rpc(this.stub()._rpcListPorts());
|
|
277
483
|
},
|
|
278
484
|
expose: async (port) => {
|
|
279
485
|
await this.ready();
|
|
280
|
-
const result = await this.stub()._rpcExposePort(port);
|
|
486
|
+
const result = await this.rpc(this.stub()._rpcExposePort(port));
|
|
281
487
|
return { ...result, url: this.portUrl(port) };
|
|
282
488
|
},
|
|
283
489
|
unexpose: async (port) => {
|
|
284
490
|
await this.ready();
|
|
285
|
-
return this.stub()._rpcUnexposePort(port);
|
|
491
|
+
return this.rpc(this.stub()._rpcUnexposePort(port));
|
|
286
492
|
},
|
|
287
493
|
url: (port) => this.portUrl(port),
|
|
288
494
|
};
|
|
289
495
|
tools(options = {}) {
|
|
290
496
|
const namespace = options.namespace ?? this.profile.tools?.namespace ?? 'nimbus';
|
|
291
497
|
const kind = options.kind ?? this.profile.tools?.kind ?? 'nimbus';
|
|
292
|
-
const callPath = (input) =>
|
|
498
|
+
const callPath = (input) => {
|
|
499
|
+
if (typeof input === 'string')
|
|
500
|
+
return input;
|
|
501
|
+
return ToolPathInputSchema.parse(input).path ?? '';
|
|
502
|
+
};
|
|
503
|
+
const writeFileInput = (input) => {
|
|
504
|
+
const parsed = ToolWriteFileInputSchema.parse(input);
|
|
505
|
+
return {
|
|
506
|
+
path: parsed.path ?? '',
|
|
507
|
+
content: parsed.content ?? parsed.data ?? '',
|
|
508
|
+
};
|
|
509
|
+
};
|
|
510
|
+
const deleteFileInput = (input) => {
|
|
511
|
+
if (typeof input === 'string')
|
|
512
|
+
return { path: input, recursive: false };
|
|
513
|
+
const parsed = ToolDeleteFileInputSchema.parse(input);
|
|
514
|
+
return { path: parsed.path ?? '', recursive: parsed.recursive === true };
|
|
515
|
+
};
|
|
293
516
|
return {
|
|
294
517
|
name: options.name ?? namespace,
|
|
295
518
|
kind,
|
|
@@ -301,13 +524,23 @@ export class NimbusSandbox {
|
|
|
301
524
|
exec: { execute: (command, opts) => this.exec(command, opts) },
|
|
302
525
|
runCode: { execute: (code, opts) => this.runCode(code, opts) },
|
|
303
526
|
readFile: { execute: (input) => this.files.read(callPath(input)) },
|
|
304
|
-
writeFile: { execute: (input) =>
|
|
527
|
+
writeFile: { execute: (input) => {
|
|
528
|
+
const parsed = writeFileInput(input);
|
|
529
|
+
return this.files.write(parsed.path, parsed.content);
|
|
530
|
+
} },
|
|
305
531
|
listFiles: { execute: (input = this.root) => this.files.list(callPath(input) || this.root) },
|
|
306
532
|
readdir: { execute: (input = this.root) => this.files.list(callPath(input) || this.root) },
|
|
307
|
-
deleteFile: { execute: (input) =>
|
|
533
|
+
deleteFile: { execute: (input) => {
|
|
534
|
+
const parsed = deleteFileInput(input);
|
|
535
|
+
return this.files.delete(parsed.path, { recursive: parsed.recursive });
|
|
536
|
+
} },
|
|
308
537
|
exists: { execute: (input) => this.files.exists(callPath(input)) },
|
|
309
538
|
startProcess: { execute: (command, opts) => this.startProcess(command, opts) },
|
|
310
539
|
killProcess: { execute: (input) => this.processes.kill(typeof input === 'number' ? input : input.pid) },
|
|
540
|
+
writeProcessInput: { execute: (input) => this.processes.write(input.pid, input.data) },
|
|
541
|
+
endProcessInput: { execute: (input) => this.processes.endInput(typeof input === 'number' ? input : input.pid) },
|
|
542
|
+
resizeProcess: { execute: (input) => this.processes.resize(input.pid, { columns: input.columns, rows: input.rows }) },
|
|
543
|
+
signalProcess: { execute: (input) => this.processes.signal(input.pid, input.signal) },
|
|
311
544
|
logs: { execute: (input) => this.processes.logs(typeof input === 'number' ? input : input.pid, typeof input === 'number' ? {} : input) },
|
|
312
545
|
exposePort: { execute: (input) => this.ports.expose(typeof input === 'number' ? input : input.port) },
|
|
313
546
|
unexposePort: { execute: (input) => this.ports.unexpose(typeof input === 'number' ? input : input.port) },
|
|
@@ -331,11 +564,16 @@ export class NimbusSandbox {
|
|
|
331
564
|
'net_inbound',
|
|
332
565
|
'process_spawn',
|
|
333
566
|
'process_long',
|
|
567
|
+
'process_attached_stdio',
|
|
568
|
+
'terminal_resize',
|
|
569
|
+
'ansi_output',
|
|
334
570
|
];
|
|
335
571
|
if (hasRuntime('python'))
|
|
336
572
|
caps.push('python');
|
|
573
|
+
if (hasRuntime('ruby'))
|
|
574
|
+
caps.push('ruby');
|
|
337
575
|
if (hasRuntime('clang'))
|
|
338
|
-
caps.push('
|
|
576
|
+
caps.push('wasi', 'clang_wasi');
|
|
339
577
|
return caps;
|
|
340
578
|
}
|
|
341
579
|
execOptions(options) {
|
|
@@ -358,7 +596,20 @@ export class NimbusSandbox {
|
|
|
358
596
|
throw new Error(`Nimbus runtime '${name}' is not preinstalled and on-demand runtime installs are disabled by sandbox profile '${this.profileName}'`);
|
|
359
597
|
}
|
|
360
598
|
}
|
|
599
|
+
/**
|
|
600
|
+
* Browser-facing URL for an exposed port, or undefined when the deployment
|
|
601
|
+
* is not addressable (no `endpoint`, no configured preview base).
|
|
602
|
+
*
|
|
603
|
+
* The URL carries NO credential. On a deployment with auth enforced it is
|
|
604
|
+
* the destination, not the ticket: the session mints a single-use attach
|
|
605
|
+
* token for it at `GET /s/<id>/api/preview-url?port=<n>`, which is what the
|
|
606
|
+
* session shell opens and what an embedder should hand to a browser.
|
|
607
|
+
*/
|
|
361
608
|
portUrl(port) {
|
|
609
|
+
const hostSuffix = this.config.previewHostSuffix;
|
|
610
|
+
if (hostSuffix && !this.profile.preview?.pathStyle && isPreviewHostSafeSid(this.id)) {
|
|
611
|
+
return `https://${buildPreviewHost(this.id, port, hostSuffix)}/`;
|
|
612
|
+
}
|
|
362
613
|
const explicit = this.profile.preview?.baseUrl;
|
|
363
614
|
if (explicit) {
|
|
364
615
|
const base = trimTrailingSlashes(explicit.replace('{sessionId}', encodeURIComponent(this.id)));
|
|
@@ -369,6 +620,81 @@ export class NimbusSandbox {
|
|
|
369
620
|
return undefined;
|
|
370
621
|
return `${endpoint}/s/${encodeURIComponent(this.id)}/port/${port}/`;
|
|
371
622
|
}
|
|
623
|
+
async rpc(promise) {
|
|
624
|
+
const value = await promise;
|
|
625
|
+
disposeSdkRpcResult(value);
|
|
626
|
+
return value;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
export class NimbusProcessAttachment {
|
|
630
|
+
sandbox;
|
|
631
|
+
pid;
|
|
632
|
+
options;
|
|
633
|
+
cursor = null;
|
|
634
|
+
constructor(sandbox, pid, options = {}) {
|
|
635
|
+
this.sandbox = sandbox;
|
|
636
|
+
this.pid = pid;
|
|
637
|
+
this.options = options;
|
|
638
|
+
}
|
|
639
|
+
async write(data) {
|
|
640
|
+
return this.sandbox.processes.write(this.pid, data);
|
|
641
|
+
}
|
|
642
|
+
async endInput() {
|
|
643
|
+
return this.sandbox.processes.endInput(this.pid);
|
|
644
|
+
}
|
|
645
|
+
async resize(size) {
|
|
646
|
+
return this.sandbox.processes.resize(this.pid, size);
|
|
647
|
+
}
|
|
648
|
+
async signal(signal) {
|
|
649
|
+
return this.sandbox.processes.signal(this.pid, signal);
|
|
650
|
+
}
|
|
651
|
+
async kill() {
|
|
652
|
+
return this.sandbox.processes.kill(this.pid);
|
|
653
|
+
}
|
|
654
|
+
async logs(options = {}) {
|
|
655
|
+
const result = await this.sandbox.processes.logs(this.pid, options);
|
|
656
|
+
this.cursor = result.cursor;
|
|
657
|
+
return result;
|
|
658
|
+
}
|
|
659
|
+
stream(options = {}) {
|
|
660
|
+
const attach = this;
|
|
661
|
+
const pollIntervalMs = boundedPollInterval(options.pollIntervalMs ?? this.options.pollIntervalMs);
|
|
662
|
+
const signal = options.signal ?? this.options.signal;
|
|
663
|
+
const initialLines = options.lines ?? this.options.lines;
|
|
664
|
+
const initialBytes = options.bytes ?? this.options.bytes;
|
|
665
|
+
return {
|
|
666
|
+
async *[Symbol.asyncIterator]() {
|
|
667
|
+
if (signal?.aborted)
|
|
668
|
+
return;
|
|
669
|
+
let cursor = attach.cursor;
|
|
670
|
+
if (cursor === null) {
|
|
671
|
+
const initial = await attach.logs({
|
|
672
|
+
...(initialBytes !== undefined ? { bytes: initialBytes } : {}),
|
|
673
|
+
...(initialBytes === undefined && initialLines !== undefined ? { lines: initialLines } : {}),
|
|
674
|
+
});
|
|
675
|
+
cursor = initial.cursor;
|
|
676
|
+
for (const chunk of initial.chunks)
|
|
677
|
+
yield chunk;
|
|
678
|
+
if (initial.exit || signal?.aborted)
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
while (!signal?.aborted) {
|
|
682
|
+
await sleep(pollIntervalMs, signal);
|
|
683
|
+
if (signal?.aborted)
|
|
684
|
+
return;
|
|
685
|
+
const next = await attach.logs({ cursor });
|
|
686
|
+
cursor = next.cursor;
|
|
687
|
+
for (const chunk of next.chunks)
|
|
688
|
+
yield chunk;
|
|
689
|
+
if (next.exit)
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
},
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
[Symbol.asyncIterator]() {
|
|
696
|
+
return this.stream()[Symbol.asyncIterator]();
|
|
697
|
+
}
|
|
372
698
|
}
|
|
373
699
|
function idComponent(value, field) {
|
|
374
700
|
const text = String(value);
|
|
@@ -391,6 +717,29 @@ function isIdComponent(value) {
|
|
|
391
717
|
}
|
|
392
718
|
return true;
|
|
393
719
|
}
|
|
720
|
+
function boundedPollInterval(value) {
|
|
721
|
+
if (!Number.isFinite(value))
|
|
722
|
+
return 100;
|
|
723
|
+
return Math.max(25, Math.min(5000, Math.floor(Number(value))));
|
|
724
|
+
}
|
|
725
|
+
function sleep(ms, signal) {
|
|
726
|
+
if (signal?.aborted)
|
|
727
|
+
return Promise.resolve();
|
|
728
|
+
return new Promise((resolve) => {
|
|
729
|
+
let done = false;
|
|
730
|
+
let timer;
|
|
731
|
+
const finish = () => {
|
|
732
|
+
if (done)
|
|
733
|
+
return;
|
|
734
|
+
done = true;
|
|
735
|
+
clearTimeout(timer);
|
|
736
|
+
signal?.removeEventListener('abort', finish);
|
|
737
|
+
resolve();
|
|
738
|
+
};
|
|
739
|
+
timer = setTimeout(finish, ms);
|
|
740
|
+
signal?.addEventListener('abort', finish, { once: true });
|
|
741
|
+
});
|
|
742
|
+
}
|
|
394
743
|
function isNimbusTarget(value) {
|
|
395
744
|
return !!value && typeof value === 'object' && 'kind' in value;
|
|
396
745
|
}
|
|
@@ -413,6 +762,22 @@ function trimTrailingSlashes(value) {
|
|
|
413
762
|
end--;
|
|
414
763
|
return value.slice(0, end);
|
|
415
764
|
}
|
|
765
|
+
function disposeSdkRpcResult(value) {
|
|
766
|
+
if ((typeof value !== 'object' && typeof value !== 'function') || value === null)
|
|
767
|
+
return;
|
|
768
|
+
const disposerKey = Symbol.dispose;
|
|
769
|
+
if (!disposerKey)
|
|
770
|
+
return;
|
|
771
|
+
const disposer = Reflect.get(value, disposerKey);
|
|
772
|
+
if (typeof disposer !== 'function')
|
|
773
|
+
return;
|
|
774
|
+
try {
|
|
775
|
+
Reflect.apply(disposer, value, []);
|
|
776
|
+
}
|
|
777
|
+
catch {
|
|
778
|
+
// Disposal only releases Worker RPC bookkeeping. Preserve SDK behavior.
|
|
779
|
+
}
|
|
780
|
+
}
|
|
416
781
|
async function resolveHeaders(input) {
|
|
417
782
|
if (!input)
|
|
418
783
|
return undefined;
|
|
@@ -451,12 +816,9 @@ function encodeWire(value) {
|
|
|
451
816
|
return value;
|
|
452
817
|
}
|
|
453
818
|
function decodeWire(value) {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
&& typeof value.base64 === 'string') {
|
|
458
|
-
return base64ToBytes(value.base64);
|
|
459
|
-
}
|
|
819
|
+
const bytes = WireBytesSchema.safeParse(value);
|
|
820
|
+
if (bytes.success)
|
|
821
|
+
return base64ToBytes(bytes.data.base64);
|
|
460
822
|
if (Array.isArray(value))
|
|
461
823
|
return value.map(decodeWire);
|
|
462
824
|
if (value && typeof value === 'object') {
|
package/dist/worker.d.ts
CHANGED
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
* should import through the SDK so the interactive app and programmatic
|
|
7
7
|
* sandbox APIs share one public package surface.
|
|
8
8
|
*/
|
|
9
|
-
export { NimbusSession, SupervisorRPC, NimbusAssetsRPC, NimbusLoaderRPC, NimbusLoadedWorker, NimbusLoadedEntrypoint, NimbusDurableObjectNamespace, NimbusDOStub, CirrusHmrRPC, base64Utf8, base64Url, base64UrlDecode, createNimbusHandler, decodeJsonBase64Url, encodeJsonBase64Url, generateSessionId, isValidSessionId, issueNimbusToken, pkceChallenge, randomBase64Url, sealJson, sha256Base64Url, unsealJson, verifyNimbusToken, NimbusAuthError, } from '@nimbus-sh/worker';
|
|
10
|
-
export type { NimbusHandler, NimbusHooks, NimbusHookContext, CustomRoutes, CreateNimbusHandlerOptions, NimbusRemoteApiConfig, NimbusRuntimePolicy, NimbusSandboxProfile, NimbusSdkConfig, NimbusSdkRouterConfig, AuthMode, NimbusAuthConfig, NimbusAuthEnv, NimbusTokenClaims, VerifiedNimbusToken, } from '@nimbus-sh/worker';
|
|
9
|
+
export { NimbusSession, SupervisorRPC, NimbusAssetsRPC, NimbusLoaderRPC, NimbusLoadedWorker, NimbusLoadedEntrypoint, NimbusDurableObjectNamespace, NimbusDOStub, CirrusHmrRPC, base64Utf8, base64Url, base64UrlDecode, clearNimbusAgentOAuthCookie, createNimbusHandler, createNimbusAgentOAuthCookie, decodeJsonBase64Url, encodeJsonBase64Url, fetchNimbusCloudflareAccounts, fetchNimbusCloudflareUserInfo, generateSessionId, isNimbusCloudflareAccountId, isNimbusTenantSegment, isPreviewHostRequest, isValidSessionId, issueNimbusToken, loadNimbusAgentOAuthFromRequest, nimbusAgentAuthCookiePath, nimbusAgentRouteContext, NIMBUS_AGENT_AUTH_COOKIE, NIMBUS_AGENT_AUTH_COOKIE_PURPOSE, NIMBUS_AGENT_AUTH_COOKIE_TTL_SECONDS, NIMBUS_CF_OAUTH_AUTH_URL, NIMBUS_CF_OAUTH_TOKEN_URL, NIMBUS_CF_OAUTH_USERINFO_URL, NIMBUS_CLOUDFLARE_API, pkceChallenge, randomBase64Url, readNimbusAgentCookieSecret, readNimbusCookie, requestNimbusCloudflareOAuthToken, sealJson, serializeNimbusCookie, sha256Base64Url, unsealJson, verifyNimbusToken, NimbusAuthError, } from '@nimbus-sh/worker';
|
|
10
|
+
export type { NimbusHandler, NimbusHooks, NimbusHookContext, CustomRoutes, CreateNimbusHandlerOptions, NimbusRemoteApiConfig, NimbusRuntimePolicy, NimbusSandboxProfile, NimbusSdkConfig, NimbusSdkRouterConfig, AuthMode, NimbusAuthConfig, NimbusAuthEnv, NimbusAgentOAuthCookie, NimbusCloudflareAccount, NimbusTokenClaims, VerifiedNimbusToken, } from '@nimbus-sh/worker';
|
|
11
11
|
//# sourceMappingURL=worker.d.ts.map
|
package/dist/worker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,aAAa,EACb,aAAa,EACb,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,sBAAsB,EACtB,4BAA4B,EAC5B,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,QAAQ,EACR,eAAe,EACf,UAAU,EACV,iBAAiB,EACjB,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,0BAA0B,EAC1B,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,qBAAqB,EACrB,QAAQ,EACR,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,aAAa,EACb,aAAa,EACb,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,sBAAsB,EACtB,4BAA4B,EAC5B,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,SAAS,EACT,eAAe,EACf,2BAA2B,EAC3B,mBAAmB,EACnB,4BAA4B,EAC5B,mBAAmB,EACnB,mBAAmB,EACnB,6BAA6B,EAC7B,6BAA6B,EAC7B,iBAAiB,EACjB,2BAA2B,EAC3B,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,+BAA+B,EAC/B,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,gCAAgC,EAChC,oCAAoC,EACpC,wBAAwB,EACxB,yBAAyB,EACzB,4BAA4B,EAC5B,qBAAqB,EACrB,aAAa,EACb,eAAe,EACf,2BAA2B,EAC3B,gBAAgB,EAChB,iCAAiC,EACjC,QAAQ,EACR,qBAAqB,EACrB,eAAe,EACf,UAAU,EACV,iBAAiB,EACjB,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,0BAA0B,EAC1B,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,qBAAqB,EACrB,QAAQ,EACR,gBAAgB,EAChB,aAAa,EACb,sBAAsB,EACtB,uBAAuB,EACvB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC"}
|
package/dist/worker.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
* should import through the SDK so the interactive app and programmatic
|
|
7
7
|
* sandbox APIs share one public package surface.
|
|
8
8
|
*/
|
|
9
|
-
export { NimbusSession, SupervisorRPC, NimbusAssetsRPC, NimbusLoaderRPC, NimbusLoadedWorker, NimbusLoadedEntrypoint, NimbusDurableObjectNamespace, NimbusDOStub, CirrusHmrRPC, base64Utf8, base64Url, base64UrlDecode, createNimbusHandler, decodeJsonBase64Url, encodeJsonBase64Url, generateSessionId, isValidSessionId, issueNimbusToken, pkceChallenge, randomBase64Url, sealJson, sha256Base64Url, unsealJson, verifyNimbusToken, NimbusAuthError, } from '@nimbus-sh/worker';
|
|
9
|
+
export { NimbusSession, SupervisorRPC, NimbusAssetsRPC, NimbusLoaderRPC, NimbusLoadedWorker, NimbusLoadedEntrypoint, NimbusDurableObjectNamespace, NimbusDOStub, CirrusHmrRPC, base64Utf8, base64Url, base64UrlDecode, clearNimbusAgentOAuthCookie, createNimbusHandler, createNimbusAgentOAuthCookie, decodeJsonBase64Url, encodeJsonBase64Url, fetchNimbusCloudflareAccounts, fetchNimbusCloudflareUserInfo, generateSessionId, isNimbusCloudflareAccountId, isNimbusTenantSegment, isPreviewHostRequest, isValidSessionId, issueNimbusToken, loadNimbusAgentOAuthFromRequest, nimbusAgentAuthCookiePath, nimbusAgentRouteContext, NIMBUS_AGENT_AUTH_COOKIE, NIMBUS_AGENT_AUTH_COOKIE_PURPOSE, NIMBUS_AGENT_AUTH_COOKIE_TTL_SECONDS, NIMBUS_CF_OAUTH_AUTH_URL, NIMBUS_CF_OAUTH_TOKEN_URL, NIMBUS_CF_OAUTH_USERINFO_URL, NIMBUS_CLOUDFLARE_API, pkceChallenge, randomBase64Url, readNimbusAgentCookieSecret, readNimbusCookie, requestNimbusCloudflareOAuthToken, sealJson, serializeNimbusCookie, sha256Base64Url, unsealJson, verifyNimbusToken, NimbusAuthError, } from '@nimbus-sh/worker';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nimbus-sh/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Nimbus SDK — Worker embedder, programmatic sandboxes, token mint, and client helpers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -72,14 +72,17 @@
|
|
|
72
72
|
"typecheck": "tsc --noEmit"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
|
-
"@nimbus-sh/worker": "^0.
|
|
75
|
+
"@nimbus-sh/worker": "^0.2.0"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@cloudflare/workers-types": "^4.20250327.0",
|
|
79
|
-
"@nimbus-sh/worker": "^0.
|
|
79
|
+
"@nimbus-sh/worker": "^0.2.0",
|
|
80
80
|
"typescript": "^5.7.0"
|
|
81
81
|
},
|
|
82
82
|
"publishConfig": {
|
|
83
83
|
"access": "public"
|
|
84
|
+
},
|
|
85
|
+
"dependencies": {
|
|
86
|
+
"zod": "^4.4.3"
|
|
84
87
|
}
|
|
85
88
|
}
|