import {z} from 'zod' export type GetApiSnapshotsSnapshotIdOwnersOwnerKeyArgs = {snapshot_id: string, owner_key: string}; export type GetApiSnapshotsSnapshotIdOwnersOwnerKeyOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const ownerModuleRollup = z.object({module_path: z.string(), file_count: z.number().int(), hotspot_count: z.number().int(), dominant_pct: z.number()}); export const ownerFileEntry = z.object({file_path: z.string(), commit_count_90d: z.number().int(), churn_percentile: z.number(), bus_factor: z.number().int(), is_hotspot: z.boolean(), last_commit_at: z.string().nullable(), primary_owner_commit_pct: z.number().nullable()}); export const ownerCoAuthor = z.object({name: z.string(), email: z.string().nullable(), shared_files: z.number().int(), co_change_strength: z.number()}); export const ownerAgentCollab = z.object({files_with_agent_commits: z.number().int(), agent_commit_count: z.number().int(), agent_share_pct: z.number().nullable(), tier_counts: z.record(z.string(), z.unknown()).optional()}); export const ownerProfileResponse = z.object({key: z.string(), name: z.string(), email: z.string().nullable(), files_owned: z.number().int(), hotspots_owned: z.number().int(), silo_modules: z.number().int(), dead_code_files_owned: z.number().int(), dead_code_lines_owned: z.number().int(), commit_count_90d: z.number().int().nullable(), last_commit_at: z.string().nullable(), first_commit_at: z.string().nullable(), bus_factor_risk_files: z.number().int(), lines_added_90d_est: z.number().int(), lines_deleted_90d_est: z.number().int(), modules: z.array(ownerModuleRollup), top_files: z.array(ownerFileEntry), files_touched_total: z.number().int().optional(), co_authors: z.array(ownerCoAuthor), co_authors_total: z.number().int().optional(), commit_categories: z.record(z.string(), z.unknown()), agent_collab: ownerAgentCollab.nullable().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 }; /** * Get Owner * * GET /snapshots/{snapshot_id}/owners/{owner_key} */ export const getApiSnapshotsSnapshotIdOwnersOwnerKey = async (args: GetApiSnapshotsSnapshotIdOwnersOwnerKeyArgs, options: GetApiSnapshotsSnapshotIdOwnersOwnerKeyOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/snapshots/${encodeURIComponent(String(args.snapshot_id))}/owners/${encodeURIComponent(String(args.owner_key))}${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(ownerProfileResponse, await res.json()) };