Skip to content

Commit b18e46d

Browse files
feat: add WebSocket process attach and PTY support
1 parent b9715f8 commit b18e46d

File tree

6 files changed

+108
-4
lines changed

6 files changed

+108
-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: 89
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-8e4a29d23d2882fcb0864606091790fd58bffa4f5d5c8d081052b72ad47b215b.yml
3-
openapi_spec_hash: fc82d930dad739ac01e3c2bddba7bf61
4-
config_hash: d0585c44724cd7deecea60a5ffae69df
1+
configured_endpoints: 90
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-6a44c851ec955b997558a8524eb641355ff3097474f40772b8ea2fef5bee4134.yml
3+
openapi_spec_hash: 155ee005a1b43e1c11e843de91e9f509
4+
config_hash: 6cbbf855a29bc675f35ddb1106ea9083

api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ Types:
133133

134134
- <code><a href="./src/resources/browsers/process.ts">ProcessExecResponse</a></code>
135135
- <code><a href="./src/resources/browsers/process.ts">ProcessKillResponse</a></code>
136+
- <code><a href="./src/resources/browsers/process.ts">ProcessResizeResponse</a></code>
136137
- <code><a href="./src/resources/browsers/process.ts">ProcessSpawnResponse</a></code>
137138
- <code><a href="./src/resources/browsers/process.ts">ProcessStatusResponse</a></code>
138139
- <code><a href="./src/resources/browsers/process.ts">ProcessStdinResponse</a></code>
@@ -142,6 +143,7 @@ Methods:
142143

143144
- <code title="post /browsers/{id}/process/exec">client.browsers.process.<a href="./src/resources/browsers/process.ts">exec</a>(id, { ...params }) -> ProcessExecResponse</code>
144145
- <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>
146+
- <code title="post /browsers/{id}/process/{process_id}/resize">client.browsers.process.<a href="./src/resources/browsers/process.ts">resize</a>(processID, { ...params }) -> ProcessResizeResponse</code>
145147
- <code title="post /browsers/{id}/process/spawn">client.browsers.process.<a href="./src/resources/browsers/process.ts">spawn</a>(id, { ...params }) -> ProcessSpawnResponse</code>
146148
- <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>
147149
- <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>

