Skip to content

Commit

Permalink
Merge pull request #7 from e2b-dev/js-sdk
Browse files Browse the repository at this point in the history
Add JS SDK & video stream support
  • Loading branch information
mlejva authored Nov 24, 2024
2 parents 861a13b + 0e4a7b2 commit 02b1402
Show file tree
Hide file tree
Showing 35 changed files with 3,935 additions and 2,069 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/publish_packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Test Decktop SDK Packages

on:
workflow_call:
secrets:
E2B_API_KEY:
required: true
NPM_TOKEN:
required: true
PYPI_TOKEN:
required: true

permissions:
contents: write

jobs:
test:
name: Build and test SDK
runs-on: ubuntu-20.04
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"

- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: 1.5.1
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- uses: pnpm/action-setup@v3
with:
version: 9.5

- name: Setup Node.js 18
uses: actions/setup-node@v3
with:
node-version: '18.x'
cache: pnpm

- name: Configure pnpm
run: |
pnpm config set auto-install-peers true
pnpm config set exclude-links-from-lockfile true
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Create new versions
run: pnpm run version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Release new versions
uses: changesets/action@v1
with:
publish: pnpm run publish
createGithubReleases: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}

- name: Generate API Ref
run: pnpm run generate-api-reference

- name: Update lock file
run: pnpm i --no-link --no-frozen-lockfile

- name: Commit new versions
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add apps/web/src/app/\(docs\)/docs/api-reference
git commit -am "[skip ci] Release new versions" || exit 0
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45 changes: 0 additions & 45 deletions .github/workflows/python_tests.yml

This file was deleted.

93 changes: 15 additions & 78 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ jobs:
if: needs.is_release.outputs.release == 'true'
runs-on: ubuntu-latest
outputs:
python: ${{ steps.filter.outputs.python }}
js-sdk: ${{ steps.filter.outputs.js-sdk }}
python-sdk: ${{ steps.filter.outputs.python-sdk }}
cli: ${{ steps.filter.outputs.cli }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -77,93 +79,28 @@ jobs:
with:
base: ${{ steps.last_release.outputs.tag_name }}
filters: |
python:
- 'python/**'
js-sdk:
- 'packages/js-sdk/**'
python-sdk:
- 'packages/python-sdk/**'
python-tests:
name: Python Tests
needs: [changes]
if: needs.changes.outputs.python == 'true'
uses: ./.github/workflows/python_tests.yml
secrets: inherit

release:
needs: [python-tests]
publish:
name: Publish
needs: [is_release]
if: (!cancelled()) && !contains(needs.*.result, 'failure') && needs.is_release.outputs.release == 'true'
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"

- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.1
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- uses: pnpm/action-setup@v3
with:
version: 9.5

- name: Setup Node.js 18
uses: actions/setup-node@v3
with:
node-version: "18.x"
cache: pnpm

- name: Configure pnpm
run: |
pnpm config set auto-install-peers true
pnpm config set exclude-links-from-lockfile true
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Create new versions
run: pnpm run version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Release new versions
uses: changesets/action@v1
with:
publish: pnpm run publish
createGithubReleases: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}

- name: Update lock file
run: pnpm i --no-link --no-frozen-lockfile

- name: Commit new versions
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -am "[skip ci] Release new versions" || exit 0
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: ./.github/workflows/publish_packages.yml
secrets: inherit

report-failure:
needs: [python-tests, release]
needs: [publish]
if: failure()
name: Desktop Release Failed - Slack Notification
name: Release Failed - Slack Notification
runs-on: ubuntu-latest
steps:
- name: Release Failed - Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_COLOR: "#ff0000"
SLACK_MESSAGE: ":here-we-go-again: :bob-the-destroyer: We need :fix-parrot: ASAP :pray:"
SLACK_TITLE: Desktop Release Failed
SLACK_TITLE: Release Failed
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Launching E2B Sandbox takes about 300-500ms. You can customize the desktop envir

