/** * Trace Recorder Middleware — Drop-in middleware for popular frameworks * * Provides Express middleware and Vercel AI SDK wrapper for automatic * agent trace recording. * * @example * ```typescript * // Express * import { agentProbeMiddleware } from '@neuzhou/agentprobe'; * app.use(agentProbeMiddleware({ output: './traces' })); * * // Vercel AI SDK * import { withAgentProbe } from '@neuzhou/agentprobe'; * const model = withAgentProbe(openai('gpt-4')); * ``` */ import type { AgentTrace } from './types'; export interface MiddlewareOptions { output: string; prefix?: string; includeHeaders?: boolean; includeBody?: boolean; flushInterval?: number; maxTraces?: number; filter?: (req: any) => boolean; onTrace?: (trace: AgentTrace) => void; } export interface TraceBuffer { traces: AgentTrace[]; outputDir: string; maxTraces: number; } /** * Create a trace buffer for batching trace writes. */ export declare function createTraceBuffer(outputDir: string, maxTraces?: number): TraceBuffer; /** * Flush traces from buffer to disk. */ export declare function flushTraceBuffer(buffer: TraceBuffer): number; /** * Add a trace to the buffer, auto-flushing if full. */ export declare function addToBuffer(buffer: TraceBuffer, trace: AgentTrace): boolean; /** * Build a trace from an HTTP request/response cycle. */ export declare function buildTraceFromHTTP(method: string, url: string, requestBody: any, responseBody: any, durationMs: number, metadata?: Record): AgentTrace; /** * Create Express-compatible middleware for recording agent traces. */ export declare function agentProbeMiddleware(options: MiddlewareOptions): (req: any, res: any, next: any) => void; /** * Wrapper configuration for AI SDK models. */ export interface WrapperOptions { output?: string; onTrace?: (trace: AgentTrace) => void; metadata?: Record; } /** * Wrap a Vercel AI SDK model to record traces. * Returns a proxy that intercepts calls and records them. */ export declare function withAgentProbe(model: any, options?: WrapperOptions): any; /** * Format middleware stats. */ export declare function formatMiddlewareStats(buffer: TraceBuffer): string; //# sourceMappingURL=middleware.d.ts.map