@gengage/assistant-fe 0.6.21 → 0.6.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +4 -2
  2. package/dist/agentic/adaptor/create-adaptor.d.ts +6 -3
  3. package/dist/agentic/adaptor/mount.d.ts +8 -2
  4. package/dist/agentic/{similarity.d.ts → algos/similarity.d.ts} +11 -2
  5. package/dist/agentic/algos/similarity.js +261 -0
  6. package/dist/agentic/context/chat-context.d.ts +4 -2
  7. package/dist/agentic/context/context-store.d.ts +11 -1
  8. package/dist/agentic/context/persistence.d.ts +1 -0
  9. package/dist/agentic/contracts/agentic-contracts.d.ts +133 -0
  10. package/dist/agentic/debug/activity-collector.d.ts +14 -0
  11. package/dist/agentic/debug/activity-instrumentation.d.ts +22 -0
  12. package/dist/agentic/debug/activity-overlay.d.ts +3 -0
  13. package/dist/agentic/debug/activity-state.d.ts +37 -0
  14. package/dist/agentic/debug/local-dev.d.ts +18 -0
  15. package/dist/agentic/events/product-normalize.d.ts +4 -1
  16. package/dist/agentic/events/ui-specs.d.ts +8 -4
  17. package/dist/agentic/index.d.ts +25 -2
  18. package/dist/agentic/index.js +2792 -441
  19. package/dist/agentic/types.d.ts +77 -4
  20. package/dist/agentic/util/common/declarative-cache.d.ts +21 -0
  21. package/dist/agentic/util/common/fallback-status.d.ts +10 -0
  22. package/dist/agentic/util/common/flow-steps.d.ts +8 -0
  23. package/dist/agentic/util/common/gss-tool-aliases.d.ts +66 -0
  24. package/dist/agentic/util/common/iframe-scraper.d.ts +22 -0
  25. package/dist/agentic/util/common/llm-routing.d.ts +50 -0
  26. package/dist/agentic/util/common/object.d.ts +1 -0
  27. package/dist/agentic/util/common/open-product-page.d.ts +30 -0
  28. package/dist/agentic/util/common/panel-context.d.ts +3 -0
  29. package/dist/agentic/util/common/privacy.d.ts +14 -0
  30. package/dist/agentic/util/common/product-resolver.d.ts +20 -0
  31. package/dist/agentic/util/common/product-surface.d.ts +24 -0
  32. package/dist/agentic/util/common/ref-store.d.ts +15 -0
  33. package/dist/agentic/util/common/retail-privacy.d.ts +4 -0
  34. package/dist/agentic/util/common/route-params.d.ts +3 -0
  35. package/dist/agentic/util/common/similarity-ranking.d.ts +2 -0
  36. package/dist/agentic/util/common/site-awareness.d.ts +130 -0
  37. package/dist/agentic/util/lazy-runtime-loader.d.ts +2 -1
  38. package/dist/agentic/worker/rpc.d.ts +26 -6
  39. package/dist/agentic/worker.d.ts +15 -2
  40. package/dist/agentic/worker.js +316 -119
  41. package/dist/agentic.iife.js +352 -6
  42. package/dist/{api-paths-DcKsQqb6.js → api-paths-BmN07ddR.js} +144 -154
  43. package/dist/chat/catalog.d.ts +8 -0
  44. package/dist/chat/types.d.ts +2 -1
  45. package/dist/{chat-rvSffJXw.js → chat-CIfQyuBl.js} +26 -21
  46. package/dist/chat-runtime.js +1 -1
  47. package/dist/chat.iife.js +44 -44
  48. package/dist/chat.js +2 -2
  49. package/dist/{common-MpBmMLVk.js → common-sx2gD-IP.js} +1 -1
  50. package/dist/common.js +5 -5
  51. package/dist/{connection-warning-ClrMLgmZ.js → connection-warning-D5T4gHSM.js} +1 -1
  52. package/dist/{fastIntent-Bl4xN0qL.js → fastIntent-BFAGybCb.js} +1 -1
  53. package/dist/index.js +10 -10
  54. package/dist/native.iife.js +17 -17
  55. package/dist/qna-runtime.js +1 -1
  56. package/dist/qna.iife.js +7 -7
  57. package/dist/qna.js +1 -1
  58. package/dist/route-params-5KSvTyeb.js +2454 -0
  59. package/dist/{runtime-CS4mg3ra.js → runtime-BD2fW-ed.js} +3 -3
  60. package/dist/{runtime-_koZbJK_.js → runtime-DM7DHhH9.js} +1816 -1778
  61. package/dist/{runtime-BlU1rKqc.js → runtime-DQ3ULuNF.js} +3 -3
  62. package/dist/{simbut-BtL7zYIJ.js → simbut-hkt_4H97.js} +1 -1
  63. package/dist/simbut.iife.js +1 -1
  64. package/dist/simbut.js +1 -1
  65. package/dist/{simrel-ekf3kUb_.js → simrel-BbkK5Bwt.js} +1 -1
  66. package/dist/simrel-runtime.js +1 -1
  67. package/dist/simrel.iife.js +6 -6
  68. package/dist/simrel.js +2 -2
  69. package/dist/{widget-base-p1EKDuiI.js → widget-base-BPKfPh0N.js} +1 -1
  70. package/package.json +5 -1
  71. package/dist/account-config-D_EMuR0g.js +0 -1479
