@burtson-labs/ui 0.5.1 → 0.7.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.
Files changed (35) hide show
  1. package/README.md +1 -1
  2. package/dist/components/composer.d.ts +30 -0
  3. package/dist/components/composer.js +95 -0
  4. package/dist/components/composer.js.map +1 -0
  5. package/dist/components/conversation.d.ts +14 -0
  6. package/dist/components/conversation.js +78 -0
  7. package/dist/components/conversation.js.map +1 -0
  8. package/dist/components/copy-button.d.ts +15 -0
  9. package/dist/components/copy-button.js +47 -0
  10. package/dist/components/copy-button.js.map +1 -0
  11. package/dist/components/markdown.d.ts +33 -0
  12. package/dist/components/markdown.js +177 -0
  13. package/dist/components/markdown.js.map +1 -0
  14. package/dist/components/message.d.ts +21 -0
  15. package/dist/components/message.js +56 -0
  16. package/dist/components/message.js.map +1 -0
  17. package/dist/components/reasoning.d.ts +14 -0
  18. package/dist/components/reasoning.js +61 -0
  19. package/dist/components/reasoning.js.map +1 -0
  20. package/dist/components/secret-input.d.ts +11 -0
  21. package/dist/components/secret-input.js +40 -0
  22. package/dist/components/secret-input.js.map +1 -0
  23. package/dist/components/slider.d.ts +15 -0
  24. package/dist/components/slider.js +31 -0
  25. package/dist/components/slider.js.map +1 -0
  26. package/dist/components/toaster.d.ts +20 -0
  27. package/dist/components/toaster.js +61 -0
  28. package/dist/components/toaster.js.map +1 -0
  29. package/dist/components/tool-call.d.ts +32 -0
  30. package/dist/components/tool-call.js +152 -0
  31. package/dist/components/tool-call.js.map +1 -0
  32. package/dist/index.d.ts +10 -0
  33. package/dist/index.js +13 -3
  34. package/dist/styles.css +1 -1
  35. package/package.json +1 -1
package/README.md CHANGED
@@ -58,7 +58,7 @@ npx shadcn@latest add https://ui.burtson.ai/r/button.json
58
58
 
59
59
  ## <picture><source media="(prefers-color-scheme: dark)" srcset="https://icons.burtson.ai/svg-white/panel-grid.svg"/><img src="https://icons.burtson.ai/svg-black/panel-grid.svg" align="center" alt=""/></picture> Components
60
60
 
61
- Accordion · Alert · Alert Dialog · App Shell · Avatar · Badge · Breadcrumb · Button · Card · Checkbox · Collapsible · Combobox · Command · Dialog · Dropdown Menu · Empty State · Field · Icon Button · Input · Kbd · Label · Navigation Menu · Page Header · Pagination · Popover · Progress · Radio Group · Scroll Area · Select · Separator · Sheet · Skeleton · Spinner · Stat Card · Status · Steps · Switch · Table · Tabs · Textarea · Toast · Toolbar · Tooltip
61
+ Accordion · Alert · Alert Dialog · App Shell · Avatar · Badge · Breadcrumb · Button · Card · Checkbox · Collapsible · Combobox · Command · Copy Button · Dialog · Dropdown Menu · Empty State · Field · Icon Button · Input · Kbd · Label · Navigation Menu · Page Header · Pagination · Popover · Progress · Radio Group · Reasoning · Scroll Area · Secret Input · Select · Separator · Sheet · Skeleton · Slider · Spinner · Stat Card · Status · Steps · Switch · Table · Tabs · Textarea · Toast · Toaster · Toolbar · Tooltip
62
62
 
