lua-ai-chat 0.0.1

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 ADDED
@@ -0,0 +1,67 @@
1
+ # lua-ai-chat
2
+
3
+ A comprehensive set of React components for building chat interfaces in the Lua ai ecosystem.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install lua-ai-chat
9
+ # or
10
+ yarn add lua-ai-chat
11
+ # or
12
+ pnpm add lua-ai-chat
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```tsx
18
+ import { ChatMessage, ChatInput, ChatContext } from 'lua-ai-chat';
19
+
20
+ function MyChatApp() {
21
+ return (
22
+ <ChatContext.Provider value={chatContextValue}>
23
+ <div className="chat-container">
24
+ <ChatMessage message={message} />
25
+ <ChatInput onSend={handleSend} />
26
+ </div>
27
+ </ChatContext.Provider>
28
+ );
29
+ }
30
+ ```
31
+
32
+ ## Components
33
+
34
+ ### Messages
35
+ - `ChatMessage` - Main message component
36
+ - `ActionMessage` - Action-based messages
37
+ - `DocumentsMessage` - Document display
38
+ - `ImageMessage` - Image display
39
+ - `VideoMessage` - Video display
40
+ - `LocationMessage` - Location display
41
+ - `LoadingMessage` - Loading state
42
+
43
+ ### Input & Toolbar
44
+ - `ChatInput` - Main input component
45
+ - `Toolbar` - Message composition toolbar
46
+ - `FilePreview` - File preview components
47
+
48
+ ### Dialogs
49
+ - `ImageDialog` - Image viewing dialog
50
+ - `VideoDialog` - Video viewing dialog
51
+ - `LocationDialog` - Location viewing dialog
52
+ - `CameraDialog` - Camera interface
53
+
54
+ ### Audio
55
+ - `AudioRecorder` - Audio recording component
56
+
57
+ ## Development
58
+
59
+ This package is built with:
60
+ - React 18+
61
+ - TypeScript
62
+ - Tailwind CSS
63
+ - Radix UI primitives
64
+
65
+ ## License
66
+
67
+ MIT
@@ -0,0 +1,269 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+ import { RefObject, ReactNode } from 'react';
4
+
5
+ type AudioRecorderProps = {
6
+ onAudioRecorded: (audioBlob: Blob, messageText?: string) => void;
7
+ onClose: () => void;
8
+ inputMessage?: string;
9
+ };
10
+ declare function AudioRecorder({ onAudioRecorded, onClose, inputMessage, }: AudioRecorderProps): react_jsx_runtime.JSX.Element;
11
+
12
+ type VideoDialogProps = {
13
+ videoRef: RefObject<HTMLVideoElement>;
14
+ isRecording: boolean;
15
+ recordingTime: number;
16
+ loading: boolean;
17
+ onStartRecording: () => void;
18
+ onStopRecording: () => void;
19
+ onClose: () => void;
20
+ open: boolean;
21
+ };
22
+ declare function VideoDialog({ videoRef, isRecording, recordingTime, loading, onStartRecording, onStopRecording, onClose, open, }: VideoDialogProps): react_jsx_runtime.JSX.Element;
23
+
24
+ type ImageDialogProps = {
25
+ url: string;
26
+ alt?: string;
27
+ open: boolean;
28
+ onClose: () => void;
29
+ };
30
+ declare function ImageDialog({ url, alt, open, onClose }: ImageDialogProps): react_jsx_runtime.JSX.Element;
31
+
32
+ type CarouselImage = {
33
+ src: string;
34
+ alt: string;
35
+ };
36
+ type CarouselImageDialogProps = {
37
+ images: CarouselImage[];
38
+ initialIndex?: number;
39
+ open: boolean;
40
+ onClose: () => void;
41
+ };
42
+ declare function CarouselImageDialog({ images, initialIndex, open, onClose, }: CarouselImageDialogProps): react_jsx_runtime.JSX.Element;
43
+
44
+ type CameraDialogProps = {
45
+ videoRef: RefObject<HTMLVideoElement>;
46
+ canvasRef: RefObject<HTMLCanvasElement>;
47
+ onCapture: () => void;
48
+ onClose: () => void;
49
+ open: boolean;
50
+ };
51
+ declare function CameraDialog({ videoRef, canvasRef, onCapture, onClose, open, }: CameraDialogProps): react_jsx_runtime.JSX.Element;
52
+
53
+ type LocationDialogProps = {
54
+ locationError: string;
55
+ currentLocation: {
56
+ latitude: number;
57
+ longitude: number;
58
+ address?: string;
59
+ } | null;
60
+ loading: boolean;
61
+ onShare: () => void;
62
+ onClose: () => void;
63
+ };
64
+ declare function LocationDialog({ locationError, currentLocation, loading, onShare, onClose, }: LocationDialogProps): react_jsx_runtime.JSX.Element;
65
+
66
+ type ChatMessageProps = {
67
+ id: string;
68
+ role: "user" | "assistant";
69
+ content: string;
70
+ type?: "text" | "image" | "video" | "audio" | "location" | "actions" | "links" | "tool" | "payment" | "file";
71
+ image?: string;
72
+ video?: string;
73
+ audio?: string;
74
+ mimeType?: string;
75
+ text?: string;
76
+ location?: {
77
+ latitude: number;
78
+ longitude: number;
79
+ address?: string;
80
+ };
81
+ url?: string;
82
+ waitingMessage?: string;
83
+ isUploading?: boolean;
84
+ uploadProgress?: number;
85
+ createdAt: string;
86
+ onSelect?: (text: string) => void;
87
+ luaApiUrl?: string;
88
+ };
89
+ declare const ChatMessage: react.NamedExoticComponent<{
90
+ message: ChatMessageProps;
91
+ onSelect?: (text: string) => void;
92
+ luaApiUrl?: string;
93
+ authToken?: string;
94
+ disablePreviewOnLinks?: boolean;
95
+ onNavigate?: (pathname: string, options: {
96
+ query: Record<string, string>;
97
+ }) => void;
98
+ }>;
99
+
100
+ type CodeBlockProps = {
101
+ children: ReactNode;
102
+ className?: string;
103
+ language?: string;
104
+ };
105
+ declare function CodeBlock({ children, language }: CodeBlockProps): react_jsx_runtime.JSX.Element;
106
+
107
+ declare function LoadingMessage$1(): react_jsx_runtime.JSX.Element | null;
108
+
109
+ type ActionButton = {
110
+ text: string;
111
+ onClick: string;
112
+ };
113
+
114
+ type ActionMessageProps = {
115
+ buttons: ActionButton[];
116
+ onClick: (text: string) => void;
117
+ };
118
+ declare function ActionMessage({ buttons, onClick }: ActionMessageProps): react_jsx_runtime.JSX.Element;
119
+
120
+ type ChatActions = {
121
+ onSelect: (text: string) => void;
122
+ };
123
+ declare function ChatActions({ onSelect }: ChatActions): react_jsx_runtime.JSX.Element | null;
124
+
125
+ type AudioPreviewProps = {
126
+ message: {
127
+ audio?: string;
128
+ content: string;
129
+ isUploading?: boolean;
130
+ url?: string;
131
+ };
132
+ };
133
+ declare function AudioPreview({ message }: AudioPreviewProps): react_jsx_runtime.JSX.Element;
134
+
135
+ type PaymentPreviewProps = {
136
+ url: string;
137
+ };
138
+ declare function PaymentPreview({ url }: PaymentPreviewProps): react_jsx_runtime.JSX.Element;
139
+
140
+ type ChatInputProps = {
141
+ loading: boolean;
142
+ disabled: boolean;
143
+ onSend: () => void;
144
+ onFilePaste?: (files: File[]) => void;
145
+ };
146
+ declare const ChatInput: react.NamedExoticComponent<ChatInputProps>;
147
+
148
+ type FileMetadata = {
149
+ file: File;
150
+ url: string;
151
+ type: "image" | "video" | "audio" | "document" | "archive" | "other";
152
+ mimeType: string;
153
+ propertyName: "image" | "data";
154
+ };
155
+ type FilePreviewProps = {
156
+ files: File[];
157
+ onRemove: (index: number) => void;
158
+ cdnUrl: string;
159
+ fileMetadata?: FileMetadata[];
160
+ onFileUploadComplete?: (file: File, url: string) => void;
161
+ };
162
+ declare function FilePreview({ files, onRemove, cdnUrl, fileMetadata, onFileUploadComplete, }: FilePreviewProps): react_jsx_runtime.JSX.Element | null;
163
+
164
+ type FilePreviewCardProps = {
165
+ file: File;
166
+ onRemove: () => void;
167
+ cdnUrl: string;
168
+ initialUrl?: string;
169
+ onUploadComplete?: (file: File, url: string) => void;
170
+ };
171
+ declare function FilePreviewCard({ file, onRemove, cdnUrl, initialUrl, onUploadComplete, }: FilePreviewCardProps): react_jsx_runtime.JSX.Element;
172
+
173
+ type ToolbarProps = {
174
+ loading: boolean;
175
+ onFileClick: () => void;
176
+ onCameraClick: () => void;
177
+ onVideoClick: () => void;
178
+ onAudioClick: () => void;
179
+ onLocationClick: () => void;
180
+ onSendClick: () => void;
181
+ uploadProgress: number;
182
+ };
183
+ declare function Toolbar({ loading, onFileClick, onCameraClick, onVideoClick, onAudioClick, onLocationClick, onSendClick, }: ToolbarProps): react_jsx_runtime.JSX.Element;
184
+
185
+ declare const parseActions: (content: string) => ActionButton[];
186
+
187
+ declare const markdownStyles: {
188
+ p: string;
189
+ h1: string;
190
+ h2: string;
191
+ h3: string;
192
+ h4: string;
193
+ ul: string;
194
+ ol: string;
195
+ li: string;
196
+ a: string;
197
+ blockquote: string;
198
+ pre: string;
199
+ code: string;
200
+ img: string;
201
+ table: string;
202
+ th: string;
203
+ td: string;
204
+ };
205
+
206
+ declare function uploadFile(file: File, cdnUrl: string, onProgress?: (progress: number) => void): Promise<{
207
+ fileId: string;
208
+ }>;
209
+
210
+ type Message = {
211
+ id: string;
212
+ role: "user" | "assistant";
213
+ content: string;
214
+ type?: "text" | "image" | "video" | "audio" | "location" | "tool" | "file";
215
+ url?: string;
216
+ image?: string;
217
+ video?: string;
218
+ audio?: string;
219
+ location?: {
220
+ latitude: number;
221
+ longitude: number;
222
+ address?: string;
223
+ };
224
+ waitingMessage?: string;
225
+ isUploading?: boolean;
226
+ createdAt: string;
227
+ data?: string;
228
+ mimeType?: string;
229
+ uploadProgress?: number;
230
+ };
231
+ type LoadingMessage = string | null;
232
+ type ChatContextType = {
233
+ messages: Message[];
234
+ setMessages: React.Dispatch<React.SetStateAction<Message[]>>;
235
+ inputMessage: string;
236
+ setInputMessage: React.Dispatch<React.SetStateAction<string>>;
237
+ loadingMessage: LoadingMessage | null;
238
+ setLoadingMessage: React.Dispatch<React.SetStateAction<LoadingMessage | null>>;
239
+ hasUnreadMessages: boolean;
240
+ setHasUnreadMessages: React.Dispatch<React.SetStateAction<boolean>>;
241
+ getFileUrl: (file: File) => string;
242
+ removeFileUrl: (file: File) => void;
243
+ };
244
+ declare function ChatProvider({ children }: {
245
+ children: ReactNode;
246
+ }): react_jsx_runtime.JSX.Element;
247
+ declare function useMessages(): {
248
+ messages: Message[];
249
+ setMessages: React.Dispatch<React.SetStateAction<Message[]>>;
250
+ };
251
+ declare function useInput(): {
252
+ inputMessage: string;
253
+ setInputMessage: React.Dispatch<React.SetStateAction<string>>;
254
+ };
255
+ declare function useLoadingMessage(): {
256
+ loadingMessage: LoadingMessage | null;
257
+ setLoadingMessage: React.Dispatch<React.SetStateAction<LoadingMessage | null>>;
258
+ };
259
+ declare function useFileUrls(): {
260
+ getFileUrl: (file: File) => string;
261
+ removeFileUrl: (file: File) => void;
262
+ };
263
+ declare function useUnreadMessages(): {
264
+ hasUnreadMessages: boolean;
265
+ setHasUnreadMessages: React.Dispatch<React.SetStateAction<boolean>>;
266
+ };
267
+ declare function useChat(): ChatContextType;
268
+
269
+ export { type ActionButton, ActionMessage, AudioPreview, AudioRecorder, CameraDialog, CarouselImageDialog, ChatActions, ChatInput, ChatMessage, type ChatMessageProps, ChatProvider, CodeBlock, type FileMetadata, FilePreview, FilePreviewCard, ImageDialog, LoadingMessage$1 as LoadingMessage, LocationDialog, PaymentPreview, Toolbar, VideoDialog, markdownStyles, parseActions, uploadFile, useChat, useFileUrls, useInput, useLoadingMessage, useMessages, useUnreadMessages };
@@ -0,0 +1,269 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+ import { RefObject, ReactNode } from 'react';
4
+
5
+ type AudioRecorderProps = {
6
+ onAudioRecorded: (audioBlob: Blob, messageText?: string) => void;
7
+ onClose: () => void;
8
+ inputMessage?: string;
9
+ };
10
+ declare function AudioRecorder({ onAudioRecorded, onClose, inputMessage, }: AudioRecorderProps): react_jsx_runtime.JSX.Element;
11
+
12
+ type VideoDialogProps = {
13
+ videoRef: RefObject<HTMLVideoElement>;
14
+ isRecording: boolean;
15
+ recordingTime: number;
16
+ loading: boolean;
17
+ onStartRecording: () => void;
18
+ onStopRecording: () => void;
19
+ onClose: () => void;
20
+ open: boolean;
21
+ };
22
+ declare function VideoDialog({ videoRef, isRecording, recordingTime, loading, onStartRecording, onStopRecording, onClose, open, }: VideoDialogProps): react_jsx_runtime.JSX.Element;
23
+
24
+ type ImageDialogProps = {
25
+ url: string;
26
+ alt?: string;
27
+ open: boolean;
28
+ onClose: () => void;
29
+ };
30
+ declare function ImageDialog({ url, alt, open, onClose }: ImageDialogProps): react_jsx_runtime.JSX.Element;
31
+
32
+ type CarouselImage = {
33
+ src: string;
34
+ alt: string;
35
+ };
36
+ type CarouselImageDialogProps = {
37
+ images: CarouselImage[];
38
+ initialIndex?: number;
39
+ open: boolean;
40
+ onClose: () => void;
41
+ };
42
+ declare function CarouselImageDialog({ images, initialIndex, open, onClose, }: CarouselImageDialogProps): react_jsx_runtime.JSX.Element;
43
+
44
+ type CameraDialogProps = {
45
+ videoRef: RefObject<HTMLVideoElement>;
46
+ canvasRef: RefObject<HTMLCanvasElement>;
47
+ onCapture: () => void;
48
+ onClose: () => void;
49
+ open: boolean;
50
+ };
51
+ declare function CameraDialog({ videoRef, canvasRef, onCapture, onClose, open, }: CameraDialogProps): react_jsx_runtime.JSX.Element;
52
+
53
+ type LocationDialogProps = {
54
+ locationError: string;
55
+ currentLocation: {
56
+ latitude: number;
57
+ longitude: number;
58
+ address?: string;
59
+ } | null;
60
+ loading: boolean;
61
+ onShare: () => void;
62
+ onClose: () => void;
63
+ };
64
+ declare function LocationDialog({ locationError, currentLocation, loading, onShare, onClose, }: LocationDialogProps): react_jsx_runtime.JSX.Element;
65
+
66
+ type ChatMessageProps = {
67
+ id: string;
68
+ role: "user" | "assistant";
69
+ content: string;
70
+ type?: "text" | "image" | "video" | "audio" | "location" | "actions" | "links" | "tool" | "payment" | "file";
71
+ image?: string;
72
+ video?: string;
73
+ audio?: string;
74
+ mimeType?: string;
75
+ text?: string;
76
+ location?: {
77
+ latitude: number;
78
+ longitude: number;
79
+ address?: string;
80
+ };
81
+ url?: string;
82
+ waitingMessage?: string;
83
+ isUploading?: boolean;
84
+ uploadProgress?: number;
85
+ createdAt: string;
86
+ onSelect?: (text: string) => void;
87
+ luaApiUrl?: string;
88
+ };
89
+ declare const ChatMessage: react.NamedExoticComponent<{
90
+ message: ChatMessageProps;
91
+ onSelect?: (text: string) => void;
92
+ luaApiUrl?: string;
93
+ authToken?: string;
94
+ disablePreviewOnLinks?: boolean;
95
+ onNavigate?: (pathname: string, options: {
96
+ query: Record<string, string>;
97
+ }) => void;
98
+ }>;
99
+
100
+ type CodeBlockProps = {
101
+ children: ReactNode;
102
+ className?: string;
103
+ language?: string;
104
+ };
105
+ declare function CodeBlock({ children, language }: CodeBlockProps): react_jsx_runtime.JSX.Element;
106
+
107
+ declare function LoadingMessage$1(): react_jsx_runtime.JSX.Element | null;
108
+
109
+ type ActionButton = {
110
+ text: string;
111
+ onClick: string;
112
+ };
113
+
114
+ type ActionMessageProps = {
115
+ buttons: ActionButton[];
116
+ onClick: (text: string) => void;
117
+ };
118
+ declare function ActionMessage({ buttons, onClick }: ActionMessageProps): react_jsx_runtime.JSX.Element;
119
+
120
+ type ChatActions = {
121
+ onSelect: (text: string) => void;
122
+ };
123
+ declare function ChatActions({ onSelect }: ChatActions): react_jsx_runtime.JSX.Element | null;
124
+
125
+ type AudioPreviewProps = {
126
+ message: {
127
+ audio?: string;
128
+ content: string;
129
+ isUploading?: boolean;
130
+ url?: string;
131
+ };
132
+ };
133
+ declare function AudioPreview({ message }: AudioPreviewProps): react_jsx_runtime.JSX.Element;
134
+
135
+ type PaymentPreviewProps = {
136
+ url: string;
137
+ };
138
+ declare function PaymentPreview({ url }: PaymentPreviewProps): react_jsx_runtime.JSX.Element;
139
+
140
+ type ChatInputProps = {
141
+ loading: boolean;
142
+ disabled: boolean;
143
+ onSend: () => void;
144
+ onFilePaste?: (files: File[]) => void;
145
+ };
146
+ declare const ChatInput: react.NamedExoticComponent<ChatInputProps>;
147
+
148
+ type FileMetadata = {
149
+ file: File;
150
+ url: string;
151
+ type: "image" | "video" | "audio" | "document" | "archive" | "other";
152
+ mimeType: string;
153
+ propertyName: "image" | "data";
154
+ };
155
+ type FilePreviewProps = {
156
+ files: File[];
157
+ onRemove: (index: number) => void;
158
+ cdnUrl: string;
159
+ fileMetadata?: FileMetadata[];
160
+ onFileUploadComplete?: (file: File, url: string) => void;
161
+ };
162
+ declare function FilePreview({ files, onRemove, cdnUrl, fileMetadata, onFileUploadComplete, }: FilePreviewProps): react_jsx_runtime.JSX.Element | null;
163
+
164
+ type FilePreviewCardProps = {
165
+ file: File;
166
+ onRemove: () => void;
167
+ cdnUrl: string;
168
+ initialUrl?: string;
169
+ onUploadComplete?: (file: File, url: string) => void;
170
+ };
171
+ declare function FilePreviewCard({ file, onRemove, cdnUrl, initialUrl, onUploadComplete, }: FilePreviewCardProps): react_jsx_runtime.JSX.Element;
172
+
173
+ type ToolbarProps = {
174
+ loading: boolean;
175
+ onFileClick: () => void;
176
+ onCameraClick: () => void;
177
+ onVideoClick: () => void;
178
+ onAudioClick: () => void;
179
+ onLocationClick: () => void;
180
+ onSendClick: () => void;
181
+ uploadProgress: number;
182
+ };
183
+ declare function Toolbar({ loading, onFileClick, onCameraClick, onVideoClick, onAudioClick, onLocationClick, onSendClick, }: ToolbarProps): react_jsx_runtime.JSX.Element;
184
+
185
+ declare const parseActions: (content: string) => ActionButton[];
186
+
187
+ declare const markdownStyles: {
188
+ p: string;
189
+ h1: string;
190
+ h2: string;
191
+ h3: string;
192
+ h4: string;
193
+ ul: string;
194
+ ol: string;
195
+ li: string;
196
+ a: string;
197
+ blockquote: string;
198
+ pre: string;
199
+ code: string;
200
+ img: string;
201
+ table: string;
202
+ th: string;
203
+ td: string;
204
+ };
205
+
206
+ declare function uploadFile(file: File, cdnUrl: string, onProgress?: (progress: number) => void): Promise<{
207
+ fileId: string;
208
+ }>;
209
+
210
+ type Message = {
211
+ id: string;
212
+ role: "user" | "assistant";
213
+ content: string;
214
+ type?: "text" | "image" | "video" | "audio" | "location" | "tool" | "file";
215
+ url?: string;
216
+ image?: string;
217
+ video?: string;
218
+ audio?: string;
219
+ location?: {
220
+ latitude: number;
221
+ longitude: number;
222
+ address?: string;
223
+ };
224
+ waitingMessage?: string;
225
+ isUploading?: boolean;
226
+ createdAt: string;
227
+ data?: string;
228
+ mimeType?: string;
229
+ uploadProgress?: number;
230
+ };
231
+ type LoadingMessage = string | null;
232
+ type ChatContextType = {
233
+ messages: Message[];
234
+ setMessages: React.Dispatch<React.SetStateAction<Message[]>>;
235
+ inputMessage: string;
236
+ setInputMessage: React.Dispatch<React.SetStateAction<string>>;
237
+ loadingMessage: LoadingMessage | null;
238
+ setLoadingMessage: React.Dispatch<React.SetStateAction<LoadingMessage | null>>;
239
+ hasUnreadMessages: boolean;
240
+ setHasUnreadMessages: React.Dispatch<React.SetStateAction<boolean>>;
241
+ getFileUrl: (file: File) => string;
242
+ removeFileUrl: (file: File) => void;
243
+ };
244
+ declare function ChatProvider({ children }: {
245
+ children: ReactNode;
246
+ }): react_jsx_runtime.JSX.Element;
247
+ declare function useMessages(): {
248
+ messages: Message[];
249
+ setMessages: React.Dispatch<React.SetStateAction<Message[]>>;
250
+ };
251
+ declare function useInput(): {
252
+ inputMessage: string;
253
+ setInputMessage: React.Dispatch<React.SetStateAction<string>>;
254
+ };
255
+ declare function useLoadingMessage(): {
256
+ loadingMessage: LoadingMessage | null;
257
+ setLoadingMessage: React.Dispatch<React.SetStateAction<LoadingMessage | null>>;
258
+ };
259
+ declare function useFileUrls(): {
260
+ getFileUrl: (file: File) => string;
261
+ removeFileUrl: (file: File) => void;
262
+ };
263
+ declare function useUnreadMessages(): {
264
+ hasUnreadMessages: boolean;
265
+ setHasUnreadMessages: React.Dispatch<React.SetStateAction<boolean>>;
266
+ };
267
+ declare function useChat(): ChatContextType;
268
+
269
+ export { type ActionButton, ActionMessage, AudioPreview, AudioRecorder, CameraDialog, CarouselImageDialog, ChatActions, ChatInput, ChatMessage, type ChatMessageProps, ChatProvider, CodeBlock, type FileMetadata, FilePreview, FilePreviewCard, ImageDialog, LoadingMessage$1 as LoadingMessage, LocationDialog, PaymentPreview, Toolbar, VideoDialog, markdownStyles, parseActions, uploadFile, useChat, useFileUrls, useInput, useLoadingMessage, useMessages, useUnreadMessages };