@asgard-js/react 0.0.32 → 0.0.33-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.
- package/dist/components/chatbot/chatbot-body/conversation-message-renderer.d.ts +1 -1
- package/dist/components/chatbot/chatbot.d.ts +1 -1
- package/dist/components/chatbot/chatbot.d.ts.map +1 -1
- package/dist/components/templates/button-template/button-template.d.ts +1 -1
- package/dist/components/templates/button-template/card.d.ts +1 -1
- package/dist/components/templates/carousel-template/carousel-template.d.ts +1 -1
- package/dist/components/templates/carousel-template/carousel-template.d.ts.map +1 -1
- package/dist/components/templates/chart-template/chart-template.d.ts +1 -1
- package/dist/components/templates/chart-template/chart-template.d.ts.map +1 -1
- package/dist/components/templates/hint-template/hint-template.d.ts +1 -1
- package/dist/components/templates/image-template/image-template.d.ts +1 -1
- package/dist/components/templates/image-template/image-template.d.ts.map +1 -1
- package/dist/components/templates/text-template/text-template.d.ts +1 -1
- package/dist/context/asgard-app-initialization-context.d.ts +1 -1
- package/dist/context/asgard-service-context.d.ts +1 -1
- package/dist/context/asgard-service-context.d.ts.map +1 -1
- package/dist/context/asgard-template-context.d.ts +3 -3
- package/dist/context/asgard-template-context.d.ts.map +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/use-asgard-service-client.d.ts +1 -1
- package/dist/hooks/use-channel.d.ts +4 -4
- package/dist/hooks/use-channel.d.ts.map +1 -1
- package/dist/hooks/use-react-markdown-renderer.d.ts.map +1 -0
- package/dist/index.js +15609 -15654
- package/dist/models/bot-provider.d.ts +1 -1
- package/dist/utils/deep-merge.d.ts +1 -1
- package/dist/utils/deep-merge.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/components/chatbot/chatbot-body/chatbot-body.tsx +2 -2
- package/src/components/chatbot/chatbot-container/chatbot-container.tsx +2 -2
- package/src/components/chatbot/chatbot-container/chatbot-full-screen-container.tsx +2 -2
- package/src/components/chatbot/chatbot-footer/chatbot-footer.tsx +3 -3
- package/src/components/chatbot/chatbot-footer/speech-input-button.tsx +2 -2
- package/src/components/chatbot/chatbot-header/chatbot-header.tsx +3 -3
- package/src/components/chatbot/chatbot.tsx +2 -2
- package/src/components/chatbot/profile-icon.tsx +1 -1
- package/src/components/templates/avatar/avatar.tsx +1 -1
- package/src/components/templates/button-template/button-template.tsx +2 -2
- package/src/components/templates/button-template/card.tsx +4 -4
- package/src/components/templates/carousel-template/carousel-template.tsx +4 -3
- package/src/components/templates/chart-template/chart-template.tsx +6 -7
- package/src/components/templates/hint-template/hint-template.tsx +2 -2
- package/src/components/templates/image-template/image-template.tsx +6 -6
- package/src/components/templates/quick-replies/quick-replies.tsx +2 -2
- package/src/components/templates/text-template/bot-typing-box.tsx +4 -4
- package/src/components/templates/text-template/bot-typing-placeholder.tsx +1 -1
- package/src/components/templates/text-template/text-template.tsx +3 -3
- package/src/components/templates/text-template/use-react-markdown-renderer.spec.tsx +8 -8
- package/src/components/templates/time/time.tsx +2 -2
- package/src/context/asgard-app-initialization-context.tsx +4 -4
- package/src/context/asgard-service-context.tsx +1 -1
- package/src/context/asgard-template-context.tsx +2 -2
- package/src/context/asgard-theme-context.tsx +3 -3
- package/src/hooks/index.ts +1 -1
- package/src/hooks/use-channel.ts +8 -8
- package/src/{components/templates/text-template → hooks}/use-react-markdown-renderer.tsx +13 -11
- package/src/utils/deep-merge.ts +7 -4
- package/tsconfig.lib.json +2 -1
- package/tsconfig.tsbuildinfo +1 -0
- package/dist/components/templates/text-template/use-react-markdown-renderer.d.ts.map +0 -1
- /package/dist/{components/templates/text-template → hooks}/use-react-markdown-renderer.d.ts +0 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare function isObject(item: unknown): item is Record<string, unknown>;
|
|
2
|
-
export declare function deepMerge<T extends
|
|
2
|
+
export declare function deepMerge<T extends Record<string, unknown>, U extends Record<string, unknown>>(target: T, source: U): T & U;
|
|
3
3
|
//# sourceMappingURL=deep-merge.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deep-merge.d.ts","sourceRoot":"","sources":["../../src/utils/deep-merge.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEvE;AAED,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"deep-merge.d.ts","sourceRoot":"","sources":["../../src/utils/deep-merge.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEvE;AAED,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5F,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,CAAC,GACR,CAAC,GAAG,CAAC,CAkBP"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asgard-js/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.33-canary.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"vitest": "^1.6.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@asgard-js/core": "^0.0.
|
|
57
|
+
"@asgard-js/core": "^0.0.33-canary.1",
|
|
58
58
|
"react": "^18.0.0",
|
|
59
59
|
"react-dom": "^18.0.0"
|
|
60
60
|
},
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ReactNode, useEffect, useMemo } from 'react';
|
|
2
|
-
import { useAsgardContext } from '
|
|
2
|
+
import { useAsgardContext } from '../../../context/asgard-service-context';
|
|
3
3
|
import styles from './chatbot-body.module.scss';
|
|
4
4
|
import { ConversationMessageRenderer } from './conversation-message-renderer';
|
|
5
5
|
import { BotTypingPlaceholder } from '../../templates';
|
|
6
|
-
import { useAsgardThemeContext } from '
|
|
6
|
+
import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
|
|
7
7
|
import clsx from 'clsx';
|
|
8
8
|
|
|
9
9
|
export function ChatbotBody(): ReactNode {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { PropsWithChildren, ReactNode, useRef, CSSProperties } from 'react';
|
|
2
|
-
import { useUpdateVh } from '
|
|
2
|
+
import { useUpdateVh } from '../../../hooks';
|
|
3
3
|
import { ChatbotFullScreenContainer } from './chatbot-full-screen-container';
|
|
4
4
|
import classes from './chatbot-container.module.scss';
|
|
5
|
-
import { useAsgardThemeContext } from '
|
|
5
|
+
import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
|
|
6
6
|
import clsx from 'clsx';
|
|
7
7
|
|
|
8
8
|
interface ChatbotContainerProps extends PropsWithChildren {
|
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
useOnScreenKeyboardScrollFix,
|
|
6
6
|
usePreventOverScrolling,
|
|
7
7
|
useViewportSize,
|
|
8
|
-
} from '
|
|
8
|
+
} from '../../../hooks';
|
|
9
9
|
import classes from './chatbot-container.module.scss';
|
|
10
|
-
import { useAsgardThemeContext } from '
|
|
10
|
+
import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
|
|
11
11
|
|
|
12
12
|
export function ChatbotFullScreenContainer(
|
|
13
13
|
props: PropsWithChildren
|
|
@@ -8,12 +8,12 @@ import {
|
|
|
8
8
|
useRef,
|
|
9
9
|
useState,
|
|
10
10
|
} from 'react';
|
|
11
|
-
import { useAsgardContext } from '
|
|
11
|
+
import { useAsgardContext } from '../../../context/asgard-service-context';
|
|
12
12
|
import styles from './chatbot-footer.module.scss';
|
|
13
|
-
import SendSvg from '
|
|
13
|
+
import SendSvg from '../../../icons/send.svg?react';
|
|
14
14
|
import { SpeechInputButton } from './speech-input-button';
|
|
15
15
|
import clsx from 'clsx';
|
|
16
|
-
import { useAsgardThemeContext } from '
|
|
16
|
+
import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
|
|
17
17
|
|
|
18
18
|
export function ChatbotFooter(): ReactNode {
|
|
19
19
|
const { sendMessage, isConnecting } = useAsgardContext();
|
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
useState,
|
|
11
11
|
CSSProperties,
|
|
12
12
|
} from 'react';
|
|
13
|
-
import MicSvg from '
|
|
14
|
-
import StopSvg from '
|
|
13
|
+
import MicSvg from '../../../icons/mic.svg?react';
|
|
14
|
+
import StopSvg from '../../../icons/stop.svg?react';
|
|
15
15
|
|
|
16
16
|
interface SpeechInputButtonProps {
|
|
17
17
|
setValue: Dispatch<SetStateAction<string>>;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { MouseEventHandler, ReactNode, useCallback, useMemo } from 'react';
|
|
2
2
|
import styles from './chatbot-header.module.scss';
|
|
3
3
|
import { ProfileIcon } from '../profile-icon';
|
|
4
|
-
import RefreshSvg from '
|
|
5
|
-
import CloseSvg from '
|
|
4
|
+
import RefreshSvg from '../../../icons/refresh.svg?react';
|
|
5
|
+
import CloseSvg from '../../../icons/close.svg?react';
|
|
6
6
|
import {
|
|
7
7
|
useAsgardAppInitializationContext,
|
|
8
8
|
useAsgardThemeContext,
|
|
9
9
|
useAsgardContext,
|
|
10
|
-
} from '
|
|
10
|
+
} from '../../../context/';
|
|
11
11
|
import clsx from 'clsx';
|
|
12
12
|
|
|
13
13
|
interface ChatbotHeaderProps {
|
|
@@ -3,7 +3,7 @@ import { ClientConfig, ConversationMessage } from '@asgard-js/core';
|
|
|
3
3
|
import {
|
|
4
4
|
AsgardThemeContextProvider,
|
|
5
5
|
AsgardThemeContextValue,
|
|
6
|
-
} from '
|
|
6
|
+
} from '../../context/asgard-theme-context';
|
|
7
7
|
import {
|
|
8
8
|
AsgardServiceContextProvider,
|
|
9
9
|
AsgardServiceContextValue,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
AsgardTemplateContextValue,
|
|
12
12
|
AsgardAppInitializationContextProvider,
|
|
13
13
|
AsgardServiceContextProviderProps,
|
|
14
|
-
} from '
|
|
14
|
+
} from '../../context';
|
|
15
15
|
import { ChatbotHeader } from './chatbot-header';
|
|
16
16
|
import { ChatbotBody } from './chatbot-body';
|
|
17
17
|
import { ChatbotFooter } from './chatbot-footer';
|
|
@@ -3,8 +3,8 @@ import { ReactNode } from 'react';
|
|
|
3
3
|
import { TemplateBox, TemplateBoxContent } from '../template-box';
|
|
4
4
|
import { Avatar } from '../avatar';
|
|
5
5
|
import { Card } from './card';
|
|
6
|
-
import { useAsgardContext } from '
|
|
7
|
-
import { useAsgardThemeContext } from '
|
|
6
|
+
import { useAsgardContext } from '../../../context/asgard-service-context';
|
|
7
|
+
import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
|
|
8
8
|
|
|
9
9
|
interface ButtonTemplateProps {
|
|
10
10
|
message: ConversationBotMessage;
|
|
@@ -11,9 +11,9 @@ import {
|
|
|
11
11
|
ButtonMessageTemplate,
|
|
12
12
|
CarouselMessageTemplate,
|
|
13
13
|
} from '@asgard-js/core';
|
|
14
|
-
import { useAsgardContext } from '
|
|
15
|
-
import { useAsgardTemplateContext } from '
|
|
16
|
-
import { safeWindowOpen } from '
|
|
14
|
+
import { useAsgardContext } from '../../../context/asgard-service-context';
|
|
15
|
+
import { useAsgardTemplateContext } from '../../../context/asgard-template-context';
|
|
16
|
+
import { safeWindowOpen } from '../../../utils/uri-validation';
|
|
17
17
|
import clsx from 'clsx';
|
|
18
18
|
|
|
19
19
|
interface CardProps {
|
|
@@ -107,7 +107,7 @@ export function Card(props: CardProps): ReactNode {
|
|
|
107
107
|
<h5 className={styles.card_title}>{template?.title}</h5>
|
|
108
108
|
<div className={styles.card_description}>{template?.text}</div>
|
|
109
109
|
<div className={styles.card_actions}>
|
|
110
|
-
{template?.buttons?.map((btn, index) => (
|
|
110
|
+
{template?.buttons?.map((btn: { label: string; action: ButtonAction }, index: number) => (
|
|
111
111
|
<button
|
|
112
112
|
key={index}
|
|
113
113
|
onClick={handleClick(btn.action)}
|
|
@@ -6,10 +6,11 @@ import { Card } from '../button-template/card';
|
|
|
6
6
|
import {
|
|
7
7
|
CarouselMessageTemplate,
|
|
8
8
|
ConversationBotMessage,
|
|
9
|
+
ButtonMessageTemplate,
|
|
9
10
|
} from '@asgard-js/core';
|
|
10
11
|
import { Time } from '../time';
|
|
11
|
-
import { useAsgardContext } from '
|
|
12
|
-
import { useAsgardThemeContext } from '
|
|
12
|
+
import { useAsgardContext } from '../../../context/asgard-service-context';
|
|
13
|
+
import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
|
|
13
14
|
|
|
14
15
|
interface CarouselTemplateProps {
|
|
15
16
|
message: ConversationBotMessage;
|
|
@@ -33,7 +34,7 @@ export function CarouselTemplate(props: CarouselTemplateProps): ReactNode {
|
|
|
33
34
|
<Avatar avatar={avatar} />
|
|
34
35
|
<TemplateBoxContent quickReplies={template.quickReplies}>
|
|
35
36
|
<div className={styles.carousel_root}>
|
|
36
|
-
{template.columns?.map((column, index) => (
|
|
37
|
+
{template.columns?.map((column: Omit<ButtonMessageTemplate, 'type' | 'quickReplies'>, index: number) => (
|
|
37
38
|
<Card
|
|
38
39
|
key={index}
|
|
39
40
|
template={column}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { ReactNode, useMemo, useState, CSSProperties } from 'react';
|
|
2
2
|
import { TemplateBox, TemplateBoxContent } from '../template-box';
|
|
3
3
|
import { Avatar } from '../avatar';
|
|
4
|
-
import { ConversationBotMessage } from '@asgard-js/core';
|
|
4
|
+
import { ConversationBotMessage, ChartMessageTemplate } from '@asgard-js/core';
|
|
5
5
|
import { Time } from '../time';
|
|
6
|
-
import { useAsgardContext } from '
|
|
7
|
-
import { ChartMessageTemplate } from '../../../../../core/src';
|
|
6
|
+
import { useAsgardContext } from '../../../context/asgard-service-context';
|
|
8
7
|
import { VegaLite, VisualizationSpec } from 'react-vega';
|
|
9
8
|
import clsx from 'clsx';
|
|
10
9
|
import classes from './chart-template.module.scss';
|
|
11
|
-
import { useAsgardThemeContext } from '
|
|
10
|
+
import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
|
|
12
11
|
|
|
13
12
|
interface ChartTemplateProps {
|
|
14
13
|
message: ConversationBotMessage;
|
|
@@ -29,9 +28,9 @@ export function ChartTemplate(props: ChartTemplateProps): ReactNode {
|
|
|
29
28
|
|
|
30
29
|
const spec = useMemo(
|
|
31
30
|
() =>
|
|
32
|
-
(template?.chartOptions?.find((item) => item.type === option)?.spec ??
|
|
31
|
+
(template?.chartOptions?.find((item: { type: string; title: string; spec: Record<string, unknown> }) => item.type === option)?.spec ??
|
|
33
32
|
options[0].spec) as VisualizationSpec,
|
|
34
|
-
[option, template.chartOptions]
|
|
33
|
+
[option, template.chartOptions, options]
|
|
35
34
|
);
|
|
36
35
|
|
|
37
36
|
const styles = useMemo<CSSProperties>(
|
|
@@ -56,7 +55,7 @@ export function ChartTemplate(props: ChartTemplateProps): ReactNode {
|
|
|
56
55
|
</div>
|
|
57
56
|
{options.length > 1 && (
|
|
58
57
|
<div className={classes.quick_replies_box}>
|
|
59
|
-
{options.map((option) => (
|
|
58
|
+
{options.map((option: { type: string; title: string; spec: Record<string, unknown> }) => (
|
|
60
59
|
<button
|
|
61
60
|
key={option.type}
|
|
62
61
|
className={classes.quick_reply}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ReactNode, useCallback } from 'react';
|
|
2
2
|
import classes from './hint-template.module.scss';
|
|
3
|
-
import { formatTime } from '
|
|
3
|
+
import { formatTime } from '../../../utils';
|
|
4
4
|
import {
|
|
5
5
|
ConversationErrorMessage,
|
|
6
6
|
ConversationMessage,
|
|
7
7
|
MessageTemplateType,
|
|
8
8
|
} from '@asgard-js/core';
|
|
9
|
-
import { useAsgardTemplateContext, useAsgardThemeContext } from '
|
|
9
|
+
import { useAsgardTemplateContext, useAsgardThemeContext } from '../../../context';
|
|
10
10
|
import clsx from 'clsx';
|
|
11
11
|
|
|
12
12
|
interface HintTemplateProps {
|
|
@@ -2,11 +2,10 @@ import { ReactNode, useState } from 'react';
|
|
|
2
2
|
import { TemplateBox, TemplateBoxContent } from '../template-box';
|
|
3
3
|
import { Avatar } from '../avatar';
|
|
4
4
|
import styles from './image-template.module.scss';
|
|
5
|
-
import { ConversationBotMessage } from '@asgard-js/core';
|
|
6
|
-
import { useAsgardContext } from '
|
|
7
|
-
import { useAsgardThemeContext } from '
|
|
8
|
-
import
|
|
9
|
-
import CloseSvg from 'src/icons/close.svg?react';
|
|
5
|
+
import { ConversationBotMessage, ImageMessageTemplate } from '@asgard-js/core';
|
|
6
|
+
import { useAsgardContext } from '../../../context/asgard-service-context';
|
|
7
|
+
import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
|
|
8
|
+
import CloseSvg from '../../../icons/close.svg?react';
|
|
10
9
|
|
|
11
10
|
interface ImageTemplateProps {
|
|
12
11
|
message: ConversationBotMessage;
|
|
@@ -37,6 +36,7 @@ export function ImageTemplate(props: ImageTemplateProps): ReactNode {
|
|
|
37
36
|
</div>
|
|
38
37
|
);
|
|
39
38
|
}
|
|
39
|
+
|
|
40
40
|
return (
|
|
41
41
|
<TemplateBox
|
|
42
42
|
className="asgard-image-template"
|
|
@@ -50,7 +50,7 @@ export function ImageTemplate(props: ImageTemplateProps): ReactNode {
|
|
|
50
50
|
time={message.time}
|
|
51
51
|
>
|
|
52
52
|
<div className={styles.image_box} onClick={() => setIsFullScreen(true)}>
|
|
53
|
-
<img src={previewImageUrl} alt="
|
|
53
|
+
<img src={previewImageUrl} alt="Conversation content" />
|
|
54
54
|
</div>
|
|
55
55
|
</TemplateBoxContent>
|
|
56
56
|
</TemplateBox>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReactNode, useCallback } from 'react';
|
|
2
2
|
import styles from './quick-replies.module.scss';
|
|
3
|
-
import { useAsgardContext } from '
|
|
4
|
-
import { useAsgardThemeContext } from '
|
|
3
|
+
import { useAsgardContext } from '../../../context/asgard-service-context';
|
|
4
|
+
import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
|
|
5
5
|
import clsx from 'clsx';
|
|
6
6
|
|
|
7
7
|
interface QuickRepliesProps {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { CSSProperties, ReactNode, useCallback, useMemo, useRef } from 'react';
|
|
2
|
-
import { useAsgardContext } from '
|
|
2
|
+
import { useAsgardContext } from '../../../context/asgard-service-context';
|
|
3
3
|
import clsx from 'clsx';
|
|
4
4
|
import { TemplateBox, TemplateBoxContent } from '../template-box';
|
|
5
5
|
import { Avatar } from '../avatar';
|
|
6
|
-
import { useDebounce, useResizeObserver } from '
|
|
6
|
+
import { useDebounce, useResizeObserver } from '../../../hooks';
|
|
7
7
|
import classes from './text-template.module.scss';
|
|
8
|
-
import { useAsgardThemeContext } from '
|
|
9
|
-
import { useMarkdownRenderer } from '
|
|
8
|
+
import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
|
|
9
|
+
import { useMarkdownRenderer } from '../../../hooks/use-react-markdown-renderer';
|
|
10
10
|
interface BotTypingBoxProps {
|
|
11
11
|
isTyping: boolean;
|
|
12
12
|
typingText: string | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactNode, useMemo } from 'react';
|
|
2
2
|
import { BotTypingBox } from './bot-typing-box';
|
|
3
|
-
import { useAsgardContext } from '
|
|
3
|
+
import { useAsgardContext } from '../../../context/asgard-service-context';
|
|
4
4
|
|
|
5
5
|
interface BotTypingPlaceholderProps {
|
|
6
6
|
placeholder: string;
|
|
@@ -5,9 +5,9 @@ import { TemplateBox, TemplateBoxContent } from '../template-box';
|
|
|
5
5
|
import classes from './text-template.module.scss';
|
|
6
6
|
import { Avatar } from '../avatar';
|
|
7
7
|
import { Time } from '../time';
|
|
8
|
-
import { useAsgardContext } from '
|
|
9
|
-
import { useAsgardThemeContext } from '
|
|
10
|
-
import { useMarkdownRenderer } from '
|
|
8
|
+
import { useAsgardContext } from '../../../context/asgard-service-context';
|
|
9
|
+
import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
|
|
10
|
+
import { useMarkdownRenderer } from '../../../hooks/use-react-markdown-renderer';
|
|
11
11
|
|
|
12
12
|
interface TextTemplateProps {
|
|
13
13
|
message: ConversationMessage;
|
|
@@ -2,7 +2,7 @@ import { describe, it, expect, vi } from 'vitest';
|
|
|
2
2
|
import { renderHook } from '@testing-library/react';
|
|
3
3
|
import { render, screen, fireEvent } from '@testing-library/react';
|
|
4
4
|
import '@testing-library/jest-dom';
|
|
5
|
-
import { useMarkdownRenderer, manageCacheSize, MAX_CACHE_SIZE } from '
|
|
5
|
+
import { useMarkdownRenderer, manageCacheSize, MAX_CACHE_SIZE } from '../../../hooks/use-react-markdown-renderer';
|
|
6
6
|
import { AsgardTemplateContextProvider } from '../../../context/asgard-template-context';
|
|
7
7
|
|
|
8
8
|
describe('useMarkdownRenderer - Simple Tests', () => {
|
|
@@ -23,7 +23,7 @@ describe('useMarkdownRenderer - Simple Tests', () => {
|
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
it('should handle null input safely', () => {
|
|
26
|
-
const { result } = renderHook(() => useMarkdownRenderer(null
|
|
26
|
+
const { result } = renderHook(() => useMarkdownRenderer(null));
|
|
27
27
|
|
|
28
28
|
expect(result.current.htmlBlocks).toBeDefined();
|
|
29
29
|
expect(result.current.lastTypingText).toBe('');
|
|
@@ -658,7 +658,7 @@ a_{m1} & a_{m2} & \\cdots & a_{mn}
|
|
|
658
658
|
const mathText = 'Cached math: $E = mc^2$';
|
|
659
659
|
|
|
660
660
|
// First render
|
|
661
|
-
|
|
661
|
+
renderHook(() => useMarkdownRenderer(mathText, 0));
|
|
662
662
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
663
663
|
|
|
664
664
|
// Second render should be faster (cached)
|
|
@@ -679,7 +679,7 @@ a_{m1} & a_{m2} & \\cdots & a_{mn}
|
|
|
679
679
|
});
|
|
680
680
|
|
|
681
681
|
it('should not evict entries when cache is below limit', () => {
|
|
682
|
-
const cache = new Map<string,
|
|
682
|
+
const cache = new Map<string, string>();
|
|
683
683
|
cache.set('key1', 'value1');
|
|
684
684
|
cache.set('key2', 'value2');
|
|
685
685
|
|
|
@@ -691,7 +691,7 @@ a_{m1} & a_{m2} & \\cdots & a_{mn}
|
|
|
691
691
|
});
|
|
692
692
|
|
|
693
693
|
it('should evict oldest entry when cache reaches MAX_CACHE_SIZE', () => {
|
|
694
|
-
const cache = new Map<string,
|
|
694
|
+
const cache = new Map<string, string>();
|
|
695
695
|
|
|
696
696
|
// Fill cache to exactly MAX_CACHE_SIZE
|
|
697
697
|
for (let i = 0; i < MAX_CACHE_SIZE; i++) {
|
|
@@ -710,7 +710,7 @@ a_{m1} & a_{m2} & \\cdots & a_{mn}
|
|
|
710
710
|
});
|
|
711
711
|
|
|
712
712
|
it('should implement LRU eviction strategy correctly', () => {
|
|
713
|
-
const cache = new Map<string,
|
|
713
|
+
const cache = new Map<string, string>();
|
|
714
714
|
|
|
715
715
|
// Fill cache to MAX_CACHE_SIZE
|
|
716
716
|
for (let i = 0; i < MAX_CACHE_SIZE; i++) {
|
|
@@ -732,7 +732,7 @@ a_{m1} & a_{m2} & \\cdots & a_{mn}
|
|
|
732
732
|
});
|
|
733
733
|
|
|
734
734
|
it('should handle empty cache gracefully', () => {
|
|
735
|
-
const cache = new Map<string,
|
|
735
|
+
const cache = new Map<string, string>();
|
|
736
736
|
|
|
737
737
|
manageCacheSize(cache);
|
|
738
738
|
|
|
@@ -740,7 +740,7 @@ a_{m1} & a_{m2} & \\cdots & a_{mn}
|
|
|
740
740
|
});
|
|
741
741
|
|
|
742
742
|
it('should handle cache with exactly MAX_CACHE_SIZE entries', () => {
|
|
743
|
-
const cache = new Map<string,
|
|
743
|
+
const cache = new Map<string, string>();
|
|
744
744
|
|
|
745
745
|
// Fill cache to exactly MAX_CACHE_SIZE
|
|
746
746
|
for (let i = 0; i < MAX_CACHE_SIZE; i++) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReactNode, useMemo } from 'react';
|
|
2
|
-
import { formatTime } from '
|
|
2
|
+
import { formatTime } from '../../../utils';
|
|
3
3
|
import styles from './time.module.scss';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
|
-
import { useAsgardThemeContext } from '
|
|
5
|
+
import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
|
|
6
6
|
|
|
7
7
|
interface TimeProps {
|
|
8
8
|
time?: Date;
|
|
@@ -7,10 +7,10 @@ import React, {
|
|
|
7
7
|
ReactNode,
|
|
8
8
|
} from 'react';
|
|
9
9
|
import { ClientConfig } from '@asgard-js/core';
|
|
10
|
-
import { getBotProviderModels } from '
|
|
11
|
-
import { useDeepCompareMemo } from '
|
|
12
|
-
import { deepMerge } from '
|
|
13
|
-
import { extractRefs } from '
|
|
10
|
+
import { getBotProviderModels } from '../models/bot-provider';
|
|
11
|
+
import { useDeepCompareMemo } from '../hooks';
|
|
12
|
+
import { deepMerge } from '../utils/deep-merge';
|
|
13
|
+
import { extractRefs } from '../utils/extractors';
|
|
14
14
|
|
|
15
15
|
type AsyncInitializers = {
|
|
16
16
|
[key: string]: () => Promise<unknown>;
|
|
@@ -17,7 +17,7 @@ export interface AsgardTemplateContextValue {
|
|
|
17
17
|
}: {
|
|
18
18
|
sse: {
|
|
19
19
|
sendMessage: (
|
|
20
|
-
payload: Pick<FetchSsePayload, 'text'
|
|
20
|
+
payload: Pick<FetchSsePayload, 'text'> & Partial<Pick<FetchSsePayload, 'payload'>>
|
|
21
21
|
) => void;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
@@ -42,7 +42,7 @@ interface AsgardTemplateContextProviderProps extends PropsWithChildren {
|
|
|
42
42
|
}: {
|
|
43
43
|
sse: {
|
|
44
44
|
sendMessage: (
|
|
45
|
-
payload: Pick<FetchSsePayload, 'text'
|
|
45
|
+
payload: Pick<FetchSsePayload, 'text'> & Partial<Pick<FetchSsePayload, 'payload'>>
|
|
46
46
|
) => void;
|
|
47
47
|
};
|
|
48
48
|
}
|
|
@@ -7,11 +7,11 @@ import {
|
|
|
7
7
|
useMemo,
|
|
8
8
|
useCallback,
|
|
9
9
|
} from 'react';
|
|
10
|
-
import { deepMerge } from '
|
|
10
|
+
import { deepMerge } from '../utils/deep-merge';
|
|
11
11
|
import {
|
|
12
12
|
useAsgardAppInitializationContext,
|
|
13
13
|
Annotations,
|
|
14
|
-
} from '
|
|
14
|
+
} from './asgard-app-initialization-context';
|
|
15
15
|
|
|
16
16
|
export interface AsgardThemeContextValue {
|
|
17
17
|
chatbot: Pick<
|
|
@@ -257,7 +257,7 @@ export function AsgardThemeContextProvider(
|
|
|
257
257
|
userMessage: {},
|
|
258
258
|
};
|
|
259
259
|
|
|
260
|
-
const tempTheme = deepMerge(defaultAsgardThemeContextValue, {
|
|
260
|
+
const tempTheme = deepMerge(defaultAsgardThemeContextValue as unknown as Record<string, unknown>, {
|
|
261
261
|
chatbot: {
|
|
262
262
|
backgroundColor: themeFromAnnotations.chatbot?.backgroundColor,
|
|
263
263
|
borderColor: themeFromAnnotations.chatbot?.borderColor,
|
package/src/hooks/index.ts
CHANGED
|
@@ -8,4 +8,4 @@ export * from './use-prevent-over-scrolling';
|
|
|
8
8
|
export * from './use-update-vh';
|
|
9
9
|
export * from './use-resize-observer';
|
|
10
10
|
export * from './use-deep-compare-memo';
|
|
11
|
-
export * from '
|
|
11
|
+
export * from './use-react-markdown-renderer';
|
package/src/hooks/use-channel.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
|
12
12
|
|
|
13
13
|
export interface UseChannelProps {
|
|
14
14
|
defaultIsOpen?: boolean;
|
|
15
|
-
resetPayload?: Pick<FetchSsePayload, 'text'
|
|
15
|
+
resetPayload?: Pick<FetchSsePayload, 'text'> & Partial<Pick<FetchSsePayload, 'payload'>>;
|
|
16
16
|
client: AsgardServiceClient | null;
|
|
17
17
|
customChannelId: string;
|
|
18
18
|
customMessageId?: string;
|
|
@@ -30,8 +30,8 @@ export interface UseChannelReturn {
|
|
|
30
30
|
isResetting: boolean;
|
|
31
31
|
isConnecting: boolean;
|
|
32
32
|
conversation: Conversation | null;
|
|
33
|
-
sendMessage?: (payload: Pick<FetchSsePayload, 'text'
|
|
34
|
-
resetChannel?: (payload?: Pick<FetchSsePayload, 'text'
|
|
33
|
+
sendMessage?: (payload: Pick<FetchSsePayload, 'text'> & Partial<Pick<FetchSsePayload, 'payload'>>) => void;
|
|
34
|
+
resetChannel?: (payload?: Pick<FetchSsePayload, 'text'> & Partial<Pick<FetchSsePayload, 'payload'>>) => void;
|
|
35
35
|
closeChannel?: () => void;
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -61,7 +61,7 @@ export function useChannel(props: UseChannelProps): UseChannelReturn {
|
|
|
61
61
|
const [conversation, setConversation] = useState<Conversation | null>(null);
|
|
62
62
|
|
|
63
63
|
const resetChannel = useCallback(
|
|
64
|
-
async (payload?: Pick<FetchSsePayload, 'text'
|
|
64
|
+
async (payload?: Pick<FetchSsePayload, 'text'> & Partial<Pick<FetchSsePayload, 'payload'>>) => {
|
|
65
65
|
const conversation = new Conversation({
|
|
66
66
|
messages: new Map(
|
|
67
67
|
initMessages?.map((message) => [message.messageId, message])
|
|
@@ -106,7 +106,7 @@ export function useChannel(props: UseChannelProps): UseChannelReturn {
|
|
|
106
106
|
);
|
|
107
107
|
|
|
108
108
|
const closeChannel = useCallback(() => {
|
|
109
|
-
setChannel((prevChannel) => {
|
|
109
|
+
setChannel((prevChannel: Channel | null) => {
|
|
110
110
|
prevChannel?.close();
|
|
111
111
|
|
|
112
112
|
return null;
|
|
@@ -118,9 +118,9 @@ export function useChannel(props: UseChannelProps): UseChannelReturn {
|
|
|
118
118
|
}, []);
|
|
119
119
|
|
|
120
120
|
const sendMessage = useCallback(
|
|
121
|
-
(payload: Pick<FetchSsePayload, 'text'
|
|
122
|
-
channel?.sendMessage(payload),
|
|
123
|
-
[channel]
|
|
121
|
+
(payload: Pick<FetchSsePayload, 'text'> & Partial<Pick<FetchSsePayload, 'payload'>>) =>
|
|
122
|
+
channel?.sendMessage({ ...payload, customMessageId }),
|
|
123
|
+
[channel, customMessageId]
|
|
124
124
|
);
|
|
125
125
|
|
|
126
126
|
useEffect(() => {
|