@libreapps/react 1.1.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/LICENSE.md +21 -0
- package/README.md +347 -0
- package/dist/index.d.mts +255 -0
- package/dist/index.d.ts +255 -0
- package/dist/index.js +548 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +539 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +100 -0
- package/src/components/LibreAppsProvider.test.tsx +346 -0
- package/src/components/LibreAppsProvider.tsx +508 -0
- package/src/hooks/index.ts +39 -0
- package/src/hooks/types.ts +162 -0
- package/src/hooks/useAttachments.ts +0 -0
- package/src/hooks/useAuth.ts +0 -0
- package/src/hooks/useComponent.ts +0 -0
- package/src/hooks/useGenerativeUI.ts +0 -0
- package/src/hooks/useMCP.ts +0 -0
- package/src/hooks/useMessage.ts +105 -0
- package/src/hooks/useModelConfig.ts +0 -0
- package/src/hooks/useStreaming.ts +161 -0
- package/src/hooks/useSuggestions.ts +0 -0
- package/src/hooks/useThread.ts +0 -0
- package/src/hooks/useTool.ts +0 -0
- package/src/index.ts +40 -0
- package/src/types/index.ts +25 -0
- package/src/utils/cn.ts +6 -0
- package/src/utils/id.ts +6 -0
- package/src/utils/stream.ts +33 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LibreApps.com
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
# @libreapps/react
|
|
2
|
+
|
|
3
|
+
React package for building AI-powered applications with generative UI, where users interact through natural language.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🤖 **Generative UI** - Dynamically render React components in AI responses
|
|
8
|
+
- 🔄 **Real-time Streaming** - Stream AI responses with progress tracking
|
|
9
|
+
- 💬 **Message Threads** - Manage conversation history and context
|
|
10
|
+
- 🛠️ **Tool Calling** - Let AI execute functions during conversations
|
|
11
|
+
- 🔌 **Model Context Protocol** - MCP integration for enhanced AI capabilities
|
|
12
|
+
- 🎨 **Component Registry** - Register custom components for AI to use
|
|
13
|
+
- 🔐 **Authentication** - Built-in auth support for user management
|
|
14
|
+
- 📎 **File Attachments** - Handle images, documents, and other files
|
|
15
|
+
- 💡 **Smart Suggestions** - Provide contextual suggestions to users
|
|
16
|
+
- ⚡ **TypeScript Support** - Full type safety and IntelliSense
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @libreapps/react
|
|
22
|
+
# or
|
|
23
|
+
pnpm add @libreapps/react
|
|
24
|
+
# or
|
|
25
|
+
yarn add @libreapps/react
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { LibreAppsProvider, useMessage } from '@libreapps/react'
|
|
32
|
+
|
|
33
|
+
function App() {
|
|
34
|
+
return (
|
|
35
|
+
<LibreAppsProvider apiKey={process.env.LIBREAPPS_API_KEY}>
|
|
36
|
+
<ChatInterface />
|
|
37
|
+
</LibreAppsProvider>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function ChatInterface() {
|
|
42
|
+
const { sendMessage, isLoading, lastMessage } = useMessage()
|
|
43
|
+
|
|
44
|
+
const handleSubmit = async (text: string) => {
|
|
45
|
+
const response = await sendMessage(text)
|
|
46
|
+
console.log('AI Response:', response)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div>
|
|
51
|
+
<input onKeyDown={(e) => {
|
|
52
|
+
if (e.key === 'Enter') {
|
|
53
|
+
handleSubmit(e.currentTarget.value)
|
|
54
|
+
}
|
|
55
|
+
}} />
|
|
56
|
+
{isLoading && <p>Loading...</p>}
|
|
57
|
+
{lastMessage && <div>{lastMessage.content}</div>}
|
|
58
|
+
</div>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Core Concepts
|
|
64
|
+
|
|
65
|
+
### LibreAppsProvider
|
|
66
|
+
|
|
67
|
+
The root component that provides LibreApps context to your app:
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
<LibreAppsProvider
|
|
71
|
+
apiKey="your-api-key"
|
|
72
|
+
apiUrl="https://api.libreapps.com/v1"
|
|
73
|
+
model="gpt-4-turbo-preview"
|
|
74
|
+
components={[/* your components */]}
|
|
75
|
+
tools={[/* your tools */]}
|
|
76
|
+
enableStreaming={true}
|
|
77
|
+
enableMCP={true}
|
|
78
|
+
onMessage={(message) => console.log('New message:', message)}
|
|
79
|
+
onError={(error) => console.error('Error:', error)}
|
|
80
|
+
>
|
|
81
|
+
<YourApp />
|
|
82
|
+
</LibreAppsProvider>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Generative UI Components
|
|
86
|
+
|
|
87
|
+
Register components that AI can dynamically render:
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
const components = [
|
|
91
|
+
{
|
|
92
|
+
name: 'weather-card',
|
|
93
|
+
component: WeatherCard,
|
|
94
|
+
description: 'Display weather information',
|
|
95
|
+
parameters: z.object({
|
|
96
|
+
city: z.string(),
|
|
97
|
+
temperature: z.number(),
|
|
98
|
+
conditions: z.string()
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
|
|
103
|
+
<LibreAppsProvider components={components}>
|
|
104
|
+
{/* AI can now render WeatherCard in responses */}
|
|
105
|
+
</LibreAppsProvider>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Message Hooks
|
|
109
|
+
|
|
110
|
+
Send messages and handle responses:
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
// Basic messaging
|
|
114
|
+
const { sendMessage, isLoading, error } = useMessage()
|
|
115
|
+
|
|
116
|
+
// Streaming responses
|
|
117
|
+
const { streamMessage, currentMessage, progress } = useStreaming()
|
|
118
|
+
|
|
119
|
+
// Thread management
|
|
120
|
+
const { threads, activeThread, createThread, switchThread } = useThread()
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Tool Calling
|
|
124
|
+
|
|
125
|
+
Add tools that AI can execute:
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
const tools = [
|
|
129
|
+
{
|
|
130
|
+
name: 'calculator',
|
|
131
|
+
description: 'Perform calculations',
|
|
132
|
+
parameters: z.object({
|
|
133
|
+
expression: z.string()
|
|
134
|
+
}),
|
|
135
|
+
execute: async ({ expression }) => {
|
|
136
|
+
return { result: eval(expression) }
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
]
|
|
140
|
+
|
|
141
|
+
<LibreAppsProvider tools={tools}>
|
|
142
|
+
{/* AI can now use the calculator tool */}
|
|
143
|
+
</LibreAppsProvider>
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Available Hooks
|
|
147
|
+
|
|
148
|
+
### Core Hooks
|
|
149
|
+
- `useLibreApps()` - Access complete LibreApps context
|
|
150
|
+
- `useMessage()` - Send messages and manage state
|
|
151
|
+
- `useStreaming()` - Stream AI responses in real-time
|
|
152
|
+
- `useThread()` - Manage conversation threads
|
|
153
|
+
|
|
154
|
+
### Component & Tool Hooks
|
|
155
|
+
- `useComponent()` - Dynamically register/render components
|
|
156
|
+
- `useTool()` - Execute and manage AI tools
|
|
157
|
+
- `useGenerativeUI()` - Generate UI components on the fly
|
|
158
|
+
|
|
159
|
+
### Utility Hooks
|
|
160
|
+
- `useSuggestions()` - Provide intelligent suggestions
|
|
161
|
+
- `useModelConfig()` - Configure and switch AI models
|
|
162
|
+
- `useAttachments()` - Handle file attachments
|
|
163
|
+
- `useAuth()` - Manage user authentication
|
|
164
|
+
- `useMCP()` - Model Context Protocol integration
|
|
165
|
+
|
|
166
|
+
## Examples
|
|
167
|
+
|
|
168
|
+
### Chat Application
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
import { LibreAppsProvider, useMessage, useStreaming } from '@libreapps/react'
|
|
172
|
+
|
|
173
|
+
function ChatApp() {
|
|
174
|
+
const [messages, setMessages] = useState([])
|
|
175
|
+
const { sendMessage } = useMessage()
|
|
176
|
+
const { streamMessage, currentMessage, isStreaming } = useStreaming()
|
|
177
|
+
|
|
178
|
+
const handleSend = async (text: string) => {
|
|
179
|
+
// Add user message
|
|
180
|
+
setMessages(prev => [...prev, { role: 'user', content: text }])
|
|
181
|
+
|
|
182
|
+
// Stream AI response
|
|
183
|
+
await streamMessage(text)
|
|
184
|
+
|
|
185
|
+
// Add AI message when complete
|
|
186
|
+
setMessages(prev => [...prev, {
|
|
187
|
+
role: 'assistant',
|
|
188
|
+
content: currentMessage
|
|
189
|
+
}])
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<div>
|
|
194
|
+
{messages.map((msg, i) => (
|
|
195
|
+
<div key={i} className={msg.role}>
|
|
196
|
+
{msg.content}
|
|
197
|
+
</div>
|
|
198
|
+
))}
|
|
199
|
+
{isStreaming && <div>{currentMessage}</div>}
|
|
200
|
+
</div>
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Custom Components
|
|
206
|
+
|
|
207
|
+
```tsx
|
|
208
|
+
// Define a custom visualization component
|
|
209
|
+
function DataChart({ data, type }) {
|
|
210
|
+
return <Chart data={data} type={type} />
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Register it with LibreApps
|
|
214
|
+
const components = [
|
|
215
|
+
{
|
|
216
|
+
name: 'data-chart',
|
|
217
|
+
component: DataChart,
|
|
218
|
+
description: 'Visualize data in a chart',
|
|
219
|
+
parameters: z.object({
|
|
220
|
+
data: z.array(z.number()),
|
|
221
|
+
type: z.enum(['bar', 'line', 'pie'])
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
]
|
|
225
|
+
|
|
226
|
+
// Use in your app
|
|
227
|
+
<LibreAppsProvider components={components}>
|
|
228
|
+
<ChatInterface />
|
|
229
|
+
</LibreAppsProvider>
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Tool Integration
|
|
233
|
+
|
|
234
|
+
```tsx
|
|
235
|
+
const tools = [
|
|
236
|
+
{
|
|
237
|
+
name: 'fetchData',
|
|
238
|
+
description: 'Fetch data from API',
|
|
239
|
+
parameters: z.object({
|
|
240
|
+
endpoint: z.string().url()
|
|
241
|
+
}),
|
|
242
|
+
execute: async ({ endpoint }) => {
|
|
243
|
+
const response = await fetch(endpoint)
|
|
244
|
+
return response.json()
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
name: 'saveToDatabase',
|
|
249
|
+
description: 'Save data to database',
|
|
250
|
+
parameters: z.object({
|
|
251
|
+
collection: z.string(),
|
|
252
|
+
data: z.any()
|
|
253
|
+
}),
|
|
254
|
+
execute: async ({ collection, data }) => {
|
|
255
|
+
await db.collection(collection).insert(data)
|
|
256
|
+
return { success: true }
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
]
|
|
260
|
+
|
|
261
|
+
<LibreAppsProvider tools={tools}>
|
|
262
|
+
{/* AI can now fetch data and save to database */}
|
|
263
|
+
</LibreAppsProvider>
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## TypeScript
|
|
267
|
+
|
|
268
|
+
Full TypeScript support with type definitions:
|
|
269
|
+
|
|
270
|
+
```tsx
|
|
271
|
+
import type {
|
|
272
|
+
LibreAppsComponent,
|
|
273
|
+
LibreAppsTool,
|
|
274
|
+
Message,
|
|
275
|
+
Thread
|
|
276
|
+
} from '@libreapps/react'
|
|
277
|
+
|
|
278
|
+
const component: LibreAppsComponent = {
|
|
279
|
+
name: 'my-component',
|
|
280
|
+
component: MyComponent,
|
|
281
|
+
description: 'A typed component',
|
|
282
|
+
parameters: z.object({
|
|
283
|
+
title: z.string(),
|
|
284
|
+
count: z.number()
|
|
285
|
+
})
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const tool: LibreAppsTool = {
|
|
289
|
+
name: 'my-tool',
|
|
290
|
+
description: 'A typed tool',
|
|
291
|
+
parameters: z.object({
|
|
292
|
+
input: z.string()
|
|
293
|
+
}),
|
|
294
|
+
execute: async ({ input }) => {
|
|
295
|
+
return { processed: input.toUpperCase() }
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## API Reference
|
|
301
|
+
|
|
302
|
+
### LibreAppsProvider Props
|
|
303
|
+
|
|
304
|
+
| Prop | Type | Required | Default | Description |
|
|
305
|
+
|------|------|----------|---------|-------------|
|
|
306
|
+
| `apiKey` | `string` | Yes | - | Your LibreApps API key |
|
|
307
|
+
| `apiUrl` | `string` | No | `https://api.libreapps.com/v1` | API endpoint URL |
|
|
308
|
+
| `model` | `string` | No | `gpt-4-turbo-preview` | AI model to use |
|
|
309
|
+
| `components` | `LibreAppsComponent[]` | No | `[]` | Registered components |
|
|
310
|
+
| `tools` | `LibreAppsTool[]` | No | `[]` | Available tools |
|
|
311
|
+
| `initialMessages` | `Message[]` | No | `[]` | Initial conversation |
|
|
312
|
+
| `enableStreaming` | `boolean` | No | `true` | Enable streaming |
|
|
313
|
+
| `enableMCP` | `boolean` | No | `false` | Enable MCP |
|
|
314
|
+
| `onMessage` | `(message: Message) => void` | No | - | Message callback |
|
|
315
|
+
| `onError` | `(error: Error) => void` | No | - | Error callback |
|
|
316
|
+
|
|
317
|
+
### Hook Options
|
|
318
|
+
|
|
319
|
+
Most hooks accept configuration options:
|
|
320
|
+
|
|
321
|
+
```tsx
|
|
322
|
+
const { sendMessage } = useMessage({
|
|
323
|
+
threadId: 'custom-thread',
|
|
324
|
+
onSuccess: (message) => console.log('Sent:', message),
|
|
325
|
+
onError: (error) => console.error('Error:', error),
|
|
326
|
+
autoRetry: true,
|
|
327
|
+
maxRetries: 3,
|
|
328
|
+
retryDelay: 1000
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
const { streamMessage } = useStreaming({
|
|
332
|
+
onChunk: (chunk) => console.log('Chunk:', chunk),
|
|
333
|
+
onComplete: (message) => console.log('Complete:', message),
|
|
334
|
+
bufferSize: 5,
|
|
335
|
+
throttleMs: 100
|
|
336
|
+
})
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
## License
|
|
340
|
+
|
|
341
|
+
BSD-3-Clause © LibreApps AI, Inc.
|
|
342
|
+
|
|
343
|
+
## Support
|
|
344
|
+
|
|
345
|
+
- Documentation: [https://ui.libreapps.com/docs/libreapps-react](https://ui.libreapps.com/docs/libreapps-react)
|
|
346
|
+
- GitHub: [https://github.com/libre-apps/ui](https://github.com/libre-apps/ui)
|
|
347
|
+
- Discord: [https://discord.gg/libreapps](https://discord.gg/libreapps)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React$1 from 'react';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { ClassValue } from 'clsx';
|
|
5
|
+
|
|
6
|
+
interface LibreAppsComponent {
|
|
7
|
+
name: string;
|
|
8
|
+
component: React$1.ComponentType<any>;
|
|
9
|
+
description?: string;
|
|
10
|
+
parameters?: z.ZodType<any>;
|
|
11
|
+
generateUI?: (params: any) => React$1.ReactElement;
|
|
12
|
+
}
|
|
13
|
+
interface LibreAppsTool {
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
parameters: z.ZodType<any>;
|
|
17
|
+
execute: (params: any) => Promise<any>;
|
|
18
|
+
}
|
|
19
|
+
interface Message {
|
|
20
|
+
id: string;
|
|
21
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
22
|
+
content: string | React$1.ReactElement;
|
|
23
|
+
timestamp: Date;
|
|
24
|
+
threadId: string;
|
|
25
|
+
toolCalls?: ToolCall[];
|
|
26
|
+
metadata?: Record<string, any>;
|
|
27
|
+
}
|
|
28
|
+
interface ToolCall {
|
|
29
|
+
id: string;
|
|
30
|
+
name: string;
|
|
31
|
+
arguments: any;
|
|
32
|
+
result?: any;
|
|
33
|
+
status: 'pending' | 'running' | 'completed' | 'failed';
|
|
34
|
+
}
|
|
35
|
+
interface Thread {
|
|
36
|
+
id: string;
|
|
37
|
+
messages: Message[];
|
|
38
|
+
createdAt: Date;
|
|
39
|
+
updatedAt: Date;
|
|
40
|
+
metadata?: Record<string, any>;
|
|
41
|
+
}
|
|
42
|
+
interface LibreAppsContextValue {
|
|
43
|
+
apiKey?: string;
|
|
44
|
+
apiUrl?: string;
|
|
45
|
+
model?: string;
|
|
46
|
+
components: Map<string, LibreAppsComponent>;
|
|
47
|
+
tools: Map<string, LibreAppsTool>;
|
|
48
|
+
threads: Map<string, Thread>;
|
|
49
|
+
activeThreadId?: string;
|
|
50
|
+
sendMessage: (content: string, threadId?: string) => Promise<Message>;
|
|
51
|
+
streamMessage: (content: string, threadId?: string) => AsyncGenerator<Message>;
|
|
52
|
+
createThread: (metadata?: Record<string, any>) => Thread;
|
|
53
|
+
switchThread: (threadId: string) => void;
|
|
54
|
+
deleteThread: (threadId: string) => void;
|
|
55
|
+
registerComponent: (component: LibreAppsComponent) => void;
|
|
56
|
+
unregisterComponent: (name: string) => void;
|
|
57
|
+
renderComponent: (name: string, props: any) => React$1.ReactElement | null;
|
|
58
|
+
registerTool: (tool: LibreAppsTool) => void;
|
|
59
|
+
unregisterTool: (name: string) => void;
|
|
60
|
+
executeTool: (name: string, params: any) => Promise<any>;
|
|
61
|
+
isStreaming: boolean;
|
|
62
|
+
responseStage?: 'thinking' | 'generating' | 'tool-calling' | 'completed';
|
|
63
|
+
error?: Error;
|
|
64
|
+
}
|
|
65
|
+
interface LibreAppsProviderProps {
|
|
66
|
+
children: React$1.ReactNode;
|
|
67
|
+
apiKey?: string;
|
|
68
|
+
apiUrl?: string;
|
|
69
|
+
model?: string;
|
|
70
|
+
components?: LibreAppsComponent[];
|
|
71
|
+
tools?: LibreAppsTool[];
|
|
72
|
+
initialMessages?: Message[];
|
|
73
|
+
onMessage?: (message: Message) => void;
|
|
74
|
+
onError?: (error: Error) => void;
|
|
75
|
+
enableStreaming?: boolean;
|
|
76
|
+
enableMCP?: boolean;
|
|
77
|
+
mcpServers?: string[];
|
|
78
|
+
}
|
|
79
|
+
declare function LibreAppsProvider({ children, apiKey, apiUrl, model, components: initialComponents, tools: initialTools, initialMessages, onMessage, onError, enableStreaming, enableMCP, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
80
|
+
mcpServers }: LibreAppsProviderProps): react_jsx_runtime.JSX.Element;
|
|
81
|
+
declare function useLibreApps(): LibreAppsContextValue;
|
|
82
|
+
|
|
83
|
+
interface UseMessageOptions {
|
|
84
|
+
threadId?: string;
|
|
85
|
+
onSuccess?: (message: Message) => void;
|
|
86
|
+
onError?: (error: Error) => void;
|
|
87
|
+
autoRetry?: boolean;
|
|
88
|
+
maxRetries?: number;
|
|
89
|
+
retryDelay?: number;
|
|
90
|
+
}
|
|
91
|
+
interface UseMessageReturn {
|
|
92
|
+
sendMessage: (content: string) => Promise<Message>;
|
|
93
|
+
sendMessageWithAttachments: (content: string, attachments: File[]) => Promise<Message>;
|
|
94
|
+
isLoading: boolean;
|
|
95
|
+
error: Error | null;
|
|
96
|
+
lastMessage: Message | null;
|
|
97
|
+
clearError: () => void;
|
|
98
|
+
retry: () => Promise<void>;
|
|
99
|
+
}
|
|
100
|
+
declare function useMessage(options?: UseMessageOptions): UseMessageReturn;
|
|
101
|
+
|
|
102
|
+
interface UseStreamingOptions {
|
|
103
|
+
threadId?: string;
|
|
104
|
+
onChunk?: (chunk: string) => void;
|
|
105
|
+
onComplete?: (message: Message) => void;
|
|
106
|
+
onError?: (error: Error) => void;
|
|
107
|
+
bufferSize?: number;
|
|
108
|
+
throttleMs?: number;
|
|
109
|
+
}
|
|
110
|
+
interface UseStreamingReturn {
|
|
111
|
+
streamMessage: (content: string) => Promise<void>;
|
|
112
|
+
isStreaming: boolean;
|
|
113
|
+
currentMessage: string;
|
|
114
|
+
error: Error | null;
|
|
115
|
+
stopStreaming: () => void;
|
|
116
|
+
clearMessage: () => void;
|
|
117
|
+
progress: number;
|
|
118
|
+
}
|
|
119
|
+
declare function useStreaming(options?: UseStreamingOptions): UseStreamingReturn;
|
|
120
|
+
|
|
121
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
122
|
+
|
|
123
|
+
declare function generateId(prefix?: string): string;
|
|
124
|
+
|
|
125
|
+
declare function parseStream(stream: ReadableStream<Uint8Array>): Promise<string>;
|
|
126
|
+
|
|
127
|
+
interface UseThreadOptions {
|
|
128
|
+
maxThreads?: number;
|
|
129
|
+
autoArchive?: boolean;
|
|
130
|
+
}
|
|
131
|
+
interface UseThreadReturn {
|
|
132
|
+
threads: Map<string, any>;
|
|
133
|
+
activeThread: any | undefined;
|
|
134
|
+
createThread: (metadata?: Record<string, any>) => any;
|
|
135
|
+
switchThread: (threadId: string) => void;
|
|
136
|
+
deleteThread: (threadId: string) => void;
|
|
137
|
+
updateThreadMetadata: (threadId: string, metadata: Record<string, any>) => void;
|
|
138
|
+
getThreadMessages: (threadId: string) => any[];
|
|
139
|
+
clearThread: (threadId: string) => void;
|
|
140
|
+
}
|
|
141
|
+
interface UseComponentOptions {
|
|
142
|
+
lazy?: boolean;
|
|
143
|
+
}
|
|
144
|
+
interface UseComponentReturn {
|
|
145
|
+
registerComponent: (component: any) => void;
|
|
146
|
+
unregisterComponent: (name: string) => void;
|
|
147
|
+
renderComponent: (name: string, props: any) => React.ReactElement | null;
|
|
148
|
+
getComponent: (name: string) => any | undefined;
|
|
149
|
+
hasComponent: (name: string) => boolean;
|
|
150
|
+
listComponents: () => string[];
|
|
151
|
+
}
|
|
152
|
+
interface UseToolOptions {
|
|
153
|
+
timeout?: number;
|
|
154
|
+
}
|
|
155
|
+
interface UseToolReturn {
|
|
156
|
+
executeTool: (name: string, params: any) => Promise<any>;
|
|
157
|
+
registerTool: (tool: any) => void;
|
|
158
|
+
unregisterTool: (name: string) => void;
|
|
159
|
+
isExecuting: boolean;
|
|
160
|
+
lastResult: any | null;
|
|
161
|
+
error: Error | null;
|
|
162
|
+
}
|
|
163
|
+
interface UseSuggestionsOptions {
|
|
164
|
+
maxSuggestions?: number;
|
|
165
|
+
autoRefresh?: boolean;
|
|
166
|
+
refreshInterval?: number;
|
|
167
|
+
}
|
|
168
|
+
interface UseSuggestionsReturn {
|
|
169
|
+
suggestions: any[];
|
|
170
|
+
getSuggestions: (options?: any) => Promise<void>;
|
|
171
|
+
acceptSuggestion: (suggestion: any) => void;
|
|
172
|
+
dismissSuggestion: (id: string) => void;
|
|
173
|
+
isLoading: boolean;
|
|
174
|
+
}
|
|
175
|
+
interface UseModelConfigOptions {
|
|
176
|
+
defaultModel?: string;
|
|
177
|
+
}
|
|
178
|
+
interface UseModelConfigReturn {
|
|
179
|
+
currentModel: string;
|
|
180
|
+
availableModels: any[];
|
|
181
|
+
switchModel: (modelId: string) => void;
|
|
182
|
+
updateParameters: (params: any) => void;
|
|
183
|
+
resetToDefaults: () => void;
|
|
184
|
+
}
|
|
185
|
+
interface UseMCPOptions {
|
|
186
|
+
autoConnect?: boolean;
|
|
187
|
+
}
|
|
188
|
+
interface UseMCPReturn {
|
|
189
|
+
connectServer: (config: any) => Promise<void>;
|
|
190
|
+
disconnectServer: (id: string) => void;
|
|
191
|
+
connectedServers: any[];
|
|
192
|
+
executeServerTool: (serverId: string, tool: string, params: any) => Promise<any>;
|
|
193
|
+
getServerResources: (serverId: string) => any[];
|
|
194
|
+
isConnected: (serverId: string) => boolean;
|
|
195
|
+
}
|
|
196
|
+
interface UseGenerativeUIOptions {
|
|
197
|
+
cacheResults?: boolean;
|
|
198
|
+
}
|
|
199
|
+
interface UseGenerativeUIReturn {
|
|
200
|
+
generateUI: (options: any) => Promise<React.ReactElement>;
|
|
201
|
+
isGenerating: boolean;
|
|
202
|
+
generatedComponents: React.ReactElement[];
|
|
203
|
+
clearComponents: () => void;
|
|
204
|
+
saveComponent: (name: string, component: React.ReactElement) => void;
|
|
205
|
+
}
|
|
206
|
+
interface UseAuthOptions {
|
|
207
|
+
provider?: string;
|
|
208
|
+
}
|
|
209
|
+
interface UseAuthReturn {
|
|
210
|
+
user: any | null;
|
|
211
|
+
isAuthenticated: boolean;
|
|
212
|
+
isLoading: boolean;
|
|
213
|
+
signIn: (options?: any) => Promise<void>;
|
|
214
|
+
signOut: () => Promise<void>;
|
|
215
|
+
getToken: () => Promise<string | null>;
|
|
216
|
+
refreshToken: () => Promise<void>;
|
|
217
|
+
}
|
|
218
|
+
interface UseAttachmentsOptions {
|
|
219
|
+
maxSize?: number;
|
|
220
|
+
allowedTypes?: string[];
|
|
221
|
+
autoUpload?: boolean;
|
|
222
|
+
}
|
|
223
|
+
interface UseAttachmentsReturn {
|
|
224
|
+
attachments: any[];
|
|
225
|
+
addAttachment: (file: File) => Promise<any>;
|
|
226
|
+
removeAttachment: (id: string) => void;
|
|
227
|
+
clearAttachments: () => void;
|
|
228
|
+
uploadAttachment: (attachment: any) => Promise<void>;
|
|
229
|
+
isUploading: boolean;
|
|
230
|
+
uploadProgress: number;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
interface Suggestion {
|
|
234
|
+
id: string;
|
|
235
|
+
text: string;
|
|
236
|
+
metadata?: Record<string, any>;
|
|
237
|
+
}
|
|
238
|
+
interface Model {
|
|
239
|
+
id: string;
|
|
240
|
+
name: string;
|
|
241
|
+
description: string;
|
|
242
|
+
parameters?: Record<string, any>;
|
|
243
|
+
}
|
|
244
|
+
interface Attachment {
|
|
245
|
+
id: string;
|
|
246
|
+
name: string;
|
|
247
|
+
size: number;
|
|
248
|
+
type: string;
|
|
249
|
+
url?: string;
|
|
250
|
+
file?: File;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
declare const VERSION = "1.0.0";
|
|
254
|
+
|
|
255
|
+
export { type Attachment, type LibreAppsComponent, type LibreAppsContextValue, LibreAppsProvider, type LibreAppsProviderProps, type LibreAppsTool, type Message, type Model, type Suggestion, type Thread, type ToolCall, type UseAttachmentsOptions, type UseAttachmentsReturn, type UseAuthOptions, type UseAuthReturn, type UseComponentOptions, type UseComponentReturn, type UseGenerativeUIOptions, type UseGenerativeUIReturn, type UseMCPOptions, type UseMCPReturn, type UseMessageOptions, type UseMessageReturn, type UseModelConfigOptions, type UseModelConfigReturn, type UseStreamingOptions, type UseStreamingReturn, type UseSuggestionsOptions, type UseSuggestionsReturn, type UseThreadOptions, type UseThreadReturn, type UseToolOptions, type UseToolReturn, VERSION, cn, generateId, parseStream, useLibreApps, useMessage, useStreaming };
|