@asgard-js/react 0.0.43 → 0.0.44-canary.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 (136) hide show
  1. package/dist/components/chatbot/chatbot.d.ts +1 -1
  2. package/dist/components/chatbot/chatbot.d.ts.map +1 -1
  3. package/dist/context/asgard-service-context.d.ts +1 -1
  4. package/dist/context/asgard-service-context.d.ts.map +1 -1
  5. package/dist/hooks/use-channel.d.ts +1 -1
  6. package/dist/hooks/use-channel.d.ts.map +1 -1
  7. package/dist/index.js +20457 -20222
  8. package/package.json +3 -3
  9. package/.babelrc +0 -12
  10. package/eslint.config.cjs +0 -12
  11. package/src/components/.DS_Store +0 -0
  12. package/src/components/chatbot/api-key-input/api-key-input.module.scss +0 -156
  13. package/src/components/chatbot/api-key-input/api-key-input.tsx +0 -111
  14. package/src/components/chatbot/api-key-input/index.ts +0 -1
  15. package/src/components/chatbot/chatbot-body/chatbot-body.module.scss +0 -13
  16. package/src/components/chatbot/chatbot-body/chatbot-body.tsx +0 -45
  17. package/src/components/chatbot/chatbot-body/conversation-message-renderer.tsx +0 -55
  18. package/src/components/chatbot/chatbot-body/index.ts +0 -1
  19. package/src/components/chatbot/chatbot-container/chatbot-container.module.scss +0 -41
  20. package/src/components/chatbot/chatbot-container/chatbot-container.tsx +0 -49
  21. package/src/components/chatbot/chatbot-container/chatbot-full-screen-container.tsx +0 -54
  22. package/src/components/chatbot/chatbot-footer/chatbot-footer.module.scss +0 -67
  23. package/src/components/chatbot/chatbot-footer/chatbot-footer.tsx +0 -140
  24. package/src/components/chatbot/chatbot-footer/index.ts +0 -1
  25. package/src/components/chatbot/chatbot-footer/speech-input-button.tsx +0 -132
  26. package/src/components/chatbot/chatbot-header/chatbot-header.module.scss +0 -48
  27. package/src/components/chatbot/chatbot-header/chatbot-header.tsx +0 -98
  28. package/src/components/chatbot/chatbot-header/index.ts +0 -1
  29. package/src/components/chatbot/chatbot.module.scss +0 -24
  30. package/src/components/chatbot/chatbot.spec.tsx +0 -8
  31. package/src/components/chatbot/chatbot.tsx +0 -227
  32. package/src/components/chatbot/profile-icon.tsx +0 -26
  33. package/src/components/index.ts +0 -2
  34. package/src/components/templates/avatar/avatar.module.scss +0 -6
  35. package/src/components/templates/avatar/avatar.tsx +0 -28
  36. package/src/components/templates/avatar/index.ts +0 -1
  37. package/src/components/templates/button-template/button-template.module.scss +0 -0
  38. package/src/components/templates/button-template/button-template.tsx +0 -45
  39. package/src/components/templates/button-template/card.module.scss +0 -58
  40. package/src/components/templates/button-template/card.spec.tsx +0 -213
  41. package/src/components/templates/button-template/card.tsx +0 -123
  42. package/src/components/templates/button-template/index.ts +0 -1
  43. package/src/components/templates/carousel-template/carousel-template.module.scss +0 -15
  44. package/src/components/templates/carousel-template/carousel-template.tsx +0 -49
  45. package/src/components/templates/carousel-template/index.ts +0 -1
  46. package/src/components/templates/chart-template/chart-template.module.scss +0 -52
  47. package/src/components/templates/chart-template/chart-template.tsx +0 -75
  48. package/src/components/templates/chart-template/index.ts +0 -1
  49. package/src/components/templates/hint-template/hint-template.module.scss +0 -43
  50. package/src/components/templates/hint-template/hint-template.tsx +0 -76
  51. package/src/components/templates/hint-template/index.ts +0 -1
  52. package/src/components/templates/image-template/image-template.module.scss +0 -67
  53. package/src/components/templates/image-template/image-template.tsx +0 -58
  54. package/src/components/templates/image-template/index.ts +0 -1
  55. package/src/components/templates/index.ts +0 -10
  56. package/src/components/templates/quick-replies/index.ts +0 -1
  57. package/src/components/templates/quick-replies/quick-replies.module.scss +0 -16
  58. package/src/components/templates/quick-replies/quick-replies.tsx +0 -47
  59. package/src/components/templates/template-box/index.ts +0 -2
  60. package/src/components/templates/template-box/template-box-content.module.scss +0 -13
  61. package/src/components/templates/template-box/template-box-content.tsx +0 -30
  62. package/src/components/templates/template-box/template-box.module.scss +0 -19
  63. package/src/components/templates/template-box/template-box.tsx +0 -48
  64. package/src/components/templates/text-template/bot-typing-box.tsx +0 -81
  65. package/src/components/templates/text-template/bot-typing-placeholder.tsx +0 -28
  66. package/src/components/templates/text-template/index.ts +0 -3
  67. package/src/components/templates/text-template/text-template.module.scss +0 -131
  68. package/src/components/templates/text-template/text-template.tsx +0 -94
  69. package/src/components/templates/text-template/use-react-markdown-renderer.spec.tsx +0 -758
  70. package/src/components/templates/time/index.ts +0 -1
  71. package/src/components/templates/time/time.module.scss +0 -6
  72. package/src/components/templates/time/time.tsx +0 -34
  73. package/src/context/asgard-app-initialization-context.tsx +0 -154
  74. package/src/context/asgard-service-context.tsx +0 -148
  75. package/src/context/asgard-template-context.tsx +0 -83
  76. package/src/context/asgard-theme-context.tsx +0 -553
  77. package/src/context/index.ts +0 -4
  78. package/src/hooks/index.ts +0 -11
  79. package/src/hooks/use-asgard-service-client.ts +0 -68
  80. package/src/hooks/use-channel.ts +0 -160
  81. package/src/hooks/use-debounce.ts +0 -18
  82. package/src/hooks/use-deep-compare-memo.ts +0 -19
  83. package/src/hooks/use-is-on-screen-keyboard-open.ts +0 -43
  84. package/src/hooks/use-on-screen-keyboard-scroll-fix.ts +0 -17
  85. package/src/hooks/use-prevent-over-scrolling.ts +0 -77
  86. package/src/hooks/use-react-markdown-renderer.tsx +0 -278
  87. package/src/hooks/use-resize-observer.tsx +0 -27
  88. package/src/hooks/use-update-vh.ts +0 -30
  89. package/src/hooks/use-viewport-size.ts +0 -51
  90. package/src/icons/add_a_photo.svg +0 -3
  91. package/src/icons/bot.svg +0 -14
  92. package/src/icons/close.svg +0 -3
  93. package/src/icons/distance.svg +0 -3
  94. package/src/icons/eye-off.svg +0 -4
  95. package/src/icons/eye.svg +0 -4
  96. package/src/icons/mic.svg +0 -3
  97. package/src/icons/photo_library.svg +0 -3
  98. package/src/icons/profile.svg +0 -28
  99. package/src/icons/refresh.svg +0 -3
  100. package/src/icons/send.svg +0 -3
  101. package/src/icons/stop.svg +0 -22
  102. package/src/icons/volume_up.svg +0 -3
  103. package/src/index.ts +0 -4
  104. package/src/models/bot-provider.ts +0 -108
  105. package/src/styles/_index.scss +0 -1
  106. package/src/styles/_styles.scss +0 -11
  107. package/src/styles/colors/_colors.scss +0 -10
  108. package/src/styles/colors/_index.scss +0 -1
  109. package/src/styles/colors/_variables.scss +0 -72
  110. package/src/styles/palette/_index.scss +0 -1
  111. package/src/styles/palette/_palette.scss +0 -42
  112. package/src/styles/palette/_variables.scss +0 -40
  113. package/src/styles/radius/_index.scss +0 -1
  114. package/src/styles/radius/_radius.scss +0 -8
  115. package/src/styles/radius/_variables.scss +0 -12
  116. package/src/styles/spacing/_index.scss +0 -1
  117. package/src/styles/spacing/_spacing.scss +0 -8
  118. package/src/styles/spacing/_variables.scss +0 -13
  119. package/src/styles/utils/_index.scss +0 -1
  120. package/src/styles/utils/_map.scss +0 -22
  121. package/src/test-setup.ts +0 -1
  122. package/src/utils/color-utils.ts +0 -52
  123. package/src/utils/deep-merge.ts +0 -26
  124. package/src/utils/extractors.ts +0 -20
  125. package/src/utils/format-time.ts +0 -8
  126. package/src/utils/index.ts +0 -1
  127. package/src/utils/is.ts +0 -72
  128. package/src/utils/selectors.ts +0 -7
  129. package/src/utils/uri-validation.spec.ts +0 -208
  130. package/src/utils/uri-validation.ts +0 -103
  131. package/tsconfig.json +0 -16
  132. package/tsconfig.lib.json +0 -63
  133. package/tsconfig.spec.json +0 -36
  134. package/tsconfig.tsbuildinfo +0 -1
  135. package/vite.config.ts +0 -63
  136. /package/dist/{style.css → index.css} +0 -0
