import {z} from 'zod' export type GetApiV4OrganizationsOrganizationIdAiServicesAgentMemoryApiKeysArgs = {projectId?: string | undefined, clusterId?: string | undefined, page?: number | undefined, perPage?: number | undefined, sortBy?: Array | undefined, sortDirection?: ('asc' | 'desc') | undefined}; export type GetApiV4OrganizationsOrganizationIdAiServicesAgentMemoryApiKeysOptions = {baseUrl?: string | undefined, token?: string | undefined, fetch?: typeof fetch | undefined}; export const agentMemoryApiKeyAccessPolicy = z.object({roles: z.array(z.enum(["ams_admin", "ams_rw", "ams_ro"])).optional()}); export const couchbaseAuditData = z.object({createdBy: z.string(), createdAt: z.string(), modifiedBy: z.string(), modifiedAt: z.string(), version: z.number().int()}); export const pages = z.object({page: z.number().int(), next: z.number().int().optional(), previous: z.number().int().optional(), last: z.number().int(), perPage: z.number().int(), totalItems: z.number().int()}); export const hrefs = z.object({first: z.string(), last: z.string(), previous: z.string(), next: z.string()}); export const cursor = z.object({pages: pages, hrefs: hrefs}); export const listOrganizationAgentMemoryApiKeysResponse = z.object({data: z.array(z.object({id: z.string(), name: z.string(), description: z.string().optional(), agentMemoryServerId: z.string(), agentMemoryServerName: z.string().optional(), expiry: z.number(), accessPolicy: agentMemoryApiKeyAccessPolicy.optional(), lastUsedAt: z.string().nullable().optional(), audit: couchbaseAuditData, projectId: z.string().optional(), clusterId: z.string().optional(), clusterName: z.string().optional()})), cursor: cursor}); 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 Agent Memory API Keys * * GET /v4/organizations/{organizationId}/aiServices/agentMemoryApiKeys */ export const getApiV4OrganizationsOrganizationIdAiServicesAgentMemoryApiKeys = async (args: GetApiV4OrganizationsOrganizationIdAiServicesAgentMemoryApiKeysArgs, options?: GetApiV4OrganizationsOrganizationIdAiServicesAgentMemoryApiKeysOptions) => { const {baseUrl = "https://cloudapi.cloud.couchbase.com", fetch: fetchFn = fetch, token} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.projectId != null) query.append("projectId", String(args.projectId)) if (args.clusterId != null) query.append("clusterId", String(args.clusterId)) if (args.page != null) query.append("page", String(args.page)) if (args.perPage != null) query.append("perPage", String(args.perPage)) for (const item of args.sortBy ?? []) query.append("sortBy", String(item)) if (args.sortDirection != null) query.append("sortDirection", String(args.sortDirection)) if (token !== undefined) headers.set('authorization', `Bearer ${token}`) const url = `${baseUrl.replace(/\/+$/, '')}/v4/organizations/${encodeURIComponent(String(args.organizationId))}/aiServices/agentMemoryApiKeys${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(listOrganizationAgentMemoryApiKeysResponse, await res.json()) };