@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/dist/index.d.ts
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 };
|