@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.
Files changed (70) hide show
  1. package/README.md +363 -0
  2. package/dist/cjs/api/client.js +118 -0
  3. package/dist/cjs/api/client.js.map +1 -0
  4. package/dist/cjs/components/ChatDrawer/ChatDrawer.js +122 -0
  5. package/dist/cjs/components/ChatDrawer/ChatDrawer.js.map +1 -0
  6. package/dist/cjs/components/ChatDrawer/ChatInput.js +128 -0
  7. package/dist/cjs/components/ChatDrawer/ChatInput.js.map +1 -0
  8. package/dist/cjs/components/ChatDrawer/ChatMessages.js +56 -0
  9. package/dist/cjs/components/ChatDrawer/ChatMessages.js.map +1 -0
  10. package/dist/cjs/components/ChatDrawer/ToolTimeline.js +26 -0
  11. package/dist/cjs/components/ChatDrawer/ToolTimeline.js.map +1 -0
  12. package/dist/cjs/hooks/useDevicChat.js +258 -0
  13. package/dist/cjs/hooks/useDevicChat.js.map +1 -0
  14. package/dist/cjs/hooks/useModelInterface.js +130 -0
  15. package/dist/cjs/hooks/useModelInterface.js.map +1 -0
  16. package/dist/cjs/hooks/usePolling.js +109 -0
  17. package/dist/cjs/hooks/usePolling.js.map +1 -0
  18. package/dist/cjs/index.js +36 -0
  19. package/dist/cjs/index.js.map +1 -0
  20. package/dist/cjs/provider/DevicContext.js +32 -0
  21. package/dist/cjs/provider/DevicContext.js.map +1 -0
  22. package/dist/cjs/provider/DevicProvider.js +43 -0
  23. package/dist/cjs/provider/DevicProvider.js.map +1 -0
  24. package/dist/cjs/styles.css +1 -0
  25. package/dist/cjs/utils/index.js +117 -0
  26. package/dist/cjs/utils/index.js.map +1 -0
  27. package/dist/esm/api/client.d.ts +56 -0
  28. package/dist/esm/api/client.js +115 -0
  29. package/dist/esm/api/client.js.map +1 -0
  30. package/dist/esm/api/types.d.ts +184 -0
  31. package/dist/esm/components/ChatDrawer/ChatDrawer.d.ts +27 -0
  32. package/dist/esm/components/ChatDrawer/ChatDrawer.js +120 -0
  33. package/dist/esm/components/ChatDrawer/ChatDrawer.js.map +1 -0
  34. package/dist/esm/components/ChatDrawer/ChatDrawer.types.d.ts +197 -0
  35. package/dist/esm/components/ChatDrawer/ChatInput.d.ts +5 -0
  36. package/dist/esm/components/ChatDrawer/ChatInput.js +126 -0
  37. package/dist/esm/components/ChatDrawer/ChatInput.js.map +1 -0
  38. package/dist/esm/components/ChatDrawer/ChatMessages.d.ts +5 -0
  39. package/dist/esm/components/ChatDrawer/ChatMessages.js +54 -0
  40. package/dist/esm/components/ChatDrawer/ChatMessages.js.map +1 -0
  41. package/dist/esm/components/ChatDrawer/ToolTimeline.d.ts +5 -0
  42. package/dist/esm/components/ChatDrawer/ToolTimeline.js +24 -0
  43. package/dist/esm/components/ChatDrawer/ToolTimeline.js.map +1 -0
  44. package/dist/esm/components/ChatDrawer/index.d.ts +5 -0
  45. package/dist/esm/hooks/index.d.ts +6 -0
  46. package/dist/esm/hooks/useDevicChat.d.ts +120 -0
  47. package/dist/esm/hooks/useDevicChat.js +256 -0
  48. package/dist/esm/hooks/useDevicChat.js.map +1 -0
  49. package/dist/esm/hooks/useModelInterface.d.ts +68 -0
  50. package/dist/esm/hooks/useModelInterface.js +128 -0
  51. package/dist/esm/hooks/useModelInterface.js.map +1 -0
  52. package/dist/esm/hooks/usePolling.d.ts +64 -0
  53. package/dist/esm/hooks/usePolling.js +107 -0
  54. package/dist/esm/hooks/usePolling.js.map +1 -0
  55. package/dist/esm/index.d.ts +10 -0
  56. package/dist/esm/index.js +12 -0
  57. package/dist/esm/index.js.map +1 -0
  58. package/dist/esm/provider/DevicContext.d.ts +15 -0
  59. package/dist/esm/provider/DevicContext.js +28 -0
  60. package/dist/esm/provider/DevicContext.js.map +1 -0
  61. package/dist/esm/provider/DevicProvider.d.ts +17 -0
  62. package/dist/esm/provider/DevicProvider.js +41 -0
  63. package/dist/esm/provider/DevicProvider.js.map +1 -0
  64. package/dist/esm/provider/index.d.ts +3 -0
  65. package/dist/esm/provider/types.d.ts +58 -0
  66. package/dist/esm/styles.css +1 -0
  67. package/dist/esm/utils/index.d.ts +32 -0
  68. package/dist/esm/utils/index.js +109 -0
  69. package/dist/esm/utils/index.js.map +1 -0
  70. package/package.json +68 -0
