@conscience-technology/ovenn 0.6.7 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/components/AIMessage/AIMessage.module.css +23 -1
- package/assets/components/AIMessage/AIMessage.tsx +27 -7
- package/assets/components/Accordion/Accordion.module.css +3 -0
- package/assets/components/AppFrame/AppFrame.module.css +2 -0
- package/assets/components/AttachmentItem/AttachmentItem.module.css +50 -13
- package/assets/components/AttachmentItem/AttachmentItem.tsx +25 -8
- package/assets/components/AttachmentThumb/AttachmentThumb.module.css +12 -9
- package/assets/components/Avatar/Avatar.module.css +26 -11
- package/assets/components/Avatar/Avatar.tsx +1 -1
- package/assets/components/AvatarUpload/AvatarUpload.module.css +4 -3
- package/assets/components/Badge/Badge.module.css +96 -70
- package/assets/components/Badge/Badge.tsx +33 -25
- package/assets/components/Breadcrumb/Breadcrumb.module.css +8 -4
- package/assets/components/Breadcrumb/Breadcrumb.tsx +1 -1
- package/assets/components/Bubble/Bubble.module.css +6 -0
- package/assets/components/Button/Button.module.css +6 -0
- package/assets/components/Calendar/Calendar.module.css +244 -0
- package/assets/components/Calendar/Calendar.tsx +419 -0
- package/assets/components/Calendar/index.ts +2 -0
- package/assets/components/Callout/Callout.module.css +54 -7
- package/assets/components/Callout/Callout.tsx +26 -2
- package/assets/components/Callout/index.ts +1 -1
- package/assets/components/Canvas/Canvas.module.css +75 -0
- package/assets/components/Canvas/Canvas.tsx +699 -0
- package/assets/components/Canvas/alignment.ts +34 -0
- package/assets/components/Canvas/clipboard.ts +30 -0
- package/assets/components/Canvas/collision.ts +67 -0
- package/assets/components/Canvas/edgeOptions.ts +11 -0
- package/assets/components/Canvas/graph.ts +11 -0
- package/assets/components/Canvas/history.ts +41 -0
- package/assets/components/Canvas/index.ts +4 -0
- package/assets/components/Canvas/selection.ts +56 -0
- package/assets/components/Canvas/tokens.css +61 -0
- package/assets/components/Canvas/types.ts +27 -0
- package/assets/components/Canvas/useCanvasSettlement.ts +79 -0
- package/assets/components/CanvasEdge/CanvasEdge.module.css +62 -0
- package/assets/components/CanvasEdge/CanvasEdge.tsx +121 -0
- package/assets/components/CanvasEdge/geometry.ts +350 -0
- package/assets/components/CanvasEdge/index.ts +4 -0
- package/assets/components/CanvasEdge/interactions.ts +14 -0
- package/assets/components/CanvasEdge/tokens.css +29 -0
- package/assets/components/CanvasNode/CanvasNode.module.css +234 -30
- package/assets/components/CanvasNode/CanvasNode.tsx +95 -28
- package/assets/components/CanvasNode/index.ts +1 -1
- package/assets/components/CanvasNode/runningOutline.ts +59 -0
- package/assets/components/CanvasNode/tokens.css +76 -13
- package/assets/components/Card/Card.module.css +5 -0
- package/assets/components/Chart/Chart.module.css +278 -0
- package/assets/components/Chart/Chart.tsx +385 -0
- package/assets/components/Chart/entrance.tsx +57 -0
- package/assets/components/Chart/index.ts +14 -0
- package/assets/components/ChatComposer/ChatComposer.module.css +17 -0
- package/assets/components/ChatComposer/ChatComposer.tsx +131 -0
- package/assets/components/ChatComposer/index.ts +2 -0
- package/assets/components/ChatInput/ChatInput.module.css +197 -30
- package/assets/components/ChatInput/ChatInput.tsx +137 -45
- package/assets/components/ChatInput/SendButton.tsx +4 -1
- package/assets/components/ChatInput/index.ts +5 -0
- package/assets/components/ChatMessage/ChatMessage.module.css +19 -0
- package/assets/components/ChatMessage/ChatMessage.tsx +63 -0
- package/assets/components/ChatMessage/index.ts +2 -0
- package/assets/components/ChatReactions/ChatReactions.module.css +15 -0
- package/assets/components/ChatReactions/ChatReactions.tsx +58 -0
- package/assets/components/ChatReactions/index.ts +2 -0
- package/assets/components/Checkbox/Checkbox.module.css +39 -0
- package/assets/components/Checkbox/Checkbox.tsx +99 -14
- package/assets/components/Checkbox/index.ts +1 -1
- package/assets/components/CheckboxCard/CheckboxCard.module.css +1 -177
- package/assets/components/CheckboxCard/CheckboxCard.tsx +6 -72
- package/assets/components/Chip/Chip.module.css +20 -30
- package/assets/components/Code/Code.module.css +1 -0
- package/assets/components/CodeBlock/CodeBlock.module.css +113 -13
- package/assets/components/CodeBlock/CodeBlock.tsx +114 -29
- package/assets/components/CodeBlock/SyntaxHighlight.tsx +20 -0
- package/assets/components/CodeBlock/diff-lines.ts +21 -0
- package/assets/components/CodeBlock/index.ts +2 -1
- package/assets/components/CodeBlock/line-preview.ts +7 -0
- package/assets/components/CodeBlock/syntax-highlighter.ts +96 -0
- package/assets/components/CodeBlock/use-syntax-tokens.ts +17 -0
- package/assets/components/ColorArea/ColorArea.module.css +3 -0
- package/assets/components/ColorField/ColorField.module.css +19 -190
- package/assets/components/ColorField/ColorField.tsx +116 -107
- package/assets/components/ColorPicker/ColorPicker.module.css +310 -0
- package/assets/components/ColorPicker/ColorPicker.tsx +387 -0
- package/assets/components/ColorPicker/index.ts +16 -0
- package/assets/components/ColorSlider/ColorSlider.module.css +15 -12
- package/assets/components/ColorSlider/ColorSlider.tsx +3 -3
- package/assets/components/ColorSwatch/ColorSwatch.module.css +2 -2
- package/assets/components/ColorSwatchPicker/ColorSwatchPicker.module.css +4 -3
- package/assets/components/Combobox/Combobox.module.css +21 -4
- package/assets/components/Combobox/Combobox.tsx +38 -22
- package/assets/components/CommandPalette/CommandPalette.module.css +19 -24
- package/assets/components/CommandPalette/CommandPalette.tsx +7 -5
- package/assets/components/Comment/Comment.module.css +25 -0
- package/assets/components/Comment/Comment.tsx +44 -0
- package/assets/components/Comment/CommentComposer.module.css +26 -0
- package/assets/components/Comment/CommentComposer.tsx +56 -0
- package/assets/components/Comment/CommentEditor.module.css +8 -0
- package/assets/components/Comment/CommentEditor.tsx +43 -0
- package/assets/components/Comment/CommentMentionInput.module.css +9 -0
- package/assets/components/Comment/CommentMentionInput.tsx +150 -0
- package/assets/components/Comment/index.ts +9 -0
- package/assets/components/Comment/types.ts +1 -0
- package/assets/components/ContextMenu/ContextMenu.module.css +5 -2
- package/assets/components/ContextMenu/ContextMenu.tsx +5 -0
- package/assets/components/ControlGroup/ControlGroup.module.css +20 -7
- package/assets/components/DataTable/DataTable.module.css +2 -0
- package/assets/components/DatePicker/DateField.tsx +72 -25
- package/assets/components/DatePicker/DatePicker.module.css +56 -54
- package/assets/components/DatePicker/DatePicker.tsx +86 -40
- package/assets/components/DatePicker/TimeSelector.tsx +1 -1
- package/assets/components/Disclosure/Disclosure.module.css +1 -0
- package/assets/components/Drawer/Drawer.module.css +23 -19
- package/assets/components/Drawer/Drawer.tsx +20 -24
- package/assets/components/DropdownMenu/DropdownMenu.tsx +5 -0
- package/assets/components/EmojiPicker/EmojiGlyph.module.css +2 -0
- package/assets/components/EmojiPicker/EmojiGlyph.tsx +12 -0
- package/assets/components/EmojiPicker/EmojiPicker.module.css +43 -0
- package/assets/components/EmojiPicker/EmojiPicker.tsx +143 -0
- package/assets/components/EmojiPicker/UNICODE-LICENSE.txt +39 -0
- package/assets/components/EmojiPicker/data.ts +41 -0
- package/assets/components/EmojiPicker/emojiData-0.json +1 -0
- package/assets/components/EmojiPicker/emojiData-1.json +1 -0
- package/assets/components/EmojiPicker/emojiData-2.json +1 -0
- package/assets/components/EmojiPicker/emojiData-3.json +1 -0
- package/assets/components/EmojiPicker/emojiData.sources.json +35 -0
- package/assets/components/EmojiPicker/emojiData.ts +8 -0
- package/assets/components/EmojiPicker/emojiFallbacks.json +1 -0
- package/assets/components/EmojiPicker/index.ts +4 -0
- package/assets/components/EmptyState/EmptyState.module.css +2 -2
- package/assets/components/EventChip/EventChip.module.css +120 -53
- package/assets/components/EventChip/EventChip.tsx +54 -6
- package/assets/components/EventChip/index.ts +1 -1
- package/assets/components/EventListItem/EventListItem.module.css +3 -0
- package/assets/components/EventListItem/EventListItem.tsx +15 -8
- package/assets/components/FileIcon/FileIcon.module.css +6 -6
- package/assets/components/FileUpload/FileUpload.module.css +10 -3
- package/assets/components/FileUpload/FileUpload.tsx +5 -9
- package/assets/components/FileUpload/FileUploadItem.tsx +34 -0
- package/assets/components/GalleryItem/GalleryItem.module.css +16 -19
- package/assets/components/GeneratedImage/GeneratedImage.module.css +2 -0
- package/assets/components/Icon/Icon.tsx +264 -1088
- package/assets/components/Icon/LucideFamilyIcon.tsx +436 -0
- package/assets/components/Icon/MissingIcon.tsx +25 -0
- package/assets/components/Icon/SolarFamilyIcon.tsx +443 -0
- package/assets/components/Icon/catalogNames.ts +8 -0
- package/assets/components/Icon/context.tsx +1 -1
- package/assets/components/Icon/index.ts +2 -0
- package/assets/components/Icon/lucideCatalog.ts +11358 -0
- package/assets/components/Icon/phosphorCatalog.ts +3052 -0
- package/assets/components/Icon/solarCatalog.ts +16064 -0
- package/assets/components/IconButton/IconButton.module.css +3 -2
- package/assets/components/Input/Input.module.css +63 -22
- package/assets/components/Input/Input.tsx +21 -10
- package/assets/components/Kanban/Kanban.module.css +6 -0
- package/assets/components/ListItem/ListItem.module.css +9 -6
- package/assets/components/MenuItem/MenuItem.module.css +24 -22
- package/assets/components/MenuItem/MenuItem.tsx +12 -12
- package/assets/components/MessageActions/MessageActions.module.css +38 -2
- package/assets/components/MessageActions/MessageActions.tsx +53 -28
- package/assets/components/MessageQuote/MessageQuote.module.css +1 -0
- package/assets/components/MessageSources/MessageSources.module.css +2 -0
- package/assets/components/MessageState/MessageState.module.css +1 -1
- package/assets/components/MetricCard/MetricCard.module.css +96 -108
- package/assets/components/MetricCard/MetricCard.tsx +45 -23
- package/assets/components/MetricCard/tokens.css +10 -0
- package/assets/components/MiniCalendar/MiniCalendar.module.css +130 -0
- package/assets/components/MiniCalendar/MiniCalendar.tsx +161 -0
- package/assets/components/MiniCalendar/index.ts +2 -0
- package/assets/components/Modal/Modal.module.css +13 -4
- package/assets/components/Modal/Modal.tsx +4 -0
- package/assets/components/Onboarding/LayoutBuilder.tsx +12 -50
- package/assets/components/Onboarding/Onboarding.module.css +211 -278
- package/assets/components/Onboarding/OnboardingAxisPanel.tsx +81 -125
- package/assets/components/Onboarding/OnboardingPage.tsx +244 -467
- package/assets/components/Onboarding/actions.ts +5 -0
- package/assets/components/Onboarding/palette.css +8 -0
- package/assets/components/Onboarding/wizardData.ts +8 -8
- package/assets/components/ProgressBar/ProgressBar.module.css +42 -8
- package/assets/components/ProgressBar/ProgressBar.tsx +5 -6
- package/assets/components/ProgressBar/index.ts +0 -1
- package/assets/components/QuotationBar/QuotationBar.module.css +2 -0
- package/assets/components/Radio/Radio.module.css +2 -0
- package/assets/components/RadioCard/RadioCard.module.css +96 -3
- package/assets/components/RadioCard/RadioCard.tsx +76 -13
- package/assets/components/RadioCard/index.ts +1 -1
- package/assets/components/SegmentedChart/SegmentedChart.module.css +16 -0
- package/assets/components/SegmentedChart/SegmentedChart.tsx +25 -8
- package/assets/components/Select/Select.module.css +9 -7
- package/assets/components/Select/Select.tsx +22 -6
- package/assets/components/Shortcut/Shortcut.module.css +2 -0
- package/assets/components/Sidebar/Sidebar.module.css +1 -0
- package/assets/components/Sidebar/Sidebar.tsx +2 -2
- package/assets/components/Skeleton/Skeleton.module.css +33 -0
- package/assets/components/Skeleton/Skeleton.tsx +20 -0
- package/assets/components/Skeleton/index.ts +2 -0
- package/assets/components/Skeleton/tokens.css +11 -0
- package/assets/components/Slider/Slider.module.css +3 -0
- package/assets/components/Slider/Slider.tsx +7 -2
- package/assets/components/Spinner/LottiePlayer.tsx +4 -4
- package/assets/components/Spinner/Spinner.module.css +3 -0
- package/assets/components/Spinner/lottieManifest.ts +3 -0
- package/assets/components/Stepper/Stepper.module.css +56 -8
- package/assets/components/Stepper/Stepper.tsx +13 -4
- package/assets/components/Switch/Switch.module.css +55 -42
- package/assets/components/Switch/Switch.tsx +6 -2
- package/assets/components/Switch/index.ts +1 -1
- package/assets/components/TabStrip/TabStrip.module.css +5 -1
- package/assets/components/TableCell/TableCell.module.css +8 -1
- package/assets/components/TableCell/TableCellBadge.tsx +7 -3
- package/assets/components/TableCell/TableCellImage.tsx +1 -1
- package/assets/components/TableCell/TableCellTag.tsx +23 -0
- package/assets/components/TableCell/index.ts +3 -0
- package/assets/components/TableHeader/TableHeader.module.css +4 -0
- package/assets/components/TableRow/TableRow.module.css +3 -0
- package/assets/components/TableRowEdit/TableRowEdit.module.css +2 -0
- package/assets/components/TableToolbar/TableToolbar.module.css +1 -0
- package/assets/components/Tabs/Tabs.module.css +23 -8
- package/assets/components/Tabs/Tabs.tsx +4 -3
- package/assets/components/Tag/Tag.module.css +101 -0
- package/assets/components/Tag/Tag.tsx +55 -0
- package/assets/components/Tag/index.ts +2 -0
- package/assets/components/TemplateBoundary/TemplateBoundary.tsx +22 -18
- package/assets/components/TemplateBoundary/types.ts +2 -0
- package/assets/components/Textarea/Textarea.module.css +30 -226
- package/assets/components/Textarea/Textarea.tsx +2 -2
- package/assets/components/ThemeController.tsx +30 -3
- package/assets/components/TimePicker/TimePicker.module.css +17 -4
- package/assets/components/TimePicker/TimePicker.tsx +102 -23
- package/assets/components/TimelineView/TimelineEventBar.tsx +109 -0
- package/assets/components/TimelineView/TimelineView.module.css +203 -0
- package/assets/components/TimelineView/TimelineView.tsx +137 -0
- package/assets/components/TimelineView/axis.ts +62 -0
- package/assets/components/TimelineView/index.ts +3 -0
- package/assets/components/TimelineView/layout.ts +56 -0
- package/assets/components/TimelineView/move.ts +51 -0
- package/assets/components/TimelineView/useTimelineDrag.ts +215 -0
- package/assets/components/TimelineView/useTimelineZoom.ts +92 -0
- package/assets/components/Toast/Toast.module.css +20 -0
- package/assets/components/Toast/Toast.tsx +1 -1
- package/assets/components/Toolbar/Toolbar.module.css +31 -24
- package/assets/components/Toolbar/Toolbar.tsx +4 -3
- package/assets/components/Tooltip/Tooltip.module.css +10 -0
- package/assets/components/Tooltip/Tooltip.tsx +50 -15
- package/assets/components/TopLoader/TopLoader.module.css +1 -0
- package/assets/components/TreeNav/TreeNav.module.css +1 -0
- package/assets/components/UserMessage/UserMessage.module.css +110 -1
- package/assets/components/UserMessage/UserMessage.tsx +138 -16
- package/assets/components/UserMessage/index.ts +4 -0
- package/assets/components/_color.ts +2 -2
- package/assets/components/_data.ts +37 -31
- package/assets/components/_utils.css +36 -5
- package/assets/components/axisOptions.ts +2 -0
- package/assets/components/component-registry.json +1731 -94
- package/assets/components/index.ts +23 -0
- package/assets/components/materialScope.tsx +11 -0
- package/assets/components/reset.css +1 -0
- package/assets/components/themeBootScript.ts +3 -2
- package/assets/components/tokens.css +308 -71
- package/assets/components/useChartEntrance.ts +119 -0
- package/assets/prompts/ASSEMBLY.md +20 -7
- package/assets/prompts/CATALOG.md +110 -92
- package/assets/prompts/FEEDBACK_PROCESS.md +19 -0
- package/assets/prompts/PRINCIPLES.md +25 -1
- package/assets/prompts/TEMPLATE_PREVIEWS.md +21 -0
- package/assets/prompts/WORKFLOW_DESIGN.md +48 -70
- package/assets/prompts/axes/font.md +12 -1
- package/assets/prompts/axes/icon.md +6 -4
- package/assets/prompts/axes/material.md +40 -0
- package/assets/prompts/axes/motion.md +2 -0
- package/assets/prompts/axes/palette.md +10 -2
- package/assets/prompts/axes/shape.md +8 -0
- package/assets/prompts/axes/voice.md +4 -0
- package/assets/prompts/components/README.md +3 -3
- package/assets/prompts/components/_variants.md +35 -35
- package/assets/prompts/components/accordion.md +15 -15
- package/assets/prompts/components/ai-message.md +14 -12
- package/assets/prompts/components/app-frame.md +16 -16
- package/assets/prompts/components/attachment-item.md +38 -31
- package/assets/prompts/components/attachment-thumb.md +14 -12
- package/assets/prompts/components/avatar-upload.md +10 -10
- package/assets/prompts/components/avatar.md +16 -16
- package/assets/prompts/components/badge.md +32 -97
- package/assets/prompts/components/breadcrumb.md +25 -24
- package/assets/prompts/components/bubble.md +13 -13
- package/assets/prompts/components/button-group.md +1 -1
- package/assets/prompts/components/button.md +36 -36
- package/assets/prompts/components/calendar.md +151 -0
- package/assets/prompts/components/callout.md +39 -23
- package/assets/prompts/components/canvas-edge.md +70 -0
- package/assets/prompts/components/canvas-node.md +27 -10
- package/assets/prompts/components/canvas.md +85 -0
- package/assets/prompts/components/card.md +31 -31
- package/assets/prompts/components/chart-bar.md +77 -0
- package/assets/prompts/components/chart-pie.md +63 -0
- package/assets/prompts/components/chart-radar.md +56 -0
- package/assets/prompts/components/chart-radial.md +56 -0
- package/assets/prompts/components/chart.md +129 -0
- package/assets/prompts/components/chat-composer.md +71 -0
- package/assets/prompts/components/chat-input.md +82 -27
- package/assets/prompts/components/chat-message.md +48 -0
- package/assets/prompts/components/chat-reactions.md +38 -0
- package/assets/prompts/components/checkbox-card.md +26 -45
- package/assets/prompts/components/checkbox.md +40 -17
- package/assets/prompts/components/chip.md +34 -34
- package/assets/prompts/components/code-block.md +109 -65
- package/assets/prompts/components/code.md +4 -4
- package/assets/prompts/components/color-area.md +9 -9
- package/assets/prompts/components/color-field.md +17 -13
- package/assets/prompts/components/color-picker.md +173 -0
- package/assets/prompts/components/color-slider.md +14 -14
- package/assets/prompts/components/color-swatch-picker.md +8 -8
- package/assets/prompts/components/color-swatch.md +9 -9
- package/assets/prompts/components/combobox.md +5 -2
- package/assets/prompts/components/command-palette.md +31 -30
- package/assets/prompts/components/comment.md +75 -0
- package/assets/prompts/components/context-menu.md +28 -25
- package/assets/prompts/components/control-group.md +4 -4
- package/assets/prompts/components/data-table.md +9 -0
- package/assets/prompts/components/date-picker.md +41 -23
- package/assets/prompts/components/disclosure.md +10 -10
- package/assets/prompts/components/drawer.md +29 -18
- package/assets/prompts/components/dropdown-menu.md +23 -21
- package/assets/prompts/components/emoji-picker.md +45 -0
- package/assets/prompts/components/empty-state.md +20 -18
- package/assets/prompts/components/event-chip.md +70 -28
- package/assets/prompts/components/event-list-item.md +32 -28
- package/assets/prompts/components/file-icon.md +18 -19
- package/assets/prompts/components/file-upload.md +1 -1
- package/assets/prompts/components/gallery-item.md +24 -23
- package/assets/prompts/components/generated-image.md +10 -10
- package/assets/prompts/components/hint.md +19 -19
- package/assets/prompts/components/icon-button.md +16 -16
- package/assets/prompts/components/icon.md +42 -17
- package/assets/prompts/components/input.md +49 -46
- package/assets/prompts/components/kanban.md +35 -35
- package/assets/prompts/components/list-item.md +50 -41
- package/assets/prompts/components/menu-item.md +49 -44
- package/assets/prompts/components/message-actions.md +15 -6
- package/assets/prompts/components/message-quote.md +7 -7
- package/assets/prompts/components/message-sources.md +10 -10
- package/assets/prompts/components/message-state.md +17 -17
- package/assets/prompts/components/message-table.md +5 -5
- package/assets/prompts/components/metric-card.md +57 -109
- package/assets/prompts/components/mini-calendar.md +77 -0
- package/assets/prompts/components/modal.md +40 -39
- package/assets/prompts/components/multi-select.md +4 -1
- package/assets/prompts/components/onboarding.md +23 -19
- package/assets/prompts/components/page-header.md +42 -33
- package/assets/prompts/components/pagination.md +17 -17
- package/assets/prompts/components/progress-bar.md +26 -13
- package/assets/prompts/components/quotation-bar.md +10 -10
- package/assets/prompts/components/radio-card.md +34 -117
- package/assets/prompts/components/radio.md +9 -9
- package/assets/prompts/components/segmented-chart.md +19 -5
- package/assets/prompts/components/select.md +29 -25
- package/assets/prompts/components/shortcut.md +11 -11
- package/assets/prompts/components/sidebar.md +67 -58
- package/assets/prompts/components/skeleton.md +47 -0
- package/assets/prompts/components/slider.md +18 -18
- package/assets/prompts/components/spinner.md +16 -16
- package/assets/prompts/components/stepper.md +29 -15
- package/assets/prompts/components/switch.md +30 -26
- package/assets/prompts/components/tab-strip.md +32 -31
- package/assets/prompts/components/table-cell.md +9 -7
- package/assets/prompts/components/table-header.md +16 -16
- package/assets/prompts/components/table-row-edit.md +19 -19
- package/assets/prompts/components/table-row-select.md +9 -9
- package/assets/prompts/components/table-row.md +29 -20
- package/assets/prompts/components/table-toolbar.md +9 -0
- package/assets/prompts/components/tabs.md +30 -27
- package/assets/prompts/components/tag.md +54 -0
- package/assets/prompts/components/textarea.md +16 -15
- package/assets/prompts/components/time-picker.md +22 -14
- package/assets/prompts/components/timeline-view.md +129 -0
- package/assets/prompts/components/toast.md +43 -42
- package/assets/prompts/components/toolbar.md +36 -23
- package/assets/prompts/components/tooltip.md +36 -17
- package/assets/prompts/components/top-loader.md +12 -12
- package/assets/prompts/components/topbar.md +43 -34
- package/assets/prompts/components/tree-nav.md +10 -10
- package/assets/prompts/components/user-message.md +23 -12
- package/assets/prompts/design-examples/README.md +1 -1
- package/assets/prompts/design-examples/ai-chat-full-page.png +0 -0
- package/assets/prompts/design-examples/catalog.json +124 -1
- package/assets/prompts/design-examples/sources/ai-chat-full-page/ChatExperience.module.css +346 -0
- package/assets/prompts/design-examples/sources/ai-chat-full-page/ChatExperience.tsx +375 -0
- package/assets/prompts/design-examples/sources/ai-chat-full-page/FullPageChat.tsx +8 -0
- package/assets/prompts/design-examples/sources/ai-chat-full-page/REFERENCE.md +19 -0
- package/assets/prompts/design-examples/sources/ai-chat-full-page/useChatDemo.ts +139 -0
- package/assets/prompts/design-examples/sources/ai-chat-full-page/useDemoTextStream.ts +30 -0
- package/assets/prompts/primitives/emerge.md +2 -0
- package/assets/prompts/templates/README.md +1 -1
- package/assets/prompts/templates/ains.md +9 -1
- package/assets/prompts/templates/aurora.md +5 -4
- package/assets/prompts/templates/minimal.md +14 -6
- package/assets/prompts/templates/onboarding.md +156 -0
- package/assets/prompts/templates/workspace.md +16 -11
- package/assets/prompts/tokens/color.md +11 -4
- package/assets/prompts/tokens/material.md +51 -0
- package/assets/prompts/tokens/radius.md +34 -0
- package/assets/prompts/tokens/typography.md +24 -2
- package/assets/prompts/use-cases/chart-chart-area.md +1334 -0
- package/assets/prompts/use-cases/chart-chart-bar.md +1886 -0
- package/assets/prompts/use-cases/chart-chart-pie.md +1031 -0
- package/assets/prompts/use-cases/chart-chart-radar.md +785 -0
- package/assets/prompts/use-cases/chart-chart-radial.md +988 -0
- package/assets/prompts/use-cases/chart-segmented-chart.md +262 -0
- package/assets/prompts/use-cases/chat-chat-composer.md +529 -0
- package/assets/prompts/use-cases/chat-chat-input.md +1766 -0
- package/assets/prompts/use-cases/data-comment.md +360 -0
- package/assets/prompts/use-cases/data-data-table.md +249 -0
- package/assets/prompts/use-cases/data-list-item.md +1056 -0
- package/assets/prompts/use-cases/data-metric-card.md +673 -0
- package/assets/prompts/use-cases/data-table-row.md +966 -0
- package/assets/prompts/use-cases/data-table-toolbar.md +481 -0
- package/assets/prompts/use-cases/feedback-drawer.md +1168 -0
- package/assets/prompts/use-cases/feedback-progress-bar.md +432 -0
- package/assets/prompts/use-cases/general-toolbar.md +854 -0
- package/assets/prompts/use-cases/general-tooltip.md +652 -0
- package/assets/prompts/use-cases/input-checkbox.md +443 -0
- package/assets/prompts/use-cases/structure-card.md +603 -0
- package/assets/prompts/use-cases/structure-page-header.md +755 -0
- package/assets/prompts/use-cases/structure-sidebar.md +1132 -0
- package/assets/prompts/use-cases/structure-topbar.md +1196 -0
- package/assets/public/ovenn-wordmark.svg +19 -0
- package/assets/skills/ovenn-wireframe/SKILL.md +17 -4
- package/package.json +10 -2
- package/src/commands/info.js +1 -1
- package/src/utils/design-examples.js +3 -4
- package/assets/prompts/templates/glass-button.md +0 -336
|
@@ -0,0 +1,1766 @@
|
|
|
1
|
+
# AI Chat Input 사용 사례 소스
|
|
2
|
+
|
|
3
|
+
<!-- Generated by scripts/build-use-cases.mjs. Edit original TSX/CSS, then regenerate. -->
|
|
4
|
+
|
|
5
|
+
### 사례 목록
|
|
6
|
+
|
|
7
|
+
- AI chat card
|
|
8
|
+
|
|
9
|
+
문서: /en/components/chat/chat-input#use-cases
|
|
10
|
+
|
|
11
|
+
문서 페이지에서 렌더하는 사례입니다.
|
|
12
|
+
|
|
13
|
+
### 조회 방법
|
|
14
|
+
|
|
15
|
+
get_guide(topic="use-cases/chat-chat-input", sections=["사례 목록", "파일 목록"])로 먼저 확인하고, 필요한 Section 또는 Source 파일 헤딩만 sections로 조회하세요. 전체 문서는 문서 페이지의 다른 예제도 포함합니다. 공용 컴포넌트 계약은 get_component로 읽고, 예제의 docs 전용 셸·locale·import 경로는 대상 프로젝트에 맞게 조합하세요. 이 연결은 디자인 승인이나 기능 검증을 뜻하지 않습니다.
|
|
16
|
+
|
|
17
|
+
### 파일 목록
|
|
18
|
+
|
|
19
|
+
- `web/app/[lang]/components/chat/chat-input/_strings.tsx`
|
|
20
|
+
- `web/app/[lang]/components/chat/chat-input/page.module.css`
|
|
21
|
+
- `web/app/[lang]/components/chat/chat-input/page.tsx`
|
|
22
|
+
- `web/examples/ai-chat/ChatExperience.module.css`
|
|
23
|
+
- `web/examples/ai-chat/ChatExperience.tsx`
|
|
24
|
+
- `web/examples/ai-chat/ChatUseCases.tsx`
|
|
25
|
+
- `web/examples/ai-chat/useChatDemo.ts`
|
|
26
|
+
- `web/examples/ai-chat/useDemoTextStream.ts`
|
|
27
|
+
|
|
28
|
+
### Section: web/app/[lang]/components/chat/chat-input/page.tsx#use-cases
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
<section id="use-cases">
|
|
32
|
+
<h2>{t.useCases.heading}</h2>
|
|
33
|
+
<h3>{t.useCases.card}</h3>
|
|
34
|
+
<p className="desc">{t.useCases.previewNote}</p>
|
|
35
|
+
<ExampleBlock previewWidth="full">
|
|
36
|
+
<ChatUseCases lang={localeFromPathname(pathname)} />
|
|
37
|
+
</ExampleBlock>
|
|
38
|
+
</section>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Source: web/app/[lang]/components/chat/chat-input/_strings.tsx
|
|
42
|
+
|
|
43
|
+
````tsx
|
|
44
|
+
import { Code } from "@/components/Code";
|
|
45
|
+
import type { ReactNode } from "react";
|
|
46
|
+
|
|
47
|
+
/* Chat Input docs 페이지 전용 문자열. */
|
|
48
|
+
|
|
49
|
+
type Strings = {
|
|
50
|
+
title: string;
|
|
51
|
+
lead: string;
|
|
52
|
+
|
|
53
|
+
usage: { heading: string; desc: ReactNode };
|
|
54
|
+
playground: { desc: string };
|
|
55
|
+
|
|
56
|
+
shape: {
|
|
57
|
+
heading: string;
|
|
58
|
+
descShape: ReactNode;
|
|
59
|
+
descVariant: ReactNode;
|
|
60
|
+
shellBody: string;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
appearance: { heading: string; desc: ReactNode };
|
|
64
|
+
separateSend: { heading: string; desc: ReactNode };
|
|
65
|
+
|
|
66
|
+
withModel: {
|
|
67
|
+
heading: string;
|
|
68
|
+
desc: ReactNode;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
withAttachments: {
|
|
72
|
+
heading: string;
|
|
73
|
+
desc: string;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
streaming: {
|
|
77
|
+
heading: string;
|
|
78
|
+
desc: ReactNode;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
useCases: { heading: string; card: string; previewNote: string };
|
|
82
|
+
|
|
83
|
+
api: {
|
|
84
|
+
heading: string;
|
|
85
|
+
columns: { prop: string; type: string; default: string; desc: string };
|
|
86
|
+
rows: {
|
|
87
|
+
shape: string;
|
|
88
|
+
variant: string;
|
|
89
|
+
appearance: string;
|
|
90
|
+
separateSend: string;
|
|
91
|
+
value: string;
|
|
92
|
+
onSend: string;
|
|
93
|
+
onStop: string;
|
|
94
|
+
isStreaming: string;
|
|
95
|
+
attachments: string;
|
|
96
|
+
onAttach: string;
|
|
97
|
+
onRemoveAttachment: string;
|
|
98
|
+
quotation: string;
|
|
99
|
+
models: string;
|
|
100
|
+
selectedModel: string;
|
|
101
|
+
sendVariant: string;
|
|
102
|
+
sendIcon: string;
|
|
103
|
+
disabled: string;
|
|
104
|
+
sendDisabled: string;
|
|
105
|
+
maxRows: string;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const en: Strings = {
|
|
111
|
+
title: "AI Chat Input",
|
|
112
|
+
lead: "AI chat composer. multi and single shapes bundled with model picker, attachments, quotation, and streaming. Internally assembles FileIcon, AttachmentThumb, AttachmentItem, and QuotationBar.",
|
|
113
|
+
|
|
114
|
+
usage: {
|
|
115
|
+
heading: "Usage",
|
|
116
|
+
desc: (
|
|
117
|
+
<>
|
|
118
|
+
<Code>value</Code> and <Code>onChange</Code> are controlled. Send with <Code>onSend</Code>, cancel streaming with <Code>onStop</Code>.
|
|
119
|
+
</>
|
|
120
|
+
),
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
playground: { desc: "Try the combinations." },
|
|
124
|
+
|
|
125
|
+
shape: {
|
|
126
|
+
heading: "Shape",
|
|
127
|
+
descShape: (
|
|
128
|
+
<>
|
|
129
|
+
<Code>multi</Code> is a two-row layout with model and send separated in the footer.
|
|
130
|
+
<Code>single</Code> lines up attach, input, model, and send on one row.
|
|
131
|
+
</>
|
|
132
|
+
),
|
|
133
|
+
descVariant: (
|
|
134
|
+
<>
|
|
135
|
+
<Code>framed</Code> floats as a block (radius, border, shadow).
|
|
136
|
+
<Code>flush</Code> strips the outer frame to sit edge-to-edge at the shell bottom.
|
|
137
|
+
</>
|
|
138
|
+
),
|
|
139
|
+
shellBody: "Conversation history",
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
appearance: {
|
|
143
|
+
heading: "Appearance",
|
|
144
|
+
desc: <><Code>outline</Code> is the recommended default. <Code>filled</Code> fills the input surface with light gray.</>,
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
separateSend: {
|
|
148
|
+
heading: "Separate Send Button",
|
|
149
|
+
desc: <><Code>separateSend</Code> moves Send outside the input only with <Code>shape="single"</Code>. It is ignored for multi. Appearance and model selection remain independent.</>,
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
withModel: {
|
|
153
|
+
heading: "With Model Selector",
|
|
154
|
+
desc: (
|
|
155
|
+
<>
|
|
156
|
+
Passing <Code>models</Code> adds a selector on the right. With single shape, the model name collapses to an icon once the input exceeds 10 characters.
|
|
157
|
+
</>
|
|
158
|
+
),
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
withAttachments: {
|
|
162
|
+
heading: "With Attachments & Quotation",
|
|
163
|
+
desc: "Attachments appear in a grid above the input; quotation renders as the QuotationBar above the input.",
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
streaming: {
|
|
167
|
+
heading: "Streaming",
|
|
168
|
+
desc: (
|
|
169
|
+
<>
|
|
170
|
+
Pass <Code>isStreaming</Code> with <Code>onStop</Code> to replace Send with Stop. Clicking Stop calls <Code>onStop</Code>.
|
|
171
|
+
</>
|
|
172
|
+
),
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
useCases: {
|
|
176
|
+
heading: "Use Cases",
|
|
177
|
+
card: "AI chat card",
|
|
178
|
+
previewNote: "Local demo. Suggested questions send immediately. Replies stream character by character and can be stopped; use the header menu to switch conversations.",
|
|
179
|
+
},
|
|
180
|
+
|
|
181
|
+
api: {
|
|
182
|
+
heading: "API Reference",
|
|
183
|
+
columns: { prop: "Prop", type: "Type", default: "Default", desc: "Description" },
|
|
184
|
+
rows: {
|
|
185
|
+
shape: "Layout. Multi-row or single-row.",
|
|
186
|
+
variant: "Frame. Floating block or edge-to-edge.",
|
|
187
|
+
appearance: "Input surface. Outline is recommended; filled adds a light gray background.",
|
|
188
|
+
separateSend: "Places Send outside the input for single shape only. Ignored for multi.",
|
|
189
|
+
value: "Controlled input value.",
|
|
190
|
+
onSend: "Fires when sending is allowed.",
|
|
191
|
+
onStop: "Fires when Stop is clicked during streaming.",
|
|
192
|
+
isStreaming: "If true, Send swaps to Stop.",
|
|
193
|
+
attachments: "Image and file attachment list.",
|
|
194
|
+
onAttach: "Fires when files are picked.",
|
|
195
|
+
onRemoveAttachment: "Fires when an attachment X is clicked.",
|
|
196
|
+
quotation: "Quotation bar above the input.",
|
|
197
|
+
models: "Model selector list. Hidden when omitted.",
|
|
198
|
+
selectedModel: "Selected model and change handler.",
|
|
199
|
+
sendVariant: "Send button tone.",
|
|
200
|
+
sendIcon: "Send icon shape.",
|
|
201
|
+
disabled: "Not operable.",
|
|
202
|
+
sendDisabled: "Disables sending while keeping the input and attachments available.",
|
|
203
|
+
maxRows: "Max rows for the textarea. Scrolls vertically past this.",
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const ko: Strings = {
|
|
209
|
+
title: "AI Chat Input",
|
|
210
|
+
lead: "메시지 입력부터 모델 선택, 파일 첨부, 인용까지 한곳에서 다뤄요. 입력창은 두 줄 배치와 한 줄 배치 중에서 고를 수 있어요.",
|
|
211
|
+
|
|
212
|
+
usage: {
|
|
213
|
+
heading: "사용법",
|
|
214
|
+
desc: (
|
|
215
|
+
<>
|
|
216
|
+
<Code>value</Code>와 <Code>onChange</Code>로 입력값을 관리해요. 전송할 때는 <Code>onSend</Code>, 응답을 멈출 때는 <Code>onStop</Code>을 호출해요.
|
|
217
|
+
</>
|
|
218
|
+
),
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
playground: { desc: "옵션을 바꿔 보세요." },
|
|
222
|
+
|
|
223
|
+
shape: {
|
|
224
|
+
heading: "형태",
|
|
225
|
+
descShape: (
|
|
226
|
+
<>
|
|
227
|
+
<Code>multi</Code>는 입력창 아래에 모델 선택과 보내기 버튼을 둬요.
|
|
228
|
+
<Code>single</Code>은 첨부·입력·모델 선택·보내기를 한 줄에 배치해요.
|
|
229
|
+
</>
|
|
230
|
+
),
|
|
231
|
+
descVariant: (
|
|
232
|
+
<>
|
|
233
|
+
<Code>framed</Code>는 둥근 모서리, 테두리, 그림자로 입력 영역을 구분해요.
|
|
234
|
+
<Code>flush</Code>는 외곽 장식 없이 주변 영역에 이어 붙일 때 써요.
|
|
235
|
+
</>
|
|
236
|
+
),
|
|
237
|
+
shellBody: "대화 내용",
|
|
238
|
+
},
|
|
239
|
+
|
|
240
|
+
appearance: {
|
|
241
|
+
heading: "표현",
|
|
242
|
+
desc: <>기본값인 <Code>outline</Code>을 권장해요. <Code>filled</Code>는 입력 영역을 연회색으로 채워요.</>,
|
|
243
|
+
},
|
|
244
|
+
|
|
245
|
+
separateSend: {
|
|
246
|
+
heading: "보내기 버튼 분리",
|
|
247
|
+
desc: <><Code>separateSend</Code>는 <Code>shape="single"</Code>일 때만 보내기를 입력 영역 밖으로 분리해요. <Code>multi</Code>에는 적용하지 않아요. 배경 표현과 모델 선택은 각각 조합할 수 있어요.</>,
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
withModel: {
|
|
251
|
+
heading: "모델 선택",
|
|
252
|
+
desc: (
|
|
253
|
+
<>
|
|
254
|
+
<Code>models</Code>로 선택할 모델을 전달해요. <Code>single</Code>에서는 입력이 10자를 넘으면 모델명을 숨기고 아이콘만 보여줘요.
|
|
255
|
+
</>
|
|
256
|
+
),
|
|
257
|
+
},
|
|
258
|
+
|
|
259
|
+
withAttachments: {
|
|
260
|
+
heading: "첨부와 인용",
|
|
261
|
+
desc: "첨부 파일과 인용문은 입력창 위에 표시해요.",
|
|
262
|
+
},
|
|
263
|
+
|
|
264
|
+
streaming: {
|
|
265
|
+
heading: "응답 중",
|
|
266
|
+
desc: (
|
|
267
|
+
<>
|
|
268
|
+
<Code>isStreaming</Code>과 <Code>onStop</Code>을 함께 지정하면 보내기 버튼이 중지 버튼으로 바뀌어요. 중지 버튼을 누르면 <Code>onStop</Code>을 호출해요.
|
|
269
|
+
</>
|
|
270
|
+
),
|
|
271
|
+
},
|
|
272
|
+
|
|
273
|
+
useCases: {
|
|
274
|
+
heading: "사용사례",
|
|
275
|
+
card: "AI 채팅 카드",
|
|
276
|
+
previewNote: "실제 AI 연결 없이 동작하는 데모예요. 추천 질문을 누르면 바로 보내요. 응답은 한 글자씩 나타나고 중지할 수 있어요. 상단 메뉴에서 대화를 바꿔 보세요.",
|
|
277
|
+
},
|
|
278
|
+
|
|
279
|
+
api: {
|
|
280
|
+
heading: "속성",
|
|
281
|
+
columns: { prop: "속성", type: "타입", default: "기본값", desc: "설명" },
|
|
282
|
+
rows: {
|
|
283
|
+
shape: "입력 영역을 두 줄 또는 한 줄로 배치해요.",
|
|
284
|
+
variant: "입력 영역의 외곽을 구분하거나 주변 영역에 이어 붙여요.",
|
|
285
|
+
appearance: "기본은 outline이에요. filled는 연회색으로 채워요.",
|
|
286
|
+
separateSend: "single일 때만 보내기를 입력 영역 밖으로 분리해요. multi에서는 무시해요.",
|
|
287
|
+
value: "외부에서 관리하는 입력값이에요.",
|
|
288
|
+
onSend: "메시지를 보낼 수 있을 때 호출해요.",
|
|
289
|
+
onStop: "응답 중 중지 버튼을 누르면 호출해요.",
|
|
290
|
+
isStreaming: "onStop과 함께 지정하면 보내기 대신 중지 버튼을 보여줘요.",
|
|
291
|
+
attachments: "첨부한 이미지와 파일 목록이에요.",
|
|
292
|
+
onAttach: "파일을 선택하면 호출해요.",
|
|
293
|
+
onRemoveAttachment: "첨부 제거 버튼을 누르면 해당 항목의 ID를 전달해요.",
|
|
294
|
+
quotation: "입력창 위에 표시할 인용문이에요.",
|
|
295
|
+
models: "선택할 모델 목록이에요. 생략하면 모델 선택을 숨겨요.",
|
|
296
|
+
selectedModel: "선택한 모델의 ID와 변경할 때 호출할 함수예요.",
|
|
297
|
+
sendVariant: "보내기 버튼의 색 표현을 골라요.",
|
|
298
|
+
sendIcon: "보내기 아이콘의 모양을 골라요.",
|
|
299
|
+
disabled: "입력과 첨부, 전송을 비활성화해요.",
|
|
300
|
+
sendDisabled: "입력·첨부는 유지하고 전송만 비활성화해요.",
|
|
301
|
+
maxRows: "입력창의 최대 줄 수예요. 넘치는 내용은 세로로 스크롤해요.",
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
export const strings = { en, ko };
|
|
307
|
+
export type { Strings };
|
|
308
|
+
````
|
|
309
|
+
|
|
310
|
+
### Source: web/app/[lang]/components/chat/chat-input/page.module.css
|
|
311
|
+
|
|
312
|
+
````css
|
|
313
|
+
.column {
|
|
314
|
+
display: flex;
|
|
315
|
+
flex-direction: column;
|
|
316
|
+
gap: var(--space-5);
|
|
317
|
+
width: 100%;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/* ChatInput 벤더가 자연 폭 가지므로 ExampleBlock 안에서 가로 가득 쓰도록 wrapper 공급. */
|
|
321
|
+
.stage {
|
|
322
|
+
width: 100%;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
.shellWrap {
|
|
326
|
+
background: var(--bg-subtle);
|
|
327
|
+
corner-shape: var(--corner-shape);
|
|
328
|
+
border-radius: var(--radius-lg);
|
|
329
|
+
overflow: hidden;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
.shellBody {
|
|
333
|
+
padding: var(--space-4);
|
|
334
|
+
color: var(--fg-muted);
|
|
335
|
+
font-size: var(--text-sm);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
.shellBottom {
|
|
339
|
+
border-top: var(--hairline) solid var(--border);
|
|
340
|
+
background: var(--bg);
|
|
341
|
+
}
|
|
342
|
+
````
|
|
343
|
+
|
|
344
|
+
### Source: web/app/[lang]/components/chat/chat-input/page.tsx
|
|
345
|
+
|
|
346
|
+
````tsx
|
|
347
|
+
"use client";
|
|
348
|
+
|
|
349
|
+
import { useState } from "react";
|
|
350
|
+
import { usePathname } from "next/navigation";
|
|
351
|
+
import {
|
|
352
|
+
AIChatInput,
|
|
353
|
+
type ChatAttachment,
|
|
354
|
+
type ChatInputShape,
|
|
355
|
+
type ChatInputAppearance,
|
|
356
|
+
type ChatInputVariant,
|
|
357
|
+
type ChatInputSendVariant,
|
|
358
|
+
type ChatInputSendIcon,
|
|
359
|
+
} from "@/components/ChatInput";
|
|
360
|
+
import { ChatUseCases } from "@/examples/ai-chat/ChatUseCases";
|
|
361
|
+
import { Code } from "@/components/Code";
|
|
362
|
+
import { Icon } from "@/components/Icon";
|
|
363
|
+
import { ExampleBlock } from "../../../../_components/ExampleBlock";
|
|
364
|
+
import { Playground } from "../../../../_components/Playground";
|
|
365
|
+
import { DocsTable } from "../../../../_components/DocsTable";
|
|
366
|
+
import { localeFromPathname } from "../../../../_dict";
|
|
367
|
+
import { strings } from "./_strings";
|
|
368
|
+
import styles from "./page.module.css";
|
|
369
|
+
|
|
370
|
+
const SHAPES: ChatInputShape[] = ["multi", "single"];
|
|
371
|
+
const APPEARANCES: ChatInputAppearance[] = ["outline", "filled"];
|
|
372
|
+
const VARIANTS: ChatInputVariant[] = ["framed", "flush"];
|
|
373
|
+
const SEND_VARIANTS: ChatInputSendVariant[] = ["solid", "ghost", "soft"];
|
|
374
|
+
const SEND_ICONS: ChatInputSendIcon[] = ["arrow-up", "return", "paper-plane"];
|
|
375
|
+
|
|
376
|
+
const MODELS = [
|
|
377
|
+
{ id: "gpt", label: "GPT", icon: <Icon name="chat-circle" />, description: "Great Conversation" },
|
|
378
|
+
{ id: "claude", label: "Claude", icon: <Icon name="star" />, description: "Smart" },
|
|
379
|
+
{ id: "gemini", label: "Gemini", icon: <Icon name="squares-four" />, description: "Versatile" },
|
|
380
|
+
{ id: "grok", label: "Grok", icon: <Icon name="trend-up" />, description: "Trend Insights" },
|
|
381
|
+
];
|
|
382
|
+
|
|
383
|
+
const IMG_A = "https://images.unsplash.com/photo-1557683316-973673baf926?w=200";
|
|
384
|
+
|
|
385
|
+
const FULL_ATTACHMENTS: ChatAttachment[] = [
|
|
386
|
+
{ id: "t1", kind: "image", src: IMG_A, alt: "a" },
|
|
387
|
+
{ id: "t2", kind: "image" },
|
|
388
|
+
{ id: "t3", kind: "image", loading: true },
|
|
389
|
+
{ id: "f1", kind: "file", filename: "cover.psd" },
|
|
390
|
+
{ id: "f2", kind: "file", filename: "writeup.pdf" },
|
|
391
|
+
];
|
|
392
|
+
|
|
393
|
+
const QUOTE_TEXT =
|
|
394
|
+
"System-level macOS feature, not something regular apps can directly replicate.";
|
|
395
|
+
|
|
396
|
+
type LocalProps = {
|
|
397
|
+
shape?: ChatInputShape;
|
|
398
|
+
variant?: ChatInputVariant;
|
|
399
|
+
appearance?: ChatInputAppearance;
|
|
400
|
+
separateSend?: boolean;
|
|
401
|
+
sendVariant?: ChatInputSendVariant;
|
|
402
|
+
sendIcon?: ChatInputSendIcon;
|
|
403
|
+
withModel?: boolean;
|
|
404
|
+
initialValue?: string;
|
|
405
|
+
attachments?: ChatAttachment[];
|
|
406
|
+
quotation?: string;
|
|
407
|
+
streaming?: boolean;
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
function LocalChatInput(props: LocalProps) {
|
|
411
|
+
const [v, setV] = useState(props.initialValue ?? "");
|
|
412
|
+
const [atts, setAtts] = useState<ChatAttachment[]>(props.attachments ?? []);
|
|
413
|
+
const [quote, setQuote] = useState<string | null>(props.quotation ?? null);
|
|
414
|
+
const [model, setModel] = useState("claude");
|
|
415
|
+
const [streaming, setStreaming] = useState(props.streaming ?? false);
|
|
416
|
+
|
|
417
|
+
return (
|
|
418
|
+
<AIChatInput
|
|
419
|
+
shape={props.shape ?? "multi"}
|
|
420
|
+
variant={props.variant ?? "framed"}
|
|
421
|
+
appearance={props.appearance}
|
|
422
|
+
separateSend={props.separateSend}
|
|
423
|
+
sendVariant={props.sendVariant}
|
|
424
|
+
sendIcon={props.sendIcon}
|
|
425
|
+
value={v}
|
|
426
|
+
onChange={setV}
|
|
427
|
+
onSend={() => {
|
|
428
|
+
setV("");
|
|
429
|
+
setAtts([]);
|
|
430
|
+
setQuote(null);
|
|
431
|
+
setStreaming(true);
|
|
432
|
+
setTimeout(() => setStreaming(false), 1500);
|
|
433
|
+
}}
|
|
434
|
+
onStop={() => setStreaming(false)}
|
|
435
|
+
isStreaming={streaming}
|
|
436
|
+
attachments={atts}
|
|
437
|
+
onRemoveAttachment={(id) => setAtts((prev) => prev.filter((a) => a.id !== id))}
|
|
438
|
+
onAttach={(files) => {
|
|
439
|
+
const next: ChatAttachment[] = files.map((f, i) =>
|
|
440
|
+
f.type.startsWith("image/")
|
|
441
|
+
? {
|
|
442
|
+
id: `${Date.now()}-${i}`,
|
|
443
|
+
kind: "image",
|
|
444
|
+
src: URL.createObjectURL(f),
|
|
445
|
+
alt: f.name,
|
|
446
|
+
}
|
|
447
|
+
: { id: `${Date.now()}-${i}`, kind: "file", filename: f.name },
|
|
448
|
+
);
|
|
449
|
+
setAtts((prev) => [...prev, ...next]);
|
|
450
|
+
}}
|
|
451
|
+
quotation={quote ? { text: quote, onRemove: () => setQuote(null) } : undefined}
|
|
452
|
+
models={props.withModel === false ? undefined : MODELS}
|
|
453
|
+
selectedModel={props.withModel === false ? undefined : model}
|
|
454
|
+
onSelectModel={setModel}
|
|
455
|
+
/>
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export default function ChatInputPage() {
|
|
460
|
+
const pathname = usePathname() ?? "/";
|
|
461
|
+
const t = strings[localeFromPathname(pathname)];
|
|
462
|
+
|
|
463
|
+
const [pgShape, setPgShape] = useState<ChatInputShape>("multi");
|
|
464
|
+
const [pgAppearance, setPgAppearance] = useState<ChatInputAppearance>("outline");
|
|
465
|
+
const [pgSeparateSend, setPgSeparateSend] = useState(false);
|
|
466
|
+
const [pgVariant, setPgVariant] = useState<ChatInputVariant>("framed");
|
|
467
|
+
const [pgSendVariant, setPgSendVariant] = useState<ChatInputSendVariant>("solid");
|
|
468
|
+
const [pgSendIcon, setPgSendIcon] = useState<ChatInputSendIcon>("arrow-up");
|
|
469
|
+
const [pgWithModel, setPgWithModel] = useState(true);
|
|
470
|
+
const [pgWithAttachments, setPgWithAttachments] = useState(false);
|
|
471
|
+
const [pgWithQuote, setPgWithQuote] = useState(false);
|
|
472
|
+
const [pgStreaming, setPgStreaming] = useState(false);
|
|
473
|
+
const [pgDisabled, setPgDisabled] = useState(false);
|
|
474
|
+
|
|
475
|
+
const [pgValue, setPgValue] = useState("");
|
|
476
|
+
const [pgAtts, setPgAtts] = useState<ChatAttachment[]>([]);
|
|
477
|
+
const [pgModel, setPgModel] = useState("claude");
|
|
478
|
+
|
|
479
|
+
return (
|
|
480
|
+
<>
|
|
481
|
+
<h1 className="page-title">{t.title}</h1>
|
|
482
|
+
<p className="page-lead">{t.lead}</p>
|
|
483
|
+
|
|
484
|
+
<section id="usage" className="section-first">
|
|
485
|
+
<h2>{t.usage.heading}</h2>
|
|
486
|
+
<p className="desc">{t.usage.desc}</p>
|
|
487
|
+
<ExampleBlock
|
|
488
|
+
align="column"
|
|
489
|
+
code={`import { AIChatInput } from "@/components/ChatInput";
|
|
490
|
+
|
|
491
|
+
const [value, setValue] = useState("");
|
|
492
|
+
|
|
493
|
+
<AIChatInput
|
|
494
|
+
value={value}
|
|
495
|
+
onChange={setValue}
|
|
496
|
+
onSend={() => submit(value)}
|
|
497
|
+
/>`}
|
|
498
|
+
>
|
|
499
|
+
<div className={styles.stage}>
|
|
500
|
+
<LocalChatInput shape="multi" />
|
|
501
|
+
</div>
|
|
502
|
+
</ExampleBlock>
|
|
503
|
+
</section>
|
|
504
|
+
|
|
505
|
+
<Playground
|
|
506
|
+
desc={t.playground.desc}
|
|
507
|
+
axes={[
|
|
508
|
+
{
|
|
509
|
+
label: "shape",
|
|
510
|
+
value: pgShape,
|
|
511
|
+
onChange: (v) => setPgShape(v as ChatInputShape),
|
|
512
|
+
options: SHAPES,
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
label: "appearance",
|
|
516
|
+
value: pgAppearance,
|
|
517
|
+
onChange: (v) => setPgAppearance(v as ChatInputAppearance),
|
|
518
|
+
options: APPEARANCES,
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
label: "variant",
|
|
522
|
+
value: pgVariant,
|
|
523
|
+
onChange: (v) => setPgVariant(v as ChatInputVariant),
|
|
524
|
+
options: VARIANTS,
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
label: "sendVariant",
|
|
528
|
+
value: pgSendVariant,
|
|
529
|
+
onChange: (v) => setPgSendVariant(v as ChatInputSendVariant),
|
|
530
|
+
options: SEND_VARIANTS,
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
label: "sendIcon",
|
|
534
|
+
value: pgSendIcon,
|
|
535
|
+
onChange: (v) => setPgSendIcon(v as ChatInputSendIcon),
|
|
536
|
+
options: SEND_ICONS,
|
|
537
|
+
},
|
|
538
|
+
]}
|
|
539
|
+
toggles={[
|
|
540
|
+
{ group: "layout", label: "separateSend (single only)", value: pgSeparateSend, onChange: setPgSeparateSend },
|
|
541
|
+
{ group: "content", label: "model selector", value: pgWithModel, onChange: setPgWithModel },
|
|
542
|
+
{ group: "content", label: "attachments", value: pgWithAttachments, onChange: (next) => { setPgWithAttachments(next); setPgAtts(next ? FULL_ATTACHMENTS : []); } },
|
|
543
|
+
{ group: "content", label: "quotation", value: pgWithQuote, onChange: setPgWithQuote },
|
|
544
|
+
{ group: "state", label: "streaming", value: pgStreaming, onChange: setPgStreaming },
|
|
545
|
+
{ group: "state", label: "disabled", value: pgDisabled, onChange: setPgDisabled },
|
|
546
|
+
]}
|
|
547
|
+
>
|
|
548
|
+
<div className={styles.stage}>
|
|
549
|
+
<AIChatInput
|
|
550
|
+
shape={pgShape}
|
|
551
|
+
variant={pgVariant}
|
|
552
|
+
appearance={pgAppearance}
|
|
553
|
+
separateSend={pgSeparateSend}
|
|
554
|
+
sendVariant={pgSendVariant}
|
|
555
|
+
sendIcon={pgSendIcon}
|
|
556
|
+
value={pgValue}
|
|
557
|
+
onChange={setPgValue}
|
|
558
|
+
onSend={() => { setPgValue(""); setPgAtts([]); setPgWithAttachments(false); setPgWithQuote(false); }}
|
|
559
|
+
onStop={() => setPgStreaming(false)}
|
|
560
|
+
isStreaming={pgStreaming}
|
|
561
|
+
disabled={pgDisabled}
|
|
562
|
+
attachments={pgWithAttachments ? pgAtts : []}
|
|
563
|
+
onRemoveAttachment={(id) => setPgAtts((prev) => prev.filter((a) => a.id !== id))}
|
|
564
|
+
onAttach={(files) => {
|
|
565
|
+
setPgWithAttachments(true);
|
|
566
|
+
setPgAtts((previous) => [...previous, ...files.map((file, index): ChatAttachment =>
|
|
567
|
+
file.type.startsWith("image/")
|
|
568
|
+
? { id: `upload-${Date.now()}-${index}`, kind: "image", src: URL.createObjectURL(file), alt: file.name }
|
|
569
|
+
: { id: `upload-${Date.now()}-${index}`, kind: "file", filename: file.name },
|
|
570
|
+
)]);
|
|
571
|
+
}}
|
|
572
|
+
quotation={pgWithQuote ? { text: QUOTE_TEXT, onRemove: () => setPgWithQuote(false) } : undefined}
|
|
573
|
+
models={pgWithModel ? MODELS : undefined}
|
|
574
|
+
selectedModel={pgWithModel ? pgModel : undefined}
|
|
575
|
+
onSelectModel={setPgModel}
|
|
576
|
+
/>
|
|
577
|
+
</div>
|
|
578
|
+
</Playground>
|
|
579
|
+
|
|
580
|
+
<section id="variants">
|
|
581
|
+
<h2>{t.shape.heading}</h2>
|
|
582
|
+
<p className="desc">{t.shape.descShape}</p>
|
|
583
|
+
<ExampleBlock
|
|
584
|
+
align="column"
|
|
585
|
+
code={`<AIChatInput shape="multi" value={v} onChange={setV} onSend={send} />
|
|
586
|
+
<AIChatInput shape="single" value={v} onChange={setV} onSend={send} />`}
|
|
587
|
+
>
|
|
588
|
+
<div className={styles.column}>
|
|
589
|
+
<LocalChatInput shape="multi" />
|
|
590
|
+
<LocalChatInput shape="single" />
|
|
591
|
+
</div>
|
|
592
|
+
</ExampleBlock>
|
|
593
|
+
|
|
594
|
+
<p className="desc">{t.shape.descVariant}</p>
|
|
595
|
+
<ExampleBlock
|
|
596
|
+
align="column"
|
|
597
|
+
code={`<AIChatInput variant="framed" ... />
|
|
598
|
+
|
|
599
|
+
<div className={shellWrap}>
|
|
600
|
+
<div className={shellBody}>...</div>
|
|
601
|
+
<div className={shellBottom}>
|
|
602
|
+
<AIChatInput variant="flush" ... />
|
|
603
|
+
</div>
|
|
604
|
+
</div>`}
|
|
605
|
+
>
|
|
606
|
+
<div className={styles.column}>
|
|
607
|
+
<LocalChatInput shape="multi" variant="framed" />
|
|
608
|
+
<div className={styles.shellWrap}>
|
|
609
|
+
<div className={styles.shellBody}>{strings.en.shape.shellBody}</div>
|
|
610
|
+
<div className={styles.shellBottom}>
|
|
611
|
+
<LocalChatInput shape="single" variant="flush" />
|
|
612
|
+
</div>
|
|
613
|
+
</div>
|
|
614
|
+
</div>
|
|
615
|
+
</ExampleBlock>
|
|
616
|
+
</section>
|
|
617
|
+
|
|
618
|
+
<section id="appearance">
|
|
619
|
+
<h2>{t.appearance.heading}</h2>
|
|
620
|
+
<p className="desc">{t.appearance.desc}</p>
|
|
621
|
+
<ExampleBlock
|
|
622
|
+
align="column"
|
|
623
|
+
code={`<AIChatInput appearance="outline" value={v} onChange={setV} onSend={send} />
|
|
624
|
+
<AIChatInput appearance="filled" value={v} onChange={setV} onSend={send} />`}
|
|
625
|
+
>
|
|
626
|
+
<div className={styles.column}>
|
|
627
|
+
<LocalChatInput appearance="outline" />
|
|
628
|
+
<LocalChatInput appearance="filled" />
|
|
629
|
+
</div>
|
|
630
|
+
</ExampleBlock>
|
|
631
|
+
</section>
|
|
632
|
+
|
|
633
|
+
<section id="separate-send">
|
|
634
|
+
<h2>{t.separateSend.heading}</h2>
|
|
635
|
+
<p className="desc">{t.separateSend.desc}</p>
|
|
636
|
+
<ExampleBlock
|
|
637
|
+
align="column"
|
|
638
|
+
code={`<AIChatInput shape="single" separateSend value={v} onChange={setV} onSend={send} />
|
|
639
|
+
<AIChatInput shape="single" appearance="filled" separateSend value={v} onChange={setV} onSend={send} />
|
|
640
|
+
<AIChatInput shape="multi" separateSend value={v} onChange={setV} onSend={send} /> // ignored in multi`}
|
|
641
|
+
>
|
|
642
|
+
<div className={styles.column}>
|
|
643
|
+
<LocalChatInput shape="single" separateSend />
|
|
644
|
+
<LocalChatInput shape="single" appearance="filled" separateSend withModel={false} />
|
|
645
|
+
<LocalChatInput shape="multi" separateSend />
|
|
646
|
+
</div>
|
|
647
|
+
</ExampleBlock>
|
|
648
|
+
</section>
|
|
649
|
+
|
|
650
|
+
<section id="with-model">
|
|
651
|
+
<h2>{t.withModel.heading}</h2>
|
|
652
|
+
<p className="desc">{t.withModel.desc}</p>
|
|
653
|
+
<ExampleBlock
|
|
654
|
+
align="column"
|
|
655
|
+
code={`<AIChatInput
|
|
656
|
+
models={MODELS}
|
|
657
|
+
selectedModel={id}
|
|
658
|
+
onSelectModel={setId}
|
|
659
|
+
...
|
|
660
|
+
/>`}
|
|
661
|
+
>
|
|
662
|
+
<div className={styles.column}>
|
|
663
|
+
<LocalChatInput shape="multi" withModel />
|
|
664
|
+
<LocalChatInput shape="multi" withModel={false} />
|
|
665
|
+
</div>
|
|
666
|
+
</ExampleBlock>
|
|
667
|
+
</section>
|
|
668
|
+
|
|
669
|
+
<section id="with-attachments">
|
|
670
|
+
<h2>{t.withAttachments.heading}</h2>
|
|
671
|
+
<p className="desc">{t.withAttachments.desc}</p>
|
|
672
|
+
<ExampleBlock
|
|
673
|
+
align="column"
|
|
674
|
+
code={`<AIChatInput
|
|
675
|
+
attachments={files}
|
|
676
|
+
onRemoveAttachment={remove}
|
|
677
|
+
quotation={{ text, onRemove }}
|
|
678
|
+
...
|
|
679
|
+
/>`}
|
|
680
|
+
>
|
|
681
|
+
<div className={styles.column}>
|
|
682
|
+
<LocalChatInput shape="multi" initialValue="Text" attachments={FULL_ATTACHMENTS} />
|
|
683
|
+
<LocalChatInput shape="multi" initialValue="Text" quotation={QUOTE_TEXT} />
|
|
684
|
+
</div>
|
|
685
|
+
</ExampleBlock>
|
|
686
|
+
</section>
|
|
687
|
+
|
|
688
|
+
<section id="states">
|
|
689
|
+
<h2>{t.streaming.heading}</h2>
|
|
690
|
+
<p className="desc">{t.streaming.desc}</p>
|
|
691
|
+
<ExampleBlock
|
|
692
|
+
align="column"
|
|
693
|
+
code={`<AIChatInput isStreaming onStop={cancel} ... />`}
|
|
694
|
+
>
|
|
695
|
+
<LocalChatInput shape="multi" initialValue="..." streaming />
|
|
696
|
+
</ExampleBlock>
|
|
697
|
+
</section>
|
|
698
|
+
|
|
699
|
+
<section id="use-cases">
|
|
700
|
+
<h2>{t.useCases.heading}</h2>
|
|
701
|
+
<h3>{t.useCases.card}</h3>
|
|
702
|
+
<p className="desc">{t.useCases.previewNote}</p>
|
|
703
|
+
<ExampleBlock previewWidth="full">
|
|
704
|
+
<ChatUseCases lang={localeFromPathname(pathname)} />
|
|
705
|
+
</ExampleBlock>
|
|
706
|
+
</section>
|
|
707
|
+
|
|
708
|
+
<section id="api">
|
|
709
|
+
<h2>{t.api.heading}</h2>
|
|
710
|
+
<DocsTable
|
|
711
|
+
columns={[
|
|
712
|
+
{ key: "prop", label: t.api.columns.prop, width: 180 },
|
|
713
|
+
{ key: "type", label: t.api.columns.type, flex: true, minWidth: 220 },
|
|
714
|
+
{ key: "default", label: t.api.columns.default, width: 140 },
|
|
715
|
+
{ key: "desc", label: t.api.columns.desc, flex: true, minWidth: 240 },
|
|
716
|
+
]}
|
|
717
|
+
rows={[
|
|
718
|
+
{
|
|
719
|
+
prop: <Code>shape</Code>,
|
|
720
|
+
type: <Code>'multi' | 'single'</Code>,
|
|
721
|
+
default: <Code>'multi'</Code>,
|
|
722
|
+
desc: t.api.rows.shape,
|
|
723
|
+
},
|
|
724
|
+
{
|
|
725
|
+
prop: <Code>variant</Code>,
|
|
726
|
+
type: <Code>'framed' | 'flush'</Code>,
|
|
727
|
+
default: <Code>'framed'</Code>,
|
|
728
|
+
desc: t.api.rows.variant,
|
|
729
|
+
},
|
|
730
|
+
{
|
|
731
|
+
prop: <Code>appearance</Code>,
|
|
732
|
+
type: <Code>'outline' | 'filled'</Code>,
|
|
733
|
+
default: <Code>'outline'</Code>,
|
|
734
|
+
desc: t.api.rows.appearance,
|
|
735
|
+
},
|
|
736
|
+
{
|
|
737
|
+
prop: <Code>separateSend</Code>,
|
|
738
|
+
type: <Code>boolean</Code>,
|
|
739
|
+
default: <Code>false</Code>,
|
|
740
|
+
desc: t.api.rows.separateSend,
|
|
741
|
+
},
|
|
742
|
+
{
|
|
743
|
+
prop: <Code>value / onChange</Code>,
|
|
744
|
+
type: <Code>string / (v) => void</Code>,
|
|
745
|
+
default: "",
|
|
746
|
+
desc: t.api.rows.value,
|
|
747
|
+
},
|
|
748
|
+
{
|
|
749
|
+
prop: <Code>onSend</Code>,
|
|
750
|
+
type: <Code>() => void</Code>,
|
|
751
|
+
default: "",
|
|
752
|
+
desc: t.api.rows.onSend,
|
|
753
|
+
},
|
|
754
|
+
{
|
|
755
|
+
prop: <Code>onStop</Code>,
|
|
756
|
+
type: <Code>() => void</Code>,
|
|
757
|
+
default: "",
|
|
758
|
+
desc: t.api.rows.onStop,
|
|
759
|
+
},
|
|
760
|
+
{
|
|
761
|
+
prop: <Code>isStreaming</Code>,
|
|
762
|
+
type: <Code>boolean</Code>,
|
|
763
|
+
default: <Code>false</Code>,
|
|
764
|
+
desc: t.api.rows.isStreaming,
|
|
765
|
+
},
|
|
766
|
+
{
|
|
767
|
+
prop: <Code>attachments</Code>,
|
|
768
|
+
type: <Code>ChatAttachment[]</Code>,
|
|
769
|
+
default: <Code>[]</Code>,
|
|
770
|
+
desc: t.api.rows.attachments,
|
|
771
|
+
},
|
|
772
|
+
{
|
|
773
|
+
prop: <Code>onAttach</Code>,
|
|
774
|
+
type: <Code>(files: File[]) => void</Code>,
|
|
775
|
+
default: "",
|
|
776
|
+
desc: t.api.rows.onAttach,
|
|
777
|
+
},
|
|
778
|
+
{
|
|
779
|
+
prop: <Code>onRemoveAttachment</Code>,
|
|
780
|
+
type: <Code>(id: string) => void</Code>,
|
|
781
|
+
default: "",
|
|
782
|
+
desc: t.api.rows.onRemoveAttachment,
|
|
783
|
+
},
|
|
784
|
+
{
|
|
785
|
+
prop: <Code>quotation</Code>,
|
|
786
|
+
type: <Code>{"{ text, onRemove? }"}</Code>,
|
|
787
|
+
default: "",
|
|
788
|
+
desc: t.api.rows.quotation,
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
prop: <Code>models</Code>,
|
|
792
|
+
type: <Code>ChatInputModel[]</Code>,
|
|
793
|
+
default: "",
|
|
794
|
+
desc: t.api.rows.models,
|
|
795
|
+
},
|
|
796
|
+
{
|
|
797
|
+
prop: <Code>selectedModel / onSelectModel</Code>,
|
|
798
|
+
type: <Code>string / (id) => void</Code>,
|
|
799
|
+
default: "",
|
|
800
|
+
desc: t.api.rows.selectedModel,
|
|
801
|
+
},
|
|
802
|
+
{
|
|
803
|
+
prop: <Code>sendVariant</Code>,
|
|
804
|
+
type: <Code>'solid' | 'ghost' | 'soft'</Code>,
|
|
805
|
+
default: <Code>'solid'</Code>,
|
|
806
|
+
desc: t.api.rows.sendVariant,
|
|
807
|
+
},
|
|
808
|
+
{
|
|
809
|
+
prop: <Code>sendIcon</Code>,
|
|
810
|
+
type: <Code>'arrow-up' | 'return' | 'paper-plane'</Code>,
|
|
811
|
+
default: <Code>'arrow-up'</Code>,
|
|
812
|
+
desc: t.api.rows.sendIcon,
|
|
813
|
+
},
|
|
814
|
+
{
|
|
815
|
+
prop: <Code>disabled</Code>,
|
|
816
|
+
type: <Code>boolean</Code>,
|
|
817
|
+
default: <Code>false</Code>,
|
|
818
|
+
desc: t.api.rows.disabled,
|
|
819
|
+
},
|
|
820
|
+
{
|
|
821
|
+
prop: <Code>sendDisabled</Code>,
|
|
822
|
+
type: <Code>boolean</Code>,
|
|
823
|
+
default: <Code>false</Code>,
|
|
824
|
+
desc: t.api.rows.sendDisabled,
|
|
825
|
+
},
|
|
826
|
+
{
|
|
827
|
+
prop: <Code>maxRows</Code>,
|
|
828
|
+
type: <Code>number</Code>,
|
|
829
|
+
default: <Code>8</Code>,
|
|
830
|
+
desc: t.api.rows.maxRows,
|
|
831
|
+
},
|
|
832
|
+
]}
|
|
833
|
+
/>
|
|
834
|
+
</section>
|
|
835
|
+
</>
|
|
836
|
+
);
|
|
837
|
+
}
|
|
838
|
+
````
|
|
839
|
+
|
|
840
|
+
### Source: web/examples/ai-chat/ChatExperience.module.css
|
|
841
|
+
|
|
842
|
+
````css
|
|
843
|
+
.stage {
|
|
844
|
+
container-type: inline-size;
|
|
845
|
+
display: flex;
|
|
846
|
+
justify-content: center;
|
|
847
|
+
width: 100%;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
.card.card {
|
|
851
|
+
--chat-content-inset: var(--space-4);
|
|
852
|
+
--chat-secondary-fg: color-mix(in oklch, var(--fg-strong) 60%, var(--bg));
|
|
853
|
+
--chat-card-width: calc(var(--size-24) * 4.5);
|
|
854
|
+
--chat-card-height: calc(var(--size-24) * 5.5);
|
|
855
|
+
--chat-question-width: calc(var(--size-unit) * 40);
|
|
856
|
+
|
|
857
|
+
display: grid;
|
|
858
|
+
grid-template-rows: auto minmax(0, 1fr) auto;
|
|
859
|
+
width: 100%;
|
|
860
|
+
max-width: var(--chat-card-width);
|
|
861
|
+
height: var(--chat-card-height);
|
|
862
|
+
min-height: 0;
|
|
863
|
+
padding: 0 0 var(--space-4);
|
|
864
|
+
overflow: hidden;
|
|
865
|
+
background: var(--bg);
|
|
866
|
+
border-color: var(--border);
|
|
867
|
+
corner-shape: var(--card-corner-shape);
|
|
868
|
+
border-radius: var(--radius-xl);
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
.card.card:lang(en) {
|
|
872
|
+
--chat-question-width: calc(var(--size-24) * 2);
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
.header {
|
|
876
|
+
display: flex;
|
|
877
|
+
align-items: center;
|
|
878
|
+
min-width: 0;
|
|
879
|
+
padding: var(--space-2) var(--chat-content-inset) var(--space-1);
|
|
880
|
+
background: var(--bg);
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
.threadTrigger.threadTrigger {
|
|
884
|
+
max-width: 100%;
|
|
885
|
+
min-width: 0;
|
|
886
|
+
justify-content: flex-start;
|
|
887
|
+
padding-inline: var(--space-2);
|
|
888
|
+
font-size: var(--text-base);
|
|
889
|
+
font-weight: var(--font-weight-medium);
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
.threadTitle {
|
|
893
|
+
display: block;
|
|
894
|
+
min-width: 0;
|
|
895
|
+
overflow: hidden;
|
|
896
|
+
text-overflow: ellipsis;
|
|
897
|
+
white-space: nowrap;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
.viewport {
|
|
901
|
+
min-height: 0;
|
|
902
|
+
min-width: 0;
|
|
903
|
+
overflow-y: auto;
|
|
904
|
+
overscroll-behavior: contain;
|
|
905
|
+
padding-top: var(--space-4);
|
|
906
|
+
scroll-padding-block: var(--space-4);
|
|
907
|
+
mask-image: linear-gradient(to bottom, transparent, var(--fixed-black) var(--space-4));
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
.viewport:focus-visible {
|
|
911
|
+
outline: none;
|
|
912
|
+
background: var(--hover);
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
.messages {
|
|
916
|
+
display: flex;
|
|
917
|
+
flex-direction: column;
|
|
918
|
+
gap: var(--space-5);
|
|
919
|
+
padding: var(--space-2) var(--chat-content-inset) var(--space-5);
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
.messageText {
|
|
923
|
+
white-space: pre-wrap;
|
|
924
|
+
overflow-wrap: anywhere;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
.assistant.assistant [data-ai-message-body] {
|
|
928
|
+
font-size: var(--text-base);
|
|
929
|
+
line-height: var(--lh-base);
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
.welcome {
|
|
933
|
+
display: flex;
|
|
934
|
+
min-height: 100%;
|
|
935
|
+
flex-direction: column;
|
|
936
|
+
align-items: center;
|
|
937
|
+
justify-content: center;
|
|
938
|
+
gap: var(--space-1);
|
|
939
|
+
padding: var(--space-8) var(--space-5) var(--space-10);
|
|
940
|
+
text-align: center;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
.greeting.greeting,
|
|
944
|
+
.invitation.invitation {
|
|
945
|
+
margin: 0;
|
|
946
|
+
font-size: clamp(var(--text-xl), 4cqi, var(--text-2xl));
|
|
947
|
+
font-weight: var(--font-weight-semibold);
|
|
948
|
+
line-height: var(--lh-snug);
|
|
949
|
+
letter-spacing: var(--tracking-tight);
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
.greeting.greeting {
|
|
953
|
+
color: var(--fg-strong);
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
.invitation.invitation {
|
|
957
|
+
color: var(--chat-secondary-fg);
|
|
958
|
+
text-wrap: balance;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
.bottom {
|
|
962
|
+
display: flex;
|
|
963
|
+
flex-direction: column;
|
|
964
|
+
gap: var(--space-1);
|
|
965
|
+
min-width: 0;
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
.questions {
|
|
969
|
+
display: flex;
|
|
970
|
+
align-items: flex-start;
|
|
971
|
+
gap: var(--space-2);
|
|
972
|
+
padding: var(--space-2) var(--chat-content-inset);
|
|
973
|
+
overflow-x: auto;
|
|
974
|
+
overscroll-behavior-inline: contain;
|
|
975
|
+
scroll-padding-inline: var(--chat-content-inset);
|
|
976
|
+
scrollbar-width: none;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
.question.question {
|
|
980
|
+
flex: 0 0 var(--chat-question-width);
|
|
981
|
+
margin-top: 0;
|
|
982
|
+
word-break: keep-all;
|
|
983
|
+
border-radius: var(--radius-lg);
|
|
984
|
+
--selected-fg: var(--fg-muted);
|
|
985
|
+
--ring-shadow-field: none;
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
.question > span:first-of-type {
|
|
989
|
+
box-shadow: none;
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
.question:focus-visible {
|
|
993
|
+
background: var(--hover);
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
.composer.composer {
|
|
997
|
+
--chat-input-padding-y: var(--space-2);
|
|
998
|
+
margin-inline: var(--chat-content-inset);
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
.composer textarea::placeholder {
|
|
1002
|
+
color: var(--chat-secondary-fg);
|
|
1003
|
+
white-space: nowrap;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
.composer button:disabled {
|
|
1007
|
+
cursor: not-allowed;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
@container (max-width: 480px) {
|
|
1011
|
+
.card.card {
|
|
1012
|
+
--chat-content-inset: var(--space-3);
|
|
1013
|
+
--chat-card-height: calc(var(--size-24) * 5);
|
|
1014
|
+
--chat-question-width: calc(var(--size-unit) * 40);
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
/* Independent page: shared conversation, wider track and its own shell. */
|
|
1021
|
+
.fullPage {
|
|
1022
|
+
--chat-content-inset: var(--space-6);
|
|
1023
|
+
--chat-secondary-fg: color-mix(in oklch, var(--fg-strong) 60%, var(--bg));
|
|
1024
|
+
--chat-page-width: calc(var(--size-24) * 8);
|
|
1025
|
+
--app-frame-bg: var(--bg);
|
|
1026
|
+
--chat-page-offset: 0px;
|
|
1027
|
+
--chat-page-height: 100dvh;
|
|
1028
|
+
|
|
1029
|
+
position: fixed;
|
|
1030
|
+
inset-inline: 0;
|
|
1031
|
+
top: var(--chat-page-offset);
|
|
1032
|
+
height: var(--chat-page-height);
|
|
1033
|
+
width: 100%;
|
|
1034
|
+
container-type: inline-size;
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
.fullPage > [data-slot="app-frame-content"] {
|
|
1038
|
+
overflow: hidden;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
.fullPage .header {
|
|
1042
|
+
padding: 0;
|
|
1043
|
+
background: transparent;
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
.pageBody {
|
|
1047
|
+
display: grid;
|
|
1048
|
+
grid-template-rows: minmax(0, 1fr) auto;
|
|
1049
|
+
height: 100%;
|
|
1050
|
+
min-height: 0;
|
|
1051
|
+
min-width: 0;
|
|
1052
|
+
overflow: hidden;
|
|
1053
|
+
background: var(--app-frame-bg);
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
.fullPage .messages {
|
|
1057
|
+
width: 100%;
|
|
1058
|
+
max-width: var(--chat-page-width);
|
|
1059
|
+
margin-inline: auto;
|
|
1060
|
+
gap: 0;
|
|
1061
|
+
padding-block: var(--space-6) var(--space-8);
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
.fullPage .bottom {
|
|
1065
|
+
width: 100%;
|
|
1066
|
+
max-width: var(--chat-page-width);
|
|
1067
|
+
margin-inline: auto;
|
|
1068
|
+
padding-bottom: max(var(--space-6), env(safe-area-inset-bottom));
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
.fullPage .composer.composer {
|
|
1072
|
+
--chat-input-padding-y: var(--space-4);
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
|
|
1076
|
+
|
|
1077
|
+
@media (max-width: 640px) {
|
|
1078
|
+
.fullPage {
|
|
1079
|
+
--chat-content-inset: var(--space-4);
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
|
|
1083
|
+
|
|
1084
|
+
.fullPage .bottom {
|
|
1085
|
+
padding-bottom: max(var(--space-4), env(safe-area-inset-bottom));
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
/* Full application shell: full-height left navigation with a topbar beside it. */
|
|
1090
|
+
.fullPage.fullPage[data-has-sidebar][data-layout="sidebar-first"] {
|
|
1091
|
+
--chat-history-width: calc(var(--size-24) * 3);
|
|
1092
|
+
|
|
1093
|
+
grid-template-columns: var(--chat-history-width) minmax(0, 1fr);
|
|
1094
|
+
grid-template-rows: auto minmax(0, 1fr);
|
|
1095
|
+
grid-template-areas: "sidebar topbar" "sidebar content";
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
.fullPage.fullPage[data-has-sidebar] > [data-slot="app-frame-sidebar"] {
|
|
1099
|
+
display: flex;
|
|
1100
|
+
min-width: 0;
|
|
1101
|
+
border-inline-end: 1px solid var(--border);
|
|
1102
|
+
background: var(--app-frame-bg);
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
.threadHeading {
|
|
1106
|
+
flex: 1 1 0;
|
|
1107
|
+
min-width: 0;
|
|
1108
|
+
max-width: 100%;
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
.mobileThreadTrigger.mobileThreadTrigger {
|
|
1112
|
+
max-width: 100%;
|
|
1113
|
+
padding-inline: 0;
|
|
1114
|
+
font: inherit;
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
.pageThreadTitle {
|
|
1118
|
+
display: block;
|
|
1119
|
+
overflow: hidden;
|
|
1120
|
+
text-overflow: ellipsis;
|
|
1121
|
+
white-space: nowrap;
|
|
1122
|
+
color: var(--fg-strong);
|
|
1123
|
+
font-size: var(--text-base);
|
|
1124
|
+
font-weight: var(--font-weight-medium);
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
.pageThreadTitle:focus {
|
|
1128
|
+
outline: none;
|
|
1129
|
+
color: var(--fg-strong);
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
.history.history {
|
|
1133
|
+
width: 100%;
|
|
1134
|
+
min-width: 0;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
.historyHeaderInner {
|
|
1138
|
+
display: flex;
|
|
1139
|
+
flex-direction: column;
|
|
1140
|
+
gap: var(--space-2);
|
|
1141
|
+
width: 100%;
|
|
1142
|
+
padding: var(--space-4) var(--space-4) var(--space-2);
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
.historyTitle.historyTitle {
|
|
1146
|
+
margin: 0;
|
|
1147
|
+
font-size: var(--text-base);
|
|
1148
|
+
line-height: var(--lh-base);
|
|
1149
|
+
font-weight: var(--font-weight-semibold);
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
.historyBodyInner.historyBodyInner {
|
|
1153
|
+
display: flex;
|
|
1154
|
+
flex-direction: column;
|
|
1155
|
+
flex: 1 0 auto;
|
|
1156
|
+
gap: var(--space-3);
|
|
1157
|
+
padding: var(--space-2) var(--space-3) var(--space-4);
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
.historyEmpty.historyEmpty {
|
|
1161
|
+
flex: 1 0 auto;
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
|
|
1165
|
+
@media (max-width: 700px) {
|
|
1166
|
+
.fullPage.fullPage[data-has-sidebar][data-layout="sidebar-first"] {
|
|
1167
|
+
grid-template-columns: minmax(0, 1fr);
|
|
1168
|
+
grid-template-areas: "topbar" "content";
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
.fullPage.fullPage[data-has-sidebar] > [data-slot="app-frame-sidebar"] {
|
|
1172
|
+
display: none;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
.fullPage.fullPage[data-has-sidebar][data-mobile-view="threads"] {
|
|
1176
|
+
grid-template-areas: "topbar" "sidebar";
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
.fullPage.fullPage[data-has-sidebar][data-mobile-view="threads"] > [data-slot="app-frame-sidebar"] {
|
|
1180
|
+
display: flex;
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
.fullPage.fullPage[data-has-sidebar][data-mobile-view="threads"] > [data-slot="app-frame-content"] {
|
|
1184
|
+
display: none;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
````
|
|
1188
|
+
|
|
1189
|
+
### Source: web/examples/ai-chat/ChatExperience.tsx
|
|
1190
|
+
|
|
1191
|
+
````tsx
|
|
1192
|
+
"use client";
|
|
1193
|
+
|
|
1194
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
1195
|
+
import { Button } from "@/components/Button";
|
|
1196
|
+
import { DropdownMenu } from "@/components/DropdownMenu";
|
|
1197
|
+
import { Icon } from "@/components/Icon";
|
|
1198
|
+
import { IconButton } from "@/components/IconButton";
|
|
1199
|
+
import { Modal } from "@/components/Modal";
|
|
1200
|
+
import { UserMessage } from "@/components/UserMessage";
|
|
1201
|
+
import { AIMessage } from "@/components/AIMessage";
|
|
1202
|
+
import { useChatDemo } from "./useChatDemo";
|
|
1203
|
+
import { Card } from "@/components/Card";
|
|
1204
|
+
import { AppFrame } from "@/components/AppFrame";
|
|
1205
|
+
import { Topbar } from "@/components/Topbar";
|
|
1206
|
+
import { Sidebar } from "@/components/Sidebar";
|
|
1207
|
+
import { Input } from "@/components/Input";
|
|
1208
|
+
import { MenuItem } from "@/components/MenuItem";
|
|
1209
|
+
import { EmptyState } from "@/components/EmptyState";
|
|
1210
|
+
import { AIChatInput } from "@/components/ChatInput";
|
|
1211
|
+
import { RadioCard } from "@/components/RadioCard";
|
|
1212
|
+
import styles from "./ChatExperience.module.css";
|
|
1213
|
+
|
|
1214
|
+
const content = {
|
|
1215
|
+
en: {
|
|
1216
|
+
title: "New chat",
|
|
1217
|
+
history: "Chat history", searchChats: "Search chats", recentChats: "Recent chats", searchResults: "Search results", noChats: "No chats yet", noResults: "No matching chats", showHistory: "Open chat history", hideHistory: "Close chat history",
|
|
1218
|
+
greeting: "Hello there.",
|
|
1219
|
+
invitation: "What are we working on?",
|
|
1220
|
+
placeholder: "Ask anything about your work",
|
|
1221
|
+
suggestionsLabel: "Send a starting question",
|
|
1222
|
+
switchThread: "Switch thread",
|
|
1223
|
+
createThread: "New chat",
|
|
1224
|
+
messagesLabel: "Conversation",
|
|
1225
|
+
threadTitles: ["Meeting notes", "Follow-up email", "Document summary"],
|
|
1226
|
+
replies: [
|
|
1227
|
+
"Share your meeting notes and I’ll organize them into decisions and action items.\n\nFor each action, include the task, owner, and due date when available.",
|
|
1228
|
+
"Who is the email for, and what should it cover?\n\nShare the purpose, key points, and preferred tone. I’ll help turn them into a clear follow-up.",
|
|
1229
|
+
"Paste the document you want to summarize.\n\nI’ll organize it around the main points, supporting details, and anything that needs a follow-up.",
|
|
1230
|
+
],
|
|
1231
|
+
fallbackReply: "Tell me a little more about the result you need.\n\nYou can share the context, the key information, and the format you would like to work toward.",
|
|
1232
|
+
questions: [
|
|
1233
|
+
"Turn meeting notes into action items",
|
|
1234
|
+
"Help me draft a follow-up email",
|
|
1235
|
+
"Summarize the key points of a document",
|
|
1236
|
+
],
|
|
1237
|
+
},
|
|
1238
|
+
ko: {
|
|
1239
|
+
title: "새 대화",
|
|
1240
|
+
history: "대화 기록", searchChats: "대화 검색", recentChats: "최근 대화", searchResults: "검색 결과", noChats: "아직 대화가 없어요", noResults: "검색 결과가 없어요", showHistory: "대화 기록 열기", hideHistory: "대화 기록 닫기",
|
|
1241
|
+
greeting: "안녕하세요.",
|
|
1242
|
+
invitation: "어떤 일을 도와드릴까요?",
|
|
1243
|
+
placeholder: "도움이 필요한 일을 알려주세요",
|
|
1244
|
+
suggestionsLabel: "추천 질문 바로 보내기",
|
|
1245
|
+
switchThread: "대화 전환",
|
|
1246
|
+
createThread: "새 대화",
|
|
1247
|
+
messagesLabel: "대화 내용",
|
|
1248
|
+
threadTitles: ["회의 메모 정리", "후속 메일 초안", "문서 요약"],
|
|
1249
|
+
replies: [
|
|
1250
|
+
"정리할 회의 메모를 보내주세요. 결정 사항과 실행 항목을 구분해 정리할게요.\n\n실행 항목마다 할 일, 담당자, 기한이 있다면 함께 알려주세요.",
|
|
1251
|
+
"누구에게 어떤 목적으로 보내는 메일인가요?\n\n꼭 포함할 내용과 원하는 말투를 알려주시면 후속 업무 메일 초안을 작성할게요.",
|
|
1252
|
+
"요약할 문서 내용을 붙여 넣어주세요.\n\n핵심 내용과 근거, 추가로 확인할 사항을 나누어 정리할게요.",
|
|
1253
|
+
],
|
|
1254
|
+
fallbackReply: "어떤 결과가 필요한지 조금 더 알려주세요.\n\n관련 맥락과 꼭 포함할 내용, 원하는 정리 형식을 함께 보내주시면 다음 내용을 구체화할 수 있어요.",
|
|
1255
|
+
questions: [
|
|
1256
|
+
"회의 메모를 실행 항목으로 정리하기",
|
|
1257
|
+
"후속 업무 메일 초안 작성하기",
|
|
1258
|
+
"문서의 핵심 내용 요약하기",
|
|
1259
|
+
],
|
|
1260
|
+
},
|
|
1261
|
+
};
|
|
1262
|
+
|
|
1263
|
+
export function ChatExperience({ lang, presentation = "card" }: { lang: "en" | "ko"; presentation?: "card" | "page" }) {
|
|
1264
|
+
const isPage = presentation === "page";
|
|
1265
|
+
const t = content[lang];
|
|
1266
|
+
const [threadMenuOpen, setThreadMenuOpen] = useState(false);
|
|
1267
|
+
const [mobileView, setMobileView] = useState<"chat" | "threads">("chat");
|
|
1268
|
+
const [isMobile, setIsMobile] = useState(false);
|
|
1269
|
+
const [threadSearch, setThreadSearch] = useState("");
|
|
1270
|
+
const [renameTarget, setRenameTarget] = useState<string | null>(null);
|
|
1271
|
+
const [threadName, setThreadName] = useState("");
|
|
1272
|
+
const searchRef = useRef<HTMLInputElement>(null);
|
|
1273
|
+
const pageTitleRef = useRef<HTMLSpanElement>(null);
|
|
1274
|
+
const historyToggleRef = useRef<HTMLButtonElement>(null);
|
|
1275
|
+
const threadActionsRef = useRef<HTMLButtonElement>(null);
|
|
1276
|
+
const focusConversation = useRef(false);
|
|
1277
|
+
useLayoutEffect(() => {
|
|
1278
|
+
if (!isPage) return;
|
|
1279
|
+
const media = window.matchMedia("(max-width: 700px)");
|
|
1280
|
+
const update = () => setIsMobile(media.matches);
|
|
1281
|
+
update();
|
|
1282
|
+
media.addEventListener("change", update);
|
|
1283
|
+
return () => media.removeEventListener("change", update);
|
|
1284
|
+
}, [isPage]);
|
|
1285
|
+
useLayoutEffect(() => {
|
|
1286
|
+
if (focusConversation.current && (!isMobile || mobileView === "chat")) {
|
|
1287
|
+
pageTitleRef.current?.focus({ preventScroll: true });
|
|
1288
|
+
focusConversation.current = false;
|
|
1289
|
+
}
|
|
1290
|
+
}, [isMobile, mobileView]);
|
|
1291
|
+
const getReply = (text: string) => t.replies[t.questions.indexOf(text)] ?? t.fallbackReply;
|
|
1292
|
+
const getTitle = (text: string) => t.threadTitles[t.questions.indexOf(text)] ?? Array.from(text).slice(0, 18).join("");
|
|
1293
|
+
const { threads, activeThread, setActiveId, createThread, renameThread, deleteThread, setDraft, send, stop, edit, regenerate, isStreaming } = useChatDemo(getReply, getTitle);
|
|
1294
|
+
const viewportRef = useRef<HTMLDivElement>(null);
|
|
1295
|
+
const pageRef = useRef<HTMLDivElement>(null);
|
|
1296
|
+
useLayoutEffect(() => {
|
|
1297
|
+
if (!isPage) return;
|
|
1298
|
+
const viewport = window.visualViewport;
|
|
1299
|
+
const resize = () => {
|
|
1300
|
+
pageRef.current?.style.setProperty("--chat-page-height", `${viewport?.height ?? window.innerHeight}px`);
|
|
1301
|
+
pageRef.current?.style.setProperty("--chat-page-offset", `${viewport?.offsetTop ?? 0}px`);
|
|
1302
|
+
};
|
|
1303
|
+
resize();
|
|
1304
|
+
viewport?.addEventListener("resize", resize);
|
|
1305
|
+
viewport?.addEventListener("scroll", resize);
|
|
1306
|
+
window.addEventListener("resize", resize);
|
|
1307
|
+
return () => {
|
|
1308
|
+
viewport?.removeEventListener("resize", resize);
|
|
1309
|
+
viewport?.removeEventListener("scroll", resize);
|
|
1310
|
+
window.removeEventListener("resize", resize);
|
|
1311
|
+
};
|
|
1312
|
+
}, [isPage]);
|
|
1313
|
+
const composerRef = useRef<HTMLDivElement>(null);
|
|
1314
|
+
const scrollPositions = useRef(new Map<string, number>());
|
|
1315
|
+
const previousThread = useRef(activeThread.id);
|
|
1316
|
+
const navigationSuspended = useRef(false);
|
|
1317
|
+
const followLatest = useRef(true);
|
|
1318
|
+
const focusAfterSend = useRef(false);
|
|
1319
|
+
const newMessageIds = useRef(new Set<string>());
|
|
1320
|
+
const hasMessages = activeThread.messages.length > 0;
|
|
1321
|
+
|
|
1322
|
+
useLayoutEffect(() => {
|
|
1323
|
+
const viewport = viewportRef.current;
|
|
1324
|
+
if (!viewport) return;
|
|
1325
|
+
if (isPage && isMobile && mobileView === "threads") {
|
|
1326
|
+
navigationSuspended.current = true;
|
|
1327
|
+
return;
|
|
1328
|
+
}
|
|
1329
|
+
if (previousThread.current !== activeThread.id || navigationSuspended.current) {
|
|
1330
|
+
viewport.scrollTop = scrollPositions.current.get(activeThread.id) ?? viewport.scrollHeight;
|
|
1331
|
+
followLatest.current = viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight < viewport.clientHeight * 0.1;
|
|
1332
|
+
previousThread.current = activeThread.id;
|
|
1333
|
+
navigationSuspended.current = false;
|
|
1334
|
+
} else if (followLatest.current) {
|
|
1335
|
+
viewport.scrollTop = viewport.scrollHeight;
|
|
1336
|
+
}
|
|
1337
|
+
if (focusAfterSend.current) {
|
|
1338
|
+
composerRef.current?.querySelector("textarea")?.focus({ preventScroll: true });
|
|
1339
|
+
focusAfterSend.current = false;
|
|
1340
|
+
}
|
|
1341
|
+
}, [activeThread.id, activeThread.messages, isPage, isMobile, mobileView]);
|
|
1342
|
+
|
|
1343
|
+
const saveScroll = () => {
|
|
1344
|
+
newMessageIds.current.clear();
|
|
1345
|
+
if (viewportRef.current && !(isPage && isMobile && mobileView === "threads")) scrollPositions.current.set(activeThread.id, viewportRef.current.scrollTop);
|
|
1346
|
+
};
|
|
1347
|
+
const sendPrompt = (text: string, focusInput = true) => {
|
|
1348
|
+
if (!text.trim() || isStreaming) return;
|
|
1349
|
+
followLatest.current = true;
|
|
1350
|
+
focusAfterSend.current = focusInput;
|
|
1351
|
+
newMessageIds.current.add(`${activeThread.id}-${activeThread.messages.length}-user`);
|
|
1352
|
+
send(text);
|
|
1353
|
+
};
|
|
1354
|
+
|
|
1355
|
+
const toggleHistory = () => {
|
|
1356
|
+
saveScroll();
|
|
1357
|
+
setMobileView((view) => view === "chat" ? "threads" : "chat");
|
|
1358
|
+
};
|
|
1359
|
+
const newChat = () => {
|
|
1360
|
+
saveScroll();
|
|
1361
|
+
createThread();
|
|
1362
|
+
setThreadSearch("");
|
|
1363
|
+
focusConversation.current = isMobile;
|
|
1364
|
+
setMobileView("chat");
|
|
1365
|
+
};
|
|
1366
|
+
const normalizedSearch = threadSearch.trim().toLocaleLowerCase();
|
|
1367
|
+
const historyThreads = [...threads].reverse().filter((thread) => thread.title || thread.messages.length > 0 || thread.draft.trim());
|
|
1368
|
+
const visibleThreads = historyThreads.filter((thread) => [thread.title, thread.draft, ...thread.messages.map((message) => message.text)].join(" ").toLocaleLowerCase().includes(normalizedSearch));
|
|
1369
|
+
|
|
1370
|
+
const header = (
|
|
1371
|
+
<div className={styles.header}>
|
|
1372
|
+
<DropdownMenu open={threadMenuOpen} onOpenChange={setThreadMenuOpen}>
|
|
1373
|
+
<DropdownMenu.Trigger asChild>
|
|
1374
|
+
<Button
|
|
1375
|
+
variant="ghost"
|
|
1376
|
+
size="md"
|
|
1377
|
+
className={styles.threadTrigger}
|
|
1378
|
+
rightIcon={<Icon name="caret-down" />}
|
|
1379
|
+
aria-label={`${t.switchThread}: ${activeThread.title || t.title}`}
|
|
1380
|
+
>
|
|
1381
|
+
<span className={styles.threadTitle}>{activeThread.title || t.title}</span>
|
|
1382
|
+
</Button>
|
|
1383
|
+
</DropdownMenu.Trigger>
|
|
1384
|
+
<DropdownMenu.Content align="start" size="sm">
|
|
1385
|
+
<DropdownMenu.Item
|
|
1386
|
+
leadingActions={[{ node: <Icon name="plus" />, key: "new-thread" }]}
|
|
1387
|
+
onSelect={() => { saveScroll(); createThread(); setThreadMenuOpen(false); }}
|
|
1388
|
+
>
|
|
1389
|
+
{t.createThread}
|
|
1390
|
+
</DropdownMenu.Item>
|
|
1391
|
+
{threads.some((thread) => thread.messages.length > 0 || thread.draft.trim()) && (
|
|
1392
|
+
<>
|
|
1393
|
+
<DropdownMenu.Separator />
|
|
1394
|
+
<DropdownMenu.Group>
|
|
1395
|
+
{[...threads].reverse()
|
|
1396
|
+
.filter((thread) => thread.messages.length > 0 || thread.draft.trim())
|
|
1397
|
+
.map((thread) => (
|
|
1398
|
+
<DropdownMenu.Item
|
|
1399
|
+
key={thread.id}
|
|
1400
|
+
onSelect={() => { saveScroll(); setActiveId(thread.id); setThreadMenuOpen(false); }}
|
|
1401
|
+
>
|
|
1402
|
+
{thread.title || Array.from(thread.draft.trim()).slice(0, 18).join("")}
|
|
1403
|
+
</DropdownMenu.Item>
|
|
1404
|
+
))}
|
|
1405
|
+
</DropdownMenu.Group>
|
|
1406
|
+
</>
|
|
1407
|
+
)}
|
|
1408
|
+
</DropdownMenu.Content>
|
|
1409
|
+
</DropdownMenu>
|
|
1410
|
+
</div>
|
|
1411
|
+
);
|
|
1412
|
+
const viewport = (
|
|
1413
|
+
<div
|
|
1414
|
+
ref={viewportRef}
|
|
1415
|
+
className={styles.viewport}
|
|
1416
|
+
data-chat-viewport
|
|
1417
|
+
tabIndex={hasMessages ? 0 : undefined}
|
|
1418
|
+
aria-label={t.messagesLabel}
|
|
1419
|
+
onScroll={(event) => {
|
|
1420
|
+
if (isPage && isMobile && mobileView === "threads") return;
|
|
1421
|
+
const viewport = event.currentTarget;
|
|
1422
|
+
scrollPositions.current.set(activeThread.id, viewport.scrollTop);
|
|
1423
|
+
followLatest.current = viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight < viewport.clientHeight * 0.1;
|
|
1424
|
+
}}
|
|
1425
|
+
>
|
|
1426
|
+
{hasMessages ? (
|
|
1427
|
+
<div className={styles.messages} role="log" aria-live="polite" aria-relevant="additions text" aria-label={t.messagesLabel}>
|
|
1428
|
+
{activeThread.messages.map((message) => message.role === "user" ? (
|
|
1429
|
+
<UserMessage key={message.id} actionsVisibility="hover" textValue={message.text}
|
|
1430
|
+
onEdit={(text) => edit(message.id, text)} animate={newMessageIds.current.has(message.id)}>
|
|
1431
|
+
<span className={styles.messageText}>{message.text}</span>
|
|
1432
|
+
</UserMessage>
|
|
1433
|
+
) : (
|
|
1434
|
+
<AIMessage key={message.id} actionsVisibility="hover" actions={[
|
|
1435
|
+
{ kind: "copy", onClick: () => navigator.clipboard.writeText(message.text), successLabel: lang === "ko" ? "복사됨" : "Copied", errorLabel: lang === "ko" ? "복사 실패" : "Copy failed" },
|
|
1436
|
+
{ kind: "regenerate", onClick: () => regenerate(message.id) },
|
|
1437
|
+
]} isStreaming={message.isStreaming} className={styles.assistant}>
|
|
1438
|
+
{message.text}
|
|
1439
|
+
</AIMessage>
|
|
1440
|
+
))}
|
|
1441
|
+
</div>
|
|
1442
|
+
) : !isPage ? (
|
|
1443
|
+
<div className={styles.welcome}>
|
|
1444
|
+
<p className={styles.greeting}>{t.greeting}</p>
|
|
1445
|
+
<p className={styles.invitation}>{t.invitation}</p>
|
|
1446
|
+
</div>
|
|
1447
|
+
) : null}
|
|
1448
|
+
</div>
|
|
1449
|
+
);
|
|
1450
|
+
const bottom = (
|
|
1451
|
+
<div className={styles.bottom}>
|
|
1452
|
+
{!isPage && !hasMessages && (
|
|
1453
|
+
<div className={styles.questions} role="group" aria-label={t.suggestionsLabel}>
|
|
1454
|
+
{t.questions.map((question) => (
|
|
1455
|
+
<RadioCard
|
|
1456
|
+
key={question}
|
|
1457
|
+
mode="button"
|
|
1458
|
+
onClick={(event) => sendPrompt(question, event.detail === 0)}
|
|
1459
|
+
onFocus={(event) => event.currentTarget.scrollIntoView({ block: "nearest", inline: "nearest" })}
|
|
1460
|
+
align="start"
|
|
1461
|
+
size="md"
|
|
1462
|
+
title={question}
|
|
1463
|
+
className={styles.question}
|
|
1464
|
+
/>
|
|
1465
|
+
))}
|
|
1466
|
+
</div>
|
|
1467
|
+
)}
|
|
1468
|
+
<AIChatInput
|
|
1469
|
+
ref={composerRef}
|
|
1470
|
+
shape={isPage ? "multi" : "single"}
|
|
1471
|
+
appearance={isPage ? "outline" : "filled"}
|
|
1472
|
+
separateSend={!isPage}
|
|
1473
|
+
value={activeThread.draft}
|
|
1474
|
+
onChange={setDraft}
|
|
1475
|
+
onSend={() => sendPrompt(activeThread.draft)}
|
|
1476
|
+
isStreaming={isStreaming}
|
|
1477
|
+
onStop={stop}
|
|
1478
|
+
sendVariant="solid"
|
|
1479
|
+
placeholder={t.placeholder}
|
|
1480
|
+
className={styles.composer}
|
|
1481
|
+
/>
|
|
1482
|
+
</div>
|
|
1483
|
+
);
|
|
1484
|
+
|
|
1485
|
+
if (isPage) return (
|
|
1486
|
+
<AppFrame ref={pageRef} variant="flat" layout="sidebar-first" className={styles.fullPage} data-ai-chat-page data-chat-thread={activeThread.id} data-mobile-view={mobileView} lang={lang}>
|
|
1487
|
+
<AppFrame.Topbar>
|
|
1488
|
+
<Topbar size="sm">
|
|
1489
|
+
<Topbar.Leading className={styles.threadHeading}>
|
|
1490
|
+
<span ref={pageTitleRef} tabIndex={-1} className={styles.pageThreadTitle}>
|
|
1491
|
+
{isMobile ? (
|
|
1492
|
+
<Button ref={historyToggleRef} variant="ghost" size="md" className={styles.mobileThreadTrigger} aria-label={`${mobileView === "threads" ? t.hideHistory : t.showHistory}: ${activeThread.title || t.title}`} aria-expanded={mobileView === "threads"} aria-controls="chat-history" rightIcon={<Icon name={mobileView === "threads" ? "caret-up" : "caret-down"} />} onClick={toggleHistory}>
|
|
1493
|
+
{activeThread.title || t.title}
|
|
1494
|
+
</Button>
|
|
1495
|
+
) : activeThread.title || t.title}
|
|
1496
|
+
</span>
|
|
1497
|
+
</Topbar.Leading>
|
|
1498
|
+
<Topbar.Trailing>
|
|
1499
|
+
<DropdownMenu modal={false}>
|
|
1500
|
+
<DropdownMenu.Trigger asChild>
|
|
1501
|
+
<IconButton ref={threadActionsRef} variant="ghost" size="sm" icon={<Icon name="dots-three" />} aria-label={lang === "ko" ? "대화 메뉴" : "Chat menu"} />
|
|
1502
|
+
</DropdownMenu.Trigger>
|
|
1503
|
+
<DropdownMenu.Content align="end" size="sm">
|
|
1504
|
+
<DropdownMenu.Item leadingActions={[{ node: <Icon name="pencil" />, key: "rename" }]} onSelect={() => { setThreadName(activeThread.title || t.title); setRenameTarget(activeThread.id); }}>
|
|
1505
|
+
{lang === "ko" ? "이름 변경" : "Rename"}
|
|
1506
|
+
</DropdownMenu.Item>
|
|
1507
|
+
<DropdownMenu.Item leadingActions={[{ node: <Icon name="trash" />, key: "delete" }]} onSelect={() => { scrollPositions.current.delete(activeThread.id); deleteThread(activeThread.id); setThreadSearch(""); }}>
|
|
1508
|
+
{lang === "ko" ? "삭제" : "Delete"}
|
|
1509
|
+
</DropdownMenu.Item>
|
|
1510
|
+
</DropdownMenu.Content>
|
|
1511
|
+
</DropdownMenu>
|
|
1512
|
+
</Topbar.Trailing>
|
|
1513
|
+
</Topbar>
|
|
1514
|
+
<Modal open={renameTarget !== null} onOpenChange={(open) => { if (!open) setRenameTarget(null); }} onCloseAutoFocus={(event) => { event.preventDefault(); threadActionsRef.current?.focus(); }} size="sm" title={lang === "ko" ? "쓰레드 이름 변경" : "Rename thread"} dismissLabel={lang === "ko" ? "닫기" : "Close"}
|
|
1515
|
+
footer={<><Button variant="outline" onClick={() => setRenameTarget(null)}>{lang === "ko" ? "취소" : "Cancel"}</Button><Button variant="primary" type="submit" form="rename-chat-thread" disabled={!threadName.trim()}>{lang === "ko" ? "저장" : "Save"}</Button></>}
|
|
1516
|
+
>
|
|
1517
|
+
<form id="rename-chat-thread" onSubmit={(event) => { event.preventDefault(); if (renameTarget && threadName.trim()) { renameThread(renameTarget, threadName); setRenameTarget(null); } }}>
|
|
1518
|
+
<Input autoFocus aria-label={lang === "ko" ? "쓰레드 이름" : "Thread name"} variant="outline" value={threadName} onChange={(event) => setThreadName(event.target.value)} />
|
|
1519
|
+
</form>
|
|
1520
|
+
</Modal>
|
|
1521
|
+
</AppFrame.Topbar>
|
|
1522
|
+
<AppFrame.Sidebar>
|
|
1523
|
+
<Sidebar id="chat-history" className={styles.history} aria-label={t.history} onKeyDown={(event) => {
|
|
1524
|
+
if (event.key === "Escape" && isMobile) {
|
|
1525
|
+
event.preventDefault();
|
|
1526
|
+
setMobileView("chat");
|
|
1527
|
+
historyToggleRef.current?.focus({ preventScroll: true });
|
|
1528
|
+
}
|
|
1529
|
+
}}>
|
|
1530
|
+
<Sidebar.Header>
|
|
1531
|
+
<div className={styles.historyHeaderInner}>
|
|
1532
|
+
<h2 className={styles.historyTitle}>{t.history}</h2>
|
|
1533
|
+
<Button variant="primary" size="md" fullWidth leftIcon={<Icon name="plus" />} onClick={newChat}>{t.createThread}</Button>
|
|
1534
|
+
<form role="search" aria-label={t.searchChats} onSubmit={(event) => event.preventDefault()}>
|
|
1535
|
+
<Input ref={searchRef} type="text" enterKeyHint="search" variant="outline" size="md" aria-label={t.searchChats} placeholder={t.searchChats} leftIcon={<Icon name="search" />} value={threadSearch} onChange={(event) => setThreadSearch(event.target.value)} clearable onClear={() => setThreadSearch("")} />
|
|
1536
|
+
</form>
|
|
1537
|
+
</div>
|
|
1538
|
+
</Sidebar.Header>
|
|
1539
|
+
<Sidebar.Body>
|
|
1540
|
+
<div className={styles.historyBodyInner}>
|
|
1541
|
+
<MenuItem.Section title={normalizedSearch ? t.searchResults : t.recentChats} size="sm" collapsible={false}>
|
|
1542
|
+
{visibleThreads.map((thread) => (
|
|
1543
|
+
<MenuItem key={thread.id} role="button" size="md" active={thread.id === activeThread.id} activeStyle="fill" aria-current={thread.id === activeThread.id ? "page" : undefined} leadingActions={[{ node: <Icon name="chat-circle" />, key: "thread" }]} onClick={() => {
|
|
1544
|
+
saveScroll();
|
|
1545
|
+
setActiveId(thread.id);
|
|
1546
|
+
focusConversation.current = isMobile;
|
|
1547
|
+
setMobileView("chat");
|
|
1548
|
+
}}>{thread.title || Array.from(thread.draft.trim()).slice(0, 18).join("")}</MenuItem>
|
|
1549
|
+
))}
|
|
1550
|
+
</MenuItem.Section>
|
|
1551
|
+
{visibleThreads.length === 0 && <EmptyState className={styles.historyEmpty} size="sm" icon={normalizedSearch ? "search" : "chat-circle"} title={normalizedSearch ? t.noResults : t.noChats} role="status" />}
|
|
1552
|
+
</div>
|
|
1553
|
+
</Sidebar.Body>
|
|
1554
|
+
</Sidebar>
|
|
1555
|
+
</AppFrame.Sidebar>
|
|
1556
|
+
<AppFrame.Content>
|
|
1557
|
+
<main className={styles.pageBody} aria-label={t.messagesLabel}>{viewport}{bottom}</main>
|
|
1558
|
+
</AppFrame.Content>
|
|
1559
|
+
</AppFrame>
|
|
1560
|
+
);
|
|
1561
|
+
return (
|
|
1562
|
+
<Card variant="line" size="lg" className={styles.card} data-ai-chat-card data-chat-thread={activeThread.id} lang={lang}>
|
|
1563
|
+
{header}{viewport}{bottom}
|
|
1564
|
+
</Card>
|
|
1565
|
+
);
|
|
1566
|
+
}
|
|
1567
|
+
````
|
|
1568
|
+
|
|
1569
|
+
### Source: web/examples/ai-chat/ChatUseCases.tsx
|
|
1570
|
+
|
|
1571
|
+
````tsx
|
|
1572
|
+
"use client";
|
|
1573
|
+
|
|
1574
|
+
import { ThemeLocaleProvider } from "@/components/ThemeController";
|
|
1575
|
+
import styles from "./ChatExperience.module.css";
|
|
1576
|
+
import { ChatExperience } from "./ChatExperience";
|
|
1577
|
+
|
|
1578
|
+
export function ChatUseCases({ lang }: { lang: "en" | "ko" }) {
|
|
1579
|
+
return (
|
|
1580
|
+
<div className={styles.stage}>
|
|
1581
|
+
<ThemeLocaleProvider lang={lang}>
|
|
1582
|
+
<ChatExperience lang={lang} />
|
|
1583
|
+
</ThemeLocaleProvider>
|
|
1584
|
+
</div>
|
|
1585
|
+
);
|
|
1586
|
+
}
|
|
1587
|
+
````
|
|
1588
|
+
|
|
1589
|
+
### Source: web/examples/ai-chat/useChatDemo.ts
|
|
1590
|
+
|
|
1591
|
+
````tsx
|
|
1592
|
+
"use client";
|
|
1593
|
+
|
|
1594
|
+
import { useRef, useState } from "react";
|
|
1595
|
+
import { useDemoTextStream } from "./useDemoTextStream";
|
|
1596
|
+
|
|
1597
|
+
export type ChatDemoMessage = { id: string; role: "user" | "assistant"; text: string; isStreaming?: boolean };
|
|
1598
|
+
export type ChatDemoThread = {
|
|
1599
|
+
id: string;
|
|
1600
|
+
title: string;
|
|
1601
|
+
draft: string;
|
|
1602
|
+
messages: ChatDemoMessage[];
|
|
1603
|
+
};
|
|
1604
|
+
|
|
1605
|
+
export function useChatDemo(getReply: (text: string) => string, getTitle: (text: string) => string) {
|
|
1606
|
+
const sequence = useRef(1);
|
|
1607
|
+
const delivery = useDemoTextStream();
|
|
1608
|
+
const pendingThreads = useRef(new Set<string>());
|
|
1609
|
+
const [threads, setThreads] = useState<ChatDemoThread[]>([
|
|
1610
|
+
{ id: "chat-0", title: "", draft: "", messages: [] },
|
|
1611
|
+
]);
|
|
1612
|
+
const [activeId, setActiveId] = useState("chat-0");
|
|
1613
|
+
const activeThread = threads.find((thread) => thread.id === activeId) ?? threads[0];
|
|
1614
|
+
|
|
1615
|
+
const setDraft = (draft: string) => {
|
|
1616
|
+
setThreads((previous) => previous.map((thread) => thread.id === activeId ? { ...thread, draft } : thread));
|
|
1617
|
+
};
|
|
1618
|
+
|
|
1619
|
+
const send = (text: string) => {
|
|
1620
|
+
const value = text.trim();
|
|
1621
|
+
if (!value || pendingThreads.current.has(activeId)) return;
|
|
1622
|
+
const targetId = activeId;
|
|
1623
|
+
const baseMessages = activeThread.messages;
|
|
1624
|
+
const messageId = `${targetId}-${baseMessages.length}`;
|
|
1625
|
+
const assistantId = `${messageId}-assistant`;
|
|
1626
|
+
pendingThreads.current.add(targetId);
|
|
1627
|
+
setThreads((previous) => previous.map((thread) => {
|
|
1628
|
+
if (thread.id !== activeId) return thread;
|
|
1629
|
+
return {
|
|
1630
|
+
...thread,
|
|
1631
|
+
title: thread.title || getTitle(value),
|
|
1632
|
+
draft: "",
|
|
1633
|
+
messages: [
|
|
1634
|
+
...baseMessages,
|
|
1635
|
+
{ id: `${messageId}-user`, role: "user", text: value },
|
|
1636
|
+
{ id: `${messageId}-assistant`, role: "assistant", text: "", isStreaming: true },
|
|
1637
|
+
],
|
|
1638
|
+
};
|
|
1639
|
+
}));
|
|
1640
|
+
delivery.start(targetId, getReply(value), (reply, isStreaming) => {
|
|
1641
|
+
if (!isStreaming) pendingThreads.current.delete(targetId);
|
|
1642
|
+
setThreads((previous) => previous.map((thread) => thread.id === targetId ? {
|
|
1643
|
+
...thread,
|
|
1644
|
+
messages: thread.messages.map((message) => message.id === assistantId ? { ...message, text: reply, isStreaming } : message),
|
|
1645
|
+
} : thread));
|
|
1646
|
+
});
|
|
1647
|
+
};
|
|
1648
|
+
|
|
1649
|
+
const stop = () => {
|
|
1650
|
+
delivery.stop(activeId);
|
|
1651
|
+
pendingThreads.current.delete(activeId);
|
|
1652
|
+
setThreads((previous) => previous.map((thread) => thread.id === activeId ? {
|
|
1653
|
+
...thread, messages: thread.messages.map((message) => message.isStreaming ? { ...message, isStreaming: false } : message),
|
|
1654
|
+
} : thread));
|
|
1655
|
+
};
|
|
1656
|
+
|
|
1657
|
+
const edit = (messageId: string, text: string) => {
|
|
1658
|
+
const value = text.trim();
|
|
1659
|
+
const index = activeThread.messages.findIndex((message) => message.id === messageId && message.role === "user");
|
|
1660
|
+
if (!value || index < 0) return;
|
|
1661
|
+
const targetId = activeId;
|
|
1662
|
+
const assistantId = `${targetId}-${index}-assistant`;
|
|
1663
|
+
delivery.stop(targetId);
|
|
1664
|
+
pendingThreads.current.add(targetId);
|
|
1665
|
+
setThreads((previous) => previous.map((thread) => thread.id === targetId ? {
|
|
1666
|
+
...thread,
|
|
1667
|
+
messages: [
|
|
1668
|
+
...thread.messages.slice(0, index),
|
|
1669
|
+
{ id: messageId, role: "user", text: value },
|
|
1670
|
+
{ id: assistantId, role: "assistant", text: "", isStreaming: true },
|
|
1671
|
+
],
|
|
1672
|
+
} : thread));
|
|
1673
|
+
delivery.start(targetId, getReply(value), (reply, streaming) => {
|
|
1674
|
+
if (!streaming) pendingThreads.current.delete(targetId);
|
|
1675
|
+
setThreads((previous) => previous.map((thread) => thread.id === targetId ? {
|
|
1676
|
+
...thread,
|
|
1677
|
+
messages: thread.messages.map((message) => message.id === assistantId ? { ...message, text: reply, isStreaming: streaming } : message),
|
|
1678
|
+
} : thread));
|
|
1679
|
+
});
|
|
1680
|
+
};
|
|
1681
|
+
|
|
1682
|
+
const regenerate = (messageId: string) => {
|
|
1683
|
+
if (pendingThreads.current.has(activeId)) return;
|
|
1684
|
+
const index = activeThread.messages.findIndex((message) => message.id === messageId && message.role === "assistant");
|
|
1685
|
+
const prompt = activeThread.messages[index - 1];
|
|
1686
|
+
if (index < 1 || prompt?.role !== "user") return;
|
|
1687
|
+
const targetId = activeId;
|
|
1688
|
+
pendingThreads.current.add(targetId);
|
|
1689
|
+
setThreads((previous) => previous.map((thread) => thread.id === targetId ? {
|
|
1690
|
+
...thread,
|
|
1691
|
+
messages: [...thread.messages.slice(0, index), { id: messageId, role: "assistant", text: "", isStreaming: true }],
|
|
1692
|
+
} : thread));
|
|
1693
|
+
delivery.start(targetId, getReply(prompt.text), (text, streaming) => {
|
|
1694
|
+
if (!streaming) pendingThreads.current.delete(targetId);
|
|
1695
|
+
setThreads((previous) => previous.map((thread) => thread.id === targetId ? {
|
|
1696
|
+
...thread,
|
|
1697
|
+
messages: thread.messages.map((message) => message.id === messageId ? { ...message, text, isStreaming: streaming } : message),
|
|
1698
|
+
} : thread));
|
|
1699
|
+
});
|
|
1700
|
+
};
|
|
1701
|
+
|
|
1702
|
+
const createThread = () => {
|
|
1703
|
+
const empty = threads.find((thread) => thread.messages.length === 0 && !thread.draft && !thread.title);
|
|
1704
|
+
if (empty) {
|
|
1705
|
+
setActiveId(empty.id);
|
|
1706
|
+
return;
|
|
1707
|
+
}
|
|
1708
|
+
const id = `chat-${sequence.current++}`;
|
|
1709
|
+
setThreads((previous) => [...previous, { id, title: "", draft: "", messages: [] }]);
|
|
1710
|
+
setActiveId(id);
|
|
1711
|
+
};
|
|
1712
|
+
|
|
1713
|
+
const renameThread = (id: string, title: string) => {
|
|
1714
|
+
if (!title.trim()) return;
|
|
1715
|
+
setThreads((previous) => previous.map((thread) => thread.id === id ? { ...thread, title: title.trim() } : thread));
|
|
1716
|
+
};
|
|
1717
|
+
|
|
1718
|
+
const deleteThread = (id: string) => {
|
|
1719
|
+
delivery.stop(id);
|
|
1720
|
+
pendingThreads.current.delete(id);
|
|
1721
|
+
const remaining = threads.filter((thread) => thread.id !== id);
|
|
1722
|
+
if (!remaining.length) {
|
|
1723
|
+
remaining.push({ id: `chat-${sequence.current++}`, title: "", draft: "", messages: [] });
|
|
1724
|
+
}
|
|
1725
|
+
setThreads(remaining);
|
|
1726
|
+
if (activeId === id) setActiveId(remaining[remaining.length - 1].id);
|
|
1727
|
+
};
|
|
1728
|
+
|
|
1729
|
+
return { threads, activeThread, setActiveId, createThread, renameThread, deleteThread, setDraft, send, stop, edit, regenerate, isStreaming: activeThread.messages.some((message) => message.isStreaming) };
|
|
1730
|
+
}
|
|
1731
|
+
````
|
|
1732
|
+
|
|
1733
|
+
### Source: web/examples/ai-chat/useDemoTextStream.ts
|
|
1734
|
+
|
|
1735
|
+
````tsx
|
|
1736
|
+
"use client";
|
|
1737
|
+
|
|
1738
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
1739
|
+
|
|
1740
|
+
/** Local demo transport. UI components render incoming text without delaying real data. */
|
|
1741
|
+
export function useDemoTextStream() {
|
|
1742
|
+
const jobs = useRef(new Map<string, ReturnType<typeof setInterval>>());
|
|
1743
|
+
const stop = useCallback((id: string) => {
|
|
1744
|
+
clearInterval(jobs.current.get(id));
|
|
1745
|
+
jobs.current.delete(id);
|
|
1746
|
+
}, []);
|
|
1747
|
+
useEffect(() => {
|
|
1748
|
+
const pending = jobs.current;
|
|
1749
|
+
return () => { pending.forEach(clearInterval); pending.clear(); };
|
|
1750
|
+
}, []);
|
|
1751
|
+
const start = useCallback((id: string, text: string, update: (text: string, streaming: boolean) => void) => {
|
|
1752
|
+
stop(id);
|
|
1753
|
+
const characters = Array.from(new Intl.Segmenter(undefined, { granularity: "grapheme" }).segment(text), (part) => part.segment);
|
|
1754
|
+
let index = 0;
|
|
1755
|
+
update("", characters.length > 0);
|
|
1756
|
+
if (!characters.length) return;
|
|
1757
|
+
jobs.current.set(id, setInterval(() => {
|
|
1758
|
+
index += 1;
|
|
1759
|
+
const streaming = index < characters.length;
|
|
1760
|
+
if (!streaming) stop(id);
|
|
1761
|
+
update(characters.slice(0, index).join(""), streaming);
|
|
1762
|
+
}, 24));
|
|
1763
|
+
}, [stop]);
|
|
1764
|
+
return { start, stop };
|
|
1765
|
+
}
|
|
1766
|
+
````
|