Skip to content

Commit 0cceb4e

Browse files
feat(api): new process, fs, and log endpoints
New endpoints for executing processes on browser instances, uploading / downloading whole directories as zip files, and streaming any log file on a browser instance
1 parent b0aabec commit 0cceb4e

File tree

11 files changed

+850
-4
lines changed

11 files changed

+850
-4
lines changed

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 31
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-b55c3e0424fa7733487139488b9fff00ad8949ff02ee3160ee36b9334e84b134.yml
3-
openapi_spec_hash: 17f36677e3dc0a3aeb419654c8d5cae3
4-
config_hash: f67e4b33b2fb30c1405ee2fff8096320
1+
configured_endpoints: 41
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-a7c1df5070fe59642d7a1f168aa902a468227752bfc930cbf38930f7c205dbb6.yml
3+
openapi_spec_hash: eab65e39aef4f0a0952b82adeecf6b5b
4+
config_hash: 5de78bc29ac060562575cb54bb26826c

api.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,14 @@ Methods:
9797
- <code title="put /browsers/{id}/fs/create_directory">client.browsers.fs.<a href="./src/resources/browsers/fs/fs.ts">createDirectory</a>(id, { ...params }) -> void</code>
9898
- <code title="put /browsers/{id}/fs/delete_directory">client.browsers.fs.<a href="./src/resources/browsers/fs/fs.ts">deleteDirectory</a>(id, { ...params }) -> void</code>
9999
- <code title="put /browsers/{id}/fs/delete_file">client.browsers.fs.<a href="./src/resources/browsers/fs/fs.ts">deleteFile</a>(id, { ...params }) -> void</code>
100+
- <code title="get /browsers/{id}/fs/download_dir_zip">client.browsers.fs.<a href="./src/resources/browsers/fs/fs.ts">downloadDirZip</a>(id, { ...params }) -> Response</code>
100101
- <code title="get /browsers/{id}/fs/file_info">client.browsers.fs.<a href="./src/resources/browsers/fs/fs.ts">fileInfo</a>(id, { ...params }) -> FFileInfoResponse</code>
101102
- <code title="get /browsers/{id}/fs/list_files">client.browsers.fs.<a href="./src/resources/browsers/fs/fs.ts">listFiles</a>(id, { ...params }) -> FListFilesResponse</code>
102103
- <code title="put /browsers/{id}/fs/move">client.browsers.fs.<a href="./src/resources/browsers/fs/fs.ts">move</a>(id, { ...params }) -> void</code>
103104
- <code title="get /browsers/{id}/fs/read_file">client.browsers.fs.<a href="./src/resources/browsers/fs/fs.ts">readFile</a>(id, { ...params }) -> Response</code>
104105
- <code title="put /browsers/{id}/fs/set_file_permissions">client.browsers.fs.<a href="./src/resources/browsers/fs/fs.ts">setFilePermissions</a>(id, { ...params }) -> void</code>
106+
- <code title="post /browsers/{id}/fs/upload">client.browsers.fs.<a href="./src/resources/browsers/fs/fs.ts">upload</a>(id, { ...params }) -> void</code>
107+
- <code title="post /browsers/{id}/fs/upload_zip">client.browsers.fs.<a href="./src/resources/browsers/fs/fs.ts">uploadZip</a>(id, { ...params }) -> void</code>
105108
- <code title="put /browsers/{id}/fs/write_file">client.browsers.fs.<a href="./src/resources/browsers/fs/fs.ts">writeFile</a>(id, contents, { ...params }) -> void</code>
106109

