libre-webui 0.34.0 → 0.34.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/backend/dist/index.d.ts.map +1 -1
  2. package/backend/dist/index.js +20 -31
  3. package/backend/dist/index.js.map +1 -1
  4. package/backend/dist/middleware/cors.d.ts +12 -7
  5. package/backend/dist/middleware/cors.d.ts.map +1 -1
  6. package/backend/dist/middleware/cors.js +27 -26
  7. package/backend/dist/middleware/cors.js.map +1 -1
  8. package/backend/dist/middleware/preferencesBody.d.ts +4 -0
  9. package/backend/dist/middleware/preferencesBody.d.ts.map +1 -0
  10. package/backend/dist/middleware/preferencesBody.js +43 -0
  11. package/backend/dist/middleware/preferencesBody.js.map +1 -0
  12. package/backend/dist/routes/preferences.d.ts.map +1 -1
  13. package/backend/dist/routes/preferences.js +2 -1
  14. package/backend/dist/routes/preferences.js.map +1 -1
  15. package/backend/dist/services/preferencesService.d.ts.map +1 -1
  16. package/backend/dist/services/preferencesService.js +7 -10
  17. package/backend/dist/services/preferencesService.js.map +1 -1
  18. package/backend/dist/types/index.d.ts +1 -0
  19. package/backend/dist/types/index.d.ts.map +1 -1
  20. package/backend/dist/types/index.js.map +1 -1
  21. package/backend/dist/utils/backgroundSettings.d.ts +7 -0
  22. package/backend/dist/utils/backgroundSettings.d.ts.map +1 -0
  23. package/backend/dist/utils/backgroundSettings.js +39 -0
  24. package/backend/dist/utils/backgroundSettings.js.map +1 -0
  25. package/backend/package.json +3 -3
  26. package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
  27. package/frontend/dist/artifact-runtime/framer-motion.js +3 -3
  28. package/frontend/dist/artifact-runtime/lucide-react.js +1 -1
  29. package/frontend/dist/assets/index-C59a0tht.css +1 -0
  30. package/frontend/dist/assets/index-Cyi10ekV.js +43 -0
  31. package/frontend/dist/assets/{markdown-math-Ddr6Z9Sf.css → markdown-math-B3MBJsZb.css} +1 -1
  32. package/frontend/dist/index.html +22 -21
  33. package/frontend/dist/js/{ArtifactContainer-8ZacPNwg.js → ArtifactContainer-CQjqR9G1.js} +1 -1
  34. package/frontend/dist/js/{ArtifactDemoPage-DvvT45ZJ.js → ArtifactDemoPage-DbbqglMU.js} +1 -1
  35. package/frontend/dist/js/{ArtifactSandboxFrame-Dbp1bB_9.js → ArtifactSandboxFrame-DI2b9BW5.js} +1 -1
  36. package/frontend/dist/js/{ArtifactSlideOutPanel-Ct9nlG_6.js → ArtifactSlideOutPanel-B_UX92CK.js} +1 -1
  37. package/frontend/dist/js/{AutomationModal-Ie_MxC18.js → AutomationModal-CNiy1Dxm.js} +1 -1
  38. package/frontend/dist/js/{AutomationsPage-Czg-rMEr.js → AutomationsPage-CeAsldk_.js} +1 -1
  39. package/frontend/dist/js/{AvatarUpload-DgyIHr7P.js → AvatarUpload-xCWQm3_w.js} +1 -1
  40. package/frontend/dist/js/CalendarPage-Cwk0X00z.js +1 -0
  41. package/frontend/dist/js/ChannelsPage-BG3n4ElV.js +1 -0
  42. package/frontend/dist/js/ChatPage-wSRfAOeh.js +14 -0
  43. package/frontend/dist/js/{ConnectModels-Cg7Wp-43.js → ConnectModels-D7ZTGihA.js} +1 -1
  44. package/frontend/dist/js/{EvaluationsPage-BBafHC8o.js → EvaluationsPage-C795TI_6.js} +2 -2
  45. package/frontend/dist/js/{FirstTimeSetup-Cd9cLLz6.js → FirstTimeSetup-C4C5GLjW.js} +1 -1
  46. package/frontend/dist/js/{GalleryPage-6aa0A9fS.js → GalleryPage-DVWl3LaC.js} +1 -1
  47. package/frontend/dist/js/{HomePage-1vKjY6Aw.js → HomePage-BljB9ZMN.js} +1 -1
  48. package/frontend/dist/js/LanguageSwitcher-BuS3i6u5.js +1 -0
  49. package/frontend/dist/js/{LibreClawPage-DXxJP96Q.js → LibreClawPage-OD6iZtiy.js} +1 -1
  50. package/frontend/dist/js/ModelManagerModals-DdL3LeGl.js +1 -0
  51. package/frontend/dist/js/NotesPage-rqL0zS8z.js +3 -0
  52. package/frontend/dist/js/{PasswordStrengthMeter-DLQ5jaO_.js → PasswordStrengthMeter-H0Os6XbX.js} +1 -1
  53. package/frontend/dist/js/{PersonasPage-HYkaAXAe.js → PersonasPage-Babix8IA.js} +1 -1
  54. package/frontend/dist/js/{PluginUsagePage-B2MRIZme.js → PluginUsagePage-CudDkMxy.js} +1 -1
  55. package/frontend/dist/js/RichMessageContent-B-U0EcyW.js +1 -0
  56. package/frontend/dist/js/{RichMessageContent-BnpRgouz.js → RichMessageContent-CcKn_kcQ.js} +3 -3
  57. package/frontend/dist/js/SettingsModal-CXU60RIf.js +19 -0
  58. package/frontend/dist/js/{ShareDialog-BdFJRfxV.js → ShareDialog-CnU4ptx7.js} +1 -1
  59. package/frontend/dist/js/{SystemPage-DkKnu35i.js → SystemPage-BzpTjdQY.js} +1 -1
  60. package/frontend/dist/js/{UserManagementPage-DdpcN4-Q.js → UserManagementPage-BHEMaK5a.js} +1 -1
  61. package/frontend/dist/js/{UserManagementPanel-Dpn15Nyr.js → UserManagementPanel-pbtLqF8X.js} +1 -1
  62. package/frontend/dist/js/{WhatsNewModal-BH-kE-Wb.js → WhatsNewModal-TuDrBWKj.js} +1 -1
  63. package/frontend/dist/js/WorkPage-DCeqm0BN.js +7 -0
  64. package/frontend/dist/js/api-BIVGtaZy.js +1 -0
  65. package/frontend/dist/js/{api-HgGU3dII.js → api-CgnEj5Jc.js} +1 -1
  66. package/frontend/dist/js/{appNavigation-DAd7SkU_.js → appNavigation-DySHcEGS.js} +1 -1
  67. package/frontend/dist/js/appStore-DrTsJPfh.js +2 -0
  68. package/frontend/dist/js/appVersion-CAidQlBP.js +1 -0
  69. package/frontend/dist/js/{ar-CM3oZcHT.js → ar-DNI77Stn.js} +1 -1
  70. package/frontend/dist/js/authStore-CieFdk4S.js +4 -0
  71. package/frontend/dist/js/authStore-GaOHAAsM.js +1 -0
  72. package/frontend/dist/js/{bn-BuYroL_j.js → bn-u6oyZr4U.js} +1 -1
  73. package/frontend/dist/js/{chatStore-DYm9cXVV.js → chatStore-BvZkd8Un.js} +3 -3
  74. package/frontend/dist/js/composerStyles-BjJm_BgC.js +1 -0
  75. package/frontend/dist/js/{config-BH2zUU2X.js → config-D7WLbWrW.js} +1 -1
  76. package/frontend/dist/js/{cs-D3NqP5wD.js → cs-BIkJ6jwb.js} +1 -1
  77. package/frontend/dist/js/{da-BGpE68rg.js → da-DV3V6XJ_.js} +1 -1
  78. package/frontend/dist/js/{de-BjYUQYNL.js → de-DdcTQ-vn.js} +1 -1
  79. package/frontend/dist/js/{es-vNJrO8Lj.js → es-Cw-ozFaX.js} +1 -1
  80. package/frontend/dist/js/{evaluationsApi-v6Qj2fFv.js → evaluationsApi-Dn-WNzzH.js} +1 -1
  81. package/frontend/dist/js/{fr-BvtHFXNM.js → fr-Y2NfnlYR.js} +1 -1
  82. package/frontend/dist/js/{hi-CUfuHlbY.js → hi-BKU62_1Y.js} +1 -1
  83. package/frontend/dist/js/{i18next-ChipS_AK.js → i18next-Dq_6N9uy.js} +1 -1
  84. package/frontend/dist/js/{id-B4CE64s6.js → id-q6wo4InR.js} +1 -1
  85. package/frontend/dist/js/{is-Dr6Is7-Q.js → is-_B6QblCu.js} +1 -1
  86. package/frontend/dist/js/{it-Cj4NfoeU.js → it-NUupXhzK.js} +1 -1
  87. package/frontend/dist/js/{ja-DByiJVO0.js → ja-BUvl9RXq.js} +1 -1
  88. package/frontend/dist/js/{ko-DqBvZqIv.js → ko-df4leR83.js} +1 -1
  89. package/frontend/dist/js/markdownMath-BW8RNkEl.js +1 -0
  90. package/frontend/dist/js/{messageCodeStyles-ERvWXB7Y.js → messageCodeStyles-C0pbLr0L.js} +2 -2
  91. package/frontend/dist/js/{ms-DobJ-R5X.js → ms-CN-7Q9S2.js} +1 -1
  92. package/frontend/dist/js/{nl-D4tVIakl.js → nl-OEm4uNIo.js} +1 -1
  93. package/frontend/dist/js/{pl-BIoYiVJA.js → pl-B9pHpjg7.js} +1 -1
  94. package/frontend/dist/js/{pt-Bzww3XtB.js → pt-D3uaEKud.js} +1 -1
  95. package/frontend/dist/js/router-vendor-Epc3_KZ_.js +1 -0
  96. package/frontend/dist/js/{ru-lqQ-JuMd.js → ru-z9H07lhi.js} +1 -1
  97. package/frontend/dist/js/{sv-9dcksSEJ.js → sv-GkQDA4wx.js} +1 -1
  98. package/frontend/dist/js/{teamEventStream-CTyr4r5f.js → teamEventStream-CI_GSbae.js} +1 -1
  99. package/frontend/dist/js/{th-DuOX28lk.js → th-0hzCkDzt.js} +1 -1
  100. package/frontend/dist/js/{tr-Dz7bMTi1.js → tr-CZDobfHQ.js} +1 -1
  101. package/frontend/dist/js/ui-CgokQU6I.js +2 -0
  102. package/frontend/dist/js/ui-vendor-Dt9hfsGD.js +177 -0
  103. package/frontend/dist/js/{uk-aTAky5l4.js → uk-BwspIPCI.js} +1 -1
  104. package/frontend/dist/js/{useChat-CXcosgJB.js → useChat-DIGuMg5j.js} +1 -1
  105. package/frontend/dist/js/useDialogFocus-BQLdAGYH.js +1 -0
  106. package/frontend/dist/js/{vi-CHcYXhCs.js → vi-Dipdv5ta.js} +1 -1
  107. package/frontend/dist/js/{workApi-CntsmsAA.js → workApi-C-WfyZSs.js} +2 -2
  108. package/frontend/dist/js/workApi-CApikuye.js +1 -0
  109. package/frontend/dist/js/{zh-DvvksD8_.js → zh-CgdWmtP_.js} +1 -1
  110. package/package.json +8 -4
  111. package/frontend/dist/assets/index-By_-fwuh.css +0 -1
  112. package/frontend/dist/assets/index-D3XhYdgN.js +0 -108
  113. package/frontend/dist/js/CalendarPage-D1ZeHpZ0.js +0 -1
  114. package/frontend/dist/js/ChannelsPage-DgXZdSLa.js +0 -1
  115. package/frontend/dist/js/ChatPage-ov4Xlf8Q.js +0 -14
  116. package/frontend/dist/js/ModelManagerModals-BBGWbTTi.js +0 -1
  117. package/frontend/dist/js/NotesPage-DCLkl9a9.js +0 -3
  118. package/frontend/dist/js/RichMessageContent-2fzm0XIM.js +0 -1
  119. package/frontend/dist/js/SettingsModal-4ITUSJqi.js +0 -19
  120. package/frontend/dist/js/WorkPage-CCyCPnwr.js +0 -7
  121. package/frontend/dist/js/api-DOlirnw_.js +0 -1
  122. package/frontend/dist/js/appStore-DefVAJAx.js +0 -2
  123. package/frontend/dist/js/appVersion-RvElMU1Q.js +0 -1
  124. package/frontend/dist/js/authStore-AE-cc9PJ.js +0 -1
  125. package/frontend/dist/js/authStore-DbDFBMx0.js +0 -4
  126. package/frontend/dist/js/markdownMath-CoDj1i7z.js +0 -1
  127. package/frontend/dist/js/router-vendor-CMbYTGdh.js +0 -1
  128. package/frontend/dist/js/ui-CHgZA8lG.js +0 -2
  129. package/frontend/dist/js/ui-vendor-BvD5yGW1.js +0 -177
  130. package/frontend/dist/js/useDictation-BGlY44fp.js +0 -1
  131. package/frontend/dist/js/webauthnClient-B1yv1m81.js +0 -1
  132. package/frontend/dist/js/workApi-nKavXIsg.js +0 -1
  133. /package/frontend/dist/js/{markdown-math-Dg-WB9ui.js → markdown-math-gtdBxaM5.js} +0 -0
