@automattic/agenttic-ui 0.1.10 → 0.1.12

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.
Files changed (50) hide show
  1. package/README.md +281 -387
  2. package/dist/components/AgentUI.d.ts +19 -1
  3. package/dist/components/AgentUI.d.ts.map +1 -1
  4. package/dist/components/AgentUIContainer.d.ts +8 -0
  5. package/dist/components/AgentUIContainer.d.ts.map +1 -0
  6. package/dist/components/chat/Chat.d.ts.map +1 -1
  7. package/dist/components/chat/ChatFooter.stories.d.ts.map +1 -1
  8. package/dist/components/chat/ChatHeader.d.ts +2 -1
  9. package/dist/components/chat/ChatHeader.d.ts.map +1 -1
  10. package/dist/components/chat/ChatInput.d.ts +2 -1
  11. package/dist/components/chat/ChatInput.d.ts.map +1 -1
  12. package/dist/components/chat/ChatInput.stories.d.ts +39 -1
  13. package/dist/components/chat/ChatInput.stories.d.ts.map +1 -1
  14. package/dist/components/chat/Messages.d.ts +2 -1
  15. package/dist/components/chat/Messages.d.ts.map +1 -1
  16. package/dist/components/chat/Notice.d.ts +3 -1
  17. package/dist/components/chat/Notice.d.ts.map +1 -1
  18. package/dist/components/chat/Notice.stories.d.ts +3 -0
  19. package/dist/components/chat/Notice.stories.d.ts.map +1 -1
  20. package/dist/components/chat/Suggestions.d.ts +2 -0
  21. package/dist/components/chat/Suggestions.d.ts.map +1 -1
  22. package/dist/components/composable/AgentUIConversationView.d.ts +8 -0
  23. package/dist/components/composable/AgentUIConversationView.d.ts.map +1 -0
  24. package/dist/components/composable/AgentUIFooter.d.ts +7 -0
  25. package/dist/components/composable/AgentUIFooter.d.ts.map +1 -0
  26. package/dist/components/composable/AgentUIHeader.d.ts +5 -0
  27. package/dist/components/composable/AgentUIHeader.d.ts.map +1 -0
  28. package/dist/components/composable/AgentUIInput.d.ts +9 -0
  29. package/dist/components/composable/AgentUIInput.d.ts.map +1 -0
  30. package/dist/components/composable/AgentUIMessages.d.ts +5 -0
  31. package/dist/components/composable/AgentUIMessages.d.ts.map +1 -0
  32. package/dist/components/composable/AgentUINotice.d.ts +5 -0
  33. package/dist/components/composable/AgentUINotice.d.ts.map +1 -0
  34. package/dist/components/composable/AgentUISuggestions.d.ts +6 -0
  35. package/dist/components/composable/AgentUISuggestions.d.ts.map +1 -0
  36. package/dist/components/ui/button.d.ts +2 -2
  37. package/dist/components/ui/button.d.ts.map +1 -1
  38. package/dist/components/views/CompactView.d.ts +4 -1
  39. package/dist/components/views/CompactView.d.ts.map +1 -1
  40. package/dist/context/AgentUIContext.d.ts +41 -0
  41. package/dist/context/AgentUIContext.d.ts.map +1 -0
  42. package/dist/hooks/useMultiTimeout.d.ts +11 -0
  43. package/dist/hooks/useMultiTimeout.d.ts.map +1 -0
  44. package/dist/index.css +1 -1
  45. package/dist/index.d.ts +19 -1
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +1388 -1852
  48. package/dist/types/index.d.ts +2 -0
  49. package/dist/types/index.d.ts.map +1 -1
  50. package/package.json +3 -6
package/README.md CHANGED
@@ -10,321 +10,345 @@ npm install @automattic/agenttic-ui
10
10
 
11
11
  ## Key Features
12
12
 
13
- - Pure UI components with no agent communication logic
14
- - Floating and embedded chat variants
15
- - Smooth animations and drag-and-drop positioning
16
- - Message actions and markdown rendering
17
- - Request cancellation UI with stop button functionality
18
- - TypeScript support with comprehensive types
19
- - Storybook component documentation
20
- - Modular component architecture for custom layouts
13
+ - Pure UI components with no agent communication logic
14
+ - Composable architecture for complete layout flexibility
15
+ - Floating and embedded chat variants
16
+ - Controlled input support for external value management
17
+ - Smooth animations and drag-and-drop positioning
18
+ - Message actions and markdown rendering
19
+ - Request cancellation UI with stop button functionality
20
+ - TypeScript support with comprehensive types
21
+ - Storybook component documentation
21
22
 
