@convai/web-sdk 1.9.1 → 2.0.0-beta.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.
Files changed (86) hide show
  1. package/README.md +25 -14
  2. package/dist/core/ConvaiClient.js +10 -1
  3. package/dist/core/types.d.ts +13 -3
  4. package/dist/core/websocketUrl.d.ts +11 -0
  5. package/dist/core/websocketUrl.js +17 -0
  6. package/dist/react/hooks/index.d.ts +0 -2
  7. package/dist/react/hooks/index.js +0 -3
  8. package/dist/react/index.d.ts +0 -3
  9. package/dist/react/index.js +3 -10
  10. package/dist/utils/inlineMarkdown.d.ts +7 -5
  11. package/dist/utils/inlineMarkdown.js +7 -5
  12. package/dist/vanilla/WebSocketSession.d.ts +19 -13
  13. package/dist/vanilla/WebSocketSession.js +58 -14
  14. package/dist/vanilla/index.d.ts +6 -18
  15. package/dist/vanilla/index.js +7 -19
  16. package/dist/version.d.ts +1 -1
  17. package/dist/version.js +1 -1
  18. package/package.json +9 -8
  19. package/dist/react/components/ConvaiWidget.d.ts +0 -86
  20. package/dist/react/components/ConvaiWidget.js +0 -610
  21. package/dist/react/components/index.d.ts +0 -1
  22. package/dist/react/components/index.js +0 -2
  23. package/dist/react/components/rtc-widget/components/AudioSettingsPanel.d.ts +0 -9
  24. package/dist/react/components/rtc-widget/components/AudioSettingsPanel.js +0 -315
  25. package/dist/react/components/rtc-widget/components/AudioVisualizer.d.ts +0 -35
  26. package/dist/react/components/rtc-widget/components/AudioVisualizer.js +0 -285
  27. package/dist/react/components/rtc-widget/components/ConviMessage.d.ts +0 -12
  28. package/dist/react/components/rtc-widget/components/ConviMessage.js +0 -13
  29. package/dist/react/components/rtc-widget/components/FloatingVideo.d.ts +0 -8
  30. package/dist/react/components/rtc-widget/components/FloatingVideo.js +0 -120
  31. package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts +0 -31
  32. package/dist/react/components/rtc-widget/components/MarkdownRenderer.js +0 -140
  33. package/dist/react/components/rtc-widget/components/MessageBubble.d.ts +0 -9
  34. package/dist/react/components/rtc-widget/components/MessageBubble.js +0 -22
  35. package/dist/react/components/rtc-widget/components/MessageList.d.ts +0 -13
  36. package/dist/react/components/rtc-widget/components/MessageList.js +0 -88
  37. package/dist/react/components/rtc-widget/components/SiteCard.d.ts +0 -14
  38. package/dist/react/components/rtc-widget/components/SiteCard.js +0 -34
  39. package/dist/react/components/rtc-widget/components/UserMessage.d.ts +0 -8
  40. package/dist/react/components/rtc-widget/components/UserMessage.js +0 -14
  41. package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.d.ts +0 -5
  42. package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.js +0 -14
  43. package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.d.ts +0 -24
  44. package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.js +0 -170
  45. package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.d.ts +0 -16
  46. package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.js +0 -64
  47. package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.d.ts +0 -11
  48. package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.js +0 -65
  49. package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts +0 -13
  50. package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js +0 -298
  51. package/dist/react/components/rtc-widget/components/conviComponents/index.d.ts +0 -5
  52. package/dist/react/components/rtc-widget/components/conviComponents/index.js +0 -5
  53. package/dist/react/components/rtc-widget/components/index.d.ts +0 -8
  54. package/dist/react/components/rtc-widget/components/index.js +0 -14
  55. package/dist/react/components/rtc-widget/index.d.ts +0 -5
  56. package/dist/react/components/rtc-widget/index.js +0 -8
  57. package/dist/react/components/rtc-widget/styles/framerConfig.d.ts +0 -115
  58. package/dist/react/components/rtc-widget/styles/framerConfig.js +0 -72
  59. package/dist/react/components/rtc-widget/styles/icons.d.ts +0 -27
  60. package/dist/react/components/rtc-widget/styles/icons.js +0 -256
  61. package/dist/react/components/rtc-widget/styles/index.d.ts +0 -5
  62. package/dist/react/components/rtc-widget/styles/index.js +0 -8
  63. package/dist/react/components/rtc-widget/styles/styledComponents.d.ts +0 -89
  64. package/dist/react/components/rtc-widget/styles/styledComponents.js +0 -662
  65. package/dist/react/components/rtc-widget/styles/theme.d.ts +0 -187
  66. package/dist/react/components/rtc-widget/styles/theme.js +0 -289
  67. package/dist/react/components/rtc-widget/types/index.d.ts +0 -59
  68. package/dist/react/components/rtc-widget/types/index.js +0 -1
  69. package/dist/react/hooks/useCharacterInfo.d.ts +0 -18
  70. package/dist/react/hooks/useCharacterInfo.js +0 -65
  71. package/dist/react/hooks/useLocalCameraTrack.d.ts +0 -21
  72. package/dist/react/hooks/useLocalCameraTrack.js +0 -33
  73. package/dist/react/icons.d.ts +0 -37
  74. package/dist/react/icons.js +0 -53
  75. package/dist/utils/lightbox.d.ts +0 -15
  76. package/dist/utils/lightbox.js +0 -94
  77. package/dist/vanilla/ConvaiWidget.d.ts +0 -46
  78. package/dist/vanilla/ConvaiWidget.js +0 -2866
  79. package/dist/vanilla/WidgetEventSubscriptions.d.ts +0 -14
  80. package/dist/vanilla/WidgetEventSubscriptions.js +0 -36
  81. package/dist/vanilla/icons.d.ts +0 -34
  82. package/dist/vanilla/icons.js +0 -268
  83. package/dist/vanilla/styles.d.ts +0 -168
  84. package/dist/vanilla/styles.js +0 -407
  85. package/dist/vanilla/types.d.ts +0 -170
  86. package/dist/vanilla/types.js +0 -1
