@watasu/sdk 0.1.25 → 0.1.40

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/dist/process.js CHANGED
@@ -67,10 +67,10 @@ export class Process {
67
67
  async kill() {
68
68
  await this.handle.kill();
69
69
  }
70
- async wait(timeout) {
70
+ async wait(timeoutMs) {
71
71
  if (!this.waitPromise)
72
72
  this.waitPromise = this.waitOnce();
73
- return waitFor(this.waitPromise, timeout);
73
+ return waitFor(this.waitPromise, timeoutMs);
74
74
  }
75
75
  async waitOnce() {
76
76
  try {
@@ -126,7 +126,7 @@ export class ProcessManager {
126
126
  }
127
127
  async startAndWait(cmdOrOpts) {
128
128
  const process = await this.start(cmdOrOpts);
129
- return process.wait(typeof cmdOrOpts === 'string' ? undefined : cmdOrOpts.timeout);
129
+ return process.wait(typeof cmdOrOpts === 'string' ? undefined : cmdOrOpts.timeoutMs);
130
130
  }
131
131
  }
132
132
  function processOpts(cmdOrOpts) {
@@ -5,12 +5,13 @@ export declare class ProcessSocket implements AsyncIterable<ProcessFrame> {
5
5
  private readonly token;
6
6
  private readonly path;
7
7
  private readonly requestTimeoutMs;
8
+ private readonly headers;
8
9
  private ws?;
9
10
  private queue;
10
11
  private waiters;
11
12
  private closed;
12
13
  private keepalive?;
13
- constructor(baseUrl: string, token: string, path: string, requestTimeoutMs?: number);
14
+ constructor(baseUrl: string, token: string, path: string, requestTimeoutMs?: number, headers?: Record<string, string>);
14
15
  connect(): Promise<this>;
15
16
  sendJson(payload: ProcessFrame): void;
16
17
  sendStdin(data: string | Uint8Array): void;
@@ -8,20 +8,22 @@ export class ProcessSocket {
8
8
  token;
9
9
  path;
10
10
  requestTimeoutMs;
11
+ headers;
11
12
  ws;
12
13
  queue = [];
13
14
  waiters = [];
14
15
  closed = false;
15
16
  keepalive;
16
- constructor(baseUrl, token, path, requestTimeoutMs = 60_000) {
17
+ constructor(baseUrl, token, path, requestTimeoutMs = 60_000, headers = {}) {
17
18
  this.baseUrl = baseUrl;
18
19
  this.token = token;
19
20
  this.path = path;
20
21
  this.requestTimeoutMs = requestTimeoutMs;
22
+ this.headers = headers;
21
23
  }
22
24
  async connect() {
23
25
  const ws = new WebSocket(wsUrl(this.baseUrl, this.path), {
24
- headers: { Authorization: `Bearer ${this.token}` },
26
+ headers: { ...this.headers, Authorization: `Bearer ${this.token}` },
25
27
  });
26
28
  this.ws = ws;
27
29
  ws.on('message', (data) => this.onMessage(data));
package/dist/pty.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CommandHandle, CommandStartOpts } from './commands.js';
2
- import { ConnectionConfig } from './connectionConfig.js';
2
+ import { ConnectionConfig, type ConnectionOpts } from './connectionConfig.js';
3
3
  import { DataPlaneClient } from './transport.js';
4
4
  export interface PtySize {
5
5
  cols: number;
@@ -28,10 +28,10 @@ export declare class Pty {
28
28
  connect(pid: number | string, opts?: PtyConnectOpts): Promise<CommandHandle>;
29
29
  /** Send input bytes or text to a PTY. */
30
30
  sendStdin(pid: number | string, data: string | Uint8Array, opts?: PtyConnectOpts): Promise<void>;
31
- /** Alias for `sendStdin`. */
31
+ /** Send input bytes or text to a PTY. */
32
32
  sendInput(pid: number | string, data: string | Uint8Array, opts?: PtyConnectOpts): Promise<void>;
33
33
  /** Resize a running PTY. */
34
34
  resize(pid: number | string, size: PtySize, opts?: PtyConnectOpts): Promise<void>;
35
35
  /** Kill a running PTY. */
36
- kill(pid: number | string): Promise<boolean>;
36
+ kill(pid: number | string, opts?: Pick<ConnectionOpts, 'requestTimeoutMs' | 'signal'>): Promise<boolean>;
37
37
  }
package/dist/pty.js CHANGED
@@ -11,21 +11,21 @@ export class Pty {
11
11
  }
12
12
  /** Create an interactive shell PTY and return its live command handle. */
13
13
  async create(opts) {
14
- const socket = await new ProcessSocket(this.dataPlane.baseUrl, this.dataPlane.token, '/runtime/v1/process', opts.requestTimeoutMs ?? this.config.requestTimeoutMs).connect();
15
- const envs = { TERM: 'xterm-256color', LANG: 'C.UTF-8', LC_ALL: 'C.UTF-8', ...(opts.envVars ?? opts.envs ?? {}) };
14
+ const socket = await new ProcessSocket(this.dataPlane.baseUrl, this.dataPlane.token, '/runtime/v1/process', opts.requestTimeoutMs ?? this.config.requestTimeoutMs, this.config.headers).connect();
15
+ const envs = { TERM: 'xterm-256color', LANG: 'C.UTF-8', LC_ALL: 'C.UTF-8', ...(opts.envs ?? {}) };
16
16
  const size = opts.size ?? { cols: opts.cols ?? 80, rows: opts.rows ?? 24 };
17
17
  const args = opts.cmd === undefined ? ['-i', '-l'] : ['-l', '-c', opts.cmd];
18
18
  socket.sendJson({
19
19
  type: 'start',
20
20
  cmd: '/bin/bash',
21
21
  args,
22
- cwd: opts.cwd ?? opts.rootDir,
22
+ cwd: opts.cwd,
23
23
  user: opts.user,
24
24
  environment: envs,
25
25
  envs,
26
26
  stdin: true,
27
27
  pty: { cols: size.cols, rows: size.rows },
28
- timeout_ms: opts.timeoutMs ?? opts.timeout ?? 60_000,
28
+ timeout_ms: opts.timeoutMs ?? 60_000,
29
29
  });
30
30
  const first = await nextStarted(socket);
31
31
  const pid = framePid(first);
@@ -35,7 +35,7 @@ export class Pty {
35
35
  }
36
36
  /** Connect to a running PTY by pid. */
37
37
  async connect(pid, opts = {}) {
38
- const socket = await new ProcessSocket(this.dataPlane.baseUrl, this.dataPlane.token, `/runtime/v1/process/${pid}/connect?since=0`, opts.requestTimeoutMs ?? this.config.requestTimeoutMs).connect();
38
+ const socket = await new ProcessSocket(this.dataPlane.baseUrl, this.dataPlane.token, `/runtime/v1/process/${pid}/connect?since=0`, opts.requestTimeoutMs ?? this.config.requestTimeoutMs, this.config.headers).connect();
39
39
  const first = await nextStarted(socket);
40
40
  const actualPid = framePid(first) ?? pid;
41
41
  return new CommandHandle(actualPid, socket, () => this.kill(actualPid), withFirst(first, socket), undefined, undefined, opts.onData);
@@ -50,7 +50,7 @@ export class Pty {
50
50
  await handle.disconnect();
51
51
  }
52
52
  }
53
- /** Alias for `sendStdin`. */
53
+ /** Send input bytes or text to a PTY. */
54
54
  async sendInput(pid, data, opts = {}) {
55
55
  return this.sendStdin(pid, data, opts);
56
56
  }
@@ -65,9 +65,11 @@ export class Pty {
65
65
  }
66
66
  }
67
67
  /** Kill a running PTY. */
68
- async kill(pid) {
68
+ async kill(pid, opts = {}) {
69
69
  await this.dataPlane.postJson(`/runtime/v1/process/${pid}/signal`, {
70
70
  json: { signal: 'SIGKILL' },
71
+ requestTimeoutMs: opts.requestTimeoutMs,
72
+ signal: opts.signal,
71
73
  });
72
74
  return true;
73
75
  }
package/dist/sandbox.d.ts CHANGED
@@ -6,6 +6,7 @@ import { Git } from './git.js';
6
6
  import { Pty } from './pty.js';
7
7
  import { ProcessManager } from './process.js';
8
8
  import { TerminalManager } from './terminal.js';
9
+ import type { Volume } from './volume.js';
9
10
  export interface SandboxCreateOpts extends ConnectionOpts {
10
11
  /** Template slug to create. Defaults to "base". */
11
12
  template?: string;
@@ -19,7 +20,16 @@ export interface SandboxCreateOpts extends ConnectionOpts {
19
20
  team?: string;
20
21
  /** MCP gateway configuration to launch inside an `mcp-gateway` sandbox. */
21
22
  mcp?: McpServer;
22
- volumeMounts?: unknown;
23
+ /** Timeout lifecycle policy. Defaults to killing the sandbox at timeout. */
24
+ lifecycle?: SandboxLifecycle;
25
+ /** Persistent volumes to mount, keyed by guest path. */
26
+ volumeMounts?: Record<string, string | Volume | {
27
+ name: string;
28
+ }>;
29
+ }
30
+ export interface SandboxLifecycle {
31
+ onTimeout: 'kill' | 'pause';
32
+ autoResume?: boolean;
23
33
  }
24
34
  export type SandboxNetworkSelector = string | string[];
25
35
  export interface SandboxNetworkUpdate {
@@ -53,15 +63,25 @@ export interface SandboxListOpts extends ConnectionOpts {
53
63
  /** Team slug to list within. */
54
64
  team?: string;
55
65
  }
66
+ type SandboxRequestOpts = Pick<ConnectionOpts, 'requestTimeoutMs' | 'signal'>;
56
67
  export interface SandboxInfo {
57
68
  sandboxId: string;
58
69
  templateId?: string;
59
70
  name?: string;
60
71
  state?: string;
72
+ lifecycle?: SandboxInfoLifecycle;
73
+ volumeMounts?: Array<{
74
+ name: string;
75
+ path: string;
76
+ }>;
61
77
  metadata: Record<string, string>;
62
78
  startedAt?: string;
63
79
  endAt?: string;
64
80
  }
81
+ export interface SandboxInfoLifecycle {
82
+ onTimeout: 'kill' | 'pause' | string;
83
+ autoResume: boolean;
84
+ }
65
85
  export interface SandboxMetrics {
66
86
  sandboxId?: string;
67
87
  state?: string;
@@ -71,6 +91,12 @@ export interface SandboxMetrics {
71
91
  memoryMb?: number;
72
92
  raw: Record<string, unknown>;
73
93
  }
94
+ export interface SandboxMetricsOpts extends ConnectionOpts {
95
+ /** Start time for the metrics. Defaults to the sandbox start time. */
96
+ start?: Date;
97
+ /** End time for the metrics. Defaults to the current time. */
98
+ end?: Date;
99
+ }
74
100
  export interface SnapshotInfo {
75
101
  snapshotId: string;
76
102
  sandboxId?: string;
@@ -114,7 +140,6 @@ export interface SnapshotListOpts extends ConnectionOpts {
114
140
  export interface RestoreSnapshotOpts extends ConnectionOpts {
115
141
  checkpointId?: string | number;
116
142
  snapshotId?: string | number;
117
- timeout?: number;
118
143
  timeoutMs?: number;
119
144
  }
120
145
  /** Paginator for listing sandbox snapshots. */
@@ -148,14 +173,12 @@ export declare class Sandbox {
148
173
  /** Default sandbox lifetime in milliseconds. */
149
174
  static readonly defaultSandboxTimeoutMs = 300000;
150
175
  files: Filesystem;
151
- filesystem: Filesystem;
152
176
  commands: Commands;
153
177
  process: ProcessManager;
154
178
  pty: Pty;
155
179
  terminal: TerminalManager;
156
180
  git: Git;
157
181
  cwd: string | undefined;
158
- envVars: Record<string, string>;
159
182
  readonly sandboxId: string;
160
183
  private readonly mcpPort;
161
184
  private mcpToken;
@@ -178,28 +201,21 @@ export declare class Sandbox {
178
201
  static create(template: string, opts?: SandboxCreateOpts): Promise<Sandbox>;
179
202
  /** Connect to an existing sandbox and return it with a fresh data-plane session. */
180
203
  static connect(sandboxId: string, opts?: SandboxConnectOpts): Promise<Sandbox>;
181
- /** Alias for `connect`. */
182
- static reconnect(sandboxId: string, opts?: SandboxConnectOpts): Promise<Sandbox>;
183
- static reconnect(opts: SandboxConnectOpts & {
184
- sandboxID: string;
185
- }): Promise<Sandbox>;
186
204
  /** Refresh this sandbox's data-plane session in place. */
187
205
  connect(opts?: SandboxConnectOpts): Promise<this>;
188
206
  /** Resume a paused sandbox by id. */
189
207
  static resume(sandboxId: string, opts?: SandboxConnectOpts): Promise<boolean>;
190
208
  /** Pause a sandbox by id. Returns false when it was already paused. */
191
209
  static betaPause(sandboxId: string, opts?: ConnectionOpts): Promise<boolean>;
192
- /** Alias for `betaPause`. */
210
+ /** Pause a sandbox by id. */
193
211
  static pause(sandboxId: string, opts?: ConnectionOpts): Promise<boolean>;
194
212
  /** Destroy a sandbox by id. */
195
213
  static kill(sandboxId: string, opts?: ConnectionOpts | string): Promise<boolean>;
196
214
  /** Fetch sandbox metrics by id. */
197
- static getMetrics(sandboxId: string, opts?: ConnectionOpts): Promise<SandboxMetrics[]>;
215
+ static getMetrics(sandboxId: string, opts?: SandboxMetricsOpts): Promise<SandboxMetrics[]>;
198
216
  /** Atomically replace a sandbox's network egress policy by id. */
199
217
  static updateNetwork(sandboxId: string, network: SandboxNetworkUpdate, opts?: SandboxNetworkUpdateOpts): Promise<void>;
200
218
  private static putNetwork;
201
- /** Deprecated alias for `getInfo`. */
202
- static getFullInfo(sandboxId: string, opts?: ConnectionOpts): Promise<SandboxInfo>;
203
219
  /** Create a Watasu checkpoint using snapshot naming. */
204
220
  static createSnapshot(sandboxId: string, opts?: CreateSnapshotOpts): Promise<SnapshotInfo>;
205
221
  /** List snapshots visible to the configured API key. */
@@ -207,21 +223,19 @@ export declare class Sandbox {
207
223
  /** Delete a snapshot by id. Returns `false` when the snapshot does not exist. */
208
224
  static deleteSnapshot(snapshotId: string, opts?: ConnectionOpts): Promise<boolean>;
209
225
  /** Destroy this sandbox. */
210
- kill(): Promise<boolean>;
226
+ kill(opts?: SandboxRequestOpts): Promise<boolean>;
211
227
  /** Check if this sandbox is in a runtime-active lifecycle state. */
212
- isRunning(opts?: Pick<ConnectionOpts, 'requestTimeoutMs'>): Promise<boolean>;
228
+ isRunning(opts?: SandboxRequestOpts): Promise<boolean>;
213
229
  /** Set a sandbox's lifetime by id. */
214
230
  static setTimeout(sandboxId: string, timeoutMs: number, opts?: ConnectionOpts): Promise<void>;
215
231
  /** Set this sandbox's lifetime. */
216
- setTimeout(timeoutMs: number): Promise<void>;
217
- /** Keep the sandbox alive for `duration` milliseconds. */
218
- keepAlive(duration: number): Promise<void>;
232
+ setTimeout(timeoutMs: number, opts?: SandboxRequestOpts): Promise<void>;
219
233
  /** Fetch control-plane metadata for a sandbox by id. */
220
234
  static getInfo(sandboxId: string, opts?: ConnectionOpts): Promise<SandboxInfo>;
221
235
  /** Fetch the latest control-plane metadata for this sandbox. */
222
- getInfo(): Promise<SandboxInfo>;
236
+ getInfo(opts?: SandboxRequestOpts): Promise<SandboxInfo>;
223
237
  /** Fetch latest sandbox metrics. */
224
- getMetrics(opts?: ConnectionOpts): Promise<SandboxMetrics[]>;
238
+ getMetrics(opts?: SandboxMetricsOpts): Promise<SandboxMetrics[]>;
225
239
  /** Create a Watasu checkpoint using snapshot naming. */
226
240
  createSnapshot(opts?: CreateSnapshotOpts): Promise<SnapshotInfo>;
227
241
  /** Delete a snapshot by id. */
@@ -236,16 +250,10 @@ export declare class Sandbox {
236
250
  static list(opts?: SandboxListOpts | string): SandboxPaginator;
237
251
  /** Return the public hostname for an exposed sandbox port. */
238
252
  getHost(port: number): string;
239
- /** Return the public hostname for the sandbox or an exposed sandbox port. */
240
- getHostname(port?: number): string;
241
253
  /** Return the conventional MCP URL for this sandbox. */
242
254
  getMcpUrl(): string;
243
255
  /** Return the MCP gateway token when the sandbox contains one. */
244
256
  getMcpToken(): Promise<string | undefined>;
245
- /** Return a protocol string for a secure or insecure sandbox URL. */
246
- getProtocol(baseProtocol?: string, secure?: boolean): string;
247
- /** Close the local SDK attachment. This does not destroy the sandbox. */
248
- close(): Promise<void>;
249
257
  /** Get a signed URL that accepts a POST upload for a sandbox file path. */
250
258
  uploadUrl(path?: string, opts?: SandboxUrlOpts): Promise<string>;
251
259
  /** Get a signed URL that accepts a GET download for a sandbox file path. */
@@ -258,12 +266,17 @@ export declare class Sandbox {
258
266
  updateNetwork(network: SandboxNetworkUpdate, opts?: SandboxNetworkUpdateOpts): Promise<void>;
259
267
  /** Pause this sandbox. Returns false when it was already paused. */
260
268
  betaPause(opts?: ConnectionOpts): Promise<boolean>;
261
- /** Alias for `betaPause`. */
269
+ /** Pause this sandbox. Returns false when it was already paused. */
262
270
  pause(opts?: ConnectionOpts): Promise<boolean>;
263
271
  /** Resume this sandbox and refresh its data-plane session. */
264
272
  resume(opts?: SandboxConnectOpts): Promise<boolean>;
265
273
  private fileUrl;
266
274
  /** POST JSON to the sandbox data-plane runtime API. */
267
275
  protected runtimePostJson(path: string, json: Record<string, unknown>, opts?: ConnectionOpts): Promise<Record<string, unknown>>;
276
+ /** GET JSON from the sandbox data-plane runtime API. */
277
+ protected runtimeGetJson(path: string, opts?: ConnectionOpts): Promise<Record<string, unknown>>;
278
+ /** DELETE JSON from the sandbox data-plane runtime API. */
279
+ protected runtimeDeleteJson(path: string, opts?: ConnectionOpts): Promise<Record<string, unknown>>;
268
280
  private configOptions;
269
281
  }
282
+ export {};