@trillet-ai/web-sdk 1.9.1 → 1.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/widget/index.d.ts +11 -0
- package/dist/widget/index.js +136 -1
- package/dist/widget/index.js.map +1 -1
- package/dist/widget.umd.js +53 -1
- package/dist/widget.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/widget/index.d.ts
CHANGED
|
@@ -166,6 +166,11 @@ declare class TrilletWidgetElement extends HTMLElement {
|
|
|
166
166
|
startCall(): Promise<void>;
|
|
167
167
|
/** @deprecated Use {@link endConversation}. Kept as a thin alias for back-compat. */
|
|
168
168
|
endCall(): void;
|
|
169
|
+
/**
|
|
170
|
+
* Voice embeds run entirely on the floating control. Text and `both` still need
|
|
171
|
+
* the conversation panel.
|
|
172
|
+
*/
|
|
173
|
+
private isInlineVoice;
|
|
169
174
|
/** The concrete modality to run for the current session (`both` -> activeMode). */
|
|
170
175
|
private resolvedMode;
|
|
171
176
|
/** Keep activeMode consistent with the configured mode. */
|
|
@@ -194,6 +199,12 @@ declare class TrilletWidgetElement extends HTMLElement {
|
|
|
194
199
|
private renderStatus;
|
|
195
200
|
private timerText;
|
|
196
201
|
private render;
|
|
202
|
+
/**
|
|
203
|
+
* Voice chrome: one floating control. Idle/ended starts the call. Connecting
|
|
204
|
+
* shows progress on that same control. Live turns it into hang up and reflects
|
|
205
|
+
* listening vs speaking. No panel.
|
|
206
|
+
*/
|
|
207
|
+
private renderInlineVoice;
|
|
197
208
|
private renderLauncher;
|
|
198
209
|
private renderPanel;
|
|
199
210
|
/**
|
package/dist/widget/index.js
CHANGED
|
@@ -241,6 +241,58 @@ var WIDGET_STYLES = (
|
|
|
241
241
|
background-position: center;
|
|
242
242
|
animation: none;
|
|
243
243
|
}
|
|
244
|
+
.tw-launcher-copy {
|
|
245
|
+
display: flex;
|
|
246
|
+
flex-direction: column;
|
|
247
|
+
align-items: flex-start;
|
|
248
|
+
line-height: 1.15;
|
|
249
|
+
text-align: left;
|
|
250
|
+
}
|
|
251
|
+
.tw-launcher-state {
|
|
252
|
+
font-size: 11px;
|
|
253
|
+
font-weight: 500;
|
|
254
|
+
opacity: 0.92;
|
|
255
|
+
}
|
|
256
|
+
/* Voice calls stay on this control: connecting, then hang up. */
|
|
257
|
+
.tw-launcher.tw-hangup { background: #e5484d; }
|
|
258
|
+
.tw-launcher.tw-listening {
|
|
259
|
+
box-shadow: var(--trillet-shadow), 0 0 0 3px rgba(255, 255, 255, 0.45);
|
|
260
|
+
}
|
|
261
|
+
.tw-launcher.tw-speaking {
|
|
262
|
+
box-shadow: var(--trillet-shadow), 0 0 0 4px rgba(255, 255, 255, 0.8);
|
|
263
|
+
}
|
|
264
|
+
.tw-launcher.tw-speaking .tw-launcher-orb {
|
|
265
|
+
animation: tw-orb-rotate 4.5s linear infinite, tw-bob 0.7s ease-in-out infinite alternate;
|
|
266
|
+
}
|
|
267
|
+
.tw-launcher.tw-connecting { cursor: default; }
|
|
268
|
+
.tw-launcher.tw-connecting .tw-launcher-orb {
|
|
269
|
+
animation: tw-orb-rotate 1.2s linear infinite;
|
|
270
|
+
}
|
|
271
|
+
.tw-launcher:disabled { opacity: 0.72; cursor: default; }
|
|
272
|
+
.tw-launcher:disabled:hover { transform: none; box-shadow: var(--trillet-shadow); }
|
|
273
|
+
|
|
274
|
+
/* Optional reCAPTCHA sits with the floating control. Not a call panel. */
|
|
275
|
+
.tw-inline {
|
|
276
|
+
display: flex;
|
|
277
|
+
flex-direction: column;
|
|
278
|
+
align-items: flex-end;
|
|
279
|
+
gap: 10px;
|
|
280
|
+
}
|
|
281
|
+
:host([placement="bottom-left"]) .tw-inline,
|
|
282
|
+
:host([placement="top-left"]) .tw-inline { align-items: flex-start; }
|
|
283
|
+
:host([placement="bottom"]) .tw-inline,
|
|
284
|
+
:host([placement="top"]) .tw-inline { align-items: center; }
|
|
285
|
+
.tw-inline-hint {
|
|
286
|
+
max-width: 304px;
|
|
287
|
+
padding: 8px 12px;
|
|
288
|
+
border-radius: 10px;
|
|
289
|
+
background: var(--trillet-surface);
|
|
290
|
+
color: var(--trillet-on-surface);
|
|
291
|
+
border: 1px solid var(--trillet-border);
|
|
292
|
+
box-shadow: var(--trillet-shadow);
|
|
293
|
+
font-size: 12px;
|
|
294
|
+
font-weight: 600;
|
|
295
|
+
}
|
|
244
296
|
|
|
245
297
|
/* ---- Panel ---- */
|
|
246
298
|
.tw-panel {
|
|
@@ -719,7 +771,9 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
719
771
|
*/
|
|
720
772
|
async startConversation(modality) {
|
|
721
773
|
if (this.state === "connecting" || this.state === "live") return;
|
|
722
|
-
this.
|
|
774
|
+
if (!this.isInlineVoice()) {
|
|
775
|
+
this.open = true;
|
|
776
|
+
}
|
|
723
777
|
if (this.needsRecaptcha()) {
|
|
724
778
|
this.render();
|
|
725
779
|
return;
|
|
@@ -740,6 +794,13 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
740
794
|
this.endConversation();
|
|
741
795
|
}
|
|
742
796
|
// ---- Modality helpers ------------------------------------------------------
|
|
797
|
+
/**
|
|
798
|
+
* Voice embeds run entirely on the floating control. Text and `both` still need
|
|
799
|
+
* the conversation panel.
|
|
800
|
+
*/
|
|
801
|
+
isInlineVoice() {
|
|
802
|
+
return this.config.mode === "voice";
|
|
803
|
+
}
|
|
743
804
|
/** The concrete modality to run for the current session (`both` -> activeMode). */
|
|
744
805
|
resolvedMode() {
|
|
745
806
|
var _a;
|
|
@@ -856,6 +917,7 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
856
917
|
endLocalCall() {
|
|
857
918
|
if (this.state === "ended" || this.state === "idle") return;
|
|
858
919
|
this.clearDurationTimer();
|
|
920
|
+
this.speaking = false;
|
|
859
921
|
this.dispatch("call-end", this.elapsedSeconds);
|
|
860
922
|
this.dispatch("conversationEnded", this.elapsedSeconds);
|
|
861
923
|
this.setState("ended");
|
|
@@ -865,6 +927,7 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
865
927
|
handleError(error) {
|
|
866
928
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
867
929
|
this.clearDurationTimer();
|
|
930
|
+
this.speaking = false;
|
|
868
931
|
this.switching = false;
|
|
869
932
|
this.dispatch("error", err);
|
|
870
933
|
this.agent = null;
|
|
@@ -959,12 +1022,84 @@ var TrilletWidgetElement = class extends HTMLElement {
|
|
|
959
1022
|
}
|
|
960
1023
|
render() {
|
|
961
1024
|
this.container.replaceChildren();
|
|
1025
|
+
if (this.isInlineVoice()) {
|
|
1026
|
+
this.container.appendChild(this.renderInlineVoice());
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
962
1029
|
if (!this.open) {
|
|
963
1030
|
this.container.appendChild(this.renderLauncher());
|
|
964
1031
|
return;
|
|
965
1032
|
}
|
|
966
1033
|
this.container.appendChild(this.renderPanel());
|
|
967
1034
|
}
|
|
1035
|
+
/**
|
|
1036
|
+
* Voice chrome: one floating control. Idle/ended starts the call. Connecting
|
|
1037
|
+
* shows progress on that same control. Live turns it into hang up and reflects
|
|
1038
|
+
* listening vs speaking. No panel.
|
|
1039
|
+
*/
|
|
1040
|
+
renderInlineVoice() {
|
|
1041
|
+
const wrap = document.createElement("div");
|
|
1042
|
+
wrap.className = "tw-inline";
|
|
1043
|
+
const showGate = this.needsRecaptcha() && (this.state === "idle" || this.state === "ended");
|
|
1044
|
+
if (showGate) {
|
|
1045
|
+
const hint = document.createElement("div");
|
|
1046
|
+
hint.className = "tw-inline-hint";
|
|
1047
|
+
hint.textContent = this.config.recaptchaText;
|
|
1048
|
+
wrap.appendChild(hint);
|
|
1049
|
+
const slot = document.createElement("slot");
|
|
1050
|
+
slot.setAttribute("name", "recaptcha");
|
|
1051
|
+
slot.className = "tw-recaptcha-slot";
|
|
1052
|
+
wrap.appendChild(slot);
|
|
1053
|
+
this.ensureRecaptchaSlot();
|
|
1054
|
+
}
|
|
1055
|
+
const btn = document.createElement("button");
|
|
1056
|
+
btn.className = "tw-launcher";
|
|
1057
|
+
btn.type = "button";
|
|
1058
|
+
const orb = document.createElement("span");
|
|
1059
|
+
orb.className = "tw-launcher-orb";
|
|
1060
|
+
if (this.config.avatar) {
|
|
1061
|
+
orb.classList.add("tw-launcher-orb-avatar");
|
|
1062
|
+
orb.style.backgroundImage = `url("${this.config.avatar}")`;
|
|
1063
|
+
}
|
|
1064
|
+
btn.appendChild(orb);
|
|
1065
|
+
const copy = document.createElement("span");
|
|
1066
|
+
copy.className = "tw-launcher-copy";
|
|
1067
|
+
const label = document.createElement("span");
|
|
1068
|
+
label.className = "tw-launcher-label";
|
|
1069
|
+
if (this.state === "connecting") {
|
|
1070
|
+
btn.classList.add("tw-connecting");
|
|
1071
|
+
btn.disabled = true;
|
|
1072
|
+
label.textContent = "Connecting\u2026";
|
|
1073
|
+
btn.setAttribute("aria-label", "Connecting");
|
|
1074
|
+
} else if (this.state === "live") {
|
|
1075
|
+
btn.classList.add("tw-hangup");
|
|
1076
|
+
btn.classList.add(this.speaking ? "tw-speaking" : "tw-listening");
|
|
1077
|
+
label.textContent = this.config.endCallText;
|
|
1078
|
+
const activity = this.speaking ? this.config.speakingText : this.config.listeningText;
|
|
1079
|
+
const stateLabel = document.createElement("span");
|
|
1080
|
+
stateLabel.className = "tw-launcher-state";
|
|
1081
|
+
stateLabel.textContent = activity;
|
|
1082
|
+
copy.appendChild(label);
|
|
1083
|
+
copy.appendChild(stateLabel);
|
|
1084
|
+
btn.setAttribute("aria-label", `${this.config.endCallText}. ${activity}`);
|
|
1085
|
+
btn.addEventListener("click", () => {
|
|
1086
|
+
this.endConversation();
|
|
1087
|
+
});
|
|
1088
|
+
} else {
|
|
1089
|
+
label.textContent = this.config.actionText || this.config.startCallText;
|
|
1090
|
+
btn.disabled = showGate;
|
|
1091
|
+
btn.setAttribute("aria-label", label.textContent);
|
|
1092
|
+
btn.addEventListener("click", () => {
|
|
1093
|
+
if (this.state === "connecting" || this.state === "live") return;
|
|
1094
|
+
if (this.needsRecaptcha()) return;
|
|
1095
|
+
void this.beginCall();
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
if (this.state !== "live") copy.appendChild(label);
|
|
1099
|
+
btn.appendChild(copy);
|
|
1100
|
+
wrap.appendChild(btn);
|
|
1101
|
+
return wrap;
|
|
1102
|
+
}
|
|
968
1103
|
renderLauncher() {
|
|
969
1104
|
const btn = document.createElement("button");
|
|
970
1105
|
btn.className = "tw-launcher";
|