import {z} from 'zod' export type GetApiPoliciesAttachmentsAttachmentIdArgs = {attachment_id: string}; export type GetApiPoliciesAttachmentsAttachmentIdOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const policyAttachmentDBResponse = z.object({attachment_id: z.string(), created_at: z.string().nullable().optional(), created_by: z.string().nullable().optional(), default: z.boolean().optional(), definition_location: z.enum(["db", "config"]).optional(), keys: z.array(z.string()).optional(), models: z.array(z.string()).optional(), policy_name: z.string(), priority: z.number().int().nullable().optional(), scope: z.string().nullable().optional(), tags: z.array(z.string()).optional(), teams: z.array(z.string()).optional(), updated_at: z.string().nullable().optional(), updated_by: z.string().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 }; /** * Get Policy Attachment * * GET /policies/attachments/{attachment_id} */ export const getApiPoliciesAttachmentsAttachmentId = async (args: GetApiPoliciesAttachmentsAttachmentIdArgs, options: GetApiPoliciesAttachmentsAttachmentIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (APIKeyHeader !== undefined) headers.set("x-litellm-api-key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/policies/attachments/${encodeURIComponent(String(args.attachment_id))}${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(policyAttachmentDBResponse, await res.json()) };