import {z} from 'zod' export type GetApiApiV1DecisionsArgs = {'X-Tenant-ID': string, limit?: number | undefined, since?: string | undefined, decision?: ('allowed' | 'blocked' | 'redacted' | 'needs_approval' | 'error') | undefined, policy_id?: string | undefined, tool_signature?: string | undefined}; export type GetApiApiV1DecisionsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const decisionListItem = z.object({decision_id: z.string().optional(), timestamp: z.string().optional(), decision: z.enum(["allowed", "blocked", "redacted", "needs_approval", "error"]).optional(), policy_id: z.string().optional(), tool_signature: z.string().optional(), context: z.record(z.string(), z.string()).optional(), transfer_basis: z.string().optional(), data_residency: z.string().optional()}); export const decisionListResponse = z.object({decisions: z.array(decisionListItem).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 }; /** * List recent governance decisions * * GET /api/v1/decisions */ export const getApiApiV1Decisions = async (args: GetApiApiV1DecisionsArgs, options?: GetApiApiV1DecisionsOptions) => { const {baseUrl = "https://orchestrator.getaxonflow.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Tenant-ID'] != null) headers.set("X-Tenant-ID", String(args['X-Tenant-ID'])) if (args.limit != null) query.append("limit", String(args.limit)) if (args.since != null) query.append("since", String(args.since)) if (args.decision != null) query.append("decision", String(args.decision)) if (args.policy_id != null) query.append("policy_id", String(args.policy_id)) if (args.tool_signature != null) query.append("tool_signature", String(args.tool_signature)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/decisions${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(decisionListResponse, await res.json()) };