import { PrivacyConfig } from "../core/privacy.js";
import { AmplitudeLike, AmplitudeOrAI, TrackCallOptions, TrackFn } from "../types.js";
import { TrackAiMessageOptions } from "../core/tracking.js";
import { StreamingAccumulator } from "../utils/streaming.js";

//#region src/providers/base.d.ts

/**
 * Per-call context overrides for provider wrappers.
 *
 * Pass as the second argument to wrapped provider methods
 * (e.g., `openai.chat.completions.create(params, overrides)`)
 * to set Amplitude tracking context for that specific call.
 * Any fields left `null`/`undefined` are filled from the
 * active `SessionContext` via `AsyncLocalStorage`.
 */
interface ProviderTrackOptions {
  userId?: string | null;
  deviceId?: string | null;
  sessionId?: string | null;
  traceId?: string | null;
  turnId?: number | null;
  agentId?: string | null;
  parentAgentId?: string | null;
  customerOrgId?: string | null;
  agentVersion?: string | null;
  description?: string | null;
  context?: Record<string, unknown> | null;
  env?: string | null;
  groups?: Record<string, unknown> | null;
  eventProperties?: Record<string, unknown> | null;
  browserSessionId?: string | number | null;
  /**
   * Controls whether provider wrappers auto-track user input payloads.
   * Set to false when you already call `trackUserMessage()` explicitly.
   */
  trackInputMessages?: boolean;
}
/**
 * Apply session context fields from AsyncLocalStorage to tracking options.
 * Returns a merged set of fields with explicit values taking precedence.
 * Also injects idle_timeout_minutes and session_replay_id from the context.
 */
declare function applySessionContext(overrides?: ProviderTrackOptions): ProviderTrackOptions;
/**
 * Extract all context fields from a resolved ProviderTrackOptions into a
 * flat object suitable for spreading into _trackFn() / _track() calls.
 * Ensures all 13 context fields propagate consistently.
 */
type TrackContextFields = Pick<TrackCallOptions, 'userId' | 'deviceId' | 'sessionId' | 'traceId' | 'turnId' | 'agentId' | 'parentAgentId' | 'customerOrgId' | 'agentVersion' | 'description' | 'context' | 'env' | 'groups' | 'eventProperties'> & {
  browserSessionId?: string | number | null;
};
declare function contextFields(ctx: ProviderTrackOptions): TrackContextFields;
declare abstract class BaseAIProvider {
  protected _amplitude: AmplitudeLike;
  protected _privacyConfig: PrivacyConfig | null;
  readonly _providerName: string;
  constructor(options: {
    amplitude: AmplitudeOrAI;
    privacyConfig?: PrivacyConfig | null;
    providerName: string;
  });
  protected _track(opts: Omit<TrackAiMessageOptions, 'amplitude'>): string;
  trackFn(): TrackFn;
  createStreamingTracker(): SimpleStreamingTracker;
  /** @internal Accessor for SimpleStreamingTracker. */
  _amplitudeClient(): AmplitudeLike;
  /** @internal Accessor for SimpleStreamingTracker. */
  _privacyConfigRef(): PrivacyConfig | null;
}
declare class SimpleStreamingTracker {
  private _trackFn;
  private _amplitude;
  private _privacyConfig;
  readonly accumulator: StreamingAccumulator;
  private _modelName;
  private _providerName;
  private _inputMessages;
  private _autoUserTracked;
  private _skipAutoUserTracking;
  constructor(provider: BaseAIProvider);
  /**
   * Hand the tracker the request's input conversation so that
   * {@link SimpleStreamingTracker.finalize} emits
   * `trackUserMessage` events for any new user-role messages
   * (those appearing after the last assistant reply). Matches the
   * behavior of the provider wrappers' `_trackInputMessages()`.
   *
   * Pass `{ skipAuto: true }` when the caller is already emitting
   * user-message events themselves.
   */
  setInputMessages(messages: unknown, options?: {
    skipAuto?: boolean;
  }): void;
  setModel(model: string): void;
  addContent(chunk: string): void;
  setUsage(usage: Parameters<StreamingAccumulator['setUsage']>[0]): void;
  setFinishReason(reason: string): void;
  addToolCall(toolCall: Record<string, unknown>): void;
  finalize(overrides?: ProviderTrackOptions): string;
  /**
   * Track each new user-role message in the input conversation.
   * Mirrors the provider wrappers' `_trackInputMessages()` logic —
   * only messages appearing after the last assistant / tool reply
   * are emitted, so repeat turns don't double-track.
   */
  private _emitAutoUserMessages;
}
//#endregion
export { BaseAIProvider, ProviderTrackOptions, SimpleStreamingTracker, TrackContextFields, applySessionContext, contextFields };
//# sourceMappingURL=base.d.ts.map