import {z} from 'zod' export type AIGatewayEntityIdentifier = string; export type AIGatewayPolicyReferences = Array; export type AIGatewayAllowACL = {allow: Array}; export type AIGatewayDenyACL = {deny: Array}; export type AIGatewayAllowWhenACL = {allow_when: Array}; export type AIGatewayDenyWhenACL = {deny_when: Array}; export type AIGatewayACLS = AIGatewayAllowACL | AIGatewayDenyACL | AIGatewayAllowWhenACL | AIGatewayDenyWhenACL; export type AIGatewayIdentityProviderReference = string; export type AIGatewayAuthStrategyReference = string; export type AIGatewayAgentAccess = {acls?: AIGatewayACLS | undefined, identity_providers?: Array | undefined, auth_strategies?: Array | undefined}; export type AIGatewayUpstreamAuthAWS = {type: 'aws', access_key_id?: string | undefined, secret_access_key?: string | undefined, session_token?: string | undefined, region?: string | undefined, assume_role_arn?: string | undefined, role_session_name?: string | undefined, sts_endpoint_url?: string | undefined}; export type AIGatewayUpstreamConfig = {auth?: AIGatewayUpstreamAuthAWS | undefined}; export type AIGatewayRouteConfig = {headers?: {[key: string]: unknown} | undefined, hosts?: Array | undefined, https_redirect_status_code?: number | undefined, methods?: Array | undefined, paths?: Array | undefined, preserve_host?: boolean | undefined, protocols?: Array | undefined, regex_priority?: number | undefined, request_buffering?: boolean | undefined, response_buffering?: boolean | undefined, strip_path?: boolean | undefined, tags?: Array | undefined}; export type AIGatewayProxyConfig = {http_proxy?: ({host?: string | undefined, port?: number | undefined}) | undefined, https_proxy?: ({host?: string | undefined, port?: number | undefined}) | undefined, proxy_scheme?: 'http' | undefined, auth?: ({username?: string | undefined, password?: string | undefined}) | undefined, no_proxy?: string | undefined}; export type AIGatewayCertificateReference = string; export type AIGatewayCACertificateReference = string; export type PublicLabels = {[key: string]: string}; export type ManagedBy = {[key: string]: string}; export type UpdateAIGatewayAgentRequest = {display_name: string, name: AIGatewayEntityIdentifier, enabled?: boolean | undefined, type: 'a2a' | 'http', policies?: AIGatewayPolicyReferences | undefined, access?: AIGatewayAgentAccess | undefined, config: {url: string, upstream?: AIGatewayUpstreamConfig | undefined, route?: AIGatewayRouteConfig | undefined, proxy?: AIGatewayProxyConfig | undefined, max_request_body_size?: number | undefined, logging?: ({payloads?: boolean | undefined, max_payload_size?: number | undefined}) | undefined, certificates?: Array | undefined, ca_certificates?: Array | undefined}, labels?: PublicLabels | undefined, managed_by?: ManagedBy | undefined}; export type UpdateApiV1AiGatewaysGatewayIdAgentsAgentIdOrNameArgs = {body: UpdateAIGatewayAgentRequest}; export type UpdateApiV1AiGatewaysGatewayIdAgentsAgentIdOrNameOptions = {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 }; /** * Update an AI Gateway Agent * * PUT /v1/ai-gateways/{gatewayId}/agents/{agentIdOrName} * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const updateApiV1AiGatewaysGatewayIdAgentsAgentIdOrName = async (args: UpdateApiV1AiGatewaysGatewayIdAgentsAgentIdOrNameArgs, options?: UpdateApiV1AiGatewaysGatewayIdAgentsAgentIdOrNameOptions) => { const {baseUrl = "https://global.api.konghq.com", fetch: fetchFn = fetch, personalAccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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: "PUT", headers, body: JSON.stringify(args.body)}) 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()) };