import {z} from 'zod' export type GetApiExperimentalOrgsOrgIdContextFindingsArgs = {sort?: (Array<'priority' | '-priority'> | 'priority' | '-priority') | undefined, 'page[size]'?: number | undefined, 'page[after]'?: string | undefined, 'page[before]'?: string | undefined, contextLineageId: string, 'filter[status]'?: ('active' | 'ignored') | undefined, 'filter[archetype]'?: ('registry-match' | 'overlap' | 'frontmatter-error' | 'publishable' | 'drift' | 'untracked' | 'skill-overload' | 'oversized-skill' | 'policy-violation' | 'stale-content' | 'outdated-copy' | 'conflicting-rules' | Array<'registry-match' | 'overlap' | 'frontmatter-error' | 'publishable' | 'drift' | 'untracked' | 'skill-overload' | 'oversized-skill' | 'policy-violation' | 'stale-content' | 'outdated-copy' | 'conflicting-rules'>) | undefined, 'filter[priority]'?: ('critical' | 'high' | 'medium' | 'low' | Array<'critical' | 'high' | 'medium' | 'low'>) | undefined, orgId: string, Authorization?: string | undefined}; export type GetApiExperimentalOrgsOrgIdContextFindingsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiExperimentalOrgsOrgIdContextFindingsResponse = z.object({links: z.object({self: z.string(), next: z.string().nullable(), prev: z.string().nullable()}), meta: z.object({count: z.number(), total: z.number().int(), activeFamilyTotal: z.number().int()}), data: z.array(z.object({id: z.string(), type: z.literal("finding"), attributes: z.object({archetype: z.union([z.literal("registry-match"), z.literal("overlap"), z.literal("frontmatter-error"), z.literal("publishable"), z.literal("drift"), z.literal("untracked"), z.literal("skill-overload"), z.literal("oversized-skill"), z.literal("policy-violation"), z.literal("stale-content"), z.literal("outdated-copy"), z.literal("conflicting-rules")]), priority: z.union([z.literal("critical"), z.literal("high"), z.literal("medium"), z.literal("low")]), title: z.string(), description: z.string(), repoActivity: z.union([z.literal("active"), z.literal("quiet"), z.literal("dormant")]).nullable(), status: z.union([z.literal("active"), z.literal("resolved"), z.literal("ignored")]), ignoreReason: z.union([z.literal("not-relevant"), z.literal("wont-fix"), z.literal("noisy")]).nullable(), gated: z.boolean(), logicalSkill: z.object({canonicalRepo: z.string(), canonicalName: z.string(), body: z.string().nullable(), frontmatter: z.record(z.string(), z.unknown()).nullable(), instanceCount: z.number()}).nullable(), skillInstance: z.object({name: z.string(), path: z.string(), frontmatterError: z.string().nullable(), body: z.string().nullable(), frontmatter: z.record(z.string(), z.unknown()).nullable(), repoFullName: z.string(), repoDefaultBranch: z.string(), repoUrl: z.string()}).nullable(), clusterMembers: z.array(z.object({canonicalRepo: z.string(), canonicalName: z.string(), body: z.string().nullable(), frontmatter: z.record(z.string(), z.unknown()).nullable(), instanceCount: z.number()})), instances: z.array(z.object({id: z.string(), path: z.string(), kind: z.union([z.literal("source"), z.literal("dependency")]), agents: z.array(z.string()), lastModified: z.object({date: z.string().nullable(), authorLogin: z.string().nullable(), authorName: z.string().nullable()}).nullable(), repoFullName: z.string(), repoUrl: z.string(), repoDefaultBranch: z.string()})), repoFullName: z.string().nullable(), canonicalName: z.string().nullable(), evidence: z.object({document: z.object({contextType: z.literal("agent-docs"), provider: z.string(), canonicalRepoUrl: z.string(), path: z.string(), contextLineageId: z.string(), contextVersionId: z.string()}), ruleA: z.object({startLine: z.number().int().gte(1), endLine: z.number().int().gte(1), text: z.string()}), ruleB: z.object({startLine: z.number().int().gte(1), endLine: z.number().int().gte(1), text: z.string()}), sharedCondition: z.string(), explanation: z.string(), suggestedClarification: z.string()}).nullable(), workspaceId: z.string().nullable(), workspaceName: z.string().nullable(), groupId: 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 }; /** * Lists findings for the specified context and related contexts that are visible to the caller in an organization. * * GET /experimental/orgs/{orgId}/context-findings */ export const getApiExperimentalOrgsOrgIdContextFindings = async (args: GetApiExperimentalOrgsOrgIdContextFindingsArgs, options?: GetApiExperimentalOrgsOrgIdContextFindingsOptions) => { 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.sort != null) query.append("sort", String(args.sort)) if (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (args['page[after]'] != null) query.append("page[after]", String(args['page[after]'])) if (args['page[before]'] != null) query.append("page[before]", String(args['page[before]'])) if (args.contextLineageId != null) query.append("contextLineageId", String(args.contextLineageId)) if (args['filter[status]'] != null) query.append("filter[status]", String(args['filter[status]'])) if (args['filter[archetype]'] != null) query.append("filter[archetype]", String(args['filter[archetype]'])) if (args['filter[priority]'] != null) query.append("filter[priority]", String(args['filter[priority]'])) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/experimental/orgs/${encodeURIComponent(String(args.orgId))}/context-findings${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(getApiExperimentalOrgsOrgIdContextFindingsResponse, await res.json()) };