Skip to content

Commit f7bc0ba

Browse files
committed
Remove crypto dependency
1 parent 768b9a0 commit f7bc0ba

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

js/src/messaging.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import IWebSocket from 'isomorphic-ws'
22
import { ProcessMessage } from 'e2b'
3+
import { id } from './utils'
34

45
/**
56
* Represents an error that occurred during the execution of a cell.
@@ -43,7 +44,7 @@ export type RawData = {
4344

4445
/**
4546
* Represents the data to be displayed as a result of executing a cell in a Jupyter notebook.
46-
* This is result returned by ipython kernel: https://ipython.readthedocs.io/en/stable/development/execution.html#execution-semantics
47+
* The result is similar to the structure returned by ipython kernel: https://ipython.readthedocs.io/en/stable/development/execution.html#execution-semantics
4748
*
4849
*
4950
* The result can contain multiple types of data, such as text, images, plots, etc. Each type of data is represented
@@ -348,7 +349,7 @@ export class JupyterKernelWebSocket {
348349
timeout?: number
349350
) {
350351
return new Promise<Execution>((resolve, reject) => {
351-
const msg_id = crypto.randomUUID()
352+
const msg_id = id(16)
352353
const data = this.sendExecuteRequest(msg_id, code)
353354

354355
// give limited time for response
@@ -409,7 +410,7 @@ export class JupyterKernelWebSocket {
409410
* @param code Code to be executed.
410411
*/
411412
private sendExecuteRequest(msg_id: string, code: string) {
412-
const session = crypto.randomUUID()
413+
const session = id(16)
413414
return {
414415
header: {
415416
msg_id: msg_id,

js/src/utils.ts

+11
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,14 @@ export function createDeferredPromise<T = void>() {
1414
resolve: resolve!
1515
}
1616
}
17+
18+
export function id(length: number) {
19+
let result = ''
20+
const characters =
21+
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
22+
const charactersLength = characters.length
23+
for (let i = 0; i < length; i++) {
24+
result += characters.charAt(Math.floor(Math.random() * charactersLength))
25+
}
26+
return result
27+
}

js/tests/kernels.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test('independence of kernels', async () => {
1313
const sandbox = await CodeInterpreter.create()
1414
await sandbox.notebook.execCell('x = 1')
1515
const kernelID = await sandbox.notebook.createKernel()
16-
const output = await sandbox.notebook.execCell('x', kernelID)
16+
const output = await sandbox.notebook.execCell('x', { kernelID })
1717

1818
expect(output.error!.value).toEqual("name 'x' is not defined")
1919

python/e2b_code_interpreter/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class MIMEType(str):
3535
class Result:
3636
"""
3737
Represents the data to be displayed as a result of executing a cell in a Jupyter notebook.
38-
This is result returned by ipython kernel: https://ipython.readthedocs.io/en/stable/development/execution.html#execution-semantics
38+
The result is similar to the structure returned by ipython kernel: https://ipython.readthedocs.io/en/stable/development/execution.html#execution-semantics
3939
4040
The result can contain multiple types of data, such as text, images, plots, etc. Each type of data is represented
4141
as a string, and the result can contain multiple types of data. The text representation is always present, and

0 commit comments

Comments
 (0)