-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocess.ts
More file actions
437 lines (384 loc) · 8.84 KB
/
process.ts
File metadata and controls
437 lines (384 loc) · 8.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../core/resource';
import { APIPromise } from '../../core/api-promise';
import { Stream } from '../../core/streaming';
import { buildHeaders } from '../../internal/headers';
import { RequestOptions } from '../../internal/request-options';
import { path } from '../../internal/utils/path';
/**
* Execute and manage processes on the browser instance.
*/
export class Process extends APIResource {
/**
* Execute a command synchronously
*
* @example
* ```ts
* const response = await client.browsers.process.exec('id', {
* command: 'command',
* });
* ```
*/
exec(id: string, body: ProcessExecParams, options?: RequestOptions): APIPromise<ProcessExecResponse> {
return this._client.post(path`/browsers/${id}/process/exec`, { body, ...options });
}
/**
* Send signal to process
*
* @example
* ```ts
* const response = await client.browsers.process.kill(
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
* { id: 'id', signal: 'TERM' },
* );
* ```
*/
kill(
processID: string,
params: ProcessKillParams,
options?: RequestOptions,
): APIPromise<ProcessKillResponse> {
const { id, ...body } = params;
return this._client.post(path`/browsers/${id}/process/${processID}/kill`, { body, ...options });
}
/**
* Resize a PTY-backed process terminal
*
* @example
* ```ts
* const response = await client.browsers.process.resize(
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
* {
* id: 'id',
* cols: 1,
* rows: 1,
* },
* );
* ```
*/
resize(
processID: string,
params: ProcessResizeParams,
options?: RequestOptions,
): APIPromise<ProcessResizeResponse> {
const { id, ...body } = params;
return this._client.post(path`/browsers/${id}/process/${processID}/resize`, { body, ...options });
}
/**
* Execute a command asynchronously
*
* @example
* ```ts
* const response = await client.browsers.process.spawn('id', {
* command: 'command',
* });
* ```
*/
spawn(id: string, body: ProcessSpawnParams, options?: RequestOptions): APIPromise<ProcessSpawnResponse> {
return this._client.post(path`/browsers/${id}/process/spawn`, { body, ...options });
}
/**
* Get process status
*
* @example
* ```ts
* const response = await client.browsers.process.status(
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
* { id: 'id' },
* );
* ```
*/
status(
processID: string,
params: ProcessStatusParams,
options?: RequestOptions,
): APIPromise<ProcessStatusResponse> {
const { id } = params;
return this._client.get(path`/browsers/${id}/process/${processID}/status`, options);
}
/**
* Write to process stdin
*
* @example
* ```ts
* const response = await client.browsers.process.stdin(
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
* { id: 'id', data_b64: 'data_b64' },
* );
* ```
*/
stdin(
processID: string,
params: ProcessStdinParams,
options?: RequestOptions,
): APIPromise<ProcessStdinResponse> {
const { id, ...body } = params;
return this._client.post(path`/browsers/${id}/process/${processID}/stdin`, { body, ...options });
}
/**
* Stream process stdout via SSE
*
* @example
* ```ts
* const response = await client.browsers.process.stdoutStream(
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
* { id: 'id' },
* );
* ```
*/
stdoutStream(
processID: string,
params: ProcessStdoutStreamParams,
options?: RequestOptions,
): APIPromise<Stream<ProcessStdoutStreamResponse>> {
const { id } = params;
return this._client.get(path`/browsers/${id}/process/${processID}/stdout/stream`, {
...options,
headers: buildHeaders([{ Accept: 'text/event-stream' }, options?.headers]),
stream: true,
}) as APIPromise<Stream<ProcessStdoutStreamResponse>>;
}
}
/**
* Result of a synchronous command execution.
*/
export interface ProcessExecResponse {
/**
* Execution duration in milliseconds.
*/
duration_ms?: number;
/**
* Process exit code.
*/
exit_code?: number;
/**
* Base64-encoded stderr buffer.
*/
stderr_b64?: string;
/**
* Base64-encoded stdout buffer.
*/
stdout_b64?: string;
}
/**
* Generic OK response.
*/
export interface ProcessKillResponse {
/**
* Indicates success.
*/
ok: boolean;
}
/**
* Generic OK response.
*/
export interface ProcessResizeResponse {
/**
* Indicates success.
*/
ok: boolean;
}
/**
* Information about a spawned process.
*/
export interface ProcessSpawnResponse {
/**
* OS process ID.
*/
pid?: number;
/**
* Server-assigned identifier for the process.
*/
process_id?: string;
/**
* Timestamp when the process started.
*/
started_at?: string;
}
/**
* Current status of a process.
*/
export interface ProcessStatusResponse {
/**
* Estimated CPU usage percentage.
*/
cpu_pct?: number;
/**
* Exit code if the process has exited.
*/
exit_code?: number | null;
/**
* Estimated resident memory usage in bytes.
*/
mem_bytes?: number;
/**
* Process state.
*/
state?: 'running' | 'exited';
}
/**
* Result of writing to stdin.
*/
export interface ProcessStdinResponse {
/**
* Number of bytes written.
*/
written_bytes?: number;
}
/**
* SSE payload representing process output or lifecycle events.
*/
export interface ProcessStdoutStreamResponse {
/**
* Base64-encoded data from the process stream.
*/
data_b64?: string;
/**
* Lifecycle event type.
*/
event?: 'exit';
/**
* Exit code when the event is "exit".
*/
exit_code?: number;
/**
* Source stream of the data chunk.
*/
stream?: 'stdout' | 'stderr';
}
export interface ProcessExecParams {
/**
* Executable or shell command to run.
*/
command: string;
/**
* Command arguments.
*/
args?: Array<string>;
/**
* Run the process with root privileges.
*/
as_root?: boolean;
/**
* Run the process as this user.
*/
as_user?: string | null;
/**
* Working directory (absolute path) to run the command in.
*/
cwd?: string | null;
/**
* Environment variables to set for the process.
*/
env?: { [key: string]: string };
/**
* Maximum execution time in seconds.
*/
timeout_sec?: number | null;
}
export interface ProcessKillParams {
/**
* Path param: Browser session ID
*/
id: string;
/**
* Body param: Signal to send.
*/
signal: 'TERM' | 'KILL' | 'INT' | 'HUP';
}
export interface ProcessResizeParams {
/**
* Path param: Browser session ID
*/
id: string;
/**
* Body param: New terminal columns.
*/
cols: number;
/**
* Body param: New terminal rows.
*/
rows: number;
}
export interface ProcessSpawnParams {
/**
* Executable or shell command to run.
*/
command: string;
/**
* Allocate a pseudo-terminal (PTY) for interactive shells.
*/
allocate_tty?: boolean;
/**
* Command arguments.
*/
args?: Array<string>;
/**
* Run the process with root privileges.
*/
as_root?: boolean;
/**
* Run the process as this user.
*/
as_user?: string | null;
/**
* Initial terminal columns. Only used when allocate_tty is true.
*/
cols?: number;
/**
* Working directory (absolute path) to run the command in.
*/
cwd?: string | null;
/**
* Environment variables to set for the process.
*/
env?: { [key: string]: string };
/**
* Initial terminal rows. Only used when allocate_tty is true.
*/
rows?: number;
/**
* Maximum execution time in seconds.
*/
timeout_sec?: number | null;
}
export interface ProcessStatusParams {
/**
* Browser session ID
*/
id: string;
}
export interface ProcessStdinParams {
/**
* Path param: Browser session ID
*/
id: string;
/**
* Body param: Base64-encoded data to write.
*/
data_b64: string;
}
export interface ProcessStdoutStreamParams {
/**
* Browser session ID
*/
id: string;
}
export declare namespace Process {
export {
type ProcessExecResponse as ProcessExecResponse,
type ProcessKillResponse as ProcessKillResponse,
type ProcessResizeResponse as ProcessResizeResponse,
type ProcessSpawnResponse as ProcessSpawnResponse,
type ProcessStatusResponse as ProcessStatusResponse,
type ProcessStdinResponse as ProcessStdinResponse,
type ProcessStdoutStreamResponse as ProcessStdoutStreamResponse,
type ProcessExecParams as ProcessExecParams,
type ProcessKillParams as ProcessKillParams,
type ProcessResizeParams as ProcessResizeParams,
type ProcessSpawnParams as ProcessSpawnParams,
type ProcessStatusParams as ProcessStatusParams,
type ProcessStdinParams as ProcessStdinParams,
type ProcessStdoutStreamParams as ProcessStdoutStreamParams,
};
}