@vitral/chat 0.2.4 → 0.2.6

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
@@ -33,6 +33,14 @@ reader is already at the bottom — scrolling someone away from what they were
33
33
  reading is the one thing an auto-scrolling log must never do. When they have
34
34
  scrolled off, a button offers to take them back.
35
35
 
36
+ ## Under a message
37
+
38
+ `messageActions` puts buttons under each settled message: `'copy'`,
39
+ `'regenerate'`, `'like'` and `'dislike'` are built in, and anything else — a
40
+ quote, a share — is the application's. Every press is reported through
41
+ `message-action`; a rating shows as pressed while the message carries it as
42
+ its `feedback`. Copying shows a tick for a moment and is announced.
43
+
36
44
  ## Shapes
37
45
 
38
46
  `variant` decides the shape, not the colours:
package/dist/chat.js CHANGED
@@ -3,7 +3,7 @@ import { chatView } from "./render/chat.js";
3
3
  import { en, isClient, loadStyle } from "@vitral/core";
4
4
  import { createOverlay } from "@vitral/controls";
5
5
  import { createRoot, h, iconNode, mergeAttrs, partResolver } from "@vitral/dom";
6
- import { close, getIcon, messageSquare, paperclip, registerIcons, send } from "@vitral/icons";
6
+ import { close, getIcon, messageSquare, paperclip, registerIcons, send, thumbsDown, thumbsUp } from "@vitral/icons";
7
7
  import { baseStyle, chatStyle } from "@vitral/styles";
8
8
  //#region src/chat.ts
9
9
  var counter = 0;
@@ -32,7 +32,9 @@ function createChat(element, config = {}) {
32
32
  paperclip,
33
33
  send,
34
34
  close,
35
- messageSquare
35
+ messageSquare,
36
+ thumbsUp,
37
+ thumbsDown
36
38
  ]);
37
39
  const messages = () => current.messages ?? [];
38
40
  const variant = () => current.variant ?? "basic";
@@ -96,6 +98,13 @@ function createChat(element, config = {}) {
96
98
  retry(message) {
97
99
  emit("retry", message);
98
100
  },
101
+ messageAction(action, message) {
102
+ if (action.id === "copy") copy(message);
103
+ emit("message-action", {
104
+ action: action.id,
105
+ message
106
+ });
107
+ },
99
108
  suggest(text) {
100
109
  emit("suggestion", text);
101
110
  },
@@ -129,6 +138,37 @@ function createChat(element, config = {}) {
129
138
  render();
130
139
  }
131
140
  };
141
+ /** The message just copied, which wears a tick until the timer takes it off. */
142
+ let copied = null;
143
+ let copiedTimer;
144
+ async function copy(message) {
145
+ const text = message.content ?? "";
146
+ try {
147
+ if (typeof navigator === "undefined" || !navigator.clipboard?.writeText) throw new Error("No clipboard here");
148
+ await navigator.clipboard.writeText(text);
149
+ } catch {
150
+ return;
151
+ }
152
+ if (destroyed) return;
153
+ copied = message.id;
154
+ say(locale().chat.copied);
155
+ clearTimeout(copiedTimer);
156
+ copiedTimer = setTimeout(() => {
157
+ copied = null;
158
+ render();
159
+ }, 2e3);
160
+ render();
161
+ }
162
+ /** Says something through the live region: emptied first, so the same words twice are read twice. */
163
+ function say(words) {
164
+ announcement = "";
165
+ render();
166
+ Promise.resolve().then(() => {
167
+ if (destroyed) return;
168
+ announcement = words;
169
+ render();
170
+ });
171
+ }
132
172
  /** The composer grows with what is typed, up to `maxRows`, and then scrolls. */
133
173
  function grow() {
134
174
  if (!inputEl) return;
@@ -156,6 +196,7 @@ function createChat(element, config = {}) {
156
196
  tabIndex: Math.min(tabIndex, Math.max(0, messages().length - 1)),
157
197
  away,
158
198
  announcement,
199
+ copied,
159
200
  on: actions,
160
201
  refs: {
161
202
  log: (el) => logEl = el,
@@ -223,7 +264,7 @@ function createChat(element, config = {}) {
223
264
  "aria-label": open ? locale().chat.closeChat : locale().chat.openChat,
224
265
  ref: (el) => launcherEl = el,
225
266
  onClick: actions.toggleOpen
226
- }), custom !== null && custom !== void 0 ? custom : iconNode(getIcon(open ? "x" : "messageSquare")))];
267
+ }), custom !== null && custom !== void 0 ? custom : iconNode(getIcon(open ? "close" : "messageSquare")))];
227
268
  }
