import {z} from 'zod' export type GetApiApiV1UsinsuranceOversightArgs = {'X-Org-ID'?: string | undefined, 'X-Tenant-ID'?: string | undefined, period_start?: string | undefined, period_end?: string | undefined}; export type GetApiApiV1UsinsuranceOversightOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const uSInsuranceOversightItem = z.object({id: z.string().optional(), request_id: z.string().optional(), created_at: z.string().optional(), request_type: z.string().optional(), trigger_reason: z.string().optional(), policy_id: z.string().optional(), policy_name: z.string().optional(), severity: z.string().optional(), status: z.string().optional(), reviewer_id: z.string().optional(), reviewer_role: z.string().optional(), reviewed_at: z.string().optional(), review_latency_ms: z.number().int().optional(), is_exception: z.boolean().optional(), override_authorized_by: z.string().optional(), override_justification: z.string().optional()}); export const uSInsuranceCompleteness = z.object({complete: z.boolean(), truncated: z.boolean(), unavailable: z.boolean(), note: z.string().optional()}); export const uSInsuranceOversightResponse = z.object({items: z.array(uSInsuranceOversightItem).optional(), total: z.number().int().optional(), exceptions: z.number().int().optional(), unresolved: z.number().int().optional(), period_start: z.string().optional(), period_end: z.string().optional(), completeness: uSInsuranceCompleteness.optional()}); 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 }; /** * Human oversight register with exceptions and overrides (Exhibits B and C) * * GET /api/v1/usinsurance/oversight */ export const getApiApiV1UsinsuranceOversight = async (args: GetApiApiV1UsinsuranceOversightArgs, options?: GetApiApiV1UsinsuranceOversightOptions) => { const {baseUrl = "https://orchestrator.getaxonflow.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Org-ID'] != null) headers.set("X-Org-ID", String(args['X-Org-ID'])) if (args['X-Tenant-ID'] != null) headers.set("X-Tenant-ID", String(args['X-Tenant-ID'])) if (args.period_start != null) query.append("period_start", String(args.period_start)) if (args.period_end != null) query.append("period_end", String(args.period_end)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/usinsurance/oversight${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(uSInsuranceOversightResponse, await res.json()) };