22
23
  ## Quick Start
23
24
 
24
- ### Complete Chat Interface
25
+ ### Complete Chat Interface (Convenience API)
25
26
 
26
27
  ```tsx
27
28
  import { useAgentChat } from '@automattic/agenttic-client';
28
29
  import { AgentUI } from '@automattic/agenttic-ui';
29
30
 
30
31
  function ChatApplication() {
31
- const {
32
- messages,
33
- isProcessing,
34
- error,
35
- onSubmit,
36
- abortCurrentRequest,
37
- suggestions,
38
- clearSuggestions,
39
- messageRenderer
40
- } = useAgentChat({
41
- agentId: 'big-sky',
42
- sessionId: 'my-session'
43
- });
44
-
45
- return (
46
- <AgentUI
47
- messages={messages}
48
- isProcessing={isProcessing}
49
- error={error}
50
- onSubmit={onSubmit}
51
- onStop={abortCurrentRequest}
52
- suggestions={suggestions}
53
- clearSuggestions={clearSuggestions}
54
- messageRenderer={messageRenderer}
55
- variant="floating"
56
- placeholder="Ask me anything..."
57
- />
58
- );
32
+ const {
33
+ messages,
34
+ isProcessing,
35
+ error,
36
+ onSubmit,
37
+ abortCurrentRequest,
38
+ suggestions,
39
+ clearSuggestions,
40
+ messageRenderer,
41
+ } = useAgentChat( {
42
+ agentId: 'big-sky',
43
+ sessionId: 'my-session',
44
+ } );
45
+
46
+ return (
47
+ <AgentUI
48
+ messages={ messages }
49
+ isProcessing={ isProcessing }
50
+ error={ error }
51
+ onSubmit={ onSubmit }
52
+ onStop={ abortCurrentRequest }
53
+ suggestions={ suggestions }
54
+ clearSuggestions={ clearSuggestions }
55
+ messageRenderer={ messageRenderer }
56
+ variant="floating"
57
+ placeholder="Ask me anything..."
58
+ />
59
+ );
59
60
  }
60
61
  ```
61
62
 
62
- ### Embedded Chat
63
+ ### Composable Architecture
64
+
65
+ For complete control over layout and component ordering:
63
66
 
64
67
  ```tsx
65
- <AgentUI
66
- messages={messages}
67
- isProcessing={isProcessing}
68
- error={error}
69
- onSubmit={onSubmit}
70
- variant="embedded"
71
- placeholder="How can I help you?"
72
- />
73
- ```
68
+ import { AgentUI } from '@automattic/agenttic-ui';
74
69
 
75
- ## Core Components
70
+ function CustomChatLayout() {
71
+ return (
72
+ <AgentUI.Container
73
+ messages={ messages }
74
+ isProcessing={ isProcessing }
75
+ error={ error }
76
+ onSubmit={ onSubmit }
77
+ onStop={ abortCurrentRequest }
78
+ variant="embedded"
79
+ >
80
+ <AgentUI.ConversationView>
81
+ <AgentUI.Header />
82
+ <AgentUI.Messages />
83
+ <AgentUI.Footer>
84
+ <AgentUI.Notice />
85
+ <AgentUI.Input />
86
+ </AgentUI.Footer>
87
+ <AgentUI.Suggestions />
88
+ </AgentUI.ConversationView>
89
+ </AgentUI.Container>
90
+ );
91
+ }
92
+ ```
76
93
 
77
- ### AgentUI
94
+ ### Controlled Input
78
95
 
79
- The main component that provides a complete chat interface.
96
+ External control of input value and changes:
80
97
 
81
98
  ```tsx
