@vettvangur/ai-sdk 0.8.0 → 0.9.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"
@@ -154,7 +154,8 @@ does. Then an `__notice--joined` divider names them, the `agent` event fires, `d
154
154
  on the root goes from `waiting` to `agent`, and elements marked `data-ai-chat-agent-name` and
155
155
  `data-ai-chat-agent-initials` are filled in. An agent's messages are `__message--person` with
156
156
  `__initials` and a `__sender` (their first name, then the `live-chat-team` label when set), and
157
- the buttons a message carries (`actions`) under it in `renderActions` markup, the first primary. A
157
+ the buttons a message carries (`actions`) in its `__text` bubble (or in the message when it has
158
+ no text) in `renderActions` markup, the first primary. A
158
159
  link button opens in a new tab. A `sheet` button opens its page in a `__sheet` dialog appended to
159
160
  the root: a `__sheet-header` with a `__sheet-title` (the button's text) and a `__sheet-close`
160
161
  button (the `sheet-close` label), and the page in a `__sheet-frame`. Escape closes it too, and
@@ -315,27 +316,60 @@ or cell) holds Markdown, which the card would show as its characters.
315
316
 
316
317
  ## Styles
317
318
 
318
- `@vettvangur/ai-sdk/styles.css` is an opt-in base for what the SDK renders: the mechanics a thread
319
- needs, not a look. It keeps `hidden` on `data-ai-chat-send`, `-stop`, `-end`,
320
- `data-ai-launcher-teaser` and survey errors whatever display a host gives them, pulses the tool and
321
- typing dots (and stops under reduced motion), hides the typing label for all but screen readers,
322
- draws the `started`, `joined`, `agent-ended`, `ended` and `system` notices as dividers, scrolls a
323
- wide answer-card table inside its region, draws the survey's toggle as a switch, and lays a sheet
324
- over the root, its frame filling what the header leaves. The root needs a position for the sheet to
325
- cover it. Load it before
326
- the host's own styles; its selectors are as plain as each rule allows, so a later host rule of the
327
- same weight wins. Colours and sizes come from custom properties, set on the root or any ancestor:
319
+ `@vettvangur/ai-sdk/styles.css` is an opt-in look for the chat page, the window over every page and
320
+ its launcher: the shell's layout, everything the SDK renders, the live-chat header states, the
321
+ window growing out of the launcher's corner as the launcher spins away, and a plain default theme.
322
+ Load it before the host's own styles; its selectors are as plain as each rule allows, so a later
323
+ host rule of the same weight wins. Its tokens sit in `:where(:root)`, so any host declaration of
324
+ them wins too.
325
+
326
+ The shell's markup stays the host's (labels, icons and editable text are the site's), and carries
327
+ these classes beside its `data-ai-*` attributes:
328
+
329
+ | Part | Classes |
330
+ | --- | --- |
331
+ | Root | `vv-ai-chat`, plus `vv-ai-chat--window` for the window |
332
+ | 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` |
333
+ | Thread | `__thread`, `__thread-inner`, `__intro`, `__intro-avatar`, `__intro-title`, `__intro-text`, `__suggestions`, `__suggestion`, `__suggestion-icon` |
334
+ | Reply actions template | `__reply-action` (`--copy`), `__reply-icon` (`--done`) |
335
+ | Composer | `__composer`, `__composer-inner`, `__prompt`, `__input`, `__send` (`--stop`), `__counter`, `__disclaimer` (`--agent`), `__cancel`, `__brand` |
336
+ | Launcher | `vv-ai-launcher`, `__action`, `__icon`, `__teaser`, `__teaser-open`, `__teaser-title`, `__teaser-text`, `__teaser-dismiss` |
337
+
338
+ Every `vv-ai-chat__` class above is under the root. The page pins the root between the element
339
+ `data-ai-chat-offset` names and the keyboard, and stops the body scrolling. The window floats in the
340
+ corner from `36rem` up and fills the screen below it. The thread is the `vv-ai-chat-thread`
341
+ container, so a host's cards can lay out by its width with `@container vv-ai-chat-thread`.
342
+
343
+ The theme's custom properties, set on the root or any ancestor of the chat and the launcher:
328
344
 
329
345
  | Property | Default |
330
346
  | --- | --- |
