import {z} from 'zod' export type SandboxMCPServer = '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 type CreateApiSandboxServerNameSandboxIdResetArgs = {server_name: SandboxMCPServer, sandbox_id: string}; export type CreateApiSandboxServerNameSandboxIdResetOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const sandboxStatus = z.enum(["idle", "occupied", "error"]); export const resetSandboxResponse = z.object({sandbox_id: z.string(), status: sandboxStatus, message: z.string()}); 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 }; /** * Reset sandbox to initial state * * POST /sandbox/{server_name}/{sandbox_id}/reset */ export const createApiSandboxServerNameSandboxIdReset = async (args: CreateApiSandboxServerNameSandboxIdResetArgs, options?: CreateApiSandboxServerNameSandboxIdResetOptions) => { 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/${encodeURIComponent(String(args.server_name))}/${encodeURIComponent(String(args.sandbox_id))}/reset${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(resetSandboxResponse, await res.json()) };