@vettvangur/ai-sdk 0.16.0 → 0.17.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 +4 -2
- package/dist/contracts.d.ts +3 -0
- package/dist/live-chat.d.ts +3 -0
- package/dist/omnichannel.js +22 -10
- package/dist/provider.d.ts +2 -0
- package/dist/survey.js +1 -1
- package/dist/window.js +5 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -175,7 +175,9 @@ there, shows its pre-chat survey in the thread as a `vv-ai-survey` form with `pr
|
|
|
175
175
|
(by field name or id), and starts the chat. A toggle is never ticked from `prefill`: consent is
|
|
176
176
|
the visitor's to give. The form has an optional `survey-title` and
|
|
177
177
|
`survey-intro` above its fields, a `survey-prefilled` note under each field filled in for the
|
|
178
|
-
visitor, and checks that an email field holds an address (`survey-invalid-email`).
|
|
178
|
+
visitor, and checks that an email field holds an address (`survey-invalid-email`). Omnichannel
|
|
179
|
+
writes its own heading and a legend for required fields into the survey, in the widget's language
|
|
180
|
+
rather than the page's; `survey-heading` and `survey-legend` show in their place when set. With `handoverEndpoint` (or
|
|
179
181
|
`data-ai-chat-handover-endpoint`), it first posts `{ conversationId, culture, messages }` with the
|
|
180
182
|
antiforgery header and expects `{ transcript, context, ticket }`: the transcript is sent as the
|
|
181
183
|
visitor's opening message and the context goes to the agent, under the `context` the host passes.
|
|
@@ -231,7 +233,7 @@ binding read. `binding.liveChat` is the provider in use, for a host to offer its
|
|
|
231
233
|
`upload`. Labels: `live-chat-connecting`, `live-chat-closed`, `live-chat-ended`, `live-chat-failed`,
|
|
232
234
|
`live-chat-typing`, `live-chat-agent`, `live-chat-started`, `live-chat-joined` and
|
|
233
235
|
`live-chat-agent-ended` (with `{name}`), `live-chat-waiting`, `live-chat-waiting-text`,
|
|
234
|
-
`live-chat-team`, `survey-title`, `survey-intro`, `survey-prefilled`, `survey-submit`,
|
|
236
|
+
`live-chat-team`, `survey-title`, `survey-intro`, `survey-prefilled`, `survey-heading`, `survey-legend`, `survey-submit`,
|
|
235
237
|
`survey-cancel`, `survey-required`, `survey-invalid-email`, `sheet-close`.
|
|
236
238
|
|
|
237
239
|
`@vettvangur/ai-sdk/live-chat` exports the provider contract (`AiLiveChatProvider`) and
|
package/dist/contracts.d.ts
CHANGED
|
@@ -171,6 +171,9 @@ type AiChatLabels = AiAnswerCardLabels & {
|
|
|
171
171
|
surveyIntro: string;
|
|
172
172
|
/** Under a field the host's prefill filled in, when not empty. */
|
|
173
173
|
surveyPrefilled: string;
|
|
174
|
+
/** In place of the live chat service's own heading and legend in its survey, when not empty. */
|
|
175
|
+
surveyHeading: string;
|
|
176
|
+
surveyLegend: string;
|
|
174
177
|
/** The button that closes a page an agent's message opened in a sheet over the thread. */
|
|
175
178
|
sheetClose: string;
|
|
176
179
|
error: string;
|
package/dist/live-chat.d.ts
CHANGED
|
@@ -13,6 +13,9 @@ type AiLiveChatSurveyLabels = {
|
|
|
13
13
|
intro?: string;
|
|
14
14
|
/** Shown under a field the prefill filled in, when not empty. */
|
|
15
15
|
prefilled?: string;
|
|
16
|
+
/** In place of the survey's own heading and legend notes, when not empty. */
|
|
17
|
+
heading?: string;
|
|
18
|
+
legend?: string;
|
|
16
19
|
};
|
|
17
20
|
type AiLiveChatSurveyOptions = {
|
|
18
21
|
labels: AiLiveChatSurveyLabels;
|
package/dist/omnichannel.js
CHANGED
|
@@ -66,24 +66,35 @@ function isPlaceholderChoice(title) {
|
|
|
66
66
|
/**
|
|
67
67
|
* The pre-chat survey Omnichannel keeps as an Adaptive Card, as the field list the chat window
|
|
68
68
|
* draws. A question's label is its own, or the text block right above it as Omnichannel lays them
|
|
69
|
-
* out; any other text block is a note.
|
|
70
|
-
*
|
|
69
|
+
* out; any other text block is a note. Omnichannel writes its own heading, in bold before the first
|
|
70
|
+
* question, and a subtle legend after the last, in the widget's language rather than the page's;
|
|
71
|
+
* those notes say so in `role`, so the window can show the host's text instead. Throws on an input
|
|
72
|
+
* type the window cannot show rather than leaving a question out.
|
|
71
73
|
*/
|
|
72
74
|
function surveyFieldsFromAdaptiveCard(card) {
|
|
73
75
|
const fields = [];
|
|
74
76
|
let pending = null;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
let questions = 0;
|
|
78
|
+
const flush = (last = false) => {
|
|
79
|
+
const note = pending ? text(pending.text) : null;
|
|
80
|
+
if (pending && note) {
|
|
81
|
+
const role = !questions && String(pending.weight ?? "").toLowerCase() === "bolder" ? "heading" : last && pending.isSubtle === true ? "legend" : null;
|
|
82
|
+
fields.push(role ? {
|
|
83
|
+
kind: "note",
|
|
84
|
+
text: markdown(note),
|
|
85
|
+
role
|
|
86
|
+
} : {
|
|
87
|
+
kind: "note",
|
|
88
|
+
text: markdown(note)
|
|
89
|
+
});
|
|
90
|
+
}
|
|
80
91
|
pending = null;
|
|
81
92
|
};
|
|
82
93
|
for (const element of inputs(card)) {
|
|
83
94
|
const type = element.type;
|
|
84
95
|
if (type === "TextBlock") {
|
|
85
96
|
flush();
|
|
86
|
-
pending =
|
|
97
|
+
pending = element;
|
|
87
98
|
continue;
|
|
88
99
|
}
|
|
89
100
|
if (typeof type !== "string" || !INPUT_TYPES.has(type)) continue;
|
|
@@ -94,10 +105,11 @@ function surveyFieldsFromAdaptiveCard(card) {
|
|
|
94
105
|
const base = {
|
|
95
106
|
id,
|
|
96
107
|
name: asked.name ?? id,
|
|
97
|
-
label: label(own ?? pending ?? asked.text ?? id),
|
|
108
|
+
label: label(own ?? (pending ? text(pending.text) : null) ?? asked.text ?? id),
|
|
98
109
|
required: element.isRequired === true || asked.required
|
|
99
110
|
};
|
|
100
111
|
pending = null;
|
|
112
|
+
questions++;
|
|
101
113
|
if (type === "Input.Text") {
|
|
102
114
|
const style = String(element.style ?? "");
|
|
103
115
|
fields.push({
|
|
@@ -127,7 +139,7 @@ function surveyFieldsFromAdaptiveCard(card) {
|
|
|
127
139
|
kind: "toggle"
|
|
128
140
|
});
|
|
129
141
|
}
|
|
130
|
-
flush();
|
|
142
|
+
flush(true);
|
|
131
143
|
return fields;
|
|
132
144
|
}
|
|
133
145
|
/**
|
package/dist/provider.d.ts
CHANGED
|
@@ -40,6 +40,8 @@ type AiLiveChatToggleField = AiLiveChatFieldBase & {
|
|
|
40
40
|
type AiLiveChatSurveyNote = {
|
|
41
41
|
kind: 'note';
|
|
42
42
|
text: string;
|
|
43
|
+
/** The survey's own heading or its legend, written by the live chat service rather than its author. */
|
|
44
|
+
role?: 'heading' | 'legend';
|
|
43
45
|
};
|
|
44
46
|
type AiLiveChatSurveyField = AiLiveChatTextField | AiLiveChatChoiceField | AiLiveChatToggleField | AiLiveChatSurveyNote;
|
|
45
47
|
/**
|
package/dist/survey.js
CHANGED
|
@@ -62,7 +62,7 @@ function renderSurveyForm(document, fields, options) {
|
|
|
62
62
|
fields.forEach((field, index) => {
|
|
63
63
|
if (field.kind === "note") {
|
|
64
64
|
const note = createPart(document, "div", SURVEY_CLASS, "note");
|
|
65
|
-
note.append(renderMarkdown(document, field.text));
|
|
65
|
+
note.append(renderMarkdown(document, field.role && options.labels[field.role] || field.text));
|
|
66
66
|
form.append(note);
|
|
67
67
|
return;
|
|
68
68
|
}
|
package/dist/window.js
CHANGED
|
@@ -915,6 +915,8 @@ const defaultLabels = {
|
|
|
915
915
|
surveyTitle: "",
|
|
916
916
|
surveyIntro: "",
|
|
917
917
|
surveyPrefilled: "",
|
|
918
|
+
surveyHeading: "",
|
|
919
|
+
surveyLegend: "",
|
|
918
920
|
sheetClose: "Close"
|
|
919
921
|
};
|
|
920
922
|
const NEAR_LIMIT = .9;
|
|
@@ -1585,7 +1587,9 @@ function bindChat(root, options = {}) {
|
|
|
1585
1587
|
invalidEmail: labels.surveyInvalidEmail,
|
|
1586
1588
|
title: labels.surveyTitle,
|
|
1587
1589
|
intro: labels.surveyIntro,
|
|
1588
|
-
prefilled: labels.surveyPrefilled
|
|
1590
|
+
prefilled: labels.surveyPrefilled,
|
|
1591
|
+
heading: labels.surveyHeading,
|
|
1592
|
+
legend: labels.surveyLegend
|
|
1589
1593
|
},
|
|
1590
1594
|
prefill: {
|
|
1591
1595
|
...handoverPrefill,
|