libre-webui 0.39.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.
Files changed (198) hide show
  1. package/backend/dist/persistence/extensionTypes.d.ts +2 -0
  2. package/backend/dist/persistence/extensionTypes.d.ts.map +1 -1
  3. package/backend/dist/persistence/extensionTypes.js.map +1 -1
  4. package/backend/dist/persistence/postgresExtensionRepositories.d.ts.map +1 -1
  5. package/backend/dist/persistence/postgresExtensionRepositories.js +6 -0
  6. package/backend/dist/persistence/postgresExtensionRepositories.js.map +1 -1
  7. package/backend/dist/persistence/sqliteExtensionRepositories.d.ts.map +1 -1
  8. package/backend/dist/persistence/sqliteExtensionRepositories.js +7 -0
  9. package/backend/dist/persistence/sqliteExtensionRepositories.js.map +1 -1
  10. package/backend/dist/routes/email.d.ts.map +1 -1
  11. package/backend/dist/routes/email.js +51 -1
  12. package/backend/dist/routes/email.js.map +1 -1
  13. package/backend/dist/routes/tts.d.ts.map +1 -1
  14. package/backend/dist/routes/tts.js +6 -1
  15. package/backend/dist/routes/tts.js.map +1 -1
  16. package/backend/dist/services/agentCliService.d.ts.map +1 -1
  17. package/backend/dist/services/agentCliService.js +1 -0
  18. package/backend/dist/services/agentCliService.js.map +1 -1
  19. package/backend/dist/services/emailService.d.ts +17 -3
  20. package/backend/dist/services/emailService.d.ts.map +1 -1
  21. package/backend/dist/services/emailService.js +73 -11
  22. package/backend/dist/services/emailService.js.map +1 -1
  23. package/backend/dist/services/pluginCredentialsService.d.ts +3 -0
  24. package/backend/dist/services/pluginCredentialsService.d.ts.map +1 -1
  25. package/backend/dist/services/pluginCredentialsService.js +18 -5
  26. package/backend/dist/services/pluginCredentialsService.js.map +1 -1
  27. package/backend/dist/services/pluginService.d.ts +9 -0
  28. package/backend/dist/services/pluginService.d.ts.map +1 -1
  29. package/backend/dist/services/pluginService.js +31 -14
  30. package/backend/dist/services/pluginService.js.map +1 -1
  31. package/backend/dist/services/workRuntimeService.d.ts +5 -0
  32. package/backend/dist/services/workRuntimeService.d.ts.map +1 -1
  33. package/backend/dist/services/workRuntimeService.js +243 -84
  34. package/backend/dist/services/workRuntimeService.js.map +1 -1
  35. package/backend/dist/utils/emailMarkdown.js +3 -3
  36. package/backend/dist/utils/emailMarkdown.js.map +1 -1
  37. package/backend/dist/utils/pluginDefinitionTrust.d.ts +7 -0
  38. package/backend/dist/utils/pluginDefinitionTrust.d.ts.map +1 -1
  39. package/backend/dist/utils/pluginDefinitionTrust.js +49 -1
  40. package/backend/dist/utils/pluginDefinitionTrust.js.map +1 -1
  41. package/backend/package.json +1 -1
  42. package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
  43. package/frontend/dist/artifact-runtime/mermaid.js +366 -366
  44. package/frontend/dist/assets/index-DLfU_qNT.js +75 -0
  45. package/frontend/dist/assets/index-DtS3qhdq.css +2 -0
  46. package/frontend/dist/assets/xterm-B1njb2Cr.css +1 -0
  47. package/frontend/dist/index.html +27 -26
  48. package/frontend/dist/js/ArtifactContainer-BjzltfdU.js +1 -0
  49. package/frontend/dist/js/{ArtifactDemoPage-Ddpy2O_v.js → ArtifactDemoPage-DWua6xj9.js} +1 -1
  50. package/frontend/dist/js/{ArtifactSandboxFrame-CdsAqv8H.js → ArtifactSandboxFrame-CR9ghP0A.js} +1 -1
  51. package/frontend/dist/js/ArtifactSlideOutPanel-DX2nL3AS.js +1 -0
  52. package/frontend/dist/js/AutomationModal-DZe-C2jN.js +1 -0
  53. package/frontend/dist/js/AutomationsPage-CrCcnTyk.js +1 -0
  54. package/frontend/dist/js/AvatarUpload-nPS0QHod.js +1 -0
  55. package/frontend/dist/js/Button-Dh2UJA-B.js +1 -0
  56. package/frontend/dist/js/CalendarPage-D2WiWglM.js +1 -0
  57. package/frontend/dist/js/ChannelsPage-COp2T8FQ.js +1 -0
  58. package/frontend/dist/js/ChatPage-CUfAlpdt.js +14 -0
  59. package/frontend/dist/js/ConnectModels-emc3dv4A.js +1 -0
  60. package/frontend/dist/js/EvaluationsPage-CbyeDkz_.js +2 -0
  61. package/frontend/dist/js/FirstTimeSetup-C4ffQRMN.js +1 -0
  62. package/frontend/dist/js/GalleryPage-D4Ci_3dv.js +1 -0
  63. package/frontend/dist/js/HomePage-C3IhEERN.js +1 -0
  64. package/frontend/dist/js/LanguageSwitcher-BQqDJPwm.js +1 -0
  65. package/frontend/dist/js/ModelManagerModals-DhY8Rme6.js +1 -0
  66. package/frontend/dist/js/NotesPage-j812I1BN.js +3 -0
  67. package/frontend/dist/js/PasswordStrengthMeter-BSEtQBJp.js +1 -0
  68. package/frontend/dist/js/PersonasPage--YWoThqF.js +13 -0
  69. package/frontend/dist/js/PluginUsagePage-CZiMdmjI.js +1 -0
  70. package/frontend/dist/js/{RichMessageContent-BfYbVBFz.js → RichMessageContent-BLI0hhzR.js} +2 -2
  71. package/frontend/dist/js/RichMessageContent-BXv5baJ_.js +1 -0
  72. package/frontend/dist/js/SettingsModal-C6aVzSI-.js +19 -0
  73. package/frontend/dist/js/SettingsToggle-CkLLtFbz.js +1 -0
  74. package/frontend/dist/js/ShareDialog-DQskc17d.js +1 -0
  75. package/frontend/dist/js/StrandsPage-DENhVKcz.js +1 -0
  76. package/frontend/dist/js/SystemPage-C86ypXG4.js +1 -0
  77. package/frontend/dist/js/UserManagementPanel-D1CS0KPn.js +1 -0
  78. package/frontend/dist/js/WhatsNewModal-B31A_UQY.js +1 -0
  79. package/frontend/dist/js/WorkPage-DEXBL5J7.js +7 -0
  80. package/frontend/dist/js/api-DRAKhdz7.js +1 -0
  81. package/frontend/dist/js/{api-BrHW-VGd.js → api-Dcz1G4Ib.js} +4 -2
  82. package/frontend/dist/js/{appNavigation-B6xYIgLi.js → appNavigation-C5A9BF_G.js} +1 -1
  83. package/frontend/dist/js/appStore-0_qlwS8f.js +2 -0
  84. package/frontend/dist/js/appVersion-D5lk_2zb.js +1 -0
  85. package/frontend/dist/js/ar-BZntyucf.js +2 -0
  86. package/frontend/dist/js/authStore-C4dzH1NY.js +1 -0
  87. package/frontend/dist/js/{authStore-DjAsRpNL.js → authStore-COgKeTRv.js} +3 -3
  88. package/frontend/dist/js/bn-BDCaFQu-.js +2 -0
  89. package/frontend/dist/js/chatStore-CVTbkZyb.js +3 -0
  90. package/frontend/dist/js/{client-DppLngAs.js → client-jaxZzn-I.js} +2 -2
  91. package/frontend/dist/js/{composerStyles-C83jssgZ.js → composerStyles-BEx0XAp6.js} +1 -1
  92. package/frontend/dist/js/{config-4_s8hdqO.js → config-Da1yh9sC.js} +1 -1
  93. package/frontend/dist/js/confirmStore-CKkUtP9c.js +1 -0
  94. package/frontend/dist/js/cs-BCmN--jQ.js +2 -0
  95. package/frontend/dist/js/da-B895dAyV.js +2 -0
  96. package/frontend/dist/js/de-B0ZhC0dm.js +2 -0
  97. package/frontend/dist/js/es-D7eaw4_W.js +2 -0
  98. package/frontend/dist/js/{evaluationsApi-DyuW7IJ_.js → evaluationsApi-BwaxBVpl.js} +1 -1
  99. package/frontend/dist/js/fr-DsB0gLW4.js +2 -0
  100. package/frontend/dist/js/hi-CLeU3ung.js +2 -0
  101. package/frontend/dist/js/id-Cdq6tOTi.js +2 -0
  102. package/frontend/dist/js/is-DJ1tHaAT.js +2 -0
  103. package/frontend/dist/js/it-9K1R4CeT.js +2 -0
  104. package/frontend/dist/js/ja-BYP_3M5M.js +2 -0
  105. package/frontend/dist/js/ko-CNtjlaDm.js +2 -0
  106. package/frontend/dist/js/liveAnnouncerStore-B6mS-JWC.js +1 -0
  107. package/frontend/dist/js/messageCodeStyles-D3cWF9XO.js +2 -0
  108. package/frontend/dist/js/ms-A_IVO_qt.js +2 -0
  109. package/frontend/dist/js/nl-CrKWO3ea.js +2 -0
  110. package/frontend/dist/js/pl-BrpSuyDP.js +2 -0
  111. package/frontend/dist/js/pt-BHbpB5BM.js +2 -0
  112. package/frontend/dist/js/ru-DzLsS9zY.js +2 -0
  113. package/frontend/dist/js/{strandsApi-BFbeEpAY.js → strandsApi-COxSPh_5.js} +1 -1
  114. package/frontend/dist/js/sv-VU2CjzNj.js +2 -0
  115. package/frontend/dist/js/{teamEventStream-DsAS6P4m.js → teamEventStream-RNJYm84u.js} +1 -1
  116. package/frontend/dist/js/th-DV2hNXXc.js +2 -0
  117. package/frontend/dist/js/tr-DvVZ9jxF.js +2 -0
  118. package/frontend/dist/js/ui-CI0OdG9q.js +2 -0
  119. package/frontend/dist/js/ui-vendor-6S05F84J.js +1 -0
  120. package/frontend/dist/js/uk-MFFDRo2m.js +2 -0
  121. package/frontend/dist/js/useChat-BSkqxHnH.js +13 -0
  122. package/frontend/dist/js/useDictation-D9whH12W.js +1 -0
  123. package/frontend/dist/js/vi-CfZ-U8Cw.js +2 -0
  124. package/frontend/dist/js/{work-CdbmBok5.js → work-C7MYlv5S.js} +1 -1
  125. package/frontend/dist/js/{workModels-BM2Zyiba.js → workAnnouncements-CAsI8P7c.js} +1 -1
  126. package/frontend/dist/js/workApi-BJfbaV6k.js +1 -0
  127. package/frontend/dist/js/{workApi-UPxumrEF.js → workApi-Ck8nTlJn.js} +1 -1
  128. package/frontend/dist/js/zh-CTl_raYa.js +2 -0
  129. package/package.json +3 -2
  130. package/plugins/codex-oauth.json +1 -0
  131. package/frontend/dist/assets/index-D99DS5c6.js +0 -57
  132. package/frontend/dist/assets/index-Dz1JufgZ.css +0 -1
  133. package/frontend/dist/assets/xterm-B8QFf3JU.css +0 -1
  134. package/frontend/dist/js/ArtifactContainer-Cn7X9HGm.js +0 -1
  135. package/frontend/dist/js/ArtifactSlideOutPanel-cVd9X80o.js +0 -1
  136. package/frontend/dist/js/AutomationModal-B4UaWjkk.js +0 -1
  137. package/frontend/dist/js/AutomationsPage-huCrvLUp.js +0 -1
  138. package/frontend/dist/js/AvatarUpload-CG-w6Mpt.js +0 -1
  139. package/frontend/dist/js/Button-j68Q8KVh.js +0 -1
  140. package/frontend/dist/js/CalendarPage-CZXT1w99.js +0 -1
  141. package/frontend/dist/js/ChannelsPage-DbtdHnSL.js +0 -1
  142. package/frontend/dist/js/ChatPage-BZE65kiq.js +0 -14
  143. package/frontend/dist/js/ConnectModels-DD4bLgdq.js +0 -1
  144. package/frontend/dist/js/EvaluationsPage-Dq53LaXd.js +0 -2
  145. package/frontend/dist/js/FirstTimeSetup-BoJIfuQT.js +0 -1
  146. package/frontend/dist/js/GalleryPage-DKwqeB2A.js +0 -1
  147. package/frontend/dist/js/HomePage-C8bCJfls.js +0 -1
  148. package/frontend/dist/js/LanguageSwitcher-B_YyU5JG.js +0 -1
  149. package/frontend/dist/js/ModelManagerModals-BzjZ-QwL.js +0 -1
  150. package/frontend/dist/js/NotesPage-CnaAp_w_.js +0 -3
  151. package/frontend/dist/js/PasswordStrengthMeter-DI4RDv67.js +0 -1
  152. package/frontend/dist/js/PersonasPage-CH3GUKph.js +0 -13
  153. package/frontend/dist/js/PluginUsagePage-d54K2gAj.js +0 -1
  154. package/frontend/dist/js/RichMessageContent-CDxxs3Tt.js +0 -1
  155. package/frontend/dist/js/SettingsModal-BvtJcvow.js +0 -19
  156. package/frontend/dist/js/SettingsToggle-DrJ0Bapi.js +0 -1
  157. package/frontend/dist/js/ShareDialog-DaSxkTKS.js +0 -1
  158. package/frontend/dist/js/StrandsPage-BQwz0mWq.js +0 -1
  159. package/frontend/dist/js/SystemPage-BqNZoFxR.js +0 -1
  160. package/frontend/dist/js/UserManagementPanel-C3T1ReJJ.js +0 -1
  161. package/frontend/dist/js/WhatsNewModal-CLcU2Ugk.js +0 -1
  162. package/frontend/dist/js/WorkPage-BpjGn--1.js +0 -8
  163. package/frontend/dist/js/api-K_hhqPdx.js +0 -1
  164. package/frontend/dist/js/appStore-DkRdQQeY.js +0 -2
  165. package/frontend/dist/js/appVersion-BVtSqLVj.js +0 -1
  166. package/frontend/dist/js/ar-XTZGEtBr.js +0 -2
  167. package/frontend/dist/js/authStore-DBS6Kbvh.js +0 -1
  168. package/frontend/dist/js/bn-JiK7ZWmy.js +0 -2
  169. package/frontend/dist/js/chatStore-DpVxt9VX.js +0 -3
  170. package/frontend/dist/js/cs-D8ju18CO.js +0 -2
  171. package/frontend/dist/js/da-BJWcAoUc.js +0 -2
  172. package/frontend/dist/js/de-CLJLmy69.js +0 -2
  173. package/frontend/dist/js/es-BvqHEL-3.js +0 -2
  174. package/frontend/dist/js/fr-B8ZoZomI.js +0 -2
  175. package/frontend/dist/js/goober.modern-BaHbaW3_.js +0 -1
  176. package/frontend/dist/js/hi-AzJLALo-.js +0 -2
  177. package/frontend/dist/js/id-DZYGQhvC.js +0 -2
  178. package/frontend/dist/js/is-Da_kvtzW.js +0 -2
  179. package/frontend/dist/js/it-B90zSlqn.js +0 -2
  180. package/frontend/dist/js/ja-DU_K1GOr.js +0 -2
  181. package/frontend/dist/js/ko-DicfoO-e.js +0 -2
  182. package/frontend/dist/js/messageCodeStyles-CuQPkfEK.js +0 -2
  183. package/frontend/dist/js/ms-CfH7wjUY.js +0 -2
  184. package/frontend/dist/js/nl-ELlOz-B3.js +0 -2
  185. package/frontend/dist/js/pl-33dayyUk.js +0 -2
  186. package/frontend/dist/js/pt-aIXSQPCT.js +0 -2
  187. package/frontend/dist/js/ru-BSvGtBtW.js +0 -2
  188. package/frontend/dist/js/sv-B7KOz81W.js +0 -2
  189. package/frontend/dist/js/th-DgpjGxvA.js +0 -2
  190. package/frontend/dist/js/tr-BQTbl2h-.js +0 -2
  191. package/frontend/dist/js/ui-Aq8MP7Ph.js +0 -2
  192. package/frontend/dist/js/ui-vendor-DVTj_sKN.js +0 -1
  193. package/frontend/dist/js/uk-JLymloot.js +0 -2
  194. package/frontend/dist/js/useChat-D3ZAGz70.js +0 -10
  195. package/frontend/dist/js/useDictation-B6l8QzeM.js +0 -1
  196. package/frontend/dist/js/vi-BXdLOJ8q.js +0 -2
  197. package/frontend/dist/js/workApi-D1xtiG3Q.js +0 -1
  198. package/frontend/dist/js/zh-gdUf9sXa.js +0 -2
