@convai/web-widget 0.1.4 → 0.2.0
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 +55 -11
- package/chunks/lightbox-Dxfdw3VU.js +683 -0
- package/index.d.ts +26 -0
- package/index.js +4 -0
- package/package.json +53 -2
- package/react.d.ts +23 -0
- package/react.js +3551 -0
- package/runtime.js +12588 -18085
- package/types.d.ts +62 -0
- package/ui/react/components/ConvaiWidget.d.ts +86 -0
- package/ui/react/components/index.d.ts +1 -0
- package/ui/react/components/rtc-widget/components/AudioSettingsPanel.d.ts +9 -0
- package/ui/react/components/rtc-widget/components/AudioVisualizer.d.ts +35 -0
- package/ui/react/components/rtc-widget/components/ConviMessage.d.ts +13 -0
- package/ui/react/components/rtc-widget/components/FloatingVideo.d.ts +8 -0
- package/ui/react/components/rtc-widget/components/MarkdownRenderer.d.ts +31 -0
- package/ui/react/components/rtc-widget/components/MessageBubble.d.ts +9 -0
- package/ui/react/components/rtc-widget/components/MessageList.d.ts +14 -0
- package/ui/react/components/rtc-widget/components/SiteCard.d.ts +15 -0
- package/ui/react/components/rtc-widget/components/UserMessage.d.ts +9 -0
- package/ui/react/components/rtc-widget/components/conviComponents/ConviButton.d.ts +6 -0
- package/ui/react/components/rtc-widget/components/conviComponents/ConviFooter.d.ts +24 -0
- package/ui/react/components/rtc-widget/components/conviComponents/ConviHeader.d.ts +16 -0
- package/ui/react/components/rtc-widget/components/conviComponents/SettingsTray.d.ts +12 -0
- package/ui/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts +14 -0
- package/ui/react/components/rtc-widget/components/conviComponents/index.d.ts +5 -0
- package/ui/react/components/rtc-widget/components/index.d.ts +8 -0
- package/ui/react/components/rtc-widget/index.d.ts +5 -0
- package/ui/react/components/rtc-widget/styles/framerConfig.d.ts +115 -0
- package/ui/react/components/rtc-widget/styles/icons.d.ts +27 -0
- package/ui/react/components/rtc-widget/styles/index.d.ts +5 -0
- package/ui/react/components/rtc-widget/styles/styledComponents.d.ts +53 -0
- package/ui/react/components/rtc-widget/styles/theme.d.ts +187 -0
- package/ui/react/components/rtc-widget/types/index.d.ts +59 -0
- package/ui/react/hooks/useCharacterInfo.d.ts +18 -0
- package/ui/react/hooks/useLocalCameraTrack.d.ts +21 -0
- package/ui/react/icons.d.ts +37 -0
- package/ui/shared/lightbox.d.ts +15 -0
- package/ui/shared/linkStyles.d.ts +64 -0
- package/ui/shared/logger.d.ts +30 -0
- package/ui/vanilla/ConvaiWidget.d.ts +46 -0
- package/ui/vanilla/WidgetEventSubscriptions.d.ts +14 -0
- package/ui/vanilla/icons.d.ts +34 -0
- package/ui/vanilla/styles.d.ts +168 -0
- package/ui/vanilla/types.d.ts +170 -0
- package/vanilla.d.ts +21 -0
- package/vanilla.js +2512 -0
package/vanilla.js
ADDED
|
@@ -0,0 +1,2512 @@
|
|
|
1
|
+
import { AudioRenderer } from "@convai/web-sdk/vanilla";
|
|
2
|
+
import { a as injectGlobalStyles, i as injectKeyframes, b as aeroTheme, M as MAX_CARDS_PER_MESSAGE, g as glyph, t as toCssText, p as presentationStyles, P as PREVIEW_TIMEOUT_MS, o as openLightbox } from "./chunks/lightbox-Dxfdw3VU.js";
|
|
3
|
+
import { ConvaiClient, fetchCharacterInfo, parseInlineMarkdown, linkKindForUrl, hoverTitle, contactLabel, compactUrl, resolveLinkPreviewCached, isCardWorthy, faviconFor, siteNameFor, documentBadge, fileNameOf, isMixedContent, describeUrl } from "@convai/web-sdk/core";
|
|
4
|
+
import { freshPublicationGrantOptions } from "@convai/web-sdk/embed";
|
|
5
|
+
const iconSizes = {
|
|
6
|
+
xs: "12px",
|
|
7
|
+
sm: "16px",
|
|
8
|
+
md: "20px",
|
|
9
|
+
lg: "24px",
|
|
10
|
+
xl: "32px",
|
|
11
|
+
"2xl": "40px"
|
|
12
|
+
};
|
|
13
|
+
const secondStripColors = {
|
|
14
|
+
idle: "#1EB453",
|
|
15
|
+
connecting: "#f59e0b",
|
|
16
|
+
connected: "#1EB453",
|
|
17
|
+
disconnected: "#ef4444",
|
|
18
|
+
typing: "#8b5cf6",
|
|
19
|
+
listening: "#3b82f6",
|
|
20
|
+
processing: "#6366f1"
|
|
21
|
+
};
|
|
22
|
+
function createSVG(size, viewBox, paths, className) {
|
|
23
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
24
|
+
const sizeValue = iconSizes[size];
|
|
25
|
+
svg.setAttribute("width", sizeValue);
|
|
26
|
+
svg.setAttribute("height", sizeValue);
|
|
27
|
+
svg.setAttribute("viewBox", viewBox);
|
|
28
|
+
svg.setAttribute("fill", "none");
|
|
29
|
+
svg.setAttribute("stroke", "currentColor");
|
|
30
|
+
svg.setAttribute("stroke-width", "2");
|
|
31
|
+
svg.setAttribute("stroke-linecap", "round");
|
|
32
|
+
svg.setAttribute("stroke-linejoin", "round");
|
|
33
|
+
if (className) {
|
|
34
|
+
svg.className.baseVal = className;
|
|
35
|
+
}
|
|
36
|
+
paths.forEach((pathData) => {
|
|
37
|
+
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
38
|
+
path.setAttribute("d", pathData);
|
|
39
|
+
svg.appendChild(path);
|
|
40
|
+
});
|
|
41
|
+
return svg;
|
|
42
|
+
}
|
|
43
|
+
function createFilledSVG(size, viewBox, paths, className) {
|
|
44
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
45
|
+
const sizeValue = iconSizes[size];
|
|
46
|
+
svg.setAttribute("width", sizeValue);
|
|
47
|
+
svg.setAttribute("height", sizeValue);
|
|
48
|
+
svg.setAttribute("viewBox", viewBox);
|
|
49
|
+
svg.setAttribute("fill", "currentColor");
|
|
50
|
+
if (className) {
|
|
51
|
+
svg.className.baseVal = className;
|
|
52
|
+
}
|
|
53
|
+
paths.forEach((pathConfig) => {
|
|
54
|
+
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
55
|
+
path.setAttribute("d", pathConfig.d);
|
|
56
|
+
if (pathConfig.fill) {
|
|
57
|
+
path.setAttribute("fill", pathConfig.fill);
|
|
58
|
+
}
|
|
59
|
+
if (pathConfig.transform) {
|
|
60
|
+
path.setAttribute("transform", pathConfig.transform);
|
|
61
|
+
}
|
|
62
|
+
if (pathConfig.stroke) {
|
|
63
|
+
path.setAttribute("stroke", pathConfig.stroke);
|
|
64
|
+
}
|
|
65
|
+
if (pathConfig.strokeWidth) {
|
|
66
|
+
path.setAttribute("stroke-width", pathConfig.strokeWidth);
|
|
67
|
+
}
|
|
68
|
+
if (pathConfig.strokeLinecap) {
|
|
69
|
+
path.setAttribute("stroke-linecap", pathConfig.strokeLinecap);
|
|
70
|
+
}
|
|
71
|
+
if (pathConfig.strokeMiterlimit) {
|
|
72
|
+
path.setAttribute("stroke-miterlimit", pathConfig.strokeMiterlimit);
|
|
73
|
+
}
|
|
74
|
+
svg.appendChild(path);
|
|
75
|
+
});
|
|
76
|
+
return svg;
|
|
77
|
+
}
|
|
78
|
+
const Icons = {
|
|
79
|
+
// Convai Logo - exact copy from React example
|
|
80
|
+
ConvaiLogo: (size = "md", state = "idle", className) => {
|
|
81
|
+
return createFilledSVG(
|
|
82
|
+
size,
|
|
83
|
+
"0 0 384 384",
|
|
84
|
+
[
|
|
85
|
+
// First strip - Main body (always original green)
|
|
86
|
+
{
|
|
87
|
+
d: "M0 0 C0.69959839 -0.0065712 1.39919678 -0.0131424 2.11999512 -0.01991272 C4.43522251 -0.03962096 6.75038501 -0.05130455 9.06567383 -0.0612793 C9.85831446 -0.06535482 10.65095509 -0.06943035 11.46761513 -0.07362938 C15.66541914 -0.0944825 19.86319057 -0.10878583 24.06103516 -0.11816406 C28.38410215 -0.12920936 32.70665171 -0.16358924 37.02953625 -0.20333576 C40.36427221 -0.22956171 43.69888619 -0.23786131 47.0337162 -0.24144554 C48.62643224 -0.24629839 50.21914331 -0.2578751 51.81175804 -0.27648354 C69.26930263 -0.46773456 69.26930263 -0.46773456 75.58610535 5.6245575 C80.21645647 10.85588298 81.33540199 14.49016989 81.35986328 21.4206543 C81.36497421 22.14311844 81.37008514 22.86558258 81.37535095 23.60993958 C81.38923214 25.99435754 81.38829113 28.37848592 81.38598633 30.76293945 C81.38987448 32.42436836 81.39420939 34.08579627 81.39897156 35.7472229 C81.40643089 39.22905703 81.40614488 42.71078976 81.40087891 46.19262695 C81.39508893 50.64694813 81.41200506 55.10085286 81.43522358 59.55510521 C81.44998192 62.98670871 81.4508297 66.41821245 81.44771385 69.84984207 C81.44822615 71.49163258 81.45344672 73.1334288 81.46352577 74.77518845 C81.47591195 77.07525124 81.46908575 79.37450987 81.45751953 81.67456055 C81.45814896 82.981539 81.45877838 84.28851746 81.45942688 85.63510132 C80.84254452 91.47371365 78.52732357 95.26249723 74.08520508 98.98950195 C73.40458008 99.57344727 72.72395508 100.15739258 72.02270508 100.7590332 C68.47350615 103.35653161 65.36290965 103.30519544 61.10424805 103.31884766 C59.87221649 103.32588211 58.64018494 103.33291656 57.37081909 103.34016418 C56.7124493 103.34198008 56.05407951 103.34379597 55.37575912 103.34566689 C53.30624131 103.35285669 51.23695729 103.36854441 49.16751099 103.38700867 C43.28366424 103.43934056 37.3999433 103.4873775 31.51586914 103.50292969 C27.91355676 103.5130737 24.3118307 103.54256243 20.70975113 103.5842495 C19.34402042 103.59647838 17.97820656 103.60169572 16.61242294 103.59945107 C8.73090231 103.58969075 1.87263728 103.81383569 -4.91479492 108.17700195 C-7.72384754 111.13052013 -9.15477197 114.52324306 -10.91479492 118.17700195 C-11.28512344 118.93435638 -11.65545197 119.69171082 -12.03700256 120.47201538 C-16.07726993 130.41632989 -15.43823163 140.76281367 -15.37008476 151.32646561 C-15.34801891 154.90096301 -15.35197296 158.47462262 -15.36256409 162.04916382 C-15.38412577 170.92003422 -15.36687668 179.79071265 -15.34106445 188.66156006 C-15.31962039 196.17710783 -15.31776573 203.69211414 -15.34398079 211.20765305 C-15.34831203 214.71647808 -15.32375642 218.22434564 -15.29844666 221.73306274 C-15.30371999 223.89748554 -15.31044419 226.06190545 -15.31884766 228.22631836 C-15.30393784 229.19074356 -15.28902802 230.15516876 -15.27366638 231.14881897 C-15.34508206 238.01141921 -16.9480351 243.5040945 -20.91479492 249.17700195 C-26.0538927 253.49142781 -30.93587496 255.28530317 -37.61843872 255.3309021 C-38.56028519 255.33950256 -39.50213165 255.34810303 -40.47251892 255.35696411 C-41.49906082 255.36122406 -42.52560272 255.36548401 -43.58325195 255.36987305 C-44.66992661 255.37805054 -45.75660126 255.38622803 -46.87620544 255.39465332 C-50.47500054 255.41947905 -54.07375621 255.43601739 -57.67260742 255.45043945 C-58.90313717 255.45576313 -60.13366692 255.46108681 -61.40148544 255.46657181 C-67.24488135 255.49053877 -73.08826109 255.5097802 -78.93169224 255.52259386 C-84.98841103 255.53614167 -91.04475988 255.56242227 -97.10131836 255.60913086 C-103.60933706 255.65850314 -110.11701183 255.68322666 -116.62520981 255.69032669 C-119.10105009 255.69703038 -121.57688297 255.71222923 -124.05261612 255.7362175 C-127.52547148 255.76794397 -130.99700762 255.7678936 -134.4699707 255.76049805 C-135.48436722 255.77690338 -136.49876373 255.79330872 -137.54389954 255.81021118 C-144.58516525 255.74911945 -150.0594436 254.18666177 -155.91479492 250.17700195 C-160.11922437 245.7740819 -162.02935988 241.44006577 -162.06869507 235.39033508 C-162.08159576 233.91218575 -162.08159576 233.91218575 -162.09475708 232.4041748 C-162.09901703 231.32414185 -162.10327698 230.24410889 -162.10766602 229.13134766 C-162.11584351 227.99283859 -162.124021 226.85432953 -162.13244629 225.68132019 C-162.15730395 221.90514656 -162.17381777 218.12901055 -162.18823242 214.3527832 C-162.1935561 213.06367727 -162.19887978 211.77457134 -162.20436478 210.4464016 C-162.22559522 205.02735272 -162.24472449 199.60831609 -162.25598717 194.18923664 C-162.27221051 186.43543753 -162.30535181 178.68214076 -162.36238801 170.92853099 C-162.40584504 164.81123062 -162.42174109 158.6941264 -162.42811966 152.57668114 C-162.43483541 149.9791729 -162.45006568 147.38167207 -162.47401047 144.78426552 C-162.50563862 141.14566586 -162.50570126 137.50833002 -162.49829102 133.86962891 C-162.51469635 132.7997171 -162.53110168 131.7298053 -162.54800415 130.62747192 C-162.49171427 123.86379339 -161.30224231 119.40867493 -156.91479492 114.17700195 C-150.70048633 108.27340879 -145.09496666 107.88810653 -136.89892578 107.9375 C-135.89334625 107.93548584 -134.88776672 107.93347168 -133.85171509 107.93139648 C-131.67026481 107.92785441 -129.48880427 107.92861384 -127.30735588 107.93317223 C-123.84643147 107.93877446 -120.38584111 107.92958995 -116.92494202 107.91596985 C-107.08536336 107.87889048 -97.24589659 107.86026615 -87.40625 107.87158203 C-81.38322548 107.87745814 -75.36066903 107.85904709 -69.33773994 107.82569313 C-67.05060701 107.81777476 -64.76342257 107.81896733 -62.47630119 107.82971764 C-43.45245929 108.09017669 -43.45245929 108.09017669 -26.78979492 99.73950195 C-23.10917107 94.70931602 -22.66695746 89.8832171 -22.67529297 83.76977539 C-22.67327881 83.05344437 -22.67126465 82.33711334 -22.66918945 81.59907532 C-22.66565984 80.05224746 -22.66639133 78.50540513 -22.67096519 76.95858002 C-22.67659236 74.50202502 -22.66734352 72.0459363 -22.65376282 69.5894165 C-22.61678347 62.60801088 -22.59805845 55.62676468 -22.609375 48.64526367 C-22.61525918 44.36517663 -22.59680667 40.08574677 -22.5634861 35.80579376 C-22.55558359 34.18408293 -22.55673851 32.56229947 -22.5675106 30.94060516 C-22.62477994 21.92945939 -22.61028477 13.70058716 -16.91479492 6.17700195 C-11.68775031 1.25109893 -7.03157131 0.05467437 0 0 Z",
|
|
88
|
+
fill: "#1EB453",
|
|
89
|
+
transform: "translate(275.914794921875,92.822998046875)"
|
|
90
|
+
},
|
|
91
|
+
// Second strip - Accent (dynamic colors based on state)
|
|
92
|
+
{
|
|
93
|
+
d: "M0 0 C0.70949799 -0.0065712 1.41899597 -0.0131424 2.1499939 -0.01991272 C4.49224974 -0.03958252 6.83444162 -0.05129463 9.17675781 -0.0612793 C9.97951393 -0.06535482 10.78227005 -0.06943035 11.60935211 -0.07362938 C15.85903157 -0.09446397 20.10867901 -0.10877652 24.35839844 -0.11816406 C28.73412049 -0.12921848 33.10933265 -0.16361435 37.48487473 -0.20333576 C40.86164252 -0.22955602 44.23828982 -0.2378607 47.61515045 -0.24144554 C49.22740367 -0.24629814 50.83965199 -0.25787412 52.45180511 -0.27648354 C61.87754315 -0.37851798 69.22600258 -0.40722527 76.90332031 5.81762695 C77.34933594 6.3487207 77.79535156 6.87981445 78.25488281 7.42700195 C78.94710937 8.20817383 78.94710937 8.20817383 79.65332031 9.00512695 C84.02596265 16.74776753 83.1900497 25.91727112 83.18066406 34.5168457 C83.18455855 36.00842913 83.18889475 37.50001147 83.19364929 38.99159241 C83.20108066 42.10738735 83.20084254 45.22306892 83.19555664 48.33886719 C83.189763 52.31076588 83.20670518 56.28219809 83.22990131 60.25401974 C83.24470727 63.33145309 83.24550113 66.40877581 83.24239159 69.48623848 C83.24290125 70.94971198 83.24807164 72.41319226 83.25820351 73.87663078 C83.37438765 93.0006229 83.37438765 93.0006229 77.12988281 100.05200195 C76.68128906 100.58567383 76.23269531 101.1193457 75.77050781 101.66918945 C70.71771348 105.69889733 65.71373184 106.5516213 59.38745117 106.56176758 C58.67430252 106.56714035 57.96115387 106.57251312 57.22639465 106.57804871 C55.69051241 106.58777157 54.15457559 106.5907876 52.6186657 106.58769226 C50.18403577 106.58318589 47.75012185 106.59729184 45.31556702 106.61608887 C39.27289347 106.65895188 33.23023785 106.67011114 27.18743896 106.68231201 C22.07081894 106.69385979 16.95452773 106.71746947 11.83804512 106.75700378 C9.4460817 106.7705322 7.05456878 106.76641182 4.6625824 106.76159668 C3.1893558 106.77094038 1.71613413 106.78110998 0.24291992 106.79223633 C-1.03724503 106.79429077 -2.31740997 106.79634521 -3.6363678 106.79846191 C-7.41637293 107.20919275 -9.82064532 108.34953123 -13.12011719 110.17700195 C-13.78011719 110.17700195 -14.44011719 110.17700195 -15.12011719 110.17700195 C-17.52280099 115.83889015 -17.41598579 121.16057712 -17.42871094 127.20043945 C-17.45386958 129.37752548 -17.47926763 131.55460875 -17.50488281 133.73168945 C-17.53360338 137.14379163 -17.55763834 140.55584604 -17.57641602 143.96801758 C-17.59814672 147.27490607 -17.63758849 150.58124339 -17.67871094 153.88793945 C-17.67882675 154.89964203 -17.67894257 155.9113446 -17.67906189 156.95370483 C-17.7841159 164.52274898 -19.03497091 169.98795471 -23.24511719 176.42700195 C-29.45623238 182.36806866 -36.31490332 183.78705333 -44.68652344 183.6730957 C-46.00401833 183.67527855 -46.00401833 183.67527855 -47.34812927 183.67750549 C-49.19102319 183.67585714 -51.03393241 183.66441631 -52.87670898 183.64355469 C-55.67914918 183.61453786 -58.47969965 183.62298099 -61.28222656 183.63598633 C-63.08366794 183.62974909 -64.88510341 183.62135826 -66.68652344 183.6105957 C-67.51382462 183.61353134 -68.34112579 183.61646698 -69.1934967 183.61949158 C-75.59165864 183.51691869 -81.40132888 182.53204156 -86.39746094 178.2043457 C-86.9453125 177.51469727 -87.49316406 176.82504883 -88.05761719 176.11450195 C-88.62351562 175.42227539 -89.18941406 174.73004883 -89.77246094 174.0168457 C-91.95579877 171.03611492 -92.25725067 169.22772898 -92.31298828 165.57885742 C-92.32905121 164.62381317 -92.34511414 163.66876892 -92.36166382 162.68478394 C-92.40618833 158.30003565 -92.44720831 153.91543939 -92.47021484 149.53051758 C-92.48674024 147.22214655 -92.51398466 144.91382596 -92.55224609 142.60571289 C-92.60721123 139.27243575 -92.62892302 135.94035974 -92.64355469 132.60668945 C-92.66622406 131.58243866 -92.68889343 130.55818787 -92.71224976 129.50289917 C-92.69275809 122.84191599 -91.55490715 118.27254494 -87.12011719 113.17700195 C-82.85713484 109.85187572 -79.42315905 108.06794719 -74.01928711 108.01928711 C-73.19800827 108.00902496 -72.37672943 107.99876282 -71.53056335 107.9881897 C-70.64617081 107.98088837 -69.76177826 107.97358704 -68.85058594 107.96606445 C-66.97362414 107.93799282 -65.09667113 107.90932834 -63.21972656 107.88012695 C-60.26391881 107.83890024 -57.30827464 107.80200782 -54.35229492 107.77563477 C-51.49721474 107.74795955 -48.64287792 107.70208605 -45.78808594 107.65356445 C-44.47060616 107.64868515 -44.47060616 107.64868515 -43.12651062 107.64370728 C-38.07403193 107.54295109 -34.47561603 107.02250373 -30.12011719 104.17700195 C-28.38692337 101.61731491 -28.38692337 101.61731491 -27.30761719 98.67700195 C-26.90929687 97.71793945 -26.51097656 96.75887695 -26.10058594 95.77075195 C-24.41267145 91.30551203 -23.99587525 87.9866657 -23.99414062 83.20214844 C-23.99227249 82.49600906 -23.99040436 81.78986969 -23.98847961 81.06233215 C-23.9844771 79.52854718 -23.98240091 77.99475626 -23.98201752 76.46096611 C-23.97859338 73.18930997 -23.95721325 69.91785101 -23.93678665 66.64626408 C-23.89884548 60.55842138 -23.86749302 54.47078699 -23.86962891 48.3828125 C-23.87042015 44.14504806 -23.84687404 39.90800348 -23.80774689 35.67042732 C-23.79734392 34.06268623 -23.79572049 32.45486145 -23.80339813 30.84710503 C-23.84202858 21.8556044 -23.77030332 13.69524181 -18.12011719 6.17700195 C-12.50415323 0.77468343 -7.52615394 0.05781024 0 0 Z",
|
|
94
|
+
fill: secondStripColors[state],
|
|
95
|
+
transform: "translate(92.1201171875,53.822998046875)"
|
|
96
|
+
},
|
|
97
|
+
// Additional detail paths
|
|
98
|
+
{
|
|
99
|
+
d: "M0 0 C0.66 0.33 1.32 0.66 2 1 C0.90033225 2.29549899 -0.20491801 3.58626071 -1.3125 4.875 C-1.92738281 5.59429687 -2.54226563 6.31359375 -3.17578125 7.0546875 C-5 9 -5 9 -8 11 C-6.60366572 6.55711819 -4.39598172 4.13475236 -1 1 C-0.67 0.67 -0.34 0.34 0 0 Z",
|
|
100
|
+
fill: "currentColor",
|
|
101
|
+
transform: "translate(264,95)"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
d: "M0 0 C0.66 0.33 1.32 0.66 2 1 C-0.64 3.64 -3.28 6.28 -6 9 C-6 6 -6 6 -3.5625 3.375 C-2.716875 2.59125 -1.87125 1.8075 -1 1 C-0.67 0.67 -0.34 0.34 0 0 Z",
|
|
105
|
+
fill: "currentColor",
|
|
106
|
+
transform: "translate(79,56)"
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
className
|
|
110
|
+
);
|
|
111
|
+
},
|
|
112
|
+
// ChevronDown - from Feather Icons (react-icons/fi)
|
|
113
|
+
ChevronDown: (size = "md", className) => {
|
|
114
|
+
return createSVG(size, "0 0 24 24", ["M6 9l6 6 6-6"], className);
|
|
115
|
+
},
|
|
116
|
+
// Close - IoClose from react-icons/io5
|
|
117
|
+
Close: (size = "md", className) => {
|
|
118
|
+
return createSVG(size, "0 0 24 24", ["M18 6L6 18M6 6l12 12"], className);
|
|
119
|
+
},
|
|
120
|
+
// Send - FiSend from react-icons/fi
|
|
121
|
+
Send: (size = "md", className) => {
|
|
122
|
+
return createSVG(size, "0 0 24 24", ["M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"], className);
|
|
123
|
+
},
|
|
124
|
+
// Microphone - FiMic from react-icons/fi
|
|
125
|
+
Mic: (size = "md", className) => {
|
|
126
|
+
return createSVG(
|
|
127
|
+
size,
|
|
128
|
+
"0 0 24 24",
|
|
129
|
+
[
|
|
130
|
+
"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z",
|
|
131
|
+
"M19 10v2a7 7 0 0 1-14 0v-2",
|
|
132
|
+
"M12 19v4M8 23h8"
|
|
133
|
+
],
|
|
134
|
+
className
|
|
135
|
+
);
|
|
136
|
+
},
|
|
137
|
+
// Waveform - PiWaveform from react-icons/pi (Phosphor). The previous
|
|
138
|
+
// version was a hand-drawn 6-bar stroke icon on a 24x24 grid; the real
|
|
139
|
+
// PiWaveform is a single filled path with 5 bars on Phosphor's 256x256
|
|
140
|
+
// grid. Source: node_modules/react-icons/pi/index.js, PiWaveform.
|
|
141
|
+
Waveform: (size = "md", className) => {
|
|
142
|
+
return createFilledSVG(
|
|
143
|
+
size,
|
|
144
|
+
"0 0 256 256",
|
|
145
|
+
[
|
|
146
|
+
{
|
|
147
|
+
d: "M56,96v64a8,8,0,0,1-16,0V96a8,8,0,0,1,16,0ZM88,24a8,8,0,0,0-8,8V224a8,8,0,0,0,16,0V32A8,8,0,0,0,88,24Zm40,32a8,8,0,0,0-8,8V192a8,8,0,0,0,16,0V64A8,8,0,0,0,128,56Zm40,32a8,8,0,0,0-8,8v64a8,8,0,0,0,16,0V96A8,8,0,0,0,168,88Zm40-16a8,8,0,0,0-8,8v96a8,8,0,0,0,16,0V80A8,8,0,0,0,208,72Z"
|
|
148
|
+
}
|
|
149
|
+
],
|
|
150
|
+
className
|
|
151
|
+
);
|
|
152
|
+
},
|
|
153
|
+
// Phone Off - FiPhoneOff from react-icons/fi
|
|
154
|
+
PhoneOff: (size = "md", className) => {
|
|
155
|
+
return createSVG(
|
|
156
|
+
size,
|
|
157
|
+
"0 0 24 24",
|
|
158
|
+
[
|
|
159
|
+
"M10.68 13.31a16 16 0 0 0 3.41 2.6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7 2 2 0 0 1 1.72 2v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.42 19.42 0 0 1-3.33-2.67m-2.67-3.34a19.79 19.79 0 0 1-3.07-8.63A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91",
|
|
160
|
+
"M23 1L1 23"
|
|
161
|
+
],
|
|
162
|
+
className
|
|
163
|
+
);
|
|
164
|
+
},
|
|
165
|
+
// Video Camera - IoVideocam from react-icons/io5
|
|
166
|
+
Video: (size = "md", className) => {
|
|
167
|
+
return createSVG(
|
|
168
|
+
size,
|
|
169
|
+
"0 0 24 24",
|
|
170
|
+
["M23 7l-7 5 7 5V7zM16 5H2C.9 5 0 5.9 0 7v10c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2z"],
|
|
171
|
+
className
|
|
172
|
+
);
|
|
173
|
+
},
|
|
174
|
+
// Video Camera Off - IoVideocamOff from react-icons/io5
|
|
175
|
+
VideoOff: (size = "md", className) => {
|
|
176
|
+
return createSVG(
|
|
177
|
+
size,
|
|
178
|
+
"0 0 24 24",
|
|
179
|
+
[
|
|
180
|
+
"M1 1l22 22M16 16v1a2 2 0 01-2 2H3a2 2 0 01-2-2V7a2 2 0 012-2h2m5.66 0H14a2 2 0 012 2v3.34l1 1L23 7v10"
|
|
181
|
+
],
|
|
182
|
+
className
|
|
183
|
+
);
|
|
184
|
+
},
|
|
185
|
+
// Volume Mute - IoVolumeMute from react-icons/io5 (Ionicons). The previous
|
|
186
|
+
// version was a hand-drawn Feather-style "volume-x" glyph on a 24x24 grid;
|
|
187
|
+
// the real IoVolumeMute lives on Ionicons' 512x512 grid and mixes two
|
|
188
|
+
// filled paths with one stroked diagonal slash. Source:
|
|
189
|
+
// node_modules/react-icons/io5/index.js, IoVolumeMute.
|
|
190
|
+
VolumeMute: (size = "md", className) => {
|
|
191
|
+
return createFilledSVG(
|
|
192
|
+
size,
|
|
193
|
+
"0 0 512 512",
|
|
194
|
+
[
|
|
195
|
+
{
|
|
196
|
+
d: "M416 432 64 80",
|
|
197
|
+
fill: "none",
|
|
198
|
+
stroke: "currentColor",
|
|
199
|
+
strokeWidth: "32",
|
|
200
|
+
strokeLinecap: "round",
|
|
201
|
+
strokeMiterlimit: "10"
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
d: "M243.33 98.86a23.89 23.89 0 0 0-25.55 1.82l-.66.51-28.52 23.35a8 8 0 0 0-.59 11.85l54.33 54.33a8 8 0 0 0 13.66-5.66v-64.49a24.51 24.51 0 0 0-12.67-21.71zm8 236.43L96.69 180.69A16 16 0 0 0 85.38 176H56a24 24 0 0 0-24 24v112a24 24 0 0 0 24 24h69.76l92 75.31a23.9 23.9 0 0 0 25.87 1.69A24.51 24.51 0 0 0 256 391.45v-44.86a16 16 0 0 0-4.67-11.3zM352 256c0-24.56-5.81-47.87-17.75-71.27a16 16 0 1 0-28.5 14.55C315.34 218.06 320 236.62 320 256q0 4-.31 8.13a8 8 0 0 0 2.32 6.25l14.36 14.36a8 8 0 0 0 13.55-4.31A146 146 0 0 0 352 256zm64 0c0-51.18-13.08-83.89-34.18-120.06a16 16 0 0 0-27.64 16.12C373.07 184.44 384 211.83 384 256c0 23.83-3.29 42.88-9.37 60.65a8 8 0 0 0 1.9 8.26L389 337.4a8 8 0 0 0 13.13-2.79C411 311.76 416 287.26 416 256z"
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
d: "M480 256c0-74.25-20.19-121.11-50.51-168.61a16 16 0 1 0-27 17.22C429.82 147.38 448 189.5 448 256c0 46.19-8.43 80.27-22.43 110.53a8 8 0 0 0 1.59 9l11.92 11.92a8 8 0 0 0 12.92-2.16C471.6 344.9 480 305 480 256z"
|
|
208
|
+
}
|
|
209
|
+
],
|
|
210
|
+
className
|
|
211
|
+
);
|
|
212
|
+
},
|
|
213
|
+
// Volume High - IoVolumeHigh from react-icons/io5 (Ionicons). Same
|
|
214
|
+
// grid/source mismatch as VolumeMute above: the previous version was a
|
|
215
|
+
// hand-drawn 24x24 Feather-style "volume-2" glyph. The real IoVolumeHigh
|
|
216
|
+
// is three filled paths on a 512x512 grid, no stroke. Source:
|
|
217
|
+
// node_modules/react-icons/io5/index.js, IoVolumeHigh.
|
|
218
|
+
VolumeHigh: (size = "md", className) => {
|
|
219
|
+
return createFilledSVG(
|
|
220
|
+
size,
|
|
221
|
+
"0 0 512 512",
|
|
222
|
+
[
|
|
223
|
+
{
|
|
224
|
+
d: "M232 416a23.88 23.88 0 0 1-14.2-4.68 8.27 8.27 0 0 1-.66-.51L125.76 336H56a24 24 0 0 1-24-24V200a24 24 0 0 1 24-24h69.75l91.37-74.81a8.27 8.27 0 0 1 .66-.51A24 24 0 0 1 256 120v272a24 24 0 0 1-24 24zm-106.18-80zm-.27-159.86zM320 336a16 16 0 0 1-14.29-23.19c9.49-18.87 14.3-38 14.3-56.81 0-19.38-4.66-37.94-14.25-56.73a16 16 0 0 1 28.5-14.54C346.19 208.12 352 231.44 352 256c0 23.86-6 47.81-17.7 71.19A16 16 0 0 1 320 336z"
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
d: "M368 384a16 16 0 0 1-13.86-24C373.05 327.09 384 299.51 384 256c0-44.17-10.93-71.56-29.82-103.94a16 16 0 0 1 27.64-16.12C402.92 172.11 416 204.81 416 256c0 50.43-13.06 83.29-34.13 120a16 16 0 0 1-13.87 8z"
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
d: "M416 432a16 16 0 0 1-13.39-24.74C429.85 365.47 448 323.76 448 256c0-66.5-18.18-108.62-45.49-151.39a16 16 0 1 1 27-17.22C459.81 134.89 480 181.74 480 256c0 64.75-14.66 113.63-50.6 168.74A16 16 0 0 1 416 432z"
|
|
231
|
+
}
|
|
232
|
+
],
|
|
233
|
+
className
|
|
234
|
+
);
|
|
235
|
+
},
|
|
236
|
+
// More Vertical - FiMoreVertical from react-icons/fi
|
|
237
|
+
MoreVertical: (size = "md", className) => {
|
|
238
|
+
const svg = createSVG(size, "0 0 24 24", [], className);
|
|
239
|
+
for (let cy of [12, 5, 19]) {
|
|
240
|
+
const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
241
|
+
circle.setAttribute("cx", "12");
|
|
242
|
+
circle.setAttribute("cy", cy.toString());
|
|
243
|
+
circle.setAttribute("r", "1");
|
|
244
|
+
circle.setAttribute("fill", "currentColor");
|
|
245
|
+
svg.appendChild(circle);
|
|
246
|
+
}
|
|
247
|
+
return svg;
|
|
248
|
+
},
|
|
249
|
+
// Screen Share - MdScreenShare from react-icons/md
|
|
250
|
+
ScreenShare: (size = "md", className) => {
|
|
251
|
+
return createSVG(
|
|
252
|
+
size,
|
|
253
|
+
"0 0 24 24",
|
|
254
|
+
[
|
|
255
|
+
"M20 18c1.1 0 1.99-.9 1.99-2L22 6c0-1.11-.9-2-2-2H4c-1.11 0-2 .89-2 2v10c0 1.1.89 2 2 2H0v2h24v-2h-4zM13 14.47v-2.19c-2.78 0-4.61.85-6 2.72.56-2.67 2.11-5.33 6-5.87V7l4 3.73-4 3.74z"
|
|
256
|
+
],
|
|
257
|
+
className
|
|
258
|
+
);
|
|
259
|
+
},
|
|
260
|
+
// Stop Screen Share - MdStopScreenShare from react-icons/md
|
|
261
|
+
StopScreenShare: (size = "md", className) => {
|
|
262
|
+
return createSVG(
|
|
263
|
+
size,
|
|
264
|
+
"0 0 24 24",
|
|
265
|
+
[
|
|
266
|
+
"M21.22 18.02l2 2H24v-2h-2.78zm-1.13-1.13l1.54 1.54c.15-.34.24-.72.24-1.12L21.88 7c0-1.11-.9-2-2-2H7.8l5.88 5.88L13 12 6.97 6.97 2.39 2.39 1.11 3.67l.8.8c-.01.01-.01.02-.01.02L2 17.33c0 1.11.89 2 1.99 2H0v2h18.13l2.71 2.71 1.27-1.27L2.39 2.39zM7 15.13c.96-1.29 2.13-2.08 3.67-2.46l3.46 3.46H7v-1z"
|
|
267
|
+
],
|
|
268
|
+
className
|
|
269
|
+
);
|
|
270
|
+
},
|
|
271
|
+
// Redo/Refresh - LiaRedoAltSolid from react-icons/lia
|
|
272
|
+
Redo: (size = "md", className) => {
|
|
273
|
+
return createSVG(
|
|
274
|
+
size,
|
|
275
|
+
"0 0 24 24",
|
|
276
|
+
["M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0118.8-4.3M22 12.5a10 10 0 01-18.8 4.2"],
|
|
277
|
+
className
|
|
278
|
+
);
|
|
279
|
+
},
|
|
280
|
+
// Drag Indicator - MdDragIndicator from react-icons/md
|
|
281
|
+
DragIndicator: (size = "md", className) => {
|
|
282
|
+
const svg = createFilledSVG(
|
|
283
|
+
size,
|
|
284
|
+
"0 0 24 24",
|
|
285
|
+
[
|
|
286
|
+
{ d: "M11 18c0 1.1-.9 2-2 2s-2-.9-2-2 .9-2 2-2 2 .9 2 2zm-2-8c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0-6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm6 4c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z" }
|
|
287
|
+
],
|
|
288
|
+
className
|
|
289
|
+
);
|
|
290
|
+
svg.removeAttribute("stroke");
|
|
291
|
+
svg.removeAttribute("stroke-width");
|
|
292
|
+
return svg;
|
|
293
|
+
},
|
|
294
|
+
// User - FaUser from react-icons/fa
|
|
295
|
+
User: (size = "md", className) => {
|
|
296
|
+
return createSVG(
|
|
297
|
+
size,
|
|
298
|
+
"0 0 24 24",
|
|
299
|
+
["M20 21v-2a4 4 0 00-4-4H8a4 4 0 00-4 4v2", "M12 11a4 4 0 100-8 4 4 0 000 8z"],
|
|
300
|
+
className
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
class WidgetEventSubscriptions {
|
|
305
|
+
constructor(isDestroyed) {
|
|
306
|
+
this.isDestroyed = isDestroyed;
|
|
307
|
+
this.unsubscribes = [];
|
|
308
|
+
}
|
|
309
|
+
register(subscribe, listener) {
|
|
310
|
+
if (this.isDestroyed()) return;
|
|
311
|
+
const unsubscribe = subscribe((...args) => {
|
|
312
|
+
if (!this.isDestroyed()) {
|
|
313
|
+
listener(...args);
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
if (typeof unsubscribe !== "function") return;
|
|
317
|
+
if (this.isDestroyed()) {
|
|
318
|
+
unsubscribe();
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
this.unsubscribes.push(unsubscribe);
|
|
322
|
+
}
|
|
323
|
+
unsubscribeAll() {
|
|
324
|
+
for (const unsubscribe of this.unsubscribes.splice(0)) {
|
|
325
|
+
unsubscribe();
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const PLACEMENT_INSET_PX = 24;
|
|
330
|
+
const PLACEMENT_CSS = {
|
|
331
|
+
"bottom-right": `position: fixed; bottom: ${PLACEMENT_INSET_PX}px; right: ${PLACEMENT_INSET_PX}px;`,
|
|
332
|
+
"bottom-left": `position: fixed; bottom: ${PLACEMENT_INSET_PX}px; left: ${PLACEMENT_INSET_PX}px;`,
|
|
333
|
+
"top-right": `position: fixed; top: ${PLACEMENT_INSET_PX}px; right: ${PLACEMENT_INSET_PX}px;`,
|
|
334
|
+
"top-left": `position: fixed; top: ${PLACEMENT_INSET_PX}px; left: ${PLACEMENT_INSET_PX}px;`,
|
|
335
|
+
inline: "position: relative;"
|
|
336
|
+
};
|
|
337
|
+
const PANEL_W_PX = 400;
|
|
338
|
+
const PANEL_H_PX = 600;
|
|
339
|
+
const PANEL_MAX_W = `calc(100dvw - ${PLACEMENT_INSET_PX * 2}px)`;
|
|
340
|
+
const PANEL_MAX_H = `calc(100dvh - ${PLACEMENT_INSET_PX * 2}px)`;
|
|
341
|
+
const MIC_PERMISSION_ERROR_CODE = "mic-permission";
|
|
342
|
+
function isMicPermissionDenial(error) {
|
|
343
|
+
const name = error == null ? void 0 : error.name;
|
|
344
|
+
return name === "NotAllowedError" || name === "PermissionDeniedError";
|
|
345
|
+
}
|
|
346
|
+
function toMicPermissionError(cause) {
|
|
347
|
+
const err = new Error(
|
|
348
|
+
"Microphone access was denied. Continuing in text-only mode."
|
|
349
|
+
);
|
|
350
|
+
err.name = "ConvaiMicPermissionError";
|
|
351
|
+
err.code = MIC_PERMISSION_ERROR_CODE;
|
|
352
|
+
err.cause = cause;
|
|
353
|
+
return err;
|
|
354
|
+
}
|
|
355
|
+
function reportMicFailure(client, logLabel, error) {
|
|
356
|
+
var _a;
|
|
357
|
+
console.error(logLabel, error);
|
|
358
|
+
const payload = isMicPermissionDenial(error) ? toMicPermissionError(error) : error;
|
|
359
|
+
(_a = client.emit) == null ? void 0 : _a.call(client, "error", payload);
|
|
360
|
+
}
|
|
361
|
+
function createConvaiWidget(container, options) {
|
|
362
|
+
var _a;
|
|
363
|
+
const styleTarget = (_a = options.styleTarget) != null ? _a : container.getRootNode() instanceof ShadowRoot ? container.getRootNode() : document;
|
|
364
|
+
const client = options.convaiClient || (() => {
|
|
365
|
+
var _a2, _b, _c;
|
|
366
|
+
const hasAuth = Boolean(options.apiKey || options.authToken);
|
|
367
|
+
if (!hasAuth || !options.characterId) {
|
|
368
|
+
throw new Error(
|
|
369
|
+
"Either convaiClient or (apiKey or authToken) and characterId must be provided"
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
return new ConvaiClient({
|
|
373
|
+
apiKey: (options == null ? void 0 : options.apiKey) || void 0,
|
|
374
|
+
authToken: (options == null ? void 0 : options.authToken) || void 0,
|
|
375
|
+
characterId: options.characterId,
|
|
376
|
+
enableVideo: (_a2 = options.enableVideo) != null ? _a2 : false,
|
|
377
|
+
startWithVideoOn: (_b = options.startWithVideoOn) != null ? _b : false,
|
|
378
|
+
enableLipsync: (_c = options.enableLipsync) != null ? _c : false,
|
|
379
|
+
enableEmotion: options.enableEmotion,
|
|
380
|
+
blendshapeConfig: options.blendshapeConfig
|
|
381
|
+
});
|
|
382
|
+
})();
|
|
383
|
+
const {
|
|
384
|
+
showVideo = true,
|
|
385
|
+
showScreenShare = true,
|
|
386
|
+
defaultVoiceMode = true,
|
|
387
|
+
requestPublicationGrant,
|
|
388
|
+
publishedChatConnectOptions,
|
|
389
|
+
publishedChatDescriptor,
|
|
390
|
+
onConnect,
|
|
391
|
+
onDisconnect,
|
|
392
|
+
onMessage
|
|
393
|
+
} = options;
|
|
394
|
+
const placement = options.placement && options.placement in PLACEMENT_CSS ? options.placement : "bottom-right";
|
|
395
|
+
injectGlobalStyles(styleTarget);
|
|
396
|
+
injectKeyframes(styleTarget);
|
|
397
|
+
let isOpen = false;
|
|
398
|
+
let isSettingsOpen = false;
|
|
399
|
+
let isVoiceMode = defaultVoiceMode && !requestPublicationGrant && client.connectionType !== "text";
|
|
400
|
+
let isMuted = false;
|
|
401
|
+
let isVideoVisible = false;
|
|
402
|
+
let inputValue = "";
|
|
403
|
+
let characterName = (publishedChatDescriptor == null ? void 0 : publishedChatDescriptor.display_name) || "Character";
|
|
404
|
+
let characterImage = (publishedChatDescriptor == null ? void 0 : publishedChatDescriptor.image_url) || "";
|
|
405
|
+
let audioRenderer = null;
|
|
406
|
+
let hasEnteredDefaultVoiceMode = false;
|
|
407
|
+
let hasConnectedBefore = false;
|
|
408
|
+
let pendingOpen = false;
|
|
409
|
+
let isDestroyed = false;
|
|
410
|
+
const eventSubscriptions = new WidgetEventSubscriptions(() => isDestroyed);
|
|
411
|
+
let rootElement;
|
|
412
|
+
let morphingContainer;
|
|
413
|
+
let buttonContent;
|
|
414
|
+
let chatContent;
|
|
415
|
+
let headerElement;
|
|
416
|
+
let contentElement;
|
|
417
|
+
let footerElement;
|
|
418
|
+
let inputElement;
|
|
419
|
+
let messageListElement;
|
|
420
|
+
let settingsTray;
|
|
421
|
+
let floatingVideo;
|
|
422
|
+
let voiceModeOverlay;
|
|
423
|
+
let connectingOverlay;
|
|
424
|
+
const refs = {};
|
|
425
|
+
let audioContext = null;
|
|
426
|
+
let analyzer = null;
|
|
427
|
+
let dataArray = null;
|
|
428
|
+
let rafId = null;
|
|
429
|
+
let source = null;
|
|
430
|
+
const fetchCharacterInfo$1 = async () => {
|
|
431
|
+
var _a2, _b;
|
|
432
|
+
if (publishedChatDescriptor) return;
|
|
433
|
+
const credential = (_a2 = client.authToken) != null ? _a2 : client.apiKey;
|
|
434
|
+
if (!credential || !client.characterId) return;
|
|
435
|
+
try {
|
|
436
|
+
const info = await fetchCharacterInfo({
|
|
437
|
+
characterId: client.characterId,
|
|
438
|
+
apiKey: credential,
|
|
439
|
+
authToken: client.authToken,
|
|
440
|
+
baseUrl: client.characterInfoUrl
|
|
441
|
+
});
|
|
442
|
+
characterName = info.name;
|
|
443
|
+
characterImage = (_b = info.image) != null ? _b : "";
|
|
444
|
+
updateHeader();
|
|
445
|
+
} catch (error) {
|
|
446
|
+
console.error("Failed to fetch character info:", error);
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
const createDOM = () => {
|
|
450
|
+
rootElement = document.createElement("div");
|
|
451
|
+
rootElement.className = "convai-widget";
|
|
452
|
+
rootElement.style.cssText = `
|
|
453
|
+
${PLACEMENT_CSS[placement]}
|
|
454
|
+
z-index: var(--convai-z-index, ${aeroTheme.zIndex.modal});
|
|
455
|
+
font-family: var(--convai-font, ${aeroTheme.typography.fontFamily.primary});
|
|
456
|
+
`;
|
|
457
|
+
morphingContainer = document.createElement("div");
|
|
458
|
+
morphingContainer.setAttribute("part", "launcher");
|
|
459
|
+
morphingContainer.style.cssText = `
|
|
460
|
+
position: relative;
|
|
461
|
+
width: var(--convai-launcher-size, 64px);
|
|
462
|
+
height: var(--convai-launcher-size, 64px);
|
|
463
|
+
max-width: ${PANEL_MAX_W};
|
|
464
|
+
max-height: ${PANEL_MAX_H};
|
|
465
|
+
background: var(--convai-panel-bg, ${aeroTheme.colors.glass.backdrop});
|
|
466
|
+
backdrop-filter: ${aeroTheme.glass.backdrop};
|
|
467
|
+
border: ${aeroTheme.glass.border};
|
|
468
|
+
border-radius: 50%;
|
|
469
|
+
box-shadow: var(--convai-shadow, ${aeroTheme.shadows.glass});
|
|
470
|
+
transition: all 0.3s ease-in-out;
|
|
471
|
+
overflow: hidden;
|
|
472
|
+
display: flex;
|
|
473
|
+
align-items: center;
|
|
474
|
+
justify-content: center;
|
|
475
|
+
cursor: pointer;
|
|
476
|
+
`;
|
|
477
|
+
buttonContent = document.createElement("div");
|
|
478
|
+
buttonContent.style.cssText = `
|
|
479
|
+
position: absolute;
|
|
480
|
+
inset: 0;
|
|
481
|
+
display: flex;
|
|
482
|
+
align-items: center;
|
|
483
|
+
justify-content: center;
|
|
484
|
+
transition: opacity 0.3s, transform 0.3s;
|
|
485
|
+
opacity: 1;
|
|
486
|
+
transform: scale(1);
|
|
487
|
+
`;
|
|
488
|
+
const convaiLogo = Icons.ConvaiLogo("xl", "idle");
|
|
489
|
+
convaiLogo.style.color = `var(--convai-accent, ${aeroTheme.colors.convai.light})`;
|
|
490
|
+
buttonContent.appendChild(convaiLogo);
|
|
491
|
+
chatContent = document.createElement("div");
|
|
492
|
+
chatContent.setAttribute("part", "panel");
|
|
493
|
+
chatContent.style.cssText = `
|
|
494
|
+
position: absolute;
|
|
495
|
+
inset: 0;
|
|
496
|
+
display: flex;
|
|
497
|
+
flex-direction: column;
|
|
498
|
+
opacity: 0;
|
|
499
|
+
transform: scale(0.8);
|
|
500
|
+
transition: opacity 0.2s, transform 0.2s;
|
|
501
|
+
pointer-events: none;
|
|
502
|
+
`;
|
|
503
|
+
voiceModeOverlay = createVoiceModeOverlay();
|
|
504
|
+
chatContent.appendChild(voiceModeOverlay);
|
|
505
|
+
headerElement = createHeader();
|
|
506
|
+
contentElement = document.createElement("div");
|
|
507
|
+
contentElement.style.cssText = `
|
|
508
|
+
flex: 1;
|
|
509
|
+
overflow-y: auto;
|
|
510
|
+
padding: 16px;
|
|
511
|
+
background: transparent;
|
|
512
|
+
position: relative;
|
|
513
|
+
`;
|
|
514
|
+
messageListElement = createMessageList();
|
|
515
|
+
contentElement.appendChild(messageListElement);
|
|
516
|
+
connectingOverlay = createConnectingOverlay();
|
|
517
|
+
contentElement.appendChild(connectingOverlay);
|
|
518
|
+
footerElement = createFooter();
|
|
519
|
+
chatContent.appendChild(headerElement);
|
|
520
|
+
chatContent.appendChild(contentElement);
|
|
521
|
+
chatContent.appendChild(footerElement);
|
|
522
|
+
morphingContainer.appendChild(buttonContent);
|
|
523
|
+
morphingContainer.appendChild(chatContent);
|
|
524
|
+
rootElement.appendChild(morphingContainer);
|
|
525
|
+
settingsTray = createSettingsTray();
|
|
526
|
+
rootElement.appendChild(settingsTray);
|
|
527
|
+
floatingVideo = createFloatingVideo();
|
|
528
|
+
container.appendChild(floatingVideo);
|
|
529
|
+
container.appendChild(rootElement);
|
|
530
|
+
morphingContainer.addEventListener("click", handleLauncherClick);
|
|
531
|
+
};
|
|
532
|
+
const createVoiceModeOverlay = () => {
|
|
533
|
+
const overlay = document.createElement("div");
|
|
534
|
+
overlay.style.cssText = `
|
|
535
|
+
position: absolute;
|
|
536
|
+
top: 50%;
|
|
537
|
+
left: 50%;
|
|
538
|
+
transform: translate(-50%, -50%);
|
|
539
|
+
text-align: center;
|
|
540
|
+
padding: 16px;
|
|
541
|
+
z-index: 10;
|
|
542
|
+
pointer-events: auto;
|
|
543
|
+
display: none;
|
|
544
|
+
flex-direction: column;
|
|
545
|
+
align-items: center;
|
|
546
|
+
gap: 32px;
|
|
547
|
+
`;
|
|
548
|
+
const avatarWrap = document.createElement("div");
|
|
549
|
+
avatarWrap.style.cssText = `
|
|
550
|
+
position: relative;
|
|
551
|
+
display: flex;
|
|
552
|
+
align-items: center;
|
|
553
|
+
justify-content: center;
|
|
554
|
+
isolation: isolate;
|
|
555
|
+
`;
|
|
556
|
+
const avatarStack = document.createElement("div");
|
|
557
|
+
avatarStack.className = "convai-voice-avatar";
|
|
558
|
+
refs.voiceModeAvatar = avatarStack;
|
|
559
|
+
avatarStack.style.cssText = `
|
|
560
|
+
position: relative;
|
|
561
|
+
z-index: 10;
|
|
562
|
+
border-radius: 50%;
|
|
563
|
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
|
564
|
+
background: white;
|
|
565
|
+
display: flex;
|
|
566
|
+
align-items: center;
|
|
567
|
+
justify-content: center;
|
|
568
|
+
`;
|
|
569
|
+
const layer1 = document.createElement("div");
|
|
570
|
+
layer1.className = "convai-voice-gradient";
|
|
571
|
+
layer1.style.cssText = `
|
|
572
|
+
position: absolute;
|
|
573
|
+
width: 126px;
|
|
574
|
+
height: 126px;
|
|
575
|
+
border-radius: 50%;
|
|
576
|
+
background: conic-gradient(
|
|
577
|
+
from 0deg,
|
|
578
|
+
${aeroTheme.colors.convai.light}00 0%,
|
|
579
|
+
${aeroTheme.colors.convai.light}40 25%,
|
|
580
|
+
${aeroTheme.colors.convai.dark}60 50%,
|
|
581
|
+
${aeroTheme.colors.convai.light}40 75%,
|
|
582
|
+
${aeroTheme.colors.convai.light}00 100%
|
|
583
|
+
);
|
|
584
|
+
opacity: 0.8;
|
|
585
|
+
filter: blur(8px);
|
|
586
|
+
z-index: -2;
|
|
587
|
+
animation: convaiVoiceSpin 20s linear infinite;
|
|
588
|
+
`;
|
|
589
|
+
const layer2 = document.createElement("div");
|
|
590
|
+
layer2.className = "convai-voice-gradient";
|
|
591
|
+
layer2.style.cssText = `
|
|
592
|
+
position: absolute;
|
|
593
|
+
width: 126px;
|
|
594
|
+
height: 126px;
|
|
595
|
+
border-radius: 50%;
|
|
596
|
+
background:
|
|
597
|
+
radial-gradient(ellipse 80% 100% at 30% 40%,
|
|
598
|
+
${aeroTheme.colors.convai.light}50,
|
|
599
|
+
${aeroTheme.colors.convai.light}30 40%,
|
|
600
|
+
transparent 70%),
|
|
601
|
+
radial-gradient(ellipse 80% 100% at 70% 60%,
|
|
602
|
+
${aeroTheme.colors.convai.dark}50,
|
|
603
|
+
${aeroTheme.colors.convai.dark}30 40%,
|
|
604
|
+
transparent 70%);
|
|
605
|
+
opacity: 0.9;
|
|
606
|
+
filter: blur(6px);
|
|
607
|
+
z-index: -1;
|
|
608
|
+
animation: convaiVoiceSpinReverse 15s linear infinite;
|
|
609
|
+
`;
|
|
610
|
+
const avatarClip = document.createElement("div");
|
|
611
|
+
avatarClip.style.cssText = `
|
|
612
|
+
position: relative;
|
|
613
|
+
border-radius: 50%;
|
|
614
|
+
overflow: hidden;
|
|
615
|
+
border: 3px solid rgba(255, 255, 255, 0.2);
|
|
616
|
+
width: 120px;
|
|
617
|
+
height: 120px;
|
|
618
|
+
display: flex;
|
|
619
|
+
align-items: center;
|
|
620
|
+
justify-content: center;
|
|
621
|
+
`;
|
|
622
|
+
refs.voiceModeAvatarClip = avatarClip;
|
|
623
|
+
avatarStack.append(layer1, layer2, avatarClip);
|
|
624
|
+
avatarWrap.appendChild(avatarStack);
|
|
625
|
+
overlay.appendChild(avatarWrap);
|
|
626
|
+
const canvas = document.createElement("canvas");
|
|
627
|
+
canvas.className = "convai-voice-wave";
|
|
628
|
+
canvas.style.cssText = `width: 250px; height: 80px;`;
|
|
629
|
+
refs.voiceModeCanvas = canvas;
|
|
630
|
+
overlay.appendChild(canvas);
|
|
631
|
+
const statusContainer = document.createElement("div");
|
|
632
|
+
const statusTitle = document.createElement("div");
|
|
633
|
+
statusTitle.id = "voice-mode-title";
|
|
634
|
+
refs.voiceModeTitle = statusTitle;
|
|
635
|
+
statusTitle.style.cssText = `
|
|
636
|
+
font-size: 16px;
|
|
637
|
+
font-weight: 600;
|
|
638
|
+
color: var(--convai-panel-fg, ${aeroTheme.colors.text.primary});
|
|
639
|
+
margin-bottom: 8px;
|
|
640
|
+
`;
|
|
641
|
+
statusTitle.textContent = "Voice Mode";
|
|
642
|
+
const statusSubtitle = document.createElement("div");
|
|
643
|
+
statusSubtitle.id = "voice-mode-subtitle";
|
|
644
|
+
refs.voiceModeSubtitle = statusSubtitle;
|
|
645
|
+
statusSubtitle.style.cssText = `
|
|
646
|
+
font-size: 13px;
|
|
647
|
+
color: ${aeroTheme.colors.text.secondary};
|
|
648
|
+
`;
|
|
649
|
+
statusSubtitle.textContent = "Tap microphone to talk";
|
|
650
|
+
statusContainer.append(statusTitle, statusSubtitle);
|
|
651
|
+
overlay.appendChild(statusContainer);
|
|
652
|
+
return overlay;
|
|
653
|
+
};
|
|
654
|
+
const updateVoiceModeAvatar = () => {
|
|
655
|
+
var _a2;
|
|
656
|
+
const clip = refs.voiceModeAvatarClip;
|
|
657
|
+
if (!clip) return;
|
|
658
|
+
const wanted = characterImage || `letter:${characterName}`;
|
|
659
|
+
if (clip.dataset.filledWith === wanted) return;
|
|
660
|
+
clip.dataset.filledWith = wanted;
|
|
661
|
+
clip.replaceChildren();
|
|
662
|
+
if (characterImage) {
|
|
663
|
+
const img = document.createElement("img");
|
|
664
|
+
img.src = characterImage;
|
|
665
|
+
img.alt = characterName;
|
|
666
|
+
img.style.cssText = `width: 120px; height: 120px; object-fit: cover; display: block;`;
|
|
667
|
+
clip.appendChild(img);
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
const letter = document.createElement("div");
|
|
671
|
+
letter.style.cssText = `
|
|
672
|
+
width: 120px;
|
|
673
|
+
height: 120px;
|
|
674
|
+
background-color: ${aeroTheme.colors.convai.light}20;
|
|
675
|
+
display: flex;
|
|
676
|
+
align-items: center;
|
|
677
|
+
justify-content: center;
|
|
678
|
+
font-size: 48px;
|
|
679
|
+
font-weight: 600;
|
|
680
|
+
color: var(--convai-accent, ${aeroTheme.colors.convai.light});
|
|
681
|
+
`;
|
|
682
|
+
letter.textContent = ((_a2 = characterName[0]) == null ? void 0 : _a2.toUpperCase()) || "C";
|
|
683
|
+
clip.appendChild(letter);
|
|
684
|
+
};
|
|
685
|
+
const createConnectingOverlay = () => {
|
|
686
|
+
const overlay = document.createElement("div");
|
|
687
|
+
overlay.id = "convai-connecting-overlay";
|
|
688
|
+
overlay.style.cssText = `
|
|
689
|
+
position: absolute;
|
|
690
|
+
inset: 0;
|
|
691
|
+
z-index: 100;
|
|
692
|
+
display: flex;
|
|
693
|
+
flex-direction: column;
|
|
694
|
+
align-items: center;
|
|
695
|
+
justify-content: center;
|
|
696
|
+
gap: 16px;
|
|
697
|
+
background: rgba(255, 255, 255, 0.95);
|
|
698
|
+
opacity: 0;
|
|
699
|
+
pointer-events: none;
|
|
700
|
+
transition: opacity 0.3s;
|
|
701
|
+
`;
|
|
702
|
+
injectKeyframes(styleTarget);
|
|
703
|
+
const spinWrapper = document.createElement("div");
|
|
704
|
+
spinWrapper.className = "convai-connecting-spin";
|
|
705
|
+
spinWrapper.style.cssText = `
|
|
706
|
+
display: inline-flex;
|
|
707
|
+
animation: convaiConnectingSpin 2s linear infinite;
|
|
708
|
+
`;
|
|
709
|
+
const logo = Icons.ConvaiLogo("xl", "connecting");
|
|
710
|
+
logo.style.color = `var(--convai-accent, ${aeroTheme.colors.convai.light})`;
|
|
711
|
+
spinWrapper.appendChild(logo);
|
|
712
|
+
overlay.appendChild(spinWrapper);
|
|
713
|
+
const label = document.createElement("div");
|
|
714
|
+
label.id = "convai-connecting-text";
|
|
715
|
+
label.className = "convai-connecting-pulse";
|
|
716
|
+
label.style.cssText = `
|
|
717
|
+
font-size: 14px;
|
|
718
|
+
font-weight: 500;
|
|
719
|
+
color: ${aeroTheme.colors.text.secondary};
|
|
720
|
+
animation: convaiConnectingPulse 2s ease-in-out infinite;
|
|
721
|
+
`;
|
|
722
|
+
refs.connectingLabel = label;
|
|
723
|
+
overlay.appendChild(label);
|
|
724
|
+
return overlay;
|
|
725
|
+
};
|
|
726
|
+
const updateConnectingOverlay = () => {
|
|
727
|
+
if (!connectingOverlay) return;
|
|
728
|
+
const label = refs.connectingLabel;
|
|
729
|
+
if (label) {
|
|
730
|
+
label.textContent = `Connecting to ${characterName}...`;
|
|
731
|
+
}
|
|
732
|
+
const shouldShow = (client.state.isConnected || client.state.isConnecting) && !client.isBotReady;
|
|
733
|
+
connectingOverlay.style.opacity = shouldShow ? "1" : "0";
|
|
734
|
+
connectingOverlay.style.pointerEvents = shouldShow ? "auto" : "none";
|
|
735
|
+
};
|
|
736
|
+
let audioLevels = Array(40).fill(0);
|
|
737
|
+
let startTime = 0;
|
|
738
|
+
let waveFrameParity = 0;
|
|
739
|
+
let waveWasSilent = false;
|
|
740
|
+
const drawWaves = () => {
|
|
741
|
+
const canvas = refs.voiceModeCanvas;
|
|
742
|
+
if (!canvas) return;
|
|
743
|
+
waveFrameParity ^= 1;
|
|
744
|
+
if (waveFrameParity) return;
|
|
745
|
+
let sum = 0;
|
|
746
|
+
for (let i = 0; i < audioLevels.length; i++) sum += audioLevels[i];
|
|
747
|
+
const silent = sum / audioLevels.length < 0.012;
|
|
748
|
+
if (silent && waveWasSilent) return;
|
|
749
|
+
waveWasSilent = silent;
|
|
750
|
+
const dpr = Math.min(window.devicePixelRatio || 1, 2);
|
|
751
|
+
if (canvas.width !== 250 * dpr) {
|
|
752
|
+
canvas.width = 250 * dpr;
|
|
753
|
+
canvas.height = 80 * dpr;
|
|
754
|
+
}
|
|
755
|
+
const ctx = canvas.getContext("2d");
|
|
756
|
+
if (!ctx) return;
|
|
757
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
758
|
+
ctx.clearRect(0, 0, 250, 80);
|
|
759
|
+
const centerY = 40;
|
|
760
|
+
const waveWidth = 250;
|
|
761
|
+
const segments = 40;
|
|
762
|
+
const avgLevel = sum / audioLevels.length;
|
|
763
|
+
const waveColors = [
|
|
764
|
+
aeroTheme.colors.convai.light,
|
|
765
|
+
aeroTheme.colors.convai.light,
|
|
766
|
+
"#34d399"
|
|
767
|
+
];
|
|
768
|
+
ctx.lineCap = "round";
|
|
769
|
+
ctx.lineJoin = "round";
|
|
770
|
+
for (let waveIndex = 2; waveIndex >= 0; waveIndex--) {
|
|
771
|
+
ctx.beginPath();
|
|
772
|
+
for (let i = 0; i <= segments; i++) {
|
|
773
|
+
const x = i / segments * waveWidth;
|
|
774
|
+
const levelIndex = Math.floor(i / segments * (audioLevels.length - 1));
|
|
775
|
+
const level = audioLevels[levelIndex] || 0;
|
|
776
|
+
const phase = (Date.now() / 500 + i * 0.2 + waveIndex * 1.5) % (Math.PI * 2);
|
|
777
|
+
const baseAmplitude = avgLevel > 0.05 ? 2 + waveIndex * 1.5 : 0;
|
|
778
|
+
const amplitude = baseAmplitude + level * (25 - baseAmplitude);
|
|
779
|
+
const y = centerY + Math.sin(phase) * amplitude;
|
|
780
|
+
if (i === 0) ctx.moveTo(x, y);
|
|
781
|
+
else ctx.lineTo(x, y);
|
|
782
|
+
}
|
|
783
|
+
ctx.strokeStyle = waveColors[waveIndex];
|
|
784
|
+
ctx.globalAlpha = 0.18 * (0.3 + avgLevel);
|
|
785
|
+
ctx.lineWidth = 2.5 - waveIndex * 0.4 + 8 * avgLevel + 3;
|
|
786
|
+
ctx.stroke();
|
|
787
|
+
ctx.globalAlpha = 0.95 - waveIndex * 0.15;
|
|
788
|
+
ctx.lineWidth = 2.5 - waveIndex * 0.4;
|
|
789
|
+
ctx.stroke();
|
|
790
|
+
}
|
|
791
|
+
ctx.globalAlpha = 1;
|
|
792
|
+
};
|
|
793
|
+
const updateAudioBars = () => {
|
|
794
|
+
if (!voiceModeOverlay) return;
|
|
795
|
+
const isTalking = client.state.isSpeaking;
|
|
796
|
+
const isListening = client.state.isListening;
|
|
797
|
+
const micOpen = !client.audioControls.isAudioMuted;
|
|
798
|
+
const avatar = refs.voiceModeAvatar;
|
|
799
|
+
if (avatar) {
|
|
800
|
+
const wanted = isTalking ? "convaiVoiceBreathe 3s ease-in-out infinite" : "";
|
|
801
|
+
if (avatar.style.animation !== wanted) avatar.style.animation = wanted;
|
|
802
|
+
}
|
|
803
|
+
const title = refs.voiceModeTitle;
|
|
804
|
+
const subtitle = refs.voiceModeSubtitle;
|
|
805
|
+
if (title) {
|
|
806
|
+
title.textContent = isTalking ? `${characterName} Speaking...` : isListening || micOpen ? "Listening..." : "Voice Mode";
|
|
807
|
+
}
|
|
808
|
+
if (subtitle) {
|
|
809
|
+
subtitle.textContent = isListening || micOpen || isTalking ? "Audio active" : "Tap microphone to talk";
|
|
810
|
+
}
|
|
811
|
+
if ((isListening || micOpen) && analyzer && dataArray) {
|
|
812
|
+
analyzer.getByteTimeDomainData(dataArray);
|
|
813
|
+
let sum = 0;
|
|
814
|
+
for (let i = 0; i < dataArray.length; i++) {
|
|
815
|
+
const normalized = (dataArray[i] - 128) / 128;
|
|
816
|
+
sum += normalized * normalized;
|
|
817
|
+
}
|
|
818
|
+
const rms = Math.sqrt(sum / dataArray.length);
|
|
819
|
+
const volume = Math.min(1, rms * 3);
|
|
820
|
+
for (let i = 0; i < audioLevels.length; i++) {
|
|
821
|
+
const position = i / audioLevels.length;
|
|
822
|
+
const wavePhase = Date.now() / 300 + position * Math.PI * 2;
|
|
823
|
+
const waveVariation = Math.sin(wavePhase) * 0.15 + 0.85;
|
|
824
|
+
audioLevels[i] = volume * waveVariation;
|
|
825
|
+
}
|
|
826
|
+
} else {
|
|
827
|
+
for (let i = 0; i < audioLevels.length; i++) audioLevels[i] = 0;
|
|
828
|
+
}
|
|
829
|
+
drawWaves();
|
|
830
|
+
rafId = requestAnimationFrame(updateAudioBars);
|
|
831
|
+
};
|
|
832
|
+
const startAudioAnalysis = async () => {
|
|
833
|
+
try {
|
|
834
|
+
if (!audioContext) {
|
|
835
|
+
audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
|
836
|
+
}
|
|
837
|
+
if (audioContext.state === "suspended") {
|
|
838
|
+
await audioContext.resume();
|
|
839
|
+
}
|
|
840
|
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
841
|
+
analyzer = audioContext.createAnalyser();
|
|
842
|
+
analyzer.fftSize = 256;
|
|
843
|
+
analyzer.smoothingTimeConstant = 0.7;
|
|
844
|
+
source = audioContext.createMediaStreamSource(stream);
|
|
845
|
+
source.connect(analyzer);
|
|
846
|
+
dataArray = new Uint8Array(analyzer.fftSize);
|
|
847
|
+
updateAudioBars();
|
|
848
|
+
} catch (e) {
|
|
849
|
+
reportMicFailure(client, "Audio analysis setup failed:", e);
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
const stopAudioAnalysis = () => {
|
|
853
|
+
if (rafId) cancelAnimationFrame(rafId);
|
|
854
|
+
if (source) {
|
|
855
|
+
source.disconnect();
|
|
856
|
+
source.mediaStream.getTracks().forEach((t) => t.stop());
|
|
857
|
+
source = null;
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
const createHeader = () => {
|
|
861
|
+
const header = document.createElement("div");
|
|
862
|
+
header.setAttribute("part", "header");
|
|
863
|
+
header.style.cssText = `
|
|
864
|
+
display: flex;
|
|
865
|
+
align-items: center;
|
|
866
|
+
justify-content: space-between;
|
|
867
|
+
padding: 16px;
|
|
868
|
+
border-bottom: 1px solid ${aeroTheme.colors.neutral[200]};
|
|
869
|
+
background: var(--convai-panel-bg, white);
|
|
870
|
+
position: relative;
|
|
871
|
+
`;
|
|
872
|
+
const closeButton = document.createElement("button");
|
|
873
|
+
const chevronIcon = Icons.ChevronDown("md");
|
|
874
|
+
closeButton.appendChild(chevronIcon);
|
|
875
|
+
closeButton.style.cssText = `
|
|
876
|
+
font-size: 20px;
|
|
877
|
+
color: ${aeroTheme.colors.text.secondary};
|
|
878
|
+
cursor: pointer;
|
|
879
|
+
padding: 4px;
|
|
880
|
+
transition: ${aeroTheme.transitions.fast};
|
|
881
|
+
background: transparent;
|
|
882
|
+
border: none;
|
|
883
|
+
`;
|
|
884
|
+
closeButton.addEventListener("click", (e) => {
|
|
885
|
+
e.stopPropagation();
|
|
886
|
+
handleClose();
|
|
887
|
+
});
|
|
888
|
+
const titleSection = document.createElement("div");
|
|
889
|
+
titleSection.style.cssText = `
|
|
890
|
+
position: absolute;
|
|
891
|
+
left: 50%;
|
|
892
|
+
transform: translateX(-50%);
|
|
893
|
+
display: flex;
|
|
894
|
+
align-items: center;
|
|
895
|
+
gap: 8px;
|
|
896
|
+
font-size: ${aeroTheme.typography.fontSize.base};
|
|
897
|
+
font-weight: ${aeroTheme.typography.fontWeight.semibold};
|
|
898
|
+
color: var(--convai-panel-fg, ${aeroTheme.colors.text.primary});
|
|
899
|
+
`;
|
|
900
|
+
titleSection.id = "convai-widget-title";
|
|
901
|
+
refs.widgetTitle = titleSection;
|
|
902
|
+
const settingsButton = document.createElement("button");
|
|
903
|
+
const moreIcon = Icons.MoreVertical("md");
|
|
904
|
+
settingsButton.appendChild(moreIcon);
|
|
905
|
+
settingsButton.style.cssText = `
|
|
906
|
+
font-size: 24px;
|
|
907
|
+
color: ${aeroTheme.colors.text.secondary};
|
|
908
|
+
cursor: pointer;
|
|
909
|
+
padding: 4px;
|
|
910
|
+
transition: ${aeroTheme.transitions.fast};
|
|
911
|
+
background: transparent;
|
|
912
|
+
border: none;
|
|
913
|
+
margin-left: auto;
|
|
914
|
+
`;
|
|
915
|
+
settingsButton.addEventListener("click", (e) => {
|
|
916
|
+
e.stopPropagation();
|
|
917
|
+
handleSettingsToggle();
|
|
918
|
+
});
|
|
919
|
+
header.appendChild(closeButton);
|
|
920
|
+
header.appendChild(titleSection);
|
|
921
|
+
header.appendChild(settingsButton);
|
|
922
|
+
return header;
|
|
923
|
+
};
|
|
924
|
+
const updateHeader = () => {
|
|
925
|
+
const titleSection = refs.widgetTitle;
|
|
926
|
+
if (!titleSection) return;
|
|
927
|
+
titleSection.innerHTML = "";
|
|
928
|
+
if (characterImage) {
|
|
929
|
+
const img = document.createElement("img");
|
|
930
|
+
img.src = characterImage;
|
|
931
|
+
img.alt = characterName;
|
|
932
|
+
img.style.cssText = `
|
|
933
|
+
width: 24px;
|
|
934
|
+
height: 24px;
|
|
935
|
+
border-radius: 50%;
|
|
936
|
+
object-fit: cover;
|
|
937
|
+
border: 1.5px solid ${getBotStatusColor().color};
|
|
938
|
+
box-shadow: 0 0 6px ${getBotStatusColor().color}40;
|
|
939
|
+
transition: all 0.3s ease;
|
|
940
|
+
`;
|
|
941
|
+
titleSection.appendChild(img);
|
|
942
|
+
}
|
|
943
|
+
const nameSpan = document.createElement("span");
|
|
944
|
+
nameSpan.textContent = characterName;
|
|
945
|
+
titleSection.appendChild(nameSpan);
|
|
946
|
+
const muteButton = document.createElement("button");
|
|
947
|
+
muteButton.innerHTML = "";
|
|
948
|
+
const volumeIcon = isMuted ? Icons.VolumeMute("sm") : Icons.VolumeHigh("sm");
|
|
949
|
+
volumeIcon.style.color = isMuted ? "#919EABA6" : "#0E7360";
|
|
950
|
+
muteButton.appendChild(volumeIcon);
|
|
951
|
+
muteButton.style.cssText = `
|
|
952
|
+
cursor: pointer;
|
|
953
|
+
background: transparent;
|
|
954
|
+
border: none;
|
|
955
|
+
box-shadow: none;
|
|
956
|
+
width: auto;
|
|
957
|
+
height: auto;
|
|
958
|
+
padding: 0;
|
|
959
|
+
display: inline-flex;
|
|
960
|
+
align-items: center;
|
|
961
|
+
margin-left: 8px;
|
|
962
|
+
outline: none;
|
|
963
|
+
transition: transform 0.1s ease-out;
|
|
964
|
+
`;
|
|
965
|
+
muteButton.addEventListener("click", (e) => {
|
|
966
|
+
e.stopPropagation();
|
|
967
|
+
handleToggleMute();
|
|
968
|
+
});
|
|
969
|
+
muteButton.addEventListener("mouseenter", () => {
|
|
970
|
+
muteButton.style.transform = "scale(1.1)";
|
|
971
|
+
});
|
|
972
|
+
muteButton.addEventListener("mouseleave", () => {
|
|
973
|
+
muteButton.style.transform = "scale(1)";
|
|
974
|
+
});
|
|
975
|
+
titleSection.appendChild(muteButton);
|
|
976
|
+
if (isVoiceMode) {
|
|
977
|
+
const voiceBadge = document.createElement("span");
|
|
978
|
+
voiceBadge.textContent = "VOICE";
|
|
979
|
+
voiceBadge.style.cssText = `
|
|
980
|
+
font-size: 10px;
|
|
981
|
+
color: var(--convai-accent, ${aeroTheme.colors.convai.light});
|
|
982
|
+
font-weight: 500;
|
|
983
|
+
margin-left: 8px;
|
|
984
|
+
padding: 2px 6px;
|
|
985
|
+
border-radius: 4px;
|
|
986
|
+
background-color: ${aeroTheme.colors.convai.light}20;
|
|
987
|
+
`;
|
|
988
|
+
titleSection.appendChild(voiceBadge);
|
|
989
|
+
}
|
|
990
|
+
if (client.state.isSpeaking) {
|
|
991
|
+
const speakingTag = document.createElement("span");
|
|
992
|
+
speakingTag.textContent = "SPEAKING";
|
|
993
|
+
speakingTag.style.cssText = `
|
|
994
|
+
font-size: 10px;
|
|
995
|
+
color: #10b981;
|
|
996
|
+
font-weight: 600;
|
|
997
|
+
margin-left: 8px;
|
|
998
|
+
padding: 3px 8px;
|
|
999
|
+
border-radius: 6px;
|
|
1000
|
+
background-color: #10b98120;
|
|
1001
|
+
border: 1px solid #10b98140;
|
|
1002
|
+
display: inline-flex;
|
|
1003
|
+
align-items: center;
|
|
1004
|
+
gap: 4px;
|
|
1005
|
+
`;
|
|
1006
|
+
const dot = document.createElement("span");
|
|
1007
|
+
dot.style.cssText = `
|
|
1008
|
+
width: 6px;
|
|
1009
|
+
height: 6px;
|
|
1010
|
+
border-radius: 50%;
|
|
1011
|
+
background-color: #10b981;
|
|
1012
|
+
display: inline-block;
|
|
1013
|
+
`;
|
|
1014
|
+
speakingTag.insertBefore(dot, speakingTag.firstChild);
|
|
1015
|
+
titleSection.appendChild(speakingTag);
|
|
1016
|
+
}
|
|
1017
|
+
if (client.state.isListening && !client.state.isSpeaking) {
|
|
1018
|
+
const listeningTag = document.createElement("span");
|
|
1019
|
+
listeningTag.textContent = "LISTENING";
|
|
1020
|
+
listeningTag.style.cssText = `
|
|
1021
|
+
font-size: 10px;
|
|
1022
|
+
color: #3b82f6;
|
|
1023
|
+
font-weight: 600;
|
|
1024
|
+
margin-left: 8px;
|
|
1025
|
+
padding: 3px 8px;
|
|
1026
|
+
border-radius: 6px;
|
|
1027
|
+
background-color: #3b82f620;
|
|
1028
|
+
border: 1px solid #3b82f640;
|
|
1029
|
+
display: inline-flex;
|
|
1030
|
+
align-items: center;
|
|
1031
|
+
gap: 4px;
|
|
1032
|
+
`;
|
|
1033
|
+
const dot = document.createElement("span");
|
|
1034
|
+
dot.style.cssText = `
|
|
1035
|
+
width: 6px;
|
|
1036
|
+
height: 6px;
|
|
1037
|
+
border-radius: 50%;
|
|
1038
|
+
background-color: #3b82f6;
|
|
1039
|
+
display: inline-block;
|
|
1040
|
+
`;
|
|
1041
|
+
listeningTag.insertBefore(dot, listeningTag.firstChild);
|
|
1042
|
+
titleSection.appendChild(listeningTag);
|
|
1043
|
+
}
|
|
1044
|
+
updateConnectingOverlay();
|
|
1045
|
+
updateVoiceModeAvatar();
|
|
1046
|
+
};
|
|
1047
|
+
const createMessageList = () => {
|
|
1048
|
+
const list = document.createElement("div");
|
|
1049
|
+
list.id = "convai-message-list";
|
|
1050
|
+
list.setAttribute("part", "messages");
|
|
1051
|
+
list.style.cssText = `
|
|
1052
|
+
display: flex;
|
|
1053
|
+
flex-direction: column;
|
|
1054
|
+
gap: 12px;
|
|
1055
|
+
min-height: 100%;
|
|
1056
|
+
`;
|
|
1057
|
+
return list;
|
|
1058
|
+
};
|
|
1059
|
+
const createFooter = () => {
|
|
1060
|
+
const footer = document.createElement("div");
|
|
1061
|
+
footer.style.cssText = `
|
|
1062
|
+
padding: 16px;
|
|
1063
|
+
border-top: 1px solid ${aeroTheme.colors.neutral[200]};
|
|
1064
|
+
background: var(--convai-panel-bg, white);
|
|
1065
|
+
display: flex;
|
|
1066
|
+
gap: 8px;
|
|
1067
|
+
align-items: center;
|
|
1068
|
+
position: relative;
|
|
1069
|
+
`;
|
|
1070
|
+
const voiceExitButton = document.createElement("button");
|
|
1071
|
+
voiceExitButton.id = "convai-voice-exit-btn";
|
|
1072
|
+
refs.voiceExitBtn = voiceExitButton;
|
|
1073
|
+
const exitIcon = Icons.PhoneOff("md");
|
|
1074
|
+
voiceExitButton.appendChild(exitIcon);
|
|
1075
|
+
voiceExitButton.style.cssText = `
|
|
1076
|
+
width: 36px;
|
|
1077
|
+
height: 36px;
|
|
1078
|
+
border-radius: 50%;
|
|
1079
|
+
background: ${aeroTheme.colors.error[500]};
|
|
1080
|
+
color: white;
|
|
1081
|
+
display: none; /* Hidden by default */
|
|
1082
|
+
align-items: center;
|
|
1083
|
+
justify-content: center;
|
|
1084
|
+
cursor: pointer;
|
|
1085
|
+
margin: 0 auto;
|
|
1086
|
+
border: none;
|
|
1087
|
+
`;
|
|
1088
|
+
voiceExitButton.addEventListener("click", () => {
|
|
1089
|
+
client.sendInterruptMessage();
|
|
1090
|
+
isVoiceMode = false;
|
|
1091
|
+
applyVoiceMode();
|
|
1092
|
+
});
|
|
1093
|
+
footer.appendChild(voiceExitButton);
|
|
1094
|
+
const standardContent = document.createElement("div");
|
|
1095
|
+
standardContent.id = "convai-footer-standard";
|
|
1096
|
+
refs.footerStandard = standardContent;
|
|
1097
|
+
standardContent.style.cssText = `
|
|
1098
|
+
display: flex;
|
|
1099
|
+
gap: 8px;
|
|
1100
|
+
align-items: center;
|
|
1101
|
+
width: 100%;
|
|
1102
|
+
`;
|
|
1103
|
+
const inputContainer = document.createElement("div");
|
|
1104
|
+
inputContainer.style.cssText = `
|
|
1105
|
+
flex: 1;
|
|
1106
|
+
position: relative;
|
|
1107
|
+
display: flex;
|
|
1108
|
+
align-items: center;
|
|
1109
|
+
`;
|
|
1110
|
+
inputElement = document.createElement("input");
|
|
1111
|
+
inputElement.setAttribute("part", "input");
|
|
1112
|
+
inputElement.type = "text";
|
|
1113
|
+
inputElement.placeholder = "Conversation";
|
|
1114
|
+
inputElement.style.cssText = `
|
|
1115
|
+
width: 100%;
|
|
1116
|
+
padding: 12px 44px 12px 16px;
|
|
1117
|
+
border-radius: ${aeroTheme.borderRadius.full};
|
|
1118
|
+
border: 1px solid ${aeroTheme.colors.neutral[300]};
|
|
1119
|
+
background: ${aeroTheme.colors.glass.medium};
|
|
1120
|
+
color: var(--convai-panel-fg, ${aeroTheme.colors.text.primary});
|
|
1121
|
+
font-size: ${aeroTheme.typography.fontSize.sm};
|
|
1122
|
+
transition: ${aeroTheme.transitions.fast};
|
|
1123
|
+
outline: none;
|
|
1124
|
+
`;
|
|
1125
|
+
inputElement.addEventListener("input", (e) => {
|
|
1126
|
+
inputValue = e.target.value;
|
|
1127
|
+
updateSendButton();
|
|
1128
|
+
});
|
|
1129
|
+
inputElement.addEventListener("keypress", (e) => {
|
|
1130
|
+
if (e.key === "Enter") handleSend();
|
|
1131
|
+
});
|
|
1132
|
+
const sendButton = document.createElement("button");
|
|
1133
|
+
sendButton.id = "convai-send-button";
|
|
1134
|
+
sendButton.setAttribute("part", "send-button");
|
|
1135
|
+
refs.sendButton = sendButton;
|
|
1136
|
+
const sendIcon = Icons.Send("md");
|
|
1137
|
+
sendButton.appendChild(sendIcon);
|
|
1138
|
+
sendButton.style.cssText = `
|
|
1139
|
+
position: absolute;
|
|
1140
|
+
right: 6px;
|
|
1141
|
+
width: 36px;
|
|
1142
|
+
height: 36px;
|
|
1143
|
+
border-radius: 50%;
|
|
1144
|
+
background: transparent; /* Initial transparent for voice toggle */
|
|
1145
|
+
color: var(--convai-panel-fg, ${aeroTheme.colors.text.primary});
|
|
1146
|
+
display: flex;
|
|
1147
|
+
align-items: center;
|
|
1148
|
+
justify-content: center;
|
|
1149
|
+
cursor: pointer;
|
|
1150
|
+
transition: ${aeroTheme.transitions.fast};
|
|
1151
|
+
border: none;
|
|
1152
|
+
`;
|
|
1153
|
+
sendButton.addEventListener("click", async () => {
|
|
1154
|
+
if (inputValue.length > 0) {
|
|
1155
|
+
handleSend();
|
|
1156
|
+
} else if (!requestPublicationGrant && client.connectionType !== "text") {
|
|
1157
|
+
client.sendInterruptMessage();
|
|
1158
|
+
try {
|
|
1159
|
+
await client.audioControls.unmuteAudio();
|
|
1160
|
+
isVoiceMode = true;
|
|
1161
|
+
await updateVoiceMode();
|
|
1162
|
+
} catch (error) {
|
|
1163
|
+
reportMicFailure(client, "Failed to enable microphone:", error);
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
});
|
|
1167
|
+
inputContainer.appendChild(inputElement);
|
|
1168
|
+
inputContainer.appendChild(sendButton);
|
|
1169
|
+
standardContent.appendChild(inputContainer);
|
|
1170
|
+
footer.appendChild(standardContent);
|
|
1171
|
+
return footer;
|
|
1172
|
+
};
|
|
1173
|
+
const createSettingsTray = () => {
|
|
1174
|
+
const tray = document.createElement("div");
|
|
1175
|
+
tray.setAttribute("data-settings-tray", "true");
|
|
1176
|
+
tray.style.cssText = `
|
|
1177
|
+
position: absolute;
|
|
1178
|
+
top: 60px;
|
|
1179
|
+
right: 16px;
|
|
1180
|
+
background: var(--convai-panel-bg, white);
|
|
1181
|
+
border-radius: ${aeroTheme.borderRadius.xl};
|
|
1182
|
+
box-shadow: ${aeroTheme.shadows.xl};
|
|
1183
|
+
padding: 0;
|
|
1184
|
+
display: none;
|
|
1185
|
+
flex-direction: row;
|
|
1186
|
+
align-items: center;
|
|
1187
|
+
gap: 0;
|
|
1188
|
+
z-index: 9999;
|
|
1189
|
+
min-width: auto;
|
|
1190
|
+
transform-origin: top right;
|
|
1191
|
+
animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
|
1192
|
+
overflow: hidden;
|
|
1193
|
+
`;
|
|
1194
|
+
injectKeyframes(styleTarget);
|
|
1195
|
+
const settingsRow = document.createElement("div");
|
|
1196
|
+
settingsRow.style.cssText = `
|
|
1197
|
+
display: flex;
|
|
1198
|
+
flex-direction: row;
|
|
1199
|
+
align-items: center;
|
|
1200
|
+
padding: 8px;
|
|
1201
|
+
gap: 4px;
|
|
1202
|
+
`;
|
|
1203
|
+
const createOption = (icon, label, onClick, isActive = false, isDestructive = false) => {
|
|
1204
|
+
const btn = document.createElement("div");
|
|
1205
|
+
btn.style.cssText = `
|
|
1206
|
+
display: flex;
|
|
1207
|
+
flex-direction: column;
|
|
1208
|
+
align-items: center;
|
|
1209
|
+
gap: 4px;
|
|
1210
|
+
padding: 8px 12px;
|
|
1211
|
+
cursor: pointer;
|
|
1212
|
+
border-radius: ${aeroTheme.borderRadius.md};
|
|
1213
|
+
background-color: ${isActive ? "rgba(16, 185, 129, 0.15)" : isDestructive ? "rgba(239, 68, 68, 0.1)" : "transparent"};
|
|
1214
|
+
color: ${isActive ? "#10b981" : isDestructive ? "#ef4444" : `var(--convai-panel-fg, ${aeroTheme.colors.text.primary})`};
|
|
1215
|
+
transition: ${aeroTheme.transitions.fast};
|
|
1216
|
+
min-width: 50px;
|
|
1217
|
+
`;
|
|
1218
|
+
const iconContainer = document.createElement("div");
|
|
1219
|
+
iconContainer.appendChild(icon);
|
|
1220
|
+
btn.appendChild(iconContainer);
|
|
1221
|
+
const span = document.createElement("span");
|
|
1222
|
+
span.textContent = label;
|
|
1223
|
+
span.style.cssText = `
|
|
1224
|
+
font-size: 10px;
|
|
1225
|
+
font-weight: 500;
|
|
1226
|
+
`;
|
|
1227
|
+
btn.appendChild(span);
|
|
1228
|
+
btn.addEventListener("click", (e) => {
|
|
1229
|
+
e.stopPropagation();
|
|
1230
|
+
onClick();
|
|
1231
|
+
});
|
|
1232
|
+
btn.addEventListener("mouseover", () => {
|
|
1233
|
+
btn.style.transform = "scale(1.02)";
|
|
1234
|
+
if (!isActive && !isDestructive) {
|
|
1235
|
+
btn.style.backgroundColor = aeroTheme.colors.neutral[100];
|
|
1236
|
+
}
|
|
1237
|
+
});
|
|
1238
|
+
btn.addEventListener("mouseout", () => {
|
|
1239
|
+
btn.style.transform = "scale(1)";
|
|
1240
|
+
btn.style.backgroundColor = isActive ? "rgba(16, 185, 129, 0.15)" : isDestructive ? "rgba(239, 68, 68, 0.1)" : "transparent";
|
|
1241
|
+
});
|
|
1242
|
+
return btn;
|
|
1243
|
+
};
|
|
1244
|
+
const resetIcon = Icons.Redo("md");
|
|
1245
|
+
resetIcon.style.width = "18px";
|
|
1246
|
+
resetIcon.style.height = "18px";
|
|
1247
|
+
if (!client.isPublishedChatSession || requestPublicationGrant) {
|
|
1248
|
+
settingsRow.appendChild(createOption(resetIcon, "Reset", handleReset));
|
|
1249
|
+
}
|
|
1250
|
+
const connectionType = client.connectionType;
|
|
1251
|
+
if (connectionType === "video" && showVideo) {
|
|
1252
|
+
const videoIcon = isVideoVisible ? Icons.Video("md") : Icons.VideoOff("md");
|
|
1253
|
+
videoIcon.style.width = "18px";
|
|
1254
|
+
videoIcon.style.height = "18px";
|
|
1255
|
+
const videoBtn = createOption(
|
|
1256
|
+
videoIcon,
|
|
1257
|
+
"Video",
|
|
1258
|
+
handleToggleVideo,
|
|
1259
|
+
isVideoVisible
|
|
1260
|
+
);
|
|
1261
|
+
videoBtn.id = "convai-settings-video-btn";
|
|
1262
|
+
refs.settingsVideoBtn = videoBtn;
|
|
1263
|
+
settingsRow.appendChild(videoBtn);
|
|
1264
|
+
}
|
|
1265
|
+
if (connectionType === "video" && showScreenShare) {
|
|
1266
|
+
const isSharing = client.screenShareControls.isScreenShareActive;
|
|
1267
|
+
const shareIcon = isSharing ? Icons.StopScreenShare("md") : Icons.ScreenShare("md");
|
|
1268
|
+
shareIcon.style.width = "18px";
|
|
1269
|
+
shareIcon.style.height = "18px";
|
|
1270
|
+
const shareBtn = createOption(
|
|
1271
|
+
shareIcon,
|
|
1272
|
+
"Screen",
|
|
1273
|
+
handleToggleScreenShare,
|
|
1274
|
+
isSharing
|
|
1275
|
+
);
|
|
1276
|
+
shareBtn.id = "convai-settings-share-btn";
|
|
1277
|
+
refs.settingsShareBtn = shareBtn;
|
|
1278
|
+
settingsRow.appendChild(shareBtn);
|
|
1279
|
+
}
|
|
1280
|
+
const disconnectIcon = document.createElement("span");
|
|
1281
|
+
disconnectIcon.innerHTML = "⏻";
|
|
1282
|
+
disconnectIcon.style.fontSize = "18px";
|
|
1283
|
+
if (!client.isPublishedChatSession || requestPublicationGrant) {
|
|
1284
|
+
settingsRow.appendChild(
|
|
1285
|
+
createOption(disconnectIcon, "Disconnect", handleDisconnect, false, true)
|
|
1286
|
+
);
|
|
1287
|
+
}
|
|
1288
|
+
tray.appendChild(settingsRow);
|
|
1289
|
+
return tray;
|
|
1290
|
+
};
|
|
1291
|
+
const updateSettingsTray = () => {
|
|
1292
|
+
const settingsRow = settingsTray.querySelector("div");
|
|
1293
|
+
if (!settingsRow) return;
|
|
1294
|
+
settingsRow.innerHTML = "";
|
|
1295
|
+
const createOption = (icon, label, onClick, isActive = false, isDestructive = false) => {
|
|
1296
|
+
const btn = document.createElement("div");
|
|
1297
|
+
btn.style.cssText = `
|
|
1298
|
+
display: flex;
|
|
1299
|
+
flex-direction: column;
|
|
1300
|
+
align-items: center;
|
|
1301
|
+
gap: 4px;
|
|
1302
|
+
padding: 8px 12px;
|
|
1303
|
+
cursor: pointer;
|
|
1304
|
+
border-radius: ${aeroTheme.borderRadius.md};
|
|
1305
|
+
background-color: ${isActive ? "rgba(16, 185, 129, 0.15)" : isDestructive ? "rgba(239, 68, 68, 0.1)" : "transparent"};
|
|
1306
|
+
color: ${isActive ? "#10b981" : isDestructive ? "#ef4444" : `var(--convai-panel-fg, ${aeroTheme.colors.text.primary})`};
|
|
1307
|
+
transition: ${aeroTheme.transitions.fast};
|
|
1308
|
+
min-width: 50px;
|
|
1309
|
+
`;
|
|
1310
|
+
const iconContainer = document.createElement("div");
|
|
1311
|
+
iconContainer.appendChild(icon);
|
|
1312
|
+
btn.appendChild(iconContainer);
|
|
1313
|
+
const span = document.createElement("span");
|
|
1314
|
+
span.textContent = label;
|
|
1315
|
+
span.style.cssText = `
|
|
1316
|
+
font-size: 10px;
|
|
1317
|
+
font-weight: 500;
|
|
1318
|
+
`;
|
|
1319
|
+
btn.appendChild(span);
|
|
1320
|
+
btn.addEventListener("click", (e) => {
|
|
1321
|
+
e.stopPropagation();
|
|
1322
|
+
onClick();
|
|
1323
|
+
});
|
|
1324
|
+
btn.addEventListener("mouseover", () => {
|
|
1325
|
+
btn.style.transform = "scale(1.02)";
|
|
1326
|
+
if (!isActive && !isDestructive) {
|
|
1327
|
+
btn.style.backgroundColor = aeroTheme.colors.neutral[100];
|
|
1328
|
+
}
|
|
1329
|
+
});
|
|
1330
|
+
btn.addEventListener("mouseout", () => {
|
|
1331
|
+
btn.style.transform = "scale(1)";
|
|
1332
|
+
btn.style.backgroundColor = isActive ? "rgba(16, 185, 129, 0.15)" : isDestructive ? "rgba(239, 68, 68, 0.1)" : "transparent";
|
|
1333
|
+
});
|
|
1334
|
+
return btn;
|
|
1335
|
+
};
|
|
1336
|
+
const resetIcon = Icons.Redo("md");
|
|
1337
|
+
resetIcon.style.width = "18px";
|
|
1338
|
+
resetIcon.style.height = "18px";
|
|
1339
|
+
if (!client.isPublishedChatSession || requestPublicationGrant) {
|
|
1340
|
+
settingsRow.appendChild(createOption(resetIcon, "Reset", handleReset));
|
|
1341
|
+
}
|
|
1342
|
+
const connectionType = client.connectionType;
|
|
1343
|
+
if (connectionType === "video" && showVideo) {
|
|
1344
|
+
const videoIcon = isVideoVisible ? Icons.Video("md") : Icons.VideoOff("md");
|
|
1345
|
+
videoIcon.style.width = "18px";
|
|
1346
|
+
videoIcon.style.height = "18px";
|
|
1347
|
+
const videoBtn = createOption(
|
|
1348
|
+
videoIcon,
|
|
1349
|
+
"Video",
|
|
1350
|
+
handleToggleVideo,
|
|
1351
|
+
isVideoVisible
|
|
1352
|
+
);
|
|
1353
|
+
videoBtn.id = "convai-settings-video-btn";
|
|
1354
|
+
refs.settingsVideoBtn = videoBtn;
|
|
1355
|
+
settingsRow.appendChild(videoBtn);
|
|
1356
|
+
}
|
|
1357
|
+
if (connectionType === "video" && showScreenShare) {
|
|
1358
|
+
const isSharing = client.screenShareControls.isScreenShareActive;
|
|
1359
|
+
const shareIcon = isSharing ? Icons.StopScreenShare("md") : Icons.ScreenShare("md");
|
|
1360
|
+
shareIcon.style.width = "18px";
|
|
1361
|
+
shareIcon.style.height = "18px";
|
|
1362
|
+
const shareBtn = createOption(
|
|
1363
|
+
shareIcon,
|
|
1364
|
+
"Screen",
|
|
1365
|
+
handleToggleScreenShare,
|
|
1366
|
+
isSharing
|
|
1367
|
+
);
|
|
1368
|
+
shareBtn.id = "convai-settings-share-btn";
|
|
1369
|
+
refs.settingsShareBtn = shareBtn;
|
|
1370
|
+
settingsRow.appendChild(shareBtn);
|
|
1371
|
+
}
|
|
1372
|
+
const disconnectIcon = document.createElement("span");
|
|
1373
|
+
disconnectIcon.innerHTML = "⏻";
|
|
1374
|
+
disconnectIcon.style.fontSize = "18px";
|
|
1375
|
+
if (!client.isPublishedChatSession || requestPublicationGrant) {
|
|
1376
|
+
settingsRow.appendChild(
|
|
1377
|
+
createOption(disconnectIcon, "Disconnect", handleDisconnect, false, true)
|
|
1378
|
+
);
|
|
1379
|
+
}
|
|
1380
|
+
};
|
|
1381
|
+
const createFloatingVideo = () => {
|
|
1382
|
+
const container2 = document.createElement("div");
|
|
1383
|
+
container2.id = "floating-video-container";
|
|
1384
|
+
container2.style.cssText = `
|
|
1385
|
+
position: fixed;
|
|
1386
|
+
left: 20px;
|
|
1387
|
+
top: 20px;
|
|
1388
|
+
z-index: 10000;
|
|
1389
|
+
width: 320px;
|
|
1390
|
+
border-radius: ${aeroTheme.borderRadius.lg};
|
|
1391
|
+
overflow: hidden;
|
|
1392
|
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
|
1393
|
+
cursor: grab;
|
|
1394
|
+
display: none;
|
|
1395
|
+
transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1), transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
|
|
1396
|
+
`;
|
|
1397
|
+
const wrapper = document.createElement("div");
|
|
1398
|
+
wrapper.style.cssText = `
|
|
1399
|
+
background: rgba(15, 23, 42, 0.95);
|
|
1400
|
+
backdrop-filter: blur(20px);
|
|
1401
|
+
border: 1px solid ${aeroTheme.colors.neutral[700]};
|
|
1402
|
+
border-radius: ${aeroTheme.borderRadius.lg};
|
|
1403
|
+
overflow: hidden;
|
|
1404
|
+
`;
|
|
1405
|
+
const header = document.createElement("div");
|
|
1406
|
+
header.style.cssText = `
|
|
1407
|
+
display: flex;
|
|
1408
|
+
align-items: center;
|
|
1409
|
+
justify-content: space-between;
|
|
1410
|
+
padding: 8px 12px;
|
|
1411
|
+
background: rgba(0, 0, 0, 0.3);
|
|
1412
|
+
border-bottom: 1px solid ${aeroTheme.colors.neutral[700]};
|
|
1413
|
+
`;
|
|
1414
|
+
const headerLeft = document.createElement("div");
|
|
1415
|
+
headerLeft.style.cssText = `
|
|
1416
|
+
display: flex;
|
|
1417
|
+
align-items: center;
|
|
1418
|
+
gap: 8px;
|
|
1419
|
+
color: ${aeroTheme.colors.neutral[300]};
|
|
1420
|
+
font-size: 12px;
|
|
1421
|
+
font-weight: 500;
|
|
1422
|
+
`;
|
|
1423
|
+
const dragIcon = Icons.DragIndicator("sm");
|
|
1424
|
+
dragIcon.style.width = "16px";
|
|
1425
|
+
dragIcon.style.height = "16px";
|
|
1426
|
+
headerLeft.appendChild(dragIcon);
|
|
1427
|
+
const label = document.createElement("span");
|
|
1428
|
+
label.textContent = "Your Camera";
|
|
1429
|
+
headerLeft.appendChild(label);
|
|
1430
|
+
const closeButton = document.createElement("button");
|
|
1431
|
+
closeButton.innerHTML = "";
|
|
1432
|
+
const closeIcon = Icons.Close("md");
|
|
1433
|
+
closeIcon.style.width = "20px";
|
|
1434
|
+
closeIcon.style.height = "20px";
|
|
1435
|
+
closeButton.appendChild(closeIcon);
|
|
1436
|
+
closeButton.style.cssText = `
|
|
1437
|
+
background: transparent;
|
|
1438
|
+
border: none;
|
|
1439
|
+
color: ${aeroTheme.colors.neutral[400]};
|
|
1440
|
+
cursor: pointer;
|
|
1441
|
+
display: flex;
|
|
1442
|
+
align-items: center;
|
|
1443
|
+
justify-content: center;
|
|
1444
|
+
padding: 4px;
|
|
1445
|
+
transition: transform 0.1s ease-out;
|
|
1446
|
+
`;
|
|
1447
|
+
closeButton.addEventListener("click", (e) => {
|
|
1448
|
+
e.stopPropagation();
|
|
1449
|
+
client.videoControls.disableVideo();
|
|
1450
|
+
});
|
|
1451
|
+
closeButton.addEventListener("mouseenter", () => {
|
|
1452
|
+
closeButton.style.transform = "scale(1.1)";
|
|
1453
|
+
});
|
|
1454
|
+
closeButton.addEventListener("mouseleave", () => {
|
|
1455
|
+
closeButton.style.transform = "scale(1)";
|
|
1456
|
+
});
|
|
1457
|
+
header.appendChild(headerLeft);
|
|
1458
|
+
header.appendChild(closeButton);
|
|
1459
|
+
const videoContainer = document.createElement("div");
|
|
1460
|
+
videoContainer.style.cssText = `
|
|
1461
|
+
position: relative;
|
|
1462
|
+
width: 100%;
|
|
1463
|
+
padding-bottom: 75%;
|
|
1464
|
+
background: #000;
|
|
1465
|
+
`;
|
|
1466
|
+
const videoWrapper = document.createElement("div");
|
|
1467
|
+
videoWrapper.id = "floating-video-wrapper";
|
|
1468
|
+
videoWrapper.style.cssText = `
|
|
1469
|
+
position: absolute;
|
|
1470
|
+
top: 0;
|
|
1471
|
+
left: 0;
|
|
1472
|
+
width: 100%;
|
|
1473
|
+
height: 100%;
|
|
1474
|
+
`;
|
|
1475
|
+
const videoElement = document.createElement("video");
|
|
1476
|
+
videoElement.id = "floating-video-element";
|
|
1477
|
+
videoElement.autoplay = true;
|
|
1478
|
+
videoElement.playsInline = true;
|
|
1479
|
+
videoElement.muted = true;
|
|
1480
|
+
videoElement.style.cssText = `
|
|
1481
|
+
width: 100%;
|
|
1482
|
+
height: 100%;
|
|
1483
|
+
object-fit: cover;
|
|
1484
|
+
transform: scaleX(-1);
|
|
1485
|
+
`;
|
|
1486
|
+
const cameraOffPlaceholder = document.createElement("div");
|
|
1487
|
+
cameraOffPlaceholder.id = "camera-off-placeholder";
|
|
1488
|
+
cameraOffPlaceholder.style.cssText = `
|
|
1489
|
+
width: 100%;
|
|
1490
|
+
height: 100%;
|
|
1491
|
+
display: flex;
|
|
1492
|
+
flex-direction: column;
|
|
1493
|
+
align-items: center;
|
|
1494
|
+
justify-content: center;
|
|
1495
|
+
color: ${aeroTheme.colors.neutral[400]};
|
|
1496
|
+
gap: 12px;
|
|
1497
|
+
background: #000;
|
|
1498
|
+
`;
|
|
1499
|
+
const cameraOffIcon = Icons.VideoOff("lg");
|
|
1500
|
+
cameraOffIcon.style.width = "48px";
|
|
1501
|
+
cameraOffIcon.style.height = "48px";
|
|
1502
|
+
cameraOffPlaceholder.appendChild(cameraOffIcon);
|
|
1503
|
+
const cameraOffText = document.createElement("span");
|
|
1504
|
+
cameraOffText.textContent = "Camera is off";
|
|
1505
|
+
cameraOffText.style.cssText = `
|
|
1506
|
+
font-size: 14px;
|
|
1507
|
+
text-align: center;
|
|
1508
|
+
`;
|
|
1509
|
+
cameraOffPlaceholder.appendChild(cameraOffText);
|
|
1510
|
+
videoWrapper.appendChild(videoElement);
|
|
1511
|
+
videoWrapper.appendChild(cameraOffPlaceholder);
|
|
1512
|
+
videoContainer.appendChild(videoWrapper);
|
|
1513
|
+
wrapper.appendChild(header);
|
|
1514
|
+
wrapper.appendChild(videoContainer);
|
|
1515
|
+
container2.appendChild(wrapper);
|
|
1516
|
+
let isDragging = false;
|
|
1517
|
+
let startX = 0;
|
|
1518
|
+
let startY = 0;
|
|
1519
|
+
let startLeft = 20;
|
|
1520
|
+
let startTop = 20;
|
|
1521
|
+
const handleMouseDown = (e) => {
|
|
1522
|
+
if (e.target.closest("button")) return;
|
|
1523
|
+
isDragging = true;
|
|
1524
|
+
startX = e.clientX;
|
|
1525
|
+
startY = e.clientY;
|
|
1526
|
+
const style = window.getComputedStyle(container2);
|
|
1527
|
+
startLeft = parseInt(style.left);
|
|
1528
|
+
startTop = parseInt(style.top);
|
|
1529
|
+
container2.style.cursor = "grabbing";
|
|
1530
|
+
e.preventDefault();
|
|
1531
|
+
};
|
|
1532
|
+
const handleMouseMove = (e) => {
|
|
1533
|
+
if (!isDragging) return;
|
|
1534
|
+
const deltaX = e.clientX - startX;
|
|
1535
|
+
const deltaY = e.clientY - startY;
|
|
1536
|
+
const newLeft = startLeft + deltaX;
|
|
1537
|
+
const newTop = startTop + deltaY;
|
|
1538
|
+
const maxX = window.innerWidth - 320;
|
|
1539
|
+
const maxY = window.innerHeight - 240;
|
|
1540
|
+
const boundedLeft = Math.max(0, Math.min(newLeft, maxX));
|
|
1541
|
+
const boundedTop = Math.max(0, Math.min(newTop, maxY));
|
|
1542
|
+
container2.style.left = `${boundedLeft}px`;
|
|
1543
|
+
container2.style.top = `${boundedTop}px`;
|
|
1544
|
+
};
|
|
1545
|
+
const handleMouseUp = () => {
|
|
1546
|
+
if (isDragging) {
|
|
1547
|
+
isDragging = false;
|
|
1548
|
+
container2.style.cursor = "grab";
|
|
1549
|
+
}
|
|
1550
|
+
};
|
|
1551
|
+
container2.addEventListener("mousedown", handleMouseDown);
|
|
1552
|
+
document.addEventListener("mousemove", handleMouseMove);
|
|
1553
|
+
document.addEventListener("mouseup", handleMouseUp);
|
|
1554
|
+
return container2;
|
|
1555
|
+
};
|
|
1556
|
+
const handleToggle = async () => {
|
|
1557
|
+
if (isDestroyed) return;
|
|
1558
|
+
if (isOpen || pendingOpen) {
|
|
1559
|
+
return;
|
|
1560
|
+
}
|
|
1561
|
+
if (!client.state.isConnected && !client.state.isConnecting) {
|
|
1562
|
+
pendingOpen = true;
|
|
1563
|
+
try {
|
|
1564
|
+
if (requestPublicationGrant || client.isPublishedChatSession) {
|
|
1565
|
+
if (!requestPublicationGrant) {
|
|
1566
|
+
throw new Error(
|
|
1567
|
+
"Published chat widgets require requestPublicationGrant to start a new session"
|
|
1568
|
+
);
|
|
1569
|
+
}
|
|
1570
|
+
if (!client.connectWithPublicationGrant) {
|
|
1571
|
+
throw new Error(
|
|
1572
|
+
"This Convai client does not support published chat connections"
|
|
1573
|
+
);
|
|
1574
|
+
}
|
|
1575
|
+
const launchToken = await requestPublicationGrant();
|
|
1576
|
+
if (isDestroyed) {
|
|
1577
|
+
return;
|
|
1578
|
+
}
|
|
1579
|
+
await client.connectWithPublicationGrant(
|
|
1580
|
+
launchToken,
|
|
1581
|
+
freshPublicationGrantOptions(publishedChatConnectOptions)
|
|
1582
|
+
);
|
|
1583
|
+
} else if (hasConnectedBefore && typeof client.reconnect === "function") {
|
|
1584
|
+
await client.reconnect();
|
|
1585
|
+
} else {
|
|
1586
|
+
await client.connect();
|
|
1587
|
+
}
|
|
1588
|
+
if (isDestroyed) {
|
|
1589
|
+
await client.disconnect();
|
|
1590
|
+
return;
|
|
1591
|
+
}
|
|
1592
|
+
if (isDestroyed) {
|
|
1593
|
+
await client.disconnect();
|
|
1594
|
+
return;
|
|
1595
|
+
}
|
|
1596
|
+
if (!pendingOpen) return;
|
|
1597
|
+
setIsOpen(true);
|
|
1598
|
+
} catch (error) {
|
|
1599
|
+
if (!isDestroyed) {
|
|
1600
|
+
console.error("Failed to connect:", error);
|
|
1601
|
+
}
|
|
1602
|
+
} finally {
|
|
1603
|
+
pendingOpen = false;
|
|
1604
|
+
}
|
|
1605
|
+
} else {
|
|
1606
|
+
setIsOpen(!isOpen);
|
|
1607
|
+
}
|
|
1608
|
+
};
|
|
1609
|
+
const handleLauncherClick = () => {
|
|
1610
|
+
if (pendingOpen) {
|
|
1611
|
+
handleClose();
|
|
1612
|
+
return;
|
|
1613
|
+
}
|
|
1614
|
+
void handleToggle();
|
|
1615
|
+
};
|
|
1616
|
+
const handleClose = () => {
|
|
1617
|
+
pendingOpen = false;
|
|
1618
|
+
setIsOpen(false);
|
|
1619
|
+
};
|
|
1620
|
+
const requiresBotReadyForText = () => Boolean(requestPublicationGrant) || Boolean(client.isPublishedChatSession);
|
|
1621
|
+
const isTextInputReady = () => client.state.isConnected && (!requiresBotReadyForText() || client.isBotReady);
|
|
1622
|
+
const handleSend = () => {
|
|
1623
|
+
if (inputValue.trim() && isTextInputReady()) {
|
|
1624
|
+
client.sendUserTextMessage(inputValue);
|
|
1625
|
+
inputValue = "";
|
|
1626
|
+
inputElement.value = "";
|
|
1627
|
+
updateSendButton();
|
|
1628
|
+
}
|
|
1629
|
+
};
|
|
1630
|
+
const handleToggleMute = () => {
|
|
1631
|
+
isMuted = !isMuted;
|
|
1632
|
+
client.setCharacterMuted(isMuted);
|
|
1633
|
+
updateHeader();
|
|
1634
|
+
};
|
|
1635
|
+
const handleReset = async () => {
|
|
1636
|
+
setIsSettingsOpen(false);
|
|
1637
|
+
try {
|
|
1638
|
+
await client.disconnect();
|
|
1639
|
+
client.resetSession();
|
|
1640
|
+
isMuted = false;
|
|
1641
|
+
isVoiceMode = false;
|
|
1642
|
+
hasEnteredDefaultVoiceMode = false;
|
|
1643
|
+
updateHeader();
|
|
1644
|
+
await updateVoiceMode();
|
|
1645
|
+
updateSendButton();
|
|
1646
|
+
} catch (error) {
|
|
1647
|
+
console.error("Failed to reset:", error);
|
|
1648
|
+
}
|
|
1649
|
+
};
|
|
1650
|
+
const handleDisconnect = async () => {
|
|
1651
|
+
setIsSettingsOpen(false);
|
|
1652
|
+
await client.disconnect();
|
|
1653
|
+
isMuted = false;
|
|
1654
|
+
isVoiceMode = false;
|
|
1655
|
+
hasEnteredDefaultVoiceMode = false;
|
|
1656
|
+
updateHeader();
|
|
1657
|
+
applyVoiceMode();
|
|
1658
|
+
updateSendButton();
|
|
1659
|
+
};
|
|
1660
|
+
const handleToggleVideo = async () => {
|
|
1661
|
+
if (client.connectionType !== "video") return;
|
|
1662
|
+
try {
|
|
1663
|
+
if (isVideoVisible) {
|
|
1664
|
+
await client.videoControls.disableVideo();
|
|
1665
|
+
} else {
|
|
1666
|
+
await client.videoControls.enableVideo();
|
|
1667
|
+
}
|
|
1668
|
+
} catch (e) {
|
|
1669
|
+
console.error("Failed to toggle video:", e);
|
|
1670
|
+
}
|
|
1671
|
+
};
|
|
1672
|
+
const handleToggleScreenShare = async () => {
|
|
1673
|
+
try {
|
|
1674
|
+
await client.screenShareControls.toggleScreenShare();
|
|
1675
|
+
} catch (e) {
|
|
1676
|
+
console.error("Failed to toggle screen share:", e);
|
|
1677
|
+
}
|
|
1678
|
+
};
|
|
1679
|
+
const handleSettingsToggle = () => {
|
|
1680
|
+
if (!isSettingsOpen) {
|
|
1681
|
+
updateSettingsTray();
|
|
1682
|
+
}
|
|
1683
|
+
setIsSettingsOpen(!isSettingsOpen);
|
|
1684
|
+
};
|
|
1685
|
+
const setIsOpen = async (open) => {
|
|
1686
|
+
isOpen = open;
|
|
1687
|
+
if (open) {
|
|
1688
|
+
morphingContainer.style.width = `${PANEL_W_PX}px`;
|
|
1689
|
+
morphingContainer.style.height = `${PANEL_H_PX}px`;
|
|
1690
|
+
morphingContainer.style.borderRadius = `var(--convai-radius, ${aeroTheme.borderRadius.xl})`;
|
|
1691
|
+
morphingContainer.style.cursor = "default";
|
|
1692
|
+
morphingContainer.style.background = "var(--convai-panel-bg, rgba(252, 252, 253, 0.95))";
|
|
1693
|
+
morphingContainer.style.backdropFilter = "blur(20px) saturate(180%)";
|
|
1694
|
+
buttonContent.style.opacity = "0";
|
|
1695
|
+
buttonContent.style.transform = "scale(0.8)";
|
|
1696
|
+
buttonContent.style.pointerEvents = "none";
|
|
1697
|
+
chatContent.style.opacity = "1";
|
|
1698
|
+
chatContent.style.transform = "scale(1)";
|
|
1699
|
+
chatContent.style.pointerEvents = "auto";
|
|
1700
|
+
if (defaultVoiceMode && !requestPublicationGrant && client.connectionType !== "text" && !hasEnteredDefaultVoiceMode && client.state.isConnected) {
|
|
1701
|
+
setTimeout(async () => {
|
|
1702
|
+
try {
|
|
1703
|
+
await client.audioControls.unmuteAudio();
|
|
1704
|
+
isVoiceMode = true;
|
|
1705
|
+
hasEnteredDefaultVoiceMode = true;
|
|
1706
|
+
await updateVoiceMode();
|
|
1707
|
+
} catch (error) {
|
|
1708
|
+
reportMicFailure(client, "Failed to enter voice mode on open:", error);
|
|
1709
|
+
}
|
|
1710
|
+
}, 100);
|
|
1711
|
+
}
|
|
1712
|
+
} else {
|
|
1713
|
+
morphingContainer.style.width = "var(--convai-launcher-size, 64px)";
|
|
1714
|
+
morphingContainer.style.height = "var(--convai-launcher-size, 64px)";
|
|
1715
|
+
morphingContainer.style.borderRadius = "50%";
|
|
1716
|
+
morphingContainer.style.cursor = "pointer";
|
|
1717
|
+
morphingContainer.style.background = `var(--convai-panel-bg, ${aeroTheme.colors.glass.backdrop})`;
|
|
1718
|
+
morphingContainer.style.backdropFilter = aeroTheme.glass.backdrop;
|
|
1719
|
+
buttonContent.style.opacity = "1";
|
|
1720
|
+
buttonContent.style.transform = "scale(1)";
|
|
1721
|
+
buttonContent.style.pointerEvents = "auto";
|
|
1722
|
+
chatContent.style.opacity = "0";
|
|
1723
|
+
chatContent.style.transform = "scale(0.8)";
|
|
1724
|
+
chatContent.style.pointerEvents = "none";
|
|
1725
|
+
}
|
|
1726
|
+
};
|
|
1727
|
+
const setIsSettingsOpen = (open) => {
|
|
1728
|
+
isSettingsOpen = open;
|
|
1729
|
+
settingsTray.style.display = open ? "flex" : "none";
|
|
1730
|
+
};
|
|
1731
|
+
const updateSendButton = () => {
|
|
1732
|
+
const sendButton = refs.sendButton;
|
|
1733
|
+
if (!sendButton) return;
|
|
1734
|
+
sendButton.innerHTML = "";
|
|
1735
|
+
const isPublishedTextChat = requiresBotReadyForText();
|
|
1736
|
+
const textInputReady = isTextInputReady();
|
|
1737
|
+
inputElement.disabled = isPublishedTextChat && !textInputReady;
|
|
1738
|
+
if (inputValue.length > 0 || requestPublicationGrant || client.connectionType === "text") {
|
|
1739
|
+
sendButton.appendChild(Icons.Send("md"));
|
|
1740
|
+
sendButton.style.background = `var(--convai-accent, ${aeroTheme.colors.text.primary})`;
|
|
1741
|
+
sendButton.style.color = "var(--convai-panel-bg, white)";
|
|
1742
|
+
sendButton.style.border = "none";
|
|
1743
|
+
sendButton.disabled = isPublishedTextChat && (inputValue.length === 0 || !textInputReady);
|
|
1744
|
+
if (isPublishedTextChat) {
|
|
1745
|
+
sendButton.style.opacity = inputValue.length > 0 && textInputReady ? "1" : "0.5";
|
|
1746
|
+
sendButton.title = textInputReady ? inputValue.length > 0 ? "Send" : "Type a message" : "Waiting for character";
|
|
1747
|
+
} else {
|
|
1748
|
+
sendButton.title = "Send";
|
|
1749
|
+
}
|
|
1750
|
+
} else {
|
|
1751
|
+
sendButton.appendChild(Icons.Waveform("md"));
|
|
1752
|
+
sendButton.style.background = "transparent";
|
|
1753
|
+
sendButton.style.color = `var(--convai-panel-fg, ${aeroTheme.colors.text.primary})`;
|
|
1754
|
+
sendButton.style.border = `1px solid ${aeroTheme.colors.neutral[300]}`;
|
|
1755
|
+
sendButton.style.opacity = "1";
|
|
1756
|
+
sendButton.disabled = false;
|
|
1757
|
+
sendButton.title = "Voice Mode";
|
|
1758
|
+
}
|
|
1759
|
+
};
|
|
1760
|
+
const updateVideoTrack = () => {
|
|
1761
|
+
if (!floatingVideo || !client.room || !client.room.localParticipant) return;
|
|
1762
|
+
const videoEl = floatingVideo.querySelector(
|
|
1763
|
+
"#floating-video-element"
|
|
1764
|
+
);
|
|
1765
|
+
const placeholder = floatingVideo.querySelector(
|
|
1766
|
+
"#camera-off-placeholder"
|
|
1767
|
+
);
|
|
1768
|
+
if (!videoEl || !placeholder) return;
|
|
1769
|
+
if (isVideoVisible && !isVoiceMode) {
|
|
1770
|
+
const tracks = Array.from(
|
|
1771
|
+
client.room.localParticipant.videoTrackPublications.values()
|
|
1772
|
+
);
|
|
1773
|
+
const videoPub = tracks.find((t) => t.kind === "video");
|
|
1774
|
+
if (videoPub && videoPub.track) {
|
|
1775
|
+
videoPub.track.attach(videoEl);
|
|
1776
|
+
videoEl.style.display = "block";
|
|
1777
|
+
placeholder.style.display = "none";
|
|
1778
|
+
} else {
|
|
1779
|
+
videoEl.style.display = "none";
|
|
1780
|
+
placeholder.style.display = "flex";
|
|
1781
|
+
}
|
|
1782
|
+
} else {
|
|
1783
|
+
videoEl.style.display = "none";
|
|
1784
|
+
placeholder.style.display = "flex";
|
|
1785
|
+
}
|
|
1786
|
+
};
|
|
1787
|
+
const updateVoiceMode = async () => {
|
|
1788
|
+
const standardFooter = refs.footerStandard;
|
|
1789
|
+
const voiceExitBtn = refs.voiceExitBtn;
|
|
1790
|
+
if (isVoiceMode) {
|
|
1791
|
+
if (voiceModeOverlay) voiceModeOverlay.style.display = "flex";
|
|
1792
|
+
if (messageListElement) messageListElement.style.display = "none";
|
|
1793
|
+
if (floatingVideo) floatingVideo.style.display = "none";
|
|
1794
|
+
if (standardFooter) standardFooter.style.display = "none";
|
|
1795
|
+
if (voiceExitBtn) voiceExitBtn.style.display = "flex";
|
|
1796
|
+
if (footerElement) footerElement.style.justifyContent = "center";
|
|
1797
|
+
updateHeader();
|
|
1798
|
+
startTime = Date.now();
|
|
1799
|
+
startAudioAnalysis();
|
|
1800
|
+
} else {
|
|
1801
|
+
if (!client.audioControls.isAudioMuted) {
|
|
1802
|
+
try {
|
|
1803
|
+
await client.audioControls.muteAudio();
|
|
1804
|
+
} catch (error) {
|
|
1805
|
+
reportMicFailure(client, "Failed to mute microphone:", error);
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
if (voiceModeOverlay) voiceModeOverlay.style.display = "none";
|
|
1809
|
+
if (isVideoVisible) {
|
|
1810
|
+
if (messageListElement) messageListElement.style.display = "none";
|
|
1811
|
+
if (floatingVideo) floatingVideo.style.display = "block";
|
|
1812
|
+
updateVideoTrack();
|
|
1813
|
+
} else {
|
|
1814
|
+
if (messageListElement) messageListElement.style.display = "flex";
|
|
1815
|
+
if (floatingVideo) floatingVideo.style.display = "none";
|
|
1816
|
+
}
|
|
1817
|
+
if (standardFooter) standardFooter.style.display = "flex";
|
|
1818
|
+
if (voiceExitBtn) voiceExitBtn.style.display = "none";
|
|
1819
|
+
if (footerElement) footerElement.style.justifyContent = "flex-start";
|
|
1820
|
+
updateHeader();
|
|
1821
|
+
stopAudioAnalysis();
|
|
1822
|
+
}
|
|
1823
|
+
};
|
|
1824
|
+
const applyVoiceMode = () => {
|
|
1825
|
+
void updateVoiceMode().catch((error) => {
|
|
1826
|
+
reportMicFailure(client, "Failed to apply voice mode:", error);
|
|
1827
|
+
});
|
|
1828
|
+
};
|
|
1829
|
+
const renderMarkdown = (text, container2, { media = true } = {}) => {
|
|
1830
|
+
if (!text) return;
|
|
1831
|
+
const lines = text.replace(/\\n/g, "\n").split("\n");
|
|
1832
|
+
const budget = { cards: 0 };
|
|
1833
|
+
const make = (tag, part, ...styles) => {
|
|
1834
|
+
const node = document.createElement(tag);
|
|
1835
|
+
node.setAttribute("part", part);
|
|
1836
|
+
node.style.cssText = toCssText(Object.assign({}, ...styles));
|
|
1837
|
+
return node;
|
|
1838
|
+
};
|
|
1839
|
+
const focusRing = (node) => {
|
|
1840
|
+
const base = node.style.cssText;
|
|
1841
|
+
node.addEventListener("focus", () => {
|
|
1842
|
+
if (node.matches(":focus-visible")) node.style.cssText = `${base} ${toCssText(presentationStyles.linkFocus)}`;
|
|
1843
|
+
});
|
|
1844
|
+
node.addEventListener("blur", () => {
|
|
1845
|
+
node.style.cssText = base;
|
|
1846
|
+
});
|
|
1847
|
+
};
|
|
1848
|
+
const anchor = (href, kind, label) => {
|
|
1849
|
+
const a = make("a", "message-link", presentationStyles.link);
|
|
1850
|
+
a.href = href;
|
|
1851
|
+
a.target = "_blank";
|
|
1852
|
+
a.rel = "noopener noreferrer";
|
|
1853
|
+
const display = label === href ? compactUrl(label) : label;
|
|
1854
|
+
a.textContent = display;
|
|
1855
|
+
const title = hoverTitle(kind, href, display);
|
|
1856
|
+
if (title) a.title = title;
|
|
1857
|
+
if (kind === "ftp") {
|
|
1858
|
+
const badge = make("span", "message-link-badge", presentationStyles.badge);
|
|
1859
|
+
badge.textContent = "FTP";
|
|
1860
|
+
a.appendChild(badge);
|
|
1861
|
+
}
|
|
1862
|
+
focusRing(a);
|
|
1863
|
+
return a;
|
|
1864
|
+
};
|
|
1865
|
+
const contactChip = (href, kind) => {
|
|
1866
|
+
const a = make("a", "message-contact", presentationStyles.contact);
|
|
1867
|
+
a.href = href;
|
|
1868
|
+
a.title = hoverTitle(kind, href, href);
|
|
1869
|
+
const g = make("span", "message-contact-glyph", presentationStyles.contactGlyph);
|
|
1870
|
+
g.innerHTML = glyph(kind);
|
|
1871
|
+
const t = document.createElement("span");
|
|
1872
|
+
t.textContent = contactLabel(href);
|
|
1873
|
+
a.append(g, t);
|
|
1874
|
+
focusRing(a);
|
|
1875
|
+
return a;
|
|
1876
|
+
};
|
|
1877
|
+
const documentCard = (href) => {
|
|
1878
|
+
let host = "";
|
|
1879
|
+
try {
|
|
1880
|
+
host = new URL(href).host;
|
|
1881
|
+
} catch {
|
|
1882
|
+
}
|
|
1883
|
+
const a = make("a", "message-file-card", presentationStyles.fileCard);
|
|
1884
|
+
a.href = href;
|
|
1885
|
+
a.target = "_blank";
|
|
1886
|
+
a.rel = "noopener noreferrer";
|
|
1887
|
+
a.title = href;
|
|
1888
|
+
const icon = make("span", "message-file-icon", presentationStyles.fileIcon);
|
|
1889
|
+
icon.textContent = documentBadge(href);
|
|
1890
|
+
const body = document.createElement("span");
|
|
1891
|
+
body.style.cssText = toCssText(presentationStyles.fileBody);
|
|
1892
|
+
const name = make("span", "message-file-name", presentationStyles.fileName);
|
|
1893
|
+
name.textContent = fileNameOf(href);
|
|
1894
|
+
const meta = make("span", "message-file-meta", presentationStyles.fileMeta);
|
|
1895
|
+
meta.textContent = `${host} · Opens in a new tab`;
|
|
1896
|
+
body.append(name, meta);
|
|
1897
|
+
a.append(icon, body);
|
|
1898
|
+
focusRing(a);
|
|
1899
|
+
return a;
|
|
1900
|
+
};
|
|
1901
|
+
const siteCard = (href) => {
|
|
1902
|
+
const resolver = options.linkPreviewResolver;
|
|
1903
|
+
const slot = document.createComment("site-card");
|
|
1904
|
+
if (!resolver) return slot;
|
|
1905
|
+
resolveLinkPreviewCached(resolver, href).then((meta) => {
|
|
1906
|
+
if (!isCardWorthy(meta) || !slot.parentNode) return;
|
|
1907
|
+
const a = make("a", "message-site-card", presentationStyles.siteCard);
|
|
1908
|
+
a.href = href;
|
|
1909
|
+
a.target = "_blank";
|
|
1910
|
+
a.rel = "noopener noreferrer";
|
|
1911
|
+
const header = document.createElement("span");
|
|
1912
|
+
header.style.cssText = toCssText(presentationStyles.siteHeader);
|
|
1913
|
+
const favicon = faviconFor(meta, href);
|
|
1914
|
+
if (favicon) {
|
|
1915
|
+
const icon = make("img", "message-site-favicon", presentationStyles.siteFavicon);
|
|
1916
|
+
icon.src = favicon;
|
|
1917
|
+
icon.alt = "";
|
|
1918
|
+
icon.addEventListener("error", () => icon.remove());
|
|
1919
|
+
header.appendChild(icon);
|
|
1920
|
+
}
|
|
1921
|
+
const name = make("span", "message-site-name", presentationStyles.siteName);
|
|
1922
|
+
name.textContent = siteNameFor(meta, href);
|
|
1923
|
+
header.appendChild(name);
|
|
1924
|
+
a.appendChild(header);
|
|
1925
|
+
if (meta.title) {
|
|
1926
|
+
const t = make("span", "message-site-title", presentationStyles.siteTitle);
|
|
1927
|
+
t.textContent = meta.title;
|
|
1928
|
+
a.appendChild(t);
|
|
1929
|
+
}
|
|
1930
|
+
if (meta.description) {
|
|
1931
|
+
const d = make("span", "message-site-description", presentationStyles.siteDescription);
|
|
1932
|
+
d.textContent = meta.description;
|
|
1933
|
+
a.appendChild(d);
|
|
1934
|
+
}
|
|
1935
|
+
if (meta.image) {
|
|
1936
|
+
const img = make("img", "message-site-image", presentationStyles.siteImage);
|
|
1937
|
+
img.src = meta.image;
|
|
1938
|
+
img.alt = "";
|
|
1939
|
+
img.loading = "lazy";
|
|
1940
|
+
img.addEventListener("error", () => img.remove());
|
|
1941
|
+
a.appendChild(img);
|
|
1942
|
+
}
|
|
1943
|
+
focusRing(a);
|
|
1944
|
+
slot.replaceWith(a);
|
|
1945
|
+
});
|
|
1946
|
+
return slot;
|
|
1947
|
+
};
|
|
1948
|
+
const unavailable = (src, insecure) => {
|
|
1949
|
+
const dead = make("span", "message-media-unavailable", presentationStyles.unavailable);
|
|
1950
|
+
dead.textContent = `Preview unavailable — ${describeUrl(src)}${insecure ? " (insecure URL)" : ""}`;
|
|
1951
|
+
return dead;
|
|
1952
|
+
};
|
|
1953
|
+
const mediaPreview = (src, alt, kind) => {
|
|
1954
|
+
const frag = document.createDocumentFragment();
|
|
1955
|
+
if (isMixedContent(src)) {
|
|
1956
|
+
frag.appendChild(unavailable(src, true));
|
|
1957
|
+
return frag;
|
|
1958
|
+
}
|
|
1959
|
+
const card = make("span", "message-media-card", presentationStyles.card, kind === "image" ? presentationStyles.cardButton : {});
|
|
1960
|
+
const el = kind === "image" ? Object.assign(document.createElement("img"), { src, alt, loading: "lazy" }) : Object.assign(document.createElement("video"), { src, controls: true, preload: "metadata" });
|
|
1961
|
+
el.setAttribute("part", "message-media");
|
|
1962
|
+
el.style.cssText = toCssText(
|
|
1963
|
+
Object.assign({}, presentationStyles.media, kind === "video" ? presentationStyles.videoMedia : {}, { opacity: 0 })
|
|
1964
|
+
);
|
|
1965
|
+
const skeleton = make("span", "message-media-skeleton", presentationStyles.skeleton);
|
|
1966
|
+
skeleton.setAttribute("aria-hidden", "true");
|
|
1967
|
+
skeleton.dataset.convaiSkeleton = "";
|
|
1968
|
+
const caption = make("span", "message-media-caption", presentationStyles.caption);
|
|
1969
|
+
caption.textContent = describeUrl(src);
|
|
1970
|
+
const fail = () => {
|
|
1971
|
+
clearTimeout(timer);
|
|
1972
|
+
card.replaceWith(unavailable(src, false));
|
|
1973
|
+
caption.remove();
|
|
1974
|
+
};
|
|
1975
|
+
const settled = () => {
|
|
1976
|
+
clearTimeout(timer);
|
|
1977
|
+
el.style.opacity = "1";
|
|
1978
|
+
skeleton.remove();
|
|
1979
|
+
if (kind === "image") {
|
|
1980
|
+
const zoom = make("span", "message-media-zoom", presentationStyles.zoom);
|
|
1981
|
+
zoom.innerHTML = glyph("zoom");
|
|
1982
|
+
card.appendChild(zoom);
|
|
1983
|
+
}
|
|
1984
|
+
};
|
|
1985
|
+
const timer = setTimeout(fail, PREVIEW_TIMEOUT_MS);
|
|
1986
|
+
el.addEventListener(kind === "image" ? "load" : "loadedmetadata", settled);
|
|
1987
|
+
el.addEventListener("error", fail);
|
|
1988
|
+
if (kind === "image") {
|
|
1989
|
+
card.setAttribute("role", "button");
|
|
1990
|
+
card.tabIndex = 0;
|
|
1991
|
+
card.setAttribute("aria-label", `Open image: ${fileNameOf(src)}`);
|
|
1992
|
+
const open = () => openLightbox({
|
|
1993
|
+
src,
|
|
1994
|
+
alt,
|
|
1995
|
+
caption: describeUrl(src),
|
|
1996
|
+
href: src,
|
|
1997
|
+
root: styleTarget,
|
|
1998
|
+
returnFocusTo: card
|
|
1999
|
+
});
|
|
2000
|
+
card.addEventListener("click", open);
|
|
2001
|
+
card.addEventListener("keydown", (e) => {
|
|
2002
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
2003
|
+
e.preventDefault();
|
|
2004
|
+
open();
|
|
2005
|
+
}
|
|
2006
|
+
});
|
|
2007
|
+
}
|
|
2008
|
+
card.append(el, skeleton);
|
|
2009
|
+
frag.append(card, caption);
|
|
2010
|
+
return frag;
|
|
2011
|
+
};
|
|
2012
|
+
const processLine = (line) => {
|
|
2013
|
+
const parts = [];
|
|
2014
|
+
for (const node of parseInlineMarkdown(line)) {
|
|
2015
|
+
switch (node.kind) {
|
|
2016
|
+
case "strong": {
|
|
2017
|
+
const strong = document.createElement("strong");
|
|
2018
|
+
strong.textContent = node.text;
|
|
2019
|
+
strong.style.cssText = `
|
|
2020
|
+
font-weight: 600;
|
|
2021
|
+
color: var(--convai-panel-fg, ${aeroTheme.colors.text.primary});
|
|
2022
|
+
`;
|
|
2023
|
+
parts.push(strong);
|
|
2024
|
+
break;
|
|
2025
|
+
}
|
|
2026
|
+
case "em": {
|
|
2027
|
+
const em = document.createElement("em");
|
|
2028
|
+
em.textContent = node.text;
|
|
2029
|
+
em.style.cssText = `font-style: italic;`;
|
|
2030
|
+
parts.push(em);
|
|
2031
|
+
break;
|
|
2032
|
+
}
|
|
2033
|
+
case "blocked": {
|
|
2034
|
+
const blocked = make("span", "message-link-blocked", presentationStyles.blocked);
|
|
2035
|
+
blocked.textContent = node.label;
|
|
2036
|
+
blocked.title = `Link blocked: ${node.href}`;
|
|
2037
|
+
parts.push(blocked);
|
|
2038
|
+
break;
|
|
2039
|
+
}
|
|
2040
|
+
case "image": {
|
|
2041
|
+
if (media && budget.cards < MAX_CARDS_PER_MESSAGE) {
|
|
2042
|
+
budget.cards++;
|
|
2043
|
+
parts.push(mediaPreview(node.src, node.alt, "image"));
|
|
2044
|
+
} else {
|
|
2045
|
+
parts.push(anchor(node.src, "image", node.alt || node.src));
|
|
2046
|
+
}
|
|
2047
|
+
break;
|
|
2048
|
+
}
|
|
2049
|
+
case "link": {
|
|
2050
|
+
const kind = linkKindForUrl(node.href);
|
|
2051
|
+
if (kind === "email" || kind === "phone" || kind === "sms") {
|
|
2052
|
+
parts.push(media ? contactChip(node.href, kind) : anchor(node.href, kind, node.label));
|
|
2053
|
+
break;
|
|
2054
|
+
}
|
|
2055
|
+
parts.push(anchor(node.href, kind, node.label));
|
|
2056
|
+
const wantsSiteCard = media && kind === "web" && !!options.linkPreviewResolver && budget.cards < MAX_CARDS_PER_MESSAGE;
|
|
2057
|
+
if (wantsSiteCard) {
|
|
2058
|
+
budget.cards++;
|
|
2059
|
+
parts.push(siteCard(node.href));
|
|
2060
|
+
break;
|
|
2061
|
+
}
|
|
2062
|
+
const wantsCard = media && (kind === "image" || kind === "video" || kind === "document") && budget.cards < MAX_CARDS_PER_MESSAGE;
|
|
2063
|
+
if (!wantsCard) break;
|
|
2064
|
+
budget.cards++;
|
|
2065
|
+
parts.push(kind === "document" ? documentCard(node.href) : mediaPreview(node.href, node.label, kind));
|
|
2066
|
+
break;
|
|
2067
|
+
}
|
|
2068
|
+
default:
|
|
2069
|
+
parts.push(document.createTextNode(node.text));
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
return parts;
|
|
2073
|
+
};
|
|
2074
|
+
lines.forEach((line, lineIndex) => {
|
|
2075
|
+
if (line.trim() === "" && lineIndex > 0) {
|
|
2076
|
+
container2.appendChild(document.createElement("br"));
|
|
2077
|
+
return;
|
|
2078
|
+
}
|
|
2079
|
+
const processed = processLine(line);
|
|
2080
|
+
if (processed.length > 0) processed.forEach((p) => container2.appendChild(p));
|
|
2081
|
+
else container2.appendChild(document.createTextNode(line));
|
|
2082
|
+
if (lineIndex < lines.length - 1) container2.appendChild(document.createElement("br"));
|
|
2083
|
+
});
|
|
2084
|
+
};
|
|
2085
|
+
const updateMessageList = () => {
|
|
2086
|
+
if (!messageListElement) return;
|
|
2087
|
+
const messages = formatMessages();
|
|
2088
|
+
messageListElement.innerHTML = "";
|
|
2089
|
+
if (messages.length === 0) {
|
|
2090
|
+
const emptyState = document.createElement("div");
|
|
2091
|
+
emptyState.style.cssText = `
|
|
2092
|
+
display: flex;
|
|
2093
|
+
flex-direction: column;
|
|
2094
|
+
align-items: center;
|
|
2095
|
+
justify-content: center;
|
|
2096
|
+
height: 100%;
|
|
2097
|
+
color: ${aeroTheme.colors.text.secondary};
|
|
2098
|
+
text-align: center;
|
|
2099
|
+
padding: 32px;
|
|
2100
|
+
`;
|
|
2101
|
+
emptyState.innerHTML = `
|
|
2102
|
+
<p style="font-weight: 500; margin-bottom: 8px;">Start a conversation</p>
|
|
2103
|
+
<p style="font-size: 12px;">Type a message below to begin chatting</p>
|
|
2104
|
+
`;
|
|
2105
|
+
messageListElement.appendChild(emptyState);
|
|
2106
|
+
return;
|
|
2107
|
+
}
|
|
2108
|
+
messages.forEach((msg) => {
|
|
2109
|
+
const messageWrapper = document.createElement("div");
|
|
2110
|
+
messageWrapper.style.cssText = `
|
|
2111
|
+
display: flex;
|
|
2112
|
+
flex-direction: column;
|
|
2113
|
+
max-width: ${msg.isUser ? "70%" : "70%"};
|
|
2114
|
+
margin-left: ${msg.isUser ? "auto" : "0"};
|
|
2115
|
+
width: 100%;
|
|
2116
|
+
isolation: isolate;
|
|
2117
|
+
contain: layout style paint;
|
|
2118
|
+
`;
|
|
2119
|
+
const bubble = document.createElement("div");
|
|
2120
|
+
bubble.setAttribute("part", msg.isUser ? "message message-user" : "message message-bot");
|
|
2121
|
+
if (msg.isUser) {
|
|
2122
|
+
bubble.setAttribute("data-message-type", "user");
|
|
2123
|
+
}
|
|
2124
|
+
const backgroundColor = "rgba(252, 252, 253, 0.95)";
|
|
2125
|
+
bubble.style.cssText = `
|
|
2126
|
+
padding: 12px;
|
|
2127
|
+
border-radius: ${msg.isUser ? "12px 12px 4px 12px" : "12px 12px 12px 4px"};
|
|
2128
|
+
background: ${backgroundColor};
|
|
2129
|
+
background-color: ${backgroundColor};
|
|
2130
|
+
backdrop-filter: blur(20px) saturate(180%);
|
|
2131
|
+
border: 1px solid rgba(0, 0, 0, 0.06);
|
|
2132
|
+
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.8) inset, 0 2px 8px rgba(0, 0, 0, 0.08);
|
|
2133
|
+
color: var(--convai-panel-fg, ${aeroTheme.colors.text.primary});
|
|
2134
|
+
font-family: var(--convai-font, ${aeroTheme.typography.fontFamily.body});
|
|
2135
|
+
font-size: 14px;
|
|
2136
|
+
line-height: 1.5;
|
|
2137
|
+
word-wrap: break-word;
|
|
2138
|
+
max-width: 100%;
|
|
2139
|
+
display: flex;
|
|
2140
|
+
flex-direction: column;
|
|
2141
|
+
font-synthesis: none;
|
|
2142
|
+
text-rendering: optimizeLegibility;
|
|
2143
|
+
-webkit-font-smoothing: antialiased;
|
|
2144
|
+
-moz-osx-font-smoothing: grayscale;
|
|
2145
|
+
-webkit-text-size-adjust: 100%;
|
|
2146
|
+
isolation: isolate;
|
|
2147
|
+
contain: layout style paint;
|
|
2148
|
+
`;
|
|
2149
|
+
bubble.style.setProperty("background", backgroundColor, "important");
|
|
2150
|
+
bubble.style.setProperty(
|
|
2151
|
+
"background-color",
|
|
2152
|
+
backgroundColor,
|
|
2153
|
+
"important"
|
|
2154
|
+
);
|
|
2155
|
+
if (msg.sender) {
|
|
2156
|
+
const header = document.createElement("div");
|
|
2157
|
+
header.style.cssText = `
|
|
2158
|
+
display: flex;
|
|
2159
|
+
align-items: center;
|
|
2160
|
+
gap: ${aeroTheme.spacing.xs};
|
|
2161
|
+
margin-bottom: ${aeroTheme.spacing.xs};
|
|
2162
|
+
isolation: isolate;
|
|
2163
|
+
contain: layout style paint;
|
|
2164
|
+
`;
|
|
2165
|
+
const logoContainer = document.createElement("div");
|
|
2166
|
+
logoContainer.style.cssText = `
|
|
2167
|
+
width: 16px;
|
|
2168
|
+
height: 16px;
|
|
2169
|
+
display: flex;
|
|
2170
|
+
align-items: center;
|
|
2171
|
+
justify-content: center;
|
|
2172
|
+
isolation: isolate;
|
|
2173
|
+
contain: layout style paint;
|
|
2174
|
+
`;
|
|
2175
|
+
if (msg.isUser) {
|
|
2176
|
+
const userIcon = Icons.User("sm");
|
|
2177
|
+
userIcon.style.width = "16px";
|
|
2178
|
+
userIcon.style.height = "16px";
|
|
2179
|
+
userIcon.style.color = aeroTheme.colors.convai.dark;
|
|
2180
|
+
logoContainer.appendChild(userIcon);
|
|
2181
|
+
} else {
|
|
2182
|
+
const botLogo = Icons.ConvaiLogo("sm", "connected");
|
|
2183
|
+
botLogo.style.width = "16px";
|
|
2184
|
+
botLogo.style.height = "16px";
|
|
2185
|
+
botLogo.style.color = "#10b981";
|
|
2186
|
+
logoContainer.appendChild(botLogo);
|
|
2187
|
+
}
|
|
2188
|
+
const nameLabel = document.createElement("span");
|
|
2189
|
+
nameLabel.textContent = msg.sender === "User" ? "You" : msg.sender;
|
|
2190
|
+
nameLabel.style.cssText = `
|
|
2191
|
+
font-size: 12px;
|
|
2192
|
+
color: ${msg.isUser ? aeroTheme.colors.convai.dark : "#10b981"};
|
|
2193
|
+
font-weight: 500;
|
|
2194
|
+
font-family: var(--convai-font, ${aeroTheme.typography.fontFamily.body});
|
|
2195
|
+
isolation: isolate;
|
|
2196
|
+
contain: layout style paint;
|
|
2197
|
+
`;
|
|
2198
|
+
header.appendChild(logoContainer);
|
|
2199
|
+
header.appendChild(nameLabel);
|
|
2200
|
+
bubble.appendChild(header);
|
|
2201
|
+
}
|
|
2202
|
+
const contentDiv = document.createElement("div");
|
|
2203
|
+
contentDiv.style.cssText = `
|
|
2204
|
+
white-space: pre-wrap;
|
|
2205
|
+
word-wrap: break-word;
|
|
2206
|
+
`;
|
|
2207
|
+
renderMarkdown(msg.text, contentDiv, { media: !msg.isUser });
|
|
2208
|
+
bubble.appendChild(contentDiv);
|
|
2209
|
+
messageWrapper.appendChild(bubble);
|
|
2210
|
+
if (msg.timestamp) {
|
|
2211
|
+
const timestamp = document.createElement("span");
|
|
2212
|
+
timestamp.textContent = msg.timestamp;
|
|
2213
|
+
timestamp.style.cssText = `
|
|
2214
|
+
font-size: 12px;
|
|
2215
|
+
color: ${aeroTheme.colors.text.secondary};
|
|
2216
|
+
margin-top: 4px;
|
|
2217
|
+
align-self: ${msg.isUser ? "flex-end" : "flex-start"};
|
|
2218
|
+
font-family: var(--convai-font, ${aeroTheme.typography.fontFamily.body});
|
|
2219
|
+
`;
|
|
2220
|
+
messageWrapper.appendChild(timestamp);
|
|
2221
|
+
}
|
|
2222
|
+
messageListElement.appendChild(messageWrapper);
|
|
2223
|
+
});
|
|
2224
|
+
messageListElement.scrollTop = messageListElement.scrollHeight;
|
|
2225
|
+
};
|
|
2226
|
+
const getBotStatusColor = () => {
|
|
2227
|
+
if (!client.state.isConnected) {
|
|
2228
|
+
return { color: "#ef4444", label: "Disconnected" };
|
|
2229
|
+
}
|
|
2230
|
+
if (client.state.isConnecting || !client.isBotReady) {
|
|
2231
|
+
return { color: "#f59e0b", label: "Connecting" };
|
|
2232
|
+
}
|
|
2233
|
+
if (client.state.isListening) {
|
|
2234
|
+
return { color: "#3b82f6", label: "Listening" };
|
|
2235
|
+
}
|
|
2236
|
+
return { color: "#10b981", label: "Connected" };
|
|
2237
|
+
};
|
|
2238
|
+
const formatMessages = () => {
|
|
2239
|
+
const filteredMessages = client.chatMessages.filter(
|
|
2240
|
+
(msg) => (msg.type === "user-transcription" || msg.type === "user-llm-text" || msg.type === "bot-llm-text" || msg.type === "bot-output" || msg.type === "bot-emotion") && msg.content && msg.content.trim().length > 0
|
|
2241
|
+
);
|
|
2242
|
+
return filteredMessages.map((msg) => ({
|
|
2243
|
+
id: msg.id,
|
|
2244
|
+
text: msg.content,
|
|
2245
|
+
isUser: msg.type.includes("user"),
|
|
2246
|
+
timestamp: new Date(msg.timestamp).toLocaleTimeString([], {
|
|
2247
|
+
hour: "2-digit",
|
|
2248
|
+
minute: "2-digit"
|
|
2249
|
+
}),
|
|
2250
|
+
sender: msg.type.includes("user") ? "You" : characterName,
|
|
2251
|
+
showLogo: msg.type.includes("bot")
|
|
2252
|
+
}));
|
|
2253
|
+
};
|
|
2254
|
+
const setupClientListeners = () => {
|
|
2255
|
+
eventSubscriptions.register(
|
|
2256
|
+
(listener) => client.on("stateChange", listener),
|
|
2257
|
+
() => {
|
|
2258
|
+
if (client.connectionType === "text") {
|
|
2259
|
+
if (isVoiceMode) {
|
|
2260
|
+
isVoiceMode = false;
|
|
2261
|
+
hasEnteredDefaultVoiceMode = true;
|
|
2262
|
+
void updateVoiceMode();
|
|
2263
|
+
}
|
|
2264
|
+
updateSendButton();
|
|
2265
|
+
}
|
|
2266
|
+
updateHeader();
|
|
2267
|
+
if (client.state.isConnecting) {
|
|
2268
|
+
morphingContainer.style.animation = "convai-pulse 2s ease-in-out infinite";
|
|
2269
|
+
} else {
|
|
2270
|
+
morphingContainer.style.animation = "none";
|
|
2271
|
+
}
|
|
2272
|
+
if (client.state.isSpeaking) {
|
|
2273
|
+
if (!startTime) {
|
|
2274
|
+
startTime = Date.now();
|
|
2275
|
+
}
|
|
2276
|
+
} else {
|
|
2277
|
+
if (startTime && !client.state.isSpeaking) {
|
|
2278
|
+
startTime = 0;
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
if (!client.state.isConnected && !client.state.isConnecting) {
|
|
2282
|
+
if (isOpen) {
|
|
2283
|
+
setIsOpen(false);
|
|
2284
|
+
}
|
|
2285
|
+
isMuted = false;
|
|
2286
|
+
isVoiceMode = false;
|
|
2287
|
+
isVideoVisible = false;
|
|
2288
|
+
hasEnteredDefaultVoiceMode = false;
|
|
2289
|
+
updateHeader();
|
|
2290
|
+
applyVoiceMode();
|
|
2291
|
+
}
|
|
2292
|
+
if (client.state.isConnected && defaultVoiceMode && isOpen && !hasEnteredDefaultVoiceMode && !isVoiceMode) {
|
|
2293
|
+
setTimeout(async () => {
|
|
2294
|
+
try {
|
|
2295
|
+
await client.audioControls.unmuteAudio();
|
|
2296
|
+
isVoiceMode = true;
|
|
2297
|
+
hasEnteredDefaultVoiceMode = true;
|
|
2298
|
+
await updateVoiceMode();
|
|
2299
|
+
} catch (error) {
|
|
2300
|
+
reportMicFailure(client, "Failed to enter voice mode:", error);
|
|
2301
|
+
}
|
|
2302
|
+
}, 100);
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
);
|
|
2306
|
+
eventSubscriptions.register(
|
|
2307
|
+
(listener) => client.videoControls.on("videoStateChange", listener),
|
|
2308
|
+
(videoState) => {
|
|
2309
|
+
if (videoState.isVideoEnabled !== void 0) {
|
|
2310
|
+
isVideoVisible = videoState.isVideoEnabled;
|
|
2311
|
+
applyVoiceMode();
|
|
2312
|
+
const videoBtn = refs.settingsVideoBtn;
|
|
2313
|
+
if (videoBtn) {
|
|
2314
|
+
const isActive = isVideoVisible;
|
|
2315
|
+
videoBtn.style.backgroundColor = isActive ? "rgba(16, 185, 129, 0.15)" : "transparent";
|
|
2316
|
+
videoBtn.style.color = isActive ? "#10b981" : `var(--convai-panel-fg, ${aeroTheme.colors.text.primary})`;
|
|
2317
|
+
const iconContainer = videoBtn.querySelector("div");
|
|
2318
|
+
if (iconContainer) {
|
|
2319
|
+
iconContainer.innerHTML = "";
|
|
2320
|
+
const icon = isActive ? Icons.Video("md") : Icons.VideoOff("md");
|
|
2321
|
+
icon.style.width = "18px";
|
|
2322
|
+
icon.style.height = "18px";
|
|
2323
|
+
iconContainer.appendChild(icon);
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
);
|
|
2329
|
+
client.screenShareControls.on(
|
|
2330
|
+
"screenShareStateChange",
|
|
2331
|
+
(screenShareState) => {
|
|
2332
|
+
if (screenShareState.isScreenShareActive !== void 0) {
|
|
2333
|
+
const isSharing = screenShareState.isScreenShareActive;
|
|
2334
|
+
const shareBtn = refs.settingsShareBtn;
|
|
2335
|
+
if (shareBtn) {
|
|
2336
|
+
const isActive = isSharing;
|
|
2337
|
+
shareBtn.style.backgroundColor = isActive ? "rgba(16, 185, 129, 0.15)" : "transparent";
|
|
2338
|
+
shareBtn.style.color = isActive ? "#10b981" : `var(--convai-panel-fg, ${aeroTheme.colors.text.primary})`;
|
|
2339
|
+
const iconContainer = shareBtn.querySelector("div");
|
|
2340
|
+
if (iconContainer) {
|
|
2341
|
+
iconContainer.innerHTML = "";
|
|
2342
|
+
const icon = isActive ? Icons.StopScreenShare("md") : Icons.ScreenShare("md");
|
|
2343
|
+
icon.style.width = "18px";
|
|
2344
|
+
icon.style.height = "18px";
|
|
2345
|
+
iconContainer.appendChild(icon);
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
);
|
|
2351
|
+
eventSubscriptions.register(
|
|
2352
|
+
(listener) => client.on("messagesChange", listener),
|
|
2353
|
+
() => {
|
|
2354
|
+
updateMessageList();
|
|
2355
|
+
}
|
|
2356
|
+
);
|
|
2357
|
+
eventSubscriptions.register(
|
|
2358
|
+
(listener) => client.on("botReady", listener),
|
|
2359
|
+
() => {
|
|
2360
|
+
updateHeader();
|
|
2361
|
+
updateSendButton();
|
|
2362
|
+
}
|
|
2363
|
+
);
|
|
2364
|
+
eventSubscriptions.register(
|
|
2365
|
+
(listener) => client.on("connect", listener),
|
|
2366
|
+
() => {
|
|
2367
|
+
hasConnectedBefore = true;
|
|
2368
|
+
if (client.room && !audioRenderer) {
|
|
2369
|
+
audioRenderer = new AudioRenderer(client.room, { container: rootElement });
|
|
2370
|
+
}
|
|
2371
|
+
fetchCharacterInfo$1();
|
|
2372
|
+
if (onConnect) {
|
|
2373
|
+
onConnect();
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
);
|
|
2377
|
+
eventSubscriptions.register(
|
|
2378
|
+
(listener) => client.on("disconnect", listener),
|
|
2379
|
+
() => {
|
|
2380
|
+
if (audioRenderer) {
|
|
2381
|
+
audioRenderer.destroy();
|
|
2382
|
+
audioRenderer = null;
|
|
2383
|
+
}
|
|
2384
|
+
updateMessageList();
|
|
2385
|
+
if (onDisconnect) {
|
|
2386
|
+
onDisconnect();
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
);
|
|
2390
|
+
eventSubscriptions.register(
|
|
2391
|
+
(listener) => client.on("message", listener),
|
|
2392
|
+
(message) => {
|
|
2393
|
+
const row = message;
|
|
2394
|
+
if (onMessage && row) {
|
|
2395
|
+
onMessage(row);
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
);
|
|
2399
|
+
eventSubscriptions.register(
|
|
2400
|
+
(listener) => client.screenShareControls.on("screenShareStateChange", listener),
|
|
2401
|
+
(screenShareState) => {
|
|
2402
|
+
if (screenShareState.isScreenShareActive !== void 0) {
|
|
2403
|
+
const isSharing = screenShareState.isScreenShareActive;
|
|
2404
|
+
const shareBtn = document.getElementById("convai-settings-share-btn");
|
|
2405
|
+
if (shareBtn) {
|
|
2406
|
+
const isActive = isSharing;
|
|
2407
|
+
shareBtn.style.backgroundColor = isActive ? "rgba(16, 185, 129, 0.15)" : "transparent";
|
|
2408
|
+
shareBtn.style.color = isActive ? "#10b981" : aeroTheme.colors.text.primary;
|
|
2409
|
+
const iconContainer = shareBtn.querySelector("div");
|
|
2410
|
+
if (iconContainer) {
|
|
2411
|
+
iconContainer.innerHTML = "";
|
|
2412
|
+
const icon = isActive ? Icons.StopScreenShare("md") : Icons.ScreenShare("md");
|
|
2413
|
+
icon.style.width = "18px";
|
|
2414
|
+
icon.style.height = "18px";
|
|
2415
|
+
iconContainer.appendChild(icon);
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
);
|
|
2421
|
+
};
|
|
2422
|
+
createDOM();
|
|
2423
|
+
setupClientListeners();
|
|
2424
|
+
updateConnectingOverlay();
|
|
2425
|
+
updateSendButton();
|
|
2426
|
+
if (defaultVoiceMode) {
|
|
2427
|
+
applyVoiceMode();
|
|
2428
|
+
}
|
|
2429
|
+
if (client.state.isConnected && client.room) {
|
|
2430
|
+
audioRenderer = new AudioRenderer(client.room, { container: rootElement });
|
|
2431
|
+
fetchCharacterInfo$1();
|
|
2432
|
+
}
|
|
2433
|
+
const widget = {
|
|
2434
|
+
element: rootElement,
|
|
2435
|
+
client,
|
|
2436
|
+
// `isOpen` reports *requested* state, which on a warm client is the same
|
|
2437
|
+
// thing as rendered state: `setIsOpen()` runs synchronously. The one case
|
|
2438
|
+
// where they differ is the first open on a disconnected client, where the
|
|
2439
|
+
// panel is committed only after `connect()` resolves; reporting `false`
|
|
2440
|
+
// for those seconds would tell an embed reconciling its own
|
|
2441
|
+
// convai-open/convai-close events that a widget it just opened is closed.
|
|
2442
|
+
// `pendingOpen` is cleared by every cancellation path, so this never
|
|
2443
|
+
// reports open for a request that was called off.
|
|
2444
|
+
get isOpen() {
|
|
2445
|
+
return isOpen || pendingOpen;
|
|
2446
|
+
},
|
|
2447
|
+
// Drives the exact same path the launcher click does: `handleToggle`
|
|
2448
|
+
// (connect-on-first-open, then `setIsOpen(true)`). Idempotent against an
|
|
2449
|
+
// in-flight open as well as an open panel, so repeat calls never start a
|
|
2450
|
+
// second connect.
|
|
2451
|
+
open: () => {
|
|
2452
|
+
if (isOpen || pendingOpen) return;
|
|
2453
|
+
void handleToggle();
|
|
2454
|
+
},
|
|
2455
|
+
// Drives the same path the header's close button does: `handleClose` ->
|
|
2456
|
+
// `setIsOpen(false)`. Also cancels an open that is still waiting on
|
|
2457
|
+
// `connect()`; a redundant `close()` is a no-op.
|
|
2458
|
+
close: () => {
|
|
2459
|
+
if (!isOpen && !pendingOpen) return;
|
|
2460
|
+
handleClose();
|
|
2461
|
+
},
|
|
2462
|
+
toggle: () => {
|
|
2463
|
+
if (isOpen || pendingOpen) {
|
|
2464
|
+
handleClose();
|
|
2465
|
+
} else {
|
|
2466
|
+
void handleToggle();
|
|
2467
|
+
}
|
|
2468
|
+
},
|
|
2469
|
+
// Pushes a synthetic ChatMessage straight onto `client.chatMessages` and
|
|
2470
|
+
// re-renders via the widget's existing `updateMessageList()`. It never
|
|
2471
|
+
// calls a client send method (e.g. `sendUserTextMessage`), so the
|
|
2472
|
+
// message never reaches the character and is never billed as an LLM
|
|
2473
|
+
// turn. The `local-` id keeps it from colliding with a server-issued id.
|
|
2474
|
+
appendMessage: (message) => {
|
|
2475
|
+
if (typeof client.appendMessage === "function") {
|
|
2476
|
+
client.appendMessage(message);
|
|
2477
|
+
} else {
|
|
2478
|
+
const chatMessage = {
|
|
2479
|
+
id: `local-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`,
|
|
2480
|
+
type: message.sender === "user" ? "user-llm-text" : "bot-llm-text",
|
|
2481
|
+
content: message.content,
|
|
2482
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
2483
|
+
};
|
|
2484
|
+
client.chatMessages.push(chatMessage);
|
|
2485
|
+
}
|
|
2486
|
+
updateMessageList();
|
|
2487
|
+
},
|
|
2488
|
+
destroy: () => {
|
|
2489
|
+
isDestroyed = true;
|
|
2490
|
+
if (audioRenderer) {
|
|
2491
|
+
audioRenderer.destroy();
|
|
2492
|
+
audioRenderer = null;
|
|
2493
|
+
}
|
|
2494
|
+
morphingContainer.removeEventListener("click", handleLauncherClick);
|
|
2495
|
+
if (rootElement.parentElement) {
|
|
2496
|
+
rootElement.remove();
|
|
2497
|
+
}
|
|
2498
|
+
if (floatingVideo.parentElement) {
|
|
2499
|
+
floatingVideo.remove();
|
|
2500
|
+
}
|
|
2501
|
+
eventSubscriptions.unsubscribeAll();
|
|
2502
|
+
}
|
|
2503
|
+
};
|
|
2504
|
+
return widget;
|
|
2505
|
+
}
|
|
2506
|
+
function destroyConvaiWidget(widget) {
|
|
2507
|
+
widget.destroy();
|
|
2508
|
+
}
|
|
2509
|
+
export {
|
|
2510
|
+
createConvaiWidget,
|
|
2511
|
+
destroyConvaiWidget
|
|
2512
|
+
};
|