import {z} from 'zod' export type GetApiApiChatSessionsSessionIdComputerArgs = {session_id: string}; export type GetApiApiChatSessionsSessionIdComputerOptions = {baseUrl: string, HTTPBearerJWT?: string | undefined, fetch?: typeof fetch | undefined}; export const sandboxSummary = z.object({sandbox_id: z.string(), state: z.enum(["running", "paused"]), started_at: z.string(), cpu_count: z.number().int(), memory_mb: z.number().int(), template_id: z.string(), mounts_attached: z.boolean()}); export const computerInfo = z.object({owner_kind: z.enum(["session", "expert"]), owner_id: z.string(), e2b_active: z.boolean(), box: sandboxSummary.nullable().optional(), screen_on: z.boolean().optional(), mounts: z.record(z.string(), z.string()).optional(), workspace_path: z.string().optional(), shared_path: z.string().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get Session Computer * * GET /api/chat/sessions/{session_id}/computer */ export const getApiApiChatSessionsSessionIdComputer = async (args: GetApiApiChatSessionsSessionIdComputerArgs, options: GetApiApiChatSessionsSessionIdComputerOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearerJWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HTTPBearerJWT !== undefined) headers.set('authorization', `Bearer ${HTTPBearerJWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/chat/sessions/${encodeURIComponent(String(args.session_id))}/computer${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(computerInfo, await res.json()) };