@smooai/chat-widget 0.5.0 → 0.5.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.
@@ -49,7 +49,45 @@ var SmoothAgentChat = (function(exports) {
49
49
  return !resolved.allowAnonymous && (resolved.requireName || resolved.requireEmail || resolved.requirePhone);
50
50
  }
51
51
  //#endregion
52
- //#region node_modules/.pnpm/@smooai+smooth-operator@0.2.0/node_modules/@smooai/smooth-operator/dist/transport.js
52
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/typeof.js
53
+ function _typeof(o) {
54
+ "@babel/helpers - typeof";
55
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
56
+ return typeof o;
57
+ } : function(o) {
58
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
59
+ }, _typeof(o);
60
+ }
61
+ //#endregion
62
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPrimitive.js
63
+ function toPrimitive(t, r) {
64
+ if ("object" != _typeof(t) || !t) return t;
65
+ var e = t[Symbol.toPrimitive];
66
+ if (void 0 !== e) {
67
+ var i = e.call(t, r || "default");
68
+ if ("object" != _typeof(i)) return i;
69
+ throw new TypeError("@@toPrimitive must return a primitive value.");
70
+ }
71
+ return ("string" === r ? String : Number)(t);
72
+ }
73
+ //#endregion
74
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPropertyKey.js
75
+ function toPropertyKey(t) {
76
+ var i = toPrimitive(t, "string");
77
+ return "symbol" == _typeof(i) ? i : i + "";
78
+ }
79
+ //#endregion
80
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/defineProperty.js
81
+ function _defineProperty(e, r, t) {
82
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
83
+ value: t,
84
+ enumerable: !0,
85
+ configurable: !0,
86
+ writable: !0
87
+ }) : e[r] = t, e;
88
+ }
89
+ //#endregion
90
+ //#region node_modules/.pnpm/@smooai+smooth-operator@1.8.0/node_modules/@smooai/smooth-operator/dist/transport.js
53
91
  /**
54
92
  * Transport abstraction for the client.
55
93
  *
@@ -69,14 +107,14 @@ var SmoothAgentChat = (function(exports) {
69
107
  * Node, or a mock in tests).
70
108
  */
