@gengage/assistant-fe 0.6.5 → 0.6.6

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.
@@ -1,11 +1,11 @@
1
- import { A as q, C as Ee, D as B, E as Ae, F as Re, I as Pe, M as I, O as Ue, P as k, R as F, S as ve, T as Te, _ as xe, a as _e, b as Le, c as je, d as Ce, f as Me, g as $e, h as De, i as Oe, j as qe, k as Be, l as Ie, m as ke, n as Fe, o as Ge, p as Ne, r as He, s as Je, t as ze, u as We, v as G, w as Ke, x as Qe, y as N, z as H } from "../similarity-DcfZ0CKT.js";
1
+ import { A as q, C as Ee, D as B, E as Ae, F as Pe, I as Re, M as I, O as Ue, P as k, R as F, S as ve, T as Te, _ as xe, a as _e, b as Le, c as je, d as Ce, f as Me, g as $e, h as De, i as Oe, j as qe, k as Be, l as Ie, m as ke, n as Fe, o as Ge, p as Ne, r as He, s as Je, t as ze, u as We, v as G, w as Ke, x as Qe, y as N, z as H } from "../similarity-DcfZ0CKT.js";
2
2
  var J = 512, z = 0.74;
3
- function W({ accountId: e, worker: t, beUrl: r, devJwtSecret: n, tokenBrokerUrl: o, tokenBrokerAudience: s, defaultLocale: i, tools: u = {}, beacon: w }) {
3
+ function W({ accountId: e, worker: t, beUrl: r, devJwtSecret: n, tokenBrokerUrl: o, tokenBrokerAudience: s, defaultLocale: i, tools: d = {}, beacon: w }) {
4
4
  let m = 1;
5
- const d = /* @__PURE__ */ new Map();
5
+ const u = /* @__PURE__ */ new Map();
6
6
  return F({
7
7
  worker: t,
8
- tools: u,
8
+ tools: d,
9
9
  beacon: (l) => w?.({
10
10
  ...l,
11
11
  accountId: l.accountId || e
@@ -14,23 +14,23 @@ function W({ accountId: e, worker: t, beUrl: r, devJwtSecret: n, tokenBrokerUrl:
14
14
  }), t.addEventListener("message", (l) => {
15
15
  const a = l.data || {}, c = typeof a.id == "number" ? a.id : null;
16
16
  if (c == null) return;
17
- const f = d.get(c);
17
+ const f = u.get(c);
18
18
  if (f) {
19
19
  if (a.type === "event" && a.event) {
20
20
  S(f, a.event);
21
21
  return;
22
22
  }
23
23
  if (a.type === "error") {
24
- f.onError(new Error(a.message || "Agent worker failed")), d.delete(c);
24
+ f.onError(new Error(a.message || "Agent worker failed")), u.delete(c);
25
25
  return;
26
26
  }
27
- a.type === "end" && d.delete(c);
27
+ a.type === "end" && u.delete(c);
28
28
  }
29
29
  }), (l, a, c, f) => {
30
30
  const p = m++;
31
- d.set(p, a);
31
+ u.set(p, a);
32
32
  const g = () => {
33
- d.delete(p), t.postMessage({
33
+ u.delete(p), t.postMessage({
34
34
  id: p,
35
35
  type: "abort"
36
36
  });
@@ -58,20 +58,20 @@ function W({ accountId: e, worker: t, beUrl: r, devJwtSecret: n, tokenBrokerUrl:
58
58
  }
59
59
  if (c.addEventListener("abort", g, { once: !0 }), f) {
60
60
  j(l, f).then(h).catch((y) => {
61
- d.delete(p), a.onError(y instanceof Error ? y : /* @__PURE__ */ new Error("Failed to read image attachment"));
61
+ u.delete(p), a.onError(y instanceof Error ? y : /* @__PURE__ */ new Error("Failed to read image attachment"));
62
62
  });
63
63
  return;
64
64
  }
65
65
  h(l);
66
66
  };
67
67
  }
68
- function K({ accountId: e, accountModule: t, beUrl: r, devJwtSecret: n, tokenBrokerUrl: o, tokenBrokerAudience: s, defaultLocale: i, tools: u = {}, beacon: w }) {
68
+ function K({ accountId: e, accountModule: t, beUrl: r, devJwtSecret: n, tokenBrokerUrl: o, tokenBrokerAudience: s, defaultLocale: i, tools: d = {}, beacon: w }) {
69
69
  let m = null;
70
- const d = Q({
70
+ const u = Q({
71
71
  accountId: e,
72
- tools: u,
72
+ tools: d,
73
73
  beacon: w
74
- }), l = G(d), a = I({
74
+ }), l = G(u), a = I({
75
75
  accountId: e,
76
76
  ...n ? { devJwtSecret: n } : {},
77
77
  ...o ? { tokenBrokerUrl: o } : {},
@@ -83,7 +83,7 @@ function K({ accountId: e, accountModule: t, beUrl: r, devJwtSecret: n, tokenBro
83
83
  accountId: e,
84
84
  locale: h?.locale || i,
85
85
  parentUrl: window.location.href,
86
- rpc: d
86
+ rpc: u
87
87
  });
88
88
  try {
89
89
  await N({
@@ -107,7 +107,7 @@ function K({ accountId: e, accountModule: t, beUrl: r, devJwtSecret: n, tokenBro
107
107
  } },
108
108
  toolBridge: l,
109
109
  emit: (y) => S(f, y),
110
- rpc: d,
110
+ rpc: u,
111
111
  signal: p
112
112
  });
113
113
  } catch (y) {
@@ -165,10 +165,10 @@ async function Z(e) {
165
165
  const i = s.getContext("2d");
166
166
  if (!i) return null;
167
167
  i.drawImage(t, 0, 0, n, o);
168
- const u = await new Promise((w) => s.toBlob(w, "image/jpeg", z));
169
- return u ? {
170
- dataUrl: await C(u),
171
- mime: u.type || "image/jpeg"
168
+ const d = await new Promise((w) => s.toBlob(w, "image/jpeg", z));
169
+ return d ? {
170
+ dataUrl: await C(d),
171
+ mime: d.type || "image/jpeg"
172
172
  } : null;
173
173
  } catch {
174
174
  return null;
@@ -219,21 +219,21 @@ var v = "__gengageAgentFetchBridge";
219
219
  function Ye({ accountId: e, streamTransport: t, endpoints: r = {} }) {
220
220
  if (!e) throw new Error("accountId is required.");
221
221
  if (typeof t != "function") throw new Error("streamTransport is required.");
222
- const n = te(), o = `https://gengage-injector.invalid/${encodeURIComponent(e)}`, s = /* @__PURE__ */ new Set(), i = (u) => {
223
- const w = `${o}/chat/${u}`;
222
+ const n = te(), o = `https://gengage-injector.invalid/${encodeURIComponent(e)}`, s = /* @__PURE__ */ new Set(), i = (d) => {
223
+ const w = `${o}/chat/${d}`;
224
224
  s.add(w);
225
- const m = r[u], d = {
225
+ const m = r[d], u = {
226
226
  streamTransport: t,
227
- endpoint: u
227
+ endpoint: d
228
228
  };
229
- m && (d.endpointHandler = m), n.routes.set(w, d);
229
+ m && (u.endpointHandler = m), n.routes.set(w, u);
230
230
  };
231
231
  i("process_action");
232
- for (const u of Object.keys(r)) u !== "process_action" && i(u);
232
+ for (const d of Object.keys(r)) d !== "process_action" && i(d);
233
233
  return {
234
234
  middlewareUrl: o,
235
235
  stop() {
236
- for (const u of s) n.routes.delete(u);
236
+ for (const d of s) n.routes.delete(d);
237
237
  }
238
238
  };
239
239
  }
@@ -245,8 +245,8 @@ function te() {
245
245
  originalFetch: r
246
246
  };
247
247
  return e.fetch = (o, s) => {
248
- const i = M(o), u = n.routes.get(i);
249
- return u ? ne(u, o, s) : r(o, s);
248
+ const i = M(o), d = n.routes.get(i);
249
+ return d ? ne(d, o, s) : r(o, s);
250
250
  }, e[v] = n, n;
251
251
  }
252
252
  function M(e) {
@@ -273,11 +273,11 @@ async function re(e, t) {
273
273
  }
274
274
  async function ne(e, t, r) {
275
275
  if (e.endpoint && e.endpoint !== "process_action" && e.endpointHandler) {
276
- const m = new AbortController(), d = T(t, r);
276
+ const m = new AbortController(), u = T(t, r);
277
277
  let l = null;
278
- if (d) {
278
+ if (u) {
279
279
  const a = () => m.abort();
280
- d.aborted && a(), d.addEventListener("abort", a, { once: !0 }), l = () => d.removeEventListener("abort", a);
280
+ u.aborted && a(), u.addEventListener("abort", a, { once: !0 }), l = () => u.removeEventListener("abort", a);
281
281
  }
282
282
  try {
283
283
  const a = await oe(t, r);
@@ -291,40 +291,40 @@ async function ne(e, t, r) {
291
291
  }
292
292
  }
293
293
  const n = new TextEncoder(), o = new AbortController(), s = T(t, r);
294
- let i = !1, u = null;
294
+ let i = !1, d = null;
295
295
  const w = new ReadableStream({
296
296
  async start(m) {
297
- const d = (c) => {
297
+ const u = (c) => {
298
298
  i || m.enqueue(n.encode(`${JSON.stringify(c)}
299
299
  `));
300
300
  }, l = () => {
301
- i || (i = !0, u?.(), m.close());
301
+ i || (i = !0, d?.(), m.close());
302
302
  }, a = (c) => {
303
- d({
303
+ u({
304
304
  type: "error",
305
305
  code: c?.code || "agent_bridge_error",
306
306
  message: c instanceof Error ? c.message : String(c)
307
- }), d({ type: "done" }), l();
307
+ }), u({ type: "done" }), l();
308
308
  };
309
309
  if (s) {
310
310
  const c = () => {
311
- o.abort(), i || (i = !0, u?.(), m.error(new DOMException("Aborted", "AbortError")));
311
+ o.abort(), i || (i = !0, d?.(), m.error(new DOMException("Aborted", "AbortError")));
312
312
  };
313
313
  if (s.aborted) {
314
314
  c();
315
315
  return;
316
316
  }
317
- s.addEventListener("abort", c, { once: !0 }), u = () => s.removeEventListener("abort", c);
317
+ s.addEventListener("abort", c, { once: !0 }), d = () => s.removeEventListener("abort", c);
318
318
  }
319
319
  try {
320
320
  const { request: c, attachment: f } = await re(t, r), p = e.streamTransport(c, {
321
- onTextChunk: (g, h, y = {}) => d({
321
+ onTextChunk: (g, h, y = {}) => u({
322
322
  type: "text_chunk",
323
323
  content: g,
324
324
  final: h === !0,
325
325
  ...y
326
326
  }),
327
- onUISpec: (g, h, y, b) => d({
327
+ onUISpec: (g, h, y, b) => u({
328
328
  type: "ui_spec",
329
329
  spec: g,
330
330
  widget: h,
@@ -332,29 +332,29 @@ async function ne(e, t, r) {
332
332
  ...b ? { clearPanel: !0 } : {}
333
333
  }),
334
334
  onAction: (g) => {
335
- d(g?.type === "action" ? g : {
335
+ u(g?.type === "action" ? g : {
336
336
  type: "action",
337
337
  action: g
338
338
  });
339
339
  },
340
340
  onMetadata: (g) => {
341
- d(g?.type === "metadata" ? g : {
341
+ u(g?.type === "metadata" ? g : {
342
342
  type: "metadata",
343
343
  ...g
344
344
  });
345
345
  },
346
346
  onError: a,
347
347
  onDone: () => {
348
- d({ type: "done" }), l();
348
+ u({ type: "done" }), l();
349
349
  }
350
350
  }, o.signal, f);
351
- se(p) && (await p, o.signal.aborted || (d({ type: "done" }), l()));
351
+ se(p) && (await p, o.signal.aborted || (u({ type: "done" }), l()));
352
352
  } catch (c) {
353
353
  o.signal.aborted || a(c);
354
354
  }
355
355
  },
356
356
  cancel() {
357
- o.abort(), u?.(), i = !0;
357
+ o.abort(), d?.(), i = !0;
358
358
  }
359
359
  });
360
360
  return new Response(w, {
@@ -377,13 +377,13 @@ function ae(e) {
377
377
  function se(e) {
378
378
  return e !== null && (typeof e == "object" || typeof e == "function") && typeof e.then == "function";
379
379
  }
380
- function Ve({ accountId: e, beUrl: t, devJwtSecret: r, tokenBrokerUrl: n, tokenBrokerAudience: o, workerUrl: s, defaultLocale: i = "en-GB", accountModule: u, tools: w = {}, beacon: m, allowBlobWorker: d = !1 }) {
380
+ function Ve({ accountId: e, beUrl: t, devJwtSecret: r, tokenBrokerUrl: n, tokenBrokerAudience: o, workerUrl: s, defaultLocale: i = "en-GB", accountModule: d, tools: w = {}, beacon: m, allowBlobWorker: u = !1 }) {
381
381
  if (!e) throw new Error("accountId is required.");
382
382
  if (!t) throw new Error("beUrl is required. The injector owns backend URLs; the SDK has no default.");
383
383
  if (!s) throw new Error("workerUrl is required.");
384
384
  const l = window, a = l.GengageAssistantInjector || (l.GengageAssistantInjector = {}), c = a[e] || (a[e] = {});
385
385
  if (c.agentController) return c.agentController;
386
- const f = D(s) || d ? ie(s, `gengage-${e}-agent`, { allowBlobWorker: d }) : null;
386
+ const f = D(s) || u ? ie(s, `gengage-${e}-agent`, { allowBlobWorker: u }) : null;
387
387
  c.streamTransport = f ? W({
388
388
  accountId: e,
389
389
  worker: f.worker,
@@ -396,7 +396,7 @@ function Ve({ accountId: e, beUrl: t, devJwtSecret: r, tokenBrokerUrl: n, tokenB
396
396
  ...m ? { beacon: m } : {}
397
397
  }) : K({
398
398
  accountId: e,
399
- accountModule: u,
399
+ accountModule: d,
400
400
  beUrl: t,
401
401
  ...r ? { devJwtSecret: r } : {},
402
402
  ...n ? { tokenBrokerUrl: n } : {},
@@ -417,7 +417,7 @@ function Ve({ accountId: e, beUrl: t, devJwtSecret: r, tokenBrokerUrl: n, tokenB
417
417
  workerUrl: s,
418
418
  mounted: !0,
419
419
  transport: f ? "worker" : "main-thread",
420
- flows: Object.keys(u?.flows || {})
420
+ flows: Object.keys(d?.flows || {})
421
421
  };
422
422
  }
423
423
  };
@@ -487,10 +487,10 @@ var de = "entries", fe = 1, ge = {
487
487
  function E() {
488
488
  return Date.now();
489
489
  }
490
- function R(e) {
490
+ function P(e) {
491
491
  return e?.expiresAt != null && e.expiresAt <= E();
492
492
  }
493
- function P(e, t) {
493
+ function R(e, t) {
494
494
  return {
495
495
  value: e,
496
496
  createdAt: E(),
@@ -502,14 +502,14 @@ function me(e, t, r) {
502
502
  const n = e.getItem(`${t}${r}`);
503
503
  if (!n) return null;
504
504
  const o = JSON.parse(n);
505
- return R(o) ? (e.removeItem(`${t}${r}`), null) : o.value;
505
+ return P(o) ? (e.removeItem(`${t}${r}`), null) : o.value;
506
506
  } catch {
507
507
  return null;
508
508
  }
509
509
  }
510
510
  function pe(e, t, r, n, o) {
511
511
  try {
512
- return e.setItem(`${t}${r}`, JSON.stringify(P(n, o))), !0;
512
+ return e.setItem(`${t}${r}`, JSON.stringify(R(n, o))), !0;
513
513
  } catch {
514
514
  return !1;
515
515
  }
@@ -557,7 +557,7 @@ function ye(e) {
557
557
  function he(e, t) {
558
558
  const r = t.dbName || `gengage-${e}`, n = t.dbStore || de, o = t.dbVersion || fe, s = /* @__PURE__ */ new Map();
559
559
  let i = null;
560
- const u = () => "indexedDB" in window ? i || (i = new Promise((l) => {
560
+ const d = () => "indexedDB" in window ? i || (i = new Promise((l) => {
561
561
  const a = indexedDB.open(r, o);
562
562
  a.onupgradeneeded = () => {
563
563
  a.result.createObjectStore(n, { keyPath: "key" });
@@ -566,12 +566,12 @@ function he(e, t) {
566
566
  return {
567
567
  volatileEntries: s,
568
568
  idbGet: async (l) => {
569
- const a = await u();
569
+ const a = await d();
570
570
  return a ? new Promise((c) => {
571
571
  const f = a.transaction(n, "readwrite").objectStore(n), p = f.get(l);
572
572
  p.onsuccess = () => {
573
573
  const g = p.result;
574
- if (!g || R(g)) {
574
+ if (!g || P(g)) {
575
575
  g && f.delete(l), c(null);
576
576
  return;
577
577
  }
@@ -580,17 +580,17 @@ function he(e, t) {
580
580
  }) : null;
581
581
  },
582
582
  idbSet: async (l, a, c = {}) => {
583
- const f = await u();
583
+ const f = await d();
584
584
  return f ? new Promise((p) => {
585
585
  const g = f.transaction(n, "readwrite");
586
586
  g.oncomplete = () => p(!0), g.onerror = () => p(!1), g.objectStore(n).put({
587
587
  key: l,
588
- ...P(a, c.ttlMs)
588
+ ...R(a, c.ttlMs)
589
589
  });
590
590
  }) : !1;
591
591
  },
592
592
  idbRemove: async (l) => {
593
- const a = await u();
593
+ const a = await d();
594
594
  a && a.transaction(n, "readwrite").objectStore(n).delete(l);
595
595
  }
596
596
  };
@@ -600,12 +600,12 @@ function et(e, t = {}) {
600
600
  if (s) return s;
601
601
  const i = x.get(e) || he(e, t);
602
602
  x.set(e, i);
603
- const u = t.sessionPrefix || `gengage:${e}:session:`, w = t.localPrefix || `gengage:${e}:local:`, d = {
603
+ const d = t.sessionPrefix || `gengage:${e}:session:`, w = t.localPrefix || `gengage:${e}:local:`, u = {
604
604
  get: (c) => {
605
605
  const f = i.volatileEntries.get(c);
606
- return f ? R(f) ? (i.volatileEntries.delete(c), null) : f.value : null;
606
+ return f ? P(f) ? (i.volatileEntries.delete(c), null) : f.value : null;
607
607
  },
608
- set: (c, f, p = {}) => (i.volatileEntries.set(c, P(f, p.ttlMs)), !0),
608
+ set: (c, f, p = {}) => (i.volatileEntries.set(c, R(f, p.ttlMs)), !0),
609
609
  remove: (c) => {
610
610
  i.volatileEntries.delete(c);
611
611
  },
@@ -616,8 +616,8 @@ function et(e, t = {}) {
616
616
  remove: i.idbRemove
617
617
  }, a = {
618
618
  accountId: e,
619
- volatile: d,
620
- session: L(_("sessionStorage"), u),
619
+ volatile: u,
620
+ session: L(_("sessionStorage"), d),
621
621
  local: L(_("localStorage"), w),
622
622
  indexedDb: l,
623
623
  stableKey: ye,
@@ -643,8 +643,8 @@ function tt(e, t, r = {}) {
643
643
  s[e] = t;
644
644
  for (const i of r.accountAliases || []) s[i] = t;
645
645
  if (r.exposeStandardAliases !== !1) for (const i of r.standardAliases || be) {
646
- const u = t[i];
647
- typeof u == "function" && (s[i] = s[i] || u);
646
+ const d = t[i];
647
+ typeof d == "function" && (s[i] = s[i] || d);
648
648
  }
649
649
  return t;
650
650
  }
@@ -670,20 +670,20 @@ function nt({ accountId: e, getPageType: t, getProduct: r, getToolNames: n, getS
670
670
  }
671
671
  function ot({ accountId: e, runtimeFile: t = "runtime.js", startExport: r = "start", globalBaseUrlKey: n, errorLabel: o } = {}) {
672
672
  if (!e) throw new Error("accountId is required.");
673
- const s = o || e, i = window, u = () => {
673
+ const s = o || e, i = window, d = () => {
674
674
  const l = i.GengageInjectorConfig || {}, a = l[e] || {};
675
675
  return {
676
676
  ...l,
677
677
  ...a
678
678
  };
679
679
  }, w = () => {
680
- const l = u();
680
+ const l = d();
681
681
  if (l.runtimeUrl) return l.runtimeUrl;
682
682
  const a = l.assetBaseUrl || l.baseUrl || document.currentScript?.getAttribute("src") || (n ? i[n] : null);
683
683
  if (!a) throw new Error(`${s} runtime URL cannot be resolved.`);
684
684
  return new URL(t, a).href;
685
- }, m = i.GengageAssistantInjector || (i.GengageAssistantInjector = {}), d = m[e] || (m[e] = {});
686
- return d.loaderPromise || (d.loaderPromise = import(
685
+ }, m = i.GengageAssistantInjector || (i.GengageAssistantInjector = {}), u = m[e] || (m[e] = {});
686
+ return u.loaderPromise || (u.loaderPromise = import(
687
687
  /* @vite-ignore */
688
688
  w()
689
689
  ).then((l) => {
@@ -691,8 +691,8 @@ function ot({ accountId: e, runtimeFile: t = "runtime.js", startExport: r = "sta
691
691
  if (typeof a != "function") throw new Error(`${s} runtime export ${r} is unavailable.`);
692
692
  return a();
693
693
  }).catch((l) => {
694
- throw console.error(`[Gengage][${e}] runtime load failed`, l), l;
695
- })), d.loaderPromise;
694
+ throw delete u.loaderPromise, console.error(`[Gengage][${e}] runtime load failed`, l), l;
695
+ })), u.loaderPromise;
696
696
  }
697
697
  export {
698
698
  Ue as AgentError,
@@ -715,7 +715,7 @@ export {
715
715
  ie as createModuleWorker,
716
716
  rt as createReadPageTool,
717
717
  ve as done,
718
- Re as elapsedMs,
718
+ Pe as elapsedMs,
719
719
  Ee as error,
720
720
  qe as httpErrorToAgentError,
721
721
  tt as installBrowserTools,
@@ -724,7 +724,7 @@ export {
724
724
  Ve as mountAccount,
725
725
  De as normalizeProduct,
726
726
  Oe as normalizeSimilarityText,
727
- Pe as nowIso,
727
+ Re as nowIso,
728
728
  Ne as productDetailsUiSpec,
729
729
  ke as productsUiSpec,
730
730
  _e as rankSimilarProducts,