@codesandbox/sdk
Version:
The CodeSandbox SDK
1,126 lines (1,125 loc) • 24 kB
TypeScript
export type ClientOptions = {
baseUrl: 'http://localhost:57468' | 'http://localhost:{port}' | (string & {});
};
export type _Error = {
code: number;
message: string;
};
export type FileReadResponse = {
/**
* File path
*/
path: string;
/**
* File content
*/
content: string;
};
export type FileCreateRequest = {
/**
* File content to create
*/
content?: string;
};
export type FileOperationResponse = {
/**
* Operation result message
*/
message: string;
/**
* File or directory path
*/
path: string;
};
export type FileActionRequest = {
/**
* Type of action to perform on the file
*/
action: 'move' | 'copy';
/**
* Destination path for move operation
*/
destination: string;
};
export type FileActionResponse = {
/**
* Operation result message
*/
message: string;
/**
* Source path
*/
from: string;
/**
* Destination path
*/
to: string;
};
export type FileInfo = {
/**
* File or directory name
*/
name: string;
/**
* Full path to the file or directory
*/
path: string;
/**
* Whether this entry is a directory
*/
isDir: boolean;
/**
* File size in bytes
*/
size: number;
/**
* Last modification time
*/
modTime: string;
};
export type DirectoryListResponse = {
/**
* Directory path
*/
path: string;
/**
* List of files and directories
*/
files: Array<FileInfo>;
};
export type ExecItem = {
/**
* Exec unique identifier
*/
id: string;
/**
* Command being executed
*/
command: string;
/**
* Command line arguments
*/
args: Array<string>;
/**
* Exec status (e.g., running, stopped, finished)
*/
status: string;
/**
* Process ID of the exec
*/
pid: number;
/**
* Whether the exec is interactive
*/
interactive: boolean;
/**
* Exit code of the process (only present when process has exited)
*/
exitCode: number;
};
export type ExecListResponse = {
/**
* List of execs
*/
execs: Array<ExecItem>;
};
export type CreateExecRequest = {
/**
* Command to execute in the exec
*/
command: string;
/**
* Command line arguments
*/
args: Array<string>;
/**
* Whether to automatically start the exec (defaults to true)
*/
autorun?: boolean;
/**
* Whether to start interactive shell session or not (defaults to false)
*/
interactive?: boolean;
};
export type UpdateExecRequest = {
/**
* Status to set for the exec (currently only 'running' is supported)
*/
status: 'running';
};
export type ExecDeleteResponse = {
/**
* Deletion confirmation message
*/
message: string;
};
export type ExecStdin = {
/**
* Type of the exec input
*/
type: 'stdin' | 'resize';
/**
* Data associated with the exec input
*/
input: string;
};
export type TaskStatus = 'RUNNING' | 'FINISHED' | 'ERROR' | 'KILLED' | 'RESTARTING' | 'IDLE';
/**
* TaskBase
* Base schema for a task item, containing common fields shared across different task types.
*/
export type TaskBase = {
status: TaskStatus;
/**
* Exec identifier associated with the task
*/
execId: string;
/**
* Task start time in RFC3339 format
*/
startTime: string;
/**
* Task end time in RFC3339 format
*/
endTime: string;
};
export type TaskRestart = {
files: Array<string>;
clone: boolean;
resume: boolean;
branch: boolean;
};
export type TaskPreview = {
port: number;
};
export type TaskConfig = {
name: string;
command: string;
runAtStart: boolean;
restartOn: TaskRestart;
preview: TaskPreview;
};
export type TaskItem = TaskBase & {
/**
* Task identifier
*/
id: string;
config: TaskConfig;
};
export type TaskListResponse = {
tasks: Array<TaskItem>;
};
export type GetTaskResponse = {
task: TaskItem;
};
/**
* Type of action to execute on a task
*/
export type TaskActionType = 'start' | 'stop' | 'restart';
/**
* TaskActionResponse
* Schema for task action responses, containing details about the task and the action performed.
*/
export type TaskActionResponse = TaskBase & {
/**
* Task identifier
*/
id: string;
/**
* Task name
*/
name: string;
/**
* Task command
*/
command: string;
/**
* Action result message
*/
message: string;
};
export type SetupTaskItem = TaskBase & {
/**
* Setup task name
*/
name: string;
/**
* Setup task command
*/
command: string;
};
export type SetupTaskListResponse = {
setupTasks: Array<SetupTaskItem>;
};
export type PortInfo = {
/**
* Port number
*/
port: number;
/**
* IP address the port is bound to
*/
address: string;
};
export type PortsListResponse = {
/**
* List of open ports
*/
ports: Array<PortInfo>;
};
export type ExecStdout = {
/**
* Type of the exec output
*/
type: 'stdout' | 'stderr';
/**
* Data associated with the exec output
*/
output: string;
/**
* Sequence number of the output message
*/
sequence: number;
/**
* Timestamp of when the output was generated
*/
timestamp?: string;
/**
* Exit code of the process (only present when process has exited)
*/
exitCode?: number;
};
export type Task = TaskItem;
export type DeleteFileData = {
body?: never;
path: {
/**
* File path
*/
path: string;
};
query?: never;
url: '/api/v1/files/{path}';
};
export type DeleteFileErrors = {
/**
* Bad Request - Path is required or invalid path
*/
400: _Error;
/**
* Unauthorized
*/
401: _Error;
/**
* File not found
*/
404: _Error;
/**
* Internal Server Error - Failed to delete file
*/
500: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type DeleteFileError = DeleteFileErrors[keyof DeleteFileErrors];
export type DeleteFileResponses = {
/**
* File deleted successfully
*/
200: FileOperationResponse;
};
export type DeleteFileResponse = DeleteFileResponses[keyof DeleteFileResponses];
export type ReadFileData = {
body?: never;
path: {
/**
* File path
*/
path: string;
};
query?: never;
url: '/api/v1/files/{path}';
};
export type ReadFileErrors = {
/**
* Bad Request - Path is required or invalid path
*/
400: _Error;
/**
* Unauthorized
*/
401: _Error;
/**
* File not found
*/
404: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type ReadFileError = ReadFileErrors[keyof ReadFileErrors];
export type ReadFileResponses = {
/**
* File content retrieved successfully
*/
200: FileReadResponse;
};
export type ReadFileResponse = ReadFileResponses[keyof ReadFileResponses];
export type PerformFileActionData = {
/**
* File action request
*/
body: FileActionRequest;
path: {
/**
* Source file path (will be URL decoded)
*/
path: string;
};
query?: never;
url: '/api/v1/files/{path}';
};
export type PerformFileActionErrors = {
/**
* Bad Request - Path is required, invalid action, or missing destination
*/
400: _Error;
/**
* Unauthorized
*/
401: _Error;
/**
* Internal Server Error - Failed to perform action
*/
500: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type PerformFileActionError = PerformFileActionErrors[keyof PerformFileActionErrors];
export type PerformFileActionResponses = {
/**
* Action performed successfully
*/
200: FileActionResponse;
};
export type PerformFileActionResponse = PerformFileActionResponses[keyof PerformFileActionResponses];
export type CreateFileData = {
/**
* File creation request
*/
body?: FileCreateRequest;
path: {
/**
* File path
*/
path: string;
};
query?: never;
url: '/api/v1/files/{path}';
};
export type CreateFileErrors = {
/**
* Bad Request - Path is required or invalid path
*/
400: _Error;
/**
* Unauthorized
*/
401: _Error;
/**
* Internal Server Error - Failed to create file
*/
500: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type CreateFileError = CreateFileErrors[keyof CreateFileErrors];
export type CreateFileResponses = {
/**
* File created successfully
*/
201: FileReadResponse;
};
export type CreateFileResponse = CreateFileResponses[keyof CreateFileResponses];
export type GetFileStatData = {
body?: never;
path: {
/**
* File path
*/
path: string;
};
query?: never;
url: '/api/v1/file_stat/{path}';
};
export type GetFileStatErrors = {
/**
* Bad Request - Path is required or invalid path
*/
400: _Error;
/**
* Unauthorized
*/
401: _Error;
/**
* File not found
*/
404: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type GetFileStatError = GetFileStatErrors[keyof GetFileStatErrors];
export type GetFileStatResponses = {
/**
* File metadata retrieved successfully
*/
200: FileInfo;
};
export type GetFileStatResponse = GetFileStatResponses[keyof GetFileStatResponses];
export type DeleteDirectoryData = {
body?: never;
path: {
/**
* Directory path
*/
path: string;
};
query?: never;
url: '/api/v1/directories/{path}';
};
export type DeleteDirectoryErrors = {
/**
* Bad Request - Path is required or invalid path
*/
400: _Error;
/**
* Unauthorized
*/
401: _Error;
/**
* Directory not found
*/
404: _Error;
/**
* Internal Server Error - Failed to delete directory
*/
500: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type DeleteDirectoryError = DeleteDirectoryErrors[keyof DeleteDirectoryErrors];
export type DeleteDirectoryResponses = {
/**
* Directory deleted successfully
*/
200: FileOperationResponse;
};
export type DeleteDirectoryResponse = DeleteDirectoryResponses[keyof DeleteDirectoryResponses];
export type ListDirectoryData = {
body?: never;
path: {
/**
* Directory path (will be URL decoded). Use "/" for root directory.
*/
path: string;
};
query?: never;
url: '/api/v1/directories/{path}';
};
export type ListDirectoryErrors = {
/**
* Bad Request - Invalid path
*/
400: _Error;
/**
* Unauthorized
*/
401: _Error;
/**
* Directory not found
*/
404: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type ListDirectoryError = ListDirectoryErrors[keyof ListDirectoryErrors];
export type ListDirectoryResponses = {
/**
* Directory contents retrieved successfully
*/
200: DirectoryListResponse;
};
export type ListDirectoryResponse = ListDirectoryResponses[keyof ListDirectoryResponses];
export type CreateDirectoryData = {
body?: never;
path: {
/**
* Directory path
*/
path: string;
};
query?: never;
url: '/api/v1/directories/{path}';
};
export type CreateDirectoryErrors = {
/**
* Bad Request - Path is required or invalid path
*/
400: _Error;
/**
* Unauthorized
*/
401: _Error;
/**
* Internal Server Error - Failed to create directory
*/
500: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type CreateDirectoryError = CreateDirectoryErrors[keyof CreateDirectoryErrors];
export type CreateDirectoryResponses = {
/**
* Directory created successfully
*/
201: FileOperationResponse;
};
export type CreateDirectoryResponse = CreateDirectoryResponses[keyof CreateDirectoryResponses];
export type ListExecsData = {
body?: never;
path?: never;
query?: never;
url: '/api/v1/execs';
};
export type ListExecsErrors = {
/**
* Unauthorized
*/
401: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type ListExecsError = ListExecsErrors[keyof ListExecsErrors];
export type ListExecsResponses = {
/**
* Execs retrieved successfully
*/
200: ExecListResponse;
};
export type ListExecsResponse = ListExecsResponses[keyof ListExecsResponses];
export type CreateExecData = {
/**
* Exec creation request
*/
body: CreateExecRequest;
path?: never;
query?: never;
url: '/api/v1/execs';
};
export type CreateExecErrors = {
/**
* Bad Request - Invalid request body
*/
400: _Error;
/**
* Unauthorized
*/
401: _Error;
/**
* Internal Server Error - Failed to create exec
*/
500: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type CreateExecError = CreateExecErrors[keyof CreateExecErrors];
export type CreateExecResponses = {
/**
* Exec created successfully
*/
201: ExecItem;
};
export type CreateExecResponse = CreateExecResponses[keyof CreateExecResponses];
export type DeleteExecData = {
body?: never;
path: {
/**
* Exec identifier
*/
id: string;
};
query?: never;
url: '/api/v1/execs/{id}';
};
export type DeleteExecErrors = {
/**
* Bad Request - Exec ID is required
*/
400: _Error;
/**
* Unauthorized
*/
401: _Error;
/**
* Exec not found
*/
404: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type DeleteExecError = DeleteExecErrors[keyof DeleteExecErrors];
export type DeleteExecResponses = {
/**
* Exec deleted successfully
*/
200: ExecDeleteResponse;
};
export type DeleteExecResponse = DeleteExecResponses[keyof DeleteExecResponses];
export type GetExecData = {
body?: never;
path: {
/**
* Exec identifier
*/
id: string;
};
query?: never;
url: '/api/v1/execs/{id}';
};
export type GetExecErrors = {
/**
* Bad Request - Exec ID is required
*/
400: _Error;
/**
* Unauthorized
*/
401: _Error;
/**
* Exec not found
*/
404: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type GetExecError = GetExecErrors[keyof GetExecErrors];
export type GetExecResponses = {
/**
* Exec retrieved successfully
*/
200: ExecItem;
};
export type GetExecResponse = GetExecResponses[keyof GetExecResponses];
export type UpdateExecData = {
/**
* Exec update request
*/
body: UpdateExecRequest;
path: {
/**
* Exec identifier
*/
id: string;
};
query?: never;
url: '/api/v1/execs/{id}';
};
export type UpdateExecErrors = {
/**
* Bad Request - Exec ID is required or invalid status
*/
400: _Error;
/**
* Unauthorized
*/
401: _Error;
/**
* Exec not found
*/
404: _Error;
/**
* Conflict - Exec is already in the requested state
*/
409: _Error;
/**
* Internal Server Error - Failed to update exec
*/
500: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type UpdateExecError = UpdateExecErrors[keyof UpdateExecErrors];
export type UpdateExecResponses = {
/**
* Exec updated successfully
*/
200: ExecItem;
};
export type UpdateExecResponse = UpdateExecResponses[keyof UpdateExecResponses];
export type GetExecOutputData = {
body?: never;
path: {
/**
* Exec identifier
*/
id: string;
};
query?: {
/**
* Last sequence number received by the client. Used to fetch only new output since that sequence or before if it is negative.
*/
lastSequence?: number;
};
url: '/api/v1/execs/{id}/io';
};
export type GetExecOutputErrors = {
/**
* Bad Request - Exec ID is required
*/
400: _Error;
/**
* Unauthorized
*/
401: _Error;
/**
* Exec not found
*/
404: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type GetExecOutputError = GetExecOutputErrors[keyof GetExecOutputErrors];
export type GetExecOutputResponses = {
/**
* Server-Sent Events stream of exec updates with same format as ExecStdout
*/
200: string;
};
export type GetExecOutputResponse = GetExecOutputResponses[keyof GetExecOutputResponses];
export type ExecExecStdinData = {
/**
* Exec update request
*/
body: ExecStdin;
path: {
/**
* Exec identifier
*/
id: string;
};
query?: never;
url: '/api/v1/execs/{id}/io';
};
export type ExecExecStdinErrors = {
/**
* Bad Request - Exec ID is required or invalid status
*/
400: _Error;
/**
* Unauthorized
*/
401: _Error;
/**
* Exec not found
*/
404: _Error;
/**
* Internal Server Error - Failed to update exec
*/
500: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type ExecExecStdinError = ExecExecStdinErrors[keyof ExecExecStdinErrors];
export type ExecExecStdinResponses = {
/**
* Exec stdin executed successfully
*/
200: ExecItem;
};
export type ExecExecStdinResponse = ExecExecStdinResponses[keyof ExecExecStdinResponses];
export type ConnectToExecWebSocketData = {
body?: never;
path: {
/**
* Exec identifier
*/
id: string;
};
query?: never;
url: '/ws/v1/execs/{id}';
};
export type ConnectToExecWebSocketErrors = {
/**
* Bad Request - Exec ID is required
*/
400: _Error;
/**
* Unauthorized - Authentication token required or invalid
*/
401: _Error;
/**
* Exec not found
*/
404: _Error;
/**
* Internal Server Error - Failed to establish WebSocket connection
*/
500: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type ConnectToExecWebSocketError = ConnectToExecWebSocketErrors[keyof ConnectToExecWebSocketErrors];
export type ConnectToExecWebSocketResponses = {
/**
* Unexpected Error
*/
default: _Error;
};
export type ConnectToExecWebSocketResponse = ConnectToExecWebSocketResponses[keyof ConnectToExecWebSocketResponses];
export type ListTasksData = {
body?: never;
path?: never;
query?: never;
url: '/api/v1/tasks';
};
export type ListTasksErrors = {
/**
* Unauthorized
*/
401: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type ListTasksError = ListTasksErrors[keyof ListTasksErrors];
export type ListTasksResponses = {
/**
* List of tasks retrieved successfully
*/
200: TaskListResponse;
};
export type ListTasksResponse = ListTasksResponses[keyof ListTasksResponses];
export type GetTaskData = {
body?: never;
path: {
/**
* Task identifier
*/
id: string;
};
query?: never;
url: '/api/v1/tasks/{id}';
};
export type GetTaskErrors = {
/**
* Bad Request - Task ID is required
*/
400: _Error;
/**
* Unauthorized
*/
401: _Error;
/**
* Task not found
*/
404: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type GetTaskError = GetTaskErrors[keyof GetTaskErrors];
export type GetTaskResponses = {
/**
* Task retrieved successfully
*/
200: GetTaskResponse;
};
export type GetTaskResponse2 = GetTaskResponses[keyof GetTaskResponses];
export type ExecuteTaskActionData = {
body?: never;
path: {
/**
* Task identifier
*/
id: string;
};
query: {
/**
* Type of action to execute
*/
actionType: TaskActionType;
};
url: '/api/v1/tasks/{id}/actions';
};
export type ExecuteTaskActionErrors = {
/**
* Bad Request - Task ID is required, invalid action type, or invalid command
*/
400: _Error;
/**
* Unauthorized
*/
401: _Error;
/**
* Task not found
*/
404: _Error;
/**
* Conflict - Invalid state transition (e.g., task already running for start, task not running for stop)
*/
409: _Error;
/**
* Internal Server Error - Failed to execute action
*/
500: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type ExecuteTaskActionError = ExecuteTaskActionErrors[keyof ExecuteTaskActionErrors];
export type ExecuteTaskActionResponses = {
/**
* Action executed successfully
*/
200: TaskActionResponse;
};
export type ExecuteTaskActionResponse = ExecuteTaskActionResponses[keyof ExecuteTaskActionResponses];
export type ListSetupTasksData = {
body?: never;
path?: never;
query?: never;
url: '/api/v1/setup-tasks';
};
export type ListSetupTasksErrors = {
/**
* Unauthorized
*/
401: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type ListSetupTasksError = ListSetupTasksErrors[keyof ListSetupTasksErrors];
export type ListSetupTasksResponses = {
/**
* Setup tasks retrieved successfully
*/
200: SetupTaskListResponse;
};
export type ListSetupTasksResponse = ListSetupTasksResponses[keyof ListSetupTasksResponses];
export type ListPortsData = {
body?: never;
path?: never;
query?: never;
url: '/api/v1/ports';
};
export type ListPortsErrors = {
/**
* Unauthorized
*/
401: _Error;
/**
* Internal Server Error - Failed to read port information
*/
500: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type ListPortsError = ListPortsErrors[keyof ListPortsErrors];
export type ListPortsResponses = {
/**
* Open ports retrieved successfully
*/
200: PortsListResponse;
};
export type ListPortsResponse = ListPortsResponses[keyof ListPortsResponses];
export type StreamExecsListData = {
body?: never;
path?: never;
query?: never;
url: '/api/v1/stream/execs';
};
export type StreamExecsListErrors = {
/**
* Unauthorized
*/
401: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type StreamExecsListError = StreamExecsListErrors[keyof StreamExecsListErrors];
export type StreamExecsListResponses = {
/**
* Server-Sent Events stream of exec updates
*/
200: string;
};
export type StreamExecsListResponse = StreamExecsListResponses[keyof StreamExecsListResponses];
export type StreamPortsListData = {
body?: never;
path?: never;
query?: never;
url: '/api/v1/stream/ports';
};
export type StreamPortsListErrors = {
/**
* Unauthorized
*/
401: _Error;
/**
* Internal Server Error - Failed to read port information
*/
500: _Error;
/**
* Unexpected Error
*/
default: _Error;
};
export type StreamPortsListError = StreamPortsListErrors[keyof StreamPortsListErrors];
export type StreamPortsListResponses = {
/**
* Server-Sent Events stream of ports list updates
*/
200: string;
};
export type StreamPortsListResponse = StreamPortsListResponses[keyof StreamPortsListResponses];