@gengage/assistant-fe 0.6.0 → 0.6.2

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