ppio-sandbox 2.0.4-a2 → 2.1.0-a2

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.
@@ -0,0 +1,468 @@
1
+ import {
2
+ InvalidArgumentError,
3
+ NotFoundError,
4
+ Sandbox,
5
+ SandboxError,
6
+ TimeoutError,
7
+ __asyncGenerator,
8
+ __await,
9
+ __forAwait,
10
+ __spreadProps,
11
+ __spreadValues
12
+ } from "./chunk-46KYZWWN.mjs";
13
+
14
+ // src/code-interpreter/messaging.ts
15
+ async function extractError(res) {
16
+ if (res.ok) {
17
+ return;
18
+ }
19
+ switch (res.status) {
20
+ case 502:
21
+ return new TimeoutError(
22
+ `${await res.text()}: This error is likely due to sandbox timeout. You can modify the sandbox timeout by passing 'timeoutMs' when starting the sandbox or calling '.setTimeout' on the sandbox with the desired timeout.`
23
+ );
24
+ case 404:
25
+ return new NotFoundError(await res.text());
26
+ default:
27
+ return new SandboxError(`${res.status} ${res.statusText}`);
28
+ }
29
+ }
30
+ var ExecutionError = class {
31
+ constructor(name, value, traceback) {
32
+ this.name = name;
33
+ this.value = value;
34
+ this.traceback = traceback;
35
+ }
36
+ };
37
+ var Result = class {
38
+ constructor(rawData, isMainResult) {
39
+ this.isMainResult = isMainResult;
40
+ const data = __spreadValues({}, rawData);
41
+ delete data["type"];
42
+ delete data["is_main_result"];
43
+ this.text = data["text"];
44
+ this.html = data["html"];
45
+ this.markdown = data["markdown"];
46
+ this.svg = data["svg"];
47
+ this.png = data["png"];
48
+ this.jpeg = data["jpeg"];
49
+ this.pdf = data["pdf"];
50
+ this.latex = data["latex"];
51
+ this.json = data["json"];
52
+ this.javascript = data["javascript"];
53
+ this.isMainResult = isMainResult;
54
+ this.raw = data;
55
+ this.data = data["data"];
56
+ this.chart = data["chart"];
57
+ this.extra = {};
58
+ for (const key of Object.keys(data)) {
59
+ if (![
60
+ "plain",
61
+ "html",
62
+ "markdown",
63
+ "svg",
64
+ "png",
65
+ "jpeg",
66
+ "pdf",
67
+ "latex",
68
+ "json",
69
+ "javascript",
70
+ "data",
71
+ "chart",
72
+ "extra",
73
+ "text"
74
+ ].includes(key)) {
75
+ this.extra[key] = data[key];
76
+ }
77
+ }
78
+ }
79
+ /**
80
+ * Returns all the formats available for the result.
81
+ *
82
+ * @returns Array of strings representing the formats available for the result.
83
+ */
84
+ formats() {
85
+ const formats = [];
86
+ if (this.html) {
87
+ formats.push("html");
88
+ }
89
+ if (this.markdown) {
90
+ formats.push("markdown");
91
+ }
92
+ if (this.svg) {
93
+ formats.push("svg");
94
+ }
95
+ if (this.png) {
96
+ formats.push("png");
97
+ }
98
+ if (this.jpeg) {
99
+ formats.push("jpeg");
100
+ }
101
+ if (this.pdf) {
102
+ formats.push("pdf");
103
+ }
104
+ if (this.latex) {
105
+ formats.push("latex");
106
+ }
107
+ if (this.json) {
108
+ formats.push("json");
109
+ }
110
+ if (this.javascript) {
111
+ formats.push("javascript");
112
+ }
113
+ if (this.data) {
114
+ formats.push("data");
115
+ }
116
+ for (const key of Object.keys(this.extra)) {
117
+ formats.push(key);
118
+ }
119
+ return formats;
120
+ }
121
+ /**
122
+ * Returns the serializable representation of the result.
123
+ */
124
+ toJSON() {
125
+ return __spreadValues({
126
+ text: this.text,
127
+ html: this.html,
128
+ markdown: this.markdown,
129
+ svg: this.svg,
130
+ png: this.png,
131
+ jpeg: this.jpeg,
132
+ pdf: this.pdf,
133
+ latex: this.latex,
134
+ json: this.json,
135
+ javascript: this.javascript
136
+ }, Object.keys(this.extra).length > 0 ? { extra: this.extra } : {});
137
+ }
138
+ };
139
+ var Execution = class {
140
+ constructor(results = [], logs = { stdout: [], stderr: [] }, error, executionCount) {
141
+ this.results = results;
142
+ this.logs = logs;
143
+ this.error = error;
144
+ this.executionCount = executionCount;
145
+ }
146
+ /**
147
+ * Returns the text representation of the main result of the cell.
148
+ */
149
+ get text() {
150
+ for (const data of this.results) {
151
+ if (data.isMainResult) {
152
+ return data.text;
153
+ }
154
+ }
155
+ }
156
+ /**
157
+ * Returns the serializable representation of the execution result.
158
+ */
159
+ toJSON() {
160
+ return {
161
+ results: this.results,
162
+ logs: this.logs,
163
+ error: this.error
164
+ };
165
+ }
166
+ };
167
+ async function parseOutput(execution, line, onStdout, onStderr, onResult, onError) {
168
+ const msg = JSON.parse(line);
169
+ switch (msg.type) {
170
+ case "result":
171
+ const result = new Result(
172
+ __spreadProps(__spreadValues({}, msg), { type: void 0, is_main_result: void 0 }),
173
+ msg.is_main_result
174
+ );
175
+ execution.results.push(result);
176
+ if (onResult) {
177
+ await onResult(result);
178
+ }
179
+ break;
180
+ case "stdout":
181
+ execution.logs.stdout.push(msg.text);
182
+ if (onStdout) {
183
+ await onStdout({
184
+ error: false,
185
+ line: msg.text,
186
+ timestamp: (/* @__PURE__ */ new Date()).getTime() * 1e3
187
+ });
188
+ }
189
+ break;
190
+ case "stderr":
191
+ execution.logs.stderr.push(msg.text);
192
+ if (onStderr) {
193
+ await onStderr({
194
+ error: true,
195
+ line: msg.text,
196
+ timestamp: (/* @__PURE__ */ new Date()).getTime() * 1e3
197
+ });
198
+ }
199
+ break;
200
+ case "error":
201
+ execution.error = new ExecutionError(msg.name, msg.value, msg.traceback);
202
+ if (onError) {
203
+ await onError(execution.error);
204
+ }
205
+ break;
206
+ case "number_of_executions":
207
+ execution.executionCount = msg.execution_count;
208
+ break;
209
+ }
210
+ }
211
+
212
+ // src/code-interpreter/utils.ts
213
+ function formatRequestTimeoutError(error) {
214
+ if (error instanceof Error && error.name === "AbortError") {
215
+ return new TimeoutError("Request timed out \u2014 the 'requestTimeoutMs' option can be used to increase this timeout");
216
+ }
217
+ return error;
218
+ }
219
+ function formatExecutionTimeoutError(error) {
220
+ if (error instanceof Error && error.name === "AbortError") {
221
+ return new TimeoutError("Execution timed out \u2014 the 'timeoutMs' option can be used to increase this timeout");
222
+ }
223
+ return error;
224
+ }
225
+ function readLines(stream) {
226
+ return __asyncGenerator(this, null, function* () {
227
+ const reader = stream.getReader();
228
+ let buffer = "";
229
+ try {
230
+ while (true) {
231
+ const { done, value } = yield new __await(reader.read());
232
+ if (value !== void 0) {
233
+ buffer += new TextDecoder().decode(value);
234
+ }
235
+ if (done) {
236
+ if (buffer.length > 0) {
237
+ yield buffer;
238
+ }
239
+ break;
240
+ }
241
+ let newlineIdx = -1;
242
+ do {
243
+ newlineIdx = buffer.indexOf("\n");
244
+ if (newlineIdx !== -1) {
245
+ yield buffer.slice(0, newlineIdx);
246
+ buffer = buffer.slice(newlineIdx + 1);
247
+ }
248
+ } while (newlineIdx !== -1);
249
+ }
250
+ } finally {
251
+ reader.releaseLock();
252
+ }
253
+ });
254
+ }
255
+
256
+ // src/code-interpreter/consts.ts
257
+ var DEFAULT_TIMEOUT_MS = 6e4;
258
+ var JUPYTER_PORT = 49999;
259
+
260
+ // src/code-interpreter/sandbox.ts
261
+ var Sandbox2 = class extends Sandbox {
262
+ async runCode(code, opts) {
263
+ var _a, _b, _c;
264
+ if ((opts == null ? void 0 : opts.context) && (opts == null ? void 0 : opts.language)) {
265
+ throw new InvalidArgumentError(
266
+ "You can provide context or language, but not both at the same time."
267
+ );
268
+ }
269
+ const controller = new AbortController();
270
+ const requestTimeout = (_a = opts == null ? void 0 : opts.requestTimeoutMs) != null ? _a : this.connectionConfig.requestTimeoutMs;
271
+ const reqTimer = requestTimeout ? setTimeout(() => {
272
+ controller.abort();
273
+ }, requestTimeout) : void 0;
274
+ try {
275
+ const res = await fetch(`${this.jupyterUrl}/execute`, {
276
+ method: "POST",
277
+ headers: this.jupyterHeaders,
278
+ body: JSON.stringify({
279
+ code,
280
+ context_id: (_b = opts == null ? void 0 : opts.context) == null ? void 0 : _b.id,
281
+ language: opts == null ? void 0 : opts.language,
282
+ env_vars: opts == null ? void 0 : opts.envs
283
+ }),
284
+ signal: controller.signal,
285
+ keepalive: true
286
+ });
287
+ const error2 = await extractError(res);
288
+ if (error2) {
289
+ throw error2;
290
+ }
291
+ if (!res.body) {
292
+ throw new Error(
293
+ `Not response body: ${res.statusText} ${await (res == null ? void 0 : res.text())}`
294
+ );
295
+ }
296
+ clearTimeout(reqTimer);
297
+ const bodyTimeout = (_c = opts == null ? void 0 : opts.timeoutMs) != null ? _c : DEFAULT_TIMEOUT_MS;
298
+ const bodyTimer = bodyTimeout ? setTimeout(() => {
299
+ controller.abort();
300
+ }, bodyTimeout) : void 0;
301
+ const execution = new Execution();
302
+ try {
303
+ try {
304
+ for (var iter = __forAwait(readLines(res.body)), more, temp, error; more = !(temp = await iter.next()).done; more = false) {
305
+ const chunk = temp.value;
306
+ await parseOutput(
307
+ execution,
308
+ chunk,
309
+ opts == null ? void 0 : opts.onStdout,
310
+ opts == null ? void 0 : opts.onStderr,
311
+ opts == null ? void 0 : opts.onResult,
312
+ opts == null ? void 0 : opts.onError
313
+ );
314
+ }
315
+ } catch (temp) {
316
+ error = [temp];
317
+ } finally {
318
+ try {
319
+ more && (temp = iter.return) && await temp.call(iter);
320
+ } finally {
321
+ if (error)
322
+ throw error[0];
323
+ }
324
+ }
325
+ } catch (error3) {
326
+ throw formatExecutionTimeoutError(error3);
327
+ } finally {
328
+ clearTimeout(bodyTimer);
329
+ }
330
+ return execution;
331
+ } catch (error2) {
332
+ throw formatRequestTimeoutError(error2);
333
+ }
334
+ }
335
+ /**
336
+ * Creates a new context to run code in.
337
+ *
338
+ * @param opts options for creating the context.
339
+ *
340
+ * @returns context object.
341
+ */
342
+ async createCodeContext(opts) {
343
+ try {
344
+ const res = await fetch(`${this.jupyterUrl}/contexts`, {
345
+ method: "POST",
346
+ headers: this.jupyterHeaders,
347
+ body: JSON.stringify({
348
+ language: opts == null ? void 0 : opts.language,
349
+ cwd: opts == null ? void 0 : opts.cwd
350
+ }),
351
+ keepalive: true,
352
+ signal: this.connectionConfig.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
353
+ });
354
+ const error = await extractError(res);
355
+ if (error) {
356
+ throw error;
357
+ }
358
+ return await res.json();
359
+ } catch (error) {
360
+ throw formatRequestTimeoutError(error);
361
+ }
362
+ }
363
+ /**
364
+ * Lists all code execution contexts in the sandbox.
365
+ *
366
+ * @param opts options for the request.
367
+ *
368
+ * @returns array of context objects.
369
+ */
370
+ async listCodeContexts(opts) {
371
+ var _a;
372
+ try {
373
+ const res = await fetch(`${this.jupyterUrl}/contexts`, {
374
+ method: "GET",
375
+ headers: this.jupyterHeaders,
376
+ keepalive: true,
377
+ signal: this.connectionConfig.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
378
+ });
379
+ const error = await extractError(res);
380
+ if (error) {
381
+ throw error;
382
+ }
383
+ const data = await res.json();
384
+ return Array.isArray(data) ? data : (_a = data.contexts) != null ? _a : [];
385
+ } catch (error) {
386
+ throw formatRequestTimeoutError(error);
387
+ }
388
+ }
389
+ /**
390
+ * Removes a code execution context from the sandbox.
391
+ *
392
+ * @param context context object or context ID to remove.
393
+ * @param opts options for the request.
394
+ */
395
+ async removeCodeContext(context, opts) {
396
+ const contextID = typeof context === "string" ? context : context.id;
397
+ try {
398
+ const res = await fetch(
399
+ `${this.jupyterUrl}/contexts/${encodeURIComponent(contextID)}`,
400
+ {
401
+ method: "DELETE",
402
+ headers: this.jupyterHeaders,
403
+ keepalive: true,
404
+ signal: this.connectionConfig.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
405
+ }
406
+ );
407
+ const error = await extractError(res);
408
+ if (error) {
409
+ throw error;
410
+ }
411
+ } catch (error) {
412
+ throw formatRequestTimeoutError(error);
413
+ }
414
+ }
415
+ /**
416
+ * Restarts a code execution context in the sandbox.
417
+ *
418
+ * @param context context object or context ID to restart.
419
+ * @param opts options for the request.
420
+ */
421
+ async restartCodeContext(context, opts) {
422
+ const contextID = typeof context === "string" ? context : context.id;
423
+ try {
424
+ const res = await fetch(
425
+ `${this.jupyterUrl}/contexts/${encodeURIComponent(contextID)}/restart`,
426
+ {
427
+ method: "POST",
428
+ headers: this.jupyterHeaders,
429
+ keepalive: true,
430
+ signal: this.connectionConfig.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
431
+ }
432
+ );
433
+ const error = await extractError(res);
434
+ if (error) {
435
+ throw error;
436
+ }
437
+ } catch (error) {
438
+ throw formatRequestTimeoutError(error);
439
+ }
440
+ }
441
+ /**
442
+ * Deletes a code execution context from the sandbox.
443
+ *
444
+ * Alias for {@link removeCodeContext}.
445
+ *
446
+ * @param context context object or context ID to delete.
447
+ * @param opts options for the request.
448
+ */
449
+ async deleteCodeContext(context, opts) {
450
+ return this.removeCodeContext(context, opts);
451
+ }
452
+ get jupyterHeaders() {
453
+ return __spreadValues(__spreadValues(__spreadValues({
454
+ "Content-Type": "application/json"
455
+ }, this.connectionConfig.headers), this.envdAccessToken ? { "X-Access-Token": this.envdAccessToken } : {}), this.trafficAccessToken ? { "E2B-Traffic-Access-Token": this.trafficAccessToken } : {});
456
+ }
457
+ get jupyterUrl() {
458
+ return `${this.connectionConfig.debug ? "http" : "https"}://${this.getHost(
459
+ JUPYTER_PORT
460
+ )}`;
461
+ }
462
+ };
463
+ Sandbox2.defaultTemplate = "code-interpreter-v1";
464
+
465
+ export {
466
+ Sandbox2 as Sandbox
467
+ };
468
+ //# sourceMappingURL=chunk-T5IKSUZH.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/code-interpreter/messaging.ts","../src/code-interpreter/utils.ts","../src/code-interpreter/consts.ts","../src/code-interpreter/sandbox.ts"],"sourcesContent":["import { NotFoundError, SandboxError, TimeoutError } from '../core'\nimport { ChartTypes } from './charts'\n\nexport async function extractError(res: Response) {\n if (res.ok) {\n return\n }\n\n switch (res.status) {\n case 502:\n return new TimeoutError(\n `${await res.text()}: This error is likely due to sandbox timeout. You can modify the sandbox timeout by passing 'timeoutMs' when starting the sandbox or calling '.setTimeout' on the sandbox with the desired timeout.`\n )\n case 404:\n return new NotFoundError(await res.text())\n default:\n return new SandboxError(`${res.status} ${res.statusText}`)\n }\n}\n\n/**\n * Represents an output message from the sandbox code execution.\n */\nexport class OutputMessage {\n constructor(\n /**\n * The output line.\n */\n public readonly line: string,\n /**\n * Unix epoch in nanoseconds.\n */\n public readonly timestamp: number,\n /**\n * Whether the output is an error.\n */\n public readonly error: boolean\n ) { }\n\n public toString() {\n return this.line\n }\n}\n\n/**\n * Represents an error that occurred during the execution of a cell.\n * The error contains the name of the error, the value of the error, and the traceback.\n */\nexport class ExecutionError {\n constructor(\n /**\n * Name of the error.\n **/\n public name: string,\n /**\n * Value of the error.\n **/\n public value: string,\n /**\n * The raw traceback of the error.\n **/\n public traceback: string\n ) { }\n}\n\n/**\n * Represents a MIME type.\n */\nexport type MIMEType = string\n\n\ntype PPIOSandboxData = {\n data: Record<string, unknown>\n chart: ChartTypes\n}\n\n/**\n * Dictionary that maps MIME types to their corresponding representations of the data.\n */\nexport type RawData = {\n [key: MIMEType]: string\n} & PPIOSandboxData\n\n/**\n * Represents the data to be displayed as a result of executing a cell in a Jupyter notebook.\n * The result is similar to the structure returned by ipython kernel: https://ipython.readthedocs.io/en/stable/development/execution.html#execution-semantics\n *\n *\n * The result can contain multiple types of data, such as text, images, plots, etc. Each type of data is represented\n * as a string, and the result can contain multiple types of data. The display calls don't have to have text representation,\n * for the actual result the representation is always present for the result, the other representations are always optional.\n */\nexport class Result {\n /**\n * Text representation of the result.\n */\n readonly text?: string\n /**\n * HTML representation of the data.\n */\n readonly html?: string\n /**\n * Markdown representation of the data.\n */\n readonly markdown?: string\n /**\n * SVG representation of the data.\n */\n readonly svg?: string\n /**\n * PNG representation of the data.\n */\n readonly png?: string\n /**\n * JPEG representation of the data.\n */\n readonly jpeg?: string\n /**\n * PDF representation of the data.\n */\n readonly pdf?: string\n /**\n * LaTeX representation of the data.\n */\n readonly latex?: string\n /**\n * JSON representation of the data.\n */\n readonly json?: string\n /**\n * JavaScript representation of the data.\n */\n readonly javascript?: string\n /**\n * Contains the data from DataFrame.\n */\n readonly data?: Record<string, unknown>\n /**\n * Contains the chart data.\n */\n readonly chart?: ChartTypes\n /**\n * Extra data that can be included. Not part of the standard types.\n */\n readonly extra?: any\n\n readonly raw: RawData\n\n constructor(rawData: RawData, public readonly isMainResult: boolean) {\n const data = { ...rawData }\n delete data['type']\n delete data['is_main_result']\n\n this.text = data['text']\n this.html = data['html']\n this.markdown = data['markdown']\n this.svg = data['svg']\n this.png = data['png']\n this.jpeg = data['jpeg']\n this.pdf = data['pdf']\n this.latex = data['latex']\n this.json = data['json']\n this.javascript = data['javascript']\n this.isMainResult = isMainResult\n this.raw = data\n\n this.data = data['data']\n this.chart = data['chart']\n\n this.extra = {}\n\n for (const key of Object.keys(data)) {\n if (\n ![\n 'plain',\n 'html',\n 'markdown',\n 'svg',\n 'png',\n 'jpeg',\n 'pdf',\n 'latex',\n 'json',\n 'javascript',\n 'data',\n 'chart',\n 'extra',\n \"text\"\n ].includes(key)\n ) {\n this.extra[key] = data[key]\n }\n }\n }\n\n /**\n * Returns all the formats available for the result.\n *\n * @returns Array of strings representing the formats available for the result.\n */\n formats(): string[] {\n const formats = []\n if (this.html) {\n formats.push('html')\n }\n if (this.markdown) {\n formats.push('markdown')\n }\n if (this.svg) {\n formats.push('svg')\n }\n if (this.png) {\n formats.push('png')\n }\n if (this.jpeg) {\n formats.push('jpeg')\n }\n if (this.pdf) {\n formats.push('pdf')\n }\n if (this.latex) {\n formats.push('latex')\n }\n if (this.json) {\n formats.push('json')\n }\n if (this.javascript) {\n formats.push('javascript')\n }\n if (this.data) {\n formats.push('data')\n }\n\n for (const key of Object.keys(this.extra)) {\n formats.push(key)\n }\n\n return formats\n }\n\n /**\n * Returns the serializable representation of the result.\n */\n toJSON() {\n return {\n text: this.text,\n html: this.html,\n markdown: this.markdown,\n svg: this.svg,\n png: this.png,\n jpeg: this.jpeg,\n pdf: this.pdf,\n latex: this.latex,\n json: this.json,\n javascript: this.javascript,\n ...(Object.keys(this.extra).length > 0 ? { extra: this.extra } : {}),\n }\n }\n}\n\n/**\n * Data printed to stdout and stderr during execution, usually by print statements, logs, warnings, subprocesses, etc.\n */\nexport type Logs = {\n /**\n * List of strings printed to stdout by prints, subprocesses, etc.\n */\n stdout: string[]\n /**\n * List of strings printed to stderr by prints, subprocesses, etc.\n */\n stderr: string[]\n}\n\n/**\n * Represents the result of a cell execution.\n */\nexport class Execution {\n constructor(\n /**\n * List of result of the cell (interactively interpreted last line), display calls (e.g. matplotlib plots).\n */\n public results: Result[] = [],\n /**\n * Logs printed to stdout and stderr during execution.\n */\n public logs: Logs = { stdout: [], stderr: [] },\n /**\n * An Error object if an error occurred, null otherwise.\n */\n public error?: ExecutionError,\n /**\n * Execution count of the cell.\n */\n public executionCount?: number\n ) { }\n\n /**\n * Returns the text representation of the main result of the cell.\n */\n get text(): string | undefined {\n for (const data of this.results) {\n if (data.isMainResult) {\n return data.text\n }\n }\n }\n\n /**\n * Returns the serializable representation of the execution result.\n */\n toJSON() {\n return {\n results: this.results,\n logs: this.logs,\n error: this.error,\n }\n }\n}\n\nexport async function parseOutput(\n execution: Execution,\n line: string,\n onStdout?: (output: OutputMessage) => Promise<any> | any,\n onStderr?: (output: OutputMessage) => Promise<any> | any,\n onResult?: (data: Result) => Promise<any> | any,\n onError?: (error: ExecutionError) => Promise<any> | any\n) {\n const msg = JSON.parse(line)\n\n switch (msg.type) {\n case 'result':\n const result = new Result(\n { ...msg, type: undefined, is_main_result: undefined },\n msg.is_main_result\n )\n execution.results.push(result)\n if (onResult) {\n await onResult(result)\n }\n break\n case 'stdout':\n execution.logs.stdout.push(msg.text)\n if (onStdout) {\n await onStdout({\n error: false,\n line: msg.text,\n timestamp: new Date().getTime() * 1000,\n })\n }\n break\n case 'stderr':\n execution.logs.stderr.push(msg.text)\n if (onStderr) {\n await onStderr({\n error: true,\n line: msg.text,\n timestamp: new Date().getTime() * 1000,\n })\n }\n break\n case 'error':\n execution.error = new ExecutionError(msg.name, msg.value, msg.traceback)\n if (onError) {\n await onError(execution.error)\n }\n break\n case 'number_of_executions':\n execution.executionCount = msg.execution_count\n break\n }\n}\n","import { TimeoutError } from '../core'\n\nexport function formatRequestTimeoutError(error: unknown) {\n if (error instanceof Error && error.name === 'AbortError') {\n return new TimeoutError('Request timed out — the \\'requestTimeoutMs\\' option can be used to increase this timeout')\n }\n\n return error\n}\n\nexport function formatExecutionTimeoutError(error: unknown) {\n if (error instanceof Error && error.name === 'AbortError') {\n return new TimeoutError('Execution timed out — the \\'timeoutMs\\' option can be used to increase this timeout')\n }\n\n return error\n}\n\nexport async function* readLines(stream: ReadableStream<Uint8Array>) {\n const reader = stream.getReader();\n let buffer = ''\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n\n if (value !== undefined) {\n buffer += new TextDecoder().decode(value)\n }\n\n if (done) {\n if (buffer.length > 0) {\n yield buffer\n }\n break\n }\n\n let newlineIdx = -1\n\n do {\n newlineIdx = buffer.indexOf('\\n')\n if (newlineIdx !== -1) {\n yield buffer.slice(0, newlineIdx)\n buffer = buffer.slice(newlineIdx + 1)\n }\n } while (newlineIdx !== -1)\n }\n } finally {\n reader.releaseLock()\n }\n}\n","export const DEFAULT_TIMEOUT_MS = 60_000 // 1 minute\nexport const JUPYTER_PORT = 49999\n","import { Sandbox as BaseSandbox, InvalidArgumentError } from '../core'\n\nimport {\n Result,\n Execution,\n OutputMessage,\n parseOutput,\n extractError,\n ExecutionError,\n} from './messaging'\nimport {\n formatExecutionTimeoutError,\n formatRequestTimeoutError,\n readLines,\n} from './utils'\nimport { JUPYTER_PORT, DEFAULT_TIMEOUT_MS } from './consts'\n\n/**\n * Represents a context for code execution.\n */\nexport type Context = {\n /**\n * The ID of the context.\n */\n id: string\n /**\n * The language of the context.\n */\n language: string\n /**\n * The working directory of the context.\n */\n cwd: string\n}\n\n/**\n * Options for running code.\n */\nexport interface RunCodeOpts {\n /**\n * Callback for handling stdout messages.\n */\n onStdout?: (output: OutputMessage) => Promise<any> | any\n /**\n * Callback for handling stderr messages.\n */\n onStderr?: (output: OutputMessage) => Promise<any> | any\n /**\n * Callback for handling the final execution result.\n */\n onResult?: (data: Result) => Promise<any> | any\n /**\n * Callback for handling the `ExecutionError` object.\n */\n onError?: (error: ExecutionError) => Promise<any> | any\n /**\n * Custom environment variables for code execution.\n *\n * @default {}\n */\n envs?: Record<string, string>\n /**\n * Timeout for the code execution in **milliseconds**.\n *\n * @default 60_000 // 60 seconds\n */\n timeoutMs?: number\n /**\n * Timeout for the request in **milliseconds**.\n *\n * @default 30_000 // 30 seconds\n */\n requestTimeoutMs?: number\n}\n\n/**\n * Options for creating a code context.\n */\nexport interface CreateCodeContextOpts {\n /**\n * Working directory for the context.\n *\n * @default /home/user\n */\n cwd?: string\n /**\n * Language for the context.\n *\n * @default python\n */\n language?: string\n /**\n * Timeout for the request in **milliseconds**.\n *\n * @default 30_000 // 30 seconds\n */\n requestTimeoutMs?: number\n}\n\n/**\n * Options for code context management requests.\n */\nexport interface CodeContextRequestOpts {\n /**\n * Timeout for the request in **milliseconds**.\n *\n * @default 30_000 // 30 seconds\n */\n requestTimeoutMs?: number\n}\n\n/**\n * PPIO agent sandbox is a secure and isolated cloud environment.\n *\n * The sandbox allows you to:\n * - Access Linux OS\n * - Create, list, and delete files and directories\n * - Run commands\n * - Run isolated code\n * - Access the internet\n *\n * Check docs [here](https://ppio.com/docs/sandbox/overview).\n *\n * Use {@link Sandbox.create} to create a new sandbox.\n *\n * @example\n * ```ts\n * import { Sandbox } from '@ppio-sandbox/code-interpreter'\n *\n * const sandbox = await Sandbox.create()\n * ```\n */\nexport class Sandbox extends BaseSandbox {\n protected static override readonly defaultTemplate: string =\n 'code-interpreter-v1'\n\n /**\n * Run the code as Python.\n *\n * Specify the `language` or `context` option to run the code as a different language or in a different `Context`.\n *\n * You can reference previously defined variables, imports, and functions in the code.\n *\n * @param code code to execute.\n * @param opts options for executing the code.\n *\n * @returns `Execution` result object.\n */\n async runCode(\n code: string,\n opts?: RunCodeOpts & {\n /**\n * Language to use for code execution.\n *\n * If not defined, the default Python context is used.\n */\n language?: 'python'\n }\n ): Promise<Execution>\n /**\n * Run the code for the specified language.\n *\n * Specify the `language` or `context` option to run the code as a different language or in a different `Context`.\n * If no language is specified, Python is used.\n *\n * You can reference previously defined variables, imports, and functions in the code.\n *\n * @param code code to execute.\n * @param opts options for executing the code.\n *\n * @returns `Execution` result object.\n */\n async runCode(\n code: string,\n opts?: RunCodeOpts & {\n /**\n * Language to use for code execution.\n *\n * If not defined, the default Python context is used.\n */\n language?: string\n }\n ): Promise<Execution>\n /**\n * Runs the code in the specified context, if not specified, the default context is used.\n *\n * Specify the `language` or `context` option to run the code as a different language or in a different `Context`.\n *\n * You can reference previously defined variables, imports, and functions in the code.\n *\n * @param code code to execute.\n * @param opts options for executing the code\n *\n * @returns `Execution` result object\n */\n async runCode(\n code: string,\n opts?: RunCodeOpts & {\n /**\n * Context to run the code in.\n */\n context?: Context\n }\n ): Promise<Execution>\n async runCode(\n code: string,\n opts?: RunCodeOpts & {\n language?: string\n context?: Context\n }\n ): Promise<Execution> {\n if (opts?.context && opts?.language) {\n throw new InvalidArgumentError(\n 'You can provide context or language, but not both at the same time.'\n )\n }\n\n const controller = new AbortController()\n\n const requestTimeout =\n opts?.requestTimeoutMs ?? this.connectionConfig.requestTimeoutMs\n\n const reqTimer = requestTimeout\n ? setTimeout(() => {\n controller.abort()\n }, requestTimeout)\n : undefined\n\n try {\n const res = await fetch(`${this.jupyterUrl}/execute`, {\n method: 'POST',\n headers: this.jupyterHeaders,\n body: JSON.stringify({\n code,\n context_id: opts?.context?.id,\n language: opts?.language,\n env_vars: opts?.envs,\n }),\n signal: controller.signal,\n keepalive: true,\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n\n if (!res.body) {\n throw new Error(\n `Not response body: ${res.statusText} ${await res?.text()}`\n )\n }\n\n clearTimeout(reqTimer)\n\n const bodyTimeout = opts?.timeoutMs ?? DEFAULT_TIMEOUT_MS\n\n const bodyTimer = bodyTimeout\n ? setTimeout(() => {\n controller.abort()\n }, bodyTimeout)\n : undefined\n\n const execution = new Execution()\n\n try {\n for await (const chunk of readLines(res.body)) {\n await parseOutput(\n execution,\n chunk,\n opts?.onStdout,\n opts?.onStderr,\n opts?.onResult,\n opts?.onError\n )\n }\n } catch (error) {\n throw formatExecutionTimeoutError(error)\n } finally {\n clearTimeout(bodyTimer)\n }\n\n return execution\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Creates a new context to run code in.\n *\n * @param opts options for creating the context.\n *\n * @returns context object.\n */\n async createCodeContext(opts?: CreateCodeContextOpts): Promise<Context> {\n try {\n const res = await fetch(`${this.jupyterUrl}/contexts`, {\n method: 'POST',\n headers: this.jupyterHeaders,\n body: JSON.stringify({\n language: opts?.language,\n cwd: opts?.cwd,\n }),\n keepalive: true,\n signal: this.connectionConfig.getSignal(opts?.requestTimeoutMs),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n\n return (await res.json()) as Context\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Lists all code execution contexts in the sandbox.\n *\n * @param opts options for the request.\n *\n * @returns array of context objects.\n */\n async listCodeContexts(opts?: CodeContextRequestOpts): Promise<Context[]> {\n try {\n const res = await fetch(`${this.jupyterUrl}/contexts`, {\n method: 'GET',\n headers: this.jupyterHeaders,\n keepalive: true,\n signal: this.connectionConfig.getSignal(opts?.requestTimeoutMs),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n\n const data = await res.json()\n return Array.isArray(data) ? data : (data.contexts ?? [])\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Removes a code execution context from the sandbox.\n *\n * @param context context object or context ID to remove.\n * @param opts options for the request.\n */\n async removeCodeContext(\n context: Context | string,\n opts?: CodeContextRequestOpts\n ): Promise<void> {\n const contextID = typeof context === 'string' ? context : context.id\n\n try {\n const res = await fetch(\n `${this.jupyterUrl}/contexts/${encodeURIComponent(contextID)}`,\n {\n method: 'DELETE',\n headers: this.jupyterHeaders,\n keepalive: true,\n signal: this.connectionConfig.getSignal(opts?.requestTimeoutMs),\n }\n )\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Restarts a code execution context in the sandbox.\n *\n * @param context context object or context ID to restart.\n * @param opts options for the request.\n */\n async restartCodeContext(\n context: Context | string,\n opts?: CodeContextRequestOpts\n ): Promise<void> {\n const contextID = typeof context === 'string' ? context : context.id\n\n try {\n const res = await fetch(\n `${this.jupyterUrl}/contexts/${encodeURIComponent(contextID)}/restart`,\n {\n method: 'POST',\n headers: this.jupyterHeaders,\n keepalive: true,\n signal: this.connectionConfig.getSignal(opts?.requestTimeoutMs),\n }\n )\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Deletes a code execution context from the sandbox.\n *\n * Alias for {@link removeCodeContext}.\n *\n * @param context context object or context ID to delete.\n * @param opts options for the request.\n */\n async deleteCodeContext(\n context: Context | string,\n opts?: CodeContextRequestOpts\n ): Promise<void> {\n return this.removeCodeContext(context, opts)\n }\n\n private get jupyterHeaders(): Record<string, string> {\n return {\n 'Content-Type': 'application/json',\n ...this.connectionConfig.headers,\n ...(this.envdAccessToken\n ? { 'X-Access-Token': this.envdAccessToken }\n : {}),\n ...(this.trafficAccessToken\n ? { 'E2B-Traffic-Access-Token': this.trafficAccessToken }\n : {}),\n }\n }\n\n protected get jupyterUrl(): string {\n return `${this.connectionConfig.debug ? 'http' : 'https'}://${this.getHost(\n JUPYTER_PORT\n )}`\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAGA,eAAsB,aAAa,KAAe;AAChD,MAAI,IAAI,IAAI;AACV;AAAA,EACF;AAEA,UAAQ,IAAI,QAAQ;AAAA,IAClB,KAAK;AACH,aAAO,IAAI;AAAA,QACT,GAAG,MAAM,IAAI,KAAK,CAAC;AAAA,MACrB;AAAA,IACF,KAAK;AACH,aAAO,IAAI,cAAc,MAAM,IAAI,KAAK,CAAC;AAAA,IAC3C;AACE,aAAO,IAAI,aAAa,GAA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