@hanzo/ui 4.5.3 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-MCP.md +3 -3
- package/README.md +229 -0
- package/assets/ai-icons.tsx +207 -0
- package/assets/crypto.tsx +33 -0
- package/assets/file-type-icon.tsx +66 -0
- package/assets/file.tsx +45 -0
- package/assets/general.tsx +2318 -0
- package/assets/hanzo-logo.svg +9 -0
- package/assets/hanzo-logo.tsx +15 -0
- package/assets/index.ts +8 -0
- package/assets/index.tsx +4 -0
- package/assets/llm-provider.tsx +1094 -0
- package/bin/create-registry.js +1 -1
- package/bin/test-mcp.sh +1 -1
- package/bin/update-registry.js +2 -2
- package/blocks/components/content.tsx +1 -1
- package/blocks/components/grid-block/index.tsx +1 -1
- package/blocks/components/screenful-block/content.tsx +1 -1
- package/blocks/components/screenful-block/poster-background.tsx +1 -1
- package/components/index.ts +56 -0
- package/dist/button.d.ts +1 -0
- package/dist/button.js +1 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/index.js +7 -0
- package/dist/hooks/use-click-away.d.ts +2 -0
- package/dist/hooks/use-click-away.js +23 -0
- package/dist/hooks/use-combined-refs.d.ts +3 -0
- package/dist/hooks/use-combined-refs.js +18 -0
- package/dist/hooks/use-copy-clipboard.d.ts +9 -0
- package/dist/hooks/use-copy-clipboard.js +21 -0
- package/dist/hooks/use-debounce.d.ts +1 -0
- package/dist/hooks/use-debounce.js +13 -0
- package/dist/hooks/use-fill-ids.d.ts +8 -0
- package/dist/hooks/use-fill-ids.js +20 -0
- package/dist/hooks/use-map.d.ts +1 -0
- package/dist/hooks/use-map.js +20 -0
- package/dist/hooks/use-measure.d.ts +8 -0
- package/dist/hooks/use-measure.js +25 -0
- package/dist/hooks/use-reverse-video-playback.d.ts +1 -0
- package/dist/hooks/use-reverse-video-playback.js +41 -0
- package/dist/hooks/use-scroll-restoration.d.ts +8 -0
- package/dist/hooks/use-scroll-restoration.js +36 -0
- package/dist/mcp/enhanced-server.js +3 -3
- package/dist/mcp/index.js +1 -1
- package/dist/registry/api.d.ts +1 -1
- package/dist/registry/api.js +3 -4
- package/dist/registry/index.d.ts +348 -4
- package/dist/registry/index.js +3 -3
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +1 -0
- package/helpers/file.ts +33 -0
- package/helpers/memoization.ts +40 -0
- package/package.json +27 -6
- package/primitives/accordion.tsx +53 -45
- package/primitives/alert-dialog.tsx +185 -0
- package/primitives/alert.tsx +74 -0
- package/primitives/apply-typography.tsx +1 -1
- package/primitives/avatar.tsx +37 -29
- package/primitives/background-beams.tsx +142 -0
- package/primitives/badge.tsx +27 -19
- package/primitives/breadcrumb.tsx +77 -62
- package/primitives/button.tsx +69 -72
- package/primitives/card.tsx +73 -59
- package/primitives/chat/chat-input-area.tsx +87 -0
- package/primitives/chat/chat-input.tsx +71 -0
- package/primitives/chat/files-preview.tsx +330 -0
- package/primitives/chat/index.ts +6 -0
- package/primitives/chat/json-form.tsx +8 -0
- package/primitives/chat/message-list.tsx +307 -0
- package/primitives/chat/message.tsx +569 -0
- package/primitives/chat/sqlite-preview.tsx +215 -0
- package/primitives/checkbox.tsx +18 -19
- package/primitives/collapsible.tsx +9 -0
- package/primitives/command.tsx +75 -83
- package/primitives/context-menu.tsx +115 -109
- package/primitives/copy-to-clipboard-icon.tsx +60 -0
- package/primitives/dialog-video-controller.tsx +1 -1
- package/primitives/dialog.tsx +111 -145
- package/primitives/dot-pattern.tsx +57 -0
- package/primitives/dots-loader.tsx +13 -0
- package/primitives/drawer.tsx +59 -87
- package/primitives/dropdown-menu.tsx +199 -0
- package/primitives/error-message.tsx +19 -0
- package/primitives/file-uploader.tsx +200 -0
- package/primitives/form.tsx +92 -87
- package/primitives/hover-card.tsx +28 -0
- package/primitives/icons/github.tsx +1 -1
- package/primitives/icons/youtube-logo.tsx +1 -1
- package/primitives/index-common.ts +121 -42
- package/primitives/index-next.ts +3 -1
- package/primitives/input.tsx +115 -20
- package/primitives/label.tsx +15 -23
- package/primitives/loading-spinner.tsx +1 -1
- package/primitives/markdown-preview.tsx +609 -0
- package/primitives/mermaid.tsx +196 -0
- package/primitives/next/link-element.tsx +1 -1
- package/primitives/next/mdx-link.tsx +1 -1
- package/primitives/pagination.tsx +117 -0
- package/primitives/popover.tsx +20 -25
- package/primitives/pretty-json-print.tsx +28 -0
- package/primitives/progress.tsx +14 -15
- package/primitives/prompt-textarea.tsx +72 -0
- package/primitives/qr-code.tsx +112 -0
- package/primitives/radio-group.tsx +25 -39
- package/primitives/resizable.tsx +47 -0
- package/primitives/scroll-area.tsx +35 -25
- package/primitives/search-input.tsx +66 -0
- package/primitives/select.tsx +62 -109
- package/primitives/separator.tsx +22 -26
- package/primitives/sheet.tsx +78 -117
- package/primitives/skeleton.tsx +13 -16
- package/primitives/slider.tsx +50 -60
- package/primitives/stepper.tsx +272 -0
- package/primitives/switch.tsx +14 -23
- package/primitives/table.tsx +65 -77
- package/primitives/tabs.tsx +29 -39
- package/primitives/text-link.tsx +25 -0
- package/primitives/textarea.tsx +61 -0
- package/primitives/textfield.tsx +75 -0
- package/primitives/toast.tsx +30 -0
- package/primitives/toggle-group.tsx +33 -33
- package/primitives/toggle.tsx +22 -51
- package/primitives/tooltip.tsx +37 -38
- package/registry.json +1 -1
- package/src/button.ts +1 -0
- package/src/hooks/index.ts +7 -0
- package/src/hooks/use-click-away.ts +31 -0
- package/src/hooks/use-combined-refs.ts +22 -0
- package/src/hooks/use-copy-clipboard.ts +30 -0
- package/src/hooks/use-debounce.ts +17 -0
- package/src/hooks/use-fill-ids.ts +25 -0
- package/src/hooks/use-map.ts +26 -0
- package/src/hooks/use-measure.ts +42 -0
- package/src/hooks/use-reverse-video-playback.ts +43 -0
- package/src/hooks/use-scroll-restoration.ts +50 -0
- package/{mcp → src/mcp}/README.md +1 -1
- package/{mcp → src/mcp}/enhanced-server.ts +2 -2
- package/{registry → src/registry}/api.ts +3 -3
- package/{registry → src/registry}/index.ts +3 -3
- package/src/utils.ts +1 -0
- package/style/theme-provider.tsx +1 -1
- package/test-imports.mjs +19 -0
- package/tsconfig.json +9 -4
- package/types/animation-def.ts +1 -1
- package/types/button-def.ts +1 -1
- package/types/index.ts +1 -1
- package/util/blob.ts +28 -0
- package/util/copy-to-clipboard.ts +17 -0
- package/util/create-shadow-root.ts +22 -0
- package/util/date.ts +83 -0
- package/util/debounce.ts +11 -0
- package/util/file.ts +15 -0
- package/util/format-and-abbreviate-as-currency.ts +1 -1
- package/util/format-text.ts +33 -0
- package/util/index.ts +9 -78
- package/util/timing.ts +3 -0
- package/util/toasts.tsx +17 -0
- package/utils.ts +9 -0
- package/dist/blocks/components/accordian-block.d.ts +0 -4
- package/dist/blocks/components/accordian-block.jsx +0 -25
- package/dist/blocks/components/block-component-props.d.ts +0 -7
- package/dist/blocks/components/block-component-props.js +0 -1
- package/dist/blocks/components/bullet-cards-block.d.ts +0 -4
- package/dist/blocks/components/bullet-cards-block.jsx +0 -25
- package/dist/blocks/components/card-block/index.d.ts +0 -6
- package/dist/blocks/components/card-block/index.jsx +0 -87
- package/dist/blocks/components/card-block/link-out-button.d.ts +0 -6
- package/dist/blocks/components/card-block/link-out-button.jsx +0 -4
- package/dist/blocks/components/card-block/util.d.ts +0 -4
- package/dist/blocks/components/card-block/util.js +0 -6
- package/dist/blocks/components/carte-blanche-block/index.d.ts +0 -4
- package/dist/blocks/components/carte-blanche-block/index.jsx +0 -82
- package/dist/blocks/components/carte-blanche-block/variant-content-left.d.ts +0 -10
- package/dist/blocks/components/carte-blanche-block/variant-content-left.jsx +0 -23
- package/dist/blocks/components/content.d.ts +0 -10
- package/dist/blocks/components/content.jsx +0 -47
- package/dist/blocks/components/cta-block.d.ts +0 -12
- package/dist/blocks/components/cta-block.jsx +0 -69
- package/dist/blocks/components/enh-heading-block.d.ts +0 -7
- package/dist/blocks/components/enh-heading-block.jsx +0 -142
- package/dist/blocks/components/grid-block/grid-block-mutator.d.ts +0 -5
- package/dist/blocks/components/grid-block/grid-block-mutator.js +0 -1
- package/dist/blocks/components/grid-block/index.d.ts +0 -9
- package/dist/blocks/components/grid-block/index.jsx +0 -56
- package/dist/blocks/components/grid-block/mutator-registry.d.ts +0 -3
- package/dist/blocks/components/grid-block/mutator-registry.js +0 -5
- package/dist/blocks/components/grid-block/table-borders.mutator.d.ts +0 -3
- package/dist/blocks/components/grid-block/table-borders.mutator.js +0 -36
- package/dist/blocks/components/group-block.d.ts +0 -7
- package/dist/blocks/components/group-block.jsx +0 -61
- package/dist/blocks/components/heading-block.d.ts +0 -4
- package/dist/blocks/components/heading-block.jsx +0 -99
- package/dist/blocks/components/image-block.d.ts +0 -7
- package/dist/blocks/components/image-block.jsx +0 -69
- package/dist/blocks/components/index.d.ts +0 -14
- package/dist/blocks/components/index.js +0 -13
- package/dist/blocks/components/screenful-block/content.d.ts +0 -8
- package/dist/blocks/components/screenful-block/content.jsx +0 -71
- package/dist/blocks/components/screenful-block/index.d.ts +0 -12
- package/dist/blocks/components/screenful-block/index.jsx +0 -57
- package/dist/blocks/components/screenful-block/poster-background.d.ts +0 -7
- package/dist/blocks/components/screenful-block/poster-background.jsx +0 -14
- package/dist/blocks/components/screenful-block/video-background.d.ts +0 -8
- package/dist/blocks/components/screenful-block/video-background.jsx +0 -20
- package/dist/blocks/components/space-block.d.ts +0 -4
- package/dist/blocks/components/space-block.jsx +0 -42
- package/dist/blocks/components/video-block.d.ts +0 -9
- package/dist/blocks/components/video-block.jsx +0 -83
- package/dist/blocks/def/accordian-block.d.ts +0 -10
- package/dist/blocks/def/accordian-block.js +0 -2
- package/dist/blocks/def/block.d.ts +0 -4
- package/dist/blocks/def/block.js +0 -1
- package/dist/blocks/def/bullet-cards-block.d.ts +0 -17
- package/dist/blocks/def/bullet-cards-block.js +0 -1
- package/dist/blocks/def/card-block.d.ts +0 -17
- package/dist/blocks/def/card-block.js +0 -2
- package/dist/blocks/def/carte-blanche-block.d.ts +0 -12
- package/dist/blocks/def/carte-blanche-block.js +0 -1
- package/dist/blocks/def/cta-block.d.ts +0 -8
- package/dist/blocks/def/cta-block.js +0 -1
- package/dist/blocks/def/element-block.d.ts +0 -7
- package/dist/blocks/def/element-block.js +0 -2
- package/dist/blocks/def/enh-heading-block.d.ts +0 -22
- package/dist/blocks/def/enh-heading-block.js +0 -1
- package/dist/blocks/def/grid-block.d.ts +0 -12
- package/dist/blocks/def/grid-block.js +0 -1
- package/dist/blocks/def/group-block.d.ts +0 -7
- package/dist/blocks/def/group-block.js +0 -1
- package/dist/blocks/def/heading-block.d.ts +0 -11
- package/dist/blocks/def/heading-block.js +0 -1
- package/dist/blocks/def/image-block.d.ts +0 -26
- package/dist/blocks/def/image-block.js +0 -1
- package/dist/blocks/def/index.d.ts +0 -17
- package/dist/blocks/def/index.js +0 -2
- package/dist/blocks/def/screenful-block.d.ts +0 -41
- package/dist/blocks/def/screenful-block.js +0 -1
- package/dist/blocks/def/space-block.d.ts +0 -47
- package/dist/blocks/def/space-block.js +0 -8
- package/dist/blocks/def/video-block.d.ts +0 -5
- package/dist/blocks/def/video-block.js +0 -1
- package/dist/blocks/index.d.ts +0 -2
- package/dist/blocks/index.js +0 -2
- package/dist/primitives/accordion.d.ts +0 -10
- package/dist/primitives/accordion.jsx +0 -21
- package/dist/primitives/action-button.d.ts +0 -9
- package/dist/primitives/action-button.jsx +0 -16
- package/dist/primitives/apply-typography.d.ts +0 -7
- package/dist/primitives/apply-typography.jsx +0 -38
- package/dist/primitives/aspect-ratio.d.ts +0 -3
- package/dist/primitives/aspect-ratio.jsx +0 -4
- package/dist/primitives/avatar.d.ts +0 -6
- package/dist/primitives/avatar.jsx +0 -11
- package/dist/primitives/badge.d.ts +0 -9
- package/dist/primitives/badge.jsx +0 -18
- package/dist/primitives/breadcrumb.d.ts +0 -19
- package/dist/primitives/breadcrumb.jsx +0 -27
- package/dist/primitives/breakpoint-indicator.d.ts +0 -3
- package/dist/primitives/breakpoint-indicator.jsx +0 -14
- package/dist/primitives/button.d.ts +0 -12
- package/dist/primitives/button.jsx +0 -55
- package/dist/primitives/calendar.d.ts +0 -8
- package/dist/primitives/calendar.jsx +0 -40
- package/dist/primitives/card.d.ts +0 -8
- package/dist/primitives/card.jsx +0 -18
- package/dist/primitives/carousel.d.ts +0 -18
- package/dist/primitives/carousel.jsx +0 -106
- package/dist/primitives/checkbox.d.ts +0 -4
- package/dist/primitives/checkbox.jsx +0 -15
- package/dist/primitives/combobox.d.ts +0 -41
- package/dist/primitives/combobox.jsx +0 -77
- package/dist/primitives/command.d.ts +0 -17
- package/dist/primitives/command.jsx +0 -38
- package/dist/primitives/context-menu.d.ts +0 -27
- package/dist/primitives/context-menu.jsx +0 -57
- package/dist/primitives/dialog-video-controller.d.ts +0 -3
- package/dist/primitives/dialog-video-controller.jsx +0 -24
- package/dist/primitives/dialog.d.ts +0 -28
- package/dist/primitives/dialog.jsx +0 -37
- package/dist/primitives/drawer.d.ts +0 -29
- package/dist/primitives/drawer.jsx +0 -34
- package/dist/primitives/form.d.ts +0 -12
- package/dist/primitives/form.jsx +0 -69
- package/dist/primitives/icons/github.d.ts +0 -4
- package/dist/primitives/icons/github.jsx +0 -6
- package/dist/primitives/icons/index.d.ts +0 -4
- package/dist/primitives/icons/index.js +0 -4
- package/dist/primitives/icons/youtube-logo.d.ts +0 -4
- package/dist/primitives/icons/youtube-logo.jsx +0 -39
- package/dist/primitives/index-common.d.ts +0 -47
- package/dist/primitives/index-common.js +0 -46
- package/dist/primitives/index-next.d.ts +0 -2
- package/dist/primitives/index-next.js +0 -2
- package/dist/primitives/input-otp.d.ts +0 -7
- package/dist/primitives/input-otp.jsx +0 -24
- package/dist/primitives/input.d.ts +0 -5
- package/dist/primitives/input.jsx +0 -11
- package/dist/primitives/label.d.ts +0 -5
- package/dist/primitives/label.jsx +0 -11
- package/dist/primitives/list-adaptor.d.ts +0 -9
- package/dist/primitives/list-adaptor.js +0 -1
- package/dist/primitives/list-box.d.ts +0 -10
- package/dist/primitives/list-box.jsx +0 -14
- package/dist/primitives/loading-spinner.d.ts +0 -5
- package/dist/primitives/loading-spinner.jsx +0 -8
- package/dist/primitives/navigation-menu.d.ts +0 -12
- package/dist/primitives/navigation-menu.jsx +0 -38
- package/dist/primitives/next/image.d.ts +0 -11
- package/dist/primitives/next/image.jsx +0 -42
- package/dist/primitives/next/index.d.ts +0 -7
- package/dist/primitives/next/index.js +0 -7
- package/dist/primitives/next/inline-icon.d.ts +0 -13
- package/dist/primitives/next/inline-icon.jsx +0 -15
- package/dist/primitives/next/link-element.d.ts +0 -23
- package/dist/primitives/next/link-element.jsx +0 -56
- package/dist/primitives/next/mdx-link.d.ts +0 -3
- package/dist/primitives/next/mdx-link.jsx +0 -12
- package/dist/primitives/next/media-stack.d.ts +0 -8
- package/dist/primitives/next/media-stack.jsx +0 -28
- package/dist/primitives/next/nav-items.d.ts +0 -10
- package/dist/primitives/next/nav-items.jsx +0 -24
- package/dist/primitives/next/youtube-embed.d.ts +0 -11
- package/dist/primitives/next/youtube-embed.jsx +0 -23
- package/dist/primitives/popover.d.ts +0 -9
- package/dist/primitives/popover.jsx +0 -18
- package/dist/primitives/progress.d.ts +0 -4
- package/dist/primitives/progress.jsx +0 -9
- package/dist/primitives/radio-group.d.ts +0 -7
- package/dist/primitives/radio-group.jsx +0 -18
- package/dist/primitives/scroll-area.d.ts +0 -5
- package/dist/primitives/scroll-area.jsx +0 -19
- package/dist/primitives/select.d.ts +0 -13
- package/dist/primitives/select.jsx +0 -62
- package/dist/primitives/separator.d.ts +0 -4
- package/dist/primitives/separator.jsx +0 -7
- package/dist/primitives/sheet.d.ts +0 -30
- package/dist/primitives/sheet.jsx +0 -56
- package/dist/primitives/skeleton.d.ts +0 -4
- package/dist/primitives/skeleton.jsx +0 -3
- package/dist/primitives/slider.d.ts +0 -9
- package/dist/primitives/slider.jsx +0 -30
- package/dist/primitives/sonner.d.ts +0 -5
- package/dist/primitives/sonner.jsx +0 -16
- package/dist/primitives/step-indicator.d.ts +0 -9
- package/dist/primitives/step-indicator.jsx +0 -23
- package/dist/primitives/switch.d.ts +0 -6
- package/dist/primitives/switch.jsx +0 -14
- package/dist/primitives/table.d.ts +0 -10
- package/dist/primitives/table.jsx +0 -21
- package/dist/primitives/tabs.d.ts +0 -7
- package/dist/primitives/tabs.jsx +0 -18
- package/dist/primitives/text-area.d.ts +0 -5
- package/dist/primitives/text-area.jsx +0 -9
- package/dist/primitives/toggle-group.d.ts +0 -14
- package/dist/primitives/toggle-group.jsx +0 -28
- package/dist/primitives/toggle.d.ts +0 -14
- package/dist/primitives/toggle.jsx +0 -52
- package/dist/primitives/tooltip.d.ts +0 -11
- package/dist/primitives/tooltip.jsx +0 -18
- package/dist/primitives/video-player.d.ts +0 -6
- package/dist/primitives/video-player.jsx +0 -8
- package/dist/style/theme-provider.d.ts +0 -4
- package/dist/style/theme-provider.jsx +0 -11
- package/dist/tailwind/fontFamily.tailwind.d.ts +0 -8
- package/dist/tailwind/fontFamily.tailwind.js +0 -7
- package/dist/tailwind/fontSize.tailwind.d.ts +0 -36
- package/dist/tailwind/fontSize.tailwind.js +0 -13
- package/dist/tailwind/index.d.ts +0 -3
- package/dist/tailwind/index.js +0 -2
- package/dist/tailwind/screens.tailwind.d.ts +0 -9
- package/dist/tailwind/screens.tailwind.js +0 -8
- package/dist/tailwind/tw-font-desc.d.ts +0 -6
- package/dist/tailwind/tw-font-desc.js +0 -6
- package/dist/types/animation-def.d.ts +0 -2
- package/dist/types/animation-def.js +0 -1
- package/dist/types/breakpoints.d.ts +0 -4
- package/dist/types/breakpoints.js +0 -4
- package/dist/types/bullet-item.d.ts +0 -6
- package/dist/types/bullet-item.js +0 -2
- package/dist/types/button-def.d.ts +0 -29
- package/dist/types/button-def.js +0 -2
- package/dist/types/dimensions.d.ts +0 -5
- package/dist/types/dimensions.js +0 -1
- package/dist/types/grid-def.d.ts +0 -36
- package/dist/types/grid-def.js +0 -33
- package/dist/types/image-def.d.ts +0 -27
- package/dist/types/image-def.js +0 -1
- package/dist/types/index.d.ts +0 -13
- package/dist/types/index.js +0 -2
- package/dist/types/link-def.d.ts +0 -44
- package/dist/types/link-def.js +0 -1
- package/dist/types/media-stack-def.d.ts +0 -25
- package/dist/types/media-stack-def.js +0 -1
- package/dist/types/t-shirt-size.d.ts +0 -2
- package/dist/types/t-shirt-size.js +0 -1
- package/dist/types/tshirt-dimensions.d.ts +0 -12
- package/dist/types/tshirt-dimensions.js +0 -1
- package/dist/types/video-def.d.ts +0 -9
- package/dist/types/video-def.js +0 -1
- package/dist/util/format-and-abbreviate-as-currency.d.ts +0 -11
- package/dist/util/format-and-abbreviate-as-currency.js +0 -91
- package/dist/util/format-to-max-char.d.ts +0 -5
- package/dist/util/format-to-max-char.js +0 -57
- package/dist/util/index-client.d.ts +0 -2
- package/dist/util/index-client.js +0 -3
- package/dist/util/index.d.ts +0 -17
- package/dist/util/index.js +0 -41
- package/dist/util/number-abbreviate.d.ts +0 -9
- package/dist/util/number-abbreviate.js +0 -30
- package/dist/util/specifier.d.ts +0 -7
- package/dist/util/specifier.js +0 -31
- package/dist/util/spread-to-transform.d.ts +0 -7
- package/dist/util/spread-to-transform.js +0 -18
- package/dist/util/step-animation.d.ts +0 -5
- package/dist/util/step-animation.js +0 -60
- package/dist/util/two-way-map.d.ts +0 -8
- package/dist/util/two-way-map.js +0 -16
- /package/{mcp → src/mcp}/index.ts +0 -0
- /package/{mcp → src/mcp}/package.json +0 -0
- /package/{registry → src/registry}/package.json +0 -0
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { DialogClose } from '@radix-ui/react-dialog';
|
|
2
|
+
import {
|
|
3
|
+
type Attachment,
|
|
4
|
+
FileTypeSupported,
|
|
5
|
+
} from '@hanzo_network/hanzo-node-state/v2/queries/getChatConversation/types';
|
|
6
|
+
import { save } from '@tauri-apps/plugin-dialog';
|
|
7
|
+
import * as fs from '@tauri-apps/plugin-fs';
|
|
8
|
+
import { BaseDirectory } from '@tauri-apps/plugin-fs';
|
|
9
|
+
import { partial } from 'filesize';
|
|
10
|
+
import { AnimatePresence, motion } from 'framer-motion';
|
|
11
|
+
import { CircleSlashIcon, XIcon } from 'lucide-react';
|
|
12
|
+
import React, { useState } from 'react';
|
|
13
|
+
import { toast } from 'sonner';
|
|
14
|
+
|
|
15
|
+
import { fileIconMap, FileTypeIcon, PaperClipIcon } from '../../assets';
|
|
16
|
+
import { getFileExt } from '../../helpers/file';
|
|
17
|
+
import { cn } from '../../src/utils';
|
|
18
|
+
import { Avatar, AvatarFallback, AvatarImage } from '../avatar';
|
|
19
|
+
import { Button } from '../button';
|
|
20
|
+
import { Dialog, DialogContent } from '../dialog';
|
|
21
|
+
import {
|
|
22
|
+
Tooltip,
|
|
23
|
+
TooltipContent,
|
|
24
|
+
TooltipPortal,
|
|
25
|
+
TooltipTrigger,
|
|
26
|
+
} from '../tooltip';
|
|
27
|
+
import { SqlitePreview } from './sqlite-preview';
|
|
28
|
+
|
|
29
|
+
export type FileListProps = {
|
|
30
|
+
files: Attachment[];
|
|
31
|
+
className?: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const isImageFile = (file: string) => {
|
|
35
|
+
return file.match(/\.(jpg|jpeg|png|gif)$/i);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const size = partial({ standard: 'jedec' });
|
|
39
|
+
|
|
40
|
+
const ImagePreview = ({
|
|
41
|
+
name,
|
|
42
|
+
size,
|
|
43
|
+
url,
|
|
44
|
+
onFullscreen,
|
|
45
|
+
}: Pick<Attachment, 'name' | 'size' | 'url'> & {
|
|
46
|
+
onFullscreen: (open: boolean) => void;
|
|
47
|
+
}) => (
|
|
48
|
+
<button
|
|
49
|
+
className="border-divider hover:bg-bg-secondary flex h-14 w-full max-w-[210px] min-w-[210px] shrink-0 cursor-pointer items-center gap-2 rounded-md border py-1.5 pr-1.5 pl-2 text-left"
|
|
50
|
+
onClick={() => onFullscreen(true)}
|
|
51
|
+
>
|
|
52
|
+
<Avatar className="bg-bg-quaternary text-text-default flex size-10 shrink-0 items-center justify-center overflow-hidden rounded-xs transition-colors">
|
|
53
|
+
<AvatarImage
|
|
54
|
+
alt={name}
|
|
55
|
+
className="border-divider aspect-square h-full w-full rounded-xs border object-cover"
|
|
56
|
+
src={url}
|
|
57
|
+
/>
|
|
58
|
+
<AvatarFallback>
|
|
59
|
+
<CircleSlashIcon className="text-text-secondary h-4 w-4" />
|
|
60
|
+
</AvatarFallback>
|
|
61
|
+
</Avatar>
|
|
62
|
+
<FileInfo fileName={name} fileSize={size} />
|
|
63
|
+
</button>
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const FileInfo = ({
|
|
67
|
+
fileSize,
|
|
68
|
+
fileName,
|
|
69
|
+
}: {
|
|
70
|
+
fileSize?: number;
|
|
71
|
+
fileName: string;
|
|
72
|
+
}) => (
|
|
73
|
+
<div className="text-text-secondary text-em-sm grid flex-1 -translate-x-px gap-1 py-0.5 leading-none">
|
|
74
|
+
<div className="text-text-default truncate overflow-hidden font-medium">
|
|
75
|
+
{decodeURIComponent(fileName.split('/').at(-1) ?? '')}
|
|
76
|
+
</div>
|
|
77
|
+
{fileSize && (
|
|
78
|
+
<div className="text-text-secondary line-clamp-1 aspect-auto font-normal">
|
|
79
|
+
{size(fileSize)}
|
|
80
|
+
</div>
|
|
81
|
+
)}
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
type FileContentViewerProps = Pick<
|
|
86
|
+
Attachment,
|
|
87
|
+
'name' | 'url' | 'content' | 'type'
|
|
88
|
+
>;
|
|
89
|
+
|
|
90
|
+
export const FileContentViewer: React.FC<FileContentViewerProps> = ({
|
|
91
|
+
name,
|
|
92
|
+
content,
|
|
93
|
+
url,
|
|
94
|
+
type,
|
|
95
|
+
}) => {
|
|
96
|
+
switch (type) {
|
|
97
|
+
case FileTypeSupported.Text: {
|
|
98
|
+
return (
|
|
99
|
+
<pre className="bg-bg-dark h-full overflow-auto p-4 pt-10 font-mono text-xs break-words whitespace-pre-wrap">
|
|
100
|
+
{content}
|
|
101
|
+
</pre>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
case FileTypeSupported.Image: {
|
|
105
|
+
return (
|
|
106
|
+
<div className="flex h-full w-full items-center justify-center">
|
|
107
|
+
<img
|
|
108
|
+
alt={name}
|
|
109
|
+
className="max-h-full max-w-full object-contain"
|
|
110
|
+
src={url}
|
|
111
|
+
/>
|
|
112
|
+
</div>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
case FileTypeSupported.Video: {
|
|
116
|
+
return (
|
|
117
|
+
<div className="flex h-full w-full items-center justify-center">
|
|
118
|
+
<video className="max-h-full max-w-full" controls src={url}>
|
|
119
|
+
Your browser does not support the video tag.
|
|
120
|
+
</video>
|
|
121
|
+
</div>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
case FileTypeSupported.Audio: {
|
|
125
|
+
return (
|
|
126
|
+
<div className="flex h-full w-full items-center justify-center">
|
|
127
|
+
<audio className="w-full" controls src={url}>
|
|
128
|
+
Your browser does not support the audio tag.
|
|
129
|
+
</audio>
|
|
130
|
+
</div>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
case FileTypeSupported.Html: {
|
|
134
|
+
return (
|
|
135
|
+
<div className="flex h-full w-full items-center justify-center">
|
|
136
|
+
<iframe
|
|
137
|
+
className="h-full w-full bg-gray-100"
|
|
138
|
+
sandbox="allow-same-origin"
|
|
139
|
+
src={url}
|
|
140
|
+
title={name}
|
|
141
|
+
/>
|
|
142
|
+
</div>
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
case FileTypeSupported.SqliteDatabase: {
|
|
146
|
+
return <SqlitePreview url={url || ''} />;
|
|
147
|
+
}
|
|
148
|
+
default:
|
|
149
|
+
return (
|
|
150
|
+
<div className="text-text-secondary flex h-full flex-col items-center justify-center gap-6">
|
|
151
|
+
<span>Preview not available for this file type</span>
|
|
152
|
+
</div>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const FullscreenDialog = ({
|
|
158
|
+
open,
|
|
159
|
+
name,
|
|
160
|
+
type,
|
|
161
|
+
url,
|
|
162
|
+
content,
|
|
163
|
+
setOpen,
|
|
164
|
+
onDownload,
|
|
165
|
+
}: Pick<Attachment, 'name' | 'url' | 'content' | 'type'> & {
|
|
166
|
+
open: boolean;
|
|
167
|
+
setOpen: (open: boolean) => void;
|
|
168
|
+
onDownload?: () => void;
|
|
169
|
+
}) => (
|
|
170
|
+
<Dialog onOpenChange={setOpen} open={open}>
|
|
171
|
+
<DialogContent className="flex size-full max-h-[99vh] max-w-[99vw] flex-col gap-2 bg-transparent p-1 py-8">
|
|
172
|
+
<div className="flex w-full items-center justify-between gap-16 px-10">
|
|
173
|
+
<div className="text-text-default max-w-3xl truncate text-left text-sm">
|
|
174
|
+
{name}
|
|
175
|
+
</div>
|
|
176
|
+
<div className="flex items-center gap-4">
|
|
177
|
+
<Button onClick={onDownload} size="xs" variant="outline">
|
|
178
|
+
Download
|
|
179
|
+
</Button>
|
|
180
|
+
<DialogClose>
|
|
181
|
+
<XIcon className="text-text-secondary h-6 w-6" />
|
|
182
|
+
<span className="sr-only">Close</span>
|
|
183
|
+
</DialogClose>
|
|
184
|
+
</div>
|
|
185
|
+
</div>
|
|
186
|
+
<div className="text-text-default flex size-full flex-col overflow-hidden rounded-l-xl p-10">
|
|
187
|
+
<FileContentViewer
|
|
188
|
+
content={content}
|
|
189
|
+
name={name}
|
|
190
|
+
type={type}
|
|
191
|
+
url={url}
|
|
192
|
+
/>
|
|
193
|
+
</div>
|
|
194
|
+
</DialogContent>
|
|
195
|
+
</Dialog>
|
|
196
|
+
);
|
|
197
|
+
const FileButton = ({
|
|
198
|
+
name,
|
|
199
|
+
size,
|
|
200
|
+
onFullscreen,
|
|
201
|
+
}: Pick<Attachment, 'name' | 'size'> & {
|
|
202
|
+
onFullscreen: (open: boolean) => void;
|
|
203
|
+
}) => (
|
|
204
|
+
<button
|
|
205
|
+
className="border-divider hover:bg-bg-secondary flex h-14 w-full max-w-[210px] min-w-[210px] shrink-0 cursor-pointer items-center gap-2 rounded-md border py-1.5 pr-1.5 pl-2 text-left"
|
|
206
|
+
onClick={() => onFullscreen(true)}
|
|
207
|
+
>
|
|
208
|
+
<span className="bg-bg-quaternary text-text-default flex size-10 shrink-0 items-center justify-center overflow-hidden rounded-xs transition-colors">
|
|
209
|
+
{fileIconMap[getFileExt(name)] ? (
|
|
210
|
+
<FileTypeIcon
|
|
211
|
+
className="text-text-secondary h-5 w-5"
|
|
212
|
+
type={getFileExt(name)}
|
|
213
|
+
/>
|
|
214
|
+
) : (
|
|
215
|
+
<PaperClipIcon className="text-text-secondary h-4 w-4" />
|
|
216
|
+
)}
|
|
217
|
+
</span>
|
|
218
|
+
<FileInfo fileName={name} fileSize={size} />
|
|
219
|
+
</button>
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
export const FilePreview = ({
|
|
223
|
+
name,
|
|
224
|
+
url,
|
|
225
|
+
size,
|
|
226
|
+
content,
|
|
227
|
+
blob,
|
|
228
|
+
type,
|
|
229
|
+
}: Attachment) => {
|
|
230
|
+
const [open, setOpen] = useState(false);
|
|
231
|
+
|
|
232
|
+
const fileName = decodeURIComponent(name).split('/').at(-1) ?? '';
|
|
233
|
+
|
|
234
|
+
const children = isImageFile(name) ? (
|
|
235
|
+
<ImagePreview name={name} onFullscreen={setOpen} size={size} url={url} />
|
|
236
|
+
) : (
|
|
237
|
+
<FileButton name={name} onFullscreen={setOpen} size={size} />
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
return (
|
|
241
|
+
<Tooltip>
|
|
242
|
+
<TooltipTrigger asChild>
|
|
243
|
+
<div>{children}</div>
|
|
244
|
+
</TooltipTrigger>
|
|
245
|
+
<TooltipPortal>
|
|
246
|
+
<TooltipContent className="container break-words" side="top">
|
|
247
|
+
<p>{fileName}</p>
|
|
248
|
+
</TooltipContent>
|
|
249
|
+
</TooltipPortal>
|
|
250
|
+
<FullscreenDialog
|
|
251
|
+
content={content}
|
|
252
|
+
name={fileName}
|
|
253
|
+
onDownload={async () => {
|
|
254
|
+
const currentFile =
|
|
255
|
+
blob ??
|
|
256
|
+
new Blob([content || url || ''], {
|
|
257
|
+
type: 'application/octet-stream',
|
|
258
|
+
});
|
|
259
|
+
const arrayBuffer = await currentFile.arrayBuffer();
|
|
260
|
+
const currentContent = new Uint8Array(arrayBuffer);
|
|
261
|
+
const savePath = await save({
|
|
262
|
+
defaultPath: fileName,
|
|
263
|
+
filters: [
|
|
264
|
+
{
|
|
265
|
+
name: 'File',
|
|
266
|
+
extensions: [getFileExt(name)],
|
|
267
|
+
},
|
|
268
|
+
],
|
|
269
|
+
});
|
|
270
|
+
if (!savePath) {
|
|
271
|
+
toast.info('File saving cancelled');
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
await fs.writeFile(savePath, currentContent, {
|
|
276
|
+
baseDir: BaseDirectory.Download,
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
toast.success(`${fileName} downloaded successfully`);
|
|
280
|
+
}}
|
|
281
|
+
open={open}
|
|
282
|
+
setOpen={setOpen}
|
|
283
|
+
type={type}
|
|
284
|
+
url={url}
|
|
285
|
+
/>
|
|
286
|
+
</Tooltip>
|
|
287
|
+
);
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
const animations = {
|
|
291
|
+
initial: { scale: 0.97, opacity: 0, y: 10 },
|
|
292
|
+
animate: {
|
|
293
|
+
scale: 1,
|
|
294
|
+
opacity: 1,
|
|
295
|
+
y: 0,
|
|
296
|
+
transition: {
|
|
297
|
+
type: 'spring',
|
|
298
|
+
stiffness: 200,
|
|
299
|
+
damping: 20,
|
|
300
|
+
mass: 0.8,
|
|
301
|
+
velocity: 1,
|
|
302
|
+
duration: 0.6,
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
exit: {
|
|
306
|
+
scale: 0.97,
|
|
307
|
+
opacity: 0,
|
|
308
|
+
y: -10,
|
|
309
|
+
transition: {
|
|
310
|
+
type: 'spring',
|
|
311
|
+
stiffness: 150,
|
|
312
|
+
damping: 15,
|
|
313
|
+
duration: 0.4,
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
export const FileList = ({ files, className }: FileListProps) => {
|
|
319
|
+
return (
|
|
320
|
+
<ul className={cn('flex flex-wrap gap-3', className)}>
|
|
321
|
+
<AnimatePresence>
|
|
322
|
+
{files?.map((file, index) => (
|
|
323
|
+
<motion.li {...animations} key={index}>
|
|
324
|
+
<FilePreview {...file} />
|
|
325
|
+
</motion.li>
|
|
326
|
+
))}
|
|
327
|
+
</AnimatePresence>
|
|
328
|
+
</ul>
|
|
329
|
+
);
|
|
330
|
+
};
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { ChatConversationInfiniteData } from '@hanzo_network/hanzo-node-state/v2/queries/getChatConversation/types';
|
|
2
|
+
import {
|
|
3
|
+
type FetchPreviousPageOptions,
|
|
4
|
+
type InfiniteQueryObserverResult,
|
|
5
|
+
} from '@tanstack/react-query';
|
|
6
|
+
import React, {
|
|
7
|
+
Fragment,
|
|
8
|
+
memo,
|
|
9
|
+
type RefObject,
|
|
10
|
+
useCallback,
|
|
11
|
+
useEffect,
|
|
12
|
+
useLayoutEffect,
|
|
13
|
+
useRef,
|
|
14
|
+
useState,
|
|
15
|
+
} from 'react';
|
|
16
|
+
import { useInView } from 'react-intersection-observer';
|
|
17
|
+
|
|
18
|
+
import { getRelativeDateLabel, groupMessagesByDate } from '../../helpers';
|
|
19
|
+
import { cn } from '../src/utils';
|
|
20
|
+
import { Skeleton } from '../skeleton';
|
|
21
|
+
import { Message } from './message';
|
|
22
|
+
|
|
23
|
+
function useScrollToBottom(
|
|
24
|
+
scrollRef: RefObject<HTMLDivElement | null>,
|
|
25
|
+
detach = false,
|
|
26
|
+
) {
|
|
27
|
+
const [autoScroll, setAutoScroll] = useState(true);
|
|
28
|
+
function scrollDomToBottom() {
|
|
29
|
+
const scrollContainer = scrollRef.current;
|
|
30
|
+
if (scrollContainer) {
|
|
31
|
+
requestAnimationFrame(() => {
|
|
32
|
+
setAutoScroll(true);
|
|
33
|
+
scrollContainer.scrollTo(0, scrollContainer.scrollHeight);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (autoScroll && !detach) {
|
|
40
|
+
scrollDomToBottom();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
scrollRef,
|
|
46
|
+
autoScroll,
|
|
47
|
+
setAutoScroll,
|
|
48
|
+
scrollDomToBottom,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const MessageList = ({
|
|
53
|
+
noMoreMessageLabel,
|
|
54
|
+
paginatedMessages,
|
|
55
|
+
isSuccess,
|
|
56
|
+
isLoading,
|
|
57
|
+
isFetchingPreviousPage,
|
|
58
|
+
hasPreviousPage,
|
|
59
|
+
fetchPreviousPage,
|
|
60
|
+
containerClassName,
|
|
61
|
+
lastMessageContent,
|
|
62
|
+
editAndRegenerateMessage,
|
|
63
|
+
regenerateMessage,
|
|
64
|
+
disabledRetryAndEdit,
|
|
65
|
+
messageExtra,
|
|
66
|
+
hidePythonExecution,
|
|
67
|
+
}: {
|
|
68
|
+
noMoreMessageLabel: string;
|
|
69
|
+
isSuccess: boolean;
|
|
70
|
+
isLoading: boolean;
|
|
71
|
+
isFetchingPreviousPage: boolean;
|
|
72
|
+
hasPreviousPage: boolean;
|
|
73
|
+
paginatedMessages: ChatConversationInfiniteData | undefined;
|
|
74
|
+
fetchPreviousPage: (
|
|
75
|
+
options?: FetchPreviousPageOptions | undefined,
|
|
76
|
+
) => Promise<
|
|
77
|
+
InfiniteQueryObserverResult<ChatConversationInfiniteData, Error>
|
|
78
|
+
>;
|
|
79
|
+
regenerateMessage?: (messageId: string) => void;
|
|
80
|
+
editAndRegenerateMessage?: (content: string, messageHash: string) => void;
|
|
81
|
+
containerClassName?: string;
|
|
82
|
+
lastMessageContent?: React.ReactNode;
|
|
83
|
+
disabledRetryAndEdit?: boolean;
|
|
84
|
+
messageExtra?: React.ReactNode;
|
|
85
|
+
hidePythonExecution?: boolean;
|
|
86
|
+
}) => {
|
|
87
|
+
const chatContainerRef = useRef<HTMLDivElement>(null);
|
|
88
|
+
const previousChatHeightRef = useRef<number>(0);
|
|
89
|
+
const { ref, inView } = useInView();
|
|
90
|
+
const messageList = paginatedMessages?.pages.flat() ?? [];
|
|
91
|
+
|
|
92
|
+
const { autoScroll, setAutoScroll, scrollDomToBottom } =
|
|
93
|
+
useScrollToBottom(chatContainerRef);
|
|
94
|
+
|
|
95
|
+
const fetchPreviousMessages = useCallback(async () => {
|
|
96
|
+
setAutoScroll(false);
|
|
97
|
+
await fetchPreviousPage();
|
|
98
|
+
}, [fetchPreviousPage]);
|
|
99
|
+
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
if (hasPreviousPage && inView) {
|
|
102
|
+
void fetchPreviousMessages();
|
|
103
|
+
}
|
|
104
|
+
}, [hasPreviousPage, inView]);
|
|
105
|
+
|
|
106
|
+
// adjust the scroll position of a chat container after new messages are fetched
|
|
107
|
+
useLayoutEffect(() => {
|
|
108
|
+
if (!isFetchingPreviousPage && inView) {
|
|
109
|
+
const chatContainerElement = chatContainerRef.current;
|
|
110
|
+
if (!chatContainerElement) return;
|
|
111
|
+
const currentHeight = chatContainerElement.scrollHeight;
|
|
112
|
+
const previousHeight = previousChatHeightRef.current;
|
|
113
|
+
|
|
114
|
+
if (!autoScroll) {
|
|
115
|
+
chatContainerElement.scrollTop =
|
|
116
|
+
currentHeight - previousHeight + chatContainerElement.scrollTop;
|
|
117
|
+
} else {
|
|
118
|
+
scrollDomToBottom();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
chatContainerElement.scrollTop = currentHeight - previousHeight;
|
|
122
|
+
}
|
|
123
|
+
}, [paginatedMessages, isFetchingPreviousPage, inView]);
|
|
124
|
+
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
const chatContainerElement = chatContainerRef.current;
|
|
127
|
+
if (!chatContainerElement) return;
|
|
128
|
+
const handleScroll = async () => {
|
|
129
|
+
const currentHeight = chatContainerElement.scrollHeight;
|
|
130
|
+
const currentScrollTop = chatContainerElement.scrollTop;
|
|
131
|
+
previousChatHeightRef.current = currentHeight;
|
|
132
|
+
const scrollThreshold = 100;
|
|
133
|
+
const isNearBottom =
|
|
134
|
+
currentScrollTop + chatContainerElement.clientHeight >=
|
|
135
|
+
currentHeight - scrollThreshold;
|
|
136
|
+
|
|
137
|
+
setAutoScroll(isNearBottom);
|
|
138
|
+
|
|
139
|
+
if (inView && hasPreviousPage && !isFetchingPreviousPage) {
|
|
140
|
+
previousChatHeightRef.current = currentHeight - currentScrollTop;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
chatContainerElement.addEventListener('scroll', handleScroll, {
|
|
145
|
+
passive: true,
|
|
146
|
+
});
|
|
147
|
+
return () => {
|
|
148
|
+
chatContainerElement.removeEventListener('scroll', handleScroll);
|
|
149
|
+
};
|
|
150
|
+
}, [
|
|
151
|
+
fetchPreviousMessages,
|
|
152
|
+
hasPreviousPage,
|
|
153
|
+
inView,
|
|
154
|
+
isFetchingPreviousPage,
|
|
155
|
+
paginatedMessages?.pages?.length,
|
|
156
|
+
]);
|
|
157
|
+
|
|
158
|
+
useEffect(() => {
|
|
159
|
+
if (messageList?.length % 2 === 1) {
|
|
160
|
+
scrollDomToBottom();
|
|
161
|
+
}
|
|
162
|
+
}, [messageList?.length]);
|
|
163
|
+
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
if (isSuccess) {
|
|
166
|
+
scrollDomToBottom();
|
|
167
|
+
}
|
|
168
|
+
}, [isSuccess]);
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<div
|
|
172
|
+
className={cn(
|
|
173
|
+
'scroll flex-1 overflow-y-auto overscroll-none will-change-scroll',
|
|
174
|
+
'flex-1 overflow-y-auto',
|
|
175
|
+
containerClassName,
|
|
176
|
+
)}
|
|
177
|
+
id="chat-container-scroll"
|
|
178
|
+
ref={chatContainerRef}
|
|
179
|
+
>
|
|
180
|
+
{isSuccess &&
|
|
181
|
+
!isFetchingPreviousPage &&
|
|
182
|
+
!hasPreviousPage &&
|
|
183
|
+
(paginatedMessages?.pages ?? [])?.length > 1 && (
|
|
184
|
+
<div className="text-text-secondary py-2 text-center text-xs">
|
|
185
|
+
{noMoreMessageLabel}
|
|
186
|
+
</div>
|
|
187
|
+
)}
|
|
188
|
+
<div className="">
|
|
189
|
+
{isLoading && (
|
|
190
|
+
<div className="flex flex-col space-y-8">
|
|
191
|
+
{[...Array(10).keys()].map((index) => (
|
|
192
|
+
<div
|
|
193
|
+
className={cn(
|
|
194
|
+
'flex w-[85%] gap-2',
|
|
195
|
+
index % 2 === 0
|
|
196
|
+
? 'mr-auto ml-0 flex-row items-end'
|
|
197
|
+
: 'mr-0 ml-auto flex-row-reverse items-start',
|
|
198
|
+
)}
|
|
199
|
+
key={`${index}`}
|
|
200
|
+
>
|
|
201
|
+
<Skeleton
|
|
202
|
+
className="h-8 w-8 shrink-0 rounded-full bg-gray-300"
|
|
203
|
+
key={index}
|
|
204
|
+
/>
|
|
205
|
+
<Skeleton
|
|
206
|
+
className={cn(
|
|
207
|
+
'w-full rounded-lg px-2.5 py-3',
|
|
208
|
+
index % 2 === 0
|
|
209
|
+
? 'h-24 rounded-bl-none bg-gray-300'
|
|
210
|
+
: 'h-16 rounded-tr-none bg-gray-200',
|
|
211
|
+
index % 3 === 0 && 'h-32',
|
|
212
|
+
)}
|
|
213
|
+
/>
|
|
214
|
+
</div>
|
|
215
|
+
))}
|
|
216
|
+
</div>
|
|
217
|
+
)}
|
|
218
|
+
{(hasPreviousPage || isFetchingPreviousPage) && (
|
|
219
|
+
<div className="flex flex-col space-y-3" ref={ref}>
|
|
220
|
+
{[...Array(4).keys()].map((index) => (
|
|
221
|
+
<div
|
|
222
|
+
className={cn(
|
|
223
|
+
'flex w-[85%] gap-2',
|
|
224
|
+
index % 2 === 0
|
|
225
|
+
? 'mr-auto ml-0 flex-row items-end'
|
|
226
|
+
: 'mr-0 ml-auto flex-row-reverse items-start',
|
|
227
|
+
)}
|
|
228
|
+
key={`${index}`}
|
|
229
|
+
>
|
|
230
|
+
<Skeleton
|
|
231
|
+
className="h-8 w-8 shrink-0 rounded-full bg-gray-300"
|
|
232
|
+
key={index}
|
|
233
|
+
/>
|
|
234
|
+
<Skeleton
|
|
235
|
+
className={cn(
|
|
236
|
+
'w-full rounded-lg px-2.5 py-3',
|
|
237
|
+
index % 2 === 0
|
|
238
|
+
? 'h-24 rounded-bl-none bg-gray-300'
|
|
239
|
+
: 'h-16 rounded-tr-none bg-gray-200',
|
|
240
|
+
index % 3 === 0 && 'h-32',
|
|
241
|
+
)}
|
|
242
|
+
/>
|
|
243
|
+
</div>
|
|
244
|
+
))}
|
|
245
|
+
</div>
|
|
246
|
+
)}
|
|
247
|
+
{isSuccess && messageList?.length > 0 && (
|
|
248
|
+
<Fragment>
|
|
249
|
+
{Object.entries(groupMessagesByDate(messageList)).map(
|
|
250
|
+
([date, messages]) => {
|
|
251
|
+
return (
|
|
252
|
+
<div key={date}>
|
|
253
|
+
<div
|
|
254
|
+
className={cn(
|
|
255
|
+
'relative z-10 m-auto my-2 flex h-[26px] w-fit min-w-[100px] items-center justify-center rounded-xl bg-gray-400 px-2.5 capitalize',
|
|
256
|
+
'sticky top-5',
|
|
257
|
+
)}
|
|
258
|
+
>
|
|
259
|
+
<span className="text-text-secondary text-xs font-medium">
|
|
260
|
+
{getRelativeDateLabel(
|
|
261
|
+
new Date(messages[0].createdAt || ''),
|
|
262
|
+
)}
|
|
263
|
+
</span>
|
|
264
|
+
</div>
|
|
265
|
+
<div className="flex flex-col">
|
|
266
|
+
{messages.map((message, messageIndex) => {
|
|
267
|
+
const previousMessage = messages[messageIndex - 1];
|
|
268
|
+
|
|
269
|
+
const disabledRetryAndEditValue =
|
|
270
|
+
disabledRetryAndEdit ?? messageIndex === 0;
|
|
271
|
+
|
|
272
|
+
const handleRetryMessage = () => {
|
|
273
|
+
regenerateMessage?.(message?.messageId ?? '');
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
const handleEditMessage = (message: string) => {
|
|
277
|
+
editAndRegenerateMessage?.(
|
|
278
|
+
message,
|
|
279
|
+
previousMessage?.messageId ?? '',
|
|
280
|
+
);
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
return (
|
|
284
|
+
<Message
|
|
285
|
+
disabledEdit={disabledRetryAndEditValue}
|
|
286
|
+
handleEditMessage={handleEditMessage}
|
|
287
|
+
handleRetryMessage={handleRetryMessage}
|
|
288
|
+
hidePythonExecution={hidePythonExecution}
|
|
289
|
+
key={`${message.messageId}::${messageIndex}`}
|
|
290
|
+
message={message}
|
|
291
|
+
messageId={message.messageId}
|
|
292
|
+
/>
|
|
293
|
+
);
|
|
294
|
+
})}
|
|
295
|
+
</div>
|
|
296
|
+
</div>
|
|
297
|
+
);
|
|
298
|
+
},
|
|
299
|
+
)}
|
|
300
|
+
{messageExtra}
|
|
301
|
+
{lastMessageContent}
|
|
302
|
+
</Fragment>
|
|
303
|
+
)}
|
|
304
|
+
</div>
|
|
305
|
+
</div>
|
|
306
|
+
);
|
|
307
|
+
};
|