@e2b/code-interpreter 0.0.9-beta.70 → 0.0.9-beta.71
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/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConnectionConfig, Sandbox } from 'e2b';
|
|
1
|
+
import { ConnectionConfig, Sandbox as Sandbox$1 } from 'e2b';
|
|
2
2
|
export * from 'e2b';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -387,10 +387,10 @@ declare class JupyterExtension {
|
|
|
387
387
|
/**
|
|
388
388
|
* Code interpreter module for executing code in a stateful context.
|
|
389
389
|
*/
|
|
390
|
-
declare class
|
|
390
|
+
declare class Sandbox extends Sandbox$1 {
|
|
391
391
|
protected static readonly defaultTemplate: string;
|
|
392
392
|
protected static readonly jupyterPort = 49999;
|
|
393
393
|
readonly notebook: JupyterExtension;
|
|
394
394
|
}
|
|
395
395
|
|
|
396
|
-
export { type BarData, type BarGraph, type BoxAndWhiskerData, type BoxAndWhiskerGraph,
|
|
396
|
+
export { type BarData, type BarGraph, type BoxAndWhiskerData, type BoxAndWhiskerGraph, Execution, ExecutionError, type Graph, GraphType, type GraphTypes, JupyterExtension, type LineGraph, type Logs, type MIMEType, OutputMessage, type PieData, type PieGraph, type PointData, type RawData, Result, Sandbox, ScaleType, type ScatterGraph, type SuperGraph, Sandbox as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConnectionConfig, Sandbox } from 'e2b';
|
|
1
|
+
import { ConnectionConfig, Sandbox as Sandbox$1 } from 'e2b';
|
|
2
2
|
export * from 'e2b';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -387,10 +387,10 @@ declare class JupyterExtension {
|
|
|
387
387
|
/**
|
|
388
388
|
* Code interpreter module for executing code in a stateful context.
|
|
389
389
|
*/
|
|
390
|
-
declare class
|
|
390
|
+
declare class Sandbox extends Sandbox$1 {
|
|
391
391
|
protected static readonly defaultTemplate: string;
|
|
392
392
|
protected static readonly jupyterPort = 49999;
|
|
393
393
|
readonly notebook: JupyterExtension;
|
|
394
394
|
}
|
|
395
395
|
|
|
396
|
-
export { type BarData, type BarGraph, type BoxAndWhiskerData, type BoxAndWhiskerGraph,
|
|
396
|
+
export { type BarData, type BarGraph, type BoxAndWhiskerData, type BoxAndWhiskerGraph, Execution, ExecutionError, type Graph, GraphType, type GraphTypes, JupyterExtension, type LineGraph, type Logs, type MIMEType, OutputMessage, type PieData, type PieGraph, type PointData, type RawData, Result, Sandbox, ScaleType, type ScatterGraph, type SuperGraph, Sandbox as default };
|
package/dist/index.js
CHANGED
|
@@ -75,14 +75,14 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
|
|
|
75
75
|
// src/index.ts
|
|
76
76
|
var src_exports = {};
|
|
77
77
|
__export(src_exports, {
|
|
78
|
-
CodeInterpreter: () => CodeInterpreter,
|
|
79
78
|
JupyterExtension: () => JupyterExtension,
|
|
79
|
+
Sandbox: () => Sandbox,
|
|
80
80
|
default: () => src_default
|
|
81
81
|
});
|
|
82
82
|
module.exports = __toCommonJS(src_exports);
|
|
83
83
|
__reExport(src_exports, require("e2b"), module.exports);
|
|
84
84
|
|
|
85
|
-
// src/
|
|
85
|
+
// src/sandbox.ts
|
|
86
86
|
var import_e2b2 = require("e2b");
|
|
87
87
|
|
|
88
88
|
// src/messaging.ts
|
|
@@ -283,7 +283,7 @@ function parseOutput(execution, line, onStdout, onStderr, onResult) {
|
|
|
283
283
|
});
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
-
// src/
|
|
286
|
+
// src/sandbox.ts
|
|
287
287
|
function formatRequestTimeoutError(error) {
|
|
288
288
|
if (error instanceof Error && error.name === "AbortError") {
|
|
289
289
|
return new import_e2b2.TimeoutError("Request timed out \u2014 the 'requestTimeoutMs' option can be used to increase this timeout");
|
|
@@ -533,25 +533,25 @@ var _JupyterExtension = class _JupyterExtension {
|
|
|
533
533
|
_JupyterExtension.execTimeoutMs = 3e5;
|
|
534
534
|
_JupyterExtension.defaultKernelID = "default";
|
|
535
535
|
var JupyterExtension = _JupyterExtension;
|
|
536
|
-
var
|
|
536
|
+
var _Sandbox = class _Sandbox extends import_e2b2.Sandbox {
|
|
537
537
|
constructor() {
|
|
538
538
|
super(...arguments);
|
|
539
539
|
this.notebook = new JupyterExtension(
|
|
540
|
-
`${this.connectionConfig.debug ? "http" : "https"}://${this.getHost(
|
|
540
|
+
`${this.connectionConfig.debug ? "http" : "https"}://${this.getHost(_Sandbox.jupyterPort)}`,
|
|
541
541
|
this.connectionConfig
|
|
542
542
|
);
|
|
543
543
|
}
|
|
544
544
|
};
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
var
|
|
545
|
+
_Sandbox.defaultTemplate = "code-interpreter-beta";
|
|
546
|
+
_Sandbox.jupyterPort = 49999;
|
|
547
|
+
var Sandbox = _Sandbox;
|
|
548
548
|
|
|
549
549
|
// src/index.ts
|
|
550
|
-
var src_default =
|
|
550
|
+
var src_default = Sandbox;
|
|
551
551
|
// Annotate the CommonJS export names for ESM import in node:
|
|
552
552
|
0 && (module.exports = {
|
|
553
|
-
CodeInterpreter,
|
|
554
553
|
JupyterExtension,
|
|
554
|
+
Sandbox,
|
|
555
555
|
...require("e2b")
|
|
556
556
|
});
|
|
557
557
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/codeInterpreter.ts","../src/messaging.ts"],"sourcesContent":["export * from 'e2b'\n\nexport { CodeInterpreter, JupyterExtension } from './codeInterpreter'\n\nexport type {\n Logs,\n ExecutionError,\n Result,\n Execution,\n MIMEType,\n RawData,\n OutputMessage,\n} from './messaging'\nexport type {\n ScaleType,\n GraphType,\n GraphTypes,\n Graph,\n BarGraph,\n BarData,\n LineGraph,\n ScatterGraph,\n BoxAndWhiskerGraph,\n BoxAndWhiskerData,\n PieGraph,\n PieData,\n SuperGraph,\n PointData,\n} from './graphs'\nimport { CodeInterpreter } from './codeInterpreter'\n\nexport default CodeInterpreter\n","import { ConnectionConfig, Sandbox, TimeoutError } from 'e2b'\n\nimport { Result, Execution, OutputMessage, parseOutput, extractError } from './messaging'\n\nfunction 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\nfunction 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\nasync 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\n/**\n * Code interpreter module for executing code in a stateful context.\n */\nexport class JupyterExtension {\n private static readonly execTimeoutMs = 300_000\n private static readonly defaultKernelID = 'default'\n\n constructor(private readonly url: string, private readonly connectionConfig: ConnectionConfig) { }\n\n /**\n * Runs the code in the specified context, if not specified, the default context is used.\n * You can reference previously defined variables, imports, and functions in the code.\n *\n * @param code The code to execute\n * @param opts Options for executing the code\n * @param opts.kernelID The context ID to run the code in\n * @param opts.onStdout Callback for handling stdout messages\n * @param opts.onStderr Callback for handling stderr messages\n * @param opts.onResult Callback for handling the final result\n * @param opts.envs Environment variables to set for the execution\n * @param opts.timeoutMs Max time to wait for the execution to finish\n * @param opts.requestTimeoutMs Max time to wait for the request to finish\n * @returns Execution object\n */\n async execCell(\n code: string,\n opts?: {\n kernelID?: string,\n onStdout?: (output: OutputMessage) => (Promise<any> | any),\n onStderr?: (output: OutputMessage) => (Promise<any> | any),\n onResult?: (data: Result) => (Promise<any> | any),\n envs?: Record<string, string>,\n timeoutMs?: number,\n requestTimeoutMs?: number,\n },\n ): Promise<Execution> {\n const controller = new AbortController()\n\n const requestTimeout = opts?.requestTimeoutMs ?? this.connectionConfig.requestTimeoutMs\n\n const reqTimer = requestTimeout ? setTimeout(() => {\n controller.abort()\n }, requestTimeout)\n : undefined\n\n try {\n const res = await fetch(`${this.url}/execute`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n code,\n context_id: opts?.kernelID,\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(`Not response body: ${res.statusText} ${await res?.text()}`)\n }\n\n clearTimeout(reqTimer)\n\n const bodyTimeout = opts?.timeoutMs ?? JupyterExtension.execTimeoutMs\n\n const bodyTimer = bodyTimeout\n ? setTimeout(() => {\n controller.abort()\n }, bodyTimeout)\n : undefined\n\n const execution = new Execution()\n\n\n try {\n for await (const chunk of readLines(res.body)) {\n await parseOutput(execution, chunk, opts?.onStdout, opts?.onStderr, opts?.onResult)\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 cwd The working directory for the context\n * @param kernelName The name of the context\n * @param requestTimeoutMs Max time to wait for the request to finish\n * @returns The context ID\n */\n async createKernel({\n cwd,\n kernelName,\n requestTimeoutMs,\n }: {\n cwd?: string,\n kernelName?: string,\n requestTimeoutMs?: number,\n } = {}): Promise<string> {\n try {\n\n const res = await fetch(`${this.url}/contexts`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n name: kernelName,\n cwd,\n }),\n keepalive: true,\n signal: this.connectionConfig.getSignal(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 data.id\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Restarts the context.\n * Restarting will clear all variables, imports, and other settings set during previous executions.\n *\n * @param kernelID The context ID to restart\n * @param requestTimeoutMs Max time to wait for the request to finish\n */\n async restartKernel({\n kernelID,\n requestTimeoutMs,\n }: {\n kernelID?: string,\n requestTimeoutMs?: number,\n } = {}): Promise<void> {\n try {\n kernelID = kernelID || JupyterExtension.defaultKernelID\n const res = await fetch(`${this.url}/contexts/${kernelID}/restart`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n keepalive: true,\n signal: this.connectionConfig.getSignal(requestTimeoutMs),\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 * Shuts down the context.\n *\n * @param kernelID The context ID to shut down\n * @param requestTimeoutMs Max time to wait for the request to finish\n */\n async shutdownKernel({\n kernelID,\n requestTimeoutMs,\n }: {\n kernelID?: string,\n requestTimeoutMs?: number,\n } = {}): Promise<void> {\n try {\n\n kernelID = kernelID || JupyterExtension.defaultKernelID\n\n const res = await fetch(`${this.url}/contexts/${kernelID}`, {\n method: 'DELETE',\n keepalive: true,\n signal: this.connectionConfig.getSignal(requestTimeoutMs),\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 * Lists all available contexts.\n *\n * @param requestTimeoutMs Max time to wait for the request to finish\n * @returns List of context IDs and names\n */\n async listKernels({\n requestTimeoutMs,\n }: {\n requestTimeoutMs?: number,\n } = {}): Promise<{ kernelID: string, name: string }[]> {\n try {\n const res = await fetch(`${this.url}/contexts`, {\n keepalive: true,\n signal: this.connectionConfig.getSignal(requestTimeoutMs),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n\n return (await res.json()).map((kernel: any) => ({ kernelID: kernel.id, name: kernel.name }))\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n}\n\n/**\n * Code interpreter module for executing code in a stateful context.\n */\nexport class CodeInterpreter extends Sandbox {\n protected static override readonly defaultTemplate: string = 'code-interpreter-beta'\n protected static readonly jupyterPort = 49999\n\n readonly notebook = new JupyterExtension(\n `${this.connectionConfig.debug ? 'http' : 'https'}://${this.getHost(CodeInterpreter.jupyterPort)}`,\n this.connectionConfig,\n )\n}\n","import { NotFoundError, SandboxError, TimeoutError } from 'e2b'\nimport { GraphTypes } from './graphs'\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\nexport class OutputMessage {\n constructor(\n public readonly line: string,\n /**\n * Unix epoch in nanoseconds\n */\n public readonly timestamp: number,\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\ntype E2BData = {\n data: Record<string, unknown>\n graph: GraphTypes\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} & E2BData\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 graph data.\n */\n readonly graph?: GraphTypes\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.graph = data['graph']\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 'extra',\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) {\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 break\n case 'number_of_executions':\n execution.executionCount = msg.execution_count\n break\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,gBAAd;;;ACAA,IAAAA,cAAwD;;;ACAxD,iBAA0D;AAG1D,SAAsB,aAAa,KAAe;AAAA;AAChD,QAAI,IAAI,IAAI;AACV;AAAA,IACF;AAEA,YAAQ,IAAI,QAAQ;AAAA,MAClB,KAAK;AACH,eAAO,IAAI;AAAA,UACT,GAAG,MAAM,IAAI,KAAK,CAAC;AAAA,QACrB;AAAA,MACF,KAAK;AACH,eAAO,IAAI,yBAAc,MAAM,IAAI,KAAK,CAAC;AAAA,MAC3C;AACE,eAAO,IAAI,wBAAa,GAAG,IAAI,MAAM,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ts","../src/messaging.ts"],"sourcesContent":["export * from 'e2b'\n\nexport { Sandbox, JupyterExtension } from './sandbox'\n\nexport type {\n Logs,\n ExecutionError,\n Result,\n Execution,\n MIMEType,\n RawData,\n OutputMessage,\n} from './messaging'\nexport type {\n ScaleType,\n GraphType,\n GraphTypes,\n Graph,\n BarGraph,\n BarData,\n LineGraph,\n ScatterGraph,\n BoxAndWhiskerGraph,\n BoxAndWhiskerData,\n PieGraph,\n PieData,\n SuperGraph,\n PointData,\n} from './graphs'\nimport { Sandbox } from './sandbox'\n\nexport default Sandbox\n","import { ConnectionConfig, Sandbox as BaseSandbox, TimeoutError } from 'e2b'\n\nimport { Result, Execution, OutputMessage, parseOutput, extractError } from './messaging'\n\nfunction 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\nfunction 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\nasync 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\n/**\n * Code interpreter module for executing code in a stateful context.\n */\nexport class JupyterExtension {\n private static readonly execTimeoutMs = 300_000\n private static readonly defaultKernelID = 'default'\n\n constructor(private readonly url: string, private readonly connectionConfig: ConnectionConfig) { }\n\n /**\n * Runs the code in the specified context, if not specified, the default context is used.\n * You can reference previously defined variables, imports, and functions in the code.\n *\n * @param code The code to execute\n * @param opts Options for executing the code\n * @param opts.kernelID The context ID to run the code in\n * @param opts.onStdout Callback for handling stdout messages\n * @param opts.onStderr Callback for handling stderr messages\n * @param opts.onResult Callback for handling the final result\n * @param opts.envs Environment variables to set for the execution\n * @param opts.timeoutMs Max time to wait for the execution to finish\n * @param opts.requestTimeoutMs Max time to wait for the request to finish\n * @returns Execution object\n */\n async execCell(\n code: string,\n opts?: {\n kernelID?: string,\n onStdout?: (output: OutputMessage) => (Promise<any> | any),\n onStderr?: (output: OutputMessage) => (Promise<any> | any),\n onResult?: (data: Result) => (Promise<any> | any),\n envs?: Record<string, string>,\n timeoutMs?: number,\n requestTimeoutMs?: number,\n },\n ): Promise<Execution> {\n const controller = new AbortController()\n\n const requestTimeout = opts?.requestTimeoutMs ?? this.connectionConfig.requestTimeoutMs\n\n const reqTimer = requestTimeout ? setTimeout(() => {\n controller.abort()\n }, requestTimeout)\n : undefined\n\n try {\n const res = await fetch(`${this.url}/execute`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n code,\n context_id: opts?.kernelID,\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(`Not response body: ${res.statusText} ${await res?.text()}`)\n }\n\n clearTimeout(reqTimer)\n\n const bodyTimeout = opts?.timeoutMs ?? JupyterExtension.execTimeoutMs\n\n const bodyTimer = bodyTimeout\n ? setTimeout(() => {\n controller.abort()\n }, bodyTimeout)\n : undefined\n\n const execution = new Execution()\n\n\n try {\n for await (const chunk of readLines(res.body)) {\n await parseOutput(execution, chunk, opts?.onStdout, opts?.onStderr, opts?.onResult)\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 cwd The working directory for the context\n * @param kernelName The name of the context\n * @param requestTimeoutMs Max time to wait for the request to finish\n * @returns The context ID\n */\n async createKernel({\n cwd,\n kernelName,\n requestTimeoutMs,\n }: {\n cwd?: string,\n kernelName?: string,\n requestTimeoutMs?: number,\n } = {}): Promise<string> {\n try {\n\n const res = await fetch(`${this.url}/contexts`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n name: kernelName,\n cwd,\n }),\n keepalive: true,\n signal: this.connectionConfig.getSignal(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 data.id\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Restarts the context.\n * Restarting will clear all variables, imports, and other settings set during previous executions.\n *\n * @param kernelID The context ID to restart\n * @param requestTimeoutMs Max time to wait for the request to finish\n */\n async restartKernel({\n kernelID,\n requestTimeoutMs,\n }: {\n kernelID?: string,\n requestTimeoutMs?: number,\n } = {}): Promise<void> {\n try {\n kernelID = kernelID || JupyterExtension.defaultKernelID\n const res = await fetch(`${this.url}/contexts/${kernelID}/restart`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n keepalive: true,\n signal: this.connectionConfig.getSignal(requestTimeoutMs),\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 * Shuts down the context.\n *\n * @param kernelID The context ID to shut down\n * @param requestTimeoutMs Max time to wait for the request to finish\n */\n async shutdownKernel({\n kernelID,\n requestTimeoutMs,\n }: {\n kernelID?: string,\n requestTimeoutMs?: number,\n } = {}): Promise<void> {\n try {\n\n kernelID = kernelID || JupyterExtension.defaultKernelID\n\n const res = await fetch(`${this.url}/contexts/${kernelID}`, {\n method: 'DELETE',\n keepalive: true,\n signal: this.connectionConfig.getSignal(requestTimeoutMs),\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 * Lists all available contexts.\n *\n * @param requestTimeoutMs Max time to wait for the request to finish\n * @returns List of context IDs and names\n */\n async listKernels({\n requestTimeoutMs,\n }: {\n requestTimeoutMs?: number,\n } = {}): Promise<{ kernelID: string, name: string }[]> {\n try {\n const res = await fetch(`${this.url}/contexts`, {\n keepalive: true,\n signal: this.connectionConfig.getSignal(requestTimeoutMs),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n\n return (await res.json()).map((kernel: any) => ({ kernelID: kernel.id, name: kernel.name }))\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n}\n\n/**\n * Code interpreter module for executing code in a stateful context.\n */\nexport class Sandbox extends BaseSandbox {\n protected static override readonly defaultTemplate: string = 'code-interpreter-beta'\n protected static readonly jupyterPort = 49999\n\n readonly notebook = new JupyterExtension(\n `${this.connectionConfig.debug ? 'http' : 'https'}://${this.getHost(Sandbox.jupyterPort)}`,\n this.connectionConfig,\n )\n}\n","import { NotFoundError, SandboxError, TimeoutError } from 'e2b'\nimport { GraphTypes } from './graphs'\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\nexport class OutputMessage {\n constructor(\n public readonly line: string,\n /**\n * Unix epoch in nanoseconds\n */\n public readonly timestamp: number,\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\ntype E2BData = {\n data: Record<string, unknown>\n graph: GraphTypes\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} & E2BData\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 graph data.\n */\n readonly graph?: GraphTypes\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.graph = data['graph']\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 'extra',\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) {\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 break\n case 'number_of_executions':\n execution.executionCount = msg.execution_count\n break\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,gBAAd;;;ACAA,IAAAA,cAAuE;;;ACAvE,iBAA0D;AAG1D,SAAsB,aAAa,KAAe;AAAA;AAChD,QAAI,IAAI,IAAI;AACV;AAAA,IACF;AAEA,YAAQ,IAAI,QAAQ;AAAA,MAClB,KAAK;AACH,eAAO,IAAI;AAAA,UACT,GAAG,MAAM,IAAI,KAAK,CAAC;AAAA,QACrB;AAAA,M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cAAc;AAFnC,IAAM,UAAN;;;ADvQP,IAAO,cAAQ;","names":["import_e2b","error","BaseSandbox"]}
|
package/dist/index.mjs
CHANGED
|
@@ -58,8 +58,8 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
|
|
|
58
58
|
// src/index.ts
|
|
59
59
|
export * from "e2b";
|
|
60
60
|
|
|
61
|
-
// src/
|
|
62
|
-
import { Sandbox, TimeoutError as TimeoutError2 } from "e2b";
|
|
61
|
+
// src/sandbox.ts
|
|
62
|
+
import { Sandbox as BaseSandbox, TimeoutError as TimeoutError2 } from "e2b";
|
|
63
63
|
|
|
64
64
|
// src/messaging.ts
|
|
65
65
|
import { NotFoundError, SandboxError, TimeoutError } from "e2b";
|
|
@@ -259,7 +259,7 @@ function parseOutput(execution, line, onStdout, onStderr, onResult) {
|
|
|
259
259
|
});
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
// src/
|
|
262
|
+
// src/sandbox.ts
|
|
263
263
|
function formatRequestTimeoutError(error) {
|
|
264
264
|
if (error instanceof Error && error.name === "AbortError") {
|
|
265
265
|
return new TimeoutError2("Request timed out \u2014 the 'requestTimeoutMs' option can be used to increase this timeout");
|
|
@@ -509,24 +509,24 @@ var _JupyterExtension = class _JupyterExtension {
|
|
|
509
509
|
_JupyterExtension.execTimeoutMs = 3e5;
|
|
510
510
|
_JupyterExtension.defaultKernelID = "default";
|
|
511
511
|
var JupyterExtension = _JupyterExtension;
|
|
512
|
-
var
|
|
512
|
+
var _Sandbox = class _Sandbox extends BaseSandbox {
|
|
513
513
|
constructor() {
|
|
514
514
|
super(...arguments);
|
|
515
515
|
this.notebook = new JupyterExtension(
|
|
516
|
-
`${this.connectionConfig.debug ? "http" : "https"}://${this.getHost(
|
|
516
|
+
`${this.connectionConfig.debug ? "http" : "https"}://${this.getHost(_Sandbox.jupyterPort)}`,
|
|
517
517
|
this.connectionConfig
|
|
518
518
|
);
|
|
519
519
|
}
|
|
520
520
|
};
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
var
|
|
521
|
+
_Sandbox.defaultTemplate = "code-interpreter-beta";
|
|
522
|
+
_Sandbox.jupyterPort = 49999;
|
|
523
|
+
var Sandbox = _Sandbox;
|
|
524
524
|
|
|
525
525
|
// src/index.ts
|
|
526
|
-
var src_default =
|
|
526
|
+
var src_default = Sandbox;
|
|
527
527
|
export {
|
|
528
|
-
CodeInterpreter,
|
|
529
528
|
JupyterExtension,
|
|
529
|
+
Sandbox,
|
|
530
530
|
src_default as default
|
|
531
531
|
};
|
|
532
532
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/codeInterpreter.ts","../src/messaging.ts"],"sourcesContent":["export * from 'e2b'\n\nexport { CodeInterpreter, JupyterExtension } from './codeInterpreter'\n\nexport type {\n Logs,\n ExecutionError,\n Result,\n Execution,\n MIMEType,\n RawData,\n OutputMessage,\n} from './messaging'\nexport type {\n ScaleType,\n GraphType,\n GraphTypes,\n Graph,\n BarGraph,\n BarData,\n LineGraph,\n ScatterGraph,\n BoxAndWhiskerGraph,\n BoxAndWhiskerData,\n PieGraph,\n PieData,\n SuperGraph,\n PointData,\n} from './graphs'\nimport { CodeInterpreter } from './codeInterpreter'\n\nexport default CodeInterpreter\n","import { ConnectionConfig, Sandbox, TimeoutError } from 'e2b'\n\nimport { Result, Execution, OutputMessage, parseOutput, extractError } from './messaging'\n\nfunction 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\nfunction 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\nasync 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\n/**\n * Code interpreter module for executing code in a stateful context.\n */\nexport class JupyterExtension {\n private static readonly execTimeoutMs = 300_000\n private static readonly defaultKernelID = 'default'\n\n constructor(private readonly url: string, private readonly connectionConfig: ConnectionConfig) { }\n\n /**\n * Runs the code in the specified context, if not specified, the default context is used.\n * You can reference previously defined variables, imports, and functions in the code.\n *\n * @param code The code to execute\n * @param opts Options for executing the code\n * @param opts.kernelID The context ID to run the code in\n * @param opts.onStdout Callback for handling stdout messages\n * @param opts.onStderr Callback for handling stderr messages\n * @param opts.onResult Callback for handling the final result\n * @param opts.envs Environment variables to set for the execution\n * @param opts.timeoutMs Max time to wait for the execution to finish\n * @param opts.requestTimeoutMs Max time to wait for the request to finish\n * @returns Execution object\n */\n async execCell(\n code: string,\n opts?: {\n kernelID?: string,\n onStdout?: (output: OutputMessage) => (Promise<any> | any),\n onStderr?: (output: OutputMessage) => (Promise<any> | any),\n onResult?: (data: Result) => (Promise<any> | any),\n envs?: Record<string, string>,\n timeoutMs?: number,\n requestTimeoutMs?: number,\n },\n ): Promise<Execution> {\n const controller = new AbortController()\n\n const requestTimeout = opts?.requestTimeoutMs ?? this.connectionConfig.requestTimeoutMs\n\n const reqTimer = requestTimeout ? setTimeout(() => {\n controller.abort()\n }, requestTimeout)\n : undefined\n\n try {\n const res = await fetch(`${this.url}/execute`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n code,\n context_id: opts?.kernelID,\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(`Not response body: ${res.statusText} ${await res?.text()}`)\n }\n\n clearTimeout(reqTimer)\n\n const bodyTimeout = opts?.timeoutMs ?? JupyterExtension.execTimeoutMs\n\n const bodyTimer = bodyTimeout\n ? setTimeout(() => {\n controller.abort()\n }, bodyTimeout)\n : undefined\n\n const execution = new Execution()\n\n\n try {\n for await (const chunk of readLines(res.body)) {\n await parseOutput(execution, chunk, opts?.onStdout, opts?.onStderr, opts?.onResult)\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 cwd The working directory for the context\n * @param kernelName The name of the context\n * @param requestTimeoutMs Max time to wait for the request to finish\n * @returns The context ID\n */\n async createKernel({\n cwd,\n kernelName,\n requestTimeoutMs,\n }: {\n cwd?: string,\n kernelName?: string,\n requestTimeoutMs?: number,\n } = {}): Promise<string> {\n try {\n\n const res = await fetch(`${this.url}/contexts`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n name: kernelName,\n cwd,\n }),\n keepalive: true,\n signal: this.connectionConfig.getSignal(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 data.id\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Restarts the context.\n * Restarting will clear all variables, imports, and other settings set during previous executions.\n *\n * @param kernelID The context ID to restart\n * @param requestTimeoutMs Max time to wait for the request to finish\n */\n async restartKernel({\n kernelID,\n requestTimeoutMs,\n }: {\n kernelID?: string,\n requestTimeoutMs?: number,\n } = {}): Promise<void> {\n try {\n kernelID = kernelID || JupyterExtension.defaultKernelID\n const res = await fetch(`${this.url}/contexts/${kernelID}/restart`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n keepalive: true,\n signal: this.connectionConfig.getSignal(requestTimeoutMs),\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 * Shuts down the context.\n *\n * @param kernelID The context ID to shut down\n * @param requestTimeoutMs Max time to wait for the request to finish\n */\n async shutdownKernel({\n kernelID,\n requestTimeoutMs,\n }: {\n kernelID?: string,\n requestTimeoutMs?: number,\n } = {}): Promise<void> {\n try {\n\n kernelID = kernelID || JupyterExtension.defaultKernelID\n\n const res = await fetch(`${this.url}/contexts/${kernelID}`, {\n method: 'DELETE',\n keepalive: true,\n signal: this.connectionConfig.getSignal(requestTimeoutMs),\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 * Lists all available contexts.\n *\n * @param requestTimeoutMs Max time to wait for the request to finish\n * @returns List of context IDs and names\n */\n async listKernels({\n requestTimeoutMs,\n }: {\n requestTimeoutMs?: number,\n } = {}): Promise<{ kernelID: string, name: string }[]> {\n try {\n const res = await fetch(`${this.url}/contexts`, {\n keepalive: true,\n signal: this.connectionConfig.getSignal(requestTimeoutMs),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n\n return (await res.json()).map((kernel: any) => ({ kernelID: kernel.id, name: kernel.name }))\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n}\n\n/**\n * Code interpreter module for executing code in a stateful context.\n */\nexport class CodeInterpreter extends Sandbox {\n protected static override readonly defaultTemplate: string = 'code-interpreter-beta'\n protected static readonly jupyterPort = 49999\n\n readonly notebook = new JupyterExtension(\n `${this.connectionConfig.debug ? 'http' : 'https'}://${this.getHost(CodeInterpreter.jupyterPort)}`,\n this.connectionConfig,\n )\n}\n","import { NotFoundError, SandboxError, TimeoutError } from 'e2b'\nimport { GraphTypes } from './graphs'\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\nexport class OutputMessage {\n constructor(\n public readonly line: string,\n /**\n * Unix epoch in nanoseconds\n */\n public readonly timestamp: number,\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\ntype E2BData = {\n data: Record<string, unknown>\n graph: GraphTypes\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} & E2BData\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 graph data.\n */\n readonly graph?: GraphTypes\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.graph = data['graph']\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 'extra',\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) {\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 break\n case 'number_of_executions':\n execution.executionCount = msg.execution_count\n break\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,cAAc;;;ACAd,SAA2B,SAAS,gBAAAA,qBAAoB;;;ACAxD,SAAS,eAAe,cAAc,oBAAoB;AAG1D,SAAsB,aAAa,KAAe;AAAA;AAChD,QAAI,IAAI,IAAI;AACV;AAAA,IACF;AAEA,YAAQ,IAAI,QAAQ;AAAA,MAClB,KAAK;AACH,eAAO,IAAI;AAAA,UACT,GAAG,MAAM,IAAI,KAAK,CAAC;AAAA,QACrB;AAAA,MACF,KAAK;AACH,eAAO,IAAI,cAAc,MAAM,IAAI,KAAK,CAAC;AAAA,MAC3C;AACE,eAAO,IAAI,aAAa,GAAG,IAAI,MAAM,IAAI,IAAI,UAAU,EAAE;AAAA,IAC7D;AAAA,EACF;AAAA;AAqBO,IAAM,iBAAN,MAAqB;AAAA,EAC1B,YAIS,MAIA,OAIA,WACP;AATO;AAIA;AAIA;AAAA,EACN;AACL;AA4BO,IAAM,SAAN,MAAa;AAAA,EAwDlB,YAAY,SAAkC,cAAuB;AAAvB;AAC5C,UAAM,OAAO,mBAAK;AAClB,WAAO,KAAK,MAAM;AAClB,WAAO,KAAK,gBAAgB;AAE5B,SAAK,OAAO,KAAK,MAAM;AACvB,SAAK,OAAO,KAAK,MAAM;AACvB,SAAK,WAAW,KAAK,UAAU;AAC/B,SAAK,MAAM,KAAK,KAAK;AACrB,SAAK,MAAM,KAAK,KAAK;AACrB,SAAK,OAAO,KAAK,MAAM;AACvB,SAAK,MAAM,KAAK,KAAK;AACrB,SAAK,QAAQ,KAAK,OAAO;AACzB,SAAK,OAAO,KAAK,MAAM;AACvB,SAAK,aAAa,KAAK,YAAY;AACnC,SAAK,eAAe;AACpB,SAAK,MAAM;AAEX,SAAK,OAAO,KAAK,MAAM;AACvB,SAAK,QAA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,OAAO,IAAI,MAAM,OAAO,KAAK,EAAE;AAAA,MAC7F,SAAS,OAAO;AACd,cAAM,0BAA0B,KAAK;AAAA,MACvC;AAAA,IACF;AAAA;AACF;AAxOa,kBACa,gBAAgB;AAD7B,kBAEa,kBAAkB;AAFrC,IAAM,mBAAN;AA6OA,IAAM,mBAAN,MAAM,yBAAwB,QAAQ;AAAA,EAAtC;AAAA;AAIL,SAAS,WAAW,IAAI;AAAA,MACtB,GAAG,KAAK,iBAAiB,QAAQ,SAAS,OAAO,MAAM,KAAK,QAAQ,iBAAgB,WAAW,CAAC;AAAA,MAChG,KAAK;AAAA,IACP;AAAA;AACF;AARa,iBACwB,kBAA0B;AADlD,iBAEe,cAAc;AAFnC,IAAM,kBAAN;;;ADvQP,IAAO,cAAQ;","names":["TimeoutError","TimeoutError","error"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/sandbox.ts","../src/messaging.ts"],"sourcesContent":["export * from 'e2b'\n\nexport { Sandbox, JupyterExtension } from './sandbox'\n\nexport type {\n Logs,\n ExecutionError,\n Result,\n Execution,\n MIMEType,\n RawData,\n OutputMessage,\n} from './messaging'\nexport type {\n ScaleType,\n GraphType,\n GraphTypes,\n Graph,\n BarGraph,\n BarData,\n LineGraph,\n ScatterGraph,\n BoxAndWhiskerGraph,\n BoxAndWhiskerData,\n PieGraph,\n PieData,\n SuperGraph,\n PointData,\n} from './graphs'\nimport { Sandbox } from './sandbox'\n\nexport default Sandbox\n","import { ConnectionConfig, Sandbox as BaseSandbox, TimeoutError } from 'e2b'\n\nimport { Result, Execution, OutputMessage, parseOutput, extractError } from './messaging'\n\nfunction 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\nfunction 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\nasync 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\n/**\n * Code interpreter module for executing code in a stateful context.\n */\nexport class JupyterExtension {\n private static readonly execTimeoutMs = 300_000\n private static readonly defaultKernelID = 'default'\n\n constructor(private readonly url: string, private readonly connectionConfig: ConnectionConfig) { }\n\n /**\n * Runs the code in the specified context, if not specified, the default context is used.\n * You can reference previously defined variables, imports, and functions in the code.\n *\n * @param code The code to execute\n * @param opts Options for executing the code\n * @param opts.kernelID The context ID to run the code in\n * @param opts.onStdout Callback for handling stdout messages\n * @param opts.onStderr Callback for handling stderr messages\n * @param opts.onResult Callback for handling the final result\n * @param opts.envs Environment variables to set for the execution\n * @param opts.timeoutMs Max time to wait for the execution to finish\n * @param opts.requestTimeoutMs Max time to wait for the request to finish\n * @returns Execution object\n */\n async execCell(\n code: string,\n opts?: {\n kernelID?: string,\n onStdout?: (output: OutputMessage) => (Promise<any> | any),\n onStderr?: (output: OutputMessage) => (Promise<any> | any),\n onResult?: (data: Result) => (Promise<any> | any),\n envs?: Record<string, string>,\n timeoutMs?: number,\n requestTimeoutMs?: number,\n },\n ): Promise<Execution> {\n const controller = new AbortController()\n\n const requestTimeout = opts?.requestTimeoutMs ?? this.connectionConfig.requestTimeoutMs\n\n const reqTimer = requestTimeout ? setTimeout(() => {\n controller.abort()\n }, requestTimeout)\n : undefined\n\n try {\n const res = await fetch(`${this.url}/execute`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n code,\n context_id: opts?.kernelID,\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(`Not response body: ${res.statusText} ${await res?.text()}`)\n }\n\n clearTimeout(reqTimer)\n\n const bodyTimeout = opts?.timeoutMs ?? JupyterExtension.execTimeoutMs\n\n const bodyTimer = bodyTimeout\n ? setTimeout(() => {\n controller.abort()\n }, bodyTimeout)\n : undefined\n\n const execution = new Execution()\n\n\n try {\n for await (const chunk of readLines(res.body)) {\n await parseOutput(execution, chunk, opts?.onStdout, opts?.onStderr, opts?.onResult)\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 cwd The working directory for the context\n * @param kernelName The name of the context\n * @param requestTimeoutMs Max time to wait for the request to finish\n * @returns The context ID\n */\n async createKernel({\n cwd,\n kernelName,\n requestTimeoutMs,\n }: {\n cwd?: string,\n kernelName?: string,\n requestTimeoutMs?: number,\n } = {}): Promise<string> {\n try {\n\n const res = await fetch(`${this.url}/contexts`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n name: kernelName,\n cwd,\n }),\n keepalive: true,\n signal: this.connectionConfig.getSignal(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 data.id\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n\n /**\n * Restarts the context.\n * Restarting will clear all variables, imports, and other settings set during previous executions.\n *\n * @param kernelID The context ID to restart\n * @param requestTimeoutMs Max time to wait for the request to finish\n */\n async restartKernel({\n kernelID,\n requestTimeoutMs,\n }: {\n kernelID?: string,\n requestTimeoutMs?: number,\n } = {}): Promise<void> {\n try {\n kernelID = kernelID || JupyterExtension.defaultKernelID\n const res = await fetch(`${this.url}/contexts/${kernelID}/restart`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n keepalive: true,\n signal: this.connectionConfig.getSignal(requestTimeoutMs),\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 * Shuts down the context.\n *\n * @param kernelID The context ID to shut down\n * @param requestTimeoutMs Max time to wait for the request to finish\n */\n async shutdownKernel({\n kernelID,\n requestTimeoutMs,\n }: {\n kernelID?: string,\n requestTimeoutMs?: number,\n } = {}): Promise<void> {\n try {\n\n kernelID = kernelID || JupyterExtension.defaultKernelID\n\n const res = await fetch(`${this.url}/contexts/${kernelID}`, {\n method: 'DELETE',\n keepalive: true,\n signal: this.connectionConfig.getSignal(requestTimeoutMs),\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 * Lists all available contexts.\n *\n * @param requestTimeoutMs Max time to wait for the request to finish\n * @returns List of context IDs and names\n */\n async listKernels({\n requestTimeoutMs,\n }: {\n requestTimeoutMs?: number,\n } = {}): Promise<{ kernelID: string, name: string }[]> {\n try {\n const res = await fetch(`${this.url}/contexts`, {\n keepalive: true,\n signal: this.connectionConfig.getSignal(requestTimeoutMs),\n })\n\n const error = await extractError(res)\n if (error) {\n throw error\n }\n\n return (await res.json()).map((kernel: any) => ({ kernelID: kernel.id, name: kernel.name }))\n } catch (error) {\n throw formatRequestTimeoutError(error)\n }\n }\n}\n\n/**\n * Code interpreter module for executing code in a stateful context.\n */\nexport class Sandbox extends BaseSandbox {\n protected static override readonly defaultTemplate: string = 'code-interpreter-beta'\n protected static readonly jupyterPort = 49999\n\n readonly notebook = new JupyterExtension(\n `${this.connectionConfig.debug ? 'http' : 'https'}://${this.getHost(Sandbox.jupyterPort)}`,\n this.connectionConfig,\n )\n}\n","import { NotFoundError, SandboxError, TimeoutError } from 'e2b'\nimport { GraphTypes } from './graphs'\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\nexport class OutputMessage {\n constructor(\n public readonly line: string,\n /**\n * Unix epoch in nanoseconds\n */\n public readonly timestamp: number,\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\ntype E2BData = {\n data: Record<string, unknown>\n graph: GraphTypes\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} & E2BData\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 graph data.\n */\n readonly graph?: GraphTypes\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.graph = data['graph']\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 'extra',\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) {\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 break\n case 'number_of_executions':\n execution.executionCount = msg.execution_count\n break\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,cAAc;;;ACAd,SAA2B,WAAW,aAAa,gBAAAA,qBAAoB;;;ACAvE,SAAS,eAAe,cAAc,oBAAoB;AAG1D,SAAsB,aAAa,KAAe;AAAA;AAChD,QAAI,IAAI,IAAI;AACV;AAAA,IACF;AAEA,YAAQ,IAAI,QAAQ;AAAA,MAClB,KAAK;AACH,eAAO,IAAI;AAAA,UACT,GAAG,MAAM,IAAI,KAAK,CAAC;AAAA,QACrB;AAAA,MACF,KAAK;AACH,eAAO,IAAI,cAAc,MAAM,IAAI,KAAK,CAAC;AAAA,MAC3C;AACE,eAAO,IAAI,aAAa,GAAG,IAAI,MAAM,IAAI,IAAI,UAAU,EAAE;AAAA,IAC7D;AAAA,EACF;AAAA;AAqBO,IAAM,iBAAN,MAAqB;AAAA,EAC1B,YAIS,MAIA,OAIA,WACP;AATO;AAIA;AAIA;AAAA,EACN;AACL;AA4BO,IAAM,SAAN,MAAa;AAAA,EAwDlB,YAAY,SAAkC,cAAuB;AAAvB;AAC5C,UAAM,OAAO,mBAAK;AAClB,WAAO,KAAK,MAAM;AAClB,WAAO,KAAK,gBAAgB;AAE5B,SAAK,OAAO,KAAK,MAAM;AACvB,SAAK,OAAO,KAAK,MAAM;AACvB,SAAK,WAAW,KAAK,UAAU;AAC/B,SAAK,MAAM,KAAK,KAAK;AACrB,SAAK,MAAM,KAAK,KAAK;AACrB,SAAK,OAAO,KAAK,MAAM;AACvB,SAAK,MAAM,KAAK,KAAK;AACrB,SAAK,QAAQ,KAAK,OAAO;AACzB,SAAK,OAAO,KAAK,MAAM;AACvB,SAAK,aAAa,KAAK,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