@vettvangur/ai-sdk 0.13.0 → 0.14.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 +6 -3
- package/dist/contracts.d.ts +1 -0
- package/dist/livechat.js +3 -1
- package/dist/omnichannel.js +3 -1
- package/dist/styles.css +3 -3
- package/dist/window.js +11 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ const chat = bindChat(document.querySelector('[data-ai-chat]')!, { registry })
|
|
|
52
52
|
| `data-ai-chat-scroll` | The element the thread scrolls in. While an answer arrives, the latest question is held at its top; scrolling by hand lets go until the next question. |
|
|
53
53
|
| `data-ai-chat-offset` | A selector for the element the shell sits under, such as a fixed header. Its height is kept in `--vv-ai-chat-offset` on the root. `offsetElement` does the same from script. |
|
|
54
54
|
| `data-ai-chat-label-*` | Labels, in kebab case: `error`, `timeout`, `tool-running`, `tool-complete`, `tool-failed`, `tool-interrupted`, `sources`, `details`, `table`, `table-scroll`, `follow-ups`, `live-chat`, `contact`. The `labels` option wins over the attribute. Any other name is the host's own, read with `label(name)`. |
|
|
55
|
-
| `data-ai-chat-tool-*` | The progress label for one tool, with underscores in its name written as hyphens.
|
|
55
|
+
| `data-ai-chat-tool-*` | The progress label for one tool, with underscores in its name written as hyphens. The `toolLabels` option wins over the attribute, and the attribute over a `label` the server sends with the `tool` event. Other tools show `tool-running`. |
|
|
56
56
|
|
|
57
57
|
The binding also keeps `--vv-ai-chat-keyboard` on the root at the height an on-screen keyboard
|
|
58
58
|
covers, grows the input to fit what is typed, sets `aria-busy` on the root while a turn is in flight,
|
|
@@ -192,7 +192,10 @@ binding read. `binding.liveChat` is the provider in use, for a host to offer its
|
|
|
192
192
|
`renderSurveyForm`. `@vettvangur/ai-sdk/live-chat/omnichannel` exports
|
|
193
193
|
`createOmnichannelProvider({ orgId, orgUrl, widgetId })` over Dynamics 365 Omnichannel. It needs
|
|
194
194
|
the optional peer dependency `@microsoft/omnichannel-chat-sdk` and imports it only when the
|
|
195
|
-
provider is first used, so a page pays for it when a visitor asks for a person.
|
|
195
|
+
provider is first used, so a page pays for it when a visitor asks for a person. A site that does
|
|
196
|
+
not install it needs no bundler setting for it: esbuild leaves the import for run time, where it
|
|
197
|
+
fails with an error naming the package only if the provider is used. The same holds for
|
|
198
|
+
`@livechat/customer-sdk` below, so `mountAiChat` builds without either. It reads opening
|
|
196
199
|
hours from the widget's config and turns the Adaptive Card survey into text, choice and toggle
|
|
197
200
|
fields, refusing a card with any other input rather than leaving a question out.
|
|
198
201
|
|
|
@@ -394,7 +397,7 @@ The theme's custom properties, set on the root or any ancestor of the chat and t
|
|
|
394
397
|
| `--vv-ai-shadow-prompt`, `--vv-ai-focus-ring` | a faint ring, the accent at 15% |
|
|
395
398
|
| `--vv-ai-chat-window-z` (the launcher sits one above) | `1000` |
|
|
396
399
|
| `--vv-ai-chat-window-width`, `-height`, `-inset`, `-radius`, `-shadow` | `23.75rem`, `38.75rem`, `1.25rem`, `1rem`, a soft drop |
|
|
397
|
-
| `--vv-ai-chat-window-header`, `-header-agent`, `-header-text`, `-header-muted`, `-header-hover` | the accent, its hover, on-accent,
|
|
400
|
+
| `--vv-ai-chat-window-header`, `-header-agent`, `-header-text`, `-header-muted`, `-header-hover` | the accent, its hover, on-accent, the header text at 85% and 15% |
|
|
398
401
|
| `--vv-ai-chat-assistant-avatar` (an image in the window's assistant avatar) | `none` |
|
|
399
402
|
| `--vv-ai-launcher-shadow`, `--vv-ai-launcher-teaser-shadow`, `--vv-ai-menu-shadow` | soft drops |
|
|
400
403
|
| `--vv-ai-chat-spring`, `--vv-ai-launcher-spring`, `--vv-ai-launcher-wind-up` | the window's and launcher's easings |
|
package/dist/contracts.d.ts
CHANGED
package/dist/livechat.js
CHANGED
|
@@ -345,7 +345,9 @@ function createLiveChatProvider(config) {
|
|
|
345
345
|
function load() {
|
|
346
346
|
if (connection) return connection;
|
|
347
347
|
const pending = (async () => {
|
|
348
|
-
const sdk = (await import("@livechat/customer-sdk")
|
|
348
|
+
const sdk = (await import("@livechat/customer-sdk").catch((error) => {
|
|
349
|
+
throw new Error("LiveChat needs @livechat/customer-sdk installed.", { cause: error });
|
|
350
|
+
})).init({
|
|
349
351
|
organizationId: config.organizationId,
|
|
350
352
|
clientId: config.clientId,
|
|
351
353
|
...config.groupId === void 0 ? {} : { groupId: config.groupId }
|
package/dist/omnichannel.js
CHANGED
|
@@ -171,7 +171,9 @@ function createOmnichannelProvider(config) {
|
|
|
171
171
|
function load() {
|
|
172
172
|
if (chat) return chat;
|
|
173
173
|
const pending = (async () => {
|
|
174
|
-
const module = await import("@microsoft/omnichannel-chat-sdk")
|
|
174
|
+
const module = await import("@microsoft/omnichannel-chat-sdk").catch((error) => {
|
|
175
|
+
throw new Error("Omnichannel needs @microsoft/omnichannel-chat-sdk installed.", { cause: error });
|
|
176
|
+
});
|
|
175
177
|
const sdk = new module.OmnichannelChatSDK({
|
|
176
178
|
orgId: config.orgId,
|
|
177
179
|
orgUrl: config.orgUrl,
|
package/dist/styles.css
CHANGED
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
--vv-ai-chat-window-header: var(--vv-ai-color-accent);
|
|
55
55
|
--vv-ai-chat-window-header-agent: var(--vv-ai-color-accent-hover);
|
|
56
56
|
--vv-ai-chat-window-header-text: var(--vv-ai-color-on-accent);
|
|
57
|
-
--vv-ai-chat-window-header-muted:
|
|
58
|
-
--vv-ai-chat-window-header-hover:
|
|
57
|
+
--vv-ai-chat-window-header-muted: color-mix(in srgb, var(--vv-ai-chat-window-header-text) 85%, transparent);
|
|
58
|
+
--vv-ai-chat-window-header-hover: color-mix(in srgb, var(--vv-ai-chat-window-header-text) 15%, transparent);
|
|
59
59
|
/* An image in the circle beside each of the assistant's bubbles in the window. */
|
|
60
60
|
--vv-ai-chat-assistant-avatar: none;
|
|
61
61
|
--vv-ai-launcher-shadow: 0 0.375rem 1.25rem rgb(16 40 80 / 0.25);
|
|
@@ -1007,7 +1007,7 @@ body:has(.vv-ai-chat:not(.vv-ai-chat--window)) {
|
|
|
1007
1007
|
}
|
|
1008
1008
|
|
|
1009
1009
|
.vv-ai-chat--window .vv-ai-chat__avatar {
|
|
1010
|
-
background:
|
|
1010
|
+
background: color-mix(in srgb, var(--vv-ai-chat-window-header-text) 18%, transparent);
|
|
1011
1011
|
}
|
|
1012
1012
|
|
|
1013
1013
|
.vv-ai-chat--window .vv-ai-chat__name {
|
package/dist/window.js
CHANGED
|
@@ -429,6 +429,7 @@ function stringValue(data, key) {
|
|
|
429
429
|
const value = data[key];
|
|
430
430
|
return typeof value === "string" ? value : null;
|
|
431
431
|
}
|
|
432
|
+
const MAX_TOOL_LABEL_LENGTH = 120;
|
|
432
433
|
function signatureEntry(data, key) {
|
|
433
434
|
const value = stringValue(data, key);
|
|
434
435
|
return value && value.length <= MAX_SIGNATURE_LENGTH ? { [key]: value } : {};
|
|
@@ -446,11 +447,14 @@ function parseStreamEvent(name, data) {
|
|
|
446
447
|
case "tool": {
|
|
447
448
|
const id = stringValue(data, "id");
|
|
448
449
|
const toolName = stringValue(data, "name");
|
|
449
|
-
|
|
450
|
+
if (id === null || toolName === null) return null;
|
|
451
|
+
const label = stringValue(data, "label");
|
|
452
|
+
return {
|
|
450
453
|
name,
|
|
451
454
|
data: {
|
|
452
455
|
id,
|
|
453
|
-
name: toolName
|
|
456
|
+
name: toolName,
|
|
457
|
+
...label ? { label: label.slice(0, MAX_TOOL_LABEL_LENGTH) } : {}
|
|
454
458
|
}
|
|
455
459
|
};
|
|
456
460
|
}
|
|
@@ -1097,11 +1101,11 @@ function bindChat(root, options = {}) {
|
|
|
1097
1101
|
if (name in labels) return labels[name];
|
|
1098
1102
|
return options.labels?.[name] || root.getAttribute(`data-ai-chat-label-${kebab(name)}`) || "";
|
|
1099
1103
|
}
|
|
1100
|
-
function toolLabel(name) {
|
|
1104
|
+
function toolLabel(name, sent) {
|
|
1101
1105
|
if (!/^[\w-]{1,64}$/.test(name)) return labels.toolRunning;
|
|
1102
|
-
return options.toolLabels?.[name] || root.getAttribute(`data-ai-chat-tool-${kebab(name)}`) || labels.toolRunning;
|
|
1106
|
+
return options.toolLabels?.[name] || root.getAttribute(`data-ai-chat-tool-${kebab(name)}`) || sent || labels.toolRunning;
|
|
1103
1107
|
}
|
|
1104
|
-
function tool(id, name) {
|
|
1108
|
+
function tool(id, name, sent) {
|
|
1105
1109
|
const element = root.ownerDocument.createElement("div");
|
|
1106
1110
|
element.dataset.aiChatTool = id;
|
|
1107
1111
|
element.className = part("tool");
|
|
@@ -1110,7 +1114,7 @@ function bindChat(root, options = {}) {
|
|
|
1110
1114
|
dot.setAttribute("aria-hidden", "true");
|
|
1111
1115
|
const label = root.ownerDocument.createElement("span");
|
|
1112
1116
|
label.className = part("tool-label");
|
|
1113
|
-
label.append(root.ownerDocument.createTextNode(toolLabel(name)));
|
|
1117
|
+
label.append(root.ownerDocument.createTextNode(toolLabel(name, sent)));
|
|
1114
1118
|
const status = root.ownerDocument.createElement("span");
|
|
1115
1119
|
status.className = part("tool-status");
|
|
1116
1120
|
element.append(dot, label, status);
|
|
@@ -1187,7 +1191,7 @@ function bindChat(root, options = {}) {
|
|
|
1187
1191
|
}
|
|
1188
1192
|
} else if (event.name === "tool") {
|
|
1189
1193
|
clearPendingTool();
|
|
1190
|
-
tool(event.data.id, event.data.name);
|
|
1194
|
+
tool(event.data.id, event.data.name, event.data.label);
|
|
1191
1195
|
} else if (event.name === "tool_result") {
|
|
1192
1196
|
clearPendingTool();
|
|
1193
1197
|
if (activeAssistant) {
|