import type { JsonValue } from "./session-api.js"; export type ExecutionSignal = "SIGHUP" | "SIGINT" | "SIGQUIT" | "SIGTERM" | "SIGKILL" | "SIGSTOP" | "SIGCONT" | "SIGUSR1" | "SIGUSR2"; export interface LanguageExecutionOptions { contextId?: string; cwd?: string; env?: Record; args?: string[]; stdin?: string | Uint8Array; timeoutMs?: number; pty?: { cols?: number; rows?: number; }; signal?: AbortSignal; onStdout?: (chunk: Uint8Array) => void; onStderr?: (chunk: Uint8Array) => void; output?: ExecutionOutputOptions; } export type OutputCapture = "none" | "stderr" | "all"; export interface ExecutionOutputOptions { capture?: OutputCapture; retainEvents?: boolean; } export interface InlineExecutionOptions extends LanguageExecutionOptions { inputs?: Record; } export interface JavaScriptExecutionOptions extends InlineExecutionOptions { format?: "module" | "commonjs"; filePath?: string; } export type JavaScriptEvaluationOptions = JavaScriptExecutionOptions; export interface TypeScriptExecutionOptions extends InlineExecutionOptions { filePath?: string; tsconfigPath?: string; compilerOptions?: Record; } export type TypeScriptEvaluationOptions = TypeScriptExecutionOptions; export interface TypeScriptFileExecutionOptions extends LanguageExecutionOptions { tsconfigPath?: string; compilerOptions?: Record; } export interface TypeScriptCheckOptions { contextId?: string; cwd?: string; filePath?: string; tsconfigPath?: string; compilerOptions?: Record; timeoutMs?: number; signal?: AbortSignal; output?: ExecutionOutputOptions; } export interface NpmProjectInstallOptions extends Omit { frozen?: boolean; } export interface NpmPackageInstallOptions extends Omit { dev?: boolean; global?: boolean; } export interface PythonInstallOptions extends Omit { upgrade?: boolean; requirementsFile?: string; indexUrl?: string; extraIndexUrls?: string[]; } export type ContextState = "idle" | "running" | "resetting" | "deleting" | "failed"; export type ExecutionOutcome = "succeeded" | "failed" | "cancelled" | "timed_out"; export interface ContextDescriptor { contextId: string; state: ContextState; language?: "javascript" | "python"; createdAtMs: number; lastStartedAtMs?: number; lastCompletedAtMs?: number; } export interface ProcessDescriptor { pid: number; state: "running" | "exited"; language?: "javascript" | "python"; command?: string; startedAtMs: number; } export interface ProcessExit { pid: number; outcome: "exited" | "signalled" | "timed_out"; exitCode?: number; signal?: ExecutionSignal; } export interface SpawnOptions { cwd?: string; env?: Record; args?: string[]; stdin?: string | Uint8Array; timeoutMs?: number; pty?: { cols?: number; rows?: number; }; signal?: AbortSignal; onStdout?: (chunk: Uint8Array) => void; onStderr?: (chunk: Uint8Array) => void; output?: { retainEvents?: boolean; }; } export type LanguageSpawnOptions = SpawnOptions; export interface ExecutionErrorData { code: string; name: string; message: string; stack?: string; details?: JsonValue; } interface CodeExecutionResultBase { exitCode?: number; stdout?: string; stderr?: string; stdoutTruncated?: boolean; stderrTruncated?: boolean; } type ExecutionResultOutcome = (CodeExecutionResultBase & { outcome: "succeeded"; error?: never; } & TIdentity) | (CodeExecutionResultBase & { outcome: Exclude; error: ExecutionErrorData; } & TIdentity); export type CodeExecutionResult = ExecutionResultOutcome>; export type CodeEvaluationResult = (CodeExecutionResultBase & { outcome: "succeeded"; error?: never; value: T; }) | (CodeExecutionResultBase & { outcome: Exclude; error: ExecutionErrorData; value?: never; }); export interface TypeScriptDiagnostic { code: number; category: "error" | "warning" | "suggestion" | "message"; message: string; filePath?: string; line?: number; column?: number; } export type TypeScriptCheckResult = (CodeExecutionResultBase & { outcome: "succeeded"; error?: never; hasErrors: boolean; diagnostics: TypeScriptDiagnostic[]; }) | (CodeExecutionResultBase & { outcome: Exclude; error: ExecutionErrorData; hasErrors?: never; diagnostics: TypeScriptDiagnostic[]; }); export interface ProcessOutputEvent { pid: number; sequence: number; channel: "stdout" | "stderr" | "pty"; chunk: TChunk; timestampMs: number; } export interface OutputReplay { pid: number; events: ProcessOutputEvent[]; nextCursor: string; hasMore: boolean; truncated: boolean; } export {};