107110
### Watch
@@ -116,3 +119,29 @@ Methods:
116119
- <code title="get /browsers/{id}/fs/watch/{watch_id}/events">client.browsers.fs.watch.<a href="./src/resources/browsers/fs/watch.ts">events</a>(watchID, { ...params }) -> WatchEventsResponse</code>
117120
- <code title="post /browsers/{id}/fs/watch">client.browsers.fs.watch.<a href="./src/resources/browsers/fs/watch.ts">start</a>(id, { ...params }) -> WatchStartResponse</code>
118121
- <code title="delete /browsers/{id}/fs/watch/{watch_id}">client.browsers.fs.watch.<a href="./src/resources/browsers/fs/watch.ts">stop</a>(watchID, { ...params }) -> void</code>
122+
123+
## Process
124+
125+
Types:
126+
127+
- <code><a href="./src/resources/browsers/process.ts">ProcessExecResponse</a></code>
128+
- <code><a href="./src/resources/browsers/process.ts">ProcessKillResponse</a></code>
129+
- <code><a href="./src/resources/browsers/process.ts">ProcessSpawnResponse</a></code>
130+
- <code><a href="./src/resources/browsers/process.ts">ProcessStatusResponse</a></code>
131+
- <code><a href="./src/resources/browsers/process.ts">ProcessStdinResponse</a></code>
132+
- <code><a href="./src/resources/browsers/process.ts">ProcessStdoutStreamResponse</a></code>
133+
134+
Methods:
135+
136+
- <code title="post /browsers/{id}/process/exec">client.browsers.process.<a href="./src/resources/browsers/process.ts">exec</a>(id, { ...params }) -> ProcessExecResponse</code>
137+
- <code title="post /browsers/{id}/process/{process_id}/kill">client.browsers.process.<a href="./src/resources/browsers/process.ts">kill</a>(processID, { ...params }) -> ProcessKillResponse</code>
138+
- <code title="post /browsers/{id}/process/spawn">client.browsers.process.<a href="./src/resources/browsers/process.ts">spawn</a>(id, { ...params }) -> ProcessSpawnResponse</code>
139+
- <code title="get /browsers/{id}/process/{process_id}/status">client.browsers.process.<a href="./src/resources/browsers/process.ts">status</a>(processID, { ...params }) -> ProcessStatusResponse</code>
140+
- <code title="post /browsers/{id}/process/{process_id}/stdin">client.browsers.process.<a href="./src/resources/browsers/process.ts">stdin</a>(processID, { ...params }) -> ProcessStdinResponse</code>
141+
- <code title="get /browsers/{id}/process/{process_id}/stdout/stream">client.browsers.process.<a href="./src/resources/browsers/process.ts">stdoutStream</a>(processID, { ...params }) -> ProcessStdoutStreamResponse</code>
142+
143+
## Logs
144+
145+
Methods:
146+
147+
- <code title="get /browsers/{id}/logs/stream">client.browsers.logs.<a href="./src/resources/browsers/logs.ts">stream</a>(id, { ...params }) -> LogEvent</code>

