libre-webui 0.34.0 → 0.34.1

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 (119) 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 +1 -1
  26. package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
  27. package/frontend/dist/assets/index-Bv773ECu.js +17 -0
  28. package/frontend/dist/assets/index-CxFIHoRc.css +1 -0
  29. package/frontend/dist/index.html +18 -17
  30. package/frontend/dist/js/{ArtifactContainer-8ZacPNwg.js → ArtifactContainer-Cdrv0kJM.js} +1 -1
  31. package/frontend/dist/js/{ArtifactDemoPage-DvvT45ZJ.js → ArtifactDemoPage-BcXPfD-W.js} +1 -1
  32. package/frontend/dist/js/{ArtifactSandboxFrame-Dbp1bB_9.js → ArtifactSandboxFrame-5qM5QELi.js} +1 -1
  33. package/frontend/dist/js/{ArtifactSlideOutPanel-Ct9nlG_6.js → ArtifactSlideOutPanel-tuGsj_HW.js} +1 -1
  34. package/frontend/dist/js/{AutomationModal-Ie_MxC18.js → AutomationModal-DL9kNzgL.js} +1 -1
  35. package/frontend/dist/js/{AutomationsPage-Czg-rMEr.js → AutomationsPage-BMtR7wCN.js} +1 -1
  36. package/frontend/dist/js/{AvatarUpload-DgyIHr7P.js → AvatarUpload-DrfSzzOZ.js} +1 -1
  37. package/frontend/dist/js/{CalendarPage-D1ZeHpZ0.js → CalendarPage-BBkLlXa5.js} +1 -1
  38. package/frontend/dist/js/ChannelsPage-C2KWU3sZ.js +1 -0
  39. package/frontend/dist/js/ChatPage-CWsAjCPP.js +14 -0
  40. package/frontend/dist/js/{ConnectModels-Cg7Wp-43.js → ConnectModels-flyZgito.js} +1 -1
  41. package/frontend/dist/js/{EvaluationsPage-BBafHC8o.js → EvaluationsPage-DUntWRVo.js} +1 -1
  42. package/frontend/dist/js/{FirstTimeSetup-Cd9cLLz6.js → FirstTimeSetup-CMQ000Hh.js} +1 -1
  43. package/frontend/dist/js/{GalleryPage-6aa0A9fS.js → GalleryPage-DNSo3Q0p.js} +1 -1
  44. package/frontend/dist/js/{HomePage-1vKjY6Aw.js → HomePage-BOXsuk3g.js} +1 -1
  45. package/frontend/dist/js/LanguageSwitcher-BIrE0C-N.js +1 -0
  46. package/frontend/dist/js/{LibreClawPage-DXxJP96Q.js → LibreClawPage-D97-90n6.js} +1 -1
  47. package/frontend/dist/js/ModelManagerModals-DzEVkCuT.js +1 -0
  48. package/frontend/dist/js/NotesPage-VBGqE4aV.js +3 -0
  49. package/frontend/dist/js/{PersonasPage-HYkaAXAe.js → PersonasPage-D8-4PyoM.js} +1 -1
  50. package/frontend/dist/js/{PluginUsagePage-B2MRIZme.js → PluginUsagePage-CHcweo11.js} +1 -1
  51. package/frontend/dist/js/RichMessageContent-D7wqrY68.js +1 -0
  52. package/frontend/dist/js/{RichMessageContent-BnpRgouz.js → RichMessageContent-yWLHf4YS.js} +2 -2
  53. package/frontend/dist/js/SettingsModal-CxVt1ObR.js +19 -0
  54. package/frontend/dist/js/{ShareDialog-BdFJRfxV.js → ShareDialog-J5zbwIWY.js} +1 -1
  55. package/frontend/dist/js/{SystemPage-DkKnu35i.js → SystemPage-CEjZpR5I.js} +1 -1
  56. package/frontend/dist/js/{UserManagementPanel-Dpn15Nyr.js → UserManagementPanel-Dhwk4I0s.js} +1 -1
  57. package/frontend/dist/js/{WhatsNewModal-BH-kE-Wb.js → WhatsNewModal-5lCndkFc.js} +1 -1
  58. package/frontend/dist/js/WorkPage-c8xOdYyy.js +7 -0
  59. package/frontend/dist/js/api-CHEuZtwG.js +1 -0
  60. package/frontend/dist/js/{api-HgGU3dII.js → api-DEOxp9DN.js} +1 -1
  61. package/frontend/dist/js/{appNavigation-DAd7SkU_.js → appNavigation-DToyRu19.js} +1 -1
  62. package/frontend/dist/js/appStore-Bsxed1km.js +2 -0
  63. package/frontend/dist/js/appVersion-CgCvuf4s.js +1 -0
  64. package/frontend/dist/js/{ar-CM3oZcHT.js → ar-DNI77Stn.js} +1 -1
  65. package/frontend/dist/js/authStore-8w9Idb5o.js +4 -0
  66. package/frontend/dist/js/authStore-DwmcyHDN.js +1 -0
  67. package/frontend/dist/js/{bn-BuYroL_j.js → bn-u6oyZr4U.js} +1 -1
  68. package/frontend/dist/js/{chatStore-DYm9cXVV.js → chatStore-lyGhYu24.js} +3 -3
  69. package/frontend/dist/js/composerStyles-DqJg-2vE.js +1 -0
  70. package/frontend/dist/js/{config-BH2zUU2X.js → config-B5SBQwEe.js} +1 -1
  71. package/frontend/dist/js/{cs-D3NqP5wD.js → cs-BIkJ6jwb.js} +1 -1
  72. package/frontend/dist/js/{da-BGpE68rg.js → da-DV3V6XJ_.js} +1 -1
  73. package/frontend/dist/js/{de-BjYUQYNL.js → de-DdcTQ-vn.js} +1 -1
  74. package/frontend/dist/js/{es-vNJrO8Lj.js → es-Cw-ozFaX.js} +1 -1
  75. package/frontend/dist/js/{evaluationsApi-v6Qj2fFv.js → evaluationsApi-BvkmhMgQ.js} +1 -1
  76. package/frontend/dist/js/{fr-BvtHFXNM.js → fr-Y2NfnlYR.js} +1 -1
  77. package/frontend/dist/js/{hi-CUfuHlbY.js → hi-BKU62_1Y.js} +1 -1
  78. package/frontend/dist/js/{id-B4CE64s6.js → id-q6wo4InR.js} +1 -1
  79. package/frontend/dist/js/{is-Dr6Is7-Q.js → is-_B6QblCu.js} +1 -1
  80. package/frontend/dist/js/{it-Cj4NfoeU.js → it-NUupXhzK.js} +1 -1
  81. package/frontend/dist/js/{ja-DByiJVO0.js → ja-BUvl9RXq.js} +1 -1
  82. package/frontend/dist/js/{ko-DqBvZqIv.js → ko-df4leR83.js} +1 -1
  83. package/frontend/dist/js/{messageCodeStyles-ERvWXB7Y.js → messageCodeStyles-DchDafYE.js} +1 -1
  84. package/frontend/dist/js/{ms-DobJ-R5X.js → ms-CN-7Q9S2.js} +1 -1
  85. package/frontend/dist/js/{nl-D4tVIakl.js → nl-OEm4uNIo.js} +1 -1
  86. package/frontend/dist/js/{pl-BIoYiVJA.js → pl-B9pHpjg7.js} +1 -1
  87. package/frontend/dist/js/{pt-Bzww3XtB.js → pt-D3uaEKud.js} +1 -1
  88. package/frontend/dist/js/{ru-lqQ-JuMd.js → ru-z9H07lhi.js} +1 -1
  89. package/frontend/dist/js/{sv-9dcksSEJ.js → sv-GkQDA4wx.js} +1 -1
  90. package/frontend/dist/js/{teamEventStream-CTyr4r5f.js → teamEventStream-C0_UAzCG.js} +1 -1
  91. package/frontend/dist/js/{th-DuOX28lk.js → th-0hzCkDzt.js} +1 -1
  92. package/frontend/dist/js/{tr-Dz7bMTi1.js → tr-CZDobfHQ.js} +1 -1
  93. package/frontend/dist/js/ui-BQojEu4t.js +2 -0
  94. package/frontend/dist/js/{uk-aTAky5l4.js → uk-BwspIPCI.js} +1 -1
  95. package/frontend/dist/js/{useChat-CXcosgJB.js → useChat-CDllZR7C.js} +1 -1
  96. package/frontend/dist/js/useDialogFocus-BQLdAGYH.js +1 -0
  97. package/frontend/dist/js/{vi-CHcYXhCs.js → vi-Dipdv5ta.js} +1 -1
  98. package/frontend/dist/js/{workApi-CntsmsAA.js → workApi-0L8fBGq1.js} +2 -2
  99. package/frontend/dist/js/workApi-BjDBLsFh.js +1 -0
  100. package/frontend/dist/js/{zh-DvvksD8_.js → zh-CgdWmtP_.js} +1 -1
  101. package/package.json +4 -4
  102. package/frontend/dist/assets/index-By_-fwuh.css +0 -1
  103. package/frontend/dist/assets/index-D3XhYdgN.js +0 -108
  104. package/frontend/dist/js/ChannelsPage-DgXZdSLa.js +0 -1
  105. package/frontend/dist/js/ChatPage-ov4Xlf8Q.js +0 -14
  106. package/frontend/dist/js/ModelManagerModals-BBGWbTTi.js +0 -1
  107. package/frontend/dist/js/NotesPage-DCLkl9a9.js +0 -3
  108. package/frontend/dist/js/RichMessageContent-2fzm0XIM.js +0 -1
  109. package/frontend/dist/js/SettingsModal-4ITUSJqi.js +0 -19
  110. package/frontend/dist/js/WorkPage-CCyCPnwr.js +0 -7
  111. package/frontend/dist/js/api-DOlirnw_.js +0 -1
  112. package/frontend/dist/js/appStore-DefVAJAx.js +0 -2
  113. package/frontend/dist/js/appVersion-RvElMU1Q.js +0 -1
  114. package/frontend/dist/js/authStore-AE-cc9PJ.js +0 -1
  115. package/frontend/dist/js/authStore-DbDFBMx0.js +0 -4
  116. package/frontend/dist/js/ui-CHgZA8lG.js +0 -2
  117. package/frontend/dist/js/useDictation-BGlY44fp.js +0 -1
  118. package/frontend/dist/js/webauthnClient-B1yv1m81.js +0 -1
  119. package/frontend/dist/js/workApi-nKavXIsg.js +0 -1
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{C as r,t as i}from"./useQuery-BKulzCS7.js";import{t as a}from"./logger-DnuT4jgB.js";import{t as o}from"./useTranslation-rdLmo6zV.js";import{t as s}from"./utils-CKWltgs8.js";import{t as c}from"./chatStore-DYm9cXVV.js";import{B as l,D as u,En as d,Et as f,Fn as p,Ft as m,H as h,Ht as g,Jt as _,M as v,N as ee,Tn as y,Ut as b,Yn as x,Z as S,_ as C,c as w,g as T,gn as E,gr as te,j as D,n as O,nr as k,p as A,rt as j,t as M,tt as N,v as P,wn as F,xr as I}from"./ui-vendor-BvD5yGW1.js";import{M as L,_ as R,d as z,f as B,g as V,j as H,m as U,p as W}from"./api-HgGU3dII.js";import{t as G}from"./appStore-DefVAJAx.js";import{t as K}from"./Button-BxwbQ5xw.js";import{a as ne,o as re}from"./ui-CHgZA8lG.js";import{t as ie}from"./AvatarUpload-DgyIHr7P.js";import{t as ae}from"./ShareDialog-BdFJRfxV.js";var q=e(t(),1),J=n(),Y=a(`components:persona-card`),oe=({persona:e,onEdit:t,onDelete:n,onDownload:a,onSelect:c,onToggleFavorite:p,isSelected:m=!1,compact:g=!1})=>{let{t:_}=o(),ee=r(),[b,x]=(0,q.useState)(!1),[S,C]=(0,q.useState)(!1),[w,O]=(0,q.useState)(!1),A=!!(e.memory_settings?.enabled||e.mutation_settings?.enabled),{data:N=null}=i({queryKey:[`persona-memory-status`,e.id],queryFn:async()=>{let t=await U.getMemoryStatus(e.id);return t.success&&t.data?t.data:null},enabled:A}),L=()=>ee.invalidateQueries({queryKey:[`persona-memory-status`,e.id]}),z=async()=>{if(confirm(_(`personaCard.wipeConfirm`))){O(!0);try{let t=await U.wipeMemories(e.id);t.success?(I.success(_(`personaCard.wipeSuccess`,{count:t.data?.deleted_count||0})),await L()):I.error(_(`personaCard.failed`,{action:`wipe memories`}))}catch(e){I.error(_(`personaCard.failed`,{action:`wipe memories`})),Y.error(e)}finally{O(!1),x(!1)}}},B=async()=>{O(!0);try{let t=await U.backupPersona(e.id),n=window.URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${e.name.toLowerCase().replace(/\s+/g,`-`)}-backup.json`,document.body.appendChild(r),r.click(),window.URL.revokeObjectURL(n),document.body.removeChild(r),I.success(_(`personaCard.backupSuccess`))}catch(e){I.error(_(`personaCard.failed`,{action:`backup persona`})),Y.error(e)}finally{O(!1),x(!1)}},H=async()=>{O(!0);try{let t=await U.exportPersonaDNA(e.id),n=window.URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${e.name.toLowerCase().replace(/\s+/g,`-`)}-dna.json`,document.body.appendChild(r),r.click(),window.URL.revokeObjectURL(n),document.body.removeChild(r),I.success(_(`personaCard.dnaSuccess`))}catch(e){I.error(_(`personaCard.failed`,{action:`export persona DNA`})),Y.error(e)}finally{O(!1),x(!1)}},W=(t=128)=>V(e,t),G=(t=128)=>n=>{R(n.currentTarget,e.name,t)};return g?(0,J.jsxs)(`div`,{className:s(`group relative flex items-center gap-3 p-3 rounded-xl cursor-pointer transition-all duration-200`,`border border-transparent`,`hover:bg-gray-50 dark:hover:bg-dark-100`,m&&[`bg-primary-50 dark:bg-primary-900/20`,`border-primary-200 dark:border-primary-700`]),onClick:()=>c?.(e),children:[(0,J.jsxs)(`div`,{className:`relative flex-shrink-0`,children:[(0,J.jsx)(`img`,{src:W(64),alt:e.name,className:`w-10 h-10 rounded-full object-cover ring-2 ring-white dark:ring-dark-100`,onError:G(64)}),A&&(0,J.jsx)(`div`,{className:`absolute -bottom-0.5 -end-0.5 flex h-4 w-4 items-center justify-center rounded-full bg-primary-600`,children:(0,J.jsx)(v,{className:`h-2.5 w-2.5 text-white`})})]}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`h4`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100 truncate`,children:e.name}),e.is_favorite&&(0,J.jsx)(u,{className:`h-3 w-3 text-amber-500 fill-amber-500 flex-shrink-0`})]}),(0,J.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 truncate`,children:e.model})]}),m&&(0,J.jsx)(`div`,{className:`flex-shrink-0`,children:(0,J.jsx)(`div`,{className:`w-6 h-6 rounded-full bg-primary-500 dark:bg-primary-600 flex items-center justify-center`,children:(0,J.jsx)(j,{className:`h-3 w-3 text-white rtl:rotate-180`})})})]}):(0,J.jsxs)(`div`,{className:s(`group relative overflow-hidden rounded-2xl transition-[border-color,background-color] duration-200`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`hover:border-gray-300 dark:hover:border-white/20`,m&&[`ring-2 ring-primary-500 dark:ring-primary-400`,`border-primary-300 dark:border-primary-600`]),children:[(0,J.jsxs)(`div`,{className:`relative h-24`,children:[e.background?(0,J.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,J.jsx)(`div`,{className:`absolute inset-0 bg-gray-200 dark:bg-dark-200`}),e.background&&(0,J.jsx)(`div`,{className:`absolute inset-0 bg-black/15 dark:bg-black/25`}),(0,J.jsxs)(`div`,{className:`absolute inset-x-3 top-3 flex items-start justify-between`,children:[(0,J.jsx)(`button`,{onClick:t=>{t.stopPropagation(),p?.(e)},className:s(`p-1.5 rounded-full transition-all duration-200`,`border border-white/30 bg-black/20 text-white backdrop-blur-sm hover:bg-black/30`,e.is_favorite&&`bg-amber-500/80 hover:bg-amber-500`),children:(0,J.jsx)(u,{className:s(`h-4 w-4`,e.is_favorite?`fill-ink text-ink dark:fill-ink-inverse dark:text-ink-inverse`:`text-white/80 hover:text-white`)})}),A&&(0,J.jsxs)(`div`,{className:`flex items-center gap-1 rounded-full border border-white/30 bg-black/20 px-2 py-1 text-[10px] font-medium text-white backdrop-blur-sm`,children:[(0,J.jsx)(v,{className:`h-3 w-3`}),_(`personaCard.enhanced`)]})]})]}),(0,J.jsx)(`div`,{className:`relative -mt-8 px-4`,children:(0,J.jsxs)(`div`,{className:`relative inline-block`,children:[(0,J.jsx)(`img`,{src:W(128),alt:e.name,className:`h-16 w-16 rounded-xl object-cover ring-4 ring-white dark:ring-dark-100`,onError:G(128)}),A&&(0,J.jsx)(`div`,{className:`absolute -bottom-1 -end-1 flex h-6 w-6 items-center justify-center rounded-lg bg-primary-600 ring-2 ring-white dark:ring-dark-100`,children:(0,J.jsx)(k,{className:`h-3.5 w-3.5 text-white`})})]})}),(0,J.jsxs)(`div`,{className:`px-4 pt-3 pb-4`,children:[(0,J.jsxs)(`div`,{className:`mb-3`,children:[(0,J.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 leading-tight`,children:e.name}),(0,J.jsxs)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 flex items-center gap-1.5 mt-0.5`,children:[(0,J.jsx)(h,{className:`h-3.5 w-3.5`}),e.model]})]}),e.description&&(0,J.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 line-clamp-2 mb-3`,children:e.description}),e.parameters.system_prompt&&(0,J.jsxs)(`div`,{className:`mb-3 rounded-xl border border-gray-200/70 bg-gray-50/70 p-2.5 dark:border-white/[0.08] dark:bg-white/[0.025]`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-1`,children:[(0,J.jsx)(f,{className:`h-3 w-3 text-gray-400 dark:text-gray-500`}),(0,J.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider font-medium text-gray-400 dark:text-gray-500`,children:_(`personaCard.systemPrompt`)})]}),(0,J.jsxs)(`p`,{className:`line-clamp-2 text-xs leading-5 text-gray-600 dark:text-gray-400`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-3`,children:[(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-lg border border-gray-200/70 px-2 py-1 text-[11px] font-medium text-gray-600 dark:border-white/[0.08] dark:text-gray-400`,children:[(0,J.jsx)(M,{className:`h-3 w-3`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,J.jsxs)(`span`,{className:`inline-flex items-center rounded-lg border border-gray-200/70 px-2 py-1 text-[11px] font-medium text-gray-600 dark:border-white/[0.08] dark:text-gray-400`,children:[`Top-P `,e.parameters.top_p?.toFixed(1)||`0.9`]}),(0,J.jsxs)(`span`,{className:`inline-flex items-center rounded-lg border border-gray-200/70 px-2 py-1 text-[11px] font-medium text-gray-600 dark:border-white/[0.08] dark:text-gray-400`,children:[(e.parameters.context_window||4096).toLocaleString(),` ctx`]})]}),A&&N&&(0,J.jsx)(`div`,{className:`mb-3 rounded-xl border border-primary-200/70 bg-primary-50/50 p-2.5 dark:border-primary-800/40 dark:bg-primary-900/10`,children:(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(d,{className:`h-4 w-4 text-primary-600 dark:text-primary-400`}),(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`span`,{className:`text-xs font-medium text-primary-700 dark:text-primary-300`,children:[N.memory_count,` `,_(`personaCard.memories`)]}),(0,J.jsx)(`span`,{className:`ms-2 text-[10px] text-primary-600/70 dark:text-primary-400/70`,children:(e=>e<1?`${(e*1024).toFixed(0)} KB`:`${e.toFixed(1)} MB`)(N.size_mb)})]})]}),N.status&&(0,J.jsx)(`span`,{className:s(`text-[10px] px-1.5 py-0.5 rounded-full font-medium`,N.status===`active`?`bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400`:`bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`),children:N.status})]})}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between border-t border-gray-200/70 pt-3 dark:border-white/[0.08]`,children:[c&&(0,J.jsxs)(K,{onClick:()=>c(e),size:`sm`,className:`px-4`,children:[(0,J.jsx)(j,{className:`me-1.5 h-3.5 w-3.5 rtl:rotate-180`}),_(`personaCard.use`)]}),(0,J.jsxs)(`div`,{className:`ms-auto flex items-center gap-1`,children:[(0,J.jsx)(`button`,{onClick:()=>t(e),className:`p-2 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-dark-200 transition-colors`,title:_(`personaCard.editTooltip`),children:(0,J.jsx)(D,{className:`h-4 w-4`})}),!e.shared&&(0,J.jsx)(`button`,{onClick:()=>C(!0),className:`p-2 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-dark-200 transition-colors`,title:_(`personaCard.shareTooltip`),"data-testid":`persona-share`,children:(0,J.jsx)(l,{className:`h-4 w-4`})}),(0,J.jsx)(`button`,{onClick:()=>a(e),className:`p-2 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-dark-200 transition-colors`,title:_(`personaCard.downloadTooltip`),children:(0,J.jsx)(y,{className:`h-4 w-4`})}),(0,J.jsxs)(`div`,{className:`relative`,children:[(0,J.jsx)(`button`,{onClick:()=>x(!b),className:`p-2 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-dark-200 transition-colors`,title:_(`common.more`,{defaultValue:`More`}),children:(0,J.jsx)(F,{className:`h-4 w-4`})}),b&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>x(!1)}),(0,J.jsxs)(`div`,{className:`absolute end-0 bottom-full z-20 mb-1 w-44 rounded-xl border border-gray-200 bg-white py-1 shadow-lg dark:border-white/10 dark:bg-dark-100`,children:[A&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{onClick:B,disabled:w,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-dark-50 disabled:opacity-50`,children:[(0,J.jsx)(te,{className:`h-4 w-4`}),_(`personaCard.backup`)]}),(0,J.jsxs)(`button`,{onClick:H,disabled:w,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-dark-50 disabled:opacity-50`,children:[(0,J.jsx)(E,{className:`h-4 w-4`}),_(`personaCard.exportDNA`)]}),N&&N.memory_count>0&&(0,J.jsxs)(`button`,{onClick:z,disabled:w,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 disabled:opacity-50`,children:[(0,J.jsx)(T,{className:`h-4 w-4`}),_(`personaCard.wipeMemories`)]}),(0,J.jsx)(`div`,{className:`my-1 border-t border-gray-100 dark:border-dark-200`})]}),(0,J.jsxs)(`button`,{onClick:()=>{n(e),x(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20`,children:[(0,J.jsx)(P,{className:`h-4 w-4`}),_(`common.delete`)]})]})]})]})]})]})]}),S&&(0,J.jsx)(ae,{resourceType:`persona`,resourceId:e.id,resourceLabel:e.name,onClose:()=>C(!1)})]})},X={name:``,description:``,model:``,parameters:{temperature:.7,top_p:.9,top_k:40,context_window:4096,max_tokens:1024,system_prompt:``,repeat_penalty:1.1,presence_penalty:0,frequency_penalty:0},avatar:``,background:``,embedding_model:``,memory_settings:{enabled:!1,max_memories:1e3,auto_cleanup:!0,retention_days:90},mutation_settings:{enabled:!1,sensitivity:`medium`,auto_adapt:!0}};function se({embeddingModel:e,embeddingModels:t,onEmbeddingModelChange:n}){let{t:r}=o(),i=t.filter(e=>e.isDetectedEmbedding),a=t.filter(e=>!e.isDetectedEmbedding);return(0,J.jsxs)(`div`,{className:`space-y-6`,children:[(0,J.jsxs)(`div`,{className:`rounded-xl p-5 bg-gradient-to-br from-primary-50 to-primary-100/50 dark:from-primary-900/30 dark:to-primary-800/20 border border-primary-200/50 dark:border-primary-700/30`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,J.jsx)(d,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`}),(0,J.jsx)(`h3`,{className:`font-semibold text-primary-900 dark:text-primary-100`,children:r(`personaForm.advanced.embeddingModel`)})]}),(0,J.jsx)(`p`,{className:`text-xs text-primary-600 dark:text-primary-400 mb-3`,children:r(`personaForm.advanced.embeddingHint`)}),(0,J.jsx)(`select`,{value:e,onChange:e=>n(e.target.value),className:`w-full px-3 py-2.5 border border-primary-200 dark:border-primary-700 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20`,children:t.length===0?(0,J.jsx)(`option`,{value:``,disabled:!0,children:r(`personaForm.advanced.noModels`)}):(0,J.jsxs)(J.Fragment,{children:[i.length>0&&(0,J.jsx)(`optgroup`,{label:r(`personaForm.advanced.embeddingModels`),children:i.map(e=>(0,J.jsxs)(`option`,{value:e.id,children:[e.name,` - `,e.description]},e.id))}),a.length>0&&(0,J.jsx)(`optgroup`,{label:r(`personaForm.advanced.otherModels`),children:a.map(e=>(0,J.jsxs)(`option`,{value:e.id,children:[e.name,` - `,e.description]},e.id))})]})}),t.length===0&&(0,J.jsx)(`div`,{className:`mt-3 rounded-lg border border-amber-200 bg-amber-500/10 p-3 dark:border-amber-700/50 dark:bg-amber-900/20`,children:(0,J.jsxs)(`p`,{className:`text-sm text-ink`,children:[r(`personaForm.advanced.installHint`),` `,(0,J.jsx)(`code`,{className:`rounded bg-amber-500/20 px-1.5 py-0.5 text-xs dark:bg-amber-900/40`,children:`ollama pull nomic-embed-text`})]})}),(0,J.jsx)(`p`,{className:`text-[10px] text-primary-500 dark:text-primary-500 mt-2`,children:r(`personaForm.advanced.recommended`)})]}),(0,J.jsx)(`div`,{className:`p-4 bg-gray-50 dark:bg-dark-50 rounded-xl border border-gray-200 dark:border-dark-300`,children:(0,J.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,J.jsx)(g,{className:`h-5 w-5 text-gray-400 mt-0.5 flex-shrink-0`}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`personaForm.advanced.aboutTitle`)}),(0,J.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:r(`personaForm.advanced.aboutDescription`)})]})]})})]})}var ce=a(`components:persona-background-upload`),le=({value:e,onChange:t,className:n=``})=>{let{t:r}=o(),i=(0,q.useRef)(null),[a,s]=(0,q.useState)(!1),[c,l]=(0,q.useState)(!1),u=async e=>{if(!e.type.startsWith(`image/`)){I.error(r(`personaBackground.invalidFile`));return}if(e.size>5242880){I.error(r(`personaBackground.fileTooLarge`));return}s(!0);try{let n=new FileReader;n.onload=e=>{let n=e.target?.result;t(n),I.success(r(`personaBackground.uploaded`))},n.onerror=()=>{I.error(r(`personaBackground.readFailed`))},n.readAsDataURL(e)}catch(e){ce.error(`Failed to upload background:`,e),I.error(r(`personaBackground.uploadFailed`))}finally{s(!1)}};return(0,J.jsx)(`div`,{className:`space-y-4 ${n}`,children:(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:r(`personaBackground.label`)}),(0,J.jsxs)(`div`,{className:`space-y-3`,children:[e?(0,J.jsxs)(`div`,{className:`space-y-3`,children:[(0,J.jsx)(`div`,{className:`w-full h-32 rounded-lg bg-cover bg-center border-2 border-gray-300 dark:border-dark-300`,style:{backgroundImage:`url(${e})`}}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-gray-50 dark:bg-dark-200 rounded-lg`,children:[(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:r(`personaBackground.customBackground`)}),(0,J.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:r(`personaBackground.clickToChange`)})]}),(0,J.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>{t(``),I.success(r(`personaBackground.removed`))},className:`text-red-600 hover:text-red-700 hover:bg-red-50 dark:text-red-400 dark:hover:text-red-300 dark:hover:bg-red-900/20`,children:(0,J.jsx)(O,{className:`h-4 w-4`})})]})]}):(0,J.jsxs)(`div`,{className:`border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${c?`border-primary-500 bg-primary-50 dark:bg-primary-900/20`:`border-gray-300 dark:border-gray-600 hover:border-gray-400 dark:hover:border-gray-500`}`,onDragOver:e=>{e.preventDefault(),l(!0)},onDragLeave:e=>{e.preventDefault(),l(!1)},onDrop:e=>{e.preventDefault(),l(!1);let t=e.dataTransfer.files?.[0];t&&u(t)},onClick:()=>i.current?.click(),children:[(0,J.jsx)(b,{className:`h-12 w-12 mx-auto text-gray-400 dark:text-gray-500 mb-4`}),(0,J.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-2`,children:r(`personaBackground.uploadBackgroundImage`)}),(0,J.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-4`,children:r(`personaBackground.dragAndDrop`)}),(0,J.jsxs)(K,{variant:`outline`,size:`sm`,disabled:a,className:`mx-auto`,children:[(0,J.jsx)(A,{className:`h-4 w-4 mr-2`}),r(a?`personaBackground.uploading`:`personaBackground.chooseImage`)]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1`,children:r(`personaBackground.enterImageUrl`)}),(0,J.jsx)(`input`,{type:`url`,value:e,onChange:e=>t(e.target.value),className:`w-full px-3 py-2 text-sm border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800`,placeholder:`https://example.com/background.jpg`})]})]}),(0,J.jsx)(`input`,{ref:i,type:`file`,accept:`image/*`,onChange:e=>{let t=e.target.files?.[0];t&&u(t)},className:`hidden`}),(0,J.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-2`,children:r(`personaBackground.supportedFormats`)})]})})};function ue({formData:e,availableModels:t,onFieldChange:n,onParameterChange:r}){let{t:i}=o(),a=(0,q.useMemo)(()=>t.filter(e=>!e.isPlugin),[t]),s=(0,q.useMemo)(()=>{let e=new Map;for(let n of t){if(!n.isPlugin)continue;let t=n.pluginName||n.pluginId||`Provider`,r=e.get(t);r?r.push(n):e.set(t,[n])}return[...e.entries()].sort(([e],[t])=>e.localeCompare(t))},[t]);return(0,J.jsxs)(`div`,{className:`space-y-6`,children:[(0,J.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:[i(`personaForm.basic.name`),` *`]}),(0,J.jsx)(`input`,{type:`text`,value:e.name,onChange:e=>n(`name`,e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-colors`,placeholder:i(`personaForm.basic.namePlaceholder`),required:!0})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:[i(`personaForm.basic.model`),` *`]}),(0,J.jsxs)(`select`,{value:e.model,onChange:e=>n(`model`,e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-colors`,required:!0,children:[(0,J.jsx)(`option`,{value:``,children:i(`personaForm.basic.selectModel`)}),e.model&&!t.some(t=>t.name===e.model)&&(0,J.jsx)(`option`,{value:e.model,children:e.model}),a.length>0&&(0,J.jsx)(`optgroup`,{label:`Ollama`,children:a.map(e=>(0,J.jsx)(`option`,{value:e.name,children:e.name},e.name))}),s.map(([e,t])=>(0,J.jsx)(`optgroup`,{label:e,children:t.map(e=>(0,J.jsx)(`option`,{value:e.name,children:e.name},e.name))},e))]})]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:i(`personaForm.basic.description`)}),(0,J.jsx)(`textarea`,{value:e.description,onChange:e=>n(`description`,e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-colors resize-none`,rows:3,placeholder:i(`personaForm.basic.descriptionPlaceholder`)})]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,J.jsx)(ie,{value:e.avatar||``,onChange:e=>n(`avatar`,e)}),(0,J.jsx)(le,{value:e.background||``,onChange:e=>n(`background`,e)})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:i(`personaForm.basic.systemPrompt`)}),(0,J.jsx)(`textarea`,{value:e.parameters.system_prompt,onChange:e=>r(`system_prompt`,e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-colors resize-none font-mono text-sm`,rows:6,placeholder:i(`personaForm.basic.systemPromptPlaceholder`)}),(0,J.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-600 mt-2`,children:i(`personaForm.basic.systemPromptHint`)})]})]})}function de({submitting:e,lastSaved:t,onCancel:n,onSave:r}){let{t:i}=o();return(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsx)(K,{type:`button`,variant:`ghost`,onClick:n,disabled:e,className:`text-gray-600 dark:text-gray-400`,children:i(`personaForm.actions.cancel`)}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[t&&(0,J.jsxs)(`div`,{role:`status`,"aria-live":`polite`,className:`flex items-center gap-1.5 text-sm text-emerald-600 dark:text-emerald-400`,children:[(0,J.jsx)(x,{className:`h-4 w-4`}),(0,J.jsx)(`span`,{children:i(`personaForm.saved`)})]}),(0,J.jsx)(K,{type:`button`,onClick:r,disabled:e,children:i(e?`personaForm.actions.saving`:`personaForm.actions.save`)})]})]})}var fe=a(`components:persona-bindings`),pe=[`web_search`,`search_documents`,`list_documents`,`read_document`,`load_skill`];function me({bindings:e,onChange:t}){let{t:n}=o(),[r,i]=(0,q.useState)([]),[a,s]=(0,q.useState)([]),[c,l]=(0,q.useState)([]),[u,d]=(0,q.useState)([]),[f,p]=(0,q.useState)(!0);(0,q.useEffect)(()=>{let e=!1;return Promise.all([z.listServers(),B.list(),W.list(),H.getCollections()]).then(([t,n,r,a])=>{e||(t.success&&t.data&&i(t.data),n.success&&n.data&&s(n.data),r.success&&r.data&&l(r.data),a.success&&a.data&&d(a.data))}).catch(e=>{fe.error(`Failed to load bindable resources:`,e)}).finally(()=>{e||p(!1)}),()=>{e=!0}},[]);let h=n=>t({...e??{},...n}),g=(t,n)=>{let r=e?.[t]??[];h({[t]:r.includes(n)?r.filter(e=>e!==n):[...r,n]})};return f?(0,J.jsx)(`div`,{className:`flex items-center justify-center py-10`,children:(0,J.jsx)(m,{className:`h-5 w-5 animate-spin text-gray-400`})}):(0,J.jsxs)(`div`,{className:`space-y-6`,"data-testid":`persona-bindings-tab`,children:[(0,J.jsx)(Z,{title:n(`personaForm.bindings.toolServers`),hint:n(`personaForm.bindings.toolServersHint`),emptyLabel:n(`personaForm.bindings.noToolServers`),options:r.map(e=>({id:e.id,label:e.name,detail:e.description})),selected:e?.tool_server_ids??[],onToggle:e=>g(`tool_server_ids`,e),testId:`persona-binding-tool-servers`}),(0,J.jsx)(Z,{title:n(`personaForm.bindings.builtinTools`),hint:n(`personaForm.bindings.builtinToolsHint`),emptyLabel:n(`personaForm.bindings.noBuiltinTools`),options:pe.map(e=>({id:e,label:n(`personaForm.bindings.builtin.${e}`),detail:e})),selected:e?.builtin_tools??[],onToggle:e=>g(`builtin_tools`,e),testId:`persona-binding-builtin-tools`}),(0,J.jsx)(Z,{title:n(`personaForm.bindings.skills`),hint:n(`personaForm.bindings.skillsHint`),emptyLabel:n(`personaForm.bindings.noSkills`),options:a.map(e=>({id:e.id,label:e.name,detail:`$${e.slug}`})),selected:e?.skill_ids??[],onToggle:e=>g(`skill_ids`,e),testId:`persona-binding-skills`}),(0,J.jsx)(Z,{title:n(`personaForm.bindings.collections`),hint:n(`personaForm.bindings.collectionsHint`),emptyLabel:n(`personaForm.bindings.noCollections`),options:u.map(e=>({id:e.id,label:e.name})),selected:e?.knowledge_collection_ids??[],onToggle:t=>{let n=e?.knowledge_collection_ids??[];h({knowledge_collection_ids:n.includes(t)?n.filter(e=>e!==t):[...n,t]})},testId:`persona-binding-collections`}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-800`,children:n(`personaForm.bindings.prompt`)}),(0,J.jsx)(`p`,{className:`mb-2 mt-1 text-xs text-gray-500 dark:text-dark-600`,children:n(`personaForm.bindings.promptHint`)}),(0,J.jsxs)(`select`,{value:e?.prompt_id??``,onChange:e=>h({prompt_id:e.target.value||void 0}),"data-testid":`persona-binding-prompt`,"aria-label":n(`personaForm.bindings.prompt`),className:`w-full rounded-lg border border-gray-200 bg-white px-3 py-2.5 text-sm text-gray-900 focus:ring-2 focus:ring-primary-500/20 dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`,children:[(0,J.jsx)(`option`,{value:``,children:n(`personaForm.bindings.noPrompt`)}),c.map(e=>(0,J.jsx)(`option`,{value:e.id,children:e.title},e.id))]})]}),(0,J.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-dark-500`,children:n(`personaForm.bindings.version`,{version:e?.version??0})})]})}function Z({title:e,hint:t,emptyLabel:n,options:r,selected:i,onToggle:a,testId:o}){return(0,J.jsxs)(`div`,{"data-testid":o,children:[(0,J.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-800`,children:e}),(0,J.jsx)(`p`,{className:`mb-2 mt-1 text-xs text-gray-500 dark:text-dark-600`,children:t}),r.length===0?(0,J.jsx)(`p`,{className:`rounded-lg border border-dashed border-gray-200 px-3 py-4 text-center text-xs text-gray-400 dark:border-dark-300 dark:text-dark-500`,children:n}):(0,J.jsx)(`div`,{className:`space-y-1`,children:r.map(e=>(0,J.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2.5 rounded-lg px-2.5 py-1.5 transition-colors hover:bg-gray-50 dark:hover:bg-dark-200`,children:[(0,J.jsx)(`input`,{type:`checkbox`,checked:i.includes(e.id),onChange:()=>a(e.id),className:`h-4 w-4 rounded border-gray-300 dark:border-dark-400`}),(0,J.jsx)(`span`,{className:`text-sm text-gray-900 dark:text-dark-800`,children:e.label}),e.detail&&(0,J.jsx)(`span`,{className:`truncate text-xs text-gray-400 dark:text-dark-500`,children:e.detail})]},e.id))})]})}var Q=({label:e,value:t,min:n,max:r,step:i,onChange:a,hint:o,format:c=e=>String(e),colorClass:l=`text-gray-700 dark:text-dark-600`})=>{let u=(t-n)/(r-n)*100;return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,J.jsx)(`label`,{className:s(`block text-sm font-medium`,l),children:e}),(0,J.jsx)(`input`,{type:`number`,min:n,max:r,step:i,value:c(t),onChange:e=>{let t=parseFloat(e.target.value);isNaN(t)||a(Math.min(r,Math.max(n,t)))},className:`w-20 px-2 py-1 text-sm text-right bg-gray-100 dark:bg-dark-200 border border-gray-300 dark:border-dark-300 rounded focus:outline-none focus:ring-1 focus:ring-primary-500 dark:text-dark-600`})]}),(0,J.jsx)(`input`,{type:`range`,min:n,max:r,step:i,value:t,onChange:e=>a(parseFloat(e.target.value)),className:`w-full h-2 bg-gray-200 dark:bg-dark-200 rounded-lg appearance-none cursor-pointer slider`,style:{"--progress":`${u}%`}}),o&&(0,J.jsx)(`p`,{className:s(`text-xs mt-1`,l.replace(`700`,`500`).replace(`600`,`400`)),children:o})]})},$=({label:e,checked:t,onChange:n,colorClass:r=`text-gray-700 dark:text-dark-600`})=>(0,J.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,J.jsx)(`div`,{className:s(`relative w-10 h-5 rounded-full transition-colors`,t?`bg-primary-500 dark:bg-primary-600`:`bg-gray-300 dark:bg-dark-300`),onClick:()=>n(!t),children:(0,J.jsx)(`div`,{className:s(`absolute top-0.5 start-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform`,t&&`translate-x-5 rtl:-translate-x-5`)})}),(0,J.jsx)(`span`,{className:s(`text-sm font-medium`,r),children:e})]});function he({formData:e,persona:t,memoryStatus:n,loadingMemoryStatus:r,wipingMemories:i,onSettingsChange:a,onWipeMemories:c}){let{t:l}=o();return(0,J.jsxs)(`div`,{className:`space-y-6`,children:[(0,J.jsxs)(`div`,{className:`rounded-xl overflow-hidden border border-emerald-200/50 dark:border-emerald-700/30`,children:[(0,J.jsx)(`div`,{className:`px-5 py-4 bg-gradient-to-r from-emerald-500 to-teal-500 dark:from-emerald-600 dark:to-teal-600`,children:(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(`div`,{className:`w-10 h-10 rounded-lg bg-white/20 flex items-center justify-center`,children:(0,J.jsx)(d,{className:`h-5 w-5 text-white`})}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h3`,{className:`font-semibold text-white`,children:l(`personaForm.memory.title`)}),(0,J.jsx)(`p`,{className:`text-xs text-white/80`,children:l(`personaForm.memory.subtitle`)})]})]}),(0,J.jsx)($,{label:``,checked:e.memory_settings?.enabled||!1,onChange:e=>a(`memory_settings`,{enabled:e})})]})}),e.memory_settings?.enabled&&t?.id&&(0,J.jsx)(`div`,{className:`px-5 py-4 bg-emerald-50 dark:bg-emerald-900/20 border-b border-emerald-100 dark:border-emerald-800/30`,children:r?(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-emerald-600 dark:text-emerald-400`,children:[(0,J.jsx)(S,{className:`h-4 w-4 animate-spin`}),l(`personaForm.memory.loading`)]}):n?(0,J.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,J.jsxs)(`div`,{className:`text-center`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,J.jsx)(d,{className:`h-5 w-5`}),n.memory_count.toLocaleString()]}),(0,J.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:l(`personaForm.memory.memories`)})]}),(0,J.jsxs)(`div`,{className:`text-center`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,J.jsx)(_,{className:`h-5 w-5`}),n.size_mb.toFixed(1)]}),(0,J.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:l(`personaForm.memory.mbUsed`)})]}),(0,J.jsxs)(`div`,{className:`text-center`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,J.jsx)(p,{className:`h-5 w-5`}),n.last_backup?new Date(n.last_backup).toLocaleDateString():l(`personaForm.memory.never`)]}),(0,J.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:l(`personaForm.memory.lastBackup`)})]})]}):(0,J.jsx)(`p`,{className:`text-sm text-emerald-600 dark:text-emerald-400`,children:l(`personaForm.memory.noData`)})}),e.memory_settings?.enabled&&(0,J.jsxs)(`div`,{className:`p-5 bg-white dark:bg-dark-100 space-y-4`,children:[(0,J.jsx)(Q,{label:l(`personaForm.memory.maxMemories`),value:e.memory_settings.max_memories,min:100,max:1e4,step:100,hint:l(`personaForm.memory.maxMemoriesHint`),format:e=>e.toLocaleString(),colorClass:`text-emerald-700 dark:text-emerald-300`,onChange:e=>a(`memory_settings`,{max_memories:e})}),(0,J.jsx)(Q,{label:l(`personaForm.memory.retention`),value:e.memory_settings.retention_days,min:7,max:365,step:7,hint:l(`personaForm.memory.retentionHint`),format:e=>`${Math.round(e)} days`,colorClass:`text-emerald-700 dark:text-emerald-300`,onChange:e=>a(`memory_settings`,{retention_days:e})}),(0,J.jsx)($,{label:l(`personaForm.memory.autoCleanup`),checked:e.memory_settings.auto_cleanup,onChange:e=>a(`memory_settings`,{auto_cleanup:e}),colorClass:`text-emerald-700 dark:text-emerald-300`}),t?.id&&n&&n.memory_count>0&&(0,J.jsx)(`div`,{className:`pt-4 border-t border-gray-200 dark:border-dark-300`,children:(0,J.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-red-50 dark:bg-red-900/20 rounded-lg border border-red-200 dark:border-red-800/30`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`text-sm font-medium text-red-700 dark:text-red-300`,children:l(`personaForm.memory.wipeAll`)}),(0,J.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:l(`personaForm.memory.wipeCannot`)})]}),(0,J.jsxs)(`button`,{type:`button`,onClick:c,disabled:i,className:`px-3 py-1.5 bg-red-500 hover:bg-red-600 text-white text-sm font-medium rounded-lg transition-colors disabled:opacity-50 flex items-center gap-1.5`,children:[i?(0,J.jsx)(S,{className:`h-3.5 w-3.5 animate-spin`}):(0,J.jsx)(P,{className:`h-3.5 w-3.5`}),l(i?`personaForm.memory.wiping`:`personaForm.memory.wipeButton`)]})]})})]}),!e.memory_settings?.enabled&&(0,J.jsx)(`div`,{className:`p-5 bg-gray-50 dark:bg-dark-50`,children:(0,J.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 text-center`,children:l(`personaForm.memory.enableHint`)})})]}),(0,J.jsxs)(`div`,{className:`rounded-xl overflow-hidden border border-primary-200/50 dark:border-primary-700/30`,children:[(0,J.jsx)(`div`,{className:`px-5 py-4 bg-primary-600 dark:bg-primary-600`,children:(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(`div`,{className:`w-10 h-10 rounded-lg bg-white/20 flex items-center justify-center`,children:(0,J.jsx)(C,{className:`h-5 w-5 text-white`})}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h3`,{className:`font-semibold text-white`,children:l(`personaForm.learning.title`)}),(0,J.jsx)(`p`,{className:`text-xs text-white/80`,children:l(`personaForm.learning.subtitle`)})]})]}),(0,J.jsx)($,{label:``,checked:e.mutation_settings?.enabled||!1,onChange:e=>a(`mutation_settings`,{enabled:e})})]})}),e.mutation_settings?.enabled&&(0,J.jsxs)(`div`,{className:`p-5 bg-white dark:bg-dark-100 space-y-5`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-primary-700 dark:text-primary-300 mb-3`,children:l(`personaForm.learning.speed`)}),(0,J.jsx)(`div`,{className:`grid grid-cols-3 gap-3`,children:[{level:`low`,icon:M,label:l(`personaForm.learning.slow`),desc:l(`personaForm.learning.slowDesc`)},{level:`medium`,icon:C,label:l(`personaForm.learning.balanced`),desc:l(`personaForm.learning.balancedDesc`)},{level:`high`,icon:v,label:l(`personaForm.learning.fast`),desc:l(`personaForm.learning.fastDesc`)}].map(({level:t,icon:n,label:r,desc:i})=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>a(`mutation_settings`,{sensitivity:t}),className:s(`p-3 rounded-xl text-center transition-all border`,e.mutation_settings?.sensitivity===t?`bg-primary-600 border-primary-600 text-white shadow-lg`:`bg-primary-50 dark:bg-primary-900/20 border-primary-200 dark:border-primary-700/30 text-primary-700 dark:text-primary-300 hover:bg-primary-100 dark:hover:bg-primary-900/30`),children:[(0,J.jsx)(n,{className:`h-5 w-5 mx-auto mb-1`}),(0,J.jsx)(`p`,{className:`text-sm font-medium`,children:r}),(0,J.jsx)(`p`,{className:`text-[10px] opacity-70`,children:i})]},t))})]}),(0,J.jsx)($,{label:l(`personaForm.learning.autoAdapt`),checked:e.mutation_settings.auto_adapt,onChange:e=>a(`mutation_settings`,{auto_adapt:e}),colorClass:`text-primary-700 dark:text-primary-300`}),(0,J.jsxs)(`div`,{className:`p-4 bg-primary-50 dark:bg-primary-900/20 rounded-xl`,children:[(0,J.jsxs)(`p`,{className:`text-xs font-medium text-primary-700 dark:text-primary-300 mb-2 flex items-center gap-1.5`,children:[(0,J.jsx)(k,{className:`h-3.5 w-3.5`}),l(`personaForm.learning.whatLearns`)]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs text-primary-600 dark:text-primary-400`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),l(`personaForm.learning.conversationTone`)]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),l(`personaForm.learning.responseStyle`)]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),l(`personaForm.learning.userPreferences`)]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),l(`personaForm.learning.topicInterests`)]})]})]})]}),!e.mutation_settings?.enabled&&(0,J.jsx)(`div`,{className:`p-5 bg-gray-50 dark:bg-dark-50`,children:(0,J.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 text-center`,children:l(`personaForm.learning.enableHint`)})})]})]})}function ge({parameters:e,onParameterChange:t}){let{t:n}=o(),r=(0,q.useMemo)(()=>[{key:`temperature`,label:n(`personaForm.parameters.temperature`),min:0,max:2,step:.1,hint:n(`personaForm.parameters.temperatureHint`),format:e=>e.toFixed(1)},{key:`top_p`,label:n(`personaForm.parameters.topP`),min:0,max:1,step:.1,hint:n(`personaForm.parameters.topPHint`),format:e=>e.toFixed(1)},{key:`top_k`,label:n(`personaForm.parameters.topK`),min:1,max:100,step:1,hint:n(`personaForm.parameters.topKHint`),format:e=>String(Math.round(e))},{key:`context_window`,label:n(`personaForm.parameters.contextWindow`),min:128,max:131072,step:128,hint:n(`personaForm.parameters.contextWindowHint`),format:e=>String(Math.round(e))},{key:`max_tokens`,label:n(`personaForm.parameters.maxTokens`),min:1,max:8192,step:1,hint:n(`personaForm.parameters.maxTokensHint`),format:e=>String(Math.round(e))},{key:`repeat_penalty`,label:n(`personaForm.parameters.repeatPenalty`),min:.5,max:2,step:.1,hint:n(`personaForm.parameters.repeatPenaltyHint`),format:e=>e.toFixed(1)}],[n]);return(0,J.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:r.map(({key:n,label:r,min:i,max:a,step:o,hint:s,format:c})=>(0,J.jsx)(Q,{label:r,value:e[n]||0,min:i,max:a,step:o,hint:s,format:c,onChange:e=>t(n,e)},n))})}var _e=a(`components:persona-form`),ve=({persona:e,onSubmit:t,onCancel:n})=>{let{preferences:a}=G(),{t:l}=o(),[u,d]=(0,q.useState)(X),f=c(e=>e.models),p=c(e=>e.loadModels),m=(0,q.useMemo)(()=>f.filter(e=>!e.isPersona&&!e.isAgent&&!e.isUnavailable&&!e.isLegacySelection),[f]),[h,g]=(0,q.useState)([]),[_,y]=(0,q.useState)(!1),[b,x]=(0,q.useState)(!1),[S,C]=(0,q.useState)(null),[T,E]=(0,q.useState)(`basic`),[te,D]=(0,q.useState)(!1),O=(0,q.useRef)(!1),A=(0,q.useCallback)((e,t)=>{d(n=>({...n,[e]:t})),C(null)},[]),j=(0,q.useCallback)((e,t)=>{d(n=>({...n,parameters:{...n.parameters,[e]:t}})),C(null)},[]),M=(0,q.useCallback)((e,t)=>{d(n=>({...n,[e]:{...n[e],...t}})),C(null)},[]),P=(0,q.useCallback)(e=>{let t=e.reduce((e,t)=>(e.find(e=>e.id===t.id)||e.push(t),e),[]);return t.length>0?t:[{id:`nomic-embed-text`,name:`nomic-embed-text`,description:`Ollama - Default embedding model`,provider:`ollama`,dimensions:0,isDetectedEmbedding:!0}]},[]),F=e?.id,R=!!u.memory_settings?.enabled,z=r(),{data:B=null,isLoading:V}=i({queryKey:[`persona-memory-status`,F],queryFn:async()=>{if(!F)return null;let e=await U.getMemoryStatus(F);return e.success&&e.data?e.data:null},enabled:!!F&&R}),H=()=>z.invalidateQueries({queryKey:[`persona-memory-status`,F]}),W=async()=>{if(e?.id&&confirm(l(`personaForm.memory.wipeConfirm`))){D(!0);try{let t=await U.wipeMemories(e.id);t.success?(I.success(l(`personaForm.memory.wipeSuccess`,{count:t.data?.deleted_count||0})),await H()):I.error(l(`personaForm.error.saveFailed`))}catch{I.error(l(`personaForm.error.saveFailed`))}finally{D(!1)}}};(0,q.useEffect)(()=>{O.current||(O.current=!0,(async()=>{y(!0);try{let[t,n]=await Promise.all([L.getModels(),e?Promise.resolve(null):U.getDefaultParameters(),c.getState().models.length===0?p({quiet:!0}):Promise.resolve()]),r=P(t.success&&t.data?t.data:[]);g(r);let i=r.find(e=>e.id===a.embeddingSettings?.model||e.rawModel===a.embeddingSettings?.model)?.id||r[0]?.id||``,o=r.find(t=>t.id===e?.embedding_model||t.rawModel===e?.embedding_model)?.id||e?.embedding_model||r[0]?.id||``;if(e)d({name:e.name,description:e.description||``,model:e.model,parameters:e.parameters,avatar:e.avatar||``,background:e.background||``,embedding_model:o,memory_settings:e.memory_settings||X.memory_settings,mutation_settings:e.mutation_settings||X.mutation_settings,bindings:e.bindings}),e.embedding_model&&!r.find(t=>t.id===e.embedding_model||t.rawModel===e.embedding_model)&&g(t=>P([...t,{id:e.embedding_model,name:e.embedding_model,description:`Previously selected model (not currently available)`,provider:`openai`,dimensions:0}]));else{let e=n?.success?n.data:{};d(t=>({...t,parameters:{...t.parameters,...e},embedding_model:i}))}}catch(e){_e.error(`Error loading data:`,e)}finally{y(!1)}})())},[e,P,p,a.embeddingSettings?.model]);let K=async()=>{x(!0);try{let n={name:u.name,description:u.description,model:u.model,parameters:u.parameters,avatar:u.avatar,background:u.background,embedding_model:u.embedding_model,memory_settings:u.memory_settings,mutation_settings:u.mutation_settings,bindings:u.bindings},r=e?await U.updatePersona(e.id,n):await U.createPersona(u);r.success&&r.data?(I.success(l(e?`personaForm.success.updated`:`personaForm.success.created`)),C(new Date),await t(r.data)):I.error(r.error?`${l(`personaForm.error.saveFailed`)}: ${r.error}`:l(`personaForm.error.saveFailed`))}catch(e){I.error(`${l(`personaForm.error.saveFailed`)}: ${e instanceof Error?e.message:String(e)}`)}finally{x(!1)}},ne=(0,q.useMemo)(()=>[{id:`basic`,label:l(`personaForm.tabs.basic`),icon:w},{id:`parameters`,label:l(`personaForm.tabs.parameters`),icon:ee},{id:`memory`,label:l(`personaForm.tabs.memory`),icon:v},{id:`bindings`,label:l(`personaForm.tabs.bindings`),icon:N},{id:`advanced`,label:l(`personaForm.tabs.advanced`),icon:k}],[l]);return _?(0,J.jsx)(`div`,{className:`flex items-center justify-center p-8`,children:(0,J.jsxs)(`div`,{className:`animate-pulse flex items-center gap-3`,children:[(0,J.jsx)(`div`,{className:`w-5 h-5 border-2 border-primary-500 border-t-transparent rounded-full animate-spin`}),(0,J.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:l(`personaForm.loading`)})]})}):(0,J.jsxs)(`div`,{className:`max-w-4xl mx-auto`,children:[(0,J.jsxs)(`div`,{className:`mb-6`,children:[(0,J.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-dark-800`,children:l(e?`personaForm.title.edit`:`personaForm.title.create`)}),(0,J.jsx)(`p`,{className:`mt-1 text-gray-600 dark:text-dark-600`,children:l(e?`personaForm.subtitle.edit`:`personaForm.subtitle.create`)})]}),(0,J.jsxs)(`form`,{onSubmit:e=>e.preventDefault(),className:`space-y-6`,children:[(0,J.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg shadow-sm border border-gray-200 dark:border-dark-300`,children:[(0,J.jsx)(`div`,{className:`flex border-b border-gray-200 dark:border-dark-300`,children:ne.map(e=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>E(e.id),className:s(`flex items-center gap-2 px-6 py-4 text-sm font-medium transition-colors`,T===e.id?`border-b-2 border-primary-500 text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-dark-600 hover:text-gray-700 dark:hover:text-dark-800`),children:[(0,J.jsx)(e.icon,{className:`h-4 w-4`}),e.label]},e.id))}),(0,J.jsxs)(`div`,{className:`p-6`,children:[T===`basic`&&(0,J.jsx)(ue,{formData:u,availableModels:m,onFieldChange:A,onParameterChange:j}),T===`parameters`&&(0,J.jsx)(ge,{parameters:u.parameters,onParameterChange:j}),T===`memory`&&(0,J.jsx)(he,{formData:u,persona:e,memoryStatus:B,loadingMemoryStatus:V,wipingMemories:te,onSettingsChange:M,onWipeMemories:W}),T===`bindings`&&(0,J.jsx)(me,{bindings:u.bindings,onChange:e=>A(`bindings`,e)}),T===`advanced`&&(0,J.jsx)(se,{embeddingModel:u.embedding_model,embeddingModels:h,onEmbeddingModelChange:e=>A(`embedding_model`,e)})]})]}),(0,J.jsx)(de,{submitting:b,lastSaved:S,onCancel:n,onSave:K})]})]})},ye=a(`components:persona-import-export`),be=({personas:e,onImport:t,onClose:n})=>{let{t:r}=o(),[i,a]=(0,q.useState)(!1),[s,c]=(0,q.useState)(``),l=async e=>{try{let t=await U.exportPersona(e.id),n=new Blob([JSON.stringify(t,null,2)],{type:`application/json`}),i=URL.createObjectURL(n),a=document.createElement(`a`);a.href=i,a.download=`${e.name}.json`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i),I.success(r(`personaImportExport.exportSuccess`,{name:e.name}))}catch(e){let t=e instanceof Error?e.message:String(e);I.error(r(`personaImportExport.exportFailed`)+`: `+t)}};return(0,J.jsxs)(`div`,{className:`max-w-4xl mx-auto`,children:[(0,J.jsxs)(`div`,{className:`mb-6`,children:[(0,J.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-dark-800`,children:r(`personaImportExport.title`)}),(0,J.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 mt-1`,children:r(`personaImportExport.description`)})]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-6`,children:[(0,J.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-6 shadow-sm border border-gray-200 dark:border-dark-300`,children:[(0,J.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 mb-4`,children:r(`personaImportExport.exportPersonas`)}),e.length===0?(0,J.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 text-center py-8`,children:r(`personaImportExport.noPersonasToExport`)}):(0,J.jsxs)(`div`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,J.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:r(`personaImportExport.personasAvailable`,{count:e.length})}),(0,J.jsx)(K,{onClick:async()=>{try{let t=e.map(e=>U.exportPersona(e.id)),n=await Promise.all(t),i={personas:n,exportedAt:Date.now(),version:`1.0.0`,count:n.length},a=new Blob([JSON.stringify(i,null,2)],{type:`application/json`}),o=URL.createObjectURL(a),s=document.createElement(`a`);s.href=o,s.download=`personas-export-${new Date().toISOString().split(`T`)[0]}.json`,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(o),I.success(r(`personaImportExport.exportAllSuccess`,{count:e.length}))}catch(e){let t=e instanceof Error?e.message:String(e);I.error(r(`personaImportExport.exportAllFailed`)+`: `+t)}},variant:`outline`,size:`sm`,className:`px-3 py-1`,children:r(`personaImportExport.exportAll`)})]}),(0,J.jsx)(`div`,{className:`space-y-2 max-h-80 overflow-y-auto`,children:e.map(e=>(0,J.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-gray-50 dark:bg-dark-200 rounded-md`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(`img`,{src:V(e,32),alt:e.name,className:`w-8 h-8 rounded-full`,onError:t=>R(t.currentTarget,e.name,32)}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`font-medium text-gray-900 dark:text-dark-800`,children:e.name}),(0,J.jsx)(`div`,{className:`text-sm text-gray-500 dark:text-dark-500`,children:e.model})]})]}),(0,J.jsx)(K,{onClick:()=>l(e),variant:`outline`,size:`sm`,className:`px-3 py-1`,children:r(`common.export`)})]},e.id))})]})]}),(0,J.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-6 shadow-sm border border-gray-200 dark:border-dark-300`,children:[(0,J.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 mb-4`,children:r(`personaImportExport.importPersonas`)}),(0,J.jsxs)(`div`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:r(`personaImportExport.uploadJsonFile`)}),(0,J.jsx)(`input`,{type:`file`,accept:`.json`,onChange:e=>{let t=e.target.files?.[0];if(t){let e=new FileReader;e.onload=e=>{let t=e.target?.result;typeof t==`string`&&c(t)},e.readAsText(t)}},className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-700`})]}),(0,J.jsx)(`div`,{className:`text-center text-gray-500 dark:text-dark-500`,children:r(`common.or`).toUpperCase()}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:r(`personaImportExport.pasteJsonLabel`)}),(0,J.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-700`,rows:8,placeholder:r(`personaImportExport.pasteJsonPlaceholder`)})]}),(0,J.jsx)(K,{onClick:async()=>{if(!s.trim()){I.error(r(`personaImportExport.pasteJsonData`));return}a(!0);try{let e=JSON.parse(s);if(e.personas&&Array.isArray(e.personas)){let t=0,n=0;for(let r of e.personas)try{await U.importPersona(r),t++}catch(e){n++,ye.error(`Failed to import persona:`,e)}t>0?(I.success(r(`personaImportExport.importMultipleSuccess`,{count:t})),n>0&&I.error(r(`personaImportExport.importMultipleFailed`,{count:n}))):I.error(r(`personaImportExport.importNoneFailed`))}else await U.importPersona(e),I.success(r(`personaImportExport.importSuccess`));c(``),t()}catch(e){let t=e instanceof Error?e.message:String(e);I.error(r(`personaImportExport.importFailed`)+`: `+t)}finally{a(!1)}},disabled:!s.trim()||i,className:`w-full`,children:r(i?`personaImportExport.importing`:`personaImportExport.importButton`)})]})]})]}),(0,J.jsxs)(`div`,{className:`mt-6 bg-gray-50 dark:bg-dark-200 rounded-lg p-4`,children:[(0,J.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-dark-800 mb-2`,children:r(`personaImportExport.expectedFormat`)}),(0,J.jsx)(`pre`,{className:`text-xs text-gray-600 dark:text-dark-600 overflow-x-auto`,children:`{
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{C as r,t as i}from"./useQuery-BKulzCS7.js";import{t as a}from"./logger-DnuT4jgB.js";import{t as o}from"./useTranslation-rdLmo6zV.js";import{t as s}from"./utils-CKWltgs8.js";import{t as c}from"./chatStore-lyGhYu24.js";import{B as l,D as u,En as d,Et as f,Fn as p,Ft as m,H as h,Ht as g,Jt as _,M as v,N as ee,Tn as y,Ut as b,Yn as x,Z as S,_ as C,c as w,g as T,gn as E,gr as te,j as D,n as O,nr as k,p as A,rt as j,t as M,tt as N,v as P,wn as F,xr as I}from"./ui-vendor-BvD5yGW1.js";import{M as L,_ as R,d as z,f as B,g as V,j as H,m as U,p as W}from"./api-DEOxp9DN.js";import{t as G}from"./appStore-Bsxed1km.js";import{t as K}from"./Button-BxwbQ5xw.js";import{a as ne,o as re}from"./ui-BQojEu4t.js";import{t as ie}from"./AvatarUpload-DrfSzzOZ.js";import{t as ae}from"./ShareDialog-J5zbwIWY.js";var q=e(t(),1),J=n(),Y=a(`components:persona-card`),oe=({persona:e,onEdit:t,onDelete:n,onDownload:a,onSelect:c,onToggleFavorite:p,isSelected:m=!1,compact:g=!1})=>{let{t:_}=o(),ee=r(),[b,x]=(0,q.useState)(!1),[S,C]=(0,q.useState)(!1),[w,O]=(0,q.useState)(!1),A=!!(e.memory_settings?.enabled||e.mutation_settings?.enabled),{data:N=null}=i({queryKey:[`persona-memory-status`,e.id],queryFn:async()=>{let t=await U.getMemoryStatus(e.id);return t.success&&t.data?t.data:null},enabled:A}),L=()=>ee.invalidateQueries({queryKey:[`persona-memory-status`,e.id]}),z=async()=>{if(confirm(_(`personaCard.wipeConfirm`))){O(!0);try{let t=await U.wipeMemories(e.id);t.success?(I.success(_(`personaCard.wipeSuccess`,{count:t.data?.deleted_count||0})),await L()):I.error(_(`personaCard.failed`,{action:`wipe memories`}))}catch(e){I.error(_(`personaCard.failed`,{action:`wipe memories`})),Y.error(e)}finally{O(!1),x(!1)}}},B=async()=>{O(!0);try{let t=await U.backupPersona(e.id),n=window.URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${e.name.toLowerCase().replace(/\s+/g,`-`)}-backup.json`,document.body.appendChild(r),r.click(),window.URL.revokeObjectURL(n),document.body.removeChild(r),I.success(_(`personaCard.backupSuccess`))}catch(e){I.error(_(`personaCard.failed`,{action:`backup persona`})),Y.error(e)}finally{O(!1),x(!1)}},H=async()=>{O(!0);try{let t=await U.exportPersonaDNA(e.id),n=window.URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${e.name.toLowerCase().replace(/\s+/g,`-`)}-dna.json`,document.body.appendChild(r),r.click(),window.URL.revokeObjectURL(n),document.body.removeChild(r),I.success(_(`personaCard.dnaSuccess`))}catch(e){I.error(_(`personaCard.failed`,{action:`export persona DNA`})),Y.error(e)}finally{O(!1),x(!1)}},W=(t=128)=>V(e,t),G=(t=128)=>n=>{R(n.currentTarget,e.name,t)};return g?(0,J.jsxs)(`div`,{className:s(`group relative flex items-center gap-3 p-3 rounded-xl cursor-pointer transition-all duration-200`,`border border-transparent`,`hover:bg-gray-50 dark:hover:bg-dark-100`,m&&[`bg-primary-50 dark:bg-primary-900/20`,`border-primary-200 dark:border-primary-700`]),onClick:()=>c?.(e),children:[(0,J.jsxs)(`div`,{className:`relative flex-shrink-0`,children:[(0,J.jsx)(`img`,{src:W(64),alt:e.name,className:`w-10 h-10 rounded-full object-cover ring-2 ring-white dark:ring-dark-100`,onError:G(64)}),A&&(0,J.jsx)(`div`,{className:`absolute -bottom-0.5 -end-0.5 flex h-4 w-4 items-center justify-center rounded-full bg-primary-600`,children:(0,J.jsx)(v,{className:`h-2.5 w-2.5 text-white`})})]}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`h4`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100 truncate`,children:e.name}),e.is_favorite&&(0,J.jsx)(u,{className:`h-3 w-3 text-amber-500 fill-amber-500 flex-shrink-0`})]}),(0,J.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 truncate`,children:e.model})]}),m&&(0,J.jsx)(`div`,{className:`flex-shrink-0`,children:(0,J.jsx)(`div`,{className:`w-6 h-6 rounded-full bg-primary-500 dark:bg-primary-600 flex items-center justify-center`,children:(0,J.jsx)(j,{className:`h-3 w-3 text-white rtl:rotate-180`})})})]}):(0,J.jsxs)(`div`,{className:s(`group relative overflow-hidden rounded-2xl transition-[border-color,background-color] duration-200`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`hover:border-gray-300 dark:hover:border-white/20`,m&&[`ring-2 ring-primary-500 dark:ring-primary-400`,`border-primary-300 dark:border-primary-600`]),children:[(0,J.jsxs)(`div`,{className:`relative h-24`,children:[e.background?(0,J.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,J.jsx)(`div`,{className:`absolute inset-0 bg-gray-200 dark:bg-dark-200`}),e.background&&(0,J.jsx)(`div`,{className:`absolute inset-0 bg-black/15 dark:bg-black/25`}),(0,J.jsxs)(`div`,{className:`absolute inset-x-3 top-3 flex items-start justify-between`,children:[(0,J.jsx)(`button`,{onClick:t=>{t.stopPropagation(),p?.(e)},className:s(`p-1.5 rounded-full transition-all duration-200`,`border border-white/30 bg-black/20 text-white backdrop-blur-sm hover:bg-black/30`,e.is_favorite&&`bg-amber-500/80 hover:bg-amber-500`),children:(0,J.jsx)(u,{className:s(`h-4 w-4`,e.is_favorite?`fill-ink text-ink dark:fill-ink-inverse dark:text-ink-inverse`:`text-white/80 hover:text-white`)})}),A&&(0,J.jsxs)(`div`,{className:`flex items-center gap-1 rounded-full border border-white/30 bg-black/20 px-2 py-1 text-[10px] font-medium text-white backdrop-blur-sm`,children:[(0,J.jsx)(v,{className:`h-3 w-3`}),_(`personaCard.enhanced`)]})]})]}),(0,J.jsx)(`div`,{className:`relative -mt-8 px-4`,children:(0,J.jsxs)(`div`,{className:`relative inline-block`,children:[(0,J.jsx)(`img`,{src:W(128),alt:e.name,className:`h-16 w-16 rounded-xl object-cover ring-4 ring-white dark:ring-dark-100`,onError:G(128)}),A&&(0,J.jsx)(`div`,{className:`absolute -bottom-1 -end-1 flex h-6 w-6 items-center justify-center rounded-lg bg-primary-600 ring-2 ring-white dark:ring-dark-100`,children:(0,J.jsx)(k,{className:`h-3.5 w-3.5 text-white`})})]})}),(0,J.jsxs)(`div`,{className:`px-4 pt-3 pb-4`,children:[(0,J.jsxs)(`div`,{className:`mb-3`,children:[(0,J.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 leading-tight`,children:e.name}),(0,J.jsxs)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 flex items-center gap-1.5 mt-0.5`,children:[(0,J.jsx)(h,{className:`h-3.5 w-3.5`}),e.model]})]}),e.description&&(0,J.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 line-clamp-2 mb-3`,children:e.description}),e.parameters.system_prompt&&(0,J.jsxs)(`div`,{className:`mb-3 rounded-xl border border-gray-200/70 bg-gray-50/70 p-2.5 dark:border-white/[0.08] dark:bg-white/[0.025]`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-1`,children:[(0,J.jsx)(f,{className:`h-3 w-3 text-gray-400 dark:text-gray-500`}),(0,J.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider font-medium text-gray-400 dark:text-gray-500`,children:_(`personaCard.systemPrompt`)})]}),(0,J.jsxs)(`p`,{className:`line-clamp-2 text-xs leading-5 text-gray-600 dark:text-gray-400`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-3`,children:[(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-lg border border-gray-200/70 px-2 py-1 text-[11px] font-medium text-gray-600 dark:border-white/[0.08] dark:text-gray-400`,children:[(0,J.jsx)(M,{className:`h-3 w-3`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,J.jsxs)(`span`,{className:`inline-flex items-center rounded-lg border border-gray-200/70 px-2 py-1 text-[11px] font-medium text-gray-600 dark:border-white/[0.08] dark:text-gray-400`,children:[`Top-P `,e.parameters.top_p?.toFixed(1)||`0.9`]}),(0,J.jsxs)(`span`,{className:`inline-flex items-center rounded-lg border border-gray-200/70 px-2 py-1 text-[11px] font-medium text-gray-600 dark:border-white/[0.08] dark:text-gray-400`,children:[(e.parameters.context_window||4096).toLocaleString(),` ctx`]})]}),A&&N&&(0,J.jsx)(`div`,{className:`mb-3 rounded-xl border border-primary-200/70 bg-primary-50/50 p-2.5 dark:border-primary-800/40 dark:bg-primary-900/10`,children:(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(d,{className:`h-4 w-4 text-primary-600 dark:text-primary-400`}),(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`span`,{className:`text-xs font-medium text-primary-700 dark:text-primary-300`,children:[N.memory_count,` `,_(`personaCard.memories`)]}),(0,J.jsx)(`span`,{className:`ms-2 text-[10px] text-primary-600/70 dark:text-primary-400/70`,children:(e=>e<1?`${(e*1024).toFixed(0)} KB`:`${e.toFixed(1)} MB`)(N.size_mb)})]})]}),N.status&&(0,J.jsx)(`span`,{className:s(`text-[10px] px-1.5 py-0.5 rounded-full font-medium`,N.status===`active`?`bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400`:`bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`),children:N.status})]})}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between border-t border-gray-200/70 pt-3 dark:border-white/[0.08]`,children:[c&&(0,J.jsxs)(K,{onClick:()=>c(e),size:`sm`,className:`px-4`,children:[(0,J.jsx)(j,{className:`me-1.5 h-3.5 w-3.5 rtl:rotate-180`}),_(`personaCard.use`)]}),(0,J.jsxs)(`div`,{className:`ms-auto flex items-center gap-1`,children:[(0,J.jsx)(`button`,{onClick:()=>t(e),className:`p-2 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-dark-200 transition-colors`,title:_(`personaCard.editTooltip`),children:(0,J.jsx)(D,{className:`h-4 w-4`})}),!e.shared&&(0,J.jsx)(`button`,{onClick:()=>C(!0),className:`p-2 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-dark-200 transition-colors`,title:_(`personaCard.shareTooltip`),"data-testid":`persona-share`,children:(0,J.jsx)(l,{className:`h-4 w-4`})}),(0,J.jsx)(`button`,{onClick:()=>a(e),className:`p-2 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-dark-200 transition-colors`,title:_(`personaCard.downloadTooltip`),children:(0,J.jsx)(y,{className:`h-4 w-4`})}),(0,J.jsxs)(`div`,{className:`relative`,children:[(0,J.jsx)(`button`,{onClick:()=>x(!b),className:`p-2 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-dark-200 transition-colors`,title:_(`common.more`,{defaultValue:`More`}),children:(0,J.jsx)(F,{className:`h-4 w-4`})}),b&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>x(!1)}),(0,J.jsxs)(`div`,{className:`absolute end-0 bottom-full z-20 mb-1 w-44 rounded-xl border border-gray-200 bg-white py-1 shadow-lg dark:border-white/10 dark:bg-dark-100`,children:[A&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{onClick:B,disabled:w,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-dark-50 disabled:opacity-50`,children:[(0,J.jsx)(te,{className:`h-4 w-4`}),_(`personaCard.backup`)]}),(0,J.jsxs)(`button`,{onClick:H,disabled:w,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-dark-50 disabled:opacity-50`,children:[(0,J.jsx)(E,{className:`h-4 w-4`}),_(`personaCard.exportDNA`)]}),N&&N.memory_count>0&&(0,J.jsxs)(`button`,{onClick:z,disabled:w,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 disabled:opacity-50`,children:[(0,J.jsx)(T,{className:`h-4 w-4`}),_(`personaCard.wipeMemories`)]}),(0,J.jsx)(`div`,{className:`my-1 border-t border-gray-100 dark:border-dark-200`})]}),(0,J.jsxs)(`button`,{onClick:()=>{n(e),x(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20`,children:[(0,J.jsx)(P,{className:`h-4 w-4`}),_(`common.delete`)]})]})]})]})]})]})]}),S&&(0,J.jsx)(ae,{resourceType:`persona`,resourceId:e.id,resourceLabel:e.name,onClose:()=>C(!1)})]})},X={name:``,description:``,model:``,parameters:{temperature:.7,top_p:.9,top_k:40,context_window:4096,max_tokens:1024,system_prompt:``,repeat_penalty:1.1,presence_penalty:0,frequency_penalty:0},avatar:``,background:``,embedding_model:``,memory_settings:{enabled:!1,max_memories:1e3,auto_cleanup:!0,retention_days:90},mutation_settings:{enabled:!1,sensitivity:`medium`,auto_adapt:!0}};function se({embeddingModel:e,embeddingModels:t,onEmbeddingModelChange:n}){let{t:r}=o(),i=t.filter(e=>e.isDetectedEmbedding),a=t.filter(e=>!e.isDetectedEmbedding);return(0,J.jsxs)(`div`,{className:`space-y-6`,children:[(0,J.jsxs)(`div`,{className:`rounded-xl p-5 bg-gradient-to-br from-primary-50 to-primary-100/50 dark:from-primary-900/30 dark:to-primary-800/20 border border-primary-200/50 dark:border-primary-700/30`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,J.jsx)(d,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`}),(0,J.jsx)(`h3`,{className:`font-semibold text-primary-900 dark:text-primary-100`,children:r(`personaForm.advanced.embeddingModel`)})]}),(0,J.jsx)(`p`,{className:`text-xs text-primary-600 dark:text-primary-400 mb-3`,children:r(`personaForm.advanced.embeddingHint`)}),(0,J.jsx)(`select`,{value:e,onChange:e=>n(e.target.value),className:`w-full px-3 py-2.5 border border-primary-200 dark:border-primary-700 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20`,children:t.length===0?(0,J.jsx)(`option`,{value:``,disabled:!0,children:r(`personaForm.advanced.noModels`)}):(0,J.jsxs)(J.Fragment,{children:[i.length>0&&(0,J.jsx)(`optgroup`,{label:r(`personaForm.advanced.embeddingModels`),children:i.map(e=>(0,J.jsxs)(`option`,{value:e.id,children:[e.name,` - `,e.description]},e.id))}),a.length>0&&(0,J.jsx)(`optgroup`,{label:r(`personaForm.advanced.otherModels`),children:a.map(e=>(0,J.jsxs)(`option`,{value:e.id,children:[e.name,` - `,e.description]},e.id))})]})}),t.length===0&&(0,J.jsx)(`div`,{className:`mt-3 rounded-lg border border-amber-200 bg-amber-500/10 p-3 dark:border-amber-700/50 dark:bg-amber-900/20`,children:(0,J.jsxs)(`p`,{className:`text-sm text-ink`,children:[r(`personaForm.advanced.installHint`),` `,(0,J.jsx)(`code`,{className:`rounded bg-amber-500/20 px-1.5 py-0.5 text-xs dark:bg-amber-900/40`,children:`ollama pull nomic-embed-text`})]})}),(0,J.jsx)(`p`,{className:`text-[10px] text-primary-500 dark:text-primary-500 mt-2`,children:r(`personaForm.advanced.recommended`)})]}),(0,J.jsx)(`div`,{className:`p-4 bg-gray-50 dark:bg-dark-50 rounded-xl border border-gray-200 dark:border-dark-300`,children:(0,J.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,J.jsx)(g,{className:`h-5 w-5 text-gray-400 mt-0.5 flex-shrink-0`}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`personaForm.advanced.aboutTitle`)}),(0,J.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:r(`personaForm.advanced.aboutDescription`)})]})]})})]})}var ce=a(`components:persona-background-upload`),le=({value:e,onChange:t,className:n=``})=>{let{t:r}=o(),i=(0,q.useRef)(null),[a,s]=(0,q.useState)(!1),[c,l]=(0,q.useState)(!1),u=async e=>{if(!e.type.startsWith(`image/`)){I.error(r(`personaBackground.invalidFile`));return}if(e.size>5242880){I.error(r(`personaBackground.fileTooLarge`));return}s(!0);try{let n=new FileReader;n.onload=e=>{let n=e.target?.result;t(n),I.success(r(`personaBackground.uploaded`))},n.onerror=()=>{I.error(r(`personaBackground.readFailed`))},n.readAsDataURL(e)}catch(e){ce.error(`Failed to upload background:`,e),I.error(r(`personaBackground.uploadFailed`))}finally{s(!1)}};return(0,J.jsx)(`div`,{className:`space-y-4 ${n}`,children:(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:r(`personaBackground.label`)}),(0,J.jsxs)(`div`,{className:`space-y-3`,children:[e?(0,J.jsxs)(`div`,{className:`space-y-3`,children:[(0,J.jsx)(`div`,{className:`w-full h-32 rounded-lg bg-cover bg-center border-2 border-gray-300 dark:border-dark-300`,style:{backgroundImage:`url(${e})`}}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-gray-50 dark:bg-dark-200 rounded-lg`,children:[(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:r(`personaBackground.customBackground`)}),(0,J.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:r(`personaBackground.clickToChange`)})]}),(0,J.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>{t(``),I.success(r(`personaBackground.removed`))},className:`text-red-600 hover:text-red-700 hover:bg-red-50 dark:text-red-400 dark:hover:text-red-300 dark:hover:bg-red-900/20`,children:(0,J.jsx)(O,{className:`h-4 w-4`})})]})]}):(0,J.jsxs)(`div`,{className:`border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${c?`border-primary-500 bg-primary-50 dark:bg-primary-900/20`:`border-gray-300 dark:border-gray-600 hover:border-gray-400 dark:hover:border-gray-500`}`,onDragOver:e=>{e.preventDefault(),l(!0)},onDragLeave:e=>{e.preventDefault(),l(!1)},onDrop:e=>{e.preventDefault(),l(!1);let t=e.dataTransfer.files?.[0];t&&u(t)},onClick:()=>i.current?.click(),children:[(0,J.jsx)(b,{className:`h-12 w-12 mx-auto text-gray-400 dark:text-gray-500 mb-4`}),(0,J.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-2`,children:r(`personaBackground.uploadBackgroundImage`)}),(0,J.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-4`,children:r(`personaBackground.dragAndDrop`)}),(0,J.jsxs)(K,{variant:`outline`,size:`sm`,disabled:a,className:`mx-auto`,children:[(0,J.jsx)(A,{className:`h-4 w-4 mr-2`}),r(a?`personaBackground.uploading`:`personaBackground.chooseImage`)]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1`,children:r(`personaBackground.enterImageUrl`)}),(0,J.jsx)(`input`,{type:`url`,value:e,onChange:e=>t(e.target.value),className:`w-full px-3 py-2 text-sm border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800`,placeholder:`https://example.com/background.jpg`})]})]}),(0,J.jsx)(`input`,{ref:i,type:`file`,accept:`image/*`,onChange:e=>{let t=e.target.files?.[0];t&&u(t)},className:`hidden`}),(0,J.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-2`,children:r(`personaBackground.supportedFormats`)})]})})};function ue({formData:e,availableModels:t,onFieldChange:n,onParameterChange:r}){let{t:i}=o(),a=(0,q.useMemo)(()=>t.filter(e=>!e.isPlugin),[t]),s=(0,q.useMemo)(()=>{let e=new Map;for(let n of t){if(!n.isPlugin)continue;let t=n.pluginName||n.pluginId||`Provider`,r=e.get(t);r?r.push(n):e.set(t,[n])}return[...e.entries()].sort(([e],[t])=>e.localeCompare(t))},[t]);return(0,J.jsxs)(`div`,{className:`space-y-6`,children:[(0,J.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:[i(`personaForm.basic.name`),` *`]}),(0,J.jsx)(`input`,{type:`text`,value:e.name,onChange:e=>n(`name`,e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-colors`,placeholder:i(`personaForm.basic.namePlaceholder`),required:!0})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:[i(`personaForm.basic.model`),` *`]}),(0,J.jsxs)(`select`,{value:e.model,onChange:e=>n(`model`,e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-colors`,required:!0,children:[(0,J.jsx)(`option`,{value:``,children:i(`personaForm.basic.selectModel`)}),e.model&&!t.some(t=>t.name===e.model)&&(0,J.jsx)(`option`,{value:e.model,children:e.model}),a.length>0&&(0,J.jsx)(`optgroup`,{label:`Ollama`,children:a.map(e=>(0,J.jsx)(`option`,{value:e.name,children:e.name},e.name))}),s.map(([e,t])=>(0,J.jsx)(`optgroup`,{label:e,children:t.map(e=>(0,J.jsx)(`option`,{value:e.name,children:e.name},e.name))},e))]})]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:i(`personaForm.basic.description`)}),(0,J.jsx)(`textarea`,{value:e.description,onChange:e=>n(`description`,e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-colors resize-none`,rows:3,placeholder:i(`personaForm.basic.descriptionPlaceholder`)})]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,J.jsx)(ie,{value:e.avatar||``,onChange:e=>n(`avatar`,e)}),(0,J.jsx)(le,{value:e.background||``,onChange:e=>n(`background`,e)})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:i(`personaForm.basic.systemPrompt`)}),(0,J.jsx)(`textarea`,{value:e.parameters.system_prompt,onChange:e=>r(`system_prompt`,e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-colors resize-none font-mono text-sm`,rows:6,placeholder:i(`personaForm.basic.systemPromptPlaceholder`)}),(0,J.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-600 mt-2`,children:i(`personaForm.basic.systemPromptHint`)})]})]})}function de({submitting:e,lastSaved:t,onCancel:n,onSave:r}){let{t:i}=o();return(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsx)(K,{type:`button`,variant:`ghost`,onClick:n,disabled:e,className:`text-gray-600 dark:text-gray-400`,children:i(`personaForm.actions.cancel`)}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[t&&(0,J.jsxs)(`div`,{role:`status`,"aria-live":`polite`,className:`flex items-center gap-1.5 text-sm text-emerald-600 dark:text-emerald-400`,children:[(0,J.jsx)(x,{className:`h-4 w-4`}),(0,J.jsx)(`span`,{children:i(`personaForm.saved`)})]}),(0,J.jsx)(K,{type:`button`,onClick:r,disabled:e,children:i(e?`personaForm.actions.saving`:`personaForm.actions.save`)})]})]})}var fe=a(`components:persona-bindings`),pe=[`web_search`,`search_documents`,`list_documents`,`read_document`,`load_skill`];function me({bindings:e,onChange:t}){let{t:n}=o(),[r,i]=(0,q.useState)([]),[a,s]=(0,q.useState)([]),[c,l]=(0,q.useState)([]),[u,d]=(0,q.useState)([]),[f,p]=(0,q.useState)(!0);(0,q.useEffect)(()=>{let e=!1;return Promise.all([z.listServers(),B.list(),W.list(),H.getCollections()]).then(([t,n,r,a])=>{e||(t.success&&t.data&&i(t.data),n.success&&n.data&&s(n.data),r.success&&r.data&&l(r.data),a.success&&a.data&&d(a.data))}).catch(e=>{fe.error(`Failed to load bindable resources:`,e)}).finally(()=>{e||p(!1)}),()=>{e=!0}},[]);let h=n=>t({...e??{},...n}),g=(t,n)=>{let r=e?.[t]??[];h({[t]:r.includes(n)?r.filter(e=>e!==n):[...r,n]})};return f?(0,J.jsx)(`div`,{className:`flex items-center justify-center py-10`,children:(0,J.jsx)(m,{className:`h-5 w-5 animate-spin text-gray-400`})}):(0,J.jsxs)(`div`,{className:`space-y-6`,"data-testid":`persona-bindings-tab`,children:[(0,J.jsx)(Z,{title:n(`personaForm.bindings.toolServers`),hint:n(`personaForm.bindings.toolServersHint`),emptyLabel:n(`personaForm.bindings.noToolServers`),options:r.map(e=>({id:e.id,label:e.name,detail:e.description})),selected:e?.tool_server_ids??[],onToggle:e=>g(`tool_server_ids`,e),testId:`persona-binding-tool-servers`}),(0,J.jsx)(Z,{title:n(`personaForm.bindings.builtinTools`),hint:n(`personaForm.bindings.builtinToolsHint`),emptyLabel:n(`personaForm.bindings.noBuiltinTools`),options:pe.map(e=>({id:e,label:n(`personaForm.bindings.builtin.${e}`),detail:e})),selected:e?.builtin_tools??[],onToggle:e=>g(`builtin_tools`,e),testId:`persona-binding-builtin-tools`}),(0,J.jsx)(Z,{title:n(`personaForm.bindings.skills`),hint:n(`personaForm.bindings.skillsHint`),emptyLabel:n(`personaForm.bindings.noSkills`),options:a.map(e=>({id:e.id,label:e.name,detail:`$${e.slug}`})),selected:e?.skill_ids??[],onToggle:e=>g(`skill_ids`,e),testId:`persona-binding-skills`}),(0,J.jsx)(Z,{title:n(`personaForm.bindings.collections`),hint:n(`personaForm.bindings.collectionsHint`),emptyLabel:n(`personaForm.bindings.noCollections`),options:u.map(e=>({id:e.id,label:e.name})),selected:e?.knowledge_collection_ids??[],onToggle:t=>{let n=e?.knowledge_collection_ids??[];h({knowledge_collection_ids:n.includes(t)?n.filter(e=>e!==t):[...n,t]})},testId:`persona-binding-collections`}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-800`,children:n(`personaForm.bindings.prompt`)}),(0,J.jsx)(`p`,{className:`mb-2 mt-1 text-xs text-gray-500 dark:text-dark-600`,children:n(`personaForm.bindings.promptHint`)}),(0,J.jsxs)(`select`,{value:e?.prompt_id??``,onChange:e=>h({prompt_id:e.target.value||void 0}),"data-testid":`persona-binding-prompt`,"aria-label":n(`personaForm.bindings.prompt`),className:`w-full rounded-lg border border-gray-200 bg-white px-3 py-2.5 text-sm text-gray-900 focus:ring-2 focus:ring-primary-500/20 dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`,children:[(0,J.jsx)(`option`,{value:``,children:n(`personaForm.bindings.noPrompt`)}),c.map(e=>(0,J.jsx)(`option`,{value:e.id,children:e.title},e.id))]})]}),(0,J.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-dark-500`,children:n(`personaForm.bindings.version`,{version:e?.version??0})})]})}function Z({title:e,hint:t,emptyLabel:n,options:r,selected:i,onToggle:a,testId:o}){return(0,J.jsxs)(`div`,{"data-testid":o,children:[(0,J.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-800`,children:e}),(0,J.jsx)(`p`,{className:`mb-2 mt-1 text-xs text-gray-500 dark:text-dark-600`,children:t}),r.length===0?(0,J.jsx)(`p`,{className:`rounded-lg border border-dashed border-gray-200 px-3 py-4 text-center text-xs text-gray-400 dark:border-dark-300 dark:text-dark-500`,children:n}):(0,J.jsx)(`div`,{className:`space-y-1`,children:r.map(e=>(0,J.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2.5 rounded-lg px-2.5 py-1.5 transition-colors hover:bg-gray-50 dark:hover:bg-dark-200`,children:[(0,J.jsx)(`input`,{type:`checkbox`,checked:i.includes(e.id),onChange:()=>a(e.id),className:`h-4 w-4 rounded border-gray-300 dark:border-dark-400`}),(0,J.jsx)(`span`,{className:`text-sm text-gray-900 dark:text-dark-800`,children:e.label}),e.detail&&(0,J.jsx)(`span`,{className:`truncate text-xs text-gray-400 dark:text-dark-500`,children:e.detail})]},e.id))})]})}var Q=({label:e,value:t,min:n,max:r,step:i,onChange:a,hint:o,format:c=e=>String(e),colorClass:l=`text-gray-700 dark:text-dark-600`})=>{let u=(t-n)/(r-n)*100;return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,J.jsx)(`label`,{className:s(`block text-sm font-medium`,l),children:e}),(0,J.jsx)(`input`,{type:`number`,min:n,max:r,step:i,value:c(t),onChange:e=>{let t=parseFloat(e.target.value);isNaN(t)||a(Math.min(r,Math.max(n,t)))},className:`w-20 px-2 py-1 text-sm text-right bg-gray-100 dark:bg-dark-200 border border-gray-300 dark:border-dark-300 rounded focus:outline-none focus:ring-1 focus:ring-primary-500 dark:text-dark-600`})]}),(0,J.jsx)(`input`,{type:`range`,min:n,max:r,step:i,value:t,onChange:e=>a(parseFloat(e.target.value)),className:`w-full h-2 bg-gray-200 dark:bg-dark-200 rounded-lg appearance-none cursor-pointer slider`,style:{"--progress":`${u}%`}}),o&&(0,J.jsx)(`p`,{className:s(`text-xs mt-1`,l.replace(`700`,`500`).replace(`600`,`400`)),children:o})]})},$=({label:e,checked:t,onChange:n,colorClass:r=`text-gray-700 dark:text-dark-600`})=>(0,J.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,J.jsx)(`div`,{className:s(`relative w-10 h-5 rounded-full transition-colors`,t?`bg-primary-500 dark:bg-primary-600`:`bg-gray-300 dark:bg-dark-300`),onClick:()=>n(!t),children:(0,J.jsx)(`div`,{className:s(`absolute top-0.5 start-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform`,t&&`translate-x-5 rtl:-translate-x-5`)})}),(0,J.jsx)(`span`,{className:s(`text-sm font-medium`,r),children:e})]});function he({formData:e,persona:t,memoryStatus:n,loadingMemoryStatus:r,wipingMemories:i,onSettingsChange:a,onWipeMemories:c}){let{t:l}=o();return(0,J.jsxs)(`div`,{className:`space-y-6`,children:[(0,J.jsxs)(`div`,{className:`rounded-xl overflow-hidden border border-emerald-200/50 dark:border-emerald-700/30`,children:[(0,J.jsx)(`div`,{className:`px-5 py-4 bg-gradient-to-r from-emerald-500 to-teal-500 dark:from-emerald-600 dark:to-teal-600`,children:(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(`div`,{className:`w-10 h-10 rounded-lg bg-white/20 flex items-center justify-center`,children:(0,J.jsx)(d,{className:`h-5 w-5 text-white`})}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h3`,{className:`font-semibold text-white`,children:l(`personaForm.memory.title`)}),(0,J.jsx)(`p`,{className:`text-xs text-white/80`,children:l(`personaForm.memory.subtitle`)})]})]}),(0,J.jsx)($,{label:``,checked:e.memory_settings?.enabled||!1,onChange:e=>a(`memory_settings`,{enabled:e})})]})}),e.memory_settings?.enabled&&t?.id&&(0,J.jsx)(`div`,{className:`px-5 py-4 bg-emerald-50 dark:bg-emerald-900/20 border-b border-emerald-100 dark:border-emerald-800/30`,children:r?(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-emerald-600 dark:text-emerald-400`,children:[(0,J.jsx)(S,{className:`h-4 w-4 animate-spin`}),l(`personaForm.memory.loading`)]}):n?(0,J.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,J.jsxs)(`div`,{className:`text-center`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,J.jsx)(d,{className:`h-5 w-5`}),n.memory_count.toLocaleString()]}),(0,J.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:l(`personaForm.memory.memories`)})]}),(0,J.jsxs)(`div`,{className:`text-center`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,J.jsx)(_,{className:`h-5 w-5`}),n.size_mb.toFixed(1)]}),(0,J.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:l(`personaForm.memory.mbUsed`)})]}),(0,J.jsxs)(`div`,{className:`text-center`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,J.jsx)(p,{className:`h-5 w-5`}),n.last_backup?new Date(n.last_backup).toLocaleDateString():l(`personaForm.memory.never`)]}),(0,J.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:l(`personaForm.memory.lastBackup`)})]})]}):(0,J.jsx)(`p`,{className:`text-sm text-emerald-600 dark:text-emerald-400`,children:l(`personaForm.memory.noData`)})}),e.memory_settings?.enabled&&(0,J.jsxs)(`div`,{className:`p-5 bg-white dark:bg-dark-100 space-y-4`,children:[(0,J.jsx)(Q,{label:l(`personaForm.memory.maxMemories`),value:e.memory_settings.max_memories,min:100,max:1e4,step:100,hint:l(`personaForm.memory.maxMemoriesHint`),format:e=>e.toLocaleString(),colorClass:`text-emerald-700 dark:text-emerald-300`,onChange:e=>a(`memory_settings`,{max_memories:e})}),(0,J.jsx)(Q,{label:l(`personaForm.memory.retention`),value:e.memory_settings.retention_days,min:7,max:365,step:7,hint:l(`personaForm.memory.retentionHint`),format:e=>`${Math.round(e)} days`,colorClass:`text-emerald-700 dark:text-emerald-300`,onChange:e=>a(`memory_settings`,{retention_days:e})}),(0,J.jsx)($,{label:l(`personaForm.memory.autoCleanup`),checked:e.memory_settings.auto_cleanup,onChange:e=>a(`memory_settings`,{auto_cleanup:e}),colorClass:`text-emerald-700 dark:text-emerald-300`}),t?.id&&n&&n.memory_count>0&&(0,J.jsx)(`div`,{className:`pt-4 border-t border-gray-200 dark:border-dark-300`,children:(0,J.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-red-50 dark:bg-red-900/20 rounded-lg border border-red-200 dark:border-red-800/30`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`text-sm font-medium text-red-700 dark:text-red-300`,children:l(`personaForm.memory.wipeAll`)}),(0,J.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:l(`personaForm.memory.wipeCannot`)})]}),(0,J.jsxs)(`button`,{type:`button`,onClick:c,disabled:i,className:`px-3 py-1.5 bg-red-500 hover:bg-red-600 text-white text-sm font-medium rounded-lg transition-colors disabled:opacity-50 flex items-center gap-1.5`,children:[i?(0,J.jsx)(S,{className:`h-3.5 w-3.5 animate-spin`}):(0,J.jsx)(P,{className:`h-3.5 w-3.5`}),l(i?`personaForm.memory.wiping`:`personaForm.memory.wipeButton`)]})]})})]}),!e.memory_settings?.enabled&&(0,J.jsx)(`div`,{className:`p-5 bg-gray-50 dark:bg-dark-50`,children:(0,J.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 text-center`,children:l(`personaForm.memory.enableHint`)})})]}),(0,J.jsxs)(`div`,{className:`rounded-xl overflow-hidden border border-primary-200/50 dark:border-primary-700/30`,children:[(0,J.jsx)(`div`,{className:`px-5 py-4 bg-primary-600 dark:bg-primary-600`,children:(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(`div`,{className:`w-10 h-10 rounded-lg bg-white/20 flex items-center justify-center`,children:(0,J.jsx)(C,{className:`h-5 w-5 text-white`})}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h3`,{className:`font-semibold text-white`,children:l(`personaForm.learning.title`)}),(0,J.jsx)(`p`,{className:`text-xs text-white/80`,children:l(`personaForm.learning.subtitle`)})]})]}),(0,J.jsx)($,{label:``,checked:e.mutation_settings?.enabled||!1,onChange:e=>a(`mutation_settings`,{enabled:e})})]})}),e.mutation_settings?.enabled&&(0,J.jsxs)(`div`,{className:`p-5 bg-white dark:bg-dark-100 space-y-5`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-primary-700 dark:text-primary-300 mb-3`,children:l(`personaForm.learning.speed`)}),(0,J.jsx)(`div`,{className:`grid grid-cols-3 gap-3`,children:[{level:`low`,icon:M,label:l(`personaForm.learning.slow`),desc:l(`personaForm.learning.slowDesc`)},{level:`medium`,icon:C,label:l(`personaForm.learning.balanced`),desc:l(`personaForm.learning.balancedDesc`)},{level:`high`,icon:v,label:l(`personaForm.learning.fast`),desc:l(`personaForm.learning.fastDesc`)}].map(({level:t,icon:n,label:r,desc:i})=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>a(`mutation_settings`,{sensitivity:t}),className:s(`p-3 rounded-xl text-center transition-all border`,e.mutation_settings?.sensitivity===t?`bg-primary-600 border-primary-600 text-white shadow-lg`:`bg-primary-50 dark:bg-primary-900/20 border-primary-200 dark:border-primary-700/30 text-primary-700 dark:text-primary-300 hover:bg-primary-100 dark:hover:bg-primary-900/30`),children:[(0,J.jsx)(n,{className:`h-5 w-5 mx-auto mb-1`}),(0,J.jsx)(`p`,{className:`text-sm font-medium`,children:r}),(0,J.jsx)(`p`,{className:`text-[10px] opacity-70`,children:i})]},t))})]}),(0,J.jsx)($,{label:l(`personaForm.learning.autoAdapt`),checked:e.mutation_settings.auto_adapt,onChange:e=>a(`mutation_settings`,{auto_adapt:e}),colorClass:`text-primary-700 dark:text-primary-300`}),(0,J.jsxs)(`div`,{className:`p-4 bg-primary-50 dark:bg-primary-900/20 rounded-xl`,children:[(0,J.jsxs)(`p`,{className:`text-xs font-medium text-primary-700 dark:text-primary-300 mb-2 flex items-center gap-1.5`,children:[(0,J.jsx)(k,{className:`h-3.5 w-3.5`}),l(`personaForm.learning.whatLearns`)]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs text-primary-600 dark:text-primary-400`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),l(`personaForm.learning.conversationTone`)]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),l(`personaForm.learning.responseStyle`)]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),l(`personaForm.learning.userPreferences`)]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),l(`personaForm.learning.topicInterests`)]})]})]})]}),!e.mutation_settings?.enabled&&(0,J.jsx)(`div`,{className:`p-5 bg-gray-50 dark:bg-dark-50`,children:(0,J.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 text-center`,children:l(`personaForm.learning.enableHint`)})})]})]})}function ge({parameters:e,onParameterChange:t}){let{t:n}=o(),r=(0,q.useMemo)(()=>[{key:`temperature`,label:n(`personaForm.parameters.temperature`),min:0,max:2,step:.1,hint:n(`personaForm.parameters.temperatureHint`),format:e=>e.toFixed(1)},{key:`top_p`,label:n(`personaForm.parameters.topP`),min:0,max:1,step:.1,hint:n(`personaForm.parameters.topPHint`),format:e=>e.toFixed(1)},{key:`top_k`,label:n(`personaForm.parameters.topK`),min:1,max:100,step:1,hint:n(`personaForm.parameters.topKHint`),format:e=>String(Math.round(e))},{key:`context_window`,label:n(`personaForm.parameters.contextWindow`),min:128,max:131072,step:128,hint:n(`personaForm.parameters.contextWindowHint`),format:e=>String(Math.round(e))},{key:`max_tokens`,label:n(`personaForm.parameters.maxTokens`),min:1,max:8192,step:1,hint:n(`personaForm.parameters.maxTokensHint`),format:e=>String(Math.round(e))},{key:`repeat_penalty`,label:n(`personaForm.parameters.repeatPenalty`),min:.5,max:2,step:.1,hint:n(`personaForm.parameters.repeatPenaltyHint`),format:e=>e.toFixed(1)}],[n]);return(0,J.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:r.map(({key:n,label:r,min:i,max:a,step:o,hint:s,format:c})=>(0,J.jsx)(Q,{label:r,value:e[n]||0,min:i,max:a,step:o,hint:s,format:c,onChange:e=>t(n,e)},n))})}var _e=a(`components:persona-form`),ve=({persona:e,onSubmit:t,onCancel:n})=>{let{preferences:a}=G(),{t:l}=o(),[u,d]=(0,q.useState)(X),f=c(e=>e.models),p=c(e=>e.loadModels),m=(0,q.useMemo)(()=>f.filter(e=>!e.isPersona&&!e.isAgent&&!e.isUnavailable&&!e.isLegacySelection),[f]),[h,g]=(0,q.useState)([]),[_,y]=(0,q.useState)(!1),[b,x]=(0,q.useState)(!1),[S,C]=(0,q.useState)(null),[T,E]=(0,q.useState)(`basic`),[te,D]=(0,q.useState)(!1),O=(0,q.useRef)(!1),A=(0,q.useCallback)((e,t)=>{d(n=>({...n,[e]:t})),C(null)},[]),j=(0,q.useCallback)((e,t)=>{d(n=>({...n,parameters:{...n.parameters,[e]:t}})),C(null)},[]),M=(0,q.useCallback)((e,t)=>{d(n=>({...n,[e]:{...n[e],...t}})),C(null)},[]),P=(0,q.useCallback)(e=>{let t=e.reduce((e,t)=>(e.find(e=>e.id===t.id)||e.push(t),e),[]);return t.length>0?t:[{id:`nomic-embed-text`,name:`nomic-embed-text`,description:`Ollama - Default embedding model`,provider:`ollama`,dimensions:0,isDetectedEmbedding:!0}]},[]),F=e?.id,R=!!u.memory_settings?.enabled,z=r(),{data:B=null,isLoading:V}=i({queryKey:[`persona-memory-status`,F],queryFn:async()=>{if(!F)return null;let e=await U.getMemoryStatus(F);return e.success&&e.data?e.data:null},enabled:!!F&&R}),H=()=>z.invalidateQueries({queryKey:[`persona-memory-status`,F]}),W=async()=>{if(e?.id&&confirm(l(`personaForm.memory.wipeConfirm`))){D(!0);try{let t=await U.wipeMemories(e.id);t.success?(I.success(l(`personaForm.memory.wipeSuccess`,{count:t.data?.deleted_count||0})),await H()):I.error(l(`personaForm.error.saveFailed`))}catch{I.error(l(`personaForm.error.saveFailed`))}finally{D(!1)}}};(0,q.useEffect)(()=>{O.current||(O.current=!0,(async()=>{y(!0);try{let[t,n]=await Promise.all([L.getModels(),e?Promise.resolve(null):U.getDefaultParameters(),c.getState().models.length===0?p({quiet:!0}):Promise.resolve()]),r=P(t.success&&t.data?t.data:[]);g(r);let i=r.find(e=>e.id===a.embeddingSettings?.model||e.rawModel===a.embeddingSettings?.model)?.id||r[0]?.id||``,o=r.find(t=>t.id===e?.embedding_model||t.rawModel===e?.embedding_model)?.id||e?.embedding_model||r[0]?.id||``;if(e)d({name:e.name,description:e.description||``,model:e.model,parameters:e.parameters,avatar:e.avatar||``,background:e.background||``,embedding_model:o,memory_settings:e.memory_settings||X.memory_settings,mutation_settings:e.mutation_settings||X.mutation_settings,bindings:e.bindings}),e.embedding_model&&!r.find(t=>t.id===e.embedding_model||t.rawModel===e.embedding_model)&&g(t=>P([...t,{id:e.embedding_model,name:e.embedding_model,description:`Previously selected model (not currently available)`,provider:`openai`,dimensions:0}]));else{let e=n?.success?n.data:{};d(t=>({...t,parameters:{...t.parameters,...e},embedding_model:i}))}}catch(e){_e.error(`Error loading data:`,e)}finally{y(!1)}})())},[e,P,p,a.embeddingSettings?.model]);let K=async()=>{x(!0);try{let n={name:u.name,description:u.description,model:u.model,parameters:u.parameters,avatar:u.avatar,background:u.background,embedding_model:u.embedding_model,memory_settings:u.memory_settings,mutation_settings:u.mutation_settings,bindings:u.bindings},r=e?await U.updatePersona(e.id,n):await U.createPersona(u);r.success&&r.data?(I.success(l(e?`personaForm.success.updated`:`personaForm.success.created`)),C(new Date),await t(r.data)):I.error(r.error?`${l(`personaForm.error.saveFailed`)}: ${r.error}`:l(`personaForm.error.saveFailed`))}catch(e){I.error(`${l(`personaForm.error.saveFailed`)}: ${e instanceof Error?e.message:String(e)}`)}finally{x(!1)}},ne=(0,q.useMemo)(()=>[{id:`basic`,label:l(`personaForm.tabs.basic`),icon:w},{id:`parameters`,label:l(`personaForm.tabs.parameters`),icon:ee},{id:`memory`,label:l(`personaForm.tabs.memory`),icon:v},{id:`bindings`,label:l(`personaForm.tabs.bindings`),icon:N},{id:`advanced`,label:l(`personaForm.tabs.advanced`),icon:k}],[l]);return _?(0,J.jsx)(`div`,{className:`flex items-center justify-center p-8`,children:(0,J.jsxs)(`div`,{className:`animate-pulse flex items-center gap-3`,children:[(0,J.jsx)(`div`,{className:`w-5 h-5 border-2 border-primary-500 border-t-transparent rounded-full animate-spin`}),(0,J.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:l(`personaForm.loading`)})]})}):(0,J.jsxs)(`div`,{className:`max-w-4xl mx-auto`,children:[(0,J.jsxs)(`div`,{className:`mb-6`,children:[(0,J.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-dark-800`,children:l(e?`personaForm.title.edit`:`personaForm.title.create`)}),(0,J.jsx)(`p`,{className:`mt-1 text-gray-600 dark:text-dark-600`,children:l(e?`personaForm.subtitle.edit`:`personaForm.subtitle.create`)})]}),(0,J.jsxs)(`form`,{onSubmit:e=>e.preventDefault(),className:`space-y-6`,children:[(0,J.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg shadow-sm border border-gray-200 dark:border-dark-300`,children:[(0,J.jsx)(`div`,{className:`flex border-b border-gray-200 dark:border-dark-300`,children:ne.map(e=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>E(e.id),className:s(`flex items-center gap-2 px-6 py-4 text-sm font-medium transition-colors`,T===e.id?`border-b-2 border-primary-500 text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-dark-600 hover:text-gray-700 dark:hover:text-dark-800`),children:[(0,J.jsx)(e.icon,{className:`h-4 w-4`}),e.label]},e.id))}),(0,J.jsxs)(`div`,{className:`p-6`,children:[T===`basic`&&(0,J.jsx)(ue,{formData:u,availableModels:m,onFieldChange:A,onParameterChange:j}),T===`parameters`&&(0,J.jsx)(ge,{parameters:u.parameters,onParameterChange:j}),T===`memory`&&(0,J.jsx)(he,{formData:u,persona:e,memoryStatus:B,loadingMemoryStatus:V,wipingMemories:te,onSettingsChange:M,onWipeMemories:W}),T===`bindings`&&(0,J.jsx)(me,{bindings:u.bindings,onChange:e=>A(`bindings`,e)}),T===`advanced`&&(0,J.jsx)(se,{embeddingModel:u.embedding_model,embeddingModels:h,onEmbeddingModelChange:e=>A(`embedding_model`,e)})]})]}),(0,J.jsx)(de,{submitting:b,lastSaved:S,onCancel:n,onSave:K})]})]})},ye=a(`components:persona-import-export`),be=({personas:e,onImport:t,onClose:n})=>{let{t:r}=o(),[i,a]=(0,q.useState)(!1),[s,c]=(0,q.useState)(``),l=async e=>{try{let t=await U.exportPersona(e.id),n=new Blob([JSON.stringify(t,null,2)],{type:`application/json`}),i=URL.createObjectURL(n),a=document.createElement(`a`);a.href=i,a.download=`${e.name}.json`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i),I.success(r(`personaImportExport.exportSuccess`,{name:e.name}))}catch(e){let t=e instanceof Error?e.message:String(e);I.error(r(`personaImportExport.exportFailed`)+`: `+t)}};return(0,J.jsxs)(`div`,{className:`max-w-4xl mx-auto`,children:[(0,J.jsxs)(`div`,{className:`mb-6`,children:[(0,J.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-dark-800`,children:r(`personaImportExport.title`)}),(0,J.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 mt-1`,children:r(`personaImportExport.description`)})]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-6`,children:[(0,J.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-6 shadow-sm border border-gray-200 dark:border-dark-300`,children:[(0,J.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 mb-4`,children:r(`personaImportExport.exportPersonas`)}),e.length===0?(0,J.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 text-center py-8`,children:r(`personaImportExport.noPersonasToExport`)}):(0,J.jsxs)(`div`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,J.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:r(`personaImportExport.personasAvailable`,{count:e.length})}),(0,J.jsx)(K,{onClick:async()=>{try{let t=e.map(e=>U.exportPersona(e.id)),n=await Promise.all(t),i={personas:n,exportedAt:Date.now(),version:`1.0.0`,count:n.length},a=new Blob([JSON.stringify(i,null,2)],{type:`application/json`}),o=URL.createObjectURL(a),s=document.createElement(`a`);s.href=o,s.download=`personas-export-${new Date().toISOString().split(`T`)[0]}.json`,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(o),I.success(r(`personaImportExport.exportAllSuccess`,{count:e.length}))}catch(e){let t=e instanceof Error?e.message:String(e);I.error(r(`personaImportExport.exportAllFailed`)+`: `+t)}},variant:`outline`,size:`sm`,className:`px-3 py-1`,children:r(`personaImportExport.exportAll`)})]}),(0,J.jsx)(`div`,{className:`space-y-2 max-h-80 overflow-y-auto`,children:e.map(e=>(0,J.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-gray-50 dark:bg-dark-200 rounded-md`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(`img`,{src:V(e,32),alt:e.name,className:`w-8 h-8 rounded-full`,onError:t=>R(t.currentTarget,e.name,32)}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`font-medium text-gray-900 dark:text-dark-800`,children:e.name}),(0,J.jsx)(`div`,{className:`text-sm text-gray-500 dark:text-dark-500`,children:e.model})]})]}),(0,J.jsx)(K,{onClick:()=>l(e),variant:`outline`,size:`sm`,className:`px-3 py-1`,children:r(`common.export`)})]},e.id))})]})]}),(0,J.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-6 shadow-sm border border-gray-200 dark:border-dark-300`,children:[(0,J.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 mb-4`,children:r(`personaImportExport.importPersonas`)}),(0,J.jsxs)(`div`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:r(`personaImportExport.uploadJsonFile`)}),(0,J.jsx)(`input`,{type:`file`,accept:`.json`,onChange:e=>{let t=e.target.files?.[0];if(t){let e=new FileReader;e.onload=e=>{let t=e.target?.result;typeof t==`string`&&c(t)},e.readAsText(t)}},className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-700`})]}),(0,J.jsx)(`div`,{className:`text-center text-gray-500 dark:text-dark-500`,children:r(`common.or`).toUpperCase()}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:r(`personaImportExport.pasteJsonLabel`)}),(0,J.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-700`,rows:8,placeholder:r(`personaImportExport.pasteJsonPlaceholder`)})]}),(0,J.jsx)(K,{onClick:async()=>{if(!s.trim()){I.error(r(`personaImportExport.pasteJsonData`));return}a(!0);try{let e=JSON.parse(s);if(e.personas&&Array.isArray(e.personas)){let t=0,n=0;for(let r of e.personas)try{await U.importPersona(r),t++}catch(e){n++,ye.error(`Failed to import persona:`,e)}t>0?(I.success(r(`personaImportExport.importMultipleSuccess`,{count:t})),n>0&&I.error(r(`personaImportExport.importMultipleFailed`,{count:n}))):I.error(r(`personaImportExport.importNoneFailed`))}else await U.importPersona(e),I.success(r(`personaImportExport.importSuccess`));c(``),t()}catch(e){let t=e instanceof Error?e.message:String(e);I.error(r(`personaImportExport.importFailed`)+`: `+t)}finally{a(!1)}},disabled:!s.trim()||i,className:`w-full`,children:r(i?`personaImportExport.importing`:`personaImportExport.importButton`)})]})]})]}),(0,J.jsxs)(`div`,{className:`mt-6 bg-gray-50 dark:bg-dark-200 rounded-lg p-4`,children:[(0,J.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-dark-800 mb-2`,children:r(`personaImportExport.expectedFormat`)}),(0,J.jsx)(`pre`,{className:`text-xs text-gray-600 dark:text-dark-600 overflow-x-auto`,children:`{
2
2
  "name": "Assistant Name",
3
3
  "description": "Brief description of the assistant's personality",
4
4
  "model": "model-name:version",
@@ -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"./useQuery-BKulzCS7.js";import{t as i}from"./useTranslation-rdLmo6zV.js";import{t as a}from"./utils-CKWltgs8.js";import{Bn as o,Ft as s,In as c,Tn as l,Z as u,an as d,br as f,et as p,g as m,or as h,s as g,v as _,vr as v}from"./ui-vendor-BvD5yGW1.js";import{n as y}from"./workApi-CntsmsAA.js";import{u as b}from"./api-HgGU3dII.js";import{t as x}from"./Button-BxwbQ5xw.js";import{a as S,o as C}from"./ui-CHgZA8lG.js";var w=e(t(),1),T={getAnalytics:e=>y.get(`/costs/analytics`,{params:{days:e}}).then(e=>e.data),listTariffs:()=>y.get(`/costs/tariffs`).then(e=>e.data),createTariff:e=>y.post(`/costs/tariffs`,e).then(e=>e.data),deleteTariff:e=>y.delete(`/costs/tariffs/${encodeURIComponent(e)}`).then(()=>void 0),listBudgets:()=>y.get(`/costs/budgets`).then(e=>e.data),createBudget:e=>y.post(`/costs/budgets`,e).then(e=>e.data),deleteBudget:e=>y.delete(`/costs/budgets/${encodeURIComponent(e)}`).then(()=>void 0),exportUrl:e=>`/api/costs/export?days=${e}`,exportCsv:e=>y.get(`/costs/export`,{params:{days:e},responseType:`blob`}).then(e=>e.data)},E=n(),D=e=>new Intl.NumberFormat(void 0,{style:`currency`,currency:`USD`,maximumFractionDigits:e<1?4:2}).format(e),O=`w-full rounded-lg border border-gray-300 bg-white px-2 py-1.5 text-sm dark:border-dark-300 dark:bg-dark-50`,k=({days:e})=>{let{t}=i(),[n,r]=(0,w.useState)(null),[a,o]=(0,w.useState)([]),[c,u]=(0,w.useState)([]),[d,m]=(0,w.useState)(!0),[h,g]=(0,w.useState)(0),[v,y]=(0,w.useState)({pluginId:``,model:``,inputPerMillion:``,outputPerMillion:``,unitPrice:``}),[b,S]=(0,w.useState)({name:``,principalType:`instance`,principalId:``,period:`monthly`,amountUsd:``,mode:`soft`});(0,w.useEffect)(()=>{let n=!1;return Promise.all([T.getAnalytics(e),T.listTariffs(),T.listBudgets()]).then(([e,t,i])=>{n||(e.success&&e.data&&r(e.data),t.success&&t.data&&o(t.data),i.success&&i.data&&u(i.data))}).catch(()=>f.error(t(`costs.loadFailed`))).finally(()=>{n||m(!1)}),()=>{n=!0}},[e,h,t]);let C=e=>{if(!e.trim())return;let t=Number(e);return Number.isFinite(t)?t:void 0},k=async()=>{try{let e=await T.createTariff({pluginId:v.pluginId.trim(),model:v.model.trim()||void 0,inputPerMillion:C(v.inputPerMillion),outputPerMillion:C(v.outputPerMillion),unitPrice:C(v.unitPrice)});if(!e.success)throw Error(e.message);f.success(t(`costs.tariffSaved`)),y({pluginId:``,model:``,inputPerMillion:``,outputPerMillion:``,unitPrice:``}),g(e=>e+1)}catch(e){f.error(e instanceof Error?e.message:t(`costs.saveFailed`))}},A=async()=>{try{let e=await T.createBudget({name:b.name.trim(),principalType:b.principalType,principalId:b.principalType===`instance`?void 0:b.principalId.trim(),period:b.period,amountUsd:Number(b.amountUsd),mode:b.mode});if(!e.success)throw Error(e.message);f.success(t(`costs.budgetSaved`)),S({name:``,principalType:`instance`,principalId:``,period:`monthly`,amountUsd:``,mode:`soft`}),g(e=>e+1)}catch(e){f.error(e instanceof Error?e.message:t(`costs.saveFailed`))}},j=async()=>{try{let t=await T.exportCsv(e),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`libre-webui-costs.csv`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}catch{f.error(t(`costs.exportFailed`))}};return d&&!n?(0,E.jsx)(`div`,{className:`flex justify-center rounded-lg border border-gray-200 bg-white p-6 dark:border-dark-300 dark:bg-dark-100`,children:(0,E.jsx)(s,{className:`h-5 w-5 animate-spin text-gray-400`})}):(0,E.jsxs)(`div`,{className:`space-y-4 rounded-lg border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,"data-testid":`cost-governance-panel`,children:[(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:t(`costs.title`)}),(0,E.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:t(`costs.description`)})]}),(0,E.jsxs)(x,{size:`sm`,variant:`outline`,onClick:()=>void j(),children:[(0,E.jsx)(l,{className:`mr-1 h-3.5 w-3.5`}),t(`costs.exportCsv`)]})]}),n&&(0,E.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:[(0,E.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,E.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.totalSpend`)}),(0,E.jsx)(`p`,{className:`text-lg font-semibold`,children:D(n.totalUsd)})]}),(0,E.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,E.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.meteredEvents`)}),(0,E.jsx)(`p`,{className:`text-lg font-semibold`,children:n.meteredEvents})]}),(0,E.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,E.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.unmeteredEvents`)}),(0,E.jsx)(`p`,{className:`text-lg font-semibold`,children:n.unmeteredEvents})]}),(0,E.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,E.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.topModel`)}),(0,E.jsx)(`p`,{className:`truncate text-sm font-medium`,children:n.byModel[0]?`${n.byModel[0].model} (${D(n.byModel[0].usd)})`:`—`})]})]}),(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-gray-500`,children:t(`costs.budgets`)}),(0,E.jsxs)(`div`,{className:`space-y-2`,children:[n?.budgets.map(e=>{let n=Math.min(1,e.spentUsd/e.amountUsd);return(0,E.jsxs)(`div`,{className:`rounded-lg border border-gray-200 p-2 dark:border-dark-300`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-sm`,children:[(0,E.jsxs)(`span`,{className:`min-w-0 truncate font-medium`,children:[e.name,(0,E.jsxs)(`span`,{className:`ml-2 text-xs font-normal text-gray-500`,children:[t(`costs.mode.${e.mode}`),` ·`,` `,t(`costs.period.${e.period}`),` ·`,` `,e.principalType===`instance`?t(`costs.scope.instance`):`${t(`costs.scope.${e.principalType}`)}: ${e.principalId}`]})]}),(0,E.jsxs)(`span`,{className:`shrink-0 text-xs text-gray-600 dark:text-gray-300`,children:[D(e.spentUsd),` / `,D(e.amountUsd)]}),(0,E.jsx)(`button`,{onClick:()=>{T.deleteBudget(e.id).then(()=>g(e=>e+1)).catch(()=>f.error(t(`costs.saveFailed`)))},className:`shrink-0 rounded p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-950/30`,"aria-label":t(`costs.deleteBudget`),children:(0,E.jsx)(_,{className:`h-3.5 w-3.5`})})]}),(0,E.jsx)(`div`,{className:`mt-1 h-1.5 overflow-hidden rounded bg-gray-200 dark:bg-dark-300`,children:(0,E.jsx)(`div`,{className:n>=1?`h-full bg-red-500`:n>=.8?`h-full bg-amber-500`:`h-full bg-emerald-500`,style:{width:`${Math.round(n*100)}%`}})})]},e.id)}),c.length===0&&(0,E.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.noBudgets`)})]}),(0,E.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-2 sm:grid-cols-6`,children:[(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.budgetName`),value:b.name,onChange:e=>S({...b,name:e.target.value})}),(0,E.jsxs)(`select`,{className:O,value:b.principalType,onChange:e=>S({...b,principalType:e.target.value}),children:[(0,E.jsx)(`option`,{value:`instance`,children:t(`costs.scope.instance`)}),(0,E.jsx)(`option`,{value:`user`,children:t(`costs.scope.user`)}),(0,E.jsx)(`option`,{value:`group`,children:t(`costs.scope.group`)})]}),(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.principalId`),value:b.principalId,disabled:b.principalType===`instance`,onChange:e=>S({...b,principalId:e.target.value})}),(0,E.jsxs)(`select`,{className:O,value:b.period,onChange:e=>S({...b,period:e.target.value}),children:[(0,E.jsx)(`option`,{value:`daily`,children:t(`costs.period.daily`)}),(0,E.jsx)(`option`,{value:`weekly`,children:t(`costs.period.weekly`)}),(0,E.jsx)(`option`,{value:`monthly`,children:t(`costs.period.monthly`)})]}),(0,E.jsxs)(`div`,{className:`flex gap-2`,children:[(0,E.jsx)(`input`,{className:O,placeholder:`USD`,inputMode:`decimal`,value:b.amountUsd,onChange:e=>S({...b,amountUsd:e.target.value})}),(0,E.jsxs)(`select`,{className:O,value:b.mode,onChange:e=>S({...b,mode:e.target.value}),children:[(0,E.jsx)(`option`,{value:`observe`,children:t(`costs.mode.observe`)}),(0,E.jsx)(`option`,{value:`soft`,children:t(`costs.mode.soft`)}),(0,E.jsx)(`option`,{value:`hard`,children:t(`costs.mode.hard`)})]})]}),(0,E.jsxs)(x,{size:`sm`,onClick:()=>void A(),children:[(0,E.jsx)(p,{className:`mr-1 h-3.5 w-3.5`}),t(`costs.addBudget`)]})]})]}),(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-gray-500`,children:t(`costs.tariffs`)}),(0,E.jsx)(`div`,{className:`overflow-x-auto`,children:(0,E.jsxs)(`table`,{className:`w-full text-left text-xs`,children:[(0,E.jsx)(`thead`,{className:`text-gray-500`,children:(0,E.jsxs)(`tr`,{children:[(0,E.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.plugin`)}),(0,E.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.model`)}),(0,E.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.inputPerMillion`)}),(0,E.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.outputPerMillion`)}),(0,E.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.unitPrice`)}),(0,E.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.effectiveFrom`)}),(0,E.jsx)(`th`,{})]})}),(0,E.jsxs)(`tbody`,{children:[a.map(e=>(0,E.jsxs)(`tr`,{className:`border-t border-gray-100 dark:border-dark-300`,children:[(0,E.jsx)(`td`,{className:`py-1 pr-2`,children:e.plugin_id}),(0,E.jsx)(`td`,{className:`py-1 pr-2`,children:e.model??t(`costs.allModels`)}),(0,E.jsx)(`td`,{className:`py-1 pr-2`,children:e.input_per_million===null?`—`:D(e.input_per_million)}),(0,E.jsx)(`td`,{className:`py-1 pr-2`,children:e.output_per_million===null?`—`:D(e.output_per_million)}),(0,E.jsx)(`td`,{className:`py-1 pr-2`,children:e.unit_price===null?`—`:D(e.unit_price)}),(0,E.jsx)(`td`,{className:`py-1 pr-2`,children:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}).format(e.effective_from)}),(0,E.jsx)(`td`,{className:`py-1`,children:(0,E.jsx)(`button`,{onClick:()=>{T.deleteTariff(e.id).then(()=>g(e=>e+1)).catch(()=>f.error(t(`costs.saveFailed`)))},className:`rounded p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-950/30`,"aria-label":t(`costs.deleteTariff`),children:(0,E.jsx)(_,{className:`h-3.5 w-3.5`})})})]},e.id)),a.length===0&&(0,E.jsx)(`tr`,{children:(0,E.jsx)(`td`,{colSpan:7,className:`py-2 text-gray-500`,children:t(`costs.noTariffs`)})})]})]})}),(0,E.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-2 sm:grid-cols-6`,children:[(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.plugin`),value:v.pluginId,onChange:e=>y({...v,pluginId:e.target.value})}),(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.modelOptional`),value:v.model,onChange:e=>y({...v,model:e.target.value})}),(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.inputPerMillion`),inputMode:`decimal`,value:v.inputPerMillion,onChange:e=>y({...v,inputPerMillion:e.target.value})}),(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.outputPerMillion`),inputMode:`decimal`,value:v.outputPerMillion,onChange:e=>y({...v,outputPerMillion:e.target.value})}),(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.unitPrice`),inputMode:`decimal`,value:v.unitPrice,onChange:e=>y({...v,unitPrice:e.target.value})}),(0,E.jsxs)(x,{size:`sm`,onClick:()=>void k(),children:[(0,E.jsx)(p,{className:`mr-1 h-3.5 w-3.5`}),t(`costs.addTariff`)]})]})]})]})},A=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),j=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1}),M=e=>e>=1e4?j.format(e):A.format(e),N=e=>e?e<1e3?`${A.format(e)} ms`:`${(e/1e3).toFixed(+(e<1e4))} s`:`—`,P=(e,t)=>e===0?0:(e-t)/e*100,F=({analytics:e,metric:t,onMetricChange:n})=>{let{t:r}=i(),o={top:22,right:18,bottom:42,left:52},s=e.series.map(e=>e[t]),c=Math.max(1,...s),l=960-o.left-o.right,u=280-o.top-o.bottom,d=t=>o.left+(e.series.length<=1?l/2:t/(e.series.length-1)*l),f=e=>o.top+u-e/c*u,p=e.series.map((e,n)=>({x:d(n),y:f(e[t]),point:e})),m=p.map(({x:e,y:t},n)=>`${n===0?`M`:`L`} ${e} ${t}`).join(` `),h=p.length?`${m} L ${p[p.length-1].x} ${o.top+u} L ${p[0].x} ${o.top+u} Z`:``,g=new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,timeZone:`UTC`}),_=Array.from(new Set([0,Math.floor((e.series.length-1)/2),e.series.length-1])).filter(e=>e>=0);return(0,E.jsxs)(`div`,{"data-testid":`plugin-usage-chart`,className:`overflow-hidden rounded-2xl border border-gray-200/80 bg-white/80 shadow-subtle backdrop-blur-md dark:border-white/[0.08] dark:bg-dark-100/75`,children:[(0,E.jsxs)(`div`,{className:`flex flex-col gap-3 border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.07] sm:flex-row sm:items-center sm:justify-between sm:px-5`,children:[(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:r(`usageAnalytics.activity.title`)}),(0,E.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:r(t===`calls`?`usageAnalytics.activity.callsDescription`:`usageAnalytics.activity.tokensDescription`)})]}),(0,E.jsx)(`div`,{className:`inline-flex w-fit rounded-xl bg-gray-100 p-1 dark:bg-dark-200/80`,children:[`calls`,`tokens`].map(e=>(0,E.jsx)(`button`,{type:`button`,"aria-pressed":t===e,className:a(`rounded-lg px-3 py-1.5 text-xs font-medium transition-colors`,t===e?`bg-white text-gray-950 shadow-sm dark:bg-dark-300 dark:text-dark-950`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),onClick:()=>n(e),children:r(`usageAnalytics.metrics.${e}`)},e))})]}),(0,E.jsx)(`div`,{className:`px-2 pb-3 pt-4 sm:px-5 sm:pt-6`,children:(0,E.jsxs)(`svg`,{viewBox:`0 0 960 280`,className:`h-auto w-full overflow-visible`,role:`img`,"aria-label":r(`usageAnalytics.activity.chartLabel`,{metric:r(`usageAnalytics.metrics.${t}`)}),children:[(0,E.jsx)(`defs`,{children:(0,E.jsxs)(`linearGradient`,{id:`plugin-usage-area`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,E.jsx)(`stop`,{offset:`0%`,stopColor:`rgb(var(--color-primary-500))`,stopOpacity:`0.28`}),(0,E.jsx)(`stop`,{offset:`100%`,stopColor:`rgb(var(--color-primary-500))`,stopOpacity:`0.015`})]})}),[0,.25,.5,.75,1].map(e=>{let t=o.top+u*e,n=Math.round(c*(1-e));return(0,E.jsxs)(`g`,{children:[(0,E.jsx)(`line`,{x1:o.left,x2:960-o.right,y1:t,y2:t,className:`stroke-gray-200 dark:stroke-white/[0.07]`,strokeDasharray:e===1?void 0:`4 8`}),(0,E.jsx)(`text`,{x:o.left-12,y:t+4,textAnchor:`end`,className:`fill-gray-400 text-[11px] dark:fill-dark-500`,children:M(n)})]},e)}),h&&(0,E.jsx)(`path`,{d:h,fill:`url(#plugin-usage-area)`}),m&&(0,E.jsx)(`path`,{d:m,fill:`none`,className:`stroke-primary-500 dark:stroke-primary-400`,strokeWidth:`3`,strokeLinecap:`round`,strokeLinejoin:`round`}),(e.series.length<=31?p:[]).map(({x:e,y:n,point:i})=>(0,E.jsx)(`circle`,{cx:e,cy:n,r:`4`,className:`fill-white stroke-primary-500 dark:fill-dark-100 dark:stroke-primary-400`,strokeWidth:`2.5`,children:(0,E.jsx)(`title`,{children:`${g.format(i.timestamp)}: ${M(i[t])} ${r(`usageAnalytics.metrics.${t}`).toLocaleLowerCase()}`})},i.timestamp)),_.map(t=>{let n=e.series[t];if(!n)return null;let r=t===0?`start`:t===e.series.length-1?`end`:`middle`;return(0,E.jsx)(`text`,{x:d(t),y:270,textAnchor:r,className:`fill-gray-500 text-[12px] dark:fill-dark-500`,children:g.format(n.timestamp)},n.timestamp)})]})})]})},I=864e5,L=10,R=12,z=30,B=16,V=[`fill-blue-500`,`fill-emerald-500 dark:fill-emerald-600`,`fill-amber-500 dark:fill-amber-600`,`fill-violet-500`,`fill-rose-500`],H=[`bg-blue-500`,`bg-emerald-500 dark:bg-emerald-600`,`bg-amber-500 dark:bg-amber-600`,`bg-violet-500`,`bg-rose-500`],U=`fill-gray-400 dark:fill-gray-500`,W=`bg-gray-400 dark:bg-gray-500`,G=`fill-gray-950/[0.06] dark:fill-white/[0.07]`,K=[0,.35,.55,.75,1],q=({heatmap:e})=>{let{t,i18n:n}=i(),[r,o]=(0,w.useState)(null),{weeks:s,firstColStart:c,cellsByDay:l,maxCalls:u,modelRank:d,totalCalls:f}=(0,w.useMemo)(()=>{let t=new Map(e.cells.map(e=>[e.timestamp,e])),n=e.from,r=e.from+(e.days-1)*I,i=n-new Date(n).getUTCDay()*I;return{weeks:Math.ceil((r-i+I)/(7*I)),firstColStart:i,cellsByDay:t,maxCalls:Math.max(1,...e.cells.map(e=>e.calls)),modelRank:new Map(e.models.map((e,t)=>[e,t])),totalCalls:e.cells.reduce((e,t)=>e+t.calls,0)}},[e]),p=new Intl.DateTimeFormat(n.language,{month:`short`,timeZone:`UTC`}),m=new Intl.DateTimeFormat(n.language,{weekday:`short`,timeZone:`UTC`}),h=new Intl.DateTimeFormat(n.language,{dateStyle:`medium`,timeZone:`UTC`}),g=e.from,_=e.from+(e.days-1)*I,v=z+s*R,y=[],b=-1;for(let e=0;e<s;e++){let t=c+e*7*I,n=Math.max(t,g),r=new Date(n).getUTCMonth();r!==b&&t>=g-6*I&&((b!==-1||t>=g)&&y.push({x:z+e*R,label:p.format(n)}),b=r)}let x=e=>e<=0?0:Math.min(4,Math.max(1,Math.ceil(e/u*4))),S=e=>{let t=e.models[0]?.model,n=t===void 0?void 0:d.get(t);return n===void 0?U:V[n]},C=(e,t,n)=>{let r=e.currentTarget.closest(`[data-heatmap-wrapper]`);if(!r)return;let i=r.getBoundingClientRect(),a=e.currentTarget.getBoundingClientRect(),s=a.left-i.left+a.width/2;o({x:Math.min(Math.max(s,96),Math.max(i.width-96,96)),y:a.top-i.top,timestamp:t,calls:n.calls,models:n.models})};return(0,E.jsxs)(`section`,{"data-testid":`usage-heatmap`,className:`overflow-hidden rounded-2xl border border-gray-200/80 bg-white/80 shadow-subtle backdrop-blur-md dark:border-white/[0.08] dark:bg-dark-100/75`,children:[(0,E.jsxs)(`div`,{className:`flex flex-col gap-1 border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.07] sm:flex-row sm:items-center sm:justify-between sm:px-5`,children:[(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:t(`usageAnalytics.heatmap.title`)}),(0,E.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.heatmap.description`)})]}),(0,E.jsx)(`span`,{className:`shrink-0 text-xs tabular-nums text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.heatmap.yearTotal`,{count:f,formatted:M(f)})})]}),(0,E.jsxs)(`div`,{className:`relative p-4 sm:px-5`,"data-heatmap-wrapper":!0,children:[(0,E.jsx)(`div`,{className:`overflow-x-auto`,children:(0,E.jsxs)(`svg`,{viewBox:`0 0 ${v} 100`,className:`h-auto w-full min-w-[640px]`,role:`img`,"aria-label":t(`usageAnalytics.heatmap.title`),onMouseLeave:()=>o(null),children:[y.map(({x:e,label:t})=>(0,E.jsx)(`text`,{x:e,y:10,className:`fill-gray-400 text-[8px] dark:fill-dark-500`,children:t},`${e}-${t}`)),[1,3,5].map(e=>(0,E.jsx)(`text`,{x:0,y:B+e*R+L-2,className:`fill-gray-400 text-[8px] dark:fill-dark-500`,children:m.format(new Date(Date.UTC(2023,0,1+e)))},e)),Array.from({length:s},(e,t)=>Array.from({length:7},(e,n)=>{let i=c+(t*7+n)*I;if(i<g||i>_)return null;let o=l.get(i),s=o?.calls??0,u=x(s);return(0,E.jsx)(`rect`,{x:z+t*R,y:B+n*R,width:L,height:L,rx:2,fillOpacity:u===0?1:K[u],strokeWidth:+(r?.timestamp===i),className:a(`transition-opacity`,u===0||!o?G:S(o),r?.timestamp===i?`stroke-gray-500 dark:stroke-white/60`:`stroke-transparent`),onMouseEnter:e=>C(e,i,{calls:s,models:o?.models??[]}),children:(0,E.jsx)(`title`,{children:`${h.format(i)} — ${M(s)}`})},i)}))]})}),r&&(0,E.jsxs)(`div`,{className:`pointer-events-none absolute z-10 min-w-[10rem] -translate-x-1/2 -translate-y-full rounded-lg border border-gray-200/80 bg-white/95 px-3 py-2 shadow-card backdrop-blur-md dark:border-white/[0.1] dark:bg-dark-100/95`,style:{left:r.x,top:r.y-6},children:[(0,E.jsx)(`div`,{className:`text-[11px] font-medium text-gray-900 dark:text-dark-900`,children:h.format(r.timestamp)}),(0,E.jsx)(`div`,{className:`mt-0.5 text-[11px] text-gray-500 dark:text-dark-500`,children:r.calls===0?t(`usageAnalytics.heatmap.noCalls`):`${M(r.calls)} ${t(`usageAnalytics.heatmap.calls`)}`}),r.models.slice(0,3).map(e=>(0,E.jsxs)(`div`,{className:`mt-1 flex items-center justify-between gap-3 text-[11px]`,children:[(0,E.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,E.jsx)(`span`,{className:a(`h-2 w-2 shrink-0 rounded-[3px]`,d.has(e.model)?H[d.get(e.model)]:W)}),(0,E.jsx)(`span`,{className:`truncate font-mono text-gray-700 dark:text-dark-700`,dir:`ltr`,children:e.model})]}),(0,E.jsx)(`span`,{className:`tabular-nums text-gray-500 dark:text-dark-500`,children:M(e.calls)})]},e.model))]}),(0,E.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center justify-between gap-3`,children:[(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5`,children:[e.models.map((e,t)=>(0,E.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-gray-600 dark:text-dark-600`,children:[(0,E.jsx)(`span`,{className:a(`h-2.5 w-2.5 rounded-[3px]`,H[t])}),(0,E.jsx)(`span`,{className:`font-mono`,dir:`ltr`,children:e})]},e)),(0,E.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-gray-600 dark:text-dark-600`,children:[(0,E.jsx)(`span`,{className:a(`h-2.5 w-2.5 rounded-[3px]`,W)}),t(`usageAnalytics.heatmap.other`)]})]}),(0,E.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] text-gray-500 dark:text-dark-500`,children:[t(`usageAnalytics.heatmap.less`),(0,E.jsx)(`span`,{className:`h-2.5 w-2.5 rounded-[3px] bg-gray-950/[0.06] dark:bg-white/[0.07]`}),K.slice(1).map(e=>(0,E.jsx)(`span`,{className:`h-2.5 w-2.5 rounded-[3px] bg-primary-500`,style:{opacity:e}},e)),t(`usageAnalytics.heatmap.more`)]})]})]})]})},J=()=>{let{t:e}=i(),[t,n]=(0,w.useState)(30),[l,f]=(0,w.useState)(`calls`),{data:p,error:_,isLoading:y,isFetching:T,refetch:D}=r({queryKey:[`plugin-usage`,t],queryFn:async()=>{let n=await b.getUsage(t);if(!n.success||!n.data)throw Error(n.error||e(`usageAnalytics.loadFailed`));return n.data}}),O=_?_ instanceof Error?_.message:e(`usageAnalytics.loadFailed`):null,A=p?.totals,j=(0,w.useMemo)(()=>[{label:e(`usageAnalytics.cards.calls`),value:M(A?.calls??0),detail:e(`usageAnalytics.cards.callsDetail`,{count:A?.uniqueUsers??0}),icon:v},{label:e(`usageAnalytics.cards.tokens`),value:M(A?.reportedTokens??0),detail:e(`usageAnalytics.cards.tokensDetail`,{count:A?.meteredCalls??0}),icon:d},{label:e(`usageAnalytics.cards.success`),value:`${P(A?.calls??0,(A?.failedCalls??0)+(A?.cancelledCalls??0)).toFixed(1)}%`,detail:e(`usageAnalytics.cards.successDetail`,{count:A?.failedCalls??0}),icon:o},{label:e(`usageAnalytics.cards.latency`),value:N(A?.averageLatencyMs??0),detail:e(`usageAnalytics.cards.latencyDetail`),icon:c}],[e,A]);return y&&!p?(0,E.jsx)(C,{width:`wide`,children:(0,E.jsx)(`div`,{className:`flex min-h-[50vh] items-center justify-center`,children:(0,E.jsx)(s,{className:`h-7 w-7 animate-spin text-primary-500`})})}):(0,E.jsxs)(C,{width:`wide`,children:[(0,E.jsx)(S,{eyebrow:e(`usageAnalytics.eyebrow`),title:e(`usageAnalytics.title`),description:e(`usageAnalytics.description`),actions:(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(`div`,{className:`inline-flex rounded-xl border border-gray-200 bg-white/70 p-1 dark:border-white/[0.08] dark:bg-dark-100/70`,children:[7,30,90].map(r=>(0,E.jsx)(`button`,{type:`button`,className:a(`rounded-lg px-3 py-1.5 text-xs font-medium transition-colors`,t===r?`bg-gray-950 text-white dark:bg-white dark:text-gray-950`:`text-gray-500 hover:text-gray-900 dark:text-dark-500 dark:hover:text-dark-900`),onClick:()=>n(r),children:e(`usageAnalytics.days`,{count:r})},r))}),(0,E.jsxs)(x,{variant:`outline`,size:`sm`,onClick:()=>void D(),disabled:T,children:[(0,E.jsx)(u,{className:a(`h-4 w-4`,T&&`animate-spin`)}),(0,E.jsx)(`span`,{className:`sr-only`,children:e(`usageAnalytics.refresh`)})]})]})}),O&&(0,E.jsxs)(`div`,{className:`mb-6 flex items-center gap-3 rounded-2xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700 dark:border-red-900/40 dark:bg-red-950/30 dark:text-red-300`,children:[(0,E.jsx)(m,{className:`h-4 w-4 shrink-0`}),(0,E.jsx)(`span`,{children:O})]}),(0,E.jsx)(`div`,{className:`mb-6`,children:(0,E.jsx)(k,{days:t})}),p&&(0,E.jsxs)(`div`,{className:`space-y-4`,children:[(0,E.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-4`,children:j.map(e=>{let t=e.icon;return(0,E.jsxs)(`section`,{className:`rounded-2xl border border-gray-200/80 bg-white/75 p-4 shadow-subtle backdrop-blur-md dark:border-white/[0.08] dark:bg-dark-100/70`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,E.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-[0.12em] text-gray-500 dark:text-dark-500`,children:e.label}),(0,E.jsx)(t,{className:`h-4 w-4 text-primary-500 dark:text-primary-400`})]}),(0,E.jsx)(`div`,{className:`mt-2 text-2xl font-normal tracking-[-0.04em] text-gray-950 dark:text-dark-950`,children:e.value}),(0,E.jsx)(`p`,{className:`mt-1.5 text-xs text-gray-500 dark:text-dark-500`,children:e.detail})]},e.label)})}),p.heatmap&&p.heatmap.cells.length>0&&(0,E.jsx)(q,{heatmap:p.heatmap}),(0,E.jsx)(F,{analytics:p,metric:l,onMetricChange:f}),p.totals.calls===0?(0,E.jsxs)(`div`,{className:`rounded-2xl border border-dashed border-gray-300 px-6 py-10 text-center dark:border-white/[0.12]`,children:[(0,E.jsx)(h,{className:`mx-auto h-8 w-8 text-gray-400 dark:text-dark-500`}),(0,E.jsx)(`h2`,{className:`mt-4 text-base font-medium text-gray-900 dark:text-dark-900`,children:e(`usageAnalytics.empty.title`)}),(0,E.jsx)(`p`,{className:`mx-auto mt-2 max-w-md text-sm leading-6 text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.empty.description`)})]}):(0,E.jsxs)(`div`,{className:`grid gap-4 xl:grid-cols-[1.15fr_0.85fr]`,children:[(0,E.jsxs)(`section`,{className:`overflow-hidden rounded-2xl border border-gray-200/80 bg-white/80 shadow-subtle backdrop-blur-md dark:border-white/[0.08] dark:bg-dark-100/75`,children:[(0,E.jsxs)(`div`,{className:`border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.07] sm:px-5`,children:[(0,E.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e(`usageAnalytics.models.title`)}),(0,E.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.models.description`)})]}),(0,E.jsx)(`div`,{className:`overflow-x-auto`,children:(0,E.jsxs)(`table`,{className:`w-full min-w-[620px] text-start text-sm`,children:[(0,E.jsx)(`thead`,{className:`text-[11px] uppercase tracking-[0.1em] text-gray-400 dark:text-dark-500`,children:(0,E.jsxs)(`tr`,{children:[(0,E.jsx)(`th`,{className:`px-5 py-2 text-start font-medium`,children:e(`usageAnalytics.models.model`)}),(0,E.jsx)(`th`,{className:`px-4 py-2 text-end font-medium`,children:e(`usageAnalytics.metrics.calls`)}),(0,E.jsx)(`th`,{className:`px-4 py-2 text-end font-medium`,children:e(`usageAnalytics.metrics.tokens`)}),(0,E.jsx)(`th`,{className:`px-4 py-2 text-end font-medium`,children:e(`usageAnalytics.models.success`)}),(0,E.jsx)(`th`,{className:`px-5 py-2 text-end font-medium`,children:e(`usageAnalytics.models.latency`)})]})}),(0,E.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-white/[0.06]`,children:p.models.slice(0,12).map(e=>(0,E.jsxs)(`tr`,{children:[(0,E.jsxs)(`td`,{className:`px-5 py-2.5`,children:[(0,E.jsx)(`div`,{className:`max-w-[260px] truncate font-medium text-gray-900 dark:text-dark-900`,title:e.model,children:e.model}),(0,E.jsx)(`div`,{className:`mt-0.5 text-xs text-gray-500 dark:text-dark-500`,children:e.pluginName})]}),(0,E.jsx)(`td`,{className:`px-4 py-2.5 text-end tabular-nums text-gray-700 dark:text-dark-700`,children:M(e.calls)}),(0,E.jsx)(`td`,{className:`px-4 py-2.5 text-end tabular-nums text-gray-700 dark:text-dark-700`,children:e.tokens?M(e.tokens):`—`}),(0,E.jsxs)(`td`,{className:`px-4 py-2.5 text-end tabular-nums text-gray-700 dark:text-dark-700`,children:[P(e.calls,e.errors).toFixed(1),`%`]}),(0,E.jsx)(`td`,{className:`px-5 py-2.5 text-end tabular-nums text-gray-500 dark:text-dark-500`,children:N(e.averageLatencyMs)})]},`${e.pluginId}:${e.model}`))})]})})]}),(0,E.jsxs)(`div`,{className:`space-y-4`,children:[(0,E.jsxs)(`section`,{className:`rounded-2xl border border-gray-200/80 bg-white/80 p-4 shadow-subtle backdrop-blur-md dark:border-white/[0.08] dark:bg-dark-100/75 sm:p-5`,children:[(0,E.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e(`usageAnalytics.providers.title`)}),(0,E.jsx)(`div`,{className:`mt-5 space-y-4`,children:p.plugins.slice(0,8).map(t=>{let n=p.totals.calls?t.calls/p.totals.calls*100:0;return(0,E.jsxs)(`div`,{children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[(0,E.jsxs)(`div`,{className:`min-w-0`,children:[(0,E.jsx)(`div`,{className:`truncate font-medium text-gray-900 dark:text-dark-900`,children:t.pluginName}),(0,E.jsxs)(`div`,{className:`mt-0.5 text-xs text-gray-500 dark:text-dark-500`,children:[M(t.tokens),` `,e(`usageAnalytics.metrics.tokens`).toLocaleLowerCase()]})]}),(0,E.jsx)(`span`,{className:`shrink-0 tabular-nums text-gray-600 dark:text-dark-600`,children:M(t.calls)})]}),(0,E.jsx)(`div`,{className:`mt-2 h-1.5 overflow-hidden rounded-full bg-gray-100 dark:bg-dark-300`,children:(0,E.jsx)(`div`,{className:`h-full rounded-full bg-primary-500 dark:bg-primary-400`,style:{width:`${Math.max(2,n)}%`}})})]},t.pluginId)})})]}),(0,E.jsxs)(`section`,{className:`rounded-2xl border border-gray-200/80 bg-white/80 p-4 shadow-subtle backdrop-blur-md dark:border-white/[0.08] dark:bg-dark-100/75 sm:p-5`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(g,{className:`h-4 w-4 text-primary-500 dark:text-primary-400`}),(0,E.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e(`usageAnalytics.capabilities.title`)})]}),(0,E.jsx)(`div`,{className:`mt-5 grid grid-cols-2 gap-3`,children:p.capabilities.map(t=>(0,E.jsxs)(`div`,{className:`rounded-xl bg-gray-50 px-3 py-2.5 dark:bg-dark-200/70`,children:[(0,E.jsx)(`div`,{className:`text-xs font-medium capitalize text-gray-500 dark:text-dark-500`,children:t.capability}),(0,E.jsx)(`div`,{className:`mt-1 text-xl text-gray-950 dark:text-dark-950`,children:M(t.calls)}),(0,E.jsx)(`div`,{className:`mt-1 text-[11px] text-gray-500 dark:text-dark-500`,children:t.capability===`tts`?e(`usageAnalytics.capabilities.characters`,{count:M(t.inputUnits)}):t.capability===`stt`?e(`usageAnalytics.capabilities.bytes`,{count:M(t.inputUnits)}):t.capability===`image`?e(`usageAnalytics.capabilities.images`,{count:M(t.outputUnits)}):t.capability===`video`?e(`usageAnalytics.capabilities.jobs`,{count:M(t.calls)}):t.capability===`embedding`?e(`usageAnalytics.capabilities.inputs`,{count:M(t.inputUnits)}):e(`usageAnalytics.capabilities.reportedTokens`,{count:M(t.tokens)})})]},t.capability))})]})]})]}),(0,E.jsx)(`p`,{className:`px-1 text-xs leading-5 text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.privacyNote`)})]})]})};export{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{t as r}from"./useQuery-BKulzCS7.js";import{t as i}from"./useTranslation-rdLmo6zV.js";import{t as a}from"./utils-CKWltgs8.js";import{Bn as o,Ft as s,In as c,Tn as l,Z as u,an as d,br as f,et as p,g as m,or as h,s as g,v as _,vr as v}from"./ui-vendor-BvD5yGW1.js";import{n as y}from"./workApi-0L8fBGq1.js";import{u as b}from"./api-DEOxp9DN.js";import{t as x}from"./Button-BxwbQ5xw.js";import{a as S,o as C}from"./ui-BQojEu4t.js";var w=e(t(),1),T={getAnalytics:e=>y.get(`/costs/analytics`,{params:{days:e}}).then(e=>e.data),listTariffs:()=>y.get(`/costs/tariffs`).then(e=>e.data),createTariff:e=>y.post(`/costs/tariffs`,e).then(e=>e.data),deleteTariff:e=>y.delete(`/costs/tariffs/${encodeURIComponent(e)}`).then(()=>void 0),listBudgets:()=>y.get(`/costs/budgets`).then(e=>e.data),createBudget:e=>y.post(`/costs/budgets`,e).then(e=>e.data),deleteBudget:e=>y.delete(`/costs/budgets/${encodeURIComponent(e)}`).then(()=>void 0),exportUrl:e=>`/api/costs/export?days=${e}`,exportCsv:e=>y.get(`/costs/export`,{params:{days:e},responseType:`blob`}).then(e=>e.data)},E=n(),D=e=>new Intl.NumberFormat(void 0,{style:`currency`,currency:`USD`,maximumFractionDigits:e<1?4:2}).format(e),O=`w-full rounded-lg border border-gray-300 bg-white px-2 py-1.5 text-sm dark:border-dark-300 dark:bg-dark-50`,k=({days:e})=>{let{t}=i(),[n,r]=(0,w.useState)(null),[a,o]=(0,w.useState)([]),[c,u]=(0,w.useState)([]),[d,m]=(0,w.useState)(!0),[h,g]=(0,w.useState)(0),[v,y]=(0,w.useState)({pluginId:``,model:``,inputPerMillion:``,outputPerMillion:``,unitPrice:``}),[b,S]=(0,w.useState)({name:``,principalType:`instance`,principalId:``,period:`monthly`,amountUsd:``,mode:`soft`});(0,w.useEffect)(()=>{let n=!1;return Promise.all([T.getAnalytics(e),T.listTariffs(),T.listBudgets()]).then(([e,t,i])=>{n||(e.success&&e.data&&r(e.data),t.success&&t.data&&o(t.data),i.success&&i.data&&u(i.data))}).catch(()=>f.error(t(`costs.loadFailed`))).finally(()=>{n||m(!1)}),()=>{n=!0}},[e,h,t]);let C=e=>{if(!e.trim())return;let t=Number(e);return Number.isFinite(t)?t:void 0},k=async()=>{try{let e=await T.createTariff({pluginId:v.pluginId.trim(),model:v.model.trim()||void 0,inputPerMillion:C(v.inputPerMillion),outputPerMillion:C(v.outputPerMillion),unitPrice:C(v.unitPrice)});if(!e.success)throw Error(e.message);f.success(t(`costs.tariffSaved`)),y({pluginId:``,model:``,inputPerMillion:``,outputPerMillion:``,unitPrice:``}),g(e=>e+1)}catch(e){f.error(e instanceof Error?e.message:t(`costs.saveFailed`))}},A=async()=>{try{let e=await T.createBudget({name:b.name.trim(),principalType:b.principalType,principalId:b.principalType===`instance`?void 0:b.principalId.trim(),period:b.period,amountUsd:Number(b.amountUsd),mode:b.mode});if(!e.success)throw Error(e.message);f.success(t(`costs.budgetSaved`)),S({name:``,principalType:`instance`,principalId:``,period:`monthly`,amountUsd:``,mode:`soft`}),g(e=>e+1)}catch(e){f.error(e instanceof Error?e.message:t(`costs.saveFailed`))}},j=async()=>{try{let t=await T.exportCsv(e),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`libre-webui-costs.csv`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}catch{f.error(t(`costs.exportFailed`))}};return d&&!n?(0,E.jsx)(`div`,{className:`flex justify-center rounded-lg border border-gray-200 bg-white p-6 dark:border-dark-300 dark:bg-dark-100`,children:(0,E.jsx)(s,{className:`h-5 w-5 animate-spin text-gray-400`})}):(0,E.jsxs)(`div`,{className:`space-y-4 rounded-lg border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,"data-testid":`cost-governance-panel`,children:[(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:t(`costs.title`)}),(0,E.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:t(`costs.description`)})]}),(0,E.jsxs)(x,{size:`sm`,variant:`outline`,onClick:()=>void j(),children:[(0,E.jsx)(l,{className:`mr-1 h-3.5 w-3.5`}),t(`costs.exportCsv`)]})]}),n&&(0,E.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:[(0,E.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,E.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.totalSpend`)}),(0,E.jsx)(`p`,{className:`text-lg font-semibold`,children:D(n.totalUsd)})]}),(0,E.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,E.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.meteredEvents`)}),(0,E.jsx)(`p`,{className:`text-lg font-semibold`,children:n.meteredEvents})]}),(0,E.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,E.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.unmeteredEvents`)}),(0,E.jsx)(`p`,{className:`text-lg font-semibold`,children:n.unmeteredEvents})]}),(0,E.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,E.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.topModel`)}),(0,E.jsx)(`p`,{className:`truncate text-sm font-medium`,children:n.byModel[0]?`${n.byModel[0].model} (${D(n.byModel[0].usd)})`:`—`})]})]}),(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-gray-500`,children:t(`costs.budgets`)}),(0,E.jsxs)(`div`,{className:`space-y-2`,children:[n?.budgets.map(e=>{let n=Math.min(1,e.spentUsd/e.amountUsd);return(0,E.jsxs)(`div`,{className:`rounded-lg border border-gray-200 p-2 dark:border-dark-300`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-sm`,children:[(0,E.jsxs)(`span`,{className:`min-w-0 truncate font-medium`,children:[e.name,(0,E.jsxs)(`span`,{className:`ml-2 text-xs font-normal text-gray-500`,children:[t(`costs.mode.${e.mode}`),` ·`,` `,t(`costs.period.${e.period}`),` ·`,` `,e.principalType===`instance`?t(`costs.scope.instance`):`${t(`costs.scope.${e.principalType}`)}: ${e.principalId}`]})]}),(0,E.jsxs)(`span`,{className:`shrink-0 text-xs text-gray-600 dark:text-gray-300`,children:[D(e.spentUsd),` / `,D(e.amountUsd)]}),(0,E.jsx)(`button`,{onClick:()=>{T.deleteBudget(e.id).then(()=>g(e=>e+1)).catch(()=>f.error(t(`costs.saveFailed`)))},className:`shrink-0 rounded p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-950/30`,"aria-label":t(`costs.deleteBudget`),children:(0,E.jsx)(_,{className:`h-3.5 w-3.5`})})]}),(0,E.jsx)(`div`,{className:`mt-1 h-1.5 overflow-hidden rounded bg-gray-200 dark:bg-dark-300`,children:(0,E.jsx)(`div`,{className:n>=1?`h-full bg-red-500`:n>=.8?`h-full bg-amber-500`:`h-full bg-emerald-500`,style:{width:`${Math.round(n*100)}%`}})})]},e.id)}),c.length===0&&(0,E.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.noBudgets`)})]}),(0,E.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-2 sm:grid-cols-6`,children:[(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.budgetName`),value:b.name,onChange:e=>S({...b,name:e.target.value})}),(0,E.jsxs)(`select`,{className:O,value:b.principalType,onChange:e=>S({...b,principalType:e.target.value}),children:[(0,E.jsx)(`option`,{value:`instance`,children:t(`costs.scope.instance`)}),(0,E.jsx)(`option`,{value:`user`,children:t(`costs.scope.user`)}),(0,E.jsx)(`option`,{value:`group`,children:t(`costs.scope.group`)})]}),(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.principalId`),value:b.principalId,disabled:b.principalType===`instance`,onChange:e=>S({...b,principalId:e.target.value})}),(0,E.jsxs)(`select`,{className:O,value:b.period,onChange:e=>S({...b,period:e.target.value}),children:[(0,E.jsx)(`option`,{value:`daily`,children:t(`costs.period.daily`)}),(0,E.jsx)(`option`,{value:`weekly`,children:t(`costs.period.weekly`)}),(0,E.jsx)(`option`,{value:`monthly`,children:t(`costs.period.monthly`)})]}),(0,E.jsxs)(`div`,{className:`flex gap-2`,children:[(0,E.jsx)(`input`,{className:O,placeholder:`USD`,inputMode:`decimal`,value:b.amountUsd,onChange:e=>S({...b,amountUsd:e.target.value})}),(0,E.jsxs)(`select`,{className:O,value:b.mode,onChange:e=>S({...b,mode:e.target.value}),children:[(0,E.jsx)(`option`,{value:`observe`,children:t(`costs.mode.observe`)}),(0,E.jsx)(`option`,{value:`soft`,children:t(`costs.mode.soft`)}),(0,E.jsx)(`option`,{value:`hard`,children:t(`costs.mode.hard`)})]})]}),(0,E.jsxs)(x,{size:`sm`,onClick:()=>void A(),children:[(0,E.jsx)(p,{className:`mr-1 h-3.5 w-3.5`}),t(`costs.addBudget`)]})]})]}),(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-gray-500`,children:t(`costs.tariffs`)}),(0,E.jsx)(`div`,{className:`overflow-x-auto`,children:(0,E.jsxs)(`table`,{className:`w-full text-left text-xs`,children:[(0,E.jsx)(`thead`,{className:`text-gray-500`,children:(0,E.jsxs)(`tr`,{children:[(0,E.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.plugin`)}),(0,E.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.model`)}),(0,E.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.inputPerMillion`)}),(0,E.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.outputPerMillion`)}),(0,E.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.unitPrice`)}),(0,E.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.effectiveFrom`)}),(0,E.jsx)(`th`,{})]})}),(0,E.jsxs)(`tbody`,{children:[a.map(e=>(0,E.jsxs)(`tr`,{className:`border-t border-gray-100 dark:border-dark-300`,children:[(0,E.jsx)(`td`,{className:`py-1 pr-2`,children:e.plugin_id}),(0,E.jsx)(`td`,{className:`py-1 pr-2`,children:e.model??t(`costs.allModels`)}),(0,E.jsx)(`td`,{className:`py-1 pr-2`,children:e.input_per_million===null?`—`:D(e.input_per_million)}),(0,E.jsx)(`td`,{className:`py-1 pr-2`,children:e.output_per_million===null?`—`:D(e.output_per_million)}),(0,E.jsx)(`td`,{className:`py-1 pr-2`,children:e.unit_price===null?`—`:D(e.unit_price)}),(0,E.jsx)(`td`,{className:`py-1 pr-2`,children:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}).format(e.effective_from)}),(0,E.jsx)(`td`,{className:`py-1`,children:(0,E.jsx)(`button`,{onClick:()=>{T.deleteTariff(e.id).then(()=>g(e=>e+1)).catch(()=>f.error(t(`costs.saveFailed`)))},className:`rounded p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-950/30`,"aria-label":t(`costs.deleteTariff`),children:(0,E.jsx)(_,{className:`h-3.5 w-3.5`})})})]},e.id)),a.length===0&&(0,E.jsx)(`tr`,{children:(0,E.jsx)(`td`,{colSpan:7,className:`py-2 text-gray-500`,children:t(`costs.noTariffs`)})})]})]})}),(0,E.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-2 sm:grid-cols-6`,children:[(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.plugin`),value:v.pluginId,onChange:e=>y({...v,pluginId:e.target.value})}),(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.modelOptional`),value:v.model,onChange:e=>y({...v,model:e.target.value})}),(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.inputPerMillion`),inputMode:`decimal`,value:v.inputPerMillion,onChange:e=>y({...v,inputPerMillion:e.target.value})}),(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.outputPerMillion`),inputMode:`decimal`,value:v.outputPerMillion,onChange:e=>y({...v,outputPerMillion:e.target.value})}),(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.unitPrice`),inputMode:`decimal`,value:v.unitPrice,onChange:e=>y({...v,unitPrice:e.target.value})}),(0,E.jsxs)(x,{size:`sm`,onClick:()=>void k(),children:[(0,E.jsx)(p,{className:`mr-1 h-3.5 w-3.5`}),t(`costs.addTariff`)]})]})]})]})},A=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),j=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1}),M=e=>e>=1e4?j.format(e):A.format(e),N=e=>e?e<1e3?`${A.format(e)} ms`:`${(e/1e3).toFixed(+(e<1e4))} s`:`—`,P=(e,t)=>e===0?0:(e-t)/e*100,F=({analytics:e,metric:t,onMetricChange:n})=>{let{t:r}=i(),o={top:22,right:18,bottom:42,left:52},s=e.series.map(e=>e[t]),c=Math.max(1,...s),l=960-o.left-o.right,u=280-o.top-o.bottom,d=t=>o.left+(e.series.length<=1?l/2:t/(e.series.length-1)*l),f=e=>o.top+u-e/c*u,p=e.series.map((e,n)=>({x:d(n),y:f(e[t]),point:e})),m=p.map(({x:e,y:t},n)=>`${n===0?`M`:`L`} ${e} ${t}`).join(` `),h=p.length?`${m} L ${p[p.length-1].x} ${o.top+u} L ${p[0].x} ${o.top+u} Z`:``,g=new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,timeZone:`UTC`}),_=Array.from(new Set([0,Math.floor((e.series.length-1)/2),e.series.length-1])).filter(e=>e>=0);return(0,E.jsxs)(`div`,{"data-testid":`plugin-usage-chart`,className:`overflow-hidden rounded-2xl border border-gray-200/80 bg-white/80 shadow-subtle backdrop-blur-md dark:border-white/[0.08] dark:bg-dark-100/75`,children:[(0,E.jsxs)(`div`,{className:`flex flex-col gap-3 border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.07] sm:flex-row sm:items-center sm:justify-between sm:px-5`,children:[(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:r(`usageAnalytics.activity.title`)}),(0,E.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:r(t===`calls`?`usageAnalytics.activity.callsDescription`:`usageAnalytics.activity.tokensDescription`)})]}),(0,E.jsx)(`div`,{className:`inline-flex w-fit rounded-xl bg-gray-100 p-1 dark:bg-dark-200/80`,children:[`calls`,`tokens`].map(e=>(0,E.jsx)(`button`,{type:`button`,"aria-pressed":t===e,className:a(`rounded-lg px-3 py-1.5 text-xs font-medium transition-colors`,t===e?`bg-white text-gray-950 shadow-sm dark:bg-dark-300 dark:text-dark-950`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),onClick:()=>n(e),children:r(`usageAnalytics.metrics.${e}`)},e))})]}),(0,E.jsx)(`div`,{className:`px-2 pb-3 pt-4 sm:px-5 sm:pt-6`,children:(0,E.jsxs)(`svg`,{viewBox:`0 0 960 280`,className:`h-auto w-full overflow-visible`,role:`img`,"aria-label":r(`usageAnalytics.activity.chartLabel`,{metric:r(`usageAnalytics.metrics.${t}`)}),children:[(0,E.jsx)(`defs`,{children:(0,E.jsxs)(`linearGradient`,{id:`plugin-usage-area`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,E.jsx)(`stop`,{offset:`0%`,stopColor:`rgb(var(--color-primary-500))`,stopOpacity:`0.28`}),(0,E.jsx)(`stop`,{offset:`100%`,stopColor:`rgb(var(--color-primary-500))`,stopOpacity:`0.015`})]})}),[0,.25,.5,.75,1].map(e=>{let t=o.top+u*e,n=Math.round(c*(1-e));return(0,E.jsxs)(`g`,{children:[(0,E.jsx)(`line`,{x1:o.left,x2:960-o.right,y1:t,y2:t,className:`stroke-gray-200 dark:stroke-white/[0.07]`,strokeDasharray:e===1?void 0:`4 8`}),(0,E.jsx)(`text`,{x:o.left-12,y:t+4,textAnchor:`end`,className:`fill-gray-400 text-[11px] dark:fill-dark-500`,children:M(n)})]},e)}),h&&(0,E.jsx)(`path`,{d:h,fill:`url(#plugin-usage-area)`}),m&&(0,E.jsx)(`path`,{d:m,fill:`none`,className:`stroke-primary-500 dark:stroke-primary-400`,strokeWidth:`3`,strokeLinecap:`round`,strokeLinejoin:`round`}),(e.series.length<=31?p:[]).map(({x:e,y:n,point:i})=>(0,E.jsx)(`circle`,{cx:e,cy:n,r:`4`,className:`fill-white stroke-primary-500 dark:fill-dark-100 dark:stroke-primary-400`,strokeWidth:`2.5`,children:(0,E.jsx)(`title`,{children:`${g.format(i.timestamp)}: ${M(i[t])} ${r(`usageAnalytics.metrics.${t}`).toLocaleLowerCase()}`})},i.timestamp)),_.map(t=>{let n=e.series[t];if(!n)return null;let r=t===0?`start`:t===e.series.length-1?`end`:`middle`;return(0,E.jsx)(`text`,{x:d(t),y:270,textAnchor:r,className:`fill-gray-500 text-[12px] dark:fill-dark-500`,children:g.format(n.timestamp)},n.timestamp)})]})})]})},I=864e5,L=10,R=12,z=30,B=16,V=[`fill-blue-500`,`fill-emerald-500 dark:fill-emerald-600`,`fill-amber-500 dark:fill-amber-600`,`fill-violet-500`,`fill-rose-500`],H=[`bg-blue-500`,`bg-emerald-500 dark:bg-emerald-600`,`bg-amber-500 dark:bg-amber-600`,`bg-violet-500`,`bg-rose-500`],U=`fill-gray-400 dark:fill-gray-500`,W=`bg-gray-400 dark:bg-gray-500`,G=`fill-gray-950/[0.06] dark:fill-white/[0.07]`,K=[0,.35,.55,.75,1],q=({heatmap:e})=>{let{t,i18n:n}=i(),[r,o]=(0,w.useState)(null),{weeks:s,firstColStart:c,cellsByDay:l,maxCalls:u,modelRank:d,totalCalls:f}=(0,w.useMemo)(()=>{let t=new Map(e.cells.map(e=>[e.timestamp,e])),n=e.from,r=e.from+(e.days-1)*I,i=n-new Date(n).getUTCDay()*I;return{weeks:Math.ceil((r-i+I)/(7*I)),firstColStart:i,cellsByDay:t,maxCalls:Math.max(1,...e.cells.map(e=>e.calls)),modelRank:new Map(e.models.map((e,t)=>[e,t])),totalCalls:e.cells.reduce((e,t)=>e+t.calls,0)}},[e]),p=new Intl.DateTimeFormat(n.language,{month:`short`,timeZone:`UTC`}),m=new Intl.DateTimeFormat(n.language,{weekday:`short`,timeZone:`UTC`}),h=new Intl.DateTimeFormat(n.language,{dateStyle:`medium`,timeZone:`UTC`}),g=e.from,_=e.from+(e.days-1)*I,v=z+s*R,y=[],b=-1;for(let e=0;e<s;e++){let t=c+e*7*I,n=Math.max(t,g),r=new Date(n).getUTCMonth();r!==b&&t>=g-6*I&&((b!==-1||t>=g)&&y.push({x:z+e*R,label:p.format(n)}),b=r)}let x=e=>e<=0?0:Math.min(4,Math.max(1,Math.ceil(e/u*4))),S=e=>{let t=e.models[0]?.model,n=t===void 0?void 0:d.get(t);return n===void 0?U:V[n]},C=(e,t,n)=>{let r=e.currentTarget.closest(`[data-heatmap-wrapper]`);if(!r)return;let i=r.getBoundingClientRect(),a=e.currentTarget.getBoundingClientRect(),s=a.left-i.left+a.width/2;o({x:Math.min(Math.max(s,96),Math.max(i.width-96,96)),y:a.top-i.top,timestamp:t,calls:n.calls,models:n.models})};return(0,E.jsxs)(`section`,{"data-testid":`usage-heatmap`,className:`overflow-hidden rounded-2xl border border-gray-200/80 bg-white/80 shadow-subtle backdrop-blur-md dark:border-white/[0.08] dark:bg-dark-100/75`,children:[(0,E.jsxs)(`div`,{className:`flex flex-col gap-1 border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.07] sm:flex-row sm:items-center sm:justify-between sm:px-5`,children:[(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:t(`usageAnalytics.heatmap.title`)}),(0,E.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.heatmap.description`)})]}),(0,E.jsx)(`span`,{className:`shrink-0 text-xs tabular-nums text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.heatmap.yearTotal`,{count:f,formatted:M(f)})})]}),(0,E.jsxs)(`div`,{className:`relative p-4 sm:px-5`,"data-heatmap-wrapper":!0,children:[(0,E.jsx)(`div`,{className:`overflow-x-auto`,children:(0,E.jsxs)(`svg`,{viewBox:`0 0 ${v} 100`,className:`h-auto w-full min-w-[640px]`,role:`img`,"aria-label":t(`usageAnalytics.heatmap.title`),onMouseLeave:()=>o(null),children:[y.map(({x:e,label:t})=>(0,E.jsx)(`text`,{x:e,y:10,className:`fill-gray-400 text-[8px] dark:fill-dark-500`,children:t},`${e}-${t}`)),[1,3,5].map(e=>(0,E.jsx)(`text`,{x:0,y:B+e*R+L-2,className:`fill-gray-400 text-[8px] dark:fill-dark-500`,children:m.format(new Date(Date.UTC(2023,0,1+e)))},e)),Array.from({length:s},(e,t)=>Array.from({length:7},(e,n)=>{let i=c+(t*7+n)*I;if(i<g||i>_)return null;let o=l.get(i),s=o?.calls??0,u=x(s);return(0,E.jsx)(`rect`,{x:z+t*R,y:B+n*R,width:L,height:L,rx:2,fillOpacity:u===0?1:K[u],strokeWidth:+(r?.timestamp===i),className:a(`transition-opacity`,u===0||!o?G:S(o),r?.timestamp===i?`stroke-gray-500 dark:stroke-white/60`:`stroke-transparent`),onMouseEnter:e=>C(e,i,{calls:s,models:o?.models??[]}),children:(0,E.jsx)(`title`,{children:`${h.format(i)} — ${M(s)}`})},i)}))]})}),r&&(0,E.jsxs)(`div`,{className:`pointer-events-none absolute z-10 min-w-[10rem] -translate-x-1/2 -translate-y-full rounded-lg border border-gray-200/80 bg-white/95 px-3 py-2 shadow-card backdrop-blur-md dark:border-white/[0.1] dark:bg-dark-100/95`,style:{left:r.x,top:r.y-6},children:[(0,E.jsx)(`div`,{className:`text-[11px] font-medium text-gray-900 dark:text-dark-900`,children:h.format(r.timestamp)}),(0,E.jsx)(`div`,{className:`mt-0.5 text-[11px] text-gray-500 dark:text-dark-500`,children:r.calls===0?t(`usageAnalytics.heatmap.noCalls`):`${M(r.calls)} ${t(`usageAnalytics.heatmap.calls`)}`}),r.models.slice(0,3).map(e=>(0,E.jsxs)(`div`,{className:`mt-1 flex items-center justify-between gap-3 text-[11px]`,children:[(0,E.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,E.jsx)(`span`,{className:a(`h-2 w-2 shrink-0 rounded-[3px]`,d.has(e.model)?H[d.get(e.model)]:W)}),(0,E.jsx)(`span`,{className:`truncate font-mono text-gray-700 dark:text-dark-700`,dir:`ltr`,children:e.model})]}),(0,E.jsx)(`span`,{className:`tabular-nums text-gray-500 dark:text-dark-500`,children:M(e.calls)})]},e.model))]}),(0,E.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center justify-between gap-3`,children:[(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5`,children:[e.models.map((e,t)=>(0,E.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-gray-600 dark:text-dark-600`,children:[(0,E.jsx)(`span`,{className:a(`h-2.5 w-2.5 rounded-[3px]`,H[t])}),(0,E.jsx)(`span`,{className:`font-mono`,dir:`ltr`,children:e})]},e)),(0,E.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-gray-600 dark:text-dark-600`,children:[(0,E.jsx)(`span`,{className:a(`h-2.5 w-2.5 rounded-[3px]`,W)}),t(`usageAnalytics.heatmap.other`)]})]}),(0,E.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] text-gray-500 dark:text-dark-500`,children:[t(`usageAnalytics.heatmap.less`),(0,E.jsx)(`span`,{className:`h-2.5 w-2.5 rounded-[3px] bg-gray-950/[0.06] dark:bg-white/[0.07]`}),K.slice(1).map(e=>(0,E.jsx)(`span`,{className:`h-2.5 w-2.5 rounded-[3px] bg-primary-500`,style:{opacity:e}},e)),t(`usageAnalytics.heatmap.more`)]})]})]})]})},J=()=>{let{t:e}=i(),[t,n]=(0,w.useState)(30),[l,f]=(0,w.useState)(`calls`),{data:p,error:_,isLoading:y,isFetching:T,refetch:D}=r({queryKey:[`plugin-usage`,t],queryFn:async()=>{let n=await b.getUsage(t);if(!n.success||!n.data)throw Error(n.error||e(`usageAnalytics.loadFailed`));return n.data}}),O=_?_ instanceof Error?_.message:e(`usageAnalytics.loadFailed`):null,A=p?.totals,j=(0,w.useMemo)(()=>[{label:e(`usageAnalytics.cards.calls`),value:M(A?.calls??0),detail:e(`usageAnalytics.cards.callsDetail`,{count:A?.uniqueUsers??0}),icon:v},{label:e(`usageAnalytics.cards.tokens`),value:M(A?.reportedTokens??0),detail:e(`usageAnalytics.cards.tokensDetail`,{count:A?.meteredCalls??0}),icon:d},{label:e(`usageAnalytics.cards.success`),value:`${P(A?.calls??0,(A?.failedCalls??0)+(A?.cancelledCalls??0)).toFixed(1)}%`,detail:e(`usageAnalytics.cards.successDetail`,{count:A?.failedCalls??0}),icon:o},{label:e(`usageAnalytics.cards.latency`),value:N(A?.averageLatencyMs??0),detail:e(`usageAnalytics.cards.latencyDetail`),icon:c}],[e,A]);return y&&!p?(0,E.jsx)(C,{width:`wide`,children:(0,E.jsx)(`div`,{className:`flex min-h-[50vh] items-center justify-center`,children:(0,E.jsx)(s,{className:`h-7 w-7 animate-spin text-primary-500`})})}):(0,E.jsxs)(C,{width:`wide`,children:[(0,E.jsx)(S,{eyebrow:e(`usageAnalytics.eyebrow`),title:e(`usageAnalytics.title`),description:e(`usageAnalytics.description`),actions:(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(`div`,{className:`inline-flex rounded-xl border border-gray-200 bg-white/70 p-1 dark:border-white/[0.08] dark:bg-dark-100/70`,children:[7,30,90].map(r=>(0,E.jsx)(`button`,{type:`button`,className:a(`rounded-lg px-3 py-1.5 text-xs font-medium transition-colors`,t===r?`bg-gray-950 text-white dark:bg-white dark:text-gray-950`:`text-gray-500 hover:text-gray-900 dark:text-dark-500 dark:hover:text-dark-900`),onClick:()=>n(r),children:e(`usageAnalytics.days`,{count:r})},r))}),(0,E.jsxs)(x,{variant:`outline`,size:`sm`,onClick:()=>void D(),disabled:T,children:[(0,E.jsx)(u,{className:a(`h-4 w-4`,T&&`animate-spin`)}),(0,E.jsx)(`span`,{className:`sr-only`,children:e(`usageAnalytics.refresh`)})]})]})}),O&&(0,E.jsxs)(`div`,{className:`mb-6 flex items-center gap-3 rounded-2xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700 dark:border-red-900/40 dark:bg-red-950/30 dark:text-red-300`,children:[(0,E.jsx)(m,{className:`h-4 w-4 shrink-0`}),(0,E.jsx)(`span`,{children:O})]}),(0,E.jsx)(`div`,{className:`mb-6`,children:(0,E.jsx)(k,{days:t})}),p&&(0,E.jsxs)(`div`,{className:`space-y-4`,children:[(0,E.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-4`,children:j.map(e=>{let t=e.icon;return(0,E.jsxs)(`section`,{className:`rounded-2xl border border-gray-200/80 bg-white/75 p-4 shadow-subtle backdrop-blur-md dark:border-white/[0.08] dark:bg-dark-100/70`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,E.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-[0.12em] text-gray-500 dark:text-dark-500`,children:e.label}),(0,E.jsx)(t,{className:`h-4 w-4 text-primary-500 dark:text-primary-400`})]}),(0,E.jsx)(`div`,{className:`mt-2 text-2xl font-normal tracking-[-0.04em] text-gray-950 dark:text-dark-950`,children:e.value}),(0,E.jsx)(`p`,{className:`mt-1.5 text-xs text-gray-500 dark:text-dark-500`,children:e.detail})]},e.label)})}),p.heatmap&&p.heatmap.cells.length>0&&(0,E.jsx)(q,{heatmap:p.heatmap}),(0,E.jsx)(F,{analytics:p,metric:l,onMetricChange:f}),p.totals.calls===0?(0,E.jsxs)(`div`,{className:`rounded-2xl border border-dashed border-gray-300 px-6 py-10 text-center dark:border-white/[0.12]`,children:[(0,E.jsx)(h,{className:`mx-auto h-8 w-8 text-gray-400 dark:text-dark-500`}),(0,E.jsx)(`h2`,{className:`mt-4 text-base font-medium text-gray-900 dark:text-dark-900`,children:e(`usageAnalytics.empty.title`)}),(0,E.jsx)(`p`,{className:`mx-auto mt-2 max-w-md text-sm leading-6 text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.empty.description`)})]}):(0,E.jsxs)(`div`,{className:`grid gap-4 xl:grid-cols-[1.15fr_0.85fr]`,children:[(0,E.jsxs)(`section`,{className:`overflow-hidden rounded-2xl border border-gray-200/80 bg-white/80 shadow-subtle backdrop-blur-md dark:border-white/[0.08] dark:bg-dark-100/75`,children:[(0,E.jsxs)(`div`,{className:`border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.07] sm:px-5`,children:[(0,E.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e(`usageAnalytics.models.title`)}),(0,E.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.models.description`)})]}),(0,E.jsx)(`div`,{className:`overflow-x-auto`,children:(0,E.jsxs)(`table`,{className:`w-full min-w-[620px] text-start text-sm`,children:[(0,E.jsx)(`thead`,{className:`text-[11px] uppercase tracking-[0.1em] text-gray-400 dark:text-dark-500`,children:(0,E.jsxs)(`tr`,{children:[(0,E.jsx)(`th`,{className:`px-5 py-2 text-start font-medium`,children:e(`usageAnalytics.models.model`)}),(0,E.jsx)(`th`,{className:`px-4 py-2 text-end font-medium`,children:e(`usageAnalytics.metrics.calls`)}),(0,E.jsx)(`th`,{className:`px-4 py-2 text-end font-medium`,children:e(`usageAnalytics.metrics.tokens`)}),(0,E.jsx)(`th`,{className:`px-4 py-2 text-end font-medium`,children:e(`usageAnalytics.models.success`)}),(0,E.jsx)(`th`,{className:`px-5 py-2 text-end font-medium`,children:e(`usageAnalytics.models.latency`)})]})}),(0,E.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-white/[0.06]`,children:p.models.slice(0,12).map(e=>(0,E.jsxs)(`tr`,{children:[(0,E.jsxs)(`td`,{className:`px-5 py-2.5`,children:[(0,E.jsx)(`div`,{className:`max-w-[260px] truncate font-medium text-gray-900 dark:text-dark-900`,title:e.model,children:e.model}),(0,E.jsx)(`div`,{className:`mt-0.5 text-xs text-gray-500 dark:text-dark-500`,children:e.pluginName})]}),(0,E.jsx)(`td`,{className:`px-4 py-2.5 text-end tabular-nums text-gray-700 dark:text-dark-700`,children:M(e.calls)}),(0,E.jsx)(`td`,{className:`px-4 py-2.5 text-end tabular-nums text-gray-700 dark:text-dark-700`,children:e.tokens?M(e.tokens):`—`}),(0,E.jsxs)(`td`,{className:`px-4 py-2.5 text-end tabular-nums text-gray-700 dark:text-dark-700`,children:[P(e.calls,e.errors).toFixed(1),`%`]}),(0,E.jsx)(`td`,{className:`px-5 py-2.5 text-end tabular-nums text-gray-500 dark:text-dark-500`,children:N(e.averageLatencyMs)})]},`${e.pluginId}:${e.model}`))})]})})]}),(0,E.jsxs)(`div`,{className:`space-y-4`,children:[(0,E.jsxs)(`section`,{className:`rounded-2xl border border-gray-200/80 bg-white/80 p-4 shadow-subtle backdrop-blur-md dark:border-white/[0.08] dark:bg-dark-100/75 sm:p-5`,children:[(0,E.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e(`usageAnalytics.providers.title`)}),(0,E.jsx)(`div`,{className:`mt-5 space-y-4`,children:p.plugins.slice(0,8).map(t=>{let n=p.totals.calls?t.calls/p.totals.calls*100:0;return(0,E.jsxs)(`div`,{children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[(0,E.jsxs)(`div`,{className:`min-w-0`,children:[(0,E.jsx)(`div`,{className:`truncate font-medium text-gray-900 dark:text-dark-900`,children:t.pluginName}),(0,E.jsxs)(`div`,{className:`mt-0.5 text-xs text-gray-500 dark:text-dark-500`,children:[M(t.tokens),` `,e(`usageAnalytics.metrics.tokens`).toLocaleLowerCase()]})]}),(0,E.jsx)(`span`,{className:`shrink-0 tabular-nums text-gray-600 dark:text-dark-600`,children:M(t.calls)})]}),(0,E.jsx)(`div`,{className:`mt-2 h-1.5 overflow-hidden rounded-full bg-gray-100 dark:bg-dark-300`,children:(0,E.jsx)(`div`,{className:`h-full rounded-full bg-primary-500 dark:bg-primary-400`,style:{width:`${Math.max(2,n)}%`}})})]},t.pluginId)})})]}),(0,E.jsxs)(`section`,{className:`rounded-2xl border border-gray-200/80 bg-white/80 p-4 shadow-subtle backdrop-blur-md dark:border-white/[0.08] dark:bg-dark-100/75 sm:p-5`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(g,{className:`h-4 w-4 text-primary-500 dark:text-primary-400`}),(0,E.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e(`usageAnalytics.capabilities.title`)})]}),(0,E.jsx)(`div`,{className:`mt-5 grid grid-cols-2 gap-3`,children:p.capabilities.map(t=>(0,E.jsxs)(`div`,{className:`rounded-xl bg-gray-50 px-3 py-2.5 dark:bg-dark-200/70`,children:[(0,E.jsx)(`div`,{className:`text-xs font-medium capitalize text-gray-500 dark:text-dark-500`,children:t.capability}),(0,E.jsx)(`div`,{className:`mt-1 text-xl text-gray-950 dark:text-dark-950`,children:M(t.calls)}),(0,E.jsx)(`div`,{className:`mt-1 text-[11px] text-gray-500 dark:text-dark-500`,children:t.capability===`tts`?e(`usageAnalytics.capabilities.characters`,{count:M(t.inputUnits)}):t.capability===`stt`?e(`usageAnalytics.capabilities.bytes`,{count:M(t.inputUnits)}):t.capability===`image`?e(`usageAnalytics.capabilities.images`,{count:M(t.outputUnits)}):t.capability===`video`?e(`usageAnalytics.capabilities.jobs`,{count:M(t.calls)}):t.capability===`embedding`?e(`usageAnalytics.capabilities.inputs`,{count:M(t.inputUnits)}):e(`usageAnalytics.capabilities.reportedTokens`,{count:M(t.tokens)})})]},t.capability))})]})]})]}),(0,E.jsx)(`p`,{className:`px-1 text-xs leading-5 text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.privacyNote`)})]})]})};export{J as default};
@@ -0,0 +1 @@
1
+ import{t as e}from"./RichMessageContent-yWLHf4YS.js";export{e as RichMessageContent,e as default};
@@ -1,3 +1,3 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["js/markdownMath-CoDj1i7z.js","js/markdown-math-Dg-WB9ui.js","js/markdown-core-D067gSd8.js","js/rolldown-runtime-hePW80VL.js","js/react-vendor-D0Ec-185.js","assets/markdown-math-Ddr6Z9Sf.css","js/markdownHtml-Djpz4yB3.js","js/markdown-html-CQM6wA9G.js","js/OptimizedSyntaxHighlighter-SkJc7ZMe.js","js/OptimizedSyntaxHighlighter-CtQ_FGCX.js","js/syntax-highlight-DTWfgxYh.js"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{o as r}from"./logger-DnuT4jgB.js";import{t as i}from"./utils-CKWltgs8.js";import{t as a}from"./appStore-DefVAJAx.js";import{a as o,i as s,n as c,r as l,s as u,t as d}from"./messageCodeStyles-ERvWXB7Y.js";import{i as f,s as p}from"./markdown-core-D067gSd8.js";var m=e(t(),1),h=null,g=null,_=null,v=null,y=()=>_??=r(()=>import(`./markdownMath-CoDj1i7z.js`).then(e=>(h=e,e)),__vite__mapDeps([0,1,2,3,4,5])),b=()=>v??=r(()=>import(`./markdownHtml-Djpz4yB3.js`).then(e=>(g=e,e)),__vite__mapDeps([6,7,2,3,4])),x=e=>e.includes(`$`);function S(e){let{needsMath:t,needsHtml:n}=e,[,r]=m.useReducer(e=>e+1,0);return m.useEffect(()=>{if(!t||h)return;let e=!1;return y().then(()=>{e||r()}),()=>{e=!0}},[t]),m.useEffect(()=>{if(!n||g)return;let e=!1;return b().then(()=>{e||r()}),()=>{e=!0}},[n]),{math:t?h:null,html:n?g:null}}var C=n(),w=m.lazy(()=>r(()=>import(`./OptimizedSyntaxHighlighter-SkJc7ZMe.js`),__vite__mapDeps([8,9,3,4,10,2])));function T({children:e,className:t}){return(0,C.jsx)(`pre`,{dir:`ltr`,className:i(l,`rounded-lg`,t),children:(0,C.jsx)(`code`,{children:e})})}var E=m.memo(({content:e,className:t,allowHtml:n=!1})=>{let r=a(e=>e.theme.mode!==`light`),l=m.useMemo(()=>u(e),[e]),{math:h,html:g}=S({needsMath:x(l),needsHtml:n}),_=m.useMemo(()=>h?[f,h.remarkMath]:[f],[h]),v=m.useMemo(()=>{let e=[];return g&&e.push(g.rehypeRaw,[g.rehypeSanitize,g.richContentSanitizeSchema]),h&&e.push([h.rehypeKatex,{strict:e=>e===`unknownSymbol`?`ignore`:`warn`}]),e},[g,h]);return(0,C.jsx)(`div`,{dir:`auto`,className:i(`prose prose-sm max-w-none dark:prose-invert prose-gray`,`[&_.katex-display]:overflow-x-auto [&_.katex-display]:overflow-y-hidden [&_.katex-display]:py-2`,`[&_.katex]:text-inherit`,t),children:(0,C.jsx)(p,{remarkPlugins:_,rehypePlugins:v,components:{code({className:e,children:t,node:n,...a}){let l=/language-([^\s]+)/.exec(e||``),u=String(t),f=u.replace(/\n$/,``),p=l?l[1]:null;return p||u.includes(`
3
- `)?(0,C.jsx)(o,{code:f,language:p,state:`complete`,children:(0,C.jsx)(`div`,{className:`overflow-x-auto`,children:(0,C.jsx)(m.Suspense,{fallback:(0,C.jsx)(T,{className:`!m-0 !rounded-none !border-none`,children:f}),children:(0,C.jsx)(w,{language:p||`text`,isDark:r,codeTheme:`night`,backgroundColor:r?d:c,borderRadius:0,customStyle:s,className:`!m-0 !rounded-none !border-none`,showLineNumbers:!0,children:f})})})}):(0,C.jsx)(`code`,{dir:`ltr`,className:i(`px-1.5 py-0.5 rounded-md bg-gray-100 dark:bg-dark-200 text-gray-800 dark:text-dark-800`,`font-mono text-[0.85em] border border-gray-200 dark:border-dark-300`,e),...a,children:t})},pre({children:e}){return(0,C.jsx)(C.Fragment,{children:e})},p({children:e,...t}){return(0,C.jsx)(`div`,{dir:`auto`,className:`mb-2.5 last:mb-0 leading-relaxed`,...t,children:e})},ul({children:e,...t}){return(0,C.jsx)(`ul`,{dir:`auto`,className:`list-disc list-inside mb-2.5 space-y-1 ps-4`,...t,children:e})},ol({children:e,...t}){return(0,C.jsx)(`ol`,{dir:`auto`,className:`list-decimal list-inside mb-2.5 space-y-1 ps-4`,...t,children:e})},li({children:e,...t}){return(0,C.jsx)(`li`,{dir:`auto`,className:`text-gray-700 dark:text-dark-700 leading-relaxed`,...t,children:e})},blockquote({children:e,...t}){return(0,C.jsx)(`blockquote`,{dir:`auto`,className:`border-s-2 border-primary-400 dark:border-primary-500 bg-primary-25 dark:bg-primary-950/30 ps-3 py-2 my-3 rounded-e-lg italic text-gray-700 dark:text-dark-700`,...t,children:e})},h1({children:e,...t}){return(0,C.jsx)(`h1`,{dir:`auto`,className:`text-xl font-bold mb-3 mt-5 first:mt-0 text-gray-900 dark:text-dark-800 border-b border-gray-200 dark:border-dark-300 pb-1.5`,...t,children:e})},h2({children:e,...t}){return(0,C.jsx)(`h2`,{dir:`auto`,className:`text-lg font-semibold mb-2 mt-5 first:mt-0 text-gray-900 dark:text-dark-800`,...t,children:e})},h3({children:e,...t}){return(0,C.jsx)(`h3`,{dir:`auto`,className:`text-base font-medium mb-2 mt-4 first:mt-0 text-gray-900 dark:text-dark-800`,...t,children:e})},table({children:e,node:t,...n}){return(0,C.jsx)(`div`,{className:i(`my-4 w-full overflow-x-auto rounded-xl border border-line bg-surface shadow-subtle`,`focus:outline-none focus-visible:ring-2 focus-visible:ring-primary-500/40`),tabIndex:0,children:(0,C.jsx)(`table`,{dir:`auto`,className:`w-full min-w-[42rem] border-separate border-spacing-0 text-start text-sm`,...n,children:e})})},thead({children:e,node:t,...n}){return(0,C.jsx)(`thead`,{className:`bg-surface-subtle`,...n,children:e})},tbody({children:e,node:t,...n}){return(0,C.jsx)(`tbody`,{...n,children:e})},tr({children:e,node:t,...n}){return(0,C.jsx)(`tr`,{className:`transition-colors hover:bg-black/[0.025] last:[&>td]:border-b-0 dark:hover:bg-white/[0.025]`,...n,children:e})},th({align:e,children:t,node:n,...r}){return(0,C.jsx)(`th`,{className:i(`border-b border-e border-line-strong px-3 py-2.5 align-bottom font-semibold text-ink last:border-e-0`,e===`center`?`text-center`:e===`right`?`text-right`:e===`left`?`text-left`:`text-start`),...r,children:t})},td({align:e,children:t,node:n,...r}){return(0,C.jsx)(`td`,{className:i(`min-w-40 border-b border-e border-line px-3 py-2.5 align-top leading-relaxed text-ink last:border-e-0`,e===`center`?`text-center`:e===`right`?`text-right`:e===`left`?`text-left`:`text-start`),...r,children:t})}},children:l})})});E.displayName=`RichMessageContent`;export{E as t};
2
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{o as r}from"./logger-DnuT4jgB.js";import{t as i}from"./utils-CKWltgs8.js";import{t as a}from"./appStore-Bsxed1km.js";import{a as o,i as s,n as c,r as l,s as u,t as d}from"./messageCodeStyles-DchDafYE.js";import{i as f,s as p}from"./markdown-core-D067gSd8.js";var m=e(t(),1),h=null,g=null,_=null,v=null,y=()=>_??=r(()=>import(`./markdownMath-CoDj1i7z.js`).then(e=>(h=e,e)),__vite__mapDeps([0,1,2,3,4,5])),b=()=>v??=r(()=>import(`./markdownHtml-Djpz4yB3.js`).then(e=>(g=e,e)),__vite__mapDeps([6,7,2,3,4])),x=e=>e.includes(`$`);function S(e){let{needsMath:t,needsHtml:n}=e,[,r]=m.useReducer(e=>e+1,0);return m.useEffect(()=>{if(!t||h)return;let e=!1;return y().then(()=>{e||r()}),()=>{e=!0}},[t]),m.useEffect(()=>{if(!n||g)return;let e=!1;return b().then(()=>{e||r()}),()=>{e=!0}},[n]),{math:t?h:null,html:n?g:null}}var C=n(),w=m.lazy(()=>r(()=>import(`./OptimizedSyntaxHighlighter-SkJc7ZMe.js`),__vite__mapDeps([8,9,3,4,10,2])));function T({children:e,className:t}){return(0,C.jsx)(`pre`,{dir:`ltr`,className:i(l,`rounded-lg`,t),children:(0,C.jsx)(`code`,{children:e})})}var E=m.memo(({content:e,className:t,allowHtml:n=!1})=>{let r=a(e=>e.theme.mode!==`light`),l=m.useMemo(()=>u(e),[e]),{math:h,html:g}=S({needsMath:x(l),needsHtml:n}),_=m.useMemo(()=>h?[f,h.remarkMath]:[f],[h]),v=m.useMemo(()=>{let e=[];return g&&e.push(g.rehypeRaw,[g.rehypeSanitize,g.richContentSanitizeSchema]),h&&e.push([h.rehypeKatex,{strict:e=>e===`unknownSymbol`?`ignore`:`warn`}]),e},[g,h]);return(0,C.jsx)(`div`,{dir:`auto`,className:i(`prose prose-sm max-w-none dark:prose-invert prose-gray`,`[&_.katex-display]:overflow-x-auto [&_.katex-display]:overflow-y-hidden [&_.katex-display]:py-2`,`[&_.katex]:text-inherit`,t),children:(0,C.jsx)(p,{remarkPlugins:_,rehypePlugins:v,components:{code({className:e,children:t,node:n,...a}){let l=/language-([^\s]+)/.exec(e||``),u=String(t),f=u.replace(/\n$/,``),p=l?l[1]:null;return p||u.includes(`
3
+ `)?(0,C.jsx)(o,{code:f,language:p,state:`complete`,children:(0,C.jsx)(`div`,{className:`overflow-x-auto`,children:(0,C.jsx)(m.Suspense,{fallback:(0,C.jsx)(T,{className:`!m-0 !rounded-none !border-none`,children:f}),children:(0,C.jsx)(w,{language:p||`text`,isDark:r,codeTheme:`night`,backgroundColor:r?d:c,borderRadius:0,customStyle:s,className:`!m-0 !rounded-none !border-none`,showLineNumbers:!0,children:f})})})}):(0,C.jsx)(`code`,{dir:`ltr`,className:i(`px-1.5 py-0.5 rounded-md bg-gray-100 dark:bg-dark-200 text-gray-800 dark:text-dark-800`,`font-mono text-[0.85em] border border-gray-200 dark:border-dark-300`,e),...a,children:t})},pre({children:e}){return(0,C.jsx)(C.Fragment,{children:e})},p({children:e,...t}){return(0,C.jsx)(`div`,{dir:`auto`,className:`mb-2.5 last:mb-0 leading-relaxed`,...t,children:e})},ul({children:e,...t}){return(0,C.jsx)(`ul`,{dir:`auto`,className:`list-disc list-inside mb-2.5 space-y-1 ps-4`,...t,children:e})},ol({children:e,...t}){return(0,C.jsx)(`ol`,{dir:`auto`,className:`list-decimal list-inside mb-2.5 space-y-1 ps-4`,...t,children:e})},li({children:e,...t}){return(0,C.jsx)(`li`,{dir:`auto`,className:`text-ink leading-relaxed`,...t,children:e})},blockquote({children:e,...t}){return(0,C.jsx)(`blockquote`,{dir:`auto`,className:`border-s-2 border-primary-400 dark:border-primary-500 bg-primary-25 dark:bg-primary-950/30 ps-3 py-2 my-3 rounded-e-lg italic text-ink`,...t,children:e})},h1({children:e,...t}){return(0,C.jsx)(`h1`,{dir:`auto`,className:`text-xl font-bold mb-3 mt-5 first:mt-0 text-ink border-b border-gray-200 dark:border-dark-300 pb-1.5`,...t,children:e})},h2({children:e,...t}){return(0,C.jsx)(`h2`,{dir:`auto`,className:`text-lg font-semibold mb-2 mt-5 first:mt-0 text-ink`,...t,children:e})},h3({children:e,...t}){return(0,C.jsx)(`h3`,{dir:`auto`,className:`text-base font-medium mb-2 mt-4 first:mt-0 text-ink`,...t,children:e})},table({children:e,node:t,...n}){return(0,C.jsx)(`div`,{className:i(`my-4 w-full overflow-x-auto rounded-xl border border-line bg-surface shadow-subtle`,`focus:outline-none focus-visible:ring-2 focus-visible:ring-primary-500/40`),tabIndex:0,children:(0,C.jsx)(`table`,{dir:`auto`,className:`w-full min-w-[42rem] border-separate border-spacing-0 text-start text-sm`,...n,children:e})})},thead({children:e,node:t,...n}){return(0,C.jsx)(`thead`,{className:`bg-surface-subtle`,...n,children:e})},tbody({children:e,node:t,...n}){return(0,C.jsx)(`tbody`,{...n,children:e})},tr({children:e,node:t,...n}){return(0,C.jsx)(`tr`,{className:`transition-colors hover:bg-black/[0.025] last:[&>td]:border-b-0 dark:hover:bg-white/[0.025]`,...n,children:e})},th({align:e,children:t,node:n,...r}){return(0,C.jsx)(`th`,{className:i(`border-b border-e border-line-strong px-3 py-2.5 align-bottom font-semibold text-ink last:border-e-0`,e===`center`?`text-center`:e===`right`?`text-right`:e===`left`?`text-left`:`text-start`),...r,children:t})},td({align:e,children:t,node:n,...r}){return(0,C.jsx)(`td`,{className:i(`min-w-40 border-b border-e border-line px-3 py-2.5 align-top leading-relaxed text-ink last:border-e-0`,e===`center`?`text-center`:e===`right`?`text-right`:e===`left`?`text-left`:`text-start`),...r,children:t})}},children:l})})});E.displayName=`RichMessageContent`;export{E as t};