@convai/web-sdk 1.8.0 → 1.9.0-beta.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/README.md +213 -45
- package/dist/core/CharacterRoster.d.ts +84 -0
- package/dist/core/CharacterRoster.d.ts.map +1 -0
- package/dist/core/CharacterRoster.js +348 -0
- package/dist/core/CharacterRoster.js.map +1 -0
- package/dist/core/CharacterVersionManager.d.ts +100 -0
- package/dist/core/CharacterVersionManager.d.ts.map +1 -0
- package/dist/core/CharacterVersionManager.js +227 -0
- package/dist/core/CharacterVersionManager.js.map +1 -0
- package/dist/core/ConvaiClient.d.ts +190 -1
- package/dist/core/ConvaiClient.d.ts.map +1 -1
- package/dist/core/ConvaiClient.js +1328 -289
- package/dist/core/ConvaiClient.js.map +1 -1
- package/dist/core/ConvaiRoomError.d.ts +48 -0
- package/dist/core/ConvaiRoomError.d.ts.map +1 -0
- package/dist/core/ConvaiRoomError.js +111 -0
- package/dist/core/ConvaiRoomError.js.map +1 -0
- package/dist/core/MessageHandler.d.ts +26 -2
- package/dist/core/MessageHandler.d.ts.map +1 -1
- package/dist/core/MessageHandler.js +397 -32
- package/dist/core/MessageHandler.js.map +1 -1
- package/dist/core/SSESession.d.ts +74 -0
- package/dist/core/SSESession.d.ts.map +1 -0
- package/dist/core/SSESession.js +499 -0
- package/dist/core/SSESession.js.map +1 -0
- package/dist/core/characterReference.d.ts +40 -0
- package/dist/core/characterReference.d.ts.map +1 -0
- package/dist/core/characterReference.js +72 -0
- package/dist/core/characterReference.js.map +1 -0
- package/dist/core/connectRequest.d.ts +17 -4
- package/dist/core/connectRequest.d.ts.map +1 -1
- package/dist/core/connectRequest.js +28 -17
- package/dist/core/connectRequest.js.map +1 -1
- package/dist/core/index.d.ts +10 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +14 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/logicalTurn.d.ts +4 -6
- package/dist/core/logicalTurn.d.ts.map +1 -1
- package/dist/core/logicalTurn.js +29 -4
- package/dist/core/logicalTurn.js.map +1 -1
- package/dist/core/modelOutput.d.ts.map +1 -1
- package/dist/core/modelOutput.js +2 -2
- package/dist/core/modelOutput.js.map +1 -1
- package/dist/core/rosterRequest.d.ts +57 -0
- package/dist/core/rosterRequest.d.ts.map +1 -0
- package/dist/core/rosterRequest.js +210 -0
- package/dist/core/rosterRequest.js.map +1 -0
- package/dist/core/types.d.ts +869 -22
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/embed/ConvaiChatElement.d.ts +77 -1
- package/dist/embed/ConvaiChatElement.d.ts.map +1 -1
- package/dist/embed/ConvaiChatElement.js +433 -54
- package/dist/embed/ConvaiChatElement.js.map +1 -1
- package/dist/embed/chat-embed-v1.js +136 -35
- package/dist/embed/chat-embed-v1.js.map +4 -4
- package/dist/react/components/ConvaiWidget.d.ts.map +1 -1
- package/dist/react/components/ConvaiWidget.js +6 -1
- package/dist/react/components/ConvaiWidget.js.map +1 -1
- package/dist/react/components/rtc-widget/components/AudioVisualizer.d.ts.map +1 -1
- package/dist/react/components/rtc-widget/components/AudioVisualizer.js +28 -1
- package/dist/react/components/rtc-widget/components/AudioVisualizer.js.map +1 -1
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts +18 -0
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts.map +1 -1
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.js +132 -63
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.js.map +1 -1
- package/dist/react/components/rtc-widget/components/UserMessage.js +1 -1
- package/dist/react/components/rtc-widget/components/UserMessage.js.map +1 -1
- package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts.map +1 -1
- package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js +93 -49
- package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js.map +1 -1
- package/dist/react/hooks/useConvaiClient.d.ts.map +1 -1
- package/dist/react/hooks/useConvaiClient.js +17 -2
- package/dist/react/hooks/useConvaiClient.js.map +1 -1
- package/dist/react/index.d.ts +6 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +9 -1
- package/dist/react/index.js.map +1 -1
- package/dist/utils/inlineMarkdown.d.ts +60 -0
- package/dist/utils/inlineMarkdown.d.ts.map +1 -0
- package/dist/utils/inlineMarkdown.js +183 -0
- package/dist/utils/inlineMarkdown.js.map +1 -0
- 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 +69 -0
- package/dist/utils/linkPresentation.d.ts.map +1 -0
- package/dist/utils/linkPresentation.js +358 -0
- package/dist/utils/linkPresentation.js.map +1 -0
- package/dist/vanilla/AudioRenderer.d.ts +3 -1
- package/dist/vanilla/AudioRenderer.d.ts.map +1 -1
- package/dist/vanilla/AudioRenderer.js +8 -2
- package/dist/vanilla/AudioRenderer.js.map +1 -1
- package/dist/vanilla/ConvaiWidget.d.ts.map +1 -1
- package/dist/vanilla/ConvaiWidget.js +1162 -315
- package/dist/vanilla/ConvaiWidget.js.map +1 -1
- package/dist/vanilla/WidgetEventSubscriptions.d.ts +1 -1
- package/dist/vanilla/WidgetEventSubscriptions.d.ts.map +1 -1
- package/dist/vanilla/WidgetEventSubscriptions.js +5 -0
- package/dist/vanilla/WidgetEventSubscriptions.js.map +1 -1
- package/dist/vanilla/icons.d.ts.map +1 -1
- package/dist/vanilla/icons.js +62 -15
- package/dist/vanilla/icons.js.map +1 -1
- package/dist/vanilla/index.d.ts +8 -2
- package/dist/vanilla/index.d.ts.map +1 -1
- package/dist/vanilla/index.js +6 -1
- package/dist/vanilla/index.js.map +1 -1
- package/dist/vanilla/styles.d.ts +18 -1
- package/dist/vanilla/styles.d.ts.map +1 -1
- package/dist/vanilla/styles.js +150 -29
- package/dist/vanilla/styles.js.map +1 -1
- package/dist/vanilla/types.d.ts +74 -0
- package/dist/vanilla/types.d.ts.map +1 -1
- package/dist/vanilla/types.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +44 -17
|
@@ -1,68 +1,137 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import React from "react";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
3
|
+
import { parseInlineMarkdown, compactUrl } from "../../../../utils/inlineMarkdown.js";
|
|
4
|
+
import { linkKindForUrl, describeUrl, fileNameOf, documentBadge, contactLabel, hoverTitle, isMixedContent, glyph, presentationStyles as S, PREVIEW_TIMEOUT_MS, MAX_CARDS_PER_MESSAGE, } from "../../../../utils/linkPresentation.js";
|
|
5
|
+
import { openLightbox } from "../../../../utils/lightbox.js";
|
|
6
|
+
import { injectKeyframes } from "../../../../vanilla/styles.js";
|
|
7
|
+
const css = (...objs) => Object.assign({}, ...objs);
|
|
8
|
+
const Glyph = ({ name, style }) => (_jsx("span", { style: css(S.contactGlyph, style ?? {}), dangerouslySetInnerHTML: { __html: glyph(name) } }));
|
|
9
|
+
/** Inline styles cannot express :focus-visible, so the ring is toggled by hand. */
|
|
10
|
+
const useFocusRing = () => {
|
|
11
|
+
const [focused, setFocused] = React.useState(false);
|
|
12
|
+
return {
|
|
13
|
+
style: focused ? S.linkFocus : {},
|
|
14
|
+
onFocus: (e) => setFocused(e.target.matches(":focus-visible")),
|
|
15
|
+
onBlur: () => setFocused(false),
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const Anchor = ({ href, kind, label }) => {
|
|
19
|
+
const ring = useFocusRing();
|
|
20
|
+
// A bare URL is its own label and may be elided for display; the title
|
|
21
|
+
// compares against what is actually shown so the full target is one hover away.
|
|
22
|
+
const display = label === href ? compactUrl(label) : label;
|
|
23
|
+
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" }))] }));
|
|
24
|
+
};
|
|
25
|
+
const ContactChip = ({ href, kind }) => {
|
|
26
|
+
const ring = useFocusRing();
|
|
27
|
+
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) })] }));
|
|
28
|
+
};
|
|
29
|
+
const DocumentCard = ({ href }) => {
|
|
30
|
+
const ring = useFocusRing();
|
|
31
|
+
let host = "";
|
|
32
|
+
try {
|
|
33
|
+
host = new URL(href).host;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
/* keep empty */
|
|
37
|
+
}
|
|
38
|
+
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"] })] })] }));
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Inline preview for an image or video URL. The element is in the tree from
|
|
42
|
+
* the start so the fetch begins immediately; a skeleton covers it until it
|
|
43
|
+
* decodes. Error, timeout, or an insecure URL collapse it to one muted line
|
|
44
|
+
* so a URL the character invented never leaves an empty player behind.
|
|
45
|
+
*/
|
|
46
|
+
const MediaPreview = ({ src, alt, kind, pageProtocol, }) => {
|
|
47
|
+
const insecure = isMixedContent(src, pageProtocol);
|
|
48
|
+
const [state, setState] = React.useState(insecure ? "error" : "loading");
|
|
49
|
+
const cardRef = React.useRef(null);
|
|
50
|
+
React.useEffect(() => {
|
|
51
|
+
injectKeyframes(document);
|
|
52
|
+
}, []);
|
|
53
|
+
React.useEffect(() => {
|
|
54
|
+
if (state !== "loading")
|
|
55
|
+
return;
|
|
56
|
+
const t = setTimeout(() => setState((s) => (s === "loading" ? "error" : s)), PREVIEW_TIMEOUT_MS);
|
|
57
|
+
return () => clearTimeout(t);
|
|
58
|
+
}, [state]);
|
|
59
|
+
if (state === "error") {
|
|
60
|
+
return (_jsxs("span", { "data-convai-part": "message-media-unavailable", style: css(S.unavailable), children: ["Preview unavailable \u2014 ", describeUrl(src), insecure ? " (insecure URL)" : ""] }));
|
|
61
|
+
}
|
|
62
|
+
const ready = state === "ready";
|
|
63
|
+
const open = () => openLightbox({
|
|
64
|
+
src,
|
|
65
|
+
alt,
|
|
66
|
+
caption: describeUrl(src),
|
|
67
|
+
href: src,
|
|
68
|
+
root: document,
|
|
69
|
+
returnFocusTo: cardRef.current,
|
|
70
|
+
});
|
|
71
|
+
const buttonProps = kind === "image"
|
|
72
|
+
? {
|
|
73
|
+
role: "button",
|
|
74
|
+
tabIndex: 0,
|
|
75
|
+
"aria-label": `Open image: ${fileNameOf(src)}`,
|
|
76
|
+
onClick: open,
|
|
77
|
+
onKeyDown: (e) => {
|
|
78
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
79
|
+
e.preventDefault();
|
|
80
|
+
open();
|
|
54
81
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
: {};
|
|
85
|
+
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) })] }));
|
|
86
|
+
};
|
|
87
|
+
const renderNode = (node, key, media, budget, pageProtocol) => {
|
|
88
|
+
switch (node.kind) {
|
|
89
|
+
case "strong":
|
|
90
|
+
return _jsx("strong", { children: node.text }, key);
|
|
91
|
+
case "em":
|
|
92
|
+
return _jsx("em", { children: node.text }, key);
|
|
93
|
+
case "blocked":
|
|
94
|
+
// Not an anchor, ever. The label reads as the character wrote it; the
|
|
95
|
+
// target is only revealed on hover.
|
|
96
|
+
return (_jsx("span", { "data-convai-part": "message-link-blocked", style: css(S.blocked), title: `Link blocked: ${node.href}`, children: node.label }, key));
|
|
97
|
+
case "image": {
|
|
98
|
+
if (media && budget.cards < MAX_CARDS_PER_MESSAGE) {
|
|
99
|
+
budget.cards++;
|
|
100
|
+
return (_jsx(MediaPreview, { src: node.src, alt: node.alt, kind: "image", pageProtocol: pageProtocol }, key));
|
|
61
101
|
}
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
102
|
+
// With previews off (or the budget spent), an image still has to say
|
|
103
|
+
// what it pointed at, so it degrades to the same anchor a link renders.
|
|
104
|
+
return _jsx(Anchor, { href: node.src, kind: "image", label: node.alt || node.src }, key);
|
|
105
|
+
}
|
|
106
|
+
case "link": {
|
|
107
|
+
const kind = linkKindForUrl(node.href);
|
|
108
|
+
if (kind === "email" || kind === "phone" || kind === "sms") {
|
|
109
|
+
return media ? (_jsx(ContactChip, { href: node.href, kind: kind }, key)) : (_jsx(Anchor, { href: node.href, kind: kind, label: node.label }, key));
|
|
110
|
+
}
|
|
111
|
+
const wantsCard = media &&
|
|
112
|
+
(kind === "image" || kind === "video" || kind === "document") &&
|
|
113
|
+
budget.cards < MAX_CARDS_PER_MESSAGE;
|
|
114
|
+
if (wantsCard)
|
|
115
|
+
budget.cards++;
|
|
116
|
+
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 }))] }, key));
|
|
117
|
+
}
|
|
118
|
+
default:
|
|
119
|
+
return _jsx(React.Fragment, { children: node.text }, key);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const wrapperStyle = { whiteSpace: "pre-wrap", wordWrap: "break-word" };
|
|
123
|
+
export const MarkdownRenderer = ({ text, media = true, pageProtocol, }) => {
|
|
124
|
+
if (!text)
|
|
125
|
+
return _jsx("div", { style: wrapperStyle });
|
|
126
|
+
// Handle both actual newlines and literal "\n" sequences.
|
|
127
|
+
const lines = text.replace(/\\n/g, "\n").split("\n");
|
|
128
|
+
const budget = { cards: 0 };
|
|
129
|
+
return (_jsx("div", { style: wrapperStyle, children: lines.map((line, lineIndex) => {
|
|
130
|
+
// An empty line is paragraph spacing.
|
|
131
|
+
if (line.trim() === "" && lineIndex > 0)
|
|
132
|
+
return _jsx("br", {}, `br-${lineIndex}`);
|
|
133
|
+
const nodes = parseInlineMarkdown(line).map((node, i) => renderNode(node, `${node.kind}-${lineIndex}-${i}`, media, budget, pageProtocol));
|
|
134
|
+
return (_jsxs(React.Fragment, { children: [nodes.length > 0 ? nodes : line, lineIndex < lines.length - 1 && _jsx("br", {})] }, `line-${lineIndex}`));
|
|
135
|
+
}) }));
|
|
67
136
|
};
|
|
68
137
|
//# 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;AAM1B,MAAM,CAAC,MAAM,gBAAgB,GAAoC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;IAC5E,mCAAmC;IACnC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAmB,EAAE;QACxD,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QAExB,sDAAsD;QACtD,kDAAkD;QAClD,MAAM,cAAc,GAAG,KAAK,CAAC,OAA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AAG,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\";\n\ninterface MarkdownRendererProps {\n text: string;\n}\n\nexport const MarkdownRenderer: React.FC<MarkdownRendererProps> = ({ text }) => {\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 // Process markdown within each line\n const processLine = (text: string): React.ReactNode[] => {\n const parts: React.ReactNode[] = [];\n let remaining = text;\n let keyCounter = 0;\n\n // Process bold and italic markdown\n // Bold: **text** or __text__\n // Italic: *text* or _text_\n const markdownRegex = /(\\*\\*|__)(.*?)\\1|\\*([^*]+)\\*|_([^_]+)_/g;\n let lastIndex = 0;\n let match;\n\n while ((match = markdownRegex.exec(remaining)) !== null) {\n // Add text before the match\n if (match.index > lastIndex) {\n const textBefore = remaining.substring(lastIndex, match.index);\n if (textBefore) {\n parts.push(\n <React.Fragment key={`text-${lineIndex}-${keyCounter++}`}>\n {textBefore}\n </React.Fragment>\n );\n }\n }\n\n // Determine if it's bold or italic\n if (match[1] && match[2]) {\n // Bold text (** or __)\n parts.push(\n <strong key={`bold-${lineIndex}-${keyCounter++}`}>\n {match[2]}\n </strong>\n );\n } else if (match[3]) {\n // Italic text (*)\n parts.push(\n <em key={`italic-${lineIndex}-${keyCounter++}`}>\n {match[3]}\n </em>\n );\n } else if (match[4]) {\n // Italic text (_)\n parts.push(\n <em key={`italic-${lineIndex}-${keyCounter++}`}>\n {match[4]}\n </em>\n );\n }\n\n lastIndex = match.index + match[0].length;\n }\n\n // Add remaining text\n if (lastIndex < remaining.length) {\n const textAfter = remaining.substring(lastIndex);\n if (textAfter) {\n parts.push(\n <React.Fragment key={`text-${lineIndex}-${keyCounter++}`}>\n {textAfter}\n </React.Fragment>\n );\n }\n }\n\n return parts;\n };\n\n const processedLine = processLine(line);\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\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;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAwB7D,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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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 { 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\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): 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 if (wantsCard) 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 </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}) => {\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(node, `${node.kind}-${lineIndex}-${i}`, media, budget, pageProtocol),\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"]}
|
|
@@ -4,7 +4,7 @@ import { UserBubble, UserMessageContainer, MessageHeader, UserLabel, LogoWrapper
|
|
|
4
4
|
import { FaUser } from "react-icons/fa";
|
|
5
5
|
import { MarkdownRenderer } from "./MarkdownRenderer.js";
|
|
6
6
|
export const UserMessage = ({ message, timestamp, className, sender, }) => {
|
|
7
|
-
return (_jsxs(UserMessageContainer, { className: className, children: [_jsxs(UserBubble, { children: [sender && (_jsxs(MessageHeader, { children: [_jsx(LogoWrapper, { children: _jsx(FaUser, { size: 16, color: aeroTheme.colors.convai.dark }) }), _jsx(UserLabel, { children: sender === "User" ? "You" : sender })] })), _jsx(MarkdownRenderer, { text: message })] }), timestamp && (_jsx("span", { style: {
|
|
7
|
+
return (_jsxs(UserMessageContainer, { className: className, children: [_jsxs(UserBubble, { children: [sender && (_jsxs(MessageHeader, { children: [_jsx(LogoWrapper, { children: _jsx(FaUser, { size: 16, color: aeroTheme.colors.convai.dark }) }), _jsx(UserLabel, { children: sender === "User" ? "You" : sender })] })), _jsx(MarkdownRenderer, { text: message, media: false })] }), timestamp && (_jsx("span", { style: {
|
|
8
8
|
fontSize: aeroTheme.typography.sizes.caption,
|
|
9
9
|
color: aeroTheme.colors.text.secondary,
|
|
10
10
|
marginTop: 4,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserMessage.js","sourceRoot":"","sources":["../../../../../src/react/components/rtc-widget/components/UserMessage.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,aAAa,EACb,SAAS,EACT,WAAW,GACZ,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAStD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAC1B,OAAO,EACP,SAAS,EACT,SAAS,EACT,MAAM,GACW,EAAE,EAAE;IACrB,OAAO,CACL,MAAC,oBAAoB,IAAC,SAAS,EAAE,SAAS,aACxC,MAAC,UAAU,eACR,MAAM,IAAI,CACT,MAAC,aAAa,eACZ,KAAC,WAAW,cACV,KAAC,MAAM,IAAC,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,GAAI,GAC7C,EACd,KAAC,SAAS,cAAE,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,GAAa,IAC7C,CACjB,EACD,KAAC,gBAAgB,IAAC,IAAI,EAAE,OAAO,GAAI,
|
|
1
|
+
{"version":3,"file":"UserMessage.js","sourceRoot":"","sources":["../../../../../src/react/components/rtc-widget/components/UserMessage.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,aAAa,EACb,SAAS,EACT,WAAW,GACZ,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAStD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAC1B,OAAO,EACP,SAAS,EACT,SAAS,EACT,MAAM,GACW,EAAE,EAAE;IACrB,OAAO,CACL,MAAC,oBAAoB,IAAC,SAAS,EAAE,SAAS,aACxC,MAAC,UAAU,eACR,MAAM,IAAI,CACT,MAAC,aAAa,eACZ,KAAC,WAAW,cACV,KAAC,MAAM,IAAC,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,GAAI,GAC7C,EACd,KAAC,SAAS,cAAE,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,GAAa,IAC7C,CACjB,EACD,KAAC,gBAAgB,IAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,GAAI,IACtC,EACZ,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,UAAU;oBACrB,UAAU,EAAE,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI;iBACjD,YAEA,SAAS,GACL,CACR,IACoB,CACxB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React from \"react\";\nimport { aeroTheme } from \"../styles\";\nimport {\n UserBubble,\n UserMessageContainer,\n MessageHeader,\n UserLabel,\n LogoWrapper,\n} from \"../styles\";\n\nimport { FaUser } from \"react-icons/fa\";\nimport { MarkdownRenderer } from \"./MarkdownRenderer\";\n\ninterface UserMessageProps {\n message: string;\n timestamp?: string;\n className?: string;\n sender?: string;\n}\n\nexport const UserMessage = ({\n message,\n timestamp,\n className,\n sender,\n}: UserMessageProps) => {\n return (\n <UserMessageContainer className={className}>\n <UserBubble>\n {sender && (\n <MessageHeader>\n <LogoWrapper>\n <FaUser size={16} color={aeroTheme.colors.convai.dark} />\n </LogoWrapper>\n <UserLabel>{sender === \"User\" ? \"You\" : sender}</UserLabel>\n </MessageHeader>\n )}\n <MarkdownRenderer text={message} media={false} />\n </UserBubble>\n {timestamp && (\n <span\n style={{\n fontSize: aeroTheme.typography.sizes.caption,\n color: aeroTheme.colors.text.secondary,\n marginTop: 4,\n alignSelf: \"flex-end\",\n fontFamily: aeroTheme.typography.fontFamily.body,\n }}\n >\n {timestamp}\n </span>\n )}\n </UserMessageContainer>\n );\n};\n\n"]}
|
package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VoiceModeOverlay.d.ts","sourceRoot":"","sources":["../../../../../../src/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,2EAA2E;IAC3E,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACpB;AAED,eAAO,MAAM,gBAAgB,GAAI,0FAQ9B,qBAAqB,
|
|
1
|
+
{"version":3,"file":"VoiceModeOverlay.d.ts","sourceRoot":"","sources":["../../../../../../src/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,2EAA2E;IAC3E,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACpB;AAED,eAAO,MAAM,gBAAgB,GAAI,0FAQ9B,qBAAqB,4CA6ZvB,CAAC"}
|
|
@@ -6,10 +6,91 @@ import { iosTransitions } from "../../styles/framerConfig.js";
|
|
|
6
6
|
import { AudioVisualizer } from "../AudioVisualizer.js";
|
|
7
7
|
export const VoiceModeOverlay = ({ isActive, isTalking, isListening = false, convaiClient, characterImage, characterName = "Character", room, }) => {
|
|
8
8
|
const barsCount = 40; // Number of bars for user microphone waveform
|
|
9
|
-
|
|
9
|
+
// PERF: the waveform is driven OUTSIDE React. A setState per animation
|
|
10
|
+
// frame re-rendered the whole overlay (reconcile + style recalc +
|
|
11
|
+
// framer-motion filter retarget) ~60x/s — ~30ms main-thread tasks that
|
|
12
|
+
// visibly juddered the host page's 3D scene whenever voice mode was
|
|
13
|
+
// open. Levels live in a ref and the SVG paths are updated directly.
|
|
14
|
+
const audioLevelsRef = useRef(Array(barsCount).fill(0));
|
|
15
|
+
const waveCanvasRef = useRef(null);
|
|
10
16
|
const analyzerRef = useRef(null);
|
|
11
17
|
const animationFrameRef = useRef(undefined);
|
|
12
18
|
const audioContextRef = useRef(null);
|
|
19
|
+
// Paint the three waves onto a small canvas — no React, no SVG filters.
|
|
20
|
+
// (The previous SVG version re-rasterized a 35px drop-shadow blur every
|
|
21
|
+
// frame; that GPU paint alone pushed the host page to ~30fps.) Glow is
|
|
22
|
+
// approximated with a wide low-alpha understroke, which is ~free.
|
|
23
|
+
// Painting is THROTTLED to 30fps and skipped entirely while silent:
|
|
24
|
+
// every canvas update forces the compositor to re-blend the whole
|
|
25
|
+
// panel stack over the host WebGL canvas, so idle repaints are pure
|
|
26
|
+
// waste that judders the 3D scene.
|
|
27
|
+
const waveFrameParityRef = useRef(0);
|
|
28
|
+
const waveWasSilentRef = useRef(false);
|
|
29
|
+
const drawWaves = () => {
|
|
30
|
+
waveFrameParityRef.current ^= 1;
|
|
31
|
+
if (waveFrameParityRef.current)
|
|
32
|
+
return; // 30fps is plenty for a waveform
|
|
33
|
+
const canvas = waveCanvasRef.current;
|
|
34
|
+
if (!canvas)
|
|
35
|
+
return;
|
|
36
|
+
{
|
|
37
|
+
const lv = audioLevelsRef.current;
|
|
38
|
+
let sum = 0;
|
|
39
|
+
for (let i = 0; i < lv.length; i++)
|
|
40
|
+
sum += lv[i];
|
|
41
|
+
const silent = sum / lv.length < 0.012;
|
|
42
|
+
if (silent && waveWasSilentRef.current)
|
|
43
|
+
return; // static line already drawn
|
|
44
|
+
waveWasSilentRef.current = silent;
|
|
45
|
+
}
|
|
46
|
+
const dpr = Math.min(window.devicePixelRatio || 1, 2);
|
|
47
|
+
if (canvas.width !== 250 * dpr) {
|
|
48
|
+
canvas.width = 250 * dpr;
|
|
49
|
+
canvas.height = 80 * dpr;
|
|
50
|
+
}
|
|
51
|
+
const ctx = canvas.getContext("2d");
|
|
52
|
+
if (!ctx)
|
|
53
|
+
return;
|
|
54
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
55
|
+
ctx.clearRect(0, 0, 250, 80);
|
|
56
|
+
const audioLevels = audioLevelsRef.current;
|
|
57
|
+
const centerY = 40;
|
|
58
|
+
const waveWidth = 250;
|
|
59
|
+
const segments = barsCount;
|
|
60
|
+
const avgLevel = audioLevels.reduce((sum, level) => sum + level, 0) / audioLevels.length;
|
|
61
|
+
const waveColors = [
|
|
62
|
+
aeroTheme.colors.convai.light,
|
|
63
|
+
aeroTheme.colors.convai.light,
|
|
64
|
+
"#34d399",
|
|
65
|
+
];
|
|
66
|
+
ctx.lineCap = "round";
|
|
67
|
+
ctx.lineJoin = "round";
|
|
68
|
+
for (let waveIndex = 2; waveIndex >= 0; waveIndex--) {
|
|
69
|
+
ctx.beginPath();
|
|
70
|
+
for (let i = 0; i <= segments; i++) {
|
|
71
|
+
const x = (i / segments) * waveWidth;
|
|
72
|
+
const levelIndex = Math.floor((i / segments) * (audioLevels.length - 1));
|
|
73
|
+
const level = audioLevels[levelIndex] || 0;
|
|
74
|
+
const phase = (Date.now() / 500 + i * 0.2 + waveIndex * 1.5) % (Math.PI * 2);
|
|
75
|
+
const baseAmplitude = avgLevel > 0.05 ? 2 + waveIndex * 1.5 : 0;
|
|
76
|
+
const amplitude = baseAmplitude + level * (25 - baseAmplitude);
|
|
77
|
+
const y = centerY + Math.sin(phase) * amplitude;
|
|
78
|
+
if (i === 0)
|
|
79
|
+
ctx.moveTo(x, y);
|
|
80
|
+
else
|
|
81
|
+
ctx.lineTo(x, y);
|
|
82
|
+
}
|
|
83
|
+
// glow understroke scaled by level, then the crisp line on top
|
|
84
|
+
ctx.strokeStyle = waveColors[waveIndex];
|
|
85
|
+
ctx.globalAlpha = 0.18 * (0.3 + avgLevel);
|
|
86
|
+
ctx.lineWidth = (2.5 - waveIndex * 0.4) + 8 * avgLevel + 3;
|
|
87
|
+
ctx.stroke();
|
|
88
|
+
ctx.globalAlpha = 0.95 - waveIndex * 0.15;
|
|
89
|
+
ctx.lineWidth = 2.5 - waveIndex * 0.4;
|
|
90
|
+
ctx.stroke();
|
|
91
|
+
}
|
|
92
|
+
ctx.globalAlpha = 1;
|
|
93
|
+
};
|
|
13
94
|
// Setup audio analysis for USER microphone input ONLY
|
|
14
95
|
useEffect(() => {
|
|
15
96
|
if (!isActive) {
|
|
@@ -17,7 +98,8 @@ export const VoiceModeOverlay = ({ isActive, isTalking, isListening = false, con
|
|
|
17
98
|
if (animationFrameRef.current) {
|
|
18
99
|
cancelAnimationFrame(animationFrameRef.current);
|
|
19
100
|
}
|
|
20
|
-
|
|
101
|
+
audioLevelsRef.current = Array(barsCount).fill(0);
|
|
102
|
+
drawWaves();
|
|
21
103
|
return;
|
|
22
104
|
}
|
|
23
105
|
let stream = null;
|
|
@@ -50,17 +132,17 @@ export const VoiceModeOverlay = ({ isActive, isTalking, isListening = false, con
|
|
|
50
132
|
const rms = Math.sqrt(sum / dataArray.length);
|
|
51
133
|
// Apply some scaling and clamping
|
|
52
134
|
const volume = Math.min(1, rms * 3); // Boost sensitivity
|
|
53
|
-
// Create left-to-right wave effect
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
135
|
+
// Create left-to-right wave effect — write into the ref and paint
|
|
136
|
+
// the SVG directly (no setState: a per-frame React render here
|
|
137
|
+
// visibly juddered the host page).
|
|
138
|
+
const levels = audioLevelsRef.current;
|
|
139
|
+
for (let i = 0; i < barsCount; i++) {
|
|
58
140
|
const position = i / barsCount; // 0 to 1 from left to right
|
|
59
141
|
const wavePhase = Date.now() / 300 + position * Math.PI * 2;
|
|
60
142
|
const waveVariation = Math.sin(wavePhase) * 0.15 + 0.85; // 0.7 to 1.0
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
143
|
+
levels[i] = volume * waveVariation;
|
|
144
|
+
}
|
|
145
|
+
drawWaves();
|
|
64
146
|
animationFrameRef.current = requestAnimationFrame(updateLevels);
|
|
65
147
|
};
|
|
66
148
|
updateLevels();
|
|
@@ -200,45 +282,7 @@ export const VoiceModeOverlay = ({ isActive, isTalking, isListening = false, con
|
|
|
200
282
|
width: "250px",
|
|
201
283
|
height: "80px",
|
|
202
284
|
position: "relative",
|
|
203
|
-
}, children: _jsx("
|
|
204
|
-
overflow: "visible",
|
|
205
|
-
}, children: [0, 1, 2].map((waveIndex) => {
|
|
206
|
-
// Calculate wave path based on audio levels
|
|
207
|
-
const points = [];
|
|
208
|
-
const centerY = 40;
|
|
209
|
-
const waveWidth = 250;
|
|
210
|
-
const segments = barsCount;
|
|
211
|
-
// Calculate average audio level for glow intensity
|
|
212
|
-
const avgLevel = audioLevels.reduce((sum, level) => sum + level, 0) / audioLevels.length;
|
|
213
|
-
const glowIntensity = avgLevel * 35; // 0-35px glow (increased from 20)
|
|
214
|
-
// Green color variants for each wave
|
|
215
|
-
const waveColors = [
|
|
216
|
-
aeroTheme.colors.convai.light, // Bright green - front wave
|
|
217
|
-
aeroTheme.colors.convai.light, // Medium green - mid wave
|
|
218
|
-
"#34d399", // Medium-light green - back wave (lighter than dark)
|
|
219
|
-
];
|
|
220
|
-
for (let i = 0; i <= segments; i++) {
|
|
221
|
-
const x = (i / segments) * waveWidth;
|
|
222
|
-
const levelIndex = Math.floor((i / segments) * (audioLevels.length - 1));
|
|
223
|
-
const level = audioLevels[levelIndex] || 0;
|
|
224
|
-
// When idle (low audio), show straight line
|
|
225
|
-
// When active, create waves with increased amplitude
|
|
226
|
-
const phase = (Date.now() / 500 + i * 0.2 + waveIndex * 1.5) % (Math.PI * 2);
|
|
227
|
-
// Only add wave motion when there's audio
|
|
228
|
-
// Idle: amplitude ~0 (straight line)
|
|
229
|
-
// Active: amplitude up to 25px (increased from 15)
|
|
230
|
-
const baseAmplitude = avgLevel > 0.05 ? (2 + waveIndex * 1.5) : 0;
|
|
231
|
-
const amplitude = baseAmplitude + level * (25 - baseAmplitude);
|
|
232
|
-
const y = centerY + Math.sin(phase) * amplitude;
|
|
233
|
-
points.push(`${x},${y}`);
|
|
234
|
-
}
|
|
235
|
-
return (_jsx(motion.path, { d: `M ${points.join(" L ")}`, fill: "none", stroke: waveColors[waveIndex], strokeWidth: 2.5 - waveIndex * 0.4, strokeLinecap: "round", strokeLinejoin: "round", opacity: 0.95 - waveIndex * 0.15, animate: {
|
|
236
|
-
filter: `drop-shadow(0 0 ${glowIntensity}px ${waveColors[waveIndex]}) blur(${waveIndex * 0.3}px)`,
|
|
237
|
-
}, transition: {
|
|
238
|
-
duration: 0.1,
|
|
239
|
-
ease: "easeOut",
|
|
240
|
-
} }, waveIndex));
|
|
241
|
-
}) }) })) }), _jsxs(motion.div, { initial: { opacity: 0, y: 10 }, animate: { opacity: 1, y: 0 }, transition: { delay: 0.2, ...iosTransitions.fadePop }, children: [_jsx("div", { style: {
|
|
285
|
+
}, children: _jsx("canvas", { ref: waveCanvasRef, style: { width: "250px", height: "80px" } }) })) }), _jsxs(motion.div, { initial: { opacity: 0, y: 10 }, animate: { opacity: 1, y: 0 }, transition: { delay: 0.2, ...iosTransitions.fadePop }, children: [_jsx("div", { style: {
|
|
242
286
|
fontSize: "16px",
|
|
243
287
|
fontWeight: 600,
|
|
244
288
|
color: aeroTheme.colors.text.primary,
|