@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.
- package/dist/agentic/adaptor/fetch-bridge.d.ts +3 -2
- package/dist/agentic/index.d.ts +1 -0
- package/dist/agentic/index.js +347 -257
- package/dist/agentic/similarity.d.ts +77 -0
- package/dist/agentic/types.d.ts +2 -0
- package/dist/agentic/worker/be-client.d.ts +2 -1
- package/dist/agentic/worker.d.ts +1 -0
- package/dist/agentic/worker.js +65 -57
- package/dist/agentic.iife.js +5 -5
- package/dist/{api-paths-C4WzXzyY.js → api-paths-Bidgft9p.js} +1 -1
- package/dist/chat-runtime.js +1 -1
- package/dist/chat.iife.js +1 -1
- package/dist/chat.js +1 -1
- package/dist/common/transport.d.ts +7 -0
- package/dist/{common-DstAcheX.js → common-DWDSD8LC.js} +1 -1
- package/dist/common.js +5 -5
- package/dist/{connection-warning-Ddr91Y9x.js → connection-warning-BSO1YDm6.js} +1 -1
- package/dist/{fastIntent-XtUvISni.js → fastIntent-9jfo-OnO.js} +1 -1
- package/dist/index.js +10 -10
- package/dist/native.iife.js +1 -1
- package/dist/qna-runtime.js +1 -1
- package/dist/qna.iife.js +1 -1
- package/dist/qna.js +1 -1
- package/dist/{runtime-CcA_r8pw.js → runtime-B-25I0p6.js} +3 -3
- package/dist/{runtime-C66Wp6OR.js → runtime-B-lBAc6Z.js} +3 -3
- package/dist/{runtime-DJMUL882.js → runtime-BivTyMiH.js} +3 -3
- package/dist/{simbut-B6L3fwI7.js → simbut-DytP3AWT.js} +1 -1
- package/dist/simbut.iife.js +1 -1
- package/dist/simbut.js +1 -1
- package/dist/{beauty-consulting-turn-BmPXbkQg.js → similarity-DcfZ0CKT.js} +515 -295
- package/dist/{simrel-BB4Jrr32.js → simrel-CJp2qMtU.js} +1 -1
- package/dist/simrel-runtime.js +1 -1
- package/dist/simrel.iife.js +1 -1
- package/dist/simrel.js +2 -2
- package/dist/{widget-base-B3Oq8pjs.js → widget-base-UJbh-z_5.js} +1 -1
- package/package.json +1 -1
package/dist/agentic/index.js
CHANGED
|
@@ -1,117 +1,160 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
function
|
|
3
|
-
let
|
|
4
|
-
const
|
|
5
|
-
return
|
|
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:
|
|
8
|
-
beacon: (
|
|
9
|
-
...
|
|
10
|
-
accountId:
|
|
7
|
+
tools: d,
|
|
8
|
+
beacon: (l) => w?.({
|
|
9
|
+
...l,
|
|
10
|
+
accountId: l.accountId || e
|
|
11
11
|
}),
|
|
12
12
|
memory: sessionStorage
|
|
13
|
-
}), t.addEventListener("message", (
|
|
14
|
-
const a =
|
|
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
|
|
17
|
-
if (
|
|
16
|
+
const f = u.get(s);
|
|
17
|
+
if (f) {
|
|
18
18
|
if (a.type === "event" && a.event) {
|
|
19
|
-
|
|
19
|
+
S(f, a.event);
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
22
|
if (a.type === "error") {
|
|
23
|
-
|
|
23
|
+
f.onError(new Error(a.message || "Agent worker failed")), u.delete(s);
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
a.type === "end" &&
|
|
26
|
+
a.type === "end" && u.delete(s);
|
|
27
27
|
}
|
|
28
|
-
}), (
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
id:
|
|
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
|
-
|
|
55
|
+
g();
|
|
39
56
|
return;
|
|
40
57
|
}
|
|
41
|
-
s.addEventListener("abort",
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
|
56
|
-
let
|
|
57
|
-
const
|
|
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:
|
|
60
|
-
beacon:
|
|
61
|
-
}),
|
|
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,
|
|
68
|
-
|
|
79
|
+
return async (s, f, m, g) => {
|
|
80
|
+
const h = await j(s || {}, g);
|
|
81
|
+
p ||= new M({
|
|
69
82
|
accountId: e,
|
|
70
|
-
locale:
|
|
83
|
+
locale: h?.locale || c,
|
|
71
84
|
parentUrl: window.location.href,
|
|
72
|
-
rpc:
|
|
85
|
+
rpc: u
|
|
73
86
|
});
|
|
74
87
|
try {
|
|
75
|
-
await
|
|
76
|
-
request:
|
|
88
|
+
await I({
|
|
89
|
+
request: h,
|
|
77
90
|
accountModule: {
|
|
78
91
|
...t,
|
|
79
92
|
accountId: e
|
|
80
93
|
},
|
|
81
|
-
contextStore:
|
|
82
|
-
beClient: { invoke({ op:
|
|
83
|
-
return
|
|
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:
|
|
89
|
-
input:
|
|
90
|
-
|
|
101
|
+
op: y,
|
|
102
|
+
input: b,
|
|
103
|
+
cacheTtlS: O,
|
|
104
|
+
...P ? { signal: P } : {}
|
|
91
105
|
});
|
|
92
106
|
} },
|
|
93
|
-
toolBridge:
|
|
94
|
-
emit: (
|
|
95
|
-
rpc:
|
|
96
|
-
signal:
|
|
107
|
+
toolBridge: l,
|
|
108
|
+
emit: (y) => S(f, y),
|
|
109
|
+
rpc: u,
|
|
110
|
+
signal: m
|
|
97
111
|
});
|
|
98
|
-
} catch (
|
|
99
|
-
|
|
112
|
+
} catch (y) {
|
|
113
|
+
m?.aborted || (S(f, q(y)), f.onDone());
|
|
100
114
|
}
|
|
101
115
|
};
|
|
102
116
|
}
|
|
103
|
-
function
|
|
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) =>
|
|
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
|
|
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(
|
|
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
|
|
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
|
|
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
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
|
|
207
|
+
for (const d of i) n.routes.delete(d);
|
|
155
208
|
}
|
|
156
209
|
};
|
|
157
210
|
}
|
|
158
|
-
function
|
|
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 =
|
|
167
|
-
return
|
|
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
|
|
223
|
+
function C(e) {
|
|
171
224
|
return typeof e == "string" ? e : e instanceof URL ? e.href : e?.url || "";
|
|
172
225
|
}
|
|
173
|
-
function
|
|
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
|
|
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
|
|
181
|
-
const r =
|
|
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
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const
|
|
198
|
-
|
|
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
|
-
},
|
|
201
|
-
c || (c = !0,
|
|
271
|
+
}, l = () => {
|
|
272
|
+
c || (c = !0, d?.(), p.close());
|
|
202
273
|
}, a = (s) => {
|
|
203
|
-
|
|
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
|
-
}),
|
|
278
|
+
}), u({ type: "done" }), l();
|
|
208
279
|
};
|
|
209
280
|
if (i) {
|
|
210
281
|
const s = () => {
|
|
211
|
-
o.abort(), c || (c = !0,
|
|
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 }),
|
|
288
|
+
i.addEventListener("abort", s, { once: !0 }), d = () => i.removeEventListener("abort", s);
|
|
218
289
|
}
|
|
219
290
|
try {
|
|
220
|
-
const { request: s, attachment:
|
|
221
|
-
onTextChunk: (
|
|
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:
|
|
224
|
-
final:
|
|
225
|
-
...
|
|
294
|
+
content: g,
|
|
295
|
+
final: h === !0,
|
|
296
|
+
...y
|
|
226
297
|
}),
|
|
227
|
-
onUISpec: (
|
|
298
|
+
onUISpec: (g, h, y, b) => u({
|
|
228
299
|
type: "ui_spec",
|
|
229
|
-
spec:
|
|
230
|
-
widget:
|
|
231
|
-
...
|
|
232
|
-
...
|
|
300
|
+
spec: g,
|
|
301
|
+
widget: h,
|
|
302
|
+
...y ? { panelHint: y } : {},
|
|
303
|
+
...b ? { clearPanel: !0 } : {}
|
|
233
304
|
}),
|
|
234
|
-
onAction: (
|
|
235
|
-
|
|
305
|
+
onAction: (g) => {
|
|
306
|
+
u(g?.type === "action" ? g : {
|
|
236
307
|
type: "action",
|
|
237
|
-
action:
|
|
308
|
+
action: g
|
|
238
309
|
});
|
|
239
310
|
},
|
|
240
|
-
onMetadata: (
|
|
241
|
-
|
|
311
|
+
onMetadata: (g) => {
|
|
312
|
+
u(g?.type === "metadata" ? g : {
|
|
242
313
|
type: "metadata",
|
|
243
|
-
...
|
|
314
|
+
...g
|
|
244
315
|
});
|
|
245
316
|
},
|
|
246
317
|
onError: a,
|
|
247
318
|
onDone: () => {
|
|
248
|
-
|
|
319
|
+
u({ type: "done" }), l();
|
|
249
320
|
}
|
|
250
|
-
}, o.signal,
|
|
251
|
-
|
|
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(),
|
|
328
|
+
o.abort(), d?.(), c = !0;
|
|
258
329
|
}
|
|
259
330
|
});
|
|
260
|
-
return
|
|
331
|
+
return new Response(w, {
|
|
261
332
|
status: 200,
|
|
262
333
|
headers: { "Content-Type": "application/x-ndjson" }
|
|
263
|
-
})
|
|
334
|
+
});
|
|
264
335
|
}
|
|
265
|
-
function
|
|
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
|
|
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
|
|
355
|
+
const l = window, a = l.GengageAssistantInjector || (l.GengageAssistantInjector = {}), s = a[e] || (a[e] = {});
|
|
273
356
|
if (s.agentController) return s.agentController;
|
|
274
|
-
const
|
|
275
|
-
s.streamTransport =
|
|
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:
|
|
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:
|
|
284
|
-
...
|
|
285
|
-
}) :
|
|
366
|
+
tools: w,
|
|
367
|
+
...p ? { beacon: p } : {}
|
|
368
|
+
}) : z({
|
|
286
369
|
accountId: e,
|
|
287
|
-
accountModule:
|
|
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:
|
|
294
|
-
...
|
|
376
|
+
tools: w,
|
|
377
|
+
...p ? { beacon: p } : {}
|
|
295
378
|
});
|
|
296
|
-
const
|
|
379
|
+
const m = {
|
|
297
380
|
type: "agent",
|
|
298
381
|
stop() {
|
|
299
|
-
delete s.streamTransport,
|
|
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:
|
|
308
|
-
flows: Object.keys(
|
|
390
|
+
transport: f ? "worker" : "main-thread",
|
|
391
|
+
flows: Object.keys(d?.flows || {})
|
|
309
392
|
};
|
|
310
393
|
}
|
|
311
394
|
};
|
|
312
|
-
return s.agentController =
|
|
395
|
+
return s.agentController = m, m;
|
|
313
396
|
}
|
|
314
|
-
function
|
|
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
|
|
401
|
+
function ne(e, t, r = {}) {
|
|
319
402
|
const n = new URL(e, window.location.href);
|
|
320
|
-
if (
|
|
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
|
|
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
|
|
350
|
-
const r =
|
|
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
|
|
354
|
-
function
|
|
355
|
-
const r =
|
|
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
|
|
442
|
+
function se() {
|
|
360
443
|
try {
|
|
361
|
-
const e = new URLSearchParams(window.location.search).get(
|
|
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
|
|
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
|
-
},
|
|
375
|
-
function
|
|
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 <=
|
|
462
|
+
return e?.expiresAt != null && e.expiresAt <= E();
|
|
380
463
|
}
|
|
381
|
-
function
|
|
464
|
+
function U(e, t) {
|
|
382
465
|
return {
|
|
383
466
|
value: e,
|
|
384
|
-
createdAt:
|
|
385
|
-
expiresAt: t ?
|
|
467
|
+
createdAt: E(),
|
|
468
|
+
expiresAt: t ? E() + t : null
|
|
386
469
|
};
|
|
387
470
|
}
|
|
388
|
-
function
|
|
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
|
|
481
|
+
function de(e, t, r, n, o) {
|
|
399
482
|
try {
|
|
400
|
-
return e.setItem(`${t}${r}`, JSON.stringify(
|
|
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
|
|
488
|
+
function fe(e, t, r) {
|
|
406
489
|
try {
|
|
407
490
|
e.removeItem(`${t}${r}`);
|
|
408
491
|
} catch {
|
|
409
492
|
}
|
|
410
493
|
}
|
|
411
|
-
function
|
|
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
|
|
501
|
+
function _(e, t) {
|
|
419
502
|
return e ? {
|
|
420
|
-
get: (r) =>
|
|
421
|
-
set: (r, n, o = {}) =>
|
|
422
|
-
remove: (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
|
|
431
|
-
if (Array.isArray(e)) return `[${e.map(
|
|
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)}:${
|
|
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
|
|
521
|
+
function ge(e) {
|
|
439
522
|
let t = 2166136261;
|
|
440
|
-
const r =
|
|
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
|
|
446
|
-
const r = t.dbName || `gengage-${e}`, n = t.dbStore ||
|
|
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
|
|
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 = () =>
|
|
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 (
|
|
457
|
-
const a = await
|
|
539
|
+
idbGet: async (l) => {
|
|
540
|
+
const a = await d();
|
|
458
541
|
return a ? new Promise((s) => {
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
const
|
|
462
|
-
if (!
|
|
463
|
-
|
|
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(
|
|
467
|
-
},
|
|
549
|
+
s(g.value);
|
|
550
|
+
}, m.onerror = () => s(null);
|
|
468
551
|
}) : null;
|
|
469
552
|
},
|
|
470
|
-
idbSet: async (
|
|
471
|
-
const
|
|
472
|
-
return
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
key:
|
|
476
|
-
...
|
|
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 (
|
|
481
|
-
const a = await
|
|
482
|
-
a && a.transaction(n, "readwrite").objectStore(n).delete(
|
|
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
|
|
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 =
|
|
490
|
-
|
|
491
|
-
const
|
|
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
|
|
494
|
-
return
|
|
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,
|
|
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
|
-
},
|
|
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:
|
|
508
|
-
session:
|
|
509
|
-
local:
|
|
510
|
-
indexedDb:
|
|
511
|
-
stableKey:
|
|
590
|
+
volatile: u,
|
|
591
|
+
session: _(L("sessionStorage"), d),
|
|
592
|
+
local: _(L("localStorage"), w),
|
|
593
|
+
indexedDb: l,
|
|
594
|
+
stableKey: ge,
|
|
512
595
|
policy: {
|
|
513
|
-
...
|
|
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
|
|
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
|
|
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 ||
|
|
534
|
-
const
|
|
535
|
-
typeof
|
|
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
|
|
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
|
|
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
|
|
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,
|
|
562
|
-
const
|
|
644
|
+
const i = o || e, c = window, d = () => {
|
|
645
|
+
const l = c.GengageInjectorConfig || {}, a = l[e] || {};
|
|
563
646
|
return {
|
|
564
|
-
...
|
|
647
|
+
...l,
|
|
565
648
|
...a
|
|
566
649
|
};
|
|
567
|
-
},
|
|
568
|
-
const
|
|
569
|
-
if (
|
|
570
|
-
const a =
|
|
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
|
-
},
|
|
574
|
-
return
|
|
656
|
+
}, p = c.GengageAssistantInjector || (c.GengageAssistantInjector = {}), u = p[e] || (p[e] = {});
|
|
657
|
+
return u.loaderPromise || (u.loaderPromise = import(
|
|
575
658
|
/* @vite-ignore */
|
|
576
|
-
|
|
577
|
-
).then((
|
|
578
|
-
const a =
|
|
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((
|
|
582
|
-
throw console.error(`[Gengage][${e}] runtime load failed`,
|
|
583
|
-
})),
|
|
664
|
+
}).catch((l) => {
|
|
665
|
+
throw console.error(`[Gengage][${e}] runtime load failed`, l), l;
|
|
666
|
+
})), u.loaderPromise;
|
|
584
667
|
}
|
|
585
668
|
export {
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
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
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
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
|
-
|
|
713
|
+
he as uiSpec
|
|
624
714
|
};
|