@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,9 @@
1
+ import { AgentMessageProps } from '.';
2
+ export type ComponentProps<TData> = AgentMessageProps<TData>;
3
+ export type ComponentType = {
4
+ key: string;
5
+ component: React.ElementType;
6
+ };
7
+ export type OptionsType = {
8
+ components?: ComponentType[];
9
+ };
@@ -0,0 +1,101 @@
1
+ import { ReactNode } from 'react';
2
+ import { HandoffPayloadType } from '.';
3
+ import { ComponentType } from './components';
4
+ type User = {
5
+ name?: string;
6
+ email?: string;
7
+ phone: string;
8
+ avatar?: string;
9
+ custom?: Record<string, string>;
10
+ };
11
+ type Agent = {
12
+ name?: string;
13
+ logo?: string;
14
+ };
15
+ type ContainerProps = React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
16
+ /**
17
+ * Public, grouped widget configuration.
18
+ *
19
+ * Styling is NOT configured here — the widget is pure namespaced CSS
20
+ * (`.uraiagent-*`) + design tokens (`--uw-*`). Retheme from your own stylesheet
21
+ * (e.g. `.uraiagent-root { --uw-color-primary: #6d28d9 }`). So there is no
22
+ * `theme.tokens` / `theme.classNames` — only the host `container` survives.
23
+ */
24
+ export type WidgetConfig = {
25
+ identity: {
26
+ /** Widget ID from the dashboard. */
27
+ token: string;
28
+ organizationId: string;
29
+ agentId: string;
30
+ };
31
+ connection: {
32
+ /** Backend API base URL, e.g. "https://api.example.com". */
33
+ api: string;
34
+ headers?: Record<string, string>;
35
+ queryParams?: Record<string, string>;
36
+ };
37
+ content?: {
38
+ initialMessage?: string;
39
+ inputPlaceholder?: string;
40
+ description?: {
41
+ visible?: boolean;
42
+ text?: string;
43
+ };
44
+ /** Custom node rendered inside the trigger button. */
45
+ triggerIcon?: ReactNode;
46
+ };
47
+ behavior?: {
48
+ defaultOpen?: boolean;
49
+ closeOutside?: boolean;
50
+ debug?: boolean;
51
+ warn?: boolean;
52
+ language?: string;
53
+ };
54
+ people?: {
55
+ user?: User;
56
+ agent?: Agent;
57
+ };
58
+ on?: {
59
+ close?: () => void;
60
+ handoff?: (handout: HandoffPayloadType) => void;
61
+ };
62
+ /** Custom message/event components. */
63
+ components?: ComponentType[];
64
+ /** Props spread onto the widget's host container <div>. */
65
+ container?: ContainerProps;
66
+ };
67
+ /**
68
+ * Flat, resolved config — the shape every internal component reads via
69
+ * `useConfig()`. Produced from `WidgetConfig` by `normalizeConfig`.
70
+ */
71
+ export type OptionsProps = {
72
+ token: string;
73
+ organizationId: string;
74
+ agentId: string;
75
+ api: string;
76
+ headers?: Record<string, string>;
77
+ queryParams?: Record<string, string>;
78
+ initialMessage?: string;
79
+ inputPlaceholder?: string;
80
+ description?: {
81
+ visible?: boolean;
82
+ text?: string;
83
+ };
84
+ triggerIcon?: ReactNode;
85
+ defaultOpen?: boolean;
86
+ closeOutside?: boolean;
87
+ debug?: boolean;
88
+ warn?: boolean;
89
+ language?: string;
90
+ user?: User;
91
+ agent?: Agent;
92
+ components?: ComponentType[];
93
+ onClose?: () => void;
94
+ onHandoff?: (handout: HandoffPayloadType) => void;
95
+ container?: ContainerProps;
96
+ };
97
+ /** Flatten the grouped public config into the internal flat shape. */
98
+ export declare function normalizeConfig(c: WidgetConfig): OptionsProps;
99
+ /** Back-compat alias for the flat shape. */
100
+ export type ConfigProps = OptionsProps;
101
+ export {};
@@ -0,0 +1,15 @@
1
+ export type FormFieldType = {
2
+ type: string;
3
+ name: string;
4
+ label: string;
5
+ value: string | boolean | Date;
6
+ checked: boolean;
7
+ setValue: (value: string | boolean) => void;
8
+ placeholder?: string;
9
+ required: boolean;
10
+ disabled: boolean;
11
+ description?: string;
12
+ onChange: (value: string | boolean | Date) => void;
13
+ onSelect: (value: string | boolean | Date) => void;
14
+ };
15
+ export type FormFieldProps = Omit<FormFieldType, "onChange" | "onSelect" | "setValue">;
@@ -0,0 +1,2 @@
1
+ export type PromiseType<P extends Promise<any>> = P extends Promise<infer T> ? T : never;
2
+ export type FunctionReturningPromise = (...args: any[]) => Promise<any>;
@@ -0,0 +1,5 @@
1
+ export * from './helpers';
2
+ export * from './messages';
3
+ export * from './components';
4
+ export * from './config';
5
+ export * from './translations';
@@ -0,0 +1,127 @@
1
+ import { FormFieldProps } from './form';
2
+ export type Meta = {
3
+ count: number;
4
+ page: number;
5
+ limit: number;
6
+ total_pages: number;
7
+ has_next: boolean;
8
+ has_previous: boolean;
9
+ };
10
+ export type AgentMessageProps<TData = Record<string, unknown>> = {
11
+ _id: string;
12
+ from: "agent";
13
+ type: string;
14
+ data: TData;
15
+ senderName?: string;
16
+ senderAvatarUrl?: string;
17
+ attachement?: {
18
+ type: string;
19
+ value: string;
20
+ };
21
+ createdAt: string;
22
+ };
23
+ export type UserMessageProps = {
24
+ _id: string;
25
+ from: "user";
26
+ message: string;
27
+ attachement?: {
28
+ type: string;
29
+ value: string;
30
+ };
31
+ createdAt: string;
32
+ };
33
+ export type EventMessageProps<TData = Record<string, unknown>> = {
34
+ _id: string;
35
+ from: "event";
36
+ type: string;
37
+ data: TData;
38
+ createdAt: string;
39
+ };
40
+ export type UserMessageFormProps = Omit<UserMessageProps, "from" | "_id" | "createdAt" | "session_id">;
41
+ export type Message = AgentMessageProps | UserMessageProps | EventMessageProps;
42
+ export type HistoryMessage = {
43
+ _id: string;
44
+ agent: {
45
+ name: string;
46
+ logo: string;
47
+ _id: string;
48
+ };
49
+ event?: {
50
+ _id: string;
51
+ type: string;
52
+ status: string;
53
+ data: Record<string, any>;
54
+ };
55
+ conversation_id: string;
56
+ source: "user" | "agent" | "support" | "event";
57
+ contact?: {
58
+ name: string;
59
+ email: string;
60
+ };
61
+ assigned?: {
62
+ public_name: string;
63
+ avatar: string;
64
+ };
65
+ attachment?: {
66
+ type: string;
67
+ value: string;
68
+ };
69
+ api_requests?: Record<string, any>;
70
+ debug?: Record<string, any>;
71
+ message: string;
72
+ createdAt: string;
73
+ };
74
+ export type HandoffPayloadType = {
75
+ summary: string;
76
+ sentiment: "happy" | "angry" | "neutral";
77
+ };
78
+ export type FollowUpProps = {
79
+ follow_up_questions: {
80
+ label: string;
81
+ value: string;
82
+ }[];
83
+ };
84
+ export type ConfirmationEvent = {
85
+ event_id: string;
86
+ status: string;
87
+ };
88
+ export type AgentResponseUI = {
89
+ _id: string;
90
+ type: "ui_form";
91
+ message_id: string;
92
+ action: {
93
+ submit_url: string;
94
+ request_type: string;
95
+ fields: FormFieldProps[];
96
+ };
97
+ createdAt: string;
98
+ } | {
99
+ _id: string;
100
+ key: string;
101
+ type: "ui_component";
102
+ message_id: string;
103
+ request_response: Record<string, any>;
104
+ senderName?: string;
105
+ senderAvatarUrl?: string;
106
+ createdAt: string;
107
+ } | {
108
+ _id: string;
109
+ type: "ui_confirmation";
110
+ message_id: string;
111
+ createdAt: string;
112
+ };
113
+ export declare enum EventEnum {
114
+ API_ACTION = "API_ACTION",
115
+ CONFIRM_EVENT = "CONFIRM_EVENT",
116
+ FORM_EVENT = "FORM_EVENT",
117
+ INTERFACE_EVENT = "INTERFACE_EVENT",
118
+ CALL_WEBHOOK = "CALL_WEBHOOK"
119
+ }
120
+ export declare enum ProgressEventType {
121
+ LOADING = "LOADING",
122
+ TYPING = "TYPING",
123
+ THINKING = "THINKING",
124
+ INFO = "INFO",
125
+ ERROR = "ERROR",
126
+ WARNING = "WARNING"
127
+ }
@@ -0,0 +1,3 @@
1
+ export type TranslatableMessages = {
2
+ [key: string]: string;
3
+ };
@@ -0,0 +1,2 @@
1
+ import { ClassValue } from 'clsx';
2
+ export default function cn(...inputs: ClassValue[]): string;
@@ -0,0 +1 @@
1
+ export declare const FileSVGDraw: () => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,126 @@
1
+ import { FormFieldType } from '../interfaces/form';
2
+ import { default as json } from '../../../package.json';
3
+ import { z } from 'zod';
4
+ export declare const isServer: boolean;
5
+ declare const isEmpty: (value: string | object | any[] | undefined) => boolean;
6
+ declare const getLast: <T>(arr: T[]) => T | undefined;
7
+ declare const get: <K extends keyof typeof json>(key: K) => {
8
+ name: string;
9
+ private: boolean;
10
+ version: string;
11
+ type: string;
12
+ description: string;
13
+ publishConfig: {
14
+ access: string;
15
+ };
16
+ scripts: {
17
+ dev: string;
18
+ clean: string;
19
+ "build:embed": string;
20
+ "build:lib": string;
21
+ format: string;
22
+ lint: string;
23
+ preview: string;
24
+ release: string;
25
+ prepublishOnly: string;
26
+ "update-dashboard-agent": string;
27
+ };
28
+ peerDependencies: {
29
+ "framer-motion": string;
30
+ postcss: string;
31
+ react: string;
32
+ };
33
+ devDependencies: {
34
+ "@eslint/js": string;
35
+ "@types/node": string;
36
+ "@types/react": string;
37
+ "@types/react-dom": string;
38
+ "@typescript-eslint/eslint-plugin": string;
39
+ "@typescript-eslint/parser": string;
40
+ "@vitejs/plugin-react": string;
41
+ eslint: string;
42
+ "eslint-plugin-react-hooks": string;
43
+ "eslint-plugin-react-refresh": string;
44
+ postcss: string;
45
+ prettier: string;
46
+ react: string;
47
+ "react-dom": string;
48
+ "release-it": string;
49
+ typescript: string;
50
+ "typescript-eslint": string;
51
+ vite: string;
52
+ "vite-plugin-dts": string;
53
+ "vite-tsconfig-paths": string;
54
+ };
55
+ files: string[];
56
+ author: {
57
+ name: string;
58
+ url: string;
59
+ };
60
+ main: string;
61
+ types: string;
62
+ exports: {
63
+ ".": {
64
+ require: string;
65
+ import: string;
66
+ default: string;
67
+ types: string;
68
+ };
69
+ };
70
+ dependencies: {
71
+ "@heroicons/react": string;
72
+ "@hookform/resolvers": string;
73
+ "@radix-ui/react-avatar": string;
74
+ "@radix-ui/react-checkbox": string;
75
+ "@radix-ui/react-dialog": string;
76
+ "@radix-ui/react-icons": string;
77
+ "@radix-ui/react-label": string;
78
+ "@radix-ui/react-popover": string;
79
+ "@radix-ui/react-progress": string;
80
+ "@radix-ui/react-radio-group": string;
81
+ "@radix-ui/react-scroll-area": string;
82
+ "@radix-ui/react-select": string;
83
+ "@radix-ui/react-separator": string;
84
+ "@radix-ui/react-slider": string;
85
+ "@radix-ui/react-slot": string;
86
+ "@radix-ui/react-switch": string;
87
+ "@radix-ui/react-tabs": string;
88
+ "@radix-ui/react-toast": string;
89
+ "@uidotdev/usehooks": string;
90
+ "class-variance-authority": string;
91
+ clsx: string;
92
+ cmdk: string;
93
+ "date-fns": string;
94
+ "framer-motion": string;
95
+ "html-react-parser": string;
96
+ immer: string;
97
+ "input-otp": string;
98
+ "lucide-react": string;
99
+ nanoid: string;
100
+ "pusher-js": string;
101
+ "react-day-picker": string;
102
+ "react-dropzone": string;
103
+ "react-hook-form": string;
104
+ "react-intersection-observer": string;
105
+ "react-markdown": string;
106
+ "react-phone-number-input": string;
107
+ "react-textarea-autosize": string;
108
+ "remark-gfm": string;
109
+ sonner: string;
110
+ vaul: string;
111
+ zod: string;
112
+ };
113
+ }[K];
114
+ declare const randomString: (length?: number) => string;
115
+ declare const formatDates: (date: string) => string;
116
+ /** Per-message timestamp shown inside the bubble, e.g. "27 Jun, 1:24 PM". */
117
+ declare const formatMessageTime: (iso: string | undefined) => string | null;
118
+ declare const getCurrentDate: () => string;
119
+ declare const parse_json: <T extends Record<string, any>>(jsonString: string) => T | null;
120
+ declare const convertLinkToElement: (message: string) => string;
121
+ declare const getLastObject: (object: Record<string, any>) => any;
122
+ export declare const generateZodSchema: (formFields: FormFieldType[]) => z.ZodObject<{
123
+ [x: string]: any;
124
+ }, z.core.$strip>;
125
+ export { isEmpty, getLast, get, randomString, formatDates, getCurrentDate, formatMessageTime, parse_json, convertLinkToElement, getLastObject, };
126
+ export declare const composeRoot: (id: string, fluid?: boolean) => HTMLElement;
@@ -0,0 +1,9 @@
1
+ import { ReactNode } from 'react';
2
+ type RenderFunction<T> = (item: T, index: number) => ReactNode;
3
+ interface MapProps<T> {
4
+ data: T[];
5
+ render: RenderFunction<T>;
6
+ fallback?: ReactNode;
7
+ }
8
+ export declare function Map<T>({ data, render, fallback }: MapProps<T>): string | number | bigint | true | import('react').ReactElement<unknown, string | import('react').JSXElementConstructor<any>> | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import('react').ReactPortal | import('react').ReactElement<unknown, string | import('react').JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null;
9
+ export {};