import {z} from 'zod' export type GetApiAgentsJobIdConfigHistoryVersionArgs = {job_id: string, version: number}; export type GetApiAgentsJobIdConfigHistoryVersionOptions = {baseUrl?: string | undefined, FronteggHTTPAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const agentTypeEnum = z.enum(["workflow", "react"]); export const agentSerializationEnum = z.enum(["JsonConfluent", "AvroConfluent"]); export const agentInputConfig = z.object({topicPattern: z.string().min(1).max(1024), inputSerialization: agentSerializationEnum.optional(), fields: z.array(z.string()).nullable().optional(), createTableSQL: z.string().max(4000).nullable().optional(), filterSQL: z.string().max(4000).nullable().optional()}); export const agentOutputSchemaTypeEnum = z.enum(["STRING", "DOUBLE", "INT32", "INT64", "BOOLEAN"]); export const agentOutputConfig = z.object({topic: z.string().min(1).max(249), deadLetterTopic: z.string().max(249).nullable().optional(), outputSerialization: agentSerializationEnum.optional(), schema: z.record(z.string(), agentOutputSchemaTypeEnum).optional()}); export const agentLlmProviderEnum = z.enum(["anthropic", "openai", "openai-responses", "ollama", "azure", "azure-openai", "bedrock", "qwen", "openai-compatible"]); export const agentLlmConfig = z.object({provider: agentLlmProviderEnum, model: z.string().min(1), apiKey: z.string().max(512).optional(), llmConnectionId: z.string().max(100).nullable().optional(), baseUrl: z.string().nullable().optional(), temperature: z.number().gte(0).lte(2).nullable().optional(), maxTokens: z.number().int().gte(1).lte(100000).nullable().optional(), timeout: z.number().int().gte(1).lte(600).nullable().optional(), reasoningEffort: z.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).nullable().optional(), thinkingBudgetTokens: z.number().int().gte(0).lte(64000).nullable().optional(), ollamaThink: z.boolean().nullable().optional(), maxRetries: z.number().int().gte(0).lte(20).nullable().optional(), region: z.string().max(64).nullable().optional(), strict: z.boolean().nullable().optional(), store: z.boolean().nullable().optional(), instructions: z.string().max(8192).nullable().optional(), additionalKwargs: z.record(z.string(), z.unknown()).nullable().optional(), apiVersion: z.string().max(32).nullable().optional(), azureEndpoint: z.string().max(512).nullable().optional(), azureUrlPathMode: z.enum(["AUTO", "LEGACY", "UNIFIED"]).nullable().optional()}); export const agentPromptConfig = z.object({system: z.string().max(8000).optional(), customInstructions: z.string().max(8000).optional(), user: z.string().max(2000).optional()}); export const agentMcpServerConfig = z.object({projectKeyId: z.string().max(128).nullable().optional(), serverUrl: z.string().min(1).max(2048).nullable().optional(), headers: z.record(z.string(), z.string()).optional()}); export const agentToolTypeEnum = z.enum(["http", "transform", "mcp"]); export const agentToolParameterConfig = z.object({name: z.string().min(1).max(100), type: z.string().max(50).optional(), description: z.string().max(2000).optional()}); export const agentToolConfig = z.object({name: z.string().min(1).max(100), type: agentToolTypeEnum, description: z.string().max(2000).optional(), config: z.record(z.string(), z.unknown()).optional(), parameters: z.array(agentToolParameterConfig).optional()}); export const agentShortTermMemoryConfig = z.object({enabled: z.boolean().optional(), ttlMs: z.number().int().gte(0).optional(), maxEntries: z.number().int().gte(1).lte(100).optional()}); export const agentLongTermMemoryConfig = z.object({enabled: z.boolean().optional(), vectorStoreConnectionId: z.string().max(64).nullable().optional(), namespace: z.string().max(200).nullable().optional(), destinationId: z.string().max(64).nullable().optional()}); export const agentMemoryConfig = z.object({keyField: z.string().nullable().optional(), shortTerm: agentShortTermMemoryConfig.optional(), longTerm: agentLongTermMemoryConfig.optional()}); export const agentKnowledgeBaseRef = z.object({id: z.string().min(1).max(64), name: z.string().max(200).optional()}); export const agentProcessingConfig = z.object({parallelism: z.number().int().gte(1).lte(128).optional(), checkpointIntervalMin: z.number().int().gte(1).lte(60).optional(), maxIterations: z.number().int().gte(1).lte(25).optional(), maxTokensPerHour: z.number().int().gte(0).optional()}); export const createAgentConfigRequest = z.object({name: z.string().min(1).max(200), description: z.string().max(500).nullable().optional(), enabled: z.boolean().optional(), agentType: agentTypeEnum.optional(), input: agentInputConfig, output: agentOutputConfig, llm: agentLlmConfig, prompts: agentPromptConfig, mcpServer: agentMcpServerConfig.nullable().optional(), tools: z.array(agentToolConfig).optional(), memory: agentMemoryConfig.nullable().optional(), knowledgeBases: z.array(agentKnowledgeBaseRef).optional(), processing: agentProcessingConfig.optional()}); export const agentConfigHistoryDetailResponse = z.object({version: z.number().int().gte(0), changedByEmail: z.string().nullable().optional(), changedTimestamp: z.string(), changeKind: z.enum(["create", "update", "rollback"]), rollbackSourceVersion: z.number().int().nullable().optional(), changeNote: z.string().nullable().optional(), agentConfig: createAgentConfigRequest}).and(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 }; /** * Get Agent Config History Entry * * GET /agents/{job_id}/config/history/{version} */ export const getApiAgentsJobIdConfigHistoryVersion = async (args: GetApiAgentsJobIdConfigHistoryVersionArgs, options?: GetApiAgentsJobIdConfigHistoryVersionOptions) => { const {baseUrl = "https://api.streamkap.com", fetch: fetchFn = fetch, FronteggHTTPAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (FronteggHTTPAuthentication !== undefined) headers.set('authorization', `Bearer ${FronteggHTTPAuthentication}`) const url = `${baseUrl.replace(/\/+$/, '')}/agents/${encodeURIComponent(String(args.job_id))}/config/history/${encodeURIComponent(String(args.version))}${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(agentConfigHistoryDetailResponse, await res.json()) };