interface IsoChannelHandlers<M = any> {
    start?: (context: M, name: string) => void;
    end?: (context: M, name: string) => void;
    asyncStart?: (context: M, name: string) => void;
    asyncEnd?: (context: M, name: string) => void;
    error?: (context: M, name: string) => void;
}

/**
 * Base class for creating instrumentation plugins.
 *
 * Plugins subscribe to diagnostics_channel events and convert them
 * into spans, logs, or other observability data.
 */
declare abstract class BasePlugin {
    protected enabled: boolean;
    protected unsubscribers: Array<() => void>;
    /**
     * Enables the plugin. Must be called before the plugin will receive events.
     */
    enable(): void;
    /**
     * Disables the plugin. After this, the plugin will no longer receive events.
     */
    disable(): void;
    /**
     * Called when the plugin is enabled.
     * Override this to set up subscriptions.
     */
    protected abstract onEnable(): void;
    /**
     * Called when the plugin is disabled.
     * Override this to clean up subscriptions.
     */
    protected abstract onDisable(): void;
    /**
     * Helper to subscribe to a channel with raw handlers.
     *
     * @param channelName - The channel name to subscribe to
     * @param handlers - Event handlers
     */
    protected subscribe(channelName: string, handlers: IsoChannelHandlers): void;
    /**
     * Subscribe to a channel for async methods (non-streaming).
     * Creates a span and logs input/output/metrics.
     */
    protected subscribeToChannel(channelName: string, config: {
        name: string;
        type: string;
        extractInput: (args: any[]) => {
            input: any;
            metadata: any;
        };
        extractOutput: (result: any, endEvent?: any) => any;
        extractMetadata?: (result: any, endEvent?: any) => any;
        extractMetrics: (result: any, startTime?: number, endEvent?: any) => Record<string, number>;
    }): void;
    /**
     * Subscribe to a channel for async methods that may return streams.
     * Handles both streaming and non-streaming responses.
     */
    protected subscribeToStreamingChannel(channelName: string, config: {
        name: string;
        type: string;
        extractInput: (args: any[]) => {
            input: any;
            metadata: any;
        };
        extractOutput: (result: any, endEvent?: any) => any;
        extractMetadata?: (result: any, endEvent?: any) => any;
        extractMetrics: (result: any, startTime?: number, endEvent?: any) => Record<string, number>;
        aggregateChunks?: (chunks: any[], result?: any, endEvent?: any) => {
            output: any;
            metrics: Record<string, number>;
            metadata?: any;
        };
    }): void;
    /**
     * Subscribe to a channel for sync methods that return event-based streams.
     * Used for methods like beta.chat.completions.stream() and responses.stream().
     */
    protected subscribeToSyncStreamChannel(channelName: string, config: {
        name: string;
        type: string;
        extractInput: (args: any[]) => {
            input: any;
            metadata: any;
        };
        extractFromEvent?: (event: any) => {
            output?: any;
            metrics?: Record<string, number>;
            metadata?: any;
        };
    }): void;
}

/**
 * Utilities for diagnostics_channel naming and management.
 */
/**
 * Channel naming convention: braintrust:{component}:{operation}
 *
 * Examples:
 * - braintrust:openai:chat.completions.create
 * - braintrust:anthropic:messages.create
 * - braintrust:ai-sdk:generateText
 */
/**
 * Creates a standardized channel name.
 *
 * @param component - The SDK/library being instrumented (e.g., 'openai', 'anthropic')
 * @param operation - The operation being traced (e.g., 'chat.completions.create')
 * @returns The full channel name
 */
declare function createChannelName(component: string, operation: string): string;
/**
 * Parses a channel name into its component parts.
 *
 * @param channelName - The full channel name
 * @returns Object with component and operation, or null if invalid
 */
declare function parseChannelName(channelName: string): {
    component: string;
    operation: string;
} | null;
/**
 * Validates a channel name follows the expected convention.
 *
 * @param channelName - The channel name to validate
 * @returns True if valid
 */
declare function isValidChannelName(channelName: string): boolean;

/**
 * Base context object shared across all events in a trace.
 */
interface BaseContext {
    /**
     * Unique identifier for this trace.
     * Can be used to correlate start/end/error events.
     */
    traceId?: string;
    /**
     * Arbitrary data that can be attached by event handlers
     * and passed between start/end/error events.
     */
    [key: string]: unknown;
}
/**
 * Event emitted before the synchronous portion of a function executes.
 * This is where you should create spans and extract input data.
 */
interface StartEvent<TInput = unknown> extends BaseContext {
    /**
     * Arguments passed to the function being traced.
     */
    arguments: TInput[];
}
/**
 * Event emitted after the synchronous portion completes.
 * For async functions, this fires when the promise is returned (not settled).
 */
