@chainlit/react-client 0.1.0 → 0.1.2
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 +13 -10
- package/dist/index.d.mts +148 -71
- package/dist/index.d.ts +148 -71
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,11 +17,19 @@ import React from 'react';
|
|
|
17
17
|
import ReactDOM from 'react-dom/client';
|
|
18
18
|
import { RecoilRoot } from 'recoil';
|
|
19
19
|
|
|
20
|
+
import { ChainlitAPI, ChainlitContext } from '@chainlit/react-client';
|
|
21
|
+
|
|
22
|
+
const CHAINLIT_SERVER_URL = 'http://localhost:8000';
|
|
23
|
+
|
|
24
|
+
const apiClient = new ChainlitAPI(CHAINLIT_SERVER_URL, 'webapp');
|
|
25
|
+
|
|
20
26
|
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
|
|
21
27
|
<React.StrictMode>
|
|
22
|
-
<
|
|
23
|
-
<
|
|
24
|
-
|
|
28
|
+
<ChainlitContext.Provider value={apiClient}>
|
|
29
|
+
<RecoilRoot>
|
|
30
|
+
<MyApp />
|
|
31
|
+
</RecoilRoot>
|
|
32
|
+
</ChainlitContext.Provider>
|
|
25
33
|
</React.StrictMode>
|
|
26
34
|
);
|
|
27
35
|
```
|
|
@@ -41,11 +49,7 @@ This hook is responsible for managing the chat session's connection to the WebSo
|
|
|
41
49
|
#### Example
|
|
42
50
|
|
|
43
51
|
```jsx
|
|
44
|
-
import {
|
|
45
|
-
|
|
46
|
-
const CHAINLIT_SERVER_URL = 'http://localhost:8000';
|
|
47
|
-
|
|
48
|
-
const apiClient = new ChainlitAPI(CHAINLIT_SERVER_URL, 'app');
|
|
52
|
+
import { useChatSession } from '@chainlit/react-client';
|
|
49
53
|
|
|
50
54
|
const ChatComponent = () => {
|
|
51
55
|
const { connect, disconnect, chatProfile, setChatProfile } = useChatSession();
|
|
@@ -53,7 +57,6 @@ const ChatComponent = () => {
|
|
|
53
57
|
// Connect to the WebSocket server
|
|
54
58
|
useEffect(() => {
|
|
55
59
|
connect({
|
|
56
|
-
client: apiClient,
|
|
57
60
|
userEnv: {
|
|
58
61
|
/* user environment variables */
|
|
59
62
|
},
|
|
@@ -63,7 +66,7 @@ const ChatComponent = () => {
|
|
|
63
66
|
return () => {
|
|
64
67
|
disconnect();
|
|
65
68
|
};
|
|
66
|
-
}, [
|
|
69
|
+
}, []);
|
|
67
70
|
|
|
68
71
|
// Rest of your component logic
|
|
69
72
|
};
|
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,7 @@ import * as recoil from 'recoil';
|
|
|
2
2
|
import { Socket } from 'socket.io-client';
|
|
3
3
|
export { Socket } from 'socket.io-client';
|
|
4
4
|
import * as lodash from 'lodash';
|
|
5
|
+
import * as react from 'react';
|
|
5
6
|
import * as swr__internal from 'swr/_internal';
|
|
6
7
|
import { SWRConfiguration } from 'swr';
|
|
7
8
|
|
|
@@ -148,6 +149,59 @@ type ThreadHistory = {
|
|
|
148
149
|
pageInfo?: IPageInfo;
|
|
149
150
|
};
|
|
150
151
|
|
|
152
|
+
interface IStarter {
|
|
153
|
+
label: string;
|
|
154
|
+
message: string;
|
|
155
|
+
icon?: string;
|
|
156
|
+
}
|
|
157
|
+
interface ChatProfile {
|
|
158
|
+
default: boolean;
|
|
159
|
+
icon?: string;
|
|
160
|
+
name: string;
|
|
161
|
+
markdown_description: string;
|
|
162
|
+
starters?: IStarter[];
|
|
163
|
+
}
|
|
164
|
+
interface IAudioConfig {
|
|
165
|
+
enabled: boolean;
|
|
166
|
+
min_decibels: number;
|
|
167
|
+
initial_silence_timeout: number;
|
|
168
|
+
silence_timeout: number;
|
|
169
|
+
chunk_duration: number;
|
|
170
|
+
max_duration: number;
|
|
171
|
+
}
|
|
172
|
+
interface IChainlitConfig {
|
|
173
|
+
markdown?: string;
|
|
174
|
+
ui: {
|
|
175
|
+
name: string;
|
|
176
|
+
description?: string;
|
|
177
|
+
default_collapse_content?: boolean;
|
|
178
|
+
github?: string;
|
|
179
|
+
theme: any;
|
|
180
|
+
custom_css?: string;
|
|
181
|
+
custom_js?: string;
|
|
182
|
+
custom_font?: string;
|
|
183
|
+
custom_meta_image_url?: string;
|
|
184
|
+
};
|
|
185
|
+
features: {
|
|
186
|
+
spontaneous_file_upload?: {
|
|
187
|
+
enabled?: boolean;
|
|
188
|
+
max_size_mb?: number;
|
|
189
|
+
max_files?: number;
|
|
190
|
+
accept?: string[] | Record<string, string[]>;
|
|
191
|
+
};
|
|
192
|
+
audio: IAudioConfig;
|
|
193
|
+
unsafe_allow_html?: boolean;
|
|
194
|
+
latex?: boolean;
|
|
195
|
+
};
|
|
196
|
+
debugUrl?: string;
|
|
197
|
+
userEnv: string[];
|
|
198
|
+
dataPersistence: boolean;
|
|
199
|
+
threadResumable: boolean;
|
|
200
|
+
chatProfiles: ChatProfile[];
|
|
201
|
+
starters?: IStarter[];
|
|
202
|
+
translation: object;
|
|
203
|
+
}
|
|
204
|
+
|
|
151
205
|
interface IToken {
|
|
152
206
|
id: number | string;
|
|
153
207
|
token: string;
|
|
@@ -157,6 +211,7 @@ interface IToken {
|
|
|
157
211
|
declare const useChatData: () => {
|
|
158
212
|
actions: IAction[];
|
|
159
213
|
askUser: IAsk | undefined;
|
|
214
|
+
callFn: ICallFn | undefined;
|
|
160
215
|
chatSettingsDefaultValue: any;
|
|
161
216
|
chatSettingsInputs: any;
|
|
162
217
|
chatSettingsValue: any;
|
|
@@ -168,7 +223,93 @@ declare const useChatData: () => {
|
|
|
168
223
|
tasklists: ITasklistElement[];
|
|
169
224
|
};
|
|
170
225
|
|
|
171
|
-
|
|
226
|
+
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
227
|
+
declare const useChatInteract: () => {
|
|
228
|
+
uploadFile: (file: File, onProgress: (progress: number) => void) => {
|
|
229
|
+
xhr: XMLHttpRequest;
|
|
230
|
+
promise: Promise<{
|
|
231
|
+
id: string;
|
|
232
|
+
}>;
|
|
233
|
+
};
|
|
234
|
+
callAction: (action: IAction) => Promise<{
|
|
235
|
+
id: string;
|
|
236
|
+
status: boolean;
|
|
237
|
+
response?: string | undefined;
|
|
238
|
+
}> | undefined;
|
|
239
|
+
clear: () => void;
|
|
240
|
+
replyMessage: (message: IStep) => void;
|
|
241
|
+
sendMessage: (message: PartialBy<IStep, 'createdAt' | 'id'>, fileReferences?: IFileRef[]) => void;
|
|
242
|
+
sendAudioChunk: (isStart: boolean, mimeType: string, elapsedTime: number, data: Blob) => void;
|
|
243
|
+
endAudioStream: (fileReferences?: IFileRef[]) => void;
|
|
244
|
+
stopTask: () => void;
|
|
245
|
+
setIdToResume: recoil.SetterOrUpdater<string | undefined>;
|
|
246
|
+
updateChatSettings: (values: object) => void;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
declare const useChatMessages: () => {
|
|
250
|
+
threadId: string | undefined;
|
|
251
|
+
messages: IStep[];
|
|
252
|
+
firstInteraction: string | undefined;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
interface ISession {
|
|
256
|
+
socket: Socket;
|
|
257
|
+
error?: boolean;
|
|
258
|
+
}
|
|
259
|
+
declare const threadIdToResumeState: recoil.RecoilState<string | undefined>;
|
|
260
|
+
declare const chatProfileState: recoil.RecoilState<string | undefined>;
|
|
261
|
+
declare const sessionIdState: recoil.RecoilState<string>;
|
|
262
|
+
declare const sessionState: recoil.RecoilState<ISession | undefined>;
|
|
263
|
+
declare const actionState: recoil.RecoilState<IAction[]>;
|
|
264
|
+
declare const messagesState: recoil.RecoilState<IStep[]>;
|
|
265
|
+
declare const tokenCountState: recoil.RecoilState<number>;
|
|
266
|
+
declare const loadingState: recoil.RecoilState<boolean>;
|
|
267
|
+
declare const askUserState: recoil.RecoilState<IAsk | undefined>;
|
|
268
|
+
declare const callFnState: recoil.RecoilState<ICallFn | undefined>;
|
|
269
|
+
declare const chatSettingsInputsState: recoil.RecoilState<any>;
|
|
270
|
+
declare const chatSettingsDefaultValueSelector: recoil.RecoilValueReadOnly<any>;
|
|
271
|
+
declare const chatSettingsValueState: recoil.RecoilState<any>;
|
|
272
|
+
declare const elementState: recoil.RecoilState<IMessageElement[]>;
|
|
273
|
+
declare const tasklistState: recoil.RecoilState<ITasklistElement[]>;
|
|
274
|
+
declare const firstUserInteraction: recoil.RecoilState<string | undefined>;
|
|
275
|
+
declare const accessTokenState: recoil.RecoilState<string | undefined>;
|
|
276
|
+
declare const userState: recoil.RecoilState<IUser | null>;
|
|
277
|
+
declare const configState: recoil.RecoilState<IChainlitConfig | undefined>;
|
|
278
|
+
declare const threadHistoryState: recoil.RecoilState<ThreadHistory | undefined>;
|
|
279
|
+
declare const sideViewState: recoil.RecoilState<IMessageElement | undefined>;
|
|
280
|
+
declare const currentThreadIdState: recoil.RecoilState<string | undefined>;
|
|
281
|
+
|
|
282
|
+
declare const useChatSession: () => {
|
|
283
|
+
connect: lodash.DebouncedFunc<({ userEnv, accessToken }: {
|
|
284
|
+
userEnv: Record<string, string>;
|
|
285
|
+
accessToken?: string | undefined;
|
|
286
|
+
}) => void>;
|
|
287
|
+
disconnect: () => void;
|
|
288
|
+
session: ISession | undefined;
|
|
289
|
+
sessionId: string;
|
|
290
|
+
chatProfile: string | undefined;
|
|
291
|
+
idToResume: string | undefined;
|
|
292
|
+
setChatProfile: recoil.SetterOrUpdater<string | undefined>;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
declare const useAudio: (config?: IAudioConfig) => {
|
|
296
|
+
startRecording: (fileReferences?: IFileRef[]) => void;
|
|
297
|
+
stopRecording: () => void;
|
|
298
|
+
cancelRecording: () => void;
|
|
299
|
+
isRecording: boolean;
|
|
300
|
+
isSpeaking: boolean;
|
|
301
|
+
isRecordingFinished: boolean;
|
|
302
|
+
error: string | undefined;
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
declare const useConfig: (accessToken?: string) => {
|
|
306
|
+
config: IChainlitConfig | undefined;
|
|
307
|
+
error: Error | undefined;
|
|
308
|
+
isLoading: boolean;
|
|
309
|
+
language: string;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
declare const useAuth: () => {
|
|
172
313
|
data: {
|
|
173
314
|
requireLogin: boolean;
|
|
174
315
|
passwordAuth: boolean;
|
|
@@ -197,7 +338,9 @@ declare const useAuth: (apiClient: ChainlitAPI) => {
|
|
|
197
338
|
};
|
|
198
339
|
|
|
199
340
|
declare const fetcher: (client: ChainlitAPI, endpoint: string, token?: string) => Promise<any>;
|
|
200
|
-
declare function useApi<T>(
|
|
341
|
+
declare function useApi<T>(path?: string | null, { token, ...swrConfig }?: SWRConfiguration & {
|
|
342
|
+
token?: string;
|
|
343
|
+
}): swr__internal.SWRResponse<T, Error, Partial<swr__internal.PublicConfiguration<T, Error, swr__internal.BareFetcher<T>>> | undefined>;
|
|
201
344
|
|
|
202
345
|
interface IThreadFilters {
|
|
203
346
|
search?: string;
|
|
@@ -259,74 +402,8 @@ declare class ChainlitAPI extends APIBase {
|
|
|
259
402
|
getOAuthEndpoint(provider: string): string;
|
|
260
403
|
}
|
|
261
404
|
|
|
262
|
-
declare const
|
|
263
|
-
|
|
264
|
-
xhr: XMLHttpRequest;
|
|
265
|
-
promise: Promise<{
|
|
266
|
-
id: string;
|
|
267
|
-
}>;
|
|
268
|
-
};
|
|
269
|
-
callAction: (action: IAction) => Promise<{
|
|
270
|
-
id: string;
|
|
271
|
-
status: boolean;
|
|
272
|
-
response?: string | undefined;
|
|
273
|
-
}> | undefined;
|
|
274
|
-
clear: () => void;
|
|
275
|
-
replyMessage: (message: IStep) => void;
|
|
276
|
-
sendMessage: (message: IStep, fileReferences?: IFileRef[]) => void;
|
|
277
|
-
sendAudioChunk: (isStart: boolean, mimeType: string, elapsedTime: number, data: Blob) => void;
|
|
278
|
-
endAudioStream: (fileReferences?: IFileRef[]) => void;
|
|
279
|
-
stopTask: () => void;
|
|
280
|
-
setIdToResume: recoil.SetterOrUpdater<string | undefined>;
|
|
281
|
-
updateChatSettings: (values: object) => void;
|
|
282
|
-
sendCopilotEvent: (data: any) => void;
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
declare const useChatMessages: () => {
|
|
286
|
-
threadId: string | undefined;
|
|
287
|
-
messages: IStep[];
|
|
288
|
-
firstInteraction: string | undefined;
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
interface ISession {
|
|
292
|
-
socket: Socket;
|
|
293
|
-
error?: boolean;
|
|
294
|
-
}
|
|
295
|
-
declare const threadIdToResumeState: recoil.RecoilState<string | undefined>;
|
|
296
|
-
declare const chatProfileState: recoil.RecoilState<string | undefined>;
|
|
297
|
-
declare const sessionIdState: recoil.RecoilState<string>;
|
|
298
|
-
declare const sessionState: recoil.RecoilState<ISession | undefined>;
|
|
299
|
-
declare const actionState: recoil.RecoilState<IAction[]>;
|
|
300
|
-
declare const messagesState: recoil.RecoilState<IStep[]>;
|
|
301
|
-
declare const tokenCountState: recoil.RecoilState<number>;
|
|
302
|
-
declare const loadingState: recoil.RecoilState<boolean>;
|
|
303
|
-
declare const askUserState: recoil.RecoilState<IAsk | undefined>;
|
|
304
|
-
declare const callFnState: recoil.RecoilState<ICallFn | undefined>;
|
|
305
|
-
declare const chatSettingsInputsState: recoil.RecoilState<any>;
|
|
306
|
-
declare const chatSettingsDefaultValueSelector: recoil.RecoilValueReadOnly<any>;
|
|
307
|
-
declare const chatSettingsValueState: recoil.RecoilState<any>;
|
|
308
|
-
declare const elementState: recoil.RecoilState<IMessageElement[]>;
|
|
309
|
-
declare const tasklistState: recoil.RecoilState<ITasklistElement[]>;
|
|
310
|
-
declare const firstUserInteraction: recoil.RecoilState<string | undefined>;
|
|
311
|
-
declare const accessTokenState: recoil.RecoilState<string | undefined>;
|
|
312
|
-
declare const userState: recoil.RecoilState<IUser | null>;
|
|
313
|
-
declare const threadHistoryState: recoil.RecoilState<ThreadHistory | undefined>;
|
|
314
|
-
declare const sideViewState: recoil.RecoilState<IMessageElement | undefined>;
|
|
315
|
-
declare const currentThreadIdState: recoil.RecoilState<string | undefined>;
|
|
316
|
-
|
|
317
|
-
declare const useChatSession: () => {
|
|
318
|
-
connect: lodash.DebouncedFunc<({ client, userEnv, accessToken }: {
|
|
319
|
-
client: ChainlitAPI;
|
|
320
|
-
userEnv: Record<string, string>;
|
|
321
|
-
accessToken?: string | undefined;
|
|
322
|
-
}) => void>;
|
|
323
|
-
disconnect: () => void;
|
|
324
|
-
session: ISession | undefined;
|
|
325
|
-
sessionId: string;
|
|
326
|
-
chatProfile: string | undefined;
|
|
327
|
-
idToResume: string | undefined;
|
|
328
|
-
setChatProfile: recoil.SetterOrUpdater<string | undefined>;
|
|
329
|
-
};
|
|
405
|
+
declare const defaultChainlitContext: undefined;
|
|
406
|
+
declare const ChainlitContext: react.Context<ChainlitAPI>;
|
|
330
407
|
|
|
331
408
|
declare const nestMessages: (messages: IStep[]) => IStep[];
|
|
332
409
|
declare const isLastMessage: (messages: IStep[], index: number) => boolean;
|
|
@@ -337,4 +414,4 @@ declare const updateMessageById: (messages: IStep[], messageId: string, updatedM
|
|
|
337
414
|
declare const deleteMessageById: (messages: IStep[], messageId: string) => IStep[];
|
|
338
415
|
declare const updateMessageContentById: (messages: IStep[], messageId: number | string, updatedContent: string, isSequence: boolean, isInput: boolean) => IStep[];
|
|
339
416
|
|
|
340
|
-
export { APIBase, ActionSpec, AuthProvider, ChainlitAPI, ClientError, ElementType, FileSpec, IAction, IAsk, IAudioElement, ICallFn, IElement, IElementSize, IFeedback, IFileElement, IFileRef, IImageElement, IMessageElement, IPageInfo, IPagination, IPdfElement, IPlotlyElement, ISession, IStep, ITasklistElement, ITextElement, IThread, IThreadFilters, IToken, IUser, IUserMetadata, IVideoElement, ThreadHistory, UserInput, accessTokenState, actionState, addMessage, addMessageToParent, askUserState, callFnState, chatProfileState, chatSettingsDefaultValueSelector, chatSettingsInputsState, chatSettingsValueState, currentThreadIdState, deleteMessageById, elementState, fetcher, firstUserInteraction, hasMessageById, isLastMessage, loadingState, messagesState, nestMessages, sessionIdState, sessionState, sideViewState, tasklistState, threadHistoryState, threadIdToResumeState, tokenCountState, updateMessageById, updateMessageContentById, useApi, useAuth, useChatData, useChatInteract, useChatMessages, useChatSession, userState };
|
|
417
|
+
export { APIBase, ActionSpec, AuthProvider, ChainlitAPI, ChainlitContext, ChatProfile, ClientError, ElementType, FileSpec, IAction, IAsk, IAudioConfig, IAudioElement, ICallFn, IChainlitConfig, IElement, IElementSize, IFeedback, IFileElement, IFileRef, IImageElement, IMessageElement, IPageInfo, IPagination, IPdfElement, IPlotlyElement, ISession, IStarter, IStep, ITasklistElement, ITextElement, IThread, IThreadFilters, IToken, IUser, IUserMetadata, IVideoElement, ThreadHistory, UserInput, accessTokenState, actionState, addMessage, addMessageToParent, askUserState, callFnState, chatProfileState, chatSettingsDefaultValueSelector, chatSettingsInputsState, chatSettingsValueState, configState, currentThreadIdState, defaultChainlitContext, deleteMessageById, elementState, fetcher, firstUserInteraction, hasMessageById, isLastMessage, loadingState, messagesState, nestMessages, sessionIdState, sessionState, sideViewState, tasklistState, threadHistoryState, threadIdToResumeState, tokenCountState, updateMessageById, updateMessageContentById, useApi, useAudio, useAuth, useChatData, useChatInteract, useChatMessages, useChatSession, useConfig, userState };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as recoil from 'recoil';
|
|
|
2
2
|
import { Socket } from 'socket.io-client';
|
|
3
3
|
export { Socket } from 'socket.io-client';
|
|
4
4
|
import * as lodash from 'lodash';
|
|
5
|
+
import * as react from 'react';
|
|
5
6
|
import * as swr__internal from 'swr/_internal';
|
|
6
7
|
import { SWRConfiguration } from 'swr';
|
|
7
8
|
|
|
@@ -148,6 +149,59 @@ type ThreadHistory = {
|
|
|
148
149
|
pageInfo?: IPageInfo;
|
|
149
150
|
};
|
|
150
151
|
|
|
152
|
+
interface IStarter {
|
|
153
|
+
label: string;
|
|
154
|
+
message: string;
|
|
155
|
+
icon?: string;
|
|
156
|
+
}
|
|
157
|
+
interface ChatProfile {
|
|
158
|
+
default: boolean;
|
|
159
|
+
icon?: string;
|
|
160
|
+
name: string;
|
|
161
|
+
markdown_description: string;
|
|
162
|
+
starters?: IStarter[];
|
|
163
|
+
}
|
|
164
|
+
interface IAudioConfig {
|
|
165
|
+
enabled: boolean;
|
|
166
|
+
min_decibels: number;
|
|
167
|
+
initial_silence_timeout: number;
|
|
168
|
+
silence_timeout: number;
|
|
169
|
+
chunk_duration: number;
|
|
170
|
+
max_duration: number;
|
|
171
|
+
}
|
|
172
|
+
interface IChainlitConfig {
|
|
173
|
+
markdown?: string;
|
|
174
|
+
ui: {
|
|
175
|
+
name: string;
|
|
176
|
+
description?: string;
|
|
177
|
+
default_collapse_content?: boolean;
|
|
178
|
+
github?: string;
|
|
179
|
+
theme: any;
|
|
180
|
+
custom_css?: string;
|
|
181
|
+
custom_js?: string;
|
|
182
|
+
custom_font?: string;
|
|
183
|
+
custom_meta_image_url?: string;
|
|
184
|
+
};
|
|
185
|
+
features: {
|
|
186
|
+
spontaneous_file_upload?: {
|
|
187
|
+
enabled?: boolean;
|
|
188
|
+
max_size_mb?: number;
|
|
189
|
+
max_files?: number;
|
|
190
|
+
accept?: string[] | Record<string, string[]>;
|
|
191
|
+
};
|
|
192
|
+
audio: IAudioConfig;
|
|
193
|
+
unsafe_allow_html?: boolean;
|
|
194
|
+
latex?: boolean;
|
|
195
|
+
};
|
|
196
|
+
debugUrl?: string;
|
|
197
|
+
userEnv: string[];
|
|
198
|
+
dataPersistence: boolean;
|
|
199
|
+
threadResumable: boolean;
|
|
200
|
+
chatProfiles: ChatProfile[];
|
|
201
|
+
starters?: IStarter[];
|
|
202
|
+
translation: object;
|
|
203
|
+
}
|
|
204
|
+
|
|
151
205
|
interface IToken {
|
|
152
206
|
id: number | string;
|
|
153
207
|
token: string;
|
|
@@ -157,6 +211,7 @@ interface IToken {
|
|
|
157
211
|
declare const useChatData: () => {
|
|
158
212
|
actions: IAction[];
|
|
159
213
|
askUser: IAsk | undefined;
|
|
214
|
+
callFn: ICallFn | undefined;
|
|
160
215
|
chatSettingsDefaultValue: any;
|
|
161
216
|
chatSettingsInputs: any;
|
|
162
217
|
chatSettingsValue: any;
|
|
@@ -168,7 +223,93 @@ declare const useChatData: () => {
|
|
|
168
223
|
tasklists: ITasklistElement[];
|
|
169
224
|
};
|
|
170
225
|
|
|
171
|
-
|
|
226
|
+
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
227
|
+
declare const useChatInteract: () => {
|
|
228
|
+
uploadFile: (file: File, onProgress: (progress: number) => void) => {
|
|
229
|
+
xhr: XMLHttpRequest;
|
|
230
|
+
promise: Promise<{
|
|
231
|
+
id: string;
|
|
232
|
+
}>;
|
|
233
|
+
};
|
|
234
|
+
callAction: (action: IAction) => Promise<{
|
|
235
|
+
id: string;
|
|
236
|
+
status: boolean;
|
|
237
|
+
response?: string | undefined;
|
|
238
|
+
}> | undefined;
|
|
239
|
+
clear: () => void;
|
|
240
|
+
replyMessage: (message: IStep) => void;
|
|
241
|
+
sendMessage: (message: PartialBy<IStep, 'createdAt' | 'id'>, fileReferences?: IFileRef[]) => void;
|
|
242
|
+
sendAudioChunk: (isStart: boolean, mimeType: string, elapsedTime: number, data: Blob) => void;
|
|
243
|
+
endAudioStream: (fileReferences?: IFileRef[]) => void;
|
|
244
|
+
stopTask: () => void;
|
|
245
|
+
setIdToResume: recoil.SetterOrUpdater<string | undefined>;
|
|
246
|
+
updateChatSettings: (values: object) => void;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
declare const useChatMessages: () => {
|
|
250
|
+
threadId: string | undefined;
|
|
251
|
+
messages: IStep[];
|
|
252
|
+
firstInteraction: string | undefined;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
interface ISession {
|
|
256
|
+
socket: Socket;
|
|
257
|
+
error?: boolean;
|
|
258
|
+
}
|
|
259
|
+
declare const threadIdToResumeState: recoil.RecoilState<string | undefined>;
|
|
260
|
+
declare const chatProfileState: recoil.RecoilState<string | undefined>;
|
|
261
|
+
declare const sessionIdState: recoil.RecoilState<string>;
|
|
262
|
+
declare const sessionState: recoil.RecoilState<ISession | undefined>;
|
|
263
|
+
declare const actionState: recoil.RecoilState<IAction[]>;
|
|
264
|
+
declare const messagesState: recoil.RecoilState<IStep[]>;
|
|
265
|
+
declare const tokenCountState: recoil.RecoilState<number>;
|
|
266
|
+
declare const loadingState: recoil.RecoilState<boolean>;
|
|
267
|
+
declare const askUserState: recoil.RecoilState<IAsk | undefined>;
|
|
268
|
+
declare const callFnState: recoil.RecoilState<ICallFn | undefined>;
|
|
269
|
+
declare const chatSettingsInputsState: recoil.RecoilState<any>;
|
|
270
|
+
declare const chatSettingsDefaultValueSelector: recoil.RecoilValueReadOnly<any>;
|
|
271
|
+
declare const chatSettingsValueState: recoil.RecoilState<any>;
|
|
272
|
+
declare const elementState: recoil.RecoilState<IMessageElement[]>;
|
|
273
|
+
declare const tasklistState: recoil.RecoilState<ITasklistElement[]>;
|
|
274
|
+
declare const firstUserInteraction: recoil.RecoilState<string | undefined>;
|
|
275
|
+
declare const accessTokenState: recoil.RecoilState<string | undefined>;
|
|
276
|
+
declare const userState: recoil.RecoilState<IUser | null>;
|
|
277
|
+
declare const configState: recoil.RecoilState<IChainlitConfig | undefined>;
|
|
278
|
+
declare const threadHistoryState: recoil.RecoilState<ThreadHistory | undefined>;
|
|
279
|
+
declare const sideViewState: recoil.RecoilState<IMessageElement | undefined>;
|
|
280
|
+
declare const currentThreadIdState: recoil.RecoilState<string | undefined>;
|
|
281
|
+
|
|
282
|
+
declare const useChatSession: () => {
|
|
283
|
+
connect: lodash.DebouncedFunc<({ userEnv, accessToken }: {
|
|
284
|
+
userEnv: Record<string, string>;
|
|
285
|
+
accessToken?: string | undefined;
|
|
286
|
+
}) => void>;
|
|
287
|
+
disconnect: () => void;
|
|
288
|
+
session: ISession | undefined;
|
|
289
|
+
sessionId: string;
|
|
290
|
+
chatProfile: string | undefined;
|
|
291
|
+
idToResume: string | undefined;
|
|
292
|
+
setChatProfile: recoil.SetterOrUpdater<string | undefined>;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
declare const useAudio: (config?: IAudioConfig) => {
|
|
296
|
+
startRecording: (fileReferences?: IFileRef[]) => void;
|
|
297
|
+
stopRecording: () => void;
|
|
298
|
+
cancelRecording: () => void;
|
|
299
|
+
isRecording: boolean;
|
|
300
|
+
isSpeaking: boolean;
|
|
301
|
+
isRecordingFinished: boolean;
|
|
302
|
+
error: string | undefined;
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
declare const useConfig: (accessToken?: string) => {
|
|
306
|
+
config: IChainlitConfig | undefined;
|
|
307
|
+
error: Error | undefined;
|
|
308
|
+
isLoading: boolean;
|
|
309
|
+
language: string;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
declare const useAuth: () => {
|
|
172
313
|
data: {
|
|
173
314
|
requireLogin: boolean;
|
|
174
315
|
passwordAuth: boolean;
|
|
@@ -197,7 +338,9 @@ declare const useAuth: (apiClient: ChainlitAPI) => {
|
|
|
197
338
|
};
|
|
198
339
|
|
|
199
340
|
declare const fetcher: (client: ChainlitAPI, endpoint: string, token?: string) => Promise<any>;
|
|
200
|
-
declare function useApi<T>(
|
|
341
|
+
declare function useApi<T>(path?: string | null, { token, ...swrConfig }?: SWRConfiguration & {
|
|
342
|
+
token?: string;
|
|
343
|
+
}): swr__internal.SWRResponse<T, Error, Partial<swr__internal.PublicConfiguration<T, Error, swr__internal.BareFetcher<T>>> | undefined>;
|
|
201
344
|
|
|
202
345
|
interface IThreadFilters {
|
|
203
346
|
search?: string;
|
|
@@ -259,74 +402,8 @@ declare class ChainlitAPI extends APIBase {
|
|
|
259
402
|
getOAuthEndpoint(provider: string): string;
|
|
260
403
|
}
|
|
261
404
|
|
|
262
|
-
declare const
|
|
263
|
-
|
|
264
|
-
xhr: XMLHttpRequest;
|
|
265
|
-
promise: Promise<{
|
|
266
|
-
id: string;
|
|
267
|
-
}>;
|
|
268
|
-
};
|
|
269
|
-
callAction: (action: IAction) => Promise<{
|
|
270
|
-
id: string;
|
|
271
|
-
status: boolean;
|
|
272
|
-
response?: string | undefined;
|
|
273
|
-
}> | undefined;
|
|
274
|
-
clear: () => void;
|
|
275
|
-
replyMessage: (message: IStep) => void;
|
|
276
|
-
sendMessage: (message: IStep, fileReferences?: IFileRef[]) => void;
|
|
277
|
-
sendAudioChunk: (isStart: boolean, mimeType: string, elapsedTime: number, data: Blob) => void;
|
|
278
|
-
endAudioStream: (fileReferences?: IFileRef[]) => void;
|
|
279
|
-
stopTask: () => void;
|
|
280
|
-
setIdToResume: recoil.SetterOrUpdater<string | undefined>;
|
|
281
|
-
updateChatSettings: (values: object) => void;
|
|
282
|
-
sendCopilotEvent: (data: any) => void;
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
declare const useChatMessages: () => {
|
|
286
|
-
threadId: string | undefined;
|
|
287
|
-
messages: IStep[];
|
|
288
|
-
firstInteraction: string | undefined;
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
interface ISession {
|
|
292
|
-
socket: Socket;
|
|
293
|
-
error?: boolean;
|
|
294
|
-
}
|
|
295
|
-
declare const threadIdToResumeState: recoil.RecoilState<string | undefined>;
|
|
296
|
-
declare const chatProfileState: recoil.RecoilState<string | undefined>;
|
|
297
|
-
declare const sessionIdState: recoil.RecoilState<string>;
|
|
298
|
-
declare const sessionState: recoil.RecoilState<ISession | undefined>;
|
|
299
|
-
declare const actionState: recoil.RecoilState<IAction[]>;
|
|
300
|
-
declare const messagesState: recoil.RecoilState<IStep[]>;
|
|
301
|
-
declare const tokenCountState: recoil.RecoilState<number>;
|
|
302
|
-
declare const loadingState: recoil.RecoilState<boolean>;
|
|
303
|
-
declare const askUserState: recoil.RecoilState<IAsk | undefined>;
|
|
304
|
-
declare const callFnState: recoil.RecoilState<ICallFn | undefined>;
|
|
305
|
-
declare const chatSettingsInputsState: recoil.RecoilState<any>;
|
|
306
|
-
declare const chatSettingsDefaultValueSelector: recoil.RecoilValueReadOnly<any>;
|
|
307
|
-
declare const chatSettingsValueState: recoil.RecoilState<any>;
|
|
308
|
-
declare const elementState: recoil.RecoilState<IMessageElement[]>;
|
|
309
|
-
declare const tasklistState: recoil.RecoilState<ITasklistElement[]>;
|
|
310
|
-
declare const firstUserInteraction: recoil.RecoilState<string | undefined>;
|
|
311
|
-
declare const accessTokenState: recoil.RecoilState<string | undefined>;
|
|
312
|
-
declare const userState: recoil.RecoilState<IUser | null>;
|
|
313
|
-
declare const threadHistoryState: recoil.RecoilState<ThreadHistory | undefined>;
|
|
314
|
-
declare const sideViewState: recoil.RecoilState<IMessageElement | undefined>;
|
|
315
|
-
declare const currentThreadIdState: recoil.RecoilState<string | undefined>;
|
|
316
|
-
|
|
317
|
-
declare const useChatSession: () => {
|
|
318
|
-
connect: lodash.DebouncedFunc<({ client, userEnv, accessToken }: {
|
|
319
|
-
client: ChainlitAPI;
|
|
320
|
-
userEnv: Record<string, string>;
|
|
321
|
-
accessToken?: string | undefined;
|
|
322
|
-
}) => void>;
|
|
323
|
-
disconnect: () => void;
|
|
324
|
-
session: ISession | undefined;
|
|
325
|
-
sessionId: string;
|
|
326
|
-
chatProfile: string | undefined;
|
|
327
|
-
idToResume: string | undefined;
|
|
328
|
-
setChatProfile: recoil.SetterOrUpdater<string | undefined>;
|
|
329
|
-
};
|
|
405
|
+
declare const defaultChainlitContext: undefined;
|
|
406
|
+
declare const ChainlitContext: react.Context<ChainlitAPI>;
|
|
330
407
|
|
|
331
408
|
declare const nestMessages: (messages: IStep[]) => IStep[];
|
|
332
409
|
declare const isLastMessage: (messages: IStep[], index: number) => boolean;
|
|
@@ -337,4 +414,4 @@ declare const updateMessageById: (messages: IStep[], messageId: string, updatedM
|
|
|
337
414
|
declare const deleteMessageById: (messages: IStep[], messageId: string) => IStep[];
|
|
338
415
|
declare const updateMessageContentById: (messages: IStep[], messageId: number | string, updatedContent: string, isSequence: boolean, isInput: boolean) => IStep[];
|
|
339
416
|
|
|
340
|
-
export { APIBase, ActionSpec, AuthProvider, ChainlitAPI, ClientError, ElementType, FileSpec, IAction, IAsk, IAudioElement, ICallFn, IElement, IElementSize, IFeedback, IFileElement, IFileRef, IImageElement, IMessageElement, IPageInfo, IPagination, IPdfElement, IPlotlyElement, ISession, IStep, ITasklistElement, ITextElement, IThread, IThreadFilters, IToken, IUser, IUserMetadata, IVideoElement, ThreadHistory, UserInput, accessTokenState, actionState, addMessage, addMessageToParent, askUserState, callFnState, chatProfileState, chatSettingsDefaultValueSelector, chatSettingsInputsState, chatSettingsValueState, currentThreadIdState, deleteMessageById, elementState, fetcher, firstUserInteraction, hasMessageById, isLastMessage, loadingState, messagesState, nestMessages, sessionIdState, sessionState, sideViewState, tasklistState, threadHistoryState, threadIdToResumeState, tokenCountState, updateMessageById, updateMessageContentById, useApi, useAuth, useChatData, useChatInteract, useChatMessages, useChatSession, userState };
|
|
417
|
+
export { APIBase, ActionSpec, AuthProvider, ChainlitAPI, ChainlitContext, ChatProfile, ClientError, ElementType, FileSpec, IAction, IAsk, IAudioConfig, IAudioElement, ICallFn, IChainlitConfig, IElement, IElementSize, IFeedback, IFileElement, IFileRef, IImageElement, IMessageElement, IPageInfo, IPagination, IPdfElement, IPlotlyElement, ISession, IStarter, IStep, ITasklistElement, ITextElement, IThread, IThreadFilters, IToken, IUser, IUserMetadata, IVideoElement, ThreadHistory, UserInput, accessTokenState, actionState, addMessage, addMessageToParent, askUserState, callFnState, chatProfileState, chatSettingsDefaultValueSelector, chatSettingsInputsState, chatSettingsValueState, configState, currentThreadIdState, defaultChainlitContext, deleteMessageById, elementState, fetcher, firstUserInteraction, hasMessageById, isLastMessage, loadingState, messagesState, nestMessages, sessionIdState, sessionState, sideViewState, tasklistState, threadHistoryState, threadIdToResumeState, tokenCountState, updateMessageById, updateMessageContentById, useApi, useAudio, useAuth, useChatData, useChatInteract, useChatMessages, useChatSession, useConfig, userState };
|