@uraiagent/react 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/README.md +133 -0
  2. package/dist/Root.d.ts +8 -0
  3. package/dist/Widget.d.ts +1 -0
  4. package/dist/components/Agent/AgentAvatar.d.ts +1 -0
  5. package/dist/components/Agent/AgentInitialMessage.d.ts +3 -0
  6. package/dist/components/Agent/AgentMaximize.d.ts +1 -0
  7. package/dist/components/Agent/AgentMessage.d.ts +2 -0
  8. package/dist/components/Agent/AgentMessageWrapper.d.ts +9 -0
  9. package/dist/components/Agent/index.d.ts +5 -0
  10. package/dist/components/Chat/ChatFooter.d.ts +1 -0
  11. package/dist/components/Chat/ChatHeader.d.ts +1 -0
  12. package/dist/components/Chat/ChatLoader.d.ts +6 -0
  13. package/dist/components/Chat/ChatScreen.d.ts +1 -0
  14. package/dist/components/Chat/ChatWarning.d.ts +4 -0
  15. package/dist/components/Chat/WidgetTrigger.d.ts +10 -0
  16. package/dist/components/Chat/index.d.ts +6 -0
  17. package/dist/components/Dialog/Dialog.d.ts +12 -0
  18. package/dist/components/Dialog/index.d.ts +1 -0
  19. package/dist/components/Event/Confirmation.d.ts +4 -0
  20. package/dist/components/Event/EventMessage.d.ts +2 -0
  21. package/dist/components/Event/Fallback.d.ts +7 -0
  22. package/dist/components/Event/FollowUp.d.ts +4 -0
  23. package/dist/components/Event/Handoff.d.ts +4 -0
  24. package/dist/components/Event/Progress.d.ts +1 -0
  25. package/dist/components/Event/Text.d.ts +9 -0
  26. package/dist/components/Event/index.d.ts +7 -0
  27. package/dist/components/Loader.d.ts +5 -0
  28. package/dist/components/User/UserAvatar.d.ts +1 -0
  29. package/dist/components/User/UserMessage.d.ts +2 -0
  30. package/dist/components/User/index.d.ts +2 -0
  31. package/dist/components/Voice/VoiceRecorder.d.ts +4 -0
  32. package/dist/components/Voice/index.d.ts +1 -0
  33. package/dist/components/Vote/Vote.d.ts +3 -0
  34. package/dist/components/Vote/index.d.ts +1 -0
  35. package/dist/components/index.d.ts +6 -0
  36. package/dist/contexts/ConfigContext.d.ts +10 -0
  37. package/dist/contexts/DialogContext.d.ts +10 -0
  38. package/dist/contexts/LanguageProvider.d.ts +10 -0
  39. package/dist/contexts/MessageProvider.d.ts +12 -0
  40. package/dist/contexts/WidgetContext.d.ts +23 -0
  41. package/dist/contexts/index.d.ts +5 -0
  42. package/dist/contexts/session/SessionContext.d.ts +12 -0
  43. package/dist/contexts/session/index.d.ts +2 -0
  44. package/dist/contexts/session/session.api.d.ts +61 -0
  45. package/dist/contexts/session/session.cookie.d.ts +3 -0
  46. package/dist/contexts/socket/SocketContext.d.ts +15 -0
  47. package/dist/contexts/socket/channels.d.ts +2 -0
  48. package/dist/contexts/socket/index.d.ts +1 -0
  49. package/dist/contexts/socket/pusher.client.d.ts +9 -0
  50. package/dist/contexts/socket/ws.config.d.ts +15 -0
  51. package/dist/helpers/ComponentRegistry.d.ts +13 -0
  52. package/dist/helpers/MessageHandler.d.ts +78 -0
  53. package/dist/hooks/index.d.ts +11 -0
  54. package/dist/hooks/useAsyncFn.d.ts +23 -0
  55. package/dist/hooks/useAudioRecord.d.ts +27 -0
  56. package/dist/hooks/useCanSend.d.ts +6 -0
  57. package/dist/hooks/useChatLoading.d.ts +1 -0
  58. package/dist/hooks/useChatState.d.ts +1 -0
  59. package/dist/hooks/useDocumentDirection.d.ts +7 -0
  60. package/dist/hooks/useMountedState.d.ts +1 -0
  61. package/dist/hooks/useOutsideClick.d.ts +1 -0
  62. package/dist/hooks/useScrollTo.d.ts +2 -0
  63. package/dist/hooks/useSendMessage.d.ts +3 -0
  64. package/dist/hooks/useToast.d.ts +44 -0
  65. package/dist/hooks/useToggle.d.ts +2 -0
  66. package/dist/hooks/useTrigger.d.ts +1 -0
  67. package/dist/hooks/useVote.d.ts +2 -0
  68. package/dist/index.cjs.js +202 -0
  69. package/dist/index.d.ts +6 -0
  70. package/dist/index.es.js +88453 -0
  71. package/dist/interfaces/components.d.ts +9 -0
  72. package/dist/interfaces/config.d.ts +101 -0
  73. package/dist/interfaces/form.d.ts +15 -0
  74. package/dist/interfaces/helpers.d.ts +2 -0
  75. package/dist/interfaces/index.d.ts +5 -0
  76. package/dist/interfaces/messages.d.ts +127 -0
  77. package/dist/interfaces/translations.d.ts +3 -0
  78. package/dist/utils/cn.d.ts +2 -0
  79. package/dist/utils/icons.d.ts +1 -0
  80. package/dist/utils/index.d.ts +126 -0
  81. package/dist/utils/map.d.ts +9 -0
  82. package/dist-embed/agent.js +204 -0
  83. package/package.json +110 -0
