Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Rename `sandboxID` to `sandboxId`

Jakub Novak3f1b6e1a2a97
diff --git a/packages/js-sdk/src/sandbox/index.ts b/packages/js-sdk/src/sandbox/index.ts
index 432da5b0c..a5a78fe80 100644
--- a/packages/js-sdk/src/sandbox/index.ts
+++ b/packages/js-sdk/src/sandbox/index.ts
@@ -11,13 +11,6 @@ import { EnvdApiClient, handleEnvdApiError } from '../envd/api'
// @ts-ignore
Symbol.asyncDispose ??= Symbol('Symbol.asyncDispose')
-export interface RunningSandbox {
- sandboxID: string
- templateID: string
- name?: string
- metadata?: Record<string, string>
- startedAt: Date
-}
export interface SandboxOpts extends ConnectionOpts {
metadata?: Record<string, string>
@@ -38,7 +31,7 @@ export class Sandbox extends SandboxApi {
private readonly envdApiUrl: string
private readonly envdApi: EnvdApiClient
- constructor(readonly sandboxID: string, opts?: Omit<SandboxOpts, 'timeoutMs' | 'metadata'>) {
+ constructor(readonly sandboxId: string, opts?: Omit<SandboxOpts, 'timeoutMs' | 'metadata'>) {
super()
this.connectionConfig = new ConnectionConfig(opts)
@@ -65,19 +58,19 @@ export class Sandbox extends SandboxApi {
const config = new ConnectionConfig(sandboxOpts)
- const sandboxID = config.debug
+ const sandboxId = config.debug
? 'debug_sandbox_id'
: await this.createSandbox(template, sandboxOpts?.timeoutMs ?? this.defaultSandboxTimeoutMs, sandboxOpts)
- const sbx = new this(sandboxID, config) as InstanceType<S>
+ const sbx = new this(sandboxId, config) as InstanceType<S>
await sbx.onInit(config)
return sbx
}
- static async connect<S extends typeof Sandbox>(this: S, sandboxID: string, opts?: Omit<SandboxOpts, 'metadata' | 'timeoutMs'>): Promise<InstanceType<S>> {
+ static async connect<S extends typeof Sandbox>(this: S, sandboxId: string, opts?: Omit<SandboxOpts, 'metadata' | 'timeoutMs'>): Promise<InstanceType<S>> {
const config = new ConnectionConfig(opts)
- const sbx = new this(sandboxID, config) as InstanceType<S>
+ const sbx = new this(sandboxId, config) as InstanceType<S>
await sbx.onInit(config)
return sbx
}
@@ -87,7 +80,7 @@ export class Sandbox extends SandboxApi {
return `localhost:${port}`
}
- return `${port}-${this.sandboxID}.${this.connectionConfig.domain}`
+ return `${port}-${this.sandboxId}.${this.connectionConfig.domain}`
}
uploadUrl(path?: string) {
@@ -118,11 +111,11 @@ export class Sandbox extends SandboxApi {
}
async setTimeout(timeoutMs: number, opts?: Pick<SandboxOpts, 'requestTimeoutMs'>) {
- await Sandbox.setTimeout(this.sandboxID, timeoutMs, { ...this.connectionConfig, ...opts })
+ await Sandbox.setTimeout(this.sandboxId, timeoutMs, { ...this.connectionConfig, ...opts })
}
async kill(opts?: Pick<SandboxOpts, 'requestTimeoutMs'>) {
- await Sandbox.kill(this.sandboxID, { ...this.connectionConfig, ...opts })
+ await Sandbox.kill(this.sandboxId, { ...this.connectionConfig, ...opts })
}
async[Symbol.asyncDispose]() {
diff --git a/packages/js-sdk/src/sandbox/sandboxApi.ts b/packages/js-sdk/src/sandbox/sandboxApi.ts
index e43617d6c..f16789f97 100644
--- a/packages/js-sdk/src/sandbox/sandboxApi.ts
+++ b/packages/js-sdk/src/sandbox/sandboxApi.ts
@@ -12,12 +12,12 @@ export interface SandboxInfo {
/**
* Sandbox ID.
*/
- sandboxID: string
+ sandboxId: string
/**
* Template ID.
*/
- templateID: string
+ templateId: string
/**
* Sandbox name.
@@ -41,17 +41,17 @@ export class SandboxApi {
/**
* Kills sandbox specified by sandbox ID.
*
- * @param sandboxID - Sandbox ID.
+ * @param sandboxId - Sandbox ID.
* @param opts - Connection options.
*/
- static async kill(sandboxID: string, opts?: SandboxApiOpts): Promise<boolean> {
+ static async kill(sandboxId: string, opts?: SandboxApiOpts): Promise<boolean> {
const config = new ConnectionConfig(opts)
const client = new ApiClient(config)
const res = await client.api.DELETE('/sandboxes/{sandboxID}', {
params: {
path: {
- sandboxID,
+ sandboxID: sandboxId,
},
},
})
@@ -80,22 +80,22 @@ export class SandboxApi {
}
return res.data?.map((sandbox) => ({
- sandboxID: this.getSandboxID(sandbox),
- templateID: sandbox.templateID,
+ sandboxId: this.getSandboxId({sandboxId: sandbox.sandboxID, clientId: sandbox.clientID}),
+ templateId: sandbox.templateID,
...(sandbox.alias && { name: sandbox.alias }),
...(sandbox.metadata && { metadata: sandbox.metadata }),
startedAt: new Date(sandbox.startedAt),
})) ?? []
}
- static async setTimeout(sandboxID: string, timeoutMs: number, opts?: SandboxApiOpts): Promise<void> {
+ static async setTimeout(sandboxId: string, timeoutMs: number, opts?: SandboxApiOpts): Promise<void> {
const config = new ConnectionConfig(opts)
const client = new ApiClient(config)
const res = await client.api.POST('/sandboxes/{sandboxID}/timeout', {
params: {
path: {
- sandboxID,
+ sandboxID: sandboxId,
},
},
body: {
@@ -132,20 +132,20 @@ export class SandboxApi {
}
if (compareVersions(res.data!.envdVersion, '0.1.0') < 0) {
- await this.kill(this.getSandboxID(res.data!), opts)
+ await this.kill(this.getSandboxId({sandboxId: res.data!.sandboxID, clientId: res.data!.clientID}), opts)
throw new TemplateError(
'You need to update the template to use the new SDK. ' +
'You can do this by running `e2b template build` in the directory with the template.'
)
}
- return this.getSandboxID(res.data!)
+ return this.getSandboxId({sandboxId: res.data!.sandboxID, clientId: res.data!.clientID})
}
private static timeoutToSeconds(timeout: number): number {
return Math.ceil(timeout / 1000)
}
- private static getSandboxID({ sandboxID, clientID }: { sandboxID: string, clientID: string }): string {
- return `${sandboxID}-${clientID}`
+ private static getSandboxId({ sandboxId, clientId }: { sandboxId: string, clientId: string }): string {
+ return `${sandboxId}-${clientId}`
}
}