admesh-ui-sdk 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,326 @@
1
+ # AdMesh Conversational Ad Units Integration Guide
2
+
3
+ This guide covers how to integrate AdMesh conversational ad units into chat interfaces, AI assistants, and other conversational experiences.
4
+
5
+ ## 🎯 Overview
6
+
7
+ Conversational ad units are designed to seamlessly inject product recommendations into conversations without disrupting the user experience. They can be displayed inline, as summaries, or as floating overlays.
8
+
9
+ ## 🚀 Quick Integration
10
+
11
+ ### 1. Basic Chat Integration
12
+
13
+ ```tsx
14
+ import React, { useState } from 'react';
15
+ import { AdMeshConversationalUnit } from 'admesh-ui-sdk';
16
+
17
+ function ChatInterface() {
18
+ const [messages, setMessages] = useState([]);
19
+ const [currentRecommendations, setCurrentRecommendations] = useState([]);
20
+
21
+ const handleUserMessage = async (userInput) => {
22
+ // Add user message
23
+ setMessages(prev => [...prev, {
24
+ role: 'user',
25
+ content: userInput
26
+ }]);
27
+
28
+ // Get AI response with recommendations
29
+ const response = await fetch('/api/chat', {
30
+ method: 'POST',
31
+ body: JSON.stringify({ message: userInput })
32
+ });
33
+
34
+ const data = await response.json();
35
+
36
+ // Add AI response
37
+ setMessages(prev => [...prev, {
38
+ role: 'assistant',
39
+ content: data.response,
40
+ recommendations: data.recommendations
41
+ }]);
42
+ };
43
+
44
+ return (
45
+ <div className="chat-container">
46
+ {messages.map((message, index) => (
47
+ <div key={index} className={`message ${message.role}`}>
48
+ <div className="message-content">
49
+ {message.content}
50
+ </div>
51
+
52
+ {/* Show recommendations after assistant messages */}
53
+ {message.role === 'assistant' && message.recommendations && (
54
+ <AdMeshConversationalUnit
55
+ recommendations={message.recommendations}
56
+ config={{
57
+ displayMode: 'inline',
58
+ context: 'chat',
59
+ maxRecommendations: 3,
60
+ showPoweredBy: true
61
+ }}
62
+ onRecommendationClick={(adId, admeshLink) => {
63
+ // Track click and open link
64
+ window.open(admeshLink, '_blank');
65
+ }}
66
+ />
67
+ )}
68
+ </div>
69
+ ))}
70
+ </div>
71
+ );
72
+ }
73
+ ```
74
+
75
+ ### 2. AI Assistant Integration
76
+
77
+ ```tsx
78
+ import { AdMeshConversationalUnit, AdMeshConversationSummary } from 'admesh-ui-sdk';
79
+
80
+ function AIAssistant() {
81
+ const [conversation, setConversation] = useState([]);
82
+ const [sessionSummary, setSessionSummary] = useState(null);
83
+ const [isSessionEnded, setIsSessionEnded] = useState(false);
84
+
85
+ const endConversation = () => {
86
+ setIsSessionEnded(true);
87
+ // Generate session summary with recommendations
88
+ generateSessionSummary();
89
+ };
90
+
91
+ return (
92
+ <div className="assistant-interface">
93
+ {/* Conversation messages */}
94
+ {conversation.map((msg, i) => (
95
+ <div key={i} className="message">
96
+ {msg.content}
97
+
98
+ {/* Inline recommendations during conversation */}
99
+ {msg.recommendations && !isSessionEnded && (
100
+ <AdMeshConversationalUnit
101
+ recommendations={msg.recommendations}
102
+ config={{
103
+ displayMode: 'minimal',
104
+ context: 'assistant',
105
+ maxRecommendations: 1,
106
+ autoShow: true,
107
+ delayMs: 1000
108
+ }}
109
+ />
110
+ )}
111
+ </div>
112
+ ))}
113
+
114
+ {/* Session summary at the end */}
115
+ {isSessionEnded && sessionSummary && (
116
+ <AdMeshConversationSummary
117
+ recommendations={sessionSummary.recommendations}
118
+ conversationSummary={sessionSummary.text}
119
+ showTopRecommendations={3}
120
+ onRecommendationClick={(adId, link) => window.open(link)}
121
+ onStartNewConversation={() => {
122
+ setIsSessionEnded(false);
123
+ setConversation([]);
124
+ setSessionSummary(null);
125
+ }}
126
+ />
127
+ )}
128
+ </div>
129
+ );
130
+ }
131
+ ```
132
+
133
+ ## 🎨 Display Modes
134
+
135
+ ### Inline Mode
136
+ Best for: Chat applications, conversational AI
137
+ - Shows full recommendation cards inline with the conversation
138
+ - Doesn't interrupt conversation flow
139
+ - Provides detailed product information
140
+
141
+ ```tsx
142
+ <AdMeshConversationalUnit
143
+ recommendations={recommendations}
144
+ config={{
145
+ displayMode: 'inline',
146
+ context: 'chat',
147
+ maxRecommendations: 3
148
+ }}
149
+ />
150
+ ```
151
+
152
+ ### Minimal Mode
153
+ Best for: Quick suggestions, space-constrained interfaces
154
+ - Shows match count and top recommendation only
155
+ - Very compact footprint
156
+ - Perfect for mobile interfaces
157
+
158
+ ```tsx
159
+ <AdMeshConversationalUnit
160
+ recommendations={recommendations}
161
+ config={{
162
+ displayMode: 'minimal',
163
+ context: 'assistant',
164
+ maxRecommendations: 1
165
+ }}
166
+ />
167
+ ```
168
+
169
+ ### Floating Mode
170
+ Best for: Non-intrusive suggestions, overlay recommendations
171
+ - Appears as floating overlay
172
+ - Dismissible by user
173
+ - Doesn't affect conversation layout
174
+
175
+ ```tsx
176
+ <AdMeshConversationalUnit
177
+ recommendations={recommendations}
178
+ config={{
179
+ displayMode: 'floating',
180
+ context: 'support',
181
+ maxRecommendations: 2,
182
+ position: 'bottom'
183
+ }}
184
+ onDismiss={() => console.log('User dismissed recommendations')}
185
+ />
186
+ ```
187
+
188
+ ### Summary Mode
189
+ Best for: End-of-conversation summaries, session wrap-ups
190
+ - Comprehensive summary with top recommendations
191
+ - Action buttons for next steps
192
+ - Perfect for conversation conclusions
193
+
194
+ ```tsx
195
+ <AdMeshConversationalUnit
196
+ recommendations={recommendations}
197
+ config={{
198
+ displayMode: 'summary',
199
+ context: 'agent'
200
+ }}
201
+ conversationSummary="Based on our conversation about CRM solutions..."
202
+ />
203
+ ```
204
+
205
+ ## 🔧 Advanced Configuration
206
+
207
+ ### Delayed Display
208
+ Show recommendations after a delay to avoid overwhelming users:
209
+
210
+ ```tsx
211
+ <AdMeshConversationalUnit
212
+ recommendations={recommendations}
213
+ config={{
214
+ displayMode: 'inline',
215
+ context: 'chat',
216
+ autoShow: false,
217
+ delayMs: 2000 // Show after 2 seconds
218
+ }}
219
+ />
220
+ ```
221
+
222
+ ### Context-Aware Styling
223
+ Different contexts automatically apply appropriate styling:
224
+
225
+ ```tsx
226
+ // Chat context - casual, friendly styling
227
+ config={{ context: 'chat' }}
228
+
229
+ // Assistant context - professional, helpful styling
230
+ config={{ context: 'assistant' }}
231
+
232
+ // Agent context - business-focused styling
233
+ config={{ context: 'agent' }}
234
+
235
+ // Support context - problem-solving styling
236
+ config={{ context: 'support' }}
237
+ ```
238
+
239
+ ### Custom Theming
240
+ Apply consistent theming across your application:
241
+
242
+ ```tsx
243
+ const theme = {
244
+ mode: 'dark',
245
+ accentColor: '#3b82f6',
246
+ borderRadius: '8px',
247
+ fontFamily: 'Inter, sans-serif'
248
+ };
249
+
250
+ <AdMeshConversationalUnit
251
+ recommendations={recommendations}
252
+ config={{ displayMode: 'inline', context: 'chat' }}
253
+ theme={theme}
254
+ />
255
+ ```
256
+
257
+ ## 📱 Mobile Optimization
258
+
259
+ Conversational ad units are mobile-first and automatically adapt:
260
+
261
+ ```tsx
262
+ // Automatically uses compact layout on mobile
263
+ <AdMeshConversationalUnit
264
+ recommendations={recommendations}
265
+ config={{
266
+ displayMode: 'inline',
267
+ context: 'chat',
268
+ maxRecommendations: 2 // Fewer recommendations on mobile
269
+ }}
270
+ />
271
+ ```
272
+
273
+ ## 🎯 Best Practices
274
+
275
+ ### 1. Timing
276
+ - Show recommendations after the AI provides a helpful response
277
+ - Use delays for non-urgent suggestions
278
+ - Don't show recommendations on every message
279
+
280
+ ### 2. Relevance
281
+ - Only show recommendations when they're contextually relevant
282
+ - Limit to 1-3 recommendations to avoid overwhelming users
283
+ - Prioritize by intent match score
284
+
285
+ ### 3. User Experience
286
+ - Make recommendations dismissible
287
+ - Provide clear value proposition
288
+ - Don't interrupt active conversations
289
+
290
+ ### 4. Performance
291
+ - Load recommendations asynchronously
292
+ - Cache recommendations when possible
293
+ - Use minimal mode for better performance
294
+
295
+ ## 🔗 Integration with AdMesh API
296
+
297
+ ```tsx
298
+ const getRecommendations = async (userQuery, sessionId) => {
299
+ const response = await fetch('/api/admesh/recommendations', {
300
+ method: 'POST',
301
+ headers: { 'Content-Type': 'application/json' },
302
+ body: JSON.stringify({
303
+ query: userQuery,
304
+ session_id: sessionId,
305
+ context: 'chat'
306
+ })
307
+ });
308
+
309
+ const data = await response.json();
310
+ return data.recommendations;
311
+ };
312
+
313
+ // Use in your chat handler
314
+ const handleMessage = async (message) => {
315
+ const recommendations = await getRecommendations(message, sessionId);
316
+
317
+ if (recommendations && recommendations.length > 0) {
318
+ // Show conversational ad unit
319
+ setCurrentRecommendations(recommendations);
320
+ }
321
+ };
322
+ ```
323
+
324
+ ## 🎉 Complete Example
325
+
326
+ See `examples/conversational-usage.jsx` for a complete working example with all display modes and configurations.
package/README.md CHANGED
@@ -56,21 +56,34 @@ function App() {
56
56
 
57
57
  ## 🧩 Components
58
58
 
59
- ### AdMeshLayout
59
+ ### Core Components
60
+
61
+ #### AdMeshLayout
60
62
  The main layout component that automatically chooses the best display format.
61
63
 
62
- ### AdMeshProductCard
64
+ #### AdMeshProductCard
63
65
  Individual product recommendation card.
64
66
 
65
- ### AdMeshCompareTable
67
+ #### AdMeshCompareTable
66
68
  Side-by-side product comparison table.
67
69
 
68
- ### AdMeshBadge
70
+ #### AdMeshBadge
69
71
  Reusable badge component.
70
72
 
71
- ### AdMeshLinkTracker
73
+ #### AdMeshLinkTracker
72
74
  Wrapper for tracking any clickable element.
73
75
 
76
+ ### 💬 Conversational Ad Units
77
+
78
+ #### AdMeshConversationalUnit
79
+ Smart conversational ad component that adapts to different chat contexts and display modes.
80
+
81
+ #### AdMeshConversationSummary
82
+ End-of-conversation summary with top recommendations and action buttons.
83
+
84
+ #### AdMeshInlineRecommendation
85
+ Compact inline recommendation component perfect for chat interfaces.
86
+
74
87
  ## 🎨 Theming
75
88
 
76
89
  ```tsx
@@ -78,6 +91,186 @@ const theme = {
78
91
  mode: 'dark', // 'light' | 'dark'
79
92
  accentColor: '#8b5cf6', // Custom accent color
80
93
  };
94
+ ```
95
+
96
+ ## 💬 Conversational Ad Units
97
+
98
+ Perfect for chat interfaces, AI assistants, and conversational experiences.
99
+
100
+ ### Quick Start - Conversational Units
101
+
102
+ ```tsx
103
+ import React from 'react';
104
+ import { AdMeshConversationalUnit } from 'admesh-ui-sdk';
105
+
106
+ const recommendations = [
107
+ {
108
+ title: "HubSpot CRM",
109
+ reason: "Perfect for remote teams with excellent collaboration features",
110
+ intent_match_score: 0.92,
111
+ admesh_link: "https://useadmesh.com/track?ad_id=hubspot-123",
112
+ ad_id: "hubspot-123",
113
+ product_id: "hubspot-crm",
114
+ has_free_tier: true,
115
+ trial_days: 14,
116
+ keywords: ["CRM", "Sales", "Marketing"]
117
+ }
118
+ ];
119
+
120
+ function ChatInterface() {
121
+ return (
122
+ <div className="chat-container">
123
+ {/* Your chat messages */}
124
+ <div className="message">I need a CRM for my team</div>
125
+
126
+ {/* AdMesh conversational ad unit */}
127
+ <AdMeshConversationalUnit
128
+ recommendations={recommendations}
129
+ config={{
130
+ displayMode: 'inline', // 'inline' | 'minimal' | 'floating' | 'summary'
131
+ context: 'chat',
132
+ maxRecommendations: 3,
133
+ showPoweredBy: true
134
+ }}
135
+ onRecommendationClick={(adId, admeshLink) => {
136
+ window.open(admeshLink, '_blank');
137
+ }}
138
+ />
139
+ </div>
140
+ );
141
+ }
142
+ ```
143
+
144
+ ### Display Modes
145
+
146
+ #### Inline Mode
147
+ Full recommendations displayed inline with the conversation:
148
+ ```tsx
149
+ <AdMeshConversationalUnit
150
+ recommendations={recommendations}
151
+ config={{ displayMode: 'inline', context: 'chat' }}
152
+ />
153
+ ```
154
+
155
+ #### Minimal Mode
156
+ Compact display showing match count and top recommendation:
157
+ ```tsx
158
+ <AdMeshConversationalUnit
159
+ recommendations={recommendations}
160
+ config={{ displayMode: 'minimal', context: 'assistant' }}
161
+ />
162
+ ```
163
+
164
+ #### Floating Mode
165
+ Floating overlay that doesn't interrupt the conversation flow:
166
+ ```tsx
167
+ <AdMeshConversationalUnit
168
+ recommendations={recommendations}
169
+ config={{ displayMode: 'floating', context: 'support' }}
170
+ />
171
+ ```
172
+
173
+ #### Summary Mode
174
+ End-of-conversation summary with top recommendations:
175
+ ```tsx
176
+ <AdMeshConversationalUnit
177
+ recommendations={recommendations}
178
+ config={{ displayMode: 'summary', context: 'agent' }}
179
+ conversationSummary="We discussed your CRM needs..."
180
+ />
181
+ ```
182
+
183
+ ### Individual Conversational Components
184
+
185
+ #### AdMeshConversationSummary
186
+ Perfect for end-of-conversation summaries:
187
+
188
+ ```tsx
189
+ import { AdMeshConversationSummary } from 'admesh-ui-sdk';
190
+
191
+ <AdMeshConversationSummary
192
+ recommendations={recommendations}
193
+ conversationSummary="Here's what we discussed and found for you..."
194
+ showTopRecommendations={3}
195
+ onRecommendationClick={(adId, link) => window.open(link)}
196
+ onStartNewConversation={() => startNewChat()}
197
+ />
198
+ ```
199
+
200
+ #### AdMeshInlineRecommendation
201
+ Compact inline recommendations for chat bubbles:
202
+
203
+ ```tsx
204
+ import { AdMeshInlineRecommendation } from 'admesh-ui-sdk';
205
+
206
+ <AdMeshInlineRecommendation
207
+ recommendation={recommendation}
208
+ compact={true}
209
+ showReason={true}
210
+ onClick={(adId, link) => window.open(link)}
211
+ />
212
+ ```
213
+
214
+ ### Configuration Options
215
+
216
+ #### ConversationalAdConfig
217
+
218
+ ```tsx
219
+ interface ConversationalAdConfig {
220
+ displayMode: 'inline' | 'summary' | 'floating' | 'minimal';
221
+ context: 'chat' | 'assistant' | 'agent' | 'support';
222
+ maxRecommendations?: number; // Default: 3
223
+ showPoweredBy?: boolean; // Default: true
224
+ autoShow?: boolean; // Default: true
225
+ delayMs?: number; // Default: 0
226
+ position?: 'top' | 'bottom' | 'inline'; // Default: 'inline'
227
+ }
228
+ ```
229
+
230
+ ### Integration Examples
231
+
232
+ #### Chat Application
233
+ ```tsx
234
+ function ChatApp() {
235
+ const [messages, setMessages] = useState([]);
236
+ const [recommendations, setRecommendations] = useState([]);
237
+
238
+ const handleUserMessage = async (message) => {
239
+ // Add user message
240
+ setMessages(prev => [...prev, { role: 'user', content: message }]);
241
+
242
+ // Get AI response and recommendations
243
+ const response = await getAIResponse(message);
244
+ setMessages(prev => [...prev, { role: 'assistant', content: response.text }]);
245
+
246
+ // Show recommendations if available
247
+ if (response.recommendations) {
248
+ setRecommendations(response.recommendations);
249
+ }
250
+ };
251
+
252
+ return (
253
+ <div className="chat-container">
254
+ {messages.map((msg, i) => (
255
+ <div key={i} className={`message ${msg.role}`}>
256
+ {msg.content}
257
+
258
+ {/* Show recommendations after assistant messages */}
259
+ {msg.role === 'assistant' && recommendations.length > 0 && (
260
+ <AdMeshConversationalUnit
261
+ recommendations={recommendations}
262
+ config={{
263
+ displayMode: 'inline',
264
+ context: 'chat',
265
+ maxRecommendations: 2
266
+ }}
267
+ />
268
+ )}
269
+ </div>
270
+ ))}
271
+ </div>
272
+ );
273
+ }
81
274
 
82
275
  <AdMeshLayout theme={theme} recommendations={recommendations} />
83
276
  ```
package/dist/index.d.ts CHANGED
@@ -28,6 +28,43 @@ export declare interface AdMeshConfig {
28
28
  debug?: boolean;
29
29
  }
30
30
 
31
+ export declare const AdMeshConversationalUnit: default_2.FC<AdMeshConversationalUnitProps>;
32
+
33
+ export declare interface AdMeshConversationalUnitProps {
34
+ recommendations: AdMeshRecommendation[];
35
+ config: ConversationalAdConfig;
36
+ theme?: AdMeshTheme;
37
+ conversationSummary?: string;
38
+ userQuery?: string;
39
+ sessionId?: string;
40
+ onRecommendationClick?: (adId: string, admeshLink: string) => void;
41
+ onDismiss?: () => void;
42
+ className?: string;
43
+ }
44
+
45
+ export declare const AdMeshConversationSummary: default_2.FC<AdMeshConversationSummaryProps>;
46
+
47
+ export declare interface AdMeshConversationSummaryProps {
48
+ recommendations: AdMeshRecommendation[];
49
+ conversationSummary: string;
50
+ theme?: AdMeshTheme;
51
+ showTopRecommendations?: number;
52
+ onRecommendationClick?: (adId: string, admeshLink: string) => void;
53
+ onStartNewConversation?: () => void;
54
+ className?: string;
55
+ }
56
+
57
+ export declare const AdMeshInlineRecommendation: default_2.FC<AdMeshInlineRecommendationProps>;
58
+
59
+ export declare interface AdMeshInlineRecommendationProps {
60
+ recommendation: AdMeshRecommendation;
61
+ theme?: AdMeshTheme;
62
+ compact?: boolean;
63
+ showReason?: boolean;
64
+ onClick?: (adId: string, admeshLink: string) => void;
65
+ className?: string;
66
+ }
67
+
31
68
  export declare const AdMeshLayout: default_2.FC<AdMeshLayoutProps>;
32
69
 
33
70
  export declare interface AdMeshLayoutProps {
@@ -141,6 +178,20 @@ export declare type BadgeVariant = 'primary' | 'secondary' | 'success' | 'warnin
141
178
 
142
179
  export declare const buildAdMeshLink: (baseLink: string, adId: string, additionalParams?: Record<string, string>) => string;
143
180
 
181
+ export declare interface ConversationalAdConfig {
182
+ displayMode: ConversationalDisplayMode;
183
+ context: ConversationContext;
184
+ maxRecommendations?: number;
185
+ showPoweredBy?: boolean;
186
+ autoShow?: boolean;
187
+ delayMs?: number;
188
+ position?: 'top' | 'bottom' | 'inline';
189
+ }
190
+
191
+ export declare type ConversationalDisplayMode = 'inline' | 'summary' | 'floating' | 'minimal';
192
+
193
+ export declare type ConversationContext = 'chat' | 'assistant' | 'agent' | 'support';
194
+
144
195
  export declare const DEFAULT_CONFIG: {
145
196
  trackingEnabled: boolean;
146
197
  debug: boolean;