Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Make api key required in JS SDK
Tomas Valentaa29e07b2480c
diff --git a/packages/js-sdk/src/session/error.ts b/packages/js-sdk/src/session/error.tsnew file mode 100644index 000000000..410cdb22e--- /dev/null+++ b/packages/js-sdk/src/session/error.ts@@ -0,0 +1,6 @@+export class AuthenticationError extends Error {+ constructor(message: any) {+ super(message)+ this.name = 'AuthenticationError'+ }+}diff --git a/packages/js-sdk/src/session/sessionConnection.ts b/packages/js-sdk/src/session/sessionConnection.tsindex 5b22d7127..2ecbf5ab5 100644--- a/packages/js-sdk/src/session/sessionConnection.ts+++ b/packages/js-sdk/src/session/sessionConnection.ts@@ -12,6 +12,7 @@ import Logger from '../utils/logger'import { assertFulfilled, formatSettledErrors } from '../utils/promise'import wait from '../utils/wait'import { codeSnippetService } from './codeSnippet'+import { AuthenticationError } from './error'import { filesystemService } from './filesystem'import { processService } from './process'import { terminalService } from './terminal'@@ -33,9 +34,8 @@ interface Subscriber {export interface SessionConnectionOpts {id: string- apiKey?: string+ apiKey: stringdebug?: boolean- editEnabled?: boolean__debug_hostname?: string__debug_port?: number__debug_devEnv?: 'remote' | 'local'@@ -56,6 +56,12 @@ export class SessionConnection {private subscribers: Subscriber[] = []constructor(private readonly opts: SessionConnectionOpts) {+ if (!opts.apiKey) {+ throw new AuthenticationError(+ 'API key is required, please visit https://e2b.dev/docs to get your API key',+ )+ }+this.logger = new Logger('Session', opts.debug)this.logger.log(`Session for code snippet "${opts.id}" initialized`)}@@ -137,7 +143,7 @@ export class SessionConnection {const res = await createSession({api_key: this.opts.apiKey,codeSnippetID: this.opts.id,- editEnabled: this.opts.editEnabled,+ editEnabled: false,})this.session = res.datathis.logger.log('Aquired session:', this.session)