331
- | `--vv-ai-chat-dot-size` | `0.375rem` |
332
- | `--vv-ai-chat-dot-color` (typing dots) | `currentColor` |
333
- | `--vv-ai-chat-divider-color` | `currentColor` |
334
- | `--vv-ai-chat-divider-gap` | `0.625rem` |
347
+ | `--vv-ai-color-accent`, `-accent-hover`, `-on-accent` | `#2563eb`, `#1d4ed8`, `#fff` |
348
+ | `--vv-ai-color-text`, `-text-muted`, `-text-subtle` | `#374151`, `#6b7280`, `#9ca3af` |
349
+ | `--vv-ai-color-surface`, `-surface-muted`, `-surface-subtle` | `#fff`, `#f1f4f8`, `#f3f4f6` |
350
+ | `--vv-ai-color-border`, `-border-strong`, `-border-accent` | `#e5e7eb`, `#9ca3af`, `#60a5fa` |
351
+ | `--vv-ai-color-disabled`, `-success`, `-error` | `#d1d5db`, `#16a34a`, `#dc2626` |
352
+ | `--vv-ai-color-error-surface`, `-error-border` | `#fef2f2`, `#fca5a5` |
353
+ | `--vv-ai-color-agent`, `-online`, `-waiting` (initials, header dots) | `#f59e0b`, `#5be38c`, `#ffc93d` |
354
+ | `--vv-ai-font-heading`, `--vv-ai-font-weight-bold` | `inherit`, `700` |
355
+ | `--vv-ai-radius`, `-radius-l`, `-radius-bubble` | `0.3125rem`, `0.625rem`, `1rem` |
356
+ | `--vv-ai-shadow-prompt`, `--vv-ai-focus-ring` | a faint ring, the accent at 15% |
357
+ | `--vv-ai-chat-window-z` (the launcher sits one above) | `1000` |
358
+ | `--vv-ai-chat-window-width`, `-height`, `-inset`, `-radius`, `-shadow` | `23.75rem`, `38.75rem`, `1.25rem`, `1rem`, a soft drop |
359
+ | `--vv-ai-chat-window-header`, `-header-agent`, `-header-text`, `-header-muted`, `-header-hover` | the accent, its hover, on-accent, white at 85% and 15% |
360
+ | `--vv-ai-chat-assistant-avatar` (an image in the window's assistant avatar) | `none` |
361
+ | `--vv-ai-launcher-shadow`, `--vv-ai-launcher-teaser-shadow`, `--vv-ai-menu-shadow` | soft drops |
362
+ | `--vv-ai-chat-spring`, `--vv-ai-launcher-spring`, `--vv-ai-launcher-wind-up` | the window's and launcher's easings |
363
+ | `--vv-ai-chat-window-delay` (the window opens once the launcher has mostly spun away) | `0.35s` |
364
+ | `--vv-ai-chat-dot-size`, `--vv-ai-chat-dot-color` | `0.375rem`, `-border-strong` |
365
+ | `--vv-ai-chat-divider-color`, `--vv-ai-chat-divider-gap` | `-border`, `0.625rem` |
335
366
  | `--vv-ai-survey-toggle-width`, `-height`, `-inset` | `2.125rem`, `1.25rem`, `0.125rem` |
336
- | `--vv-ai-survey-toggle-off`, `-on`, `-knob` | `#9ca3af`, `currentColor`, `#fff` |
337
- | `--vv-ai-chat-sheet-background` | `#fff` |
367
+ | `--vv-ai-survey-toggle-off`, `-on`, `-knob` | `-border-strong`, the accent, `-surface` |
368
+ | `--vv-ai-chat-sheet-background` | `-surface` |
369
+
370
+ Reduced motion turns off the window's and launcher's transitions, the pulsing dots and smooth
371
+ scrolling.
338
372
 
339
373
  The package accepts protocol-v1 events (`delta`, `tool`, `tool_result`, `tool_done`, `suggestions`,
340
374
  `done` with an optional `turn` token, and `error`) and ignores any other. Host-specific card
341
- rendering and the look of the chat remain host responsibilities.
375
+ rendering remains the host's.
package/dist/index.js CHANGED
@@ -1025,6 +1025,7 @@ function bindChat(root, options = {}) {
1025
1025
  bubble.className = part("text");
1026
1026
  bubble.append(renderMarkdown(root.ownerDocument, text));
1027
1027
  parent.append(bubble);
1028
+ return bubble;
1028
1029
  }
1029
1030
  function appendStreamedMarkdown(text) {
1030
1031
  if (!activeAssistant) return;
@@ -1295,7 +1296,7 @@ function bindChat(root, options = {}) {
1295
1296
  const shown = name ? firstName(name) : labels.liveChatAgent;
1296
1297
  sender.append(labels.liveChatTeam ? `${shown} · ${labels.liveChatTeam}` : shown);
1297
1298
  message.append(sender);
1298
- if (text) appendMarkdown(message, text);
1299
+ const bubble = text ? appendMarkdown(message, text) : null;
1299
1300
  const buttons = renderActions(root.ownerDocument, actions.map((action, index) => action.sheet ? {
1300
1301
  label: action.label,
1301
1302
  action: SHEET_ACTION,
@@ -1306,7 +1307,7 @@ function bindChat(root, options = {}) {
1306
1307
  url: action.url,
1307
1308
  primary: index === 0
1308
1309
  }));
1309
- if (buttons) message.append(buttons);
1310
+ if (buttons) (bubble ?? message).append(buttons);
1310
1311
  scrollToEnd();
1311
1312
  }
1312
1313
  function showSheet(url, title) {