@@ -0,0 +1,78 @@
1
+ import { ProgressEventType, AgentResponseUI, ConfirmationEvent, FollowUpProps, HandoffPayloadType, Message, Meta, UserMessageProps } from '../interfaces';
2
+ export type State = {
3
+ current_message: null | UserMessageProps;
4
+ progress_msg: null | string;
5
+ progress_event: null | ProgressEventType;
6
+ last_server_message_id: null | string;
7
+ messages: Message[];
8
+ meta: Meta;
9
+ logo: string;
10
+ client_state: Record<string, unknown>;
11
+ };
12
+ type Listener<T = State> = (value: T) => void;
13
+ type UpdaterFunction<T = State> = (old_value: T) => T;
14
+ export declare class ChatController {
15
+ listeners: Set<Listener<State>>;
16
+ private state;
17
+ private startSettleTimer;
18
+ private clearSettleTimer;
19
+ notify: () => void;
20
+ unSubscribe: (listener: Listener) => void;
21
+ subscribe: (listener: Listener) => () => void;
22
+ getSnapshot: () => State;
23
+ reset: () => void;
24
+ genId: (len?: number) => string;
25
+ isLoading: () => boolean;
26
+ setState: (newValue: State | UpdaterFunction) => void;
27
+ setStateUpdater: (updater: (draft: State) => void) => void;
28
+ select: <KT extends keyof State>(key: KT) => State[KT];
29
+ setProgress: (event: ProgressEventType | null, msg?: string | null) => void;
30
+ settle: () => void;
31
+ setLastServerMessageId: (_id: string | null) => void;
32
+ /** Bulk-load history messages without triggering loading state. */
33
+ loadMessages: (history: Array<{
34
+ id: string;
35
+ role: "user" | "agent";
36
+ text: string;
37
+ createdAt: string;
38
+ senderName?: string;
39
+ senderAvatarUrl?: string;
40
+ type?: string;
41
+ uiComponent?: {
42
+ componentType: string;
43
+ componentId?: string;
44
+ data?: {
45
+ structure?: Record<string, unknown>;
46
+ state?: Record<string, unknown>;
47
+ source?: Record<string, unknown>;
48
+ [k: string]: unknown;
49
+ };
50
+ };
51
+ }>) => void;
52
+ /** Optimistically add the user's message and mark as loading. */
53
+ appendUserMessage: (message: string) => string;
54
+ /** Add a complete agent message (non-streaming). */
55
+ appendAgentMessageFull: (id: string, text: string, senderName?: string, senderAvatarUrl?: string) => void;
56
+ /** Append a streaming chunk to the current in-progress agent message. */
57
+ appendAgentMessage: (text: string) => void;
58
+ /**
59
+ * Append a streaming chunk identified by a stable server-side message id.
60
+ * This is the preferred method for streaming — it does not rely on
61
+ * current_message and always finds or creates the right bubble.
62
+ */
63
+ appendStreamingChunk: (id: string, text: string, senderName?: string, senderAvatarUrl?: string) => void;
64
+ handleHandoff: (payload: HandoffPayloadType) => void;
65
+ handleFollowUp: (payload: FollowUpProps) => void;
66
+ handleConfirmation: (payload: ConfirmationEvent) => void;
67
+ handleUiEvent: (response: AgentResponseUI) => void;
68
+ /**
69
+ * Merge a state patch into an already-rendered widget message (server `message.update`
70
+ * or optimistic local update) so it re-renders its resolved look (e.g. an approval that
71
+ * hides its buttons). Looks up the message by id and merges into the widget's state.
72
+ */
73
+ patchMessage: (messageId: string, statePatch: Record<string, unknown>) => void;
74
+ private getAgentMessage;
75
+ private appendExistingMessage;
76
+ private addNewAgentMessage;
77
+ }
78
+ export {};
@@ -0,0 +1,11 @@
1
+ export * from './useAsyncFn.ts';
2
+ export * from './useAudioRecord.ts';
3
+ export * from './useMountedState';
4
+ export * from './useScrollTo';
5
+ export * from './useToggle';
6
+ export * from './useVote';
7
+ export * from './useCanSend';
8
+ export * from './useChatLoading';
9
+ export * from './useSendMessage';
10
+ export * from './useChatState';
11
+ export * from './useToast';
@@ -0,0 +1,23 @@
1
+ import { DependencyList } from 'react';
2
+ import { FunctionReturningPromise, PromiseType } from '../interfaces';
3
+ export type AsyncState<T> = {
4
+ loading: boolean;
5
+ error?: undefined;
6
+ value?: undefined;
7
+ } | {
8
+ loading: true;
9
+ error?: Error | undefined;
10
+ value?: T;
11
+ } | {
12
+ loading: false;
13
+ error: Error;
14
+ value?: undefined;
15
+ } | {
16
+ loading: false;
17
+ error?: undefined;
18
+ value: T;
19
+ };
20
+ type StateFromFunctionReturningPromise<T extends FunctionReturningPromise> = AsyncState<PromiseType<ReturnType<T>>>;
21
+ export type AsyncFnReturn<T extends FunctionReturningPromise = FunctionReturningPromise> = [StateFromFunctionReturningPromise<T>, T];
22
+ export declare function useAsyncFn<T extends FunctionReturningPromise>(fn: T, deps?: DependencyList, initialState?: StateFromFunctionReturningPromise<T>): AsyncFnReturn<T>;
23
+ export {};
@@ -0,0 +1,27 @@
1
+ export interface recorderControls {
2
+ startRecording: () => void;
3
+ stopRecording: () => void;
4
+ togglePauseResume: () => void;
5
+ recordingBlob?: Blob;
6
+ isRecording: boolean;
7
+ isPaused: boolean;
8
+ recordingTime: number;
9
+ mediaRecorder?: MediaRecorder;
10
+ }
11
+ export type MediaAudioTrackConstraints = Pick<MediaTrackConstraints, "deviceId" | "groupId" | "autoGainControl" | "channelCount" | "echoCancellation" | "noiseSuppression" | "sampleRate" | "sampleSize">;
12
+ /**
13
+ * @returns Controls for the recording. Details of returned controls are given below
14
+ *
15
+ * @param `audioTrackConstraints`: Takes a {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackSettings#instance_properties_of_audio_tracks subset} of `MediaTrackConstraints` that apply to the audio track
16
+ * @param `onNotAllowedOrFound`: A method that gets called when the getUserMedia promise is rejected. It receives the DOMException as its input.
17
+ *
18
+ * @details `startRecording`: Calling this method would result in the recording to start. Sets `isRecording` to true
19
+ * @details `stopRecording`: This results in a recording in progress being stopped and the resulting audio being present in `recordingBlob`. Sets `isRecording` to false
20
+ * @details `togglePauseResume`: Calling this method would pause the recording if it is currently running or resume if it is paused. Toggles the value `isPaused`
21
+ * @details `recordingBlob`: This is the recording blob that is created after `stopRecording` has been called
22
+ * @details `isRecording`: A boolean value that represents whether a recording is currently in progress
23
+ * @details `isPaused`: A boolean value that represents whether a recording in progress is paused
24
+ * @details `recordingTime`: Number of seconds that the recording has gone on. This is updated every second
25
+ * @details `mediaRecorder`: The current mediaRecorder in use
26
+ */
27
+ export declare const useAudioRecorder: (audioTrackConstraints?: MediaAudioTrackConstraints, onNotAllowedOrFound?: (exception: DOMException) => any, mediaRecorderOptions?: MediaRecorderOptions) => recorderControls;
@@ -0,0 +1,6 @@
1
+ export declare function useCanSend({ input }: {
2
+ input?: string;
3
+ }): {
4
+ canSend: boolean;
5
+ cantSendReason: "disconnected" | "loading" | "empty";
6
+ };
@@ -0,0 +1 @@
1
+ export declare function useChatLoading(): boolean;
@@ -0,0 +1 @@
1
+ export declare function useChatState(): import('../helpers/MessageHandler').State;
@@ -0,0 +1,7 @@
1
+ type Dir = "rtl" | "ltr";
2
+ export declare function useDocumentDirection(): {
3
+ rtl: boolean;
4
+ ltr: boolean;
5
+ direction: Dir;
6
+ };
7
+ export {};
@@ -0,0 +1 @@
1
+ export declare function useMountedState(): () => boolean;
@@ -0,0 +1 @@
1
+ export declare const useOutsideClick: (callback: () => void, ref: any) => void;
@@ -0,0 +1,2 @@
1
+ import { RefObject } from 'react';
2
+ export declare const useScrollToPercentage: (elementRef: RefObject<HTMLElement>) => [(percentageX: number, percentageY: number) => void];
@@ -0,0 +1,3 @@
1
+ export declare function useSendMessage(): {
2
+ send: (message: string) => Promise<void>;
3
+ };
@@ -0,0 +1,44 @@
1
+ import { ToastActionElement, ToastProps } from '../../builder/form/ui/toast';
2
+ import * as React from "react";
3
+ type ToasterToast = ToastProps & {
4
+ id: string;
5
+ title?: React.ReactNode;
6
+ description?: React.ReactNode;
7
+ action?: ToastActionElement;
8
+ };
9
+ declare const actionTypes: {
10
+ readonly ADD_TOAST: "ADD_TOAST";
11
+ readonly UPDATE_TOAST: "UPDATE_TOAST";
12
+ readonly DISMISS_TOAST: "DISMISS_TOAST";
13
+ readonly REMOVE_TOAST: "REMOVE_TOAST";
14
+ };
15
+ type ActionType = typeof actionTypes;
16
+ type Action = {
17
+ type: ActionType["ADD_TOAST"];
18
+ toast: ToasterToast;
19
+ } | {
20
+ type: ActionType["UPDATE_TOAST"];
21
+ toast: Partial<ToasterToast>;
22
+ } | {
23
+ type: ActionType["DISMISS_TOAST"];
24
+ toastId?: ToasterToast["id"];
25
+ } | {
26
+ type: ActionType["REMOVE_TOAST"];
27
+ toastId?: ToasterToast["id"];
28
+ };
29
+ interface State {
30
+ toasts: ToasterToast[];
31
+ }
32
+ export declare const reducer: (state: State, action: Action) => State;
33
+ type Toast = Omit<ToasterToast, "id">;
34
+ declare function toast({ ...props }: Toast): {
35
+ id: string;
36
+ dismiss: () => void;
37
+ update: (props: ToasterToast) => void;
38
+ };
39
+ declare function useToast(): {
40
+ toast: typeof toast;
41
+ dismiss: (toastId?: string) => void;
42
+ toasts: ToasterToast[];
43
+ };
44
+ export { useToast, toast };
@@ -0,0 +1,2 @@
1
+ import { Dispatch, SetStateAction } from 'react';
2
+ export declare function useToggle(defaultValue?: boolean): [boolean, () => void, Dispatch<SetStateAction<boolean>>];
@@ -0,0 +1 @@
1
+ export declare const useTrigger: (selector?: string, toggle?: () => void) => void;
@@ -0,0 +1,2 @@
1
+ export declare function useUpvote(id: string): import('./useAsyncFn').AsyncFnReturn<() => Promise<void>>;
2
+ export declare function useDownvote(id: string): import('./useAsyncFn').AsyncFnReturn<() => Promise<void>>;