import {z} from 'zod' export type ReportConsultantStatusUpdateRequest = {status: string}; export type CreateApiReportsIdConsultantInsightsInsightIdUpdateArgs = {id: string, insightId: string, body: ReportConsultantStatusUpdateRequest}; export type CreateApiReportsIdConsultantInsightsInsightIdUpdateOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const reportConsultantConfidence = z.enum(["high", "medium", "low"]); export const reportConsultantCardType = z.enum(["finding", "risk", "data_gap", "assumption", "summary", "action"]); export const reportConsultantInsight = z.object({body: z.string(), confidence: reportConsultantConfidence, createdAt: z.string(), createdBy: z.string().optional(), evidenceIds: z.array(z.string()), id: z.string(), reportId: z.string(), sourceRunId: z.string().optional(), status: z.enum(["suggested", "saved", "inserted", "dismissed"]), suggestedDestination: z.string().optional(), title: z.string(), type: reportConsultantCardType, updatedAt: z.string()}); export const reportConsultantInsightResponse = z.object({data: reportConsultantInsight}); 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 }; /** * Compatibility endpoint for clients or proxies that do not reliably pass PATCH requests. * * POST /reports/{id}/consultant/insights/{insightId}/update */ export const createApiReportsIdConsultantInsightsInsightIdUpdate = async (args: CreateApiReportsIdConsultantInsightsInsightIdUpdateArgs, options: CreateApiReportsIdConsultantInsightsInsightIdUpdateOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/reports/${encodeURIComponent(String(args.id))}/consultant/insights/${encodeURIComponent(String(args.insightId))}/update${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(reportConsultantInsightResponse, await res.json()) };