src/resources/browsers/browsers.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
import { APIResource } from '../../core/resource';
44
import * as BrowsersAPI from './browsers';
5+
import * as LogsAPI from './logs';
6+
import { LogStreamParams, Logs } from './logs';
7+
import * as ProcessAPI from './process';
8+
import {
9+
Process,
10+
ProcessExecParams,
11+
ProcessExecResponse,
12+
ProcessKillParams,
13+
ProcessKillResponse,
14+
ProcessSpawnParams,
15+
ProcessSpawnResponse,
16+
ProcessStatusParams,
17+
ProcessStatusResponse,
18+
ProcessStdinParams,
19+
ProcessStdinResponse,
20+
ProcessStdoutStreamParams,
21+
ProcessStdoutStreamResponse,
22+
} from './process';
523
import * as ReplaysAPI from './replays';
624
import {
725
ReplayDownloadParams,
@@ -16,13 +34,16 @@ import {
1634
FCreateDirectoryParams,
1735
FDeleteDirectoryParams,
1836
FDeleteFileParams,
37+
FDownloadDirZipParams,
1938
FFileInfoParams,
2039
FFileInfoResponse,
2140
FListFilesParams,
2241
FListFilesResponse,
2342
FMoveParams,
2443
FReadFileParams,
2544
FSetFilePermissionsParams,
45+
FUploadParams,
46+
FUploadZipParams,
2647
FWriteFileParams,
2748
Fs,
2849
} from './fs/fs';
@@ -34,6 +55,8 @@ import { path } from '../../internal/utils/path';
3455
export class Browsers extends APIResource {
3556
replays: ReplaysAPI.Replays = new ReplaysAPI.Replays(this._client);
3657
fs: FsAPI.Fs = new FsAPI.Fs(this._client);
58+
process: ProcessAPI.Process = new ProcessAPI.Process(this._client);
59+
logs: LogsAPI.Logs = new LogsAPI.Logs(this._client);
3760

3861
/**
3962
* Create a new browser session from within an action.
@@ -296,6 +319,8 @@ export interface BrowserDeleteParams {
296319

297320
Browsers.Replays = Replays;
298321
Browsers.Fs = Fs;
322+
Browsers.Process = Process;
323+
Browsers.Logs = Logs;
299324

300325
export declare namespace Browsers {
301326
export {
@@ -323,11 +348,32 @@ export declare namespace Browsers {
323348
type FCreateDirectoryParams as FCreateDirectoryParams,
324349
type FDeleteDirectoryParams as FDeleteDirectoryParams,
325350
type FDeleteFileParams as FDeleteFileParams,
351+
type FDownloadDirZipParams as FDownloadDirZipParams,
326352
type FFileInfoParams as FFileInfoParams,
327353
type FListFilesParams as FListFilesParams,
328354
type FMoveParams as FMoveParams,
329355
type FReadFileParams as FReadFileParams,
330356
type FSetFilePermissionsParams as FSetFilePermissionsParams,
357+
type FUploadParams as FUploadParams,
358+
type FUploadZipParams as FUploadZipParams,
331359
type FWriteFileParams as FWriteFileParams,
332360
};
361+
362+
export {
363+
Process as Process,
364+
type ProcessExecResponse as ProcessExecResponse,
365+
type ProcessKillResponse as ProcessKillResponse,
366+
type ProcessSpawnResponse as ProcessSpawnResponse,
367+
type ProcessStatusResponse as ProcessStatusResponse,
368+
type ProcessStdinResponse as ProcessStdinResponse,
369+
type ProcessStdoutStreamResponse as ProcessStdoutStreamResponse,
370+
type ProcessExecParams as ProcessExecParams,
371+
type ProcessKillParams as ProcessKillParams,
372+
type ProcessSpawnParams as ProcessSpawnParams,
373+
type ProcessStatusParams as ProcessStatusParams,
374+
type ProcessStdinParams as ProcessStdinParams,
375+
type ProcessStdoutStreamParams as ProcessStdoutStreamParams,
376+
};
377+
378+
export { Logs as Logs, type LogStreamParams as LogStreamParams };
333379
}

src/resources/browsers/fs/fs.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import {
1111
WatchStopParams,
1212
} from './watch';
1313
import { APIPromise } from '../../../core/api-promise';
14+
import { type Uploadable } from '../../../core/uploads';
1415
import { buildHeaders } from '../../../internal/headers';
1516
import { RequestOptions } from '../../../internal/request-options';
17+
import { multipartFormRequestOptions } from '../../../internal/uploads';
1618
import { path } from '../../../internal/utils/path';
1719

1820
export class Fs extends APIResource {
@@ -70,6 +72,29 @@ export class Fs extends APIResource {
7072
});
7173
}
7274

75+
/**
76+
* Returns a ZIP file containing the contents of the specified directory.
77+
*
78+
* @example
79+
* ```ts
80+
* const response = await client.browsers.fs.downloadDirZip(
81+
* 'id',
82+
* { path: '/J!' },
83+
* );
84+
*
85+
* const content = await response.blob();
86+
* console.log(content);
87+
* ```
88+
*/
89+
downloadDirZip(id: string, query: FDownloadDirZipParams, options?: RequestOptions): APIPromise<Response> {
90+
return this._client.get(path`/browsers/${id}/fs/download_dir_zip`, {
91+
query,
92+
...options,
93+
headers: buildHeaders([{ Accept: 'application/zip' }, options?.headers]),
94+
__binaryResponse: true,
95+
});
96+
}
97+
7398
/**
7499
* Get information about a file or directory
75100
*
@@ -162,6 +187,52 @@ export class Fs extends APIResource {
162187
});
163188
}
164189

190+
/**
191+
* Allows uploading single or multiple files to the remote filesystem.
192+
*
193+
* @example
194+
* ```ts
195+
* await client.browsers.fs.upload('id', {
196+
* files: [
197+
* {
198+
* dest_path: '/J!',
199+
* file: fs.createReadStream('path/to/file'),
200+
* },
201+
* ],
202+
* });
203+
* ```
204+
*/
205+
upload(id: string, body: FUploadParams, options?: RequestOptions): APIPromise<void> {
206+
return this._client.post(
207+
path`/browsers/${id}/fs/upload`,
208+
multipartFormRequestOptions(
209+
{ body, ...options, headers: buildHeaders([{ Accept: '*/*' }, options?.headers]) },
210+
this._client,
211+
),
212+
);
213+
}
214+
215+
/**
216+
* Upload a zip file and extract its contents to the specified destination path.
217+
*
218+
* @example
219+
* ```ts
220+
* await client.browsers.fs.uploadZip('id', {
221+
* dest_path: '/J!',
222+
* zip_file: fs.createReadStream('path/to/file'),
223+
* });
224+
* ```
225+
*/
226+
uploadZip(id: string, body: FUploadZipParams, options?: RequestOptions): APIPromise<void> {
227+
return this._client.post(
228+
path`/browsers/${id}/fs/upload_zip`,
229+
multipartFormRequestOptions(
230+
{ body, ...options, headers: buildHeaders([{ Accept: '*/*' }, options?.headers]) },
231+
this._client,
232+
),
233+
);
234+
}
235+
165236
/**
166237
* Write or create a file
167238
*
@@ -290,6 +361,13 @@ export interface FDeleteFileParams {
290361
path: string;
291362
}
292363

364+
export interface FDownloadDirZipParams {
365+
/**
366+
* Absolute directory path to archive and download.
367+
*/
368+
path: string;
369+
}
370+
293371
export interface FFileInfoParams {
294372
/**
295373
* Absolute path of the file or directory.
@@ -345,6 +423,30 @@ export interface FSetFilePermissionsParams {
345423
owner?: string;
346424
}
347425

426+
export interface FUploadParams {
427+
files: Array<FUploadParams.File>;
428+
}
429+
430+
export namespace FUploadParams {
431+
export interface File {
432+
/**
433+
* Absolute destination path to write the file.
434+
*/
435+
dest_path: string;
436+
437+
file: Uploadable;
438+
}
439+
}
440+
441+
export interface FUploadZipParams {
442+
/**
443+
* Absolute destination directory to extract the archive to.
444+
*/
445+
dest_path: string;
446+
447+
zip_file: Uploadable;
448+
}
449+
348450
export interface FWriteFileParams {
349451
/**
350452
* Query param: Destination absolute file path.
@@ -366,11 +468,14 @@ export declare namespace Fs {
366468
type FCreateDirectoryParams as FCreateDirectoryParams,
367469
type FDeleteDirectoryParams as FDeleteDirectoryParams,
368470
type FDeleteFileParams as FDeleteFileParams,
471+
type FDownloadDirZipParams as FDownloadDirZipParams,
369472
type FFileInfoParams as FFileInfoParams,
370473
type FListFilesParams as FListFilesParams,
371474
type FMoveParams as FMoveParams,
372475
type FReadFileParams as FReadFileParams,
373476
type FSetFilePermissionsParams as FSetFilePermissionsParams,
477+
type FUploadParams as FUploadParams,
478+
type FUploadZipParams as FUploadZipParams,
374479
type FWriteFileParams as FWriteFileParams,
375480
};
376481

src/resources/browsers/fs/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ export {
77
type FCreateDirectoryParams,
88
type FDeleteDirectoryParams,
99
type FDeleteFileParams,
10+
type FDownloadDirZipParams,
1011
type FFileInfoParams,
1112
type FListFilesParams,
1213
type FMoveParams,
1314
type FReadFileParams,
1415
type FSetFilePermissionsParams,
16+
type FUploadParams,
17+
type FUploadZipParams,
1518
type FWriteFileParams,
1619
} from './fs';
1720
export {

src/resources/browsers/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,32 @@ export {
1616
type FCreateDirectoryParams,
1717
type FDeleteDirectoryParams,
1818
type FDeleteFileParams,
19+
type FDownloadDirZipParams,
1920
type FFileInfoParams,
2021
type FListFilesParams,
2122
type FMoveParams,
2223
type FReadFileParams,
2324
type FSetFilePermissionsParams,
25+
type FUploadParams,
26+
type FUploadZipParams,
2427
type FWriteFileParams,
2528
} from './fs/index';
29+
export { Logs, type LogStreamParams } from './logs';
30+
export {
31+
Process,
32+
type ProcessExecResponse,
33+
type ProcessKillResponse,
34+
type ProcessSpawnResponse,
35+
type ProcessStatusResponse,
36+
type ProcessStdinResponse,
37+
type ProcessStdoutStreamResponse,
38+
type ProcessExecParams,
39+
type ProcessKillParams,
40+
type ProcessSpawnParams,
41+
type ProcessStatusParams,
42+
type ProcessStdinParams,
43+
type ProcessStdoutStreamParams,
44+
} from './process';
2645
export {
2746
Replays,
2847
type ReplayListResponse,

src/resources/browsers/logs.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import { APIResource } from '../../core/resource';
4+
import * as Shared from '../shared';
5+
import { APIPromise } from '../../core/api-promise';
6+
import { Stream } from '../../core/streaming';
7+
import { buildHeaders } from '../../internal/headers';
8+
import { RequestOptions } from '../../internal/request-options';
9+
import { path } from '../../internal/utils/path';
10+
11+
export class Logs extends APIResource {
12+
/**
13+
* Stream log files on the browser instance via SSE
14+
*
15+
* @example
16+
* ```ts
17+
* const logEvent = await client.browsers.logs.stream('id', {
18+
* source: 'path',
19+
* });
20+
* ```
21+
*/
22+
stream(id: string, query: LogStreamParams, options?: RequestOptions): APIPromise<Stream<Shared.LogEvent>> {
23+
return this._client.get(path`/browsers/${id}/logs/stream`, {
24+
query,
25+
...options,
26+
headers: buildHeaders([{ Accept: 'text/event-stream' }, options?.headers]),
27+
stream: true,
28+
}) as APIPromise<Stream<Shared.LogEvent>>;
29+
}
30+
}
31+
32+
export interface LogStreamParams {
33+
source: 'path' | 'supervisor';
34+
35+
follow?: boolean;
36+
37+
/**
38+
* only required if source is path
39+
*/
40+
path?: string;
41+
42+
/**
43+
* only required if source is supervisor
44+
*/
45+
supervisor_process?: string;
46+
}
47+
48+
export declare namespace Logs {
49+
export { type LogStreamParams as LogStreamParams };
50+
}

0 commit comments

Comments
 (0)