Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Fix browser + node compatibility [WIP]

Tomas Valentab9132a89ab14
diff --git a/packages/js-sdk/package.json b/packages/js-sdk/package.json
index 7380f983b..bdd829962 100644
--- a/packages/js-sdk/package.json
+++ b/packages/js-sdk/package.json
@@ -31,7 +31,8 @@
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"test-smoke": "vitest run _smoke",
- "generate": "openapi-typescript ../../openapi.yml -x api_key --support-array-length --alphabetize --output src/api/schema.gen.ts"
+ "generate": "openapi-typescript ../../openapi.yml -x api_key --support-array-length --alphabetize --output src/api/schema.gen.ts",
+ "check-deps": "knip"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^14.1.0",
@@ -43,6 +44,7 @@
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@typescript-eslint/parser": "^5.38.1",
"jsdom": "^22.1.0",
+ "knip": "^2.25.2",
"markdown-it": "^13.0.2",
"openai": "^4.12.1",
"openapi-typescript": "^5.4.1",
@@ -75,9 +77,10 @@
"dependencies": {
"@types/node-fetch": "^2.6.5",
"bufferutil": "^4.0.7",
+ "cross-blob": "^3.0.2",
"cross-fetch": "^3.1.5",
"form-data": "^4.0.0",
- "node-fetch": "^2.7.0",
+ "formdata-polyfill": "^4.0.10",
"normalize-path": "^3.0.0",
"openapi-typescript-fetch": "^1.1.3",
"platform": "^1.3.6",
diff --git a/packages/js-sdk/src/session/index.ts b/packages/js-sdk/src/session/index.ts
index b16d81fe3..3029e9f7b 100644
--- a/packages/js-sdk/src/session/index.ts
+++ b/packages/js-sdk/src/session/index.ts
@@ -1,6 +1,7 @@
import normalizePath from 'normalize-path'
-import FormData from 'form-data'
-import fetch from 'node-fetch'
+import fetch from 'cross-fetch'
+import { FormData } from 'formdata-polyfill/esm.min.js'
+import Blob from 'cross-blob'
import { ENVD_PORT } from '../constants'
import { components } from '../api'
@@ -389,7 +390,7 @@ export class Session extends SessionConnection {
const portsHandler = this.onScanPorts
? (ports: { State: string; Ip: string; Port: number }[]) =>
- this.onScanPorts?.(ports.map(p => ({ ip: p.Ip, port: p.Port, state: p.State })))
+ this.onScanPorts?.(ports.map(p => ({ ip: p.Ip, port: p.Port, state: p.State })))
: undefined
await this.handleSubscriptions(
@@ -412,9 +413,14 @@ export class Session extends SessionConnection {
*/
async uploadFile(file: Buffer | Blob, filename: string) {
const formData = new FormData()
- formData.append('file', file, {
+
+ formData.append(
+ 'file',
+ file instanceof Blob
+ ? file
+ : new Blob([file.buffer], { type: 'application/octet-stream' }),
filename,
- })
+ )
const response = await fetch(this.fileURL, {
method: 'POST',
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 0567d56b1..070ebd2f8 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -351,15 +351,18 @@ importers:
bufferutil:
specifier: ^4.0.7
version: 4.0.7
+ cross-blob:
+ specifier: ^3.0.2
+ version: 3.0.2
cross-fetch:
specifier: ^3.1.5
version: 3.1.8
form-data:
specifier: ^4.0.0
version: 4.0.0
- node-fetch:
- specifier: ^2.7.0
- version: 2.7.0
+ formdata-polyfill:
+ specifier: ^4.0.10
+ version: 4.0.10
normalize-path:
specifier: ^3.0.0
version: 3.0.0
@@ -403,6 +406,9 @@ importers:
jsdom:
specifier: ^22.1.0
+ knip:
+ specifier: ^2.25.2
+ version: 2.25.2
markdown-it:
specifier: ^13.0.2
version: 13.0.2