@chainlit/react-client 0.1.0 → 0.2.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.
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
- <RecoilRoot>
23
- <MyApp />
24
- </RecoilRoot>
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 { ChainlitAPI, useChatSession } from '@chainlit/react-client';
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
- }, [connect, disconnect]);
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
 
@@ -85,7 +86,6 @@ interface IStep {
85
86
  createdAt: number | string;
86
87
  start?: number | string;
87
88
  end?: number | string;
88
- disableFeedback?: boolean;
89
89
  feedback?: IFeedback;
90
90
  language?: string;
91
91
  streaming?: boolean;
@@ -121,6 +121,7 @@ interface IUserMetadata extends Record<string, any> {
121
121
  interface IUser {
122
122
  id: string;
123
123
  identifier: string;
124
+ display_name?: string;
124
125
  metadata: IUserMetadata;
125
126
  }
126
127
 
@@ -148,6 +149,63 @@ 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
+ sample_rate: number;
167
+ }
168
+ interface IAuthConfig {
169
+ requireLogin: boolean;
170
+ passwordAuth: boolean;
171
+ headerAuth: boolean;
172
+ oauthProviders: string[];
173
+ }
174
+ interface IChainlitConfig {
175
+ markdown?: string;
176
+ ui: {
177
+ name: string;
178
+ description?: string;
179
+ cot: 'hidden' | 'tool_call' | 'full';
180
+ default_collapse_content?: boolean;
181
+ github?: string;
182
+ theme: any;
183
+ custom_css?: string;
184
+ custom_js?: string;
185
+ custom_font?: string;
186
+ custom_meta_image_url?: string;
187
+ };
188
+ features: {
189
+ spontaneous_file_upload?: {
190
+ enabled?: boolean;
191
+ max_size_mb?: number;
192
+ max_files?: number;
193
+ accept?: string[] | Record<string, string[]>;
194
+ };
195
+ audio: IAudioConfig;
196
+ unsafe_allow_html?: boolean;
197
+ latex?: boolean;
198
+ edit_message?: boolean;
199
+ };
200
+ debugUrl?: string;
201
+ userEnv: string[];
202
+ dataPersistence: boolean;
203
+ threadResumable: boolean;
204
+ chatProfiles: ChatProfile[];
205
+ starters?: IStarter[];
206
+ translation: object;
207
+ }
208
+
151
209
  interface IToken {
152
210
  id: number | string;
153
211
  token: string;
@@ -157,6 +215,7 @@ interface IToken {
157
215
  declare const useChatData: () => {
158
216
  actions: IAction[];
159
217
  askUser: IAsk | undefined;
218
+ callFn: ICallFn | undefined;
160
219
  chatSettingsDefaultValue: any;
161
220
  chatSettingsInputs: any;
162
221
  chatSettingsValue: any;
@@ -168,36 +227,122 @@ declare const useChatData: () => {
168
227
  tasklists: ITasklistElement[];
169
228
  };
170
229
 
171
- declare const useAuth: (apiClient: ChainlitAPI) => {
172
- data: {
173
- requireLogin: boolean;
174
- passwordAuth: boolean;
175
- headerAuth: boolean;
176
- oauthProviders: string[];
230
+ type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
231
+ declare const useChatInteract: () => {
232
+ uploadFile: (file: File, onProgress: (progress: number) => void) => {
233
+ xhr: XMLHttpRequest;
234
+ promise: Promise<{
235
+ id: string;
236
+ }>;
177
237
  };
238
+ callAction: (action: IAction) => Promise<{
239
+ id: string;
240
+ status: boolean;
241
+ response?: string | undefined;
242
+ }> | undefined;
243
+ clear: () => void;
244
+ replyMessage: (message: IStep) => void;
245
+ sendMessage: (message: PartialBy<IStep, 'createdAt' | 'id'>, fileReferences?: IFileRef[]) => void;
246
+ editMessage: (message: IStep) => void;
247
+ startAudioStream: () => void;
248
+ sendAudioChunk: (isStart: boolean, mimeType: string, elapsedTime: number, data: Int16Array) => void;
249
+ endAudioStream: () => void;
250
+ stopTask: () => void;
251
+ setIdToResume: recoil.SetterOrUpdater<string | undefined>;
252
+ updateChatSettings: (values: object) => void;
253
+ };
254
+
255
+ declare const useChatMessages: () => {
256
+ threadId: string | undefined;
257
+ messages: IStep[];
258
+ firstInteraction: string | undefined;
259
+ };
260
+
261
+ interface ISession {
262
+ socket: Socket;
263
+ error?: boolean;
264
+ }
265
+ declare const threadIdToResumeState: recoil.RecoilState<string | undefined>;
266
+ declare const chatProfileState: recoil.RecoilState<string | undefined>;
267
+ declare const sessionIdState: recoil.RecoilState<string>;
268
+ declare const sessionState: recoil.RecoilState<ISession | undefined>;
269
+ declare const actionState: recoil.RecoilState<IAction[]>;
270
+ declare const messagesState: recoil.RecoilState<IStep[]>;
271
+ declare const tokenCountState: recoil.RecoilState<number>;
272
+ declare const loadingState: recoil.RecoilState<boolean>;
273
+ declare const askUserState: recoil.RecoilState<IAsk | undefined>;
274
+ declare const wavRecorderState: recoil.RecoilState<any>;
275
+ declare const wavStreamPlayerState: recoil.RecoilState<any>;
276
+ declare const audioConnectionState: recoil.RecoilState<"connecting" | "on" | "off">;
277
+ declare const isAiSpeakingState: recoil.RecoilState<boolean>;
278
+ declare const callFnState: recoil.RecoilState<ICallFn | undefined>;
279
+ declare const chatSettingsInputsState: recoil.RecoilState<any>;
280
+ declare const chatSettingsDefaultValueSelector: recoil.RecoilValueReadOnly<any>;
281
+ declare const chatSettingsValueState: recoil.RecoilState<any>;
282
+ declare const elementState: recoil.RecoilState<IMessageElement[]>;
283
+ declare const tasklistState: recoil.RecoilState<ITasklistElement[]>;
284
+ declare const firstUserInteraction: recoil.RecoilState<string | undefined>;
285
+ declare const accessTokenState: recoil.RecoilState<string | undefined>;
286
+ declare const userState: recoil.RecoilState<IUser | null>;
287
+ declare const configState: recoil.RecoilState<IChainlitConfig | undefined>;
288
+ declare const authState: recoil.RecoilState<IAuthConfig | undefined>;
289
+ declare const threadHistoryState: recoil.RecoilState<ThreadHistory | undefined>;
290
+ declare const sideViewState: recoil.RecoilState<IMessageElement | undefined>;
291
+ declare const currentThreadIdState: recoil.RecoilState<string | undefined>;
292
+
293
+ declare const useChatSession: () => {
294
+ connect: lodash.DebouncedFunc<({ userEnv, accessToken }: {
295
+ userEnv: Record<string, string>;
296
+ accessToken?: string | undefined;
297
+ }) => void>;
298
+ disconnect: () => void;
299
+ session: ISession | undefined;
300
+ sessionId: string;
301
+ chatProfile: string | undefined;
302
+ idToResume: string | undefined;
303
+ setChatProfile: recoil.SetterOrUpdater<string | undefined>;
304
+ };
305
+
306
+ declare const useAudio: () => {
307
+ startConversation: () => Promise<void>;
308
+ endConversation: () => Promise<void>;
309
+ audioConnection: "connecting" | "on" | "off";
310
+ isAiSpeaking: boolean;
311
+ wavRecorder: any;
312
+ wavStreamPlayer: any;
313
+ };
314
+
315
+ declare const useConfig: (accessToken?: string) => {
316
+ config: IChainlitConfig | undefined;
317
+ error: Error | undefined;
318
+ isLoading: boolean;
319
+ language: string;
320
+ };
321
+
322
+ declare const useAuth: () => {
323
+ authConfig: IAuthConfig;
178
324
  user: null;
179
325
  isReady: boolean;
180
326
  isAuthenticated: boolean;
181
327
  accessToken: string;
182
328
  logout: () => void;
183
329
  setAccessToken: () => void;
330
+ data?: undefined;
184
331
  } | {
185
- data: {
186
- requireLogin: boolean;
187
- passwordAuth: boolean;
188
- headerAuth: boolean;
189
- oauthProviders: string[];
190
- } | undefined;
332
+ data: IAuthConfig | undefined;
191
333
  user: IUser | null;
192
334
  isAuthenticated: boolean;
193
335
  isReady: boolean;
194
336
  accessToken: string | undefined;
195
- logout: () => Promise<void>;
337
+ logout: (reload?: boolean) => Promise<void>;
196
338
  setAccessToken: (token: string | null | undefined) => void;
339
+ authConfig?: undefined;
197
340
  };
198
341
 
199
342
  declare const fetcher: (client: ChainlitAPI, endpoint: string, token?: string) => Promise<any>;
200
- declare function useApi<T>(client: ChainlitAPI, path?: string | null, options?: SWRConfiguration): swr__internal.SWRResponse<T, Error, Partial<swr__internal.PublicConfiguration<T, Error, swr__internal.BareFetcher<T>>> | undefined>;
343
+ declare function useApi<T>(path?: string | null, { token, ...swrConfig }?: SWRConfiguration & {
344
+ token?: string;
345
+ }): swr__internal.SWRResponse<T, Error, Partial<swr__internal.PublicConfiguration<T, Error, swr__internal.BareFetcher<T>>> | undefined>;
201
346
 
202
347
  interface IThreadFilters {
203
348
  search?: string;
@@ -259,74 +404,8 @@ declare class ChainlitAPI extends APIBase {
259
404
  getOAuthEndpoint(provider: string): string;
260
405
  }
261
406
 
262
- declare const useChatInteract: () => {
263
- uploadFile: (client: ChainlitAPI, file: File, onProgress: (progress: number) => void) => {
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
- };
407
+ declare const defaultChainlitContext: undefined;
408
+ declare const ChainlitContext: react.Context<ChainlitAPI>;
330
409
 
331
410
  declare const nestMessages: (messages: IStep[]) => IStep[];
332
411
  declare const isLastMessage: (messages: IStep[], index: number) => boolean;
@@ -337,4 +416,8 @@ declare const updateMessageById: (messages: IStep[], messageId: string, updatedM
337
416
  declare const deleteMessageById: (messages: IStep[], messageId: string) => IStep[];
338
417
  declare const updateMessageContentById: (messages: IStep[], messageId: number | string, updatedContent: string, isSequence: boolean, isInput: boolean) => IStep[];
339
418
 
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 };
419
+ declare const WavRenderer: {
420
+ drawBars: (ctx: CanvasRenderingContext2D, data: Float32Array, cssWidth: number, cssHeight: number, color: string, pointCount?: number, barWidth?: number, barSpacing?: number, center?: boolean) => void;
421
+ };
422
+
423
+ export { APIBase, ActionSpec, AuthProvider, ChainlitAPI, ChainlitContext, ChatProfile, ClientError, ElementType, FileSpec, IAction, IAsk, IAudioConfig, IAudioElement, IAuthConfig, 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, WavRenderer, accessTokenState, actionState, addMessage, addMessageToParent, askUserState, audioConnectionState, authState, callFnState, chatProfileState, chatSettingsDefaultValueSelector, chatSettingsInputsState, chatSettingsValueState, configState, currentThreadIdState, defaultChainlitContext, deleteMessageById, elementState, fetcher, firstUserInteraction, hasMessageById, isAiSpeakingState, isLastMessage, loadingState, messagesState, nestMessages, sessionIdState, sessionState, sideViewState, tasklistState, threadHistoryState, threadIdToResumeState, tokenCountState, updateMessageById, updateMessageContentById, useApi, useAudio, useAuth, useChatData, useChatInteract, useChatMessages, useChatSession, useConfig, userState, wavRecorderState, wavStreamPlayerState };
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
 
@@ -85,7 +86,6 @@ interface IStep {
85
86
  createdAt: number | string;
86
87
  start?: number | string;
87
88
  end?: number | string;
88
- disableFeedback?: boolean;
89
89
  feedback?: IFeedback;
90
90
  language?: string;
91
91
  streaming?: boolean;
@@ -121,6 +121,7 @@ interface IUserMetadata extends Record<string, any> {
121
121
  interface IUser {
122
122
  id: string;
123
123
  identifier: string;
124
+ display_name?: string;
124
125
  metadata: IUserMetadata;
125
126
  }
126
127
 
@@ -148,6 +149,63 @@ 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
+ sample_rate: number;
167
+ }
168
+ interface IAuthConfig {
169
+ requireLogin: boolean;
170
+ passwordAuth: boolean;
171
+ headerAuth: boolean;
172
+ oauthProviders: string[];
173
+ }
174
+ interface IChainlitConfig {
175
+ markdown?: string;
176
+ ui: {
177
+ name: string;
178
+ description?: string;
179
+ cot: 'hidden' | 'tool_call' | 'full';
180
+ default_collapse_content?: boolean;
181
+ github?: string;
182
+ theme: any;
183
+ custom_css?: string;
184
+ custom_js?: string;
185
+ custom_font?: string;
186
+ custom_meta_image_url?: string;
187
+ };
188
+ features: {
189
+ spontaneous_file_upload?: {
190
+ enabled?: boolean;
191
+ max_size_mb?: number;
192
+ max_files?: number;
193
+ accept?: string[] | Record<string, string[]>;
194
+ };
195
+ audio: IAudioConfig;
196
+ unsafe_allow_html?: boolean;
197
+ latex?: boolean;
198
+ edit_message?: boolean;
199
+ };
200
+ debugUrl?: string;
201
+ userEnv: string[];
202
+ dataPersistence: boolean;
203
+ threadResumable: boolean;
204
+ chatProfiles: ChatProfile[];
205
+ starters?: IStarter[];
206
+ translation: object;
207
+ }
208
+
151
209
  interface IToken {
152
210
  id: number | string;
153
211
  token: string;
@@ -157,6 +215,7 @@ interface IToken {
157
215
  declare const useChatData: () => {
158
216
  actions: IAction[];
159
217
  askUser: IAsk | undefined;
218
+ callFn: ICallFn | undefined;
160
219
  chatSettingsDefaultValue: any;
161
220
  chatSettingsInputs: any;
162
221
  chatSettingsValue: any;
@@ -168,36 +227,122 @@ declare const useChatData: () => {
168
227
  tasklists: ITasklistElement[];
169
228
  };
170
229
 
171
- declare const useAuth: (apiClient: ChainlitAPI) => {
172
- data: {
173
- requireLogin: boolean;
174
- passwordAuth: boolean;
175
- headerAuth: boolean;
176
- oauthProviders: string[];
230
+ type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
231
+ declare const useChatInteract: () => {
232
+ uploadFile: (file: File, onProgress: (progress: number) => void) => {
233
+ xhr: XMLHttpRequest;
234
+ promise: Promise<{
235
+ id: string;
236
+ }>;
177
237
  };
238
+ callAction: (action: IAction) => Promise<{
239
+ id: string;
240
+ status: boolean;
241
+ response?: string | undefined;
242
+ }> | undefined;
243
+ clear: () => void;
244
+ replyMessage: (message: IStep) => void;
245
+ sendMessage: (message: PartialBy<IStep, 'createdAt' | 'id'>, fileReferences?: IFileRef[]) => void;
246
+ editMessage: (message: IStep) => void;
247
+ startAudioStream: () => void;
248
+ sendAudioChunk: (isStart: boolean, mimeType: string, elapsedTime: number, data: Int16Array) => void;
249
+ endAudioStream: () => void;
250
+ stopTask: () => void;
251
+ setIdToResume: recoil.SetterOrUpdater<string | undefined>;
252
+ updateChatSettings: (values: object) => void;
253
+ };
254
+
255
+ declare const useChatMessages: () => {
256
+ threadId: string | undefined;
257
+ messages: IStep[];
258
+ firstInteraction: string | undefined;
259
+ };
260
+
261
+ interface ISession {
262
+ socket: Socket;
263
+ error?: boolean;
264
+ }
265
+ declare const threadIdToResumeState: recoil.RecoilState<string | undefined>;
266
+ declare const chatProfileState: recoil.RecoilState<string | undefined>;
267
+ declare const sessionIdState: recoil.RecoilState<string>;
268
+ declare const sessionState: recoil.RecoilState<ISession | undefined>;
269
+ declare const actionState: recoil.RecoilState<IAction[]>;
270
+ declare const messagesState: recoil.RecoilState<IStep[]>;
271
+ declare const tokenCountState: recoil.RecoilState<number>;
272
+ declare const loadingState: recoil.RecoilState<boolean>;
273
+ declare const askUserState: recoil.RecoilState<IAsk | undefined>;
274
+ declare const wavRecorderState: recoil.RecoilState<any>;
275
+ declare const wavStreamPlayerState: recoil.RecoilState<any>;
276
+ declare const audioConnectionState: recoil.RecoilState<"connecting" | "on" | "off">;
277
+ declare const isAiSpeakingState: recoil.RecoilState<boolean>;
278
+ declare const callFnState: recoil.RecoilState<ICallFn | undefined>;
279
+ declare const chatSettingsInputsState: recoil.RecoilState<any>;
280
+ declare const chatSettingsDefaultValueSelector: recoil.RecoilValueReadOnly<any>;
281
+ declare const chatSettingsValueState: recoil.RecoilState<any>;
282
+ declare const elementState: recoil.RecoilState<IMessageElement[]>;
283
+ declare const tasklistState: recoil.RecoilState<ITasklistElement[]>;
284
+ declare const firstUserInteraction: recoil.RecoilState<string | undefined>;
285
+ declare const accessTokenState: recoil.RecoilState<string | undefined>;
286
+ declare const userState: recoil.RecoilState<IUser | null>;
287
+ declare const configState: recoil.RecoilState<IChainlitConfig | undefined>;
288
+ declare const authState: recoil.RecoilState<IAuthConfig | undefined>;
289
+ declare const threadHistoryState: recoil.RecoilState<ThreadHistory | undefined>;
290
+ declare const sideViewState: recoil.RecoilState<IMessageElement | undefined>;
291
+ declare const currentThreadIdState: recoil.RecoilState<string | undefined>;
292
+
293
+ declare const useChatSession: () => {
294
+ connect: lodash.DebouncedFunc<({ userEnv, accessToken }: {
295
+ userEnv: Record<string, string>;
296
+ accessToken?: string | undefined;
297
+ }) => void>;
298
+ disconnect: () => void;
299
+ session: ISession | undefined;
300
+ sessionId: string;
301
+ chatProfile: string | undefined;
302
+ idToResume: string | undefined;
303
+ setChatProfile: recoil.SetterOrUpdater<string | undefined>;
304
+ };
305
+
306
+ declare const useAudio: () => {
307
+ startConversation: () => Promise<void>;
308
+ endConversation: () => Promise<void>;
309
+ audioConnection: "connecting" | "on" | "off";
310
+ isAiSpeaking: boolean;
311
+ wavRecorder: any;
312
+ wavStreamPlayer: any;
313
+ };
314
+
315
+ declare const useConfig: (accessToken?: string) => {
316
+ config: IChainlitConfig | undefined;
317
+ error: Error | undefined;
318
+ isLoading: boolean;
319
+ language: string;
320
+ };
321
+
322
+ declare const useAuth: () => {
323
+ authConfig: IAuthConfig;
178
324
  user: null;
179
325
  isReady: boolean;
180
326
  isAuthenticated: boolean;
181
327
  accessToken: string;
182
328
  logout: () => void;
183
329
  setAccessToken: () => void;
330
+ data?: undefined;
184
331
  } | {
185
- data: {
186
- requireLogin: boolean;
187
- passwordAuth: boolean;
188
- headerAuth: boolean;
189
- oauthProviders: string[];
190
- } | undefined;
332
+ data: IAuthConfig | undefined;
191
333
  user: IUser | null;
192
334
  isAuthenticated: boolean;
193
335
  isReady: boolean;
194
336
  accessToken: string | undefined;
195
- logout: () => Promise<void>;
337
+ logout: (reload?: boolean) => Promise<void>;
196
338
  setAccessToken: (token: string | null | undefined) => void;
339
+ authConfig?: undefined;
197
340
  };
198
341
 
199
342
  declare const fetcher: (client: ChainlitAPI, endpoint: string, token?: string) => Promise<any>;
200
- declare function useApi<T>(client: ChainlitAPI, path?: string | null, options?: SWRConfiguration): swr__internal.SWRResponse<T, Error, Partial<swr__internal.PublicConfiguration<T, Error, swr__internal.BareFetcher<T>>> | undefined>;
343
+ declare function useApi<T>(path?: string | null, { token, ...swrConfig }?: SWRConfiguration & {
344
+ token?: string;
345
+ }): swr__internal.SWRResponse<T, Error, Partial<swr__internal.PublicConfiguration<T, Error, swr__internal.BareFetcher<T>>> | undefined>;
201
346
 
202
347
  interface IThreadFilters {
203
348
  search?: string;
@@ -259,74 +404,8 @@ declare class ChainlitAPI extends APIBase {
259
404
  getOAuthEndpoint(provider: string): string;
260
405
  }
261
406
 
262
- declare const useChatInteract: () => {
263
- uploadFile: (client: ChainlitAPI, file: File, onProgress: (progress: number) => void) => {
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
- };
407
+ declare const defaultChainlitContext: undefined;
408
+ declare const ChainlitContext: react.Context<ChainlitAPI>;
330
409
 
331
410
  declare const nestMessages: (messages: IStep[]) => IStep[];
332
411
  declare const isLastMessage: (messages: IStep[], index: number) => boolean;
@@ -337,4 +416,8 @@ declare const updateMessageById: (messages: IStep[], messageId: string, updatedM
337
416
  declare const deleteMessageById: (messages: IStep[], messageId: string) => IStep[];
338
417
  declare const updateMessageContentById: (messages: IStep[], messageId: number | string, updatedContent: string, isSequence: boolean, isInput: boolean) => IStep[];
339
418
 
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 };
419
+ declare const WavRenderer: {
420
+ drawBars: (ctx: CanvasRenderingContext2D, data: Float32Array, cssWidth: number, cssHeight: number, color: string, pointCount?: number, barWidth?: number, barSpacing?: number, center?: boolean) => void;
421
+ };
422
+
423
+ export { APIBase, ActionSpec, AuthProvider, ChainlitAPI, ChainlitContext, ChatProfile, ClientError, ElementType, FileSpec, IAction, IAsk, IAudioConfig, IAudioElement, IAuthConfig, 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, WavRenderer, accessTokenState, actionState, addMessage, addMessageToParent, askUserState, audioConnectionState, authState, callFnState, chatProfileState, chatSettingsDefaultValueSelector, chatSettingsInputsState, chatSettingsValueState, configState, currentThreadIdState, defaultChainlitContext, deleteMessageById, elementState, fetcher, firstUserInteraction, hasMessageById, isAiSpeakingState, isLastMessage, loadingState, messagesState, nestMessages, sessionIdState, sessionState, sideViewState, tasklistState, threadHistoryState, threadIdToResumeState, tokenCountState, updateMessageById, updateMessageContentById, useApi, useAudio, useAuth, useChatData, useChatInteract, useChatMessages, useChatSession, useConfig, userState, wavRecorderState, wavStreamPlayerState };