@@ -1,553 +0,0 @@
1
- import {
2
- createContext,
3
- CSSProperties,
4
- PropsWithChildren,
5
- ReactNode,
6
- useContext,
7
- useMemo,
8
- useCallback,
9
- } from 'react';
10
- import { deepMerge } from '../utils/deep-merge';
11
- import { darkenColor } from '../utils/color-utils';
12
- import {
13
- useAsgardAppInitializationContext,
14
- Annotations,
15
- } from './asgard-app-initialization-context';
16
-
17
- export interface AsgardThemeContextValue {
18
- chatbot: Pick<
19
- CSSProperties,
20
- | 'width'
21
- | 'height'
22
- | 'maxWidth'
23
- | 'minWidth'
24
- | 'maxHeight'
25
- | 'minHeight'
26
- | 'backgroundColor'
27
- | 'borderColor'
28
- | 'borderRadius'
29
- > & {
30
- contentMaxWidth?: CSSProperties['maxWidth'];
31
- backgroundColor?: CSSProperties['backgroundColor'];
32
- borderColor?: CSSProperties['borderColor'];
33
- inactiveColor?: CSSProperties['color'];
34
- mainColor?: CSSProperties['color'];
35
- secondaryColor?: CSSProperties['color'];
36
- primaryComponent?: {
37
- mainColor?: CSSProperties['color'];
38
- secondaryColor?: CSSProperties['color'];
39
- };
40
- style?: CSSProperties;
41
- header?: Partial<{
42
- style: CSSProperties;
43
- title: {
44
- style: CSSProperties;
45
- };
46
- actionButton?: {
47
- style: CSSProperties;
48
- };
49
- }>;
50
- body?: Partial<{
51
- style: CSSProperties;
52
- }>;
53
- footer?: Partial<{
54
- style: CSSProperties;
55
- textArea: {
56
- style: CSSProperties;
57
- '::placeholder': CSSProperties;
58
- };
59
- submitButton: {
60
- style: CSSProperties;
61
- };
62
- speechInputButton: {
63
- style: CSSProperties;
64
- };
65
- }>;
66
- };
67
- botMessage: Pick<CSSProperties, 'color' | 'backgroundColor'> & {
68
- carouselButtonBackgroundColor?: CSSProperties['backgroundColor'];
69
- linkColor?: CSSProperties['color'];
70
- unsentBackgroundColor?: CSSProperties['backgroundColor'];
71
- quickReplyBackgroundColor?: CSSProperties['backgroundColor'];
72
- };
73
- userMessage: Pick<CSSProperties, 'color' | 'backgroundColor'>;
74
- template?: Partial<{
75
- /**
76
- * first level for common/shared properties.
77
- * Check MessageTemplate type for more details (packages/core/src/types/sse-response.ts).
78
- */
79
- quickReplies?: Partial<{
80
- style: CSSProperties;
81
- button: {
82
- style: CSSProperties;
83
- };
84
- }>;
85
- time?: Partial<{
86
- style: CSSProperties;
87
- }>;
88
- /**
89
- * TBD: Fill the necessary properties based on the requirements.
90
- */
91
- TextMessageTemplate: Partial<{ style: CSSProperties }>;
92
- /**
93
- * TBD: Fill the necessary properties based on the requirements.
94
- */
95
- HintMessageTemplate: Partial<{ style: CSSProperties }>;
96
- /**
97
- * TBD: Fill the necessary properties based on the requirements.
98
- */
99
- ImageMessageTemplate: Partial<{ style: CSSProperties }>;
100
- /**
101
- * TBD: Fill the necessary properties based on the requirements.
102
- */
103
- VideoMessageTemplate: Partial<{ style: CSSProperties }>;
104
- /**
105
- * TBD: Fill the necessary properties based on the requirements.
106
- */
107
- AudioMessageTemplate: Partial<{ style: CSSProperties }>;
108
- /**
109
- * TBD: Fill the necessary properties based on the requirements.
110
- */
111
- LocationMessageTemplate: Partial<{ style: CSSProperties }>;
112
- /**
113
- * TBD: Fill the necessary properties based on the requirements.
114
- */
115
- ChartMessageTemplate: Partial<{ style: CSSProperties }>;
116
- /**
117
- * TBD: Fill the necessary properties based on the requirements.
118
- */
119
- ButtonMessageTemplate: Partial<{
120
- style: CSSProperties;
121
- button?: {
122
- style: CSSProperties;
123
- };
124
- }>;
125
- /**
126
- * TBD: Fill the necessary properties based on the requirements.
127
- */
128
- CarouselMessageTemplate: Partial<{
129
- style: CSSProperties;
130
- card: {
131
- style: CSSProperties;
132
- button?: {
133
- style: CSSProperties;
134
- };
135
- };
136
- }>;
137
- }>;
138
- }
139
-
140
- export const defaultAsgardThemeContextValue: AsgardThemeContextValue = {
141
- chatbot: {
142
- width: '375px',
143
- height: '640px',
144
- backgroundColor: 'var(--asg-color-bg)',
145
- borderColor: 'var(--asg-color-border)',
146
- borderRadius: 'var(--asg-radius-md)',
147
- contentMaxWidth: '1200px',
148
- style: {},
149
- header: {
150
- style: {},
151
- title: {
152
- style: {},
153
- },
154
- actionButton: {
155
- style: {},
156
- },
157
- },
158
- body: {
159
- style: {},
160
- },
161
- footer: {
162
- style: {},
163
- textArea: {
164
- style: {},
165
- '::placeholder': {
166
- color: 'var(--asg-color-text-placeholder)',
167
- },
168
- },
169
- submitButton: {
170
- style: {},
171
- },
172
- speechInputButton: {
173
- style: {},
174
- },
175
- },
176
- },
177
- botMessage: {
178
- color: 'var(--asg-color-text)',
179
- backgroundColor: 'var(--asg-color-secondary)',
180
- },
181
- userMessage: {
182
- color: 'var(--asg-color-text)',
183
- backgroundColor: 'var(--asg-color-primary)',
184
- },
185
- template: {
186
- quickReplies: {
187
- style: {},
188
- button: {
189
- style: {},
190
- },
191
- },
192
- time: {
193
- style: {},
194
- },
195
- TextMessageTemplate: {
196
- style: {},
197
- },
198
- HintMessageTemplate: {
199
- style: {},
200
- },
201
- ImageMessageTemplate: {
202
- style: {},
203
- },
204
- VideoMessageTemplate: {
205
- style: {},
206
- },
207
- AudioMessageTemplate: {
208
- style: {},
209
- },
210
- LocationMessageTemplate: {
211
- style: {},
212
- },
213
- ChartMessageTemplate: {
214
- style: {},
215
- },
216
- ButtonMessageTemplate: {
217
- style: {},
218
- button: {
219
- style: {
220
- border: '1px solid var(--asg-color-border)',
221
- },
222
- },
223
- },
224
- CarouselMessageTemplate: {
225
- style: {},
226
- card: {
227
- style: {},
228
- button: {
229
- style: {
230
- border: '1px solid var(--asg-color-border)',
231
- },
232
- },
233
- },
234
- },
235
- },
236
- };
237
-
238
- export const AsgardThemeContext = createContext<AsgardThemeContextValue>(
239
- defaultAsgardThemeContextValue
240
- );
241
-
242
- export function AsgardThemeContextProvider(
243
- props: PropsWithChildren<{
244
- theme?: Partial<AsgardThemeContextValue>;
245
- }>
246
- ): ReactNode {
247
- const { children, theme = {} } = props;
248
- const {
249
- data: { annotations },
250
- } = useAsgardAppInitializationContext();
251
-
252
- const deepMergeTheme = useCallback(
253
- function () {
254
- /**
255
- * Orders of theme (high to low):
256
- * 1. Theme from props
257
- * 2. Theme from annotations
258
- * 3. Default theme
259
- */
260
-
261
- const themeFromAnnotations: Annotations['embedConfig']['theme'] =
262
- annotations?.embedConfig?.theme ?? {
263
- chatbot: {},
264
- botMessage: {},
265
- userMessage: {},
266
- };
267
-
268
- const tempTheme = deepMerge(defaultAsgardThemeContextValue as unknown as Record<string, unknown>, {
269
- chatbot: {
270
- backgroundColor: themeFromAnnotations.chatbot?.backgroundColor,
271
- borderColor: themeFromAnnotations.chatbot?.borderColor,
272
- mainColor: themeFromAnnotations.chatbot?.primaryComponent?.mainColor,
273
- secondaryColor: themeFromAnnotations.chatbot?.primaryComponent?.secondaryColor,
274
-
275
- header: {
276
- style: {
277
- borderBottomColor: themeFromAnnotations.chatbot?.borderColor,
278
- },
279
- title: {
280
- style: {
281
- color:
282
- themeFromAnnotations.chatbot?.primaryComponent
283
- ?.secondaryColor, // Title text color
284
- },
285
- },
286
- actionButton: {
287
- style: {
288
- color: themeFromAnnotations.chatbot?.inactiveColor,
289
- },
290
- },
291
- },
292
- body: {
293
- style: {
294
- // Time/timestamp text color
295
- color: themeFromAnnotations.chatbot?.inactiveColor,
296
- },
297
- },
298
- footer: {
299
- style: {
300
- borderTopColor: themeFromAnnotations.chatbot?.borderColor,
301
- },
302
- textArea: {
303
- style: {
304
- color: themeFromAnnotations.chatbot?.inactiveColor,
305
- backgroundColor: themeFromAnnotations.chatbot?.backgroundColor,
306
- },
307
- '::placeholder': {
308
- color: themeFromAnnotations.chatbot?.inactiveColor,
309
- },
310
- },
311
- submitButton: {
312
- style: {
313
- color:
314
- themeFromAnnotations.chatbot?.primaryComponent
315
- ?.secondaryColor,
316
- },
317
- },
318
- speechInputButton: {
319
- style: {
320
- color:
321
- themeFromAnnotations.chatbot?.primaryComponent
322
- ?.secondaryColor,
323
- },
324
- },
325
- },
326
- },
327
- botMessage: {
328
- backgroundColor: themeFromAnnotations.botMessage?.backgroundColor, // #585858
329
- color: themeFromAnnotations.botMessage?.color,
330
- linkColor: themeFromAnnotations.botMessage?.backgroundColor
331
- ? darkenColor(themeFromAnnotations.botMessage.backgroundColor, 0.2)
332
- : undefined,
333
- unsentBackgroundColor: themeFromAnnotations.botMessage?.backgroundColor
334
- ? `color-mix(in srgb, ${themeFromAnnotations.botMessage.backgroundColor} 20%, transparent)`
335
- : undefined,
336
- quickReplyBackgroundColor: themeFromAnnotations.botMessage?.backgroundColor
337
- ? `color-mix(in srgb, ${themeFromAnnotations.botMessage.backgroundColor} 20%, transparent)`
338
- : undefined,
339
- },
340
- userMessage: {
341
- backgroundColor: themeFromAnnotations.userMessage?.backgroundColor,
342
- color: themeFromAnnotations.userMessage?.color,
343
- },
344
- template: {
345
- quickReplies: {
346
- button: {
347
- style: {
348
- color:
349
- themeFromAnnotations.chatbot?.primaryComponent
350
- ?.secondaryColor, // Button text (#FFFFFF)
351
- borderColor: themeFromAnnotations.chatbot?.borderColor,
352
- backgroundColor: themeFromAnnotations.botMessage
353
- ?.backgroundColor
354
- ? `${themeFromAnnotations.botMessage.backgroundColor}33`
355
- : undefined,
356
- },
357
- },
358
- },
359
- time: {
360
- style: {
361
- color: themeFromAnnotations.chatbot?.inactiveColor,
362
- },
363
- },
364
- TextMessageTemplate: {
365
- style: {
366
- // For unset messages
367
- color:
368
- themeFromAnnotations.chatbot?.primaryComponent?.secondaryColor,
369
- },
370
- },
371
- ButtonMessageTemplate: {
372
- button: {
373
- style: {
374
- borderColor: themeFromAnnotations.chatbot?.primaryComponent?.mainColor,
375
- backgroundColor:
376
- themeFromAnnotations.chatbot?.primaryComponent?.mainColor,
377
- color:
378
- themeFromAnnotations.chatbot?.primaryComponent
379
- ?.secondaryColor,
380
- },
381
- },
382
- },
383
- CarouselMessageTemplate: {
384
- card: {
385
- style: {
386
- backgroundColor:
387
- themeFromAnnotations.botMessage
388
- ?.carouselButtonBackgroundColor,
389
- },
390
- button: {
391
- style: {
392
- borderColor: themeFromAnnotations.chatbot?.primaryComponent?.mainColor,
393
- backgroundColor:
394
- themeFromAnnotations.chatbot?.primaryComponent?.mainColor,
395
- color:
396
- themeFromAnnotations.chatbot?.primaryComponent
397
- ?.secondaryColor,
398
- },
399
- },
400
- },
401
- },
402
- },
403
- });
404
-
405
- // Handle theme prop that contains backend format (like themeFromAnnotations)
406
- const propsTheme = theme as any; // Cast to handle backend format
407
- const propsHasBackendFormat = propsTheme.chatbot?.primaryComponent || propsTheme.chatbot?.backgroundColor || propsTheme.botMessage || propsTheme.userMessage;
408
-
409
- if (propsHasBackendFormat) {
410
- // Apply same transformation logic as tempTheme for props theme
411
- const transformedPropsTheme = deepMerge(defaultAsgardThemeContextValue as unknown as Record<string, unknown>, {
412
- chatbot: {
413
- backgroundColor: propsTheme.chatbot?.backgroundColor,
414
- borderColor: propsTheme.chatbot?.borderColor,
415
- mainColor: propsTheme.chatbot?.primaryComponent?.mainColor,
416
- secondaryColor: propsTheme.chatbot?.primaryComponent?.secondaryColor,
417
- header: {
418
- style: {
419
- borderBottomColor: propsTheme.chatbot?.borderColor,
420
- },
421
- title: {
422
- style: {
423
- color: propsTheme.chatbot?.primaryComponent?.secondaryColor,
424
- },
425
- },
426
- actionButton: {
427
- style: {
428
- color: propsTheme.chatbot?.inactiveColor,
429
- },
430
- },
431
- },
432
- body: {
433
- style: {
434
- // Time/timestamp text color
435
- color: propsTheme.chatbot?.inactiveColor,
436
- },
437
- },
438
- footer: {
439
- style: {
440
- borderTopColor: propsTheme.chatbot?.borderColor,
441
- },
442
- textArea: {
443
- style: {
444
- color: propsTheme.chatbot?.inactiveColor,
445
- backgroundColor: propsTheme.chatbot?.backgroundColor,
446
- },
447
- '::placeholder': {
448
- color: propsTheme.chatbot?.inactiveColor,
449
- },
450
- },
451
- submitButton: {
452
- style: {
453
- color: propsTheme.chatbot?.primaryComponent?.secondaryColor,
454
- },
455
- },
456
- speechInputButton: {
457
- style: {
458
- color: propsTheme.chatbot?.primaryComponent?.secondaryColor,
459
- },
460
- },
461
- },
462
- },
463
- botMessage: {
464
- backgroundColor: propsTheme.botMessage?.backgroundColor,
465
- color: propsTheme.botMessage?.color,
466
- linkColor: propsTheme.botMessage?.backgroundColor
467
- ? darkenColor(propsTheme.botMessage.backgroundColor, 0.2)
468
- : undefined,
469
- unsentBackgroundColor: propsTheme.botMessage?.backgroundColor
470
- ? `color-mix(in srgb, ${propsTheme.botMessage.backgroundColor} 20%, transparent)`
471
- : undefined,
472
- quickReplyBackgroundColor: propsTheme.botMessage?.backgroundColor
473
- ? `color-mix(in srgb, ${propsTheme.botMessage.backgroundColor} 20%, transparent)`
474
- : undefined,
475
- },
476
- userMessage: {
477
- backgroundColor: propsTheme.userMessage?.backgroundColor,
478
- color: propsTheme.userMessage?.color,
479
- },
480
- template: {
481
- quickReplies: {
482
- button: {
483
- style: {
484
- color: propsTheme.chatbot?.primaryComponent?.secondaryColor,
485
- borderColor: propsTheme.chatbot?.borderColor,
486
- backgroundColor: propsTheme.botMessage?.backgroundColor
487
- ? `${propsTheme.botMessage.backgroundColor}33`
488
- : undefined,
489
- },
490
- },
491
- },
492
- time: {
493
- style: {
494
- color: propsTheme.chatbot?.inactiveColor,
495
- },
496
- },
497
- TextMessageTemplate: {
498
- style: {
499
- // For unset messages
500
- color: propsTheme.chatbot?.primaryComponent?.secondaryColor,
501
- },
502
- },
503
- HintMessageTemplate: {
504
- style: {
505
- color: propsTheme.chatbot?.primaryComponent?.secondaryColor,
506
- },
507
- },
508
- ButtonMessageTemplate: {
509
- button: {
510
- style: {
511
- borderColor: propsTheme.chatbot?.primaryComponent?.mainColor,
512
- backgroundColor: propsTheme.chatbot?.primaryComponent?.mainColor,
513
- color: propsTheme.chatbot?.primaryComponent?.secondaryColor,
514
- },
515
- },
516
- },
517
- CarouselMessageTemplate: {
518
- card: {
519
- style: {
520
- backgroundColor: propsTheme.botMessage?.carouselButtonBackgroundColor,
521
- },
522
- button: {
523
- style: {
524
- borderColor: propsTheme.chatbot?.primaryComponent?.mainColor,
525
- backgroundColor: propsTheme.chatbot?.primaryComponent?.mainColor,
526
- color: propsTheme.chatbot?.primaryComponent?.secondaryColor,
527
- },
528
- },
529
- },
530
- },
531
- },
532
- });
533
-
534
- return deepMerge(tempTheme, transformedPropsTheme);
535
- }
536
-
537
- return deepMerge(tempTheme, theme);
538
- },
539
- [theme, annotations?.embedConfig?.theme]
540
- );
541
-
542
- const value = useMemo(() => deepMergeTheme(), [deepMergeTheme]);
543
-
544
- return (
545
- <AsgardThemeContext.Provider value={value}>
546
- {children}
547
- </AsgardThemeContext.Provider>
548
- );
549
- }
550
-
551
- export function useAsgardThemeContext(): AsgardThemeContextValue {
552
- return useContext(AsgardThemeContext);
553
- }
@@ -1,4 +0,0 @@
1
- export * from './asgard-service-context';
2
- export * from './asgard-template-context';
3
- export * from './asgard-theme-context';
4
- export * from './asgard-app-initialization-context';
@@ -1,11 +0,0 @@
1
- export * from './use-asgard-service-client';
2
- export * from './use-channel';
3
- export * from './use-debounce';
4
- export * from './use-viewport-size';
5
- export * from './use-is-on-screen-keyboard-open';
6
- export * from './use-on-screen-keyboard-scroll-fix';
7
- export * from './use-prevent-over-scrolling';
8
- export * from './use-update-vh';
9
- export * from './use-resize-observer';
10
- export * from './use-deep-compare-memo';
11
- export * from './use-react-markdown-renderer';
@@ -1,68 +0,0 @@
1
- import { ClientConfig, AsgardServiceClient, EventType } from '@asgard-js/core';
2
- import { useEffect, useRef } from 'react';
3
-
4
- interface UseAsgardServiceClientProps {
5
- config: ClientConfig;
6
- }
7
-
8
- export function useAsgardServiceClient(
9
- props: UseAsgardServiceClientProps
10
- ): AsgardServiceClient | null {
11
- const { config } = props;
12
-
13
- const { onRunInit, onProcess, onMessage, onToolCall, onRunDone, onRunError } =
14
- config;
15
-
16
- const clientRef = useRef<AsgardServiceClient | null>(null);
17
-
18
- if (!clientRef.current) {
19
- clientRef.current = new AsgardServiceClient(config);
20
- }
21
-
22
- useEffect(() => {
23
- return (): void => {
24
- if (clientRef.current) {
25
- clientRef.current.close();
26
- clientRef.current = null;
27
- }
28
- };
29
- }, []);
30
-
31
- useEffect(() => {
32
- if (!clientRef.current || !onRunInit) return;
33
-
34
- clientRef.current.on(EventType.INIT, onRunInit);
35
- }, [onRunInit]);
36
-
37
- useEffect(() => {
38
- if (!clientRef.current || !onProcess) return;
39
-
40
- clientRef.current.on(EventType.PROCESS, onProcess);
41
- }, [onProcess]);
42
-
43
- useEffect(() => {
44
- if (!clientRef.current || !onMessage) return;
45
-
46
- clientRef.current.on(EventType.MESSAGE, onMessage);
47
- }, [onMessage]);
48
-
49
- useEffect(() => {
50
- if (!clientRef.current || !onToolCall) return;
51
-
52
- clientRef.current.on(EventType.TOOL_CALL, onToolCall);
53
- }, [onToolCall]);
54
-
55
- useEffect(() => {
56
- if (!clientRef.current || !onRunDone) return;
57
-
58
- clientRef.current.on(EventType.DONE, onRunDone);
59
- }, [onRunDone]);
60
-
61
- useEffect(() => {
62
- if (!clientRef.current || !onRunError) return;
63
-
64
- clientRef.current.on(EventType.ERROR, onRunError);
65
- }, [onRunError]);
66
-
67
- return clientRef.current;
68
- }