@@ -1,2 +1,2 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{t as r}from"./useTranslation-rdLmo6zV.js";import{t as i}from"./utils-CKWltgs8.js";import{t as a}from"./chatStore-DYm9cXVV.js";import{C as o,Ft as s,Tn as c,br as l,et as u,h as d,n as f,rt as p,v as m}from"./ui-vendor-BvD5yGW1.js";import{t as h}from"./Button-BxwbQ5xw.js";import{a as g,o as ee}from"./ui-CHgZA8lG.js";import{t as _}from"./evaluationsApi-v6Qj2fFv.js";var v=e(t(),1),y=n(),b=`w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50`,x=()=>{let{t:e}=r(),t=a(e=>e.models),n=a(e=>e.loadModels),[x,S]=(0,v.useState)(`arena`),[C,w]=(0,v.useState)(0),[T,E]=(0,v.useState)(``),[D,O]=(0,v.useState)(``),[k,A]=(0,v.useState)(``),[j,M]=(0,v.useState)(null),[N,P]=(0,v.useState)(!1),[F,I]=(0,v.useState)(!1),[L,R]=(0,v.useState)([]),[z,B]=(0,v.useState)([]),[V,H]=(0,v.useState)([]),[U,W]=(0,v.useState)([]),[G,K]=(0,v.useState)(``),[q,J]=(0,v.useState)(``),[Y,X]=(0,v.useState)(``);(0,v.useEffect)(()=>{n()},[n]),(0,v.useEffect)(()=>{let t=!1;return Promise.all([_.leaderboard(),_.listSets(),_.listRuns(),_.listFeedback()]).then(([e,n,r,i])=>{t||(e.success&&e.data&&R(e.data),n.success&&n.data&&B(n.data),r.success&&r.data&&H(r.data),i.success&&i.data&&W(i.data))}).catch(()=>l.error(e(`evaluations.loadFailed`))),()=>{t=!0}},[C,e]),(0,v.useEffect)(()=>{if(!V.some(e=>e.status===`queued`||e.status===`running`))return;let e=window.setInterval(()=>w(e=>e+1),4e3);return()=>window.clearInterval(e)},[V]);let Z=t.map(e=>e.name),Q=async()=>{if(!(!T.trim()||!D||!k||F)){I(!0),M(null),P(!1);try{let e=await _.runArenaMatch({prompt:T.trim(),modelA:D,modelB:k});if(!e.success||!e.data)throw Error(e.message||e.error);M(e.data)}catch(t){l.error(t instanceof Error?t.message:e(`evaluations.matchFailed`))}finally{I(!1)}}},$=async t=>{if(!(!j||N))try{let n=j.candidates.find(e=>e.key===`a`)?.model,r=j.candidates.find(e=>e.key===`b`)?.model;if(!n||!r)return;let i=await _.voteArena({compareGroup:j.compareGroup,modelA:n,modelB:r,winner:t});if(!i.success)throw Error(i.message);P(!0),w(e=>e+1),l.success(e(`evaluations.voteRecorded`))}catch(t){l.error(t instanceof Error?t.message:e(`evaluations.voteFailed`))}},te=async()=>{let t=q.split(`
2
- `).map(e=>e.trim()).filter(Boolean);if(!(!G.trim()||t.length===0))try{let n=await _.saveSet({name:G.trim(),items:t.map(e=>({prompt:e}))});if(!n.success)throw Error(n.message);K(``),J(``),w(e=>e+1),l.success(e(`evaluations.setSaved`))}catch(t){l.error(t instanceof Error?t.message:e(`evaluations.saveFailed`))}},ne=async t=>{if(!Y){l.error(e(`evaluations.pickModel`));return}try{let n=await _.startRun({setId:t,model:Y});if(!n.success)throw Error(n.message);w(e=>e+1),l.success(e(`evaluations.runStarted`))}catch(t){l.error(t instanceof Error?t.message:e(`evaluations.saveFailed`))}},re=async t=>{try{let e=await _.exportRun(t),n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=`eval-run-${t}.json`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}catch{l.error(e(`evaluations.exportFailed`))}},ie=[{id:`arena`,label:e(`evaluations.tabs.arena`)},{id:`leaderboard`,label:e(`evaluations.tabs.leaderboard`)},{id:`sets`,label:e(`evaluations.tabs.sets`)},{id:`feedback`,label:e(`evaluations.tabs.feedback`)}];return(0,y.jsxs)(ee,{width:`wide`,children:[(0,y.jsx)(g,{title:e(`evaluations.title`),description:e(`evaluations.description`)}),(0,y.jsx)(`div`,{className:`mb-4 inline-flex rounded-xl border border-gray-200 bg-white/70 p-1 dark:border-white/[0.08] dark:bg-dark-100/70`,children:ie.map(e=>(0,y.jsx)(`button`,{type:`button`,onClick:()=>S(e.id),className:i(`rounded-lg px-3 py-1.5 text-xs font-medium transition-colors`,x===e.id?`bg-gray-950 text-white dark:bg-white dark:text-gray-950`:`text-gray-500 hover:text-gray-900 dark:text-dark-500 dark:hover:text-dark-900`),children:e.label},e.id))}),x===`arena`&&(0,y.jsxs)(`div`,{className:`space-y-4`,"data-testid":`arena-tab`,children:[(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[(0,y.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,y.jsxs)(`label`,{className:`text-xs text-gray-600 dark:text-gray-300`,children:[e(`evaluations.arenaModelA`),(0,y.jsxs)(`select`,{className:`${b} mt-1`,value:D,onChange:e=>O(e.target.value),children:[(0,y.jsx)(`option`,{value:``,children:`—`}),Z.map(e=>(0,y.jsx)(`option`,{value:e,children:e},`a-${e}`))]})]}),(0,y.jsxs)(`label`,{className:`text-xs text-gray-600 dark:text-gray-300`,children:[e(`evaluations.arenaModelB`),(0,y.jsxs)(`select`,{className:`${b} mt-1`,value:k,onChange:e=>A(e.target.value),children:[(0,y.jsx)(`option`,{value:``,children:`—`}),Z.map(e=>(0,y.jsx)(`option`,{value:e,children:e},`b-${e}`))]})]})]}),(0,y.jsx)(`textarea`,{className:`${b} mt-2`,rows:3,placeholder:e(`evaluations.arenaPrompt`),value:T,onChange:e=>E(e.target.value),"data-testid":`arena-prompt`}),(0,y.jsxs)(h,{className:`mt-2`,onClick:()=>void Q(),disabled:F||!T.trim()||!D||!k||D===k,"data-testid":`arena-start`,children:[F?(0,y.jsx)(s,{className:`mr-1 h-4 w-4 animate-spin`}):(0,y.jsx)(o,{className:`mr-1 h-4 w-4`}),e(`evaluations.startMatch`)]}),(0,y.jsx)(`p`,{className:`mt-1 text-xs text-gray-500`,children:e(`evaluations.arenaHint`)})]}),j&&(0,y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[j.candidates.map((t,n)=>(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-3 dark:border-dark-300 dark:bg-dark-100`,children:[(0,y.jsx)(`p`,{className:`mb-2 text-xs font-semibold text-gray-500`,children:N?t.model:e(`evaluations.candidate`,{letter:n+1})}),(0,y.jsx)(`div`,{className:`max-h-80 overflow-y-auto whitespace-pre-wrap text-sm text-gray-800 dark:text-gray-200`,children:t.output||`—`})]},t.key)),!N&&(0,y.jsxs)(`div`,{className:`sm:col-span-2 flex flex-wrap gap-2`,children:[(0,y.jsx)(h,{size:`sm`,onClick:()=>void $(j.candidates[0].key),children:e(`evaluations.voteFirst`)}),(0,y.jsx)(h,{size:`sm`,onClick:()=>void $(j.candidates[1].key),children:e(`evaluations.voteSecond`)}),(0,y.jsx)(h,{size:`sm`,variant:`outline`,onClick:()=>void $(`tie`),children:e(`evaluations.voteTie`)}),(0,y.jsx)(h,{size:`sm`,variant:`outline`,onClick:()=>void $(`both-bad`),children:e(`evaluations.voteBothBad`)})]})]})]}),x===`leaderboard`&&(0,y.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:(0,y.jsxs)(`table`,{className:`w-full text-left text-sm`,children:[(0,y.jsx)(`thead`,{className:`text-xs text-gray-500`,children:(0,y.jsxs)(`tr`,{children:[(0,y.jsx)(`th`,{className:`py-1 pr-2`,children:`#`}),(0,y.jsx)(`th`,{className:`py-1 pr-2`,children:e(`evaluations.model`)}),(0,y.jsx)(`th`,{className:`py-1 pr-2`,children:e(`evaluations.rating`)}),(0,y.jsx)(`th`,{className:`py-1 pr-2`,children:e(`evaluations.record`)}),(0,y.jsx)(`th`,{className:`py-1`,children:e(`evaluations.votes`)})]})}),(0,y.jsxs)(`tbody`,{children:[L.map((e,t)=>(0,y.jsxs)(`tr`,{className:`border-t border-gray-100 dark:border-dark-300`,children:[(0,y.jsx)(`td`,{className:`py-1.5 pr-2`,children:t===0?(0,y.jsx)(d,{className:`h-4 w-4 text-amber-500`}):t+1}),(0,y.jsx)(`td`,{className:`py-1.5 pr-2 font-medium`,children:e.model}),(0,y.jsx)(`td`,{className:`py-1.5 pr-2`,children:e.rating}),(0,y.jsxs)(`td`,{className:`py-1.5 pr-2 text-xs text-gray-500`,children:[e.wins,`W · `,e.losses,`L · `,e.ties,`T`]}),(0,y.jsx)(`td`,{className:`py-1.5`,children:e.votes})]},e.model)),L.length===0&&(0,y.jsx)(`tr`,{children:(0,y.jsx)(`td`,{colSpan:5,className:`py-3 text-sm text-gray-500`,children:e(`evaluations.noVotes`)})})]})]})}),x===`sets`&&(0,y.jsxs)(`div`,{className:`space-y-4`,children:[(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[(0,y.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:e(`evaluations.newSet`)}),(0,y.jsx)(`input`,{className:b,placeholder:e(`evaluations.setName`),value:G,onChange:e=>K(e.target.value)}),(0,y.jsx)(`textarea`,{className:`${b} mt-2`,rows:4,placeholder:e(`evaluations.setPrompts`),value:q,onChange:e=>J(e.target.value)}),(0,y.jsxs)(h,{size:`sm`,className:`mt-2`,onClick:()=>void te(),disabled:!G.trim()||!q.trim(),children:[(0,y.jsx)(u,{className:`mr-1 h-3.5 w-3.5`}),e(`evaluations.saveSet`)]})]}),(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[(0,y.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,y.jsx)(`h3`,{className:`text-sm font-semibold`,children:e(`evaluations.yourSets`)}),(0,y.jsxs)(`select`,{className:`rounded-lg border border-gray-300 bg-white px-2 py-1 text-xs dark:border-dark-300 dark:bg-dark-50`,value:Y,onChange:e=>X(e.target.value),children:[(0,y.jsx)(`option`,{value:``,children:e(`evaluations.pickModel`)}),Z.map(e=>(0,y.jsx)(`option`,{value:e,children:e},`run-${e}`))]})]}),z.length===0&&(0,y.jsx)(`p`,{className:`text-sm text-gray-500`,children:e(`evaluations.noSets`)}),(0,y.jsx)(`div`,{className:`space-y-2`,children:z.map(t=>(0,y.jsxs)(`div`,{className:`rounded-lg border border-gray-200 p-2 dark:border-dark-300`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,y.jsxs)(`span`,{className:`min-w-0 truncate text-sm font-medium`,children:[t.name,(0,y.jsx)(`span`,{className:`ml-2 text-xs font-normal text-gray-500`,children:e(`evaluations.itemCount`,{total:t.items.length})})]}),(0,y.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,y.jsxs)(h,{size:`sm`,variant:`outline`,onClick:()=>void ne(t.id),children:[(0,y.jsx)(p,{className:`mr-1 h-3 w-3`}),e(`evaluations.run`)]}),(0,y.jsx)(`button`,{onClick:()=>{_.deleteSet(t.id).then(()=>w(e=>e+1)).catch(()=>l.error(e(`evaluations.saveFailed`)))},className:`rounded p-1.5 text-red-500 hover:bg-red-50 dark:hover:bg-red-950/30`,"aria-label":e(`evaluations.deleteSet`),children:(0,y.jsx)(m,{className:`h-3.5 w-3.5`})})]})]}),V.filter(e=>e.setId===t.id).slice(0,5).map(t=>(0,y.jsxs)(`div`,{className:`mt-1 flex items-center justify-between gap-2 rounded bg-gray-50 px-2 py-1 text-xs dark:bg-dark-50`,children:[(0,y.jsxs)(`span`,{className:`min-w-0 truncate`,children:[t.model,` · `,e(`evaluations.status.${t.status}`),t.error?` — ${t.error}`:``]}),(0,y.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(t.status===`queued`||t.status===`running`)&&(0,y.jsx)(`button`,{onClick:()=>{_.cancelRun(t.id).then(()=>w(e=>e+1)).catch(()=>void 0)},className:`rounded p-1 text-gray-500 hover:bg-gray-200 dark:hover:bg-dark-200`,"aria-label":e(`evaluations.cancelRun`),children:(0,y.jsx)(f,{className:`h-3 w-3`})}),t.status===`completed`&&(0,y.jsx)(`button`,{onClick:()=>void re(t.id),className:`rounded p-1 text-gray-500 hover:bg-gray-200 dark:hover:bg-dark-200`,"aria-label":e(`evaluations.exportRun`),children:(0,y.jsx)(c,{className:`h-3 w-3`})})]})]},t.id))]},t.id))})]})]}),x===`feedback`&&(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[U.length===0&&(0,y.jsx)(`p`,{className:`text-sm text-gray-500`,children:e(`evaluations.noFeedback`)}),(0,y.jsx)(`div`,{className:`space-y-2`,children:U.map(e=>(0,y.jsxs)(`div`,{className:`rounded-lg border border-gray-200 p-2 text-sm dark:border-dark-300`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-xs text-gray-500`,children:[(0,y.jsxs)(`span`,{children:[e.rating===1?`👍`:`👎`,` `,e.model??``,e.tags.length>0&&` · ${e.tags.join(`, `)}`]}),(0,y.jsx)(`span`,{children:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}).format(e.createdAt)})]}),e.snapshot&&(0,y.jsx)(`p`,{className:`mt-1 line-clamp-2 text-xs text-gray-600 dark:text-gray-300`,children:e.snapshot.assistant}),e.comment&&(0,y.jsxs)(`p`,{className:`mt-1 text-xs italic text-gray-500`,children:[`“`,e.comment,`”`]})]},e.id))})]})]})};export{x as EvaluationsPage,x as default};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{t as r}from"./useTranslation-rdLmo6zV.js";import{t as i}from"./utils-CKWltgs8.js";import{t as a}from"./chatStore-BvZkd8Un.js";import{C as o,Ft as s,Tn as c,br as l,h as u,n as d,rt as f,tt as p,v as m}from"./ui-vendor-Dt9hfsGD.js";import{t as h}from"./Button-BxwbQ5xw.js";import{a as g,o as ee}from"./ui-CgokQU6I.js";import{t as _}from"./evaluationsApi-Dn-WNzzH.js";var v=e(t(),1),y=n(),b=`w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50`,x=()=>{let{t:e}=r(),t=a(e=>e.models),n=a(e=>e.loadModels),[x,S]=(0,v.useState)(`arena`),[C,w]=(0,v.useState)(0),[T,E]=(0,v.useState)(``),[D,O]=(0,v.useState)(``),[k,A]=(0,v.useState)(``),[j,M]=(0,v.useState)(null),[N,P]=(0,v.useState)(!1),[F,I]=(0,v.useState)(!1),[L,R]=(0,v.useState)([]),[z,B]=(0,v.useState)([]),[V,H]=(0,v.useState)([]),[U,W]=(0,v.useState)([]),[G,K]=(0,v.useState)(``),[q,J]=(0,v.useState)(``),[Y,X]=(0,v.useState)(``);(0,v.useEffect)(()=>{n()},[n]),(0,v.useEffect)(()=>{let t=!1;return Promise.all([_.leaderboard(),_.listSets(),_.listRuns(),_.listFeedback()]).then(([e,n,r,i])=>{t||(e.success&&e.data&&R(e.data),n.success&&n.data&&B(n.data),r.success&&r.data&&H(r.data),i.success&&i.data&&W(i.data))}).catch(()=>l.error(e(`evaluations.loadFailed`))),()=>{t=!0}},[C,e]),(0,v.useEffect)(()=>{if(!V.some(e=>e.status===`queued`||e.status===`running`))return;let e=window.setInterval(()=>w(e=>e+1),4e3);return()=>window.clearInterval(e)},[V]);let Z=t.map(e=>e.name),Q=async()=>{if(!(!T.trim()||!D||!k||F)){I(!0),M(null),P(!1);try{let e=await _.runArenaMatch({prompt:T.trim(),modelA:D,modelB:k});if(!e.success||!e.data)throw Error(e.message||e.error);M(e.data)}catch(t){l.error(t instanceof Error?t.message:e(`evaluations.matchFailed`))}finally{I(!1)}}},$=async t=>{if(!(!j||N))try{let n=j.candidates.find(e=>e.key===`a`)?.model,r=j.candidates.find(e=>e.key===`b`)?.model;if(!n||!r)return;let i=await _.voteArena({compareGroup:j.compareGroup,modelA:n,modelB:r,winner:t});if(!i.success)throw Error(i.message);P(!0),w(e=>e+1),l.success(e(`evaluations.voteRecorded`))}catch(t){l.error(t instanceof Error?t.message:e(`evaluations.voteFailed`))}},te=async()=>{let t=q.split(`
2
+ `).map(e=>e.trim()).filter(Boolean);if(!(!G.trim()||t.length===0))try{let n=await _.saveSet({name:G.trim(),items:t.map(e=>({prompt:e}))});if(!n.success)throw Error(n.message);K(``),J(``),w(e=>e+1),l.success(e(`evaluations.setSaved`))}catch(t){l.error(t instanceof Error?t.message:e(`evaluations.saveFailed`))}},ne=async t=>{if(!Y){l.error(e(`evaluations.pickModel`));return}try{let n=await _.startRun({setId:t,model:Y});if(!n.success)throw Error(n.message);w(e=>e+1),l.success(e(`evaluations.runStarted`))}catch(t){l.error(t instanceof Error?t.message:e(`evaluations.saveFailed`))}},re=async t=>{try{let e=await _.exportRun(t),n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=`eval-run-${t}.json`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}catch{l.error(e(`evaluations.exportFailed`))}},ie=[{id:`arena`,label:e(`evaluations.tabs.arena`)},{id:`leaderboard`,label:e(`evaluations.tabs.leaderboard`)},{id:`sets`,label:e(`evaluations.tabs.sets`)},{id:`feedback`,label:e(`evaluations.tabs.feedback`)}];return(0,y.jsxs)(ee,{width:`wide`,children:[(0,y.jsx)(g,{title:e(`evaluations.title`),description:e(`evaluations.description`)}),(0,y.jsx)(`div`,{className:`mb-4 inline-flex rounded-xl border border-gray-200 bg-white/70 p-1 dark:border-white/[0.08] dark:bg-dark-100/70`,children:ie.map(e=>(0,y.jsx)(`button`,{type:`button`,onClick:()=>S(e.id),className:i(`rounded-lg px-3 py-1.5 text-xs font-medium transition-colors`,x===e.id?`bg-gray-950 text-white dark:bg-white dark:text-gray-950`:`text-gray-500 hover:text-gray-900 dark:text-dark-500 dark:hover:text-dark-900`),children:e.label},e.id))}),x===`arena`&&(0,y.jsxs)(`div`,{className:`space-y-4`,"data-testid":`arena-tab`,children:[(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[(0,y.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,y.jsxs)(`label`,{className:`text-xs text-gray-600 dark:text-gray-300`,children:[e(`evaluations.arenaModelA`),(0,y.jsxs)(`select`,{className:`${b} mt-1`,value:D,onChange:e=>O(e.target.value),children:[(0,y.jsx)(`option`,{value:``,children:`—`}),Z.map(e=>(0,y.jsx)(`option`,{value:e,children:e},`a-${e}`))]})]}),(0,y.jsxs)(`label`,{className:`text-xs text-gray-600 dark:text-gray-300`,children:[e(`evaluations.arenaModelB`),(0,y.jsxs)(`select`,{className:`${b} mt-1`,value:k,onChange:e=>A(e.target.value),children:[(0,y.jsx)(`option`,{value:``,children:`—`}),Z.map(e=>(0,y.jsx)(`option`,{value:e,children:e},`b-${e}`))]})]})]}),(0,y.jsx)(`textarea`,{className:`${b} mt-2`,rows:3,placeholder:e(`evaluations.arenaPrompt`),value:T,onChange:e=>E(e.target.value),"data-testid":`arena-prompt`}),(0,y.jsxs)(h,{className:`mt-2`,onClick:()=>void Q(),disabled:F||!T.trim()||!D||!k||D===k,"data-testid":`arena-start`,children:[F?(0,y.jsx)(s,{className:`mr-1 h-4 w-4 animate-spin`}):(0,y.jsx)(o,{className:`mr-1 h-4 w-4`}),e(`evaluations.startMatch`)]}),(0,y.jsx)(`p`,{className:`mt-1 text-xs text-gray-500`,children:e(`evaluations.arenaHint`)})]}),j&&(0,y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[j.candidates.map((t,n)=>(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-3 dark:border-dark-300 dark:bg-dark-100`,children:[(0,y.jsx)(`p`,{className:`mb-2 text-xs font-semibold text-gray-500`,children:N?t.model:e(`evaluations.candidate`,{letter:n+1})}),(0,y.jsx)(`div`,{className:`max-h-80 overflow-y-auto whitespace-pre-wrap text-sm text-gray-800 dark:text-gray-200`,children:t.output||`—`})]},t.key)),!N&&(0,y.jsxs)(`div`,{className:`sm:col-span-2 flex flex-wrap gap-2`,children:[(0,y.jsx)(h,{size:`sm`,onClick:()=>void $(j.candidates[0].key),children:e(`evaluations.voteFirst`)}),(0,y.jsx)(h,{size:`sm`,onClick:()=>void $(j.candidates[1].key),children:e(`evaluations.voteSecond`)}),(0,y.jsx)(h,{size:`sm`,variant:`outline`,onClick:()=>void $(`tie`),children:e(`evaluations.voteTie`)}),(0,y.jsx)(h,{size:`sm`,variant:`outline`,onClick:()=>void $(`both-bad`),children:e(`evaluations.voteBothBad`)})]})]})]}),x===`leaderboard`&&(0,y.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:(0,y.jsxs)(`table`,{className:`w-full text-left text-sm`,children:[(0,y.jsx)(`thead`,{className:`text-xs text-gray-500`,children:(0,y.jsxs)(`tr`,{children:[(0,y.jsx)(`th`,{className:`py-1 pr-2`,children:`#`}),(0,y.jsx)(`th`,{className:`py-1 pr-2`,children:e(`evaluations.model`)}),(0,y.jsx)(`th`,{className:`py-1 pr-2`,children:e(`evaluations.rating`)}),(0,y.jsx)(`th`,{className:`py-1 pr-2`,children:e(`evaluations.record`)}),(0,y.jsx)(`th`,{className:`py-1`,children:e(`evaluations.votes`)})]})}),(0,y.jsxs)(`tbody`,{children:[L.map((e,t)=>(0,y.jsxs)(`tr`,{className:`border-t border-gray-100 dark:border-dark-300`,children:[(0,y.jsx)(`td`,{className:`py-1.5 pr-2`,children:t===0?(0,y.jsx)(u,{className:`h-4 w-4 text-amber-500`}):t+1}),(0,y.jsx)(`td`,{className:`py-1.5 pr-2 font-medium`,children:e.model}),(0,y.jsx)(`td`,{className:`py-1.5 pr-2`,children:e.rating}),(0,y.jsxs)(`td`,{className:`py-1.5 pr-2 text-xs text-gray-500`,children:[e.wins,`W · `,e.losses,`L · `,e.ties,`T`]}),(0,y.jsx)(`td`,{className:`py-1.5`,children:e.votes})]},e.model)),L.length===0&&(0,y.jsx)(`tr`,{children:(0,y.jsx)(`td`,{colSpan:5,className:`py-3 text-sm text-gray-500`,children:e(`evaluations.noVotes`)})})]})]})}),x===`sets`&&(0,y.jsxs)(`div`,{className:`space-y-4`,children:[(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[(0,y.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:e(`evaluations.newSet`)}),(0,y.jsx)(`input`,{className:b,placeholder:e(`evaluations.setName`),value:G,onChange:e=>K(e.target.value)}),(0,y.jsx)(`textarea`,{className:`${b} mt-2`,rows:4,placeholder:e(`evaluations.setPrompts`),value:q,onChange:e=>J(e.target.value)}),(0,y.jsxs)(h,{size:`sm`,className:`mt-2`,onClick:()=>void te(),disabled:!G.trim()||!q.trim(),children:[(0,y.jsx)(p,{className:`mr-1 h-3.5 w-3.5`}),e(`evaluations.saveSet`)]})]}),(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[(0,y.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,y.jsx)(`h3`,{className:`text-sm font-semibold`,children:e(`evaluations.yourSets`)}),(0,y.jsxs)(`select`,{className:`rounded-lg border border-gray-300 bg-white px-2 py-1 text-xs dark:border-dark-300 dark:bg-dark-50`,value:Y,onChange:e=>X(e.target.value),children:[(0,y.jsx)(`option`,{value:``,children:e(`evaluations.pickModel`)}),Z.map(e=>(0,y.jsx)(`option`,{value:e,children:e},`run-${e}`))]})]}),z.length===0&&(0,y.jsx)(`p`,{className:`text-sm text-gray-500`,children:e(`evaluations.noSets`)}),(0,y.jsx)(`div`,{className:`space-y-2`,children:z.map(t=>(0,y.jsxs)(`div`,{className:`rounded-lg border border-gray-200 p-2 dark:border-dark-300`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,y.jsxs)(`span`,{className:`min-w-0 truncate text-sm font-medium`,children:[t.name,(0,y.jsx)(`span`,{className:`ml-2 text-xs font-normal text-gray-500`,children:e(`evaluations.itemCount`,{total:t.items.length})})]}),(0,y.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,y.jsxs)(h,{size:`sm`,variant:`outline`,onClick:()=>void ne(t.id),children:[(0,y.jsx)(f,{className:`mr-1 h-3 w-3`}),e(`evaluations.run`)]}),(0,y.jsx)(`button`,{onClick:()=>{_.deleteSet(t.id).then(()=>w(e=>e+1)).catch(()=>l.error(e(`evaluations.saveFailed`)))},className:`rounded p-1.5 text-red-500 hover:bg-red-50 dark:hover:bg-red-950/30`,"aria-label":e(`evaluations.deleteSet`),children:(0,y.jsx)(m,{className:`h-3.5 w-3.5`})})]})]}),V.filter(e=>e.setId===t.id).slice(0,5).map(t=>(0,y.jsxs)(`div`,{className:`mt-1 flex items-center justify-between gap-2 rounded bg-gray-50 px-2 py-1 text-xs dark:bg-dark-50`,children:[(0,y.jsxs)(`span`,{className:`min-w-0 truncate`,children:[t.model,` · `,e(`evaluations.status.${t.status}`),t.error?` — ${t.error}`:``]}),(0,y.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(t.status===`queued`||t.status===`running`)&&(0,y.jsx)(`button`,{onClick:()=>{_.cancelRun(t.id).then(()=>w(e=>e+1)).catch(()=>void 0)},className:`rounded p-1 text-gray-500 hover:bg-gray-200 dark:hover:bg-dark-200`,"aria-label":e(`evaluations.cancelRun`),children:(0,y.jsx)(d,{className:`h-3 w-3`})}),t.status===`completed`&&(0,y.jsx)(`button`,{onClick:()=>void re(t.id),className:`rounded p-1 text-gray-500 hover:bg-gray-200 dark:hover:bg-dark-200`,"aria-label":e(`evaluations.exportRun`),children:(0,y.jsx)(c,{className:`h-3 w-3`})})]})]},t.id))]},t.id))})]})]}),x===`feedback`&&(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[U.length===0&&(0,y.jsx)(`p`,{className:`text-sm text-gray-500`,children:e(`evaluations.noFeedback`)}),(0,y.jsx)(`div`,{className:`space-y-2`,children:U.map(e=>(0,y.jsxs)(`div`,{className:`rounded-lg border border-gray-200 p-2 text-sm dark:border-dark-300`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-xs text-gray-500`,children:[(0,y.jsxs)(`span`,{children:[e.rating===1?`👍`:`👎`,` `,e.model??``,e.tags.length>0&&` · ${e.tags.join(`, `)}`]}),(0,y.jsx)(`span`,{children:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}).format(e.createdAt)})]}),e.snapshot&&(0,y.jsx)(`p`,{className:`mt-1 line-clamp-2 text-xs text-gray-600 dark:text-gray-300`,children:e.snapshot.assistant}),e.comment&&(0,y.jsxs)(`p`,{className:`mt-1 text-xs italic text-gray-500`,children:[`“`,e.comment,`”`]})]},e.id))})]})]})};export{x as EvaluationsPage,x as default};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{t as r}from"./logger-DnuT4jgB.js";import{t as i}from"./useTranslation-rdLmo6zV.js";import{Bt as a,I as o,On as s,Qt as ee,Yn as c,bn as l,br as u,g as d,pr as f,t as p,u as m,xn as h}from"./ui-vendor-BvD5yGW1.js";import{I as g}from"./api-HgGU3dII.js";import{t as _}from"./authStore-DbDFBMx0.js";import{t as v}from"./Logo-BHz_QQlV.js";import{t as y}from"./LogoMark-BDqTSfCe.js";import{t as b}from"./TurnstileWidget-CEJst9eS.js";import{n as x,t as S}from"./PasswordStrengthMeter-DLQ5jaO_.js";import{t as C}from"./ConnectModels-Cg7Wp-43.js";var w=e(t(),1),T=n(),E=r(`components:first-time-setup`),D=({onComplete:e})=>{let{t}=i(),[n,r]=(0,w.useState)(`welcome`),[D,O]=(0,w.useState)(``),[k,A]=(0,w.useState)(``),[j,M]=(0,w.useState)(``),[N,P]=(0,w.useState)(!1),[F,I]=(0,w.useState)(!1),[L,R]=(0,w.useState)(!1),[z,B]=(0,w.useState)(null),[V,H]=(0,w.useState)(!1),[U,W]=(0,w.useState)(!1),[G,K]=(0,w.useState)(``),{login:q,systemInfo:J}=_(),Y=J?.turnstile?.siteKey,X=!!(J?.turnstile?.enabled&&Y),Z=(0,w.useCallback)(e=>{K(e)},[]),Q=(0,w.useMemo)(()=>L||X&&!G,[L,X,G]);(0,w.useEffect)(()=>{n===`encryption-key`&&!z&&g.getEncryptionKey().then(e=>{e.success&&e.data&&B(e.data.encryptionKey)})},[n,z]);let te=async e=>{if(e.preventDefault(),!D.trim()||!k.trim()||!j.trim()){u.error(t(`setup.admin.fillAllFields`));return}if(k!==j){u.error(t(`auth.signup.passwordMismatch`));return}let n=x(k);if(n){u.error(n);return}if(X&&!G){u.error(t(`auth.signup.tryAgain`));return}R(!0);try{let e=await g.signup({username:D,password:k,email:``,turnstileToken:G});if(e.success&&e.data){if(!(`token`in e.data)){u.error(t(`setup.admin.approvalUnexpected`,`The initial administrator could not be activated. Please try again.`));return}q(e.data.user,e.data.token,e.data.systemInfo),u.success(t(`setup.admin.success`)),r(`encryption-key`)}else u.error(e.message||t(`setup.admin.failed`))}catch(e){E.error(`Admin creation error:`,e),u.error(t(`setup.admin.failed`))}finally{K(``),R(!1)}},ne=async()=>{if(z)try{await navigator.clipboard.writeText(z),H(!0),u.success(t(`setup.encryptionKey.copied`)),setTimeout(()=>H(!1),3e3)}catch{u.error(t(`setup.encryptionKey.copyFailed`))}},re=()=>{if(!U){u.error(t(`setup.encryptionKey.confirmRequired`));return}r(`connect-models`)},$=e=>{if(e.key===`Enter`){let t=e.currentTarget.form;t&&t.requestSubmit()}};return n===`welcome`?(0,T.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,T.jsx)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:(0,T.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,T.jsx)(y,{size:`md`,label:null}),(0,T.jsx)(v,{})]})}),(0,T.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,T.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,T.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,T.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.welcome.subtitle`)}),(0,T.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.description`)})]}),(0,T.jsxs)(`div`,{className:`mb-7 divide-y divide-gray-200/70 border-y border-gray-200/70 dark:divide-white/[0.08] dark:border-white/[0.08]`,children:[(0,T.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,T.jsx)(o,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.secure.title`)}),(0,T.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.secure.description`)})]})]}),(0,T.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,T.jsx)(p,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.fast.title`)}),(0,T.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.fast.description`)})]})]}),(0,T.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,T.jsx)(ee,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.openSource.title`)}),(0,T.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.openSource.description`)})]})]})]}),(0,T.jsx)(`button`,{onClick:()=>r(`create-admin`),className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2`,children:(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(`span`,{children:t(`setup.welcome.createAdmin`)}),(0,T.jsx)(f,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):n===`connect-models`?(0,T.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,T.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,T.jsx)(y,{size:`md`,label:null}),(0,T.jsx)(v,{})]}),(0,T.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.connectModels.title`)}),(0,T.jsx)(`p`,{className:`mt-3 text-center text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.connectModels.subtitle`)})]}),(0,T.jsx)(`div`,{className:`mt-10 flex justify-center sm:mx-auto sm:w-full sm:max-w-lg`,children:(0,T.jsx)(C,{variant:`setup`,onDone:()=>e?.()})})]}):n===`encryption-key`?(0,T.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,T.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,T.jsx)(y,{size:`md`,label:null}),(0,T.jsx)(v,{})]}),(0,T.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.title`)})]}),(0,T.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-lg`,children:(0,T.jsxs)(`div`,{className:`mx-auto w-full max-w-lg rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,T.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,T.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,T.jsx)(`div`,{className:`rounded-xl border border-amber-200 bg-amber-500/10 p-3 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,T.jsx)(a,{className:`h-8 w-8 text-amber-600 dark:text-amber-400`})})}),(0,T.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.subtitle`)}),(0,T.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.encryptionKey.description`)})]}),(0,T.jsx)(`div`,{className:`mb-6 rounded-xl border border-amber-200 bg-amber-500/10 p-4 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,T.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,T.jsx)(d,{className:`h-5 w-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,T.jsxs)(`div`,{className:`text-sm text-ink`,children:[(0,T.jsx)(`p`,{className:`font-medium mb-1`,children:t(`setup.encryptionKey.warning`)}),(0,T.jsx)(`p`,{children:t(`setup.encryptionKey.warningText`)})]})]})}),(0,T.jsxs)(`div`,{className:`mb-6`,children:[(0,T.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`setup.encryptionKey.label`)}),(0,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsx)(`div`,{className:`w-full break-all rounded-xl border border-gray-200 bg-gray-50 px-3 py-3 pe-12 font-mono text-sm text-gray-900 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800`,children:z||t(`setup.encryptionKey.loading`)}),(0,T.jsx)(`button`,{type:`button`,onClick:ne,disabled:!z,className:`absolute end-2 top-1/2 -translate-y-1/2 p-2 text-gray-500 hover:text-gray-700 disabled:opacity-50 dark:text-dark-500 dark:hover:text-dark-700`,title:t(`setup.encryptionKey.copyToClipboard`),children:V?(0,T.jsx)(c,{className:`h-5 w-5 text-green-500`}):(0,T.jsx)(s,{className:`h-5 w-5`})})]}),(0,T.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.encryptionKey.envNote`)})]}),(0,T.jsx)(`div`,{className:`mb-6`,children:(0,T.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3`,children:[(0,T.jsx)(`input`,{type:`checkbox`,checked:U,onChange:e=>W(e.target.checked),className:`mt-1 h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-dark-300 rounded`}),(0,T.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-dark-700`,children:t(`setup.encryptionKey.acknowledgment`)})]})}),(0,T.jsx)(`button`,{onClick:re,disabled:!U,className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(`span`,{children:t(`setup.encryptionKey.continue`)}),(0,T.jsx)(f,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):(0,T.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,T.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,T.jsx)(y,{size:`md`,label:null}),(0,T.jsx)(v,{})]}),(0,T.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.title`)})]}),(0,T.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,T.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,T.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,T.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.subtitle`)}),(0,T.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.admin.description`)})]}),(0,T.jsxs)(`form`,{onSubmit:te,className:`space-y-4`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.username`)}),(0,T.jsx)(`input`,{id:`username`,type:`text`,value:D,onChange:e=>O(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.usernamePlaceholder`),required:!0,disabled:L})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.password`)}),(0,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsx)(`input`,{id:`password`,type:N?`text`:`password`,value:k,onChange:e=>A(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.passwordPlaceholder`),required:!0,disabled:L}),(0,T.jsx)(`button`,{type:`button`,onClick:()=>P(!N),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:L,children:N?(0,T.jsx)(h,{size:20}):(0,T.jsx)(l,{size:20})})]}),(0,T.jsx)(S,{password:k})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`confirmPassword`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.signup.confirmPassword`)}),(0,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsx)(`input`,{id:`confirmPassword`,type:F?`text`:`password`,value:j,onChange:e=>M(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.confirmPlaceholder`),required:!0,disabled:L}),(0,T.jsx)(`button`,{type:`button`,onClick:()=>I(!F),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:L,children:F?(0,T.jsx)(h,{size:20}):(0,T.jsx)(l,{size:20})})]})]}),X&&Y&&(0,T.jsx)(b,{siteKey:Y,action:`signup`,disabled:L,errorMessage:t(`auth.signup.tryAgain`),onTokenChange:Z}),(0,T.jsxs)(`div`,{className:`flex gap-3`,children:[(0,T.jsx)(`button`,{type:`button`,onClick:()=>r(`welcome`),disabled:L,className:`min-h-11 flex-1 rounded-xl border border-gray-200 bg-transparent px-4 py-2.5 text-sm font-medium text-gray-700 transition-colors duration-200 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/10 dark:text-dark-700 dark:hover:bg-white/[0.06]`,children:t(`common.back`)}),(0,T.jsx)(`button`,{type:`submit`,disabled:Q,className:`flex min-h-11 flex-1 items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:L?(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(`div`,{className:`me-2 h-4 w-4 animate-spin rounded-full border-b-2 border-white`}),t(`setup.admin.creating`)]}):(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(m,{size:16,className:`me-2`}),t(`setup.admin.createAdmin`)]})})]})]}),(0,T.jsx)(`div`,{className:`mt-6 text-center`,children:(0,T.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.admin.note`)})})]})})]})};export{D as FirstTimeSetup};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{t as r}from"./logger-DnuT4jgB.js";import{t as i}from"./useTranslation-rdLmo6zV.js";import{Bt as a,I as o,On as s,Qt as ee,Yn as c,bn as l,br as u,g as d,pr as f,t as p,u as m,xn as h}from"./ui-vendor-Dt9hfsGD.js";import{I as g}from"./api-CgnEj5Jc.js";import{t as _}from"./authStore-CieFdk4S.js";import{t as v}from"./Logo-BHz_QQlV.js";import{t as y}from"./LogoMark-BDqTSfCe.js";import{t as b}from"./TurnstileWidget-CEJst9eS.js";import{n as x,t as S}from"./PasswordStrengthMeter-H0Os6XbX.js";import{t as C}from"./ConnectModels-D7ZTGihA.js";var w=e(t(),1),T=n(),E=r(`components:first-time-setup`),D=({onComplete:e})=>{let{t}=i(),[n,r]=(0,w.useState)(`welcome`),[D,O]=(0,w.useState)(``),[k,A]=(0,w.useState)(``),[j,M]=(0,w.useState)(``),[N,P]=(0,w.useState)(!1),[F,I]=(0,w.useState)(!1),[L,R]=(0,w.useState)(!1),[z,B]=(0,w.useState)(null),[V,H]=(0,w.useState)(!1),[U,W]=(0,w.useState)(!1),[G,K]=(0,w.useState)(``),{login:q,systemInfo:J}=_(),Y=J?.turnstile?.siteKey,X=!!(J?.turnstile?.enabled&&Y),Z=(0,w.useCallback)(e=>{K(e)},[]),Q=(0,w.useMemo)(()=>L||X&&!G,[L,X,G]);(0,w.useEffect)(()=>{n===`encryption-key`&&!z&&g.getEncryptionKey().then(e=>{e.success&&e.data&&B(e.data.encryptionKey)})},[n,z]);let te=async e=>{if(e.preventDefault(),!D.trim()||!k.trim()||!j.trim()){u.error(t(`setup.admin.fillAllFields`));return}if(k!==j){u.error(t(`auth.signup.passwordMismatch`));return}let n=x(k);if(n){u.error(n);return}if(X&&!G){u.error(t(`auth.signup.tryAgain`));return}R(!0);try{let e=await g.signup({username:D,password:k,email:``,turnstileToken:G});if(e.success&&e.data){if(!(`token`in e.data)){u.error(t(`setup.admin.approvalUnexpected`,`The initial administrator could not be activated. Please try again.`));return}q(e.data.user,e.data.token,e.data.systemInfo),u.success(t(`setup.admin.success`)),r(`encryption-key`)}else u.error(e.message||t(`setup.admin.failed`))}catch(e){E.error(`Admin creation error:`,e),u.error(t(`setup.admin.failed`))}finally{K(``),R(!1)}},ne=async()=>{if(z)try{await navigator.clipboard.writeText(z),H(!0),u.success(t(`setup.encryptionKey.copied`)),setTimeout(()=>H(!1),3e3)}catch{u.error(t(`setup.encryptionKey.copyFailed`))}},re=()=>{if(!U){u.error(t(`setup.encryptionKey.confirmRequired`));return}r(`connect-models`)},$=e=>{if(e.key===`Enter`){let t=e.currentTarget.form;t&&t.requestSubmit()}};return n===`welcome`?(0,T.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,T.jsx)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:(0,T.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,T.jsx)(y,{size:`md`,label:null}),(0,T.jsx)(v,{})]})}),(0,T.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,T.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,T.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,T.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.welcome.subtitle`)}),(0,T.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.description`)})]}),(0,T.jsxs)(`div`,{className:`mb-7 divide-y divide-gray-200/70 border-y border-gray-200/70 dark:divide-white/[0.08] dark:border-white/[0.08]`,children:[(0,T.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,T.jsx)(o,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.secure.title`)}),(0,T.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.secure.description`)})]})]}),(0,T.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,T.jsx)(p,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.fast.title`)}),(0,T.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.fast.description`)})]})]}),(0,T.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,T.jsx)(ee,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.openSource.title`)}),(0,T.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.openSource.description`)})]})]})]}),(0,T.jsx)(`button`,{onClick:()=>r(`create-admin`),className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2`,children:(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(`span`,{children:t(`setup.welcome.createAdmin`)}),(0,T.jsx)(f,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):n===`connect-models`?(0,T.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,T.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,T.jsx)(y,{size:`md`,label:null}),(0,T.jsx)(v,{})]}),(0,T.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.connectModels.title`)}),(0,T.jsx)(`p`,{className:`mt-3 text-center text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.connectModels.subtitle`)})]}),(0,T.jsx)(`div`,{className:`mt-10 flex justify-center sm:mx-auto sm:w-full sm:max-w-lg`,children:(0,T.jsx)(C,{variant:`setup`,onDone:()=>e?.()})})]}):n===`encryption-key`?(0,T.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,T.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,T.jsx)(y,{size:`md`,label:null}),(0,T.jsx)(v,{})]}),(0,T.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.title`)})]}),(0,T.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-lg`,children:(0,T.jsxs)(`div`,{className:`mx-auto w-full max-w-lg rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,T.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,T.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,T.jsx)(`div`,{className:`rounded-xl border border-amber-200 bg-amber-500/10 p-3 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,T.jsx)(a,{className:`h-8 w-8 text-amber-600 dark:text-amber-400`})})}),(0,T.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.subtitle`)}),(0,T.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.encryptionKey.description`)})]}),(0,T.jsx)(`div`,{className:`mb-6 rounded-xl border border-amber-200 bg-amber-500/10 p-4 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,T.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,T.jsx)(d,{className:`h-5 w-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,T.jsxs)(`div`,{className:`text-sm text-ink`,children:[(0,T.jsx)(`p`,{className:`font-medium mb-1`,children:t(`setup.encryptionKey.warning`)}),(0,T.jsx)(`p`,{children:t(`setup.encryptionKey.warningText`)})]})]})}),(0,T.jsxs)(`div`,{className:`mb-6`,children:[(0,T.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`setup.encryptionKey.label`)}),(0,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsx)(`div`,{className:`w-full break-all rounded-xl border border-gray-200 bg-gray-50 px-3 py-3 pe-12 font-mono text-sm text-gray-900 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800`,children:z||t(`setup.encryptionKey.loading`)}),(0,T.jsx)(`button`,{type:`button`,onClick:ne,disabled:!z,className:`absolute end-2 top-1/2 -translate-y-1/2 p-2 text-gray-500 hover:text-gray-700 disabled:opacity-50 dark:text-dark-500 dark:hover:text-dark-700`,title:t(`setup.encryptionKey.copyToClipboard`),children:V?(0,T.jsx)(c,{className:`h-5 w-5 text-green-500`}):(0,T.jsx)(s,{className:`h-5 w-5`})})]}),(0,T.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.encryptionKey.envNote`)})]}),(0,T.jsx)(`div`,{className:`mb-6`,children:(0,T.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3`,children:[(0,T.jsx)(`input`,{type:`checkbox`,checked:U,onChange:e=>W(e.target.checked),className:`mt-1 h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-dark-300 rounded`}),(0,T.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-dark-700`,children:t(`setup.encryptionKey.acknowledgment`)})]})}),(0,T.jsx)(`button`,{onClick:re,disabled:!U,className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(`span`,{children:t(`setup.encryptionKey.continue`)}),(0,T.jsx)(f,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):(0,T.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,T.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,T.jsx)(y,{size:`md`,label:null}),(0,T.jsx)(v,{})]}),(0,T.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.title`)})]}),(0,T.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,T.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,T.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,T.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.subtitle`)}),(0,T.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.admin.description`)})]}),(0,T.jsxs)(`form`,{onSubmit:te,className:`space-y-4`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.username`)}),(0,T.jsx)(`input`,{id:`username`,type:`text`,value:D,onChange:e=>O(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.usernamePlaceholder`),required:!0,disabled:L})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.password`)}),(0,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsx)(`input`,{id:`password`,type:N?`text`:`password`,value:k,onChange:e=>A(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.passwordPlaceholder`),required:!0,disabled:L}),(0,T.jsx)(`button`,{type:`button`,onClick:()=>P(!N),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:L,children:N?(0,T.jsx)(h,{size:20}):(0,T.jsx)(l,{size:20})})]}),(0,T.jsx)(S,{password:k})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`confirmPassword`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.signup.confirmPassword`)}),(0,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsx)(`input`,{id:`confirmPassword`,type:F?`text`:`password`,value:j,onChange:e=>M(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.confirmPlaceholder`),required:!0,disabled:L}),(0,T.jsx)(`button`,{type:`button`,onClick:()=>I(!F),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:L,children:F?(0,T.jsx)(h,{size:20}):(0,T.jsx)(l,{size:20})})]})]}),X&&Y&&(0,T.jsx)(b,{siteKey:Y,action:`signup`,disabled:L,errorMessage:t(`auth.signup.tryAgain`),onTokenChange:Z}),(0,T.jsxs)(`div`,{className:`flex gap-3`,children:[(0,T.jsx)(`button`,{type:`button`,onClick:()=>r(`welcome`),disabled:L,className:`min-h-11 flex-1 rounded-xl border border-gray-200 bg-transparent px-4 py-2.5 text-sm font-medium text-gray-700 transition-colors duration-200 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/10 dark:text-dark-700 dark:hover:bg-white/[0.06]`,children:t(`common.back`)}),(0,T.jsx)(`button`,{type:`submit`,disabled:Q,className:`flex min-h-11 flex-1 items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:L?(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(`div`,{className:`me-2 h-4 w-4 animate-spin rounded-full border-b-2 border-white`}),t(`setup.admin.creating`)]}):(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(m,{size:16,className:`me-2`}),t(`setup.admin.createAdmin`)]})})]})]}),(0,T.jsx)(`div`,{className:`mt-6 text-center`,children:(0,T.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.admin.note`)})})]})})]})};export{D as FirstTimeSetup};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,r as n,t as r}from"./react-vendor-D0Ec-185.js";import{C as i,a,n as o,o as s,r as c,t as l}from"./useQuery-BKulzCS7.js";import{t as u}from"./logger-DnuT4jgB.js";import{t as d}from"./useTranslation-rdLmo6zV.js";import{t as f}from"./utils-CKWltgs8.js";import{At as p,Cn as m,Dn as h,Fn as g,Ft as _,M as ee,Tn as v,Ut as y,Wt as b,br as x,dn as S,i as C,n as w,o as T,v as E}from"./ui-vendor-BvD5yGW1.js";import{S as D,b as O}from"./api-HgGU3dII.js";import{i as k,n as A,r as j,s as M}from"./imageGenModels-Dx_QMLJQ.js";import{t as N}from"./appStore-DefVAJAx.js";import{t as P}from"./Button-BxwbQ5xw.js";import{a as F,o as I}from"./ui-CHgZA8lG.js";var L=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 te(e,t){return o(e,L,t)}var R=e(t(),1),ne=n(),z=r(),re=u(`components:image-generation-panel`);function ie(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:M(e.models,t.model,void 0,``),size:M(n,t.size,e.config?.default_size,`1024x1024`),quality:r.length>0?M(r,t.quality,e.config?.default_quality,`standard`):``,style:i.length>0?M(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 B=({isOpen:e,onClose:t,onImageGenerated:n})=>{let{t:r}=d(),i=N(e=>e.preferences.imageGenSettings),a=i?.enabled===!0,[o,s]=(0,R.useState)([]),[c,l]=(0,R.useState)(``),[u,p]=(0,R.useState)(``),[m,h]=(0,R.useState)(``),[g,_]=(0,R.useState)(`1024x1024`),[b,S]=(0,R.useState)(`standard`),[C,T]=(0,R.useState)(``),[E,O]=(0,R.useState)(!1),[M,F]=(0,R.useState)(null),I=(0,R.useRef)(null),[L,te]=(0,R.useState)([`512x512`,`768x768`,`1024x1024`]),[B,ae]=(0,R.useState)([`standard`,`high`]),[V,H]=(0,R.useState)([]),[U,oe]=(0,R.useState)(null),[se,ce]=(0,R.useState)(``),W=R.useId(),G=(0,R.useCallback)((e,t)=>{let n=ie(e,t);l(n.pluginId),p(n.model),_(n.size),S(n.quality),T(n.style),te(n.sizes),ae(n.qualities),H(n.styles),oe(n.maxPromptLength),ce(n.sizeLabel)},[]);(0,R.useEffect)(()=>{let t=!1;return e&&a&&(async()=>{try{let e=await D.getPlugins();if(t)return;let n=e.success&&e.data?e.data.filter(e=>e.models.length>0):[];s(n);let r=A(n,i);r?G(r,i):(l(``),p(``))}catch(e){if(t)return;s([]),l(``),p(``),re.error(`Failed to load image generation plugins:`,e)}})(),()=>{t=!0}},[G,a,e,i]),(0,R.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,R.useEffect)(()=>()=>{I.current?.abort(),I.current=null},[]),(0,R.useEffect)(()=>{e||I.current?.abort()},[e]);let K=()=>{I.current?.abort(),t()},le=e=>{let t=o.find(t=>t.id===e);t&&G(t,{model:u,size:g,quality:b,style:C})},ue=async()=>{if(!a||!c||!u||!m.trim()){x.error(r(`imageGeneration.enterPrompt`));return}if(U&&m.length>U){x.error(r(`imageGeneration.promptTooLong`,{max:U.toLocaleString()}));return}let e=new AbortController;I.current?.abort(),I.current=e,O(!0),F(null);try{let i=await D.generate({model:u,pluginId:c,prompt:m.trim(),size:g,quality:b,...C?{style:C}:{}},e.signal);if(e.signal.aborted)return;if(i.success&&i.data?.images&&i.data.images.length>0){let e=k(i.data.images[0]);e&&(x.success(r(`imageGeneration.success`)),n?(n(e,m.trim(),u),h(``),F(null),t()):F(e))}else x.error(r(`imageGeneration.failed`))}catch(t){if(e.signal.aborted)return;re.error(`Image generation failed:`,t);let n=t instanceof Error?t.message:r(`imageGeneration.failed`);x.error(n)}finally{I.current===e&&(I.current=null,O(!1))}},de=()=>{I.current?.abort()},fe=()=>{if(!M)return;let e=document.createElement(`a`);e.href=M,e.download=`generated-image-${Date.now()}.${j(M)}`,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,ne.createPortal)((0,z.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,z.jsx)(`div`,{className:`absolute inset-0 bg-black/55 backdrop-blur-sm`,onClick:K}),(0,z.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,z.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200/70 px-5 py-4 dark:border-white/[0.08] sm:px-6 sm:py-5`,children:[(0,z.jsx)(`div`,{children:(0,z.jsx)(`h2`,{id:W,className:`text-xl font-normal tracking-[-0.025em] text-gray-950 dark:text-dark-950`,children:r(`imageGeneration.title`)})}),(0,z.jsx)(`button`,{onClick:K,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/[0.06] dark:hover:text-dark-900`,title:r(`common.close`,{defaultValue:`Close`}),children:(0,z.jsx)(w,{className:`h-5 w-5 text-gray-500 dark:text-gray-400`})})]}),(0,z.jsx)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-5 p-5 scrollbar-thin sm:p-6`,children:q?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`settings.plugins.title`)}),(0,z.jsx)(`select`,{value:c,onChange:e=>le(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-none focus:ring-2 focus:ring-primary-500/20`),children:o.map(e=>(0,z.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.model`)}),(0,z.jsx)(`select`,{value:u,onChange:e=>p(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-none focus:ring-2 focus:ring-primary-500/20`),children:q?.models.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))})]}),V.length>0&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.style`)}),(0,z.jsx)(`select`,{value:C,onChange:e=>T(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-none focus:ring-2 focus:ring-primary-500/20`),children:V.map(e=>(0,z.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),(0,z.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:se||r(`imageGeneration.size`)}),(0,z.jsx)(`select`,{value:g,onChange: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-none focus:ring-2 focus:ring-primary-500/20`),children:L.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))})]}),B.length>0&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.quality`)}),(0,z.jsx)(`select`,{value:b,onChange:e=>S(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-none focus:ring-2 focus:ring-primary-500/20`),children:B.map(e=>(0,z.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.prompt`)}),(0,z.jsx)(`textarea`,{value:m,onChange:e=>h(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-none focus:ring-2 focus:ring-primary-500/20`,U&&m.length>U&&`border-red-500 dark:border-red-500`)}),U&&(0,z.jsxs)(`div`,{className:f(`mt-1 text-end text-xs`,m.length>U?`text-red-500`:`text-gray-500 dark:text-gray-400`),children:[m.length.toLocaleString(),` /`,` `,U.toLocaleString()]})]}),M&&(0,z.jsxs)(`div`,{className:`relative overflow-hidden rounded-2xl border border-gray-200/80 dark:border-white/10`,children:[(0,z.jsx)(`img`,{src:M,alt:`Generated`,className:`w-full h-auto`}),(0,z.jsx)(`button`,{onClick:fe,className:f(`absolute bottom-3 end-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,z.jsx)(v,{className:`h-5 w-5 text-gray-700 dark:text-gray-200`})})]})]}):(0,z.jsxs)(`div`,{className:`text-center py-8`,children:[(0,z.jsx)(y,{className:`h-12 w-12 mx-auto mb-3 text-gray-300 dark:text-gray-600`}),(0,z.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:r(`imageGeneration.noModels`)}),(0,z.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-gray-500 mt-1`,children:r(`imageGeneration.configurePlugin`)})]})}),q&&(0,z.jsx)(`div`,{className:`border-t border-gray-200/70 p-4 dark:border-white/[0.08] sm:px-6 sm:py-5`,children:(0,z.jsx)(P,{onClick:E?de:ue,disabled:!E&&(!a||!m.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:E?(0,z.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,z.jsx)(w,{className:`h-4 w-4`}),r(`common.cancel`)]}):(0,z.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,z.jsx)(ee,{className:`h-4 w-4`}),r(`imageGeneration.generate`)]})})})]})]}),document.body)},ae={video:[],audio:[]};function V({isOpen:e,initialKind:t,onClose:n,onGenerated:r}){let{t:a}=d(),o=i(),[s,c]=(0,R.useState)(t),[l,u]=(0,R.useState)(ae),[p,m]=(0,R.useState)(``),[h,g]=(0,R.useState)(``),[v,y]=(0,R.useState)(``),[b,C]=(0,R.useState)(!1),[E,D]=(0,R.useState)(null),[k,A]=(0,R.useState)(``),[j,M]=(0,R.useState)(!1),[N,F]=(0,R.useState)(``),[I,L]=(0,R.useState)(!1),[te,re]=(0,R.useState)(null),[ie,B]=(0,R.useState)(0),[V,G]=(0,R.useState)(``),[K,le]=(0,R.useState)(``),[ue,de]=(0,R.useState)(``),[fe,q]=(0,R.useState)(!0),[pe,me]=(0,R.useState)(!0),[J,he]=(0,R.useState)(!1),[ge,_e]=(0,R.useState)([]),Y=(0,R.useRef)(null),ve=R.useId(),ye=()=>{C(!1),D(null),A(``),M(!1),F(``),L(!1),B(e=>e+1)},be=()=>{Y.current?.abort(),ye(),n()};(0,R.useEffect)(()=>()=>{Y.current?.abort(),Y.current=null},[]),(0,R.useEffect)(()=>{e||Y.current?.abort()},[e]),(0,R.useEffect)(()=>{if(!e)return;let t=!1;return O.getModels().then(e=>{t||!e.success||!e.data||u(e.data)}).catch(()=>{t||x.error(a(`mediaGeneration.loadFailed`))}).finally(()=>{t||me(!1)}),()=>{t=!0}},[e,a]),(0,R.useEffect)(()=>{if(!e)return;let t=!1;return O.listVideoJobs({limit:100,active:!0}).then(e=>{!t&&e.success&&e.data&&_e(e.data.jobs)}).catch(()=>{t||x.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=>U(e)===p)?p:X[0]?U(X[0]):``,Z=(0,R.useMemo)(()=>X.find(e=>U(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&&b,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 oe(3e4,t.signal);try{let n=await O.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`));x.success(a(`mediaGeneration.success`)),r()}catch(e){if(t.signal.aborted)return;x.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 O.cancelVideoJob(e.id);if(!t.success)throw Error(t.message||a(`mediaGeneration.failed`));_e(t=>t.filter(t=>t.id!==e.id)),x.success(a(`mediaGeneration.jobCancelled`,{defaultValue:`Video job cancelled at the provider`}))}catch(e){x.error(e instanceof Error?e.message:a(`mediaGeneration.failed`))}};return e?(0,ne.createPortal)((0,z.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center p-3 sm:p-6`,children:[(0,z.jsx)(`button`,{className:`absolute inset-0 bg-black/55 backdrop-blur-sm`,onClick:be,"aria-label":a(`common.close`)}),(0,z.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,z.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.08] sm:px-5`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h2`,{id:ve,className:`text-xl text-gray-950 dark:text-dark-950`,children:a(`mediaGeneration.title`)}),(0,z.jsx)(`p`,{className:`mt-1 text-sm text-gray-500 dark:text-dark-500`,children:a(`mediaGeneration.description`)})]}),(0,z.jsx)(`button`,{onClick:be,className:`rounded-xl p-2`,children:(0,z.jsx)(w,{className:`h-5 w-5`})})]}),(0,z.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-4 p-4 sm:p-5`,children:[(0,z.jsx)(`div`,{className:`grid grid-cols-2 gap-2 rounded-xl bg-gray-100 p-1 dark:bg-white/[0.05]`,children:[`video`,`audio`].map(e=>(0,z.jsxs)(`button`,{type:`button`,disabled:J,onClick:()=>{c(e),m(``),y(``),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-sm dark:bg-white/10 dark:text-white`:`text-gray-500 dark:text-dark-500`,J&&`cursor-not-allowed opacity-50`),children:[e===`video`?(0,z.jsx)(S,{className:`h-4 w-4`}):(0,z.jsx)(T,{className:`h-4 w-4`}),a(`mediaGeneration.${e}`)]},e))}),s===`video`&&xe.length>0&&(0,z.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/[0.025]`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:a(`mediaGeneration.savedJobs`,{defaultValue:`Saved video jobs`})}),(0,z.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,z.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,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`p`,{className:`truncate text-sm text-gray-900 dark:text-gray-100`,children:e.prompt||e.model}),(0,z.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,z.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,z.jsx)(P,{type:`button`,variant:`outline`,size:`sm`,disabled:J,onClick:()=>void ke(e),children:a(`mediaGeneration.resumeJob`,{defaultValue:`Resume`})}),e.cancellable&&(0,z.jsx)(P,{type:`button`,variant:`outline`,size:`sm`,disabled:J,onClick:()=>void Ae(e),children:a(`mediaGeneration.cancelJob`,{defaultValue:`Cancel job`})})]},e.id))]}),pe?(0,z.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,z.jsx)(_,{className:`h-7 w-7 animate-spin`})}):X.length===0?(0,z.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,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(H,{label:a(`mediaGeneration.model`),children:(0,z.jsx)(`select`,{value:Se,onChange:e=>{m(e.target.value),y(``),ye(),G(``),le(``),de(``),q(!0)},className:W,children:X.map(e=>(0,z.jsxs)(`option`,{value:U(e),children:[e.model,` (`,e.plugin,`mode`in e?` · ${a(`mediaGeneration.${e.mode}`)}`:``,`)`]},U(e)))})}),s===`audio`&&!$&&Ee?(0,z.jsx)(H,{label:a(`mediaGeneration.voice`),children:(0,z.jsx)(`input`,{value:v,onChange:e=>y(e.target.value),className:W,placeholder:Q?.config?.default_voice||a(`mediaGeneration.providerDefault`)})}):s===`video`?(0,z.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-3`,children:[(0,z.jsx)(H,{label:a(`mediaGeneration.resolution`),children:(0,z.jsxs)(`select`,{value:V,onChange:e=>G(e.target.value),className:W,children:[(0,z.jsx)(`option`,{value:``,children:a(`mediaGeneration.providerDefault`)}),Ce?.resolutions?.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))]})}),(0,z.jsx)(H,{label:a(`mediaGeneration.aspectRatio`),children:(0,z.jsxs)(`select`,{value:K,onChange:e=>le(e.target.value),className:W,children:[(0,z.jsx)(`option`,{value:``,children:a(`mediaGeneration.providerDefault`)}),Ce?.aspect_ratios?.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))]})}),(0,z.jsx)(H,{label:a(`mediaGeneration.duration`),children:(0,z.jsxs)(`select`,{value:ue,onChange:e=>de(e.target.value),className:W,children:[(0,z.jsx)(`option`,{value:``,children:a(`mediaGeneration.providerDefault`)}),Ce?.durations?.map(e=>(0,z.jsxs)(`option`,{value:e,children:[e,`s`]},e))]})})]}):null,we&&(0,z.jsxs)(`div`,{className:`space-y-3 rounded-xl border border-primary-500/20 bg-primary-500/[0.06] p-4`,children:[(0,z.jsxs)(`label`,{className:`flex items-start gap-3 text-sm`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:$,onChange:e=>{e.target.checked?C(!0):ye()},className:`mt-0.5`}),(0,z.jsxs)(`span`,{children:[(0,z.jsx)(`span`,{className:`block font-medium text-gray-900 dark:text-gray-100`,children:a(`mediaGeneration.cloneVoice`)}),(0,z.jsx)(`span`,{className:`mt-0.5 block text-xs font-normal text-gray-500 dark:text-dark-500`,children:a(`mediaGeneration.cloneVoiceDescription`)})]})]}),$&&(0,z.jsxs)(`div`,{className:`space-y-3 border-t border-primary-500/15 pt-3`,children:[(0,z.jsx)(H,{label:a(`mediaGeneration.referenceAudio`),children:(0,z.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){x.error(a(`mediaGeneration.referenceAudioTooLarge`,{max:ce(n)})),e.target.value=``,D(null);return}D(t)},className:f(W,`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`)},ie)}),(0,z.jsx)(H,{label:a(`mediaGeneration.referenceTranscript`),children:(0,z.jsx)(`textarea`,{value:k,onChange:e=>A(e.target.value),rows:3,required:Te,className:f(W,`resize-none`),placeholder:a(`mediaGeneration.referenceTranscriptPlaceholder`)})}),(0,z.jsxs)(`label`,{className:`flex items-start gap-3 text-sm`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:j,onChange:e=>{M(e.target.checked),e.target.checked||(F(``),L(!1))},className:`mt-0.5`}),(0,z.jsxs)(`span`,{children:[(0,z.jsx)(`span`,{className:`block font-medium text-gray-900 dark:text-gray-100`,children:a(`mediaGeneration.saveVoiceProfile`,{defaultValue:`Save as a reusable voice`})}),(0,z.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,z.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,z.jsx)(H,{label:a(`mediaGeneration.voiceProfileName`,{defaultValue:`Saved voice name`}),children:(0,z.jsx)(`input`,{type:`text`,value:N,onChange:e=>F(e.target.value),maxLength:80,autoComplete:`off`,className:W,placeholder:a(`mediaGeneration.voiceProfileNamePlaceholder`,{defaultValue:`For example, My voice`})})}),(0,z.jsxs)(`label`,{className:`flex items-start gap-3 text-xs text-amber-700 dark:text-amber-300`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:I,onChange:e=>L(e.target.checked),className:`mt-0.5`}),(0,z.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,z.jsx)(H,{label:a(`mediaGeneration.consentTtl.label`,{defaultValue:`Consent duration`}),children:(0,z.jsxs)(`select`,{value:te??``,onChange:e=>re(e.target.value===``?null:Number(e.target.value)),className:W,children:[(0,z.jsx)(`option`,{value:``,children:a(`mediaGeneration.consentTtl.never`,{defaultValue:`Until I withdraw it`})}),(0,z.jsx)(`option`,{value:`30`,children:a(`mediaGeneration.consentTtl.days30`,{defaultValue:`30 days`})}),(0,z.jsx)(`option`,{value:`90`,children:a(`mediaGeneration.consentTtl.days90`,{defaultValue:`90 days`})}),(0,z.jsx)(`option`,{value:`365`,children:a(`mediaGeneration.consentTtl.days365`,{defaultValue:`One year`})})]})})]}),!j&&(0,z.jsx)(`p`,{className:`text-xs font-normal text-amber-700 dark:text-amber-300`,children:a(`mediaGeneration.cloneConsent`)})]})]}),s===`video`&&Ce?.supports_audio&&(0,z.jsxs)(`label`,{className:`flex items-center gap-3 text-sm`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:fe,onChange:e=>q(e.target.checked)}),a(`mediaGeneration.generateAudio`)]}),(0,z.jsxs)(H,{label:s===`video`||Q?.mode===`sound`?a(`mediaGeneration.prompt`):a(`mediaGeneration.text`),children:[(0,z.jsx)(`textarea`,{value:h,onChange:e=>g(e.target.value),rows:6,maxLength:De,className:f(W,`resize-none`),placeholder:a(s===`audio`&&Q?.mode===`sound`?`mediaGeneration.soundPlaceholder`:`mediaGeneration.${s}Placeholder`)}),De&&(0,z.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,z.jsx)(`div`,{className:`border-t border-gray-200/70 p-4 dark:border-white/[0.08] sm:px-5`,children:(0,z.jsxs)(P,{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=se(Q?.config?.default_format),n=$?await O.cloneVoice({model:Z.model,pluginId:Z.plugin,input:h.trim(),referenceAudio:E,referenceText:k.trim()||void 0,responseFormat:t,saveVoiceName:j?N.trim():void 0,consentToStore:j&&I,consentTtlDays:j&&te!==null?te:void 0},e.signal):Q?.mode===`sound`?await O.generateSound({model:Z.model,pluginId:Z.plugin,prompt:h.trim(),voice:v.trim()||Q?.config?.default_voice||void 0,format:`wav`},e.signal):await O.generateAudio({model:Z.model,pluginId:Z.plugin,input:h.trim(),voice:v.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 O.generateVideo({model:Z.model,pluginId:Z.plugin,prompt:h.trim(),...ue?{duration:Number(ue)}:{},...V?{resolution:V}:{},...K?{aspect_ratio:K}:{},...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;x.success($&&j?a(`mediaGeneration.successWithSavedVoice`,{name:N.trim(),defaultValue:`Media generated and “{{name}}” is now available in Speech settings`}):a(`mediaGeneration.success`)),g(``),ye(),r(),n()}catch(t){if(e.signal.aborted)return;x.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)||$&&(!E||Te&&!k.trim()||j&&(!N.trim()||!I)),className:`w-full gap-2`,children:[J?(0,z.jsx)(w,{className:`h-4 w-4`}):(0,z.jsx)(ee,{className:`h-4 w-4`}),J?s===`video`?a(`mediaGeneration.stopWaiting`,{defaultValue:`Stop waiting`}):a(`common.cancel`):a(`mediaGeneration.generate`)]})})]})]}),document.body):null}function H({label:e,children:t}){return(0,z.jsxs)(`label`,{className:`block space-y-1.5 text-sm font-medium text-gray-700 dark:text-gray-300`,children:[(0,z.jsx)(`span`,{children:e}),t]})}function U(e){return`${e.mode||`default`}::${e.plugin}::${e.model}`}function oe(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 se(e){return[`mp3`,`opus`,`aac`,`flac`,`wav`,`pcm`].includes(e||``)?e:`mp3`}function ce(e){return e>=1048576?`${Math.ceil(e/1048576)} MB`:`${Math.ceil(e/1024)} KB`}var W=`w-full rounded-xl border border-gray-200/80 bg-white/70 px-3 py-2.5 text-sm text-gray-900 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.035] dark:text-gray-100`,G=u(`components:image-edit-panel`),K=e=>e.filter(e=>!!e.config?.edit_endpoint),le=({isOpen:e,onClose:t,source:n,onEdited:r})=>{let{t:i}=d(),[a,o]=(0,R.useState)([]),[s,c]=(0,R.useState)(``),[l,u]=(0,R.useState)(``),[f,p]=(0,R.useState)(36),[h,g]=(0,R.useState)([]),[ee,v]=(0,R.useState)(!1),[y,b]=(0,R.useState)(null),[S,T]=(0,R.useState)(!1),E=(0,R.useRef)(null),k=(0,R.useRef)(null),A=(0,R.useRef)(null),j=(0,R.useRef)(!1),M=(0,R.useRef)(null),N=a.find(e=>`${e.plugin}:${e.model}`===s);(0,R.useEffect)(()=>{if(!e)return;let t=!1;return D.getModels().then(e=>{if(t||!e.success||!e.data)return;let n=K(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,R.useEffect)(()=>{if(!e||!n)return;let t=null,r=!1;return O.getGalleryContent(n.id).then(e=>{r||(t=URL.createObjectURL(e),b(t))}).catch(e=>{G.error(`Failed to load the source image:`,e),x.error(i(`imageEdit.loadFailed`))}),()=>{r=!0,t&&URL.revokeObjectURL(t),b(null),T(!1),g([])}},[e,n?.id]),(0,R.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]);let F=()=>{let e=A.current,t=E.current,n=k.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())},I=()=>{let e=E.current,t=A.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,k.current=i,T(!1),F()},L=e=>{let t=A.current,n=k.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(),T(!0),F()},te=()=>{let e=k.current;e&&(e.getContext(`2d`)?.clearRect(0,0,e.width,e.height),T(!1),F())},re=async()=>{let e=k.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},ie=async()=>{if(!n||!N||!l.trim()||ee)return;v(!0);let e=new AbortController;M.current=e;try{let a=await re(),o=await O.editImage({model:N.model,pluginId:N.plugin,prompt:l.trim(),sourceMediaId:n.id,images:h,...a?{mask:a}:{}},e.signal);if(!o.success)throw Error(o.message||o.error||`Edit failed`);x.success(i(`imageEdit.saved`)),r(),t()}catch(t){e.signal.aborted||(G.error(`Image edit failed:`,t),x.error(t instanceof Error?t.message:i(`imageEdit.failed`)))}finally{v(!1),M.current=null}};if(!e||!n)return null;let B=Math.max(0,(N?.config?.max_reference_images??1)-1);return(0,ne.createPortal)((0,z.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,z.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,z.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200 px-4 py-3 dark:border-dark-300`,children:[(0,z.jsxs)(`h2`,{className:`flex items-center gap-2 text-base font-semibold text-gray-900 dark:text-gray-100`,children:[(0,z.jsx)(C,{className:`h-4 w-4`}),i(`imageEdit.title`)]}),(0,z.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,z.jsx)(w,{className:`h-5 w-5`})})]}),(0,z.jsx)(`div`,{className:`flex-1 space-y-4 overflow-y-auto p-4`,children:a.length===0?(0,z.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:i(`imageEdit.noModels`)}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`relative`,children:y?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`img`,{ref:E,src:y,alt:n.prompt,className:`hidden`,onLoad:I}),(0,z.jsx)(`canvas`,{ref:A,onPointerDown:e=>{j.current=!0,e.currentTarget.setPointerCapture(e.pointerId),L(e)},onPointerMove:e=>{j.current&&L(e)},onPointerUp:()=>{j.current=!1},className:`w-full cursor-crosshair rounded-xl border border-gray-200 dark:border-dark-300`,"data-testid":`image-edit-canvas`})]}):(0,z.jsx)(`div`,{className:`flex h-56 items-center justify-center`,children:(0,z.jsx)(_,{className:`h-6 w-6 animate-spin text-gray-400`})})}),(0,z.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:i(`imageEdit.maskHint`)}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,z.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-gray-600 dark:text-gray-300`,children:[i(`imageEdit.brushSize`),(0,z.jsx)(`input`,{type:`range`,min:8,max:96,value:f,onChange:e=>p(Number(e.target.value))})]}),(0,z.jsxs)(P,{type:`button`,size:`sm`,variant:`outline`,onClick:te,disabled:!S,children:[(0,z.jsx)(m,{className:`mr-1 h-3.5 w-3.5`}),i(`imageEdit.clearMask`)]})]}),(0,z.jsxs)(`label`,{className:`block text-xs font-medium text-gray-700 dark:text-gray-300`,children:[i(`imageEdit.model`),(0,z.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,z.jsxs)(`option`,{value:`${e.plugin}:${e.model}`,children:[e.plugin,` · `,e.model]},`${e.plugin}:${e.model}`))})]}),(0,z.jsxs)(`label`,{className:`block text-xs font-medium text-gray-700 dark:text-gray-300`,children:[i(`imageEdit.prompt`),(0,z.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`})]}),B>0&&(0,z.jsxs)(`label`,{className:`block text-xs font-medium text-gray-700 dark:text-gray-300`,children:[i(`imageEdit.referenceImages`,{total:B}),(0,z.jsx)(`input`,{type:`file`,accept:`image/png,image/jpeg,image/webp`,multiple:!0,onChange:e=>g(Array.from(e.target.files??[]).slice(0,B)),className:`mt-1 block w-full text-xs`})]})]})}),(0,z.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,z.jsx)(P,{type:`button`,variant:`outline`,onClick:t,children:i(`common.cancel`)}),(0,z.jsxs)(P,{type:`button`,onClick:()=>void ie(),disabled:ee||!N||!l.trim()||!y,"data-testid":`image-edit-submit`,children:[ee?(0,z.jsx)(_,{className:`mr-1 h-4 w-4 animate-spin`}):(0,z.jsx)(C,{className:`mr-1 h-4 w-4`}),i(`imageEdit.apply`)]})]})]})}),document.body)},ue=({image:e,onClose:t,onDelete:n,onDownload:r})=>{let{t:i}=d();return(0,R.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return document.addEventListener(`keydown`,e),document.body.style.overflow=`hidden`,()=>{document.removeEventListener(`keydown`,e),document.body.style.overflow=``}},[t]),(0,ne.createPortal)((0,z.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center`,onClick:t,children:[(0,z.jsx)(`div`,{className:`absolute inset-0 bg-black/90 backdrop-blur-sm`}),(0,z.jsxs)(`div`,{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,z.jsx)(`button`,{onClick:t,className:f(`absolute -top-12 right-0 lg:top-0 lg:-right-12 z-10`,`p-2 rounded-full`,`bg-white/10 hover:bg-white/20`,`transition-colors`),children:(0,z.jsx)(w,{className:`h-6 w-6 text-white`})}),(0,z.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-0`,children:(0,z.jsx)(`img`,{src:e.imageData,alt:e.prompt,className:`max-w-full max-h-[70vh] lg:max-h-[90vh] object-contain rounded-lg`})}),(0,z.jsxs)(`div`,{className:f(`w-full lg:w-80 flex-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,z.jsxs)(`div`,{className:`mb-4`,children:[(0,z.jsx)(`h3`,{className:`text-sm font-medium text-gray-500 dark:text-gray-400 mb-1`,children:i(`gallery.prompt`)}),(0,z.jsx)(`p`,{className:`text-gray-900 dark:text-gray-100 text-sm leading-relaxed`,children:e.prompt})]}),(0,z.jsxs)(`div`,{className:`space-y-3 mb-4`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(h,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,z.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.model`),`:`]}),(0,z.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.model})]}),e.size&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(p,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,z.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.size`),`:`]}),(0,z.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.size})]}),e.quality&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.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,z.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.quality`),`:`]}),(0,z.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100 capitalize`,children:e.quality})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(g,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,z.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.created`),`:`]}),(0,z.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,z.jsxs)(`div`,{className:`flex gap-2 pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,z.jsxs)(`button`,{onClick:()=>{if(r)r(e);else{let t=document.createElement(`a`);t.href=e.imageData,t.download=`generated-${e.id}.${j(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-primary-600 dark:bg-primary-600`,`hover:bg-primary-700 dark:hover:bg-primary-500`,`text-white font-medium text-sm`,`transition-colors`),children:[(0,z.jsx)(v,{className:`h-4 w-4`}),i(`gallery.download`)]}),n&&(0,z.jsx)(`button`,{onClick:()=>n(e.id),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:`Delete image`,children:(0,z.jsx)(E,{className:`h-4 w-4`})})]})]})]})]}),document.body)};function de({kind:e,refreshKey:t,onCountChange:n,onEditImage:r}){let{t:a}=d(),o=i(),[s,c]=(0,R.useState)(null),[l,u]=(0,R.useState)(null),f=te({queryKey:[`media-gallery`,e||`all`,t||0],queryFn:async({pageParam:t})=>{let n=await O.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,R.useMemo)(()=>f.data?.pages.flatMap(e=>e.media)||[],[f.data]),m=f.data?.pages[0]?.total||0;(0,R.useEffect)(()=>n?.(m),[n,m]);let h=async e=>{if(!l){u(e.id);try{let t=await O.deleteGalleryItem(e.id);if(!t.success)throw Error(t.message);c(null),await o.invalidateQueries({queryKey:[`media-gallery`]}),x.success(a(`imageGallery.deleteSuccess`))}catch{x.error(a(`imageGallery.deleteFailed`))}finally{u(null)}}},g=async e=>{let t=await O.getGalleryContent(e.id),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`generated-${e.id}.${pe(e.mimeType)}`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)};return f.isLoading?(0,z.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,z.jsx)(_,{className:`h-8 w-8 animate-spin text-gray-400`})}):p.length===0?(0,z.jsxs)(`div`,{className:`flex flex-col items-center justify-center rounded-2xl border border-dashed border-gray-300 bg-white/30 px-6 py-12 text-center dark:border-white/15 dark:bg-white/[0.02]`,children:[(0,z.jsx)(b,{className:`mb-4 h-10 w-10 text-gray-300 dark:text-gray-600`}),(0,z.jsx)(`h3`,{className:`text-lg font-medium`,children:a(`mediaGallery.empty`)}),(0,z.jsx)(`p`,{className:`mt-2 max-w-sm text-gray-500 dark:text-gray-400`,children:a(`mediaGallery.emptyHint`)})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.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,z.jsxs)(`article`,{className:`overflow-hidden rounded-2xl border border-gray-200/80 bg-white/70 dark:border-white/10 dark:bg-white/[0.025]`,children:[(0,z.jsx)(fe,{item:e,onOpenImage:t=>c(q(e,t))}),(0,z.jsxs)(`div`,{className:`space-y-3 p-3`,children:[(0,z.jsx)(`p`,{className:`line-clamp-2 text-sm text-gray-800 dark:text-gray-200`,children:e.prompt}),(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,z.jsx)(`span`,{className:`min-w-0 truncate text-xs text-gray-500`,children:e.model}),(0,z.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[e.kind===`image`&&r&&(0,z.jsx)(`button`,{onClick:()=>r(e),className:`rounded-lg p-1.5 hover:bg-gray-100 dark:hover:bg-white/10`,title:a(`imageEdit.title`),"data-testid":`edit-image-${e.id}`,children:(0,z.jsx)(C,{className:`h-4 w-4`})}),(0,z.jsx)(`button`,{onClick:()=>void g(e),className:`rounded-lg p-1.5 hover:bg-gray-100 dark:hover:bg-white/10`,title:a(`imageGallery.download`),children:(0,z.jsx)(v,{className:`h-4 w-4`})}),(0,z.jsx)(`button`,{onClick:()=>void h(e),disabled:l===e.id,className:`rounded-lg p-1.5 hover:bg-red-500/15 hover:text-red-500`,title:a(`imageGallery.delete`),children:l===e.id?(0,z.jsx)(_,{className:`h-4 w-4 animate-spin`}):(0,z.jsx)(E,{className:`h-4 w-4`})})]})]})]})]},e.id))}),f.hasNextPage&&(0,z.jsx)(`div`,{className:`mt-8 flex justify-center`,children:(0,z.jsx)(P,{variant:`outline`,disabled:f.isFetchingNextPage,onClick:()=>void f.fetchNextPage(),children:f.isFetchingNextPage?a(`common.loading`):a(`imageGallery.loadMore`,{current:p.length,total:m})})}),s&&(0,z.jsx)(ue,{image:s,onClose:()=>c(null),onDelete:e=>{let t=p.find(t=>t.id===e);t&&h(t)},onDownload:e=>{let t=p.find(t=>t.id===e.id);t&&g(t)}})]})}function fe({item:e,onOpenImage:t}){let{data:n,isLoading:r}=l({queryKey:[`media-gallery-content`,e.id],queryFn:()=>O.getGalleryContent(e.id),staleTime:3e5}),i=(0,R.useMemo)(()=>n?URL.createObjectURL(n):``,[n]),a=(0,R.useRef)(new Map);return(0,R.useEffect)(()=>{if(!i)return;let e=a.current,t=e.get(i);return t&&(clearTimeout(t),e.delete(i)),()=>{e.set(i,setTimeout(()=>{e.delete(i),URL.revokeObjectURL(i)},0))}},[i]),r||!i?(0,z.jsx)(`div`,{className:`flex aspect-video items-center justify-center bg-gray-100 dark:bg-white/[0.03]`,children:(0,z.jsx)(_,{className:`h-6 w-6 animate-spin text-gray-400`})}):e.kind===`image`?(0,z.jsx)(`button`,{className:`block aspect-square w-full overflow-hidden`,onClick:()=>t(i),children:(0,z.jsx)(`img`,{src:i,alt:e.prompt,className:`h-full w-full object-cover`,loading:`lazy`})}):e.kind===`video`?(0,z.jsx)(`div`,{className:`aspect-video bg-black`,children:(0,z.jsx)(`video`,{src:i,controls:!0,preload:`metadata`,className:`h-full w-full object-contain`})}):(0,z.jsxs)(`div`,{className:`flex min-h-40 flex-col items-center justify-center gap-3 bg-gradient-to-br from-primary-500/10 to-cyan-500/10 p-4`,children:[(0,z.jsx)(T,{className:`h-9 w-9 text-primary-500`}),(0,z.jsx)(`audio`,{src:i,controls:!0,preload:`metadata`,className:`w-full`})]})}function q(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 pe(e){let t=e.split(`/`)[1]?.split(`;`)[0];return t===`mpeg`?e.startsWith(`audio/`)?`mp3`:`mpeg`:t===`svg+xml`?`svg`:t||`bin`}var me=()=>{let{t:e}=d(),[t,n]=(0,R.useState)(null),[r,i]=(0,R.useState)(!1),[a,o]=(0,R.useState)(null),[s,c]=(0,R.useState)(`all`),[l,u]=(0,R.useState)(null),[p,m]=(0,R.useState)(0),h=N(e=>e.preferences.imageGenSettings?.enabled===!0),g=(0,R.useCallback)(()=>{m(e=>e+1)},[]);return(0,z.jsxs)(I,{width:`wide`,children:[(0,z.jsx)(F,{title:e(`sidebar.navigation.imagine`),description:e(`gallery.subtitle`),meta:t!==null&&t>0?(0,z.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/[0.04] dark:text-dark-500`,children:e(`mediaGallery.itemCount`,{count:t})}):null,actions:(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,z.jsxs)(P,{onClick:()=>{h&&i(!0)},disabled:!h,className:`gap-2 px-4`,children:[(0,z.jsx)(y,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`gallery.generate`)]}),(0,z.jsxs)(P,{variant:`outline`,onClick:()=>o(`video`),className:`gap-2 px-4`,children:[(0,z.jsx)(S,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`mediaGeneration.video`)]}),(0,z.jsxs)(P,{variant:`outline`,onClick:()=>o(`audio`),className:`gap-2 px-4`,children:[(0,z.jsx)(T,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`mediaGeneration.audio`)]})]})}),(0,z.jsx)(`div`,{className:`mb-5 flex flex-wrap gap-2`,children:[`all`,`image`,`video`,`audio`].map(t=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>c(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,z.jsx)(de,{kind:s===`all`?void 0:s,refreshKey:p,onCountChange:n,onEditImage:u}),(0,z.jsx)(le,{isOpen:l!==null,source:l,onClose:()=>u(null),onEdited:g}),(0,z.jsx)(B,{isOpen:r&&h,onClose:()=>i(!1),onImageGenerated:g}),(0,z.jsx)(V,{isOpen:a!==null,initialKind:a||`video`,onClose:()=>o(null),onGenerated:g},a||`closed`)]})};export{me as GalleryPage,me as default};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,r as n,t as r}from"./react-vendor-D0Ec-185.js";import{C as i,a,n as o,o as s,r as c,t as l}from"./useQuery-BKulzCS7.js";import{t as u}from"./logger-DnuT4jgB.js";import{t as d}from"./useTranslation-rdLmo6zV.js";import{t as f}from"./utils-CKWltgs8.js";import{At as p,Cn as m,Dn as h,Fn as g,Ft as _,M as ee,Tn as v,Ut as y,Wt as b,br as x,dn as S,i as C,n as w,o as T,v as E}from"./ui-vendor-Dt9hfsGD.js";import{S as D,b as O}from"./api-CgnEj5Jc.js";import{i as k,n as A,r as j,s as M}from"./imageGenModels-Dx_QMLJQ.js";import{t as N}from"./appStore-DrTsJPfh.js";import{t as P}from"./Button-BxwbQ5xw.js";import{a as F,o as I}from"./ui-CgokQU6I.js";var L=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 te(e,t){return o(e,L,t)}var R=e(t(),1),ne=n(),z=r(),re=u(`components:image-generation-panel`);function ie(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:M(e.models,t.model,void 0,``),size:M(n,t.size,e.config?.default_size,`1024x1024`),quality:r.length>0?M(r,t.quality,e.config?.default_quality,`standard`):``,style:i.length>0?M(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 B=({isOpen:e,onClose:t,onImageGenerated:n})=>{let{t:r}=d(),i=N(e=>e.preferences.imageGenSettings),a=i?.enabled===!0,[o,s]=(0,R.useState)([]),[c,l]=(0,R.useState)(``),[u,p]=(0,R.useState)(``),[m,h]=(0,R.useState)(``),[g,_]=(0,R.useState)(`1024x1024`),[b,S]=(0,R.useState)(`standard`),[C,T]=(0,R.useState)(``),[E,O]=(0,R.useState)(!1),[M,F]=(0,R.useState)(null),I=(0,R.useRef)(null),[L,te]=(0,R.useState)([`512x512`,`768x768`,`1024x1024`]),[B,ae]=(0,R.useState)([`standard`,`high`]),[V,H]=(0,R.useState)([]),[U,oe]=(0,R.useState)(null),[se,ce]=(0,R.useState)(``),W=R.useId(),G=(0,R.useCallback)((e,t)=>{let n=ie(e,t);l(n.pluginId),p(n.model),_(n.size),S(n.quality),T(n.style),te(n.sizes),ae(n.qualities),H(n.styles),oe(n.maxPromptLength),ce(n.sizeLabel)},[]);(0,R.useEffect)(()=>{let t=!1;return e&&a&&(async()=>{try{let e=await D.getPlugins();if(t)return;let n=e.success&&e.data?e.data.filter(e=>e.models.length>0):[];s(n);let r=A(n,i);r?G(r,i):(l(``),p(``))}catch(e){if(t)return;s([]),l(``),p(``),re.error(`Failed to load image generation plugins:`,e)}})(),()=>{t=!0}},[G,a,e,i]),(0,R.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,R.useEffect)(()=>()=>{I.current?.abort(),I.current=null},[]),(0,R.useEffect)(()=>{e||I.current?.abort()},[e]);let K=()=>{I.current?.abort(),t()},le=e=>{let t=o.find(t=>t.id===e);t&&G(t,{model:u,size:g,quality:b,style:C})},ue=async()=>{if(!a||!c||!u||!m.trim()){x.error(r(`imageGeneration.enterPrompt`));return}if(U&&m.length>U){x.error(r(`imageGeneration.promptTooLong`,{max:U.toLocaleString()}));return}let e=new AbortController;I.current?.abort(),I.current=e,O(!0),F(null);try{let i=await D.generate({model:u,pluginId:c,prompt:m.trim(),size:g,quality:b,...C?{style:C}:{}},e.signal);if(e.signal.aborted)return;if(i.success&&i.data?.images&&i.data.images.length>0){let e=k(i.data.images[0]);e&&(x.success(r(`imageGeneration.success`)),n?(n(e,m.trim(),u),h(``),F(null),t()):F(e))}else x.error(r(`imageGeneration.failed`))}catch(t){if(e.signal.aborted)return;re.error(`Image generation failed:`,t);let n=t instanceof Error?t.message:r(`imageGeneration.failed`);x.error(n)}finally{I.current===e&&(I.current=null,O(!1))}},de=()=>{I.current?.abort()},fe=()=>{if(!M)return;let e=document.createElement(`a`);e.href=M,e.download=`generated-image-${Date.now()}.${j(M)}`,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,ne.createPortal)((0,z.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,z.jsx)(`div`,{className:`absolute inset-0 bg-black/55 backdrop-blur-sm`,onClick:K}),(0,z.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,z.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200/70 px-5 py-4 dark:border-white/[0.08] sm:px-6 sm:py-5`,children:[(0,z.jsx)(`div`,{children:(0,z.jsx)(`h2`,{id:W,className:`text-xl font-normal tracking-[-0.025em] text-gray-950 dark:text-dark-950`,children:r(`imageGeneration.title`)})}),(0,z.jsx)(`button`,{onClick:K,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/[0.06] dark:hover:text-dark-900`,title:r(`common.close`,{defaultValue:`Close`}),children:(0,z.jsx)(w,{className:`h-5 w-5 text-gray-500 dark:text-gray-400`})})]}),(0,z.jsx)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-5 p-5 scrollbar-thin sm:p-6`,children:q?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`settings.plugins.title`)}),(0,z.jsx)(`select`,{value:c,onChange:e=>le(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-none focus:ring-2 focus:ring-primary-500/20`),children:o.map(e=>(0,z.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.model`)}),(0,z.jsx)(`select`,{value:u,onChange:e=>p(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-none focus:ring-2 focus:ring-primary-500/20`),children:q?.models.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))})]}),V.length>0&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.style`)}),(0,z.jsx)(`select`,{value:C,onChange:e=>T(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-none focus:ring-2 focus:ring-primary-500/20`),children:V.map(e=>(0,z.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),(0,z.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:se||r(`imageGeneration.size`)}),(0,z.jsx)(`select`,{value:g,onChange: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-none focus:ring-2 focus:ring-primary-500/20`),children:L.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))})]}),B.length>0&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.quality`)}),(0,z.jsx)(`select`,{value:b,onChange:e=>S(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-none focus:ring-2 focus:ring-primary-500/20`),children:B.map(e=>(0,z.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.prompt`)}),(0,z.jsx)(`textarea`,{value:m,onChange:e=>h(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-none focus:ring-2 focus:ring-primary-500/20`,U&&m.length>U&&`border-red-500 dark:border-red-500`)}),U&&(0,z.jsxs)(`div`,{className:f(`mt-1 text-end text-xs`,m.length>U?`text-red-500`:`text-gray-500 dark:text-gray-400`),children:[m.length.toLocaleString(),` /`,` `,U.toLocaleString()]})]}),M&&(0,z.jsxs)(`div`,{className:`relative overflow-hidden rounded-2xl border border-gray-200/80 dark:border-white/10`,children:[(0,z.jsx)(`img`,{src:M,alt:`Generated`,className:`w-full h-auto`}),(0,z.jsx)(`button`,{onClick:fe,className:f(`absolute bottom-3 end-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,z.jsx)(v,{className:`h-5 w-5 text-gray-700 dark:text-gray-200`})})]})]}):(0,z.jsxs)(`div`,{className:`text-center py-8`,children:[(0,z.jsx)(y,{className:`h-12 w-12 mx-auto mb-3 text-gray-300 dark:text-gray-600`}),(0,z.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:r(`imageGeneration.noModels`)}),(0,z.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-gray-500 mt-1`,children:r(`imageGeneration.configurePlugin`)})]})}),q&&(0,z.jsx)(`div`,{className:`border-t border-gray-200/70 p-4 dark:border-white/[0.08] sm:px-6 sm:py-5`,children:(0,z.jsx)(P,{onClick:E?de:ue,disabled:!E&&(!a||!m.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:E?(0,z.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,z.jsx)(w,{className:`h-4 w-4`}),r(`common.cancel`)]}):(0,z.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,z.jsx)(ee,{className:`h-4 w-4`}),r(`imageGeneration.generate`)]})})})]})]}),document.body)},ae={video:[],audio:[]};function V({isOpen:e,initialKind:t,onClose:n,onGenerated:r}){let{t:a}=d(),o=i(),[s,c]=(0,R.useState)(t),[l,u]=(0,R.useState)(ae),[p,m]=(0,R.useState)(``),[h,g]=(0,R.useState)(``),[v,y]=(0,R.useState)(``),[b,C]=(0,R.useState)(!1),[E,D]=(0,R.useState)(null),[k,A]=(0,R.useState)(``),[j,M]=(0,R.useState)(!1),[N,F]=(0,R.useState)(``),[I,L]=(0,R.useState)(!1),[te,re]=(0,R.useState)(null),[ie,B]=(0,R.useState)(0),[V,G]=(0,R.useState)(``),[K,le]=(0,R.useState)(``),[ue,de]=(0,R.useState)(``),[fe,q]=(0,R.useState)(!0),[pe,me]=(0,R.useState)(!0),[J,he]=(0,R.useState)(!1),[ge,_e]=(0,R.useState)([]),Y=(0,R.useRef)(null),ve=R.useId(),ye=()=>{C(!1),D(null),A(``),M(!1),F(``),L(!1),B(e=>e+1)},be=()=>{Y.current?.abort(),ye(),n()};(0,R.useEffect)(()=>()=>{Y.current?.abort(),Y.current=null},[]),(0,R.useEffect)(()=>{e||Y.current?.abort()},[e]),(0,R.useEffect)(()=>{if(!e)return;let t=!1;return O.getModels().then(e=>{t||!e.success||!e.data||u(e.data)}).catch(()=>{t||x.error(a(`mediaGeneration.loadFailed`))}).finally(()=>{t||me(!1)}),()=>{t=!0}},[e,a]),(0,R.useEffect)(()=>{if(!e)return;let t=!1;return O.listVideoJobs({limit:100,active:!0}).then(e=>{!t&&e.success&&e.data&&_e(e.data.jobs)}).catch(()=>{t||x.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=>U(e)===p)?p:X[0]?U(X[0]):``,Z=(0,R.useMemo)(()=>X.find(e=>U(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&&b,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 oe(3e4,t.signal);try{let n=await O.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`));x.success(a(`mediaGeneration.success`)),r()}catch(e){if(t.signal.aborted)return;x.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 O.cancelVideoJob(e.id);if(!t.success)throw Error(t.message||a(`mediaGeneration.failed`));_e(t=>t.filter(t=>t.id!==e.id)),x.success(a(`mediaGeneration.jobCancelled`,{defaultValue:`Video job cancelled at the provider`}))}catch(e){x.error(e instanceof Error?e.message:a(`mediaGeneration.failed`))}};return e?(0,ne.createPortal)((0,z.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center p-3 sm:p-6`,children:[(0,z.jsx)(`button`,{className:`absolute inset-0 bg-black/55 backdrop-blur-sm`,onClick:be,"aria-label":a(`common.close`)}),(0,z.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,z.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.08] sm:px-5`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h2`,{id:ve,className:`text-xl text-gray-950 dark:text-dark-950`,children:a(`mediaGeneration.title`)}),(0,z.jsx)(`p`,{className:`mt-1 text-sm text-gray-500 dark:text-dark-500`,children:a(`mediaGeneration.description`)})]}),(0,z.jsx)(`button`,{onClick:be,className:`rounded-xl p-2`,children:(0,z.jsx)(w,{className:`h-5 w-5`})})]}),(0,z.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-4 p-4 sm:p-5`,children:[(0,z.jsx)(`div`,{className:`grid grid-cols-2 gap-2 rounded-xl bg-gray-100 p-1 dark:bg-white/[0.05]`,children:[`video`,`audio`].map(e=>(0,z.jsxs)(`button`,{type:`button`,disabled:J,onClick:()=>{c(e),m(``),y(``),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-sm dark:bg-white/10 dark:text-white`:`text-gray-500 dark:text-dark-500`,J&&`cursor-not-allowed opacity-50`),children:[e===`video`?(0,z.jsx)(S,{className:`h-4 w-4`}):(0,z.jsx)(T,{className:`h-4 w-4`}),a(`mediaGeneration.${e}`)]},e))}),s===`video`&&xe.length>0&&(0,z.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/[0.025]`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:a(`mediaGeneration.savedJobs`,{defaultValue:`Saved video jobs`})}),(0,z.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,z.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,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`p`,{className:`truncate text-sm text-gray-900 dark:text-gray-100`,children:e.prompt||e.model}),(0,z.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,z.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,z.jsx)(P,{type:`button`,variant:`outline`,size:`sm`,disabled:J,onClick:()=>void ke(e),children:a(`mediaGeneration.resumeJob`,{defaultValue:`Resume`})}),e.cancellable&&(0,z.jsx)(P,{type:`button`,variant:`outline`,size:`sm`,disabled:J,onClick:()=>void Ae(e),children:a(`mediaGeneration.cancelJob`,{defaultValue:`Cancel job`})})]},e.id))]}),pe?(0,z.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,z.jsx)(_,{className:`h-7 w-7 animate-spin`})}):X.length===0?(0,z.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,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(H,{label:a(`mediaGeneration.model`),children:(0,z.jsx)(`select`,{value:Se,onChange:e=>{m(e.target.value),y(``),ye(),G(``),le(``),de(``),q(!0)},className:W,children:X.map(e=>(0,z.jsxs)(`option`,{value:U(e),children:[e.model,` (`,e.plugin,`mode`in e?` · ${a(`mediaGeneration.${e.mode}`)}`:``,`)`]},U(e)))})}),s===`audio`&&!$&&Ee?(0,z.jsx)(H,{label:a(`mediaGeneration.voice`),children:(0,z.jsx)(`input`,{value:v,onChange:e=>y(e.target.value),className:W,placeholder:Q?.config?.default_voice||a(`mediaGeneration.providerDefault`)})}):s===`video`?(0,z.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-3`,children:[(0,z.jsx)(H,{label:a(`mediaGeneration.resolution`),children:(0,z.jsxs)(`select`,{value:V,onChange:e=>G(e.target.value),className:W,children:[(0,z.jsx)(`option`,{value:``,children:a(`mediaGeneration.providerDefault`)}),Ce?.resolutions?.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))]})}),(0,z.jsx)(H,{label:a(`mediaGeneration.aspectRatio`),children:(0,z.jsxs)(`select`,{value:K,onChange:e=>le(e.target.value),className:W,children:[(0,z.jsx)(`option`,{value:``,children:a(`mediaGeneration.providerDefault`)}),Ce?.aspect_ratios?.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))]})}),(0,z.jsx)(H,{label:a(`mediaGeneration.duration`),children:(0,z.jsxs)(`select`,{value:ue,onChange:e=>de(e.target.value),className:W,children:[(0,z.jsx)(`option`,{value:``,children:a(`mediaGeneration.providerDefault`)}),Ce?.durations?.map(e=>(0,z.jsxs)(`option`,{value:e,children:[e,`s`]},e))]})})]}):null,we&&(0,z.jsxs)(`div`,{className:`space-y-3 rounded-xl border border-primary-500/20 bg-primary-500/[0.06] p-4`,children:[(0,z.jsxs)(`label`,{className:`flex items-start gap-3 text-sm`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:$,onChange:e=>{e.target.checked?C(!0):ye()},className:`mt-0.5`}),(0,z.jsxs)(`span`,{children:[(0,z.jsx)(`span`,{className:`block font-medium text-gray-900 dark:text-gray-100`,children:a(`mediaGeneration.cloneVoice`)}),(0,z.jsx)(`span`,{className:`mt-0.5 block text-xs font-normal text-gray-500 dark:text-dark-500`,children:a(`mediaGeneration.cloneVoiceDescription`)})]})]}),$&&(0,z.jsxs)(`div`,{className:`space-y-3 border-t border-primary-500/15 pt-3`,children:[(0,z.jsx)(H,{label:a(`mediaGeneration.referenceAudio`),children:(0,z.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){x.error(a(`mediaGeneration.referenceAudioTooLarge`,{max:ce(n)})),e.target.value=``,D(null);return}D(t)},className:f(W,`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`)},ie)}),(0,z.jsx)(H,{label:a(`mediaGeneration.referenceTranscript`),children:(0,z.jsx)(`textarea`,{value:k,onChange:e=>A(e.target.value),rows:3,required:Te,className:f(W,`resize-none`),placeholder:a(`mediaGeneration.referenceTranscriptPlaceholder`)})}),(0,z.jsxs)(`label`,{className:`flex items-start gap-3 text-sm`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:j,onChange:e=>{M(e.target.checked),e.target.checked||(F(``),L(!1))},className:`mt-0.5`}),(0,z.jsxs)(`span`,{children:[(0,z.jsx)(`span`,{className:`block font-medium text-gray-900 dark:text-gray-100`,children:a(`mediaGeneration.saveVoiceProfile`,{defaultValue:`Save as a reusable voice`})}),(0,z.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,z.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,z.jsx)(H,{label:a(`mediaGeneration.voiceProfileName`,{defaultValue:`Saved voice name`}),children:(0,z.jsx)(`input`,{type:`text`,value:N,onChange:e=>F(e.target.value),maxLength:80,autoComplete:`off`,className:W,placeholder:a(`mediaGeneration.voiceProfileNamePlaceholder`,{defaultValue:`For example, My voice`})})}),(0,z.jsxs)(`label`,{className:`flex items-start gap-3 text-xs text-amber-700 dark:text-amber-300`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:I,onChange:e=>L(e.target.checked),className:`mt-0.5`}),(0,z.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,z.jsx)(H,{label:a(`mediaGeneration.consentTtl.label`,{defaultValue:`Consent duration`}),children:(0,z.jsxs)(`select`,{value:te??``,onChange:e=>re(e.target.value===``?null:Number(e.target.value)),className:W,children:[(0,z.jsx)(`option`,{value:``,children:a(`mediaGeneration.consentTtl.never`,{defaultValue:`Until I withdraw it`})}),(0,z.jsx)(`option`,{value:`30`,children:a(`mediaGeneration.consentTtl.days30`,{defaultValue:`30 days`})}),(0,z.jsx)(`option`,{value:`90`,children:a(`mediaGeneration.consentTtl.days90`,{defaultValue:`90 days`})}),(0,z.jsx)(`option`,{value:`365`,children:a(`mediaGeneration.consentTtl.days365`,{defaultValue:`One year`})})]})})]}),!j&&(0,z.jsx)(`p`,{className:`text-xs font-normal text-amber-700 dark:text-amber-300`,children:a(`mediaGeneration.cloneConsent`)})]})]}),s===`video`&&Ce?.supports_audio&&(0,z.jsxs)(`label`,{className:`flex items-center gap-3 text-sm`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:fe,onChange:e=>q(e.target.checked)}),a(`mediaGeneration.generateAudio`)]}),(0,z.jsxs)(H,{label:s===`video`||Q?.mode===`sound`?a(`mediaGeneration.prompt`):a(`mediaGeneration.text`),children:[(0,z.jsx)(`textarea`,{value:h,onChange:e=>g(e.target.value),rows:6,maxLength:De,className:f(W,`resize-none`),placeholder:a(s===`audio`&&Q?.mode===`sound`?`mediaGeneration.soundPlaceholder`:`mediaGeneration.${s}Placeholder`)}),De&&(0,z.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,z.jsx)(`div`,{className:`border-t border-gray-200/70 p-4 dark:border-white/[0.08] sm:px-5`,children:(0,z.jsxs)(P,{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=se(Q?.config?.default_format),n=$?await O.cloneVoice({model:Z.model,pluginId:Z.plugin,input:h.trim(),referenceAudio:E,referenceText:k.trim()||void 0,responseFormat:t,saveVoiceName:j?N.trim():void 0,consentToStore:j&&I,consentTtlDays:j&&te!==null?te:void 0},e.signal):Q?.mode===`sound`?await O.generateSound({model:Z.model,pluginId:Z.plugin,prompt:h.trim(),voice:v.trim()||Q?.config?.default_voice||void 0,format:`wav`},e.signal):await O.generateAudio({model:Z.model,pluginId:Z.plugin,input:h.trim(),voice:v.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 O.generateVideo({model:Z.model,pluginId:Z.plugin,prompt:h.trim(),...ue?{duration:Number(ue)}:{},...V?{resolution:V}:{},...K?{aspect_ratio:K}:{},...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;x.success($&&j?a(`mediaGeneration.successWithSavedVoice`,{name:N.trim(),defaultValue:`Media generated and “{{name}}” is now available in Speech settings`}):a(`mediaGeneration.success`)),g(``),ye(),r(),n()}catch(t){if(e.signal.aborted)return;x.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)||$&&(!E||Te&&!k.trim()||j&&(!N.trim()||!I)),className:`w-full gap-2`,children:[J?(0,z.jsx)(w,{className:`h-4 w-4`}):(0,z.jsx)(ee,{className:`h-4 w-4`}),J?s===`video`?a(`mediaGeneration.stopWaiting`,{defaultValue:`Stop waiting`}):a(`common.cancel`):a(`mediaGeneration.generate`)]})})]})]}),document.body):null}function H({label:e,children:t}){return(0,z.jsxs)(`label`,{className:`block space-y-1.5 text-sm font-medium text-gray-700 dark:text-gray-300`,children:[(0,z.jsx)(`span`,{children:e}),t]})}function U(e){return`${e.mode||`default`}::${e.plugin}::${e.model}`}function oe(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 se(e){return[`mp3`,`opus`,`aac`,`flac`,`wav`,`pcm`].includes(e||``)?e:`mp3`}function ce(e){return e>=1048576?`${Math.ceil(e/1048576)} MB`:`${Math.ceil(e/1024)} KB`}var W=`w-full rounded-xl border border-gray-200/80 bg-white/70 px-3 py-2.5 text-sm text-gray-900 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.035] dark:text-gray-100`,G=u(`components:image-edit-panel`),K=e=>e.filter(e=>!!e.config?.edit_endpoint),le=({isOpen:e,onClose:t,source:n,onEdited:r})=>{let{t:i}=d(),[a,o]=(0,R.useState)([]),[s,c]=(0,R.useState)(``),[l,u]=(0,R.useState)(``),[f,p]=(0,R.useState)(36),[h,g]=(0,R.useState)([]),[ee,v]=(0,R.useState)(!1),[y,b]=(0,R.useState)(null),[S,T]=(0,R.useState)(!1),E=(0,R.useRef)(null),k=(0,R.useRef)(null),A=(0,R.useRef)(null),j=(0,R.useRef)(!1),M=(0,R.useRef)(null),N=a.find(e=>`${e.plugin}:${e.model}`===s);(0,R.useEffect)(()=>{if(!e)return;let t=!1;return D.getModels().then(e=>{if(t||!e.success||!e.data)return;let n=K(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,R.useEffect)(()=>{if(!e||!n)return;let t=null,r=!1;return O.getGalleryContent(n.id).then(e=>{r||(t=URL.createObjectURL(e),b(t))}).catch(e=>{G.error(`Failed to load the source image:`,e),x.error(i(`imageEdit.loadFailed`))}),()=>{r=!0,t&&URL.revokeObjectURL(t),b(null),T(!1),g([])}},[e,n?.id]),(0,R.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]);let F=()=>{let e=A.current,t=E.current,n=k.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())},I=()=>{let e=E.current,t=A.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,k.current=i,T(!1),F()},L=e=>{let t=A.current,n=k.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(),T(!0),F()},te=()=>{let e=k.current;e&&(e.getContext(`2d`)?.clearRect(0,0,e.width,e.height),T(!1),F())},re=async()=>{let e=k.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},ie=async()=>{if(!n||!N||!l.trim()||ee)return;v(!0);let e=new AbortController;M.current=e;try{let a=await re(),o=await O.editImage({model:N.model,pluginId:N.plugin,prompt:l.trim(),sourceMediaId:n.id,images:h,...a?{mask:a}:{}},e.signal);if(!o.success)throw Error(o.message||o.error||`Edit failed`);x.success(i(`imageEdit.saved`)),r(),t()}catch(t){e.signal.aborted||(G.error(`Image edit failed:`,t),x.error(t instanceof Error?t.message:i(`imageEdit.failed`)))}finally{v(!1),M.current=null}};if(!e||!n)return null;let B=Math.max(0,(N?.config?.max_reference_images??1)-1);return(0,ne.createPortal)((0,z.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,z.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,z.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200 px-4 py-3 dark:border-dark-300`,children:[(0,z.jsxs)(`h2`,{className:`flex items-center gap-2 text-base font-semibold text-gray-900 dark:text-gray-100`,children:[(0,z.jsx)(C,{className:`h-4 w-4`}),i(`imageEdit.title`)]}),(0,z.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,z.jsx)(w,{className:`h-5 w-5`})})]}),(0,z.jsx)(`div`,{className:`flex-1 space-y-4 overflow-y-auto p-4`,children:a.length===0?(0,z.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:i(`imageEdit.noModels`)}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`relative`,children:y?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`img`,{ref:E,src:y,alt:n.prompt,className:`hidden`,onLoad:I}),(0,z.jsx)(`canvas`,{ref:A,onPointerDown:e=>{j.current=!0,e.currentTarget.setPointerCapture(e.pointerId),L(e)},onPointerMove:e=>{j.current&&L(e)},onPointerUp:()=>{j.current=!1},className:`w-full cursor-crosshair rounded-xl border border-gray-200 dark:border-dark-300`,"data-testid":`image-edit-canvas`})]}):(0,z.jsx)(`div`,{className:`flex h-56 items-center justify-center`,children:(0,z.jsx)(_,{className:`h-6 w-6 animate-spin text-gray-400`})})}),(0,z.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:i(`imageEdit.maskHint`)}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,z.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-gray-600 dark:text-gray-300`,children:[i(`imageEdit.brushSize`),(0,z.jsx)(`input`,{type:`range`,min:8,max:96,value:f,onChange:e=>p(Number(e.target.value))})]}),(0,z.jsxs)(P,{type:`button`,size:`sm`,variant:`outline`,onClick:te,disabled:!S,children:[(0,z.jsx)(m,{className:`mr-1 h-3.5 w-3.5`}),i(`imageEdit.clearMask`)]})]}),(0,z.jsxs)(`label`,{className:`block text-xs font-medium text-gray-700 dark:text-gray-300`,children:[i(`imageEdit.model`),(0,z.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,z.jsxs)(`option`,{value:`${e.plugin}:${e.model}`,children:[e.plugin,` · `,e.model]},`${e.plugin}:${e.model}`))})]}),(0,z.jsxs)(`label`,{className:`block text-xs font-medium text-gray-700 dark:text-gray-300`,children:[i(`imageEdit.prompt`),(0,z.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`})]}),B>0&&(0,z.jsxs)(`label`,{className:`block text-xs font-medium text-gray-700 dark:text-gray-300`,children:[i(`imageEdit.referenceImages`,{total:B}),(0,z.jsx)(`input`,{type:`file`,accept:`image/png,image/jpeg,image/webp`,multiple:!0,onChange:e=>g(Array.from(e.target.files??[]).slice(0,B)),className:`mt-1 block w-full text-xs`})]})]})}),(0,z.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,z.jsx)(P,{type:`button`,variant:`outline`,onClick:t,children:i(`common.cancel`)}),(0,z.jsxs)(P,{type:`button`,onClick:()=>void ie(),disabled:ee||!N||!l.trim()||!y,"data-testid":`image-edit-submit`,children:[ee?(0,z.jsx)(_,{className:`mr-1 h-4 w-4 animate-spin`}):(0,z.jsx)(C,{className:`mr-1 h-4 w-4`}),i(`imageEdit.apply`)]})]})]})}),document.body)},ue=({image:e,onClose:t,onDelete:n,onDownload:r})=>{let{t:i}=d();return(0,R.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return document.addEventListener(`keydown`,e),document.body.style.overflow=`hidden`,()=>{document.removeEventListener(`keydown`,e),document.body.style.overflow=``}},[t]),(0,ne.createPortal)((0,z.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center`,onClick:t,children:[(0,z.jsx)(`div`,{className:`absolute inset-0 bg-black/90 backdrop-blur-sm`}),(0,z.jsxs)(`div`,{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,z.jsx)(`button`,{onClick:t,className:f(`absolute -top-12 right-0 lg:top-0 lg:-right-12 z-10`,`p-2 rounded-full`,`bg-white/10 hover:bg-white/20`,`transition-colors`),children:(0,z.jsx)(w,{className:`h-6 w-6 text-white`})}),(0,z.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-0`,children:(0,z.jsx)(`img`,{src:e.imageData,alt:e.prompt,className:`max-w-full max-h-[70vh] lg:max-h-[90vh] object-contain rounded-lg`})}),(0,z.jsxs)(`div`,{className:f(`w-full lg:w-80 flex-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,z.jsxs)(`div`,{className:`mb-4`,children:[(0,z.jsx)(`h3`,{className:`text-sm font-medium text-gray-500 dark:text-gray-400 mb-1`,children:i(`gallery.prompt`)}),(0,z.jsx)(`p`,{className:`text-gray-900 dark:text-gray-100 text-sm leading-relaxed`,children:e.prompt})]}),(0,z.jsxs)(`div`,{className:`space-y-3 mb-4`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(h,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,z.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.model`),`:`]}),(0,z.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.model})]}),e.size&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(p,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,z.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.size`),`:`]}),(0,z.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.size})]}),e.quality&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.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,z.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.quality`),`:`]}),(0,z.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100 capitalize`,children:e.quality})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(g,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,z.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.created`),`:`]}),(0,z.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,z.jsxs)(`div`,{className:`flex gap-2 pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,z.jsxs)(`button`,{onClick:()=>{if(r)r(e);else{let t=document.createElement(`a`);t.href=e.imageData,t.download=`generated-${e.id}.${j(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-primary-600 dark:bg-primary-600`,`hover:bg-primary-700 dark:hover:bg-primary-500`,`text-white font-medium text-sm`,`transition-colors`),children:[(0,z.jsx)(v,{className:`h-4 w-4`}),i(`gallery.download`)]}),n&&(0,z.jsx)(`button`,{onClick:()=>n(e.id),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:`Delete image`,children:(0,z.jsx)(E,{className:`h-4 w-4`})})]})]})]})]}),document.body)};function de({kind:e,refreshKey:t,onCountChange:n,onEditImage:r}){let{t:a}=d(),o=i(),[s,c]=(0,R.useState)(null),[l,u]=(0,R.useState)(null),f=te({queryKey:[`media-gallery`,e||`all`,t||0],queryFn:async({pageParam:t})=>{let n=await O.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,R.useMemo)(()=>f.data?.pages.flatMap(e=>e.media)||[],[f.data]),m=f.data?.pages[0]?.total||0;(0,R.useEffect)(()=>n?.(m),[n,m]);let h=async e=>{if(!l){u(e.id);try{let t=await O.deleteGalleryItem(e.id);if(!t.success)throw Error(t.message);c(null),await o.invalidateQueries({queryKey:[`media-gallery`]}),x.success(a(`imageGallery.deleteSuccess`))}catch{x.error(a(`imageGallery.deleteFailed`))}finally{u(null)}}},g=async e=>{let t=await O.getGalleryContent(e.id),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`generated-${e.id}.${pe(e.mimeType)}`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)};return f.isLoading?(0,z.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,z.jsx)(_,{className:`h-8 w-8 animate-spin text-gray-400`})}):p.length===0?(0,z.jsxs)(`div`,{className:`flex flex-col items-center justify-center rounded-2xl border border-dashed border-gray-300 bg-white/30 px-6 py-12 text-center dark:border-white/15 dark:bg-white/[0.02]`,children:[(0,z.jsx)(b,{className:`mb-4 h-10 w-10 text-gray-300 dark:text-gray-600`}),(0,z.jsx)(`h3`,{className:`text-lg font-medium`,children:a(`mediaGallery.empty`)}),(0,z.jsx)(`p`,{className:`mt-2 max-w-sm text-gray-500 dark:text-gray-400`,children:a(`mediaGallery.emptyHint`)})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.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,z.jsxs)(`article`,{className:`overflow-hidden rounded-2xl border border-gray-200/80 bg-white/70 dark:border-white/10 dark:bg-white/[0.025]`,children:[(0,z.jsx)(fe,{item:e,onOpenImage:t=>c(q(e,t))}),(0,z.jsxs)(`div`,{className:`space-y-3 p-3`,children:[(0,z.jsx)(`p`,{className:`line-clamp-2 text-sm text-gray-800 dark:text-gray-200`,children:e.prompt}),(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,z.jsx)(`span`,{className:`min-w-0 truncate text-xs text-gray-500`,children:e.model}),(0,z.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[e.kind===`image`&&r&&(0,z.jsx)(`button`,{onClick:()=>r(e),className:`rounded-lg p-1.5 hover:bg-gray-100 dark:hover:bg-white/10`,title:a(`imageEdit.title`),"data-testid":`edit-image-${e.id}`,children:(0,z.jsx)(C,{className:`h-4 w-4`})}),(0,z.jsx)(`button`,{onClick:()=>void g(e),className:`rounded-lg p-1.5 hover:bg-gray-100 dark:hover:bg-white/10`,title:a(`imageGallery.download`),children:(0,z.jsx)(v,{className:`h-4 w-4`})}),(0,z.jsx)(`button`,{onClick:()=>void h(e),disabled:l===e.id,className:`rounded-lg p-1.5 hover:bg-red-500/15 hover:text-red-500`,title:a(`imageGallery.delete`),children:l===e.id?(0,z.jsx)(_,{className:`h-4 w-4 animate-spin`}):(0,z.jsx)(E,{className:`h-4 w-4`})})]})]})]})]},e.id))}),f.hasNextPage&&(0,z.jsx)(`div`,{className:`mt-8 flex justify-center`,children:(0,z.jsx)(P,{variant:`outline`,disabled:f.isFetchingNextPage,onClick:()=>void f.fetchNextPage(),children:f.isFetchingNextPage?a(`common.loading`):a(`imageGallery.loadMore`,{current:p.length,total:m})})}),s&&(0,z.jsx)(ue,{image:s,onClose:()=>c(null),onDelete:e=>{let t=p.find(t=>t.id===e);t&&h(t)},onDownload:e=>{let t=p.find(t=>t.id===e.id);t&&g(t)}})]})}function fe({item:e,onOpenImage:t}){let{data:n,isLoading:r}=l({queryKey:[`media-gallery-content`,e.id],queryFn:()=>O.getGalleryContent(e.id),staleTime:3e5}),i=(0,R.useMemo)(()=>n?URL.createObjectURL(n):``,[n]),a=(0,R.useRef)(new Map);return(0,R.useEffect)(()=>{if(!i)return;let e=a.current,t=e.get(i);return t&&(clearTimeout(t),e.delete(i)),()=>{e.set(i,setTimeout(()=>{e.delete(i),URL.revokeObjectURL(i)},0))}},[i]),r||!i?(0,z.jsx)(`div`,{className:`flex aspect-video items-center justify-center bg-gray-100 dark:bg-white/[0.03]`,children:(0,z.jsx)(_,{className:`h-6 w-6 animate-spin text-gray-400`})}):e.kind===`image`?(0,z.jsx)(`button`,{className:`block aspect-square w-full overflow-hidden`,onClick:()=>t(i),children:(0,z.jsx)(`img`,{src:i,alt:e.prompt,className:`h-full w-full object-cover`,loading:`lazy`})}):e.kind===`video`?(0,z.jsx)(`div`,{className:`aspect-video bg-black`,children:(0,z.jsx)(`video`,{src:i,controls:!0,preload:`metadata`,className:`h-full w-full object-contain`})}):(0,z.jsxs)(`div`,{className:`flex min-h-40 flex-col items-center justify-center gap-3 bg-gradient-to-br from-primary-500/10 to-cyan-500/10 p-4`,children:[(0,z.jsx)(T,{className:`h-9 w-9 text-primary-500`}),(0,z.jsx)(`audio`,{src:i,controls:!0,preload:`metadata`,className:`w-full`})]})}function q(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 pe(e){let t=e.split(`/`)[1]?.split(`;`)[0];return t===`mpeg`?e.startsWith(`audio/`)?`mp3`:`mpeg`:t===`svg+xml`?`svg`:t||`bin`}var me=()=>{let{t:e}=d(),[t,n]=(0,R.useState)(null),[r,i]=(0,R.useState)(!1),[a,o]=(0,R.useState)(null),[s,c]=(0,R.useState)(`all`),[l,u]=(0,R.useState)(null),[p,m]=(0,R.useState)(0),h=N(e=>e.preferences.imageGenSettings?.enabled===!0),g=(0,R.useCallback)(()=>{m(e=>e+1)},[]);return(0,z.jsxs)(I,{width:`wide`,children:[(0,z.jsx)(F,{title:e(`sidebar.navigation.imagine`),description:e(`gallery.subtitle`),meta:t!==null&&t>0?(0,z.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/[0.04] dark:text-dark-500`,children:e(`mediaGallery.itemCount`,{count:t})}):null,actions:(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,z.jsxs)(P,{onClick:()=>{h&&i(!0)},disabled:!h,className:`gap-2 px-4`,children:[(0,z.jsx)(y,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`gallery.generate`)]}),(0,z.jsxs)(P,{variant:`outline`,onClick:()=>o(`video`),className:`gap-2 px-4`,children:[(0,z.jsx)(S,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`mediaGeneration.video`)]}),(0,z.jsxs)(P,{variant:`outline`,onClick:()=>o(`audio`),className:`gap-2 px-4`,children:[(0,z.jsx)(T,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`mediaGeneration.audio`)]})]})}),(0,z.jsx)(`div`,{className:`mb-5 flex flex-wrap gap-2`,children:[`all`,`image`,`video`,`audio`].map(t=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>c(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,z.jsx)(de,{kind:s===`all`?void 0:s,refreshKey:p,onCountChange:n,onEditImage:u}),(0,z.jsx)(le,{isOpen:l!==null,source:l,onClose:()=>u(null),onEdited:g}),(0,z.jsx)(B,{isOpen:r&&h,onClose:()=>i(!1),onImageGenerated:g}),(0,z.jsx)(V,{isOpen:a!==null,initialKind:a||`video`,onClose:()=>o(null),onGenerated:g},a||`closed`)]})};export{me as GalleryPage,me as default};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{d as r}from"./router-vendor-CMbYTGdh.js";import{t as i}from"./useTranslation-rdLmo6zV.js";import{a,r as o,t as s}from"./utils-CKWltgs8.js";import{t as c}from"./chatStore-DYm9cXVV.js";import{$n as l,Et as u,M as d,c as f,in as p,mt as m,or as h,t as g,tr as _}from"./ui-vendor-BvD5yGW1.js";import{d as v,t as y}from"./authStore-DbDFBMx0.js";import{t as b}from"./workStatus-CcO9Fg41.js";import{n as x,r as S,t as C}from"./appNavigation-DAd7SkU_.js";import{t as w}from"./appVersion-RvElMU1Q.js";import{t as T}from"./work-DVgm81bJ.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-gray-500 dark:text-dark-500`,A=`group flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-start text-sm text-gray-700 transition-colors hover:bg-white hover:text-gray-950 dark:text-dark-700 dark:hover:bg-dark-200 dark:hover:text-dark-950 outline-none focus-visible:ring-2 focus-visible:ring-primary-500/40`,j=()=>{let{t:e,i18n:t}=i(),n=r(),{user:j,systemInfo:M,canUseWork:N,canUseAgents:P}=y(),F=c(e=>e.sessions),I=c(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=a()?`⌘`:`Ctrl`,Y=G.length>0||K.length>0,X=w(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-gray-950 dark:text-dark-950`,children:W?`${U}, ${W}.`:`${U}.`}),(0,D.jsxs)(`p`,{"data-testid":`app-version`,className:`mt-1 font-mono text-xs text-gray-400 dark:text-dark-500`,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:()=>x(n),children:[(0,D.jsx)(u,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-600 dark:text-dark-500 dark:group-hover:text-dark-700`}),(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-gray-400 opacity-0 transition-opacity group-hover:opacity-100 dark:text-dark-500`,children:[J,`⇧O`]})]}),(0,D.jsxs)(`button`,{type:`button`,"data-testid":`home-incognito-chat`,className:A,onClick:()=>C(n),children:[(0,D.jsx)(p,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-600 dark:text-dark-500 dark:group-hover:text-dark-700`}),(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:()=>S(n),children:[(0,D.jsx)(_,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-600 dark:text-dark-500 dark:group-hover:text-dark-700`}),(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-gray-400 opacity-0 transition-opacity group-hover:opacity-100 dark:text-dark-500`,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:s(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-gray-400 dark:text-dark-500`,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];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:s(`h-2 w-2 shrink-0 rounded-full ring-1 ring-black/[0.06] dark:ring-white/[0.1]`,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-[14rem] shrink-0 truncate font-mono text-[10px] text-gray-400 sm:inline dark:text-dark-500`,title:r.hostPath,children:r.hostPath}),(0,D.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] text-gray-400 dark:text-dark-500`,children:T(r)?e(i.labelKey,i.label):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)(u,{className:`h-4 w-4 shrink-0 text-gray-400 dark:text-dark-500`}),(0,D.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:r.title||e(`tabs.chat`,`Chat`)}),(0,D.jsx)(`span`,{className:`hidden shrink-0 font-mono text-[10px] text-gray-400 sm:inline dark:text-dark-500`,children:r.model.startsWith(`persona:`)?I.find(e=>e.isPersona&&e.name===r.model)?.personaName||e(`chat.persona.label`,`Persona`):r.model}),(0,D.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] text-gray-400 dark:text-dark-500`,children: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`,m,e(`sidebar.navigation.notes`,`Notes`)],[`/calendar`,l,e(`sidebar.navigation.calendar`,`Calendar`)],[`/automations`,g,e(`sidebar.navigation.automations`,`Automations`)],[`/personas`,f,e(`sidebar.navigation.personas`,`Personas`)],[`/gallery`,d,e(`sidebar.navigation.imagine`,`Imagine`)],...H?[[`/agents`,h,e(`sidebar.navigation.agents`,`Agents`)]]:[]].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-gray-400 transition-colors group-hover:text-gray-600 dark:text-dark-500 dark:group-hover:text-dark-700`}),(0,D.jsx)(`span`,{className:`flex-1`,children:r})]},e))})]})]})})};export{j as HomePage,j as default};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{d as r}from"./router-vendor-Epc3_KZ_.js";import{t as i}from"./useTranslation-rdLmo6zV.js";import{a,r as o,t as s}from"./utils-CKWltgs8.js";import{t as c}from"./chatStore-BvZkd8Un.js";import{$n as l,Et as u,M as d,c as f,in as p,mt as m,or as h,t as g,tr as _}from"./ui-vendor-Dt9hfsGD.js";import{d as v,t as y}from"./authStore-CieFdk4S.js";import{t as b}from"./workStatus-CcO9Fg41.js";import{n as x,r as S,t as C}from"./appNavigation-DySHcEGS.js";import{t as w}from"./appVersion-CAidQlBP.js";import{t as T}from"./work-DVgm81bJ.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-gray-500 dark:text-dark-500`,A=`group flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-start text-sm text-gray-700 transition-colors hover:bg-white hover:text-gray-950 dark:text-dark-700 dark:hover:bg-dark-200 dark:hover:text-dark-950 outline-none focus-visible:ring-2 focus-visible:ring-primary-500/40`,j=()=>{let{t:e,i18n:t}=i(),n=r(),{user:j,systemInfo:M,canUseWork:N,canUseAgents:P}=y(),F=c(e=>e.sessions),I=c(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=a()?`⌘`:`Ctrl`,Y=G.length>0||K.length>0,X=w(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-gray-950 dark:text-dark-950`,children:W?`${U}, ${W}.`:`${U}.`}),(0,D.jsxs)(`p`,{"data-testid":`app-version`,className:`mt-1 font-mono text-xs text-gray-400 dark:text-dark-500`,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:()=>x(n),children:[(0,D.jsx)(u,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-600 dark:text-dark-500 dark:group-hover:text-dark-700`}),(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-gray-400 opacity-0 transition-opacity group-hover:opacity-100 dark:text-dark-500`,children:[J,`⇧O`]})]}),(0,D.jsxs)(`button`,{type:`button`,"data-testid":`home-incognito-chat`,className:A,onClick:()=>C(n),children:[(0,D.jsx)(p,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-600 dark:text-dark-500 dark:group-hover:text-dark-700`}),(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:()=>S(n),children:[(0,D.jsx)(_,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-600 dark:text-dark-500 dark:group-hover:text-dark-700`}),(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-gray-400 opacity-0 transition-opacity group-hover:opacity-100 dark:text-dark-500`,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:s(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-gray-400 dark:text-dark-500`,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];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:s(`h-2 w-2 shrink-0 rounded-full ring-1 ring-black/[0.06] dark:ring-white/[0.1]`,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-[14rem] shrink-0 truncate font-mono text-[10px] text-gray-400 sm:inline dark:text-dark-500`,title:r.hostPath,children:r.hostPath}),(0,D.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] text-gray-400 dark:text-dark-500`,children:T(r)?e(i.labelKey,i.label):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)(u,{className:`h-4 w-4 shrink-0 text-gray-400 dark:text-dark-500`}),(0,D.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:r.title||e(`tabs.chat`,`Chat`)}),(0,D.jsx)(`span`,{className:`hidden shrink-0 font-mono text-[10px] text-gray-400 sm:inline dark:text-dark-500`,children:r.model.startsWith(`persona:`)?I.find(e=>e.isPersona&&e.name===r.model)?.personaName||e(`chat.persona.label`,`Persona`):r.model}),(0,D.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] text-gray-400 dark:text-dark-500`,children: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`,m,e(`sidebar.navigation.notes`,`Notes`)],[`/calendar`,l,e(`sidebar.navigation.calendar`,`Calendar`)],[`/automations`,g,e(`sidebar.navigation.automations`,`Automations`)],[`/personas`,f,e(`sidebar.navigation.personas`,`Personas`)],[`/gallery`,d,e(`sidebar.navigation.imagine`,`Imagine`)],...H?[[`/agents`,h,e(`sidebar.navigation.agents`,`Agents`)]]:[]].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-gray-400 transition-colors group-hover:text-gray-600 dark:text-dark-500 dark:group-hover:text-dark-700`}),(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-D0Ec-185.js";import{t as r}from"./useTranslation-rdLmo6zV.js";import{t as i}from"./utils-CKWltgs8.js";import{C as a,D as o,E as s}from"./chatStore-BvZkd8Un.js";import{E as c,In as l,J as u,Jn as d,T as f,_t as p,ct as m,w as h}from"./ui-vendor-Dt9hfsGD.js";import{t as g}from"./authStore-CieFdk4S.js";import{f as _,l as v,n as y,p as b,t as x,u as S}from"./appStore-DrTsJPfh.js";var C=e(t(),1),w=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=Math.round(s/255*1+o),l=Math.max(0,Math.min(1,c))*255/1/s;for(let t=0;t<3;t+=1)r[a+t]=e[a+t]*l}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=x(e=>e.theme.mode),l=S(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=x(e=>e.preferences.backgroundSettings),n=x(e=>e.backgroundImage),r=g(e=>e.user?.id),i=g(e=>e.systemInfo?.requiresAuth),a=y(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}=r(),t=S(e=>e.palette),n=S(e=>e.previewMinutes),a=S(e=>e.location),o=S(e=>e.weather),s=S(e=>e.weatherEnabled),d=new Date().setHours(0,0,0,0),g=s&&a?o:null,y=(0,C.useMemo)(()=>{let e=new Date(d);return`linear-gradient(to right, ${Array.from({length:17},(t,n)=>{let r=Math.min(n*1440/16,1439);return`${b(e,r,{location:a,weather:g}).sky.mid} ${n*100/16}%`}).join(`, `)})`},[d,a,g]);if(!t)return null;let x=B(n??t.solar.minutes),w=_(x),T=n!==null,E=t.solar.isDay?c:p,D=T?m:l,O=[{key:`sunrise`,minutes:t.solar.sunrise,Icon:f},{key:`sunset`,minutes:t.solar.sunset,Icon:h}];return(0,I.jsxs)(`div`,{className:`celestial-day-preview flex min-w-0 flex-col gap-3`,style:{"--celestial-day-gradient":y,"--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, ${x/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:x,onChange:e=>v(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-none 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:_(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`,onClick:()=>v(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-none 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:_(n)})]})]},t))}),(0,I.jsxs)(`button`,{type:`button`,onClick:()=>v(null),disabled:!T,"data-testid":`celestial-follow-clock`,className:i(`flex items-center justify-center gap-2 rounded-xl border px-3 py-2 text-xs font-medium outline-none 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)(u,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}):(0,I.jsx)(l,{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}=r();return(0,I.jsxs)(`div`,{className:i(`flex items-center gap-4`,!e&&`py-4`),children:[(0,I.jsxs)(`div`,{className:i(`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-subtle`,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:s(n.language),onChange:e=>{let t=e.target.value;a(t)},className:i(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-none focus-visible:ring-2 focus-visible:ring-primary-500/40`),children:o.map(t=>(0,I.jsx)(`option`,{value:t.code,children:e?t.nativeName:`${t.nativeName} (${t.name})`},t.code))}),(0,I.jsx)(d,{className:`pointer-events-none absolute end-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};