import { PrivacyConfig } from "./core/privacy.js"; import { AIConfig } from "./config.js"; import { MessageLabel, SessionEnrichments } from "./core/enrichments.js"; import { AmplitudeClientLike, AmplitudeEvent, Attachment } from "./types.js"; import { OtelSpanFilter } from "./otel/mapper.js"; import { ReviewRequest } from "./review.js"; import { TenantHandle } from "./tenant.js"; import { AgentOptions, BoundAgent } from "./bound-agent.js"; //#region src/client.d.ts /** @internal Exposed for testing only. */ declare function _resetShortIdWarned(): void; /** Options for {@link AmplitudeAI.flush}. */ interface FlushOptions { /** * Stop waiting after this many milliseconds. Values above 300000 are * clamped; non-positive or non-numeric values mean "no timeout". */ timeoutMs?: number; } /** @internal Exposed for testing only. */ declare function _getGlobalUnflushedCount(): number; /** @internal Registered by `AmplitudeAI.enableOtel()`. */ declare function _setOtelOwner(owner: { otelEnabled?: boolean; } | null): void; /** @internal Consulted by `decorators.ts` as an opt-in fallback. */ declare function _getOtelOwner(): { otelEnabled?: boolean; } | null; /** * Main Amplitude AI client for tracking LLM interactions. * * Create an instance with an API key or an existing Amplitude client, * then use `.agent()` to create bound agents and `.session()` to * manage session context. * * @example * ```typescript * const ai = new AmplitudeAI({ apiKey: 'YOUR_KEY' }); * const agent = ai.agent('my-chatbot', { userId: 'user-1' }); * const session = agent.session(); * await session.run(async (s) => { * s.trackUserMessage('Hello'); * s.trackAiMessage('Hi there!', 'gpt-4', 'openai', 150); * }); * ``` */ declare class AmplitudeAI { protected _amplitude: AmplitudeClientLike; protected _ownsClient: boolean; protected _config: AIConfig; protected _privacyConfig: PrivacyConfig; protected _sessionTurnCounters: Map; protected _traceEmittedCostUsd: Map; protected _traceEmittedTokens: Map; /** @internal Tracks events since last flush() — used by the exit warning. */ _trackCountSinceFlush: number; private _reviewBuffer; /** @internal Settles when an SDK-owned client (apiKey path) finishes init. */ _initPromise: Promise; private _otelEnabled; private _otelTracerProvider; private _otelMapper; private _otelProcessor; constructor(options: { amplitude?: AmplitudeClientLike; apiKey?: string; config?: AIConfig; }); private _installTrackCounter; private _installTrackHook; get amplitude(): AmplitudeClientLike; get config(): AIConfig; _nextTurnId(sessionId: string): number; private _traceCostKey; _recordEmittedCostFromEvent(event: AmplitudeEvent): void; _getTraceEmittedCostUsd(sessionId: string, traceId: string | null | undefined): number; _getTraceEmittedTokens(sessionId: string, traceId: string | null | undefined): [number, number, number, number]; _autoCalculateCost(opts: { model: string; provider: string; inputTokens: number; outputTokens: number; reasoningTokens?: number | null; cacheReadTokens?: number | null; cacheCreationTokens?: number | null; }): number | null; trackUserMessage(opts: { userId?: string; deviceId?: string | null; content: string; sessionId: string; traceId?: string | null; turnId?: number | null; messageId?: string | null; messageSource?: string | null; agentId?: string | null; parentAgentId?: string | null; customerOrgId?: string | null; agentVersion?: string | null; description?: string | null; context?: Record | null; env?: string | null; isRegeneration?: boolean; isEdit?: boolean; editedMessageId?: string | null; attachments?: Attachment[] | null; labels?: MessageLabel[] | null; idleTimeoutMinutes?: number | null; eventProperties?: Record | null; groups?: Record | null; browserSessionId?: string | number | null; privacyConfig?: PrivacyConfig | null; }): string; trackAiMessage(opts: { userId?: string; deviceId?: string | null; content: string; providerRequestId?: string | null; sessionId: string; model: string; provider: string; latencyMs: number; inputTokens?: number | null; outputTokens?: number | null; reasoningTokens?: number | null; cacheReadTokens?: number | null; cacheCreationTokens?: number | null; totalTokens?: number | null; totalCostUsd?: number | null; finishReason?: string | null; toolCalls?: Array> | null; reasoningContent?: string | null; toolDefinitions?: Array> | null; systemPrompt?: string | null; temperature?: number | null; maxOutputTokens?: number | null; topP?: number | null; isStreaming?: boolean | null; promptId?: string | null; wasCopied?: boolean; wasCached?: boolean; modelTier?: string | null; attachments?: Attachment[] | null; labels?: MessageLabel[] | null; traceId?: string | null; turnId?: number | null; messageId?: string | null; agentId?: string | null; parentAgentId?: string | null; customerOrgId?: string | null; agentVersion?: string | null; description?: string | null; context?: Record | null; env?: string | null; isError?: boolean; errorMessage?: string | null; errorType?: string | null; ttfbMs?: number | null; eventProperties?: Record | null; groups?: Record | null; privacyConfig?: PrivacyConfig | null; browserSessionId?: string | number | null; }): string; trackRunCost(opts: { totalCostUsd: number; inputTokens: number; outputTokens: number; model: string; provider: string; latencyMs?: number | null; content?: string; finishReason?: string | null; cacheReadTokens?: number; cacheCreationTokens?: number; userId?: string; deviceId?: string | null; sessionId?: string; 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; eventProperties?: Record | null; groups?: Record | null; browserSessionId?: string | number | null; }): string; trackToolCall(opts: { userId?: string; deviceId?: string | null; toolName: string; toolType?: string | null; toolOwner?: string | null; latencyMs: number; success: boolean; sessionId?: string | null; traceId?: string | null; turnId?: number | null; invocationId?: string | null; input?: unknown; output?: unknown; parentMessageId?: string | null; agentId?: string | null; parentAgentId?: string | null; customerOrgId?: string | null; agentVersion?: string | null; description?: string | null; context?: Record | null; env?: string | null; errorMessage?: string | null; errorType?: string | null; eventProperties?: Record | null; groups?: Record | null; browserSessionId?: string | number | null; privacyConfig?: PrivacyConfig | null; }): string; trackEmbedding(opts: { userId?: string; deviceId?: string | null; model: string; provider: string; latencyMs: number; inputTokens?: number | null; dimensions?: number | null; totalCostUsd?: number | 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; eventProperties?: Record | null; groups?: Record | null; browserSessionId?: string | number | null; privacyConfig?: PrivacyConfig | null; }): string; trackSpan(opts: { userId?: string; deviceId?: string | null; spanName: string; traceId: string; latencyMs: number; inputState?: Record | null; outputState?: Record | null; parentSpanId?: string | null; isError?: boolean; errorMessage?: string | null; errorType?: string | null; sessionId?: 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; eventProperties?: Record | null; groups?: Record | null; browserSessionId?: string | number | null; }): string; trackSessionEnd(opts: { userId?: string; deviceId?: string | null; sessionId: string; enrichments?: SessionEnrichments | 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; abandonmentTurn?: number | null; idleTimeoutMinutes?: number | null; eventProperties?: Record | null; groups?: Record | null; browserSessionId?: string | number | null; }): void; trackSessionEnrichment(opts: { userId?: string; deviceId?: string | null; sessionId: string; enrichments: SessionEnrichments; 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; eventProperties?: Record | null; groups?: Record | null; browserSessionId?: string | number | null; }): void; score(opts: { userId?: string; deviceId?: string | null; name: string; value: number; targetId: string; targetType?: string; source?: string; comment?: 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; eventProperties?: Record | null; groups?: Record | null; browserSessionId?: string | number | null; }): void; agent(agentId: string, opts?: AgentOptions): BoundAgent; tenant(customerOrgId: string, opts?: { groups?: Record | null; env?: string | null; }): TenantHandle; enableOtel(options?: { defaultUserId?: string; defaultDeviceId?: string; otelEndpoint?: string; /** * `'genai'` (default): only spans with `gen_ai.*` / `amplitude.*` * attributes become events. `'all'`: map every span in the process. */ otelSpanFilter?: OtelSpanFilter; }): this; get otelEnabled(): boolean; usingAttributes(attrs: Record, fn: () => T): T; updateCurrentSpan(attrs: Record): void; updateCurrentTrace(attrs: Record): void; status(): Record; /** * Flush queued events. * * Without options, returns the underlying client's flush result unchanged. * With `timeoutMs`, returns a promise that resolves when the flush settles * or when the timeout elapses (whichever comes first). It never rejects. */ /** Closed review batches plus a snapshot of the still-open batch. */ getReviewTraffic(): ReviewRequest[]; /** Drop captured review batches without printing them. */ clearReviewTraffic(): void; flush(options?: FlushOptions): unknown; shutdown(): void; } //#endregion export { AmplitudeAI, FlushOptions, _getGlobalUnflushedCount, _getOtelOwner, _resetShortIdWarned, _setOtelOwner }; //# sourceMappingURL=client.d.ts.map