diff --git a/.changeset/add-language-overloads.md b/.changeset/add-language-overloads.md new file mode 100644 index 00000000..0a1f00bd --- /dev/null +++ b/.changeset/add-language-overloads.md @@ -0,0 +1,6 @@ +--- +"@e2b/code-interpreter": patch +"e2b-code-interpreter": patch +--- + +Add autocomplete support for javascript, typescript, r, java, and bash languages in runCode/run_code and createCodeContext/create_code_context diff --git a/js/src/sandbox.ts b/js/src/sandbox.ts index a02b9d9e..5d12b93a 100644 --- a/js/src/sandbox.ts +++ b/js/src/sandbox.ts @@ -88,7 +88,16 @@ export interface CreateCodeContextOpts { * * @default python */ - language?: string + /* eslint-disable @typescript-eslint/ban-types */ + language?: + | 'python' + | 'javascript' + | 'typescript' + | 'r' + | 'java' + | 'bash' + | (string & {}) + /* eslint-enable @typescript-eslint/ban-types */ /** * Timeout for the request in **milliseconds**. * @@ -128,29 +137,6 @@ export class Sandbox extends BaseSandbox { )}` } - /** - * Run the code as Python. - * - * Specify the `language` or `context` option to run the code as a different language or in a different `Context`. - * - * You can reference previously defined variables, imports, and functions in the code. - * - * @param code code to execute. - * @param opts options for executing the code. - * - * @returns `Execution` result object. - */ - async runCode( - code: string, - opts?: RunCodeOpts & { - /** - * Language to use for code execution. - * - * If not defined, the default Python context is used. - */ - language?: 'python' - } - ): Promise /** * Run the code for the specified language. * @@ -172,7 +158,16 @@ export class Sandbox extends BaseSandbox { * * If not defined, the default Python context is used. */ - language?: string + /* eslint-disable @typescript-eslint/ban-types */ + language?: + | 'python' + | 'javascript' + | 'typescript' + | 'r' + | 'java' + | 'bash' + | (string & {}) + /* eslint-enable @typescript-eslint/ban-types */ } ): Promise /** diff --git a/python/e2b_code_interpreter/code_interpreter_async.py b/python/e2b_code_interpreter/code_interpreter_async.py index de938240..68001c19 100644 --- a/python/e2b_code_interpreter/code_interpreter_async.py +++ b/python/e2b_code_interpreter/code_interpreter_async.py @@ -68,41 +68,11 @@ def _client(self) -> AsyncClient: async def run_code( self, code: str, - language: Union[Literal["python"], None] = None, - on_stdout: Optional[OutputHandlerWithAsync[OutputMessage]] = None, - on_stderr: Optional[OutputHandlerWithAsync[OutputMessage]] = None, - on_result: Optional[OutputHandlerWithAsync[Result]] = None, - on_error: Optional[OutputHandlerWithAsync[ExecutionError]] = None, - envs: Optional[Dict[str, str]] = None, - timeout: Optional[float] = None, - request_timeout: Optional[float] = None, - ) -> Execution: - """ - Runs the code as Python. - - Specify the `language` or `context` option to run the code as a different language or in a different `Context`. - - You can reference previously defined variables, imports, and functions in the code. - - :param code: Code to execute - :param language: Language to use for code execution. If not defined, the default Python context is used. - :param on_stdout: Callback for stdout messages - :param on_stderr: Callback for stderr messages - :param on_result: Callback for the `Result` object - :param on_error: Callback for the `ExecutionError` object - :param envs: Custom environment variables - :param timeout: Timeout for the code execution in **seconds** - :param request_timeout: Timeout for the request in **seconds** - - :return: `Execution` result object - """ - ... - - @overload - async def run_code( - self, - code: str, - language: Optional[str] = None, + language: Union[ + Literal["python", "javascript", "typescript", "r", "java", "bash"], + str, + None, + ] = None, on_stdout: Optional[OutputHandlerWithAsync[OutputMessage]] = None, on_stderr: Optional[OutputHandlerWithAsync[OutputMessage]] = None, on_result: Optional[OutputHandlerWithAsync[Result]] = None, @@ -236,7 +206,11 @@ async def run_code( async def create_code_context( self, cwd: Optional[str] = None, - language: Optional[str] = None, + language: Union[ + Literal["python", "javascript", "typescript", "r", "java", "bash"], + str, + None, + ] = None, request_timeout: Optional[float] = None, ) -> Context: """ diff --git a/python/e2b_code_interpreter/code_interpreter_sync.py b/python/e2b_code_interpreter/code_interpreter_sync.py index 3adb2804..8e6eb743 100644 --- a/python/e2b_code_interpreter/code_interpreter_sync.py +++ b/python/e2b_code_interpreter/code_interpreter_sync.py @@ -65,41 +65,11 @@ def _client(self) -> Client: def run_code( self, code: str, - language: Union[Literal["python"], None] = None, - on_stdout: Optional[OutputHandler[OutputMessage]] = None, - on_stderr: Optional[OutputHandler[OutputMessage]] = None, - on_result: Optional[OutputHandler[Result]] = None, - on_error: Optional[OutputHandler[ExecutionError]] = None, - envs: Optional[Dict[str, str]] = None, - timeout: Optional[float] = None, - request_timeout: Optional[float] = None, - ) -> Execution: - """ - Runs the code as Python. - - Specify the `language` or `context` option to run the code as a different language or in a different `Context`. - - You can reference previously defined variables, imports, and functions in the code. - - :param code: Code to execute - :param language: Language to use for code execution. If not defined, the default Python context is used. - :param on_stdout: Callback for stdout messages - :param on_stderr: Callback for stderr messages - :param on_result: Callback for the `Result` object - :param on_error: Callback for the `ExecutionError` object - :param envs: Custom environment variables - :param timeout: Timeout for the code execution in **seconds** - :param request_timeout: Timeout for the request in **seconds** - - :return: `Execution` result object - """ - ... - - @overload - def run_code( - self, - code: str, - language: Optional[str] = None, + language: Union[ + Literal["python", "javascript", "typescript", "r", "java", "bash"], + str, + None, + ] = None, on_stdout: Optional[OutputHandler[OutputMessage]] = None, on_stderr: Optional[OutputHandler[OutputMessage]] = None, on_result: Optional[OutputHandler[Result]] = None, @@ -232,7 +202,11 @@ def run_code( def create_code_context( self, cwd: Optional[str] = None, - language: Optional[str] = None, + language: Union[ + Literal["python", "javascript", "typescript", "r", "java", "bash"], + str, + None, + ] = None, request_timeout: Optional[float] = None, ) -> Context: """