import {z} from 'zod' export type GetApiApiAccessProfilesArgs = {limit?: number | undefined, offset?: number | undefined, search?: string | undefined, tags?: string | undefined, is_active?: boolean | undefined}; export type GetApiApiAccessProfilesOptions = {baseUrl?: string | undefined, ManagementBearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiAccessProfilesResponse = z.object({access_profiles: z.array(z.object({id: z.number().int().optional(), name: z.string().optional(), description: z.string().nullable().optional(), is_active: z.boolean().optional(), version: z.number().int().optional(), tags: z.array(z.string()).optional(), provider_configs: z.array(z.object({id: z.number().int().optional(), provider_name: z.string(), all_models_allowed: z.boolean().optional(), allowed_models: z.array(z.string()).optional(), budgets: z.array(z.object({id: z.string().optional(), max_limit: z.number(), reset_duration: z.enum(["1h", "1d", "1w", "1M", "1Y"]), scope: z.string().optional(), current_usage: z.number().optional(), last_reset: z.string().optional()})).optional(), rate_limit: z.object({id: z.string().optional(), token_max_limit: z.number().nullable().optional(), token_reset_duration: z.enum(["1h", "1d", "1w", "1M", "1Y"]).optional(), request_max_limit: z.number().nullable().optional(), request_reset_duration: z.enum(["1h", "1d", "1w", "1M", "1Y"]).optional(), token_current_usage: z.number().optional(), request_current_usage: z.number().optional()}).optional()})).optional(), budgets: z.array(z.object({id: z.string().optional(), max_limit: z.number(), reset_duration: z.enum(["1h", "1d", "1w", "1M", "1Y"]), scope: z.string().optional(), current_usage: z.number().optional(), last_reset: z.string().optional()})).optional(), rate_limit: z.object({id: z.string().optional(), token_max_limit: z.number().nullable().optional(), token_reset_duration: z.enum(["1h", "1d", "1w", "1M", "1Y"]).optional(), request_max_limit: z.number().nullable().optional(), request_reset_duration: z.enum(["1h", "1d", "1w", "1M", "1Y"]).optional(), token_current_usage: z.number().optional(), request_current_usage: z.number().optional()}).optional(), calendar_aligned: z.boolean().optional(), mcp_tool_groups: z.array(z.object({tool_group_id: z.number().int()})).optional(), mcp_servers: z.array(z.object({mcp_server_id: z.string()})).optional(), mcp_tool_overrides: z.array(z.object({mcp_client_id: z.string(), tool_name: z.string(), action: z.enum(["include", "exclude"])})).optional(), created_at: z.string().optional(), updated_at: z.string().optional()})).optional(), count: z.number().int().optional(), total_count: z.number().int().optional(), limit: z.number().int().optional(), offset: z.number().int().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 access profiles * * GET /api/access-profiles */ export const getApiApiAccessProfiles = async (args: GetApiApiAccessProfilesArgs, options?: GetApiApiAccessProfilesOptions) => { const {baseUrl = "http://localhost:8080", fetch: fetchFn = fetch, ManagementBearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.search != null) query.append("search", String(args.search)) if (args.tags != null) query.append("tags", String(args.tags)) if (args.is_active != null) query.append("is_active", String(args.is_active)) if (ManagementBearerAuth !== undefined) headers.set('authorization', `Bearer ${ManagementBearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/access-profiles${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(getApiApiAccessProfilesResponse, await res.json()) };