import {z} from 'zod' export type GetApiExperimentalOrgsOrgIdVerifierAuditsRunIdArgs = {declarationId?: string | undefined, orgId: string, runId: string, Authorization?: string | undefined}; export type GetApiExperimentalOrgsOrgIdVerifierAuditsRunIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiExperimentalOrgsOrgIdVerifierAuditsRunIdResponse = z.object({links: z.object({self: z.string()}), data: z.object({id: z.string(), type: z.literal("context-verifier-audit-run"), attributes: z.object({status: z.union([z.literal("pending"), z.literal("running"), z.literal("complete"), z.literal("failed")]), model: z.string().nullable(), ref: z.string(), commitSha: z.string().nullable(), declarationId: z.string().nullable(), configurationRevisionId: z.string().nullable(), filesMatched: z.number().int(), filesJudged: z.number().int(), treeTruncated: z.boolean(), filesSkippedByContent: z.number().int(), error: z.string().nullable(), recoveryAction: z.union([z.literal("wait_for_index"), z.literal("use_latest_skill"), z.literal("reindex_required")]).nullable(), startedAt: z.string().nullable(), completedAt: z.string().nullable(), createdAt: z.string(), updatedAt: z.string(), verdicts: z.array(z.object({path: z.string(), status: z.union([z.literal("pass"), z.literal("fail"), z.literal("na")]), checks: z.array(z.object({name: z.string(), status: z.union([z.literal("pass"), z.literal("fail"), z.literal("na")]), reasoning: z.string().optional(), citation: z.string().optional()})), judgeError: z.string().nullable(), failureCategory: z.union([z.literal("read_failed"), z.literal("judge_unavailable"), z.literal("judge_unparseable"), z.literal("too_large"), z.literal("binary"), z.literal("absent"), z.literal("unsupported"), z.literal("unknown")]).nullable()}))})})}); 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 }; /** * Read a current-state audit run by id * * GET /experimental/orgs/{orgId}/verifier-audits/{runId} */ export const getApiExperimentalOrgsOrgIdVerifierAuditsRunId = async (args: GetApiExperimentalOrgsOrgIdVerifierAuditsRunIdArgs, options?: GetApiExperimentalOrgsOrgIdVerifierAuditsRunIdOptions) => { const {baseUrl = "https://api.tessl.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.declarationId != null) query.append("declarationId", String(args.declarationId)) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/experimental/orgs/${encodeURIComponent(String(args.orgId))}/verifier-audits/${encodeURIComponent(String(args.runId))}${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(getApiExperimentalOrgsOrgIdVerifierAuditsRunIdResponse, await res.json()) };