@gengage/assistant-fe 0.6.3 → 0.6.5

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