brainerce 1.31.0 → 1.33.0
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/README.md +16 -2
- package/dist/bot/bootstrap.global.js +245 -51
- package/dist/bot/index.d.mts +57 -1
- package/dist/bot/index.d.ts +57 -1
- package/dist/bot/index.js +755 -146
- package/dist/bot/index.mjs +755 -146
- package/package.json +1 -1
package/dist/bot/index.d.ts
CHANGED
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
* anonymousSessionId (localStorage). The server re-validates it on every call
|
|
12
12
|
* and silently replaces it when stale — the widget always adopts whatever ids
|
|
13
13
|
* arrive on the `connected` frame.
|
|
14
|
+
*
|
|
15
|
+
* Rendering safety: server/model strings NEVER pass through innerHTML. Text
|
|
16
|
+
* renders via textContent; the markdown-lite renderer builds DOM with
|
|
17
|
+
* createElement only; URLs pass the isSafeUrl gate before reaching href/src.
|
|
14
18
|
*/
|
|
15
19
|
interface BrainerceBotOptions {
|
|
16
20
|
/** Public vc_* connection id of the storefront. */
|
|
@@ -19,24 +23,43 @@ interface BrainerceBotOptions {
|
|
|
19
23
|
baseUrl?: string;
|
|
20
24
|
/** Mount target. Defaults to document.body. */
|
|
21
25
|
target?: HTMLElement;
|
|
26
|
+
/**
|
|
27
|
+
* Host-provided add-to-cart. When present the widget calls it instead of
|
|
28
|
+
* navigating, so the host's own cart state/UI stays in sync. Return (or
|
|
29
|
+
* resolve) false to signal failure — the widget then falls back to the PDP.
|
|
30
|
+
*/
|
|
31
|
+
onAddToCart?: (item: {
|
|
32
|
+
productId: string;
|
|
33
|
+
variantId?: string | null;
|
|
34
|
+
quantity: number;
|
|
35
|
+
}) => boolean | Promise<boolean>;
|
|
22
36
|
}
|
|
23
37
|
declare class BrainerceBot {
|
|
24
38
|
private readonly connectionId;
|
|
25
39
|
private readonly baseUrl;
|
|
26
40
|
private readonly storageKey;
|
|
41
|
+
private readonly onAddToCart?;
|
|
27
42
|
private host?;
|
|
28
43
|
private root?;
|
|
29
44
|
private windowEl?;
|
|
30
45
|
private messagesEl?;
|
|
31
46
|
private inputEl?;
|
|
47
|
+
private sendBtn?;
|
|
32
48
|
private chipsEl?;
|
|
49
|
+
private launcherEl?;
|
|
50
|
+
private expandBtn?;
|
|
33
51
|
private settings;
|
|
34
52
|
private locale;
|
|
35
53
|
private sessionId;
|
|
36
54
|
private conversationId;
|
|
37
55
|
private busy;
|
|
38
56
|
private opened;
|
|
57
|
+
private expanded;
|
|
39
58
|
private destroyed;
|
|
59
|
+
/** Per-turn streaming state. */
|
|
60
|
+
private pendingText;
|
|
61
|
+
private cardsRow;
|
|
62
|
+
private cardIds;
|
|
40
63
|
private constructor();
|
|
41
64
|
/** Boot the widget. Resolves to null when the bot is disabled server-side. */
|
|
42
65
|
static mount(options: BrainerceBotOptions): Promise<BrainerceBot | null>;
|
|
@@ -45,16 +68,49 @@ declare class BrainerceBot {
|
|
|
45
68
|
private t;
|
|
46
69
|
private restoreIds;
|
|
47
70
|
private persistIds;
|
|
71
|
+
private css;
|
|
48
72
|
private render;
|
|
73
|
+
private iconButton;
|
|
74
|
+
private syncSendState;
|
|
49
75
|
private open;
|
|
50
76
|
private close;
|
|
77
|
+
/**
|
|
78
|
+
* The large dialog owns the screen — the page behind must not scroll.
|
|
79
|
+
* Locks <body> while a big surface is open; restores on close/collapse.
|
|
80
|
+
*/
|
|
81
|
+
private prevBodyOverflow;
|
|
82
|
+
private syncBodyScroll;
|
|
83
|
+
private toggleExpand;
|
|
51
84
|
/** First open: restore the server thread, or show the greeting. */
|
|
52
85
|
private primeThread;
|
|
53
86
|
private send;
|
|
54
87
|
private handleFrame;
|
|
88
|
+
private appendCard;
|
|
89
|
+
/**
|
|
90
|
+
* In-card variant picker: one chip-row per attribute; a complete selection
|
|
91
|
+
* resolves to a variantId and becomes a real add-to-cart. Variant image and
|
|
92
|
+
* price update live. Built entirely with createElement (no innerHTML).
|
|
93
|
+
*/
|
|
94
|
+
private togglePicker;
|
|
95
|
+
/**
|
|
96
|
+
* Add-to-cart resolution chain — must never be a dead button:
|
|
97
|
+
* 1. host `onAddToCart` option (scaffolded stores: syncs their cart UI)
|
|
98
|
+
* 2. cancelable `brainerce:bot:add-to-cart` CustomEvent (custom embeds)
|
|
99
|
+
* 3. fallback: navigate to the product page
|
|
100
|
+
*/
|
|
101
|
+
private addToCart;
|
|
102
|
+
/**
|
|
103
|
+
* The host-cart chain shared by card buttons and bot-initiated actions:
|
|
104
|
+
* onAddToCart option -> cancelable CustomEvent. Returns whether a host
|
|
105
|
+
* took the add.
|
|
106
|
+
*/
|
|
107
|
+
private dispatchAdd;
|
|
108
|
+
/** Bot-initiated widget actions (the model called the addToCart tool). */
|
|
109
|
+
private handleAction;
|
|
110
|
+
/** The durable conversion signal — fire-and-forget, never blocks. */
|
|
111
|
+
private beacon;
|
|
55
112
|
private toggleEscalation;
|
|
56
113
|
private submitEscalation;
|
|
57
|
-
private appendCard;
|
|
58
114
|
private appendMessage;
|
|
59
115
|
private appendTyping;
|
|
60
116
|
private scrollDown;
|