71
109
  var WebSocketTransport = class {
72
- socket = null;
73
- url;
74
- factory;
75
- connectTimeout;
76
- messageHandlers = /* @__PURE__ */ new Set();
77
- closeHandlers = /* @__PURE__ */ new Set();
78
- errorHandlers = /* @__PURE__ */ new Set();
79
110
  constructor(url, factory, connectTimeout = DEFAULT_CONNECT_TIMEOUT) {
111
+ _defineProperty(this, "socket", null);
112
+ _defineProperty(this, "url", void 0);
113
+ _defineProperty(this, "factory", void 0);
114
+ _defineProperty(this, "connectTimeout", void 0);
115
+ _defineProperty(this, "messageHandlers", /* @__PURE__ */ new Set());
116
+ _defineProperty(this, "closeHandlers", /* @__PURE__ */ new Set());
117
+ _defineProperty(this, "errorHandlers", /* @__PURE__ */ new Set());
80
118
  this.url = url;
81
119
  this.connectTimeout = connectTimeout;
82
120
  if (factory) this.factory = factory;
@@ -174,7 +212,7 @@ var SmoothAgentChat = (function(exports) {
174
212
  }
175
213
  };
176
214
  //#endregion
177
- //#region node_modules/.pnpm/@smooai+smooth-operator@0.2.0/node_modules/@smooai/smooth-operator/dist/types.js
215
+ //#region node_modules/.pnpm/@smooai+smooth-operator@1.8.0/node_modules/@smooai/smooth-operator/dist/types.js
178
216
  /** Every server→client `type` discriminator value. */
179
217
  const EVENT_TYPES = [
180
218
  "immediate_response",
@@ -195,7 +233,7 @@ var SmoothAgentChat = (function(exports) {
195
233
  return typeof frame === "object" && frame !== null && "type" in frame && typeof frame.type === "string" && EVENT_TYPES.includes(frame.type);
196
234
  }
197
235
  //#endregion
198
- //#region node_modules/.pnpm/@smooai+smooth-operator@0.2.0/node_modules/@smooai/smooth-operator/dist/client.js
236
+ //#region node_modules/.pnpm/@smooai+smooth-operator@1.8.0/node_modules/@smooai/smooth-operator/dist/client.js
199
237
  /**
200
238
  * SmoothAgentClient — a minimal, idiomatic, transport-agnostic client for the
201
239
  * smooth-operator WebSocket protocol.
@@ -215,6 +253,7 @@ var SmoothAgentChat = (function(exports) {
215
253
  * - **No live server required.** Correctness is fully unit-testable with a mock
216
254
  * transport (see `test/client.test.ts`).
217
255
  */
256
+ let _Symbol$asyncIterator;
218
257
  /** A timeout that yields no terminal event. */
219
258
  var RequestTimeoutError = class extends Error {
220
259
  constructor(requestId, ms) {
@@ -228,24 +267,25 @@ var SmoothAgentChat = (function(exports) {
228
267
  * and its async iteration throws it, so a stuck server can never hang the caller.
229
268
  */
230
269
  var TurnTimeoutError = class extends Error {
231
- requestId;
232
270
  constructor(requestId, ms) {
233
271
  super(`Turn ${requestId} timed out after ${ms}ms without a terminal response`);
272
+ _defineProperty(this, "requestId", void 0);
234
273
  this.name = "TurnTimeoutError";
235
274
  this.requestId = requestId;
236
275
  }
237
276
  };
238
277
  /** A protocol-level error event surfaced as a throwable. */
239
278
  var ProtocolError = class extends Error {
240
- code;
241
- requestId;
242
279
  constructor(code, message, requestId) {
243
280
  super(message);
281
+ _defineProperty(this, "code", void 0);
282
+ _defineProperty(this, "requestId", void 0);
244
283
  this.name = "ProtocolError";
245
284
  this.code = code;
246
285
  this.requestId = requestId;
247
286
  }
248
287
  };
288
+ _Symbol$asyncIterator = Symbol.asyncIterator;
249
289
  /**
250
290
  * A streaming message turn. Await it for the terminal {@link EventualResponse},
251
291
  * or async-iterate it to receive every intermediate event in arrival order.
@@ -259,19 +299,23 @@ var SmoothAgentChat = (function(exports) {
259
299
  * ```
260
300
  */
261
301
  var MessageTurn = class {
262
- /** The requestId this turn is correlated on. */
263
- requestId;
264
- queue = [];
265
- waiter = null;
266
- done = false;
267
- finalEvent = null;
268
- error = null;
269
- settled;
270
- settle;
271
- fail;
272
- onClose;
273
- timeoutTimer;
274
302
  constructor(requestId, onClose, turnTimeout = 0) {
303
+ _defineProperty(
304
+ this,
305
+ /** The requestId this turn is correlated on. */
306
+ "requestId",
307
+ void 0
308
+ );
309
+ _defineProperty(this, "queue", []);
310
+ _defineProperty(this, "waiter", null);
311
+ _defineProperty(this, "done", false);
312
+ _defineProperty(this, "finalEvent", null);
313
+ _defineProperty(this, "error", null);
314
+ _defineProperty(this, "settled", void 0);
315
+ _defineProperty(this, "settle", void 0);
316
+ _defineProperty(this, "fail", void 0);
317
+ _defineProperty(this, "onClose", void 0);
318
+ _defineProperty(this, "timeoutTimer", void 0);
275
319
  this.requestId = requestId;
276
320
  this.onClose = onClose;
277
321
  this.settled = new Promise((resolve, reject) => {
@@ -333,7 +377,7 @@ var SmoothAgentChat = (function(exports) {
333
377
  });
334
378
  }
335
379
  }
336
- [Symbol.asyncIterator]() {
380
+ [_Symbol$asyncIterator]() {
337
381
  return { next: () => {
338
382
  if (this.queue.length > 0) return Promise.resolve({
339
383
  value: this.queue.shift(),
@@ -359,19 +403,31 @@ var SmoothAgentChat = (function(exports) {
359
403
  }
360
404
  };
361
405
  var SmoothAgentClient = class {
362
- transport;
363
- generateRequestId;
364
- requestTimeout;
365
- turnTimeout;
366
- /** requestId → single-response waiter (create_session, get_session, ping, …). */
367
- pending = /* @__PURE__ */ new Map();
368
- /** requestId → active streaming turn (send_message, and HITL resumes). */
369
- turns = /* @__PURE__ */ new Map();
370
- /** Unsolicited-event listeners (keepalive, server-push). */
371
- listeners = /* @__PURE__ */ new Set();
372
- unsubscribe = [];
373
406
  constructor(options) {
374
- this.transport = options.transport ?? new WebSocketTransport(options.url, options.webSocketFactory);
407
+ _defineProperty(this, "transport", void 0);
408
+ _defineProperty(this, "generateRequestId", void 0);
409
+ _defineProperty(this, "requestTimeout", void 0);
410
+ _defineProperty(this, "turnTimeout", void 0);
411
+ _defineProperty(
412
+ this,
413
+ /** requestId → single-response waiter (create_session, get_session, ping, …). */
414
+ "pending",
415
+ /* @__PURE__ */ new Map()
416
+ );
417
+ _defineProperty(
418
+ this,
419
+ /** requestId → active streaming turn (send_message, and HITL resumes). */
420
+ "turns",
421
+ /* @__PURE__ */ new Map()
422
+ );
423
+ _defineProperty(
424
+ this,
425
+ /** Unsolicited-event listeners (keepalive, server-push). */
426
+ "listeners",
427
+ /* @__PURE__ */ new Set()
428
+ );
429
+ _defineProperty(this, "unsubscribe", []);
430
+ this.transport = options.transport ?? new WebSocketTransport(withConnectionToken(options.url, options.token), options.webSocketFactory);
375
431
  this.requestTimeout = options.requestTimeout ?? 3e4;
376
432
  this.turnTimeout = options.turnTimeout ?? 12e4;
377
433
  this.generateRequestId = options.generateRequestId ?? (() => `req-${globalThis.crypto?.randomUUID?.() ?? Math.random().toString(36).slice(2)}`);
@@ -526,6 +582,26 @@ var SmoothAgentChat = (function(exports) {
526
582
  this.turns.clear();
527
583
  }
528
584
  };
585
+ /**
586
+ * Merge a connection auth `token` into a WebSocket URL as a `?token=` query param,
587
+ * preserving any existing query string. Returns `url` unchanged when no token is
588
+ * given, so the no-token path is byte-for-byte identical to before. Uses `URL` /
589
+ * `URLSearchParams` so an existing `?foo=bar` becomes `?foo=bar&token=…` (and the
590
+ * value is properly percent-encoded) rather than a naive `?`/`&` string-concat.
591
+ *
592
+ * Falls back to manual concatenation if `url` is not absolute (so `URL` can't parse
593
+ * it) — e.g. a relative or mock URL used in tests.
594
+ */
595
+ function withConnectionToken(url, token) {
596
+ if (!token) return url;
597
+ try {
598
+ const parsed = new URL(url);
599
+ parsed.searchParams.set("token", token);
600
+ return parsed.toString();
601
+ } catch {
602
+ return `${url}${url.includes("?") ? "&" : "?"}token=${encodeURIComponent(token)}`;
603
+ }
604
+ }
529
605
  /** Pull the typed `data` payload out of an `immediate_response` event. */
530
606
  function extractImmediateData(event) {
531
607
  if (event.type === "immediate_response") return event.data;
@@ -592,19 +668,17 @@ var SmoothAgentChat = (function(exports) {
592
668
  return out;
593
669
  }
594
670
  var ConversationController = class {
595
- config;
596
- events;
597
- client = null;
598
- sessionId = null;
599
- messages = [];
600
- status = "idle";
601
- seq = 0;
602
- /** Visitor identity, seeded from config and updated by the pre-chat form. */
603
- identity;
604
- /** requestId of the in-flight turn — used to resume OTP / tool confirmations. */
605
- activeRequestId = null;
606
- interrupt = null;
607
671
  constructor(config, events) {
672
+ _defineProperty(this, "config", void 0);
673
+ _defineProperty(this, "events", void 0);
674
+ _defineProperty(this, "client", null);
675
+ _defineProperty(this, "sessionId", null);
676
+ _defineProperty(this, "messages", []);
677
+ _defineProperty(this, "status", "idle");
678
+ _defineProperty(this, "seq", 0);
679
+ _defineProperty(this, "identity", void 0);
680
+ _defineProperty(this, "activeRequestId", null);
681
+ _defineProperty(this, "interrupt", null);
608
682
  this.config = config;
609
683
  this.events = events;
610
684
  this.identity = {
@@ -1424,31 +1498,27 @@ var SmoothAgentChat = (function(exports) {
1424
1498
  static get observedAttributes() {
1425
1499
  return OBSERVED;
1426
1500
  }
1427
- root;
1428
- controller = null;
1429
- overrides = {};
1430
- open = false;
1431
- messages = [];
1432
- status = "idle";
1433
- mounted = false;
1434
- /** True once the visitor has cleared the pre-chat identity gate (or it's not needed). */
1435
- userInfoSatisfied = false;
1436
- /** True after the visitor has sent their first message (hides starter chips). */
1437
- hasSent = false;
1438
- /** Starter prompts shown as chips in the empty state. */
1439
- examplePrompts = [];
1440
- /** Current mid-turn interrupt (OTP / tool-confirmation), or null. */
1441
- interrupt = null;
1442
- interruptEl = null;
1443
- panelEl = null;
1444
- launcherEl = null;
1445
- messagesEl = null;
1446
- statusEl = null;
1447
- dotEl = null;
1448
- inputEl = null;
1449
- sendBtn = null;
1450
1501
  constructor() {
1451
1502
  super();
1503
+ _defineProperty(this, "root", void 0);
1504
+ _defineProperty(this, "controller", null);
1505
+ _defineProperty(this, "overrides", {});
1506
+ _defineProperty(this, "open", false);
1507
+ _defineProperty(this, "messages", []);
1508
+ _defineProperty(this, "status", "idle");
1509
+ _defineProperty(this, "mounted", false);
1510
+ _defineProperty(this, "userInfoSatisfied", false);
1511
+ _defineProperty(this, "hasSent", false);
1512
+ _defineProperty(this, "examplePrompts", []);
1513
+ _defineProperty(this, "interrupt", null);
1514
+ _defineProperty(this, "interruptEl", null);
1515
+ _defineProperty(this, "panelEl", null);
1516
+ _defineProperty(this, "launcherEl", null);
1517
+ _defineProperty(this, "messagesEl", null);
1518
+ _defineProperty(this, "statusEl", null);
1519
+ _defineProperty(this, "dotEl", null);
1520
+ _defineProperty(this, "inputEl", null);
1521
+ _defineProperty(this, "sendBtn", null);
1452
1522
  this.root = this.attachShadow({ mode: "open" });
1453
1523
  }
1454
1524
  connectedCallback() {