@asgard-js/react 0.0.40 → 0.0.41-canary.2
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.map +1 -1
- package/dist/components/chatbot/chatbot-footer/chatbot-footer.d.ts.map +1 -1
- package/dist/components/templates/index.d.ts +1 -0
- package/dist/components/templates/index.d.ts.map +1 -1
- package/dist/components/templates/user-image-template/index.d.ts +2 -0
- package/dist/components/templates/user-image-template/index.d.ts.map +1 -0
- package/dist/components/templates/user-image-template/user-image-template.d.ts +12 -0
- package/dist/components/templates/user-image-template/user-image-template.d.ts.map +1 -0
- package/dist/context/asgard-service-context.d.ts +1 -0
- package/dist/context/asgard-service-context.d.ts.map +1 -1
- package/dist/hooks/use-channel.d.ts +1 -1
- package/dist/hooks/use-channel.d.ts.map +1 -1
- package/dist/index.js +17672 -18151
- package/dist/style.css +1 -1
- package/dist/utils/file-validation.d.ts +12 -0
- package/dist/utils/file-validation.d.ts.map +1 -0
- package/package.json +2 -2
- package/.babelrc +0 -12
- package/eslint.config.cjs +0 -12
- package/src/components/chatbot/chatbot-body/chatbot-body.module.scss +0 -13
- package/src/components/chatbot/chatbot-body/chatbot-body.tsx +0 -45
- package/src/components/chatbot/chatbot-body/conversation-message-renderer.tsx +0 -55
- package/src/components/chatbot/chatbot-body/index.ts +0 -1
- package/src/components/chatbot/chatbot-container/chatbot-container.module.scss +0 -41
- package/src/components/chatbot/chatbot-container/chatbot-container.tsx +0 -49
- package/src/components/chatbot/chatbot-container/chatbot-full-screen-container.tsx +0 -54
- package/src/components/chatbot/chatbot-footer/chatbot-footer.module.scss +0 -67
- package/src/components/chatbot/chatbot-footer/chatbot-footer.tsx +0 -140
- package/src/components/chatbot/chatbot-footer/index.ts +0 -1
- package/src/components/chatbot/chatbot-footer/speech-input-button.tsx +0 -132
- package/src/components/chatbot/chatbot-header/chatbot-header.module.scss +0 -48
- package/src/components/chatbot/chatbot-header/chatbot-header.tsx +0 -98
- package/src/components/chatbot/chatbot-header/index.ts +0 -1
- package/src/components/chatbot/chatbot.spec.tsx +0 -8
- package/src/components/chatbot/chatbot.tsx +0 -121
- package/src/components/chatbot/profile-icon.tsx +0 -26
- package/src/components/index.ts +0 -2
- package/src/components/templates/avatar/avatar.module.scss +0 -6
- package/src/components/templates/avatar/avatar.tsx +0 -28
- package/src/components/templates/avatar/index.ts +0 -1
- package/src/components/templates/button-template/button-template.module.scss +0 -0
- package/src/components/templates/button-template/button-template.tsx +0 -45
- package/src/components/templates/button-template/card.module.scss +0 -58
- package/src/components/templates/button-template/card.spec.tsx +0 -213
- package/src/components/templates/button-template/card.tsx +0 -123
- package/src/components/templates/button-template/index.ts +0 -1
- package/src/components/templates/carousel-template/carousel-template.module.scss +0 -15
- package/src/components/templates/carousel-template/carousel-template.tsx +0 -49
- package/src/components/templates/carousel-template/index.ts +0 -1
- package/src/components/templates/chart-template/chart-template.module.scss +0 -52
- package/src/components/templates/chart-template/chart-template.tsx +0 -75
- package/src/components/templates/chart-template/index.ts +0 -1
- package/src/components/templates/hint-template/hint-template.module.scss +0 -43
- package/src/components/templates/hint-template/hint-template.tsx +0 -76
- package/src/components/templates/hint-template/index.ts +0 -1
- package/src/components/templates/image-template/image-template.module.scss +0 -67
- package/src/components/templates/image-template/image-template.tsx +0 -58
- package/src/components/templates/image-template/index.ts +0 -1
- package/src/components/templates/index.ts +0 -10
- package/src/components/templates/quick-replies/index.ts +0 -1
- package/src/components/templates/quick-replies/quick-replies.module.scss +0 -16
- package/src/components/templates/quick-replies/quick-replies.tsx +0 -47
- package/src/components/templates/template-box/index.ts +0 -2
- package/src/components/templates/template-box/template-box-content.module.scss +0 -13
- package/src/components/templates/template-box/template-box-content.tsx +0 -30
- package/src/components/templates/template-box/template-box.module.scss +0 -19
- package/src/components/templates/template-box/template-box.tsx +0 -48
- package/src/components/templates/text-template/bot-typing-box.tsx +0 -81
- package/src/components/templates/text-template/bot-typing-placeholder.tsx +0 -28
- package/src/components/templates/text-template/index.ts +0 -3
- package/src/components/templates/text-template/text-template.module.scss +0 -131
- package/src/components/templates/text-template/text-template.tsx +0 -94
- package/src/components/templates/text-template/use-react-markdown-renderer.spec.tsx +0 -758
- package/src/components/templates/time/index.ts +0 -1
- package/src/components/templates/time/time.module.scss +0 -6
- package/src/components/templates/time/time.tsx +0 -34
- package/src/context/asgard-app-initialization-context.tsx +0 -154
- package/src/context/asgard-service-context.tsx +0 -145
- package/src/context/asgard-template-context.tsx +0 -83
- package/src/context/asgard-theme-context.tsx +0 -546
- package/src/context/index.ts +0 -4
- package/src/hooks/index.ts +0 -11
- package/src/hooks/use-asgard-service-client.ts +0 -68
- package/src/hooks/use-channel.ts +0 -154
- package/src/hooks/use-debounce.ts +0 -18
- package/src/hooks/use-deep-compare-memo.ts +0 -19
- package/src/hooks/use-is-on-screen-keyboard-open.ts +0 -43
- package/src/hooks/use-on-screen-keyboard-scroll-fix.ts +0 -15
- package/src/hooks/use-prevent-over-scrolling.ts +0 -77
- package/src/hooks/use-react-markdown-renderer.tsx +0 -278
- package/src/hooks/use-resize-observer.tsx +0 -27
- package/src/hooks/use-update-vh.ts +0 -30
- package/src/hooks/use-viewport-size.ts +0 -51
- package/src/icons/add_a_photo.svg +0 -3
- package/src/icons/bot.svg +0 -14
- package/src/icons/close.svg +0 -3
- package/src/icons/distance.svg +0 -3
- package/src/icons/mic.svg +0 -3
- package/src/icons/photo_library.svg +0 -3
- package/src/icons/profile.svg +0 -28
- package/src/icons/refresh.svg +0 -3
- package/src/icons/send.svg +0 -3
- package/src/icons/stop.svg +0 -22
- package/src/icons/volume_up.svg +0 -3
- package/src/index.ts +0 -4
- package/src/models/bot-provider.ts +0 -108
- package/src/styles/_index.scss +0 -1
- package/src/styles/_styles.scss +0 -11
- package/src/styles/colors/_colors.scss +0 -10
- package/src/styles/colors/_index.scss +0 -1
- package/src/styles/colors/_variables.scss +0 -72
- package/src/styles/palette/_index.scss +0 -1
- package/src/styles/palette/_palette.scss +0 -42
- package/src/styles/palette/_variables.scss +0 -40
- package/src/styles/radius/_index.scss +0 -1
- package/src/styles/radius/_radius.scss +0 -8
- package/src/styles/radius/_variables.scss +0 -12
- package/src/styles/spacing/_index.scss +0 -1
- package/src/styles/spacing/_spacing.scss +0 -8
- package/src/styles/spacing/_variables.scss +0 -13
- package/src/styles/utils/_index.scss +0 -1
- package/src/styles/utils/_map.scss +0 -22
- package/src/test-setup.ts +0 -1
- package/src/utils/color-utils.ts +0 -52
- package/src/utils/deep-merge.ts +0 -26
- package/src/utils/extractors.ts +0 -20
- package/src/utils/format-time.ts +0 -8
- package/src/utils/index.ts +0 -1
- package/src/utils/is.ts +0 -72
- package/src/utils/selectors.ts +0 -7
- package/src/utils/uri-validation.spec.ts +0 -208
- package/src/utils/uri-validation.ts +0 -103
- package/tsconfig.json +0 -16
- package/tsconfig.lib.json +0 -63
- package/tsconfig.spec.json +0 -36
- package/tsconfig.tsbuildinfo +0 -1
- package/vite.config.ts +0 -63
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './time';
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { ReactNode, useMemo } from 'react';
|
|
2
|
-
import { formatTime } from '../../../utils';
|
|
3
|
-
import styles from './time.module.scss';
|
|
4
|
-
import clsx from 'clsx';
|
|
5
|
-
import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
|
|
6
|
-
|
|
7
|
-
interface TimeProps {
|
|
8
|
-
time?: Date;
|
|
9
|
-
className?: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function Time(props: TimeProps): ReactNode {
|
|
13
|
-
const { time, className } = props;
|
|
14
|
-
|
|
15
|
-
const { template } = useAsgardThemeContext();
|
|
16
|
-
|
|
17
|
-
const timeStyle = useMemo(
|
|
18
|
-
() => ({
|
|
19
|
-
color: template?.time?.style?.color,
|
|
20
|
-
}),
|
|
21
|
-
[template?.time?.style?.color]
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
if (!time) return null;
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<div
|
|
28
|
-
className={clsx('asgard-time', styles.time, className)}
|
|
29
|
-
style={timeStyle}
|
|
30
|
-
>
|
|
31
|
-
{formatTime(time)}
|
|
32
|
-
</div>
|
|
33
|
-
);
|
|
34
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
createContext,
|
|
3
|
-
useContext,
|
|
4
|
-
useEffect,
|
|
5
|
-
useState,
|
|
6
|
-
PropsWithChildren,
|
|
7
|
-
ReactNode,
|
|
8
|
-
} from 'react';
|
|
9
|
-
import { ClientConfig } from '@asgard-js/core';
|
|
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
|
-
|
|
15
|
-
type AsyncInitializers = {
|
|
16
|
-
[key: string]: () => Promise<unknown>;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export interface Annotations {
|
|
20
|
-
embedConfig: {
|
|
21
|
-
avatar?: string;
|
|
22
|
-
botTypingPlaceholder?: string;
|
|
23
|
-
debugMode?: boolean;
|
|
24
|
-
fullScreen?: boolean;
|
|
25
|
-
inputPlaceholder?: string;
|
|
26
|
-
theme: {
|
|
27
|
-
chatbot: {
|
|
28
|
-
backgroundColor?: string;
|
|
29
|
-
borderColor?: string;
|
|
30
|
-
inactiveColor?: string;
|
|
31
|
-
primaryComponent?: {
|
|
32
|
-
mainColor?: string;
|
|
33
|
-
secondaryColor?: string;
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
botMessage: {
|
|
37
|
-
backgroundColor?: string;
|
|
38
|
-
carouselButtonBackgroundColor?: string;
|
|
39
|
-
color?: string;
|
|
40
|
-
};
|
|
41
|
-
userMessage: {
|
|
42
|
-
backgroundColor?: string;
|
|
43
|
-
color?: string;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
title?: string;
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface AsgardAppInitializationContextValue {
|
|
51
|
-
data: {
|
|
52
|
-
annotations?: Annotations;
|
|
53
|
-
};
|
|
54
|
-
loading: boolean;
|
|
55
|
-
error: Error | null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export const AsgardAppInitializationContext =
|
|
59
|
-
createContext<AsgardAppInitializationContextValue>({
|
|
60
|
-
data: {},
|
|
61
|
-
loading: true,
|
|
62
|
-
error: null,
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
export interface AsgardAppInitializationContextProviderProps {
|
|
66
|
-
enabled: boolean;
|
|
67
|
-
config: ClientConfig;
|
|
68
|
-
asyncInitializers?: AsyncInitializers;
|
|
69
|
-
loadingComponent?: React.ReactNode;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export const AsgardAppInitializationContextProvider = (
|
|
73
|
-
props: PropsWithChildren<AsgardAppInitializationContextProviderProps>
|
|
74
|
-
): ReactNode => {
|
|
75
|
-
const {
|
|
76
|
-
enabled,
|
|
77
|
-
asyncInitializers: asyncInitializersFromProp = {},
|
|
78
|
-
children,
|
|
79
|
-
loadingComponent = <div>Loading...</div>,
|
|
80
|
-
} = props;
|
|
81
|
-
|
|
82
|
-
const botProviderModels = useDeepCompareMemo(
|
|
83
|
-
() => getBotProviderModels(props.config),
|
|
84
|
-
[props.config]
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
const asyncInitializers = useDeepCompareMemo(
|
|
88
|
-
() =>
|
|
89
|
-
deepMerge(
|
|
90
|
-
{ annotations: botProviderModels.getAnnotations },
|
|
91
|
-
asyncInitializersFromProp
|
|
92
|
-
),
|
|
93
|
-
[...extractRefs(asyncInitializersFromProp), botProviderModels]
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
const [data, setData] = useState<AsgardAppInitializationContextValue['data']>(
|
|
97
|
-
{}
|
|
98
|
-
);
|
|
99
|
-
const [loading, setLoading] = useState(true);
|
|
100
|
-
const [error, setError] = useState<Error | null>(null);
|
|
101
|
-
|
|
102
|
-
useEffect(() => {
|
|
103
|
-
let isMounted = true;
|
|
104
|
-
|
|
105
|
-
if (!enabled) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
setLoading(true);
|
|
110
|
-
|
|
111
|
-
Promise.all(
|
|
112
|
-
Object.entries(asyncInitializers).map(async ([key, fn]) => {
|
|
113
|
-
try {
|
|
114
|
-
const value = await fn();
|
|
115
|
-
|
|
116
|
-
return [key, value];
|
|
117
|
-
} catch {
|
|
118
|
-
return [key, undefined];
|
|
119
|
-
}
|
|
120
|
-
})
|
|
121
|
-
)
|
|
122
|
-
.then((results) => {
|
|
123
|
-
if (isMounted) setData(Object.fromEntries(results));
|
|
124
|
-
})
|
|
125
|
-
.catch((err) => {
|
|
126
|
-
if (isMounted) setError(err);
|
|
127
|
-
})
|
|
128
|
-
.finally(() => {
|
|
129
|
-
if (isMounted) setLoading(false);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
return (): void => {
|
|
133
|
-
isMounted = false;
|
|
134
|
-
};
|
|
135
|
-
}, [asyncInitializers, enabled]);
|
|
136
|
-
|
|
137
|
-
if (!enabled) {
|
|
138
|
-
return children;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (loading) {
|
|
142
|
-
return loadingComponent;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return (
|
|
146
|
-
<AsgardAppInitializationContext.Provider value={{ data, loading, error }}>
|
|
147
|
-
{children}
|
|
148
|
-
</AsgardAppInitializationContext.Provider>
|
|
149
|
-
);
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
export const useAsgardAppInitializationContext =
|
|
153
|
-
(): AsgardAppInitializationContextValue =>
|
|
154
|
-
useContext(AsgardAppInitializationContext);
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AsgardServiceClient,
|
|
3
|
-
ClientConfig,
|
|
4
|
-
ConversationMessage,
|
|
5
|
-
} from '@asgard-js/core';
|
|
6
|
-
import {
|
|
7
|
-
createContext,
|
|
8
|
-
ForwardedRef,
|
|
9
|
-
ReactNode,
|
|
10
|
-
RefObject,
|
|
11
|
-
useContext,
|
|
12
|
-
useImperativeHandle,
|
|
13
|
-
useMemo,
|
|
14
|
-
useRef,
|
|
15
|
-
} from 'react';
|
|
16
|
-
import {
|
|
17
|
-
useAsgardServiceClient,
|
|
18
|
-
useChannel,
|
|
19
|
-
UseChannelProps,
|
|
20
|
-
UseChannelReturn,
|
|
21
|
-
} from '../hooks';
|
|
22
|
-
|
|
23
|
-
export interface AsgardServiceContextValue {
|
|
24
|
-
avatar?: string;
|
|
25
|
-
client: AsgardServiceClient | null;
|
|
26
|
-
isOpen: boolean;
|
|
27
|
-
isResetting: boolean;
|
|
28
|
-
isConnecting: boolean;
|
|
29
|
-
messages: Map<string, ConversationMessage> | null;
|
|
30
|
-
messageBoxBottomRef: RefObject<HTMLDivElement>;
|
|
31
|
-
sendMessage?: UseChannelReturn['sendMessage'];
|
|
32
|
-
resetChannel?: UseChannelReturn['resetChannel'];
|
|
33
|
-
closeChannel?: UseChannelReturn['closeChannel'];
|
|
34
|
-
botTypingPlaceholder?: string;
|
|
35
|
-
inputPlaceholder?: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export const AsgardServiceContext = createContext<AsgardServiceContextValue>({
|
|
39
|
-
avatar: undefined,
|
|
40
|
-
client: null,
|
|
41
|
-
isOpen: false,
|
|
42
|
-
isResetting: false,
|
|
43
|
-
isConnecting: false,
|
|
44
|
-
messages: null,
|
|
45
|
-
messageBoxBottomRef: { current: null },
|
|
46
|
-
botTypingPlaceholder: undefined,
|
|
47
|
-
inputPlaceholder: undefined,
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
export interface AsgardServiceContextProviderProps {
|
|
51
|
-
children: ReactNode;
|
|
52
|
-
parentRef?: ForwardedRef<
|
|
53
|
-
Partial<{ serviceContext?: AsgardServiceContextValue }>
|
|
54
|
-
>;
|
|
55
|
-
avatar?: string;
|
|
56
|
-
config: ClientConfig;
|
|
57
|
-
botTypingPlaceholder?: string;
|
|
58
|
-
inputPlaceholder?: string;
|
|
59
|
-
customChannelId: string;
|
|
60
|
-
customMessageId?: string;
|
|
61
|
-
delayTime?: number;
|
|
62
|
-
initMessages?: ConversationMessage[];
|
|
63
|
-
onSseMessage?: UseChannelProps['onSseMessage'];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function AsgardServiceContextProvider(
|
|
67
|
-
props: AsgardServiceContextProviderProps
|
|
68
|
-
): ReactNode {
|
|
69
|
-
const {
|
|
70
|
-
avatar,
|
|
71
|
-
children,
|
|
72
|
-
parentRef,
|
|
73
|
-
config,
|
|
74
|
-
botTypingPlaceholder,
|
|
75
|
-
inputPlaceholder,
|
|
76
|
-
customChannelId,
|
|
77
|
-
initMessages,
|
|
78
|
-
onSseMessage,
|
|
79
|
-
} = props;
|
|
80
|
-
|
|
81
|
-
const messageBoxBottomRef = useRef<HTMLDivElement>(null);
|
|
82
|
-
|
|
83
|
-
const client = useAsgardServiceClient({ config });
|
|
84
|
-
|
|
85
|
-
const {
|
|
86
|
-
isOpen,
|
|
87
|
-
isResetting,
|
|
88
|
-
isConnecting,
|
|
89
|
-
conversation,
|
|
90
|
-
sendMessage,
|
|
91
|
-
resetChannel,
|
|
92
|
-
closeChannel,
|
|
93
|
-
} = useChannel({
|
|
94
|
-
client,
|
|
95
|
-
customChannelId,
|
|
96
|
-
initMessages,
|
|
97
|
-
onSseMessage,
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
const contextValue = useMemo(
|
|
101
|
-
() => ({
|
|
102
|
-
avatar,
|
|
103
|
-
client,
|
|
104
|
-
isOpen,
|
|
105
|
-
isResetting,
|
|
106
|
-
isConnecting,
|
|
107
|
-
messages: conversation?.messages ?? null,
|
|
108
|
-
sendMessage,
|
|
109
|
-
resetChannel,
|
|
110
|
-
closeChannel,
|
|
111
|
-
botTypingPlaceholder,
|
|
112
|
-
inputPlaceholder,
|
|
113
|
-
messageBoxBottomRef,
|
|
114
|
-
}),
|
|
115
|
-
[
|
|
116
|
-
avatar,
|
|
117
|
-
client,
|
|
118
|
-
isOpen,
|
|
119
|
-
isResetting,
|
|
120
|
-
isConnecting,
|
|
121
|
-
conversation?.messages,
|
|
122
|
-
sendMessage,
|
|
123
|
-
resetChannel,
|
|
124
|
-
closeChannel,
|
|
125
|
-
botTypingPlaceholder,
|
|
126
|
-
inputPlaceholder,
|
|
127
|
-
]
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
useImperativeHandle(parentRef, () => {
|
|
131
|
-
return {
|
|
132
|
-
serviceContext: contextValue,
|
|
133
|
-
};
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
return (
|
|
137
|
-
<AsgardServiceContext.Provider value={contextValue}>
|
|
138
|
-
{children}
|
|
139
|
-
</AsgardServiceContext.Provider>
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export function useAsgardContext(): AsgardServiceContextValue {
|
|
144
|
-
return useContext(AsgardServiceContext);
|
|
145
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createContext,
|
|
3
|
-
PropsWithChildren,
|
|
4
|
-
ReactNode,
|
|
5
|
-
useContext,
|
|
6
|
-
useMemo,
|
|
7
|
-
} from 'react';
|
|
8
|
-
import { ConversationErrorMessage, FetchSsePayload } from '@asgard-js/core';
|
|
9
|
-
|
|
10
|
-
export interface AsgardTemplateContextValue {
|
|
11
|
-
onErrorClick?: (message: ConversationErrorMessage) => void;
|
|
12
|
-
errorMessageRenderer?: (message: ConversationErrorMessage) => ReactNode;
|
|
13
|
-
onTemplateBtnClick?: (
|
|
14
|
-
payload: Record<string, unknown>,
|
|
15
|
-
{
|
|
16
|
-
sse,
|
|
17
|
-
}: {
|
|
18
|
-
sse: {
|
|
19
|
-
sendMessage: (
|
|
20
|
-
payload: Pick<FetchSsePayload, 'text'> & Partial<Pick<FetchSsePayload, 'payload'>>
|
|
21
|
-
) => void;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
) => void;
|
|
25
|
-
defaultLinkTarget?: '_blank' | '_self' | '_parent' | '_top';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const AsgardTemplateContext = createContext<AsgardTemplateContextValue>({
|
|
29
|
-
onErrorClick: undefined,
|
|
30
|
-
errorMessageRenderer: undefined,
|
|
31
|
-
onTemplateBtnClick: undefined,
|
|
32
|
-
defaultLinkTarget: undefined,
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
interface AsgardTemplateContextProviderProps extends PropsWithChildren {
|
|
36
|
-
onErrorClick?: (message: ConversationErrorMessage) => void;
|
|
37
|
-
errorMessageRenderer?: (message: ConversationErrorMessage) => ReactNode;
|
|
38
|
-
onTemplateBtnClick?: (
|
|
39
|
-
payload: Record<string, unknown>,
|
|
40
|
-
{
|
|
41
|
-
sse,
|
|
42
|
-
}: {
|
|
43
|
-
sse: {
|
|
44
|
-
sendMessage: (
|
|
45
|
-
payload: Pick<FetchSsePayload, 'text'> & Partial<Pick<FetchSsePayload, 'payload'>>
|
|
46
|
-
) => void;
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
) => void;
|
|
50
|
-
defaultLinkTarget?: '_blank' | '_self' | '_parent' | '_top';
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function AsgardTemplateContextProvider(
|
|
54
|
-
props: AsgardTemplateContextProviderProps
|
|
55
|
-
): ReactNode {
|
|
56
|
-
const {
|
|
57
|
-
children,
|
|
58
|
-
onErrorClick,
|
|
59
|
-
errorMessageRenderer,
|
|
60
|
-
onTemplateBtnClick,
|
|
61
|
-
defaultLinkTarget,
|
|
62
|
-
} = props;
|
|
63
|
-
|
|
64
|
-
const contextValue = useMemo(
|
|
65
|
-
() => ({
|
|
66
|
-
onErrorClick,
|
|
67
|
-
errorMessageRenderer,
|
|
68
|
-
onTemplateBtnClick,
|
|
69
|
-
defaultLinkTarget,
|
|
70
|
-
}),
|
|
71
|
-
[errorMessageRenderer, onErrorClick, onTemplateBtnClick, defaultLinkTarget]
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
return (
|
|
75
|
-
<AsgardTemplateContext.Provider value={contextValue}>
|
|
76
|
-
{children}
|
|
77
|
-
</AsgardTemplateContext.Provider>
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function useAsgardTemplateContext(): AsgardTemplateContextValue {
|
|
82
|
-
return useContext(AsgardTemplateContext);
|
|
83
|
-
}
|