import {z} from 'zod' export type GetApiV1InsightsChatAnalysisRunsArgs = {workspace_id: string, interview_id?: (string | null) | undefined, status?: (string | null) | undefined, limit?: number | undefined, offset?: number | undefined, 'X-API-Key'?: (string | null) | undefined}; export type GetApiV1InsightsChatAnalysisRunsOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const transcriptAnalysisRunOut = z.object({id: z.string(), chat_session_id: z.string(), interview_id: z.string(), request_message_id: z.string().nullable().optional(), assistant_message_id: z.string().nullable().optional(), objective: z.string(), analysis_kind: z.string(), model: z.string(), model_provider: z.string(), status: z.string(), phase: z.string(), run_generation: z.number().int(), progress: z.record(z.string(), z.unknown()).nullable().optional(), usage: z.record(z.string(), z.unknown()), coverage: z.record(z.string(), z.unknown()), result: z.record(z.string(), z.unknown()).nullable().optional(), suggested_follow_ups: z.array(z.string()).nullable().optional(), stale_reason: z.string().nullable().optional(), error_code: z.string().nullable().optional(), error_message: z.string().nullable().optional(), report_version_id: z.string().nullable().optional(), report_version_number: z.number().int().nullable().optional(), guide_fingerprint: z.string(), created_at: z.string(), started_at: z.string().nullable().optional(), completed_at: z.string().nullable().optional()}); export const getApiV1InsightsChatAnalysisRunsResponse = z.array(transcriptAnalysisRunOut); 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 Workspace Analysis Runs * * GET /v1/insights-chat/analysis-runs */ export const getApiV1InsightsChatAnalysisRuns = async (args: GetApiV1InsightsChatAnalysisRunsArgs, options: GetApiV1InsightsChatAnalysisRunsOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.workspace_id != null) query.append("workspace_id", String(args.workspace_id)) if (args.interview_id != null) query.append("interview_id", String(args.interview_id)) if (args.status != null) query.append("status", String(args.status)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args['X-API-Key'] != null) headers.set("X-API-Key", String(args['X-API-Key'])) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/insights-chat/analysis-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(getApiV1InsightsChatAnalysisRunsResponse, await res.json()) };