@e2b/code-interpreter 0.0.9-beta.7 → 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/README.md CHANGED
@@ -24,7 +24,7 @@ const sandbox = await CodeInterpreter.create()
24
24
  await sandbox.notebook.execCell('x = 1')
25
25
 
26
26
  const execution = await sandbox.notebook.execCell('x+=1; x')
27
- console.log(execution.text) // outputs 2
27
+ console.log(execution.text) // outputs 2
28
28
 
29
29
  await sandbox.close()
30
30
  ```
@@ -48,7 +48,7 @@ plt.show()
48
48
  `
49
49
 
50
50
  // you can install dependencies in "jupyter notebook style"
51
- await sandbox.notebook.execCell("!pip install matplotlib")
51
+ await sandbox.notebook.execCell('!pip install matplotlib')
52
52
 
53
53
  const execution = await sandbox.notebook.execCell(code)
54
54
 
@@ -80,7 +80,7 @@ const sandbox = await CodeInterpreter.create()
80
80
  await sandbox.notebook.execCell(code, {
81
81
  onStdout: (out) => console.log(out),
82
82
  onStderr: (outErr) => console.error(outErr),
83
- onResult: (result) => console.log(result.text)
83
+ onResult: (result) => console.log(result.text),
84
84
  })
85
85
 
86
86
  await sandbox.close()
package/dist/index.d.mts CHANGED
@@ -1,6 +1,98 @@
1
- import { ConnectionConfig, Sandbox } from 'e2b';
1
+ import { ConnectionConfig, Sandbox as Sandbox$1 } from 'e2b';
2
2
  export * from 'e2b';
3
3
 
4
+ /**
5
+ * Graph types
6
+ */
7
+ declare enum GraphType {
8
+ LINE = "line",
9
+ SCATTER = "scatter",
10
+ BAR = "bar",
11
+ PIE = "pie",
12
+ BOX_AND_WHISKER = "box_and_whisker",
13
+ SUPERGRAPH = "supergraph",
14
+ UNKNOWN = "unknown"
15
+ }
16
+ /**
17
+ * Ax scale types
18
+ */
19
+ declare enum ScaleType {
20
+ LINEAR = "linear",
21
+ DATETIME = "datetime",
22
+ CATEGORICAL = "categorical",
23
+ LOG = "log",
24
+ SYMLOG = "symlog",
25
+ LOGIT = "logit",
26
+ FUNCTION = "function",
27
+ FUNCTIONLOG = "functionlog",
28
+ ASINH = "asinh"
29
+ }
30
+ type Graph = {
31
+ type: GraphType;
32
+ title: string;
33
+ elements: any[];
34
+ };
35
+ type Graph2D = Graph & {
36
+ x_label?: string;
37
+ y_label?: string;
38
+ x_unit?: string;
39
+ y_unit?: string;
40
+ };
41
+ type PointData = {
42
+ label: string;
43
+ points: [number | string, number | string][];
44
+ };
45
+ type PointGraph = Graph2D & {
46
+ x_ticks: (number | string)[];
47
+ x_scale: ScaleType;
48
+ x_tick_labels: string[];
49
+ y_ticks: (number | string)[];
50
+ y_scale: ScaleType;
51
+ y_tick_labels: string[];
52
+ elements: PointData[];
53
+ };
54
+ type LineGraph = PointGraph & {
55
+ type: GraphType.LINE;
56
+ };
57
+ type ScatterGraph = PointGraph & {
58
+ type: GraphType.SCATTER;
59
+ };
60
+ type BarData = {
61
+ label: string;
62
+ value: string;
63
+ group: string;
64
+ };
65
+ type BarGraph = Graph2D & {
66
+ type: GraphType.BAR;
67
+ elements: BarData[];
68
+ };
69
+ type PieData = {
70
+ label: string;
71
+ angle: number;
72
+ radius: number;
73
+ };
74
+ type PieGraph = Graph & {
75
+ type: GraphType.PIE;
76
+ elements: PieData[];
77
+ };
78
+ type BoxAndWhiskerData = {
79
+ label: string;
80
+ min: number;
81
+ first_quartile: number;
82
+ median: number;
83
+ third_quartile: number;
84
+ max: number;
85
+ };
86
+ type BoxAndWhiskerGraph = Graph2D & {
87
+ type: GraphType.BOX_AND_WHISKER;
88
+ elements: BoxAndWhiskerData[];
89
+ };
90
+ type SuperGraph = Graph & {
91
+ type: GraphType.SUPERGRAPH;
92
+ elements: Graph[];
93
+ };
94
+ type GraphTypes = LineGraph | ScatterGraph | BarGraph | PieGraph | BoxAndWhiskerGraph | SuperGraph;
95
+
4
96
  declare class OutputMessage {
5
97
  readonly line: string;
6
98
  /**
@@ -50,12 +142,16 @@ declare class ExecutionError {
50
142
  * Represents a MIME type.
51
143
  */
52
144
  type MIMEType = string;
145
+ type E2BData = {
146
+ data: Record<string, unknown>;
147
+ graph: GraphTypes;
148
+ };
53
149
  /**
54
- * Dictionary that maps MIME types to their corresponding string representations of the data.
150
+ * Dictionary that maps MIME types to their corresponding representations of the data.
55
151
  */
56
152
  type RawData = {
57
153
  [key: MIMEType]: string;
58
- };
154
+ } & E2BData;
59
155
  /**
60
156
  * Represents the data to be displayed as a result of executing a cell in a Jupyter notebook.
61
157
  * The result is similar to the structure returned by ipython kernel: https://ipython.readthedocs.io/en/stable/development/execution.html#execution-semantics
@@ -107,6 +203,14 @@ declare class Result {
107
203
  * JavaScript representation of the data.
108
204
  */
