@vettvangur/ai-sdk 0.7.4 → 0.7.5
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/live-chat/livechat.js +17 -2
- package/package.json +1 -1
|
@@ -136,6 +136,20 @@ function filledFormFields(form, answers) {
|
|
|
136
136
|
}
|
|
137
137
|
return filled;
|
|
138
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* A rich message as the markdown an agent message renders with: each card's title and subtitle,
|
|
141
|
+
* and its link buttons as links. A webview button, such as an agent app's sign-in card, opens in a
|
|
142
|
+
* new tab, since the window has no webview; buttons that post back to the agent are left out.
|
|
143
|
+
*/
|
|
144
|
+
function richMessageText(event) {
|
|
145
|
+
const parts = [];
|
|
146
|
+
for (const element of event.elements) {
|
|
147
|
+
if (element.title?.trim()) parts.push(`**${element.title.trim()}**`);
|
|
148
|
+
if (element.subtitle?.trim()) parts.push(element.subtitle.trim());
|
|
149
|
+
for (const button of element.buttons ?? []) if ((button.type === "url" || button.type === "open_external" || button.type === "webview") && button.text.trim()) parts.push(`[${button.text.trim()}](${button.value})`);
|
|
150
|
+
}
|
|
151
|
+
return parts.join("\n\n");
|
|
152
|
+
}
|
|
139
153
|
function errorCode(caught) {
|
|
140
154
|
return caught && typeof caught === "object" && "code" in caught ? String(caught.code) : null;
|
|
141
155
|
}
|
|
@@ -162,8 +176,9 @@ function createLiveChatProvider(config) {
|
|
|
162
176
|
for (const listener of agentListeners) listener({ name: user.name.trim() || null });
|
|
163
177
|
}
|
|
164
178
|
function receive(event) {
|
|
165
|
-
if (!event || event.authorId === customerId
|
|
166
|
-
|
|
179
|
+
if (!event || event.authorId === customerId) return;
|
|
180
|
+
if (event.type !== "message" && event.type !== "system_message" && event.type !== "rich_message") return;
|
|
181
|
+
const text = event.type === "rich_message" ? richMessageText(event) : event.text.trim();
|
|
167
182
|
if (!text) return;
|
|
168
183
|
const system = event.type === "system_message";
|
|
169
184
|
const item = {
|