import {z} from 'zod' export type GetApiSandboxGmailSandboxIdDumpArgs = {sandbox_id: string}; export type GetApiSandboxGmailSandboxIdDumpOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const sandboxMCPServer = z.enum(["jira", "github", "salesforce", "hubspot", "notion", "airtable", "linear", "asana", "google_sheets", "google_drive", "google_docs", "gmail", "google_calendar", "google_forms", "clickup", "close", "monday", "motion", "onedrive", "microsoft_teams", "outlook_mail", "cal.com", "quickbooks", "moneybird", "dropbox", "shopify", "woocommerce", "outlook_calendar", "resend", "wordpress", "mem0", "supabase", "slack", "confluence", "discord", "snowflake", "postgres", "mongodb", "youtube", "googleworkspaceatlas", "huggingface", "mock_notion", "arxiv_latex", "calculator", "clinicaltrialsgov", "fetch", "met_museum", "open_library", "osm", "pubmed", "us_weather", "duckduckgo", "whois", "wikipedia", "scholarly", "howtocook", "yahoo_finance", "12306", "youtube_transcript", "weather", "twelvedata", "national_parks", "lara_translate", "e2b", "context7", "alchemy", "weights_and_biases", "oxylabs", "google_maps", "brave_search", "exa", "serper"]); export const gmailMessage = z.object({subject: z.string().max(255), to: z.string(), cc: z.string().nullable().optional(), bcc: z.string().nullable().optional(), body: z.string(), from: z.string().nullable().optional(), reply_to: z.string().nullable().optional(), labels: z.array(z.string()).nullable().optional()}); export const gmailDraft = z.object({subject: z.string().max(255), to: z.string(), cc: z.string().nullable().optional(), bcc: z.string().nullable().optional(), body: z.string(), from: z.string().nullable().optional(), reply_to: z.string().nullable().optional()}); export const gmailData = z.object({messages: z.array(gmailMessage).nullable().optional(), drafts: z.array(gmailDraft).nullable().optional()}); export const dumpSandboxResponseGmailData = z.object({sandbox_id: z.string(), server_name: sandboxMCPServer, dumped_at: z.string(), data: gmailData}); 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 }; /** * Export gmail sandbox data * * GET /sandbox/gmail/{sandbox_id}/dump */ export const getApiSandboxGmailSandboxIdDump = async (args: GetApiSandboxGmailSandboxIdDumpArgs, options?: GetApiSandboxGmailSandboxIdDumpOptions) => { const {baseUrl = "https://api.klavis.ai", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/sandbox/gmail/${encodeURIComponent(String(args.sandbox_id))}/dump${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(dumpSandboxResponseGmailData, await res.json()) };