@devicai/ui 0.1.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 +363 -0
- package/dist/cjs/api/client.js +118 -0
- package/dist/cjs/api/client.js.map +1 -0
- package/dist/cjs/components/ChatDrawer/ChatDrawer.js +122 -0
- package/dist/cjs/components/ChatDrawer/ChatDrawer.js.map +1 -0
- package/dist/cjs/components/ChatDrawer/ChatInput.js +128 -0
- package/dist/cjs/components/ChatDrawer/ChatInput.js.map +1 -0
- package/dist/cjs/components/ChatDrawer/ChatMessages.js +56 -0
- package/dist/cjs/components/ChatDrawer/ChatMessages.js.map +1 -0
- package/dist/cjs/components/ChatDrawer/ToolTimeline.js +26 -0
- package/dist/cjs/components/ChatDrawer/ToolTimeline.js.map +1 -0
- package/dist/cjs/hooks/useDevicChat.js +258 -0
- package/dist/cjs/hooks/useDevicChat.js.map +1 -0
- package/dist/cjs/hooks/useModelInterface.js +130 -0
- package/dist/cjs/hooks/useModelInterface.js.map +1 -0
- package/dist/cjs/hooks/usePolling.js +109 -0
- package/dist/cjs/hooks/usePolling.js.map +1 -0
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/provider/DevicContext.js +32 -0
- package/dist/cjs/provider/DevicContext.js.map +1 -0
- package/dist/cjs/provider/DevicProvider.js +43 -0
- package/dist/cjs/provider/DevicProvider.js.map +1 -0
- package/dist/cjs/styles.css +1 -0
- package/dist/cjs/utils/index.js +117 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/esm/api/client.d.ts +56 -0
- package/dist/esm/api/client.js +115 -0
- package/dist/esm/api/client.js.map +1 -0
- package/dist/esm/api/types.d.ts +184 -0
- package/dist/esm/components/ChatDrawer/ChatDrawer.d.ts +27 -0
- package/dist/esm/components/ChatDrawer/ChatDrawer.js +120 -0
- package/dist/esm/components/ChatDrawer/ChatDrawer.js.map +1 -0
- package/dist/esm/components/ChatDrawer/ChatDrawer.types.d.ts +197 -0
- package/dist/esm/components/ChatDrawer/ChatInput.d.ts +5 -0
- package/dist/esm/components/ChatDrawer/ChatInput.js +126 -0
- package/dist/esm/components/ChatDrawer/ChatInput.js.map +1 -0
- package/dist/esm/components/ChatDrawer/ChatMessages.d.ts +5 -0
- package/dist/esm/components/ChatDrawer/ChatMessages.js +54 -0
- package/dist/esm/components/ChatDrawer/ChatMessages.js.map +1 -0
- package/dist/esm/components/ChatDrawer/ToolTimeline.d.ts +5 -0
- package/dist/esm/components/ChatDrawer/ToolTimeline.js +24 -0
- package/dist/esm/components/ChatDrawer/ToolTimeline.js.map +1 -0
- package/dist/esm/components/ChatDrawer/index.d.ts +5 -0
- package/dist/esm/hooks/index.d.ts +6 -0
- package/dist/esm/hooks/useDevicChat.d.ts +120 -0
- package/dist/esm/hooks/useDevicChat.js +256 -0
- package/dist/esm/hooks/useDevicChat.js.map +1 -0
- package/dist/esm/hooks/useModelInterface.d.ts +68 -0
- package/dist/esm/hooks/useModelInterface.js +128 -0
- package/dist/esm/hooks/useModelInterface.js.map +1 -0
- package/dist/esm/hooks/usePolling.d.ts +64 -0
- package/dist/esm/hooks/usePolling.js +107 -0
- package/dist/esm/hooks/usePolling.js.map +1 -0
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.js +12 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/provider/DevicContext.d.ts +15 -0
- package/dist/esm/provider/DevicContext.js +28 -0
- package/dist/esm/provider/DevicContext.js.map +1 -0
- package/dist/esm/provider/DevicProvider.d.ts +17 -0
- package/dist/esm/provider/DevicProvider.js +41 -0
- package/dist/esm/provider/DevicProvider.js.map +1 -0
- package/dist/esm/provider/index.d.ts +3 -0
- package/dist/esm/provider/types.d.ts +58 -0
- package/dist/esm/styles.css +1 -0
- package/dist/esm/utils/index.d.ts +32 -0
- package/dist/esm/utils/index.js +109 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import { useState, useRef, useCallback } from 'react';
|
|
3
|
+
|
|
4
|
+
const FILE_TYPE_ACCEPT = {
|
|
5
|
+
images: ['image/jpeg', 'image/png', 'image/gif', 'image/webp'],
|
|
6
|
+
documents: [
|
|
7
|
+
'application/pdf',
|
|
8
|
+
'application/msword',
|
|
9
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
10
|
+
'text/plain',
|
|
11
|
+
'text/csv',
|
|
12
|
+
],
|
|
13
|
+
audio: ['audio/mpeg', 'audio/wav', 'audio/ogg'],
|
|
14
|
+
video: ['video/mp4', 'video/webm', 'video/ogg'],
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Chat input component with file upload support
|
|
18
|
+
*/
|
|
19
|
+
function ChatInput({ onSend, disabled = false, placeholder = 'Type a message...', enableFileUploads = false, allowedFileTypes = { images: true, documents: true }, maxFileSize = 10 * 1024 * 1024, // 10MB
|
|
20
|
+
}) {
|
|
21
|
+
const [message, setMessage] = useState('');
|
|
22
|
+
const [files, setFiles] = useState([]);
|
|
23
|
+
const textareaRef = useRef(null);
|
|
24
|
+
const fileInputRef = useRef(null);
|
|
25
|
+
// Calculate accepted file types
|
|
26
|
+
const acceptedTypes = Object.entries(allowedFileTypes)
|
|
27
|
+
.filter(([, enabled]) => enabled)
|
|
28
|
+
.flatMap(([type]) => FILE_TYPE_ACCEPT[type] || [])
|
|
29
|
+
.join(',');
|
|
30
|
+
// Auto-resize textarea
|
|
31
|
+
const handleInput = useCallback(() => {
|
|
32
|
+
const textarea = textareaRef.current;
|
|
33
|
+
if (textarea) {
|
|
34
|
+
textarea.style.height = 'auto';
|
|
35
|
+
textarea.style.height = `${Math.min(textarea.scrollHeight, 120)}px`;
|
|
36
|
+
}
|
|
37
|
+
}, []);
|
|
38
|
+
// Handle send
|
|
39
|
+
const handleSend = useCallback(() => {
|
|
40
|
+
const trimmedMessage = message.trim();
|
|
41
|
+
if (!trimmedMessage && files.length === 0)
|
|
42
|
+
return;
|
|
43
|
+
// Convert File objects to ChatFile format
|
|
44
|
+
const chatFiles = files.map((file) => ({
|
|
45
|
+
name: file.name,
|
|
46
|
+
fileType: getFileType(file.type),
|
|
47
|
+
}));
|
|
48
|
+
onSend(trimmedMessage, chatFiles.length > 0 ? chatFiles : undefined);
|
|
49
|
+
setMessage('');
|
|
50
|
+
setFiles([]);
|
|
51
|
+
// Reset textarea height
|
|
52
|
+
if (textareaRef.current) {
|
|
53
|
+
textareaRef.current.style.height = 'auto';
|
|
54
|
+
}
|
|
55
|
+
}, [message, files, onSend]);
|
|
56
|
+
// Handle key press
|
|
57
|
+
const handleKeyDown = useCallback((e) => {
|
|
58
|
+
if (e.key === 'Enter' && !e.shiftKey) {
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
handleSend();
|
|
61
|
+
}
|
|
62
|
+
}, [handleSend]);
|
|
63
|
+
// Handle file selection
|
|
64
|
+
const handleFileSelect = useCallback((e) => {
|
|
65
|
+
const selectedFiles = Array.from(e.target.files || []);
|
|
66
|
+
// Filter valid files
|
|
67
|
+
const validFiles = selectedFiles.filter((file) => {
|
|
68
|
+
if (file.size > maxFileSize) {
|
|
69
|
+
console.warn(`File ${file.name} exceeds maximum size`);
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
});
|
|
74
|
+
setFiles((prev) => [...prev, ...validFiles]);
|
|
75
|
+
// Reset input
|
|
76
|
+
if (fileInputRef.current) {
|
|
77
|
+
fileInputRef.current.value = '';
|
|
78
|
+
}
|
|
79
|
+
}, [maxFileSize]);
|
|
80
|
+
// Remove file
|
|
81
|
+
const removeFile = useCallback((index) => {
|
|
82
|
+
setFiles((prev) => prev.filter((_, i) => i !== index));
|
|
83
|
+
}, []);
|
|
84
|
+
return (jsxs("div", { className: "devic-input-area", children: [files.length > 0 && (jsx("div", { className: "devic-file-preview", children: files.map((file, idx) => (jsxs("div", { className: "devic-file-preview-item", children: [jsx(FileIcon, {}), jsx("span", { children: file.name }), jsx("button", { className: "devic-file-remove", onClick: () => removeFile(idx), type: "button", children: "\u00D7" })] }, idx))) })), jsxs("div", { className: "devic-input-wrapper", children: [enableFileUploads && (jsxs(Fragment, { children: [jsx("input", { ref: fileInputRef, type: "file", accept: acceptedTypes, multiple: true, onChange: handleFileSelect, style: { display: 'none' } }), jsx("button", { className: "devic-input-btn", onClick: () => fileInputRef.current?.click(), disabled: disabled, type: "button", title: "Attach file", children: jsx(AttachIcon, {}) })] })), jsx("textarea", { ref: textareaRef, className: "devic-input", value: message, onChange: (e) => {
|
|
85
|
+
setMessage(e.target.value);
|
|
86
|
+
handleInput();
|
|
87
|
+
}, onKeyDown: handleKeyDown, placeholder: placeholder, disabled: disabled, rows: 1 }), jsx("button", { className: "devic-input-btn devic-send-btn", onClick: handleSend, disabled: disabled || (!message.trim() && files.length === 0), type: "button", title: "Send message", children: jsx(SendIcon, {}) })] })] }));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get file type category from MIME type
|
|
91
|
+
*/
|
|
92
|
+
function getFileType(mimeType) {
|
|
93
|
+
if (mimeType.startsWith('image/'))
|
|
94
|
+
return 'image';
|
|
95
|
+
if (mimeType.startsWith('audio/'))
|
|
96
|
+
return 'audio';
|
|
97
|
+
if (mimeType.startsWith('video/'))
|
|
98
|
+
return 'video';
|
|
99
|
+
if (mimeType.startsWith('application/pdf') ||
|
|
100
|
+
mimeType.startsWith('application/msword') ||
|
|
101
|
+
mimeType.startsWith('text/')) {
|
|
102
|
+
return 'document';
|
|
103
|
+
}
|
|
104
|
+
return 'other';
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Attach icon
|
|
108
|
+
*/
|
|
109
|
+
function AttachIcon() {
|
|
110
|
+
return (jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: jsx("path", { d: "M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48" }) }));
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Send icon
|
|
114
|
+
*/
|
|
115
|
+
function SendIcon() {
|
|
116
|
+
return (jsx("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "currentColor", children: jsx("path", { d: "M2.01 21L23 12 2.01 3 2 10l15 2-15 2z" }) }));
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* File icon
|
|
120
|
+
*/
|
|
121
|
+
function FileIcon() {
|
|
122
|
+
return (jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [jsx("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }), jsx("polyline", { points: "14,2 14,8 20,8" })] }));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export { ChatInput };
|
|
126
|
+
//# sourceMappingURL=ChatInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatInput.js","sources":["../../../../src/components/ChatDrawer/ChatInput.tsx"],"sourcesContent":["import React, { useState, useRef, useCallback } from 'react';\nimport type { ChatInputProps } from './ChatDrawer.types';\nimport type { ChatFile } from '../../api/types';\n\nconst FILE_TYPE_ACCEPT: Record<string, string[]> = {\n images: ['image/jpeg', 'image/png', 'image/gif', 'image/webp'],\n documents: [\n 'application/pdf',\n 'application/msword',\n 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n 'text/plain',\n 'text/csv',\n ],\n audio: ['audio/mpeg', 'audio/wav', 'audio/ogg'],\n video: ['video/mp4', 'video/webm', 'video/ogg'],\n};\n\n/**\n * Chat input component with file upload support\n */\nexport function ChatInput({\n onSend,\n disabled = false,\n placeholder = 'Type a message...',\n enableFileUploads = false,\n allowedFileTypes = { images: true, documents: true },\n maxFileSize = 10 * 1024 * 1024, // 10MB\n}: ChatInputProps): JSX.Element {\n const [message, setMessage] = useState('');\n const [files, setFiles] = useState<File[]>([]);\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const fileInputRef = useRef<HTMLInputElement>(null);\n\n // Calculate accepted file types\n const acceptedTypes = Object.entries(allowedFileTypes)\n .filter(([, enabled]) => enabled)\n .flatMap(([type]) => FILE_TYPE_ACCEPT[type] || [])\n .join(',');\n\n // Auto-resize textarea\n const handleInput = useCallback(() => {\n const textarea = textareaRef.current;\n if (textarea) {\n textarea.style.height = 'auto';\n textarea.style.height = `${Math.min(textarea.scrollHeight, 120)}px`;\n }\n }, []);\n\n // Handle send\n const handleSend = useCallback(() => {\n const trimmedMessage = message.trim();\n if (!trimmedMessage && files.length === 0) return;\n\n // Convert File objects to ChatFile format\n const chatFiles: ChatFile[] = files.map((file) => ({\n name: file.name,\n fileType: getFileType(file.type),\n }));\n\n onSend(trimmedMessage, chatFiles.length > 0 ? chatFiles : undefined);\n setMessage('');\n setFiles([]);\n\n // Reset textarea height\n if (textareaRef.current) {\n textareaRef.current.style.height = 'auto';\n }\n }, [message, files, onSend]);\n\n // Handle key press\n const handleKeyDown = useCallback(\n (e: React.KeyboardEvent) => {\n if (e.key === 'Enter' && !e.shiftKey) {\n e.preventDefault();\n handleSend();\n }\n },\n [handleSend]\n );\n\n // Handle file selection\n const handleFileSelect = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const selectedFiles = Array.from(e.target.files || []);\n\n // Filter valid files\n const validFiles = selectedFiles.filter((file) => {\n if (file.size > maxFileSize) {\n console.warn(`File ${file.name} exceeds maximum size`);\n return false;\n }\n return true;\n });\n\n setFiles((prev) => [...prev, ...validFiles]);\n\n // Reset input\n if (fileInputRef.current) {\n fileInputRef.current.value = '';\n }\n },\n [maxFileSize]\n );\n\n // Remove file\n const removeFile = useCallback((index: number) => {\n setFiles((prev) => prev.filter((_, i) => i !== index));\n }, []);\n\n return (\n <div className=\"devic-input-area\">\n {files.length > 0 && (\n <div className=\"devic-file-preview\">\n {files.map((file, idx) => (\n <div key={idx} className=\"devic-file-preview-item\">\n <FileIcon />\n <span>{file.name}</span>\n <button\n className=\"devic-file-remove\"\n onClick={() => removeFile(idx)}\n type=\"button\"\n >\n ×\n </button>\n </div>\n ))}\n </div>\n )}\n\n <div className=\"devic-input-wrapper\">\n {enableFileUploads && (\n <>\n <input\n ref={fileInputRef}\n type=\"file\"\n accept={acceptedTypes}\n multiple\n onChange={handleFileSelect}\n style={{ display: 'none' }}\n />\n <button\n className=\"devic-input-btn\"\n onClick={() => fileInputRef.current?.click()}\n disabled={disabled}\n type=\"button\"\n title=\"Attach file\"\n >\n <AttachIcon />\n </button>\n </>\n )}\n\n <textarea\n ref={textareaRef}\n className=\"devic-input\"\n value={message}\n onChange={(e) => {\n setMessage(e.target.value);\n handleInput();\n }}\n onKeyDown={handleKeyDown}\n placeholder={placeholder}\n disabled={disabled}\n rows={1}\n />\n\n <button\n className=\"devic-input-btn devic-send-btn\"\n onClick={handleSend}\n disabled={disabled || (!message.trim() && files.length === 0)}\n type=\"button\"\n title=\"Send message\"\n >\n <SendIcon />\n </button>\n </div>\n </div>\n );\n}\n\n/**\n * Get file type category from MIME type\n */\nfunction getFileType(\n mimeType: string\n): 'image' | 'document' | 'audio' | 'video' | 'other' {\n if (mimeType.startsWith('image/')) return 'image';\n if (mimeType.startsWith('audio/')) return 'audio';\n if (mimeType.startsWith('video/')) return 'video';\n if (\n mimeType.startsWith('application/pdf') ||\n mimeType.startsWith('application/msword') ||\n mimeType.startsWith('text/')\n ) {\n return 'document';\n }\n return 'other';\n}\n\n/**\n * Attach icon\n */\nfunction AttachIcon(): JSX.Element {\n return (\n <svg\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48\" />\n </svg>\n );\n}\n\n/**\n * Send icon\n */\nfunction SendIcon(): JSX.Element {\n return (\n <svg\n width=\"18\"\n height=\"18\"\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n >\n <path d=\"M2.01 21L23 12 2.01 3 2 10l15 2-15 2z\" />\n </svg>\n );\n}\n\n/**\n * File icon\n */\nfunction FileIcon(): JSX.Element {\n return (\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z\" />\n <polyline points=\"14,2 14,8 20,8\" />\n </svg>\n );\n}\n"],"names":["_jsxs","_jsx","_Fragment"],"mappings":";;;AAIA,MAAM,gBAAgB,GAA6B;IACjD,MAAM,EAAE,CAAC,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,CAAC;AAC9D,IAAA,SAAS,EAAE;QACT,iBAAiB;QACjB,oBAAoB;QACpB,yEAAyE;QACzE,YAAY;QACZ,UAAU;AACX,KAAA;AACD,IAAA,KAAK,EAAE,CAAC,YAAY,EAAE,WAAW,EAAE,WAAW,CAAC;AAC/C,IAAA,KAAK,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,WAAW,CAAC;CAChD;AAED;;AAEG;SACa,SAAS,CAAC,EACxB,MAAM,EACN,QAAQ,GAAG,KAAK,EAChB,WAAW,GAAG,mBAAmB,EACjC,iBAAiB,GAAG,KAAK,EACzB,gBAAgB,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,E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,EAAA,EAAU,MAAM,EAAC,gBAAgB,EAAA,CAAG,CAAA,EAAA,CAChC;AAEV;;;;"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useRef, useEffect } from 'react';
|
|
3
|
+
import { ToolTimeline } from './ToolTimeline.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Format timestamp to readable time
|
|
7
|
+
*/
|
|
8
|
+
function formatTime(timestamp) {
|
|
9
|
+
return new Date(timestamp).toLocaleTimeString([], {
|
|
10
|
+
hour: '2-digit',
|
|
11
|
+
minute: '2-digit',
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Messages list component
|
|
16
|
+
*/
|
|
17
|
+
function ChatMessages({ messages, isLoading, welcomeMessage, suggestedMessages, onSuggestedClick, showToolTimeline = true, }) {
|
|
18
|
+
const containerRef = useRef(null);
|
|
19
|
+
const lastMessageCountRef = useRef(messages.length);
|
|
20
|
+
// Auto-scroll to bottom when new messages arrive
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (messages.length > lastMessageCountRef.current && containerRef.current) {
|
|
23
|
+
containerRef.current.scrollTop = containerRef.current.scrollHeight;
|
|
24
|
+
}
|
|
25
|
+
lastMessageCountRef.current = messages.length;
|
|
26
|
+
}, [messages.length]);
|
|
27
|
+
// Extract tool calls for timeline
|
|
28
|
+
const toolCalls = showToolTimeline
|
|
29
|
+
? messages
|
|
30
|
+
.filter((m) => m.tool_calls?.length)
|
|
31
|
+
.flatMap((m) => m.tool_calls.map((tc) => ({
|
|
32
|
+
id: tc.id,
|
|
33
|
+
name: tc.function.name,
|
|
34
|
+
status: 'completed',
|
|
35
|
+
timestamp: m.timestamp,
|
|
36
|
+
})))
|
|
37
|
+
: [];
|
|
38
|
+
return (jsxs("div", { className: "devic-messages-container", ref: containerRef, children: [messages.length === 0 && (welcomeMessage || suggestedMessages?.length) && (jsxs("div", { className: "devic-welcome", children: [welcomeMessage && (jsx("p", { className: "devic-welcome-text", children: welcomeMessage })), suggestedMessages && suggestedMessages.length > 0 && (jsx("div", { className: "devic-suggested-messages", children: suggestedMessages.map((msg, idx) => (jsx("button", { className: "devic-suggested-btn", onClick: () => onSuggestedClick?.(msg), children: msg }, idx))) }))] })), messages.map((message) => {
|
|
39
|
+
// Skip tool messages in main display (shown in timeline)
|
|
40
|
+
if (message.role === 'tool' && showToolTimeline) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return (jsxs("div", { className: "devic-message", "data-role": message.role, children: [jsxs("div", { className: "devic-message-bubble", children: [message.content.message, message.content.files && message.content.files.length > 0 && (jsx("div", { className: "devic-message-files", children: message.content.files.map((file, idx) => (jsxs("div", { className: "devic-message-file", children: [jsx(FileIcon, {}), jsx("span", { children: file.name })] }, idx))) }))] }), jsx("span", { className: "devic-message-time", children: formatTime(message.timestamp) })] }, message.uid));
|
|
44
|
+
}), showToolTimeline && toolCalls.length > 0 && (jsx(ToolTimeline, { toolCalls: toolCalls })), isLoading && (jsxs("div", { className: "devic-loading", children: [jsx("span", { className: "devic-loading-dot" }), jsx("span", { className: "devic-loading-dot" }), jsx("span", { className: "devic-loading-dot" })] }))] }));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Simple file icon
|
|
48
|
+
*/
|
|
49
|
+
function FileIcon() {
|
|
50
|
+
return (jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [jsx("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }), jsx("polyline", { points: "14,2 14,8 20,8" })] }));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { ChatMessages };
|
|
54
|
+
//# sourceMappingURL=ChatMessages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatMessages.js","sources":["../../../../src/components/ChatDrawer/ChatMessages.tsx"],"sourcesContent":["import React, { useEffect, useRef } from 'react';\nimport type { ChatMessagesProps } from './ChatDrawer.types';\nimport { ToolTimeline } from './ToolTimeline';\n\n/**\n * Format timestamp to readable time\n */\nfunction formatTime(timestamp: number): string {\n return new Date(timestamp).toLocaleTimeString([], {\n hour: '2-digit',\n minute: '2-digit',\n });\n}\n\n/**\n * Messages list component\n */\nexport function ChatMessages({\n messages,\n isLoading,\n welcomeMessage,\n suggestedMessages,\n onSuggestedClick,\n showToolTimeline = true,\n}: ChatMessagesProps): JSX.Element {\n const containerRef = useRef<HTMLDivElement>(null);\n const lastMessageCountRef = useRef(messages.length);\n\n // Auto-scroll to bottom when new messages arrive\n useEffect(() => {\n if (messages.length > lastMessageCountRef.current && containerRef.current) {\n containerRef.current.scrollTop = containerRef.current.scrollHeight;\n }\n lastMessageCountRef.current = messages.length;\n }, [messages.length]);\n\n // Extract tool calls for timeline\n const toolCalls = showToolTimeline\n ? messages\n .filter((m) => m.tool_calls?.length)\n .flatMap((m) =>\n m.tool_calls!.map((tc) => ({\n id: tc.id,\n name: tc.function.name,\n status: 'completed' as const,\n timestamp: m.timestamp,\n }))\n )\n : [];\n\n return (\n <div className=\"devic-messages-container\" ref={containerRef}>\n {messages.length === 0 && (welcomeMessage || suggestedMessages?.length) && (\n <div className=\"devic-welcome\">\n {welcomeMessage && (\n <p className=\"devic-welcome-text\">{welcomeMessage}</p>\n )}\n {suggestedMessages && suggestedMessages.length > 0 && (\n <div className=\"devic-suggested-messages\">\n {suggestedMessages.map((msg, idx) => (\n <button\n key={idx}\n className=\"devic-suggested-btn\"\n onClick={() => onSuggestedClick?.(msg)}\n >\n {msg}\n </button>\n ))}\n </div>\n )}\n </div>\n )}\n\n {messages.map((message) => {\n // Skip tool messages in main display (shown in timeline)\n if (message.role === 'tool' && showToolTimeline) {\n return null;\n }\n\n return (\n <div\n key={message.uid}\n className=\"devic-message\"\n data-role={message.role}\n >\n <div className=\"devic-message-bubble\">\n {message.content.message}\n {message.content.files && message.content.files.length > 0 && (\n <div className=\"devic-message-files\">\n {message.content.files.map((file, idx) => (\n <div key={idx} className=\"devic-message-file\">\n <FileIcon />\n <span>{file.name}</span>\n </div>\n ))}\n </div>\n )}\n </div>\n <span className=\"devic-message-time\">\n {formatTime(message.timestamp)}\n </span>\n </div>\n );\n })}\n\n {showToolTimeline && toolCalls.length > 0 && (\n <ToolTimeline toolCalls={toolCalls} />\n )}\n\n {isLoading && (\n <div className=\"devic-loading\">\n <span className=\"devic-loading-dot\"></span>\n <span className=\"devic-loading-dot\"></span>\n <span className=\"devic-loading-dot\"></span>\n </div>\n )}\n </div>\n );\n}\n\n/**\n * Simple file icon\n */\nfunction FileIcon(): JSX.Element {\n return (\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z\" />\n <polyline points=\"14,2 14,8 20,8\" />\n </svg>\n );\n}\n"],"names":["_jsxs","_jsx"],"mappings":";;;;AAIA;;AAEG;AACH,SAAS,UAAU,CAAC,SAAiB,EAAA;IACnC,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,EAAE,EAAE;AAChD,QAAA,IAAI,EAAE,SAAS;AACf,QAAA,MAAM,EAAE,SAAS;AAClB,KAAA,CAAC;AACJ;AAEA;;AAEG;SACa,YAAY,CAAC,EAC3B,QAAQ,EACR,SAAS,EACT,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,GAAG,IAAI,GACL,EAAA;AAClB,IAAA,MAAM,YAAY,GAAG,MAAM,CAAiB,IAAI,CAAC;IACjD,MAAM,mBAAmB,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,C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AAE,SAAS,GAAI,CACvC,EAEA,SAAS,KACRD,IAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,eAAe,aAC5BC,GAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,mBAAmB,EAAA,CAAQ,EAC3CA,GAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,mBAAmB,EAAA,CAAQ,EAC3CA,GAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,mBAAmB,GAAQ,CAAA,EAAA,CACvC,CACP,CAAA,EAAA,CACG;AAEV;AAEA;;AAEG;AACH,SAAS,QAAQ,GAAA;IACf,QACED,cACE,KAAK,EAAC,IAAI,EACV,MAAM,EAAC,IAAI,EACX,OAAO,EAAC,WAAW,EACnB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,GAAG,EACf,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,EAAA,QAAA,EAAA,CAEtBC,GAAA,CAAA,MAAA,EAAA,EAAM,CAAC,EAAC,4DAA4D,EAAA,CAAG,EACvEA,GAAA,CAAA,UAAA,EAAA,EAAU,MAAM,EAAC,gBAAgB,EAAA,CAAG,CAAA,EAAA,CAChC;AAEV;;;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Tool execution timeline component
|
|
5
|
+
*/
|
|
6
|
+
function ToolTimeline({ toolCalls }) {
|
|
7
|
+
if (toolCalls.length === 0) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
return (jsx("div", { className: "devic-tool-timeline", children: toolCalls.map((tool) => (jsxs("div", { className: "devic-tool-item", children: [jsx("span", { className: "devic-tool-status", "data-status": tool.status }), jsx("span", { className: "devic-tool-name", children: formatToolName(tool.name) }), tool.status === 'error' && tool.error && (jsx("span", { className: "devic-tool-error", children: tool.error }))] }, tool.id))) }));
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Format tool name for display
|
|
14
|
+
*/
|
|
15
|
+
function formatToolName(name) {
|
|
16
|
+
// Convert snake_case or camelCase to Title Case with spaces
|
|
17
|
+
return name
|
|
18
|
+
.replace(/_/g, ' ')
|
|
19
|
+
.replace(/([a-z])([A-Z])/g, '$1 $2')
|
|
20
|
+
.replace(/\b\w/g, (char) => char.toUpperCase());
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { ToolTimeline };
|
|
24
|
+
//# sourceMappingURL=ToolTimeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolTimeline.js","sources":["../../../../src/components/ChatDrawer/ToolTimeline.tsx"],"sourcesContent":["import React from 'react';\nimport type { ToolTimelineProps } from './ChatDrawer.types';\n\n/**\n * Tool execution timeline component\n */\nexport function ToolTimeline({ toolCalls }: ToolTimelineProps): JSX.Element | null {\n if (toolCalls.length === 0) {\n return null;\n }\n\n return (\n <div className=\"devic-tool-timeline\">\n {toolCalls.map((tool) => (\n <div key={tool.id} className=\"devic-tool-item\">\n <span className=\"devic-tool-status\" data-status={tool.status} />\n <span className=\"devic-tool-name\">{formatToolName(tool.name)}</span>\n {tool.status === 'error' && tool.error && (\n <span className=\"devic-tool-error\">{tool.error}</span>\n )}\n </div>\n ))}\n </div>\n );\n}\n\n/**\n * Format tool name for display\n */\nfunction formatToolName(name: string): string {\n // Convert snake_case or camelCase to Title Case with spaces\n return name\n .replace(/_/g, ' ')\n .replace(/([a-z])([A-Z])/g, '$1 $2')\n .replace(/\\b\\w/g, (char) => char.toUpperCase());\n}\n"],"names":["_jsx","_jsxs"],"mappings":";;AAGA;;AAEG;AACG,SAAU,YAAY,CAAC,EAAE,SAAS,EAAqB,EAAA;AAC3D,IAAA,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;AAC1B,QAAA,OAAO,IAAI;IACb;AAEA,IAAA,QACEA,GAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,qBAAqB,EAAA,QAAA,EACjC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,MAClBC,IAAA,CAAA,KAAA,EAAA,EAAmB,SAAS,EAAC,iBAAiB,EAAA,QAAA,EAAA,CAC5CD,GAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,mBAAmB,EAAA,aAAA,EAAc,IAAI,CAAC,MAAM,GAAI,EAChEA,GAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,iBAAiB,EAAA,QAAA,EAAE,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAA,CAAQ,EACnE,IAAI,CAAC,MAAM,KAAK,OAAO,IAAI,IAAI,CAAC,KAAK,KACpCA,GAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,kBAAkB,EAAA,QAAA,EAAE,IAAI,CAAC,KAAK,GAAQ,CACvD,CAAA,EAAA,EALO,IAAI,CAAC,EAAE,CAMX,CACP,CAAC,EAAA,CACE;AAEV;AAEA;;AAEG;AACH,SAAS,cAAc,CAAC,IAAY,EAAA;;AAElC,IAAA,OAAO;AACJ,SAAA,OAAO,CAAC,IAAI,EAAE,GAAG;AACjB,SAAA,OAAO,CAAC,iBAAiB,EAAE,OAAO;AAClC,SAAA,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,WAAW,EAAE,CAAC;AACnD;;;;"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ChatDrawer } from './ChatDrawer';
|
|
2
|
+
export { ChatMessages } from './ChatMessages';
|
|
3
|
+
export { ChatInput } from './ChatInput';
|
|
4
|
+
export { ToolTimeline } from './ToolTimeline';
|
|
5
|
+
export type { ChatDrawerProps, ChatDrawerOptions, ChatMessagesProps, ChatInputProps, ToolTimelineProps, AllowedFileTypes, } from './ChatDrawer.types';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { useDevicChat } from './useDevicChat';
|
|
2
|
+
export type { UseDevicChatOptions, UseDevicChatResult } from './useDevicChat';
|
|
3
|
+
export { usePolling } from './usePolling';
|
|
4
|
+
export type { UsePollingOptions, UsePollingResult } from './usePolling';
|
|
5
|
+
export { useModelInterface } from './useModelInterface';
|
|
6
|
+
export type { UseModelInterfaceOptions, UseModelInterfaceResult } from './useModelInterface';
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { ChatMessage, ChatFile, ModelInterfaceTool, RealtimeStatus } from '../api/types';
|
|
2
|
+
export interface UseDevicChatOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Assistant identifier
|
|
5
|
+
*/
|
|
6
|
+
assistantId: string;
|
|
7
|
+
/**
|
|
8
|
+
* Existing chat UID to continue a conversation
|
|
9
|
+
*/
|
|
10
|
+
chatUid?: string;
|
|
11
|
+
/**
|
|
12
|
+
* API key (overrides provider context)
|
|
13
|
+
*/
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Base URL (overrides provider context)
|
|
17
|
+
*/
|
|
18
|
+
baseUrl?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Tenant ID for multi-tenant environments
|
|
21
|
+
*/
|
|
22
|
+
tenantId?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Tenant metadata
|
|
25
|
+
*/
|
|
26
|
+
tenantMetadata?: Record<string, any>;
|
|
27
|
+
/**
|
|
28
|
+
* Tools enabled from the assistant's configured tool groups
|
|
29
|
+
*/
|
|
30
|
+
enabledTools?: string[];
|
|
31
|
+
/**
|
|
32
|
+
* Client-side tools for model interface protocol
|
|
33
|
+
*/
|
|
34
|
+
modelInterfaceTools?: ModelInterfaceTool[];
|
|
35
|
+
/**
|
|
36
|
+
* Polling interval for async mode (ms)
|
|
37
|
+
* @default 1000
|
|
38
|
+
*/
|
|
39
|
+
pollingInterval?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Callback when a message is sent
|
|
42
|
+
*/
|
|
43
|
+
onMessageSent?: (message: ChatMessage) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Callback when a message is received
|
|
46
|
+
*/
|
|
47
|
+
onMessageReceived?: (message: ChatMessage) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Callback when a tool is called
|
|
50
|
+
*/
|
|
51
|
+
onToolCall?: (toolName: string, params: any) => void;
|
|
52
|
+
/**
|
|
53
|
+
* Callback when an error occurs
|
|
54
|
+
*/
|
|
55
|
+
onError?: (error: Error) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Callback when a new chat is created
|
|
58
|
+
*/
|
|
59
|
+
onChatCreated?: (chatUid: string) => void;
|
|
60
|
+
}
|
|
61
|
+
export interface UseDevicChatResult {
|
|
62
|
+
/**
|
|
63
|
+
* Current chat messages
|
|
64
|
+
*/
|
|
65
|
+
messages: ChatMessage[];
|
|
66
|
+
/**
|
|
67
|
+
* Current chat UID
|
|
68
|
+
*/
|
|
69
|
+
chatUid: string | null;
|
|
70
|
+
/**
|
|
71
|
+
* Whether a message is being processed
|
|
72
|
+
*/
|
|
73
|
+
isLoading: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Current status
|
|
76
|
+
*/
|
|
77
|
+
status: RealtimeStatus | 'idle';
|
|
78
|
+
/**
|
|
79
|
+
* Last error
|
|
80
|
+
*/
|
|
81
|
+
error: Error | null;
|
|
82
|
+
/**
|
|
83
|
+
* Send a message
|
|
84
|
+
*/
|
|
85
|
+
sendMessage: (message: string, options?: {
|
|
86
|
+
files?: ChatFile[];
|
|
87
|
+
metadata?: Record<string, any>;
|
|
88
|
+
}) => Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Clear the chat and start a new conversation
|
|
91
|
+
*/
|
|
92
|
+
clearChat: () => void;
|
|
93
|
+
/**
|
|
94
|
+
* Load an existing chat
|
|
95
|
+
*/
|
|
96
|
+
loadChat: (chatUid: string) => Promise<void>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Main hook for managing chat with a Devic assistant
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```tsx
|
|
103
|
+
* const {
|
|
104
|
+
* messages,
|
|
105
|
+
* isLoading,
|
|
106
|
+
* sendMessage,
|
|
107
|
+
* } = useDevicChat({
|
|
108
|
+
* assistantId: 'my-assistant',
|
|
109
|
+
* modelInterfaceTools: [
|
|
110
|
+
* {
|
|
111
|
+
* toolName: 'get_user_location',
|
|
112
|
+
* schema: { ... },
|
|
113
|
+
* callback: async () => ({ lat: 40.7, lng: -74.0 })
|
|
114
|
+
* }
|
|
115
|
+
* ],
|
|
116
|
+
* onMessageReceived: (msg) => console.log('Received:', msg),
|
|
117
|
+
* });
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare function useDevicChat(options: UseDevicChatOptions): UseDevicChatResult;
|