xertica-ui 2.3.0 → 2.4.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/CHANGELOG.md +564 -552
- package/README.md +417 -406
- package/assets/xertica-logo.svg +37 -37
- package/assets/xertica-x-logo.svg +20 -20
- package/bin/cli.ts +1244 -1155
- package/bin/language-config.ts +358 -361
- package/components/assistant/code-block/CodeBlock.tsx +268 -268
- package/components/assistant/formatted-document/FormattedDocument.tsx +147 -147
- package/components/assistant/modern-chat-input/ModernChatInput.tsx +564 -554
- package/components/assistant/xertica-assistant/parts/AssistantCollapsedView.tsx +99 -99
- package/components/assistant/xertica-assistant/parts/AssistantConversationList.tsx +104 -106
- package/components/assistant/xertica-assistant/parts/AssistantDocumentEditor.tsx +81 -81
- package/components/assistant/xertica-assistant/parts/AssistantFeedbackDialog.tsx +88 -78
- package/components/assistant/xertica-assistant/parts/AssistantHeader.tsx +75 -75
- package/components/assistant/xertica-assistant/parts/AssistantMessageBubble.tsx +564 -560
- package/components/assistant/xertica-assistant/parts/AssistantTabBar.tsx +67 -67
- package/components/assistant/xertica-assistant/parts/AssistantWelcomeScreen.tsx +103 -103
- package/components/assistant/xertica-assistant/use-assistant.ts +615 -615
- package/components/assistant/xertica-assistant/xertica-assistant.tsx +611 -613
- package/components/blocks/card-patterns/ActivityCard.tsx +100 -100
- package/components/blocks/card-patterns/ActivityCardSkeleton.tsx +56 -56
- package/components/blocks/card-patterns/FeatureCardSkeleton.tsx +58 -63
- package/components/blocks/card-patterns/NotificationCard.tsx +140 -140
- package/components/blocks/card-patterns/NotificationCardSkeleton.tsx +81 -81
- package/components/blocks/card-patterns/ProfileCard.tsx +112 -114
- package/components/blocks/card-patterns/ProfileCardSkeleton.tsx +69 -69
- package/components/blocks/card-patterns/ProjectCard.tsx +123 -123
- package/components/blocks/card-patterns/ProjectCardSkeleton.tsx +67 -72
- package/components/blocks/card-patterns/QuickActionCardSkeleton.tsx +44 -44
- package/components/blocks/card-patterns/card-patterns.stories.tsx +594 -594
- package/components/blocks/card-patterns/index.ts +29 -29
- package/components/brand/language-selector/LanguageSelector.tsx +102 -102
- package/components/brand/language-selector/language-selector.stories.tsx +111 -114
- package/components/brand/language-selector/language-selector.test.tsx +101 -101
- package/components/brand/theme-toggle/ThemeToggle.tsx +74 -70
- package/components/brand/xertica-provider/XerticaProvider.tsx +109 -112
- package/components/brand/xertica-provider/xertica-provider.mdx +61 -61
- package/components/index.ts +86 -90
- package/components/layout/sidebar/sidebar.mdx +1 -1
- package/components/layout/sidebar/sidebar.tsx +1079 -1073
- package/components/media/FloatingMediaWrapper.tsx +371 -371
- package/components/media/audio-player/AudioPlayer.tsx +768 -766
- package/components/media/video-player/VideoPlayer.tsx +310 -310
- package/components/pages/forgot-password-page/ForgotPasswordPage.tsx +1 -1
- package/components/pages/home-content/HomeContent.tsx +120 -120
- package/components/pages/home-content/home-content.mdx +62 -62
- package/components/pages/home-page/HomePage.tsx +78 -74
- package/components/pages/home-page/home-page.mdx +53 -53
- package/components/pages/login-page/LoginPage.tsx +218 -216
- package/components/pages/reset-password-page/ResetPasswordPage.tsx +243 -239
- package/components/pages/template-content/TemplateContent.tsx +1354 -1235
- package/components/pages/template-content/template-content.mdx +61 -61
- package/components/pages/template-page/template-page.mdx +53 -53
- package/components/pages/verify-email-page/VerifyEmailPage.tsx +206 -206
- package/components/shared/error-boundary.stories.tsx +4 -22
- package/components/shared/error-boundary.tsx +1 -5
- package/components/shared/error-fallbacks.tsx +4 -8
- package/components/ui/accordion/accordion.mdx +8 -8
- package/components/ui/alert/alert.mdx +8 -8
- package/components/ui/alert-dialog/alert-dialog.mdx +8 -8
- package/components/ui/aspect-ratio/aspect-ratio.mdx +8 -8
- package/components/ui/assistant-chart/assistant-chart.mdx +8 -8
- package/components/ui/avatar/avatar.mdx +8 -8
- package/components/ui/badge/badge.mdx +8 -8
- package/components/ui/breadcrumb/breadcrumb.mdx +8 -8
- package/components/ui/button/button.mdx +8 -8
- package/components/ui/calendar/calendar.mdx +8 -8
- package/components/ui/card/card.mdx +8 -8
- package/components/ui/carousel/carousel.mdx +8 -8
- package/components/ui/chart/chart.mdx +8 -8
- package/components/ui/checkbox/checkbox.mdx +8 -8
- package/components/ui/collapsible/collapsible.mdx +8 -8
- package/components/ui/command/command.mdx +8 -8
- package/components/ui/context-menu/context-menu.mdx +8 -8
- package/components/ui/dialog/dialog.mdx +8 -8
- package/components/ui/drawer/drawer.mdx +8 -8
- package/components/ui/dropdown-menu/dropdown-menu.mdx +8 -8
- package/components/ui/empty/empty.mdx +8 -8
- package/components/ui/file-upload/file-upload.mdx +8 -8
- package/components/ui/hover-card/hover-card.mdx +8 -8
- package/components/ui/input/input.mdx +8 -8
- package/components/ui/input-otp/input-otp.mdx +8 -8
- package/components/ui/label/label.mdx +8 -8
- package/components/ui/map/map.mdx +8 -8
- package/components/ui/menubar/menubar.mdx +8 -8
- package/components/ui/navigation-menu/navigation-menu.mdx +8 -8
- package/components/ui/notification-badge/notification-badge.mdx +8 -8
- package/components/ui/pagination/pagination.mdx +8 -8
- package/components/ui/popover/popover.mdx +8 -8
- package/components/ui/progress/progress.mdx +8 -8
- package/components/ui/radio-group/radio-group.mdx +8 -8
- package/components/ui/rating/rating.mdx +8 -8
- package/components/ui/resizable/resizable.mdx +8 -8
- package/components/ui/route-map/route-map.mdx +8 -8
- package/components/ui/scroll-area/scroll-area.mdx +8 -8
- package/components/ui/search/search.mdx +8 -8
- package/components/ui/select/select.mdx +8 -8
- package/components/ui/separator/separator.mdx +8 -8
- package/components/ui/sheet/sheet.mdx +8 -8
- package/components/ui/simple-map/simple-map.mdx +8 -8
- package/components/ui/skeleton/skeleton.mdx +8 -8
- package/components/ui/slider/slider.mdx +8 -8
- package/components/ui/sonner/sonner.mdx +8 -8
- package/components/ui/stats-card/index.ts +2 -2
- package/components/ui/stats-card/stats-card-skeleton.tsx +60 -62
- package/components/ui/stats-card/stats-card.mdx +8 -8
- package/components/ui/stats-card/stats-card.stories.tsx +99 -99
- package/components/ui/stepper/stepper.mdx +8 -8
- package/components/ui/switch/switch.mdx +8 -8
- package/components/ui/table/table.mdx +8 -8
- package/components/ui/tabs/tabs.mdx +8 -8
- package/components/ui/textarea/textarea.mdx +8 -8
- package/components/ui/timeline/timeline.mdx +8 -8
- package/components/ui/toggle/toggle.mdx +8 -8
- package/components/ui/toggle-group/toggle-group.mdx +8 -8
- package/components/ui/tooltip/tooltip.mdx +8 -8
- package/components/ui/tree-view/tree-view.mdx +8 -8
- package/components.json +892 -892
- package/contexts/AuthContext.tsx +11 -8
- package/contexts/LanguageContext.test.tsx +121 -121
- package/contexts/LanguageContext.tsx +250 -251
- package/dist/{AssistantChart-DoZCyS5r.cjs → AssistantChart-9w31gdAb.cjs} +4 -4
- package/dist/{AssistantChart-CldVCVDe.cjs → AssistantChart-BAudAfne.cjs} +5 -5
- package/dist/{AssistantChart-Bdd44uBn.cjs → AssistantChart-BAx9VQvb.cjs} +127 -388
- package/dist/{AssistantChart-Cu3m7RBo.js → AssistantChart-BP8upjMk.js} +5 -5
- package/dist/{AssistantChart-CFhDdGyU.js → AssistantChart-CVko2A1W.js} +130 -391
- package/dist/{AssistantChart-C_hwFRRr.js → AssistantChart-CVzmmhx4.js} +4 -4
- package/dist/{AudioPlayer-IAU5q5T1.cjs → AudioPlayer-1ypwE2Wh.cjs} +1 -1
- package/dist/{AudioPlayer-CGRUtUdN.js → AudioPlayer-DuKXrCfy.js} +1 -1
- package/dist/{LanguageContext-CS14yCpi.js → LanguageContext-BwhwC3G2.js} +2 -2
- package/dist/{LanguageContext-B_KFTCzT.cjs → LanguageContext-DvUt5jBg.cjs} +2 -2
- package/dist/{ThemeContext-C2EwAPDt.js → ThemeContext-BbBNoFTG.js} +2 -2
- package/dist/{ThemeContext-Bmod0Cg2.cjs → ThemeContext-BblcjQup.cjs} +13 -8
- package/dist/{ThemeContext-BWq9ACPo.js → ThemeContext-Bo-W2WZH.js} +13 -8
- package/dist/{ThemeContext-j5aGtPky.cjs → ThemeContext-CP3a0jxy.cjs} +193 -262
- package/dist/{ThemeContext-vTjumZeM.cjs → ThemeContext-Cmr8Ex8H.cjs} +2 -2
- package/dist/ThemeContext-CpqYShLq.cjs +324 -0
- package/dist/{ThemeContext-CQSo4Iwc.js → ThemeContext-D3LzacmG.js} +8 -1
- package/dist/ThemeContext-Du2nE1PL.js +325 -0
- package/dist/ThemeContext-GeEBTJ3q.cjs +1621 -0
- package/dist/ThemeContext-JyLK9B1o.js +1622 -0
- package/dist/{ThemeContext-CGk3KK0k.cjs → ThemeContext-U4dEYc6C.cjs} +8 -1
- package/dist/{ThemeContext-BXjrgUjW.js → ThemeContext-ept8jhXI.js} +200 -261
- package/dist/{VerifyEmailPage-C0c2e5n0.js → VerifyEmailPage-BE-L9mB7.js} +7 -7
- package/dist/{VerifyEmailPage-DSBMRHtl.js → VerifyEmailPage-BIBOKV7Z.js} +41 -36
- package/dist/{VerifyEmailPage-DgIid028.js → VerifyEmailPage-BJjAMUTW.js} +4 -4
- package/dist/{VerifyEmailPage--1Vurewl.cjs → VerifyEmailPage-BRSP-Pwt.cjs} +3 -3
- package/dist/{VerifyEmailPage-Cwi3kbol.cjs → VerifyEmailPage-Bae2cBXT.cjs} +7 -7
- package/dist/{VerifyEmailPage-De6bQjrz.cjs → VerifyEmailPage-BiRm7Nh4.cjs} +41 -36
- package/dist/{VerifyEmailPage-ByerOcm4.cjs → VerifyEmailPage-Bv8Ah_TK.cjs} +23 -20
- package/dist/VerifyEmailPage-Bvfv8HVQ.js +3214 -0
- package/dist/{VerifyEmailPage-BComraR7.cjs → VerifyEmailPage-CR7kb5df.cjs} +22 -12
- package/dist/{VerifyEmailPage-MTD7AG1Z.js → VerifyEmailPage-C_ihbcth.js} +4 -4
- package/dist/{VerifyEmailPage-1WwWczAn.js → VerifyEmailPage-CbgjOF0v.js} +22 -12
- package/dist/{VerifyEmailPage-DvMLZgFt.js → VerifyEmailPage-CdYPSJoO.js} +1 -1
- package/dist/{VerifyEmailPage-By3Jf__L.cjs → VerifyEmailPage-CkBYfsNy.cjs} +4 -4
- package/dist/{VerifyEmailPage-CJLz3jrn.js → VerifyEmailPage-Cyl55sJb.js} +23 -20
- package/dist/VerifyEmailPage-D-FRj5TU.cjs +3213 -0
- package/dist/VerifyEmailPage-DF2ilhum.cjs +3210 -0
- package/dist/{VerifyEmailPage-CYXtbKi3.cjs → VerifyEmailPage-DMBh4NM9.cjs} +1 -1
- package/dist/{VerifyEmailPage-CgMxRb4z.js → VerifyEmailPage-DTtFfC-J.js} +3 -3
- package/dist/{VerifyEmailPage-CFLMls1p.cjs → VerifyEmailPage-Dt7zgA4w.cjs} +4 -4
- package/dist/VerifyEmailPage-EhudUdqF.js +3211 -0
- package/dist/{VerifyEmailPage-C5TNQTBa.js → VerifyEmailPage-X14vhdyl.js} +148 -75
- package/dist/VerifyEmailPage-hdB8JQGv.cjs +3213 -0
- package/dist/{VerifyEmailPage-B4peJjAT.cjs → VerifyEmailPage-u_Dn7t1U.cjs} +148 -75
- package/dist/VerifyEmailPage-vYHbYK3q.js +3214 -0
- package/dist/{XerticaProvider-CBGc4EMA.cjs → XerticaProvider-AChwphCO.cjs} +4 -4
- package/dist/{XerticaProvider-BIrqfZ-i.cjs → XerticaProvider-AbWlr7Af.cjs} +8 -11
- package/dist/{XerticaProvider-D-yNhF94.cjs → XerticaProvider-B8CaV7xu.cjs} +1 -1
- package/dist/{XerticaProvider-DDuiIcKo.js → XerticaProvider-BErr83Bg.js} +14 -11
- package/dist/{XerticaProvider-CEoWMTxu.js → XerticaProvider-BITjgC5p.js} +2 -2
- package/dist/{XerticaProvider-CllrbMEJ.cjs → XerticaProvider-By8q3Roe.cjs} +2 -2
- package/dist/{XerticaProvider-C1DKnvLh.js → XerticaProvider-CUYJZc32.js} +4 -4
- package/dist/{XerticaProvider-ET0ihewn.cjs → XerticaProvider-CW9hpCdF.cjs} +2 -2
- package/dist/{XerticaProvider-Dt5HEzbQ.js → XerticaProvider-CWgby5mY.js} +10 -10
- package/dist/XerticaProvider-CWs6EwNa.js +49 -0
- package/dist/XerticaProvider-CjQAQPcn.cjs +48 -0
- package/dist/XerticaProvider-CwOkHxiT.cjs +44 -0
- package/dist/XerticaProvider-D5lLumH-.js +49 -0
- package/dist/{XerticaProvider-DYq4JWtg.js → XerticaProvider-DQtvJU7m.js} +1 -1
- package/dist/XerticaProvider-qQUDop71.cjs +48 -0
- package/dist/{XerticaProvider-B7EVH-NF.js → XerticaProvider-siSt9uG2.js} +2 -2
- package/dist/{XerticaXLogo-Zw2B276b.cjs → XerticaXLogo-8TTzBjHw.cjs} +1 -1
- package/dist/{XerticaXLogo-B7xQ5dhi.js → XerticaXLogo-BWaag64t.js} +1 -1
- package/dist/{XerticaXLogo-DZbo4vOE.js → XerticaXLogo-BX3ueACh.js} +5 -2
- package/dist/XerticaXLogo-CFuIlYFH.js +252 -0
- package/dist/XerticaXLogo-CU-U-GP4.cjs +251 -0
- package/dist/XerticaXLogo-ChryA6xj.js +252 -0
- package/dist/{XerticaXLogo-CQUUjXoH.cjs → XerticaXLogo-CziKMQil.cjs} +8 -8
- package/dist/XerticaXLogo-DHz5SugF.js +252 -0
- package/dist/XerticaXLogo-DTee_y8X.cjs +251 -0
- package/dist/{XerticaXLogo-Cmsp-Eey.js → XerticaXLogo-DfUvz-lD.js} +9 -9
- package/dist/XerticaXLogo-kslQ8Tk_.cjs +251 -0
- package/dist/{XerticaXLogo-bvZSgwGF.cjs → XerticaXLogo-qBPhwK3g.cjs} +5 -2
- package/dist/{alert-dialog-s-vmNkJ_.js → alert-dialog-iDe5VE5o.js} +3 -3
- package/dist/{alert-dialog-DSKByiKZ.cjs → alert-dialog-yckpaOpy.cjs} +3 -3
- package/dist/assistant.cjs.js +1 -1
- package/dist/assistant.es.js +1 -1
- package/dist/brand.cjs.js +2 -2
- package/dist/brand.es.js +2 -2
- package/dist/cli.js +90 -37
- package/dist/components/brand/theme-toggle/ThemeToggle.d.ts +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/{google-maps-loader-Y-QkD-Li.cjs → google-maps-loader-BqsYL48U.cjs} +0 -5
- package/dist/{google-maps-loader-CTYySAun.js → google-maps-loader-t2IlYBzw.js} +0 -4
- package/dist/index-CkTUgOwX.js +8 -0
- package/dist/{index-COtD8bRW.cjs → index-D3RLKRAs.cjs} +1 -1
- package/dist/index.cjs.js +5 -5
- package/dist/index.es.js +5 -5
- package/dist/index.umd.js +454 -1027
- package/dist/layout.cjs.js +1 -1
- package/dist/layout.es.js +1 -1
- package/dist/pages.cjs.js +1 -1
- package/dist/pages.es.js +1 -1
- package/dist/{sidebar-DAaY8bRU.cjs → sidebar-B3EYhli0.cjs} +33 -24
- package/dist/{sidebar-B6SlKZYN.js → sidebar-B4ZWaMrE.js} +1 -1
- package/dist/{sidebar-DQj1z3jG.cjs → sidebar-B9NR0lCe.cjs} +269 -227
- package/dist/{sidebar-nzPoVHBQ.cjs → sidebar-BS1p2V7t.cjs} +1 -1
- package/dist/sidebar-BvF5I2Ue.cjs +800 -0
- package/dist/{sidebar-q7P2Godd.cjs → sidebar-C5B_LHek.cjs} +1 -1
- package/dist/{sidebar-CrQDDdcz.js → sidebar-CA6_ek3f.js} +33 -24
- package/dist/{sidebar-BxGXsDAd.cjs → sidebar-CVUGHOS_.cjs} +8 -16
- package/dist/{sidebar-BViy8Eeu.js → sidebar-CmvwjnVb.js} +9 -17
- package/dist/sidebar-CplprZpM.js +801 -0
- package/dist/{sidebar-BbVIQvlP.js → sidebar-Dz7bd3zP.js} +1 -1
- package/dist/sidebar-KIS0C2JH.js +801 -0
- package/dist/sidebar-OTO_up7Z.js +801 -0
- package/dist/sidebar-zowjejT2.cjs +800 -0
- package/dist/{use-audio-player-nv8ZSGa1.js → use-audio-player-Bkh23vQ3.js} +3 -7
- package/dist/{use-audio-player-NKsWyjWu.cjs → use-audio-player-Dn1NR9xN.cjs} +3 -7
- package/dist/{xertica-assistant-dyP7KHM5.cjs → xertica-assistant-B1IaHXnB.cjs} +388 -529
- package/dist/{xertica-assistant-DCsnQyi5.js → xertica-assistant-B1NaSFFj.js} +46 -29
- package/dist/{xertica-assistant-ciJaWqm1.js → xertica-assistant-BMqdyRVi.js} +10 -28
- package/dist/{xertica-assistant-V_IdW4WF.cjs → xertica-assistant-Bj3vBCq_.cjs} +9 -27
- package/dist/{xertica-assistant-CrgTb6Hs.cjs → xertica-assistant-CIaUlbIt.cjs} +47 -22
- package/dist/{xertica-assistant-yX1CFBBo.js → xertica-assistant-DPsESB6t.js} +390 -531
- package/dist/{CodeBlock-BgfYL_rD.cjs → xertica-assistant-Qp3ydksa.cjs} +51 -263
- package/dist/{CodeBlock-BeSt1h5P.js → xertica-assistant-gnCJdcZY.js} +7 -219
- package/dist/xertica-ui.css +2 -2
- package/docs/architecture-improvements.md +456 -456
- package/docs/architecture.md +312 -306
- package/docs/components/assistant.md +428 -428
- package/docs/components/branding.md +252 -252
- package/docs/components/card-patterns.md +447 -445
- package/docs/components/error-boundary.md +32 -22
- package/docs/components/hooks.md +432 -430
- package/docs/components/language-selector.md +176 -172
- package/docs/components/pages.md +20 -6
- package/docs/doc-audit.md +244 -243
- package/docs/getting-started.md +616 -603
- package/docs/guidelines.md +330 -328
- package/docs/i18n.md +480 -476
- package/docs/installation.md +7 -6
- package/docs/llms.md +295 -295
- package/docs/state-management.md +289 -289
- package/guidelines/Guidelines.md +409 -406
- package/llms-compact.txt +1 -1
- package/llms.txt +1 -1
- package/package.json +219 -219
- package/styles/xertica/base.css +6 -0
- package/templates/.prettierignore +4 -4
- package/templates/.prettierrc +10 -10
- package/templates/CLAUDE.md +180 -165
- package/templates/guidelines/Guidelines.md +577 -553
- package/templates/package.json +69 -69
- package/templates/src/app/App.tsx +46 -46
- package/templates/src/app/components/AuthGuard.tsx +57 -8
- package/templates/src/features/assistant/data/mock.ts +75 -75
- package/templates/src/features/assistant/hooks/useAssistantConfig.ts +20 -20
- package/templates/src/features/assistant/index.ts +5 -5
- package/templates/src/features/auth/ui/AuthPageShell.tsx +1 -1
- package/templates/src/features/auth/ui/ForgotPasswordContent.tsx +70 -72
- package/templates/src/features/auth/ui/LoginContent.tsx +92 -92
- package/templates/src/features/auth/ui/ResetPasswordContent.tsx +183 -179
- package/templates/src/features/auth/ui/SocialLoginButtons.tsx +78 -78
- package/templates/src/features/auth/ui/VerifyEmailContent.tsx +80 -84
- package/templates/src/features/home/data/mock.ts +6 -0
- package/templates/src/features/home/hooks/useFeatureCards.ts +20 -20
- package/templates/src/features/home/index.ts +11 -11
- package/templates/src/features/home/ui/HomeContent.tsx +117 -119
- package/templates/src/features/template/ui/CrudTemplate.tsx +112 -115
- package/templates/src/features/template/ui/DashboardTemplate.tsx +110 -110
- package/templates/src/features/template/ui/FormTemplate.tsx +117 -117
- package/templates/src/features/template/ui/LoginTemplate.tsx +59 -59
- package/templates/src/features/template/ui/TemplateContent.tsx +1322 -1314
- package/templates/src/i18n.ts +124 -124
- package/templates/src/locales/en/common.json +21 -21
- package/templates/src/locales/en/components/activityCard.json +10 -10
- package/templates/src/locales/en/components/assistant.json +119 -119
- package/templates/src/locales/en/components/media.json +29 -29
- package/templates/src/locales/en/components/notificationCard.json +5 -5
- package/templates/src/locales/en/components/profileCard.json +8 -8
- package/templates/src/locales/en/components/projectCard.json +10 -10
- package/templates/src/locales/en/components/sidebar.json +14 -14
- package/templates/src/locales/en/components/stats.json +8 -8
- package/templates/src/locales/en/components/team.json +14 -14
- package/templates/src/locales/en/errors.json +9 -9
- package/templates/src/locales/en/languageSelector.json +7 -7
- package/templates/src/locales/en/nav.json +6 -6
- package/templates/src/locales/en/pages/crudTemplate.json +25 -25
- package/templates/src/locales/en/pages/dashboardTemplate.json +20 -20
- package/templates/src/locales/en/pages/forgotPassword.json +10 -10
- package/templates/src/locales/en/pages/formTemplate.json +16 -16
- package/templates/src/locales/en/pages/home.json +7 -7
- package/templates/src/locales/en/pages/login.json +15 -15
- package/templates/src/locales/en/pages/loginTemplate.json +9 -9
- package/templates/src/locales/en/pages/resetPassword.json +18 -18
- package/templates/src/locales/en/pages/templates.json +317 -317
- package/templates/src/locales/en/pages/verifyEmail.json +12 -12
- package/templates/src/locales/en/themeToggle.json +6 -6
- package/templates/src/locales/es/common.json +21 -21
- package/templates/src/locales/es/components/activityCard.json +10 -10
- package/templates/src/locales/es/components/assistant.json +119 -119
- package/templates/src/locales/es/components/media.json +29 -29
- package/templates/src/locales/es/components/notificationCard.json +5 -5
- package/templates/src/locales/es/components/profileCard.json +8 -8
- package/templates/src/locales/es/components/projectCard.json +10 -10
- package/templates/src/locales/es/components/sidebar.json +14 -14
- package/templates/src/locales/es/components/stats.json +8 -8
- package/templates/src/locales/es/components/team.json +14 -14
- package/templates/src/locales/es/errors.json +9 -9
- package/templates/src/locales/es/languageSelector.json +7 -7
- package/templates/src/locales/es/nav.json +6 -6
- package/templates/src/locales/es/pages/crudTemplate.json +25 -25
- package/templates/src/locales/es/pages/dashboardTemplate.json +20 -20
- package/templates/src/locales/es/pages/forgotPassword.json +10 -10
- package/templates/src/locales/es/pages/formTemplate.json +16 -16
- package/templates/src/locales/es/pages/home.json +7 -7
- package/templates/src/locales/es/pages/login.json +15 -15
- package/templates/src/locales/es/pages/loginTemplate.json +9 -9
- package/templates/src/locales/es/pages/resetPassword.json +18 -18
- package/templates/src/locales/es/pages/templates.json +317 -317
- package/templates/src/locales/es/pages/verifyEmail.json +12 -12
- package/templates/src/locales/es/themeToggle.json +6 -6
- package/templates/src/locales/pt-BR/common.json +21 -21
- package/templates/src/locales/pt-BR/components/activityCard.json +10 -10
- package/templates/src/locales/pt-BR/components/assistant.json +119 -119
- package/templates/src/locales/pt-BR/components/media.json +29 -29
- package/templates/src/locales/pt-BR/components/notificationCard.json +5 -5
- package/templates/src/locales/pt-BR/components/profileCard.json +8 -8
- package/templates/src/locales/pt-BR/components/projectCard.json +10 -10
- package/templates/src/locales/pt-BR/components/sidebar.json +14 -14
- package/templates/src/locales/pt-BR/components/stats.json +8 -8
- package/templates/src/locales/pt-BR/components/team.json +14 -14
- package/templates/src/locales/pt-BR/errors.json +9 -9
- package/templates/src/locales/pt-BR/languageSelector.json +7 -7
- package/templates/src/locales/pt-BR/nav.json +6 -6
- package/templates/src/locales/pt-BR/pages/crudTemplate.json +25 -25
- package/templates/src/locales/pt-BR/pages/dashboardTemplate.json +20 -20
- package/templates/src/locales/pt-BR/pages/forgotPassword.json +10 -10
- package/templates/src/locales/pt-BR/pages/formTemplate.json +16 -16
- package/templates/src/locales/pt-BR/pages/home.json +7 -7
- package/templates/src/locales/pt-BR/pages/login.json +15 -15
- package/templates/src/locales/pt-BR/pages/loginTemplate.json +9 -9
- package/templates/src/locales/pt-BR/pages/resetPassword.json +18 -18
- package/templates/src/locales/pt-BR/pages/templates.json +317 -317
- package/templates/src/locales/pt-BR/pages/verifyEmail.json +12 -12
- package/templates/src/locales/pt-BR/themeToggle.json +6 -6
- package/templates/src/pages/AssistantPage.tsx +470 -464
- package/templates/src/pages/HomePage.tsx +53 -49
- package/templates/src/shared/error-boundary.tsx +1 -5
- package/templates/src/shared/error-fallbacks.tsx +4 -8
- package/templates/vite.config.js +20 -20
- package/templates/vite.config.ts +55 -52
- package/dist/AssistantChart-CxGjH7Qk.js +0 -3477
- package/dist/AssistantChart-DIpshm3i.js +0 -4784
- package/dist/AssistantChart-D_PTeu8P.cjs +0 -3503
- package/dist/AssistantChart-zjsy2GaZ.cjs +0 -4810
- package/dist/AudioPlayer-B1lt5cPl.cjs +0 -989
- package/dist/AudioPlayer-BZ7bibzU.cjs +0 -982
- package/dist/AudioPlayer-BpRPS4-1.cjs +0 -1277
- package/dist/AudioPlayer-C12BjQBV.cjs +0 -997
- package/dist/AudioPlayer-CFeV8t-5.cjs +0 -936
- package/dist/AudioPlayer-Coly3q5R.js +0 -1278
- package/dist/AudioPlayer-CySJIyvL.js +0 -937
- package/dist/AudioPlayer-DMcG_c7L.js +0 -990
- package/dist/AudioPlayer-DcFKRJE_.js +0 -998
- package/dist/AudioPlayer-e8LfNoqO.js +0 -983
- package/dist/BrandColorsContext-565dDHd5.js +0 -660
- package/dist/BrandColorsContext-BcJbtkqn.cjs +0 -659
- package/dist/CodeBlock-7TTgmdGG.cjs +0 -2094
- package/dist/CodeBlock-BlcqlA9M.cjs +0 -2094
- package/dist/CodeBlock-Bnmeu5ez.cjs +0 -2094
- package/dist/CodeBlock-BtfPlbAI.js +0 -2078
- package/dist/CodeBlock-CIySIuYr.js +0 -2078
- package/dist/CodeBlock-CuPtUM-7.cjs +0 -2094
- package/dist/CodeBlock-D6ffWXgc.js +0 -2078
- package/dist/CodeBlock-D8dcwbit.cjs +0 -2094
- package/dist/CodeBlock-DMZrFnlw.cjs +0 -2094
- package/dist/CodeBlock-DlBehYN8.js +0 -2078
- package/dist/CodeBlock-DnYNI8rQ.js +0 -2078
- package/dist/CodeBlock-DvKWbSnE.cjs +0 -2094
- package/dist/CodeBlock-DwMCfkFY.js +0 -2078
- package/dist/CodeBlock-Dy6CNYyj.js +0 -2078
- package/dist/CodeBlock-U1pPOQI7.cjs +0 -2094
- package/dist/CodeBlock-f_GpNhEB.js +0 -2078
- package/dist/CodeBlock-oB6u8nI1.js +0 -2078
- package/dist/CodeBlock-tZC31B73.cjs +0 -2094
- package/dist/FeatureCard-CxC-7C-C.cjs +0 -300
- package/dist/FeatureCard-DbHWCb4E.js +0 -301
- package/dist/ImageWithFallback-CGtidP6B.cjs +0 -4542
- package/dist/ImageWithFallback-lsg3pdFg.js +0 -4508
- package/dist/LanguageSelector-B5YfbHra.js +0 -231
- package/dist/LanguageSelector-D6uacAIM.cjs +0 -230
- package/dist/LayoutContext-B45-e9DI.cjs +0 -93
- package/dist/LayoutContext-BAql6ZRY.js +0 -97
- package/dist/LayoutContext-Bav3UMEA.js +0 -94
- package/dist/LayoutContext-BvK-ggDa.cjs +0 -96
- package/dist/ThemeContext-BoH4NLfN.js +0 -734
- package/dist/ThemeContext-r69W20Xg.cjs +0 -733
- package/dist/VerifyEmailPage-COiyNl1y.js +0 -2825
- package/dist/VerifyEmailPage-CqKsR2v8.js +0 -2827
- package/dist/VerifyEmailPage-DjQKRlUS.cjs +0 -2824
- package/dist/VerifyEmailPage-s-1X3LDJ.cjs +0 -2826
- package/dist/XerticaOrbe-KL1RBHzw.cjs +0 -1354
- package/dist/XerticaOrbe-zwS1p2a8.js +0 -1355
- package/dist/XerticaProvider-6btlAlzc.js +0 -17
- package/dist/XerticaProvider-BNoNOxQ5.cjs +0 -16
- package/dist/XerticaProvider-BlY2limY.cjs +0 -38
- package/dist/XerticaProvider-cI9hSs27.cjs +0 -38
- package/dist/XerticaProvider-hSwhNQex.js +0 -39
- package/dist/alert-dialog-BOje--vD.js +0 -847
- package/dist/alert-dialog-BtEuQqrg.cjs +0 -870
- package/dist/breadcrumb-CqJ7bHY5.js +0 -161
- package/dist/breadcrumb-m9Hb2_XN.cjs +0 -177
- package/dist/components/assistant/xertica-assistant/hooks/index.d.ts +0 -6
- package/dist/components/assistant/xertica-assistant/hooks/use-assistant-conversations.d.ts +0 -21
- package/dist/components/assistant/xertica-assistant/hooks/use-assistant-messages.d.ts +0 -49
- package/dist/components/assistant/xertica-assistant/hooks/use-assistant-suggestions.d.ts +0 -16
- package/dist/components/blocks/audio-player/AudioPlayer.d.ts +0 -35
- package/dist/components/blocks/audio-player/index.d.ts +0 -1
- package/dist/components/blocks/document-editor/DocumentEditor.d.ts +0 -26
- package/dist/components/blocks/document-editor/index.d.ts +0 -1
- package/dist/components/blocks/podcast-player/PodcastPlayer.d.ts +0 -41
- package/dist/components/blocks/podcast-player/index.d.ts +0 -1
- package/dist/components/ui/chart/parts/chart-dashboard.d.ts +0 -113
- package/dist/components/ui/chart/parts/chart-metric.d.ts +0 -118
- package/dist/components/ui/chart/parts/chart-primitives.d.ts +0 -101
- package/dist/components/ui/chart/parts/chart-shared.d.ts +0 -20
- package/dist/components/ui/chart/parts/chart-utils.d.ts +0 -12
- package/dist/components/ui/chart/parts/index.d.ts +0 -5
- package/dist/dropdown-menu-BDB5CmQs.cjs +0 -247
- package/dist/dropdown-menu-DQidbKBD.js +0 -231
- package/dist/google-maps-loader-BFWp6VPd.js +0 -287
- package/dist/google-maps-loader-BKcdgFbu.cjs +0 -312
- package/dist/google-maps-loader-CumCNXeG.js +0 -312
- package/dist/google-maps-loader-eS3uQ5TA.cjs +0 -287
- package/dist/header-Cgy6vYPk.cjs +0 -731
- package/dist/header-DRlT4jgI.js +0 -715
- package/dist/header-Dux00SI4.cjs +0 -731
- package/dist/header-EkGKXPsD.js +0 -715
- package/dist/header-WfEywpyc.cjs +0 -731
- package/dist/header-tifNQn2U.js +0 -715
- package/dist/index-BhapVLVj.js +0 -8
- package/dist/index-D6fxYEY8.cjs +0 -7
- package/dist/index-DAIp0_HK.js +0 -8
- package/dist/index-DW5tYe26.js +0 -8
- package/dist/index-GA__GvnG.cjs +0 -7
- package/dist/input-2R4loU86.js +0 -127
- package/dist/input-DWANSKGb.cjs +0 -145
- package/dist/progress-DPtzoVV8.js +0 -175
- package/dist/progress-EeaoqqUs.cjs +0 -191
- package/dist/rich-text-editor-0mraWT5y.cjs +0 -2376
- package/dist/rich-text-editor-B-IkcPD0.js +0 -2874
- package/dist/rich-text-editor-B6jMRLzk.cjs +0 -1939
- package/dist/rich-text-editor-B8_oYcIR.js +0 -1730
- package/dist/rich-text-editor-B9UbSXNb.js +0 -1203
- package/dist/rich-text-editor-BYuRBNBU.js +0 -2373
- package/dist/rich-text-editor-Bb9pySTs.cjs +0 -2374
- package/dist/rich-text-editor-BcL6L3cm.cjs +0 -2374
- package/dist/rich-text-editor-BoVZYtTs.cjs +0 -2391
- package/dist/rich-text-editor-Bp3zQqMC.js +0 -2954
- package/dist/rich-text-editor-CMgSN_w2.js +0 -1189
- package/dist/rich-text-editor-CPV1lEPH.cjs +0 -1748
- package/dist/rich-text-editor-CeucBdIv.cjs +0 -2971
- package/dist/rich-text-editor-CoKqbCtu.cjs +0 -1799
- package/dist/rich-text-editor-Cw56T_mB.js +0 -2356
- package/dist/rich-text-editor-Cyt8qs2b.js +0 -1921
- package/dist/rich-text-editor-D6H84OcX.cjs +0 -1220
- package/dist/rich-text-editor-D76gD-QI.js +0 -2328
- package/dist/rich-text-editor-DKkokOnA.js +0 -1781
- package/dist/rich-text-editor-DNsdpN64.cjs +0 -2359
- package/dist/rich-text-editor-DfG8bCyY.js +0 -2358
- package/dist/rich-text-editor-Dxjw31Z4.js +0 -2341
- package/dist/rich-text-editor-DzP0Epmb.js +0 -2356
- package/dist/rich-text-editor-bRkNoeZY.cjs +0 -2891
- package/dist/rich-text-editor-lyYE2ZG5.cjs +0 -1207
- package/dist/rich-text-editor-skplNlBM.cjs +0 -2345
- package/dist/select-Bkbr0f-Z.cjs +0 -162
- package/dist/select-CvIVdX2n.js +0 -145
- package/dist/sidebar-CK_0ZQHj.cjs +0 -803
- package/dist/sidebar-CUuOvYhK.js +0 -787
- package/dist/sidebar-Djn5syhi.cjs +0 -786
- package/dist/sidebar-LluMXfam.js +0 -759
- package/dist/sidebar-_rT7rBMk.js +0 -787
- package/dist/slider-Bc5Hd0y1.js +0 -56
- package/dist/slider-N7hFFj6X.cjs +0 -73
- package/dist/tooltip-Ded96neP.cjs +0 -137
- package/dist/tooltip-HDOoD2-0.js +0 -120
- package/dist/use-audio-player-B31J-aqh.cjs +0 -187
- package/dist/use-audio-player-BkmEmj8Q.js +0 -185
- package/dist/use-audio-player-CLFTWFW1.cjs +0 -184
- package/dist/use-audio-player-CLLn00I6.js +0 -188
- package/dist/use-file-upload-BcjEo2S5.js +0 -404
- package/dist/use-file-upload-CRJR68Tj.cjs +0 -403
- package/dist/use-mobile-B0hNy_Y6.cjs +0 -4303
- package/dist/use-mobile-BXuYROXM.js +0 -4202
- package/dist/use-mobile-Bbd51ASU.cjs +0 -4392
- package/dist/use-mobile-Bk6CX-TC.js +0 -4359
- package/dist/use-mobile-BvYdisLP.js +0 -4202
- package/dist/use-mobile-BzuxjzNX.cjs +0 -4392
- package/dist/use-mobile-CG2-SdXV.cjs +0 -4235
- package/dist/use-mobile-CKb5pqTs.js +0 -4269
- package/dist/use-mobile-CYuAuGDl.js +0 -4202
- package/dist/use-mobile-CaENcqm-.js +0 -4508
- package/dist/use-mobile-CbrYgJGJ.js +0 -4203
- package/dist/use-mobile-Cd4xPrKq.cjs +0 -46
- package/dist/use-mobile-DMOvImGQ.cjs +0 -4542
- package/dist/use-mobile-DRB3BQgD.cjs +0 -4235
- package/dist/use-mobile-DZvv7QMR.js +0 -4359
- package/dist/use-mobile-DdI_TXam.cjs +0 -4235
- package/dist/use-mobile-DlceKf8a.js +0 -4359
- package/dist/use-mobile-DsOnow1o.cjs +0 -4236
- package/dist/use-mobile-Kcj6jSnK.cjs +0 -4392
- package/dist/use-mobile-bnKcua_i.js +0 -4202
- package/dist/use-mobile-j4w2Jrf1.js +0 -30
- package/dist/use-mobile-ncXBeE2z.cjs +0 -4235
- package/dist/use-rich-text-editor-DjiddBGv.js +0 -282
- package/dist/use-rich-text-editor-lpeswbCs.cjs +0 -281
- package/dist/xertica-assistant-BdiZag0h.js +0 -2187
- package/dist/xertica-assistant-DUBpmEgo.cjs +0 -2186
- package/dist/{rich-text-editor-DgF8s7xW.js → rich-text-editor-BmsjY03B.js} +26 -26
- package/dist/{rich-text-editor-mWoaSCE4.cjs → rich-text-editor-GS2kpTAK.cjs} +26 -26
|
@@ -1,615 +1,615 @@
|
|
|
1
|
-
import { useState, useEffect, useRef, useCallback, useMemo } from 'react';
|
|
2
|
-
import { useTranslation } from 'react-i18next';
|
|
3
|
-
import type { ActionType } from '../modern-chat-input/ModernChatInput';
|
|
4
|
-
import { toast } from 'sonner';
|
|
5
|
-
import { gerarResposta } from '../../shared/assistant-utils';
|
|
6
|
-
import { useIsMobile } from '../../shared/use-mobile';
|
|
7
|
-
import type {
|
|
8
|
-
Message,
|
|
9
|
-
Conversation,
|
|
10
|
-
Suggestion,
|
|
11
|
-
AssistantTab,
|
|
12
|
-
AssistantMode,
|
|
13
|
-
SearchResult,
|
|
14
|
-
MockResponse,
|
|
15
|
-
} from './types';
|
|
16
|
-
|
|
17
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
18
|
-
// Hook Props
|
|
19
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
20
|
-
|
|
21
|
-
export interface UseAssistantProps {
|
|
22
|
-
/** Layout mode for the assistant panel */
|
|
23
|
-
mode?: AssistantMode;
|
|
24
|
-
/** Controlled expansion state */
|
|
25
|
-
isExpanded?: boolean;
|
|
26
|
-
/** Toggle callback for controlled expansion */
|
|
27
|
-
onToggle?: () => void;
|
|
28
|
-
/** Initially selected tab */
|
|
29
|
-
defaultTab?: AssistantTab;
|
|
30
|
-
/** Enables demo mode with mock AI responses */
|
|
31
|
-
demoMode?: boolean;
|
|
32
|
-
/** Custom mock responses for demo mode */
|
|
33
|
-
customResponses?: MockResponse[];
|
|
34
|
-
/** Pre-loaded messages to hydrate an existing conversation */
|
|
35
|
-
initialMessages?: Message[];
|
|
36
|
-
/** Previously saved conversations */
|
|
37
|
-
savedConversations?: Conversation[];
|
|
38
|
-
/** Suggested prompts shown in the empty state */
|
|
39
|
-
suggestions?: Suggestion[];
|
|
40
|
-
/** Callback fired when the user sends a message */
|
|
41
|
-
onSendMessage?: (message: string) => void;
|
|
42
|
-
/** Whether the assistant is currently processing a response */
|
|
43
|
-
isProcessing?: boolean;
|
|
44
|
-
/** Custom response generator — overrides demo mode defaults */
|
|
45
|
-
responseGenerator?: (
|
|
46
|
-
message: string
|
|
47
|
-
) => Promise<string | Partial<Message>> | string | Partial<Message>;
|
|
48
|
-
/** Extended suggestions shown when the user clicks "More suggestions" */
|
|
49
|
-
richSuggestions?: Suggestion[];
|
|
50
|
-
/** Callback fired when the user clicks a rich suggestion */
|
|
51
|
-
onRichAction?: (actionId: string, actionText: string) => void;
|
|
52
|
-
/** Callback fired when the user rates a message */
|
|
53
|
-
onEvaluation?: (messageId: string, type: 'like' | 'dislike', reason?: string) => void;
|
|
54
|
-
/** Negative feedback categories shown in the dislike dropdown */
|
|
55
|
-
feedbackOptions?: string[];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
59
|
-
// Hook Return Value
|
|
60
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
61
|
-
|
|
62
|
-
export interface UseAssistantReturn {
|
|
63
|
-
// ── Layout state ──────────────────────────────────────────────────────────
|
|
64
|
-
isFullPage: boolean;
|
|
65
|
-
isExpanded: boolean;
|
|
66
|
-
isMobile: boolean;
|
|
67
|
-
abaSelecionada: AssistantTab;
|
|
68
|
-
setAbaSelecionada: (tab: AssistantTab) => void;
|
|
69
|
-
|
|
70
|
-
// ── Message state ─────────────────────────────────────────────────────────
|
|
71
|
-
mensagens: Message[];
|
|
72
|
-
setMensagens: React.Dispatch<React.SetStateAction<Message[]>>;
|
|
73
|
-
mensagem: string;
|
|
74
|
-
setMensagem: (value: string) => void;
|
|
75
|
-
|
|
76
|
-
// ── Conversation state ────────────────────────────────────────────────────
|
|
77
|
-
conversas: Conversation[];
|
|
78
|
-
conversaAtual: string | null;
|
|
79
|
-
conversasFiltradas: Conversation[];
|
|
80
|
-
|
|
81
|
-
// ── UI state ──────────────────────────────────────────────────────────────
|
|
82
|
-
copiedId: string | null;
|
|
83
|
-
generatingPodcastId: string | null;
|
|
84
|
-
executingCommand: string | null;
|
|
85
|
-
savedSearches: string[];
|
|
86
|
-
editingDocument: { content: string; title: string } | null;
|
|
87
|
-
setEditingDocument: (doc: { content: string; title: string } | null) => void;
|
|
88
|
-
showMoreSuggestions: boolean;
|
|
89
|
-
setShowMoreSuggestions: (show: boolean) => void;
|
|
90
|
-
evaluationState: {
|
|
91
|
-
isOpen: boolean;
|
|
92
|
-
messageId: string | null;
|
|
93
|
-
type: 'dislike' | null;
|
|
94
|
-
category?: string | null;
|
|
95
|
-
reason: string;
|
|
96
|
-
};
|
|
97
|
-
setEvaluationState: React.Dispatch<React.SetStateAction<UseAssistantReturn['evaluationState']>>;
|
|
98
|
-
|
|
99
|
-
// ── Suggestions ───────────────────────────────────────────────────────────
|
|
100
|
-
sugestoes: Suggestion[];
|
|
101
|
-
|
|
102
|
-
// ── Refs ──────────────────────────────────────────────────────────────────
|
|
103
|
-
messagesEndRef: React.RefObject<HTMLDivElement>;
|
|
104
|
-
fileInputRef: React.RefObject<HTMLInputElement>;
|
|
105
|
-
audioInputRef: React.RefObject<HTMLInputElement>;
|
|
106
|
-
|
|
107
|
-
// ── Handlers ──────────────────────────────────────────────────────────────
|
|
108
|
-
handleToggle: () => void;
|
|
109
|
-
handleExpandWithTab: (tab: AssistantTab) => void;
|
|
110
|
-
handleEnviarMensagem: (arg?: string | ActionType) => Promise<void>;
|
|
111
|
-
handleToggleFavorite: (messageId: string) => void;
|
|
112
|
-
handleCopyMessage: (content: string, messageId: string) => Promise<void>;
|
|
113
|
-
handleGeneratePodcast: (messageId: string, content: string) => Promise<void>;
|
|
114
|
-
handleDownloadDocument: (content: string, fileName: string) => void;
|
|
115
|
-
handleDownloadPodcast: (audioUrl: string, fileName: string) => void;
|
|
116
|
-
handleEditDocument: (content: string, title: string) => void;
|
|
117
|
-
handleNovaConversa: () => void;
|
|
118
|
-
handleSelecionarConversa: (conversaId: string) => void;
|
|
119
|
-
handleToggleFavoritaConversa: (conversaId: string) => void;
|
|
120
|
-
handleOpenSearchResult: (result: SearchResult) => void;
|
|
121
|
-
handleExecuteSearchCommand: (
|
|
122
|
-
commandId: string,
|
|
123
|
-
searchTerm: string,
|
|
124
|
-
results: SearchResult[],
|
|
125
|
-
messageId: string
|
|
126
|
-
) => Promise<void>;
|
|
127
|
-
handleRichSuggestionClick: (suggestion: Suggestion) => void;
|
|
128
|
-
handleEvaluationClick: (messageId: string, type: 'like' | 'dislike') => void;
|
|
129
|
-
openFeedbackDialog: (messageId: string, category: string | null) => void;
|
|
130
|
-
handleSubmitDislike: () => void;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// DEFAULT_SUGGESTIONS is intentionally NOT defined at module scope.
|
|
134
|
-
// See the `useAssistant` hook below where they are built with `useMemo`
|
|
135
|
-
// so that `t()` is always called inside the React render cycle with the
|
|
136
|
-
// currently active language.
|
|
137
|
-
|
|
138
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
139
|
-
// Hook
|
|
140
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* `useAssistant` — Headless hook for the XerticaAssistant component.
|
|
144
|
-
*
|
|
145
|
-
* Encapsulates all state management and business logic for the AI assistant panel.
|
|
146
|
-
* Use this hook when you need to build a fully custom assistant UI while reusing
|
|
147
|
-
* the same state logic as the default `XerticaAssistant` component.
|
|
148
|
-
*
|
|
149
|
-
* @example
|
|
150
|
-
* ```tsx
|
|
151
|
-
* import { useAssistant } from 'xertica-ui/assistant';
|
|
152
|
-
*
|
|
153
|
-
* function MyCustomAssistant() {
|
|
154
|
-
* const {
|
|
155
|
-
* mensagens,
|
|
156
|
-
* mensagem,
|
|
157
|
-
* setMensagem,
|
|
158
|
-
* handleEnviarMensagem,
|
|
159
|
-
* isExpanded,
|
|
160
|
-
* handleToggle,
|
|
161
|
-
* } = useAssistant({ demoMode: true });
|
|
162
|
-
*
|
|
163
|
-
* return (
|
|
164
|
-
* <div>
|
|
165
|
-
* {mensagens.map(msg => <p key={msg.id}>{msg.content}</p>)}
|
|
166
|
-
* <input value={mensagem} onChange={e => setMensagem(e.target.value)} />
|
|
167
|
-
* <button onClick={() => handleEnviarMensagem()}>Send</button>
|
|
168
|
-
* </div>
|
|
169
|
-
* );
|
|
170
|
-
* }
|
|
171
|
-
* ```
|
|
172
|
-
*/
|
|
173
|
-
export function useAssistant({
|
|
174
|
-
mode = 'expanded',
|
|
175
|
-
isExpanded: controlledIsExpanded,
|
|
176
|
-
onToggle,
|
|
177
|
-
defaultTab = 'chat',
|
|
178
|
-
demoMode = true,
|
|
179
|
-
customResponses = [],
|
|
180
|
-
initialMessages = [],
|
|
181
|
-
savedConversations = [],
|
|
182
|
-
suggestions: propSuggestions,
|
|
183
|
-
onSendMessage,
|
|
184
|
-
isProcessing = false,
|
|
185
|
-
responseGenerator,
|
|
186
|
-
richSuggestions = [],
|
|
187
|
-
onRichAction,
|
|
188
|
-
onEvaluation,
|
|
189
|
-
}: UseAssistantProps = {}): UseAssistantReturn {
|
|
190
|
-
const { t } = useTranslation();
|
|
191
|
-
|
|
192
|
-
// ── Layout state ────────────────────────────────────────────────────────────
|
|
193
|
-
const isFullPage = mode === 'fullPage';
|
|
194
|
-
const [internalIsExpanded, setInternalIsExpanded] = useState(controlledIsExpanded ?? true);
|
|
195
|
-
const isExpanded = controlledIsExpanded ?? internalIsExpanded;
|
|
196
|
-
const isMobile = useIsMobile();
|
|
197
|
-
|
|
198
|
-
// ── Tab state ───────────────────────────────────────────────────────────────
|
|
199
|
-
const [abaSelecionada, setAbaSelecionada] = useState<AssistantTab>(defaultTab);
|
|
200
|
-
|
|
201
|
-
// ── Message state ───────────────────────────────────────────────────────────
|
|
202
|
-
const [mensagens, setMensagens] = useState<Message[]>(initialMessages);
|
|
203
|
-
const [mensagem, setMensagem] = useState('');
|
|
204
|
-
|
|
205
|
-
// ── Conversation state ──────────────────────────────────────────────────────
|
|
206
|
-
const [conversas, setConversas] = useState<Conversation[]>(savedConversations);
|
|
207
|
-
const [conversaAtual, setConversaAtual] = useState<string | null>(null);
|
|
208
|
-
|
|
209
|
-
// ── UI state ────────────────────────────────────────────────────────────────
|
|
210
|
-
const [copiedId, setCopiedId] = useState<string | null>(null);
|
|
211
|
-
const [generatingPodcastId, setGeneratingPodcastId] = useState<string | null>(null);
|
|
212
|
-
const [executingCommand, setExecutingCommand] = useState<string | null>(null);
|
|
213
|
-
const [savedSearches, setSavedSearches] = useState<string[]>([]);
|
|
214
|
-
const [editingDocument, setEditingDocument] = useState<{ content: string; title: string } | null>(
|
|
215
|
-
null
|
|
216
|
-
);
|
|
217
|
-
const [showMoreSuggestions, setShowMoreSuggestions] = useState(false);
|
|
218
|
-
const [evaluationState, setEvaluationState] = useState<UseAssistantReturn['evaluationState']>({
|
|
219
|
-
isOpen: false,
|
|
220
|
-
messageId: null,
|
|
221
|
-
type: null,
|
|
222
|
-
category: null,
|
|
223
|
-
reason: '',
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
// ── Refs ────────────────────────────────────────────────────────────────────
|
|
227
|
-
const messagesEndRef = useRef<HTMLDivElement>(null);
|
|
228
|
-
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
229
|
-
const audioInputRef = useRef<HTMLInputElement>(null);
|
|
230
|
-
const responseTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
231
|
-
const commandTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
232
|
-
const hydratedRef = useRef(false);
|
|
233
|
-
|
|
234
|
-
// ── Suggestions ─────────────────────────────────────────────────────────────
|
|
235
|
-
// Built inside useMemo so t() is re-evaluated when language changes.
|
|
236
|
-
const defaultSuggestions = useMemo<Suggestion[]>(
|
|
237
|
-
() => [
|
|
238
|
-
{ id: '1', text: t('assistant.defaultSuggestions.createDocument') },
|
|
239
|
-
{ id: '2', text: t('assistant.defaultSuggestions.searchFiles') },
|
|
240
|
-
{ id: '3', text: t('assistant.defaultSuggestions.summarizeConversations') },
|
|
241
|
-
{ id: '4', text: t('assistant.defaultSuggestions.createPodcast') },
|
|
242
|
-
],
|
|
243
|
-
[t]
|
|
244
|
-
);
|
|
245
|
-
const sugestoes = propSuggestions ?? defaultSuggestions;
|
|
246
|
-
|
|
247
|
-
// ── Effects ─────────────────────────────────────────────────────────────────
|
|
248
|
-
|
|
249
|
-
// Cleanup timers on unmount
|
|
250
|
-
useEffect(() => {
|
|
251
|
-
return () => {
|
|
252
|
-
if (responseTimerRef.current) clearTimeout(responseTimerRef.current);
|
|
253
|
-
if (commandTimerRef.current) clearTimeout(commandTimerRef.current);
|
|
254
|
-
};
|
|
255
|
-
}, []);
|
|
256
|
-
|
|
257
|
-
// Auto-scroll on new messages (condicional ≤ 120px)
|
|
258
|
-
useEffect(() => {
|
|
259
|
-
if (messagesEndRef.current && abaSelecionada === 'chat') {
|
|
260
|
-
const container = messagesEndRef.current.parentElement;
|
|
261
|
-
if (!container) {
|
|
262
|
-
messagesEndRef.current.scrollIntoView({ behavior: 'smooth' });
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
const distanceFromBottom =
|
|
266
|
-
container.scrollHeight - container.scrollTop - container.clientHeight;
|
|
267
|
-
if (distanceFromBottom < 120) {
|
|
268
|
-
messagesEndRef.current.scrollIntoView({ behavior: 'smooth' });
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}, [mensagens, abaSelecionada]);
|
|
272
|
-
|
|
273
|
-
// Sync initial messages when they change (one-shot hydration)
|
|
274
|
-
useEffect(() => {
|
|
275
|
-
if (!hydratedRef.current && initialMessages && initialMessages.length > 0) {
|
|
276
|
-
setMensagens(initialMessages);
|
|
277
|
-
hydratedRef.current = true;
|
|
278
|
-
}
|
|
279
|
-
}, [initialMessages]);
|
|
280
|
-
|
|
281
|
-
// ── Computed ────────────────────────────────────────────────────────────────
|
|
282
|
-
|
|
283
|
-
const conversasFiltradas = useMemo(
|
|
284
|
-
() => conversas.filter(c => (abaSelecionada === 'favoritos' ? c.isFavorite : true)),
|
|
285
|
-
[conversas, abaSelecionada]
|
|
286
|
-
);
|
|
287
|
-
|
|
288
|
-
// ── Handlers ────────────────────────────────────────────────────────────────
|
|
289
|
-
|
|
290
|
-
const handleToggle = useCallback(() => {
|
|
291
|
-
if (onToggle) {
|
|
292
|
-
onToggle();
|
|
293
|
-
} else {
|
|
294
|
-
setInternalIsExpanded(prev => !prev);
|
|
295
|
-
}
|
|
296
|
-
}, [onToggle]);
|
|
297
|
-
|
|
298
|
-
const handleExpandWithTab = useCallback(
|
|
299
|
-
(tab: AssistantTab) => {
|
|
300
|
-
setAbaSelecionada(tab);
|
|
301
|
-
if (onToggle) {
|
|
302
|
-
onToggle();
|
|
303
|
-
} else {
|
|
304
|
-
setInternalIsExpanded(true);
|
|
305
|
-
}
|
|
306
|
-
},
|
|
307
|
-
[onToggle]
|
|
308
|
-
);
|
|
309
|
-
|
|
310
|
-
const handleEnviarMensagem = useCallback(
|
|
311
|
-
async (arg?: string | ActionType) => {
|
|
312
|
-
let msgToSend = mensagem;
|
|
313
|
-
|
|
314
|
-
if (typeof arg === 'string' && !['document', 'podcast', 'search'].includes(arg)) {
|
|
315
|
-
msgToSend = arg;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
if (!msgToSend.trim() || isProcessing) return;
|
|
319
|
-
|
|
320
|
-
const novaMensagem: Message = {
|
|
321
|
-
id: `msg-${Date.now()}`,
|
|
322
|
-
type: 'user',
|
|
323
|
-
content: msgToSend,
|
|
324
|
-
timestamp: new Date(),
|
|
325
|
-
isFavorite: false,
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
setMensagens(prev => [...prev, novaMensagem]);
|
|
329
|
-
|
|
330
|
-
if (onSendMessage) {
|
|
331
|
-
onSendMessage(msgToSend);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
if (demoMode || responseGenerator) {
|
|
335
|
-
const mensagemAtual = msgToSend;
|
|
336
|
-
responseTimerRef.current = setTimeout(
|
|
337
|
-
async () => {
|
|
338
|
-
let resposta: string | Partial<Message>;
|
|
339
|
-
|
|
340
|
-
if (responseGenerator) {
|
|
341
|
-
resposta = await responseGenerator(mensagemAtual);
|
|
342
|
-
} else {
|
|
343
|
-
resposta = gerarResposta(mensagemAtual, customResponses);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
let novaMensagemIA: Message = {
|
|
347
|
-
id: `msg-${Date.now()}-ia`,
|
|
348
|
-
type: 'assistant',
|
|
349
|
-
content: '',
|
|
350
|
-
timestamp: new Date(),
|
|
351
|
-
isFavorite: false,
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
if (typeof resposta === 'string') {
|
|
355
|
-
novaMensagemIA.content = resposta;
|
|
356
|
-
} else {
|
|
357
|
-
novaMensagemIA = { ...novaMensagemIA, ...resposta };
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
setMensagens(prev => [...prev, novaMensagemIA]);
|
|
361
|
-
},
|
|
362
|
-
1000 + Math.random() * 1000
|
|
363
|
-
);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
setMensagem('');
|
|
367
|
-
},
|
|
368
|
-
[mensagem, isProcessing, onSendMessage, demoMode, responseGenerator, customResponses]
|
|
369
|
-
);
|
|
370
|
-
|
|
371
|
-
const handleToggleFavorite = useCallback((messageId: string) => {
|
|
372
|
-
setMensagens(prev =>
|
|
373
|
-
prev.map(msg => (msg.id === messageId ? { ...msg, isFavorite: !msg.isFavorite } : msg))
|
|
374
|
-
);
|
|
375
|
-
}, []);
|
|
376
|
-
|
|
377
|
-
const handleCopyMessage = useCallback(async (content: string, messageId: string) => {
|
|
378
|
-
try {
|
|
379
|
-
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
380
|
-
try {
|
|
381
|
-
await navigator.clipboard.writeText(content);
|
|
382
|
-
setCopiedId(messageId);
|
|
383
|
-
setTimeout(() => setCopiedId(null), 2000);
|
|
384
|
-
} catch (clipboardError: any) {
|
|
385
|
-
if (
|
|
386
|
-
clipboardError.name === 'NotAllowedError' ||
|
|
387
|
-
clipboardError.message.includes('permissions policy')
|
|
388
|
-
) {
|
|
389
|
-
throw new Error('Clipboard permission denied, falling back');
|
|
390
|
-
}
|
|
391
|
-
throw clipboardError;
|
|
392
|
-
}
|
|
393
|
-
} else {
|
|
394
|
-
throw new Error('Clipboard API not available');
|
|
395
|
-
}
|
|
396
|
-
} catch {
|
|
397
|
-
try {
|
|
398
|
-
const textArea = document.createElement('textarea');
|
|
399
|
-
textArea.value = content;
|
|
400
|
-
textArea.style.position = 'fixed';
|
|
401
|
-
textArea.style.left = '-999999px';
|
|
402
|
-
textArea.style.top = '-999999px';
|
|
403
|
-
document.body.appendChild(textArea);
|
|
404
|
-
textArea.focus();
|
|
405
|
-
textArea.select();
|
|
406
|
-
const successful = document.execCommand('copy');
|
|
407
|
-
document.body.removeChild(textArea);
|
|
408
|
-
if (successful) {
|
|
409
|
-
setCopiedId(messageId);
|
|
410
|
-
setTimeout(() => setCopiedId(null), 2000);
|
|
411
|
-
}
|
|
412
|
-
} catch (fallbackErr) {
|
|
413
|
-
console.error('Falha ao copiar:', fallbackErr);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
}, []);
|
|
417
|
-
|
|
418
|
-
const handleGeneratePodcast = useCallback(async (messageId: string, content: string) => {
|
|
419
|
-
setGeneratingPodcastId(messageId);
|
|
420
|
-
setTimeout(() => {
|
|
421
|
-
setMensagens(prev =>
|
|
422
|
-
prev.map(msg =>
|
|
423
|
-
msg.id === messageId
|
|
424
|
-
? {
|
|
425
|
-
...msg,
|
|
426
|
-
attachmentType: 'podcast' as const,
|
|
427
|
-
attachmentName: `${t('assistant.podcastName')} - ${content.substring(0, 30)}...`,
|
|
428
|
-
audioUrl: 'data:audio/mpeg;base64,//uQx...',
|
|
429
|
-
}
|
|
430
|
-
: msg
|
|
431
|
-
)
|
|
432
|
-
);
|
|
433
|
-
setGeneratingPodcastId(null);
|
|
434
|
-
}, 2000);
|
|
435
|
-
}, []);
|
|
436
|
-
|
|
437
|
-
const handleDownloadDocument = useCallback((content: string, fileName: string) => {
|
|
438
|
-
const blob = new Blob([content], { type: 'text/markdown' });
|
|
439
|
-
const url = URL.createObjectURL(blob);
|
|
440
|
-
const a = document.createElement('a');
|
|
441
|
-
a.href = url;
|
|
442
|
-
a.download = fileName.endsWith('.md') ? fileName : fileName + '.md';
|
|
443
|
-
document.body.appendChild(a);
|
|
444
|
-
a.click();
|
|
445
|
-
document.body.removeChild(a);
|
|
446
|
-
URL.revokeObjectURL(url);
|
|
447
|
-
}, []);
|
|
448
|
-
|
|
449
|
-
const handleDownloadPodcast = useCallback((audioUrl: string, fileName: string) => {
|
|
450
|
-
const a = document.createElement('a');
|
|
451
|
-
a.href = audioUrl;
|
|
452
|
-
a.download = fileName.endsWith('.mp3') ? fileName : fileName + '.mp3';
|
|
453
|
-
document.body.appendChild(a);
|
|
454
|
-
a.click();
|
|
455
|
-
document.body.removeChild(a);
|
|
456
|
-
}, []);
|
|
457
|
-
|
|
458
|
-
const handleEditDocument = useCallback((content: string, title: string) => {
|
|
459
|
-
setEditingDocument({ content, title });
|
|
460
|
-
}, []);
|
|
461
|
-
|
|
462
|
-
const handleNovaConversa = useCallback(() => {
|
|
463
|
-
setMensagens([]);
|
|
464
|
-
setConversaAtual(null);
|
|
465
|
-
setAbaSelecionada('chat');
|
|
466
|
-
}, []);
|
|
467
|
-
|
|
468
|
-
const handleSelecionarConversa = useCallback(
|
|
469
|
-
(conversaId: string) => {
|
|
470
|
-
const conversa = conversas.find(c => c.id === conversaId);
|
|
471
|
-
if (conversa) {
|
|
472
|
-
setMensagens(conversa.messages);
|
|
473
|
-
setConversaAtual(conversaId);
|
|
474
|
-
setAbaSelecionada('chat');
|
|
475
|
-
}
|
|
476
|
-
},
|
|
477
|
-
[conversas]
|
|
478
|
-
);
|
|
479
|
-
|
|
480
|
-
const handleToggleFavoritaConversa = useCallback((conversaId: string) => {
|
|
481
|
-
setConversas(prev =>
|
|
482
|
-
prev.map(conv => (conv.id === conversaId ? { ...conv, isFavorite: !conv.isFavorite } : conv))
|
|
483
|
-
);
|
|
484
|
-
}, []);
|
|
485
|
-
|
|
486
|
-
const handleOpenSearchResult = useCallback((result: SearchResult) => {
|
|
487
|
-
console.log('Abrir resultado:', result);
|
|
488
|
-
}, []);
|
|
489
|
-
|
|
490
|
-
const handleExecuteSearchCommand = useCallback(
|
|
491
|
-
async (commandId: string, searchTerm: string, results: SearchResult[], messageId: string) => {
|
|
492
|
-
setExecutingCommand(commandId);
|
|
493
|
-
commandTimerRef.current = setTimeout(() => {
|
|
494
|
-
if (commandId === '5') {
|
|
495
|
-
setSavedSearches(prev => [...prev, messageId]);
|
|
496
|
-
}
|
|
497
|
-
setExecutingCommand(null);
|
|
498
|
-
}, 1500);
|
|
499
|
-
},
|
|
500
|
-
[]
|
|
501
|
-
);
|
|
502
|
-
|
|
503
|
-
const handleRichSuggestionClick = useCallback(
|
|
504
|
-
(suggestion: Suggestion) => {
|
|
505
|
-
if (onRichAction) {
|
|
506
|
-
onRichAction(suggestion.id, suggestion.text);
|
|
507
|
-
} else {
|
|
508
|
-
handleEnviarMensagem(suggestion.text);
|
|
509
|
-
}
|
|
510
|
-
setShowMoreSuggestions(false);
|
|
511
|
-
},
|
|
512
|
-
[onRichAction, handleEnviarMensagem]
|
|
513
|
-
);
|
|
514
|
-
|
|
515
|
-
const handleEvaluationClick = useCallback(
|
|
516
|
-
(messageId: string, type: 'like' | 'dislike') => {
|
|
517
|
-
if (type === 'like') {
|
|
518
|
-
if (onEvaluation) onEvaluation(messageId, 'like');
|
|
519
|
-
setMensagens(prev =>
|
|
520
|
-
prev.map(m => (m.id === messageId ? { ...m, evaluation: 'like' as const } : m))
|
|
521
|
-
);
|
|
522
|
-
toast.success(t('assistant.likeToast'));
|
|
523
|
-
}
|
|
524
|
-
},
|
|
525
|
-
[onEvaluation]
|
|
526
|
-
);
|
|
527
|
-
|
|
528
|
-
const openFeedbackDialog = useCallback((messageId: string, category: string | null) => {
|
|
529
|
-
setEvaluationState({
|
|
530
|
-
isOpen: true,
|
|
531
|
-
messageId,
|
|
532
|
-
type: 'dislike',
|
|
533
|
-
category,
|
|
534
|
-
reason: '',
|
|
535
|
-
});
|
|
536
|
-
}, []);
|
|
537
|
-
|
|
538
|
-
const handleSubmitDislike = useCallback(() => {
|
|
539
|
-
if (evaluationState.messageId) {
|
|
540
|
-
const finalReason = evaluationState.category
|
|
541
|
-
? evaluationState.reason
|
|
542
|
-
? `${evaluationState.category}: ${evaluationState.reason}`
|
|
543
|
-
: evaluationState.category
|
|
544
|
-
: evaluationState.reason;
|
|
545
|
-
|
|
546
|
-
if (onEvaluation) {
|
|
547
|
-
onEvaluation(evaluationState.messageId, 'dislike', finalReason);
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
setMensagens(prev =>
|
|
551
|
-
prev.map(m =>
|
|
552
|
-
m.id === evaluationState.messageId
|
|
553
|
-
? { ...m, evaluation: 'dislike' as const, evaluationReason: finalReason }
|
|
554
|
-
: m
|
|
555
|
-
)
|
|
556
|
-
);
|
|
557
|
-
toast.success(t('assistant.feedbackToast'));
|
|
558
|
-
}
|
|
559
|
-
setEvaluationState({ isOpen: false, messageId: null, type: null, category: null, reason: '' });
|
|
560
|
-
}, [evaluationState, onEvaluation]);
|
|
561
|
-
|
|
562
|
-
return {
|
|
563
|
-
// Layout
|
|
564
|
-
isFullPage,
|
|
565
|
-
isExpanded,
|
|
566
|
-
isMobile,
|
|
567
|
-
abaSelecionada,
|
|
568
|
-
setAbaSelecionada,
|
|
569
|
-
// Messages
|
|
570
|
-
mensagens,
|
|
571
|
-
setMensagens,
|
|
572
|
-
mensagem,
|
|
573
|
-
setMensagem,
|
|
574
|
-
// Conversations
|
|
575
|
-
conversas,
|
|
576
|
-
conversaAtual,
|
|
577
|
-
conversasFiltradas,
|
|
578
|
-
// UI
|
|
579
|
-
copiedId,
|
|
580
|
-
generatingPodcastId,
|
|
581
|
-
executingCommand,
|
|
582
|
-
savedSearches,
|
|
583
|
-
editingDocument,
|
|
584
|
-
setEditingDocument,
|
|
585
|
-
showMoreSuggestions,
|
|
586
|
-
setShowMoreSuggestions,
|
|
587
|
-
evaluationState,
|
|
588
|
-
setEvaluationState,
|
|
589
|
-
// Suggestions
|
|
590
|
-
sugestoes,
|
|
591
|
-
// Refs
|
|
592
|
-
messagesEndRef,
|
|
593
|
-
fileInputRef,
|
|
594
|
-
audioInputRef,
|
|
595
|
-
// Handlers
|
|
596
|
-
handleToggle,
|
|
597
|
-
handleExpandWithTab,
|
|
598
|
-
handleEnviarMensagem,
|
|
599
|
-
handleToggleFavorite,
|
|
600
|
-
handleCopyMessage,
|
|
601
|
-
handleGeneratePodcast,
|
|
602
|
-
handleDownloadDocument,
|
|
603
|
-
handleDownloadPodcast,
|
|
604
|
-
handleEditDocument,
|
|
605
|
-
handleNovaConversa,
|
|
606
|
-
handleSelecionarConversa,
|
|
607
|
-
handleToggleFavoritaConversa,
|
|
608
|
-
handleOpenSearchResult,
|
|
609
|
-
handleExecuteSearchCommand,
|
|
610
|
-
handleRichSuggestionClick,
|
|
611
|
-
handleEvaluationClick,
|
|
612
|
-
openFeedbackDialog,
|
|
613
|
-
handleSubmitDislike,
|
|
614
|
-
};
|
|
615
|
-
}
|
|
1
|
+
import { useState, useEffect, useRef, useCallback, useMemo } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import type { ActionType } from '../modern-chat-input/ModernChatInput';
|
|
4
|
+
import { toast } from 'sonner';
|
|
5
|
+
import { gerarResposta } from '../../shared/assistant-utils';
|
|
6
|
+
import { useIsMobile } from '../../shared/use-mobile';
|
|
7
|
+
import type {
|
|
8
|
+
Message,
|
|
9
|
+
Conversation,
|
|
10
|
+
Suggestion,
|
|
11
|
+
AssistantTab,
|
|
12
|
+
AssistantMode,
|
|
13
|
+
SearchResult,
|
|
14
|
+
MockResponse,
|
|
15
|
+
} from './types';
|
|
16
|
+
|
|
17
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
18
|
+
// Hook Props
|
|
19
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
20
|
+
|
|
21
|
+
export interface UseAssistantProps {
|
|
22
|
+
/** Layout mode for the assistant panel */
|
|
23
|
+
mode?: AssistantMode;
|
|
24
|
+
/** Controlled expansion state */
|
|
25
|
+
isExpanded?: boolean;
|
|
26
|
+
/** Toggle callback for controlled expansion */
|
|
27
|
+
onToggle?: () => void;
|
|
28
|
+
/** Initially selected tab */
|
|
29
|
+
defaultTab?: AssistantTab;
|
|
30
|
+
/** Enables demo mode with mock AI responses */
|
|
31
|
+
demoMode?: boolean;
|
|
32
|
+
/** Custom mock responses for demo mode */
|
|
33
|
+
customResponses?: MockResponse[];
|
|
34
|
+
/** Pre-loaded messages to hydrate an existing conversation */
|
|
35
|
+
initialMessages?: Message[];
|
|
36
|
+
/** Previously saved conversations */
|
|
37
|
+
savedConversations?: Conversation[];
|
|
38
|
+
/** Suggested prompts shown in the empty state */
|
|
39
|
+
suggestions?: Suggestion[];
|
|
40
|
+
/** Callback fired when the user sends a message */
|
|
41
|
+
onSendMessage?: (message: string) => void;
|
|
42
|
+
/** Whether the assistant is currently processing a response */
|
|
43
|
+
isProcessing?: boolean;
|
|
44
|
+
/** Custom response generator — overrides demo mode defaults */
|
|
45
|
+
responseGenerator?: (
|
|
46
|
+
message: string
|
|
47
|
+
) => Promise<string | Partial<Message>> | string | Partial<Message>;
|
|
48
|
+
/** Extended suggestions shown when the user clicks "More suggestions" */
|
|
49
|
+
richSuggestions?: Suggestion[];
|
|
50
|
+
/** Callback fired when the user clicks a rich suggestion */
|
|
51
|
+
onRichAction?: (actionId: string, actionText: string) => void;
|
|
52
|
+
/** Callback fired when the user rates a message */
|
|
53
|
+
onEvaluation?: (messageId: string, type: 'like' | 'dislike', reason?: string) => void;
|
|
54
|
+
/** Negative feedback categories shown in the dislike dropdown */
|
|
55
|
+
feedbackOptions?: string[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
59
|
+
// Hook Return Value
|
|
60
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
61
|
+
|
|
62
|
+
export interface UseAssistantReturn {
|
|
63
|
+
// ── Layout state ──────────────────────────────────────────────────────────
|
|
64
|
+
isFullPage: boolean;
|
|
65
|
+
isExpanded: boolean;
|
|
66
|
+
isMobile: boolean;
|
|
67
|
+
abaSelecionada: AssistantTab;
|
|
68
|
+
setAbaSelecionada: (tab: AssistantTab) => void;
|
|
69
|
+
|
|
70
|
+
// ── Message state ─────────────────────────────────────────────────────────
|
|
71
|
+
mensagens: Message[];
|
|
72
|
+
setMensagens: React.Dispatch<React.SetStateAction<Message[]>>;
|
|
73
|
+
mensagem: string;
|
|
74
|
+
setMensagem: (value: string) => void;
|
|
75
|
+
|
|
76
|
+
// ── Conversation state ────────────────────────────────────────────────────
|
|
77
|
+
conversas: Conversation[];
|
|
78
|
+
conversaAtual: string | null;
|
|
79
|
+
conversasFiltradas: Conversation[];
|
|
80
|
+
|
|
81
|
+
// ── UI state ──────────────────────────────────────────────────────────────
|
|
82
|
+
copiedId: string | null;
|
|
83
|
+
generatingPodcastId: string | null;
|
|
84
|
+
executingCommand: string | null;
|
|
85
|
+
savedSearches: string[];
|
|
86
|
+
editingDocument: { content: string; title: string } | null;
|
|
87
|
+
setEditingDocument: (doc: { content: string; title: string } | null) => void;
|
|
88
|
+
showMoreSuggestions: boolean;
|
|
89
|
+
setShowMoreSuggestions: (show: boolean) => void;
|
|
90
|
+
evaluationState: {
|
|
91
|
+
isOpen: boolean;
|
|
92
|
+
messageId: string | null;
|
|
93
|
+
type: 'dislike' | null;
|
|
94
|
+
category?: string | null;
|
|
95
|
+
reason: string;
|
|
96
|
+
};
|
|
97
|
+
setEvaluationState: React.Dispatch<React.SetStateAction<UseAssistantReturn['evaluationState']>>;
|
|
98
|
+
|
|
99
|
+
// ── Suggestions ───────────────────────────────────────────────────────────
|
|
100
|
+
sugestoes: Suggestion[];
|
|
101
|
+
|
|
102
|
+
// ── Refs ──────────────────────────────────────────────────────────────────
|
|
103
|
+
messagesEndRef: React.RefObject<HTMLDivElement>;
|
|
104
|
+
fileInputRef: React.RefObject<HTMLInputElement>;
|
|
105
|
+
audioInputRef: React.RefObject<HTMLInputElement>;
|
|
106
|
+
|
|
107
|
+
// ── Handlers ──────────────────────────────────────────────────────────────
|
|
108
|
+
handleToggle: () => void;
|
|
109
|
+
handleExpandWithTab: (tab: AssistantTab) => void;
|
|
110
|
+
handleEnviarMensagem: (arg?: string | ActionType) => Promise<void>;
|
|
111
|
+
handleToggleFavorite: (messageId: string) => void;
|
|
112
|
+
handleCopyMessage: (content: string, messageId: string) => Promise<void>;
|
|
113
|
+
handleGeneratePodcast: (messageId: string, content: string) => Promise<void>;
|
|
114
|
+
handleDownloadDocument: (content: string, fileName: string) => void;
|
|
115
|
+
handleDownloadPodcast: (audioUrl: string, fileName: string) => void;
|
|
116
|
+
handleEditDocument: (content: string, title: string) => void;
|
|
117
|
+
handleNovaConversa: () => void;
|
|
118
|
+
handleSelecionarConversa: (conversaId: string) => void;
|
|
119
|
+
handleToggleFavoritaConversa: (conversaId: string) => void;
|
|
120
|
+
handleOpenSearchResult: (result: SearchResult) => void;
|
|
121
|
+
handleExecuteSearchCommand: (
|
|
122
|
+
commandId: string,
|
|
123
|
+
searchTerm: string,
|
|
124
|
+
results: SearchResult[],
|
|
125
|
+
messageId: string
|
|
126
|
+
) => Promise<void>;
|
|
127
|
+
handleRichSuggestionClick: (suggestion: Suggestion) => void;
|
|
128
|
+
handleEvaluationClick: (messageId: string, type: 'like' | 'dislike') => void;
|
|
129
|
+
openFeedbackDialog: (messageId: string, category: string | null) => void;
|
|
130
|
+
handleSubmitDislike: () => void;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// DEFAULT_SUGGESTIONS is intentionally NOT defined at module scope.
|
|
134
|
+
// See the `useAssistant` hook below where they are built with `useMemo`
|
|
135
|
+
// so that `t()` is always called inside the React render cycle with the
|
|
136
|
+
// currently active language.
|
|
137
|
+
|
|
138
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
139
|
+
// Hook
|
|
140
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* `useAssistant` — Headless hook for the XerticaAssistant component.
|
|
144
|
+
*
|
|
145
|
+
* Encapsulates all state management and business logic for the AI assistant panel.
|
|
146
|
+
* Use this hook when you need to build a fully custom assistant UI while reusing
|
|
147
|
+
* the same state logic as the default `XerticaAssistant` component.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```tsx
|
|
151
|
+
* import { useAssistant } from 'xertica-ui/assistant';
|
|
152
|
+
*
|
|
153
|
+
* function MyCustomAssistant() {
|
|
154
|
+
* const {
|
|
155
|
+
* mensagens,
|
|
156
|
+
* mensagem,
|
|
157
|
+
* setMensagem,
|
|
158
|
+
* handleEnviarMensagem,
|
|
159
|
+
* isExpanded,
|
|
160
|
+
* handleToggle,
|
|
161
|
+
* } = useAssistant({ demoMode: true });
|
|
162
|
+
*
|
|
163
|
+
* return (
|
|
164
|
+
* <div>
|
|
165
|
+
* {mensagens.map(msg => <p key={msg.id}>{msg.content}</p>)}
|
|
166
|
+
* <input value={mensagem} onChange={e => setMensagem(e.target.value)} />
|
|
167
|
+
* <button onClick={() => handleEnviarMensagem()}>Send</button>
|
|
168
|
+
* </div>
|
|
169
|
+
* );
|
|
170
|
+
* }
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
export function useAssistant({
|
|
174
|
+
mode = 'expanded',
|
|
175
|
+
isExpanded: controlledIsExpanded,
|
|
176
|
+
onToggle,
|
|
177
|
+
defaultTab = 'chat',
|
|
178
|
+
demoMode = true,
|
|
179
|
+
customResponses = [],
|
|
180
|
+
initialMessages = [],
|
|
181
|
+
savedConversations = [],
|
|
182
|
+
suggestions: propSuggestions,
|
|
183
|
+
onSendMessage,
|
|
184
|
+
isProcessing = false,
|
|
185
|
+
responseGenerator,
|
|
186
|
+
richSuggestions = [],
|
|
187
|
+
onRichAction,
|
|
188
|
+
onEvaluation,
|
|
189
|
+
}: UseAssistantProps = {}): UseAssistantReturn {
|
|
190
|
+
const { t } = useTranslation();
|
|
191
|
+
|
|
192
|
+
// ── Layout state ────────────────────────────────────────────────────────────
|
|
193
|
+
const isFullPage = mode === 'fullPage';
|
|
194
|
+
const [internalIsExpanded, setInternalIsExpanded] = useState(controlledIsExpanded ?? true);
|
|
195
|
+
const isExpanded = controlledIsExpanded ?? internalIsExpanded;
|
|
196
|
+
const isMobile = useIsMobile();
|
|
197
|
+
|
|
198
|
+
// ── Tab state ───────────────────────────────────────────────────────────────
|
|
199
|
+
const [abaSelecionada, setAbaSelecionada] = useState<AssistantTab>(defaultTab);
|
|
200
|
+
|
|
201
|
+
// ── Message state ───────────────────────────────────────────────────────────
|
|
202
|
+
const [mensagens, setMensagens] = useState<Message[]>(initialMessages);
|
|
203
|
+
const [mensagem, setMensagem] = useState('');
|
|
204
|
+
|
|
205
|
+
// ── Conversation state ──────────────────────────────────────────────────────
|
|
206
|
+
const [conversas, setConversas] = useState<Conversation[]>(savedConversations);
|
|
207
|
+
const [conversaAtual, setConversaAtual] = useState<string | null>(null);
|
|
208
|
+
|
|
209
|
+
// ── UI state ────────────────────────────────────────────────────────────────
|
|
210
|
+
const [copiedId, setCopiedId] = useState<string | null>(null);
|
|
211
|
+
const [generatingPodcastId, setGeneratingPodcastId] = useState<string | null>(null);
|
|
212
|
+
const [executingCommand, setExecutingCommand] = useState<string | null>(null);
|
|
213
|
+
const [savedSearches, setSavedSearches] = useState<string[]>([]);
|
|
214
|
+
const [editingDocument, setEditingDocument] = useState<{ content: string; title: string } | null>(
|
|
215
|
+
null
|
|
216
|
+
);
|
|
217
|
+
const [showMoreSuggestions, setShowMoreSuggestions] = useState(false);
|
|
218
|
+
const [evaluationState, setEvaluationState] = useState<UseAssistantReturn['evaluationState']>({
|
|
219
|
+
isOpen: false,
|
|
220
|
+
messageId: null,
|
|
221
|
+
type: null,
|
|
222
|
+
category: null,
|
|
223
|
+
reason: '',
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
// ── Refs ────────────────────────────────────────────────────────────────────
|
|
227
|
+
const messagesEndRef = useRef<HTMLDivElement>(null);
|
|
228
|
+
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
229
|
+
const audioInputRef = useRef<HTMLInputElement>(null);
|
|
230
|
+
const responseTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
231
|
+
const commandTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
232
|
+
const hydratedRef = useRef(false);
|
|
233
|
+
|
|
234
|
+
// ── Suggestions ─────────────────────────────────────────────────────────────
|
|
235
|
+
// Built inside useMemo so t() is re-evaluated when language changes.
|
|
236
|
+
const defaultSuggestions = useMemo<Suggestion[]>(
|
|
237
|
+
() => [
|
|
238
|
+
{ id: '1', text: t('assistant.defaultSuggestions.createDocument') },
|
|
239
|
+
{ id: '2', text: t('assistant.defaultSuggestions.searchFiles') },
|
|
240
|
+
{ id: '3', text: t('assistant.defaultSuggestions.summarizeConversations') },
|
|
241
|
+
{ id: '4', text: t('assistant.defaultSuggestions.createPodcast') },
|
|
242
|
+
],
|
|
243
|
+
[t]
|
|
244
|
+
);
|
|
245
|
+
const sugestoes = propSuggestions ?? defaultSuggestions;
|
|
246
|
+
|
|
247
|
+
// ── Effects ─────────────────────────────────────────────────────────────────
|
|
248
|
+
|
|
249
|
+
// Cleanup timers on unmount
|
|
250
|
+
useEffect(() => {
|
|
251
|
+
return () => {
|
|
252
|
+
if (responseTimerRef.current) clearTimeout(responseTimerRef.current);
|
|
253
|
+
if (commandTimerRef.current) clearTimeout(commandTimerRef.current);
|
|
254
|
+
};
|
|
255
|
+
}, []);
|
|
256
|
+
|
|
257
|
+
// Auto-scroll on new messages (condicional ≤ 120px)
|
|
258
|
+
useEffect(() => {
|
|
259
|
+
if (messagesEndRef.current && abaSelecionada === 'chat') {
|
|
260
|
+
const container = messagesEndRef.current.parentElement;
|
|
261
|
+
if (!container) {
|
|
262
|
+
messagesEndRef.current.scrollIntoView({ behavior: 'smooth' });
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const distanceFromBottom =
|
|
266
|
+
container.scrollHeight - container.scrollTop - container.clientHeight;
|
|
267
|
+
if (distanceFromBottom < 120) {
|
|
268
|
+
messagesEndRef.current.scrollIntoView({ behavior: 'smooth' });
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}, [mensagens, abaSelecionada]);
|
|
272
|
+
|
|
273
|
+
// Sync initial messages when they change (one-shot hydration)
|
|
274
|
+
useEffect(() => {
|
|
275
|
+
if (!hydratedRef.current && initialMessages && initialMessages.length > 0) {
|
|
276
|
+
setMensagens(initialMessages);
|
|
277
|
+
hydratedRef.current = true;
|
|
278
|
+
}
|
|
279
|
+
}, [initialMessages]);
|
|
280
|
+
|
|
281
|
+
// ── Computed ────────────────────────────────────────────────────────────────
|
|
282
|
+
|
|
283
|
+
const conversasFiltradas = useMemo(
|
|
284
|
+
() => conversas.filter(c => (abaSelecionada === 'favoritos' ? c.isFavorite : true)),
|
|
285
|
+
[conversas, abaSelecionada]
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
// ── Handlers ────────────────────────────────────────────────────────────────
|
|
289
|
+
|
|
290
|
+
const handleToggle = useCallback(() => {
|
|
291
|
+
if (onToggle) {
|
|
292
|
+
onToggle();
|
|
293
|
+
} else {
|
|
294
|
+
setInternalIsExpanded(prev => !prev);
|
|
295
|
+
}
|
|
296
|
+
}, [onToggle]);
|
|
297
|
+
|
|
298
|
+
const handleExpandWithTab = useCallback(
|
|
299
|
+
(tab: AssistantTab) => {
|
|
300
|
+
setAbaSelecionada(tab);
|
|
301
|
+
if (onToggle) {
|
|
302
|
+
onToggle();
|
|
303
|
+
} else {
|
|
304
|
+
setInternalIsExpanded(true);
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
[onToggle]
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
const handleEnviarMensagem = useCallback(
|
|
311
|
+
async (arg?: string | ActionType) => {
|
|
312
|
+
let msgToSend = mensagem;
|
|
313
|
+
|
|
314
|
+
if (typeof arg === 'string' && !['document', 'podcast', 'search'].includes(arg)) {
|
|
315
|
+
msgToSend = arg;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (!msgToSend.trim() || isProcessing) return;
|
|
319
|
+
|
|
320
|
+
const novaMensagem: Message = {
|
|
321
|
+
id: `msg-${Date.now()}`,
|
|
322
|
+
type: 'user',
|
|
323
|
+
content: msgToSend,
|
|
324
|
+
timestamp: new Date(),
|
|
325
|
+
isFavorite: false,
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
setMensagens(prev => [...prev, novaMensagem]);
|
|
329
|
+
|
|
330
|
+
if (onSendMessage) {
|
|
331
|
+
onSendMessage(msgToSend);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (demoMode || responseGenerator) {
|
|
335
|
+
const mensagemAtual = msgToSend;
|
|
336
|
+
responseTimerRef.current = setTimeout(
|
|
337
|
+
async () => {
|
|
338
|
+
let resposta: string | Partial<Message>;
|
|
339
|
+
|
|
340
|
+
if (responseGenerator) {
|
|
341
|
+
resposta = await responseGenerator(mensagemAtual);
|
|
342
|
+
} else {
|
|
343
|
+
resposta = gerarResposta(mensagemAtual, customResponses);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
let novaMensagemIA: Message = {
|
|
347
|
+
id: `msg-${Date.now()}-ia`,
|
|
348
|
+
type: 'assistant',
|
|
349
|
+
content: '',
|
|
350
|
+
timestamp: new Date(),
|
|
351
|
+
isFavorite: false,
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
if (typeof resposta === 'string') {
|
|
355
|
+
novaMensagemIA.content = resposta;
|
|
356
|
+
} else {
|
|
357
|
+
novaMensagemIA = { ...novaMensagemIA, ...resposta };
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
setMensagens(prev => [...prev, novaMensagemIA]);
|
|
361
|
+
},
|
|
362
|
+
1000 + Math.random() * 1000
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
setMensagem('');
|
|
367
|
+
},
|
|
368
|
+
[mensagem, isProcessing, onSendMessage, demoMode, responseGenerator, customResponses]
|
|
369
|
+
);
|
|
370
|
+
|
|
371
|
+
const handleToggleFavorite = useCallback((messageId: string) => {
|
|
372
|
+
setMensagens(prev =>
|
|
373
|
+
prev.map(msg => (msg.id === messageId ? { ...msg, isFavorite: !msg.isFavorite } : msg))
|
|
374
|
+
);
|
|
375
|
+
}, []);
|
|
376
|
+
|
|
377
|
+
const handleCopyMessage = useCallback(async (content: string, messageId: string) => {
|
|
378
|
+
try {
|
|
379
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
380
|
+
try {
|
|
381
|
+
await navigator.clipboard.writeText(content);
|
|
382
|
+
setCopiedId(messageId);
|
|
383
|
+
setTimeout(() => setCopiedId(null), 2000);
|
|
384
|
+
} catch (clipboardError: any) {
|
|
385
|
+
if (
|
|
386
|
+
clipboardError.name === 'NotAllowedError' ||
|
|
387
|
+
clipboardError.message.includes('permissions policy')
|
|
388
|
+
) {
|
|
389
|
+
throw new Error('Clipboard permission denied, falling back');
|
|
390
|
+
}
|
|
391
|
+
throw clipboardError;
|
|
392
|
+
}
|
|
393
|
+
} else {
|
|
394
|
+
throw new Error('Clipboard API not available');
|
|
395
|
+
}
|
|
396
|
+
} catch {
|
|
397
|
+
try {
|
|
398
|
+
const textArea = document.createElement('textarea');
|
|
399
|
+
textArea.value = content;
|
|
400
|
+
textArea.style.position = 'fixed';
|
|
401
|
+
textArea.style.left = '-999999px';
|
|
402
|
+
textArea.style.top = '-999999px';
|
|
403
|
+
document.body.appendChild(textArea);
|
|
404
|
+
textArea.focus();
|
|
405
|
+
textArea.select();
|
|
406
|
+
const successful = document.execCommand('copy');
|
|
407
|
+
document.body.removeChild(textArea);
|
|
408
|
+
if (successful) {
|
|
409
|
+
setCopiedId(messageId);
|
|
410
|
+
setTimeout(() => setCopiedId(null), 2000);
|
|
411
|
+
}
|
|
412
|
+
} catch (fallbackErr) {
|
|
413
|
+
console.error('Falha ao copiar:', fallbackErr);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}, []);
|
|
417
|
+
|
|
418
|
+
const handleGeneratePodcast = useCallback(async (messageId: string, content: string) => {
|
|
419
|
+
setGeneratingPodcastId(messageId);
|
|
420
|
+
setTimeout(() => {
|
|
421
|
+
setMensagens(prev =>
|
|
422
|
+
prev.map(msg =>
|
|
423
|
+
msg.id === messageId
|
|
424
|
+
? {
|
|
425
|
+
...msg,
|
|
426
|
+
attachmentType: 'podcast' as const,
|
|
427
|
+
attachmentName: `${t('assistant.podcastName')} - ${content.substring(0, 30)}...`,
|
|
428
|
+
audioUrl: 'data:audio/mpeg;base64,//uQx...',
|
|
429
|
+
}
|
|
430
|
+
: msg
|
|
431
|
+
)
|
|
432
|
+
);
|
|
433
|
+
setGeneratingPodcastId(null);
|
|
434
|
+
}, 2000);
|
|
435
|
+
}, []);
|
|
436
|
+
|
|
437
|
+
const handleDownloadDocument = useCallback((content: string, fileName: string) => {
|
|
438
|
+
const blob = new Blob([content], { type: 'text/markdown' });
|
|
439
|
+
const url = URL.createObjectURL(blob);
|
|
440
|
+
const a = document.createElement('a');
|
|
441
|
+
a.href = url;
|
|
442
|
+
a.download = fileName.endsWith('.md') ? fileName : fileName + '.md';
|
|
443
|
+
document.body.appendChild(a);
|
|
444
|
+
a.click();
|
|
445
|
+
document.body.removeChild(a);
|
|
446
|
+
URL.revokeObjectURL(url);
|
|
447
|
+
}, []);
|
|
448
|
+
|
|
449
|
+
const handleDownloadPodcast = useCallback((audioUrl: string, fileName: string) => {
|
|
450
|
+
const a = document.createElement('a');
|
|
451
|
+
a.href = audioUrl;
|
|
452
|
+
a.download = fileName.endsWith('.mp3') ? fileName : fileName + '.mp3';
|
|
453
|
+
document.body.appendChild(a);
|
|
454
|
+
a.click();
|
|
455
|
+
document.body.removeChild(a);
|
|
456
|
+
}, []);
|
|
457
|
+
|
|
458
|
+
const handleEditDocument = useCallback((content: string, title: string) => {
|
|
459
|
+
setEditingDocument({ content, title });
|
|
460
|
+
}, []);
|
|
461
|
+
|
|
462
|
+
const handleNovaConversa = useCallback(() => {
|
|
463
|
+
setMensagens([]);
|
|
464
|
+
setConversaAtual(null);
|
|
465
|
+
setAbaSelecionada('chat');
|
|
466
|
+
}, []);
|
|
467
|
+
|
|
468
|
+
const handleSelecionarConversa = useCallback(
|
|
469
|
+
(conversaId: string) => {
|
|
470
|
+
const conversa = conversas.find(c => c.id === conversaId);
|
|
471
|
+
if (conversa) {
|
|
472
|
+
setMensagens(conversa.messages);
|
|
473
|
+
setConversaAtual(conversaId);
|
|
474
|
+
setAbaSelecionada('chat');
|
|
475
|
+
}
|
|
476
|
+
},
|
|
477
|
+
[conversas]
|
|
478
|
+
);
|
|
479
|
+
|
|
480
|
+
const handleToggleFavoritaConversa = useCallback((conversaId: string) => {
|
|
481
|
+
setConversas(prev =>
|
|
482
|
+
prev.map(conv => (conv.id === conversaId ? { ...conv, isFavorite: !conv.isFavorite } : conv))
|
|
483
|
+
);
|
|
484
|
+
}, []);
|
|
485
|
+
|
|
486
|
+
const handleOpenSearchResult = useCallback((result: SearchResult) => {
|
|
487
|
+
console.log('Abrir resultado:', result);
|
|
488
|
+
}, []);
|
|
489
|
+
|
|
490
|
+
const handleExecuteSearchCommand = useCallback(
|
|
491
|
+
async (commandId: string, searchTerm: string, results: SearchResult[], messageId: string) => {
|
|
492
|
+
setExecutingCommand(commandId);
|
|
493
|
+
commandTimerRef.current = setTimeout(() => {
|
|
494
|
+
if (commandId === '5') {
|
|
495
|
+
setSavedSearches(prev => [...prev, messageId]);
|
|
496
|
+
}
|
|
497
|
+
setExecutingCommand(null);
|
|
498
|
+
}, 1500);
|
|
499
|
+
},
|
|
500
|
+
[]
|
|
501
|
+
);
|
|
502
|
+
|
|
503
|
+
const handleRichSuggestionClick = useCallback(
|
|
504
|
+
(suggestion: Suggestion) => {
|
|
505
|
+
if (onRichAction) {
|
|
506
|
+
onRichAction(suggestion.id, suggestion.text);
|
|
507
|
+
} else {
|
|
508
|
+
handleEnviarMensagem(suggestion.text);
|
|
509
|
+
}
|
|
510
|
+
setShowMoreSuggestions(false);
|
|
511
|
+
},
|
|
512
|
+
[onRichAction, handleEnviarMensagem]
|
|
513
|
+
);
|
|
514
|
+
|
|
515
|
+
const handleEvaluationClick = useCallback(
|
|
516
|
+
(messageId: string, type: 'like' | 'dislike') => {
|
|
517
|
+
if (type === 'like') {
|
|
518
|
+
if (onEvaluation) onEvaluation(messageId, 'like');
|
|
519
|
+
setMensagens(prev =>
|
|
520
|
+
prev.map(m => (m.id === messageId ? { ...m, evaluation: 'like' as const } : m))
|
|
521
|
+
);
|
|
522
|
+
toast.success(t('assistant.likeToast'));
|
|
523
|
+
}
|
|
524
|
+
},
|
|
525
|
+
[onEvaluation]
|
|
526
|
+
);
|
|
527
|
+
|
|
528
|
+
const openFeedbackDialog = useCallback((messageId: string, category: string | null) => {
|
|
529
|
+
setEvaluationState({
|
|
530
|
+
isOpen: true,
|
|
531
|
+
messageId,
|
|
532
|
+
type: 'dislike',
|
|
533
|
+
category,
|
|
534
|
+
reason: '',
|
|
535
|
+
});
|
|
536
|
+
}, []);
|
|
537
|
+
|
|
538
|
+
const handleSubmitDislike = useCallback(() => {
|
|
539
|
+
if (evaluationState.messageId) {
|
|
540
|
+
const finalReason = evaluationState.category
|
|
541
|
+
? evaluationState.reason
|
|
542
|
+
? `${evaluationState.category}: ${evaluationState.reason}`
|
|
543
|
+
: evaluationState.category
|
|
544
|
+
: evaluationState.reason;
|
|
545
|
+
|
|
546
|
+
if (onEvaluation) {
|
|
547
|
+
onEvaluation(evaluationState.messageId, 'dislike', finalReason);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
setMensagens(prev =>
|
|
551
|
+
prev.map(m =>
|
|
552
|
+
m.id === evaluationState.messageId
|
|
553
|
+
? { ...m, evaluation: 'dislike' as const, evaluationReason: finalReason }
|
|
554
|
+
: m
|
|
555
|
+
)
|
|
556
|
+
);
|
|
557
|
+
toast.success(t('assistant.feedbackToast'));
|
|
558
|
+
}
|
|
559
|
+
setEvaluationState({ isOpen: false, messageId: null, type: null, category: null, reason: '' });
|
|
560
|
+
}, [evaluationState, onEvaluation]);
|
|
561
|
+
|
|
562
|
+
return {
|
|
563
|
+
// Layout
|
|
564
|
+
isFullPage,
|
|
565
|
+
isExpanded,
|
|
566
|
+
isMobile,
|
|
567
|
+
abaSelecionada,
|
|
568
|
+
setAbaSelecionada,
|
|
569
|
+
// Messages
|
|
570
|
+
mensagens,
|
|
571
|
+
setMensagens,
|
|
572
|
+
mensagem,
|
|
573
|
+
setMensagem,
|
|
574
|
+
// Conversations
|
|
575
|
+
conversas,
|
|
576
|
+
conversaAtual,
|
|
577
|
+
conversasFiltradas,
|
|
578
|
+
// UI
|
|
579
|
+
copiedId,
|
|
580
|
+
generatingPodcastId,
|
|
581
|
+
executingCommand,
|
|
582
|
+
savedSearches,
|
|
583
|
+
editingDocument,
|
|
584
|
+
setEditingDocument,
|
|
585
|
+
showMoreSuggestions,
|
|
586
|
+
setShowMoreSuggestions,
|
|
587
|
+
evaluationState,
|
|
588
|
+
setEvaluationState,
|
|
589
|
+
// Suggestions
|
|
590
|
+
sugestoes,
|
|
591
|
+
// Refs
|
|
592
|
+
messagesEndRef,
|
|
593
|
+
fileInputRef,
|
|
594
|
+
audioInputRef,
|
|
595
|
+
// Handlers
|
|
596
|
+
handleToggle,
|
|
597
|
+
handleExpandWithTab,
|
|
598
|
+
handleEnviarMensagem,
|
|
599
|
+
handleToggleFavorite,
|
|
600
|
+
handleCopyMessage,
|
|
601
|
+
handleGeneratePodcast,
|
|
602
|
+
handleDownloadDocument,
|
|
603
|
+
handleDownloadPodcast,
|
|
604
|
+
handleEditDocument,
|
|
605
|
+
handleNovaConversa,
|
|
606
|
+
handleSelecionarConversa,
|
|
607
|
+
handleToggleFavoritaConversa,
|
|
608
|
+
handleOpenSearchResult,
|
|
609
|
+
handleExecuteSearchCommand,
|
|
610
|
+
handleRichSuggestionClick,
|
|
611
|
+
handleEvaluationClick,
|
|
612
|
+
openFeedbackDialog,
|
|
613
|
+
handleSubmitDislike,
|
|
614
|
+
};
|
|
615
|
+
}
|