import { APIResource } from "../../core/resource.js"; import * as SessionsAPI from "./sessions.js"; import { SessionListResponse, Sessions } from "./sessions.js"; import { APIPromise } from "../../core/api-promise.js"; import { RequestOptions } from "../../internal/request-options.js"; export declare class CodeInterpreter extends APIResource { sessions: SessionsAPI.Sessions; /** * Executes the given code snippet and returns the output. Without a session_id, a * new session will be created to run the code. If you do pass in a valid * session_id, the code will be run in that session. This is useful for running * multiple code snippets in the same environment, because dependencies and similar * things are persisted between calls to the same session. * * @example * ```ts * const executeResponse = * await client.codeInterpreter.execute({ * code: "print('Hello, world!')", * language: 'python', * }); * ``` */ execute(body: CodeInterpreterExecuteParams, options?: RequestOptions): APIPromise; } /** * The result of the execution. If successful, `data` contains the result and * `errors` will be null. If unsuccessful, `data` will be null and `errors` will * contain the errors. */ export type ExecuteResponse = ExecuteResponse.SuccessfulExecution | ExecuteResponse.FailedExecution; export declare namespace ExecuteResponse { interface SuccessfulExecution { data: SuccessfulExecution.Data; errors: null; } namespace SuccessfulExecution { interface Data { outputs: Array; /** * Identifier of the current session. Used to make follow-up calls. */ session_id: string; /** * Status of the execution. Currently only supports success. */ status?: 'success'; } namespace Data { /** * Outputs that were printed to stdout or stderr */ interface StreamOutput { data: string; type: 'stdout' | 'stderr'; } /** * Errors and exceptions that occurred. If this output type is present, your code * did not execute successfully. */ interface Error { data: string; type: 'error'; } interface DisplayorExecuteOutput { data: DisplayorExecuteOutput.Data; type: 'display_data' | 'execute_result'; } namespace DisplayorExecuteOutput { interface Data { 'application/geo+json'?: { [key: string]: unknown; }; 'application/javascript'?: string; 'application/json'?: { [key: string]: unknown; }; 'application/pdf'?: string; 'application/vnd.vega.v5+json'?: { [key: string]: unknown; }; 'application/vnd.vegalite.v4+json'?: { [key: string]: unknown; }; 'image/gif'?: string; 'image/jpeg'?: string; 'image/png'?: string; 'image/svg+xml'?: string; 'text/html'?: string; 'text/latex'?: string; 'text/markdown'?: string; 'text/plain'?: string; } } } } interface FailedExecution { data: null; errors: Array; } } export interface CodeInterpreterExecuteParams { /** * Code snippet to execute. */ code: string; /** * Programming language for the code to execute. Currently only supports Python, * but more will be added. */ language: 'python'; /** * Files to upload to the session. If present, files will be uploaded before * executing the given code. */ files?: Array; /** * Identifier of the current session. Used to make follow-up calls. Requests will * return an error if the session does not belong to the caller or has expired. */ session_id?: string; } export declare namespace CodeInterpreterExecuteParams { interface File { content: string; /** * Encoding of the file content. Use `string` for text files such as code, and * `base64` for binary files, such as images. */ encoding: 'string' | 'base64'; name: string; } } export declare namespace CodeInterpreter { export { type ExecuteResponse as ExecuteResponse, type CodeInterpreterExecuteParams as CodeInterpreterExecuteParams, }; export { Sessions as Sessions, type SessionListResponse as SessionListResponse }; } //# sourceMappingURL=code-interpreter.d.ts.map