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 | null; env?: string | null; groups?: Record | null; eventProperties?: Record | 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; /** * Next Turn ID for an event in this completion. The first call returns the * id `applySessionContext` already allocated. Later calls take the next * session id, so a user message, tool call, and AI response do not share one. */ takeTurnId?: () => number | undefined; } /** * Provider SDK request options accepted alongside Amplitude overrides in the * second argument of wrapped methods, e.g. * `create(params, { userId, signal, timeout })`. They are forwarded to the * underlying SDK call. Anything else can be passed as a third argument. */ interface ProviderRequestOptions { signal?: AbortSignal | null; timeout?: number; maxRetries?: number; headers?: Record; query?: Record; idempotencyKey?: string; fetchOptions?: Record; } type ProviderCallOptions = ProviderTrackOptions & ProviderRequestOptions; /** * Separate Amplitude tracking overrides from provider SDK request options. * Request options from `extra` take precedence over those in `options`. */ declare function splitCallOptions(options?: ProviderCallOptions | null, extra?: Record | null): { overrides: ProviderTrackOptions | undefined; requestOptions: Record | undefined; }; /** Arguments for the underlying SDK call: `[params]` or `[params, requestOptions]`. */ declare function sdkCallArgs(params: Record, requestOptions: Record | undefined): unknown[]; /** * 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 & { browserSessionId?: string | number | null; }; declare function contextFields(ctx: ProviderTrackOptions): TrackContextFields; declare abstract class BaseAIProvider { protected _amplitude: AmplitudeLike; protected _privacyConfig: PrivacyConfig | null; protected _otelEnabled: boolean; readonly _providerName: string; constructor(options: { amplitude: AmplitudeOrAI; privacyConfig?: PrivacyConfig | null; providerName: string; }); /** * Emit the AI response event. Never throws: a failure in validation, cost * enforcement or serialization skips the event with a content-free warning * so the host's provider call is unaffected. */ protected _track(opts: Omit): string; private _trackUnguarded; trackFn(): TrackFn; createStreamingTracker(): SimpleStreamingTracker; /** @internal Accessor for SimpleStreamingTracker. */ _amplitudeClient(): AmplitudeLike; /** @internal Accessor for SimpleStreamingTracker. */ _privacyConfigRef(): PrivacyConfig | null; /** @internal Accessor for SimpleStreamingTracker (AA-151931 V3-A). */ _otelEnabledRef(): boolean; } declare class SimpleStreamingTracker { private _trackFn; private _amplitude; private _privacyConfig; private _otelEnabled; readonly accumulator: StreamingAccumulator; private _modelName; private _providerName; private _providerRequestId; private _bodyProviderRequestIdSet; 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; setProviderRequestId(providerRequestId: string, bodyPreferred?: boolean): void; addContent(chunk: string): void; setUsage(usage: Parameters[0]): void; setFinishReason(reason: string): void; addToolCall(toolCall: Record): 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, ProviderCallOptions, ProviderRequestOptions, ProviderTrackOptions, SimpleStreamingTracker, TrackContextFields, applySessionContext, contextFields, sdkCallArgs, splitCallOptions }; //# sourceMappingURL=base.d.ts.map