82
- interface AgentUIProps {
83
- // Core chat data
84
- messages: Message[];
85
- isProcessing: boolean;
86
- error?: string | null;
87
- onSubmit: (message: string) => void;
88
- onStop?: () => void; // Optional callback to stop current request
89
-
90
- // UI configuration
91
- variant?: 'floating' | 'embedded';
92
- placeholder?: string;
93
- triggerIcon?: React.ReactNode;
94
- notice?: NoticeConfig;
95
- emptyView?: React.ReactNode;
96
-
97
- // Chat state management (floating variant)
98
- floatingChatState?: ChatState;
99
- onOpen?: () => void;
100
- onExpand?: () => void;
101
- onClose?: () => void;
102
-
103
- // Suggestions
104
- suggestions?: Suggestion[];
105
- clearSuggestions?: () => void;
106
-
107
- // Message rendering
108
- messageRenderer?: ComponentType<{ children: string }>;
109
-
110
- // Styling
111
- className?: string;
112
- style?: React.CSSProperties;
99
+ function ExternallyControlledChat() {
100
+ const [ inputValue, setInputValue ] = useState( '' );
101
+
102
+ return (
103
+ <AgentUI
104
+ messages={ messages }
105
+ isProcessing={ isProcessing }
106
+ onSubmit={ onSubmit }
107
+ inputValue={ inputValue }
108
+ onInputChange={ setInputValue }
109
+ variant="embedded"
110
+ />
111
+ );
113
112
  }
114
113
  ```
115
114
 
116
- **Variants:**
117
- - `floating` - Draggable chat widget with collapsed/compact/expanded states
118
- - `embedded` - Fixed chat interface for integration in existing layouts
115
+ ## Architecture
119
116
 
120
- ### Individual Components
117
+ ### AgentUI Components
121
118
 
122
- For custom chat layouts, use individual components:
119
+ **AgentUI** - Convenience wrapper with default layout
120
+ **AgentUI.Container** - Root container with state management and context
121
+ **AgentUI.ConversationView** - Conversation layout wrapper
122
+ **AgentUI.Header** - Chat header with close/expand buttons
123
+ **AgentUI.Messages** - Message history display
124
+ **AgentUI.Footer** - Footer wrapper for input and notice
125
+ **AgentUI.Input** - Text input with auto-resize
126
+ **AgentUI.Notice** - Error and notification display
127
+ **AgentUI.Suggestions** - Quick action suggestions
123
128
 
124
- ```tsx
125
- import {
126
- Chat,
127
- Messages,
128
- Message,
129
- ChatInput,
130
- Suggestions
131
- } from '@automattic/agenttic-ui';
129
+ ### AgentUIProps Interface
132
130
 
133
- function CustomChat() {
134
- return (
135
- <div className="my-chat-container">
136
- <Messages messages={messages} messageRenderer={messageRenderer} />
137
- <Suggestions
138
- suggestions={suggestions}
139
- onSuggestionClick={onSubmit}
140
- onClear={clearSuggestions}
141
- />
142
- <ChatInput
143
- value={inputValue}
144
- onChange={setInputValue}
145
- onSubmit={onSubmit}
146
- placeholder="Type a message..."
147
- isProcessing={isProcessing}
148
- />
149
- </div>
150
- );
131
+ ```tsx
132
+ interface AgentUIProps {
133
+ // Core chat data
134
+ messages: Message[];
135
+ isProcessing: boolean;
136
+ error?: string | null;
137
+ onSubmit: ( message: string ) => void;
138
+ onStop?: () => void;
139
+
140
+ // UI configuration
141
+ variant?: 'floating' | 'embedded';
142
+ placeholder?: string | string[];
143
+ triggerIcon?: React.ReactNode;
144
+ notice?: NoticeConfig;
145
+ emptyView?: React.ReactNode;
146
+
147
+ // Chat state management (floating variant)
148
+ floatingChatState?: ChatState;
149
+ onOpen?: () => void;
150
+ onExpand?: () => void;
151
+ onClose?: () => void;
152
+
153
+ // Suggestions
154
+ suggestions?: Suggestion[];
155
+ clearSuggestions?: () => void;
156
+
157
+ // Message rendering
158
+ messageRenderer?: ComponentType< { children: string } >;
159
+
160
+ // Controlled input (optional)
161
+ inputValue?: string;
162
+ onInputChange?: ( value: string ) => void;
163
+
164
+ // Styling
165
+ className?: string;
166
+ style?: React.CSSProperties;
151
167
  }
152
168
  ```
153
169
 
154
- ## Component APIs
170
+ ## Usage Patterns
155
171
 
156
- ### Chat
172
+ ### Flexible Component Ordering
157
173
 
158
- Main chat component supporting both floating and embedded variants.
174
+ Place suggestions anywhere in your layout:
159
175
 
160
176
  ```tsx
161
- <Chat
162
- messages={messages}
163
- isProcessing={isProcessing}
164
- error={error}
165
- onSubmit={onSubmit}
166
- variant="floating"
167
- placeholder="Ask anything..."
168
- suggestions={suggestions}
169
- clearSuggestions={clearSuggestions}
170
- messageRenderer={messageRenderer}
171
- />
177
+ <AgentUI.Container {...props}>
178
+ <AgentUI.ConversationView>
179
+ <AgentUI.Messages />
180
+ <AgentUI.Suggestions /> {/* Above input */}
181
+ <AgentUI.Footer>
182
+ <AgentUI.Input />
183
+ </AgentUI.Footer>
184
+ </AgentUI.ConversationView>
185
+ </AgentUI.Container>
186
+
187
+ // Or below input:
188
+ <AgentUI.Container {...props}>
189
+ <AgentUI.ConversationView>
190
+ <AgentUI.Messages />
191
+ <AgentUI.Footer>
192
+ <AgentUI.Input />
193
+ </AgentUI.Footer>
194
+ <AgentUI.Suggestions /> {/* Below input */}
195
+ </AgentUI.ConversationView>
196
+ </AgentUI.Container>
172
197
  ```
173
198
 
174
- ### Messages
199
+ ### Individual Components
175
200
 
176
- Container for displaying message history.
201
+ Use individual components for complete customization:
177
202
 
178
203
  ```tsx
179
- <Messages
180
- messages={messages}
181
- messageRenderer={messageRenderer}
182
- emptyView={<div>No messages yet</div>}
183
- />
204
+ import {
205
+ Messages,
206
+ Message,
207
+ ChatInput,
208
+ Suggestions,
209
+ } from '@automattic/agenttic-ui';
210
+
211
+ function FullyCustomChat() {
212
+ return (
213
+ <div className="my-chat-container">
214
+ <Messages
215
+ messages={ messages }
216
+ messageRenderer={ messageRenderer }
217
+ />
218
+ <ChatInput
219
+ value={ inputValue }
220
+ onChange={ setInputValue }
221
+ onSubmit={ onSubmit }
222
+ placeholder="Type a message..."
223
+ isProcessing={ isProcessing }
224
+ />
225
+ <Suggestions
226
+ suggestions={ suggestions }
227
+ onSuggestionClick={ onSubmit }
228
+ onClear={ clearSuggestions }
229
+ />
230
+ </div>
231
+ );
232
+ }
184
233
  ```
185
234
 
186
- ### Message
235
+ ### Request Cancellation
187
236
 
188
- Individual message component with action support.
237
+ Stop button appears automatically during processing:
189
238
 
190
239
  ```tsx
191
- <Message
192
- message={message}
193
- messageRenderer={messageRenderer}
194
- showIcon={true}
240
+ <AgentUI
241
+ isProcessing={ isProcessing }
242
+ onStop={ abortCurrentRequest }
243
+ // Submit button becomes stop button when processing
195
244
  />
196
245
  ```
197
246
 
198
- ### ChatInput
199
-
200
- Text input with auto-resize and submit handling.
247
+ ### Custom Message Renderer
201
248
 
202
249
  ```tsx
203
- <ChatInput
204
- value={value}
205
- onChange={setValue}
206
- onSubmit={handleSubmit}
207
- onKeyDown={handleKeyDown}
208
- onStop={handleStop} // Optional callback to stop current request
209
- placeholder="Type a message..."
210
- isProcessing={false}
211
- textareaRef={textareaRef}
212
- />
250
+ import { ReactMarkdown } from 'react-markdown';
251
+
252
+ const customRenderer = ( { children }: { children: string } ) => (
253
+ <ReactMarkdown remarkPlugins={ [ remarkGfm ] }>{ children }</ReactMarkdown>
254
+ );
255
+
256
+ <AgentUI messageRenderer={ customRenderer } />;
213
257
  ```
214
258
 
215
- ### Suggestions
259
+ ### Chat State Control
216
260
 
217
- Quick action suggestions for users.
261
+ For floating variant, control state externally:
218
262
 
219
263
  ```tsx
220
- <Suggestions
221
- suggestions={[
222
- { id: '1', label: 'Help me code', prompt: 'Can you help me write code?' },
223
- { id: '2', label: 'Explain concept', prompt: 'Explain this concept to me' }
224
- ]}
225
- onSuggestionClick={onSubmit}
226
- onClear={clearSuggestions}
227
- />
264
+ const [ chatState, setChatState ] = useState< ChatState >( 'collapsed' );
265
+
266
+ <AgentUI
267
+ variant="floating"
268
+ floatingChatState={ chatState }
269
+ onOpen={ () => setChatState( 'compact' ) }
270
+ onExpand={ () => setChatState( 'expanded' ) }
271
+ onClose={ () => setChatState( 'collapsed' ) }
272
+ />;
228
273
  ```
229
274
 
230
275
  ## Hooks
231
276
 
232
277
  ### useChat
233
278
 
234
- Manages chat state for floating variant.
279
+ Manages floating chat state:
235
280
 
236
281
  ```tsx
237
282
  const {
238
- state, // 'collapsed' | 'compact' | 'expanded'
239
- setState,
240
- isOpen, // boolean
241
- open, // () => void
242
- close, // () => void
243
- toggle // () => void
244
- } = useChat(initialState);
283
+ state, // 'collapsed' | 'compact' | 'expanded'
284
+ setState,
285
+ isOpen, // boolean
286
+ open, // () => void
287
+ close, // () => void
288
+ toggle, // () => void
289
+ } = useChat( initialState );
245
290
  ```
246
291
 
247
292
  ### useInput
248
293
 
249
- Manages text input state with auto-resize and keyboard handling.
294
+ Manages input state with auto-resize:
250
295
 
251
296
  ```tsx
252
- const {
253
- value,
254
- setValue,
255
- clear,
256
- textareaRef,
257
- handleKeyDown,
258
- adjustHeight
259
- } = useInput({
260
- value: inputValue,
261
- setValue: setInputValue,
262
- onSubmit: handleSubmit,
263
- isProcessing: false
264
- });
265
- ```
266
-
267
- ## Icons
268
-
269
- Pre-built icon components for consistent UI:
270
-
271
- ```tsx
272
- import {
273
- ThumbsUpIcon,
274
- ThumbsDownIcon,
275
- CopyIcon,
276
- StopIcon,
277
- ArrowUpIcon,
278
- XIcon,
279
- BigSkyIcon,
280
- StylesIcon
281
- } from '@automattic/agenttic-ui';
297
+ const { value, setValue, clear, textareaRef, handleKeyDown, adjustHeight } =
298
+ useInput( {
299
+ value: inputValue,
300
+ setValue: setInputValue,
301
+ onSubmit: handleSubmit,
302
+ isProcessing: false,
303
+ } );
282
304
  ```
283
305
 
284
306
  ## Type Definitions
285
307
 
286
308
  ```tsx
287
309
  interface Message {
288
- id: string;
289
- role: 'user' | 'agent';
290
- content: Array<{
291
- type: 'text' | 'image_url' | 'component';
292
- text?: string;
293
- image_url?: string;
294
- component?: React.ComponentType;
295
- componentProps?: any;
296
- }>;
297
- timestamp: number;
298
- archived: boolean;
299
- showIcon: boolean;
300
- icon?: string;
301
- actions?: MessageAction[];
310
+ id: string;
311
+ role: 'user' | 'agent';
312
+ content: Array< {
313
+ type: 'text' | 'image_url' | 'component';
314
+ text?: string;
315
+ image_url?: string;
316
+ component?: React.ComponentType;
317
+ componentProps?: any;
318
+ } >;
319
+ timestamp: number;
320
+ archived: boolean;
321
+ showIcon: boolean;
322
+ icon?: string;
323
+ actions?: MessageAction[];
302
324
  }
303
325
 
304
326
  interface MessageAction {
305
- id: string;
306
- icon: React.ReactNode;
307
- label: string;
308
- onClick: (message: Message) => void | Promise<void>;
309
- tooltip?: string;
310
- disabled?: boolean;
327
+ id: string;
328
+ icon?: React.ReactNode;
329
+ label: string;
330
+ onClick: ( message: Message ) => void | Promise< void >;
331
+ tooltip?: string;
332
+ disabled?: boolean;
333
+ pressed?: boolean;
334
+ showLabel?: boolean;
311
335
  }
312
336
 
313
337
  interface Suggestion {
314
- id: string;
315
- label: string;
316
- prompt: string;
338
+ id: string;
339
+ label: string;
340
+ prompt: string;
317
341
  }
318
342
 
319
343
  interface NoticeConfig {
320
- icon?: React.ReactNode;
321
- message: string;
322
- action?: {
323
- label: string;
324
- onClick: () => void;
325
- };
326
- dismissible?: boolean;
327
- onDismiss?: () => void;
344
+ icon?: React.ReactNode;
345
+ message: string;
346
+ action?: {
347
+ label: string;
348
+ onClick: () => void;
349
+ };
350
+ dismissible?: boolean;
351
+ onDismiss?: () => void;
328
352
  }
329
353
 
330
354
  type ChatState = 'collapsed' | 'compact' | 'expanded';
@@ -334,163 +358,46 @@ type ChatState = 'collapsed' | 'compact' | 'expanded';
334
358
 
335
359
  ### CSS Import
336
360
 
337
- Components automatically import their styles. For manual control:
338
-
339
- ```css
340
- /* In your CSS */
341
- @import '@automattic/agenttic-ui/index.css';
342
- ```
343
-
344
361
  ```tsx
345
- // In JavaScript/TypeScript
346
362
  import '@automattic/agenttic-ui/index.css';
347
363
  ```
348
364
 
349
365
  ### CSS Scoping
350
366
 
351
- All AgentUI styles are scoped to the `.agenttic` class to prevent conflicts with host applications. This ensures that the component styles don't interfere with your existing styles.
367
+ All styles are scoped to `.agenttic` class to prevent conflicts.
352
368
 
353
369
  ### Customization
354
370
 
355
- Override CSS custom properties to theme the entire chat or specific areas:
371
+ Override CSS custom properties:
356
372
 
357
373
  ```css
358
- /* Global theming */
359
374
  .agenttic {
360
- --color-primary: #your-brand-color;
361
- --color-background: #ffffff;
362
- --color-foreground: #000000;
363
- /* ...other custom properties as needed. */
375
+ --color-primary: #your-brand-color;
376
+ --color-background: #ffffff;
377
+ --color-foreground: #000000;
364
378
  }
365
379
 
366
- /* Target specific UI areas, e.g. the chat footer as seen in Big Sky embedded site spec. */
367
- .agenttic [data-slot="chat-footer"] {
368
- --color-background: oklch(1 0 0);
369
- --color-foreground: oklch(0.241 0 0);
370
- --color-primary: #your-brand-color;
371
- --color-primary-foreground: oklch(1 0 0);
372
- --color-muted: oklch(0.925 0 0);
373
- --color-muted-foreground: oklch(0.6 0 0);
380
+ .agenttic [data-slot='chat-footer'] {
381
+ --color-background: oklch( 1 0 0 );
382
+ --color-primary: #your-brand-color;
374
383
  }
375
384
  ```
376
385
 
377
- This approach allows granular theming of specific areas without affecting other parts of the application.
378
-
379
- ## Advanced Usage
380
-
381
- ### Request Cancellation UI
382
-
383
- The UI automatically displays a stop button when `isProcessing` is true and an `onStop` callback is provided. The submit button transforms into a stop button during processing:
384
-
385
- ```tsx
386
- const {
387
- abortCurrentRequest,
388
- isProcessing
389
- } = useAgentChat(config);
390
-
391
- <AgentUI
392
- isProcessing={isProcessing}
393
- onStop={abortCurrentRequest}
394
- // When processing, the submit button becomes a stop button
395
- // ... other props
396
- />
397
- ```
398
-
399
- For custom implementations:
400
-
401
- ```tsx
402
- <ChatInput
403
- isProcessing={isProcessing}
404
- onStop={() => {
405
- console.log('User requested to stop');
406
- abortCurrentRequest();
407
- }}
408
- // The button automatically shows stop icon during processing
409
- // ... other props
410
- />
411
- ```
412
-
413
- ### Custom Message Renderer
414
-
415
- Provide a custom markdown renderer:
416
-
417
- ```tsx
418
- import { ReactMarkdown } from 'react-markdown';
419
-
420
- const customRenderer = ({ children }: { children: string }) => (
421
- <ReactMarkdown
422
- remarkPlugins={[remarkGfm]}
423
- components={{
424
- code: ({ children }) => <code className="custom-code">{children}</code>
425
- }}
426
- >
427
- {children}
428
- </ReactMarkdown>
429
- );
430
-
431
- <AgentUI
432
- messages={messages}
433
- messageRenderer={customRenderer}
434
- // ... other props
435
- />
436
- ```
437
-
438
- ### Message Actions
439
-
440
- Messages can include interactive actions:
441
-
442
- ```tsx
443
- const messagesWithActions = messages.map(message => ({
444
- ...message,
445
- actions: message.role === 'agent' ? [
446
- {
447
- id: 'copy',
448
- icon: <CopyIcon />,
449
- label: 'Copy',
450
- onClick: () => navigator.clipboard.writeText(message.content[0].text)
451
- },
452
- {
453
- id: 'feedback',
454
- icon: <ThumbsUpIcon />,
455
- label: 'Good response',
456
- onClick: () => console.log('Positive feedback')
457
- }
458
- ] : []
459
- }));
460
- ```
461
-
462
- ### Controlled Chat State
463
-
464
- For floating variant, control the chat state externally:
465
-
466
- ```tsx
467
- const [chatState, setChatState] = useState<ChatState>('collapsed');
468
-
469
- <AgentUI
470
- variant="floating"
471
- floatingChatState={chatState}
472
- onOpen={() => setChatState('compact')}
473
- onExpand={() => setChatState('expanded')}
474
- onClose={() => setChatState('collapsed')}
475
- // ... other props
476
- />
477
- ```
478
-
479
- ### Custom Empty View
386
+ ## Icons
480
387
 
481
- Provide custom content when there are no messages:
388
+ Pre-built icon components:
482
389
 
483
390
  ```tsx
484
- <AgentUI
485
- messages={[]}
486
- emptyView={
487
- <div className="welcome-message">
488
- <h3>Welcome to AI Assistant</h3>
489
- <p>I'm here to help you with any questions.</p>
490
- </div>
491
- }
492
- // ... other props
493
- />
391
+ import {
392
+ ThumbsUpIcon,
393
+ ThumbsDownIcon,
394
+ CopyIcon,
395
+ StopIcon,
396
+ ArrowUpIcon,
397
+ XIcon,
398
+ BigSkyIcon,
399
+ StylesIcon,
400
+ } from '@automattic/agenttic-ui';
494
401
  ```
495
402
 
496
403
  ## Development
@@ -512,32 +419,19 @@ pnpm type-check
512
419
  pnpm storybook
513
420
  ```
514
421
 
515
- ## Storybook Documentation
516
-
517
- Interactive component documentation is available via Storybook:
518
-
519
- ```bash
520
- pnpm storybook
521
- ```
522
-
523
- Visit `http://localhost:6006` to explore component examples and documentation.
524
-
525
422
  ## Integration with agenttic-client
526
423
 
527
- This UI package is designed to work seamlessly with `@automattic/agenttic-client`:
528
-
529
424
  ```tsx
530
425
  import { useAgentChat } from '@automattic/agenttic-client';
531
426
  import { AgentUI } from '@automattic/agenttic-ui';
532
427
 
533
428
  function App() {
534
- const agentProps = useAgentChat({
535
- agentId: 'big-sky',
536
- // ... configuration
537
- });
429
+ const agentProps = useAgentChat( {
430
+ agentId: 'big-sky',
431
+ } );
538
432
 
539
- return <AgentUI {...agentProps} variant="floating" />;
433
+ return <AgentUI { ...agentProps } variant="floating" />;
540
434
  }
541
435
  ```
542
436
 
543
- The `useAgentChat` hook returns props that match the `AgentUI` interface perfectly, making integration seamless.
437
+ The `useAgentChat` hook returns props that match the `AgentUI` interface.