@trillet-ai/web-sdk 1.7.1 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -0
- package/dist/TranscriptManager-Bh-JJm_m.d.ts +15 -0
- package/dist/chunk-3MH6DJZ6.js +46 -0
- package/dist/chunk-3MH6DJZ6.js.map +1 -0
- package/dist/chunk-FSJ42TKR.js +718 -0
- package/dist/chunk-FSJ42TKR.js.map +1 -0
- package/dist/index.d.ts +101 -5
- package/dist/index.js +9 -347
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +43 -0
- package/dist/server.js +7 -0
- package/dist/server.js.map +1 -0
- package/dist/widget/index.d.ts +266 -0
- package/dist/widget/index.js +1513 -0
- package/dist/widget/index.js.map +1 -0
- package/dist/widget.umd.js +3831 -0
- package/dist/widget.umd.js.map +1 -0
- package/package.json +24 -3
- package/dist/BrowserFingerprint.d.ts +0 -46
- package/dist/BrowserFingerprint.js +0 -131
- package/dist/TranscriptManager.d.ts +0 -35
- package/dist/TranscriptManager.js +0 -63
- package/dist/TrilletWebSDK.d.ts +0 -38
- package/dist/TrilletWebSDK.js +0 -238
package/dist/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { TrilletRoomDetails } from '../server.js';
|
|
3
|
+
import { T as Transcript } from '../TranscriptManager-Bh-JJm_m.js';
|
|
4
|
+
|
|
5
|
+
type WidgetVariant = 'compact' | 'expanded';
|
|
6
|
+
type WidgetVariantInput = WidgetVariant | 'tiny' | 'full';
|
|
7
|
+
type WidgetMode = 'voice' | 'text' | 'both';
|
|
8
|
+
type WidgetPlacement = 'top-left' | 'top' | 'top-right' | 'bottom-left' | 'bottom' | 'bottom-right';
|
|
9
|
+
interface WidgetBrand {
|
|
10
|
+
logo?: string;
|
|
11
|
+
primaryColor?: string;
|
|
12
|
+
name?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Resolved, typed widget configuration. The custom element builds this from HTML
|
|
16
|
+
* attributes; the React wrapper builds it from props.
|
|
17
|
+
*/
|
|
18
|
+
interface WidgetConfig {
|
|
19
|
+
agentId: string;
|
|
20
|
+
signedUrlEndpoint?: string;
|
|
21
|
+
workspaceId?: string;
|
|
22
|
+
agentName?: string;
|
|
23
|
+
callFlowName?: string;
|
|
24
|
+
workspaceName?: string;
|
|
25
|
+
avatar?: string;
|
|
26
|
+
/** Legacy single accent/orb color; alias of orbColor1. */
|
|
27
|
+
orbColor?: string;
|
|
28
|
+
/** Gradient orb color 1 (convai `avatar-orb-color-1`). */
|
|
29
|
+
orbColor1?: string;
|
|
30
|
+
/** Gradient orb color 2 (convai `avatar-orb-color-2`). */
|
|
31
|
+
orbColor2?: string;
|
|
32
|
+
variant: WidgetVariant;
|
|
33
|
+
placement: WidgetPlacement;
|
|
34
|
+
dismissible: boolean;
|
|
35
|
+
actionText?: string;
|
|
36
|
+
startCallText: string;
|
|
37
|
+
endCallText: string;
|
|
38
|
+
messageText: string;
|
|
39
|
+
switchToTextText: string;
|
|
40
|
+
switchToVoiceText: string;
|
|
41
|
+
listeningText: string;
|
|
42
|
+
speakingText: string;
|
|
43
|
+
expandText: string;
|
|
44
|
+
collapseText: string;
|
|
45
|
+
recaptchaText: string;
|
|
46
|
+
mode: WidgetMode;
|
|
47
|
+
variables?: Record<string, unknown>;
|
|
48
|
+
maxCallDuration?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Optional Google reCAPTCHA v2 site key. When set, the widget renders a checkbox the
|
|
51
|
+
* visitor solves once per session before the first conversation starts.
|
|
52
|
+
*
|
|
53
|
+
* BYO and client-only: the solved token is never sent to Trillet and never verified,
|
|
54
|
+
* so this is UI friction, not bot protection. See ./recaptcha.ts. For a real gate,
|
|
55
|
+
* use the core SDK's `onBeforeCall` hook and verify on your own backend.
|
|
56
|
+
*/
|
|
57
|
+
recaptchaSiteKey?: string;
|
|
58
|
+
/** convai `disable-banner` — accepted no-op (we're blank by default). */
|
|
59
|
+
disableBanner: boolean;
|
|
60
|
+
brand: WidgetBrand;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface TrilletWidgetProps {
|
|
64
|
+
agentId: string;
|
|
65
|
+
signedUrlEndpoint?: string;
|
|
66
|
+
/** JS-only: invoked at call-start to mint room details (cannot be an HTML attribute). */
|
|
67
|
+
getRoomDetails?: () => Promise<TrilletRoomDetails> | TrilletRoomDetails;
|
|
68
|
+
/** JS-only: static pre-minted room details. */
|
|
69
|
+
roomDetails?: TrilletRoomDetails;
|
|
70
|
+
workspaceId?: string;
|
|
71
|
+
agentName?: string;
|
|
72
|
+
callFlowName?: string;
|
|
73
|
+
workspaceName?: string;
|
|
74
|
+
avatar?: string;
|
|
75
|
+
/** convai alias of `avatar`. */
|
|
76
|
+
avatarImageUrl?: string;
|
|
77
|
+
/** Legacy single accent/orb color; alias of orbColor1. */
|
|
78
|
+
orbColor?: string;
|
|
79
|
+
/** Gradient orb color 1 (convai `avatar-orb-color-1`). */
|
|
80
|
+
orbColor1?: string;
|
|
81
|
+
/** Gradient orb color 2 (convai `avatar-orb-color-2`). */
|
|
82
|
+
orbColor2?: string;
|
|
83
|
+
/** Accepts both our `compact|expanded` and convai's `tiny|compact|full`. */
|
|
84
|
+
variant?: WidgetVariantInput;
|
|
85
|
+
placement?: WidgetPlacement;
|
|
86
|
+
dismissible?: boolean;
|
|
87
|
+
actionText?: string;
|
|
88
|
+
startCallText?: string;
|
|
89
|
+
endCallText?: string;
|
|
90
|
+
/** Label for the text/chat entry point in mode="both" (default "Message"). */
|
|
91
|
+
messageText?: string;
|
|
92
|
+
switchToTextText?: string;
|
|
93
|
+
switchToVoiceText?: string;
|
|
94
|
+
listeningText?: string;
|
|
95
|
+
speakingText?: string;
|
|
96
|
+
expandText?: string;
|
|
97
|
+
collapseText?: string;
|
|
98
|
+
/** Copy shown above the reCAPTCHA checkbox, when `recaptchaSiteKey` is set. */
|
|
99
|
+
recaptchaText?: string;
|
|
100
|
+
/** "voice" | "text" | "both" (multimodal, user-switchable). */
|
|
101
|
+
mode?: WidgetMode;
|
|
102
|
+
variables?: Record<string, unknown>;
|
|
103
|
+
/** convai alias of `variables`. */
|
|
104
|
+
dynamicVariables?: Record<string, unknown>;
|
|
105
|
+
maxCallDuration?: number;
|
|
106
|
+
/**
|
|
107
|
+
* Google reCAPTCHA v2 site key. Renders a checkbox the visitor solves once per
|
|
108
|
+
* session before the first conversation. BYO and client-only — the token is never
|
|
109
|
+
* sent to Trillet nor verified, so it is UI friction, not bot protection.
|
|
110
|
+
*/
|
|
111
|
+
recaptchaSiteKey?: string;
|
|
112
|
+
/** convai `disable-banner` — accepted no-op (blank by default). */
|
|
113
|
+
disableBanner?: boolean;
|
|
114
|
+
brand?: WidgetBrand;
|
|
115
|
+
/** Primary. Fires alongside onCallStart. */
|
|
116
|
+
onConversationStart?: () => void;
|
|
117
|
+
/** Primary. Fires alongside onCallEnd. */
|
|
118
|
+
onConversationEnd?: (durationSeconds: number) => void;
|
|
119
|
+
/** @deprecated Use onConversationStart. Still fired for back-compat. */
|
|
120
|
+
onCallStart?: () => void;
|
|
121
|
+
/** @deprecated Use onConversationEnd. Still fired for back-compat. */
|
|
122
|
+
onCallEnd?: (durationSeconds: number) => void;
|
|
123
|
+
onError?: (error: Error) => void;
|
|
124
|
+
onTranscript?: (transcripts: Transcript[]) => void;
|
|
125
|
+
className?: string;
|
|
126
|
+
style?: React.CSSProperties;
|
|
127
|
+
}
|
|
128
|
+
declare const TrilletWidget: React.FC<TrilletWidgetProps>;
|
|
129
|
+
|
|
130
|
+
type ActiveMode = 'voice' | 'text';
|
|
131
|
+
declare class TrilletWidgetElement extends HTMLElement {
|
|
132
|
+
static get observedAttributes(): readonly string[];
|
|
133
|
+
private root;
|
|
134
|
+
private config;
|
|
135
|
+
private agent;
|
|
136
|
+
private state;
|
|
137
|
+
private open;
|
|
138
|
+
private micEnabled;
|
|
139
|
+
private speaking;
|
|
140
|
+
private transcripts;
|
|
141
|
+
private display;
|
|
142
|
+
private activeMode;
|
|
143
|
+
private switching;
|
|
144
|
+
getRoomDetails?: () => Promise<TrilletRoomDetails> | TrilletRoomDetails;
|
|
145
|
+
roomDetails?: TrilletRoomDetails;
|
|
146
|
+
private durationTimer;
|
|
147
|
+
private remainingSeconds;
|
|
148
|
+
private elapsedSeconds;
|
|
149
|
+
private recaptchaSolved;
|
|
150
|
+
private recaptchaSlot;
|
|
151
|
+
private recaptchaWidgetId;
|
|
152
|
+
private styleEl;
|
|
153
|
+
private container;
|
|
154
|
+
constructor();
|
|
155
|
+
connectedCallback(): void;
|
|
156
|
+
disconnectedCallback(): void;
|
|
157
|
+
attributeChangedCallback(): void;
|
|
158
|
+
/**
|
|
159
|
+
* Imperatively start a conversation. Primary headless API (convai-aligned).
|
|
160
|
+
* @param modality - optional; only used in `mode="both"` to pick voice vs text.
|
|
161
|
+
*/
|
|
162
|
+
startConversation(modality?: ActiveMode): Promise<void>;
|
|
163
|
+
/** Imperatively end the active conversation. Primary headless API. */
|
|
164
|
+
endConversation(): void;
|
|
165
|
+
/** @deprecated Use {@link startConversation}. Kept as a thin alias for back-compat. */
|
|
166
|
+
startCall(): Promise<void>;
|
|
167
|
+
/** @deprecated Use {@link endConversation}. Kept as a thin alias for back-compat. */
|
|
168
|
+
endCall(): void;
|
|
169
|
+
/** The concrete modality to run for the current session (`both` -> activeMode). */
|
|
170
|
+
private resolvedMode;
|
|
171
|
+
/** Keep activeMode consistent with the configured mode. */
|
|
172
|
+
private syncActiveMode;
|
|
173
|
+
/** Tear down the current agent cleanly: detach listeners, end the call, drop the ref. */
|
|
174
|
+
private teardownAgent;
|
|
175
|
+
/**
|
|
176
|
+
* Switch modality mid-session (mode="both"). Because the core binds `mode` at
|
|
177
|
+
* construction, this ends the current `TrilletAgent` and constructs a fresh one in
|
|
178
|
+
* the other modality, rejoining via the same credential path. Transcripts and the
|
|
179
|
+
* duration timer are preserved across the switch; no lifecycle events fire (it's one
|
|
180
|
+
* conversation from the consumer's perspective).
|
|
181
|
+
*/
|
|
182
|
+
private switchModality;
|
|
183
|
+
private beginCall;
|
|
184
|
+
private wireAgentEvents;
|
|
185
|
+
private endLocalCall;
|
|
186
|
+
private handleError;
|
|
187
|
+
private startDurationTimer;
|
|
188
|
+
private clearDurationTimer;
|
|
189
|
+
private setState;
|
|
190
|
+
private dispatch;
|
|
191
|
+
private applyTheme;
|
|
192
|
+
private formatTime;
|
|
193
|
+
private statusText;
|
|
194
|
+
private renderStatus;
|
|
195
|
+
private timerText;
|
|
196
|
+
private render;
|
|
197
|
+
private renderLauncher;
|
|
198
|
+
private renderPanel;
|
|
199
|
+
/**
|
|
200
|
+
* The header title identifying who the user is talking to. Each identity value is
|
|
201
|
+
* code-overridable per value: a static `agent-name`/`call-flow-name`/`workspace-name`
|
|
202
|
+
* config value takes precedence over the corresponding backend `display.*` value
|
|
203
|
+
* (which only arrives on `connected`), falling back to it when unset. Resolution:
|
|
204
|
+
* effectiveAgent = config.agentName ?? display.agent_name
|
|
205
|
+
* effectiveCallFlow = config.callFlowName ?? display.call_flow_name
|
|
206
|
+
* effectiveWorkspace = config.workspaceName ?? display.workspace_name
|
|
207
|
+
* title = effectiveAgent || effectiveCallFlow || effectiveWorkspace || ''
|
|
208
|
+
* Because the overrides are static config, the title can render pre-call. Note:
|
|
209
|
+
* `brand.name` is intentionally NOT part of this chain — it renders in the brand
|
|
210
|
+
* slot only.
|
|
211
|
+
*/
|
|
212
|
+
private headerTitle;
|
|
213
|
+
private renderHeader;
|
|
214
|
+
/** True when a `both` widget is idle/ended with no modality chosen yet. */
|
|
215
|
+
private isBothPreCall;
|
|
216
|
+
/** True when a site key is configured and this session has not solved it yet. */
|
|
217
|
+
private needsRecaptcha;
|
|
218
|
+
/**
|
|
219
|
+
* The pre-call gate shown in the panel: orb, prompt, the reCAPTCHA checkbox, and a
|
|
220
|
+
* disabled start button. The button enables once the checkbox is solved.
|
|
221
|
+
*
|
|
222
|
+
* The checkbox itself is projected in via a <slot>: reCAPTCHA v2 hangs inside a
|
|
223
|
+
* shadow root (its anchor iframe never finishes initializing), so the actual widget
|
|
224
|
+
* is rendered into a LIGHT-DOM node — a child of the host element — that is assigned
|
|
225
|
+
* to this slot. It therefore *displays* here inside the panel while its DOM home
|
|
226
|
+
* stays in the light tree, where reCAPTCHA works. Verified via examples/recaptcha-
|
|
227
|
+
* isolate.local.html (case C).
|
|
228
|
+
*/
|
|
229
|
+
private renderRecaptchaGate;
|
|
230
|
+
/**
|
|
231
|
+
* Create the light-DOM node that hosts the reCAPTCHA checkbox and render the checkbox
|
|
232
|
+
* into it. The node is a child of the host element with `slot="recaptcha"`, so it is
|
|
233
|
+
* projected into the gate's <slot>. Idempotent: every widget re-render recreates the
|
|
234
|
+
* <slot> element, but this node (and its iframe) persists in the light DOM untouched,
|
|
235
|
+
* so the checkbox is rendered exactly once and re-projects automatically.
|
|
236
|
+
*/
|
|
237
|
+
private ensureRecaptchaSlot;
|
|
238
|
+
/** Remove the slotted light-DOM checkbox node. Safe to call when none exists. */
|
|
239
|
+
private removeRecaptchaSlot;
|
|
240
|
+
private renderBody;
|
|
241
|
+
/** Build the animated gradient orb (or avatar image) reflecting the current state. */
|
|
242
|
+
private buildOrb;
|
|
243
|
+
/** Pre-call panel for mode="both": orb + "Start a call" (voice) and "Message" (text). */
|
|
244
|
+
private renderBothEntry;
|
|
245
|
+
/** Voice UI: orb + spoken status + timer + mic/end controls. Never a text input. */
|
|
246
|
+
private renderVoiceBody;
|
|
247
|
+
/** Text/chat UI: conversation thread + message input. Never an orb or "listening" state. */
|
|
248
|
+
private renderTextBody;
|
|
249
|
+
/** In mode="both" during a live session, a control to switch to the other modality. */
|
|
250
|
+
private renderSwitchButton;
|
|
251
|
+
private renderControls;
|
|
252
|
+
private renderTextInput;
|
|
253
|
+
/**
|
|
254
|
+
* The chat thread for text mode. This is a fixed-height, internally scrolling
|
|
255
|
+
* window (like a normal website chatbot): the container is rendered at its full
|
|
256
|
+
* height as soon as the chat opens — empty until messages arrive — and messages
|
|
257
|
+
* accumulate + scroll inside it, so the panel's overall height stays stable.
|
|
258
|
+
* Auto-scrolls to the newest message after each render.
|
|
259
|
+
*/
|
|
260
|
+
private renderTranscript;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
declare const TRILLET_WIDGET_TAG = "trillet-widget";
|
|
264
|
+
declare function registerTrilletWidget(tag?: string): void;
|
|
265
|
+
|
|
266
|
+
export { TRILLET_WIDGET_TAG, TrilletWidget, TrilletWidgetElement, type TrilletWidgetProps, type WidgetBrand, type WidgetConfig, type WidgetMode, type WidgetPlacement, type WidgetVariant, type WidgetVariantInput, registerTrilletWidget };
|