import {z} from 'zod' export type DeleteApiV1SessionsSessionIdWindowsWindowIdArgs = {sessionId: string, windowId: string}; export type DeleteApiV1SessionsSessionIdWindowsWindowIdOptions = {baseUrl?: string | undefined, defaultValue?: string | undefined, fetch?: typeof fetch | undefined}; export const windowId = z.object({targetId: z.string(), title: z.string().optional(), url: z.string().optional(), windowId: z.string()}); export const issue = z.object({code: z.string().optional(), details: z.record(z.string(), z.unknown()).optional(), message: z.string(), reason: z.string().optional()}); export const envelopeDefaultMeta = z.object({requestId: z.string().optional()}); export const windowIdResponse = z.object({data: windowId, errors: z.array(issue).optional(), meta: envelopeDefaultMeta, warnings: z.array(issue).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 }; /** * Close window * * DELETE /v1/sessions/{sessionId}/windows/{windowId} */ export const deleteApiV1SessionsSessionIdWindowsWindowId = async (args: DeleteApiV1SessionsSessionIdWindowsWindowIdArgs, options?: DeleteApiV1SessionsSessionIdWindowsWindowIdOptions) => { const {baseUrl = "https://api.airtop.ai/api", fetch: fetchFn = fetch, defaultValue} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (defaultValue !== undefined) headers.set('authorization', `Bearer ${defaultValue}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/sessions/${encodeURIComponent(String(args.sessionId))}/windows/${encodeURIComponent(String(args.windowId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(windowIdResponse, await res.json()) };