@gengage/assistant-fe 0.6.34 → 0.6.35
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/chat-runtime.js +1 -1
- package/dist/chat.iife.js +1 -1
- package/dist/chat.js +1 -1
- package/dist/common/index.d.ts +2 -1
- package/dist/{common-CB1Vjd-T.js → common-C-lXfS-s.js} +1 -1
- package/dist/common.js +68 -67
- package/dist/{connection-warning-DBE8pkFv.js → connection-warning-DrXU9qN9.js} +1 -1
- package/dist/{fastIntent-D9jYpC8V.js → fastIntent-Diz6Vo0W.js} +1 -1
- package/dist/index.js +21 -21
- 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/request-response-cache-DmnzO4Hu.js +1426 -0
- package/dist/{runtime-By-msZ8j.js → runtime-CiO-HX8B.js} +198 -199
- package/dist/{runtime-DyG44pqo.js → runtime-D0v-KyzN.js} +36 -37
- package/dist/{runtime-CABcQc-L.js → runtime-hci1VRsa.js} +8 -9
- package/dist/{simbut-CsQSH5vN.js → simbut-D-IPkTT8.js} +1 -1
- package/dist/simbut.iife.js +1 -1
- package/dist/simbut.js +1 -1
- package/dist/{simrel-bxdmsMmZ.js → simrel-BjMCvCdo.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-C_RZ-VIr.js → widget-base-_HBDf5VH.js} +1 -1
- package/package.json +3 -19
- package/dist/agent-ui-steps-DIWmTMuV.js +0 -3199
- package/dist/agentic/adaptor/create-adaptor.d.ts +0 -22
- package/dist/agentic/adaptor/fetch-bridge.d.ts +0 -31
- package/dist/agentic/adaptor/mount.d.ts +0 -45
- package/dist/agentic/algos/similarity.d.ts +0 -86
- package/dist/agentic/algos/similarity.js +0 -261
- package/dist/agentic/context/chat-context.d.ts +0 -17
- package/dist/agentic/context/context-store.d.ts +0 -57
- package/dist/agentic/context/persistence.d.ts +0 -14
- package/dist/agentic/contracts/agentic-contracts.d.ts +0 -133
- package/dist/agentic/debug/activity-collector.d.ts +0 -15
- package/dist/agentic/debug/activity-instrumentation.d.ts +0 -22
- package/dist/agentic/debug/activity-overlay.d.ts +0 -3
- package/dist/agentic/debug/activity-state.d.ts +0 -37
- package/dist/agentic/debug/local-dev.d.ts +0 -18
- package/dist/agentic/events/builders.d.ts +0 -10
- package/dist/agentic/events/comparison.d.ts +0 -6
- package/dist/agentic/events/context-products.d.ts +0 -6
- package/dist/agentic/events/error-taxonomy.d.ts +0 -27
- package/dist/agentic/events/product-normalize.d.ts +0 -50
- package/dist/agentic/events/ui-specs.d.ts +0 -41
- package/dist/agentic/flow/create-flow.d.ts +0 -2
- package/dist/agentic/flow/dispatch.d.ts +0 -3
- package/dist/agentic/index.d.ts +0 -65
- package/dist/agentic/index.js +0 -3493
- package/dist/agentic/types.d.ts +0 -360
- package/dist/agentic/util/account-config.d.ts +0 -8
- package/dist/agentic/util/assistant-host.d.ts +0 -11
- package/dist/agentic/util/be-url.d.ts +0 -4
- package/dist/agentic/util/browser-memory.d.ts +0 -13
- package/dist/agentic/util/browser-tools.d.ts +0 -31
- package/dist/agentic/util/cache-key.d.ts +0 -15
- package/dist/agentic/util/common/declarative-cache.d.ts +0 -21
- package/dist/agentic/util/common/fallback-status.d.ts +0 -10
- package/dist/agentic/util/common/flow-steps.d.ts +0 -8
- package/dist/agentic/util/common/gss-tool-aliases.d.ts +0 -66
- package/dist/agentic/util/common/iframe-scraper.d.ts +0 -22
- package/dist/agentic/util/common/llm-routing.d.ts +0 -50
- package/dist/agentic/util/common/object.d.ts +0 -1
- package/dist/agentic/util/common/open-product-page.d.ts +0 -30
- package/dist/agentic/util/common/panel-context.d.ts +0 -3
- package/dist/agentic/util/common/privacy.d.ts +0 -14
- package/dist/agentic/util/common/product-resolver.d.ts +0 -20
- package/dist/agentic/util/common/product-surface.d.ts +0 -24
- package/dist/agentic/util/common/ref-store.d.ts +0 -15
- package/dist/agentic/util/common/retail-privacy.d.ts +0 -4
- package/dist/agentic/util/common/route-params.d.ts +0 -3
- package/dist/agentic/util/common/similarity-ranking.d.ts +0 -2
- package/dist/agentic/util/common/site-awareness.d.ts +0 -130
- package/dist/agentic/util/lazy-runtime-loader.d.ts +0 -10
- package/dist/agentic/util/privacy.d.ts +0 -12
- package/dist/agentic/util/request-text.d.ts +0 -3
- package/dist/agentic/util/time.d.ts +0 -2
- package/dist/agentic/widgets/endpoints.d.ts +0 -12
- package/dist/agentic/worker/agent-ui-steps.d.ts +0 -43
- package/dist/agentic/worker/agent-ui.d.ts +0 -44
- package/dist/agentic/worker/be-client.d.ts +0 -32
- package/dist/agentic/worker/coalesce.d.ts +0 -25
- package/dist/agentic/worker/compaction.d.ts +0 -12
- package/dist/agentic/worker/entry.d.ts +0 -2
- package/dist/agentic/worker/flow-runner.d.ts +0 -24
- package/dist/agentic/worker/jwt-mint.d.ts +0 -21
- package/dist/agentic/worker/pdp-hydrate.d.ts +0 -30
- package/dist/agentic/worker/rpc.d.ts +0 -47
- package/dist/agentic/worker/tool-bridge.d.ts +0 -2
- package/dist/agentic/worker/tool-schema.d.ts +0 -19
- package/dist/agentic/worker.d.ts +0 -52
- package/dist/agentic/worker.js +0 -432
- package/dist/agentic.iife.js +0 -445
- package/dist/api-paths-DZQ4Xx7u.js +0 -1274
- package/dist/request-response-cache-BxRsKGJ0.js +0 -154
|
@@ -1,3199 +0,0 @@
|
|
|
1
|
-
import { t as ve } from "./request-response-cache-BxRsKGJ0.js";
|
|
2
|
-
var Ce = 120 * 1e3, Te = "gengage-agentic-ref";
|
|
3
|
-
function Ee({ namespace: t = Te, ttlMs: e = Ce, maxEntries: r = 100 } = {}) {
|
|
4
|
-
const n = /* @__PURE__ */ new Map();
|
|
5
|
-
async function o(u, l = {}) {
|
|
6
|
-
c();
|
|
7
|
-
const f = Ie(), d = l.kind || "pageRef", p = {
|
|
8
|
-
kind: d,
|
|
9
|
-
value: u,
|
|
10
|
-
expiresAt: Date.now() + (l.ttlMs || e)
|
|
11
|
-
};
|
|
12
|
-
for (n.set(f, p); n.size > r; ) n.delete(n.keys().next().value);
|
|
13
|
-
return await Oe(t, f, p), {
|
|
14
|
-
kind: d,
|
|
15
|
-
id: f
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
async function i(u) {
|
|
19
|
-
const l = typeof u == "string" ? u : u?.id;
|
|
20
|
-
if (!l) return;
|
|
21
|
-
const f = n.get(l) || await je(t, l);
|
|
22
|
-
if (f) {
|
|
23
|
-
if (f.expiresAt <= Date.now()) {
|
|
24
|
-
n.delete(l), await Lt(t, l);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
return n.set(l, f), f.value;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async function a(u) {
|
|
31
|
-
const l = typeof u == "string" ? u : u?.id;
|
|
32
|
-
l && (n.delete(l), await Lt(t, l));
|
|
33
|
-
}
|
|
34
|
-
async function s(u) {
|
|
35
|
-
if (Pe(u)) return i(u);
|
|
36
|
-
if (Array.isArray(u)) return Promise.all(u.map((f) => s(f)));
|
|
37
|
-
if (!u || typeof u != "object") return u;
|
|
38
|
-
const l = await Promise.all(Object.entries(u).map(async ([f, d]) => [f, await s(d)]));
|
|
39
|
-
return Object.fromEntries(l);
|
|
40
|
-
}
|
|
41
|
-
function c() {
|
|
42
|
-
const u = Date.now();
|
|
43
|
-
for (const [l, f] of n.entries()) f.expiresAt <= u && n.delete(l);
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
put: o,
|
|
47
|
-
get: i,
|
|
48
|
-
delete: a,
|
|
49
|
-
materialize: s,
|
|
50
|
-
cleanup: c
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function Pe(t) {
|
|
54
|
-
return !!(t && typeof t == "object" && typeof t.kind == "string" && typeof t.id == "string");
|
|
55
|
-
}
|
|
56
|
-
function Ie() {
|
|
57
|
-
return globalThis.crypto?.randomUUID ? globalThis.crypto.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
58
|
-
}
|
|
59
|
-
async function Oe(t, e, r) {
|
|
60
|
-
const n = await xt(t);
|
|
61
|
-
n && (await it(n.transaction("refs", "readwrite").objectStore("refs").put(r, e)), n.close());
|
|
62
|
-
}
|
|
63
|
-
async function je(t, e) {
|
|
64
|
-
const r = await xt(t);
|
|
65
|
-
if (!r) return;
|
|
66
|
-
const n = await it(r.transaction("refs", "readonly").objectStore("refs").get(e));
|
|
67
|
-
return r.close(), n;
|
|
68
|
-
}
|
|
69
|
-
async function Lt(t, e) {
|
|
70
|
-
const r = await xt(t);
|
|
71
|
-
r && (await it(r.transaction("refs", "readwrite").objectStore("refs").delete(e)), r.close());
|
|
72
|
-
}
|
|
73
|
-
async function xt(t) {
|
|
74
|
-
if (!globalThis.indexedDB) return null;
|
|
75
|
-
try {
|
|
76
|
-
const e = globalThis.indexedDB.open(t, 1);
|
|
77
|
-
return e.onupgradeneeded = () => {
|
|
78
|
-
e.result.createObjectStore("refs");
|
|
79
|
-
}, await it(e);
|
|
80
|
-
} catch {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
function it(t) {
|
|
85
|
-
return new Promise((e, r) => {
|
|
86
|
-
t.onsuccess = () => e(t.result), t.onerror = () => r(t.error);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
var Me = 12e4;
|
|
90
|
-
function Re(t) {
|
|
91
|
-
return !!t && typeof t == "object" && t.type === "rpc.result";
|
|
92
|
-
}
|
|
93
|
-
function Be(t) {
|
|
94
|
-
return !!t && typeof t == "object" && t.type === "rpc.req";
|
|
95
|
-
}
|
|
96
|
-
function wo(t = self, e = {}) {
|
|
97
|
-
let r = 1;
|
|
98
|
-
const n = /* @__PURE__ */ new Map(), o = e.timeoutMs === void 0 ? Me : Number.isFinite(e.timeoutMs) && e.timeoutMs > 0 ? e.timeoutMs : 0, i = (a) => {
|
|
99
|
-
const s = n.get(a);
|
|
100
|
-
if (s)
|
|
101
|
-
return n.delete(a), s.timer && clearTimeout(s.timer), s;
|
|
102
|
-
};
|
|
103
|
-
return t.addEventListener("message", (a) => {
|
|
104
|
-
const s = a.data;
|
|
105
|
-
if (!Re(s)) return;
|
|
106
|
-
const c = i(s.rpcId);
|
|
107
|
-
if (c) {
|
|
108
|
-
if (s.ok === !1) {
|
|
109
|
-
const u = typeof s.error == "object" ? s.error?.message : s.error;
|
|
110
|
-
c.reject(new Error(u || "RPC failed"));
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
c.resolve(s.value);
|
|
114
|
-
}
|
|
115
|
-
}), function(s, c, u) {
|
|
116
|
-
const l = r++;
|
|
117
|
-
return t.postMessage({
|
|
118
|
-
type: "rpc.req",
|
|
119
|
-
rpcId: l,
|
|
120
|
-
method: s,
|
|
121
|
-
payload: c
|
|
122
|
-
}, u || []), new Promise((f, d) => {
|
|
123
|
-
const p = {
|
|
124
|
-
resolve: (m) => f(m),
|
|
125
|
-
reject: d
|
|
126
|
-
};
|
|
127
|
-
o && (p.timer = setTimeout(() => {
|
|
128
|
-
n.has(l) && (n.delete(l), d(/* @__PURE__ */ new Error(`RPC '${s}' timed out after ${o}ms`)));
|
|
129
|
-
}, o)), n.set(l, p);
|
|
130
|
-
});
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
function bo({ worker: t, tools: e = {}, beacon: r, confirmation: n, memory: o = Ne(), refStore: i }) {
|
|
134
|
-
t.addEventListener("message", (a) => {
|
|
135
|
-
const s = a.data;
|
|
136
|
-
Be(s) && $e(t, s, {
|
|
137
|
-
tools: e,
|
|
138
|
-
beacon: r,
|
|
139
|
-
confirmation: n,
|
|
140
|
-
memory: o,
|
|
141
|
-
refStore: i
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
async function $e(t, e, r) {
|
|
146
|
-
try {
|
|
147
|
-
const n = await We(e.method, e.payload, r);
|
|
148
|
-
t.postMessage({
|
|
149
|
-
type: "rpc.result",
|
|
150
|
-
rpcId: e.rpcId,
|
|
151
|
-
ok: !0,
|
|
152
|
-
value: n
|
|
153
|
-
});
|
|
154
|
-
} catch (n) {
|
|
155
|
-
t.postMessage({
|
|
156
|
-
type: "rpc.result",
|
|
157
|
-
rpcId: e.rpcId,
|
|
158
|
-
ok: !1,
|
|
159
|
-
error: { message: n instanceof Error ? n.message : String(n) }
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
var ft = /* @__PURE__ */ new Map(), qt = null;
|
|
164
|
-
function Ne() {
|
|
165
|
-
try {
|
|
166
|
-
if (typeof sessionStorage < "u") return sessionStorage;
|
|
167
|
-
} catch {
|
|
168
|
-
}
|
|
169
|
-
return {
|
|
170
|
-
getItem: (t) => ft.get(t) ?? null,
|
|
171
|
-
setItem: (t, e) => {
|
|
172
|
-
ft.set(t, e);
|
|
173
|
-
},
|
|
174
|
-
removeItem: (t) => {
|
|
175
|
-
ft.delete(t);
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
function Fe() {
|
|
180
|
-
return qt ||= Ee(), qt;
|
|
181
|
-
}
|
|
182
|
-
function Le(t) {
|
|
183
|
-
if (t && typeof t == "object" && typeof t.name == "string") return t;
|
|
184
|
-
throw new Error("tool.invoke requires { name, input }");
|
|
185
|
-
}
|
|
186
|
-
function qe(t) {
|
|
187
|
-
if (t && typeof t == "object" && t.key !== void 0) return t;
|
|
188
|
-
throw new Error("memory.get requires { key }");
|
|
189
|
-
}
|
|
190
|
-
function De(t) {
|
|
191
|
-
if (t && typeof t == "object" && t.key !== void 0) return t;
|
|
192
|
-
throw new Error("memory.set requires { key }");
|
|
193
|
-
}
|
|
194
|
-
function Ue(t) {
|
|
195
|
-
if (t && typeof t == "object" && t.key !== void 0) return t;
|
|
196
|
-
throw new Error("memory.remove requires { key }");
|
|
197
|
-
}
|
|
198
|
-
function ze(t) {
|
|
199
|
-
return !t || typeof t != "object" ? { value: t } : t;
|
|
200
|
-
}
|
|
201
|
-
function Ve(t) {
|
|
202
|
-
const e = typeof t.kind == "string" && t.kind.trim() ? t.kind.trim() : void 0, r = typeof t.ttlMs == "number" && Number.isFinite(t.ttlMs) && t.ttlMs > 0 ? t.ttlMs : void 0;
|
|
203
|
-
return e || r ? {
|
|
204
|
-
...e ? { kind: e } : {},
|
|
205
|
-
...r ? { ttlMs: r } : {}
|
|
206
|
-
} : void 0;
|
|
207
|
-
}
|
|
208
|
-
function dt(t) {
|
|
209
|
-
if (t == null) return "session";
|
|
210
|
-
if (t === "volatile" || t === "session" || t === "local" || t === "indexedDb") return t;
|
|
211
|
-
if (typeof t == "string") {
|
|
212
|
-
const e = t.toLowerCase();
|
|
213
|
-
if (e === "indexeddb" || e === "idb") return "indexedDb";
|
|
214
|
-
}
|
|
215
|
-
throw new Error(`Unsupported memory tier: ${String(t)}`);
|
|
216
|
-
}
|
|
217
|
-
function vt(t) {
|
|
218
|
-
return typeof t.getItem == "function" && typeof t.setItem == "function";
|
|
219
|
-
}
|
|
220
|
-
function Ct(t) {
|
|
221
|
-
return typeof t.get == "function" && typeof t.set == "function";
|
|
222
|
-
}
|
|
223
|
-
function Tt(t) {
|
|
224
|
-
return typeof t.accountId == "string" && !!t.session && !!t.indexedDb;
|
|
225
|
-
}
|
|
226
|
-
function Ke(t) {
|
|
227
|
-
const e = t.options?.ttlMs ?? t.ttlMs;
|
|
228
|
-
return typeof e == "number" && Number.isFinite(e) && e > 0 ? { ttlMs: e } : void 0;
|
|
229
|
-
}
|
|
230
|
-
async function He(t, e, r) {
|
|
231
|
-
if (vt(t)) {
|
|
232
|
-
const n = t.getItem(r);
|
|
233
|
-
if (!n) return null;
|
|
234
|
-
try {
|
|
235
|
-
return JSON.parse(n);
|
|
236
|
-
} catch {
|
|
237
|
-
return t.removeItem?.(r), null;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return Ct(t) && !Tt(t) ? await t.get(e, r) ?? null : await t[e].get(r) ?? null;
|
|
241
|
-
}
|
|
242
|
-
async function Je(t, e, r, n, o) {
|
|
243
|
-
return vt(t) ? (t.setItem(r, JSON.stringify(n ?? null)), !0) : Ct(t) && !Tt(t) ? await t.set(e, r, n ?? null, o) !== !1 : await t[e].set(r, n ?? null, o) !== !1;
|
|
244
|
-
}
|
|
245
|
-
async function Ze(t, e, r) {
|
|
246
|
-
return vt(t) ? (t.removeItem?.(r), !0) : Ct(t) && !Tt(t) ? t.remove ? (await t.remove(e, r), !0) : !1 : (await t[e].remove(r), !0);
|
|
247
|
-
}
|
|
248
|
-
async function We(t, e, { tools: r, beacon: n, confirmation: o, memory: i, refStore: a }) {
|
|
249
|
-
if (t === "tool.invoke") {
|
|
250
|
-
const { name: s, input: c } = Le(e), u = r[s];
|
|
251
|
-
if (typeof u != "function") throw new Error(`Unknown tool: ${s}`);
|
|
252
|
-
return u(c);
|
|
253
|
-
}
|
|
254
|
-
if (t === "beacon.send")
|
|
255
|
-
return n?.(e), { sent: !0 };
|
|
256
|
-
if (t === "confirmation.request") {
|
|
257
|
-
if (typeof o != "function") throw new Error("No confirmation handler is configured.");
|
|
258
|
-
const s = await o(e);
|
|
259
|
-
return typeof s == "boolean" ? { confirmed: s } : s;
|
|
260
|
-
}
|
|
261
|
-
if (t === "memory.get") {
|
|
262
|
-
const { key: s, tier: c } = qe(e);
|
|
263
|
-
return He(i, dt(c), String(s));
|
|
264
|
-
}
|
|
265
|
-
if (t === "memory.set") {
|
|
266
|
-
const s = De(e);
|
|
267
|
-
return { ok: await Je(i, dt(s.tier), String(s.key), s.value, Ke(s)) };
|
|
268
|
-
}
|
|
269
|
-
if (t === "memory.remove") {
|
|
270
|
-
const { key: s, tier: c } = Ue(e);
|
|
271
|
-
return { ok: await Ze(i, dt(c), String(s)) };
|
|
272
|
-
}
|
|
273
|
-
if (t === "ref.put") {
|
|
274
|
-
const s = et({
|
|
275
|
-
tools: r,
|
|
276
|
-
beacon: n,
|
|
277
|
-
confirmation: o,
|
|
278
|
-
memory: i,
|
|
279
|
-
refStore: a
|
|
280
|
-
}), c = ze(e);
|
|
281
|
-
return s.put(c.value, Ve(c));
|
|
282
|
-
}
|
|
283
|
-
if (t === "ref.get") return et({
|
|
284
|
-
tools: r,
|
|
285
|
-
beacon: n,
|
|
286
|
-
confirmation: o,
|
|
287
|
-
memory: i,
|
|
288
|
-
refStore: a
|
|
289
|
-
}).get(e);
|
|
290
|
-
if (t === "ref.materialize") return et({
|
|
291
|
-
tools: r,
|
|
292
|
-
beacon: n,
|
|
293
|
-
confirmation: o,
|
|
294
|
-
memory: i,
|
|
295
|
-
refStore: a
|
|
296
|
-
}).materialize(e);
|
|
297
|
-
if (t === "ref.remove")
|
|
298
|
-
return await et({
|
|
299
|
-
tools: r,
|
|
300
|
-
beacon: n,
|
|
301
|
-
confirmation: o,
|
|
302
|
-
memory: i,
|
|
303
|
-
refStore: a
|
|
304
|
-
}).delete(e), { ok: !0 };
|
|
305
|
-
throw new Error(`Unknown RPC method: ${t}`);
|
|
306
|
-
}
|
|
307
|
-
function et(t) {
|
|
308
|
-
const e = t.refStore || Fe();
|
|
309
|
-
if (!e || typeof e.put != "function" || typeof e.get != "function") throw new Error("No ref store is configured.");
|
|
310
|
-
return e;
|
|
311
|
-
}
|
|
312
|
-
function Ge() {
|
|
313
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
314
|
-
}
|
|
315
|
-
function I(t) {
|
|
316
|
-
return Math.max(0, Math.round(performance.now() - t));
|
|
317
|
-
}
|
|
318
|
-
function V(t) {
|
|
319
|
-
return typeof t == "object" && t !== null && !Array.isArray(t);
|
|
320
|
-
}
|
|
321
|
-
function Ye(t) {
|
|
322
|
-
const { accountId: e, locale: r = "en-GB", parentUrl: n = "", threadId: o, incomingContext: i, messageLimit: a } = t, s = V(i) ? i : {}, c = V(s.thread) ? s.thread : {}, u = V(s.panel) ? s.panel : {}, l = V(s.meta) ? s.meta : {}, f = Qt(s.messages, a), d = {
|
|
323
|
-
id: String(o || c.id || self.crypto.randomUUID()),
|
|
324
|
-
started_at: String(c.started_at || Ge()),
|
|
325
|
-
extensions: V(c.extensions) ? { ...c.extensions } : {}
|
|
326
|
-
}, p = String(l.locale || r), m = String(l.parentUrl || n || typeof self < "u" && self.location?.href || "");
|
|
327
|
-
return {
|
|
328
|
-
panel: { ...u },
|
|
329
|
-
messages: f,
|
|
330
|
-
thread: d,
|
|
331
|
-
meta: {
|
|
332
|
-
locale: p,
|
|
333
|
-
parentUrl: m,
|
|
334
|
-
accountId: e
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
function Dt(t, e, r) {
|
|
339
|
-
const n = Qt([e], r)[0];
|
|
340
|
-
return n ? {
|
|
341
|
-
...t,
|
|
342
|
-
messages: at([...t.messages, n], r)
|
|
343
|
-
} : t;
|
|
344
|
-
}
|
|
345
|
-
function at(t, e) {
|
|
346
|
-
const r = Qe(e);
|
|
347
|
-
return r === 1 / 0 ? [...t] : t.slice(-r);
|
|
348
|
-
}
|
|
349
|
-
function Qt(t, e) {
|
|
350
|
-
return Array.isArray(t) ? at(t.map((r) => {
|
|
351
|
-
const n = r?.role;
|
|
352
|
-
return {
|
|
353
|
-
role: n === "model" ? "assistant" : typeof n == "string" ? n : "",
|
|
354
|
-
content: String(r?.content || "")
|
|
355
|
-
};
|
|
356
|
-
}).filter((r) => (r.role === "user" || r.role === "assistant" || r.role === "tool_result") && (r.role === "tool_result" || !!r.content)), e) : [];
|
|
357
|
-
}
|
|
358
|
-
function Qe(t) {
|
|
359
|
-
if (t === void 0) return 50;
|
|
360
|
-
if (!Number.isFinite(t)) return 1 / 0;
|
|
361
|
-
const e = Math.floor(t);
|
|
362
|
-
return e > 0 ? e : 50;
|
|
363
|
-
}
|
|
364
|
-
var Xe = "gengage:agent:context:";
|
|
365
|
-
async function tr({ accountId: t, threadId: e, rpc: r }) {
|
|
366
|
-
const n = await r("memory.get", {
|
|
367
|
-
tier: "session",
|
|
368
|
-
key: Xt(t, e)
|
|
369
|
-
});
|
|
370
|
-
return n && typeof n == "object" && !Array.isArray(n) ? n : {};
|
|
371
|
-
}
|
|
372
|
-
async function er({ accountId: t, threadId: e, extensions: r, panel: n, rpc: o }) {
|
|
373
|
-
await o("memory.set", {
|
|
374
|
-
tier: "session",
|
|
375
|
-
key: Xt(t, e),
|
|
376
|
-
value: {
|
|
377
|
-
thread: { extensions: r },
|
|
378
|
-
...n && Object.keys(n).length > 0 ? { panel: n } : {}
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
function Xt(t, e) {
|
|
383
|
-
return `${Xe}${t}:${e}`;
|
|
384
|
-
}
|
|
385
|
-
function w(t) {
|
|
386
|
-
return typeof t == "object" && t !== null && !Array.isArray(t);
|
|
387
|
-
}
|
|
388
|
-
var rr = "gengage_agentic_savepoints", rt = "savepoints", Ut = 3600 * 1e3, nr = 1, ko = class {
|
|
389
|
-
#t = /* @__PURE__ */ new Map();
|
|
390
|
-
#i = /* @__PURE__ */ new Map();
|
|
391
|
-
#e;
|
|
392
|
-
#u;
|
|
393
|
-
#l;
|
|
394
|
-
#a;
|
|
395
|
-
#f;
|
|
396
|
-
#d;
|
|
397
|
-
#o;
|
|
398
|
-
#s;
|
|
399
|
-
#c;
|
|
400
|
-
#r = /* @__PURE__ */ new Map();
|
|
401
|
-
constructor({ accountId: t, locale: e, parentUrl: r, rpc: n, persistentPanelKeys: o = [], panelKeyLimits: i = {}, messageLimit: a, maxThreads: s, threadTtlMs: c }) {
|
|
402
|
-
this.#e = t, this.#u = e, this.#l = r, this.#a = n, this.#f = [...new Set(o.filter(Boolean))], this.#d = ar(i), this.#o = yt(a), this.#s = yt(s), this.#c = yt(c);
|
|
403
|
-
}
|
|
404
|
-
get size() {
|
|
405
|
-
return this.pruneExpired(), this.#t.size;
|
|
406
|
-
}
|
|
407
|
-
get(t = "default") {
|
|
408
|
-
this.pruneExpired();
|
|
409
|
-
const e = String(t || "default"), r = this.#t.get(e);
|
|
410
|
-
return r ? (this.#n(e, r), r) : null;
|
|
411
|
-
}
|
|
412
|
-
getPanel(t = "default") {
|
|
413
|
-
return this.get(t)?.panel ?? null;
|
|
414
|
-
}
|
|
415
|
-
getRecentProducts(t = "default", e = "last_search_products") {
|
|
416
|
-
const r = this.getPanel(t)?.[e];
|
|
417
|
-
return Array.isArray(r) ? r : [];
|
|
418
|
-
}
|
|
419
|
-
async load(t) {
|
|
420
|
-
this.pruneExpired();
|
|
421
|
-
const e = t?.session_id || t?.meta?.threadId || t?.sessionId, r = String(e || "default"), n = this.#t.get(r);
|
|
422
|
-
if (n) {
|
|
423
|
-
const a = ur(n, t?.context, this.#o);
|
|
424
|
-
return this.#n(r, a), a;
|
|
425
|
-
}
|
|
426
|
-
const o = await tr({
|
|
427
|
-
accountId: this.#e,
|
|
428
|
-
threadId: r,
|
|
429
|
-
rpc: this.#a
|
|
430
|
-
}), i = Ye({
|
|
431
|
-
accountId: this.#e,
|
|
432
|
-
locale: t?.locale || this.#u,
|
|
433
|
-
parentUrl: this.#l,
|
|
434
|
-
threadId: r,
|
|
435
|
-
incomingContext: cr(o, t?.context),
|
|
436
|
-
messageLimit: this.#o
|
|
437
|
-
});
|
|
438
|
-
return this.#n(r, i), this.#m(), i;
|
|
439
|
-
}
|
|
440
|
-
patch(t, e) {
|
|
441
|
-
this.pruneExpired();
|
|
442
|
-
const r = String(t || "default"), n = this.#t.get(r);
|
|
443
|
-
if (!n) return null;
|
|
444
|
-
const o = Et(n, typeof e == "function" ? e(n) : e, this.#o);
|
|
445
|
-
return this.#n(r, o), o;
|
|
446
|
-
}
|
|
447
|
-
appendUserMessage(t, e) {
|
|
448
|
-
this.pruneExpired();
|
|
449
|
-
const r = String(t || "default");
|
|
450
|
-
if (!e) return this.#t.get(r) ?? null;
|
|
451
|
-
const n = this.#t.get(r);
|
|
452
|
-
if (!n) return null;
|
|
453
|
-
const o = Dt(n, {
|
|
454
|
-
role: "user",
|
|
455
|
-
content: e
|
|
456
|
-
}, this.#o);
|
|
457
|
-
return this.#n(r, o), o;
|
|
458
|
-
}
|
|
459
|
-
appendToolResult(t, e) {
|
|
460
|
-
this.pruneExpired();
|
|
461
|
-
const r = String(t || "default"), n = this.#t.get(r);
|
|
462
|
-
if (!n) return null;
|
|
463
|
-
const o = Dt(n, {
|
|
464
|
-
role: "tool_result",
|
|
465
|
-
content: String(e?.content || ""),
|
|
466
|
-
...e?.name ? { name: String(e.name) } : {},
|
|
467
|
-
...e?.details !== void 0 ? { details: e.details } : {}
|
|
468
|
-
}, this.#o);
|
|
469
|
-
return this.#n(r, o), o;
|
|
470
|
-
}
|
|
471
|
-
async commit(t) {
|
|
472
|
-
this.pruneExpired();
|
|
473
|
-
const e = String(t || "default"), r = this.#t.get(e);
|
|
474
|
-
return r ? (this.#n(e, r), await er({
|
|
475
|
-
accountId: this.#e,
|
|
476
|
-
threadId: e,
|
|
477
|
-
extensions: r.thread.extensions,
|
|
478
|
-
panel: ir(r.panel, this.#f, this.#d),
|
|
479
|
-
rpc: this.#a
|
|
480
|
-
}), r) : null;
|
|
481
|
-
}
|
|
482
|
-
delete(t) {
|
|
483
|
-
const e = String(t || "default");
|
|
484
|
-
return this.#i.delete(e), this.#r.delete(e), this.#t.delete(e);
|
|
485
|
-
}
|
|
486
|
-
clear() {
|
|
487
|
-
this.#t.clear(), this.#i.clear(), this.#r.clear();
|
|
488
|
-
}
|
|
489
|
-
enqueueSteer(t, e, r = "all") {
|
|
490
|
-
this.#p(t, "steer", e, r);
|
|
491
|
-
}
|
|
492
|
-
enqueueFollowUp(t, e, r = "all") {
|
|
493
|
-
this.#p(t, "follow_up", e, r);
|
|
494
|
-
}
|
|
495
|
-
drainPending(t, e) {
|
|
496
|
-
const r = String(t || "default"), n = this.#r.get(r);
|
|
497
|
-
if (!n || !n.length) return null;
|
|
498
|
-
const o = n.findIndex((a) => a.kind === e);
|
|
499
|
-
if (o < 0) return null;
|
|
500
|
-
const [i] = n.splice(o, 1);
|
|
501
|
-
return n.length || this.#r.delete(r), i || null;
|
|
502
|
-
}
|
|
503
|
-
peekPending(t = "default") {
|
|
504
|
-
const e = String(t || "default"), r = this.#r.get(e);
|
|
505
|
-
return r ? [...r] : [];
|
|
506
|
-
}
|
|
507
|
-
#p(t, e, r, n) {
|
|
508
|
-
const o = String(r || "").trim();
|
|
509
|
-
if (!o) return;
|
|
510
|
-
const i = String(t || "default"), a = this.#r.get(i) || [];
|
|
511
|
-
if (n === "one-at-a-time")
|
|
512
|
-
for (let s = a.length - 1; s >= 0; s -= 1) a[s].kind === e && a.splice(s, 1);
|
|
513
|
-
a.push({
|
|
514
|
-
kind: e,
|
|
515
|
-
text: o,
|
|
516
|
-
enqueuedAt: Date.now()
|
|
517
|
-
}), this.#r.set(i, a);
|
|
518
|
-
}
|
|
519
|
-
async savepoint(t, e, r) {
|
|
520
|
-
if (!t || typeof e != "number" || !Number.isFinite(e)) return;
|
|
521
|
-
const n = {
|
|
522
|
-
threadId: t,
|
|
523
|
-
turnIndex: e,
|
|
524
|
-
payload: r,
|
|
525
|
-
createdAt: Date.now()
|
|
526
|
-
};
|
|
527
|
-
try {
|
|
528
|
-
await mt(this.#e, "readwrite", (o) => {
|
|
529
|
-
o.put(n, pt(t, e));
|
|
530
|
-
});
|
|
531
|
-
} catch {
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
async restoreSavepoint(t, e) {
|
|
535
|
-
if (!t) return null;
|
|
536
|
-
try {
|
|
537
|
-
let r = null;
|
|
538
|
-
return await mt(this.#e, "readonly", (n) => {
|
|
539
|
-
const o = typeof e == "number" ? pt(t, e) : null;
|
|
540
|
-
if (o !== null) {
|
|
541
|
-
const i = n.get(o);
|
|
542
|
-
i.onsuccess = () => {
|
|
543
|
-
const a = i.result;
|
|
544
|
-
a && Date.now() - a.createdAt < Ut && (r = a);
|
|
545
|
-
};
|
|
546
|
-
} else {
|
|
547
|
-
const i = n.openCursor(null, "prev");
|
|
548
|
-
i.onsuccess = () => {
|
|
549
|
-
const a = i.result;
|
|
550
|
-
if (!a || r) return;
|
|
551
|
-
const s = a.value;
|
|
552
|
-
if (s.threadId !== t) {
|
|
553
|
-
a.continue();
|
|
554
|
-
return;
|
|
555
|
-
}
|
|
556
|
-
Date.now() - s.createdAt < Ut && (r = s);
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
|
-
}), r;
|
|
560
|
-
} catch {
|
|
561
|
-
return null;
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
async clearSavepoint(t, e) {
|
|
565
|
-
if (t)
|
|
566
|
-
try {
|
|
567
|
-
await mt(this.#e, "readwrite", (r) => {
|
|
568
|
-
if (typeof e == "number") {
|
|
569
|
-
r.delete(pt(t, e));
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
const n = r.openCursor();
|
|
573
|
-
n.onsuccess = () => {
|
|
574
|
-
const o = n.result;
|
|
575
|
-
o && (o.value.threadId === t && o.delete(), o.continue());
|
|
576
|
-
};
|
|
577
|
-
});
|
|
578
|
-
} catch {
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
pruneExpired(t = Date.now()) {
|
|
582
|
-
if (!this.#c) return 0;
|
|
583
|
-
let e = 0;
|
|
584
|
-
for (const [r, n] of this.#i)
|
|
585
|
-
t - n <= this.#c || (this.#i.delete(r), this.#t.delete(r) && (e += 1));
|
|
586
|
-
return e;
|
|
587
|
-
}
|
|
588
|
-
#n(t, e) {
|
|
589
|
-
this.#t.delete(t), this.#t.set(t, e), this.#i.set(t, Date.now());
|
|
590
|
-
}
|
|
591
|
-
#m() {
|
|
592
|
-
if (this.#s)
|
|
593
|
-
for (; this.#t.size > this.#s; ) {
|
|
594
|
-
const t = this.#t.keys().next().value;
|
|
595
|
-
if (!t) return;
|
|
596
|
-
this.delete(t);
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
};
|
|
600
|
-
function pt(t, e) {
|
|
601
|
-
return `${t}|${e}`;
|
|
602
|
-
}
|
|
603
|
-
function or() {
|
|
604
|
-
return (typeof self < "u" ? self : globalThis)?.indexedDB || null;
|
|
605
|
-
}
|
|
606
|
-
async function mt(t, e, r) {
|
|
607
|
-
const n = or();
|
|
608
|
-
if (!n) return;
|
|
609
|
-
const o = `${rr}_${t}`;
|
|
610
|
-
await new Promise((i, a) => {
|
|
611
|
-
const s = n.open(o, nr);
|
|
612
|
-
s.onupgradeneeded = () => {
|
|
613
|
-
const c = s.result;
|
|
614
|
-
c.objectStoreNames.contains(rt) || c.createObjectStore(rt);
|
|
615
|
-
}, s.onerror = () => a(s.error || /* @__PURE__ */ new Error("savepoint:open_failed")), s.onsuccess = () => {
|
|
616
|
-
const c = s.result;
|
|
617
|
-
try {
|
|
618
|
-
const u = c.transaction(rt, e);
|
|
619
|
-
r(u.objectStore(rt)), u.oncomplete = () => {
|
|
620
|
-
c.close(), i();
|
|
621
|
-
}, u.onerror = () => {
|
|
622
|
-
c.close(), a(u.error || /* @__PURE__ */ new Error("savepoint:tx_failed"));
|
|
623
|
-
}, u.onabort = () => {
|
|
624
|
-
c.close(), a(u.error || /* @__PURE__ */ new Error("savepoint:tx_aborted"));
|
|
625
|
-
};
|
|
626
|
-
} catch (u) {
|
|
627
|
-
c.close(), a(u instanceof Error ? u : new Error(String(u)));
|
|
628
|
-
}
|
|
629
|
-
};
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
|
-
function ir(t, e, r) {
|
|
633
|
-
if (!e.length || !w(t)) return;
|
|
634
|
-
const n = {};
|
|
635
|
-
for (const o of e) Object.prototype.hasOwnProperty.call(t, o) && (n[o] = sr(t[o], r[o]));
|
|
636
|
-
return n;
|
|
637
|
-
}
|
|
638
|
-
function ar(t) {
|
|
639
|
-
const e = {};
|
|
640
|
-
for (const [r, n] of Object.entries(t || {})) {
|
|
641
|
-
const o = Math.floor(Number(n));
|
|
642
|
-
r && Number.isFinite(o) && o > 0 && (e[r] = o);
|
|
643
|
-
}
|
|
644
|
-
return e;
|
|
645
|
-
}
|
|
646
|
-
function yt(t) {
|
|
647
|
-
if (t === void 0) return;
|
|
648
|
-
const e = Math.floor(Number(t));
|
|
649
|
-
return Number.isFinite(e) && e > 0 ? e : void 0;
|
|
650
|
-
}
|
|
651
|
-
function sr(t, e) {
|
|
652
|
-
return !e || !Array.isArray(t) ? t : t.slice(-e);
|
|
653
|
-
}
|
|
654
|
-
function cr(t, e) {
|
|
655
|
-
if (!w(t) && !w(e)) return {};
|
|
656
|
-
const r = w(t) ? t : {}, n = Et(r, w(e) ? e : {});
|
|
657
|
-
return w(r.panel) && (n.panel = r.panel), n;
|
|
658
|
-
}
|
|
659
|
-
function ur(t, e, r) {
|
|
660
|
-
if (!w(e)) return t;
|
|
661
|
-
const n = Et(t, e, r);
|
|
662
|
-
return {
|
|
663
|
-
...n,
|
|
664
|
-
panel: t.panel,
|
|
665
|
-
thread: {
|
|
666
|
-
...n.thread,
|
|
667
|
-
id: t.thread.id,
|
|
668
|
-
started_at: t.thread.started_at
|
|
669
|
-
},
|
|
670
|
-
meta: {
|
|
671
|
-
...n.meta,
|
|
672
|
-
accountId: t.meta.accountId
|
|
673
|
-
}
|
|
674
|
-
};
|
|
675
|
-
}
|
|
676
|
-
function Et(t, e, r) {
|
|
677
|
-
if (!w(e)) return t;
|
|
678
|
-
const n = t, o = e, i = w(n.panel) ? n.panel : {}, a = w(o.panel) ? o.panel : {}, s = w(n.thread) ? n.thread : {}, c = w(o.thread) ? o.thread : {}, u = w(s.extensions) ? s.extensions : {}, l = w(c.extensions) ? c.extensions : {}, f = w(n.meta) ? n.meta : {}, d = w(o.meta) ? o.meta : {};
|
|
679
|
-
return {
|
|
680
|
-
...t,
|
|
681
|
-
...e,
|
|
682
|
-
panel: {
|
|
683
|
-
...i,
|
|
684
|
-
...a
|
|
685
|
-
},
|
|
686
|
-
thread: {
|
|
687
|
-
...s,
|
|
688
|
-
...c,
|
|
689
|
-
extensions: {
|
|
690
|
-
...u,
|
|
691
|
-
...l
|
|
692
|
-
}
|
|
693
|
-
},
|
|
694
|
-
meta: {
|
|
695
|
-
...f,
|
|
696
|
-
...d
|
|
697
|
-
},
|
|
698
|
-
messages: Array.isArray(o.messages) ? at(o.messages, r) : t.messages ?? []
|
|
699
|
-
};
|
|
700
|
-
}
|
|
701
|
-
function te(t) {
|
|
702
|
-
const e = String.fromCharCode(...t);
|
|
703
|
-
return btoa(e).replace(/\+/gu, "-").replace(/\//gu, "_").replace(/=+$/u, "");
|
|
704
|
-
}
|
|
705
|
-
function zt(t) {
|
|
706
|
-
return te(new TextEncoder().encode(JSON.stringify(t)));
|
|
707
|
-
}
|
|
708
|
-
async function lr({ accountId: t, devJwtSecret: e, ttlS: r = 300 }) {
|
|
709
|
-
if (!e) throw new Error("devJwtSecret is required for local agent mode.");
|
|
710
|
-
const n = Math.floor(Date.now() / 1e3), o = `${zt({
|
|
711
|
-
alg: "HS256",
|
|
712
|
-
typ: "JWT"
|
|
713
|
-
})}.${zt({
|
|
714
|
-
sub: t,
|
|
715
|
-
iat: n,
|
|
716
|
-
exp: n + r,
|
|
717
|
-
scope: "invoke",
|
|
718
|
-
jti: crypto.randomUUID?.() || `${n}-${Math.random()}`
|
|
719
|
-
})}`, i = await crypto.subtle.importKey("raw", new TextEncoder().encode(e), {
|
|
720
|
-
name: "HMAC",
|
|
721
|
-
hash: "SHA-256"
|
|
722
|
-
}, !1, ["sign"]), a = await crypto.subtle.sign("HMAC", i, new TextEncoder().encode(o));
|
|
723
|
-
return `${o}.${te(new Uint8Array(a))}`;
|
|
724
|
-
}
|
|
725
|
-
function fr({ accountId: t, devJwtSecret: e, tokenBrokerUrl: r, tokenBrokerAudience: n, refreshSkewS: o = 30, fetchImpl: i = fetch }) {
|
|
726
|
-
let a = null;
|
|
727
|
-
return async ({ signal: s, parentUrl: c } = {}) => {
|
|
728
|
-
if (e) return lr({
|
|
729
|
-
accountId: t,
|
|
730
|
-
devJwtSecret: e
|
|
731
|
-
});
|
|
732
|
-
if (!r) throw new Error("tokenBrokerUrl is required for production agent mode.");
|
|
733
|
-
const u = Math.floor(Date.now() / 1e3);
|
|
734
|
-
return a?.token && a.expiresAtS - o > u || (a = await dr({
|
|
735
|
-
accountId: t,
|
|
736
|
-
tokenBrokerUrl: r,
|
|
737
|
-
tokenBrokerAudience: n,
|
|
738
|
-
parentUrl: c,
|
|
739
|
-
signal: s,
|
|
740
|
-
fetchImpl: i
|
|
741
|
-
})), a.token;
|
|
742
|
-
};
|
|
743
|
-
}
|
|
744
|
-
async function dr({ accountId: t, tokenBrokerUrl: e, tokenBrokerAudience: r, parentUrl: n, signal: o, fetchImpl: i }) {
|
|
745
|
-
const a = await i(e, {
|
|
746
|
-
method: "POST",
|
|
747
|
-
credentials: "include",
|
|
748
|
-
headers: {
|
|
749
|
-
accept: "application/json",
|
|
750
|
-
"content-type": "application/json"
|
|
751
|
-
},
|
|
752
|
-
body: JSON.stringify({
|
|
753
|
-
accountId: t,
|
|
754
|
-
scope: "invoke",
|
|
755
|
-
audience: r || void 0,
|
|
756
|
-
parentUrl: n || void 0
|
|
757
|
-
}),
|
|
758
|
-
...o ? { signal: o } : {}
|
|
759
|
-
});
|
|
760
|
-
if (!a.ok) throw new Error(`Token broker request failed (${a.status}).`);
|
|
761
|
-
const s = await a.json(), c = s?.token || s?.jwt || s?.access_token;
|
|
762
|
-
if (!c || typeof c != "string") throw new Error("Token broker response did not include a JWT.");
|
|
763
|
-
return {
|
|
764
|
-
token: c,
|
|
765
|
-
expiresAtS: pr(s) || mr(c) || Math.floor(Date.now() / 1e3) + 300
|
|
766
|
-
};
|
|
767
|
-
}
|
|
768
|
-
function pr(t) {
|
|
769
|
-
const e = t?.expiresAtS ?? t?.expires_at_s ?? t?.expiresInS ?? t?.expires_in_s;
|
|
770
|
-
if (Number.isFinite(e)) return Number(e);
|
|
771
|
-
const r = t?.expiresIn ?? t?.expires_in;
|
|
772
|
-
if (Number.isFinite(r)) return Math.floor(Date.now() / 1e3) + Number(r);
|
|
773
|
-
const n = t?.expiresAt ?? t?.expires_at;
|
|
774
|
-
if (typeof n == "string") {
|
|
775
|
-
const o = Date.parse(n);
|
|
776
|
-
if (Number.isFinite(o)) return Math.floor(o / 1e3);
|
|
777
|
-
}
|
|
778
|
-
return null;
|
|
779
|
-
}
|
|
780
|
-
function mr(t) {
|
|
781
|
-
try {
|
|
782
|
-
const [, e] = t.split(".");
|
|
783
|
-
if (!e) return null;
|
|
784
|
-
const r = e.replace(/-/gu, "+").replace(/_/gu, "/"), n = atob(r.padEnd(Math.ceil(r.length / 4) * 4, "=")), o = JSON.parse(n);
|
|
785
|
-
return Number.isFinite(o?.exp) ? Number(o.exp) : null;
|
|
786
|
-
} catch {
|
|
787
|
-
return null;
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
var Vt = {
|
|
791
|
-
unauthorized: {
|
|
792
|
-
code: "auth",
|
|
793
|
-
message: "Assistant authentication failed. Please retry."
|
|
794
|
-
},
|
|
795
|
-
forbidden: {
|
|
796
|
-
code: "auth",
|
|
797
|
-
message: "Assistant authentication failed. Please retry."
|
|
798
|
-
},
|
|
799
|
-
unknown_op: {
|
|
800
|
-
code: "op_unavailable",
|
|
801
|
-
message: "This assistant action is not available yet."
|
|
802
|
-
},
|
|
803
|
-
invalid_input: {
|
|
804
|
-
code: "invalid_request",
|
|
805
|
-
message: "The assistant request was not valid."
|
|
806
|
-
},
|
|
807
|
-
account_config: {
|
|
808
|
-
code: "account_config",
|
|
809
|
-
message: "Assistant configuration is unavailable."
|
|
810
|
-
},
|
|
811
|
-
upstream_llm: {
|
|
812
|
-
code: "op_failed",
|
|
813
|
-
message: "The assistant could not complete that request."
|
|
814
|
-
},
|
|
815
|
-
upstream_timeout: {
|
|
816
|
-
code: "op_timeout",
|
|
817
|
-
message: "The assistant took too long to respond."
|
|
818
|
-
},
|
|
819
|
-
schema_mismatch: {
|
|
820
|
-
code: "op_failed",
|
|
821
|
-
message: "The assistant could not complete that request."
|
|
822
|
-
},
|
|
823
|
-
rate_limited: {
|
|
824
|
-
code: "rate_limited",
|
|
825
|
-
message: "The assistant is receiving too many requests. Please retry shortly."
|
|
826
|
-
},
|
|
827
|
-
internal: {
|
|
828
|
-
code: "op_failed",
|
|
829
|
-
message: "The assistant could not complete that request."
|
|
830
|
-
},
|
|
831
|
-
payload_too_large: {
|
|
832
|
-
code: "invalid_request",
|
|
833
|
-
message: "The assistant request was too large."
|
|
834
|
-
}
|
|
835
|
-
}, v = class extends Error {
|
|
836
|
-
constructor(t, e, r = {}) {
|
|
837
|
-
super(e), this.name = "AgentError", this.code = t, this.source = r.source || "agent", r.sourceCode && (this.sourceCode = r.sourceCode), r.detail !== void 0 && (this.detail = r.detail);
|
|
838
|
-
}
|
|
839
|
-
};
|
|
840
|
-
function ee(t) {
|
|
841
|
-
const e = String(t?.code || "upstream_llm"), r = Vt[e] || Vt.upstream_llm;
|
|
842
|
-
return new v(r.code, r.message, {
|
|
843
|
-
source: "be",
|
|
844
|
-
sourceCode: e,
|
|
845
|
-
detail: t?.detail
|
|
846
|
-
});
|
|
847
|
-
}
|
|
848
|
-
function yr(t, e) {
|
|
849
|
-
const r = e?.error && typeof e.error == "object" ? e.error : {};
|
|
850
|
-
return ee({
|
|
851
|
-
code: String(r.code || gr(t)),
|
|
852
|
-
detail: r.detail
|
|
853
|
-
});
|
|
854
|
-
}
|
|
855
|
-
function _o(t) {
|
|
856
|
-
return t instanceof v ? {
|
|
857
|
-
type: "error",
|
|
858
|
-
code: t.code,
|
|
859
|
-
message: t.message
|
|
860
|
-
} : {
|
|
861
|
-
type: "error",
|
|
862
|
-
code: "agent_invoke_failed",
|
|
863
|
-
message: "The assistant could not complete that request."
|
|
864
|
-
};
|
|
865
|
-
}
|
|
866
|
-
function gr(t) {
|
|
867
|
-
return t === 401 ? "unauthorized" : t === 403 ? "forbidden" : t === 413 ? "payload_too_large" : t === 429 ? "rate_limited" : "internal";
|
|
868
|
-
}
|
|
869
|
-
async function Ao(t) {
|
|
870
|
-
const { beUrl: e, accountId: r, devJwtSecret: n, tokenBrokerUrl: o, tokenBrokerAudience: i, jwtProvider: a, parentUrl: s, op: c, input: u, cacheTtlS: l, cacheKey: f, cacheFreshness: d, browserCache: p, signal: m, interceptors: g } = t, S = await (a || fr({
|
|
871
|
-
accountId: r,
|
|
872
|
-
devJwtSecret: n,
|
|
873
|
-
tokenBrokerUrl: o,
|
|
874
|
-
tokenBrokerAudience: i
|
|
875
|
-
}))({
|
|
876
|
-
...m ? { signal: m } : {},
|
|
877
|
-
...s ? { parentUrl: s } : {}
|
|
878
|
-
}), { opDomain: $, opName: tt } = hr(c, r);
|
|
879
|
-
let M = {
|
|
880
|
-
method: "POST",
|
|
881
|
-
headers: {
|
|
882
|
-
authorization: `Bearer ${S}`,
|
|
883
|
-
"content-type": "application/json",
|
|
884
|
-
accept: "application/x-ndjson"
|
|
885
|
-
},
|
|
886
|
-
body: JSON.stringify({
|
|
887
|
-
op_domain: $,
|
|
888
|
-
op_name: tt,
|
|
889
|
-
op_payload: u,
|
|
890
|
-
...l !== void 0 ? { cache_ttl_s: l } : {},
|
|
891
|
-
...f !== void 0 ? { cache_key: f } : {},
|
|
892
|
-
...d !== void 0 ? { cache_freshness: d } : {}
|
|
893
|
-
}),
|
|
894
|
-
...m ? { signal: m } : {}
|
|
895
|
-
};
|
|
896
|
-
const N = `${String(e).replace(/\/+$/u, "")}/v1/execute`;
|
|
897
|
-
if (g?.beforeRequest) {
|
|
898
|
-
const _ = await g.beforeRequest(t, {
|
|
899
|
-
url: N,
|
|
900
|
-
init: M
|
|
901
|
-
});
|
|
902
|
-
if (_ && "cached" in _ && _.cached !== void 0) return _.cached;
|
|
903
|
-
_?.init && (M = _.init);
|
|
904
|
-
}
|
|
905
|
-
const R = p === !1 ? await fetch(N, M) : await ve(N, M, typeof p == "object" ? p : {});
|
|
906
|
-
if (!R.ok) throw yr(R.status, await br(R));
|
|
907
|
-
let F = await kr(R);
|
|
908
|
-
if (g?.afterResponse) {
|
|
909
|
-
const _ = await g.afterResponse(t, F);
|
|
910
|
-
_ && "result" in _ && _.result !== void 0 && (F = _.result);
|
|
911
|
-
}
|
|
912
|
-
return F;
|
|
913
|
-
}
|
|
914
|
-
function hr(t, e) {
|
|
915
|
-
if (!t || t.startsWith("-") || t.endsWith("-")) throw new Error(`Invalid BE op name: ${t}`);
|
|
916
|
-
return {
|
|
917
|
-
opDomain: wr(e),
|
|
918
|
-
opName: t
|
|
919
|
-
};
|
|
920
|
-
}
|
|
921
|
-
function wr(t) {
|
|
922
|
-
return t.replace(/-agentic$/u, "");
|
|
923
|
-
}
|
|
924
|
-
async function br(t) {
|
|
925
|
-
try {
|
|
926
|
-
return await t.json();
|
|
927
|
-
} catch {
|
|
928
|
-
return { error: { code: t.statusText || "internal" } };
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
async function kr(t) {
|
|
932
|
-
const e = t.body?.getReader();
|
|
933
|
-
if (!e) throw new Error("BE response body is not readable.");
|
|
934
|
-
const r = new TextDecoder();
|
|
935
|
-
let n = "";
|
|
936
|
-
const o = {};
|
|
937
|
-
for (; ; ) {
|
|
938
|
-
const { value: a, done: s } = await e.read();
|
|
939
|
-
if (s) break;
|
|
940
|
-
n += r.decode(a, { stream: !0 });
|
|
941
|
-
let c = n.indexOf(`
|
|
942
|
-
`);
|
|
943
|
-
for (; c >= 0; ) {
|
|
944
|
-
const u = n.slice(0, c).trim();
|
|
945
|
-
n = n.slice(c + 1), u && Kt(JSON.parse(u), o), c = n.indexOf(`
|
|
946
|
-
`);
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
const i = n.trim();
|
|
950
|
-
return i && Kt(JSON.parse(i), o), o;
|
|
951
|
-
}
|
|
952
|
-
function Kt(t, e) {
|
|
953
|
-
if (t._error) throw ee(t._error);
|
|
954
|
-
if (!t._end)
|
|
955
|
-
for (const [r, n] of Object.entries(t)) {
|
|
956
|
-
if (Object.prototype.hasOwnProperty.call(e, r)) throw new v("op_failed", `BE streamed duplicate field "${r}".`, {
|
|
957
|
-
source: "be",
|
|
958
|
-
sourceCode: "schema_mismatch"
|
|
959
|
-
});
|
|
960
|
-
e[r] = n;
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
function So(t = {}) {
|
|
964
|
-
return {
|
|
965
|
-
type: "metadata",
|
|
966
|
-
...t
|
|
967
|
-
};
|
|
968
|
-
}
|
|
969
|
-
function _r(t, e = !1, r = {}) {
|
|
970
|
-
return {
|
|
971
|
-
type: "text_chunk",
|
|
972
|
-
content: t,
|
|
973
|
-
final: e,
|
|
974
|
-
...r
|
|
975
|
-
};
|
|
976
|
-
}
|
|
977
|
-
function xo(t) {
|
|
978
|
-
return {
|
|
979
|
-
type: "ui_spec",
|
|
980
|
-
...t
|
|
981
|
-
};
|
|
982
|
-
}
|
|
983
|
-
function vo(t) {
|
|
984
|
-
return {
|
|
985
|
-
type: "action",
|
|
986
|
-
action: t
|
|
987
|
-
};
|
|
988
|
-
}
|
|
989
|
-
function Ar(t, e) {
|
|
990
|
-
return {
|
|
991
|
-
type: "error",
|
|
992
|
-
code: t,
|
|
993
|
-
message: e
|
|
994
|
-
};
|
|
995
|
-
}
|
|
996
|
-
function re() {
|
|
997
|
-
return { type: "done" };
|
|
998
|
-
}
|
|
999
|
-
function Sr(t, e) {
|
|
1000
|
-
return t[e?.type || e?.action?.type || "inputText"] || t.inputText;
|
|
1001
|
-
}
|
|
1002
|
-
function ne(t) {
|
|
1003
|
-
return t && typeof t == "object" && !Array.isArray(t) ? t : null;
|
|
1004
|
-
}
|
|
1005
|
-
function Pt(t, e = {}) {
|
|
1006
|
-
const r = ne(t);
|
|
1007
|
-
if (!r) return null;
|
|
1008
|
-
const n = e.catalogMapper?.(r);
|
|
1009
|
-
if (n) return n;
|
|
1010
|
-
const o = L(r.sku, r.SKU);
|
|
1011
|
-
if (!o) return null;
|
|
1012
|
-
const i = {
|
|
1013
|
-
sku: o,
|
|
1014
|
-
name: L(r.name, r.title, r.short_name, o) || o,
|
|
1015
|
-
url: L(r.url) || ""
|
|
1016
|
-
}, a = Array.isArray(r.images) ? r.images : void 0, s = L(r.imageUrl, r.image_url, r.image, a?.[0]);
|
|
1017
|
-
s && (i.imageUrl = s), a && a.length > 1 && (i.images = a.filter(($) => !!$).map(String));
|
|
1018
|
-
const c = K(r.price_discounted), u = K(r.price), l = c || u;
|
|
1019
|
-
l > 0 && (i.price = String(l));
|
|
1020
|
-
const f = c > 0 ? u : 0;
|
|
1021
|
-
f > 0 && (i.originalPrice = String(f));
|
|
1022
|
-
const d = L(r.brand);
|
|
1023
|
-
d && (i.brand = d);
|
|
1024
|
-
const p = K(r.rating);
|
|
1025
|
-
p > 0 && (i.rating = p);
|
|
1026
|
-
const m = K(r.review_count) || K(r.reviewCount);
|
|
1027
|
-
m > 0 && (i.reviewCount = m);
|
|
1028
|
-
const g = L(r.cart_code, r.cartCode);
|
|
1029
|
-
g && (i.cartCode = g), typeof r.in_stock == "boolean" && (i.inStock = r.in_stock), typeof r.inStock == "boolean" && (i.inStock = r.inStock);
|
|
1030
|
-
const S = r.category_names;
|
|
1031
|
-
return Array.isArray(S) && (i.categoryNames = S.map(String)), i;
|
|
1032
|
-
}
|
|
1033
|
-
function It(t) {
|
|
1034
|
-
const e = ne(t);
|
|
1035
|
-
if (!e) return t;
|
|
1036
|
-
const r = e.category_names, n = Array.isArray(r) ? r : void 0, o = e.images, i = Array.isArray(o) ? o : void 0, a = {
|
|
1037
|
-
sku: e.sku,
|
|
1038
|
-
name: e.name || e.title,
|
|
1039
|
-
url: e.url,
|
|
1040
|
-
price: e.price,
|
|
1041
|
-
currency: e.price_currency || e.currency,
|
|
1042
|
-
category: n?.[n.length - 1] ?? void 0,
|
|
1043
|
-
category_names: n ? n.slice(0, 4) : void 0,
|
|
1044
|
-
image: i ? i[0] : e.image,
|
|
1045
|
-
in_stock: e.in_stock,
|
|
1046
|
-
rating: e.rating,
|
|
1047
|
-
review_count: e.review_count
|
|
1048
|
-
};
|
|
1049
|
-
for (const s of Object.keys(a)) a[s] === void 0 && delete a[s];
|
|
1050
|
-
return a;
|
|
1051
|
-
}
|
|
1052
|
-
function Co(t) {
|
|
1053
|
-
return Array.isArray(t) ? t.map(It).filter((e) => !!e) : [];
|
|
1054
|
-
}
|
|
1055
|
-
function L(...t) {
|
|
1056
|
-
for (const e of t) if (typeof e == "string" && e.trim()) return e.trim();
|
|
1057
|
-
return "";
|
|
1058
|
-
}
|
|
1059
|
-
function K(t) {
|
|
1060
|
-
const e = Number(t);
|
|
1061
|
-
return Number.isFinite(e) ? e : 0;
|
|
1062
|
-
}
|
|
1063
|
-
function Ht(t) {
|
|
1064
|
-
return Array.isArray(t) ? t.map(String).filter(Boolean) : typeof t == "string" && t ? [t] : [];
|
|
1065
|
-
}
|
|
1066
|
-
function oe(t, e, r = {}) {
|
|
1067
|
-
return `${t}:${r.version || "v2"}:${ie(e)}`;
|
|
1068
|
-
}
|
|
1069
|
-
function To(t, e = {}) {
|
|
1070
|
-
return ae(t).map((r) => se(typeof r == "string" ? r : r.sku, e.locale)).filter(Boolean).filter((r, n, o) => o.indexOf(r) === n).sort((r, n) => Ot(r, n, e.locale)).slice(0, e.limit || 16).join(",");
|
|
1071
|
-
}
|
|
1072
|
-
function Eo(t, e = {}) {
|
|
1073
|
-
return ie(ae(t).map((r) => xr(r, e)).filter((r) => !!r).sort((r, n) => Ot(String(r.sku || r.name || ""), String(n.sku || n.name || ""), e.locale)).slice(0, e.limit || 16));
|
|
1074
|
-
}
|
|
1075
|
-
function Po(t, e) {
|
|
1076
|
-
return O(t, e);
|
|
1077
|
-
}
|
|
1078
|
-
function ie(t) {
|
|
1079
|
-
let e = 2166136261;
|
|
1080
|
-
const r = vr(t);
|
|
1081
|
-
for (let n = 0; n < r.length; n += 1)
|
|
1082
|
-
e ^= r.charCodeAt(n), e = Math.imul(e, 16777619);
|
|
1083
|
-
return (e >>> 0).toString(36);
|
|
1084
|
-
}
|
|
1085
|
-
function xr(t, e) {
|
|
1086
|
-
if (!t || typeof t != "object" || Array.isArray(t)) return null;
|
|
1087
|
-
const r = t, n = e.mapProduct?.(r);
|
|
1088
|
-
if (n) return J(n);
|
|
1089
|
-
const o = It(r);
|
|
1090
|
-
return o && typeof o == "object" && !Array.isArray(o) ? J(Cr(o, e)) : null;
|
|
1091
|
-
}
|
|
1092
|
-
function ae(t) {
|
|
1093
|
-
return Array.isArray(t) ? t.filter((e) => typeof e == "string" || !!(e && typeof e == "object" && !Array.isArray(e))) : [];
|
|
1094
|
-
}
|
|
1095
|
-
function vr(t) {
|
|
1096
|
-
return JSON.stringify(J(t));
|
|
1097
|
-
}
|
|
1098
|
-
function J(t) {
|
|
1099
|
-
return Array.isArray(t) ? t.map(J) : !t || typeof t != "object" ? t : Object.fromEntries(Object.entries(t).filter(([, e]) => e !== void 0).sort(([e], [r]) => e.localeCompare(r)).map(([e, r]) => [e, J(r)]));
|
|
1100
|
-
}
|
|
1101
|
-
function Cr(t, e) {
|
|
1102
|
-
return {
|
|
1103
|
-
sku: se(t.sku, e.locale),
|
|
1104
|
-
name: O(t.name, e.locale),
|
|
1105
|
-
url: O(t.url, e.locale),
|
|
1106
|
-
price: t.price,
|
|
1107
|
-
currency: O(t.currency, e.locale),
|
|
1108
|
-
category: O(t.category, e.locale),
|
|
1109
|
-
category_names: Tr(t.category_names, e.locale, 16),
|
|
1110
|
-
image: O(t.image, e.locale),
|
|
1111
|
-
in_stock: t.in_stock,
|
|
1112
|
-
rating: t.rating,
|
|
1113
|
-
review_count: t.review_count
|
|
1114
|
-
};
|
|
1115
|
-
}
|
|
1116
|
-
function se(t, e) {
|
|
1117
|
-
return O(t, e).toUpperCase();
|
|
1118
|
-
}
|
|
1119
|
-
function O(t, e) {
|
|
1120
|
-
return typeof t == "string" ? t.trim().replace(/\s+/gu, " ").toLocaleLowerCase(e || void 0) : "";
|
|
1121
|
-
}
|
|
1122
|
-
function Ot(t, e, r) {
|
|
1123
|
-
return t.localeCompare(e, r, { numeric: !0 });
|
|
1124
|
-
}
|
|
1125
|
-
function Tr(t, e, r) {
|
|
1126
|
-
return Array.isArray(t) ? t.map((n) => O(n, e)).filter(Boolean).sort((n, o) => Ot(n, o, e)).slice(0, r) : void 0;
|
|
1127
|
-
}
|
|
1128
|
-
function Er(t, e) {
|
|
1129
|
-
if (!t) return { ok: !0 };
|
|
1130
|
-
const r = [];
|
|
1131
|
-
return kt(t, e, "", r), r.length ? {
|
|
1132
|
-
ok: !1,
|
|
1133
|
-
error: r[0] || "invalid"
|
|
1134
|
-
} : { ok: !0 };
|
|
1135
|
-
}
|
|
1136
|
-
function kt(t, e, r, n) {
|
|
1137
|
-
if (t) {
|
|
1138
|
-
if (Array.isArray(t.enum) && !t.enum.includes(e)) {
|
|
1139
|
-
n.push(`${r || "value"} must be one of [${t.enum.join(", ")}]`);
|
|
1140
|
-
return;
|
|
1141
|
-
}
|
|
1142
|
-
switch (t.type) {
|
|
1143
|
-
case "string":
|
|
1144
|
-
if (typeof e != "string") {
|
|
1145
|
-
n.push(`${r || "value"} must be a string`);
|
|
1146
|
-
return;
|
|
1147
|
-
}
|
|
1148
|
-
t.minLength && e.length < t.minLength && n.push(`${r || "value"} must be at least ${t.minLength} chars`);
|
|
1149
|
-
return;
|
|
1150
|
-
case "number":
|
|
1151
|
-
if (typeof e != "number" || !Number.isFinite(e)) {
|
|
1152
|
-
n.push(`${r || "value"} must be a number`);
|
|
1153
|
-
return;
|
|
1154
|
-
}
|
|
1155
|
-
t.minimum != null && e < t.minimum && n.push(`${r || "value"} must be >= ${t.minimum}`), t.maximum != null && e > t.maximum && n.push(`${r || "value"} must be <= ${t.maximum}`);
|
|
1156
|
-
return;
|
|
1157
|
-
case "boolean":
|
|
1158
|
-
typeof e != "boolean" && n.push(`${r || "value"} must be a boolean`);
|
|
1159
|
-
return;
|
|
1160
|
-
case "array":
|
|
1161
|
-
if (!Array.isArray(e)) {
|
|
1162
|
-
n.push(`${r || "value"} must be an array`);
|
|
1163
|
-
return;
|
|
1164
|
-
}
|
|
1165
|
-
if (t.minItems != null && e.length < t.minItems && n.push(`${r || "value"} must have >= ${t.minItems} items`), t.maxItems != null && e.length > t.maxItems && n.push(`${r || "value"} must have <= ${t.maxItems} items`), t.items) {
|
|
1166
|
-
for (let o = 0; o < e.length; o += 1)
|
|
1167
|
-
if (kt(t.items, e[o], `${r}[${o}]`, n), n.length) return;
|
|
1168
|
-
}
|
|
1169
|
-
return;
|
|
1170
|
-
case "object":
|
|
1171
|
-
if (!e || typeof e != "object" || Array.isArray(e)) {
|
|
1172
|
-
n.push(`${r || "value"} must be an object`);
|
|
1173
|
-
return;
|
|
1174
|
-
}
|
|
1175
|
-
if (Array.isArray(t.required)) for (const o of t.required) {
|
|
1176
|
-
const i = e[o];
|
|
1177
|
-
if (i == null || i === "") {
|
|
1178
|
-
n.push(`${r ? `${r}.` : ""}${o} is required`);
|
|
1179
|
-
return;
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
if (t.properties) for (const [o, i] of Object.entries(t.properties)) {
|
|
1183
|
-
const a = e[o];
|
|
1184
|
-
if (a !== void 0 && (kt(i, a, r ? `${r}.${o}` : o, n), n.length))
|
|
1185
|
-
return;
|
|
1186
|
-
}
|
|
1187
|
-
return;
|
|
1188
|
-
default:
|
|
1189
|
-
return;
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
var Pr = 12e4;
|
|
1194
|
-
async function Io({ request: t, accountModule: e, contextStore: r, beClient: n, toolBridge: o, emit: i, rpc: a, signal: s }) {
|
|
1195
|
-
const c = performance.now(), u = await r.load(t), l = u.thread.id, f = Qr(t);
|
|
1196
|
-
zr(u, f) && r.appendUserMessage(l, f);
|
|
1197
|
-
const d = Sr(e.flows, t);
|
|
1198
|
-
if (!d)
|
|
1199
|
-
return i(Ar("unknown_action", `No agent flow for request type ${t?.type || "inputText"}`)), i(re()), {
|
|
1200
|
-
steps: 0,
|
|
1201
|
-
productSkusEmitted: []
|
|
1202
|
-
};
|
|
1203
|
-
const p = {
|
|
1204
|
-
request: t,
|
|
1205
|
-
context: r.patch(l, {}) || u,
|
|
1206
|
-
bag: {},
|
|
1207
|
-
accountConfig: e.accountConfig || {},
|
|
1208
|
-
threadId: l,
|
|
1209
|
-
steps: 0,
|
|
1210
|
-
productSkusEmitted: /* @__PURE__ */ new Set(),
|
|
1211
|
-
committed: !1,
|
|
1212
|
-
messageLimit: Yr(e.contextPersistence?.messageLimit),
|
|
1213
|
-
catalogMapper: e.catalogMapper,
|
|
1214
|
-
similarityMapper: e.similarityMapper
|
|
1215
|
-
}, m = {
|
|
1216
|
-
contextStore: r,
|
|
1217
|
-
beClient: n,
|
|
1218
|
-
toolBridge: o,
|
|
1219
|
-
emit: i,
|
|
1220
|
-
rpc: a,
|
|
1221
|
-
adapters: e.adapters || {},
|
|
1222
|
-
...s ? { signal: s } : {},
|
|
1223
|
-
...e.trace ? { trace: e.trace } : {},
|
|
1224
|
-
...e.hooks ? { hooks: e.hooks } : {}
|
|
1225
|
-
};
|
|
1226
|
-
await C(m, q("turn:start", p));
|
|
1227
|
-
try {
|
|
1228
|
-
await U(d, p, m), p.committed || await jt(p, m);
|
|
1229
|
-
} catch (g) {
|
|
1230
|
-
throw await C(m, {
|
|
1231
|
-
...q("turn:error", p),
|
|
1232
|
-
latencyMs: I(c),
|
|
1233
|
-
errorCode: G(g)
|
|
1234
|
-
}), g;
|
|
1235
|
-
}
|
|
1236
|
-
return await a("beacon.send", {
|
|
1237
|
-
type: "turnSummary",
|
|
1238
|
-
threadId: l,
|
|
1239
|
-
sessionId: t?.session_id || t?.sessionId || l,
|
|
1240
|
-
accountId: e.accountId || p.context.meta.accountId,
|
|
1241
|
-
steps: p.steps,
|
|
1242
|
-
totalLatencyMs: I(c),
|
|
1243
|
-
productSkusEmitted: [...p.productSkusEmitted]
|
|
1244
|
-
}), await C(m, {
|
|
1245
|
-
...q("turn:end", p),
|
|
1246
|
-
latencyMs: I(c)
|
|
1247
|
-
}), {
|
|
1248
|
-
steps: p.steps,
|
|
1249
|
-
productSkusEmitted: [...p.productSkusEmitted]
|
|
1250
|
-
};
|
|
1251
|
-
}
|
|
1252
|
-
async function U(t, e, r) {
|
|
1253
|
-
for (const n of t) {
|
|
1254
|
-
if (r.signal?.aborted || e.committed) return;
|
|
1255
|
-
e.steps += 1;
|
|
1256
|
-
const o = e.steps, i = performance.now();
|
|
1257
|
-
await C(r, gt("step:start", e, n, o));
|
|
1258
|
-
try {
|
|
1259
|
-
await Ir(n, e, r), await C(r, {
|
|
1260
|
-
...gt("step:end", e, n, o),
|
|
1261
|
-
latencyMs: I(i)
|
|
1262
|
-
});
|
|
1263
|
-
} catch (a) {
|
|
1264
|
-
throw await C(r, {
|
|
1265
|
-
...gt("step:error", e, n, o),
|
|
1266
|
-
latencyMs: I(i),
|
|
1267
|
-
errorCode: G(a)
|
|
1268
|
-
}), a;
|
|
1269
|
-
}
|
|
1270
|
-
e.context = r.contextStore.patch(e.threadId, {}) || e.context;
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
async function Ir(t, e, r) {
|
|
1274
|
-
if (r.hooks?.transformContext) {
|
|
1275
|
-
const o = await W(r, e, "transformContext", () => r.hooks.transformContext(e.context));
|
|
1276
|
-
o && (e.context = o);
|
|
1277
|
-
}
|
|
1278
|
-
const n = D(e, r);
|
|
1279
|
-
if (t.kind === "be_op") {
|
|
1280
|
-
await Or(t, e, r, n);
|
|
1281
|
-
return;
|
|
1282
|
-
}
|
|
1283
|
-
if (t.kind === "tool") {
|
|
1284
|
-
await Rr(t, e, r, n);
|
|
1285
|
-
return;
|
|
1286
|
-
}
|
|
1287
|
-
if (t.kind === "adapter") {
|
|
1288
|
-
await Br(t, e, r, n);
|
|
1289
|
-
return;
|
|
1290
|
-
}
|
|
1291
|
-
if (t.kind === "emit") {
|
|
1292
|
-
await $r(t, e, r);
|
|
1293
|
-
return;
|
|
1294
|
-
}
|
|
1295
|
-
if (t.kind === "patch") {
|
|
1296
|
-
await Nr(t, e, r);
|
|
1297
|
-
return;
|
|
1298
|
-
}
|
|
1299
|
-
if (t.kind === "branch") {
|
|
1300
|
-
await Fr(t, e, r, n);
|
|
1301
|
-
return;
|
|
1302
|
-
}
|
|
1303
|
-
if (t.kind === "agent_loop") {
|
|
1304
|
-
await Lr(t, e, r, n);
|
|
1305
|
-
return;
|
|
1306
|
-
}
|
|
1307
|
-
if (t.kind === "parallel") {
|
|
1308
|
-
await qr(t, e, r);
|
|
1309
|
-
return;
|
|
1310
|
-
}
|
|
1311
|
-
if (t.kind === "refusal") {
|
|
1312
|
-
await Dr(t, e, r, n);
|
|
1313
|
-
return;
|
|
1314
|
-
}
|
|
1315
|
-
t.kind === "commit" && await Ur(t, e, r);
|
|
1316
|
-
}
|
|
1317
|
-
async function Or(t, e, r, n) {
|
|
1318
|
-
const o = performance.now();
|
|
1319
|
-
let i;
|
|
1320
|
-
try {
|
|
1321
|
-
let s = await b(t.input, n);
|
|
1322
|
-
if (r.hooks?.beforeBeOp) {
|
|
1323
|
-
const c = await W(r, e, "beforeBeOp", () => r.hooks.beforeBeOp(t.op, s, n));
|
|
1324
|
-
c && "cached" in c && c.cached !== void 0 ? i = c.cached : c && "input" in c && c.input !== void 0 && (s = c.input);
|
|
1325
|
-
}
|
|
1326
|
-
if (i === void 0) {
|
|
1327
|
-
const c = await b(t.cache, n), u = jr(t, e, s, c), l = await b(t.cacheTtlS, n) ?? u.cacheTtlS, f = await b(t.cacheKey, n) ?? u.cacheKey, d = await b(t.cacheFreshness, n), p = await b(t.browserCache, n), m = Y(await b(t.timeoutMs, n));
|
|
1328
|
-
await Mt(t, e, r, n);
|
|
1329
|
-
const g = m ? new AbortController() : null, S = ce(r.signal, g?.signal);
|
|
1330
|
-
i = await Q(r.beClient.invoke({
|
|
1331
|
-
op: t.op,
|
|
1332
|
-
input: s,
|
|
1333
|
-
...l !== void 0 ? { cacheTtlS: l } : {},
|
|
1334
|
-
...f !== void 0 ? { cacheKey: f } : {},
|
|
1335
|
-
...d !== void 0 ? { cacheFreshness: d } : {},
|
|
1336
|
-
...p !== void 0 ? { browserCache: p } : {},
|
|
1337
|
-
...S ? { signal: S } : {}
|
|
1338
|
-
}), m, () => new v("op_timeout", "The assistant took too long to respond.", {
|
|
1339
|
-
source: "be",
|
|
1340
|
-
sourceCode: "timeout"
|
|
1341
|
-
}), () => g?.abort());
|
|
1342
|
-
}
|
|
1343
|
-
if (r.hooks?.afterBeOp) {
|
|
1344
|
-
const c = await W(r, e, "afterBeOp", () => r.hooks.afterBeOp(t.op, i, n));
|
|
1345
|
-
c && "result" in c && c.result !== void 0 && (i = c.result);
|
|
1346
|
-
}
|
|
1347
|
-
} catch (s) {
|
|
1348
|
-
const c = s, u = String(c?.sourceCode || c?.code || "unknown"), l = {
|
|
1349
|
-
type: "agentOp",
|
|
1350
|
-
threadId: e.threadId,
|
|
1351
|
-
sessionId: e.request?.session_id || e.request?.sessionId || e.threadId,
|
|
1352
|
-
accountId: e.context.meta.accountId,
|
|
1353
|
-
op: t.op,
|
|
1354
|
-
status: "error",
|
|
1355
|
-
latencyMs: I(o),
|
|
1356
|
-
errorCode: u
|
|
1357
|
-
};
|
|
1358
|
-
if (await r.rpc("beacon.send", l), t.onError) {
|
|
1359
|
-
t.errorOut && (e.bag[t.errorOut] = s), await U(t.onError, e, r);
|
|
1360
|
-
return;
|
|
1361
|
-
}
|
|
1362
|
-
throw s;
|
|
1363
|
-
}
|
|
1364
|
-
t.out && (e.bag[t.out] = i), await st(t, i, e, r.contextStore);
|
|
1365
|
-
const a = {
|
|
1366
|
-
type: "agentOp",
|
|
1367
|
-
threadId: e.threadId,
|
|
1368
|
-
sessionId: e.request?.session_id || e.request?.sessionId || e.threadId,
|
|
1369
|
-
accountId: e.context.meta.accountId,
|
|
1370
|
-
op: t.op,
|
|
1371
|
-
status: "ok",
|
|
1372
|
-
latencyMs: I(o)
|
|
1373
|
-
};
|
|
1374
|
-
await r.rpc("beacon.send", a);
|
|
1375
|
-
}
|
|
1376
|
-
function jr(t, e, r, n) {
|
|
1377
|
-
if (!n || n.strategy !== "input-hash") return {};
|
|
1378
|
-
const o = Y(n.ttlS);
|
|
1379
|
-
if (!o) return {};
|
|
1380
|
-
const i = e.context.meta.locale, a = n.promptVersion || Mr(r) || "current";
|
|
1381
|
-
return {
|
|
1382
|
-
cacheTtlS: o,
|
|
1383
|
-
cacheKey: oe(t.op, {
|
|
1384
|
-
account: e.context.meta.accountId,
|
|
1385
|
-
locale: i,
|
|
1386
|
-
promptVersion: a,
|
|
1387
|
-
payload: r
|
|
1388
|
-
}, { version: "input-hash" })
|
|
1389
|
-
};
|
|
1390
|
-
}
|
|
1391
|
-
function Mr(t) {
|
|
1392
|
-
if (!t || typeof t != "object" || Array.isArray(t)) return;
|
|
1393
|
-
const e = t, r = e.prompt_version || e.promptVersion;
|
|
1394
|
-
return typeof r == "string" && r.trim() ? r.trim() : void 0;
|
|
1395
|
-
}
|
|
1396
|
-
async function Rr(t, e, r, n) {
|
|
1397
|
-
const o = performance.now();
|
|
1398
|
-
try {
|
|
1399
|
-
await Mt(t, e, r, n);
|
|
1400
|
-
const i = Y(await b(t.timeoutMs, n));
|
|
1401
|
-
let a = await b(t.input, n);
|
|
1402
|
-
if (r.hooks?.beforeToolCall) {
|
|
1403
|
-
const c = await W(r, e, "beforeToolCall", () => r.hooks.beforeToolCall(t.name, a, n));
|
|
1404
|
-
if (c?.block) throw new v("tool_blocked", c.reason || `Tool '${t.name}' blocked by hook.`, {
|
|
1405
|
-
source: "tool",
|
|
1406
|
-
sourceCode: "blocked"
|
|
1407
|
-
});
|
|
1408
|
-
c && "args" in c && c.args !== void 0 && (a = c.args);
|
|
1409
|
-
}
|
|
1410
|
-
if (t.parameters) {
|
|
1411
|
-
const c = Er(t.parameters, a);
|
|
1412
|
-
if (!c.ok) throw new v("tool_invalid_args", `Invalid args for tool '${t.name}': ${c.error}`, {
|
|
1413
|
-
source: "tool",
|
|
1414
|
-
sourceCode: "invalid_args"
|
|
1415
|
-
});
|
|
1416
|
-
}
|
|
1417
|
-
let s = await Q(r.toolBridge.invoke(t.name, a), i, () => new v("tool_timeout", "The assistant tool took too long to respond.", {
|
|
1418
|
-
source: "tool",
|
|
1419
|
-
sourceCode: "timeout"
|
|
1420
|
-
}));
|
|
1421
|
-
if (r.hooks?.afterToolCall) {
|
|
1422
|
-
const c = await W(r, e, "afterToolCall", () => r.hooks.afterToolCall(t.name, s, n));
|
|
1423
|
-
c && "result" in c && c.result !== void 0 && (s = c.result), c?.terminate && (e.committed = !0);
|
|
1424
|
-
}
|
|
1425
|
-
t.out && (e.bag[t.out] = s), await st(t, s, e, r.contextStore), await r.rpc("beacon.send", {
|
|
1426
|
-
type: "agentTool",
|
|
1427
|
-
threadId: e.threadId,
|
|
1428
|
-
sessionId: Z(e),
|
|
1429
|
-
accountId: e.context.meta.accountId,
|
|
1430
|
-
tool: t.name,
|
|
1431
|
-
status: "ok",
|
|
1432
|
-
latencyMs: I(o)
|
|
1433
|
-
});
|
|
1434
|
-
} catch (i) {
|
|
1435
|
-
const a = i;
|
|
1436
|
-
if (await r.rpc("beacon.send", {
|
|
1437
|
-
type: "agentTool",
|
|
1438
|
-
threadId: e.threadId,
|
|
1439
|
-
sessionId: Z(e),
|
|
1440
|
-
accountId: e.context.meta.accountId,
|
|
1441
|
-
tool: t.name,
|
|
1442
|
-
status: "error",
|
|
1443
|
-
latencyMs: I(o),
|
|
1444
|
-
errorCode: String(a?.code || a?.name || "unknown")
|
|
1445
|
-
}), t.onError) {
|
|
1446
|
-
t.errorOut && (e.bag[t.errorOut] = i), await U(t.onError, e, r);
|
|
1447
|
-
return;
|
|
1448
|
-
}
|
|
1449
|
-
throw i;
|
|
1450
|
-
}
|
|
1451
|
-
}
|
|
1452
|
-
async function Br(t, e, r, n) {
|
|
1453
|
-
const o = r.adapters?.[t.name];
|
|
1454
|
-
if (typeof o != "function") throw new Error(`Unknown flow adapter: ${t.name}`);
|
|
1455
|
-
await Mt(t, e, r, n);
|
|
1456
|
-
const i = Y(await b(t.timeoutMs, n)), a = await Q(o(await b(t.input, n), n), i, () => new v("adapter_timeout", "The assistant adapter took too long to respond.", {
|
|
1457
|
-
source: "adapter",
|
|
1458
|
-
sourceCode: "timeout"
|
|
1459
|
-
}));
|
|
1460
|
-
t.out && (e.bag[t.out] = a), await st(t, a, e, r.contextStore);
|
|
1461
|
-
}
|
|
1462
|
-
async function $r(t, e, r) {
|
|
1463
|
-
const n = await t.build(D(e, r));
|
|
1464
|
-
Xr(n, e.productSkusEmitted), r.emit(n);
|
|
1465
|
-
}
|
|
1466
|
-
async function Nr(t, e, r) {
|
|
1467
|
-
await st(t, void 0, e, r.contextStore);
|
|
1468
|
-
}
|
|
1469
|
-
async function Fr(t, e, r, n) {
|
|
1470
|
-
const o = String(await b(t.on, n) || "default");
|
|
1471
|
-
await U(t.cases[o] || t.cases.default || [], e, r);
|
|
1472
|
-
}
|
|
1473
|
-
async function Lr(t, e, r, n) {
|
|
1474
|
-
if (!await t.shouldContinue(e.bag, n)) return;
|
|
1475
|
-
const o = Math.max(0, Math.floor(Number(t.maxIterations) || 0));
|
|
1476
|
-
let i = 0;
|
|
1477
|
-
for (; !r.signal?.aborted && !e.committed; ) {
|
|
1478
|
-
if (await U(t.body, e, r), r.signal?.aborted || e.committed || !await t.shouldContinue(e.bag, D(e, r)) || i >= o) return;
|
|
1479
|
-
const a = await t.onIterate?.(e.bag, D(e, r));
|
|
1480
|
-
a && typeof a == "object" && Object.assign(e.bag, a), i += 1;
|
|
1481
|
-
}
|
|
1482
|
-
}
|
|
1483
|
-
async function qr(t, e, r) {
|
|
1484
|
-
const n = Y(await b(t.timeoutMs, D(e, r))), o = n ? new AbortController() : null, i = ce(r.signal, o?.signal), a = t.steps.map((u) => {
|
|
1485
|
-
const l = {
|
|
1486
|
-
...e,
|
|
1487
|
-
context: Vr(e.context),
|
|
1488
|
-
bag: _t(e.bag),
|
|
1489
|
-
productSkusEmitted: new Set(e.productSkusEmitted),
|
|
1490
|
-
committed: !1
|
|
1491
|
-
}, f = [];
|
|
1492
|
-
return U(u, l, {
|
|
1493
|
-
...r,
|
|
1494
|
-
emit: (d) => {
|
|
1495
|
-
!i?.aborted && d.type !== "done" && f.push(d);
|
|
1496
|
-
},
|
|
1497
|
-
contextStore: Kr(l),
|
|
1498
|
-
...i ? { signal: i } : {}
|
|
1499
|
-
}).then(() => ({
|
|
1500
|
-
state: l,
|
|
1501
|
-
events: f
|
|
1502
|
-
}));
|
|
1503
|
-
}), s = await Q(Promise.all(a), n, () => new v("parallel_timeout", "The assistant parallel step took too long to respond.", {
|
|
1504
|
-
source: "agent",
|
|
1505
|
-
sourceCode: "timeout"
|
|
1506
|
-
}), () => o?.abort()), c = t.merge || {};
|
|
1507
|
-
for (const { state: u, events: l } of s) {
|
|
1508
|
-
for (const f of l) r.emit(f);
|
|
1509
|
-
for (const f of u.productSkusEmitted) e.productSkusEmitted.add(f);
|
|
1510
|
-
for (const f of c.bag || []) Object.prototype.hasOwnProperty.call(u.bag, f) && (e.bag[f] = u.bag[f]);
|
|
1511
|
-
if (c.panel?.length) {
|
|
1512
|
-
const f = Jt(u.context.panel, c.panel);
|
|
1513
|
-
Object.keys(f).length && (e.context = r.contextStore.patch(e.threadId, { panel: f }) || e.context);
|
|
1514
|
-
}
|
|
1515
|
-
if (c.threadExtensions?.length) {
|
|
1516
|
-
const f = Jt(u.context.thread.extensions, c.threadExtensions);
|
|
1517
|
-
Object.keys(f).length && (e.context = r.contextStore.patch(e.threadId, { thread: {
|
|
1518
|
-
...e.context.thread,
|
|
1519
|
-
extensions: f
|
|
1520
|
-
} }) || e.context);
|
|
1521
|
-
}
|
|
1522
|
-
}
|
|
1523
|
-
}
|
|
1524
|
-
async function Dr(t, e, r, n) {
|
|
1525
|
-
r.emit(_r(await b(t.message, n), !0)), await jt(e, r);
|
|
1526
|
-
}
|
|
1527
|
-
async function Ur(t, e, r) {
|
|
1528
|
-
await jt(e, r);
|
|
1529
|
-
}
|
|
1530
|
-
async function jt(t, { contextStore: e, emit: r }) {
|
|
1531
|
-
t.committed || (t.context = await e.commit(t.threadId) || t.context, t.committed = !0, r(re()));
|
|
1532
|
-
}
|
|
1533
|
-
async function st(t, e, r, n) {
|
|
1534
|
-
if (typeof t.patch != "function") return;
|
|
1535
|
-
const o = await t.patch(r.context, e, D(r));
|
|
1536
|
-
o && (r.context = n.patch(r.threadId, o) || r.context);
|
|
1537
|
-
}
|
|
1538
|
-
function D(t, e) {
|
|
1539
|
-
return {
|
|
1540
|
-
request: t.request,
|
|
1541
|
-
context: t.context,
|
|
1542
|
-
bag: t.bag,
|
|
1543
|
-
accountConfig: t.accountConfig,
|
|
1544
|
-
catalogMapper: t.catalogMapper,
|
|
1545
|
-
similarityMapper: t.similarityMapper,
|
|
1546
|
-
...e ? {
|
|
1547
|
-
beClient: e.beClient,
|
|
1548
|
-
toolBridge: e.toolBridge
|
|
1549
|
-
} : {},
|
|
1550
|
-
...e?.signal ? { signal: e.signal } : {}
|
|
1551
|
-
};
|
|
1552
|
-
}
|
|
1553
|
-
function Z(t) {
|
|
1554
|
-
return t.request?.session_id || t.request?.sessionId || t.threadId;
|
|
1555
|
-
}
|
|
1556
|
-
function zr(t, e) {
|
|
1557
|
-
if (!e) return !1;
|
|
1558
|
-
const r = t.messages[t.messages.length - 1];
|
|
1559
|
-
return r?.role !== "user" || r.content !== e;
|
|
1560
|
-
}
|
|
1561
|
-
function Jt(t, e) {
|
|
1562
|
-
const r = {};
|
|
1563
|
-
for (const n of e) Object.prototype.hasOwnProperty.call(t, n) && (r[n] = t[n]);
|
|
1564
|
-
return r;
|
|
1565
|
-
}
|
|
1566
|
-
function Vr(t) {
|
|
1567
|
-
return {
|
|
1568
|
-
...t,
|
|
1569
|
-
panel: _t(t.panel || {}),
|
|
1570
|
-
thread: {
|
|
1571
|
-
...t.thread,
|
|
1572
|
-
extensions: _t(t.thread?.extensions || {})
|
|
1573
|
-
},
|
|
1574
|
-
meta: t.meta,
|
|
1575
|
-
messages: t.messages
|
|
1576
|
-
};
|
|
1577
|
-
}
|
|
1578
|
-
function Kr(t) {
|
|
1579
|
-
return {
|
|
1580
|
-
async load() {
|
|
1581
|
-
return t.context;
|
|
1582
|
-
},
|
|
1583
|
-
patch(e, r) {
|
|
1584
|
-
return t.context = Hr(t.context, r, t.messageLimit), t.context;
|
|
1585
|
-
},
|
|
1586
|
-
appendUserMessage() {
|
|
1587
|
-
return t.context;
|
|
1588
|
-
},
|
|
1589
|
-
async commit() {
|
|
1590
|
-
return t.context;
|
|
1591
|
-
}
|
|
1592
|
-
};
|
|
1593
|
-
}
|
|
1594
|
-
function Hr(t, e, r) {
|
|
1595
|
-
if (!e || typeof e != "object") return t;
|
|
1596
|
-
const n = Zt(t.panel, e.panel), o = Zt(t.thread?.extensions || {}, e.thread?.extensions);
|
|
1597
|
-
return {
|
|
1598
|
-
...t,
|
|
1599
|
-
...e,
|
|
1600
|
-
panel: n,
|
|
1601
|
-
thread: {
|
|
1602
|
-
...t.thread || {},
|
|
1603
|
-
...e.thread || {},
|
|
1604
|
-
extensions: o
|
|
1605
|
-
},
|
|
1606
|
-
meta: {
|
|
1607
|
-
...t.meta || {},
|
|
1608
|
-
...e.meta || {}
|
|
1609
|
-
},
|
|
1610
|
-
messages: Array.isArray(e.messages) ? at(e.messages, r) : t.messages
|
|
1611
|
-
};
|
|
1612
|
-
}
|
|
1613
|
-
function Zt(t, e) {
|
|
1614
|
-
if (!e || typeof e != "object" || Array.isArray(e)) return t;
|
|
1615
|
-
const r = {};
|
|
1616
|
-
for (const n of Object.keys(t)) r[n] = t[n];
|
|
1617
|
-
for (const [n, o] of Object.entries(e)) r[n] = o;
|
|
1618
|
-
return r;
|
|
1619
|
-
}
|
|
1620
|
-
function _t(t) {
|
|
1621
|
-
return new Proxy({}, {
|
|
1622
|
-
get(e, r, n) {
|
|
1623
|
-
if (typeof r != "string") return Reflect.get(e, r, n);
|
|
1624
|
-
if (Object.prototype.hasOwnProperty.call(e, r)) return e[r];
|
|
1625
|
-
const o = t[r];
|
|
1626
|
-
if (Jr(o)) {
|
|
1627
|
-
const i = Zr(o);
|
|
1628
|
-
return e[r] = i, i;
|
|
1629
|
-
}
|
|
1630
|
-
return o;
|
|
1631
|
-
},
|
|
1632
|
-
has(e, r) {
|
|
1633
|
-
return Reflect.has(e, r) || Reflect.has(t, r);
|
|
1634
|
-
},
|
|
1635
|
-
ownKeys(e) {
|
|
1636
|
-
return Reflect.ownKeys(e);
|
|
1637
|
-
},
|
|
1638
|
-
getOwnPropertyDescriptor(e, r) {
|
|
1639
|
-
return Object.getOwnPropertyDescriptor(e, r);
|
|
1640
|
-
}
|
|
1641
|
-
});
|
|
1642
|
-
}
|
|
1643
|
-
function Jr(t) {
|
|
1644
|
-
return !!(t && typeof t == "object");
|
|
1645
|
-
}
|
|
1646
|
-
function Zr(t) {
|
|
1647
|
-
if (typeof structuredClone == "function") try {
|
|
1648
|
-
return structuredClone(t);
|
|
1649
|
-
} catch {
|
|
1650
|
-
}
|
|
1651
|
-
try {
|
|
1652
|
-
return JSON.parse(JSON.stringify(t));
|
|
1653
|
-
} catch {
|
|
1654
|
-
return t;
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
async function b(t, e) {
|
|
1658
|
-
return typeof t == "function" ? await t(e) : t;
|
|
1659
|
-
}
|
|
1660
|
-
function Y(t) {
|
|
1661
|
-
if (t === void 0) return;
|
|
1662
|
-
const e = Math.floor(Number(t));
|
|
1663
|
-
return Number.isFinite(e) && e > 0 ? e : void 0;
|
|
1664
|
-
}
|
|
1665
|
-
async function Q(t, e, r, n) {
|
|
1666
|
-
if (!e) return t;
|
|
1667
|
-
let o, i = !1;
|
|
1668
|
-
return new Promise((a, s) => {
|
|
1669
|
-
o = setTimeout(() => {
|
|
1670
|
-
i || (i = !0, n?.(), s(r()));
|
|
1671
|
-
}, e), Promise.resolve(t).then((c) => {
|
|
1672
|
-
i || (i = !0, o && clearTimeout(o), a(c));
|
|
1673
|
-
}, (c) => {
|
|
1674
|
-
i || (i = !0, o && clearTimeout(o), s(c));
|
|
1675
|
-
});
|
|
1676
|
-
});
|
|
1677
|
-
}
|
|
1678
|
-
function ce(t, e) {
|
|
1679
|
-
if (!t) return e;
|
|
1680
|
-
if (!e || t.aborted) return t;
|
|
1681
|
-
if (e.aborted) return e;
|
|
1682
|
-
const r = new AbortController(), n = () => r.abort();
|
|
1683
|
-
return t.addEventListener("abort", n, { once: !0 }), e.addEventListener("abort", n, { once: !0 }), r.signal;
|
|
1684
|
-
}
|
|
1685
|
-
async function Mt(t, e, r, n) {
|
|
1686
|
-
if (!t.confirm) return;
|
|
1687
|
-
const o = await b(t.confirm, n);
|
|
1688
|
-
if (!o) return;
|
|
1689
|
-
const i = Wr(o, t, e);
|
|
1690
|
-
await C(r, ht("confirmation:start", e, t));
|
|
1691
|
-
try {
|
|
1692
|
-
const a = await Q(r.rpc("confirmation.request", i), Pr, () => new v("confirmation_timeout", "The confirmation prompt timed out without a response.", {
|
|
1693
|
-
source: t.kind === "be_op" ? "be" : t.kind,
|
|
1694
|
-
sourceCode: "confirmation_timeout"
|
|
1695
|
-
})), s = typeof a == "boolean" ? a : a?.confirmed === !0;
|
|
1696
|
-
if (await C(r, ht("confirmation:end", e, t)), s) return;
|
|
1697
|
-
throw new v("confirmation_declined", "The requested action was not confirmed.", {
|
|
1698
|
-
source: t.kind === "be_op" ? "be" : t.kind,
|
|
1699
|
-
sourceCode: "confirmation_declined",
|
|
1700
|
-
detail: a
|
|
1701
|
-
});
|
|
1702
|
-
} catch (a) {
|
|
1703
|
-
throw await C(r, {
|
|
1704
|
-
...ht("confirmation:error", e, t),
|
|
1705
|
-
errorCode: G(a)
|
|
1706
|
-
}), a;
|
|
1707
|
-
}
|
|
1708
|
-
}
|
|
1709
|
-
function Wr(t, e, r) {
|
|
1710
|
-
return {
|
|
1711
|
-
...Gr(t),
|
|
1712
|
-
accountId: r.context.meta.accountId,
|
|
1713
|
-
threadId: r.threadId,
|
|
1714
|
-
sessionId: Z(r),
|
|
1715
|
-
stepKind: e.kind,
|
|
1716
|
-
...e.kind === "be_op" ? { stepName: e.op } : { stepName: e.name }
|
|
1717
|
-
};
|
|
1718
|
-
}
|
|
1719
|
-
function Gr(t) {
|
|
1720
|
-
return typeof t == "string" ? { message: t } : t === !0 ? {} : t && typeof t == "object" ? {
|
|
1721
|
-
...typeof t.title == "string" ? { title: t.title } : {},
|
|
1722
|
-
...typeof t.message == "string" ? { message: t.message } : {},
|
|
1723
|
-
...typeof t.action == "string" ? { action: t.action } : {},
|
|
1724
|
-
...Object.prototype.hasOwnProperty.call(t, "payload") ? { payload: t.payload } : {}
|
|
1725
|
-
} : {};
|
|
1726
|
-
}
|
|
1727
|
-
async function C(t, e) {
|
|
1728
|
-
try {
|
|
1729
|
-
await t.trace?.(e);
|
|
1730
|
-
} catch {
|
|
1731
|
-
}
|
|
1732
|
-
}
|
|
1733
|
-
async function W(t, e, r, n) {
|
|
1734
|
-
try {
|
|
1735
|
-
return await n();
|
|
1736
|
-
} catch (o) {
|
|
1737
|
-
await C(t, {
|
|
1738
|
-
...q("step:error", e),
|
|
1739
|
-
stepName: `hook:${r}`,
|
|
1740
|
-
errorCode: G(o)
|
|
1741
|
-
});
|
|
1742
|
-
try {
|
|
1743
|
-
await t.rpc("beacon.send", {
|
|
1744
|
-
type: "agentHookError",
|
|
1745
|
-
threadId: e.threadId,
|
|
1746
|
-
sessionId: Z(e),
|
|
1747
|
-
accountId: e.context.meta.accountId,
|
|
1748
|
-
hook: r,
|
|
1749
|
-
errorCode: G(o),
|
|
1750
|
-
message: o instanceof Error ? o.message : String(o)
|
|
1751
|
-
});
|
|
1752
|
-
} catch {
|
|
1753
|
-
}
|
|
1754
|
-
return;
|
|
1755
|
-
}
|
|
1756
|
-
}
|
|
1757
|
-
function q(t, e) {
|
|
1758
|
-
return {
|
|
1759
|
-
type: t,
|
|
1760
|
-
accountId: e.context.meta.accountId,
|
|
1761
|
-
threadId: e.threadId,
|
|
1762
|
-
sessionId: Z(e)
|
|
1763
|
-
};
|
|
1764
|
-
}
|
|
1765
|
-
function gt(t, e, r, n) {
|
|
1766
|
-
const o = ue(r);
|
|
1767
|
-
return {
|
|
1768
|
-
...q(t, e),
|
|
1769
|
-
stepIndex: n,
|
|
1770
|
-
stepKind: r.kind,
|
|
1771
|
-
...o ? { stepName: o } : {}
|
|
1772
|
-
};
|
|
1773
|
-
}
|
|
1774
|
-
function ht(t, e, r) {
|
|
1775
|
-
const n = ue(r);
|
|
1776
|
-
return {
|
|
1777
|
-
...q(t, e),
|
|
1778
|
-
stepKind: r.kind,
|
|
1779
|
-
...n ? { stepName: n } : {}
|
|
1780
|
-
};
|
|
1781
|
-
}
|
|
1782
|
-
function ue(t) {
|
|
1783
|
-
if (t.kind === "be_op") return t.op;
|
|
1784
|
-
if (t.kind === "tool" || t.kind === "adapter") return t.name;
|
|
1785
|
-
}
|
|
1786
|
-
function G(t) {
|
|
1787
|
-
if (t && typeof t == "object") {
|
|
1788
|
-
const e = t;
|
|
1789
|
-
return String(e.sourceCode || e.code || e.name || "unknown");
|
|
1790
|
-
}
|
|
1791
|
-
return "unknown";
|
|
1792
|
-
}
|
|
1793
|
-
function Yr(t) {
|
|
1794
|
-
if (t === void 0) return;
|
|
1795
|
-
const e = Math.floor(Number(t));
|
|
1796
|
-
return Number.isFinite(e) && e > 0 ? e : void 0;
|
|
1797
|
-
}
|
|
1798
|
-
function Qr(t) {
|
|
1799
|
-
const e = t?.payload;
|
|
1800
|
-
if (typeof e == "string") return e;
|
|
1801
|
-
if (e && typeof e == "object" && "text" in e) {
|
|
1802
|
-
const r = e.text;
|
|
1803
|
-
if (typeof r == "string") return r;
|
|
1804
|
-
}
|
|
1805
|
-
return typeof t?.action?.payload == "string" ? t.action.payload : typeof t?.action?.title == "string" ? t.action.title : "";
|
|
1806
|
-
}
|
|
1807
|
-
function Xr(t, e) {
|
|
1808
|
-
const r = t, n = r.spec, o = Array.isArray(n?.items) ? n.items : void 0, i = Array.isArray(r.items) ? r.items : void 0, a = o || i;
|
|
1809
|
-
if (Array.isArray(a)) {
|
|
1810
|
-
for (const s of a) if (s && typeof s == "object") {
|
|
1811
|
-
const c = s.sku;
|
|
1812
|
-
typeof c == "string" && e.add(c);
|
|
1813
|
-
}
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
|
-
function Oo(t) {
|
|
1817
|
-
return { invoke(e, r) {
|
|
1818
|
-
return t("tool.invoke", {
|
|
1819
|
-
name: e,
|
|
1820
|
-
input: r
|
|
1821
|
-
});
|
|
1822
|
-
} };
|
|
1823
|
-
}
|
|
1824
|
-
function jo(t, e = {}) {
|
|
1825
|
-
if (!Array.isArray(t)) return [];
|
|
1826
|
-
const r = e.maxItems ?? 8, n = e.maxFeatures ?? 8;
|
|
1827
|
-
return t.map((o) => tn(o, e.defaultBrand, n)).filter((o) => !!o).slice(0, r);
|
|
1828
|
-
}
|
|
1829
|
-
function tn(t, e, r) {
|
|
1830
|
-
if (!t || typeof t != "object" || Array.isArray(t)) return null;
|
|
1831
|
-
const n = t, o = It(n);
|
|
1832
|
-
return o ? nn({
|
|
1833
|
-
sku: o.sku,
|
|
1834
|
-
name: o.name,
|
|
1835
|
-
url: o.url,
|
|
1836
|
-
image: o.image,
|
|
1837
|
-
price: o.price,
|
|
1838
|
-
currency: o.currency,
|
|
1839
|
-
category: o.category,
|
|
1840
|
-
category_names: o.category_names,
|
|
1841
|
-
brand: n.brand || e,
|
|
1842
|
-
features: en(n.features, r),
|
|
1843
|
-
specs: rn(n.specs, r),
|
|
1844
|
-
in_stock: o.in_stock
|
|
1845
|
-
}) : null;
|
|
1846
|
-
}
|
|
1847
|
-
function en(t, e) {
|
|
1848
|
-
return Array.isArray(t) ? t.filter(Boolean).slice(0, e) : void 0;
|
|
1849
|
-
}
|
|
1850
|
-
function rn(t, e) {
|
|
1851
|
-
if (!(!t || typeof t != "object" || Array.isArray(t)))
|
|
1852
|
-
return Object.fromEntries(Object.entries(t).filter(([, r]) => r != null).slice(0, e));
|
|
1853
|
-
}
|
|
1854
|
-
function nn(t) {
|
|
1855
|
-
return Object.fromEntries(Object.entries(t).filter(([, e]) => e != null));
|
|
1856
|
-
}
|
|
1857
|
-
function le(t) {
|
|
1858
|
-
if (!t || typeof t != "object" || Array.isArray(t)) return {};
|
|
1859
|
-
const e = t, r = Array.isArray(e.rows) ? e.rows : [];
|
|
1860
|
-
return {
|
|
1861
|
-
...e,
|
|
1862
|
-
rows: r.map(an).filter(Boolean)
|
|
1863
|
-
};
|
|
1864
|
-
}
|
|
1865
|
-
function on(t, e) {
|
|
1866
|
-
const r = Array.isArray(t) ? t.filter((s) => !!(s && typeof s == "object" && !Array.isArray(s))) : [], n = le(e), o = Array.isArray(n.columns) ? n.columns.map(String) : [];
|
|
1867
|
-
if (!o.length) return r;
|
|
1868
|
-
const i = new Map(r.map((s) => [String(s.sku || s.id || ""), s])), a = o.map((s) => i.get(s)).filter((s) => !!s);
|
|
1869
|
-
return a.length ? a : r;
|
|
1870
|
-
}
|
|
1871
|
-
function Mo(t, e) {
|
|
1872
|
-
const r = le(t?.table), n = on(e, r);
|
|
1873
|
-
return {
|
|
1874
|
-
...t || {},
|
|
1875
|
-
table: r,
|
|
1876
|
-
products: n,
|
|
1877
|
-
multiple_product_details: n
|
|
1878
|
-
};
|
|
1879
|
-
}
|
|
1880
|
-
function an(t) {
|
|
1881
|
-
return !t || typeof t != "object" || Array.isArray(t) ? null : Object.fromEntries(Object.entries(t).filter(([, e]) => e !== void 0));
|
|
1882
|
-
}
|
|
1883
|
-
function Ro(t = [], e = {}) {
|
|
1884
|
-
const r = {}, n = [];
|
|
1885
|
-
return (Array.isArray(t) ? t.map((o) => Pt(o, e)).filter((o) => !!o) : []).forEach((o, i) => {
|
|
1886
|
-
const a = `product-${i.toString()}`;
|
|
1887
|
-
n.push(a);
|
|
1888
|
-
const s = {
|
|
1889
|
-
sku: o.sku,
|
|
1890
|
-
product: o
|
|
1891
|
-
};
|
|
1892
|
-
r[a] = {
|
|
1893
|
-
type: "ProductCard",
|
|
1894
|
-
props: {
|
|
1895
|
-
product: o,
|
|
1896
|
-
index: i,
|
|
1897
|
-
action: {
|
|
1898
|
-
title: o.name,
|
|
1899
|
-
type: "launchSingleProduct",
|
|
1900
|
-
payload: s
|
|
1901
|
-
}
|
|
1902
|
-
}
|
|
1903
|
-
};
|
|
1904
|
-
}), r.root = {
|
|
1905
|
-
type: "ProductGrid",
|
|
1906
|
-
props: { layout: "grid" },
|
|
1907
|
-
children: n
|
|
1908
|
-
}, {
|
|
1909
|
-
widget: "chat",
|
|
1910
|
-
panelHint: "panel",
|
|
1911
|
-
spec: {
|
|
1912
|
-
root: "root",
|
|
1913
|
-
elements: r
|
|
1914
|
-
}
|
|
1915
|
-
};
|
|
1916
|
-
}
|
|
1917
|
-
function Bo(t, e = {}) {
|
|
1918
|
-
return {
|
|
1919
|
-
widget: "chat",
|
|
1920
|
-
panelHint: "panel",
|
|
1921
|
-
spec: {
|
|
1922
|
-
root: "root",
|
|
1923
|
-
elements: { root: {
|
|
1924
|
-
type: "ProductDetailsPanel",
|
|
1925
|
-
props: { product: Pt(t, e) || t || {} }
|
|
1926
|
-
} }
|
|
1927
|
-
}
|
|
1928
|
-
};
|
|
1929
|
-
}
|
|
1930
|
-
function $o(t = {}, e = {}) {
|
|
1931
|
-
const r = (t.multiple_product_details || t.products || []).map((o) => Pt(o, e)).filter((o) => !!o), n = t.table || sn(t.comparison_table);
|
|
1932
|
-
return {
|
|
1933
|
-
widget: "chat",
|
|
1934
|
-
panelHint: "panel",
|
|
1935
|
-
spec: {
|
|
1936
|
-
root: "root",
|
|
1937
|
-
elements: { root: {
|
|
1938
|
-
type: "ComparisonTable",
|
|
1939
|
-
props: {
|
|
1940
|
-
products: r,
|
|
1941
|
-
recommended: r.find((o) => o.sku === t.recommended_choice_sku) || r[0],
|
|
1942
|
-
attributes: Object.entries(n).map(([o, i]) => ({
|
|
1943
|
-
label: o,
|
|
1944
|
-
values: Array.isArray(i) ? i.map(String) : [String(i ?? "")]
|
|
1945
|
-
})),
|
|
1946
|
-
highlights: Ht(t.key_differences),
|
|
1947
|
-
specialCases: Ht(t.special_considerations),
|
|
1948
|
-
recommendedText: t.recommended_choice,
|
|
1949
|
-
productActions: Object.fromEntries(r.map((o) => [o.sku, {
|
|
1950
|
-
title: o.name,
|
|
1951
|
-
type: "launchSingleProduct",
|
|
1952
|
-
payload: {
|
|
1953
|
-
sku: o.sku,
|
|
1954
|
-
product: o
|
|
1955
|
-
}
|
|
1956
|
-
}]))
|
|
1957
|
-
}
|
|
1958
|
-
} }
|
|
1959
|
-
}
|
|
1960
|
-
};
|
|
1961
|
-
}
|
|
1962
|
-
function sn(t) {
|
|
1963
|
-
return Array.isArray(t) ? Object.fromEntries(t.map((e) => {
|
|
1964
|
-
const r = typeof e?.label == "string" ? e.label.trim() : "";
|
|
1965
|
-
return r ? [r, e.values] : null;
|
|
1966
|
-
}).filter((e) => !!e)) : {};
|
|
1967
|
-
}
|
|
1968
|
-
function No(t = []) {
|
|
1969
|
-
return {
|
|
1970
|
-
widget: "chat",
|
|
1971
|
-
panelHint: "inline",
|
|
1972
|
-
spec: {
|
|
1973
|
-
root: "root",
|
|
1974
|
-
elements: { root: {
|
|
1975
|
-
type: "ActionButtons",
|
|
1976
|
-
props: { buttons: (Array.isArray(t) ? t : []).map((e) => {
|
|
1977
|
-
const r = e.label || e.title || e.shortName || "", n = e.action || e.requestDetails || e.request_details;
|
|
1978
|
-
return !r || !n?.type ? null : {
|
|
1979
|
-
label: r,
|
|
1980
|
-
action: {
|
|
1981
|
-
title: r,
|
|
1982
|
-
type: n.type,
|
|
1983
|
-
...n.payload !== void 0 ? { payload: n.payload } : {}
|
|
1984
|
-
}
|
|
1985
|
-
};
|
|
1986
|
-
}).filter((e) => !!e) }
|
|
1987
|
-
} }
|
|
1988
|
-
}
|
|
1989
|
-
};
|
|
1990
|
-
}
|
|
1991
|
-
function Fo(t) {
|
|
1992
|
-
return Object.freeze([...t]);
|
|
1993
|
-
}
|
|
1994
|
-
function cn(t) {
|
|
1995
|
-
const e = t?.payload;
|
|
1996
|
-
if (typeof e == "string") return e;
|
|
1997
|
-
if (e && typeof e == "object" && "text" in e) {
|
|
1998
|
-
const n = e.text;
|
|
1999
|
-
if (typeof n == "string") return n;
|
|
2000
|
-
}
|
|
2001
|
-
const r = t?.action;
|
|
2002
|
-
return r && typeof r.payload == "string" ? r.payload : r && typeof r.title == "string" ? r.title : "";
|
|
2003
|
-
}
|
|
2004
|
-
var fe = [
|
|
2005
|
-
{
|
|
2006
|
-
pattern: /\bhttps?:\/\/[^\s?#]+(?:\?[^\s#]*)?/giu,
|
|
2007
|
-
replacement: ln
|
|
2008
|
-
},
|
|
2009
|
-
{
|
|
2010
|
-
pattern: /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/giu,
|
|
2011
|
-
replacement: "[email]"
|
|
2012
|
-
},
|
|
2013
|
-
{
|
|
2014
|
-
pattern: /\b(?:\+?\d[\d\s().-]{7,}\d)\b/gu,
|
|
2015
|
-
replacement: "[phone]"
|
|
2016
|
-
},
|
|
2017
|
-
{
|
|
2018
|
-
pattern: /\b(?:token|secret|csrf|cookie|bearer|session|sid|cart(?:[_-]?id)?)\s*[:=]\s*[^\s,;&]+/giu,
|
|
2019
|
-
replacement: "[secret]"
|
|
2020
|
-
},
|
|
2021
|
-
{
|
|
2022
|
-
pattern: /\b(?:order|cart|session)[_-]?(?:id|no|number)?\s*[:#=]?\s*[A-Z0-9-]{6,}\b/giu,
|
|
2023
|
-
replacement: "[secret]"
|
|
2024
|
-
}
|
|
2025
|
-
], de = { patterns: fe };
|
|
2026
|
-
function pe(t, e = de) {
|
|
2027
|
-
let r = typeof t == "string" ? t : t == null ? "" : String(t);
|
|
2028
|
-
for (const n of e.patterns || []) {
|
|
2029
|
-
const o = n.replacement;
|
|
2030
|
-
r = typeof o == "function" ? r.replace(n.pattern, (i) => o(i)) : r.replace(n.pattern, o);
|
|
2031
|
-
}
|
|
2032
|
-
return r;
|
|
2033
|
-
}
|
|
2034
|
-
function un(t, e = de) {
|
|
2035
|
-
return pe(cn(t), e);
|
|
2036
|
-
}
|
|
2037
|
-
function ln(t) {
|
|
2038
|
-
try {
|
|
2039
|
-
const e = new URL(t);
|
|
2040
|
-
return `${e.origin}${e.pathname}${e.search ? "?[query]" : ""}`;
|
|
2041
|
-
} catch {
|
|
2042
|
-
return "[url]";
|
|
2043
|
-
}
|
|
2044
|
-
}
|
|
2045
|
-
var fn = [
|
|
2046
|
-
"assistantName",
|
|
2047
|
-
"homeDomain",
|
|
2048
|
-
"categories",
|
|
2049
|
-
"policyTopics"
|
|
2050
|
-
], dn = { intent: ["searchContract", "competitorBrands"] };
|
|
2051
|
-
function Lo(t, e, r, n = {}) {
|
|
2052
|
-
const o = pn(e, r, n);
|
|
2053
|
-
return Object.keys(o).length ? {
|
|
2054
|
-
...t,
|
|
2055
|
-
account_config: o
|
|
2056
|
-
} : t;
|
|
2057
|
-
}
|
|
2058
|
-
function pn(t, e, r = {}) {
|
|
2059
|
-
if (!t) return {};
|
|
2060
|
-
const n = {}, o = r.baseKeys || fn;
|
|
2061
|
-
for (const s of o) Wt(n, t, s);
|
|
2062
|
-
const i = t[e];
|
|
2063
|
-
i && typeof i == "object" && !Array.isArray(i) && Object.assign(n, mn(i));
|
|
2064
|
-
const a = r.opAllowlist || dn;
|
|
2065
|
-
for (const s of a[e] || []) Wt(n, t, s);
|
|
2066
|
-
return n;
|
|
2067
|
-
}
|
|
2068
|
-
function Wt(t, e, r) {
|
|
2069
|
-
e[r] !== void 0 && (t[r] = e[r]);
|
|
2070
|
-
}
|
|
2071
|
-
function mn(t) {
|
|
2072
|
-
return Object.fromEntries(Object.entries(t).filter(([, e]) => e !== void 0));
|
|
2073
|
-
}
|
|
2074
|
-
var yn = "input-hash";
|
|
2075
|
-
function gn({ ttlS: t, promptVersion: e = "current" } = {}) {
|
|
2076
|
-
if (!Number.isFinite(t) || t <= 0) throw new Error("inputHashCachePolicy requires a positive ttlS");
|
|
2077
|
-
return {
|
|
2078
|
-
strategy: yn,
|
|
2079
|
-
ttlS: t,
|
|
2080
|
-
promptVersion: e
|
|
2081
|
-
};
|
|
2082
|
-
}
|
|
2083
|
-
function hn({ accountId: t = "", op: e, ttlS: r, promptVersion: n = "current", input: o, keyParts: i, locale: a } = {}) {
|
|
2084
|
-
if (!e) throw new Error("declarativeBeOpCache requires an op");
|
|
2085
|
-
return {
|
|
2086
|
-
cache: gn({
|
|
2087
|
-
ttlS: r,
|
|
2088
|
-
promptVersion: n
|
|
2089
|
-
}),
|
|
2090
|
-
cacheTtlS: r,
|
|
2091
|
-
cacheKey: (s = {}) => oe(e, {
|
|
2092
|
-
account: t,
|
|
2093
|
-
locale: wt(a, s) || s.context?.meta?.locale || s.locale || "",
|
|
2094
|
-
promptVersion: n,
|
|
2095
|
-
payload: At(wt(o, s)),
|
|
2096
|
-
...wn(wt(i, s))
|
|
2097
|
-
})
|
|
2098
|
-
};
|
|
2099
|
-
}
|
|
2100
|
-
function qo(t, e = {}) {
|
|
2101
|
-
return !t || t.kind !== "be_op" ? t : {
|
|
2102
|
-
...t,
|
|
2103
|
-
...hn({
|
|
2104
|
-
op: t.op,
|
|
2105
|
-
ttlS: t.cacheTtlS,
|
|
2106
|
-
input: t.input,
|
|
2107
|
-
...e
|
|
2108
|
-
})
|
|
2109
|
-
};
|
|
2110
|
-
}
|
|
2111
|
-
function wt(t, e) {
|
|
2112
|
-
return typeof t == "function" ? t(e) : t;
|
|
2113
|
-
}
|
|
2114
|
-
function At(t) {
|
|
2115
|
-
return Array.isArray(t) ? t.map(At) : !t || typeof t != "object" ? t : Object.fromEntries(Object.entries(t).filter(([, e]) => e !== void 0).sort(([e], [r]) => e.localeCompare(r)).map(([e, r]) => [e, At(r)]));
|
|
2116
|
-
}
|
|
2117
|
-
function wn(t) {
|
|
2118
|
-
return !t || typeof t != "object" || Array.isArray(t) ? {} : Object.fromEntries(Object.entries(t).filter(([, e]) => e != null));
|
|
2119
|
-
}
|
|
2120
|
-
var Do = Object.freeze({
|
|
2121
|
-
FALLBACK_RESULTS: "fallback_results",
|
|
2122
|
-
FALLBACK_NO_RESULTS: "fallback_no_results",
|
|
2123
|
-
FALLBACK_PARTIAL: "fallback_partial",
|
|
2124
|
-
OP_UNAVAILABLE: "op_unavailable"
|
|
2125
|
-
});
|
|
2126
|
-
function Uo(t, e = {}) {
|
|
2127
|
-
return {
|
|
2128
|
-
status: t,
|
|
2129
|
-
...e
|
|
2130
|
-
};
|
|
2131
|
-
}
|
|
2132
|
-
function zo(t) {
|
|
2133
|
-
return !!(t && typeof t == "object" && typeof t.status == "string");
|
|
2134
|
-
}
|
|
2135
|
-
function Vo(t) {
|
|
2136
|
-
return function() {
|
|
2137
|
-
return [{
|
|
2138
|
-
kind: "tool",
|
|
2139
|
-
name: "readPage",
|
|
2140
|
-
input: () => ({}),
|
|
2141
|
-
out: "page",
|
|
2142
|
-
patch: (r, n) => n?.product && typeof t == "function" ? t(r, n.product) : null,
|
|
2143
|
-
onError: []
|
|
2144
|
-
}];
|
|
2145
|
-
};
|
|
2146
|
-
}
|
|
2147
|
-
function Ko(t) {
|
|
2148
|
-
return !t || typeof t != "object" || Array.isArray(t) ? {} : Object.fromEntries(Object.entries(t).filter(([, e]) => e != null && e !== "" && (!Array.isArray(e) || e.length > 0)));
|
|
2149
|
-
}
|
|
2150
|
-
function Ho(t, { screenSummary: e } = {}) {
|
|
2151
|
-
return { panel: {
|
|
2152
|
-
...t?.panel || {},
|
|
2153
|
-
screen_type: "homepage",
|
|
2154
|
-
screen_sku_list: [],
|
|
2155
|
-
screen_summary: e || null,
|
|
2156
|
-
last_search_products: [],
|
|
2157
|
-
last_search: null,
|
|
2158
|
-
chat_mentioned_skus: [],
|
|
2159
|
-
reviews_summary_skus: [],
|
|
2160
|
-
ai_plist_summary: null,
|
|
2161
|
-
search_suggestions_skus: [],
|
|
2162
|
-
list_source: null,
|
|
2163
|
-
active_product_panel: !1,
|
|
2164
|
-
assistant_mode: "shopping",
|
|
2165
|
-
redirected_agent_state: null,
|
|
2166
|
-
ui_hints: null
|
|
2167
|
-
} };
|
|
2168
|
-
}
|
|
2169
|
-
function bn({ patterns: t, messageFilter: e, messageNormalizer: r = (o) => o, messageLimit: n = 10 } = {}) {
|
|
2170
|
-
const o = { patterns: [...fe, ...Array.isArray(t) ? t : []] };
|
|
2171
|
-
function i(c) {
|
|
2172
|
-
return pe(c, o);
|
|
2173
|
-
}
|
|
2174
|
-
function a(c) {
|
|
2175
|
-
return un(c, o);
|
|
2176
|
-
}
|
|
2177
|
-
function s(c = []) {
|
|
2178
|
-
const u = (Array.isArray(c) ? c : []).filter((l) => typeof e == "function" ? e(l) : l && typeof l == "object").filter(Boolean);
|
|
2179
|
-
return (Number.isFinite(n) && n > 0 ? u.slice(-n) : u).map((l) => ({
|
|
2180
|
-
role: l.role,
|
|
2181
|
-
content: i(r(l.content)).slice(0, 1e3)
|
|
2182
|
-
}));
|
|
2183
|
-
}
|
|
2184
|
-
return {
|
|
2185
|
-
redactPii: i,
|
|
2186
|
-
anonymousRequestText: a,
|
|
2187
|
-
anonymizeMessages: s
|
|
2188
|
-
};
|
|
2189
|
-
}
|
|
2190
|
-
function Jo(t) {
|
|
2191
|
-
return String(t || "").replace(/<script\b[\s\S]*?<\/script>/giu, " ").replace(/<style\b[\s\S]*?<\/style>/giu, " ").replace(/<[^>]+>/gu, " ").replace(/ /giu, " ").replace(/&/giu, "&").replace(/<|>/giu, " ").replace(/\s+/gu, " ").trim();
|
|
2192
|
-
}
|
|
2193
|
-
var A = {
|
|
2194
|
-
features: 18,
|
|
2195
|
-
reviews: 4,
|
|
2196
|
-
qna: 4,
|
|
2197
|
-
sellers: 4,
|
|
2198
|
-
variants: 12,
|
|
2199
|
-
documents: 6,
|
|
2200
|
-
textBlocks: 6,
|
|
2201
|
-
relatedProducts: 8,
|
|
2202
|
-
textChars: 220
|
|
2203
|
-
}, Rt = {
|
|
2204
|
-
description: /\b(?:description|details|product information|urun bilgisi|urun aciklamasi|açıklama|aciklama)\b/iu,
|
|
2205
|
-
seller: /\b(?:seller|merchant|store|satici|satıcı|magaza|mağaza)\b/iu,
|
|
2206
|
-
review: /\b(?:review|reviews|rating|ratings|yorum|degerlendirme|değerlendirme|puan)\b/iu,
|
|
2207
|
-
qna: /\b(?:questions?|answers?|qna|q&a|soru|cevap)\b/iu,
|
|
2208
|
-
payment: /\b(?:installment|instalment|payment|pay in|taksit|odeme|ödeme|vade)\b/iu,
|
|
2209
|
-
delivery: /\b(?:delivery|shipping|cargo|stock|availability|teslimat|kargo|stok|gonderim|gönderim)\b/iu,
|
|
2210
|
-
promotion: /\b(?:campaign|promotion|discount|coupon|deal|kampanya|indirim|kupon|firsat|fırsat)\b/iu,
|
|
2211
|
-
variant: /\b(?:variant|size|colour|color|beden|olcu|ölçü|renk|numara)\b/iu
|
|
2212
|
-
}, kn = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}|\+?\d[\d\s().-]{8,}\d|\b[A-Z]{1,2}\d[A-Z\d]?\s*\d[A-Z]{2}\b|\b(?:token|session|csrf|secret)\s*[:=]\s*[\w.-]+/giu, _n = /(?:token|session|sid|auth|code|csrf|secret|key|password|passwd|phone|email|address|postcode|zip|jwt|bearer)/iu, An = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}|\+?\d[\d\s().-]{8,}\d|[A-Z]{1,2}\d[A-Z\d]?\s*\d[A-Z]{2}|[A-Za-z0-9_-]{24,}/iu;
|
|
2213
|
-
function Zo({ accountId: t, getPageType: e, getProduct: r, getProducts: n, normalizeProduct: o = (i) => i }) {
|
|
2214
|
-
return (i = {}) => Sn({
|
|
2215
|
-
accountId: t,
|
|
2216
|
-
getPageType: e,
|
|
2217
|
-
getProduct: r,
|
|
2218
|
-
getProducts: n,
|
|
2219
|
-
normalizeProduct: o,
|
|
2220
|
-
input: i
|
|
2221
|
-
});
|
|
2222
|
-
}
|
|
2223
|
-
function Sn({ accountId: t, getPageType: e, getProduct: r, getProducts: n, normalizeProduct: o = (a) => a, input: i = {} }) {
|
|
2224
|
-
const a = Wn(i), s = o(i.product || bt(r)), c = (bt(n) || []).map(o).filter(Boolean), u = k(i.sku || s?.sku || i.product?.sku), l = u ? c.find((lt) => k(lt?.sku) === u) || s : s || c[0] || null, f = Cn(u || l?.sku), d = Gt({
|
|
2225
|
-
...f.product,
|
|
2226
|
-
...l
|
|
2227
|
-
}), p = Ft(ot(l?.features), ot(l?.specs), Fn(l?.facet_hits), ot(f.product?.features), En(), Pn(), In()).slice(0, a.features), m = ye(ct(l?.reviews), f.reviews, On()).slice(0, a.reviews), g = ge(Bt(l?.qna), jn()).slice(0, a.qna), S = he($t(l?.sellers), Mn()).slice(0, a.sellers), $ = B([...l?.payment || [], ...nt("payment", a)]), tt = B([...l?.delivery || [], ...nt("delivery", a)]), M = B([...l?.promotions || [], ...nt("promotion", a)]), N = we(Nt(l?.variants), Rn()).slice(0, a.variants), R = Bn(a.documents), F = ke(l?.description, f.product?.description, $n("description"), nt("description", {
|
|
2228
|
-
...a,
|
|
2229
|
-
textBlocks: 2
|
|
2230
|
-
})[0]), _ = c.filter((lt) => !u || k(lt?.sku) !== u).map(Gt).filter(Boolean).slice(0, a.relatedProducts);
|
|
2231
|
-
return z({
|
|
2232
|
-
accountId: t,
|
|
2233
|
-
pageType: bt(e) || "other",
|
|
2234
|
-
url: Zn(),
|
|
2235
|
-
product: d,
|
|
2236
|
-
description: F,
|
|
2237
|
-
features: p,
|
|
2238
|
-
sellers: S,
|
|
2239
|
-
reviews: m,
|
|
2240
|
-
qna: g,
|
|
2241
|
-
rating: x(l?.rating ?? f.rating),
|
|
2242
|
-
review_count: x(l?.review_count ?? f.review_count),
|
|
2243
|
-
payment: $,
|
|
2244
|
-
delivery: tt,
|
|
2245
|
-
promotions: M,
|
|
2246
|
-
variants: N,
|
|
2247
|
-
documents: R,
|
|
2248
|
-
related_products: _,
|
|
2249
|
-
capabilities: Vn({
|
|
2250
|
-
description: F,
|
|
2251
|
-
features: p,
|
|
2252
|
-
sellers: S,
|
|
2253
|
-
reviews: m,
|
|
2254
|
-
qna: g,
|
|
2255
|
-
payment: $,
|
|
2256
|
-
delivery: tt,
|
|
2257
|
-
promotions: M,
|
|
2258
|
-
variants: N,
|
|
2259
|
-
documents: R,
|
|
2260
|
-
relatedProducts: _
|
|
2261
|
-
}),
|
|
2262
|
-
privacy: {
|
|
2263
|
-
browserLocal: !0,
|
|
2264
|
-
rawHtml: !1,
|
|
2265
|
-
formValues: !1,
|
|
2266
|
-
cookies: !1,
|
|
2267
|
-
storage: !1,
|
|
2268
|
-
redacted: !0
|
|
2269
|
-
}
|
|
2270
|
-
});
|
|
2271
|
-
}
|
|
2272
|
-
function Wo(t, e) {
|
|
2273
|
-
const r = Array.isArray(t) ? t.filter(Boolean) : [];
|
|
2274
|
-
if (!e || typeof e != "object" || !r.length) return r;
|
|
2275
|
-
const n = k(e.product?.sku);
|
|
2276
|
-
return r.map((o, i) => {
|
|
2277
|
-
const a = k(o?.sku);
|
|
2278
|
-
return r.length === 1 || n && a && n === a || i === 0 ? vn(o, e) : o;
|
|
2279
|
-
});
|
|
2280
|
-
}
|
|
2281
|
-
function xn(t) {
|
|
2282
|
-
return !t || typeof t != "object" ? null : z({
|
|
2283
|
-
product: t.product,
|
|
2284
|
-
description: h(t.description, 500),
|
|
2285
|
-
features: Ln(t.features, 14),
|
|
2286
|
-
sellers: Un(t.sellers, 4),
|
|
2287
|
-
reviews: qn(t.reviews, 4),
|
|
2288
|
-
qna: Dn(t.qna, 4),
|
|
2289
|
-
rating: t.rating,
|
|
2290
|
-
review_count: t.review_count,
|
|
2291
|
-
payment: j(t.payment, 5, 160),
|
|
2292
|
-
delivery: j(t.delivery, 5, 160),
|
|
2293
|
-
promotions: j(t.promotions, 5, 160),
|
|
2294
|
-
variants: zn(t.variants, 10),
|
|
2295
|
-
documents: j(t.documents, 5, 220),
|
|
2296
|
-
capabilities: Array.isArray(t.capabilities) ? t.capabilities.slice(0, 12) : void 0
|
|
2297
|
-
});
|
|
2298
|
-
}
|
|
2299
|
-
function Go(t, e, r = {}) {
|
|
2300
|
-
const n = xn(t);
|
|
2301
|
-
if (!n) return e;
|
|
2302
|
-
const o = String(r.locale || "").toLowerCase().startsWith("en"), i = [], a = [n.rating ? `${n.rating}/5` : "", n.review_count ? `${n.review_count} ${o ? "reviews" : "yorum"}` : ""].filter(Boolean).join(", ");
|
|
2303
|
-
return a && i.push(o ? `Visible rating: ${a}.` : `Görünür puan bilgisi: ${a}.`), n.reviews?.length && i.push(`${o ? "Visible review highlights" : "Görünür yorumlardan öne çıkanlar"}: ${n.reviews.map((s) => [s.star ? `${s.star}/5` : "", s.content].filter(Boolean).join(" ")).filter(Boolean).slice(0, 3).join(" | ")}.`), i.length ? (i.push(o ? "This summary only uses product review and rating fields visible in the browser." : "Bu özet yalnızca tarayıcıda görünen ürün yorumu ve puan alanlarından hazırlandı."), i.join(" ")) : e;
|
|
2304
|
-
}
|
|
2305
|
-
function vn(t, e) {
|
|
2306
|
-
return z({
|
|
2307
|
-
...t,
|
|
2308
|
-
description: ke(t.description, e.description),
|
|
2309
|
-
features: Ft(ot(t.features), e.features).slice(0, 24),
|
|
2310
|
-
specs: t.specs || (e.features?.length ? Object.fromEntries(e.features.map(Kn)) : void 0),
|
|
2311
|
-
sellers: he($t(t.sellers), e.sellers),
|
|
2312
|
-
reviews: ye(ct(t.reviews), e.reviews),
|
|
2313
|
-
qna: ge(Bt(t.qna), e.qna),
|
|
2314
|
-
rating: t.rating ?? e.rating,
|
|
2315
|
-
review_count: t.review_count ?? e.review_count,
|
|
2316
|
-
payment: B([...t.payment || [], ...e.payment || []]),
|
|
2317
|
-
delivery: B([...t.delivery || [], ...e.delivery || []]),
|
|
2318
|
-
promotions: B([...t.promotions || [], ...e.promotions || []]),
|
|
2319
|
-
variants: we(Nt(t.variants), e.variants),
|
|
2320
|
-
documents: B([...t.documents || [], ...e.documents || []])
|
|
2321
|
-
});
|
|
2322
|
-
}
|
|
2323
|
-
function Cn(t) {
|
|
2324
|
-
const e = [];
|
|
2325
|
-
for (const o of T('script[type="application/ld+json"]')) {
|
|
2326
|
-
const i = Tn(o.textContent);
|
|
2327
|
-
for (const a of St(i))
|
|
2328
|
-
String(a?.["@type"] || "").toLowerCase() === "product" && e.push(a);
|
|
2329
|
-
}
|
|
2330
|
-
const r = e.find((o) => k(o.sku || o.productID || o.mpn) === k(t)) || e[0];
|
|
2331
|
-
if (!r) return {};
|
|
2332
|
-
const n = r.aggregateRating || {};
|
|
2333
|
-
return {
|
|
2334
|
-
product: z({
|
|
2335
|
-
sku: k(r.sku || r.productID || r.mpn),
|
|
2336
|
-
name: y(r.name),
|
|
2337
|
-
brand: y(r.brand?.name || r.brand),
|
|
2338
|
-
description: y(r.description),
|
|
2339
|
-
images: j(r.image, 8, 280),
|
|
2340
|
-
url: X(r.url),
|
|
2341
|
-
rating: x(n.ratingValue),
|
|
2342
|
-
review_count: x(n.reviewCount || n.ratingCount)
|
|
2343
|
-
}),
|
|
2344
|
-
reviews: ct(r.review),
|
|
2345
|
-
rating: x(n.ratingValue),
|
|
2346
|
-
review_count: x(n.reviewCount || n.ratingCount)
|
|
2347
|
-
};
|
|
2348
|
-
}
|
|
2349
|
-
function St(t) {
|
|
2350
|
-
return Array.isArray(t) ? t.flatMap(St) : !t || typeof t != "object" ? [] : [t, ...St(t["@graph"])];
|
|
2351
|
-
}
|
|
2352
|
-
function Tn(t) {
|
|
2353
|
-
try {
|
|
2354
|
-
return JSON.parse(String(t || ""));
|
|
2355
|
-
} catch {
|
|
2356
|
-
return null;
|
|
2357
|
-
}
|
|
2358
|
-
}
|
|
2359
|
-
function En() {
|
|
2360
|
-
const t = [];
|
|
2361
|
-
for (const e of T("table tr")) {
|
|
2362
|
-
const r = [...e.querySelectorAll?.("th,td") || []].map((n) => y(n.textContent));
|
|
2363
|
-
r.length >= 2 && r[0] && r[1] && t.push({
|
|
2364
|
-
key: r[0],
|
|
2365
|
-
value: r.slice(1).join(" ")
|
|
2366
|
-
});
|
|
2367
|
-
}
|
|
2368
|
-
return t;
|
|
2369
|
-
}
|
|
2370
|
-
function Pn() {
|
|
2371
|
-
const t = [];
|
|
2372
|
-
for (const e of T("dt")) {
|
|
2373
|
-
const r = y(e.textContent), n = y(e.nextElementSibling?.matches?.("dd") ? e.nextElementSibling.textContent : "");
|
|
2374
|
-
r && n && t.push({
|
|
2375
|
-
key: r,
|
|
2376
|
-
value: n
|
|
2377
|
-
});
|
|
2378
|
-
}
|
|
2379
|
-
return t;
|
|
2380
|
-
}
|
|
2381
|
-
function In() {
|
|
2382
|
-
return T('[class*="spec" i], [class*="feature" i], [class*="attribute" i], li').map((t) => me(y(t.textContent))).filter(Boolean).slice(0, A.features);
|
|
2383
|
-
}
|
|
2384
|
-
function On() {
|
|
2385
|
-
return T('[class*="review" i], [data-review], [itemprop="review"]').map((t) => {
|
|
2386
|
-
const e = y(t.textContent);
|
|
2387
|
-
return !e || e.length < 8 || Rt.qna.test(e) ? null : {
|
|
2388
|
-
content: h(e, 260),
|
|
2389
|
-
star: x(t.getAttribute?.("data-rating"))
|
|
2390
|
-
};
|
|
2391
|
-
}).filter(Boolean);
|
|
2392
|
-
}
|
|
2393
|
-
function jn() {
|
|
2394
|
-
const t = T('[class*="question" i], [class*="answer" i], [data-question], [data-answer]'), e = [];
|
|
2395
|
-
for (const r of t) {
|
|
2396
|
-
const n = y(r.textContent);
|
|
2397
|
-
if (!n || !Rt.qna.test(n)) continue;
|
|
2398
|
-
const o = y(r.getAttribute?.("data-question") || n), i = y(r.getAttribute?.("data-answer") || r.nextElementSibling?.textContent || "");
|
|
2399
|
-
e.push({
|
|
2400
|
-
question: h(o, 220),
|
|
2401
|
-
answer: h(i, 260)
|
|
2402
|
-
});
|
|
2403
|
-
}
|
|
2404
|
-
return e;
|
|
2405
|
-
}
|
|
2406
|
-
function Mn() {
|
|
2407
|
-
return T('[class*="seller" i], [class*="merchant" i], [data-seller], [data-merchant]').map((t) => y(t.getAttribute?.("data-seller") || t.getAttribute?.("data-merchant") || t.textContent)).filter(Boolean).map((t) => ({ merchant: h(t, 120) }));
|
|
2408
|
-
}
|
|
2409
|
-
function Rn() {
|
|
2410
|
-
return T('[class*="variant" i] a,[class*="variant" i] button,[class*="size" i] button,[class*="color" i] button,[data-variant],[data-size],[data-color]').map((t) => z({
|
|
2411
|
-
name: h(_e(t), 120),
|
|
2412
|
-
value: h(t.getAttribute?.("data-value") || t.getAttribute?.("data-size") || t.getAttribute?.("data-color"), 120),
|
|
2413
|
-
sku: k(t.getAttribute?.("data-sku") || t.getAttribute?.("data-product-id")),
|
|
2414
|
-
url: X(t.getAttribute?.("href")),
|
|
2415
|
-
in_stock: t.getAttribute?.("disabled") == null && t.getAttribute?.("aria-disabled") !== "true"
|
|
2416
|
-
})).filter((t) => t.name || t.value || t.sku);
|
|
2417
|
-
}
|
|
2418
|
-
function Bn(t) {
|
|
2419
|
-
return T("a[href]").filter((e) => /\.pdf(?:$|[?#])/iu.test(e.getAttribute?.("href") || "")).map((e) => {
|
|
2420
|
-
const r = _e(e) || "PDF", n = X(e.getAttribute?.("href"));
|
|
2421
|
-
return n ? `${r}: ${n}` : "";
|
|
2422
|
-
}).filter(Boolean).slice(0, t);
|
|
2423
|
-
}
|
|
2424
|
-
function nt(t, e) {
|
|
2425
|
-
const r = Rt[t];
|
|
2426
|
-
return r ? T("section,article,div,li,p,span,button,a").map((n) => y(n.textContent)).filter((n) => n && r.test(n) && n.length <= 900).map((n) => h(n, e.textChars || A.textChars)).filter(be()).slice(0, e.textBlocks || A.textBlocks) : [];
|
|
2427
|
-
}
|
|
2428
|
-
function $n(t) {
|
|
2429
|
-
return y(document.querySelector?.(`meta[name="${t}"]`)?.getAttribute?.("content") || document.querySelector?.(`meta[property="og:${t}"]`)?.getAttribute?.("content"));
|
|
2430
|
-
}
|
|
2431
|
-
function T(t) {
|
|
2432
|
-
try {
|
|
2433
|
-
return [...document.querySelectorAll?.(t) || []].filter(Nn);
|
|
2434
|
-
} catch {
|
|
2435
|
-
return [];
|
|
2436
|
-
}
|
|
2437
|
-
}
|
|
2438
|
-
function Nn(t) {
|
|
2439
|
-
if (!t) return !1;
|
|
2440
|
-
if (!t.getBoundingClientRect) return !0;
|
|
2441
|
-
const e = t.getBoundingClientRect();
|
|
2442
|
-
if (e.width <= 0 || e.height <= 0) return !1;
|
|
2443
|
-
const r = window.getComputedStyle?.(t);
|
|
2444
|
-
return !r || r.visibility !== "hidden" && r.display !== "none" && Number(r.opacity || 1) > 0;
|
|
2445
|
-
}
|
|
2446
|
-
function ot(t) {
|
|
2447
|
-
return t ? (Array.isArray(t) ? t : Object.entries(t).map(([e, r]) => ({
|
|
2448
|
-
key: e,
|
|
2449
|
-
value: r
|
|
2450
|
-
}))).map((e) => typeof e == "string" ? me(e) || {
|
|
2451
|
-
key: "",
|
|
2452
|
-
value: y(e)
|
|
2453
|
-
} : {
|
|
2454
|
-
key: y(e.key || e.name || e.label),
|
|
2455
|
-
value: y(e.value || e.text || "")
|
|
2456
|
-
}).filter((e) => e.key || e.value) : [];
|
|
2457
|
-
}
|
|
2458
|
-
function Fn(t) {
|
|
2459
|
-
return !t || typeof t != "object" ? [] : Object.entries(t).map(([e, r]) => ({
|
|
2460
|
-
key: y(e),
|
|
2461
|
-
value: y(r)
|
|
2462
|
-
}));
|
|
2463
|
-
}
|
|
2464
|
-
function me(t) {
|
|
2465
|
-
const e = /^(.{2,80}?)\s*[::]\s*(.{1,220})$/u.exec(y(t));
|
|
2466
|
-
return e ? {
|
|
2467
|
-
key: e[1],
|
|
2468
|
-
value: e[2]
|
|
2469
|
-
} : null;
|
|
2470
|
-
}
|
|
2471
|
-
function ct(t) {
|
|
2472
|
-
return (Array.isArray(t) ? t : t ? [t] : []).map((e) => typeof e == "string" ? { content: h(e, 260) } : {
|
|
2473
|
-
content: h(e.content || e.reviewBody || e.description || e.text, 260),
|
|
2474
|
-
star: x(e.star || e.rating || e.reviewRating?.ratingValue)
|
|
2475
|
-
}).filter((e) => e.content || e.star);
|
|
2476
|
-
}
|
|
2477
|
-
function Bt(t) {
|
|
2478
|
-
return (Array.isArray(t) ? t : t ? [t] : []).map((e) => ({
|
|
2479
|
-
question: h(e.question || e.name || "", 220),
|
|
2480
|
-
answer: h(e.answer || e.acceptedAnswer?.text || e.text || "", 260)
|
|
2481
|
-
})).filter((e) => e.question || e.answer);
|
|
2482
|
-
}
|
|
2483
|
-
function $t(t) {
|
|
2484
|
-
return (Array.isArray(t) ? t : t ? [t] : []).map((e) => typeof e == "string" ? { merchant: h(e, 120) } : {
|
|
2485
|
-
merchant: h(e.merchant || e.name || e.seller || "", 120),
|
|
2486
|
-
merchant_id: k(e.merchant_id || e.id || ""),
|
|
2487
|
-
merchant_rating: x(e.merchant_rating || e.rating),
|
|
2488
|
-
price_offer: x(e.price_offer || e.price)
|
|
2489
|
-
}).filter((e) => e.merchant || e.merchant_id);
|
|
2490
|
-
}
|
|
2491
|
-
function Nt(t) {
|
|
2492
|
-
return (Array.isArray(t) ? t : t ? [t] : []).map((e) => ({
|
|
2493
|
-
name: h(e.name || e.label || e.title || "", 120),
|
|
2494
|
-
value: h(e.value || e.size || e.color || "", 120),
|
|
2495
|
-
sku: k(e.sku || e.code || ""),
|
|
2496
|
-
url: X(e.url),
|
|
2497
|
-
in_stock: e.in_stock
|
|
2498
|
-
})).filter((e) => e.name || e.value || e.sku || e.url);
|
|
2499
|
-
}
|
|
2500
|
-
function Ft(...t) {
|
|
2501
|
-
const e = /* @__PURE__ */ new Set(), r = [];
|
|
2502
|
-
for (const n of t.flat().filter(Boolean)) {
|
|
2503
|
-
const o = {
|
|
2504
|
-
key: h(n.key || n.name || "", 90),
|
|
2505
|
-
value: h(n.value || n.text || "", 180)
|
|
2506
|
-
}, i = `${o.key}:${o.value}`.toLocaleLowerCase("tr-TR");
|
|
2507
|
-
!o.key && !o.value || e.has(i) || (e.add(i), r.push(o));
|
|
2508
|
-
}
|
|
2509
|
-
return r;
|
|
2510
|
-
}
|
|
2511
|
-
function ye(...t) {
|
|
2512
|
-
return ut(t.flat().filter(Boolean), (e) => `${e.star || ""}:${e.content || ""}`);
|
|
2513
|
-
}
|
|
2514
|
-
function ge(...t) {
|
|
2515
|
-
return ut(t.flat().filter(Boolean), (e) => `${e.question || ""}:${e.answer || ""}`);
|
|
2516
|
-
}
|
|
2517
|
-
function he(...t) {
|
|
2518
|
-
return ut(t.flat().filter(Boolean), (e) => `${e.merchant || ""}:${e.merchant_id || ""}`);
|
|
2519
|
-
}
|
|
2520
|
-
function we(...t) {
|
|
2521
|
-
return ut(t.flat().filter(Boolean), (e) => `${e.sku || ""}:${e.name || ""}:${e.value || ""}`);
|
|
2522
|
-
}
|
|
2523
|
-
function ut(t, e) {
|
|
2524
|
-
const r = /* @__PURE__ */ new Set();
|
|
2525
|
-
return t.filter((n) => {
|
|
2526
|
-
const o = e(n).toLocaleLowerCase("tr-TR");
|
|
2527
|
-
return !o.trim() || r.has(o) ? !1 : (r.add(o), !0);
|
|
2528
|
-
});
|
|
2529
|
-
}
|
|
2530
|
-
function B(t) {
|
|
2531
|
-
return j(t, 20, A.textChars);
|
|
2532
|
-
}
|
|
2533
|
-
function j(t, e, r) {
|
|
2534
|
-
return (Array.isArray(t) ? t : t ? [t] : []).map((n) => h(n, r)).filter(Boolean).filter(be()).slice(0, e);
|
|
2535
|
-
}
|
|
2536
|
-
function be() {
|
|
2537
|
-
const t = /* @__PURE__ */ new Set();
|
|
2538
|
-
return (e) => {
|
|
2539
|
-
const r = y(e).toLocaleLowerCase("tr-TR");
|
|
2540
|
-
return !r || t.has(r) ? !1 : (t.add(r), !0);
|
|
2541
|
-
};
|
|
2542
|
-
}
|
|
2543
|
-
function Ln(t, e) {
|
|
2544
|
-
return Ft(t).slice(0, e);
|
|
2545
|
-
}
|
|
2546
|
-
function qn(t, e) {
|
|
2547
|
-
return ct(t).slice(0, e);
|
|
2548
|
-
}
|
|
2549
|
-
function Dn(t, e) {
|
|
2550
|
-
return Bt(t).slice(0, e);
|
|
2551
|
-
}
|
|
2552
|
-
function Un(t, e) {
|
|
2553
|
-
return $t(t).slice(0, e);
|
|
2554
|
-
}
|
|
2555
|
-
function zn(t, e) {
|
|
2556
|
-
return Nt(t).slice(0, e);
|
|
2557
|
-
}
|
|
2558
|
-
function Gt(t) {
|
|
2559
|
-
return !t || typeof t != "object" ? null : z({
|
|
2560
|
-
sku: k(t.sku || t.id || ""),
|
|
2561
|
-
group_id: k(t.group_id || t.groupId || ""),
|
|
2562
|
-
name: y(t.name || t.title || ""),
|
|
2563
|
-
brand: y(t.brand || ""),
|
|
2564
|
-
url: X(t.url),
|
|
2565
|
-
images: j(t.images || t.image, 8, 280),
|
|
2566
|
-
price: x(t.price),
|
|
2567
|
-
price_discounted: x(t.price_discounted || t.discountedPrice),
|
|
2568
|
-
price_text: y(t.price_text || t.priceText || ""),
|
|
2569
|
-
price_currency: y(t.price_currency || t.currency || ""),
|
|
2570
|
-
category_ids: Hn(t.category_ids || t.categoryIds, 8, 90),
|
|
2571
|
-
category_names: j(t.category_names || t.categoryNames || t.category, 8, 140),
|
|
2572
|
-
in_stock: t.in_stock
|
|
2573
|
-
});
|
|
2574
|
-
}
|
|
2575
|
-
function Vn(t) {
|
|
2576
|
-
return [
|
|
2577
|
-
t.description ? "description" : "",
|
|
2578
|
-
t.features?.length ? "features" : "",
|
|
2579
|
-
t.sellers?.length ? "seller" : "",
|
|
2580
|
-
t.reviews?.length || t.rating || t.review_count ? "reviews_ratings" : "",
|
|
2581
|
-
t.qna?.length ? "qna" : "",
|
|
2582
|
-
t.payment?.length ? "installment_payment" : "",
|
|
2583
|
-
t.delivery?.length ? "shipping_delivery_stock" : "",
|
|
2584
|
-
t.promotions?.length ? "campaigns_promotions" : "",
|
|
2585
|
-
t.variants?.length ? "variants" : "",
|
|
2586
|
-
t.documents?.length ? "documents" : "",
|
|
2587
|
-
t.relatedProducts?.length ? "related_products" : ""
|
|
2588
|
-
].filter(Boolean);
|
|
2589
|
-
}
|
|
2590
|
-
function Kn(t) {
|
|
2591
|
-
return [y(t.key || t.name), y(t.value || t.text)];
|
|
2592
|
-
}
|
|
2593
|
-
function ke(...t) {
|
|
2594
|
-
return t.map((e) => h(e, 700)).find(Boolean) || "";
|
|
2595
|
-
}
|
|
2596
|
-
function h(t, e) {
|
|
2597
|
-
return y(t).slice(0, e);
|
|
2598
|
-
}
|
|
2599
|
-
function _e(t) {
|
|
2600
|
-
return y(t.getAttribute?.("aria-label") || t.getAttribute?.("title") || t.getAttribute?.("alt") || t.textContent);
|
|
2601
|
-
}
|
|
2602
|
-
function y(t) {
|
|
2603
|
-
return String(t ?? "").replace(/<script\b[\s\S]*?<\/script>/giu, " ").replace(/<style\b[\s\S]*?<\/style>/giu, " ").replace(/<[^>]+>/gu, " ").replace(kn, "[redacted]").replace(/\s+/gu, " ").trim();
|
|
2604
|
-
}
|
|
2605
|
-
function k(t) {
|
|
2606
|
-
const e = String(t ?? "").replace(/<script\b[\s\S]*?<\/script>/giu, " ").replace(/<style\b[\s\S]*?<\/style>/giu, " ").replace(/<[^>]+>/gu, " ").replace(/\s+/gu, " ").trim();
|
|
2607
|
-
return !e || /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/iu.test(e) || /\b(?:token|session|csrf|secret|password|passwd|jwt|bearer)\s*[:=]\s*[\w.-]+/iu.test(e) ? "" : e.slice(0, 120);
|
|
2608
|
-
}
|
|
2609
|
-
function Hn(t, e, r) {
|
|
2610
|
-
return (Array.isArray(t) ? t : t ? [t] : []).map((n) => k(n).slice(0, r)).filter(Boolean).filter(Jn()).slice(0, e);
|
|
2611
|
-
}
|
|
2612
|
-
function Jn() {
|
|
2613
|
-
const t = /* @__PURE__ */ new Set();
|
|
2614
|
-
return (e) => {
|
|
2615
|
-
const r = k(e).toLocaleLowerCase("tr-TR");
|
|
2616
|
-
return !r || t.has(r) ? !1 : (t.add(r), !0);
|
|
2617
|
-
};
|
|
2618
|
-
}
|
|
2619
|
-
function x(t) {
|
|
2620
|
-
const e = Number(String(t ?? "").replace(",", "."));
|
|
2621
|
-
return Number.isFinite(e) && e > 0 ? e : void 0;
|
|
2622
|
-
}
|
|
2623
|
-
function X(t) {
|
|
2624
|
-
if (!t) return "";
|
|
2625
|
-
try {
|
|
2626
|
-
const e = new URL(t, window.location.href);
|
|
2627
|
-
return /^https?:$/u.test(e.protocol) ? (e.hash = "", Ae(e), e.href) : "";
|
|
2628
|
-
} catch {
|
|
2629
|
-
return "";
|
|
2630
|
-
}
|
|
2631
|
-
}
|
|
2632
|
-
function Zn() {
|
|
2633
|
-
try {
|
|
2634
|
-
const t = new URL(window.location.href);
|
|
2635
|
-
return t.hash = "", Ae(t), `${t.origin}${t.pathname}${t.search}`;
|
|
2636
|
-
} catch {
|
|
2637
|
-
return "";
|
|
2638
|
-
}
|
|
2639
|
-
}
|
|
2640
|
-
function Ae(t) {
|
|
2641
|
-
for (const [e, r] of [...t.searchParams.entries()]) {
|
|
2642
|
-
const n = String(r || "");
|
|
2643
|
-
(_n.test(e) || An.test(n)) && t.searchParams.set(e, "redacted");
|
|
2644
|
-
}
|
|
2645
|
-
return t;
|
|
2646
|
-
}
|
|
2647
|
-
function Wn(t = {}) {
|
|
2648
|
-
return {
|
|
2649
|
-
features: E(t.maxFeatures, A.features, 40),
|
|
2650
|
-
reviews: E(t.maxReviews, A.reviews, 12),
|
|
2651
|
-
qna: E(t.maxQna, A.qna, 12),
|
|
2652
|
-
sellers: E(t.maxSellers, A.sellers, 12),
|
|
2653
|
-
variants: E(t.maxVariants, A.variants, 30),
|
|
2654
|
-
documents: E(t.maxDocuments, A.documents, 12),
|
|
2655
|
-
textBlocks: E(t.maxTextBlocks, A.textBlocks, 16),
|
|
2656
|
-
relatedProducts: E(t.maxRelatedProducts, A.relatedProducts, 20),
|
|
2657
|
-
textChars: E(t.textChars, A.textChars, 420)
|
|
2658
|
-
};
|
|
2659
|
-
}
|
|
2660
|
-
function E(t, e, r) {
|
|
2661
|
-
const n = Number(t);
|
|
2662
|
-
return !Number.isFinite(n) || n <= 0 ? e : Math.min(Math.floor(n), r);
|
|
2663
|
-
}
|
|
2664
|
-
function bt(t) {
|
|
2665
|
-
try {
|
|
2666
|
-
return typeof t == "function" ? t() : null;
|
|
2667
|
-
} catch {
|
|
2668
|
-
return null;
|
|
2669
|
-
}
|
|
2670
|
-
}
|
|
2671
|
-
function z(t) {
|
|
2672
|
-
return Object.fromEntries(Object.entries(t || {}).filter(([, e]) => e != null && e !== "" && (!Array.isArray(e) || e.length)));
|
|
2673
|
-
}
|
|
2674
|
-
var { redactPii: Yo, anonymousRequestText: Qo, anonymizeMessages: Xo } = bn({ patterns: [{
|
|
2675
|
-
pattern: /\b\d{5}\b/gu,
|
|
2676
|
-
replacement: "[postcode]"
|
|
2677
|
-
}, {
|
|
2678
|
-
pattern: /\b(?:adresim|adres|mahalle|sokak|cadde)\b[^,.!?\n]{8,160}/giu,
|
|
2679
|
-
replacement: "[address]"
|
|
2680
|
-
}] });
|
|
2681
|
-
function Gn(t) {
|
|
2682
|
-
return (t?.route?.flow_params && typeof t.route.flow_params == "object" ? t.route.flow_params : null) || (t?.route?.flowParams && typeof t.route.flowParams == "object" ? t.route.flowParams : null) || {};
|
|
2683
|
-
}
|
|
2684
|
-
function ti(t) {
|
|
2685
|
-
return Array.isArray(t) ? t.find((e) => String(e || "").trim()) : void 0;
|
|
2686
|
-
}
|
|
2687
|
-
function ei(t) {
|
|
2688
|
-
const e = Gn(t);
|
|
2689
|
-
return [
|
|
2690
|
-
...e.sku ? [e.sku] : [],
|
|
2691
|
-
...Array.isArray(e.sku_list) ? e.sku_list : [],
|
|
2692
|
-
...Array.isArray(e.skus) ? e.skus : [],
|
|
2693
|
-
...Array.isArray(e.target_skus) ? e.target_skus : []
|
|
2694
|
-
].map((r) => String(r || "").trim()).filter(Boolean).filter((r, n, o) => o.indexOf(r) === n);
|
|
2695
|
-
}
|
|
2696
|
-
var Yn = 3e4;
|
|
2697
|
-
function Qn(t, e, r = {}) {
|
|
2698
|
-
const n = r.ttlMs ?? Yn, o = r.clock ?? Date.now, i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
|
|
2699
|
-
return async function(c) {
|
|
2700
|
-
const u = String(e(c) ?? "");
|
|
2701
|
-
if (!u) return t(c);
|
|
2702
|
-
const l = o();
|
|
2703
|
-
Xn(a, l, n);
|
|
2704
|
-
const f = i.get(u);
|
|
2705
|
-
if (f) return f;
|
|
2706
|
-
const d = a.get(u);
|
|
2707
|
-
if (d && l - d.at < n) return to(d.observation, u);
|
|
2708
|
-
const p = (async () => {
|
|
2709
|
-
try {
|
|
2710
|
-
const m = await t(c);
|
|
2711
|
-
return a.set(u, {
|
|
2712
|
-
at: o(),
|
|
2713
|
-
observation: m
|
|
2714
|
-
}), m;
|
|
2715
|
-
} finally {
|
|
2716
|
-
i.delete(u);
|
|
2717
|
-
}
|
|
2718
|
-
})();
|
|
2719
|
-
return i.set(u, p), p;
|
|
2720
|
-
};
|
|
2721
|
-
}
|
|
2722
|
-
function Xn(t, e, r) {
|
|
2723
|
-
for (const [n, o] of t) e - o.at >= r && t.delete(n);
|
|
2724
|
-
}
|
|
2725
|
-
function to(t, e) {
|
|
2726
|
-
return !t || typeof t != "object" ? t : {
|
|
2727
|
-
...t,
|
|
2728
|
-
deduped: !0,
|
|
2729
|
-
dedupe_key: e
|
|
2730
|
-
};
|
|
2731
|
-
}
|
|
2732
|
-
var eo = 3e4, Se = /* @__PURE__ */ new Set();
|
|
2733
|
-
function ri(t) {
|
|
2734
|
-
const e = () => Qn(async (o) => t(o || {}), (o) => {
|
|
2735
|
-
const i = ro(o), a = Number(o?.quantity || o?.qty || 1) || 1, s = no(o);
|
|
2736
|
-
return i ? `${i}|${a}|${s}` : "";
|
|
2737
|
-
}, { ttlMs: eo });
|
|
2738
|
-
let r = e();
|
|
2739
|
-
const n = async function(i = {}) {
|
|
2740
|
-
return r(i);
|
|
2741
|
-
};
|
|
2742
|
-
return n.__resetForTesting = () => {
|
|
2743
|
-
r = e();
|
|
2744
|
-
}, Se.add(n), n;
|
|
2745
|
-
}
|
|
2746
|
-
function ni() {
|
|
2747
|
-
for (const t of Se) typeof t.__resetForTesting == "function" && t.__resetForTesting();
|
|
2748
|
-
}
|
|
2749
|
-
function ro(t) {
|
|
2750
|
-
const e = t?.cartCode ?? t?.sku ?? t?.productCode ?? t?.product?.sku ?? t?.product?.cart_code;
|
|
2751
|
-
return e == null ? "" : String(e).trim();
|
|
2752
|
-
}
|
|
2753
|
-
function no(t) {
|
|
2754
|
-
const e = t?.variantId ?? t?.variantCode ?? t?.product?.variantId ?? "";
|
|
2755
|
-
return e == null ? "" : String(e).trim();
|
|
2756
|
-
}
|
|
2757
|
-
var oo = 32, xe = /* @__PURE__ */ new Set();
|
|
2758
|
-
function oi(t, e) {
|
|
2759
|
-
const { accountId: r, allowedHostnames: n, productFromPage: o, mergeProduct: i = ao, needsHydration: a = io, fetchOptions: s = { credentials: "include" }, maxConcurrency: c = 4 } = e;
|
|
2760
|
-
if (!r) throw new Error("wrapResolveProductsWithPdpHydration: accountId is required");
|
|
2761
|
-
if (typeof o != "function") throw new Error("wrapResolveProductsWithPdpHydration: productFromPage(doc, url) is required");
|
|
2762
|
-
if (!Array.isArray(n) || !n.length) throw new Error("wrapResolveProductsWithPdpHydration: allowedHostnames must be a non-empty array");
|
|
2763
|
-
const u = /* @__PURE__ */ new Map(), l = uo({
|
|
2764
|
-
productFromPage: o,
|
|
2765
|
-
fetchOptions: s,
|
|
2766
|
-
isAllowed: so(n)
|
|
2767
|
-
}), f = async function(p = {}) {
|
|
2768
|
-
const m = await t(p || {});
|
|
2769
|
-
if (p?.hydrateFromPdp === !1) return m;
|
|
2770
|
-
const g = Array.isArray(m?.products) ? m.products : [];
|
|
2771
|
-
if (!g.length) return m;
|
|
2772
|
-
const S = await lo(g, l, u, c, i, a);
|
|
2773
|
-
return {
|
|
2774
|
-
...m,
|
|
2775
|
-
products: S
|
|
2776
|
-
};
|
|
2777
|
-
};
|
|
2778
|
-
return f.__resetCacheForTesting = () => u.clear(), f.__cacheSizeForTesting = () => u.size, xe.add(f), f;
|
|
2779
|
-
}
|
|
2780
|
-
function ii() {
|
|
2781
|
-
for (const t of xe) typeof t.__resetCacheForTesting == "function" && t.__resetCacheForTesting();
|
|
2782
|
-
}
|
|
2783
|
-
function io(t) {
|
|
2784
|
-
if (!t || !t.url) return !1;
|
|
2785
|
-
const e = t, r = e.features, n = e.specs, o = e.category_names, i = Array.isArray(r) && r.length > 0, a = !!n && typeof n == "object" && Object.keys(n).length > 0, s = Array.isArray(o) && o.length > 0;
|
|
2786
|
-
return !i && !a && !s;
|
|
2787
|
-
}
|
|
2788
|
-
function ao(t, e) {
|
|
2789
|
-
return t ? e ? {
|
|
2790
|
-
...t,
|
|
2791
|
-
...e
|
|
2792
|
-
} : t : e;
|
|
2793
|
-
}
|
|
2794
|
-
function so(t) {
|
|
2795
|
-
const e = t.map((r) => String(r || "").toLowerCase().trim()).filter(Boolean);
|
|
2796
|
-
return (r) => {
|
|
2797
|
-
const n = String(r || "").toLowerCase();
|
|
2798
|
-
if (!n) return !1;
|
|
2799
|
-
for (const o of e)
|
|
2800
|
-
if (n === o || n.endsWith(`.${o}`)) return !0;
|
|
2801
|
-
return !1;
|
|
2802
|
-
};
|
|
2803
|
-
}
|
|
2804
|
-
function co(t, e) {
|
|
2805
|
-
if (!t) return null;
|
|
2806
|
-
try {
|
|
2807
|
-
const r = new URL(String(t));
|
|
2808
|
-
return r.protocol !== "https:" || !e(r.hostname) ? null : r.href;
|
|
2809
|
-
} catch {
|
|
2810
|
-
return null;
|
|
2811
|
-
}
|
|
2812
|
-
}
|
|
2813
|
-
function uo(t) {
|
|
2814
|
-
const { productFromPage: e, fetchOptions: r, isAllowed: n } = t;
|
|
2815
|
-
return async function(i) {
|
|
2816
|
-
const a = co(i?.url, n);
|
|
2817
|
-
if (!a || typeof fetch != "function") return null;
|
|
2818
|
-
let s;
|
|
2819
|
-
try {
|
|
2820
|
-
const u = await fetch(a, r);
|
|
2821
|
-
if (!u?.ok) return null;
|
|
2822
|
-
s = await u.text();
|
|
2823
|
-
} catch {
|
|
2824
|
-
return null;
|
|
2825
|
-
}
|
|
2826
|
-
if (!s || typeof DOMParser > "u") return null;
|
|
2827
|
-
let c;
|
|
2828
|
-
try {
|
|
2829
|
-
c = new DOMParser().parseFromString(s, "text/html");
|
|
2830
|
-
} catch {
|
|
2831
|
-
return null;
|
|
2832
|
-
}
|
|
2833
|
-
if (!c) return null;
|
|
2834
|
-
try {
|
|
2835
|
-
return e(c, a) || null;
|
|
2836
|
-
} catch {
|
|
2837
|
-
return null;
|
|
2838
|
-
}
|
|
2839
|
-
};
|
|
2840
|
-
}
|
|
2841
|
-
async function lo(t, e, r, n, o, i) {
|
|
2842
|
-
const a = new Array(t.length);
|
|
2843
|
-
let s = 0;
|
|
2844
|
-
const c = Math.max(1, Math.min(n, t.length)), u = new Array(c).fill(null).map(() => l());
|
|
2845
|
-
return await Promise.all(u), a;
|
|
2846
|
-
async function l() {
|
|
2847
|
-
for (; ; ) {
|
|
2848
|
-
const d = s++;
|
|
2849
|
-
if (d >= t.length) return;
|
|
2850
|
-
a[d] = await f(t[d]);
|
|
2851
|
-
}
|
|
2852
|
-
}
|
|
2853
|
-
async function f(d) {
|
|
2854
|
-
if (!d || !i(d)) return d;
|
|
2855
|
-
const p = d?.sku == null ? "" : String(d.sku).trim();
|
|
2856
|
-
if (p && r.has(p)) {
|
|
2857
|
-
const g = r.get(p);
|
|
2858
|
-
return g ? o(d, g) : d;
|
|
2859
|
-
}
|
|
2860
|
-
const m = await e(d);
|
|
2861
|
-
return p && (r.set(p, m || null), fo(r)), m ? o(d, m) : d;
|
|
2862
|
-
}
|
|
2863
|
-
}
|
|
2864
|
-
function fo(t) {
|
|
2865
|
-
for (; t.size > oo; ) {
|
|
2866
|
-
const e = t.keys().next().value;
|
|
2867
|
-
if (e === void 0) break;
|
|
2868
|
-
t.delete(e);
|
|
2869
|
-
}
|
|
2870
|
-
}
|
|
2871
|
-
var po = 20;
|
|
2872
|
-
function mo(t, e = {}) {
|
|
2873
|
-
const { context: r, accountConfig: n } = e, o = Array.isArray(t) ? t.filter(Boolean) : [];
|
|
2874
|
-
if (!o.length) return [];
|
|
2875
|
-
const i = String(r?.meta?.locale || n?.locale || n?.defaultLocale || "tr-TR").toLowerCase().startsWith("en"), a = i ? "Compare the first two" : "İlk ikisini karşılaştır", s = i ? "Open product page" : "Ürün sayfasını aç", c = i ? "Tell me the comfort details" : "Konfor özelliklerini anlat", u = i ? "Show similar" : "Benzerlerini göster", l = [];
|
|
2876
|
-
o.length >= 2 && l.push({
|
|
2877
|
-
label: a,
|
|
2878
|
-
action: {
|
|
2879
|
-
type: "getComparisonTable",
|
|
2880
|
-
payload: {
|
|
2881
|
-
skus: o.slice(0, 2).map((d) => d.sku).filter(Boolean),
|
|
2882
|
-
limit: 2
|
|
2883
|
-
}
|
|
2884
|
-
}
|
|
2885
|
-
});
|
|
2886
|
-
const f = o[0]?.sku;
|
|
2887
|
-
return f && !i && (l.push({
|
|
2888
|
-
label: s,
|
|
2889
|
-
action: {
|
|
2890
|
-
type: "openProductPage",
|
|
2891
|
-
payload: {
|
|
2892
|
-
sku: f,
|
|
2893
|
-
url: o[0]?.url
|
|
2894
|
-
}
|
|
2895
|
-
}
|
|
2896
|
-
}), l.push({
|
|
2897
|
-
label: c,
|
|
2898
|
-
action: {
|
|
2899
|
-
type: "productQuestion",
|
|
2900
|
-
payload: { sku_list: [f] }
|
|
2901
|
-
}
|
|
2902
|
-
})), l.push({
|
|
2903
|
-
label: u,
|
|
2904
|
-
action: {
|
|
2905
|
-
type: "findSimilar",
|
|
2906
|
-
payload: { sku: f }
|
|
2907
|
-
}
|
|
2908
|
-
}), l;
|
|
2909
|
-
}
|
|
2910
|
-
function Yt(t, e = po) {
|
|
2911
|
-
const r = [];
|
|
2912
|
-
if (!Array.isArray(t)) return [];
|
|
2913
|
-
for (const a of t) {
|
|
2914
|
-
const s = Array.isArray(a?.observation?.products) ? a.observation.products : [];
|
|
2915
|
-
s.length && r.push([...s]);
|
|
2916
|
-
}
|
|
2917
|
-
if (r.length <= 1) return (r[0] || []).slice(0, e);
|
|
2918
|
-
const n = [], o = /* @__PURE__ */ new Set();
|
|
2919
|
-
let i = 0;
|
|
2920
|
-
for (; n.length < e; ) {
|
|
2921
|
-
let a = !1;
|
|
2922
|
-
for (const s of r) {
|
|
2923
|
-
const c = s[i];
|
|
2924
|
-
if (!c) continue;
|
|
2925
|
-
const u = String(c.sku || c.url || c.name || "");
|
|
2926
|
-
if (u && o.has(u)) {
|
|
2927
|
-
a = !0;
|
|
2928
|
-
continue;
|
|
2929
|
-
}
|
|
2930
|
-
if (u && o.add(u), n.push(c), a = !0, n.length >= e) break;
|
|
2931
|
-
}
|
|
2932
|
-
if (!a) break;
|
|
2933
|
-
i += 1;
|
|
2934
|
-
}
|
|
2935
|
-
return n;
|
|
2936
|
-
}
|
|
2937
|
-
function ai(t) {
|
|
2938
|
-
if (!t?.spec?.elements) return t;
|
|
2939
|
-
const e = t.spec.root;
|
|
2940
|
-
if (!e) return t;
|
|
2941
|
-
const r = t.spec.elements[e];
|
|
2942
|
-
return !r || r.type !== "ProductGrid" ? (typeof console < "u" && console.warn && console.warn("[agentic] withSimilarsAppend: products envelope root is not ProductGrid", r?.type), t) : {
|
|
2943
|
-
...t,
|
|
2944
|
-
spec: {
|
|
2945
|
-
...t.spec,
|
|
2946
|
-
elements: {
|
|
2947
|
-
...t.spec.elements,
|
|
2948
|
-
[e]: {
|
|
2949
|
-
...r,
|
|
2950
|
-
props: {
|
|
2951
|
-
...r.props || {},
|
|
2952
|
-
similarsAppend: !0
|
|
2953
|
-
}
|
|
2954
|
-
}
|
|
2955
|
-
}
|
|
2956
|
-
}
|
|
2957
|
-
};
|
|
2958
|
-
}
|
|
2959
|
-
function si(t, e = {}) {
|
|
2960
|
-
const r = e.threshold ?? 0;
|
|
2961
|
-
return !r || r <= 0 || !Array.isArray(t) ? !1 : t.length > r;
|
|
2962
|
-
}
|
|
2963
|
-
function ci(t, e = {}) {
|
|
2964
|
-
const r = Math.max(0, e.retainTail ?? 4);
|
|
2965
|
-
if (!Array.isArray(t) || t.length === 0 || t.length <= r) return null;
|
|
2966
|
-
const n = t.slice(t.length - r), o = t.slice(0, t.length - r);
|
|
2967
|
-
return o.length ? {
|
|
2968
|
-
messagesToSummarize: o,
|
|
2969
|
-
retainedTail: n
|
|
2970
|
-
} : null;
|
|
2971
|
-
}
|
|
2972
|
-
function ui(t, e, r = {}) {
|
|
2973
|
-
const n = String(e || "").trim();
|
|
2974
|
-
if (!n) return t;
|
|
2975
|
-
const o = Math.max(0, r.retainTail ?? 4), i = Array.isArray(t.messages) ? t.messages : [], a = i.slice(Math.max(0, i.length - o));
|
|
2976
|
-
return {
|
|
2977
|
-
...t,
|
|
2978
|
-
messages: [{
|
|
2979
|
-
role: "assistant",
|
|
2980
|
-
content: n,
|
|
2981
|
-
name: "compaction"
|
|
2982
|
-
}, ...a],
|
|
2983
|
-
panel: {
|
|
2984
|
-
...t.panel || {},
|
|
2985
|
-
compaction_summary: {
|
|
2986
|
-
summary: n,
|
|
2987
|
-
replacedCount: i.length - a.length,
|
|
2988
|
-
retainedTailCount: a.length,
|
|
2989
|
-
compactedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2990
|
-
}
|
|
2991
|
-
}
|
|
2992
|
-
};
|
|
2993
|
-
}
|
|
2994
|
-
function P(t, e) {
|
|
2995
|
-
const r = t?.[e];
|
|
2996
|
-
return Array.isArray(r) ? r : [];
|
|
2997
|
-
}
|
|
2998
|
-
function H(t, e, r = !1) {
|
|
2999
|
-
return [...t].reverse().find((n) => n?.name === e && (!r || n?.observation?.status === "ok"));
|
|
3000
|
-
}
|
|
3001
|
-
function yo(t) {
|
|
3002
|
-
return {
|
|
3003
|
-
kind: "patch",
|
|
3004
|
-
patch: (e, r, n) => {
|
|
3005
|
-
const o = H(P(n.bag, t), "search_catalog"), i = Array.isArray(o?.observation?.products) ? o.observation.products : null;
|
|
3006
|
-
return i?.length ? { panel: {
|
|
3007
|
-
...e.panel,
|
|
3008
|
-
screen_type: "product_list",
|
|
3009
|
-
list_source: "agent",
|
|
3010
|
-
last_search_products: i,
|
|
3011
|
-
last_search: {
|
|
3012
|
-
query: o.observation.query,
|
|
3013
|
-
source: o.observation.source,
|
|
3014
|
-
count: o.observation.count
|
|
3015
|
-
},
|
|
3016
|
-
screen_sku_list: i.map((a) => a?.sku).filter(Boolean).slice(0, 24)
|
|
3017
|
-
} } : null;
|
|
3018
|
-
}
|
|
3019
|
-
};
|
|
3020
|
-
}
|
|
3021
|
-
function li(t) {
|
|
3022
|
-
const e = t.obsKey || "roundObservations", r = t.gridLimit ?? 20, n = t.similarsFollowupSteps ? t.similarsFollowupSteps() : [];
|
|
3023
|
-
return [
|
|
3024
|
-
yo(e),
|
|
3025
|
-
{
|
|
3026
|
-
kind: "branch",
|
|
3027
|
-
on: ({ bag: o }) => P(o, e).some((i) => Array.isArray(i?.observation?.products) && i.observation.products.length) ? "has_products" : "no_products",
|
|
3028
|
-
cases: {
|
|
3029
|
-
has_products: [{
|
|
3030
|
-
kind: "emit",
|
|
3031
|
-
build: ({ bag: o }) => {
|
|
3032
|
-
const i = Yt(P(o, e), r);
|
|
3033
|
-
return t.uiSpec(t.productsUiSpec(i));
|
|
3034
|
-
}
|
|
3035
|
-
}, {
|
|
3036
|
-
kind: "emit",
|
|
3037
|
-
build: ({ bag: o, context: i, accountConfig: a }) => {
|
|
3038
|
-
const s = Yt(P(o, e), r);
|
|
3039
|
-
return t.uiSpec(t.actionButtonsUiSpec(mo(s, {
|
|
3040
|
-
context: i,
|
|
3041
|
-
accountConfig: a
|
|
3042
|
-
})));
|
|
3043
|
-
}
|
|
3044
|
-
}],
|
|
3045
|
-
no_products: []
|
|
3046
|
-
}
|
|
3047
|
-
},
|
|
3048
|
-
{
|
|
3049
|
-
kind: "branch",
|
|
3050
|
-
on: ({ bag: o }) => H(P(o, e), "compare_products", !0) ? "has_compare" : "no_compare",
|
|
3051
|
-
cases: {
|
|
3052
|
-
has_compare: [{
|
|
3053
|
-
kind: "emit",
|
|
3054
|
-
build: ({ context: o, bag: i }) => {
|
|
3055
|
-
const a = H(P(i, e), "compare_products"), s = a?.observation || {}, c = a?.arguments || {}, u = Array.isArray(c.target_skus) ? c.target_skus.map(String) : [], l = Array.isArray(o?.panel?.last_search_products) ? o.panel.last_search_products : [], f = u.length ? u.map((d) => l.find((p) => String(p?.sku) === d)).filter(Boolean) : l.slice(0, 4);
|
|
3056
|
-
return t.uiSpec(t.comparisonUiSpec({
|
|
3057
|
-
products: f,
|
|
3058
|
-
comparison_table: s.comparison_table,
|
|
3059
|
-
key_differences: s.key_differences,
|
|
3060
|
-
recommended_choice_sku: s.recommendation?.sku,
|
|
3061
|
-
recommended_choice: s.recommendation?.reason
|
|
3062
|
-
}));
|
|
3063
|
-
}
|
|
3064
|
-
}],
|
|
3065
|
-
no_compare: []
|
|
3066
|
-
}
|
|
3067
|
-
},
|
|
3068
|
-
{
|
|
3069
|
-
kind: "branch",
|
|
3070
|
-
on: ({ bag: o }) => H(P(o, e), "get_product_details", !0) ? "has_details" : "no_details",
|
|
3071
|
-
cases: {
|
|
3072
|
-
has_details: [{
|
|
3073
|
-
kind: "emit",
|
|
3074
|
-
build: ({ context: o, bag: i }) => {
|
|
3075
|
-
const a = H(P(i, e), "get_product_details"), s = a?.observation?.surface || {}, c = a?.arguments || {}, u = Array.isArray(o?.panel?.last_search_products) ? o.panel.last_search_products : [], l = c.sku ? u.find((d) => String(d?.sku) === String(c.sku)) : null, f = s.product || l || s || {};
|
|
3076
|
-
return t.uiSpec(t.productDetailsUiSpec(f));
|
|
3077
|
-
}
|
|
3078
|
-
}, ...n],
|
|
3079
|
-
no_details: []
|
|
3080
|
-
}
|
|
3081
|
-
},
|
|
3082
|
-
...go({
|
|
3083
|
-
...t,
|
|
3084
|
-
obsKey: e
|
|
3085
|
-
})
|
|
3086
|
-
];
|
|
3087
|
-
}
|
|
3088
|
-
function go(t) {
|
|
3089
|
-
const e = t.obsKey || "roundObservations", r = t.pdpFollowupProduct;
|
|
3090
|
-
return r ? [{
|
|
3091
|
-
kind: "branch",
|
|
3092
|
-
on: ({ bag: n, context: o }) => n.pdpFollowupRendered || P(n, e).some((i) => {
|
|
3093
|
-
const a = i?.name;
|
|
3094
|
-
return a === "search_catalog" || a === "compare_products" || a === "get_product_details" || Array.isArray(i?.observation?.products) && i.observation.products.length;
|
|
3095
|
-
}) ? "skip" : r(n, o) ? "render" : "skip",
|
|
3096
|
-
cases: {
|
|
3097
|
-
render: [
|
|
3098
|
-
{
|
|
3099
|
-
kind: "emit",
|
|
3100
|
-
build: ({ bag: n, context: o }) => t.uiSpec(t.productDetailsUiSpec(r(n, o)))
|
|
3101
|
-
},
|
|
3102
|
-
{
|
|
3103
|
-
kind: "patch",
|
|
3104
|
-
patch: (n, o, i) => (i.bag.pdpFollowupRendered = !0, null)
|
|
3105
|
-
},
|
|
3106
|
-
...t.similarsFollowupSteps ? t.similarsFollowupSteps() : []
|
|
3107
|
-
],
|
|
3108
|
-
skip: []
|
|
3109
|
-
}
|
|
3110
|
-
}] : [];
|
|
3111
|
-
}
|
|
3112
|
-
export {
|
|
3113
|
-
Io as $,
|
|
3114
|
-
Do as A,
|
|
3115
|
-
We as At,
|
|
3116
|
-
fe as B,
|
|
3117
|
-
Wo as C,
|
|
3118
|
-
ko as Ct,
|
|
3119
|
-
Ho as D,
|
|
3120
|
-
wo as Dt,
|
|
3121
|
-
Jo as E,
|
|
3122
|
-
Ge as Et,
|
|
3123
|
-
qo as F,
|
|
3124
|
-
$o as G,
|
|
3125
|
-
cn as H,
|
|
3126
|
-
pn as I,
|
|
3127
|
-
on as J,
|
|
3128
|
-
Bo as K,
|
|
3129
|
-
Lo as L,
|
|
3130
|
-
zo as M,
|
|
3131
|
-
Pe as Mt,
|
|
3132
|
-
hn as N,
|
|
3133
|
-
Ko as O,
|
|
3134
|
-
Ne as Ot,
|
|
3135
|
-
gn as P,
|
|
3136
|
-
Oo as Q,
|
|
3137
|
-
un as R,
|
|
3138
|
-
Sn as S,
|
|
3139
|
-
lr as St,
|
|
3140
|
-
bn as T,
|
|
3141
|
-
I as Tt,
|
|
3142
|
-
Fo as U,
|
|
3143
|
-
pe as V,
|
|
3144
|
-
No as W,
|
|
3145
|
-
le as X,
|
|
3146
|
-
Mo as Y,
|
|
3147
|
-
jo as Z,
|
|
3148
|
-
Xo as _,
|
|
3149
|
-
v as _t,
|
|
3150
|
-
si as a,
|
|
3151
|
-
Po as at,
|
|
3152
|
-
xn as b,
|
|
3153
|
-
yr as bt,
|
|
3154
|
-
ai as c,
|
|
3155
|
-
Co as ct,
|
|
3156
|
-
ni as d,
|
|
3157
|
-
re as dt,
|
|
3158
|
-
Er as et,
|
|
3159
|
-
ri as f,
|
|
3160
|
-
Ar as ft,
|
|
3161
|
-
ei as g,
|
|
3162
|
-
Ao as gt,
|
|
3163
|
-
Gn as h,
|
|
3164
|
-
xo as ht,
|
|
3165
|
-
ci as i,
|
|
3166
|
-
ie as it,
|
|
3167
|
-
Uo as j,
|
|
3168
|
-
Ee as jt,
|
|
3169
|
-
Vo as k,
|
|
3170
|
-
bo as kt,
|
|
3171
|
-
ii as l,
|
|
3172
|
-
Sr as lt,
|
|
3173
|
-
ti as m,
|
|
3174
|
-
_r as mt,
|
|
3175
|
-
li as n,
|
|
3176
|
-
Eo as nt,
|
|
3177
|
-
Yt as o,
|
|
3178
|
-
Pt as ot,
|
|
3179
|
-
Qn as p,
|
|
3180
|
-
So as pt,
|
|
3181
|
-
Ro as q,
|
|
3182
|
-
ui as r,
|
|
3183
|
-
To as rt,
|
|
3184
|
-
mo as s,
|
|
3185
|
-
It as st,
|
|
3186
|
-
go as t,
|
|
3187
|
-
oe as tt,
|
|
3188
|
-
oi as u,
|
|
3189
|
-
vo as ut,
|
|
3190
|
-
Qo as v,
|
|
3191
|
-
ee as vt,
|
|
3192
|
-
Go as w,
|
|
3193
|
-
Xt as wt,
|
|
3194
|
-
Zo as x,
|
|
3195
|
-
fr as xt,
|
|
3196
|
-
Yo as y,
|
|
3197
|
-
_o as yt,
|
|
3198
|
-
de as z
|
|
3199
|
-
};
|