export type CommandSpec = Array | string; export type MachineCommandRequest = {background?: boolean | undefined, command: CommandSpec, cwd?: (string | null) | undefined, env?: {[key: string]: string} | undefined, stdin?: (string | null) | undefined, stream?: boolean | undefined, timeoutSeconds?: (number | null) | undefined, user?: (string | null) | undefined}; export type CreateApiV1MachinesIdExecStreamArgs = {id: string, body: MachineCommandRequest}; export type CreateApiV1MachinesIdExecStreamOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Run a command and stream its output. * * POST /v1/machines/{id}/exec/stream */ export const createApiV1MachinesIdExecStream = async (args: CreateApiV1MachinesIdExecStreamArgs, options?: CreateApiV1MachinesIdExecStreamOptions) => { const {baseUrl = "https://api.smolmachines.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "text/event-stream") if (ApiKeyAuth !== undefined) headers.set('authorization', `Bearer ${ApiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/machines/${encodeURIComponent(String(args.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() };