@paramms/chat-widget 1.0.25 → 1.0.27

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/index.js CHANGED
@@ -2,8 +2,8 @@ var De = Object.defineProperty;
2
2
  var _e = (s, e, t) => e in s ? De(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
3
  var a = (s, e, t) => _e(s, typeof e != "symbol" ? e + "" : e, t);
4
4
  import { p as $e, r as He, a as Re } from "./uid.js";
5
- import { h as en } from "./uid.js";
6
- const Yt = (s) => s;
5
+ import { h as nn } from "./uid.js";
6
+ const Gt = (s) => s;
7
7
  function Fe(s) {
8
8
  const e = s.length;
9
9
  let t = 0, n = 0;
@@ -36,8 +36,8 @@ function je(s, e, t) {
36
36
  e[i++] = r >> 6 & 31 | 192;
37
37
  else {
38
38
  if (r >= 55296 && r <= 56319 && o < n) {
39
- const h = s.charCodeAt(o);
40
- (h & 64512) === 56320 && (++o, r = ((r & 1023) << 10) + (h & 1023) + 65536);
39
+ const p = s.charCodeAt(o);
40
+ (p & 64512) === 56320 && (++o, r = ((r & 1023) << 10) + (p & 1023) + 65536);
41
41
  }
42
42
  r & 4294901760 ? (e[i++] = r >> 18 & 7 | 240, e[i++] = r >> 12 & 63 | 128, e[i++] = r >> 6 & 63 | 128) : (e[i++] = r >> 12 & 15 | 224, e[i++] = r >> 6 & 63 | 128);
43
43
  }
@@ -61,21 +61,21 @@ function ke(s, e, t) {
61
61
  const i = n + t, o = [];
62
62
  let r = "";
63
63
  for (; n < i; ) {
64
- const h = s[n++];
65
- if (!(h & 128))
66
- o.push(h);
67
- else if ((h & 224) === 192) {
64
+ const p = s[n++];
65
+ if (!(p & 128))
66
+ o.push(p);
67
+ else if ((p & 224) === 192) {
68
68
  const w = s[n++] & 63;
69
- o.push((h & 31) << 6 | w);
70
- } else if ((h & 240) === 224) {
69
+ o.push((p & 31) << 6 | w);
70
+ } else if ((p & 240) === 224) {
71
71
  const w = s[n++] & 63, d = s[n++] & 63;
72
- o.push((h & 31) << 12 | w << 6 | d);
73
- } else if ((h & 248) === 240) {
72
+ o.push((p & 31) << 12 | w << 6 | d);
73
+ } else if ((p & 248) === 240) {
74
74
  const w = s[n++] & 63, d = s[n++] & 63, v = s[n++] & 63;
75
- let x = (h & 7) << 18 | w << 12 | d << 6 | v;
75
+ let x = (p & 7) << 18 | w << 12 | d << 6 | v;
76
76
  x > 65535 && (x -= 65536, o.push(x >>> 10 & 1023 | 55296), x = 56320 | x & 1023), o.push(x);
77
77
  } else
78
- o.push(h);
78
+ o.push(p);
79
79
  o.length >= We && (r += String.fromCharCode(...o), o.length = 0);
80
80
  }
81
81
  return o.length > 0 && (r += String.fromCharCode(...o)), r;
@@ -107,7 +107,7 @@ class z extends Error {
107
107
  }
108
108
  }
109
109
  const q = 4294967295;
110
- function Qe(s, e, t) {
110
+ function Ze(s, e, t) {
111
111
  const n = t / 4294967296, i = t;
112
112
  s.setUint32(e, n), s.setUint32(e + 4, i);
113
113
  }
@@ -119,7 +119,7 @@ function Ie(s, e) {
119
119
  const t = s.getInt32(e), n = s.getUint32(e + 4);
120
120
  return t * 4294967296 + n;
121
121
  }
122
- function Ze(s, e) {
122
+ function Qe(s, e) {
123
123
  const t = s.getUint32(e), n = s.getUint32(e + 4);
124
124
  return t * 4294967296 + n;
125
125
  }
@@ -228,7 +228,7 @@ const ct = {
228
228
  }
229
229
  };
230
230
  a(te, "defaultCodec", new te());
231
- let Z = te;
231
+ let Q = te;
232
232
  function dt(s) {
233
233
  return s instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && s instanceof SharedArrayBuffer;
234
234
  }
@@ -251,7 +251,7 @@ class ce {
251
251
  a(this, "view");
252
252
  a(this, "bytes");
253
253
  a(this, "entered", !1);
254
- this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? Z.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.maxDepth = (e == null ? void 0 : e.maxDepth) ?? lt, this.initialBufferSize = (e == null ? void 0 : e.initialBufferSize) ?? ht, this.sortKeys = (e == null ? void 0 : e.sortKeys) ?? !1, this.forceFloat32 = (e == null ? void 0 : e.forceFloat32) ?? !1, this.ignoreUndefined = (e == null ? void 0 : e.ignoreUndefined) ?? !1, this.forceIntegerToFloat = (e == null ? void 0 : e.forceIntegerToFloat) ?? !1, this.pos = 0, this.view = new DataView(new ArrayBuffer(this.initialBufferSize)), this.bytes = new Uint8Array(this.view.buffer);
254
+ this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? Q.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.maxDepth = (e == null ? void 0 : e.maxDepth) ?? lt, this.initialBufferSize = (e == null ? void 0 : e.initialBufferSize) ?? ht, this.sortKeys = (e == null ? void 0 : e.sortKeys) ?? !1, this.forceFloat32 = (e == null ? void 0 : e.forceFloat32) ?? !1, this.ignoreUndefined = (e == null ? void 0 : e.ignoreUndefined) ?? !1, this.forceIntegerToFloat = (e == null ? void 0 : e.forceIntegerToFloat) ?? !1, this.pos = 0, this.view = new DataView(new ArrayBuffer(this.initialBufferSize)), this.bytes = new Uint8Array(this.view.buffer);
255
255
  }
256
256
  clone() {
257
257
  return new ce({
@@ -459,7 +459,7 @@ class ce {
459
459
  this.ensureBufferSizeToWrite(8), this.view.setFloat64(this.pos, e), this.pos += 8;
460
460
  }
461
461
  writeU64(e) {
462
- this.ensureBufferSizeToWrite(8), Qe(this.view, this.pos, e), this.pos += 8;
462
+ this.ensureBufferSizeToWrite(8), Ze(this.view, this.pos, e), this.pos += 8;
463
463
  }
464
464
  writeI64(e) {
465
465
  this.ensureBufferSizeToWrite(8), Se(this.view, this.pos, e), this.pos += 8;
@@ -496,8 +496,8 @@ class wt {
496
496
  const i = this.caches[n - 1];
497
497
  e: for (const o of i) {
498
498
  const r = o.bytes;
499
- for (let h = 0; h < n; h++)
500
- if (r[h] !== e[t + h])
499
+ for (let p = 0; p < n; p++)
500
+ if (r[p] !== e[t + p])
501
501
  continue e;
502
502
  return o.str;
503
503
  }
@@ -600,7 +600,7 @@ class le {
600
600
  a(this, "headByte", O);
601
601
  a(this, "stack", new yt());
602
602
  a(this, "entered", !1);
603
- this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? Z.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.rawStrings = (e == null ? void 0 : e.rawStrings) ?? !1, this.maxStrLength = (e == null ? void 0 : e.maxStrLength) ?? q, this.maxBinLength = (e == null ? void 0 : e.maxBinLength) ?? q, this.maxArrayLength = (e == null ? void 0 : e.maxArrayLength) ?? q, this.maxMapLength = (e == null ? void 0 : e.maxMapLength) ?? q, this.maxExtLength = (e == null ? void 0 : e.maxExtLength) ?? q, this.keyDecoder = (e == null ? void 0 : e.keyDecoder) !== void 0 ? e.keyDecoder : bt, this.mapKeyConverter = (e == null ? void 0 : e.mapKeyConverter) ?? xt;
603
+ this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? Q.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.rawStrings = (e == null ? void 0 : e.rawStrings) ?? !1, this.maxStrLength = (e == null ? void 0 : e.maxStrLength) ?? q, this.maxBinLength = (e == null ? void 0 : e.maxBinLength) ?? q, this.maxArrayLength = (e == null ? void 0 : e.maxArrayLength) ?? q, this.maxMapLength = (e == null ? void 0 : e.maxMapLength) ?? q, this.maxExtLength = (e == null ? void 0 : e.maxExtLength) ?? q, this.keyDecoder = (e == null ? void 0 : e.keyDecoder) !== void 0 ? e.keyDecoder : bt, this.mapKeyConverter = (e == null ? void 0 : e.mapKeyConverter) ?? xt;
604
604
  }
605
605
  clone() {
606
606
  return new le({
@@ -673,10 +673,10 @@ class le {
673
673
  try {
674
674
  this.entered = !0;
675
675
  let t = !1, n;
676
- for await (const h of e) {
676
+ for await (const p of e) {
677
677
  if (t)
678
678
  throw this.entered = !1, this.createExtraByteError(this.totalPos);
679
- this.appendBuffer(h);
679
+ this.appendBuffer(p);
680
680
  try {
681
681
  n = this.doDecodeSync(), t = !0;
682
682
  } catch (w) {
@@ -975,7 +975,7 @@ class le {
975
975
  return this.pos += 4, e;
976
976
  }
977
977
  readU64() {
978
- const e = Ze(this.view, this.pos);
978
+ const e = Qe(this.view, this.pos);
979
979
  return this.pos += 8, e;
980
980
  }
981
981
  readI64() {
@@ -1203,6 +1203,7 @@ class Et {
1203
1203
  a(this, "socket", null);
1204
1204
  a(this, "state", "idle");
1205
1205
  a(this, "authed", !1);
1206
+ a(this, "everAuthed", !1);
1206
1207
  a(this, "attempt", 0);
1207
1208
  a(this, "outbox", []);
1208
1209
  a(this, "stopped", !1);
@@ -1213,7 +1214,7 @@ class Et {
1213
1214
  var n, i;
1214
1215
  if (this.state === "connecting" || this.state === "open") return;
1215
1216
  this.stopped = !1, this.state = "connecting", this.authed = !1, (i = (n = this.opts).onStatusChange) == null || i.call(n, this.attempt > 0 ? "reconnecting" : "connecting");
1216
- const t = (this.opts.socketFactory ?? Tt)(this.opts.url);
1217
+ const t = (this.opts.socketFactory ?? Pt)(this.opts.url);
1217
1218
  t.binaryType = "arraybuffer", this.socket = t, t.onopen = () => {
1218
1219
  this.raw({ type: "auth", token: this.opts.token });
1219
1220
  }, t.onmessage = (o) => {
@@ -1246,8 +1247,17 @@ class Et {
1246
1247
  }
1247
1248
  }
1248
1249
  handle(e) {
1249
- var t, n;
1250
- e.type === "authed" && (this.attempt = 0, this.state = "open", this.authed = !0, (n = (t = this.opts).onStatusChange) == null || n.call(t, "open"), this.raw(this.opts.open), this.flush()), e.type === "opened" && this.raw({ type: "sync", conversationId: e.conversation.id, sinceSeq: this.opts.getCursor() }), this.opts.onFrame(e);
1250
+ var t, n, i, o, r;
1251
+ if (e.type === "authed" && (this.attempt = 0, this.state = "open", this.authed = !0, this.everAuthed = !0, (n = (t = this.opts).onStatusChange) == null || n.call(t, "open"), this.raw(this.opts.open), this.flush()), e.type === "opened" && this.raw({ type: "sync", conversationId: e.conversation.id, sinceSeq: this.opts.getCursor() }), e.type === "error" && Tt.has(e.code)) {
1252
+ this.stopped = !0;
1253
+ try {
1254
+ (i = this.socket) == null || i.close();
1255
+ } catch {
1256
+ }
1257
+ this.state = "closed", (r = (o = this.opts).onStatusChange) == null || r.call(o, "error", Ut(e.code)), this.opts.onFrame(e);
1258
+ return;
1259
+ }
1260
+ this.opts.onFrame(e);
1251
1261
  }
1252
1262
  flush() {
1253
1263
  const e = this.outbox;
@@ -1263,20 +1273,30 @@ class Et {
1263
1273
  }
1264
1274
  }
1265
1275
  onClosed() {
1276
+ var i, o;
1266
1277
  if (this.authed = !1, this.socket = null, this.stopped) {
1267
1278
  this.state = "closed";
1268
1279
  return;
1269
1280
  }
1270
1281
  this.state = "idle";
1271
1282
  const e = this.opts.backoffBaseMs ?? 500, t = this.opts.backoffMaxMs ?? 15e3, n = Math.min(t, e * 2 ** this.attempt) * (0.5 + Math.random() * 0.5);
1272
- this.attempt++, this.timer = setTimeout(() => this.connect(), n);
1283
+ this.attempt++, this.attempt >= 3 && !this.everAuthed && ((o = (i = this.opts).onStatusChange) == null || o.call(i, "reconnecting", "Can't reach chat — retrying…")), this.timer = setTimeout(() => this.connect(), n);
1273
1284
  }
1274
1285
  }
1275
- function Tt(s) {
1286
+ const Tt = /* @__PURE__ */ new Set(["UNAUTHORIZED"]);
1287
+ function Ut(s) {
1288
+ switch (s) {
1289
+ case "UNAUTHORIZED":
1290
+ return "Chat unavailable — sign-in/token was rejected";
1291
+ default:
1292
+ return "Chat unavailable";
1293
+ }
1294
+ }
1295
+ function Pt(s) {
1276
1296
  return new WebSocket(s);
1277
1297
  }
1278
- const ge = 200, Ut = 7 * 864e5;
1279
- class Pt {
1298
+ const ge = 200, Bt = 7 * 864e5;
1299
+ class At {
1280
1300
  constructor(e) {
1281
1301
  a(this, "key");
1282
1302
  this.key = `ocw_outbox_${e}`;
@@ -1286,7 +1306,7 @@ class Pt {
1286
1306
  try {
1287
1307
  const e = localStorage.getItem(this.key);
1288
1308
  if (!e) return [];
1289
- const t = JSON.parse(e), n = Date.now() - Ut, i = t.filter((o) => o.ts >= n);
1309
+ const t = JSON.parse(e), n = Date.now() - Bt, i = t.filter((o) => o.ts >= n);
1290
1310
  return i.length !== t.length && this.save(i), i;
1291
1311
  } catch {
1292
1312
  return [];
@@ -1336,7 +1356,7 @@ async function _(s) {
1336
1356
  async function F(s) {
1337
1357
  return C().importKey("raw", ae(s), { name: "ECDH", namedCurve: "P-256" }, !1, []);
1338
1358
  }
1339
- async function Bt(s, e) {
1359
+ async function Kt(s, e) {
1340
1360
  const t = await F(e);
1341
1361
  return C().deriveKey(
1342
1362
  { name: "ECDH", public: t },
@@ -1346,21 +1366,21 @@ async function Bt(s, e) {
1346
1366
  ["encrypt", "decrypt"]
1347
1367
  );
1348
1368
  }
1349
- async function Kt(s, e) {
1369
+ async function zt(s, e) {
1350
1370
  const t = globalThis.crypto.getRandomValues(new Uint8Array(12)), n = new TextEncoder().encode(e), i = await C().encrypt({ name: "AES-GCM", iv: t }, s, n);
1351
1371
  return { ct: ee(i), iv: ee(t) };
1352
1372
  }
1353
- async function At(s, e, t) {
1373
+ async function Lt(s, e, t) {
1354
1374
  const n = await C().decrypt({ name: "AES-GCM", iv: ae(t) }, s, ae(e));
1355
1375
  return new TextDecoder().decode(n);
1356
1376
  }
1357
- async function zt(s) {
1377
+ async function Mt(s) {
1358
1378
  var t, n;
1359
1379
  try {
1360
1380
  const i = (t = globalThis.localStorage) == null ? void 0 : t.getItem(s);
1361
1381
  if (i) {
1362
- const { pub: o, priv: r } = JSON.parse(i), h = await C().importKey("jwk", o, { name: "ECDH", namedCurve: "P-256" }, !0, []), w = await C().importKey("jwk", r, { name: "ECDH", namedCurve: "P-256" }, !0, ["deriveKey", "deriveBits"]);
1363
- return { publicKey: h, privateKey: w };
1382
+ const { pub: o, priv: r } = JSON.parse(i), p = await C().importKey("jwk", o, { name: "ECDH", namedCurve: "P-256" }, !0, []), w = await C().importKey("jwk", r, { name: "ECDH", namedCurve: "P-256" }, !0, ["deriveKey", "deriveBits"]);
1383
+ return { publicKey: p, privateKey: w };
1364
1384
  }
1365
1385
  } catch {
1366
1386
  }
@@ -1372,11 +1392,11 @@ async function zt(s) {
1372
1392
  }
1373
1393
  return e;
1374
1394
  }
1375
- async function Lt(s, e) {
1395
+ async function Dt(s, e) {
1376
1396
  const t = await C().exportKey("raw", e), n = await C().sign({ name: "ECDSA", hash: "SHA-256" }, s, t);
1377
1397
  return ee(n);
1378
1398
  }
1379
- async function Mt() {
1399
+ async function _t() {
1380
1400
  const s = await V(), e = await C().generateKey({ name: "ECDSA", namedCurve: "P-256" }, !0, ["sign", "verify"]);
1381
1401
  return {
1382
1402
  ecdhKP: s,
@@ -1390,9 +1410,9 @@ async function be(s) {
1390
1410
  try {
1391
1411
  const i = (t = globalThis.localStorage) == null ? void 0 : t.getItem(`${s}-identity`);
1392
1412
  if (i) {
1393
- const o = JSON.parse(i), r = await C().importKey("jwk", o.ecdhPub, { name: "ECDH", namedCurve: "P-256" }, !0, []), h = await C().importKey("jwk", o.ecdhPriv, { name: "ECDH", namedCurve: "P-256" }, !0, ["deriveKey", "deriveBits"]), w = await C().importKey("jwk", o.ecdsaPub, { name: "ECDSA", namedCurve: "P-256" }, !0, ["verify"]), d = await C().importKey("jwk", o.ecdsaPriv, { name: "ECDSA", namedCurve: "P-256" }, !0, ["sign"]);
1413
+ const o = JSON.parse(i), r = await C().importKey("jwk", o.ecdhPub, { name: "ECDH", namedCurve: "P-256" }, !0, []), p = await C().importKey("jwk", o.ecdhPriv, { name: "ECDH", namedCurve: "P-256" }, !0, ["deriveKey", "deriveBits"]), w = await C().importKey("jwk", o.ecdsaPub, { name: "ECDSA", namedCurve: "P-256" }, !0, ["verify"]), d = await C().importKey("jwk", o.ecdsaPriv, { name: "ECDSA", namedCurve: "P-256" }, !0, ["sign"]);
1394
1414
  return {
1395
- ecdhKP: { publicKey: r, privateKey: h },
1415
+ ecdhKP: { publicKey: r, privateKey: p },
1396
1416
  ecdsaKP: { publicKey: w, privateKey: d },
1397
1417
  publicKeyB64: await _(r),
1398
1418
  sigPublicKeyB64: await _(w)
@@ -1400,20 +1420,20 @@ async function be(s) {
1400
1420
  }
1401
1421
  } catch {
1402
1422
  }
1403
- const e = await Mt();
1423
+ const e = await _t();
1404
1424
  try {
1405
- const i = await C().exportKey("jwk", e.ecdhKP.publicKey), o = await C().exportKey("jwk", e.ecdhKP.privateKey), r = await C().exportKey("jwk", e.ecdsaKP.publicKey), h = await C().exportKey("jwk", e.ecdsaKP.privateKey);
1406
- (n = globalThis.localStorage) == null || n.setItem(`${s}-identity`, JSON.stringify({ ecdhPub: i, ecdhPriv: o, ecdsaPub: r, ecdsaPriv: h }));
1425
+ const i = await C().exportKey("jwk", e.ecdhKP.publicKey), o = await C().exportKey("jwk", e.ecdhKP.privateKey), r = await C().exportKey("jwk", e.ecdsaKP.publicKey), p = await C().exportKey("jwk", e.ecdsaKP.privateKey);
1426
+ (n = globalThis.localStorage) == null || n.setItem(`${s}-identity`, JSON.stringify({ ecdhPub: i, ecdhPriv: o, ecdsaPub: r, ecdsaPriv: p }));
1407
1427
  } catch {
1408
1428
  }
1409
1429
  return e;
1410
1430
  }
1411
- async function Dt(s, e) {
1412
- const t = await V(), n = await _(t.publicKey), i = await F(e.identityKey), o = await F(e.signedPrekey), r = e.oneTimePrekey ? await F(e.oneTimePrekey) : null, h = await D(s.privateKey, o), w = await D(t.privateKey, i), d = await D(t.privateKey, o), v = r ? await D(t.privateKey, r) : null, x = Ee(h, w, d, ...v ? [v] : []);
1431
+ async function $t(s, e) {
1432
+ const t = await V(), n = await _(t.publicKey), i = await F(e.identityKey), o = await F(e.signedPrekey), r = e.oneTimePrekey ? await F(e.oneTimePrekey) : null, p = await D(s.privateKey, o), w = await D(t.privateKey, i), d = await D(t.privateKey, o), v = r ? await D(t.privateKey, r) : null, x = Ee(p, w, d, ...v ? [v] : []);
1413
1433
  return { sharedKey: await Te(x), ephemeralPublicKey: n };
1414
1434
  }
1415
- async function _t(s, e, t, n, i) {
1416
- const o = await F(t), r = await F(n), h = await D(e.privateKey, o), w = await D(s.privateKey, r), d = await D(e.privateKey, r), v = i ? await D(i.privateKey, r) : null, x = Ee(h, w, d, ...v ? [v] : []);
1435
+ async function Ht(s, e, t, n, i) {
1436
+ const o = await F(t), r = await F(n), p = await D(e.privateKey, o), w = await D(s.privateKey, r), d = await D(e.privateKey, r), v = i ? await D(i.privateKey, r) : null, x = Ee(p, w, d, ...v ? [v] : []);
1417
1437
  return Te(x);
1418
1438
  }
1419
1439
  async function D(s, e) {
@@ -1436,8 +1456,8 @@ async function Te(s) {
1436
1456
  ["encrypt", "decrypt"]
1437
1457
  );
1438
1458
  }
1439
- const $t = 20;
1440
- class Ht {
1459
+ const Rt = 20;
1460
+ class Ft {
1441
1461
  constructor(e) {
1442
1462
  // Live ECDH mode state
1443
1463
  a(this, "kp");
@@ -1458,19 +1478,19 @@ class Ht {
1458
1478
  }
1459
1479
  /** Live ECDH mode: Generate/restore our keypair and return our public key to publish. */
1460
1480
  async begin() {
1461
- return this.kp = await zt(this.storageKey), _(this.kp.publicKey);
1481
+ return this.kp = await Mt(this.storageKey), _(this.kp.publicKey);
1462
1482
  }
1463
1483
  /** Live ECDH mode: A peer published their key — derive the shared secret. */
1464
1484
  async onPeerKey(e) {
1465
- this.kp && (this.shared = await Bt(this.kp.privateKey, e));
1485
+ this.kp && (this.shared = await Kt(this.kp.privateKey, e));
1466
1486
  }
1467
1487
  // ── X3DH async mode ────────────────────────────────────────────────────────
1468
1488
  /** X3DH: Generate identity key, signed prekey, and OTP prekeys.
1469
1489
  * Returns the upload frame payload the caller should send to the server. */
1470
1490
  async initX3DH() {
1471
1491
  this.identityKP = await be(this.storageKey), this.signedPreKP = await V(), this.signedPrekeyId = `spk-${Date.now()}-${Math.random().toString(36).slice(2)}`;
1472
- for (let i = 0; i < $t; i++) this.otpKeys.push(await V());
1473
- const e = await _(this.signedPreKP.publicKey), t = await Lt(this.identityKP.ecdsaKP.privateKey, this.signedPreKP.publicKey), n = await Promise.all(this.otpKeys.map((i) => _(i.publicKey)));
1492
+ for (let i = 0; i < Rt; i++) this.otpKeys.push(await V());
1493
+ const e = await _(this.signedPreKP.publicKey), t = await Dt(this.identityKP.ecdsaKP.privateKey, this.signedPreKP.publicKey), n = await Promise.all(this.otpKeys.map((i) => _(i.publicKey)));
1474
1494
  return {
1475
1495
  identityKey: this.identityKP.publicKeyB64,
1476
1496
  signedPrekey: e,
@@ -1483,7 +1503,7 @@ class Ht {
1483
1503
  * return the init message fields to embed in the first encrypted message. */
1484
1504
  async x3dhSendTo(e) {
1485
1505
  this.identityKP || (this.identityKP = await be(this.storageKey));
1486
- const { sharedKey: t, ephemeralPublicKey: n } = await Dt(this.identityKP.ecdhKP, e);
1506
+ const { sharedKey: t, ephemeralPublicKey: n } = await $t(this.identityKP.ecdhKP, e);
1487
1507
  return this.x3dhShared = t, { ephemeralKey: n, spkId: e.signedPrekeyId, usedOTP: !!e.oneTimePrekey, senderIK: this.identityKP.publicKeyB64 };
1488
1508
  }
1489
1509
  /** X3DH recipient: given an init message's sender IK + EK + SPK ID, derive the shared key. */
@@ -1493,7 +1513,7 @@ class Ht {
1493
1513
  return;
1494
1514
  }
1495
1515
  const i = this.otpKeys.shift();
1496
- this.x3dhShared = await _t(this.identityKP.ecdhKP, this.signedPreKP, e, t, i);
1516
+ this.x3dhShared = await Ht(this.identityKP.ecdhKP, this.signedPreKP, e, t, i);
1497
1517
  }
1498
1518
  /** Flush pending X3DH derivation after initX3DH() completes. */
1499
1519
  async flushPendingX3DH() {
@@ -1506,7 +1526,7 @@ class Ht {
1506
1526
  async sealText(e, t) {
1507
1527
  const n = this.x3dhShared ?? this.shared;
1508
1528
  if (!n) throw new Error("secure channel not ready");
1509
- const { ct: i, iv: o } = await Kt(n, e);
1529
+ const { ct: i, iv: o } = await zt(n, e);
1510
1530
  return {
1511
1531
  kind: "text",
1512
1532
  text: i,
@@ -1521,7 +1541,7 @@ class Ht {
1521
1541
  const t = this.x3dhShared ?? this.shared;
1522
1542
  if (!t) return { kind: "text", text: "🔒 encrypted" };
1523
1543
  try {
1524
- return { kind: "text", text: await At(t, e.text, e.iv) };
1544
+ return { kind: "text", text: await Lt(t, e.text, e.iv) };
1525
1545
  } catch {
1526
1546
  return { kind: "text", text: "🔒 unable to decrypt" };
1527
1547
  }
@@ -1533,12 +1553,12 @@ class Ht {
1533
1553
  for (const t of e.messages) t.content = await this.openContent(t.content);
1534
1554
  }
1535
1555
  }
1536
- function Rt(s) {
1556
+ function jt(s) {
1537
1557
  if (s.kind !== "text" || !s.enc) return null;
1538
1558
  const e = s;
1539
1559
  return !e.x3dhEK || !e.x3dhSPK || !e.x3dhIK ? null : { x3dhEK: e.x3dhEK, x3dhSPK: e.x3dhSPK, x3dhIK: e.x3dhIK };
1540
1560
  }
1541
- const me = "objectchat-widget-styles", Ft = ["👍", "❤️", "😂", "😮", "😢", "🙏"], jt = `
1561
+ const me = "objectchat-widget-styles", qt = ["👍", "❤️", "😂", "😮", "😢", "🙏"], Ot = `
1542
1562
  .ocw { --ocw-accent:#4F63F5; --ocw-bg:#f3efe9; --ocw-card:#fff; --ocw-line:#ececec; --ocw-ink:#1c1b1a; --ocw-mut:#9b9690;
1543
1563
  position:relative;
1544
1564
  display:flex; flex-direction:column; height:100%; min-height:320px; background:var(--ocw-bg);
@@ -1623,6 +1643,7 @@ const me = "objectchat-widget-styles", Ft = ["👍", "❤️", "😂", "😮", "
1623
1643
  .ocw-appt-btn-sec { background:#fff; color:var(--ocw-accent); border:1px solid var(--ocw-accent); }
1624
1644
  .ocw-conn-status { font-size:10px; color:var(--ocw-mut); margin-left:4px; }
1625
1645
  .ocw-conn-status.warn { color:#e67e22; }
1646
+ .ocw-conn-status.err { color:#c0392b; font-weight:600; }
1626
1647
  .ocw-load-more { display:block; width:100%; background:none; border:1px solid #e3ded7; border-radius:10px; padding:6px 0; font-size:12px; color:var(--ocw-mut); cursor:pointer; margin-bottom:8px; }
1627
1648
  .ocw-load-more:hover { border-color:var(--ocw-accent); color:var(--ocw-accent); }
1628
1649
  .ocw-offline { margin:20px 14px; padding:20px; background:#fff; border:1px solid #e3ded7; border-radius:16px; text-align:center; }
@@ -1697,16 +1718,16 @@ const me = "objectchat-widget-styles", Ft = ["👍", "❤️", "😂", "😮", "
1697
1718
  .ocw-bubble-wrap:hover .ocw-translate-btn { opacity:1; }
1698
1719
  .ocw-translated-tag { font-size:10px; color:var(--ocw-mut); margin-top:2px; }
1699
1720
  `;
1700
- function qt() {
1721
+ function Nt() {
1701
1722
  if (typeof document > "u" || document.getElementById(me)) return;
1702
1723
  const s = document.createElement("style");
1703
- s.id = me, s.textContent = jt, document.head.appendChild(s);
1724
+ s.id = me, s.textContent = Ot, document.head.appendChild(s);
1704
1725
  }
1705
1726
  function c(s, e, t) {
1706
1727
  const n = document.createElement(s);
1707
1728
  return e && (n.className = e), t !== void 0 && (n.textContent = t), n;
1708
1729
  }
1709
- function Ot(s) {
1730
+ function Vt(s) {
1710
1731
  try {
1711
1732
  return new Date(s).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
1712
1733
  } catch {
@@ -1730,7 +1751,7 @@ function se(s) {
1730
1751
  return `📅 ${s.title} — ${new Date(s.startIso).toLocaleString()}`;
1731
1752
  }
1732
1753
  }
1733
- class Nt {
1754
+ class Wt {
1734
1755
  /** Last seq the guest has seen per conversationId — used to compute unread badges. */
1735
1756
  constructor(e, t, n, i = {}) {
1736
1757
  a(this, "scroll");
@@ -1763,8 +1784,8 @@ class Nt {
1763
1784
  a(this, "translationCache", /* @__PURE__ */ new Map());
1764
1785
  a(this, "showingTranslation", /* @__PURE__ */ new Set());
1765
1786
  a(this, "subjectBuilt", !1);
1766
- var m, g, U, K, P, A, b, S, M;
1767
- this.root = e, this.me = t, this.h = n, this.cfg = i, qt(), e.replaceChildren(), e.classList.add("ocw"), i.accent && e.style.setProperty("--ocw-accent", i.accent);
1787
+ var m, g, U, A, P, K, b, S, M;
1788
+ this.root = e, this.me = t, this.h = n, this.cfg = i, Nt(), e.replaceChildren(), e.classList.add("ocw"), i.accent && e.style.setProperty("--ocw-accent", i.accent);
1768
1789
  const o = c("div", "ocw-head"), r = c("div", "ocw-avatar");
1769
1790
  if ((m = i.userInfo) != null && m.avatar) {
1770
1791
  const k = document.createElement("img");
@@ -1772,8 +1793,8 @@ class Nt {
1772
1793
  } else
1773
1794
  r.textContent = (g = i.userInfo) != null && g.name ? i.userInfo.name[0].toUpperCase() : "🧑";
1774
1795
  o.append(r);
1775
- const h = c("div", "ocw-head-main");
1776
- this.headerName = c("div", "ocw-head-name", ((U = i.subject) == null ? void 0 : U.ownerLabel) ?? ((K = i.subject) == null ? void 0 : K.title) ?? ""), h.append(this.headerName), (P = i.subject) != null && P.subtitle && h.append(c("div", "ocw-head-meta", i.subject.subtitle)), o.append(h), this.statusBadge = c("span", "ocw-badge", ((A = i.subject) == null ? void 0 : A.status) ?? ""), (b = i.subject) != null && b.status || (this.statusBadge.style.display = "none"), o.append(this.statusBadge), this.e2eBadge = c("span", "ocw-e2e", "🔒 E2E"), this.e2eBadge.style.display = "none", o.append(this.e2eBadge), this.connStatus = c("span", "ocw-conn-status"), this.connStatus.style.display = "none", o.append(this.connStatus), this.cobrowseBtn = c("button", "ocw-menu ocw-cobrowse-btn", "🖍"), this.cobrowseBtn.title = "Shared whiteboard — draw to point things out together", this.cobrowseBtn.addEventListener("click", () => {
1796
+ const p = c("div", "ocw-head-main");
1797
+ this.headerName = c("div", "ocw-head-name", ((U = i.subject) == null ? void 0 : U.ownerLabel) ?? ((A = i.subject) == null ? void 0 : A.title) ?? ""), p.append(this.headerName), (P = i.subject) != null && P.subtitle && p.append(c("div", "ocw-head-meta", i.subject.subtitle)), o.append(p), this.statusBadge = c("span", "ocw-badge", ((K = i.subject) == null ? void 0 : K.status) ?? ""), (b = i.subject) != null && b.status || (this.statusBadge.style.display = "none"), o.append(this.statusBadge), this.e2eBadge = c("span", "ocw-e2e", "🔒 E2E"), this.e2eBadge.style.display = "none", o.append(this.e2eBadge), this.connStatus = c("span", "ocw-conn-status"), this.connStatus.style.display = "none", o.append(this.connStatus), this.cobrowseBtn = c("button", "ocw-menu ocw-cobrowse-btn", "🖍"), this.cobrowseBtn.title = "Shared whiteboard — draw to point things out together", this.cobrowseBtn.addEventListener("click", () => {
1777
1798
  this.cobrowseActive = !this.cobrowseActive, this.updateCobrowseUI();
1778
1799
  }), o.append(this.cobrowseBtn), o.append(c("button", "ocw-menu", "⋯")), this.chips = c("div", "ocw-chiprow"), this.scroll = c("div", "ocw-scroll"), this.subjectCard = c("div", "ocw-subject"), this.typing = c("div", "ocw-typing");
1779
1800
  const w = c("div", "ocw-typing-bubble");
@@ -1847,7 +1868,7 @@ class Nt {
1847
1868
  const f = (d = this.cfg.subject) == null ? void 0 : d.ownerLabel;
1848
1869
  f && (this.headerName.textContent = f);
1849
1870
  }
1850
- this.chips.replaceChildren();
1871
+ this.quick.style.display = e.messages().length === 0 ? "flex" : "none", this.chips.replaceChildren();
1851
1872
  const t = e.visibleActions();
1852
1873
  this.chips.style.display = t.length ? "flex" : "none";
1853
1874
  for (const f of t) this.chips.append(this.chipEl(f));
@@ -1862,21 +1883,23 @@ class Nt {
1862
1883
  i > 20 ? this.scroll.scrollTop = this.scroll.scrollHeight - n + i : this.scroll.scrollTop = this.scroll.scrollHeight, o > 0 && this.h.onReadUpTo(o);
1863
1884
  const r = [...e.typing];
1864
1885
  this.typing.classList.toggle("active", r.length > 0);
1865
- const h = this.typing.querySelector(".ocw-typing-bubble");
1866
- h && h.setAttribute("aria-label", r.length ? "typing" : ""), this.footer.style.display = e.whiteLabel ? "none" : "block", e.offline ? (this.offlinePanel.style.display === "none" && this.buildOfflinePanel(e.offlineMessage), this.offlinePanel.style.display = "block", (v = this.root.querySelector(".ocw-input")) == null || v.style.setProperty("display", "none")) : (this.offlinePanel.style.display = "none", (x = this.root.querySelector(".ocw-input")) == null || x.style.removeProperty("display"));
1886
+ const p = this.typing.querySelector(".ocw-typing-bubble");
1887
+ p && p.setAttribute("aria-label", r.length ? "typing" : ""), this.footer.style.display = e.whiteLabel ? "none" : "block", e.offline ? (this.offlinePanel.style.display === "none" && this.buildOfflinePanel(e.offlineMessage), this.offlinePanel.style.display = "block", (v = this.root.querySelector(".ocw-input")) == null || v.style.setProperty("display", "none")) : (this.offlinePanel.style.display = "none", (x = this.root.querySelector(".ocw-input")) == null || x.style.removeProperty("display"));
1867
1888
  const w = ["resolved", "closed", "sold", "issued", "checked_out"];
1868
1889
  this.h.onCsat && !this.csatSubmitted && w.includes(e.state) && e.messages().length > 0 && (this.csatPanel.style.display === "none" && this.buildCsatPanel(), this.csatPanel.style.display = "block");
1869
1890
  }
1870
- setConnStatus(e) {
1891
+ setConnStatus(e, t) {
1871
1892
  if (e === "open") {
1872
1893
  this.connStatus.style.display = "none";
1873
1894
  return;
1874
1895
  }
1875
- this.connStatus.style.display = "", this.connStatus.className = `ocw-conn-status${e === "reconnecting" ? " warn" : ""}`, this.connStatus.textContent = e === "reconnecting" ? "↻ reconnecting…" : "● connecting…";
1896
+ this.connStatus.style.display = "";
1897
+ const n = e === "error";
1898
+ this.connStatus.className = `ocw-conn-status${n ? " err" : e === "reconnecting" ? " warn" : ""}`, this.connStatus.textContent = n ? `⚠ ${t ?? "Chat unavailable"}` : e === "reconnecting" ? t ?? "↻ reconnecting…" : "● connecting…";
1876
1899
  }
1877
1900
  buildOfflinePanel(e) {
1878
- var h;
1879
- this.offlinePanel.replaceChildren(), this.offlinePanel.append(c("div", "ocw-offline-icon", "🌙")), this.offlinePanel.append(c("div", "ocw-offline-title", ((h = this.cfg.i18n) == null ? void 0 : h.offline) ?? "We're offline right now")), this.offlinePanel.append(c("div", "ocw-offline-msg", e || "Leave your details and we'll get back to you soon."));
1901
+ var p;
1902
+ this.offlinePanel.replaceChildren(), this.offlinePanel.append(c("div", "ocw-offline-icon", "🌙")), this.offlinePanel.append(c("div", "ocw-offline-title", ((p = this.cfg.i18n) == null ? void 0 : p.offline) ?? "We're offline right now")), this.offlinePanel.append(c("div", "ocw-offline-msg", e || "Leave your details and we'll get back to you soon."));
1880
1903
  const t = c("div", "ocw-offline-form"), n = c("input", "ocw-offline-input");
1881
1904
  n.placeholder = "Your name", n.type = "text";
1882
1905
  const i = c("input", "ocw-offline-input");
@@ -1933,7 +1956,7 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(c("div", "ocw-offline-t
1933
1956
  bindCobrowsePointerEvents() {
1934
1957
  let e = !1, t = [];
1935
1958
  const n = (r) => {
1936
- const h = this.cobrowseCanvas.getBoundingClientRect(), w = h.width > 0 ? (r.clientX - h.left) / h.width : 0, d = h.height > 0 ? (r.clientY - h.top) / h.height : 0;
1959
+ const p = this.cobrowseCanvas.getBoundingClientRect(), w = p.width > 0 ? (r.clientX - p.left) / p.width : 0, d = p.height > 0 ? (r.clientY - p.top) / p.height : 0;
1937
1960
  return { x: Math.min(1, Math.max(0, w)), y: Math.min(1, Math.max(0, d)) };
1938
1961
  }, i = 6e-3;
1939
1962
  this.cobrowseCanvas.addEventListener("pointerdown", (r) => {
@@ -1942,9 +1965,9 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(c("div", "ocw-offline-t
1942
1965
  e && (t.push(n(r)), this.redrawCobrowse(), this.drawStroke({ points: t, color: this.cobrowseColor, width: i }));
1943
1966
  });
1944
1967
  const o = (r) => {
1945
- var h, w;
1968
+ var p, w;
1946
1969
  if (e) {
1947
- e = !1, t.length > 1 && ((w = (h = this.h).onAnnotate) == null || w.call(h, { id: `an_${Date.now()}_${Math.random().toString(36).slice(2)}`, points: t, color: this.cobrowseColor, width: i })), t = [];
1970
+ e = !1, t.length > 1 && ((w = (p = this.h).onAnnotate) == null || w.call(p, { id: `an_${Date.now()}_${Math.random().toString(36).slice(2)}`, points: t, color: this.cobrowseColor, width: i })), t = [];
1948
1971
  try {
1949
1972
  this.cobrowseCanvas.releasePointerCapture(r.pointerId);
1950
1973
  } catch {
@@ -1959,8 +1982,8 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(c("div", "ocw-offline-t
1959
1982
  if (!i) return;
1960
1983
  this.subjectBuilt = !0, this.subjectCard.replaceChildren(), this.subjectCard.append(c("div", "ocw-subject-title", i)), n != null && n.subtitle && this.subjectCard.append(c("div", "ocw-subject-sub", n.subtitle));
1961
1984
  const o = c("div", "ocw-tags");
1962
- if (t) for (const [h, w] of Object.entries(t.fields)) o.append(c("span", "ocw-tag", `${h}: ${w}`));
1963
- else for (const h of (n == null ? void 0 : n.tags) ?? []) o.append(c("span", "ocw-tag", h));
1985
+ if (t) for (const [p, w] of Object.entries(t.fields)) o.append(c("span", "ocw-tag", `${p}: ${w}`));
1986
+ else for (const p of (n == null ? void 0 : n.tags) ?? []) o.append(c("span", "ocw-tag", p));
1964
1987
  o.childNodes.length && this.subjectCard.append(o);
1965
1988
  const r = (t == null ? void 0 : t.state) ?? (n == null ? void 0 : n.status);
1966
1989
  r && (this.statusBadge.textContent = r, this.statusBadge.style.display = "inline-flex");
@@ -1977,25 +2000,25 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(c("div", "ocw-offline-t
1977
2000
  return new Promise((t) => {
1978
2001
  const n = c("div", "ocw-modal"), i = c("div", "ocw-modal-card");
1979
2002
  i.append(c("div", "ocw-modal-title", e)), i.append(c("div", "ocw-modal-body", `Confirm “${e}”?`));
1980
- const o = c("div", "ocw-modal-actions"), r = c("button", "ocw-modal-cancel", "Cancel"), h = c("button", "ocw-modal-ok", "Confirm"), w = (d) => {
2003
+ const o = c("div", "ocw-modal-actions"), r = c("button", "ocw-modal-cancel", "Cancel"), p = c("button", "ocw-modal-ok", "Confirm"), w = (d) => {
1981
2004
  n.remove(), t(d);
1982
2005
  };
1983
- r.addEventListener("click", () => w(!1)), h.addEventListener("click", () => w(!0)), n.addEventListener("click", (d) => {
2006
+ r.addEventListener("click", () => w(!1)), p.addEventListener("click", () => w(!0)), n.addEventListener("click", (d) => {
1984
2007
  d.target === n && w(!1);
1985
- }), o.append(r, h), i.append(o), n.append(i), this.root.append(n), h.focus();
2008
+ }), o.append(r, p), i.append(o), n.append(i), this.root.append(n), p.focus();
1986
2009
  });
1987
2010
  }
1988
2011
  /** Inline form for a form-effect action: typed inputs (date picker, number,
1989
2012
  * text) rendered above the composer — no browser prompts. */
1990
2013
  openForm(e) {
1991
- var h, w;
2014
+ var p, w;
1992
2015
  this.formHost.replaceChildren();
1993
2016
  const t = c("div", "ocw-form");
1994
2017
  t.append(c("div", "ocw-form-title", e.icon ? `${e.icon} ${e.label}` : e.label));
1995
2018
  const n = /* @__PURE__ */ new Map();
1996
2019
  for (const d of e.input ?? []) {
1997
2020
  const v = c("label", "ocw-form-row");
1998
- if (v.append(c("span", "ocw-form-lbl", d.label)), d.type === "select" && ((h = d.options) != null && h.length)) {
2021
+ if (v.append(c("span", "ocw-form-lbl", d.label)), d.type === "select" && ((p = d.options) != null && p.length)) {
1999
2022
  const x = c("select", "ocw-form-input");
2000
2023
  d.required || x.append(c("option", void 0, "— select —"));
2001
2024
  for (const f of d.options) {
@@ -2030,7 +2053,7 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(c("div", "ocw-offline-t
2030
2053
  }
2031
2054
  const n = e.senderId === this.me, i = !!e.internal, o = c("div", `ocw-row ${i ? "ocw-note mine" : n ? "mine" : "theirs"} ${e.senderRole === "bot" ? "ocw-bot" : ""}`);
2032
2055
  !n && !i && o.append(c("div", "ocw-dot", e.senderRole === "bot" ? "🤖" : "🧑"));
2033
- const r = c("div"), h = c("div", "ocw-bubble-wrap");
2056
+ const r = c("div"), p = c("div", "ocw-bubble-wrap");
2034
2057
  if (e.replyToId) {
2035
2058
  const f = c("div", "ocw-reply-to", "↩ replying to a message");
2036
2059
  f.style.cssText = "font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic", r.append(f);
@@ -2056,7 +2079,7 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(c("div", "ocw-offline-t
2056
2079
  g.href = f.icalUrl, g.download = `${f.title}.ics`, g.className = "ocw-appt-btn ocw-appt-btn-sec", g.textContent = "🍎 Apple / iCal", I.append(m, g), u.append(I), w.append(u);
2057
2080
  } else
2058
2081
  d = document.createTextNode(se(e.content)), w.append(d), e.editedAt && w.append(c("span", "ocw-edited", "(edited)"));
2059
- if (h.append(w), !n && !i && this.h.onTranslate && e.content.kind === "text" && !e.deletedAt && e.seq > 0 && d) {
2082
+ if (p.append(w), !n && !i && this.h.onTranslate && e.content.kind === "text" && !e.deletedAt && e.seq > 0 && d) {
2060
2083
  const f = e.content.text;
2061
2084
  if (f.trim()) {
2062
2085
  const u = c("button", "ocw-translate-btn", "🌐");
@@ -2079,7 +2102,7 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(c("div", "ocw-offline-t
2079
2102
  }
2080
2103
  this.translationCache.set(e.id, g), this.showingTranslation.add(e.id), d.textContent = g, u.textContent = "↩", u.title = "Show original";
2081
2104
  });
2082
- }), h.append(u);
2105
+ }), p.append(u);
2083
2106
  }
2084
2107
  }
2085
2108
  if (n && !e.deletedAt && e.seq > 0 && (this.h.onEdit ?? this.h.onDelete)) {
@@ -2092,14 +2115,14 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(c("div", "ocw-offline-t
2092
2115
  g.value = m, g.rows = Math.min(4, Math.ceil(m.length / 40) + 1), g.style.cssText = "width:100%;resize:vertical;border:1px solid var(--ocw-accent);border-radius:8px;padding:6px 10px;font:inherit;font-size:14px;background:#fff;color:#1c1b1a;box-sizing:border-box";
2093
2116
  const U = c("button", "ocw-form-submit", "Save");
2094
2117
  U.style.cssText = "margin-top:6px;padding:5px 14px;font-size:13px";
2095
- const K = c("button", "ocw-form-cancel", "Cancel");
2096
- K.style.cssText = "margin-top:6px;padding:5px 10px;font-size:13px";
2118
+ const A = c("button", "ocw-form-cancel", "Cancel");
2119
+ A.style.cssText = "margin-top:6px;padding:5px 10px;font-size:13px";
2097
2120
  const P = c("div");
2098
- P.style.cssText = "display:flex;gap:6px;justify-content:flex-end", P.append(K, U);
2099
- const A = c("div");
2100
- A.append(g, P), w.replaceChildren(A), g.focus(), g.select();
2121
+ P.style.cssText = "display:flex;gap:6px;justify-content:flex-end", P.append(A, U);
2122
+ const K = c("div");
2123
+ K.append(g, P), w.replaceChildren(K), g.focus(), g.select();
2101
2124
  const b = () => w.replaceChildren(d ?? document.createTextNode(m));
2102
- K.addEventListener("click", b), U.addEventListener("click", () => {
2125
+ A.addEventListener("click", b), U.addEventListener("click", () => {
2103
2126
  const S = g.value.trim();
2104
2127
  S && S !== m && this.h.onEdit(e.id, S), b();
2105
2128
  }), g.addEventListener("keydown", (S) => {
@@ -2113,25 +2136,25 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(c("div", "ocw-offline-t
2113
2136
  I.stopPropagation(), this.h.onDelete(e.id);
2114
2137
  }), f.append(u);
2115
2138
  }
2116
- h.append(f);
2139
+ p.append(f);
2117
2140
  }
2118
- if (r.append(h), this.h.onReact && !e.deletedAt && e.seq > 0) {
2141
+ if (r.append(p), this.h.onReact && !e.deletedAt && e.seq > 0) {
2119
2142
  const f = c("div", "ocw-react-wrap"), u = c("div", "ocw-react");
2120
2143
  if (e.reactions && Object.keys(e.reactions).length)
2121
2144
  for (const [g, U] of Object.entries(e.reactions)) {
2122
- const K = c("button", `ocw-react-pill${U.includes(this.me) ? " mine" : ""}`, `${g} ${U.length}`);
2123
- K.addEventListener("click", () => {
2124
- var P, A;
2125
- return (A = (P = this.h).onReact) == null ? void 0 : A.call(P, e.id, g, U.includes(this.me));
2126
- }), u.append(K);
2145
+ const A = c("button", `ocw-react-pill${U.includes(this.me) ? " mine" : ""}`, `${g} ${U.length}`);
2146
+ A.addEventListener("click", () => {
2147
+ var P, K;
2148
+ return (K = (P = this.h).onReact) == null ? void 0 : K.call(P, e.id, g, U.includes(this.me));
2149
+ }), u.append(A);
2127
2150
  }
2128
2151
  const I = c("button", "ocw-react-btn", "+"), m = c("div", "ocw-react-picker");
2129
- for (const g of Ft) {
2152
+ for (const g of qt) {
2130
2153
  const U = c("button", void 0, g);
2131
- U.addEventListener("click", (K) => {
2132
- var A, b, S, M;
2133
- K.stopPropagation();
2134
- const P = (b = (A = e.reactions) == null ? void 0 : A[g]) == null ? void 0 : b.includes(this.me);
2154
+ U.addEventListener("click", (A) => {
2155
+ var K, b, S, M;
2156
+ A.stopPropagation();
2157
+ const P = (b = (K = e.reactions) == null ? void 0 : K[g]) == null ? void 0 : b.includes(this.me);
2135
2158
  (M = (S = this.h).onReact) == null || M.call(S, e.id, g, !!P), m.style.display = "none";
2136
2159
  }), m.append(U);
2137
2160
  }
@@ -2141,15 +2164,15 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(c("div", "ocw-offline-t
2141
2164
  m.style.display = "none";
2142
2165
  }, { once: !0 }), u.append(I), f.append(u, m), r.append(f);
2143
2166
  } else e.reactions && Object.keys(e.reactions).length && r.append(c("div", "ocw-react", Object.entries(e.reactions).map(([f, u]) => `${f}${u.length}`).join(" ")));
2144
- const v = c("div", "ocw-time ocw-meta", Ot(e.ts));
2167
+ const v = c("div", "ocw-time ocw-meta", Vt(e.ts));
2145
2168
  if (n && e.status) {
2146
- const f = c("span", `ocw-tick${e.status === "read" ? " read" : e.status === "delivered" ? " delivered" : ""}`, Vt(e.status));
2169
+ const f = c("span", `ocw-tick${e.status === "read" ? " read" : e.status === "delivered" ? " delivered" : ""}`, Xt(e.status));
2147
2170
  v.append(f);
2148
2171
  }
2149
2172
  return n && e.seq > 0 && t.lastReadByOthers >= e.seq && v.append(c("span", "ocw-seen", " · Seen")), r.append(v), o.append(r), o;
2150
2173
  }
2151
2174
  }
2152
- function Vt(s) {
2175
+ function Xt(s) {
2153
2176
  switch (s) {
2154
2177
  case "read":
2155
2178
  return "✓✓";
@@ -2161,27 +2184,27 @@ function Vt(s) {
2161
2184
  return "🕓";
2162
2185
  }
2163
2186
  }
2164
- const H = /* @__PURE__ */ new WeakMap(), Q = /* @__PURE__ */ new Map();
2187
+ const H = /* @__PURE__ */ new WeakMap(), Z = /* @__PURE__ */ new Map();
2165
2188
  function ve(s) {
2166
2189
  return `relay-launcher::${s.profileId}::${s.subjectId ?? ""}`;
2167
2190
  }
2168
- function Jt(s) {
2191
+ function Zt(s) {
2169
2192
  var e;
2170
2193
  (e = H.get(s)) == null || e.close(), H.delete(s);
2171
2194
  }
2172
- function Gt(s) {
2195
+ function Qt(s) {
2173
2196
  var he, pe, ue, fe, we;
2174
- H.has(s.el) && (H.get(s.el).close(), H.delete(s.el)), s.launcher && ((he = Q.get(ve(s))) == null || he.close());
2197
+ H.has(s.el) && (H.get(s.el).close(), H.delete(s.el)), s.launcher && ((he = Z.get(ve(s))) == null || he.close());
2175
2198
  const e = $e(), t = s.token ?? s.userId ?? e, n = t !== e ? e : void 0, { wsUrl: i, httpBase: o } = He(s.url, s.apiUrl);
2176
2199
  let r = new Ct(t);
2177
- const h = s.subjectId ? `${t}::${s.subjectId}` : t, w = new Pt(h);
2200
+ const p = s.subjectId ? `${t}::${s.subjectId}` : t, w = new At(p);
2178
2201
  let d, v = !1, x = null, f = null;
2179
2202
  !s.launcher && !s.el.style.height && s.el.clientHeight === 0 && (s.el.style.width = s.el.style.width || "100%", s.el.style.height = "600px");
2180
2203
  for (const l of w.load()) r.addOptimistic(l.clientMsgId, l.content);
2181
2204
  let u = null, I = null, m = 0, g = !s.launcher;
2182
2205
  if (s.launcher) {
2183
- const p = (s.position ?? "bottom-right").includes("right");
2184
- u = document.createElement("div"), u.style.cssText = `position:fixed;${p ? "right:20px" : "left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${p ? "flex-end" : "flex-start"};gap:12px`;
2206
+ const h = (s.position ?? "bottom-right").includes("right");
2207
+ u = document.createElement("div"), u.style.cssText = `position:fixed;${h ? "right:20px" : "left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${h ? "flex-end" : "flex-start"};gap:12px`;
2185
2208
  const y = document.createElement("div"), E = typeof window < "u" ? window.matchMedia("(max-width: 479px)") : null, R = ($) => {
2186
2209
  y.style.cssText = $ ? [
2187
2210
  "position:fixed",
@@ -2206,7 +2229,7 @@ function Gt(s) {
2206
2229
  "display:none",
2207
2230
  "flex-direction:column",
2208
2231
  "background:#fff",
2209
- "transform-origin:bottom " + (p ? "right" : "left"),
2232
+ "transform-origin:bottom " + (h ? "right" : "left"),
2210
2233
  "transition:opacity .18s,transform .18s",
2211
2234
  "opacity:0",
2212
2235
  "transform:scale(.95)"
@@ -2243,29 +2266,29 @@ function Gt(s) {
2243
2266
  }
2244
2267
  const U = () => {
2245
2268
  g || (m++, I && (I.textContent = String(m), I.style.display = "flex"));
2246
- }, K = () => {
2269
+ }, A = () => {
2247
2270
  try {
2248
- const l = new AudioContext(), p = l.createOscillator(), y = l.createGain();
2249
- p.connect(y), y.connect(l.destination), p.frequency.setValueAtTime(880, l.currentTime), p.frequency.exponentialRampToValueAtTime(440, l.currentTime + 0.15), y.gain.setValueAtTime(0.3, l.currentTime), y.gain.exponentialRampToValueAtTime(1e-3, l.currentTime + 0.3), p.start(), p.stop(l.currentTime + 0.3);
2271
+ const l = new AudioContext(), h = l.createOscillator(), y = l.createGain();
2272
+ h.connect(y), y.connect(l.destination), h.frequency.setValueAtTime(880, l.currentTime), h.frequency.exponentialRampToValueAtTime(440, l.currentTime + 0.15), y.gain.setValueAtTime(0.3, l.currentTime), y.gain.exponentialRampToValueAtTime(1e-3, l.currentTime + 0.3), h.start(), h.stop(l.currentTime + 0.3);
2250
2273
  } catch {
2251
2274
  }
2252
- }, P = [], A = (l) => {
2275
+ }, P = [], K = (l) => {
2253
2276
  for (; P.length; ) {
2254
- const p = P.shift();
2255
- w.add({ clientMsgId: p.clientMsgId, content: p.content, ts: Date.now() }), b.send({ type: "send", conversationId: l, clientMsgId: p.clientMsgId, content: p.content });
2277
+ const h = P.shift();
2278
+ w.add({ clientMsgId: h.clientMsgId, content: h.content, ts: Date.now() }), b.send({ type: "send", conversationId: l, clientMsgId: h.clientMsgId, content: h.content });
2256
2279
  }
2257
2280
  };
2258
2281
  let b;
2259
- const S = new Ht(`ocw-e2e-${s.profileId}`);
2282
+ const S = new Ft(`ocw-e2e-${s.profileId}`);
2260
2283
  let M = !1;
2261
2284
  const k = [], T = [];
2262
2285
  let W = !1;
2263
- const ne = (l, p) => {
2264
- S.sealText(p).then((y) => {
2286
+ const ne = (l, h) => {
2287
+ S.sealText(h).then((y) => {
2265
2288
  d && b.send({ type: "send", conversationId: d, clientMsgId: l, content: y });
2266
2289
  });
2267
- }, Ue = (l, p, y) => {
2268
- S.sealText(p, y).then((E) => {
2290
+ }, Ue = (l, h, y) => {
2291
+ S.sealText(h, y).then((E) => {
2269
2292
  d && b.send({ type: "send", conversationId: d, clientMsgId: l, content: E });
2270
2293
  });
2271
2294
  }, Pe = () => {
@@ -2279,19 +2302,19 @@ function Gt(s) {
2279
2302
  }
2280
2303
  }, Be = (l) => {
2281
2304
  b.send({ type: "fetchPrekey", targetUserId: l });
2282
- }, Ke = s.i18n ?? {}, Ae = ["ar", "he", "fa", "ur"], ze = typeof navigator < "u" ? (navigator.language ?? "").slice(0, 2).toLowerCase() : "";
2283
- Ae.includes(ze) && !s.el.dir && (s.el.dir = "rtl", s.el.style.fontFamily = s.el.style.fontFamily || "Tahoma,Arial,system-ui,sans-serif");
2284
- const L = new Nt(s.el, t, {
2305
+ }, Ae = s.i18n ?? {}, Ke = ["ar", "he", "fa", "ur"], ze = typeof navigator < "u" ? (navigator.language ?? "").slice(0, 2).toLowerCase() : "";
2306
+ Ke.includes(ze) && !s.el.dir && (s.el.dir = "rtl", s.el.style.fontFamily = s.el.style.fontFamily || "Tahoma,Arial,system-ui,sans-serif");
2307
+ const L = new Wt(s.el, t, {
2285
2308
  onSend(l) {
2286
- const p = `cm_${Math.random().toString(36).slice(2)}`, y = { kind: "text", text: l };
2287
- r.addOptimistic(p, y), L.render(r), r.e2e ? S.ready ? ne(p, l) : W ? T.push({ clientMsgId: p, text: l }) : (k.push({ clientMsgId: p, text: l }), r.assignedAgentId && Be(r.assignedAgentId)) : d ? (w.add({ clientMsgId: p, content: y, ts: Date.now() }), b.send({ type: "send", conversationId: d, clientMsgId: p, content: y })) : P.push({ clientMsgId: p, content: y });
2309
+ const h = `cm_${Math.random().toString(36).slice(2)}`, y = { kind: "text", text: l };
2310
+ r.addOptimistic(h, y), L.render(r), r.e2e ? S.ready ? ne(h, l) : W ? T.push({ clientMsgId: h, text: l }) : (k.push({ clientMsgId: h, text: l }), r.assignedAgentId && Be(r.assignedAgentId)) : d ? (w.add({ clientMsgId: h, content: y, ts: Date.now() }), b.send({ type: "send", conversationId: d, clientMsgId: h, content: y })) : P.push({ clientMsgId: h, content: y });
2288
2311
  },
2289
2312
  async onAttach(l) {
2290
2313
  if (!d) return;
2291
- const p = `${o}/upload?name=${encodeURIComponent(l.name)}`, y = `cm_${Math.random().toString(36).slice(2)}`;
2314
+ const h = `${o}/upload?name=${encodeURIComponent(l.name)}`, y = `cm_${Math.random().toString(36).slice(2)}`;
2292
2315
  r.addOptimistic(y, { kind: "text", text: `📎 Uploading ${l.name}…` }), L.render(r);
2293
2316
  try {
2294
- const E = await fetch(p, {
2317
+ const E = await fetch(h, {
2295
2318
  method: "POST",
2296
2319
  headers: { "content-type": l.type, ...s.token ? { authorization: `Bearer ${s.token}` } : {} },
2297
2320
  body: l
@@ -2303,11 +2326,11 @@ function Gt(s) {
2303
2326
  r.addOptimistic(y, { kind: "text", text: `⚠️ Upload failed: ${E.message}` }), L.render(r);
2304
2327
  }
2305
2328
  },
2306
- onInvoke(l, p) {
2307
- d && b.send({ type: "invoke", conversationId: d, actionId: l, clientInvokeId: `iv_${Math.random().toString(36).slice(2)}`, ...p ? { inputs: p } : {} });
2329
+ onInvoke(l, h) {
2330
+ d && b.send({ type: "invoke", conversationId: d, actionId: l, clientInvokeId: `iv_${Math.random().toString(36).slice(2)}`, ...h ? { inputs: h } : {} });
2308
2331
  },
2309
- onTyping(l, p) {
2310
- d && b.send({ type: "typing", conversationId: d, isTyping: l, ...p ? { preview: p } : {} });
2332
+ onTyping(l, h) {
2333
+ d && b.send({ type: "typing", conversationId: d, isTyping: l, ...h ? { preview: h } : {} });
2311
2334
  },
2312
2335
  onReadUpTo(l) {
2313
2336
  d && b.send({ type: "read", conversationId: d, seq: l });
@@ -2317,14 +2340,14 @@ function Gt(s) {
2317
2340
  const l = r.messages()[0];
2318
2341
  l && b.send({ type: "history", conversationId: d, beforeSeq: l.seq, limit: 20 });
2319
2342
  },
2320
- onEdit(l, p) {
2321
- d && b.send({ type: "edit", conversationId: d, messageId: l, content: { kind: "text", text: p } });
2343
+ onEdit(l, h) {
2344
+ d && b.send({ type: "edit", conversationId: d, messageId: l, content: { kind: "text", text: h } });
2322
2345
  },
2323
2346
  onDelete(l) {
2324
2347
  d && b.send({ type: "delete", conversationId: d, messageId: l });
2325
2348
  },
2326
- onReact(l, p, y) {
2327
- d && b.send({ type: "react", conversationId: d, messageId: l, emoji: p, remove: y });
2349
+ onReact(l, h, y) {
2350
+ d && b.send({ type: "react", conversationId: d, messageId: l, emoji: h, remove: y });
2328
2351
  },
2329
2352
  onCsat(l) {
2330
2353
  d && fetch(`${o}/conversations/${d}/csat`, {
@@ -2343,13 +2366,13 @@ function Gt(s) {
2343
2366
  ...s.translateLang ? {
2344
2367
  async onTranslate(l) {
2345
2368
  try {
2346
- const p = await fetch(`${o}/translate`, {
2369
+ const h = await fetch(`${o}/translate`, {
2347
2370
  method: "POST",
2348
2371
  headers: { "content-type": "application/json", authorization: `Bearer ${t}` },
2349
2372
  body: JSON.stringify({ text: l, targetLang: s.translateLang })
2350
2373
  });
2351
- if (!p.ok) return null;
2352
- const { translated: y } = await p.json();
2374
+ if (!h.ok) return null;
2375
+ const { translated: y } = await h.json();
2353
2376
  return y;
2354
2377
  } catch {
2355
2378
  return null;
@@ -2361,7 +2384,7 @@ function Gt(s) {
2361
2384
  ...s.quickReplies ? { quickReplies: s.quickReplies } : {},
2362
2385
  ...s.accent ? { accent: s.accent } : {},
2363
2386
  ...(pe = s.user) != null && pe.name || (ue = s.user) != null && ue.avatar ? { userInfo: { ...s.user.name ? { name: s.user.name } : {}, ...s.user.avatar ? { avatar: s.user.avatar } : {} } } : {},
2364
- i18n: Ke
2387
+ i18n: Ae
2365
2388
  }), Le = {
2366
2389
  type: "open",
2367
2390
  profileId: s.profileId,
@@ -2374,10 +2397,10 @@ function Gt(s) {
2374
2397
  ...(fe = s.subject) != null && fe.title ? { subjectTitle: s.subject.title } : {},
2375
2398
  ...(we = s.subject) != null && we.subtitle ? { subjectMeta: s.subject.subtitle } : {}
2376
2399
  }, Me = (l) => {
2377
- const p = s.user;
2378
- if (!p || !p.name && !p.email && !p.avatar && !p.meta) return;
2400
+ const h = s.user;
2401
+ if (!h || !h.name && !h.email && !h.avatar && !h.meta) return;
2379
2402
  const y = [];
2380
- if (p.name && y.push(`Name: ${p.name}`), p.email && y.push(`Email: ${p.email}`), p.avatar && y.push(`Avatar: ${p.avatar}`), p.meta) for (const [E, R] of Object.entries(p.meta)) y.push(`${E}: ${R}`);
2403
+ if (h.name && y.push(`Name: ${h.name}`), h.email && y.push(`Email: ${h.email}`), h.avatar && y.push(`Avatar: ${h.avatar}`), h.meta) for (const [E, R] of Object.entries(h.meta)) y.push(`${E}: ${R}`);
2381
2404
  b.send({ type: "note", conversationId: l, clientMsgId: `ui_${Date.now()}`, text: `[User info]
2382
2405
  ${y.join(`
2383
2406
  `)}` });
@@ -2387,29 +2410,29 @@ ${y.join(`
2387
2410
  token: t,
2388
2411
  open: Le,
2389
2412
  getCursor: () => r.highestSeq(),
2390
- onStatusChange: (l) => L.setConnStatus(l),
2413
+ onStatusChange: (l, h) => L.setConnStatus(l, h),
2391
2414
  onFrame(l) {
2392
2415
  if (l.type === "opened") {
2393
- const p = d === void 0;
2416
+ const h = d === void 0;
2394
2417
  if (d = l.conversation.id, !v) {
2395
2418
  v = !0;
2396
2419
  for (const y of w.load())
2397
2420
  b.send({ type: "send", conversationId: d, clientMsgId: y.clientMsgId, content: y.content });
2398
2421
  }
2399
- Re(i, t, d, r, L, o), P.length && A(d), p && l.conversation.lastSeq === 0 && Me(d);
2422
+ Re(i, t, d, r, L, o), P.length && K(d), h && l.conversation.lastSeq === 0 && Me(d);
2400
2423
  }
2401
2424
  if (l.type === "ack" && w.remove(l.clientMsgId), l.type === "prekeyBundle") {
2402
- l.bundle && (W = !0, S.x3dhSendTo(l.bundle).then((p) => {
2425
+ l.bundle && (W = !0, S.x3dhSendTo(l.bundle).then((h) => {
2403
2426
  const y = [...k.splice(0), ...T.splice(0)];
2404
- for (const E of y) Ue(E.clientMsgId, E.text, p);
2427
+ for (const E of y) Ue(E.clientMsgId, E.text, h);
2405
2428
  L.render(r);
2406
2429
  }));
2407
2430
  return;
2408
2431
  }
2409
2432
  if (l.type === "message" && r.e2e) {
2410
- const p = Rt(l.message.content);
2411
- if (p && !S.ready) {
2412
- S.x3dhReceiveFrom(p.x3dhIK, p.x3dhEK, p.x3dhSPK).then(async () => {
2433
+ const h = jt(l.message.content);
2434
+ if (h && !S.ready) {
2435
+ S.x3dhReceiveFrom(h.x3dhIK, h.x3dhEK, h.x3dhSPK).then(async () => {
2413
2436
  await S.openFrame(l), r.apply(l), L.render(r);
2414
2437
  });
2415
2438
  return;
@@ -2422,10 +2445,10 @@ ${y.join(`
2422
2445
  return;
2423
2446
  }
2424
2447
  (async () => {
2425
- if (r.e2e && await S.openFrame(l), r.apply(l), l.type === "message" && l.message.senderId !== t && !l.message.internal && (U(), K()), r.e2e && d && !M) {
2448
+ if (r.e2e && await S.openFrame(l), r.apply(l), l.type === "message" && l.message.senderId !== t && !l.message.internal && (U(), A()), r.e2e && d && !M) {
2426
2449
  M = !0;
2427
- const p = await S.initX3DH();
2428
- b.send({ type: "uploadPrekeys", ...p });
2450
+ const h = await S.initX3DH();
2451
+ b.send({ type: "uploadPrekeys", ...h });
2429
2452
  const y = await S.begin();
2430
2453
  b.send({ type: "pubkey", conversationId: d, key: y });
2431
2454
  }
@@ -2434,22 +2457,22 @@ ${y.join(`
2434
2457
  }
2435
2458
  }), b.connect(), L.render(r);
2436
2459
  const j = s.launcher ? ve(s) : null, X = { close: () => {
2437
- b.close(), u == null || u.remove(), L.destroy(), x && f && x.removeEventListener("change", f), H.delete(s.el), j && Q.get(j) === X && Q.delete(j);
2460
+ b.close(), u == null || u.remove(), L.destroy(), x && f && x.removeEventListener("change", f), H.delete(s.el), j && Z.get(j) === X && Z.delete(j);
2438
2461
  } };
2439
- return H.set(s.el, X), j && Q.set(j, X), X;
2462
+ return H.set(s.el, X), j && Z.set(j, X), X;
2440
2463
  }
2441
2464
  export {
2442
2465
  Ct as ChatStore,
2443
2466
  Et as ConnectionManager,
2444
- Ht as E2ESession,
2445
- Pt as PersistentOutbox,
2446
- Nt as Renderer,
2447
- Yt as asConversationId,
2448
- Rt as extractX3DHInit,
2449
- en as httpBaseFromWsUrl,
2450
- Gt as mount,
2467
+ Ft as E2ESession,
2468
+ At as PersistentOutbox,
2469
+ Wt as Renderer,
2470
+ Gt as asConversationId,
2471
+ jt as extractX3DHInit,
2472
+ nn as httpBaseFromWsUrl,
2473
+ Qt as mount,
2451
2474
  He as resolveRelayUrls,
2452
2475
  Re as restoreHistory,
2453
- Jt as unmount
2476
+ Zt as unmount
2454
2477
  };
2455
2478
  //# sourceMappingURL=index.js.map