import { AdMeshTheme, PlatformResponse, DelegationActivationPayload, ActiveDelegationSession } from '../types/index'; export interface AdMeshSDKConfig { apiKey: string; theme?: AdMeshTheme; apiBaseUrl?: string; /** Set true when requests originate from the browser extension */ extension?: boolean; /** Optional override for extension source domain header */ extensionSourceDomain?: string; /** Optional user identifier forwarded to ACIE/aip context flows */ userId?: string; } export interface ShowRecommendationsOptions { query: string; containerId: string; theme?: AdMeshTheme; followups_container_id?: string; sessionId: string; messageId: string; platformSurface?: string; model?: string; messages?: Array<{ role: string; content: string; }>; locale?: string; location?: { city?: string; state?: string; stateCode?: string; country?: string; countryCode?: string; zipcode?: string; latitude?: number; longitude?: number; }; userId?: string; /** Legacy bridge CTA callback; prefer onStartDelegation */ onPasteToInput?: (content: string) => void; /** Called when the SDK needs host approval before starting a delegated brand flow */ onDelegationConsent?: (recommendation: PlatformResponse) => boolean | Promise; /** Called with normalized delegation metadata the host can use directly */ onDelegationActivated?: (payload: DelegationActivationPayload) => void | Promise; /** Called after consent is granted so the host can create/open the delegation session */ onStartDelegation?: (recommendation: PlatformResponse) => void | Promise; /** Callback to execute query when follow-up is selected (required for follow-up functionality) */ onExecuteQuery?: (query: string) => void | Promise; } export type PublisherAssistantEventName = 'assistant_loaded' | 'assistant_opened' | 'suggestion_exposure' | 'suggestion_clicked' | 'query_submitted' | 'answer_completed' | 'answer_failed' | 'source_link_clicked' | 'recommendation_shown' | 'delegation_started' | 'delegation_stopped' | 'answer_feedback'; export interface PublisherAssistantAnalyticsEvent { event_name: PublisherAssistantEventName; timestamp: string; session_id: string; message_id?: string; page_url?: string; page_path?: string; article_slug?: string; page_title?: string; referrer?: string; device_type?: 'mobile' | 'tablet' | 'desktop' | 'unknown'; query?: string; suggestion_id?: string; suggestion_text?: string; suggestion_type?: string; suggestion_position?: number; is_sponsored?: boolean; recommendation_id?: string; brand_name?: string; delegation_session_id?: string; used_capability?: string; status?: string; latency_ms?: number; metadata?: Record; } export interface SponsoredRecommendationReportEvent { recommendation_id: string; reason: string; session_id?: string; message_id?: string; brand_name?: string; platform_surface?: string; user_id?: string; metadata?: Record; } /** * Main AdMesh SDK class for zero-code integration * * The SDK is stateless regarding session management. Developers must provide * sessionId when calling showRecommendations(). * * @example * ```typescript * import { AdMeshSDK } from '@admesh/ui-sdk'; * * const admesh = new AdMeshSDK({ apiKey: 'your-api-key' }); * * // Generate session ID on your platform * const sessionId = AdMeshSDK.createSession(); * * await admesh.showRecommendations({ * query: 'best CRM for small business', * containerId: 'admesh-recommendations', * sessionId: sessionId * }); * ``` */ export declare class AdMeshSDK { private config; private apiBaseUrl; private static inFlightPlatformResponses; private renderer; private tracker; constructor(config: AdMeshSDKConfig); /** * Get the API base URL * @returns The API base URL being used by the SDK */ getApiBaseUrl(): string; private static buildPlatformResponseCacheKey; /** * Resolve source domain for extension-originated requests. */ private getExtensionSourceDomain; /** * PLATFORM UTILITY: Generate a unique session ID for tracking recommendations * * IMPORTANT: This is a utility method for PLATFORMS to use. The SDK itself * NEVER calls this method automatically. Platforms must: * 1. Call this method (or generate their own sessionId) * 2. Store the sessionId in their own storage * 3. Pass sessionId to AdMeshProvider and SDK methods * * The SDK will throw an error if sessionId is not provided - it will never * auto-generate one. * * @returns A unique session ID (platform must store and manage this) */ static createSession(): string; /** * PLATFORM UTILITY: Generate session ID from URL for digital publishers * * This utility function helps platforms generate session IDs based on URL structure. * Platforms can call this function on page load to get a consistent session ID. * * @param url - The URL to extract session information from (defaults to current page URL) * @returns A session ID in format: session_{timestamp}_{article-slug} * * @example * ```typescript * // In your React component * const sessionId = AdMeshSDK.generateSessionIdFromUrl(); * * // Or with a specific URL * const sessionId = AdMeshSDK.generateSessionIdFromUrl('https://techcrunch.com/2025/12/30/ai-apps/'); * // Returns: "session_1739534760000_ai-apps" * ``` */ static generateSessionIdFromUrl(url?: string): string; /** * PLATFORM UTILITY: Generate a unique message ID for tracking recommendations per message * @returns A unique message ID (platform must provide this to SDK methods) */ static createMessageId(sessionId?: string): string; /** * OPTIMIZATION: Lazy initialize renderer on first use */ private getRenderer; /** * OPTIMIZATION: Lazy initialize tracker on first use */ private getTracker; private postDelegationEvent; reportDelegationTurnStarted(session: ActiveDelegationSession, metadata?: Record): Promise; reportDelegationSessionStarted(session: ActiveDelegationSession, metadata?: Record): Promise; reportDelegationTurnCompleted(session: ActiveDelegationSession, metadata?: Record): Promise; reportDelegationToolInvocation(session: ActiveDelegationSession, metadata?: Record): Promise; reportDelegationOutcome(session: ActiveDelegationSession, outcomeType: string, metadata?: Record): Promise; stopDelegationSession(session: ActiveDelegationSession, reason?: string, metadata?: Record): Promise; getActiveDelegationSession(session: ActiveDelegationSession | null): ActiveDelegationSession | null; hasActiveDelegationSession(session: ActiveDelegationSession | null): boolean; /** * Fetch and render recommendations automatically using /aip/context endpoint * * IMPORTANT: Both sessionId and messageId MUST be provided by the platform. * The SDK NEVER generates these automatically. Use AdMeshSDK.createSession() * and AdMeshSDK.createMessageId() on your platform, or generate your own IDs. */ showRecommendations(options: ShowRecommendationsOptions): Promise; /** * Fetch the canonical PlatformResponse from `/aip/context`. * * Use this when you want the full platform response returned by the operator, * including `status`, `recommendation`, `tracking`, and `delegation`. */ fetchPlatformResponse(params: { query: string; sessionId: string; messageId?: string; platformSurface?: string; model?: string; messages?: Array<{ role: string; content: string; id?: string; }>; language?: string; location?: { city?: string; state?: string; stateCode?: string; country?: string; countryCode?: string; zipcode?: string; latitude?: number; longitude?: number; }; userId?: string; }): Promise; trackPublisherAssistantEvent(event: PublisherAssistantAnalyticsEvent | PublisherAssistantAnalyticsEvent[]): Promise; reportSponsoredRecommendation(event: SponsoredRecommendationReportEvent): Promise; /** * Fire exposure for sponsored followup * * @param exposureUrl - The exposure URL to fire (can use regular exposure_url) * @param recommendationId - The recommendation ID * @param sessionId - The session ID */ fireFollowupExposure(exposureUrl: string, recommendationId: string, sessionId: string): void; /** * Fire engagement for sponsored followup * * @param engagementUrl - The engagement URL to fire * @param recommendationId - The recommendation ID * @param sessionId - The session ID * @returns Promise that resolves when engagement is fired */ fireFollowupEngagement(engagementUrl: string, recommendationId: string, sessionId: string): Promise; } export default AdMeshSDK; //# sourceMappingURL=AdMeshSDK.d.ts.map