109
205
  readonly javascript?: string;
206
+ /**
207
+ * Contains the data from DataFrame.
208
+ */
209
+ readonly data?: Record<string, unknown>;
210
+ /**
211
+ * Contains the graph data.
212
+ */
213
+ readonly graph?: GraphTypes;
110
214
  /**
111
215
  * Extra data that can be included. Not part of the standard types.
112
216
  */
@@ -200,33 +304,79 @@ declare class Execution {
200
304
  };
201
305
  }
202
306
 
307
+ /**
308
+ * Code interpreter module for executing code in a stateful context.
309
+ */
203
310
  declare class JupyterExtension {
204
311
  private readonly url;
205
312
  private readonly connectionConfig;
206
313
  private static readonly execTimeoutMs;
207
314
  private static readonly defaultKernelID;
208
315
  constructor(url: string, connectionConfig: ConnectionConfig);
316
+ /**
317
+ * Runs the code in the specified context, if not specified, the default context is used.
318
+ * You can reference previously defined variables, imports, and functions in the code.
319
+ *
320
+ * @param code The code to execute
321
+ * @param opts Options for executing the code
322
+ * @param opts.kernelID The context ID to run the code in
323
+ * @param opts.onStdout Callback for handling stdout messages
324
+ * @param opts.onStderr Callback for handling stderr messages
325
+ * @param opts.onResult Callback for handling the final result
326
+ * @param opts.envs Environment variables to set for the execution
327
+ * @param opts.timeoutMs Max time to wait for the execution to finish
328
+ * @param opts.requestTimeoutMs Max time to wait for the request to finish
329
+ * @returns Execution object
330
+ */
209
331
  execCell(code: string, opts?: {
210
332
  kernelID?: string;
211
333
  onStdout?: (output: OutputMessage) => (Promise<any> | any);
212
334
  onStderr?: (output: OutputMessage) => (Promise<any> | any);
213
335
  onResult?: (data: Result) => (Promise<any> | any);
336
+ envs?: Record<string, string>;
214
337
  timeoutMs?: number;
215
338
  requestTimeoutMs?: number;
216
339
  }): Promise<Execution>;
340
+ /**
341
+ * Creates a new context to run code in.
342
+ *
343
+ * @param cwd The working directory for the context
344
+ * @param kernelName The name of the context
345
+ * @param requestTimeoutMs Max time to wait for the request to finish
346
+ * @returns The context ID
347
+ */
217
348
  createKernel({ cwd, kernelName, requestTimeoutMs, }?: {
218
349
  cwd?: string;
219
350
  kernelName?: string;
220
351
  requestTimeoutMs?: number;
221
352
  }): Promise<string>;
353
+ /**
354
+ * Restarts the context.
355
+ * Restarting will clear all variables, imports, and other settings set during previous executions.
356
+ *
357
+ * @param kernelID The context ID to restart
358
+ * @param requestTimeoutMs Max time to wait for the request to finish
359
+ */
222
360
  restartKernel({ kernelID, requestTimeoutMs, }?: {
223
361
  kernelID?: string;
224
362
  requestTimeoutMs?: number;
225
363
  }): Promise<void>;
364
+ /**
365
+ * Shuts down the context.
366
+ *
367
+ * @param kernelID The context ID to shut down
368
+ * @param requestTimeoutMs Max time to wait for the request to finish
369
+ */
226
370
  shutdownKernel({ kernelID, requestTimeoutMs, }?: {
227
371
  kernelID?: string;
228
372
  requestTimeoutMs?: number;
229
373
  }): Promise<void>;
374
+ /**
375
+ * Lists all available contexts.
376
+ *
377
+ * @param requestTimeoutMs Max time to wait for the request to finish
378
+ * @returns List of context IDs and names
379
+ */
230
380
  listKernels({ requestTimeoutMs, }?: {
231
381
  requestTimeoutMs?: number;
232
382
  }): Promise<{
@@ -234,10 +384,13 @@ declare class JupyterExtension {
234
384
  name: string;
235
385
  }[]>;
236
386
  }
237
- declare class CodeInterpreter extends Sandbox {
387
+ /**
388
+ * Code interpreter module for executing code in a stateful context.
389
+ */
390
+ declare class Sandbox extends Sandbox$1 {
238
391
  protected static readonly defaultTemplate: string;
239
392
  protected static readonly jupyterPort = 49999;
240
393
  readonly notebook: JupyterExtension;
241
394
  }
242
395
 
243
- export { CodeInterpreter, Execution, ExecutionError, JupyterExtension, type Logs, type MIMEType, OutputMessage, type RawData, Result, CodeInterpreter as default };
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,6 +1,98 @@
1
- import { ConnectionConfig, Sandbox } from 'e2b';
1
+ import { ConnectionConfig, Sandbox as Sandbox$1 } from 'e2b';
2
2
  export * from 'e2b';
3
3
 
4
+ /**
5
+ * Graph types
6
+ */
7
+ declare enum GraphType {
8
+ LINE = "line",
9
+ SCATTER = "scatter",
10
+ BAR = "bar",
11
+ PIE = "pie",
12
+ BOX_AND_WHISKER = "box_and_whisker",
13
+ SUPERGRAPH = "supergraph",
14
+ UNKNOWN = "unknown"
15
+ }
16
+ /**
17
+ * Ax scale types
18
+ */
19
+ declare enum ScaleType {
20
+ LINEAR = "linear",
21
+ DATETIME = "datetime",
22
+ CATEGORICAL = "categorical",
23
+ LOG = "log",
24
+ SYMLOG = "symlog",
25
+ LOGIT = "logit",
26
+ FUNCTION = "function",
27
+ FUNCTIONLOG = "functionlog",
28
+ ASINH = "asinh"
29
+ }
30
+ type Graph = {
31
+ type: GraphType;
32
+ title: string;
33
+ elements: any[];
34
+ };
35
+ type Graph2D = Graph & {
36
+ x_label?: string;
37
+ y_label?: string;
38
+ x_unit?: string;
39
+ y_unit?: string;
40
+ };
41
+ type PointData = {
42
+ label: string;
43
+ points: [number | string, number | string][];
44
+ };
45
+ type PointGraph = Graph2D & {
46
+ x_ticks: (number | string)[];
47
+ x_scale: ScaleType;
48
+ x_tick_labels: string[];
49
+ y_ticks: (number | string)[];
50
+ y_scale: ScaleType;
51
+ y_tick_labels: string[];
52
+ elements: PointData[];
53
+ };
54
+ type LineGraph = PointGraph & {
55
+ type: GraphType.LINE;
56
+ };
57
+ type ScatterGraph = PointGraph & {
58
+ type: GraphType.SCATTER;
59
+ };
60
+ type BarData = {
61
+ label: string;
62
+ value: string;
63
+ group: string;
64
+ };
65
+ type BarGraph = Graph2D & {
66
+ type: GraphType.BAR;
67
+ elements: BarData[];
68
+ };
69
+ type PieData = {
70
+ label: string;
71
+ angle: number;
72
+ radius: number;
73
+ };
74
+ type PieGraph = Graph & {
75
+ type: GraphType.PIE;
76
+ elements: PieData[];
77
+ };
78
+ type BoxAndWhiskerData = {
79
+ label: string;
80
+ min: number;
81
+ first_quartile: number;
82
+ median: number;
83
+ third_quartile: number;
84
+ max: number;
85
+ };
86
+ type BoxAndWhiskerGraph = Graph2D & {
87
+ type: GraphType.BOX_AND_WHISKER;
88
+ elements: BoxAndWhiskerData[];
89
+ };
90
+ type SuperGraph = Graph & {
91
+ type: GraphType.SUPERGRAPH;
92
+ elements: Graph[];
93
+ };
94
+ type GraphTypes = LineGraph | ScatterGraph | BarGraph | PieGraph | BoxAndWhiskerGraph | SuperGraph;
95
+
4
96
  declare class OutputMessage {
5
97
  readonly line: string;
6
98
  /**
@@ -50,12 +142,16 @@ declare class ExecutionError {
50
142
  * Represents a MIME type.
51
143
  */
52
144
  type MIMEType = string;
145
+ type E2BData = {
146
+ data: Record<string, unknown>;
147
+ graph: GraphTypes;
148
+ };
53
149
  /**
54
- * Dictionary that maps MIME types to their corresponding string representations of the data.
150
+ * Dictionary that maps MIME types to their corresponding representations of the data.
55
151
  */
56
152
  type RawData = {
57
153
  [key: MIMEType]: string;
58
- };
154
+ } & E2BData;
59
155
  /**
60
156
  * Represents the data to be displayed as a result of executing a cell in a Jupyter notebook.
61
157
  * The result is similar to the structure returned by ipython kernel: https://ipython.readthedocs.io/en/stable/development/execution.html#execution-semantics
@@ -107,6 +203,14 @@ declare class Result {
107
203
  * JavaScript representation of the data.
108
204
  */
109
205
  readonly javascript?: string;
206
+ /**
207
+ * Contains the data from DataFrame.
208
+ */
209
+ readonly data?: Record<string, unknown>;
210
+ /**
211
+ * Contains the graph data.
212
+ */
213
+ readonly graph?: GraphTypes;
110
214
  /**
111
215
  * Extra data that can be included. Not part of the standard types.
112
216
  */
@@ -200,33 +304,79 @@ declare class Execution {
200
304
  };
201
305
  }
202
306
 
307
+ /**
308
+ * Code interpreter module for executing code in a stateful context.
309
+ */
203
310
  declare class JupyterExtension {
204
311
  private readonly url;
205
312
  private readonly connectionConfig;
206
313
  private static readonly execTimeoutMs;
207
314
  private static readonly defaultKernelID;
208
315
  constructor(url: string, connectionConfig: ConnectionConfig);
316
+ /**
317
+ * Runs the code in the specified context, if not specified, the default context is used.
318
+ * You can reference previously defined variables, imports, and functions in the code.
319
+ *
320
+ * @param code The code to execute
321
+ * @param opts Options for executing the code
322
+ * @param opts.kernelID The context ID to run the code in
323
+ * @param opts.onStdout Callback for handling stdout messages
324
+ * @param opts.onStderr Callback for handling stderr messages
325
+ * @param opts.onResult Callback for handling the final result
326
+ * @param opts.envs Environment variables to set for the execution
327
+ * @param opts.timeoutMs Max time to wait for the execution to finish
328
+ * @param opts.requestTimeoutMs Max time to wait for the request to finish
329
+ * @returns Execution object
330
+ */
209
331
  execCell(code: string, opts?: {
210
332
  kernelID?: string;
211
333
  onStdout?: (output: OutputMessage) => (Promise<any> | any);
212
334
  onStderr?: (output: OutputMessage) => (Promise<any> | any);
213
335
  onResult?: (data: Result) => (Promise<any> | any);
336
+ envs?: Record<string, string>;
214
337
  timeoutMs?: number;
215
338
  requestTimeoutMs?: number;
216
339
  }): Promise<Execution>;
340
+ /**
341
+ * Creates a new context to run code in.
342
+ *
343
+ * @param cwd The working directory for the context
344
+ * @param kernelName The name of the context
345
+ * @param requestTimeoutMs Max time to wait for the request to finish
346
+ * @returns The context ID
347
+ */
217
348
  createKernel({ cwd, kernelName, requestTimeoutMs, }?: {
218
349
  cwd?: string;
219
350
  kernelName?: string;
220
351
  requestTimeoutMs?: number;
221
352
  }): Promise<string>;
353
+ /**
354
+ * Restarts the context.
355
+ * Restarting will clear all variables, imports, and other settings set during previous executions.
356
+ *
357
+ * @param kernelID The context ID to restart
358
+ * @param requestTimeoutMs Max time to wait for the request to finish
359
+ */
222
360
  restartKernel({ kernelID, requestTimeoutMs, }?: {
223
361
  kernelID?: string;
224
362
  requestTimeoutMs?: number;
225
363
  }): Promise<void>;
364
+ /**
365
+ * Shuts down the context.
366
+ *
367
+ * @param kernelID The context ID to shut down
368
+ * @param requestTimeoutMs Max time to wait for the request to finish
369
+ */
226
370
  shutdownKernel({ kernelID, requestTimeoutMs, }?: {
227
371
  kernelID?: string;
228
372
  requestTimeoutMs?: number;
229
373
  }): Promise<void>;
374
+ /**
375
+ * Lists all available contexts.
376
+ *
377
+ * @param requestTimeoutMs Max time to wait for the request to finish
378
+ * @returns List of context IDs and names
379
+ */
230
380
  listKernels({ requestTimeoutMs, }?: {
231
381
  requestTimeoutMs?: number;
232
382
  }): Promise<{
@@ -234,10 +384,13 @@ declare class JupyterExtension {
234
384
  name: string;
235
385
  }[]>;
236
386
  }
237
- declare class CodeInterpreter extends Sandbox {
387
+ /**
388
+ * Code interpreter module for executing code in a stateful context.
389
+ */
390
+ declare class Sandbox extends Sandbox$1 {
238
391
  protected static readonly defaultTemplate: string;
239
392
  protected static readonly jupyterPort = 49999;
240
393
  readonly notebook: JupyterExtension;
241
394
  }
242
395
 
243
- export { CodeInterpreter, Execution, ExecutionError, JupyterExtension, type Logs, type MIMEType, OutputMessage, type RawData, Result, CodeInterpreter as default };
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 };