@@ -0,0 +1 @@
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{C as i,a,n as o,o as s,r as c,t as l}from"./useQuery-BTKpXudI.js";import{t as u}from"./logger-BR4forr_.js";import{t as d}from"./useTranslation-Boi0fB1B.js";import{t as f}from"./utils-B-Bhh1pF.js";import{t as p}from"./appStore-0_qlwS8f.js";import{An as m,Bn as h,Dr as g,Jt as _,M as v,Mn as y,Mt as b,On as ee,Rt as x,Yt as S,gn as C,i as w,n as T,o as E,v as D}from"./ui-vendor-6S05F84J.js";import{t as O}from"./Button-Dh2UJA-B.js";import{t as k}from"./useDialogFocus-zSGHkpE4.js";import{n as A,o as j,r as M,s as N,t as P}from"./ui-CI0OdG9q.js";import{t as F}from"./confirmStore-CKkUtP9c.js";import{b as I,x as L}from"./api-Dcz1G4Ib.js";import{i as te,n as ne,r as re,s as R}from"./imageGenModels-Dx_QMLJQ.js";var z=class extends c{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){e._type=`infinite`,super.setOptions(e)}getOptimisticResult(e){return e._type=`infinite`,super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`forward`}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`backward`}}})}createResult(e,t){let{state:n}=e,r=super.createResult(e,t),{isFetching:i,isRefetching:o,isError:c,isRefetchError:l}=r,u=n.fetchMeta?.fetchMore?.direction,d=c&&u===`forward`,f=i&&u===`forward`,p=c&&u===`backward`,m=i&&u===`backward`;return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:a(t,n.data),hasPreviousPage:s(t,n.data),isFetchNextPageError:d,isFetchingNextPage:f,isFetchPreviousPageError:p,isFetchingPreviousPage:m,isRefetchError:l&&!d&&!p,isRefetching:o&&!f&&!m}}};function B(e,t){return o(e,z,t)}var V=e(t(),1),ie=n(),H=r(),ae=u(`components:image-generation-panel`);function oe(e,t={}){let n=e.config?.sizes&&e.config.sizes.length>0?e.config.sizes:[t.size||e.config?.default_size||`1024x1024`],r=e.config?.qualities&&e.config.qualities.length>0?e.config.qualities:e.config?.omit_quality_when_empty?[]:[t.quality||e.config?.default_quality||`standard`],i=e.config?.styles&&e.config.styles.length>0?e.config.styles:[];return{pluginId:e.id,model:R(e.models,t.model,void 0,``),size:R(n,t.size,e.config?.default_size,`1024x1024`),quality:r.length>0?R(r,t.quality,e.config?.default_quality,`standard`):``,style:i.length>0?R(i,t.style,e.config?.default_style,i[0]):``,sizes:n,qualities:r,styles:i,maxPromptLength:e.config?.max_prompt_length??null,sizeLabel:e.config?.size_label||``}}var U=({isOpen:e,onClose:t,onImageGenerated:n})=>{let{t:r}=d(),i=p(e=>e.preferences.imageGenSettings),a=i?.enabled===!0,[o,s]=(0,V.useState)([]),[c,l]=(0,V.useState)(``),[u,h]=(0,V.useState)(``),[y,b]=(0,V.useState)(``),[ee,x]=(0,V.useState)(`1024x1024`),[S,C]=(0,V.useState)(`standard`),[w,E]=(0,V.useState)(``),[D,k]=(0,V.useState)(!1),[A,j]=(0,V.useState)(null),M=(0,V.useRef)(null),[N,P]=(0,V.useState)([`512x512`,`768x768`,`1024x1024`]),[F,I]=(0,V.useState)([`standard`,`high`]),[R,z]=(0,V.useState)([]),[B,U]=(0,V.useState)(null),[se,ce]=(0,V.useState)(``),W=V.useId(),G=(0,V.useCallback)((e,t)=>{let n=oe(e,t);l(n.pluginId),h(n.model),x(n.size),C(n.quality),E(n.style),P(n.sizes),I(n.qualities),z(n.styles),U(n.maxPromptLength),ce(n.sizeLabel)},[]);(0,V.useEffect)(()=>{let t=!1;return e&&a&&(async()=>{try{let e=await L.getPlugins();if(t)return;let n=e.success&&e.data?e.data.filter(e=>e.models.length>0):[];s(n);let r=ne(n,i);r?G(r,i):(l(``),h(``))}catch(e){if(t)return;s([]),l(``),h(``),ae.error(`Failed to load image generation plugins:`,e)}})(),()=>{t=!0}},[G,a,e,i]),(0,V.useEffect)(()=>{if(!e)return;let n=document.body.style.overflow,r=e=>{e.key===`Escape`&&t()};return document.body.style.overflow=`hidden`,document.addEventListener(`keydown`,r),()=>{document.body.style.overflow=n,document.removeEventListener(`keydown`,r)}},[e,t]),(0,V.useEffect)(()=>()=>{M.current?.abort(),M.current=null},[]),(0,V.useEffect)(()=>{e||M.current?.abort()},[e]);let le=()=>{M.current?.abort(),t()},ue=e=>{let t=o.find(t=>t.id===e);t&&G(t,{model:u,size:ee,quality:S,style:w})},de=async()=>{if(!a||!c||!u||!y.trim()){g.error(r(`imageGeneration.enterPrompt`));return}if(B&&y.length>B){g.error(r(`imageGeneration.promptTooLong`,{max:B.toLocaleString()}));return}let e=new AbortController;M.current?.abort(),M.current=e,k(!0),j(null);try{let i=await L.generate({model:u,pluginId:c,prompt:y.trim(),size:ee,quality:S,...w?{style:w}:{}},e.signal);if(e.signal.aborted)return;if(i.success&&i.data?.images&&i.data.images.length>0){let e=te(i.data.images[0]);e&&(g.success(r(`imageGeneration.success`)),n?(n(e,y.trim(),u),b(``),j(null),t()):j(e))}else g.error(r(`imageGeneration.failed`))}catch(t){if(e.signal.aborted)return;ae.error(`Image generation failed:`,t);let n=t instanceof Error?t.message:r(`imageGeneration.failed`);g.error(n)}finally{M.current===e&&(M.current=null,k(!1))}},K=()=>{M.current?.abort()},fe=()=>{if(!A)return;let e=document.createElement(`a`);e.href=A,e.download=`generated-image-${Date.now()}.${re(A)}`,document.body.appendChild(e),e.click(),document.body.removeChild(e)};if(!e||!a)return null;let q=o.find(e=>e.id===c);return(0,ie.createPortal)((0,H.jsxs)(`div`,{className:`fixed inset-0 z-99999 flex items-center justify-center p-3 sm:p-6`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":W,children:[(0,H.jsx)(`div`,{className:`absolute inset-0 bg-black/55 backdrop-blur-sm`,onClick:le}),(0,H.jsxs)(`div`,{className:f(`relative bg-white/95 dark:bg-dark-25/95`,`border border-gray-200/80 dark:border-white/10`,`rounded-3xl shadow-2xl backdrop-blur-xl`,`flex max-h-[92vh] w-full max-w-2xl flex-col overflow-hidden`),onClick:e=>e.stopPropagation(),children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200/70 px-5 py-4 dark:border-white/8 sm:px-6 sm:py-5`,children:[(0,H.jsx)(`div`,{children:(0,H.jsx)(`h2`,{id:W,className:`text-xl font-normal tracking-tight text-gray-950 dark:text-dark-950`,children:r(`imageGeneration.title`)})}),(0,H.jsx)(`button`,{onClick:le,className:`rounded-xl p-2 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 dark:text-dark-500 dark:hover:bg-white/6 dark:hover:text-dark-900`,title:r(`common.close`,{defaultValue:`Close`}),children:(0,H.jsx)(T,{className:`h-5 w-5 text-gray-500 dark:text-gray-400`})})]}),(0,H.jsx)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-5 p-5 scrollbar-thin sm:p-6`,children:q?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`settings.plugins.title`)}),(0,H.jsx)(`select`,{value:c,onChange:e=>ue(e.target.value),className:f(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-hidden focus:ring-2 focus:ring-primary-500/20`),children:o.map(e=>(0,H.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.model`)}),(0,H.jsx)(`select`,{value:u,onChange:e=>h(e.target.value),className:f(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-hidden focus:ring-2 focus:ring-primary-500/20`),children:q?.models.map(e=>(0,H.jsx)(`option`,{value:e,children:e},e))})]}),R.length>0&&(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.style`)}),(0,H.jsx)(`select`,{value:w,onChange:e=>E(e.target.value),className:f(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-hidden focus:ring-2 focus:ring-primary-500/20`),children:R.map(e=>(0,H.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),(0,H.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:se||r(`imageGeneration.size`)}),(0,H.jsx)(`select`,{value:ee,onChange:e=>x(e.target.value),className:f(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-hidden focus:ring-2 focus:ring-primary-500/20`),children:N.map(e=>(0,H.jsx)(`option`,{value:e,children:e},e))})]}),F.length>0&&(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.quality`)}),(0,H.jsx)(`select`,{value:S,onChange:e=>C(e.target.value),className:f(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-hidden focus:ring-2 focus:ring-primary-500/20`),children:F.map(e=>(0,H.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.prompt`)}),(0,H.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),placeholder:r(`imageGeneration.promptPlaceholder`),rows:5,className:f(`w-full resize-none rounded-2xl px-4 py-3 text-sm leading-6`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`placeholder-gray-500 dark:placeholder-gray-400`,`focus:outline-hidden focus:ring-2 focus:ring-primary-500/20`,B&&y.length>B&&`border-red-500 dark:border-red-500`)}),B&&(0,H.jsxs)(`div`,{className:f(`mt-1 text-end text-xs`,y.length>B?`text-red-500`:`text-gray-500 dark:text-gray-400`),children:[y.length.toLocaleString(),` /`,` `,B.toLocaleString()]})]}),A&&(0,H.jsxs)(`div`,{className:`relative overflow-hidden rounded-2xl border border-gray-200/80 dark:border-white/10`,children:[(0,H.jsx)(`img`,{src:A,alt:`Generated`,className:`w-full h-auto`}),(0,H.jsx)(`button`,{onClick:fe,className:f(`absolute bottom-3 inset-e-3 rounded-lg p-2`,`bg-white/90 dark:bg-dark-100/90`,`hover:bg-white dark:hover:bg-dark-100`,`border border-gray-200 dark:border-dark-300`,`transition-colors`),title:r(`imageGallery.download`),children:(0,H.jsx)(m,{className:`h-5 w-5 text-gray-700 dark:text-gray-200`})})]})]}):(0,H.jsxs)(`div`,{className:`text-center py-8`,children:[(0,H.jsx)(_,{className:`h-12 w-12 mx-auto mb-3 text-gray-300 dark:text-gray-600`}),(0,H.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:r(`imageGeneration.noModels`)}),(0,H.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-gray-500 mt-1`,children:r(`imageGeneration.configurePlugin`)})]})}),q&&(0,H.jsx)(`div`,{className:`border-t border-gray-200/70 p-4 dark:border-white/8 sm:px-6 sm:py-5`,children:(0,H.jsx)(O,{onClick:D?K:de,disabled:!D&&(!a||!y.trim()||!c||!u),className:f(`w-full py-2.5 rounded-xl font-medium`,`bg-primary-600 dark:bg-primary-600`,`hover:bg-primary-700 dark:hover:bg-primary-500`,`text-white`,`disabled:opacity-50 disabled:cursor-not-allowed`,`transition-colors`),children:D?(0,H.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,H.jsx)(T,{className:`h-4 w-4`}),r(`common.cancel`)]}):(0,H.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,H.jsx)(v,{className:`h-4 w-4`}),r(`imageGeneration.generate`)]})})})]})]}),document.body)},se={video:[],audio:[]};function ce({isOpen:e,initialKind:t,onClose:n,onGenerated:r}){let{t:a}=d(),o=i(),[s,c]=(0,V.useState)(t),[l,u]=(0,V.useState)(se),[p,m]=(0,V.useState)(``),[h,_]=(0,V.useState)(``),[y,b]=(0,V.useState)(``),[ee,S]=(0,V.useState)(!1),[w,D]=(0,V.useState)(null),[k,A]=(0,V.useState)(``),[j,M]=(0,V.useState)(!1),[N,P]=(0,V.useState)(``),[F,L]=(0,V.useState)(!1),[te,ne]=(0,V.useState)(null),[re,R]=(0,V.useState)(0),[z,B]=(0,V.useState)(``),[ae,oe]=(0,V.useState)(``),[U,ce]=(0,V.useState)(``),[fe,q]=(0,V.useState)(!0),[pe,me]=(0,V.useState)(!0),[J,he]=(0,V.useState)(!1),[ge,_e]=(0,V.useState)([]),Y=(0,V.useRef)(null),ve=V.useId(),ye=()=>{S(!1),D(null),A(``),M(!1),P(``),L(!1),R(e=>e+1)},be=()=>{Y.current?.abort(),ye(),n()};(0,V.useEffect)(()=>()=>{Y.current?.abort(),Y.current=null},[]),(0,V.useEffect)(()=>{e||Y.current?.abort()},[e]),(0,V.useEffect)(()=>{if(!e)return;let t=!1;return I.getModels().then(e=>{!t&&e.success&&e.data&&u(e.data)}).catch(()=>{t||g.error(a(`mediaGeneration.loadFailed`))}).finally(()=>{t||me(!1)}),()=>{t=!0}},[e,a]),(0,V.useEffect)(()=>{if(!e)return;let t=!1;return I.listVideoJobs({limit:100,active:!0}).then(e=>{!t&&e.success&&e.data&&_e(e.data.jobs)}).catch(()=>{t||g.error(a(`mediaGeneration.jobsLoadFailed`,{defaultValue:`Failed to load saved video jobs`}))}),()=>{t=!0}},[e,a]);let X=s===`video`?l.video:l.audio,xe=ge.filter(e=>e.status!==`completed`),Se=X.some(e=>G(e)===p)?p:X[0]?G(X[0]):``,Z=(0,V.useMemo)(()=>X.find(e=>G(e)===Se),[Se,X]),Ce=s===`video`?Z?.config:void 0,Q=s===`audio`?Z:void 0,we=!!(Q?.mode===`speech`&&Q.config?.supports_voice_cloning),Te=!!Q?.config?.clone_requires_transcript,$=we&&ee,Ee=!!(Q?.mode!==`speech`||Q.config?.allows_custom_voice!==!1||Q.config?.voices?.length),De=Q?.mode===`speech`?Q.config?.max_characters:void 0,Oe=async(e,t,n,r=0)=>{if(e.status!==`pending`&&e.status!==`in_progress`)return e;n&&await le(3e4,t.signal);try{let n=await I.resumeVideoJob(e.id,t.signal);if(!n.success||!n.data)throw Error(n.message||a(`mediaGeneration.failed`));let r=n.data;return _e(e=>[r,...e.filter(e=>e.id!==r.id)]),Oe(r,t,!0)}catch(n){if(t.signal.aborted||r>=4)throw n;return Oe(e,t,!0,r+1)}},ke=async e=>{let t=new AbortController;Y.current?.abort(),Y.current=t,he(!0);try{let n=await Oe(e,t,!1);if(t.signal.aborted)return;if(n.status===`failed`)throw Error(n.error||a(`mediaGeneration.failed`));g.success(a(`mediaGeneration.success`)),r()}catch(e){if(t.signal.aborted)return;g.error(e instanceof Error?e.message:a(`mediaGeneration.failed`))}finally{Y.current===t&&(Y.current=null,he(!1))}},Ae=async e=>{try{let t=await I.cancelVideoJob(e.id);if(!t.success)throw Error(t.message||a(`mediaGeneration.failed`));_e(t=>t.filter(t=>t.id!==e.id)),g.success(a(`mediaGeneration.jobCancelled`,{defaultValue:`Video job cancelled at the provider`}))}catch(e){g.error(e instanceof Error?e.message:a(`mediaGeneration.failed`))}};return e?(0,ie.createPortal)((0,H.jsxs)(`div`,{className:`fixed inset-0 z-99999 flex items-center justify-center p-3 sm:p-6`,children:[(0,H.jsx)(`button`,{className:`absolute inset-0 bg-black/55 backdrop-blur-sm`,onClick:be,"aria-label":a(`common.close`)}),(0,H.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":ve,className:`relative flex max-h-[92vh] w-full max-w-2xl flex-col overflow-hidden rounded-2xl border border-gray-200/80 bg-white/95 shadow-2xl backdrop-blur-xl dark:border-white/10 dark:bg-dark-25/95`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200/70 px-4 py-3 dark:border-white/8 sm:px-5`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h2`,{id:ve,className:`text-xl text-gray-950 dark:text-dark-950`,children:a(`mediaGeneration.title`)}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-gray-500 dark:text-dark-500`,children:a(`mediaGeneration.description`)})]}),(0,H.jsx)(`button`,{onClick:be,className:`rounded-xl p-2`,children:(0,H.jsx)(T,{className:`h-5 w-5`})})]}),(0,H.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-4 p-4 sm:p-5`,children:[(0,H.jsx)(`div`,{className:`grid grid-cols-2 gap-2 rounded-xl bg-gray-100 p-1 dark:bg-white/5`,children:[`video`,`audio`].map(e=>(0,H.jsxs)(`button`,{type:`button`,disabled:J,onClick:()=>{c(e),m(``),b(``),ye()},className:f(`flex items-center justify-center gap-2 rounded-xl px-3 py-2 text-sm transition-colors`,e===s?`bg-white text-gray-950 shadow-xs dark:bg-white/10 dark:text-white`:`text-gray-500 dark:text-dark-500`,J&&`cursor-not-allowed opacity-50`),children:[e===`video`?(0,H.jsx)(C,{className:`h-4 w-4`}):(0,H.jsx)(E,{className:`h-4 w-4`}),a(`mediaGeneration.${e}`)]},e))}),s===`video`&&xe.length>0&&(0,H.jsxs)(`section`,{className:`space-y-2 rounded-xl border border-gray-200/80 bg-gray-50/80 p-3 dark:border-white/10 dark:bg-white/2.5`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:a(`mediaGeneration.savedJobs`,{defaultValue:`Saved video jobs`})}),(0,H.jsx)(`p`,{className:`mt-0.5 text-xs text-gray-500 dark:text-dark-500`,children:a(`mediaGeneration.savedJobsDescription`,{defaultValue:`Closing this panel only stops waiting. Reopen it to resume any provider job listed here.`})})]}),xe.map(e=>(0,H.jsxs)(`div`,{"data-testid":`video-job-${e.id}`,className:`flex items-center gap-3 rounded-lg border border-gray-200/70 bg-white/80 p-2.5 dark:border-white/10 dark:bg-dark-50/70`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(`p`,{className:`truncate text-sm text-gray-900 dark:text-gray-100`,children:e.prompt||e.model}),(0,H.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:[e.model,` ·`,` `,a(`mediaGeneration.jobStatus.${e.status}`,{defaultValue:e.status.replace(`_`,` `)})]}),e.error&&(0,H.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-300`,children:e.error})]}),(e.status===`pending`||e.status===`in_progress`)&&(0,H.jsx)(O,{type:`button`,variant:`outline`,size:`sm`,disabled:J,onClick:()=>void ke(e),children:a(`mediaGeneration.resumeJob`,{defaultValue:`Resume`})}),e.cancellable&&(0,H.jsx)(O,{type:`button`,variant:`outline`,size:`sm`,disabled:J,onClick:()=>void Ae(e),children:a(`mediaGeneration.cancelJob`,{defaultValue:`Cancel job`})})]},e.id))]}),pe?(0,H.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,H.jsx)(x,{className:`h-7 w-7 animate-spin`})}):X.length===0?(0,H.jsx)(`div`,{className:`rounded-xl border border-amber-500/25 bg-amber-500/10 p-4 text-sm text-amber-800 dark:text-amber-200`,children:a(`mediaGeneration.noModels`,{kind:a(`mediaGeneration.${s}`)})}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(W,{label:a(`mediaGeneration.model`),children:(0,H.jsx)(`select`,{value:Se,onChange:e=>{m(e.target.value),b(``),ye(),B(``),oe(``),ce(``),q(!0)},className:K,children:X.map(e=>(0,H.jsxs)(`option`,{value:G(e),children:[e.model,` (`,e.plugin,`mode`in e?` · ${a(`mediaGeneration.${e.mode}`)}`:``,`)`]},G(e)))})}),s===`audio`&&!$&&Ee?(0,H.jsx)(W,{label:a(`mediaGeneration.voice`),children:(0,H.jsx)(`input`,{value:y,onChange:e=>b(e.target.value),className:K,placeholder:Q?.config?.default_voice||a(`mediaGeneration.providerDefault`)})}):s===`video`?(0,H.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-3`,children:[(0,H.jsx)(W,{label:a(`mediaGeneration.resolution`),children:(0,H.jsxs)(`select`,{value:z,onChange:e=>B(e.target.value),className:K,children:[(0,H.jsx)(`option`,{value:``,children:a(`mediaGeneration.providerDefault`)}),Ce?.resolutions?.map(e=>(0,H.jsx)(`option`,{value:e,children:e},e))]})}),(0,H.jsx)(W,{label:a(`mediaGeneration.aspectRatio`),children:(0,H.jsxs)(`select`,{value:ae,onChange:e=>oe(e.target.value),className:K,children:[(0,H.jsx)(`option`,{value:``,children:a(`mediaGeneration.providerDefault`)}),Ce?.aspect_ratios?.map(e=>(0,H.jsx)(`option`,{value:e,children:e},e))]})}),(0,H.jsx)(W,{label:a(`mediaGeneration.duration`),children:(0,H.jsxs)(`select`,{value:U,onChange:e=>ce(e.target.value),className:K,children:[(0,H.jsx)(`option`,{value:``,children:a(`mediaGeneration.providerDefault`)}),Ce?.durations?.map(e=>(0,H.jsxs)(`option`,{value:e,children:[e,`s`]},e))]})})]}):null,we&&(0,H.jsxs)(`div`,{className:`space-y-3 rounded-xl border border-primary-500/20 bg-primary-500/6 p-4`,children:[(0,H.jsxs)(`label`,{className:`flex items-start gap-3 text-sm`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:$,onChange:e=>{e.target.checked?S(!0):ye()},className:`mt-0.5`}),(0,H.jsxs)(`span`,{children:[(0,H.jsx)(`span`,{className:`block font-medium text-gray-900 dark:text-gray-100`,children:a(`mediaGeneration.cloneVoice`)}),(0,H.jsx)(`span`,{className:`mt-0.5 block text-xs font-normal text-gray-500 dark:text-dark-500`,children:a(`mediaGeneration.cloneVoiceDescription`)})]})]}),$&&(0,H.jsxs)(`div`,{className:`space-y-3 border-t border-primary-500/15 pt-3`,children:[(0,H.jsx)(W,{label:a(`mediaGeneration.referenceAudio`),children:(0,H.jsx)(`input`,{type:`file`,accept:Q?.config?.clone_audio_mime_types?.join(`,`)||`audio/wav,audio/mpeg,audio/flac,audio/ogg`,onChange:e=>{let t=e.target.files?.[0]||null,n=Q?.config?.clone_max_audio_bytes;if(t&&n&&t.size>n){g.error(a(`mediaGeneration.referenceAudioTooLarge`,{max:de(n)})),e.target.value=``,D(null);return}D(t)},className:f(K,`file:me-3 file:rounded-lg file:border-0 file:bg-primary-500/10 file:px-3 file:py-1 file:text-primary-700 dark:file:text-primary-300`)},re)}),(0,H.jsx)(W,{label:a(`mediaGeneration.referenceTranscript`),children:(0,H.jsx)(`textarea`,{value:k,onChange:e=>A(e.target.value),rows:3,required:Te,className:f(K,`resize-none`),placeholder:a(`mediaGeneration.referenceTranscriptPlaceholder`)})}),(0,H.jsxs)(`label`,{className:`flex items-start gap-3 text-sm`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:j,onChange:e=>{M(e.target.checked),e.target.checked||(P(``),L(!1))},className:`mt-0.5`}),(0,H.jsxs)(`span`,{children:[(0,H.jsx)(`span`,{className:`block font-medium text-gray-900 dark:text-gray-100`,children:a(`mediaGeneration.saveVoiceProfile`,{defaultValue:`Save as a reusable voice`})}),(0,H.jsx)(`span`,{className:`mt-0.5 block text-xs font-normal text-gray-500 dark:text-dark-500`,children:a(`mediaGeneration.saveVoiceProfileDescription`,{defaultValue:`Store this reference recording and transcript securely. Libre WebUI sends them to the selected provider for every Speech batch that uses this voice.`})})]})]}),j&&(0,H.jsxs)(`div`,{className:`space-y-3 rounded-lg border border-primary-500/15 bg-white/60 p-3 dark:bg-dark-100/50`,children:[(0,H.jsx)(W,{label:a(`mediaGeneration.voiceProfileName`,{defaultValue:`Saved voice name`}),children:(0,H.jsx)(`input`,{type:`text`,value:N,onChange:e=>P(e.target.value),maxLength:80,autoComplete:`off`,className:K,placeholder:a(`mediaGeneration.voiceProfileNamePlaceholder`,{defaultValue:`For example, My voice`})})}),(0,H.jsxs)(`label`,{className:`flex items-start gap-3 text-xs text-amber-700 dark:text-amber-300`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:F,onChange:e=>L(e.target.checked),className:`mt-0.5`}),(0,H.jsx)(`span`,{children:a(`mediaGeneration.voiceStorageConsent`,{defaultValue:`I confirm that I have the speaker’s permission to clone and store this voice. The reference stays saved until I delete it.`})})]}),(0,H.jsx)(W,{label:a(`mediaGeneration.consentTtl.label`,{defaultValue:`Consent duration`}),children:(0,H.jsxs)(`select`,{value:te??``,onChange:e=>ne(e.target.value===``?null:Number(e.target.value)),className:K,children:[(0,H.jsx)(`option`,{value:``,children:a(`mediaGeneration.consentTtl.never`,{defaultValue:`Until I withdraw it`})}),(0,H.jsx)(`option`,{value:`30`,children:a(`mediaGeneration.consentTtl.days30`,{defaultValue:`30 days`})}),(0,H.jsx)(`option`,{value:`90`,children:a(`mediaGeneration.consentTtl.days90`,{defaultValue:`90 days`})}),(0,H.jsx)(`option`,{value:`365`,children:a(`mediaGeneration.consentTtl.days365`,{defaultValue:`One year`})})]})})]}),!j&&(0,H.jsx)(`p`,{className:`text-xs font-normal text-amber-700 dark:text-amber-300`,children:a(`mediaGeneration.cloneConsent`)})]})]}),s===`video`&&Ce?.supports_audio&&(0,H.jsxs)(`label`,{className:`flex items-center gap-3 text-sm`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:fe,onChange:e=>q(e.target.checked)}),a(`mediaGeneration.generateAudio`)]}),(0,H.jsxs)(W,{label:s===`video`||Q?.mode===`sound`?a(`mediaGeneration.prompt`):a(`mediaGeneration.text`),children:[(0,H.jsx)(`textarea`,{value:h,onChange:e=>_(e.target.value),rows:6,maxLength:De,className:f(K,`resize-none`),placeholder:a(s===`audio`&&Q?.mode===`sound`?`mediaGeneration.soundPlaceholder`:`mediaGeneration.${s}Placeholder`)}),De&&(0,H.jsxs)(`span`,{className:`block text-end text-xs font-normal text-gray-500 dark:text-dark-500`,children:[h.length,` / `,De]})]})]})]}),X.length>0&&(0,H.jsx)(`div`,{className:`border-t border-gray-200/70 p-4 dark:border-white/8 sm:px-5`,children:(0,H.jsxs)(O,{onClick:J?()=>{Y.current?.abort()}:async()=>{if(!Z||!h.trim())return;let e=new AbortController;Y.current?.abort(),Y.current=e,he(!0);try{if(s===`audio`){let t=ue(Q?.config?.default_format),n=$?await I.cloneVoice({model:Z.model,pluginId:Z.plugin,input:h.trim(),referenceAudio:w,referenceText:k.trim()||void 0,responseFormat:t,saveVoiceName:j?N.trim():void 0,consentToStore:j&&F,consentTtlDays:j&&te!==null?te:void 0},e.signal):Q?.mode===`sound`?await I.generateSound({model:Z.model,pluginId:Z.plugin,prompt:h.trim(),voice:y.trim()||Q?.config?.default_voice||void 0,format:`wav`},e.signal):await I.generateAudio({model:Z.model,pluginId:Z.plugin,input:h.trim(),voice:y.trim()||Q?.config?.default_voice||void 0,response_format:t},e.signal);if(e.signal.aborted)return;if(!n.success)throw Error(n.message);if($&&j&&(await o.invalidateQueries({queryKey:[`tts-voice-profiles`]}),e.signal.aborted))return}else{let t=await I.generateVideo({model:Z.model,pluginId:Z.plugin,prompt:h.trim(),...U?{duration:Number(U)}:{},...z?{resolution:z}:{},...ae?{aspect_ratio:ae}:{},...Ce?.supports_audio?{generate_audio:fe}:{}},e.signal);if(e.signal.aborted)return;if(!t.success||!t.data)throw Error(t.message||a(`mediaGeneration.failed`));let n=t.data;_e(e=>[n,...e.filter(e=>e.id!==n.id)]);let r=await Oe(n,e,!0);if(r.status===`failed`)throw Error(r.error||a(`mediaGeneration.failed`))}if(e.signal.aborted)return;g.success($&&j?a(`mediaGeneration.successWithSavedVoice`,{name:N.trim(),defaultValue:`Media generated and “{{name}}” is now available in Speech settings`}):a(`mediaGeneration.success`)),_(``),ye(),r(),n()}catch(t){if(e.signal.aborted)return;g.error(t instanceof Error?t.message:a(`mediaGeneration.failed`))}finally{Y.current===e&&(Y.current=null,he(!1))}},disabled:J?!1:!Z||!h.trim()||!!(De&&h.length>De)||$&&(!w||Te&&!k.trim()||j&&(!N.trim()||!F)),className:`w-full gap-2`,children:[J?(0,H.jsx)(T,{className:`h-4 w-4`}):(0,H.jsx)(v,{className:`h-4 w-4`}),J?s===`video`?a(`mediaGeneration.stopWaiting`,{defaultValue:`Stop waiting`}):a(`common.cancel`):a(`mediaGeneration.generate`)]})})]})]}),document.body):null}function W({label:e,children:t}){return(0,H.jsxs)(`label`,{className:`block space-y-1.5 text-sm font-medium text-gray-700 dark:text-gray-300`,children:[(0,H.jsx)(`span`,{children:e}),t]})}function G(e){return`${e.mode||`default`}::${e.plugin}::${e.model}`}function le(e,t){return t?.aborted?Promise.reject(t.reason):new Promise((n,r)=>{let i=window.setTimeout(()=>{t?.removeEventListener(`abort`,a),n()},e),a=()=>{window.clearTimeout(i),r(t?.reason)};t?.addEventListener(`abort`,a,{once:!0})})}function ue(e){return[`mp3`,`opus`,`aac`,`flac`,`wav`,`pcm`].includes(e||``)?e:`mp3`}function de(e){return e>=1048576?`${Math.ceil(e/1048576)} MB`:`${Math.ceil(e/1024)} KB`}var K=`w-full rounded-xl border border-gray-200/80 bg-white/70 px-3 py-2.5 text-sm text-gray-900 focus:outline-hidden focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.035] dark:text-gray-100`,fe=u(`components:image-edit-panel`),q=e=>e.filter(e=>!!e.config?.edit_endpoint),pe=({isOpen:e,onClose:t,source:n,onEdited:r})=>{let{t:i}=d(),[a,o]=(0,V.useState)([]),[s,c]=(0,V.useState)(``),[l,u]=(0,V.useState)(``),[f,p]=(0,V.useState)(36),[m,h]=(0,V.useState)([]),[_,v]=(0,V.useState)(!1),[y,b]=(0,V.useState)(null),[S,C]=(0,V.useState)(!1),E=(0,V.useRef)(null),D=(0,V.useRef)(null),k=(0,V.useRef)(null),A=(0,V.useRef)(!1),j=(0,V.useRef)(null),M=a.find(e=>`${e.plugin}:${e.model}`===s);(0,V.useEffect)(()=>{if(!e)return;let t=!1;return L.getModels().then(e=>{if(t||!e.success||!e.data)return;let n=q(e.data);o(n),c(e=>n.some(t=>`${t.plugin}:${t.model}`===e)?e:n[0]?`${n[0].plugin}:${n[0].model}`:``)}),()=>{t=!0}},[e]),(0,V.useEffect)(()=>{if(!e||!n)return;let t=null,r=!1;return I.getGalleryContent(n.id).then(e=>{r||(t=URL.createObjectURL(e),b(t))}).catch(e=>{fe.error(`Failed to load the source image:`,e),g.error(i(`imageEdit.loadFailed`))}),()=>{r=!0,t&&URL.revokeObjectURL(t),b(null),C(!1),h([])}},[e,n?.id]),(0,V.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]);let N=()=>{let e=k.current,t=E.current,n=D.current;if(!e||!t||!n)return;let r=e.getContext(`2d`);r&&(r.clearRect(0,0,e.width,e.height),r.drawImage(t,0,0,e.width,e.height),r.save(),r.globalAlpha=.55,r.drawImage(n,0,0,e.width,e.height),r.restore())},P=()=>{let e=E.current,t=k.current;if(!e||!t)return;let n=e.naturalWidth,r=e.naturalHeight;t.width=n,t.height=r;let i=document.createElement(`canvas`);i.width=n,i.height=r,D.current=i,C(!1),N()},F=e=>{let t=k.current,n=D.current;if(!t||!n)return;let r=t.getBoundingClientRect(),i=(e.clientX-r.left)/r.width*t.width,a=(e.clientY-r.top)/r.height*t.height,o=n.getContext(`2d`);if(!o)return;let s=f/r.width*t.width;o.fillStyle=`rgba(239, 68, 68, 1)`,o.beginPath(),o.arc(i,a,s,0,Math.PI*2),o.fill(),C(!0),N()},te=()=>{let e=D.current;e&&(e.getContext(`2d`)?.clearRect(0,0,e.width,e.height),C(!1),N())},ne=async()=>{let e=D.current;if(!e||!S)return null;let t=document.createElement(`canvas`);t.width=e.width,t.height=e.height;let n=t.getContext(`2d`);return n?(n.fillStyle=`#000000`,n.fillRect(0,0,t.width,t.height),n.globalCompositeOperation=`destination-out`,n.drawImage(e,0,0),new Promise(e=>t.toBlob(t=>e(t),`image/png`))):null},re=async()=>{if(!n||!M||!l.trim()||_)return;v(!0);let e=new AbortController;j.current=e;try{let a=await ne(),o=await I.editImage({model:M.model,pluginId:M.plugin,prompt:l.trim(),sourceMediaId:n.id,images:m,...a?{mask:a}:{}},e.signal);if(!o.success)throw Error(o.message||o.error||`Edit failed`);g.success(i(`imageEdit.saved`)),r(),t()}catch(t){e.signal.aborted||(fe.error(`Image edit failed:`,t),g.error(t instanceof Error?t.message:i(`imageEdit.failed`)))}finally{v(!1),j.current=null}};if(!e||!n)return null;let R=Math.max(0,(M?.config?.max_reference_images??1)-1);return(0,ie.createPortal)((0,H.jsx)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":i(`imageEdit.title`),className:`fixed inset-0 z-70 flex items-center justify-center bg-black/50 p-4`,"data-testid":`image-edit-panel`,children:(0,H.jsxs)(`div`,{className:`flex max-h-[90vh] w-full max-w-3xl flex-col overflow-hidden rounded-2xl bg-white shadow-xl dark:bg-dark-100`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200 px-4 py-3 dark:border-dark-300`,children:[(0,H.jsxs)(`h2`,{className:`flex items-center gap-2 text-base font-semibold text-gray-900 dark:text-gray-100`,children:[(0,H.jsx)(w,{className:`h-4 w-4`}),i(`imageEdit.title`)]}),(0,H.jsx)(`button`,{type:`button`,onClick:t,"aria-label":i(`common.close`),className:`rounded-full p-1.5 text-gray-500 hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,H.jsx)(T,{className:`h-5 w-5`})})]}),(0,H.jsx)(`div`,{className:`flex-1 space-y-4 overflow-y-auto p-4`,children:a.length===0?(0,H.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:i(`imageEdit.noModels`)}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`div`,{className:`relative`,children:y?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`img`,{ref:E,src:y,alt:n.prompt,className:`hidden`,onLoad:P}),(0,H.jsx)(`canvas`,{ref:k,onPointerDown:e=>{A.current=!0,e.currentTarget.setPointerCapture(e.pointerId),F(e)},onPointerMove:e=>{A.current&&F(e)},onPointerUp:()=>{A.current=!1},className:`w-full cursor-crosshair rounded-xl border border-gray-200 dark:border-dark-300`,"data-testid":`image-edit-canvas`})]}):(0,H.jsx)(`div`,{className:`flex h-56 items-center justify-center`,children:(0,H.jsx)(x,{className:`h-6 w-6 animate-spin text-gray-400`})})}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:i(`imageEdit.maskHint`)}),(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,H.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-gray-600 dark:text-gray-300`,children:[i(`imageEdit.brushSize`),(0,H.jsx)(`input`,{type:`range`,min:8,max:96,value:f,onChange:e=>p(Number(e.target.value))})]}),(0,H.jsxs)(O,{type:`button`,size:`sm`,variant:`outline`,onClick:te,disabled:!S,children:[(0,H.jsx)(ee,{className:`mr-1 h-3.5 w-3.5`}),i(`imageEdit.clearMask`)]})]}),(0,H.jsxs)(`label`,{className:`block text-xs font-medium text-gray-700 dark:text-gray-300`,children:[i(`imageEdit.model`),(0,H.jsx)(`select`,{value:s,onChange:e=>c(e.target.value),className:`mt-1 w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50`,children:a.map(e=>(0,H.jsxs)(`option`,{value:`${e.plugin}:${e.model}`,children:[e.plugin,` · `,e.model]},`${e.plugin}:${e.model}`))})]}),(0,H.jsxs)(`label`,{className:`block text-xs font-medium text-gray-700 dark:text-gray-300`,children:[i(`imageEdit.prompt`),(0,H.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),rows:3,placeholder:i(`imageEdit.promptPlaceholder`),className:`mt-1 w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50`,"data-testid":`image-edit-prompt`})]}),R>0&&(0,H.jsxs)(`label`,{className:`block text-xs font-medium text-gray-700 dark:text-gray-300`,children:[i(`imageEdit.referenceImages`,{total:R}),(0,H.jsx)(`input`,{type:`file`,accept:`image/png,image/jpeg,image/webp`,multiple:!0,onChange:e=>h(Array.from(e.target.files??[]).slice(0,R)),className:`mt-1 block w-full text-xs`})]})]})}),(0,H.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t border-gray-200 px-4 py-3 dark:border-dark-300`,children:[(0,H.jsx)(O,{type:`button`,variant:`outline`,onClick:t,children:i(`common.cancel`)}),(0,H.jsxs)(O,{type:`button`,onClick:()=>void re(),disabled:_||!M||!l.trim()||!y,"data-testid":`image-edit-submit`,children:[_?(0,H.jsx)(x,{className:`mr-1 h-4 w-4 animate-spin`}):(0,H.jsx)(w,{className:`mr-1 h-4 w-4`}),i(`imageEdit.apply`)]})]})]})}),document.body)},me=({image:e,onClose:t,onDelete:n,onDownload:r})=>{let{t:i}=d(),a=(0,V.useRef)(null);k(a,{onClose:t}),(0,V.useEffect)(()=>(document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=``}),[]);let o=async()=>{n&&await F({title:i(`imageGallery.deleteConfirm`),destructive:!0})&&n(e.id)};return(0,ie.createPortal)((0,H.jsxs)(`div`,{className:`fixed inset-0 z-99999 flex items-center justify-center`,onClick:t,children:[(0,H.jsx)(`div`,{className:`absolute inset-0 bg-black/90 backdrop-blur-sm`}),(0,H.jsxs)(`div`,{ref:a,role:`dialog`,"aria-modal":`true`,"aria-label":i(`gallery.lightboxLabel`),className:`relative flex flex-col lg:flex-row max-w-7xl max-h-[95vh] w-full mx-4 gap-4`,onClick:e=>e.stopPropagation(),children:[(0,H.jsx)(`button`,{type:`button`,onClick:t,"aria-label":i(`common.close`),className:f(`absolute -top-12 inset-e-0 lg:top-0 lg:-inset-e-12 z-10`,`p-2 rounded-full`,`bg-white/10 hover:bg-white/20`,`transition-colors`),children:(0,H.jsx)(T,{className:`h-6 w-6 text-white`})}),(0,H.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-0`,children:(0,H.jsx)(`img`,{src:e.imageData,alt:e.prompt,className:`max-w-full max-h-[70vh] lg:max-h-[90vh] object-contain rounded-lg`})}),(0,H.jsxs)(`div`,{className:f(`w-full lg:w-80 shrink-0`,`bg-white dark:bg-dark-100`,`rounded-xl p-4 lg:p-5`,`overflow-y-auto max-h-[25vh] lg:max-h-[90vh]`),children:[(0,H.jsxs)(`div`,{className:`mb-4`,children:[(0,H.jsx)(`h3`,{className:`text-sm font-medium text-gray-500 dark:text-gray-400 mb-1`,children:i(`gallery.prompt`)}),(0,H.jsx)(`p`,{className:`text-gray-900 dark:text-gray-100 text-sm leading-relaxed`,children:e.prompt})]}),(0,H.jsxs)(`div`,{className:`space-y-3 mb-4`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,H.jsx)(y,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,H.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.model`),`:`]}),(0,H.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.model})]}),e.size&&(0,H.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,H.jsx)(b,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,H.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.size`),`:`]}),(0,H.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.size})]}),e.quality&&(0,H.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,H.jsx)(`span`,{className:`w-4 h-4 flex items-center justify-center text-gray-400 dark:text-gray-500 text-xs font-bold`,children:`Q`}),(0,H.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.quality`),`:`]}),(0,H.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100 capitalize`,children:e.quality})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,H.jsx)(h,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,H.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.created`),`:`]}),(0,H.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:(e=>new Date(e).toLocaleString(void 0,{year:`numeric`,month:`long`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}))(e.createdAt)})]})]}),(0,H.jsxs)(`div`,{className:`flex gap-2 pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,H.jsxs)(`button`,{type:`button`,onClick:()=>{if(r)r(e);else{let t=document.createElement(`a`);t.href=e.imageData,t.download=`generated-${e.id}.${re(e.imageData)}`,document.body.appendChild(t),t.click(),document.body.removeChild(t)}},className:f(`flex-1 flex items-center justify-center gap-2 py-2.5 rounded-lg`,`bg-ink text-ink-inverse hover:opacity-90`,`font-medium text-sm`,`transition-opacity`),children:[(0,H.jsx)(m,{className:`h-4 w-4`}),i(`gallery.download`)]}),n&&(0,H.jsx)(`button`,{type:`button`,onClick:()=>void o(),className:f(`p-2.5 rounded-lg`,`bg-gray-100 dark:bg-dark-200`,`hover:bg-red-100 dark:hover:bg-red-900/30`,`text-gray-600 dark:text-gray-300`,`hover:text-red-600 dark:hover:text-red-400`,`transition-colors`),title:i(`imageGallery.delete`),"aria-label":i(`imageGallery.delete`),children:(0,H.jsx)(D,{className:`h-4 w-4`})})]})]})]})]}),document.body)};function J({kind:e,refreshKey:t,onCountChange:n,onEditImage:r}){let{t:a}=d(),o=i(),[s,c]=(0,V.useState)(null),[l,u]=(0,V.useState)(null),f=B({queryKey:[`media-gallery`,e||`all`,t||0],queryFn:async({pageParam:t})=>{let n=await I.getGallery({limit:20,offset:t,...e?{kind:e}:{}});if(!n.success||!n.data)throw Error(n.message||a(`imageGallery.loadFailed`));return n.data},initialPageParam:0,getNextPageParam:(e,t)=>{let n=t.reduce((e,t)=>e+t.media.length,0);return n<e.total?n:void 0}}),p=(0,V.useMemo)(()=>f.data?.pages.flatMap(e=>e.media)||[],[f.data]),h=f.data?.pages[0]?.total||0;(0,V.useEffect)(()=>n?.(h),[n,h]);let _=async e=>{if(!l){u(e.id);try{let t=await I.deleteGalleryItem(e.id);if(!t.success)throw Error(t.message);c(null),await o.invalidateQueries({queryKey:[`media-gallery`]}),g.success(a(`imageGallery.deleteSuccess`))}catch{g.error(a(`imageGallery.deleteFailed`))}finally{u(null)}}},v=async e=>{await F({title:a(`mediaGallery.deleteConfirmTitle`),description:a(`mediaGallery.deleteConfirmDescription`),destructive:!0})&&await _(e)},y=async e=>{try{let t=await I.getGalleryContent(e.id),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`generated-${e.id}.${_e(e.mimeType)}`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}catch{g.error(a(`imageGallery.downloadFailed`))}};return f.isLoading?(0,H.jsx)(A,{srOnly:!0}):f.isError&&p.length===0?(0,H.jsx)(P,{message:a(`imageGallery.loadFailed`),onRetry:()=>void f.refetch()}):p.length===0?(0,H.jsx)(M,{icon:S,titleAs:`h3`,title:a(`mediaGallery.empty`),description:a(`mediaGallery.emptyHint`)}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`,children:p.map(e=>(0,H.jsxs)(`article`,{className:`overflow-hidden rounded-2xl border border-gray-200/80 bg-white/70 dark:border-white/10 dark:bg-white/2.5`,children:[(0,H.jsx)(he,{item:e,onOpenImage:t=>c(ge(e,t))}),(0,H.jsxs)(`div`,{className:`space-y-3 p-3`,children:[(0,H.jsx)(`p`,{className:`line-clamp-2 text-sm text-gray-800 dark:text-gray-200`,children:e.prompt}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,H.jsx)(`span`,{className:`min-w-0 truncate text-xs text-gray-500`,children:e.model}),(0,H.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[e.kind===`image`&&r&&(0,H.jsx)(`button`,{type:`button`,onClick:()=>r(e),className:`rounded-lg p-1.5 hover:bg-gray-100 dark:hover:bg-white/10`,title:a(`imageEdit.title`),"aria-label":a(`imageEdit.title`),"data-testid":`edit-image-${e.id}`,children:(0,H.jsx)(w,{className:`h-4 w-4`})}),(0,H.jsx)(`button`,{type:`button`,onClick:()=>void y(e),className:`rounded-lg p-1.5 hover:bg-gray-100 dark:hover:bg-white/10`,title:a(`imageGallery.download`),"aria-label":a(`imageGallery.download`),children:(0,H.jsx)(m,{className:`h-4 w-4`})}),(0,H.jsx)(`button`,{type:`button`,onClick:()=>void v(e),disabled:l===e.id,className:`rounded-lg p-1.5 hover:bg-red-500/15 hover:text-red-500`,title:a(`imageGallery.delete`),"aria-label":a(`imageGallery.delete`),children:l===e.id?(0,H.jsx)(x,{className:`h-4 w-4 animate-spin`}):(0,H.jsx)(D,{className:`h-4 w-4`})})]})]})]})]},e.id))}),f.isFetchNextPageError&&(0,H.jsx)(P,{size:`sm`,message:a(`imageGallery.loadFailed`),className:`mt-6 py-0`}),f.hasNextPage&&(0,H.jsx)(`div`,{className:`mt-8 flex justify-center`,children:(0,H.jsx)(O,{variant:`outline`,disabled:f.isFetchingNextPage,onClick:()=>void f.fetchNextPage(),children:f.isFetchingNextPage?a(`common.loading`):a(`imageGallery.loadMore`,{current:p.length,total:h})})}),s&&(0,H.jsx)(me,{image:s,onClose:()=>c(null),onDelete:e=>{let t=p.find(t=>t.id===e);t&&_(t)},onDownload:e=>{let t=p.find(t=>t.id===e.id);t&&y(t)}})]})}function he({item:e,onOpenImage:t}){let{t:n}=d(),{data:r,isLoading:i,isError:a}=l({queryKey:[`media-gallery-content`,e.id],queryFn:()=>I.getGalleryContent(e.id),staleTime:3e5}),o=(0,V.useMemo)(()=>r?URL.createObjectURL(r):``,[r]),s=(0,V.useRef)(new Map);return(0,V.useEffect)(()=>{if(!o)return;let e=s.current,t=e.get(o);return t&&(clearTimeout(t),e.delete(o)),()=>{e.set(o,setTimeout(()=>{e.delete(o),URL.revokeObjectURL(o)},0))}},[o]),a?(0,H.jsxs)(`div`,{className:`flex aspect-video flex-col items-center justify-center gap-2 bg-surface-subtle px-3 text-center text-xs text-ink-muted`,children:[(0,H.jsx)(S,{className:`h-6 w-6`}),n(`mediaGallery.previewFailed`)]}):i||!o?(0,H.jsxs)(`div`,{role:`status`,className:`flex aspect-video items-center justify-center bg-gray-100 dark:bg-white/3`,children:[(0,H.jsx)(x,{className:`h-6 w-6 animate-spin text-gray-400`}),(0,H.jsx)(`span`,{className:`sr-only`,children:n(`common.loading`)})]}):e.kind===`image`?(0,H.jsx)(`button`,{type:`button`,className:`block aspect-square w-full overflow-hidden`,onClick:()=>t(o),children:(0,H.jsx)(`img`,{src:o,alt:e.prompt,className:`h-full w-full object-cover`,loading:`lazy`})}):e.kind===`video`?(0,H.jsx)(`div`,{className:`aspect-video bg-black`,children:(0,H.jsx)(`video`,{src:o,controls:!0,preload:`metadata`,"aria-label":e.prompt,className:`h-full w-full object-contain`})}):(0,H.jsxs)(`div`,{className:`flex min-h-40 flex-col items-center justify-center gap-3 bg-surface-subtle p-4`,children:[(0,H.jsx)(E,{className:`h-9 w-9 text-ink-muted`}),(0,H.jsx)(`audio`,{src:o,controls:!0,preload:`metadata`,"aria-label":e.prompt,className:`w-full`})]})}function ge(e,t){return{id:e.id,userId:e.userId,prompt:e.prompt,model:e.model,imageData:t,size:e.size,quality:e.quality,createdAt:e.createdAt}}function _e(e){let t=e.split(`/`)[1]?.split(`;`)[0];return t===`mpeg`?e.startsWith(`audio/`)?`mp3`:`mpeg`:t===`svg+xml`?`svg`:t||`bin`}var Y=()=>{let{t:e}=d(),[t,n]=(0,V.useState)(null),[r,i]=(0,V.useState)(!1),[a,o]=(0,V.useState)(null),[s,c]=(0,V.useState)(`all`),[l,u]=(0,V.useState)(null),[m,h]=(0,V.useState)(0),g=p(e=>e.preferences.imageGenSettings?.enabled===!0),v=(0,V.useCallback)(()=>{h(e=>e+1)},[]);return(0,H.jsxs)(N,{width:`wide`,children:[(0,H.jsx)(j,{title:e(`sidebar.navigation.imagine`),description:e(`gallery.subtitle`),meta:t!==null&&t>0?(0,H.jsx)(`span`,{className:`inline-flex rounded-full border border-gray-200/80 bg-white/60 px-2.5 py-1 text-xs text-gray-500 dark:border-white/10 dark:bg-white/4 dark:text-dark-500`,children:e(`mediaGallery.itemCount`,{count:t})}):null,actions:(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,H.jsxs)(O,{onClick:()=>{g&&i(!0)},disabled:!g,className:`gap-2 px-4`,children:[(0,H.jsx)(_,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`gallery.generate`)]}),(0,H.jsxs)(O,{variant:`outline`,onClick:()=>o(`video`),className:`gap-2 px-4`,children:[(0,H.jsx)(C,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`mediaGeneration.video`)]}),(0,H.jsxs)(O,{variant:`outline`,onClick:()=>o(`audio`),className:`gap-2 px-4`,children:[(0,H.jsx)(E,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`mediaGeneration.audio`)]})]})}),(0,H.jsx)(`div`,{className:`mb-5 flex flex-wrap gap-2`,children:[`all`,`image`,`video`,`audio`].map(t=>(0,H.jsx)(`button`,{type:`button`,onClick:()=>c(t),"aria-pressed":s===t,className:f(`rounded-full border px-3 py-1.5 text-sm transition-colors`,s===t?`border-gray-950 bg-gray-950 text-white dark:border-white dark:bg-white dark:text-gray-950`:`border-gray-200 text-gray-600 hover:border-gray-400 dark:border-white/10 dark:text-dark-600`),children:e(`mediaGallery.filters.${t}`)},t))}),(0,H.jsx)(J,{kind:s===`all`?void 0:s,refreshKey:m,onCountChange:n,onEditImage:u}),(0,H.jsx)(pe,{isOpen:l!==null,source:l,onClose:()=>u(null),onEdited:v}),(0,H.jsx)(U,{isOpen:r&&g,onClose:()=>i(!1),onImageGenerated:v}),(0,H.jsx)(ce,{isOpen:a!==null,initialKind:a||`video`,onClose:()=>o(null),onGenerated:v},a||`closed`)]})};export{Y as GalleryPage,Y 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{d as r}from"./router-vendor-DqMnEJWK.js";import{t as i}from"./chatStore-CVTbkZyb.js";import{t as a}from"./useTranslation-Boi0fB1B.js";import{i as o,o as s,t as c}from"./utils-B-Bhh1pF.js";import{Dt as l,M as u,c as d,dr as f,ht as p,ir as m,ln as h,or as g,t as _}from"./ui-vendor-6S05F84J.js";import{d as v,t as y}from"./authStore-COgKeTRv.js";import{a as b,t as x}from"./work-C7MYlv5S.js";import{n as S,r as C,t as w}from"./appNavigation-C5A9BF_G.js";import{t as T}from"./appVersion-D5lk_2zb.js";var E=e(t(),1),D=n(),O=e=>e<5?`chat.greeting.night`:e<12?`chat.greeting.morning`:e<18?`chat.greeting.afternoon`:`chat.greeting.evening`,k=`mb-2 text-xs font-medium text-ink-muted`,A=`group flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-start text-sm text-ink-muted transition-colors hover:bg-white hover:text-ink dark:hover:bg-dark-200 outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500`,j=()=>{let{t:e,i18n:t}=a(),n=r(),{user:j,systemInfo:M,canUseWork:N,canUseStrands:P}=y(),F=i(e=>e.sessions),I=i(e=>e.models),L=v(e=>e.tasks),R=v(e=>e.capabilities),z=v(e=>e.loadTasks),B=v(e=>e.loadCapabilities),V=N(),H=P();(0,E.useEffect)(()=>{V&&(z(!0).catch(()=>{}),B().catch(()=>{}))},[V,z,B]);let U=e(O(new Date().getHours())),W=j?.username,G=[...F].sort((e,t)=>t.updatedAt-e.updatedAt).slice(0,4),K=[...L].sort((e,t)=>new Date(t.updatedAt).getTime()-new Date(e.updatedAt).getTime()).slice(0,3),q=R?.activeRuntimes?.user??0,J=s()?`⌘`:`Ctrl`,Y=G.length>0||K.length>0,X=T(M?.version);return(0,D.jsx)(`div`,{"data-testid":`home-page`,className:`h-full overflow-y-auto scrollbar-thin`,children:(0,D.jsxs)(`div`,{className:`mx-auto flex min-h-full w-full max-w-xl flex-col justify-center px-6 py-12`,children:[(0,D.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-ink`,children:W?e(`home.greetingWithName`,{greeting:U,name:W}):e(`home.greeting`,{greeting:U})}),(0,D.jsxs)(`p`,{"data-testid":`app-version`,className:`mt-1 font-mono text-xs text-ink-subtle`,children:[window.location.host||`Libre WebUI`,X?` · v${X}`:``]}),(0,D.jsxs)(`div`,{className:`mt-8`,children:[(0,D.jsx)(`p`,{className:k,children:e(`home.start`,`Start`)}),(0,D.jsxs)(`div`,{className:`-mx-2.5 flex flex-col`,children:[(0,D.jsxs)(`button`,{type:`button`,"data-testid":`home-new-chat`,className:A,onClick:()=>S(n),children:[(0,D.jsx)(l,{className:`h-4 w-4 shrink-0 text-ink-subtle transition-colors group-hover:text-ink-muted`}),(0,D.jsx)(`span`,{className:`flex-1`,children:e(`tabs.newChat`,`New Chat`)}),(0,D.jsxs)(`span`,{className:`font-mono text-[10px] tracking-wide text-ink-muted opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100`,children:[J,`⇧O`]})]}),(0,D.jsxs)(`button`,{type:`button`,"data-testid":`home-incognito-chat`,className:A,onClick:()=>w(n),children:[(0,D.jsx)(h,{className:`h-4 w-4 shrink-0 text-ink-subtle transition-colors group-hover:text-ink-muted`}),(0,D.jsx)(`span`,{className:`flex-1`,children:e(`chat.session.incognito`,`Incognito Chat`)})]}),V&&(0,D.jsxs)(`button`,{type:`button`,"data-testid":`home-new-work`,className:A,onClick:()=>C(n),children:[(0,D.jsx)(g,{className:`h-4 w-4 shrink-0 text-ink-subtle transition-colors group-hover:text-ink-muted`}),(0,D.jsx)(`span`,{className:`flex-1`,children:e(`tabs.newWork`,`New Work`)}),(0,D.jsxs)(`span`,{className:`font-mono text-[10px] tracking-wide text-ink-muted opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100`,children:[J,`⇧U`]})]})]})]}),Y&&(0,D.jsxs)(`div`,{className:`mt-8`,children:[(0,D.jsxs)(`div`,{className:`mb-2 flex items-baseline justify-between`,children:[(0,D.jsx)(`p`,{className:c(k,`mb-0`),children:e(`home.continue`,`Continue`)}),V&&q>0&&(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5 font-mono text-[10px] text-ink-subtle`,children:[(0,D.jsx)(`span`,{className:`h-1.5 w-1.5 animate-pulse-subtle rounded-full bg-[rgb(48,121,255)]`}),q,` `,e(`home.active`,`active`)]})]}),(0,D.jsxs)(`div`,{className:`-mx-2.5 flex flex-col`,children:[K.map(r=>{let i=b[r.status],a=e(i.labelKey,i.label);return(0,D.jsxs)(`button`,{type:`button`,"data-testid":`home-continue-work`,className:A,onClick:()=>n(`/work/${r.id}`),children:[(0,D.jsx)(`span`,{"aria-hidden":`true`,className:c(`h-2 w-2 shrink-0 rounded-full ring-1 ring-black/6 dark:ring-white/10`,i.animated&&`animate-pulse-subtle`),style:{backgroundColor:i.color}}),(0,D.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:r.title||e(`work.tasks.untitled`,`Untitled task`)}),r.hostPath&&(0,D.jsx)(`span`,{className:`hidden max-w-56 shrink-0 truncate font-mono text-[10px] text-ink-subtle sm:inline`,title:r.hostPath,children:r.hostPath}),(0,D.jsxs)(`span`,{className:`shrink-0 font-mono text-[10px] text-ink-subtle`,children:[a,!x(r)&&` · ${o(new Date(r.updatedAt).getTime(),t.language)}`]})]},r.id)}),G.map(r=>(0,D.jsxs)(`button`,{type:`button`,"data-testid":`home-continue-chat`,className:A,onClick:()=>n(`/c/${r.id}`),children:[(0,D.jsx)(l,{className:`h-4 w-4 shrink-0 text-ink-subtle`}),(0,D.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:r.title||e(`tabs.chat`,`Chat`)}),(0,D.jsxs)(`span`,{className:`shrink-0 font-mono text-[10px] text-ink-subtle`,children:[(0,D.jsxs)(`span`,{className:`hidden sm:inline`,children:[r.model.startsWith(`persona:`)?I.find(e=>e.isPersona&&e.name===r.model)?.personaName||e(`chat.persona.label`,`Persona`):r.model,` · `]}),o(r.updatedAt,t.language)]})]},r.id))]})]}),(0,D.jsxs)(`div`,{className:`mt-8`,children:[(0,D.jsx)(`p`,{className:k,children:e(`home.explore`,`Explore`)}),(0,D.jsx)(`div`,{className:`-mx-2.5 flex flex-col`,children:[[`/notes`,p,e(`sidebar.navigation.notes`,`Notes`)],[`/calendar`,m,e(`sidebar.navigation.calendar`,`Calendar`)],[`/automations`,_,e(`sidebar.navigation.automations`,`Automations`)],[`/personas`,d,e(`sidebar.navigation.personas`,`Personas`)],[`/gallery`,u,e(`sidebar.navigation.imagine`,`Imagine`)],...H?[[`/strands`,f,e(`sidebar.navigation.strands`,`Strands`)]]:[]].map(([e,t,r])=>(0,D.jsxs)(`button`,{type:`button`,className:A,onClick:()=>n(e),children:[(0,D.jsx)(t,{className:`h-4 w-4 shrink-0 text-ink-subtle transition-colors group-hover:text-ink-muted`}),(0,D.jsx)(`span`,{className:`flex-1`,children:r})]},e))})]})]})})};export{j as HomePage,j 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{C as r,D as i,E as a}from"./chatStore-CVTbkZyb.js";import{t as o}from"./useTranslation-Boi0fB1B.js";import{t as s}from"./utils-B-Bhh1pF.js";import{f as c,l,n as u,p as d,t as f,u as p}from"./appStore-0_qlwS8f.js";import{$n as m,E as h,T as g,Vn as _,Y as v,lt as y,vt as b,w as x}from"./ui-vendor-6S05F84J.js";import{t as S}from"./authStore-COgKeTRv.js";var C=e(t(),1),w=e=>e===`/`||/^\/(?:chat\/?|c\/[^/]+\/?|work(?:\/[^/]+)?\/?)$/.test(e),T=524288,E=1024;function D(e,t,n=2){if(!Number.isFinite(e)||!Number.isFinite(t)||e<=0||t<=0)return{width:0,height:0};let r=Math.min(1/Math.max(1,n),E/Math.max(e,t),Math.sqrt(T/(e*t)));return{width:Math.max(1,Math.floor(e*r)),height:Math.max(1,Math.floor(t*r))}}function O(e,t,n,r){let i=Math.max(n/e,r/t),a=n/i,o=r/i;return{x:(e-a)/2,y:(t-o)/2,width:a,height:o}}var k=[0,48,12,60,3,51,15,63,32,16,44,28,35,19,47,31,8,56,4,52,11,59,7,55,40,24,36,20,43,27,39,23,2,50,14,62,1,49,13,61,34,18,46,30,33,17,45,29,10,58,6,54,9,57,5,53,42,26,38,22,41,25,37,21];function A(e){let t=new Float32Array(e);for(let n=0;n<t.length;n+=4){let r=Math.max(e[n],e[n+1],e[n+2]);if(r===0)continue;let i=M[e[n]]*.2126+M[e[n+1]]*.7152+M[e[n+2]]*.0722,a=N[Math.round(i*4096)],o=(a<=64?a:64+(a-64)*48/191)/r;for(let r=0;r<3;r+=1)t[n+r]=e[n+r]*o}return t}function j(e,t,n){if(!Number.isSafeInteger(t)||!Number.isSafeInteger(n)||t<0||n<0||t*n*4!==e.length)throw RangeError(`Wallpaper pixel dimensions do not match the buffer`);let r=new Uint8ClampedArray(e);for(let i=0;i<n;i+=1)for(let n=0;n<t;n+=1){let a=(i*t+n)*4,o=(k[i%8*8+n%8]+.5)/64-.5,s=Math.max(e[a],e[a+1],e[a+2]);if(s===0)continue;let c=s/255+o>=.5?255/s:0;for(let t=0;t<3;t+=1)r[a+t]=e[a+t]*c}return r}var M=Array.from({length:256},(e,t)=>{let n=t/255;return n<=.04045?n/12.92:((n+.055)/1.055)**2.4}),N=Uint8ClampedArray.from({length:4097},(e,t)=>{let n=t/4096;return 255*(n<=.0031308?n*12.92:1.055*n**(1/2.4)-.055)});function P(e){let t=new Uint8ClampedArray(e);for(let e=0;e<t.length;e+=4){let n=M[t[e]],r=M[t[e+1]],i=M[t[e+2]],a=n*.2126+r*.7152+i*.0722;if(a<=.16)continue;let o=.16/a;t[e]=N[Math.round(n*o*4096)],t[e+1]=N[Math.round(r*o*4096)],t[e+2]=N[Math.round(i*o*4096)]}return t}function F(e,t,n){let r=P(j(A(e),t,n));for(let e=0;e<r.length;e+=4)r[e]===0&&r[e+1]===0&&r[e+2]===0&&(r[e+3]=0);return r}var I=n();function L({settings:e,testId:t=`wallpaper-layer`}){return!e.enabled||!e.imageUrl||e.opacity===0?null:(0,I.jsx)(R,{settings:e,testId:t})}function R({settings:e,testId:t}){let n=(0,C.useRef)(null),r=(0,C.useRef)(null),[i,a]=(0,C.useState)(null),{imageUrl:o,effect:s}=e,c=f(e=>e.theme.mode),l=p(e=>e.palette?.isDark),u=c===`dark`||c===`amoled`||c===`celestial`&&l===!0,d=i?.source===o&&i.effect===s&&i.dark===u?i.state:`loading`;return(0,C.useEffect)(()=>{let e=n.current;if(!e)return;let t=!1,i,c=new Image;c.decoding=`async`,c.referrerPolicy=`no-referrer`,(s===`dither`||u)&&(c.crossOrigin=`anonymous`);let l=e=>{t||a({source:o,effect:s,state:e,dark:u})},d=()=>{if(t||!c.naturalWidth||!c.naturalHeight)return;let n=r.current,{width:i,height:a}=e.getBoundingClientRect(),o=D(i,a,s===`dither`?3:1);if(n&&o.width&&o.height)try{n.width=o.width,n.height=o.height;let e=n.getContext(`2d`,{willReadFrequently:!0});if(!e)throw Error(`Canvas unavailable`);let t=O(c.naturalWidth,c.naturalHeight,o.width,o.height);if(e.drawImage(c,t.x,t.y,t.width,t.height,0,0,o.width,o.height),s===`dither`||u){let t=e.getImageData(0,0,o.width,o.height),n=s===`dither`?F(t.data,o.width,o.height):P(t.data);t.data.set(n),e.putImageData(t,0,0)}l(`ready`)}catch{l(`fallback`)}},f=new ResizeObserver(()=>{i&&clearTimeout(i),i=setTimeout(d,100)});return f.observe(e),c.onload=d,c.onerror=()=>l(`fallback`),c.src=o,()=>{t=!0,f.disconnect(),i&&clearTimeout(i),c.onload=null,c.onerror=null,c.removeAttribute(`src`)}},[o,s,u]),(0,I.jsxs)(`div`,{ref:n,"data-testid":t,"data-effect":s,"data-state":d,"data-tone":i?.dark?`dark`:`light`,className:`account-wallpaper`,"aria-hidden":`true`,style:{"--wallpaper-intensity":e.opacity,"--wallpaper-blur":`${e.blurAmount}px`},children:[(0,I.jsxs)(`div`,{className:`account-wallpaper__art`,children:[(0,I.jsx)(`canvas`,{ref:r,"data-testid":`wallpaper-canvas`,className:`account-wallpaper__canvas`}),d===`fallback`&&(0,I.jsx)(`img`,{src:o,alt:``,draggable:!1,referrerPolicy:`no-referrer`,className:`account-wallpaper__photo`})]}),(0,I.jsx)(`div`,{className:`account-wallpaper__veil`})]})}function z({active:e=!0}){let t=f(e=>e.preferences.backgroundSettings),n=f(e=>e.backgroundImage),r=S(e=>e.user?.id),i=S(e=>e.systemInfo?.requiresAuth),a=u(t);return a.imageUrl=n??a.imageUrl,!e||i!==!1&&!r||!a.enabled||!a.imageUrl?null:(0,I.jsx)(L,{settings:a,testId:`app-background`},r??`solo`)}var B=e=>(Math.round(e)%1440+1440)%1440,V=()=>{let{t:e}=o(),t=p(e=>e.palette),n=p(e=>e.previewMinutes),r=p(e=>e.location),i=p(e=>e.weather),a=p(e=>e.weatherEnabled),u=new Date().setHours(0,0,0,0),f=a&&r?i:null,m=(0,C.useMemo)(()=>{let e=new Date(u);return`linear-gradient(to right, ${Array.from({length:17},(t,n)=>{let i=Math.min(n*1440/16,1439);return`${d(e,i,{location:r,weather:f}).sky.mid} ${n*100/16}%`}).join(`, `)})`},[u,r,f]);if(!t)return null;let S=B(n??t.solar.minutes),w=c(S),T=n!==null,E=t.solar.isDay?h:b,D=T?y:_,O=[{key:`sunrise`,minutes:t.solar.sunrise,Icon:g},{key:`sunset`,minutes:t.solar.sunset,Icon:x}];return(0,I.jsxs)(`div`,{className:`celestial-day-preview flex min-w-0 flex-col gap-3`,style:{"--celestial-day-gradient":m,"--celestial-preview-sky":`linear-gradient(${t.sky.top}, ${t.sky.mid} 65%, ${t.sky.horizon})`,"--celestial-preview-glow":t.glow},children:[(0,I.jsxs)(`div`,{className:`celestial-day-preview__header flex min-w-0 items-start justify-between gap-3`,children:[(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`h4`,{className:`text-sm font-medium text-ink`,children:e(`settings.appearance.celestial.title`)}),(0,I.jsxs)(`span`,{role:`status`,"data-testid":`celestial-preview-status`,className:`mt-1.5 inline-flex items-center gap-1.5 rounded-full border border-line bg-surface-subtle px-2 py-0.5 text-[11px] font-medium text-ink-muted`,children:[(0,I.jsx)(D,{className:`h-3 w-3`,"aria-hidden":`true`}),e(T?`settings.appearance.celestial.preview`:`settings.appearance.celestial.live`)]})]}),(0,I.jsx)(`span`,{dir:`ltr`,className:`shrink-0 text-xl font-medium tabular-nums tracking-tight text-ink`,"data-testid":`celestial-preview-clock`,children:w})]}),(0,I.jsx)(`p`,{className:`text-xs leading-5 text-ink-muted`,children:e(`settings.appearance.celestial.description`)}),(0,I.jsxs)(`div`,{className:`celestial-day-preview__scene`,"aria-hidden":`true`,dir:`ltr`,children:[(0,I.jsx)(`div`,{className:`celestial-day-preview__horizon`}),(0,I.jsx)(`div`,{className:`celestial-day-preview__orb`,"data-day":t.solar.isDay,style:{left:`clamp(22px, ${S/1439*100}%, calc(100% - 22px))`,bottom:`${20+Math.abs(t.solar.altitude)*45}%`},children:(0,I.jsx)(E,{className:`h-5 w-5`,strokeWidth:1.5})})]}),(0,I.jsxs)(`div`,{dir:`ltr`,children:[(0,I.jsx)(`input`,{type:`range`,min:0,max:1439,step:1,value:S,onChange:e=>l(Number(e.target.value)),"aria-label":e(`settings.appearance.celestial.title`),"aria-valuetext":w,"data-testid":`celestial-scrubber`,className:`celestial-day-preview__range w-full rounded-full outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/60 focus-visible:ring-offset-2 focus-visible:ring-offset-surface`,dir:`ltr`}),(0,I.jsx)(`div`,{"aria-hidden":`true`,"data-testid":`celestial-time-anchors`,className:`flex justify-between gap-2 text-[11px] tabular-nums text-ink-muted`,children:[0,720,1439].map(e=>(0,I.jsx)(`span`,{children:c(e)},e))})]}),(0,I.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:O.map(({key:t,minutes:n,Icon:r})=>(0,I.jsxs)(`button`,{type:`button`,tabIndex:0,onClick:()=>l(B(n)),"data-testid":`celestial-preview-${t}`,className:`flex min-w-0 items-center gap-2 rounded-xl border border-line px-3 py-2 text-start text-ink hover:bg-interactive-hover outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/60`,children:[(0,I.jsx)(r,{className:`h-4 w-4 shrink-0`,"aria-hidden":`true`}),(0,I.jsxs)(`span`,{className:`min-w-0`,children:[(0,I.jsx)(`span`,{className:`block truncate text-[11px] text-ink-muted`,children:e(`settings.appearance.celestial.${t}`)}),(0,I.jsx)(`span`,{dir:`ltr`,className:`block text-xs tabular-nums`,children:c(n)})]})]},t))}),(0,I.jsxs)(`button`,{type:`button`,tabIndex:0,onClick:()=>l(null),disabled:!T,"data-testid":`celestial-follow-clock`,className:s(`flex items-center justify-center gap-2 rounded-xl border px-3 py-2 text-xs font-medium outline-hidden transition-colors duration-150 focus-visible:ring-2 focus-visible:ring-primary-500/60 motion-reduce:transition-none`,T?`border-transparent bg-ink text-ink-inverse hover:opacity-90`:`border-line text-ink-muted disabled:cursor-default`),children:[T?(0,I.jsx)(v,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}):(0,I.jsx)(_,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),e(`settings.appearance.celestial.followClock`)]})]})},H=()=>typeof window<`u`&&window.PublicKeyCredential!==void 0&&typeof navigator.credentials?.create==`function`,U=e=>{let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=t+`=`.repeat((4-t.length%4)%4),r=atob(n),i=new Uint8Array(r.length);for(let e=0;e<r.length;e++)i[e]=r.charCodeAt(e);return i.buffer},W=e=>{let t=new Uint8Array(e),n=``;for(let e of t)n+=String.fromCharCode(e);return btoa(n).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)},G=async e=>{let t=e.user,n={...e,challenge:U(e.challenge),user:{...t,id:U(t.id)},excludeCredentials:(e.excludeCredentials??[]).map(e=>({type:`public-key`,id:U(e.id)}))},r=await navigator.credentials.create({publicKey:n});if(!r)throw Error(`Passkey creation was cancelled`);let i=r.response;return{rawId:W(r.rawId),response:{clientDataJSON:W(i.clientDataJSON),attestationObject:W(i.attestationObject),transports:typeof i.getTransports==`function`?i.getTransports():[]}}},K=async e=>{let t={...e,challenge:U(e.challenge)},n=await navigator.credentials.get({publicKey:t});if(!n)throw Error(`Passkey sign-in was cancelled`);let r=n.response;return{rawId:W(n.rawId),response:{clientDataJSON:W(r.clientDataJSON),authenticatorData:W(r.authenticatorData),signature:W(r.signature),userHandle:r.userHandle?W(r.userHandle):null}}},q=({compact:e=!1})=>{let{t,i18n:n}=o();return(0,I.jsxs)(`div`,{className:s(`flex items-center gap-4`,!e&&`py-4`),children:[(0,I.jsxs)(`div`,{className:s(`min-w-0 flex-1`,e&&`sr-only`),children:[(0,I.jsx)(`h4`,{className:`text-sm leading-[22px] text-ink`,children:t(`settings.appearance.language.title`)}),(0,I.jsx)(`p`,{className:`mt-0.5 text-xs text-ink-muted`,children:t(`settings.appearance.language.description`)})]}),(0,I.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,I.jsx)(`select`,{"data-testid":`language-switcher-select`,"aria-label":t(`settings.appearance.language.title`),value:a(n.language),onChange:e=>{let t=e.target.value;r(t)},className:s(e?`max-w-[140px]`:`max-w-[220px]`,`h-9 cursor-pointer appearance-none rounded-full bg-surface-subtle pe-9 ps-3.5 text-sm text-ink transition-colors hover:bg-hover-solid focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500`),children:i.map(t=>(0,I.jsx)(`option`,{value:t.code,children:e?t.nativeName:`${t.nativeName} (${t.name})`},t.code))}),(0,I.jsx)(m,{className:`pointer-events-none absolute inset-e-3 top-1/2 h-4 w-4 -translate-y-1/2 text-ink-muted`})]})]})};export{V as a,w as c,H as i,G as n,z as o,K as r,L as s,q as t};
@@ -0,0 +1 @@
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{t as i}from"./useTranslation-Boi0fB1B.js";import{t as a}from"./utils-B-Bhh1pF.js";import{Cn as o,Nn as s,Q as c,n as l,x as u}from"./ui-vendor-6S05F84J.js";import{t as d}from"./Button-Dh2UJA-B.js";import{t as f}from"./useDialogFocus-zSGHkpE4.js";var p=e(t(),1),m=n(),h=r(),g=({models:e,showDetailsModal:t,setShowDetailsModal:n,selectedModelName:r,selectedModelDetails:g,loadingDetails:_,showCopyModal:v,setShowCopyModal:y,copySource:b,setCopySource:x,copyDestination:S,setCopyDestination:C,copying:w,handleCopyModel:T,showCreateModal:E,setShowCreateModal:D,createModelName:O,setCreateModelName:k,createModelfile:A,setCreateModelfile:j,creating:M,handleCreateModel:N,showEmbeddingsModal:P,setShowEmbeddingsModal:F,embeddingsModel:I,setEmbeddingsModel:L,embeddingsInput:R,setEmbeddingsInput:z,embeddingsResult:B,generatingEmbeddings:V,handleGenerateEmbeddings:H})=>{let{t:U}=i(),W=(0,p.useId)(),G=(0,p.useRef)(null),K=(0,p.useRef)(null),q=(0,p.useRef)(null),J=(0,p.useRef)(null);return f(G,{enabled:t,onClose:()=>n(!1)}),f(K,{enabled:v,onClose:()=>y(!1)}),f(q,{enabled:E,onClose:()=>D(!1)}),f(J,{enabled:P,onClose:()=>F(!1)}),(0,h.jsxs)(h.Fragment,{children:[t&&(0,m.createPortal)((0,h.jsxs)(`div`,{className:`fixed inset-0 z-999999 flex items-center justify-center p-4`,children:[(0,h.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:()=>n(!1)}),(0,h.jsxs)(`div`,{ref:G,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`${W}-details-title`,tabIndex:-1,className:a(`relative w-full max-w-2xl max-h-[85vh] overflow-hidden rounded-xl border shadow-2xl`,`bg-white dark:bg-dark-100`,`border-gray-200 dark:border-dark-300`),children:[(0,h.jsxs)(`div`,{className:a(`flex items-center justify-between p-4 border-b`,`border-gray-200 dark:border-dark-300`),children:[(0,h.jsxs)(`h3`,{id:`${W}-details-title`,className:`text-lg font-semibold text-gray-900 dark:text-gray-100`,children:[U(`modelManager.modals.details.title`),`: `,r]}),(0,h.jsx)(`button`,{type:`button`,"aria-label":U(`common.close`),onClick:()=>n(!1),className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,h.jsx)(l,{className:`h-5 w-5 text-gray-500`})})]}),(0,h.jsx)(`div`,{className:`overflow-y-auto max-h-[calc(85vh-60px)] p-4 space-y-4`,children:_?(0,h.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,h.jsx)(c,{className:`h-6 w-6 animate-spin text-gray-400`})}):g?(0,h.jsxs)(h.Fragment,{children:[g.details&&(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:U(`modelManager.modals.details.info`)}),(0,h.jsx)(`div`,{className:a(`p-3 rounded-lg text-sm`,`bg-gray-50 dark:bg-dark-50`),children:(0,h.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[g.details.family&&(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`span`,{className:`text-gray-500`,children:[U(`modelManager.modals.details.family`),`:`]}),` `,(0,h.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:g.details.family})]}),g.details.parameter_size&&(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`span`,{className:`text-gray-500`,children:[U(`modelManager.modals.details.parameters`),`:`]}),` `,(0,h.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:g.details.parameter_size})]}),g.details.quantization_level&&(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`span`,{className:`text-gray-500`,children:[U(`modelManager.modals.details.quantization`),`:`]}),` `,(0,h.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:g.details.quantization_level})]}),g.details.format&&(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`span`,{className:`text-gray-500`,children:[U(`modelManager.modals.details.format`),`:`]}),` `,(0,h.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:g.details.format})]})]})})]}),g.system&&(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:U(`modelManager.modals.details.systemPrompt`)}),(0,h.jsx)(`pre`,{className:a(`p-3 rounded-lg text-xs overflow-x-auto`,`bg-gray-50 dark:bg-dark-50`,`text-gray-700 dark:text-gray-300`),children:g.system})]}),g.template&&(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:U(`modelManager.modals.details.template`)}),(0,h.jsx)(`pre`,{className:a(`p-3 rounded-lg text-xs overflow-x-auto max-h-40`,`bg-gray-50 dark:bg-dark-50`,`text-gray-700 dark:text-gray-300`),children:g.template})]}),g.parameters&&(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:U(`modelManager.modals.details.parameters`)}),(0,h.jsx)(`pre`,{className:a(`p-3 rounded-lg text-xs overflow-x-auto`,`bg-gray-50 dark:bg-dark-50`,`text-gray-700 dark:text-gray-300`),children:g.parameters})]}),g.license&&(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:U(`modelManager.modals.details.license`)}),(0,h.jsx)(`pre`,{className:a(`p-3 rounded-lg text-xs overflow-x-auto max-h-32`,`bg-gray-50 dark:bg-dark-50`,`text-gray-700 dark:text-gray-300`),children:g.license})]}),g.modelfile&&(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:U(`modelManager.modals.details.modelfile`)}),(0,h.jsx)(`pre`,{className:a(`p-3 rounded-lg text-xs overflow-x-auto max-h-60`,`bg-gray-50 dark:bg-dark-50`,`text-gray-700 dark:text-gray-300`),children:g.modelfile})]})]}):(0,h.jsx)(`p`,{className:`text-center text-gray-500`,children:U(`modelManager.modals.details.noDetails`)})})]})]}),document.body),v&&(0,m.createPortal)((0,h.jsxs)(`div`,{className:`fixed inset-0 z-999999 flex items-center justify-center p-4`,children:[(0,h.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:()=>y(!1)}),(0,h.jsxs)(`div`,{ref:K,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`${W}-copy-title`,tabIndex:-1,className:a(`relative w-full max-w-md rounded-xl border shadow-2xl`,`bg-white dark:bg-dark-100`,`border-gray-200 dark:border-dark-300`),children:[(0,h.jsxs)(`div`,{className:a(`flex items-center justify-between p-4 border-b`,`border-gray-200 dark:border-dark-300`),children:[(0,h.jsx)(`h3`,{id:`${W}-copy-title`,className:`text-lg font-semibold text-gray-900 dark:text-gray-100`,children:U(`modelManager.modals.copy.title`)}),(0,h.jsx)(`button`,{type:`button`,"aria-label":U(`common.close`),onClick:()=>y(!1),className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,h.jsx)(l,{className:`h-5 w-5 text-gray-500`})})]}),(0,h.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{htmlFor:`${W}-copy-source`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:U(`modelManager.modals.copy.source`)}),(0,h.jsxs)(`select`,{id:`${W}-copy-source`,value:b,onChange:e=>x(e.target.value),className:a(`w-full px-3 py-2 rounded-lg border text-sm`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-gray-100`),children:[(0,h.jsx)(`option`,{value:``,children:U(`modelManager.modals.copy.selectModel`)}),e.map(e=>(0,h.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{htmlFor:`${W}-copy-newName`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:U(`modelManager.modals.copy.newName`)}),(0,h.jsx)(`input`,{id:`${W}-copy-newName`,type:`text`,value:S,onChange:e=>C(e.target.value),placeholder:U(`modelManager.modals.copy.placeholder`),className:a(`w-full px-3 py-2 rounded-lg border text-sm`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-gray-100`,`placeholder-gray-500`)})]}),(0,h.jsxs)(d,{onClick:T,disabled:!b.trim()||!S.trim()||w,className:a(`w-full gap-2`,``),children:[w?(0,h.jsx)(c,{className:`h-4 w-4 animate-spin`}):(0,h.jsx)(s,{className:`h-4 w-4`}),U(w?`modelManager.modals.copy.copying`:`modelManager.modals.copy.button`)]})]})]})]}),document.body),E&&(0,m.createPortal)((0,h.jsxs)(`div`,{className:`fixed inset-0 z-999999 flex items-center justify-center p-4`,children:[(0,h.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:()=>D(!1)}),(0,h.jsxs)(`div`,{ref:q,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`${W}-create-title`,tabIndex:-1,className:a(`relative w-full max-w-lg rounded-xl border shadow-2xl`,`bg-white dark:bg-dark-100`,`border-gray-200 dark:border-dark-300`),children:[(0,h.jsxs)(`div`,{className:a(`flex items-center justify-between p-4 border-b`,`border-gray-200 dark:border-dark-300`),children:[(0,h.jsx)(`h3`,{id:`${W}-create-title`,className:`text-lg font-semibold text-gray-900 dark:text-gray-100`,children:U(`modelManager.modals.create.title`)}),(0,h.jsx)(`button`,{type:`button`,"aria-label":U(`common.close`),onClick:()=>D(!1),className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,h.jsx)(l,{className:`h-5 w-5 text-gray-500`})})]}),(0,h.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{htmlFor:`${W}-create-name`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:U(`modelManager.modals.create.name`)}),(0,h.jsx)(`input`,{id:`${W}-create-name`,type:`text`,value:O,onChange:e=>k(e.target.value),placeholder:U(`modelManager.modals.create.namePlaceholder`),className:a(`w-full px-3 py-2 rounded-lg border text-sm`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-gray-100`,`placeholder-gray-500`)})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{htmlFor:`${W}-create-modelfile`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:U(`modelManager.modals.create.modelfile`)}),(0,h.jsx)(`textarea`,{id:`${W}-create-modelfile`,value:A,onChange:e=>j(e.target.value),placeholder:U(`modelManager.modals.create.modelfilePlaceholder`),rows:8,className:a(`w-full px-3 py-2 rounded-lg border text-sm font-mono`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-gray-100`,`placeholder-gray-500`,`resize-none`)}),(0,h.jsxs)(`p`,{className:`mt-1 text-xs text-gray-500`,children:[U(`modelManager.modals.create.see`),` `,(0,h.jsx)(`a`,{href:`https://github.com/ollama/ollama/blob/main/docs/modelfile.md`,target:`_blank`,rel:`noopener noreferrer`,className:`text-primary-600 hover:underline`,children:U(`modelManager.modals.create.docs`)}),` `,U(`modelManager.modals.create.docsLink`)]})]}),(0,h.jsxs)(d,{onClick:N,disabled:!O.trim()||!A.trim()||M,className:a(`w-full gap-2`,``),children:[M?(0,h.jsx)(c,{className:`h-4 w-4 animate-spin`}):(0,h.jsx)(o,{className:`h-4 w-4`}),U(M?`modelManager.modals.create.creating`:`modelManager.modals.create.button`)]})]})]})]}),document.body),P&&(0,m.createPortal)((0,h.jsxs)(`div`,{className:`fixed inset-0 z-999999 flex items-center justify-center p-4`,children:[(0,h.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:()=>F(!1)}),(0,h.jsxs)(`div`,{ref:J,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`${W}-embeddings-title`,tabIndex:-1,className:a(`relative w-full max-w-lg rounded-xl border shadow-2xl`,`bg-white dark:bg-dark-100`,`border-gray-200 dark:border-dark-300`),children:[(0,h.jsxs)(`div`,{className:a(`flex items-center justify-between p-4 border-b`,`border-gray-200 dark:border-dark-300`),children:[(0,h.jsx)(`h3`,{id:`${W}-embeddings-title`,className:`text-lg font-semibold text-gray-900 dark:text-gray-100`,children:U(`modelManager.modals.embeddings.title`)}),(0,h.jsx)(`button`,{type:`button`,"aria-label":U(`common.close`),onClick:()=>F(!1),className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,h.jsx)(l,{className:`h-5 w-5 text-gray-500`})})]}),(0,h.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{htmlFor:`${W}-embeddings-model`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:U(`modelManager.modals.embeddings.model`)}),(0,h.jsxs)(`select`,{id:`${W}-embeddings-model`,value:I,onChange:e=>L(e.target.value),className:a(`w-full px-3 py-2 rounded-lg border text-sm`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-gray-100`),children:[(0,h.jsx)(`option`,{value:``,children:U(`modelManager.modals.embeddings.selectModel`)}),e.map(e=>(0,h.jsx)(`option`,{value:e.name,children:e.name},e.name))]}),(0,h.jsx)(`p`,{className:`mt-1 text-xs text-gray-500`,children:U(`modelManager.modals.embeddings.recommended`)})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{htmlFor:`${W}-embeddings-input`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:U(`modelManager.modals.embeddings.input`)}),(0,h.jsx)(`textarea`,{id:`${W}-embeddings-input`,value:R,onChange:e=>z(e.target.value),placeholder:U(`modelManager.modals.embeddings.placeholder`),rows:3,className:a(`w-full px-3 py-2 rounded-lg border text-sm`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-gray-100`,`placeholder-gray-500`,`resize-none`)})]}),(0,h.jsxs)(d,{onClick:H,disabled:!I.trim()||!R.trim()||V,className:a(`w-full gap-2`,``),children:[V?(0,h.jsx)(c,{className:`h-4 w-4 animate-spin`}):(0,h.jsx)(u,{className:`h-4 w-4`}),U(V?`modelManager.modals.embeddings.generating`:`modelManager.modals.embeddings.button`)]}),B&&(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:U(`modelManager.modals.embeddings.result`,{count:B.length})}),(0,h.jsxs)(`pre`,{className:a(`p-3 rounded-lg text-xs overflow-x-auto max-h-32`,`bg-gray-50 dark:bg-dark-50`,`text-gray-700 dark:text-gray-300`),children:[`[`,B.slice(0,10).join(`, `),B.length>10&&`, ...`,` ]`]})]})]})]})]}),document.body)]})};export{g as ModelManagerModals,g as default};
@@ -0,0 +1,3 @@
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{An as ee,B as l,G as te,M as u,Or as d,P as ne,Rt as f,Tn as re,X as p,at as m,ht as h,m as g,n as _,s as v,st as ie,tt as y,ut as b,v as ae,yr as x}from"./ui-vendor-6S05F84J.js";import{t as S}from"./Button-Dh2UJA-B.js";import{i as C,n as oe,r as w,t as T}from"./ui-CI0OdG9q.js";import{t as E}from"./confirmStore-CKkUtP9c.js";import{A as D,k as O}from"./api-Dcz1G4Ib.js";import{t as se}from"./RichMessageContent-BLI0hhzR.js";var k=e(t(),1),A=4e3,j=(e,t)=>{let n=e.split(`
2
+ `),r=t.split(`
3
+ `);if(n.length>A||r.length>A)return[...n.map(e=>({type:`removed`,text:e})),...r.map(e=>({type:`added`,text:e}))];let i=Array.from({length:n.length+1},()=>Array(r.length+1).fill(0));for(let e=n.length-1;e>=0;--e)for(let t=r.length-1;t>=0;--t)i[e][t]=n[e]===r[t]?i[e+1][t+1]+1:Math.max(i[e+1][t],i[e][t+1]);let a=[],o=0,s=0;for(;o<n.length&&s<r.length;)n[o]===r[s]?(a.push({type:`context`,text:n[o]}),o+=1,s+=1):i[o+1][s]>=i[o][s+1]?(a.push({type:`removed`,text:n[o]}),o+=1):(a.push({type:`added`,text:r[s]}),s+=1);for(;o<n.length;)a.push({type:`removed`,text:n[o]}),o+=1;for(;s<r.length;)a.push({type:`added`,text:r[s]}),s+=1;return a},M=e=>e.some(e=>e.type!==`context`),N=n(),P=i(`components:note-tools`),F=({rows:e})=>(0,N.jsx)(`div`,{className:`max-h-64 overflow-auto rounded-lg border border-black/6 font-mono text-[12px] leading-relaxed dark:border-white/8`,"data-testid":`note-diff-view`,children:e.map((e,t)=>(0,N.jsx)(`div`,{className:c(`whitespace-pre-wrap px-2`,e.type===`added`&&`bg-[rgb(76,212,117)]/12 text-green-800 dark:text-green-300`,e.type===`removed`&&`bg-[rgb(255,61,129)]/10 text-red-800 line-through dark:text-red-300`,e.type===`context`&&`text-gray-600 dark:text-dark-700`),children:e.text||`\xA0`},t))}),ce=({note:e,currentContent:t,currentTitle:n,canWrite:r,isOwner:i,initialTab:te,onClose:ne,onApplyContent:re})=>{let{t:m,i18n:h}=o(),[v,ie]=(0,k.useState)(te),[y,x]=(0,k.useState)({revisions:!1,attachments:!1,share:!1}),[C,se]=(0,k.useState)(null),[A,ce]=(0,k.useState)(null),[I,le]=(0,k.useState)(null),[L,R]=(0,k.useState)(!1),z=(0,k.useRef)(null),[B,ue]=(0,k.useState)(null),[V,H]=(0,k.useState)(``),[U,de]=(0,k.useState)(`read`),[W,G]=(0,k.useState)(!1),[K,fe]=(0,k.useState)(``),[pe,q]=(0,k.useState)(!1),[J,Y]=(0,k.useState)(null),X=a(e=>e.selectedModel),me=a(e=>e.selectedProviderType),he=a(e=>e.selectedProviderId),ge=(0,k.useCallback)(()=>{D.getRevisions(e.id).then(e=>{if(e.success&&Array.isArray(e.data))se(e.data);else throw Error(e.error)}).catch(e=>{P.error(`Failed to load revisions:`,e),d.error(m(`notes.loadFailed`)),x(e=>({...e,revisions:!0}))})},[e.id,m]),Z=(0,k.useCallback)(()=>{D.getAttachments(e.id).then(e=>{if(e.success&&Array.isArray(e.data))le(e.data);else throw Error(e.error)}).catch(e=>{P.error(`Failed to load attachments:`,e),d.error(m(`notes.loadFailed`)),x(e=>({...e,attachments:!0}))})},[e.id,m]),Q=(0,k.useCallback)(()=>{O.listGrants(`note`,e.id).then(e=>{if(e.success&&Array.isArray(e.data))ue(e.data);else throw Error(e.error)}).catch(e=>{P.error(`Failed to load shares:`,e),d.error(m(`notes.loadFailed`)),x(e=>({...e,share:!0}))})},[e.id,m]),_e=e=>y[e]?(0,N.jsx)(T,{size:`sm`,message:m(`notes.loadFailed`),onRetry:()=>x(t=>({...t,[e]:!1}))}):(0,N.jsx)(oe,{size:`sm`,srOnly:!0});(0,k.useEffect)(()=>{v===`revisions`&&C===null&&!y.revisions&&ge(),v===`attachments`&&I===null&&!y.attachments&&Z(),v===`share`&&i&&B===null&&!y.share&&Q()},[v,C,I,B,y,i,ge,Z,Q]);let ve=async t=>{if(await E({title:m(`notes.restoreConfirmTitle`),description:m(`notes.restoreConfirmDescription`),confirmLabel:m(`notes.restore`),destructive:!0}))try{let n=await D.restoreRevision(e.id,t);n.success&&n.data?(re(n.data.content,n.data.title),se(null),ce(null),d.success(m(`notes.revisionRestored`))):d.error(n.error||m(`notes.revisionRestoreFailed`))}catch(e){P.error(`Failed to restore revision:`,e),d.error(m(`notes.revisionRestoreFailed`))}},ye=async t=>{if(t&&t.length!==0){R(!0);try{let n=await D.uploadAttachment(e.id,t[0]);n.success?(Z(),d.success(m(`notes.attachmentAdded`))):d.error(n.error||m(`notes.attachmentFailed`))}catch(e){P.error(`Failed to upload attachment:`,e),d.error(m(`notes.attachmentFailed`))}finally{R(!1),z.current&&(z.current.value=``)}}},be=async t=>{try{let n=await D.downloadAttachment(e.id,t.id),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=t.filename,i.click(),URL.revokeObjectURL(r)}catch(e){P.error(`Failed to download attachment:`,e),d.error(m(`notes.attachmentDownloadFailed`))}},xe=async t=>{if(await E({title:m(`notes.deleteAttachmentConfirmTitle`,{name:t.filename}),description:m(`notes.deleteAttachmentConfirmDescription`),destructive:!0}))try{(await D.deleteAttachment(e.id,t.id)).success?Z():d.error(m(`notes.attachmentDeleteFailed`))}catch(e){P.error(`Failed to delete attachment:`,e),d.error(m(`notes.attachmentDeleteFailed`))}},Se=async()=>{let t=V.trim();if(t){G(!0);try{let n=await O.resolvePrincipal(t);if(!n.success||!n.data){d.error(m(`notes.shareUserNotFound`));return}let r=await O.createGrant({resourceType:`note`,resourceId:e.id,principalType:`user`,principalId:n.data.id,permission:U});r.success?(H(``),Q(),d.success(m(`notes.shareAdded`,{username:t}))):d.error(r.error||m(`notes.shareFailed`))}catch(e){P.error(`Failed to share note:`,e),d.error(m(`notes.shareFailed`))}finally{G(!1)}}},Ce=async e=>{try{(await O.deleteGrant(e)).success?Q():d.error(m(`notes.revokeFailed`))}catch(e){P.error(`Failed to revoke share:`,e),d.error(m(`notes.revokeFailed`))}},we=async()=>{if(K.trim()&&X){q(!0),Y(null);try{let t=await D.assist(e.id,{instruction:K,model:X,providerType:me,providerId:he});t.success&&t.data?.content!==void 0?Y(t.data.content):d.error(t.error||m(`notes.assistFailed`))}catch(e){P.error(`Note assist failed:`,e),d.error(m(`notes.assistFailed`))}finally{q(!1)}}},$=(0,k.useMemo)(()=>J===null?null:j(t,J),[J,t]),Te=[{id:`revisions`,icon:(0,N.jsx)(p,{className:`h-3.5 w-3.5`}),label:m(`notes.revisions`)},{id:`attachments`,icon:(0,N.jsx)(b,{className:`h-3.5 w-3.5`}),label:m(`notes.attachments`)},{id:`share`,icon:(0,N.jsx)(l,{className:`h-3.5 w-3.5`}),label:m(`notes.share`),hidden:!i},{id:`assist`,icon:(0,N.jsx)(u,{className:`h-3.5 w-3.5`}),label:m(`notes.assist`),hidden:!r}];return(0,N.jsxs)(`div`,{className:`absolute inset-y-0 inset-e-0 z-30 flex w-full max-w-md flex-col border-s border-black/6 bg-surface shadow-xl dark:border-white/[0.07] dark:bg-dark-100`,"data-testid":`note-tools-drawer`,role:`dialog`,"aria-label":m(`notes.tools`),children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-black/6 px-3 py-2 dark:border-white/[0.07]`,children:[(0,N.jsx)(`div`,{role:`tablist`,className:`flex items-center gap-1`,children:Te.filter(e=>!e.hidden).map(e=>(0,N.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":v===e.id,onClick:()=>ie(e.id),"data-testid":`note-tools-tab-${e.id}`,className:c(`flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[12px] transition-colors`,v===e.id?`bg-black/6 text-gray-900 dark:bg-white/8 dark:text-dark-900`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),children:[e.icon,e.label]},e.id))}),(0,N.jsx)(`button`,{type:`button`,onClick:ne,className:`ms-auto rounded-md p-1.5 text-gray-400 hover:text-gray-700 dark:text-dark-500 dark:hover:text-dark-800`,"aria-label":m(`common.close`),"data-testid":`note-tools-close`,children:(0,N.jsx)(_,{className:`h-4 w-4`})})]}),(0,N.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-4 scrollbar-thin`,children:[v===`revisions`&&(0,N.jsx)(`div`,{className:`space-y-2`,children:C===null?_e(`revisions`):C.length===0?(0,N.jsx)(w,{icon:p,size:`sm`,title:m(`notes.noRevisions`)}):C.map(e=>(0,N.jsxs)(`div`,{className:`rounded-lg border border-black/6 p-2.5 dark:border-white/8`,"data-testid":`note-revision-item`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>ce(t=>t===e.id?null:e.id),className:`min-w-0 flex-1 truncate text-start text-[13px] text-gray-800 dark:text-dark-800`,children:[s(e.createdAt,h.language),e.title!==n&&(0,N.jsxs)(`span`,{className:`ms-1 text-gray-400 dark:text-dark-500`,children:[`· `,e.title||m(`notes.untitled`)]})]}),r&&(0,N.jsxs)(S,{size:`sm`,variant:`ghost`,className:`h-7 gap-1 px-2 text-[11px]`,onClick:()=>void ve(e.id),"data-testid":`note-revision-restore`,children:[(0,N.jsx)(g,{className:`h-3 w-3`}),m(`notes.restore`)]})]}),A===e.id&&(0,N.jsx)(`div`,{className:`mt-2`,children:(0,N.jsx)(F,{rows:j(e.content,t)})})]},e.id))}),v===`attachments`&&(0,N.jsxs)(`div`,{className:`space-y-2`,children:[r&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`input`,{ref:z,type:`file`,className:`hidden`,onChange:e=>void ye(e.target.files),"data-testid":`note-attachment-input`}),(0,N.jsxs)(S,{size:`sm`,variant:`outline`,className:`w-full gap-1.5`,disabled:L,onClick:()=>z.current?.click(),"data-testid":`note-attachment-upload`,children:[L?(0,N.jsx)(f,{className:`h-3.5 w-3.5 animate-spin`}):(0,N.jsx)(b,{className:`h-3.5 w-3.5`}),m(`notes.addAttachment`)]})]}),I===null?_e(`attachments`):I.length===0?(0,N.jsx)(w,{icon:b,size:`sm`,title:m(`notes.noAttachments`)}):I.map(e=>(0,N.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-black/6 px-2.5 py-2 dark:border-white/8`,"data-testid":`note-attachment-item`,children:[(0,N.jsx)(b,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,N.jsx)(`span`,{dir:`ltr`,className:`min-w-0 flex-1 truncate text-[13px] text-gray-800 dark:text-dark-800`,children:e.filename}),(0,N.jsxs)(`span`,{className:`shrink-0 text-[11px] text-gray-400 dark:text-dark-500`,children:[Math.max(1,Math.round(e.size/1024)),` KB`]}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>void be(e),className:`rounded-md p-1.5 text-gray-500 hover:text-gray-700 dark:text-dark-500 dark:hover:text-dark-800`,title:m(`common.download`),"aria-label":`${m(`common.download`)}: ${e.filename}`,children:(0,N.jsx)(ee,{className:`h-3.5 w-3.5`})}),r&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>void xe(e),className:`rounded-md p-1.5 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,title:m(`common.delete`),"aria-label":`${m(`common.delete`)}: ${e.filename}`,children:(0,N.jsx)(ae,{className:`h-3.5 w-3.5`})})]},e.id))]}),v===`share`&&i&&(0,N.jsxs)(`div`,{className:`space-y-3`,children:[(0,N.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,N.jsx)(`input`,{type:`text`,value:V,onChange:e=>H(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Se()},placeholder:m(`notes.shareUsernamePlaceholder`),"aria-label":m(`notes.shareUsernamePlaceholder`),className:`min-w-0 flex-1 rounded-lg border border-black/8 bg-transparent 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/10 dark:text-dark-900`,"data-testid":`note-share-username`}),(0,N.jsxs)(`select`,{value:U,onChange:e=>de(e.target.value),className:`rounded-lg border border-black/8 bg-transparent px-2 py-1.5 text-[12px] text-gray-700 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-800`,"aria-label":m(`notes.sharePermissionLabel`),"data-testid":`note-share-permission`,children:[(0,N.jsx)(`option`,{value:`read`,children:m(`notes.permissionRead`)}),(0,N.jsx)(`option`,{value:`write`,children:m(`notes.permissionWrite`)})]}),(0,N.jsx)(S,{size:`sm`,disabled:W||!V.trim(),onClick:()=>void Se(),"data-testid":`note-share-submit`,children:W?(0,N.jsx)(f,{className:`h-3.5 w-3.5 animate-spin`}):m(`notes.shareAction`)})]}),B===null?_e(`share`):B.length===0?(0,N.jsx)(w,{icon:l,size:`sm`,title:m(`notes.notShared`)}):B.map(e=>(0,N.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-black/6 px-2.5 py-2 dark:border-white/8`,"data-testid":`note-share-item`,children:[(0,N.jsx)(l,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] text-gray-800 dark:text-dark-800`,children:e.principalId}),(0,N.jsx)(`span`,{className:`shrink-0 text-[11px] uppercase text-gray-400 dark:text-dark-500`,children:e.permission}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>void Ce(e.id),className:`rounded-md p-1.5 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,title:m(`notes.revokeShare`),"aria-label":m(`notes.revokeShare`),children:(0,N.jsx)(_,{className:`h-3.5 w-3.5`})})]},e.id)),(0,N.jsx)(`p`,{className:`text-[11px] leading-relaxed text-gray-400 dark:text-dark-500`,children:m(`notes.shareHint`)})]}),v===`assist`&&r&&(0,N.jsxs)(`div`,{className:`space-y-3`,children:[(0,N.jsx)(`textarea`,{value:K,onChange:e=>fe(e.target.value),placeholder:m(`notes.assistPlaceholder`),rows:3,className:`w-full resize-none rounded-lg border border-black/8 bg-transparent px-2.5 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`,"aria-label":m(`notes.assistPlaceholder`),"data-testid":`note-assist-instruction`}),(0,N.jsxs)(S,{size:`sm`,className:`w-full gap-1.5`,disabled:pe||!K.trim()||!X,onClick:()=>void we(),"data-testid":`note-assist-generate`,children:[pe?(0,N.jsx)(f,{className:`h-3.5 w-3.5 animate-spin`}):(0,N.jsx)(u,{className:`h-3.5 w-3.5`}),m(`notes.assistGenerate`)]}),!X&&(0,N.jsx)(`p`,{className:`text-[11px] text-amber-600 dark:text-amber-400`,children:m(`notes.assistNoModel`)}),J!==null&&$&&(0,N.jsxs)(`div`,{className:`space-y-2`,children:[M($)?(0,N.jsx)(F,{rows:$}):(0,N.jsx)(`p`,{className:`text-center text-xs text-gray-400 dark:text-dark-500`,children:m(`notes.assistNoChanges`)}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(S,{size:`sm`,className:`flex-1`,disabled:!M($),onClick:()=>{re(J),Y(null),fe(``),d.success(m(`notes.assistApplied`))},"data-testid":`note-assist-apply`,children:m(`notes.assistApply`)}),(0,N.jsx)(S,{size:`sm`,variant:`outline`,className:`flex-1`,onClick:()=>Y(null),"data-testid":`note-assist-discard`,children:m(`notes.assistDiscard`)})]}),(0,N.jsx)(`p`,{className:`text-[11px] leading-relaxed text-gray-400 dark:text-dark-500`,children:m(`notes.assistRevisionHint`)})]})]})]})]})},I=i(`pages:notes`),le=800,L=()=>{let{t:e,i18n:t}=o(),[n,i]=(0,k.useState)([]),[a,l]=(0,k.useState)(!0),[u,f]=(0,k.useState)(null),p=(0,k.useRef)(null);(0,k.useEffect)(()=>{p.current=u},[u]);let[g,_]=(0,k.useState)(``),[b,T]=(0,k.useState)(``),[E,O]=(0,k.useState)(``),[A,j]=(0,k.useState)(!0),[M,P]=(0,k.useState)(`idle`),[F,L]=(0,k.useState)(null),R=(0,k.useRef)(null),z=(0,k.useRef)(null),[B,ue]=r(),V=(0,k.useMemo)(()=>n.find(e=>e.id===u)??null,[n,u]);(0,k.useEffect)(()=>{let e=!1;return D.getNotes().then(t=>{e||t.success&&t.data&&i(t.data)}).catch(e=>I.error(`Failed to load notes:`,e)).finally(()=>{e||l(!1)}),()=>{e=!0}},[]);let H=B.get(`note`),U=H?n.find(e=>e.id===H):void 0;U&&u!==U.id&&(f(U.id),T(U.title),O(U.content),j(!0),P(`idle`));let de=H!==null&&(U!==void 0||!a);(0,k.useEffect)(()=>{de&&ue({},{replace:!0})},[de,ue]);let W=!V||!V.shared,G=V?!V.shared||V.shared.permission===`write`:!1,K=(e,t=`preview`)=>{Y(),p.current=e.id,f(e.id),T(e.title),O(e.content),j(t===`preview`),P(`idle`),L(null)},fe=async()=>{if(V)try{let t=await D.updateNote(V.id,{pinned:!V.pinned});if(t.success&&t.data){let e=t.data;i(t=>t.map(t=>t.id===e.id?e:t))}else d.error(e(`notes.saveFailed`))}catch(t){I.error(`Failed to toggle pin:`,t),d.error(e(`notes.saveFailed`))}},pe=()=>{if(!V)return;let e=new Blob([E],{type:`text/markdown;charset=utf-8`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`${(b||`note`).replace(/[\\/:*?"<>|]/g,`-`)}.md`,n.click(),URL.revokeObjectURL(t)},q=(e,t,n)=>{R.current!==null&&window.clearTimeout(R.current),P(`saving`),R.current=window.setTimeout(()=>{R.current=null,J(e,t,n)},le)},J=async(t,n,r)=>{try{let a=await D.updateNote(t,{title:n,content:r});if(a.success&&a.data){let e=a.data;i(n=>[e,...n.filter(e=>e.id!==t)].sort((e,t)=>t.updatedAt-e.updatedAt)),p.current===t&&P(`saved`)}else d.error(e(`notes.saveFailed`)),p.current===t&&P(`error`)}catch(n){I.error(`Failed to save note:`,n),d.error(e(`notes.saveFailed`)),p.current===t&&P(`error`)}},Y=()=>{R.current!==null&&u&&(window.clearTimeout(R.current),R.current=null,J(u,b,E))};(0,k.useEffect)(()=>()=>{R.current!==null&&window.clearTimeout(R.current)},[]);let X=async()=>{try{let e=await D.createNote(``,``);if(e.success&&e.data){let t=e.data;i(e=>[t,...e]),K(t,`edit`)}}catch(t){I.error(`Failed to create note:`,t),d.error(e(`notes.createFailed`))}},me=async t=>{if(window.confirm(e(`notes.deleteConfirm`)))try{(await D.deleteNote(t)).success?(i(e=>e.filter(e=>e.id!==t)),u===t&&f(null)):d.error(e(`notes.deleteFailed`))}catch(t){I.error(`Failed to delete note:`,t),d.error(e(`notes.deleteFailed`))}},he=(0,k.useMemo)(()=>{let e=g.trim().toLowerCase();return e?n.filter(t=>t.title.toLowerCase().includes(e)||t.content.toLowerCase().includes(e)):n},[n,g]);return(0,N.jsxs)(`div`,{className:`relative flex h-full min-h-0 overflow-hidden`,"data-testid":`notes-page`,children:[(0,N.jsxs)(`div`,{"data-testid":`notes-list`,className:c(`min-h-0 w-full shrink-0 flex-col border-e border-black/6 dark:border-white/[0.07] md:w-72`,V?`hidden md:flex`:`flex`),children:[(0,N.jsx)(C,{title:e(`notes.title`),actions:(0,N.jsx)(S,{size:`sm`,variant:`ghost`,onClick:()=>void X(),className:`h-7 w-7 p-0`,title:e(`notes.new`),"aria-label":e(`notes.new`),children:(0,N.jsx)(y,{className:`h-4 w-4`})})}),(0,N.jsxs)(`div`,{className:`relative mx-3 mb-2 mt-3`,children:[(0,N.jsx)(te,{className:`pointer-events-none absolute inset-s-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-gray-400 dark:text-dark-500`}),(0,N.jsx)(`input`,{ref:z,type:`search`,value:g,onChange:e=>_(e.target.value),placeholder:e(`common.search`),"aria-label":e(`common.search`),className:`w-full rounded-lg border border-transparent bg-black/4 py-1.5 pe-2.5 ps-8 text-base text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:bg-white/5 dark:text-dark-900 dark:placeholder:text-dark-500 sm:text-[13px]`})]}),(0,N.jsx)(`div`,{className:`scroll-region min-h-0 flex-1 overflow-y-auto px-2 pb-3 scrollbar-thin`,children:a?(0,N.jsx)(oe,{size:`sm`,srOnly:!0}):he.length===0?(0,N.jsx)(`div`,{role:`status`,children:(0,N.jsx)(w,{icon:h,size:`sm`,title:g.trim()?e(`common.noResults`):e(`notes.empty`),action:g.trim()?(0,N.jsx)(S,{size:`sm`,variant:`ghost`,onClick:()=>{_(``),z.current?.focus()},children:e(`common.clear`)}):void 0})}):(0,N.jsx)(`div`,{className:`space-y-0.5`,children:he.map(n=>(0,N.jsxs)(`div`,{"data-testid":`note-list-item`,className:c(`group relative flex items-center rounded-lg transition-colors`,u===n.id?`bg-white ring-1 ring-black/4 dark:bg-dark-200 dark:ring-white/5`:`hover:bg-white/60 dark:hover:bg-dark-200/60`),children:[(0,N.jsxs)(`button`,{type:`button`,tabIndex:0,onClick:()=>K(n),"aria-label":n.title||e(`notes.untitled`),"aria-current":u===n.id?`true`:void 0,className:`min-w-0 flex-1 rounded-lg px-2.5 py-2 text-start focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,children:[(0,N.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1 truncate text-[13px] font-medium text-gray-900 dark:text-dark-900`,children:[n.pinned&&(0,N.jsx)(m,{className:`h-3 w-3 shrink-0 text-primary-500`,"aria-label":e(`notes.pinned`)}),n.shared&&(0,N.jsx)(v,{className:`h-3 w-3 shrink-0 text-gray-400 dark:text-dark-500`,"aria-label":e(`notes.sharedWithYou`)}),(0,N.jsx)(`span`,{className:`truncate`,children:n.title||e(`notes.untitled`)})]}),(0,N.jsxs)(`span`,{className:`mt-0.5 block truncate text-[11px] text-gray-500 dark:text-dark-500`,children:[s(n.updatedAt,t.language),n.content.trim()&&(0,N.jsxs)(N.Fragment,{children:[` · `,n.content.trim().slice(0,60)]})]})]}),!n.shared&&(0,N.jsx)(`button`,{type:`button`,tabIndex:0,onClick:()=>void me(n.id),className:`me-1.5 shrink-0 rounded-md p-1.5 text-gray-500 opacity-100 transition-opacity hover:bg-red-50 hover:text-red-600 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500 sm:opacity-0 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100 dark:text-dark-500 dark:hover:bg-red-900/20 dark:hover:text-red-400`,title:e(`common.delete`),"aria-label":`${e(`common.delete`)}: ${n.title||e(`notes.untitled`)}`,children:(0,N.jsx)(ae,{className:`h-3 w-3`,"aria-hidden":`true`})})]},n.id))})})]}),(0,N.jsx)(`div`,{"data-testid":`notes-editor`,className:c(`min-w-0 flex-1 flex-col`,V?`flex`:`hidden md:flex`),children:V?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 border-b border-black/6 px-2.5 py-2.5 dark:border-white/[0.07] sm:gap-2 sm:px-5 sm:py-3`,children:[(0,N.jsx)(S,{size:`sm`,variant:`ghost`,onClick:()=>{Y(),f(null),j(!0)},className:`h-9 w-9 shrink-0 p-0 md:hidden`,title:`${e(`common.back`)}: ${e(`notes.title`)}`,"aria-label":`${e(`common.back`)}: ${e(`notes.title`)}`,"data-testid":`notes-mobile-back`,children:(0,N.jsx)(x,{className:`h-4 w-4 rtl:rotate-180`})}),A?(0,N.jsx)(`h2`,{"data-testid":`notes-title-preview`,dir:`auto`,className:`min-w-0 flex-1 truncate text-base font-semibold text-gray-950 dark:text-dark-950 sm:text-lg`,children:b||e(`notes.untitled`)}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`input`,{"data-testid":`notes-title-editor`,dir:`auto`,readOnly:!G,value:b,onChange:e=>{T(e.target.value),q(V.id,e.target.value,E)},placeholder:e(`notes.untitled`),"aria-label":e(`notes.titleLabel`),className:`min-w-0 flex-1 rounded-md bg-transparent text-base font-semibold text-gray-950 placeholder:text-gray-400 focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/50 dark:text-dark-950 dark:placeholder:text-dark-500 sm:text-lg`}),(0,N.jsx)(`span`,{className:c(`hidden shrink-0 text-[11px] sm:inline`,M===`error`?`text-error-700 dark:text-error-300`:`text-ink-muted`),"aria-live":`polite`,children:M===`saving`?e(`common.saving`):M===`saved`?e(`notes.saved`):M===`error`?e(`notes.saveFailed`):``})]}),W&&(0,N.jsx)(S,{size:`sm`,variant:`ghost`,onClick:()=>void fe(),className:c(`hidden h-8 w-8 shrink-0 p-0 sm:flex`,V.pinned&&`text-primary-500`),title:V.pinned?e(`notes.unpin`):e(`notes.pin`),"aria-label":V.pinned?e(`notes.unpin`):e(`notes.pin`),"data-testid":`notes-pin-toggle`,children:(0,N.jsx)(m,{className:`h-3.5 w-3.5`})}),(0,N.jsx)(S,{size:`sm`,variant:`ghost`,onClick:pe,className:`hidden h-8 w-8 shrink-0 p-0 sm:flex`,title:e(`notes.export`),"aria-label":e(`notes.export`),"data-testid":`notes-export`,children:(0,N.jsx)(ee,{className:`h-3.5 w-3.5`})}),(0,N.jsx)(S,{size:`sm`,variant:`ghost`,onClick:()=>L(e=>e===null?`revisions`:null),className:`h-9 w-9 shrink-0 p-0 sm:h-8 sm:w-8`,title:e(`notes.tools`),"aria-label":e(`notes.tools`),"aria-expanded":F!==null,"data-testid":`notes-tools-toggle`,children:(0,N.jsx)(ne,{className:`h-3.5 w-3.5`})}),(0,N.jsx)(S,{size:`sm`,variant:`ghost`,onClick:()=>{A||Y(),j(e=>!e)},className:`h-9 w-9 shrink-0 gap-1.5 p-0 text-xs sm:h-8 sm:w-auto sm:px-2.5`,title:e(A?`common.edit`:`artifacts.preview`),"aria-label":e(A?`common.edit`:`artifacts.preview`),"data-testid":`notes-preview-toggle`,children:A?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(ie,{className:`h-3.5 w-3.5`}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.edit`)})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(re,{className:`h-3.5 w-3.5`}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:e(`artifacts.preview`)})]})})]}),A?(0,N.jsx)(`div`,{"data-testid":`notes-preview`,className:`scroll-region min-h-0 flex-1 overflow-y-auto px-4 py-3 scrollbar-thin sm:px-5 sm:py-4`,children:(0,N.jsx)(se,{content:E,allowHtml:!0,className:`mx-auto w-full max-w-5xl pb-12`})}):(0,N.jsx)(`textarea`,{"data-testid":`notes-content-editor`,dir:`auto`,readOnly:!G,value:E,onChange:e=>{O(e.target.value),q(V.id,b,e.target.value)},onBlur:Y,placeholder:e(`notes.contentPlaceholder`),"aria-label":e(`notes.contentPlaceholder`),className:`min-h-0 flex-1 resize-none bg-transparent px-4 py-3 font-mono text-base leading-relaxed text-gray-900 placeholder:text-gray-400 focus:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary-500/50 dark:text-dark-900 dark:placeholder:text-dark-500 sm:px-5 sm:py-4 sm:text-[13.5px]`}),F!==null&&(0,N.jsx)(ce,{note:V,currentContent:E,currentTitle:b,canWrite:G,isOwner:W,initialTab:F,onClose:()=>L(null),onApplyContent:(e,t)=>{O(e),t!==void 0&&T(t),J(V.id,t===void 0?b:t,e)}})]}):(0,N.jsx)(`div`,{className:`flex flex-1 items-center justify-center`,children:(0,N.jsxs)(`div`,{className:`text-center`,children:[(0,N.jsx)(h,{className:`mx-auto mb-3 h-8 w-8 text-gray-300 dark:text-dark-400`}),(0,N.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-dark-600`,children:e(`notes.selectOrCreate`)}),(0,N.jsxs)(S,{size:`sm`,onClick:()=>void X(),className:`mt-4 gap-1.5`,children:[(0,N.jsx)(y,{className:`h-3.5 w-3.5`}),e(`notes.new`)]})]})})})]})};export{L as NotesPage,L as default};
@@ -0,0 +1 @@
1
+ import"./rolldown-runtime-hePW80VL.js";import{i as e,t}from"./react-vendor-CR5VJ85Q.js";import{t as n}from"./useTranslation-Boi0fB1B.js";import{t as r}from"./utils-B-Bhh1pF.js";import{er as i,n as a}from"./ui-vendor-6S05F84J.js";e();var o=`passwordStrength.requirements`,s=e=>{let t={minLength:e.length>=12,withinBytes:new TextEncoder().encode(e).length<=72,hasCase:/[A-Z]/.test(e)&&/[a-z]/.test(e),hasNumber:/[0-9]/.test(e)},n=t.minLength&&t.withinBytes&&t.hasCase&&t.hasNumber,r=Number(t.minLength)+Number(t.hasCase)+Number(t.hasNumber),i=e.length>=16||/[^A-Za-z0-9]/.test(e),a;return a=t.withinBytes?r<=1?+(e.length>0):r===2?2:i?4:3:1,{checks:t,satisfied:n,score:a,level:a<=1?`weak`:a===2?`fair`:a===3?`good`:`strong`}},c=e=>e.length<12?`passwordStrength.errors.minLength`:new TextEncoder().encode(e).length>72?`passwordStrength.errors.tooLong`:/[A-Z]/.test(e)?/[a-z]/.test(e)?/[0-9]/.test(e)?null:`passwordStrength.errors.number`:`passwordStrength.errors.lowercase`:`passwordStrength.errors.uppercase`,l=t(),u={weak:`bg-red-500`,fair:`bg-amber-500`,good:`bg-lime-500`,strong:`bg-green-500`},d={weak:`text-error-700 dark:text-error-400`,fair:`text-ink`,good:`text-ink`,strong:`text-success-800 dark:text-success-400`},f=({met:e,label:t})=>(0,l.jsxs)(`li`,{className:r(`flex items-center gap-1.5`,e?`text-success-800 dark:text-success-400`:`text-ink-muted`),children:[e?(0,l.jsx)(i,{className:`h-3 w-3 shrink-0`,"aria-hidden":`true`}):(0,l.jsx)(a,{className:`h-3 w-3 shrink-0`,"aria-hidden":`true`}),(0,l.jsx)(`span`,{children:t})]}),p=({password:e})=>{let{t}=n();if(!e)return(0,l.jsx)(`p`,{className:`mt-1.5 text-xs text-ink-muted`,children:t(o)});let i=s(e);return(0,l.jsxs)(`div`,{className:`mt-2 space-y-1.5`,"data-testid":`password-strength-meter`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`div`,{className:`flex flex-1 gap-1`,children:[1,2,3,4].map(e=>(0,l.jsx)(`div`,{className:r(`h-1 flex-1 rounded-full transition-colors motion-reduce:transition-none`,e<=i.score?u[i.level]:`bg-gray-200 dark:bg-dark-300`)},e))}),(0,l.jsx)(`span`,{"data-testid":`password-strength-label`,"aria-live":`polite`,className:r(`text-xs font-medium`,d[i.level]),children:t(`passwordStrength.levels.${i.level}`)})]}),(0,l.jsxs)(`ul`,{className:`space-y-0.5 text-xs`,children:[(0,l.jsx)(f,{met:i.checks.minLength,label:t(`passwordStrength.checks.minLength`)}),(0,l.jsx)(f,{met:i.checks.hasCase,label:t(`passwordStrength.checks.hasCase`)}),(0,l.jsx)(f,{met:i.checks.hasNumber,label:t(`passwordStrength.checks.hasNumber`)}),!i.checks.withinBytes&&(0,l.jsx)(f,{met:!1,label:t(`passwordStrength.checks.tooLong`)})]})]})};export{c as n,p as t};
@@ -0,0 +1,13 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-CR5VJ85Q.js";import{C as r,t as i}from"./useQuery-BTKpXudI.js";import{t as a}from"./logger-BR4forr_.js";import{t as o}from"./chatStore-CVTbkZyb.js";import{t as s}from"./useTranslation-Boi0fB1B.js";import{t as c}from"./utils-B-Bhh1pF.js";import{t as l}from"./appStore-0_qlwS8f.js";import{$t as u,An as d,B as f,Bn as p,D as m,Dt as h,H as g,Jt as _,M as v,N as y,Or as b,Q as x,Rt as S,_ as C,c as w,er as T,g as ee,it as E,j as D,jn as O,kn as te,n as k,nt as A,p as j,qt as M,s as N,sr as P,t as F,v as I,xn as L,xr as ne}from"./ui-vendor-6S05F84J.js";import{t as R}from"./Button-Dh2UJA-B.js";import{n as z,o as B,r as V,s as H,t as U}from"./ui-CI0OdG9q.js";import{M as re,_ as W,d as G,f as K,g as ie,j as ae,m as q,p as oe}from"./api-Dcz1G4Ib.js";import{t as se}from"./AvatarUpload-nPS0QHod.js";import{t as ce}from"./ShareDialog-DQskc17d.js";var J=e(t(),1),Y=n(),X=a(`components:persona-card`),le=({persona:e,onEdit:t,onDelete:n,onDownload:a,onSelect:o,onToggleFavorite:l,isSelected:u=!1,compact:p=!1})=>{let{t:_}=s(),y=r(),[x,S]=(0,J.useState)(!1),C=(0,J.useRef)(null),w=(0,J.useRef)(null),[T,k]=(0,J.useState)(!1),[A,j]=(0,J.useState)(!1);(0,J.useEffect)(()=>{x&&w.current?.querySelector(`[role="menuitem"]:not(:disabled)`)?.focus()},[x]);let M=(e=!1)=>{S(!1),e&&C.current?.focus()},N=e=>{if(e.key===`Escape`){e.stopPropagation(),M(!0);return}if(e.key!==`ArrowDown`&&e.key!==`ArrowUp`)return;let t=Array.from(w.current?.querySelectorAll(`[role="menuitem"]:not(:disabled)`)??[]);if(t.length===0)return;e.preventDefault();let n=t.indexOf(document.activeElement);t[e.key===`ArrowDown`?(n+1)%t.length:(n-1+t.length)%t.length]?.focus()},z=!!(e.memory_settings?.enabled||e.mutation_settings?.enabled),{data:B=null}=i({queryKey:[`persona-memory-status`,e.id],queryFn:async()=>{let t=await q.getMemoryStatus(e.id);return t.success&&t.data?t.data:null},enabled:z}),V=()=>y.invalidateQueries({queryKey:[`persona-memory-status`,e.id]}),H=async()=>{if(confirm(_(`personaCard.wipeConfirm`))){j(!0);try{let t=await q.wipeMemories(e.id);t.success?(b.success(_(`personaCard.wipeSuccess`,{count:t.data?.deleted_count||0})),await V()):b.error(_(`personaCard.wipeFailed`))}catch(e){b.error(_(`personaCard.wipeFailed`)),X.error(e)}finally{j(!1),S(!1)}}},U=async()=>{j(!0);try{let t=await q.backupPersona(e.id),n=window.URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${e.name.toLowerCase().replace(/\s+/g,`-`)}-backup.json`,document.body.appendChild(r),r.click(),window.URL.revokeObjectURL(n),document.body.removeChild(r),b.success(_(`personaCard.backupSuccess`))}catch(e){b.error(_(`personaCard.backupFailed`)),X.error(e)}finally{j(!1),S(!1)}},re=async()=>{j(!0);try{let t=await q.exportPersonaDNA(e.id),n=window.URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${e.name.toLowerCase().replace(/\s+/g,`-`)}-dna.json`,document.body.appendChild(r),r.click(),window.URL.revokeObjectURL(n),document.body.removeChild(r),b.success(_(`personaCard.dnaSuccess`))}catch(e){b.error(_(`personaCard.exportDnaFailed`)),X.error(e)}finally{j(!1),S(!1)}},G=(t=128)=>ie(e,t),K=(t=128)=>n=>{W(n.currentTarget,e.name,t)};return p?(0,Y.jsxs)(`div`,{className:c(`group relative flex items-center gap-3 p-3 rounded-xl cursor-pointer transition-all duration-200`,`border border-transparent`,`hover:bg-gray-50 dark:hover:bg-dark-100`,u&&[`bg-primary-50 dark:bg-primary-900/20`,`border-primary-200 dark:border-primary-700`]),onClick:()=>o?.(e),children:[(0,Y.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,Y.jsx)(`img`,{src:G(64),alt:e.name,className:`w-10 h-10 rounded-full object-cover ring-2 ring-white dark:ring-dark-100`,onError:K(64)}),z&&(0,Y.jsx)(`div`,{className:`absolute -bottom-0.5 -inset-e-0.5 flex h-4 w-4 items-center justify-center rounded-full bg-primary-600`,children:(0,Y.jsx)(v,{className:`h-2.5 w-2.5 text-white`})})]}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`h4`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100 truncate`,children:e.name}),e.is_favorite&&(0,Y.jsx)(m,{className:`h-3 w-3 text-amber-500 fill-amber-500 shrink-0`})]}),(0,Y.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 truncate`,children:e.model})]}),u&&(0,Y.jsx)(`div`,{className:`shrink-0`,children:(0,Y.jsx)(`div`,{className:`w-6 h-6 rounded-full bg-primary-500 dark:bg-primary-600 flex items-center justify-center`,children:(0,Y.jsx)(E,{className:`h-3 w-3 text-white rtl:rotate-180`})})})]}):(0,Y.jsxs)(`div`,{className:c(`group relative overflow-hidden rounded-2xl transition-[border-color,background-color] duration-200`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`hover:border-gray-300 dark:hover:border-white/20`,u&&[`ring-2 ring-primary-500 dark:ring-primary-400`,`border-primary-300 dark:border-primary-600`]),children:[(0,Y.jsxs)(`div`,{className:`relative h-24`,children:[e.background?(0,Y.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,Y.jsx)(`div`,{className:`absolute inset-0 bg-gray-200 dark:bg-dark-200`}),e.background&&(0,Y.jsx)(`div`,{className:`absolute inset-0 bg-black/15 dark:bg-black/25`}),(0,Y.jsxs)(`div`,{className:`absolute inset-x-3 top-3 flex items-start justify-between`,children:[l?(0,Y.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),l(e)},"aria-pressed":!!e.is_favorite,"aria-label":_(`personaCard.favorite`),title:_(`personaCard.favorite`),className:c(`p-1.5 rounded-full transition-all duration-200`,`border border-white/30 bg-black/20 text-white backdrop-blur-sm hover:bg-black/30`,e.is_favorite&&`bg-amber-500/80 hover:bg-amber-500`),children:(0,Y.jsx)(m,{className:c(`h-4 w-4`,e.is_favorite?`fill-ink text-ink dark:fill-ink-inverse dark:text-ink-inverse`:`text-white/80 hover:text-white`)})}):e.is_favorite?(0,Y.jsx)(`span`,{role:`img`,"aria-label":_(`personaCard.favorite`),title:_(`personaCard.favorite`),className:`rounded-full border border-white/30 bg-amber-500/80 p-1.5 backdrop-blur-sm`,children:(0,Y.jsx)(m,{className:`h-4 w-4 fill-ink text-ink dark:fill-ink-inverse dark:text-ink-inverse`})}):(0,Y.jsx)(`span`,{}),z&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 rounded-full border border-white/30 bg-black/20 px-2 py-1 text-[10px] font-medium text-white backdrop-blur-sm`,children:[(0,Y.jsx)(v,{className:`h-3 w-3`}),_(`personaCard.enhanced`)]})]})]}),(0,Y.jsx)(`div`,{className:`relative -mt-8 px-4`,children:(0,Y.jsxs)(`div`,{className:`relative inline-block`,children:[(0,Y.jsx)(`img`,{src:G(128),alt:e.name,className:`h-16 w-16 rounded-xl object-cover ring-4 ring-white dark:ring-dark-100`,onError:K(128)}),z&&(0,Y.jsx)(`div`,{className:`absolute -bottom-1 -inset-e-1 flex h-6 w-6 items-center justify-center rounded-lg bg-primary-600 ring-2 ring-white dark:ring-dark-100`,children:(0,Y.jsx)(P,{className:`h-3.5 w-3.5 text-white`})})]})}),(0,Y.jsxs)(`div`,{className:`px-4 pt-3 pb-4`,children:[(0,Y.jsxs)(`div`,{className:`mb-3`,children:[(0,Y.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 leading-tight`,children:e.name}),(0,Y.jsxs)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 flex items-center gap-1.5 mt-0.5`,children:[(0,Y.jsx)(g,{className:`h-3.5 w-3.5`}),e.model]})]}),e.description&&(0,Y.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 line-clamp-2 mb-3`,children:e.description}),e.parameters.system_prompt&&(0,Y.jsxs)(`div`,{className:`mb-3 rounded-xl border border-gray-200/70 bg-gray-50/70 p-2.5 dark:border-white/8 dark:bg-white/2.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-1`,children:[(0,Y.jsx)(h,{className:`h-3 w-3 text-gray-400 dark:text-gray-500`}),(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider font-medium text-gray-400 dark:text-gray-500`,children:_(`personaCard.systemPrompt`)})]}),(0,Y.jsxs)(`p`,{className:`line-clamp-2 text-xs leading-5 text-gray-600 dark:text-gray-400`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-3`,children:[(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-lg border border-gray-200/70 px-2 py-1 text-[11px] font-medium text-gray-600 dark:border-white/8 dark:text-gray-400`,children:[(0,Y.jsx)(F,{className:`h-3 w-3`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center rounded-lg border border-gray-200/70 px-2 py-1 text-[11px] font-medium text-gray-600 dark:border-white/8 dark:text-gray-400`,children:[`Top-P `,e.parameters.top_p?.toFixed(1)||`0.9`]}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center rounded-lg border border-gray-200/70 px-2 py-1 text-[11px] font-medium text-gray-600 dark:border-white/8 dark:text-gray-400`,children:[(e.parameters.context_window||4096).toLocaleString(),` ctx`]})]}),z&&B&&(0,Y.jsx)(`div`,{className:`mb-3 rounded-xl border border-primary-200/70 bg-primary-50/50 p-2.5 dark:border-primary-800/40 dark:bg-primary-900/10`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(O,{className:`h-4 w-4 text-primary-600 dark:text-primary-400`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`text-xs font-medium text-primary-700 dark:text-primary-300`,children:[B.memory_count,` `,_(`personaCard.memories`)]}),(0,Y.jsx)(`span`,{className:`ms-2 text-[10px] text-primary-600/70 dark:text-primary-400/70`,children:(e=>e<1?`${(e*1024).toFixed(0)} KB`:`${e.toFixed(1)} MB`)(B.size_mb)})]})]}),B.status&&(0,Y.jsx)(`span`,{className:c(`text-[10px] px-1.5 py-0.5 rounded-full font-medium`,B.status===`active`?`bg-success-500/20 text-ink`:`bg-surface-subtle text-ink-muted`),children:_(`personaCard.memoryStatus.${B.status}`)})]})}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between border-t border-gray-200/70 pt-3 dark:border-white/8`,children:[o&&(0,Y.jsxs)(R,{onClick:()=>o(e),size:`sm`,className:`px-4`,children:[(0,Y.jsx)(E,{className:`me-1.5 h-3.5 w-3.5 rtl:rotate-180`}),_(`personaCard.use`)]}),(0,Y.jsxs)(`div`,{className:`ms-auto flex items-center gap-1`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>t(e),className:`p-2 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-dark-200 transition-colors`,title:_(`personaCard.editTooltip`),"aria-label":_(`personaCard.editTooltip`),children:(0,Y.jsx)(D,{className:`h-4 w-4`})}),!e.shared&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>k(!0),className:`p-2 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-dark-200 transition-colors`,title:_(`personaCard.shareTooltip`),"aria-label":_(`personaCard.shareTooltip`),"data-testid":`persona-share`,children:(0,Y.jsx)(f,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>a(e),className:`p-2 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-dark-200 transition-colors`,title:_(`personaCard.downloadTooltip`),"aria-label":_(`personaCard.downloadTooltip`),children:(0,Y.jsx)(d,{className:`h-4 w-4`})}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`button`,{ref:C,type:`button`,onClick:()=>S(!x),"aria-haspopup":`menu`,"aria-expanded":x,className:`p-2 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-dark-200 transition-colors`,title:_(`common.more`),"aria-label":_(`common.more`),children:(0,Y.jsx)(te,{className:`h-4 w-4`})}),x&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>S(!1)}),(0,Y.jsxs)(`div`,{ref:w,role:`menu`,onKeyDown:N,className:`absolute inset-e-0 bottom-full z-20 mb-1 w-44 rounded-xl border border-gray-200 bg-white py-1 shadow-lg dark:border-white/10 dark:bg-dark-100`,children:[z&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:U,disabled:A,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-dark-50 disabled:opacity-50`,children:[(0,Y.jsx)(ne,{className:`h-4 w-4`}),_(`personaCard.backup`)]}),(0,Y.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:re,disabled:A,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-dark-50 disabled:opacity-50`,children:[(0,Y.jsx)(L,{className:`h-4 w-4`}),_(`personaCard.exportDNA`)]}),B&&B.memory_count>0&&(0,Y.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:H,disabled:A,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 disabled:opacity-50`,children:[(0,Y.jsx)(ee,{className:`h-4 w-4`}),_(`personaCard.wipeMemories`)]}),(0,Y.jsx)(`div`,{className:`my-1 border-t border-gray-100 dark:border-dark-200`})]}),(0,Y.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{n(e),S(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20`,children:[(0,Y.jsx)(I,{className:`h-4 w-4`}),_(`common.delete`)]})]})]})]})]})]})]}),T&&(0,Y.jsx)(ce,{resourceType:`persona`,resourceId:e.id,resourceLabel:e.name,onClose:()=>k(!1)})]})},Z={name:``,description:``,model:``,parameters:{temperature:.7,top_p:.9,top_k:40,context_window:4096,max_tokens:1024,system_prompt:``,repeat_penalty:1.1,presence_penalty:0,frequency_penalty:0},avatar:``,background:``,embedding_model:``,memory_settings:{enabled:!1,max_memories:1e3,auto_cleanup:!0,retention_days:90},mutation_settings:{enabled:!1,sensitivity:`medium`,auto_adapt:!0}};function ue({embeddingModel:e,embeddingModels:t,onEmbeddingModelChange:n}){let{t:r}=s(),i=t.filter(e=>e.isDetectedEmbedding),a=t.filter(e=>!e.isDetectedEmbedding);return(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsxs)(`div`,{className:`rounded-xl p-5 bg-linear-to-br from-primary-50 to-primary-100/50 dark:from-primary-900/30 dark:to-primary-800/20 border border-primary-200/50 dark:border-primary-700/30`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,Y.jsx)(O,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`}),(0,Y.jsx)(`h3`,{className:`font-semibold text-primary-900 dark:text-primary-100`,children:r(`personaForm.advanced.embeddingModel`)})]}),(0,Y.jsx)(`p`,{className:`text-xs text-primary-600 dark:text-primary-400 mb-3`,children:r(`personaForm.advanced.embeddingHint`)}),(0,Y.jsx)(`select`,{value:e,onChange:e=>n(e.target.value),className:`w-full px-3 py-2.5 border border-primary-200 dark:border-primary-700 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20`,children:t.length===0?(0,Y.jsx)(`option`,{value:``,disabled:!0,children:r(`personaForm.advanced.noModels`)}):(0,Y.jsxs)(Y.Fragment,{children:[i.length>0&&(0,Y.jsx)(`optgroup`,{label:r(`personaForm.advanced.embeddingModels`),children:i.map(e=>(0,Y.jsxs)(`option`,{value:e.id,children:[e.name,` - `,e.description]},e.id))}),a.length>0&&(0,Y.jsx)(`optgroup`,{label:r(`personaForm.advanced.otherModels`),children:a.map(e=>(0,Y.jsxs)(`option`,{value:e.id,children:[e.name,` - `,e.description]},e.id))})]})}),t.length===0&&(0,Y.jsx)(`div`,{className:`mt-3 rounded-lg border border-amber-200 bg-amber-500/10 p-3 dark:border-amber-700/50 dark:bg-amber-900/20`,children:(0,Y.jsxs)(`p`,{className:`text-sm text-ink`,children:[r(`personaForm.advanced.installHint`),` `,(0,Y.jsx)(`code`,{className:`rounded-sm bg-amber-500/20 px-1.5 py-0.5 text-xs dark:bg-amber-900/40`,children:`ollama pull nomic-embed-text`})]})}),(0,Y.jsx)(`p`,{className:`text-[10px] text-primary-500 dark:text-primary-500 mt-2`,children:r(`personaForm.advanced.recommended`)})]}),(0,Y.jsx)(`div`,{className:`p-4 bg-gray-50 dark:bg-dark-50 rounded-xl border border-gray-200 dark:border-dark-300`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(M,{className:`h-5 w-5 text-gray-400 mt-0.5 shrink-0`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`personaForm.advanced.aboutTitle`)}),(0,Y.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:r(`personaForm.advanced.aboutDescription`)})]})]})})]})}var de=a(`components:persona-background-upload`),fe=({value:e,onChange:t,className:n=``})=>{let{t:r}=s(),i=(0,J.useRef)(null),[a,o]=(0,J.useState)(!1),[c,l]=(0,J.useState)(!1),u=async e=>{if(!e.type.startsWith(`image/`)){b.error(r(`personaBackground.invalidFile`));return}if(e.size>5242880){b.error(r(`personaBackground.fileTooLarge`));return}o(!0);try{let n=new FileReader;n.onload=e=>{let n=e.target?.result;t(n),b.success(r(`personaBackground.uploaded`))},n.onerror=()=>{b.error(r(`personaBackground.readFailed`))},n.readAsDataURL(e)}catch(e){de.error(`Failed to upload background:`,e),b.error(r(`personaBackground.uploadFailed`))}finally{o(!1)}};return(0,Y.jsx)(`div`,{className:`space-y-4 ${n}`,children:(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:r(`personaBackground.label`)}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[e?(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(`div`,{className:`w-full h-32 rounded-lg bg-cover bg-center border-2 border-gray-300 dark:border-dark-300`,style:{backgroundImage:`url(${e})`}}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-gray-50 dark:bg-dark-200 rounded-lg`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:r(`personaBackground.customBackground`)}),(0,Y.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:r(`personaBackground.clickToChange`)})]}),(0,Y.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>{t(``),b.success(r(`personaBackground.removed`))},className:`text-red-600 hover:text-red-700 hover:bg-red-50 dark:text-red-400 dark:hover:text-red-300 dark:hover:bg-red-900/20`,children:(0,Y.jsx)(k,{className:`h-4 w-4`})})]})]}):(0,Y.jsxs)(`div`,{className:`border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${c?`border-primary-500 bg-primary-50 dark:bg-primary-900/20`:`border-gray-300 dark:border-gray-600 hover:border-gray-400 dark:hover:border-gray-500`}`,onDragOver:e=>{e.preventDefault(),l(!0)},onDragLeave:e=>{e.preventDefault(),l(!1)},onDrop:e=>{e.preventDefault(),l(!1);let t=e.dataTransfer.files?.[0];t&&u(t)},onClick:()=>i.current?.click(),children:[(0,Y.jsx)(_,{className:`h-12 w-12 mx-auto text-gray-400 dark:text-gray-500 mb-4`}),(0,Y.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-2`,children:r(`personaBackground.uploadBackgroundImage`)}),(0,Y.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-4`,children:r(`personaBackground.dragAndDrop`)}),(0,Y.jsxs)(R,{variant:`outline`,size:`sm`,disabled:a,className:`mx-auto`,children:[(0,Y.jsx)(j,{className:`h-4 w-4 mr-2`}),r(a?`personaBackground.uploading`:`personaBackground.chooseImage`)]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1`,children:r(`personaBackground.enterImageUrl`)}),(0,Y.jsx)(`input`,{type:`url`,value:e,onChange:e=>t(e.target.value),className:`w-full px-3 py-2 text-sm border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800`,placeholder:`https://example.com/background.jpg`})]})]}),(0,Y.jsx)(`input`,{ref:i,type:`file`,accept:`image/*`,onChange:e=>{let t=e.target.files?.[0];t&&u(t)},className:`hidden`}),(0,Y.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-2`,children:r(`personaBackground.supportedFormats`)})]})})};function pe({formData:e,availableModels:t,onFieldChange:n,onParameterChange:r}){let{t:i}=s(),a=(0,J.useMemo)(()=>t.filter(e=>!e.isPlugin),[t]),o=(0,J.useMemo)(()=>{let e=new Map;for(let n of t){if(!n.isPlugin)continue;let t=n.pluginName||n.pluginId||`Provider`,r=e.get(t);r?r.push(n):e.set(t,[n])}return[...e.entries()].sort(([e],[t])=>e.localeCompare(t))},[t]);return(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:[i(`personaForm.basic.name`),` *`]}),(0,Y.jsx)(`input`,{type:`text`,value:e.name,onChange:e=>n(`name`,e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-colors`,placeholder:i(`personaForm.basic.namePlaceholder`),required:!0})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:[i(`personaForm.basic.model`),` *`]}),(0,Y.jsxs)(`select`,{value:e.model,onChange:e=>n(`model`,e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-colors`,required:!0,children:[(0,Y.jsx)(`option`,{value:``,children:i(`personaForm.basic.selectModel`)}),e.model&&!t.some(t=>t.name===e.model)&&(0,Y.jsx)(`option`,{value:e.model,children:e.model}),a.length>0&&(0,Y.jsx)(`optgroup`,{label:`Ollama`,children:a.map(e=>(0,Y.jsx)(`option`,{value:e.name,children:e.name},e.name))}),o.map(([e,t])=>(0,Y.jsx)(`optgroup`,{label:e,children:t.map(e=>(0,Y.jsx)(`option`,{value:e.name,children:e.name},e.name))},e))]})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:i(`personaForm.basic.description`)}),(0,Y.jsx)(`textarea`,{value:e.description,onChange:e=>n(`description`,e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-colors resize-none`,rows:3,placeholder:i(`personaForm.basic.descriptionPlaceholder`)})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,Y.jsx)(se,{value:e.avatar||``,onChange:e=>n(`avatar`,e)}),(0,Y.jsx)(fe,{value:e.background||``,onChange:e=>n(`background`,e)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:i(`personaForm.basic.systemPrompt`)}),(0,Y.jsx)(`textarea`,{value:e.parameters.system_prompt,onChange:e=>r(`system_prompt`,e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-colors resize-none font-mono text-sm`,rows:6,placeholder:i(`personaForm.basic.systemPromptPlaceholder`)}),(0,Y.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-600 mt-2`,children:i(`personaForm.basic.systemPromptHint`)})]})]})}function me({submitting:e,lastSaved:t,onCancel:n,onSave:r}){let{t:i}=s();return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(R,{type:`button`,variant:`ghost`,onClick:n,disabled:e,className:`text-gray-600 dark:text-gray-400`,children:i(`personaForm.actions.cancel`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[t&&(0,Y.jsxs)(`div`,{role:`status`,"aria-live":`polite`,className:`flex items-center gap-1.5 text-sm text-emerald-600 dark:text-emerald-400`,children:[(0,Y.jsx)(T,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:i(`personaForm.saved`)})]}),(0,Y.jsx)(R,{type:`button`,onClick:r,disabled:e,children:i(e?`personaForm.actions.saving`:`personaForm.actions.save`)})]})]})}var he=a(`components:persona-bindings`),ge=[`web_search`,`search_documents`,`list_documents`,`read_document`,`load_skill`];function _e({bindings:e,onChange:t}){let{t:n}=s(),[r,i]=(0,J.useState)([]),[a,o]=(0,J.useState)([]),[c,l]=(0,J.useState)([]),[u,d]=(0,J.useState)([]),[f,p]=(0,J.useState)(!0);(0,J.useEffect)(()=>{let e=!1;return Promise.all([G.listServers(),K.list(),oe.list(),ae.getCollections()]).then(([t,n,r,a])=>{e||(t.success&&t.data&&i(t.data),n.success&&n.data&&o(n.data),r.success&&r.data&&l(r.data),a.success&&a.data&&d(a.data))}).catch(e=>{he.error(`Failed to load bindable resources:`,e)}).finally(()=>{e||p(!1)}),()=>{e=!0}},[]);let m=n=>t({...e??{},...n}),h=(t,n)=>{let r=e?.[t]??[];m({[t]:r.includes(n)?r.filter(e=>e!==n):[...r,n]})};return f?(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-10`,children:(0,Y.jsx)(S,{className:`h-5 w-5 animate-spin text-gray-400`})}):(0,Y.jsxs)(`div`,{className:`space-y-6`,"data-testid":`persona-bindings-tab`,children:[(0,Y.jsx)(Q,{title:n(`personaForm.bindings.toolServers`),hint:n(`personaForm.bindings.toolServersHint`),emptyLabel:n(`personaForm.bindings.noToolServers`),options:r.map(e=>({id:e.id,label:e.name,detail:e.description})),selected:e?.tool_server_ids??[],onToggle:e=>h(`tool_server_ids`,e),testId:`persona-binding-tool-servers`}),(0,Y.jsx)(Q,{title:n(`personaForm.bindings.builtinTools`),hint:n(`personaForm.bindings.builtinToolsHint`),emptyLabel:n(`personaForm.bindings.noBuiltinTools`),options:ge.map(e=>({id:e,label:n(`personaForm.bindings.builtin.${e}`),detail:e})),selected:e?.builtin_tools??[],onToggle:e=>h(`builtin_tools`,e),testId:`persona-binding-builtin-tools`}),(0,Y.jsx)(Q,{title:n(`personaForm.bindings.skills`),hint:n(`personaForm.bindings.skillsHint`),emptyLabel:n(`personaForm.bindings.noSkills`),options:a.map(e=>({id:e.id,label:e.name,detail:`$${e.slug}`})),selected:e?.skill_ids??[],onToggle:e=>h(`skill_ids`,e),testId:`persona-binding-skills`}),(0,Y.jsx)(Q,{title:n(`personaForm.bindings.collections`),hint:n(`personaForm.bindings.collectionsHint`),emptyLabel:n(`personaForm.bindings.noCollections`),options:u.map(e=>({id:e.id,label:e.name})),selected:e?.knowledge_collection_ids??[],onToggle:t=>{let n=e?.knowledge_collection_ids??[];m({knowledge_collection_ids:n.includes(t)?n.filter(e=>e!==t):[...n,t]})},testId:`persona-binding-collections`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-800`,children:n(`personaForm.bindings.prompt`)}),(0,Y.jsx)(`p`,{className:`mb-2 mt-1 text-xs text-gray-500 dark:text-dark-600`,children:n(`personaForm.bindings.promptHint`)}),(0,Y.jsxs)(`select`,{value:e?.prompt_id??``,onChange:e=>m({prompt_id:e.target.value||void 0}),"data-testid":`persona-binding-prompt`,"aria-label":n(`personaForm.bindings.prompt`),className:`w-full rounded-lg border border-gray-200 bg-white px-3 py-2.5 text-sm text-gray-900 focus:ring-2 focus:ring-primary-500/20 dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`personaForm.bindings.noPrompt`)}),c.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.title},e.id))]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-dark-500`,children:n(`personaForm.bindings.version`,{version:e?.version??0})})]})}function Q({title:e,hint:t,emptyLabel:n,options:r,selected:i,onToggle:a,testId:o}){return(0,Y.jsxs)(`div`,{"data-testid":o,children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-800`,children:e}),(0,Y.jsx)(`p`,{className:`mb-2 mt-1 text-xs text-gray-500 dark:text-dark-600`,children:t}),r.length===0?(0,Y.jsx)(`p`,{className:`rounded-lg border border-dashed border-gray-200 px-3 py-4 text-center text-xs text-gray-400 dark:border-dark-300 dark:text-dark-500`,children:n}):(0,Y.jsx)(`div`,{className:`space-y-1`,children:r.map(e=>(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2.5 rounded-lg px-2.5 py-1.5 transition-colors hover:bg-gray-50 dark:hover:bg-dark-200`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:i.includes(e.id),onChange:()=>a(e.id),className:`h-4 w-4 rounded-sm border-gray-300 dark:border-dark-400`}),(0,Y.jsx)(`span`,{className:`text-sm text-gray-900 dark:text-dark-800`,children:e.label}),e.detail&&(0,Y.jsx)(`span`,{className:`truncate text-xs text-gray-400 dark:text-dark-500`,children:e.detail})]},e.id))})]})}var ve=({label:e,value:t,min:n,max:r,step:i,onChange:a,hint:o,format:s=e=>String(e),colorClass:l=`text-gray-700 dark:text-dark-600`})=>{let u=(t-n)/(r-n)*100;return(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsx)(`label`,{className:c(`block text-sm font-medium`,l),children:e}),(0,Y.jsx)(`input`,{type:`number`,min:n,max:r,step:i,value:s(t),onChange:e=>{let t=parseFloat(e.target.value);isNaN(t)||a(Math.min(r,Math.max(n,t)))},className:`w-20 px-2 py-1 text-sm text-right bg-gray-100 dark:bg-dark-200 border border-gray-300 dark:border-dark-300 rounded-sm focus:outline-hidden focus:ring-1 focus:ring-primary-500 dark:text-dark-600`})]}),(0,Y.jsx)(`input`,{type:`range`,min:n,max:r,step:i,value:t,onChange:e=>a(parseFloat(e.target.value)),className:`w-full h-2 bg-gray-200 dark:bg-dark-200 rounded-lg appearance-none cursor-pointer slider`,style:{"--progress":`${u}%`}}),o&&(0,Y.jsx)(`p`,{className:c(`text-xs mt-1`,l.replace(`700`,`500`).replace(`600`,`400`)),children:o})]})},$=({label:e,checked:t,onChange:n,colorClass:r=`text-gray-700 dark:text-dark-600`})=>(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`div`,{className:c(`relative w-10 h-5 rounded-full transition-colors`,t?`bg-primary-500 dark:bg-primary-600`:`bg-gray-300 dark:bg-dark-300`),onClick:()=>n(!t),children:(0,Y.jsx)(`div`,{className:c(`absolute top-0.5 inset-s-0.5 w-4 h-4 rounded-full bg-white shadow-sm transition-transform`,t&&`translate-x-5 rtl:-translate-x-5`)})}),(0,Y.jsx)(`span`,{className:c(`text-sm font-medium`,r),children:e})]});function ye({formData:e,persona:t,memoryStatus:n,loadingMemoryStatus:r,wipingMemories:i,onSettingsChange:a,onWipeMemories:o}){let{t:l}=s();return(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsxs)(`div`,{className:`rounded-xl overflow-hidden border border-emerald-200/50 dark:border-emerald-700/30`,children:[(0,Y.jsx)(`div`,{className:`px-5 py-4 bg-linear-to-r from-emerald-500 to-teal-500 dark:from-emerald-600 dark:to-teal-600`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`w-10 h-10 rounded-lg bg-white/20 flex items-center justify-center`,children:(0,Y.jsx)(O,{className:`h-5 w-5 text-white`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`font-semibold text-white`,children:l(`personaForm.memory.title`)}),(0,Y.jsx)(`p`,{className:`text-xs text-white/80`,children:l(`personaForm.memory.subtitle`)})]})]}),(0,Y.jsx)($,{label:``,checked:e.memory_settings?.enabled||!1,onChange:e=>a(`memory_settings`,{enabled:e})})]})}),e.memory_settings?.enabled&&t?.id&&(0,Y.jsx)(`div`,{className:`px-5 py-4 bg-emerald-50 dark:bg-emerald-900/20 border-b border-emerald-100 dark:border-emerald-800/30`,children:r?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-emerald-600 dark:text-emerald-400`,children:[(0,Y.jsx)(x,{className:`h-4 w-4 animate-spin`}),l(`personaForm.memory.loading`)]}):n?(0,Y.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,Y.jsxs)(`div`,{className:`text-center`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,Y.jsx)(O,{className:`h-5 w-5`}),n.memory_count.toLocaleString()]}),(0,Y.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:l(`personaForm.memory.memories`)})]}),(0,Y.jsxs)(`div`,{className:`text-center`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,Y.jsx)(u,{className:`h-5 w-5`}),n.size_mb.toFixed(1)]}),(0,Y.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:l(`personaForm.memory.mbUsed`)})]}),(0,Y.jsxs)(`div`,{className:`text-center`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,Y.jsx)(p,{className:`h-5 w-5`}),n.last_backup?new Date(n.last_backup).toLocaleDateString():l(`personaForm.memory.never`)]}),(0,Y.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:l(`personaForm.memory.lastBackup`)})]})]}):(0,Y.jsx)(`p`,{className:`text-sm text-emerald-600 dark:text-emerald-400`,children:l(`personaForm.memory.noData`)})}),e.memory_settings?.enabled&&(0,Y.jsxs)(`div`,{className:`p-5 bg-white dark:bg-dark-100 space-y-4`,children:[(0,Y.jsx)(ve,{label:l(`personaForm.memory.maxMemories`),value:e.memory_settings.max_memories,min:100,max:1e4,step:100,hint:l(`personaForm.memory.maxMemoriesHint`),format:e=>e.toLocaleString(),colorClass:`text-emerald-700 dark:text-emerald-300`,onChange:e=>a(`memory_settings`,{max_memories:e})}),(0,Y.jsx)(ve,{label:l(`personaForm.memory.retention`),value:e.memory_settings.retention_days,min:7,max:365,step:7,hint:l(`personaForm.memory.retentionHint`),format:e=>`${Math.round(e)} days`,colorClass:`text-emerald-700 dark:text-emerald-300`,onChange:e=>a(`memory_settings`,{retention_days:e})}),(0,Y.jsx)($,{label:l(`personaForm.memory.autoCleanup`),checked:e.memory_settings.auto_cleanup,onChange:e=>a(`memory_settings`,{auto_cleanup:e}),colorClass:`text-emerald-700 dark:text-emerald-300`}),t?.id&&n&&n.memory_count>0&&(0,Y.jsx)(`div`,{className:`pt-4 border-t border-gray-200 dark:border-dark-300`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-red-50 dark:bg-red-900/20 rounded-lg border border-red-200 dark:border-red-800/30`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-red-700 dark:text-red-300`,children:l(`personaForm.memory.wipeAll`)}),(0,Y.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:l(`personaForm.memory.wipeCannot`)})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:o,disabled:i,className:`px-3 py-1.5 bg-red-500 hover:bg-red-600 text-white text-sm font-medium rounded-lg transition-colors disabled:opacity-50 flex items-center gap-1.5`,children:[i?(0,Y.jsx)(x,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(I,{className:`h-3.5 w-3.5`}),l(i?`personaForm.memory.wiping`:`personaForm.memory.wipeButton`)]})]})})]}),!e.memory_settings?.enabled&&(0,Y.jsx)(`div`,{className:`p-5 bg-gray-50 dark:bg-dark-50`,children:(0,Y.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 text-center`,children:l(`personaForm.memory.enableHint`)})})]}),(0,Y.jsxs)(`div`,{className:`rounded-xl overflow-hidden border border-primary-200/50 dark:border-primary-700/30`,children:[(0,Y.jsx)(`div`,{className:`px-5 py-4 bg-primary-600 dark:bg-primary-600`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`w-10 h-10 rounded-lg bg-white/20 flex items-center justify-center`,children:(0,Y.jsx)(C,{className:`h-5 w-5 text-white`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`font-semibold text-white`,children:l(`personaForm.learning.title`)}),(0,Y.jsx)(`p`,{className:`text-xs text-white/80`,children:l(`personaForm.learning.subtitle`)})]})]}),(0,Y.jsx)($,{label:``,checked:e.mutation_settings?.enabled||!1,onChange:e=>a(`mutation_settings`,{enabled:e})})]})}),e.mutation_settings?.enabled&&(0,Y.jsxs)(`div`,{className:`p-5 bg-white dark:bg-dark-100 space-y-5`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-primary-700 dark:text-primary-300 mb-3`,children:l(`personaForm.learning.speed`)}),(0,Y.jsx)(`div`,{className:`grid grid-cols-3 gap-3`,children:[{level:`low`,icon:F,label:l(`personaForm.learning.slow`),desc:l(`personaForm.learning.slowDesc`)},{level:`medium`,icon:C,label:l(`personaForm.learning.balanced`),desc:l(`personaForm.learning.balancedDesc`)},{level:`high`,icon:v,label:l(`personaForm.learning.fast`),desc:l(`personaForm.learning.fastDesc`)}].map(({level:t,icon:n,label:r,desc:i})=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>a(`mutation_settings`,{sensitivity:t}),className:c(`p-3 rounded-xl text-center transition-all border`,e.mutation_settings?.sensitivity===t?`bg-primary-600 border-primary-600 text-white shadow-lg`:`bg-primary-50 dark:bg-primary-900/20 border-primary-200 dark:border-primary-700/30 text-primary-700 dark:text-primary-300 hover:bg-primary-100 dark:hover:bg-primary-900/30`),children:[(0,Y.jsx)(n,{className:`h-5 w-5 mx-auto mb-1`}),(0,Y.jsx)(`p`,{className:`text-sm font-medium`,children:r}),(0,Y.jsx)(`p`,{className:`text-[10px] opacity-70`,children:i})]},t))})]}),(0,Y.jsx)($,{label:l(`personaForm.learning.autoAdapt`),checked:e.mutation_settings.auto_adapt,onChange:e=>a(`mutation_settings`,{auto_adapt:e}),colorClass:`text-primary-700 dark:text-primary-300`}),(0,Y.jsxs)(`div`,{className:`p-4 bg-primary-50 dark:bg-primary-900/20 rounded-xl`,children:[(0,Y.jsxs)(`p`,{className:`text-xs font-medium text-primary-700 dark:text-primary-300 mb-2 flex items-center gap-1.5`,children:[(0,Y.jsx)(P,{className:`h-3.5 w-3.5`}),l(`personaForm.learning.whatLearns`)]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs text-primary-600 dark:text-primary-400`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),l(`personaForm.learning.conversationTone`)]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),l(`personaForm.learning.responseStyle`)]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),l(`personaForm.learning.userPreferences`)]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),l(`personaForm.learning.topicInterests`)]})]})]})]}),!e.mutation_settings?.enabled&&(0,Y.jsx)(`div`,{className:`p-5 bg-gray-50 dark:bg-dark-50`,children:(0,Y.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 text-center`,children:l(`personaForm.learning.enableHint`)})})]})]})}function be({parameters:e,onParameterChange:t}){let{t:n}=s(),r=(0,J.useMemo)(()=>[{key:`temperature`,label:n(`personaForm.parameters.temperature`),min:0,max:2,step:.1,hint:n(`personaForm.parameters.temperatureHint`),format:e=>e.toFixed(1)},{key:`top_p`,label:n(`personaForm.parameters.topP`),min:0,max:1,step:.1,hint:n(`personaForm.parameters.topPHint`),format:e=>e.toFixed(1)},{key:`top_k`,label:n(`personaForm.parameters.topK`),min:1,max:100,step:1,hint:n(`personaForm.parameters.topKHint`),format:e=>String(Math.round(e))},{key:`context_window`,label:n(`personaForm.parameters.contextWindow`),min:128,max:131072,step:128,hint:n(`personaForm.parameters.contextWindowHint`),format:e=>String(Math.round(e))},{key:`max_tokens`,label:n(`personaForm.parameters.maxTokens`),min:1,max:8192,step:1,hint:n(`personaForm.parameters.maxTokensHint`),format:e=>String(Math.round(e))},{key:`repeat_penalty`,label:n(`personaForm.parameters.repeatPenalty`),min:.5,max:2,step:.1,hint:n(`personaForm.parameters.repeatPenaltyHint`),format:e=>e.toFixed(1)}],[n]);return(0,Y.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:r.map(({key:n,label:r,min:i,max:a,step:o,hint:s,format:c})=>(0,Y.jsx)(ve,{label:r,value:e[n]||0,min:i,max:a,step:o,hint:s,format:c,onChange:e=>t(n,e)},n))})}var xe=a(`components:persona-form`),Se=({persona:e,onSubmit:t,onCancel:n})=>{let{preferences:a}=l(),{t:u}=s(),[d,f]=(0,J.useState)(Z),p=o(e=>e.models),m=o(e=>e.loadModels),h=(0,J.useMemo)(()=>p.filter(e=>!e.isPersona&&!e.isAgent&&!e.isUnavailable&&!e.isLegacySelection),[p]),[g,_]=(0,J.useState)([]),[x,S]=(0,J.useState)(!1),[C,T]=(0,J.useState)(!1),[ee,E]=(0,J.useState)(null),[D,O]=(0,J.useState)(`basic`),[te,k]=(0,J.useState)(!1),j=(0,J.useRef)(!1),M=(0,J.useCallback)((e,t)=>{f(n=>({...n,[e]:t})),E(null)},[]),N=(0,J.useCallback)((e,t)=>{f(n=>({...n,parameters:{...n.parameters,[e]:t}})),E(null)},[]),F=(0,J.useCallback)((e,t)=>{f(n=>({...n,[e]:{...n[e],...t}})),E(null)},[]),I=(0,J.useCallback)(e=>{let t=e.reduce((e,t)=>(e.find(e=>e.id===t.id)||e.push(t),e),[]);return t.length>0?t:[{id:`nomic-embed-text`,name:`nomic-embed-text`,description:`Ollama - Default embedding model`,provider:`ollama`,dimensions:0,isDetectedEmbedding:!0}]},[]),L=e?.id,ne=!!d.memory_settings?.enabled,R=r(),{data:z=null,isLoading:B}=i({queryKey:[`persona-memory-status`,L],queryFn:async()=>{if(!L)return null;let e=await q.getMemoryStatus(L);return e.success&&e.data?e.data:null},enabled:!!L&&ne}),V=()=>R.invalidateQueries({queryKey:[`persona-memory-status`,L]}),H=async()=>{if(e?.id&&confirm(u(`personaForm.memory.wipeConfirm`))){k(!0);try{let t=await q.wipeMemories(e.id);t.success?(b.success(u(`personaForm.memory.wipeSuccess`,{count:t.data?.deleted_count||0})),await V()):b.error(u(`personaForm.error.saveFailed`))}catch{b.error(u(`personaForm.error.saveFailed`))}finally{k(!1)}}};(0,J.useEffect)(()=>{j.current||(j.current=!0,(async()=>{S(!0);try{let[t,n]=await Promise.all([re.getModels(),e?Promise.resolve(null):q.getDefaultParameters(),o.getState().models.length===0?m({quiet:!0}):Promise.resolve()]),r=I(t.success&&t.data?t.data:[]);_(r);let i=r.find(e=>e.id===a.embeddingSettings?.model||e.rawModel===a.embeddingSettings?.model)?.id||r[0]?.id||``,s=r.find(t=>t.id===e?.embedding_model||t.rawModel===e?.embedding_model)?.id||e?.embedding_model||r[0]?.id||``;if(e)f({name:e.name,description:e.description||``,model:e.model,parameters:e.parameters,avatar:e.avatar||``,background:e.background||``,embedding_model:s,memory_settings:e.memory_settings||Z.memory_settings,mutation_settings:e.mutation_settings||Z.mutation_settings,bindings:e.bindings}),e.embedding_model&&!r.find(t=>t.id===e.embedding_model||t.rawModel===e.embedding_model)&&_(t=>I([...t,{id:e.embedding_model,name:e.embedding_model,description:`Previously selected model (not currently available)`,provider:`openai`,dimensions:0}]));else{let e=n?.success?n.data:{};f(t=>({...t,parameters:{...t.parameters,...e},embedding_model:i}))}}catch(e){xe.error(`Error loading data:`,e)}finally{S(!1)}})())},[e,I,m,a.embeddingSettings?.model]);let U=async()=>{T(!0);try{let n={name:d.name,description:d.description,model:d.model,parameters:d.parameters,avatar:d.avatar,background:d.background,embedding_model:d.embedding_model,memory_settings:d.memory_settings,mutation_settings:d.mutation_settings,bindings:d.bindings},r=e?await q.updatePersona(e.id,n):await q.createPersona(d);r.success&&r.data?(b.success(u(e?`personaForm.success.updated`:`personaForm.success.created`)),E(new Date),await t(r.data)):b.error(r.error?`${u(`personaForm.error.saveFailed`)}: ${r.error}`:u(`personaForm.error.saveFailed`))}catch(e){b.error(`${u(`personaForm.error.saveFailed`)}: ${e instanceof Error?e.message:String(e)}`)}finally{T(!1)}},W=(0,J.useMemo)(()=>[{id:`basic`,label:u(`personaForm.tabs.basic`),icon:w},{id:`parameters`,label:u(`personaForm.tabs.parameters`),icon:y},{id:`memory`,label:u(`personaForm.tabs.memory`),icon:v},{id:`bindings`,label:u(`personaForm.tabs.bindings`),icon:A},{id:`advanced`,label:u(`personaForm.tabs.advanced`),icon:P}],[u]);return x?(0,Y.jsx)(`div`,{className:`flex items-center justify-center p-8`,children:(0,Y.jsxs)(`div`,{className:`animate-pulse flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`w-5 h-5 border-2 border-primary-500 border-t-transparent rounded-full animate-spin`}),(0,Y.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:u(`personaForm.loading`)})]})}):(0,Y.jsxs)(`div`,{className:`max-w-4xl mx-auto`,children:[(0,Y.jsxs)(`div`,{className:`mb-6`,children:[(0,Y.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-dark-800`,children:u(e?`personaForm.title.edit`:`personaForm.title.create`)}),(0,Y.jsx)(`p`,{className:`mt-1 text-gray-600 dark:text-dark-600`,children:u(e?`personaForm.subtitle.edit`:`personaForm.subtitle.create`)})]}),(0,Y.jsxs)(`form`,{onSubmit:e=>e.preventDefault(),className:`space-y-6`,children:[(0,Y.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg shadow-xs border border-gray-200 dark:border-dark-300`,children:[(0,Y.jsx)(`div`,{role:`tablist`,"aria-label":u(`personaForm.sections`),className:`flex overflow-x-auto border-b border-gray-200 dark:border-dark-300`,onKeyDown:e=>{let t=W.findIndex(e=>e.id===D),n=document.documentElement.dir===`rtl`,r=n?`ArrowLeft`:`ArrowRight`,i=n?`ArrowRight`:`ArrowLeft`,a=-1;e.key===r?a=(t+1)%W.length:e.key===i?a=(t-1+W.length)%W.length:e.key===`Home`?a=0:e.key===`End`&&(a=W.length-1);let o=W[a];o&&(e.preventDefault(),O(o.id),document.getElementById(`persona-tab-${o.id}`)?.focus())},children:W.map(e=>(0,Y.jsxs)(`button`,{id:`persona-tab-${e.id}`,type:`button`,role:`tab`,"aria-selected":D===e.id,"aria-controls":`persona-tabpanel`,tabIndex:D===e.id?0:-1,onClick:()=>O(e.id),className:c(`flex shrink-0 items-center gap-2 whitespace-nowrap px-6 py-4 text-sm font-medium transition-colors`,D===e.id?`border-b-2 border-primary-500 text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-dark-600 hover:text-gray-700 dark:hover:text-dark-800`),children:[(0,Y.jsx)(e.icon,{className:`h-4 w-4`,"aria-hidden":`true`}),e.label]},e.id))}),(0,Y.jsxs)(`div`,{id:`persona-tabpanel`,role:`tabpanel`,"aria-labelledby":`persona-tab-${D}`,className:`p-6`,children:[D===`basic`&&(0,Y.jsx)(pe,{formData:d,availableModels:h,onFieldChange:M,onParameterChange:N}),D===`parameters`&&(0,Y.jsx)(be,{parameters:d.parameters,onParameterChange:N}),D===`memory`&&(0,Y.jsx)(ye,{formData:d,persona:e,memoryStatus:z,loadingMemoryStatus:B,wipingMemories:te,onSettingsChange:F,onWipeMemories:H}),D===`bindings`&&(0,Y.jsx)(_e,{bindings:d.bindings,onChange:e=>M(`bindings`,e)}),D===`advanced`&&(0,Y.jsx)(ue,{embeddingModel:d.embedding_model,embeddingModels:g,onEmbeddingModelChange:e=>M(`embedding_model`,e)})]})]}),(0,Y.jsx)(me,{submitting:C,lastSaved:ee,onCancel:n,onSave:U})]})]})},Ce=a(`components:persona-import-export`),we=({personas:e,onImport:t,onClose:n})=>{let{t:r}=s(),[i,a]=(0,J.useState)(!1),[o,c]=(0,J.useState)(``),l=async e=>{try{let t=await q.exportPersona(e.id),n=new Blob([JSON.stringify(t,null,2)],{type:`application/json`}),i=URL.createObjectURL(n),a=document.createElement(`a`);a.href=i,a.download=`${e.name}.json`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i),b.success(r(`personaImportExport.exportSuccess`,{name:e.name}))}catch(e){let t=e instanceof Error?e.message:String(e);b.error(r(`personaImportExport.exportFailed`)+`: `+t)}};return(0,Y.jsxs)(`div`,{className:`max-w-4xl mx-auto`,children:[(0,Y.jsxs)(`div`,{className:`mb-6`,children:[(0,Y.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-dark-800`,children:r(`personaImportExport.title`)}),(0,Y.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 mt-1`,children:r(`personaImportExport.description`)})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-6`,children:[(0,Y.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-6 shadow-xs border border-gray-200 dark:border-dark-300`,children:[(0,Y.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 mb-4`,children:r(`personaImportExport.exportPersonas`)}),e.length===0?(0,Y.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 text-center py-8`,children:r(`personaImportExport.noPersonasToExport`)}):(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:r(`personaImportExport.personasAvailable`,{count:e.length})}),(0,Y.jsx)(R,{onClick:async()=>{try{let t=e.map(e=>q.exportPersona(e.id)),n=await Promise.all(t),i={personas:n,exportedAt:Date.now(),version:`1.0.0`,count:n.length},a=new Blob([JSON.stringify(i,null,2)],{type:`application/json`}),o=URL.createObjectURL(a),s=document.createElement(`a`);s.href=o,s.download=`personas-export-${new Date().toISOString().split(`T`)[0]}.json`,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(o),b.success(r(`personaImportExport.exportAllSuccess`,{count:e.length}))}catch(e){let t=e instanceof Error?e.message:String(e);b.error(r(`personaImportExport.exportAllFailed`)+`: `+t)}},variant:`outline`,size:`sm`,className:`px-3 py-1`,children:r(`personaImportExport.exportAll`)})]}),(0,Y.jsx)(`div`,{className:`space-y-2 max-h-80 overflow-y-auto`,children:e.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-gray-50 dark:bg-dark-200 rounded-md`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`img`,{src:ie(e,32),alt:e.name,className:`w-8 h-8 rounded-full`,onError:t=>W(t.currentTarget,e.name,32)}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`font-medium text-gray-900 dark:text-dark-800`,children:e.name}),(0,Y.jsx)(`div`,{className:`text-sm text-gray-500 dark:text-dark-500`,children:e.model})]})]}),(0,Y.jsx)(R,{onClick:()=>l(e),variant:`outline`,size:`sm`,className:`px-3 py-1`,children:r(`common.export`)})]},e.id))})]})]}),(0,Y.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-6 shadow-xs border border-gray-200 dark:border-dark-300`,children:[(0,Y.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 mb-4`,children:r(`personaImportExport.importPersonas`)}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:r(`personaImportExport.uploadJsonFile`)}),(0,Y.jsx)(`input`,{type:`file`,accept:`.json`,onChange:e=>{let t=e.target.files?.[0];if(t){let e=new FileReader;e.onload=e=>{let t=e.target?.result;typeof t==`string`&&c(t)},e.readAsText(t)}},className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-700`})]}),(0,Y.jsx)(`div`,{className:`text-center text-gray-500 dark:text-dark-500`,children:r(`common.or`).toUpperCase()}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:r(`personaImportExport.pasteJsonLabel`)}),(0,Y.jsx)(`textarea`,{value:o,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-700`,rows:8,placeholder:r(`personaImportExport.pasteJsonPlaceholder`)})]}),(0,Y.jsx)(R,{onClick:async()=>{if(!o.trim()){b.error(r(`personaImportExport.pasteJsonData`));return}a(!0);try{let e=JSON.parse(o);if(e.personas&&Array.isArray(e.personas)){let t=0,n=0;for(let r of e.personas)try{await q.importPersona(r),t++}catch(e){n++,Ce.error(`Failed to import persona:`,e)}t>0?(b.success(r(`personaImportExport.importMultipleSuccess`,{count:t})),n>0&&b.error(r(`personaImportExport.importMultipleFailed`,{count:n}))):b.error(r(`personaImportExport.importNoneFailed`))}else await q.importPersona(e),b.success(r(`personaImportExport.importSuccess`));c(``),t()}catch(e){let t=e instanceof Error?e.message:String(e);b.error(r(`personaImportExport.importFailed`)+`: `+t)}finally{a(!1)}},disabled:!o.trim()||i,className:`w-full`,children:r(i?`personaImportExport.importing`:`personaImportExport.importButton`)})]})]})]}),(0,Y.jsxs)(`div`,{className:`mt-6 bg-gray-50 dark:bg-dark-200 rounded-lg p-4`,children:[(0,Y.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-dark-800 mb-2`,children:r(`personaImportExport.expectedFormat`)}),(0,Y.jsx)(`pre`,{className:`text-xs text-gray-600 dark:text-dark-600 overflow-x-auto`,children:`{
2
+ "name": "Assistant Name",
3
+ "description": "Brief description of the assistant's personality",
4
+ "model": "model-name:version",
5
+ "params": {
6
+ "temperature": 0.8,
7
+ "top_p": 0.9,
8
+ "context_window": 4096,
9
+ "system_prompt": "You are a helpful assistant with specific traits..."
10
+ },
11
+ "avatar": "/path/to/avatar.png",
12
+ "background": "/path/to/background.png"
13
+ }`})]}),(0,Y.jsx)(`div`,{className:`mt-6 flex justify-end`,children:(0,Y.jsx)(R,{onClick:n,variant:`outline`,children:r(`common.close`)})})]})},Te=()=>{let{t:e}=s(),t=r(),[n,a]=(0,J.useState)(!1),[o,c]=(0,J.useState)(null),[l,u]=(0,J.useState)(!1),{data:d=[],isLoading:f,isError:p,refetch:m}=i({queryKey:[`personas`],queryFn:async()=>{let e=await q.getPersonas();if(!e.success)throw Error(e.error||`Failed to load personas`);return e.data||[]}}),h=async()=>{await t.invalidateQueries({queryKey:[`personas`]}),await m()},g=()=>{c(null),a(!0)},_=e=>{c(e),a(!0)},v=async t=>{if(confirm(e(`personaManager.deleteConfirm`,{name:t.name})))try{let n=await q.deletePersona(t.id);n.success?(b.success(e(`personaManager.deleteSuccess`,{name:t.name})),await h()):b.error(e(`personaManager.deleteFailed`)+`: `+n.error)}catch(t){let n=t instanceof Error?t.message:String(t);b.error(e(`personaManager.deleteFailed`)+`: `+n)}},y=async t=>{try{await q.downloadPersona(t.id,t.name),b.success(e(`personaManager.downloadSuccess`,{name:t.name}))}catch(t){let n=t instanceof Error?t.message:String(t);b.error(e(`personaManager.downloadFailed`)+`: `+n)}};return f?(0,Y.jsx)(z,{label:e(`personaManager.loading`)}):n?(0,Y.jsx)(Se,{persona:o,onSubmit:async e=>{c(e),await h()},onCancel:()=>{a(!1),c(null)}}):l?(0,Y.jsx)(we,{personas:d,onImport:h,onClose:()=>u(!1)}):(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`text-sm text-gray-500 dark:text-dark-500`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-gray-900 dark:text-dark-800`,children:e(`personaManager.stats.title`)}),` `,`· `,e(`personaManager.stats.count`,{count:d.length})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsx)(R,{onClick:()=>u(!0),variant:`outline`,className:`px-4`,children:e(`personaManager.importExport`)}),(0,Y.jsx)(R,{onClick:g,className:`px-4`,children:e(`personaManager.createButton`)})]})]}),p&&d.length===0?(0,Y.jsx)(U,{message:e(`personaManager.loadFailed`),onRetry:()=>void m()}):d.length===0?(0,Y.jsx)(V,{icon:N,titleAs:`h3`,title:e(`personaManager.empty.title`),description:e(`personaManager.empty.description`),action:(0,Y.jsx)(R,{onClick:g,className:`px-6 py-2`,children:e(`personaManager.empty.button`)})}):(0,Y.jsx)(`div`,{className:`grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3`,children:d.map(e=>(0,Y.jsx)(le,{persona:e,onEdit:_,onDelete:v,onDownload:y},e.id))})]})},Ee=()=>{let{t:e}=s();return(0,Y.jsxs)(H,{children:[(0,Y.jsx)(B,{title:e(`personaManager.title`),description:e(`personaManager.subtitle`)}),(0,Y.jsx)(Te,{})]})};export{Ee as PersonasPage,Ee 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"./useQuery-BTKpXudI.js";import{t as i}from"./useTranslation-Boi0fB1B.js";import{t as a}from"./utils-B-Bhh1pF.js";import{An as o,Cr as s,Dr as c,Gn as l,Q as u,Rt as d,Vn as f,Y as p,dr as m,er as h,g,s as _,tt as v,un as y,v as b}from"./ui-vendor-6S05F84J.js";import{t as x}from"./Button-Dh2UJA-B.js";import{o as S,s as C}from"./ui-CI0OdG9q.js";import{t as w}from"./client-jaxZzn-I.js";import{u as T}from"./api-Dcz1G4Ib.js";var E=e(t(),1),D={getAnalytics:e=>w.get(`/costs/analytics`,{params:{days:e}}).then(e=>e.data),listTariffs:()=>w.get(`/costs/tariffs`).then(e=>e.data),createTariff:e=>w.post(`/costs/tariffs`,e).then(e=>e.data),deleteTariff:e=>w.delete(`/costs/tariffs/${encodeURIComponent(e)}`).then(()=>void 0),listBudgets:()=>w.get(`/costs/budgets`).then(e=>e.data),createBudget:e=>w.post(`/costs/budgets`,e).then(e=>e.data),deleteBudget:e=>w.delete(`/costs/budgets/${encodeURIComponent(e)}`).then(()=>void 0),exportUrl:e=>`/api/costs/export?days=${e}`,exportCsv:e=>w.get(`/costs/export`,{params:{days:e},responseType:`blob`}).then(e=>e.data)},O=n(),k=e=>new Intl.NumberFormat(void 0,{style:`currency`,currency:`USD`,maximumFractionDigits:e<1?4:2}).format(e),A=`w-full rounded-lg border border-gray-300 bg-white px-2 py-1.5 text-sm dark:border-dark-300 dark:bg-dark-50`,j=({days:e})=>{let{t}=i(),[n,r]=(0,E.useState)(null),[a,s]=(0,E.useState)([]),[l,u]=(0,E.useState)([]),[f,p]=(0,E.useState)(!0),[m,h]=(0,E.useState)(0),[g,_]=(0,E.useState)({pluginId:``,model:``,inputPerMillion:``,outputPerMillion:``,unitPrice:``}),[y,S]=(0,E.useState)({name:``,principalType:`instance`,principalId:``,period:`monthly`,amountUsd:``,mode:`soft`});(0,E.useEffect)(()=>{let n=!1;return Promise.all([D.getAnalytics(e),D.listTariffs(),D.listBudgets()]).then(([e,t,i])=>{n||(e.success&&e.data&&r(e.data),t.success&&t.data&&s(t.data),i.success&&i.data&&u(i.data))}).catch(()=>c.error(t(`costs.loadFailed`))).finally(()=>{n||p(!1)}),()=>{n=!0}},[e,m,t]);let C=e=>{if(!e.trim())return;let t=Number(e);return Number.isFinite(t)?t:void 0},w=async()=>{try{let e=await D.createTariff({pluginId:g.pluginId.trim(),model:g.model.trim()||void 0,inputPerMillion:C(g.inputPerMillion),outputPerMillion:C(g.outputPerMillion),unitPrice:C(g.unitPrice)});if(!e.success)throw Error(e.message);c.success(t(`costs.tariffSaved`)),_({pluginId:``,model:``,inputPerMillion:``,outputPerMillion:``,unitPrice:``}),h(e=>e+1)}catch(e){c.error(e instanceof Error?e.message:t(`costs.saveFailed`))}},T=async()=>{try{let e=await D.createBudget({name:y.name.trim(),principalType:y.principalType,principalId:y.principalType===`instance`?void 0:y.principalId.trim(),period:y.period,amountUsd:Number(y.amountUsd),mode:y.mode});if(!e.success)throw Error(e.message);c.success(t(`costs.budgetSaved`)),S({name:``,principalType:`instance`,principalId:``,period:`monthly`,amountUsd:``,mode:`soft`}),h(e=>e+1)}catch(e){c.error(e instanceof Error?e.message:t(`costs.saveFailed`))}},j=async()=>{try{let t=await D.exportCsv(e),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`libre-webui-costs.csv`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}catch{c.error(t(`costs.exportFailed`))}};return f&&!n?(0,O.jsx)(`div`,{className:`flex justify-center rounded-lg border border-gray-200 bg-white p-6 dark:border-dark-300 dark:bg-dark-100`,children:(0,O.jsx)(d,{className:`h-5 w-5 animate-spin text-gray-400`})}):(0,O.jsxs)(`div`,{className:`space-y-4 rounded-lg border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,"data-testid":`cost-governance-panel`,children:[(0,O.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:t(`costs.title`)}),(0,O.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:t(`costs.description`)})]}),(0,O.jsxs)(x,{size:`sm`,variant:`outline`,onClick:()=>void j(),children:[(0,O.jsx)(o,{className:`mr-1 h-3.5 w-3.5`}),t(`costs.exportCsv`)]})]}),n&&(0,O.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:[(0,O.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,O.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.totalSpend`)}),(0,O.jsx)(`p`,{className:`text-lg font-semibold`,children:k(n.totalUsd)})]}),(0,O.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,O.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.meteredEvents`)}),(0,O.jsx)(`p`,{className:`text-lg font-semibold`,children:n.meteredEvents})]}),(0,O.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,O.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.unmeteredEvents`)}),(0,O.jsx)(`p`,{className:`text-lg font-semibold`,children:n.unmeteredEvents})]}),(0,O.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,O.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.topModel`)}),(0,O.jsx)(`p`,{className:`truncate text-sm font-medium`,children:n.byModel[0]?`${n.byModel[0].model} (${k(n.byModel[0].usd)})`:`—`})]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-gray-500`,children:t(`costs.budgets`)}),(0,O.jsxs)(`div`,{className:`space-y-2`,children:[n?.budgets.map(e=>{let n=Math.min(1,e.spentUsd/e.amountUsd);return(0,O.jsxs)(`div`,{className:`rounded-lg border border-gray-200 p-2 dark:border-dark-300`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-sm`,children:[(0,O.jsxs)(`span`,{className:`min-w-0 truncate font-medium`,children:[e.name,(0,O.jsxs)(`span`,{className:`ml-2 text-xs font-normal text-gray-500`,children:[t(`costs.mode.${e.mode}`),` ·`,` `,t(`costs.period.${e.period}`),` ·`,` `,e.principalType===`instance`?t(`costs.scope.instance`):`${t(`costs.scope.${e.principalType}`)}: ${e.principalId}`]})]}),(0,O.jsxs)(`span`,{className:`shrink-0 text-xs text-gray-600 dark:text-gray-300`,children:[k(e.spentUsd),` / `,k(e.amountUsd)]}),(0,O.jsx)(`button`,{onClick:()=>{D.deleteBudget(e.id).then(()=>h(e=>e+1)).catch(()=>c.error(t(`costs.saveFailed`)))},className:`shrink-0 rounded-sm p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-950/30`,"aria-label":t(`costs.deleteBudget`),children:(0,O.jsx)(b,{className:`h-3.5 w-3.5`})})]}),(0,O.jsx)(`div`,{className:`mt-1 h-1.5 overflow-hidden rounded-sm bg-gray-200 dark:bg-dark-300`,children:(0,O.jsx)(`div`,{className:n>=1?`h-full bg-red-500`:n>=.8?`h-full bg-amber-500`:`h-full bg-emerald-500`,style:{width:`${Math.round(n*100)}%`}})})]},e.id)}),l.length===0&&(0,O.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.noBudgets`)})]}),(0,O.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-2 sm:grid-cols-6`,children:[(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.budgetName`),value:y.name,onChange:e=>S({...y,name:e.target.value})}),(0,O.jsxs)(`select`,{className:A,value:y.principalType,onChange:e=>S({...y,principalType:e.target.value}),children:[(0,O.jsx)(`option`,{value:`instance`,children:t(`costs.scope.instance`)}),(0,O.jsx)(`option`,{value:`user`,children:t(`costs.scope.user`)}),(0,O.jsx)(`option`,{value:`group`,children:t(`costs.scope.group`)})]}),(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.principalId`),value:y.principalId,disabled:y.principalType===`instance`,onChange:e=>S({...y,principalId:e.target.value})}),(0,O.jsxs)(`select`,{className:A,value:y.period,onChange:e=>S({...y,period:e.target.value}),children:[(0,O.jsx)(`option`,{value:`daily`,children:t(`costs.period.daily`)}),(0,O.jsx)(`option`,{value:`weekly`,children:t(`costs.period.weekly`)}),(0,O.jsx)(`option`,{value:`monthly`,children:t(`costs.period.monthly`)})]}),(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsx)(`input`,{className:A,placeholder:`USD`,inputMode:`decimal`,value:y.amountUsd,onChange:e=>S({...y,amountUsd:e.target.value})}),(0,O.jsxs)(`select`,{className:A,value:y.mode,onChange:e=>S({...y,mode:e.target.value}),children:[(0,O.jsx)(`option`,{value:`observe`,children:t(`costs.mode.observe`)}),(0,O.jsx)(`option`,{value:`soft`,children:t(`costs.mode.soft`)}),(0,O.jsx)(`option`,{value:`hard`,children:t(`costs.mode.hard`)})]})]}),(0,O.jsxs)(x,{size:`sm`,onClick:()=>void T(),children:[(0,O.jsx)(v,{className:`mr-1 h-3.5 w-3.5`}),t(`costs.addBudget`)]})]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-gray-500`,children:t(`costs.tariffs`)}),(0,O.jsx)(`div`,{className:`overflow-x-auto`,children:(0,O.jsxs)(`table`,{className:`w-full text-left text-xs`,children:[(0,O.jsx)(`thead`,{className:`text-gray-500`,children:(0,O.jsxs)(`tr`,{children:[(0,O.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.plugin`)}),(0,O.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.model`)}),(0,O.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.inputPerMillion`)}),(0,O.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.outputPerMillion`)}),(0,O.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.unitPrice`)}),(0,O.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.effectiveFrom`)}),(0,O.jsx)(`th`,{})]})}),(0,O.jsxs)(`tbody`,{children:[a.map(e=>(0,O.jsxs)(`tr`,{className:`border-t border-gray-100 dark:border-dark-300`,children:[(0,O.jsx)(`td`,{className:`py-1 pr-2`,children:e.plugin_id}),(0,O.jsx)(`td`,{className:`py-1 pr-2`,children:e.model??t(`costs.allModels`)}),(0,O.jsx)(`td`,{className:`py-1 pr-2`,children:e.input_per_million===null?`—`:k(e.input_per_million)}),(0,O.jsx)(`td`,{className:`py-1 pr-2`,children:e.output_per_million===null?`—`:k(e.output_per_million)}),(0,O.jsx)(`td`,{className:`py-1 pr-2`,children:e.unit_price===null?`—`:k(e.unit_price)}),(0,O.jsx)(`td`,{className:`py-1 pr-2`,children:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}).format(e.effective_from)}),(0,O.jsx)(`td`,{className:`py-1`,children:(0,O.jsx)(`button`,{onClick:()=>{D.deleteTariff(e.id).then(()=>h(e=>e+1)).catch(()=>c.error(t(`costs.saveFailed`)))},className:`rounded-sm p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-950/30`,"aria-label":t(`costs.deleteTariff`),children:(0,O.jsx)(b,{className:`h-3.5 w-3.5`})})})]},e.id)),a.length===0&&(0,O.jsx)(`tr`,{children:(0,O.jsx)(`td`,{colSpan:7,className:`py-2 text-gray-500`,children:t(`costs.noTariffs`)})})]})]})}),(0,O.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-2 sm:grid-cols-6`,children:[(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.plugin`),value:g.pluginId,onChange:e=>_({...g,pluginId:e.target.value})}),(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.modelOptional`),value:g.model,onChange:e=>_({...g,model:e.target.value})}),(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.inputPerMillion`),inputMode:`decimal`,value:g.inputPerMillion,onChange:e=>_({...g,inputPerMillion:e.target.value})}),(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.outputPerMillion`),inputMode:`decimal`,value:g.outputPerMillion,onChange:e=>_({...g,outputPerMillion:e.target.value})}),(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.unitPrice`),inputMode:`decimal`,value:g.unitPrice,onChange:e=>_({...g,unitPrice:e.target.value})}),(0,O.jsxs)(x,{size:`sm`,onClick:()=>void w(),children:[(0,O.jsx)(v,{className:`mr-1 h-3.5 w-3.5`}),t(`costs.addTariff`)]})]})]})]})},M={strands:`Strands`,"claude-code":`Claude Code`,codex:`Codex`,opencode:`OpenCode`,pi:`Pi`},N=e=>{if(e.startsWith(`agent-cli:`))return e.slice(10)||void 0};function P(e){if(e.agents!==void 0)return e.agents;let t=new Map;for(let n of e.plugins){let e=N(n.pluginId);if(!e)continue;let r=t.get(e)??{agentId:e,agentName:M[e]??n.pluginName,calls:0,tokens:0,errors:0,averageLatencyMs:0,models:[]},i=r.calls+n.calls;r.averageLatencyMs=i?(r.averageLatencyMs*r.calls+n.averageLatencyMs*n.calls)/i:0,r.calls=i,r.tokens+=n.tokens,r.errors+=n.errors,t.set(e,r)}for(let n of e.models){let e=N(n.pluginId),r=e?t.get(e):void 0;if(!r)continue;let i=r.models.find(e=>e.model===n.model);i?(i.calls+=n.calls,i.tokens+=n.tokens,i.errors+=n.errors):r.models.push({model:n.model,calls:n.calls,tokens:n.tokens,errors:n.errors})}return[...t.values()]}var F=[`#3b82f6`,`#059669`,`#db683c`,`#8b5cf6`,`#e11d48`,`#0891b2`,`#a16207`,`#db2777`,`#0d9488`,`#6366f1`,`#65a30d`,`#a855f7`,`#4879a8`,`#9d6c34`,`#c25280`,`#6f7d35`,`#5363bb`],I=`#6b7280`,L=e=>{let t=e*137.508%360,n=e=>{let n=.65*Math.min(e,1-e);return[0,8,4].map(r=>{let i=(r+t/30)%12;return e-n*Math.max(-1,Math.min(i-3,9-i,1))})},r=0,i=1;for(let e=0;e<16;e++){let e=(r+i)/2,t=n(e).map(e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4);t[0]*.2126+t[1]*.7152+t[2]*.0722<.2?r=e:i=e}return`#${n((r+i)/2).map(e=>Math.round(e*255).toString(16).padStart(2,`0`)).join(``)}`},R=e=>e===null?`other`:`model:${e}`;function z(e,t){return e.range.from===t.range.from&&e.range.to===t.range.to&&e.series.length===t.series.length&&e.series.every((e,n)=>{let r=t.series[n];return e.timestamp===r.timestamp&&e.calls===r.calls&&e.tokens===r.tokens&&e.errors===r.errors})}function ee(e){return e.modelSeries?.length?e.modelSeries.map(e=>({...e,key:R(e.model)})):[{key:`total`,model:void 0,points:e.series}]}function te(e){let t=e.heatmap?.models??[],n=(e.modelSeries??[]).flatMap(e=>e.model===null?[]:[e.model]).filter(e=>!t.includes(e)).sort(),r=new Set([...t,...e.heatmap?.cells.flatMap(e=>e.models.map(e=>e.model))??[],...e.modelSeries?.flatMap(e=>e.model===null?[]:[e.model])??[],...e.models.map(e=>e.model)]),i=[...t,...n,...[...r].filter(e=>!t.includes(e)&&!n.includes(e)).sort()],a=new Map([[`other`,I],[`total`,I]]);return i.forEach((e,t)=>{a.set(R(e),F[t]??L(t))}),a}function ne(e,t,n,r){let i=e.models.filter(e=>e.pluginId===t&&(r===void 0||e.pluginName===r)&&e.calls>0).map(({model:e,calls:t})=>({model:e,calls:t})),a=n-i.reduce((e,t)=>e+t.calls,0);return a>0?[...i,{model:null,calls:a}]:i}function re({analytics:e,metric:t,onMetricChange:n,colors:r,highlighted:o,selected:s,loadingModel:c,canLoadModels:l=!1,onHighlight:u,onSelect:d}){let{t:f,i18n:m}=i(),g=(0,E.useMemo)(()=>ee(e),[e]),_=(0,E.useRef)(null),[v,y]=(0,E.useState)(960),[b,x]=(0,E.useState)();(0,E.useEffect)(()=>{let e=_.current;if(!e)return;let t=new ResizeObserver(e=>{y(Math.max(280,e[0].contentRect.width))});return t.observe(e),()=>t.disconnect()},[]);let S=(e,t=!1)=>new Intl.NumberFormat(m.language,{notation:t&&e>=1e4?`compact`:`standard`,maximumFractionDigits:+!!t}).format(e),C=new Intl.DateTimeFormat(m.language,{month:`short`,day:`numeric`,timeZone:`UTC`}),w=e=>e===void 0?f(`usageAnalytics.activity.allModels`):e===null?f(`usageAnalytics.heatmap.other`):e||`—`,T={top:18,right:20,bottom:32,left:48},D=v-T.left-T.right,k=260-T.top-T.bottom,A=Math.max(1,...g.flatMap(e=>e.points.map(e=>e[t]))),j=Math.ceil(A/4)*4,M=e.series.reduce((e,n)=>e+n[t],0),N=t===`tokens`&&M===0,P=t=>T.left+(e.series.length<=1?D/2:t/(e.series.length-1)*D),F=e=>T.top+k-e/j*k,I=e.series.findIndex(e=>e.timestamp===b),L=I<0?Math.max(0,e.series.length-1):I,R=e.series[L],z=g.find(e=>e.key===o),te=[...new Set([0,Math.floor((e.series.length-1)/2),e.series.length-1])].filter(e=>e>=0),ne=g.map(e=>({...e,value:e.points[L]?.[t]??0})).sort((e,t)=>t.value-e.value),re=e=>e.map((e,n)=>`${n===0?`M`:`L`} ${P(n)} ${F(e[t])}`).join(` `);return(0,O.jsxs)(`section`,{"data-testid":`plugin-usage-chart`,"aria-busy":c!==void 0,className:`min-w-0 overflow-hidden rounded-2xl border border-gray-200/80 bg-white/80 shadow-subtle dark:border-white/8 dark:bg-dark-100/75`,children:[(0,O.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3 border-b border-gray-200/70 px-4 py-4 dark:border-white/[0.07] sm:px-5`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:f(`usageAnalytics.activity.title`)}),(0,O.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:f(`usageAnalytics.activity.${t===`calls`?`callsDescription`:`tokensDescription`}`)})]}),(0,O.jsx)(`div`,{className:`inline-flex rounded-xl bg-gray-100 p-1 dark:bg-dark-200/80`,children:[`calls`,`tokens`].map(e=>(0,O.jsx)(`button`,{type:`button`,"aria-pressed":t===e,className:a(`min-h-9 rounded-lg px-3 text-xs font-medium focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500`,t===e?`bg-white text-gray-950 shadow-xs dark:bg-dark-300 dark:text-dark-950`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),onClick:()=>n(e),children:f(`usageAnalytics.metrics.${e}`)},e))})]}),(0,O.jsxs)(`div`,{className:`px-4 pt-4 sm:px-5`,children:[(0,O.jsxs)(`div`,{className:`mb-3 flex min-h-8 flex-wrap items-center justify-between gap-2`,children:[(0,O.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:f(`usageAnalytics.activity.compareHint`)}),(0,O.jsxs)(`button`,{type:`button`,disabled:!s&&!o,className:a(`inline-flex min-h-9 items-center gap-1.5 rounded-lg px-2 text-xs font-medium text-gray-700 hover:bg-gray-100 focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-primary-500 dark:text-dark-800 dark:hover:bg-dark-200`,!s&&!o&&`invisible`),onClick:()=>{d(void 0),u(void 0)},children:[(0,O.jsx)(p,{className:`h-3.5 w-3.5`}),f(`usageAnalytics.activity.showAll`)]})]}),(0,O.jsx)(`div`,{"data-testid":`usage-model-legend`,className:a(`grid gap-2 sm:grid-cols-2 lg:grid-cols-3`,l&&`h-48 content-start overflow-y-auto pe-1`),children:g.map(e=>{let n=o===e.key,i=s===e.key,c=r.get(e.key)??`#6b7280`,l=e.points.reduce((e,n)=>e+n[t],0);return(0,O.jsxs)(`button`,{type:`button`,"aria-pressed":i,"aria-label":w(e.model),title:w(e.model),onMouseEnter:()=>u(e.key),onMouseLeave:()=>u(void 0),onFocus:()=>u(e.key),onBlur:()=>u(void 0),onClick:()=>d(i?void 0:e.key),className:a(`flex min-h-11 min-w-0 items-center gap-2.5 rounded-xl border px-3 py-2 text-start focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500`,n?`border-gray-400 bg-gray-50 dark:border-dark-500 dark:bg-dark-200`:`border-gray-200/70 hover:bg-gray-50 dark:border-white/[0.07] dark:hover:bg-dark-200/70`),children:[(0,O.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-full`,style:{backgroundColor:c},"aria-hidden":`true`}),(0,O.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs font-medium text-gray-800 dark:text-dark-900`,dir:`auto`,children:w(e.model)}),(0,O.jsx)(`span`,{className:`shrink-0 text-xs tabular-nums text-gray-500 dark:text-dark-500`,children:S(l,!0)}),i&&(0,O.jsx)(h,{className:`h-3.5 w-3.5 shrink-0 text-gray-800 dark:text-dark-900`,"aria-hidden":`true`})]},e.key)})}),(l||g.some(e=>e.model===null))&&(0,O.jsx)(`p`,{className:`mt-2 text-[11px] text-gray-500 dark:text-dark-500`,children:f(`usageAnalytics.activity.topModels`)}),g[0]?.model===void 0&&(0,O.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:f(`usageAnalytics.activity.breakdownUnavailable`)})]}),(0,O.jsx)(`div`,{className:`relative mx-3 mt-4 sm:mx-5`,ref:_,children:N?(0,O.jsx)(`div`,{className:`flex h-[260px] items-center justify-center text-sm text-gray-500 dark:text-dark-500`,children:f(`usageAnalytics.activity.noTokens`)}):(0,O.jsxs)(`svg`,{viewBox:`0 0 ${v} 260`,direction:`ltr`,className:`block h-[260px] w-full touch-pan-y`,role:`img`,"aria-label":f(`usageAnalytics.activity.chartLabel`,{metric:f(`usageAnalytics.metrics.${t}`)}),onPointerMove:t=>{let n=t.currentTarget.getBoundingClientRect(),r=(t.clientX-n.left)*v/n.width,i=Math.round(Math.max(0,Math.min(1,(r-T.left)/D))*(e.series.length-1));e.series[i]&&x(e.series[i].timestamp)},children:[(0,O.jsx)(`title`,{children:f(`usageAnalytics.activity.chartLabel`,{metric:f(`usageAnalytics.metrics.${t}`)})}),[0,.25,.5,.75,1].map(e=>{let t=T.top+k*e;return(0,O.jsxs)(`g`,{children:[(0,O.jsx)(`line`,{x1:T.left,x2:v-T.right,y1:t,y2:t,className:`stroke-gray-200 dark:stroke-white/[0.07]`,strokeDasharray:e===1?void 0:`3 6`}),(0,O.jsx)(`text`,{x:T.left-9,y:t+4,textAnchor:`end`,className:`fill-gray-500 text-[11px] dark:fill-dark-500`,children:S(Math.round(j*(1-e)),!0)})]},e)}),R&&(0,O.jsx)(`line`,{x1:P(L),x2:P(L),y1:T.top,y2:260-T.bottom,className:`stroke-gray-300 dark:stroke-dark-400`,strokeDasharray:`3 4`}),[...g].sort((e,t)=>Number(e.key===o)-Number(t.key===o)).map(e=>{let n=e.key===o,i=r.get(e.key)??`#6b7280`,a=e.points[L];return(0,O.jsxs)(`g`,{opacity:o&&!n?.18:1,children:[(0,O.jsx)(`path`,{"data-testid":`usage-model-line`,"data-model":e.model===void 0?`__total__`:e.model??`__other__`,"data-highlighted":n,d:re(e.points),stroke:i,fill:`none`,strokeWidth:n?3.5:2,strokeDasharray:e.model===null?`6 4`:void 0,strokeLinecap:`round`,strokeLinejoin:`round`,vectorEffect:`non-scaling-stroke`,children:(0,O.jsx)(`title`,{children:w(e.model)})}),a&&(0,O.jsx)(`circle`,{cx:P(L),cy:F(a[t]),r:n?5:3.5,fill:i,className:`stroke-white dark:stroke-dark-100`,strokeWidth:`2`})]},e.key)}),te.map(t=>(0,O.jsx)(`text`,{x:P(t),y:252,textAnchor:t===0?`start`:t===e.series.length-1?`end`:`middle`,className:`fill-gray-500 text-[11px] dark:fill-dark-500`,children:C.format(e.series[t].timestamp)},t))]})}),R&&(0,O.jsxs)(`div`,{className:`border-t border-gray-200/70 px-4 py-4 dark:border-white/[0.07] sm:px-5`,children:[(0,O.jsxs)(`label`,{className:`mb-2 flex flex-wrap items-center justify-between gap-2 text-xs text-gray-500 dark:text-dark-500`,children:[(0,O.jsx)(`span`,{children:f(`usageAnalytics.activity.exploreDay`)}),(0,O.jsx)(`span`,{className:`text-gray-800 dark:text-dark-800`,children:C.format(R.timestamp)}),(0,O.jsx)(`input`,{"data-testid":`usage-chart-day-slider`,type:`range`,min:0,max:Math.max(0,e.series.length-1),step:1,value:L,"aria-label":f(`usageAnalytics.activity.exploreDay`),"aria-valuetext":C.format(R.timestamp),onChange:t=>x(e.series[Number(t.target.value)]?.timestamp),className:`h-6 w-full cursor-pointer accent-gray-700 focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-primary-500 dark:accent-gray-300`,dir:`ltr`})]}),(0,O.jsxs)(`div`,{"data-testid":`usage-chart-day-detail`,"aria-live":`polite`,"aria-atomic":`true`,children:[(0,O.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-baseline justify-between gap-2`,children:[(0,O.jsxs)(`span`,{className:`text-xs font-medium text-gray-700 dark:text-dark-800`,children:[f(`usageAnalytics.activity.dayTotal`),` ·`,` `,C.format(R.timestamp)]}),(0,O.jsxs)(`span`,{className:`text-sm font-medium tabular-nums text-gray-950 dark:text-dark-950`,children:[S(R[t]),` `,f(`usageAnalytics.metrics.${t}`)]})]}),(0,O.jsx)(`div`,{className:a(`grid gap-x-5 gap-y-2 sm:grid-cols-2 lg:grid-cols-3`,l&&`max-h-40 overflow-y-auto`),children:ne.map(e=>(0,O.jsxs)(`div`,{"data-model":e.model===void 0?`__total__`:e.model??`__other__`,className:a(`flex min-w-0 items-center gap-2 text-xs`,o===e.key&&`font-medium`),children:[(0,O.jsx)(`span`,{"aria-hidden":`true`,className:`h-2 w-2 shrink-0 rounded-full`,style:{backgroundColor:r.get(e.key)??`#6b7280`}}),(0,O.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-gray-600 dark:text-dark-700`,title:w(e.model),dir:`auto`,children:w(e.model)}),(0,O.jsx)(`span`,{className:`shrink-0 tabular-nums text-gray-900 dark:text-dark-900`,children:S(e.value)})]},e.key))}),(0,O.jsx)(`p`,{className:`mt-3 h-4 truncate text-xs font-medium text-gray-600 dark:text-dark-700`,children:c===void 0?z?f(`usageAnalytics.activity.highlightedModel`,{model:w(z.model)}):f(`usageAnalytics.activity.allModels`):f(`usageAnalytics.activity.loadingModel`,{model:c})})]})]})]})}var B=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),V=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1}),H=e=>e>=1e4?V.format(e):B.format(e),U=e=>e?e<1e3?`${B.format(e)} ms`:`${(e/1e3).toFixed(+(e<1e4))} s`:`—`,W=(e,t)=>e===0?0:(e-t)/e*100,G=864e5,K=10,q=12,J=30,Y=16,ie=`fill-gray-950/6 dark:fill-white/[0.07]`,ae=[0,.35,.55,.75,1],oe=({heatmap:e,colors:t,chartModels:n,focusedModel:r})=>{let{t:o,i18n:s}=i(),[c,l]=(0,E.useState)(null),u=[...new Set([...e.models,...n])],d=e=>e!==void 0&&(u.includes(e)||e===r)?t.get(R(e))??`#6b7280`:I,{weeks:f,firstColStart:p,cellsByDay:m,maxCalls:h,totalCalls:g}=(0,E.useMemo)(()=>{let t=new Map(e.cells.map(e=>[e.timestamp,e])),n=e.from,r=e.from+(e.days-1)*G,i=n-new Date(n).getUTCDay()*G;return{weeks:Math.ceil((r-i+G)/(7*G)),firstColStart:i,cellsByDay:t,maxCalls:Math.max(1,...e.cells.map(e=>e.calls)),totalCalls:e.cells.reduce((e,t)=>e+t.calls,0)}},[e]),_=new Intl.DateTimeFormat(s.language,{month:`short`,timeZone:`UTC`}),v=new Intl.DateTimeFormat(s.language,{weekday:`short`,timeZone:`UTC`}),y=new Intl.DateTimeFormat(s.language,{dateStyle:`medium`,timeZone:`UTC`}),b=e.from,x=e.from+(e.days-1)*G,S=J+f*q,C=[],w=-1;for(let e=0;e<f;e++){let t=p+e*7*G,n=Math.max(t,b),r=new Date(n).getUTCMonth();r!==w&&t>=b-6*G&&((w!==-1||t>=b)&&C.push({x:J+e*q,label:_.format(n)}),w=r)}let T=e=>e<=0?0:Math.min(4,Math.max(1,Math.ceil(e/h*4))),D=e=>d(e.models[0]?.model),k=(e,t,n)=>{let r=e.currentTarget.closest(`[data-heatmap-wrapper]`);if(!r)return;let i=r.getBoundingClientRect(),a=e.currentTarget.getBoundingClientRect(),o=a.left-i.left+a.width/2;l({x:Math.min(Math.max(o,96),Math.max(i.width-96,96)),y:a.top-i.top,timestamp:t,calls:n.calls,models:n.models})};return(0,O.jsxs)(`section`,{"data-testid":`usage-heatmap`,className:`min-w-0 overflow-hidden rounded-2xl border border-gray-200/80 bg-white/80 shadow-subtle backdrop-blur-md dark:border-white/8 dark:bg-dark-100/75`,children:[(0,O.jsxs)(`div`,{className:`flex flex-col gap-1 border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.07] sm:flex-row sm:items-center sm:justify-between sm:px-5`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:o(`usageAnalytics.heatmap.title`)}),(0,O.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:o(`usageAnalytics.heatmap.description`)})]}),(0,O.jsx)(`span`,{className:`shrink-0 text-xs tabular-nums text-gray-500 dark:text-dark-500`,children:o(`usageAnalytics.heatmap.yearTotal`,{count:g,formatted:H(g)})})]}),(0,O.jsxs)(`div`,{className:`relative p-4 sm:px-5`,"data-heatmap-wrapper":!0,children:[(0,O.jsx)(`div`,{className:`overflow-x-auto`,children:(0,O.jsxs)(`svg`,{viewBox:`0 0 ${S} 100`,direction:`ltr`,className:`h-auto w-full min-w-[640px]`,role:`img`,"aria-label":o(`usageAnalytics.heatmap.title`),onMouseLeave:()=>l(null),children:[C.map(({x:e,label:t})=>(0,O.jsx)(`text`,{x:e,y:10,className:`fill-gray-400 text-[8px] dark:fill-dark-500`,children:t},`${e}-${t}`)),[1,3,5].map(e=>(0,O.jsx)(`text`,{x:0,y:Y+e*q+K-2,className:`fill-gray-400 text-[8px] dark:fill-dark-500`,children:v.format(new Date(Date.UTC(2023,0,1+e)))},e)),Array.from({length:f},(e,t)=>Array.from({length:7},(e,n)=>{let r=p+(t*7+n)*G;if(r<b||r>x)return null;let i=m.get(r),o=i?.calls??0,s=T(o);return(0,O.jsx)(`rect`,{x:J+t*q,y:Y+n*q,width:K,height:K,rx:2,"data-model":i?.models[0]?.model,fill:i&&s>0?D(i):void 0,fillOpacity:s===0?1:ae[s],strokeWidth:+(c?.timestamp===r),className:a(`motion-safe:transition-opacity`,(s===0||!i)&&ie,c?.timestamp===r?`stroke-gray-500 dark:stroke-white/60`:`stroke-transparent`),onMouseEnter:e=>k(e,r,{calls:o,models:i?.models??[]}),children:(0,O.jsx)(`title`,{children:`${y.format(r)} — ${H(o)}`})},r)}))]})}),c&&(0,O.jsxs)(`div`,{className:`pointer-events-none absolute z-10 min-w-40 -translate-x-1/2 -translate-y-full rounded-lg border border-gray-200/80 bg-white/95 px-3 py-2 shadow-card backdrop-blur-md dark:border-white/10 dark:bg-dark-100/95`,style:{left:c.x,top:c.y-6},children:[(0,O.jsx)(`div`,{className:`text-[11px] font-medium text-gray-900 dark:text-dark-900`,children:y.format(c.timestamp)}),(0,O.jsx)(`div`,{className:`mt-0.5 text-[11px] text-gray-500 dark:text-dark-500`,children:c.calls===0?o(`usageAnalytics.heatmap.noCalls`):`${H(c.calls)} ${o(`usageAnalytics.heatmap.calls`)}`}),c.models.slice(0,3).map(e=>(0,O.jsxs)(`div`,{className:`mt-1 flex items-center justify-between gap-3 text-[11px]`,children:[(0,O.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,O.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-[3px]`,style:{backgroundColor:d(e.model)}}),(0,O.jsx)(`span`,{className:`truncate font-mono text-gray-700 dark:text-dark-700`,dir:`ltr`,children:e.model})]}),(0,O.jsx)(`span`,{className:`tabular-nums text-gray-500 dark:text-dark-500`,children:H(e.calls)})]},e.model))]}),(0,O.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center justify-between gap-3`,children:[(0,O.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5`,children:[u.map(e=>(0,O.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-gray-600 dark:text-dark-600`,children:[(0,O.jsx)(`span`,{className:`h-2.5 w-2.5 rounded-[3px]`,style:{backgroundColor:t.get(R(e))??`#6b7280`}}),(0,O.jsx)(`span`,{className:`font-mono`,dir:`ltr`,children:e})]},e)),(0,O.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-gray-600 dark:text-dark-600`,children:[(0,O.jsx)(`span`,{className:`h-2.5 w-2.5 rounded-[3px]`,style:{backgroundColor:I}}),o(`usageAnalytics.heatmap.other`)]})]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] text-gray-500 dark:text-dark-500`,children:[o(`usageAnalytics.heatmap.less`),(0,O.jsx)(`span`,{className:`h-2.5 w-2.5 rounded-[3px] bg-gray-950/6 dark:bg-white/[0.07]`}),ae.slice(1).map(e=>(0,O.jsx)(`span`,{className:`h-2.5 w-2.5 rounded-[3px] bg-gray-500`,style:{opacity:e}},e)),o(`usageAnalytics.heatmap.more`)]})]})]})]})},se=({analytics:e})=>{let{t}=i(),n=P(e),r=e=>(e.meteredCalls??0)>0||e.tokens>0;return(0,O.jsxs)(`section`,{"data-testid":`usage-agent-breakdown`,"aria-labelledby":`usage-agent-heading`,className:`rounded-2xl border border-gray-200/80 bg-white/80 p-4 shadow-subtle dark:border-white/8 dark:bg-dark-100/75 sm:p-5`,children:[(0,O.jsxs)(`h2`,{id:`usage-agent-heading`,className:`flex items-center gap-2 text-sm font-medium text-gray-950 dark:text-dark-950`,children:[(0,O.jsx)(m,{className:`h-4 w-4`,"aria-hidden":`true`}),t(`usageAnalytics.agents.title`)]}),(0,O.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.agents.description`)}),e.agents===void 0&&(0,O.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.agents.legacy`)}),(0,O.jsx)(`div`,{className:`mt-4 grid min-w-0 gap-3 sm:grid-cols-2 xl:grid-cols-3`,children:n.map(e=>(0,O.jsxs)(`article`,{"data-agent":e.agentId,className:`min-w-0 rounded-xl border border-gray-200/70 p-3 dark:border-white/[0.07]`,children:[(0,O.jsx)(`h3`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e.agentName}),(0,O.jsxs)(`dl`,{className:`mt-3 grid grid-cols-2 gap-3`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`dt`,{className:`text-[11px] text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.metrics.calls`)}),(0,O.jsx)(`dd`,{"data-agent-metric":`calls`,className:`mt-1 text-lg tabular-nums text-gray-950 dark:text-dark-950`,children:H(e.calls)})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`dt`,{className:`text-[11px] text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.cards.tokens`)}),(0,O.jsx)(`dd`,{"data-agent-metric":`tokens`,className:`mt-1 text-sm tabular-nums text-gray-950 dark:text-dark-950`,children:r(e)?H(e.tokens):e.calls===0?`—`:e.meteredCalls===0?t(`usageAnalytics.agents.unreported`):`—`})]})]}),e.calls===0?(0,O.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.agents.noCalls`)}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:[t(`usageAnalytics.cards.latency`),`:`,` `,(0,O.jsx)(`span`,{className:`tabular-nums`,dir:`ltr`,children:U(e.averageLatencyMs)})]}),e.meteredCalls!==void 0&&e.meteredCalls>0&&(0,O.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.cards.tokensDetail`,{count:e.meteredCalls})}),e.errors>0&&(0,O.jsxs)(`p`,{className:`mt-2 flex items-center gap-1 text-xs text-gray-600 dark:text-dark-600`,children:[(0,O.jsx)(g,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),t(`usageAnalytics.providers.failures`,{count:e.errors})]}),e.models.length>0&&(0,O.jsxs)(`div`,{className:`mt-3`,children:[(0,O.jsx)(`h4`,{className:`text-xs font-medium text-gray-700 dark:text-dark-700`,children:t(`usageAnalytics.agents.topModels`)}),(0,O.jsx)(`div`,{className:`mt-1 max-h-48 overflow-y-auto`,children:(0,O.jsxs)(`table`,{className:`w-full table-fixed text-start text-xs`,children:[(0,O.jsx)(`thead`,{className:`text-gray-500 dark:text-dark-500`,children:(0,O.jsxs)(`tr`,{children:[(0,O.jsx)(`th`,{className:`w-1/2 py-1 text-start font-normal`,children:t(`usageAnalytics.models.model`)}),(0,O.jsx)(`th`,{className:`px-1 py-1 text-end font-normal`,children:t(`usageAnalytics.metrics.calls`)}),(0,O.jsx)(`th`,{className:`py-1 text-end font-normal`,children:t(`usageAnalytics.metrics.tokens`)})]})}),(0,O.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-white/6`,children:e.models.map(e=>(0,O.jsxs)(`tr`,{"data-agent-model":e.model,children:[(0,O.jsx)(`td`,{className:`wrap-break-word py-1.5 pe-2 text-gray-700 dark:text-dark-700`,children:(0,O.jsx)(`span`,{dir:`auto`,children:e.model})}),(0,O.jsx)(`td`,{className:`px-1 py-1.5 text-end tabular-nums`,children:H(e.calls)}),(0,O.jsx)(`td`,{className:`py-1.5 text-end tabular-nums`,children:r(e)?H(e.tokens):`—`})]},e.model))})]})})]})]})]},e.agentId))})]})},X=()=>{let{t:e}=i(),[t,n]=(0,E.useState)(30),[o,c]=(0,E.useState)(`calls`),[p,h]=(0,E.useState)(),[v,b]=(0,E.useState)(),{data:w,error:D,isLoading:k,isFetching:A,refetch:M}=r({queryKey:[`plugin-usage`,t],refetchInterval:2e4,refetchIntervalInBackground:!1,queryFn:async()=>{let n=await T.getUsage(t);if(!n.success||!n.data)throw Error(n.error||e(`usageAnalytics.loadFailed`));return n.data}}),N=(0,E.useMemo)(()=>new Set(w?ee(w).map(e=>e.key):[]),[w]),P=(0,E.useMemo)(()=>new Set([...N,...w?.models.map(e=>R(e.model))??[]]),[N,w]),F=p&&P.has(p)?p:void 0,I=v&&P.has(v)?v:void 0,L=N.has(`other`),B=(L?[I,F].find(e=>e?.startsWith(`model:`)&&!N.has(e)):void 0)?.slice(6),V=r({queryKey:[`plugin-usage`,t,`model`,B,w?.range.to],enabled:B!==void 0,staleTime:3e4,queryFn:async()=>{let n=await T.getUsage(t,B,w?.range.to);if(!n.success||!n.data)throw Error(n.error||e(`usageAnalytics.loadFailed`));return n.data}}),G=w,K=!!w&&!!V.data&&z(w,V.data),q=(0,E.useMemo)(()=>w&&B!==void 0&&K?{...w,modelSeries:V.data.modelSeries}:w,[w,B,K,V.data]),J=(0,E.useRef)(null);(0,E.useEffect)(()=>{B!==void 0&&V.data&&!K&&!A&&J.current!==V.data&&(J.current=V.data,M())},[B,V.data,K,A,M]);let Y=D??(B===void 0?null:V.error),ie=Y?Y instanceof Error?Y.message:e(`usageAnalytics.loadFailed`):null,ae=B!==void 0&&!K&&!Y?B:void 0,X=(0,E.useMemo)(()=>w?te(w):new Map,[w]),ce=(0,E.useMemo)(()=>new Set(q?ee(q).map(e=>e.key):[]),[q]),Z=I??F,le=e=>h(e),Q=e=>{if(w?.modelSeries?.length&&(e!==null||N.has(`other`)))return R(e)},$=G?.totals,ue=(0,E.useMemo)(()=>[{label:e(`usageAnalytics.cards.calls`),value:H($?.calls??0),detail:e(`usageAnalytics.cards.callsDetail`,{count:$?.uniqueUsers??0}),icon:s},{label:e(`usageAnalytics.cards.tokens`),value:H($?.reportedTokens??0),detail:e(`usageAnalytics.cards.coverage`,{percent:$?.calls?($.meteredCalls/$.calls*100).toFixed(1):`0`}),icon:y},{label:e(`usageAnalytics.cards.success`),value:`${W($?.calls??0,($?.failedCalls??0)+($?.cancelledCalls??0)).toFixed(1)}%`,detail:e(`usageAnalytics.cards.successDetail`,{count:$?.failedCalls??0}),icon:l},{label:e(`usageAnalytics.cards.latency`),value:U($?.averageLatencyMs??0),detail:e(`usageAnalytics.cards.latencyDetail`),icon:f}],[e,$]);return k&&!G?(0,O.jsx)(C,{width:`wide`,children:(0,O.jsxs)(`div`,{role:`status`,className:`flex min-h-[50vh] items-center justify-center`,children:[(0,O.jsx)(d,{className:`h-7 w-7 motion-safe:animate-spin text-primary-500`}),(0,O.jsx)(`span`,{className:`sr-only`,children:e(`common.loading`)})]})}):(0,O.jsxs)(C,{width:`wide`,children:[(0,O.jsx)(S,{eyebrow:e(`usageAnalytics.eyebrow`),title:e(`usageAnalytics.title`),description:e(`usageAnalytics.description`),actions:(0,O.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,O.jsx)(`div`,{className:`inline-flex rounded-xl border border-gray-200 bg-white/70 p-1 dark:border-white/8 dark:bg-dark-100/70`,children:[7,30,90].map(r=>(0,O.jsx)(`button`,{type:`button`,className:a(`min-h-9 rounded-lg px-3 py-1.5 text-xs font-medium motion-safe:transition-colors focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-primary-500`,t===r?`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`),"aria-pressed":t===r,onClick:()=>{n(r),b(void 0)},children:e(`usageAnalytics.days`,{count:r})},r))}),(0,O.jsxs)(x,{variant:`outline`,size:`sm`,onClick:()=>{M(),B!==void 0&&V.refetch()},disabled:A||B!==void 0&&V.isFetching,children:[(0,O.jsx)(u,{className:a(`h-4 w-4`,A&&`motion-safe:animate-spin`)}),(0,O.jsx)(`span`,{children:e(`usageAnalytics.refresh`)})]})]})}),ie&&(0,O.jsxs)(`div`,{role:`alert`,className:`mb-6 flex items-center gap-3 rounded-2xl border border-error-200 bg-error-50 px-4 py-3 text-sm text-error-700 dark:border-error-900/40 dark:bg-error-900/30 dark:text-error-300`,children:[(0,O.jsx)(g,{className:`h-4 w-4 shrink-0`}),(0,O.jsx)(`span`,{children:ie})]}),!G&&(0,O.jsx)(j,{days:t}),G&&(0,O.jsxs)(`div`,{className:`min-w-0 space-y-4`,children:[(0,O.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-4`,children:ue.map(e=>{let t=e.icon;return(0,O.jsxs)(`section`,{className:`rounded-2xl border border-gray-200/80 bg-white/75 p-4 shadow-subtle backdrop-blur-md dark:border-white/8 dark:bg-dark-100/70`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,O.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-[0.12em] text-gray-500 dark:text-dark-500`,children:e.label}),(0,O.jsx)(t,{className:`h-4 w-4 text-primary-500 dark:text-primary-400`})]}),(0,O.jsx)(`div`,{className:`mt-2 text-2xl font-normal tracking-[-0.04em] text-gray-950 dark:text-dark-950`,children:e.value}),(0,O.jsx)(`p`,{className:`mt-1.5 text-xs text-gray-500 dark:text-dark-500`,children:e.detail})]},e.label)})}),(0,O.jsx)(se,{analytics:G}),(0,O.jsx)(j,{days:t}),G.heatmap&&G.heatmap.cells.length>0&&(0,O.jsx)(oe,{heatmap:G.heatmap,colors:X,focusedModel:Z?.startsWith(`model:`)?Z.slice(6):void 0,chartModels:(w?.modelSeries??[]).flatMap(e=>e.model===null?[]:[e.model])}),(0,O.jsx)(re,{analytics:q??G,metric:o,onMetricChange:c,colors:X,highlighted:Z,selected:F,onHighlight:b,onSelect:le,loadingModel:ae,canLoadModels:L}),G.totals.calls===0?(0,O.jsxs)(`div`,{className:`rounded-2xl border border-dashed border-gray-300 px-6 py-10 text-center dark:border-white/12`,children:[(0,O.jsx)(m,{className:`mx-auto h-8 w-8 text-gray-400 dark:text-dark-500`}),(0,O.jsx)(`h2`,{className:`mt-4 text-base font-medium text-gray-900 dark:text-dark-900`,children:e(`usageAnalytics.empty.title`)}),(0,O.jsx)(`p`,{className:`mx-auto mt-2 max-w-md text-sm leading-6 text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.empty.description`)})]}):(0,O.jsxs)(`div`,{className:`grid min-w-0 gap-4 xl:grid-cols-[minmax(0,1.15fr)_minmax(0,0.85fr)]`,children:[(0,O.jsxs)(`section`,{className:`min-w-0 overflow-hidden rounded-2xl border border-gray-200/80 bg-white/80 shadow-subtle backdrop-blur-md dark:border-white/8 dark:bg-dark-100/75`,children:[(0,O.jsxs)(`div`,{className:`border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.07] sm:px-5`,children:[(0,O.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e(`usageAnalytics.models.title`)}),(0,O.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.models.description`)})]}),(0,O.jsx)(`div`,{className:`overflow-x-auto`,children:(0,O.jsxs)(`table`,{"data-testid":`usage-model-table`,className:`w-full min-w-[620px] text-start text-sm`,children:[(0,O.jsx)(`thead`,{className:`text-[11px] uppercase tracking-widest text-gray-400 dark:text-dark-500`,children:(0,O.jsxs)(`tr`,{children:[(0,O.jsx)(`th`,{className:`px-5 py-2 text-start font-medium`,children:e(`usageAnalytics.models.model`)}),(0,O.jsx)(`th`,{className:`px-4 py-2 text-end font-medium`,children:e(`usageAnalytics.metrics.calls`)}),(0,O.jsx)(`th`,{className:`px-4 py-2 text-end font-medium`,children:e(`usageAnalytics.metrics.tokens`)}),(0,O.jsx)(`th`,{className:`px-4 py-2 text-end font-medium`,children:e(`usageAnalytics.models.success`)}),(0,O.jsx)(`th`,{className:`px-5 py-2 text-end font-medium`,children:e(`usageAnalytics.models.latency`)})]})}),(0,O.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-white/6`,children:G.models.map(t=>(0,O.jsxs)(`tr`,{"data-testid":`usage-model-row`,"data-model":t.model,"data-highlighted":Z===Q(t.model),onMouseEnter:()=>b(Q(t.model)),onMouseLeave:()=>b(void 0),className:a(Z===Q(t.model)&&Z&&`bg-gray-50 dark:bg-dark-200/70`),children:[(0,O.jsxs)(`td`,{className:`px-5 py-2.5`,children:[(0,O.jsxs)(`button`,{type:`button`,disabled:!Q(t.model),"aria-label":e(`usageAnalytics.activity.highlightModel`,{model:t.model}),"aria-pressed":!!F&&F===Q(t.model),className:`flex min-h-9 max-w-[260px] items-center gap-2 rounded-md text-start font-medium text-gray-900 focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500 dark:text-dark-900`,title:ce.has(R(t.model))?t.model:e(`usageAnalytics.models.notCharted`),onFocus:()=>b(Q(t.model)),onBlur:()=>b(void 0),onClick:()=>le(F===Q(t.model)?void 0:Q(t.model)),children:[(0,O.jsx)(`span`,{"aria-hidden":`true`,className:`h-2.5 w-2.5 shrink-0 rounded-full`,style:{backgroundColor:X.get(R(t.model))??`#6b7280`}}),(0,O.jsx)(`span`,{className:`truncate`,dir:`ltr`,children:t.model})]}),(0,O.jsx)(`div`,{className:`mt-0.5 text-xs text-gray-500 dark:text-dark-500`,children:t.pluginName})]}),(0,O.jsxs)(`td`,{className:`px-4 py-2.5 text-end tabular-nums text-gray-700 dark:text-dark-700`,children:[H(t.calls),(0,O.jsxs)(`div`,{className:`mt-1 text-[11px] text-gray-500 dark:text-dark-500`,title:e(`usageAnalytics.models.share`),children:[(t.calls/G.totals.calls*100).toFixed(1),`%`]})]}),(0,O.jsx)(`td`,{className:`px-4 py-2.5 text-end tabular-nums text-gray-700 dark:text-dark-700`,children:t.tokens?H(t.tokens):`—`}),(0,O.jsxs)(`td`,{className:`px-4 py-2.5 text-end tabular-nums text-gray-700 dark:text-dark-700`,children:[W(t.calls,t.errors).toFixed(1),`%`]}),(0,O.jsx)(`td`,{className:`px-5 py-2.5 text-end tabular-nums text-gray-500 dark:text-dark-500`,children:U(t.averageLatencyMs)})]},JSON.stringify([t.pluginId,t.pluginName,t.model])))})]})})]}),(0,O.jsxs)(`div`,{className:`min-w-0 space-y-4`,children:[(0,O.jsxs)(`section`,{"data-testid":`usage-provider-breakdown`,className:`min-w-0 rounded-2xl border border-gray-200/80 bg-white/80 p-4 shadow-subtle dark:border-white/8 dark:bg-dark-100/75 sm:p-5`,children:[(0,O.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e(`usageAnalytics.providers.title`)}),(0,O.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.providers.description`)}),(0,O.jsx)(`div`,{className:`mt-4 divide-y divide-gray-200/70 dark:divide-white/[0.07]`,children:G.plugins.map(t=>{let n=G.totals.calls?t.calls/G.totals.calls*100:0,r=ne(G,t.pluginId,t.calls,t.pluginName);return(0,O.jsxs)(`article`,{"data-provider":t.pluginId,className:`py-4 first:pt-0 last:pb-0`,children:[(0,O.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,O.jsxs)(`div`,{className:`min-w-0`,children:[(0,O.jsx)(`h3`,{className:`truncate text-sm font-medium text-gray-900 dark:text-dark-900`,title:t.pluginName,children:t.pluginName}),(0,O.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.providers.share`,{percent:n.toFixed(1)})})]}),(0,O.jsxs)(`div`,{className:`shrink-0 text-end`,children:[(0,O.jsx)(`div`,{className:`text-base font-medium tabular-nums text-gray-950 dark:text-dark-950`,children:H(t.calls)}),(0,O.jsx)(`div`,{className:`text-[11px] text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.metrics.calls`)})]})]}),(0,O.jsx)(`div`,{className:`my-3 flex h-2 overflow-hidden rounded-full bg-gray-100 dark:bg-dark-300`,"aria-hidden":`true`,children:r.map(n=>(0,O.jsx)(`span`,{"data-model":n.model??`__other__`,title:`${n.model??e(`usageAnalytics.heatmap.other`)}: ${H(n.calls)}`,style:{width:`${t.calls?n.calls/t.calls*100:0}%`,backgroundColor:X.get(R(n.model))??`#6b7280`,opacity:Z&&Z!==Q(n.model)?.25:1}},R(n.model)))}),(0,O.jsxs)(`dl`,{className:`grid grid-cols-3 gap-2`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`dt`,{className:`text-[10px] text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.metrics.tokens`)}),(0,O.jsx)(`dd`,{className:`mt-1 text-xs tabular-nums text-gray-800 dark:text-dark-800`,title:t.tokens?void 0:e(`usageAnalytics.providers.noTokens`),children:t.tokens?H(t.tokens):`—`})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`dt`,{className:`text-[10px] text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.models.success`)}),(0,O.jsxs)(`dd`,{className:`mt-1 text-xs tabular-nums text-gray-800 dark:text-dark-800`,children:[W(t.calls,t.errors).toFixed(1),`%`]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`dt`,{className:`text-[10px] text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.models.latency`)}),(0,O.jsx)(`dd`,{className:`mt-1 text-xs tabular-nums text-gray-800 dark:text-dark-800`,children:U(t.averageLatencyMs)})]})]}),t.errors>0&&(0,O.jsxs)(`p`,{className:`mt-2 flex items-center gap-1 text-[11px] text-gray-500 dark:text-dark-500`,children:[(0,O.jsx)(g,{className:`h-3 w-3`}),e(`usageAnalytics.providers.failures`,{count:t.errors})]}),(0,O.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:r.map(t=>{let n=Q(t.model),r=t.model??e(`usageAnalytics.heatmap.other`);return(0,O.jsxs)(`button`,{type:`button`,disabled:!n,"aria-label":e(`usageAnalytics.activity.highlightModel`,{model:r}),"aria-pressed":!!F&&F===n,title:r,onMouseEnter:()=>b(n),onMouseLeave:()=>b(void 0),onFocus:()=>b(n),onBlur:()=>b(void 0),onClick:()=>le(F===n?void 0:n),className:a(`flex min-h-8 min-w-0 max-w-full items-center gap-1.5 rounded-md border px-2 py-1 text-[11px] text-gray-600 focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-primary-500 dark:text-dark-700`,Z&&Z===n?`border-gray-400 bg-gray-50 dark:border-dark-500 dark:bg-dark-200`:`border-gray-200/70 dark:border-white/[0.07]`),children:[(0,O.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-full`,style:{backgroundColor:X.get(R(t.model))??`#6b7280`},"aria-hidden":`true`}),(0,O.jsx)(`span`,{className:`truncate`,dir:`auto`,children:r})]},R(t.model))})})]},JSON.stringify([t.pluginId,t.pluginName]))})})]}),(0,O.jsxs)(`section`,{className:`rounded-2xl border border-gray-200/80 bg-white/80 p-4 shadow-subtle backdrop-blur-md dark:border-white/8 dark:bg-dark-100/75 sm:p-5`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(_,{className:`h-4 w-4 text-primary-500 dark:text-primary-400`}),(0,O.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e(`usageAnalytics.capabilities.title`)})]}),(0,O.jsx)(`div`,{className:`mt-5 grid grid-cols-2 gap-3`,children:G.capabilities.map(t=>(0,O.jsxs)(`div`,{className:`rounded-xl bg-gray-50 px-3 py-2.5 dark:bg-dark-200/70`,children:[(0,O.jsx)(`div`,{className:`text-xs font-medium capitalize text-gray-500 dark:text-dark-500`,children:t.capability}),(0,O.jsx)(`div`,{className:`mt-1 text-xl text-gray-950 dark:text-dark-950`,children:H(t.calls)}),(0,O.jsx)(`div`,{className:`mt-1 text-[11px] text-gray-500 dark:text-dark-500`,children:t.capability===`tts`?e(`usageAnalytics.capabilities.characters`,{count:H(t.inputUnits)}):t.capability===`stt`?e(`usageAnalytics.capabilities.bytes`,{count:H(t.inputUnits)}):t.capability===`image`?e(`usageAnalytics.capabilities.images`,{count:H(t.outputUnits)}):t.capability===`video`?e(`usageAnalytics.capabilities.jobs`,{count:H(t.calls)}):t.capability===`embedding`?e(`usageAnalytics.capabilities.inputs`,{count:H(t.inputUnits)}):e(`usageAnalytics.capabilities.reportedTokens`,{count:H(t.tokens)})})]},t.capability))})]})]})]}),(0,O.jsx)(`p`,{className:`px-1 text-xs leading-5 text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.privacyNote`)})]})]})};export{X as default};
@@ -1,3 +1,3 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["js/markdownMath-CsfRQAcz.js","js/markdown-math-DxPfMKvO.js","js/markdown-core-Cyql92Hg.js","js/rolldown-runtime-hePW80VL.js","js/react-vendor-CR5VJ85Q.js","assets/markdown-math-DzFXvcrH.css","js/markdownHtml-KhS0cFNH.js","js/markdown-html-CUc2fCgY.js","js/OptimizedSyntaxHighlighter-B_BbHeO1.js","js/OptimizedSyntaxHighlighter-B0g8cxZQ.js","js/syntax-highlight-D7dQ5s5-.js"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-CR5VJ85Q.js";import{o as r}from"./logger-BR4forr_.js";import{t as i}from"./utils-B-Bhh1pF.js";import{t as a}from"./appStore-DkRdQQeY.js";import{a as o,i as s,n as c,r as l,s as u,t as d}from"./messageCodeStyles-CuQPkfEK.js";import{i as f,s as p}from"./markdown-core-Cyql92Hg.js";var m=e(t(),1),h=null,g=null,_=null,v=null,y=()=>_??=r(()=>import(`./markdownMath-CsfRQAcz.js`).then(e=>(h=e,e)),__vite__mapDeps([0,1,2,3,4,5])),b=()=>v??=r(()=>import(`./markdownHtml-KhS0cFNH.js`).then(e=>(g=e,e)),__vite__mapDeps([6,7,2,3,4])),x=e=>e.includes(`$`);function S(e){let{needsMath:t,needsHtml:n}=e,[,r]=m.useReducer(e=>e+1,0);return m.useEffect(()=>{if(!t||h)return;let e=!1;return y().then(()=>{e||r()}),()=>{e=!0}},[t]),m.useEffect(()=>{if(!n||g)return;let e=!1;return b().then(()=>{e||r()}),()=>{e=!0}},[n]),{math:t?h:null,html:n?g:null}}var C=n(),w=m.lazy(()=>r(()=>import(`./OptimizedSyntaxHighlighter-B_BbHeO1.js`),__vite__mapDeps([8,9,3,4,10,2])));function T({children:e,className:t}){return(0,C.jsx)(`pre`,{dir:`ltr`,className:i(l,`rounded-lg`,t),children:(0,C.jsx)(`code`,{children:e})})}var E=m.memo(({content:e,className:t,allowHtml:n=!1})=>{let r=a(e=>e.theme.mode!==`light`),l=m.useMemo(()=>u(e),[e]),{math:h,html:g}=S({needsMath:x(l),needsHtml:n}),_=m.useMemo(()=>h?[f,h.remarkMath]:[f],[h]),v=m.useMemo(()=>{let e=[];return g&&e.push(g.rehypeRaw,[g.rehypeSanitize,g.richContentSanitizeSchema]),h&&e.push([h.rehypeKatex,{strict:e=>e===`unknownSymbol`?`ignore`:`warn`}]),e},[g,h]);return(0,C.jsx)(`div`,{dir:`auto`,className:i(`prose prose-sm max-w-none dark:prose-invert prose-gray`,`[&_.katex-display]:overflow-x-auto [&_.katex-display]:overflow-y-hidden [&_.katex-display]:py-2`,`[&_.katex]:text-inherit`,t),children:(0,C.jsx)(p,{remarkPlugins:_,rehypePlugins:v,components:{code({className:e,children:t,node:n,...a}){let l=/language-([^\s]+)/.exec(e||``),u=String(t),f=u.replace(/\n$/,``),p=l?l[1]:null;return p||u.includes(`
3
- `)?(0,C.jsx)(o,{code:f,language:p,state:`complete`,children:(0,C.jsx)(`div`,{className:`overflow-x-auto`,children:(0,C.jsx)(m.Suspense,{fallback:(0,C.jsx)(T,{className:`!m-0 !rounded-none !border-none`,children:f}),children:(0,C.jsx)(w,{language:p||`text`,isDark:r,codeTheme:`night`,backgroundColor:r?d:c,borderRadius:0,customStyle:s,className:`!m-0 !rounded-none !border-none`,showLineNumbers:!0,children:f})})})}):(0,C.jsx)(`code`,{dir:`ltr`,className:i(`px-1.5 py-0.5 rounded-md bg-gray-100 dark:bg-dark-200 text-gray-800 dark:text-dark-800`,`font-mono text-[0.85em] border border-gray-200 dark:border-dark-300`,e),...a,children:t})},pre({children:e}){return(0,C.jsx)(C.Fragment,{children:e})},p({children:e,...t}){return(0,C.jsx)(`div`,{dir:`auto`,className:`mb-2.5 last:mb-0 leading-relaxed`,...t,children:e})},ul({children:e,...t}){return(0,C.jsx)(`ul`,{dir:`auto`,className:`list-disc list-inside mb-2.5 space-y-1 ps-4`,...t,children:e})},ol({children:e,...t}){return(0,C.jsx)(`ol`,{dir:`auto`,className:`list-decimal list-inside mb-2.5 space-y-1 ps-4`,...t,children:e})},li({children:e,...t}){return(0,C.jsx)(`li`,{dir:`auto`,className:`text-ink leading-relaxed`,...t,children:e})},blockquote({children:e,...t}){return(0,C.jsx)(`blockquote`,{dir:`auto`,className:`border-s-2 border-primary-400 dark:border-primary-500 bg-primary-25 dark:bg-primary-950/30 ps-3 py-2 my-3 rounded-e-lg italic text-ink`,...t,children:e})},h1({children:e,...t}){return(0,C.jsx)(`h1`,{dir:`auto`,className:`text-xl font-bold mb-3 mt-5 first:mt-0 text-ink border-b border-gray-200 dark:border-dark-300 pb-1.5`,...t,children:e})},h2({children:e,...t}){return(0,C.jsx)(`h2`,{dir:`auto`,className:`text-lg font-semibold mb-2 mt-5 first:mt-0 text-ink`,...t,children:e})},h3({children:e,...t}){return(0,C.jsx)(`h3`,{dir:`auto`,className:`text-base font-medium mb-2 mt-4 first:mt-0 text-ink`,...t,children:e})},table({children:e,node:t,...n}){return(0,C.jsx)(`div`,{className:i(`my-4 w-full overflow-x-auto rounded-xl border border-line bg-surface shadow-subtle`,`focus:outline-none focus-visible:ring-2 focus-visible:ring-primary-500/40`),tabIndex:0,children:(0,C.jsx)(`table`,{dir:`auto`,className:`w-full min-w-[42rem] border-separate border-spacing-0 text-start text-sm`,...n,children:e})})},thead({children:e,node:t,...n}){return(0,C.jsx)(`thead`,{className:`bg-surface-subtle`,...n,children:e})},tbody({children:e,node:t,...n}){return(0,C.jsx)(`tbody`,{...n,children:e})},tr({children:e,node:t,...n}){return(0,C.jsx)(`tr`,{className:`transition-colors hover:bg-black/[0.025] last:[&>td]:border-b-0 dark:hover:bg-white/[0.025]`,...n,children:e})},th({align:e,children:t,node:n,...r}){return(0,C.jsx)(`th`,{className:i(`border-b border-e border-line-strong px-3 py-2.5 align-bottom font-semibold text-ink last:border-e-0`,e===`center`?`text-center`:e===`right`?`text-right`:e===`left`?`text-left`:`text-start`),...r,children:t})},td({align:e,children:t,node:n,...r}){return(0,C.jsx)(`td`,{className:i(`min-w-40 border-b border-e border-line px-3 py-2.5 align-top leading-relaxed text-ink last:border-e-0`,e===`center`?`text-center`:e===`right`?`text-right`:e===`left`?`text-left`:`text-start`),...r,children:t})}},children:l})})});E.displayName=`RichMessageContent`;export{E as t};
2
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-CR5VJ85Q.js";import{o as r}from"./logger-BR4forr_.js";import{t as i}from"./utils-B-Bhh1pF.js";import{t as a}from"./appStore-0_qlwS8f.js";import{a as o,i as s,n as c,r as l,s as u,t as d}from"./messageCodeStyles-D3cWF9XO.js";import{i as f,s as p}from"./markdown-core-Cyql92Hg.js";var m=e(t(),1),h=null,g=null,_=null,v=null,y=()=>_??=r(()=>import(`./markdownMath-CsfRQAcz.js`).then(e=>(h=e,e)),__vite__mapDeps([0,1,2,3,4,5])),b=()=>v??=r(()=>import(`./markdownHtml-KhS0cFNH.js`).then(e=>(g=e,e)),__vite__mapDeps([6,7,2,3,4])),x=e=>e.includes(`$`);function S(e){let{needsMath:t,needsHtml:n}=e,[,r]=m.useReducer(e=>e+1,0);return m.useEffect(()=>{if(!t||h)return;let e=!1;return y().then(()=>{e||r()}),()=>{e=!0}},[t]),m.useEffect(()=>{if(!n||g)return;let e=!1;return b().then(()=>{e||r()}),()=>{e=!0}},[n]),{math:t?h:null,html:n?g:null}}var C=n(),w=m.lazy(()=>r(()=>import(`./OptimizedSyntaxHighlighter-B_BbHeO1.js`),__vite__mapDeps([8,9,3,4,10,2])));function T({children:e,className:t}){return(0,C.jsx)(`pre`,{dir:`ltr`,className:i(l,`rounded-lg`,t),children:(0,C.jsx)(`code`,{children:e})})}var E=m.memo(({content:e,className:t,allowHtml:n=!1})=>{let r=a(e=>e.theme.mode!==`light`),l=m.useMemo(()=>u(e),[e]),{math:h,html:g}=S({needsMath:x(l),needsHtml:n}),_=m.useMemo(()=>h?[f,h.remarkMath]:[f],[h]),v=m.useMemo(()=>{let e=[];return g&&e.push(g.rehypeRaw,[g.rehypeSanitize,g.richContentSanitizeSchema]),h&&e.push([h.rehypeKatex,{strict:e=>e===`unknownSymbol`?`ignore`:`warn`}]),e},[g,h]);return(0,C.jsx)(`div`,{dir:`auto`,className:i(`prose prose-sm max-w-none dark:prose-invert prose-gray`,`[&_.katex-display]:overflow-x-auto [&_.katex-display]:overflow-y-hidden [&_.katex-display]:py-2`,`[&_.katex]:text-inherit`,t),children:(0,C.jsx)(p,{remarkPlugins:_,rehypePlugins:v,components:{code({className:e,children:t,node:n,...a}){let l=/language-([^\s]+)/.exec(e||``),u=String(t),f=u.replace(/\n$/,``),p=l?l[1]:null;return p||u.includes(`
3
+ `)?(0,C.jsx)(o,{code:f,language:p,state:`complete`,children:(0,C.jsx)(`div`,{className:`overflow-x-auto`,children:(0,C.jsx)(m.Suspense,{fallback:(0,C.jsx)(T,{className:`m-0! rounded-none! border-none!`,children:f}),children:(0,C.jsx)(w,{language:p||`text`,isDark:r,codeTheme:`night`,backgroundColor:r?d:c,borderRadius:0,customStyle:s,className:`m-0! rounded-none! border-none!`,showLineNumbers:!0,children:f})})})}):(0,C.jsx)(`code`,{dir:`ltr`,className:i(`px-1.5 py-0.5 rounded-md bg-gray-100 dark:bg-dark-200 text-gray-800 dark:text-dark-800`,`font-mono text-[0.85em] border border-gray-200 dark:border-dark-300`,e),...a,children:t})},pre({children:e}){return(0,C.jsx)(C.Fragment,{children:e})},p({children:e,...t}){return(0,C.jsx)(`div`,{dir:`auto`,className:`mb-2.5 last:mb-0 leading-relaxed`,...t,children:e})},ul({children:e,...t}){return(0,C.jsx)(`ul`,{dir:`auto`,className:`list-disc list-inside mb-2.5 space-y-1 ps-4`,...t,children:e})},ol({children:e,...t}){return(0,C.jsx)(`ol`,{dir:`auto`,className:`list-decimal list-inside mb-2.5 space-y-1 ps-4`,...t,children:e})},li({children:e,...t}){return(0,C.jsx)(`li`,{dir:`auto`,className:`text-ink leading-relaxed`,...t,children:e})},blockquote({children:e,...t}){return(0,C.jsx)(`blockquote`,{dir:`auto`,className:`border-s-2 border-primary-400 dark:border-primary-500 bg-primary-25 dark:bg-primary-950/30 ps-3 py-2 my-3 rounded-e-lg italic text-ink`,...t,children:e})},h1({children:e,...t}){return(0,C.jsx)(`h1`,{dir:`auto`,className:`text-xl font-bold mb-3 mt-5 first:mt-0 text-ink border-b border-gray-200 dark:border-dark-300 pb-1.5`,...t,children:e})},h2({children:e,...t}){return(0,C.jsx)(`h2`,{dir:`auto`,className:`text-lg font-semibold mb-2 mt-5 first:mt-0 text-ink`,...t,children:e})},h3({children:e,...t}){return(0,C.jsx)(`h3`,{dir:`auto`,className:`text-base font-medium mb-2 mt-4 first:mt-0 text-ink`,...t,children:e})},table({children:e,node:t,...n}){return(0,C.jsx)(`div`,{className:i(`my-4 w-full overflow-x-auto rounded-xl border border-line bg-surface shadow-subtle`,`focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/40`),tabIndex:0,children:(0,C.jsx)(`table`,{dir:`auto`,className:`w-full min-w-2xl border-separate border-spacing-0 text-start text-sm`,...n,children:e})})},thead({children:e,node:t,...n}){return(0,C.jsx)(`thead`,{className:`bg-surface-subtle`,...n,children:e})},tbody({children:e,node:t,...n}){return(0,C.jsx)(`tbody`,{...n,children:e})},tr({children:e,node:t,...n}){return(0,C.jsx)(`tr`,{className:`transition-colors hover:bg-black/2.5 [&>td]:last:border-b-0 dark:hover:bg-white/2.5`,...n,children:e})},th({align:e,children:t,node:n,...r}){return(0,C.jsx)(`th`,{className:i(`border-b border-e border-line-strong px-3 py-2.5 align-bottom font-semibold text-ink last:border-e-0`,e===`center`?`text-center`:e===`right`?`text-right`:e===`left`?`text-left`:`text-start`),...r,children:t})},td({align:e,children:t,node:n,...r}){return(0,C.jsx)(`td`,{className:i(`min-w-40 border-b border-e border-line px-3 py-2.5 align-top leading-relaxed text-ink last:border-e-0`,e===`center`?`text-center`:e===`right`?`text-right`:e===`left`?`text-left`:`text-start`),...r,children:t})},a({children:e,node:t,href:n,...r}){let i=!!n&&!n?.startsWith(`#`);return(0,C.jsx)(`a`,{...r,href:n,...i?{target:`_blank`,rel:`noopener noreferrer`}:{},className:`text-primary-600 underline decoration-primary-600/30 underline-offset-2 transition-colors hover:decoration-current dark:text-primary-400 dark:decoration-primary-400/40`,children:e})}},children:l})})});E.displayName=`RichMessageContent`;export{E as t};
@@ -0,0 +1 @@
1
+ import{t as e}from"./RichMessageContent-BLI0hhzR.js";export{e as RichMessageContent,e as default};