export type ExecRequest = {command: string, args?: Array | undefined, env?: {[key: string]: string} | undefined, working_dir?: string | undefined, timeout_s?: number | undefined}; export type CreateApiSandboxesSandboxIdExecStreamArgs = {body: ExecRequest}; export type CreateApiSandboxesSandboxIdExecStreamOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Execute a command and stream output via SSE * * POST /sandboxes/{sandbox_id}/exec/stream */ export const createApiSandboxesSandboxIdExecStream = async (args: CreateApiSandboxesSandboxIdExecStreamArgs, options?: CreateApiSandboxesSandboxIdExecStreamOptions) => { const {baseUrl = "https://api-staging.superserve.ai", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "text/event-stream") if (apiKey !== undefined) headers.set("X-API-Key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/sandboxes/${encodeURIComponent(String(args.sandbox_id))}/exec/stream${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };