@meistrari/sandbox-sdk 0.1.4
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 +373 -0
- package/dist/index.cjs +381 -0
- package/dist/index.d.cts +195 -0
- package/dist/index.d.mts +195 -0
- package/dist/index.d.ts +195 -0
- package/dist/index.mjs +374 -0
- package/package.json +29 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
interface SandboxConfig {
|
|
2
|
+
apiUrl: string;
|
|
3
|
+
auth: AuthStrategy;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
}
|
|
6
|
+
interface AuthStrategy {
|
|
7
|
+
getHeaders(): Headers;
|
|
8
|
+
}
|
|
9
|
+
interface CreateRunRequest {
|
|
10
|
+
code: string;
|
|
11
|
+
language?: 'javascript' | 'typescript' | 'python' | 'bash' | 'ts' | 'js';
|
|
12
|
+
libraries?: string[];
|
|
13
|
+
env?: Record<string, string>;
|
|
14
|
+
files?: FileInput[];
|
|
15
|
+
memSize?: number;
|
|
16
|
+
cpuSize?: number;
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
sandboxId?: string;
|
|
19
|
+
persistent?: boolean;
|
|
20
|
+
sandboxTtlSeconds?: number;
|
|
21
|
+
}
|
|
22
|
+
interface CreateSandboxRequest {
|
|
23
|
+
cpuSize?: number;
|
|
24
|
+
memSize?: number;
|
|
25
|
+
sandboxTtlSeconds?: number;
|
|
26
|
+
files?: FileInput[];
|
|
27
|
+
}
|
|
28
|
+
interface FileInput {
|
|
29
|
+
name: string;
|
|
30
|
+
content: string;
|
|
31
|
+
encoding: 'base64' | 'utf8';
|
|
32
|
+
path?: string;
|
|
33
|
+
}
|
|
34
|
+
type Status = 'pending' | 'running' | 'completed' | 'failed' | 'timeout' | 'cancelled';
|
|
35
|
+
interface RunResponse {
|
|
36
|
+
id: string;
|
|
37
|
+
workspaceId: string;
|
|
38
|
+
status: Status;
|
|
39
|
+
sandboxId?: string;
|
|
40
|
+
exitCode?: number;
|
|
41
|
+
stdout?: string;
|
|
42
|
+
stderr?: string;
|
|
43
|
+
durationMs?: number;
|
|
44
|
+
errorMessage?: string;
|
|
45
|
+
createdAt: Date;
|
|
46
|
+
completedAt?: Date;
|
|
47
|
+
}
|
|
48
|
+
interface StreamEvent {
|
|
49
|
+
type: 'run_created' | 'sandbox_created' | 'stdout' | 'stderr' | 'status' | 'done' | 'error';
|
|
50
|
+
content?: string;
|
|
51
|
+
runId?: string;
|
|
52
|
+
sandboxId?: string;
|
|
53
|
+
metadata?: Record<string, unknown>;
|
|
54
|
+
}
|
|
55
|
+
interface StreamCallbacks {
|
|
56
|
+
onStdout?: (line: string) => void | Promise<void>;
|
|
57
|
+
onStderr?: (line: string) => void | Promise<void>;
|
|
58
|
+
onStatus?: (status: Status) => void | Promise<void>;
|
|
59
|
+
onError?: (error: Error) => void | Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
interface ExecutionResult {
|
|
62
|
+
stdout: string;
|
|
63
|
+
stderr: string;
|
|
64
|
+
exitCode?: number;
|
|
65
|
+
error?: string;
|
|
66
|
+
}
|
|
67
|
+
interface RunCodeOptions {
|
|
68
|
+
envs?: Record<string, string>;
|
|
69
|
+
language?: 'typescript' | 'javascript' | 'python' | 'bash' | 'ts' | 'js';
|
|
70
|
+
timeoutMs?: number;
|
|
71
|
+
libraries?: string[];
|
|
72
|
+
files?: FileInput[];
|
|
73
|
+
onStdout?: (data: {
|
|
74
|
+
line: string;
|
|
75
|
+
}) => void | Promise<void>;
|
|
76
|
+
onStderr?: (data: {
|
|
77
|
+
line: string;
|
|
78
|
+
}) => void | Promise<void>;
|
|
79
|
+
onError?: (error: Error) => void;
|
|
80
|
+
}
|
|
81
|
+
interface FileReadOptions {
|
|
82
|
+
format?: 'text' | 'blob';
|
|
83
|
+
}
|
|
84
|
+
interface SandboxFiles {
|
|
85
|
+
write: (path: string, content: string | Uint8Array) => Promise<void>;
|
|
86
|
+
read: {
|
|
87
|
+
(path: string): Promise<string>;
|
|
88
|
+
(path: string, options: {
|
|
89
|
+
format: 'text';
|
|
90
|
+
}): Promise<string>;
|
|
91
|
+
(path: string, options: {
|
|
92
|
+
format: 'blob';
|
|
93
|
+
}): Promise<Blob>;
|
|
94
|
+
};
|
|
95
|
+
exists: (path: string) => Promise<boolean>;
|
|
96
|
+
remove: (path: string) => Promise<void>;
|
|
97
|
+
list: (directory?: string) => Promise<string[]>;
|
|
98
|
+
}
|
|
99
|
+
interface SandboxCommands {
|
|
100
|
+
run: (command: string) => Promise<{
|
|
101
|
+
stdout: string;
|
|
102
|
+
stderr: string;
|
|
103
|
+
exitCode?: number;
|
|
104
|
+
}>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
declare class Sandbox {
|
|
108
|
+
private client;
|
|
109
|
+
private auth;
|
|
110
|
+
readonly sandboxId: string;
|
|
111
|
+
readonly files: SandboxFiles;
|
|
112
|
+
readonly commands: SandboxCommands;
|
|
113
|
+
private timeoutMs;
|
|
114
|
+
constructor(client: SandboxClient, sandboxId: string, auth: AuthStrategy);
|
|
115
|
+
static create(client: SandboxClient, options?: {
|
|
116
|
+
memSize?: number;
|
|
117
|
+
cpuSize?: number;
|
|
118
|
+
files?: Array<{
|
|
119
|
+
name: string;
|
|
120
|
+
content: string;
|
|
121
|
+
encoding: 'utf8' | 'base64';
|
|
122
|
+
path?: string;
|
|
123
|
+
}>;
|
|
124
|
+
}): Promise<Sandbox>;
|
|
125
|
+
static connect(client: SandboxClient, sandboxId: string): Promise<Sandbox>;
|
|
126
|
+
private normalizeLanguage;
|
|
127
|
+
runCode(script: string, options?: RunCodeOptions): Promise<ExecutionResult>;
|
|
128
|
+
kill(): Promise<void>;
|
|
129
|
+
betaPause(): Promise<void>;
|
|
130
|
+
setTimeout(ms: number): void;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
declare class SandboxRun {
|
|
134
|
+
private client;
|
|
135
|
+
readonly id: string;
|
|
136
|
+
readonly sandboxId?: string;
|
|
137
|
+
status: Status;
|
|
138
|
+
stdout?: string;
|
|
139
|
+
stderr?: string;
|
|
140
|
+
exitCode?: number;
|
|
141
|
+
errorMessage?: string;
|
|
142
|
+
durationMs?: number;
|
|
143
|
+
constructor(client: SandboxClient, data: RunResponse);
|
|
144
|
+
refresh(): Promise<this>;
|
|
145
|
+
waitForCompletion(options?: {
|
|
146
|
+
intervalMs?: number;
|
|
147
|
+
maxAttempts?: number;
|
|
148
|
+
}): Promise<this>;
|
|
149
|
+
get isComplete(): boolean;
|
|
150
|
+
get isSuccess(): boolean;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
declare class SandboxClient {
|
|
154
|
+
private apiUrl;
|
|
155
|
+
private auth;
|
|
156
|
+
private timeout;
|
|
157
|
+
constructor(config: SandboxConfig);
|
|
158
|
+
private fetch;
|
|
159
|
+
createRun(request: CreateRunRequest): Promise<SandboxRun>;
|
|
160
|
+
createRunAndWait(request: CreateRunRequest): Promise<SandboxRun>;
|
|
161
|
+
streamRun(request: CreateRunRequest): AsyncGenerator<StreamEvent>;
|
|
162
|
+
getRun(runId: string): Promise<SandboxRun>;
|
|
163
|
+
createSandbox(request?: CreateSandboxRequest): Promise<Sandbox>;
|
|
164
|
+
getSandboxStatus(sandboxId: string): Promise<{
|
|
165
|
+
sandboxId: string;
|
|
166
|
+
status: Status;
|
|
167
|
+
}>;
|
|
168
|
+
connectToSandbox(sandboxId: string): Promise<Sandbox>;
|
|
169
|
+
deleteSandbox(sandboxId: string): Promise<void>;
|
|
170
|
+
writeFile(sandboxId: string, path: string, content: string | Uint8Array): Promise<void>;
|
|
171
|
+
readFile(sandboxId: string, path: string, options?: FileReadOptions): Promise<string | Blob>;
|
|
172
|
+
fileExists(sandboxId: string, path: string): Promise<boolean>;
|
|
173
|
+
listFiles(sandboxId: string, directory?: string): Promise<string[]>;
|
|
174
|
+
deleteFile(sandboxId: string, path: string): Promise<void>;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
declare class DataTokenAuthStrategy implements AuthStrategy {
|
|
178
|
+
private dataToken;
|
|
179
|
+
constructor(dataToken: string);
|
|
180
|
+
getHeaders(): Headers;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
declare class FetchError extends Error {
|
|
184
|
+
readonly url: string;
|
|
185
|
+
readonly method: string;
|
|
186
|
+
readonly status: number;
|
|
187
|
+
readonly response?: unknown | undefined;
|
|
188
|
+
constructor(message: string, url: string, method: string, status: number, response?: unknown | undefined);
|
|
189
|
+
static from(url: string, method: string, res: Response): Promise<FetchError>;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
declare function sandbox(config: SandboxConfig): SandboxClient;
|
|
193
|
+
|
|
194
|
+
export { DataTokenAuthStrategy, FetchError, Sandbox, SandboxClient, SandboxRun, sandbox };
|
|
195
|
+
export type { AuthStrategy, CreateRunRequest, CreateSandboxRequest, ExecutionResult, FileInput, RunCodeOptions, RunResponse, SandboxCommands, SandboxConfig, SandboxFiles, Status, StreamCallbacks, StreamEvent };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
interface SandboxConfig {
|
|
2
|
+
apiUrl: string;
|
|
3
|
+
auth: AuthStrategy;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
}
|
|
6
|
+
interface AuthStrategy {
|
|
7
|
+
getHeaders(): Headers;
|
|
8
|
+
}
|
|
9
|
+
interface CreateRunRequest {
|
|
10
|
+
code: string;
|
|
11
|
+
language?: 'javascript' | 'typescript' | 'python' | 'bash' | 'ts' | 'js';
|
|
12
|
+
libraries?: string[];
|
|
13
|
+
env?: Record<string, string>;
|
|
14
|
+
files?: FileInput[];
|
|
15
|
+
memSize?: number;
|
|
16
|
+
cpuSize?: number;
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
sandboxId?: string;
|
|
19
|
+
persistent?: boolean;
|
|
20
|
+
sandboxTtlSeconds?: number;
|
|
21
|
+
}
|
|
22
|
+
interface CreateSandboxRequest {
|
|
23
|
+
cpuSize?: number;
|
|
24
|
+
memSize?: number;
|
|
25
|
+
sandboxTtlSeconds?: number;
|
|
26
|
+
files?: FileInput[];
|
|
27
|
+
}
|
|
28
|
+
interface FileInput {
|
|
29
|
+
name: string;
|
|
30
|
+
content: string;
|
|
31
|
+
encoding: 'base64' | 'utf8';
|
|
32
|
+
path?: string;
|
|
33
|
+
}
|
|
34
|
+
type Status = 'pending' | 'running' | 'completed' | 'failed' | 'timeout' | 'cancelled';
|
|
35
|
+
interface RunResponse {
|
|
36
|
+
id: string;
|
|
37
|
+
workspaceId: string;
|
|
38
|
+
status: Status;
|
|
39
|
+
sandboxId?: string;
|
|
40
|
+
exitCode?: number;
|
|
41
|
+
stdout?: string;
|
|
42
|
+
stderr?: string;
|
|
43
|
+
durationMs?: number;
|
|
44
|
+
errorMessage?: string;
|
|
45
|
+
createdAt: Date;
|
|
46
|
+
completedAt?: Date;
|
|
47
|
+
}
|
|
48
|
+
interface StreamEvent {
|
|
49
|
+
type: 'run_created' | 'sandbox_created' | 'stdout' | 'stderr' | 'status' | 'done' | 'error';
|
|
50
|
+
content?: string;
|
|
51
|
+
runId?: string;
|
|
52
|
+
sandboxId?: string;
|
|
53
|
+
metadata?: Record<string, unknown>;
|
|
54
|
+
}
|
|
55
|
+
interface StreamCallbacks {
|
|
56
|
+
onStdout?: (line: string) => void | Promise<void>;
|
|
57
|
+
onStderr?: (line: string) => void | Promise<void>;
|
|
58
|
+
onStatus?: (status: Status) => void | Promise<void>;
|
|
59
|
+
onError?: (error: Error) => void | Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
interface ExecutionResult {
|
|
62
|
+
stdout: string;
|
|
63
|
+
stderr: string;
|
|
64
|
+
exitCode?: number;
|
|
65
|
+
error?: string;
|
|
66
|
+
}
|
|
67
|
+
interface RunCodeOptions {
|
|
68
|
+
envs?: Record<string, string>;
|
|
69
|
+
language?: 'typescript' | 'javascript' | 'python' | 'bash' | 'ts' | 'js';
|
|
70
|
+
timeoutMs?: number;
|
|
71
|
+
libraries?: string[];
|
|
72
|
+
files?: FileInput[];
|
|
73
|
+
onStdout?: (data: {
|
|
74
|
+
line: string;
|
|
75
|
+
}) => void | Promise<void>;
|
|
76
|
+
onStderr?: (data: {
|
|
77
|
+
line: string;
|
|
78
|
+
}) => void | Promise<void>;
|
|
79
|
+
onError?: (error: Error) => void;
|
|
80
|
+
}
|
|
81
|
+
interface FileReadOptions {
|
|
82
|
+
format?: 'text' | 'blob';
|
|
83
|
+
}
|
|
84
|
+
interface SandboxFiles {
|
|
85
|
+
write: (path: string, content: string | Uint8Array) => Promise<void>;
|
|
86
|
+
read: {
|
|
87
|
+
(path: string): Promise<string>;
|
|
88
|
+
(path: string, options: {
|
|
89
|
+
format: 'text';
|
|
90
|
+
}): Promise<string>;
|
|
91
|
+
(path: string, options: {
|
|
92
|
+
format: 'blob';
|
|
93
|
+
}): Promise<Blob>;
|
|
94
|
+
};
|
|
95
|
+
exists: (path: string) => Promise<boolean>;
|
|
96
|
+
remove: (path: string) => Promise<void>;
|
|
97
|
+
list: (directory?: string) => Promise<string[]>;
|
|
98
|
+
}
|
|
99
|
+
interface SandboxCommands {
|
|
100
|
+
run: (command: string) => Promise<{
|
|
101
|
+
stdout: string;
|
|
102
|
+
stderr: string;
|
|
103
|
+
exitCode?: number;
|
|
104
|
+
}>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
declare class Sandbox {
|
|
108
|
+
private client;
|
|
109
|
+
private auth;
|
|
110
|
+
readonly sandboxId: string;
|
|
111
|
+
readonly files: SandboxFiles;
|
|
112
|
+
readonly commands: SandboxCommands;
|
|
113
|
+
private timeoutMs;
|
|
114
|
+
constructor(client: SandboxClient, sandboxId: string, auth: AuthStrategy);
|
|
115
|
+
static create(client: SandboxClient, options?: {
|
|
116
|
+
memSize?: number;
|
|
117
|
+
cpuSize?: number;
|
|
118
|
+
files?: Array<{
|
|
119
|
+
name: string;
|
|
120
|
+
content: string;
|
|
121
|
+
encoding: 'utf8' | 'base64';
|
|
122
|
+
path?: string;
|
|
123
|
+
}>;
|
|
124
|
+
}): Promise<Sandbox>;
|
|
125
|
+
static connect(client: SandboxClient, sandboxId: string): Promise<Sandbox>;
|
|
126
|
+
private normalizeLanguage;
|
|
127
|
+
runCode(script: string, options?: RunCodeOptions): Promise<ExecutionResult>;
|
|
128
|
+
kill(): Promise<void>;
|
|
129
|
+
betaPause(): Promise<void>;
|
|
130
|
+
setTimeout(ms: number): void;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
declare class SandboxRun {
|
|
134
|
+
private client;
|
|
135
|
+
readonly id: string;
|
|
136
|
+
readonly sandboxId?: string;
|
|
137
|
+
status: Status;
|
|
138
|
+
stdout?: string;
|
|
139
|
+
stderr?: string;
|
|
140
|
+
exitCode?: number;
|
|
141
|
+
errorMessage?: string;
|
|
142
|
+
durationMs?: number;
|
|
143
|
+
constructor(client: SandboxClient, data: RunResponse);
|
|
144
|
+
refresh(): Promise<this>;
|
|
145
|
+
waitForCompletion(options?: {
|
|
146
|
+
intervalMs?: number;
|
|
147
|
+
maxAttempts?: number;
|
|
148
|
+
}): Promise<this>;
|
|
149
|
+
get isComplete(): boolean;
|
|
150
|
+
get isSuccess(): boolean;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
declare class SandboxClient {
|
|
154
|
+
private apiUrl;
|
|
155
|
+
private auth;
|
|
156
|
+
private timeout;
|
|
157
|
+
constructor(config: SandboxConfig);
|
|
158
|
+
private fetch;
|
|
159
|
+
createRun(request: CreateRunRequest): Promise<SandboxRun>;
|
|
160
|
+
createRunAndWait(request: CreateRunRequest): Promise<SandboxRun>;
|
|
161
|
+
streamRun(request: CreateRunRequest): AsyncGenerator<StreamEvent>;
|
|
162
|
+
getRun(runId: string): Promise<SandboxRun>;
|
|
163
|
+
createSandbox(request?: CreateSandboxRequest): Promise<Sandbox>;
|
|
164
|
+
getSandboxStatus(sandboxId: string): Promise<{
|
|
165
|
+
sandboxId: string;
|
|
166
|
+
status: Status;
|
|
167
|
+
}>;
|
|
168
|
+
connectToSandbox(sandboxId: string): Promise<Sandbox>;
|
|
169
|
+
deleteSandbox(sandboxId: string): Promise<void>;
|
|
170
|
+
writeFile(sandboxId: string, path: string, content: string | Uint8Array): Promise<void>;
|
|
171
|
+
readFile(sandboxId: string, path: string, options?: FileReadOptions): Promise<string | Blob>;
|
|
172
|
+
fileExists(sandboxId: string, path: string): Promise<boolean>;
|
|
173
|
+
listFiles(sandboxId: string, directory?: string): Promise<string[]>;
|
|
174
|
+
deleteFile(sandboxId: string, path: string): Promise<void>;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
declare class DataTokenAuthStrategy implements AuthStrategy {
|
|
178
|
+
private dataToken;
|
|
179
|
+
constructor(dataToken: string);
|
|
180
|
+
getHeaders(): Headers;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
declare class FetchError extends Error {
|
|
184
|
+
readonly url: string;
|
|
185
|
+
readonly method: string;
|
|
186
|
+
readonly status: number;
|
|
187
|
+
readonly response?: unknown | undefined;
|
|
188
|
+
constructor(message: string, url: string, method: string, status: number, response?: unknown | undefined);
|
|
189
|
+
static from(url: string, method: string, res: Response): Promise<FetchError>;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
declare function sandbox(config: SandboxConfig): SandboxClient;
|
|
193
|
+
|
|
194
|
+
export { DataTokenAuthStrategy, FetchError, Sandbox, SandboxClient, SandboxRun, sandbox };
|
|
195
|
+
export type { AuthStrategy, CreateRunRequest, CreateSandboxRequest, ExecutionResult, FileInput, RunCodeOptions, RunResponse, SandboxCommands, SandboxConfig, SandboxFiles, Status, StreamCallbacks, StreamEvent };
|