@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
@@ -1,407 +0,0 @@
1
- /**
2
- * Vanilla Styles - Port of React theme system for vanilla implementations
3
- */
4
- // Theme configuration (matching React version)
5
- export const aeroTheme = {
6
- colors: {
7
- primary: {
8
- 50: "#f0f9ff",
9
- 100: "#e0f2fe",
10
- 200: "#bae6fd",
11
- 300: "#7dd3fc",
12
- 400: "#38bdf8",
13
- 500: "#0ea5e9",
14
- 600: "#0284c7",
15
- 700: "#0369a1",
16
- 800: "#075985",
17
- 900: "#0c4a6e",
18
- },
19
- convai: {
20
- light: "#1EB453",
21
- medium: "#0b6049",
22
- dark: "#084c3a",
23
- },
24
- neutral: {
25
- 50: "#fafafa",
26
- 100: "#f5f5f5",
27
- 200: "#e5e5e5",
28
- 300: "#d4d4d4",
29
- 400: "#a3a3a3",
30
- 500: "#737373",
31
- 600: "#525252",
32
- 700: "#404040",
33
- 800: "#262626",
34
- 900: "#171717",
35
- },
36
- glass: {
37
- light: "rgba(255, 255, 255, 0.1)",
38
- medium: "rgba(255, 255, 255, 0.15)",
39
- dark: "rgba(0, 0, 0, 0.1)",
40
- backdrop: "rgba(255, 255, 255, 0.8)",
41
- card: "rgba(255, 255, 255, 0.9)",
42
- backdropLight: "blur(20px)",
43
- borderLight: "1px solid rgba(255, 255, 255, 0.2)",
44
- },
45
- accent: {
46
- purple: "#8b5cf6",
47
- green: "#10b981",
48
- blue: "#3b82f6",
49
- orange: "#f59e0b",
50
- red: "#ef4444",
51
- },
52
- error: {
53
- 50: "#fef2f2",
54
- 100: "#fee2e2",
55
- 200: "#fecaca",
56
- 300: "#fca5a5",
57
- 400: "#f87171",
58
- 500: "#ef4444",
59
- 600: "#dc2626",
60
- 700: "#b91c1c",
61
- 800: "#991b1b",
62
- 900: "#7f1d1d",
63
- },
64
- text: {
65
- primary: "#1f2937",
66
- secondary: "#6b7280",
67
- tertiary: "#9ca3af",
68
- inverse: "#ffffff",
69
- },
70
- },
71
- typography: {
72
- fontFamily: {
73
- primary: '"Noto Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
74
- body: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
75
- mono: 'SF Mono, Monaco, "Cascadia Code", "Roboto Mono", Consolas, "Courier New", monospace',
76
- },
77
- fontSize: {
78
- xs: "12px",
79
- sm: "14px",
80
- base: "16px",
81
- lg: "18px",
82
- xl: "20px",
83
- "2xl": "24px",
84
- "3xl": "30px",
85
- "4xl": "36px",
86
- },
87
- fontWeight: {
88
- normal: 400,
89
- medium: 500,
90
- semibold: 600,
91
- bold: 700,
92
- },
93
- },
94
- spacing: {
95
- xs: "4px",
96
- sm: "8px",
97
- md: "16px",
98
- lg: "24px",
99
- xl: "32px",
100
- "2xl": "48px",
101
- "3xl": "64px",
102
- },
103
- borderRadius: {
104
- none: "0",
105
- sm: "4px",
106
- md: "8px",
107
- lg: "12px",
108
- xl: "16px",
109
- "2xl": "24px",
110
- full: "9999px",
111
- },
112
- shadows: {
113
- sm: "0 1px 2px 0 rgba(0, 0, 0, 0.05)",
114
- md: "0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)",
115
- lg: "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",
116
- xl: "0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)",
117
- glass: "0 8px 32px rgba(0, 0, 0, 0.1)",
118
- },
119
- glass: {
120
- backdrop: "blur(20px)",
121
- backdropLight: "blur(10px)",
122
- backdropHeavy: "blur(40px)",
123
- border: "1px solid rgba(255, 255, 255, 0.2)",
124
- borderLight: "1px solid rgba(255, 255, 255, 0.1)",
125
- },
126
- transitions: {
127
- fast: "0.15s ease-in-out",
128
- normal: "0.2s ease-in-out",
129
- slow: "0.3s ease-in-out",
130
- spring: "0.4s cubic-bezier(0.4, 0, 0.2, 1)",
131
- snappy: "all 0.1s ease-out",
132
- },
133
- zIndex: {
134
- base: 1,
135
- dropdown: 1000,
136
- sticky: 1020,
137
- fixed: 1030,
138
- modal: 1040,
139
- popover: 1050,
140
- tooltip: 1060,
141
- },
142
- };
143
- /**
144
- * Global CSS styles for the Convai widget
145
- * This should be injected once into the document head
146
- */
147
- export const getGlobalStyles = () => `
148
- @keyframes convai-pulse {
149
- 0%, 100% {
150
- opacity: 1;
151
- }
152
- 50% {
153
- opacity: 0.5;
154
- }
155
- }
156
-
157
- @keyframes convai-spin {
158
- from {
159
- transform: rotate(0deg);
160
- }
161
- to {
162
- transform: rotate(360deg);
163
- }
164
- }
165
-
166
- @keyframes convai-bounce {
167
- 0%, 100% {
168
- transform: translateY(0);
169
- }
170
- 50% {
171
- transform: translateY(-10px);
172
- }
173
- }
174
-
175
- @keyframes convai-slide-up {
176
- from {
177
- transform: translateY(20px);
178
- opacity: 0;
179
- }
180
- to {
181
- transform: translateY(0);
182
- opacity: 1;
183
- }
184
- }
185
-
186
- @keyframes convai-slide-down {
187
- from {
188
- transform: translateY(-20px);
189
- opacity: 0;
190
- }
191
- to {
192
- transform: translateY(0);
193
- opacity: 1;
194
- }
195
- }
196
-
197
- @keyframes convai-fade-in {
198
- from {
199
- opacity: 0;
200
- }
201
- to {
202
- opacity: 1;
203
- }
204
- }
205
-
206
- @keyframes convai-scale-in {
207
- from {
208
- transform: scale(0.8);
209
- opacity: 0;
210
- }
211
- to {
212
- transform: scale(1);
213
- opacity: 1;
214
- }
215
- }
216
-
217
- .convai-widget * {
218
- box-sizing: border-box;
219
- }
220
-
221
- .convai-widget {
222
- font-family: var(--convai-font, ${aeroTheme.typography.fontFamily.primary});
223
- color: var(--convai-panel-fg, ${aeroTheme.colors.text.primary});
224
- -webkit-font-smoothing: antialiased;
225
- -moz-osx-font-smoothing: grayscale;
226
- }
227
-
228
- .convai-widget button {
229
- font-family: inherit;
230
- cursor: pointer;
231
- border: none;
232
- outline: none;
233
- background: none;
234
- padding: 0;
235
- margin: 0;
236
- }
237
-
238
- .convai-widget input {
239
- font-family: inherit;
240
- border: none;
241
- outline: none;
242
- background: none;
243
- }
244
-
245
- .convai-widget::-webkit-scrollbar {
246
- width: 6px;
247
- }
248
-
249
- .convai-widget::-webkit-scrollbar-track {
250
- background: rgba(0, 0, 0, 0.05);
251
- border-radius: 3px;
252
- }
253
-
254
- .convai-widget::-webkit-scrollbar-thumb {
255
- background: rgba(0, 0, 0, 0.2);
256
- border-radius: 3px;
257
- }
258
-
259
- .convai-widget::-webkit-scrollbar-thumb:hover {
260
- background: rgba(0, 0, 0, 0.3);
261
- }
262
- `;
263
- /** Ids of the injected <style> nodes. Public in effect: hosts and a second
264
- * copy of the SDK on the same page both key off them. */
265
- const WIDGET_STYLES_ID = 'convai-widget-styles';
266
- const WIDGET_KEYFRAMES_ID = 'convai-widget-keyframes';
267
- /** Targets that already hold the widget stylesheet. Per-target, so multiple
268
- * widget instances and shadow roots each get their own copy. */
269
- const styledTargets = new WeakSet();
270
- /** Targets that already hold the widget's `@keyframes`. */
271
- const keyframedTargets = new WeakSet();
272
- /** Where a <style> node should be appended for a given target. */
273
- const styleHost = (target) => target instanceof ShadowRoot ? target : target.head;
274
- /**
275
- * True when `target` already holds a <style> with this id.
276
- *
277
- * The WeakSets above dedup within one module instance. This is the
278
- * cross-bundle guard: two copies of the SDK on one page (an app bundling it
279
- * and an embed script loading its own) each get their own WeakSet, so without
280
- * an existence check they would both append a <style> carrying the same id.
281
- * Inert, but the pre-refactor inline code checked for this and it should not
282
- * regress.
283
- */
284
- const hasStyleNode = (target, id) => styleHost(target).querySelector(`#${id}`) !== null;
285
- const WIDGET_KEYFRAMES = `
286
- @keyframes popIn {
287
- from { opacity: 0; transform: scale(0.95) translateY(-10px); }
288
- to { opacity: 1; transform: scale(1) translateY(0); }
289
- }
290
-
291
- /* Link-preview skeleton: one sweep across the placeholder while the media
292
- * decodes. Lives here rather than in getGlobalStyles() because that string is
293
- * pinned byte-for-byte by the inline-style parity fixture, and this is an
294
- * addition no existing element uses. */
295
- @keyframes convai-preview-shimmer {
296
- from { background-position: 200% 0; }
297
- to { background-position: -200% 0; }
298
- }
299
-
300
- /* Image lightbox entrance. Additive, like the shimmer above. */
301
- @keyframes convai-lightbox-in {
302
- from { opacity: 0; transform: scale(.98); }
303
- to { opacity: 1; transform: scale(1); }
304
- }
305
-
306
- /* Connecting overlay: logo spin + label pulse. Values match the React
307
- * widget's framer-motion transitions (ConvaiWidget.tsx:681-737) exactly --
308
- * a full turn every 2s linear, and opacity 0.5 -> 1 -> 0.5 every 2s
309
- * ease-in-out. React does not honour prefers-reduced-motion; vanilla does,
310
- * via the media query below, since a full-turn infinite spin plus a
311
- * pulsing label is exactly what that setting exists for. */
312
- @keyframes convaiConnectingSpin {
313
- from { transform: rotate(0deg); }
314
- to { transform: rotate(360deg); }
315
- }
316
-
317
- @keyframes convaiConnectingPulse {
318
- 0%, 100% { opacity: 0.5; }
319
- 50% { opacity: 1; }
320
- }
321
-
322
- /* Voice mode's avatar: two counter-rotating liquid-gradient layers behind
323
- * the character image. Matches the React overlay's framer-motion values
324
- * (VoiceModeOverlay.tsx) — 20s clockwise for the conic layer, 15s
325
- * anticlockwise for the radial one, both linear and infinite — and the
326
- * gentle scale breathing it applies while the character is speaking. */
327
- @keyframes convaiVoiceSpin {
328
- from { transform: rotate(0deg); }
329
- to { transform: rotate(360deg); }
330
- }
331
-
332
- @keyframes convaiVoiceSpinReverse {
333
- from { transform: rotate(360deg); }
334
- to { transform: rotate(0deg); }
335
- }
336
-
337
- @keyframes convaiVoiceBreathe {
338
- 0%, 100% { transform: scale(1); }
339
- 50% { transform: scale(1.05); }
340
- }
341
-
342
- @media (prefers-reduced-motion: reduce) {
343
- .convai-connecting-spin {
344
- animation: none !important;
345
- }
346
- .convai-connecting-pulse {
347
- animation: none !important;
348
- }
349
- .convai-voice-gradient,
350
- .convai-voice-avatar {
351
- animation: none !important;
352
- }
353
- [data-convai-skeleton] {
354
- animation: none !important;
355
- }
356
- [part~="lightbox-backdrop"] {
357
- animation: none !important;
358
- }
359
- }
360
- `;
361
- /**
362
- * Inject the widget's global styles into a document or a shadow root.
363
- * Defaults to the document, so existing callers are unaffected.
364
- */
365
- export const injectGlobalStyles = (target = document) => {
366
- if (styledTargets.has(target))
367
- return;
368
- if (hasStyleNode(target, WIDGET_STYLES_ID)) {
369
- styledTargets.add(target);
370
- return;
371
- }
372
- const styleElement = document.createElement('style');
373
- styleElement.id = WIDGET_STYLES_ID;
374
- styleElement.textContent = getGlobalStyles();
375
- styleHost(target).appendChild(styleElement);
376
- styledTargets.add(target);
377
- };
378
- /**
379
- * Inject the widget's `@keyframes` (e.g. the settings tray's `popIn`)
380
- * into a document or a shadow root. `@keyframes` defined in the document
381
- * do not resolve for shadow content, so they must be injected into each
382
- * shadow root that uses them.
383
- */
384
- export const injectKeyframes = (target = document) => {
385
- if (keyframedTargets.has(target))
386
- return;
387
- if (hasStyleNode(target, WIDGET_KEYFRAMES_ID)) {
388
- keyframedTargets.add(target);
389
- return;
390
- }
391
- const style = document.createElement('style');
392
- style.id = WIDGET_KEYFRAMES_ID;
393
- style.textContent = WIDGET_KEYFRAMES;
394
- styleHost(target).appendChild(style);
395
- keyframedTargets.add(target);
396
- };
397
- /**
398
- * Helper to create inline styles object from theme
399
- */
400
- export const createStyles = (styles) => {
401
- return Object.entries(styles)
402
- .map(([key, value]) => {
403
- const cssKey = key.replace(/([A-Z])/g, '-$1').toLowerCase();
404
- return `${cssKey}: ${value}`;
405
- })
406
- .join('; ');
407
- };
@@ -1,170 +0,0 @@
1
- import type { IConvaiClient, ChatMessage, PublishedChatConnectOptions } from '../core/types.js';
2
- import type { PublishedChatDescriptor } from '../embed/publicationApi.js';
3
- import type { LinkPreviewResolver } from "../utils/linkPreview.js";
4
- /** Where the widget anchors itself. `inline` renders it in normal document flow. */
5
- export type WidgetPlacement = 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left' | 'inline';
6
- /**
7
- * Options for creating a vanilla ConvaiWidget
8
- *
9
- * You can either:
10
- * 1. Pass an existing convaiClient instance, OR
11
- * 2. Pass connection config (apiKey, characterId, etc.) directly
12
- */
13
- export interface VanillaWidgetOptions {
14
- /**
15
- * Option 1: Pass an existing Convai client instance.
16
- * Should be initialized with config: new ConvaiClient({ apiKey, characterId, ... })
17
- * The widget will auto-connect on first click.
18
- */
19
- convaiClient?: IConvaiClient & {
20
- activity?: string;
21
- chatMessages: ChatMessage[];
22
- /**
23
- * Present on the real `ConvaiClient` (it extends `EventEmitter`) and on
24
- * the test stubs; absent only if a caller hand-rolls a minimal
25
- * `IConvaiClient`. Optional so that case still type-checks -- the widget
26
- * calls it defensively (`client.emit?.(...)`) to surface mic-permission
27
- * failures on the same `error` channel `ConvaiClient` already uses.
28
- */
29
- emit?: (event: string, ...args: any[]) => void;
30
- };
31
- /** Option 2: Pass connection config directly (convenience shortcut). Either apiKey or authToken is required. */
32
- apiKey?: string;
33
- /** Auth token for realtime API (alternative to apiKey). See https://realtime-api.convai.com/docs */
34
- authToken?: string;
35
- characterId?: string;
36
- enableVideo?: boolean;
37
- startWithVideoOn?: boolean;
38
- /** Enable lipsync/facial animation blendshapes (default: false) */
39
- enableLipsync?: boolean;
40
- /** Enable emotion detection and bot-emotion updates (default: false) */
41
- enableEmotion?: boolean;
42
- /** Log incoming and outgoing decoded RTVI data messages to the browser console (default: true) */
43
- logRtviMessages?: boolean;
44
- /** Blendshape configuration for facial animation format */
45
- blendshapeConfig?: {
46
- /** Format of blendshapes: "arkit" or "mha" (Meta Human Animation, default: "mha") */
47
- format?: "arkit" | "mha";
48
- /** Custom mapper function to transform incoming blendshapes */
49
- customMapper?: (input: number[] | Float32Array) => Float32Array;
50
- /** Indexed NeuroSync ahead-delivery. Defaults to true; set false for the legacy paced path. */
51
- deliver_chunks_ahead?: boolean;
52
- /** Ahead-delivery timeline FPS override; ignored when deliver_chunks_ahead is false. */
53
- output_fps?: number;
54
- /** Seconds the server buffers blendshapes before releasing them. */
55
- frames_buffer_duration?: number;
56
- };
57
- /**
58
- * Show video toggle button in settings (default: true).
59
- * Only works if connection type is "video". If false, hides the video button.
60
- */
61
- showVideo?: boolean;
62
- /**
63
- * Show screen share toggle button in settings (default: true).
64
- * Only works if connection type is "video". If false, hides the screen share button.
65
- */
66
- showScreenShare?: boolean;
67
- /**
68
- * Start in voice mode by default when widget opens (default: true).
69
- * When true, the widget will open directly in voice mode with microphone enabled.
70
- */
71
- defaultVoiceMode?: boolean;
72
- /**
73
- * Open Graph lookup for plain web links the character sends. Supply a
74
- * function that asks your backend for a page's metadata and each such link
75
- * gets a site card (favicon, site name, title, description, image) once it
76
- * resolves. Omit it and links render as before. See
77
- * docs/convai_link_previews.md, "Site cards".
78
- */
79
- linkPreviewResolver?: LinkPreviewResolver;
80
- /** Mint a fresh single-use grant when a published-chat session is reopened. */
81
- requestPublicationGrant?: () => Promise<string>;
82
- /** Core endpoint override used with requestPublicationGrant. */
83
- publishedChatConnectOptions?: PublishedChatConnectOptions;
84
- /** Public descriptor used to label a credential-free published session. */
85
- publishedChatDescriptor?: Pick<PublishedChatDescriptor, 'display_name' | 'image_url'>;
86
- /**
87
- * Where the widget's `<style>` and `@keyframes` nodes are injected.
88
- *
89
- * Omit it and the target is derived from `container.getRootNode()` at
90
- * construction time — correct only when the container is *already* inside
91
- * its final root. A custom element that builds its subtree first and appends
92
- * it to its shadow root afterwards (the usual pattern) constructs the widget
93
- * while the container is still detached, so the derivation sees the
94
- * document and the shadow root never receives the stylesheet or the `popIn`
95
- * keyframes — silently, with no error. Pass the shadow root here in that
96
- * case; when supplied it is used verbatim and no derivation happens.
97
- */
98
- styleTarget?: Document | ShadowRoot;
99
- /** Corner to anchor to, or `inline` for normal flow. Default `bottom-right`. */
100
- placement?: WidgetPlacement;
101
- /** Optional callbacks */
102
- onConnect?: () => void;
103
- onDisconnect?: () => void;
104
- onMessage?: (message: ChatMessage) => void;
105
- }
106
- /**
107
- * Vanilla ConvaiWidget instance with cleanup method
108
- */
109
- export interface VanillaWidget {
110
- /** Root DOM element of the widget */
111
- element: HTMLElement;
112
- /** Cleanup and destroy the widget */
113
- destroy: () => void;
114
- /** The Convai client instance */
115
- client: IConvaiClient & {
116
- activity?: string;
117
- chatMessages: ChatMessage[];
118
- emit?: (event: string, ...args: any[]) => void;
119
- };
120
- /** Update widget state (for future extensions) */
121
- update?: (options: Partial<VanillaWidgetOptions>) => void;
122
- /**
123
- * Open the panel. Drives the same internal open path as the launcher
124
- * click (connect-on-first-open, then the morph to the panel). Idempotent:
125
- * calling `open()` while already open — or while a first open is still
126
- * waiting on `connect()` — is a no-op. It will not re-run the morph
127
- * animation, and it will not start a second connect.
128
- */
129
- open: () => void;
130
- /**
131
- * Close the panel. Drives the same internal path as the header's close
132
- * button. Idempotent: calling `close()` while already closed is a no-op.
133
- *
134
- * Called while a first open is still connecting, it *cancels* that open:
135
- * the connect completes (the client ends up connected) but the panel stays
136
- * collapsed rather than popping open once the promise resolves.
137
- */
138
- close: () => void;
139
- /**
140
- * Toggle the panel open or closed, per the current {@link isOpen} state.
141
- * Mid-connect this closes — i.e. a second click cancels the open in flight,
142
- * rather than queueing a second one.
143
- */
144
- toggle: () => void;
145
- /**
146
- * Whether the panel is open, or is opening. This is *requested* state, and
147
- * it updates synchronously: `widget.open(); widget.isOpen` is always `true`,
148
- * including on a cold client where the panel is only committed once
149
- * `connect()` resolves seconds later. Cancelling that open (via `close()`,
150
- * `toggle()`, or a second launcher click) returns it to `false`
151
- * immediately.
152
- *
153
- * The distinction matters only for the first open on a disconnected client;
154
- * every other transition is synchronous, so rendered and requested state
155
- * coincide. Consumers reconciling their own open/close events against this
156
- * flag get the answer that matches the user's last instruction, not the
157
- * animation frame.
158
- */
159
- readonly isOpen: boolean;
160
- /**
161
- * Insert a message into the transcript locally, without sending it to the
162
- * character. Use this for client-side lines — e.g. a greeting — that must
163
- * appear in the chat but must never reach the LLM and must never be billed
164
- * as a turn. This is not `sendUserTextMessage`: nothing is transmitted.
165
- */
166
- appendMessage: (message: {
167
- sender: "user" | "bot";
168
- content: string;
169
- }) => void;
170
- }
@@ -1 +0,0 @@
1
- export {};