import {z} from 'zod' export type GetApiV1AiGatewaysGatewayIdAgentsAgentIdOrNameOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const aIGatewayEntityIdentifier = z.string().min(1).max(256); export const aIGatewayPolicyReferences = z.array(z.string()); export const aIGatewayAllowACL = z.object({allow: z.array(z.string())}); export const aIGatewayDenyACL = z.object({deny: z.array(z.string())}); export const aIGatewayAllowWhenACL = z.object({allow_when: z.array(z.string().min(1).max(1024))}); export const aIGatewayDenyWhenACL = z.object({deny_when: z.array(z.string().min(1).max(1024))}); export const aIGatewayACLS = z.union([aIGatewayAllowACL, aIGatewayDenyACL, aIGatewayAllowWhenACL, aIGatewayDenyWhenACL]); export const aIGatewayIdentityProviderReference = z.string(); export const aIGatewayAuthStrategyReference = z.string(); export const aIGatewayAgentAccess = z.object({acls: aIGatewayACLS.optional(), identity_providers: z.array(aIGatewayIdentityProviderReference).optional(), auth_strategies: z.array(aIGatewayAuthStrategyReference).optional()}); export const aIGatewayUpstreamAuthAWS = z.object({type: z.literal("aws"), access_key_id: z.string().optional(), secret_access_key: z.string().optional(), session_token: z.string().optional(), region: z.string().optional(), assume_role_arn: z.string().optional(), role_session_name: z.string().optional(), sts_endpoint_url: z.string().optional()}); export const aIGatewayUpstreamConfig = z.object({auth: aIGatewayUpstreamAuthAWS.optional()}); export const aIGatewayRouteConfig = z.object({headers: z.record(z.string(), z.unknown()).optional(), hosts: z.array(z.string()).optional(), https_redirect_status_code: z.number().int().gte(100).lte(599).optional(), methods: z.array(z.string()).optional(), paths: z.array(z.string()).optional(), preserve_host: z.boolean().optional(), protocols: z.array(z.string()).optional(), regex_priority: z.number().int().gte(-2147483648).lte(2147483647).optional(), request_buffering: z.boolean().optional(), response_buffering: z.boolean().optional(), strip_path: z.boolean().optional(), tags: z.array(z.string()).optional()}); export const aIGatewayProxyConfig = z.object({http_proxy: z.object({host: z.string().optional(), port: z.number().int().gte(0).lte(65535).optional()}).optional(), https_proxy: z.object({host: z.string().optional(), port: z.number().int().gte(0).lte(65535).optional()}).optional(), proxy_scheme: z.literal("http").optional(), auth: z.object({username: z.string().optional(), password: z.string().optional()}).optional(), no_proxy: z.string().optional()}); export const aIGatewayCertificateReference = z.string(); export const aIGatewayCACertificateReference = z.string(); export const publicLabels = z.record(z.string(), z.string().min(1).max(63)); export const managedBy = z.record(z.string(), z.string().min(1).max(127)); export const uUID = z.string(); export const createdAt = z.string(); export const updatedAt = z.string(); export const aIGatewayAgent = z.object({display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, enabled: z.boolean().optional(), type: z.enum(["a2a", "http"]), policies: aIGatewayPolicyReferences.optional(), access: aIGatewayAgentAccess.optional(), config: z.object({url: z.string().min(1), upstream: aIGatewayUpstreamConfig.optional(), route: aIGatewayRouteConfig.optional(), proxy: aIGatewayProxyConfig.optional(), max_request_body_size: z.number().int().gte(0).lte(2147483646).optional(), logging: z.object({payloads: z.boolean().optional(), max_payload_size: z.number().int().gt(0).lte(2147483646).optional()}).optional(), certificates: z.array(aIGatewayCertificateReference).optional(), ca_certificates: z.array(aIGatewayCACertificateReference).optional()}), labels: publicLabels.optional(), managed_by: managedBy.optional(), id: uUID, created_at: createdAt, updated_at: updatedAt}); 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 an AI Gateway Agent * * GET /v1/ai-gateways/{gatewayId}/agents/{agentIdOrName} * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const getApiV1AiGatewaysGatewayIdAgentsAgentIdOrName = async (options?: GetApiV1AiGatewaysGatewayIdAgentsAgentIdOrNameOptions) => { 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 (personalAccessToken !== undefined) headers.set('authorization', `Bearer ${personalAccessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/ai-gateways/${encodeURIComponent(String(args.gatewayId))}/agents/${encodeURIComponent(String(args.agentIdOrName))}${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(aIGatewayAgent, await res.json()) };