@convai/web-sdk 1.9.0-beta.0 → 1.9.0-beta.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/core/AudioManager.d.ts +3 -3
- package/dist/core/AudioManager.js +1 -1
- package/dist/core/CharacterRoster.d.ts +1 -1
- package/dist/core/CharacterVersionManager.d.ts +2 -2
- package/dist/core/CharacterVersionManager.js +1 -1
- package/dist/core/ConnectionStateHandler.d.ts +1 -1
- package/dist/core/ConvaiClient.d.ts +6 -6
- package/dist/core/ConvaiClient.d.ts.map +1 -1
- package/dist/core/ConvaiClient.js +34 -28
- package/dist/core/ConvaiClient.js.map +1 -1
- package/dist/core/MemoryManager.d.ts +1 -1
- package/dist/core/MessageHandler.d.ts +7 -4
- package/dist/core/MessageHandler.d.ts.map +1 -1
- package/dist/core/MessageHandler.js +68 -43
- package/dist/core/MessageHandler.js.map +1 -1
- package/dist/core/SSESession.d.ts +7 -8
- package/dist/core/SSESession.d.ts.map +1 -1
- package/dist/core/SSESession.js +225 -11
- package/dist/core/SSESession.js.map +1 -1
- package/dist/core/ScreenShareManager.d.ts +2 -2
- package/dist/core/ScreenShareManager.js +2 -2
- package/dist/core/VideoManager.d.ts +2 -2
- package/dist/core/VideoManager.js +3 -3
- package/dist/core/connectRequest.d.ts +1 -1
- package/dist/core/contextUpdateRequest.d.ts +1 -1
- package/dist/core/index.d.ts +25 -21
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +19 -17
- package/dist/core/index.js.map +1 -1
- package/dist/core/modelOutput.d.ts +2 -2
- package/dist/core/publishedChat.d.ts +1 -1
- package/dist/core/rosterRequest.d.ts +1 -1
- package/dist/core/rosterRequest.js +1 -1
- package/dist/core/rtviEnvelope.d.ts +6 -0
- package/dist/core/rtviEnvelope.d.ts.map +1 -0
- package/dist/core/rtviEnvelope.js +10 -0
- package/dist/core/rtviEnvelope.js.map +1 -0
- package/dist/core/types.d.ts +27 -9
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/core/videoSourceState.d.ts +1 -1
- package/dist/core/visionRequest.d.ts +1 -1
- package/dist/embed/ConvaiChatElement.js +2 -2
- package/dist/embed/browser.d.ts +2 -2
- package/dist/embed/browser.js +3 -3
- package/dist/embed/chat-embed-v1.js +14 -14
- package/dist/embed/chat-embed-v1.js.map +4 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/lipsync-helpers/createBlendshapeQueue.d.ts +2 -2
- package/dist/lipsync-helpers/createBlendshapeQueue.js +2 -2
- package/dist/lipsync-helpers/declarativeMapping.d.ts +1 -1
- package/dist/lipsync-helpers/declarativeMapping.js +2 -2
- package/dist/lipsync-helpers/index.d.ts +12 -12
- package/dist/lipsync-helpers/index.js +9 -9
- package/dist/lipsync-helpers/mhaLimitDrivers.js +2 -2
- package/dist/lipsync-helpers/naturalness/processor.d.ts +1 -1
- package/dist/lipsync-helpers/naturalness/processor.js +1 -1
- package/dist/lipsync-helpers/naturalness/profiles/mha.d.ts +1 -1
- package/dist/lipsync-helpers/naturalness/profiles/mha.js +1 -1
- package/dist/lipsync-helpers/presetMappers.d.ts +1 -1
- package/dist/react/components/ConvaiWidget.d.ts +11 -2
- package/dist/react/components/ConvaiWidget.d.ts.map +1 -1
- package/dist/react/components/ConvaiWidget.js +7 -7
- package/dist/react/components/ConvaiWidget.js.map +1 -1
- package/dist/react/components/index.d.ts +1 -1
- package/dist/react/components/index.js +1 -1
- package/dist/react/components/rtc-widget/components/AudioSettingsPanel.d.ts +1 -1
- package/dist/react/components/rtc-widget/components/ConviMessage.d.ts +4 -1
- package/dist/react/components/rtc-widget/components/ConviMessage.d.ts.map +1 -1
- package/dist/react/components/rtc-widget/components/ConviMessage.js +5 -5
- package/dist/react/components/rtc-widget/components/ConviMessage.js.map +1 -1
- package/dist/react/components/rtc-widget/components/FloatingVideo.js +3 -3
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts +21 -3
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts.map +1 -1
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.js +114 -130
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.js.map +1 -1
- package/dist/react/components/rtc-widget/components/MessageBubble.js +1 -1
- package/dist/react/components/rtc-widget/components/MessageList.d.ts +5 -2
- package/dist/react/components/rtc-widget/components/MessageList.d.ts.map +1 -1
- package/dist/react/components/rtc-widget/components/MessageList.js +6 -6
- package/dist/react/components/rtc-widget/components/MessageList.js.map +1 -1
- package/dist/react/components/rtc-widget/components/SiteCard.d.ts +15 -0
- package/dist/react/components/rtc-widget/components/SiteCard.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/SiteCard.js +35 -0
- package/dist/react/components/rtc-widget/components/SiteCard.js.map +1 -0
- package/dist/react/components/rtc-widget/components/UserMessage.js +3 -3
- package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.js +4 -4
- package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.js +3 -3
- package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.js +4 -4
- package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.js +3 -3
- package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js +3 -3
- package/dist/react/components/rtc-widget/components/conviComponents/index.d.ts +5 -5
- package/dist/react/components/rtc-widget/components/conviComponents/index.js +5 -5
- package/dist/react/components/rtc-widget/components/index.d.ts +8 -8
- package/dist/react/components/rtc-widget/components/index.js +9 -9
- package/dist/react/components/rtc-widget/index.d.ts +5 -5
- package/dist/react/components/rtc-widget/index.js +3 -3
- package/dist/react/components/rtc-widget/styles/icons.d.ts +1 -1
- package/dist/react/components/rtc-widget/styles/icons.js +1 -1
- package/dist/react/components/rtc-widget/styles/index.d.ts +5 -5
- package/dist/react/components/rtc-widget/styles/index.js +4 -4
- package/dist/react/components/rtc-widget/styles/styledComponents.js +1 -1
- package/dist/react/hooks/index.d.ts +3 -3
- package/dist/react/hooks/index.js +3 -3
- package/dist/react/hooks/useCharacterInfo.js +1 -1
- package/dist/react/hooks/useConvaiClient.d.ts +1 -1
- package/dist/react/hooks/useConvaiClient.js +1 -1
- package/dist/react/index.d.ts +13 -9
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +10 -8
- package/dist/react/index.js.map +1 -1
- package/dist/utils/lightbox.d.ts +16 -0
- package/dist/utils/lightbox.d.ts.map +1 -0
- package/dist/utils/lightbox.js +95 -0
- package/dist/utils/lightbox.js.map +1 -0
- package/dist/utils/linkPresentation.d.ts +76 -0
- package/dist/utils/linkPresentation.d.ts.map +1 -0
- package/dist/utils/linkPresentation.js +415 -0
- package/dist/utils/linkPresentation.js.map +1 -0
- package/dist/utils/linkPreview.d.ts +46 -0
- package/dist/utils/linkPreview.d.ts.map +1 -0
- package/dist/utils/linkPreview.js +72 -0
- package/dist/utils/linkPreview.js.map +1 -0
- package/dist/vanilla/AudioRenderer.js +1 -1
- package/dist/vanilla/ConvaiWidget.d.ts +1 -1
- package/dist/vanilla/ConvaiWidget.d.ts.map +1 -1
- package/dist/vanilla/ConvaiWidget.js +287 -193
- package/dist/vanilla/ConvaiWidget.js.map +1 -1
- package/dist/vanilla/WebSocketSession.d.ts +1 -1
- package/dist/vanilla/WebSocketSession.js +1 -1
- package/dist/vanilla/index.d.ts +13 -9
- package/dist/vanilla/index.d.ts.map +1 -1
- package/dist/vanilla/index.js +9 -7
- package/dist/vanilla/index.js.map +1 -1
- package/dist/vanilla/styles.d.ts.map +1 -1
- package/dist/vanilla/styles.js +9 -0
- package/dist/vanilla/styles.js.map +1 -1
- package/dist/vanilla/types.d.ts +11 -2
- package/dist/vanilla/types.d.ts.map +1 -1
- package/dist/vanilla/types.js.map +1 -1
- package/dist/vanilla/websocket.d.ts +1 -1
- package/dist/vanilla/websocket.js +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { AudioSettings } from "../../../../core/types
|
|
2
|
+
import { AudioSettings } from "../../../../core/types";
|
|
3
3
|
interface AudioSettingsPanelProps {
|
|
4
4
|
currentSettings: AudioSettings;
|
|
5
5
|
onUpdateSettings: (settings: Partial<AudioSettings>) => Promise<void>;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import type { LinkPreviewResolver } from "../../../../utils/linkPreview";
|
|
1
2
|
interface ConviMessageProps {
|
|
2
3
|
message: string;
|
|
3
4
|
timestamp?: string;
|
|
4
5
|
className?: string;
|
|
5
6
|
showLogo?: boolean;
|
|
6
7
|
sender?: string;
|
|
8
|
+
/** Open Graph lookup for plain web links; see MarkdownRenderer. */
|
|
9
|
+
resolveLinkPreview?: LinkPreviewResolver;
|
|
7
10
|
}
|
|
8
|
-
export declare const ConviMessage: ({ message, timestamp, className, showLogo, sender, }: ConviMessageProps) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare const ConviMessage: ({ message, timestamp, className, showLogo, sender, resolveLinkPreview, }: ConviMessageProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
12
|
export {};
|
|
10
13
|
//# sourceMappingURL=ConviMessage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConviMessage.d.ts","sourceRoot":"","sources":["../../../../../src/react/components/rtc-widget/components/ConviMessage.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ConviMessage.d.ts","sourceRoot":"","sources":["../../../../../src/react/components/rtc-widget/components/ConviMessage.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,UAAU,iBAAiB;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,kBAAkB,CAAC,EAAE,mBAAmB,CAAC;CAC1C;AAED,eAAO,MAAM,YAAY,GAAI,0EAO1B,iBAAiB,4CAkCnB,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { aeroTheme } from "../styles
|
|
3
|
-
import { ConvaiLogo, ConviBubble, ConviMessageContainer, MessageHeader, ConviLabel, LogoWrapper, } from "../styles
|
|
4
|
-
import { MarkdownRenderer } from "./MarkdownRenderer
|
|
5
|
-
export const ConviMessage = ({ message, timestamp, className, showLogo = true, sender, }) => {
|
|
6
|
-
return (_jsxs(ConviMessageContainer, { className: className, children: [_jsxs(ConviBubble, { children: [showLogo && (_jsxs(MessageHeader, { children: [_jsx(LogoWrapper, { children: _jsx(ConvaiLogo, { size: "sm", color: "#10b981", animate: false, state: "connected" }) }), _jsx(ConviLabel, { children: sender })] })), _jsx(MarkdownRenderer, { text: message })] }), timestamp && (_jsx("span", { style: {
|
|
2
|
+
import { aeroTheme } from "../styles";
|
|
3
|
+
import { ConvaiLogo, ConviBubble, ConviMessageContainer, MessageHeader, ConviLabel, LogoWrapper, } from "../styles";
|
|
4
|
+
import { MarkdownRenderer } from "./MarkdownRenderer";
|
|
5
|
+
export const ConviMessage = ({ message, timestamp, className, showLogo = true, sender, resolveLinkPreview, }) => {
|
|
6
|
+
return (_jsxs(ConviMessageContainer, { className: className, children: [_jsxs(ConviBubble, { children: [showLogo && (_jsxs(MessageHeader, { children: [_jsx(LogoWrapper, { children: _jsx(ConvaiLogo, { size: "sm", color: "#10b981", animate: false, state: "connected" }) }), _jsx(ConviLabel, { children: sender })] })), _jsx(MarkdownRenderer, { text: message, resolveLinkPreview: resolveLinkPreview })] }), timestamp && (_jsx("span", { style: {
|
|
7
7
|
fontSize: aeroTheme.typography.sizes.caption,
|
|
8
8
|
color: aeroTheme.colors.text.secondary,
|
|
9
9
|
marginTop: 4,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConviMessage.js","sourceRoot":"","sources":["../../../../../src/react/components/rtc-widget/components/ConviMessage.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACL,UAAU,EACV,WAAW,EACX,qBAAqB,EACrB,aAAa,EACb,UAAU,EACV,WAAW,GACZ,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"ConviMessage.js","sourceRoot":"","sources":["../../../../../src/react/components/rtc-widget/components/ConviMessage.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACL,UAAU,EACV,WAAW,EACX,qBAAqB,EACrB,aAAa,EACb,UAAU,EACV,WAAW,GACZ,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAatD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAC3B,OAAO,EACP,SAAS,EACT,SAAS,EACT,QAAQ,GAAG,IAAI,EACf,MAAM,EACN,kBAAkB,GACA,EAAE,EAAE;IACtB,OAAO,CACL,MAAC,qBAAqB,IAAC,SAAS,EAAE,SAAS,aACzC,MAAC,WAAW,eACT,QAAQ,IAAI,CACX,MAAC,aAAa,eACZ,KAAC,WAAW,cACV,KAAC,UAAU,IACT,IAAI,EAAC,IAAI,EACT,KAAK,EAAC,SAAS,EACf,OAAO,EAAE,KAAK,EACd,KAAK,EAAC,WAAW,GACjB,GACU,EACd,KAAC,UAAU,cAAE,MAAM,GAAc,IACnB,CACjB,EACD,KAAC,gBAAgB,IAAC,IAAI,EAAE,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,GAAI,IAC/D,EACb,SAAS,IAAI,CACZ,eACE,KAAK,EAAE;oBACL,QAAQ,EAAE,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO;oBAC5C,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS;oBACtC,SAAS,EAAE,CAAC;oBACZ,SAAS,EAAE,YAAY;oBACvB,UAAU,EAAE,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI;iBACjD,YAEA,SAAS,GACL,CACR,IACqB,CACzB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React from \"react\";\nimport { aeroTheme } from \"../styles\";\nimport {\n ConvaiLogo,\n ConviBubble,\n ConviMessageContainer,\n MessageHeader,\n ConviLabel,\n LogoWrapper,\n} from \"../styles\";\nimport { MarkdownRenderer } from \"./MarkdownRenderer\";\nimport type { LinkPreviewResolver } from \"../../../../utils/linkPreview\";\n\ninterface ConviMessageProps {\n message: string;\n timestamp?: string;\n className?: string;\n showLogo?: boolean;\n sender?: string;\n /** Open Graph lookup for plain web links; see MarkdownRenderer. */\n resolveLinkPreview?: LinkPreviewResolver;\n}\n\nexport const ConviMessage = ({\n message,\n timestamp,\n className,\n showLogo = true,\n sender,\n resolveLinkPreview,\n}: ConviMessageProps) => {\n return (\n <ConviMessageContainer className={className}>\n <ConviBubble>\n {showLogo && (\n <MessageHeader>\n <LogoWrapper>\n <ConvaiLogo\n size=\"sm\"\n color=\"#10b981\"\n animate={false}\n state=\"connected\"\n />\n </LogoWrapper>\n <ConviLabel>{sender}</ConviLabel>\n </MessageHeader>\n )}\n <MarkdownRenderer text={message} resolveLinkPreview={resolveLinkPreview} />\n </ConviBubble>\n {timestamp && (\n <span\n style={{\n fontSize: aeroTheme.typography.sizes.caption,\n color: aeroTheme.colors.text.secondary,\n marginTop: 4,\n alignSelf: \"flex-start\",\n fontFamily: aeroTheme.typography.fontFamily.body,\n }}\n >\n {timestamp}\n </span>\n )}\n </ConviMessageContainer>\n );\n};\n\n"]}
|
|
@@ -4,9 +4,9 @@ import { motion } from "framer-motion";
|
|
|
4
4
|
import { VideoTrack, RoomContext, useRoomContext } from "@livekit/components-react";
|
|
5
5
|
import { IoClose, IoVideocamOff } from "react-icons/io5";
|
|
6
6
|
import { MdDragIndicator } from "react-icons/md";
|
|
7
|
-
import { aeroTheme } from "../styles/theme
|
|
8
|
-
import { iosTransitions } from "../styles/framerConfig
|
|
9
|
-
import { useLocalCameraTrack } from "../../../hooks/useLocalCameraTrack
|
|
7
|
+
import { aeroTheme } from "../styles/theme";
|
|
8
|
+
import { iosTransitions } from "../styles/framerConfig";
|
|
9
|
+
import { useLocalCameraTrack } from "../../../hooks/useLocalCameraTrack";
|
|
10
10
|
/**
|
|
11
11
|
* LocalVideoDisplay component for rendering local camera feed inside FloatingVideo.
|
|
12
12
|
*/
|
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import type { LinkPreviewResolver } from "../../../../utils/linkPreview";
|
|
3
|
+
/**
|
|
4
|
+
* The widget's bubble renderer. Everything visual comes from
|
|
5
|
+
* utils/linkPresentation so this file and the vanilla widget cannot drift;
|
|
6
|
+
* this file only maps tokenizer nodes onto JSX.
|
|
7
|
+
*
|
|
8
|
+
* `data-convai-part` mirrors the vanilla widget's `part` names. React renders
|
|
9
|
+
* in light DOM where `part` means nothing, but the same names let tests and
|
|
10
|
+
* host CSS target both renderers with one vocabulary.
|
|
11
|
+
*/
|
|
2
12
|
interface MarkdownRendererProps {
|
|
3
13
|
text: string;
|
|
4
14
|
/**
|
|
5
|
-
* Render
|
|
6
|
-
*
|
|
7
|
-
*
|
|
15
|
+
* Render cards and chips under links. Bot messages want them; the user's
|
|
16
|
+
* own bubble does not — you already know what you typed, and a preview
|
|
17
|
+
* there would let a URL a user pasted embed remote media into the
|
|
8
18
|
* transcript. Links stay clickable either way.
|
|
9
19
|
*/
|
|
10
20
|
media?: boolean;
|
|
21
|
+
/** Test seam for mixed-content detection. Defaults to the page's protocol. */
|
|
22
|
+
pageProtocol?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Host-supplied Open Graph lookup. With it, a plain web link in a bot
|
|
25
|
+
* bubble gets a site card once the lookup settles; without it, nothing
|
|
26
|
+
* changes. See docs/convai_link_previews.md, "Site cards".
|
|
27
|
+
*/
|
|
28
|
+
resolveLinkPreview?: LinkPreviewResolver;
|
|
11
29
|
}
|
|
12
30
|
export declare const MarkdownRenderer: React.FC<MarkdownRendererProps>;
|
|
13
31
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownRenderer.d.ts","sourceRoot":"","sources":["../../../../../src/react/components/rtc-widget/components/MarkdownRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"MarkdownRenderer.d.ts","sourceRoot":"","sources":["../../../../../src/react/components/rtc-widget/components/MarkdownRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAmB1B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAIzE;;;;;;;;GAQG;AACH,UAAU,qBAAqB;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,mBAAmB,CAAC;CAC1C;AAkSD,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAoC5D,CAAC"}
|
|
@@ -1,157 +1,141 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import { parseInlineMarkdown, compactUrl
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
style.textContent = `
|
|
19
|
-
@keyframes ${SHIMMER} { from { background-position: 200% 0 } to { background-position: -200% 0 } }
|
|
20
|
-
@media (prefers-reduced-motion: reduce) {
|
|
21
|
-
[data-convai-skeleton] { animation: none !important }
|
|
22
|
-
}`;
|
|
23
|
-
document.head.appendChild(style);
|
|
24
|
-
}
|
|
25
|
-
const linkStyle = {
|
|
26
|
-
color: "#10b981",
|
|
27
|
-
textDecoration: "underline",
|
|
28
|
-
wordBreak: "break-all",
|
|
29
|
-
};
|
|
30
|
-
const mediaStyle = {
|
|
31
|
-
display: "block",
|
|
32
|
-
width: "100%",
|
|
33
|
-
height: "100%",
|
|
34
|
-
objectFit: "cover",
|
|
35
|
-
borderRadius: MEDIA_RADIUS,
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* A preview card sizes itself before the media arrives, so the bubble does not
|
|
39
|
-
* jump when an image decodes. 16/10 is a compromise: tall enough to read, short
|
|
40
|
-
* enough that several in a row still scroll.
|
|
41
|
-
*/
|
|
42
|
-
const CARD_ASPECT = "16 / 10";
|
|
43
|
-
const cardStyle = {
|
|
44
|
-
// A span by default is inline, where aspect-ratio does nothing.
|
|
45
|
-
display: "block",
|
|
46
|
-
position: "relative",
|
|
47
|
-
marginTop: 6,
|
|
48
|
-
maxWidth: 320,
|
|
49
|
-
aspectRatio: CARD_ASPECT,
|
|
50
|
-
borderRadius: MEDIA_RADIUS,
|
|
51
|
-
overflow: "hidden",
|
|
52
|
-
// The widget is embedded in someone else's page on an unknown background, so
|
|
53
|
-
// chrome is derived from the inherited text colour rather than a fixed grey.
|
|
54
|
-
background: "color-mix(in srgb, currentColor 6%, transparent)",
|
|
55
|
-
boxShadow: "inset 0 0 0 1px color-mix(in srgb, currentColor 10%, transparent)",
|
|
56
|
-
};
|
|
57
|
-
const skeletonStyle = {
|
|
58
|
-
position: "absolute",
|
|
59
|
-
inset: 0,
|
|
60
|
-
borderRadius: MEDIA_RADIUS,
|
|
61
|
-
background: "color-mix(in srgb, currentColor 8%, transparent)",
|
|
62
|
-
backgroundImage: "linear-gradient(90deg, transparent, color-mix(in srgb, currentColor 12%, transparent), transparent)",
|
|
63
|
-
backgroundSize: "200% 100%",
|
|
64
|
-
animation: `${SHIMMER} 1.4s ease-in-out infinite`,
|
|
65
|
-
};
|
|
66
|
-
const captionStyle = {
|
|
67
|
-
display: "block",
|
|
68
|
-
marginTop: 4,
|
|
69
|
-
fontSize: 11,
|
|
70
|
-
opacity: 0.7,
|
|
71
|
-
whiteSpace: "nowrap",
|
|
72
|
-
overflow: "hidden",
|
|
73
|
-
textOverflow: "ellipsis",
|
|
3
|
+
import { parseInlineMarkdown, compactUrl } from "../../../../utils/inlineMarkdown";
|
|
4
|
+
import { linkKindForUrl, describeUrl, fileNameOf, documentBadge, contactLabel, hoverTitle, isMixedContent, glyph, presentationStyles as S, PREVIEW_TIMEOUT_MS, MAX_CARDS_PER_MESSAGE, } from "../../../../utils/linkPresentation";
|
|
5
|
+
import { openLightbox } from "../../../../utils/lightbox";
|
|
6
|
+
import { SiteCard } from "./SiteCard";
|
|
7
|
+
import { injectKeyframes } from "../../../../vanilla/styles";
|
|
8
|
+
const css = (...objs) => Object.assign({}, ...objs);
|
|
9
|
+
const Glyph = ({ name, style }) => (_jsx("span", { style: css(S.contactGlyph, style ?? {}), dangerouslySetInnerHTML: { __html: glyph(name) } }));
|
|
10
|
+
/** Inline styles cannot express :focus-visible, so the ring is toggled by hand. */
|
|
11
|
+
const useFocusRing = () => {
|
|
12
|
+
const [focused, setFocused] = React.useState(false);
|
|
13
|
+
return {
|
|
14
|
+
style: focused ? S.linkFocus : {},
|
|
15
|
+
onFocus: (e) => setFocused(e.target.matches(":focus-visible")),
|
|
16
|
+
onBlur: () => setFocused(false),
|
|
17
|
+
};
|
|
74
18
|
};
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
19
|
+
const Anchor = ({ href, kind, label }) => {
|
|
20
|
+
const ring = useFocusRing();
|
|
21
|
+
// A bare URL is its own label and may be elided for display; the title
|
|
22
|
+
// compares against what is actually shown so the full target is one hover away.
|
|
23
|
+
const display = label === href ? compactUrl(label) : label;
|
|
24
|
+
return (_jsxs("a", { href: href, target: "_blank", rel: "noopener noreferrer", title: hoverTitle(kind, href, display), "data-convai-part": "message-link", style: css(S.link, ring.style), onFocus: ring.onFocus, onBlur: ring.onBlur, children: [display, kind === "ftp" && (_jsx("span", { "data-convai-part": "message-link-badge", style: css(S.badge), children: "FTP" }))] }));
|
|
80
25
|
};
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
textDecoration: "underline",
|
|
85
|
-
textDecorationStyle: "dotted",
|
|
86
|
-
cursor: "help",
|
|
26
|
+
const ContactChip = ({ href, kind }) => {
|
|
27
|
+
const ring = useFocusRing();
|
|
28
|
+
return (_jsxs("a", { href: href, title: hoverTitle(kind, href, href), "data-convai-part": "message-contact", style: css(S.contact, ring.style), onFocus: ring.onFocus, onBlur: ring.onBlur, children: [_jsx(Glyph, { name: kind }), _jsx("span", { children: contactLabel(href) })] }));
|
|
87
29
|
};
|
|
88
|
-
|
|
89
|
-
|
|
30
|
+
const DocumentCard = ({ href }) => {
|
|
31
|
+
const ring = useFocusRing();
|
|
32
|
+
let host = "";
|
|
90
33
|
try {
|
|
91
|
-
|
|
92
|
-
const file = pathname.split("/").filter(Boolean).pop();
|
|
93
|
-
return file ? `${host} · ${file}` : host;
|
|
34
|
+
host = new URL(href).host;
|
|
94
35
|
}
|
|
95
36
|
catch {
|
|
96
|
-
|
|
37
|
+
/* keep empty */
|
|
97
38
|
}
|
|
98
|
-
}
|
|
39
|
+
return (_jsxs("a", { href: href, target: "_blank", rel: "noopener noreferrer", title: href, "data-convai-part": "message-file-card", style: css(S.fileCard, ring.style), onFocus: ring.onFocus, onBlur: ring.onBlur, children: [_jsx("span", { "data-convai-part": "message-file-icon", style: css(S.fileIcon), children: documentBadge(href) }), _jsxs("span", { style: css(S.fileBody), children: [_jsx("span", { "data-convai-part": "message-file-name", style: css(S.fileName), children: fileNameOf(href) }), _jsxs("span", { "data-convai-part": "message-file-meta", style: css(S.fileMeta), children: [host, " \u00B7 Opens in a new tab"] })] })] }));
|
|
40
|
+
};
|
|
99
41
|
/**
|
|
100
|
-
* Inline preview for an image or video URL
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* resolve — which a character can easily invent — collapses to one muted line
|
|
105
|
-
* instead of leaving an empty player in the transcript.
|
|
42
|
+
* Inline preview for an image or video URL. The element is in the tree from
|
|
43
|
+
* the start so the fetch begins immediately; a skeleton covers it until it
|
|
44
|
+
* decodes. Error, timeout, or an insecure URL collapse it to one muted line
|
|
45
|
+
* so a URL the character invented never leaves an empty player behind.
|
|
106
46
|
*/
|
|
107
|
-
const MediaPreview = ({ src, alt, kind }) => {
|
|
108
|
-
const
|
|
109
|
-
React.
|
|
47
|
+
const MediaPreview = ({ src, alt, kind, pageProtocol, }) => {
|
|
48
|
+
const insecure = isMixedContent(src, pageProtocol);
|
|
49
|
+
const [state, setState] = React.useState(insecure ? "error" : "loading");
|
|
50
|
+
const cardRef = React.useRef(null);
|
|
51
|
+
React.useEffect(() => {
|
|
52
|
+
injectKeyframes(document);
|
|
53
|
+
}, []);
|
|
54
|
+
React.useEffect(() => {
|
|
55
|
+
if (state !== "loading")
|
|
56
|
+
return;
|
|
57
|
+
const t = setTimeout(() => setState((s) => (s === "loading" ? "error" : s)), PREVIEW_TIMEOUT_MS);
|
|
58
|
+
return () => clearTimeout(t);
|
|
59
|
+
}, [state]);
|
|
110
60
|
if (state === "error") {
|
|
111
|
-
return _jsxs("span", { style:
|
|
61
|
+
return (_jsxs("span", { "data-convai-part": "message-media-unavailable", style: css(S.unavailable), children: ["Preview unavailable \u2014 ", describeUrl(src), insecure ? " (insecure URL)" : ""] }));
|
|
112
62
|
}
|
|
113
63
|
const ready = state === "ready";
|
|
114
|
-
|
|
64
|
+
const open = () => openLightbox({
|
|
65
|
+
src,
|
|
66
|
+
alt,
|
|
67
|
+
caption: describeUrl(src),
|
|
68
|
+
href: src,
|
|
69
|
+
root: document,
|
|
70
|
+
returnFocusTo: cardRef.current,
|
|
71
|
+
});
|
|
72
|
+
const buttonProps = kind === "image"
|
|
73
|
+
? {
|
|
74
|
+
role: "button",
|
|
75
|
+
tabIndex: 0,
|
|
76
|
+
"aria-label": `Open image: ${fileNameOf(src)}`,
|
|
77
|
+
onClick: open,
|
|
78
|
+
onKeyDown: (e) => {
|
|
79
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
open();
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
}
|
|
85
|
+
: {};
|
|
86
|
+
return (_jsxs(_Fragment, { children: [_jsxs("span", { ref: cardRef, "data-convai-part": "message-media-card", style: css(S.card, kind === "image" ? S.cardButton : {}), ...buttonProps, children: [kind === "image" ? (_jsx("img", { src: src, alt: alt, loading: "lazy", "data-convai-part": "message-media", onLoad: () => setState("ready"), onError: () => setState("error"), style: css(S.media, { opacity: ready ? 1 : 0 }) })) : (_jsx("video", { src: src, controls: true, preload: "metadata", "data-convai-part": "message-media", onLoadedMetadata: () => setState("ready"), onError: () => setState("error"), style: css(S.media, S.videoMedia, { opacity: ready ? 1 : 0 }) })), !ready && (_jsx("span", { "data-convai-skeleton": "", "data-convai-part": "message-media-skeleton", style: css(S.skeleton), "aria-hidden": "true" })), kind === "image" && (_jsx("span", { "data-convai-part": "message-media-zoom", style: css(S.zoom), children: _jsx(Glyph, { name: "zoom", style: { fontSize: 14 } }) }))] }), _jsx("span", { "data-convai-part": "message-media-caption", style: css(S.caption), children: describeUrl(src) })] }));
|
|
115
87
|
};
|
|
116
|
-
const renderNode = (node, key, media) => {
|
|
88
|
+
const renderNode = (node, key, media, budget, pageProtocol, resolveLinkPreview) => {
|
|
117
89
|
switch (node.kind) {
|
|
118
90
|
case "strong":
|
|
119
91
|
return _jsx("strong", { children: node.text }, key);
|
|
120
92
|
case "em":
|
|
121
93
|
return _jsx("em", { children: node.text }, key);
|
|
122
|
-
case "link":
|
|
123
|
-
return (_jsxs(React.Fragment, { children: [_jsx("a", { href: node.href, target: "_blank", rel: "noopener noreferrer", style: linkStyle, children: node.label === node.href ? compactUrl(node.label) : node.label }), media && node.media && (_jsx(MediaPreview, { src: node.href, alt: node.label, kind: node.media }))] }, key));
|
|
124
94
|
case "blocked":
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
95
|
+
// Not an anchor, ever. The label reads as the character wrote it; the
|
|
96
|
+
// target is only revealed on hover.
|
|
97
|
+
return (_jsx("span", { "data-convai-part": "message-link-blocked", style: css(S.blocked), title: `Link blocked: ${node.href}`, children: node.label }, key));
|
|
98
|
+
case "image": {
|
|
99
|
+
if (media && budget.cards < MAX_CARDS_PER_MESSAGE) {
|
|
100
|
+
budget.cards++;
|
|
101
|
+
return (_jsx(MediaPreview, { src: node.src, alt: node.alt, kind: "image", pageProtocol: pageProtocol }, key));
|
|
102
|
+
}
|
|
103
|
+
// With previews off (or the budget spent), an image still has to say
|
|
104
|
+
// what it pointed at, so it degrades to the same anchor a link renders.
|
|
105
|
+
return _jsx(Anchor, { href: node.src, kind: "image", label: node.alt || node.src }, key);
|
|
106
|
+
}
|
|
107
|
+
case "link": {
|
|
108
|
+
const kind = linkKindForUrl(node.href);
|
|
109
|
+
if (kind === "email" || kind === "phone" || kind === "sms") {
|
|
110
|
+
return media ? (_jsx(ContactChip, { href: node.href, kind: kind }, key)) : (_jsx(Anchor, { href: node.href, kind: kind, label: node.label }, key));
|
|
111
|
+
}
|
|
112
|
+
const wantsCard = media &&
|
|
113
|
+
(kind === "image" || kind === "video" || kind === "document") &&
|
|
114
|
+
budget.cards < MAX_CARDS_PER_MESSAGE;
|
|
115
|
+
// The budget is spent when the card mounts, not when it resolves, so the
|
|
116
|
+
// cap stays deterministic for a message naming twenty pages.
|
|
117
|
+
const wantsSiteCard = media && kind === "web" && !!resolveLinkPreview && budget.cards < MAX_CARDS_PER_MESSAGE;
|
|
118
|
+
if (wantsCard || wantsSiteCard)
|
|
119
|
+
budget.cards++;
|
|
120
|
+
return (_jsxs(React.Fragment, { children: [_jsx(Anchor, { href: node.href, kind: kind, label: node.label }), wantsCard && kind === "document" && _jsx(DocumentCard, { href: node.href }), wantsCard && kind !== "document" && (_jsx(MediaPreview, { src: node.href, alt: node.label, kind: kind, pageProtocol: pageProtocol })), wantsSiteCard && _jsx(SiteCard, { href: node.href, resolver: resolveLinkPreview })] }, key));
|
|
121
|
+
}
|
|
130
122
|
default:
|
|
131
123
|
return _jsx(React.Fragment, { children: node.text }, key);
|
|
132
124
|
}
|
|
133
125
|
};
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return lines.map((line, lineIndex) => {
|
|
145
|
-
// Bold, italic, links, images and bare URLs — see utils/inlineMarkdown.
|
|
146
|
-
const processedLine = parseInlineMarkdown(line).map((node, i) => renderNode(node, `${node.kind}-${lineIndex}-${i}`, media));
|
|
147
|
-
// Handle empty lines (creates paragraph spacing)
|
|
148
|
-
if (line.trim() === "" && lineIndex > 0) {
|
|
126
|
+
const wrapperStyle = { whiteSpace: "pre-wrap", wordWrap: "break-word" };
|
|
127
|
+
export const MarkdownRenderer = ({ text, media = true, pageProtocol, resolveLinkPreview, }) => {
|
|
128
|
+
if (!text)
|
|
129
|
+
return _jsx("div", { style: wrapperStyle });
|
|
130
|
+
// Handle both actual newlines and literal "\n" sequences.
|
|
131
|
+
const lines = text.replace(/\\n/g, "\n").split("\n");
|
|
132
|
+
const budget = { cards: 0 };
|
|
133
|
+
return (_jsx("div", { style: wrapperStyle, children: lines.map((line, lineIndex) => {
|
|
134
|
+
// An empty line is paragraph spacing.
|
|
135
|
+
if (line.trim() === "" && lineIndex > 0)
|
|
149
136
|
return _jsx("br", {}, `br-${lineIndex}`);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
});
|
|
154
|
-
};
|
|
155
|
-
return _jsx("div", { style: { whiteSpace: 'pre-wrap', wordWrap: 'break-word' }, children: renderMarkdown(text) });
|
|
137
|
+
const nodes = parseInlineMarkdown(line).map((node, i) => renderNode(node, `${node.kind}-${lineIndex}-${i}`, media, budget, pageProtocol, resolveLinkPreview));
|
|
138
|
+
return (_jsxs(React.Fragment, { children: [nodes.length > 0 ? nodes : line, lineIndex < lines.length - 1 && _jsx("br", {})] }, `line-${lineIndex}`));
|
|
139
|
+
}) }));
|
|
156
140
|
};
|
|
157
141
|
//# sourceMappingURL=MarkdownRenderer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownRenderer.js","sourceRoot":"","sources":["../../../../../src/react/components/rtc-widget/components/MarkdownRenderer.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,mBAAmB,EACnB,UAAU,GAGX,MAAM,kCAAkC,CAAC;AAE1C,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,OAAO,GAAG,wBAAwB,CAAC;AAEzC;;;;GAIG;AACH,SAAS,sBAAsB;IAC7B,IAAI,OAAO,QAAQ,KAAK,WAAW;QAAE,OAAO;IAC5C,IAAI,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC;QAAE,OAAO;IAC7C,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAC9C,KAAK,CAAC,EAAE,GAAG,OAAO,CAAC;IACnB,KAAK,CAAC,WAAW,GAAG;aACT,OAAO;;;EAGlB,CAAC;IACD,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;AACn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KAAK;YAAE,OAAO,IAAI,CAAC;QAExB,sDAAsD;QACtD,kDAAkD;QAClD,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAEnD,2BAA2B;QAC3B,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEzC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE;YACnC,wEAAwE;YACxE,MAAM,aAAa,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAC9D,UAAU,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,IAAI,IAAI,SAAS,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,CAC1D,CAAC;YAEF,iDAAiD;YACjD,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;gBACxC,OAAO,eAAS,MAAM,SAAS,EAAE,CAAI,CAAC;YACxC,CAAC;YAED,kCAAkC;YAClC,OAAO,CACL,MAAC,KAAK,CAAC,QAAQ,eACZ,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,EAC/C,SAAS,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,cAAM,KAFpB,QAAQ,SAAS,EAAE,CAGvB,CAClB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,OAAO,cAAK,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,YAAG,cAAc,CAAC,IAAI,CAAC,GAAO,CAAC;AACtG,CAAC,CAAC","sourcesContent":["import React from \"react\";\nimport {\n parseInlineMarkdown,\n compactUrl,\n type InlineNode,\n type MediaKind,\n} from \"../../../../utils/inlineMarkdown\";\n\nconst MEDIA_RADIUS = 8;\nconst SHIMMER = \"convai-preview-shimmer\";\n\n/**\n * The renderer styles inline, but a keyframe cannot be expressed that way, so\n * the one animation it needs is injected once per document. Guarded for SSR and\n * for the tests, which render to a string with no document.\n */\nfunction ensureShimmerKeyframes(): void {\n if (typeof document === \"undefined\") return;\n if (document.getElementById(SHIMMER)) return;\n const style = document.createElement(\"style\");\n style.id = SHIMMER;\n style.textContent = `\n@keyframes ${SHIMMER} { from { background-position: 200% 0 } to { background-position: -200% 0 } }\n@media (prefers-reduced-motion: reduce) {\n [data-convai-skeleton] { animation: none !important }\n}`;\n document.head.appendChild(style);\n}\n\ninterface MarkdownRendererProps {\n text: string;\n /**\n * Render inline image/video previews under a media link. Bot messages want\n * them; the user's own bubble does not — you already know what you typed, and\n * a preview there would let a URL a user pasted embed remote media into the\n * transcript. Links stay clickable either way.\n */\n media?: boolean;\n}\n\nconst linkStyle: React.CSSProperties = {\n color: \"#10b981\",\n textDecoration: \"underline\",\n wordBreak: \"break-all\",\n};\n\nconst mediaStyle: React.CSSProperties = {\n display: \"block\",\n width: \"100%\",\n height: \"100%\",\n objectFit: \"cover\",\n borderRadius: MEDIA_RADIUS,\n};\n\n/**\n * A preview card sizes itself before the media arrives, so the bubble does not\n * jump when an image decodes. 16/10 is a compromise: tall enough to read, short\n * enough that several in a row still scroll.\n */\nconst CARD_ASPECT = \"16 / 10\";\n\nconst cardStyle: React.CSSProperties = {\n // A span by default is inline, where aspect-ratio does nothing.\n display: \"block\",\n position: \"relative\",\n marginTop: 6,\n maxWidth: 320,\n aspectRatio: CARD_ASPECT,\n borderRadius: MEDIA_RADIUS,\n overflow: \"hidden\",\n // The widget is embedded in someone else's page on an unknown background, so\n // chrome is derived from the inherited text colour rather than a fixed grey.\n background: \"color-mix(in srgb, currentColor 6%, transparent)\",\n boxShadow: \"inset 0 0 0 1px color-mix(in srgb, currentColor 10%, transparent)\",\n};\n\nconst skeletonStyle: React.CSSProperties = {\n position: \"absolute\",\n inset: 0,\n borderRadius: MEDIA_RADIUS,\n background: \"color-mix(in srgb, currentColor 8%, transparent)\",\n backgroundImage:\n \"linear-gradient(90deg, transparent, color-mix(in srgb, currentColor 12%, transparent), transparent)\",\n backgroundSize: \"200% 100%\",\n animation: `${SHIMMER} 1.4s ease-in-out infinite`,\n};\n\nconst captionStyle: React.CSSProperties = {\n display: \"block\",\n marginTop: 4,\n fontSize: 11,\n opacity: 0.7,\n whiteSpace: \"nowrap\",\n overflow: \"hidden\",\n textOverflow: \"ellipsis\",\n};\n\nconst unavailableStyle: React.CSSProperties = {\n ...captionStyle,\n marginTop: 6,\n opacity: 0.55,\n fontStyle: \"italic\",\n};\n\n/** An unsafe target: the words the character wrote, with no href behind them. */\nconst blockedStyle: React.CSSProperties = {\n opacity: 0.75,\n textDecoration: \"underline\",\n textDecorationStyle: \"dotted\",\n cursor: \"help\",\n};\n\n/** `cdn.example.com/a/b/c.png` → `cdn.example.com · c.png` */\nfunction describeUrl(url: string): string {\n try {\n const { host, pathname } = new URL(url);\n const file = pathname.split(\"/\").filter(Boolean).pop();\n return file ? `${host} · ${file}` : host;\n } catch {\n return compactUrl(url);\n }\n}\n\ntype LoadState = \"loading\" | \"ready\" | \"error\";\n\n/**\n * Inline preview for an image or video URL, shown under its link.\n *\n * The media element is always in the tree so the browser starts fetching it\n * immediately; the skeleton sits on top until it decodes. A URL that does not\n * resolve — which a character can easily invent — collapses to one muted line\n * instead of leaving an empty player in the transcript.\n */\nconst MediaPreview = ({ src, alt, kind }: { src: string; alt: string; kind: MediaKind }) => {\n const [state, setState] = React.useState<LoadState>(\"loading\");\n React.useEffect(ensureShimmerKeyframes, []);\n\n if (state === \"error\") {\n return <span style={unavailableStyle}>Preview unavailable — {describeUrl(src)}</span>;\n }\n\n const ready = state === \"ready\";\n return (\n <>\n <span style={cardStyle}>\n {kind === \"image\" ? (\n <img\n src={src}\n alt={alt}\n loading=\"lazy\"\n onLoad={() => setState(\"ready\")}\n onError={() => setState(\"error\")}\n style={{ ...mediaStyle, opacity: ready ? 1 : 0 }}\n />\n ) : (\n <video\n src={src}\n controls\n preload=\"metadata\"\n onLoadedMetadata={() => setState(\"ready\")}\n onError={() => setState(\"error\")}\n style={{ ...mediaStyle, objectFit: \"contain\", opacity: ready ? 1 : 0 }}\n />\n )}\n {!ready && <span data-convai-skeleton=\"\" style={skeletonStyle} aria-hidden=\"true\" />}\n </span>\n <span style={captionStyle}>{describeUrl(src)}</span>\n </>\n );\n};\n\nconst renderNode = (node: InlineNode, key: string, media: boolean): React.ReactNode => {\n switch (node.kind) {\n case \"strong\":\n return <strong key={key}>{node.text}</strong>;\n case \"em\":\n return <em key={key}>{node.text}</em>;\n case \"link\":\n return (\n <React.Fragment key={key}>\n <a href={node.href} target=\"_blank\" rel=\"noopener noreferrer\" style={linkStyle}>\n {node.label === node.href ? compactUrl(node.label) : node.label}\n </a>\n {media && node.media && (\n <MediaPreview src={node.href} alt={node.label} kind={node.media} />\n )}\n </React.Fragment>\n );\n case \"blocked\":\n return (\n <span key={key} style={blockedStyle} title={`Link blocked: ${node.href}`}>\n {node.label}\n </span>\n );\n case \"image\":\n // With previews off, an image still has to say what it pointed at, so it\n // degrades to the same anchor a plain link would render.\n return media ? (\n <MediaPreview key={key} src={node.src} alt={node.alt} kind=\"image\" />\n ) : (\n <a key={key} href={node.src} target=\"_blank\" rel=\"noopener noreferrer\" style={linkStyle}>\n {node.alt || node.src}\n </a>\n );\n default:\n return <React.Fragment key={key}>{node.text}</React.Fragment>;\n }\n};\n\nexport const MarkdownRenderer: React.FC<MarkdownRendererProps> = ({ text, media = true }) => {\n // Convert markdown to JSX elements\n const renderMarkdown = (input: string): React.ReactNode => {\n if (!input) return null;\n\n // Handle both actual newlines and \\n escape sequences\n // Replace literal \\n strings with actual newlines\n const normalizedText = input.replace(/\\\\n/g, '\\n');\n\n // Split by actual newlines\n const lines = normalizedText.split('\\n');\n\n return lines.map((line, lineIndex) => {\n // Bold, italic, links, images and bare URLs — see utils/inlineMarkdown.\n const processedLine = parseInlineMarkdown(line).map((node, i) =>\n renderNode(node, `${node.kind}-${lineIndex}-${i}`, media),\n );\n\n // Handle empty lines (creates paragraph spacing)\n if (line.trim() === \"\" && lineIndex > 0) {\n return <br key={`br-${lineIndex}`} />;\n }\n\n // Return the line with line break\n return (\n <React.Fragment key={`line-${lineIndex}`}>\n {processedLine.length > 0 ? processedLine : line}\n {lineIndex < lines.length - 1 && <br />}\n </React.Fragment>\n );\n });\n };\n\n return <div style={{ whiteSpace: 'pre-wrap', wordWrap: 'break-word' }}>{renderMarkdown(text)}</div>;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"MarkdownRenderer.js","sourceRoot":"","sources":["../../../../../src/react/components/rtc-widget/components/MarkdownRenderer.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAmB,MAAM,kCAAkC,CAAC;AACpG,OAAO,EACL,cAAc,EACd,WAAW,EACX,UAAU,EACV,aAAa,EACb,YAAY,EACZ,UAAU,EACV,cAAc,EACd,KAAK,EACL,kBAAkB,IAAI,CAAC,EACvB,kBAAkB,EAClB,qBAAqB,GAItB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AA8B7D,MAAM,GAAG,GAAG,CAAC,GAAG,IAAmB,EAAuB,EAAE,CAC1D,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,IAAI,CAAwB,CAAC;AAEpD,MAAM,KAAK,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,EAA4C,EAAE,EAAE,CAAC,CAC3E,eAAM,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,YAAY,EAAE,KAAK,IAAI,EAAE,CAAC,EAAE,uBAAuB,EAAE,EAAE,M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AK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAC/B,SAAS,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,cAAM,KAFpB,QAAQ,SAAS,EAAE,CAGvB,CAClB,CAAC;QACJ,CAAC,CAAC,GACE,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React from \"react\";\nimport { parseInlineMarkdown, compactUrl, type InlineNode } from \"../../../../utils/inlineMarkdown\";\nimport {\n linkKindForUrl,\n describeUrl,\n fileNameOf,\n documentBadge,\n contactLabel,\n hoverTitle,\n isMixedContent,\n glyph,\n presentationStyles as S,\n PREVIEW_TIMEOUT_MS,\n MAX_CARDS_PER_MESSAGE,\n type GlyphName,\n type LinkKind,\n type StyleObject,\n} from \"../../../../utils/linkPresentation\";\nimport { openLightbox } from \"../../../../utils/lightbox\";\nimport type { LinkPreviewResolver } from \"../../../../utils/linkPreview\";\nimport { SiteCard } from \"./SiteCard\";\nimport { injectKeyframes } from \"../../../../vanilla/styles\";\n\n/**\n * The widget's bubble renderer. Everything visual comes from\n * utils/linkPresentation so this file and the vanilla widget cannot drift;\n * this file only maps tokenizer nodes onto JSX.\n *\n * `data-convai-part` mirrors the vanilla widget's `part` names. React renders\n * in light DOM where `part` means nothing, but the same names let tests and\n * host CSS target both renderers with one vocabulary.\n */\ninterface MarkdownRendererProps {\n text: string;\n /**\n * Render cards and chips under links. Bot messages want them; the user's\n * own bubble does not — you already know what you typed, and a preview\n * there would let a URL a user pasted embed remote media into the\n * transcript. Links stay clickable either way.\n */\n media?: boolean;\n /** Test seam for mixed-content detection. Defaults to the page's protocol. */\n pageProtocol?: string;\n /**\n * Host-supplied Open Graph lookup. With it, a plain web link in a bot\n * bubble gets a site card once the lookup settles; without it, nothing\n * changes. See docs/convai_link_previews.md, \"Site cards\".\n */\n resolveLinkPreview?: LinkPreviewResolver;\n}\n\nconst css = (...objs: StyleObject[]): React.CSSProperties =>\n Object.assign({}, ...objs) as React.CSSProperties;\n\nconst Glyph = ({ name, style }: { name: GlyphName; style?: StyleObject }) => (\n <span style={css(S.contactGlyph, style ?? {})} dangerouslySetInnerHTML={{ __html: glyph(name) }} />\n);\n\n/** Inline styles cannot express :focus-visible, so the ring is toggled by hand. */\nconst useFocusRing = () => {\n const [focused, setFocused] = React.useState(false);\n return {\n style: focused ? S.linkFocus : {},\n onFocus: (e: React.FocusEvent<HTMLElement>) => setFocused(e.target.matches(\":focus-visible\")),\n onBlur: () => setFocused(false),\n };\n};\n\nconst Anchor = ({ href, kind, label }: { href: string; kind: LinkKind; label: string }) => {\n const ring = useFocusRing();\n // A bare URL is its own label and may be elided for display; the title\n // compares against what is actually shown so the full target is one hover away.\n const display = label === href ? compactUrl(label) : label;\n return (\n <a\n href={href}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n title={hoverTitle(kind, href, display)}\n data-convai-part=\"message-link\"\n style={css(S.link, ring.style)}\n onFocus={ring.onFocus}\n onBlur={ring.onBlur}\n >\n {display}\n {kind === \"ftp\" && (\n <span data-convai-part=\"message-link-badge\" style={css(S.badge)}>\n FTP\n </span>\n )}\n </a>\n );\n};\n\nconst ContactChip = ({ href, kind }: { href: string; kind: \"email\" | \"phone\" | \"sms\" }) => {\n const ring = useFocusRing();\n return (\n <a\n href={href}\n title={hoverTitle(kind, href, href)}\n data-convai-part=\"message-contact\"\n style={css(S.contact, ring.style)}\n onFocus={ring.onFocus}\n onBlur={ring.onBlur}\n >\n <Glyph name={kind} />\n <span>{contactLabel(href)}</span>\n </a>\n );\n};\n\nconst DocumentCard = ({ href }: { href: string }) => {\n const ring = useFocusRing();\n let host = \"\";\n try {\n host = new URL(href).host;\n } catch {\n /* keep empty */\n }\n return (\n <a\n href={href}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n title={href}\n data-convai-part=\"message-file-card\"\n style={css(S.fileCard, ring.style)}\n onFocus={ring.onFocus}\n onBlur={ring.onBlur}\n >\n <span data-convai-part=\"message-file-icon\" style={css(S.fileIcon)}>\n {documentBadge(href)}\n </span>\n <span style={css(S.fileBody)}>\n <span data-convai-part=\"message-file-name\" style={css(S.fileName)}>\n {fileNameOf(href)}\n </span>\n <span data-convai-part=\"message-file-meta\" style={css(S.fileMeta)}>\n {host} · Opens in a new tab\n </span>\n </span>\n </a>\n );\n};\n\ntype LoadState = \"loading\" | \"ready\" | \"error\";\n\n/**\n * Inline preview for an image or video URL. The element is in the tree from\n * the start so the fetch begins immediately; a skeleton covers it until it\n * decodes. Error, timeout, or an insecure URL collapse it to one muted line\n * so a URL the character invented never leaves an empty player behind.\n */\nconst MediaPreview = ({\n src,\n alt,\n kind,\n pageProtocol,\n}: {\n src: string;\n alt: string;\n kind: \"image\" | \"video\";\n pageProtocol?: string;\n}) => {\n const insecure = isMixedContent(src, pageProtocol);\n const [state, setState] = React.useState<LoadState>(insecure ? \"error\" : \"loading\");\n const cardRef = React.useRef<HTMLSpanElement>(null);\n React.useEffect(() => {\n injectKeyframes(document);\n }, []);\n React.useEffect(() => {\n if (state !== \"loading\") return;\n const t = setTimeout(() => setState((s) => (s === \"loading\" ? \"error\" : s)), PREVIEW_TIMEOUT_MS);\n return () => clearTimeout(t);\n }, [state]);\n\n if (state === \"error\") {\n return (\n <span data-convai-part=\"message-media-unavailable\" style={css(S.unavailable)}>\n Preview unavailable — {describeUrl(src)}\n {insecure ? \" (insecure URL)\" : \"\"}\n </span>\n );\n }\n\n const ready = state === \"ready\";\n const open = () =>\n openLightbox({\n src,\n alt,\n caption: describeUrl(src),\n href: src,\n root: document,\n returnFocusTo: cardRef.current,\n });\n const buttonProps =\n kind === \"image\"\n ? {\n role: \"button\",\n tabIndex: 0,\n \"aria-label\": `Open image: ${fileNameOf(src)}`,\n onClick: open,\n onKeyDown: (e: React.KeyboardEvent) => {\n if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n open();\n }\n },\n }\n : {};\n\n return (\n <>\n <span\n ref={cardRef}\n data-convai-part=\"message-media-card\"\n style={css(S.card, kind === \"image\" ? S.cardButton : {})}\n {...buttonProps}\n >\n {kind === \"image\" ? (\n <img\n src={src}\n alt={alt}\n loading=\"lazy\"\n data-convai-part=\"message-media\"\n onLoad={() => setState(\"ready\")}\n onError={() => setState(\"error\")}\n style={css(S.media, { opacity: ready ? 1 : 0 })}\n />\n ) : (\n <video\n src={src}\n controls\n preload=\"metadata\"\n data-convai-part=\"message-media\"\n onLoadedMetadata={() => setState(\"ready\")}\n onError={() => setState(\"error\")}\n style={css(S.media, S.videoMedia, { opacity: ready ? 1 : 0 })}\n />\n )}\n {!ready && (\n <span\n data-convai-skeleton=\"\"\n data-convai-part=\"message-media-skeleton\"\n style={css(S.skeleton)}\n aria-hidden=\"true\"\n />\n )}\n {kind === \"image\" && (\n <span data-convai-part=\"message-media-zoom\" style={css(S.zoom)}>\n <Glyph name=\"zoom\" style={{ fontSize: 14 }} />\n </span>\n )}\n </span>\n <span data-convai-part=\"message-media-caption\" style={css(S.caption)}>\n {describeUrl(src)}\n </span>\n </>\n );\n};\n\n/** One per message: cards drawn so far, against MAX_CARDS_PER_MESSAGE. */\ninterface CardBudget {\n cards: number;\n}\n\nconst renderNode = (\n node: InlineNode,\n key: string,\n media: boolean,\n budget: CardBudget,\n pageProtocol?: string,\n resolveLinkPreview?: LinkPreviewResolver,\n): React.ReactNode => {\n switch (node.kind) {\n case \"strong\":\n return <strong key={key}>{node.text}</strong>;\n case \"em\":\n return <em key={key}>{node.text}</em>;\n case \"blocked\":\n // Not an anchor, ever. The label reads as the character wrote it; the\n // target is only revealed on hover.\n return (\n <span\n key={key}\n data-convai-part=\"message-link-blocked\"\n style={css(S.blocked)}\n title={`Link blocked: ${node.href}`}\n >\n {node.label}\n </span>\n );\n case \"image\": {\n if (media && budget.cards < MAX_CARDS_PER_MESSAGE) {\n budget.cards++;\n return (\n <MediaPreview key={key} src={node.src} alt={node.alt} kind=\"image\" pageProtocol={pageProtocol} />\n );\n }\n // With previews off (or the budget spent), an image still has to say\n // what it pointed at, so it degrades to the same anchor a link renders.\n return <Anchor key={key} href={node.src} kind=\"image\" label={node.alt || node.src} />;\n }\n case \"link\": {\n const kind = linkKindForUrl(node.href);\n if (kind === \"email\" || kind === \"phone\" || kind === \"sms\") {\n return media ? (\n <ContactChip key={key} href={node.href} kind={kind} />\n ) : (\n <Anchor key={key} href={node.href} kind={kind} label={node.label} />\n );\n }\n const wantsCard =\n media &&\n (kind === \"image\" || kind === \"video\" || kind === \"document\") &&\n budget.cards < MAX_CARDS_PER_MESSAGE;\n // The budget is spent when the card mounts, not when it resolves, so the\n // cap stays deterministic for a message naming twenty pages.\n const wantsSiteCard =\n media && kind === \"web\" && !!resolveLinkPreview && budget.cards < MAX_CARDS_PER_MESSAGE;\n if (wantsCard || wantsSiteCard) budget.cards++;\n return (\n <React.Fragment key={key}>\n <Anchor href={node.href} kind={kind} label={node.label} />\n {wantsCard && kind === \"document\" && <DocumentCard href={node.href} />}\n {wantsCard && kind !== \"document\" && (\n <MediaPreview src={node.href} alt={node.label} kind={kind} pageProtocol={pageProtocol} />\n )}\n {wantsSiteCard && <SiteCard href={node.href} resolver={resolveLinkPreview!} />}\n </React.Fragment>\n );\n }\n default:\n return <React.Fragment key={key}>{node.text}</React.Fragment>;\n }\n};\n\nconst wrapperStyle: React.CSSProperties = { whiteSpace: \"pre-wrap\", wordWrap: \"break-word\" };\n\nexport const MarkdownRenderer: React.FC<MarkdownRendererProps> = ({\n text,\n media = true,\n pageProtocol,\n resolveLinkPreview,\n}) => {\n if (!text) return <div style={wrapperStyle} />;\n\n // Handle both actual newlines and literal \"\\n\" sequences.\n const lines = text.replace(/\\\\n/g, \"\\n\").split(\"\\n\");\n const budget: CardBudget = { cards: 0 };\n\n return (\n <div style={wrapperStyle}>\n {lines.map((line, lineIndex) => {\n // An empty line is paragraph spacing.\n if (line.trim() === \"\" && lineIndex > 0) return <br key={`br-${lineIndex}`} />;\n const nodes = parseInlineMarkdown(line).map((node, i) =>\n renderNode(\n node,\n `${node.kind}-${lineIndex}-${i}`,\n media,\n budget,\n pageProtocol,\n resolveLinkPreview,\n ),\n );\n return (\n <React.Fragment key={`line-${lineIndex}`}>\n {nodes.length > 0 ? nodes : line}\n {lineIndex < lines.length - 1 && <br />}\n </React.Fragment>\n );\n })}\n </div>\n );\n};\n"]}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { LinkPreviewResolver } from "../../../../utils/linkPreview";
|
|
2
|
+
import { RTCChatMessage } from "../types";
|
|
2
3
|
type Message = RTCChatMessage;
|
|
3
4
|
interface MessageListProps {
|
|
4
5
|
messages: Message[];
|
|
5
6
|
className?: string;
|
|
6
7
|
isStreaming?: boolean;
|
|
7
8
|
forceToBottomToken?: string | number | boolean;
|
|
9
|
+
/** Open Graph lookup for plain web links in bot bubbles. */
|
|
10
|
+
linkPreviewResolver?: LinkPreviewResolver;
|
|
8
11
|
}
|
|
9
|
-
export declare const MessageList: ({ messages, className, isStreaming, forceToBottomToken, }: MessageListProps) => import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export declare const MessageList: ({ messages, className, isStreaming, forceToBottomToken, linkPreviewResolver, }: MessageListProps) => import("react/jsx-runtime").JSX.Element;
|
|
10
13
|
export {};
|
|
11
14
|
//# sourceMappingURL=MessageList.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageList.d.ts","sourceRoot":"","sources":["../../../../../src/react/components/rtc-widget/components/MessageList.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MessageList.d.ts","sourceRoot":"","sources":["../../../../../src/react/components/rtc-widget/components/MessageList.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAKzE,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,KAAK,OAAO,GAAG,cAAc,CAAC;AAE9B,UAAU,gBAAgB;IACxB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IAC/C,4DAA4D;IAC5D,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;CAC3C;AAED,eAAO,MAAM,WAAW,GAAI,gFAMzB,gBAAgB,4CAuHlB,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import React, { useRef, useEffect, useCallback } from "react";
|
|
3
|
-
import { UserMessage } from "./UserMessage
|
|
4
|
-
import { ConviMessage } from "./ConviMessage
|
|
5
|
-
import { aeroTheme } from "../styles
|
|
6
|
-
import { MessageListContainer, MessageWrapper, EmptyState } from "../styles
|
|
7
|
-
export const MessageList = ({ messages, className, isStreaming = false, forceToBottomToken, }) => {
|
|
3
|
+
import { UserMessage } from "./UserMessage";
|
|
4
|
+
import { ConviMessage } from "./ConviMessage";
|
|
5
|
+
import { aeroTheme } from "../styles";
|
|
6
|
+
import { MessageListContainer, MessageWrapper, EmptyState } from "../styles";
|
|
7
|
+
export const MessageList = ({ messages, className, isStreaming = false, forceToBottomToken, linkPreviewResolver, }) => {
|
|
8
8
|
const containerRef = useRef(null);
|
|
9
9
|
const [shouldAutoScroll, setShouldAutoScroll] = React.useState(true);
|
|
10
10
|
// Handle scroll events
|
|
@@ -84,6 +84,6 @@ export const MessageList = ({ messages, className, isStreaming = false, forceToB
|
|
|
84
84
|
marginTop: 8,
|
|
85
85
|
}, children: "Type a message below to begin chatting" })] }));
|
|
86
86
|
}
|
|
87
|
-
return (_jsx(MessageListContainer, { ref: containerRef, className: className, onScroll: handleScroll, children: messages.map((message) => (_jsx(MessageWrapper, { children: message.isUser ? (_jsx(UserMessage, { message: message.text, timestamp: message.timestamp, sender: message.sender })) : (_jsx(ConviMessage, { message: message.text, timestamp: message.timestamp, showLogo: message.showLogo, sender: message.sender })) }, message.id))) }));
|
|
87
|
+
return (_jsx(MessageListContainer, { ref: containerRef, className: className, onScroll: handleScroll, children: messages.map((message) => (_jsx(MessageWrapper, { children: message.isUser ? (_jsx(UserMessage, { message: message.text, timestamp: message.timestamp, sender: message.sender })) : (_jsx(ConviMessage, { message: message.text, timestamp: message.timestamp, showLogo: message.showLogo, sender: message.sender, resolveLinkPreview: linkPreviewResolver })) }, message.id))) }));
|
|
88
88
|
};
|
|
89
89
|
//# sourceMappingURL=MessageList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageList.js","sourceRoot":"","sources":["../../../../../src/react/components/rtc-widget/components/MessageList.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"MessageList.js","sourceRoot":"","sources":["../../../../../src/react/components/rtc-widget/components/MessageList.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAE9D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAc7E,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAC1B,QAAQ,EACR,SAAS,EACT,WAAW,GAAG,KAAK,EACnB,kBAAkB,EAClB,mBAAmB,GACF,EAAE,EAAE;IACrB,MAAM,YAAY,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAC;IACzD,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,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\nimport type { LinkPreviewResolver } from \"../../../../utils/linkPreview\";\nimport { UserMessage } from \"./UserMessage\";\nimport { ConviMessage } from \"./ConviMessage\";\nimport { aeroTheme } from \"../styles\";\nimport { MessageListContainer, MessageWrapper, EmptyState } from \"../styles\";\nimport { RTCChatMessage } from \"../types\";\n\ntype Message = RTCChatMessage;\n\ninterface MessageListProps {\n messages: Message[];\n className?: string;\n isStreaming?: boolean;\n forceToBottomToken?: string | number | boolean;\n /** Open Graph lookup for plain web links in bot bubbles. */\n linkPreviewResolver?: LinkPreviewResolver;\n}\n\nexport const MessageList = ({\n messages,\n className,\n isStreaming = false,\n forceToBottomToken,\n linkPreviewResolver,\n}: MessageListProps) => {\n const containerRef = useRef<HTMLDivElement | null>(null);\n const [shouldAutoScroll, setShouldAutoScroll] = React.useState(true);\n\n // Handle scroll events\n const handleScroll = useCallback((e: React.UIEvent<HTMLDivElement>) => {\n const { scrollTop, scrollHeight, clientHeight } = e.currentTarget;\n\n // Check if user is near bottom (within 100px)\n const isNearBottom = scrollHeight - scrollTop - clientHeight < 100;\n setShouldAutoScroll(isNearBottom);\n }, []);\n\n // Auto-scroll to bottom\n const scrollToBottom = useCallback(() => {\n const el = containerRef.current;\n if (!el || !shouldAutoScroll) return;\n try {\n el.scrollTo({ top: el.scrollHeight, behavior: isStreaming ? \"smooth\" : \"auto\" });\n } catch {\n // Fallback for older browsers\n el.scrollTop = el.scrollHeight;\n }\n }, [shouldAutoScroll, isStreaming]);\n\n const scrollToBottomImmediate = useCallback(() => {\n const el = containerRef.current;\n if (!el) return;\n try {\n el.scrollTo({ top: el.scrollHeight, behavior: \"auto\" });\n } catch {\n el.scrollTop = el.scrollHeight;\n }\n }, []);\n\n // Scroll to bottom on new messages\n useEffect(() => {\n if (messages.length > 0) {\n // Use requestAnimationFrame to ensure DOM is updated\n requestAnimationFrame(() => {\n scrollToBottom();\n });\n }\n }, [messages.length, scrollToBottom]);\n\n // Observe size changes to keep smooth auto-scroll when message content grows\n useEffect(() => {\n const el = containerRef.current;\n if (!el || typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(() => {\n if (!shouldAutoScroll) return;\n // Smooth during streaming, instant otherwise to prevent bounce at finalization\n try {\n el.scrollTo({ top: el.scrollHeight, behavior: isStreaming ? \"smooth\" : \"auto\" });\n } catch {\n el.scrollTop = el.scrollHeight;\n }\n });\n observer.observe(el);\n return () => observer.disconnect();\n }, [shouldAutoScroll, isStreaming]);\n\n // Force bottom when token changes (e.g., when chat opens or after reload)\n useEffect(() => {\n if (forceToBottomToken !== undefined) {\n requestAnimationFrame(() => scrollToBottomImmediate());\n }\n }, [forceToBottomToken, scrollToBottomImmediate]);\n\n // Initial scroll to bottom\n useEffect(() => {\n if (containerRef.current && messages.length > 0) {\n containerRef.current.scrollTop = containerRef.current.scrollHeight;\n }\n }, []);\n\n if (messages.length === 0) {\n return (\n <EmptyState>\n <p>Start a conversation</p>\n <p\n style={{\n fontSize: aeroTheme.typography.sizes.caption,\n marginTop: 8,\n }}\n >\n Type a message below to begin chatting\n </p>\n </EmptyState>\n );\n }\n\n return (\n <MessageListContainer\n ref={containerRef}\n className={className}\n onScroll={handleScroll}\n >\n {messages.map((message: Message) => (\n <MessageWrapper key={message.id}>\n {message.isUser ? (\n <UserMessage\n message={message.text}\n timestamp={message.timestamp}\n sender={message.sender}\n />\n ) : (\n <ConviMessage\n message={message.text}\n timestamp={message.timestamp}\n showLogo={message.showLogo}\n sender={message.sender}\n resolveLinkPreview={linkPreviewResolver}\n />\n )}\n </MessageWrapper>\n ))}\n </MessageListContainer>\n );\n};\n\n"]}
|