@e2b/code-interpreter
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -36,3 +36,3 @@ import { Sandbox, SandboxOpts, ProcessMessage } from 'e2b'; | ||
*/ | ||
traceback(): string; | ||
get traceback(): string; | ||
} | ||
@@ -55,4 +55,4 @@ /** | ||
* The result can contain multiple types of data, such as text, images, plots, etc. Each type of data is represented | ||
* as a string, and the result can contain multiple types of data. The text representation is always present, and | ||
* the other representations are optional. | ||
* as a string, and the result can contain multiple types of data. The display calls don't have to have text representation, | ||
* for the actual result the representation is always present for the result, the other representations are always optional. | ||
*/ | ||
@@ -62,5 +62,5 @@ declare class Result { | ||
/** | ||
* Text representation of the result. Always present. | ||
* Text representation of the result. | ||
*/ | ||
readonly text: string; | ||
readonly text?: string; | ||
/** | ||
@@ -108,2 +108,8 @@ * HTML representation of the data. | ||
constructor(data: RawData, isMainResult: boolean); | ||
/** | ||
* Returns all the formats available for the result. | ||
* | ||
* @returns Array of strings representing the formats available for the result. | ||
*/ | ||
formats(): string[]; | ||
} | ||
@@ -191,11 +197,11 @@ /** | ||
* @param onStderr A callback function to handle standard error messages from the code execution. | ||
* @param onDisplayData A callback function to handle display data messages from the code execution. | ||
* @param onResult A callback function to handle display data messages from the code execution. | ||
* @param timeout The maximum time to wait for the code execution to complete, in milliseconds. | ||
* @returns A promise that resolves with the result of the code execution. | ||
*/ | ||
execCell(code: string, { kernelID, onStdout, onStderr, onDisplayData, timeout }?: { | ||
execCell(code: string, { kernelID, onStdout, onStderr, onResult, timeout }?: { | ||
kernelID?: string; | ||
onStdout?: (msg: ProcessMessage) => Promise<void> | void; | ||
onStderr?: (msg: ProcessMessage) => Promise<void> | void; | ||
onDisplayData?: (data: Result) => Promise<void> | void; | ||
onStdout?: (msg: ProcessMessage) => any; | ||
onStderr?: (msg: ProcessMessage) => any; | ||
onResult?: (data: Result) => any; | ||
timeout?: number; | ||
@@ -202,0 +208,0 @@ }): Promise<Execution>; |
@@ -118,3 +118,3 @@ "use strict"; | ||
*/ | ||
traceback() { | ||
get traceback() { | ||
return this.tracebackRaw.join("\n"); | ||
@@ -156,2 +156,41 @@ } | ||
} | ||
/** | ||
* Returns all the formats available for the result. | ||
* | ||
* @returns Array of strings representing the formats available for the result. | ||
*/ | ||
formats() { | ||
const formats = []; | ||
if (this.html) { | ||
formats.push("html"); | ||
} | ||
if (this.markdown) { | ||
formats.push("markdown"); | ||
} | ||
if (this.svg) { | ||
formats.push("svg"); | ||
} | ||
if (this.png) { | ||
formats.push("png"); | ||
} | ||
if (this.jpeg) { | ||
formats.push("jpeg"); | ||
} | ||
if (this.pdf) { | ||
formats.push("pdf"); | ||
} | ||
if (this.latex) { | ||
formats.push("latex"); | ||
} | ||
if (this.json) { | ||
formats.push("json"); | ||
} | ||
if (this.javascript) { | ||
formats.push("javascript"); | ||
} | ||
for (const key of Object.keys(this.extra)) { | ||
formats.push(key); | ||
} | ||
return formats; | ||
} | ||
}; | ||
@@ -176,3 +215,3 @@ var Execution = class { | ||
var CellExecution = class { | ||
constructor(onStdout, onStderr, onDisplayData) { | ||
constructor(onStdout, onStderr, onResult) { | ||
this.inputAccepted = false; | ||
@@ -182,3 +221,3 @@ this.execution = new Execution([], { stdout: [], stderr: [] }); | ||
this.onStderr = onStderr; | ||
this.onDisplayData = onDisplayData; | ||
this.onResult = onResult; | ||
} | ||
@@ -264,7 +303,11 @@ }; | ||
execution.results.push(result); | ||
if (cell.onDisplayData) { | ||
cell.onDisplayData(result); | ||
if (cell.onResult) { | ||
cell.onResult(result); | ||
} | ||
} else if (message.msg_type == "execute_result") { | ||
execution.results.push(new Result(message.content.data, true)); | ||
const result = new Result(message.content.data, true); | ||
execution.results.push(result); | ||
if (cell.onResult) { | ||
cell.onResult(result); | ||
} | ||
} else if (message.msg_type == "status") { | ||
@@ -306,7 +349,7 @@ if (message.content.execution_state == "idle") { | ||
* @param onStderr Callback for stderr messages. | ||
* @param onDisplayData Callback for display data messages. | ||
* @param onResult Callback function to handle the result and display calls of the code execution. | ||
* @param timeout Time in milliseconds to wait for response. | ||
* @returns Promise with execution result. | ||
*/ | ||
sendExecutionMessage(code, onStdout, onStderr, onDisplayData, timeout) { | ||
sendExecutionMessage(code, onStdout, onStderr, onResult, timeout) { | ||
return new Promise((resolve, reject) => { | ||
@@ -326,3 +369,3 @@ const msg_id = id(16); | ||
} | ||
this.cells[msg_id] = new CellExecution(onStdout, onStderr, onDisplayData); | ||
this.cells[msg_id] = new CellExecution(onStdout, onStderr, onResult); | ||
this.idAwaiter[msg_id] = (responseData) => { | ||
@@ -437,3 +480,3 @@ clearInterval(timeoutSet); | ||
* @param onStderr A callback function to handle standard error messages from the code execution. | ||
* @param onDisplayData A callback function to handle display data messages from the code execution. | ||
* @param onResult A callback function to handle display data messages from the code execution. | ||
* @param timeout The maximum time to wait for the code execution to complete, in milliseconds. | ||
@@ -447,3 +490,3 @@ * @returns A promise that resolves with the result of the code execution. | ||
onStderr, | ||
onDisplayData, | ||
onResult, | ||
timeout | ||
@@ -457,3 +500,3 @@ } = {}) { | ||
onStderr, | ||
onDisplayData, | ||
onResult, | ||
timeout | ||
@@ -460,0 +503,0 @@ ); |
{ | ||
"name": "@e2b/code-interpreter", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "E2B Code Interpreter - Stateful code execution", | ||
@@ -5,0 +5,0 @@ "homepage": "https://e2b.dev", |
@@ -13,3 +13,3 @@ # Code interpreter extension for JavaScript | ||
```sh | ||
npm install e2b_code_interpreter | ||
npm install @e2b/code-interpreter | ||
``` | ||
@@ -84,3 +84,3 @@ | ||
onStderr: (outErr) => console.error(outErr), | ||
onDisplayData: (outData) => console.log(outData.text) | ||
onResult: (result) => console.log(result.text) | ||
}) | ||
@@ -87,0 +87,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
129430
1511