Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Fix API key check in JS SDK & remove deprecated fields (#869)
Jakub Novákc2195d832f0d
diff --git a/.changeset/grumpy-insects-rescue.md b/.changeset/grumpy-insects-rescue.mdnew file mode 100644index 000000000..b8cf3c2a5--- /dev/null+++ b/.changeset/grumpy-insects-rescue.md@@ -0,0 +1,6 @@+---+'@e2b/cli': patch+---++Fix the api key check+Remove deprecated fields from the config\ No newline at end of filediff --git a/packages/cli/src/api.ts b/packages/cli/src/api.tsindex 027677d28..7a6fd7bd6 100644--- a/packages/cli/src/api.ts+++ b/packages/cli/src/api.ts@@ -47,7 +47,7 @@ export function ensureAPIKey() {// If apiKey is not already set (either from env var or from user config), try to get it from config fileif (!apiKey) {const userConfig = getUserConfig()- apiKey = userConfig?.teamApiKey || userConfig?.defaultTeamApiKey+ apiKey = userConfig?.teamApiKey}if (!apiKey) {diff --git a/packages/cli/src/commands/template/delete.ts b/packages/cli/src/commands/template/delete.tsindex 69534d098..f3651256c 100644--- a/packages/cli/src/commands/template/delete.ts+++ b/packages/cli/src/commands/template/delete.ts@@ -2,7 +2,6 @@ import * as commander from 'commander'import * as chalk from 'chalk'import * as fs from 'fs'-import {asBold,asFormattedError,@@ -49,10 +48,10 @@ export const deleteCommand = new commander.Command('delete').argument('[template]',`specify ${asBold('[template]')} to delete it. If you dont specify ${asBold(- '[template]',+ '[template]')} the command will try to delete sandbox template defined by ${asLocal(- 'e2b.toml',- )}.`,+ 'e2b.toml'+ )}.`).addOption(pathOption).addOption(configOption)@@ -69,7 +68,7 @@ export const deleteCommand = new commander.Command('delete')yes?: booleanselect?: booleanteam?: string- },+ }) => {try {let teamId = opts.team@@ -87,7 +86,7 @@ export const deleteCommand = new commander.Command('delete')} else if (opts.select) {const userConfig = getUserConfig()if (userConfig) {- teamId = teamId || userConfig.teamId || userConfig.defaultTeamId! // default team ID is here for backwards compatibility+ teamId = teamId || userConfig.teamId}const allTemplates = await listSandboxTemplates({@@ -96,13 +95,13 @@ export const deleteCommand = new commander.Command('delete')const selectedTemplates = await getPromptTemplates(allTemplates,- 'Select sandbox templates to delete',+ 'Select sandbox templates to delete')templates.push(...selectedTemplates.map((e) => ({template_id: e.templateID,...e,- })),+ })))if (!templates || templates.length === 0) {@@ -118,10 +117,10 @@ export const deleteCommand = new commander.Command('delete')if (!config) {console.log(`No ${asLocal(configName)} found in ${asLocalRelative(- root,+ root)}. Specify sandbox template with ${asBold(- '[template]',- )} argument or use interactive mode with ${asBold('-s')} flag.`,+ '[template]'+ )} argument or use interactive mode with ${asBold('-s')} flag.`)return}@@ -135,24 +134,24 @@ export const deleteCommand = new commander.Command('delete')if (!templates || templates.length === 0) {console.log(`No sandbox templates selected. Specify sandbox template with ${asBold(- '[template]',- )} argument or use interactive mode with ${asBold('-s')} flag.`,+ '[template]'+ )} argument or use interactive mode with ${asBold('-s')} flag.`)return}console.log(chalk.default.red(- chalk.default.underline('\nSandbox templates to delete'),- ),+ chalk.default.underline('\nSandbox templates to delete')+ ))templates.forEach((e) =>console.log(asFormattedSandboxTemplate({ ...e, templateID: e.template_id },- e.configPath,- ),- ),+ e.configPath+ )+ ))process.stdout.write('\n')@@ -160,7 +159,7 @@ export const deleteCommand = new commander.Command('delete')const confirmed = await confirm(`Do you really want to delete ${templates.length === 1 ? 'this template' : 'these templates'- }?`,+ }?`)if (!confirmed) {@@ -174,19 +173,19 @@ export const deleteCommand = new commander.Command('delete')console.log(`- Deleting sandbox template ${asFormattedSandboxTemplate({ ...e, templateID: e.template_id },- e.configPath,- )}`,+ e.configPath+ )}`)await deleteTemplate(e.template_id)if (e.configPath) {await deleteConfig(e.configPath)}- }),+ }))process.stdout.write('\n')} catch (err: any) {console.error(asFormattedError(err.message))process.exit(1)}- },+ })diff --git a/packages/cli/src/commands/template/list.ts b/packages/cli/src/commands/template/list.tsindex d9a4c1205..c48c9e796 100644--- a/packages/cli/src/commands/template/list.ts+++ b/packages/cli/src/commands/template/list.ts@@ -4,9 +4,10 @@ import * as e2b from 'e2b'import { listAliases } from '../../utils/format'import { sortTemplatesAliases } from 'src/utils/templateSort'-import { client, ensureAccessToken, ensureUserConfig } from 'src/api'+import { client, ensureAccessToken } from 'src/api'import { teamOption } from '../../options'import { handleE2BRequestError } from '../../utils/errors'+import { getUserConfig } from '../../user'export const listCommand = new commander.Command('list').description('list sandbox templates')@@ -14,12 +15,12 @@ export const listCommand = new commander.Command('list').addOption(teamOption).action(async (opts: { team: string }) => {try {- const userConfig = ensureUserConfig()+ const userConfig = getUserConfig()ensureAccessToken()process.stdout.write('\n')const templates = await listSandboxTemplates({- teamID: opts.team || userConfig.teamId || userConfig.defaultTeamId!, // default team ID is here for backwards compatibility)+ teamID: opts.team || userConfig?.teamId,})for (const template of templates) {diff --git a/packages/cli/src/commands/template/publish.ts b/packages/cli/src/commands/template/publish.tsindex 2058d433c..b6548dc67 100644--- a/packages/cli/src/commands/template/publish.ts+++ b/packages/cli/src/commands/template/publish.ts@@ -2,8 +2,19 @@ import * as commander from 'commander'import * as chalk from 'chalk'import * as fs from 'fs'-import { asBold, asFormattedError, asFormattedSandboxTemplate, asLocal, asLocalRelative } from 'src/utils/format'-import { configOption, pathOption, selectMultipleOption, teamOption } from 'src/options'+import {+ asBold,+ asFormattedError,+ asFormattedSandboxTemplate,+ asLocal,+ asLocalRelative,+} from 'src/utils/format'+import {+ configOption,+ pathOption,+ selectMultipleOption,+ teamOption,+} from 'src/options'import { configName, E2BConfig, getConfigPath, loadConfig } from 'src/config'import { getRoot } from 'src/utils/filesystem'import { listSandboxTemplates } from './list'@@ -59,7 +70,7 @@ async function templateAction(} else if (opts.select) {const userConfig = getUserConfig()if (userConfig) {- teamId = teamId || userConfig.teamId || userConfig.defaultTeamId! // default team ID is here for backwards compatibility+ teamId = teamId || userConfig.teamId}const allTemplates = await listSandboxTemplates({diff --git a/packages/cli/src/user.ts b/packages/cli/src/user.tsindex fc3217fe0..3e1b3129a 100644--- a/packages/cli/src/user.ts+++ b/packages/cli/src/user.ts@@ -12,16 +12,6 @@ export interface UserConfig {teamId: stringteamApiKey: stringdockerProxySet?: boolean-- /**- * @deprecated Kept for backward compatibility. Use {@link UserConfig.teamApiKey} instead.- */- defaultTeamApiKey?: string-- /**- * @deprecated Kept for backward compatibility. Use {@link UserConfig.teamId} instead.- */- defaultTeamId?: string}export const USER_CONFIG_PATH = path.join(os.homedir(), '.e2b', 'config.json') // TODO: Keep in Keychaindiff --git a/packages/cli/src/utils/format.ts b/packages/cli/src/utils/format.tsindex 85433b107..ad0842a5e 100644--- a/packages/cli/src/utils/format.ts+++ b/packages/cli/src/utils/format.ts@@ -13,7 +13,7 @@ export function asFormattedConfig(config: UserConfig) {const team = config.teamName? asBold(config.teamName): asRed('Log out and log in to get team name')- const teamId = asBold(config.teamId || config.defaultTeamId!)+ const teamId = asBold(config.teamId)return `You are logged in as ${email},\nSelected team: ${team} (${teamId})`}diff --git a/packages/js-sdk/src/api/index.ts b/packages/js-sdk/src/api/index.tsindex 2d585b596..8a3ecd942 100644--- a/packages/js-sdk/src/api/index.ts+++ b/packages/js-sdk/src/api/index.ts@@ -38,10 +38,9 @@ class ApiClient {opts: {requireAccessToken?: booleanrequireApiKey?: boolean- } = { requireAccessToken: false, requireApiKey: true }+ } = { requireAccessToken: false, requireApiKey: false }) {- // FIXME: This statement makes no sense- if (!opts?.requireApiKey && !config.apiKey) {+ if (opts?.requireApiKey && !config.apiKey) {throw new AuthenticationError('API key is required, please visit the Team tab at https://e2b.dev/dashboard to get your API key. ' +'You can either set the environment variable `E2B_API_KEY` ' +