@gengage/assistant-fe 0.6.12 → 0.6.13
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/mount.d.ts +1 -0
- package/dist/agentic/context/context-store.d.ts +2 -1
- package/dist/agentic/context/persistence.d.ts +2 -1
- package/dist/agentic/index.d.ts +3 -2
- package/dist/agentic/index.js +244 -240
- package/dist/agentic/types.d.ts +28 -20
- package/dist/agentic/util/browser-memory.d.ts +2 -2
- package/dist/agentic/util/cache-key.d.ts +15 -0
- package/dist/agentic/worker/be-client.d.ts +3 -1
- package/dist/agentic/worker.d.ts +3 -2
- package/dist/agentic/worker.js +92 -86
- package/dist/agentic.iife.js +5 -5
- package/dist/{api-paths-Cth1szY1.js → api-paths-ChCMvKkx.js} +1 -1
- package/dist/{chat-CrEa2W-e.js → chat-BP-yXukW.js} +1 -1
- package/dist/chat-runtime.js +1 -1
- package/dist/chat.iife.js +17 -17
- package/dist/chat.js +2 -2
- package/dist/common/request-response-cache.d.ts +9 -0
- package/dist/{common-CmPjQ9RK.js → common-BD_DSsqY.js} +3 -3
- package/dist/common.js +7 -7
- package/dist/{connection-warning-Bx1TJaU9.js → connection-warning-CPeEsQ35.js} +1 -1
- package/dist/{fastIntent-nZXiT9DG.js → fastIntent-C1WeEqW8.js} +1 -1
- package/dist/index.js +12 -12
- package/dist/{native-webview-BlHM7cLs.js → native-webview-DbKq9lN8.js} +1 -1
- package/dist/native.iife.js +14 -14
- package/dist/native.js +1 -1
- package/dist/overlay.js +1 -1
- package/dist/{qna-BNvttR6s.js → qna-B3lMzHvS.js} +1 -1
- package/dist/qna-runtime.js +1 -1
- package/dist/qna.iife.js +13 -13
- package/dist/qna.js +2 -2
- package/dist/request-response-cache-zsgz3Awp.js +154 -0
- package/dist/request-text-su3Vlhrs.js +1318 -0
- package/dist/{runtime-xlTFF9HS.js → runtime-Dbwwd8yF.js} +38 -37
- package/dist/{runtime-B0v76aJ5.js → runtime-DclobJaN.js} +365 -364
- package/dist/{runtime-Dt6FUotQ.js → runtime-Duvrignh.js} +69 -68
- package/dist/{simbut-pTonQlCT.js → simbut-5C5EAfoM.js} +1 -1
- package/dist/simbut.iife.js +1 -1
- package/dist/simbut.js +1 -1
- package/dist/{simrel-C3ZJHVIW.js → simrel-DCcSBFez.js} +3 -3
- package/dist/simrel-runtime.js +1 -1
- package/dist/simrel.iife.js +12 -12
- package/dist/simrel.js +2 -2
- package/dist/{widget-base-C6H3cDSW.js → widget-base-BolzGV28.js} +1 -1
- package/package.json +1 -1
- package/dist/agentic/flow/beauty-consulting-turn.d.ts +0 -1
- package/dist/similarity-qMH5-do-.js +0 -1262
- /package/dist/{overlay-fgrzmFTR.js → overlay-CyoB1K0w.js} +0 -0
- /package/dist/{price-formatter-xI3g9Cd4.js → price-formatter-CFsWT0lP.js} +0 -0
- /package/dist/{schemas-CLo8wCjs.js → schemas-Cq2blsO_.js} +0 -0
|
@@ -1,1262 +0,0 @@
|
|
|
1
|
-
function it(t) {
|
|
2
|
-
return !!t && typeof t == "object" && t.type === "rpc.result";
|
|
3
|
-
}
|
|
4
|
-
function at(t) {
|
|
5
|
-
return !!t && typeof t == "object" && t.type === "rpc.req";
|
|
6
|
-
}
|
|
7
|
-
function ce(t = self) {
|
|
8
|
-
let e = 1;
|
|
9
|
-
const n = /* @__PURE__ */ new Map();
|
|
10
|
-
return t.addEventListener("message", (r) => {
|
|
11
|
-
const o = r.data;
|
|
12
|
-
if (!it(o)) return;
|
|
13
|
-
const i = n.get(o.rpcId);
|
|
14
|
-
if (i) {
|
|
15
|
-
if (n.delete(o.rpcId), o.ok === !1) {
|
|
16
|
-
const a = typeof o.error == "object" ? o.error?.message : o.error;
|
|
17
|
-
i.reject(new Error(a || "RPC failed"));
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
i.resolve(o.value);
|
|
21
|
-
}
|
|
22
|
-
}), function(o, i, a) {
|
|
23
|
-
const s = e++;
|
|
24
|
-
return t.postMessage({
|
|
25
|
-
type: "rpc.req",
|
|
26
|
-
rpcId: s,
|
|
27
|
-
method: o,
|
|
28
|
-
payload: i
|
|
29
|
-
}, a || []), new Promise((c, u) => {
|
|
30
|
-
n.set(s, {
|
|
31
|
-
resolve: (l) => c(l),
|
|
32
|
-
reject: u
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function ue({ worker: t, tools: e = {}, beacon: n, memory: r = sessionStorage }) {
|
|
38
|
-
t.addEventListener("message", (o) => {
|
|
39
|
-
const i = o.data;
|
|
40
|
-
at(i) && st(t, i, {
|
|
41
|
-
tools: e,
|
|
42
|
-
beacon: n,
|
|
43
|
-
memory: r
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
async function st(t, e, n) {
|
|
48
|
-
try {
|
|
49
|
-
const r = await dt(e.method, e.payload, n);
|
|
50
|
-
t.postMessage({
|
|
51
|
-
type: "rpc.result",
|
|
52
|
-
rpcId: e.rpcId,
|
|
53
|
-
ok: !0,
|
|
54
|
-
value: r
|
|
55
|
-
});
|
|
56
|
-
} catch (r) {
|
|
57
|
-
t.postMessage({
|
|
58
|
-
type: "rpc.result",
|
|
59
|
-
rpcId: e.rpcId,
|
|
60
|
-
ok: !1,
|
|
61
|
-
error: { message: r instanceof Error ? r.message : String(r) }
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function ct(t) {
|
|
66
|
-
if (t && typeof t == "object" && typeof t.name == "string") return t;
|
|
67
|
-
throw new Error("tool.invoke requires { name, input }");
|
|
68
|
-
}
|
|
69
|
-
function ut(t) {
|
|
70
|
-
if (t && typeof t == "object" && t.key !== void 0) return t;
|
|
71
|
-
throw new Error("memory.get requires { key }");
|
|
72
|
-
}
|
|
73
|
-
function lt(t) {
|
|
74
|
-
if (t && typeof t == "object" && t.key !== void 0) return t;
|
|
75
|
-
throw new Error("memory.set requires { key }");
|
|
76
|
-
}
|
|
77
|
-
async function dt(t, e, { tools: n, beacon: r, memory: o }) {
|
|
78
|
-
if (t === "tool.invoke") {
|
|
79
|
-
const { name: i, input: a } = ct(e), s = n[i];
|
|
80
|
-
if (typeof s != "function") throw new Error(`Unknown tool: ${i}`);
|
|
81
|
-
return s(a);
|
|
82
|
-
}
|
|
83
|
-
if (t === "beacon.send")
|
|
84
|
-
return r?.(e), { sent: !0 };
|
|
85
|
-
if (t === "memory.get") {
|
|
86
|
-
const { key: i } = ut(e), a = o.getItem(String(i));
|
|
87
|
-
return a ? JSON.parse(a) : null;
|
|
88
|
-
}
|
|
89
|
-
if (t === "memory.set") {
|
|
90
|
-
const { key: i, value: a } = lt(e);
|
|
91
|
-
return o.setItem(String(i), JSON.stringify(a ?? null)), { ok: !0 };
|
|
92
|
-
}
|
|
93
|
-
throw new Error(`Unknown RPC method: ${t}`);
|
|
94
|
-
}
|
|
95
|
-
function ft() {
|
|
96
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
97
|
-
}
|
|
98
|
-
function R(t) {
|
|
99
|
-
return Math.max(0, Math.round(performance.now() - t));
|
|
100
|
-
}
|
|
101
|
-
function E(t) {
|
|
102
|
-
return typeof t == "object" && t !== null && !Array.isArray(t);
|
|
103
|
-
}
|
|
104
|
-
function pt(t) {
|
|
105
|
-
const { accountId: e, locale: n = "en-GB", parentUrl: r = "", threadId: o, incomingContext: i } = t, a = E(i) ? i : {}, s = E(a.thread) ? a.thread : {}, c = E(a.panel) ? a.panel : {}, u = E(a.meta) ? a.meta : {}, l = Q(a.messages), d = {
|
|
106
|
-
id: String(o || s.id || self.crypto.randomUUID()),
|
|
107
|
-
started_at: String(s.started_at || ft()),
|
|
108
|
-
extensions: E(s.extensions) ? { ...s.extensions } : {}
|
|
109
|
-
}, m = String(u.locale || n), p = String(u.parentUrl || r || typeof self < "u" && self.location?.href || "");
|
|
110
|
-
return {
|
|
111
|
-
panel: { ...c },
|
|
112
|
-
messages: l,
|
|
113
|
-
thread: d,
|
|
114
|
-
meta: {
|
|
115
|
-
locale: m,
|
|
116
|
-
parentUrl: p,
|
|
117
|
-
accountId: e
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
function mt(t, e) {
|
|
122
|
-
const n = Q([e])[0];
|
|
123
|
-
return n ? {
|
|
124
|
-
...t,
|
|
125
|
-
messages: [...t.messages, n].slice(-50)
|
|
126
|
-
} : t;
|
|
127
|
-
}
|
|
128
|
-
function Q(t) {
|
|
129
|
-
return Array.isArray(t) ? t.map((e) => {
|
|
130
|
-
const n = e?.role;
|
|
131
|
-
return {
|
|
132
|
-
role: n === "model" ? "assistant" : typeof n == "string" ? n : "",
|
|
133
|
-
content: String(e?.content || "")
|
|
134
|
-
};
|
|
135
|
-
}).filter((e) => (e.role === "user" || e.role === "assistant") && !!e.content).slice(-50) : [];
|
|
136
|
-
}
|
|
137
|
-
var yt = "gengage:agent:context:";
|
|
138
|
-
async function gt({ accountId: t, threadId: e, rpc: n }) {
|
|
139
|
-
const r = await n("memory.get", {
|
|
140
|
-
tier: "session",
|
|
141
|
-
key: Y(t, e)
|
|
142
|
-
});
|
|
143
|
-
return r && typeof r == "object" && !Array.isArray(r) ? r : {};
|
|
144
|
-
}
|
|
145
|
-
async function ht({ accountId: t, threadId: e, extensions: n, rpc: r }) {
|
|
146
|
-
await r("memory.set", {
|
|
147
|
-
tier: "session",
|
|
148
|
-
key: Y(t, e),
|
|
149
|
-
value: { thread: { extensions: n } }
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
function Y(t, e) {
|
|
153
|
-
return `${yt}${t}:${e}`;
|
|
154
|
-
}
|
|
155
|
-
function h(t) {
|
|
156
|
-
return typeof t == "object" && t !== null && !Array.isArray(t);
|
|
157
|
-
}
|
|
158
|
-
var le = class {
|
|
159
|
-
#t = /* @__PURE__ */ new Map();
|
|
160
|
-
#e;
|
|
161
|
-
#r;
|
|
162
|
-
#o;
|
|
163
|
-
#n;
|
|
164
|
-
constructor({ accountId: t, locale: e, parentUrl: n, rpc: r }) {
|
|
165
|
-
this.#e = t, this.#r = e, this.#o = n, this.#n = r;
|
|
166
|
-
}
|
|
167
|
-
async load(t) {
|
|
168
|
-
const e = t?.meta?.threadId || t?.session_id || t?.sessionId, n = String(e || "default"), r = this.#t.get(n);
|
|
169
|
-
if (r) return r;
|
|
170
|
-
const o = await gt({
|
|
171
|
-
accountId: this.#e,
|
|
172
|
-
threadId: n,
|
|
173
|
-
rpc: this.#n
|
|
174
|
-
}), i = pt({
|
|
175
|
-
accountId: this.#e,
|
|
176
|
-
locale: t?.locale || this.#r,
|
|
177
|
-
parentUrl: this.#o,
|
|
178
|
-
threadId: n,
|
|
179
|
-
incomingContext: wt(o, t?.context)
|
|
180
|
-
});
|
|
181
|
-
return this.#t.set(n, i), i;
|
|
182
|
-
}
|
|
183
|
-
patch(t, e) {
|
|
184
|
-
const n = String(t || "default"), r = this.#t.get(n);
|
|
185
|
-
if (!r) return null;
|
|
186
|
-
const o = X(r, typeof e == "function" ? e(r) : e);
|
|
187
|
-
return this.#t.set(n, o), o;
|
|
188
|
-
}
|
|
189
|
-
appendUserMessage(t, e) {
|
|
190
|
-
const n = String(t || "default");
|
|
191
|
-
if (!e) return this.#t.get(n) ?? null;
|
|
192
|
-
const r = this.#t.get(n);
|
|
193
|
-
if (!r) return null;
|
|
194
|
-
const o = mt(r, {
|
|
195
|
-
role: "user",
|
|
196
|
-
content: e
|
|
197
|
-
});
|
|
198
|
-
return this.#t.set(n, o), o;
|
|
199
|
-
}
|
|
200
|
-
async commit(t) {
|
|
201
|
-
const e = String(t || "default"), n = this.#t.get(e);
|
|
202
|
-
return n ? (await ht({
|
|
203
|
-
accountId: this.#e,
|
|
204
|
-
threadId: e,
|
|
205
|
-
extensions: n.thread.extensions,
|
|
206
|
-
rpc: this.#n
|
|
207
|
-
}), n) : null;
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
function wt(t, e) {
|
|
211
|
-
return !h(t) && !h(e) ? {} : X(h(t) ? t : {}, h(e) ? e : {});
|
|
212
|
-
}
|
|
213
|
-
function X(t, e) {
|
|
214
|
-
if (!h(e)) return t;
|
|
215
|
-
const n = t, r = e, o = h(n.panel) ? n.panel : {}, i = h(r.panel) ? r.panel : {}, a = h(n.thread) ? n.thread : {}, s = h(r.thread) ? r.thread : {}, c = h(a.extensions) ? a.extensions : {}, u = h(s.extensions) ? s.extensions : {}, l = h(n.meta) ? n.meta : {}, d = h(r.meta) ? r.meta : {};
|
|
216
|
-
return {
|
|
217
|
-
...t,
|
|
218
|
-
...e,
|
|
219
|
-
panel: {
|
|
220
|
-
...o,
|
|
221
|
-
...i
|
|
222
|
-
},
|
|
223
|
-
thread: {
|
|
224
|
-
...a,
|
|
225
|
-
...s,
|
|
226
|
-
extensions: {
|
|
227
|
-
...c,
|
|
228
|
-
...u
|
|
229
|
-
}
|
|
230
|
-
},
|
|
231
|
-
meta: {
|
|
232
|
-
...l,
|
|
233
|
-
...d
|
|
234
|
-
},
|
|
235
|
-
messages: Array.isArray(r.messages) ? r.messages.slice(-50) : t.messages ?? []
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
function Z(t) {
|
|
239
|
-
const e = String.fromCharCode(...t);
|
|
240
|
-
return btoa(e).replace(/\+/gu, "-").replace(/\//gu, "_").replace(/=+$/u, "");
|
|
241
|
-
}
|
|
242
|
-
function L(t) {
|
|
243
|
-
return Z(new TextEncoder().encode(JSON.stringify(t)));
|
|
244
|
-
}
|
|
245
|
-
async function kt({ accountId: t, devJwtSecret: e, ttlS: n = 300 }) {
|
|
246
|
-
if (!e) throw new Error("devJwtSecret is required for local agent mode.");
|
|
247
|
-
const r = Math.floor(Date.now() / 1e3), o = `${L({
|
|
248
|
-
alg: "HS256",
|
|
249
|
-
typ: "JWT"
|
|
250
|
-
})}.${L({
|
|
251
|
-
sub: t,
|
|
252
|
-
iat: r,
|
|
253
|
-
exp: r + n,
|
|
254
|
-
scope: "invoke",
|
|
255
|
-
jti: crypto.randomUUID?.() || `${r}-${Math.random()}`
|
|
256
|
-
})}`, i = await crypto.subtle.importKey("raw", new TextEncoder().encode(e), {
|
|
257
|
-
name: "HMAC",
|
|
258
|
-
hash: "SHA-256"
|
|
259
|
-
}, !1, ["sign"]), a = await crypto.subtle.sign("HMAC", i, new TextEncoder().encode(o));
|
|
260
|
-
return `${o}.${Z(new Uint8Array(a))}`;
|
|
261
|
-
}
|
|
262
|
-
function bt({ accountId: t, devJwtSecret: e, tokenBrokerUrl: n, tokenBrokerAudience: r, refreshSkewS: o = 30, fetchImpl: i = fetch }) {
|
|
263
|
-
let a = null;
|
|
264
|
-
return async ({ signal: s, parentUrl: c } = {}) => {
|
|
265
|
-
if (e) return kt({
|
|
266
|
-
accountId: t,
|
|
267
|
-
devJwtSecret: e
|
|
268
|
-
});
|
|
269
|
-
if (!n) throw new Error("tokenBrokerUrl is required for production agent mode.");
|
|
270
|
-
const u = Math.floor(Date.now() / 1e3);
|
|
271
|
-
return a?.token && a.expiresAtS - o > u || (a = await _t({
|
|
272
|
-
accountId: t,
|
|
273
|
-
tokenBrokerUrl: n,
|
|
274
|
-
tokenBrokerAudience: r,
|
|
275
|
-
parentUrl: c,
|
|
276
|
-
signal: s,
|
|
277
|
-
fetchImpl: i
|
|
278
|
-
})), a.token;
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
async function _t({ accountId: t, tokenBrokerUrl: e, tokenBrokerAudience: n, parentUrl: r, signal: o, fetchImpl: i }) {
|
|
282
|
-
const a = await i(e, {
|
|
283
|
-
method: "POST",
|
|
284
|
-
credentials: "include",
|
|
285
|
-
headers: {
|
|
286
|
-
accept: "application/json",
|
|
287
|
-
"content-type": "application/json"
|
|
288
|
-
},
|
|
289
|
-
body: JSON.stringify({
|
|
290
|
-
accountId: t,
|
|
291
|
-
scope: "invoke",
|
|
292
|
-
audience: n || void 0,
|
|
293
|
-
parentUrl: r || void 0
|
|
294
|
-
}),
|
|
295
|
-
...o ? { signal: o } : {}
|
|
296
|
-
});
|
|
297
|
-
if (!a.ok) throw new Error(`Token broker request failed (${a.status}).`);
|
|
298
|
-
const s = await a.json(), c = s?.token || s?.jwt || s?.access_token;
|
|
299
|
-
if (!c || typeof c != "string") throw new Error("Token broker response did not include a JWT.");
|
|
300
|
-
return {
|
|
301
|
-
token: c,
|
|
302
|
-
expiresAtS: St(s) || xt(c) || Math.floor(Date.now() / 1e3) + 300
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
function St(t) {
|
|
306
|
-
const e = t?.expiresAtS ?? t?.expires_at_s ?? t?.expiresInS ?? t?.expires_in_s;
|
|
307
|
-
if (Number.isFinite(e)) return Number(e);
|
|
308
|
-
const n = t?.expiresIn ?? t?.expires_in;
|
|
309
|
-
if (Number.isFinite(n)) return Math.floor(Date.now() / 1e3) + Number(n);
|
|
310
|
-
const r = t?.expiresAt ?? t?.expires_at;
|
|
311
|
-
if (typeof r == "string") {
|
|
312
|
-
const o = Date.parse(r);
|
|
313
|
-
if (Number.isFinite(o)) return Math.floor(o / 1e3);
|
|
314
|
-
}
|
|
315
|
-
return null;
|
|
316
|
-
}
|
|
317
|
-
function xt(t) {
|
|
318
|
-
try {
|
|
319
|
-
const [, e] = t.split(".");
|
|
320
|
-
if (!e) return null;
|
|
321
|
-
const n = e.replace(/-/gu, "+").replace(/_/gu, "/"), r = atob(n.padEnd(Math.ceil(n.length / 4) * 4, "=")), o = JSON.parse(r);
|
|
322
|
-
return Number.isFinite(o?.exp) ? Number(o.exp) : null;
|
|
323
|
-
} catch {
|
|
324
|
-
return null;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
var q = {
|
|
328
|
-
unauthorized: {
|
|
329
|
-
code: "auth",
|
|
330
|
-
message: "Assistant authentication failed. Please retry."
|
|
331
|
-
},
|
|
332
|
-
forbidden: {
|
|
333
|
-
code: "auth",
|
|
334
|
-
message: "Assistant authentication failed. Please retry."
|
|
335
|
-
},
|
|
336
|
-
unknown_op: {
|
|
337
|
-
code: "op_unavailable",
|
|
338
|
-
message: "This assistant action is not available yet."
|
|
339
|
-
},
|
|
340
|
-
invalid_input: {
|
|
341
|
-
code: "invalid_request",
|
|
342
|
-
message: "The assistant request was not valid."
|
|
343
|
-
},
|
|
344
|
-
account_config: {
|
|
345
|
-
code: "account_config",
|
|
346
|
-
message: "Assistant configuration is unavailable."
|
|
347
|
-
},
|
|
348
|
-
upstream_llm: {
|
|
349
|
-
code: "op_failed",
|
|
350
|
-
message: "The assistant could not complete that request."
|
|
351
|
-
},
|
|
352
|
-
upstream_timeout: {
|
|
353
|
-
code: "op_timeout",
|
|
354
|
-
message: "The assistant took too long to respond."
|
|
355
|
-
},
|
|
356
|
-
schema_mismatch: {
|
|
357
|
-
code: "op_failed",
|
|
358
|
-
message: "The assistant could not complete that request."
|
|
359
|
-
},
|
|
360
|
-
rate_limited: {
|
|
361
|
-
code: "rate_limited",
|
|
362
|
-
message: "The assistant is receiving too many requests. Please retry shortly."
|
|
363
|
-
},
|
|
364
|
-
internal: {
|
|
365
|
-
code: "op_failed",
|
|
366
|
-
message: "The assistant could not complete that request."
|
|
367
|
-
},
|
|
368
|
-
payload_too_large: {
|
|
369
|
-
code: "invalid_request",
|
|
370
|
-
message: "The assistant request was too large."
|
|
371
|
-
}
|
|
372
|
-
}, tt = class extends Error {
|
|
373
|
-
constructor(t, e, n = {}) {
|
|
374
|
-
super(e), this.name = "AgentError", this.code = t, this.source = n.source || "agent", n.sourceCode && (this.sourceCode = n.sourceCode), n.detail !== void 0 && (this.detail = n.detail);
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
|
-
function et(t) {
|
|
378
|
-
const e = String(t?.code || "upstream_llm"), n = q[e] || q.upstream_llm;
|
|
379
|
-
return new tt(n.code, n.message, {
|
|
380
|
-
source: "be",
|
|
381
|
-
sourceCode: e,
|
|
382
|
-
detail: t?.detail
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
function Tt(t, e) {
|
|
386
|
-
const n = e?.error && typeof e.error == "object" ? e.error : {};
|
|
387
|
-
return et({
|
|
388
|
-
code: String(n.code || At(t)),
|
|
389
|
-
detail: n.detail
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
function de(t) {
|
|
393
|
-
return t instanceof tt ? {
|
|
394
|
-
type: "error",
|
|
395
|
-
code: t.code,
|
|
396
|
-
message: t.message
|
|
397
|
-
} : {
|
|
398
|
-
type: "error",
|
|
399
|
-
code: "agent_invoke_failed",
|
|
400
|
-
message: "The assistant could not complete that request."
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
function At(t) {
|
|
404
|
-
return t === 401 ? "unauthorized" : t === 403 ? "forbidden" : t === 413 ? "payload_too_large" : t === 429 ? "rate_limited" : "internal";
|
|
405
|
-
}
|
|
406
|
-
async function fe({ beUrl: t, accountId: e, devJwtSecret: n, tokenBrokerUrl: r, tokenBrokerAudience: o, jwtProvider: i, parentUrl: a, op: s, input: c, cacheTtlS: u, cacheKey: l, signal: d }) {
|
|
407
|
-
const m = await (i || bt({
|
|
408
|
-
accountId: e,
|
|
409
|
-
devJwtSecret: n,
|
|
410
|
-
tokenBrokerUrl: r,
|
|
411
|
-
tokenBrokerAudience: o
|
|
412
|
-
}))({
|
|
413
|
-
...d ? { signal: d } : {},
|
|
414
|
-
...a ? { parentUrl: a } : {}
|
|
415
|
-
}), { opDomain: p, opName: g } = It(s, e), f = {
|
|
416
|
-
method: "POST",
|
|
417
|
-
headers: {
|
|
418
|
-
authorization: `Bearer ${m}`,
|
|
419
|
-
"content-type": "application/json",
|
|
420
|
-
accept: "application/x-ndjson"
|
|
421
|
-
},
|
|
422
|
-
body: JSON.stringify({
|
|
423
|
-
op_domain: p,
|
|
424
|
-
op_name: g,
|
|
425
|
-
op_payload: c,
|
|
426
|
-
...u !== void 0 ? { cache_ttl_s: u } : {},
|
|
427
|
-
...l !== void 0 ? { cache_key: l } : {}
|
|
428
|
-
}),
|
|
429
|
-
...d ? { signal: d } : {}
|
|
430
|
-
}, _ = await fetch(`${String(t).replace(/\/+$/u, "")}/v1/execute`, f);
|
|
431
|
-
if (!_.ok) throw Tt(_.status, await jt(_));
|
|
432
|
-
return Pt(_);
|
|
433
|
-
}
|
|
434
|
-
function It(t, e) {
|
|
435
|
-
if (!t || t.startsWith("-") || t.endsWith("-")) throw new Error(`Invalid BE op name: ${t}`);
|
|
436
|
-
return {
|
|
437
|
-
opDomain: Et(e),
|
|
438
|
-
opName: t
|
|
439
|
-
};
|
|
440
|
-
}
|
|
441
|
-
function Et(t) {
|
|
442
|
-
return t.replace(/-agentic$/u, "");
|
|
443
|
-
}
|
|
444
|
-
async function jt(t) {
|
|
445
|
-
try {
|
|
446
|
-
return await t.json();
|
|
447
|
-
} catch {
|
|
448
|
-
return { error: { code: t.statusText || "internal" } };
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
async function Pt(t) {
|
|
452
|
-
const e = t.body?.getReader();
|
|
453
|
-
if (!e) throw new Error("BE response body is not readable.");
|
|
454
|
-
const n = new TextDecoder();
|
|
455
|
-
let r = "";
|
|
456
|
-
const o = {};
|
|
457
|
-
for (; ; ) {
|
|
458
|
-
const { value: a, done: s } = await e.read();
|
|
459
|
-
if (s) break;
|
|
460
|
-
r += n.decode(a, { stream: !0 });
|
|
461
|
-
let c = r.indexOf(`
|
|
462
|
-
`);
|
|
463
|
-
for (; c >= 0; ) {
|
|
464
|
-
const u = r.slice(0, c).trim();
|
|
465
|
-
r = r.slice(c + 1), u && J(JSON.parse(u), o), c = r.indexOf(`
|
|
466
|
-
`);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
const i = r.trim();
|
|
470
|
-
return i && J(JSON.parse(i), o), o;
|
|
471
|
-
}
|
|
472
|
-
function J(t, e) {
|
|
473
|
-
if (t._error) throw et(t._error);
|
|
474
|
-
t._end || Object.assign(e, t);
|
|
475
|
-
}
|
|
476
|
-
function pe(t = {}) {
|
|
477
|
-
return {
|
|
478
|
-
type: "metadata",
|
|
479
|
-
...t
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
function C(t, e = !1, n = {}) {
|
|
483
|
-
return {
|
|
484
|
-
type: "text_chunk",
|
|
485
|
-
content: t,
|
|
486
|
-
final: e,
|
|
487
|
-
...n
|
|
488
|
-
};
|
|
489
|
-
}
|
|
490
|
-
function Ct(t) {
|
|
491
|
-
return {
|
|
492
|
-
type: "ui_spec",
|
|
493
|
-
...t
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
function me(t) {
|
|
497
|
-
return {
|
|
498
|
-
type: "action",
|
|
499
|
-
action: t
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
function Mt(t, e) {
|
|
503
|
-
return {
|
|
504
|
-
type: "error",
|
|
505
|
-
code: t,
|
|
506
|
-
message: e
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
function nt() {
|
|
510
|
-
return { type: "done" };
|
|
511
|
-
}
|
|
512
|
-
function Nt(t, e) {
|
|
513
|
-
return t[e?.type || e?.action?.type || "inputText"] || t.inputText;
|
|
514
|
-
}
|
|
515
|
-
async function ye({ request: t, accountModule: e, contextStore: n, beClient: r, toolBridge: o, emit: i, rpc: a, signal: s }) {
|
|
516
|
-
const c = performance.now(), u = await n.load(t), l = u.thread.id, d = Lt(t);
|
|
517
|
-
n.appendUserMessage(l, d);
|
|
518
|
-
const m = Nt(e.flows, t);
|
|
519
|
-
if (!m)
|
|
520
|
-
return i(Mt("unknown_action", `No agent flow for request type ${t?.type || "inputText"}`)), i(nt()), {
|
|
521
|
-
steps: 0,
|
|
522
|
-
productSkusEmitted: []
|
|
523
|
-
};
|
|
524
|
-
const p = {
|
|
525
|
-
request: t,
|
|
526
|
-
context: n.patch(l, {}) || u,
|
|
527
|
-
bag: {},
|
|
528
|
-
accountConfig: e.accountConfig || {},
|
|
529
|
-
threadId: l,
|
|
530
|
-
steps: 0,
|
|
531
|
-
productSkusEmitted: /* @__PURE__ */ new Set(),
|
|
532
|
-
committed: !1
|
|
533
|
-
}, g = {
|
|
534
|
-
contextStore: n,
|
|
535
|
-
beClient: r,
|
|
536
|
-
toolBridge: o,
|
|
537
|
-
emit: i,
|
|
538
|
-
rpc: a,
|
|
539
|
-
adapters: e.adapters || {},
|
|
540
|
-
...s ? { signal: s } : {}
|
|
541
|
-
};
|
|
542
|
-
return await U(m, p, g), p.committed || await $(p, g), await a("beacon.send", {
|
|
543
|
-
type: "turnSummary",
|
|
544
|
-
threadId: l,
|
|
545
|
-
sessionId: t?.session_id || t?.sessionId || l,
|
|
546
|
-
accountId: e.accountId || p.context.meta.accountId,
|
|
547
|
-
steps: p.steps,
|
|
548
|
-
totalLatencyMs: R(c),
|
|
549
|
-
productSkusEmitted: [...p.productSkusEmitted]
|
|
550
|
-
}), {
|
|
551
|
-
steps: p.steps,
|
|
552
|
-
productSkusEmitted: [...p.productSkusEmitted]
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
async function U(t, e, n) {
|
|
556
|
-
for (const r of t) {
|
|
557
|
-
if (n.signal?.aborted) return;
|
|
558
|
-
e.steps += 1, await vt(r, e, n), e.context = n.contextStore.patch(e.threadId, {}) || e.context;
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
async function vt(t, e, n) {
|
|
562
|
-
const r = F(e);
|
|
563
|
-
if (t.kind === "be_op") {
|
|
564
|
-
await Ot(t, e, n, r);
|
|
565
|
-
return;
|
|
566
|
-
}
|
|
567
|
-
if (t.kind === "tool") {
|
|
568
|
-
await Bt(t, e, n, r);
|
|
569
|
-
return;
|
|
570
|
-
}
|
|
571
|
-
if (t.kind === "adapter") {
|
|
572
|
-
await Rt(t, e, n, r);
|
|
573
|
-
return;
|
|
574
|
-
}
|
|
575
|
-
if (t.kind === "emit") {
|
|
576
|
-
Ut(t, e, n);
|
|
577
|
-
return;
|
|
578
|
-
}
|
|
579
|
-
if (t.kind === "branch") {
|
|
580
|
-
await $t(t, e, n, r);
|
|
581
|
-
return;
|
|
582
|
-
}
|
|
583
|
-
if (t.kind === "parallel") {
|
|
584
|
-
await Dt(t, e, n);
|
|
585
|
-
return;
|
|
586
|
-
}
|
|
587
|
-
if (t.kind === "refusal") {
|
|
588
|
-
await Ft(t, e, n, r);
|
|
589
|
-
return;
|
|
590
|
-
}
|
|
591
|
-
t.kind === "commit" && await zt(t, e, n);
|
|
592
|
-
}
|
|
593
|
-
async function Ot(t, e, n, r) {
|
|
594
|
-
const o = performance.now();
|
|
595
|
-
let i;
|
|
596
|
-
const a = T(t.cacheTtlS, r), s = T(t.cacheKey, r);
|
|
597
|
-
try {
|
|
598
|
-
i = await n.beClient.invoke({
|
|
599
|
-
op: t.op,
|
|
600
|
-
input: T(t.input, r),
|
|
601
|
-
...a !== void 0 ? { cacheTtlS: a } : {},
|
|
602
|
-
...s !== void 0 ? { cacheKey: s } : {},
|
|
603
|
-
...n.signal ? { signal: n.signal } : {}
|
|
604
|
-
});
|
|
605
|
-
} catch (u) {
|
|
606
|
-
const l = u, d = String(l?.sourceCode || l?.code || "unknown"), m = {
|
|
607
|
-
type: "agentOp",
|
|
608
|
-
threadId: e.threadId,
|
|
609
|
-
sessionId: e.request?.session_id || e.request?.sessionId || e.threadId,
|
|
610
|
-
accountId: e.context.meta.accountId,
|
|
611
|
-
op: t.op,
|
|
612
|
-
status: "error",
|
|
613
|
-
latencyMs: R(o),
|
|
614
|
-
errorCode: d
|
|
615
|
-
};
|
|
616
|
-
throw await n.rpc("beacon.send", m), u;
|
|
617
|
-
}
|
|
618
|
-
t.out && (e.bag[t.out] = i), D(t, i, e, n.contextStore);
|
|
619
|
-
const c = {
|
|
620
|
-
type: "agentOp",
|
|
621
|
-
threadId: e.threadId,
|
|
622
|
-
sessionId: e.request?.session_id || e.request?.sessionId || e.threadId,
|
|
623
|
-
accountId: e.context.meta.accountId,
|
|
624
|
-
op: t.op,
|
|
625
|
-
status: "ok",
|
|
626
|
-
latencyMs: R(o)
|
|
627
|
-
};
|
|
628
|
-
await n.rpc("beacon.send", c);
|
|
629
|
-
}
|
|
630
|
-
async function Bt(t, e, n, r) {
|
|
631
|
-
const o = await n.toolBridge.invoke(t.name, T(t.input, r));
|
|
632
|
-
t.out && (e.bag[t.out] = o), D(t, o, e, n.contextStore);
|
|
633
|
-
}
|
|
634
|
-
async function Rt(t, e, n, r) {
|
|
635
|
-
const o = n.adapters?.[t.name];
|
|
636
|
-
if (typeof o != "function") throw new Error(`Unknown flow adapter: ${t.name}`);
|
|
637
|
-
const i = await o(T(t.input, r), r);
|
|
638
|
-
t.out && (e.bag[t.out] = i), D(t, i, e, n.contextStore);
|
|
639
|
-
}
|
|
640
|
-
function Ut(t, e, n) {
|
|
641
|
-
const r = t.build(F(e));
|
|
642
|
-
qt(r, e.productSkusEmitted), n.emit(r);
|
|
643
|
-
}
|
|
644
|
-
async function $t(t, e, n, r) {
|
|
645
|
-
const o = String(T(t.on, r) || "default");
|
|
646
|
-
await U(t.cases[o] || t.cases.default || [], e, n);
|
|
647
|
-
}
|
|
648
|
-
async function Dt(t, e, n) {
|
|
649
|
-
await Promise.all(t.steps.map((r) => U(r, e, n)));
|
|
650
|
-
}
|
|
651
|
-
async function Ft(t, e, n, r) {
|
|
652
|
-
n.emit(C(T(t.message, r), !0)), await $(e, n);
|
|
653
|
-
}
|
|
654
|
-
async function zt(t, e, n) {
|
|
655
|
-
await $(e, n);
|
|
656
|
-
}
|
|
657
|
-
async function $(t, { contextStore: e, emit: n }) {
|
|
658
|
-
t.committed || (t.context = await e.commit(t.threadId) || t.context, t.committed = !0, n(nt()));
|
|
659
|
-
}
|
|
660
|
-
function D(t, e, n, r) {
|
|
661
|
-
if (typeof t.patch != "function") return;
|
|
662
|
-
const o = t.patch(n.context, e, F(n));
|
|
663
|
-
o && (n.context = r.patch(n.threadId, o) || n.context);
|
|
664
|
-
}
|
|
665
|
-
function F(t) {
|
|
666
|
-
return {
|
|
667
|
-
request: t.request,
|
|
668
|
-
context: t.context,
|
|
669
|
-
bag: t.bag,
|
|
670
|
-
accountConfig: t.accountConfig
|
|
671
|
-
};
|
|
672
|
-
}
|
|
673
|
-
function T(t, e) {
|
|
674
|
-
return typeof t == "function" ? t(e) : t;
|
|
675
|
-
}
|
|
676
|
-
function Lt(t) {
|
|
677
|
-
const e = t?.payload;
|
|
678
|
-
if (typeof e == "string") return e;
|
|
679
|
-
if (e && typeof e == "object" && "text" in e) {
|
|
680
|
-
const n = e.text;
|
|
681
|
-
if (typeof n == "string") return n;
|
|
682
|
-
}
|
|
683
|
-
return typeof t?.action?.payload == "string" ? t.action.payload : typeof t?.action?.title == "string" ? t.action.title : "";
|
|
684
|
-
}
|
|
685
|
-
function qt(t, e) {
|
|
686
|
-
const n = t, r = n.spec, o = Array.isArray(r?.items) ? r.items : void 0, i = Array.isArray(n.items) ? n.items : void 0, a = o || i;
|
|
687
|
-
if (Array.isArray(a)) {
|
|
688
|
-
for (const s of a) if (s && typeof s == "object") {
|
|
689
|
-
const c = s.sku;
|
|
690
|
-
typeof c == "string" && e.add(c);
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
function ge(t) {
|
|
695
|
-
return { invoke(e, n) {
|
|
696
|
-
return t("tool.invoke", {
|
|
697
|
-
name: e,
|
|
698
|
-
input: n
|
|
699
|
-
});
|
|
700
|
-
} };
|
|
701
|
-
}
|
|
702
|
-
function rt(t) {
|
|
703
|
-
return t && typeof t == "object" && !Array.isArray(t) ? t : null;
|
|
704
|
-
}
|
|
705
|
-
function z(t) {
|
|
706
|
-
const e = rt(t);
|
|
707
|
-
if (!e) return null;
|
|
708
|
-
const n = A(e.sku, e.SKU);
|
|
709
|
-
if (!n) return null;
|
|
710
|
-
const r = {
|
|
711
|
-
sku: n,
|
|
712
|
-
name: A(e.name, e.title, e.short_name, n) || n,
|
|
713
|
-
url: A(e.url) || ""
|
|
714
|
-
}, o = Array.isArray(e.images) ? e.images : void 0, i = A(e.imageUrl, e.image_url, e.image, o?.[0]);
|
|
715
|
-
i && (r.imageUrl = i), o && o.length > 1 && (r.images = o.filter((f) => !!f).map(String));
|
|
716
|
-
const a = j(e.price_discounted), s = j(e.price), c = a || s;
|
|
717
|
-
c > 0 && (r.price = String(c));
|
|
718
|
-
const u = a > 0 ? s : 0;
|
|
719
|
-
u > 0 && (r.originalPrice = String(u));
|
|
720
|
-
const l = A(e.brand);
|
|
721
|
-
l && (r.brand = l);
|
|
722
|
-
const d = j(e.rating);
|
|
723
|
-
d > 0 && (r.rating = d);
|
|
724
|
-
const m = j(e.review_count) || j(e.reviewCount);
|
|
725
|
-
m > 0 && (r.reviewCount = m);
|
|
726
|
-
const p = A(e.cart_code, e.cartCode);
|
|
727
|
-
p && (r.cartCode = p), typeof e.in_stock == "boolean" && (r.inStock = e.in_stock), typeof e.inStock == "boolean" && (r.inStock = e.inStock);
|
|
728
|
-
const g = e.category_names;
|
|
729
|
-
return Array.isArray(g) && (r.categoryNames = g.map(String)), r;
|
|
730
|
-
}
|
|
731
|
-
function Jt(t) {
|
|
732
|
-
const e = rt(t);
|
|
733
|
-
if (!e) return t;
|
|
734
|
-
const n = e.category_names, r = Array.isArray(n) ? n : void 0, o = e.images, i = Array.isArray(o) ? o : void 0, a = {
|
|
735
|
-
sku: e.sku,
|
|
736
|
-
name: e.name || e.title,
|
|
737
|
-
url: e.url,
|
|
738
|
-
price: e.price,
|
|
739
|
-
currency: e.price_currency || e.currency,
|
|
740
|
-
category: r?.[r.length - 1] ?? void 0,
|
|
741
|
-
category_names: r ? r.slice(0, 4) : void 0,
|
|
742
|
-
image: i ? i[0] : e.image,
|
|
743
|
-
in_stock: e.in_stock,
|
|
744
|
-
rating: e.rating,
|
|
745
|
-
review_count: e.review_count
|
|
746
|
-
};
|
|
747
|
-
for (const s of Object.keys(a)) a[s] === void 0 && delete a[s];
|
|
748
|
-
return a;
|
|
749
|
-
}
|
|
750
|
-
function ot(t) {
|
|
751
|
-
return Array.isArray(t) ? t.map(Jt).filter((e) => !!e) : [];
|
|
752
|
-
}
|
|
753
|
-
function A(...t) {
|
|
754
|
-
for (const e of t) if (typeof e == "string" && e.trim()) return e.trim();
|
|
755
|
-
return "";
|
|
756
|
-
}
|
|
757
|
-
function j(t) {
|
|
758
|
-
const e = Number(t);
|
|
759
|
-
return Number.isFinite(e) ? e : 0;
|
|
760
|
-
}
|
|
761
|
-
function K(t) {
|
|
762
|
-
return Array.isArray(t) ? t.map(String).filter(Boolean) : typeof t == "string" && t ? [t] : [];
|
|
763
|
-
}
|
|
764
|
-
function Kt(t = []) {
|
|
765
|
-
const e = {}, n = [];
|
|
766
|
-
return (Array.isArray(t) ? t.map(z).filter((r) => !!r) : []).forEach((r, o) => {
|
|
767
|
-
const i = `product-${o.toString()}`;
|
|
768
|
-
n.push(i);
|
|
769
|
-
const a = {
|
|
770
|
-
sku: r.sku,
|
|
771
|
-
product: r
|
|
772
|
-
};
|
|
773
|
-
e[i] = {
|
|
774
|
-
type: "ProductCard",
|
|
775
|
-
props: {
|
|
776
|
-
product: r,
|
|
777
|
-
index: o,
|
|
778
|
-
action: {
|
|
779
|
-
title: r.name,
|
|
780
|
-
type: "launchSingleProduct",
|
|
781
|
-
payload: a
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
};
|
|
785
|
-
}), e.root = {
|
|
786
|
-
type: "ProductGrid",
|
|
787
|
-
props: { layout: "grid" },
|
|
788
|
-
children: n
|
|
789
|
-
}, {
|
|
790
|
-
widget: "chat",
|
|
791
|
-
panelHint: "panel",
|
|
792
|
-
spec: {
|
|
793
|
-
root: "root",
|
|
794
|
-
elements: e
|
|
795
|
-
}
|
|
796
|
-
};
|
|
797
|
-
}
|
|
798
|
-
function he(t) {
|
|
799
|
-
return {
|
|
800
|
-
widget: "chat",
|
|
801
|
-
panelHint: "panel",
|
|
802
|
-
spec: {
|
|
803
|
-
root: "root",
|
|
804
|
-
elements: { root: {
|
|
805
|
-
type: "ProductDetailsPanel",
|
|
806
|
-
props: { product: z(t) || t || {} }
|
|
807
|
-
} }
|
|
808
|
-
}
|
|
809
|
-
};
|
|
810
|
-
}
|
|
811
|
-
function we(t = {}) {
|
|
812
|
-
const e = (t.multiple_product_details || t.products || []).map(z).filter((r) => !!r), n = t.table || {};
|
|
813
|
-
return {
|
|
814
|
-
widget: "chat",
|
|
815
|
-
panelHint: "panel",
|
|
816
|
-
spec: {
|
|
817
|
-
root: "root",
|
|
818
|
-
elements: { root: {
|
|
819
|
-
type: "ComparisonTable",
|
|
820
|
-
props: {
|
|
821
|
-
products: e,
|
|
822
|
-
recommended: e.find((r) => r.sku === t.recommended_choice_sku) || e[0],
|
|
823
|
-
attributes: Object.entries(n).map(([r, o]) => ({
|
|
824
|
-
label: r,
|
|
825
|
-
values: Array.isArray(o) ? o.map(String) : [String(o ?? "")]
|
|
826
|
-
})),
|
|
827
|
-
highlights: K(t.key_differences),
|
|
828
|
-
specialCases: K(t.special_considerations),
|
|
829
|
-
recommendedText: t.recommended_choice,
|
|
830
|
-
productActions: Object.fromEntries(e.map((r) => [r.sku, {
|
|
831
|
-
title: r.name,
|
|
832
|
-
type: "launchSingleProduct",
|
|
833
|
-
payload: {
|
|
834
|
-
sku: r.sku,
|
|
835
|
-
product: r
|
|
836
|
-
}
|
|
837
|
-
}]))
|
|
838
|
-
}
|
|
839
|
-
} }
|
|
840
|
-
}
|
|
841
|
-
};
|
|
842
|
-
}
|
|
843
|
-
function ke(t = []) {
|
|
844
|
-
return {
|
|
845
|
-
widget: "chat",
|
|
846
|
-
panelHint: "inline",
|
|
847
|
-
spec: {
|
|
848
|
-
root: "root",
|
|
849
|
-
elements: { root: {
|
|
850
|
-
type: "ActionButtons",
|
|
851
|
-
props: { buttons: (Array.isArray(t) ? t : []).map((e) => {
|
|
852
|
-
const n = e.label || e.title || e.shortName || "", r = e.action || e.requestDetails || e.request_details;
|
|
853
|
-
return !n || !r?.type ? null : {
|
|
854
|
-
label: n,
|
|
855
|
-
action: {
|
|
856
|
-
title: n,
|
|
857
|
-
type: r.type,
|
|
858
|
-
...r.payload !== void 0 ? { payload: r.payload } : {}
|
|
859
|
-
}
|
|
860
|
-
};
|
|
861
|
-
}).filter((e) => !!e) }
|
|
862
|
-
} }
|
|
863
|
-
}
|
|
864
|
-
};
|
|
865
|
-
}
|
|
866
|
-
function N(t) {
|
|
867
|
-
const e = t?.payload;
|
|
868
|
-
if (typeof e == "string") return e;
|
|
869
|
-
if (e && typeof e == "object" && "text" in e) {
|
|
870
|
-
const r = e.text;
|
|
871
|
-
if (typeof r == "string") return r;
|
|
872
|
-
}
|
|
873
|
-
const n = t?.action;
|
|
874
|
-
return n && typeof n.payload == "string" ? n.payload : n && typeof n.title == "string" ? n.title : "";
|
|
875
|
-
}
|
|
876
|
-
function Wt(t) {
|
|
877
|
-
return Object.freeze([...t]);
|
|
878
|
-
}
|
|
879
|
-
function S(t) {
|
|
880
|
-
return t && typeof t == "object" ? t : {};
|
|
881
|
-
}
|
|
882
|
-
function v(t) {
|
|
883
|
-
return t && typeof t == "object" ? t : {};
|
|
884
|
-
}
|
|
885
|
-
function W(t) {
|
|
886
|
-
return t.thread.extensions.beauty_profile;
|
|
887
|
-
}
|
|
888
|
-
var be = Wt([{
|
|
889
|
-
kind: "be_op",
|
|
890
|
-
op: "beauty-consulting-turn",
|
|
891
|
-
input: ({ request: t, context: e }) => ({
|
|
892
|
-
utterance: N(t),
|
|
893
|
-
prior_messages: e.messages.slice(-10),
|
|
894
|
-
profile: W(e),
|
|
895
|
-
candidate_products: Vt(t),
|
|
896
|
-
locale: e.meta.locale
|
|
897
|
-
}),
|
|
898
|
-
out: "consultation",
|
|
899
|
-
patch: H
|
|
900
|
-
}, {
|
|
901
|
-
kind: "branch",
|
|
902
|
-
on: ({ bag: t }) => S(t.consultation).consultation_state?.stage || "answer",
|
|
903
|
-
cases: {
|
|
904
|
-
refuse: [{
|
|
905
|
-
kind: "refusal",
|
|
906
|
-
message: ({ bag: t }) => {
|
|
907
|
-
const e = S(t.consultation);
|
|
908
|
-
return e.refusal?.message || e.plain_text || "I cannot help with that request.";
|
|
909
|
-
}
|
|
910
|
-
}],
|
|
911
|
-
needs_more_info: [{
|
|
912
|
-
kind: "emit",
|
|
913
|
-
build: ({ bag: t }) => C(B(S(t.consultation)), !0)
|
|
914
|
-
}, { kind: "commit" }],
|
|
915
|
-
search: [
|
|
916
|
-
{
|
|
917
|
-
kind: "tool",
|
|
918
|
-
name: "search",
|
|
919
|
-
input: ({ request: t, bag: e, context: n }) => {
|
|
920
|
-
const r = S(e.consultation);
|
|
921
|
-
return {
|
|
922
|
-
query: r.search_params?.query || N(t),
|
|
923
|
-
facets: r.search_params?.facets || {},
|
|
924
|
-
limit: 12,
|
|
925
|
-
locale: n.meta.locale
|
|
926
|
-
};
|
|
927
|
-
},
|
|
928
|
-
out: "products",
|
|
929
|
-
patch: (t, e) => {
|
|
930
|
-
const n = v(e);
|
|
931
|
-
return { panel: {
|
|
932
|
-
...t.panel,
|
|
933
|
-
screen_sku_list: O(n).map((r) => Ht(r)).filter((r) => !!r),
|
|
934
|
-
last_search: { query: n.query || "" }
|
|
935
|
-
} };
|
|
936
|
-
}
|
|
937
|
-
},
|
|
938
|
-
{
|
|
939
|
-
kind: "emit",
|
|
940
|
-
build: ({ bag: t }) => Ct(Kt(O(v(t.products))))
|
|
941
|
-
},
|
|
942
|
-
{
|
|
943
|
-
kind: "be_op",
|
|
944
|
-
op: "beauty-consulting-turn",
|
|
945
|
-
input: ({ request: t, context: e, bag: n }) => ({
|
|
946
|
-
utterance: N(t),
|
|
947
|
-
prior_messages: e.messages.slice(-10),
|
|
948
|
-
profile: W(e),
|
|
949
|
-
candidate_products: ot(O(v(n.products)).slice(0, 12)),
|
|
950
|
-
locale: e.meta.locale
|
|
951
|
-
}),
|
|
952
|
-
out: "answer",
|
|
953
|
-
patch: (t, e) => {
|
|
954
|
-
const n = H(t, e), r = (S(e).product_mentions || []).map((o) => o.sku).filter((o) => !!o);
|
|
955
|
-
return {
|
|
956
|
-
...n || {},
|
|
957
|
-
panel: {
|
|
958
|
-
...t.panel,
|
|
959
|
-
chat_mentioned_skus: r
|
|
960
|
-
}
|
|
961
|
-
};
|
|
962
|
-
}
|
|
963
|
-
},
|
|
964
|
-
{
|
|
965
|
-
kind: "emit",
|
|
966
|
-
build: ({ bag: t }) => {
|
|
967
|
-
const e = S(t.answer);
|
|
968
|
-
return C(B(e), !0, { productMentions: e.product_mentions || [] });
|
|
969
|
-
}
|
|
970
|
-
},
|
|
971
|
-
{ kind: "commit" }
|
|
972
|
-
],
|
|
973
|
-
default: [{
|
|
974
|
-
kind: "emit",
|
|
975
|
-
build: ({ bag: t }) => {
|
|
976
|
-
const e = S(t.consultation);
|
|
977
|
-
return C(B(e), !0, { productMentions: e.product_mentions || [] });
|
|
978
|
-
}
|
|
979
|
-
}, { kind: "commit" }]
|
|
980
|
-
}
|
|
981
|
-
}]);
|
|
982
|
-
function H(t, e) {
|
|
983
|
-
const n = S(e).consultation_state?.captured_profile;
|
|
984
|
-
if (!n) return null;
|
|
985
|
-
const r = t.thread.extensions.beauty_profile && typeof t.thread.extensions.beauty_profile == "object" ? t.thread.extensions.beauty_profile : {};
|
|
986
|
-
return { thread: {
|
|
987
|
-
...t.thread,
|
|
988
|
-
extensions: {
|
|
989
|
-
...t.thread.extensions,
|
|
990
|
-
beauty_profile: {
|
|
991
|
-
...r,
|
|
992
|
-
...n
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
} };
|
|
996
|
-
}
|
|
997
|
-
function O(t) {
|
|
998
|
-
return Array.isArray(t?.products) ? t.products : [];
|
|
999
|
-
}
|
|
1000
|
-
function Ht(t) {
|
|
1001
|
-
if (t && typeof t == "object" && "sku" in t) {
|
|
1002
|
-
const e = t.sku;
|
|
1003
|
-
if (typeof e == "string") return e;
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
function Vt(t) {
|
|
1007
|
-
const e = t?.payload && typeof t.payload == "object" ? t.payload.products : void 0, n = t?.action?.payload && typeof t.action.payload == "object" ? t.action.payload.products : void 0, r = e || n;
|
|
1008
|
-
return Array.isArray(r) ? ot(r.slice(0, 12)) : void 0;
|
|
1009
|
-
}
|
|
1010
|
-
function B(t) {
|
|
1011
|
-
return t?.answer_html || t?.plain_text || t?.refusal?.message || "I can help with beauty shopping.";
|
|
1012
|
-
}
|
|
1013
|
-
var V = /* @__PURE__ */ new Set([
|
|
1014
|
-
"and",
|
|
1015
|
-
"are",
|
|
1016
|
-
"box",
|
|
1017
|
-
"for",
|
|
1018
|
-
"from",
|
|
1019
|
-
"gift",
|
|
1020
|
-
"gifts",
|
|
1021
|
-
"the",
|
|
1022
|
-
"with"
|
|
1023
|
-
]), Gt = {
|
|
1024
|
-
token: 0.26,
|
|
1025
|
-
keyword: 0.22,
|
|
1026
|
-
category: 0.18,
|
|
1027
|
-
facet: 0.16,
|
|
1028
|
-
color: 0.08,
|
|
1029
|
-
attribute: 0.06,
|
|
1030
|
-
price: 0.08,
|
|
1031
|
-
retrieval: 0.08
|
|
1032
|
-
}, Qt = [
|
|
1033
|
-
"amber",
|
|
1034
|
-
"beige",
|
|
1035
|
-
"black",
|
|
1036
|
-
"blue",
|
|
1037
|
-
"blush",
|
|
1038
|
-
"bronze",
|
|
1039
|
-
"brown",
|
|
1040
|
-
"cream",
|
|
1041
|
-
"gold",
|
|
1042
|
-
"green",
|
|
1043
|
-
"grey",
|
|
1044
|
-
"ivory",
|
|
1045
|
-
"lilac",
|
|
1046
|
-
"mixed",
|
|
1047
|
-
"orange",
|
|
1048
|
-
"pastel",
|
|
1049
|
-
"pink",
|
|
1050
|
-
"purple",
|
|
1051
|
-
"red",
|
|
1052
|
-
"silver",
|
|
1053
|
-
"white",
|
|
1054
|
-
"yellow"
|
|
1055
|
-
];
|
|
1056
|
-
function x(t) {
|
|
1057
|
-
return String(t ?? "").normalize("NFKD").replace(new RegExp("\\p{Diacritic}", "gu"), "").toLowerCase().replace(/[^\p{L}\p{N}]+/gu, " ").replace(/\s+/gu, " ").trim();
|
|
1058
|
-
}
|
|
1059
|
-
function w(t, e = V) {
|
|
1060
|
-
const n = e instanceof Set ? e : /* @__PURE__ */ new Set([...V, ...e]), r = /* @__PURE__ */ new Set(), o = [];
|
|
1061
|
-
for (const i of x(t).split(/\s+/u))
|
|
1062
|
-
i.length < 3 || n.has(i) || r.has(i) || (r.add(i), o.push(i));
|
|
1063
|
-
return o;
|
|
1064
|
-
}
|
|
1065
|
-
function M(t, e = {}) {
|
|
1066
|
-
if (Xt(t)) return t;
|
|
1067
|
-
const n = e.facetKeys, r = y(t.category_names ?? t.category), o = y(t.category_ids), i = Zt(t.facet_hits), a = Object.entries(i).filter(([f]) => !n || n.some((_) => x(_) === x(f))).map(([, f]) => f), s = k(t.name, t.title), c = k(t.brand), u = e.sourceKeywords ?? [], l = [
|
|
1068
|
-
s,
|
|
1069
|
-
c,
|
|
1070
|
-
...r,
|
|
1071
|
-
...a,
|
|
1072
|
-
...y(t.promotions),
|
|
1073
|
-
k(t.description),
|
|
1074
|
-
...u
|
|
1075
|
-
].join(" "), d = w(l, e.stopWords), m = k(e.sourceProductType, ne(r, s, d), d[0]), p = b([...ee(l, Qt), ...Object.entries(i).filter(([f]) => /colou?r/iu.test(f)).flatMap(([, f]) => w(f, e.stopWords))]), g = b([...a.flatMap((f) => w(f, e.stopWords)), ...y(t.promotions).flatMap((f) => w(f, e.stopWords))]).slice(0, 24);
|
|
1076
|
-
return {
|
|
1077
|
-
sku: k(t.sku),
|
|
1078
|
-
title: s,
|
|
1079
|
-
brand: c,
|
|
1080
|
-
productType: m,
|
|
1081
|
-
categoryNames: r,
|
|
1082
|
-
categoryIds: o,
|
|
1083
|
-
facets: i,
|
|
1084
|
-
keywords: b([...u.flatMap((f) => w(f, e.stopWords)), ...d]).slice(0, 12),
|
|
1085
|
-
tokens: d,
|
|
1086
|
-
colors: p,
|
|
1087
|
-
attributes: g,
|
|
1088
|
-
price: te(t)
|
|
1089
|
-
};
|
|
1090
|
-
}
|
|
1091
|
-
function _e(t, e = {}) {
|
|
1092
|
-
const n = k(t.product_type, t.productType), r = k(t.title, n, y(t.keywords).join(" ")), o = b([
|
|
1093
|
-
...y(t.keywords),
|
|
1094
|
-
...y(t.colors),
|
|
1095
|
-
...y(t.materials),
|
|
1096
|
-
...y(t.styles),
|
|
1097
|
-
...y(t.attributes)
|
|
1098
|
-
]);
|
|
1099
|
-
return M({
|
|
1100
|
-
sku: "__photo__",
|
|
1101
|
-
name: r,
|
|
1102
|
-
category_names: n ? [n] : [],
|
|
1103
|
-
facet_hits: {
|
|
1104
|
-
colors: y(t.colors).join(", "),
|
|
1105
|
-
materials: y(t.materials).join(", "),
|
|
1106
|
-
styles: y(t.styles).join(", "),
|
|
1107
|
-
attributes: y(t.attributes).join(", ")
|
|
1108
|
-
},
|
|
1109
|
-
promotions: o
|
|
1110
|
-
}, {
|
|
1111
|
-
...e,
|
|
1112
|
-
sourceProductType: n,
|
|
1113
|
-
sourceKeywords: o
|
|
1114
|
-
});
|
|
1115
|
-
}
|
|
1116
|
-
function Se(t, e = {}) {
|
|
1117
|
-
const n = M(t, e);
|
|
1118
|
-
return b([
|
|
1119
|
-
...e.sourceQueries ?? [],
|
|
1120
|
-
P([
|
|
1121
|
-
n.productType,
|
|
1122
|
-
...n.colors.slice(0, 1),
|
|
1123
|
-
...n.attributes.slice(0, 2)
|
|
1124
|
-
]),
|
|
1125
|
-
P([n.productType, ...n.keywords.slice(0, 3)]),
|
|
1126
|
-
P([n.categoryNames[n.categoryNames.length - 1], ...n.keywords.slice(0, 2)]),
|
|
1127
|
-
P(n.title.split(/\s+/u).slice(0, 6)),
|
|
1128
|
-
n.productType
|
|
1129
|
-
].map((r) => r.trim()).filter(Boolean)).slice(0, e.queryLimit ?? 6);
|
|
1130
|
-
}
|
|
1131
|
-
function Yt(t, e, n = {}) {
|
|
1132
|
-
const r = {
|
|
1133
|
-
...Gt,
|
|
1134
|
-
...n.weights
|
|
1135
|
-
}, o = M(e, n), i = [], a = I(t.tokens, o.tokens), s = I(t.keywords, o.tokens), c = re(t.categoryNames, o.categoryNames) || I(G(t.categoryNames), G(o.categoryNames)), u = I(t.attributes, o.attributes), l = I(t.colors, o.colors), d = I(t.attributes, o.tokens), m = oe(t.price, o.price), p = ie(o.sku, n.hitCounts) > 0 ? 1 : 0, g = ae(t, o), f = a * r.token + s * r.keyword + c * r.category + u * r.facet + l * r.color + d * r.attribute + m * r.price + p * r.retrieval, _ = se(g ? f : f * 0.35);
|
|
1136
|
-
return g && t.productType && t.productType === o.productType && i.push("same product type"), c > 0.4 && i.push("similar category"), u > 0.2 && i.push("matching product attributes"), l > 0 && i.push("matching colour"), m > 0.8 && i.push("similar price"), g || i.push("weaker product-type match"), {
|
|
1137
|
-
score: Number(_.toFixed(4)),
|
|
1138
|
-
reasons: i
|
|
1139
|
-
};
|
|
1140
|
-
}
|
|
1141
|
-
function xe(t, e, n = {}) {
|
|
1142
|
-
const r = M(t, n), o = new Set([r.sku, ...n.ignoreSkus ?? []].filter(Boolean));
|
|
1143
|
-
return e.filter((i) => {
|
|
1144
|
-
const a = k(i.sku);
|
|
1145
|
-
return a && !o.has(a);
|
|
1146
|
-
}).map((i) => {
|
|
1147
|
-
const a = Yt(r, i, n);
|
|
1148
|
-
return {
|
|
1149
|
-
...i,
|
|
1150
|
-
similarity_score: a.score,
|
|
1151
|
-
similarity_reasons: a.reasons
|
|
1152
|
-
};
|
|
1153
|
-
}).sort((i, a) => a.similarity_score - i.similarity_score).slice(0, Math.max(1, Math.min(n.limit ?? 12, 100)));
|
|
1154
|
-
}
|
|
1155
|
-
function Xt(t) {
|
|
1156
|
-
return !!(t && typeof t == "object" && Array.isArray(t.tokens));
|
|
1157
|
-
}
|
|
1158
|
-
function k(...t) {
|
|
1159
|
-
for (const e of t) if (typeof e == "string" && e.trim()) return e.trim();
|
|
1160
|
-
return "";
|
|
1161
|
-
}
|
|
1162
|
-
function y(t) {
|
|
1163
|
-
return Array.isArray(t) ? t.map((e) => k(e)).filter(Boolean) : typeof t == "string" && t.trim() ? t.split(/[,;/|]+/u).map((e) => e.trim()).filter(Boolean) : [];
|
|
1164
|
-
}
|
|
1165
|
-
function Zt(t) {
|
|
1166
|
-
return !t || typeof t != "object" || Array.isArray(t) ? {} : Object.fromEntries(Object.entries(t).map(([e, n]) => [e, k(n)]).filter(([, e]) => e));
|
|
1167
|
-
}
|
|
1168
|
-
function te(t) {
|
|
1169
|
-
const e = Number(t.price_discounted);
|
|
1170
|
-
if (Number.isFinite(e) && e > 0) return e;
|
|
1171
|
-
const n = Number(t.price);
|
|
1172
|
-
return Number.isFinite(n) && n > 0 ? n : 0;
|
|
1173
|
-
}
|
|
1174
|
-
function b(t) {
|
|
1175
|
-
const e = /* @__PURE__ */ new Set(), n = [];
|
|
1176
|
-
for (const r of t) {
|
|
1177
|
-
const o = x(r);
|
|
1178
|
-
!o || e.has(o) || (e.add(o), n.push(o));
|
|
1179
|
-
}
|
|
1180
|
-
return n;
|
|
1181
|
-
}
|
|
1182
|
-
function ee(t, e) {
|
|
1183
|
-
const n = ` ${x(t)} `;
|
|
1184
|
-
return e.filter((r) => n.includes(` ${x(r)} `));
|
|
1185
|
-
}
|
|
1186
|
-
function ne(t, e, n) {
|
|
1187
|
-
const r = x(t[t.length - 1] ?? t[0] ?? "");
|
|
1188
|
-
if (r) {
|
|
1189
|
-
const o = w(r), i = new Set(w(e));
|
|
1190
|
-
return o.find((a) => i.has(a)) ?? o[0] ?? r;
|
|
1191
|
-
}
|
|
1192
|
-
return n[0] ?? "";
|
|
1193
|
-
}
|
|
1194
|
-
function P(t) {
|
|
1195
|
-
return t.map((e) => x(e)).filter(Boolean).join(" ").replace(/\s+/gu, " ").trim().slice(0, 120);
|
|
1196
|
-
}
|
|
1197
|
-
function G(t) {
|
|
1198
|
-
return t.flatMap((e) => w(e));
|
|
1199
|
-
}
|
|
1200
|
-
function I(t, e) {
|
|
1201
|
-
const n = b(t), r = new Set(b(e));
|
|
1202
|
-
return n.length === 0 || r.size === 0 ? 0 : n.filter((o) => r.has(o)).length / n.length;
|
|
1203
|
-
}
|
|
1204
|
-
function re(t, e) {
|
|
1205
|
-
const n = b(t), r = new Set(b(e));
|
|
1206
|
-
return n.length === 0 || r.size === 0 ? 0 : n.filter((o) => r.has(o)).length / n.length;
|
|
1207
|
-
}
|
|
1208
|
-
function oe(t, e) {
|
|
1209
|
-
return t <= 0 || e <= 0 ? 0 : Math.min(t, e) / Math.max(t, e);
|
|
1210
|
-
}
|
|
1211
|
-
function ie(t, e) {
|
|
1212
|
-
return !t || !e ? 0 : typeof e.get == "function" ? e.get(t) ?? 0 : e[t] ?? 0;
|
|
1213
|
-
}
|
|
1214
|
-
function ae(t, e) {
|
|
1215
|
-
if (!t.productType || !e.productType || t.productType === e.productType) return !0;
|
|
1216
|
-
const n = new Set(w(t.productType)), r = /* @__PURE__ */ new Set([...w(e.productType), ...e.tokens]);
|
|
1217
|
-
return [...n].some((o) => r.has(o));
|
|
1218
|
-
}
|
|
1219
|
-
function se(t) {
|
|
1220
|
-
return Math.max(0, Math.min(1, t));
|
|
1221
|
-
}
|
|
1222
|
-
export {
|
|
1223
|
-
de as A,
|
|
1224
|
-
Mt as C,
|
|
1225
|
-
fe as D,
|
|
1226
|
-
Ct as E,
|
|
1227
|
-
R as F,
|
|
1228
|
-
ft as I,
|
|
1229
|
-
ce as L,
|
|
1230
|
-
bt as M,
|
|
1231
|
-
kt as N,
|
|
1232
|
-
tt as O,
|
|
1233
|
-
le as P,
|
|
1234
|
-
ue as R,
|
|
1235
|
-
nt as S,
|
|
1236
|
-
C as T,
|
|
1237
|
-
ot as _,
|
|
1238
|
-
xe as a,
|
|
1239
|
-
Nt as b,
|
|
1240
|
-
be as c,
|
|
1241
|
-
ke as d,
|
|
1242
|
-
we as f,
|
|
1243
|
-
Jt as g,
|
|
1244
|
-
z as h,
|
|
1245
|
-
x as i,
|
|
1246
|
-
Tt as j,
|
|
1247
|
-
et as k,
|
|
1248
|
-
Wt as l,
|
|
1249
|
-
Kt as m,
|
|
1250
|
-
M as n,
|
|
1251
|
-
Yt as o,
|
|
1252
|
-
he as p,
|
|
1253
|
-
Se as r,
|
|
1254
|
-
w as s,
|
|
1255
|
-
_e as t,
|
|
1256
|
-
N as u,
|
|
1257
|
-
ge as v,
|
|
1258
|
-
pe as w,
|
|
1259
|
-
me as x,
|
|
1260
|
-
ye as y,
|
|
1261
|
-
dt as z
|
|
1262
|
-
};
|