import {z} from 'zod' export type GetApiSnapshotsSnapshotIdHealthOverviewArgs = {snapshot_id: string, limit?: number | undefined, scope?: string | undefined, counts?: string | undefined}; export type GetApiSnapshotsSnapshotIdHealthOverviewOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const healthKpis = z.object({hotspot_health: z.number().nullable().optional(), hotspot_health_measured: z.number().nullable().optional(), average_health: z.number(), worst_performer_path: z.string().nullable().optional(), worst_performer_score: z.number().nullable().optional(), worst_test_path: z.string().nullable().optional(), worst_test_score: z.number().nullable().optional(), file_count: z.number().int().optional(), maintainability_average: z.number().nullable().optional(), performance_average: z.number().nullable().optional(), maintainability_findings: z.number().int().optional(), performance_findings: z.number().int().optional(), band: z.enum(["excellent", "good", "fair", "needs_work", "at_risk"]).nullable().optional(), scope: z.string().optional(), counts: z.string().optional(), unscored_files: z.number().int().optional(), structure_average: z.number().nullable().optional(), structure_hotspot: z.number().nullable().optional(), history_average: z.number().nullable().optional(), history_hotspot: z.number().nullable().optional(), maintainability_hotspot: z.number().nullable().optional(), performance_hotspot: z.number().nullable().optional(), production_average: z.number().nullable().optional(), production_file_count: z.number().int().optional()}); export const biomarkerFinding = z.object({id: z.string(), biomarker_type: z.string(), severity: z.string(), file_path: z.string(), function_name: z.string().nullable().optional(), line_start: z.number().int().nullable().optional(), line_end: z.number().int().nullable().optional(), details: z.record(z.string(), z.unknown()).optional(), health_impact: z.number().optional(), reason: z.string().optional(), status: z.string().optional(), suggestion: z.string().nullable().optional(), dimension: z.string().optional(), symbol_id: z.string().nullable().optional(), is_test: z.boolean().optional(), verification: z.string().nullable().optional()}); export const healthFileMetric = z.object({file_path: z.string(), score: z.number().gte(0).lte(10), band: z.enum(["excellent", "good", "fair", "needs_work", "at_risk"]).nullable().optional(), max_ccn: z.number().int().optional(), max_nesting: z.number().int().optional(), nloc: z.number().int().optional(), duplication_pct: z.number().nullable().optional(), has_test_file: z.boolean().optional(), line_coverage_pct: z.number().nullable().optional(), branch_coverage_pct: z.number().nullable().optional(), module: z.string().nullable().optional(), defect_score: z.number().nullable().optional(), maintainability_score: z.number().nullable().optional(), performance_score: z.number().nullable().optional(), structure_deduction: z.number().nullable().optional(), history_deduction: z.number().nullable().optional(), unclamped_score: z.number().nullable().optional(), performance_findings: z.number().int().optional(), performance_analyzed: z.boolean().nullable().optional(), primary_biomarker: z.string().nullable().optional(), primary_reason: z.string().nullable().optional(), total_deduction: z.number().nullable().optional(), top_biomarkers: z.array(biomarkerFinding).optional(), is_test: z.boolean().optional()}); export const healthModuleRollup = z.object({module: z.string(), file_count: z.number().int(), average_health: z.number(), worst_file_path: z.string().nullable().optional(), worst_file_score: z.number().nullable().optional(), nloc_weighted_health: z.number(), critical_finding_count: z.number().int().optional(), warning_finding_count: z.number().int().optional()}); export const defectAccuracyPoint = z.object({k: z.number().int(), hits: z.number().int()}); export const defectAccuracyFile = z.object({file_path: z.string(), score: z.number(), recent_fixes: z.number().int()}); export const defectAccuracy = z.object({k: z.number().int(), hits: z.number().int(), precision: z.number(), base_rate: z.number(), lift: z.number().nullable().optional(), window_days: z.number().int().optional(), scored_files: z.number().int(), defect_files: z.number().int(), concentration_file_fraction: z.number(), concentration_defect_share: z.number(), precision_table: z.array(defectAccuracyPoint).optional(), flagged_files: z.array(defectAccuracyFile).optional()}); export const healthMeta = z.object({last_indexed_at: z.string().nullable().optional(), head_commit: z.string().nullable().optional(), snapshot_count: z.number().int().optional()}); export const healthOverviewResponse = z.object({kpis: healthKpis, files: z.array(healthFileMetric).optional(), biomarkers: z.array(biomarkerFinding).optional(), test_biomarkers: z.array(biomarkerFinding).optional(), biomarkers_total: z.number().int().optional(), test_biomarkers_total: z.number().int().optional(), modules: z.array(healthModuleRollup).optional(), defect_accuracy: defectAccuracy.nullable().optional(), meta: healthMeta.nullable().optional(), state: z.string().optional(), reason: z.string().nullable().optional(), scope: z.string().optional(), counts: z.string().optional(), distribution: z.record(z.string(), z.unknown()).optional(), unscored_files: z.number().int().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 }; /** * Health Overview * * GET /snapshots/{snapshot_id}/health/overview */ export const getApiSnapshotsSnapshotIdHealthOverview = async (args: GetApiSnapshotsSnapshotIdHealthOverviewArgs, options: GetApiSnapshotsSnapshotIdHealthOverviewOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.scope != null) query.append("scope", String(args.scope)) if (args.counts != null) query.append("counts", String(args.counts)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/snapshots/${encodeURIComponent(String(args.snapshot_id))}/health/overview${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(healthOverviewResponse, await res.json()) };