import {z} from 'zod' export type GetApiAgentHistoryAgentInvocationExchangesArgs = {agentDefinitionId?: string | undefined, agentDefinitionKey?: string | undefined, agentInstanceId?: string | undefined, agentInvocationId?: string | undefined, operationKey?: string | undefined, order?: string | undefined, size?: number | undefined, sort?: string | undefined, start?: number | undefined, subType?: string | undefined, subTypeLike?: string | undefined, tenantId?: string | undefined, type?: string | undefined, userId?: string | undefined}; export type GetApiAgentHistoryAgentInvocationExchangesOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const temporalUnit = z.object({durationEstimated: z.boolean().optional(), duration: z.lazy(() => duration.optional()), timeBased: z.boolean().optional(), dateBased: z.boolean().optional()}); export const duration: z.ZodType = z.object({seconds: z.number().int().optional(), zero: z.boolean().optional(), nano: z.number().int().optional(), negative: z.boolean().optional(), positive: z.boolean().optional(), units: z.array(temporalUnit).optional()}); export const agentInvocationExchangeResponse = z.object({id: z.string(), agentInstanceId: z.string(), invocationId: z.string(), agentDefinitionId: z.string().optional(), agentDefinitionKey: z.string().optional(), creationTime: z.number().int(), endTime: z.number().int().optional(), duration: duration.optional(), type: z.string().optional(), subType: z.string().optional(), userId: z.string().optional(), promptTokenCount: z.number().int().optional(), outputTokenCount: z.number().int().optional(), cachedTokenCount: z.number().int().optional()}); export const dataResponseAgentInvocationExchangeResponse = z.object({data: z.array(agentInvocationExchangeResponse).optional(), total: z.number().int().optional(), start: z.number().int().optional(), sort: z.string().optional(), order: z.string().optional(), size: z.number().int().optional()}); 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 }; /** * Query agent invocation exchanges * * GET /agent-history/agent-invocation-exchanges */ export const getApiAgentHistoryAgentInvocationExchanges = async (args: GetApiAgentHistoryAgentInvocationExchangesArgs, options?: GetApiAgentHistoryAgentInvocationExchangesOptions) => { const {baseUrl = "http://localhost:8090/agent-api", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.agentDefinitionId != null) query.append("agentDefinitionId", String(args.agentDefinitionId)) if (args.agentDefinitionKey != null) query.append("agentDefinitionKey", String(args.agentDefinitionKey)) if (args.agentInstanceId != null) query.append("agentInstanceId", String(args.agentInstanceId)) if (args.agentInvocationId != null) query.append("agentInvocationId", String(args.agentInvocationId)) if (args.operationKey != null) query.append("operationKey", String(args.operationKey)) if (args.order != null) query.append("order", String(args.order)) if (args.size != null) query.append("size", String(args.size)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.start != null) query.append("start", String(args.start)) if (args.subType != null) query.append("subType", String(args.subType)) if (args.subTypeLike != null) query.append("subTypeLike", String(args.subTypeLike)) if (args.tenantId != null) query.append("tenantId", String(args.tenantId)) if (args.type != null) query.append("type", String(args.type)) if (args.userId != null) query.append("userId", String(args.userId)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/agent-history/agent-invocation-exchanges${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(dataResponseAgentInvocationExchangeResponse, await res.json()) };