@trillet-ai/web-sdk 1.15.0 → 1.16.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.
@@ -323,7 +323,7 @@ declare class TrilletWidgetElement extends HTMLElement {
323
323
  private config;
324
324
  private agent;
325
325
  private state;
326
- private open;
326
+ private isOpen;
327
327
  private micEnabled;
328
328
  private speaking;
329
329
  private transcripts;
@@ -372,6 +372,12 @@ declare class TrilletWidgetElement extends HTMLElement {
372
372
  * first when needed; the message is delivered as soon as the session connects.
373
373
  */
374
374
  sendMessage(text: string): Promise<void>;
375
+ /**
376
+ * Expand the widget if it is minimised, without touching the conversation, its
377
+ * transcript or the session. Safe to call when already open, when no conversation is
378
+ * live, and in voice mode (which has no panel, so it does nothing there).
379
+ */
380
+ open(): void;
375
381
  /** Send now, or behind a message still held for the agent's greeting (TRI-2230). */
376
382
  private deliver;
377
383
  /**
@@ -1289,13 +1289,21 @@ var HeldMessages = class {
1289
1289
  }
1290
1290
  };
1291
1291
 
1292
+ // src/widget/panelOpen.ts
1293
+ function panelOpenAction(ctx) {
1294
+ if (ctx.mode === "voice" || ctx.open) return "none";
1295
+ const fresh = ctx.state === "idle" && !ctx.hasTranscript;
1296
+ if (ctx.mode === "text" && fresh && !ctx.needsRecaptcha) return "begin";
1297
+ return "expand";
1298
+ }
1299
+
1292
1300
  // src/widget/TrilletWidgetElement.ts
1293
1301
  var TrilletWidgetElement = class extends HTMLElement {
1294
1302
  constructor() {
1295
1303
  super();
1296
1304
  this.agent = null;
1297
1305
  this.state = "idle";
1298
- this.open = false;
1306
+ this.isOpen = false;
1299
1307
  // panel open vs. launcher only
1300
1308
  this.micEnabled = true;
1301
1309
  this.speaking = false;
@@ -1427,6 +1435,7 @@ var TrilletWidgetElement = class extends HTMLElement {
1427
1435
  const message = text.trim();
1428
1436
  if (!message) return;
1429
1437
  if (this.state === "live" && (this.resolvedMode() === "text" || this.config.mode === "both")) {
1438
+ this.open();
1430
1439
  await this.deliver(message);
1431
1440
  return;
1432
1441
  }
@@ -1437,6 +1446,28 @@ var TrilletWidgetElement = class extends HTMLElement {
1437
1446
  }
1438
1447
  this.held.hold(message);
1439
1448
  if (this.state !== "connecting") await this.startConversation("text");
1449
+ else this.open();
1450
+ }
1451
+ /**
1452
+ * Expand the widget if it is minimised, without touching the conversation, its
1453
+ * transcript or the session. Safe to call when already open, when no conversation is
1454
+ * live, and in voice mode (which has no panel, so it does nothing there).
1455
+ */
1456
+ open() {
1457
+ const action = panelOpenAction({
1458
+ mode: this.config.mode,
1459
+ open: this.isOpen,
1460
+ state: this.state,
1461
+ hasTranscript: this.transcripts.length > 0,
1462
+ needsRecaptcha: this.needsRecaptcha()
1463
+ });
1464
+ if (action === "none") return;
1465
+ this.isOpen = true;
1466
+ if (action === "begin") {
1467
+ void this.beginCall("text");
1468
+ return;
1469
+ }
1470
+ this.render();
1440
1471
  }
1441
1472
  /** Send now, or behind a message still held for the agent's greeting (TRI-2230). */
1442
1473
  async deliver(text) {
@@ -1453,10 +1484,13 @@ var TrilletWidgetElement = class extends HTMLElement {
1453
1484
  * @param modality - optional; only used in `mode="both"` to pick voice vs text.
1454
1485
  */
1455
1486
  async startConversation(modality) {
1456
- if (this.state === "connecting" || this.state === "live") return;
1487
+ if (this.state === "connecting" || this.state === "live") {
1488
+ if (this.config.mode === "text" || this.config.mode === "both" && modality !== "voice") this.open();
1489
+ return;
1490
+ }
1457
1491
  const chat = this.config.mode === "text" || this.config.mode === "both" && modality !== "voice";
1458
1492
  if (chat) {
1459
- this.open = true;
1493
+ this.isOpen = true;
1460
1494
  }
1461
1495
  if (this.needsRecaptcha()) {
1462
1496
  this.render();
@@ -1814,7 +1848,7 @@ var TrilletWidgetElement = class extends HTMLElement {
1814
1848
  } else if (this.showVariablesForm) {
1815
1849
  view = "variables";
1816
1850
  el = this.renderVariablesForm();
1817
- } else if (this.open) {
1851
+ } else if (this.isOpen) {
1818
1852
  view = "panel";
1819
1853
  el = this.renderPanel();
1820
1854
  } else {
@@ -1912,7 +1946,7 @@ var TrilletWidgetElement = class extends HTMLElement {
1912
1946
  this.showTerms = false;
1913
1947
  const start = this.pendingStart;
1914
1948
  this.pendingStart = null;
1915
- if (start === "text") this.open = true;
1949
+ if (start === "text") this.isOpen = true;
1916
1950
  void this.beginCall(start != null ? start : void 0);
1917
1951
  });
1918
1952
  const decline = document.createElement("button");
@@ -1922,7 +1956,7 @@ var TrilletWidgetElement = class extends HTMLElement {
1922
1956
  decline.addEventListener("click", () => {
1923
1957
  this.showTerms = false;
1924
1958
  this.pendingStart = null;
1925
- this.open = false;
1959
+ this.isOpen = false;
1926
1960
  this.render();
1927
1961
  });
1928
1962
  row.appendChild(accept);
@@ -1967,7 +2001,7 @@ var TrilletWidgetElement = class extends HTMLElement {
1967
2001
  this.showVariablesForm = false;
1968
2002
  const start = this.pendingStart;
1969
2003
  this.pendingStart = null;
1970
- if (start === "text") this.open = true;
2004
+ if (start === "text") this.isOpen = true;
1971
2005
  void this.beginCall(start != null ? start : void 0);
1972
2006
  });
1973
2007
  this.config.dynamicVariablePrompts.forEach((prompt, index) => {
@@ -2021,7 +2055,7 @@ var TrilletWidgetElement = class extends HTMLElement {
2021
2055
  decline.addEventListener("click", () => {
2022
2056
  this.showVariablesForm = false;
2023
2057
  this.pendingStart = null;
2024
- this.open = false;
2058
+ this.isOpen = false;
2025
2059
  this.render();
2026
2060
  });
2027
2061
  row.appendChild(decline);
@@ -2204,7 +2238,7 @@ var TrilletWidgetElement = class extends HTMLElement {
2204
2238
  * until the visitor explicitly starts over (see {@link startOver}).
2205
2239
  */
2206
2240
  openPanel() {
2207
- this.open = true;
2241
+ this.isOpen = true;
2208
2242
  const fresh = this.state === "idle" && this.transcripts.length === 0;
2209
2243
  if (this.config.mode === "text" && fresh && !this.needsRecaptcha()) {
2210
2244
  void this.beginCall("text");
@@ -2265,7 +2299,7 @@ var TrilletWidgetElement = class extends HTMLElement {
2265
2299
  actions.className = "tw-header-actions";
2266
2300
  actions.appendChild(
2267
2301
  this.iconButton(ICONS.minimize, this.config.copy.minimize, () => {
2268
- this.open = false;
2302
+ this.isOpen = false;
2269
2303
  this.render();
2270
2304
  })
2271
2305
  );
@@ -2273,7 +2307,7 @@ var TrilletWidgetElement = class extends HTMLElement {
2273
2307
  actions.appendChild(
2274
2308
  this.iconButton(ICONS.close, this.config.copy.close, () => {
2275
2309
  if (this.state === "live" || this.state === "connecting") this.endConversation();
2276
- this.open = false;
2310
+ this.isOpen = false;
2277
2311
  this.render();
2278
2312
  })
2279
2313
  );
@@ -2599,7 +2633,7 @@ var TrilletWidgetElement = class extends HTMLElement {
2599
2633
  } else if (this.config.mode === "both") {
2600
2634
  bar.appendChild(
2601
2635
  this.iconButton(ICONS.chat, this.config.copy.showConversation, () => {
2602
- this.open = true;
2636
+ this.isOpen = true;
2603
2637
  this.render();
2604
2638
  }, "tw-sq tw-sq-quiet")
2605
2639
  );
@@ -2711,7 +2745,7 @@ var TrilletWidgetElement = class extends HTMLElement {
2711
2745
  * there is no text thread on screen, in which case the caller does a full render.
2712
2746
  */
2713
2747
  updateThread() {
2714
- if (!this.open) return false;
2748
+ if (!this.isOpen) return false;
2715
2749
  const thread = this.root.querySelector(".tw-chat");
2716
2750
  if (!thread) return false;
2717
2751
  this.fillThread(thread);