@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.
Files changed (147) hide show
  1. package/dist/core/AudioManager.d.ts +3 -3
  2. package/dist/core/AudioManager.js +1 -1
  3. package/dist/core/CharacterRoster.d.ts +1 -1
  4. package/dist/core/CharacterVersionManager.d.ts +2 -2
  5. package/dist/core/CharacterVersionManager.js +1 -1
  6. package/dist/core/ConnectionStateHandler.d.ts +1 -1
  7. package/dist/core/ConvaiClient.d.ts +6 -6
  8. package/dist/core/ConvaiClient.d.ts.map +1 -1
  9. package/dist/core/ConvaiClient.js +34 -28
  10. package/dist/core/ConvaiClient.js.map +1 -1
  11. package/dist/core/MemoryManager.d.ts +1 -1
  12. package/dist/core/MessageHandler.d.ts +7 -4
  13. package/dist/core/MessageHandler.d.ts.map +1 -1
  14. package/dist/core/MessageHandler.js +68 -43
  15. package/dist/core/MessageHandler.js.map +1 -1
  16. package/dist/core/SSESession.d.ts +7 -8
  17. package/dist/core/SSESession.d.ts.map +1 -1
  18. package/dist/core/SSESession.js +225 -11
  19. package/dist/core/SSESession.js.map +1 -1
  20. package/dist/core/ScreenShareManager.d.ts +2 -2
  21. package/dist/core/ScreenShareManager.js +2 -2
  22. package/dist/core/VideoManager.d.ts +2 -2
  23. package/dist/core/VideoManager.js +3 -3
  24. package/dist/core/connectRequest.d.ts +1 -1
  25. package/dist/core/contextUpdateRequest.d.ts +1 -1
  26. package/dist/core/index.d.ts +25 -21
  27. package/dist/core/index.d.ts.map +1 -1
  28. package/dist/core/index.js +19 -17
  29. package/dist/core/index.js.map +1 -1
  30. package/dist/core/modelOutput.d.ts +2 -2
  31. package/dist/core/publishedChat.d.ts +1 -1
  32. package/dist/core/rosterRequest.d.ts +1 -1
  33. package/dist/core/rosterRequest.js +1 -1
  34. package/dist/core/rtviEnvelope.d.ts +6 -0
  35. package/dist/core/rtviEnvelope.d.ts.map +1 -0
  36. package/dist/core/rtviEnvelope.js +10 -0
  37. package/dist/core/rtviEnvelope.js.map +1 -0
  38. package/dist/core/types.d.ts +27 -9
  39. package/dist/core/types.d.ts.map +1 -1
  40. package/dist/core/types.js.map +1 -1
  41. package/dist/core/videoSourceState.d.ts +1 -1
  42. package/dist/core/visionRequest.d.ts +1 -1
  43. package/dist/embed/ConvaiChatElement.js +2 -2
  44. package/dist/embed/browser.d.ts +2 -2
  45. package/dist/embed/browser.js +3 -3
  46. package/dist/embed/chat-embed-v1.js +14 -14
  47. package/dist/embed/chat-embed-v1.js.map +4 -4
  48. package/dist/index.d.ts +2 -2
  49. package/dist/index.js +2 -2
  50. package/dist/lipsync-helpers/createBlendshapeQueue.d.ts +2 -2
  51. package/dist/lipsync-helpers/createBlendshapeQueue.js +2 -2
  52. package/dist/lipsync-helpers/declarativeMapping.d.ts +1 -1
  53. package/dist/lipsync-helpers/declarativeMapping.js +2 -2
  54. package/dist/lipsync-helpers/index.d.ts +12 -12
  55. package/dist/lipsync-helpers/index.js +9 -9
  56. package/dist/lipsync-helpers/mhaLimitDrivers.js +2 -2
  57. package/dist/lipsync-helpers/naturalness/processor.d.ts +1 -1
  58. package/dist/lipsync-helpers/naturalness/processor.js +1 -1
  59. package/dist/lipsync-helpers/naturalness/profiles/mha.d.ts +1 -1
  60. package/dist/lipsync-helpers/naturalness/profiles/mha.js +1 -1
  61. package/dist/lipsync-helpers/presetMappers.d.ts +1 -1
  62. package/dist/react/components/ConvaiWidget.d.ts +11 -2
  63. package/dist/react/components/ConvaiWidget.d.ts.map +1 -1
  64. package/dist/react/components/ConvaiWidget.js +7 -7
  65. package/dist/react/components/ConvaiWidget.js.map +1 -1
  66. package/dist/react/components/index.d.ts +1 -1
  67. package/dist/react/components/index.js +1 -1
  68. package/dist/react/components/rtc-widget/components/AudioSettingsPanel.d.ts +1 -1
  69. package/dist/react/components/rtc-widget/components/ConviMessage.d.ts +4 -1
  70. package/dist/react/components/rtc-widget/components/ConviMessage.d.ts.map +1 -1
  71. package/dist/react/components/rtc-widget/components/ConviMessage.js +5 -5
  72. package/dist/react/components/rtc-widget/components/ConviMessage.js.map +1 -1
  73. package/dist/react/components/rtc-widget/components/FloatingVideo.js +3 -3
  74. package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts +21 -3
  75. package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts.map +1 -1
  76. package/dist/react/components/rtc-widget/components/MarkdownRenderer.js +114 -130
  77. package/dist/react/components/rtc-widget/components/MarkdownRenderer.js.map +1 -1
  78. package/dist/react/components/rtc-widget/components/MessageBubble.js +1 -1
  79. package/dist/react/components/rtc-widget/components/MessageList.d.ts +5 -2
  80. package/dist/react/components/rtc-widget/components/MessageList.d.ts.map +1 -1
  81. package/dist/react/components/rtc-widget/components/MessageList.js +6 -6
  82. package/dist/react/components/rtc-widget/components/MessageList.js.map +1 -1
  83. package/dist/react/components/rtc-widget/components/SiteCard.d.ts +15 -0
  84. package/dist/react/components/rtc-widget/components/SiteCard.d.ts.map +1 -0
  85. package/dist/react/components/rtc-widget/components/SiteCard.js +35 -0
  86. package/dist/react/components/rtc-widget/components/SiteCard.js.map +1 -0
  87. package/dist/react/components/rtc-widget/components/UserMessage.js +3 -3
  88. package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.js +4 -4
  89. package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.js +3 -3
  90. package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.js +4 -4
  91. package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.js +3 -3
  92. package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js +3 -3
  93. package/dist/react/components/rtc-widget/components/conviComponents/index.d.ts +5 -5
  94. package/dist/react/components/rtc-widget/components/conviComponents/index.js +5 -5
  95. package/dist/react/components/rtc-widget/components/index.d.ts +8 -8
  96. package/dist/react/components/rtc-widget/components/index.js +9 -9
  97. package/dist/react/components/rtc-widget/index.d.ts +5 -5
  98. package/dist/react/components/rtc-widget/index.js +3 -3
  99. package/dist/react/components/rtc-widget/styles/icons.d.ts +1 -1
  100. package/dist/react/components/rtc-widget/styles/icons.js +1 -1
  101. package/dist/react/components/rtc-widget/styles/index.d.ts +5 -5
  102. package/dist/react/components/rtc-widget/styles/index.js +4 -4
  103. package/dist/react/components/rtc-widget/styles/styledComponents.js +1 -1
  104. package/dist/react/hooks/index.d.ts +3 -3
  105. package/dist/react/hooks/index.js +3 -3
  106. package/dist/react/hooks/useCharacterInfo.js +1 -1
  107. package/dist/react/hooks/useConvaiClient.d.ts +1 -1
  108. package/dist/react/hooks/useConvaiClient.js +1 -1
  109. package/dist/react/index.d.ts +13 -9
  110. package/dist/react/index.d.ts.map +1 -1
  111. package/dist/react/index.js +10 -8
  112. package/dist/react/index.js.map +1 -1
  113. package/dist/utils/lightbox.d.ts +16 -0
  114. package/dist/utils/lightbox.d.ts.map +1 -0
  115. package/dist/utils/lightbox.js +95 -0
  116. package/dist/utils/lightbox.js.map +1 -0
  117. package/dist/utils/linkPresentation.d.ts +76 -0
  118. package/dist/utils/linkPresentation.d.ts.map +1 -0
  119. package/dist/utils/linkPresentation.js +415 -0
  120. package/dist/utils/linkPresentation.js.map +1 -0
  121. package/dist/utils/linkPreview.d.ts +46 -0
  122. package/dist/utils/linkPreview.d.ts.map +1 -0
  123. package/dist/utils/linkPreview.js +72 -0
  124. package/dist/utils/linkPreview.js.map +1 -0
  125. package/dist/vanilla/AudioRenderer.js +1 -1
  126. package/dist/vanilla/ConvaiWidget.d.ts +1 -1
  127. package/dist/vanilla/ConvaiWidget.d.ts.map +1 -1
  128. package/dist/vanilla/ConvaiWidget.js +287 -193
  129. package/dist/vanilla/ConvaiWidget.js.map +1 -1
  130. package/dist/vanilla/WebSocketSession.d.ts +1 -1
  131. package/dist/vanilla/WebSocketSession.js +1 -1
  132. package/dist/vanilla/index.d.ts +13 -9
  133. package/dist/vanilla/index.d.ts.map +1 -1
  134. package/dist/vanilla/index.js +9 -7
  135. package/dist/vanilla/index.js.map +1 -1
  136. package/dist/vanilla/styles.d.ts.map +1 -1
  137. package/dist/vanilla/styles.js +9 -0
  138. package/dist/vanilla/styles.js.map +1 -1
  139. package/dist/vanilla/types.d.ts +11 -2
  140. package/dist/vanilla/types.d.ts.map +1 -1
  141. package/dist/vanilla/types.js.map +1 -1
  142. package/dist/vanilla/websocket.d.ts +1 -1
  143. package/dist/vanilla/websocket.js +2 -2
  144. package/dist/version.d.ts +1 -1
  145. package/dist/version.js +1 -1
  146. package/dist/version.js.map +1 -1
  147. package/package.json +2 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linkPreview.js","sourceRoot":"","sources":["../../src/utils/linkPreview.ts"],"names":[],"mappings":"AA+BA,4EAA4E;AAC5E,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC;AAC5C,8CAA8C;AAC9C,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAE3C,qEAAqE;AACrE,MAAM,UAAU,YAAY,CAAC,IAAwC;IACnE,OAAO,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,WAAW,CAAC,KAAyB;IACnD,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;QACzB,OAAO,CAAC,CAAC,QAAQ,KAAK,OAAO,IAAI,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAChF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAqB,EAAE,GAAW;IAC5D,IAAI,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC,QAAQ,CAAC;IACxC,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACrD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG,CAAC;IACb,CAAC;AACH,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,UAAU,CAAC,IAAqB,EAAE,GAAW;IAC3D,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3C,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAC9B,IAAI,CAAC;QACH,OAAO,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,cAAc,CAAC;IAC9C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,KAAK,GAAG,IAAI,GAAG,EAA2C,CAAC;AAEjE;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CACtC,QAA6B,EAC7B,GAAW;IAEX,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,GAAG;QAAE,OAAO,GAAG,CAAC;IAEpB,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,uBAAuB,CAAC,CAAC;IAC5E,MAAM,CAAC,GAAG,OAAO,CAAC,OAAO,EAAE;SACxB,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;SAC5C,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CACb,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAC9F;SACA,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;SACjB,OAAO,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;IAEtC,IAAI,KAAK,CAAC,IAAI,IAAI,uBAAuB,EAAE,CAAC;QAC1C,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,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.js';
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.js";
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;AA4HjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,WAAW,EACtB,OAAO,EAAE,oBAAoB,GAC5B,aAAa,CAk5Ff;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAE/D"}
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.js";
6
- import { aeroTheme, injectGlobalStyles, injectKeyframes, } from "./styles.js";
7
- import { Icons } from "./icons.js";
8
- import { WidgetEventSubscriptions } from "./WidgetEventSubscriptions.js";
9
- import { ConvaiClient } from "../core/ConvaiClient.js";
10
- import { parseInlineMarkdown, compactUrl } from "../utils/inlineMarkdown.js";
11
- import { freshPublicationGrantOptions } from "../core/publishedChat.js";
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
- // Helper for Markdown - matches React MarkdownRenderer.tsx
2078
- // `media` renders inline image/video previews under a media link. Bot messages
2079
- // want them; the user's own bubble does not — you already know what you typed,
2080
- // and a preview there would let a URL a user pasted embed remote media into
2081
- // the transcript. Links stay clickable either way.
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 escape sequences
2086
- const normalizedText = text.replace(/\\n/g, "\n");
2087
- const lines = normalizedText.split("\n");
2088
- lines.forEach((line, lineIndex) => {
2089
- // Process markdown within each line
2090
- // Bold, italic, links, images and bare URLs — see utils/inlineMarkdown.
2091
- // `cdn.example.com/a/b/c.png` -> `cdn.example.com · c.png`
2092
- const describeUrl = (url) => {
2093
- try {
2094
- const { host, pathname } = new URL(url);
2095
- const file = pathname.split("/").filter(Boolean).pop();
2096
- return file ? `${host} · ${file}` : host;
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
- catch {
2099
- return url;
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
- * A preview card that reserves its space before the media arrives, so the
2104
- * bubble does not jump when an image decodes, and collapses to one muted
2105
- * line if the URL does not resolve — a character can easily invent one,
2106
- * and an empty player in the transcript reads as a broken widget.
2107
- *
2108
- * Chrome is derived from the inherited text colour: the widget is embedded
2109
- * in someone else's page, on a background this code cannot know.
2110
- */
2111
- const mediaPreview = (src, alt, media) => {
2112
- const card = document.createElement("span");
2113
- card.setAttribute("part", "message-media-card");
2114
- card.style.cssText = `
2115
- display: block;
2116
- position: relative;
2117
- margin-top: 6px;
2118
- max-width: 320px;
2119
- aspect-ratio: 16 / 10;
2120
- border-radius: 8px;
2121
- overflow: hidden;
2122
- background: color-mix(in srgb, currentColor 6%, transparent);
2123
- box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 10%, transparent);
2124
- `;
2125
- const el = media === "image"
2126
- ? Object.assign(document.createElement("img"), { src, alt, loading: "lazy" })
2127
- : Object.assign(document.createElement("video"), { src, controls: true, preload: "metadata" });
2128
- el.setAttribute("part", "message-media");
2129
- el.style.cssText = `
2130
- display: block;
2131
- width: 100%;
2132
- height: 100%;
2133
- object-fit: ${media === "image" ? "cover" : "contain"};
2134
- border-radius: 8px;
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 processLine = (text) => {
2193
- const parts = [];
2194
- for (const node of parseInlineMarkdown(text)) {
2195
- switch (node.kind) {
2196
- case "strong": {
2197
- // matches React UserBubble styling
2198
- const strong = document.createElement("strong");
2199
- strong.textContent = node.text;
2200
- strong.style.cssText = `
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
- parts.push(strong);
2205
- break;
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
- case "em": {
2208
- const em = document.createElement("em");
2209
- em.textContent = node.text;
2210
- em.style.cssText = `font-style: italic;`;
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
- case "link": {
2215
- const a = document.createElement("a");
2216
- a.href = node.href;
2217
- a.textContent = node.label === node.href ? compactUrl(node.label) : node.label;
2218
- a.target = "_blank";
2219
- a.rel = "noopener noreferrer";
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
- case "blocked": {
2232
- const blocked = document.createElement("span");
2233
- blocked.setAttribute("part", "message-link-blocked");
2234
- blocked.textContent = node.label;
2235
- blocked.title = `Link blocked: ${node.href}`;
2236
- blocked.style.cssText = `
2237
- opacity: .75;
2238
- text-decoration: underline dotted;
2239
- cursor: help;
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
- case "image": {
2245
- if (media) {
2246
- parts.push(mediaPreview(node.src, node.alt, "image"));
2247
- break;
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
- default:
2266
- parts.push(document.createTextNode(node.text));
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
- return parts;
2270
- };
2271
- const processedLine = processLine(line);
2272
- // Handle empty lines (creates paragraph spacing)
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
- // Append the processed line
2278
- if (processedLine.length > 0) {
2279
- processedLine.forEach((part) => container.appendChild(part));
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 = () => {