import {z} from 'zod' export type VoiceCallReviewVerdict = 'good' | 'par' | 'bad'; export type VoiceCallTurnAnnotationCategory = 'wrong_response' | 'missed_info' | 'wrong_tone' | 'hallucination' | 'wrong_tool_call' | 'should_have_escalated' | 'other'; export type TextSessionReviewAnnotationWrite = {id?: (string | null) | undefined, message_id: string, char_start?: (number | null) | undefined, char_end?: (number | null) | undefined, quoted_text?: (string | null) | undefined, suggested_correction: string, finding_category: VoiceCallTurnAnnotationCategory}; export type TextSessionReviewWrite = {verdict: VoiceCallReviewVerdict, outcome: string, annotations?: Array | undefined}; export type UpdateApiApiV1TextAiTextSessionsTextSessionIdReviewArgs = {text_session_id: string, body: TextSessionReviewWrite}; export type UpdateApiApiV1TextAiTextSessionsTextSessionIdReviewOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const voiceCallReviewVerdict = z.enum(["good", "par", "bad"]); export const voiceCallTurnAnnotationCategory = z.enum(["wrong_response", "missed_info", "wrong_tone", "hallucination", "wrong_tool_call", "should_have_escalated", "other"]); export const textSessionReviewAnnotationRead = z.object({id: z.string(), text_session_review_id: z.string(), text_session_id: z.string(), message_id: z.string(), char_start: z.number().int().nullable().optional(), char_end: z.number().int().nullable().optional(), quoted_text: z.string().nullable().optional(), suggested_correction: z.string(), finding_category: voiceCallTurnAnnotationCategory, created_at: z.string(), updated_at: z.string()}); export const textSessionReviewRead = z.object({id: z.string(), text_session_id: z.string(), reviewer_user_id: z.string(), verdict: voiceCallReviewVerdict, outcome: z.string(), annotations: z.array(textSessionReviewAnnotationRead).optional(), created_at: z.string(), updated_at: 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 }; /** * Put Text Session Review * * PUT /api/v1/text-ai/text-sessions/{text_session_id}/review */ export const updateApiApiV1TextAiTextSessionsTextSessionIdReview = async (args: UpdateApiApiV1TextAiTextSessionsTextSessionIdReviewArgs, options: UpdateApiApiV1TextAiTextSessionsTextSessionIdReviewOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/text-ai/text-sessions/${encodeURIComponent(String(args.text_session_id))}/review${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(textSessionReviewRead, await res.json()) };