src/resources/browsers/browsers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {
2626
ProcessExecResponse,
2727
ProcessKillParams,
2828
ProcessKillResponse,
29+
ProcessResizeParams,
30+
ProcessResizeResponse,
2931
ProcessSpawnParams,
3032
ProcessSpawnResponse,
3133
ProcessStatusParams,
@@ -615,12 +617,14 @@ export declare namespace Browsers {
615617
Process as Process,
616618
type ProcessExecResponse as ProcessExecResponse,
617619
type ProcessKillResponse as ProcessKillResponse,
620+
type ProcessResizeResponse as ProcessResizeResponse,
618621
type ProcessSpawnResponse as ProcessSpawnResponse,
619622
type ProcessStatusResponse as ProcessStatusResponse,
620623
type ProcessStdinResponse as ProcessStdinResponse,
621624
type ProcessStdoutStreamResponse as ProcessStdoutStreamResponse,
622625
type ProcessExecParams as ProcessExecParams,
623626
type ProcessKillParams as ProcessKillParams,
627+
type ProcessResizeParams as ProcessResizeParams,
624628
type ProcessSpawnParams as ProcessSpawnParams,
625629
type ProcessStatusParams as ProcessStatusParams,
626630
type ProcessStdinParams as ProcessStdinParams,

src/resources/browsers/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ export {
4848
Process,
4949
type ProcessExecResponse,
5050
type ProcessKillResponse,
51+
type ProcessResizeResponse,
5152
type ProcessSpawnResponse,
5253
type ProcessStatusResponse,
5354
type ProcessStdinResponse,
5455
type ProcessStdoutStreamResponse,
5556
type ProcessExecParams,
5657
type ProcessKillParams,
58+
type ProcessResizeParams,
5759
type ProcessSpawnParams,
5860
type ProcessStatusParams,
5961
type ProcessStdinParams,

src/resources/browsers/process.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,30 @@ export class Process extends APIResource {
4242
return this._client.post(path`/browsers/${id}/process/${processID}/kill`, { body, ...options });
4343
}
4444

45+
/**
46+
* Resize a PTY-backed process terminal
47+
*
48+
* @example
49+
* ```ts
50+
* const response = await client.browsers.process.resize(
51+
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
52+
* {
53+
* id: 'id',
54+
* cols: 1,
55+
* rows: 1,
56+
* },
57+
* );
58+
* ```
59+
*/
60+
resize(
61+
processID: string,
62+
params: ProcessResizeParams,
63+
options?: RequestOptions,
64+
): APIPromise<ProcessResizeResponse> {
65+
const { id, ...body } = params;
66+
return this._client.post(path`/browsers/${id}/process/${processID}/resize`, { body, ...options });
67+
}
68+
4569
/**
4670
* Execute a command asynchronously
4771
*
@@ -156,6 +180,16 @@ export interface ProcessKillResponse {
156180
ok: boolean;
157181
}
158182

183+
/**
184+
* Generic OK response.
185+
*/
186+
export interface ProcessResizeResponse {
187+
/**
188+
* Indicates success.
189+
*/
190+
ok: boolean;
191+
}
192+
159193
/**
160194
* Information about a spawned process.
161195
*/
@@ -285,12 +319,34 @@ export interface ProcessKillParams {
285319
signal: 'TERM' | 'KILL' | 'INT' | 'HUP';
286320
}
287321

322+
export interface ProcessResizeParams {
323+
/**
324+
* Path param: Browser session ID
325+
*/
326+
id: string;
327+
328+
/**
329+
* Body param: New terminal columns.
330+
*/
331+
cols: number;
332+
333+
/**
334+
* Body param: New terminal rows.
335+
*/
336+
rows: number;
337+
}
338+
288339
export interface ProcessSpawnParams {
289340
/**
290341
* Executable or shell command to run.
291342
*/
292343
command: string;
293344

345+
/**
346+
* Allocate a pseudo-terminal (PTY) for interactive shells.
347+
*/
348+
allocate_tty?: boolean;
349+
294350
/**
295351
* Command arguments.
296352
*/
@@ -306,6 +362,11 @@ export interface ProcessSpawnParams {
306362
*/
307363
as_user?: string | null;
308364

365+
/**
366+
* Initial terminal columns. Only used when allocate_tty is true.
367+
*/
368+
cols?: number;
369+
309370
/**
310371
* Working directory (absolute path) to run the command in.
311372
*/
@@ -316,6 +377,11 @@ export interface ProcessSpawnParams {
316377
*/
317378
env?: { [key: string]: string };
318379

380+
/**
381+
* Initial terminal rows. Only used when allocate_tty is true.
382+
*/
383+
rows?: number;
384+
319385
/**
320386
* Maximum execution time in seconds.
321387
*/
@@ -352,12 +418,14 @@ export declare namespace Process {
352418
export {
353419
type ProcessExecResponse as ProcessExecResponse,
354420
type ProcessKillResponse as ProcessKillResponse,
421+
type ProcessResizeResponse as ProcessResizeResponse,
355422
type ProcessSpawnResponse as ProcessSpawnResponse,
356423
type ProcessStatusResponse as ProcessStatusResponse,
357424
type ProcessStdinResponse as ProcessStdinResponse,
358425
type ProcessStdoutStreamResponse as ProcessStdoutStreamResponse,
359426
type ProcessExecParams as ProcessExecParams,
360427
type ProcessKillParams as ProcessKillParams,
428+
type ProcessResizeParams as ProcessResizeParams,
361429
type ProcessSpawnParams as ProcessSpawnParams,
362430
type ProcessStatusParams as ProcessStatusParams,
363431
type ProcessStdinParams as ProcessStdinParams,

tests/api-resources/browsers/process.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,31 @@ describe('resource process', () => {
5656
});
5757
});
5858

59+
// Prism tests are disabled
60+
test.skip('resize: only required params', async () => {
61+
const responsePromise = client.browsers.process.resize('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
62+
id: 'id',
63+
cols: 1,
64+
rows: 1,
65+
});
66+
const rawResponse = await responsePromise.asResponse();
67+
expect(rawResponse).toBeInstanceOf(Response);
68+
const response = await responsePromise;
69+
expect(response).not.toBeInstanceOf(Response);
70+
const dataAndResponse = await responsePromise.withResponse();
71+
expect(dataAndResponse.data).toBe(response);
72+
expect(dataAndResponse.response).toBe(rawResponse);
73+
});
74+
75+
// Prism tests are disabled
76+
test.skip('resize: required and optional params', async () => {
77+
const response = await client.browsers.process.resize('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
78+
id: 'id',
79+
cols: 1,
80+
rows: 1,
81+
});
82+
});
83+
5984
// Prism tests are disabled
6085
test.skip('spawn: only required params', async () => {
6186
const responsePromise = client.browsers.process.spawn('id', { command: 'command' });
@@ -72,11 +97,14 @@ describe('resource process', () => {
7297
test.skip('spawn: required and optional params', async () => {
7398
const response = await client.browsers.process.spawn('id', {
7499
command: 'command',
100+
allocate_tty: true,
75101
args: ['string'],
76102
as_root: true,
77103
as_user: 'as_user',
104+
cols: 1,
78105
cwd: '/J!',
79106
env: { foo: 'string' },
107+
rows: 1,
80108
timeout_sec: 0,
81109
});
82110
});

0 commit comments

Comments
 (0)