@@ -0,0 +1,128 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
5
+
6
+ const FILE_TYPE_ACCEPT = {
7
+ images: ['image/jpeg', 'image/png', 'image/gif', 'image/webp'],
8
+ documents: [
9
+ 'application/pdf',
10
+ 'application/msword',
11
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
12
+ 'text/plain',
13
+ 'text/csv',
14
+ ],
15
+ audio: ['audio/mpeg', 'audio/wav', 'audio/ogg'],
16
+ video: ['video/mp4', 'video/webm', 'video/ogg'],
17
+ };
18
+ /**
19
+ * Chat input component with file upload support
20
+ */
21
+ function ChatInput({ onSend, disabled = false, placeholder = 'Type a message...', enableFileUploads = false, allowedFileTypes = { images: true, documents: true }, maxFileSize = 10 * 1024 * 1024, // 10MB
22
+ }) {
23
+ const [message, setMessage] = react.useState('');
24
+ const [files, setFiles] = react.useState([]);
25
+ const textareaRef = react.useRef(null);
26
+ const fileInputRef = react.useRef(null);
27
+ // Calculate accepted file types
28
+ const acceptedTypes = Object.entries(allowedFileTypes)
29
+ .filter(([, enabled]) => enabled)
30
+ .flatMap(([type]) => FILE_TYPE_ACCEPT[type] || [])
31
+ .join(',');
32
+ // Auto-resize textarea
33
+ const handleInput = react.useCallback(() => {
34
+ const textarea = textareaRef.current;
35
+ if (textarea) {
36
+ textarea.style.height = 'auto';
37
+ textarea.style.height = `${Math.min(textarea.scrollHeight, 120)}px`;
38
+ }
39
+ }, []);
40
+ // Handle send
41
+ const handleSend = react.useCallback(() => {
42
+ const trimmedMessage = message.trim();
43
+ if (!trimmedMessage && files.length === 0)
44
+ return;
45
+ // Convert File objects to ChatFile format
46
+ const chatFiles = files.map((file) => ({
47
+ name: file.name,
48
+ fileType: getFileType(file.type),
49
+ }));
50
+ onSend(trimmedMessage, chatFiles.length > 0 ? chatFiles : undefined);
51
+ setMessage('');
52
+ setFiles([]);
53
+ // Reset textarea height
54
+ if (textareaRef.current) {
55
+ textareaRef.current.style.height = 'auto';
56
+ }
57
+ }, [message, files, onSend]);
58
+ // Handle key press
59
+ const handleKeyDown = react.useCallback((e) => {
60
+ if (e.key === 'Enter' && !e.shiftKey) {
61
+ e.preventDefault();
62
+ handleSend();
63
+ }
64
+ }, [handleSend]);
65
+ // Handle file selection
66
+ const handleFileSelect = react.useCallback((e) => {
67
+ const selectedFiles = Array.from(e.target.files || []);
68
+ // Filter valid files
69
+ const validFiles = selectedFiles.filter((file) => {
70
+ if (file.size > maxFileSize) {
71
+ console.warn(`File ${file.name} exceeds maximum size`);
72
+ return false;
73
+ }
74
+ return true;
75
+ });
76
+ setFiles((prev) => [...prev, ...validFiles]);
77
+ // Reset input
78
+ if (fileInputRef.current) {
79
+ fileInputRef.current.value = '';
80
+ }
81
+ }, [maxFileSize]);
82
+ // Remove file
83
+ const removeFile = react.useCallback((index) => {
84
+ setFiles((prev) => prev.filter((_, i) => i !== index));
85
+ }, []);
86
+ return (jsxRuntime.jsxs("div", { className: "devic-input-area", children: [files.length > 0 && (jsxRuntime.jsx("div", { className: "devic-file-preview", children: files.map((file, idx) => (jsxRuntime.jsxs("div", { className: "devic-file-preview-item", children: [jsxRuntime.jsx(FileIcon, {}), jsxRuntime.jsx("span", { children: file.name }), jsxRuntime.jsx("button", { className: "devic-file-remove", onClick: () => removeFile(idx), type: "button", children: "\u00D7" })] }, idx))) })), jsxRuntime.jsxs("div", { className: "devic-input-wrapper", children: [enableFileUploads && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("input", { ref: fileInputRef, type: "file", accept: acceptedTypes, multiple: true, onChange: handleFileSelect, style: { display: 'none' } }), jsxRuntime.jsx("button", { className: "devic-input-btn", onClick: () => fileInputRef.current?.click(), disabled: disabled, type: "button", title: "Attach file", children: jsxRuntime.jsx(AttachIcon, {}) })] })), jsxRuntime.jsx("textarea", { ref: textareaRef, className: "devic-input", value: message, onChange: (e) => {
87
+ setMessage(e.target.value);
88
+ handleInput();
89
+ }, onKeyDown: handleKeyDown, placeholder: placeholder, disabled: disabled, rows: 1 }), jsxRuntime.jsx("button", { className: "devic-input-btn devic-send-btn", onClick: handleSend, disabled: disabled || (!message.trim() && files.length === 0), type: "button", title: "Send message", children: jsxRuntime.jsx(SendIcon, {}) })] })] }));
90
+ }
91
+ /**
92
+ * Get file type category from MIME type
93
+ */
94
+ function getFileType(mimeType) {
95
+ if (mimeType.startsWith('image/'))
96
+ return 'image';
97
+ if (mimeType.startsWith('audio/'))
98
+ return 'audio';
99
+ if (mimeType.startsWith('video/'))
100
+ return 'video';
101
+ if (mimeType.startsWith('application/pdf') ||
102
+ mimeType.startsWith('application/msword') ||
103
+ mimeType.startsWith('text/')) {
104
+ return 'document';
105
+ }
106
+ return 'other';
107
+ }
108
+ /**
109
+ * Attach icon
110
+ */
111
+ function AttachIcon() {
112
+ return (jsxRuntime.jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: jsxRuntime.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" }) }));
113
+ }
114
+ /**
115
+ * Send icon
116
+ */
117
+ function SendIcon() {
118
+ return (jsxRuntime.jsx("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "currentColor", children: jsxRuntime.jsx("path", { d: "M2.01 21L23 12 2.01 3 2 10l15 2-15 2z" }) }));
119
+ }
120
+ /**
121
+ * File icon
122
+ */
123
+ function FileIcon() {
124
+ return (jsxRuntime.jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [jsxRuntime.jsx("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }), jsxRuntime.jsx("polyline", { points: "14,2 14,8 20,8" })] }));
125
+ }
126
+
127
+ exports.ChatInput = ChatInput;
128
+ //# 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 &times;\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":["useState","useRef","useCallback","_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,EAAE,IAAI,EAAE,EACpD,WAAW,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI;AACf,EAAA,EAAA;IACf,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAGA,cAAQ,CAAC,EAAE,CAAC;IAC1C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAGA,cAAQ,CAAS,EAAE,CAAC;AAC9C,IAAA,MAAM,WAAW,GAAGC,YAAM,CAAsB,IAAI,CAAC;AACrD,IAAA,MAAM,YAAY,GAAGA,YAAM,CAAmB,IAAI,CAAC;;AAGnD,IAAA,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,gBAAgB;SAClD,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,OAAO;AAC/B,SAAA,OAAO,CAAC,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ACrB,WAAW,EAAC,GAAG,EACf,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,EAAA,QAAA,EAEtBA,yBAAM,CAAC,EAAC,mHAAmH,EAAA,CAAG,EAAA,CAC1H;AAEV;AAEA;;AAEG;AACH,SAAS,QAAQ,GAAA;IACf,QACEA,cAAA,CAAA,KAAA,EAAA,EACE,KAAK,EAAC,IAAI,EACV,MAAM,EAAC,IAAI,EACX,OAAO,EAAC,WAAW,EACnB,IAAI,EAAC,cAAc,EAAA,QAAA,EAEnBA,cAAA,CAAA,MAAA,EAAA,EAAM,CAAC,EAAC,uCAAuC,EAAA,CAAG,EAAA,CAC9C;AAEV;AAEA;;AAEG;AACH,SAAS,QAAQ,GAAA;IACf,QACED,yBACE,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,cAAA,CAAA,MAAA,EAAA,EAAM,CAAC,EAAC,4DAA4D,EAAA,CAAG,EACvEA,cAAA,CAAA,UAAA,EAAA,EAAU,MAAM,EAAC,gBAAgB,EAAA,CAAG,CAAA,EAAA,CAChC;AAEV;;;;"}
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
5
+ var ToolTimeline = require('./ToolTimeline.js');
6
+
7
+ /**
8
+ * Format timestamp to readable time
9
+ */
10
+ function formatTime(timestamp) {
11
+ return new Date(timestamp).toLocaleTimeString([], {
12
+ hour: '2-digit',
13
+ minute: '2-digit',
14
+ });
15
+ }
16
+ /**
17
+ * Messages list component
18
+ */
19
+ function ChatMessages({ messages, isLoading, welcomeMessage, suggestedMessages, onSuggestedClick, showToolTimeline = true, }) {
20
+ const containerRef = react.useRef(null);
21
+ const lastMessageCountRef = react.useRef(messages.length);
22
+ // Auto-scroll to bottom when new messages arrive
23
+ react.useEffect(() => {
24
+ if (messages.length > lastMessageCountRef.current && containerRef.current) {
25
+ containerRef.current.scrollTop = containerRef.current.scrollHeight;
26
+ }
27
+ lastMessageCountRef.current = messages.length;
28
+ }, [messages.length]);
29
+ // Extract tool calls for timeline
30
+ const toolCalls = showToolTimeline
31
+ ? messages
32
+ .filter((m) => m.tool_calls?.length)
33
+ .flatMap((m) => m.tool_calls.map((tc) => ({
34
+ id: tc.id,
35
+ name: tc.function.name,
36
+ status: 'completed',
37
+ timestamp: m.timestamp,
38
+ })))
39
+ : [];
40
+ return (jsxRuntime.jsxs("div", { className: "devic-messages-container", ref: containerRef, children: [messages.length === 0 && (welcomeMessage || suggestedMessages?.length) && (jsxRuntime.jsxs("div", { className: "devic-welcome", children: [welcomeMessage && (jsxRuntime.jsx("p", { className: "devic-welcome-text", children: welcomeMessage })), suggestedMessages && suggestedMessages.length > 0 && (jsxRuntime.jsx("div", { className: "devic-suggested-messages", children: suggestedMessages.map((msg, idx) => (jsxRuntime.jsx("button", { className: "devic-suggested-btn", onClick: () => onSuggestedClick?.(msg), children: msg }, idx))) }))] })), messages.map((message) => {
41
+ // Skip tool messages in main display (shown in timeline)
42
+ if (message.role === 'tool' && showToolTimeline) {
43
+ return null;
44
+ }
45
+ return (jsxRuntime.jsxs("div", { className: "devic-message", "data-role": message.role, children: [jsxRuntime.jsxs("div", { className: "devic-message-bubble", children: [message.content.message, message.content.files && message.content.files.length > 0 && (jsxRuntime.jsx("div", { className: "devic-message-files", children: message.content.files.map((file, idx) => (jsxRuntime.jsxs("div", { className: "devic-message-file", children: [jsxRuntime.jsx(FileIcon, {}), jsxRuntime.jsx("span", { children: file.name })] }, idx))) }))] }), jsxRuntime.jsx("span", { className: "devic-message-time", children: formatTime(message.timestamp) })] }, message.uid));
46
+ }), showToolTimeline && toolCalls.length > 0 && (jsxRuntime.jsx(ToolTimeline.ToolTimeline, { toolCalls: toolCalls })), isLoading && (jsxRuntime.jsxs("div", { className: "devic-loading", children: [jsxRuntime.jsx("span", { className: "devic-loading-dot" }), jsxRuntime.jsx("span", { className: "devic-loading-dot" }), jsxRuntime.jsx("span", { className: "devic-loading-dot" })] }))] }));
47
+ }
48
+ /**
49
+ * Simple file icon
50
+ */
51
+ function FileIcon() {
52
+ return (jsxRuntime.jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [jsxRuntime.jsx("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }), jsxRuntime.jsx("polyline", { points: "14,2 14,8 20,8" })] }));
53
+ }
54
+
55
+ exports.ChatMessages = ChatMessages;
56
+ //# 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 2v16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AAA,EAAM,CAAC,EAAC,4DAA4D,EAAA,CAAG,EACvEA,cAAA,CAAA,UAAA,EAAA,EAAU,MAAM,EAAC,gBAAgB,EAAA,CAAG,CAAA,EAAA,CAChC;AAEV;;;;"}
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+
5
+ /**
6
+ * Tool execution timeline component
7
+ */
8
+ function ToolTimeline({ toolCalls }) {
9
+ if (toolCalls.length === 0) {
10
+ return null;
11
+ }
12
+ return (jsxRuntime.jsx("div", { className: "devic-tool-timeline", children: toolCalls.map((tool) => (jsxRuntime.jsxs("div", { className: "devic-tool-item", children: [jsxRuntime.jsx("span", { className: "devic-tool-status", "data-status": tool.status }), jsxRuntime.jsx("span", { className: "devic-tool-name", children: formatToolName(tool.name) }), tool.status === 'error' && tool.error && (jsxRuntime.jsx("span", { className: "devic-tool-error", children: tool.error }))] }, tool.id))) }));
13
+ }
14
+ /**
15
+ * Format tool name for display
16
+ */
17
+ function formatToolName(name) {
18
+ // Convert snake_case or camelCase to Title Case with spaces
19
+ return name
20
+ .replace(/_/g, ' ')
21
+ .replace(/([a-z])([A-Z])/g, '$1 $2')
22
+ .replace(/\b\w/g, (char) => char.toUpperCase());
23
+ }
24
+
25
+ exports.ToolTimeline = ToolTimeline;
26
+ //# 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,cAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,qBAAqB,EAAA,QAAA,EACjC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,MAClBC,eAAA,CAAA,KAAA,EAAA,EAAmB,SAAS,EAAC,iBAAiB,EAAA,QAAA,EAAA,CAC5CD,cAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,mBAAmB,EAAA,aAAA,EAAc,IAAI,CAAC,MAAM,GAAI,EAChEA,cAAA,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,cAAA,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,258 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ require('react/jsx-runtime');
5
+ var DevicContext = require('../provider/DevicContext.js');
6
+ var client = require('../api/client.js');
7
+ var usePolling = require('./usePolling.js');
8
+ var useModelInterface = require('./useModelInterface.js');
9
+
10
+ /**
11
+ * Main hook for managing chat with a Devic assistant
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const {
16
+ * messages,
17
+ * isLoading,
18
+ * sendMessage,
19
+ * } = useDevicChat({
20
+ * assistantId: 'my-assistant',
21
+ * modelInterfaceTools: [
22
+ * {
23
+ * toolName: 'get_user_location',
24
+ * schema: { ... },
25
+ * callback: async () => ({ lat: 40.7, lng: -74.0 })
26
+ * }
27
+ * ],
28
+ * onMessageReceived: (msg) => console.log('Received:', msg),
29
+ * });
30
+ * ```
31
+ */
32
+ function useDevicChat(options) {
33
+ const { assistantId, chatUid: initialChatUid, apiKey: propsApiKey, baseUrl: propsBaseUrl, tenantId, tenantMetadata, enabledTools, modelInterfaceTools = [], pollingInterval = 1000, onMessageSent, onMessageReceived, onToolCall, onError, onChatCreated, } = options;
34
+ // Get context (may be null if not wrapped in provider)
35
+ const context = DevicContext.useOptionalDevicContext();
36
+ // Resolve configuration
37
+ const apiKey = propsApiKey || context?.apiKey;
38
+ const baseUrl = propsBaseUrl || context?.baseUrl || 'https://api.devic.ai';
39
+ const resolvedTenantId = tenantId || context?.tenantId;
40
+ const resolvedTenantMetadata = { ...context?.tenantMetadata, ...tenantMetadata };
41
+ // State
42
+ const [messages, setMessages] = react.useState([]);
43
+ const [chatUid, setChatUid] = react.useState(initialChatUid || null);
44
+ const [isLoading, setIsLoading] = react.useState(false);
45
+ const [status, setStatus] = react.useState('idle');
46
+ const [error, setError] = react.useState(null);
47
+ // Polling state
48
+ const [shouldPoll, setShouldPoll] = react.useState(false);
49
+ // Refs for callbacks
50
+ const onMessageReceivedRef = react.useRef(onMessageReceived);
51
+ const onErrorRef = react.useRef(onError);
52
+ const onChatCreatedRef = react.useRef(onChatCreated);
53
+ react.useEffect(() => {
54
+ onMessageReceivedRef.current = onMessageReceived;
55
+ onErrorRef.current = onError;
56
+ onChatCreatedRef.current = onChatCreated;
57
+ });
58
+ // Create API client
59
+ const clientRef = react.useRef(null);
60
+ if (!clientRef.current && apiKey) {
61
+ clientRef.current = new client.DevicApiClient({ apiKey, baseUrl });
62
+ }
63
+ // Update client config if it changes
64
+ react.useEffect(() => {
65
+ if (clientRef.current && apiKey) {
66
+ clientRef.current.setConfig({ apiKey, baseUrl });
67
+ }
68
+ }, [apiKey, baseUrl]);
69
+ // Model interface hook
70
+ const { toolSchemas, handleToolCalls, extractPendingToolCalls, } = useModelInterface.useModelInterface({
71
+ tools: modelInterfaceTools,
72
+ onToolExecute: onToolCall,
73
+ });
74
+ // Polling hook
75
+ usePolling.usePolling(shouldPoll ? chatUid : null, async () => {
76
+ if (!clientRef.current || !chatUid) {
77
+ throw new Error('Cannot poll without client or chatUid');
78
+ }
79
+ return clientRef.current.getRealtimeHistory(assistantId, chatUid);
80
+ }, {
81
+ interval: pollingInterval,
82
+ enabled: shouldPoll,
83
+ stopStatuses: ['completed', 'error', 'waiting_for_tool_response'],
84
+ onUpdate: async (data) => {
85
+ setMessages(data.chatHistory);
86
+ setStatus(data.status);
87
+ // Notify about new messages
88
+ const lastMessage = data.chatHistory[data.chatHistory.length - 1];
89
+ if (lastMessage && lastMessage.role === 'assistant') {
90
+ onMessageReceivedRef.current?.(lastMessage);
91
+ }
92
+ // Handle model interface - check for pending tool calls
93
+ if (data.status === 'waiting_for_tool_response' || data.pendingToolCalls?.length) {
94
+ await handlePendingToolCalls(data);
95
+ }
96
+ },
97
+ onStop: async (data) => {
98
+ setIsLoading(false);
99
+ setShouldPoll(false);
100
+ if (data?.status === 'error') {
101
+ const err = new Error('Chat processing failed');
102
+ setError(err);
103
+ onErrorRef.current?.(err);
104
+ }
105
+ else if (data?.status === 'waiting_for_tool_response') {
106
+ // Handle tool response
107
+ await handlePendingToolCalls(data);
108
+ }
109
+ },
110
+ onError: (err) => {
111
+ setError(err);
112
+ setIsLoading(false);
113
+ setShouldPoll(false);
114
+ onErrorRef.current?.(err);
115
+ },
116
+ });
117
+ // Handle pending tool calls from model interface
118
+ const handlePendingToolCalls = react.useCallback(async (data) => {
119
+ if (!clientRef.current || !chatUid)
120
+ return;
121
+ // Get pending tool calls
122
+ const pendingCalls = data.pendingToolCalls || extractPendingToolCalls(data.chatHistory);
123
+ if (pendingCalls.length === 0)
124
+ return;
125
+ try {
126
+ // Execute client-side tools
127
+ const responses = await handleToolCalls(pendingCalls);
128
+ if (responses.length > 0) {
129
+ // Send tool responses back to the API
130
+ await clientRef.current.sendToolResponses(assistantId, chatUid, responses);
131
+ // Resume polling
132
+ setShouldPoll(true);
133
+ setIsLoading(true);
134
+ }
135
+ }
136
+ catch (err) {
137
+ const error = err instanceof Error ? err : new Error(String(err));
138
+ setError(error);
139
+ onErrorRef.current?.(error);
140
+ }
141
+ }, [chatUid, assistantId, handleToolCalls, extractPendingToolCalls]);
142
+ // Send a message
143
+ const sendMessage = react.useCallback(async (message, sendOptions) => {
144
+ if (!clientRef.current) {
145
+ const err = new Error('API client not configured. Please provide an API key.');
146
+ setError(err);
147
+ onErrorRef.current?.(err);
148
+ return;
149
+ }
150
+ setIsLoading(true);
151
+ setError(null);
152
+ setStatus('processing');
153
+ // Add user message optimistically
154
+ const userMessage = {
155
+ uid: `temp-${Date.now()}`,
156
+ role: 'user',
157
+ content: {
158
+ message,
159
+ files: sendOptions?.files?.map((f) => ({
160
+ name: f.name,
161
+ url: f.downloadUrl || '',
162
+ type: f.fileType || 'other',
163
+ })),
164
+ },
165
+ timestamp: Date.now(),
166
+ };
167
+ setMessages((prev) => [...prev, userMessage]);
168
+ onMessageSent?.(userMessage);
169
+ try {
170
+ // Build request DTO
171
+ const dto = {
172
+ message,
173
+ chatUid: chatUid || undefined,
174
+ files: sendOptions?.files,
175
+ metadata: {
176
+ ...resolvedTenantMetadata,
177
+ ...sendOptions?.metadata,
178
+ },
179
+ tenantId: resolvedTenantId,
180
+ enabledTools,
181
+ // Include model interface tools if any
182
+ ...(toolSchemas.length > 0 && { tools: toolSchemas }),
183
+ };
184
+ // Send message in async mode
185
+ const response = await clientRef.current.sendMessageAsync(assistantId, dto);
186
+ // Update chat UID if this is a new chat
187
+ if (response.chatUid && response.chatUid !== chatUid) {
188
+ setChatUid(response.chatUid);
189
+ onChatCreatedRef.current?.(response.chatUid);
190
+ }
191
+ // Start polling for results
192
+ setShouldPoll(true);
193
+ }
194
+ catch (err) {
195
+ const error = err instanceof Error ? err : new Error(String(err));
196
+ setError(error);
197
+ setIsLoading(false);
198
+ setStatus('error');
199
+ onErrorRef.current?.(error);
200
+ // Remove optimistic user message on error
201
+ setMessages((prev) => prev.filter((m) => m.uid !== userMessage.uid));
202
+ }
203
+ }, [
204
+ chatUid,
205
+ assistantId,
206
+ enabledTools,
207
+ resolvedTenantId,
208
+ resolvedTenantMetadata,
209
+ toolSchemas,
210
+ onMessageSent,
211
+ ]);
212
+ // Clear chat
213
+ const clearChat = react.useCallback(() => {
214
+ setMessages([]);
215
+ setChatUid(null);
216
+ setStatus('idle');
217
+ setError(null);
218
+ setShouldPoll(false);
219
+ }, []);
220
+ // Load existing chat
221
+ const loadChat = react.useCallback(async (loadChatUid) => {
222
+ if (!clientRef.current) {
223
+ const err = new Error('API client not configured');
224
+ setError(err);
225
+ onErrorRef.current?.(err);
226
+ return;
227
+ }
228
+ setIsLoading(true);
229
+ setError(null);
230
+ try {
231
+ const history = await clientRef.current.getChatHistory(assistantId, loadChatUid);
232
+ setMessages(history.chatContent);
233
+ setChatUid(loadChatUid);
234
+ setStatus('completed');
235
+ }
236
+ catch (err) {
237
+ const error = err instanceof Error ? err : new Error(String(err));
238
+ setError(error);
239
+ onErrorRef.current?.(error);
240
+ }
241
+ finally {
242
+ setIsLoading(false);
243
+ }
244
+ }, [assistantId]);
245
+ return {
246
+ messages,
247
+ chatUid,
248
+ isLoading,
249
+ status,
250
+ error,
251
+ sendMessage,
252
+ clearChat,
253
+ loadChat,
254
+ };
255
+ }
256
+
257
+ exports.useDevicChat = useDevicChat;
258
+ //# sourceMappingURL=useDevicChat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDevicChat.js","sources":["../../../../src/hooks/useDevicChat.ts"],"sourcesContent":["import { useState, useCallback, useEffect, useRef } from 'react';\nimport { useOptionalDevicContext } from '../provider';\nimport { DevicApiClient } from '../api/client';\nimport { usePolling } from './usePolling';\nimport { useModelInterface } from './useModelInterface';\nimport type {\n ChatMessage,\n ChatFile,\n ModelInterfaceTool,\n RealtimeChatHistory,\n RealtimeStatus,\n} from '../api/types';\n\nexport interface UseDevicChatOptions {\n /**\n * Assistant identifier\n */\n assistantId: string;\n\n /**\n * Existing chat UID to continue a conversation\n */\n chatUid?: string;\n\n /**\n * API key (overrides provider context)\n */\n apiKey?: string;\n\n /**\n * Base URL (overrides provider context)\n */\n baseUrl?: string;\n\n /**\n * Tenant ID for multi-tenant environments\n */\n tenantId?: string;\n\n /**\n * Tenant metadata\n */\n tenantMetadata?: Record<string, any>;\n\n /**\n * Tools enabled from the assistant's configured tool groups\n */\n enabledTools?: string[];\n\n /**\n * Client-side tools for model interface protocol\n */\n modelInterfaceTools?: ModelInterfaceTool[];\n\n /**\n * Polling interval for async mode (ms)\n * @default 1000\n */\n pollingInterval?: number;\n\n /**\n * Callback when a message is sent\n */\n onMessageSent?: (message: ChatMessage) => void;\n\n /**\n * Callback when a message is received\n */\n onMessageReceived?: (message: ChatMessage) => void;\n\n /**\n * Callback when a tool is called\n */\n onToolCall?: (toolName: string, params: any) => void;\n\n /**\n * Callback when an error occurs\n */\n onError?: (error: Error) => void;\n\n /**\n * Callback when a new chat is created\n */\n onChatCreated?: (chatUid: string) => void;\n}\n\nexport interface UseDevicChatResult {\n /**\n * Current chat messages\n */\n messages: ChatMessage[];\n\n /**\n * Current chat UID\n */\n chatUid: string | null;\n\n /**\n * Whether a message is being processed\n */\n isLoading: boolean;\n\n /**\n * Current status\n */\n status: RealtimeStatus | 'idle';\n\n /**\n * Last error\n */\n error: Error | null;\n\n /**\n * Send a message\n */\n sendMessage: (\n message: string,\n options?: {\n files?: ChatFile[];\n metadata?: Record<string, any>;\n }\n ) => Promise<void>;\n\n /**\n * Clear the chat and start a new conversation\n */\n clearChat: () => void;\n\n /**\n * Load an existing chat\n */\n loadChat: (chatUid: string) => Promise<void>;\n}\n\n/**\n * Main hook for managing chat with a Devic assistant\n *\n * @example\n * ```tsx\n * const {\n * messages,\n * isLoading,\n * sendMessage,\n * } = useDevicChat({\n * assistantId: 'my-assistant',\n * modelInterfaceTools: [\n * {\n * toolName: 'get_user_location',\n * schema: { ... },\n * callback: async () => ({ lat: 40.7, lng: -74.0 })\n * }\n * ],\n * onMessageReceived: (msg) => console.log('Received:', msg),\n * });\n * ```\n */\nexport function useDevicChat(options: UseDevicChatOptions): UseDevicChatResult {\n const {\n assistantId,\n chatUid: initialChatUid,\n apiKey: propsApiKey,\n baseUrl: propsBaseUrl,\n tenantId,\n tenantMetadata,\n enabledTools,\n modelInterfaceTools = [],\n pollingInterval = 1000,\n onMessageSent,\n onMessageReceived,\n onToolCall,\n onError,\n onChatCreated,\n } = options;\n\n // Get context (may be null if not wrapped in provider)\n const context = useOptionalDevicContext();\n\n // Resolve configuration\n const apiKey = propsApiKey || context?.apiKey;\n const baseUrl = propsBaseUrl || context?.baseUrl || 'https://api.devic.ai';\n const resolvedTenantId = tenantId || context?.tenantId;\n const resolvedTenantMetadata = { ...context?.tenantMetadata, ...tenantMetadata };\n\n // State\n const [messages, setMessages] = useState<ChatMessage[]>([]);\n const [chatUid, setChatUid] = useState<string | null>(initialChatUid || null);\n const [isLoading, setIsLoading] = useState(false);\n const [status, setStatus] = useState<RealtimeStatus | 'idle'>('idle');\n const [error, setError] = useState<Error | null>(null);\n\n // Polling state\n const [shouldPoll, setShouldPoll] = useState(false);\n\n // Refs for callbacks\n const onMessageReceivedRef = useRef(onMessageReceived);\n const onErrorRef = useRef(onError);\n const onChatCreatedRef = useRef(onChatCreated);\n\n useEffect(() => {\n onMessageReceivedRef.current = onMessageReceived;\n onErrorRef.current = onError;\n onChatCreatedRef.current = onChatCreated;\n });\n\n // Create API client\n const clientRef = useRef<DevicApiClient | null>(null);\n if (!clientRef.current && apiKey) {\n clientRef.current = new DevicApiClient({ apiKey, baseUrl });\n }\n\n // Update client config if it changes\n useEffect(() => {\n if (clientRef.current && apiKey) {\n clientRef.current.setConfig({ apiKey, baseUrl });\n }\n }, [apiKey, baseUrl]);\n\n // Model interface hook\n const {\n toolSchemas,\n handleToolCalls,\n extractPendingToolCalls,\n } = useModelInterface({\n tools: modelInterfaceTools,\n onToolExecute: onToolCall,\n });\n\n // Polling hook\n const polling = usePolling(\n shouldPoll ? chatUid : null,\n async () => {\n if (!clientRef.current || !chatUid) {\n throw new Error('Cannot poll without client or chatUid');\n }\n return clientRef.current.getRealtimeHistory(assistantId, chatUid);\n },\n {\n interval: pollingInterval,\n enabled: shouldPoll,\n stopStatuses: ['completed', 'error', 'waiting_for_tool_response'],\n onUpdate: async (data: RealtimeChatHistory) => {\n setMessages(data.chatHistory);\n setStatus(data.status);\n\n // Notify about new messages\n const lastMessage = data.chatHistory[data.chatHistory.length - 1];\n if (lastMessage && lastMessage.role === 'assistant') {\n onMessageReceivedRef.current?.(lastMessage);\n }\n\n // Handle model interface - check for pending tool calls\n if (data.status === 'waiting_for_tool_response' || data.pendingToolCalls?.length) {\n await handlePendingToolCalls(data);\n }\n },\n onStop: async (data) => {\n setIsLoading(false);\n setShouldPoll(false);\n\n if (data?.status === 'error') {\n const err = new Error('Chat processing failed');\n setError(err);\n onErrorRef.current?.(err);\n } else if (data?.status === 'waiting_for_tool_response') {\n // Handle tool response\n await handlePendingToolCalls(data);\n }\n },\n onError: (err) => {\n setError(err);\n setIsLoading(false);\n setShouldPoll(false);\n onErrorRef.current?.(err);\n },\n }\n );\n\n // Handle pending tool calls from model interface\n const handlePendingToolCalls = useCallback(\n async (data: RealtimeChatHistory) => {\n if (!clientRef.current || !chatUid) return;\n\n // Get pending tool calls\n const pendingCalls = data.pendingToolCalls || extractPendingToolCalls(data.chatHistory);\n\n if (pendingCalls.length === 0) return;\n\n try {\n // Execute client-side tools\n const responses = await handleToolCalls(pendingCalls);\n\n if (responses.length > 0) {\n // Send tool responses back to the API\n await clientRef.current.sendToolResponses(assistantId, chatUid, responses);\n\n // Resume polling\n setShouldPoll(true);\n setIsLoading(true);\n }\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n onErrorRef.current?.(error);\n }\n },\n [chatUid, assistantId, handleToolCalls, extractPendingToolCalls]\n );\n\n // Send a message\n const sendMessage = useCallback(\n async (\n message: string,\n sendOptions?: {\n files?: ChatFile[];\n metadata?: Record<string, any>;\n }\n ) => {\n if (!clientRef.current) {\n const err = new Error(\n 'API client not configured. Please provide an API key.'\n );\n setError(err);\n onErrorRef.current?.(err);\n return;\n }\n\n setIsLoading(true);\n setError(null);\n setStatus('processing');\n\n // Add user message optimistically\n const userMessage: ChatMessage = {\n uid: `temp-${Date.now()}`,\n role: 'user',\n content: {\n message,\n files: sendOptions?.files?.map((f) => ({\n name: f.name,\n url: f.downloadUrl || '',\n type: f.fileType || 'other',\n })),\n },\n timestamp: Date.now(),\n };\n\n setMessages((prev) => [...prev, userMessage]);\n onMessageSent?.(userMessage);\n\n try {\n // Build request DTO\n const dto = {\n message,\n chatUid: chatUid || undefined,\n files: sendOptions?.files,\n metadata: {\n ...resolvedTenantMetadata,\n ...sendOptions?.metadata,\n },\n tenantId: resolvedTenantId,\n enabledTools,\n // Include model interface tools if any\n ...(toolSchemas.length > 0 && { tools: toolSchemas }),\n };\n\n // Send message in async mode\n const response = await clientRef.current.sendMessageAsync(assistantId, dto);\n\n // Update chat UID if this is a new chat\n if (response.chatUid && response.chatUid !== chatUid) {\n setChatUid(response.chatUid);\n onChatCreatedRef.current?.(response.chatUid);\n }\n\n // Start polling for results\n setShouldPoll(true);\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n setIsLoading(false);\n setStatus('error');\n onErrorRef.current?.(error);\n\n // Remove optimistic user message on error\n setMessages((prev) => prev.filter((m) => m.uid !== userMessage.uid));\n }\n },\n [\n chatUid,\n assistantId,\n enabledTools,\n resolvedTenantId,\n resolvedTenantMetadata,\n toolSchemas,\n onMessageSent,\n ]\n );\n\n // Clear chat\n const clearChat = useCallback(() => {\n setMessages([]);\n setChatUid(null);\n setStatus('idle');\n setError(null);\n setShouldPoll(false);\n }, []);\n\n // Load existing chat\n const loadChat = useCallback(\n async (loadChatUid: string) => {\n if (!clientRef.current) {\n const err = new Error('API client not configured');\n setError(err);\n onErrorRef.current?.(err);\n return;\n }\n\n setIsLoading(true);\n setError(null);\n\n try {\n const history = await clientRef.current.getChatHistory(\n assistantId,\n loadChatUid\n );\n\n setMessages(history.chatContent);\n setChatUid(loadChatUid);\n setStatus('completed');\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n onErrorRef.current?.(error);\n } finally {\n setIsLoading(false);\n }\n },\n [assistantId]\n );\n\n return {\n messages,\n chatUid,\n isLoading,\n status,\n error,\n sendMessage,\n clearChat,\n loadChat,\n };\n}\n"],"names":["useOptionalDevicContext","useState","useRef","useEffect","DevicApiClient","useModelInterface","usePolling","useCallback"],"mappings":";;;;;;;;;AAsIA;;;;;;;;;;;;;;;;;;;;;AAqBG;AACG,SAAU,YAAY,CAAC,OAA4B,EAAA;AACvD,IAAA,MAAM,EACJ,WAAW,EACX,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,YAAY,EACrB,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,mBAAmB,GAAG,EAAE,EACxB,eAA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