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