pixelize-design-library 3.1.1 → 3.3.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 (143) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/COMPONENT-GOTCHAS.md +33 -0
  3. package/DESIGN-GUIDE.md +27 -0
  4. package/README.md +8 -8
  5. package/dist/Components/Assistant/assistantModel.d.ts +17 -0
  6. package/dist/Components/Assistant/assistantModel.js +35 -0
  7. package/dist/Components/Assistant/assistantStyles.d.ts +27 -0
  8. package/dist/Components/Assistant/assistantStyles.js +53 -0
  9. package/dist/Components/Assistant/assistantTypes.d.ts +163 -0
  10. package/dist/Components/Assistant/assistantTypes.js +2 -0
  11. package/dist/Components/Assistant/banner/AssistantStatusBanner.d.ts +3 -0
  12. package/dist/Components/Assistant/banner/AssistantStatusBanner.js +25 -0
  13. package/dist/Components/Assistant/banner/AssistantStatusBannerProps.d.ts +27 -0
  14. package/dist/Components/Assistant/banner/AssistantStatusBannerProps.js +2 -0
  15. package/dist/Components/Assistant/cards/AssistantApprovalCard.d.ts +3 -0
  16. package/dist/Components/Assistant/cards/AssistantApprovalCard.js +51 -0
  17. package/dist/Components/Assistant/cards/AssistantApprovalCardProps.d.ts +66 -0
  18. package/dist/Components/Assistant/cards/AssistantApprovalCardProps.js +2 -0
  19. package/dist/Components/Assistant/cards/AssistantProposalCard.d.ts +3 -0
  20. package/dist/Components/Assistant/cards/AssistantProposalCard.js +36 -0
  21. package/dist/Components/Assistant/cards/AssistantProposalCardProps.d.ts +56 -0
  22. package/dist/Components/Assistant/cards/AssistantProposalCardProps.js +2 -0
  23. package/dist/Components/Assistant/cards/CardShell.d.ts +31 -0
  24. package/dist/Components/Assistant/cards/CardShell.js +32 -0
  25. package/dist/Components/Assistant/composer/AssistantComposer.d.ts +3 -0
  26. package/dist/Components/Assistant/composer/AssistantComposer.js +264 -0
  27. package/dist/Components/Assistant/composer/AssistantComposerProps.d.ts +128 -0
  28. package/dist/Components/Assistant/composer/AssistantComposerProps.js +2 -0
  29. package/dist/Components/Assistant/composer/ComposerMenu.d.ts +24 -0
  30. package/dist/Components/Assistant/composer/ComposerMenu.js +38 -0
  31. package/dist/Components/Assistant/composer/composerLogic.d.ts +19 -0
  32. package/dist/Components/Assistant/composer/composerLogic.js +65 -0
  33. package/dist/Components/Assistant/context/AssistantContextBar.d.ts +3 -0
  34. package/dist/Components/Assistant/context/AssistantContextBar.js +27 -0
  35. package/dist/Components/Assistant/context/AssistantContextBarProps.d.ts +34 -0
  36. package/dist/Components/Assistant/context/AssistantContextBarProps.js +2 -0
  37. package/dist/Components/Assistant/history/AssistantHistoryList.d.ts +3 -0
  38. package/dist/Components/Assistant/history/AssistantHistoryList.js +123 -0
  39. package/dist/Components/Assistant/history/AssistantHistoryListProps.d.ts +83 -0
  40. package/dist/Components/Assistant/history/AssistantHistoryListProps.js +2 -0
  41. package/dist/Components/Assistant/history/groupConversations.d.ts +12 -0
  42. package/dist/Components/Assistant/history/groupConversations.js +55 -0
  43. package/dist/Components/Assistant/index.d.ts +16 -0
  44. package/dist/Components/Assistant/index.js +38 -0
  45. package/dist/Components/Assistant/launcher/AssistantLauncher.d.ts +3 -0
  46. package/dist/Components/Assistant/launcher/AssistantLauncher.js +45 -0
  47. package/dist/Components/Assistant/launcher/AssistantLauncherProps.d.ts +37 -0
  48. package/dist/Components/Assistant/launcher/AssistantLauncherProps.js +2 -0
  49. package/dist/Components/Assistant/markdown/AssistantMarkdown.d.ts +3 -0
  50. package/dist/Components/Assistant/markdown/AssistantMarkdown.js +146 -0
  51. package/dist/Components/Assistant/markdown/AssistantMarkdownProps.d.ts +38 -0
  52. package/dist/Components/Assistant/markdown/AssistantMarkdownProps.js +2 -0
  53. package/dist/Components/Assistant/markdown/parseMarkdown.d.ts +74 -0
  54. package/dist/Components/Assistant/markdown/parseMarkdown.js +328 -0
  55. package/dist/Components/Assistant/markdown/safeHref.d.ts +21 -0
  56. package/dist/Components/Assistant/markdown/safeHref.js +28 -0
  57. package/dist/Components/Assistant/message/AssistantMessage.d.ts +3 -0
  58. package/dist/Components/Assistant/message/AssistantMessage.js +131 -0
  59. package/dist/Components/Assistant/message/AssistantMessageProps.d.ts +83 -0
  60. package/dist/Components/Assistant/message/AssistantMessageProps.js +2 -0
  61. package/dist/Components/Assistant/message/MessageActions.d.ts +16 -0
  62. package/dist/Components/Assistant/message/MessageActions.js +23 -0
  63. package/dist/Components/Assistant/panel/AssistantPanel.d.ts +3 -0
  64. package/dist/Components/Assistant/panel/AssistantPanel.js +87 -0
  65. package/dist/Components/Assistant/panel/AssistantPanelProps.d.ts +86 -0
  66. package/dist/Components/Assistant/panel/AssistantPanelProps.js +2 -0
  67. package/dist/Components/Assistant/panel/ResizeHandle.d.ts +14 -0
  68. package/dist/Components/Assistant/panel/ResizeHandle.js +72 -0
  69. package/dist/Components/Assistant/sources/AssistantSources.d.ts +3 -0
  70. package/dist/Components/Assistant/sources/AssistantSources.js +63 -0
  71. package/dist/Components/Assistant/sources/AssistantSourcesProps.d.ts +29 -0
  72. package/dist/Components/Assistant/sources/AssistantSourcesProps.js +2 -0
  73. package/dist/Components/Assistant/steps/AssistantToolSteps.d.ts +3 -0
  74. package/dist/Components/Assistant/steps/AssistantToolSteps.js +41 -0
  75. package/dist/Components/Assistant/steps/AssistantToolStepsProps.d.ts +37 -0
  76. package/dist/Components/Assistant/steps/AssistantToolStepsProps.js +2 -0
  77. package/dist/Components/Assistant/suggestions/AssistantSuggestions.d.ts +3 -0
  78. package/dist/Components/Assistant/suggestions/AssistantSuggestions.js +18 -0
  79. package/dist/Components/Assistant/suggestions/AssistantSuggestionsProps.d.ts +15 -0
  80. package/dist/Components/Assistant/suggestions/AssistantSuggestionsProps.js +2 -0
  81. package/dist/Components/Assistant/thread/AssistantThread.d.ts +3 -0
  82. package/dist/Components/Assistant/thread/AssistantThread.js +158 -0
  83. package/dist/Components/Assistant/thread/AssistantThreadProps.d.ts +39 -0
  84. package/dist/Components/Assistant/thread/AssistantThreadProps.js +2 -0
  85. package/dist/Components/Assistant/thread/replyStartScroll.d.ts +8 -0
  86. package/dist/Components/Assistant/thread/replyStartScroll.js +6 -0
  87. package/dist/Components/Assistant/typing/AssistantTypingIndicator.d.ts +3 -0
  88. package/dist/Components/Assistant/typing/AssistantTypingIndicator.js +33 -0
  89. package/dist/Components/Assistant/typing/AssistantTypingIndicatorProps.d.ts +9 -0
  90. package/dist/Components/Assistant/typing/AssistantTypingIndicatorProps.js +2 -0
  91. package/dist/Components/Assistant/welcome/AssistantWelcome.d.ts +3 -0
  92. package/dist/Components/Assistant/welcome/AssistantWelcome.js +30 -0
  93. package/dist/Components/Assistant/welcome/AssistantWelcomeProps.d.ts +40 -0
  94. package/dist/Components/Assistant/welcome/AssistantWelcomeProps.js +2 -0
  95. package/dist/esm/Components/Assistant/assistantModel.js +29 -0
  96. package/dist/esm/Components/Assistant/assistantStyles.js +47 -0
  97. package/dist/esm/Components/Assistant/assistantTypes.js +1 -0
  98. package/dist/esm/Components/Assistant/banner/AssistantStatusBanner.js +20 -0
  99. package/dist/esm/Components/Assistant/banner/AssistantStatusBannerProps.js +1 -0
  100. package/dist/esm/Components/Assistant/cards/AssistantApprovalCard.js +46 -0
  101. package/dist/esm/Components/Assistant/cards/AssistantApprovalCardProps.js +1 -0
  102. package/dist/esm/Components/Assistant/cards/AssistantProposalCard.js +31 -0
  103. package/dist/esm/Components/Assistant/cards/AssistantProposalCardProps.js +1 -0
  104. package/dist/esm/Components/Assistant/cards/CardShell.js +23 -0
  105. package/dist/esm/Components/Assistant/composer/AssistantComposer.js +259 -0
  106. package/dist/esm/Components/Assistant/composer/AssistantComposerProps.js +1 -0
  107. package/dist/esm/Components/Assistant/composer/ComposerMenu.js +30 -0
  108. package/dist/esm/Components/Assistant/composer/composerLogic.js +56 -0
  109. package/dist/esm/Components/Assistant/context/AssistantContextBar.js +22 -0
  110. package/dist/esm/Components/Assistant/context/AssistantContextBarProps.js +1 -0
  111. package/dist/esm/Components/Assistant/history/AssistantHistoryList.js +118 -0
  112. package/dist/esm/Components/Assistant/history/AssistantHistoryListProps.js +1 -0
  113. package/dist/esm/Components/Assistant/history/groupConversations.js +51 -0
  114. package/dist/esm/Components/Assistant/index.js +16 -0
  115. package/dist/esm/Components/Assistant/launcher/AssistantLauncher.js +40 -0
  116. package/dist/esm/Components/Assistant/launcher/AssistantLauncherProps.js +1 -0
  117. package/dist/esm/Components/Assistant/markdown/AssistantMarkdown.js +141 -0
  118. package/dist/esm/Components/Assistant/markdown/AssistantMarkdownProps.js +1 -0
  119. package/dist/esm/Components/Assistant/markdown/parseMarkdown.js +322 -0
  120. package/dist/esm/Components/Assistant/markdown/safeHref.js +23 -0
  121. package/dist/esm/Components/Assistant/message/AssistantMessage.js +126 -0
  122. package/dist/esm/Components/Assistant/message/AssistantMessageProps.js +1 -0
  123. package/dist/esm/Components/Assistant/message/MessageActions.js +16 -0
  124. package/dist/esm/Components/Assistant/panel/AssistantPanel.js +82 -0
  125. package/dist/esm/Components/Assistant/panel/AssistantPanelProps.js +1 -0
  126. package/dist/esm/Components/Assistant/panel/ResizeHandle.js +68 -0
  127. package/dist/esm/Components/Assistant/sources/AssistantSources.js +58 -0
  128. package/dist/esm/Components/Assistant/sources/AssistantSourcesProps.js +1 -0
  129. package/dist/esm/Components/Assistant/steps/AssistantToolSteps.js +36 -0
  130. package/dist/esm/Components/Assistant/steps/AssistantToolStepsProps.js +1 -0
  131. package/dist/esm/Components/Assistant/suggestions/AssistantSuggestions.js +13 -0
  132. package/dist/esm/Components/Assistant/suggestions/AssistantSuggestionsProps.js +1 -0
  133. package/dist/esm/Components/Assistant/thread/AssistantThread.js +153 -0
  134. package/dist/esm/Components/Assistant/thread/AssistantThreadProps.js +1 -0
  135. package/dist/esm/Components/Assistant/thread/replyStartScroll.js +2 -0
  136. package/dist/esm/Components/Assistant/typing/AssistantTypingIndicator.js +28 -0
  137. package/dist/esm/Components/Assistant/typing/AssistantTypingIndicatorProps.js +1 -0
  138. package/dist/esm/Components/Assistant/welcome/AssistantWelcome.js +25 -0
  139. package/dist/esm/Components/Assistant/welcome/AssistantWelcomeProps.js +1 -0
  140. package/dist/esm/index.js +2 -0
  141. package/dist/index.d.ts +18 -0
  142. package/dist/index.js +20 -1
  143. package/package.json +1 -1
