@vettvangur/ai-sdk 0.8.1 → 0.10.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 CHANGED
@@ -1,11 +1,11 @@
1
1
  # @vettvangur/ai-sdk
2
2
 
3
- Framework-agnostic, unstyled AI chat primitives for server-rendered shells.
3
+ Framework-agnostic AI chat primitives for server-rendered shells.
4
4
 
5
5
  It exports protocol-v1 contracts, parsing and SSE stream-reading primitives, a headless chat session,
6
6
  a DOM binding for a server-rendered shell, and the few generic pieces a host draws tool results with. It
7
- ships no styles by default: every element it renders carries a BEM class, and the project styles
8
- those. An opt-in base stylesheet holds the mechanics (see [Styles](#styles)).
7
+ ships no styles by default: every element it renders carries a BEM class. An opt-in stylesheet lays
8
+ out and draws the chat, its window and launcher, themed by custom properties (see [Styles](#styles)).
9
9
 
10
10
  ```html
11
11
  <section data-ai-chat data-ai-chat-endpoint="/webapi/aichat/stream"
@@ -241,6 +241,29 @@ import { liveChatFromRoot } from '@vettvangur/ai-sdk/live-chat/aichat'
241
241
  const chat = bindChat(root, { liveChat: liveChatFromRoot })
242
242
  ```
243
243
 
244
+ ## Mounting
245
+
246
+ `@vettvangur/ai-sdk/mount` binds a shell the way most hosts would, from its markup alone.
247
+ `mountAiChat(root, options)` binds `root`, or the first `[data-ai-chat]` in the document, once:
248
+ asked again for the same root, it returns the same binding, so a page chat and a launcher can both
249
+ ask for it. A root that is also `vv-ai-chat--window` gets `bindChatWindow` and the document's
250
+ `data-ai-launcher-teaser` through `bindLauncherTeaser`. `options` are `bindChat`'s, and a person
251
+ answers through `liveChatFromAttributes` unless they name a `liveChat`:
252
+
253
+ | Attributes on the root | Provider |
254
+ | --- | --- |
255
+ | `data-ai-chat-omnichannel-org-id`, `-org-url`, `-widget-id` | Omnichannel |
256
+ | `data-ai-chat-livechat-organization-id`, `-client-id`, optional `-group-id` | LiveChat |
257
+ | `data-ai-chat-live-endpoint` | The AiChat Live desk, as `liveChatFromRoot` |
258
+
259
+ ```ts
260
+ import { createAiChatRegistry } from '@vettvangur/ai-sdk'
261
+ import { mountAiChat } from '@vettvangur/ai-sdk/mount'
262
+
263
+ const registry = createAiChatRegistry()
264
+ const chat = mountAiChat(null, { registry })
265
+ ```
266
+
244
267
  ## Surfaces
245
268
 
246
269
  `createTemplateItemSurface({ template, attribute, key })` shows one item from an authored list
@@ -316,27 +339,60 @@ or cell) holds Markdown, which the card would show as its characters.
316
339
 
317
340
  ## Styles
318
341
 
319
- `@vettvangur/ai-sdk/styles.css` is an opt-in base for what the SDK renders: the mechanics a thread
320
- needs, not a look. It keeps `hidden` on `data-ai-chat-send`, `-stop`, `-end`,
321
- `data-ai-launcher-teaser` and survey errors whatever display a host gives them, pulses the tool and
322
- typing dots (and stops under reduced motion), hides the typing label for all but screen readers,
323
- draws the `started`, `joined`, `agent-ended`, `ended` and `system` notices as dividers, scrolls a
324
- wide answer-card table inside its region, draws the survey's toggle as a switch, and lays a sheet
325
- over the root, its frame filling what the header leaves. The root needs a position for the sheet to
326
- cover it. Load it before
327
- the host's own styles; its selectors are as plain as each rule allows, so a later host rule of the
328
- same weight wins. Colours and sizes come from custom properties, set on the root or any ancestor:
342
+ `@vettvangur/ai-sdk/styles.css` is an opt-in look for the chat page, the window over every page and
343
+ its launcher: the shell's layout, everything the SDK renders, the live-chat header states, the
344
+ window growing out of the launcher's corner as the launcher spins away, and a plain default theme.
345
+ Load it before the host's own styles; its selectors are as plain as each rule allows, so a later
346
+ host rule of the same weight wins. Its tokens sit in `:where(:root)`, so any host declaration of
347
+ them wins too.
348
+
349
+ The shell's markup stays the host's (labels, icons and editable text are the site's), and carries
350
+ these classes beside its `data-ai-*` attributes:
351
+
352
+ | Part | Classes |
353
+ | --- | --- |
354
+ | Root | `vv-ai-chat`, plus `vv-ai-chat--window` for the window |
355
+ | Header | `__header`, `__header-inner`, `__identity`, `__avatar` (`--agent`), `__who`, `__name` and `__status` (`--ai`, `--waiting`, `--agent`), `__header-actions`, `__reset`, `__expand`, `__close`, `__menu`, `__menu-toggle`, `__menu-list`, `__menu-item` |
356
+ | Thread | `__thread`, `__thread-inner`, `__intro`, `__intro-avatar`, `__intro-title`, `__intro-text`, `__suggestions`, `__suggestion`, `__suggestion-icon` |
357
+ | Reply actions template | `__reply-action` (`--copy`), `__reply-icon` (`--done`) |
358
+ | Composer | `__composer`, `__composer-inner`, `__prompt`, `__input`, `__send` (`--stop`), `__counter`, `__disclaimer` (`--agent`), `__cancel`, `__brand` |
359
+ | Launcher | `vv-ai-launcher`, `__action`, `__icon`, `__teaser`, `__teaser-open`, `__teaser-title`, `__teaser-text`, `__teaser-dismiss` |
360
+
361
+ Every `vv-ai-chat__` class above is under the root. The page pins the root between the element
362
+ `data-ai-chat-offset` names and the keyboard, and stops the body scrolling. The window floats in the
363
+ corner from `36rem` up and fills the screen below it. The thread is the `vv-ai-chat-thread`
364
+ container, so a host's cards can lay out by its width with `@container vv-ai-chat-thread`.
365
+
366
+ The theme's custom properties, set on the root or any ancestor of the chat and the launcher:
329
367
 
330
368
  | Property | Default |
331
369
  | --- | --- |
332
- | `--vv-ai-chat-dot-size` | `0.375rem` |
333
- | `--vv-ai-chat-dot-color` (typing dots) | `currentColor` |
334
- | `--vv-ai-chat-divider-color` | `currentColor` |
335
- | `--vv-ai-chat-divider-gap` | `0.625rem` |
370
+ | `--vv-ai-color-accent`, `-accent-hover`, `-on-accent` | `#2563eb`, `#1d4ed8`, `#fff` |
371
+ | `--vv-ai-color-text`, `-text-muted`, `-text-subtle` | `#374151`, `#6b7280`, `#9ca3af` |
372
+ | `--vv-ai-color-surface`, `-surface-muted`, `-surface-subtle` | `#fff`, `#f1f4f8`, `#f3f4f6` |
373
+ | `--vv-ai-color-border`, `-border-strong`, `-border-accent` | `#e5e7eb`, `#9ca3af`, `#60a5fa` |
374
+ | `--vv-ai-color-disabled`, `-success`, `-error` | `#d1d5db`, `#16a34a`, `#dc2626` |
375
+ | `--vv-ai-color-error-surface`, `-error-border` | `#fef2f2`, `#fca5a5` |
376
+ | `--vv-ai-color-agent`, `-online`, `-waiting` (initials, header dots) | `#f59e0b`, `#5be38c`, `#ffc93d` |
377
+ | `--vv-ai-font-heading`, `--vv-ai-font-weight-bold` | `inherit`, `700` |
378
+ | `--vv-ai-radius`, `-radius-l`, `-radius-bubble` | `0.3125rem`, `0.625rem`, `1rem` |
379
+ | `--vv-ai-shadow-prompt`, `--vv-ai-focus-ring` | a faint ring, the accent at 15% |
380
+ | `--vv-ai-chat-window-z` (the launcher sits one above) | `1000` |
381
+ | `--vv-ai-chat-window-width`, `-height`, `-inset`, `-radius`, `-shadow` | `23.75rem`, `38.75rem`, `1.25rem`, `1rem`, a soft drop |
382
+ | `--vv-ai-chat-window-header`, `-header-agent`, `-header-text`, `-header-muted`, `-header-hover` | the accent, its hover, on-accent, white at 85% and 15% |
383
+ | `--vv-ai-chat-assistant-avatar` (an image in the window's assistant avatar) | `none` |
384
+ | `--vv-ai-launcher-shadow`, `--vv-ai-launcher-teaser-shadow`, `--vv-ai-menu-shadow` | soft drops |
385
+ | `--vv-ai-chat-spring`, `--vv-ai-launcher-spring`, `--vv-ai-launcher-wind-up` | the window's and launcher's easings |
386
+ | `--vv-ai-chat-window-delay` (the window opens once the launcher has mostly spun away) | `0.35s` |
387
+ | `--vv-ai-chat-dot-size`, `--vv-ai-chat-dot-color` | `0.375rem`, `-border-strong` |
388
+ | `--vv-ai-chat-divider-color`, `--vv-ai-chat-divider-gap` | `-border`, `0.625rem` |
336
389
  | `--vv-ai-survey-toggle-width`, `-height`, `-inset` | `2.125rem`, `1.25rem`, `0.125rem` |
337
- | `--vv-ai-survey-toggle-off`, `-on`, `-knob` | `#9ca3af`, `currentColor`, `#fff` |
338
- | `--vv-ai-chat-sheet-background` | `#fff` |
390
+ | `--vv-ai-survey-toggle-off`, `-on`, `-knob` | `-border-strong`, the accent, `-surface` |
391
+ | `--vv-ai-chat-sheet-background` | `-surface` |
392
+
393
+ Reduced motion turns off the window's and launcher's transitions, the pulsing dots and smooth
394
+ scrolling.
339
395
 
340
396
  The package accepts protocol-v1 events (`delta`, `tool`, `tool_result`, `tool_done`, `suggestions`,
341
397
  `done` with an optional `turn` token, and `error`) and ignores any other. Host-specific card
342
- rendering and the look of the chat remain host responsibilities.
398
+ rendering remains the host's.