Skip to content

Commit 5bfcc9a

Browse files
committed
Imrpove connection config; [WIP] Rework Python SDK
1 parent df8e0e2 commit 5bfcc9a

79 files changed

Lines changed: 1466 additions & 3801 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ update-api-spec:
55

66

77
generate:
8-
# cd packages/python-sdk && make generate
8+
cd packages/python-sdk && make generate
99
cd packages/js-sdk && pnpm generate
1010
cd packages/connect-python && make bin/protoc-gen-connect-python
1111
cd spec && buf generate

packages/js-sdk/example.mts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ const sandbox = await Sandbox.create({
1313
})
1414
console.log(sandbox.id)
1515

16+
await sandbox.uploadFile(Buffer.from('hello world'), 'test.txt')
17+
18+
1619
await sandbox.close()

packages/js-sdk/src/api/index.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,22 @@ import type { OpArgType, TypedFetch } from 'openapi-typescript-fetch'
33

44
import type { components, paths } from './schema.gen'
55
import { defaultHeaders } from './metadata'
6-
import { DOMAIN, DEBUG } from '../constants'
6+
import { ConnectionConfig } from '../connectionConfig'
77

88
const { Fetcher } = fetcher
99

10-
export interface APIOpts {
11-
domain?: string
12-
debug?: boolean
13-
}
14-
1510
class APIClient {
1611
private client = Fetcher.for<paths>()
1712

18-
constructor(private opts?: APIOpts) {
13+
constructor(private config: ConnectionConfig) {
1914
this.client.configure({
20-
baseUrl: this.apiHost,
15+
baseUrl: this.config.apiUrl,
2116
init: {
2217
headers: defaultHeaders,
2318
},
2419
})
2520
}
2621

27-
28-
get debug() {
29-
return this.opts?.debug ?? DEBUG
30-
}
31-
32-
get domain() {
33-
return this.opts?.domain ?? DOMAIN
34-
}
35-
36-
get apiDomain() {
37-
return this.debug ? 'localhost:3000' : `api.${this.domain}`
38-
}
39-
40-
get apiHost() {
41-
return `${this.debug ? 'http' : 'https'}://${this.apiDomain}`
42-
}
43-
4422
get api() {
4523
return this.client
4624
}

packages/js-sdk/src/api/schema.gen.ts

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { AuthenticationError } from './sandbox/errors'
2+
3+
const DOMAIN = process?.env?.E2B_DOMAIN || 'e2b.dev'
4+
const DEBUG = (process?.env?.E2B_DEBUG || 'false').toLowerCase() === 'true'
5+
const API_KEY = process?.env?.E2B_API_KEY
6+
7+
export interface ConnectionOpts {
8+
apiKey?: string
9+
domain?: string
10+
debug?: boolean
11+
}
12+
13+
export class ConnectionConfig {
14+
readonly debug: boolean
15+
readonly domain: string
16+
readonly apiUrl: string
17+
18+
private readonly _apiKey?: string
19+
20+
constructor(opts: ConnectionOpts) {
21+
this._apiKey = opts.apiKey || API_KEY
22+
this.debug = opts.debug || DEBUG
23+
this.domain = opts.domain || DOMAIN
24+
25+
this.apiUrl = this.debug ? 'http://localhost:3000' : `https://api.${this.domain}`
26+
}
27+
28+
get apiKey() {
29+
if (!this._apiKey) {
30+
throw new AuthenticationError(
31+
'API key is required, please visit https://e2b.dev/docs to get your API key. ' +
32+
'You can either set the environment variable `E2B_API_KEY` ' +
33+
"or you can pass it directly to the sandbox like Sandbox.create({ apiKey: 'e2b_...' })",
34+
)
35+
}
36+
37+
return this._apiKey
38+
}
39+
}

packages/js-sdk/src/constants.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/js-sdk/src/envd/filesystem/v1/filesystem_connect.ts

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* eslint-disable */
44
// @ts-nocheck
55

6-
import { CopyRequest, CopyResponse, CreateDirRequest, CreateDirResponse, ListDirRequest, ListDirResponse, RemoveRequest, RemoveResponse, RenameRequest, RenameResponse, StatRequest, StatResponse, WatchRequest, WatchResponse } from "./filesystem_pb.js";
6+
import { ListRequest, ListResponse, RemoveRequest, RemoveResponse, StatRequest, StatResponse, WatchRequest, WatchResponse } from "./filesystem_pb.js";
77
import { MethodKind } from "@bufbuild/protobuf";
88

99
/**
@@ -22,21 +22,12 @@ export const FilesystemService = {
2222
kind: MethodKind.Unary,
2323
},
2424
/**
25-
* @generated from rpc envd.filesystem.v1.FilesystemService.CreateDir
25+
* @generated from rpc envd.filesystem.v1.FilesystemService.List
2626
*/
27-
createDir: {
28-
name: "CreateDir",
29-
I: CreateDirRequest,
30-
O: CreateDirResponse,
31-
kind: MethodKind.Unary,
32-
},
33-
/**
34-
* @generated from rpc envd.filesystem.v1.FilesystemService.ListDir
35-
*/
36-
listDir: {
37-
name: "ListDir",
38-
I: ListDirRequest,
39-
O: ListDirResponse,
27+
list: {
28+
name: "List",
29+
I: ListRequest,
30+
O: ListResponse,
4031
kind: MethodKind.Unary,
4132
},
4233
/**
@@ -48,15 +39,6 @@ export const FilesystemService = {
4839
O: WatchResponse,
4940
kind: MethodKind.ServerStreaming,
5041
},
51-
/**
52-
* @generated from rpc envd.filesystem.v1.FilesystemService.Rename
53-
*/
54-
rename: {
55-
name: "Rename",
56-
I: RenameRequest,
57-
O: RenameResponse,
58-
kind: MethodKind.Unary,
59-
},
6042
/**
6143
* @generated from rpc envd.filesystem.v1.FilesystemService.Remove
6244
*/
@@ -66,15 +48,6 @@ export const FilesystemService = {
6648
O: RemoveResponse,
6749
kind: MethodKind.Unary,
6850
},
69-
/**
70-
* @generated from rpc envd.filesystem.v1.FilesystemService.Copy
71-
*/
72-
copy: {
73-
name: "Copy",
74-
I: CopyRequest,
75-
O: CopyResponse,
76-
kind: MethodKind.Unary,
77-
},
7851
}
7952
} as const;
8053

0 commit comments

Comments
 (0)