**Work in progress**
This repository is a work in progress. We welcome feedback and contributions. Here's the list of features we're working on:
- [ ] JavaScript SDK
- [ ] Streaming live desktop
- [x] JavaScript SDK
- [x] Streaming live desktop
- [ ] Tests
- [ ] Docstrings
- [x] Docstrings

## Getting started
The E2B Desktop Sandbox is built on top of [E2B Sandbox](https://e2b.dev/docs).
Expand All @@ -29,7 +29,7 @@ pip install e2b-desktop

**JavaScript**
```bash
Coming soon
npm install @e2b/desktop
```

### 3. Create Desktop Sandbox
Expand Down
55 changes: 55 additions & 0 deletions packages/js-sdk/example.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { config } from 'dotenv'
// import Tesseract from 'tesseract.js'
import { createCanvas, loadImage } from 'canvas'
import fs from 'fs'

config()
import { Sandbox } from './dist'



const sbx = await Sandbox.create({
videoStream: true,
onVideoStreamStart: (url) => console.log('Video stream started:', url)
})

// const command = "ffmpeg -video_size 1024x768 -f x11grab -i :99 -c:v libx264 -c:a aac -g 50 -b:v 4000k -maxrate 4000k -bufsize 8000k -f flv rtmp://global-live.mux.com:5222/app/stream-key"
// const ffmpeg = await sbx.commands.run(command, { background: true, onStdout: (data) => console.log(data.toString()) })

for (let i = 0; i < 30; i++) {
const x = Math.floor(Math.random() * 1024);
const y = Math.floor(Math.random() * 768);
await sbx.moveMouse(x, y);
await new Promise(resolve => setTimeout(resolve, 2000));
await sbx.rightClick();
console.log('right clicked', i)
}


// await sbx.kill()


// // await sbx.rightClick()
// let imageData = await sbx.takeScreenshot()
// await processImage(imageData)
// // const pos = await sbx.locateTextOnScreen('Applications')
// // if (!pos) throw new Error('Text not found on screen')
// await sbx.moveMouse(384 + 150, 1024 - 80)
// // await new Promise(resolve => setTimeout(resolve, 5000));
// await sbx.doubleClick()
// // await sbx.leftClick()
// console.log('clicked')
// await new Promise(resolve => setTimeout(resolve, 2000));
// console.log('screenshot')
// imageData = await sbx.takeScreenshot()
// await processImage(imageData)
// await sbx.kill()




// {
// text: 'File System',
// confidence: 95.43375396728516,
// bbox: { x0: 33, y0: 228, x1: 107, y1: 241 }
// }
62 changes: 62 additions & 0 deletions packages/js-sdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "@e2b/desktop",
"version": "1.0.0",
"description": "E2B Desktop Sandbox - isolated cloud environment with a desktop-like interface powered by E2B. Ready for AI Computer Use",
"author": {
"name": "FoundryLabs, Inc.",
"email": "[email protected]",
"url": "https://e2b.dev"
},
"keywords": [
"e2b",
"ai-agents",
"agents",
"ai",
"computer-use",
"sandbox",
"code",
"runtime",
"vm"
],
"bugs": "https://github.com/e2b-dev/desktop/issues",
"repository": {
"type": "git",
"url": "https://github.com/e2b-dev/desktop",
"directory": "packages/js-sdk"
},
"publishConfig": {
"access": "public"
},
"files": [
"dist",
"README.md",
"package.json"
],
"engines": {
"node": ">=18"
},
"browserslist": [
"defaults"
],
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc --noEmit && tsup",
"example": "tsx example.mts",
"dev": "tsup --watch",
"test": "vitest run --disable-console-intercept",
"test:coverage": "vitest run --coverage"
},
"devDependencies": {
"canvas": "^2.11.2",
"dotenv": "^16.4.5",
"tsup": "^8.3.5",
"tsx": "^4.19.2",
"typescript": "^5.6.3",
"vitest": "^2.1.5"
},
"dependencies": {
"e2b": "^1.0.5"
}
}
3 changes: 3 additions & 0 deletions packages/js-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from 'e2b'

export { Sandbox } from './sandbox'
Loading

0 comments on commit 02b1402

Please sign in to comment.