11import { NotFoundError , SandboxError , TimeoutError } from 'e2b'
2+ import { GraphTypes } from './graphs'
23
34export async function extractError ( res : Response ) {
45 if ( res . ok ) {
@@ -24,9 +25,8 @@ export class OutputMessage {
2425 * Unix epoch in nanoseconds
2526 */
2627 public readonly timestamp : number ,
27- public readonly error : boolean ,
28- ) {
29- }
28+ public readonly error : boolean
29+ ) { }
3030
3131 public toString ( ) {
3232 return this . line
@@ -50,25 +50,26 @@ export class ExecutionError {
5050 /**
5151 * The raw traceback of the error.
5252 **/
53- public traceback : string ,
54- ) { }
53+ public traceback : string
54+ ) { }
5555}
5656
5757/**
5858 * Represents a MIME type.
5959 */
6060export type MIMEType = string
6161
62- type Data = {
62+ type E2BData = {
6363 data : Record < string , unknown >
64+ graph : GraphTypes
6465}
6566
6667/**
6768 * Dictionary that maps MIME types to their corresponding representations of the data.
6869 */
6970export type RawData = {
7071 [ key : MIMEType ] : string
71- } & Data
72+ } & E2BData
7273
7374/**
7475 * Represents the data to be displayed as a result of executing a cell in a Jupyter notebook.
@@ -124,6 +125,10 @@ export class Result {
124125 * Contains the data from DataFrame.
125126 */
126127 readonly data ?: Record < string , unknown >
128+ /**
129+ * Contains the graph data.
130+ */
131+ readonly graph ?: GraphTypes
127132 /**
128133 * Extra data that can be included. Not part of the standard types.
129134 */
@@ -146,10 +151,12 @@ export class Result {
146151 this . latex = data [ 'latex' ]
147152 this . json = data [ 'json' ]
148153 this . javascript = data [ 'javascript' ]
149- this . data = data [ 'data' ]
150154 this . isMainResult = isMainResult
151155 this . raw = data
152156
157+ this . data = data [ 'data' ]
158+ this . graph = data [ 'graph' ]
159+
153160 this . extra = { }
154161
155162 for ( const key of Object . keys ( data ) ) {
@@ -166,7 +173,7 @@ export class Result {
166173 'json' ,
167174 'javascript' ,
168175 'data' ,
169- 'extra'
176+ 'extra' ,
170177 ] . includes ( key )
171178 ) {
172179 this . extra [ key ] = data [ key ]
@@ -234,7 +241,7 @@ export class Result {
234241 latex : this . latex ,
235242 json : this . json ,
236243 javascript : this . javascript ,
237- ...( Object . keys ( this . extra ) . length > 0 ? { extra : this . extra } : { } )
244+ ...( Object . keys ( this . extra ) . length > 0 ? { extra : this . extra } : { } ) ,
238245 }
239246 }
240247}
@@ -274,7 +281,7 @@ export class Execution {
274281 * Execution count of the cell.
275282 */
276283 public executionCount ?: number
277- ) { }
284+ ) { }
278285
279286 /**
280287 * Returns the text representation of the main result of the cell.
@@ -294,23 +301,26 @@ export class Execution {
294301 return {
295302 results : this . results ,
296303 logs : this . logs ,
297- error : this . error
304+ error : this . error ,
298305 }
299306 }
300307}
301308
302309export async function parseOutput (
303310 execution : Execution ,
304311 line : string ,
305- onStdout ?: ( output : OutputMessage ) => ( Promise < any > | any ) ,
306- onStderr ?: ( output : OutputMessage ) => ( Promise < any > | any ) ,
307- onResult ?: ( data : Result ) => ( Promise < any > | any ) ,
312+ onStdout ?: ( output : OutputMessage ) => Promise < any > | any ,
313+ onStderr ?: ( output : OutputMessage ) => Promise < any > | any ,
314+ onResult ?: ( data : Result ) => Promise < any > | any
308315) {
309316 const msg = JSON . parse ( line )
310317
311318 switch ( msg . type ) {
312319 case 'result' :
313- const result = new Result ( { ...msg , type : undefined , is_main_result : undefined } , msg . is_main_result )
320+ const result = new Result (
321+ { ...msg , type : undefined , is_main_result : undefined } ,
322+ msg . is_main_result
323+ )
314324 execution . results . push ( result )
315325 if ( onResult ) {
316326 await onResult ( result )
0 commit comments