interface EndEvent<TResult = unknown> extends BaseContext {
    /**
     * The result of the synchronous portion.
     * For async functions, this is the promise (not the resolved value).
     */
    result: TResult;
    /**
     * Arguments passed to the function (also available in StartEvent).
     */
    arguments?: unknown[];
}
/**
 * Event emitted when a function throws or a promise rejects.
 */
interface ErrorEvent extends BaseContext {
    /**
     * The error that was thrown or the rejection reason.
     */
    error: Error;
    /**
     * Arguments passed to the function (also available in StartEvent).
     */
    arguments?: unknown[];
}
interface AsyncStartEvent<TInput = unknown> extends StartEvent<TInput> {
}
/**
 * Event emitted when a promise finishes settling.
 * This fires BEFORE control returns to user code after await.
 * This is where you should extract output data and finalize spans.
 */
interface AsyncEndEvent<TResult = unknown> extends EndEvent<TResult> {
}
/**
 * Subscription handlers for a TracingChannel.
 *
 * Common usage pattern:
 * - Use start to create spans and extract input
 * - Use asyncEnd to extract output and finalize spans
 * - Use error to handle failures
 */
interface ChannelHandlers<TInput = unknown, TResult = unknown> {
    /**
     * Called before the synchronous portion of a function executes.
     * Use this to create spans and extract input data.
     */
    start?: (event: StartEvent<TInput>) => void;
    /**
     * Called after the synchronous portion completes (promise returned).
     * Usually not needed for typical instrumentation.
     */
    end?: (event: EndEvent<TResult>) => void;
    /**
     * Called when a promise begins to settle.
     * Usually not needed for typical instrumentation.
     */
    asyncStart?: (event: AsyncStartEvent<TInput>) => void;
    /**
     * Called when a promise finishes settling, before user code continues.
     * Use this to extract output, patch streams, and finalize spans.
     */
    asyncEnd?: (event: AsyncEndEvent<TResult>) => void;
    /**
     * Called when a function throws or promise rejects.
     * Use this to log errors and clean up spans.
     */
    error?: (event: ErrorEvent) => void;
}

interface BraintrustPluginConfig {
    integrations?: {
        openai?: boolean;
        anthropic?: boolean;
        vercel?: boolean;
        aisdk?: boolean;
        google?: boolean;
        googleGenAI?: boolean;
        claudeAgentSDK?: boolean;
        openrouter?: boolean;
    };
}
/**
 * Default Braintrust plugin that manages all AI provider instrumentation plugins.
 *
 * This plugin orchestrates:
 * - OpenAI SDK (chat completions, embeddings, etc.)
 * - Anthropic SDK (messages)
 * - Claude Agent SDK (agent interactions)
 * - Vercel AI SDK (generateText, streamText, etc.)
 * - Google GenAI SDK
 *
 * The plugin is automatically enabled when the Braintrust library is loaded.
 * Individual integrations can be disabled via configuration.
 */
declare class BraintrustPlugin extends BasePlugin {
    private config;
    private openaiPlugin;
    private anthropicPlugin;
    private aiSDKPlugin;
    private claudeAgentSDKPlugin;
    private googleGenAIPlugin;
    private openRouterPlugin;
    constructor(config?: BraintrustPluginConfig);
    protected onEnable(): void;
    protected onDisable(): void;
}

/**
 * Plugin registry and configuration for auto-instrumentation.
 *
 * Plugins are automatically enabled when the Braintrust library is loaded.
 * Users can disable specific integrations programmatically or via environment variables.
 */
interface InstrumentationConfig {
    /**
     * Configuration for individual SDK integrations.
     * Set to false to disable instrumentation for that SDK.
     */
    integrations?: {
        openai?: boolean;
        anthropic?: boolean;
        vercel?: boolean;
        aisdk?: boolean;
        google?: boolean;
        claudeAgentSDK?: boolean;
        openrouter?: boolean;
    };
}
/**
 * Configure auto-instrumentation.
 *
 * This must be called before importing any AI SDKs to take effect.
 *
 * @example
 * ```typescript
 * import { configureInstrumentation } from 'braintrust';
 *
 * // Disable OpenAI instrumentation
 * configureInstrumentation({
 *   integrations: { openai: false }
 * });
 *
 * // Now import SDKs
 * import OpenAI from 'openai';
 * ```
 *
 * Environment variables can also be used:
 * ```bash
 * # Disable single SDK
 * BRAINTRUST_DISABLE_INSTRUMENTATION=openai node app.js
 *
 * # Disable multiple SDKs
 * BRAINTRUST_DISABLE_INSTRUMENTATION=openai,anthropic node app.js
 * ```
 */
declare function configureInstrumentation(config: InstrumentationConfig): void;

export { type AsyncEndEvent, type AsyncStartEvent, type BaseContext, BasePlugin, BraintrustPlugin, type BraintrustPluginConfig, type ChannelHandlers, type EndEvent, type ErrorEvent, type InstrumentationConfig, type StartEvent, configureInstrumentation, createChannelName, isValidChannelName, parseChannelName };
