@codesandbox/sdk
Version:
The CodeSandbox SDK
126 lines (125 loc) • 5.38 kB
TypeScript
import { fs, port, setup, shell, task } from "../pitcher-protocol";
import { IAgentClient, IAgentClientFS, IAgentClientPorts, IAgentClientSetup, IAgentClientShells, IAgentClientSystem, IAgentClientTasks, PickRawFsResult } from "../agent-client-interface";
import { AgentConnection } from "./AgentConnection";
import { Event } from "../utils/event";
import { SandboxSession } from "../types";
import { InitStatus } from "../pitcher-protocol/messages/system";
declare class AgentClientShells implements IAgentClientShells {
private agentConnection;
private onShellExitedEmitter;
onShellExited: Event<{
shellId: string;
exitCode: number;
}>;
private onShellTerminatedEmitter;
onShellTerminated: Event<{
shellId: shell.ShellId;
author: string;
}>;
private onShellOutEmitter;
onShellOut: Event<{
shellId: shell.ShellId;
out: string;
}>;
constructor(agentConnection: AgentConnection);
create(projectPath: string, size: shell.ShellSize, command?: string, type?: shell.ShellProcessType, isSystemShell?: boolean): Promise<shell.OpenShellDTO>;
delete(shellId: shell.ShellId): Promise<shell.CommandShellDTO | shell.TerminalShellDTO | null>;
getShells(): Promise<shell.ShellDTO[]>;
open(shellId: shell.ShellId, size: shell.ShellSize): Promise<shell.OpenShellDTO>;
rename(shellId: shell.ShellId, name: string): Promise<null>;
restart(shellId: shell.ShellId): Promise<null>;
send(shellId: shell.ShellId, input: string, size: shell.ShellSize): Promise<null>;
}
declare class AgentClientFS implements IAgentClientFS {
private agentConnection;
private workspacePath;
constructor(agentConnection: AgentConnection, workspacePath: string);
private handleRawFsResponse;
copy(from: string, to: string, recursive?: boolean, overwrite?: boolean): Promise<PickRawFsResult<"fs/copy">>;
download(path?: string): Promise<{
downloadUrl: string;
}>;
mkdir(path: string, recursive?: boolean): Promise<PickRawFsResult<"fs/mkdir">>;
readdir(path: string): Promise<PickRawFsResult<"fs/readdir">>;
readFile(path: string): Promise<PickRawFsResult<"fs/readFile">>;
remove(path: string, recursive?: boolean): Promise<PickRawFsResult<"fs/remove">>;
rename(path: string, newPath: string): Promise<PickRawFsResult<"fs/rename">>;
stat(path: string): Promise<PickRawFsResult<"fs/stat">>;
watch(path: string, options: {
readonly recursive?: boolean;
readonly excludes?: readonly string[];
}, onEvent: (watchEvent: fs.FSWatchEvent) => void): Promise<(PickRawFsResult<"fs/watch"> & {
type: "error";
}) | {
type: "success";
dispose(): void;
}>;
writeFile(path: string, content: Uint8Array, create?: boolean, overwrite?: boolean): Promise<PickRawFsResult<"fs/writeFile">>;
}
declare class AgentClientPorts implements IAgentClientPorts {
private agentConnection;
private onPortsUpdatedEmitter;
onPortsUpdated: Event<port.Port[]>;
constructor(agentConnection: AgentConnection);
getPorts(): Promise<port.Port[]>;
}
declare class AgentClientSetup implements IAgentClientSetup {
private agentConnection;
private onSetupProgressUpdateEmitter;
onSetupProgressUpdate: Event<setup.SetupProgress>;
constructor(agentConnection: AgentConnection);
getProgress(): Promise<setup.SetupProgress>;
init(): Promise<setup.SetupProgress>;
}
declare class AgentClientTasks implements IAgentClientTasks {
private agentConnection;
private onTaskUpdateEmitter;
onTaskUpdate: Event<task.TaskDTO>;
constructor(agentConnection: AgentConnection);
getTasks(): Promise<task.TaskListDTO>;
getTask(taskId: string): Promise<task.TaskDTO | undefined>;
runTask(taskId: string): Promise<task.TaskDTO>;
stopTask(taskId: string): Promise<task.TaskDTO | null>;
}
declare class AgentClientSystem implements IAgentClientSystem {
private agentConnection;
constructor(agentConnection: AgentConnection);
private onInitStatusUpdateEmitter;
onInitStatusUpdate: Event<InitStatus>;
update(): Promise<Record<string, undefined>>;
}
export declare class AgentClient implements IAgentClient {
private getSession;
private agentConnection;
private params;
static create({ session, getSession, }: {
session: SandboxSession;
getSession: (sandboxId: string) => Promise<SandboxSession>;
}): Promise<{
client: AgentClient;
joinResult: import("../pitcher-protocol/messages/client").ClientJoinResult;
}>;
sandboxId: string;
workspacePath: string;
isUpToDate: boolean;
private reconnectToken;
get state(): import("../agent-client-interface").IAgentClientState;
onStateChange: Event<import("../agent-client-interface").IAgentClientState>;
shells: AgentClientShells;
fs: AgentClientFS;
setup: AgentClientSetup;
tasks: AgentClientTasks;
system: AgentClientSystem;
ports: AgentClientPorts;
constructor(getSession: (sandboxId: string) => Promise<SandboxSession>, agentConnection: AgentConnection, params: {
sandboxId: string;
workspacePath: string;
isUpToDate: boolean;
reconnectToken: string;
});
ping(): void;
disconnect(): Promise<void>;
reconnect(): Promise<void>;
dispose(): void;
}
export {};