import {z} from 'zod' export type GetApiV3beta1EnterpriseOrganizationsOrgIdGuardrailViolationsArgs = {org_id: string, order?: ('asc' | 'desc') | undefined, time_before?: (number | null) | undefined, time_after?: (number | null) | undefined, after?: (string | null) | undefined, first?: number | undefined, session_id?: (string | null) | undefined, guardrail_id?: (string | null) | undefined}; export type GetApiV3beta1EnterpriseOrganizationsOrgIdGuardrailViolationsOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const guardrailViolationResponse = z.object({action_taken: z.string(), confidence_score: z.number(), created_at: z.number().int(), event_id: z.string(), guardrail_id: z.string(), guardrail_name: z.string(), org_id: z.string(), reasoning: z.string(), session_id: z.string().nullable(), user_message: z.string(), violation_id: z.number().int()}); export const paginatedResponseGuardrailViolationResponse = z.object({end_cursor: z.string().nullable().optional(), has_next_page: z.boolean().optional(), items: z.array(guardrailViolationResponse), total: z.number().int().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 }; /** * List Organization Guardrail Violations * * GET /v3beta1/enterprise/organizations/{org_id}/guardrail-violations */ export const getApiV3beta1EnterpriseOrganizationsOrgIdGuardrailViolations = async (args: GetApiV3beta1EnterpriseOrganizationsOrgIdGuardrailViolationsArgs, options: GetApiV3beta1EnterpriseOrganizationsOrgIdGuardrailViolationsOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.order != null) query.append("order", String(args.order)) if (args.time_before != null) query.append("time_before", String(args.time_before)) if (args.time_after != null) query.append("time_after", String(args.time_after)) if (args.after != null) query.append("after", String(args.after)) if (args.first != null) query.append("first", String(args.first)) if (args.session_id != null) query.append("session_id", String(args.session_id)) if (args.guardrail_id != null) query.append("guardrail_id", String(args.guardrail_id)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3beta1/enterprise/organizations/${encodeURIComponent(String(args.org_id))}/guardrail-violations${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(paginatedResponseGuardrailViolationResponse, await res.json()) };