libre-webui 0.38.0 → 0.40.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.md +1 -0
- package/backend/dist/persistence/extensionTypes.d.ts +2 -0
- package/backend/dist/persistence/extensionTypes.d.ts.map +1 -1
- package/backend/dist/persistence/extensionTypes.js.map +1 -1
- package/backend/dist/persistence/postgresExtensionRepositories.d.ts.map +1 -1
- package/backend/dist/persistence/postgresExtensionRepositories.js +6 -0
- package/backend/dist/persistence/postgresExtensionRepositories.js.map +1 -1
- package/backend/dist/persistence/postgresMigrationRegistry.d.ts.map +1 -1
- package/backend/dist/persistence/postgresMigrationRegistry.js +2 -0
- package/backend/dist/persistence/postgresMigrationRegistry.js.map +1 -1
- package/backend/dist/persistence/postgresWorkRunThinkMigration.d.ts +9 -0
- package/backend/dist/persistence/postgresWorkRunThinkMigration.d.ts.map +1 -0
- package/backend/dist/persistence/postgresWorkRunThinkMigration.js +39 -0
- package/backend/dist/persistence/postgresWorkRunThinkMigration.js.map +1 -0
- package/backend/dist/persistence/sqliteExtensionRepositories.d.ts.map +1 -1
- package/backend/dist/persistence/sqliteExtensionRepositories.js +7 -0
- package/backend/dist/persistence/sqliteExtensionRepositories.js.map +1 -1
- package/backend/dist/persistence/sqliteMigrations.d.ts.map +1 -1
- package/backend/dist/persistence/sqliteMigrations.js +20 -0
- package/backend/dist/persistence/sqliteMigrations.js.map +1 -1
- package/backend/dist/persistence/sqliteToPostgresMigration.d.ts.map +1 -1
- package/backend/dist/persistence/sqliteToPostgresMigration.js +1 -0
- package/backend/dist/persistence/sqliteToPostgresMigration.js.map +1 -1
- package/backend/dist/platform/workPersistence/postgresWorkPersistence.d.ts.map +1 -1
- package/backend/dist/platform/workPersistence/postgresWorkPersistence.js +3 -2
- package/backend/dist/platform/workPersistence/postgresWorkPersistence.js.map +1 -1
- package/backend/dist/platform/workPersistence/sqliteWorkPersistence.d.ts.map +1 -1
- package/backend/dist/platform/workPersistence/sqliteWorkPersistence.js +3 -3
- package/backend/dist/platform/workPersistence/sqliteWorkPersistence.js.map +1 -1
- package/backend/dist/platform/workPersistence/types.d.ts +5 -0
- package/backend/dist/platform/workPersistence/types.d.ts.map +1 -1
- package/backend/dist/platform/workPersistence/types.js.map +1 -1
- package/backend/dist/routes/email.d.ts.map +1 -1
- package/backend/dist/routes/email.js +51 -1
- package/backend/dist/routes/email.js.map +1 -1
- package/backend/dist/routes/tts.d.ts.map +1 -1
- package/backend/dist/routes/tts.js +6 -1
- package/backend/dist/routes/tts.js.map +1 -1
- package/backend/dist/routes/work.d.ts.map +1 -1
- package/backend/dist/routes/work.js +17 -2
- package/backend/dist/routes/work.js.map +1 -1
- package/backend/dist/services/agentCliService.d.ts.map +1 -1
- package/backend/dist/services/agentCliService.js +2 -0
- package/backend/dist/services/agentCliService.js.map +1 -1
- package/backend/dist/services/emailService.d.ts +17 -3
- package/backend/dist/services/emailService.d.ts.map +1 -1
- package/backend/dist/services/emailService.js +73 -11
- package/backend/dist/services/emailService.js.map +1 -1
- package/backend/dist/services/followUpService.d.ts +4 -1
- package/backend/dist/services/followUpService.d.ts.map +1 -1
- package/backend/dist/services/followUpService.js +23 -2
- package/backend/dist/services/followUpService.js.map +1 -1
- package/backend/dist/services/pluginCredentialsService.d.ts +3 -0
- package/backend/dist/services/pluginCredentialsService.d.ts.map +1 -1
- package/backend/dist/services/pluginCredentialsService.js +18 -5
- package/backend/dist/services/pluginCredentialsService.js.map +1 -1
- package/backend/dist/services/pluginService.d.ts +9 -0
- package/backend/dist/services/pluginService.d.ts.map +1 -1
- package/backend/dist/services/pluginService.js +41 -20
- package/backend/dist/services/pluginService.js.map +1 -1
- package/backend/dist/services/workAgentService.d.ts.map +1 -1
- package/backend/dist/services/workAgentService.js +3 -0
- package/backend/dist/services/workAgentService.js.map +1 -1
- package/backend/dist/services/workModelProviderService.d.ts.map +1 -1
- package/backend/dist/services/workModelProviderService.js +43 -13
- package/backend/dist/services/workModelProviderService.js.map +1 -1
- package/backend/dist/services/workRuntimeService.d.ts +5 -0
- package/backend/dist/services/workRuntimeService.d.ts.map +1 -1
- package/backend/dist/services/workRuntimeService.js +243 -84
- package/backend/dist/services/workRuntimeService.js.map +1 -1
- package/backend/dist/services/workTaskService.d.ts +3 -2
- package/backend/dist/services/workTaskService.d.ts.map +1 -1
- package/backend/dist/services/workTaskService.js +10 -6
- package/backend/dist/services/workTaskService.js.map +1 -1
- package/backend/dist/types/work.d.ts +3 -0
- package/backend/dist/types/work.d.ts.map +1 -1
- package/backend/dist/types/work.js.map +1 -1
- package/backend/dist/utils/bedrockMantle.d.ts +46 -0
- package/backend/dist/utils/bedrockMantle.d.ts.map +1 -0
- package/backend/dist/utils/bedrockMantle.js +206 -0
- package/backend/dist/utils/bedrockMantle.js.map +1 -0
- package/backend/dist/utils/emailMarkdown.js +3 -3
- package/backend/dist/utils/emailMarkdown.js.map +1 -1
- package/backend/dist/utils/pluginChatAdapter.d.ts +36 -0
- package/backend/dist/utils/pluginChatAdapter.d.ts.map +1 -1
- package/backend/dist/utils/pluginChatAdapter.js +122 -47
- package/backend/dist/utils/pluginChatAdapter.js.map +1 -1
- package/backend/dist/utils/pluginDefinitionTrust.d.ts +7 -0
- package/backend/dist/utils/pluginDefinitionTrust.d.ts.map +1 -1
- package/backend/dist/utils/pluginDefinitionTrust.js +52 -3
- package/backend/dist/utils/pluginDefinitionTrust.js.map +1 -1
- package/backend/dist/utils/pluginValidation.d.ts +1 -1
- package/backend/dist/utils/pluginValidation.d.ts.map +1 -1
- package/backend/dist/utils/pluginValidation.js +11 -0
- package/backend/dist/utils/pluginValidation.js.map +1 -1
- package/backend/package.json +3 -3
- package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
- package/frontend/dist/artifact-runtime/babel.js +170 -170
- package/frontend/dist/artifact-runtime/framer-motion.js +3 -3
- package/frontend/dist/artifact-runtime/lucide-react.js +1 -1
- package/frontend/dist/artifact-runtime/mathjs.js +1 -1
- package/frontend/dist/artifact-runtime/mermaid.js +366 -366
- package/frontend/dist/artifact-runtime/plotly.js +1 -1
- package/frontend/dist/artifact-runtime/react.js +3 -3
- package/frontend/dist/assets/index-DLfU_qNT.js +75 -0
- package/frontend/dist/assets/index-DtS3qhdq.css +2 -0
- package/frontend/dist/assets/{markdown-math-D1Bj3pDB.css → markdown-math-DzFXvcrH.css} +1 -1
- package/frontend/dist/assets/xterm-B1njb2Cr.css +1 -0
- package/frontend/dist/index.html +36 -35
- package/frontend/dist/js/ArtifactContainer-BjzltfdU.js +1 -0
- package/frontend/dist/js/{ArtifactDemoPage-CCh7lQEw.js → ArtifactDemoPage-DWua6xj9.js} +1 -1
- package/frontend/dist/js/{ArtifactSandboxFrame-D1ntMsqe.js → ArtifactSandboxFrame-CR9ghP0A.js} +1 -1
- package/frontend/dist/js/ArtifactSlideOutPanel-DX2nL3AS.js +1 -0
- package/frontend/dist/js/AutomationModal-DZe-C2jN.js +1 -0
- package/frontend/dist/js/AutomationsPage-CrCcnTyk.js +1 -0
- package/frontend/dist/js/AvatarUpload-nPS0QHod.js +1 -0
- package/frontend/dist/js/Button-Dh2UJA-B.js +1 -0
- package/frontend/dist/js/CalendarPage-D2WiWglM.js +1 -0
- package/frontend/dist/js/ChannelsPage-COp2T8FQ.js +1 -0
- package/frontend/dist/js/ChatPage-CUfAlpdt.js +14 -0
- package/frontend/dist/js/ConnectModels-emc3dv4A.js +1 -0
- package/frontend/dist/js/EvaluationsPage-CbyeDkz_.js +2 -0
- package/frontend/dist/js/FirstTimeSetup-C4ffQRMN.js +1 -0
- package/frontend/dist/js/GalleryPage-D4Ci_3dv.js +1 -0
- package/frontend/dist/js/HomePage-C3IhEERN.js +1 -0
- package/frontend/dist/js/LanguageSwitcher-BQqDJPwm.js +1 -0
- package/frontend/dist/js/{Logo-D1o5k_wt.js → Logo-DnfVtjgj.js} +1 -1
- package/frontend/dist/js/{LogoMark-lnmc98jv.js → LogoMark-BzObGdA9.js} +1 -1
- package/frontend/dist/js/ModelManagerModals-DhY8Rme6.js +1 -0
- package/frontend/dist/js/NotesPage-j812I1BN.js +3 -0
- package/frontend/dist/js/{OptimizedSyntaxHighlighter-CzzV6ONG.js → OptimizedSyntaxHighlighter-B0g8cxZQ.js} +1 -1
- package/frontend/dist/js/OptimizedSyntaxHighlighter-B_BbHeO1.js +1 -0
- package/frontend/dist/js/PasswordStrengthMeter-BSEtQBJp.js +1 -0
- package/frontend/dist/js/PersonasPage--YWoThqF.js +13 -0
- package/frontend/dist/js/PluginUsagePage-CZiMdmjI.js +1 -0
- package/frontend/dist/js/{RichMessageContent-OGBLO64L.js → RichMessageContent-BLI0hhzR.js} +3 -3
- package/frontend/dist/js/RichMessageContent-BXv5baJ_.js +1 -0
- package/frontend/dist/js/SettingsModal-C6aVzSI-.js +19 -0
- package/frontend/dist/js/SettingsToggle-CkLLtFbz.js +1 -0
- package/frontend/dist/js/ShareDialog-DQskc17d.js +1 -0
- package/frontend/dist/js/StrandsPage-DENhVKcz.js +1 -0
- package/frontend/dist/js/SystemPage-C86ypXG4.js +1 -0
- package/frontend/dist/js/{TurnstileWidget-CVepEMEQ.js → TurnstileWidget-tI50c7Kc.js} +1 -1
- package/frontend/dist/js/{UserManagementPage-2yHv89ZA.js → UserManagementPage-UvPjA9RP.js} +1 -1
- package/frontend/dist/js/UserManagementPanel-D1CS0KPn.js +1 -0
- package/frontend/dist/js/WhatsNewModal-B31A_UQY.js +1 -0
- package/frontend/dist/js/WorkPage-DEXBL5J7.js +7 -0
- package/frontend/dist/js/api-DRAKhdz7.js +1 -0
- package/frontend/dist/js/{api-CnJYEbRz.js → api-Dcz1G4Ib.js} +4 -2
- package/frontend/dist/js/{appNavigation-BXNRwrN-.js → appNavigation-C5A9BF_G.js} +1 -1
- package/frontend/dist/js/appStore-0_qlwS8f.js +2 -0
- package/frontend/dist/js/appVersion-D5lk_2zb.js +1 -0
- package/frontend/dist/js/ar-BZntyucf.js +2 -0
- package/frontend/dist/js/authStore-C4dzH1NY.js +1 -0
- package/frontend/dist/js/{authStore-DwaPsICv.js → authStore-COgKeTRv.js} +3 -3
- package/frontend/dist/js/bn-BDCaFQu-.js +2 -0
- package/frontend/dist/js/chatStore-CVTbkZyb.js +3 -0
- package/frontend/dist/js/{client-DQy1iGRM.js → client-jaxZzn-I.js} +2 -2
- package/frontend/dist/js/{composerStyles-C83jssgZ.js → composerStyles-BEx0XAp6.js} +1 -1
- package/frontend/dist/js/{config-BbrsmDn2.js → config-Da1yh9sC.js} +1 -1
- package/frontend/dist/js/confirmStore-CKkUtP9c.js +1 -0
- package/frontend/dist/js/cs-BCmN--jQ.js +2 -0
- package/frontend/dist/js/da-B895dAyV.js +2 -0
- package/frontend/dist/js/de-B0ZhC0dm.js +2 -0
- package/frontend/dist/js/es-D7eaw4_W.js +2 -0
- package/frontend/dist/js/{evaluationsApi-KVsH7yXe.js → evaluationsApi-BwaxBVpl.js} +1 -1
- package/frontend/dist/js/fr-DsB0gLW4.js +2 -0
- package/frontend/dist/js/hi-CLeU3ung.js +2 -0
- package/frontend/dist/js/id-Cdq6tOTi.js +2 -0
- package/frontend/dist/js/is-DJ1tHaAT.js +2 -0
- package/frontend/dist/js/it-9K1R4CeT.js +2 -0
- package/frontend/dist/js/ja-BYP_3M5M.js +2 -0
- package/frontend/dist/js/ko-CNtjlaDm.js +2 -0
- package/frontend/dist/js/liveAnnouncerStore-B6mS-JWC.js +1 -0
- package/frontend/dist/js/{markdown-CZ1tYEW8.js → markdown-DU84620G.js} +1 -1
- package/frontend/dist/js/{markdown-core-KjS96SYW.js → markdown-core-Cyql92Hg.js} +1 -1
- package/frontend/dist/js/{markdown-html-DQEwrWcf.js → markdown-html-CUc2fCgY.js} +1 -1
- package/frontend/dist/js/{markdown-math-CKi32S5d.js → markdown-math-DxPfMKvO.js} +1 -1
- package/frontend/dist/js/{markdownHtml-lrXhxBhK.js → markdownHtml-KhS0cFNH.js} +1 -1
- package/frontend/dist/js/markdownMath-CsfRQAcz.js +1 -0
- package/frontend/dist/js/messageCodeStyles-D3cWF9XO.js +2 -0
- package/frontend/dist/js/ms-A_IVO_qt.js +2 -0
- package/frontend/dist/js/nl-CrKWO3ea.js +2 -0
- package/frontend/dist/js/pl-BrpSuyDP.js +2 -0
- package/frontend/dist/js/pt-BHbpB5BM.js +2 -0
- package/frontend/dist/js/react-vendor-CR5VJ85Q.js +9 -0
- package/frontend/dist/js/{router-vendor-HZm4FR0A.js → router-vendor-DqMnEJWK.js} +1 -1
- package/frontend/dist/js/ru-DzLsS9zY.js +2 -0
- package/frontend/dist/js/{standalone-DbyFjvTU.js → standalone-D_lg5NC9.js} +1 -1
- package/frontend/dist/js/{strandsApi-SeoX_IsY.js → strandsApi-COxSPh_5.js} +1 -1
- package/frontend/dist/js/sv-VU2CjzNj.js +2 -0
- package/frontend/dist/js/{syntax-highlight-DNc3FFCa.js → syntax-highlight-D7dQ5s5-.js} +1 -1
- package/frontend/dist/js/{teamEventStream-CZYdpbVw.js → teamEventStream-RNJYm84u.js} +1 -1
- package/frontend/dist/js/th-DV2hNXXc.js +2 -0
- package/frontend/dist/js/tr-DvVZ9jxF.js +2 -0
- package/frontend/dist/js/ui-CI0OdG9q.js +2 -0
- package/frontend/dist/js/ui-vendor-6S05F84J.js +1 -0
- package/frontend/dist/js/uk-MFFDRo2m.js +2 -0
- package/frontend/dist/js/useChat-BSkqxHnH.js +13 -0
- package/frontend/dist/js/{useDialogFocus-DbW0oA9H.js → useDialogFocus-zSGHkpE4.js} +1 -1
- package/frontend/dist/js/useDictation-D9whH12W.js +1 -0
- package/frontend/dist/js/{useQuery-hWmQjdLu.js → useQuery-BTKpXudI.js} +1 -1
- package/frontend/dist/js/{useTranslation-UHEMTEHd.js → useTranslation-Boi0fB1B.js} +1 -1
- package/frontend/dist/js/{utils-DaXuqmQm.js → utils-B-Bhh1pF.js} +1 -1
- package/frontend/dist/js/{utils-vendor-CvhktdS_.js → utils-vendor-DPJG-EG_.js} +1 -1
- package/frontend/dist/js/vi-CfZ-U8Cw.js +2 -0
- package/frontend/dist/js/{work-CdbmBok5.js → work-C7MYlv5S.js} +1 -1
- package/frontend/dist/js/{workModels-BM2Zyiba.js → workAnnouncements-CAsI8P7c.js} +1 -1
- package/frontend/dist/js/workApi-BJfbaV6k.js +1 -0
- package/frontend/dist/js/{workApi-BqkCbCLQ.js → workApi-Ck8nTlJn.js} +1 -1
- package/frontend/dist/js/zh-CTl_raYa.js +2 -0
- package/package.json +5 -4
- package/plugins/anthropic.json +3 -1
- package/plugins/bedrock.json +86 -0
- package/plugins/codex-oauth.json +1 -0
- package/plugins/openrouter.json +2 -0
- package/frontend/dist/assets/index-CJHJxwjA.js +0 -68
- package/frontend/dist/assets/index-DSHdOZRK.css +0 -1
- package/frontend/dist/assets/xterm-B8QFf3JU.css +0 -1
- package/frontend/dist/js/ArtifactContainer-BWTN4QSW.js +0 -1
- package/frontend/dist/js/ArtifactSlideOutPanel-zPEBPoMh.js +0 -1
- package/frontend/dist/js/AutomationModal-DN98Eyym.js +0 -1
- package/frontend/dist/js/AutomationsPage-3DBwRKME.js +0 -1
- package/frontend/dist/js/AvatarUpload-D5_wGUb5.js +0 -1
- package/frontend/dist/js/Button-CTwi9N3d.js +0 -1
- package/frontend/dist/js/CalendarPage-CUbGH3Tl.js +0 -1
- package/frontend/dist/js/ChannelsPage-B1hC1rRS.js +0 -1
- package/frontend/dist/js/ChatPage-B7mEg5z2.js +0 -14
- package/frontend/dist/js/ConnectModels-Cby89_Mc.js +0 -1
- package/frontend/dist/js/EvaluationsPage-BaND2qQM.js +0 -2
- package/frontend/dist/js/FirstTimeSetup-D8ktLJKO.js +0 -1
- package/frontend/dist/js/GalleryPage-DXQLoU0l.js +0 -1
- package/frontend/dist/js/HomePage-WVug1vWc.js +0 -1
- package/frontend/dist/js/LanguageSwitcher-DHHTrDBR.js +0 -1
- package/frontend/dist/js/ModelManagerModals-BPALNMDH.js +0 -1
- package/frontend/dist/js/NotesPage-CRzX2Wa8.js +0 -3
- package/frontend/dist/js/OptimizedSyntaxHighlighter-ajqwyBQm.js +0 -1
- package/frontend/dist/js/PasswordStrengthMeter-BGrHWG0B.js +0 -1
- package/frontend/dist/js/PersonasPage-BRU9151f.js +0 -13
- package/frontend/dist/js/PluginUsagePage-BlhYZq1l.js +0 -1
- package/frontend/dist/js/RichMessageContent-FiuPwDG7.js +0 -1
- package/frontend/dist/js/SettingsModal-sLkxG-lW.js +0 -19
- package/frontend/dist/js/SettingsToggle-Du2FSUPO.js +0 -1
- package/frontend/dist/js/ShareDialog-DEhxnLfn.js +0 -1
- package/frontend/dist/js/StrandsPage-DWnUKSb0.js +0 -1
- package/frontend/dist/js/SystemPage-cqq8lSxB.js +0 -1
- package/frontend/dist/js/UserManagementPanel-NZmoTk6V.js +0 -1
- package/frontend/dist/js/WhatsNewModal-5SwIdmU1.js +0 -1
- package/frontend/dist/js/WorkPage-BIuaVNEC.js +0 -8
- package/frontend/dist/js/api-C2k0OqEk.js +0 -1
- package/frontend/dist/js/appStore-DULGAJnH.js +0 -2
- package/frontend/dist/js/appVersion-DooVk4c_.js +0 -1
- package/frontend/dist/js/ar-Bp843BgG.js +0 -2
- package/frontend/dist/js/authStore-CaLdzyAr.js +0 -1
- package/frontend/dist/js/bn-DmSGkklY.js +0 -2
- package/frontend/dist/js/chatStore-j8bGpkeT.js +0 -3
- package/frontend/dist/js/cs-BcauIRyG.js +0 -2
- package/frontend/dist/js/da-CJ14DPJ_.js +0 -2
- package/frontend/dist/js/de-ajswyAhq.js +0 -2
- package/frontend/dist/js/es-rlf8FsMZ.js +0 -2
- package/frontend/dist/js/fr-BwkM1wie.js +0 -2
- package/frontend/dist/js/goober.modern-BaHbaW3_.js +0 -1
- package/frontend/dist/js/hi-B3eId9-I.js +0 -2
- package/frontend/dist/js/id-BcgPFJh2.js +0 -2
- package/frontend/dist/js/is-Crvd3K7f.js +0 -2
- package/frontend/dist/js/it-DrLx24hb.js +0 -2
- package/frontend/dist/js/ja-DZMcf-oB.js +0 -2
- package/frontend/dist/js/ko-Cm0NiOE8.js +0 -2
- package/frontend/dist/js/markdownMath-B0BpyFBS.js +0 -1
- package/frontend/dist/js/messageCodeStyles-CDnMKLgo.js +0 -2
- package/frontend/dist/js/ms-ymaG59hx.js +0 -2
- package/frontend/dist/js/nl-CdIdeA9d.js +0 -2
- package/frontend/dist/js/pl-CuO0b605.js +0 -2
- package/frontend/dist/js/pt-Vy413FG5.js +0 -2
- package/frontend/dist/js/react-vendor-wiHys0m2.js +0 -9
- package/frontend/dist/js/ru-D0zOEVrL.js +0 -2
- package/frontend/dist/js/sv-JoS4krpk.js +0 -2
- package/frontend/dist/js/th-afhelaqR.js +0 -2
- package/frontend/dist/js/tr-BhSy9UrR.js +0 -2
- package/frontend/dist/js/ui-CW3gJ4Kl.js +0 -2
- package/frontend/dist/js/ui-vendor-_fvLnmDx.js +0 -1
- package/frontend/dist/js/uk-CibXypnZ.js +0 -2
- package/frontend/dist/js/useChat-CBySqLqR.js +0 -10
- package/frontend/dist/js/useDictation-DEAp64eu.js +0 -1
- package/frontend/dist/js/vi-Cg0WKHtb.js +0 -2
- package/frontend/dist/js/workApi-gpxrWwCm.js +0 -1
- package/frontend/dist/js/zh-DTqys9TE.js +0 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-CR5VJ85Q.js";import{i as r}from"./router-vendor-DqMnEJWK.js";import{t as i}from"./logger-BR4forr_.js";import{t as a}from"./chatStore-CVTbkZyb.js";import{t as o}from"./useTranslation-Boi0fB1B.js";import{i as s,t as c}from"./utils-B-Bhh1pF.js";import{$n as l,At as u,Fn as d,H as ee,It as f,Or as p,Ot as m,Qt as h,Rt as te,W as g,Zn as _,at as ne,dr as re,er as v,n as y,r as ie,s as ae,st as b,tt as oe,ut as x,v as se,wn as ce,yr as le}from"./ui-vendor-6S05F84J.js";import{t as S}from"./Button-Dh2UJA-B.js";import{_ as C,g as w,i as ue,n as de,r as T,t as E,v as D}from"./ui-CI0OdG9q.js";import{t as O}from"./confirmStore-CKkUtP9c.js";import{D as k}from"./api-Dcz1G4Ib.js";import{t as fe}from"./authStore-COgKeTRv.js";import{t as pe}from"./teamEventStream-RNJYm84u.js";var A=e(t(),1),j=n(),me=[`👍`,`🎉`,`❤️`,`😄`,`👀`,`🚀`],M=180,N=({calls:e})=>{let{t}=o(),[n,r]=(0,A.useState)(!1),i=e.some(e=>e.status===`denied`);return(0,j.jsxs)(`div`,{className:`mt-1`,"data-testid":`channel-tool-calls`,children:[(0,j.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),"aria-expanded":n,className:`flex items-center gap-1 text-[11px] font-medium text-gray-500 hover:text-gray-700 dark:text-dark-600 dark:hover:text-dark-800`,"data-testid":`channel-tool-calls-toggle`,children:[n?(0,j.jsx)(l,{className:`h-3 w-3`}):(0,j.jsx)(_,{className:`h-3 w-3`}),(0,j.jsx)(ie,{className:`h-3 w-3`}),t(`channels.toolCalls.summary`,{total:e.length})]}),n&&(0,j.jsxs)(`div`,{className:`mt-1 space-y-1`,children:[e.map(e=>(0,j.jsxs)(`div`,{className:`rounded-lg border border-black/6 px-2 py-1 dark:border-white/8`,"data-testid":`channel-tool-call`,children:[(0,j.jsxs)(`div`,{className:`flex items-baseline gap-1.5`,children:[(0,j.jsx)(`span`,{dir:`ltr`,className:`min-w-0 truncate text-[11px] font-medium text-gray-700 dark:text-dark-800`,children:e.name}),(0,j.jsx)(`span`,{className:c(`shrink-0 text-[10px]`,e.status===`succeeded`?`text-emerald-600 dark:text-emerald-400`:e.status===`denied`?`text-amber-600 dark:text-amber-400`:e.status===`failed`?`text-red-500`:`text-gray-400 dark:text-dark-500`),children:t(`tools.callStatus.${e.status}`)})]}),e.resultPreview&&(0,j.jsx)(`p`,{dir:`ltr`,className:`mt-0.5 whitespace-pre-wrap wrap-break-word font-mono text-[10px] leading-snug text-gray-500 dark:text-dark-600`,children:e.resultPreview.slice(0,M)})]},e.id)),i&&(0,j.jsx)(`p`,{className:`text-[10px] text-gray-400 dark:text-dark-500`,children:t(`channels.toolCalls.deniedHint`)})]})]})},P=({message:e,currentUserId:t,canModerate:n,actions:r,compact:i=!1})=>{let{t:a,i18n:l}=o(),[u,d]=(0,A.useState)(!1),[ee,f]=(0,A.useState)(e.content),[p,h]=(0,A.useState)(!1),g=e.authorKind===`model`,_=!g&&e.author?.userId===t&&!e.deleted,ie=g?e.model??a(`channels.modelAuthor`):e.author?.username??a(`channels.unknownAuthor`);return(0,j.jsxs)(`div`,{className:c(`group relative rounded-xl px-2.5 py-1.5 hover:bg-black/2.5 dark:hover:bg-white/3`,i&&`px-2 py-1`),"data-testid":`channel-message`,children:[(0,j.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[g&&(0,j.jsx)(re,{className:`h-3.5 w-3.5 shrink-0 self-center text-primary-500`}),(0,j.jsx)(`span`,{className:c(`shrink-0 text-[13px] font-semibold`,g?`text-primary-600 dark:text-primary-400`:`text-gray-900 dark:text-dark-900`),children:ie}),(0,j.jsx)(`span`,{className:`shrink-0 text-[11px] text-gray-400 dark:text-dark-500`,children:s(e.createdAt,l.language)}),e.editedAt&&!e.deleted&&(0,j.jsx)(`span`,{className:`shrink-0 text-[10px] text-gray-400 dark:text-dark-500`,children:a(`channels.edited`)}),e.pinnedAt&&(0,j.jsx)(ne,{role:`img`,"aria-label":a(`channels.pins`),className:`h-3 w-3 shrink-0 text-amber-500`})]}),e.deleted?(0,j.jsx)(`p`,{className:`text-[13px] italic text-gray-400 dark:text-dark-500`,children:a(`channels.deletedMessage`)}):u?(0,j.jsxs)(`div`,{className:`mt-1 flex items-end gap-1.5`,children:[(0,j.jsx)(`textarea`,{value:ee,onChange:e=>f(e.target.value),rows:2,"aria-label":a(`channels.edit`),className:`min-w-0 flex-1 resize-none rounded-lg border border-black/8 bg-transparent px-2 py-1 text-[13px] focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"data-testid":`channel-message-edit`}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>{r.onEdit(e,ee),d(!1)},"aria-label":a(`channels.confirmEdit`),title:a(`channels.confirmEdit`),className:`rounded-md p-1.5 text-emerald-600 hover:bg-emerald-50 dark:hover:bg-emerald-900/20`,children:(0,j.jsx)(v,{className:`h-3.5 w-3.5`})}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>d(!1),"aria-label":a(`channels.cancelEdit`),title:a(`channels.cancelEdit`),className:`rounded-md p-1.5 text-gray-400 hover:bg-black/4 dark:hover:bg-white/6`,children:(0,j.jsx)(y,{className:`h-3.5 w-3.5`})})]}):(0,j.jsxs)(j.Fragment,{children:[e.pending?(0,j.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[13px] text-gray-400 dark:text-dark-500`,children:[(0,j.jsx)(te,{className:`h-3.5 w-3.5 animate-spin`}),a(`channels.modelThinking`)]}):e.error?(0,j.jsx)(`p`,{className:`text-[13px] text-red-500`,children:e.error}):(0,j.jsx)(`p`,{className:`whitespace-pre-wrap wrap-break-word text-[13px] leading-relaxed text-gray-800 dark:text-dark-800`,children:e.content}),g&&(e.toolCalls?.length??0)>0&&(0,j.jsx)(N,{calls:e.toolCalls}),(e.attachments?.length??0)>0&&(0,j.jsx)(`div`,{className:`mt-1 space-y-1`,children:e.attachments.map(e=>(0,j.jsxs)(`button`,{type:`button`,onClick:()=>void r.onDownload(e.id,e.filename),className:`flex items-center gap-1.5 rounded-lg border border-black/6 px-2 py-1 text-[12px] text-gray-600 hover:bg-black/3 dark:border-white/8 dark:text-dark-700 dark:hover:bg-white/4`,"data-testid":`channel-attachment`,children:[(0,j.jsx)(x,{className:`h-3 w-3`}),(0,j.jsx)(`span`,{className:`min-w-0 truncate`,children:e.filename})]},e.id))})]}),(e.reactions?.length??0)>0&&(0,j.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:e.reactions.map(t=>(0,j.jsxs)(`button`,{type:`button`,"aria-pressed":t.mine,onClick:()=>void r.onReact(e,t.emoji,t.mine),className:c(`rounded-full border px-1.5 py-0.5 text-[11px]`,t.mine?`border-primary-400/50 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-black/8 text-gray-600 hover:bg-black/3 dark:border-white/10 dark:text-dark-700`),"data-testid":`channel-reaction`,children:[t.emoji,` `,t.count]},t.emoji))}),!i&&(e.replyCount??0)>0&&r.onReply&&(0,j.jsxs)(`button`,{type:`button`,onClick:()=>r.onReply(e),className:`mt-1 flex items-center gap-1 text-[11px] font-medium text-primary-600 hover:underline dark:text-primary-400`,"data-testid":`channel-reply-count`,children:[(0,j.jsx)(m,{className:`h-3 w-3`}),a(`channels.replyCount`,{total:e.replyCount})]}),!e.deleted&&!u&&(0,j.jsxs)(`div`,{className:`absolute -top-2.5 inset-e-2 hidden items-center gap-0.5 rounded-lg border border-black/8 bg-white px-1 py-0.5 shadow-xs group-focus-within:flex group-hover:flex [@media(hover:none)]:flex dark:border-white/10 dark:bg-dark-50`,children:[(0,j.jsxs)(`div`,{className:`relative`,children:[(0,j.jsx)(`button`,{type:`button`,onClick:()=>h(e=>!e),className:`rounded-sm p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:a(`channels.react`),"aria-label":a(`channels.react`),"aria-haspopup":`true`,"aria-expanded":p,"data-testid":`channel-react`,children:(0,j.jsx)(ce,{className:`h-3.5 w-3.5`})}),p&&(0,j.jsx)(`div`,{className:`absolute inset-e-0 top-6 z-10 flex gap-0.5 rounded-lg border border-black/8 bg-white p-1 shadow-md dark:border-white/10 dark:bg-dark-50`,children:me.map(t=>(0,j.jsx)(`button`,{type:`button`,onClick:()=>{let n=!!e.reactions?.find(e=>e.emoji===t)?.mine;r.onReact(e,t,n),h(!1)},"aria-label":a(`channels.reactWith`,{emoji:t}),className:`rounded-sm p-0.5 text-sm hover:bg-black/5 dark:hover:bg-white/8`,children:t},t))})]}),r.onReply&&!e.parentId&&(0,j.jsx)(`button`,{type:`button`,onClick:()=>r.onReply(e),className:`rounded-sm p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:a(`channels.reply`),"aria-label":a(`channels.reply`),"data-testid":`channel-reply`,children:(0,j.jsx)(m,{className:`h-3.5 w-3.5`})}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>void r.onPin(e),className:`rounded-sm p-1 text-gray-400 hover:text-amber-500`,title:e.pinnedAt?a(`channels.unpin`):a(`channels.pin`),"aria-label":e.pinnedAt?a(`channels.unpin`):a(`channels.pin`),"data-testid":`channel-pin`,children:(0,j.jsx)(ne,{className:`h-3.5 w-3.5`})}),_&&(0,j.jsx)(`button`,{type:`button`,onClick:()=>{f(e.content),d(!0)},className:`rounded-sm p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:a(`channels.edit`),"aria-label":a(`channels.edit`),"data-testid":`channel-edit`,children:(0,j.jsx)(b,{className:`h-3.5 w-3.5`})}),(_||n)&&(0,j.jsx)(`button`,{type:`button`,onClick:async()=>{await O({title:a(`channels.deleteMessageConfirmTitle`),description:a(`channels.deleteMessageConfirmDescription`),destructive:!0})&&await r.onDelete(e)},className:`rounded-sm p-1 text-gray-400 hover:text-red-500`,title:a(`channels.deleteMessage`),"aria-label":a(`channels.deleteMessage`),"data-testid":`channel-delete-message`,children:(0,j.jsx)(se,{className:`h-3.5 w-3.5`})})]})]})},F=i(`pages:channels`),he=e=>e.type===`dm`?(0,j.jsx)(u,{className:`h-3.5 w-3.5 shrink-0`}):e.type===`private`?(0,j.jsx)(f,{className:`h-3.5 w-3.5 shrink-0`}):(0,j.jsx)(h,{className:`h-3.5 w-3.5 shrink-0`}),I=e=>e.type===`dm`?e.dmPeer?.username??`…`:e.name,ge=()=>{let{t:e}=o(),t=fe(e=>e.user),n=a(e=>e.models),[i,s]=(0,A.useState)([]),[l,f]=(0,A.useState)(null),[_,v]=(0,A.useState)(!1),[ie,b]=(0,A.useState)(!1),[se,ce]=(0,A.useState)(!0),[C,w]=(0,A.useState)(null),[E,D]=(0,A.useState)(null),[me,M]=(0,A.useState)([]),[N,ge]=(0,A.useState)([]),[L,R]=(0,A.useState)(null),[z,xe]=(0,A.useState)(null),[Se,Ce]=(0,A.useState)([]),[B,we]=(0,A.useState)(``),[V,Te]=(0,A.useState)(``),[H,Ee]=(0,A.useState)(!1),[U,De]=(0,A.useState)(null),[Oe,ke]=(0,A.useState)(!1),[Ae,je]=(0,A.useState)(!1),[W,Me]=(0,A.useState)(``),[Ne,G]=(0,A.useState)(!1),Pe=(0,A.useRef)(null),Fe=(0,A.useRef)(null),[Ie,Le]=r(),K=(0,A.useMemo)(()=>i.find(e=>e.id===C)??null,[i,C]),[Re,ze]=(0,A.useState)(null);C!==Re&&(ze(C),D(null),xe(null),R(null));let q=K?.role===`owner`,J=(0,A.useCallback)(()=>{k.listMine().then(e=>{e.success&&e.data&&s(e.data)}).catch(e=>F.error(`Failed to load channels:`,e)).finally(()=>ce(!1))},[]);(0,A.useEffect)(()=>{J();let e=window.setInterval(J,3e4);return()=>window.clearInterval(e)},[J]);let Y=Ie.get(`channel`);Y&&C!==Y&&w(Y),(0,A.useEffect)(()=>{Y&&Le({},{replace:!0})},[Y,Le]);let X=(0,A.useRef)(null);(0,A.useLayoutEffect)(()=>(X.current=C?{channelId:C,requestId:0}:null,()=>{X.current=null}),[C]);let Z=(0,A.useCallback)(t=>{let n=X.current;if(!n||n.channelId!==t)return;let r=++n.requestId;k.listMessages(t,{limit:100}).then(e=>{X.current===n&&n.requestId===r&&e.success&&e.data&&D(e.data)}).catch(t=>{F.error(`Failed to load messages:`,t),p.error(e(`channels.loadFailed`),{id:`channels-load-failed`})})},[e]),Be=(0,A.useRef)(null);(0,A.useEffect)(()=>{Be.current=z},[z]);let Ve=(0,A.useCallback)(e=>{Z(e),k.markRead(e);let t=Be.current;t&&k.thread(t).then(e=>{e.success&&e.data&&Ce(e.data)}).catch(e=>F.error(`Failed to refresh thread:`,e))},[Z]);(0,A.useEffect)(()=>{if(!C)return;Z(C),k.markRead(C).then(J);let e=new AbortController;return pe({path:`/channels/${C}/events`,signal:e.signal,onEvent:()=>Ve(C)}),()=>e.abort()},[C,Z,J,Ve]);let He=E?.length??0;(0,A.useEffect)(()=>{let e=Fe.current;e&&(e.scrollTop=e.scrollHeight)},[He,C]),(0,A.useEffect)(()=>{if(!C||!L)return;let t=t=>{F.error(`Failed to load channel panel:`,t),p.error(e(`channels.loadFailed`))};L===`members`?k.listMembers(C).then(e=>{e.success&&e.data?M(e.data):t(e.error)}).catch(t):k.listPins(C).then(e=>{e.success&&e.data?ge(e.data):t(e.error)}).catch(t)},[C,L,e]),(0,A.useEffect)(()=>{z&&k.thread(z).then(t=>{t.success&&t.data?Ce(t.data):p.error(e(`channels.loadFailed`))}).catch(t=>{F.error(`Failed to load thread:`,t),p.error(e(`channels.loadFailed`))})},[z,e]);let Ue=()=>{v(!0),b(!1),k.listPublic().then(e=>{e.success&&e.data?f(e.data):b(!0)}).catch(e=>{F.error(`Failed to load public channels:`,e),b(!0)})},Q=async t=>{if(!C||H)return;let n=B.trim();if(n||U){Ee(!0);try{let r=await k.postMessage(C,{content:n,...t?{parentId:t}:{},...U?{attachmentIds:[U.id]}:{},...V?{mentionModel:V}:{}});if(r.success){if(we(``),De(null),Te(``),Z(C),t){let e=await k.thread(t);e.success&&e.data&&Ce(e.data)}}else p.error(r.error||e(`channels.sendFailed`))}catch(t){F.error(`Failed to send message:`,t),p.error(e(`channels.sendFailed`))}finally{Ee(!1)}}},We=async t=>{if(C)try{let n=await k.uploadAttachment(C,t);n.success&&n.data?De({id:n.data.id,filename:n.data.filename}):p.error(n.error||e(`channels.uploadFailed`))}catch(t){F.error(`Failed to upload attachment:`,t),p.error(e(`channels.uploadFailed`))}},Ge=async()=>{if(C&&W.trim()){if((await k.addMember(C,W.trim()).catch(()=>void 0))?.success){Me(``);let t=await k.listMembers(C).catch(()=>void 0);t?.success&&t.data&&M(t.data),p.success(e(`channels.memberAdded`))}else p.error(e(`channels.memberAddFailed`))}},Ke={onReply:e=>xe(e.id),onEdit:async(t,n)=>{(await k.editMessage(t.id,n).catch(()=>void 0))?.success?C&&Z(C):p.error(e(`channels.editFailed`))},onDelete:async t=>{(await k.deleteMessage(t.id).catch(()=>void 0))?.success?C&&Z(C):p.error(e(`channels.deleteMessageFailed`))},onPin:async t=>{(await k.setPinned(t.id,!t.pinnedAt).catch(()=>void 0))?.success||p.error(e(`channels.pinFailed`)),C&&Z(C)},onReact:async(t,n,r)=>{(await(r?k.removeReaction(t.id,n):k.addReaction(t.id,n)).catch(()=>void 0))?.success||p.error(e(`channels.reactFailed`)),C&&Z(C)},onDownload:async(t,n)=>{try{let e=await k.downloadAttachment(t),r=URL.createObjectURL(e),i=document.createElement(`a`);i.href=r,i.download=n,i.click(),URL.revokeObjectURL(r)}catch(t){F.error(`Failed to download attachment:`,t),p.error(e(`channels.downloadFailed`))}}},$=Se[0];return(0,j.jsxs)(`div`,{className:`flex h-full min-h-0`,children:[(0,j.jsxs)(`aside`,{className:c(`flex w-64 shrink-0 flex-col border-e border-black/6 dark:border-white/6`,C?`hidden md:flex`:`flex`),"data-testid":`channel-rail`,children:[(0,j.jsx)(ue,{title:e(`channels.title`),className:`gap-y-1 px-3`,actions:(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`button`,{type:`button`,onClick:Ue,title:e(`channels.browsePublic`),"aria-label":e(`channels.browsePublic`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channels-browse`,children:(0,j.jsx)(d,{className:`h-4 w-4`})}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>je(!0),title:e(`channels.newDm`),"aria-label":e(`channels.newDm`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channels-new-dm`,children:(0,j.jsx)(u,{className:`h-4 w-4`})}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>ke(!0),title:e(`channels.newChannel`),"aria-label":e(`channels.newChannel`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channels-new`,children:(0,j.jsx)(oe,{className:`h-4 w-4`})})]})}),(0,j.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-2 pb-3 scrollbar-thin`,children:se?(0,j.jsx)(de,{size:`sm`,srOnly:!0}):i.length===0?(0,j.jsx)(T,{icon:h,size:`sm`,title:e(`channels.empty`)}):i.map(t=>(0,j.jsxs)(`button`,{type:`button`,onClick:()=>w(t.id),className:c(`flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-start text-[13px]`,C===t.id?`bg-black/5 text-gray-900 dark:bg-white/8 dark:text-dark-900`:`text-gray-600 hover:bg-black/3 dark:text-dark-700 dark:hover:bg-white/4`),"data-testid":`channel-item`,children:[he(t),(0,j.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:I(t)}),(t.unreadCount??0)>0&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`span`,{className:`rounded-full bg-primary-600 px-1.5 text-[10px] font-semibold leading-4 text-white`,"data-testid":`channel-unread`,"aria-hidden":`true`,children:t.unreadCount}),(0,j.jsx)(`span`,{className:`sr-only`,children:e(`channels.unreadCount`,{total:t.unreadCount})})]})]},t.id))})]}),(0,j.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col`,children:K?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-black/6 px-4 py-2.5 dark:border-white/6`,children:[(0,j.jsx)(`button`,{type:`button`,onClick:()=>w(null),"aria-label":e(`common.back`),title:e(`common.back`),className:`rounded-md p-1 text-gray-500 hover:bg-black/4 md:hidden dark:text-dark-600`,children:(0,j.jsx)(le,{className:`h-4 w-4 rtl:rotate-180`})}),he(K),(0,j.jsx)(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-gray-900 dark:text-dark-900`,"data-testid":`channel-title`,children:I(K)}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>R(L===`pins`?null:`pins`),title:e(`channels.pins`),"aria-label":e(`channels.pins`),"aria-pressed":L===`pins`,className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-pins-toggle`,children:(0,j.jsx)(ne,{className:`h-4 w-4`})}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>R(L===`members`?null:`members`),title:e(`channels.members`),"aria-label":e(`channels.members`),"aria-pressed":L===`members`,className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-members-toggle`,children:(0,j.jsx)(ae,{className:`h-4 w-4`})}),q&&K.type!==`dm`&&(0,j.jsx)(`button`,{type:`button`,onClick:()=>G(!0),title:e(`channels.settings`),"aria-label":e(`channels.settings`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-settings`,children:(0,j.jsx)(ee,{className:`h-4 w-4`})})]}),(0,j.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,j.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,j.jsx)(`div`,{ref:Fe,className:`min-h-0 flex-1 space-y-1 overflow-y-auto px-4 py-3 scrollbar-thin`,"data-testid":`channel-timeline`,children:E===null?(0,j.jsx)(de,{size:`sm`,srOnly:!0}):E.length===0?(0,j.jsx)(T,{icon:m,size:`sm`,title:e(`channels.noMessages`)}):E.map(e=>(0,j.jsx)(P,{message:e,currentUserId:t?.id,canModerate:q,actions:Ke},e.id))}),(0,j.jsxs)(`div`,{className:`border-t border-black/6 p-3 dark:border-white/6`,children:[U&&(0,j.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 rounded-lg border border-black/6 px-2.5 py-1.5 text-xs text-gray-600 dark:border-white/8 dark:text-dark-700`,children:[(0,j.jsx)(x,{className:`h-3.5 w-3.5`}),(0,j.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:U.filename}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>De(null),"aria-label":e(`channels.removeAttachment`),title:e(`channels.removeAttachment`),className:`rounded-sm p-0.5 text-gray-500 hover:text-red-500`,children:(0,j.jsx)(y,{className:`h-3.5 w-3.5`})})]}),(0,j.jsxs)(`div`,{className:`flex items-end gap-1.5`,children:[(0,j.jsx)(`input`,{ref:Pe,type:`file`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&We(t),e.target.value=``}}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>Pe.current?.click(),title:e(`channels.attach`),"aria-label":e(`channels.attach`),className:`rounded-md p-2 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-attach`,children:(0,j.jsx)(x,{className:`h-4 w-4`})}),(0,j.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,j.jsx)(re,{className:c(`h-4 w-4`,V?`text-primary-500`:`text-gray-400 dark:text-dark-500`)}),(0,j.jsxs)(`select`,{value:V,onChange:e=>Te(e.target.value),className:`max-w-[130px] rounded-md border border-black/8 bg-transparent px-1 py-1 text-[11px] text-gray-600 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:bg-dark-100 dark:text-dark-700`,title:e(`channels.askModel`),"aria-label":e(`channels.askModel`),"data-testid":`channel-mention-model`,children:[(0,j.jsx)(`option`,{value:``,children:e(`channels.noModel`)}),n.map(e=>(0,j.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,j.jsx)(`textarea`,{value:B,onChange:e=>we(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),Q())},rows:1,placeholder:e(`channels.composerPlaceholder`),"aria-label":e(`channels.composerPlaceholder`),className:`max-h-32 min-w-0 flex-1 resize-none rounded-xl border border-black/8 bg-transparent px-3 py-2 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"data-testid":`channel-composer`}),(0,j.jsx)(S,{size:`sm`,disabled:H||!B.trim()&&!U,onClick:()=>void Q(),"aria-label":e(`channels.send`),title:e(`channels.send`),"data-testid":`channel-send`,children:H?(0,j.jsx)(te,{className:`h-4 w-4 animate-spin`}):(0,j.jsx)(g,{className:`h-4 w-4`})})]})]})]}),z&&(0,j.jsxs)(`aside`,{className:`flex w-80 shrink-0 flex-col border-s border-black/6 dark:border-white/6`,"data-testid":`channel-thread`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-black/6 px-3 py-2 dark:border-white/6`,children:[(0,j.jsx)(`span`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-dark-600`,children:e(`channels.thread`)}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>xe(null),"aria-label":e(`channels.closeThread`),title:e(`channels.closeThread`),className:`rounded-md p-1 text-gray-400 hover:bg-black/4 dark:hover:bg-white/6`,children:(0,j.jsx)(y,{className:`h-3.5 w-3.5`})})]}),(0,j.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1 overflow-y-auto px-3 py-2 scrollbar-thin`,children:Se.map(e=>(0,j.jsx)(P,{message:e,currentUserId:t?.id,canModerate:q,actions:{...Ke,onReply:void 0},compact:!0},e.id))}),(0,j.jsxs)(`div`,{className:`flex items-end gap-1.5 border-t border-black/6 p-2 dark:border-white/6`,children:[(0,j.jsx)(`textarea`,{value:B,onChange:e=>we(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),$&&Q($.id))},rows:1,placeholder:e(`channels.replyPlaceholder`),"aria-label":e(`channels.replyPlaceholder`),className:`min-w-0 flex-1 resize-none rounded-lg border border-black/8 bg-transparent px-2.5 py-1.5 text-[13px] text-gray-900 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"data-testid":`channel-thread-composer`}),(0,j.jsx)(S,{size:`sm`,disabled:H||!B.trim(),onClick:()=>$&&void Q($.id),"aria-label":e(`channels.send`),title:e(`channels.send`),children:(0,j.jsx)(g,{className:`h-3.5 w-3.5`})})]})]}),L&&(0,j.jsxs)(`aside`,{className:`flex w-72 shrink-0 flex-col border-s border-black/6 dark:border-white/6`,"data-testid":`channel-${L}-panel`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-black/6 px-3 py-2 dark:border-white/6`,children:[(0,j.jsx)(`span`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-dark-600`,children:e(L===`members`?`channels.members`:`channels.pins`)}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>R(null),"aria-label":e(`common.close`),title:e(`common.close`),className:`rounded-md p-1 text-gray-400 hover:bg-black/4 dark:hover:bg-white/6`,children:(0,j.jsx)(y,{className:`h-3.5 w-3.5`})})]}),(0,j.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto px-3 py-2 scrollbar-thin`,children:L===`members`?(0,j.jsxs)(j.Fragment,{children:[q&&K.type===`private`&&(0,j.jsxs)(`div`,{className:`mb-2 flex gap-1.5`,children:[(0,j.jsx)(`input`,{type:`text`,value:W,onChange:e=>Me(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&Ge()},placeholder:e(`channels.invitePlaceholder`),"aria-label":e(`channels.invitePlaceholder`),className:`min-w-0 flex-1 rounded-lg border border-black/8 bg-transparent px-2 py-1 text-xs focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-800`,"data-testid":`channel-invite-name`}),(0,j.jsx)(S,{size:`sm`,disabled:!W.trim(),onClick:()=>void Ge(),"aria-label":e(`channels.invite`),title:e(`channels.invite`),"data-testid":`channel-invite-submit`,children:(0,j.jsx)(oe,{className:`h-3.5 w-3.5`})})]}),me.map(n=>(0,j.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg px-2 py-1.5 text-[13px] text-gray-700 dark:text-dark-800`,"data-testid":`channel-member`,children:[(0,j.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:n.username}),(0,j.jsx)(`span`,{className:`text-[10px] uppercase text-gray-400 dark:text-dark-500`,children:n.role===`owner`?e(`channels.roleOwner`):``}),q&&n.userId!==t?.id&&K.type!==`dm`&&(0,j.jsx)(`button`,{type:`button`,onClick:async()=>{await O({title:e(`channels.removeMemberConfirm`,{name:n.username}),description:e(`channels.removeMemberConfirmDescription`),confirmLabel:e(`common.remove`),destructive:!0})&&((await k.removeMember(K.id,n.userId).catch(()=>void 0))?.success?M(e=>e.filter(e=>e.userId!==n.userId)):p.error(e(`channels.removeMemberFailed`)))},className:`rounded-sm p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,title:e(`channels.removeMember`),"aria-label":e(`channels.removeMemberNamed`,{name:n.username}),children:(0,j.jsx)(y,{className:`h-3 w-3`})})]},n.userId)),!q&&K.type!==`dm`&&(0,j.jsx)(S,{size:`sm`,variant:`ghost`,className:`mt-2 w-full text-red-500`,onClick:async()=>{await O({title:e(`channels.leaveConfirm`,{name:I(K)}),description:e(`channels.leaveConfirmDescription`),confirmLabel:e(`channels.leave`),destructive:!0})&&((await k.removeMember(K.id,t?.id??``).catch(()=>void 0))?.success?(w(null),J()):p.error(e(`channels.leaveFailed`)))},"data-testid":`channel-leave`,children:e(`channels.leave`)})]}):N.length===0?(0,j.jsx)(`p`,{className:`pt-4 text-center text-xs text-gray-400 dark:text-dark-500`,children:e(`channels.noPins`)}):N.map(e=>(0,j.jsx)(P,{message:e,currentUserId:t?.id,canModerate:q,actions:Ke,compact:!0},e.id))})]})]})]}):(0,j.jsx)(T,{icon:m,title:e(`channels.selectPrompt`),className:`flex-1 justify-center`})}),Oe&&(0,j.jsx)(_e,{onClose:()=>ke(!1),onCreated:e=>{ke(!1),J(),w(e.id)}}),Ae&&(0,j.jsx)(ve,{onClose:()=>je(!1),onOpened:e=>{je(!1),J(),w(e.id)}}),_&&(0,j.jsx)(ye,{channels:l,failed:ie,onRetry:Ue,onClose:()=>v(!1),onJoined:e=>{v(!1),J(),w(e)}}),Ne&&K&&(0,j.jsx)(be,{channel:K,onClose:()=>G(!1),onChanged:()=>{G(!1),J()},onDeleted:()=>{G(!1),w(null),J()}})]})},_e=({onClose:e,onCreated:t})=>{let{t:n}=o(),[r,i]=(0,A.useState)(``),[a,s]=(0,A.useState)(`public`),[c,l]=(0,A.useState)(``),[u,d]=(0,A.useState)(!1);return(0,j.jsxs)(w,{titleId:`create-channel-title`,title:n(`channels.newChannel`),onClose:e,testId:`create-channel-modal`,footer:(0,j.jsx)(S,{size:`sm`,disabled:u||!r.trim(),onClick:()=>{d(!0),k.create({type:a,name:r.trim(),...c.trim()?{description:c.trim()}:{}}).then(e=>{e.success&&e.data?t(e.data):p.error(e.error||n(`channels.createFailed`))}).catch(()=>p.error(n(`channels.createFailed`))).finally(()=>d(!1))},"data-testid":`create-channel-submit`,children:n(`channels.create`)}),children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`create-channel-name`,className:D,children:n(`channels.nameLabel`)}),(0,j.jsx)(`input`,{id:`create-channel-name`,className:C,value:r,onChange:e=>i(e.target.value),"data-testid":`create-channel-name`})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`create-channel-type`,className:D,children:n(`channels.typeLabel`)}),(0,j.jsxs)(`select`,{id:`create-channel-type`,className:C,value:a,onChange:e=>s(e.target.value),"data-testid":`create-channel-type`,children:[(0,j.jsx)(`option`,{value:`public`,children:n(`channels.typePublic`)}),(0,j.jsx)(`option`,{value:`private`,children:n(`channels.typePrivate`)})]})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`create-channel-description`,className:D,children:n(`channels.descriptionLabel`)}),(0,j.jsx)(`textarea`,{id:`create-channel-description`,className:C,rows:2,value:c,onChange:e=>l(e.target.value)})]})]})},ve=({onClose:e,onOpened:t})=>{let{t:n}=o(),[r,i]=(0,A.useState)(``),[a,s]=(0,A.useState)(!1),c=()=>{r.trim()&&(s(!0),k.openDm(r.trim()).then(e=>{e.success&&e.data?t(e.data):p.error(e.error||n(`channels.dmFailed`))}).catch(()=>p.error(n(`channels.dmFailed`))).finally(()=>s(!1)))};return(0,j.jsx)(w,{titleId:`open-dm-title`,title:n(`channels.newDm`),subtitle:n(`channels.dmHint`),onClose:e,testId:`open-dm-modal`,footer:(0,j.jsx)(S,{size:`sm`,disabled:a||!r.trim(),onClick:c,"data-testid":`open-dm-submit`,children:n(`channels.openDm`)}),children:(0,j.jsx)(`input`,{className:C,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&c()},placeholder:n(`channels.dmPlaceholder`),"aria-label":n(`channels.dmPlaceholder`),"data-testid":`open-dm-username`})})},ye=({channels:e,failed:t,onRetry:n,onClose:r,onJoined:i})=>{let{t:a}=o();return(0,j.jsx)(w,{titleId:`browse-channels-title`,title:a(`channels.browsePublic`),onClose:r,testId:`browse-channels-modal`,children:t&&e===null?(0,j.jsx)(E,{size:`sm`,message:a(`channels.loadFailed`),onRetry:n}):e===null?(0,j.jsx)(de,{size:`sm`,srOnly:!0}):e.length===0?(0,j.jsx)(T,{icon:d,size:`sm`,title:a(`channels.noPublic`)}):e.map(e=>(0,j.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-black/6 px-3 py-2 dark:border-white/8`,"data-testid":`browse-channel-item`,children:[(0,j.jsx)(h,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,j.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] text-gray-800 dark:text-dark-800`,children:e.name}),e.isMember?(0,j.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:a(`channels.joined`)}):(0,j.jsx)(S,{size:`sm`,onClick:()=>void k.join(e.id).then(t=>{t.success?i(e.id):p.error(a(`channels.joinFailed`))}).catch(()=>p.error(a(`channels.joinFailed`))),"data-testid":`browse-channel-join`,children:a(`channels.join`)})]},e.id))})},be=({channel:e,onClose:t,onChanged:n,onDeleted:r})=>{let{t:i}=o(),[a,s]=(0,A.useState)(e.name),[c,l]=(0,A.useState)(e.description??``),[u,d]=(0,A.useState)(!1);return(0,j.jsxs)(w,{titleId:`channel-settings-title`,title:i(`channels.settings`),onClose:t,testId:`channel-settings-modal`,footer:(0,j.jsxs)(`div`,{className:`flex w-full items-center justify-between`,children:[(0,j.jsx)(S,{size:`sm`,variant:`ghost`,className:`text-red-500`,onClick:async()=>{await O({title:i(`channels.deleteConfirm`,{name:e.name}),description:i(`channels.deleteConfirmDescription`),confirmLabel:i(`channels.delete`),destructive:!0})&&((await k.delete(e.id).catch(()=>void 0))?.success?r():p.error(i(`channels.deleteFailed`)))},"data-testid":`channel-delete`,children:i(`channels.delete`)}),(0,j.jsx)(S,{size:`sm`,disabled:u||!a.trim(),onClick:()=>{d(!0),k.update(e.id,{name:a.trim(),description:c.trim()}).then(e=>{e.success?n():p.error(i(`channels.saveFailed`))}).catch(()=>p.error(i(`channels.saveFailed`))).finally(()=>d(!1))},"data-testid":`channel-settings-save`,children:i(`channels.save`)})]}),children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`channel-settings-name`,className:D,children:i(`channels.nameLabel`)}),(0,j.jsx)(`input`,{id:`channel-settings-name`,className:C,value:a,onChange:e=>s(e.target.value)})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`channel-settings-description`,className:D,children:i(`channels.descriptionLabel`)}),(0,j.jsx)(`textarea`,{id:`channel-settings-description`,className:C,rows:2,value:c,onChange:e=>l(e.target.value)})]})]})};export{ge as default};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,r as n,t as r}from"./react-vendor-CR5VJ85Q.js";import{d as i,f as a,u as o}from"./router-vendor-DqMnEJWK.js";import{a as s,t as c}from"./logger-BR4forr_.js";import{T as l,_ as u,a as d,d as f,f as p,g as m,h,i as g,l as _,n as v,o as y,p as b,r as x,t as S,u as C}from"./chatStore-CVTbkZyb.js";import{t as w}from"./useTranslation-Boi0fB1B.js";import{a as T,i as E,n as D,s as ee,t as O}from"./utils-B-Bhh1pF.js";import{t as k}from"./appStore-0_qlwS8f.js";import{$n as A,Ct as te,Dr as j,Dt as ne,F as re,G as ie,H as ae,In as oe,J as M,Jt as N,L as P,Ln as se,M as F,Nn as ce,O as le,Or as I,P as ue,Q as de,Rn as fe,Rt as L,S as pe,Tt as R,V as me,Vn as he,X as ge,Xn as _e,Zn as ve,_r as ye,a as be,an as xe,b as Se,br as z,c as Ce,cn as we,cr as Te,ct as Ee,er as De,fr as B,g as V,gr as Oe,jn as H,ln as ke,m as Ae,n as U,o as W,p as G,pr as K,qt as je,r as Me,rn as Ne,sr as Pe,st as Fe,t as Ie,tt as Le,ut as Re,vn as ze,wt as Be,y as Ve,yn as He}from"./ui-vendor-6S05F84J.js";import{t as q}from"./Button-Dh2UJA-B.js";import{t as J}from"./useDialogFocus-zSGHkpE4.js";import{f as Ue,m as We,p as Ge,u as Ke}from"./ui-CI0OdG9q.js";import{N as Y,_ as qe,a as X,d as Je,f as Ye,g as Xe,i as Ze,j as Qe,m as $e,n as et,p as tt,t as nt,w as rt,x as it,y as at}from"./api-Dcz1G4Ib.js";import{t as ot}from"./authStore-COgKeTRv.js";import{i as st,r as Z,t as ct}from"./welcomePrompts-to5mv_gx.js";import{l as lt}from"./messageCodeStyles-D3cWF9XO.js";import{t as ut}from"./LogoMark-BzObGdA9.js";import{a as dt,i as ft,n as pt,o as mt,r as ht}from"./useChat-BSkqxHnH.js";import{a as gt,i as _t,o as vt,r as yt,s as bt,t as xt}from"./ttsBatching-kFVEE3Ip.js";import{t as St}from"./ConnectModels-emc3dv4A.js";import{i as Ct,r as wt,t as Tt}from"./thinking-DwlkTfPX.js";import{t as Et}from"./ArtifactContainer-BjzltfdU.js";import{t as Dt}from"./evaluationsApi-BwaxBVpl.js";import{n as Ot,r as kt,t as At}from"./useDictation-D9whH12W.js";import{n as jt,t as Mt}from"./composerStyles-BEx0XAp6.js";var Nt=n(),Q=e(t(),1),$=r(),Pt=e=>{try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}},Ft=({status:e})=>e===`running`||e===`awaiting_approval`?(0,$.jsx)(L,{className:`h-3.5 w-3.5 animate-spin`}):e===`succeeded`?(0,$.jsx)(De,{className:`h-3.5 w-3.5 text-green-600 dark:text-green-400`}):e===`denied`?(0,$.jsx)(U,{className:`h-3.5 w-3.5 text-amber-600 dark:text-amber-400`}):(0,$.jsx)(V,{className:`h-3.5 w-3.5 text-red-500 dark:text-red-400`}),It=({call:e})=>{let{t}=w(),[n,r]=(0,Q.useState)(!1),i=t(`tools.callStatus.${e.status}`);return(0,$.jsxs)(`div`,{className:`rounded-lg border border-gray-200 dark:border-dark-200 bg-gray-50 dark:bg-dark-50 text-sm`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-start`,"aria-expanded":n,children:[n?(0,$.jsx)(A,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}):(0,$.jsx)(ve,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 rtl:rotate-180`}),(0,$.jsx)(Me,{className:`h-3.5 w-3.5 shrink-0 text-gray-500 dark:text-gray-400`}),(0,$.jsx)(`span`,{className:`truncate font-medium text-gray-700 dark:text-gray-200`,dir:`ltr`,children:e.name}),e.serverName&&(0,$.jsx)(`span`,{className:`truncate text-xs text-gray-500 dark:text-gray-400`,children:e.serverName}),(0,$.jsxs)(`span`,{className:O(`ms-auto flex shrink-0 items-center gap-1 text-xs`,e.status===`succeeded`?`text-green-600 dark:text-green-400`:e.status===`failed`?`text-red-500 dark:text-red-400`:e.status===`denied`?`text-amber-600 dark:text-amber-400`:`text-gray-500 dark:text-gray-400`),children:[(0,$.jsx)(Ft,{status:e.status}),i]})]}),n&&(0,$.jsxs)(`div`,{className:`border-t border-gray-200 px-3 py-2 dark:border-dark-200`,children:[(0,$.jsx)(`div`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400`,children:t(`tools.arguments`)}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-1 max-h-48 overflow-auto whitespace-pre-wrap rounded-sm bg-white p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:Pt(e.arguments)}),e.resultPreview!==void 0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mt-2 text-xs font-medium text-gray-500 dark:text-gray-400`,children:t(`tools.result`)}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-1 max-h-48 overflow-auto whitespace-pre-wrap rounded-sm bg-white p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:e.resultPreview})]})]})]})},Lt=({calls:e,className:t})=>e.length===0?null:(0,$.jsx)(`div`,{className:O(`flex flex-col gap-1.5`,t),children:e.map(e=>(0,$.jsx)(It,{call:e},e.id))}),Rt=({approval:e,onDecide:t,className:n})=>{let{t:r}=w(),[i,a]=(0,Q.useState)(!1),o=(0,Q.useId)(),s=async(n,r)=>{a(!0);try{await t(e.approvalId,n,r)}catch{a(!1)}},c=r(`tools.approval.description`,{tool:e.toolCall.name,server:e.toolCall.serverName??r(`tools.approval.builtinSource`)});return(0,$.jsxs)(`div`,{role:`group`,"aria-labelledby":o,className:O(`rounded-lg border border-primary-300/70 bg-primary-50 p-3 text-sm dark:border-primary-700/60 dark:bg-primary-900/20`,n),children:[(0,$.jsxs)(`span`,{className:`sr-only`,role:`alert`,"aria-live":`assertive`,children:[r(`tools.approval.title`),`. `,c]}),(0,$.jsxs)(`div`,{id:o,className:`flex items-center gap-2 font-medium text-primary-800 dark:text-primary-200`,children:[(0,$.jsx)(P,{className:`h-4 w-4 shrink-0`}),r(`tools.approval.title`)]}),(0,$.jsx)(`p`,{className:`mt-1 text-primary-800/90 dark:text-primary-100/80`,children:c}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-2 max-h-32 overflow-auto whitespace-pre-wrap rounded-sm bg-white/70 p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:Pt(e.toolCall.arguments)}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,$.jsx)(q,{size:`sm`,disabled:i,onClick:()=>void s(!0,`once`),children:r(`tools.approval.allowOnce`)}),(0,$.jsx)(q,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>void s(!0,`session`),children:r(`tools.approval.allowSession`)}),(0,$.jsx)(q,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>void s(!0,`always`),children:r(`tools.approval.allowAlways`)}),(0,$.jsx)(q,{size:`sm`,variant:`ghost`,disabled:i,onClick:()=>void s(!1,`once`),children:r(`tools.approval.deny`)})]})]})},zt=({statistics:e,className:t=``})=>{let[n,r]=(0,Q.useState)(!1),{t:i,i18n:a}=w(),o=(e,t)=>e.toLocaleString(a.language,{minimumFractionDigits:t,maximumFractionDigits:t}),s=e=>{if(e==null)return i(`generationStats.notAvailable`);let t=e/1e6;if(t<1e3)return`${Math.round(t).toLocaleString(a.language)}ms`;let n=t/1e3;return`${o(n,2)}s`},c=e=>e?i(`generationStats.tokensPerSecond`,{value:o(e,1)}):i(`generationStats.notAvailable`),l=e.prompt_eval_count||0,u=e.eval_count||0,d=l+u,f=s(e.total_duration),p=c(e.tokens_per_second);return(0,$.jsxs)(`div`,{className:`text-xs text-ink-muted mt-2 ${t}`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4 mb-1`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(je,{size:12,className:`text-primary-500`}),i(`generationStats.tokenCount`,{tokens:u.toLocaleString(a.language)})]}),(0,$.jsx)(`span`,{className:`text-ink-muted`,children:p}),(0,$.jsx)(`span`,{className:`text-ink-muted`,children:f}),e.model&&(0,$.jsx)(`span`,{className:`text-ink-muted bg-gray-100 dark:bg-dark-200 px-2 py-0.5 rounded-full truncate max-w-32 sm:max-w-48`,title:e.model,children:e.model})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(!n),"aria-expanded":n,className:`flex items-center gap-1 text-ink-muted hover:text-ink transition-colors`,children:[n?(0,$.jsx)(A,{size:12}):(0,$.jsx)(ve,{size:12,className:`rtl:rotate-180`}),(0,$.jsx)(`span`,{children:i(`generationStats.details`)})]}),n&&(0,$.jsxs)(`div`,{className:`mt-2 p-3 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg text-xs space-y-2`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptTokens`)}),` `,l]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedTokens`)}),` `,u]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTokens`)}),` `,d]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.speed`)}),` `,p]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptEval`)}),` `,s(e.prompt_eval_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generation`)}),` `,s(e.eval_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.modelLoad`)}),` `,s(e.load_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTime`)}),` `,f]})]}),e.created_at&&(0,$.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString(a.language)]})]})]})},Bt=c(`components:ttsbutton`),Vt=null,Ht=null,Ut=0,Wt=3e5;async function Gt(e=!1){let t=Date.now();return!e&&Vt!==null&&t-Ut<Wt?Vt:Ht||(Ht=(async()=>{try{let e=await X.getModels();return e.success&&e.data&&e.data.length>0?(Vt=e.data,Ut=t,e.data):(Vt=[],Ut=t,[])}catch{return Vt=[],Ut=t,[]}finally{Ht=null}})(),Ht)}var Kt=({text:e,className:t,size:n=`sm`,externalPlaybackState:r,onStopExternal:i,onRetryExternal:a})=>{let{t:o,i18n:s}=w(),{preferences:c}=k(),[l,u]=(0,Q.useState)(`idle`),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)([]),[h,g]=(0,Q.useState)(null),_=(0,Q.useRef)(null),v=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{let e=!0;return(async()=>{let t=await Gt(),n=et(t,c.ttsSettings?.model,c.ttsSettings?.pluginId);c.ttsSettings?.model&&!n&&(t=await Gt(!0)),e&&(m(t),g(t.length>0))})(),()=>{e=!1}},[c.ttsSettings?.model,c.ttsSettings?.pluginId]);let y=()=>{v.current+=1,_.current?.cancel(),_.current=null,u(`idle`)},b=async()=>{if(r===`blocked`||r===`error`){a?.();return}if(r===`loading`||r===`generating`||r===`buffering`||r===`playing`){i?.();return}if(l===`loading`||l===`generating`||l===`buffering`||l===`playing`){y();return}if(_.current){y();return}let t=bt();u(`loading`),f(null);let n=v.current+1;v.current=n;try{let r=await t;if(v.current!==n)return;if(r===`blocked`){u(`blocked`);return}let i=c.ttsSettings,a=Ze(p,i?.model,i?.pluginId),l=a?.model||i?.model||`tts-1`,d=a?.plugin||i?.pluginId,f=a?.model===i?.model&&(!i?.pluginId||a?.plugin===i.pluginId),m=f&&i?.voice||a?.config?.default_voice,h=f&&i?.voiceProfileId||void 0,g=i?.speed||1,y=a?.config?.default_format,b=Math.max(1,a?.config?.max_characters||600),x=Math.min(b,600),S=i?.streamSentences!==!1||e.length>x?yt(e,{locale:s.language,maxChars:x,targetChars:Math.min(x,420),minChars:Math.min(x,80)}):[e.trim()];if(S.length===0)throw Error(o(`ttsButton.generateFailed`));let C=_t({concurrency:3,initialBufferSize:Math.min(2,S.length),generate:(e,{signal:t})=>X.generate({model:l,pluginId:d,input:e,voice:h?void 0:m||void 0,voiceProfileId:h,speed:g,response_format:y},{signal:t}),onStateChange:e=>{v.current===n&&u(e)}});_.current=C;let w=xt(C);try{await C.play(S)}finally{w(),_.current===C&&(_.current=null)}}catch(e){if(v.current!==n)return;if(gt(e)){u(`idle`);return}if(vt(e)){u(`blocked`);return}f(o(`ttsButton.generateFailed`)),Bt.error(`TTS error:`,e),u(`error`)}};if((0,Q.useEffect)(()=>()=>{v.current+=1,_.current?.cancel(),_.current=null},[]),h===!1||h===null)return null;let x={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},S={sm:`h-3.5 w-3.5`,md:`h-4 w-4`,lg:`h-5 w-5`},C=r&&![`idle`,`ended`,`cancelled`].includes(r)?r:l,T=C===`loading`||C===`generating`||C===`buffering`,E=C===`playing`,D=C===`blocked`,ee=!!d||C===`error`,A=d||o(ee?`ttsButton.playbackFailed`:D?`ttsButton.enableAudio`:E||T?E?`ttsButton.stopSpeaking`:C===`buffering`?`ttsButton.bufferingSpeech`:C===`generating`?`ttsButton.generatingSpeech`:`ttsButton.preparingSpeech`:`ttsButton.readAloud`);return(0,$.jsxs)(`button`,{onClick:b,disabled:!e,title:A,"aria-label":A,"aria-busy":T||void 0,className:O(`inline-flex items-center justify-center rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-hidden focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,ee?`text-red-500 dark:text-red-400`:D?`w-auto gap-1 bg-amber-50 px-2 text-amber-700 dark:bg-amber-900/20 dark:text-amber-300`:E?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,!D&&x[n],D&&n===`sm`&&`h-7`,D&&n===`md`&&`h-8`,D&&n===`lg`&&`h-10`,t),children:[T?(0,$.jsx)(L,{className:O(S[n],`animate-spin`)}):E?(0,$.jsx)(le,{className:S[n]}):ee||D?(0,$.jsx)(be,{className:S[n]}):(0,$.jsx)(W,{className:S[n]}),D&&(0,$.jsx)(`span`,{className:`whitespace-nowrap text-xs font-medium`,children:o(`ttsButton.enableAudioShort`)})]})},qt=80,Jt=5e3,Yt=15e3;function Xt({sessionId:e,messageId:t,thinking:n,isThinking:r,isPrivate:i}){let a=k(e=>e.preferences.titleSettings),o=(0,Q.useRef)(n),[c,l]=(0,Q.useState)(null),{autoTitle:u,taskModel:d,taskProviderType:f,taskProviderId:p}=a??{};return(0,Q.useEffect)(()=>{o.current=n},[n]),(0,Q.useEffect)(()=>{if(!e||!r||i||!u||!d||s())return;let n=!1,a,c=``,m=new AbortController,h=async()=>{let r=(o.current??``).slice(-4e3).trim();if(r.length<qt||r===c){n||(a=setTimeout(()=>void h(),400));return}c=r;let i=Date.now(),s=Jt;try{let i=await Y.summarizeThinking(e,{model:d,thinking:r,providerType:f,providerId:p},m.signal);if(!i.success||!i.data?.summary?.trim())throw Error(`Thinking summary unavailable`);n||l({sessionId:e,messageId:t,summary:i.data.summary.trim().slice(0,160)})}catch{s=Yt}n||(a=setTimeout(()=>void h(),Math.max(0,s-(Date.now()-i))))};return a=setTimeout(()=>void h(),350),()=>{n=!0,clearTimeout(a),m.abort()}},[e,t,r,i,u,d,f,p]),c&&c.sessionId===e&&c.messageId===t?c.summary:null}var Zt=[`accuracy`,`style`,`incomplete`,`harmful`,`formatting`],Qt=c(`components:chat-message`);function $t({role:e,user:t,persona:n,modelAvatar:r}){let{t:i}=w(),[a,o]=(0,Q.useState)(null);if(e===`assistant`){if(n)return(0,$.jsx)(`img`,{src:Xe(n,64),alt:n.name,"data-testid":`chat-assistant-avatar`,onError:e=>qe(e.currentTarget,n.name,64),className:`mt-0.5 h-8 w-8 shrink-0 rounded-lg object-cover`});let e=r?.trim()??``,t=e.startsWith(`data:`)&&e!==a?e:``;return(0,$.jsx)(`div`,{role:`img`,"aria-label":`Libre WebUI`,"data-testid":`chat-assistant-avatar`,className:`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full border border-black/[0.07] bg-white text-gray-900 shadow-xs dark:border-white/9 dark:bg-dark-200 dark:text-dark-950`,children:t?(0,$.jsx)(`img`,{src:t,alt:``,className:`h-full w-full object-cover`,onError:()=>o(e)}):e?(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-base leading-none`,children:e}):(0,$.jsx)(ut,{label:null,className:`h-4 w-4`})})}let s=t?.username||i(`chatMessage.user`),c=t?.avatar?.trim()||``,l=!!c&&c!==a;return(0,$.jsx)(`div`,{role:l?void 0:`img`,"aria-label":l?void 0:s,"data-testid":`chat-user-avatar`,className:O(`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full`,l?`border border-black/[0.07] bg-white dark:border-white/9 dark:bg-dark-200`:`bg-gray-950 text-white dark:bg-white dark:text-gray-950`),title:s,children:l?(0,$.jsx)(`img`,{src:c,alt:s,className:`h-full w-full object-cover`,onError:()=>o(c)}):t?.username?(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-xs font-medium uppercase leading-none`,children:t.username.charAt(0)}):(0,$.jsx)(Ce,{"aria-hidden":`true`,className:`h-4 w-4`})})}var en=Q.memo(({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:i,onFork:a,onEditResend:o})=>{let{t:s,i18n:c}=w(),l=e.role===`user`,u=e.role===`system`,f=u&&d(e.content),p=f?e.content.slice(v.length):e.content,m=k(e=>e.preferences),h=ot(e=>e.user),g=S(e=>e.setSystemMessage),_=S(e=>e.rateMessage),y=S(e=>e.modelMetadata),b=S(e=>e.currentSession?.id),x=S(e=>e.currentSession?.model),C=S(e=>e.currentSession?.isPrivate===!0),T=S(e=>e.getCurrentPersona()),D=e.model||x||``,te=D?y[D]??Object.entries(y).find(([e])=>e.slice(e.indexOf(`/`)+1)===D)?.[1]:void 0,[j,ne]=(0,Q.useState)(!1),[re,ie]=(0,Q.useState)(e.content),[ae,oe]=(0,Q.useState)(null),N=(0,Q.useRef)(null);J(N,{enabled:ae!==null,onClose:()=>oe(null)});let[P,se]=(0,Q.useState)(!1),[F,le]=(0,Q.useState)(!1),[ue,fe]=(0,Q.useState)(!1),L=(0,Q.useId)(),[pe,R]=(0,Q.useState)(`idle`),[he,ve]=(0,Q.useState)(null),[ye,be]=(0,Q.useState)([]),[z,Ce]=(0,Q.useState)(``),[we,Te]=(0,Q.useState)(!1),B=(0,Q.useRef)(null),V=(0,Q.useRef)(0),Oe=(0,Q.useRef)(t),H=(0,Q.useRef)(!1),ke=async()=>{try{await navigator.clipboard.writeText(e.content),lt(`success`),Te(!0),setTimeout(()=>Te(!1),2e3)}catch(e){Qt.error(`Failed to copy message:`,e),I.error(s(`chat.message.copyFailed`))}},{thinkingContent:W,thinkingStreaming:G,parsedContent:K,artifacts:je}=(0,Q.useMemo)(()=>{if(l||u||!e.content&&!e.thinking)return{thinkingContent:null,thinkingStreaming:!1,parsedContent:e.content,artifacts:e.artifacts||[]};let n=e.thinking?{thinking:e.thinking,content:e.content,thinkingComplete:!!e.content||!t}:ee(e.content),r=n.content,i=t&&!n.thinkingComplete;if(e.artifacts&&e.artifacts.length>0)return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:r,artifacts:e.artifacts};if(!t){let e=mt(r);return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:e.content,artifacts:e.artifacts}}return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:r,artifacts:[]}},[e.content,e.thinking,e.artifacts,l,u,t]),Me=G?void 0:e.statistics?.thinking_duration_ms??dt(e.id),Ne=Xt({sessionId:b,messageId:e.id,thinking:W,isThinking:G,isPrivate:C}),Fe=Me===void 0?s(`chatMessage.thinking`):s(`chatMessage.thoughtFor`,{duration:ft(Me)}),Ie=(0,Q.useCallback)(async e=>{let t=V.current+1;V.current=t,B.current?.cancel(),B.current=null,R(`loading`);try{if(e){let n=await e;if(V.current!==t)return;if(n===`blocked`){R(`blocked`);return}}let n=await X.getModels();if(V.current!==t)return;let r=n.success&&n.data?n.data:[],i=m.ttsSettings,a=Ze(r,i?.model,i?.pluginId),o=et(r,i?.model,i?.pluginId),s=a?.model||i?.model||`tts-1`,l=a?.plugin||i?.pluginId,u=o&&i?.voice||a?.config?.default_voice,d=o&&i?.voiceProfileId||void 0,f=Math.max(1,a?.config?.max_characters||600),p=Math.min(f,600),h=i?.streamSentences!==!1||K.length>p?yt(K,{locale:c.language,maxChars:p,targetChars:Math.min(p,420),minChars:Math.min(p,80)}):[K.trim()];if(h.length===0){R(`idle`);return}let g=_t({concurrency:3,initialBufferSize:Math.min(2,h.length),generate:(e,{signal:t})=>X.generate({model:s,pluginId:l,input:e,voice:d?void 0:u||void 0,voiceProfileId:d,speed:i?.speed||1,response_format:a?.config?.default_format},{signal:t}),onStateChange:e=>{V.current===t&&R(e)}});if(V.current!==t){g.cancel();return}B.current=g;let _=xt(g);try{await g.play(h)}finally{_(),B.current===g&&(B.current=null),V.current===t&&(g.state===`ended`||g.state===`cancelled`)&&R(`idle`)}}catch(e){if(V.current!==t)return;gt(e)?R(`idle`):vt(e)?R(`blocked`):(Qt.error(`Auto-play TTS failed:`,e),R(`error`))}},[c.language,K,m.ttsSettings]);(0,Q.useEffect)(()=>{let e=Oe.current&&!t;Oe.current=t,e&&!H.current&&!l&&!u&&K&&m.ttsSettings?.enabled&&m.ttsSettings.autoPlay&&(H.current=!0,Ie())},[t,l,u,K,m.ttsSettings?.autoPlay,m.ttsSettings?.enabled,Ie]),(0,Q.useEffect)(()=>()=>{V.current+=1,B.current?.cancel(),B.current=null},[]);let Le=()=>{let e=bt();Ie(e)},Re=()=>{V.current+=1,B.current?.cancel(),B.current=null,R(`idle`)},ze=()=>f?s(`chatMessage.conversationSummary`):u?s(`chatMessage.system`):l?m.showUsername&&h?.username?h.username:s(`chatMessage.you`):T?.name?T.name:te?.label||D||s(`chatMessage.assistant`),Be=()=>{ne(!0),ie(e.content)},[He,We]=(0,Q.useState)(!1),Ge=async()=>{if(b&&!He){We(!0);try{let t=await Y.restoreCompaction(b,e.id);if(!t.success||!t.data)throw Error(t.error||`Restore failed`);let n=t.data;S.setState(e=>({sessions:e.sessions.map(e=>e.id===n.id?n:e),currentSession:e.currentSession?.id===n.id?n:e.currentSession}))}catch(e){Qt.error(`Failed to restore compacted messages:`,e),I.error(s(`chatMessage.restoreFailed`))}finally{We(!1)}}},qe=async()=>{se(!0);try{g(re),ne(!1),Qt.debug(`✅ System message updated:`,re)}catch(e){Qt.error(`Failed to save system message:`,e)}finally{se(!1)}},Je=()=>{ne(!1),ie(e.content)},Ye=()=>{let t=re.trim();ne(!1),t&&o?.(e.id,t)},Xe=t=>{if(!b)return;let n=e.rating===t;if(_(b,e.id,n?void 0:t),!C){if(n){ve(null),Dt.deleteFeedback(e.id).catch(()=>I.error(s(`chatMessage.feedbackFailed`)));return}be([]),Ce(``),ve(t===1?1:-1),Dt.upsertFeedback({sessionId:b,messageId:e.id,rating:t===1?1:-1}).catch(()=>I.error(s(`chatMessage.feedbackFailed`)))}},Qe=()=>{b&&he!==null&&(Dt.upsertFeedback({sessionId:b,messageId:e.id,rating:he,tags:ye,...z.trim()?{comment:z.trim()}:{}}).catch(()=>I.error(s(`chatMessage.feedbackFailed`))),ve(null))},$e=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,tt=u&&p.length>100;return(0,$.jsxs)(`div`,{className:O(`group flex py-1.5 transition-colors sm:py-2`,l?`justify-end`:`justify-start`,n),children:[(0,$.jsxs)(`div`,{className:O(`flex min-w-0 gap-2.5 sm:gap-3`,l?`max-w-[85%] sm:max-w-[70%]`:`w-full`),children:[!l&&!u&&(0,$.jsx)($t,{role:`assistant`,persona:T,modelAvatar:te?.avatar}),(0,$.jsxs)(`div`,{className:O(`min-w-0 flex-1`,l?`flex flex-col items-end`:u?`py-1.5`:`py-0.5`),children:[!l&&!u&&(0,$.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,$.jsx)(`span`,{dir:`auto`,className:`text-[11px] font-semibold uppercase tracking-[0.08em] text-ink-muted rtl:tracking-normal`,children:ze()}),e.model&&T?.name&&(0,$.jsx)(`span`,{dir:`ltr`,className:`max-w-32 truncate rounded-full bg-gray-100 px-2 py-0.5 text-[10px] text-gray-500 dark:bg-dark-200 dark:text-dark-600 sm:max-w-48`,title:e.model,children:e.model}),(0,$.jsx)(`span`,{dir:`auto`,className:`text-[10px] tabular-nums text-ink-subtle`,children:E(e.timestamp,c.language)})]}),(0,$.jsxs)(`div`,{className:O(!l&&!u&&`text-[0.9375rem] leading-[1.65] text-ink`),children:[e.images&&e.images.length>0&&(0,$.jsx)(`div`,{className:`mb-1.5 grid max-w-lg grid-cols-2 gap-1.5 sm:grid-cols-3`,children:e.images.map((e,t)=>(0,$.jsx)(`div`,{className:`aspect-square overflow-hidden rounded-xl border border-black/6 bg-gray-100 dark:border-white/8 dark:bg-gray-800`,children:(0,$.jsx)(`button`,{type:`button`,className:`block h-full w-full`,"aria-label":s(`chatMessage.openImage`,{number:t+1}),onClick:()=>oe(e),children:(0,$.jsx)(`img`,{src:e,alt:s(`chatMessage.uploadedImageAlt`,{number:t+1}),className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`})})},t))}),l?j?(0,$.jsxs)(`div`,{className:`w-full min-w-[min(28rem,80vw)] rounded-2xl border border-black/8 bg-white p-2 shadow-xs focus-within:border-primary-500 focus-within:ring-2 focus-within:ring-primary-500/30 dark:border-white/8 dark:bg-dark-100`,children:[(0,$.jsx)(`textarea`,{"aria-label":s(`chatMessage.edit`),dir:`auto`,value:re,onChange:e=>ie(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||e.nativeEvent.keyCode===229||(e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),Ye()):e.key===`Escape`&&Je())},autoFocus:!0,className:`min-h-[72px] w-full resize-y rounded-xl border-none bg-transparent p-2 text-[0.9375rem] leading-relaxed text-gray-900 focus:outline-hidden dark:text-dark-900`}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5 px-1 pb-1`,children:[(0,$.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:Je,children:s(`chatMessage.cancelEditing`)}),(0,$.jsx)(q,{type:`button`,size:`sm`,onClick:Ye,children:s(`chatMessage.saveAndSubmit`)})]})]}):(0,$.jsx)(`div`,{"data-user-bubble":``,className:`rounded-2xl rounded-ee-md border border-line bg-surface-subtle px-4 py-2.5 text-ink`,children:(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[0.9375rem] leading-relaxed`,children:e.content})}):u?(0,$.jsxs)(`div`,{className:`relative z-0 rounded-2xl border border-black/6 bg-white/55 p-3 dark:border-white/6 dark:bg-dark-200/45`,children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between text-[10px] font-semibold uppercase tracking-[0.12em] text-gray-500 dark:text-dark-500`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[f?(0,$.jsx)(ge,{className:`h-2.5 w-2.5 opacity-50`}):(0,$.jsx)(me,{className:`h-2.5 w-2.5 opacity-50`}),s(f?`chatMessage.conversationSummary`:`chatMessage.system`)]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:f?(0,$.jsx)(`button`,{onClick:()=>void Ge(),disabled:He,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:s(`chatMessage.restoreCompacted`),"aria-label":s(`chatMessage.restoreCompacted`),children:(0,$.jsx)(Ae,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})}):j?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:qe,disabled:P,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:s(`chatMessage.saveChanges`),"aria-label":s(`chatMessage.saveChanges`),children:(0,$.jsx)(M,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,$.jsx)(`button`,{onClick:Je,disabled:P,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:s(`chatMessage.cancelEditing`),"aria-label":s(`chatMessage.cancelEditing`),children:(0,$.jsx)(U,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,$.jsx)(`button`,{onClick:Be,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-dark-300`,title:s(`chatMessage.editSystemMessage`),"aria-label":s(`chatMessage.editSystemMessage`),children:(0,$.jsx)(Ee,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),j?(0,$.jsx)(`textarea`,{"aria-label":s(`chatMessage.editSystemMessage`),dir:`auto`,value:re,onChange:e=>ie(e.target.value),className:`min-h-[100px] w-full resize-none rounded-xl border border-black/8 bg-white p-3 text-sm text-gray-900 focus:border-transparent focus:outline-hidden focus:ring-2 focus:ring-primary-500 dark:border-white/8 dark:bg-dark-100 dark:text-dark-900 dark:focus:ring-primary-400`,placeholder:s(`chatMessage.systemMessagePlaceholder`),disabled:P}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-xs leading-relaxed text-gray-500 dark:text-dark-600`,children:F?p:$e(p)}),tt&&(0,$.jsx)(`button`,{type:`button`,"aria-expanded":F,onClick:()=>le(!F),className:`mt-2 flex items-center gap-1 text-xs text-ink-muted transition-colors hover:text-ink`,children:F?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_e,{className:`h-3 w-3`}),s(`chatMessage.showLess`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{className:`h-3 w-3`}),s(`chatMessage.showMore`)]})})]})]}):(0,$.jsxs)(`div`,{className:`relative`,children:[(W||G)&&(0,$.jsxs)(`div`,{className:`mb-3 border-s border-gray-200 ps-3 dark:border-dark-300`,children:[(0,$.jsxs)(`button`,{type:`button`,"data-testid":`thinking-toggle`,"aria-expanded":ue,"aria-controls":L,onClick:()=>fe(!ue),className:`flex min-h-11 max-w-full items-center gap-1.5 rounded-md py-2 text-start text-xs text-ink-muted transition-colors hover:text-ink focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/30`,children:[G?(0,$.jsx)(Ue,{"data-testid":`thinking-generation-indicator`}):(0,$.jsx)(Pe,{"aria-hidden":`true`,className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsxs)(`span`,{role:`status`,"aria-live":G?`polite`:`off`,"aria-atomic":`true`,className:`min-w-0 wrap-anywhere`,children:[(0,$.jsx)(`span`,{"data-testid":`thinking-summary`,dir:`auto`,className:O(`block font-medium`,G&&`animate-slide-up [animation-duration:140ms] motion-reduce:animate-none`),children:Ne||(G?`${s(`chatMessage.thinking`)}…`:Fe)},Ne||`thinking`),Ne&&!G&&(0,$.jsx)(`span`,{className:`mt-0.5 block text-ink-subtle`,children:Fe})]}),ue?(0,$.jsx)(_e,{"aria-hidden":`true`,className:`h-3.5 w-3.5 shrink-0`}):(0,$.jsx)(A,{"aria-hidden":`true`,className:`h-3.5 w-3.5 shrink-0`})]}),(0,$.jsx)(`div`,{id:L,"data-testid":`thinking-content`,hidden:!ue,dir:`auto`,className:`mt-2 rounded-xl bg-gray-100/60 p-2.5 text-[13px] leading-relaxed text-gray-600 dark:bg-dark-200/60 dark:text-dark-700`,children:ue&&W&&(0,$.jsx)(Ke,{content:W,isStreaming:G,className:`text-[13px] text-ink-muted`})})]}),(0,$.jsx)(Ke,{content:K,isStreaming:t&&!(G&&!K)})]}),!l&&!u&&je.length>0&&(0,$.jsx)(`div`,{className:`mt-3`,children:(0,$.jsx)(Et,{artifacts:je})}),!l&&!u&&Array.isArray(e.providerMetadata?.toolCalls)&&e.providerMetadata.toolCalls.length>0&&(0,$.jsx)(Lt,{calls:e.providerMetadata.toolCalls,className:`mt-2.5`}),!l&&!u&&Array.isArray(e.providerMetadata?.webSearchSources)&&e.providerMetadata.webSearchSources.length>0&&(0,$.jsxs)(`div`,{className:`mt-2.5 flex flex-wrap items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-[0.12em] text-ink-subtle rtl:tracking-normal`,children:s(`chat.message.sources`,`Sources`)}),e.providerMetadata.webSearchSources.map((e,t)=>typeof e?.url==`string`?(0,$.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,dir:`ltr`,className:`inline-flex max-w-[220px] items-center gap-1 rounded-full border border-gray-200 bg-gray-50 px-2 py-0.5 text-[11px] text-gray-600 transition-colors hover:border-primary-300 hover:text-primary-600 dark:border-dark-300 dark:bg-dark-200 dark:text-dark-700 dark:hover:text-primary-400`,title:e.title||e.url,children:[(0,$.jsx)(`span`,{className:`tabular-nums`,children:t+1}),(0,$.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.url).hostname.replace(/^www\./,``)}catch{return e.url}})()})]},`${e.url}-${t}`):null)]}),!l&&!u&&e.statistics&&(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsx)(zt,{statistics:e.statistics})}),!u&&!t&&(0,$.jsxs)(`div`,{className:O(`flex items-center gap-0.5 text-ink-subtle`,`sm:transition-opacity sm:duration-150 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100`,!l&&[`loading`,`generating`,`buffering`,`blocked`,`playing`].includes(pe)?`sm:opacity-100`:`[@media(hover:hover)]:sm:opacity-0`,l?`mt-1 justify-end`:`mt-1`),children:[l&&(0,$.jsxs)(`span`,{dir:`auto`,className:`me-1 text-[10px] tabular-nums`,title:E(e.timestamp,c.language),children:[ze(),` ·`,` `,E(e.timestamp,c.language)]}),!l&&K&&(0,$.jsx)(Kt,{text:K,size:`sm`,externalPlaybackState:pe,onStopExternal:Re,onRetryExternal:Le,className:O(`transition-colors`,pe===`playing`&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),l&&o&&!j&&(0,$.jsx)(`button`,{onClick:()=>{ie(e.content),ne(!0)},className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:s(`chatMessage.edit`),"aria-label":s(`chatMessage.edit`),children:(0,$.jsx)(Ee,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{type:`button`,onClick:ke,"aria-label":s(we?`chatMessage.copied`:`chatMessage.copyMessage`),className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:s(we?`chatMessage.copied`:`chatMessage.copyMessage`),children:we?(0,$.jsx)(De,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(ce,{className:`h-3.5 w-3.5`})}),!l&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:()=>Xe(1),className:O(`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,e.rating===1&&`text-primary-600 dark:text-primary-400`),title:s(`chatMessage.goodResponse`),"aria-label":s(`chatMessage.goodResponse`),"aria-pressed":e.rating===1,children:(0,$.jsx)(Ve,{className:`h-3.5 w-3.5`,fill:e.rating===1?`currentColor`:`none`})}),(0,$.jsx)(`button`,{onClick:()=>Xe(-1),className:O(`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,e.rating===-1&&`text-red-500 dark:text-red-400`),title:s(`chatMessage.badResponse`),"aria-label":s(`chatMessage.badResponse`),"aria-pressed":e.rating===-1,children:(0,$.jsx)(Se,{className:`h-3.5 w-3.5`,fill:e.rating===-1?`currentColor`:`none`})}),he!==null&&(0,$.jsxs)(`div`,{className:`ms-1 flex flex-wrap items-center gap-1 rounded-lg border border-gray-200 bg-white px-2 py-1 dark:border-dark-300 dark:bg-dark-100`,"data-testid":`feedback-details`,children:[Zt.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>be(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),className:O(`rounded-full border px-2 py-0.5 text-[10px]`,ye.includes(e)?`border-primary-500 bg-primary-50 text-primary-700 dark:bg-primary-950/40 dark:text-primary-300`:`border-gray-300 text-gray-500 dark:border-dark-300`),"aria-pressed":ye.includes(e),children:s(`chatMessage.feedbackTags.${e}`)},e)),(0,$.jsx)(`input`,{value:z,onChange:e=>Ce(e.target.value),placeholder:s(`chatMessage.feedbackComment`),"aria-label":s(`chatMessage.feedbackComment`),className:`w-32 rounded-sm border border-gray-300 px-1.5 py-0.5 text-[10px] focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-dark-300 dark:bg-dark-50`,maxLength:2e3}),(0,$.jsx)(q,{type:`button`,size:`sm`,onClick:Qe,className:`h-6 px-2 text-[10px]`,children:s(`common.save`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>ve(null),"aria-label":s(`common.close`),className:`rounded-sm p-0.5 text-ink-muted hover:text-ink`,children:(0,$.jsx)(U,{className:`h-3 w-3`})})]})]}),!l&&r&&i&&(0,$.jsx)(`button`,{onClick:i,className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:s(`chatMessage.regenerateResponse`),"aria-label":s(`chatMessage.regenerateResponse`),children:(0,$.jsx)(de,{className:`h-3.5 w-3.5`})}),a&&(0,$.jsx)(`button`,{onClick:()=>a(e.id),className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:s(`chat.fork.action`),"aria-label":s(`chat.fork.action`),"data-testid":`fork-from-message`,children:(0,$.jsx)(xe,{className:`h-3.5 w-3.5`})})]})]})]}),l&&(0,$.jsx)($t,{role:`user`,user:h??null})]}),ae&&(0,Nt.createPortal)((0,$.jsxs)(`div`,{ref:N,role:`dialog`,"aria-modal":`true`,"aria-label":s(`chatMessage.fullSizeImage`),tabIndex:-1,className:`fixed inset-0 z-9999 flex items-center justify-center bg-black/85 p-6 backdrop-blur-md`,onClick:()=>oe(null),children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":s(`common.close`),className:`absolute inset-e-6 top-6 rounded-full border border-white/15 bg-white/10 p-3 text-white transition-colors hover:bg-white/20`,onClick:e=>{e.stopPropagation(),oe(null)},children:(0,$.jsx)(U,{className:`h-7 w-7`})}),(0,$.jsx)(`img`,{src:ae,alt:s(`chatMessage.fullSizeImage`),className:`max-h-[90vh] max-w-[90vw] rounded-2xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})});en.displayName=`ChatMessage`;var tn=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,nn=220,rn=e=>{let t=e.slice(0,880).replace(/```(?:\w+)?\s*([\s\S]*?)```/g,`$1`).replace(/!\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/<[^>]+>/g,` `).replace(/[#>*_~`|]/g,` `).replace(/\s+/g,` `).trim();return t.length>nn?`${t.slice(0,219).trimEnd()}…`:t},an=Q.memo(function({items:e,activeId:t,onSelect:n}){let{t:r}=w(),i=(0,Q.useRef)(null),a=(0,Q.useRef)(null),o=(0,Q.useRef)(new Map),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(0),d=(0,Q.useCallback)((e,t)=>{let n=i.current;if(!n)return;let r=n.getBoundingClientRect(),a=t.getBoundingClientRect();u(a.top-r.top+a.height/2),c(e)},[]),f=(0,Q.useCallback)(t=>{let r=e[t],i=r?o.current.get(r.id):void 0;r&&i&&(i.focus(),d(r.id,i),n(r.id))},[e,n,d]);if((0,Q.useEffect)(()=>{if(!t)return;let e=a.current,n=o.current.get(t);if(!e||!n)return;let r=e.getBoundingClientRect(),i=n.getBoundingClientRect(),s=null;i.top<r.top?s=e.scrollTop-(r.top-i.top)-8:i.bottom>r.bottom&&(s=e.scrollTop+(i.bottom-r.bottom)+8),s!==null&&e.scrollTo({top:s,behavior:tn()?`auto`:`smooth`})},[t]),e.length<3)return null;let p=Math.max(0,e.findIndex(e=>e.id===t)),m=e[p]?.id,h=e.findIndex(e=>e.id===s),g=h>=0?e[h]:null,_=h>=0?`conversation-history-preview-${h}`:void 0;return(0,$.jsxs)(`nav`,{ref:i,"data-testid":`conversation-history-rail`,"aria-label":r(`chatHistory.label`),className:`pointer-events-none absolute top-1/2 z-20 hidden h-[min(58vh,30rem)] w-7 -translate-y-1/2 lg:block xl:w-9`,style:{insetInlineStart:`max(0.25rem, calc(50% - 27rem))`},onPointerLeave:()=>{i.current?.contains(document.activeElement)||c(null)},children:[(0,$.jsx)(`ol`,{ref:a,className:`pointer-events-auto flex h-full min-h-0 flex-col overflow-y-auto py-2 scrollbar-none [&::-webkit-scrollbar]:hidden [&>li:first-child]:mt-auto [&>li:last-child]:mb-auto`,children:e.map((t,a)=>{let l=t.id===m,u=Math.abs(a-p),h=s===t.id?_:void 0;return(0,$.jsx)(`li`,{className:`flex h-4 flex-none items-center`,children:(0,$.jsx)(`button`,{ref:e=>{e?o.current.set(t.id,e):o.current.delete(t.id)},type:`button`,"data-testid":`conversation-history-marker`,"aria-current":l?`location`:void 0,"aria-describedby":h,"aria-label":r(`chatHistory.jumpToTurn`,{index:a+1,total:e.length}),tabIndex:a===p?0:-1,className:O(`group flex h-4 w-7 items-center outline-hidden xl:w-9`,`focus-visible:ring-2 focus-visible:ring-primary-500/45 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,`rounded-xs`),onClick:()=>n(t.id),onPointerEnter:e=>d(t.id,e.currentTarget),onFocus:e=>d(t.id,e.currentTarget),onBlur:()=>{window.requestAnimationFrame(()=>{i.current?.contains(document.activeElement)||c(null)})},onKeyDown:t=>{if(t.key===`Escape`){c(null);return}let n=null;t.key===`ArrowDown`?n=Math.min(e.length-1,a+1):t.key===`ArrowUp`?n=Math.max(0,a-1):t.key===`Home`?n=0:t.key===`End`&&(n=e.length-1),n!==null&&(t.preventDefault(),f(n))},children:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:O(`block h-0.5 rounded-full transition-[width,background-color,opacity] duration-150 motion-reduce:transition-none`,l?`w-6 bg-ink xl:w-7`:u===1?`w-3.5 bg-ink-subtle opacity-80 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`:`w-2.5 bg-line-strong opacity-70 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`)})})},t.id)})}),g&&(0,$.jsx)(`div`,{id:_,role:`tooltip`,className:O(`pointer-events-none absolute inset-s-full ms-2 w-72 -translate-y-1/2`,`overflow-hidden rounded-xl border border-line bg-surface-overlay/95 shadow-overlay backdrop-blur-xl`,`animate-fade-in motion-reduce:animate-none`),style:{top:`clamp(3.5rem, ${l}px, calc(100% - 3.5rem))`},children:(0,$.jsxs)(`div`,{className:`px-3.5 py-3`,children:[(0,$.jsx)(`p`,{dir:`auto`,className:`truncate text-[13px] font-semibold leading-5 text-ink`,children:rn(g.prompt)}),g.response&&(0,$.jsx)(`p`,{dir:`auto`,className:`mt-1 line-clamp-3 text-xs leading-5 text-ink-muted`,children:rn(g.response)})]})})]})}),on=Q.memo(({messages:e,isStreaming:t=!1,streamingMessage:n,streamingThinking:r,streamingMessageId:i,isLastAssistantMessage:a=!1,onRegenerate:o,onSelectBranch:s,className:c})=>{let{t:l}=w();if(e.length===1){let s=e[0],l=t&&i===s.id,u=l?{...s,content:n??s.content,thinking:r||s.thinking}:s;return(0,$.jsx)(en,{message:u,isStreaming:l,isLastAssistantMessage:a,onRegenerate:o,className:c})}return(0,$.jsxs)(`div`,{className:O(`relative py-2`,c),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 pb-3 text-[10px] font-medium uppercase tracking-[0.12em] text-ink-muted`,children:[(0,$.jsx)(we,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:l(`chat.branch.variants`,{count:e.length})})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:e.map((e,c)=>{let u=e.isActive!==!1,d=t&&i===e.id,f=d?{...e,content:n??e.content,thinking:r||e.thinking}:e;return(0,$.jsxs)(`div`,{className:O(`relative overflow-hidden rounded-2xl border bg-white/45 transition-colors duration-150 dark:bg-dark-200/35`,u||d?`border-primary-500/30 ring-1 ring-primary-500/10 dark:border-primary-400/30`:`border-black/[0.07] hover:bg-white/80 dark:border-white/[0.07] dark:hover:bg-dark-200/70`,!u&&!d&&`cursor-pointer`),role:!u&&!d?`button`:void 0,tabIndex:!u&&!d?0:void 0,"aria-label":!u&&!d?l(`chat.branch.selectVariant`,{number:c+1}):void 0,"aria-current":u||d?`true`:void 0,onClick:()=>!u&&!d&&s?.(e.id),onKeyDown:t=>{t.target===t.currentTarget&&!u&&!d&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),s?.(e.id))},children:[(0,$.jsxs)(`div`,{className:O(`flex items-center justify-between border-b px-3 py-2 text-[10px] font-medium uppercase tracking-[0.12em]`,u||d?`border-primary-500/10 bg-primary-50/50 text-primary-600 dark:border-primary-400/10 dark:bg-primary-900/10 dark:text-primary-400`:`border-black/5 text-ink-muted dark:border-white/5`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:c+1}),d&&(0,$.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:l(`chat.branch.generating`)})]}),u&&!d&&(0,$.jsx)(De,{className:`h-3 w-3`}),!u&&!d&&(0,$.jsx)(`span`,{className:`text-[10px]`,children:l(`chat.branch.select`)})]}),(0,$.jsx)(`div`,{className:O(!u&&!d&&`opacity-75`),children:(0,$.jsx)(en,{message:f,isStreaming:d,isLastAssistantMessage:a&&(u||d),onRegenerate:u&&!t?o:void 0,className:`px-3 pb-3 text-sm!`})})]},e.id)})})]})});on.displayName=`MessageBranch`;var sn={web_search:ie,web_fetch:Ne,exec:pe,browser:Ne,Read:He,Write:He,Edit:He,image:N,memory_search:H,memory_get:H,working:Me,thinking:Me,default:Me},cn={web_search:`Searching the web`,web_fetch:`Fetching page`,exec:`Running command`,browser:`Using browser`,Read:`Reading file`,Write:`Writing file`,Edit:`Editing file`,image:`Analyzing image`,memory_search:`Searching memory`,memory_get:`Reading memory`,cron:`Managing schedule`,message:`Sending message`,tts:`Generating speech`,nodes:`Checking devices`,sessions_spawn:`Spawning agent`,canvas:`Rendering canvas`,process:`Managing process`,working:`Using tools`,thinking:`Thinking`},ln=({tools:e,className:t})=>{if(e.length===0)return null;let n=e.filter(e=>e.phase!==`result`&&e.phase!==`done`);return n.length===0?null:(0,$.jsx)(`div`,{className:O(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=sn[e.name]||sn.default,n=cn[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,$.jsxs)(`div`,{className:O(`flex items-center gap-2 text-sm transition-all duration-300`,r?`text-green-600 dark:text-green-400 opacity-60`:`text-gray-500 dark:text-gray-400`),children:[(0,$.jsx)(`div`,{className:O(`flex items-center justify-center w-5 h-5`,!r&&`animate-spin-slow`),children:(0,$.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:r?`✓ ${n}`:`${n}…`}),!r&&(0,$.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})]},e.toolCallId)})})};c(`components:chat-messages`);var un=e=>e.messages.find(e=>e.isActive===!0)||e.messages.find(e=>e.isActive!==!1)||e.messages[0],dn=e=>e.messages.every(e=>e.isActive===!1),fn=e=>e.role===`system`&&!d(e.content),pn=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,mn=e=>Math.min(120,e*.28),hn=({messages:e,streamingMessage:t,streamingThinking:n,streamingMessageId:r,isStreaming:i=!1,toolActivities:a=[],activeToolCalls:o,pendingToolApproval:s,onDecideToolApproval:c,className:l,onRegenerate:u,onSelectBranch:d,onEditResend:f,onFork:p,followUpSuggestions:m,onFollowUpSelect:h})=>{let{t:g}=w(),_=(0,Q.useRef)(null),v=(0,Q.useRef)(void 0),y=(0,Q.useRef)(null),b=(0,Q.useRef)(null),[x]=(0,Q.useState)(()=>new Map),S=(0,Q.useRef)(null),C=(0,Q.useRef)(0),T=(0,Q.useRef)(!1),E=(0,Q.useRef)(!1),[D,ee]=(0,Q.useState)(!1),k=(0,Q.useMemo)(()=>{let t=[],n=new Set,r=[...e].sort((e,t)=>fn(e)&&!fn(t)?-1:fn(t)&&!fn(e)?1:e.parentId===t.parentId?(e.branchIndex||0)-(t.branchIndex||0):e.timestamp-t.timestamp);for(let i of r){if(n.has(i.id))continue;let r=i.parentId;if(r){let a=t.findIndex(e=>e.id===r);if(a>=0)t[a].messages.push(i);else{let a=e.find(e=>e.id===r);a&&!n.has(r)?(t.push({id:r,messages:[a,i],messageIndex:t.length}),n.add(r)):t.push({id:i.id,messages:[i],messageIndex:t.length})}n.add(i.id)}else{let r=e.filter(e=>e.parentId===i.id);r.length>0?(t.push({id:i.id,messages:[i,...r],messageIndex:t.length}),n.add(i.id),r.forEach(e=>n.add(e.id))):(t.push({id:i.id,messages:[i],messageIndex:t.length}),n.add(i.id))}}return t.sort((e,t)=>{let n=e.messages[0],r=t.messages[0];return fn(n)&&!fn(r)?-1:fn(r)&&!fn(n)?1:n.timestamp-r.timestamp})},[e]),A=(0,Q.useMemo)(()=>{let e=[];for(let t=0;t<k.length;t++){let n=k[t],r=un(n);if(r.role!==`user`)continue;let i;for(let e=t+1;e<k.length;e++){let t=un(k[e]);if(t.role===`user`)break;if(t.role===`assistant`){i=t.content;break}}e.push({id:n.id,prompt:r.content,response:i})}return e},[k]),te=A.map(e=>e.id).join(``),j=(0,Q.useMemo)(()=>te?te.split(``):[],[te]),ne=(0,Q.useMemo)(()=>new Set(j),[j]),re=(0,Q.useMemo)(()=>{let e=new Map;for(let t of j)e.set(t,e=>{e?x.set(t,e):x.delete(t)});return e},[x,j]),[ie,ae]=(0,Q.useState)(null),oe=(0,Q.useCallback)(()=>{let e=y.current;if(!e||j.length===0){ae(null);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight,n=Math.min(C.current,j.length-1);if(t<=2)n=j.length-1;else{let t=e.scrollTop+mn(e.clientHeight);for(;n<j.length-1;){let e=x.get(j[n+1]);if(!e||e.offsetTop>t)break;n++}for(;n>0;){let e=x.get(j[n]);if(!e||e.offsetTop<=t)break;n--}}C.current=n;let r=j[n];ae(e=>e===r?e:r)},[x,j]),M=(0,Q.useCallback)(()=>{S.current===null&&(S.current=window.requestAnimationFrame(()=>{S.current=null,oe()}))},[oe]),N=(0,Q.useCallback)(()=>{let t=y.current;if(v.current&&clearTimeout(v.current),T.current=!1,v.current=void 0,!t)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight<100;E.current=!n,ee(!n&&e.length>0),M()},[e.length,M]),P=(0,Q.useCallback)(()=>{v.current&&clearTimeout(v.current),v.current=setTimeout(N,180)},[N]),se=(0,Q.useCallback)((e=!1)=>{(!E.current||e)&&_.current?.scrollIntoView({behavior:pn()})},[]),ce=(0,Q.useCallback)(()=>{let t=y.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i,o=a<100;if(T.current){E.current=!0,ee(!o&&e.length>0),M(),P();return}E.current=!o,ee(!o&&e.length>0),a<=2&&j.length>0?(C.current=j.length-1,ae(j[j.length-1])):M()},[j,e.length,P,M]),le=(0,Q.useCallback)(e=>{let t=y.current,n=x.get(e);if(!t||!n)return;let r=pn();T.current=!0,E.current=!0,t.scrollTo({top:Math.max(0,n.offsetTop-mn(t.clientHeight)),behavior:r}),M(),r===`auto`?N():P()},[N,x,P,M]),I=(0,Q.useRef)(e.length);if((0,Q.useEffect)(()=>{e.length>I.current&&!E.current&&se(),I.current=e.length},[e.length,se]),(0,Q.useEffect)(()=>{i&&(t||n)&&!E.current&&requestAnimationFrame(()=>{let e=y.current;e&&(e.scrollTop=e.scrollHeight)})},[i,t,n]),(0,Q.useEffect)(()=>{M();let e=b.current,t=y.current,n=typeof ResizeObserver>`u`?null:new ResizeObserver(M);return e&&n?.observe(e),t&&n?.observe(t),window.addEventListener(`resize`,M),()=>{n?.disconnect(),window.removeEventListener(`resize`,M)}},[te,M]),(0,Q.useEffect)(()=>()=>{S.current!==null&&(window.cancelAnimationFrame(S.current),S.current=null)},[]),(0,Q.useEffect)(()=>()=>{v.current&&clearTimeout(v.current)},[]),e.length===0&&!i)return(0,$.jsx)(`div`,{className:O(`flex-1 flex items-center justify-center p-6 sm:p-10`,l),children:(0,$.jsxs)(`div`,{className:`max-w-sm text-center text-ink-muted`,children:[(0,$.jsx)(`div`,{className:`mx-auto mb-5 flex h-11 w-11 items-center justify-center rounded-2xl border border-black/6 bg-surface/70 text-gray-500 shadow-xs dark:border-white/[0.07] dark:bg-dark-200/70 dark:text-dark-600`,children:(0,$.jsx)(F,{className:`h-4 w-4`})}),(0,$.jsx)(`h3`,{className:`mb-2 text-lg font-medium tracking-[-0.02em] text-gray-900 dark:text-dark-900 sm:text-xl`,children:g(`chatMessage.startConversation`)}),(0,$.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:g(`chatMessage.startConversationDescription`)})]})});let ue=-1;for(let e=k.length-1;e>=0;e--)if(k[e].messages.some(e=>e.role===`assistant`)){ue=e;break}return(0,$.jsxs)(`div`,{className:O(`relative min-h-0 flex-1`,l),style:{WebkitAppRegion:`no-drag`},children:[(0,$.jsx)(`div`,{ref:y,"data-testid":`chat-scroll-viewport`,"aria-busy":i,"data-scroll-fade-top":`40`,"data-scroll-fade-bottom":`72`,onScroll:ce,className:O(`h-full overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-gray-600`,`scrollbar-track-transparent hover:scrollbar-thumb-gray-400 dark:hover:scrollbar-thumb-gray-500`,`overscroll-behavior-y-contain`,`[-webkit-overflow-scrolling:touch]`),style:{WebkitOverflowScrolling:`touch`,overscrollBehaviorY:`contain`},children:(0,$.jsxs)(`div`,{ref:b,className:`mx-auto w-full min-w-0 max-w-3xl px-4 sm:px-6 md:px-8`,children:[k.map((e,a)=>{let o=a===ue,s=ne.has(e.id),c=i&&e.messages.some(e=>e.id===r),l;if(dn(e))l=(0,$.jsx)(`div`,{className:`opacity-55`,children:(0,$.jsx)(en,{message:un(e),isStreaming:!1,isLastAssistantMessage:!1,className:a===0?`mt-3 sm:mt-4`:``})});else if(e.messages.length===1){let s=e.messages[0],c=i&&s.id===r,d=c?{...s,content:t??s.content,thinking:n||s.thinking}:s;l=(0,$.jsx)(en,{message:d,isStreaming:c,isLastAssistantMessage:o,onRegenerate:o?u:void 0,onEditResend:i?void 0:f,onFork:i?void 0:p,className:a===0?`mt-3 sm:mt-4`:``})}else l=(0,$.jsx)(on,{messages:e.messages,isStreaming:c,streamingMessage:c?t:void 0,streamingThinking:c?n:void 0,streamingMessageId:c&&r||void 0,isLastAssistantMessage:o,onRegenerate:o?u:void 0,onSelectBranch:d,className:a===0?`mt-3 sm:mt-4`:``});return(0,$.jsx)(`div`,{className:`[content-visibility:auto] [contain-intrinsic-size:auto_160px]`,ref:re.get(e.id),"data-testid":s?`conversation-turn-anchor`:void 0,"data-history-id":s?e.id:void 0,children:l},e.id)}),i&&(o?.length??0)>0&&(0,$.jsx)(Lt,{calls:o??[],className:`pb-2`}),s&&c&&(0,$.jsx)(Rt,{approval:s,onDecide:c,className:`mb-2`}),i&&a.length>0&&(0,$.jsx)(ln,{tools:a,className:`px-0`}),!i&&m&&m.length>0&&h&&(0,$.jsxs)(`div`,{className:`mt-1 pb-2`,children:[(0,$.jsx)(`p`,{className:`mb-1 text-[11px] font-semibold uppercase tracking-[0.08em] text-ink-subtle`,children:g(`chat.followUp`)}),(0,$.jsx)(`div`,{className:`flex flex-col`,children:m.map(e=>(0,$.jsx)(`button`,{onClick:()=>h(e),dir:`auto`,className:`border-t border-gray-100 py-2 text-start text-[0.9rem] leading-relaxed text-ink-muted transition-colors hover:text-ink dark:border-dark-200`,children:e},e))})]}),(0,$.jsx)(`div`,{ref:_,className:`h-4 sm:h-6`})]})}),(0,$.jsx)(an,{items:A,activeId:ie,onSelect:le}),D&&(0,$.jsxs)(`button`,{type:`button`,"data-testid":`chat-new-messages`,onClick:()=>{T.current=!1,v.current&&=(clearTimeout(v.current),void 0),E.current=!1,_.current?.scrollIntoView({behavior:pn()}),ee(!1)},className:O(`absolute bottom-4 left-1/2 -translate-x-1/2 z-10`,`flex items-center justify-center gap-1.5`,`px-3.5 py-2 rounded-full`,`bg-surface/90 dark:bg-dark-200/90`,`border border-black/[0.07] dark:border-white/8`,`shadow-[0_8px_28px_rgba(15,23,42,0.12)] backdrop-blur-xl`,`text-gray-600 dark:text-dark-600`,`hover:bg-surface-raised dark:hover:bg-dark-200`,`hover:text-gray-900 dark:hover:text-dark-800`,`transition-colors duration-150`),title:g(`chatMessage.scrollToBottom`),children:[(0,$.jsx)(z,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:g(`chatMessage.newMessages`)})]})]})};function gn(e){let t=(e.match(/```/g)||[]).length,n=t%2==1,r=null;if(n){let t=e.lastIndexOf("```");if(t!==-1){let n=e.slice(t+3).match(/^(\w+)/);n&&(r=n[1])}}return{hasCodeBlocks:t>0,isInCodeBlock:n,language:r}}var _n=Q.forwardRef(({value:e,onChange:t,className:n,placeholder:r,disabled:i,onKeyDown:a,dir:o=`auto`,...s},c)=>{let{hasCodeBlocks:l,isInCodeBlock:u,language:d}=(0,Q.useMemo)(()=>gn(e),[e]);return(0,$.jsxs)(`div`,{className:`relative w-full`,children:[(0,$.jsx)(`textarea`,{ref:c,value:e,onChange:t,onKeyDown:a,placeholder:r,disabled:i,dir:o,className:O(`w-full resize-none transition-all duration-200`,u&&[`font-mono text-[13px]`,`bg-gray-50 dark:bg-dark-100/50`,`rounded-lg`],n),...s}),l&&(0,$.jsx)(`div`,{className:`absolute inset-e-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,$.jsxs)(`div`,{className:O(`flex items-center gap-1 px-1.5 py-0.5 rounded-md text-[10px] font-medium`,`bg-gray-100 dark:bg-dark-200`,`text-gray-500 dark:text-gray-400`,`border border-gray-200/50 dark:border-dark-300/50`,u&&`animate-pulse`),children:[(0,$.jsx)(fe,{className:`h-3 w-3`}),d&&(0,$.jsx)(`span`,{children:d}),!d&&u&&(0,$.jsx)(`span`,{children:`code`})]})})]})});_n.displayName=`CodeAwareTextarea`;var vn=c(`components:media-upload`),yn=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:s}=w(),c=(0,Q.useRef)(null),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)([]),h=async r=>{if(!r||a)return;let i=Array.from(r),o=[];for(let t of i)if(t.type.startsWith(`image/`)){let r=await g(t,n-e.length-o.length);r&&o.push(r)}else t.type.includes(`pdf`)||t.type.includes(`text`)?await _(t):I.error(s(`chat.mediaUpload.unsupportedFileType`,{name:t.name}));o.length>0&&t([...e,...o])},g=(e,t)=>t<=0?(I.error(s(`chat.mediaUpload.maxImagesAllowed`,{count:n})),Promise.resolve(null)):e.size>10485760?(I.error(s(`chat.mediaUpload.imageTooLarge`,{name:e.name})),Promise.resolve(null)):new Promise(t=>{let n=new FileReader;n.onload=()=>t(typeof n.result==`string`?n.result:null),n.onerror=()=>{I.error(s(`chat.mediaUpload.readFailed`,{name:e.name})),t(null)},n.readAsDataURL(e)}),_=async e=>{if(e.size>10485760){I.error(s(`documents.fileSizeTooLarge`));return}f(!0);try{let t=await Qe.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;m(e=>[...e,n]),i?.(n),I.success(s(`documents.uploadSuccessWithName`,{name:e.name}))}else I.error(t.error||s(`documents.uploadFailed`))}catch(e){vn.error(`Document upload error:`,e),I.error(s(`documents.uploadFailed`))}finally{f(!1)}},v=e=>{e.preventDefault(),a||u(!0)},y=e=>{e.preventDefault(),u(!1)},b=e=>{e.preventDefault(),u(!1),a||h(e.dataTransfer.files)},x=n=>{t(e.filter((e,t)=>t!==n))},S=async e=>{try{let t=await Qe.deleteDocument(e);t.success?(m(t=>t.filter(t=>t.id!==e)),I.success(s(`documents.removeSuccess`))):I.error(t.error||s(`documents.removeFailed`))}catch(e){vn.error(`Error removing document:`,e),I.error(s(`documents.removeFailed`))}},C=e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]},T=e.length>0||p.length>0;return(0,$.jsxs)(`div`,{className:O(`space-y-3`,o),children:[(0,$.jsxs)(`div`,{className:O(`border-2 border-dashed rounded-xl p-6 transition-all duration-200 cursor-pointer`,`border-gray-300 dark:border-gray-600`,`hover:border-primary-400 dark:hover:border-primary-500`,l&&`border-primary-500 dark:border-primary-400 bg-primary-50/50 dark:bg-primary-900/10`,a&&`opacity-50 cursor-not-allowed`),onDragOver:v,onDragLeave:y,onDrop:b,role:`button`,tabIndex:a?-1:0,"aria-disabled":a||void 0,"aria-label":`${s(`chat.mediaUpload.dropImagesHere`)} ${s(`chat.mediaUpload.browse`)}`,onClick:()=>!a&&c.current?.click(),onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),a||c.current?.click())},children:[(0,$.jsx)(`input`,{ref:c,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{h(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[d?(0,$.jsx)(L,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`,role:`status`,"aria-label":s(`chat.mediaUpload.uploading`)}):(0,$.jsx)(G,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,$.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:[s(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:s(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-ink-muted mt-1`,children:s(`chat.mediaUpload.supportedFormats`)})]})]}),T&&(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,$.jsxs)(`div`,{className:`relative group w-16 h-16 rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,$.jsx)(`img`,{src:e,alt:s(`chat.mediaUpload.uploadAlt`,{number:t+1}),className:`w-full h-full object-cover`}),(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),x(t)},"aria-label":s(`chat.mediaUpload.removeImage`,{number:t+1}),className:`absolute top-0.5 inset-e-0.5 p-0.5 rounded-full bg-black/60 hover:bg-black/80 text-white opacity-0 group-hover:opacity-100 focus-visible:opacity-100 [@media(hover:none)]:opacity-100 transition-opacity`,children:(0,$.jsx)(U,{className:`h-3 w-3`})})]},`img-${t}`)),p.map(e=>(0,$.jsxs)(`div`,{className:`relative group flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[e.fileType===`pdf`?(0,$.jsx)(He,{className:`w-4 h-4 text-red-500 shrink-0`}):(0,$.jsx)(ze,{className:`w-4 h-4 text-blue-500 shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 truncate max-w-[100px]`,children:e.filename}),(0,$.jsx)(`p`,{className:`text-[10px] text-ink-muted`,children:C(e.size)})]}),(0,$.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),S(e.id)},"aria-label":s(`chat.mediaUpload.removeDocument`,{name:e.filename}),className:`p-0.5 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-500 hover:text-red-500 transition-colors`,children:(0,$.jsx)(U,{className:`h-3 w-3`})})]},e.id))]})]})},bn=c(`components:document-indicator`),xn=({sessionId:e,className:t=``})=>{let{t:n}=w(),[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),l=(0,Q.useRef)(null),u=(0,Q.useCallback)(async()=>{try{let t=await Qe.getDocuments();t.success&&t.data&&i(t.data.filter(t=>e&&t.sessionId===e||!t.sessionId&&!t.collectionId))}catch(e){bn.error(`Failed to load documents:`,e)}},[e]);if((0,Q.useEffect)(()=>{let e=setTimeout(()=>void u(),0),t=()=>void u();return window.addEventListener(`libre:documents-updated`,t),()=>{clearTimeout(e),window.removeEventListener(`libre:documents-updated`,t)}},[u]),(0,Q.useEffect)(()=>{if(!a)return;let e=e=>{l.current?.contains(e.target)||(o(!1),c(null))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[a]),r.length===0)return null;let d=async e=>{c(null);try{let t=await Qe.deleteDocument(e);if(!t.success)throw Error(t.error);window.dispatchEvent(new Event(`libre:documents-updated`))}catch(e){bn.error(`Failed to delete document:`,e),j.error(n(`settings.documents.library.deleteFailed`))}},f=r.reduce((e,t)=>e+t.size,0);return(0,$.jsxs)(`div`,{ref:l,className:`relative inline-block ${t}`,children:[a&&(0,$.jsxs)(`div`,{className:`absolute bottom-full left-0 z-50 mb-2 w-80 max-w-[85vw] rounded-xl border border-gray-200 bg-white p-2 shadow-lg dark:border-dark-300 dark:bg-dark-100`,children:[(0,$.jsx)(`p`,{className:`px-2 pb-1.5 pt-1 text-xs font-medium text-gray-500 dark:text-dark-600`,children:n(`chat.documents.title`)}),(0,$.jsx)(`div`,{className:`max-h-56 overflow-y-auto`,children:r.map(e=>(0,$.jsx)(`div`,{className:`flex items-center gap-2 rounded-lg px-2 py-1.5 hover:bg-gray-50 dark:hover:bg-dark-200`,children:s===e.id?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`min-w-0 flex-1 truncate text-xs text-red-700 dark:text-red-300`,children:n(`settings.documents.library.deleteConfirm`,{name:e.filename})}),(0,$.jsx)(`button`,{onClick:()=>void d(e.id),className:`shrink-0 text-xs font-medium text-red-600 underline underline-offset-2 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,children:n(`common.delete`)}),(0,$.jsx)(`button`,{onClick:()=>c(null),className:`shrink-0 text-xs text-gray-500 hover:text-gray-700 dark:text-dark-600 dark:hover:text-dark-800`,children:n(`common.cancel`)})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(He,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`truncate text-xs text-gray-900 dark:text-dark-900`,children:e.filename}),(0,$.jsxs)(`p`,{className:`text-[10px] text-gray-400 dark:text-dark-500`,children:[D(e.size),` · `,e.sessionId?n(`settings.documents.library.chatScope`):n(`settings.documents.library.everyChatScope`)]})]}),(0,$.jsx)(`button`,{onClick:()=>c(e.id),className:`shrink-0 text-gray-400 transition-colors hover:text-red-500 dark:text-dark-500`,title:n(`common.delete`),children:(0,$.jsx)(U,{className:`h-3.5 w-3.5`})})]})},e.id))})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{o(e=>!e),c(null)},className:`
|
|
2
|
+
inline-flex items-center space-x-1 px-2 py-1
|
|
3
|
+
bg-blue-50 dark:bg-blue-900/20
|
|
4
|
+
border border-blue-200 dark:border-blue-800
|
|
5
|
+
rounded-md text-xs
|
|
6
|
+
transition-colors hover:bg-blue-100 dark:hover:bg-blue-900/40
|
|
7
|
+
`,title:`${n(`chat.documents.title`)} - ${D(f)}`,children:[(0,$.jsx)(K,{className:`w-3 h-3 text-blue-600 dark:text-blue-400`}),(0,$.jsxs)(`span`,{className:`text-blue-700 dark:text-blue-300 font-medium`,children:[r.length,` doc`,r.length===1?``:`s`]})]})]})},Sn=c(`components:structured-output`),Cn=[{key:`none`,value:null},{key:`json`,value:`json`},{key:`list`,value:{type:`object`,properties:{items:{type:`array`,items:{type:`string`}}},required:[`items`]}},{key:`summary`,value:{type:`object`,properties:{title:{type:`string`},summary:{type:`string`},key_points:{type:`array`,items:{type:`string`}}},required:[`title`,`summary`,`key_points`]}},{key:`analysis`,value:{type:`object`,properties:{analysis:{type:`string`},pros:{type:`array`,items:{type:`string`}},cons:{type:`array`,items:{type:`string`}},recommendation:{type:`string`}},required:[`analysis`,`pros`,`cons`,`recommendation`]}},{key:`custom`,value:`custom`}],wn=({format:e,onFormatChange:t,className:n})=>{let{t:r}=w(),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(``),c=()=>Cn.map(e=>({key:e.key,label:r(`chat.structuredOutput.${e.key}`),value:e.value,description:r(`chat.structuredOutput.${e.key}Description`)})),l=()=>{let t=c();return e===null?t[0]:e===`json`?t[1]:typeof e==`object`?t.find(t=>typeof t.value==`object`&&JSON.stringify(t.value)===JSON.stringify(e))||{key:`customSchema`,label:r(`chat.structuredOutput.custom`),value:e,description:r(`chat.structuredOutput.customSchema`)}:t[0]},u=e=>{let n=c().find(t=>t.label===e);if(n){if(n.value===`custom`){a(!0);return}a(!1),t(n.value)}};return(0,$.jsxs)(`div`,{className:O(`space-y-3`,n),children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center`,children:[(0,$.jsx)(me,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.title`)})]})}),(0,$.jsx)(Ge,{value:l().label,onChange:e=>u(e.target.value),options:c().map(e=>({value:e.label,label:e.label}))}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:l().description}),i&&(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(We,{value:o,onChange:e=>s(e.target.value),placeholder:`{
|
|
8
|
+
"type": "object",
|
|
9
|
+
"properties": {
|
|
10
|
+
"field1": { "type": "string" },
|
|
11
|
+
"field2": { "type": "number" }
|
|
12
|
+
},
|
|
13
|
+
"required": ["field1"]
|
|
14
|
+
}`,rows:8,className:`font-mono text-sm`}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(q,{onClick:()=>{try{t(JSON.parse(o)),a(!1)}catch(e){Sn.error(`Invalid JSON schema:`,e)}},size:`sm`,disabled:!o.trim(),children:r(`chat.structuredOutput.applySchema`)}),(0,$.jsx)(q,{onClick:()=>{a(!1),s(``)},variant:`outline`,size:`sm`,children:r(`chat.structuredOutput.cancel`)})]})]}),(()=>{let e=l();return!e.value||e.value===`json`?null:(0,$.jsxs)(`div`,{className:`mt-3 p-3 bg-gray-50 dark:bg-gray-800 rounded-md`,children:[(0,$.jsxs)(`div`,{className:`flex items-center mb-2`,children:[(0,$.jsx)(se,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.schemaPreview`)})]}),(0,$.jsx)(`pre`,{className:`text-xs text-gray-700 dark:text-gray-300 overflow-x-auto`,children:JSON.stringify(e.value,null,2)})]})})(),e&&(0,$.jsxs)(`div`,{className:`flex items-center text-xs text-green-600 dark:text-green-400`,children:[(0,$.jsx)(He,{className:`h-3 w-3 mr-1`}),r(`chat.structuredOutput.enabled`)]})]})},Tn=7,En=2*Math.PI*Tn,Dn=e=>`\u2068${e}\u2069`,On=({usage:e,trainedBudget:t})=>{let{t:n,i18n:r}=w(),[i,a]=(0,Q.useState)(!1),o=typeof e.budget==`number`&&e.budget>0,s=e.ratio??0,c=Math.round(s*100),l=e.measured?``:`~`,u=r.language,d=`${l}${g(e.used,u)}`,f=o?n(`chat.context.tokensUsed`,{used:Dn(d),budget:Dn(g(e.budget,u))}):n(`chat.context.tokensUsedNoBudget`,{used:Dn(d)}),p=t===void 0?void 0:n(`chat.context.capped`,{trained:Dn(g(t,u))}),m=[n(`chat.context.title`),o?n(`chat.context.full`,{percent:c}):void 0,f,p].filter(Boolean).join(` `),h=Math.min(s,1);return(0,$.jsxs)(`div`,{className:`relative shrink-0`,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),onFocus:()=>a(!0),onBlur:()=>a(!1),onKeyDown:e=>{e.key===`Escape`&&a(!1)},children:[(0,$.jsxs)(`span`,{role:o?`meter`:`img`,tabIndex:0,"aria-label":m,...o?{"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.min(c,100),"aria-valuetext":m}:{},className:O(`touch-target relative flex h-9 w-9 items-center justify-center rounded-full text-ink-muted outline-hidden`,`transition-colors duration-150 focus-visible:ring-2 focus-visible:ring-primary-500/40`,s>=.8&&s<1&&`text-amber-600 dark:text-amber-400`,s>=1&&`text-red-600 dark:text-red-400`),children:[(0,$.jsxs)(`svg`,{viewBox:`0 0 18 18`,className:`h-4 w-4 -rotate-90`,children:[(0,$.jsx)(`circle`,{cx:`9`,cy:`9`,r:Tn,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,className:`opacity-30`,...o?{}:{strokeDasharray:`2 2`}}),o&&h>0&&(0,$.jsx)(`circle`,{cx:`9`,cy:`9`,r:Tn,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeDasharray:En,strokeDashoffset:En*(1-h)})]}),s>=.8&&(0,$.jsx)(V,{className:`absolute inset-e-0 top-0 h-3 w-3`})]}),i&&(0,$.jsxs)(`div`,{role:`tooltip`,className:O(`pointer-events-none absolute bottom-full left-1/2 z-30 mb-2 -translate-x-1/2`,`whitespace-nowrap rounded-2xl bg-surface/95 px-4 py-3 text-center shadow-lv3 backdrop-blur-xl`,`border border-black/6 dark:border-white/8 dark:bg-dark-100/95`,`animate-scale-in`),children:[(0,$.jsx)(`p`,{className:`text-[13px] text-ink-muted`,children:n(`chat.context.title`)}),o&&(0,$.jsx)(`p`,{className:`text-[13px] text-ink-muted`,children:n(`chat.context.full`,{percent:c})}),(0,$.jsx)(`p`,{className:`text-[13px] tabular-nums text-gray-900 dark:text-dark-900`,children:f}),p&&(0,$.jsx)(`p`,{className:`mt-1 text-[11px] text-ink-muted`,children:p})]})]})},kn=c(`components:prompt-queue`),An=({sessionId:e,queue:t})=>{let{t:n}=w(),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(``),s=t=>ht(e,t),c=async t=>{try{let n=await Y.claimQueuedPrompt(e,t);n.success&&n.data&&s(n.data.queue)}catch(e){kn.error(`Failed to remove queued prompt:`,e)}},l=async(n,r)=>{let i=t.findIndex(e=>e.id===n),a=i+r;if(i===-1||a<0||a>=t.length)return;let o=t.map(e=>e.id);[o[i],o[a]]=[o[a],o[i]];try{let t=await Y.reorderPromptQueue(e,o);t.success&&t.data&&s(t.data.queue)}catch(e){kn.error(`Failed to reorder the prompt queue:`,e)}},u=async t=>{let r=a.trim();if(r)try{let a=await Y.updateQueuedPrompt(e,t,r);a.success&&a.data?(s(a.data.queue),i(null)):I.error(a.error||n(`chat.queue.updateFailed`))}catch(e){kn.error(`Failed to update the queued prompt:`,e),I.error(n(`chat.queue.updateFailed`))}};return t.length===0?null:(0,$.jsxs)(`div`,{className:`mx-auto mb-1.5 w-full max-w-3xl px-1`,"data-testid":`prompt-queue`,children:[(0,$.jsxs)(`p`,{className:`mb-1 flex items-center gap-1.5 px-1 text-[11px] font-medium text-gray-400 dark:text-dark-500`,children:[(0,$.jsx)(he,{className:`h-3 w-3`}),n(`chat.queue.title`,{total:t.length})]}),(0,$.jsx)(`ul`,{className:`space-y-1`,children:t.map((e,s)=>(0,$.jsx)(`li`,{className:`flex items-center gap-1.5 rounded-lg border border-black/6 bg-surface/70 px-2 py-1 dark:border-white/8 dark:bg-dark-200/70`,"data-testid":`prompt-queue-entry`,children:r===e.id?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`input`,{autoFocus:!0,value:a,onChange:e=>o(e.target.value),onKeyDown:t=>{t.key===`Enter`&&u(e.id),t.key===`Escape`&&i(null)},className:`min-w-0 flex-1 bg-transparent text-[13px] text-gray-900 focus:outline-hidden dark:text-dark-900`,"data-testid":`prompt-queue-edit-input`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void u(e.id),className:`rounded-md p-1 text-green-600 hover:bg-green-50 dark:hover:bg-green-900/20`,"aria-label":n(`common.save`),children:(0,$.jsx)(De,{className:`h-3.5 w-3.5`})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] text-gray-700 dark:text-dark-800`,children:e.content}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void l(e.id,-1),disabled:s===0,className:`rounded-md p-1 text-gray-400 hover:text-gray-700 disabled:opacity-30 dark:text-dark-500 dark:hover:text-dark-800`,"aria-label":n(`chat.queue.moveUp`),children:(0,$.jsx)(ye,{className:`h-3 w-3`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void l(e.id,1),disabled:s===t.length-1,className:`rounded-md p-1 text-gray-400 hover:text-gray-700 disabled:opacity-30 dark:text-dark-500 dark:hover:text-dark-800`,"aria-label":n(`chat.queue.moveDown`),children:(0,$.jsx)(z,{className:`h-3 w-3`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{i(e.id),o(e.content)},className:`rounded-md p-1 text-gray-400 hover:text-gray-700 dark:text-dark-500 dark:hover:text-dark-800`,"aria-label":n(`common.edit`),children:(0,$.jsx)(Fe,{className:`h-3 w-3`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void c(e.id),className:`rounded-md p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,"aria-label":n(`common.delete`),children:(0,$.jsx)(U,{className:`h-3 w-3`})})]})},e.id))})]})},jn=(e,t)=>{let n=[];for(let r of t){let t=C(e,r);t&&n.push({model:t.model,providerType:t.providerType??null,providerId:t.providerId??null})}return n},Mn=({models:e,currentModelKey:t,selectedKeys:n,onChange:r,disabled:i=!1})=>{let{t:a}=w(),[o,s]=(0,Q.useState)(!1),c=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!o)return;let e=e=>{c.current?.contains(e.target)||s(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[o]);let l=e.filter(h).map(e=>({model:e,key:_(e)})).filter(e=>e.key!==t);if(l.length===0)return null;let u=e=>{n.includes(e)?r(n.filter(t=>t!==e)):n.length<3&&r([...n,e])};return(0,$.jsxs)(`div`,{className:`relative`,ref:c,children:[(0,$.jsxs)(q,{type:`button`,variant:`ghost`,size:`sm`,disabled:i,onClick:()=>s(e=>!e),className:O(`h-9 w-9 p-0 rounded-full shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,n.length>0&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:a(`chat.compare.title`),"aria-pressed":n.length>0,"aria-expanded":o,"data-testid":`composer-compare-toggle`,children:[(0,$.jsx)(oe,{className:`h-4 w-4`}),n.length>0&&(0,$.jsxs)(`span`,{className:`absolute -inset-e-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-md bg-primary-500 px-1 text-[9px] font-semibold tabular-nums text-white`,children:[`+`,n.length]})]}),o&&(0,$.jsxs)(`div`,{className:`absolute bottom-full inset-s-0 z-30 mb-2 max-h-72 w-72 overflow-y-auto rounded-xl border border-gray-200 bg-white p-2 shadow-lg scrollbar-thin dark:border-dark-200 dark:bg-dark-50`,role:`menu`,"data-testid":`composer-compare-menu`,children:[(0,$.jsx)(`p`,{className:`px-2 pb-1.5 pt-1 text-[11px] font-medium text-gray-400 dark:text-dark-500`,children:a(`chat.compare.hint`,{max:3})}),l.map(({model:e,key:t})=>{let r=n.includes(t),i=!r&&n.length>=3;return(0,$.jsxs)(`label`,{className:O(`flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-[13px] text-gray-800 hover:bg-gray-50 dark:text-dark-800 dark:hover:bg-dark-100`,i&&`cursor-not-allowed opacity-40`),children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:r,disabled:i,onChange:()=>u(t),className:`h-3.5 w-3.5 rounded-sm border-gray-300 text-primary-600 focus:ring-primary-500 dark:border-dark-400`}),(0,$.jsx)(`span`,{dir:`ltr`,className:`min-w-0 flex-1 truncate`,children:e.name})]},t)})]})]})},Nn=`pdf.txt.text.log.md.markdown.mdx.html.htm.xhtml.docx.pptx.xlsx.csv.tsv.ts.tsx.js.jsx.mjs.cjs.py.rb.go.rs.java.kt.swift.c.h.cc.cpp.hpp.cs.php.sh.bash.zsh.sql.r.scala.lua.pl.json.yaml.yml.toml.ini.css.scss.less.xml.graphql.proto.tf.dockerfile.png.jpg.jpeg.webp.gif.wav.webm`.split(`.`).map(e=>`.${e}`).join(`,`),Pn=/^\/([a-z0-9-]*)$/,Fn=/(?:^|\s)\$([a-z0-9-]*)$/,In=8,Ln=(e,t,n)=>e.replace(/\{\{\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\}\}/g,(e,r)=>{let i=t.find(e=>e.name===r);if(!i)return e;let a=n[r];return a!==void 0&&a!==``?a:i.default??``}),Rn=({prompt:e,onCancel:t,onInsert:n})=>{let{t:r}=w(),[i,a]=(0,Q.useState)(()=>Object.fromEntries(e.variables.map(e=>[e.name,e.default??(e.type===`boolean`?`false`:``)]))),o=e.variables.filter(e=>e.required===!0&&(i[e.name]===void 0||i[e.name]===``));return(0,$.jsxs)(`div`,{className:`p-3`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-gray-700 dark:text-gray-200`,children:r(`composer.variables.title`,{title:e.title})}),(0,$.jsx)(`div`,{className:`mt-2 flex max-h-56 flex-col gap-2 overflow-y-auto`,children:e.variables.map(e=>(0,$.jsxs)(`label`,{className:`flex flex-col gap-1 text-xs`,children:[(0,$.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,dir:`ltr`,children:[e.label||e.name,e.required?` *`:``]}),e.type===`select`?(0,$.jsxs)(`select`,{value:i[e.name]??``,onChange:t=>a(n=>({...n,[e.name]:t.target.value})),className:`rounded-md border border-gray-300 bg-white px-2 py-1.5 text-sm dark:border-dark-300 dark:bg-dark-100`,children:[(0,$.jsx)(`option`,{value:``,children:`—`}),(e.options??[]).map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))]}):e.type===`boolean`?(0,$.jsxs)(`select`,{value:i[e.name]??`false`,onChange:t=>a(n=>({...n,[e.name]:t.target.value})),className:`rounded-md border border-gray-300 bg-white px-2 py-1.5 text-sm dark:border-dark-300 dark:bg-dark-100`,children:[(0,$.jsx)(`option`,{value:`true`,children:r(`common.yes`)}),(0,$.jsx)(`option`,{value:`false`,children:r(`common.no`)})]}):(0,$.jsx)(`input`,{type:e.type===`number`?`number`:`text`,value:i[e.name]??``,onChange:t=>a(n=>({...n,[e.name]:t.target.value})),className:`rounded-md border border-gray-300 bg-white px-2 py-1.5 text-sm dark:border-dark-300 dark:bg-dark-100`})]},e.name))}),(0,$.jsxs)(`div`,{className:`mt-3 flex items-center justify-end gap-2`,children:[(0,$.jsx)(q,{size:`sm`,variant:`ghost`,onClick:t,children:r(`composer.variables.cancel`)}),(0,$.jsx)(q,{size:`sm`,disabled:o.length>0,title:o.length>0?r(`composer.variables.required`,{name:o[0]?.name??``}):void 0,onClick:()=>n(Ln(e.content,e.variables,i)),children:r(`composer.variables.insert`)})]})]})},zn=(0,Q.forwardRef)(({message:e,disabled:t=!1,onApply:n},r)=>{let{t:i}=w(),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(0),[d,f]=(0,Q.useState)(null),p=(0,Q.useRef)({prompts:!1,skills:!1}),m=t?null:Pn.exec(e),h=t||m?null:Fn.exec(e),g=m!==null,_=h!==null;(0,Q.useEffect)(()=>{g&&!p.current.prompts&&(p.current.prompts=!0,tt.list().then(e=>{o(t=>e.success&&e.data?e.data:t??[])}).catch(()=>o(e=>e??[])).finally(()=>{p.current.prompts=!1}))},[g]),(0,Q.useEffect)(()=>{_&&!p.current.skills&&(p.current.skills=!0,Ye.list().then(e=>{c(t=>e.success&&e.data?e.data:t??[])}).catch(()=>c(e=>e??[])).finally(()=>{p.current.skills=!1}))},[_]);let v=(0,Q.useMemo)(()=>{if(m){let e=m[1];return(a??[]).filter(t=>t.slug.startsWith(e)).slice(0,In).map(e=>({kind:`prompt`,key:e.id,slug:e.slug,label:e.title,detail:e.description,prompt:e}))}if(h){let e=h[1];return(s??[]).filter(t=>t.enabled&&t.slug.startsWith(e)).slice(0,In).map(e=>({kind:`skill`,key:e.id,slug:e.slug,label:e.name,detail:e.description,skill:e}))}return[]},[m,h,a,s]),[y,b]=(0,Q.useState)(e);e!==y&&(b(e),u(0),!m&&d&&f(null));let x=t=>{let r=v[t];if(r){if(r.kind===`prompt`){if(r.prompt.variables.length>0){f(r.prompt);return}n(r.prompt.content);return}if(h){let t=e.length-(h[1].length+1);n(`${e.slice(0,t)}$${r.slug} `)}}};if((0,Q.useImperativeHandle)(r,()=>({handleKeyDown(t){return d?t.key===`Escape`?(t.preventDefault(),f(null),!0):t.key===`Enter`:v.length===0?!1:t.key===`ArrowDown`?(t.preventDefault(),u(e=>(e+1)%v.length),!0):t.key===`ArrowUp`?(t.preventDefault(),u(e=>(e-1+v.length)%v.length),!0):t.key===`Enter`||t.key===`Tab`?(t.preventDefault(),x(l),!0):t.key===`Escape`&&(t.preventDefault(),n(e),!0)}})),d)return(0,$.jsx)(`div`,{className:`absolute bottom-full left-0 z-30 mb-2 w-full max-w-md rounded-xl border border-gray-200 bg-white shadow-lg dark:border-dark-200 dark:bg-dark-50`,"data-testid":`composer-variable-form`,children:(0,$.jsx)(Rn,{prompt:d,onCancel:()=>f(null),onInsert:e=>{f(null),n(e)}})});let S=m?`prompt`:h?`skill`:null,C=m?a!==null:s!==null,T=m?m[1]===``:h?h[1]===``:!1;return v.length===0?S&&C&&T?(0,$.jsx)(`div`,{className:`absolute bottom-full left-0 z-30 mb-2 w-full max-w-md rounded-xl border border-gray-200 bg-white px-3 py-2 text-xs text-gray-500 shadow-lg dark:border-dark-200 dark:bg-dark-50 dark:text-gray-400`,"data-testid":`composer-suggestions-empty`,children:i(S===`prompt`?`composer.promptMenu.empty`:`composer.skillMenu.empty`)}):null:(0,$.jsx)(`div`,{role:`listbox`,"aria-label":i(m?`composer.promptMenu.label`:`composer.skillMenu.label`),className:`absolute bottom-full left-0 z-30 mb-2 w-full max-w-md overflow-hidden rounded-xl border border-gray-200 bg-white shadow-lg dark:border-dark-200 dark:bg-dark-50`,"data-testid":`composer-suggestions`,children:v.map((e,t)=>(0,$.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t===l,onMouseEnter:()=>u(t),onMouseDown:e=>{e.preventDefault(),x(t)},className:O(`flex w-full items-center gap-2 px-3 py-2 text-left text-sm`,t===l?`bg-gray-100 dark:bg-dark-200`:`bg-transparent`),children:[e.kind===`prompt`?(0,$.jsx)(B,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}):(0,$.jsx)(F,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,$.jsxs)(`span`,{className:`font-mono text-xs text-gray-500`,dir:`ltr`,children:[e.kind===`prompt`?`/`:`$`,e.slug]}),(0,$.jsx)(`span`,{className:`truncate text-gray-700 dark:text-gray-200`,children:e.label}),e.detail&&(0,$.jsx)(`span`,{className:`ml-auto hidden max-w-[40%] truncate text-xs text-gray-400 sm:block`,children:e.detail})]},e.key))})});zn.displayName=`ComposerSuggestions`;var Bn=(e,t,n)=>{let r=new Set(e??t);r.has(n)?r.delete(n):r.add(n);let i=t.filter(e=>r.has(e));return i.length===t.length?null:i},Vn=({value:e,onChange:t,disabled:n=!1,buttonClassName:r})=>{let{t:i}=w(),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(!1),d=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=!1;return Je.getCatalog().then(t=>{!e&&t.success&&t.data&&(u(t.data.available&&t.data.tools.length>0),c(t.data.tools))}).catch(()=>{}),()=>{e=!0}},[a]),(0,Q.useEffect)(()=>{if(!a)return;let e=e=>{d.current?.contains(e.target)||o(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[a]);let[f,p]=(0,Q.useState)(void 0);if((0,Q.useLayoutEffect)(()=>{if(!a)return;let e=()=>{let e=d.current;if(!e)return;let t=e.getBoundingClientRect().top,n=0;for(let t=e.parentElement;t&&t!==document.body;t=t.parentElement){let{overflowY:e,overflowX:r}=getComputedStyle(t);(e!==`visible`||r!==`visible`)&&(n=Math.max(n,t.getBoundingClientRect().top))}p(Math.max(160,Math.floor(t-n-24)))};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[a]),!l||!s)return null;let m=s.filter(e=>e.source===`builtin`),h=new Map;for(let e of s)e.serverId&&h.set(e.serverId,e.serverName??e.serverId);let g=[...h.entries()],_=m.map(e=>e.name),v=g.map(([e])=>e),y=new Set(e.builtinTools??_),b=new Set(e.serverIds??v),x=(n,r,i,a,o)=>(0,$.jsxs)(`label`,{className:O(`flex cursor-pointer items-start gap-2 rounded-lg px-2 py-1.5 text-sm hover:bg-gray-50 dark:hover:bg-dark-100`,!e.enabled&&`opacity-50`),onClickCapture:e.enabled?void 0:n=>{n.preventDefault(),n.stopPropagation(),t({...e,enabled:!0})},children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:a,disabled:!e.enabled,onChange:o,"data-testid":`composer-tool-option`,className:`mt-0.5 h-3.5 w-3.5 accent-primary-600`}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block truncate text-gray-800 dark:text-gray-200`,dir:`ltr`,children:r}),i&&(0,$.jsx)(`span`,{className:`block truncate text-xs text-gray-500 dark:text-gray-400`,children:i})]})]},n);return(0,$.jsxs)(`div`,{ref:d,className:`relative shrink-0`,children:[(0,$.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,disabled:n,onClick:()=>o(e=>!e),className:O(`h-9 w-9 p-0 rounded-full shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,e.enabled&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`,r),title:e.enabled?i(`chat.input.toolsOn`):i(`chat.input.toolsOff`),"aria-pressed":e.enabled,"aria-expanded":a,"data-testid":`composer-tools-button`,children:(0,$.jsx)(Me,{className:`h-4 w-4`})}),a&&(0,$.jsxs)(`div`,{className:`absolute bottom-full inset-s-0 z-30 mb-2 flex w-72 flex-col rounded-xl border border-gray-200 bg-white p-2 shadow-lg dark:border-dark-200 dark:bg-dark-50`,style:{maxHeight:f},"data-testid":`composer-tools-menu`,children:[(0,$.jsxs)(`label`,{className:`flex shrink-0 cursor-pointer items-center justify-between gap-2 rounded-lg px-2 py-1.5 text-sm font-medium text-gray-800 dark:text-gray-200`,children:[i(`composer.toolsMenu.enable`),(0,$.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:()=>t({...e,enabled:!e.enabled}),"data-testid":`composer-tools-enable`,className:`h-3.5 w-3.5 accent-primary-600`})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,"data-testid":`composer-tools-options`,children:[m.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`mt-1 px-2 text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500 rtl:tracking-normal`,children:i(`composer.toolsMenu.builtin`)}),m.map(n=>x(n.name,n.name,void 0,y.has(n.name),()=>t({...e,enabled:!0,builtinTools:Bn(e.builtinTools,_,n.name)})))]}),g.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`mt-1 px-2 text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500 rtl:tracking-normal`,children:i(`composer.toolsMenu.servers`)}),g.map(([n,r])=>x(n,r,void 0,b.has(n),()=>t({...e,enabled:!0,serverIds:Bn(e.serverIds,v,n)})))]})]}),(0,$.jsx)(`p`,{className:`mt-1 shrink-0 border-t border-gray-100 px-2 pb-0.5 pt-1.5 text-[11px] leading-4 text-gray-400 dark:border-dark-200 dark:text-dark-500`,children:i(`composer.toolsMenu.hint`)})]})]})},Hn={enabled:!1,builtinTools:null,serverIds:null},Un=e=>{if(!e.enabled)return{};let t={...e.builtinTools===null?{}:{builtinTools:e.builtinTools},...e.serverIds===null?{}:{serverIds:e.serverIds}};return{tools:!0,...Object.keys(t).length>0?{toolSelection:t}:{}}},Wn=c(`components:chat-input`),Gn=560,Kn=({onSendMessage:e,onStopGeneration:t,onCancelComparison:n,onOpenVoiceMode:r,disabled:i=!1})=>{let{t:a}=w(),[o,s]=(0,Q.useState)(``),c=(0,Q.useRef)(``),[l,d]=(0,Q.useState)([]),[f,h]=(0,Q.useState)(null),[g,v]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(!1),[D,ee]=(0,Q.useState)(!1),[A,ne]=(0,Q.useState)(!1),[re,ie]=(0,Q.useState)([]),ae=S(e=>e.pendingComparisons),[oe,M]=(0,Q.useState)(Hn),P=S(e=>e.currentSession?.isPrivate===!0);(0,Q.useEffect)(()=>{let e=!1;return rt.getConfig().then(t=>{!e&&t.success&&t.data&&ee(t.data.allowed)}).catch(()=>{}),()=>{e=!0}},[]);let[se,F]=(0,Q.useState)(null),[ce,I]=(0,Q.useState)(!1),[ue,de]=(0,Q.useState)([]),[fe,pe]=(0,Q.useState)(!1),[R,me]=(0,Q.useState)(!1),[he,ge]=(0,Q.useState)(null),[_e,ve]=(0,Q.useState)(!1),be=(0,Q.useRef)(null),xe=(0,Q.useRef)(null),Se=(0,Q.useRef)(null),[z,Ce]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=Se.current;if(!e)return;let t=new ResizeObserver(t=>{let n=t[0]?.contentRect.width??e.clientWidth;Ce(n<Gn)});return t.observe(e),()=>t.disconnect()},[]);let{isGenerating:we}=k(),Ee=k(e=>e.preferences.generationOptions),B=k(e=>e.preferences.imageGenSettings?.enabled===!0),V=B&&_e,{currentSession:H,models:ke}=S(),Ae=k(e=>H?.model?e.preferences.modelGenerationOptions?.[H.model]:void 0),W=H?.id,[G,je]=(0,Q.useState)(W);G!==W&&(je(W),ie([]));let Me=(0,Q.useRef)(null),Pe=(0,Q.useRef)(null),Fe=(0,Q.useMemo)(()=>({model:H?.personaId?`persona:${H.personaId}`:H?.model||``,providerType:H?.providerType,providerId:H?.providerId}),[H?.model,H?.personaId,H?.providerId,H?.providerType]),Ie=(0,Q.useMemo)(()=>u(ke,Fe),[ke,Fe]),ze=Fe.model?b(Ie,Fe):``,Ve=m(ke,Fe);(0,Q.useEffect)(()=>{let e=!1;return B&&(async()=>{try{let t=await it.getPlugins();if(e)return;ve(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;ve(!1)}})(),()=>{e=!0}},[B]),(0,Q.useEffect)(()=>{if(!T)return;let e=e=>{be.current&&!be.current.contains(e.target)&&(E(!1),F(null))},t=e=>{e.key!==`Escape`||e.defaultPrevented||(E(!1),F(null),I(!1),be.current?.querySelector(`button`)?.focus())};return window.addEventListener(`mousedown`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`mousedown`,e),window.removeEventListener(`keydown`,t)}},[T]);let J=()=>{E(!1),F(null),I(!1)};(0,Q.useEffect)(()=>{if(!ce)return;let e=!1;return Qe.getCollections().then(t=>{!e&&t.success&&t.data&&de(t.data)}).catch(()=>{}),()=>{e=!0}},[ce]);let Ue=H?.settings?.generationOptions?.think,We=Ae?.think??Ee?.think??null,Ge=(0,Q.useMemo)(()=>ke.find(e=>e.name===H?.model),[ke,H?.model]),[Ke,qe]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{let e=H?.model;if(!e||ke.length===0||!Ge||Ge.isPlugin||Ge.isAgent)return;let t=!1;return at.getModelDefaults(e).then(n=>{!t&&n.success&&n.data&&qe({model:e,supportsThinking:n.data.supportsThinking,options:n.data.options??{},trainedContextLength:n.data.trainedContextLength,contextCapped:n.data.contextCapped})}).catch(()=>{}),()=>{t=!0}},[Ge,H?.model,ke.length]);let X=Ke?.model===H?.model?Ke:null,Je=X?.supportsThinking,Ye=!!(H&&!Ge?.isAgent&&(Ge?.isPlugin?Ge.reasoningSupport!==!1:Je!==!1)),Xe=y({model:Ge,sessionOptions:H?.settings?.generationOptions,pinnedOptions:Ae,modelDefaults:X?.options,globalOptions:Ee}),Ze=S(e=>e.contextWindowMessages),et=(0,Q.useMemo)(()=>x({messages:H?.messages??[],budget:Xe,systemPrompt:he?.parameters?.system_prompt,windowMessages:Ze}),[Xe,Ze,he,H?.messages]),tt=(e,t,n)=>{let r=e=>({...e,[t]:n});S.setState(t=>({currentSession:t.currentSession?.id===e?{...t.currentSession,settings:r(t.currentSession.settings)}:t.currentSession,sessions:t.sessions.map(t=>t.id===e?{...t,settings:r(t.settings)}:t)}))},nt=async e=>{if(!H)return;let t={...H.settings?.generationOptions??{}};e===null?delete t.think:t.think=e;let n={...H.settings,generationOptions:t};if(S.setState(e=>({currentSession:e.currentSession?.id===H.id?{...e.currentSession,settings:n}:e.currentSession,sessions:e.sessions.map(e=>e.id===H.id?{...e,settings:n}:e)})),!H.isPrivate)try{await Y.updateSession(H.id,{settings:n})}catch(e){Wn.error(`Failed to update the thinking setting:`,e),tt(H.id,`generationOptions`,H.settings?.generationOptions),j.error(a(`chat.input.thinkingUpdateFailed`))}},ot=H?.settings?.knowledgeCollectionIds??[],st=async e=>{if(!H)return;let t=ot.includes(e)?ot.filter(t=>t!==e):[...ot,e],n={...H.settings,knowledgeCollectionIds:t.length>0?t:void 0};if(S.setState(e=>({currentSession:e.currentSession?.id===H.id?{...e.currentSession,settings:n}:e.currentSession,sessions:e.sessions.map(e=>e.id===H.id?{...e,settings:n}:e)})),!H.isPrivate)try{await Y.updateSession(H.id,{settings:n})}catch(e){Wn.error(`Failed to update knowledge collections:`,e),tt(H.id,`knowledgeCollectionIds`,H.settings?.knowledgeCollectionIds),j.error(a(`chat.input.menu.attachFailed`))}},Z=At({onStart:()=>{c.current=o},onText:e=>{let t=c.current;s(t?`${t} ${e}`:e)},ownerKey:W}),ct=Z.phase===`starting`,lt=Z.phase===`recording`,ut=Z.phase===`transcribing`,dt=Z.supported,ft=Z.providerModel,pt=Z.sources.filter(e=>e.kind===`provider`),mt=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t){J(),me(!0);try{let e=await Qe.uploadDocument(t,H?.id);e.success?(j.success(a(`chat.input.menu.documentAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`))):j.error(e.error||a(`chat.input.menu.attachFailed`))}catch(e){Wn.error(`Document upload failed:`,e),j.error(a(`chat.input.menu.attachFailed`))}finally{me(!1)}}},gt=async()=>{let e=se?.trim();if(e&&!fe){pe(!0);try{let t=await Qe.fetchWebpage(e,H?.id);t.success?(j.success(a(`chat.input.menu.webpageAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`)),J()):j.error(t.error||a(`chat.input.menu.attachFailed`))}catch(e){let t=e?.response?.data?.error||a(`chat.input.menu.attachFailed`);Wn.error(`Webpage attach failed:`,e),j.error(t)}finally{pe(!1)}}},_t=async e=>{if(W&&!P)try{let t=await Y.enqueuePrompt(W,e);t.success&&t.data?(ht(W,t.data.queue),s(``)):j.error(t.error||a(`chat.queue.enqueueFailed`))}catch(e){let t=e?.response?.data?.error||a(`chat.queue.enqueueFailed`);Wn.error(`Failed to queue the prompt:`,e),j.error(t)}},vt=t=>{if(t.preventDefault(),!o.trim())return;if(we){l.length===0&&!P&&W&&_t(o.trim());return}if(!Ve){j.error(a(`chat.model.selectBeforeSending`));return}let n=P?{}:Un(oe),r=P?[]:jn(ke,re);e(o.trim(),l.length>0?l:void 0,f||void 0,D&&A?!0:void 0,n.tools,n.toolSelection,r.length>0?r:void 0),s(``),d([])},yt=e=>{e.nativeEvent.isComposing||e.nativeEvent.keyCode===229||Pe.current?.handleKeyDown(e)||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),vt(e))},xt=()=>{t()};(0,Q.useEffect)(()=>{let e=Me.current;e&&(e.style.height=`auto`,e.style.height=o?`${Math.min(e.scrollHeight,200)}px`:``)},[o]),(0,Q.useEffect)(()=>{(async()=>{if(H?.personaId)try{let e=await $e.getPersona(H.personaId);if(e.success&&e.data)ge(e.data);else{Wn.warn(`Persona ${H.personaId} not found, clearing reference`),ge(null);let{setCurrentSession:e}=S.getState();e({...H,personaId:void 0})}}catch(e){if(Wn.error(`Failed to load current persona:`,e),ge(null),H){let{setCurrentSession:e}=S.getState();e({...H,personaId:void 0})}}else ge(null)})()},[H?.personaId]);let St=async e=>{let t=C(Ie,e.target.value);if(t&&H)try{if(t.model.startsWith(`persona:`)){let e=t.model.slice(8),n=await $e.getPersona(e);if(!n.success||!n.data){j.error(a(`chat.persona.loadFailed`));return}let r=await Y.updateSession(H.id,{personaId:e,model:t.model,providerType:`ollama`,providerId:null});if(r.success&&r.data){let{sessions:e}=S.getState(),t=e.map(e=>e.id===H.id?r.data:e);S.setState({sessions:t,currentSession:r.data}),j.success(a(`chat.persona.applied`))}}else{let e=await Y.updateSession(H.id,{model:t.model,providerType:t.providerType,providerId:(t.providerType===`plugin`||t.providerType===`agent`)&&t.providerId||null,personaId:null});if(e.success&&e.data){let{sessions:t}=S.getState(),n=t.map(t=>t.id===H.id?e.data:t);S.setState({sessions:n,currentSession:e.data}),j.success(a(`chat.model.updated`))}}}catch(e){Wn.error(`Failed to update session:`,e),j.error(a(`chat.toasts.updateFailed`))}},Ct=l.length>0||f!==null,wt=a(A?`chat.input.webSearchOn`:`chat.input.webSearchOff`),Tt=ut||ct?a(`common.cancel`):lt?a(`chat.input.voiceStop`):ft?a(`chat.input.providerTranscriptionDisclosure`,{provider:ft.plugin}):a(`chat.input.voiceInput`);return(0,$.jsx)(`div`,{className:`pointer-events-none`,children:(0,$.jsxs)(`div`,{ref:Se,className:`pointer-events-auto mx-auto w-full max-w-3xl px-4 sm:px-6 md:px-8`,children:[g&&(0,$.jsxs)(`div`,{className:`mb-2 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/90 p-4 shadow-[0_12px_40px_rgba(15,23,42,0.08)] backdrop-blur-xl dark:border-white/8 dark:bg-dark-200/90`,children:[(0,$.jsx)(yn,{images:l,onImagesChange:d,maxImages:5,sessionId:H?.id,disabled:i}),(0,$.jsx)(wn,{format:f,onFormatChange:h})]}),(0,$.jsxs)(`div`,{className:`pb-2.5 pt-1.5 sm:pb-3`,children:[W&&!P&&(H?.settings?.promptQueue?.length??0)>0&&(0,$.jsx)(An,{sessionId:W,queue:H.settings.promptQueue}),W&&ae.some(e=>e.sessionId===W)&&(0,$.jsx)(`div`,{className:`mx-auto mb-1.5 flex w-full max-w-3xl flex-wrap gap-1.5 px-1`,"data-testid":`pending-comparisons`,children:ae.filter(e=>e.sessionId===W).map(e=>(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5 rounded-full border border-black/[0.07] bg-surface/70 px-2.5 py-1 text-[12px] text-gray-600 dark:border-white/8 dark:bg-dark-200/70 dark:text-dark-700`,"data-testid":`pending-comparison`,children:[(0,$.jsx)(L,{className:`h-3 w-3 animate-spin`}),(0,$.jsx)(`span`,{dir:`ltr`,className:`max-w-[160px] truncate`,children:e.model}),n&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>n(e.assistantMessageId),className:`rounded-full p-0.5 text-gray-400 hover:text-red-500`,"aria-label":a(`common.cancel`),children:(0,$.jsx)(U,{className:`h-3 w-3`,"aria-hidden":`true`})})]},e.assistantMessageId))}),(0,$.jsx)(`form`,{onSubmit:vt,children:(0,$.jsxs)(`div`,{"data-composer-box":``,className:jt,children:[(0,$.jsx)(zn,{ref:Pe,message:o,disabled:i,onApply:e=>{s(e),Me.current?.focus()}}),(0,$.jsx)(_n,{ref:Me,value:o,onChange:e=>s(e.target.value),onKeyDown:yt,placeholder:a(`chat.input.placeholder`),"aria-label":a(`chat.input.placeholder`),disabled:i,className:`m-0! block w-full min-h-9 max-h-[160px] resize-none rounded-none! border-0! bg-transparent! px-2! pt-1.5! pb-2! shadow-none! scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-ink-subtle focus:border-0! focus:bg-transparent! focus:shadow-none! focus:ring-0! dark:scrollbar-thumb-dark-400 text-[0.9375rem] leading-relaxed touch-manipulation`,rows:1}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsxs)(`div`,{ref:be,className:`relative shrink-0`,children:[(0,$.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{if(g){v(!1);return}E(e=>!e),F(null)},className:O(`h-9 w-9 p-0! rounded-full shrink-0`,`bg-surface-subtle text-ink-muted hover:bg-hover-solid hover:text-ink dark:bg-surface-raised dark:hover:bg-surface-overlay`,`transition-colors duration-150 touch-manipulation`,Ct&&`text-primary-600 dark:text-primary-400`,(g||T)&&`bg-hover-solid text-ink`),title:a(`chat.input.attachments`),"aria-label":a(`chat.input.attachments`),"aria-expanded":g||T,children:R||fe?(0,$.jsx)(L,{className:`h-4 w-4 animate-spin`}):Ct?(0,$.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,$.jsx)(Re,{className:`h-4 w-4`}),(0,$.jsx)(`div`,{className:`absolute -top-0.5 -inset-e-0.5 h-2 w-2 bg-primary-500 dark:bg-primary-400 rounded-full ring-2 ring-white dark:ring-dark-50`})]}):g?(0,$.jsx)(te,{className:`h-4 w-4`}):(0,$.jsx)(Le,{className:`h-4 w-4`})}),T&&(0,$.jsx)(`div`,{className:`absolute bottom-full inset-s-0 z-30 mb-2 w-64 rounded-2xl border border-black/8 bg-surface/95 p-1.5 shadow-[0_16px_48px_rgba(15,23,42,0.16)] backdrop-blur-xl animate-scale-in dark:border-white/9 dark:bg-dark-100/95`,children:ce?(0,$.jsxs)(`div`,{className:`p-1`,children:[(0,$.jsx)(`p`,{className:`mb-1 px-1.5 text-[11px] font-medium text-ink-muted`,children:a(`chat.input.menu.attachKnowledge`)}),ue.length===0?(0,$.jsx)(`p`,{className:`px-1.5 pb-1 text-[12px] text-ink-subtle`,children:a(`chat.input.menu.noCollections`)}):ue.map(e=>{let t=ot.includes(e.id);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void st(e.id),className:O(`flex w-full items-center justify-between gap-2 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,t&&`text-primary-600 dark:text-primary-400`),"aria-pressed":t,children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(K,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.name})]}),t&&(0,$.jsx)(De,{className:`h-3.5 w-3.5 shrink-0`})]},e.id)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>I(!1),className:`mt-1 w-full rounded-lg border-t border-gray-100 px-2.5 py-1.5 text-start text-xs text-gray-500 hover:bg-gray-100 dark:border-dark-300 dark:text-dark-600 dark:hover:bg-dark-200`,children:a(`common.back`)})]}):se===null?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{v(!0),J()},className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(N,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.uploadImages`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>xe.current?.click(),className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(He,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.attachDocument`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>F(``),className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(Ne,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.attachWebpage`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>I(!0),className:`flex w-full items-center justify-between gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(K,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.attachKnowledge`)]}),ot.length>0&&(0,$.jsx)(`span`,{className:`rounded-full bg-primary-50 px-1.5 text-[10px] font-medium tabular-nums text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`,children:ot.length})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{v(!0),J()},className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(Te,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.structuredOutput`)]}),z&&D&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{ne(e=>!e),J()},className:O(`flex w-full items-center justify-between gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,A&&`text-primary-600 dark:text-primary-400`),"aria-pressed":A,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(Ne,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(A?`chat.input.webSearchOn`:`chat.input.webSearchOff`)]}),A&&(0,$.jsx)(De,{className:`h-3.5 w-3.5 shrink-0`})]}),z&&dt&&r&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{bt(),r(),J()},className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(Oe,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`voiceMode.open`)]})]}):(0,$.jsxs)(`div`,{className:`p-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`chat-attach-webpage-url`,className:`mb-1.5 block text-[11px] font-medium text-ink-muted`,children:a(`chat.input.menu.attachWebpage`)}),(0,$.jsx)(`input`,{id:`chat-attach-webpage-url`,type:`url`,value:se,onChange:e=>F(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),gt()):e.key===`Escape`&&F(null)},placeholder:`https://…`,autoFocus:!0,dir:`ltr`,className:`w-full rounded-lg border border-black/8 bg-white px-2.5 py-1.5 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/8 dark:bg-dark-50 dark:text-dark-900`}),(0,$.jsxs)(`div`,{className:`mt-2 flex justify-end gap-1.5`,children:[(0,$.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>F(null),children:a(`common.cancel`)}),(0,$.jsx)(q,{type:`button`,size:`sm`,onClick:()=>void gt(),disabled:!se.trim(),loading:fe,children:a(`chat.input.menu.attach`)})]})]})}),(0,$.jsx)(`input`,{ref:xe,type:`file`,accept:Nn,className:`hidden`,onChange:e=>void mt(e)})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-1 sm:gap-1.5`,children:[Ye&&(0,$.jsx)(Ot,{value:Ue,inheritedValue:We,onChange:e=>void nt(e)}),D&&!z&&(0,$.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>ne(e=>!e),className:O(`h-9 w-9 p-0 rounded-full shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,A&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:wt,"aria-label":wt,"aria-pressed":A,children:(0,$.jsx)(Ne,{className:`h-4 w-4`})}),!P&&(0,$.jsx)(Vn,{value:oe,onChange:M}),!P&&H&&!z&&(0,$.jsx)(Mn,{models:ke,currentModelKey:p({model:H.personaId?`persona:${H.personaId}`:H.model,providerType:H.providerType??null,providerId:H.providerId??null}),selectedKeys:re,onChange:ie,disabled:i}),pt.length>0&&!z&&(0,$.jsx)(`select`,{value:Z.activeSourceKey,onChange:e=>Z.setSourceKey(e.target.value),disabled:ct||lt||ut,"aria-label":a(`chat.input.transcriptionSource`),title:ft?a(`chat.input.providerTranscriptionDisclosure`,{provider:ft.plugin}):a(`chat.input.transcriptionSource`),className:`h-8 max-w-32 rounded-lg border border-black/8 bg-transparent px-1.5 text-[11px] text-gray-500 outline-hidden focus:border-primary-500 focus:ring-2 focus:ring-primary-500/30 dark:border-white/9 dark:text-dark-600`,children:Z.sources.map(e=>e.kind===`browser`?(0,$.jsx)(`option`,{value:e.key,children:a(`chat.input.browserSpeech`)},e.key):(0,$.jsxs)(`option`,{value:e.key,children:[e.model?.plugin,` · `,e.model?.model]},e.key))}),dt&&(0,$.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void Z.toggle(),className:O(`h-9 w-9 p-0 rounded-full shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,(ct||lt||ut)&&`bg-red-50 text-red-500 animate-pulse dark:bg-red-900/20 dark:text-red-400`),title:Tt,"aria-label":Tt,"aria-pressed":ct||lt||ut,children:ct?(0,$.jsx)(L,{className:`h-4 w-4 animate-spin`}):ut||lt?(0,$.jsx)(le,{className:`h-4 w-4`}):(0,$.jsx)(Be,{className:`h-4 w-4`})}),dt&&r&&!z&&(0,$.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{bt(),r()},className:O(`h-9 w-9 p-0 rounded-full shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`),title:a(`voiceMode.open`),"aria-label":a(`voiceMode.open`),"data-testid":`voice-mode-open`,children:(0,$.jsx)(Oe,{className:`h-4 w-4`})}),H&&(0,$.jsx)(On,{usage:et,trainedBudget:X?.contextCapped?X.trainedContextLength:void 0}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`}),H&&Ie.length>0&&(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(kt,{models:Ie,selectedModel:ze,onModelChange:St,getModelValue:_,currentPersona:he,className:`min-w-[150px] max-w-[230px]`,compact:!0,showImageGen:V})}),we?(0,$.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:xt,className:O(`h-9 w-9 p-0 rounded-full shrink-0 flex items-center justify-center`,`bg-red-50 dark:bg-red-900/20`,`text-red-500 dark:text-red-400`,`hover:bg-red-100 dark:hover:bg-red-900/30`,`transition-colors duration-150 touch-manipulation`),title:a(`chat.input.stopGeneration`),"aria-label":a(`chat.input.stopGeneration`),children:(0,$.jsx)(le,{className:`h-4 w-4`})}):(0,$.jsx)(q,{type:`submit`,variant:`primary`,size:`sm`,disabled:!o.trim()||i||!Ve,className:Mt,title:a(`chat.input.sendMessage`),"aria-label":a(`chat.input.sendMessage`),children:(0,$.jsx)(ye,{className:`h-4 w-4`})})]})]})]})}),ft&&(0,$.jsx)(`p`,{role:`note`,className:`mt-1.5 text-center text-[10px] leading-relaxed text-amber-700 dark:text-amber-300`,children:a(`chat.input.providerTranscriptionDisclosure`,{provider:ft.plugin})}),H&&Ie.length>0&&(0,$.jsx)(`div`,{className:`mt-3 sm:hidden`,children:(0,$.jsx)(kt,{models:Ie,selectedModel:ze,onModelChange:St,getModelValue:_,currentPersona:he,className:`w-full`,compact:!0,showImageGen:V})}),(0,$.jsxs)(`div`,{className:`mt-1.5 flex min-h-4 items-center justify-center gap-2 text-[10px] text-ink-subtle`,children:[(0,$.jsx)(xn,{sessionId:H?.id}),(0,$.jsxs)(`div`,{className:`text-center leading-relaxed`,children:[(0,$.jsx)(`span`,{children:a(`chat.footer.disclaimer`)}),Ct&&(0,$.jsxs)(`span`,{className:`ms-2 text-primary-600 dark:text-primary-400`,children:[`•`,` `,l.length>0&&a(`chat.footer.images`,{count:l.length}),l.length>0&&f&&` • `,f&&a(`chat.footer.structuredOutput`)]})]})]})]})]})})},qn={phase:`idle`,muted:!1,turn:0,error:null},Jn=e=>({...e,phase:`listening`,turn:e.turn+1});function Yn(e,t){switch(t.type){case`start`:return e.phase===`idle`?{phase:`listening`,muted:!1,turn:e.turn+1,error:null}:e;case`stop`:return{...e,phase:`idle`,error:null};case`mute`:return{...e,muted:!0};case`unmute`:return{...e,muted:!1};case`captured`:return e.phase===`listening`&&!e.muted?{...e,phase:`transcribing`,error:null}:e;case`transcript`:return e.phase===`transcribing`?t.text.trim()?{...e,phase:`generating`}:Jn(e):e;case`reply`:return e.phase===`generating`?t.speak?{...e,phase:`speaking`}:Jn(e):e;case`spoken`:case`barge-in`:return e.phase===`speaking`?Jn(e):e;case`fail`:return e.phase===`idle`?e:{...Jn(e),error:t.message}}}var Xn=c(`utils:voice-mode-controller`),Zn=.015,Qn=200,$n=1500,er=6e4,tr=300,nr=18e4,rr=()=>{if(typeof window>`u`)return;let e=window;return e.SpeechRecognition||e.webkitSpeechRecognition},ir=e=>{if(typeof MediaRecorder>`u`)return;let t=new Set((e.config?.formats||[]).map(e=>e.toLowerCase())),n=`audio/webm;codecs=opus`;if(!(t.size>0&&!t.has(`webm`))&&(typeof MediaRecorder.isTypeSupported!=`function`||MediaRecorder.isTypeSupported(n)))return n},ar=class{options;state=qn;closed=!1;useBrowserRecognition=!1;sttModel=null;ttsModels=[];stream=null;recorder=null;chunks=[];audioContext=null;analyser=null;monitorTimer=null;pollTimer=null;recognition=null;ttsSession=null;abortController=null;constructor(e){this.options=e}async start(){try{let[e,t]=await Promise.all([nt.getModels().catch(()=>({success:!1,data:[]})),X.getModels().catch(()=>({success:!1,data:[]}))]);if(this.closed)return;let n=e.success&&e.data||[];this.ttsModels=t.success&&t.data||[];let r=n.find(e=>!!ir(e)),i=!!r&&typeof navigator<`u`&&!!navigator.mediaDevices?.getUserMedia,a=!!rr();if(i&&r)this.sttModel=r,this.useBrowserRecognition=!1;else if(a)this.useBrowserRecognition=!0;else{this.options.onSupport(!1);return}if(this.options.onSupport(!0),!this.useBrowserRecognition&&(await this.ensureStream(),this.closed))return;let o=this.send({type:`start`});this.beginTurn(o.turn)}catch(e){Xn.warn(`Voice mode failed to start:`,e),this.closed||this.options.onSupport(!1)}}close(){this.closed=!0,this.clearMonitor(),this.clearPoll(),this.stopRecorder(),this.stopRecognition(),this.abortController?.abort(),this.ttsSession?.cancel(),this.ttsSession=null,this.stream?.getTracks().forEach(e=>e.stop()),this.stream=null,this.audioContext&&=(this.audioContext.close().catch(()=>void 0),null)}toggleMute(){if(this.state.muted){let e=this.send({type:`unmute`});e.phase===`listening`&&(this.stopRecorder(),this.stopRecognition(),this.beginTurn(e.turn))}else this.send({type:`mute`})}finishTurn(){this.state.phase!==`listening`||this.state.muted||(this.useBrowserRecognition?this.recognition?.stop():this.finishProviderCapture(this.state.turn))}skipSpeech(){if(this.state.phase!==`speaking`)return;this.ttsSession?.cancel(),this.clearMonitor();let e=this.send({type:`spoken`});e.phase===`listening`&&this.beginTurn(e.turn)}send(e){return this.state=Yn(this.state,e),this.options.onState(this.state),this.state}staleTurn(e){return this.closed||this.state.turn!==e}clearMonitor(){this.monitorTimer!==null&&(window.clearInterval(this.monitorTimer),this.monitorTimer=null)}clearPoll(){this.pollTimer!==null&&(window.clearInterval(this.pollTimer),this.pollTimer=null)}stopRecorder(){let e=this.recorder;if(this.recorder=null,e&&e.state!==`inactive`)try{e.stop()}catch{}}stopRecognition(){let e=this.recognition;if(this.recognition=null,e){e.onresult=null,e.onend=null,e.onerror=null;try{e.stop()}catch{}}}rmsLevel(){if(!this.analyser)return 0;let e=new Float32Array(this.analyser.fftSize);this.analyser.getFloatTimeDomainData(e);let t=0;for(let n=0;n<e.length;n+=1)t+=e[n]*e[n];return Math.sqrt(t/e.length)}async ensureStream(){if(this.stream)return this.stream;let e=await navigator.mediaDevices.getUserMedia({audio:!0});this.stream=e;try{let t=window.AudioContext||window.webkitAudioContext;if(t){let n=new t;n.resume().catch(()=>void 0);let r=n.createMediaStreamSource(e),i=n.createAnalyser();i.fftSize=1024,r.connect(i),this.audioContext=n,this.analyser=i}}catch(e){Xn.warn(`Voice mode analyser unavailable:`,e)}return e}fail(e,t){if(this.staleTurn(e))return;this.clearMonitor(),this.clearPoll();let n=this.send({type:`fail`,message:t});n.phase===`listening`&&this.beginTurn(n.turn)}beginTurn(e){this.closed||this.state.turn!==e||this.state.phase===`listening`&&(this.stopRecognition(),this.useBrowserRecognition?this.startBrowserCapture(e):this.startProviderCapture(e))}startBrowserCapture(e){let t=rr();if(!t)return;let n=new t;n.lang=this.options.locale,n.continuous=!1,n.interimResults=!1;let r=``;n.onresult=e=>{r=Array.from({length:e.results.length},(t,n)=>e.results[n]?.[0]?.transcript??``).join(` `).trim()},n.onend=()=>{this.staleTurn(e)||this.state.muted||this.send({type:`captured`}).phase===`transcribing`&&this.handleTranscript(e,r)},n.onerror=()=>{this.staleTurn(e)||this.fail(e,this.options.messages.microphoneFailed)},this.recognition=n;try{n.start()}catch{this.fail(e,this.options.messages.microphoneFailed)}}async startProviderCapture(e){let t=this.sttModel;if(!t)return;let n=ir(t);if(!n){this.fail(e,this.options.messages.microphoneFailed);return}try{let t=await this.ensureStream();if(this.staleTurn(e))return;this.chunks=[];let r=new MediaRecorder(t,{mimeType:n});this.recorder=r,r.ondataavailable=e=>{e.data.size>0&&this.chunks.push(e.data)},r.onstop=()=>{if(this.staleTurn(e)&&this.state.phase!==`transcribing`)return;let t=new Blob(this.chunks,{type:n});if(this.chunks=[],t.size===0){this.handleTranscript(e,``);return}this.transcribeRecording(e,t)},r.start();let i=0,a=0,o=!1,s=Date.now();this.clearMonitor(),this.monitorTimer=window.setInterval(()=>{if(this.staleTurn(e)){this.clearMonitor();return}if(this.state.muted){i=0,a=0;return}this.analyser&&(this.rmsLevel()>Zn?(i+=50,a=0,i>=Qn&&(o=!0)):(i=0,o&&(a+=50))),(o&&a>=$n||Date.now()-s>=er)&&this.finishProviderCapture(e)},50)}catch(t){Xn.warn(`Voice mode microphone failed:`,t),this.fail(e,this.options.messages.microphoneFailed)}}finishProviderCapture(e){this.staleTurn(e)||(this.clearMonitor(),this.send({type:`captured`}).phase===`transcribing`&&this.stopRecorder())}transcribeRecording(e,t){let n=this.sttModel;if(!n){this.fail(e,this.options.messages.transcriptionFailed);return}let r=new AbortController;this.abortController=r,nt.transcribe(t,n,{language:this.options.locale?.split(`-`)[0],signal:r.signal}).then(t=>this.handleTranscript(e,t.text??``)).catch(t=>{r.signal.aborted||(Xn.warn(`Voice mode transcription failed:`,t),this.fail(e,this.options.messages.transcriptionFailed))})}handleTranscript(e,t){if(this.staleTurn(e))return;let n=this.send({type:`transcript`,text:t});n.phase===`generating`?this.startGeneration(n.turn,t.trim()):n.phase===`listening`&&this.beginTurn(n.turn)}startGeneration(e,t){this.options.onTranscript(t);let n=this.options.snapshot().lastAssistantMessage?.id??null,r=!1,i=Date.now();this.options.sendMessage(t),this.clearPoll(),this.pollTimer=window.setInterval(()=>{if(this.staleTurn(e)){this.clearPoll();return}let t=this.options.snapshot(),a=t.lastAssistantMessage,o=a!==null&&a.id!==n;if((t.isStreaming||o)&&(r=!0),r&&!t.isStreaming&&o){this.clearPoll();let t=this.ttsModels.length>0&&a.content.trim()!==``,n=this.send({type:`reply`,speak:t});n.phase===`speaking`?this.speakReply(e,a.content):n.phase===`listening`&&this.beginTurn(n.turn);return}Date.now()-i>nr&&(this.clearPoll(),this.fail(e,this.options.messages.replyTimeout))},250)}speakReply(e,t){let n=this.options.snapshot().ttsSettings,r=Ze(this.ttsModels,n?.model,n?.pluginId);if(!r){this.finishSpeaking(e);return}let i=r.model===n?.model&&(!n?.pluginId||r.plugin===n.pluginId),a=i&&n?.voice||r.config?.default_voice,o=i&&n?.voiceProfileId||void 0,s=Math.max(1,r.config?.max_characters||600),c=Math.min(s,600),l=yt(t,{locale:this.options.locale,maxChars:c,targetChars:Math.min(c,420),minChars:Math.min(c,80)});if(l.length===0){this.finishSpeaking(e);return}let u=_t({concurrency:3,initialBufferSize:Math.min(2,l.length),generate:(e,{signal:t})=>X.generate({model:r.model,pluginId:r.plugin,input:e,voice:o?void 0:a||void 0,voiceProfileId:o,speed:n?.speed||1,response_format:r.config?.default_format},{signal:t}),onStateChange:()=>void 0});this.ttsSession=u;let d=xt(u);this.startBargeInMonitor(e,u),u.play(l).then(()=>{this.staleTurn(e)||this.finishSpeaking(e)}).catch(t=>{this.staleTurn(e)||gt(t)||(Xn.warn(`Voice mode speech failed:`,t),this.finishSpeaking(e))}).finally(()=>{d(),this.ttsSession===u&&(this.ttsSession=null)})}startBargeInMonitor(e,t){if(!this.analyser)return;this.clearMonitor();let n=0;this.monitorTimer=window.setInterval(()=>{if(this.staleTurn(e)||this.state.muted){n=0;return}if(this.rmsLevel()>Zn){if(n+=50,n>=tr){this.clearMonitor(),t.cancel();let e=this.send({type:`barge-in`});e.phase===`listening`&&this.beginTurn(e.turn)}}else n=0},50)}finishSpeaking(e){if(this.staleTurn(e))return;this.clearMonitor();let t=this.send({type:`spoken`});t.phase===`listening`&&this.beginTurn(t.turn)}},or=({onClose:e,onSendMessage:t,isStreaming:n,lastAssistantMessage:r})=>{let{t:i,i18n:a}=w(),{preferences:o}=k(),[s,c]=(0,Q.useState)(qn),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(null),p=(0,Q.useRef)(null),m=(0,Q.useRef)({isStreaming:!1,lastAssistantMessage:null,ttsSettings:void 0});(0,Q.useEffect)(()=>{m.current={isStreaming:n,lastAssistantMessage:r,ttsSettings:o.ttsSettings}},[n,r,o.ttsSettings]),(0,Q.useEffect)(()=>{let e=new ar({locale:a.language,sendMessage:e=>t(e),snapshot:()=>m.current,onState:e=>c(e),onTranscript:e=>u(e),onSupport:e=>f(e),messages:{microphoneFailed:i(`voiceMode.microphoneFailed`),transcriptionFailed:i(`voiceMode.transcriptionFailed`),replyTimeout:i(`voiceMode.replyTimeout`)}});return p.current=e,e.start(),()=>{p.current=null,e.close()}},[]);let h=s.phase,g=d===!1?`voiceMode.unsupported`:h===`listening`?s.muted?`voiceMode.muted`:`voiceMode.listening`:h===`transcribing`?`voiceMode.transcribing`:h===`generating`?`voiceMode.generating`:h===`speaking`?`voiceMode.speaking`:`voiceMode.starting`;return(0,Nt.createPortal)((0,$.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":i(`voiceMode.title`),className:`fixed inset-0 z-70 flex flex-col items-center justify-center gap-6 bg-white/95 p-6 backdrop-blur-sm dark:bg-dark-25/95`,"data-testid":`voice-mode-overlay`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:e,"aria-label":i(`voiceMode.close`),className:`absolute right-4 top-4 rounded-full p-2 text-gray-500 hover:bg-gray-100 hover:text-gray-700 dark:text-gray-400 dark:hover:bg-dark-100`,children:(0,$.jsx)(U,{className:`h-5 w-5`})}),(0,$.jsx)(`div`,{className:O(`flex h-28 w-28 items-center justify-center rounded-full border-4 transition-colors`,h===`listening`&&!s.muted?`border-primary-500 text-primary-500`:h===`speaking`?`border-emerald-500 text-emerald-500`:h===`generating`||h===`transcribing`?`border-amber-500 text-amber-500`:`border-gray-300 text-gray-400 dark:border-dark-300`),children:h===`transcribing`||h===`generating`?(0,$.jsx)(L,{className:`h-10 w-10 animate-spin`}):s.muted?(0,$.jsx)(R,{className:`h-10 w-10`}):h===`speaking`?(0,$.jsx)(Oe,{className:`h-10 w-10`}):(0,$.jsx)(Be,{className:`h-10 w-10`})}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`p`,{className:`text-base font-medium text-gray-900 dark:text-gray-100`,"data-testid":`voice-mode-status`,children:i(g)}),s.error&&(0,$.jsx)(`p`,{className:`mt-1 text-sm text-red-600 dark:text-red-400`,children:s.error}),l&&(0,$.jsxs)(`p`,{className:`mt-3 max-w-md text-sm text-gray-600 dark:text-gray-300`,children:[`“`,l,`”`]})]}),d!==!1&&(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>p.current?.toggleMute(),"aria-label":s.muted?i(`voiceMode.unmute`):i(`voiceMode.mute`),"aria-pressed":s.muted,className:`rounded-full border border-gray-300 p-3 text-gray-700 hover:bg-gray-100 dark:border-dark-300 dark:text-gray-300 dark:hover:bg-dark-100`,children:s.muted?(0,$.jsx)(R,{className:`h-5 w-5`}):(0,$.jsx)(Be,{className:`h-5 w-5`})}),h===`listening`&&!s.muted&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>p.current?.finishTurn(),"aria-label":i(`voiceMode.finishTurn`),className:`rounded-full border border-primary-500 p-3 text-primary-600 hover:bg-primary-50 dark:hover:bg-primary-950/30`,children:(0,$.jsx)(De,{className:`h-5 w-5`})}),h===`speaking`&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>p.current?.skipSpeech(),"aria-label":i(`voiceMode.skipReply`),className:`rounded-full border border-emerald-500 p-3 text-emerald-600 hover:bg-emerald-50 dark:hover:bg-emerald-950/30`,children:(0,$.jsx)(re,{className:`h-5 w-5`})})]}),d===!1&&(0,$.jsx)(`p`,{className:`max-w-md text-center text-sm text-gray-600 dark:text-gray-300`,children:i(`voiceMode.unsupportedHint`)})]}),document.body)},sr=c(`components:chat-controls-panel`),cr=[{key:`temperature`,labelKey:`temperature`,step:`0.1`,min:0,max:2},{key:`top_p`,labelKey:`topP`,step:`0.05`,min:0,max:1},{key:`top_k`,labelKey:`topK`,step:`1`,min:1},{key:`min_p`,labelKey:`minP`,step:`0.05`,min:0,max:1},{key:`num_predict`,labelKey:`maxTokens`,step:`1`},{key:`repeat_penalty`,labelKey:`repeatPenalty`,step:`0.05`,min:0},{key:`seed`,labelKey:`seed`,step:`1`},{key:`num_ctx`,labelKey:`contextLength`,step:`1`}],lr=({session:e,draftModel:t,open:n,onClose:r})=>{let{t:i,i18n:a}=w(),o=S(e=>e.draftSessionSettings),s=S(e=>e.setDraftSessionSettings),c=e?.model??t??``,l=k(e=>e.preferences.generationOptions),u=k(e=>e.preferences.modelGenerationOptions?.[c]),[f,p]=(0,Q.useState)({options:{},contextCapped:!1});(0,Q.useEffect)(()=>{if(!n||!c)return;let e=!1;return at.getModelDefaults(c).then(t=>{!e&&t.success&&t.data&&p({options:t.data.options??{},trainedContextLength:t.data.trainedContextLength,contextCapped:!!t.data.contextCapped})}).catch(()=>{}),()=>{e=!0}},[n,c]);let m=(0,Q.useMemo)(()=>({...l??{},...f.options,...u??{}}),[l,f.options,u]),h=(0,Q.useMemo)(()=>e?.messages.find(e=>e.role===`system`&&!d(e.content)),[e?.messages]),[g,_]=(0,Q.useState)(h?.content??o.systemPrompt??``),[v,y]=(0,Q.useState)(e?.settings?.generationOptions??o.generationOptions??{}),[b,x]=(0,Q.useState)(!1),[C,E]=(0,Q.useState)(e?.settings?.compaction!==!1),[D,ee]=(0,Q.useState)(e?.id??`draft`),O=e?.id??`draft`;D!==O&&(ee(O),_(h?.content??o.systemPrompt??``),y(e?.settings?.generationOptions??o.generationOptions??{}),E(e?.settings?.compaction!==!1));let A=e=>{y(t=>{let n={...t},r=Ct(e);return r===null?delete n.think:n.think=r,n})},te=(e,t)=>{y(n=>{let r={...n};if(t===``)delete r[e];else{let n=Number(t);Number.isNaN(n)||(r[e]=n)}return r})},j=async()=>{x(!0);try{let t=g.trim(),n=h?.content??``,a=Object.fromEntries(Object.entries(v).filter(([,e])=>e!==void 0)),o=e?{...e.settings,generationOptions:a}:Object.keys(a).length>0?{generationOptions:a}:void 0;if(o&&e&&(C?delete o.compaction:o.compaction=!1),!e){s({systemPrompt:t||void 0,generationOptions:o?.generationOptions}),I.success(i(`chat.controls.saved`)),r();return}let c=e.messages;if(t!==n.trim()&&(h?c=t?e.messages.map(e=>e.id===h.id?{...e,content:t}:e):e.messages.filter(e=>e.id!==h.id):t&&(c=[{id:T(),role:`system`,content:t,timestamp:Date.now()},...e.messages])),e.isPrivate)S.setState(t=>({currentSession:t.currentSession?.id===e.id?{...t.currentSession,messages:c,settings:o}:t.currentSession}));else{let t=await Y.updateSession(e.id,{messages:c,settings:o});if(!t.success||!t.data)throw Error(t.error||`Update failed`);let n=t.data;S.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?n:t),currentSession:t.currentSession?.id===e.id?n:t.currentSession}))}I.success(i(`chat.controls.saved`)),r()}catch(e){sr.error(`Failed to save chat controls:`,e),I.error(i(`chat.controls.saveFailed`))}finally{x(!1)}};return n?(0,$.jsxs)(`div`,{"data-testid":`chat-controls-panel`,className:`flex h-full w-84 shrink-0 flex-col border-s border-black/6 bg-surface/70 backdrop-blur-xl dark:border-white/[0.07] dark:bg-dark-100/70`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 pb-2 pt-4`,children:[(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:i(`chat.controls.title`)}),(0,$.jsx)(`button`,{type:`button`,onClick:r,className:`rounded-full p-1.5 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-900`,title:i(`common.close`),"aria-label":i(`common.close`),children:(0,$.jsx)(U,{className:`h-4 w-4`})})]}),(0,$.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-5 overflow-y-auto px-4 py-2 scrollbar-thin`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`chat-control-system-prompt`,className:`mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.systemPrompt`)}),(0,$.jsx)(`textarea`,{id:`chat-control-system-prompt`,dir:`auto`,value:g,onChange:e=>_(e.target.value),placeholder:i(`chat.controls.systemPromptPlaceholder`),className:`min-h-[110px] w-full resize-y rounded-xl border border-black/8 bg-white p-2.5 text-[13px] leading-relaxed text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/8 dark:bg-dark-50 dark:text-dark-900 dark:placeholder:text-dark-500`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`chat-control-think`,className:`mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.thinking`)}),(0,$.jsx)(`select`,{id:`chat-control-think`,value:wt(v.think),onChange:e=>A(e.target.value),className:`w-full rounded-xl border border-black/8 bg-white px-2.5 py-2 text-[13px] text-gray-900 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/8 dark:bg-dark-50 dark:text-dark-900`,children:Tt.map(e=>(0,$.jsx)(`option`,{value:e,children:e==="default"&&m.think!==void 0&&m.think!==null?i(`settings.generation.thinkingLevels.defaultWith`,{level:i(`settings.generation.thinkingLevels.${wt(m.think)}`)}):i(`settings.generation.thinkingLevels.${e}`)},e))}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[11px] leading-snug text-ink-muted`,children:i(`chat.controls.thinkingDescription`)})]}),e&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`chat-control-compaction`,className:`mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.compaction`)}),(0,$.jsxs)(`select`,{id:`chat-control-compaction`,value:C?`default`:`off`,onChange:e=>E(e.target.value!==`off`),className:`w-full rounded-xl border border-black/8 bg-white px-2.5 py-2 text-[13px] text-gray-900 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/8 dark:bg-dark-50 dark:text-dark-900`,children:[(0,$.jsx)(`option`,{value:`default`,children:i(`chat.controls.compactionDefault`)}),(0,$.jsx)(`option`,{value:`off`,children:i(`chat.controls.compactionOff`)})]}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[11px] leading-snug text-ink-muted`,children:i(`chat.controls.compactionDescription`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-1.5 text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.advancedParams`)}),(0,$.jsx)(`p`,{className:`mb-2.5 text-[11px] leading-snug text-ink-muted`,children:i(`chat.controls.advancedParamsDescription`)}),f.contextCapped&&f.trainedContextLength&&(0,$.jsx)(`p`,{className:`mb-2.5 text-[11px] leading-snug text-gray-500 dark:text-dark-600`,children:i(`chat.controls.contextCapped`,{context:m.num_ctx?.toLocaleString(a.language),trained:f.trainedContextLength.toLocaleString(a.language)})}),(0,$.jsx)(`div`,{className:`space-y-1.5`,children:cr.map(e=>{let t=v[e.key],n=m[e.key],r=f.options[e.key]!==void 0&&u?.[e.key]===void 0;return(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`label`,{htmlFor:`chat-control-${e.key}`,className:`text-[13px] text-gray-700 dark:text-dark-700`,children:[i(`chat.controls.params.${e.labelKey}`),r&&(0,$.jsx)(`span`,{title:i(`chat.controls.fromModelHint`),className:`ms-1.5 text-[10px] uppercase tracking-wide text-ink-muted`,children:i(`chat.controls.fromModel`)})]}),(0,$.jsx)(`input`,{id:`chat-control-${e.key}`,type:`number`,inputMode:`decimal`,step:e.step,min:e.min,max:e.max,value:typeof t==`number`?t:``,placeholder:typeof n==`number`?String(n):i(`common.default`),onChange:t=>te(e.key,t.target.value),className:`w-24 rounded-lg border border-black/8 bg-white px-2 py-1 text-end text-[12px] tabular-nums text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/8 dark:bg-dark-50 dark:text-dark-900 dark:placeholder:text-dark-500`})]},e.key)})})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-t border-black/6 px-4 py-3 dark:border-white/[0.07] lg:pb-16`,children:[(0,$.jsx)(`button`,{onClick:()=>{y({}),_(h?.content??``)},className:`text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-dark-600 dark:hover:text-dark-900`,children:i(`common.reset`)}),(0,$.jsx)(q,{onClick:()=>void j(),size:`sm`,disabled:b,children:i(b?`common.saving`:`common.save`)})]})]}):null},ur=c(`components:chat-sources-panel`),dr=6,fr=[],pr=e=>{try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}},mr=({session:e})=>{let{t,i18n:n}=w(),[r,i]=(0,Q.useState)({sessionId:``,docs:fr}),a=!e.isPrivate&&r.sessionId===e.id?r.docs:fr,[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(!1),f=(0,Q.useRef)(null);J(f,{enabled:u,onClose:()=>d(!1)});let{webSources:p,ragSources:m,fullContextSkipped:h}=(0,Q.useMemo)(()=>{let t=new Map,n=new Map,r;for(let i of e.messages){let e=i.providerMetadata;if(Array.isArray(e?.webSearchSources))for(let n of e.webSearchSources){let e=n;e&&typeof e.url==`string`&&e.url&&t.set(e.url,{url:e.url,title:typeof e.title==`string`&&e.title?e.title:e.url})}if(Array.isArray(e?.ragSources))for(let t of e.ragSources){let e=t;e&&typeof e.id==`string`&&e.id&&n.set(e.id,{id:e.id,filename:typeof e.filename==`string`&&e.filename?e.filename:e.id,...Array.isArray(e.citations)?{citations:e.citations.filter(e=>!!e&&typeof e==`object`&&typeof e.chunkIndex==`number`)}:{},...e.full===!0?{full:!0}:{}})}let a=e?.ragFullContextSkipped;a&&typeof a.estimatedTokens==`number`&&typeof a.maxTokens==`number`?r={estimatedTokens:a.estimatedTokens,maxTokens:a.maxTokens}:e?.ragSources&&(r=void 0)}return{webSources:Array.from(t.values()),ragSources:Array.from(n.values()),fullContextSkipped:r}},[e.messages]);(0,Q.useEffect)(()=>{if(e.isPrivate)return;let t=!1,n=()=>{Qe.getDocuments(e.id).then(n=>{!t&&n.success&&Array.isArray(n.data)&&i({sessionId:e.id,docs:n.data.map(e=>({id:e.id,filename:e.filename,contentChars:e.contentChars}))})}).catch(()=>{})};return n(),window.addEventListener(`libre:documents-updated`,n),()=>{t=!0,window.removeEventListener(`libre:documents-updated`,n)}},[e.id,e.isPrivate]);let g=(0,Q.useMemo)(()=>{let e=new Map;for(let t of a)e.set(t.id,{...t,used:!1});for(let t of m)e.set(t.id,{...e.get(t.id)??{},id:t.id,filename:t.filename,used:!0,...t.citations?.length?{citations:t.citations}:{},...t.full?{full:!0}:{}});return Array.from(e.values())},[a,m]),_=e.settings?.fullDocumentContext===!0,v=(0,Q.useMemo)(()=>a.reduce((e,t)=>e+Math.ceil((t.contentChars??0)/4),0),[a]),y=async()=>{let n=e.settings?.fullDocumentContext,r={...e.settings,fullDocumentContext:!_||void 0};if(S.setState(t=>({currentSession:t.currentSession?.id===e.id?{...t.currentSession,settings:r}:t.currentSession,sessions:t.sessions.map(t=>t.id===e.id?{...t,settings:r}:t)})),!e.isPrivate)try{await Y.updateSession(e.id,{settings:r})}catch(r){ur.error(`Failed to update the full-document setting:`,r);let i=e=>({...e,fullDocumentContext:n});S.setState(t=>({currentSession:t.currentSession?.id===e.id?{...t.currentSession,settings:i(t.currentSession.settings)}:t.currentSession,sessions:t.sessions.map(t=>t.id===e.id?{...t,settings:i(t.settings)}:t)})),I.error(t(`chat.sources.fullContextFailed`))}},b=e=>{let t=[];for(let n of e){let e=n.location??`#${n.chunkIndex+1}`;if(t.includes(e)||t.push(e),t.length>=4)break}return t.join(` · `)};if(p.length===0&&g.length===0)return null;let x=o?p:p.slice(0,dr),C=c?g:g.slice(0,dr),T=(e,n,r)=>(e>0||n)&&(0,$.jsx)(`button`,{type:`button`,onClick:r,"aria-expanded":n,className:`mt-1 flex items-center gap-1 px-1 text-[12px] text-ink-muted transition-colors hover:text-ink`,children:n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_e,{className:`h-3 w-3`}),t(`chatMessage.showLess`,`Show less`)]}):`${t(`chatMessage.showMore`)} (${e})`}),E=(0,$.jsxs)($.Fragment,{children:[p.length>0&&(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h3`,{className:`mb-2 text-[13px] font-medium text-ink-muted`,children:t(`chat.message.sources`,`Sources`)}),(0,$.jsx)(`ul`,{className:`space-y-0.5`,children:x.map(e=>(0,$.jsx)(`li`,{children:(0,$.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`group -mx-1 flex items-center gap-2.5 rounded-lg px-1 py-1.5 transition-colors hover:bg-black/4 dark:hover:bg-white/5`,title:e.url,children:[(0,$.jsx)(Ne,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-700 dark:text-dark-500 dark:group-hover:text-dark-800`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate text-[13px] leading-snug text-gray-800 dark:text-dark-800`,children:e.title}),(0,$.jsx)(`span`,{dir:`ltr`,className:`block truncate text-[11px] text-ink-muted`,children:pr(e.url)})]})]})},e.url))}),T(p.length-x.length,o,()=>s(e=>!e))]}),g.length>0&&(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h3`,{className:`mb-2 text-[13px] font-medium text-ink-muted`,children:t(`settings.tabs.documents`,`Documents`)}),(0,$.jsx)(`ul`,{className:`space-y-0.5`,children:C.map(e=>(0,$.jsxs)(`li`,{className:`-mx-1 rounded-lg px-1 py-1.5`,title:e.filename,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(He,{className:`h-4 w-4 shrink-0 text-gray-400 dark:text-dark-500`}),(0,$.jsx)(`span`,{dir:`ltr`,className:`min-w-0 flex-1 truncate text-[13px] leading-snug text-gray-800 dark:text-dark-800`,children:e.filename}),e.used&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`h-1.5 w-1.5 shrink-0 rounded-full bg-primary-500`}),(0,$.jsx)(`span`,{className:`sr-only`,children:t(`chat.sources.usedByRetrieval`)})]})]}),e.full?(0,$.jsx)(`span`,{className:`ms-[26px] block truncate text-[11px] text-ink-muted`,"data-testid":`chat-source-citation`,children:t(`documents.fullDocument`,`Full document`)}):e.citations?.length?(0,$.jsx)(`span`,{className:`ms-[26px] block truncate text-[11px] text-ink-muted`,"data-testid":`chat-source-citation`,children:b(e.citations)}):null]},e.id))}),T(g.length-C.length,c,()=>l(e=>!e)),(0,$.jsxs)(`label`,{className:`mt-3 flex cursor-pointer items-center gap-2 px-1 text-[12px] text-ink-muted`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:_,onChange:y,"data-testid":`full-document-context-toggle`,className:`h-3.5 w-3.5 rounded-sm border-gray-300 text-primary-600 focus:ring-primary-500 dark:border-dark-400`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[t(`documents.fullContextToggle`,`Send full documents`),_&&v>0&&(0,$.jsx)(`span`,{className:`ms-1 text-ink-muted`,children:t(`documents.fullContextEstimate`,{tokens:v.toLocaleString(n.language)})})]})]}),_&&h&&(0,$.jsx)(`p`,{className:`mt-1 px-1 text-[11px] text-amber-600 dark:text-amber-400`,"data-testid":`full-document-context-warning`,children:t(`documents.fullContextTooLarge`)})]})]});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`aside`,{"data-testid":`chat-sources-panel`,className:`hidden w-72 shrink-0 flex-col gap-7 overflow-y-auto border-s border-black/5 px-5 py-6 scrollbar-thin dark:border-white/6 xl:flex`,children:E}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>d(!0),"data-testid":`chat-sources-trigger`,className:`absolute inset-e-3 top-17 z-20 flex h-8 w-8 items-center justify-center rounded-full border border-black/[0.07] bg-surface/65 text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 dark:border-white/8 dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 xl:hidden`,title:t(`chat.message.sources`,`Sources`),"aria-label":t(`chat.sources.triggerLabel`,{count:p.length+g.length}),"aria-haspopup":`dialog`,"aria-expanded":u,children:[(0,$.jsx)(K,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`absolute -inset-e-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-md bg-primary-500 px-1 text-[9px] font-semibold tabular-nums text-white shadow-xs`,children:p.length+g.length})]}),u&&(0,Nt.createPortal)((0,$.jsxs)(`div`,{className:`fixed inset-0 z-80 xl:hidden`,children:[(0,$.jsx)(`button`,{type:`button`,className:`absolute inset-0 bg-black/35 backdrop-blur-xs`,onClick:()=>d(!1),"aria-label":t(`common.close`)}),(0,$.jsxs)(`div`,{ref:f,role:`dialog`,"aria-modal":`true`,tabIndex:-1,"aria-label":t(`chat.message.sources`,`Sources`),className:`absolute inset-x-3 bottom-3 max-h-[75vh] overflow-y-auto rounded-2xl border border-black/8 bg-surface p-5 shadow-[0_20px_70px_rgba(0,0,0,0.3)] scrollbar-thin dark:border-white/9 dark:bg-dark-100`,"data-testid":`chat-sources-sheet`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,$.jsx)(`p`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:t(`chat.message.sources`,`Sources`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>d(!1),className:`rounded-md p-1.5 text-ink-muted hover:text-ink`,"aria-label":t(`common.close`),children:(0,$.jsx)(U,{className:`h-4 w-4`})})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-6`,children:E})]})]}),document.body)]})},hr=({persona:e,onClear:t,className:n})=>{let[r,i]=(0,Q.useState)(!1),a=(0,Q.useRef)(null),[o,s]=(0,Q.useState)({top:0,left:0});(0,Q.useEffect)(()=>{if(r&&a.current){let e=a.current.getBoundingClientRect(),t=document.documentElement.dir===`rtl`?e.right-288:e.left;s({top:e.bottom+8,left:Math.min(window.innerWidth-288-8,Math.max(8,t))})}},[r]);let c=!!(e.memory_settings?.enabled||e.mutation_settings?.enabled),l=()=>Xe(e,64),u=t=>{qe(t.currentTarget,e.name,64)};return(0,$.jsxs)(`div`,{className:O(`relative`,n),children:[(0,$.jsxs)(`button`,{ref:a,onClick:()=>i(!r),className:O(`flex items-center gap-2 px-3 py-1.5 rounded-full transition-all duration-200`,`bg-primary-50 dark:bg-primary-900/30`,`border border-primary-200 dark:border-primary-700/50`,`hover:bg-primary-100 dark:hover:bg-primary-900/40`,`text-primary-700 dark:text-primary-300`),children:[(0,$.jsx)(`img`,{src:l(),alt:e.name,className:`w-5 h-5 rounded-md object-cover`,onError:u}),(0,$.jsx)(`span`,{className:`text-sm font-medium max-w-[120px] truncate`,children:e.name}),c&&(0,$.jsx)(F,{className:`h-3 w-3 text-purple-500 dark:text-purple-400`}),(0,$.jsx)(A,{className:O(`h-3.5 w-3.5 transition-transform duration-200`,r&&`rotate-180`)})]}),r&&(0,Nt.createPortal)((0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`fixed inset-0 z-9998`,onClick:()=>i(!1)}),(0,$.jsx)(`div`,{className:`fixed w-72 z-9999`,style:{top:o.top,left:o.left},children:(0,$.jsxs)(`div`,{className:O(`rounded-xl overflow-hidden shadow-xl`,`bg-white dark:bg-dark-100`,`border border-gray-200 dark:border-dark-300`),children:[(0,$.jsxs)(`div`,{className:`relative h-16`,children:[e.background?(0,$.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,$.jsx)(`div`,{className:`absolute inset-0 bg-linear-to-br from-primary-400 via-primary-500 to-purple-600 dark:from-primary-600 dark:via-primary-700 dark:to-purple-800`}),(0,$.jsx)(`div`,{className:`absolute inset-0 bg-black/10`}),t&&(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),t(),i(!1)},className:`absolute top-2 inset-e-2 p-1 rounded-full bg-white/20 hover:bg-white/30 backdrop-blur-sm transition-colors`,title:`Remove persona`,children:(0,$.jsx)(U,{className:`h-3.5 w-3.5 text-white`})}),c&&(0,$.jsxs)(`div`,{className:`absolute top-2 inset-s-2 flex items-center gap-1 px-2 py-0.5 rounded-full bg-white/20 backdrop-blur-sm text-white text-[10px] font-medium`,children:[(0,$.jsx)(Pe,{className:`h-3 w-3`}),`Enhanced`]})]}),(0,$.jsx)(`div`,{className:`relative px-4 -mt-6`,children:(0,$.jsx)(`img`,{src:l(),alt:e.name,className:`w-12 h-12 rounded-lg object-cover ring-3 ring-white dark:ring-dark-100 shadow-md`,onError:u})}),(0,$.jsxs)(`div`,{className:`px-4 pt-2 pb-4`,children:[(0,$.jsx)(`h4`,{className:`text-base font-semibold text-gray-900 dark:text-gray-100`,children:e.name}),(0,$.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 flex items-center gap-1 mt-0.5`,children:[(0,$.jsx)(ae,{className:`h-3 w-3`}),e.model]}),e.description&&(0,$.jsx)(`p`,{className:`text-xs text-gray-600 dark:text-gray-400 mt-2 line-clamp-2`,children:e.description}),e.parameters.system_prompt&&(0,$.jsxs)(`div`,{className:`mt-3 p-2 rounded-lg bg-gray-50 dark:bg-dark-50 border border-gray-100 dark:border-dark-200`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 mb-1`,children:[(0,$.jsx)(ne,{className:`h-2.5 w-2.5 text-gray-400`}),(0,$.jsx)(`span`,{className:`text-[9px] uppercase tracking-wider font-medium text-gray-400`,children:`System`})]}),(0,$.jsxs)(`p`,{className:`text-[11px] text-gray-600 dark:text-gray-400 line-clamp-2 italic`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-sm text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[(0,$.jsx)(Ie,{className:`h-2.5 w-2.5`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded-sm text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[`Top-P `,e.parameters.top_p?.toFixed(1)||`0.9`]}),e.memory_settings?.enabled&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-sm text-[10px] font-medium bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300`,children:[(0,$.jsx)(Pe,{className:`h-2.5 w-2.5`}),`Memory`]})]})]})]})})]}),document.body)]})},gr=({images:e,onImagesChange:t,maxImages:n=5,className:r})=>{let{t:i}=w(),a=(0,Q.useRef)(null),[o,s]=(0,Q.useState)(!1),c=e=>new Promise(t=>{let n=new FileReader;n.onload=()=>t(typeof n.result==`string`?n.result:null),n.onerror=()=>{I.error(i(`chat.mediaUpload.readFailed`,{name:e.name})),t(null)},n.readAsDataURL(e)}),l=async r=>{if(!r)return;let a=n-e.length,o=Array.from(r).slice(0,Math.max(a,0)).filter(e=>e.type.startsWith(`image/`)?e.size>10485760?(I.error(i(`chat.mediaUpload.imageTooLarge`,{name:e.name})),!1):!0:(I.error(i(`chat.mediaUpload.unsupportedFileType`,{name:e.name})),!1));r.length>a&&I.error(i(`chat.mediaUpload.maxImagesAllowed`,{count:n}));let s=(await Promise.all(o.map(c))).filter(e=>e!==null);s.length>0&&t([...e,...s])},u=e=>{e.preventDefault(),s(!0)},d=e=>{e.preventDefault(),s(!1)},f=e=>{e.preventDefault(),s(!1),l(e.dataTransfer.files)},p=n=>{t(e.filter((e,t)=>t!==n))},m=e.length<n;return(0,$.jsxs)(`div`,{className:O(`space-y-3`,r),children:[m&&(0,$.jsxs)(`div`,{className:O(`border-2 border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-4 transition-colors`,`hover:border-primary-400 dark:hover:border-primary-500`,o&&`border-primary-500 bg-primary-50 dark:bg-primary-900/20`),onDragOver:u,onDragLeave:d,onDrop:f,children:[(0,$.jsx)(`input`,{ref:a,type:`file`,multiple:!0,accept:`image/*`,onChange:e=>{l(e.target.files),e.target.value=``},className:`hidden`}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,$.jsx)(G,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,$.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300 mb-2`,children:[i(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`button`,{type:`button`,onClick:()=>a.current?.click(),className:`text-primary-600 dark:text-primary-400 hover:underline font-medium`,children:i(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-ink-muted`,children:i(`chat.mediaUpload.supportedFormats`)})]})]}),e.length>0&&(0,$.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`relative group aspect-square rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,$.jsx)(`img`,{src:e,alt:i(`chat.mediaUpload.uploadAlt`,{number:t+1}),className:`w-full h-full object-cover`}),(0,$.jsx)(`div`,{className:`absolute inset-0 bg-black/0 group-hover:bg-black/50 transition-all duration-200 flex items-center justify-center`,children:(0,$.jsx)(q,{variant:`ghost`,size:`sm`,onClick:()=>p(t),"aria-label":i(`chat.mediaUpload.removeImage`,{number:t+1}),className:`opacity-0 group-hover:opacity-100 focus-visible:opacity-100 [@media(hover:none)]:opacity-100 transition-opacity bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 hover:bg-red-100 dark:hover:bg-red-900/20 hover:text-red-600 dark:hover:text-red-400 p-1 rounded-full`,children:(0,$.jsx)(U,{className:`h-4 w-4`})})})]},t))}),m&&e.length>0&&(0,$.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>a.current?.click(),className:`w-full sm:w-auto`,children:[(0,$.jsx)(N,{className:`h-4 w-4`}),i(`chat.mediaUpload.addMore`,{count:e.length,max:n})]})]})},_r=c(`pages:chat-page`),vr=(e,t,n=!1)=>{let r=new Date().getHours(),i=e?`${n?`،`:`,`} \u2068${e}\u2069`:``;return r>=5&&r<12?{id:`time`,title:`${t?t(`chat.greeting.morning`):`Good morning`}${i}`,subtitle:t?t(`chat.welcome.helpToday`):`What can I help with today?`}:r>=12&&r<17?{id:`time`,title:`${t?t(`chat.greeting.afternoon`):`Good afternoon`}${i}`,subtitle:t?t(`chat.welcome.helpToday`):`What can I help with today?`}:r>=17&&r<21?{id:`time`,title:`${t?t(`chat.greeting.evening`):`Good evening`}${i}`,subtitle:t?t(`chat.welcome.helpTonight`):`What can I help with tonight?`}:{id:`time`,title:`${t?t(`chat.greeting.night`):`Good night`}${i}`,subtitle:t?t(`chat.welcome.helpTonight`):`What can I help with tonight?`}},yr=(e,t,n,r=!1)=>{let i=Z(e);return i===`time`?vr(t,n,r):{id:i,title:n?n(`chat.welcome.variety.${i}.title`):`What should we make?`,subtitle:n?n(`chat.welcome.variety.${i}.subtitle`):`Start with a thought, a sketch, or a stubborn problem.`}},br=e=>{if(!e)return null;for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role===`assistant`)return{id:n.id,content:n.content}}return null},xr=()=>{let{t:e,i18n:t}=w(),{sessionId:n}=a(),r=i(),s=o(),{currentSession:c,sessions:d,models:p,selectedModel:h,selectedProviderType:g,selectedProviderId:v,setSelectedModel:y,createSession:x,setCurrentSession:E,loadSessions:D,getCurrentPersona:ee}=S(),{user:A}=ot(),j=k(e=>e.preferences.imageGenSettings?.enabled===!0),{sendMessage:ne,stopGeneration:re,cancelComparison:ie,regenerateLastMessage:ae,editAndResendMessage:oe,selectBranch:M,isStreaming:N,streamingMessage:P,streamingThinking:se,streamingMessageId:F,toolActivities:ce,activeToolCalls:le,pendingToolApproval:de,decideToolApproval:fe}=pt(c?.id||``),L=ee(),pe=(0,Q.useMemo)(()=>({model:h,providerType:g,providerId:v}),[h,v,g]),R=(0,Q.useMemo)(()=>u(p,pe),[p,pe]),me=h?b(R,pe):``,he=m(p,pe),ge=new URLSearchParams(s.search).get(`incognito`)===`1`,[_e,ve]=(0,Q.useState)(st),[be,Se]=(0,Q.useState)(null),[z,Ce]=(0,Q.useState)(!1),we=k(e=>e.preferences.showFollowUpSuggestions!==!1),Te=(0,Q.useRef)(null),Ee=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{let e=c?.id,t=Ee.current&&!N;if(Ee.current=N,!e||N||!we||c?.isPrivate||!t)return;let n=c.messages[c.messages.length-1];if(!n||n.role!==`assistant`||!n.content.trim()||Te.current===n.id)return;Te.current=n.id;let r=!1;return Y.generateFollowUps(e).then(t=>{!r&&t.success&&S.getState().currentSession?.id===e&&Se({sessionId:e,suggestions:t.data?.suggestions??[]})}).catch(()=>{}),()=>{r=!0}},[N,c,we]);let De=be&&be.sessionId===c?.id?be.suggestions:[],B=(0,Q.useMemo)(()=>yr(_e,A?.username,e,l(t.language)),[t.language,e,A?.username,_e]),[V,Oe]=(0,Q.useState)(``),[H,Ae]=(0,Q.useState)([]),[U,W]=(0,Q.useState)(!1),[G,K]=(0,Q.useState)(!1),[je,Me]=(0,Q.useState)(Hn),[Pe,Fe]=(0,Q.useState)(!1),Ie=(0,Q.useRef)(null),ze=S(e=>e.draftSessionSettings),Be=S(e=>e.setDraftSessionSettings),Ve=ze.generationOptions?.think,He=k(e=>(h?e.preferences.modelGenerationOptions?.[h]?.think:void 0)??e.preferences.generationOptions?.think??null),J=(0,Q.useMemo)(()=>p.find(e=>e.name===h),[p,h]),[Ue,We]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{if(!h||p.length===0||!J||J.isPlugin||J.isAgent)return;let e=!1;return at.getModelDefaults(h).then(t=>{!e&&t.success&&t.data&&We({model:h,supported:t.data.supportsThinking})}).catch(()=>{}),()=>{e=!0}},[h,J,p.length]);let Ge=!!(h&&!J?.isAgent&&(J?.isPlugin?J.reasoningSupport!==!1:Ue?.model!==h||Ue.supported!==!1)),Ke=e=>{let t=S.getState().draftSessionSettings,n={...t.generationOptions};e===null?delete n.think:n.think=e,Be({...t,generationOptions:Object.keys(n).length?n:void 0})},qe=async t=>{let n=t.target.files?.[0];if(t.target.value=``,n){Fe(!0);try{let t=await Qe.uploadDocument(n);t.success?(I.success(e(`chat.input.menu.documentAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`))):I.error(t.error||e(`chat.input.menu.attachFailed`))}catch(t){_r.error(`Document upload failed:`,t),I.error(e(`chat.input.menu.attachFailed`))}finally{Fe(!1)}}};(0,Q.useEffect)(()=>{let e=!1;return rt.getConfig().then(t=>{!e&&t.success&&t.data&&W(t.data.allowed)}).catch(()=>{}),()=>{e=!0}},[]);let[X,Je]=(0,Q.useState)(!1),Ye=(0,Q.useRef)(null),Xe=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=()=>{ve(st())};return window.addEventListener(ct,e),()=>window.removeEventListener(ct,e)},[]);let[Ze,$e]=(0,Q.useState)(!1),[et,tt]=(0,Q.useState)(!1),nt=br(c?.messages),Z=j&&Ze,dt=(0,Q.useCallback)((t=!0)=>{let n=h?pe:p[0]?f(p[0]):null;if(!n||!m(p,n))return t&&I.error(e(`chat.model.selectBeforePrivateChat`)),!1;let r=Date.now();return E({id:`private-${r}`,title:e(`chat.session.incognito`,`Incognito Chat`),model:n.model,providerType:n.providerType,providerId:n.providerId,messages:[],createdAt:r,updatedAt:r,isPrivate:!0}),!0},[p,h,pe,E,e]);(0,Q.useEffect)(()=>{d.length===0&&D()},[D,d.length]),(0,Q.useEffect)(()=>{ge&&!c?.isPrivate&&dt(!1)},[c?.isPrivate,ge,dt]),(0,Q.useEffect)(()=>{let e=!1;return j&&(async()=>{try{let t=await it.getPlugins();if(e)return;$e(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;$e(!1)}})(),()=>{e=!0}},[j]),(0,Q.useEffect)(()=>{(()=>{if(sessionStorage.getItem(`forceWelcomeScreen`)){sessionStorage.removeItem(`forceWelcomeScreen`);return}if((!c?.isPrivate||n)&&d.length!==0){if(n){let e=d.find(e=>e.id===n);e&&e.id!==c?.id?E(e):e||(_r.warn(`Session ${n} not found for current user, redirecting...`),d.length>0?r(`/c/${d[0].id}`,{replace:!0}):r(`/`,{replace:!0}))}else d.length>0&&s.pathname===`/`&&r(`/c/${d[0].id}`,{replace:!0})}})()},[n,d,E,r,c?.id,c?.isPrivate,s.pathname]),(0,Q.useEffect)(()=>{if(c?.id){let e=sessionStorage.getItem(`pendingMessage`);if(e){sessionStorage.removeItem(`pendingMessage`);try{let t=JSON.parse(e);setTimeout(()=>{ne(t.content,t.images,void 0,t.webSearch===!0,t.tools===!0,t.toolSelection)},100)}catch(e){_r.error(`Failed to parse pending message:`,e)}}}},[c?.id,ne]),(0,Q.useEffect)(()=>{let e=Ye.current;e&&(e.style.height=`auto`,e.style.height=V?`${Math.min(e.scrollHeight,200)}px`:``)},[V]);let ft=async t=>{if(t.preventDefault(),!V.trim()||!h)return;if(!he){I.error(e(`chat.model.selectBeforeSending`));return}lt(`impact`);let n={content:V.trim(),images:H.length>0?H:void 0,webSearch:U&&G?!0:void 0,...Un(je)};sessionStorage.setItem(`pendingMessage`,JSON.stringify(n));let i={message:V,images:H,webSearch:G,tools:je};Oe(``),Ae([]),K(!1),Me(Hn);let a;try{a=await x(h,void 0,h.startsWith(`persona:`)?h.slice(8):void 0,g,v)}catch{a=void 0}if(!a){sessionStorage.removeItem(`pendingMessage`),Oe(i.message),Ae(i.images),K(i.webSearch),Me(i.tools),S.getState().error||I.error(e(`chat.toasts.createFailed`));return}await mt(a),r(`/c/${a.id}`,{replace:!0})},mt=(0,Q.useCallback)(async e=>{let t=S.getState().draftSessionSettings,n=t.systemPrompt?.trim(),r=t.generationOptions;if(!n&&!r)return;let i=n?[{id:T(),role:`system`,content:n,timestamp:Date.now()},...e.messages.filter(e=>e.role!==`system`)]:e.messages;try{let t=await Y.updateSession(e.id,{messages:i,settings:r?{generationOptions:r}:void 0});if(t.success&&t.data){let e=t.data;S.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?e:t),currentSession:t.currentSession?.id===e.id?e:t.currentSession}))}}catch(e){_r.error(`Failed to apply chat settings to the new session`,e)}finally{S.getState().setDraftSessionSettings({})}},[]),ht=e=>{e.nativeEvent.isComposing||e.nativeEvent.keyCode===229||Xe.current?.handleKeyDown(e)||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),ft(e))},gt=async e=>{let t=C(R,e.target.value);t&&y(t.model,t.providerType,t.providerId)},_t=(e,t,n,r,i,a,o)=>{c&&(lt(`impact`),Se(null),ne(e,t,n,r,i,a,o))},vt=c?.id,yt=(0,Q.useCallback)(async t=>{if(vt)try{let n=await Y.forkSession(vt,{messageId:t});if(n.success&&n.data){let t=n.data;S.setState(e=>({sessions:[t,...e.sessions]})),I.success(e(`chat.fork.created`)),r(`/c/${t.id}`)}else I.error(n.error||e(`chat.fork.failed`))}catch(t){_r.error(`Failed to fork the chat:`,t),I.error(e(`chat.fork.failed`))}},[vt,r,e]);if(!c){let t=H.length>0;return(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`relative h-full min-w-0 flex-1 overflow-y-auto overflow-x-hidden px-4 py-20 sm:px-8 sm:py-24`,children:[(0,$.jsx)(`button`,{onClick:()=>Ce(e=>!e),className:O(`absolute inset-e-4 top-4 z-10 flex h-9 w-9 items-center justify-center rounded-full border border-black/[0.07] bg-surface/65 text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 dark:border-white/8 dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 sm:inset-e-6 sm:top-6`,z&&`text-primary-600 dark:text-primary-400`),type:`button`,title:e(`chat.controls.title`),"aria-label":e(`chat.controls.title`),"aria-expanded":z,children:(0,$.jsx)(ue,{className:`h-4 w-4`})}),(0,$.jsxs)(`button`,{onClick:()=>dt(),disabled:!h&&p.length===0||!!h&&!he,className:`absolute inset-e-15 top-4 z-10 flex items-center gap-2 rounded-full border border-black/[0.07] bg-surface/65 px-3 py-2 text-xs font-medium text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/8 dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 sm:inset-e-17 sm:top-6`,title:e(`chat.session.privateTooltip`),children:[(0,$.jsx)(ke,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{children:e(`chat.session.incognito`,`Incognito Chat`)})]}),(0,$.jsxs)(`div`,{className:`relative z-1 mx-auto flex min-h-full w-full max-w-3xl flex-col items-center justify-center`,children:[(0,$.jsxs)(`div`,{className:`mb-8 flex flex-col items-center text-center animate-fade-in sm:mb-10`,"aria-live":`polite`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-center gap-3`,children:[(0,$.jsx)(ut,{size:`sm`,label:null,className:`h-9 w-9 shrink-0 p-0 text-ink`}),(0,$.jsx)(`h1`,{className:`max-w-3xl text-balance text-[clamp(1.75rem,3.5vw,2.35rem)] font-medium leading-tight tracking-[-0.02em] text-ink rtl:tracking-normal`,children:B.title})]}),(0,$.jsx)(`p`,{className:`max-w-xl text-balance text-[15px] leading-relaxed text-ink-subtle`,children:B.subtitle})]},B.id),R.length>0?(0,$.jsxs)(`div`,{className:`w-full`,children:[X&&(0,$.jsxs)(`div`,{className:`mb-3 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/80 p-4 shadow-xs backdrop-blur-xl dark:border-white/8 dark:bg-dark-200/80`,children:[(0,$.jsx)(gr,{images:H,onImagesChange:Ae,maxImages:5}),(0,$.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-3 border-t border-black/6 pt-3 dark:border-white/[0.07]`,children:[(0,$.jsx)(`span`,{className:`text-xs text-ink-muted`,children:e(`chat.input.menu.attachDocument`)}),(0,$.jsxs)(q,{type:`button`,size:`sm`,variant:`outline`,disabled:Pe,onClick:()=>Ie.current?.click(),className:`shrink-0 whitespace-nowrap`,children:[(0,$.jsx)(Re,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`ms-1.5`,children:e(Pe?`documents.uploading`:`chat.input.menu.attach`)})]}),(0,$.jsx)(`input`,{ref:Ie,type:`file`,accept:Nn,className:`hidden`,onChange:e=>void qe(e)})]})]}),(0,$.jsx)(`form`,{onSubmit:ft,children:(0,$.jsxs)(`div`,{"data-composer-box":``,className:jt,children:[(0,$.jsx)(zn,{ref:Xe,message:V,onApply:e=>{Oe(e),Ye.current?.focus()}}),(0,$.jsx)(_n,{ref:Ye,value:V,onChange:e=>Oe(e.target.value),onKeyDown:ht,placeholder:e(`chat.input.messagePlaceholder`),"aria-label":e(`chat.input.messagePlaceholder`),className:`m-0! block w-full min-h-9 max-h-[160px] resize-none rounded-none! border-0! bg-transparent! px-2! pt-1.5! pb-2! shadow-none! scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-ink-subtle focus:border-0! focus:bg-transparent! focus:shadow-none! focus:ring-0! dark:scrollbar-thumb-dark-400 text-[0.9375rem] leading-relaxed touch-manipulation`,rows:1}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>Je(!X),className:O(`h-9 w-9 p-0! rounded-full shrink-0`,`bg-surface-subtle text-ink-muted hover:bg-hover-solid hover:text-ink dark:bg-surface-raised dark:hover:bg-surface-overlay transition-colors touch-manipulation`,t&&`text-primary-600 dark:text-primary-400`,X&&`bg-hover-solid text-ink`),title:e(`chat.input.attachImages`),"aria-label":e(`chat.input.attachImages`),"aria-expanded":X,children:t?(0,$.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,$.jsx)(Re,{className:`h-4 w-4`}),(0,$.jsx)(`div`,{className:`absolute -top-0.5 -inset-e-0.5 h-1.5 w-1.5 bg-primary-500 rounded-full`})]}):X?(0,$.jsx)(te,{className:`h-4 w-4`}):(0,$.jsx)(Le,{className:`h-4 w-4`})}),Ge&&(0,$.jsx)(Ot,{value:Ve,inheritedValue:He,onChange:Ke}),U&&(0,$.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>K(e=>!e),className:O(`h-9 w-9 p-0 rounded-full shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,G&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:e(G?`chat.input.webSearchOn`:`chat.input.webSearchOff`),"aria-label":e(G?`chat.input.webSearchOn`:`chat.input.webSearchOff`),"aria-pressed":G,children:(0,$.jsx)(Ne,{className:`h-4 w-4`})}),(0,$.jsx)(Vn,{value:je,onChange:Me,buttonClassName:`h-9 w-9`}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`}),(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(kt,{models:R,selectedModel:me,onModelChange:gt,getModelValue:_,className:`min-w-[140px] max-w-[210px]`,compact:!0,showImageGen:Z})}),(0,$.jsx)(q,{type:`submit`,variant:`primary`,size:`sm`,disabled:!V.trim()||!h||!he,className:Mt,title:e(`chat.input.sendMessage`),"aria-label":e(`chat.input.sendMessage`),children:(0,$.jsx)(ye,{className:`h-4 w-4`})})]})]})}),(0,$.jsx)(`div`,{className:`sm:hidden mt-4`,children:(0,$.jsx)(kt,{models:R,selectedModel:me,onModelChange:gt,getModelValue:_,className:`w-full`,compact:!0,showImageGen:Z})}),(0,$.jsx)(`p`,{className:`mt-4 text-center text-[10px] leading-relaxed text-ink-subtle`,children:e(`chat.footer.disclaimer`)})]}):(0,$.jsxs)(`div`,{className:`flex w-full max-w-lg flex-col items-center gap-4`,children:[(0,$.jsx)(`p`,{className:`text-center text-sm leading-relaxed text-gray-600 dark:text-dark-700`,children:e(`chat.model.connectDescription`)}),(0,$.jsx)(St,{variant:`inline`})]})]})]}),(0,$.jsx)(lr,{draftModel:h,open:z,onClose:()=>Ce(!1)})]})}return(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col`,style:L?.background?{backgroundImage:`url(${L.background})`,backgroundSize:`cover`,backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,children:[L?.background&&(0,$.jsx)(`div`,{className:`absolute inset-0 bg-gray-50/88 backdrop-blur-sm dark:bg-dark-100/88`}),(0,$.jsxs)(`div`,{className:`relative z-10 flex h-full flex-col`,children:[c?.isPrivate&&(0,$.jsx)(`div`,{className:`shrink-0 border-b border-black/5 bg-surface/55 px-4 py-2 backdrop-blur-xl dark:border-white/6 dark:bg-dark-100/55`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-gray-500 dark:text-dark-600`,children:[(0,$.jsx)(ke,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:e(`chat.session.privateMode`)}),(0,$.jsxs)(`span`,{className:`hidden text-[11px] text-ink-subtle sm:inline`,children:[`— `,e(`chat.session.privateDescription`)]})]})}),L&&!c?.isPrivate&&(0,$.jsx)(`div`,{className:`shrink-0 border-b border-black/5 bg-surface/55 px-4 py-2 backdrop-blur-xl dark:border-white/6 dark:bg-dark-100/55`,children:(0,$.jsx)(hr,{persona:L,onClear:()=>{c&&Y.updateSession(c.id,{model:L.model,providerType:`ollama`,providerId:null,personaId:null}).then(e=>{if(!e.success||!e.data)throw Error(e.error||`Failed to remove persona`);S.setState(t=>({sessions:t.sessions.map(t=>t.id===c.id?e.data:t),currentSession:e.data}))}).catch(t=>{_r.error(`Failed to remove persona:`,t),I.error(e(`chat.persona.removeFailed`))})}})}),(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`relative flex min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`button`,{onClick:()=>Ce(e=>!e),className:O(`absolute inset-e-3 top-3 z-20 flex h-8 w-8 items-center justify-center rounded-full border border-black/[0.07] bg-surface/65 text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 dark:border-white/8 dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950`,z&&`text-primary-600 dark:text-primary-400`),type:`button`,title:e(`chat.controls.title`),"aria-label":e(`chat.controls.title`),"aria-expanded":z,children:(0,$.jsx)(ue,{className:`h-3.5 w-3.5`})}),c.settings?.forkedFrom&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(`/c/${c.settings.forkedFrom.sessionId}`),className:`mx-auto mt-2 flex items-center gap-1.5 rounded-full border border-black/[0.07] bg-surface/70 px-3 py-1 text-[11px] text-gray-500 transition-colors hover:text-gray-800 dark:border-white/8 dark:bg-dark-200/70 dark:text-dark-600 dark:hover:text-dark-900`,"data-testid":`forked-from-banner`,children:[(0,$.jsx)(xe,{className:`h-3 w-3`}),e(`chat.fork.origin`,{title:c.settings.forkedFrom.title||e(`chat.fork.originUnknown`)})]}),(0,$.jsx)(hn,{messages:c.messages,streamingMessage:P,streamingThinking:se,streamingMessageId:F,isStreaming:N,toolActivities:ce,activeToolCalls:le,pendingToolApproval:de,onDecideToolApproval:fe,onRegenerate:ae,onSelectBranch:M,onEditResend:oe,onFork:yt,followUpSuggestions:De,onFollowUpSelect:e=>_t(e),className:`flex-1`}),c?.shared?(0,$.jsx)(`div`,{className:`mx-auto mb-4 w-full max-w-3xl rounded-xl border border-black/6 bg-black/2 px-4 py-3 text-center text-[13px] text-gray-500 dark:border-white/8 dark:bg-white/3 dark:text-dark-600`,"data-testid":`chat-shared-readonly`,children:e(`chat.sharedReadOnly`,{owner:c.shared.ownerUserId})}):(0,$.jsx)(Kn,{onSendMessage:_t,onStopGeneration:re,onCancelComparison:ie,onOpenVoiceMode:()=>tt(!0),disabled:!c})]}),et&&c&&(0,$.jsx)(or,{onClose:()=>tt(!1),onSendMessage:e=>_t(e),isStreaming:N,lastAssistantMessage:nt}),(0,$.jsx)(mr,{session:c}),(0,$.jsx)(lr,{session:c,open:z,onClose:()=>Ce(!1)})]})]})]})};export{xr as ChatPage,xr as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-CR5VJ85Q.js";import{t as r}from"./logger-BR4forr_.js";import{t as i}from"./chatStore-CVTbkZyb.js";import{t as a}from"./useTranslation-Boi0fB1B.js";import{t as o}from"./utils-B-Bhh1pF.js";import{Dr as s,Kt as c,Mn as l,Q as ee,U as te,Zn as u,er as d,et as f,rt as p,zn as m}from"./ui-vendor-6S05F84J.js";import{t as h}from"./Button-Dh2UJA-B.js";import"./ui-CI0OdG9q.js";import{u as g,y as _}from"./api-Dcz1G4Ib.js";import{t as v}from"./authStore-COgKeTRv.js";var y=e(t(),1),b=n(),x=r(`components:connect-models`),S=[{id:`llama-cpp`,name:`llama.cpp`,baseUrl:`http://localhost:8080/v1`},{id:`vllm`,name:`vLLM`,baseUrl:`http://localhost:8000/v1`},{id:`llama-swap`,name:`llama-swap`,baseUrl:`http://localhost:8080/v1`},{id:`lm-studio`,name:`LM Studio`,baseUrl:`http://localhost:1234/v1`},{id:`mlx-lm`,name:`mlx-lm`,baseUrl:`http://localhost:8080/v1`}],C=[{id:`openai`,name:`OpenAI`},{id:`anthropic`,name:`Anthropic`},{id:`groq`,name:`Groq`},{id:`openrouter`,name:`OpenRouter`},{id:`gemini`,name:`Google Gemini`},{id:`mistral`,name:`Mistral`},{id:`deepseek`,name:`DeepSeek`},{id:`bedrock`,name:`Amazon Bedrock`}],w=({variant:e=`setup`,onDone:t})=>{let{t:n}=a(),{user:r,systemInfo:w}=v(),T=i(e=>e.loadModels),E=r?.role===`admin`||w?.requiresAuth===!1,[D,O]=(0,y.useState)(()=>w?.ollamaEnabled===!1?`disabled`:`checking`),[k,A]=(0,y.useState)(null),[j,M]=(0,y.useState)(S[0]),[N,P]=(0,y.useState)(S[0].baseUrl),[F,I]=(0,y.useState)(``),[L,R]=(0,y.useState)(!1),[z,B]=(0,y.useState)(null),[V,H]=(0,y.useState)(!1),[U,W]=(0,y.useState)(null),[G,K]=(0,y.useState)(``),[q,J]=(0,y.useState)(!1),Y=(0,y.useCallback)(async()=>{try{let e=await _.checkHealth();e.success&&e.data?.status===`disabled`?O(`disabled`):e.success&&e.data?.status===`healthy`?O(`healthy`):O(`offline`)}catch{O(`offline`)}},[]);(0,y.useEffect)(()=>{if(w?.ollamaEnabled===!1)return;let e=window.setTimeout(()=>{Y()},0);return()=>window.clearTimeout(e)},[Y,w?.ollamaEnabled]);let X=async e=>{try{(await _.updateSettings({enabled:e})).success?(s.success(n(e?`connectModels.ollama.enabledToast`:`connectModels.ollama.disabledToast`)),e?(O(`checking`),Y()):O(`disabled`)):s.error(n(`connectModels.ollama.settingsFailed`))}catch(e){x.error(`Failed to update Ollama settings:`,e),s.error(n(`connectModels.ollama.settingsFailed`))}},Z=async()=>{R(!0),B(null);try{let e=await g.probeEndpoint(N,`openai`);e.success&&e.data?.reachable?(B(e.data.models),s.success(n(`connectModels.local.reachable`,{count:e.data.models.length}))):(B([]),s.error(e.message||n(`connectModels.local.unreachable`)))}catch(e){x.error(`Endpoint probe failed:`,e),B([]),s.error(n(`connectModels.local.unreachable`))}finally{R(!1)}},ne=async()=>{H(!0);try{let e=N.replace(/\/+$/,``),r=e.endsWith(`/v1`)?e:`${e}/v1`,i=F.trim().length>0,a=`${j.id.toUpperCase().replace(/-/g,`_`)}_API_KEY`,o={id:j.id,name:j.name,type:`completion`,endpoint:`${r}/chat/completions`,api_mode:`chat_completions`,base_url:r,auth:i?{header:`Authorization`,prefix:`Bearer `,key_env:a}:{header:``,prefix:``,key_env:``},model_map:(z??[]).slice(0,50)};if(!(await g.installPlugin(o)).success&&!(await g.updatePlugin(j.id,o)).success){s.error(n(`connectModels.local.enableFailed`));return}i&&await g.setApiKey(j.id,F.trim()),await g.activatePlugin(j.id),await T({quiet:!0}),s.success(n(`connectModels.local.enabled`,{name:j.name})),t?.()}catch(e){x.error(`Failed to enable local provider:`,e),s.error(n(`connectModels.local.enableFailed`))}finally{H(!1)}},re=async()=>{if(U&&G.trim()){J(!0);try{if(!(await g.setApiKey(U.id,G.trim())).success){s.error(n(`connectModels.cloud.saveFailed`));return}await g.activatePlugin(U.id),await T({quiet:!0}),s.success(n(`connectModels.cloud.connected`,{name:U.name})),K(``),t?.()}catch(e){x.error(`Failed to connect cloud provider:`,e),s.error(n(`connectModels.cloud.saveFailed`))}finally{J(!1)}}},Q=`rounded-2xl border border-gray-200/80 bg-white/80 p-4 dark:border-white/10 dark:bg-white/4`,$=`w-full rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm text-gray-900 placeholder-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800 dark:placeholder-dark-500`,ie={checking:`bg-gray-400 animate-pulse`,healthy:`bg-green-500`,offline:`bg-red-500`,disabled:`bg-gray-400`}[D];return(0,b.jsxs)(`div`,{className:o(`flex w-full flex-col gap-3`,`max-w-lg`),children:[(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(l,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:`Ollama`}),(0,b.jsx)(`span`,{className:o(`h-2 w-2 rounded-full`,ie)})]}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.ollama.status.${D}`)})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[D!==`disabled`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>{O(`checking`),Y()},title:n(`connectModels.ollama.recheck`),"aria-label":n(`connectModels.ollama.recheck`),children:(0,b.jsx)(ee,{className:o(`h-4 w-4`,D===`checking`&&`animate-spin`)})}),E&&D===`offline`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>void X(!1),title:n(`connectModels.ollama.disable`),"aria-label":n(`connectModels.ollama.disable`),children:(0,b.jsx)(f,{className:`h-4 w-4`})}),E&&D===`disabled`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>void X(!0),children:n(`connectModels.ollama.enable`)})]})]}),D===`offline`&&(0,b.jsx)(`p`,{className:`mt-3 text-xs leading-relaxed text-gray-500 dark:text-dark-500`,children:n(`connectModels.ollama.offlineHint`)}),D===`healthy`&&(0,b.jsx)(`p`,{className:`mt-3 text-xs leading-relaxed text-success-800 dark:text-success-400`,children:n(`connectModels.ollama.healthyHint`)})]}),(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-3 text-start`,"aria-expanded":k===`local`,onClick:()=>A(k===`local`?null:`local`),children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(te,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:n(`connectModels.local.title`)}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.local.subtitle`)})]}),(0,b.jsx)(u,{className:o(`h-4 w-4 text-gray-400 transition-transform rtl:rotate-180`,k===`local`&&`rotate-90 rtl:rotate-90`)})]}),k===`local`&&(0,b.jsx)(`div`,{className:`mt-4 flex flex-col gap-3`,children:E?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:S.map(e=>(0,b.jsx)(`button`,{type:`button`,onClick:()=>{M(e),P(e.baseUrl),B(null)},"aria-pressed":j.id===e.id,className:o(`rounded-full border px-3 py-1 text-xs transition-colors`,j.id===e.id?`border-primary-400 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-gray-200 text-gray-600 hover:border-gray-300 dark:border-white/10 dark:text-dark-600`),children:e.name},e.id))}),(0,b.jsx)(`input`,{className:$,type:`url`,"aria-label":n(`connectModels.local.urlLabel`),autoCapitalize:`none`,value:N,onChange:e=>{P(e.target.value),B(null)},placeholder:`http://localhost:8080/v1`,spellCheck:!1}),(0,b.jsx)(`input`,{className:$,value:F,onChange:e=>I(e.target.value),placeholder:n(`connectModels.local.keyPlaceholder`),"aria-label":n(`connectModels.local.keyPlaceholder`),type:`password`,autoComplete:`off`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsxs)(h,{variant:`outline`,size:`sm`,onClick:()=>void Z(),disabled:L||!N.trim(),children:[(0,b.jsx)(p,{className:`me-1.5 h-4 w-4`}),n(L?`connectModels.local.testing`:`connectModels.local.test`)]}),(0,b.jsxs)(h,{size:`sm`,onClick:()=>void ne(),disabled:V||!z||z.length===0,children:[(0,b.jsx)(d,{className:`me-1.5 h-4 w-4`}),n(V?`connectModels.local.enabling`:`connectModels.local.enable`)]})]}),z&&z.length>0&&(0,b.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[z.slice(0,8).map(e=>(0,b.jsx)(`span`,{className:`rounded-md bg-gray-100 px-2 py-0.5 font-mono text-[10px] text-gray-700 dark:bg-white/6 dark:text-dark-700`,children:e},e)),z.length>8&&(0,b.jsxs)(`span`,{className:`px-1 text-[10px] text-gray-400`,children:[`+`,z.length-8]})]}),z&&z.length===0&&(0,b.jsx)(`p`,{role:`alert`,className:`text-xs text-error-700 dark:text-error-400`,children:n(`connectModels.local.noModels`)})]}):(0,b.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.adminOnly`)})})]}),(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-3 text-start`,"aria-expanded":k===`cloud`,onClick:()=>A(k===`cloud`?null:`cloud`),children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(m,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:n(`connectModels.cloud.title`)}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.cloud.subtitle`)})]}),(0,b.jsx)(u,{className:o(`h-4 w-4 text-gray-400 transition-transform rtl:rotate-180`,k===`cloud`&&`rotate-90 rtl:rotate-90`)})]}),k===`cloud`&&(0,b.jsx)(`div`,{className:`mt-4 flex flex-col gap-3`,children:E?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:C.map(e=>(0,b.jsx)(`button`,{type:`button`,onClick:()=>W(e),"aria-pressed":U?.id===e.id,className:o(`rounded-full border px-3 py-1 text-xs transition-colors`,U?.id===e.id?`border-primary-400 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-gray-200 text-gray-600 hover:border-gray-300 dark:border-white/10 dark:text-dark-600`),children:e.name},e.id))}),U&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`relative`,children:[(0,b.jsx)(c,{className:`absolute inset-s-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,b.jsx)(`input`,{className:o($,`ps-9`),value:G,onChange:e=>K(e.target.value),placeholder:n(`connectModels.cloud.keyPlaceholder`,{name:U.name}),"aria-label":n(`connectModels.cloud.keyLabel`,{name:U.name}),type:`password`,autoComplete:`off`})]}),(0,b.jsx)(`div`,{children:(0,b.jsxs)(h,{size:`sm`,onClick:()=>void re(),disabled:q||!G.trim(),children:[(0,b.jsx)(d,{className:`me-1.5 h-4 w-4`}),n(q?`connectModels.cloud.connecting`:`connectModels.cloud.connect`)]})})]})]}):(0,b.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.adminOnly`)})})]}),e===`setup`&&(0,b.jsx)(`div`,{className:`mt-1 text-center`,children:(0,b.jsx)(`button`,{type:`button`,onClick:()=>t?.(),className:`text-sm text-gray-500 underline-offset-4 hover:underline dark:text-dark-500`,children:n(`connectModels.skip`)})})]})};export{w as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-CR5VJ85Q.js";import{t as r}from"./chatStore-CVTbkZyb.js";import{t as i}from"./useTranslation-Boi0fB1B.js";import{t as a}from"./utils-B-Bhh1pF.js";import{An as o,Bt as s,C as c,Dr as l,Rt as ee,h as u,it as d,n as te,tt as ne,v as re,y as ie}from"./ui-vendor-6S05F84J.js";import{t as f}from"./Button-Dh2UJA-B.js";import{o as p,r as m,s as h}from"./ui-CI0OdG9q.js";import{t as g}from"./confirmStore-CKkUtP9c.js";import{t as _}from"./evaluationsApi-BwaxBVpl.js";var v=e(t(),1),y=n(),b=`w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-dark-300 dark:bg-dark-50`,x=()=>{let{t:e,i18n:t}=i(),n=r(e=>e.models),x=r(e=>e.loadModels),[S,C]=(0,v.useState)(`arena`),[w,T]=(0,v.useState)(0),[E,D]=(0,v.useState)(``),[O,k]=(0,v.useState)(``),[A,ae]=(0,v.useState)(``),[j,M]=(0,v.useState)(null),[N,P]=(0,v.useState)(!1),[F,I]=(0,v.useState)(!1),[L,R]=(0,v.useState)([]),[z,B]=(0,v.useState)([]),[V,H]=(0,v.useState)([]),[U,W]=(0,v.useState)([]),[G,K]=(0,v.useState)(``),[q,J]=(0,v.useState)(``),[Y,oe]=(0,v.useState)(``);(0,v.useEffect)(()=>{x()},[x]),(0,v.useEffect)(()=>{let t=!1;return Promise.all([_.leaderboard(),_.listSets(),_.listRuns(),_.listFeedback()]).then(([e,n,r,i])=>{t||(e.success&&e.data&&R(e.data),n.success&&n.data&&B(n.data),r.success&&r.data&&H(r.data),i.success&&i.data&&W(i.data))}).catch(()=>l.error(e(`evaluations.loadFailed`))),()=>{t=!0}},[w,e]),(0,v.useEffect)(()=>{if(!V.some(e=>e.status===`queued`||e.status===`running`))return;let e=window.setInterval(()=>T(e=>e+1),4e3);return()=>window.clearInterval(e)},[V]);let X=n.map(e=>e.name),se=async()=>{if(E.trim()&&O&&A&&!F){I(!0),M(null),P(!1);try{let e=await _.runArenaMatch({prompt:E.trim(),modelA:O,modelB:A});if(!e.success||!e.data)throw Error(e.message||e.error);M(e.data)}catch(t){l.error(t instanceof Error?t.message:e(`evaluations.matchFailed`))}finally{I(!1)}}},Z=async t=>{if(j&&!N)try{let n=j.candidates.find(e=>e.key===`a`)?.model,r=j.candidates.find(e=>e.key===`b`)?.model;if(!n||!r)return;let i=await _.voteArena({compareGroup:j.compareGroup,modelA:n,modelB:r,winner:t});if(!i.success)throw Error(i.message);P(!0),T(e=>e+1),l.success(e(`evaluations.voteRecorded`))}catch(t){l.error(t instanceof Error?t.message:e(`evaluations.voteFailed`))}},Q=async()=>{let t=q.split(`
|
|
2
|
+
`).map(e=>e.trim()).filter(Boolean);if(G.trim()&&t.length!==0)try{let n=await _.saveSet({name:G.trim(),items:t.map(e=>({prompt:e}))});if(!n.success)throw Error(n.message);K(``),J(``),T(e=>e+1),l.success(e(`evaluations.setSaved`))}catch(t){l.error(t instanceof Error?t.message:e(`evaluations.saveFailed`))}},ce=async t=>{if(!Y){l.error(e(`evaluations.pickModel`));return}try{let n=await _.startRun({setId:t,model:Y});if(!n.success)throw Error(n.message);T(e=>e+1),l.success(e(`evaluations.runStarted`))}catch(t){l.error(t instanceof Error?t.message:e(`evaluations.saveFailed`))}},le=async t=>{try{let e=await _.exportRun(t),n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=`eval-run-${t}.json`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}catch{l.error(e(`evaluations.exportFailed`))}},$=[{id:`arena`,label:e(`evaluations.tabs.arena`)},{id:`leaderboard`,label:e(`evaluations.tabs.leaderboard`)},{id:`sets`,label:e(`evaluations.tabs.sets`)},{id:`feedback`,label:e(`evaluations.tabs.feedback`)}];return(0,y.jsxs)(h,{width:`wide`,children:[(0,y.jsx)(p,{title:e(`evaluations.title`),description:e(`evaluations.description`)}),(0,y.jsx)(`div`,{role:`tablist`,"aria-label":e(`evaluations.title`),className:`mb-4 inline-flex rounded-xl border border-gray-200 bg-white/70 p-1 dark:border-white/8 dark:bg-dark-100/70`,onKeyDown:e=>{let n=$.findIndex(e=>e.id===S),r=t.dir()===`rtl`,i=r?`ArrowLeft`:`ArrowRight`,a=r?`ArrowRight`:`ArrowLeft`,o=-1;e.key===i?o=(n+1)%$.length:e.key===a?o=(n-1+$.length)%$.length:e.key===`Home`?o=0:e.key===`End`&&(o=$.length-1);let s=$[o];s&&(e.preventDefault(),C(s.id),document.getElementById(`evaluations-tab-${s.id}`)?.focus())},children:$.map(e=>(0,y.jsx)(`button`,{id:`evaluations-tab-${e.id}`,type:`button`,role:`tab`,"aria-selected":S===e.id,"aria-controls":`evaluations-tabpanel`,tabIndex:S===e.id?0:-1,onClick:()=>C(e.id),className:a(`rounded-lg px-3 py-1.5 text-xs font-medium transition-colors`,S===e.id?`bg-gray-950 text-white dark:bg-white dark:text-gray-950`:`text-gray-500 hover:text-gray-900 dark:text-dark-500 dark:hover:text-dark-900`),children:e.label},e.id))}),S===`arena`&&(0,y.jsxs)(`div`,{id:`evaluations-tabpanel`,role:`tabpanel`,"aria-labelledby":`evaluations-tab-arena`,className:`space-y-4`,"data-testid":`arena-tab`,children:[(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[(0,y.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,y.jsxs)(`label`,{className:`text-xs text-gray-600 dark:text-gray-300`,children:[e(`evaluations.arenaModelA`),(0,y.jsxs)(`select`,{className:`${b} mt-1`,value:O,onChange:e=>k(e.target.value),children:[(0,y.jsx)(`option`,{value:``,children:`—`}),X.map(e=>(0,y.jsx)(`option`,{value:e,children:e},`a-${e}`))]})]}),(0,y.jsxs)(`label`,{className:`text-xs text-gray-600 dark:text-gray-300`,children:[e(`evaluations.arenaModelB`),(0,y.jsxs)(`select`,{className:`${b} mt-1`,value:A,onChange:e=>ae(e.target.value),children:[(0,y.jsx)(`option`,{value:``,children:`—`}),X.map(e=>(0,y.jsx)(`option`,{value:e,children:e},`b-${e}`))]})]})]}),(0,y.jsx)(`textarea`,{className:`${b} mt-2`,rows:3,placeholder:e(`evaluations.arenaPrompt`),"aria-label":e(`evaluations.arenaPrompt`),value:E,onChange:e=>D(e.target.value),"data-testid":`arena-prompt`}),(0,y.jsxs)(f,{className:`mt-2`,onClick:()=>void se(),disabled:F||!E.trim()||!O||!A||O===A,"data-testid":`arena-start`,children:[F?(0,y.jsx)(ee,{className:`me-1 h-4 w-4 animate-spin`}):(0,y.jsx)(c,{className:`me-1 h-4 w-4`}),e(`evaluations.startMatch`)]}),(0,y.jsx)(`p`,{className:`mt-1 text-xs text-gray-500`,children:e(`evaluations.arenaHint`)})]}),j&&(0,y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[j.candidates.map((t,n)=>(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-3 dark:border-dark-300 dark:bg-dark-100`,children:[(0,y.jsx)(`p`,{className:`mb-2 text-xs font-semibold text-gray-500`,children:N?t.model:e(`evaluations.candidate`,{letter:n+1})}),(0,y.jsx)(`div`,{className:`max-h-80 overflow-y-auto whitespace-pre-wrap text-sm text-gray-800 dark:text-gray-200`,children:t.output||`—`})]},t.key)),!N&&(0,y.jsxs)(`div`,{className:`sm:col-span-2 flex flex-wrap gap-2`,children:[(0,y.jsx)(f,{size:`sm`,onClick:()=>void Z(j.candidates[0].key),children:e(`evaluations.voteFirst`)}),(0,y.jsx)(f,{size:`sm`,onClick:()=>void Z(j.candidates[1].key),children:e(`evaluations.voteSecond`)}),(0,y.jsx)(f,{size:`sm`,variant:`outline`,onClick:()=>void Z(`tie`),children:e(`evaluations.voteTie`)}),(0,y.jsx)(f,{size:`sm`,variant:`outline`,onClick:()=>void Z(`both-bad`),children:e(`evaluations.voteBothBad`)})]})]})]}),S===`leaderboard`&&(0,y.jsx)(`div`,{id:`evaluations-tabpanel`,role:`tabpanel`,"aria-labelledby":`evaluations-tab-leaderboard`,className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:(0,y.jsxs)(`table`,{className:`w-full text-start text-sm`,children:[(0,y.jsx)(`thead`,{className:`text-xs text-gray-500`,children:(0,y.jsxs)(`tr`,{children:[(0,y.jsx)(`th`,{className:`py-1 pe-2`,children:`#`}),(0,y.jsx)(`th`,{className:`py-1 pe-2`,children:e(`evaluations.model`)}),(0,y.jsx)(`th`,{className:`py-1 pe-2`,children:e(`evaluations.rating`)}),(0,y.jsx)(`th`,{className:`py-1 pe-2`,children:e(`evaluations.record`)}),(0,y.jsx)(`th`,{className:`py-1`,children:e(`evaluations.votes`)})]})}),(0,y.jsxs)(`tbody`,{children:[L.map((e,t)=>(0,y.jsxs)(`tr`,{className:`border-t border-gray-100 dark:border-dark-300`,children:[(0,y.jsx)(`td`,{className:`py-1.5 pe-2`,children:t===0?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(u,{className:`h-4 w-4 text-amber-500`}),(0,y.jsx)(`span`,{className:`sr-only`,children:t+1})]}):t+1}),(0,y.jsx)(`td`,{className:`py-1.5 pe-2 font-medium`,children:e.model}),(0,y.jsx)(`td`,{className:`py-1.5 pe-2`,children:e.rating}),(0,y.jsxs)(`td`,{className:`py-1.5 pe-2 text-xs text-gray-500`,children:[e.wins,`W · `,e.losses,`L · `,e.ties,`T`]}),(0,y.jsx)(`td`,{className:`py-1.5`,children:e.votes})]},e.model)),L.length===0&&(0,y.jsx)(`tr`,{children:(0,y.jsx)(`td`,{colSpan:5,children:(0,y.jsx)(m,{icon:u,size:`sm`,title:e(`evaluations.noVotes`)})})})]})]})}),S===`sets`&&(0,y.jsxs)(`div`,{id:`evaluations-tabpanel`,role:`tabpanel`,"aria-labelledby":`evaluations-tab-sets`,className:`space-y-4`,children:[(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[(0,y.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:e(`evaluations.newSet`)}),(0,y.jsx)(`input`,{className:b,placeholder:e(`evaluations.setName`),"aria-label":e(`evaluations.setName`),value:G,onChange:e=>K(e.target.value)}),(0,y.jsx)(`textarea`,{className:`${b} mt-2`,rows:4,placeholder:e(`evaluations.setPrompts`),"aria-label":e(`evaluations.setPrompts`),value:q,onChange:e=>J(e.target.value)}),(0,y.jsxs)(f,{size:`sm`,className:`mt-2`,onClick:()=>void Q(),disabled:!G.trim()||!q.trim(),children:[(0,y.jsx)(ne,{className:`me-1 h-3.5 w-3.5`}),e(`evaluations.saveSet`)]})]}),(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[(0,y.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,y.jsx)(`h3`,{className:`text-sm font-semibold`,children:e(`evaluations.yourSets`)}),(0,y.jsxs)(`select`,{className:`rounded-lg border border-gray-300 bg-white px-2 py-1 text-xs focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-dark-300 dark:bg-dark-50`,"aria-label":e(`evaluations.pickModel`),value:Y,onChange:e=>oe(e.target.value),children:[(0,y.jsx)(`option`,{value:``,children:e(`evaluations.pickModel`)}),X.map(e=>(0,y.jsx)(`option`,{value:e,children:e},`run-${e}`))]})]}),z.length===0&&(0,y.jsx)(m,{icon:s,size:`sm`,title:e(`evaluations.noSets`)}),(0,y.jsx)(`div`,{className:`space-y-2`,children:z.map(t=>(0,y.jsxs)(`div`,{className:`rounded-lg border border-gray-200 p-2 dark:border-dark-300`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,y.jsxs)(`span`,{className:`min-w-0 truncate text-sm font-medium`,children:[t.name,(0,y.jsx)(`span`,{className:`ms-2 text-xs font-normal text-gray-500`,children:e(`evaluations.itemCount`,{total:t.items.length})})]}),(0,y.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,y.jsxs)(f,{size:`sm`,variant:`outline`,onClick:()=>void ce(t.id),children:[(0,y.jsx)(d,{className:`me-1 h-3 w-3`}),e(`evaluations.run`)]}),(0,y.jsx)(`button`,{type:`button`,onClick:async()=>{if(await g({title:e(`evaluations.deleteSetConfirmTitle`,{name:t.name}),description:e(`evaluations.deleteSetConfirmDescription`),destructive:!0}))try{await _.deleteSet(t.id),T(e=>e+1)}catch{l.error(e(`evaluations.deleteSetFailed`))}},className:`rounded-sm p-1.5 text-red-500 hover:bg-red-50 dark:hover:bg-red-950/30`,"aria-label":e(`evaluations.deleteSet`),children:(0,y.jsx)(re,{className:`h-3.5 w-3.5`})})]})]}),V.filter(e=>e.setId===t.id).slice(0,5).map(t=>(0,y.jsxs)(`div`,{className:`mt-1 flex items-center justify-between gap-2 rounded-sm bg-gray-50 px-2 py-1 text-xs dark:bg-dark-50`,children:[(0,y.jsxs)(`span`,{className:`min-w-0 truncate`,children:[t.model,` · `,e(`evaluations.status.${t.status}`),t.error?` — ${e(`evaluations.runError`,{detail:t.error})}`:``]}),(0,y.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(t.status===`queued`||t.status===`running`)&&(0,y.jsx)(`button`,{type:`button`,onClick:()=>{_.cancelRun(t.id).then(()=>T(e=>e+1)).catch(()=>l.error(e(`evaluations.cancelFailed`)))},className:`rounded-sm p-1 text-gray-500 hover:bg-gray-200 dark:hover:bg-dark-200`,"aria-label":e(`evaluations.cancelRun`),children:(0,y.jsx)(te,{className:`h-3 w-3`})}),t.status===`completed`&&(0,y.jsx)(`button`,{type:`button`,onClick:()=>void le(t.id),className:`rounded-sm p-1 text-gray-500 hover:bg-gray-200 dark:hover:bg-dark-200`,"aria-label":e(`evaluations.exportRun`),children:(0,y.jsx)(o,{className:`h-3 w-3`})})]})]},t.id))]},t.id))})]})]}),S===`feedback`&&(0,y.jsxs)(`div`,{id:`evaluations-tabpanel`,role:`tabpanel`,"aria-labelledby":`evaluations-tab-feedback`,className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[U.length===0&&(0,y.jsx)(m,{icon:ie,size:`sm`,title:e(`evaluations.noFeedback`)}),(0,y.jsx)(`div`,{className:`space-y-2`,children:U.map(e=>(0,y.jsxs)(`div`,{className:`rounded-lg border border-gray-200 p-2 text-sm dark:border-dark-300`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-xs text-gray-500`,children:[(0,y.jsxs)(`span`,{children:[e.rating===1?`👍`:`👎`,` `,e.model??``,e.tags.length>0&&` · ${e.tags.join(`, `)}`]}),(0,y.jsx)(`span`,{children:new Intl.DateTimeFormat(t.language,{dateStyle:`medium`}).format(e.createdAt)})]}),e.snapshot&&(0,y.jsx)(`p`,{className:`mt-1 line-clamp-2 text-xs text-gray-600 dark:text-gray-300`,children:e.snapshot.assistant}),e.comment&&(0,y.jsxs)(`p`,{className:`mt-1 text-xs italic text-gray-500`,children:[`“`,e.comment,`”`]})]},e.id))})]})]})};export{x as EvaluationsPage,x as default};
|