@convai/web-sdk 1.9.0-beta.0 → 1.9.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/AudioManager.d.ts +3 -3
- package/dist/core/AudioManager.js +1 -1
- package/dist/core/CharacterRoster.d.ts +1 -1
- package/dist/core/CharacterVersionManager.d.ts +2 -2
- package/dist/core/CharacterVersionManager.js +1 -1
- package/dist/core/ConnectionStateHandler.d.ts +1 -1
- package/dist/core/ConvaiClient.d.ts +6 -6
- package/dist/core/ConvaiClient.d.ts.map +1 -1
- package/dist/core/ConvaiClient.js +34 -28
- package/dist/core/ConvaiClient.js.map +1 -1
- package/dist/core/MemoryManager.d.ts +1 -1
- package/dist/core/MessageHandler.d.ts +7 -4
- package/dist/core/MessageHandler.d.ts.map +1 -1
- package/dist/core/MessageHandler.js +68 -43
- package/dist/core/MessageHandler.js.map +1 -1
- package/dist/core/SSESession.d.ts +7 -8
- package/dist/core/SSESession.d.ts.map +1 -1
- package/dist/core/SSESession.js +225 -11
- package/dist/core/SSESession.js.map +1 -1
- package/dist/core/ScreenShareManager.d.ts +2 -2
- package/dist/core/ScreenShareManager.js +2 -2
- package/dist/core/VideoManager.d.ts +2 -2
- package/dist/core/VideoManager.js +3 -3
- package/dist/core/connectRequest.d.ts +1 -1
- package/dist/core/contextUpdateRequest.d.ts +1 -1
- package/dist/core/index.d.ts +25 -21
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +19 -17
- package/dist/core/index.js.map +1 -1
- package/dist/core/modelOutput.d.ts +2 -2
- package/dist/core/publishedChat.d.ts +1 -1
- package/dist/core/rosterRequest.d.ts +1 -1
- package/dist/core/rosterRequest.js +1 -1
- package/dist/core/rtviEnvelope.d.ts +6 -0
- package/dist/core/rtviEnvelope.d.ts.map +1 -0
- package/dist/core/rtviEnvelope.js +10 -0
- package/dist/core/rtviEnvelope.js.map +1 -0
- package/dist/core/types.d.ts +27 -9
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/core/videoSourceState.d.ts +1 -1
- package/dist/core/visionRequest.d.ts +1 -1
- package/dist/embed/ConvaiChatElement.js +2 -2
- package/dist/embed/browser.d.ts +2 -2
- package/dist/embed/browser.js +3 -3
- package/dist/embed/chat-embed-v1.js +14 -14
- package/dist/embed/chat-embed-v1.js.map +4 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/lipsync-helpers/createBlendshapeQueue.d.ts +2 -2
- package/dist/lipsync-helpers/createBlendshapeQueue.js +2 -2
- package/dist/lipsync-helpers/declarativeMapping.d.ts +1 -1
- package/dist/lipsync-helpers/declarativeMapping.js +2 -2
- package/dist/lipsync-helpers/index.d.ts +12 -12
- package/dist/lipsync-helpers/index.js +9 -9
- package/dist/lipsync-helpers/mhaLimitDrivers.js +2 -2
- package/dist/lipsync-helpers/naturalness/processor.d.ts +1 -1
- package/dist/lipsync-helpers/naturalness/processor.js +1 -1
- package/dist/lipsync-helpers/naturalness/profiles/mha.d.ts +1 -1
- package/dist/lipsync-helpers/naturalness/profiles/mha.js +1 -1
- package/dist/lipsync-helpers/presetMappers.d.ts +1 -1
- package/dist/react/components/ConvaiWidget.d.ts +11 -2
- package/dist/react/components/ConvaiWidget.d.ts.map +1 -1
- package/dist/react/components/ConvaiWidget.js +7 -7
- package/dist/react/components/ConvaiWidget.js.map +1 -1
- package/dist/react/components/index.d.ts +1 -1
- package/dist/react/components/index.js +1 -1
- package/dist/react/components/rtc-widget/components/AudioSettingsPanel.d.ts +1 -1
- package/dist/react/components/rtc-widget/components/ConviMessage.d.ts +4 -1
- package/dist/react/components/rtc-widget/components/ConviMessage.d.ts.map +1 -1
- package/dist/react/components/rtc-widget/components/ConviMessage.js +5 -5
- package/dist/react/components/rtc-widget/components/ConviMessage.js.map +1 -1
- package/dist/react/components/rtc-widget/components/FloatingVideo.js +3 -3
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts +21 -3
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts.map +1 -1
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.js +114 -130
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.js.map +1 -1
- package/dist/react/components/rtc-widget/components/MessageBubble.js +1 -1
- package/dist/react/components/rtc-widget/components/MessageList.d.ts +5 -2
- package/dist/react/components/rtc-widget/components/MessageList.d.ts.map +1 -1
- package/dist/react/components/rtc-widget/components/MessageList.js +6 -6
- package/dist/react/components/rtc-widget/components/MessageList.js.map +1 -1
- package/dist/react/components/rtc-widget/components/SiteCard.d.ts +15 -0
- package/dist/react/components/rtc-widget/components/SiteCard.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/SiteCard.js +35 -0
- package/dist/react/components/rtc-widget/components/SiteCard.js.map +1 -0
- package/dist/react/components/rtc-widget/components/UserMessage.js +3 -3
- package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.js +4 -4
- package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.js +3 -3
- package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.js +4 -4
- package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.js +3 -3
- package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js +3 -3
- package/dist/react/components/rtc-widget/components/conviComponents/index.d.ts +5 -5
- package/dist/react/components/rtc-widget/components/conviComponents/index.js +5 -5
- package/dist/react/components/rtc-widget/components/index.d.ts +8 -8
- package/dist/react/components/rtc-widget/components/index.js +9 -9
- package/dist/react/components/rtc-widget/index.d.ts +5 -5
- package/dist/react/components/rtc-widget/index.js +3 -3
- package/dist/react/components/rtc-widget/styles/icons.d.ts +1 -1
- package/dist/react/components/rtc-widget/styles/icons.js +1 -1
- package/dist/react/components/rtc-widget/styles/index.d.ts +5 -5
- package/dist/react/components/rtc-widget/styles/index.js +4 -4
- package/dist/react/components/rtc-widget/styles/styledComponents.js +1 -1
- package/dist/react/hooks/index.d.ts +3 -3
- package/dist/react/hooks/index.js +3 -3
- package/dist/react/hooks/useCharacterInfo.js +1 -1
- package/dist/react/hooks/useConvaiClient.d.ts +1 -1
- package/dist/react/hooks/useConvaiClient.js +1 -1
- package/dist/react/index.d.ts +13 -9
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +10 -8
- package/dist/react/index.js.map +1 -1
- package/dist/utils/lightbox.d.ts +16 -0
- package/dist/utils/lightbox.d.ts.map +1 -0
- package/dist/utils/lightbox.js +95 -0
- package/dist/utils/lightbox.js.map +1 -0
- package/dist/utils/linkPresentation.d.ts +76 -0
- package/dist/utils/linkPresentation.d.ts.map +1 -0
- package/dist/utils/linkPresentation.js +415 -0
- package/dist/utils/linkPresentation.js.map +1 -0
- package/dist/utils/linkPreview.d.ts +46 -0
- package/dist/utils/linkPreview.d.ts.map +1 -0
- package/dist/utils/linkPreview.js +72 -0
- package/dist/utils/linkPreview.js.map +1 -0
- package/dist/vanilla/AudioRenderer.js +1 -1
- package/dist/vanilla/ConvaiWidget.d.ts +1 -1
- package/dist/vanilla/ConvaiWidget.d.ts.map +1 -1
- package/dist/vanilla/ConvaiWidget.js +287 -193
- package/dist/vanilla/ConvaiWidget.js.map +1 -1
- package/dist/vanilla/WebSocketSession.d.ts +1 -1
- package/dist/vanilla/WebSocketSession.js +1 -1
- package/dist/vanilla/index.d.ts +13 -9
- package/dist/vanilla/index.d.ts.map +1 -1
- package/dist/vanilla/index.js +9 -7
- package/dist/vanilla/index.js.map +1 -1
- package/dist/vanilla/styles.d.ts.map +1 -1
- package/dist/vanilla/styles.js +9 -0
- package/dist/vanilla/styles.js.map +1 -1
- package/dist/vanilla/types.d.ts +11 -2
- package/dist/vanilla/types.d.ts.map +1 -1
- package/dist/vanilla/types.js.map +1 -1
- package/dist/vanilla/websocket.d.ts +1 -1
- package/dist/vanilla/websocket.js +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1 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AAE,CAAC,KAAK,CAAC;QACzC,IAAI,MAAM,KAAK,SAAS;YAAE,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACjD,CAAC;IACD,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAClB,OAAO,CAAC,CAAC;AACX,CAAC;AAED,iBAAiB;AACjB,MAAM,UAAU,qBAAqB;IACnC,KAAK,CAAC,KAAK,EAAE,CAAC;AAChB,CAAC","sourcesContent":["/**\n * The site-card contract: what a host hands the renderer for a plain web\n * link, and the one cache both renderers share.\n *\n * The SDK cannot read another origin's HTML, so the Open Graph tags a page\n * declares have to come from somewhere server-side. That somewhere is the\n * host's business; the renderer only needs a function that turns a URL into\n * metadata or null. No resolver, no cards.\n */\nexport interface LinkPreviewMeta {\n /** Final URL after redirects. */\n url: string;\n title?: string;\n description?: string;\n /** Absolute http(s) URL, or dropped. */\n image?: string;\n siteName?: string;\n /** Absolute http(s) URL, or dropped. */\n favicon?: string;\n}\n\n/**\n * Resolve metadata for a web URL, or null when there is nothing to show.\n * Should resolve null for a bad or unknown URL and reject only on transport\n * failure; either way the renderer draws nothing.\n */\nexport type LinkPreviewResolver = (\n url: string,\n signal: AbortSignal,\n) => Promise<LinkPreviewMeta | null>;\n\n/** A resolve that has not settled by then is treated as nothing to show. */\nexport const LINK_PREVIEW_TIMEOUT_MS = 8000;\n/** Distinct URLs remembered per page load. */\nexport const LINK_PREVIEW_CACHE_SIZE = 200;\n\n/** Description, site name and favicon alone are not worth a card. */\nexport function isCardWorthy(meta: LinkPreviewMeta | null | undefined): meta is LinkPreviewMeta {\n return !!meta && (!!meta.title || !!meta.image);\n}\n\n/** Only http(s) may ever reach an `img`. Relative URLs are the resolver's job. */\nexport function safeHttpUrl(value: string | undefined): string | undefined {\n if (!value) return undefined;\n try {\n const u = new URL(value);\n return u.protocol === \"http:\" || u.protocol === \"https:\" ? u.href : undefined;\n } catch {\n return undefined;\n }\n}\n\nexport function siteNameFor(meta: LinkPreviewMeta, url: string): string {\n if (meta.siteName) return meta.siteName;\n try {\n return new URL(url).hostname.replace(/^www\\./, \"\");\n } catch {\n return url;\n }\n}\n\n/** Declared icon, else the origin's /favicon.ico. Never a third-party icon service. */\nexport function faviconFor(meta: LinkPreviewMeta, url: string): string | undefined {\n const declared = safeHttpUrl(meta.favicon);\n if (declared) return declared;\n try {\n return `${new URL(url).origin}/favicon.ico`;\n } catch {\n return undefined;\n }\n}\n\nconst cache = new Map<string, Promise<LinkPreviewMeta | null>>();\n\n/**\n * One in-flight or settled promise per URL, shared by every card on the page.\n * Rejections settle to null so a dead host is asked once, and each call gets a\n * signal that fires after LINK_PREVIEW_TIMEOUT_MS.\n */\nexport function resolveLinkPreviewCached(\n resolver: LinkPreviewResolver,\n url: string,\n): Promise<LinkPreviewMeta | null> {\n const hit = cache.get(url);\n if (hit) return hit;\n\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), LINK_PREVIEW_TIMEOUT_MS);\n const p = Promise.resolve()\n .then(() => resolver(url, controller.signal))\n .then((meta) =>\n meta ? { ...meta, image: safeHttpUrl(meta.image), favicon: safeHttpUrl(meta.favicon) } : null,\n )\n .catch(() => null)\n .finally(() => clearTimeout(timer));\n\n if (cache.size >= LINK_PREVIEW_CACHE_SIZE) {\n const oldest = cache.keys().next().value;\n if (oldest !== undefined) cache.delete(oldest);\n }\n cache.set(url, p);\n return p;\n}\n\n/** Test seam. */\nexport function resetLinkPreviewCache(): void {\n cache.clear();\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RoomEvent } from 'livekit-client';
|
|
2
|
-
import { logger } from '../utils/logger
|
|
2
|
+
import { logger } from '../utils/logger';
|
|
3
3
|
/**
|
|
4
4
|
* AudioRenderer - Manages audio playback for remote participants
|
|
5
5
|
* Automatically creates and attaches audio elements for remote audio tracks
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Vanilla ConvaiWidget - Complete UI widget for Convai conversations
|
|
3
3
|
* Ports the React ConvaiWidget to vanilla TypeScript with DOM manipulation
|
|
4
4
|
*/
|
|
5
|
-
import type { VanillaWidgetOptions, VanillaWidget } from "./types
|
|
5
|
+
import type { VanillaWidgetOptions, VanillaWidget } from "./types";
|
|
6
6
|
/**
|
|
7
7
|
* Create a Convai chat widget in the specified container
|
|
8
8
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConvaiWidget.d.ts","sourceRoot":"","sources":["../../src/vanilla/ConvaiWidget.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EAEd,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"ConvaiWidget.d.ts","sourceRoot":"","sources":["../../src/vanilla/ConvaiWidget.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EAEd,MAAM,SAAS,CAAC;AAmJjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,WAAW,EACtB,OAAO,EAAE,oBAAoB,GAC5B,aAAa,CA++Ff;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAE/D"}
|
|
@@ -2,13 +2,16 @@
|
|
|
2
2
|
* Vanilla ConvaiWidget - Complete UI widget for Convai conversations
|
|
3
3
|
* Ports the React ConvaiWidget to vanilla TypeScript with DOM manipulation
|
|
4
4
|
*/
|
|
5
|
-
import { AudioRenderer } from "./AudioRenderer
|
|
6
|
-
import { aeroTheme, injectGlobalStyles, injectKeyframes, } from "./styles
|
|
7
|
-
import { Icons } from "./icons
|
|
8
|
-
import { WidgetEventSubscriptions } from "./WidgetEventSubscriptions
|
|
9
|
-
import { ConvaiClient } from "../core/ConvaiClient
|
|
10
|
-
import { parseInlineMarkdown, compactUrl } from "../utils/inlineMarkdown
|
|
11
|
-
import {
|
|
5
|
+
import { AudioRenderer } from "./AudioRenderer";
|
|
6
|
+
import { aeroTheme, injectGlobalStyles, injectKeyframes, } from "./styles";
|
|
7
|
+
import { Icons } from "./icons";
|
|
8
|
+
import { WidgetEventSubscriptions } from "./WidgetEventSubscriptions";
|
|
9
|
+
import { ConvaiClient } from "../core/ConvaiClient";
|
|
10
|
+
import { parseInlineMarkdown, compactUrl } from "../utils/inlineMarkdown";
|
|
11
|
+
import { linkKindForUrl, describeUrl, fileNameOf, documentBadge, contactLabel, hoverTitle, isMixedContent, glyph, presentationStyles as S, toCssText, PREVIEW_TIMEOUT_MS, MAX_CARDS_PER_MESSAGE, } from "../utils/linkPresentation";
|
|
12
|
+
import { openLightbox } from "../utils/lightbox";
|
|
13
|
+
import { resolveLinkPreviewCached, isCardWorthy, siteNameFor, faviconFor, } from "../utils/linkPreview";
|
|
14
|
+
import { freshPublicationGrantOptions } from "../core/publishedChat";
|
|
12
15
|
/**
|
|
13
16
|
* Positioning declarations for the widget root, keyed by `placement`. The
|
|
14
17
|
* `bottom-right` entry must stay byte-identical to the literals it replaces --
|
|
@@ -2074,217 +2077,308 @@ export function createConvaiWidget(container, options) {
|
|
|
2074
2077
|
});
|
|
2075
2078
|
};
|
|
2076
2079
|
// Microphone button removed - only controlled via voice mode now
|
|
2077
|
-
//
|
|
2078
|
-
//
|
|
2079
|
-
//
|
|
2080
|
-
//
|
|
2081
|
-
//
|
|
2080
|
+
// The bubble renderer. Everything visual comes from utils/linkPresentation
|
|
2081
|
+
// so this and the React MarkdownRenderer cannot drift; this only maps
|
|
2082
|
+
// tokenizer nodes onto DOM. `media` gates cards and chips: bot bubbles get
|
|
2083
|
+
// them, the user's own bubble keeps anchors only, so a pasted URL never
|
|
2084
|
+
// pulls remote media into the transcript.
|
|
2082
2085
|
const renderMarkdown = (text, container, { media = true } = {}) => {
|
|
2083
2086
|
if (!text)
|
|
2084
2087
|
return;
|
|
2085
|
-
// Handle both actual newlines and \n
|
|
2086
|
-
const
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2088
|
+
// Handle both actual newlines and literal "\n" sequences.
|
|
2089
|
+
const lines = text.replace(/\\n/g, "\n").split("\n");
|
|
2090
|
+
// Cards drawn so far in this message, against MAX_CARDS_PER_MESSAGE.
|
|
2091
|
+
const budget = { cards: 0 };
|
|
2092
|
+
const make = (tag, part, ...styles) => {
|
|
2093
|
+
const node = document.createElement(tag);
|
|
2094
|
+
node.setAttribute("part", part);
|
|
2095
|
+
node.style.cssText = toCssText(Object.assign({}, ...styles));
|
|
2096
|
+
return node;
|
|
2097
|
+
};
|
|
2098
|
+
// Inline styles cannot express :focus-visible, so the ring is toggled by hand.
|
|
2099
|
+
const focusRing = (node) => {
|
|
2100
|
+
const base = node.style.cssText;
|
|
2101
|
+
node.addEventListener("focus", () => {
|
|
2102
|
+
if (node.matches(":focus-visible"))
|
|
2103
|
+
node.style.cssText = `${base} ${toCssText(S.linkFocus)}`;
|
|
2104
|
+
});
|
|
2105
|
+
node.addEventListener("blur", () => {
|
|
2106
|
+
node.style.cssText = base;
|
|
2107
|
+
});
|
|
2108
|
+
};
|
|
2109
|
+
const anchor = (href, kind, label) => {
|
|
2110
|
+
const a = make("a", "message-link", S.link);
|
|
2111
|
+
a.href = href;
|
|
2112
|
+
a.target = "_blank";
|
|
2113
|
+
a.rel = "noopener noreferrer";
|
|
2114
|
+
// A bare URL is its own label and may be elided for display; the title
|
|
2115
|
+
// compares against what is shown so the full target is one hover away.
|
|
2116
|
+
const display = label === href ? compactUrl(label) : label;
|
|
2117
|
+
a.textContent = display;
|
|
2118
|
+
const title = hoverTitle(kind, href, display);
|
|
2119
|
+
if (title)
|
|
2120
|
+
a.title = title;
|
|
2121
|
+
if (kind === "ftp") {
|
|
2122
|
+
const badge = make("span", "message-link-badge", S.badge);
|
|
2123
|
+
badge.textContent = "FTP";
|
|
2124
|
+
a.appendChild(badge);
|
|
2125
|
+
}
|
|
2126
|
+
focusRing(a);
|
|
2127
|
+
return a;
|
|
2128
|
+
};
|
|
2129
|
+
const contactChip = (href, kind) => {
|
|
2130
|
+
const a = make("a", "message-contact", S.contact);
|
|
2131
|
+
a.href = href;
|
|
2132
|
+
a.title = hoverTitle(kind, href, href);
|
|
2133
|
+
const g = make("span", "message-contact-glyph", S.contactGlyph);
|
|
2134
|
+
g.innerHTML = glyph(kind);
|
|
2135
|
+
const t = document.createElement("span");
|
|
2136
|
+
t.textContent = contactLabel(href);
|
|
2137
|
+
a.append(g, t);
|
|
2138
|
+
focusRing(a);
|
|
2139
|
+
return a;
|
|
2140
|
+
};
|
|
2141
|
+
const documentCard = (href) => {
|
|
2142
|
+
let host = "";
|
|
2143
|
+
try {
|
|
2144
|
+
host = new URL(href).host;
|
|
2145
|
+
}
|
|
2146
|
+
catch {
|
|
2147
|
+
/* keep empty */
|
|
2148
|
+
}
|
|
2149
|
+
const a = make("a", "message-file-card", S.fileCard);
|
|
2150
|
+
a.href = href;
|
|
2151
|
+
a.target = "_blank";
|
|
2152
|
+
a.rel = "noopener noreferrer";
|
|
2153
|
+
a.title = href;
|
|
2154
|
+
const icon = make("span", "message-file-icon", S.fileIcon);
|
|
2155
|
+
icon.textContent = documentBadge(href);
|
|
2156
|
+
const body = document.createElement("span");
|
|
2157
|
+
body.style.cssText = toCssText(S.fileBody);
|
|
2158
|
+
const name = make("span", "message-file-name", S.fileName);
|
|
2159
|
+
name.textContent = fileNameOf(href);
|
|
2160
|
+
const meta = make("span", "message-file-meta", S.fileMeta);
|
|
2161
|
+
meta.textContent = `${host} · Opens in a new tab`;
|
|
2162
|
+
body.append(name, meta);
|
|
2163
|
+
a.append(icon, body);
|
|
2164
|
+
focusRing(a);
|
|
2165
|
+
return a;
|
|
2166
|
+
};
|
|
2167
|
+
/**
|
|
2168
|
+
* Open Graph card under a plain web link. A comment node holds the place
|
|
2169
|
+
* until the host's resolver settles; it is replaced only when the result
|
|
2170
|
+
* has a title or an image, so nothing flashes for the many links that
|
|
2171
|
+
* resolve to nothing card-worthy. Resolver text becomes text nodes only.
|
|
2172
|
+
*/
|
|
2173
|
+
const siteCard = (href) => {
|
|
2174
|
+
const resolver = options.linkPreviewResolver;
|
|
2175
|
+
const slot = document.createComment("site-card");
|
|
2176
|
+
if (!resolver)
|
|
2177
|
+
return slot;
|
|
2178
|
+
resolveLinkPreviewCached(resolver, href).then((meta) => {
|
|
2179
|
+
if (!isCardWorthy(meta) || !slot.parentNode)
|
|
2180
|
+
return;
|
|
2181
|
+
const a = make("a", "message-site-card", S.siteCard);
|
|
2182
|
+
a.href = href;
|
|
2183
|
+
a.target = "_blank";
|
|
2184
|
+
a.rel = "noopener noreferrer";
|
|
2185
|
+
const header = document.createElement("span");
|
|
2186
|
+
header.style.cssText = toCssText(S.siteHeader);
|
|
2187
|
+
const favicon = faviconFor(meta, href);
|
|
2188
|
+
if (favicon) {
|
|
2189
|
+
const icon = make("img", "message-site-favicon", S.siteFavicon);
|
|
2190
|
+
icon.src = favicon;
|
|
2191
|
+
icon.alt = "";
|
|
2192
|
+
icon.addEventListener("error", () => icon.remove());
|
|
2193
|
+
header.appendChild(icon);
|
|
2097
2194
|
}
|
|
2098
|
-
|
|
2099
|
-
|
|
2195
|
+
const name = make("span", "message-site-name", S.siteName);
|
|
2196
|
+
name.textContent = siteNameFor(meta, href);
|
|
2197
|
+
header.appendChild(name);
|
|
2198
|
+
a.appendChild(header);
|
|
2199
|
+
if (meta.title) {
|
|
2200
|
+
const t = make("span", "message-site-title", S.siteTitle);
|
|
2201
|
+
t.textContent = meta.title;
|
|
2202
|
+
a.appendChild(t);
|
|
2100
2203
|
}
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
opacity: 0;
|
|
2136
|
-
transition: opacity .18s ease;
|
|
2137
|
-
`;
|
|
2138
|
-
const skeleton = document.createElement("span");
|
|
2139
|
-
skeleton.setAttribute("part", "message-media-skeleton");
|
|
2140
|
-
skeleton.setAttribute("aria-hidden", "true");
|
|
2141
|
-
skeleton.dataset.convaiSkeleton = "";
|
|
2142
|
-
skeleton.style.cssText = `
|
|
2143
|
-
position: absolute;
|
|
2144
|
-
inset: 0;
|
|
2145
|
-
border-radius: 8px;
|
|
2146
|
-
background: color-mix(in srgb, currentColor 8%, transparent);
|
|
2147
|
-
background-image: linear-gradient(90deg, transparent, color-mix(in srgb, currentColor 12%, transparent), transparent);
|
|
2148
|
-
background-size: 200% 100%;
|
|
2149
|
-
animation: convai-preview-shimmer 1.4s ease-in-out infinite;
|
|
2150
|
-
`;
|
|
2151
|
-
const caption = document.createElement("span");
|
|
2152
|
-
caption.setAttribute("part", "message-media-caption");
|
|
2153
|
-
caption.textContent = describeUrl(src);
|
|
2154
|
-
caption.style.cssText = `
|
|
2155
|
-
display: block;
|
|
2156
|
-
margin-top: 4px;
|
|
2157
|
-
font-size: 11px;
|
|
2158
|
-
opacity: .7;
|
|
2159
|
-
white-space: nowrap;
|
|
2160
|
-
overflow: hidden;
|
|
2161
|
-
text-overflow: ellipsis;
|
|
2162
|
-
`;
|
|
2163
|
-
const settled = () => {
|
|
2164
|
-
el.style.opacity = "1";
|
|
2165
|
-
skeleton.remove();
|
|
2166
|
-
};
|
|
2167
|
-
el.addEventListener(media === "image" ? "load" : "loadedmetadata", settled);
|
|
2168
|
-
el.addEventListener("error", () => {
|
|
2169
|
-
const dead = document.createElement("span");
|
|
2170
|
-
dead.setAttribute("part", "message-media-unavailable");
|
|
2171
|
-
dead.textContent = `Preview unavailable — ${describeUrl(src)}`;
|
|
2172
|
-
dead.style.cssText = `
|
|
2173
|
-
display: block;
|
|
2174
|
-
margin-top: 6px;
|
|
2175
|
-
font-size: 11px;
|
|
2176
|
-
opacity: .55;
|
|
2177
|
-
font-style: italic;
|
|
2178
|
-
white-space: nowrap;
|
|
2179
|
-
overflow: hidden;
|
|
2180
|
-
text-overflow: ellipsis;
|
|
2181
|
-
`;
|
|
2182
|
-
card.replaceWith(dead);
|
|
2183
|
-
caption.remove();
|
|
2184
|
-
});
|
|
2185
|
-
card.appendChild(el);
|
|
2186
|
-
card.appendChild(skeleton);
|
|
2187
|
-
const frag = document.createDocumentFragment();
|
|
2188
|
-
frag.appendChild(card);
|
|
2189
|
-
frag.appendChild(caption);
|
|
2204
|
+
if (meta.description) {
|
|
2205
|
+
const d = make("span", "message-site-description", S.siteDescription);
|
|
2206
|
+
d.textContent = meta.description;
|
|
2207
|
+
a.appendChild(d);
|
|
2208
|
+
}
|
|
2209
|
+
if (meta.image) {
|
|
2210
|
+
const img = make("img", "message-site-image", S.siteImage);
|
|
2211
|
+
img.src = meta.image;
|
|
2212
|
+
img.alt = "";
|
|
2213
|
+
img.loading = "lazy";
|
|
2214
|
+
img.addEventListener("error", () => img.remove());
|
|
2215
|
+
a.appendChild(img);
|
|
2216
|
+
}
|
|
2217
|
+
focusRing(a);
|
|
2218
|
+
slot.replaceWith(a);
|
|
2219
|
+
});
|
|
2220
|
+
return slot;
|
|
2221
|
+
};
|
|
2222
|
+
const unavailable = (src, insecure) => {
|
|
2223
|
+
const dead = make("span", "message-media-unavailable", S.unavailable);
|
|
2224
|
+
dead.textContent = `Preview unavailable — ${describeUrl(src)}${insecure ? " (insecure URL)" : ""}`;
|
|
2225
|
+
return dead;
|
|
2226
|
+
};
|
|
2227
|
+
/**
|
|
2228
|
+
* Image or video card. The element is created up front so the fetch starts
|
|
2229
|
+
* immediately; a skeleton covers it until it decodes. Error, timeout, or an
|
|
2230
|
+
* insecure URL collapse the card to one muted line — a character can
|
|
2231
|
+
* invent a URL, and an empty player in the transcript reads as a broken
|
|
2232
|
+
* widget.
|
|
2233
|
+
*/
|
|
2234
|
+
const mediaPreview = (src, alt, kind) => {
|
|
2235
|
+
const frag = document.createDocumentFragment();
|
|
2236
|
+
if (isMixedContent(src)) {
|
|
2237
|
+
frag.appendChild(unavailable(src, true));
|
|
2190
2238
|
return frag;
|
|
2239
|
+
}
|
|
2240
|
+
const card = make("span", "message-media-card", S.card, kind === "image" ? S.cardButton : {});
|
|
2241
|
+
const el = kind === "image"
|
|
2242
|
+
? Object.assign(document.createElement("img"), { src, alt, loading: "lazy" })
|
|
2243
|
+
: Object.assign(document.createElement("video"), { src, controls: true, preload: "metadata" });
|
|
2244
|
+
el.setAttribute("part", "message-media");
|
|
2245
|
+
el.style.cssText = toCssText(Object.assign({}, S.media, kind === "video" ? S.videoMedia : {}, { opacity: 0 }));
|
|
2246
|
+
const skeleton = make("span", "message-media-skeleton", S.skeleton);
|
|
2247
|
+
skeleton.setAttribute("aria-hidden", "true");
|
|
2248
|
+
skeleton.dataset.convaiSkeleton = "";
|
|
2249
|
+
const caption = make("span", "message-media-caption", S.caption);
|
|
2250
|
+
caption.textContent = describeUrl(src);
|
|
2251
|
+
const fail = () => {
|
|
2252
|
+
clearTimeout(timer);
|
|
2253
|
+
card.replaceWith(unavailable(src, false));
|
|
2254
|
+
caption.remove();
|
|
2255
|
+
};
|
|
2256
|
+
const settled = () => {
|
|
2257
|
+
clearTimeout(timer);
|
|
2258
|
+
el.style.opacity = "1";
|
|
2259
|
+
skeleton.remove();
|
|
2260
|
+
if (kind === "image") {
|
|
2261
|
+
const zoom = make("span", "message-media-zoom", S.zoom);
|
|
2262
|
+
zoom.innerHTML = glyph("zoom");
|
|
2263
|
+
card.appendChild(zoom);
|
|
2264
|
+
}
|
|
2191
2265
|
};
|
|
2192
|
-
const
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2266
|
+
const timer = setTimeout(fail, PREVIEW_TIMEOUT_MS);
|
|
2267
|
+
el.addEventListener(kind === "image" ? "load" : "loadedmetadata", settled);
|
|
2268
|
+
el.addEventListener("error", fail);
|
|
2269
|
+
if (kind === "image") {
|
|
2270
|
+
card.setAttribute("role", "button");
|
|
2271
|
+
card.tabIndex = 0;
|
|
2272
|
+
card.setAttribute("aria-label", `Open image: ${fileNameOf(src)}`);
|
|
2273
|
+
const open = () => openLightbox({
|
|
2274
|
+
src,
|
|
2275
|
+
alt,
|
|
2276
|
+
caption: describeUrl(src),
|
|
2277
|
+
href: src,
|
|
2278
|
+
root: styleTarget,
|
|
2279
|
+
returnFocusTo: card,
|
|
2280
|
+
});
|
|
2281
|
+
card.addEventListener("click", open);
|
|
2282
|
+
card.addEventListener("keydown", (e) => {
|
|
2283
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
2284
|
+
e.preventDefault();
|
|
2285
|
+
open();
|
|
2286
|
+
}
|
|
2287
|
+
});
|
|
2288
|
+
}
|
|
2289
|
+
card.append(el, skeleton);
|
|
2290
|
+
frag.append(card, caption);
|
|
2291
|
+
return frag;
|
|
2292
|
+
};
|
|
2293
|
+
const processLine = (line) => {
|
|
2294
|
+
const parts = [];
|
|
2295
|
+
for (const node of parseInlineMarkdown(line)) {
|
|
2296
|
+
switch (node.kind) {
|
|
2297
|
+
case "strong": {
|
|
2298
|
+
// matches React UserBubble styling
|
|
2299
|
+
const strong = document.createElement("strong");
|
|
2300
|
+
strong.textContent = node.text;
|
|
2301
|
+
strong.style.cssText = `
|
|
2201
2302
|
font-weight: 600;
|
|
2202
2303
|
color: var(--convai-panel-fg, ${aeroTheme.colors.text.primary});
|
|
2203
2304
|
`;
|
|
2204
|
-
|
|
2205
|
-
|
|
2305
|
+
parts.push(strong);
|
|
2306
|
+
break;
|
|
2307
|
+
}
|
|
2308
|
+
case "em": {
|
|
2309
|
+
const em = document.createElement("em");
|
|
2310
|
+
em.textContent = node.text;
|
|
2311
|
+
em.style.cssText = `font-style: italic;`;
|
|
2312
|
+
parts.push(em);
|
|
2313
|
+
break;
|
|
2314
|
+
}
|
|
2315
|
+
case "blocked": {
|
|
2316
|
+
// Not an anchor, ever. The label reads as the character wrote it;
|
|
2317
|
+
// the target is only revealed on hover.
|
|
2318
|
+
const blocked = make("span", "message-link-blocked", S.blocked);
|
|
2319
|
+
blocked.textContent = node.label;
|
|
2320
|
+
blocked.title = `Link blocked: ${node.href}`;
|
|
2321
|
+
parts.push(blocked);
|
|
2322
|
+
break;
|
|
2323
|
+
}
|
|
2324
|
+
case "image": {
|
|
2325
|
+
if (media && budget.cards < MAX_CARDS_PER_MESSAGE) {
|
|
2326
|
+
budget.cards++;
|
|
2327
|
+
parts.push(mediaPreview(node.src, node.alt, "image"));
|
|
2206
2328
|
}
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
parts.push(em);
|
|
2212
|
-
break;
|
|
2329
|
+
else {
|
|
2330
|
+
// With previews off (or the budget spent), an image still has to
|
|
2331
|
+
// say what it pointed at, so it degrades to a plain anchor.
|
|
2332
|
+
parts.push(anchor(node.src, "image", node.alt || node.src));
|
|
2213
2333
|
}
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
a.setAttribute("part", "message-link");
|
|
2221
|
-
a.style.cssText = `
|
|
2222
|
-
color: #10b981;
|
|
2223
|
-
text-decoration: underline;
|
|
2224
|
-
word-break: break-all;
|
|
2225
|
-
`;
|
|
2226
|
-
parts.push(a);
|
|
2227
|
-
if (media && node.media)
|
|
2228
|
-
parts.push(mediaPreview(node.href, node.label, node.media));
|
|
2334
|
+
break;
|
|
2335
|
+
}
|
|
2336
|
+
case "link": {
|
|
2337
|
+
const kind = linkKindForUrl(node.href);
|
|
2338
|
+
if (kind === "email" || kind === "phone" || kind === "sms") {
|
|
2339
|
+
parts.push(media ? contactChip(node.href, kind) : anchor(node.href, kind, node.label));
|
|
2229
2340
|
break;
|
|
2230
2341
|
}
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
parts.push(blocked);
|
|
2342
|
+
parts.push(anchor(node.href, kind, node.label));
|
|
2343
|
+
// The budget is spent when the card mounts, not when it resolves,
|
|
2344
|
+
// so the cap stays deterministic for a message naming twenty pages.
|
|
2345
|
+
const wantsSiteCard = media &&
|
|
2346
|
+
kind === "web" &&
|
|
2347
|
+
!!options.linkPreviewResolver &&
|
|
2348
|
+
budget.cards < MAX_CARDS_PER_MESSAGE;
|
|
2349
|
+
if (wantsSiteCard) {
|
|
2350
|
+
budget.cards++;
|
|
2351
|
+
parts.push(siteCard(node.href));
|
|
2242
2352
|
break;
|
|
2243
2353
|
}
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
}
|
|
2249
|
-
// With previews off, an image still has to say what it pointed at,
|
|
2250
|
-
// so it degrades to the same anchor a plain link would render.
|
|
2251
|
-
const imgLink = document.createElement("a");
|
|
2252
|
-
imgLink.href = node.src;
|
|
2253
|
-
imgLink.textContent = node.alt || node.src;
|
|
2254
|
-
imgLink.target = "_blank";
|
|
2255
|
-
imgLink.rel = "noopener noreferrer";
|
|
2256
|
-
imgLink.setAttribute("part", "message-link");
|
|
2257
|
-
imgLink.style.cssText = `
|
|
2258
|
-
color: #10b981;
|
|
2259
|
-
text-decoration: underline;
|
|
2260
|
-
word-break: break-all;
|
|
2261
|
-
`;
|
|
2262
|
-
parts.push(imgLink);
|
|
2354
|
+
const wantsCard = media &&
|
|
2355
|
+
(kind === "image" || kind === "video" || kind === "document") &&
|
|
2356
|
+
budget.cards < MAX_CARDS_PER_MESSAGE;
|
|
2357
|
+
if (!wantsCard)
|
|
2263
2358
|
break;
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2359
|
+
budget.cards++;
|
|
2360
|
+
parts.push(kind === "document" ? documentCard(node.href) : mediaPreview(node.href, node.label, kind));
|
|
2361
|
+
break;
|
|
2267
2362
|
}
|
|
2363
|
+
default:
|
|
2364
|
+
parts.push(document.createTextNode(node.text));
|
|
2268
2365
|
}
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2366
|
+
}
|
|
2367
|
+
return parts;
|
|
2368
|
+
};
|
|
2369
|
+
lines.forEach((line, lineIndex) => {
|
|
2370
|
+
// An empty line is paragraph spacing.
|
|
2273
2371
|
if (line.trim() === "" && lineIndex > 0) {
|
|
2274
2372
|
container.appendChild(document.createElement("br"));
|
|
2275
2373
|
return;
|
|
2276
2374
|
}
|
|
2277
|
-
|
|
2278
|
-
if (
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
else {
|
|
2375
|
+
const processed = processLine(line);
|
|
2376
|
+
if (processed.length > 0)
|
|
2377
|
+
processed.forEach((p) => container.appendChild(p));
|
|
2378
|
+
else
|
|
2282
2379
|
container.appendChild(document.createTextNode(line));
|
|
2283
|
-
|
|
2284
|
-
// Add line break between lines
|
|
2285
|
-
if (lineIndex < lines.length - 1) {
|
|
2380
|
+
if (lineIndex < lines.length - 1)
|
|
2286
2381
|
container.appendChild(document.createElement("br"));
|
|
2287
|
-
}
|
|
2288
2382
|
});
|
|
2289
2383
|
};
|
|
2290
2384
|
const updateMessageList = () => {
|