63
63
  Live previews and code for each one are at [ui.burtson.ai](https://ui.burtson.ai/docs/components/button).
64
64
 
@@ -0,0 +1,30 @@
1
+ import * as React from 'react';
2
+ export interface ComposerProps extends Omit<React.ComponentProps<'form'>, 'onSubmit' | 'onChange'> {
3
+ /** Called with the trimmed text; the composer clears itself afterwards. */
4
+ onSubmit: (text: string) => void;
5
+ /** Controlled value; leave out to let the composer keep its own. */
6
+ value?: string;
7
+ onValueChange?: (value: string) => void;
8
+ /** While a reply streams, the send button becomes Stop. */
9
+ streaming?: boolean;
10
+ onStop?: () => void;
11
+ disabled?: boolean;
12
+ placeholder?: string;
13
+ /** Attachment chips or a file button, shown under the text. */
14
+ attachments?: React.ReactNode;
15
+ /** Extra controls left of the send button (model picker, tools). */
16
+ actions?: React.ReactNode;
17
+ label?: string;
18
+ }
19
+ /**
20
+ * The message box: grows with its text, Enter sends, Shift+Enter adds a
21
+ * line, and it never sends mid-composition (IME input).
22
+ */
23
+ declare function Composer({ onSubmit, value: controlled, onValueChange, streaming, onStop, disabled, placeholder, attachments, actions, label, className, ...props }: ComposerProps): React.JSX.Element;
24
+ export interface SuggestionsProps extends Omit<React.ComponentProps<'div'>, 'onSelect'> {
25
+ items: string[];
26
+ onSelect: (item: string) => void;
27
+ }
28
+ /** Starter prompts as chips. */
29
+ declare function Suggestions({ items, onSelect, className, ...props }: SuggestionsProps): React.JSX.Element;
30
+ export { Composer, Suggestions };
@@ -0,0 +1,95 @@
1
+ import { cn } from "../lib/utils.js";
2
+ import { Button } from "./button.js";
3
+ import * as React from "react";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ import ArrowUp from "@burtson-labs/icons/react/arrow-up";
6
+ import Square from "@burtson-labs/icons/react/square";
7
+ //#region src/components/composer.tsx
8
+ /**
9
+ * The message box: grows with its text, Enter sends, Shift+Enter adds a
10
+ * line, and it never sends mid-composition (IME input).
11
+ */
12
+ function Composer({ onSubmit, value: controlled, onValueChange, streaming = false, onStop, disabled = false, placeholder = "Ask anything…", attachments, actions, label = "Message", className, ...props }) {
13
+ const [own, setOwn] = React.useState("");
14
+ const value = controlled ?? own;
15
+ const setValue = (v) => {
16
+ if (controlled === void 0) setOwn(v);
17
+ onValueChange?.(v);
18
+ };
19
+ const canSend = !disabled && !streaming && value.trim().length > 0;
20
+ const send = () => {
21
+ if (!canSend) return;
22
+ onSubmit(value.trim());
23
+ setValue("");
24
+ };
25
+ return /* @__PURE__ */ jsxs("form", {
26
+ "data-slot": "composer",
27
+ onSubmit: (e) => {
28
+ e.preventDefault();
29
+ send();
30
+ },
31
+ className: cn("grid gap-2 rounded-lg border border-input bg-surface p-2 shadow-xs transition-[border-color,box-shadow] focus-within:border-brand focus-within:ring-[3px] focus-within:ring-ring/15 dark:bg-surface-raised", disabled && "opacity-60", className),
32
+ ...props,
33
+ children: [
34
+ /* @__PURE__ */ jsx("textarea", {
35
+ "aria-label": label,
36
+ rows: 1,
37
+ value,
38
+ disabled,
39
+ placeholder,
40
+ onChange: (e) => setValue(e.target.value),
41
+ onKeyDown: (e) => {
42
+ if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) {
43
+ e.preventDefault();
44
+ send();
45
+ }
46
+ },
47
+ className: "field-sizing-content max-h-48 min-h-9 w-full resize-none bg-transparent px-2 py-1.5 text-sm leading-6 outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed"
48
+ }),
49
+ attachments && /* @__PURE__ */ jsx("div", {
50
+ className: "flex flex-wrap gap-1.5 px-1",
51
+ children: attachments
52
+ }),
53
+ /* @__PURE__ */ jsxs("div", {
54
+ className: "flex items-center gap-1",
55
+ children: [actions, /* @__PURE__ */ jsx("div", {
56
+ className: "ml-auto",
57
+ children: streaming ? /* @__PURE__ */ jsx(Button, {
58
+ type: "button",
59
+ size: "icon-sm",
60
+ variant: "secondary",
61
+ "aria-label": "Stop",
62
+ onClick: onStop,
63
+ children: /* @__PURE__ */ jsx(Square, { className: "fill-current" })
64
+ }) : /* @__PURE__ */ jsx(Button, {
65
+ type: "submit",
66
+ size: "icon-sm",
67
+ "aria-label": "Send",
68
+ disabled: !canSend,
69
+ children: /* @__PURE__ */ jsx(ArrowUp, {})
70
+ })
71
+ })]
72
+ })
73
+ ]
74
+ });
75
+ }
76
+ /** Starter prompts as chips. */
77
+ function Suggestions({ items, onSelect, className, ...props }) {
78
+ return /* @__PURE__ */ jsx("div", {
79
+ "data-slot": "suggestions",
80
+ role: "group",
81
+ "aria-label": "Suggestions",
82
+ className: cn("flex flex-wrap gap-2", className),
83
+ ...props,
84
+ children: items.map((item) => /* @__PURE__ */ jsx("button", {
85
+ type: "button",
86
+ onClick: () => onSelect(item),
87
+ className: "animate-in rounded-full border border-border-strong bg-surface px-3 py-1.5 text-[13px] text-foreground outline-none transition-colors hover:border-brand/40 hover:bg-brand-soft hover:text-brand-soft-foreground focus-visible:ring-[3px] focus-visible:ring-ring/20",
88
+ children: item
89
+ }, item))
90
+ });
91
+ }
92
+ //#endregion
93
+ export { Composer, Suggestions };
94
+
95
+ //# sourceMappingURL=composer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composer.js","names":[],"sources":["../../src/components/composer.tsx"],"sourcesContent":["import ArrowUp from '@burtson-labs/icons/react/arrow-up';\nimport Square from '@burtson-labs/icons/react/square';\nimport * as React from 'react';\n\nimport { cn } from '../lib/utils';\n\nimport { Button } from './button';\n\nexport interface ComposerProps extends Omit<React.ComponentProps<'form'>, 'onSubmit' | 'onChange'> {\n /** Called with the trimmed text; the composer clears itself afterwards. */\n onSubmit: (text: string) => void;\n /** Controlled value; leave out to let the composer keep its own. */\n value?: string;\n onValueChange?: (value: string) => void;\n /** While a reply streams, the send button becomes Stop. */\n streaming?: boolean;\n onStop?: () => void;\n disabled?: boolean;\n placeholder?: string;\n /** Attachment chips or a file button, shown under the text. */\n attachments?: React.ReactNode;\n /** Extra controls left of the send button (model picker, tools). */\n actions?: React.ReactNode;\n label?: string;\n}\n\n/**\n * The message box: grows with its text, Enter sends, Shift+Enter adds a\n * line, and it never sends mid-composition (IME input).\n */\nfunction Composer({\n onSubmit,\n value: controlled,\n onValueChange,\n streaming = false,\n onStop,\n disabled = false,\n placeholder = 'Ask anything…',\n attachments,\n actions,\n label = 'Message',\n className,\n ...props\n}: ComposerProps) {\n const [own, setOwn] = React.useState('');\n const value = controlled ?? own;\n const setValue = (v: string) => {\n if (controlled === undefined) setOwn(v);\n onValueChange?.(v);\n };\n const canSend = !disabled && !streaming && value.trim().length > 0;\n const send = () => {\n if (!canSend) return;\n onSubmit(value.trim());\n setValue('');\n };\n\n return (\n <form\n data-slot=\"composer\"\n onSubmit={(e) => {\n e.preventDefault();\n send();\n }}\n className={cn(\n 'grid gap-2 rounded-lg border border-input bg-surface p-2 shadow-xs transition-[border-color,box-shadow] focus-within:border-brand focus-within:ring-[3px] focus-within:ring-ring/15 dark:bg-surface-raised',\n disabled && 'opacity-60',\n className,\n )}\n {...props}\n >\n <textarea\n aria-label={label}\n rows={1}\n value={value}\n disabled={disabled}\n placeholder={placeholder}\n onChange={(e) => setValue(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === 'Enter' && !e.shiftKey && !e.nativeEvent.isComposing) {\n e.preventDefault();\n send();\n }\n }}\n className=\"field-sizing-content max-h-48 min-h-9 w-full resize-none bg-transparent px-2 py-1.5 text-sm leading-6 outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed\"\n />\n {attachments && <div className=\"flex flex-wrap gap-1.5 px-1\">{attachments}</div>}\n <div className=\"flex items-center gap-1\">\n {actions}\n <div className=\"ml-auto\">\n {streaming ? (\n <Button\n type=\"button\"\n size=\"icon-sm\"\n variant=\"secondary\"\n aria-label=\"Stop\"\n onClick={onStop}\n >\n <Square className=\"fill-current\" />\n </Button>\n ) : (\n <Button type=\"submit\" size=\"icon-sm\" aria-label=\"Send\" disabled={!canSend}>\n <ArrowUp />\n </Button>\n )}\n </div>\n </div>\n </form>\n );\n}\n\nexport interface SuggestionsProps extends Omit<React.ComponentProps<'div'>, 'onSelect'> {\n items: string[];\n onSelect: (item: string) => void;\n}\n\n/** Starter prompts as chips. */\nfunction Suggestions({ items, onSelect, className, ...props }: SuggestionsProps) {\n return (\n <div\n data-slot=\"suggestions\"\n role=\"group\"\n aria-label=\"Suggestions\"\n className={cn('flex flex-wrap gap-2', className)}\n {...props}\n >\n {items.map((item) => (\n <button\n key={item}\n type=\"button\"\n onClick={() => onSelect(item)}\n className=\"animate-in rounded-full border border-border-strong bg-surface px-3 py-1.5 text-[13px] text-foreground outline-none transition-colors hover:border-brand/40 hover:bg-brand-soft hover:text-brand-soft-foreground focus-visible:ring-[3px] focus-visible:ring-ring/20\"\n >\n {item}\n </button>\n ))}\n </div>\n );\n}\n\nexport { Composer, Suggestions };\n"],"mappings":";;;;;;;;;;;AA8BA,SAAS,SAAS,EAChB,UACA,OAAO,YACP,eACA,YAAY,OACZ,QACA,WAAW,OACX,cAAc,iBACd,aACA,SACA,QAAQ,WACR,WACA,GAAG,SACa;CAChB,MAAM,CAAC,KAAK,UAAU,MAAM,SAAS,EAAE;CACvC,MAAM,QAAQ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W,GAAG,wBAAwB,SAAS;EAC/C,GAAI;EAEH,UAAA,MAAM,KAAK,SACV,oBAAC,UAAD;GAEE,MAAK;GACL,eAAe,SAAS,IAAI;GAC5B,WAAU;GAET,UAAA;EACK,GAND,IAMC,CACT;CACE,CAAA;AAET"}
@@ -0,0 +1,14 @@
1
+ import * as React from 'react';
2
+ export interface ConversationProps extends React.ComponentProps<'div'> {
3
+ /** Shown instead of the messages when there are none. */
4
+ empty?: React.ReactNode;
5
+ /** Accessible name for the message log. */
6
+ label?: string;
7
+ }
8
+ /**
9
+ * A scrolling message log that stays pinned to the newest message while it
10
+ * streams, unless the reader has scrolled up; then a "Jump to latest" button
11
+ * appears instead of yanking them back down.
12
+ */
13
+ declare function Conversation({ children, empty, label, className, ...props }: ConversationProps): React.JSX.Element;
14
+ export { Conversation };
@@ -0,0 +1,78 @@
1
+ import { cn } from "../lib/utils.js";
2
+ import * as React from "react";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ import ArrowDown from "@burtson-labs/icons/react/arrow-down";
5
+ //#region src/components/conversation.tsx
6
+ /**
7
+ * A scrolling message log that stays pinned to the newest message while it
8
+ * streams, unless the reader has scrolled up; then a "Jump to latest" button
9
+ * appears instead of yanking them back down.
10
+ */
11
+ function Conversation({ children, empty, label = "Conversation", className, ...props }) {
12
+ const scroller = React.useRef(null);
13
+ const content = React.useRef(null);
14
+ const pinned = React.useRef(true);
15
+ const [atBottom, setAtBottom] = React.useState(true);
16
+ const hasMessages = React.Children.toArray(children).length > 0;
17
+ const scrollToBottom = React.useCallback((behavior = "auto") => {
18
+ const el = scroller.current;
19
+ if (!el) return;
20
+ if (typeof el.scrollTo === "function") el.scrollTo({
21
+ top: el.scrollHeight,
22
+ behavior
23
+ });
24
+ else el.scrollTop = el.scrollHeight;
25
+ }, []);
26
+ React.useEffect(() => {
27
+ const el = content.current;
28
+ if (!el) return;
29
+ const ro = new ResizeObserver(() => {
30
+ if (pinned.current) scrollToBottom();
31
+ });
32
+ ro.observe(el);
33
+ return () => ro.disconnect();
34
+ }, [scrollToBottom]);
35
+ React.useEffect(() => {
36
+ if (pinned.current) scrollToBottom();
37
+ }, [children, scrollToBottom]);
38
+ const onScroll = () => {
39
+ const el = scroller.current;
40
+ if (!el) return;
41
+ const bottom = el.scrollHeight - el.scrollTop - el.clientHeight < 32;
42
+ pinned.current = bottom;
43
+ setAtBottom(bottom);
44
+ };
45
+ return /* @__PURE__ */ jsxs("div", {
46
+ "data-slot": "conversation",
47
+ className: cn("relative min-h-0", className),
48
+ ...props,
49
+ children: [/* @__PURE__ */ jsx("div", {
50
+ ref: scroller,
51
+ role: "log",
52
+ "aria-label": label,
53
+ "aria-live": "polite",
54
+ "aria-relevant": "additions text",
55
+ tabIndex: 0,
56
+ onScroll,
57
+ className: "size-full overflow-y-auto outline-none focus-visible:ring-[3px] focus-visible:ring-ring/20",
58
+ children: /* @__PURE__ */ jsx("div", {
59
+ ref: content,
60
+ className: "grid gap-5 p-4",
61
+ children: hasMessages ? children : empty
62
+ })
63
+ }), !atBottom && /* @__PURE__ */ jsxs("button", {
64
+ type: "button",
65
+ onClick: () => {
66
+ pinned.current = true;
67
+ setAtBottom(true);
68
+ scrollToBottom("smooth");
69
+ },
70
+ className: "absolute bottom-3 left-1/2 inline-flex -translate-x-1/2 animate-in items-center gap-1.5 rounded-full border border-border-strong bg-surface-raised px-3 py-1.5 text-xs font-semibold shadow-md outline-none hover:bg-muted focus-visible:ring-[3px] focus-visible:ring-ring/20 [&_svg]:size-3.5",
71
+ children: [/* @__PURE__ */ jsx(ArrowDown, { "aria-hidden": true }), " Jump to latest"]
72
+ })]
73
+ });
74
+ }
75
+ //#endregion
76
+ export { Conversation };
77
+
78
+ //# sourceMappingURL=conversation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation.js","names":[],"sources":["../../src/components/conversation.tsx"],"sourcesContent":["import ArrowDown from '@burtson-labs/icons/react/arrow-down';\nimport * as React from 'react';\n\nimport { cn } from '../lib/utils';\n\nexport interface ConversationProps extends React.ComponentProps<'div'> {\n /** Shown instead of the messages when there are none. */\n empty?: React.ReactNode;\n /** Accessible name for the message log. */\n label?: string;\n}\n\n/**\n * A scrolling message log that stays pinned to the newest message while it\n * streams, unless the reader has scrolled up; then a \"Jump to latest\" button\n * appears instead of yanking them back down.\n */\nfunction Conversation({\n children,\n empty,\n label = 'Conversation',\n className,\n ...props\n}: ConversationProps) {\n const scroller = React.useRef<HTMLDivElement>(null);\n const content = React.useRef<HTMLDivElement>(null);\n const pinned = React.useRef(true);\n const [atBottom, setAtBottom] = React.useState(true);\n const hasMessages = React.Children.toArray(children).length > 0;\n\n const scrollToBottom = React.useCallback((behavior: ScrollBehavior = 'auto') => {\n const el = scroller.current;\n if (!el) return;\n if (typeof el.scrollTo === 'function') el.scrollTo({ top: el.scrollHeight, behavior });\n else el.scrollTop = el.scrollHeight;\n }, []);\n\n React.useEffect(() => {\n const el = content.current;\n if (!el) return;\n // Content grows while a reply streams; follow it only if pinned.\n const ro = new ResizeObserver(() => {\n if (pinned.current) scrollToBottom();\n });\n ro.observe(el);\n return () => ro.disconnect();\n }, [scrollToBottom]);\n\n React.useEffect(() => {\n if (pinned.current) scrollToBottom();\n }, [children, scrollToBottom]);\n\n const onScroll = () => {\n const el = scroller.current;\n if (!el) return;\n const bottom = el.scrollHeight - el.scrollTop - el.clientHeight < 32;\n pinned.current = bottom;\n setAtBottom(bottom);\n };\n\n return (\n <div data-slot=\"conversation\" className={cn('relative min-h-0', className)} {...props}>\n <div\n ref={scroller}\n role=\"log\"\n aria-label={label}\n aria-live=\"polite\"\n aria-relevant=\"additions text\"\n // A scrollable region must be reachable by keyboard (WCAG 2.1.1).\n // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex\n tabIndex={0}\n onScroll={onScroll}\n className=\"size-full overflow-y-auto outline-none focus-visible:ring-[3px] focus-visible:ring-ring/20\"\n >\n <div ref={content} className=\"grid gap-5 p-4\">\n {hasMessages ? children : empty}\n </div>\n </div>\n {!atBottom && (\n <button\n type=\"button\"\n onClick={() => {\n pinned.current = true;\n setAtBottom(true);\n scrollToBottom('smooth');\n }}\n className=\"absolute bottom-3 left-1/2 inline-flex -translate-x-1/2 animate-in items-center gap-1.5 rounded-full border border-border-strong bg-surface-raised px-3 py-1.5 text-xs font-semibold shadow-md outline-none hover:bg-muted focus-visible:ring-[3px] focus-visible:ring-ring/20 [&_svg]:size-3.5\"\n >\n <ArrowDown aria-hidden /> Jump to latest\n </button>\n )}\n </div>\n );\n}\n\nexport { Conversation };\n"],"mappings":";;;;;;;;;;AAiBA,SAAS,aAAa,EACpB,UACA,OACA,QAAQ,gBACR,WACA,GAAG,SACiB;CACpB,MAAM,WAAW,MAAM,OAAuB,IAAI;CAClD,MAAM,UAAU,MAAM,OAAuB,IAAI;CACjD,MAAM,SAAS,MAAM,OAAO,IAAI;CAChC,MAAM,CAAC,UAAU,eAAe,MAAM,SAAS,IAAI;CACnD,MAAM,cAAc,MAAM,SAAS,QAAQ,QAAQ,CAAC,CAAC,SAAS;CAE9D,MAAM,iBAAiB,MAAM,aAAa,WAA2B,WAAW;EAC9E,MAAM,KAAK,SAAS;EACpB,IAAI,CAAC,IAAI;EACT,IAAI,OAAO,GAAG,aAAa,YAAY,GAAG,SAAS;GAAE,KAAK,GAAG;GAAc;EAAS,CAAC;OAChF,GAAG,YAAY,GAAG;CACzB,GAAG,CAAC,CAAC;CAEL,MAAM,gBAAgB;EACpB,MAAM,KAAK,QAAQ;EACnB,IAAI,CAAC,IAAI;EAET,MAAM,KAAK,IAAI,qBAAqB;GAClC,IAAI,OAAO,SAAS,eAAe;EACrC,CAAC;EACD,GAAG,QAAQ,EAAE;EACb,aAAa,GAAG,WAAW;CAC7B,GAAG,CAAC,cAAc,CAAC;CAEnB,MAAM,gBAAgB;EACpB,IAAI,OAAO,SAAS,eAAe;CACrC,GAAG,CAAC,UAAU,cAAc,CAAC;CAE7B,MAAM,iBAAiB;EACrB,MAAM,KAAK,SAAS;EACpB,IAAI,CAAC,IAAI;EACT,MAAM,SAAS,GAAG,eAAe,GAAG,YAAY,GAAG,eAAe;EAClE,OAAO,UAAU;EACjB,YAAY,MAAM;CACpB;CAEA,OACE,qBAAC,OAAD;EAAK,aAAU;EAAe,WAAW,GAAG,oBAAoB,SAAS;EAAG,GAAI;EAAhF,UAAA,CACE,oBAAC,OAAD;GACE,KAAK;GACL,MAAK;GACL,cAAY;GACZ,aAAU;GACV,iBAAc;GAGd,UAAU;GACA;GACV,WAAU;GAEV,UAAA,oBAAC,OAAD;IAAK,KAAK;IAAS,WAAU;IAC1B,UAAA,cAAc,WAAW;GACvB,CAAA;EACF,CAAA,GACJ,CAAC,YACA,qBAAC,UAAD;GACE,MAAK;GACL,eAAe;IACb,OAAO,UAAU;IACjB,YAAY,IAAI;IAChB,eAAe,QAAQ;GACzB;GACA,WAAU;GAPZ,UAAA,CASE,oBAAC,WAAD,EAAW,eAAA,KAAa,CAAA,GAAC,iBACnB;EAEP,CAAA,CAAA;;AAET"}
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ import { type IconButtonProps } from './icon-button';
3
+ export interface CopyButtonProps extends Omit<IconButtonProps, 'label' | 'children' | 'onClick'> {
4
+ /** The text to put on the clipboard. */
5
+ value: string;
6
+ /** Accessible name, e.g. "Copy API key". */
7
+ label?: string;
8
+ }
9
+ /**
10
+ * Icon button that copies `value` and shows a check for a moment. When the
11
+ * browser blocks the clipboard it raises a toast (needs a mounted Toaster)
12
+ * asking the person to copy by hand.
13
+ */
14
+ declare function CopyButton({ value, label, variant, size, ...props }: CopyButtonProps): React.JSX.Element;
15
+ export { CopyButton };
@@ -0,0 +1,47 @@
1
+ import { IconButton } from "./icon-button.js";
2
+ import { toast } from "./toaster.js";
3
+ import * as React from "react";
4
+ import { jsx } from "react/jsx-runtime";
5
+ import Check from "@burtson-labs/icons/react/check";
6
+ import Copy from "@burtson-labs/icons/react/copy";
7
+ //#region src/components/copy-button.tsx
8
+ /**
9
+ * Icon button that copies `value` and shows a check for a moment. When the
10
+ * browser blocks the clipboard it raises a toast (needs a mounted Toaster)
11
+ * asking the person to copy by hand.
12
+ */
13
+ function CopyButton({ value, label = "Copy", variant = "ghost", size = "icon-sm", ...props }) {
14
+ const [copied, setCopied] = React.useState(false);
15
+ const timer = React.useRef(void 0);
16
+ React.useEffect(() => () => clearTimeout(timer.current), []);
17
+ const copy = async () => {
18
+ try {
19
+ await navigator.clipboard.writeText(value);
20
+ setCopied(true);
21
+ clearTimeout(timer.current);
22
+ timer.current = setTimeout(() => setCopied(false), 1600);
23
+ } catch {
24
+ toast({
25
+ title: "Copy blocked by the browser",
26
+ description: "Select the text and copy it by hand.",
27
+ variant: "destructive"
28
+ });
29
+ }
30
+ };
31
+ return /* @__PURE__ */ jsx(IconButton, {
32
+ "data-slot": "copy-button",
33
+ label: copied ? "Copied" : label,
34
+ variant,
35
+ size,
36
+ onClick: () => void copy(),
37
+ ...props,
38
+ children: copied ? /* @__PURE__ */ jsx(Check, {
39
+ "aria-hidden": true,
40
+ className: "text-success"
41
+ }) : /* @__PURE__ */ jsx(Copy, { "aria-hidden": true })
42
+ });
43
+ }
44
+ //#endregion
45
+ export { CopyButton };
46
+
47
+ //# sourceMappingURL=copy-button.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy-button.js","names":[],"sources":["../../src/components/copy-button.tsx"],"sourcesContent":["import Check from '@burtson-labs/icons/react/check';\nimport Copy from '@burtson-labs/icons/react/copy';\nimport * as React from 'react';\n\nimport { IconButton, type IconButtonProps } from './icon-button';\nimport { toast } from './toaster';\n\nexport interface CopyButtonProps extends Omit<IconButtonProps, 'label' | 'children' | 'onClick'> {\n /** The text to put on the clipboard. */\n value: string;\n /** Accessible name, e.g. \"Copy API key\". */\n label?: string;\n}\n\n/**\n * Icon button that copies `value` and shows a check for a moment. When the\n * browser blocks the clipboard it raises a toast (needs a mounted Toaster)\n * asking the person to copy by hand.\n */\nfunction CopyButton({\n value,\n label = 'Copy',\n variant = 'ghost',\n size = 'icon-sm',\n ...props\n}: CopyButtonProps) {\n const [copied, setCopied] = React.useState(false);\n const timer = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n React.useEffect(() => () => clearTimeout(timer.current), []);\n\n const copy = async () => {\n try {\n await navigator.clipboard.writeText(value);\n setCopied(true);\n clearTimeout(timer.current);\n timer.current = setTimeout(() => setCopied(false), 1600);\n } catch {\n toast({\n title: 'Copy blocked by the browser',\n description: 'Select the text and copy it by hand.',\n variant: 'destructive',\n });\n }\n };\n\n return (\n <IconButton\n data-slot=\"copy-button\"\n label={copied ? 'Copied' : label}\n variant={variant}\n size={size}\n onClick={() => void copy()}\n {...props}\n >\n {copied ? <Check aria-hidden className=\"text-success\" /> : <Copy aria-hidden />}\n </IconButton>\n );\n}\n\nexport { CopyButton };\n"],"mappings":";;;;;;;;;;;;AAmBA,SAAS,WAAW,EAClB,OACA,QAAQ,QACR,UAAU,SACV,OAAO,WACP,GAAG,SACe;CAClB,MAAM,CAAC,QAAQ,aAAa,MAAM,SAAS,KAAK;CAChD,MAAM,QAAQ,MAAM,OAAkD,KAAA,CAAS;CAC/E,MAAM,sBAAsB,aAAa,MAAM,OAAO,GAAG,CAAC,CAAC;CAE3D,MAAM,OAAO,YAAY;EACvB,IAAI;GACF,MAAM,UAAU,UAAU,UAAU,KAAK;GACzC,UAAU,IAAI;GACd,aAAa,MAAM,OAAO;GAC1B,MAAM,UAAU,iBAAiB,UAAU,KAAK,GAAG,IAAI;EACzD,QAAQ;GACN,MAAM;IACJ,OAAO;IACP,aAAa;IACb,SAAS;GACX,CAAC;EACH;CACF;CAEA,OACE,oBAAC,YAAD;EACE,aAAU;EACV,OAAO,SAAS,WAAW;EAClB;EACH;EACN,eAAe,KAAK,KAAK;EACzB,GAAI;EAEH,UAAA,SAAS,oBAAC,OAAD;GAAO,eAAA;GAAY,WAAU;EAAgB,CAAA,IAAI,oBAAC,MAAD,EAAM,eAAA,KAAa,CAAA;CACpE,CAAA;AAEhB"}
@@ -0,0 +1,33 @@
1
+ import * as React from 'react';
2
+ /** A fenced code block with a language label and a copy button. */
3
+ declare function CodeBlock({ code, lang, className }: {
4
+ code: string;
5
+ lang?: string;
6
+ className?: string;
7
+ }): React.JSX.Element;
8
+ type Block = {
9
+ type: 'p';
10
+ text: string;
11
+ } | {
12
+ type: 'h';
13
+ level: 1 | 2 | 3;
14
+ text: string;
15
+ } | {
16
+ type: 'ul' | 'ol';
17
+ items: string[];
18
+ } | {
19
+ type: 'quote';
20
+ text: string;
21
+ } | {
22
+ type: 'code';
23
+ lang: string;
24
+ code: string;
25
+ };
26
+ /** Split Markdown into blocks. Exported for tests. */
27
+ export declare function parseMarkdown(source: string): Block[];
28
+ export interface MarkdownProps extends Omit<React.ComponentProps<'div'>, 'children'> {
29
+ children: string;
30
+ }
31
+ /** Renders a Markdown string safely, for assistant messages. */
32
+ declare function Markdown({ children, className, ...props }: MarkdownProps): React.JSX.Element;
33
+ export { CodeBlock, Markdown };
@@ -0,0 +1,177 @@
1
+ import { cn } from "../lib/utils.js";
2
+ import * as React from "react";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ import Check from "@burtson-labs/icons/react/check";
5
+ import Copy from "@burtson-labs/icons/react/copy";
6
+ //#region src/components/markdown.tsx
7
+ var SAFE_HREF = /^(https?:\/\/|mailto:)/i;
8
+ function inline(text, key) {
9
+ const out = [];
10
+ const pattern = /(`[^`]+`)|(\*\*[^*]+\*\*|__[^_]+__)|(\*[^*\s][^*]*\*|_[^_\s][^_]*_)|(\[[^\]]+\]\([^)\s]+\))/g;
11
+ let last = 0;
12
+ let n = 0;
13
+ for (const m of text.matchAll(pattern)) {
14
+ const i = m.index;
15
+ if (i > last) out.push(text.slice(last, i));
16
+ const token = m[0];
17
+ const k = `${key}-${n++}`;
18
+ if (m[1]) out.push(/* @__PURE__ */ jsx("code", {
19
+ className: "rounded-xs bg-muted px-1 py-0.5 font-mono text-[0.85em]",
20
+ children: token.slice(1, -1)
21
+ }, k));
22
+ else if (m[2]) out.push(/* @__PURE__ */ jsx("strong", { children: inline(token.slice(2, -2), k) }, k));
23
+ else if (m[3]) out.push(/* @__PURE__ */ jsx("em", { children: inline(token.slice(1, -1), k) }, k));
24
+ else {
25
+ const [, label = "", href = ""] = /^\[([^\]]+)\]\(([^)\s]+)\)$/.exec(token) ?? [];
26
+ out.push(SAFE_HREF.test(href) ? /* @__PURE__ */ jsx("a", {
27
+ href,
28
+ target: "_blank",
29
+ rel: "noreferrer noopener",
30
+ className: "text-brand underline underline-offset-2 hover:text-brand-hover",
31
+ children: label
32
+ }, k) : label);
33
+ }
34
+ last = i + token.length;
35
+ }
36
+ if (last < text.length) out.push(text.slice(last));
37
+ return out;
38
+ }
39
+ /** A fenced code block with a language label and a copy button. */
40
+ function CodeBlock({ code, lang, className }) {
41
+ const [copied, setCopied] = React.useState(false);
42
+ return /* @__PURE__ */ jsxs("div", {
43
+ "data-slot": "code-block",
44
+ className: cn("overflow-hidden rounded-md border bg-code text-code-foreground", className),
45
+ children: [/* @__PURE__ */ jsxs("div", {
46
+ className: "flex h-8 items-center justify-between border-b border-white/10 px-3 text-[11px] text-code-foreground/60",
47
+ children: [/* @__PURE__ */ jsx("span", {
48
+ className: "font-mono",
49
+ children: lang || "text"
50
+ }), /* @__PURE__ */ jsx("button", {
51
+ type: "button",
52
+ "aria-label": copied ? "Copied" : "Copy code",
53
+ className: "grid size-6 place-items-center rounded-xs outline-none hover:bg-white/10 focus-visible:ring-[3px] focus-visible:ring-ring/30 [&_svg]:size-3.5",
54
+ onClick: () => {
55
+ navigator.clipboard?.writeText(code).then(() => {
56
+ setCopied(true);
57
+ setTimeout(() => setCopied(false), 1400);
58
+ });
59
+ },
60
+ children: copied ? /* @__PURE__ */ jsx(Check, { "aria-hidden": true }) : /* @__PURE__ */ jsx(Copy, { "aria-hidden": true })
61
+ })]
62
+ }), /* @__PURE__ */ jsx("pre", {
63
+ className: "overflow-x-auto p-3 font-mono text-[12.5px] leading-5",
64
+ children: /* @__PURE__ */ jsx("code", { children: code })
65
+ })]
66
+ });
67
+ }
68
+ /** Split Markdown into blocks. Exported for tests. */
69
+ function parseMarkdown(source) {
70
+ const lines = source.replace(/\r\n?/g, "\n").split("\n");
71
+ const blocks = [];
72
+ let para = [];
73
+ const flush = () => {
74
+ if (para.length) blocks.push({
75
+ type: "p",
76
+ text: para.join(" ")
77
+ });
78
+ para = [];
79
+ };
80
+ for (let i = 0; i < lines.length; i++) {
81
+ const line = lines[i] ?? "";
82
+ const fence = /^```\s*([\w+-]*)\s*$/.exec(line);
83
+ if (fence) {
84
+ flush();
85
+ const code = [];
86
+ i++;
87
+ while (i < lines.length && !/^```\s*$/.test(lines[i] ?? "")) code.push(lines[i++] ?? "");
88
+ blocks.push({
89
+ type: "code",
90
+ lang: fence[1] ?? "",
91
+ code: code.join("\n")
92
+ });
93
+ continue;
94
+ }
95
+ const heading = /^(#{1,3})\s+(.*)$/.exec(line);
96
+ if (heading) {
97
+ flush();
98
+ blocks.push({
99
+ type: "h",
100
+ level: heading[1]?.length ?? 1,
101
+ text: heading[2] ?? ""
102
+ });
103
+ continue;
104
+ }
105
+ const list = /^\s*([-*]|\d+[.)])\s+(.*)$/.exec(line);
106
+ if (list) {
107
+ flush();
108
+ const type = /\d/.test(list[1] ?? "") ? "ol" : "ul";
109
+ const prev = blocks.at(-1);
110
+ if (prev && prev.type === type) prev.items.push(list[2] ?? "");
111
+ else blocks.push({
112
+ type,
113
+ items: [list[2] ?? ""]
114
+ });
115
+ continue;
116
+ }
117
+ const quote = /^>\s?(.*)$/.exec(line);
118
+ if (quote) {
119
+ flush();
120
+ blocks.push({
121
+ type: "quote",
122
+ text: quote[1] ?? ""
123
+ });
124
+ continue;
125
+ }
126
+ if (!line.trim()) flush();
127
+ else para.push(line.trim());
128
+ }
129
+ flush();
130
+ return blocks;
131
+ }
132
+ /** Renders a Markdown string safely, for assistant messages. */
133
+ function Markdown({ children, className, ...props }) {
134
+ const blocks = React.useMemo(() => parseMarkdown(children), [children]);
135
+ return /* @__PURE__ */ jsx("div", {
136
+ "data-slot": "markdown",
137
+ className: cn("grid gap-3 text-sm leading-6 [&_li]:leading-6", className),
138
+ ...props,
139
+ children: blocks.map((b, i) => {
140
+ const k = `b${i}`;
141
+ switch (b.type) {
142
+ case "h": {
143
+ const Tag = [
144
+ "h3",
145
+ "h4",
146
+ "h5"
147
+ ][b.level - 1] ?? "h5";
148
+ return /* @__PURE__ */ jsx(Tag, {
149
+ className: "font-semibold tracking-[-0.01em]",
150
+ children: inline(b.text, k)
151
+ }, k);
152
+ }
153
+ case "ul":
154
+ case "ol": {
155
+ const Tag = b.type;
156
+ return /* @__PURE__ */ jsx(Tag, {
157
+ className: cn("grid gap-1 pl-5", b.type === "ul" ? "list-disc" : "list-decimal"),
158
+ children: b.items.map((item, j) => /* @__PURE__ */ jsx("li", { children: inline(item, `${k}-${j}`) }, `${k}-${j}`))
159
+ }, k);
160
+ }
161
+ case "quote": return /* @__PURE__ */ jsx("blockquote", {
162
+ className: "border-l-2 border-border-strong pl-3 text-muted-foreground",
163
+ children: inline(b.text, k)
164
+ }, k);
165
+ case "code": return /* @__PURE__ */ jsx(CodeBlock, {
166
+ code: b.code,
167
+ lang: b.lang
168
+ }, k);
169
+ default: return /* @__PURE__ */ jsx("p", { children: inline(b.text, k) }, k);
170
+ }
171
+ })
172
+ });
173
+ }
174
+ //#endregion
175
+ export { CodeBlock, Markdown, parseMarkdown };
176
+
177
+ //# sourceMappingURL=markdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.js","names":[],"sources":["../../src/components/markdown.tsx"],"sourcesContent":["import Check from '@burtson-labs/icons/react/check';\nimport Copy from '@burtson-labs/icons/react/copy';\nimport * as React from 'react';\n\nimport { cn } from '../lib/utils';\n\n/*\n * A small, safe Markdown renderer for chat: paragraphs, headings, bullet and\n * numbered lists, block quotes, fenced code, inline code, bold, italic and\n * links. Everything becomes React elements (never HTML strings), and links\n * only keep http(s) and mailto targets, so model output cannot inject markup\n * or script.\n */\n\nconst SAFE_HREF = /^(https?:\\/\\/|mailto:)/i;\n\nfunction inline(text: string, key: string): React.ReactNode[] {\n const out: React.ReactNode[] = [];\n const pattern =\n /(`[^`]+`)|(\\*\\*[^*]+\\*\\*|__[^_]+__)|(\\*[^*\\s][^*]*\\*|_[^_\\s][^_]*_)|(\\[[^\\]]+\\]\\([^)\\s]+\\))/g;\n let last = 0;\n let n = 0;\n for (const m of text.matchAll(pattern)) {\n const i = m.index;\n if (i > last) out.push(text.slice(last, i));\n const token = m[0];\n const k = `${key}-${n++}`;\n if (m[1]) {\n out.push(\n <code key={k} className=\"rounded-xs bg-muted px-1 py-0.5 font-mono text-[0.85em]\">\n {token.slice(1, -1)}\n </code>,\n );\n } else if (m[2]) {\n out.push(<strong key={k}>{inline(token.slice(2, -2), k)}</strong>);\n } else if (m[3]) {\n out.push(<em key={k}>{inline(token.slice(1, -1), k)}</em>);\n } else {\n const [, label = '', href = ''] = /^\\[([^\\]]+)\\]\\(([^)\\s]+)\\)$/.exec(token) ?? [];\n out.push(\n SAFE_HREF.test(href) ? (\n <a\n key={k}\n href={href}\n target=\"_blank\"\n rel=\"noreferrer noopener\"\n className=\"text-brand underline underline-offset-2 hover:text-brand-hover\"\n >\n {label}\n </a>\n ) : (\n label\n ),\n );\n }\n last = i + token.length;\n }\n if (last < text.length) out.push(text.slice(last));\n return out;\n}\n\n/** A fenced code block with a language label and a copy button. */\nfunction CodeBlock({ code, lang, className }: { code: string; lang?: string; className?: string }) {\n const [copied, setCopied] = React.useState(false);\n return (\n <div\n data-slot=\"code-block\"\n className={cn('overflow-hidden rounded-md border bg-code text-code-foreground', className)}\n >\n <div className=\"flex h-8 items-center justify-between border-b border-white/10 px-3 text-[11px] text-code-foreground/60\">\n <span className=\"font-mono\">{lang || 'text'}</span>\n <button\n type=\"button\"\n aria-label={copied ? 'Copied' : 'Copy code'}\n className=\"grid size-6 place-items-center rounded-xs outline-none hover:bg-white/10 focus-visible:ring-[3px] focus-visible:ring-ring/30 [&_svg]:size-3.5\"\n onClick={() => {\n void navigator.clipboard?.writeText(code).then(() => {\n setCopied(true);\n setTimeout(() => setCopied(false), 1400);\n });\n }}\n >\n {copied ? <Check aria-hidden /> : <Copy aria-hidden />}\n </button>\n </div>\n <pre className=\"overflow-x-auto p-3 font-mono text-[12.5px] leading-5\">\n <code>{code}</code>\n </pre>\n </div>\n );\n}\n\ntype Block =\n | { type: 'p'; text: string }\n | { type: 'h'; level: 1 | 2 | 3; text: string }\n | { type: 'ul' | 'ol'; items: string[] }\n | { type: 'quote'; text: string }\n | { type: 'code'; lang: string; code: string };\n\n/** Split Markdown into blocks. Exported for tests. */\nexport function parseMarkdown(source: string): Block[] {\n const lines = source.replace(/\\r\\n?/g, '\\n').split('\\n');\n const blocks: Block[] = [];\n let para: string[] = [];\n const flush = () => {\n if (para.length) blocks.push({ type: 'p', text: para.join(' ') });\n para = [];\n };\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i] ?? '';\n const fence = /^```\\s*([\\w+-]*)\\s*$/.exec(line);\n if (fence) {\n flush();\n const code: string[] = [];\n i++;\n while (i < lines.length && !/^```\\s*$/.test(lines[i] ?? '')) code.push(lines[i++] ?? '');\n blocks.push({ type: 'code', lang: fence[1] ?? '', code: code.join('\\n') });\n continue;\n }\n const heading = /^(#{1,3})\\s+(.*)$/.exec(line);\n if (heading) {\n flush();\n blocks.push({\n type: 'h',\n level: (heading[1]?.length ?? 1) as 1 | 2 | 3,\n text: heading[2] ?? '',\n });\n continue;\n }\n const list = /^\\s*([-*]|\\d+[.)])\\s+(.*)$/.exec(line);\n if (list) {\n flush();\n const type = /\\d/.test(list[1] ?? '') ? 'ol' : 'ul';\n const prev = blocks.at(-1);\n if (prev && prev.type === type) prev.items.push(list[2] ?? '');\n else blocks.push({ type, items: [list[2] ?? ''] });\n continue;\n }\n const quote = /^>\\s?(.*)$/.exec(line);\n if (quote) {\n flush();\n blocks.push({ type: 'quote', text: quote[1] ?? '' });\n continue;\n }\n if (!line.trim()) flush();\n else para.push(line.trim());\n }\n flush();\n return blocks;\n}\n\nexport interface MarkdownProps extends Omit<React.ComponentProps<'div'>, 'children'> {\n children: string;\n}\n\n/** Renders a Markdown string safely, for assistant messages. */\nfunction Markdown({ children, className, ...props }: MarkdownProps) {\n const blocks = React.useMemo(() => parseMarkdown(children), [children]);\n return (\n <div\n data-slot=\"markdown\"\n className={cn('grid gap-3 text-sm leading-6 [&_li]:leading-6', className)}\n {...props}\n >\n {blocks.map((b, i) => {\n const k = `b${i}`;\n switch (b.type) {\n case 'h': {\n const Tag = (['h3', 'h4', 'h5'] as const)[b.level - 1] ?? 'h5';\n return (\n <Tag key={k} className=\"font-semibold tracking-[-0.01em]\">\n {inline(b.text, k)}\n </Tag>\n );\n }\n case 'ul':\n case 'ol': {\n const Tag = b.type;\n return (\n <Tag\n key={k}\n className={cn('grid gap-1 pl-5', b.type === 'ul' ? 'list-disc' : 'list-decimal')}\n >\n {b.items.map((item, j) => (\n <li key={`${k}-${j}`}>{inline(item, `${k}-${j}`)}</li>\n ))}\n </Tag>\n );\n }\n case 'quote':\n return (\n <blockquote\n key={k}\n className=\"border-l-2 border-border-strong pl-3 text-muted-foreground\"\n >\n {inline(b.text, k)}\n </blockquote>\n );\n case 'code':\n return <CodeBlock key={k} code={b.code} lang={b.lang} />;\n default:\n return <p key={k}>{inline(b.text, k)}</p>;\n }\n })}\n </div>\n );\n}\n\nexport { CodeBlock, Markdown };\n"],"mappings":";;;;;;AAcA,IAAM,YAAY;AAElB,SAAS,OAAO,MAAc,KAAgC;CAC5D,MAAM,MAAyB,CAAC;CAChC,MAAM,UACJ;CACF,IAAI,OAAO;CACX,IAAI,IAAI;CACR,KAAK,MAAM,KAAK,KAAK,SAAS,OAAO,GAAG;EACtC,MAAM,IAAI,EAAE;EACZ,IAAI,IAAI,MAAM,IAAI,KAAK,KAAK,MAAM,MAAM,CAAC,CAAC;EAC1C,MAAM,QAAQ,EAAE;EAChB,MAAM,IAAI,GAAG,IA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P,GAJL,CAIK;IAEhB,KAAK,QACH,OAAO,oBAAC,WAAD;KAAmB,MAAM,EAAE;KAAM,MAAM,EAAE;IAAO,GAAhC,CAAgC;IACzD,SACE,OAAO,oBAAC,KAAD,EAAA,UAAY,OAAO,EAAE,MAAM,CAAC,EAAK,GAAzB,CAAyB;GAC5C;EACF,CAAC;CACE,CAAA;AAET"}
@@ -0,0 +1,21 @@
1
+ import * as React from 'react';
2
+ export type MessageRole = 'user' | 'assistant' | 'system';
3
+ export interface MessageProps extends React.ComponentProps<'div'> {
4
+ /** Who wrote it. (Not `role`, which is the ARIA attribute.) */
5
+ from: MessageRole;
6
+ /** Avatar or agent mark beside assistant messages. */
7
+ avatar?: React.ReactNode;
8
+ /** Sender name shown above the message, e.g. the agent's name. */
9
+ name?: React.ReactNode;
10
+ /** Timestamp or status text. */
11
+ meta?: React.ReactNode;
12
+ /** Actions such as copy and retry, shown on hover and focus. */
13
+ actions?: React.ReactNode;
14
+ }
15
+ /**
16
+ * One turn in a conversation. User turns sit on the right in a quiet bubble,
17
+ * assistant turns read full width with an optional avatar, and system notes
18
+ * are centred and small.
19
+ */
20
+ declare function Message({ from, avatar, name, meta, actions, children, className, ...props }: MessageProps): React.JSX.Element;
21
+ export { Message };
@@ -0,0 +1,56 @@
1
+ import { cn } from "../lib/utils.js";
2
+ import "react";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ //#region src/components/message.tsx
5
+ /**
6
+ * One turn in a conversation. User turns sit on the right in a quiet bubble,
7
+ * assistant turns read full width with an optional avatar, and system notes
8
+ * are centred and small.
9
+ */
10
+ function Message({ from, avatar, name, meta, actions, children, className, ...props }) {
11
+ if (from === "system") return /* @__PURE__ */ jsx("div", {
12
+ "data-slot": "message",
13
+ "data-role": "system",
14
+ className: cn("mx-auto max-w-prose text-center text-xs text-muted-foreground", className),
15
+ ...props,
16
+ children
17
+ });
18
+ const user = from === "user";
19
+ return /* @__PURE__ */ jsxs("div", {
20
+ "data-slot": "message",
21
+ "data-role": from,
22
+ className: cn("group/message flex animate-in gap-3", user ? "justify-end" : "justify-start", className),
23
+ ...props,
24
+ children: [!user && avatar && /* @__PURE__ */ jsx("div", {
25
+ className: "mt-0.5 grid size-7 shrink-0 place-items-center overflow-hidden rounded-md border border-brand/15 bg-brand-soft text-brand [&_svg]:size-4",
26
+ children: avatar
27
+ }), /* @__PURE__ */ jsxs("div", {
28
+ className: cn("grid min-w-0 gap-1.5", user ? "max-w-[85%] justify-items-end" : "flex-1"),
29
+ children: [
30
+ (name || meta) && /* @__PURE__ */ jsxs("div", {
31
+ className: "flex items-baseline gap-2 text-xs",
32
+ children: [name && /* @__PURE__ */ jsx("span", {
33
+ className: "font-semibold text-foreground",
34
+ children: name
35
+ }), meta && /* @__PURE__ */ jsx("span", {
36
+ className: "text-muted-foreground",
37
+ children: meta
38
+ })]
39
+ }),
40
+ /* @__PURE__ */ jsx("div", {
41
+ "data-slot": "message-body",
42
+ className: cn("min-w-0 text-sm leading-6", user && "rounded-lg rounded-tr-xs bg-secondary px-3.5 py-2 text-secondary-foreground"),
43
+ children
44
+ }),
45
+ actions && /* @__PURE__ */ jsx("div", {
46
+ className: "flex gap-1 opacity-0 transition-opacity group-focus-within/message:opacity-100 group-hover/message:opacity-100 max-md:opacity-100",
47
+ children: actions
48
+ })
49
+ ]
50
+ })]
51
+ });
52
+ }
53
+ //#endregion
54
+ export { Message };
55
+
56
+ //# sourceMappingURL=message.js.map