@devicai/ui 0.5.0 → 0.6.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 +185 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,6 +6,7 @@ React component library for integrating Devic AI assistants into your applicatio
|
|
|
6
6
|
|
|
7
7
|
- **ChatDrawer** - A ready-to-use chat drawer component
|
|
8
8
|
- **AICommandBar** - A spotlight-style command bar for quick AI interactions
|
|
9
|
+
- **AIGenerationButton** - A button for triggering AI generation with modal, tooltip, or direct modes
|
|
9
10
|
- **useDevicChat** - Hook for building custom chat UIs
|
|
10
11
|
- **Model Interface Protocol** - Support for client-side tool execution
|
|
11
12
|
- **Message Feedback** - Built-in thumbs up/down feedback with comments
|
|
@@ -250,6 +251,136 @@ commandBarRef.current?.submit('Hello!');
|
|
|
250
251
|
commandBarRef.current?.reset();
|
|
251
252
|
```
|
|
252
253
|
|
|
254
|
+
### AIGenerationButton
|
|
255
|
+
|
|
256
|
+
A button component for triggering AI generation with three interaction modes: direct, modal, or tooltip.
|
|
257
|
+
|
|
258
|
+
```tsx
|
|
259
|
+
import { AIGenerationButton } from '@devicai/ui';
|
|
260
|
+
|
|
261
|
+
// Modal mode (default) - opens a modal for user input
|
|
262
|
+
<AIGenerationButton
|
|
263
|
+
assistantId="my-assistant"
|
|
264
|
+
options={{
|
|
265
|
+
mode: 'modal',
|
|
266
|
+
modalTitle: 'Generate with AI',
|
|
267
|
+
modalDescription: 'Describe what you want to generate.',
|
|
268
|
+
placeholder: 'E.g., Create a product description...',
|
|
269
|
+
confirmText: 'Generate',
|
|
270
|
+
cancelText: 'Cancel',
|
|
271
|
+
}}
|
|
272
|
+
onResponse={({ message, toolCalls }) => {
|
|
273
|
+
console.log('Generated:', message.content.message);
|
|
274
|
+
}}
|
|
275
|
+
/>
|
|
276
|
+
|
|
277
|
+
// Direct mode - sends predefined prompt immediately
|
|
278
|
+
<AIGenerationButton
|
|
279
|
+
assistantId="my-assistant"
|
|
280
|
+
options={{
|
|
281
|
+
mode: 'direct',
|
|
282
|
+
prompt: 'Generate a summary of this content',
|
|
283
|
+
label: 'Summarize',
|
|
284
|
+
loadingLabel: 'Summarizing...',
|
|
285
|
+
}}
|
|
286
|
+
onResponse={({ message }) => setSummary(message.content.message)}
|
|
287
|
+
/>
|
|
288
|
+
|
|
289
|
+
// Tooltip mode - shows inline input
|
|
290
|
+
<AIGenerationButton
|
|
291
|
+
assistantId="my-assistant"
|
|
292
|
+
options={{
|
|
293
|
+
mode: 'tooltip',
|
|
294
|
+
tooltipPlacement: 'bottom', // 'top' | 'bottom' | 'left' | 'right'
|
|
295
|
+
tooltipWidth: 350,
|
|
296
|
+
}}
|
|
297
|
+
onResponse={handleGeneration}
|
|
298
|
+
/>
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
#### AIGenerationButton Options
|
|
302
|
+
|
|
303
|
+
```tsx
|
|
304
|
+
<AIGenerationButton
|
|
305
|
+
assistantId="my-assistant"
|
|
306
|
+
options={{
|
|
307
|
+
// Mode
|
|
308
|
+
mode: 'modal', // 'direct' | 'modal' | 'tooltip'
|
|
309
|
+
prompt: 'Predefined prompt', // Required for direct mode
|
|
310
|
+
|
|
311
|
+
// Labels
|
|
312
|
+
label: 'Generate with AI',
|
|
313
|
+
loadingLabel: 'Generating...',
|
|
314
|
+
placeholder: 'Describe what you want...',
|
|
315
|
+
modalTitle: 'Generate with AI',
|
|
316
|
+
modalDescription: 'Optional description',
|
|
317
|
+
confirmText: 'Generate',
|
|
318
|
+
cancelText: 'Cancel',
|
|
319
|
+
|
|
320
|
+
// Button styling
|
|
321
|
+
variant: 'primary', // 'primary' | 'secondary' | 'outline' | 'ghost'
|
|
322
|
+
size: 'medium', // 'small' | 'medium' | 'large'
|
|
323
|
+
icon: <CustomIcon />, // Custom icon
|
|
324
|
+
hideIcon: false,
|
|
325
|
+
hideLabel: false, // Icon-only button
|
|
326
|
+
|
|
327
|
+
// Tooltip options
|
|
328
|
+
tooltipPlacement: 'top',
|
|
329
|
+
tooltipWidth: 300,
|
|
330
|
+
|
|
331
|
+
// Tool call display
|
|
332
|
+
toolRenderers: {
|
|
333
|
+
search_docs: (input, output) => (
|
|
334
|
+
<div>Found {output.count} results</div>
|
|
335
|
+
),
|
|
336
|
+
},
|
|
337
|
+
toolIcons: {
|
|
338
|
+
search_docs: <SearchIcon />,
|
|
339
|
+
},
|
|
340
|
+
processingMessage: 'Processing...',
|
|
341
|
+
|
|
342
|
+
// Theming
|
|
343
|
+
color: '#3b82f6',
|
|
344
|
+
backgroundColor: '#ffffff',
|
|
345
|
+
textColor: '#1f2937',
|
|
346
|
+
borderColor: '#e5e7eb',
|
|
347
|
+
borderRadius: 8,
|
|
348
|
+
zIndex: 10000,
|
|
349
|
+
}}
|
|
350
|
+
|
|
351
|
+
// Callbacks
|
|
352
|
+
onResponse={({ message, toolCalls, chatUid }) => {}}
|
|
353
|
+
onBeforeSend={(prompt) => modifiedPrompt} // Modify prompt before sending
|
|
354
|
+
onError={(error) => {}}
|
|
355
|
+
onStart={() => {}}
|
|
356
|
+
onOpen={() => {}}
|
|
357
|
+
onClose={() => {}}
|
|
358
|
+
|
|
359
|
+
// Other props
|
|
360
|
+
modelInterfaceTools={[...]}
|
|
361
|
+
tenantId="tenant-123"
|
|
362
|
+
tenantMetadata={{ userId: '456' }}
|
|
363
|
+
disabled={false}
|
|
364
|
+
/>
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
#### AIGenerationButton Handle (ref methods)
|
|
368
|
+
|
|
369
|
+
```tsx
|
|
370
|
+
const buttonRef = useRef<AIGenerationButtonHandle>(null);
|
|
371
|
+
|
|
372
|
+
// Trigger generation programmatically
|
|
373
|
+
const result = await buttonRef.current?.generate('Custom prompt');
|
|
374
|
+
|
|
375
|
+
// Open/close modal or tooltip
|
|
376
|
+
buttonRef.current?.open();
|
|
377
|
+
buttonRef.current?.close();
|
|
378
|
+
buttonRef.current?.reset();
|
|
379
|
+
|
|
380
|
+
// Check processing state
|
|
381
|
+
if (buttonRef.current?.isProcessing) { ... }
|
|
382
|
+
```
|
|
383
|
+
|
|
253
384
|
## Hooks
|
|
254
385
|
|
|
255
386
|
### useDevicChat
|
|
@@ -320,6 +451,38 @@ const {
|
|
|
320
451
|
});
|
|
321
452
|
```
|
|
322
453
|
|
|
454
|
+
### useAIGenerationButton
|
|
455
|
+
|
|
456
|
+
Hook for building custom generation button UIs.
|
|
457
|
+
|
|
458
|
+
```tsx
|
|
459
|
+
import { useAIGenerationButton } from '@devicai/ui';
|
|
460
|
+
|
|
461
|
+
const {
|
|
462
|
+
isOpen, // boolean - modal/tooltip open state
|
|
463
|
+
isProcessing, // boolean
|
|
464
|
+
inputValue, // string
|
|
465
|
+
setInputValue, // (value: string) => void
|
|
466
|
+
error, // Error | null
|
|
467
|
+
result, // GenerationResult | null
|
|
468
|
+
toolCalls, // ToolCallSummary[]
|
|
469
|
+
currentToolSummary, // string | null
|
|
470
|
+
inputRef, // RefObject<HTMLTextAreaElement>
|
|
471
|
+
open, // () => void
|
|
472
|
+
close, // () => void
|
|
473
|
+
generate, // (prompt?: string) => Promise<GenerationResult | null>
|
|
474
|
+
reset, // () => void
|
|
475
|
+
handleKeyDown, // (e: KeyboardEvent) => void
|
|
476
|
+
} = useAIGenerationButton({
|
|
477
|
+
assistantId: 'my-assistant',
|
|
478
|
+
options: { mode: 'modal' },
|
|
479
|
+
onResponse: (result) => {},
|
|
480
|
+
onBeforeSend: (prompt) => prompt,
|
|
481
|
+
onError: (error) => {},
|
|
482
|
+
onStart: () => {},
|
|
483
|
+
});
|
|
484
|
+
```
|
|
485
|
+
|
|
323
486
|
### useModelInterface
|
|
324
487
|
|
|
325
488
|
Hook for implementing the Model Interface Protocol.
|
|
@@ -480,14 +643,35 @@ All types are exported:
|
|
|
480
643
|
|
|
481
644
|
```tsx
|
|
482
645
|
import type {
|
|
646
|
+
// Chat types
|
|
483
647
|
ChatMessage,
|
|
484
648
|
ChatFile,
|
|
649
|
+
ChatDrawerOptions,
|
|
650
|
+
ChatDrawerHandle,
|
|
651
|
+
|
|
652
|
+
// AICommandBar types
|
|
653
|
+
AICommandBarOptions,
|
|
654
|
+
AICommandBarHandle,
|
|
655
|
+
AICommandBarCommand,
|
|
656
|
+
CommandBarResult,
|
|
657
|
+
ToolCallSummary,
|
|
658
|
+
|
|
659
|
+
// AIGenerationButton types
|
|
660
|
+
AIGenerationButtonOptions,
|
|
661
|
+
AIGenerationButtonHandle,
|
|
662
|
+
AIGenerationButtonMode,
|
|
663
|
+
GenerationResult,
|
|
664
|
+
|
|
665
|
+
// Tool types
|
|
485
666
|
ModelInterfaceTool,
|
|
486
667
|
ModelInterfaceToolSchema,
|
|
487
668
|
ToolCall,
|
|
488
669
|
ToolCallResponse,
|
|
670
|
+
|
|
671
|
+
// API types
|
|
489
672
|
RealtimeChatHistory,
|
|
490
|
-
|
|
673
|
+
|
|
674
|
+
// Hook types
|
|
491
675
|
UseDevicChatOptions,
|
|
492
676
|
} from '@devicai/ui';
|
|
493
677
|
```
|