Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Update CLI after domain parameter changes in SDK

Tomas Valenta26ddefa7d049
diff --git a/packages/cli/src/api.ts b/packages/cli/src/api.ts
index 6df8294c7..b080dae6c 100644
--- a/packages/cli/src/api.ts
+++ b/packages/cli/src/api.ts
@@ -1,4 +1,5 @@
import * as boxen from 'boxen'
+import * as e2b from 'e2b'
import { getUserConfig } from './user'
import { asBold, asPrimary } from './utils/format'
@@ -50,3 +51,5 @@ export function ensureAccessToken() {
return accessToken
}
}
+
+export const client = new e2b.APIClient()
diff --git a/packages/cli/src/commands/sandbox/list.ts b/packages/cli/src/commands/sandbox/list.ts
index b95401ed3..22ba18ad8 100644
--- a/packages/cli/src/commands/sandbox/list.ts
+++ b/packages/cli/src/commands/sandbox/list.ts
@@ -2,10 +2,10 @@ import * as tablePrinter from 'console-table-printer'
import * as commander from 'commander'
import * as e2b from 'e2b'
-import { ensureAPIKey } from 'src/api'
+import { ensureAPIKey, client } from 'src/api'
const listRunningSandboxes = e2b.withAPIKey(
- e2b.api.path('/sandboxes').method('get').create(),
+ client.api.path('/sandboxes').method('get').create(),
)
export const listCommand = new commander.Command('list')
diff --git a/packages/cli/src/commands/template/build.ts b/packages/cli/src/commands/template/build.ts
index 36e1adfc1..a09a9abe1 100644
--- a/packages/cli/src/commands/template/build.ts
+++ b/packages/cli/src/commands/template/build.ts
@@ -27,25 +27,27 @@ import {
import { configName, getConfigPath, loadConfig, saveConfig } from 'src/config'
import * as child_process from 'child_process'
+import { client } from 'src/api'
+
const templateCheckInterval = 500 // 0.5 sec
const getTemplate = e2b.withAccessToken(
- e2b.api
+ client.api
.path('/templates/{templateID}/builds/{buildID}/status')
.method('get')
.create(),
)
const requestTemplateBuild = e2b.withAccessToken(
- e2b.api.path('/templates').method('post').create(),
+ client.api.path('/templates').method('post').create(),
)
const requestTemplateRebuild = e2b.withAccessToken(
- e2b.api.path('/templates/{templateID}').method('post').create(),
+ client.api.path('/templates/{templateID}').method('post').create(),
)
const triggerTemplateBuild = e2b.withAccessToken(
- e2b.api
+ client.api
.path('/templates/{templateID}/builds/{buildID}')
.method('post')
.create(),
@@ -364,9 +366,8 @@ async function waitForBuildFinish(
const pythonExample = asPython(`from e2b import Sandbox
# Start sandbox
-sandbox = Sandbox(template="${
- aliases?.length ? aliases[0] : template.data.templateID
- }")
+sandbox = Sandbox(template="${aliases?.length ? aliases[0] : template.data.templateID
+ }")
# Interact with sandbox. Learn more here:
# https://e2b.dev/docs/sandbox/overview
@@ -377,9 +378,8 @@ sandbox.close()`)
const typescriptExample = asTypescript(`import { Sandbox } from 'e2b'
// Start sandbox
-const sandbox = await Sandbox.create({ template: '${
- aliases?.length ? aliases[0] : template.data.templateID
- }' })
+const sandbox = await Sandbox.create({ template: '${aliases?.length ? aliases[0] : template.data.templateID
+ }' })
// Interact with sandbox. Learn more here:
// https://e2b.dev/docs/sandbox/overview
@@ -534,24 +534,21 @@ async function requestBuildTemplate(
if (error.code === 401) {
throw new Error(
- `Authentication error: ${res.statusText}, ${
- error.message ?? 'no message'
+ `Authentication error: ${res.statusText}, ${error.message ?? 'no message'
}`,
)
}
if (error.code === 404) {
throw new Error(
- `Sandbox template you want to build ${
- templateID ? `(${templateID})` : ''
- } not found: ${res.statusText}, ${error.message ?? 'no message'}\n${
- hasConfig
- ? `This could be caused by ${asLocalRelative(
- configPath,
- )} belonging to a deleted template or a template that you don't own. If so you can delete the ${asLocalRelative(
- configPath,
- )} and start building the template again.`
- : ''
+ `Sandbox template you want to build ${templateID ? `(${templateID})` : ''
+ } not found: ${res.statusText}, ${error.message ?? 'no message'}\n${hasConfig
+ ? `This could be caused by ${asLocalRelative(
+ configPath,
+ )} belonging to a deleted template or a template that you don't own. If so you can delete the ${asLocalRelative(
+ configPath,
+ )} and start building the template again.`
+ : ''
}`,
)
}
@@ -585,8 +582,7 @@ async function triggerBuild(
if (error.code === 401) {
throw new Error(
- `Authentication error: ${res.statusText}, ${
- error.message ?? 'no message'
+ `Authentication error: ${res.statusText}, ${error.message ?? 'no message'
}`,
)
}
diff --git a/packages/cli/src/commands/template/delete.ts b/packages/cli/src/commands/template/delete.ts
index 0874c9d3d..81333396d 100644
--- a/packages/cli/src/commands/template/delete.ts
+++ b/packages/cli/src/commands/template/delete.ts
@@ -24,9 +24,10 @@ import { getRoot } from 'src/utils/filesystem'
import { listSandboxTemplates } from './list'
import { getPromptTemplates } from 'src/utils/templatePrompt'
import { confirm } from 'src/utils/confirm'
+import { client } from 'src/api'
const deleteTemplate = e2b.withAccessToken(
- e2b.api.path('/templates/{templateID}').method('delete').create(),
+ client.api.path('/templates/{templateID}').method('delete').create(),
)
export const deleteCommand = new commander.Command('delete')
@@ -133,8 +134,7 @@ export const deleteCommand = new commander.Command('delete')
if (!opts.yes) {
const confirmed = await confirm(
- `Do you really want to delete ${
- templates.length === 1 ? 'this template' : 'these templates'
+ `Do you really want to delete ${templates.length === 1 ? 'this template' : 'these templates'
}?`,
)
diff --git a/packages/cli/src/commands/template/list.ts b/packages/cli/src/commands/template/list.ts
index acb357a2b..bd41896e2 100644
--- a/packages/cli/src/commands/template/list.ts
+++ b/packages/cli/src/commands/template/list.ts
@@ -5,9 +5,10 @@ import * as e2b from 'e2b'
import { ensureAccessToken } from 'src/api'
import { listAliases } from '../../utils/format'
import { sortTemplatesAliases } from 'src/utils/templateSort'
+import { client } from 'src/api'
const listTemplates = e2b.withAccessToken(
- e2b.api.path('/templates').method('get').create(),
+ client.api.path('/templates').method('get').create(),
)
export const listCommand = new commander.Command('list')
diff --git a/packages/js-sdk/src/api/index.ts b/packages/js-sdk/src/api/index.ts
index c15aed244..1c93f74b5 100644
--- a/packages/js-sdk/src/api/index.ts
+++ b/packages/js-sdk/src/api/index.ts
@@ -10,7 +10,7 @@ const { Fetcher } = fetcher
class APIClient {
private client = Fetcher.for<paths>()
- constructor(private opts: {
+ constructor(private opts?: {
secure?: boolean,
domain?: string,
debug?: boolean,
@@ -25,15 +25,15 @@ class APIClient {
}
get secure() {
- return this.opts.secure ?? SECURE
+ return this.opts?.secure ?? SECURE
}
get domain() {
- return this.opts.domain ?? DOMAIN
+ return this.opts?.domain ?? DOMAIN
}
get debug() {
- return this.opts.debug ?? DEBUG
+ return this.opts?.debug ?? DEBUG
}
get apiDomain() {
diff --git a/packages/js-sdk/src/index.ts b/packages/js-sdk/src/index.ts
index 882d1eddb..ab5eab183 100644
--- a/packages/js-sdk/src/index.ts
+++ b/packages/js-sdk/src/index.ts
@@ -1,5 +1,5 @@
-export { default as api, withAPIKey, withAccessToken } from './api'
-export type { ClientType, components, paths } from './api'
+export { APIClient, withAPIKey, withAccessToken } from './api'
+export type { components, paths } from './api'
export { SANDBOX_DOMAIN, API_HOST } from './constants'
export type { SandboxOpts, DownloadFileFormat } from './sandbox'