1
1
import { NotFoundError , SandboxError , TimeoutError } from 'e2b'
2
+ import { GraphTypes } from './graphs'
2
3
3
4
export async function extractError ( res : Response ) {
4
5
if ( res . ok ) {
@@ -24,9 +25,8 @@ export class OutputMessage {
24
25
* Unix epoch in nanoseconds
25
26
*/
26
27
public readonly timestamp : number ,
27
- public readonly error : boolean ,
28
- ) {
29
- }
28
+ public readonly error : boolean
29
+ ) { }
30
30
31
31
public toString ( ) {
32
32
return this . line
@@ -50,25 +50,26 @@ export class ExecutionError {
50
50
/**
51
51
* The raw traceback of the error.
52
52
**/
53
- public traceback : string ,
54
- ) { }
53
+ public traceback : string
54
+ ) { }
55
55
}
56
56
57
57
/**
58
58
* Represents a MIME type.
59
59
*/
60
60
export type MIMEType = string
61
61
62
- type Data = {
62
+ type E2BData = {
63
63
data : Record < string , unknown >
64
+ graph : GraphTypes
64
65
}
65
66
66
67
/**
67
68
* Dictionary that maps MIME types to their corresponding representations of the data.
68
69
*/
69
70
export type RawData = {
70
71
[ key : MIMEType ] : string
71
- } & Data
72
+ } & E2BData
72
73
73
74
/**
74
75
* Represents the data to be displayed as a result of executing a cell in a Jupyter notebook.
@@ -124,6 +125,10 @@ export class Result {
124
125
* Contains the data from DataFrame.
125
126
*/
126
127
readonly data ?: Record < string , unknown >
128
+ /**
129
+ * Contains the graph data.
130
+ */
131
+ readonly graph ?: GraphTypes
127
132
/**
128
133
* Extra data that can be included. Not part of the standard types.
129
134
*/
@@ -146,10 +151,12 @@ export class Result {
146
151
this . latex = data [ 'latex' ]
147
152
this . json = data [ 'json' ]
148
153
this . javascript = data [ 'javascript' ]
149
- this . data = data [ 'data' ]
150
154
this . isMainResult = isMainResult
151
155
this . raw = data
152
156
157
+ this . data = data [ 'data' ]
158
+ this . graph = data [ 'graph' ]
159
+
153
160
this . extra = { }
154
161
155
162
for ( const key of Object . keys ( data ) ) {
@@ -166,7 +173,7 @@ export class Result {
166
173
'json' ,
167
174
'javascript' ,
168
175
'data' ,
169
- 'extra'
176
+ 'extra' ,
170
177
] . includes ( key )
171
178
) {
172
179
this . extra [ key ] = data [ key ]
@@ -234,7 +241,7 @@ export class Result {
234
241
latex : this . latex ,
235
242
json : this . json ,
236
243
javascript : this . javascript ,
237
- ...( Object . keys ( this . extra ) . length > 0 ? { extra : this . extra } : { } )
244
+ ...( Object . keys ( this . extra ) . length > 0 ? { extra : this . extra } : { } ) ,
238
245
}
239
246
}
240
247
}
@@ -274,7 +281,7 @@ export class Execution {
274
281
* Execution count of the cell.
275
282
*/
276
283
public executionCount ?: number
277
- ) { }
284
+ ) { }
278
285
279
286
/**
280
287
* Returns the text representation of the main result of the cell.
@@ -294,23 +301,26 @@ export class Execution {
294
301
return {
295
302
results : this . results ,
296
303
logs : this . logs ,
297
- error : this . error
304
+ error : this . error ,
298
305
}
299
306
}
300
307
}
301
308
302
309
export async function parseOutput (
303
310
execution : Execution ,
304
311
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
308
315
) {
309
316
const msg = JSON . parse ( line )
310
317
311
318
switch ( msg . type ) {
312
319
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
+ )
314
324
execution . results . push ( result )
315
325
if ( onResult ) {
316
326
await onResult ( result )
0 commit comments