sandbox0 0.2.4 → 0.2.5
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 +15 -0
- package/dist/apispec/src/apis/ContextsApi.d.ts +2 -2
- package/dist/apispec/src/apis/ContextsApi.js +2 -2
- package/dist/apispec/src/models/AddTeamMemberRequest.d.ts +1 -0
- package/dist/apispec/src/models/AddTeamMemberRequest.d.ts.map +1 -1
- package/dist/apispec/src/models/AddTeamMemberRequest.js +1 -0
- package/dist/apispec/src/models/ContextWebSocketDone.d.ts +14 -2
- package/dist/apispec/src/models/ContextWebSocketDone.d.ts.map +1 -1
- package/dist/apispec/src/models/ContextWebSocketDone.js +5 -3
- package/dist/apispec/src/models/ContextWebSocketOutput.d.ts +1 -1
- package/dist/apispec/src/models/ContextWebSocketOutput.js +1 -1
- package/dist/apispec/src/models/UpdateTeamMemberRequest.d.ts +1 -0
- package/dist/apispec/src/models/UpdateTeamMemberRequest.d.ts.map +1 -1
- package/dist/apispec/src/models/UpdateTeamMemberRequest.js +1 -0
- package/dist/models.d.ts +7 -0
- package/dist/models.d.ts.map +1 -1
- package/dist/sandbox.d.ts +12 -1
- package/dist/sandbox.d.ts.map +1 -1
- package/dist/sandbox.js +95 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,6 +49,21 @@ async function main() {
|
|
|
49
49
|
main().catch(console.error);
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
+
## CMD Streaming
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
const stream = await sandbox.cmdStream("sh -c 'echo hello && echo warn >&2'", {
|
|
56
|
+
command: ["sh", "-c", "echo hello && echo warn >&2"],
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
for await (const output of stream.outputs()) {
|
|
60
|
+
process.stdout.write(output.data);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const done = await stream.wait();
|
|
64
|
+
console.log(`exit=${done.exitCode} state=${done.state}`);
|
|
65
|
+
```
|
|
66
|
+
|
|
52
67
|
## Documentation
|
|
53
68
|
|
|
54
69
|
- [Sandbox0 docs](https://sandbox0.ai/docs)
|
|
@@ -129,12 +129,12 @@ export declare class ContextsApi extends runtime.BaseAPI {
|
|
|
129
129
|
*/
|
|
130
130
|
apiV1SandboxesIdContextsCtxIdStatsGet(requestParameters: ApiV1SandboxesIdContextsCtxIdStatsGetRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<SuccessContextStatsResponse>;
|
|
131
131
|
/**
|
|
132
|
-
* Upgrades to WebSocket for streaming I/O. Client messages (JSON): - { \"type\": \"input\", \"data\": \"ls\\n\", \"request_id\": \"req-1\" } - { \"type\": \"resize\", \"rows\": 24, \"cols\": 80 } - { \"type\": \"signal\", \"signal\": \"INT\" } Server messages (JSON): - { \"type\": \"output\", \"source\": \"stdout\", \"data\": \"hello\\n\" }
|
|
132
|
+
* Upgrades to WebSocket for streaming I/O. Client messages (JSON): - { \"type\": \"input\", \"data\": \"ls\\n\", \"request_id\": \"req-1\" } - { \"type\": \"resize\", \"rows\": 24, \"cols\": 80 } - { \"type\": \"signal\", \"signal\": \"INT\" } Server messages (JSON): - { \"type\": \"output\", \"source\": \"stdout\", \"data\": \"hello\\n\" } - { \"type\": \"done\", \"request_id\": \"req-1\" } - { \"type\": \"done\", \"exit_code\": 0, \"state\": \"stopped\" }
|
|
133
133
|
* Context WebSocket (I/O)
|
|
134
134
|
*/
|
|
135
135
|
apiV1SandboxesIdContextsCtxIdWsGetRaw(requestParameters: ApiV1SandboxesIdContextsCtxIdWsGetRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>>;
|
|
136
136
|
/**
|
|
137
|
-
* Upgrades to WebSocket for streaming I/O. Client messages (JSON): - { \"type\": \"input\", \"data\": \"ls\\n\", \"request_id\": \"req-1\" } - { \"type\": \"resize\", \"rows\": 24, \"cols\": 80 } - { \"type\": \"signal\", \"signal\": \"INT\" } Server messages (JSON): - { \"type\": \"output\", \"source\": \"stdout\", \"data\": \"hello\\n\" }
|
|
137
|
+
* Upgrades to WebSocket for streaming I/O. Client messages (JSON): - { \"type\": \"input\", \"data\": \"ls\\n\", \"request_id\": \"req-1\" } - { \"type\": \"resize\", \"rows\": 24, \"cols\": 80 } - { \"type\": \"signal\", \"signal\": \"INT\" } Server messages (JSON): - { \"type\": \"output\", \"source\": \"stdout\", \"data\": \"hello\\n\" } - { \"type\": \"done\", \"request_id\": \"req-1\" } - { \"type\": \"done\", \"exit_code\": 0, \"state\": \"stopped\" }
|
|
138
138
|
* Context WebSocket (I/O)
|
|
139
139
|
*/
|
|
140
140
|
apiV1SandboxesIdContextsCtxIdWsGet(requestParameters: ApiV1SandboxesIdContextsCtxIdWsGetRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void>;
|
|
@@ -336,7 +336,7 @@ export class ContextsApi extends runtime.BaseAPI {
|
|
|
336
336
|
return await response.value();
|
|
337
337
|
}
|
|
338
338
|
/**
|
|
339
|
-
* Upgrades to WebSocket for streaming I/O. Client messages (JSON): - { \"type\": \"input\", \"data\": \"ls\\n\", \"request_id\": \"req-1\" } - { \"type\": \"resize\", \"rows\": 24, \"cols\": 80 } - { \"type\": \"signal\", \"signal\": \"INT\" } Server messages (JSON): - { \"type\": \"output\", \"source\": \"stdout\", \"data\": \"hello\\n\" }
|
|
339
|
+
* Upgrades to WebSocket for streaming I/O. Client messages (JSON): - { \"type\": \"input\", \"data\": \"ls\\n\", \"request_id\": \"req-1\" } - { \"type\": \"resize\", \"rows\": 24, \"cols\": 80 } - { \"type\": \"signal\", \"signal\": \"INT\" } Server messages (JSON): - { \"type\": \"output\", \"source\": \"stdout\", \"data\": \"hello\\n\" } - { \"type\": \"done\", \"request_id\": \"req-1\" } - { \"type\": \"done\", \"exit_code\": 0, \"state\": \"stopped\" }
|
|
340
340
|
* Context WebSocket (I/O)
|
|
341
341
|
*/
|
|
342
342
|
async apiV1SandboxesIdContextsCtxIdWsGetRaw(requestParameters, initOverrides) {
|
|
@@ -367,7 +367,7 @@ export class ContextsApi extends runtime.BaseAPI {
|
|
|
367
367
|
return new runtime.VoidApiResponse(response);
|
|
368
368
|
}
|
|
369
369
|
/**
|
|
370
|
-
* Upgrades to WebSocket for streaming I/O. Client messages (JSON): - { \"type\": \"input\", \"data\": \"ls\\n\", \"request_id\": \"req-1\" } - { \"type\": \"resize\", \"rows\": 24, \"cols\": 80 } - { \"type\": \"signal\", \"signal\": \"INT\" } Server messages (JSON): - { \"type\": \"output\", \"source\": \"stdout\", \"data\": \"hello\\n\" }
|
|
370
|
+
* Upgrades to WebSocket for streaming I/O. Client messages (JSON): - { \"type\": \"input\", \"data\": \"ls\\n\", \"request_id\": \"req-1\" } - { \"type\": \"resize\", \"rows\": 24, \"cols\": 80 } - { \"type\": \"signal\", \"signal\": \"INT\" } Server messages (JSON): - { \"type\": \"output\", \"source\": \"stdout\", \"data\": \"hello\\n\" } - { \"type\": \"done\", \"request_id\": \"req-1\" } - { \"type\": \"done\", \"exit_code\": 0, \"state\": \"stopped\" }
|
|
371
371
|
* Context WebSocket (I/O)
|
|
372
372
|
*/
|
|
373
373
|
async apiV1SandboxesIdContextsCtxIdWsGet(requestParameters, initOverrides) {
|
|
@@ -34,6 +34,7 @@ export interface AddTeamMemberRequest {
|
|
|
34
34
|
export declare const AddTeamMemberRequestRoleEnum: {
|
|
35
35
|
readonly Admin: "admin";
|
|
36
36
|
readonly Developer: "developer";
|
|
37
|
+
readonly Builder: "builder";
|
|
37
38
|
readonly Viewer: "viewer";
|
|
38
39
|
};
|
|
39
40
|
export type AddTeamMemberRequestRoleEnum = typeof AddTeamMemberRequestRoleEnum[keyof typeof AddTeamMemberRequestRoleEnum];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AddTeamMemberRequest.d.ts","sourceRoot":"","sources":["../../../../src/apispec/src/models/AddTeamMemberRequest.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAGH;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACjC;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,IAAI,EAAE,4BAA4B,CAAC;CACtC;AAGD;;GAEG;AACH,eAAO,MAAM,4BAA4B
|
|
1
|
+
{"version":3,"file":"AddTeamMemberRequest.d.ts","sourceRoot":"","sources":["../../../../src/apispec/src/models/AddTeamMemberRequest.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAGH;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACjC;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,IAAI,EAAE,4BAA4B,CAAC;CACtC;AAGD;;GAEG;AACH,eAAO,MAAM,4BAA4B;;;;;CAK/B,CAAC;AACX,MAAM,MAAM,4BAA4B,GAAG,OAAO,4BAA4B,CAAC,MAAM,OAAO,4BAA4B,CAAC,CAAC;AAG1H;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,oBAAoB,CAI3F;AAED,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,GAAG,GAAG,oBAAoB,CAE5E;AAED,wBAAgB,iCAAiC,CAAC,IAAI,EAAE,GAAG,EAAE,mBAAmB,EAAE,OAAO,GAAG,oBAAoB,CAS/G;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,GAAG,GAAG,oBAAoB,CAE1E;AAED,wBAAgB,+BAA+B,CAAC,KAAK,CAAC,EAAE,oBAAoB,GAAG,IAAI,EAAE,mBAAmB,GAAE,OAAe,GAAG,GAAG,CAU9H"}
|
|
@@ -22,11 +22,23 @@ export interface ContextWebSocketDone {
|
|
|
22
22
|
*/
|
|
23
23
|
type: ContextWebSocketDoneTypeEnum;
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
25
|
+
* Present for request-scoped REPL completion events.
|
|
26
|
+
* @type {string}
|
|
27
|
+
* @memberof ContextWebSocketDone
|
|
28
|
+
*/
|
|
29
|
+
requestId?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Present when the underlying process has exited.
|
|
32
|
+
* @type {number}
|
|
33
|
+
* @memberof ContextWebSocketDone
|
|
34
|
+
*/
|
|
35
|
+
exitCode?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Final process state when the underlying process has exited.
|
|
26
38
|
* @type {string}
|
|
27
39
|
* @memberof ContextWebSocketDone
|
|
28
40
|
*/
|
|
29
|
-
|
|
41
|
+
state?: string;
|
|
30
42
|
}
|
|
31
43
|
/**
|
|
32
44
|
* @export
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextWebSocketDone.d.ts","sourceRoot":"","sources":["../../../../src/apispec/src/models/ContextWebSocketDone.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAGH;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACjC;;;;OAIG;IACH,IAAI,EAAE,4BAA4B,CAAC;IACnC;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"ContextWebSocketDone.d.ts","sourceRoot":"","sources":["../../../../src/apispec/src/models/ContextWebSocketDone.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAGH;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACjC;;;;OAIG;IACH,IAAI,EAAE,4BAA4B,CAAC;IACnC;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAGD;;GAEG;AACH,eAAO,MAAM,4BAA4B;;CAE/B,CAAC;AACX,MAAM,MAAM,4BAA4B,GAAG,OAAO,4BAA4B,CAAC,MAAM,OAAO,4BAA4B,CAAC,CAAC;AAG1H;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,oBAAoB,CAG3F;AAED,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,GAAG,GAAG,oBAAoB,CAE5E;AAED,wBAAgB,iCAAiC,CAAC,IAAI,EAAE,GAAG,EAAE,mBAAmB,EAAE,OAAO,GAAG,oBAAoB,CAW/G;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,GAAG,GAAG,oBAAoB,CAE1E;AAED,wBAAgB,+BAA+B,CAAC,KAAK,CAAC,EAAE,oBAAoB,GAAG,IAAI,EAAE,mBAAmB,GAAE,OAAe,GAAG,GAAG,CAY9H"}
|
|
@@ -23,8 +23,6 @@ export const ContextWebSocketDoneTypeEnum = {
|
|
|
23
23
|
export function instanceOfContextWebSocketDone(value) {
|
|
24
24
|
if (!('type' in value) || value['type'] === undefined)
|
|
25
25
|
return false;
|
|
26
|
-
if (!('requestId' in value) || value['requestId'] === undefined)
|
|
27
|
-
return false;
|
|
28
26
|
return true;
|
|
29
27
|
}
|
|
30
28
|
export function ContextWebSocketDoneFromJSON(json) {
|
|
@@ -36,7 +34,9 @@ export function ContextWebSocketDoneFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
36
34
|
}
|
|
37
35
|
return {
|
|
38
36
|
'type': json['type'],
|
|
39
|
-
'requestId': json['request_id'],
|
|
37
|
+
'requestId': json['request_id'] == null ? undefined : json['request_id'],
|
|
38
|
+
'exitCode': json['exit_code'] == null ? undefined : json['exit_code'],
|
|
39
|
+
'state': json['state'] == null ? undefined : json['state'],
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
export function ContextWebSocketDoneToJSON(json) {
|
|
@@ -49,5 +49,7 @@ export function ContextWebSocketDoneToJSONTyped(value, ignoreDiscriminator = fal
|
|
|
49
49
|
return {
|
|
50
50
|
'type': value['type'],
|
|
51
51
|
'request_id': value['requestId'],
|
|
52
|
+
'exit_code': value['exitCode'],
|
|
53
|
+
'state': value['state'],
|
|
52
54
|
};
|
|
53
55
|
}
|
|
@@ -47,7 +47,7 @@ export type ContextWebSocketOutputTypeEnum = typeof ContextWebSocketOutputTypeEn
|
|
|
47
47
|
export declare const ContextWebSocketOutputSourceEnum: {
|
|
48
48
|
readonly Stdout: "stdout";
|
|
49
49
|
readonly Stderr: "stderr";
|
|
50
|
-
readonly
|
|
50
|
+
readonly Pty: "pty";
|
|
51
51
|
};
|
|
52
52
|
export type ContextWebSocketOutputSourceEnum = typeof ContextWebSocketOutputSourceEnum[keyof typeof ContextWebSocketOutputSourceEnum];
|
|
53
53
|
/**
|
|
@@ -23,7 +23,7 @@ export const ContextWebSocketOutputTypeEnum = {
|
|
|
23
23
|
export const ContextWebSocketOutputSourceEnum = {
|
|
24
24
|
Stdout: 'stdout',
|
|
25
25
|
Stderr: 'stderr',
|
|
26
|
-
|
|
26
|
+
Pty: 'pty'
|
|
27
27
|
};
|
|
28
28
|
/**
|
|
29
29
|
* Check if a given object implements the ContextWebSocketOutput interface.
|
|
@@ -28,6 +28,7 @@ export interface UpdateTeamMemberRequest {
|
|
|
28
28
|
export declare const UpdateTeamMemberRequestRoleEnum: {
|
|
29
29
|
readonly Admin: "admin";
|
|
30
30
|
readonly Developer: "developer";
|
|
31
|
+
readonly Builder: "builder";
|
|
31
32
|
readonly Viewer: "viewer";
|
|
32
33
|
};
|
|
33
34
|
export type UpdateTeamMemberRequestRoleEnum = typeof UpdateTeamMemberRequestRoleEnum[keyof typeof UpdateTeamMemberRequestRoleEnum];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UpdateTeamMemberRequest.d.ts","sourceRoot":"","sources":["../../../../src/apispec/src/models/UpdateTeamMemberRequest.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAGH;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACpC;;;;OAIG;IACH,IAAI,EAAE,+BAA+B,CAAC;CACzC;AAGD;;GAEG;AACH,eAAO,MAAM,+BAA+B
|
|
1
|
+
{"version":3,"file":"UpdateTeamMemberRequest.d.ts","sourceRoot":"","sources":["../../../../src/apispec/src/models/UpdateTeamMemberRequest.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAGH;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACpC;;;;OAIG;IACH,IAAI,EAAE,+BAA+B,CAAC;CACzC;AAGD;;GAEG;AACH,eAAO,MAAM,+BAA+B;;;;;CAKlC,CAAC;AACX,MAAM,MAAM,+BAA+B,GAAG,OAAO,+BAA+B,CAAC,MAAM,OAAO,+BAA+B,CAAC,CAAC;AAGnI;;GAEG;AACH,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,uBAAuB,CAGjG;AAED,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,GAAG,GAAG,uBAAuB,CAElF;AAED,wBAAgB,oCAAoC,CAAC,IAAI,EAAE,GAAG,EAAE,mBAAmB,EAAE,OAAO,GAAG,uBAAuB,CAQrH;AAED,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,GAAG,GAAG,uBAAuB,CAEhF;AAED,wBAAgB,kCAAkC,CAAC,KAAK,CAAC,EAAE,uBAAuB,GAAG,IAAI,EAAE,mBAAmB,GAAE,OAAe,GAAG,GAAG,CASpI"}
|
package/dist/models.d.ts
CHANGED
|
@@ -23,6 +23,13 @@ export interface StreamOutput {
|
|
|
23
23
|
source: string;
|
|
24
24
|
data: string;
|
|
25
25
|
}
|
|
26
|
+
export interface StreamDone {
|
|
27
|
+
sandboxId: string;
|
|
28
|
+
contextId: string;
|
|
29
|
+
requestId?: string;
|
|
30
|
+
exitCode?: number;
|
|
31
|
+
state?: string;
|
|
32
|
+
}
|
|
26
33
|
export interface ExposedPort {
|
|
27
34
|
port: number;
|
|
28
35
|
resume: boolean;
|
package/dist/models.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,MA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EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEjE,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;AAE3D,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,cAAc,EAAE,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;CAClB"}
|
package/dist/sandbox.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MountStatus } from "./apispec/src/models/index.js";
|
|
2
2
|
import type { Client } from "./client.js";
|
|
3
|
-
import type { CmdResult, FileWatchResponse, RunResult, StreamInput, StreamOutput } from "./models.js";
|
|
3
|
+
import type { CmdResult, FileWatchResponse, RunResult, StreamDone, StreamInput, StreamOutput } from "./models.js";
|
|
4
4
|
import { WebSocketClient } from "./ws_client.js";
|
|
5
5
|
export interface RunOptions {
|
|
6
6
|
/**
|
|
@@ -63,9 +63,13 @@ type SandboxParams = {
|
|
|
63
63
|
export declare class ContextStream {
|
|
64
64
|
readonly readable: ReadableStream<StreamOutput>;
|
|
65
65
|
readonly writable: WritableStream<StreamInput>;
|
|
66
|
+
readonly done: Promise<StreamDone>;
|
|
66
67
|
private readonly socket;
|
|
67
68
|
private readonly _contextId;
|
|
68
69
|
private readonly _sandboxId;
|
|
70
|
+
private readonly resolveDone;
|
|
71
|
+
private readonly rejectDone;
|
|
72
|
+
private doneSettled;
|
|
69
73
|
constructor(socket: WebSocketClient, sandboxId: string, contextId: string);
|
|
70
74
|
get id(): string;
|
|
71
75
|
/**
|
|
@@ -84,10 +88,16 @@ export declare class ContextStream {
|
|
|
84
88
|
* Async generator for consuming outputs.
|
|
85
89
|
*/
|
|
86
90
|
outputs(): AsyncGenerator<StreamOutput>;
|
|
91
|
+
/**
|
|
92
|
+
* Wait for the underlying process to finish.
|
|
93
|
+
*/
|
|
94
|
+
wait(): Promise<StreamDone>;
|
|
87
95
|
/**
|
|
88
96
|
* Close the stream connection.
|
|
89
97
|
*/
|
|
90
98
|
close(): void;
|
|
99
|
+
private settleDone;
|
|
100
|
+
private rejectPendingDone;
|
|
91
101
|
}
|
|
92
102
|
/**
|
|
93
103
|
* FileWatchStream provides a stream interface for file system watch events.
|
|
@@ -142,6 +152,7 @@ export declare class Sandbox {
|
|
|
142
152
|
constructor(params: SandboxParams);
|
|
143
153
|
run(alias: string, input: string, options?: RunOptions): Promise<RunResult>;
|
|
144
154
|
cmd(command: string, options?: CmdOptions): Promise<CmdResult>;
|
|
155
|
+
cmdStream(command: string, options?: CmdOptions): Promise<ContextStream>;
|
|
145
156
|
connectWsContext(contextId: string): Promise<ContextStream>;
|
|
146
157
|
private ensureReplContext;
|
|
147
158
|
}
|
package/dist/sandbox.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":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AAM,EAAE,eAAe;IA8BnC;;OAEG;IACI,MAAM,IAAI,cAAc,CAAC,iBAAiB,CAAC;IAalD;;OAEG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAKlC;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd;AAED,qBAAa,OAAO;IAClB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,eAAe,EAAE,WAAW,EAAE,CAAC;IAExC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA6B;gBAEnD,MAAM,EAAE,aAAa;IAU3B,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;IAiB3E,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;IAmC9D,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC;IA8BxE,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;YASnD,iBAAiB;CAqBhC"}
|
package/dist/sandbox.js
CHANGED
|
@@ -36,13 +36,25 @@ import { WebSocketClient } from "./ws_client.js";
|
|
|
36
36
|
export class ContextStream {
|
|
37
37
|
readable;
|
|
38
38
|
writable;
|
|
39
|
+
done;
|
|
39
40
|
socket;
|
|
40
41
|
_contextId;
|
|
41
42
|
_sandboxId;
|
|
43
|
+
resolveDone;
|
|
44
|
+
rejectDone;
|
|
45
|
+
doneSettled = false;
|
|
42
46
|
constructor(socket, sandboxId, contextId) {
|
|
43
47
|
this.socket = socket;
|
|
44
48
|
this._sandboxId = sandboxId;
|
|
45
49
|
this._contextId = contextId;
|
|
50
|
+
let resolveDone;
|
|
51
|
+
let rejectDone;
|
|
52
|
+
this.done = new Promise((resolve, reject) => {
|
|
53
|
+
resolveDone = resolve;
|
|
54
|
+
rejectDone = reject;
|
|
55
|
+
});
|
|
56
|
+
this.resolveDone = resolveDone;
|
|
57
|
+
this.rejectDone = rejectDone;
|
|
46
58
|
// Create ReadableStream for outputs with backpressure
|
|
47
59
|
this.readable = new ReadableStream({
|
|
48
60
|
start: (controller) => {
|
|
@@ -50,6 +62,19 @@ export class ContextStream {
|
|
|
50
62
|
const payload = parseWsMessage(data);
|
|
51
63
|
if (!payload)
|
|
52
64
|
return;
|
|
65
|
+
if (isTerminalDonePayload(payload)) {
|
|
66
|
+
this.settleDone(buildStreamDone(this._sandboxId, this._contextId, payload));
|
|
67
|
+
try {
|
|
68
|
+
controller.close();
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// Controller may already be closed due to error.
|
|
72
|
+
}
|
|
73
|
+
socket.close();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (payload.type && payload.type !== "output")
|
|
77
|
+
return;
|
|
53
78
|
controller.enqueue({
|
|
54
79
|
sandboxId: this._sandboxId,
|
|
55
80
|
contextId: this._contextId,
|
|
@@ -58,9 +83,14 @@ export class ContextStream {
|
|
|
58
83
|
});
|
|
59
84
|
});
|
|
60
85
|
socket.onError((err) => {
|
|
86
|
+
this.rejectPendingDone(err instanceof Error ? err : new Error("websocket error"));
|
|
61
87
|
controller.error(err instanceof Error ? err : new Error("websocket error"));
|
|
62
88
|
});
|
|
63
89
|
socket.onClose(() => {
|
|
90
|
+
this.settleDone({
|
|
91
|
+
sandboxId: this._sandboxId,
|
|
92
|
+
contextId: this._contextId,
|
|
93
|
+
});
|
|
64
94
|
try {
|
|
65
95
|
controller.close();
|
|
66
96
|
}
|
|
@@ -125,12 +155,30 @@ export class ContextStream {
|
|
|
125
155
|
reader.releaseLock();
|
|
126
156
|
}
|
|
127
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Wait for the underlying process to finish.
|
|
160
|
+
*/
|
|
161
|
+
async wait() {
|
|
162
|
+
return this.done;
|
|
163
|
+
}
|
|
128
164
|
/**
|
|
129
165
|
* Close the stream connection.
|
|
130
166
|
*/
|
|
131
167
|
close() {
|
|
132
168
|
this.socket.close();
|
|
133
169
|
}
|
|
170
|
+
settleDone(done) {
|
|
171
|
+
if (this.doneSettled)
|
|
172
|
+
return;
|
|
173
|
+
this.doneSettled = true;
|
|
174
|
+
this.resolveDone(done);
|
|
175
|
+
}
|
|
176
|
+
rejectPendingDone(reason) {
|
|
177
|
+
if (this.doneSettled)
|
|
178
|
+
return;
|
|
179
|
+
this.doneSettled = true;
|
|
180
|
+
this.rejectDone(reason);
|
|
181
|
+
}
|
|
134
182
|
}
|
|
135
183
|
/**
|
|
136
184
|
* FileWatchStream provides a stream interface for file system watch events.
|
|
@@ -288,6 +336,35 @@ export class Sandbox {
|
|
|
288
336
|
outputRaw: contextResp.outputRaw ?? "",
|
|
289
337
|
};
|
|
290
338
|
}
|
|
339
|
+
async cmdStream(command, options) {
|
|
340
|
+
if (options?.wait === true) {
|
|
341
|
+
throw new APIError({
|
|
342
|
+
statusCode: 0,
|
|
343
|
+
code: "invalid_argument",
|
|
344
|
+
message: "cmd stream requires wait=false",
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
const cmdArgs = options?.command ?? parseCommand(command);
|
|
348
|
+
if (!command.trim() || cmdArgs.length === 0) {
|
|
349
|
+
throw new APIError({
|
|
350
|
+
statusCode: 0,
|
|
351
|
+
code: "invalid_argument",
|
|
352
|
+
message: "command cannot be empty",
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
const request = {
|
|
356
|
+
type: models.ProcessType.Cmd,
|
|
357
|
+
cmd: { command: cmdArgs },
|
|
358
|
+
waitUntilDone: false,
|
|
359
|
+
cwd: options?.cwd,
|
|
360
|
+
envVars: options?.envVars,
|
|
361
|
+
ptySize: buildPty(options?.ptyRows, options?.ptyCols),
|
|
362
|
+
idleTimeoutSec: options?.idleTimeoutSec,
|
|
363
|
+
ttlSec: options?.ttlSec,
|
|
364
|
+
};
|
|
365
|
+
const contextResp = await this.createContext(request);
|
|
366
|
+
return this.connectWsContext(contextResp.id);
|
|
367
|
+
}
|
|
291
368
|
async connectWsContext(contextId) {
|
|
292
369
|
const wsUrl = this.client.websocketUrl(`/api/v1/sandboxes/${this.id}/contexts/${contextId}/ws`);
|
|
293
370
|
const headers = await this.client.wsHeaders();
|
|
@@ -389,6 +466,24 @@ function parseWsMessage(data) {
|
|
|
389
466
|
return null;
|
|
390
467
|
}
|
|
391
468
|
}
|
|
469
|
+
function isTerminalDonePayload(payload) {
|
|
470
|
+
if (payload?.type !== "done") {
|
|
471
|
+
return false;
|
|
472
|
+
}
|
|
473
|
+
return !payload.request_id && !payload.requestId
|
|
474
|
+
|| payload.exit_code !== undefined
|
|
475
|
+
|| payload.exitCode !== undefined
|
|
476
|
+
|| typeof payload.state === "string" && payload.state.length > 0;
|
|
477
|
+
}
|
|
478
|
+
function buildStreamDone(sandboxId, contextId, payload) {
|
|
479
|
+
return {
|
|
480
|
+
sandboxId,
|
|
481
|
+
contextId,
|
|
482
|
+
requestId: payload.request_id ?? payload.requestId,
|
|
483
|
+
exitCode: payload.exit_code ?? payload.exitCode,
|
|
484
|
+
state: typeof payload.state === "string" ? payload.state : undefined,
|
|
485
|
+
};
|
|
486
|
+
}
|
|
392
487
|
let requestCounter = 0;
|
|
393
488
|
function generateRequestId() {
|
|
394
489
|
requestCounter += 1;
|