import {z} from 'zod' export type GetApiApiV1VoiceAgentsVoiceAgentIdSimRunsArgs = {voice_agent_id: string, version_id?: (string | null) | undefined}; export type GetApiApiV1VoiceAgentsVoiceAgentIdSimRunsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const simRunStatus = z.enum(["queued", "running", "passed", "failed"]); export const simRunRead = z.object({id: z.string(), target_agent_type: z.string(), voice_agent_id: z.string().nullable(), voice_agent_version_id: z.string().nullable(), flywheel_run_id: z.string().nullable(), sim_provider: z.string(), bluejay_external_id: z.string().nullable(), status: simRunStatus, passed: z.boolean().nullable(), started_at: z.string().nullable(), completed_at: z.string().nullable(), coverage_note: z.string().nullable(), created_at: z.string()}); export const getApiApiV1VoiceAgentsVoiceAgentIdSimRunsResponse = z.array(simRunRead); 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 }; /** * List Sim Runs Agent Route * * GET /api/v1/voice-agents/{voice_agent_id}/sim-runs */ export const getApiApiV1VoiceAgentsVoiceAgentIdSimRuns = async (args: GetApiApiV1VoiceAgentsVoiceAgentIdSimRunsArgs, options: GetApiApiV1VoiceAgentsVoiceAgentIdSimRunsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.version_id != null) query.append("version_id", String(args.version_id)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/voice-agents/${encodeURIComponent(String(args.voice_agent_id))}/sim-runs${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(getApiApiV1VoiceAgentsVoiceAgentIdSimRunsResponse, await res.json()) };