import {z} from 'zod' export type GetApiExperimentalOrgsOrgIdVerifierAuditsLatestArgs = {lineageId: string, verifierId: string, declarationId?: string | undefined, projectId?: string | undefined, targetSourceId?: string | undefined, targetRoot?: string | undefined, coverageVerdictOffset?: number | undefined, coverageVerdictLimit?: number | undefined, orgId: string, Authorization?: string | undefined}; export type GetApiExperimentalOrgsOrgIdVerifierAuditsLatestOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiExperimentalOrgsOrgIdVerifierAuditsLatestResponse = 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()}))})}).nullable(), headCommitSha: z.string().nullable(), reuseEligible: z.boolean(), coverage: z.object({commitSha: z.string(), effectiveTargetRoot: z.string(), filesMatched: z.number().int(), filesJudged: z.number().int(), filesSkippedByContent: z.number().int(), filesUnresolved: z.number().int(), filesRetryable: z.number().int().gte(0), failureCounts: z.array(z.object({category: 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")]), count: z.number().int().gte(1), retryable: z.boolean()})), treeTruncated: z.boolean(), complete: z.boolean(), canScanMore: z.boolean(), canRetryFailed: z.boolean(), retryContinuation: z.object({afterRunId: z.string(), coverageSweepId: z.string().nullable()}).nullable(), snapshotStatus: z.union([z.literal("current"), z.literal("stale"), z.literal("unavailable")]), continuation: z.object({afterRunId: z.string(), coverageSweepId: z.string().nullable()}).nullable(), verdictsTotal: z.number().int().gte(0), verdictsOffset: z.number().int().gte(0), verdictsLimit: z.number().int().gte(1).lte(500), verdictsNextOffset: z.number().int().gte(0).nullable(), 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(), runId: z.string(), checkedAt: z.string()})), historicalVerdicts: 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(), commitSha: z.string().nullable(), runId: z.string(), checkedAt: z.string(), reason: z.union([z.literal("changed"), z.literal("out_of_scope"), z.literal("inputs_changed"), z.literal("unverified")])}))}).nullable(), continuation: z.object({afterRunId: z.string(), coverageSweepId: z.string().nullable()}).nullable(), availableTargets: z.array(z.object({projectId: z.string().optional(), sourceId: z.string(), root: z.string(), label: z.string()})), selectedTargetIsHome: z.boolean(), selectedTargetSourceUrl: z.string().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 the latest current-state audit for a verifier * * GET /experimental/orgs/{orgId}/verifier-audits/latest */ export const getApiExperimentalOrgsOrgIdVerifierAuditsLatest = async (args: GetApiExperimentalOrgsOrgIdVerifierAuditsLatestArgs, options?: GetApiExperimentalOrgsOrgIdVerifierAuditsLatestOptions) => { 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.lineageId != null) query.append("lineageId", String(args.lineageId)) if (args.verifierId != null) query.append("verifierId", String(args.verifierId)) if (args.declarationId != null) query.append("declarationId", String(args.declarationId)) if (args.projectId != null) query.append("projectId", String(args.projectId)) if (args.targetSourceId != null) query.append("targetSourceId", String(args.targetSourceId)) if (args.targetRoot != null) query.append("targetRoot", String(args.targetRoot)) if (args.coverageVerdictOffset != null) query.append("coverageVerdictOffset", String(args.coverageVerdictOffset)) if (args.coverageVerdictLimit != null) query.append("coverageVerdictLimit", String(args.coverageVerdictLimit)) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/experimental/orgs/${encodeURIComponent(String(args.orgId))}/verifier-audits/latest${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(getApiExperimentalOrgsOrgIdVerifierAuditsLatestResponse, await res.json()) };