vanilla-agent 1.21.0 → 1.22.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 CHANGED
@@ -218,6 +218,93 @@ window.addEventListener("vanilla-agent:clear-chat", (event) => {
218
218
 
219
219
  **Note:** The widget automatically clears the `"vanilla-agent-chat-history"` localStorage key by default when chat is cleared. If you set `clearChatHistoryStorageKey` in the config, it will also clear that additional key. You can still listen to this event for additional custom behavior.
220
220
 
221
+ ### Message Actions (Copy, Upvote, Downvote)
222
+
223
+ The widget includes built-in action buttons for assistant messages that allow users to copy message content and provide feedback through upvote/downvote buttons.
224
+
225
+ #### Configuration
226
+
227
+ ```ts
228
+ const controller = initAgentWidget({
229
+ target: '#app',
230
+ config: {
231
+ apiUrl: '/api/chat/dispatch',
232
+
233
+ // Message actions configuration
234
+ messageActions: {
235
+ enabled: true, // Enable/disable all action buttons (default: true)
236
+ showCopy: true, // Show copy button (default: true)
237
+ showUpvote: true, // Show upvote button (default: false - requires backend)
238
+ showDownvote: true, // Show downvote button (default: false - requires backend)
239
+ visibility: 'hover', // 'hover' or 'always' (default: 'hover')
240
+ align: 'right', // 'left', 'center', or 'right' (default: 'right')
241
+ layout: 'pill-inside', // 'pill-inside' (compact floating) or 'row-inside' (full-width bar)
242
+
243
+ // Optional callbacks (called in addition to events)
244
+ onCopy: (message) => {
245
+ console.log('Copied:', message.id);
246
+ },
247
+ onFeedback: (feedback) => {
248
+ console.log('Feedback:', feedback.type, feedback.messageId);
249
+ // Send to your analytics/backend
250
+ fetch('/api/feedback', {
251
+ method: 'POST',
252
+ headers: { 'Content-Type': 'application/json' },
253
+ body: JSON.stringify(feedback)
254
+ });
255
+ }
256
+ }
257
+ }
258
+ });
259
+ ```
260
+
261
+ #### Feedback Events
262
+
263
+ Listen to feedback events via the controller:
264
+
265
+ ```ts
266
+ // Copy event - fired when user copies a message
267
+ controller.on('message:copy', (message) => {
268
+ console.log('Message copied:', message.id, message.content);
269
+ });
270
+
271
+ // Feedback event - fired when user upvotes or downvotes
272
+ controller.on('message:feedback', (feedback) => {
273
+ console.log('Feedback received:', {
274
+ type: feedback.type, // 'upvote' or 'downvote'
275
+ messageId: feedback.messageId,
276
+ message: feedback.message // Full message object
277
+ });
278
+ });
279
+ ```
280
+
281
+ #### Feedback Types
282
+
283
+ ```typescript
284
+ type AgentWidgetMessageFeedback = {
285
+ type: 'upvote' | 'downvote';
286
+ messageId: string;
287
+ message: AgentWidgetMessage;
288
+ };
289
+
290
+ type AgentWidgetMessageActionsConfig = {
291
+ enabled?: boolean;
292
+ showCopy?: boolean;
293
+ showUpvote?: boolean;
294
+ showDownvote?: boolean;
295
+ visibility?: 'always' | 'hover';
296
+ onFeedback?: (feedback: AgentWidgetMessageFeedback) => void;
297
+ onCopy?: (message: AgentWidgetMessage) => void;
298
+ };
299
+ ```
300
+
301
+ #### Visual Behavior
302
+
303
+ - **Hover mode** (`visibility: 'hover'`): Action buttons appear when hovering over assistant messages
304
+ - **Always mode** (`visibility: 'always'`): Action buttons are always visible
305
+ - **Copy button**: Shows a checkmark briefly after successful copy
306
+ - **Vote buttons**: Toggle active state and are mutually exclusive (upvoting clears downvote and vice versa)
307
+
221
308
  ### Travrse adapter
222
309
 
223
310
  This package ships with a Travrse adapter by default. The proxy handles all flow configuration, keeping the client lightweight and flexible.