@hef2024/llmasaservice-ui 0.16.10 → 0.18.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.
- package/README.md +28 -0
- package/dist/index.d.mts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +70 -69
- package/dist/index.mjs +70 -69
- package/docs/CONVERSATION-HISTORY.md +863 -0
- package/docs/CONVERSATION-STARTING.md +815 -0
- package/package.json +1 -1
- package/src/AIAgentPanel.css +20 -1
- package/src/AIAgentPanel.tsx +110 -23
- package/src/AIChatPanel.tsx +36 -80
- package/src/components/ui/Button.tsx +2 -0
- package/src/components/ui/Dialog.tsx +2 -0
- package/src/components/ui/Input.tsx +2 -0
- package/src/components/ui/Select.tsx +2 -0
- package/src/components/ui/Tooltip.tsx +2 -0
- package/src/components/ui/index.ts +2 -0
|
@@ -0,0 +1,863 @@
|
|
|
1
|
+
# Conversation History Settings Guide
|
|
2
|
+
|
|
3
|
+
This guide covers how to configure the conversation history sidebar in AIAgentPanel, including how to enable/disable it, control its position, and customize its behavior.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Overview](#overview)
|
|
8
|
+
- [Enabling/Disabling Conversation History](#enablingdisabling-conversation-history)
|
|
9
|
+
- [Controlling Sidebar Position](#controlling-sidebar-position)
|
|
10
|
+
- [Collapse/Expand Functionality](#collapseexpand-functionality)
|
|
11
|
+
- [History List Limit](#history-list-limit)
|
|
12
|
+
- [Complete Configuration Examples](#complete-configuration-examples)
|
|
13
|
+
- [API Reference](#api-reference)
|
|
14
|
+
- [Common Use Cases](#common-use-cases)
|
|
15
|
+
- [Best Practices](#best-practices)
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Overview
|
|
20
|
+
|
|
21
|
+
The **AIAgentPanel** includes a built-in conversation history sidebar that displays all past conversations organized by time (Today, Yesterday, This Week, etc.). This sidebar provides users with:
|
|
22
|
+
|
|
23
|
+
- Quick access to previous conversations
|
|
24
|
+
- Time-grouped organization
|
|
25
|
+
- Search functionality
|
|
26
|
+
- Visual indicators for active conversations
|
|
27
|
+
- Agent-specific icons
|
|
28
|
+
|
|
29
|
+
The sidebar is **enabled by default** and appears on the **left side** of the panel by default.
|
|
30
|
+
|
|
31
|
+

|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Enabling/Disabling Conversation History
|
|
36
|
+
|
|
37
|
+
### Disabling Conversation History
|
|
38
|
+
|
|
39
|
+
To hide the conversation history sidebar completely, set the `showConversationHistory` prop to `false`:
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import AIAgentPanel from '@hef2024/llmasaservice-ui';
|
|
43
|
+
|
|
44
|
+
function App() {
|
|
45
|
+
return (
|
|
46
|
+
<AIAgentPanel
|
|
47
|
+
showConversationHistory={false} // Hides the sidebar
|
|
48
|
+
agents={['agent-1', 'agent-2']}
|
|
49
|
+
customerId="user-123"
|
|
50
|
+
apiKey="your-api-key"
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### When the Sidebar is Hidden
|
|
57
|
+
|
|
58
|
+
When `showConversationHistory={false}`:
|
|
59
|
+
|
|
60
|
+
- The sidebar is completely removed from the UI
|
|
61
|
+
- The chat panel takes up the full width
|
|
62
|
+
- Users can only interact with the current conversation
|
|
63
|
+
- No past conversations are displayed
|
|
64
|
+
- Conversation data is still persisted on the backend (if `apiKey` is provided)
|
|
65
|
+
- The CSS class `ai-agent-panel--no-history` is added to the root element
|
|
66
|
+
|
|
67
|
+
### Enabling Conversation History (Default)
|
|
68
|
+
|
|
69
|
+
To explicitly enable conversation history, you can either:
|
|
70
|
+
|
|
71
|
+
1. **Omit the prop** (it's enabled by default):
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
<AIAgentPanel
|
|
75
|
+
agents={['agent-1']}
|
|
76
|
+
customerId="user-123"
|
|
77
|
+
apiKey="your-api-key"
|
|
78
|
+
/>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
2. **Or explicitly set it to `true`**:
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
<AIAgentPanel
|
|
85
|
+
showConversationHistory={true} // Explicitly enabled
|
|
86
|
+
agents={['agent-1']}
|
|
87
|
+
customerId="user-123"
|
|
88
|
+
apiKey="your-api-key"
|
|
89
|
+
/>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Requirements for Conversation History
|
|
93
|
+
|
|
94
|
+
For conversation history to work properly, you must provide:
|
|
95
|
+
|
|
96
|
+
- **`customerId`** (required): Unique identifier for the user
|
|
97
|
+
- **`apiKey`** (recommended): Your LLM as a Service API key for backend persistence
|
|
98
|
+
- **`agents`**: At least one agent ID
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
<AIAgentPanel
|
|
102
|
+
showConversationHistory={true}
|
|
103
|
+
customerId="user-123" // Required
|
|
104
|
+
apiKey="your-api-key" // Required for backend persistence
|
|
105
|
+
agents={['agent-1', 'agent-2']}
|
|
106
|
+
/>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Controlling Sidebar Position
|
|
112
|
+
|
|
113
|
+
The `sidebarPosition` prop controls which side of the panel the conversation history sidebar appears on.
|
|
114
|
+
|
|
115
|
+
### Left Sidebar (Default)
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
<AIAgentPanel
|
|
119
|
+
sidebarPosition="left" // Sidebar on the left (default)
|
|
120
|
+
agents={['agent-1']}
|
|
121
|
+
customerId="user-123"
|
|
122
|
+
/>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Layout:**
|
|
126
|
+
```
|
|
127
|
+
┌─────────────────────────────────────┐
|
|
128
|
+
│ [Sidebar] │ Chat Panel │
|
|
129
|
+
│ │ │
|
|
130
|
+
│ History │ Messages │
|
|
131
|
+
│ • Today │ │
|
|
132
|
+
│ • Week │ │
|
|
133
|
+
└─────────────────────────────────────┘
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Right Sidebar
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
<AIAgentPanel
|
|
140
|
+
sidebarPosition="right" // Sidebar on the right
|
|
141
|
+
agents={['agent-1']}
|
|
142
|
+
customerId="user-123"
|
|
143
|
+
/>
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**Layout:**
|
|
147
|
+
```
|
|
148
|
+
┌─────────────────────────────────────┐
|
|
149
|
+
│ Chat Panel │ [Sidebar] │
|
|
150
|
+
│ │ │
|
|
151
|
+
│ Messages │ History │
|
|
152
|
+
│ │ • Today │
|
|
153
|
+
│ │ • Week │
|
|
154
|
+
└─────────────────────────────────────┘
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### When to Use Each Position
|
|
158
|
+
|
|
159
|
+
| Position | Best For |
|
|
160
|
+
|----------|----------|
|
|
161
|
+
| **Left** (default) | - Standard layouts<br>- Desktop-first applications<br>- When users read left-to-right<br>- Consistent with common chat UIs |
|
|
162
|
+
| **Right** | - Right-to-left languages<br>- Custom layouts where left space is used<br>- Matching your app's existing sidebar position<br>- User preference |
|
|
163
|
+
|
|
164
|
+
### Example: Dynamic Position Based on User Preference
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
function App() {
|
|
168
|
+
const [sidebarSide, setSidebarSide] = useState<'left' | 'right'>('left');
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<div>
|
|
172
|
+
<div className="settings">
|
|
173
|
+
<label>
|
|
174
|
+
Sidebar Position:
|
|
175
|
+
<select
|
|
176
|
+
value={sidebarSide}
|
|
177
|
+
onChange={(e) => setSidebarSide(e.target.value as 'left' | 'right')}
|
|
178
|
+
>
|
|
179
|
+
<option value="left">Left</option>
|
|
180
|
+
<option value="right">Right</option>
|
|
181
|
+
</select>
|
|
182
|
+
</label>
|
|
183
|
+
</div>
|
|
184
|
+
|
|
185
|
+
<AIAgentPanel
|
|
186
|
+
sidebarPosition={sidebarSide}
|
|
187
|
+
agents={['agent-1']}
|
|
188
|
+
customerId="user-123"
|
|
189
|
+
/>
|
|
190
|
+
</div>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Collapse/Expand Functionality
|
|
198
|
+
|
|
199
|
+
The conversation history sidebar can be collapsed to save screen space while still keeping the chat panel visible.
|
|
200
|
+
|
|
201
|
+
### How It Works
|
|
202
|
+
|
|
203
|
+
- **Collapsed State**: Sidebar shows only a thin strip with icon buttons
|
|
204
|
+
- **Expanded State**: Sidebar shows full conversation history
|
|
205
|
+
- **Toggle Button**: Click the expand/collapse button to switch states
|
|
206
|
+
- **Persistence**: The collapsed state is saved in `localStorage` and persists across sessions
|
|
207
|
+
|
|
208
|
+
### User Interaction
|
|
209
|
+
|
|
210
|
+
When the sidebar is collapsed:
|
|
211
|
+
|
|
212
|
+
1. Only the agent icons and action buttons are visible
|
|
213
|
+
2. The chat panel expands to use the available space
|
|
214
|
+
3. Click the expand button (chevron icon) to restore the sidebar
|
|
215
|
+
|
|
216
|
+
When the sidebar is expanded:
|
|
217
|
+
|
|
218
|
+
1. Full conversation history is visible
|
|
219
|
+
2. Search bar, new conversation button, and conversation list are shown
|
|
220
|
+
3. Click the collapse button (chevron icon) to minimize the sidebar
|
|
221
|
+
|
|
222
|
+
### Collapsed View
|
|
223
|
+
|
|
224
|
+
```
|
|
225
|
+
┌────┬──────────────────────────────┐
|
|
226
|
+
│ ► │ Chat Panel │
|
|
227
|
+
│ ⊕ │ │
|
|
228
|
+
│ 🤖 │ Messages │
|
|
229
|
+
│ 🤖 │ │
|
|
230
|
+
└────┴──────────────────────────────┘
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Expanded View
|
|
234
|
+
|
|
235
|
+
```
|
|
236
|
+
┌─────────────┬────────────────────┐
|
|
237
|
+
│ ◄ Search │ Chat Panel │
|
|
238
|
+
│ ⊕ New Chat │ │
|
|
239
|
+
│ │ Messages │
|
|
240
|
+
│ Today │ │
|
|
241
|
+
│ • Conv 1 │ │
|
|
242
|
+
│ • Conv 2 │ │
|
|
243
|
+
│ │ │
|
|
244
|
+
│ Yesterday │ │
|
|
245
|
+
│ • Conv 3 │ │
|
|
246
|
+
└─────────────┴────────────────────┘
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Programmatic Control
|
|
250
|
+
|
|
251
|
+
The collapse state is managed internally and persists using `localStorage`:
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
// The state is automatically saved as:
|
|
255
|
+
localStorage.setItem('ai-agent-panel-sidebar-collapsed', 'true'); // or 'false'
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Default State
|
|
259
|
+
|
|
260
|
+
By default, the sidebar starts **expanded**. Users can collapse it, and their preference will be remembered.
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## History List Limit
|
|
265
|
+
|
|
266
|
+
Control how many past conversations are displayed in the sidebar using the `historyListLimit` prop.
|
|
267
|
+
|
|
268
|
+
### Basic Usage
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
<AIAgentPanel
|
|
272
|
+
historyListLimit={20} // Show up to 20 conversations
|
|
273
|
+
agents={['agent-1']}
|
|
274
|
+
customerId="user-123"
|
|
275
|
+
/>
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Default Behavior
|
|
279
|
+
|
|
280
|
+
If not specified, the default limit is **50 conversations**.
|
|
281
|
+
|
|
282
|
+
### Examples
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
// Show only the 10 most recent conversations
|
|
286
|
+
<AIAgentPanel
|
|
287
|
+
historyListLimit={10}
|
|
288
|
+
agents={['agent-1']}
|
|
289
|
+
customerId="user-123"
|
|
290
|
+
/>
|
|
291
|
+
|
|
292
|
+
// Show up to 100 conversations (for power users)
|
|
293
|
+
<AIAgentPanel
|
|
294
|
+
historyListLimit={100}
|
|
295
|
+
agents={['agent-1']}
|
|
296
|
+
customerId="user-123"
|
|
297
|
+
/>
|
|
298
|
+
|
|
299
|
+
// Minimal history (good for mobile)
|
|
300
|
+
<AIAgentPanel
|
|
301
|
+
historyListLimit={5}
|
|
302
|
+
agents={['agent-1']}
|
|
303
|
+
customerId="user-123"
|
|
304
|
+
/>
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Performance Considerations
|
|
308
|
+
|
|
309
|
+
| Limit | Use Case | Performance |
|
|
310
|
+
|-------|----------|-------------|
|
|
311
|
+
| **5-10** | Mobile devices, limited screen space | ⚡ Excellent |
|
|
312
|
+
| **20-30** | Standard desktop applications | ⚡ Good |
|
|
313
|
+
| **50** (default) | Power users, desktop apps | ✓ Good |
|
|
314
|
+
| **100+** | Advanced users with lots of history | ⚠️ May impact load time |
|
|
315
|
+
|
|
316
|
+
### When to Adjust the Limit
|
|
317
|
+
|
|
318
|
+
- **Reduce** for:
|
|
319
|
+
- Mobile/tablet devices
|
|
320
|
+
- Users who create many conversations
|
|
321
|
+
- Performance-sensitive applications
|
|
322
|
+
|
|
323
|
+
- **Increase** for:
|
|
324
|
+
- Desktop applications
|
|
325
|
+
- Power users who need access to many past conversations
|
|
326
|
+
- Applications where conversation history is critical
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
## Complete Configuration Examples
|
|
331
|
+
|
|
332
|
+
### Example 1: Minimal Configuration (Sidebar Hidden)
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
import AIAgentPanel from '@hef2024/llmasaservice-ui';
|
|
336
|
+
|
|
337
|
+
function MinimalApp() {
|
|
338
|
+
return (
|
|
339
|
+
<AIAgentPanel
|
|
340
|
+
showConversationHistory={false} // No sidebar
|
|
341
|
+
agents={['assistant']}
|
|
342
|
+
customerId="user-123"
|
|
343
|
+
apiKey="your-api-key"
|
|
344
|
+
/>
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
**Use Case:** Simple chat interface without history navigation
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
### Example 2: Right-Aligned Sidebar
|
|
354
|
+
|
|
355
|
+
```typescript
|
|
356
|
+
function RightSidebarApp() {
|
|
357
|
+
return (
|
|
358
|
+
<AIAgentPanel
|
|
359
|
+
showConversationHistory={true}
|
|
360
|
+
sidebarPosition="right" // Sidebar on the right
|
|
361
|
+
agents={['agent-1', 'agent-2']}
|
|
362
|
+
customerId="user-123"
|
|
363
|
+
apiKey="your-api-key"
|
|
364
|
+
/>
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
**Use Case:** Matching your app's existing right-aligned navigation
|
|
370
|
+
|
|
371
|
+
---
|
|
372
|
+
|
|
373
|
+
### Example 3: Mobile-Optimized
|
|
374
|
+
|
|
375
|
+
```typescript
|
|
376
|
+
function MobileApp() {
|
|
377
|
+
return (
|
|
378
|
+
<AIAgentPanel
|
|
379
|
+
showConversationHistory={true}
|
|
380
|
+
historyListLimit={5} // Only 5 recent conversations
|
|
381
|
+
defaultWidth={350}
|
|
382
|
+
agents={['agent-1']}
|
|
383
|
+
customerId="user-123"
|
|
384
|
+
apiKey="your-api-key"
|
|
385
|
+
/>
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
**Use Case:** Mobile-first design with limited screen space
|
|
391
|
+
|
|
392
|
+
---
|
|
393
|
+
|
|
394
|
+
### Example 4: Full-Featured Desktop App
|
|
395
|
+
|
|
396
|
+
```typescript
|
|
397
|
+
function DesktopApp() {
|
|
398
|
+
return (
|
|
399
|
+
<AIAgentPanel
|
|
400
|
+
showConversationHistory={true}
|
|
401
|
+
sidebarPosition="left"
|
|
402
|
+
historyListLimit={50} // Default, showing up to 50
|
|
403
|
+
defaultWidth={720}
|
|
404
|
+
minWidth={520}
|
|
405
|
+
maxWidth={1200}
|
|
406
|
+
agents={['agent-1', 'agent-2', 'agent-3']}
|
|
407
|
+
customerId="user-123"
|
|
408
|
+
apiKey="your-api-key"
|
|
409
|
+
/>
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
**Use Case:** Desktop application with full conversation management
|
|
415
|
+
|
|
416
|
+
---
|
|
417
|
+
|
|
418
|
+
### Example 5: User Preference Settings
|
|
419
|
+
|
|
420
|
+
```typescript
|
|
421
|
+
function AppWithPreferences() {
|
|
422
|
+
const [showHistory, setShowHistory] = useState(true);
|
|
423
|
+
const [sidebarPosition, setSidebarPosition] = useState<'left' | 'right'>('left');
|
|
424
|
+
const [historyLimit, setHistoryLimit] = useState(20);
|
|
425
|
+
|
|
426
|
+
return (
|
|
427
|
+
<div>
|
|
428
|
+
{/* User Settings Panel */}
|
|
429
|
+
<div className="settings-panel">
|
|
430
|
+
<label>
|
|
431
|
+
<input
|
|
432
|
+
type="checkbox"
|
|
433
|
+
checked={showHistory}
|
|
434
|
+
onChange={(e) => setShowHistory(e.target.checked)}
|
|
435
|
+
/>
|
|
436
|
+
Show Conversation History
|
|
437
|
+
</label>
|
|
438
|
+
|
|
439
|
+
{showHistory && (
|
|
440
|
+
<>
|
|
441
|
+
<label>
|
|
442
|
+
Sidebar Position:
|
|
443
|
+
<select
|
|
444
|
+
value={sidebarPosition}
|
|
445
|
+
onChange={(e) => setSidebarPosition(e.target.value as 'left' | 'right')}
|
|
446
|
+
>
|
|
447
|
+
<option value="left">Left</option>
|
|
448
|
+
<option value="right">Right</option>
|
|
449
|
+
</select>
|
|
450
|
+
</label>
|
|
451
|
+
|
|
452
|
+
<label>
|
|
453
|
+
History Limit:
|
|
454
|
+
<input
|
|
455
|
+
type="number"
|
|
456
|
+
min={5}
|
|
457
|
+
max={100}
|
|
458
|
+
value={historyLimit}
|
|
459
|
+
onChange={(e) => setHistoryLimit(Number(e.target.value))}
|
|
460
|
+
/>
|
|
461
|
+
</label>
|
|
462
|
+
</>
|
|
463
|
+
)}
|
|
464
|
+
</div>
|
|
465
|
+
|
|
466
|
+
{/* AI Panel with User Preferences */}
|
|
467
|
+
<AIAgentPanel
|
|
468
|
+
showConversationHistory={showHistory}
|
|
469
|
+
sidebarPosition={sidebarPosition}
|
|
470
|
+
historyListLimit={historyLimit}
|
|
471
|
+
agents={['agent-1']}
|
|
472
|
+
customerId="user-123"
|
|
473
|
+
apiKey="your-api-key"
|
|
474
|
+
/>
|
|
475
|
+
</div>
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
**Use Case:** Application with user-configurable settings
|
|
481
|
+
|
|
482
|
+
---
|
|
483
|
+
|
|
484
|
+
### Example 6: Conditional History Based on User Role
|
|
485
|
+
|
|
486
|
+
```typescript
|
|
487
|
+
function RoleBasedApp({ userRole }: { userRole: 'guest' | 'user' | 'admin' }) {
|
|
488
|
+
// Guests don't see history, users see limited history, admins see full history
|
|
489
|
+
const historyConfig = {
|
|
490
|
+
guest: { show: false, limit: 0 },
|
|
491
|
+
user: { show: true, limit: 10 },
|
|
492
|
+
admin: { show: true, limit: 100 },
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
const config = historyConfig[userRole];
|
|
496
|
+
|
|
497
|
+
return (
|
|
498
|
+
<AIAgentPanel
|
|
499
|
+
showConversationHistory={config.show}
|
|
500
|
+
historyListLimit={config.limit}
|
|
501
|
+
agents={['agent-1']}
|
|
502
|
+
customerId={`${userRole}-123`}
|
|
503
|
+
apiKey="your-api-key"
|
|
504
|
+
/>
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
**Use Case:** Different history access based on user permissions
|
|
510
|
+
|
|
511
|
+
---
|
|
512
|
+
|
|
513
|
+
## API Reference
|
|
514
|
+
|
|
515
|
+
### Props Related to Conversation History
|
|
516
|
+
|
|
517
|
+
```typescript
|
|
518
|
+
interface AIAgentPanelProps {
|
|
519
|
+
// Enable/disable the conversation history sidebar
|
|
520
|
+
showConversationHistory?: boolean; // Default: true
|
|
521
|
+
|
|
522
|
+
// Control which side the sidebar appears on
|
|
523
|
+
sidebarPosition?: 'left' | 'right'; // Default: 'left'
|
|
524
|
+
|
|
525
|
+
// Limit how many conversations to display in the list
|
|
526
|
+
historyListLimit?: number; // Default: 50
|
|
527
|
+
|
|
528
|
+
// Required for conversation history to work
|
|
529
|
+
customerId: string; // Required
|
|
530
|
+
apiKey?: string; // Required for backend persistence
|
|
531
|
+
agents: string[]; // Required
|
|
532
|
+
}
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
### Complete Type Definitions
|
|
536
|
+
|
|
537
|
+
```typescript
|
|
538
|
+
// Sidebar Position
|
|
539
|
+
type SidebarPosition = 'left' | 'right';
|
|
540
|
+
|
|
541
|
+
// Example Usage
|
|
542
|
+
const config: AIAgentPanelProps = {
|
|
543
|
+
showConversationHistory: true,
|
|
544
|
+
sidebarPosition: 'left',
|
|
545
|
+
historyListLimit: 30,
|
|
546
|
+
customerId: 'user-123',
|
|
547
|
+
apiKey: 'your-api-key',
|
|
548
|
+
agents: ['agent-1'],
|
|
549
|
+
};
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
### CSS Classes Applied
|
|
553
|
+
|
|
554
|
+
When conversation history is disabled:
|
|
555
|
+
```css
|
|
556
|
+
.ai-agent-panel--no-history {
|
|
557
|
+
/* Applied to root element when showConversationHistory={false} */
|
|
558
|
+
}
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
When sidebar position changes:
|
|
562
|
+
```css
|
|
563
|
+
.ai-agent-panel--sidebar-left {
|
|
564
|
+
/* Applied when sidebarPosition="left" (default) */
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
.ai-agent-panel--sidebar-right {
|
|
568
|
+
/* Applied when sidebarPosition="right" */
|
|
569
|
+
}
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
When sidebar is collapsed:
|
|
573
|
+
```css
|
|
574
|
+
.ai-agent-panel__sidebar--collapsed {
|
|
575
|
+
/* Applied to sidebar when collapsed by user */
|
|
576
|
+
}
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
---
|
|
580
|
+
|
|
581
|
+
## Common Use Cases
|
|
582
|
+
|
|
583
|
+
### Use Case 1: Clean, Distraction-Free Chat
|
|
584
|
+
|
|
585
|
+
Perfect for focused conversations without past history visible.
|
|
586
|
+
|
|
587
|
+
```typescript
|
|
588
|
+
<AIAgentPanel
|
|
589
|
+
showConversationHistory={false}
|
|
590
|
+
agents={['focused-assistant']}
|
|
591
|
+
customerId="user-123"
|
|
592
|
+
/>
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
---
|
|
596
|
+
|
|
597
|
+
### Use Case 2: Mobile-First Design
|
|
598
|
+
|
|
599
|
+
Optimized for smaller screens with limited history.
|
|
600
|
+
|
|
601
|
+
```typescript
|
|
602
|
+
<AIAgentPanel
|
|
603
|
+
showConversationHistory={true}
|
|
604
|
+
historyListLimit={5}
|
|
605
|
+
defaultWidth={350}
|
|
606
|
+
sidebarPosition="left"
|
|
607
|
+
agents={['mobile-agent']}
|
|
608
|
+
customerId="user-123"
|
|
609
|
+
/>
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
---
|
|
613
|
+
|
|
614
|
+
### Use Case 3: Power User Dashboard
|
|
615
|
+
|
|
616
|
+
Full history with lots of conversations visible.
|
|
617
|
+
|
|
618
|
+
```typescript
|
|
619
|
+
<AIAgentPanel
|
|
620
|
+
showConversationHistory={true}
|
|
621
|
+
historyListLimit={100}
|
|
622
|
+
sidebarPosition="left"
|
|
623
|
+
agents={['agent-1', 'agent-2', 'agent-3']}
|
|
624
|
+
customerId="power-user-123"
|
|
625
|
+
apiKey="your-api-key"
|
|
626
|
+
/>
|
|
627
|
+
```
|
|
628
|
+
|
|
629
|
+
---
|
|
630
|
+
|
|
631
|
+
### Use Case 4: Right-to-Left Language Support
|
|
632
|
+
|
|
633
|
+
Better UX for RTL languages like Arabic or Hebrew.
|
|
634
|
+
|
|
635
|
+
```typescript
|
|
636
|
+
<AIAgentPanel
|
|
637
|
+
showConversationHistory={true}
|
|
638
|
+
sidebarPosition="right" // Better for RTL languages
|
|
639
|
+
agents={['rtl-agent']}
|
|
640
|
+
customerId="user-123"
|
|
641
|
+
/>
|
|
642
|
+
```
|
|
643
|
+
|
|
644
|
+
---
|
|
645
|
+
|
|
646
|
+
### Use Case 5: Embedded Widget Mode
|
|
647
|
+
|
|
648
|
+
Minimal interface embedded in another application.
|
|
649
|
+
|
|
650
|
+
```typescript
|
|
651
|
+
<AIAgentPanel
|
|
652
|
+
showConversationHistory={false} // Hide history in widget mode
|
|
653
|
+
defaultWidth={400}
|
|
654
|
+
position="right"
|
|
655
|
+
agents={['widget-agent']}
|
|
656
|
+
customerId="user-123"
|
|
657
|
+
/>
|
|
658
|
+
```
|
|
659
|
+
|
|
660
|
+
---
|
|
661
|
+
|
|
662
|
+
## Best Practices
|
|
663
|
+
|
|
664
|
+
### ✅ Do's
|
|
665
|
+
|
|
666
|
+
1. **Enable history for full-featured apps**
|
|
667
|
+
```typescript
|
|
668
|
+
<AIAgentPanel showConversationHistory={true} />
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
2. **Disable history for simple, focused interactions**
|
|
672
|
+
```typescript
|
|
673
|
+
<AIAgentPanel showConversationHistory={false} />
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
3. **Adjust history limit based on user needs**
|
|
677
|
+
```typescript
|
|
678
|
+
// Mobile
|
|
679
|
+
<AIAgentPanel historyListLimit={5} />
|
|
680
|
+
|
|
681
|
+
// Desktop
|
|
682
|
+
<AIAgentPanel historyListLimit={50} />
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
4. **Match sidebar position to your app's layout**
|
|
686
|
+
```typescript
|
|
687
|
+
<AIAgentPanel sidebarPosition="right" /> // If your app has left nav
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
5. **Always provide required props**
|
|
691
|
+
```typescript
|
|
692
|
+
<AIAgentPanel
|
|
693
|
+
customerId="user-123" // Required
|
|
694
|
+
apiKey="your-api-key" // Required for persistence
|
|
695
|
+
agents={['agent-1']} // Required
|
|
696
|
+
/>
|
|
697
|
+
```
|
|
698
|
+
|
|
699
|
+
### ❌ Don'ts
|
|
700
|
+
|
|
701
|
+
1. **Don't disable history without providing alternative navigation**
|
|
702
|
+
```typescript
|
|
703
|
+
// ❌ Bad: No way to access past conversations
|
|
704
|
+
<AIAgentPanel showConversationHistory={false} />
|
|
705
|
+
|
|
706
|
+
// ✅ Good: If disabling, ensure users don't need history
|
|
707
|
+
// or provide external navigation
|
|
708
|
+
```
|
|
709
|
+
|
|
710
|
+
2. **Don't set excessively high history limits**
|
|
711
|
+
```typescript
|
|
712
|
+
// ❌ Bad: May impact performance
|
|
713
|
+
<AIAgentPanel historyListLimit={1000} />
|
|
714
|
+
|
|
715
|
+
// ✅ Good: Reasonable limit
|
|
716
|
+
<AIAgentPanel historyListLimit={50} />
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
3. **Don't forget required dependencies**
|
|
720
|
+
```typescript
|
|
721
|
+
// ❌ Bad: Missing customerId
|
|
722
|
+
<AIAgentPanel
|
|
723
|
+
showConversationHistory={true}
|
|
724
|
+
agents={['agent-1']}
|
|
725
|
+
/>
|
|
726
|
+
|
|
727
|
+
// ✅ Good: All required props
|
|
728
|
+
<AIAgentPanel
|
|
729
|
+
showConversationHistory={true}
|
|
730
|
+
customerId="user-123"
|
|
731
|
+
agents={['agent-1']}
|
|
732
|
+
/>
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
4. **Don't frequently change sidebar position**
|
|
736
|
+
```typescript
|
|
737
|
+
// ❌ Bad: Constantly switching confuses users
|
|
738
|
+
const [position, setPosition] = useState<'left' | 'right'>('left');
|
|
739
|
+
useEffect(() => {
|
|
740
|
+
setInterval(() => {
|
|
741
|
+
setPosition(prev => prev === 'left' ? 'right' : 'left');
|
|
742
|
+
}, 1000);
|
|
743
|
+
}, []);
|
|
744
|
+
|
|
745
|
+
// ✅ Good: Stable position, changed only via user preference
|
|
746
|
+
const [position] = useState<'left' | 'right'>('left');
|
|
747
|
+
```
|
|
748
|
+
|
|
749
|
+
---
|
|
750
|
+
|
|
751
|
+
## Troubleshooting
|
|
752
|
+
|
|
753
|
+
### Issue: Conversation History Not Showing
|
|
754
|
+
|
|
755
|
+
**Symptoms:** Sidebar is visible but no conversations appear
|
|
756
|
+
|
|
757
|
+
**Solutions:**
|
|
758
|
+
|
|
759
|
+
1. Ensure `customerId` is provided:
|
|
760
|
+
```typescript
|
|
761
|
+
<AIAgentPanel customerId="user-123" {...props} />
|
|
762
|
+
```
|
|
763
|
+
|
|
764
|
+
2. Ensure `apiKey` is provided for backend persistence:
|
|
765
|
+
```typescript
|
|
766
|
+
<AIAgentPanel apiKey="your-api-key" {...props} />
|
|
767
|
+
```
|
|
768
|
+
|
|
769
|
+
3. Check that conversations have been created:
|
|
770
|
+
- Create a new conversation using the + button
|
|
771
|
+
- Or use `startNewConversation` API
|
|
772
|
+
|
|
773
|
+
4. Verify `historyListLimit` isn't set too low:
|
|
774
|
+
```typescript
|
|
775
|
+
<AIAgentPanel historyListLimit={50} {...props} /> // Not historyListLimit={0}
|
|
776
|
+
```
|
|
777
|
+
|
|
778
|
+
---
|
|
779
|
+
|
|
780
|
+
### Issue: Sidebar Position Not Changing
|
|
781
|
+
|
|
782
|
+
**Symptoms:** Setting `sidebarPosition` doesn't move the sidebar
|
|
783
|
+
|
|
784
|
+
**Solutions:**
|
|
785
|
+
|
|
786
|
+
1. Ensure you're using correct values:
|
|
787
|
+
```typescript
|
|
788
|
+
// ✅ Correct
|
|
789
|
+
sidebarPosition="left" // or "right"
|
|
790
|
+
|
|
791
|
+
// ❌ Incorrect
|
|
792
|
+
sidebarPosition="top" // Invalid
|
|
793
|
+
```
|
|
794
|
+
|
|
795
|
+
2. Check CSS isn't overriding the position:
|
|
796
|
+
- Look for custom CSS that might be interfering
|
|
797
|
+
- Check browser DevTools for conflicting styles
|
|
798
|
+
|
|
799
|
+
3. Verify the component is re-rendering:
|
|
800
|
+
```typescript
|
|
801
|
+
const [position, setPosition] = useState<'left' | 'right'>('left');
|
|
802
|
+
// Make sure state changes trigger re-render
|
|
803
|
+
```
|
|
804
|
+
|
|
805
|
+
---
|
|
806
|
+
|
|
807
|
+
### Issue: Sidebar Won't Collapse
|
|
808
|
+
|
|
809
|
+
**Symptoms:** Clicking collapse button doesn't work
|
|
810
|
+
|
|
811
|
+
**Solutions:**
|
|
812
|
+
|
|
813
|
+
1. Check if `showConversationHistory` is disabled:
|
|
814
|
+
```typescript
|
|
815
|
+
// If this is false, there's no sidebar to collapse
|
|
816
|
+
showConversationHistory={true}
|
|
817
|
+
```
|
|
818
|
+
|
|
819
|
+
2. Clear localStorage if state is stuck:
|
|
820
|
+
```javascript
|
|
821
|
+
localStorage.removeItem('ai-agent-panel-sidebar-collapsed');
|
|
822
|
+
```
|
|
823
|
+
|
|
824
|
+
3. Check for JavaScript errors in console
|
|
825
|
+
|
|
826
|
+
---
|
|
827
|
+
|
|
828
|
+
### Issue: Too Many Conversations Causing Slow Load
|
|
829
|
+
|
|
830
|
+
**Symptoms:** Panel takes a long time to load or feels sluggish
|
|
831
|
+
|
|
832
|
+
**Solutions:**
|
|
833
|
+
|
|
834
|
+
1. Reduce `historyListLimit`:
|
|
835
|
+
```typescript
|
|
836
|
+
<AIAgentPanel historyListLimit={20} {...props} /> // Instead of 100
|
|
837
|
+
```
|
|
838
|
+
|
|
839
|
+
2. Consider pagination or lazy loading (future feature)
|
|
840
|
+
|
|
841
|
+
3. Archive old conversations on the backend
|
|
842
|
+
|
|
843
|
+
---
|
|
844
|
+
|
|
845
|
+
## Related Documentation
|
|
846
|
+
|
|
847
|
+
- [AIAgentPanel API Reference](../local-dev-docs/AIAGENTPANEL.md)
|
|
848
|
+
- [Conversation Starting Guide](./CONVERSATION-STARTING.md)
|
|
849
|
+
- [Quick Start Guide](../local-dev-docs/QUICK-START.md)
|
|
850
|
+
- [Troubleshooting Conversations](../local-dev-docs/TROUBLESHOOTING-CONVERSATIONS.md)
|
|
851
|
+
|
|
852
|
+
---
|
|
853
|
+
|
|
854
|
+
## Version History
|
|
855
|
+
|
|
856
|
+
- **v0.17.0+** - Conversation history sidebar with collapse/expand
|
|
857
|
+
- **v0.16.x** - Initial conversation history support
|
|
858
|
+
|
|
859
|
+
---
|
|
860
|
+
|
|
861
|
+
## Feedback
|
|
862
|
+
|
|
863
|
+
If you have questions or suggestions about conversation history configuration, please open an issue on GitHub or contact support.
|