import {z} from 'zod' export type AgentLlmProviderEnum = 'anthropic' | 'openai' | 'openai-responses' | 'ollama' | 'azure' | 'azure-openai' | 'bedrock' | 'qwen' | 'openai-compatible'; export type ConnectionCapability = 'chat' | 'embedding'; export type ChatDefaults = {model?: string | undefined, temperature?: (number | null) | undefined, maxTokens?: (number | null) | undefined, timeout?: (number | null) | undefined, reasoningEffort?: ('none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | null) | undefined, thinkingBudgetTokens?: (number | null) | undefined, ollamaThink?: (boolean | null) | undefined, maxRetries?: (number | null) | undefined, region?: (string | null) | undefined, strict?: (boolean | null) | undefined, store?: (boolean | null) | undefined, instructions?: (string | null) | undefined, additionalKwargs?: ({[key: string]: unknown} | null) | undefined, apiVersion?: (string | null) | undefined, azureEndpoint?: (string | null) | undefined, azureUrlPathMode?: ('AUTO' | 'LEGACY' | 'UNIFIED' | null) | undefined}; export type EmbeddingDefaults = {model?: string | undefined, dimensions?: (number | null) | undefined, batchSize?: number | undefined, region?: (string | null) | undefined, maxRetries?: (number | null) | undefined}; export type AgentLlmConnection = {id?: (string | null) | undefined, name: string, provider: AgentLlmProviderEnum, apiKey?: string | undefined, baseUrl?: (string | null) | undefined, capabilities: Array, chat?: (ChatDefaults | null) | undefined, embedding?: (EmbeddingDefaults | null) | undefined, description?: (string | null) | undefined}; export type StreamkapMcpConnection = {source?: 'streamkap' | undefined, name: string, serverUrl?: string | undefined, headers?: {[key: string]: string} | undefined}; export type ExternalMcpNoneConnection = {source?: 'external' | undefined, name: string, serverUrl: string, authMode: 'none'}; export type ExternalMcpBearerConnection = {source?: 'external' | undefined, name: string, serverUrl: string, authMode: 'bearer', bearerToken: string}; export type ExternalMcpHeaderConnection = {source?: 'external' | undefined, name: string, serverUrl: string, authMode: 'header', headerName: string, headerValue: string}; export type AgentHttpConnection = {id?: (string | null) | undefined, name: string, baseUrl?: (string | null) | undefined, headers?: {[key: string]: string} | undefined, description?: (string | null) | undefined}; export type VectorStoreProviderEnum = 'pgvector' | 'pinecone' | 'milvus' | 'opensearch' | 'elasticsearch' | 's3vectors' | 'redis'; export type AgentVectorStoreConnection = {id?: (string | null) | undefined, name: string, provider: VectorStoreProviderEnum, apiKey?: string | undefined, endpoint?: (string | null) | undefined, defaultNamespace?: (string | null) | undefined, allowHashFallback?: boolean | undefined, jdbcUrl?: (string | null) | undefined, username?: (string | null) | undefined, password?: (string | null) | undefined, table?: (string | null) | undefined, dims?: (number | null) | undefined, metric?: (string | null) | undefined, properties?: ({[key: string]: unknown} | null) | undefined, description?: (string | null) | undefined}; export type AgentConnections = {llmConnections?: Array | undefined, mcpConnections?: (Array) | undefined, httpConnections?: Array | undefined, vectorStoreConnections?: Array | undefined}; export type UpdateApiAgentsConnectionsArgs = {body: AgentConnections}; export type UpdateApiAgentsConnectionsOptions = {baseUrl?: string | undefined, FronteggHTTPAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiAgentsConnectionsResponse = z.record(z.string(), z.unknown()); 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 Agent Connections * * PUT /agents/connections */ export const updateApiAgentsConnections = async (args: UpdateApiAgentsConnectionsArgs, options?: UpdateApiAgentsConnectionsOptions) => { const {baseUrl = "https://api.streamkap.com", fetch: fetchFn = fetch, FronteggHTTPAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (FronteggHTTPAuthentication !== undefined) headers.set('authorization', `Bearer ${FronteggHTTPAuthentication}`) const url = `${baseUrl.replace(/\/+$/, '')}/agents/connections${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(updateApiAgentsConnectionsResponse, await res.json()) };