@smooai/chat-widget 0.10.2 → 0.11.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 +3 -0
- package/dist/chat-widget.global.js +58 -0
- package/dist/chat-widget.global.js.map +1 -1
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +7 -0
- package/src/conversation.ts +26 -0
- package/src/element.ts +44 -0
- package/src/styles.ts +4 -0
package/dist/index.d.ts
CHANGED
|
@@ -99,6 +99,12 @@ interface ChatWidgetConfig {
|
|
|
99
99
|
* Clicking one sends it. Capped at 5 for layout.
|
|
100
100
|
*/
|
|
101
101
|
examplePrompts?: string[];
|
|
102
|
+
/**
|
|
103
|
+
* Show mid-conversation suggested-reply chips ("quick replies") under the
|
|
104
|
+
* latest assistant message when the agent returns follow-up suggestions.
|
|
105
|
+
* Clicking one sends it. Defaults to `true` (shown unless explicitly `false`).
|
|
106
|
+
*/
|
|
107
|
+
showSuggestedReplies?: boolean;
|
|
102
108
|
/** Require the visitor's name before chatting. */
|
|
103
109
|
requireName?: boolean;
|
|
104
110
|
/** Require the visitor's email before chatting. */
|
|
@@ -149,6 +155,8 @@ declare class SmoothAgentChatElement extends HTMLElement {
|
|
|
149
155
|
private hasSent;
|
|
150
156
|
/** Starter prompts shown as chips in the empty state. */
|
|
151
157
|
private examplePrompts;
|
|
158
|
+
/** Whether mid-conversation suggested-reply chips are shown (config). */
|
|
159
|
+
private showSuggestedReplies;
|
|
152
160
|
/** Resolved greeting text, cached so async (rAF) renders can reuse it. */
|
|
153
161
|
private greeting;
|
|
154
162
|
/** Current mid-turn interrupt (OTP / tool-confirmation), or null. */
|
|
@@ -167,6 +175,7 @@ declare class SmoothAgentChatElement extends HTMLElement {
|
|
|
167
175
|
private dotEl;
|
|
168
176
|
private inputEl;
|
|
169
177
|
private sendBtn;
|
|
178
|
+
private suggestionsEl;
|
|
170
179
|
/** The live streaming assistant bubble whose textContent the rAF loop drives. */
|
|
171
180
|
private streamBubbleEl;
|
|
172
181
|
/** Message id the reveal is bound to (guards against stale frames after rebuilds). */
|
|
@@ -240,6 +249,16 @@ declare class SmoothAgentChatElement extends HTMLElement {
|
|
|
240
249
|
*/
|
|
241
250
|
private handleMessages;
|
|
242
251
|
private renderMessages;
|
|
252
|
+
/**
|
|
253
|
+
* Render (or clear) the mid-conversation suggested-reply chips under the
|
|
254
|
+
* composer. Shown ONLY when: the feature is enabled, no interrupt / restore
|
|
255
|
+
* overlay is active (those reuse the slot above the composer), and the LATEST
|
|
256
|
+
* message is a finalized assistant turn that carried suggestions. A new turn
|
|
257
|
+
* (agent or the visitor typing) appends messages, so the latest is no longer
|
|
258
|
+
* that assistant message and the chips clear on the next render. Chips reuse
|
|
259
|
+
* the empty-state `.prompts`/`.chip` styling and send via the same path.
|
|
260
|
+
*/
|
|
261
|
+
private renderSuggestions;
|
|
243
262
|
/** True when the host/user prefers reduced motion (snap, no typewriter). */
|
|
244
263
|
private prefersReducedMotion;
|
|
245
264
|
/**
|
|
@@ -450,6 +469,13 @@ interface ChatMessage {
|
|
|
450
469
|
* defensively off the terminal event — see {@link extractCitations}.
|
|
451
470
|
*/
|
|
452
471
|
citations?: Citation[];
|
|
472
|
+
/**
|
|
473
|
+
* Suggested follow-up replies ("quick replies") the agent offered on the
|
|
474
|
+
* terminal `eventual_response`. Set ONLY on the finalized assistant message —
|
|
475
|
+
* never mid-stream. Read defensively (see {@link extractSuggestions}); capped
|
|
476
|
+
* at 4 for layout. Absent when the turn offered none.
|
|
477
|
+
*/
|
|
478
|
+
suggestions?: string[];
|
|
453
479
|
}
|
|
454
480
|
type ConnectionStatus = 'idle' | 'connecting' | 'ready' | 'error' | 'closed';
|
|
455
481
|
/**
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/config.ts","../src/element.ts","../src/loader-core.ts","../src/persistence.ts","../src/conversation.ts","../src/fingerprint.ts"],"mappings":";;;;UASiB,eAAA;;EAEb,IAAA;;EAEA,UAAA;EAJ4B;EAM5B,OAAA;EAN4B;EAQ5B,WAAA;EAJA;EAMA,SAAA;EAFA;EAIA,eAAA;EAAA;EAEA,mBAAA;EAEA;EAAA,UAAA;EAIA;EAFA,cAAA;EAUA;EARA,MAAA;EAYA;EANA,iBAAA;EAMsB;EAJtB,qBAAA;EAesB;EAbtB,kBAAA;EAasB;EAXtB,sBAAA;AAAA;;;;;;;;;KAWQ,cAAA;AAAA,UAEK,gBAAA;EAyBb;;;;EApBA,QAAA;EA6BmD;;;;EAxBnD,IAAA,GAAO,cAAA;EAsCP;EApCA,OAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/config.ts","../src/element.ts","../src/loader-core.ts","../src/persistence.ts","../src/conversation.ts","../src/fingerprint.ts"],"mappings":";;;;UASiB,eAAA;;EAEb,IAAA;;EAEA,UAAA;EAJ4B;EAM5B,OAAA;EAN4B;EAQ5B,WAAA;EAJA;EAMA,SAAA;EAFA;EAIA,eAAA;EAAA;EAEA,mBAAA;EAEA;EAAA,UAAA;EAIA;EAFA,cAAA;EAUA;EARA,MAAA;EAYA;EANA,iBAAA;EAMsB;EAJtB,qBAAA;EAesB;EAbtB,kBAAA;EAasB;EAXtB,sBAAA;AAAA;;;;;;;;;KAWQ,cAAA;AAAA,UAEK,gBAAA;EAyBb;;;;EApBA,QAAA;EA6BmD;;;;EAxBnD,IAAA,GAAO,cAAA;EAsCP;EApCA,OAAA;EA+CA;EA7CA,SAAA;EAiDA;;;;;;EA1CA,OAAA;EAqEQ;EAnER,QAAA;EAmEuB;EAjEvB,SAAA;;EAEA,SAAA;ECzDS;;;;AAAW;AAyDxB;EDOI,WAAA;IAAgB,MAAA;IAAgB,SAAA;IAAmB,SAAA;EAAA;ECPA;EDSnD,WAAA;ECTwC;EDWxC,QAA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B;EC8ST,SAAA,CAAU,IAAA;;EAMV,WAAA,CAAY,QAAA;EAAA,QAMJ,MAAA;EAAA,QAKA,SAAA;EAAA,QAKA,YAAA;;UAMA,WAAA;EDtUR;;;;;AAKS;AAIb;;;;;;;EATI,QC2VQ,eAAA;ED/UH;AAOT;;;;;EAPS,QCsWG,uBAAA;ED1Va;EAAA,QCmWP,YAAA;EDvWd;;;;;;;;;;;AAgBkB;ECyWZ,OAAA,IAAW,OAAA;EDrWc;;;;;;EAAA,QCyZvB,QAAA;EDtZQ;EAAA,QC8ZF,YAAA;ED5ZQ;;;;;EAAA,QCicR,mBAAA;ED9bU;EAAA,QC2cV,aAAA;EDlcF;AAAA;AAGhB;;EAHgB,QCqdE,SAAA;EDldQ;EAAA,QCkeR,cAAA;EDjdF;;;;EC0eN,IAAA,CAAK,IAAA,WAAe,OAAA;EDpXd;EAAA,QC6bJ,eAAA;;;;;EAmDF,kBAAA,CAAmB,KAAA,UAAe,OAAA,qBAAqC,OAAA;EDhfT;ECkhB9D,iBAAA,CAAkB,IAAA,WAAe,OAAA;;UA6BzB,eAAA;;AAruBlB;;;;EA2wBU,mBAAA,CAAoB,SAAA,WAAoB,OAAA;EAxvBtC;EA8wBR,qBAAA;;EAKA,UAAA;AAAA;;;;;;;AJv0BJ;;;;;;;;;;;;;;;;;;;AAgC0B;AAW1B;;;;AAA0B;AAE1B;;;;;;;;;iBKmDgB,kBAAA;;;;;;iBAUA,sBAAA,CAAuB,GAAA,uBAA0B,GAAA,GAAM,EAAA"}
|
package/dist/index.js
CHANGED
|
@@ -334,6 +334,7 @@ function resolveConfig(config) {
|
|
|
334
334
|
startOpen: config.startOpen ?? false,
|
|
335
335
|
hideBranding: config.hideBranding ?? false,
|
|
336
336
|
examplePrompts: (config.examplePrompts ?? []).filter((p) => p.trim().length > 0).slice(0, 5),
|
|
337
|
+
showSuggestedReplies: config.showSuggestedReplies ?? true,
|
|
337
338
|
requireName: config.requireName ?? false,
|
|
338
339
|
requireEmail: config.requireEmail ?? false,
|
|
339
340
|
requirePhone: config.requirePhone ?? false,
|
|
@@ -774,6 +775,19 @@ function extractCitations(inner) {
|
|
|
774
775
|
}
|
|
775
776
|
return out;
|
|
776
777
|
}
|
|
778
|
+
/**
|
|
779
|
+
* Pull the suggested follow-up replies out of a terminal `eventual_response`'s
|
|
780
|
+
* `response` object (`response.suggestedNextActions`). Optional + back-compatible
|
|
781
|
+
* like citations — read defensively (tolerating absence, non-array shapes, and
|
|
782
|
+
* non-string / blank entries) and capped at 4 so a chatty agent can't overflow
|
|
783
|
+
* the composer chip row.
|
|
784
|
+
*/
|
|
785
|
+
function extractSuggestions(response) {
|
|
786
|
+
if (!response || typeof response !== "object") return [];
|
|
787
|
+
const raw = response.suggestedNextActions;
|
|
788
|
+
if (!Array.isArray(raw)) return [];
|
|
789
|
+
return raw.filter((s) => typeof s === "string" && s.trim().length > 0).slice(0, 4);
|
|
790
|
+
}
|
|
777
791
|
/** Convert a server message row into a finalized {@link ChatMessage}. */
|
|
778
792
|
function wireMessageToChat(m, idx) {
|
|
779
793
|
const text = typeof m.content?.text === "string" ? m.content.text : "";
|
|
@@ -1124,6 +1138,8 @@ var ConversationController = class {
|
|
|
1124
1138
|
if (!assistant.text) assistant.text = "(no response)";
|
|
1125
1139
|
const citations = extractCitations(inner);
|
|
1126
1140
|
if (citations.length > 0) assistant.citations = citations;
|
|
1141
|
+
const suggestions = extractSuggestions(inner?.response);
|
|
1142
|
+
if (suggestions.length > 0) assistant.suggestions = suggestions;
|
|
1127
1143
|
assistant.streaming = false;
|
|
1128
1144
|
this.emitMessages();
|
|
1129
1145
|
} catch (err) {
|
|
@@ -1954,6 +1970,10 @@ ${mode === "fullpage" ? `
|
|
|
1954
1970
|
transform: translateY(-1px);
|
|
1955
1971
|
}
|
|
1956
1972
|
|
|
1973
|
+
/* ───────────── Mid-conversation suggested-reply chips ─────────────── */
|
|
1974
|
+
.reply-suggestions { padding: 0 14px 4px; }
|
|
1975
|
+
.reply-suggestions:empty { display: none; }
|
|
1976
|
+
|
|
1957
1977
|
/* ─────────────── OTP / tool-confirmation interrupt ────────────────── */
|
|
1958
1978
|
.interrupt { padding: 0 14px; }
|
|
1959
1979
|
.int-card {
|
|
@@ -2165,6 +2185,7 @@ var SmoothAgentChatElement = class extends HTMLElement {
|
|
|
2165
2185
|
_defineProperty(this, "userInfoSatisfied", false);
|
|
2166
2186
|
_defineProperty(this, "hasSent", false);
|
|
2167
2187
|
_defineProperty(this, "examplePrompts", []);
|
|
2188
|
+
_defineProperty(this, "showSuggestedReplies", true);
|
|
2168
2189
|
_defineProperty(this, "greeting", "");
|
|
2169
2190
|
_defineProperty(this, "interrupt", null);
|
|
2170
2191
|
_defineProperty(this, "interruptEl", null);
|
|
@@ -2178,6 +2199,7 @@ var SmoothAgentChatElement = class extends HTMLElement {
|
|
|
2178
2199
|
_defineProperty(this, "dotEl", null);
|
|
2179
2200
|
_defineProperty(this, "inputEl", null);
|
|
2180
2201
|
_defineProperty(this, "sendBtn", null);
|
|
2202
|
+
_defineProperty(this, "suggestionsEl", null);
|
|
2181
2203
|
_defineProperty(this, "streamBubbleEl", null);
|
|
2182
2204
|
_defineProperty(this, "streamMsgId", null);
|
|
2183
2205
|
_defineProperty(this, "streamTarget", "");
|
|
@@ -2246,6 +2268,7 @@ var SmoothAgentChatElement = class extends HTMLElement {
|
|
|
2246
2268
|
startOpen: this.overrides.startOpen ?? this.hasAttribute("start-open"),
|
|
2247
2269
|
hideBranding: this.overrides.hideBranding ?? this.hasAttribute("hide-branding"),
|
|
2248
2270
|
examplePrompts: this.overrides.examplePrompts,
|
|
2271
|
+
showSuggestedReplies: this.overrides.showSuggestedReplies,
|
|
2249
2272
|
requireName: this.overrides.requireName,
|
|
2250
2273
|
requireEmail: this.overrides.requireEmail,
|
|
2251
2274
|
requirePhone: this.overrides.requirePhone,
|
|
@@ -2277,10 +2300,12 @@ var SmoothAgentChatElement = class extends HTMLElement {
|
|
|
2277
2300
|
onInterrupt: (interrupt) => {
|
|
2278
2301
|
this.interrupt = interrupt;
|
|
2279
2302
|
this.renderInterrupt();
|
|
2303
|
+
this.renderSuggestions();
|
|
2280
2304
|
},
|
|
2281
2305
|
onIdentityRestore: (state) => {
|
|
2282
2306
|
this.identityRestore = state;
|
|
2283
2307
|
this.renderInterrupt();
|
|
2308
|
+
this.renderSuggestions();
|
|
2284
2309
|
}
|
|
2285
2310
|
});
|
|
2286
2311
|
if (resolved.startOpen) this.open = true;
|
|
@@ -2308,6 +2333,7 @@ var SmoothAgentChatElement = class extends HTMLElement {
|
|
|
2308
2333
|
<button class="close" aria-label="Close chat">${ICON.close}</button>
|
|
2309
2334
|
</div>`;
|
|
2310
2335
|
this.examplePrompts = resolved.examplePrompts;
|
|
2336
|
+
this.showSuggestedReplies = resolved.showSuggestedReplies;
|
|
2311
2337
|
this.greeting = resolved.greeting;
|
|
2312
2338
|
const gating = needsUserInfo(resolved) && !this.userInfoSatisfied;
|
|
2313
2339
|
this.gating = gating;
|
|
@@ -2336,6 +2362,7 @@ var SmoothAgentChatElement = class extends HTMLElement {
|
|
|
2336
2362
|
const footerHtml = footerInner ? `<div class="footer">${footerInner}</div>` : "";
|
|
2337
2363
|
const chatHtml = `
|
|
2338
2364
|
<div class="messages"></div>
|
|
2365
|
+
<div class="reply-suggestions"></div>
|
|
2339
2366
|
<div class="interrupt hidden"></div>
|
|
2340
2367
|
<div class="composer-wrap">
|
|
2341
2368
|
<div class="composer">
|
|
@@ -2366,6 +2393,7 @@ var SmoothAgentChatElement = class extends HTMLElement {
|
|
|
2366
2393
|
this.inputEl = container.querySelector("textarea");
|
|
2367
2394
|
this.sendBtn = container.querySelector(".send");
|
|
2368
2395
|
this.interruptEl = container.querySelector(".interrupt");
|
|
2396
|
+
this.suggestionsEl = container.querySelector(".reply-suggestions");
|
|
2369
2397
|
this.launcherEl?.addEventListener("click", () => this.openChat());
|
|
2370
2398
|
container.querySelector(".close")?.addEventListener("click", () => this.closeChat());
|
|
2371
2399
|
this.sendBtn?.addEventListener("click", () => this.submit());
|
|
@@ -2820,6 +2848,36 @@ var SmoothAgentChatElement = class extends HTMLElement {
|
|
|
2820
2848
|
if (msg.role === "assistant" && !msg.streaming && msg.citations && msg.citations.length > 0) this.messagesEl.appendChild(this.renderSources(msg.citations));
|
|
2821
2849
|
}
|
|
2822
2850
|
this.scrollToBottom(true);
|
|
2851
|
+
this.renderSuggestions();
|
|
2852
|
+
}
|
|
2853
|
+
/**
|
|
2854
|
+
* Render (or clear) the mid-conversation suggested-reply chips under the
|
|
2855
|
+
* composer. Shown ONLY when: the feature is enabled, no interrupt / restore
|
|
2856
|
+
* overlay is active (those reuse the slot above the composer), and the LATEST
|
|
2857
|
+
* message is a finalized assistant turn that carried suggestions. A new turn
|
|
2858
|
+
* (agent or the visitor typing) appends messages, so the latest is no longer
|
|
2859
|
+
* that assistant message and the chips clear on the next render. Chips reuse
|
|
2860
|
+
* the empty-state `.prompts`/`.chip` styling and send via the same path.
|
|
2861
|
+
*/
|
|
2862
|
+
renderSuggestions() {
|
|
2863
|
+
const el = this.suggestionsEl;
|
|
2864
|
+
if (!el) return;
|
|
2865
|
+
el.replaceChildren();
|
|
2866
|
+
if (!this.showSuggestedReplies) return;
|
|
2867
|
+
if (this.interrupt || this.identityRestore.phase !== "idle") return;
|
|
2868
|
+
const last = this.messages[this.messages.length - 1];
|
|
2869
|
+
if (!last || last.role !== "assistant" || last.streaming || !last.suggestions || last.suggestions.length === 0) return;
|
|
2870
|
+
const chips = document.createElement("div");
|
|
2871
|
+
chips.className = "prompts";
|
|
2872
|
+
for (const suggestion of last.suggestions) {
|
|
2873
|
+
const chip = document.createElement("button");
|
|
2874
|
+
chip.type = "button";
|
|
2875
|
+
chip.className = "chip";
|
|
2876
|
+
chip.textContent = suggestion;
|
|
2877
|
+
chip.addEventListener("click", () => this.submitPrompt(suggestion));
|
|
2878
|
+
chips.appendChild(chip);
|
|
2879
|
+
}
|
|
2880
|
+
el.appendChild(chips);
|
|
2823
2881
|
}
|
|
2824
2882
|
/** True when the host/user prefers reduced motion (snap, no typewriter). */
|
|
2825
2883
|
prefersReducedMotion() {
|