import {z} from 'zod' export type GetApiV1CallCallIdArgs = {call_id: string}; export type GetApiV1CallCallIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const outcomeEvaluationItem = z.object({id: z.string(), name: z.string(), type: z.enum(["mcq", "subjective"]), answer: z.string(), _source: z.string(), choices: z.array(z.string()).optional(), question: z.string()}).and(z.record(z.string(), z.unknown())); export const callDetails = z.object({agent_id: z.string(), created_at: z.string(), updated_at: z.string(), started_at: z.string().nullable().optional(), ended_at: z.string().nullable().optional(), transcript_url: z.string().nullable().optional(), recording_url: z.string().nullable().optional(), status: z.enum(["PENDING", "TRIGGERED", "ONGOING", "CALL_FINISHED", "UNANSWERED", "REJECTED"]), call_variables: z.record(z.string(), z.unknown()).nullable().optional(), call_dispositions: z.array(outcomeEvaluationItem).nullable().optional()}); export const getCallDetailsResponse = z.object({message: z.string(), data: callDetails}); 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 }; /** * Retrieves detailed information about a specific call by its ID. The call must belong to an agent that belongs to your company. Transcript and recording URLs are presigned and valid for 60 minutes. * * GET /v1/call/{call_id} */ export const getApiV1CallCallId = async (args: GetApiV1CallCallIdArgs, options?: GetApiV1CallCallIdOptions) => { const {baseUrl = "https://api.samora.ai", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/call/${encodeURIComponent(String(args.call_id))}${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(getCallDetailsResponse, await res.json()) };