@agentuity/server 0.0.104 → 0.0.106
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/api/api.d.ts +11 -6
- package/dist/api/api.d.ts.map +1 -1
- package/dist/api/api.js +21 -13
- package/dist/api/api.js.map +1 -1
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/project/deploy.d.ts +0 -6
- package/dist/api/project/deploy.d.ts.map +1 -1
- package/dist/api/project/deploy.js +0 -2
- package/dist/api/project/deploy.js.map +1 -1
- package/dist/api/project/get.d.ts +2 -1
- package/dist/api/project/get.d.ts.map +1 -1
- package/dist/api/project/get.js +10 -2
- package/dist/api/project/get.js.map +1 -1
- package/dist/api/region/create.d.ts +2 -0
- package/dist/api/region/create.d.ts.map +1 -1
- package/dist/api/region/create.js +1 -0
- package/dist/api/region/create.js.map +1 -1
- package/dist/api/region/delete.d.ts +12 -2
- package/dist/api/region/delete.d.ts.map +1 -1
- package/dist/api/region/delete.js +6 -1
- package/dist/api/region/delete.js.map +1 -1
- package/dist/api/region/resources.d.ts +4 -0
- package/dist/api/region/resources.d.ts.map +1 -1
- package/dist/api/region/resources.js +2 -0
- package/dist/api/region/resources.js.map +1 -1
- package/dist/api/sandbox/client.d.ts +125 -0
- package/dist/api/sandbox/client.d.ts.map +1 -0
- package/dist/api/sandbox/client.js +202 -0
- package/dist/api/sandbox/client.js.map +1 -0
- package/dist/api/sandbox/create.d.ts +24 -0
- package/dist/api/sandbox/create.d.ts.map +1 -0
- package/dist/api/sandbox/create.js +133 -0
- package/dist/api/sandbox/create.js.map +1 -0
- package/dist/api/sandbox/destroy.d.ts +14 -0
- package/dist/api/sandbox/destroy.d.ts.map +1 -0
- package/dist/api/sandbox/destroy.js +25 -0
- package/dist/api/sandbox/destroy.js.map +1 -0
- package/dist/api/sandbox/execute.d.ts +18 -0
- package/dist/api/sandbox/execute.d.ts.map +1 -0
- package/dist/api/sandbox/execute.js +77 -0
- package/dist/api/sandbox/execute.js.map +1 -0
- package/dist/api/sandbox/execution.d.ts +46 -0
- package/dist/api/sandbox/execution.d.ts.map +1 -0
- package/dist/api/sandbox/execution.js +101 -0
- package/dist/api/sandbox/execution.js.map +1 -0
- package/dist/api/sandbox/files.d.ts +41 -0
- package/dist/api/sandbox/files.d.ts.map +1 -0
- package/dist/api/sandbox/files.js +91 -0
- package/dist/api/sandbox/files.js.map +1 -0
- package/dist/api/sandbox/get.d.ts +16 -0
- package/dist/api/sandbox/get.d.ts.map +1 -0
- package/dist/api/sandbox/get.js +57 -0
- package/dist/api/sandbox/get.js.map +1 -0
- package/dist/api/sandbox/index.d.ts +22 -0
- package/dist/api/sandbox/index.d.ts.map +1 -0
- package/dist/api/sandbox/index.js +12 -0
- package/dist/api/sandbox/index.js.map +1 -0
- package/dist/api/sandbox/list.d.ts +15 -0
- package/dist/api/sandbox/list.d.ts.map +1 -0
- package/dist/api/sandbox/list.js +75 -0
- package/dist/api/sandbox/list.js.map +1 -0
- package/dist/api/sandbox/run.d.ts +28 -0
- package/dist/api/sandbox/run.d.ts.map +1 -0
- package/dist/api/sandbox/run.js +269 -0
- package/dist/api/sandbox/run.js.map +1 -0
- package/dist/api/sandbox/snapshot.d.ts +89 -0
- package/dist/api/sandbox/snapshot.d.ts.map +1 -0
- package/dist/api/sandbox/snapshot.js +140 -0
- package/dist/api/sandbox/snapshot.js.map +1 -0
- package/dist/api/sandbox/util.d.ts +37 -0
- package/dist/api/sandbox/util.d.ts.map +1 -0
- package/dist/api/sandbox/util.js +45 -0
- package/dist/api/sandbox/util.js.map +1 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -1
- package/dist/runtime-bootstrap.d.ts.map +1 -1
- package/dist/runtime-bootstrap.js +3 -0
- package/dist/runtime-bootstrap.js.map +1 -1
- package/package.json +4 -4
- package/src/api/api.ts +33 -13
- package/src/api/index.ts +1 -0
- package/src/api/project/deploy.ts +0 -2
- package/src/api/project/get.ts +10 -2
- package/src/api/region/create.ts +1 -0
- package/src/api/region/delete.ts +9 -2
- package/src/api/region/resources.ts +2 -0
- package/src/api/sandbox/client.ts +349 -0
- package/src/api/sandbox/create.ts +166 -0
- package/src/api/sandbox/destroy.ts +41 -0
- package/src/api/sandbox/execute.ts +102 -0
- package/src/api/sandbox/execution.ts +154 -0
- package/src/api/sandbox/files.ts +138 -0
- package/src/api/sandbox/get.ts +74 -0
- package/src/api/sandbox/index.ts +35 -0
- package/src/api/sandbox/list.ts +94 -0
- package/src/api/sandbox/run.ts +360 -0
- package/src/api/sandbox/snapshot.ts +247 -0
- package/src/api/sandbox/util.ts +55 -0
- package/src/config.ts +2 -0
- package/src/runtime-bootstrap.ts +3 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { Logger, SandboxCreateOptions, SandboxInfo, ExecuteOptions as CoreExecuteOptions, Execution, FileToWrite } from '@agentuity/core';
|
|
2
|
+
import type { Writable } from 'node:stream';
|
|
3
|
+
import { type SandboxCreateResponse } from './create';
|
|
4
|
+
/**
|
|
5
|
+
* Extended execute options that support piping output to writable streams
|
|
6
|
+
*/
|
|
7
|
+
export interface ExecuteOptions extends CoreExecuteOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Pipe stdout/stderr to writable streams (e.g., process.stdout)
|
|
10
|
+
*/
|
|
11
|
+
pipe?: {
|
|
12
|
+
stdout?: Writable;
|
|
13
|
+
stderr?: Writable;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface SandboxClientOptions {
|
|
17
|
+
/**
|
|
18
|
+
* API key for authentication.
|
|
19
|
+
* Defaults to process.env.AGENTUITY_SDK_KEY || process.env.AGENTUITY_CLI_KEY
|
|
20
|
+
*/
|
|
21
|
+
apiKey?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Base URL for the sandbox API.
|
|
24
|
+
* Defaults to process.env.AGENTUITY_SANDBOX_URL ||
|
|
25
|
+
* process.env.AGENTUITY_CATALYST_URL ||
|
|
26
|
+
* process.env.AGENTUITY_TRANSPORT_URL ||
|
|
27
|
+
* regional catalyst URL
|
|
28
|
+
*/
|
|
29
|
+
url?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Organization ID for multi-tenant operations
|
|
32
|
+
*/
|
|
33
|
+
orgId?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Custom logger instance
|
|
36
|
+
*/
|
|
37
|
+
logger?: Logger;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A sandbox instance returned by SandboxClient.create()
|
|
41
|
+
*/
|
|
42
|
+
export interface SandboxInstance {
|
|
43
|
+
/**
|
|
44
|
+
* Unique sandbox identifier
|
|
45
|
+
*/
|
|
46
|
+
id: string;
|
|
47
|
+
/**
|
|
48
|
+
* Sandbox status at creation time
|
|
49
|
+
*/
|
|
50
|
+
status: SandboxCreateResponse['status'];
|
|
51
|
+
/**
|
|
52
|
+
* URL to stream stdout output
|
|
53
|
+
*/
|
|
54
|
+
stdoutStreamUrl?: string;
|
|
55
|
+
/**
|
|
56
|
+
* URL to stream stderr output
|
|
57
|
+
*/
|
|
58
|
+
stderrStreamUrl?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Execute a command in the sandbox
|
|
61
|
+
*/
|
|
62
|
+
execute(options: ExecuteOptions): Promise<Execution>;
|
|
63
|
+
/**
|
|
64
|
+
* Get current sandbox information
|
|
65
|
+
*/
|
|
66
|
+
get(): Promise<SandboxInfo>;
|
|
67
|
+
/**
|
|
68
|
+
* Destroy the sandbox and release all resources
|
|
69
|
+
*/
|
|
70
|
+
destroy(): Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Convenience client for sandbox operations.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const client = new SandboxClient();
|
|
78
|
+
* const sandbox = await client.create();
|
|
79
|
+
* const result = await sandbox.execute({ command: ['echo', 'hello'] });
|
|
80
|
+
* await sandbox.destroy();
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare class SandboxClient {
|
|
84
|
+
#private;
|
|
85
|
+
constructor(options?: SandboxClientOptions);
|
|
86
|
+
/**
|
|
87
|
+
* Create a new sandbox instance
|
|
88
|
+
*
|
|
89
|
+
* @param options - Optional sandbox configuration
|
|
90
|
+
* @returns A sandbox instance with execute and destroy methods
|
|
91
|
+
*/
|
|
92
|
+
create(options?: SandboxCreateOptions): Promise<SandboxInstance>;
|
|
93
|
+
/**
|
|
94
|
+
* Get sandbox information by ID
|
|
95
|
+
*
|
|
96
|
+
* @param sandboxId - The sandbox ID
|
|
97
|
+
* @returns Sandbox information
|
|
98
|
+
*/
|
|
99
|
+
get(sandboxId: string): Promise<SandboxInfo>;
|
|
100
|
+
/**
|
|
101
|
+
* Destroy a sandbox by ID
|
|
102
|
+
*
|
|
103
|
+
* @param sandboxId - The sandbox ID to destroy
|
|
104
|
+
*/
|
|
105
|
+
destroy(sandboxId: string): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Write files to a sandbox workspace
|
|
108
|
+
*
|
|
109
|
+
* @param sandboxId - The sandbox ID
|
|
110
|
+
* @param files - Array of files to write with path and content
|
|
111
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
|
112
|
+
* @returns The number of files written
|
|
113
|
+
*/
|
|
114
|
+
writeFiles(sandboxId: string, files: FileToWrite[], signal?: AbortSignal): Promise<number>;
|
|
115
|
+
/**
|
|
116
|
+
* Read a file from a sandbox workspace
|
|
117
|
+
*
|
|
118
|
+
* @param sandboxId - The sandbox ID
|
|
119
|
+
* @param path - Path to the file relative to the sandbox workspace
|
|
120
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
|
121
|
+
* @returns A ReadableStream of the file contents
|
|
122
|
+
*/
|
|
123
|
+
readFile(sandboxId: string, path: string, signal?: AbortSignal): Promise<ReadableStream<Uint8Array>>;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/api/sandbox/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,MAAM,EACN,oBAAoB,EACpB,WAAW,EACX,cAAc,IAAI,kBAAkB,EACpC,SAAS,EACT,WAAW,EACX,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAiB,KAAK,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAiFrE;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,kBAAkB;IACzD;;OAEG;IACH,IAAI,CAAC,EAAE;QACN,MAAM,CAAC,EAAE,QAAQ,CAAC;QAClB,MAAM,CAAC,EAAE,QAAQ,CAAC;KAClB,CAAC;CACF;AAED,MAAM,WAAW,oBAAoB;IACpC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,MAAM,EAAE,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IAExC;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAErD;;OAEG;IACH,GAAG,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IAE5B;;OAEG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAED;;;;;;;;;;GAUG;AACH,qBAAa,aAAa;;gBAIb,OAAO,GAAE,oBAAyB;IAoB9C;;;;;OAKG;IACG,MAAM,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,eAAe,CAAC;IA2EtE;;;;;OAKG;IACG,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAIlD;;;;OAIG;IACG,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C;;;;;;;OAOG;IACG,UAAU,CACf,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,WAAW,EAAE,EACpB,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,MAAM,CAAC;IAUlB;;;;;;;OAOG;IACG,QAAQ,CACb,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;CAQtC"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { APIClient } from '../api';
|
|
2
|
+
import { sandboxCreate } from './create';
|
|
3
|
+
import { sandboxDestroy } from './destroy';
|
|
4
|
+
import { sandboxGet } from './get';
|
|
5
|
+
import { sandboxExecute } from './execute';
|
|
6
|
+
import { sandboxWriteFiles, sandboxReadFile } from './files';
|
|
7
|
+
import { executionGet } from './execution';
|
|
8
|
+
import { ConsoleLogger } from '../../logger';
|
|
9
|
+
import { getServiceUrls } from '../../config';
|
|
10
|
+
const POLL_INTERVAL_MS = 100;
|
|
11
|
+
const MAX_POLL_TIME_MS = 300000; // 5 minutes
|
|
12
|
+
/**
|
|
13
|
+
* Poll for execution completion
|
|
14
|
+
*/
|
|
15
|
+
async function waitForExecution(client, executionId, orgId, signal) {
|
|
16
|
+
const startTime = Date.now();
|
|
17
|
+
while (Date.now() - startTime < MAX_POLL_TIME_MS) {
|
|
18
|
+
if (signal?.aborted) {
|
|
19
|
+
throw new DOMException('The operation was aborted.', 'AbortError');
|
|
20
|
+
}
|
|
21
|
+
const info = await executionGet(client, { executionId, orgId });
|
|
22
|
+
if (info.status === 'completed' ||
|
|
23
|
+
info.status === 'failed' ||
|
|
24
|
+
info.status === 'timeout' ||
|
|
25
|
+
info.status === 'cancelled') {
|
|
26
|
+
return info;
|
|
27
|
+
}
|
|
28
|
+
await new Promise((resolve, reject) => {
|
|
29
|
+
const timeoutId = setTimeout(resolve, POLL_INTERVAL_MS);
|
|
30
|
+
signal?.addEventListener('abort', () => {
|
|
31
|
+
clearTimeout(timeoutId);
|
|
32
|
+
reject(new DOMException('The operation was aborted.', 'AbortError'));
|
|
33
|
+
}, { once: true });
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
throw new Error(`Execution ${executionId} timed out waiting for completion`);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Pipes a remote stream URL to a local writable stream
|
|
40
|
+
*/
|
|
41
|
+
async function pipeStreamToWritable(streamUrl, writable) {
|
|
42
|
+
const response = await fetch(streamUrl);
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
throw new Error(`Failed to fetch stream: ${response.status} ${response.statusText}`);
|
|
45
|
+
}
|
|
46
|
+
if (!response.body) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const reader = response.body.getReader();
|
|
50
|
+
try {
|
|
51
|
+
while (true) {
|
|
52
|
+
const { done, value } = await reader.read();
|
|
53
|
+
if (done)
|
|
54
|
+
break;
|
|
55
|
+
if (value) {
|
|
56
|
+
writable.write(value);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
reader.releaseLock();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Convenience client for sandbox operations.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const client = new SandboxClient();
|
|
70
|
+
* const sandbox = await client.create();
|
|
71
|
+
* const result = await sandbox.execute({ command: ['echo', 'hello'] });
|
|
72
|
+
* await sandbox.destroy();
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export class SandboxClient {
|
|
76
|
+
#client;
|
|
77
|
+
#orgId;
|
|
78
|
+
constructor(options = {}) {
|
|
79
|
+
const apiKey = options.apiKey || process.env.AGENTUITY_SDK_KEY || process.env.AGENTUITY_CLI_KEY;
|
|
80
|
+
const region = process.env.AGENTUITY_REGION ?? 'usc';
|
|
81
|
+
const serviceUrls = getServiceUrls(region);
|
|
82
|
+
const url = options.url ||
|
|
83
|
+
process.env.AGENTUITY_SANDBOX_URL ||
|
|
84
|
+
process.env.AGENTUITY_CATALYST_URL ||
|
|
85
|
+
process.env.AGENTUITY_TRANSPORT_URL ||
|
|
86
|
+
serviceUrls.sandbox;
|
|
87
|
+
const logger = options.logger ?? new ConsoleLogger('warn');
|
|
88
|
+
this.#client = new APIClient(url, logger, apiKey ?? '', {});
|
|
89
|
+
this.#orgId = options.orgId;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Create a new sandbox instance
|
|
93
|
+
*
|
|
94
|
+
* @param options - Optional sandbox configuration
|
|
95
|
+
* @returns A sandbox instance with execute and destroy methods
|
|
96
|
+
*/
|
|
97
|
+
async create(options) {
|
|
98
|
+
const response = await sandboxCreate(this.#client, {
|
|
99
|
+
options,
|
|
100
|
+
orgId: this.#orgId,
|
|
101
|
+
});
|
|
102
|
+
const sandboxId = response.sandboxId;
|
|
103
|
+
const client = this.#client;
|
|
104
|
+
const orgId = this.#orgId;
|
|
105
|
+
return {
|
|
106
|
+
id: sandboxId,
|
|
107
|
+
status: response.status,
|
|
108
|
+
stdoutStreamUrl: response.stdoutStreamUrl,
|
|
109
|
+
stderrStreamUrl: response.stderrStreamUrl,
|
|
110
|
+
async execute(executeOptions) {
|
|
111
|
+
const { pipe, ...coreOptions } = executeOptions;
|
|
112
|
+
const initialResult = await sandboxExecute(client, {
|
|
113
|
+
sandboxId,
|
|
114
|
+
options: coreOptions,
|
|
115
|
+
orgId,
|
|
116
|
+
signal: coreOptions.signal,
|
|
117
|
+
});
|
|
118
|
+
// If pipe options provided, stream the output to the writable streams
|
|
119
|
+
if (pipe) {
|
|
120
|
+
const streamPromises = [];
|
|
121
|
+
if (pipe.stdout && initialResult.stdoutStreamUrl) {
|
|
122
|
+
streamPromises.push(pipeStreamToWritable(initialResult.stdoutStreamUrl, pipe.stdout));
|
|
123
|
+
}
|
|
124
|
+
if (pipe.stderr && initialResult.stderrStreamUrl) {
|
|
125
|
+
streamPromises.push(pipeStreamToWritable(initialResult.stderrStreamUrl, pipe.stderr));
|
|
126
|
+
}
|
|
127
|
+
// Wait for all streams to complete
|
|
128
|
+
if (streamPromises.length > 0) {
|
|
129
|
+
await Promise.all(streamPromises);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Wait for execution to complete and get final result with exit code
|
|
133
|
+
const finalResult = await waitForExecution(client, initialResult.executionId, orgId, coreOptions.signal);
|
|
134
|
+
return {
|
|
135
|
+
executionId: finalResult.executionId,
|
|
136
|
+
status: finalResult.status,
|
|
137
|
+
exitCode: finalResult.exitCode,
|
|
138
|
+
durationMs: finalResult.durationMs,
|
|
139
|
+
stdoutStreamUrl: initialResult.stdoutStreamUrl,
|
|
140
|
+
stderrStreamUrl: initialResult.stderrStreamUrl,
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
async get() {
|
|
144
|
+
return sandboxGet(client, { sandboxId, orgId });
|
|
145
|
+
},
|
|
146
|
+
async destroy() {
|
|
147
|
+
return sandboxDestroy(client, { sandboxId, orgId });
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get sandbox information by ID
|
|
153
|
+
*
|
|
154
|
+
* @param sandboxId - The sandbox ID
|
|
155
|
+
* @returns Sandbox information
|
|
156
|
+
*/
|
|
157
|
+
async get(sandboxId) {
|
|
158
|
+
return sandboxGet(this.#client, { sandboxId, orgId: this.#orgId });
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Destroy a sandbox by ID
|
|
162
|
+
*
|
|
163
|
+
* @param sandboxId - The sandbox ID to destroy
|
|
164
|
+
*/
|
|
165
|
+
async destroy(sandboxId) {
|
|
166
|
+
return sandboxDestroy(this.#client, { sandboxId, orgId: this.#orgId });
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Write files to a sandbox workspace
|
|
170
|
+
*
|
|
171
|
+
* @param sandboxId - The sandbox ID
|
|
172
|
+
* @param files - Array of files to write with path and content
|
|
173
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
|
174
|
+
* @returns The number of files written
|
|
175
|
+
*/
|
|
176
|
+
async writeFiles(sandboxId, files, signal) {
|
|
177
|
+
const result = await sandboxWriteFiles(this.#client, {
|
|
178
|
+
sandboxId,
|
|
179
|
+
files,
|
|
180
|
+
orgId: this.#orgId,
|
|
181
|
+
signal,
|
|
182
|
+
});
|
|
183
|
+
return result.filesWritten;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Read a file from a sandbox workspace
|
|
187
|
+
*
|
|
188
|
+
* @param sandboxId - The sandbox ID
|
|
189
|
+
* @param path - Path to the file relative to the sandbox workspace
|
|
190
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
|
191
|
+
* @returns A ReadableStream of the file contents
|
|
192
|
+
*/
|
|
193
|
+
async readFile(sandboxId, path, signal) {
|
|
194
|
+
return sandboxReadFile(this.#client, {
|
|
195
|
+
sandboxId,
|
|
196
|
+
path,
|
|
197
|
+
orgId: this.#orgId,
|
|
198
|
+
signal,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRo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C;CACD"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { APIClient } from '../api';
|
|
2
|
+
import type { SandboxCreateOptions, SandboxStatus } from '@agentuity/core';
|
|
3
|
+
export interface SandboxCreateResponse {
|
|
4
|
+
sandboxId: string;
|
|
5
|
+
status: SandboxStatus;
|
|
6
|
+
stdoutStreamId?: string;
|
|
7
|
+
stdoutStreamUrl?: string;
|
|
8
|
+
stderrStreamId?: string;
|
|
9
|
+
stderrStreamUrl?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface SandboxCreateParams {
|
|
12
|
+
options?: SandboxCreateOptions;
|
|
13
|
+
orgId?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new sandbox instance.
|
|
17
|
+
*
|
|
18
|
+
* @param client - The API client to use for the request
|
|
19
|
+
* @param params - Parameters for creating the sandbox
|
|
20
|
+
* @returns The created sandbox response including sandbox ID and stream URLs
|
|
21
|
+
* @throws {SandboxResponseError} If the sandbox creation fails
|
|
22
|
+
*/
|
|
23
|
+
export declare function sandboxCreate(client: APIClient, params?: SandboxCreateParams): Promise<SandboxCreateResponse>;
|
|
24
|
+
//# sourceMappingURL=create.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/api/sandbox/create.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAqB,MAAM,QAAQ,CAAC;AAEtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAkF3E,MAAM,WAAW,qBAAqB;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,aAAa,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,mBAAmB;IACnC,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAClC,MAAM,EAAE,SAAS,EACjB,MAAM,GAAE,mBAAwB,GAC9B,OAAO,CAAC,qBAAqB,CAAC,CAuDhC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { APIResponseSchema } from '../api';
|
|
3
|
+
import { SandboxResponseError, API_VERSION } from './util';
|
|
4
|
+
const SandboxCreateRequestSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
resources: z
|
|
7
|
+
.object({
|
|
8
|
+
memory: z.string().optional().describe('Memory limit (e.g., "512Mi", "1Gi")'),
|
|
9
|
+
cpu: z.string().optional().describe('CPU limit (e.g., "0.5", "1")'),
|
|
10
|
+
disk: z.string().optional().describe('Disk size limit (e.g., "1Gi", "10Gi")'),
|
|
11
|
+
})
|
|
12
|
+
.optional()
|
|
13
|
+
.describe('Resource constraints for the sandbox'),
|
|
14
|
+
env: z
|
|
15
|
+
.record(z.string(), z.string())
|
|
16
|
+
.optional()
|
|
17
|
+
.describe('Environment variables to set in the sandbox'),
|
|
18
|
+
network: z
|
|
19
|
+
.object({
|
|
20
|
+
enabled: z.boolean().optional().describe('Whether network access is enabled'),
|
|
21
|
+
})
|
|
22
|
+
.optional()
|
|
23
|
+
.describe('Network configuration for the sandbox'),
|
|
24
|
+
stream: z
|
|
25
|
+
.object({
|
|
26
|
+
stdout: z.string().optional().describe('Stream ID for stdout output'),
|
|
27
|
+
stderr: z.string().optional().describe('Stream ID for stderr output'),
|
|
28
|
+
stdin: z.string().optional().describe('Stream ID for stdin input'),
|
|
29
|
+
timestamps: z.boolean().optional().describe('Whether to include timestamps in output'),
|
|
30
|
+
})
|
|
31
|
+
.optional()
|
|
32
|
+
.describe('Stream configuration for I/O redirection'),
|
|
33
|
+
timeout: z
|
|
34
|
+
.object({
|
|
35
|
+
idle: z.string().optional().describe('Idle timeout duration (e.g., "5m", "1h")'),
|
|
36
|
+
execution: z.string().optional().describe('Maximum execution time (e.g., "30m", "2h")'),
|
|
37
|
+
})
|
|
38
|
+
.optional()
|
|
39
|
+
.describe('Timeout settings for the sandbox'),
|
|
40
|
+
command: z
|
|
41
|
+
.object({
|
|
42
|
+
exec: z.array(z.string()).describe('Command and arguments to execute'),
|
|
43
|
+
files: z
|
|
44
|
+
.array(z.object({
|
|
45
|
+
path: z
|
|
46
|
+
.string()
|
|
47
|
+
.describe('Path to the file relative to the sandbox workspace'),
|
|
48
|
+
content: z.string().describe('Base64-encoded file content'),
|
|
49
|
+
}))
|
|
50
|
+
.optional()
|
|
51
|
+
.describe('Files to write before execution'),
|
|
52
|
+
mode: z
|
|
53
|
+
.enum(['oneshot', 'interactive'])
|
|
54
|
+
.optional()
|
|
55
|
+
.describe('Execution mode: oneshot runs once, interactive keeps running'),
|
|
56
|
+
})
|
|
57
|
+
.optional()
|
|
58
|
+
.describe('Initial command to run in the sandbox'),
|
|
59
|
+
snapshot: z.string().optional().describe('Snapshot ID to restore the sandbox from'),
|
|
60
|
+
dependencies: z
|
|
61
|
+
.array(z.string())
|
|
62
|
+
.optional()
|
|
63
|
+
.describe('Apt packages to install when creating the sandbox'),
|
|
64
|
+
})
|
|
65
|
+
.describe('Request body for creating a new sandbox');
|
|
66
|
+
const SandboxCreateDataSchema = z
|
|
67
|
+
.object({
|
|
68
|
+
sandboxId: z.string().describe('Unique identifier for the created sandbox'),
|
|
69
|
+
status: z
|
|
70
|
+
.enum(['creating', 'idle', 'running', 'terminated', 'failed'])
|
|
71
|
+
.describe('Current status of the sandbox'),
|
|
72
|
+
stdoutStreamId: z.string().optional().describe('Stream ID for reading stdout'),
|
|
73
|
+
stdoutStreamUrl: z.string().optional().describe('URL for streaming stdout output'),
|
|
74
|
+
stderrStreamId: z.string().optional().describe('Stream ID for reading stderr'),
|
|
75
|
+
stderrStreamUrl: z.string().optional().describe('URL for streaming stderr output'),
|
|
76
|
+
})
|
|
77
|
+
.describe('Response data from sandbox creation');
|
|
78
|
+
const SandboxCreateResponseSchema = APIResponseSchema(SandboxCreateDataSchema);
|
|
79
|
+
/**
|
|
80
|
+
* Creates a new sandbox instance.
|
|
81
|
+
*
|
|
82
|
+
* @param client - The API client to use for the request
|
|
83
|
+
* @param params - Parameters for creating the sandbox
|
|
84
|
+
* @returns The created sandbox response including sandbox ID and stream URLs
|
|
85
|
+
* @throws {SandboxResponseError} If the sandbox creation fails
|
|
86
|
+
*/
|
|
87
|
+
export async function sandboxCreate(client, params = {}) {
|
|
88
|
+
const { options = {}, orgId } = params;
|
|
89
|
+
const body = {};
|
|
90
|
+
if (options.resources) {
|
|
91
|
+
body.resources = options.resources;
|
|
92
|
+
}
|
|
93
|
+
if (options.env) {
|
|
94
|
+
body.env = options.env;
|
|
95
|
+
}
|
|
96
|
+
if (options.network) {
|
|
97
|
+
body.network = options.network;
|
|
98
|
+
}
|
|
99
|
+
if (options.stream) {
|
|
100
|
+
body.stream = options.stream;
|
|
101
|
+
}
|
|
102
|
+
if (options.timeout) {
|
|
103
|
+
body.timeout = options.timeout;
|
|
104
|
+
}
|
|
105
|
+
if (options.command) {
|
|
106
|
+
body.command = {
|
|
107
|
+
exec: options.command.exec,
|
|
108
|
+
mode: options.command.mode,
|
|
109
|
+
files: options.command.files?.map((f) => ({
|
|
110
|
+
path: f.path,
|
|
111
|
+
content: f.content.toString('base64'),
|
|
112
|
+
})),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
if (options.snapshot) {
|
|
116
|
+
body.snapshot = options.snapshot;
|
|
117
|
+
}
|
|
118
|
+
if (options.dependencies && options.dependencies.length > 0) {
|
|
119
|
+
body.dependencies = options.dependencies;
|
|
120
|
+
}
|
|
121
|
+
const queryParams = new URLSearchParams();
|
|
122
|
+
if (orgId) {
|
|
123
|
+
queryParams.set('orgId', orgId);
|
|
124
|
+
}
|
|
125
|
+
const queryString = queryParams.toString();
|
|
126
|
+
const url = `/sandbox/${API_VERSION}${queryString ? `?${queryString}` : ''}`;
|
|
127
|
+
const resp = await client.post(url, body, SandboxCreateResponseSchema, SandboxCreateRequestSchema);
|
|
128
|
+
if (resp.success) {
|
|
129
|
+
return resp.data;
|
|
130
|
+
}
|
|
131
|
+
throw new SandboxResponseError({ message: resp.message });
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/api/sandbox/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAa,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAG3D,MAAM,0BAA0B,GAAG,CAAC;KAClC,MAAM,CAAC;IACP,SAAS,EAAE,CAAC;SACV,MAAM,CAAC;QACP,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,qCAAqC,CAAC;QAC7E,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,8BAA8B,CAAC;QACnE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,uCAAuC,CAAC;KAC7E,CAAC;SACD,QAAQ,EAAE;SACV,QAAQ,CAAC,sCAAsC,CAAC;IAClD,GAAG,EAAE,CAAC;SACJ,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;SAC9B,QAAQ,EAAE;SACV,QAAQ,CAAC,6CAA6C,CAAC;IACzD,OAAO,EAAE,CAAC;SACR,MAAM,CAAC;QACP,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,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IACD,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAClC,CAAC;IACD,IAAI,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7D,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC1C,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,eAAe,EAAE,CAAC;IAC1C,IAAI,KAAK,EAAE,CAAC;QACX,WAAW,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC;IACD,MAAM,WAAW,GAAG,WAAW,CAAC,QAAQ,EAAE,CAAC;IAC3C,MAAM,GAAG,GAAG,YAAY,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAE7E,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,IAAI,CAC7B,GAAG,EACH,IAAI,EACJ,2BAA2B,EAC3B,0BAA0B,CAC1B,CAAC;IAEF,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IAED,MAAM,IAAI,oBAAoB,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { APIClient } from '../api';
|
|
2
|
+
export interface SandboxDestroyParams {
|
|
3
|
+
sandboxId: string;
|
|
4
|
+
orgId?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Destroys a sandbox and releases all associated resources.
|
|
8
|
+
*
|
|
9
|
+
* @param client - The API client to use for the request
|
|
10
|
+
* @param params - Parameters including the sandbox ID to destroy
|
|
11
|
+
* @throws {SandboxResponseError} If the sandbox is not found or destruction fails
|
|
12
|
+
*/
|
|
13
|
+
export declare function sandboxDestroy(client: APIClient, params: SandboxDestroyParams): Promise<void>;
|
|
14
|
+
//# sourceMappingURL=destroy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destroy.d.ts","sourceRoot":"","sources":["../../../src/api/sandbox/destroy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAA2B,MAAM,QAAQ,CAAC;AAK5D,MAAM,WAAW,oBAAoB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CACnC,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,oBAAoB,GAC1B,OAAO,CAAC,IAAI,CAAC,CAmBf"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { APIResponseSchemaNoData } from '../api';
|
|
2
|
+
import { SandboxResponseError, API_VERSION } from './util';
|
|
3
|
+
const DestroyResponseSchema = APIResponseSchemaNoData();
|
|
4
|
+
/**
|
|
5
|
+
* Destroys a sandbox and releases all associated resources.
|
|
6
|
+
*
|
|
7
|
+
* @param client - The API client to use for the request
|
|
8
|
+
* @param params - Parameters including the sandbox ID to destroy
|
|
9
|
+
* @throws {SandboxResponseError} If the sandbox is not found or destruction fails
|
|
10
|
+
*/
|
|
11
|
+
export async function sandboxDestroy(client, params) {
|
|
12
|
+
const { sandboxId, orgId } = params;
|
|
13
|
+
const queryParams = new URLSearchParams();
|
|
14
|
+
if (orgId) {
|
|
15
|
+
queryParams.set('orgId', orgId);
|
|
16
|
+
}
|
|
17
|
+
const queryString = queryParams.toString();
|
|
18
|
+
const url = `/sandbox/${API_VERSION}/${sandboxId}${queryString ? `?${queryString}` : ''}`;
|
|
19
|
+
const resp = await client.delete(url, DestroyResponseSchema);
|
|
20
|
+
if (resp.success) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
throw new SandboxResponseError({ message: resp.message, sandboxId });
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=destroy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destroy.js","sourceRoot":"","sources":["../../../src/api/sandbox/destroy.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,uBAAuB,EAAE,MAAM,QAAQ,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAE3D,MAAM,qBAAqB,GAAG,uBAAuB,EAAE,CAAC;AAOxD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,MAAiB,EACjB,MAA4B;IAE5B,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IACpC,MAAM,WAAW,GAAG,IAAI,eAAe,EAAE,CAAC;IAC1C,IAAI,KAAK,EAAE,CAAC;QACX,WAAW,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC;IACD,MAAM,WAAW,GAAG,WAAW,CAAC,QAAQ,EAAE,CAAC;IAC3C,MAAM,GAAG,GAAG,YAAY,WAAW,IAAI,SAAS,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAE1F,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAC/B,GAAG,EACH,qBAAqB,CACrB,CAAC;IAEF,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QAClB,OAAO;IACR,CAAC;IAED,MAAM,IAAI,oBAAoB,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { APIClient } from '../api';
|
|
2
|
+
import type { ExecuteOptions, Execution } from '@agentuity/core';
|
|
3
|
+
export interface SandboxExecuteParams {
|
|
4
|
+
sandboxId: string;
|
|
5
|
+
options: ExecuteOptions;
|
|
6
|
+
orgId?: string;
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Executes a command in an existing sandbox.
|
|
11
|
+
*
|
|
12
|
+
* @param client - The API client to use for the request
|
|
13
|
+
* @param params - Parameters including sandbox ID and execution options
|
|
14
|
+
* @returns The execution result including status and stream URLs
|
|
15
|
+
* @throws {SandboxResponseError} If the execution request fails
|
|
16
|
+
*/
|
|
17
|
+
export declare function sandboxExecute(client: APIClient, params: SandboxExecuteParams): Promise<Execution>;
|
|
18
|
+
//# sourceMappingURL=execute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/api/sandbox/execute.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAqB,MAAM,QAAQ,CAAC;AAGtD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAmB,MAAM,iBAAiB,CAAC;AAiClF,MAAM,WAAW,oBAAoB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CACnC,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,oBAAoB,GAC1B,OAAO,CAAC,SAAS,CAAC,CA8CpB"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { APIResponseSchema } from '../api';
|
|
3
|
+
import { SandboxResponseError, API_VERSION } from './util';
|
|
4
|
+
import { FileToWriteSchema } from './files';
|
|
5
|
+
const ExecuteRequestSchema = z
|
|
6
|
+
.object({
|
|
7
|
+
command: z.array(z.string()).describe('Command and arguments to execute'),
|
|
8
|
+
files: z.array(FileToWriteSchema).optional().describe('Files to write before execution'),
|
|
9
|
+
timeout: z.string().optional().describe('Execution timeout (e.g., "30s", "5m")'),
|
|
10
|
+
stream: z
|
|
11
|
+
.object({
|
|
12
|
+
stdout: z.string().optional().describe('Stream ID for stdout output'),
|
|
13
|
+
stderr: z.string().optional().describe('Stream ID for stderr output'),
|
|
14
|
+
timestamps: z.boolean().optional().describe('Whether to include timestamps in output'),
|
|
15
|
+
})
|
|
16
|
+
.optional()
|
|
17
|
+
.describe('Stream configuration for output redirection'),
|
|
18
|
+
})
|
|
19
|
+
.describe('Request body for executing a command in a sandbox');
|
|
20
|
+
const ExecuteDataSchema = z
|
|
21
|
+
.object({
|
|
22
|
+
executionId: z.string().describe('Unique identifier for the execution'),
|
|
23
|
+
status: z
|
|
24
|
+
.enum(['queued', 'running', 'completed', 'failed', 'timeout', 'cancelled'])
|
|
25
|
+
.describe('Current status of the execution'),
|
|
26
|
+
exitCode: z.number().optional().describe('Exit code of the executed command'),
|
|
27
|
+
durationMs: z.number().optional().describe('Execution duration in milliseconds'),
|
|
28
|
+
stdoutStreamUrl: z.string().optional().describe('URL for streaming stdout output'),
|
|
29
|
+
stderrStreamUrl: z.string().optional().describe('URL for streaming stderr output'),
|
|
30
|
+
})
|
|
31
|
+
.describe('Response data from command execution');
|
|
32
|
+
const ExecuteResponseSchema = APIResponseSchema(ExecuteDataSchema);
|
|
33
|
+
/**
|
|
34
|
+
* Executes a command in an existing sandbox.
|
|
35
|
+
*
|
|
36
|
+
* @param client - The API client to use for the request
|
|
37
|
+
* @param params - Parameters including sandbox ID and execution options
|
|
38
|
+
* @returns The execution result including status and stream URLs
|
|
39
|
+
* @throws {SandboxResponseError} If the execution request fails
|
|
40
|
+
*/
|
|
41
|
+
export async function sandboxExecute(client, params) {
|
|
42
|
+
const { sandboxId, options, orgId, signal } = params;
|
|
43
|
+
const body = {
|
|
44
|
+
command: options.command,
|
|
45
|
+
};
|
|
46
|
+
if (options.files) {
|
|
47
|
+
body.files = options.files.map((f) => ({
|
|
48
|
+
path: f.path,
|
|
49
|
+
content: f.content.toString('base64'),
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
if (options.timeout) {
|
|
53
|
+
body.timeout = options.timeout;
|
|
54
|
+
}
|
|
55
|
+
if (options.stream) {
|
|
56
|
+
body.stream = options.stream;
|
|
57
|
+
}
|
|
58
|
+
const queryParams = new URLSearchParams();
|
|
59
|
+
if (orgId) {
|
|
60
|
+
queryParams.set('orgId', orgId);
|
|
61
|
+
}
|
|
62
|
+
const queryString = queryParams.toString();
|
|
63
|
+
const url = `/sandbox/${API_VERSION}/${sandboxId}/execute${queryString ? `?${queryString}` : ''}`;
|
|
64
|
+
const resp = await client.post(url, body, ExecuteResponseSchema, ExecuteRequestSchema, signal ?? options.signal);
|
|
65
|
+
if (resp.success) {
|
|
66
|
+
return {
|
|
67
|
+
executionId: resp.data.executionId,
|
|
68
|
+
status: resp.data.status,
|
|
69
|
+
exitCode: resp.data.exitCode,
|
|
70
|
+
durationMs: resp.data.durationMs,
|
|
71
|
+
stdoutStreamUrl: resp.data.stdoutStreamUrl,
|
|
72
|
+
stderrStreamUrl: resp.data.stderrStreamUrl,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
throw new SandboxResponseError({ message: resp.message, sandboxId });
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=execute.js.map
|