UNPKG

@maximai/maxim-js

Version:

Maxim AI JS SDK. Visit https://getmaxim.ai for more info.

57 lines (56 loc) 2.59 kB
import type { Span as AgentsSpan, Trace as AgentsTrace, TracingProcessor } from "@openai/agents"; import { SpanData } from "@openai/agents-core/dist/tracing/spans"; import type { MaximLogger } from "../logger"; /** * A tracing processor for the OpenAI Agents SDK that forwards trace and span * lifecycle events into Maxim. * * @example * ```ts * import { addTraceProcessor, setTraceProcessors } from "@openai/agents"; * import { Maxim } from "@maximai/maxim-js"; * import { MaximOpenAIAgentsProcessor } from "@maximai/maxim-js/openai-agents"; * * const maxim = new Maxim({ apiKey: process.env.MAXIM_API_KEY! }); * const logger = await maxim.logger({ id: "my-app" }); * * // Add alongside the default OpenAI exporter * addTraceProcessor(new MaximOpenAIAgentsProcessor(logger)); * * // Or replace all processors (disables default OpenAI exporter) * // setTraceProcessors([new MaximOpenAIAgentsProcessor(logger)]); * ``` * * Trace metadata recognized on the OpenAI Agents trace * (only `traceTags`, `traceMetadata`, and `traceMetrics` are read at both onTraceStart and onTraceEnd, the rest is only read at onTraceStart): * - `traceId`: string — override the Maxim trace id (default: Agent's `traceId`) * - `traceName`: string — set the Maxim trace name * - `traceSessionId`: string — associate the trace to a session * - `traceTags`: Record<string,string> — tags to add on the trace * - `traceMetadata`: Record<string,unknown> — metadata to add on the trace * - `traceMetrics`: Record<string,number> — numeric metrics to add on the trace * - `traceSpanId`: string — id for the single top-level span * - `traceSpanName`: string — name for the top-level span * - `traceSpanTags`: Record<string,string> — tags for the top-level span * * Unsupported span types: * - "speech" | "transcription" | "speech_group" (currently ignored) * * Notes: * - No automatic flush is performed. Manage shutdown/flush in your app * lifecycle (e.g., `await maxim.cleanup()`). */ export declare class MaximOpenAIAgentsProcessor implements TracingProcessor { private readonly logger; private readonly traceStates; private readonly spanStates; private readonly generationStates; private readonly toolCallStates; constructor(logger: MaximLogger); shutdown(): Promise<void>; forceFlush(): Promise<void>; onTraceStart(trace: AgentsTrace): Promise<void>; onTraceEnd(trace: AgentsTrace): Promise<void>; onSpanStart(span: AgentsSpan<SpanData>): Promise<void>; onSpanEnd(span: AgentsSpan<SpanData>): Promise<void>; }