@aigentyc/chat-sdk 0.1.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.
Files changed (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +156 -0
  3. package/dist/JsonRenderResult-Ftw4AKwb.d.cts +18 -0
  4. package/dist/JsonRenderResult-Ftw4AKwb.d.ts +18 -0
  5. package/dist/JsonRenderResult-GQOYPLVH.cjs +15 -0
  6. package/dist/JsonRenderResult-GQOYPLVH.cjs.map +1 -0
  7. package/dist/JsonRenderResult-ZFJ6VWMS.js +6 -0
  8. package/dist/JsonRenderResult-ZFJ6VWMS.js.map +1 -0
  9. package/dist/SlotsContext-CBtt36al.d.ts +148 -0
  10. package/dist/SlotsContext-CHvISDJT.d.cts +148 -0
  11. package/dist/VisualizationRenderer-FNFYNN66.js +5 -0
  12. package/dist/VisualizationRenderer-FNFYNN66.js.map +1 -0
  13. package/dist/VisualizationRenderer-VKMZXRUX.cjs +20 -0
  14. package/dist/VisualizationRenderer-VKMZXRUX.cjs.map +1 -0
  15. package/dist/ai-elements.cjs +4608 -0
  16. package/dist/ai-elements.cjs.map +1 -0
  17. package/dist/ai-elements.d.cts +897 -0
  18. package/dist/ai-elements.d.ts +897 -0
  19. package/dist/ai-elements.js +4363 -0
  20. package/dist/ai-elements.js.map +1 -0
  21. package/dist/chunk-3MP2EGEJ.cjs +270 -0
  22. package/dist/chunk-3MP2EGEJ.cjs.map +1 -0
  23. package/dist/chunk-3RW7O444.js +26 -0
  24. package/dist/chunk-3RW7O444.js.map +1 -0
  25. package/dist/chunk-42ARGQXE.js +51 -0
  26. package/dist/chunk-42ARGQXE.js.map +1 -0
  27. package/dist/chunk-4FBVV64J.js +257 -0
  28. package/dist/chunk-4FBVV64J.js.map +1 -0
  29. package/dist/chunk-4QT25AXI.js +21 -0
  30. package/dist/chunk-4QT25AXI.js.map +1 -0
  31. package/dist/chunk-525KS5HM.cjs +30 -0
  32. package/dist/chunk-525KS5HM.cjs.map +1 -0
  33. package/dist/chunk-5F3O3ZJH.js +299 -0
  34. package/dist/chunk-5F3O3ZJH.js.map +1 -0
  35. package/dist/chunk-5QSXB6UL.cjs +259 -0
  36. package/dist/chunk-5QSXB6UL.cjs.map +1 -0
  37. package/dist/chunk-5T4FJ2SR.js +664 -0
  38. package/dist/chunk-5T4FJ2SR.js.map +1 -0
  39. package/dist/chunk-7BNYTOTE.cjs +67 -0
  40. package/dist/chunk-7BNYTOTE.cjs.map +1 -0
  41. package/dist/chunk-AWAJOSFP.cjs +96 -0
  42. package/dist/chunk-AWAJOSFP.cjs.map +1 -0
  43. package/dist/chunk-BKDV2H6Z.js +224 -0
  44. package/dist/chunk-BKDV2H6Z.js.map +1 -0
  45. package/dist/chunk-FQN6OBGN.cjs +171 -0
  46. package/dist/chunk-FQN6OBGN.cjs.map +1 -0
  47. package/dist/chunk-FYPJSHCL.js +190 -0
  48. package/dist/chunk-FYPJSHCL.js.map +1 -0
  49. package/dist/chunk-J2H6MLQF.cjs +680 -0
  50. package/dist/chunk-J2H6MLQF.cjs.map +1 -0
  51. package/dist/chunk-J2K7EJYP.cjs +198 -0
  52. package/dist/chunk-J2K7EJYP.cjs.map +1 -0
  53. package/dist/chunk-JI5KCSOI.cjs +23 -0
  54. package/dist/chunk-JI5KCSOI.cjs.map +1 -0
  55. package/dist/chunk-JOO6C3XT.cjs +44 -0
  56. package/dist/chunk-JOO6C3XT.cjs.map +1 -0
  57. package/dist/chunk-KBGPBUTI.cjs +78 -0
  58. package/dist/chunk-KBGPBUTI.cjs.map +1 -0
  59. package/dist/chunk-MT2AMINB.js +75 -0
  60. package/dist/chunk-MT2AMINB.js.map +1 -0
  61. package/dist/chunk-MZQKGNWF.js +4 -0
  62. package/dist/chunk-MZQKGNWF.js.map +1 -0
  63. package/dist/chunk-NG7OTWXQ.cjs +226 -0
  64. package/dist/chunk-NG7OTWXQ.cjs.map +1 -0
  65. package/dist/chunk-NPJKLYLV.js +68 -0
  66. package/dist/chunk-NPJKLYLV.js.map +1 -0
  67. package/dist/chunk-NW2ESHRV.js +685 -0
  68. package/dist/chunk-NW2ESHRV.js.map +1 -0
  69. package/dist/chunk-NWF735F5.js +1631 -0
  70. package/dist/chunk-NWF735F5.js.map +1 -0
  71. package/dist/chunk-NYQSM3EB.cjs +305 -0
  72. package/dist/chunk-NYQSM3EB.cjs.map +1 -0
  73. package/dist/chunk-OU7OROOE.cjs +1643 -0
  74. package/dist/chunk-OU7OROOE.cjs.map +1 -0
  75. package/dist/chunk-PS3U7T37.js +42 -0
  76. package/dist/chunk-PS3U7T37.js.map +1 -0
  77. package/dist/chunk-Q7T3VAJV.cjs +687 -0
  78. package/dist/chunk-Q7T3VAJV.cjs.map +1 -0
  79. package/dist/chunk-QYCEHFAB.js +265 -0
  80. package/dist/chunk-QYCEHFAB.js.map +1 -0
  81. package/dist/chunk-RPDJXB3U.js +676 -0
  82. package/dist/chunk-RPDJXB3U.js.map +1 -0
  83. package/dist/chunk-UKEL7FWS.js +64 -0
  84. package/dist/chunk-UKEL7FWS.js.map +1 -0
  85. package/dist/chunk-VS3NZ7FX.js +164 -0
  86. package/dist/chunk-VS3NZ7FX.js.map +1 -0
  87. package/dist/chunk-WZLWAVSS.cjs +73 -0
  88. package/dist/chunk-WZLWAVSS.cjs.map +1 -0
  89. package/dist/chunk-X5YEOOPK.cjs +758 -0
  90. package/dist/chunk-X5YEOOPK.cjs.map +1 -0
  91. package/dist/chunk-X7R334SB.cjs +5 -0
  92. package/dist/chunk-X7R334SB.cjs.map +1 -0
  93. package/dist/chunk-XXNDL5SJ.cjs +432 -0
  94. package/dist/chunk-XXNDL5SJ.cjs.map +1 -0
  95. package/dist/chunk-YQELMJW5.js +429 -0
  96. package/dist/chunk-YQELMJW5.js.map +1 -0
  97. package/dist/components.cjs +551 -0
  98. package/dist/components.cjs.map +1 -0
  99. package/dist/components.d.cts +181 -0
  100. package/dist/components.d.ts +181 -0
  101. package/dist/components.js +483 -0
  102. package/dist/components.js.map +1 -0
  103. package/dist/core.cjs +283 -0
  104. package/dist/core.cjs.map +1 -0
  105. package/dist/core.d.cts +455 -0
  106. package/dist/core.d.ts +455 -0
  107. package/dist/core.js +241 -0
  108. package/dist/core.js.map +1 -0
  109. package/dist/hooks.cjs +324 -0
  110. package/dist/hooks.cjs.map +1 -0
  111. package/dist/hooks.d.cts +163 -0
  112. package/dist/hooks.d.ts +163 -0
  113. package/dist/hooks.js +277 -0
  114. package/dist/hooks.js.map +1 -0
  115. package/dist/i18n.cjs +26 -0
  116. package/dist/i18n.cjs.map +1 -0
  117. package/dist/i18n.d.cts +50 -0
  118. package/dist/i18n.d.ts +50 -0
  119. package/dist/i18n.js +5 -0
  120. package/dist/i18n.js.map +1 -0
  121. package/dist/index.cjs +466 -0
  122. package/dist/index.cjs.map +1 -0
  123. package/dist/index.d.cts +80 -0
  124. package/dist/index.d.ts +80 -0
  125. package/dist/index.js +438 -0
  126. package/dist/index.js.map +1 -0
  127. package/dist/interaction-tracker-D9P1Oq4j.d.cts +83 -0
  128. package/dist/interaction-tracker-D9P1Oq4j.d.ts +83 -0
  129. package/dist/json-render.cjs +23 -0
  130. package/dist/json-render.cjs.map +1 -0
  131. package/dist/json-render.d.cts +857 -0
  132. package/dist/json-render.d.ts +857 -0
  133. package/dist/json-render.js +6 -0
  134. package/dist/json-render.js.map +1 -0
  135. package/dist/live-chat-transport-4XLOIPOE.js +4 -0
  136. package/dist/live-chat-transport-4XLOIPOE.js.map +1 -0
  137. package/dist/live-chat-transport-ALVRGWX7.cjs +13 -0
  138. package/dist/live-chat-transport-ALVRGWX7.cjs.map +1 -0
  139. package/dist/select-B4l9yoyn.d.cts +99 -0
  140. package/dist/select-B4l9yoyn.d.ts +99 -0
  141. package/dist/styles.css +2 -0
  142. package/dist/theme.cjs +18 -0
  143. package/dist/theme.cjs.map +1 -0
  144. package/dist/theme.d.cts +55 -0
  145. package/dist/theme.d.ts +55 -0
  146. package/dist/theme.js +5 -0
  147. package/dist/theme.js.map +1 -0
  148. package/dist/tools.cjs +32 -0
  149. package/dist/tools.cjs.map +1 -0
  150. package/dist/tools.d.cts +117 -0
  151. package/dist/tools.d.ts +117 -0
  152. package/dist/tools.js +11 -0
  153. package/dist/tools.js.map +1 -0
  154. package/dist/types-DKJ_-nbG.d.cts +349 -0
  155. package/dist/types-DKJ_-nbG.d.ts +349 -0
  156. package/dist/ui.cjs +667 -0
  157. package/dist/ui.cjs.map +1 -0
  158. package/dist/ui.d.cts +95 -0
  159. package/dist/ui.d.ts +95 -0
  160. package/dist/ui.js +414 -0
  161. package/dist/ui.js.map +1 -0
  162. package/package.json +255 -0
@@ -0,0 +1,349 @@
1
+ import { ComponentType } from 'react';
2
+
3
+ /**
4
+ * UI language code.
5
+ *
6
+ * `"en"` and `"he"` are first-class supported locales.
7
+ * Any other BCP-47 string is accepted for custom translation overrides.
8
+ */
9
+ type Language = "en" | "he" | (string & {});
10
+ /**
11
+ * Full theme configuration for the chat UI.
12
+ *
13
+ * All values are CSS color/font strings (e.g. `"#eb1d22"`, `"Inter, sans-serif"`).
14
+ */
15
+ interface ThemeConfig {
16
+ /** Primary brand color (buttons, links, accents) */
17
+ primaryColor?: string;
18
+ /** Secondary accent color (highlights, badges) */
19
+ accentColor?: string;
20
+ /** Main background color of the chat panel */
21
+ backgroundColor?: string;
22
+ /** Primary text color */
23
+ textColor?: string;
24
+ /** Color used for links inside chat messages */
25
+ linkColor?: string;
26
+ /** Loader / spinner color */
27
+ loaderColor?: string;
28
+ /** Background color of user message bubbles */
29
+ userBubbleColor?: string;
30
+ /** Background color of assistant message bubbles */
31
+ assistantBubbleColor?: string;
32
+ /** Text color inside assistant message bubbles */
33
+ assistantBubbleTextColor?: string;
34
+ /** Secondary / muted background (input bar, hover states) */
35
+ secondaryColor?: string;
36
+ /** Border color throughout the UI */
37
+ borderColor?: string;
38
+ /** Placeholder text color (inputs, search) */
39
+ placeholderColor?: string;
40
+ /** CSS padding for assistant bubbles (e.g. `"20px"`, `"16px 24px"`) */
41
+ assistantBubblePadding?: string;
42
+ /** Max width of assistant messages (e.g. `"100%"`, `"800px"`). Default: `"95%"` */
43
+ assistantMaxWidth?: string;
44
+ /** Background color for the floating button (overrides primaryColor) */
45
+ buttonBgColor?: string;
46
+ /** Border-radius for the floating button (e.g. `"50%"`, `"12px"`) */
47
+ buttonBorderRadius?: string;
48
+ /** Primary font-family for the widget (e.g. `"Inter, sans-serif"`) */
49
+ fontFamily?: string;
50
+ /** Font-family for headings inside chat responses */
51
+ headingFontFamily?: string;
52
+ }
53
+ /**
54
+ * A single quick-action question shown on the welcome page or as a
55
+ * contextual suggestion during a conversation.
56
+ */
57
+ interface QuestionConfig {
58
+ /** Unique identifier */
59
+ id: string;
60
+ /** Display label (button text) */
61
+ label: string;
62
+ /** Short description shown below the label */
63
+ description: string;
64
+ /** The actual query sent to the AI when the user clicks */
65
+ query: string;
66
+ /** Optional icon name (e.g. `"Shield"`, `"MessageSquare"`, `"Zap"`) */
67
+ icon?: string;
68
+ /** Background color for this question button */
69
+ bgColor?: string;
70
+ /** Text color for this question button */
71
+ textColor?: string;
72
+ /** Icon color (e.g. `"#f5a623"`) */
73
+ iconColor?: string;
74
+ /** Icon container background color (e.g. `"#fef3cd"`) */
75
+ iconBgColor?: string;
76
+ }
77
+ /**
78
+ * Minimal configuration required to connect to the chat backend.
79
+ */
80
+ interface ChatConfig {
81
+ /** Project identifier on the Aigentyc platform */
82
+ projectId: string;
83
+ /** Base URL of the API (e.g. `"https://api.aigentyc.com"`) */
84
+ apiEndpoint: string;
85
+ /** Bearer API key for authentication (alternative to session cookies) */
86
+ apiKey?: string;
87
+ /** Human-readable client / brand name shown in the header */
88
+ clientName?: string;
89
+ }
90
+ /**
91
+ * Props passed to every slot component so it can delegate to the default.
92
+ */
93
+ interface SlotProps<P = Record<string, unknown>> {
94
+ /** Props the default implementation expects */
95
+ props: P;
96
+ /** The SDK-provided default component — call it to render the built-in UI */
97
+ DefaultComponent: ComponentType<P>;
98
+ }
99
+ /**
100
+ * Typed map of all replaceable UI slots.
101
+ *
102
+ * Each value is a React component that receives `SlotProps<T>` where `T`
103
+ * contains the props the default slot implementation expects.
104
+ */
105
+ interface SlotMap {
106
+ /** Custom header component */
107
+ header?: ComponentType<SlotProps>;
108
+ /** Custom footer component */
109
+ footer?: ComponentType<SlotProps>;
110
+ /** Custom chat input component */
111
+ input?: ComponentType<SlotProps>;
112
+ /** Custom welcome page component */
113
+ welcomePage?: ComponentType<SlotProps>;
114
+ /** Custom user message bubble */
115
+ userMessage?: ComponentType<SlotProps>;
116
+ /** Custom assistant message bubble */
117
+ assistantMessage?: ComponentType<SlotProps>;
118
+ /** Custom system message component */
119
+ systemMessage?: ComponentType<SlotProps>;
120
+ /** Custom loading indicator */
121
+ loader?: ComponentType<SlotProps>;
122
+ /** Custom feedback (thumbs up/down) component */
123
+ feedback?: ComponentType<SlotProps>;
124
+ /** Per-tool-name component overrides (keyed by tool name) */
125
+ tools?: Record<string, ComponentType<ToolRendererProps>>;
126
+ /**
127
+ * Per-tool render-mode overrides.
128
+ *
129
+ * Keys are tool names, values are components that receive `ToolRendererProps`.
130
+ */
131
+ toolRenderers?: Record<string, ComponentType<ToolRendererProps>>;
132
+ /** Custom live-chat panel */
133
+ liveChatPanel?: ComponentType<SlotProps>;
134
+ /** Custom satisfaction rating component */
135
+ satisfactionRating?: ComponentType<SlotProps>;
136
+ /** Custom visitor identity form (shown before live-chat handoff) */
137
+ visitorIdentityForm?: ComponentType<SlotProps>;
138
+ /** Custom floating action button */
139
+ floatingButton?: ComponentType<SlotProps>;
140
+ /** Custom empty-state shown when no messages exist */
141
+ emptyState?: ComponentType<SlotProps>;
142
+ }
143
+ /**
144
+ * Describes a follow-up action attached to a tool invocation result.
145
+ *
146
+ * When the user clicks the action, the SDK fires the target tool with
147
+ * mapped parameters.
148
+ */
149
+ interface ComponentAction {
150
+ /** Unique action identifier */
151
+ id: string;
152
+ /** Human-readable action name */
153
+ name: string;
154
+ /** The tool to invoke when this action fires */
155
+ targetToolName: string;
156
+ /** ID of the target tool invocation (if reusing an existing call) */
157
+ targetToolId?: string;
158
+ /** Map of parameter names from action context to target tool args */
159
+ parameterMappings?: Record<string, string>;
160
+ /** CSS selector for the trigger element (when embedded in tool UI) */
161
+ triggerSelector?: string;
162
+ /** Label for the action button */
163
+ buttonLabel?: string;
164
+ }
165
+ /**
166
+ * Structured result returned by the API for a single tool invocation.
167
+ */
168
+ interface ToolResult {
169
+ /** Arbitrary JSON payload returned by the tool */
170
+ data?: unknown;
171
+ /**
172
+ * Hint for how the UI should render this result.
173
+ *
174
+ * `"display"` — full custom component, `"json"` — raw JSON tree,
175
+ * `"text"` — plain text, `"hidden"` — not shown to user.
176
+ */
177
+ uiRenderMode?: "display" | "json" | "text" | "hidden";
178
+ /** JSON-render specification for schema-driven rendering */
179
+ jsonRenderSpec?: Record<string, unknown>;
180
+ /** Name of a registered custom component to render this result */
181
+ customComponent?: string;
182
+ /** Inline React component (rare — usually `customComponent` is preferred) */
183
+ uiComponent?: ComponentType<unknown>;
184
+ /** Follow-up actions the user can trigger from this result */
185
+ componentActions?: ComponentAction[];
186
+ /** Text shown in the loading indicator while the tool runs */
187
+ loadingText?: string;
188
+ /** Whether to offer a "show more" toggle for long results */
189
+ enableShowMore?: boolean;
190
+ /** Number of items to show before the "show more" fold */
191
+ initialRenderLimit?: number;
192
+ /** Label for the "show more" button */
193
+ showMoreText?: string;
194
+ /** Display data for the UI — stripped before sending back to LLM */
195
+ _displayData?: unknown;
196
+ }
197
+ /**
198
+ * Props passed to custom tool renderer components.
199
+ */
200
+ interface ToolRendererProps {
201
+ /** Name of the invoked tool */
202
+ toolName: string;
203
+ /** Lifecycle state: `"partial-call"`, `"call"`, `"output-available"` */
204
+ state: string;
205
+ /** Arguments the LLM passed to the tool */
206
+ args: Record<string, unknown>;
207
+ /** Structured result (available when `state === "output-available"`) */
208
+ result?: ToolResult;
209
+ /** Whether the chat is currently streaming / processing */
210
+ isProcessing?: boolean;
211
+ /** Current UI language */
212
+ language?: Language;
213
+ /** Send a follow-up message on behalf of the user */
214
+ onSendMessage?: (text: string) => void;
215
+ /** Fire a component action */
216
+ onAction?: (action: ComponentAction) => void;
217
+ }
218
+ /**
219
+ * State machine for live-chat sessions.
220
+ *
221
+ * `"ai"` → normal AI conversation
222
+ * `"requesting"` → handoff request sent, waiting for queue
223
+ * `"queued"` → in operator queue
224
+ * `"live"` → connected to a human operator
225
+ * `"ended"` → session ended
226
+ */
227
+ type LiveChatState = "ai" | "requesting" | "queued" | "live" | "ended";
228
+ /**
229
+ * A single message in a live-chat session.
230
+ */
231
+ interface LiveChatMessage {
232
+ /** Server-assigned message ID */
233
+ id: number;
234
+ /** Message body (plain text or HTML) */
235
+ content: string;
236
+ /** Who sent the message */
237
+ senderType: "visitor" | "operator" | "system";
238
+ /** ISO-8601 timestamp */
239
+ timestamp: string;
240
+ /** Optional system-message sub-type (e.g. `"transfer"`, `"rating_request"`) */
241
+ systemMessageType?: string;
242
+ }
243
+ /**
244
+ * All lifecycle event callbacks the SDK exposes.
245
+ *
246
+ * Consumers attach these via `ChatProviderProps` to hook into chat events
247
+ * without reaching into internals.
248
+ */
249
+ interface ChatEventCallbacks {
250
+ /** Fired when the chat UI is mounted and ready */
251
+ onReady?: () => void;
252
+ /** Fired when a brand-new session starts */
253
+ onSessionStart?: (sessionId: string) => void;
254
+ /** Fired when an existing session is restored from storage */
255
+ onSessionRestore?: (sessionId: string) => void;
256
+ /** Fired after the user sends a message */
257
+ onMessageSent?: (message: ChatMessage) => void;
258
+ /** Fired when an assistant message is received (after streaming completes) */
259
+ onMessageReceived?: (message: ChatMessage) => void;
260
+ /** Fired when streaming of a new assistant message begins */
261
+ onStreamStart?: () => void;
262
+ /** Fired when streaming of an assistant message ends */
263
+ onStreamEnd?: () => void;
264
+ /** Fired when the LLM invokes a tool */
265
+ onToolCall?: (toolName: string, args: Record<string, unknown>) => void;
266
+ /** Fired when a tool invocation produces a result */
267
+ onToolResult?: (toolName: string, result: ToolResult) => void;
268
+ /** Fired when the user clicks a component action inside a tool result */
269
+ onToolAction?: (action: ComponentAction) => void;
270
+ /** Fired when the user (or AI) requests a live-chat handoff */
271
+ onLiveChatRequested?: () => void;
272
+ /** Fired when a live-chat session is connected to an operator */
273
+ onLiveChatConnected?: (operatorName: string) => void;
274
+ /** Fired when a live-chat session ends */
275
+ onLiveChatEnded?: (endedBy: string) => void;
276
+ /** Fired on any error (network, auth, etc.) */
277
+ onError?: (error: Error) => void;
278
+ /**
279
+ * Generic interaction event (link click, copy, feedback, etc.).
280
+ * Useful for external analytics pipelines.
281
+ */
282
+ onInteraction?: (type: string, metadata?: Record<string, unknown>) => void;
283
+ }
284
+ /**
285
+ * Represents a single message in the conversation (user, assistant, or system).
286
+ */
287
+ interface ChatMessage {
288
+ /** Unique message identifier */
289
+ id: string;
290
+ /** Who produced this message */
291
+ role: "user" | "assistant" | "system";
292
+ /** Plain-text content of the message */
293
+ content: string;
294
+ /** When the message was created */
295
+ createdAt?: Date;
296
+ /**
297
+ * Structured parts array (text parts, tool invocation parts, etc.).
298
+ * Mirrors the AI SDK `UIMessage.parts` shape.
299
+ */
300
+ parts?: Array<{
301
+ /** Discriminator */
302
+ type: string;
303
+ /** Text content (when `type === "text"`) */
304
+ text?: string;
305
+ /** Tool call ID (when type starts with `"tool-"`) */
306
+ toolCallId?: string;
307
+ /** Tool invocation state */
308
+ state?: string;
309
+ /** Tool input arguments */
310
+ input?: Record<string, unknown>;
311
+ /** Tool output */
312
+ output?: unknown;
313
+ }>;
314
+ }
315
+ /**
316
+ * Full configuration for the `<ChatProvider>` context wrapper.
317
+ *
318
+ * Extends `ChatConfig` with all optional customisation knobs.
319
+ */
320
+ interface ChatProviderProps extends ChatConfig, ChatEventCallbacks {
321
+ /** UI language (default `"en"`) */
322
+ language?: Language;
323
+ /** Theme customisation */
324
+ theme?: ThemeConfig;
325
+ /** Quick-action questions for the welcome page */
326
+ questions?: QuestionConfig[];
327
+ /** Persist messages across page navigations via localStorage (default `true`) */
328
+ persistMessages?: boolean;
329
+ /** Max messages to send to the API in a single request (default `20`) */
330
+ maxMessages?: number;
331
+ /** Enable the live-chat handoff feature */
332
+ enableLiveChat?: boolean;
333
+ /** Socket.IO endpoint for live chat (defaults to `apiEndpoint` if omitted) */
334
+ chatServiceUrl?: string;
335
+ /**
336
+ * Custom translation overrides keyed by language code, then by translation key.
337
+ *
338
+ * ```ts
339
+ * translations: { en: { thinking: "Pondering..." } }
340
+ * ```
341
+ */
342
+ translations?: Record<string, Record<string, string>>;
343
+ /** Replaceable UI slot components */
344
+ slots?: SlotMap;
345
+ /** React children to render inside the provider */
346
+ children?: React.ReactNode;
347
+ }
348
+
349
+ export type { ChatProviderProps as C, Language as L, QuestionConfig as Q, SlotMap as S, ThemeConfig as T, ChatConfig as a, ChatEventCallbacks as b, ChatMessage as c, ComponentAction as d, LiveChatMessage as e, LiveChatState as f, ToolRendererProps as g, ToolResult as h, SlotProps as i };
@@ -0,0 +1,349 @@
1
+ import { ComponentType } from 'react';
2
+
3
+ /**
4
+ * UI language code.
5
+ *
6
+ * `"en"` and `"he"` are first-class supported locales.
7
+ * Any other BCP-47 string is accepted for custom translation overrides.
8
+ */
9
+ type Language = "en" | "he" | (string & {});
10
+ /**
11
+ * Full theme configuration for the chat UI.
12
+ *
13
+ * All values are CSS color/font strings (e.g. `"#eb1d22"`, `"Inter, sans-serif"`).
14
+ */
15
+ interface ThemeConfig {
16
+ /** Primary brand color (buttons, links, accents) */
17
+ primaryColor?: string;
18
+ /** Secondary accent color (highlights, badges) */
19
+ accentColor?: string;
20
+ /** Main background color of the chat panel */
21
+ backgroundColor?: string;
22
+ /** Primary text color */
23
+ textColor?: string;
24
+ /** Color used for links inside chat messages */
25
+ linkColor?: string;
26
+ /** Loader / spinner color */
27
+ loaderColor?: string;
28
+ /** Background color of user message bubbles */
29
+ userBubbleColor?: string;
30
+ /** Background color of assistant message bubbles */
31
+ assistantBubbleColor?: string;
32
+ /** Text color inside assistant message bubbles */
33
+ assistantBubbleTextColor?: string;
34
+ /** Secondary / muted background (input bar, hover states) */
35
+ secondaryColor?: string;
36
+ /** Border color throughout the UI */
37
+ borderColor?: string;
38
+ /** Placeholder text color (inputs, search) */
39
+ placeholderColor?: string;
40
+ /** CSS padding for assistant bubbles (e.g. `"20px"`, `"16px 24px"`) */
41
+ assistantBubblePadding?: string;
42
+ /** Max width of assistant messages (e.g. `"100%"`, `"800px"`). Default: `"95%"` */
43
+ assistantMaxWidth?: string;
44
+ /** Background color for the floating button (overrides primaryColor) */
45
+ buttonBgColor?: string;
46
+ /** Border-radius for the floating button (e.g. `"50%"`, `"12px"`) */
47
+ buttonBorderRadius?: string;
48
+ /** Primary font-family for the widget (e.g. `"Inter, sans-serif"`) */
49
+ fontFamily?: string;
50
+ /** Font-family for headings inside chat responses */
51
+ headingFontFamily?: string;
52
+ }
53
+ /**
54
+ * A single quick-action question shown on the welcome page or as a
55
+ * contextual suggestion during a conversation.
56
+ */
57
+ interface QuestionConfig {
58
+ /** Unique identifier */
59
+ id: string;
60
+ /** Display label (button text) */
61
+ label: string;
62
+ /** Short description shown below the label */
63
+ description: string;
64
+ /** The actual query sent to the AI when the user clicks */
65
+ query: string;
66
+ /** Optional icon name (e.g. `"Shield"`, `"MessageSquare"`, `"Zap"`) */
67
+ icon?: string;
68
+ /** Background color for this question button */
69
+ bgColor?: string;
70
+ /** Text color for this question button */
71
+ textColor?: string;
72
+ /** Icon color (e.g. `"#f5a623"`) */
73
+ iconColor?: string;
74
+ /** Icon container background color (e.g. `"#fef3cd"`) */
75
+ iconBgColor?: string;
76
+ }
77
+ /**
78
+ * Minimal configuration required to connect to the chat backend.
79
+ */
80
+ interface ChatConfig {
81
+ /** Project identifier on the Aigentyc platform */
82
+ projectId: string;
83
+ /** Base URL of the API (e.g. `"https://api.aigentyc.com"`) */
84
+ apiEndpoint: string;
85
+ /** Bearer API key for authentication (alternative to session cookies) */
86
+ apiKey?: string;
87
+ /** Human-readable client / brand name shown in the header */
88
+ clientName?: string;
89
+ }
90
+ /**
91
+ * Props passed to every slot component so it can delegate to the default.
92
+ */
93
+ interface SlotProps<P = Record<string, unknown>> {
94
+ /** Props the default implementation expects */
95
+ props: P;
96
+ /** The SDK-provided default component — call it to render the built-in UI */
97
+ DefaultComponent: ComponentType<P>;
98
+ }
99
+ /**
100
+ * Typed map of all replaceable UI slots.
101
+ *
102
+ * Each value is a React component that receives `SlotProps<T>` where `T`
103
+ * contains the props the default slot implementation expects.
104
+ */
105
+ interface SlotMap {
106
+ /** Custom header component */
107
+ header?: ComponentType<SlotProps>;
108
+ /** Custom footer component */
109
+ footer?: ComponentType<SlotProps>;
110
+ /** Custom chat input component */
111
+ input?: ComponentType<SlotProps>;
112
+ /** Custom welcome page component */
113
+ welcomePage?: ComponentType<SlotProps>;
114
+ /** Custom user message bubble */
115
+ userMessage?: ComponentType<SlotProps>;
116
+ /** Custom assistant message bubble */
117
+ assistantMessage?: ComponentType<SlotProps>;
118
+ /** Custom system message component */
119
+ systemMessage?: ComponentType<SlotProps>;
120
+ /** Custom loading indicator */
121
+ loader?: ComponentType<SlotProps>;
122
+ /** Custom feedback (thumbs up/down) component */
123
+ feedback?: ComponentType<SlotProps>;
124
+ /** Per-tool-name component overrides (keyed by tool name) */
125
+ tools?: Record<string, ComponentType<ToolRendererProps>>;
126
+ /**
127
+ * Per-tool render-mode overrides.
128
+ *
129
+ * Keys are tool names, values are components that receive `ToolRendererProps`.
130
+ */
131
+ toolRenderers?: Record<string, ComponentType<ToolRendererProps>>;
132
+ /** Custom live-chat panel */
133
+ liveChatPanel?: ComponentType<SlotProps>;
134
+ /** Custom satisfaction rating component */
135
+ satisfactionRating?: ComponentType<SlotProps>;
136
+ /** Custom visitor identity form (shown before live-chat handoff) */
137
+ visitorIdentityForm?: ComponentType<SlotProps>;
138
+ /** Custom floating action button */
139
+ floatingButton?: ComponentType<SlotProps>;
140
+ /** Custom empty-state shown when no messages exist */
141
+ emptyState?: ComponentType<SlotProps>;
142
+ }
143
+ /**
144
+ * Describes a follow-up action attached to a tool invocation result.
145
+ *
146
+ * When the user clicks the action, the SDK fires the target tool with
147
+ * mapped parameters.
148
+ */
149
+ interface ComponentAction {
150
+ /** Unique action identifier */
151
+ id: string;
152
+ /** Human-readable action name */
153
+ name: string;
154
+ /** The tool to invoke when this action fires */
155
+ targetToolName: string;
156
+ /** ID of the target tool invocation (if reusing an existing call) */
157
+ targetToolId?: string;
158
+ /** Map of parameter names from action context to target tool args */
159
+ parameterMappings?: Record<string, string>;
160
+ /** CSS selector for the trigger element (when embedded in tool UI) */
161
+ triggerSelector?: string;
162
+ /** Label for the action button */
163
+ buttonLabel?: string;
164
+ }
165
+ /**
166
+ * Structured result returned by the API for a single tool invocation.
167
+ */
168
+ interface ToolResult {
169
+ /** Arbitrary JSON payload returned by the tool */
170
+ data?: unknown;
171
+ /**
172
+ * Hint for how the UI should render this result.
173
+ *
174
+ * `"display"` — full custom component, `"json"` — raw JSON tree,
175
+ * `"text"` — plain text, `"hidden"` — not shown to user.
176
+ */
177
+ uiRenderMode?: "display" | "json" | "text" | "hidden";
178
+ /** JSON-render specification for schema-driven rendering */
179
+ jsonRenderSpec?: Record<string, unknown>;
180
+ /** Name of a registered custom component to render this result */
181
+ customComponent?: string;
182
+ /** Inline React component (rare — usually `customComponent` is preferred) */
183
+ uiComponent?: ComponentType<unknown>;
184
+ /** Follow-up actions the user can trigger from this result */
185
+ componentActions?: ComponentAction[];
186
+ /** Text shown in the loading indicator while the tool runs */
187
+ loadingText?: string;
188
+ /** Whether to offer a "show more" toggle for long results */
189
+ enableShowMore?: boolean;
190
+ /** Number of items to show before the "show more" fold */
191
+ initialRenderLimit?: number;
192
+ /** Label for the "show more" button */
193
+ showMoreText?: string;
194
+ /** Display data for the UI — stripped before sending back to LLM */
195
+ _displayData?: unknown;
196
+ }
197
+ /**
198
+ * Props passed to custom tool renderer components.
199
+ */
200
+ interface ToolRendererProps {
201
+ /** Name of the invoked tool */
202
+ toolName: string;
203
+ /** Lifecycle state: `"partial-call"`, `"call"`, `"output-available"` */
204
+ state: string;
205
+ /** Arguments the LLM passed to the tool */
206
+ args: Record<string, unknown>;
207
+ /** Structured result (available when `state === "output-available"`) */
208
+ result?: ToolResult;
209
+ /** Whether the chat is currently streaming / processing */
210
+ isProcessing?: boolean;
211
+ /** Current UI language */
212
+ language?: Language;
213
+ /** Send a follow-up message on behalf of the user */
214
+ onSendMessage?: (text: string) => void;
215
+ /** Fire a component action */
216
+ onAction?: (action: ComponentAction) => void;
217
+ }
218
+ /**
219
+ * State machine for live-chat sessions.
220
+ *
221
+ * `"ai"` → normal AI conversation
222
+ * `"requesting"` → handoff request sent, waiting for queue
223
+ * `"queued"` → in operator queue
224
+ * `"live"` → connected to a human operator
225
+ * `"ended"` → session ended
226
+ */
227
+ type LiveChatState = "ai" | "requesting" | "queued" | "live" | "ended";
228
+ /**
229
+ * A single message in a live-chat session.
230
+ */
231
+ interface LiveChatMessage {
232
+ /** Server-assigned message ID */
233
+ id: number;
234
+ /** Message body (plain text or HTML) */
235
+ content: string;
236
+ /** Who sent the message */
237
+ senderType: "visitor" | "operator" | "system";
238
+ /** ISO-8601 timestamp */
239
+ timestamp: string;
240
+ /** Optional system-message sub-type (e.g. `"transfer"`, `"rating_request"`) */
241
+ systemMessageType?: string;
242
+ }
243
+ /**
244
+ * All lifecycle event callbacks the SDK exposes.
245
+ *
246
+ * Consumers attach these via `ChatProviderProps` to hook into chat events
247
+ * without reaching into internals.
248
+ */
249
+ interface ChatEventCallbacks {
250
+ /** Fired when the chat UI is mounted and ready */
251
+ onReady?: () => void;
252
+ /** Fired when a brand-new session starts */
253
+ onSessionStart?: (sessionId: string) => void;
254
+ /** Fired when an existing session is restored from storage */
255
+ onSessionRestore?: (sessionId: string) => void;
256
+ /** Fired after the user sends a message */
257
+ onMessageSent?: (message: ChatMessage) => void;
258
+ /** Fired when an assistant message is received (after streaming completes) */
259
+ onMessageReceived?: (message: ChatMessage) => void;
260
+ /** Fired when streaming of a new assistant message begins */
261
+ onStreamStart?: () => void;
262
+ /** Fired when streaming of an assistant message ends */
263
+ onStreamEnd?: () => void;
264
+ /** Fired when the LLM invokes a tool */
265
+ onToolCall?: (toolName: string, args: Record<string, unknown>) => void;
266
+ /** Fired when a tool invocation produces a result */
267
+ onToolResult?: (toolName: string, result: ToolResult) => void;
268
+ /** Fired when the user clicks a component action inside a tool result */
269
+ onToolAction?: (action: ComponentAction) => void;
270
+ /** Fired when the user (or AI) requests a live-chat handoff */
271
+ onLiveChatRequested?: () => void;
272
+ /** Fired when a live-chat session is connected to an operator */
273
+ onLiveChatConnected?: (operatorName: string) => void;
274
+ /** Fired when a live-chat session ends */
275
+ onLiveChatEnded?: (endedBy: string) => void;
276
+ /** Fired on any error (network, auth, etc.) */
277
+ onError?: (error: Error) => void;
278
+ /**
279
+ * Generic interaction event (link click, copy, feedback, etc.).
280
+ * Useful for external analytics pipelines.
281
+ */
282
+ onInteraction?: (type: string, metadata?: Record<string, unknown>) => void;
283
+ }
284
+ /**
285
+ * Represents a single message in the conversation (user, assistant, or system).
286
+ */
287
+ interface ChatMessage {
288
+ /** Unique message identifier */
289
+ id: string;
290
+ /** Who produced this message */
291
+ role: "user" | "assistant" | "system";
292
+ /** Plain-text content of the message */
293
+ content: string;
294
+ /** When the message was created */
295
+ createdAt?: Date;
296
+ /**
297
+ * Structured parts array (text parts, tool invocation parts, etc.).
298
+ * Mirrors the AI SDK `UIMessage.parts` shape.
299
+ */
300
+ parts?: Array<{
301
+ /** Discriminator */
302
+ type: string;
303
+ /** Text content (when `type === "text"`) */
304
+ text?: string;
305
+ /** Tool call ID (when type starts with `"tool-"`) */
306
+ toolCallId?: string;
307
+ /** Tool invocation state */
308
+ state?: string;
309
+ /** Tool input arguments */
310
+ input?: Record<string, unknown>;
311
+ /** Tool output */
312
+ output?: unknown;
313
+ }>;
314
+ }
315
+ /**
316
+ * Full configuration for the `<ChatProvider>` context wrapper.
317
+ *
318
+ * Extends `ChatConfig` with all optional customisation knobs.
319
+ */
320
+ interface ChatProviderProps extends ChatConfig, ChatEventCallbacks {
321
+ /** UI language (default `"en"`) */
322
+ language?: Language;
323
+ /** Theme customisation */
324
+ theme?: ThemeConfig;
325
+ /** Quick-action questions for the welcome page */
326
+ questions?: QuestionConfig[];
327
+ /** Persist messages across page navigations via localStorage (default `true`) */
328
+ persistMessages?: boolean;
329
+ /** Max messages to send to the API in a single request (default `20`) */
330
+ maxMessages?: number;
331
+ /** Enable the live-chat handoff feature */
332
+ enableLiveChat?: boolean;
333
+ /** Socket.IO endpoint for live chat (defaults to `apiEndpoint` if omitted) */
334
+ chatServiceUrl?: string;
335
+ /**
336
+ * Custom translation overrides keyed by language code, then by translation key.
337
+ *
338
+ * ```ts
339
+ * translations: { en: { thinking: "Pondering..." } }
340
+ * ```
341
+ */
342
+ translations?: Record<string, Record<string, string>>;
343
+ /** Replaceable UI slot components */
344
+ slots?: SlotMap;
345
+ /** React children to render inside the provider */
346
+ children?: React.ReactNode;
347
+ }
348
+
349
+ export type { ChatProviderProps as C, Language as L, QuestionConfig as Q, SlotMap as S, ThemeConfig as T, ChatConfig as a, ChatEventCallbacks as b, ChatMessage as c, ComponentAction as d, LiveChatMessage as e, LiveChatState as f, ToolRendererProps as g, ToolResult as h, SlotProps as i };