admesh-ui-sdk
Version:
Beautiful, modern React components for displaying AI-powered product recommendations with citation-based conversation ads, auto-triggered widgets, floating chat, conversational interfaces, persistent sidebar, and built-in tracking. Includes zero-code SDK
154 lines • 5.55 kB
TypeScript
import { AdMeshTheme, AIPContextResponse } from '../types/index';
export interface AdMeshSDKConfig {
apiKey: string;
theme?: AdMeshTheme;
apiBaseUrl?: string;
}
export interface ShowRecommendationsOptions {
query: string;
containerId: string;
theme?: AdMeshTheme;
followups_container_id?: string;
session_id: string;
messageId: string;
platformSurface?: string;
model?: string;
messages?: Array<{
role: string;
content: string;
}>;
locale?: string;
geo?: string;
userId?: string;
/** Callback to paste content to input field (for bridge format CTA) */
onPasteToInput?: (content: string) => void;
/** Callback to execute query when follow-up is selected (required for follow-up functionality) */
onExecuteQuery?: (query: string) => void | Promise<void>;
}
/**
* Main AdMesh SDK class for zero-code integration
*
* The SDK is stateless regarding session management. Developers must provide
* session_id 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',
* session_id: sessionId
* });
* ```
*/
export declare class AdMeshSDK {
private config;
private apiBaseUrl;
private renderer;
private tracker;
constructor(config: AdMeshSDKConfig);
/**
* Get the API base URL
* @returns The API base URL being used by the SDK
*/
getApiBaseUrl(): string;
/**
* 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 a unique message ID for tracking recommendations per message
*
* 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 messageId) for each user message
* 2. Pass messageId to SDK methods (showRecommendations, fetchRecommendationFromAIPContext)
*
* The SDK will throw an error if messageId is not provided - it will never
* auto-generate one.
*
* @param sessionId Optional session ID to include in the message ID
* @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;
/**
* Fetch and render recommendations automatically using /aip/context endpoint
*
* IMPORTANT: Both session_id 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<void>;
/**
* Fetch recommendation from the /aip/context endpoint (new auction-based endpoint)
*
* Public method for fetching recommendation data without rendering.
* Useful for format detection and custom rendering logic.
*
* IMPORTANT: Both sessionId and messageId MUST be provided by the platform.
* The SDK NEVER generates these automatically.
*/
fetchRecommendationFromAIPContext(params: {
query: string;
sessionId: string;
messageId?: string;
platformSurface?: string;
model?: string;
messages?: Array<{
role: string;
content: string;
id?: string;
}>;
language?: string;
geo_country?: string;
userId?: string;
}): Promise<AIPContextResponse>;
/**
* Convert AIP context response to AdMeshRecommendation format for compatibility
*/
private convertAIPResponseToRecommendation;
/**
* 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<void>;
}
export default AdMeshSDK;
//# sourceMappingURL=AdMeshSDK.d.ts.map