@vettvangur/ai-sdk 0.9.0 → 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 +32 -4
- package/dist/contracts.d.ts +3 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +3 -2022
- package/dist/live-chat/livechat.js +1 -533
- package/dist/live-chat/omnichannel.js +1 -293
- package/dist/livechat.js +534 -0
- package/dist/mount.d.ts +22 -0
- package/dist/mount.js +56 -0
- package/dist/omnichannel.js +294 -0
- package/dist/styles.css +9 -0
- package/dist/window.js +2056 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -134,15 +134,20 @@ antiforgery header and expects `{ transcript, context }`: the transcript is sent
|
|
|
134
134
|
opening message and the context goes to the agent, under the `context` the host passes. A failed
|
|
135
135
|
request hands over without them, so a visitor always reaches a person. It resolves to `live`,
|
|
136
136
|
`closed` with a reason, `canceled` or `failed`. Every handover starts from the `handoverPrefill`
|
|
137
|
-
option, or the `data-ai-chat-live-prefill` attribute as a JSON object of answers,
|
|
138
|
-
|
|
137
|
+
option, or the `data-ai-chat-live-prefill` attribute as a JSON object of answers, with `prefill`
|
|
138
|
+
over it; JSON that does not parse is reported to `onError` and left out.
|
|
139
139
|
|
|
140
140
|
A `tool_result` with `kind: 'handover'`, or from the `request_human_agent` tool (`HANDOVER_TOOL`)
|
|
141
141
|
without a kind, is drawn as a handover card when no renderer is registered for the tool:
|
|
142
142
|
`{ liveChatAvailable, contactUrl }` become a primary `live-chat` button and a `contact` link, in
|
|
143
143
|
`renderActions` markup. The button's action is `livechat` (`LIVE_CHAT_ACTION`), which the binding
|
|
144
|
-
runs as `handover()` unless the host registers its own
|
|
145
|
-
|
|
144
|
+
runs as `handover()` unless the host registers its own, with the payload's optional `prefill` (survey
|
|
145
|
+
answers by field name or id, such as a department) as the handover's `prefill`. A card that arrives
|
|
146
|
+
in the stream asks the `liveChat` provider's `availability()` at once, and when it is closed the
|
|
147
|
+
button gives way to a `vv-ai-actions__note` with the `live-chat-closed` label; a card drawn again
|
|
148
|
+
from the stored thread keeps its button, and the click asks again. `isHandoverPayload`,
|
|
149
|
+
`renderHandoverCard(document, data, labels)` and `closeHandoverCard(parent, text)` are exported for a
|
|
150
|
+
host that draws it elsewhere.
|
|
146
151
|
|
|
147
152
|
`binding.mode`, also `data-ai-chat-mode` on the root, is `ai`, `handover` (the input is disabled
|
|
148
153
|
while the survey is asked) or `live`. While live, the composer sends to the provider and the
|
|
@@ -241,6 +246,29 @@ import { liveChatFromRoot } from '@vettvangur/ai-sdk/live-chat/aichat'
|
|
|
241
246
|
const chat = bindChat(root, { liveChat: liveChatFromRoot })
|
|
242
247
|
```
|
|
243
248
|
|
|
249
|
+
## Mounting
|
|
250
|
+
|
|
251
|
+
`@vettvangur/ai-sdk/mount` binds a shell the way most hosts would, from its markup alone.
|
|
252
|
+
`mountAiChat(root, options)` binds `root`, or the first `[data-ai-chat]` in the document, once:
|
|
253
|
+
asked again for the same root, it returns the same binding, so a page chat and a launcher can both
|
|
254
|
+
ask for it. A root that is also `vv-ai-chat--window` gets `bindChatWindow` and the document's
|
|
255
|
+
`data-ai-launcher-teaser` through `bindLauncherTeaser`. `options` are `bindChat`'s, and a person
|
|
256
|
+
answers through `liveChatFromAttributes` unless they name a `liveChat`:
|
|
257
|
+
|
|
258
|
+
| Attributes on the root | Provider |
|
|
259
|
+
| --- | --- |
|
|
260
|
+
| `data-ai-chat-omnichannel-org-id`, `-org-url`, `-widget-id` | Omnichannel |
|
|
261
|
+
| `data-ai-chat-livechat-organization-id`, `-client-id`, optional `-group-id` | LiveChat |
|
|
262
|
+
| `data-ai-chat-live-endpoint` | The AiChat Live desk, as `liveChatFromRoot` |
|
|
263
|
+
|
|
264
|
+
```ts
|
|
265
|
+
import { createAiChatRegistry } from '@vettvangur/ai-sdk'
|
|
266
|
+
import { mountAiChat } from '@vettvangur/ai-sdk/mount'
|
|
267
|
+
|
|
268
|
+
const registry = createAiChatRegistry()
|
|
269
|
+
const chat = mountAiChat(null, { registry })
|
|
270
|
+
```
|
|
271
|
+
|
|
244
272
|
## Surfaces
|
|
245
273
|
|
|
246
274
|
`createTemplateItemSurface({ template, attribute, key })` shows one item from an authored list
|
package/dist/contracts.d.ts
CHANGED
|
@@ -228,7 +228,7 @@ type AiChatHandoverOptions = {
|
|
|
228
228
|
provider?: AiLiveChatProvider;
|
|
229
229
|
/** Values for the agent, over those the handover endpoint returns. */
|
|
230
230
|
context?: Record<string, string>;
|
|
231
|
-
/** Survey answers to start with, by field name or id
|
|
231
|
+
/** Survey answers to start with, by field name or id, over the binding's `handoverPrefill`. */
|
|
232
232
|
prefill?: AiLiveChatAnswers;
|
|
233
233
|
};
|
|
234
234
|
type AiChatHandoverResult = {
|
|
@@ -299,6 +299,8 @@ type AiHandoverPayload = {
|
|
|
299
299
|
kind?: 'handover';
|
|
300
300
|
liveChatAvailable?: boolean;
|
|
301
301
|
contactUrl?: string | null;
|
|
302
|
+
/** Survey answers the live chat button starts with, by field name or id, such as a department. */
|
|
303
|
+
prefill?: AiLiveChatAnswers | null;
|
|
302
304
|
};
|
|
303
305
|
type AiTemplateUrlSurfaceOptions = {
|
|
304
306
|
/** The `template[data-template]` to clone. */
|
package/dist/index.d.ts
CHANGED
|
@@ -86,9 +86,15 @@ declare const HANDOVER_TOOL = "request_human_agent";
|
|
|
86
86
|
declare function isHandoverPayload(tool: string, data: unknown): data is AiHandoverPayload;
|
|
87
87
|
/**
|
|
88
88
|
* The visitor's ways to a person: a primary `liveChat` button that runs the `livechat` action when
|
|
89
|
-
* a live chat is available, and a `contact` link to a safe contact URL.
|
|
89
|
+
* a live chat is available, and a `contact` link to a safe contact URL. The payload's `prefill`
|
|
90
|
+
* goes on the button as its value. Null when neither applies.
|
|
90
91
|
*/
|
|
91
92
|
declare function renderHandoverCard(document: Document, data: AiHandoverPayload, labels: Pick<AiChatLabels, 'liveChat' | 'contact'>): HTMLElement | null;
|
|
93
|
+
/**
|
|
94
|
+
* Puts `text` as `vv-ai-actions__note` in place of the live chat button under `parent`, for when
|
|
95
|
+
* no one can take the chat. The contact link stays.
|
|
96
|
+
*/
|
|
97
|
+
declare function closeHandoverCard(parent: ParentNode, text: string): void;
|
|
92
98
|
//#endregion
|
|
93
99
|
//#region src/protocol.d.ts
|
|
94
100
|
declare const AI_CHAT_PROTOCOL_VERSION = 1;
|
|
@@ -133,4 +139,4 @@ declare function bindChatWindow(binding: AiChatBinding): () => void;
|
|
|
133
139
|
*/
|
|
134
140
|
declare function bindLauncherTeaser(binding: AiChatBinding, container: ParentNode, options?: AiLauncherTeaserOptions): () => void;
|
|
135
141
|
//#endregion
|
|
136
|
-
export { ACTIONS_CLASS, AI_CHAT_PROTOCOL_VERSION, ANSWER_CARD_CLASS, type AiAnswerCard, type AiAnswerCardFact, type AiAnswerCardLabels, type AiAnswerCardLink, type AiAnswerCardSection, type AiAnswerCardTable, type AiCardImage, type AiChatAction, type AiChatActionItem, type AiChatBinding, type AiChatBindings, type AiChatContext, type AiChatEventMap, type AiChatExtensionContext, type AiChatHandoverOptions, type AiChatHandoverResult, type AiChatMessage, type AiChatMode, type AiChatRegistry, type AiChatRenderer, type AiChatRequest, type AiChatSession, type AiChatSessionOptions, type AiChatSessionResult, type AiChatSessionStatus, type AiChatStreamEvent, type AiChatSurface, type AiFormContextOptions, type AiHandoverPayload, type AiLauncherTeaserOptions, type AiLiveChatAction, type AiLiveChatAnswers, type AiLiveChatAvailability, type AiLiveChatFactoryContext, type AiLiveChatMessage, type AiLiveChatProvider, type AiLiveChatSheetHost, type AiLiveChatStartOptions, type AiLiveChatSurveyField, type AiTemplateItemSurfaceOptions, type AiTemplateUrlSurfaceOptions, CARD_LIST_CLASS, CHAT_CLASS, HANDOVER_TOOL, LIVE_CHAT_ACTION, MAX_ANSWER_CARD_FACTS, MAX_ANSWER_CARD_LINKS, MAX_ANSWER_CARD_SECTIONS, MAX_ANSWER_CARD_TABLES, MAX_ANSWER_CARD_TABLE_CELLS, MAX_ANSWER_CARD_TABLE_ROWS, MAX_ANSWER_CARD_TEXT_LENGTH, MAX_ANSWER_CARD_TOTAL_STRUCTURAL_ITEMS, MAX_ANSWER_CARD_TOTAL_TABLE_CELLS, MAX_ANSWER_CARD_TOTAL_TEXT_CHARACTERS, MAX_ANSWER_CARD_URL_LENGTH, assertAnswerCardContract, bindChat, bindChatWindow, bindLauncherTeaser, createAiChatRegistry, createChatSession, createPart, createSafeImage, createSafeLink, createSingleSurface, createTemplateItemSurface, isAnswerCard, isHandoverPayload, isSafeLinkUrl, parseStreamEvent, readEventStream, renderActions, renderAnswerCard, renderCardList, renderHandoverCard, watchFormContext };
|
|
142
|
+
export { ACTIONS_CLASS, AI_CHAT_PROTOCOL_VERSION, ANSWER_CARD_CLASS, type AiAnswerCard, type AiAnswerCardFact, type AiAnswerCardLabels, type AiAnswerCardLink, type AiAnswerCardSection, type AiAnswerCardTable, type AiCardImage, type AiChatAction, type AiChatActionItem, type AiChatBinding, type AiChatBindings, type AiChatContext, type AiChatEventMap, type AiChatExtensionContext, type AiChatHandoverOptions, type AiChatHandoverResult, type AiChatMessage, type AiChatMode, type AiChatRegistry, type AiChatRenderer, type AiChatRequest, type AiChatSession, type AiChatSessionOptions, type AiChatSessionResult, type AiChatSessionStatus, type AiChatStreamEvent, type AiChatSurface, type AiFormContextOptions, type AiHandoverPayload, type AiLauncherTeaserOptions, type AiLiveChatAction, type AiLiveChatAnswers, type AiLiveChatAvailability, type AiLiveChatFactoryContext, type AiLiveChatMessage, type AiLiveChatProvider, type AiLiveChatSheetHost, type AiLiveChatStartOptions, type AiLiveChatSurveyField, type AiTemplateItemSurfaceOptions, type AiTemplateUrlSurfaceOptions, CARD_LIST_CLASS, CHAT_CLASS, HANDOVER_TOOL, LIVE_CHAT_ACTION, MAX_ANSWER_CARD_FACTS, MAX_ANSWER_CARD_LINKS, MAX_ANSWER_CARD_SECTIONS, MAX_ANSWER_CARD_TABLES, MAX_ANSWER_CARD_TABLE_CELLS, MAX_ANSWER_CARD_TABLE_ROWS, MAX_ANSWER_CARD_TEXT_LENGTH, MAX_ANSWER_CARD_TOTAL_STRUCTURAL_ITEMS, MAX_ANSWER_CARD_TOTAL_TABLE_CELLS, MAX_ANSWER_CARD_TOTAL_TEXT_CHARACTERS, MAX_ANSWER_CARD_URL_LENGTH, assertAnswerCardContract, bindChat, bindChatWindow, bindLauncherTeaser, closeHandoverCard, createAiChatRegistry, createChatSession, createPart, createSafeImage, createSafeLink, createSingleSurface, createTemplateItemSurface, isAnswerCard, isHandoverPayload, isSafeLinkUrl, parseStreamEvent, readEventStream, renderActions, renderAnswerCard, renderCardList, renderHandoverCard, watchFormContext };
|