@@ -0,0 +1,259 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { memo, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, } from "react";
3
+ import { Box, Flex, Image, Text, Textarea } from "@chakra-ui/react";
4
+ import { ArrowUp, FileAudio, FileText, FileVideo, Image as ImageIcon, Mic, MicOff, Paperclip, Square, X } from "lucide-react";
5
+ import { useCustomTheme } from "../../../Theme/useCustomTheme.js";
6
+ import { fieldFocusVisible } from "../../../Theme/chakra/focusRing.styles.js";
7
+ import { placeholderInk } from "../../../Theme/tokens/builders/placeholderInk.js";
8
+ import { BORDER_WIDTHS } from "../../../Theme/tokens/primitives/borderWidths.js";
9
+ import { RADIUS_ROLE } from "../../../Theme/tokens/primitives/radii.js";
10
+ import { NUMERIC_TEXT } from "../../../Theme/tokens/primitives/typography.js";
11
+ import { scrollbarStyles } from "../../../Theme/tokens/builders/scrollbar.js";
12
+ import { fieldBoxStyles } from "../../Common/fieldStyles.js";
13
+ import { mergeRefs } from "../../../Utils/mergeRefs.js";
14
+ import IconButton from "../../IconButton/IconButton.js";
15
+ import ToolTip from "../../ToolTip/ToolTip.js";
16
+ import VisuallyHidden from "../../VisuallyHidden/VisuallyHidden.js";
17
+ import { assistantTokens, assistantTone } from "../assistantStyles.js";
18
+ import { ComposerMenu, optionId } from "./ComposerMenu.js";
19
+ import { applyMention, commandQuery, commandText, filterCommands, matchesAccept, mentionAt } from "./composerLogic.js";
20
+ const DEFAULT_LABELS = {
21
+ input: "Message the assistant",
22
+ send: "Send message",
23
+ stop: "Stop generating",
24
+ attach: "Attach files",
25
+ removeAttachment: (name) => `Remove ${name}`,
26
+ attachments: "Attachments",
27
+ commands: "Commands",
28
+ mentions: "Mentions",
29
+ mentionLoading: "Searching…",
30
+ mentionEmpty: "No matches",
31
+ voiceStart: "Start voice input",
32
+ voiceStop: "Stop voice input",
33
+ counter: (length, max) => `${length} of ${max} characters`,
34
+ dropHint: "Drop files to attach",
35
+ };
36
+ const MENTION_DEBOUNCE_MS = 150;
37
+ const COUNTER_FROM = 0.8;
38
+ const FALLBACK_LINE_PX = 20;
39
+ const ATTACHMENT_ICON = { image: ImageIcon, document: FileText, audio: FileAudio, video: FileVideo, file: FileText };
40
+ const hasFiles = (event) => { var _a, _b; return Array.from((_b = (_a = event.dataTransfer) === null || _a === void 0 ? void 0 : _a.types) !== null && _b !== void 0 ? _b : []).includes("Files"); };
41
+ /**
42
+ * The assistant's message box. Enter sends and Shift+Enter breaks the line (never mid-IME composition);
43
+ * while a reply streams Send turns into Stop. Files arrive from the paperclip, a paste or a drop. Typing
44
+ * "/" opens the command menu and "@" the mention menu; both keep focus in the field and are driven with
45
+ * ↑ ↓ Enter Tab Esc.
46
+ */
47
+ const AssistantComposer = ({ value, onChange, onSubmit, onStop, isStreaming = false, disabled = false, placeholder = "Ask anything", maxLength, maxRows = 8, autoFocus, attachments = [], onAttach, accept, onRemoveAttachment, commands, onCommand, onMentionQuery, onMentionSelect, formatMention, voice, header, footer, inputRef, labels, "data-testid": testId = "assistant-composer", }) => {
48
+ const { colors } = useCustomTheme();
49
+ const tokens = assistantTokens(colors);
50
+ const text = { ...DEFAULT_LABELS, ...labels };
51
+ const baseId = useId();
52
+ const menuId = `${baseId}-menu`;
53
+ const counterId = `${baseId}-counter`;
54
+ const textareaRef = useRef(null);
55
+ const fileRef = useRef(null);
56
+ const composing = useRef(false);
57
+ const pendingCaret = useRef(null);
58
+ const mentionToken = useRef(0);
59
+ const ref = useMemo(() => mergeRefs(textareaRef, inputRef), [inputRef]);
60
+ const [caret, setCaret] = useState(value.length);
61
+ const [dismissedFor, setDismissedFor] = useState(null);
62
+ const [activeIndex, setActiveIndex] = useState(0);
63
+ const [mention, setMention] = useState(null);
64
+ const [dragging, setDragging] = useState(false);
65
+ // Autosize: the height changes per keystroke, so it is written to inline style, never a Chakra prop.
66
+ useLayoutEffect(() => {
67
+ const el = textareaRef.current;
68
+ if (!el)
69
+ return;
70
+ const style = getComputedStyle(el);
71
+ const line = Number.parseFloat(style.lineHeight) || FALLBACK_LINE_PX;
72
+ const padding = (Number.parseFloat(style.paddingTop) || 0) + (Number.parseFloat(style.paddingBottom) || 0);
73
+ const max = line * maxRows + padding;
74
+ el.style.height = "auto";
75
+ const next = Math.min(el.scrollHeight, max);
76
+ el.style.height = next > 0 ? `${next}px` : "";
77
+ el.style.overflowY = el.scrollHeight > max ? "auto" : "hidden";
78
+ }, [value, maxRows]);
79
+ useLayoutEffect(() => {
80
+ if (pendingCaret.current === null)
81
+ return;
82
+ const el = textareaRef.current;
83
+ const at = pendingCaret.current;
84
+ pendingCaret.current = null;
85
+ if (!el)
86
+ return;
87
+ el.focus();
88
+ el.setSelectionRange(at, at);
89
+ setCaret(at);
90
+ }, [value]);
91
+ const slash = (commands === null || commands === void 0 ? void 0 : commands.length) ? commandQuery(value) : null;
92
+ const commandOptions = useMemo(() => (slash === null || !commands ? [] : filterCommands(commands, slash)), [commands, slash]);
93
+ const mentionMatch = onMentionQuery ? mentionAt(value, caret) : null;
94
+ const dismissed = dismissedFor === value;
95
+ const commandOpen = !dismissed && slash !== null && commandOptions.length > 0;
96
+ const mentionOpen = !dismissed && !commandOpen && mentionMatch !== null;
97
+ // Debounced, stale-safe mention lookup.
98
+ const mentionQuery = mentionOpen ? mentionMatch.query : null;
99
+ useEffect(() => {
100
+ if (mentionQuery === null || !onMentionQuery) {
101
+ setMention(null);
102
+ return undefined;
103
+ }
104
+ const token = ++mentionToken.current;
105
+ setMention((prev) => { var _a; return ({ query: mentionQuery, items: (_a = prev === null || prev === void 0 ? void 0 : prev.items) !== null && _a !== void 0 ? _a : [], loading: true }); });
106
+ const timer = setTimeout(() => {
107
+ onMentionQuery(mentionQuery)
108
+ .then((items) => {
109
+ if (token === mentionToken.current)
110
+ setMention({ query: mentionQuery, items, loading: false });
111
+ })
112
+ .catch(() => {
113
+ if (token === mentionToken.current)
114
+ setMention({ query: mentionQuery, items: [], loading: false });
115
+ });
116
+ }, MENTION_DEBOUNCE_MS);
117
+ return () => clearTimeout(timer);
118
+ }, [mentionQuery, onMentionQuery]);
119
+ const options = commandOpen
120
+ ? commandOptions.map((c) => ({
121
+ key: c.command,
122
+ label: c.label,
123
+ prefix: commandText(c).trim(),
124
+ description: c.description,
125
+ icon: c.icon,
126
+ }))
127
+ : mentionOpen && mention
128
+ ? mention.items.map((m) => ({ key: m.id, label: m.label, description: m.description, trailing: m.kind }))
129
+ : [];
130
+ const menuOpen = commandOpen || (mentionOpen && mention !== null);
131
+ const optionsKey = options.map((o) => o.key).join("|");
132
+ useEffect(() => setActiveIndex(0), [optionsKey]);
133
+ const active = Math.min(activeIndex, Math.max(0, options.length - 1));
134
+ const canSend = !disabled && !isStreaming && (value.trim().length > 0 || attachments.length > 0);
135
+ const submit = () => {
136
+ if (canSend)
137
+ onSubmit(value);
138
+ };
139
+ const pick = (index) => {
140
+ if (commandOpen) {
141
+ const command = commandOptions[index];
142
+ if (!command)
143
+ return;
144
+ const next = commandText(command);
145
+ pendingCaret.current = next.length;
146
+ onChange(next);
147
+ onCommand === null || onCommand === void 0 ? void 0 : onCommand(command);
148
+ return;
149
+ }
150
+ if (mentionOpen && mentionMatch && mention) {
151
+ const item = mention.items[index];
152
+ if (!item)
153
+ return;
154
+ const insert = formatMention ? formatMention(item) : `@${item.label}`;
155
+ const next = applyMention(value, mentionMatch.start, caret, insert);
156
+ pendingCaret.current = next.caret;
157
+ onChange(next.value);
158
+ onMentionSelect === null || onMentionSelect === void 0 ? void 0 : onMentionSelect(item);
159
+ }
160
+ };
161
+ const syncCaret = () => { var _a, _b; return setCaret((_b = (_a = textareaRef.current) === null || _a === void 0 ? void 0 : _a.selectionStart) !== null && _b !== void 0 ? _b : value.length); };
162
+ const onKeyDown = (event) => {
163
+ if (composing.current || event.nativeEvent.isComposing || event.keyCode === 229)
164
+ return;
165
+ if (menuOpen) {
166
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
167
+ if (options.length === 0)
168
+ return;
169
+ event.preventDefault();
170
+ const step = event.key === "ArrowDown" ? 1 : -1;
171
+ setActiveIndex((active + step + options.length) % options.length);
172
+ return;
173
+ }
174
+ if ((event.key === "Enter" && !event.shiftKey) || event.key === "Tab") {
175
+ if (options.length > 0) {
176
+ event.preventDefault();
177
+ pick(active);
178
+ return;
179
+ }
180
+ }
181
+ if (event.key === "Escape") {
182
+ event.preventDefault();
183
+ event.stopPropagation();
184
+ setDismissedFor(value);
185
+ return;
186
+ }
187
+ }
188
+ if (event.key === "Enter" && !event.shiftKey) {
189
+ event.preventDefault();
190
+ submit();
191
+ }
192
+ };
193
+ const passFiles = (list) => {
194
+ if (!onAttach || disabled)
195
+ return false;
196
+ const files = Array.from(list !== null && list !== void 0 ? list : []).filter((file) => matchesAccept(file, accept));
197
+ if (files.length)
198
+ onAttach(files);
199
+ return files.length > 0;
200
+ };
201
+ const onPaste = (event) => {
202
+ var _a;
203
+ const files = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.files;
204
+ if (!files || files.length === 0)
205
+ return;
206
+ const passed = passFiles(files);
207
+ if (passed && !event.clipboardData.getData("text/plain"))
208
+ event.preventDefault();
209
+ };
210
+ const dropHandlers = onAttach
211
+ ? {
212
+ onDragOver: (event) => {
213
+ if (!hasFiles(event) || disabled)
214
+ return;
215
+ event.preventDefault();
216
+ setDragging(true);
217
+ },
218
+ onDragLeave: (event) => {
219
+ if (!event.currentTarget.contains(event.relatedTarget))
220
+ setDragging(false);
221
+ },
222
+ onDrop: (event) => {
223
+ if (!hasFiles(event))
224
+ return;
225
+ event.preventDefault();
226
+ setDragging(false);
227
+ passFiles(event.dataTransfer.files);
228
+ },
229
+ }
230
+ : {};
231
+ const showCounter = maxLength !== undefined && value.length >= maxLength * COUNTER_FROM;
232
+ const counterInk = maxLength !== undefined && value.length >= maxLength ? colors.semanticText.error : tokens.muted;
233
+ const brand = assistantTone(colors, "info");
234
+ const attachmentChip = (attachment) => {
235
+ var _a;
236
+ const kind = (_a = attachment.kind) !== null && _a !== void 0 ? _a : (attachment.previewUrl ? "image" : "file");
237
+ const Icon = ATTACHMENT_ICON[kind];
238
+ return (_jsxs(Flex, { as: "li", align: "center", gap: 1.5, maxW: "14rem", pl: attachment.previewUrl ? 1 : 2, pr: onRemoveAttachment ? 0.5 : 2, py: 1, borderWidth: BORDER_WIDTHS.hairline, borderColor: tokens.rule, borderRadius: RADIUS_ROLE.control, "data-testid": `${testId}-attachment`, children: [attachment.previewUrl ? (_jsx(Image, { src: attachment.previewUrl, alt: "", boxSize: 7, objectFit: "cover", borderRadius: RADIUS_ROLE.option, flexShrink: 0 })) : (_jsx(Box, { as: Icon, "aria-hidden": "true", boxSize: 4, flexShrink: 0, color: tokens.muted })), _jsx(Text, { fontSize: "xs", color: tokens.body, noOfLines: 1, title: attachment.name, children: attachment.name }), onRemoveAttachment ? (_jsx(IconButton, { "aria-label": text.removeAttachment(attachment.name), icon: _jsx(X, { size: 12 }), size: "xs", variant: "ghost", colorScheme: "gray", isDisabled: disabled, onClick: () => onRemoveAttachment(attachment.id) })) : null] }, attachment.id));
239
+ };
240
+ return (_jsxs(Box, { "data-testid": testId, children: [_jsxs(Box, { position: "relative", children: [menuOpen ? (_jsx(ComposerMenu, { id: menuId, label: commandOpen ? text.commands : text.mentions, options: options, activeIndex: active, onActiveChange: setActiveIndex, onPick: pick, isLoading: !commandOpen && Boolean(mention === null || mention === void 0 ? void 0 : mention.loading) && options.length === 0, status: !commandOpen && mention && options.length === 0
241
+ ? mention.loading
242
+ ? text.mentionLoading
243
+ : text.mentionEmpty
244
+ : undefined })) : null, _jsxs(Box, { ...fieldBoxStyles(colors), position: "relative", borderRadius: RADIUS_ROLE.card, bg: disabled ? colors.background[100] : colors.background[50], _focusWithin: { borderColor: colors.primary[500], ...fieldFocusVisible(colors) }, ...dropHandlers, "data-dragging": dragging || undefined, children: [header ? _jsx(Box, { px: 3, pt: 2.5, children: header }) : null, attachments.length ? (_jsx(Flex, { as: "ul", "aria-label": text.attachments, listStyleType: "none", wrap: "wrap", gap: 1.5, px: 3, pt: 2.5, m: 0, children: attachments.map(attachmentChip) })) : null, _jsx(Textarea, { ref: ref, variant: "unstyled", value: value, rows: 1, resize: "none", minH: 0, px: 3, pt: 2.5, pb: 1, fontSize: "sm", lineHeight: 1.43, color: colors.text[900], placeholder: placeholder, maxLength: maxLength, autoFocus: autoFocus, isDisabled: disabled, "aria-label": text.input, "aria-autocomplete": (commands === null || commands === void 0 ? void 0 : commands.length) || onMentionQuery ? "list" : undefined, "aria-controls": menuOpen && options.length ? menuId : undefined, "aria-activedescendant": menuOpen && options.length ? optionId(menuId, active) : undefined, "aria-describedby": showCounter ? counterId : undefined, _placeholder: { color: placeholderInk(colors), opacity: 1 },
245
+ // The composer box draws the focus state (focus-within), so the bare field draws none of its own.
246
+ sx: { ...scrollbarStyles(colors), "&:focus, &:focus-visible": { outline: "none", boxShadow: "none" } }, onChange: (event) => {
247
+ var _a;
248
+ setCaret((_a = event.target.selectionStart) !== null && _a !== void 0 ? _a : event.target.value.length);
249
+ onChange(event.target.value);
250
+ }, onKeyDown: onKeyDown, onKeyUp: syncCaret, onClick: syncCaret, onSelect: syncCaret, onPaste: onPaste, onCompositionStart: () => {
251
+ composing.current = true;
252
+ }, onCompositionEnd: () => {
253
+ composing.current = false;
254
+ } }), _jsxs(Flex, { align: "center", gap: 1, px: 2, pb: 2, children: [onAttach ? (_jsxs(_Fragment, { children: [_jsx(ToolTip, { label: text.attach, children: _jsx(IconButton, { "aria-label": text.attach, icon: _jsx(Paperclip, { size: 16 }), size: "sm", variant: "ghost", colorScheme: "gray", isDisabled: disabled, onClick: () => { var _a; return (_a = fileRef.current) === null || _a === void 0 ? void 0 : _a.click(); } }) }), _jsx("input", { ref: fileRef, type: "file", multiple: true, hidden: true, accept: accept, tabIndex: -1, "aria-hidden": "true", "data-testid": `${testId}-file-input`, onChange: (event) => {
255
+ passFiles(event.target.files);
256
+ event.target.value = "";
257
+ } })] })) : null, (voice === null || voice === void 0 ? void 0 : voice.supported) ? (_jsx(ToolTip, { label: voice.listening ? text.voiceStop : text.voiceStart, children: _jsx(IconButton, { "aria-label": voice.listening ? text.voiceStop : text.voiceStart, "aria-pressed": voice.listening, icon: voice.listening ? _jsx(MicOff, { size: 16 }) : _jsx(Mic, { size: 16 }), size: "sm", variant: voice.listening ? "solid" : "ghost", colorScheme: voice.listening ? "red" : "gray", isDisabled: disabled, onClick: voice.onToggle }) })) : null, _jsx(Box, { flex: "1" }), showCounter && maxLength !== undefined ? (_jsxs(Text, { id: counterId, fontSize: "xs", color: counterInk, sx: NUMERIC_TEXT, "data-testid": `${testId}-counter`, children: [_jsxs("span", { "aria-hidden": "true", children: [value.length, "/", maxLength] }), _jsx(VisuallyHidden, { children: text.counter(value.length, maxLength) })] })) : null, isStreaming ? (_jsx(ToolTip, { label: text.stop, children: _jsx(IconButton, { "aria-label": text.stop, icon: _jsx(Square, { size: 14, fill: "currentColor" }), size: "sm", variant: "outline", colorScheme: "gray", isDisabled: disabled || !onStop, onClick: onStop }) })) : (_jsx(ToolTip, { label: text.send, children: _jsx(IconButton, { "aria-label": text.send, icon: _jsx(ArrowUp, { size: 16 }), size: "sm", variant: "solid", colorScheme: "primary", isDisabled: !canSend, onClick: submit }) }))] }), dragging ? (_jsx(Flex, { position: "absolute", inset: 0, align: "center", justify: "center", borderRadius: RADIUS_ROLE.card, bg: brand.bg, borderWidth: BORDER_WIDTHS.thick, borderStyle: "dashed", borderColor: brand.ink, color: brand.ink, fontSize: "sm", fontWeight: 600, pointerEvents: "none", children: text.dropHint })) : null] })] }), footer ? (_jsx(Box, { mt: 1.5, px: 1, fontSize: "xs", color: tokens.muted, children: footer })) : null] }));
258
+ };
259
+ export default memo(AssistantComposer);
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from "react";
3
+ import { Box, Flex, Text } from "@chakra-ui/react";
4
+ import { useCustomTheme } from "../../../Theme/useCustomTheme.js";
5
+ import { listRowBackgrounds } from "../../../Theme/tokens/builders/rowStates.js";
6
+ import { scrollbarStyles } from "../../../Theme/tokens/builders/scrollbar.js";
7
+ import { BORDER_WIDTHS } from "../../../Theme/tokens/primitives/borderWidths.js";
8
+ import { RADIUS_ROLE } from "../../../Theme/tokens/primitives/radii.js";
9
+ import zIndices from "../../../Theme/tokens/primitives/zIndices.js";
10
+ import Spinner from "../../Spinner/Spinner.js";
11
+ import { optionRowFill, optionRowDescriptionInk } from "../../Select/optionRowInk.js";
12
+ import { assistantTokens } from "../assistantStyles.js";
13
+ export const optionId = (menuId, index) => `${menuId}-option-${index}`;
14
+ /** The listbox the composer opens above its field; focus stays in the field (aria-activedescendant). */
15
+ export const ComposerMenu = ({ id, label, options, activeIndex, onActiveChange, onPick, status, isLoading }) => {
16
+ const { colors } = useCustomTheme();
17
+ const tokens = assistantTokens(colors);
18
+ const rows = listRowBackgrounds(colors);
19
+ const listRef = useRef(null);
20
+ useEffect(() => {
21
+ var _a, _b;
22
+ const active = (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument.getElementById(optionId(id, activeIndex));
23
+ (_b = active === null || active === void 0 ? void 0 : active.scrollIntoView) === null || _b === void 0 ? void 0 : _b.call(active, { block: "nearest" });
24
+ }, [id, activeIndex]);
25
+ return (_jsxs(Box, { position: "absolute", left: 0, right: 0, bottom: "100%", mb: 2, zIndex: zIndices.dropdown, bg: tokens.surface, borderWidth: BORDER_WIDTHS.hairline, borderColor: tokens.rule, borderRadius: RADIUS_ROLE.float, boxShadow: "md", overflow: "hidden", "data-testid": `${id}-menu`, children: [status || isLoading ? (_jsxs(Flex, { align: "center", gap: 2, px: 3, py: 2, fontSize: "sm", color: tokens.muted, role: "status", children: [isLoading ? _jsx(Spinner, { size: "xs", label: "", "aria-hidden": "true" }) : null, status] })) : null, options.length ? (_jsx(Box, { ref: listRef, id: id, role: "listbox", "aria-label": label, maxH: "16rem", overflowY: "auto", p: 1, sx: scrollbarStyles(colors), children: options.map((option, index) => {
26
+ const Icon = option.icon;
27
+ const active = index === activeIndex;
28
+ return (_jsxs(Flex, { id: optionId(id, index), role: "option", "aria-selected": active, align: "center", gap: 2.5, px: 2.5, py: 1.5, cursor: "pointer", borderRadius: RADIUS_ROLE.option, bg: optionRowFill(rows, active), onMouseDown: (event) => event.preventDefault(), onMouseMove: () => (active ? undefined : onActiveChange(index)), onClick: () => onPick(index), children: [Icon ? _jsx(Box, { as: Icon, "aria-hidden": "true", boxSize: 4, flexShrink: 0, color: tokens.muted }) : null, _jsxs(Box, { flex: "1", minW: 0, children: [_jsxs(Text, { fontSize: "sm", color: colors.text[800], noOfLines: 1, children: [option.prefix ? (_jsx(Text, { as: "span", fontFamily: "mono", color: tokens.muted, mr: 1.5, children: option.prefix })) : null, option.label] }), option.description ? (_jsx(Text, { fontSize: "xs", color: optionRowDescriptionInk(colors), noOfLines: 1, children: option.description })) : null] }), option.trailing ? (_jsx(Text, { fontSize: "xs", color: tokens.muted, flexShrink: 0, children: option.trailing })) : null] }, option.key));
29
+ }) })) : null] }));
30
+ };
@@ -0,0 +1,56 @@
1
+ /** True when `file` passes an `<input accept>`-style list (".pdf", "image/*", "text/plain"). Empty accepts all. */
2
+ export const matchesAccept = (file, accept) => {
3
+ const tokens = (accept !== null && accept !== void 0 ? accept : "")
4
+ .split(",")
5
+ .map((t) => t.trim().toLowerCase())
6
+ .filter(Boolean);
7
+ if (tokens.length === 0)
8
+ return true;
9
+ const name = file.name.toLowerCase();
10
+ const type = (file.type || "").toLowerCase();
11
+ return tokens.some((token) => {
12
+ if (token.startsWith("."))
13
+ return name.endsWith(token);
14
+ if (token.endsWith("/*"))
15
+ return type.startsWith(token.slice(0, -1));
16
+ return type === token;
17
+ });
18
+ };
19
+ const normalise = (command) => command.replace(/^\/+/, "");
20
+ /** The text after "/" while the whole value is a slash plus one word, else null. */
21
+ export const commandQuery = (value) => {
22
+ const match = /^\/(\S*)$/.exec(value);
23
+ return match ? match[1] : null;
24
+ };
25
+ /** Commands whose word or label starts with (then contains) the query, prefix matches first. */
26
+ export const filterCommands = (commands, query) => {
27
+ const q = query.toLowerCase();
28
+ const scored = commands
29
+ .map((command) => {
30
+ const word = normalise(command.command).toLowerCase();
31
+ const label = command.label.toLowerCase();
32
+ if (word.startsWith(q) || label.startsWith(q))
33
+ return { command, rank: 0 };
34
+ if (word.includes(q) || label.includes(q))
35
+ return { command, rank: 1 };
36
+ return null;
37
+ })
38
+ .filter((x) => x !== null);
39
+ return scored.sort((a, b) => a.rank - b.rank).map((x) => x.command);
40
+ };
41
+ /** The text a picked command leaves in the field. */
42
+ export const commandText = (command) => `/${normalise(command.command)} `;
43
+ /** The "@query" being typed right before the caret, with where it starts, else null. */
44
+ export const mentionAt = (value, caret) => {
45
+ const before = value.slice(0, Math.max(0, Math.min(caret, value.length)));
46
+ const match = /(^|\s)@([^\s@]{0,40})$/.exec(before);
47
+ if (!match)
48
+ return null;
49
+ return { query: match[2], start: before.length - match[2].length - 1 };
50
+ };
51
+ /** Replaces "@query" (from `start` up to `caret`) with `insert` plus a space; returns the text and the new caret. */
52
+ export const applyMention = (value, start, caret, insert) => {
53
+ const head = `${value.slice(0, start)}${insert} `;
54
+ const tail = value.slice(caret).replace(/^ /, "");
55
+ return { value: head + tail, caret: head.length };
56
+ };
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { memo } from "react";
3
+ import { Flex } from "@chakra-ui/react";
4
+ import { Plus, X } from "lucide-react";
5
+ import Tag from "../../Tag/Tag.js";
6
+ import Button from "../../Button/Button.js";
7
+ const DEFAULT_LABELS = {
8
+ group: "Context",
9
+ add: "Add context",
10
+ remove: (label) => `Remove ${label}`,
11
+ };
12
+ /** Removable context chips (built on `Tag`) plus an optional Add button. */
13
+ const AssistantContextBar = ({ items, onRemove, onAdd, labels, "data-testid": testId = "assistant-context-bar", }) => {
14
+ const text = { ...DEFAULT_LABELS, ...labels };
15
+ if (items.length === 0 && !onAdd)
16
+ return null;
17
+ return (_jsxs(Flex, { role: "group", "aria-label": text.group, wrap: "wrap", align: "center", gap: 1.5, "data-testid": testId, children: [items.map((item) => {
18
+ const removable = Boolean(onRemove) && item.removable !== false;
19
+ return (_jsx(Tag, { label: item.label, size: "sm", variant: "outline", colorScheme: "gray", maxW: "14rem", leadingIcon: item.icon, icon: removable ? X : undefined, onIconClick: removable ? () => onRemove === null || onRemove === void 0 ? void 0 : onRemove(item.id) : undefined, removeLabel: text.remove, "data-testid": `${testId}-item` }, item.id));
20
+ }), onAdd ? (_jsx(Button, { size: "xs", variant: "ghost", colorScheme: "gray", leftIcon: _jsx(Plus, { size: 14 }), label: text.add, onClick: onAdd })) : null] }));
21
+ };
22
+ export default memo(AssistantContextBar);
@@ -0,0 +1,118 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { memo, useId, useMemo, useRef, useState } from "react";
3
+ import { Box, Flex, Menu, MenuButton, MenuItem, MenuList, Portal, Text } from "@chakra-ui/react";
4
+ import { MessageSquare, MoreHorizontal, Pencil, Pin, PinOff, Search as SearchIcon, Trash2 } from "lucide-react";
5
+ import { useCustomTheme } from "../../../Theme/useCustomTheme.js";
6
+ import { focusVisibleStyles } from "../../../Theme/chakra/focusRing.styles.js";
7
+ import { listRowBackgrounds } from "../../../Theme/tokens/builders/rowStates.js";
8
+ import { transitionFor } from "../../../Theme/tokens/primitives/motion.js";
9
+ import { RADIUS_ROLE } from "../../../Theme/tokens/primitives/radii.js";
10
+ import AlertDialog from "../../AlertDialog/AlertDialog.js";
11
+ import EmptyState from "../../EmptyState/EmptyState.js";
12
+ import IconButton from "../../IconButton/IconButton.js";
13
+ import TextInput from "../../Input/TextInput.js";
14
+ import Skeletons from "../../Skeletons/Skeletons.js";
15
+ import VisuallyHidden from "../../VisuallyHidden/VisuallyHidden.js";
16
+ import { assistantTokens } from "../assistantStyles.js";
17
+ import { groupConversations } from "./groupConversations.js";
18
+ const DEFAULT_GROUPS = { pinned: "Pinned", today: "Today", yesterday: "Yesterday", week: "Previous 7 days", older: "Older" };
19
+ const DEFAULT_LABELS = {
20
+ region: "Conversation history",
21
+ search: "Search conversations",
22
+ actions: (title) => `Actions for ${title}`,
23
+ rename: "Rename",
24
+ pin: "Pin",
25
+ unpin: "Unpin",
26
+ delete: "Delete",
27
+ renameField: "Conversation title",
28
+ deleteTitle: "Delete conversation?",
29
+ deleteBody: (title) => `“${title}” will be deleted. This can't be undone.`,
30
+ deleteConfirm: "Delete",
31
+ cancel: "Cancel",
32
+ empty: "No conversations yet",
33
+ emptyDescription: "Your conversations with the assistant show up here.",
34
+ noMatches: (query) => `No conversations match “${query}”`,
35
+ loading: "Loading conversations",
36
+ untitled: "Untitled conversation",
37
+ };
38
+ const ROW_TRANSITION = transitionFor(["background-color"]);
39
+ const LOADING_ROWS = [0, 1, 2, 3, 4];
40
+ /** Recency-grouped conversation list with local search, inline rename, pin and confirmed delete. */
41
+ const AssistantHistoryList = ({ conversations, activeId, onSelect, onRename, onTogglePin, onDelete, now, isLoading = false, searchable = true, groupHeadingAs = "h3", labels, "data-testid": testId = "assistant-history", }) => {
42
+ const { colors } = useCustomTheme();
43
+ const tokens = assistantTokens(colors);
44
+ const rows = listRowBackgrounds(colors);
45
+ const text = { ...DEFAULT_LABELS, ...labels };
46
+ const groupText = { ...DEFAULT_GROUPS, ...labels === null || labels === void 0 ? void 0 : labels.groups };
47
+ const baseId = useId();
48
+ const [query, setQuery] = useState("");
49
+ const [editingId, setEditingId] = useState(null);
50
+ const [draft, setDraft] = useState("");
51
+ const [pendingDelete, setPendingDelete] = useState(null);
52
+ const [deleting, setDeleting] = useState(false);
53
+ const cancelRef = useRef(null);
54
+ const [nowAtMount] = useState(() => Date.now());
55
+ const trimmed = query.trim().toLowerCase();
56
+ const filtered = useMemo(() => (trimmed ? conversations.filter((c) => (c.title || "").toLowerCase().includes(trimmed)) : conversations), [conversations, trimmed]);
57
+ const groups = useMemo(() => groupConversations(filtered, now !== null && now !== void 0 ? now : nowAtMount), [filtered, now, nowAtMount]);
58
+ const hasMenu = Boolean(onRename || onTogglePin || onDelete);
59
+ const titleOf = (c) => c.title.trim() || text.untitled;
60
+ const startRename = (c) => {
61
+ setEditingId(c.id);
62
+ setDraft(c.title);
63
+ };
64
+ const commitRename = (c) => {
65
+ const next = draft.trim();
66
+ setEditingId(null);
67
+ if (next && next !== c.title.trim())
68
+ onRename === null || onRename === void 0 ? void 0 : onRename(c.id, next);
69
+ };
70
+ const onRenameKey = (c) => (event) => {
71
+ if (event.key === "Enter") {
72
+ event.preventDefault();
73
+ commitRename(c);
74
+ }
75
+ else if (event.key === "Escape") {
76
+ event.preventDefault();
77
+ event.stopPropagation();
78
+ setEditingId(null);
79
+ }
80
+ };
81
+ const confirmDelete = async () => {
82
+ if (!pendingDelete)
83
+ return;
84
+ setDeleting(true);
85
+ try {
86
+ await (onDelete === null || onDelete === void 0 ? void 0 : onDelete(pendingDelete.id));
87
+ setPendingDelete(null);
88
+ }
89
+ catch {
90
+ // The app reports the failure; the dialog stays open so the person can retry or cancel.
91
+ }
92
+ finally {
93
+ setDeleting(false);
94
+ }
95
+ };
96
+ const renderRow = (c) => {
97
+ const isActive = c.id === activeId;
98
+ const title = titleOf(c);
99
+ return (_jsx("li", { children: _jsxs(Flex, { align: "center", gap: 1, pl: editingId === c.id ? 1 : 0, pr: 1, borderRadius: RADIUS_ROLE.option, bg: isActive ? rows.selected : "transparent", transition: ROW_TRANSITION, _hover: { bg: isActive ? rows.selectedActive : rows.active }, "data-testid": `${testId}-row`, "data-active": isActive || undefined, children: [editingId === c.id ? (_jsx(Box, { flex: "1", minW: 0, py: 1, children: _jsx(TextInput, { "aria-label": text.renameField, value: draft, size: "xs", autoFocus: true, onChange: (e) => setDraft(e.target.value), onKeyDown: onRenameKey(c), onBlur: () => commitRename(c) }) })) : (_jsx(Box, { as: "button", type: "button", flex: "1", minW: 0, textAlign: "start", px: 2.5, py: 2, borderRadius: RADIUS_ROLE.option, fontSize: "sm", fontWeight: isActive ? 500 : 400, color: isActive ? tokens.heading : tokens.body, "aria-current": isActive ? "true" : undefined, sx: focusVisibleStyles(colors), onClick: () => onSelect(c.id), children: _jsx(Text, { as: "span", display: "block", noOfLines: 1, children: title }) })), c.pinned ? (_jsx(Box, { as: Pin, "aria-hidden": "true", boxSize: 3.5, flexShrink: 0, color: tokens.muted })) : null, hasMenu && editingId !== c.id ? (_jsxs(Menu, { isLazy: true, placement: "bottom-end", children: [_jsx(MenuButton, { as: IconButton, "aria-label": text.actions(title), icon: _jsx(MoreHorizontal, { size: 16 }), size: "xs", variant: "ghost", colorScheme: "gray", flexShrink: 0 }), _jsx(Portal, { children: _jsxs(MenuList, { minW: "10rem", fontSize: "sm", children: [onRename ? (_jsx(MenuItem, { icon: _jsx(Pencil, { size: 14 }), onClick: () => startRename(c), children: text.rename })) : null, onTogglePin ? (_jsx(MenuItem, { icon: c.pinned ? _jsx(PinOff, { size: 14 }) : _jsx(Pin, { size: 14 }), onClick: () => onTogglePin(c.id), children: c.pinned ? text.unpin : text.pin })) : null, onDelete ? (_jsx(MenuItem, { icon: _jsx(Trash2, { size: 14 }), color: colors.semanticText.error, onClick: () => setPendingDelete(c), children: text.delete })) : null] }) })] })) : null] }) }, c.id));
100
+ };
101
+ const body = () => {
102
+ if (isLoading) {
103
+ return (_jsxs(Flex, { direction: "column", gap: 2, px: 1, "aria-busy": "true", "data-testid": `${testId}-loading`, children: [_jsx(VisuallyHidden, { role: "status", children: text.loading }), LOADING_ROWS.map((row) => (_jsx(Skeletons, { type: "skeleton", height: "2rem", width: row % 2 ? "70%" : "90%", borderRadius: RADIUS_ROLE.option }, row)))] }));
104
+ }
105
+ if (conversations.length === 0) {
106
+ return _jsx(EmptyState, { size: "sm", icon: MessageSquare, title: text.empty, description: text.emptyDescription, titleAs: "p" });
107
+ }
108
+ if (groups.length === 0) {
109
+ return _jsx(EmptyState, { size: "sm", icon: SearchIcon, title: text.noMatches(query.trim()), titleAs: "p" });
110
+ }
111
+ return groups.map((group) => {
112
+ const headingId = `${baseId}-${group.key}`;
113
+ return (_jsxs(Box, { role: "group", "aria-labelledby": headingId, children: [_jsx(Text, { id: headingId, as: groupHeadingAs, px: 2.5, pt: 3, pb: 1, fontSize: "xs", fontWeight: 600, color: tokens.muted, children: groupText[group.key] }), _jsx(Box, { as: "ul", listStyleType: "none", m: 0, p: 0, children: group.items.map(renderRow) })] }, group.key));
114
+ });
115
+ };
116
+ return (_jsxs(Box, { as: "nav", "aria-label": text.region, "data-testid": testId, p: 2, children: [searchable && !isLoading && conversations.length > 0 ? (_jsx(Box, { px: 1, pb: 1, children: _jsx(TextInput, { "aria-label": text.search, placeholder: text.search, value: query, size: "sm", isClearable: true, inputLeftIcon: _jsx(SearchIcon, { size: 14 }), onChange: (e) => setQuery(e.target.value) }) })) : null, body(), _jsx(AlertDialog, { isOpen: pendingDelete !== null, onClose: () => (deleting ? undefined : setPendingDelete(null)), leastDestructiveRef: cancelRef, isCentered: true, tone: "danger", title: text.deleteTitle, content: _jsx(Text, { fontSize: "sm", children: pendingDelete ? text.deleteBody(titleOf(pendingDelete)) : null }), confirmButtonText: text.deleteConfirm, cancelButtonText: text.cancel, isConfirmLoading: deleting, onConfirm: () => void confirmDelete() })] }));
117
+ };
118
+ export default memo(AssistantHistoryList);
@@ -0,0 +1,51 @@
1
+ const DAY_MS = 24 * 60 * 60 * 1000;
2
+ const toTime = (value) => {
3
+ if (value === undefined || value === null)
4
+ return null;
5
+ const time = value instanceof Date ? value.getTime() : typeof value === "number" ? value : Date.parse(value);
6
+ return Number.isFinite(time) ? time : null;
7
+ };
8
+ const startOfDay = (time) => {
9
+ const d = new Date(time);
10
+ d.setHours(0, 0, 0, 0);
11
+ return d.getTime();
12
+ };
13
+ /**
14
+ * Buckets conversations into Pinned / Today / Yesterday / Previous 7 days / Older, by local calendar day
15
+ * relative to `now`. Each bucket is newest first; a conversation without a parseable `updatedAt` is Older.
16
+ * Empty buckets are left out.
17
+ */
18
+ export const groupConversations = (conversations, now) => {
19
+ const today = startOfDay(now instanceof Date ? now.getTime() : now);
20
+ // Noon offsets keep a 23- or 25-hour DST day from shifting a boundary by a day.
21
+ const yesterday = startOfDay(today - DAY_MS / 2);
22
+ const weekStart = startOfDay(today - 7 * DAY_MS + DAY_MS / 2);
23
+ const buckets = {
24
+ pinned: [],
25
+ today: [],
26
+ yesterday: [],
27
+ week: [],
28
+ older: [],
29
+ };
30
+ const byRecency = [...conversations].sort((a, b) => { var _a, _b; return ((_a = toTime(b.updatedAt)) !== null && _a !== void 0 ? _a : -Infinity) - ((_b = toTime(a.updatedAt)) !== null && _b !== void 0 ? _b : -Infinity); });
31
+ byRecency.forEach((conversation) => {
32
+ if (conversation.pinned) {
33
+ buckets.pinned.push(conversation);
34
+ return;
35
+ }
36
+ const time = toTime(conversation.updatedAt);
37
+ if (time === null)
38
+ buckets.older.push(conversation);
39
+ else if (time >= today)
40
+ buckets.today.push(conversation);
41
+ else if (time >= yesterday)
42
+ buckets.yesterday.push(conversation);
43
+ else if (time >= weekStart)
44
+ buckets.week.push(conversation);
45
+ else
46
+ buckets.older.push(conversation);
47
+ });
48
+ return Object.keys(buckets)
49
+ .filter((key) => buckets[key].length > 0)
50
+ .map((key) => ({ key, items: buckets[key] }));
51
+ };
@@ -0,0 +1,16 @@
1
+ export { default as AssistantPanel } from "./panel/AssistantPanel.js";
2
+ export { default as AssistantLauncher } from "./launcher/AssistantLauncher.js";
3
+ export { default as AssistantThread } from "./thread/AssistantThread.js";
4
+ export { default as AssistantMessage } from "./message/AssistantMessage.js";
5
+ export { default as AssistantMarkdown } from "./markdown/AssistantMarkdown.js";
6
+ export { default as AssistantToolSteps } from "./steps/AssistantToolSteps.js";
7
+ export { default as AssistantProposalCard } from "./cards/AssistantProposalCard.js";
8
+ export { default as AssistantApprovalCard } from "./cards/AssistantApprovalCard.js";
9
+ export { default as AssistantSuggestions } from "./suggestions/AssistantSuggestions.js";
10
+ export { default as AssistantComposer } from "./composer/AssistantComposer.js";
11
+ export { default as AssistantWelcome } from "./welcome/AssistantWelcome.js";
12
+ export { default as AssistantHistoryList } from "./history/AssistantHistoryList.js";
13
+ export { default as AssistantContextBar } from "./context/AssistantContextBar.js";
14
+ export { default as AssistantSources } from "./sources/AssistantSources.js";
15
+ export { default as AssistantStatusBanner } from "./banner/AssistantStatusBanner.js";
16
+ export { default as AssistantTypingIndicator } from "./typing/AssistantTypingIndicator.js";
@@ -0,0 +1,40 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { memo } from "react";
3
+ import { Box, Flex, Text } from "@chakra-ui/react";
4
+ import { Sparkles } from "lucide-react";
5
+ import { useCustomTheme } from "../../../Theme/useCustomTheme.js";
6
+ import { focusVisibleStyles } from "../../../Theme/chakra/focusRing.styles.js";
7
+ import { resolveFilledSurface } from "../../../Theme/tokens/builders/filledSurface.js";
8
+ import { BORDER_WIDTHS } from "../../../Theme/tokens/primitives/borderWidths.js";
9
+ import { BUTTON_SIZES } from "../../../Theme/tokens/primitives/controlSizes.js";
10
+ import { transitionFor } from "../../../Theme/tokens/primitives/motion.js";
11
+ import { NUMERIC_TEXT } from "../../../Theme/tokens/primitives/typography.js";
12
+ import zIndices from "../../../Theme/tokens/primitives/zIndices.js";
13
+ import { KbdShortcut } from "../../Kbd/Kbd.js";
14
+ import Spinner from "../../Spinner/Spinner.js";
15
+ import ToolTip from "../../ToolTip/ToolTip.js";
16
+ import { assistantTokens } from "../assistantStyles.js";
17
+ const cssLength = (value) => (typeof value === "number" ? `${value}px` : value);
18
+ const PRESS = transitionFor(["background-color", "color"]);
19
+ /** Round floating button that opens the assistant, with a busy ring, an unread badge and a shortcut hint. */
20
+ const AssistantLauncher = ({ onClick, label = "Open assistant", icon: Icon = Sparkles, isOpen, "aria-controls": controls, busy = false, badge, badgeLabel = (b) => (b === true ? "new activity" : `${b} new`), shortcut, variant = "surface", positioning = "fixed", placement = "bottom-end", offset, "data-testid": testId = "assistant-launcher", }) => {
21
+ var _a, _b;
22
+ const { colors } = useCustomTheme();
23
+ const tokens = assistantTokens(colors);
24
+ const filled = resolveFilledSurface(colors.primary, colors);
25
+ const danger = resolveFilledSurface(colors.semantic.error, colors);
26
+ const hasBadge = badge === true || (typeof badge === "number" && badge > 0);
27
+ const count = typeof badge === "number" ? (badge > 99 ? "99+" : String(badge)) : "";
28
+ const name = hasBadge ? `${label}, ${badgeLabel(badge)}` : label;
29
+ const solid = variant === "solid";
30
+ const placed = positioning === "static"
31
+ ? {}
32
+ : {
33
+ position: positioning,
34
+ bottom: cssLength((_a = offset === null || offset === void 0 ? void 0 : offset.y) !== null && _a !== void 0 ? _a : "1.5rem"),
35
+ [placement === "bottom-end" ? "right" : "left"]: cssLength((_b = offset === null || offset === void 0 ? void 0 : offset.x) !== null && _b !== void 0 ? _b : "1.5rem"),
36
+ zIndex: zIndices.sticky,
37
+ };
38
+ return (_jsx(Box, { ...placed, display: "inline-flex", "data-testid": `${testId}-root`, children: _jsx(ToolTip, { placement: placement === "bottom-end" ? "left" : "right", label: shortcut ? (_jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Text, { as: "span", children: label }), _jsx(KbdShortcut, { shortcut: shortcut, size: "xs" })] })) : (label), children: _jsxs(Flex, { as: "button", type: "button", position: "relative", align: "center", justify: "center", boxSize: BUTTON_SIZES.lg.height, borderRadius: "full", bg: solid ? filled.fill : tokens.surface, color: solid ? filled.color : colors.accentText, borderWidth: solid ? 0 : BORDER_WIDTHS.hairline, borderColor: tokens.rule, boxShadow: "lg", transition: PRESS, _hover: { bg: solid ? filled.hoverFill : colors.background[100], color: solid ? filled.hoverColor : undefined }, sx: focusVisibleStyles(colors), "aria-label": name, "aria-expanded": isOpen, "aria-controls": controls, "aria-busy": busy || undefined, onClick: onClick, "data-testid": testId, "data-open": isOpen || undefined, children: [_jsx(Icon, { size: 22, "aria-hidden": "true" }), busy ? (_jsx(Spinner, { size: "xl", color: solid ? filled.color : colors.accentText, label: "", "aria-hidden": "true", position: "absolute", inset: 0, boxSize: "100%", thickness: "0.125rem", "data-testid": `${testId}-busy` })) : null, hasBadge ? (_jsx(Flex, { "aria-hidden": "true", position: "absolute", top: 0, right: 0, minW: count ? 5 : 3, h: count ? 5 : 3, px: count ? 1 : 0, align: "center", justify: "center", borderRadius: "full", bg: danger.fill, color: danger.color, borderWidth: BORDER_WIDTHS.thick, borderColor: solid ? colors.background[50] : tokens.surface, fontSize: "xs-minus", fontWeight: 700, lineHeight: 1, sx: NUMERIC_TEXT, "data-testid": `${testId}-badge`, children: count })) : null] }) }) }));
39
+ };
40
+ export default memo(AssistantLauncher);