@gengage/assistant-fe 0.6.2 → 0.6.3

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,8 +1,8 @@
1
- import { A as C, C as de, D as O, E as fe, F as ge, I as pe, M as $, O as me, P as D, R as k, S as we, T as ye, _ as he, a as be, b as Se, c as Ee, d as Ae, f as Re, g as ve, h as Ue, i as Pe, j as Te, k as xe, l as Le, m as _e, n as je, o as qe, p as Ce, r as Oe, s as $e, t as De, u as ke, v as B, w as Be, x as Me, y as M, z as F } from "../similarity-DcfZ0CKT.js";
2
- function N({ accountId: e, worker: t, beUrl: r, devJwtSecret: n, tokenBrokerUrl: o, tokenBrokerAudience: i, defaultLocale: c, tools: d = {}, beacon: w }) {
1
+ import { A as q, C as ye, D as k, E as he, F as be, I as Se, M as B, O as Ee, P as M, R as F, S as Ae, T as Re, _ as Ue, a as Pe, b as ve, c as Te, d as xe, f as Le, g as _e, h as je, i as Ce, j as $e, k as De, l as Oe, m as qe, n as ke, o as Be, p as Me, r as Fe, s as Ne, t as Ie, u as Ge, v as N, w as He, x as ze, y as I, z as G } from "../similarity-DcfZ0CKT.js";
2
+ function H({ accountId: e, worker: t, beUrl: r, devJwtSecret: n, tokenBrokerUrl: o, tokenBrokerAudience: i, defaultLocale: c, tools: d = {}, beacon: w }) {
3
3
  let p = 1;
4
4
  const u = /* @__PURE__ */ new Map();
5
- return k({
5
+ return F({
6
6
  worker: t,
7
7
  tools: d,
8
8
  beacon: (l) => w?.({
@@ -11,107 +11,149 @@ function N({ accountId: e, worker: t, beUrl: r, devJwtSecret: n, tokenBrokerUrl:
11
11
  }),
12
12
  memory: sessionStorage
13
13
  }), t.addEventListener("message", (l) => {
14
- const s = l.data || {}, a = typeof s.id == "number" ? s.id : null;
15
- if (a == null) return;
16
- const f = u.get(a);
14
+ const a = l.data || {}, s = typeof a.id == "number" ? a.id : null;
15
+ if (s == null) return;
16
+ const f = u.get(s);
17
17
  if (f) {
18
- if (s.type === "event" && s.event) {
19
- S(f, s.event);
18
+ if (a.type === "event" && a.event) {
19
+ S(f, a.event);
20
20
  return;
21
21
  }
22
- if (s.type === "error") {
23
- f.onError(new Error(s.message || "Agent worker failed")), u.delete(a);
22
+ if (a.type === "error") {
23
+ f.onError(new Error(a.message || "Agent worker failed")), u.delete(s);
24
24
  return;
25
25
  }
26
- s.type === "end" && u.delete(a);
26
+ a.type === "end" && u.delete(s);
27
27
  }
28
- }), (l, s, a) => {
29
- const f = p++;
30
- u.set(f, s);
31
- const m = () => {
32
- u.delete(f), t.postMessage({
33
- id: f,
28
+ }), (l, a, s, f) => {
29
+ const m = p++;
30
+ u.set(m, a);
31
+ const g = () => {
32
+ u.delete(m), t.postMessage({
33
+ id: m,
34
34
  type: "abort"
35
35
  });
36
+ }, h = (y) => {
37
+ if (s.aborted) {
38
+ g();
39
+ return;
40
+ }
41
+ t.postMessage({
42
+ id: m,
43
+ type: "invoke",
44
+ accountId: e,
45
+ beUrl: r,
46
+ devJwtSecret: n,
47
+ tokenBrokerUrl: o,
48
+ tokenBrokerAudience: i,
49
+ defaultLocale: c,
50
+ request: y,
51
+ parentUrl: window.location.href
52
+ });
36
53
  };
37
- if (a.aborted) {
38
- m();
54
+ if (s.aborted) {
55
+ g();
39
56
  return;
40
57
  }
41
- a.addEventListener("abort", m, { once: !0 }), t.postMessage({
42
- id: f,
43
- type: "invoke",
44
- accountId: e,
45
- beUrl: r,
46
- devJwtSecret: n,
47
- tokenBrokerUrl: o,
48
- tokenBrokerAudience: i,
49
- defaultLocale: c,
50
- request: l,
51
- parentUrl: window.location.href
52
- });
58
+ if (s.addEventListener("abort", g, { once: !0 }), f) {
59
+ j(l, f).then(h).catch((y) => {
60
+ u.delete(m), a.onError(y instanceof Error ? y : /* @__PURE__ */ new Error("Failed to read image attachment"));
61
+ });
62
+ return;
63
+ }
64
+ h(l);
53
65
  };
54
66
  }
55
- function G({ accountId: e, accountModule: t, beUrl: r, devJwtSecret: n, tokenBrokerUrl: o, tokenBrokerAudience: i, defaultLocale: c, tools: d = {}, beacon: w }) {
67
+ function z({ accountId: e, accountModule: t, beUrl: r, devJwtSecret: n, tokenBrokerUrl: o, tokenBrokerAudience: i, defaultLocale: c, tools: d = {}, beacon: w }) {
56
68
  let p = null;
57
- const u = I({
69
+ const u = J({
58
70
  accountId: e,
59
71
  tools: d,
60
72
  beacon: w
61
- }), l = B(u), s = $({
73
+ }), l = N(u), a = B({
62
74
  accountId: e,
63
75
  ...n ? { devJwtSecret: n } : {},
64
76
  ...o ? { tokenBrokerUrl: o } : {},
65
77
  ...i ? { tokenBrokerAudience: i } : {}
66
78
  });
67
- return async (a, f, m) => {
68
- p ||= new D({
79
+ return async (s, f, m, g) => {
80
+ const h = await j(s || {}, g);
81
+ p ||= new M({
69
82
  accountId: e,
70
- locale: a?.locale || c,
83
+ locale: h?.locale || c,
71
84
  parentUrl: window.location.href,
72
85
  rpc: u
73
86
  });
74
87
  try {
75
- await M({
76
- request: a || {},
88
+ await I({
89
+ request: h,
77
90
  accountModule: {
78
91
  ...t,
79
92
  accountId: e
80
93
  },
81
94
  contextStore: p,
82
- beClient: { invoke({ op: g, input: h, signal: y, cacheTtlS: b }) {
83
- return O({
95
+ beClient: { invoke({ op: y, input: b, signal: P, cacheTtlS: O }) {
96
+ return k({
84
97
  beUrl: r,
85
98
  accountId: e,
86
- jwtProvider: s,
99
+ jwtProvider: a,
87
100
  parentUrl: window.location.href,
88
- op: g,
89
- input: h,
90
- cacheTtlS: b,
91
- ...y ? { signal: y } : {}
101
+ op: y,
102
+ input: b,
103
+ cacheTtlS: O,
104
+ ...P ? { signal: P } : {}
92
105
  });
93
106
  } },
94
107
  toolBridge: l,
95
- emit: (g) => S(f, g),
108
+ emit: (y) => S(f, y),
96
109
  rpc: u,
97
110
  signal: m
98
111
  });
99
- } catch (g) {
100
- m?.aborted || (S(f, C(g)), f.onDone());
112
+ } catch (y) {
113
+ m?.aborted || (S(f, q(y)), f.onDone());
101
114
  }
102
115
  };
103
116
  }
104
- function I({ accountId: e, tools: t, beacon: r }) {
117
+ function J({ accountId: e, tools: t, beacon: r }) {
105
118
  const n = (o) => r?.({
106
119
  ...o,
107
120
  accountId: o.accountId || e
108
121
  });
109
- return ((o, i) => F(o, i, {
122
+ return ((o, i) => G(o, i, {
110
123
  tools: t,
111
124
  beacon: n,
112
125
  memory: sessionStorage
113
126
  }));
114
127
  }
128
+ async function j(e, t) {
129
+ if (!t || !t.type?.startsWith("image/")) return e;
130
+ const r = await Q(t), n = {
131
+ ...W(e.payload ?? e.action?.payload),
132
+ image_data_url: r,
133
+ image_mime: t.type
134
+ };
135
+ return {
136
+ ...e,
137
+ payload: n,
138
+ ...e.action ? { action: {
139
+ ...e.action,
140
+ payload: n
141
+ } } : {}
142
+ };
143
+ }
144
+ function W(e) {
145
+ return K(e) ? { ...e } : typeof e == "string" ? { text: e } : {};
146
+ }
147
+ function K(e) {
148
+ return typeof e == "object" && e !== null && !Array.isArray(e);
149
+ }
150
+ async function Q(e) {
151
+ const t = new Uint8Array(await e.arrayBuffer());
152
+ let r = "";
153
+ const n = 32768;
154
+ for (let o = 0; o < t.length; o += n) r += String.fromCharCode(...t.subarray(o, o + n));
155
+ return `data:${e.type};base64,${btoa(r)}`;
156
+ }
115
157
  function S(e, t) {
116
158
  switch (t?.type) {
117
159
  case "text_chunk": {
@@ -131,7 +173,7 @@ function S(e, t) {
131
173
  e.onMetadata(t);
132
174
  break;
133
175
  case "error":
134
- e.onError(H(t));
176
+ e.onError(V(t));
135
177
  break;
136
178
  case "done":
137
179
  e.onDone();
@@ -140,15 +182,15 @@ function S(e, t) {
140
182
  break;
141
183
  }
142
184
  }
143
- function H(e) {
185
+ function V(e) {
144
186
  const t = new Error(e.message || e.code || "Agent error");
145
187
  return e.code && (t.code = e.code), t;
146
188
  }
147
- var U = "__gengageAgentFetchBridge";
148
- function Fe({ accountId: e, streamTransport: t, endpoints: r = {} }) {
189
+ var v = "__gengageAgentFetchBridge";
190
+ function Je({ accountId: e, streamTransport: t, endpoints: r = {} }) {
149
191
  if (!e) throw new Error("accountId is required.");
150
192
  if (typeof t != "function") throw new Error("streamTransport is required.");
151
- const n = J(), o = `https://gengage-injector.invalid/${encodeURIComponent(e)}`, i = /* @__PURE__ */ new Set(), c = (d) => {
193
+ const n = Y(), o = `https://gengage-injector.invalid/${encodeURIComponent(e)}`, i = /* @__PURE__ */ new Set(), c = (d) => {
152
194
  const w = `${o}/chat/${d}`;
153
195
  i.add(w);
154
196
  const p = r[d], u = {
@@ -166,30 +208,30 @@ function Fe({ accountId: e, streamTransport: t, endpoints: r = {} }) {
166
208
  }
167
209
  };
168
210
  }
169
- function J() {
170
- const e = window, t = e[U];
211
+ function Y() {
212
+ const e = window, t = e[v];
171
213
  if (t) return t;
172
214
  const r = e.fetch.bind(e), n = {
173
215
  routes: /* @__PURE__ */ new Map(),
174
216
  originalFetch: r
175
217
  };
176
218
  return e.fetch = (o, i) => {
177
- const c = _(o), d = n.routes.get(c);
178
- return d ? W(d, o, i) : r(o, i);
179
- }, e[U] = n, n;
219
+ const c = C(o), d = n.routes.get(c);
220
+ return d ? Z(d, o, i) : r(o, i);
221
+ }, e[v] = n, n;
180
222
  }
181
- function _(e) {
223
+ function C(e) {
182
224
  return typeof e == "string" ? e : e instanceof URL ? e.href : e?.url || "";
183
225
  }
184
- function P(e, t) {
226
+ function T(e, t) {
185
227
  if (t?.signal) return t.signal;
186
228
  if (typeof Request < "u" && e instanceof Request) return e.signal;
187
229
  }
188
- function j(e, t) {
230
+ function $(e, t) {
189
231
  return t?.body !== void 0 && t?.body !== null ? t.body : typeof Request < "u" && e instanceof Request ? e.clone().text() : null;
190
232
  }
191
- async function z(e, t) {
192
- const r = j(e, t);
233
+ async function X(e, t) {
234
+ const r = $(e, t);
193
235
  if (r instanceof FormData) {
194
236
  const o = r.get("request"), i = r.get("attachment");
195
237
  return {
@@ -200,18 +242,18 @@ async function z(e, t) {
200
242
  const n = await Promise.resolve(r);
201
243
  return typeof n == "string" ? { request: JSON.parse(n || "{}") } : { request: {} };
202
244
  }
203
- async function W(e, t, r) {
245
+ async function Z(e, t, r) {
204
246
  if (e.endpoint && e.endpoint !== "process_action" && e.endpointHandler) {
205
- const p = new AbortController(), u = P(t, r);
247
+ const p = new AbortController(), u = T(t, r);
206
248
  let l = null;
207
249
  if (u) {
208
- const s = () => p.abort();
209
- u.aborted && s(), u.addEventListener("abort", s, { once: !0 }), l = () => u.removeEventListener("abort", s);
250
+ const a = () => p.abort();
251
+ u.aborted && a(), u.addEventListener("abort", a, { once: !0 }), l = () => u.removeEventListener("abort", a);
210
252
  }
211
253
  try {
212
- const s = await K(t, r);
213
- return await e.endpointHandler(s, {
214
- accountId: Q(t),
254
+ const a = await ee(t, r);
255
+ return await e.endpointHandler(a, {
256
+ accountId: te(t),
215
257
  endpoint: e.endpoint,
216
258
  signal: p.signal
217
259
  });
@@ -219,34 +261,34 @@ async function W(e, t, r) {
219
261
  l?.();
220
262
  }
221
263
  }
222
- const n = new TextEncoder(), o = new AbortController(), i = P(t, r);
264
+ const n = new TextEncoder(), o = new AbortController(), i = T(t, r);
223
265
  let c = !1, d = null;
224
266
  const w = new ReadableStream({
225
267
  async start(p) {
226
- const u = (a) => {
227
- c || p.enqueue(n.encode(`${JSON.stringify(a)}
268
+ const u = (s) => {
269
+ c || p.enqueue(n.encode(`${JSON.stringify(s)}
228
270
  `));
229
271
  }, l = () => {
230
272
  c || (c = !0, d?.(), p.close());
231
- }, s = (a) => {
273
+ }, a = (s) => {
232
274
  u({
233
275
  type: "error",
234
- code: a?.code || "agent_bridge_error",
235
- message: a instanceof Error ? a.message : String(a)
276
+ code: s?.code || "agent_bridge_error",
277
+ message: s instanceof Error ? s.message : String(s)
236
278
  }), u({ type: "done" }), l();
237
279
  };
238
280
  if (i) {
239
- const a = () => {
281
+ const s = () => {
240
282
  o.abort(), c || (c = !0, d?.(), p.error(new DOMException("Aborted", "AbortError")));
241
283
  };
242
284
  if (i.aborted) {
243
- a();
285
+ s();
244
286
  return;
245
287
  }
246
- i.addEventListener("abort", a, { once: !0 }), d = () => i.removeEventListener("abort", a);
288
+ i.addEventListener("abort", s, { once: !0 }), d = () => i.removeEventListener("abort", s);
247
289
  }
248
290
  try {
249
- const { request: a, attachment: f } = await z(t, r), m = e.streamTransport(a, {
291
+ const { request: s, attachment: f } = await X(t, r), m = e.streamTransport(s, {
250
292
  onTextChunk: (g, h, y = {}) => u({
251
293
  type: "text_chunk",
252
294
  content: g,
@@ -272,14 +314,14 @@ async function W(e, t, r) {
272
314
  ...g
273
315
  });
274
316
  },
275
- onError: s,
317
+ onError: a,
276
318
  onDone: () => {
277
319
  u({ type: "done" }), l();
278
320
  }
279
321
  }, o.signal, f);
280
- V(m) && (await m, o.signal.aborted || (u({ type: "done" }), l()));
281
- } catch (a) {
282
- o.signal.aborted || s(a);
322
+ re(m) && (await m, o.signal.aborted || (u({ type: "done" }), l()));
323
+ } catch (s) {
324
+ o.signal.aborted || a(s);
283
325
  }
284
326
  },
285
327
  cancel() {
@@ -291,29 +333,29 @@ async function W(e, t, r) {
291
333
  headers: { "Content-Type": "application/x-ndjson" }
292
334
  });
293
335
  }
294
- async function K(e, t) {
295
- const r = await Promise.resolve(j(e, t));
336
+ async function ee(e, t) {
337
+ const r = await Promise.resolve($(e, t));
296
338
  return typeof r != "string" || r.trim() === "" ? {} : JSON.parse(r);
297
339
  }
298
- function Q(e) {
340
+ function te(e) {
299
341
  try {
300
- const [t] = new URL(_(e)).pathname.split("/").filter(Boolean);
342
+ const [t] = new URL(C(e)).pathname.split("/").filter(Boolean);
301
343
  return decodeURIComponent(t || "");
302
344
  } catch {
303
345
  return "";
304
346
  }
305
347
  }
306
- function V(e) {
348
+ function re(e) {
307
349
  return e !== null && (typeof e == "object" || typeof e == "function") && typeof e.then == "function";
308
350
  }
309
- function Ne({ accountId: e, beUrl: t, devJwtSecret: r, tokenBrokerUrl: n, tokenBrokerAudience: o, workerUrl: i, defaultLocale: c = "en-GB", accountModule: d, tools: w = {}, beacon: p, allowBlobWorker: u = !1 }) {
351
+ function We({ accountId: e, beUrl: t, devJwtSecret: r, tokenBrokerUrl: n, tokenBrokerAudience: o, workerUrl: i, defaultLocale: c = "en-GB", accountModule: d, tools: w = {}, beacon: p, allowBlobWorker: u = !1 }) {
310
352
  if (!e) throw new Error("accountId is required.");
311
353
  if (!t) throw new Error("beUrl is required. The injector owns backend URLs; the SDK has no default.");
312
354
  if (!i) throw new Error("workerUrl is required.");
313
- const l = window, s = l.GengageAssistantInjector || (l.GengageAssistantInjector = {}), a = s[e] || (s[e] = {});
314
- if (a.agentController) return a.agentController;
315
- const f = q(i) || u ? Y(i, `gengage-${e}-agent`, { allowBlobWorker: u }) : null;
316
- a.streamTransport = f ? N({
355
+ const l = window, a = l.GengageAssistantInjector || (l.GengageAssistantInjector = {}), s = a[e] || (a[e] = {});
356
+ if (s.agentController) return s.agentController;
357
+ const f = D(i) || u ? ne(i, `gengage-${e}-agent`, { allowBlobWorker: u }) : null;
358
+ s.streamTransport = f ? H({
317
359
  accountId: e,
318
360
  worker: f.worker,
319
361
  beUrl: t,
@@ -323,7 +365,7 @@ function Ne({ accountId: e, beUrl: t, devJwtSecret: r, tokenBrokerUrl: n, tokenB
323
365
  defaultLocale: c,
324
366
  tools: w,
325
367
  ...p ? { beacon: p } : {}
326
- }) : G({
368
+ }) : z({
327
369
  accountId: e,
328
370
  accountModule: d,
329
371
  beUrl: t,
@@ -337,7 +379,7 @@ function Ne({ accountId: e, beUrl: t, devJwtSecret: r, tokenBrokerUrl: n, tokenB
337
379
  const m = {
338
380
  type: "agent",
339
381
  stop() {
340
- delete a.streamTransport, f?.worker.terminate(), f?.cleanup(), delete a.agentController;
382
+ delete s.streamTransport, f?.worker.terminate(), f?.cleanup(), delete s.agentController;
341
383
  },
342
384
  diagnostics() {
343
385
  return {
@@ -350,15 +392,15 @@ function Ne({ accountId: e, beUrl: t, devJwtSecret: r, tokenBrokerUrl: n, tokenB
350
392
  };
351
393
  }
352
394
  };
353
- return a.agentController = m, m;
395
+ return s.agentController = m, m;
354
396
  }
355
- function q(e) {
397
+ function D(e) {
356
398
  const t = new URL(e, window.location.href);
357
399
  return t.origin === window.location.origin || t.protocol === "blob:";
358
400
  }
359
- function Y(e, t, r = {}) {
401
+ function ne(e, t, r = {}) {
360
402
  const n = new URL(e, window.location.href);
361
- if (q(e)) return {
403
+ if (D(e)) return {
362
404
  worker: new Worker(n.href, {
363
405
  type: "module",
364
406
  name: t
@@ -383,23 +425,23 @@ function Y(e, t, r = {}) {
383
425
  throw URL.revokeObjectURL(i), c;
384
426
  }
385
427
  }
386
- function X(e) {
428
+ function oe(e) {
387
429
  const t = (e?.chat || e?._chat)?.root || e?._chat?.root;
388
430
  return t ? t.getRootNode?.()?.host || t : Array.from(document.querySelectorAll("*")).find((r) => r.shadowRoot?.querySelector?.(".gengage-chat-root, .gengage-chat-launcher-container"));
389
431
  }
390
- function Ge(e, t) {
391
- const r = X(e);
432
+ function Ke(e, t) {
433
+ const r = oe(e);
392
434
  r?.style && (t ? r.style.removeProperty("display") : r.style.setProperty("display", "none", "important")), t || (e?.chat || e?._chat)?.close?.();
393
435
  }
394
- var Z = "nd_be_url";
395
- function Ie(e, t) {
396
- const r = ee() || e.beUrl || t;
436
+ var ae = "nd_be_url";
437
+ function Qe(e, t) {
438
+ const r = se() || e.beUrl || t;
397
439
  if (!r) throw new Error("resolveBeUrl: backend URL is required. The injector must supply a fallback URL; the SDK has no default.");
398
440
  return r;
399
441
  }
400
- function ee() {
442
+ function se() {
401
443
  try {
402
- const e = new URLSearchParams(window.location.search).get(Z)?.trim();
444
+ const e = new URLSearchParams(window.location.search).get(ae)?.trim();
403
445
  if (!e) return null;
404
446
  const t = new URL(e);
405
447
  return t.protocol !== "https:" && t.protocol !== "http:" ? null : t.toString().replace(/\/+$/u, "");
@@ -407,26 +449,26 @@ function ee() {
407
449
  return null;
408
450
  }
409
451
  }
410
- var te = "entries", re = 1, ne = {
452
+ var ie = "entries", ce = 1, le = {
411
453
  volatile: "Hot per-page state and sensitive request context.",
412
454
  session: "Current-visit tool context without raw tokens or PII-heavy payloads.",
413
455
  local: "Small, non-sensitive capability facts or user preferences.",
414
456
  indexedDb: "Larger product/search payload caches with short TTLs."
415
- }, T = /* @__PURE__ */ new Map();
457
+ }, x = /* @__PURE__ */ new Map();
416
458
  function E() {
417
459
  return Date.now();
418
460
  }
419
461
  function R(e) {
420
462
  return e?.expiresAt != null && e.expiresAt <= E();
421
463
  }
422
- function v(e, t) {
464
+ function U(e, t) {
423
465
  return {
424
466
  value: e,
425
467
  createdAt: E(),
426
468
  expiresAt: t ? E() + t : null
427
469
  };
428
470
  }
429
- function oe(e, t, r) {
471
+ function ue(e, t, r) {
430
472
  try {
431
473
  const n = e.getItem(`${t}${r}`);
432
474
  if (!n) return null;
@@ -436,31 +478,31 @@ function oe(e, t, r) {
436
478
  return null;
437
479
  }
438
480
  }
439
- function se(e, t, r, n, o) {
481
+ function de(e, t, r, n, o) {
440
482
  try {
441
- return e.setItem(`${t}${r}`, JSON.stringify(v(n, o))), !0;
483
+ return e.setItem(`${t}${r}`, JSON.stringify(U(n, o))), !0;
442
484
  } catch {
443
485
  return !1;
444
486
  }
445
487
  }
446
- function ae(e, t, r) {
488
+ function fe(e, t, r) {
447
489
  try {
448
490
  e.removeItem(`${t}${r}`);
449
491
  } catch {
450
492
  }
451
493
  }
452
- function x(e) {
494
+ function L(e) {
453
495
  try {
454
496
  return window[e];
455
497
  } catch {
456
498
  return null;
457
499
  }
458
500
  }
459
- function L(e, t) {
501
+ function _(e, t) {
460
502
  return e ? {
461
- get: (r) => oe(e, t, r),
462
- set: (r, n, o = {}) => se(e, t, r, n, o.ttlMs),
463
- remove: (r) => ae(e, t, r)
503
+ get: (r) => ue(e, t, r),
504
+ set: (r, n, o = {}) => de(e, t, r, n, o.ttlMs),
505
+ remove: (r) => fe(e, t, r)
464
506
  } : {
465
507
  get: () => null,
466
508
  set: () => !1,
@@ -476,90 +518,90 @@ function A(e) {
476
518
  }
477
519
  return JSON.stringify(e);
478
520
  }
479
- function ie(e) {
521
+ function ge(e) {
480
522
  let t = 2166136261;
481
523
  const r = A(e);
482
524
  for (let n = 0; n < r.length; n += 1)
483
525
  t ^= r.charCodeAt(n), t = Math.imul(t, 16777619);
484
526
  return (t >>> 0).toString(36);
485
527
  }
486
- function ce(e, t) {
487
- const r = t.dbName || `gengage-${e}`, n = t.dbStore || te, o = t.dbVersion || re, i = /* @__PURE__ */ new Map();
528
+ function pe(e, t) {
529
+ const r = t.dbName || `gengage-${e}`, n = t.dbStore || ie, o = t.dbVersion || ce, i = /* @__PURE__ */ new Map();
488
530
  let c = null;
489
531
  const d = () => "indexedDB" in window ? c || (c = new Promise((l) => {
490
- const s = indexedDB.open(r, o);
491
- s.onupgradeneeded = () => {
492
- s.result.createObjectStore(n, { keyPath: "key" });
493
- }, s.onsuccess = () => l(s.result), s.onerror = () => l(null), s.onblocked = () => l(null);
532
+ const a = indexedDB.open(r, o);
533
+ a.onupgradeneeded = () => {
534
+ a.result.createObjectStore(n, { keyPath: "key" });
535
+ }, a.onsuccess = () => l(a.result), a.onerror = () => l(null), a.onblocked = () => l(null);
494
536
  }), c) : Promise.resolve(null);
495
537
  return {
496
538
  volatileEntries: i,
497
539
  idbGet: async (l) => {
498
- const s = await d();
499
- return s ? new Promise((a) => {
500
- const f = s.transaction(n, "readwrite").objectStore(n), m = f.get(l);
540
+ const a = await d();
541
+ return a ? new Promise((s) => {
542
+ const f = a.transaction(n, "readwrite").objectStore(n), m = f.get(l);
501
543
  m.onsuccess = () => {
502
544
  const g = m.result;
503
545
  if (!g || R(g)) {
504
- g && f.delete(l), a(null);
546
+ g && f.delete(l), s(null);
505
547
  return;
506
548
  }
507
- a(g.value);
508
- }, m.onerror = () => a(null);
549
+ s(g.value);
550
+ }, m.onerror = () => s(null);
509
551
  }) : null;
510
552
  },
511
- idbSet: async (l, s, a = {}) => {
553
+ idbSet: async (l, a, s = {}) => {
512
554
  const f = await d();
513
555
  return f ? new Promise((m) => {
514
556
  const g = f.transaction(n, "readwrite");
515
557
  g.oncomplete = () => m(!0), g.onerror = () => m(!1), g.objectStore(n).put({
516
558
  key: l,
517
- ...v(s, a.ttlMs)
559
+ ...U(a, s.ttlMs)
518
560
  });
519
561
  }) : !1;
520
562
  },
521
563
  idbRemove: async (l) => {
522
- const s = await d();
523
- s && s.transaction(n, "readwrite").objectStore(n).delete(l);
564
+ const a = await d();
565
+ a && a.transaction(n, "readwrite").objectStore(n).delete(l);
524
566
  }
525
567
  };
526
568
  }
527
- function He(e, t = {}) {
569
+ function Ve(e, t = {}) {
528
570
  const r = window, n = r.gengage || (r.gengage = {}), o = n.memory || (n.memory = {}), i = o[e];
529
571
  if (i) return i;
530
- const c = T.get(e) || ce(e, t);
531
- T.set(e, c);
572
+ const c = x.get(e) || pe(e, t);
573
+ x.set(e, c);
532
574
  const d = t.sessionPrefix || `gengage:${e}:session:`, w = t.localPrefix || `gengage:${e}:local:`, u = {
533
- get: (a) => {
534
- const f = c.volatileEntries.get(a);
535
- return f ? R(f) ? (c.volatileEntries.delete(a), null) : f.value : null;
575
+ get: (s) => {
576
+ const f = c.volatileEntries.get(s);
577
+ return f ? R(f) ? (c.volatileEntries.delete(s), null) : f.value : null;
536
578
  },
537
- set: (a, f, m = {}) => (c.volatileEntries.set(a, v(f, m.ttlMs)), !0),
538
- remove: (a) => {
539
- c.volatileEntries.delete(a);
579
+ set: (s, f, m = {}) => (c.volatileEntries.set(s, U(f, m.ttlMs)), !0),
580
+ remove: (s) => {
581
+ c.volatileEntries.delete(s);
540
582
  },
541
583
  clear: () => c.volatileEntries.clear()
542
584
  }, l = {
543
585
  get: c.idbGet,
544
586
  set: c.idbSet,
545
587
  remove: c.idbRemove
546
- }, s = {
588
+ }, a = {
547
589
  accountId: e,
548
590
  volatile: u,
549
- session: L(x("sessionStorage"), d),
550
- local: L(x("localStorage"), w),
591
+ session: _(L("sessionStorage"), d),
592
+ local: _(L("localStorage"), w),
551
593
  indexedDb: l,
552
- stableKey: ie,
594
+ stableKey: ge,
553
595
  policy: {
554
- ...ne,
596
+ ...le,
555
597
  ...t.policy || {}
556
598
  }
557
599
  };
558
- o[e] = s;
559
- for (const a of t.aliases || []) o[a] = s;
560
- return s;
600
+ o[e] = a;
601
+ for (const s of t.aliases || []) o[s] = a;
602
+ return a;
561
603
  }
562
- var le = [
604
+ var me = [
563
605
  "addToCart",
564
606
  "search",
565
607
  "searchKeyword",
@@ -567,17 +609,17 @@ var le = [
567
609
  "searchGiftOptions",
568
610
  "similaritySearch"
569
611
  ];
570
- function Je(e, t, r = {}) {
612
+ function Ye(e, t, r = {}) {
571
613
  const n = window, o = n.gengage || (n.gengage = {}), i = o.tools || (o.tools = {});
572
614
  i[e] = t;
573
615
  for (const c of r.accountAliases || []) i[c] = t;
574
- if (r.exposeStandardAliases !== !1) for (const c of r.standardAliases || le) {
616
+ if (r.exposeStandardAliases !== !1) for (const c of r.standardAliases || me) {
575
617
  const d = t[c];
576
618
  typeof d == "function" && (i[c] = i[c] || d);
577
619
  }
578
620
  return t;
579
621
  }
580
- function ze({ getPageType: e, getProduct: t }) {
622
+ function Xe({ getPageType: e, getProduct: t }) {
581
623
  return () => ({
582
624
  url: window.location.href,
583
625
  title: document.title,
@@ -585,7 +627,7 @@ function ze({ getPageType: e, getProduct: t }) {
585
627
  product: t()
586
628
  });
587
629
  }
588
- function We({ accountId: e, getPageType: t, getProduct: r, getToolNames: n, getSearchCapabilities: o, getMemory: i }) {
630
+ function Ze({ accountId: e, getPageType: t, getProduct: r, getToolNames: n, getSearchCapabilities: o, getMemory: i }) {
589
631
  return async () => ({
590
632
  accountId: e,
591
633
  url: window.location.href,
@@ -597,76 +639,76 @@ function We({ accountId: e, getPageType: t, getProduct: r, getToolNames: n, getS
597
639
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
598
640
  });
599
641
  }
600
- function Ke({ accountId: e, runtimeFile: t = "runtime.js", startExport: r = "start", globalBaseUrlKey: n, errorLabel: o } = {}) {
642
+ function et({ accountId: e, runtimeFile: t = "runtime.js", startExport: r = "start", globalBaseUrlKey: n, errorLabel: o } = {}) {
601
643
  if (!e) throw new Error("accountId is required.");
602
644
  const i = o || e, c = window, d = () => {
603
- const l = c.GengageInjectorConfig || {}, s = l[e] || {};
645
+ const l = c.GengageInjectorConfig || {}, a = l[e] || {};
604
646
  return {
605
647
  ...l,
606
- ...s
648
+ ...a
607
649
  };
608
650
  }, w = () => {
609
651
  const l = d();
610
652
  if (l.runtimeUrl) return l.runtimeUrl;
611
- const s = l.assetBaseUrl || l.baseUrl || document.currentScript?.getAttribute("src") || (n ? c[n] : null);
612
- if (!s) throw new Error(`${i} runtime URL cannot be resolved.`);
613
- return new URL(t, s).href;
653
+ const a = l.assetBaseUrl || l.baseUrl || document.currentScript?.getAttribute("src") || (n ? c[n] : null);
654
+ if (!a) throw new Error(`${i} runtime URL cannot be resolved.`);
655
+ return new URL(t, a).href;
614
656
  }, p = c.GengageAssistantInjector || (c.GengageAssistantInjector = {}), u = p[e] || (p[e] = {});
615
657
  return u.loaderPromise || (u.loaderPromise = import(
616
658
  /* @vite-ignore */
617
659
  w()
618
660
  ).then((l) => {
619
- const s = l[r];
620
- if (typeof s != "function") throw new Error(`${i} runtime export ${r} is unavailable.`);
621
- return s();
661
+ const a = l[r];
662
+ if (typeof a != "function") throw new Error(`${i} runtime export ${r} is unavailable.`);
663
+ return a();
622
664
  }).catch((l) => {
623
665
  throw console.error(`[Gengage][${e}] runtime load failed`, l), l;
624
666
  })), u.loaderPromise;
625
667
  }
626
668
  export {
627
- me as AgentError,
628
- D as ContextStore,
629
- Me as action,
630
- Ae as actionButtonsUiSpec,
631
- xe as beErrorToAgentError,
632
- Ee as beautyConsultingTurnFlow,
633
- De as buildPhotoSimilarityProfile,
634
- je as buildProductSimilarityProfile,
635
- Oe as buildSimilarityQueries,
636
- q as canUseModuleWorker,
637
- C as caughtToStreamError,
638
- Re as comparisonUiSpec,
639
- He as createBrowserMemory,
640
- We as createDiagnosticsTool,
641
- Le as createFlow,
642
- N as createInjectorAdapter,
643
- G as createMainThreadInjectorAdapter,
644
- Y as createModuleWorker,
645
- ze as createReadPageTool,
646
- we as done,
647
- ge as elapsedMs,
648
- de as error,
649
- Te as httpErrorToAgentError,
650
- Je as installBrowserTools,
651
- Fe as installFetchTransportBridge,
652
- Be as metadata,
653
- Ne as mountAccount,
654
- Ue as normalizeProduct,
655
- Pe as normalizeSimilarityText,
656
- pe as nowIso,
657
- Ce as productDetailsUiSpec,
658
- _e as productsUiSpec,
659
- be as rankSimilarProducts,
660
- ke as requestText,
661
- Ie as resolveBeUrl,
662
- Se as resolveFlow,
663
- qe as scoreSimilarityCandidate,
664
- Ge as setAssistantHostVisible,
665
- ie as stableKey,
666
- Ke as startLazyRuntimeLoader,
667
- ye as textChunk,
668
- $e as tokenizeSimilarityText,
669
- ve as trimProductFactsCore,
670
- he as trimProductFactsListCore,
671
- fe as uiSpec
669
+ Ee as AgentError,
670
+ M as ContextStore,
671
+ ze as action,
672
+ xe as actionButtonsUiSpec,
673
+ De as beErrorToAgentError,
674
+ Te as beautyConsultingTurnFlow,
675
+ Ie as buildPhotoSimilarityProfile,
676
+ ke as buildProductSimilarityProfile,
677
+ Fe as buildSimilarityQueries,
678
+ D as canUseModuleWorker,
679
+ q as caughtToStreamError,
680
+ Le as comparisonUiSpec,
681
+ Ve as createBrowserMemory,
682
+ Ze as createDiagnosticsTool,
683
+ Oe as createFlow,
684
+ H as createInjectorAdapter,
685
+ z as createMainThreadInjectorAdapter,
686
+ ne as createModuleWorker,
687
+ Xe as createReadPageTool,
688
+ Ae as done,
689
+ be as elapsedMs,
690
+ ye as error,
691
+ $e as httpErrorToAgentError,
692
+ Ye as installBrowserTools,
693
+ Je as installFetchTransportBridge,
694
+ He as metadata,
695
+ We as mountAccount,
696
+ je as normalizeProduct,
697
+ Ce as normalizeSimilarityText,
698
+ Se as nowIso,
699
+ Me as productDetailsUiSpec,
700
+ qe as productsUiSpec,
701
+ Pe as rankSimilarProducts,
702
+ Ge as requestText,
703
+ Qe as resolveBeUrl,
704
+ ve as resolveFlow,
705
+ Be as scoreSimilarityCandidate,
706
+ Ke as setAssistantHostVisible,
707
+ ge as stableKey,
708
+ et as startLazyRuntimeLoader,
709
+ Re as textChunk,
710
+ Ne as tokenizeSimilarityText,
711
+ _e as trimProductFactsCore,
712
+ Ue as trimProductFactsListCore,
713
+ he as uiSpec
672
714
  };