package/README.md CHANGED
@@ -6,11 +6,18 @@
6
6
  [![TypeScript](https://img.shields.io/badge/TypeScript-first-3178C6)](https://www.typescriptlang.org/)
7
7
  [![License](https://img.shields.io/badge/license-Apache--2.0-green)](./LICENSE)
8
8
 
9
- TypeScript-first SDK for embedding Convai AI characters into React and vanilla JS applications. Voice, text, lipsync, emotions, video, and screen share — all in one package.
9
+ TypeScript-first SDK for embedding Convai AI characters into React and vanilla JS applications. Voice, text, lipsync, emotions, video, and screen share. The ready-made chat UI is the companion package [`@convai/web-widget`](https://www.npmjs.com/package/@convai/web-widget).
10
10
 
11
11
  ---
12
12
 
13
- ## What's new in 1.9.0
13
+ ## What's new in 2.0 (beta)
14
+
15
+ Install the beta with `npm install @convai/web-sdk@beta @convai/web-widget`.
16
+
17
+ - **Headless core.** The SDK ships no UI. `ConvaiWidget`, `MarkdownRenderer`, `AudioRenderer`/`AudioContext` (the React ones) and `createConvaiWidget` are now in [`@convai/web-widget`](https://www.npmjs.com/package/@convai/web-widget) (`/react`, `/vanilla`). Moving them is an import change; the [CHANGELOG](./CHANGELOG.md) has the before/after.
18
+ - **A lighter install.** `styled-components`, `framer-motion` and `@livekit/components-react` no longer come with the SDK, and `react` is an optional peer, needed only for `@convai/web-sdk/react`.
19
+
20
+ ### Previously in 1.9.0
14
21
 
15
22
  > **Breaking for 1.8.0 users:** the `<convai-chat>` custom element and the `./embed/browser` entry point (`dist/embed/chat-embed-v1.js`) are removed. The copy/paste published-chat embed is now `<convai-widget>` from [`@convai/web-widget`](https://www.npmjs.com/package/@convai/web-widget); the [CHANGELOG](./CHANGELOG.md) has the before/after snippet.
16
23
 
@@ -66,7 +73,7 @@ TypeScript-first SDK for embedding Convai AI characters into React and vanilla J
66
73
 
67
74
  ## Features
68
75
 
69
- - **React & vanilla JS** — `useConvaiClient` hook, `ConvaiWidget`, and a framework-agnostic core
76
+ - **React & vanilla JS** — `useConvaiClient` hook and a framework-agnostic core; the prebuilt chat UI (`ConvaiWidget`, `createConvaiWidget`) is in `@convai/web-widget`
70
77
  - **Real-time audio/video** — full-duplex WebRTC with echo cancellation, camera, and screen share
71
78
  - **Lipsync** — ARKit and MetaHuman blendshape streams for facial animation
72
79
  - **Emotions & state of mind** — per-turn emotion detection with intensity scale, plus a settable generation mood
@@ -87,14 +94,16 @@ TypeScript-first SDK for embedding Convai AI characters into React and vanilla J
87
94
  ## Installation
88
95
 
89
96
  ```bash
90
- npm install @convai/web-sdk
97
+ npm install @convai/web-sdk @convai/web-widget
91
98
  # or
92
- pnpm add @convai/web-sdk
99
+ pnpm add @convai/web-sdk @convai/web-widget
93
100
  # or
94
- yarn add @convai/web-sdk
101
+ yarn add @convai/web-sdk @convai/web-widget
95
102
  ```
96
103
 
97
- **React peer dependencies:** `react` and `react-dom` `^18 || ^19`
104
+ `@convai/web-widget` is the ready-made chat UI (`ConvaiWidget` for React, `createConvaiWidget` for vanilla). Since 2.0 the SDK ships no UI, so skip the widget if you build your own interface.
105
+
106
+ **React peer dependency:** `react` `^18 || ^19`, needed only for `@convai/web-sdk/react`.
98
107
 
99
108
  **Runtime requirement:** secure context (`https://` or `http://localhost`) for microphone/camera access.
100
109
 
@@ -105,7 +114,8 @@ yarn add @convai/web-sdk
105
114
  ### React
106
115
 
107
116
  ```tsx
108
- import { useConvaiClient, ConvaiWidget } from "@convai/web-sdk";
117
+ import { useConvaiClient } from "@convai/web-sdk";
118
+ import { ConvaiWidget } from "@convai/web-widget/react";
109
119
 
110
120
  export function App() {
111
121
  const client = useConvaiClient({
@@ -120,7 +130,8 @@ export function App() {
120
130
  ### Vanilla TypeScript
121
131
 
122
132
  ```ts
123
- import { ConvaiClient, createConvaiWidget } from "@convai/web-sdk/vanilla";
133
+ import { ConvaiClient } from "@convai/web-sdk/vanilla";
134
+ import { createConvaiWidget } from "@convai/web-widget/vanilla";
124
135
 
125
136
  const client = new ConvaiClient({
126
137
  apiKey: import.meta.env.VITE_CONVAI_API_KEY,
@@ -277,9 +288,9 @@ Full documentation is at **<a href="https://docs.convai.com/api-docs/plugins-and
277
288
 
278
289
  | Import path | Contents |
279
290
  | ----------------------------------- | --------------------------------------------------------------------------------------------------------------- |
280
- | `@convai/web-sdk` | React hooks, components, and re-exported core types |
291
+ | `@convai/web-sdk` | React hooks and re-exported core types (no UI; see `@convai/web-widget`) |
281
292
  | `@convai/web-sdk/react` | Same as default (React-explicit alias) |
282
- | `@convai/web-sdk/vanilla` | `ConvaiClient`, `createConvaiWidget`, `AudioRenderer` |
293
+ | `@convai/web-sdk/vanilla` | `ConvaiClient` and the headless `AudioRenderer` (the widget is `@convai/web-widget/vanilla`) |
283
294
  | `@convai/web-sdk/core` | Framework-agnostic `ConvaiClient`, managers, and all types |
284
295
  | `@convai/web-sdk/embed` | Server-safe publication descriptor and grant helpers |
285
296
  | `@convai/web-sdk/lipsync-helpers` | Blendshape format utilities and queue helpers |
@@ -400,8 +411,8 @@ personal access token; every method rejects with `CharacterApiError` (`status`,
400
411
  non-2xx answer. Point `characterApiUrl` at `https://api2-stg.convai.com` to author against
401
412
  staging.
402
413
 
403
- Explicit selectors are resolved by the runtime through the Character REST platform. Staging has
404
- this today; production answers explicit selectors with `503` until it is promoted there.
414
+ Explicit selectors are resolved by the runtime through the Character REST platform, on both
415
+ production and staging. A runtime without version resolution answers them with `503`.
405
416
  Full guide: [Character Versioning](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk/character-versioning).
406
417
 
407
418
  ---
@@ -448,7 +459,7 @@ Key points:
448
459
 
449
460
  - `characters` and `characterId` are mutually exclusive, and roster entries take a bare character UUID (no `-draft` / `-1.2` selectors).
450
461
  - `provisioningStatus` describes dispatch only; a member is usable when its own `characterReady` arrives.
451
- - Transcript rows, `characterAudioTrack` events and `botReady` payloads carry `membershipId`, so two copies of one character never merge.
462
+ - Transcript rows, `characterAudioTrack` events and `characterReady` payloads carry `membershipId`, so two copies of one character never merge. (`botReady` takes no arguments.)
452
463
  - Room-topology failures throw `ConvaiRoomError` with `status`, `code`, `requestTraceId` and `isRetryable`; the SDK retries `ROSTER_PROVISIONING_IN_PROGRESS` for you (`rosterProvisioningRetry`).
453
464
  - Action protocol v2 and `actionConfig.tools` are single-character only and cannot be combined with a roster.
454
465
 
@@ -2,6 +2,7 @@ import { Room, RoomEvent, ConnectionState, DefaultReconnectPolicy, setLogLevel,
2
2
  setLogLevel("warn");
3
3
  import { DisconnectReasonEnum, } from "./types.js";
4
4
  import { AudioManager } from "./AudioManager.js";
5
+ import { secureWebSocketUrl } from "./websocketUrl.js";
5
6
  import { VideoManager } from "./VideoManager.js";
6
7
  import { ScreenShareManager } from "./ScreenShareManager.js";
7
8
  import { MessageHandler } from "./MessageHandler.js";
@@ -435,6 +436,9 @@ export class ConvaiClient extends EventEmitter {
435
436
  // session-wide setting is the only one that can apply to it.
436
437
  this._wsBotAudioTrack.enabled = !this._characterMuted;
437
438
  }
439
+ // Pipecat's WebSocket transport plays the character's audio itself and
440
+ // exposes no track, so the session silences its own player instead.
441
+ this._wsSession?.setBotAudioMuted?.(this._characterMuted);
438
442
  if (this._room.state !== ConnectionState.Connected)
439
443
  return;
440
444
  this._room.remoteParticipants.forEach((participant) => {
@@ -1562,7 +1566,9 @@ export class ConvaiClient extends EventEmitter {
1562
1566
  if (transportType === "websocket") {
1563
1567
  // ── WebSocket (Pipecat) transport path ────────────────────────────
1564
1568
  // Server returns the WebSocket URL in room_url (same field as LiveKit).
1565
- const wsUrl = connectionData.room_url;
1569
+ // Hosted Convai returns ws:// for a TLS-only endpoint; see websocketUrl.ts.
1570
+ const roomUrl = connectionData.room_url;
1571
+ const wsUrl = roomUrl && secureWebSocketUrl(roomUrl, configWithDefaults.url);
1566
1572
  if (!wsUrl) {
1567
1573
  throw new Error("No WebSocket URL returned from /connect endpoint (expected room_url)");
1568
1574
  }
@@ -1575,6 +1581,9 @@ export class ConvaiClient extends EventEmitter {
1575
1581
  // after the connection is established (enableMic(false) works once the
1576
1582
  // stream exists, but not before it is initialized).
1577
1583
  this._wsSession = _wsFactory((payload) => this._messageHandler.handleDataReceivedPublic(payload), true);
1584
+ // The mute setting outlives sessions: a reconnect must not hand back an
1585
+ // audible character.
1586
+ this._wsSession.setBotAudioMuted?.(this._characterMuted);
1578
1587
  const webSocketVisionEnabled = configWithDefaults.enableVideo === true &&
1579
1588
  effectiveVisionInputConfig?.enabled !== false;
1580
1589
  if (webSocketVisionEnabled) {
@@ -72,6 +72,12 @@ export interface IWebSocketSession {
72
72
  disconnect(): Promise<void>;
73
73
  sendMessage(type: string, data: unknown): void;
74
74
  enableMic(enable: boolean): void;
75
+ /**
76
+ * Silence (or restore) the character's audio for the listener. Optional: an
77
+ * implementation that exposes the bot audio as a track can leave it out and
78
+ * let `botAudioTrack` carry the mute instead.
79
+ */
80
+ setBotAudioMuted?(muted: boolean): void;
75
81
  on(event: string, listener: (...args: any[]) => void): () => void;
76
82
  off(event: string, listener: (...args: any[]) => void): void;
77
83
  }
@@ -922,9 +928,13 @@ export interface ConvaiConfig {
922
928
  * which also drops link targets: `[Doc](https://…/a.pdf)` reaches the client
923
929
  * as `Doc`. With this on, the session preserves `[text](url)`, `![alt](url)`
924
930
  * and bare `http(s)://` URLs verbatim (trailing sentence punctuation stays
925
- * outside the URL, non-http(s) schemes are still stripped) while bold,
926
- * headings, tables and code are flattened as before. Speech is unaffected —
927
- * URLs are never read aloud.
931
+ * outside the URL) while bold, headings, tables and code are flattened as
932
+ * before. Speech is unaffected — URLs are never read aloud.
933
+ *
934
+ * The server does not sanitise schemes: a markdown link keeps its target
935
+ * whatever the scheme, `[x](javascript:…)` included (only bare URLs are
936
+ * limited to http(s)). @convai/web-widget's renderers allow only safe schemes;
937
+ * a custom renderer must check every href with `isSafeHref`.
928
938
  *
929
939
  * Both widgets render the preserved form as clickable links, with inline
930
940
  * previews for image and video URLs. If you render `chatMessages` yourself,
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The WebSocket URL from a `/connect` response, made safe to open.
3
+ *
4
+ * Hosted Convai answers `/connect` over https but returns `ws://…/chat` in
5
+ * `room_url`, and that endpoint only accepts TLS: a plain `ws://` socket is
6
+ * refused (the browser reports close code 1006). A `ws://` URL is upgraded to
7
+ * `wss://` when the `/connect` URL was https, or when the page itself is https,
8
+ * where the browser would block an insecure socket anyway. Local development
9
+ * over http keeps `ws://`.
10
+ */
11
+ export declare function secureWebSocketUrl(roomUrl: string, connectUrl?: string | null, pageProtocol?: string | undefined): string;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The WebSocket URL from a `/connect` response, made safe to open.
3
+ *
4
+ * Hosted Convai answers `/connect` over https but returns `ws://…/chat` in
5
+ * `room_url`, and that endpoint only accepts TLS: a plain `ws://` socket is
6
+ * refused (the browser reports close code 1006). A `ws://` URL is upgraded to
7
+ * `wss://` when the `/connect` URL was https, or when the page itself is https,
8
+ * where the browser would block an insecure socket anyway. Local development
9
+ * over http keeps `ws://`.
10
+ */
11
+ export function secureWebSocketUrl(roomUrl, connectUrl, pageProtocol = typeof location !== "undefined" ? location.protocol : undefined) {
12
+ if (!/^ws:\/\//i.test(roomUrl))
13
+ return roomUrl;
14
+ const secureConnect = typeof connectUrl === "string" && /^https:\/\//i.test(connectUrl);
15
+ const securePage = pageProtocol === "https:";
16
+ return secureConnect || securePage ? roomUrl.replace(/^ws:\/\//i, "wss://") : roomUrl;
17
+ }
@@ -1,3 +1 @@
1
1
  export { useConvaiClient } from './useConvaiClient.js';
2
- export { useCharacterInfo } from './useCharacterInfo.js';
3
- export { useLocalCameraTrack } from './useLocalCameraTrack.js';
@@ -1,5 +1,2 @@
1
1
  // Main hook
2
2
  export { useConvaiClient } from './useConvaiClient.js';
3
- // Additional hooks
4
- export { useCharacterInfo } from './useCharacterInfo.js';
5
- export { useLocalCameraTrack } from './useLocalCameraTrack.js';
@@ -1,6 +1,4 @@
1
1
  export { useConvaiClient } from './hooks/useConvaiClient.js';
2
- export { ConvaiWidget } from './components/ConvaiWidget.js';
3
- export { MarkdownRenderer } from './components/rtc-widget/components/MarkdownRenderer.js';
4
2
  export { parseInlineMarkdown, mediaKindForUrl, isSafeHref, compactUrl } from '../utils/inlineMarkdown.js';
5
3
  export type { InlineNode, MediaKind } from '../utils/inlineMarkdown.js';
6
4
  export { linkKindForUrl, describeUrl } from '../utils/linkPresentation.js';
@@ -11,4 +9,3 @@ export * from './hooks/index.js';
11
9
  export * from '../core/types.js';
12
10
  export { getDisconnectReasonMessage } from '../core/types.js';
13
11
  export { ActionResultAckError, ConvaiClient } from '../core/index.js';
14
- export { RoomAudioRenderer as AudioRenderer, RoomContext as AudioContext } from '@livekit/components-react';
@@ -1,13 +1,8 @@
1
1
  // Main hook (backward compatible)
2
2
  export { useConvaiClient } from './hooks/useConvaiClient.js';
3
- // Components
4
- export { ConvaiWidget } from './components/ConvaiWidget.js';
5
- // Bubble renderer, for a custom chat UI that is not ConvaiWidget. Pass
6
- // `media={false}` on the user's own bubble: previews are a bot-side
7
- // affordance, and rendering them on a line the user typed lets any pasted URL
8
- // pull remote media into the transcript.
9
- export { MarkdownRenderer } from './components/rtc-widget/components/MarkdownRenderer.js';
10
- // The tokenizer behind it, for building a renderer from scratch.
3
+ // No UI ships from the SDK since 2.0: ConvaiWidget, MarkdownRenderer,
4
+ // AudioRenderer and AudioContext are in @convai/web-widget/react.
5
+ // The bubble tokenizer, for building a renderer from scratch.
11
6
  export { parseInlineMarkdown, mediaKindForUrl, isSafeHref, compactUrl } from '../utils/inlineMarkdown.js';
12
7
  export { linkKindForUrl, describeUrl } from '../utils/linkPresentation.js';
13
8
  export { resolveLinkPreviewCached, isCardWorthy, LINK_PREVIEW_TIMEOUT_MS } from '../utils/linkPreview.js';
@@ -19,5 +14,3 @@ export * from '../core/types.js';
19
14
  export { getDisconnectReasonMessage } from '../core/types.js';
20
15
  // Re-export core client for advanced usage
21
16
  export { ActionResultAckError, ConvaiClient } from '../core/index.js';
22
- // Re-export LiveKit components for convenience (backward compatible)
23
- export { RoomAudioRenderer as AudioRenderer, RoomContext as AudioContext } from '@livekit/components-react';
@@ -3,12 +3,14 @@
3
3
  *
4
4
  * Core-service can hand the client bot text with links preserved
5
5
  * (`preserve_links_in_output` on /connect): `[text](url)`, `![alt](url)` and
6
- * bare `http(s)://` URLs arrive verbatim, everything else is still flattened
7
- * server-side. This turns one line of that text into nodes a renderer can
8
- * map onto DOM or JSX.
6
+ * bare `http(s)://` URLs arrive verbatim, other markdown is still flattened
7
+ * server-side. A markdown link keeps its target whatever the scheme. This
8
+ * turns one line of that text into nodes a renderer can map onto DOM or JSX.
9
9
  *
10
- * Only `http:` and `https:` become links or images. Anything else — including
11
- * `javascript:` — stays literal text, regardless of what the server sent.
10
+ * Only the schemes in `SAFE_SCHEMES` (http, https, ftp, ftps, mailto, tel,
11
+ * sms) become links or images. Anything else — including
12
+ * `javascript:` and `data:` — becomes a `blocked` node, regardless of what the
13
+ * server sent.
12
14
  * A link whose closing paren has not streamed in yet is left as text too, so
13
15
  * a bubble does not flicker between shapes mid-response.
14
16
  */
@@ -3,12 +3,14 @@
3
3
  *
4
4
  * Core-service can hand the client bot text with links preserved
5
5
  * (`preserve_links_in_output` on /connect): `[text](url)`, `![alt](url)` and
6
- * bare `http(s)://` URLs arrive verbatim, everything else is still flattened
7
- * server-side. This turns one line of that text into nodes a renderer can
8
- * map onto DOM or JSX.
6
+ * bare `http(s)://` URLs arrive verbatim, other markdown is still flattened
7
+ * server-side. A markdown link keeps its target whatever the scheme. This
8
+ * turns one line of that text into nodes a renderer can map onto DOM or JSX.
9
9
  *
10
- * Only `http:` and `https:` become links or images. Anything else — including
11
- * `javascript:` — stays literal text, regardless of what the server sent.
10
+ * Only the schemes in `SAFE_SCHEMES` (http, https, ftp, ftps, mailto, tel,
11
+ * sms) become links or images. Anything else — including
12
+ * `javascript:` and `data:` — becomes a `blocked` node, regardless of what the
13
+ * server sent.
12
14
  * A link whose closing paren has not streamed in yet is left as text too, so
13
15
  * a bubble does not flicker between shapes mid-response.
14
16
  */
@@ -1,21 +1,12 @@
1
1
  import { EventEmitter } from "../core/EventEmitter.js";
2
- /**
3
- * Adapter that wraps PipecatClient + WebSocketTransport for use in ConvaiClient.
4
- *
5
- * Responsibilities:
6
- * - Manage PipecatClient lifecycle (connect, disconnect)
7
- * - Forward all RTVI events back to MessageHandler by re-encoding them as {type, data} payloads
8
- * - Send outgoing messages via PipecatClient.sendClientMessage (Pipecat wraps to {t, d} envelope)
9
- * - Expose mic control and bot audio track
10
- *
11
- * The caller is responsible for making the HTTP /connect request.
12
- * Pass the parsed response object to connect() — WebSocketTransport extracts
13
- * wsUrl/ws_url automatically.
14
- */
15
2
  export declare class WebSocketSession extends EventEmitter {
16
3
  private _pcClient;
4
+ private readonly _transport;
17
5
  private _isConnected;
18
6
  private readonly _onMessage;
7
+ private _botAudioMuted;
8
+ private _botGain;
9
+ private _player;
19
10
  constructor(onMessage: (payload: Uint8Array) => void, enableMic?: boolean);
20
11
  get isConnected(): boolean;
21
12
  /**
@@ -38,6 +29,21 @@ export declare class WebSocketSession extends EventEmitter {
38
29
  * silence (no speech), and Daily's internal state never changes.
39
30
  */
40
31
  enableMic(enable: boolean): void;
32
+ /**
33
+ * Silence (or restore) the character's audio for the listener. The
34
+ * character keeps speaking; what it says while muted is dropped, not queued.
35
+ */
36
+ setBotAudioMuted(muted: boolean): void;
37
+ /**
38
+ * Pipecat's WebSocket transport plays the character through its own
39
+ * WavStreamPlayer, wiring each new stream straight to the speakers, and
40
+ * exposes no track to mute. Wrap the player's stream start so every stream
41
+ * goes through a GainNode instead. These are Pipecat internals, so each one
42
+ * is feature-checked: if they are missing, mute degrades to a warning rather
43
+ * than breaking playback.
44
+ */
45
+ private _routePlayerThroughGain;
46
+ private _attachGain;
41
47
  getBotAudioTrack(): MediaStreamTrack | null;
42
48
  private _getLocalAudioTrack;
43
49
  private _setupMessageForwarding;
@@ -1,26 +1,17 @@
1
1
  import { PipecatClient, RTVIEvent } from "@pipecat-ai/client-js";
2
2
  import { WebSocketTransport } from "@pipecat-ai/websocket-transport";
3
3
  import { EventEmitter } from "../core/EventEmitter.js";
4
- /**
5
- * Adapter that wraps PipecatClient + WebSocketTransport for use in ConvaiClient.
6
- *
7
- * Responsibilities:
8
- * - Manage PipecatClient lifecycle (connect, disconnect)
9
- * - Forward all RTVI events back to MessageHandler by re-encoding them as {type, data} payloads
10
- * - Send outgoing messages via PipecatClient.sendClientMessage (Pipecat wraps to {t, d} envelope)
11
- * - Expose mic control and bot audio track
12
- *
13
- * The caller is responsible for making the HTTP /connect request.
14
- * Pass the parsed response object to connect() — WebSocketTransport extracts
15
- * wsUrl/ws_url automatically.
16
- */
17
4
  export class WebSocketSession extends EventEmitter {
18
5
  constructor(onMessage, enableMic = true) {
19
6
  super();
20
7
  this._isConnected = false;
8
+ this._botAudioMuted = false;
9
+ this._botGain = null;
10
+ this._player = null;
21
11
  this._onMessage = onMessage;
12
+ this._transport = new WebSocketTransport();
22
13
  this._pcClient = new PipecatClient({
23
- transport: new WebSocketTransport(),
14
+ transport: this._transport,
24
15
  enableMic,
25
16
  enableCam: false,
26
17
  callbacks: {
@@ -38,6 +29,7 @@ export class WebSocketSession extends EventEmitter {
38
29
  },
39
30
  });
40
31
  this._setupMessageForwarding();
32
+ this._routePlayerThroughGain();
41
33
  }
42
34
  get isConnected() {
43
35
  return this._isConnected;
@@ -83,6 +75,58 @@ export class WebSocketSession extends EventEmitter {
83
75
  this._pcClient.enableMic(enable);
84
76
  }
85
77
  }
78
+ /**
79
+ * Silence (or restore) the character's audio for the listener. The
80
+ * character keeps speaking; what it says while muted is dropped, not queued.
81
+ */
82
+ setBotAudioMuted(muted) {
83
+ this._botAudioMuted = muted;
84
+ if (this._botGain)
85
+ this._botGain.gain.value = muted ? 0 : 1;
86
+ }
87
+ /**
88
+ * Pipecat's WebSocket transport plays the character through its own
89
+ * WavStreamPlayer, wiring each new stream straight to the speakers, and
90
+ * exposes no track to mute. Wrap the player's stream start so every stream
91
+ * goes through a GainNode instead. These are Pipecat internals, so each one
92
+ * is feature-checked: if they are missing, mute degrades to a warning rather
93
+ * than breaking playback.
94
+ */
95
+ _routePlayerThroughGain() {
96
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
97
+ const player = this._transport?._mediaManager?._wavStreamPlayer;
98
+ if (!player || typeof player._start !== "function") {
99
+ console.warn("[ConvaiClient] This @pipecat-ai/websocket-transport version exposes no audio player to mute; " +
100
+ "setCharacterMuted() will not silence the character on the WebSocket transport.");
101
+ return;
102
+ }
103
+ this._player = player;
104
+ const start = player._start.bind(player);
105
+ player._start = () => {
106
+ const result = start();
107
+ this._attachGain();
108
+ return result;
109
+ };
110
+ this._attachGain();
111
+ }
112
+ _attachGain() {
113
+ const context = this._player?.context;
114
+ const node = this._player?.stream;
115
+ if (!context || !node)
116
+ return;
117
+ if (!this._botGain || this._botGain.context !== context) {
118
+ this._botGain = context.createGain();
119
+ this._botGain.connect(context.destination);
120
+ }
121
+ this._botGain.gain.value = this._botAudioMuted ? 0 : 1;
122
+ try {
123
+ node.disconnect(context.destination);
124
+ }
125
+ catch {
126
+ // Not connected to the destination (already routed through the gain).
127
+ }
128
+ node.connect(this._botGain);
129
+ }
86
130
  getBotAudioTrack() {
87
131
  return this._pcClient.tracks().bot?.audio ?? null;
88
132
  }
@@ -1,38 +1,27 @@
1
1
  /**
2
2
  * Convai Web SDK - Vanilla JavaScript/TypeScript Export
3
3
  *
4
- * This module provides vanilla JS/TS exports for the Convai SDK.
5
- * Use this for non-React applications.
4
+ * The client and its helpers, for non-React applications. The SDK ships no UI
5
+ * since 2.0: `createConvaiWidget` is in `@convai/web-widget/vanilla`.
6
6
  *
7
7
  * @example
8
8
  * ```typescript
9
- * import { ConvaiClient, createConvaiWidget } from '@convai/web-sdk/vanilla';
9
+ * import { ConvaiClient } from '@convai/web-sdk/vanilla';
10
+ * import { createConvaiWidget } from '@convai/web-widget/vanilla';
10
11
  *
11
- * // Pass config to constructor (same pattern as React's useConvaiClient)
12
12
  * const client = new ConvaiClient({
13
13
  * apiKey: 'your-api-key',
14
14
  * characterId: 'your-character-id',
15
- * enableVideo: true,
16
15
  * });
17
16
  *
18
- * // Create widget - auto-connects on first click
19
- * const widget = createConvaiWidget(document.body, {
20
- * convaiClient: client
21
- * });
22
- *
23
- * // Client has all functions for advanced usage:
24
- * // - client.connect() - manual connection
25
- * // - client.disconnect() - disconnect
26
- * // - client.reconnect() - reconnect
27
- * // - client.sendUserTextMessage() - send messages
28
- * // - client.audioControls, videoControls, etc.
17
+ * // The widget auto-connects on first click.
18
+ * createConvaiWidget(document.body, { convaiClient: client });
29
19
  * ```
30
20
  */
31
21
  export { ActionResultAckError, ConvaiClient } from '../core/ConvaiClient.js';
32
22
  export { CharacterVersionManager, CharacterApiError } from '../core/CharacterVersionManager.js';
33
23
  export { ConvaiRoomError } from '../core/ConvaiRoomError.js';
34
24
  export { AudioRenderer } from './AudioRenderer.js';
35
- export { createConvaiWidget, destroyConvaiWidget } from './ConvaiWidget.js';
36
25
  export * from '../core/types.js';
37
26
  export { parseInlineMarkdown, mediaKindForUrl, isSafeHref, compactUrl } from '../utils/inlineMarkdown.js';
38
27
  export type { InlineNode, MediaKind } from '../utils/inlineMarkdown.js';
@@ -40,4 +29,3 @@ export { linkKindForUrl, describeUrl } from '../utils/linkPresentation.js';
40
29
  export type { LinkKind } from '../utils/linkPresentation.js';
41
30
  export { resolveLinkPreviewCached, isCardWorthy, LINK_PREVIEW_TIMEOUT_MS } from '../utils/linkPreview.js';
42
31
  export type { LinkPreviewMeta, LinkPreviewResolver } from '../utils/linkPreview.js';
43
- export type { VanillaWidget, VanillaWidgetOptions, WidgetPlacement, } from './types.js';
@@ -1,31 +1,21 @@
1
1
  /**
2
2
  * Convai Web SDK - Vanilla JavaScript/TypeScript Export
3
3
  *
4
- * This module provides vanilla JS/TS exports for the Convai SDK.
5
- * Use this for non-React applications.
4
+ * The client and its helpers, for non-React applications. The SDK ships no UI
5
+ * since 2.0: `createConvaiWidget` is in `@convai/web-widget/vanilla`.
6
6
  *
7
7
  * @example
8
8
  * ```typescript
9
- * import { ConvaiClient, createConvaiWidget } from '@convai/web-sdk/vanilla';
9
+ * import { ConvaiClient } from '@convai/web-sdk/vanilla';
10
+ * import { createConvaiWidget } from '@convai/web-widget/vanilla';
10
11
  *
11
- * // Pass config to constructor (same pattern as React's useConvaiClient)
12
12
  * const client = new ConvaiClient({
13
13
  * apiKey: 'your-api-key',
14
14
  * characterId: 'your-character-id',
15
- * enableVideo: true,
16
15
  * });
17
16
  *
18
- * // Create widget - auto-connects on first click
19
- * const widget = createConvaiWidget(document.body, {
20
- * convaiClient: client
21
- * });
22
- *
23
- * // Client has all functions for advanced usage:
24
- * // - client.connect() - manual connection
25
- * // - client.disconnect() - disconnect
26
- * // - client.reconnect() - reconnect
27
- * // - client.sendUserTextMessage() - send messages
28
- * // - client.audioControls, videoControls, etc.
17
+ * // The widget auto-connects on first click.
18
+ * createConvaiWidget(document.body, { convaiClient: client });
29
19
  * ```
30
20
  */
31
21
  // Main client for managing connections
@@ -34,11 +24,9 @@ export { CharacterVersionManager, CharacterApiError } from '../core/CharacterVer
34
24
  export { ConvaiRoomError } from '../core/ConvaiRoomError.js';
35
25
  // AudioRenderer for custom UI builders (handles audio playback)
36
26
  export { AudioRenderer } from './AudioRenderer.js';
37
- // Vanilla widget - complete UI solution
38
- export { createConvaiWidget, destroyConvaiWidget } from './ConvaiWidget.js';
39
27
  // Re-export ALL core types for complete parity with React
40
28
  export * from '../core/types.js';
41
- // Inline markdown tokenizer, for building a chat UI without createConvaiWidget.
29
+ // Inline markdown tokenizer, for building your own chat UI.
42
30
  export { parseInlineMarkdown, mediaKindForUrl, isSafeHref, compactUrl } from '../utils/inlineMarkdown.js';
43
31
  export { linkKindForUrl, describeUrl } from '../utils/linkPresentation.js';
44
32
  export { resolveLinkPreviewCached, isCardWorthy, LINK_PREVIEW_TIMEOUT_MS } from '../utils/linkPreview.js';
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.9.1";
1
+ export declare const SDK_VERSION = "2.0.0-beta.0";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // GENERATED by scripts/sync-version.mjs — do not edit by hand.
2
2
  // Regenerated from package.json on every build.
3
- export const SDK_VERSION = "1.9.1";
3
+ export const SDK_VERSION = "2.0.0-beta.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@convai/web-sdk",
3
- "version": "1.9.1",
3
+ "version": "2.0.0-beta.0",
4
4
  "description": "Build web apps with lifelike AI characters. The Convai Web SDK gives you real-time voice, lipsync, emotions, and dynamic context — with first-class support for React and vanilla TypeScript.",
5
5
  "private": false,
6
6
  "type": "module",
@@ -129,8 +129,7 @@
129
129
  "peerDependencies": {
130
130
  "@pipecat-ai/client-js": "^1.7.0",
131
131
  "@pipecat-ai/websocket-transport": "^1.6.2",
132
- "react": "^18.0.0 || ^19.0.0",
133
- "react-dom": "^18.0.0 || ^19.0.0"
132
+ "react": "^18.0.0 || ^19.0.0"
134
133
  },
135
134
  "peerDependenciesMeta": {
136
135
  "@pipecat-ai/client-js": {
@@ -138,16 +137,17 @@
138
137
  },
139
138
  "@pipecat-ai/websocket-transport": {
140
139
  "optional": true
140
+ },
141
+ "react": {
142
+ "optional": true
141
143
  }
142
144
  },
143
145
  "dependencies": {
144
- "@livekit/components-react": "^2.9.3",
145
- "framer-motion": "^11.18.0",
146
- "livekit-client": ">=2.17.2 <3",
147
- "styled-components": "^6.1.15"
146
+ "livekit-client": ">=2.17.2 <3"
148
147
  },
149
148
  "devDependencies": {
150
149
  "@changesets/cli": "^2.29.5",
150
+ "@convai/web-widget": "0.2.0",
151
151
  "@pipecat-ai/client-js": "^1.7.0",
152
152
  "@pipecat-ai/websocket-transport": "^1.6.2",
153
153
  "@types/node": "^20.17.13",
@@ -155,7 +155,8 @@
155
155
  "@types/react-dom": "^18.3.5",
156
156
  "esbuild": "^0.28.2",
157
157
  "happy-dom": "^15.11.7",
158
- "react-icons": "^5.4.0",
158
+ "react": "^18.3.1",
159
+ "react-dom": "^18.3.1",
159
160
  "rimraf": "^5.0.0",
160
161
  "typescript": "^5.7.3",
161
162
  "vitest": "^3.2.4"