228
269
  function afterUpdate(previous) {
229
270
  const list = messages();
@@ -283,6 +324,7 @@ function createChat(element, config = {}) {
283
324
  destroy() {
284
325
  if (destroyed) return;
285
326
  destroyed = true;
327
+ clearTimeout(copiedTimer);
286
328
  panel.destroy();
287
329
  root.clear();
288
330
  logEl = null;
package/dist/chat.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"chat.js","names":[],"sources":["../src/chat.ts"],"sourcesContent":["import { en, isClient, loadStyle, type Locale } from '@vitral/core';\nimport { createOverlay } from '@vitral/controls';\nimport { createRoot, h, iconNode, mergeAttrs, partResolver, type Child, type VElement } from '@vitral/dom';\n// Aliased: this module has a `send` of its own, and a bare `x` reads as a variable.\nimport { close as closeIcon, getIcon, messageSquare as messageSquareIcon, paperclip as paperclipIcon, registerIcons, send as sendIcon } from '@vitral/icons';\nimport { baseStyle, chatStyle } from '@vitral/styles';\nimport { announcementOf, messageKeyTarget, showsAvatars } from './engine/state';\nimport type { ChatAttachment, ChatConfig, ChatMessage, ChatVariant } from './engine/types';\nimport { chatView, type ChatActions, type ViewContext } from './render/chat';\n\n/**\n * A conversation with no framework in it: it is handed a configuration, it\n * draws the thread into the element it is given, and it reports what the\n * reader did.\n *\n * The log is one tab stop with a roving focus inside it — the arrows move a\n * message, Home and End jump — so a thread of two hundred messages does not\n * bury the composer behind two hundred tab presses. A message that is still\n * arriving grows in place with a caret after it and is announced only once it\n * settles, because a live region that changes on every token says nothing a\n * screen reader can follow.\n *\n * It scrolls to the newest message as messages arrive, but only while the\n * reader is already at the bottom: scrolling someone away from what they were\n * reading is the one thing an auto-scrolling log must never do. When they have\n * scrolled off, a button offers to take them back.\n */\n\nexport interface ChatHandle {\n element: HTMLElement;\n update(next: Partial<ChatConfig>): void;\n setLocale(locale: Locale): void;\n /** Puts the caret in the composer. */\n focus(): void;\n /** Moves the log to the newest message. */\n scrollToBottom(smooth?: boolean): void;\n /** Whether the reader is at the newest message. */\n atBottom(): boolean;\n destroy(): void;\n}\n\nlet counter = 0;\n\nexport function createChat(element: HTMLElement, config: ChatConfig = {}): ChatHandle {\n let current: ChatConfig = { ...config };\n let destroyed = false;\n\n const id = current.id ?? `vt-chat-${++counter}`;\n const root = createRoot(element);\n const locale = (): Locale => current.locale ?? en;\n const part = partResolver({\n style: chatStyle,\n unstyled: () => !!current.unstyled,\n classes: () => current.classes,\n pt: () => current.pt,\n props: () => current as Record<string, unknown>\n });\n\n if (!current.unstyled) {\n const options = { nonce: current.nonce, cssLayer: current.cssLayer };\n loadStyle(baseStyle.name, baseStyle.css, options);\n loadStyle(chatStyle.name, chatStyle.css, options);\n }\n\n // The composer and the launcher draw icons that are not in the base set,\n // so the addon brings its own rather than leaving an application to work\n // out which names it has to register before a chat will draw.\n registerIcons([paperclipIcon, sendIcon, closeIcon, messageSquareIcon]);\n\n // ---- what is on screen\n\n const messages = (): ChatMessage[] => current.messages ?? [];\n const variant = (): ChatVariant => current.variant ?? 'basic';\n\n let logEl: HTMLElement | null = null;\n let inputEl: HTMLTextAreaElement | null = null;\n let fileEl: HTMLInputElement | null = null;\n /** The message that holds the log's tab stop. */\n let tabIndex = 0;\n /** The reader has scrolled off the newest message. */\n let away = false;\n let announcement = '';\n /** The last message that had settled, so a stream is announced once it stops. */\n let announcedId: string | number | null = null;\n\n const emit = <K extends keyof NonNullable<ChatConfig['on']>>(name: K, ...args: Parameters<NonNullable<NonNullable<ChatConfig['on']>[K]>>) => {\n const handler = current.on?.[name] as ((...a: unknown[]) => void) | undefined;\n handler?.(...(args as unknown[]));\n };\n\n /** Within a few pixels of the end: a fractional scroll height must not read as \"away\". */\n const isAtBottom = (el: HTMLElement) => el.scrollHeight - el.scrollTop - el.clientHeight < 24;\n\n // ---- what the reader does\n\n function send() {\n if (current.disabled || current.readonly) return;\n const text = (current.draft ?? '').trim();\n const attachments = current.attachments ?? [];\n if (!text && attachments.length === 0) return;\n emit('send', { text, attachments });\n }\n\n const actions: ChatActions = {\n send,\n draft(text) {\n current = { ...current, draft: text };\n grow();\n emit('draft-change', text);\n render();\n },\n inputKeydown(event) {\n if (event.key !== 'Enter') return;\n // Enter sends and Shift+Enter breaks the line, unless the chat was\n // told otherwise — in which case the two swap over.\n const sends = current.sendOnEnter === false ? event.ctrlKey || event.metaKey : !event.shiftKey;\n if (!sends) return;\n event.preventDefault();\n send();\n },\n logKeydown(event) {\n const list = messages();\n const target = messageKeyTarget(tabIndex, event.key, list.length);\n if (target < 0 || target === tabIndex) return;\n event.preventDefault();\n tabIndex = target;\n render();\n focusTabbed();\n },\n focusMessage(index) {\n if (tabIndex === index) return;\n tabIndex = index;\n render();\n },\n retry(message) {\n emit('retry', message);\n },\n suggest(text) {\n emit('suggestion', text);\n },\n pickFiles() {\n fileEl?.click();\n },\n filesPicked(files) {\n if (files.length) emit('attach', files);\n // Cleared, or choosing the same file twice never fires again.\n if (fileEl) fileEl.value = '';\n },\n detach(attachment, index) {\n emit('detach', attachment, index);\n },\n scrolled(el) {\n const bottom = isAtBottom(el);\n if (bottom === !away) return;\n away = !bottom;\n emit('at-bottom-change', bottom);\n render();\n },\n jump() {\n handle.scrollToBottom(true);\n },\n toggleOpen() {\n const open = !current.open;\n current = { ...current, open };\n emit('open-change', open);\n render();\n }\n };\n\n /** The composer grows with what is typed, up to `maxRows`, and then scrolls. */\n function grow() {\n if (!inputEl) return;\n const max = current.maxRows ?? 6;\n inputEl.style.height = 'auto';\n const line = parseFloat(getComputedStyle(inputEl).lineHeight) || 20;\n const padding = inputEl.offsetHeight - inputEl.clientHeight + (parseFloat(getComputedStyle(inputEl).paddingTop) || 0) * 2;\n inputEl.style.height = `${Math.min(inputEl.scrollHeight, line * max + padding)}px`;\n }\n\n function focusTabbed() {\n if (!isClient) return;\n logEl?.querySelector<HTMLElement>('[tabindex=\"0\"]')?.focus();\n }\n\n // ---- drawing\n\n const context = (): ViewContext => ({\n config: current,\n locale: locale(),\n variant: variant(),\n messages: messages(),\n ids: { log: `${id}-log`, input: `${id}-input`, message: (index) => `${id}-m${index}` },\n part,\n tabIndex: Math.min(tabIndex, Math.max(0, messages().length - 1)),\n away,\n announcement,\n on: actions,\n refs: {\n log: (el) => (logEl = el as HTMLElement | null),\n input: (el) => (inputEl = el as HTMLTextAreaElement | null),\n file: (el) => (fileEl = el as HTMLInputElement | null)\n }\n });\n\n let drawing = false;\n function render() {\n if (destroyed || drawing) return;\n drawing = true;\n try {\n const widget = variant() === 'widget';\n root.attrs(part(widget ? 'widget' : 'root', { variant: variant(), readonly: current.readonly, disabled: current.disabled }));\n root.render(widget ? widgetView() : chatView(context()));\n if (!widget) panel.close();\n else if (current.open) (panel.isOpen ? panel.update : panel.open)();\n else panel.close();\n } finally {\n drawing = false;\n }\n }\n\n /**\n * The widget: a launcher, and the thread in a panel that opens over the\n * page. The shell is the handle's rather than the view's, because it is the\n * handle that owns whether the panel is open.\n *\n * The panel is hung from the launcher by an overlay rather than positioned\n * inside it. A launcher is dropped wherever an application has room, and\n * the first ancestor with a scrollbar or a hidden overflow would otherwise\n * cut the panel in half — which is exactly what a panel that opens over the\n * page must never let happen.\n */\n let launcherEl: HTMLElement | null = null;\n const panel = createOverlay({\n anchor: () => launcherEl,\n placement: 'top-end',\n offset: 12,\n target: () => current.overlayTarget,\n zIndex: current.zIndex,\n render: () => h('div', mergeAttrs({ id: `${id}-panel` }, part('root', { variant: 'widget' }), part('panel')), ...chatView(context())) as VElement,\n onClose: () => {\n if (!current.open) return;\n current = { ...current, open: false };\n emit('open-change', false);\n render();\n }\n });\n\n function widgetView(): Child[] {\n const open = !!current.open;\n const custom = current.slots?.launcher?.({ open });\n return [\n h(\n 'button',\n mergeAttrs({ key: 'launcher', type: 'button' }, part('launcher'), {\n 'aria-expanded': open ? 'true' : 'false',\n 'aria-controls': `${id}-panel`,\n 'aria-label': open ? locale().chat.closeChat : locale().chat.openChat,\n ref: (el: Element | null) => (launcherEl = el as HTMLElement | null),\n onClick: actions.toggleOpen\n }),\n custom !== null && custom !== undefined ? (custom as Child) : iconNode(getIcon(open ? 'x' : 'messageSquare'))\n )\n ];\n }\n\n // ---- what changed\n\n function afterUpdate(previous: ChatConfig) {\n const list = messages();\n const last = list[list.length - 1];\n\n // A message is announced once it has settled, not while it streams.\n if (last && !last.streaming && last.id !== announcedId) {\n announcedId = last.id;\n const author = last.author ?? (last.role === 'user' ? locale().chat.message : (current.ariaLabel ?? locale().chat.conversation));\n const words = announcementOf(last, author);\n if (words) {\n announcement = '';\n render();\n Promise.resolve().then(() => {\n if (destroyed) return;\n announcement = words;\n render();\n });\n }\n }\n\n // Follow the newest message, but only for a reader who was already there.\n const grew = list.length > (previous.messages?.length ?? 0);\n const streaming = !!last?.streaming;\n if ((grew || streaming) && !away) queueMicrotask(() => handle.scrollToBottom());\n }\n\n const handle: ChatHandle = {\n element,\n update(next) {\n if (destroyed) return;\n const previous = current;\n current = { ...current, ...next };\n // A thread that got shorter must not keep a tab stop past its end.\n tabIndex = Math.min(tabIndex, Math.max(0, messages().length - 1));\n render();\n grow();\n afterUpdate(previous);\n },\n setLocale(next) {\n handle.update({ locale: next });\n },\n focus() {\n inputEl?.focus();\n },\n scrollToBottom(smooth = false) {\n if (!logEl) return;\n // `scrollTo` with options is not everywhere — jsdom has no scrollTo\n // on an element at all — and this runs from a microtask, where a\n // throw goes unhandled and takes the next render with it.\n if (typeof logEl.scrollTo === 'function') logEl.scrollTo({ top: logEl.scrollHeight, behavior: smooth ? 'smooth' : 'auto' });\n else logEl.scrollTop = logEl.scrollHeight;\n if (away) {\n away = false;\n emit('at-bottom-change', true);\n render();\n }\n },\n atBottom: () => !away,\n destroy() {\n if (destroyed) return;\n destroyed = true;\n panel.destroy();\n root.clear();\n logEl = null;\n inputEl = null;\n fileEl = null;\n }\n };\n\n render();\n // The thread opens at its newest message, which is where a conversation is read from.\n queueMicrotask(() => {\n if (!destroyed) handle.scrollToBottom();\n });\n return handle;\n}\n"],"mappings":";;;;;;;;AAyCA,IAAI,UAAU;AAEd,SAAgB,WAAW,SAAsB,SAAqB,CAAC,GAAe;CAClF,IAAI,UAAsB,EAAE,GAAG,OAAO;CACtC,IAAI,YAAY;CAEhB,MAAM,KAAK,QAAQ,MAAM,WAAW,EAAE;CACtC,MAAM,OAAO,WAAW,OAAO;CAC/B,MAAM,eAAuB,QAAQ,UA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,cAAc,CAAC,MAAM,qBAAqB,OAAO,eAAe,CAAC;CAClF;CAEA,MAAM,SAAqB;EACvB;EACA,OAAO,MAAM;GACT,IAAI,WAAW;GACf,MAAM,WAAW;GACjB,UAAU;IAAE,GAAG;IAAS,GAAG;GAAK;GAEhC,WAAW,KAAK,IAAI,UAAU,KAAK,IAAI,GAAG,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC;GAChE,OAAO;GACP,KAAK;GACL,YAAY,QAAQ;EACxB;EACA,UAAU,MAAM;GACZ,OAAO,OAAO,EAAE,QAAQ,KAAK,CAAC;EAClC;EACA,QAAQ;GACJ,SAAS,MAAM;EACnB;EACA,eAAe,SAAS,OAAO;GAC3B,IAAI,CAAC,OAAO;GAIZ,IAAI,OAAO,MAAM,aAAa,YAAY,MAAM,SAAS;IAAE,KAAK,MAAM;IAAc,UAAU,SAAS,WAAW;GAAO,CAAC;QACrH,MAAM,YAAY,MAAM;GAC7B,IAAI,MAAM;IACN,OAAO;IACP,KAAK,oBAAoB,IAAI;IAC7B,OAAO;GACX;EACJ;EACA,gBAAgB,CAAC;EACjB,UAAU;GACN,IAAI,WAAW;GACf,YAAY;GACZ,MAAM,QAAQ;GACd,KAAK,MAAM;GACX,QAAQ;GACR,UAAU;GACV,SAAS;EACb;CACJ;CAEA,OAAO;CAEP,qBAAqB;EACjB,IAAI,CAAC,WAAW,OAAO,eAAe;CAC1C,CAAC;CACD,OAAO;AACX"}
1
+ {"version":3,"file":"chat.js","names":[],"sources":["../src/chat.ts"],"sourcesContent":["import { en, isClient, loadStyle, type Locale } from '@vitral/core';\nimport { createOverlay } from '@vitral/controls';\nimport { createRoot, h, iconNode, mergeAttrs, partResolver, type Child, type VElement } from '@vitral/dom';\n// Aliased: this module has a `send` of its own, and a bare `x` reads as a variable.\nimport {\n close as closeIcon,\n getIcon,\n messageSquare as messageSquareIcon,\n paperclip as paperclipIcon,\n registerIcons,\n send as sendIcon,\n thumbsDown as thumbsDownIcon,\n thumbsUp as thumbsUpIcon\n} from '@vitral/icons';\nimport { baseStyle, chatStyle } from '@vitral/styles';\nimport { announcementOf, messageKeyTarget, showsAvatars } from './engine/state';\nimport type { ChatAttachment, ChatConfig, ChatMessage, ChatVariant } from './engine/types';\nimport { chatView, type ChatActions, type ViewContext } from './render/chat';\n\n/**\n * A conversation with no framework in it: it is handed a configuration, it\n * draws the thread into the element it is given, and it reports what the\n * reader did.\n *\n * The log is one tab stop with a roving focus inside it — the arrows move a\n * message, Home and End jump — so a thread of two hundred messages does not\n * bury the composer behind two hundred tab presses. A message that is still\n * arriving grows in place with a caret after it and is announced only once it\n * settles, because a live region that changes on every token says nothing a\n * screen reader can follow.\n *\n * It scrolls to the newest message as messages arrive, but only while the\n * reader is already at the bottom: scrolling someone away from what they were\n * reading is the one thing an auto-scrolling log must never do. When they have\n * scrolled off, a button offers to take them back.\n */\n\nexport interface ChatHandle {\n element: HTMLElement;\n update(next: Partial<ChatConfig>): void;\n setLocale(locale: Locale): void;\n /** Puts the caret in the composer. */\n focus(): void;\n /** Moves the log to the newest message. */\n scrollToBottom(smooth?: boolean): void;\n /** Whether the reader is at the newest message. */\n atBottom(): boolean;\n destroy(): void;\n}\n\nlet counter = 0;\n\nexport function createChat(element: HTMLElement, config: ChatConfig = {}): ChatHandle {\n let current: ChatConfig = { ...config };\n let destroyed = false;\n\n const id = current.id ?? `vt-chat-${++counter}`;\n const root = createRoot(element);\n const locale = (): Locale => current.locale ?? en;\n const part = partResolver({\n style: chatStyle,\n unstyled: () => !!current.unstyled,\n classes: () => current.classes,\n pt: () => current.pt,\n props: () => current as Record<string, unknown>\n });\n\n if (!current.unstyled) {\n const options = { nonce: current.nonce, cssLayer: current.cssLayer };\n loadStyle(baseStyle.name, baseStyle.css, options);\n loadStyle(chatStyle.name, chatStyle.css, options);\n }\n\n // The composer and the launcher draw icons that are not in the base set,\n // so the addon brings its own rather than leaving an application to work\n // out which names it has to register before a chat will draw.\n registerIcons([paperclipIcon, sendIcon, closeIcon, messageSquareIcon, thumbsUpIcon, thumbsDownIcon]);\n // `copy`, `check` and `refresh`, which the other built-in message actions draw, are in the base set.\n\n // ---- what is on screen\n\n const messages = (): ChatMessage[] => current.messages ?? [];\n const variant = (): ChatVariant => current.variant ?? 'basic';\n\n let logEl: HTMLElement | null = null;\n let inputEl: HTMLTextAreaElement | null = null;\n let fileEl: HTMLInputElement | null = null;\n /** The message that holds the log's tab stop. */\n let tabIndex = 0;\n /** The reader has scrolled off the newest message. */\n let away = false;\n let announcement = '';\n /** The last message that had settled, so a stream is announced once it stops. */\n let announcedId: string | number | null = null;\n\n const emit = <K extends keyof NonNullable<ChatConfig['on']>>(name: K, ...args: Parameters<NonNullable<NonNullable<ChatConfig['on']>[K]>>) => {\n const handler = current.on?.[name] as ((...a: unknown[]) => void) | undefined;\n handler?.(...(args as unknown[]));\n };\n\n /** Within a few pixels of the end: a fractional scroll height must not read as \"away\". */\n const isAtBottom = (el: HTMLElement) => el.scrollHeight - el.scrollTop - el.clientHeight < 24;\n\n // ---- what the reader does\n\n function send() {\n if (current.disabled || current.readonly) return;\n const text = (current.draft ?? '').trim();\n const attachments = current.attachments ?? [];\n if (!text && attachments.length === 0) return;\n emit('send', { text, attachments });\n }\n\n const actions: ChatActions = {\n send,\n draft(text) {\n current = { ...current, draft: text };\n grow();\n emit('draft-change', text);\n render();\n },\n inputKeydown(event) {\n if (event.key !== 'Enter') return;\n // Enter sends and Shift+Enter breaks the line, unless the chat was\n // told otherwise — in which case the two swap over.\n const sends = current.sendOnEnter === false ? event.ctrlKey || event.metaKey : !event.shiftKey;\n if (!sends) return;\n event.preventDefault();\n send();\n },\n logKeydown(event) {\n const list = messages();\n const target = messageKeyTarget(tabIndex, event.key, list.length);\n if (target < 0 || target === tabIndex) return;\n event.preventDefault();\n tabIndex = target;\n render();\n focusTabbed();\n },\n focusMessage(index) {\n if (tabIndex === index) return;\n tabIndex = index;\n render();\n },\n retry(message) {\n emit('retry', message);\n },\n messageAction(action, message) {\n if (action.id === 'copy') void copy(message);\n emit('message-action', { action: action.id, message });\n },\n suggest(text) {\n emit('suggestion', text);\n },\n pickFiles() {\n fileEl?.click();\n },\n filesPicked(files) {\n if (files.length) emit('attach', files);\n // Cleared, or choosing the same file twice never fires again.\n if (fileEl) fileEl.value = '';\n },\n detach(attachment, index) {\n emit('detach', attachment, index);\n },\n scrolled(el) {\n const bottom = isAtBottom(el);\n if (bottom === !away) return;\n away = !bottom;\n emit('at-bottom-change', bottom);\n render();\n },\n jump() {\n handle.scrollToBottom(true);\n },\n toggleOpen() {\n const open = !current.open;\n current = { ...current, open };\n emit('open-change', open);\n render();\n }\n };\n\n /** The message just copied, which wears a tick until the timer takes it off. */\n let copied: string | number | null = null;\n let copiedTimer: ReturnType<typeof setTimeout> | undefined;\n async function copy(message: ChatMessage) {\n const text = message.content ?? '';\n try {\n if (typeof navigator === 'undefined' || !navigator.clipboard?.writeText) throw new Error('No clipboard here');\n await navigator.clipboard.writeText(text);\n } catch {\n return;\n }\n if (destroyed) return;\n copied = message.id;\n say(locale().chat.copied);\n clearTimeout(copiedTimer);\n copiedTimer = setTimeout(() => {\n copied = null;\n render();\n }, 2000);\n render();\n }\n\n /** Says something through the live region: emptied first, so the same words twice are read twice. */\n function say(words: string) {\n announcement = '';\n render();\n Promise.resolve().then(() => {\n if (destroyed) return;\n announcement = words;\n render();\n });\n }\n\n /** The composer grows with what is typed, up to `maxRows`, and then scrolls. */\n function grow() {\n if (!inputEl) return;\n const max = current.maxRows ?? 6;\n inputEl.style.height = 'auto';\n const line = parseFloat(getComputedStyle(inputEl).lineHeight) || 20;\n const padding = inputEl.offsetHeight - inputEl.clientHeight + (parseFloat(getComputedStyle(inputEl).paddingTop) || 0) * 2;\n inputEl.style.height = `${Math.min(inputEl.scrollHeight, line * max + padding)}px`;\n }\n\n function focusTabbed() {\n if (!isClient) return;\n logEl?.querySelector<HTMLElement>('[tabindex=\"0\"]')?.focus();\n }\n\n // ---- drawing\n\n const context = (): ViewContext => ({\n config: current,\n locale: locale(),\n variant: variant(),\n messages: messages(),\n ids: { log: `${id}-log`, input: `${id}-input`, message: (index) => `${id}-m${index}` },\n part,\n tabIndex: Math.min(tabIndex, Math.max(0, messages().length - 1)),\n away,\n announcement,\n copied,\n on: actions,\n refs: {\n log: (el) => (logEl = el as HTMLElement | null),\n input: (el) => (inputEl = el as HTMLTextAreaElement | null),\n file: (el) => (fileEl = el as HTMLInputElement | null)\n }\n });\n\n let drawing = false;\n function render() {\n if (destroyed || drawing) return;\n drawing = true;\n try {\n const widget = variant() === 'widget';\n root.attrs(part(widget ? 'widget' : 'root', { variant: variant(), readonly: current.readonly, disabled: current.disabled }));\n root.render(widget ? widgetView() : chatView(context()));\n if (!widget) panel.close();\n else if (current.open) (panel.isOpen ? panel.update : panel.open)();\n else panel.close();\n } finally {\n drawing = false;\n }\n }\n\n /**\n * The widget: a launcher, and the thread in a panel that opens over the\n * page. The shell is the handle's rather than the view's, because it is the\n * handle that owns whether the panel is open.\n *\n * The panel is hung from the launcher by an overlay rather than positioned\n * inside it. A launcher is dropped wherever an application has room, and\n * the first ancestor with a scrollbar or a hidden overflow would otherwise\n * cut the panel in half — which is exactly what a panel that opens over the\n * page must never let happen.\n */\n let launcherEl: HTMLElement | null = null;\n const panel = createOverlay({\n anchor: () => launcherEl,\n placement: 'top-end',\n offset: 12,\n target: () => current.overlayTarget,\n zIndex: current.zIndex,\n render: () => h('div', mergeAttrs({ id: `${id}-panel` }, part('root', { variant: 'widget' }), part('panel')), ...chatView(context())) as VElement,\n onClose: () => {\n if (!current.open) return;\n current = { ...current, open: false };\n emit('open-change', false);\n render();\n }\n });\n\n function widgetView(): Child[] {\n const open = !!current.open;\n const custom = current.slots?.launcher?.({ open });\n return [\n h(\n 'button',\n mergeAttrs({ key: 'launcher', type: 'button' }, part('launcher'), {\n 'aria-expanded': open ? 'true' : 'false',\n 'aria-controls': `${id}-panel`,\n 'aria-label': open ? locale().chat.closeChat : locale().chat.openChat,\n ref: (el: Element | null) => (launcherEl = el as HTMLElement | null),\n onClick: actions.toggleOpen\n }),\n custom !== null && custom !== undefined ? (custom as Child) : iconNode(getIcon(open ? 'close' : 'messageSquare'))\n )\n ];\n }\n\n // ---- what changed\n\n function afterUpdate(previous: ChatConfig) {\n const list = messages();\n const last = list[list.length - 1];\n\n // A message is announced once it has settled, not while it streams.\n if (last && !last.streaming && last.id !== announcedId) {\n announcedId = last.id;\n const author = last.author ?? (last.role === 'user' ? locale().chat.message : (current.ariaLabel ?? locale().chat.conversation));\n const words = announcementOf(last, author);\n if (words) {\n announcement = '';\n render();\n Promise.resolve().then(() => {\n if (destroyed) return;\n announcement = words;\n render();\n });\n }\n }\n\n // Follow the newest message, but only for a reader who was already there.\n const grew = list.length > (previous.messages?.length ?? 0);\n const streaming = !!last?.streaming;\n if ((grew || streaming) && !away) queueMicrotask(() => handle.scrollToBottom());\n }\n\n const handle: ChatHandle = {\n element,\n update(next) {\n if (destroyed) return;\n const previous = current;\n current = { ...current, ...next };\n // A thread that got shorter must not keep a tab stop past its end.\n tabIndex = Math.min(tabIndex, Math.max(0, messages().length - 1));\n render();\n grow();\n afterUpdate(previous);\n },\n setLocale(next) {\n handle.update({ locale: next });\n },\n focus() {\n inputEl?.focus();\n },\n scrollToBottom(smooth = false) {\n if (!logEl) return;\n // `scrollTo` with options is not everywhere — jsdom has no scrollTo\n // on an element at all — and this runs from a microtask, where a\n // throw goes unhandled and takes the next render with it.\n if (typeof logEl.scrollTo === 'function') logEl.scrollTo({ top: logEl.scrollHeight, behavior: smooth ? 'smooth' : 'auto' });\n else logEl.scrollTop = logEl.scrollHeight;\n if (away) {\n away = false;\n emit('at-bottom-change', true);\n render();\n }\n },\n atBottom: () => !away,\n destroy() {\n if (destroyed) return;\n destroyed = true;\n clearTimeout(copiedTimer);\n panel.destroy();\n root.clear();\n logEl = null;\n inputEl = null;\n fileEl = null;\n }\n };\n\n render();\n // The thread opens at its newest message, which is where a conversation is read from.\n queueMicrotask(() => {\n if (!destroyed) handle.scrollToBottom();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AO;GACP,KAAK;GACL,YAAY,QAAQ;EACxB;EACA,UAAU,MAAM;GACZ,OAAO,OAAO,EAAE,QAAQ,KAAK,CAAC;EAClC;EACA,QAAQ;GACJ,SAAS,MAAM;EACnB;EACA,eAAe,SAAS,OAAO;GAC3B,IAAI,CAAC,OAAO;GAIZ,IAAI,OAAO,MAAM,aAAa,YAAY,MAAM,SAAS;IAAE,KAAK,MAAM;IAAc,UAAU,SAAS,WAAW;GAAO,CAAC;QACrH,MAAM,YAAY,MAAM;GAC7B,IAAI,MAAM;IACN,OAAO;IACP,KAAK,oBAAoB,IAAI;IAC7B,OAAO;GACX;EACJ;EACA,gBAAgB,CAAC;EACjB,UAAU;GACN,IAAI,WAAW;GACf,YAAY;GACZ,aAAa,WAAW;GACxB,MAAM,QAAQ;GACd,KAAK,MAAM;GACX,QAAQ;GACR,UAAU;GACV,SAAS;EACb;CACJ;CAEA,OAAO;CAEP,qBAAqB;EACjB,IAAI,CAAC,WAAW,OAAO,eAAe;CAC1C,CAAC;CACD,OAAO;AACX"}
@@ -70,11 +70,34 @@ export interface ChatMessage {
70
70
  attachments?: ChatAttachment[];
71
71
  toolCalls?: ChatToolCall[];
72
72
  citations?: ChatCitation[];
73
+ /** What the reader thought of an answer, which the built-in `like` and `dislike` actions show as pressed. */
74
+ feedback?: 'like' | 'dislike' | null;
73
75
  }
74
76
  export interface ChatSendPayload {
75
77
  text: string;
76
78
  attachments: ChatAttachment[];
77
79
  }
80
+ /**
81
+ * A button under a message: copy it, ask again, rate it. `'copy'`,
82
+ * `'regenerate'`, `'like'` and `'dislike'` are built in and may be given by
83
+ * name; anything else is the application's. Every press is reported through
84
+ * `message-action`.
85
+ */
86
+ /** The actions a chat draws by name. */
87
+ export type ChatBuiltInAction = 'copy' | 'regenerate' | 'like' | 'dislike';
88
+ export interface ChatMessageAction {
89
+ id: string;
90
+ /** The button's name, and its tooltip when it shows only an icon. */
91
+ label?: string;
92
+ /** A registered icon name. */
93
+ icon?: string;
94
+ /** A toggle, pressed or not for this message: a thumbs up that stays up. */
95
+ pressed?: boolean | ((message: ChatMessage) => boolean);
96
+ /** Whose messages it goes under. Defaults to the assistant's. */
97
+ roles?: ChatRole[];
98
+ /** Shows the label beside the icon. */
99
+ showLabel?: boolean;
100
+ }
78
101
  export interface ChatEvents {
79
102
  /** The composer was submitted. The message is not added for you: add it and answer it. */
80
103
  send?: (payload: ChatSendPayload) => void;
@@ -92,6 +115,11 @@ export interface ChatEvents {
92
115
  'open-change'?: (open: boolean) => void;
93
116
  /** The reader scrolled away from the newest message, or came back to it. */
94
117
  'at-bottom-change'?: (atBottom: boolean) => void;
118
+ /** A message's action was pressed. `copy` has already copied by then. */
119
+ 'message-action'?: (event: {
120
+ action: string;
121
+ message: ChatMessage;
122
+ }) => void;
95
123
  }
96
124
  export interface ChatSlots {
97
125
  /** Over the thread: a title, a model picker, a close button. */
@@ -112,6 +140,8 @@ export interface ChatSlots {
112
140
  }
113
141
  export interface ChatConfig {
114
142
  messages?: ChatMessage[];
143
+ /** Buttons under each message: `['copy', 'regenerate', 'like', 'dislike']`, or actions of your own. */
144
+ messageActions?: (ChatMessageAction | ChatBuiltInAction)[];
115
145
  /** What the composer holds. Give it back on `draft-change` to control it. */
116
146
  draft?: string;
117
147
  variant?: ChatVariant;
@@ -1,6 +1,6 @@
1
1
  import { type Locale } from '@vitral/core';
2
2
  import { type Child, type Props } from '@vitral/dom';
3
- import type { ChatAttachment, ChatConfig, ChatMessage, ChatVariant } from '../engine/types';
3
+ import type { ChatAttachment, ChatConfig, ChatMessage, ChatMessageAction, ChatVariant } from '../engine/types';
4
4
  export interface ChatActions {
5
5
  send: () => void;
6
6
  draft: (text: string) => void;
@@ -8,6 +8,7 @@ export interface ChatActions {
8
8
  logKeydown: (event: KeyboardEvent) => void;
9
9
  focusMessage: (index: number) => void;
10
10
  retry: (message: ChatMessage) => void;
11
+ messageAction: (action: ChatMessageAction, message: ChatMessage) => void;
11
12
  suggest: (text: string) => void;
12
13
  pickFiles: () => void;
13
14
  filesPicked: (files: File[]) => void;
@@ -32,6 +33,8 @@ export interface ViewContext {
32
33
  /** The reader has scrolled away from the newest message. */
33
34
  away: boolean;
34
35
  announcement: string;
36
+ /** The message whose text was just copied, which shows a tick for a moment. */
37
+ copied?: string | number | null;
35
38
  on: ChatActions;
36
39
  /** Keeps the log and the composer reachable from the handle. */
37
40
  refs: {
@@ -40,5 +43,7 @@ export interface ViewContext {
40
43
  file: (el: Element | null) => void;
41
44
  };
42
45
  }
46
+ /** The actions a message shows: the built-in ones filled in, and only those meant for its speaker. */
47
+ export declare function actionsFor(config: ChatConfig, locale: Locale, message: ChatMessage): ChatMessageAction[];
43
48
  /** The thread: the header, the log, the composer — everything but the widget's shell. */
44
49
  export declare function chatView(context: ViewContext): Child[];
@@ -46,6 +46,54 @@ function toolView(context, tool, index) {
46
46
  const detail = [tool.input, tool.output].filter(Boolean).join("\n\n");
47
47
  return h("details", mergeAttrs({ key: `t${index}` }, part("tool")), h("summary", part("toolSummary"), icon(status === "running" ? "spinner" : status === "error" ? "warning" : "check", status === "running" ? { spin: true } : void 0), h("span", part("toolName"), tool.name), h("span", part("toolStatus", { status }), words)), detail ? h("pre", part("toolBody"), detail) : null);
48
48
  }
49
+ /** The actions a message shows: the built-in ones filled in, and only those meant for its speaker. */
50
+ function actionsFor(config, locale, message) {
51
+ if (message.streaming || message.error) return [];
52
+ return (config.messageActions ?? []).map((action) => {
53
+ const given = typeof action === "string" ? { id: action } : action;
54
+ if (given.id === "copy") return {
55
+ icon: "copy",
56
+ label: locale.chat.copy,
57
+ ...given
58
+ };
59
+ if (given.id === "regenerate") return {
60
+ icon: "refresh",
61
+ label: locale.chat.regenerate,
62
+ ...given
63
+ };
64
+ if (given.id === "like") return {
65
+ icon: "thumbsUp",
66
+ label: locale.chat.like,
67
+ pressed: (m) => m.feedback === "like",
68
+ ...given
69
+ };
70
+ if (given.id === "dislike") return {
71
+ icon: "thumbsDown",
72
+ label: locale.chat.dislike,
73
+ pressed: (m) => m.feedback === "dislike",
74
+ ...given
75
+ };
76
+ return given;
77
+ }).filter((action) => (action.roles ?? ["assistant"]).includes(message.role) && (action.id !== "copy" || !!message.content));
78
+ }
79
+ function actionView(context, action, message) {
80
+ const { part, on, locale } = context;
81
+ const copied = action.id === "copy" && context.copied === message.id;
82
+ const label = copied ? locale.chat.copied : action.label ?? action.id;
83
+ const pressed = typeof action.pressed === "function" ? action.pressed(message) : action.pressed;
84
+ return h("button", mergeAttrs({
85
+ key: `a-${action.id}`,
86
+ type: "button"
87
+ }, part("messageAction", {
88
+ pressed: !!pressed,
89
+ copied
90
+ }), {
91
+ "aria-label": action.showLabel ? void 0 : label,
92
+ title: action.showLabel ? void 0 : label,
93
+ "aria-pressed": pressed === void 0 ? void 0 : pressed ? "true" : "false",
94
+ onClick: () => on.messageAction(action, message)
95
+ }), action.icon ? icon(copied ? "check" : action.icon) : null, action.showLabel || !action.icon ? label : null);
96
+ }
49
97
  function messageView(context, message, index) {
50
98
  const { part, locale, on, config, ids, tabIndex } = context;
51
99
  const side = sideOf(message.role);
@@ -55,6 +103,7 @@ function messageView(context, message, index) {
55
103
  });
56
104
  const time = timeText(message.at, locale);
57
105
  const body = message.error ?? message.content ?? "";
106
+ const actions = actionsFor(config, locale, message);
58
107
  return h("div", mergeAttrs({
59
108
  key: String(message.id),
60
109
  id: ids.message(index)
@@ -80,7 +129,10 @@ function messageView(context, message, index) {
80
129
  target: "_blank",
81
130
  rel: "noreferrer"
82
131
  }, part("citation")), `${i + 1}. ${c.title}`) : h("span", mergeAttrs({ key: `c${i}` }, part("citation")), `${i + 1}. ${c.title}`))) : null,
83
- time || message.retryable ? h("div", mergeAttrs({ key: "meta" }, part("meta")), time ? h("time", part("time"), time) : null, message.retryable ? h("button", mergeAttrs({ type: "button" }, part("retry"), { onClick: () => on.retry(message) }), icon("refresh"), locale.chat.retry) : null) : null
132
+ time || message.retryable || actions.length ? h("div", mergeAttrs({ key: "meta" }, part("meta")), time ? h("time", mergeAttrs({ key: "time" }, part("time")), time) : null, message.retryable ? h("button", mergeAttrs({
133
+ key: "retry",
134
+ type: "button"
135
+ }, part("retry"), { onClick: () => on.retry(message) }), icon("refresh"), locale.chat.retry) : null, actions.length ? h("span", mergeAttrs({ key: "actions" }, part("messageActions")), ...actions.map((a) => actionView(context, a, message))) : null) : null
84
136
  ]);
85
137
  }
86
138
  function groupView(context, group) {
@@ -192,6 +244,6 @@ function chatView(context) {
192
244
  ];
193
245
  }
194
246
  //#endregion
195
- export { chatView };
247
+ export { actionsFor, chatView };
196
248
 
197
249
  //# sourceMappingURL=chat.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"chat.js","names":[],"sources":["../../src/render/chat.ts"],"sourcesContent":["import { formatMessage, type Locale } from '@vitral/core';\nimport { h, iconNode, mergeAttrs, type Child, type Props } from '@vitral/dom';\nimport { getIcon } from '@vitral/icons';\nimport { formatSize, groupMessages, initialsOf, showsAvatars, sideOf, type ChatGroup } from '../engine/state';\nimport type { ChatAttachment, ChatConfig, ChatMessage, ChatToolCall, ChatVariant, Content } from '../engine/types';\n\n/**\n * The conversation as plain objects: a scrolling log of runs of messages and\n * the box that adds to it. What is drawn is decided here; what happens when it\n * is pressed is the handle's.\n */\n\nconst icon = (name: string, props?: Props): Child => iconNode(getIcon(name), props);\nconst content = (value: Content): Child => (value === null || value === undefined ? null : value);\n\nexport interface ChatActions {\n send: () => void;\n draft: (text: string) => void;\n inputKeydown: (event: KeyboardEvent) => void;\n logKeydown: (event: KeyboardEvent) => void;\n focusMessage: (index: number) => void;\n retry: (message: ChatMessage) => void;\n suggest: (text: string) => void;\n pickFiles: () => void;\n filesPicked: (files: File[]) => void;\n detach: (attachment: ChatAttachment, index: number) => void;\n scrolled: (element: HTMLElement) => void;\n jump: () => void;\n toggleOpen: () => void;\n}\n\nexport interface ViewContext {\n config: ChatConfig;\n locale: Locale;\n variant: ChatVariant;\n messages: ChatMessage[];\n ids: { log: string; input: string; message: (index: number) => string };\n part: (name: string, state?: unknown) => Props;\n /** The message that holds the log's tab stop. */\n tabIndex: number;\n /** The reader has scrolled away from the newest message. */\n away: boolean;\n announcement: string;\n on: ChatActions;\n /** Keeps the log and the composer reachable from the handle. */\n refs: { log: (el: Element | null) => void; input: (el: Element | null) => void; file: (el: Element | null) => void };\n}\n\n/** The time a message carries, in the reader's own format. */\nfunction timeText(at: ChatMessage['at'], locale: Locale): string | undefined {\n if (at === undefined || at === null) return undefined;\n const date = at instanceof Date ? at : new Date(at);\n if (Number.isNaN(date.getTime())) return undefined;\n return new Intl.DateTimeFormat(locale.code, { hour: '2-digit', minute: '2-digit' }).format(date);\n}\n\nfunction attachmentView(context: ViewContext, attachment: ChatAttachment, index: number, removable: boolean): Child {\n const { part, on, locale } = context;\n const size = formatSize(attachment.size);\n const body: Child[] = [\n icon('paperclip'),\n h('span', part('attachmentName'), attachment.name),\n size ? h('span', part('attachmentSize'), size) : null,\n removable\n ? h(\n 'button',\n mergeAttrs({ type: 'button' }, part('attachmentRemove'), {\n 'aria-label': formatMessage(locale.chat.removeAttachment, { name: attachment.name }),\n onClick: () => on.detach(attachment, index)\n }),\n icon('close')\n )\n : null\n ];\n // A file that has somewhere to go is a link; one that has not is a chip.\n return attachment.url && !removable\n ? h('a', mergeAttrs({ key: `a${index}`, href: attachment.url, target: '_blank', rel: 'noreferrer' }, part('attachment')), ...body)\n : h('span', mergeAttrs({ key: `a${index}` }, part('attachment')), ...body);\n}\n\nfunction toolView(context: ViewContext, tool: ChatToolCall, index: number): Child {\n const { part, locale } = context;\n const status = tool.status ?? 'done';\n const words = status === 'running' ? locale.chat.toolRunning : status === 'error' ? locale.chat.toolFailed : locale.chat.toolDone;\n const detail = [tool.input, tool.output].filter(Boolean).join('\\n\\n');\n return h(\n 'details',\n mergeAttrs({ key: `t${index}` }, part('tool')),\n h(\n 'summary',\n part('toolSummary'),\n icon(status === 'running' ? 'spinner' : status === 'error' ? 'warning' : 'check', status === 'running' ? { spin: true } : undefined),\n h('span', part('toolName'), tool.name),\n h('span', part('toolStatus', { status }), words)\n ),\n detail ? h('pre', part('toolBody'), detail) : null\n );\n}\n\nfunction messageView(context: ViewContext, message: ChatMessage, index: number): Child {\n const { part, locale, on, config, ids, tabIndex } = context;\n const side = sideOf(message.role);\n const custom = config.slots?.message?.({ message, index });\n const time = timeText(message.at, locale);\n const body = message.error ?? message.content ?? '';\n\n return h(\n 'div',\n mergeAttrs({ key: String(message.id), id: ids.message(index) }, part('message', { side, role: message.role, error: !!message.error, streaming: !!message.streaming }), {\n role: 'listitem',\n // One tab stop for the whole log; the arrows move within it, so a\n // long thread does not bury the composer behind a hundred tabs.\n tabindex: index === tabIndex ? 0 : -1,\n onFocus: () => on.focusMessage(index)\n }),\n custom !== null && custom !== undefined\n ? content(custom)\n : [\n message.toolCalls?.length ? h('div', mergeAttrs({ key: 'tools' }, part('tools')), ...message.toolCalls.map((tool, i) => toolView(context, tool, i))) : null,\n body || message.streaming\n ? h(\n 'div',\n mergeAttrs({ key: 'bubble' }, part('bubble')),\n body,\n // The caret follows the last character while the answer arrives.\n message.streaming ? h('span', mergeAttrs({ key: 'caret', 'aria-hidden': 'true' }, part('caret'))) : null\n )\n : null,\n message.attachments?.length\n ? h('div', mergeAttrs({ key: 'files' }, part('attachments')), ...message.attachments.map((a, i) => attachmentView(context, a, i, false)))\n : null,\n message.citations?.length\n ? h(\n 'div',\n mergeAttrs({ key: 'cites' }, part('citations')),\n ...message.citations.map((c, i) =>\n c.url\n ? h('a', mergeAttrs({ key: `c${i}`, href: c.url, target: '_blank', rel: 'noreferrer' }, part('citation')), `${i + 1}. ${c.title}`)\n : h('span', mergeAttrs({ key: `c${i}` }, part('citation')), `${i + 1}. ${c.title}`)\n )\n )\n : null,\n time || message.retryable\n ? h(\n 'div',\n mergeAttrs({ key: 'meta' }, part('meta')),\n time ? h('time', part('time'), time) : null,\n message.retryable\n ? h('button', mergeAttrs({ type: 'button' }, part('retry'), { onClick: () => on.retry(message) }), icon('refresh'), locale.chat.retry)\n : null\n )\n : null\n ]\n );\n}\n\nfunction groupView(context: ViewContext, group: ChatGroup): Child {\n const { part, variant } = context;\n const first = group.messages[0]!;\n const side = sideOf(first.role);\n const withAvatar = showsAvatars(variant) && first.role !== 'system';\n const author = first.author ?? (first.role === 'assistant' ? context.config.ariaLabel : undefined);\n\n return h(\n 'div',\n mergeAttrs({ key: `g${group.start}` }, part('group', { side })),\n withAvatar\n ? h(\n 'span',\n mergeAttrs({ key: 'avatar', 'aria-hidden': 'true' }, part('avatar', {})),\n first.avatar ? h('img', { src: first.avatar, alt: '' }) : initialsOf(first)\n )\n : null,\n h(\n 'div',\n mergeAttrs({ key: 'stack' }, part('stack')),\n // The name goes once a run, not once a message: that is what makes\n // a thread read as speech instead of as a list.\n author && first.role !== 'system' ? h('span', mergeAttrs({ key: 'author' }, part('author')), author) : null,\n ...group.messages.map((message, i) => messageView(context, message, group.start + i))\n )\n );\n}\n\nfunction emptyView(context: ViewContext): Child {\n const { part, config, locale, on } = context;\n const custom = config.slots?.empty?.();\n if (custom !== null && custom !== undefined) return h('div', mergeAttrs({ key: 'empty' }, part('empty')), content(custom));\n const suggestions = config.suggestions ?? [];\n return h(\n 'div',\n mergeAttrs({ key: 'empty' }, part('empty')),\n h('p', { key: 'text' }, config.emptyMessage ?? locale.chat.empty),\n suggestions.length\n ? h(\n 'div',\n mergeAttrs({ key: 'suggestions' }, part('suggestions')),\n ...suggestions.map((text, i) => h('button', mergeAttrs({ key: `s${i}`, type: 'button' }, part('suggestion'), { onClick: () => on.suggest(text) }), text))\n )\n : null\n );\n}\n\nfunction typingView(context: ViewContext): Child {\n const { part, config, locale } = context;\n if (!config.typing) return null;\n const words = typeof config.typing === 'string' ? config.typing : locale.chat.typing;\n return h(\n 'div',\n mergeAttrs({ key: 'typing' }, part('typing')),\n h('span', mergeAttrs({ key: 'dots', 'aria-hidden': 'true' }, part('typingDots')), h('span'), h('span'), h('span')),\n words\n );\n}\n\nfunction composerView(context: ViewContext): Child {\n const { part, config, locale, on, ids, refs } = context;\n if (config.readonly) return null;\n const attachments = config.attachments ?? [];\n const empty = !(config.draft ?? '').trim() && attachments.length === 0;\n return h(\n 'div',\n mergeAttrs({ key: 'composer' }, part('composer')),\n attachments.length ? h('div', mergeAttrs({ key: 'staged' }, part('attachments')), ...attachments.map((a, i) => attachmentView(context, a, i, true))) : null,\n h(\n 'div',\n mergeAttrs({ key: 'row' }, part('composerRow')),\n config.allowAttachments\n ? [\n h('input', mergeAttrs({ key: 'file', type: 'file', multiple: true, accept: config.accept }, part('file'), {\n ref: refs.file,\n onChange: (event: Event) => on.filesPicked(Array.from((event.target as HTMLInputElement).files ?? []))\n })),\n h('button', mergeAttrs({ key: 'attach', type: 'button' }, part('attach'), { 'aria-label': locale.chat.attach, disabled: config.disabled, onClick: on.pickFiles }), icon('paperclip'))\n ]\n : null,\n h('textarea', mergeAttrs({ key: 'input', id: ids.input }, part('input'), {\n ref: refs.input,\n rows: 1,\n value: config.draft ?? '',\n placeholder: config.placeholder ?? locale.chat.placeholder,\n disabled: config.disabled,\n 'aria-label': locale.chat.message,\n 'aria-controls': ids.log,\n onInput: (event: Event) => on.draft((event.target as HTMLTextAreaElement).value),\n onKeydown: on.inputKeydown\n })),\n h('button', mergeAttrs({ key: 'send', type: 'button' }, part('send'), { 'aria-label': locale.chat.send, disabled: config.disabled || empty, onClick: on.send }), icon('send'))\n )\n );\n}\n\n/** The thread: the header, the log, the composer — everything but the widget's shell. */\nexport function chatView(context: ViewContext): Child[] {\n const { part, config, locale, messages, ids, on, refs, away, announcement } = context;\n const header = config.slots?.header?.();\n const footer = config.slots?.footer?.();\n const groups = groupMessages(messages);\n\n return [\n header !== null && header !== undefined ? h('div', mergeAttrs({ key: 'header' }, part('header')), content(header)) : null,\n h(\n 'div',\n mergeAttrs({ key: 'log', id: ids.log }, part('log'), {\n ref: refs.log,\n role: 'list',\n 'aria-label': config.ariaLabel ?? locale.chat.conversation,\n tabindex: messages.length ? -1 : 0,\n style: config.height ? { height: config.height } : undefined,\n onKeydown: on.logKeydown,\n onScroll: (event: Event) => on.scrolled(event.target as HTMLElement)\n }),\n messages.length ? groups.map((group) => groupView(context, group)) : emptyView(context),\n typingView(context)\n ),\n // Going back to the newest message when the reader has scrolled off it,\n // which is the one thing an auto-scrolling log must never do for them.\n away && messages.length\n ? h('button', mergeAttrs({ key: 'jump', type: 'button' }, part('jump'), { onClick: on.jump }), icon('chevronDown'), locale.chat.newest)\n : null,\n composerView(context),\n footer !== null && footer !== undefined ? h('div', mergeAttrs({ key: 'footer' }, part('footer')), content(footer)) : null,\n // A message is announced once it has settled: a live region that changes\n // on every token of a stream says nothing anyone can follow.\n h('div', mergeAttrs({ key: 'status', role: 'status', 'aria-live': 'polite' }, part('status')), announcement)\n ];\n}\n"],"mappings":";;;;;;;;;;AAYA,IAAM,QAAQ,MAAc,UAAyB,SAAS,QAAQ,IAAI,GAAG,KAAK;AAClF,IAAM,WAAW,UAA2B,UAAU,QAAQ,UAAU,KAAA,IAAY,OAAO;;AAoC3F,SAAS,SAAS,IAAuB,QAAoC;CACzE,IAAI,OAAO,KAAA,KAAa,OAAO,MAAM,OAAO,KAAA;CAC5C,MAAM,OAAO,cAAc,OAAO,KAAK,IAAI,KAAK,EAAE;CAClD,IAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,GAAG,OAAO,KAAA;CACzC,OAAO,IAAI,KAAK,eAAe,OAAO,MAAM;EAAE,MAAM;EAAW,QAAQ;CAAU,CAAC,CAAC,CAAC,OAAO,IAAI;AACnG;AAEA,SAAS,eAAe,SAAsB,YAA4B,OAAe,WAA2B;CAChH,MAAM,EAAE,MAAM,IAAI,WAAW;CAC7B,MAAM,OAAO,WAAW,WAAW,IAAI;CACvC,MAAM,OAAgB;EAClB,KAAK,WAAW;EAChB,EAAE,QAAQ,KAAK,gBAAgB,GAAG,WAAW,IAAI;EACjD,OAAO,EAAE,QAAQ,KAAK,gBAAgB,GAAG,IAAI,IAAI;EACjD,YACM,EACI,UACA,WAAW,EAAE,MAAM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K,aAAa,GAAG,OAAO,KAAK,MAAM,IACpI;EACN,aAAa,OAAO;EACpB,WAAW,QAAQ,WAAW,KAAA,IAAY,EAAE,OAAO,WAAW,EAAE,KAAK,SAAS,GAAG,KAAK,QAAQ,CAAC,GAAG,QAAQ,MAAM,CAAC,IAAI;EAGrH,EAAE,OAAO,WAAW;GAAE,KAAK;GAAU,MAAM;GAAU,aAAa;EAAS,GAAG,KAAK,QAAQ,CAAC,GAAG,YAAY;CAC/G;AACJ"}
1
+ {"version":3,"file":"chat.js","names":[],"sources":["../../src/render/chat.ts"],"sourcesContent":["import { formatMessage, type Locale } from '@vitral/core';\nimport { h, iconNode, mergeAttrs, type Child, type Props } from '@vitral/dom';\nimport { getIcon } from '@vitral/icons';\nimport { formatSize, groupMessages, initialsOf, showsAvatars, sideOf, type ChatGroup } from '../engine/state';\nimport type { ChatAttachment, ChatConfig, ChatMessage, ChatMessageAction, ChatToolCall, ChatVariant, Content } from '../engine/types';\n\n/**\n * The conversation as plain objects: a scrolling log of runs of messages and\n * the box that adds to it. What is drawn is decided here; what happens when it\n * is pressed is the handle's.\n */\n\nconst icon = (name: string, props?: Props): Child => iconNode(getIcon(name), props);\nconst content = (value: Content): Child => (value === null || value === undefined ? null : value);\n\nexport interface ChatActions {\n send: () => void;\n draft: (text: string) => void;\n inputKeydown: (event: KeyboardEvent) => void;\n logKeydown: (event: KeyboardEvent) => void;\n focusMessage: (index: number) => void;\n retry: (message: ChatMessage) => void;\n messageAction: (action: ChatMessageAction, message: ChatMessage) => void;\n suggest: (text: string) => void;\n pickFiles: () => void;\n filesPicked: (files: File[]) => void;\n detach: (attachment: ChatAttachment, index: number) => void;\n scrolled: (element: HTMLElement) => void;\n jump: () => void;\n toggleOpen: () => void;\n}\n\nexport interface ViewContext {\n config: ChatConfig;\n locale: Locale;\n variant: ChatVariant;\n messages: ChatMessage[];\n ids: { log: string; input: string; message: (index: number) => string };\n part: (name: string, state?: unknown) => Props;\n /** The message that holds the log's tab stop. */\n tabIndex: number;\n /** The reader has scrolled away from the newest message. */\n away: boolean;\n announcement: string;\n /** The message whose text was just copied, which shows a tick for a moment. */\n copied?: string | number | null;\n on: ChatActions;\n /** Keeps the log and the composer reachable from the handle. */\n refs: { log: (el: Element | null) => void; input: (el: Element | null) => void; file: (el: Element | null) => void };\n}\n\n/** The time a message carries, in the reader's own format. */\nfunction timeText(at: ChatMessage['at'], locale: Locale): string | undefined {\n if (at === undefined || at === null) return undefined;\n const date = at instanceof Date ? at : new Date(at);\n if (Number.isNaN(date.getTime())) return undefined;\n return new Intl.DateTimeFormat(locale.code, { hour: '2-digit', minute: '2-digit' }).format(date);\n}\n\nfunction attachmentView(context: ViewContext, attachment: ChatAttachment, index: number, removable: boolean): Child {\n const { part, on, locale } = context;\n const size = formatSize(attachment.size);\n const body: Child[] = [\n icon('paperclip'),\n h('span', part('attachmentName'), attachment.name),\n size ? h('span', part('attachmentSize'), size) : null,\n removable\n ? h(\n 'button',\n mergeAttrs({ type: 'button' }, part('attachmentRemove'), {\n 'aria-label': formatMessage(locale.chat.removeAttachment, { name: attachment.name }),\n onClick: () => on.detach(attachment, index)\n }),\n icon('close')\n )\n : null\n ];\n // A file that has somewhere to go is a link; one that has not is a chip.\n return attachment.url && !removable\n ? h('a', mergeAttrs({ key: `a${index}`, href: attachment.url, target: '_blank', rel: 'noreferrer' }, part('attachment')), ...body)\n : h('span', mergeAttrs({ key: `a${index}` }, part('attachment')), ...body);\n}\n\nfunction toolView(context: ViewContext, tool: ChatToolCall, index: number): Child {\n const { part, locale } = context;\n const status = tool.status ?? 'done';\n const words = status === 'running' ? locale.chat.toolRunning : status === 'error' ? locale.chat.toolFailed : locale.chat.toolDone;\n const detail = [tool.input, tool.output].filter(Boolean).join('\\n\\n');\n return h(\n 'details',\n mergeAttrs({ key: `t${index}` }, part('tool')),\n h(\n 'summary',\n part('toolSummary'),\n icon(status === 'running' ? 'spinner' : status === 'error' ? 'warning' : 'check', status === 'running' ? { spin: true } : undefined),\n h('span', part('toolName'), tool.name),\n h('span', part('toolStatus', { status }), words)\n ),\n detail ? h('pre', part('toolBody'), detail) : null\n );\n}\n\n/** The actions a message shows: the built-in ones filled in, and only those meant for its speaker. */\nexport function actionsFor(config: ChatConfig, locale: Locale, message: ChatMessage): ChatMessageAction[] {\n if (message.streaming || message.error) return [];\n return (config.messageActions ?? [])\n .map((action): ChatMessageAction => {\n const given = typeof action === 'string' ? { id: action } : action;\n if (given.id === 'copy') return { icon: 'copy', label: locale.chat.copy, ...given };\n if (given.id === 'regenerate') return { icon: 'refresh', label: locale.chat.regenerate, ...given };\n // A rating is a toggle, pressed while the message carries it as its feedback.\n if (given.id === 'like') return { icon: 'thumbsUp', label: locale.chat.like, pressed: (m: ChatMessage) => m.feedback === 'like', ...given };\n if (given.id === 'dislike') return { icon: 'thumbsDown', label: locale.chat.dislike, pressed: (m: ChatMessage) => m.feedback === 'dislike', ...given };\n return given;\n })\n .filter((action) => (action.roles ?? ['assistant']).includes(message.role) && (action.id !== 'copy' || !!message.content));\n}\n\nfunction actionView(context: ViewContext, action: ChatMessageAction, message: ChatMessage): Child {\n const { part, on, locale } = context;\n const copied = action.id === 'copy' && context.copied === message.id;\n const label = copied ? locale.chat.copied : (action.label ?? action.id);\n const pressed = typeof action.pressed === 'function' ? action.pressed(message) : action.pressed;\n return h(\n 'button',\n mergeAttrs({ key: `a-${action.id}`, type: 'button' }, part('messageAction', { pressed: !!pressed, copied }), {\n 'aria-label': action.showLabel ? undefined : label,\n title: action.showLabel ? undefined : label,\n 'aria-pressed': pressed === undefined ? undefined : pressed ? 'true' : 'false',\n onClick: () => on.messageAction(action, message)\n }),\n action.icon ? icon(copied ? 'check' : action.icon) : null,\n action.showLabel || !action.icon ? label : null\n );\n}\n\nfunction messageView(context: ViewContext, message: ChatMessage, index: number): Child {\n const { part, locale, on, config, ids, tabIndex } = context;\n const side = sideOf(message.role);\n const custom = config.slots?.message?.({ message, index });\n const time = timeText(message.at, locale);\n const body = message.error ?? message.content ?? '';\n const actions = actionsFor(config, locale, message);\n\n return h(\n 'div',\n mergeAttrs({ key: String(message.id), id: ids.message(index) }, part('message', { side, role: message.role, error: !!message.error, streaming: !!message.streaming }), {\n role: 'listitem',\n // One tab stop for the whole log; the arrows move within it, so a\n // long thread does not bury the composer behind a hundred tabs.\n tabindex: index === tabIndex ? 0 : -1,\n onFocus: () => on.focusMessage(index)\n }),\n custom !== null && custom !== undefined\n ? content(custom)\n : [\n message.toolCalls?.length ? h('div', mergeAttrs({ key: 'tools' }, part('tools')), ...message.toolCalls.map((tool, i) => toolView(context, tool, i))) : null,\n body || message.streaming\n ? h(\n 'div',\n mergeAttrs({ key: 'bubble' }, part('bubble')),\n body,\n // The caret follows the last character while the answer arrives.\n message.streaming ? h('span', mergeAttrs({ key: 'caret', 'aria-hidden': 'true' }, part('caret'))) : null\n )\n : null,\n message.attachments?.length\n ? h('div', mergeAttrs({ key: 'files' }, part('attachments')), ...message.attachments.map((a, i) => attachmentView(context, a, i, false)))\n : null,\n message.citations?.length\n ? h(\n 'div',\n mergeAttrs({ key: 'cites' }, part('citations')),\n ...message.citations.map((c, i) =>\n c.url\n ? h('a', mergeAttrs({ key: `c${i}`, href: c.url, target: '_blank', rel: 'noreferrer' }, part('citation')), `${i + 1}. ${c.title}`)\n : h('span', mergeAttrs({ key: `c${i}` }, part('citation')), `${i + 1}. ${c.title}`)\n )\n )\n : null,\n time || message.retryable || actions.length\n ? h(\n 'div',\n mergeAttrs({ key: 'meta' }, part('meta')),\n time ? h('time', mergeAttrs({ key: 'time' }, part('time')), time) : null,\n message.retryable\n ? h('button', mergeAttrs({ key: 'retry', type: 'button' }, part('retry'), { onClick: () => on.retry(message) }), icon('refresh'), locale.chat.retry)\n : null,\n actions.length ? h('span', mergeAttrs({ key: 'actions' }, part('messageActions')), ...actions.map((a) => actionView(context, a, message))) : null\n )\n : null\n ]\n );\n}\n\nfunction groupView(context: ViewContext, group: ChatGroup): Child {\n const { part, variant } = context;\n const first = group.messages[0]!;\n const side = sideOf(first.role);\n const withAvatar = showsAvatars(variant) && first.role !== 'system';\n const author = first.author ?? (first.role === 'assistant' ? context.config.ariaLabel : undefined);\n\n return h(\n 'div',\n mergeAttrs({ key: `g${group.start}` }, part('group', { side })),\n withAvatar\n ? h(\n 'span',\n mergeAttrs({ key: 'avatar', 'aria-hidden': 'true' }, part('avatar', {})),\n first.avatar ? h('img', { src: first.avatar, alt: '' }) : initialsOf(first)\n )\n : null,\n h(\n 'div',\n mergeAttrs({ key: 'stack' }, part('stack')),\n // The name goes once a run, not once a message: that is what makes\n // a thread read as speech instead of as a list.\n author && first.role !== 'system' ? h('span', mergeAttrs({ key: 'author' }, part('author')), author) : null,\n ...group.messages.map((message, i) => messageView(context, message, group.start + i))\n )\n );\n}\n\nfunction emptyView(context: ViewContext): Child {\n const { part, config, locale, on } = context;\n const custom = config.slots?.empty?.();\n if (custom !== null && custom !== undefined) return h('div', mergeAttrs({ key: 'empty' }, part('empty')), content(custom));\n const suggestions = config.suggestions ?? [];\n return h(\n 'div',\n mergeAttrs({ key: 'empty' }, part('empty')),\n h('p', { key: 'text' }, config.emptyMessage ?? locale.chat.empty),\n suggestions.length\n ? h(\n 'div',\n mergeAttrs({ key: 'suggestions' }, part('suggestions')),\n ...suggestions.map((text, i) => h('button', mergeAttrs({ key: `s${i}`, type: 'button' }, part('suggestion'), { onClick: () => on.suggest(text) }), text))\n )\n : null\n );\n}\n\nfunction typingView(context: ViewContext): Child {\n const { part, config, locale } = context;\n if (!config.typing) return null;\n const words = typeof config.typing === 'string' ? config.typing : locale.chat.typing;\n return h(\n 'div',\n mergeAttrs({ key: 'typing' }, part('typing')),\n h('span', mergeAttrs({ key: 'dots', 'aria-hidden': 'true' }, part('typingDots')), h('span'), h('span'), h('span')),\n words\n );\n}\n\nfunction composerView(context: ViewContext): Child {\n const { part, config, locale, on, ids, refs } = context;\n if (config.readonly) return null;\n const attachments = config.attachments ?? [];\n const empty = !(config.draft ?? '').trim() && attachments.length === 0;\n return h(\n 'div',\n mergeAttrs({ key: 'composer' }, part('composer')),\n attachments.length ? h('div', mergeAttrs({ key: 'staged' }, part('attachments')), ...attachments.map((a, i) => attachmentView(context, a, i, true))) : null,\n h(\n 'div',\n mergeAttrs({ key: 'row' }, part('composerRow')),\n config.allowAttachments\n ? [\n h('input', mergeAttrs({ key: 'file', type: 'file', multiple: true, accept: config.accept }, part('file'), {\n ref: refs.file,\n onChange: (event: Event) => on.filesPicked(Array.from((event.target as HTMLInputElement).files ?? []))\n })),\n h('button', mergeAttrs({ key: 'attach', type: 'button' }, part('attach'), { 'aria-label': locale.chat.attach, disabled: config.disabled, onClick: on.pickFiles }), icon('paperclip'))\n ]\n : null,\n h('textarea', mergeAttrs({ key: 'input', id: ids.input }, part('input'), {\n ref: refs.input,\n rows: 1,\n value: config.draft ?? '',\n placeholder: config.placeholder ?? locale.chat.placeholder,\n disabled: config.disabled,\n 'aria-label': locale.chat.message,\n 'aria-controls': ids.log,\n onInput: (event: Event) => on.draft((event.target as HTMLTextAreaElement).value),\n onKeydown: on.inputKeydown\n })),\n h('button', mergeAttrs({ key: 'send', type: 'button' }, part('send'), { 'aria-label': locale.chat.send, disabled: config.disabled || empty, onClick: on.send }), icon('send'))\n )\n );\n}\n\n/** The thread: the header, the log, the composer — everything but the widget's shell. */\nexport function chatView(context: ViewContext): Child[] {\n const { part, config, locale, messages, ids, on, refs, away, announcement } = context;\n const header = config.slots?.header?.();\n const footer = config.slots?.footer?.();\n const groups = groupMessages(messages);\n\n return [\n header !== null && header !== undefined ? h('div', mergeAttrs({ key: 'header' }, part('header')), content(header)) : null,\n h(\n 'div',\n mergeAttrs({ key: 'log', id: ids.log }, part('log'), {\n ref: refs.log,\n role: 'list',\n 'aria-label': config.ariaLabel ?? locale.chat.conversation,\n tabindex: messages.length ? -1 : 0,\n style: config.height ? { height: config.height } : undefined,\n onKeydown: on.logKeydown,\n onScroll: (event: Event) => on.scrolled(event.target as HTMLElement)\n }),\n messages.length ? groups.map((group) => groupView(context, group)) : emptyView(context),\n typingView(context)\n ),\n // Going back to the newest message when the reader has scrolled off it,\n // which is the one thing an auto-scrolling log must never do for them.\n away && messages.length\n ? h('button', mergeAttrs({ key: 'jump', type: 'button' }, part('jump'), { onClick: on.jump }), icon('chevronDown'), locale.chat.newest)\n : null,\n composerView(context),\n footer !== null && footer !== undefined ? h('div', mergeAttrs({ key: 'footer' }, part('footer')), content(footer)) : null,\n // A message is announced once it has settled: a live region that changes\n // on every token of a stream says nothing anyone can follow.\n h('div', mergeAttrs({ key: 'status', role: 'status', 'aria-live': 'polite' }, part('status')), announcement)\n ];\n}\n"],"mappings":";;;;;;;;;;AAYA,IAAM,QAAQ,MAAc,UAAyB,SAAS,QAAQ,IAAI,GAAG,KAAK;AAClF,IAAM,WAAW,UAA2B,UAAU,QAAQ,UAAU,KAAA,IAAY,OAAO;;AAuC3F,SAAS,SAAS,IAAuB,QAAoC;CACzE,IAAI,OAAO,KAAA,KAAa,OAAO,MAAM,OAAO,KAAA;CAC5C,MAAM,OAAO,cAAc,OAAO,KAAK,IAAI,KAAK,EAAE;CAClD,IAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,GAAG,OAAO,KAAA;CACzC,OAAO,IAAI,KAAK,eAAe,OAAO,MAAM;EAAE,MAAM;EAAW,QAAQ;CAAU,CAAC,CAAC,CAAC,OAAO,IAAI;AACnG;AAEA,SAAS,eAAe,SAAsB,YAA4B,OAAe,WAA2B;CAChH,MAAM,EAAE,MAAM,IAAI,WAAW;CAC7B,MAAM,OAAO,WAAW,WAAW,IAAI;CACvC,MAAM,OAAgB;EAClB,KAAK,WAAW;EAChB,EAAE,QAAQ,KAAK,gBAAgB,GAAG,WAAW,IAAI;EACjD,OAAO,EAAE,QAAQ,KAAK,gBAAgB,GAAG,IAAI,IAAI;EACjD,YACM,EACI,UACA,WAAW,EAAE,MAAM,SAAS,GAAG,KAAK,kBAAkB,GAAG;GACrD,cAAc,cAAc,OAAO,KAAK,kBAAkB,EAAE,MAAM,WAAW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V,MAAM;GACN,cAAc,OAAO,aAAa,OAAO,KAAK;GAC9C,UAAU,SAAS,SAAS,KAAK;GACjC,OAAO,OAAO,SAAS,EAAE,QAAQ,OAAO,OAAO,IAAI,KAAA;GACnD,WAAW,GAAG;GACd,WAAW,UAAiB,GAAG,SAAS,MAAM,MAAqB;EACvE,CAAC,GACD,SAAS,SAAS,OAAO,KAAK,UAAU,UAAU,SAAS,KAAK,CAAC,IAAI,UAAU,OAAO,GACtF,WAAW,OAAO,CACtB;EAGA,QAAQ,SAAS,SACX,EAAE,UAAU,WAAW;GAAE,KAAK;GAAQ,MAAM;EAAS,GAAG,KAAK,MAAM,GAAG,EAAE,SAAS,GAAG,KAAK,CAAC,GAAG,KAAK,aAAa,GAAG,OAAO,KAAK,MAAM,IACpI;EACN,aAAa,OAAO;EACpB,WAAW,QAAQ,WAAW,KAAA,IAAY,EAAE,OAAO,WAAW,EAAE,KAAK,SAAS,GAAG,KAAK,QAAQ,CAAC,GAAG,QAAQ,MAAM,CAAC,IAAI;EAGrH,EAAE,OAAO,WAAW;GAAE,KAAK;GAAU,MAAM;GAAU,aAAa;EAAS,GAAG,KAAK,QAAQ,CAAC,GAAG,YAAY;CAC/G;AACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitral/chat",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Framework-free chat for Vitral: the engine (messages, grouping, streaming, the composer) and a DOM renderer with roving focus and live announcements, which the Vue, React and Angular components wrap.",
5
5
  "keywords": [
6
6
  "vitral",
@@ -45,11 +45,11 @@
45
45
  "access": "public"
46
46
  },
47
47
  "dependencies": {
48
- "@vitral/controls": "0.2.4",
49
- "@vitral/core": "0.2.4",
50
- "@vitral/dom": "0.2.4",
51
- "@vitral/styles": "0.2.4",
52
- "@vitral/icons": "0.2.4"
48
+ "@vitral/controls": "0.2.6",
49
+ "@vitral/core": "0.2.6",
50
+ "@vitral/dom": "0.2.6",
51
+ "@vitral/icons": "0.2.6",
52
+ "@vitral/styles": "0.2.6"
53
53
  },
54
54
  "scripts": {
55
55
  "build": "vite build && tsc -p tsconfig.build.json"