package/README.md CHANGED
@@ -146,8 +146,8 @@ npm run catalog # Visual component catalog at :30
146
146
  npm run docs:build # Build contributor docs with VitePress
147
147
  ```
148
148
 
149
- This repo builds the SDK package only. Hosted account demos and exact client PDP/PLP clones live in
150
- `gengage-assistant-injector` and are deployed from that repository to gengage CDN location.
149
+ This repo builds the SDK package only. Hosted account demos and exact client PDP/PLP clones live
150
+ outside the SDK and should not be committed here.
151
151
 
152
152
  ---
153
153
 
@@ -157,6 +157,8 @@ This repo builds the SDK package only. Hosted account demos and exact client PDP
157
157
  |-----|-------------|
158
158
  | [Docs Index](docs/index.md) | Full documentation map |
159
159
  | [API Reference](docs/api-reference.md) | Public entry points and config surfaces |
160
+ | [Agentic Overview](docs/agentic-overview.md) | Agentic SDK architecture and compatibility rules |
161
+ | [Agentic Integration Guide](docs/agentic-integration-guide.md) | From-scratch browser-local agentic integration guide |
160
162
  | [Architecture](docs/architecture.md) | System design, widget lifecycle, data flows |
161
163
  | [Wire Protocol](docs/wire-protocol.md) | Backend NDJSON streaming contract |
162
164
  | [Customization](docs/customization.md) | CSS tokens, component overrides, XSS rules |
@@ -1,5 +1,6 @@
1
+ import { type MainRpcMemory } from '../worker/rpc.js';
1
2
  import type { InjectorAdapter } from '../../common/transport.js';
2
- import type { AccountModule, BeaconCallback, ToolMap } from '../types.js';
3
+ import type { AccountModule, BeaconCallback, ConfirmationCallback, ToolMap } from '../types.js';
3
4
  interface CreateInjectorAdapterArgs {
4
5
  accountId: string;
5
6
  worker: Worker;
@@ -10,10 +11,12 @@ interface CreateInjectorAdapterArgs {
10
11
  defaultLocale?: string | undefined;
11
12
  tools?: ToolMap | undefined;
12
13
  beacon?: BeaconCallback | undefined;
14
+ confirmation?: ConfirmationCallback | undefined;
15
+ memory?: MainRpcMemory | undefined;
13
16
  }
14
- export declare function createInjectorAdapter({ accountId, worker, beUrl, devJwtSecret, tokenBrokerUrl, tokenBrokerAudience, defaultLocale, tools, beacon, }: CreateInjectorAdapterArgs): InjectorAdapter;
17
+ export declare function createInjectorAdapter({ accountId, worker, beUrl, devJwtSecret, tokenBrokerUrl, tokenBrokerAudience, defaultLocale, tools, beacon, confirmation, memory, }: CreateInjectorAdapterArgs): InjectorAdapter;
15
18
  interface CreateMainThreadInjectorAdapterArgs extends Omit<CreateInjectorAdapterArgs, 'worker'> {
16
19
  accountModule: AccountModule;
17
20
  }
18
- export declare function createMainThreadInjectorAdapter({ accountId, accountModule, beUrl, devJwtSecret, tokenBrokerUrl, tokenBrokerAudience, defaultLocale, tools, beacon, }: CreateMainThreadInjectorAdapterArgs): InjectorAdapter;
21
+ export declare function createMainThreadInjectorAdapter({ accountId, accountModule, beUrl, devJwtSecret, tokenBrokerUrl, tokenBrokerAudience, defaultLocale, tools, beacon, confirmation, memory, }: CreateMainThreadInjectorAdapterArgs): InjectorAdapter;
19
22
  export {};
@@ -1,4 +1,5 @@
1
- import type { AccountModule, BeaconCallback, ToolMap } from '../types.js';
1
+ import type { AccountModule, BeaconCallback, ConfirmationCallback, ToolMap } from '../types.js';
2
+ import type { MainRpcMemory } from '../worker/rpc.js';
2
3
  interface MountAccountArgs {
3
4
  accountId: string;
4
5
  beUrl: string;
@@ -10,7 +11,10 @@ interface MountAccountArgs {
10
11
  accountModule: AccountModule;
11
12
  tools?: ToolMap;
12
13
  beacon?: BeaconCallback;
14
+ confirmation?: ConfirmationCallback;
15
+ memory?: MainRpcMemory;
13
16
  allowBlobWorker?: boolean;
17
+ signal?: AbortSignal;
14
18
  }
15
19
  interface AgentDiagnostics {
16
20
  accountId: string;
@@ -23,6 +27,8 @@ interface AgentDiagnostics {
23
27
  }
24
28
  export interface AgentController {
25
29
  type: 'agent';
30
+ signal: AbortSignal;
31
+ addCleanup: (cleanup: () => void) => void;
26
32
  stop: () => void;
27
33
  diagnostics: () => AgentDiagnostics;
28
34
  }
@@ -33,7 +39,7 @@ interface ModuleWorkerHandle {
33
39
  interface CreateModuleWorkerOptions {
34
40
  allowBlobWorker?: boolean;
35
41
  }
36
- export declare function mountAccount({ accountId, beUrl, devJwtSecret, tokenBrokerUrl, tokenBrokerAudience, workerUrl, defaultLocale, accountModule, tools, beacon, allowBlobWorker, }: MountAccountArgs): AgentController;
42
+ export declare function mountAccount({ accountId, beUrl, devJwtSecret, tokenBrokerUrl, tokenBrokerAudience, workerUrl, defaultLocale, accountModule, tools, beacon, confirmation, memory, allowBlobWorker, signal, }: MountAccountArgs): AgentController;
37
43
  export declare function canUseModuleWorker(workerUrl: string): boolean;
38
44
  export declare function createModuleWorker(workerUrl: string, name: string, options?: CreateModuleWorkerOptions): ModuleWorkerHandle;
39
45
  export {};
@@ -40,7 +40,10 @@ export interface PhotoSimilaritySignals {
40
40
  }
41
41
  export interface SimilarityRankingOptions {
42
42
  limit?: number;
43
+ maxCandidates?: number;
43
44
  queryLimit?: number;
45
+ locale?: string;
46
+ similarityMapper?: ((raw: Record<string, unknown>) => ProductSimilarityProfile | null) | undefined;
44
47
  ignoreSkus?: string[];
45
48
  stopWords?: Iterable<string>;
46
49
  facetKeys?: string[];
@@ -50,6 +53,11 @@ export interface SimilarityRankingOptions {
50
53
  hitCounts?: ReadonlyMap<string, number> | Record<string, number>;
51
54
  weights?: Partial<SimilarityWeights>;
52
55
  }
56
+ export interface SimilarityAsyncRankingOptions extends SimilarityRankingOptions {
57
+ batchSize?: number;
58
+ signal?: AbortSignal;
59
+ yield?: () => Promise<void>;
60
+ }
53
61
  export interface SimilarityWeights {
54
62
  token: number;
55
63
  keyword: number;
@@ -68,10 +76,11 @@ export type SimilarityRankedProduct<T> = T & {
68
76
  similarity_score: number;
69
77
  similarity_reasons: string[];
70
78
  };
71
- export declare function normalizeSimilarityText(value: unknown): string;
72
- export declare function tokenizeSimilarityText(value: unknown, stopWords?: Iterable<string>): string[];
79
+ export declare function normalizeSimilarityText(value: unknown, locale?: string): string;
80
+ export declare function tokenizeSimilarityText(value: unknown, stopWords?: Iterable<string>, locale?: string): string[];
73
81
  export declare function buildProductSimilarityProfile(product: SimilarityProductLike | ProductSimilarityProfile, options?: SimilarityRankingOptions): ProductSimilarityProfile;
74
82
  export declare function buildPhotoSimilarityProfile(signals: PhotoSimilaritySignals, options?: SimilarityRankingOptions): ProductSimilarityProfile;
75
83
  export declare function buildSimilarityQueries(source: SimilarityProductLike | ProductSimilarityProfile, options?: SimilarityRankingOptions): string[];
76
84
  export declare function scoreSimilarityCandidate(source: ProductSimilarityProfile, candidate: SimilarityProductLike, options?: SimilarityRankingOptions): SimilarityScore;
77
85
  export declare function rankSimilarProducts<T extends SimilarityProductLike>(source: SimilarityProductLike | ProductSimilarityProfile, candidates: T[], options?: SimilarityRankingOptions): Array<SimilarityRankedProduct<T>>;
86
+ export declare function rankSimilarProductsAsync<T extends SimilarityProductLike>(source: SimilarityProductLike | ProductSimilarityProfile, candidates: T[], options?: SimilarityAsyncRankingOptions): Promise<Array<SimilarityRankedProduct<T>>>;
@@ -0,0 +1,261 @@
1
+ var w = /* @__PURE__ */ new Set([
2
+ "and",
3
+ "are",
4
+ "for",
5
+ "from",
6
+ "the",
7
+ "with"
8
+ ]), z = {
9
+ token: 0.26,
10
+ keyword: 0.22,
11
+ category: 0.18,
12
+ facet: 0.16,
13
+ color: 0.08,
14
+ attribute: 0.06,
15
+ price: 0.08,
16
+ retrieval: 0.08
17
+ }, F = [
18
+ "amber",
19
+ "beige",
20
+ "black",
21
+ "blue",
22
+ "blush",
23
+ "bronze",
24
+ "brown",
25
+ "cream",
26
+ "gold",
27
+ "green",
28
+ "grey",
29
+ "ivory",
30
+ "lilac",
31
+ "mixed",
32
+ "orange",
33
+ "pastel",
34
+ "pink",
35
+ "purple",
36
+ "red",
37
+ "silver",
38
+ "white",
39
+ "yellow"
40
+ ];
41
+ function h(e, t) {
42
+ return String(e ?? "").toLocaleLowerCase(t || void 0).normalize("NFKD").replace(new RegExp("\\p{Diacritic}", "gu"), "").replace(/[^\p{L}\p{N}]+/gu, " ").replace(/\s+/gu, " ").trim();
43
+ }
44
+ function y(e, t = w, r) {
45
+ const i = t instanceof Set ? t : /* @__PURE__ */ new Set([...w, ...t]), n = /* @__PURE__ */ new Set(), o = [];
46
+ for (const c of h(e, r).split(/\s+/u))
47
+ c.length < 3 || i.has(c) || n.has(c) || (n.add(c), o.push(c));
48
+ return o;
49
+ }
50
+ function g(e, t = {}) {
51
+ if (B(e)) return e;
52
+ const r = t.similarityMapper?.(e);
53
+ if (r) return r;
54
+ const i = t.facetKeys, n = l(e.category_names ?? e.category), o = l(e.category_ids), c = E(e.facet_hits), m = Object.entries(c).filter(([s]) => !i || i.some((O) => h(O, t.locale) === h(s, t.locale))).map(([, s]) => s), a = f(e.name, e.title), u = f(e.brand), p = t.sourceKeywords ?? [], T = [
55
+ a,
56
+ u,
57
+ ...n,
58
+ ...m,
59
+ ...l(e.promotions),
60
+ f(e.description),
61
+ ...p
62
+ ].join(" "), b = y(T, t.stopWords, t.locale), x = f(t.sourceProductType, K(n, a, b, t.locale), b[0]), S = d([...D(T, F, t.locale), ...Object.entries(c).filter(([s]) => /colou?r/iu.test(s)).flatMap(([, s]) => y(s, t.stopWords, t.locale))], t.locale), _ = d([...m.flatMap((s) => y(s, t.stopWords, t.locale)), ...l(e.promotions).flatMap((s) => y(s, t.stopWords, t.locale))], t.locale).slice(0, 24);
63
+ return {
64
+ sku: f(e.sku),
65
+ title: a,
66
+ brand: u,
67
+ productType: x,
68
+ categoryNames: n,
69
+ categoryIds: o,
70
+ facets: c,
71
+ keywords: d([...p.flatMap((s) => y(s, t.stopWords, t.locale)), ...b], t.locale).slice(0, 12),
72
+ tokens: b,
73
+ colors: S,
74
+ attributes: _,
75
+ price: C(e)
76
+ };
77
+ }
78
+ function v(e, t = {}) {
79
+ const r = f(e.product_type, e.productType), i = f(e.title, r, l(e.keywords).join(" ")), n = d([
80
+ ...l(e.keywords),
81
+ ...l(e.colors),
82
+ ...l(e.materials),
83
+ ...l(e.styles),
84
+ ...l(e.attributes)
85
+ ]);
86
+ return g({
87
+ sku: "__photo__",
88
+ name: i,
89
+ category_names: r ? [r] : [],
90
+ facet_hits: {
91
+ colors: l(e.colors).join(", "),
92
+ materials: l(e.materials).join(", "),
93
+ styles: l(e.styles).join(", "),
94
+ attributes: l(e.attributes).join(", ")
95
+ },
96
+ promotions: n
97
+ }, {
98
+ ...t,
99
+ sourceProductType: r,
100
+ sourceKeywords: n
101
+ });
102
+ }
103
+ function U(e, t = {}) {
104
+ const r = g(e, t);
105
+ return d([
106
+ ...t.sourceQueries ?? [],
107
+ M([
108
+ r.productType,
109
+ ...r.colors.slice(0, 1),
110
+ ...r.attributes.slice(0, 2)
111
+ ]),
112
+ M([r.productType, ...r.keywords.slice(0, 3)]),
113
+ M([r.categoryNames[r.categoryNames.length - 1], ...r.keywords.slice(0, 2)]),
114
+ M(r.title.split(/\s+/u).slice(0, 6)),
115
+ r.productType
116
+ ].map((i) => i.trim()).filter(Boolean)).slice(0, t.queryLimit ?? 6);
117
+ }
118
+ function j(e, t, r = {}) {
119
+ const i = {
120
+ ...z,
121
+ ...r.weights
122
+ }, n = g(t, r), o = [], c = k(e.tokens, n.tokens, r.locale), m = k(e.keywords, n.tokens, r.locale), a = R(e.categoryNames, n.categoryNames, r.locale) || k(P(e.categoryNames, r.locale), P(n.categoryNames, r.locale), r.locale), u = k(e.attributes, n.attributes, r.locale), p = k(e.colors, n.colors, r.locale), T = k(e.attributes, n.tokens, r.locale), b = W(e.price, n.price), x = I(n.sku, r.hitCounts) > 0 ? 1 : 0, S = Q(e, n), _ = c * i.token + m * i.keyword + a * i.category + u * i.facet + p * i.color + T * i.attribute + b * i.price + x * i.retrieval, s = q(S ? _ : _ * 0.35);
123
+ return S && e.productType && e.productType === n.productType && o.push("same product type"), a > 0.4 && o.push("similar category"), u > 0.2 && o.push("matching product attributes"), p > 0 && o.push("matching colour"), b > 0.8 && o.push("similar price"), S || o.push("weaker product-type match"), {
124
+ score: Number(s.toFixed(4)),
125
+ reasons: o
126
+ };
127
+ }
128
+ function $(e, t, r = {}) {
129
+ const i = g(e, r), n = new Set([i.sku, ...r.ignoreSkus ?? []].filter(Boolean));
130
+ return A(t.filter((o) => {
131
+ const c = f(o.sku);
132
+ return c && !n.has(c);
133
+ }), r.maxCandidates).map((o) => {
134
+ const c = j(i, o, r);
135
+ return {
136
+ ...o,
137
+ similarity_score: c.score,
138
+ similarity_reasons: c.reasons
139
+ };
140
+ }).sort((o, c) => c.similarity_score - o.similarity_score).slice(0, Math.max(1, Math.min(r.limit ?? 12, 100)));
141
+ }
142
+ async function G(e, t, r = {}) {
143
+ const i = g(e, r), n = new Set([i.sku, ...r.ignoreSkus ?? []].filter(Boolean)), o = A(t.filter((a) => {
144
+ const u = f(a.sku);
145
+ return u && !n.has(u);
146
+ }), r.maxCandidates), c = Math.max(1, Math.floor(r.batchSize ?? 50)), m = [];
147
+ for (let a = 0; a < o.length; a += 1) {
148
+ N(r.signal);
149
+ const u = o[a], p = j(i, u, r);
150
+ m.push({
151
+ ...u,
152
+ similarity_score: p.score,
153
+ similarity_reasons: p.reasons
154
+ }), (a + 1) % c === 0 && await L(r.yield);
155
+ }
156
+ return N(r.signal), m.sort((a, u) => u.similarity_score - a.similarity_score).slice(0, Math.max(1, Math.min(r.limit ?? 12, 100)));
157
+ }
158
+ function A(e, t) {
159
+ if (t === void 0) return e;
160
+ const r = Math.floor(Number(t));
161
+ return Number.isFinite(r) && r > 0 ? e.slice(0, r) : e;
162
+ }
163
+ async function L(e) {
164
+ if (e) {
165
+ await e();
166
+ return;
167
+ }
168
+ await new Promise((t) => {
169
+ const r = globalThis;
170
+ if (typeof r.scheduler?.yield == "function") {
171
+ r.scheduler.yield().then(t, t);
172
+ return;
173
+ }
174
+ if (typeof setTimeout == "function") {
175
+ setTimeout(t, 0);
176
+ return;
177
+ }
178
+ t();
179
+ });
180
+ }
181
+ function N(e) {
182
+ if (e?.aborted)
183
+ throw new DOMException("Similarity ranking aborted.", "AbortError");
184
+ }
185
+ function B(e) {
186
+ return !!(e && typeof e == "object" && Array.isArray(e.tokens));
187
+ }
188
+ function f(...e) {
189
+ for (const t of e) if (typeof t == "string" && t.trim()) return t.trim();
190
+ return "";
191
+ }
192
+ function l(e) {
193
+ return Array.isArray(e) ? e.map((t) => f(t)).filter(Boolean) : typeof e == "string" && e.trim() ? e.split(/[,;/|]+/u).map((t) => t.trim()).filter(Boolean) : [];
194
+ }
195
+ function E(e) {
196
+ return !e || typeof e != "object" || Array.isArray(e) ? {} : Object.fromEntries(Object.entries(e).map(([t, r]) => [t, f(r)]).filter(([, t]) => t));
197
+ }
198
+ function C(e) {
199
+ const t = Number(e.price_discounted);
200
+ if (Number.isFinite(t) && t > 0) return t;
201
+ const r = Number(e.price);
202
+ return Number.isFinite(r) && r > 0 ? r : 0;
203
+ }
204
+ function d(e, t) {
205
+ const r = /* @__PURE__ */ new Set(), i = [];
206
+ for (const n of e) {
207
+ const o = h(n, t);
208
+ !o || r.has(o) || (r.add(o), i.push(o));
209
+ }
210
+ return i;
211
+ }
212
+ function D(e, t, r) {
213
+ const i = ` ${h(e, r)} `;
214
+ return t.filter((n) => i.includes(` ${h(n, r)} `));
215
+ }
216
+ function K(e, t, r, i) {
217
+ const n = h(e[e.length - 1] ?? e[0] ?? "", i);
218
+ if (n) {
219
+ const o = y(n, w, i), c = new Set(y(t, w, i));
220
+ return o.find((m) => c.has(m)) ?? o[0] ?? n;
221
+ }
222
+ return r[0] ?? "";
223
+ }
224
+ function M(e) {
225
+ return e.map((t) => h(t)).filter(Boolean).join(" ").replace(/\s+/gu, " ").trim().slice(0, 120);
226
+ }
227
+ function P(e, t) {
228
+ return e.flatMap((r) => y(r, w, t));
229
+ }
230
+ function k(e, t, r) {
231
+ const i = d(e, r), n = new Set(d(t, r));
232
+ return i.length === 0 || n.size === 0 ? 0 : i.filter((o) => n.has(o)).length / i.length;
233
+ }
234
+ function R(e, t, r) {
235
+ const i = d(e, r), n = new Set(d(t, r));
236
+ return i.length === 0 || n.size === 0 ? 0 : i.filter((o) => n.has(o)).length / i.length;
237
+ }
238
+ function W(e, t) {
239
+ return e <= 0 || t <= 0 ? 0 : Math.min(e, t) / Math.max(e, t);
240
+ }
241
+ function I(e, t) {
242
+ return !e || !t ? 0 : typeof t.get == "function" ? t.get(e) ?? 0 : t[e] ?? 0;
243
+ }
244
+ function Q(e, t) {
245
+ if (!e.productType || !t.productType || e.productType === t.productType) return !0;
246
+ const r = new Set(y(e.productType)), i = /* @__PURE__ */ new Set([...y(t.productType), ...t.tokens]);
247
+ return [...r].some((n) => i.has(n));
248
+ }
249
+ function q(e) {
250
+ return Math.max(0, Math.min(1, e));
251
+ }
252
+ export {
253
+ v as buildPhotoSimilarityProfile,
254
+ g as buildProductSimilarityProfile,
255
+ U as buildSimilarityQueries,
256
+ h as normalizeSimilarityText,
257
+ $ as rankSimilarProducts,
258
+ G as rankSimilarProductsAsync,
259
+ j as scoreSimilarityCandidate,
260
+ y as tokenizeSimilarityText
261
+ };
@@ -1,15 +1,17 @@
1
- import type { ChatContext } from '../types.js';
1
+ import type { ChatContext, ChatMessage } from '../types.js';
2
2
  interface CreateChatContextArgs {
3
3
  accountId: string;
4
4
  locale?: string | undefined;
5
5
  parentUrl?: string | undefined;
6
6
  threadId?: string | undefined;
7
7
  incomingContext?: unknown;
8
+ messageLimit?: number | undefined;
8
9
  }
9
10
  interface IncomingMessageLike {
10
11
  role?: unknown;
11
12
  content?: unknown;
12
13
  }
13
14
  export declare function createChatContext(args: CreateChatContextArgs): ChatContext;
14
- export declare function appendMessage(context: ChatContext, message: IncomingMessageLike): ChatContext;
15
+ export declare function appendMessage(context: ChatContext, message: IncomingMessageLike, messageLimit?: number): ChatContext;
16
+ export declare function limitMessages(messages: ChatMessage[], messageLimit?: number): ChatMessage[];
15
17
  export {};
@@ -7,16 +7,26 @@ interface ContextStoreOptions {
7
7
  rpc: RpcFn;
8
8
  persistentPanelKeys?: readonly string[] | undefined;
9
9
  panelKeyLimits?: Record<string, number> | undefined;
10
+ messageLimit?: number | undefined;
11
+ maxThreads?: number | undefined;
12
+ threadTtlMs?: number | undefined;
10
13
  }
11
14
  type PatchInput = Partial<ChatContext> | null | undefined | ((current: ChatContext) => Partial<ChatContext> | null | undefined);
12
15
  export declare class ContextStore {
13
16
  #private;
14
- constructor({ accountId, locale, parentUrl, rpc, persistentPanelKeys, panelKeyLimits, }: ContextStoreOptions);
17
+ constructor({ accountId, locale, parentUrl, rpc, persistentPanelKeys, panelKeyLimits, messageLimit, maxThreads, threadTtlMs, }: ContextStoreOptions);
18
+ get size(): number;
19
+ get(threadId?: string | null | undefined): ChatContext | null;
20
+ getPanel(threadId?: string | null | undefined): ChatContext['panel'] | null;
21
+ getRecentProducts(threadId?: string | null | undefined, key?: string): readonly unknown[];
15
22
  load(request: (ProcessActionRequest & {
16
23
  sessionId?: string;
17
24
  }) | null | undefined): Promise<ChatContext>;
18
25
  patch(threadId: string | null | undefined, patch: PatchInput): ChatContext | null;
19
26
  appendUserMessage(threadId: string | null | undefined, text: string): ChatContext | null;
20
27
  commit(threadId: string | null | undefined): Promise<ChatContext | null>;
28
+ delete(threadId: string | null | undefined): boolean;
29
+ clear(): void;
30
+ pruneExpired(now?: number): number;
21
31
  }
22
32
  export {};
@@ -10,4 +10,5 @@ interface SaveArgs extends LoadArgs {
10
10
  }
11
11
  export declare function loadStickyContext({ accountId, threadId, rpc }: LoadArgs): Promise<Record<string, unknown>>;
12
12
  export declare function saveStickyContext({ accountId, threadId, extensions, panel, rpc }: SaveArgs): Promise<void>;
13
+ export declare function stickyContextKey(accountId: string, threadId: string): string;
13
14
  export {};
@@ -0,0 +1,133 @@
1
+ export type LocaleCode = string;
2
+ export type MoneyValue = number | string;
3
+ export interface GssProductFeature {
4
+ key: string;
5
+ value: string | number | boolean;
6
+ group?: string;
7
+ unit?: string;
8
+ source?: string;
9
+ }
10
+ export interface GssProductSeller {
11
+ id?: string;
12
+ name: string;
13
+ rating?: number;
14
+ url?: string;
15
+ }
16
+ export interface GssProductReview {
17
+ id?: string;
18
+ author?: string;
19
+ rating?: number;
20
+ title?: string;
21
+ text?: string;
22
+ date?: string;
23
+ }
24
+ export interface GssProductQuestionAnswer {
25
+ question: string;
26
+ answer?: string;
27
+ date?: string;
28
+ }
29
+ export interface GssShippingOption {
30
+ label: string;
31
+ price?: MoneyValue;
32
+ currency?: string;
33
+ eta?: string;
34
+ }
35
+ export interface GssInstallmentOption {
36
+ count: number;
37
+ monthlyAmount?: MoneyValue;
38
+ totalAmount?: MoneyValue;
39
+ bank?: string;
40
+ currency?: string;
41
+ }
42
+ export interface GssProductDetails {
43
+ sku?: string;
44
+ id?: string;
45
+ name?: string;
46
+ title?: string;
47
+ brand?: string;
48
+ url?: string;
49
+ image?: string;
50
+ imageUrl?: string;
51
+ images?: string[];
52
+ category?: string;
53
+ category_names?: string[];
54
+ price?: MoneyValue;
55
+ price_discounted?: MoneyValue;
56
+ price_currency?: string;
57
+ description?: string;
58
+ features?: GssProductFeature[];
59
+ specs?: Record<string, unknown>;
60
+ seller?: GssProductSeller;
61
+ qna?: GssProductQuestionAnswer[];
62
+ reviews?: GssProductReview[];
63
+ rating?: number;
64
+ review_count?: number;
65
+ in_stock?: boolean;
66
+ availability?: 'in_stock' | 'out_of_stock' | 'preorder' | 'unknown' | string;
67
+ shipping?: GssShippingOption[];
68
+ installment?: GssInstallmentOption[];
69
+ facets?: Record<string, string | string[] | number | boolean>;
70
+ }
71
+ export interface BeOpInputBase {
72
+ locale?: LocaleCode;
73
+ account_config?: Record<string, unknown>;
74
+ }
75
+ export interface IntentOpInput extends BeOpInputBase {
76
+ utterance: string;
77
+ page_context?: Record<string, unknown>;
78
+ structured_context?: Record<string, unknown>;
79
+ }
80
+ export interface IntentOpOutput {
81
+ intent?: {
82
+ kind?: string;
83
+ confidence?: number;
84
+ rationale?: string;
85
+ };
86
+ search_params?: Record<string, unknown>;
87
+ flow_params?: Record<string, unknown>;
88
+ }
89
+ export interface ProductAnswerInput extends BeOpInputBase {
90
+ question: string;
91
+ products: GssProductDetails[];
92
+ page_context?: Record<string, unknown>;
93
+ }
94
+ export interface ProductAnswerOutput {
95
+ answer?: string;
96
+ citations?: Array<{
97
+ sku?: string;
98
+ key?: string;
99
+ value?: string;
100
+ }>;
101
+ status?: string;
102
+ }
103
+ export interface CompareInput extends BeOpInputBase {
104
+ products: GssProductDetails[];
105
+ criteria?: string[];
106
+ }
107
+ export interface CompareOutput {
108
+ summary?: string;
109
+ table?: Record<string, Array<string | number | boolean | null>>;
110
+ recommended_choice_sku?: string;
111
+ key_differences?: string[];
112
+ special_considerations?: string[];
113
+ status?: string;
114
+ }
115
+ export type UiSpecElementType = 'ActionButtons' | 'ComparisonTable' | 'ProductCard' | 'ProductGrid' | 'ReviewSummary' | 'TextBlock' | string;
116
+ export interface UiSpecElement<Props extends Record<string, unknown> = Record<string, unknown>> {
117
+ type: UiSpecElementType;
118
+ props?: Props;
119
+ children?: string[];
120
+ }
121
+ export interface UiSpec {
122
+ elements: Record<string, UiSpecElement>;
123
+ root?: string;
124
+ }
125
+ export interface UiSpecEvent {
126
+ type: 'ui_spec';
127
+ widget?: 'chat' | 'qna' | 'simrel' | 'similarity' | string;
128
+ spec: UiSpec;
129
+ }
130
+ export interface RefPayload {
131
+ kind: string;
132
+ id: string;
133
+ }
@@ -0,0 +1,14 @@
1
+ export declare function createActivityCollector({ accountId, clock }?: {
2
+ clock?: (() => number) | undefined;
3
+ }): {
4
+ accountId: any;
5
+ readonly entries: never[];
6
+ clear(): void;
7
+ record: (entry: any) => any;
8
+ subscribe(listener: any): () => void;
9
+ };
10
+ export declare function getOrCreateActivityCollector(accountId: any): any;
11
+ export declare function normalizeEntry(entry: any): any;
12
+ export declare function sectionForKind(kind: any): "Flow" | "Intent" | "Backend" | "Tools" | "Telemetry" | "Runtime";
13
+ export declare function severityForEntry(entry: any): "error" | "warn" | "info";
14
+ export declare function groupForEntry(entry: any): any;
@@ -0,0 +1,22 @@
1
+ export declare function wrapActivityTools(tools: any, collector: any): any;
2
+ export declare function wrapActivityBeacon(beacon: any, collector: any): any;
3
+ export declare function wrapActivityTransport(accountId: any, collector: any): boolean;
4
+ export declare function installActivityFetchPatch({ accountId, collector, promptBaseUrl }?: {}): void;
5
+ export declare function recordBeDebugPayload(collector: any, payload: any): void;
6
+ export declare function fetchPromptSource({ accountId, opName, promptBaseUrl }: {
7
+ accountId: any;
8
+ opName: any;
9
+ promptBaseUrl: any;
10
+ }): Promise<{
11
+ url: string;
12
+ error: string;
13
+ yaml?: never;
14
+ } | {
15
+ url: string;
16
+ yaml: string;
17
+ error?: never;
18
+ } | {
19
+ error: any;
20
+ url?: never;
21
+ yaml?: never;
22
+ } | null>;
@@ -0,0 +1,3 @@
1
+ export declare function mountActivityOverlay(collector: any): HTMLElement | null;
2
+ export declare function filterActivityEntries(entries: any, state?: {}): any[];
3
+ export declare function formatJsonHtml(value: any): string;
@@ -0,0 +1,37 @@
1
+ export declare function buildActivityVisualization(entries?: never[]): {
2
+ flow: {
3
+ status: string;
4
+ sessionId: string;
5
+ requestType: string;
6
+ actionType: string;
7
+ model: string;
8
+ current: string;
9
+ errors: number;
10
+ warnings: number;
11
+ startedAt: null;
12
+ lastAt: null;
13
+ tools: never[];
14
+ beOps: never[];
15
+ uiSurfaces: never[];
16
+ timeline: never[];
17
+ };
18
+ context: {
19
+ intent: null;
20
+ route: null;
21
+ panel: null;
22
+ threadExtensions: {};
23
+ pageProduct: null;
24
+ products: null;
25
+ ui: null;
26
+ lastText: string;
27
+ };
28
+ };
29
+ export declare function summarizeDebugState(value: any, source?: string): {
30
+ [k: string]: unknown;
31
+ } | null;
32
+ export declare function summarizePanelState(panel: any): {
33
+ [k: string]: unknown;
34
+ } | null;
35
+ export declare function summarizeUiSpec(spec: any, widget?: string, panelHint?: string): {
36
+ [k: string]: unknown;
37
+ } | null;
@@ -0,0 +1,18 @@
1
+ export declare function installLocalAgenticActivityDebug({ accountId, config, tools, beacon }?: {
2
+ config?: {} | undefined;
3
+ }): {
4
+ enabled: boolean;
5
+ tools: any;
6
+ beacon: any;
7
+ record(): void;
8
+ wrapTransport(): void;
9
+ collector?: never;
10
+ } | {
11
+ enabled: boolean;
12
+ collector: any;
13
+ tools: any;
14
+ beacon: any;
15
+ record: (entry: any) => any;
16
+ wrapTransport: () => boolean;
17
+ };
18
+ export declare function shouldInstallActivityDebug(accountId: any, config?: {}): boolean;
@@ -32,7 +32,10 @@ export interface TrimmedProductFacts {
32
32
  rating?: unknown;
33
33
  review_count?: unknown;
34
34
  }
35
- export declare function normalizeProduct(product: unknown): NormalizedProduct | null;
35
+ export interface ProductNormalizeOptions {
36
+ catalogMapper?: ((raw: Record<string, unknown>) => NormalizedProduct | null) | undefined;
37
+ }
38
+ export declare function normalizeProduct(product: unknown, options?: ProductNormalizeOptions): NormalizedProduct | null;
36
39
  /**
37
40
  * Compact product facts for BE LLM-op evidence. Account-agnostic core —
38
41
  * keeps fields aligned with BE's shared productSchema (sharedSchemas.ts)