import {z} from 'zod' export type GetApiV1AiGatewaysGatewayIdNodesArgs = {'page[size]'?: number | undefined, 'page[after]'?: string | undefined}; export type GetApiV1AiGatewaysGatewayIdNodesOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const uUID = z.string(); export const createdAt = z.string(); export const updatedAt = z.string(); export const aIGatewayDataPlaneNodeErrorDetail = z.object({error_message: z.string().optional(), type: z.string().optional(), field: z.string().optional()}); export const aIGatewayDataPlaneNodeFlattenedError = z.object({entity_id: z.string().optional(), entity_name: z.string().optional(), entity_type: z.string().optional(), errors: z.array(aIGatewayDataPlaneNodeErrorDetail).optional()}); export const aIGatewayDataPlaneNodeError = z.object({name: z.string(), error_message: z.string(), config_hash: z.string().optional(), flattened_errors: z.array(aIGatewayDataPlaneNodeFlattenedError).optional(), fields: z.record(z.string(), z.string()).optional(), code: z.number().int(), source: z.string(), traceback: z.string()}); export const aIGatewayDataPlaneNodeResiliency = z.object({fallback_config_version: z.string().optional(), activated_at: z.number().int().optional(), latest_config_errors: z.array(aIGatewayDataPlaneNodeError).optional()}); export const aIGatewayDataPlaneNodeConfigSync = z.object({state: z.enum(["STATE_UNSPECIFIED", "STATE_IN_SYNC", "STATE_PENDING", "STATE_RESILIENCY"]).optional(), version_id: z.string().optional(), resiliency: aIGatewayDataPlaneNodeResiliency.optional()}); export const aIGatewayDataPlaneNodeCompatibilityIssueAffectedResource = z.object({id: z.string(), type: z.string(), parent_code: z.string(), details: z.array(z.string())}); export const aIGatewayDataPlaneNodeCompatibilityIssue = z.object({code: z.string(), severity: z.string(), description: z.string(), resolution: z.string(), affected_resources: z.array(aIGatewayDataPlaneNodeCompatibilityIssueAffectedResource), documentation_url: z.string()}); export const publicLabels = z.record(z.string(), z.string().min(1).max(63)); export const aIGatewayDataPlaneNode = z.object({id: uUID, version: z.string(), hostname: z.string(), last_ping: z.number().int(), type: z.string(), created_at: createdAt, updated_at: updatedAt, config_version: z.string().optional(), config_sync: aIGatewayDataPlaneNodeConfigSync.optional(), errors: z.array(aIGatewayDataPlaneNodeError).optional(), compatibility_status: z.object({state: z.string().optional(), issues: z.array(aIGatewayDataPlaneNodeCompatibilityIssue).optional()}), labels: publicLabels.optional()}); export const cursorMetaWithTotal = z.object({page: z.object({first: z.string().optional(), last: z.string().optional(), next: z.string().nullable(), previous: z.string().nullable(), size: z.number(), total: z.number()})}); export const getApiV1AiGatewaysGatewayIdNodesResponse = z.object({data: z.array(aIGatewayDataPlaneNode), meta: cursorMetaWithTotal}); 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 Nodes * * GET /v1/ai-gateways/{gatewayId}/nodes * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const getApiV1AiGatewaysGatewayIdNodes = async (args: GetApiV1AiGatewaysGatewayIdNodesArgs, options?: GetApiV1AiGatewaysGatewayIdNodesOptions) => { const {baseUrl = "https://global.api.konghq.com", fetch: fetchFn = fetch, personalAccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (args['page[after]'] != null) query.append("page[after]", String(args['page[after]'])) if (personalAccessToken !== undefined) headers.set('authorization', `Bearer ${personalAccessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/ai-gateways/${encodeURIComponent(String(args.gatewayId))}/nodes${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(getApiV1AiGatewaysGatewayIdNodesResponse, await res.json()) };