Skip to content

Commit

Permalink
Remove crypto dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubno committed Apr 3, 2024
1 parent 768b9a0 commit f7bc0ba
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
7 changes: 4 additions & 3 deletions js/src/messaging.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import IWebSocket from 'isomorphic-ws'
import { ProcessMessage } from 'e2b'
import { id } from './utils'

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

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

// give limited time for response
Expand Down Expand Up @@ -409,7 +410,7 @@ export class JupyterKernelWebSocket {
* @param code Code to be executed.
*/
private sendExecuteRequest(msg_id: string, code: string) {
const session = crypto.randomUUID()
const session = id(16)
return {
header: {
msg_id: msg_id,
Expand Down
11 changes: 11 additions & 0 deletions js/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,14 @@ export function createDeferredPromise<T = void>() {
resolve: resolve!
}
}

export function id(length: number) {
let result = ''
const characters =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
const charactersLength = characters.length
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength))
}
return result
}
2 changes: 1 addition & 1 deletion js/tests/kernels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('independence of kernels', async () => {
const sandbox = await CodeInterpreter.create()
await sandbox.notebook.execCell('x = 1')
const kernelID = await sandbox.notebook.createKernel()
const output = await sandbox.notebook.execCell('x', kernelID)
const output = await sandbox.notebook.execCell('x', { kernelID })

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

Expand Down
2 changes: 1 addition & 1 deletion python/e2b_code_interpreter/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MIMEType(str):
class Result:
"""
Represents the data to be displayed as a result of executing a cell in a Jupyter notebook.
This is result returned by ipython kernel: https://ipython.readthedocs.io/en/stable/development/execution.html#execution-semantics
The result is similar to the structure returned by ipython kernel: https://ipython.readthedocs.io/en/stable/development/execution.html#execution-semantics
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
Expand Down

0 comments on commit f7bc0ba

Please sign in to comment.