UNPKG

parea-ai

Version:

Client SDK library to connect to Parea AI.

75 lines (74 loc) 3.01 kB
import { TraceLog, TraceOptions } from '../../types'; import { Trace } from './Trace'; /** * Manages the creation, updating, and finalization of traces. * Implements the Singleton pattern for global access. */ export declare class TraceManager { private static instance; private context; private constructor(); /** * Gets the singleton instance of TraceManager. * @returns {TraceManager} The singleton instance of TraceManager. */ static getInstance(): TraceManager; /** * Creates a new trace and adds it to the current context. * @param {string} name - The name of the trace. * @param {TraceOptions} [options] - Optional configuration for the trace. * @param isLLMCall * @returns {Trace} The newly created trace. */ createTrace(name: string, options?: TraceOptions, isLLMCall?: boolean): Trace; /** * Finalizes a trace, running evaluations if necessary. * @param {Trace} trace - The trace to finalize. * @param {boolean} [skipEval=false] - Whether to skip evaluations. */ finalizeTrace(trace: Trace, skipEval?: boolean): void; /** * Sets the output for a trace. * @param {Trace} trace - The trace to set the output for. * @param {any} value - The output value. * @param {Function} [accessOutputOfFunc] - Optional function to access specific output. */ setTraceOutput(trace: Trace, value: any, accessOutputOfFunc?: (arg0: any) => string): void; /** * Gets the current active trace. * @returns {Trace | undefined} The current trace or undefined if no active trace. */ getCurrentTrace(): Trace | undefined; /** * Gets the ID of the current active trace. * @returns {string | undefined} The ID of the current trace or undefined if no active trace. */ getCurrentTraceId(): string | undefined; /** * Inserts data into the trace log for the current or specified trace. * @param {Partial<TraceLog>} data - The data to insert into the trace log. * @param {string} [traceId] - The ID of the trace to insert data into. If not provided, uses the current trace. */ insertTraceData(data: Partial<TraceLog>, traceId?: string): void; /** * Runs a callback function within the current context or a new context if none exists. * @param {Function} callback - The function to run within the context. * @returns {T} The result of the callback function. * @template T */ runInContext<T>(callback: () => T): T; /** * Runs evaluations asynchronously for a given trace. * @param {Trace} trace - The trace to run evaluations for. * @private */ private runEvaluationsAsync; /** * Merges two values based on the provided key. * @param key - The key indicating the type of merge operation. * @param old - The old value to be merged. * @param newValue - The new value to be merged. * @returns The merged value. */ private merge; }