libre-webui 0.44.1 → 0.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/backend/dist/index.d.ts.map +1 -1
- package/backend/dist/index.js +2 -0
- package/backend/dist/index.js.map +1 -1
- package/backend/dist/routes/chat.d.ts.map +1 -1
- package/backend/dist/routes/chat.js +10 -2
- package/backend/dist/routes/chat.js.map +1 -1
- package/backend/dist/routes/decisions.d.ts +3 -0
- package/backend/dist/routes/decisions.d.ts.map +1 -0
- package/backend/dist/routes/decisions.js +148 -0
- package/backend/dist/routes/decisions.js.map +1 -0
- package/backend/dist/services/apiTokenService.d.ts.map +1 -1
- package/backend/dist/services/apiTokenService.js +2 -0
- package/backend/dist/services/apiTokenService.js.map +1 -1
- package/backend/dist/services/authorizationService.d.ts +1 -1
- package/backend/dist/services/authorizationService.d.ts.map +1 -1
- package/backend/dist/services/authorizationService.js +8 -1
- package/backend/dist/services/authorizationService.js.map +1 -1
- package/backend/dist/services/chatGenerationService.d.ts +24 -2
- package/backend/dist/services/chatGenerationService.d.ts.map +1 -1
- package/backend/dist/services/chatGenerationService.js +72 -4
- package/backend/dist/services/chatGenerationService.js.map +1 -1
- package/backend/dist/services/chatRequestService.d.ts +11 -3
- package/backend/dist/services/chatRequestService.d.ts.map +1 -1
- package/backend/dist/services/chatRequestService.js +19 -3
- package/backend/dist/services/chatRequestService.js.map +1 -1
- package/backend/dist/services/contextCompactionService.d.ts.map +1 -1
- package/backend/dist/services/contextCompactionService.js +8 -0
- package/backend/dist/services/contextCompactionService.js.map +1 -1
- package/backend/dist/services/decisionAccessService.d.ts +16 -0
- package/backend/dist/services/decisionAccessService.d.ts.map +1 -0
- package/backend/dist/services/decisionAccessService.js +71 -0
- package/backend/dist/services/decisionAccessService.js.map +1 -0
- package/backend/dist/services/decisionService.d.ts +128 -0
- package/backend/dist/services/decisionService.d.ts.map +1 -0
- package/backend/dist/services/decisionService.js +515 -0
- package/backend/dist/services/decisionService.js.map +1 -0
- package/backend/dist/services/durableChatGenerationService.d.ts.map +1 -1
- package/backend/dist/services/durableChatGenerationService.js +13 -2
- package/backend/dist/services/durableChatGenerationService.js.map +1 -1
- package/backend/dist/services/ollamaService.d.ts +6 -0
- package/backend/dist/services/ollamaService.d.ts.map +1 -1
- package/backend/dist/services/ollamaService.js +13 -0
- package/backend/dist/services/ollamaService.js.map +1 -1
- package/backend/dist/types/index.d.ts +38 -1
- package/backend/dist/types/index.d.ts.map +1 -1
- package/backend/dist/types/index.js.map +1 -1
- package/backend/dist/utils/decisionProtocol.d.ts +164 -0
- package/backend/dist/utils/decisionProtocol.d.ts.map +1 -0
- package/backend/dist/utils/decisionProtocol.js +755 -0
- package/backend/dist/utils/decisionProtocol.js.map +1 -0
- package/backend/dist/utils/ollamaLibrary.d.ts.map +1 -1
- package/backend/dist/utils/ollamaLibrary.js +26 -7
- package/backend/dist/utils/ollamaLibrary.js.map +1 -1
- package/backend/dist/utils/pluginDefinitionTrust.d.ts.map +1 -1
- package/backend/dist/utils/pluginDefinitionTrust.js +51 -7
- package/backend/dist/utils/pluginDefinitionTrust.js.map +1 -1
- package/backend/dist/utils/pluginModelCatalog.d.ts +4 -2
- package/backend/dist/utils/pluginModelCatalog.d.ts.map +1 -1
- package/backend/dist/utils/pluginModelCatalog.js +12 -2
- package/backend/dist/utils/pluginModelCatalog.js.map +1 -1
- package/backend/dist/websocketServer.d.ts.map +1 -1
- package/backend/dist/websocketServer.js +23 -6
- package/backend/dist/websocketServer.js.map +1 -1
- package/backend/package.json +2 -2
- package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
- package/frontend/dist/artifact-runtime/babel.js +172 -172
- package/frontend/dist/artifact-runtime/framer-motion.js +2 -2
- package/frontend/dist/artifact-runtime/lucide-react.js +1 -1
- package/frontend/dist/artifact-runtime/papaparse.js +2 -2
- package/frontend/dist/artifact-runtime/plotly.js +5 -5
- package/frontend/dist/artifact-runtime/tailwind.js +16 -16
- package/frontend/dist/assets/index-C2A5Ko4-.js +59 -0
- package/frontend/dist/assets/index-FrFgrp5E.css +2 -0
- package/frontend/dist/index.html +28 -28
- package/frontend/dist/js/{ArtifactContainer-C2PgJwen.js → ArtifactContainer-DCCcjK16.js} +1 -1
- package/frontend/dist/js/{ArtifactDemoPage-Dcy-lVrh.js → ArtifactDemoPage-C-1acgxJ.js} +1 -1
- package/frontend/dist/js/{ArtifactSandboxFrame-C7gLjHfY.js → ArtifactSandboxFrame-BXWNhmtI.js} +1 -1
- package/frontend/dist/js/{ArtifactSlideOutPanel-BKZQ7VwV.js → ArtifactSlideOutPanel-CvfdP_o2.js} +1 -1
- package/frontend/dist/js/{AutomationModal-zImHyodn.js → AutomationModal-D7qiRMhj.js} +1 -1
- package/frontend/dist/js/{AutomationsPage-BuJ1Y810.js → AutomationsPage-v98Ucl9p.js} +1 -1
- package/frontend/dist/js/{AvatarUpload-BECcVNWc.js → AvatarUpload-W41SCHKE.js} +1 -1
- package/frontend/dist/js/{Button-BGE6ZJv5.js → Button-D6d7HYoa.js} +1 -1
- package/frontend/dist/js/{CalendarPage-hF8Gk80e.js → CalendarPage-DkAa61Pa.js} +1 -1
- package/frontend/dist/js/ChannelsPage-0Vnfpgdr.js +1 -0
- package/frontend/dist/js/ChatPage-iyMY-uoE.js +14 -0
- package/frontend/dist/js/{ConnectModels-DVd2RDUM.js → ConnectModels-CpWO6ALS.js} +1 -1
- package/frontend/dist/js/{EvaluationsPage-D_R88N9b.js → EvaluationsPage-C7WHA1MJ.js} +1 -1
- package/frontend/dist/js/{FirstTimeSetup-CQQUhpPj.js → FirstTimeSetup-B8wcelBc.js} +1 -1
- package/frontend/dist/js/{GalleryPage-BYyAx84l.js → GalleryPage-u7dYKl3q.js} +1 -1
- package/frontend/dist/js/{HomePage-BRjiDJZa.js → HomePage-Cjlt3b9n.js} +1 -1
- package/frontend/dist/js/{LanguageSwitcher-0vFsK1v-.js → LanguageSwitcher-gbTZY15P.js} +1 -1
- package/frontend/dist/js/{Logo-GlNrhpKp.js → Logo-DhV6D_3q.js} +1 -1
- package/frontend/dist/js/{LogoMark-rgOHhWo-.js → LogoMark-CmF1lHXT.js} +1 -1
- package/frontend/dist/js/{ModelManagerModals-BK0iqnHd.js → ModelManagerModals-12hL-b-U.js} +1 -1
- package/frontend/dist/js/{NotesPage-DD6EntAT.js → NotesPage-BQWBA5li.js} +2 -2
- package/frontend/dist/js/{PasswordStrengthMeter-DrXjBWiT.js → PasswordStrengthMeter-DdqX0FXA.js} +1 -1
- package/frontend/dist/js/PersonasPage-B8mFdWcX.js +13 -0
- package/frontend/dist/js/{PluginUsagePage-BBfqotzy.js → PluginUsagePage-Uz6aHPIp.js} +1 -1
- package/frontend/dist/js/{RichMessageContent-BcBbr-Q2.js → RichMessageContent-CVk-fp0N.js} +1 -1
- package/frontend/dist/js/{RichMessageContent-Cdz4MI7q.js → RichMessageContent-DwMoWuR_.js} +1 -1
- package/frontend/dist/js/SettingsModal-CfjxNSmJ.js +19 -0
- package/frontend/dist/js/{SettingsToggle-BT6cbOnw.js → SettingsToggle-CNUeo6DO.js} +1 -1
- package/frontend/dist/js/{ShareDialog-CTZp6YtI.js → ShareDialog-NwirTDLR.js} +1 -1
- package/frontend/dist/js/{StrandsPage-BYY6YV5N.js → StrandsPage-ddHNdb6J.js} +1 -1
- package/frontend/dist/js/{SystemPage-DaDG0V07.js → SystemPage-C_1exwI7.js} +1 -1
- package/frontend/dist/js/UserManagementPanel-hg7ztEtL.js +1 -0
- package/frontend/dist/js/{WhatsNewModal-DgMfeACt.js → WhatsNewModal-yYk7N4KY.js} +1 -1
- package/frontend/dist/js/WorkPage-i7yYRAuj.js +7 -0
- package/frontend/dist/js/api-BU13N8gU.js +1 -0
- package/frontend/dist/js/{api-Bje32kcr.js → api-Dasm8tVY.js} +1 -1
- package/frontend/dist/js/{appNavigation-6Vs8h0Iv.js → appNavigation-DqP7fTWU.js} +1 -1
- package/frontend/dist/js/{appStore-DmeFFzzj.js → appStore-DCIUnT8X.js} +2 -2
- package/frontend/dist/js/appVersion-PJGaVilS.js +1 -0
- package/frontend/dist/js/ar-CsCftCVF.js +2 -0
- package/frontend/dist/js/authStore-Bp17zKvS.js +1 -0
- package/frontend/dist/js/{authStore-DUmjkugT.js → authStore-ac5-hjOH.js} +3 -3
- package/frontend/dist/js/babel-C4LPTjCL.js +16 -0
- package/frontend/dist/js/bn-CvxUTZ9a.js +2 -0
- package/frontend/dist/js/chatStore-GhucyjJu.js +3 -0
- package/frontend/dist/js/{client-DIxMEDnJ.js → client-DxPoTB_C.js} +2 -2
- package/frontend/dist/js/{config-HBTc75oS.js → config-CQJEcQtz.js} +1 -1
- package/frontend/dist/js/cs-BovmMwcD.js +2 -0
- package/frontend/dist/js/da-Dof1gmsv.js +2 -0
- package/frontend/dist/js/de-CF9CXojW.js +2 -0
- package/frontend/dist/js/decisionsApi-BWB64EGn.js +1 -0
- package/frontend/dist/js/decisionsApi-CoJtg4PZ.js +1 -0
- package/frontend/dist/js/es-BXCt50HZ.js +2 -0
- package/frontend/dist/js/estree-DCoUd_wj.js +44 -0
- package/frontend/dist/js/{evaluationsApi-CJ9eIoSl.js → evaluationsApi-CBqKkjmI.js} +1 -1
- package/frontend/dist/js/fr-B5QcCDIw.js +2 -0
- package/frontend/dist/js/hi-BXYwSyKl.js +2 -0
- package/frontend/dist/js/html-DMnBrAcs.js +25 -0
- package/frontend/dist/js/id-BV3mY5L7.js +2 -0
- package/frontend/dist/js/is-BDK4LrQC.js +2 -0
- package/frontend/dist/js/it-DAeWl1Fm.js +2 -0
- package/frontend/dist/js/ja-DIJV01rA.js +2 -0
- package/frontend/dist/js/ko-Btr9-64X.js +2 -0
- package/frontend/dist/js/markdown-CQ4enQcD.js +70 -0
- package/frontend/dist/js/{messageCodeStyles-C0H1Lad5.js → messageCodeStyles-BugWE4s5.js} +2 -2
- package/frontend/dist/js/ms-DgVmv5zF.js +2 -0
- package/frontend/dist/js/nl-Dz5HpdLi.js +2 -0
- package/frontend/dist/js/pl-CIATY2b0.js +2 -0
- package/frontend/dist/js/postcss-CZstCllf.js +62 -0
- package/frontend/dist/js/pt-lrDXX76Y.js +2 -0
- package/frontend/dist/js/ru-_zovUYcg.js +2 -0
- package/frontend/dist/js/standalone-CttwqOis.js +29 -0
- package/frontend/dist/js/{strandsApi-Cuqp8JZv.js → strandsApi-Ck7FrcHH.js} +1 -1
- package/frontend/dist/js/sv-TkRDWCb8.js +2 -0
- package/frontend/dist/js/{teamEventStream-DHeJw2eu.js → teamEventStream-O3qGbUZz.js} +1 -1
- package/frontend/dist/js/th-CQyavDiP.js +2 -0
- package/frontend/dist/js/tr-CBcFl4_Z.js +2 -0
- package/frontend/dist/js/typescript-h2bi7nrV.js +22 -0
- package/frontend/dist/js/{ui-BPtWIxXL.js → ui-DxaHE9GD.js} +2 -2
- package/frontend/dist/js/{ui-vendor-Bac5e8jE.js → ui-vendor-DsURZnZt.js} +1 -1
- package/frontend/dist/js/uk-BNn1cUt8.js +2 -0
- package/frontend/dist/js/{useChat-DjRbGblw.js → useChat-1HyAPpCk.js} +1 -1
- package/frontend/dist/js/useDictation-B3vNgs5D.js +1 -0
- package/frontend/dist/js/{useQuery-DCqz3UJt.js → useQuery-Cs76KYuP.js} +1 -1
- package/frontend/dist/js/useTranslation-CKqEdZ8j.js +1 -0
- package/frontend/dist/js/utils-BXRzbHJC.js +1 -0
- package/frontend/dist/js/{utils-vendor-CsC5rH1J.js → utils-vendor-B4bGLP5p.js} +1 -1
- package/frontend/dist/js/vi-Be8GO7e_.js +2 -0
- package/frontend/dist/js/{workApi-Dkf48LjA.js → workApi-BNGRSv7q.js} +1 -1
- package/frontend/dist/js/workApi-C5jw1ra6.js +1 -0
- package/frontend/dist/js/yaml-CBt8G4BX.js +150 -0
- package/frontend/dist/js/zh-9CUKyYw5.js +2 -0
- package/package.json +4 -4
- package/plugins/baseten.json +17 -0
- package/plugins/gemini.json +9 -0
- package/plugins/llama-cpp.json +13 -0
- package/plugins/openai.json +13 -0
- package/plugins/openrouter.json +26 -0
- package/frontend/dist/assets/index-BM0txgxR.css +0 -2
- package/frontend/dist/assets/index-CYJjXpq5.js +0 -34
- package/frontend/dist/js/ChannelsPage-Bb7qgmXS.js +0 -1
- package/frontend/dist/js/ChatPage-BkMm-S6C.js +0 -14
- package/frontend/dist/js/PersonasPage-CkGtixCB.js +0 -13
- package/frontend/dist/js/SettingsModal-CKtlOet9.js +0 -19
- package/frontend/dist/js/UserManagementPanel-B7SuWPQg.js +0 -1
- package/frontend/dist/js/WorkPage-CVcyA61Q.js +0 -7
- package/frontend/dist/js/api-BSMl2Tok.js +0 -1
- package/frontend/dist/js/appVersion-DWwbhdm2.js +0 -1
- package/frontend/dist/js/ar-yKmq_nxn.js +0 -2
- package/frontend/dist/js/authStore-DQ-PhUey.js +0 -1
- package/frontend/dist/js/babel-BaOs8qJH.js +0 -16
- package/frontend/dist/js/bn-DAJjz2xA.js +0 -2
- package/frontend/dist/js/chatStore-Di86sm3T.js +0 -3
- package/frontend/dist/js/cs-BcctV9SN.js +0 -2
- package/frontend/dist/js/da-YtnjzG18.js +0 -2
- package/frontend/dist/js/de-BMQofu0d.js +0 -2
- package/frontend/dist/js/es-8oFYsnHw.js +0 -2
- package/frontend/dist/js/estree-Cw-tQG5d.js +0 -44
- package/frontend/dist/js/fr-CnGTnuJK.js +0 -2
- package/frontend/dist/js/hi-Ct5Inbp9.js +0 -2
- package/frontend/dist/js/html-Drt7kOJE.js +0 -25
- package/frontend/dist/js/id-CSqCL3hQ.js +0 -2
- package/frontend/dist/js/is-Bg68TmSt.js +0 -2
- package/frontend/dist/js/it-ZngXlxOR.js +0 -2
- package/frontend/dist/js/ja-DfQEoeFi.js +0 -2
- package/frontend/dist/js/ko-IifYVGBy.js +0 -2
- package/frontend/dist/js/markdown-C7cnJl_Q.js +0 -70
- package/frontend/dist/js/ms-C8jQLzkg.js +0 -2
- package/frontend/dist/js/nl-BFEa3rgC.js +0 -2
- package/frontend/dist/js/pl-BiPrQGU-.js +0 -2
- package/frontend/dist/js/postcss-DB_e0nkW.js +0 -62
- package/frontend/dist/js/pt-BziWZm5q.js +0 -2
- package/frontend/dist/js/ru-oTAEePGS.js +0 -2
- package/frontend/dist/js/standalone-YobQElH8.js +0 -29
- package/frontend/dist/js/sv-1_et6OWH.js +0 -2
- package/frontend/dist/js/th-DjyLzIKs.js +0 -2
- package/frontend/dist/js/tr-CCga9CbK.js +0 -2
- package/frontend/dist/js/typescript-2anSzo_N.js +0 -22
- package/frontend/dist/js/uk-h80KE68A.js +0 -2
- package/frontend/dist/js/useDictation-C31FhomS.js +0 -1
- package/frontend/dist/js/useTranslation-D-_KTORQ.js +0 -1
- package/frontend/dist/js/utils-DsCVr_wG.js +0 -1
- package/frontend/dist/js/vi-CQxzmgwi.js +0 -2
- package/frontend/dist/js/workApi-D4JbAtE2.js +0 -1
- package/frontend/dist/js/yaml-Breo7DWT.js +0 -154
- package/frontend/dist/js/zh-CS3_ndbP.js +0 -2
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{i as r}from"./router-vendor-DLHZHk4K.js";import{t as i}from"./useTranslation-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{i as r}from"./router-vendor-DLHZHk4K.js";import{t as i}from"./useTranslation-CKqEdZ8j.js";import{An as a,B as o,En as s,K as ee,M as c,N as te,Or as l,Rt as u,X as d,at as f,ht as p,m,n as h,s as ne,st as g,tt as re,ut as _,v as ie,yr as v}from"./ui-vendor-DsURZnZt.js";import{t as y}from"./RichMessageContent-DwMoWuR_.js";import{i as b,n as ae,r as x,t as oe}from"./ui-DxaHE9GD.js";import{A as S,k as C}from"./api-Dasm8tVY.js";import{t as w}from"./Button-D6d7HYoa.js";import{i as se,t as T}from"./utils-BXRzbHJC.js";import{t as E}from"./logger-DAQsBb8I.js";import{t as D}from"./confirmStore-CKkUtP9c.js";import{t as O}from"./chatStore-GhucyjJu.js";var k=e(t(),1),A=4e3,j=(e,t)=>{let n=e.split(`
|
|
2
2
|
`),r=t.split(`
|
|
3
|
-
`);if(n.length>A||r.length>A)return[...n.map(e=>({type:`removed`,text:e})),...r.map(e=>({type:`added`,text:e}))];let i=Array.from({length:n.length+1},()=>Array(r.length+1).fill(0));for(let e=n.length-1;e>=0;--e)for(let t=r.length-1;t>=0;--t)i[e][t]=n[e]===r[t]?i[e+1][t+1]+1:Math.max(i[e+1][t],i[e][t+1]);let a=[],o=0,s=0;for(;o<n.length&&s<r.length;)n[o]===r[s]?(a.push({type:`context`,text:n[o]}),o+=1,s+=1):i[o+1][s]>=i[o][s+1]?(a.push({type:`removed`,text:n[o]}),o+=1):(a.push({type:`added`,text:r[s]}),s+=1);for(;o<n.length;)a.push({type:`removed`,text:n[o]}),o+=1;for(;s<r.length;)a.push({type:`added`,text:r[s]}),s+=1;return a},M=e=>e.some(e=>e.type!==`context`),N=n(),P=E(`components:note-tools`),F=({rows:e})=>(0,N.jsx)(`div`,{className:`max-h-64 overflow-auto rounded-lg border border-black/6 font-mono text-[12px] leading-relaxed dark:border-white/8`,"data-testid":`note-diff-view`,children:e.map((e,t)=>(0,N.jsx)(`div`,{className:T(`whitespace-pre-wrap px-2`,e.type===`added`&&`bg-[rgb(76,212,117)]/12 text-green-800 dark:text-green-300`,e.type===`removed`&&`bg-[rgb(255,61,129)]/10 text-red-800 line-through dark:text-red-300`,e.type===`context`&&`text-gray-600 dark:text-dark-700`),children:e.text||`\xA0`},t))}),ce=({note:e,currentContent:t,currentTitle:n,canWrite:r,isOwner:s,initialTab:ee,onClose:te,onApplyContent:f})=>{let{t:p,i18n:ne}=i(),[g,re]=(0,k.useState)(ee),[v,y]=(0,k.useState)({revisions:!1,attachments:!1,share:!1}),[b,E]=(0,k.useState)(null),[A,ce]=(0,k.useState)(null),[I,le]=(0,k.useState)(null),[L,R]=(0,k.useState)(!1),z=(0,k.useRef)(null),[B,ue]=(0,k.useState)(null),[V,H]=(0,k.useState)(``),[U,de]=(0,k.useState)(`read`),[W,G]=(0,k.useState)(!1),[K,fe]=(0,k.useState)(``),[pe,q]=(0,k.useState)(!1),[J,Y]=(0,k.useState)(null),X=O(e=>e.selectedModel),me=O(e=>e.selectedProviderType),he=O(e=>e.selectedProviderId),ge=(0,k.useCallback)(()=>{S.getRevisions(e.id).then(e=>{if(e.success&&Array.isArray(e.data))E(e.data);else throw Error(e.error)}).catch(e=>{P.error(`Failed to load revisions:`,e),l.error(p(`notes.loadFailed`)),y(e=>({...e,revisions:!0}))})},[e.id,p]),Z=(0,k.useCallback)(()=>{S.getAttachments(e.id).then(e=>{if(e.success&&Array.isArray(e.data))le(e.data);else throw Error(e.error)}).catch(e=>{P.error(`Failed to load attachments:`,e),l.error(p(`notes.loadFailed`)),y(e=>({...e,attachments:!0}))})},[e.id,p]),Q=(0,k.useCallback)(()=>{C.listGrants(`note`,e.id).then(e=>{if(e.success&&Array.isArray(e.data))ue(e.data);else throw Error(e.error)}).catch(e=>{P.error(`Failed to load shares:`,e),l.error(p(`notes.loadFailed`)),y(e=>({...e,share:!0}))})},[e.id,p]),_e=e=>v[e]?(0,N.jsx)(oe,{size:`sm`,message:p(`notes.loadFailed`),onRetry:()=>y(t=>({...t,[e]:!1}))}):(0,N.jsx)(ae,{size:`sm`,srOnly:!0});(0,k.useEffect)(()=>{g===`revisions`&&b===null&&!v.revisions&&ge(),g===`attachments`&&I===null&&!v.attachments&&Z(),g===`share`&&s&&B===null&&!v.share&&Q()},[g,b,I,B,v,s,ge,Z,Q]);let ve=async t=>{if(await D({title:p(`notes.restoreConfirmTitle`),description:p(`notes.restoreConfirmDescription`),confirmLabel:p(`notes.restore`),destructive:!0}))try{let n=await S.restoreRevision(e.id,t);n.success&&n.data?(f(n.data.content,n.data.title),E(null),ce(null),l.success(p(`notes.revisionRestored`))):l.error(n.error||p(`notes.revisionRestoreFailed`))}catch(e){P.error(`Failed to restore revision:`,e),l.error(p(`notes.revisionRestoreFailed`))}},ye=async t=>{if(t&&t.length!==0){R(!0);try{let n=await S.uploadAttachment(e.id,t[0]);n.success?(Z(),l.success(p(`notes.attachmentAdded`))):l.error(n.error||p(`notes.attachmentFailed`))}catch(e){P.error(`Failed to upload attachment:`,e),l.error(p(`notes.attachmentFailed`))}finally{R(!1),z.current&&(z.current.value=``)}}},be=async t=>{try{let n=await S.downloadAttachment(e.id,t.id),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=t.filename,i.click(),URL.revokeObjectURL(r)}catch(e){P.error(`Failed to download attachment:`,e),l.error(p(`notes.attachmentDownloadFailed`))}},xe=async t=>{if(await D({title:p(`notes.deleteAttachmentConfirmTitle`,{name:t.filename}),description:p(`notes.deleteAttachmentConfirmDescription`),destructive:!0}))try{(await S.deleteAttachment(e.id,t.id)).success?Z():l.error(p(`notes.attachmentDeleteFailed`))}catch(e){P.error(`Failed to delete attachment:`,e),l.error(p(`notes.attachmentDeleteFailed`))}},Se=async()=>{let t=V.trim();if(t){G(!0);try{let n=await C.resolvePrincipal(t);if(!n.success||!n.data){l.error(p(`notes.shareUserNotFound`));return}let r=await C.createGrant({resourceType:`note`,resourceId:e.id,principalType:`user`,principalId:n.data.id,permission:U});r.success?(H(``),Q(),l.success(p(`notes.shareAdded`,{username:t}))):l.error(r.error||p(`notes.shareFailed`))}catch(e){P.error(`Failed to share note:`,e),l.error(p(`notes.shareFailed`))}finally{G(!1)}}},Ce=async e=>{try{(await C.deleteGrant(e)).success?Q():l.error(p(`notes.revokeFailed`))}catch(e){P.error(`Failed to revoke share:`,e),l.error(p(`notes.revokeFailed`))}},we=async()=>{if(K.trim()&&X){q(!0),Y(null);try{let t=await S.assist(e.id,{instruction:K,model:X,providerType:me,providerId:he});t.success&&t.data?.content!==void 0?Y(t.data.content):l.error(t.error||p(`notes.assistFailed`))}catch(e){P.error(`Note assist failed:`,e),l.error(p(`notes.assistFailed`))}finally{q(!1)}}},$=(0,k.useMemo)(()=>J===null?null:j(t,J),[J,t]),Te=[{id:`revisions`,icon:(0,N.jsx)(d,{className:`h-3.5 w-3.5`}),label:p(`notes.revisions`)},{id:`attachments`,icon:(0,N.jsx)(_,{className:`h-3.5 w-3.5`}),label:p(`notes.attachments`)},{id:`share`,icon:(0,N.jsx)(o,{className:`h-3.5 w-3.5`}),label:p(`notes.share`),hidden:!s},{id:`assist`,icon:(0,N.jsx)(c,{className:`h-3.5 w-3.5`}),label:p(`notes.assist`),hidden:!r}];return(0,N.jsxs)(`div`,{className:`absolute inset-y-0 inset-e-0 z-30 flex w-full max-w-md flex-col border-s border-black/6 bg-surface shadow-xl dark:border-white/[0.07] dark:bg-dark-100`,"data-testid":`note-tools-drawer`,role:`dialog`,"aria-label":p(`notes.tools`),children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-black/6 px-3 py-2 dark:border-white/[0.07]`,children:[(0,N.jsx)(`div`,{role:`tablist`,className:`flex items-center gap-1`,children:Te.filter(e=>!e.hidden).map(e=>(0,N.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":g===e.id,onClick:()=>re(e.id),"data-testid":`note-tools-tab-${e.id}`,className:T(`flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[12px] transition-colors`,g===e.id?`bg-black/6 text-gray-900 dark:bg-white/8 dark:text-dark-900`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),children:[e.icon,e.label]},e.id))}),(0,N.jsx)(`button`,{type:`button`,onClick:te,className:`ms-auto rounded-md p-1.5 text-gray-400 hover:text-gray-700 dark:text-dark-500 dark:hover:text-dark-800`,"aria-label":p(`common.close`),"data-testid":`note-tools-close`,children:(0,N.jsx)(h,{className:`h-4 w-4`})})]}),(0,N.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-4 scrollbar-thin`,children:[g===`revisions`&&(0,N.jsx)(`div`,{className:`space-y-2`,children:b===null?_e(`revisions`):b.length===0?(0,N.jsx)(x,{icon:d,size:`sm`,title:p(`notes.noRevisions`)}):b.map(e=>(0,N.jsxs)(`div`,{className:`rounded-lg border border-black/6 p-2.5 dark:border-white/8`,"data-testid":`note-revision-item`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>ce(t=>t===e.id?null:e.id),className:`min-w-0 flex-1 truncate text-start text-[13px] text-gray-800 dark:text-dark-800`,children:[se(e.createdAt,ne.language),e.title!==n&&(0,N.jsxs)(`span`,{className:`ms-1 text-gray-400 dark:text-dark-500`,children:[`· `,e.title||p(`notes.untitled`)]})]}),r&&(0,N.jsxs)(w,{size:`sm`,variant:`ghost`,className:`h-7 gap-1 px-2 text-[11px]`,onClick:()=>void ve(e.id),"data-testid":`note-revision-restore`,children:[(0,N.jsx)(m,{className:`h-3 w-3`}),p(`notes.restore`)]})]}),A===e.id&&(0,N.jsx)(`div`,{className:`mt-2`,children:(0,N.jsx)(F,{rows:j(e.content,t)})})]},e.id))}),g===`attachments`&&(0,N.jsxs)(`div`,{className:`space-y-2`,children:[r&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`input`,{ref:z,type:`file`,className:`hidden`,onChange:e=>void ye(e.target.files),"data-testid":`note-attachment-input`}),(0,N.jsxs)(w,{size:`sm`,variant:`outline`,className:`w-full gap-1.5`,disabled:L,onClick:()=>z.current?.click(),"data-testid":`note-attachment-upload`,children:[L?(0,N.jsx)(u,{className:`h-3.5 w-3.5 animate-spin`}):(0,N.jsx)(_,{className:`h-3.5 w-3.5`}),p(`notes.addAttachment`)]})]}),I===null?_e(`attachments`):I.length===0?(0,N.jsx)(x,{icon:_,size:`sm`,title:p(`notes.noAttachments`)}):I.map(e=>(0,N.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-black/6 px-2.5 py-2 dark:border-white/8`,"data-testid":`note-attachment-item`,children:[(0,N.jsx)(_,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,N.jsx)(`span`,{dir:`ltr`,className:`min-w-0 flex-1 truncate text-[13px] text-gray-800 dark:text-dark-800`,children:e.filename}),(0,N.jsxs)(`span`,{className:`shrink-0 text-[11px] text-gray-400 dark:text-dark-500`,children:[Math.max(1,Math.round(e.size/1024)),` KB`]}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>void be(e),className:`rounded-md p-1.5 text-gray-500 hover:text-gray-700 dark:text-dark-500 dark:hover:text-dark-800`,title:p(`common.download`),"aria-label":`${p(`common.download`)}: ${e.filename}`,children:(0,N.jsx)(a,{className:`h-3.5 w-3.5`})}),r&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>void xe(e),className:`rounded-md p-1.5 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,title:p(`common.delete`),"aria-label":`${p(`common.delete`)}: ${e.filename}`,children:(0,N.jsx)(ie,{className:`h-3.5 w-3.5`})})]},e.id))]}),g===`share`&&s&&(0,N.jsxs)(`div`,{className:`space-y-3`,children:[(0,N.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,N.jsx)(`input`,{type:`text`,value:V,onChange:e=>H(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Se()},placeholder:p(`notes.shareUsernamePlaceholder`),"aria-label":p(`notes.shareUsernamePlaceholder`),className:`min-w-0 flex-1 rounded-lg border border-black/8 bg-transparent px-2.5 py-1.5 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"data-testid":`note-share-username`}),(0,N.jsxs)(`select`,{value:U,onChange:e=>de(e.target.value),className:`rounded-lg border border-black/8 bg-transparent px-2 py-1.5 text-[12px] text-gray-700 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:bg-dark-100 dark:text-dark-800`,"aria-label":p(`notes.sharePermissionLabel`),"data-testid":`note-share-permission`,children:[(0,N.jsx)(`option`,{value:`read`,children:p(`notes.permissionRead`)}),(0,N.jsx)(`option`,{value:`write`,children:p(`notes.permissionWrite`)})]}),(0,N.jsx)(w,{size:`sm`,disabled:W||!V.trim(),onClick:()=>void Se(),"data-testid":`note-share-submit`,children:W?(0,N.jsx)(u,{className:`h-3.5 w-3.5 animate-spin`}):p(`notes.shareAction`)})]}),B===null?_e(`share`):B.length===0?(0,N.jsx)(x,{icon:o,size:`sm`,title:p(`notes.notShared`)}):B.map(e=>(0,N.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-black/6 px-2.5 py-2 dark:border-white/8`,"data-testid":`note-share-item`,children:[(0,N.jsx)(o,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] text-gray-800 dark:text-dark-800`,children:e.principalId}),(0,N.jsx)(`span`,{className:`shrink-0 text-[11px] uppercase text-gray-400 dark:text-dark-500`,children:e.permission}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>void Ce(e.id),className:`rounded-md p-1.5 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,title:p(`notes.revokeShare`),"aria-label":p(`notes.revokeShare`),children:(0,N.jsx)(h,{className:`h-3.5 w-3.5`})})]},e.id)),(0,N.jsx)(`p`,{className:`text-[11px] leading-relaxed text-gray-400 dark:text-dark-500`,children:p(`notes.shareHint`)})]}),g===`assist`&&r&&(0,N.jsxs)(`div`,{className:`space-y-3`,children:[(0,N.jsx)(`textarea`,{value:K,onChange:e=>fe(e.target.value),placeholder:p(`notes.assistPlaceholder`),rows:3,className:`w-full resize-none rounded-lg border border-black/8 bg-transparent px-2.5 py-2 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"aria-label":p(`notes.assistPlaceholder`),"data-testid":`note-assist-instruction`}),(0,N.jsxs)(w,{size:`sm`,className:`w-full gap-1.5`,disabled:pe||!K.trim()||!X,onClick:()=>void we(),"data-testid":`note-assist-generate`,children:[pe?(0,N.jsx)(u,{className:`h-3.5 w-3.5 animate-spin`}):(0,N.jsx)(c,{className:`h-3.5 w-3.5`}),p(`notes.assistGenerate`)]}),!X&&(0,N.jsx)(`p`,{className:`text-[11px] text-amber-600 dark:text-amber-400`,children:p(`notes.assistNoModel`)}),J!==null&&$&&(0,N.jsxs)(`div`,{className:`space-y-2`,children:[M($)?(0,N.jsx)(F,{rows:$}):(0,N.jsx)(`p`,{className:`text-center text-xs text-gray-400 dark:text-dark-500`,children:p(`notes.assistNoChanges`)}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(w,{size:`sm`,className:`flex-1`,disabled:!M($),onClick:()=>{f(J),Y(null),fe(``),l.success(p(`notes.assistApplied`))},"data-testid":`note-assist-apply`,children:p(`notes.assistApply`)}),(0,N.jsx)(w,{size:`sm`,variant:`outline`,className:`flex-1`,onClick:()=>Y(null),"data-testid":`note-assist-discard`,children:p(`notes.assistDiscard`)})]}),(0,N.jsx)(`p`,{className:`text-[11px] leading-relaxed text-gray-400 dark:text-dark-500`,children:p(`notes.assistRevisionHint`)})]})]})]})]})},I=E(`pages:notes`),le=800,L=()=>{let{t:e,i18n:t}=i(),[n,o]=(0,k.useState)([]),[c,u]=(0,k.useState)(!0),[d,m]=(0,k.useState)(null),h=(0,k.useRef)(null);(0,k.useEffect)(()=>{h.current=d},[d]);let[_,oe]=(0,k.useState)(``),[C,E]=(0,k.useState)(``),[D,O]=(0,k.useState)(``),[A,j]=(0,k.useState)(!0),[M,P]=(0,k.useState)(`idle`),[F,L]=(0,k.useState)(null),R=(0,k.useRef)(null),z=(0,k.useRef)(null),[B,ue]=r(),V=(0,k.useMemo)(()=>n.find(e=>e.id===d)??null,[n,d]);(0,k.useEffect)(()=>{let e=!1;return S.getNotes().then(t=>{e||t.success&&t.data&&o(t.data)}).catch(e=>I.error(`Failed to load notes:`,e)).finally(()=>{e||u(!1)}),()=>{e=!0}},[]);let H=B.get(`note`),U=H?n.find(e=>e.id===H):void 0;U&&d!==U.id&&(m(U.id),E(U.title),O(U.content),j(!0),P(`idle`));let de=H!==null&&(U!==void 0||!c);(0,k.useEffect)(()=>{de&&ue({},{replace:!0})},[de,ue]);let W=!V||!V.shared,G=V?!V.shared||V.shared.permission===`write`:!1,K=(e,t=`preview`)=>{Y(),h.current=e.id,m(e.id),E(e.title),O(e.content),j(t===`preview`),P(`idle`),L(null)},fe=async()=>{if(V)try{let t=await S.updateNote(V.id,{pinned:!V.pinned});if(t.success&&t.data){let e=t.data;o(t=>t.map(t=>t.id===e.id?e:t))}else l.error(e(`notes.saveFailed`))}catch(t){I.error(`Failed to toggle pin:`,t),l.error(e(`notes.saveFailed`))}},pe=()=>{if(!V)return;let e=new Blob([D],{type:`text/markdown;charset=utf-8`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`${(C||`note`).replace(/[\\/:*?"<>|]/g,`-`)}.md`,n.click(),URL.revokeObjectURL(t)},q=(e,t,n)=>{R.current!==null&&window.clearTimeout(R.current),P(`saving`),R.current=window.setTimeout(()=>{R.current=null,J(e,t,n)},le)},J=async(t,n,r)=>{try{let i=await S.updateNote(t,{title:n,content:r});if(i.success&&i.data){let e=i.data;o(n=>[e,...n.filter(e=>e.id!==t)].sort((e,t)=>t.updatedAt-e.updatedAt)),h.current===t&&P(`saved`)}else l.error(e(`notes.saveFailed`)),h.current===t&&P(`error`)}catch(n){I.error(`Failed to save note:`,n),l.error(e(`notes.saveFailed`)),h.current===t&&P(`error`)}},Y=()=>{R.current!==null&&d&&(window.clearTimeout(R.current),R.current=null,J(d,C,D))};(0,k.useEffect)(()=>()=>{R.current!==null&&window.clearTimeout(R.current)},[]);let X=async()=>{try{let e=await S.createNote(``,``);if(e.success&&e.data){let t=e.data;o(e=>[t,...e]),K(t,`edit`)}}catch(t){I.error(`Failed to create note:`,t),l.error(e(`notes.createFailed`))}},me=async t=>{if(window.confirm(e(`notes.deleteConfirm`)))try{(await S.deleteNote(t)).success?(o(e=>e.filter(e=>e.id!==t)),d===t&&m(null)):l.error(e(`notes.deleteFailed`))}catch(t){I.error(`Failed to delete note:`,t),l.error(e(`notes.deleteFailed`))}},he=(0,k.useMemo)(()=>{let e=_.trim().toLowerCase();return e?n.filter(t=>t.title.toLowerCase().includes(e)||t.content.toLowerCase().includes(e)):n},[n,_]);return(0,N.jsxs)(`div`,{className:`relative flex h-full min-h-0 overflow-hidden`,"data-testid":`notes-page`,children:[(0,N.jsxs)(`div`,{"data-testid":`notes-list`,className:T(`min-h-0 w-full shrink-0 flex-col border-e border-black/6 dark:border-white/[0.07] md:w-72`,V?`hidden md:flex`:`flex`),children:[(0,N.jsx)(b,{title:e(`notes.title`),actions:(0,N.jsx)(w,{size:`sm`,variant:`ghost`,onClick:()=>void X(),className:`h-7 w-7 p-0`,title:e(`notes.new`),"aria-label":e(`notes.new`),children:(0,N.jsx)(ne,{className:`h-4 w-4`})})}),(0,N.jsxs)(`div`,{className:`relative mx-3 mb-2 mt-3`,children:[(0,N.jsx)(s,{className:`pointer-events-none absolute inset-s-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-gray-400 dark:text-dark-500`}),(0,N.jsx)(`input`,{ref:z,type:`search`,value:_,onChange:e=>oe(e.target.value),placeholder:e(`common.search`),"aria-label":e(`common.search`),className:`w-full rounded-lg border border-transparent bg-black/4 py-1.5 pe-2.5 ps-8 text-base text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:bg-white/5 dark:text-dark-900 dark:placeholder:text-dark-500 sm:text-[13px]`})]}),(0,N.jsx)(`div`,{className:`scroll-region min-h-0 flex-1 overflow-y-auto px-2 pb-3 scrollbar-thin`,children:c?(0,N.jsx)(ae,{size:`sm`,srOnly:!0}):he.length===0?(0,N.jsx)(`div`,{role:`status`,children:(0,N.jsx)(x,{icon:p,size:`sm`,title:_.trim()?e(`common.noResults`):e(`notes.empty`),action:_.trim()?(0,N.jsx)(w,{size:`sm`,variant:`ghost`,onClick:()=>{oe(``),z.current?.focus()},children:e(`common.clear`)}):void 0})}):(0,N.jsx)(`div`,{className:`space-y-0.5`,children:he.map(n=>(0,N.jsxs)(`div`,{"data-testid":`note-list-item`,className:T(`group relative flex items-center rounded-lg transition-colors`,d===n.id?`bg-white ring-1 ring-black/4 dark:bg-dark-200 dark:ring-white/5`:`hover:bg-white/60 dark:hover:bg-dark-200/60`),children:[(0,N.jsxs)(`button`,{type:`button`,tabIndex:0,onClick:()=>K(n),"aria-label":n.title||e(`notes.untitled`),"aria-current":d===n.id?`true`:void 0,className:`min-w-0 flex-1 rounded-lg px-2.5 py-2 text-start focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,children:[(0,N.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1 truncate text-[13px] font-medium text-gray-900 dark:text-dark-900`,children:[n.pinned&&(0,N.jsx)(f,{className:`h-3 w-3 shrink-0 text-primary-500`,"aria-label":e(`notes.pinned`)}),n.shared&&(0,N.jsx)(g,{className:`h-3 w-3 shrink-0 text-gray-400 dark:text-dark-500`,"aria-label":e(`notes.sharedWithYou`)}),(0,N.jsx)(`span`,{className:`truncate`,children:n.title||e(`notes.untitled`)})]}),(0,N.jsxs)(`span`,{className:`mt-0.5 block truncate text-[11px] text-gray-500 dark:text-dark-500`,children:[se(n.updatedAt,t.language),n.content.trim()&&(0,N.jsxs)(N.Fragment,{children:[` · `,n.content.trim().slice(0,60)]})]})]}),!n.shared&&(0,N.jsx)(`button`,{type:`button`,tabIndex:0,onClick:()=>void me(n.id),className:`me-1.5 shrink-0 rounded-md p-1.5 text-gray-500 opacity-100 transition-opacity hover:bg-red-50 hover:text-red-600 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500 sm:opacity-0 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100 dark:text-dark-500 dark:hover:bg-red-900/20 dark:hover:text-red-400`,title:e(`common.delete`),"aria-label":`${e(`common.delete`)}: ${n.title||e(`notes.untitled`)}`,children:(0,N.jsx)(ie,{className:`h-3 w-3`,"aria-hidden":`true`})})]},n.id))})})]}),(0,N.jsx)(`div`,{"data-testid":`notes-editor`,className:T(`min-w-0 flex-1 flex-col`,V?`flex`:`hidden md:flex`),children:V?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 border-b border-black/6 px-2.5 py-2.5 dark:border-white/[0.07] sm:gap-2 sm:px-5 sm:py-3`,children:[(0,N.jsx)(w,{size:`sm`,variant:`ghost`,onClick:()=>{Y(),m(null),j(!0)},className:`h-9 w-9 shrink-0 p-0 md:hidden`,title:`${e(`common.back`)}: ${e(`notes.title`)}`,"aria-label":`${e(`common.back`)}: ${e(`notes.title`)}`,"data-testid":`notes-mobile-back`,children:(0,N.jsx)(v,{className:`h-4 w-4 rtl:rotate-180`})}),A?(0,N.jsx)(`h2`,{"data-testid":`notes-title-preview`,dir:`auto`,className:`min-w-0 flex-1 truncate text-base font-semibold text-gray-950 dark:text-dark-950 sm:text-lg`,children:C||e(`notes.untitled`)}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`input`,{"data-testid":`notes-title-editor`,dir:`auto`,readOnly:!G,value:C,onChange:e=>{E(e.target.value),q(V.id,e.target.value,D)},placeholder:e(`notes.untitled`),"aria-label":e(`notes.titleLabel`),className:`min-w-0 flex-1 rounded-md bg-transparent text-base font-semibold text-gray-950 placeholder:text-gray-400 focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/50 dark:text-dark-950 dark:placeholder:text-dark-500 sm:text-lg`}),(0,N.jsx)(`span`,{className:T(`hidden shrink-0 text-[11px] sm:inline`,M===`error`?`text-error-700 dark:text-error-300`:`text-ink-muted`),"aria-live":`polite`,children:M===`saving`?e(`common.saving`):M===`saved`?e(`notes.saved`):M===`error`?e(`notes.saveFailed`):``})]}),W&&(0,N.jsx)(w,{size:`sm`,variant:`ghost`,onClick:()=>void fe(),className:T(`hidden h-8 w-8 shrink-0 p-0 sm:flex`,V.pinned&&`text-primary-500`),title:V.pinned?e(`notes.unpin`):e(`notes.pin`),"aria-label":V.pinned?e(`notes.unpin`):e(`notes.pin`),"data-testid":`notes-pin-toggle`,children:(0,N.jsx)(f,{className:`h-3.5 w-3.5`})}),(0,N.jsx)(w,{size:`sm`,variant:`ghost`,onClick:pe,className:`hidden h-8 w-8 shrink-0 p-0 sm:flex`,title:e(`notes.export`),"aria-label":e(`notes.export`),"data-testid":`notes-export`,children:(0,N.jsx)(a,{className:`h-3.5 w-3.5`})}),(0,N.jsx)(w,{size:`sm`,variant:`ghost`,onClick:()=>L(e=>e===null?`revisions`:null),className:`h-9 w-9 shrink-0 p-0 sm:h-8 sm:w-8`,title:e(`notes.tools`),"aria-label":e(`notes.tools`),"aria-expanded":F!==null,"data-testid":`notes-tools-toggle`,children:(0,N.jsx)(ee,{className:`h-3.5 w-3.5`})}),(0,N.jsx)(w,{size:`sm`,variant:`ghost`,onClick:()=>{A||Y(),j(e=>!e)},className:`h-9 w-9 shrink-0 gap-1.5 p-0 text-xs sm:h-8 sm:w-auto sm:px-2.5`,title:e(A?`common.edit`:`artifacts.preview`),"aria-label":e(A?`common.edit`:`artifacts.preview`),"data-testid":`notes-preview-toggle`,children:A?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(re,{className:`h-3.5 w-3.5`}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.edit`)})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(te,{className:`h-3.5 w-3.5`}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:e(`artifacts.preview`)})]})})]}),A?(0,N.jsx)(`div`,{"data-testid":`notes-preview`,className:`scroll-region min-h-0 flex-1 overflow-y-auto px-4 py-3 scrollbar-thin sm:px-5 sm:py-4`,children:(0,N.jsx)(y,{content:D,allowHtml:!0,className:`mx-auto w-full max-w-5xl pb-12`})}):(0,N.jsx)(`textarea`,{"data-testid":`notes-content-editor`,dir:`auto`,readOnly:!G,value:D,onChange:e=>{O(e.target.value),q(V.id,C,e.target.value)},onBlur:Y,placeholder:e(`notes.contentPlaceholder`),"aria-label":e(`notes.contentPlaceholder`),className:`min-h-0 flex-1 resize-none bg-transparent px-4 py-3 font-mono text-base leading-relaxed text-gray-900 placeholder:text-gray-400 focus:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary-500/50 dark:text-dark-900 dark:placeholder:text-dark-500 sm:px-5 sm:py-4 sm:text-[13.5px]`}),F!==null&&(0,N.jsx)(ce,{note:V,currentContent:D,currentTitle:C,canWrite:G,isOwner:W,initialTab:F,onClose:()=>L(null),onApplyContent:(e,t)=>{O(e),t!==void 0&&E(t),J(V.id,t===void 0?C:t,e)}})]}):(0,N.jsx)(`div`,{className:`flex flex-1 items-center justify-center`,children:(0,N.jsxs)(`div`,{className:`text-center`,children:[(0,N.jsx)(p,{className:`mx-auto mb-3 h-8 w-8 text-gray-300 dark:text-dark-400`}),(0,N.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-dark-600`,children:e(`notes.selectOrCreate`)}),(0,N.jsxs)(w,{size:`sm`,onClick:()=>void X(),className:`mt-4 gap-1.5`,children:[(0,N.jsx)(ne,{className:`h-3.5 w-3.5`}),e(`notes.new`)]})]})})})]})};export{L as NotesPage,L as default};
|
|
3
|
+
`);if(n.length>A||r.length>A)return[...n.map(e=>({type:`removed`,text:e})),...r.map(e=>({type:`added`,text:e}))];let i=Array.from({length:n.length+1},()=>Array(r.length+1).fill(0));for(let e=n.length-1;e>=0;--e)for(let t=r.length-1;t>=0;--t)i[e][t]=n[e]===r[t]?i[e+1][t+1]+1:Math.max(i[e+1][t],i[e][t+1]);let a=[],o=0,s=0;for(;o<n.length&&s<r.length;)n[o]===r[s]?(a.push({type:`context`,text:n[o]}),o+=1,s+=1):i[o+1][s]>=i[o][s+1]?(a.push({type:`removed`,text:n[o]}),o+=1):(a.push({type:`added`,text:r[s]}),s+=1);for(;o<n.length;)a.push({type:`removed`,text:n[o]}),o+=1;for(;s<r.length;)a.push({type:`added`,text:r[s]}),s+=1;return a},M=e=>e.some(e=>e.type!==`context`),N=n(),P=E(`components:note-tools`),F=({rows:e})=>(0,N.jsx)(`div`,{className:`max-h-64 overflow-auto rounded-lg border border-black/6 font-mono text-[12px] leading-relaxed dark:border-white/8`,"data-testid":`note-diff-view`,children:e.map((e,t)=>(0,N.jsx)(`div`,{className:T(`whitespace-pre-wrap px-2`,e.type===`added`&&`bg-[rgb(76,212,117)]/12 text-green-800 dark:text-green-300`,e.type===`removed`&&`bg-[rgb(255,61,129)]/10 text-red-800 line-through dark:text-red-300`,e.type===`context`&&`text-gray-600 dark:text-dark-700`),children:e.text||`\xA0`},t))}),ce=({note:e,currentContent:t,currentTitle:n,canWrite:r,isOwner:s,initialTab:ee,onClose:te,onApplyContent:f})=>{let{t:p,i18n:ne}=i(),[g,re]=(0,k.useState)(ee),[v,y]=(0,k.useState)({revisions:!1,attachments:!1,share:!1}),[b,E]=(0,k.useState)(null),[A,ce]=(0,k.useState)(null),[I,le]=(0,k.useState)(null),[L,R]=(0,k.useState)(!1),z=(0,k.useRef)(null),[B,ue]=(0,k.useState)(null),[V,H]=(0,k.useState)(``),[U,de]=(0,k.useState)(`read`),[W,G]=(0,k.useState)(!1),[K,fe]=(0,k.useState)(``),[pe,q]=(0,k.useState)(!1),[J,Y]=(0,k.useState)(null),X=O(e=>e.selectedModel),me=O(e=>e.selectedProviderType),he=O(e=>e.selectedProviderId),ge=(0,k.useCallback)(()=>{S.getRevisions(e.id).then(e=>{if(e.success&&Array.isArray(e.data))E(e.data);else throw Error(e.error)}).catch(e=>{P.error(`Failed to load revisions:`,e),l.error(p(`notes.loadFailed`)),y(e=>({...e,revisions:!0}))})},[e.id,p]),Z=(0,k.useCallback)(()=>{S.getAttachments(e.id).then(e=>{if(e.success&&Array.isArray(e.data))le(e.data);else throw Error(e.error)}).catch(e=>{P.error(`Failed to load attachments:`,e),l.error(p(`notes.loadFailed`)),y(e=>({...e,attachments:!0}))})},[e.id,p]),Q=(0,k.useCallback)(()=>{C.listGrants(`note`,e.id).then(e=>{if(e.success&&Array.isArray(e.data))ue(e.data);else throw Error(e.error)}).catch(e=>{P.error(`Failed to load shares:`,e),l.error(p(`notes.loadFailed`)),y(e=>({...e,share:!0}))})},[e.id,p]),_e=e=>v[e]?(0,N.jsx)(oe,{size:`sm`,message:p(`notes.loadFailed`),onRetry:()=>y(t=>({...t,[e]:!1}))}):(0,N.jsx)(ae,{size:`sm`,srOnly:!0});(0,k.useEffect)(()=>{g===`revisions`&&b===null&&!v.revisions&&ge(),g===`attachments`&&I===null&&!v.attachments&&Z(),g===`share`&&s&&B===null&&!v.share&&Q()},[g,b,I,B,v,s,ge,Z,Q]);let ve=async t=>{if(await D({title:p(`notes.restoreConfirmTitle`),description:p(`notes.restoreConfirmDescription`),confirmLabel:p(`notes.restore`),destructive:!0}))try{let n=await S.restoreRevision(e.id,t);n.success&&n.data?(f(n.data.content,n.data.title),E(null),ce(null),l.success(p(`notes.revisionRestored`))):l.error(n.error||p(`notes.revisionRestoreFailed`))}catch(e){P.error(`Failed to restore revision:`,e),l.error(p(`notes.revisionRestoreFailed`))}},ye=async t=>{if(t&&t.length!==0){R(!0);try{let n=await S.uploadAttachment(e.id,t[0]);n.success?(Z(),l.success(p(`notes.attachmentAdded`))):l.error(n.error||p(`notes.attachmentFailed`))}catch(e){P.error(`Failed to upload attachment:`,e),l.error(p(`notes.attachmentFailed`))}finally{R(!1),z.current&&(z.current.value=``)}}},be=async t=>{try{let n=await S.downloadAttachment(e.id,t.id),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=t.filename,i.click(),URL.revokeObjectURL(r)}catch(e){P.error(`Failed to download attachment:`,e),l.error(p(`notes.attachmentDownloadFailed`))}},xe=async t=>{if(await D({title:p(`notes.deleteAttachmentConfirmTitle`,{name:t.filename}),description:p(`notes.deleteAttachmentConfirmDescription`),destructive:!0}))try{(await S.deleteAttachment(e.id,t.id)).success?Z():l.error(p(`notes.attachmentDeleteFailed`))}catch(e){P.error(`Failed to delete attachment:`,e),l.error(p(`notes.attachmentDeleteFailed`))}},Se=async()=>{let t=V.trim();if(t){G(!0);try{let n=await C.resolvePrincipal(t);if(!n.success||!n.data){l.error(p(`notes.shareUserNotFound`));return}let r=await C.createGrant({resourceType:`note`,resourceId:e.id,principalType:`user`,principalId:n.data.id,permission:U});r.success?(H(``),Q(),l.success(p(`notes.shareAdded`,{username:t}))):l.error(r.error||p(`notes.shareFailed`))}catch(e){P.error(`Failed to share note:`,e),l.error(p(`notes.shareFailed`))}finally{G(!1)}}},Ce=async e=>{try{(await C.deleteGrant(e)).success?Q():l.error(p(`notes.revokeFailed`))}catch(e){P.error(`Failed to revoke share:`,e),l.error(p(`notes.revokeFailed`))}},we=async()=>{if(K.trim()&&X){q(!0),Y(null);try{let t=await S.assist(e.id,{instruction:K,model:X,providerType:me,providerId:he});t.success&&t.data?.content!==void 0?Y(t.data.content):l.error(t.error||p(`notes.assistFailed`))}catch(e){P.error(`Note assist failed:`,e),l.error(p(`notes.assistFailed`))}finally{q(!1)}}},$=(0,k.useMemo)(()=>J===null?null:j(t,J),[J,t]),Te=[{id:`revisions`,icon:(0,N.jsx)(d,{className:`h-3.5 w-3.5`}),label:p(`notes.revisions`)},{id:`attachments`,icon:(0,N.jsx)(_,{className:`h-3.5 w-3.5`}),label:p(`notes.attachments`)},{id:`share`,icon:(0,N.jsx)(o,{className:`h-3.5 w-3.5`}),label:p(`notes.share`),hidden:!s},{id:`assist`,icon:(0,N.jsx)(c,{className:`h-3.5 w-3.5`}),label:p(`notes.assist`),hidden:!r}];return(0,N.jsxs)(`div`,{className:`absolute inset-y-0 inset-e-0 z-30 flex w-full max-w-md flex-col border-s border-black/6 bg-surface shadow-xl dark:border-white/[0.07] dark:bg-dark-100`,"data-testid":`note-tools-drawer`,role:`dialog`,"aria-label":p(`notes.tools`),children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-black/6 px-3 py-2 dark:border-white/[0.07]`,children:[(0,N.jsx)(`div`,{role:`tablist`,className:`flex items-center gap-1`,children:Te.filter(e=>!e.hidden).map(e=>(0,N.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":g===e.id,onClick:()=>re(e.id),"data-testid":`note-tools-tab-${e.id}`,className:T(`flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[12px] transition-colors`,g===e.id?`bg-black/6 text-gray-900 dark:bg-white/8 dark:text-dark-900`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),children:[e.icon,e.label]},e.id))}),(0,N.jsx)(`button`,{type:`button`,onClick:te,className:`ms-auto rounded-md p-1.5 text-gray-400 hover:text-gray-700 dark:text-dark-500 dark:hover:text-dark-800`,"aria-label":p(`common.close`),"data-testid":`note-tools-close`,children:(0,N.jsx)(h,{className:`h-4 w-4`})})]}),(0,N.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-4 scrollbar-thin`,children:[g===`revisions`&&(0,N.jsx)(`div`,{className:`space-y-2`,children:b===null?_e(`revisions`):b.length===0?(0,N.jsx)(x,{icon:d,size:`sm`,title:p(`notes.noRevisions`)}):b.map(e=>(0,N.jsxs)(`div`,{className:`rounded-lg border border-black/6 p-2.5 dark:border-white/8`,"data-testid":`note-revision-item`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>ce(t=>t===e.id?null:e.id),className:`min-w-0 flex-1 truncate text-start text-[13px] text-gray-800 dark:text-dark-800`,children:[se(e.createdAt,ne.language),e.title!==n&&(0,N.jsxs)(`span`,{className:`ms-1 text-gray-400 dark:text-dark-500`,children:[`· `,e.title||p(`notes.untitled`)]})]}),r&&(0,N.jsxs)(w,{size:`sm`,variant:`ghost`,className:`h-7 gap-1 px-2 text-[11px]`,onClick:()=>void ve(e.id),"data-testid":`note-revision-restore`,children:[(0,N.jsx)(m,{className:`h-3 w-3`}),p(`notes.restore`)]})]}),A===e.id&&(0,N.jsx)(`div`,{className:`mt-2`,children:(0,N.jsx)(F,{rows:j(e.content,t)})})]},e.id))}),g===`attachments`&&(0,N.jsxs)(`div`,{className:`space-y-2`,children:[r&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`input`,{ref:z,type:`file`,className:`hidden`,onChange:e=>void ye(e.target.files),"data-testid":`note-attachment-input`}),(0,N.jsxs)(w,{size:`sm`,variant:`outline`,className:`w-full gap-1.5`,disabled:L,onClick:()=>z.current?.click(),"data-testid":`note-attachment-upload`,children:[L?(0,N.jsx)(u,{className:`h-3.5 w-3.5 animate-spin`}):(0,N.jsx)(_,{className:`h-3.5 w-3.5`}),p(`notes.addAttachment`)]})]}),I===null?_e(`attachments`):I.length===0?(0,N.jsx)(x,{icon:_,size:`sm`,title:p(`notes.noAttachments`)}):I.map(e=>(0,N.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-black/6 px-2.5 py-2 dark:border-white/8`,"data-testid":`note-attachment-item`,children:[(0,N.jsx)(_,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,N.jsx)(`span`,{dir:`ltr`,className:`min-w-0 flex-1 truncate text-[13px] text-gray-800 dark:text-dark-800`,children:e.filename}),(0,N.jsxs)(`span`,{className:`shrink-0 text-[11px] text-gray-400 dark:text-dark-500`,children:[Math.max(1,Math.round(e.size/1024)),` KB`]}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>void be(e),className:`rounded-md p-1.5 text-gray-500 hover:text-gray-700 dark:text-dark-500 dark:hover:text-dark-800`,title:p(`common.download`),"aria-label":`${p(`common.download`)}: ${e.filename}`,children:(0,N.jsx)(a,{className:`h-3.5 w-3.5`})}),r&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>void xe(e),className:`rounded-md p-1.5 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,title:p(`common.delete`),"aria-label":`${p(`common.delete`)}: ${e.filename}`,children:(0,N.jsx)(ie,{className:`h-3.5 w-3.5`})})]},e.id))]}),g===`share`&&s&&(0,N.jsxs)(`div`,{className:`space-y-3`,children:[(0,N.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,N.jsx)(`input`,{type:`text`,value:V,onChange:e=>H(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Se()},placeholder:p(`notes.shareUsernamePlaceholder`),"aria-label":p(`notes.shareUsernamePlaceholder`),className:`min-w-0 flex-1 rounded-lg border border-black/8 bg-transparent px-2.5 py-1.5 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"data-testid":`note-share-username`}),(0,N.jsxs)(`select`,{value:U,onChange:e=>de(e.target.value),className:`rounded-lg border border-black/8 bg-transparent px-2 py-1.5 text-[12px] text-gray-700 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:bg-dark-100 dark:text-dark-800`,"aria-label":p(`notes.sharePermissionLabel`),"data-testid":`note-share-permission`,children:[(0,N.jsx)(`option`,{value:`read`,children:p(`notes.permissionRead`)}),(0,N.jsx)(`option`,{value:`write`,children:p(`notes.permissionWrite`)})]}),(0,N.jsx)(w,{size:`sm`,disabled:W||!V.trim(),onClick:()=>void Se(),"data-testid":`note-share-submit`,children:W?(0,N.jsx)(u,{className:`h-3.5 w-3.5 animate-spin`}):p(`notes.shareAction`)})]}),B===null?_e(`share`):B.length===0?(0,N.jsx)(x,{icon:o,size:`sm`,title:p(`notes.notShared`)}):B.map(e=>(0,N.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-black/6 px-2.5 py-2 dark:border-white/8`,"data-testid":`note-share-item`,children:[(0,N.jsx)(o,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] text-gray-800 dark:text-dark-800`,children:e.principalId}),(0,N.jsx)(`span`,{className:`shrink-0 text-[11px] uppercase text-gray-400 dark:text-dark-500`,children:e.permission}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>void Ce(e.id),className:`rounded-md p-1.5 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,title:p(`notes.revokeShare`),"aria-label":p(`notes.revokeShare`),children:(0,N.jsx)(h,{className:`h-3.5 w-3.5`})})]},e.id)),(0,N.jsx)(`p`,{className:`text-[11px] leading-relaxed text-gray-400 dark:text-dark-500`,children:p(`notes.shareHint`)})]}),g===`assist`&&r&&(0,N.jsxs)(`div`,{className:`space-y-3`,children:[(0,N.jsx)(`textarea`,{value:K,onChange:e=>fe(e.target.value),placeholder:p(`notes.assistPlaceholder`),rows:3,className:`w-full resize-none rounded-lg border border-black/8 bg-transparent px-2.5 py-2 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"aria-label":p(`notes.assistPlaceholder`),"data-testid":`note-assist-instruction`}),(0,N.jsxs)(w,{size:`sm`,className:`w-full gap-1.5`,disabled:pe||!K.trim()||!X,onClick:()=>void we(),"data-testid":`note-assist-generate`,children:[pe?(0,N.jsx)(u,{className:`h-3.5 w-3.5 animate-spin`}):(0,N.jsx)(c,{className:`h-3.5 w-3.5`}),p(`notes.assistGenerate`)]}),!X&&(0,N.jsx)(`p`,{className:`text-[11px] text-amber-600 dark:text-amber-400`,children:p(`notes.assistNoModel`)}),J!==null&&$&&(0,N.jsxs)(`div`,{className:`space-y-2`,children:[M($)?(0,N.jsx)(F,{rows:$}):(0,N.jsx)(`p`,{className:`text-center text-xs text-gray-400 dark:text-dark-500`,children:p(`notes.assistNoChanges`)}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(w,{size:`sm`,className:`flex-1`,disabled:!M($),onClick:()=>{f(J),Y(null),fe(``),l.success(p(`notes.assistApplied`))},"data-testid":`note-assist-apply`,children:p(`notes.assistApply`)}),(0,N.jsx)(w,{size:`sm`,variant:`outline`,className:`flex-1`,onClick:()=>Y(null),"data-testid":`note-assist-discard`,children:p(`notes.assistDiscard`)})]}),(0,N.jsx)(`p`,{className:`text-[11px] leading-relaxed text-gray-400 dark:text-dark-500`,children:p(`notes.assistRevisionHint`)})]})]})]})]})},I=E(`pages:notes`),le=800,L=()=>{let{t:e,i18n:t}=i(),[n,o]=(0,k.useState)([]),[c,u]=(0,k.useState)(!0),[d,m]=(0,k.useState)(null),h=(0,k.useRef)(null);(0,k.useEffect)(()=>{h.current=d},[d]);let[_,oe]=(0,k.useState)(``),[C,E]=(0,k.useState)(``),[D,O]=(0,k.useState)(``),[A,j]=(0,k.useState)(!0),[M,P]=(0,k.useState)(`idle`),[F,L]=(0,k.useState)(null),R=(0,k.useRef)(null),z=(0,k.useRef)(null),[B,ue]=r(),V=(0,k.useMemo)(()=>n.find(e=>e.id===d)??null,[n,d]);(0,k.useEffect)(()=>{let e=!1;return S.getNotes().then(t=>{e||t.success&&t.data&&o(t.data)}).catch(e=>I.error(`Failed to load notes:`,e)).finally(()=>{e||u(!1)}),()=>{e=!0}},[]);let H=B.get(`note`),U=H?n.find(e=>e.id===H):void 0;U&&d!==U.id&&(m(U.id),E(U.title),O(U.content),j(!0),P(`idle`));let de=H!==null&&(U!==void 0||!c);(0,k.useEffect)(()=>{de&&ue({},{replace:!0})},[de,ue]);let W=!V||!V.shared,G=V?!V.shared||V.shared.permission===`write`:!1,K=(e,t=`preview`)=>{Y(),h.current=e.id,m(e.id),E(e.title),O(e.content),j(t===`preview`),P(`idle`),L(null)},fe=async()=>{if(V)try{let t=await S.updateNote(V.id,{pinned:!V.pinned});if(t.success&&t.data){let e=t.data;o(t=>t.map(t=>t.id===e.id?e:t))}else l.error(e(`notes.saveFailed`))}catch(t){I.error(`Failed to toggle pin:`,t),l.error(e(`notes.saveFailed`))}},pe=()=>{if(!V)return;let e=new Blob([D],{type:`text/markdown;charset=utf-8`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`${(C||`note`).replace(/[\\/:*?"<>|]/g,`-`)}.md`,n.click(),URL.revokeObjectURL(t)},q=(e,t,n)=>{R.current!==null&&window.clearTimeout(R.current),P(`saving`),R.current=window.setTimeout(()=>{R.current=null,J(e,t,n)},le)},J=async(t,n,r)=>{try{let i=await S.updateNote(t,{title:n,content:r});if(i.success&&i.data){let e=i.data;o(n=>[e,...n.filter(e=>e.id!==t)].sort((e,t)=>t.updatedAt-e.updatedAt)),h.current===t&&P(`saved`)}else l.error(e(`notes.saveFailed`)),h.current===t&&P(`error`)}catch(n){I.error(`Failed to save note:`,n),l.error(e(`notes.saveFailed`)),h.current===t&&P(`error`)}},Y=()=>{R.current!==null&&d&&(window.clearTimeout(R.current),R.current=null,J(d,C,D))};(0,k.useEffect)(()=>()=>{R.current!==null&&window.clearTimeout(R.current)},[]);let X=async()=>{try{let e=await S.createNote(``,``);if(e.success&&e.data){let t=e.data;o(e=>[t,...e]),K(t,`edit`)}}catch(t){I.error(`Failed to create note:`,t),l.error(e(`notes.createFailed`))}},me=async t=>{if(window.confirm(e(`notes.deleteConfirm`)))try{(await S.deleteNote(t)).success?(o(e=>e.filter(e=>e.id!==t)),d===t&&m(null)):l.error(e(`notes.deleteFailed`))}catch(t){I.error(`Failed to delete note:`,t),l.error(e(`notes.deleteFailed`))}},he=(0,k.useMemo)(()=>{let e=_.trim().toLowerCase();return e?n.filter(t=>t.title.toLowerCase().includes(e)||t.content.toLowerCase().includes(e)):n},[n,_]);return(0,N.jsxs)(`div`,{className:`relative flex h-full min-h-0 overflow-hidden`,"data-testid":`notes-page`,children:[(0,N.jsxs)(`div`,{"data-testid":`notes-list`,className:T(`min-h-0 w-full shrink-0 flex-col border-e border-black/6 dark:border-white/[0.07] md:w-72`,V?`hidden md:flex`:`flex`),children:[(0,N.jsx)(b,{title:e(`notes.title`),actions:(0,N.jsx)(w,{size:`sm`,variant:`ghost`,onClick:()=>void X(),className:`h-7 w-7 p-0`,title:e(`notes.new`),"aria-label":e(`notes.new`),children:(0,N.jsx)(re,{className:`h-4 w-4`})})}),(0,N.jsxs)(`div`,{className:`relative mx-3 mb-2 mt-3`,children:[(0,N.jsx)(ee,{className:`pointer-events-none absolute inset-s-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-gray-400 dark:text-dark-500`}),(0,N.jsx)(`input`,{ref:z,type:`search`,value:_,onChange:e=>oe(e.target.value),placeholder:e(`common.search`),"aria-label":e(`common.search`),className:`w-full rounded-lg border border-transparent bg-black/4 py-1.5 pe-2.5 ps-8 text-base text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:bg-white/5 dark:text-dark-900 dark:placeholder:text-dark-500 sm:text-[13px]`})]}),(0,N.jsx)(`div`,{className:`scroll-region min-h-0 flex-1 overflow-y-auto px-2 pb-3 scrollbar-thin`,children:c?(0,N.jsx)(ae,{size:`sm`,srOnly:!0}):he.length===0?(0,N.jsx)(`div`,{role:`status`,children:(0,N.jsx)(x,{icon:p,size:`sm`,title:_.trim()?e(`common.noResults`):e(`notes.empty`),action:_.trim()?(0,N.jsx)(w,{size:`sm`,variant:`ghost`,onClick:()=>{oe(``),z.current?.focus()},children:e(`common.clear`)}):void 0})}):(0,N.jsx)(`div`,{className:`space-y-0.5`,children:he.map(n=>(0,N.jsxs)(`div`,{"data-testid":`note-list-item`,className:T(`group relative flex items-center rounded-lg transition-colors`,d===n.id?`bg-white ring-1 ring-black/4 dark:bg-dark-200 dark:ring-white/5`:`hover:bg-white/60 dark:hover:bg-dark-200/60`),children:[(0,N.jsxs)(`button`,{type:`button`,tabIndex:0,onClick:()=>K(n),"aria-label":n.title||e(`notes.untitled`),"aria-current":d===n.id?`true`:void 0,className:`min-w-0 flex-1 rounded-lg px-2.5 py-2 text-start focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,children:[(0,N.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1 truncate text-[13px] font-medium text-gray-900 dark:text-dark-900`,children:[n.pinned&&(0,N.jsx)(f,{className:`h-3 w-3 shrink-0 text-primary-500`,"aria-label":e(`notes.pinned`)}),n.shared&&(0,N.jsx)(ne,{className:`h-3 w-3 shrink-0 text-gray-400 dark:text-dark-500`,"aria-label":e(`notes.sharedWithYou`)}),(0,N.jsx)(`span`,{className:`truncate`,children:n.title||e(`notes.untitled`)})]}),(0,N.jsxs)(`span`,{className:`mt-0.5 block truncate text-[11px] text-gray-500 dark:text-dark-500`,children:[se(n.updatedAt,t.language),n.content.trim()&&(0,N.jsxs)(N.Fragment,{children:[` · `,n.content.trim().slice(0,60)]})]})]}),!n.shared&&(0,N.jsx)(`button`,{type:`button`,tabIndex:0,onClick:()=>void me(n.id),className:`me-1.5 shrink-0 rounded-md p-1.5 text-gray-500 opacity-100 transition-opacity hover:bg-red-50 hover:text-red-600 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500 sm:opacity-0 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100 dark:text-dark-500 dark:hover:bg-red-900/20 dark:hover:text-red-400`,title:e(`common.delete`),"aria-label":`${e(`common.delete`)}: ${n.title||e(`notes.untitled`)}`,children:(0,N.jsx)(ie,{className:`h-3 w-3`,"aria-hidden":`true`})})]},n.id))})})]}),(0,N.jsx)(`div`,{"data-testid":`notes-editor`,className:T(`min-w-0 flex-1 flex-col`,V?`flex`:`hidden md:flex`),children:V?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 border-b border-black/6 px-2.5 py-2.5 dark:border-white/[0.07] sm:gap-2 sm:px-5 sm:py-3`,children:[(0,N.jsx)(w,{size:`sm`,variant:`ghost`,onClick:()=>{Y(),m(null),j(!0)},className:`h-9 w-9 shrink-0 p-0 md:hidden`,title:`${e(`common.back`)}: ${e(`notes.title`)}`,"aria-label":`${e(`common.back`)}: ${e(`notes.title`)}`,"data-testid":`notes-mobile-back`,children:(0,N.jsx)(v,{className:`h-4 w-4 rtl:rotate-180`})}),A?(0,N.jsx)(`h2`,{"data-testid":`notes-title-preview`,dir:`auto`,className:`min-w-0 flex-1 truncate text-base font-semibold text-gray-950 dark:text-dark-950 sm:text-lg`,children:C||e(`notes.untitled`)}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`input`,{"data-testid":`notes-title-editor`,dir:`auto`,readOnly:!G,value:C,onChange:e=>{E(e.target.value),q(V.id,e.target.value,D)},placeholder:e(`notes.untitled`),"aria-label":e(`notes.titleLabel`),className:`min-w-0 flex-1 rounded-md bg-transparent text-base font-semibold text-gray-950 placeholder:text-gray-400 focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/50 dark:text-dark-950 dark:placeholder:text-dark-500 sm:text-lg`}),(0,N.jsx)(`span`,{className:T(`hidden shrink-0 text-[11px] sm:inline`,M===`error`?`text-error-700 dark:text-error-300`:`text-ink-muted`),"aria-live":`polite`,children:M===`saving`?e(`common.saving`):M===`saved`?e(`notes.saved`):M===`error`?e(`notes.saveFailed`):``})]}),W&&(0,N.jsx)(w,{size:`sm`,variant:`ghost`,onClick:()=>void fe(),className:T(`hidden h-8 w-8 shrink-0 p-0 sm:flex`,V.pinned&&`text-primary-500`),title:V.pinned?e(`notes.unpin`):e(`notes.pin`),"aria-label":V.pinned?e(`notes.unpin`):e(`notes.pin`),"data-testid":`notes-pin-toggle`,children:(0,N.jsx)(f,{className:`h-3.5 w-3.5`})}),(0,N.jsx)(w,{size:`sm`,variant:`ghost`,onClick:pe,className:`hidden h-8 w-8 shrink-0 p-0 sm:flex`,title:e(`notes.export`),"aria-label":e(`notes.export`),"data-testid":`notes-export`,children:(0,N.jsx)(a,{className:`h-3.5 w-3.5`})}),(0,N.jsx)(w,{size:`sm`,variant:`ghost`,onClick:()=>L(e=>e===null?`revisions`:null),className:`h-9 w-9 shrink-0 p-0 sm:h-8 sm:w-8`,title:e(`notes.tools`),"aria-label":e(`notes.tools`),"aria-expanded":F!==null,"data-testid":`notes-tools-toggle`,children:(0,N.jsx)(te,{className:`h-3.5 w-3.5`})}),(0,N.jsx)(w,{size:`sm`,variant:`ghost`,onClick:()=>{A||Y(),j(e=>!e)},className:`h-9 w-9 shrink-0 gap-1.5 p-0 text-xs sm:h-8 sm:w-auto sm:px-2.5`,title:e(A?`common.edit`:`artifacts.preview`),"aria-label":e(A?`common.edit`:`artifacts.preview`),"data-testid":`notes-preview-toggle`,children:A?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(g,{className:`h-3.5 w-3.5`}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.edit`)})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(s,{className:`h-3.5 w-3.5`}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:e(`artifacts.preview`)})]})})]}),A?(0,N.jsx)(`div`,{"data-testid":`notes-preview`,className:`scroll-region min-h-0 flex-1 overflow-y-auto px-4 py-3 scrollbar-thin sm:px-5 sm:py-4`,children:(0,N.jsx)(y,{content:D,allowHtml:!0,className:`mx-auto w-full max-w-5xl pb-12`})}):(0,N.jsx)(`textarea`,{"data-testid":`notes-content-editor`,dir:`auto`,readOnly:!G,value:D,onChange:e=>{O(e.target.value),q(V.id,C,e.target.value)},onBlur:Y,placeholder:e(`notes.contentPlaceholder`),"aria-label":e(`notes.contentPlaceholder`),className:`min-h-0 flex-1 resize-none bg-transparent px-4 py-3 font-mono text-base leading-relaxed text-gray-900 placeholder:text-gray-400 focus:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary-500/50 dark:text-dark-900 dark:placeholder:text-dark-500 sm:px-5 sm:py-4 sm:text-[13.5px]`}),F!==null&&(0,N.jsx)(ce,{note:V,currentContent:D,currentTitle:C,canWrite:G,isOwner:W,initialTab:F,onClose:()=>L(null),onApplyContent:(e,t)=>{O(e),t!==void 0&&E(t),J(V.id,t===void 0?C:t,e)}})]}):(0,N.jsx)(`div`,{className:`flex flex-1 items-center justify-center`,children:(0,N.jsxs)(`div`,{className:`text-center`,children:[(0,N.jsx)(p,{className:`mx-auto mb-3 h-8 w-8 text-gray-300 dark:text-dark-400`}),(0,N.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-dark-600`,children:e(`notes.selectOrCreate`)}),(0,N.jsxs)(w,{size:`sm`,onClick:()=>void X(),className:`mt-4 gap-1.5`,children:[(0,N.jsx)(re,{className:`h-3.5 w-3.5`}),e(`notes.new`)]})]})})})]})};export{L as NotesPage,L as default};
|
package/frontend/dist/js/{PasswordStrengthMeter-DrXjBWiT.js → PasswordStrengthMeter-DdqX0FXA.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./rolldown-runtime-XKyaHtl9.js";import{i as e,t}from"./react-vendor-C1iE8mnY.js";import{t as n}from"./useTranslation-
|
|
1
|
+
import"./rolldown-runtime-XKyaHtl9.js";import{i as e,t}from"./react-vendor-C1iE8mnY.js";import{t as n}from"./useTranslation-CKqEdZ8j.js";import{er as r,n as i}from"./ui-vendor-DsURZnZt.js";import{t as a}from"./utils-BXRzbHJC.js";e();var o=`passwordStrength.requirements`,s=e=>{let t={minLength:e.length>=12,withinBytes:new TextEncoder().encode(e).length<=72,hasCase:/[A-Z]/.test(e)&&/[a-z]/.test(e),hasNumber:/[0-9]/.test(e)},n=t.minLength&&t.withinBytes&&t.hasCase&&t.hasNumber,r=Number(t.minLength)+Number(t.hasCase)+Number(t.hasNumber),i=e.length>=16||/[^A-Za-z0-9]/.test(e),a;return a=t.withinBytes?r<=1?+(e.length>0):r===2?2:i?4:3:1,{checks:t,satisfied:n,score:a,level:a<=1?`weak`:a===2?`fair`:a===3?`good`:`strong`}},c=e=>e.length<12?`passwordStrength.errors.minLength`:new TextEncoder().encode(e).length>72?`passwordStrength.errors.tooLong`:/[A-Z]/.test(e)?/[a-z]/.test(e)?/[0-9]/.test(e)?null:`passwordStrength.errors.number`:`passwordStrength.errors.lowercase`:`passwordStrength.errors.uppercase`,l=t(),u={weak:`bg-red-500`,fair:`bg-amber-500`,good:`bg-lime-500`,strong:`bg-green-500`},d={weak:`text-error-700 dark:text-error-400`,fair:`text-ink`,good:`text-ink`,strong:`text-success-800 dark:text-success-400`},f=({met:e,label:t})=>(0,l.jsxs)(`li`,{className:a(`flex items-center gap-1.5`,e?`text-success-800 dark:text-success-400`:`text-ink-muted`),children:[e?(0,l.jsx)(r,{className:`h-3 w-3 shrink-0`,"aria-hidden":`true`}):(0,l.jsx)(i,{className:`h-3 w-3 shrink-0`,"aria-hidden":`true`}),(0,l.jsx)(`span`,{children:t})]}),p=({password:e})=>{let{t}=n();if(!e)return(0,l.jsx)(`p`,{className:`mt-1.5 text-xs text-ink-muted`,children:t(o)});let r=s(e);return(0,l.jsxs)(`div`,{className:`mt-2 space-y-1.5`,"data-testid":`password-strength-meter`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`div`,{className:`flex flex-1 gap-1`,children:[1,2,3,4].map(e=>(0,l.jsx)(`div`,{className:a(`h-1 flex-1 rounded-full transition-colors motion-reduce:transition-none`,e<=r.score?u[r.level]:`bg-gray-200 dark:bg-dark-300`)},e))}),(0,l.jsx)(`span`,{"data-testid":`password-strength-label`,"aria-live":`polite`,className:a(`text-xs font-medium`,d[r.level]),children:t(`passwordStrength.levels.${r.level}`)})]}),(0,l.jsxs)(`ul`,{className:`space-y-0.5 text-xs`,children:[(0,l.jsx)(f,{met:r.checks.minLength,label:t(`passwordStrength.checks.minLength`)}),(0,l.jsx)(f,{met:r.checks.hasCase,label:t(`passwordStrength.checks.hasCase`)}),(0,l.jsx)(f,{met:r.checks.hasNumber,label:t(`passwordStrength.checks.hasNumber`)}),!r.checks.withinBytes&&(0,l.jsx)(f,{met:!1,label:t(`passwordStrength.checks.tooLong`)})]})]})};export{c as n,p as t};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{t as r}from"./useTranslation-CKqEdZ8j.js";import{C as i,t as a}from"./useQuery-Cs76KYuP.js";import{$t as o,An as s,B as c,Bn as l,D as u,Dt as d,H as f,Jt as p,M as m,Or as h,P as g,Q as _,Rt as v,_ as y,c as b,er as x,g as S,it as C,j as w,jn as T,kn as E,n as D,nt as O,p as k,qt as A,s as j,sr as ee,t as M,v as N,xn as P,xr as F}from"./ui-vendor-DsURZnZt.js";import{t as I}from"./Button-D6d7HYoa.js";import{n as L,o as R,r as z,s as B,t as V}from"./ui-DxaHE9GD.js";import{M as te,_ as H,d as U,f as ne,g as re,j as ie,m as W,p as G}from"./api-Dasm8tVY.js";import{t as ae}from"./ShareDialog-NwirTDLR.js";import{t as K}from"./utils-BXRzbHJC.js";import{t as q}from"./logger-DAQsBb8I.js";import{t as oe}from"./appStore-DCIUnT8X.js";import{t as J}from"./chatStore-GhucyjJu.js";import{t as se}from"./AvatarUpload-W41SCHKE.js";var Y=e(t(),1),X=n(),Z=q(`components:persona-card`),ce=({persona:e,onEdit:t,onDelete:n,onDownload:o,onSelect:l,onToggleFavorite:p,isSelected:g=!1,compact:_=!1})=>{let{t:v}=r(),y=i(),[b,x]=(0,Y.useState)(!1),D=(0,Y.useRef)(null),O=(0,Y.useRef)(null),[k,A]=(0,Y.useState)(!1),[j,L]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{b&&O.current?.querySelector(`[role="menuitem"]:not(:disabled)`)?.focus()},[b]);let R=(e=!1)=>{x(!1),e&&D.current?.focus()},z=e=>{if(e.key===`Escape`){e.stopPropagation(),R(!0);return}if(e.key!==`ArrowDown`&&e.key!==`ArrowUp`)return;let t=Array.from(O.current?.querySelectorAll(`[role="menuitem"]:not(:disabled)`)??[]);if(t.length===0)return;e.preventDefault();let n=t.indexOf(document.activeElement);t[e.key===`ArrowDown`?(n+1)%t.length:(n-1+t.length)%t.length]?.focus()},B=!!(e.memory_settings?.enabled||e.mutation_settings?.enabled),{data:V=null}=a({queryKey:[`persona-memory-status`,e.id],queryFn:async()=>{let t=await W.getMemoryStatus(e.id);return t.success&&t.data?t.data:null},enabled:B}),te=()=>y.invalidateQueries({queryKey:[`persona-memory-status`,e.id]}),U=async()=>{if(confirm(v(`personaCard.wipeConfirm`))){L(!0);try{let t=await W.wipeMemories(e.id);t.success?(h.success(v(`personaCard.wipeSuccess`,{count:t.data?.deleted_count||0})),await te()):h.error(v(`personaCard.wipeFailed`))}catch(e){h.error(v(`personaCard.wipeFailed`)),Z.error(e)}finally{L(!1),x(!1)}}},ne=async()=>{L(!0);try{let t=await W.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),h.success(v(`personaCard.backupSuccess`))}catch(e){h.error(v(`personaCard.backupFailed`)),Z.error(e)}finally{L(!1),x(!1)}},ie=async()=>{L(!0);try{let t=await W.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),h.success(v(`personaCard.dnaSuccess`))}catch(e){h.error(v(`personaCard.exportDnaFailed`)),Z.error(e)}finally{L(!1),x(!1)}},G=(t=128)=>re(e,t),q=(t=128)=>n=>{H(n.currentTarget,e.name,t)};return _?(0,X.jsxs)(`div`,{className:K(`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`,g&&[`bg-primary-50 dark:bg-primary-900/20`,`border-primary-200 dark:border-primary-700`]),onClick:()=>l?.(e),children:[(0,X.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,X.jsx)(`img`,{src:G(64),alt:e.name,className:`w-10 h-10 rounded-full object-cover ring-2 ring-white dark:ring-dark-100`,onError:q(64)}),B&&(0,X.jsx)(`div`,{className:`absolute -bottom-0.5 -inset-e-0.5 flex h-4 w-4 items-center justify-center rounded-full bg-primary-600`,children:(0,X.jsx)(m,{className:`h-2.5 w-2.5 text-white`})})]}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`h4`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100 truncate`,children:e.name}),e.is_favorite&&(0,X.jsx)(u,{className:`h-3 w-3 text-amber-500 fill-amber-500 shrink-0`})]}),(0,X.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 truncate`,children:e.model})]}),g&&(0,X.jsx)(`div`,{className:`shrink-0`,children:(0,X.jsx)(`div`,{className:`w-6 h-6 rounded-full bg-primary-500 dark:bg-primary-600 flex items-center justify-center`,children:(0,X.jsx)(C,{className:`h-3 w-3 text-white rtl:rotate-180`})})})]}):(0,X.jsxs)(`div`,{className:K(`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`,g&&[`ring-2 ring-primary-500 dark:ring-primary-400`,`border-primary-300 dark:border-primary-600`]),children:[(0,X.jsxs)(`div`,{className:`relative h-24`,children:[e.background?(0,X.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,X.jsx)(`div`,{className:`absolute inset-0 bg-gray-200 dark:bg-dark-200`}),e.background&&(0,X.jsx)(`div`,{className:`absolute inset-0 bg-black/15 dark:bg-black/25`}),(0,X.jsxs)(`div`,{className:`absolute inset-x-3 top-3 flex items-start justify-between`,children:[p?(0,X.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),p(e)},"aria-pressed":!!e.is_favorite,"aria-label":v(`personaCard.favorite`),title:v(`personaCard.favorite`),className:K(`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,X.jsx)(u,{className:K(`h-4 w-4`,e.is_favorite?`fill-ink text-ink dark:fill-ink-inverse dark:text-ink-inverse`:`text-white/80 hover:text-white`)})}):e.is_favorite?(0,X.jsx)(`span`,{role:`img`,"aria-label":v(`personaCard.favorite`),title:v(`personaCard.favorite`),className:`rounded-full border border-white/30 bg-amber-500/80 p-1.5 backdrop-blur-sm`,children:(0,X.jsx)(u,{className:`h-4 w-4 fill-ink text-ink dark:fill-ink-inverse dark:text-ink-inverse`})}):(0,X.jsx)(`span`,{}),B&&(0,X.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,X.jsx)(m,{className:`h-3 w-3`}),v(`personaCard.enhanced`)]})]})]}),(0,X.jsx)(`div`,{className:`relative -mt-8 px-4`,children:(0,X.jsxs)(`div`,{className:`relative inline-block`,children:[(0,X.jsx)(`img`,{src:G(128),alt:e.name,className:`h-16 w-16 rounded-xl object-cover ring-4 ring-white dark:ring-dark-100`,onError:q(128)}),B&&(0,X.jsx)(`div`,{className:`absolute -bottom-1 -inset-e-1 flex h-6 w-6 items-center justify-center rounded-lg bg-primary-600 ring-2 ring-white dark:ring-dark-100`,children:(0,X.jsx)(ee,{className:`h-3.5 w-3.5 text-white`})})]})}),(0,X.jsxs)(`div`,{className:`px-4 pt-3 pb-4`,children:[(0,X.jsxs)(`div`,{className:`mb-3`,children:[(0,X.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 leading-tight`,children:e.name}),(0,X.jsxs)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 flex items-center gap-1.5 mt-0.5`,children:[(0,X.jsx)(f,{className:`h-3.5 w-3.5`}),e.model]})]}),e.description&&(0,X.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,X.jsxs)(`div`,{className:`mb-3 rounded-xl border border-gray-200/70 bg-gray-50/70 p-2.5 dark:border-white/8 dark:bg-white/2.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-1`,children:[(0,X.jsx)(d,{className:`h-3 w-3 text-gray-400 dark:text-gray-500`}),(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider font-medium text-gray-400 dark:text-gray-500`,children:v(`personaCard.systemPrompt`)})]}),(0,X.jsxs)(`p`,{className:`line-clamp-2 text-xs leading-5 text-gray-600 dark:text-gray-400`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-3`,children:[(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-lg border border-gray-200/70 px-2 py-1 text-[11px] font-medium text-gray-600 dark:border-white/8 dark:text-gray-400`,children:[(0,X.jsx)(M,{className:`h-3 w-3`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,X.jsxs)(`span`,{className:`inline-flex items-center rounded-lg border border-gray-200/70 px-2 py-1 text-[11px] font-medium text-gray-600 dark:border-white/8 dark:text-gray-400`,children:[`Top-P `,e.parameters.top_p?.toFixed(1)||`0.9`]}),(0,X.jsxs)(`span`,{className:`inline-flex items-center rounded-lg border border-gray-200/70 px-2 py-1 text-[11px] font-medium text-gray-600 dark:border-white/8 dark:text-gray-400`,children:[(e.parameters.context_window||4096).toLocaleString(),` ctx`]})]}),B&&V&&(0,X.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,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(T,{className:`h-4 w-4 text-primary-600 dark:text-primary-400`}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`span`,{className:`text-xs font-medium text-primary-700 dark:text-primary-300`,children:[V.memory_count,` `,v(`personaCard.memories`)]}),(0,X.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`)(V.size_mb)})]})]}),V.status&&(0,X.jsx)(`span`,{className:K(`text-[10px] px-1.5 py-0.5 rounded-full font-medium`,V.status===`active`?`bg-success-500/20 text-ink`:`bg-surface-subtle text-ink-muted`),children:v(`personaCard.memoryStatus.${V.status}`)})]})}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between border-t border-gray-200/70 pt-3 dark:border-white/8`,children:[l&&(0,X.jsxs)(I,{onClick:()=>l(e),size:`sm`,className:`px-4`,children:[(0,X.jsx)(C,{className:`me-1.5 h-3.5 w-3.5 rtl:rotate-180`}),v(`personaCard.use`)]}),(0,X.jsxs)(`div`,{className:`ms-auto flex items-center gap-1`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>t(e),className:`p-2 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-dark-200 transition-colors`,title:v(`personaCard.editTooltip`),"aria-label":v(`personaCard.editTooltip`),children:(0,X.jsx)(w,{className:`h-4 w-4`})}),!e.shared&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>A(!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:v(`personaCard.shareTooltip`),"aria-label":v(`personaCard.shareTooltip`),"data-testid":`persona-share`,children:(0,X.jsx)(c,{className:`h-4 w-4`})}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>o(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:v(`personaCard.downloadTooltip`),"aria-label":v(`personaCard.downloadTooltip`),children:(0,X.jsx)(s,{className:`h-4 w-4`})}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(`button`,{ref:D,type:`button`,onClick:()=>x(!b),"aria-haspopup":`menu`,"aria-expanded":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:v(`common.more`),"aria-label":v(`common.more`),children:(0,X.jsx)(E,{className:`h-4 w-4`})}),b&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>x(!1)}),(0,X.jsxs)(`div`,{ref:O,role:`menu`,onKeyDown:z,className:`absolute inset-e-0 bottom-full z-20 mb-1 w-44 rounded-xl border border-gray-200 bg-white py-1 shadow-lg dark:border-white/10 dark:bg-dark-100`,children:[B&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:ne,disabled:j,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,X.jsx)(F,{className:`h-4 w-4`}),v(`personaCard.backup`)]}),(0,X.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:ie,disabled:j,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,X.jsx)(P,{className:`h-4 w-4`}),v(`personaCard.exportDNA`)]}),V&&V.memory_count>0&&(0,X.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:U,disabled:j,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,X.jsx)(S,{className:`h-4 w-4`}),v(`personaCard.wipeMemories`)]}),(0,X.jsx)(`div`,{className:`my-1 border-t border-gray-100 dark:border-dark-200`})]}),(0,X.jsxs)(`button`,{type:`button`,role:`menuitem`,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,X.jsx)(N,{className:`h-4 w-4`}),v(`common.delete`)]})]})]})]})]})]})]}),k&&(0,X.jsx)(ae,{resourceType:`persona`,resourceId:e.id,resourceLabel:e.name,onClose:()=>A(!1)})]})},le={name:``,description:``,model:``,parameters:{temperature:.7,top_p:.9,top_k:40,context_window:4096,max_tokens:1024,system_prompt:``,repeat_penalty:1.1,presence_penalty:0,frequency_penalty:0},avatar:``,background:``,embedding_model:``,memory_settings:{enabled:!1,max_memories:1e3,auto_cleanup:!0,retention_days:90},mutation_settings:{enabled:!1,sensitivity:`medium`,auto_adapt:!0}};function ue({embeddingModel:e,embeddingModels:t,onEmbeddingModelChange:n}){let{t:i}=r(),a=t.filter(e=>e.isDetectedEmbedding),o=t.filter(e=>!e.isDetectedEmbedding);return(0,X.jsxs)(`div`,{className:`space-y-6`,children:[(0,X.jsxs)(`div`,{className:`rounded-xl p-5 bg-linear-to-br from-primary-50 to-primary-100/50 dark:from-primary-900/30 dark:to-primary-800/20 border border-primary-200/50 dark:border-primary-700/30`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,X.jsx)(T,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`}),(0,X.jsx)(`h3`,{className:`font-semibold text-primary-900 dark:text-primary-100`,children:i(`personaForm.advanced.embeddingModel`)})]}),(0,X.jsx)(`p`,{className:`text-xs text-primary-600 dark:text-primary-400 mb-3`,children:i(`personaForm.advanced.embeddingHint`)}),(0,X.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,X.jsx)(`option`,{value:``,disabled:!0,children:i(`personaForm.advanced.noModels`)}):(0,X.jsxs)(X.Fragment,{children:[a.length>0&&(0,X.jsx)(`optgroup`,{label:i(`personaForm.advanced.embeddingModels`),children:a.map(e=>(0,X.jsxs)(`option`,{value:e.id,children:[e.name,` - `,e.description]},e.id))}),o.length>0&&(0,X.jsx)(`optgroup`,{label:i(`personaForm.advanced.otherModels`),children:o.map(e=>(0,X.jsxs)(`option`,{value:e.id,children:[e.name,` - `,e.description]},e.id))})]})}),t.length===0&&(0,X.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,X.jsxs)(`p`,{className:`text-sm text-ink`,children:[i(`personaForm.advanced.installHint`),` `,(0,X.jsx)(`code`,{className:`rounded-sm bg-amber-500/20 px-1.5 py-0.5 text-xs dark:bg-amber-900/40`,children:`ollama pull nomic-embed-text`})]})}),(0,X.jsx)(`p`,{className:`text-[10px] text-primary-500 dark:text-primary-500 mt-2`,children:i(`personaForm.advanced.recommended`)})]}),(0,X.jsx)(`div`,{className:`p-4 bg-gray-50 dark:bg-dark-50 rounded-xl border border-gray-200 dark:border-dark-300`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,X.jsx)(A,{className:`h-5 w-5 text-gray-400 mt-0.5 shrink-0`}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:i(`personaForm.advanced.aboutTitle`)}),(0,X.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:i(`personaForm.advanced.aboutDescription`)})]})]})})]})}var de=q(`components:persona-background-upload`),fe=({value:e,onChange:t,className:n=``})=>{let{t:i}=r(),a=(0,Y.useRef)(null),[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(!1),u=async e=>{if(!e.type.startsWith(`image/`))h.error(i(`personaBackground.invalidFile`));else if(e.size>5242880)h.error(i(`personaBackground.fileTooLarge`));else{s(!0);try{let n=new FileReader;n.onload=e=>{let n=e.target?.result;t(n),h.success(i(`personaBackground.uploaded`))},n.onerror=()=>{h.error(i(`personaBackground.readFailed`))},n.readAsDataURL(e)}catch(e){de.error(`Failed to upload background:`,e),h.error(i(`personaBackground.uploadFailed`))}finally{s(!1)}}};return(0,X.jsx)(`div`,{className:`space-y-4 ${n}`,children:(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:i(`personaBackground.label`)}),(0,X.jsxs)(`div`,{className:`space-y-3`,children:[e?(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.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,X.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-gray-50 dark:bg-dark-200 rounded-lg`,children:[(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:i(`personaBackground.customBackground`)}),(0,X.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:i(`personaBackground.clickToChange`)})]}),(0,X.jsx)(I,{variant:`ghost`,size:`sm`,onClick:()=>{t(``),h.success(i(`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,X.jsx)(D,{className:`h-4 w-4`})})]})]}):(0,X.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:()=>a.current?.click(),children:[(0,X.jsx)(p,{className:`h-12 w-12 mx-auto text-gray-400 dark:text-gray-500 mb-4`}),(0,X.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-2`,children:i(`personaBackground.uploadBackgroundImage`)}),(0,X.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-4`,children:i(`personaBackground.dragAndDrop`)}),(0,X.jsxs)(I,{variant:`outline`,size:`sm`,disabled:o,className:`mx-auto`,children:[(0,X.jsx)(k,{className:`h-4 w-4 mr-2`}),i(o?`personaBackground.uploading`:`personaBackground.chooseImage`)]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1`,children:i(`personaBackground.enterImageUrl`)}),(0,X.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,X.jsx)(`input`,{ref:a,type:`file`,accept:`image/*`,onChange:e=>{let t=e.target.files?.[0];t&&u(t)},className:`hidden`}),(0,X.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-2`,children:i(`personaBackground.supportedFormats`)})]})})};function pe({formData:e,availableModels:t,onFieldChange:n,onParameterChange:i}){let{t:a}=r(),o=(0,Y.useMemo)(()=>t.filter(e=>!e.isPlugin),[t]),s=(0,Y.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,X.jsxs)(`div`,{className:`space-y-6`,children:[(0,X.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:[a(`personaForm.basic.name`),` *`]}),(0,X.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:a(`personaForm.basic.namePlaceholder`),required:!0})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:[a(`personaForm.basic.model`),` *`]}),(0,X.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,X.jsx)(`option`,{value:``,children:a(`personaForm.basic.selectModel`)}),e.model&&!t.some(t=>t.name===e.model)&&(0,X.jsx)(`option`,{value:e.model,children:e.model}),o.length>0&&(0,X.jsx)(`optgroup`,{label:`Ollama`,children:o.map(e=>(0,X.jsx)(`option`,{value:e.name,children:e.name},e.name))}),s.map(([e,t])=>(0,X.jsx)(`optgroup`,{label:e,children:t.map(e=>(0,X.jsx)(`option`,{value:e.name,children:e.name},e.name))},e))]})]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:a(`personaForm.basic.description`)}),(0,X.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:a(`personaForm.basic.descriptionPlaceholder`)})]}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,X.jsx)(se,{value:e.avatar||``,onChange:e=>n(`avatar`,e)}),(0,X.jsx)(fe,{value:e.background||``,onChange:e=>n(`background`,e)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:a(`personaForm.basic.systemPrompt`)}),(0,X.jsx)(`textarea`,{value:e.parameters.system_prompt,onChange:e=>i(`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:a(`personaForm.basic.systemPromptPlaceholder`)}),(0,X.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-600 mt-2`,children:a(`personaForm.basic.systemPromptHint`)})]})]})}function me({submitting:e,lastSaved:t,onCancel:n,onSave:i}){let{t:a}=r();return(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(I,{type:`button`,variant:`ghost`,onClick:n,disabled:e,className:`text-gray-600 dark:text-gray-400`,children:a(`personaForm.actions.cancel`)}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[t&&(0,X.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,X.jsx)(x,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:a(`personaForm.saved`)})]}),(0,X.jsx)(I,{type:`button`,onClick:i,disabled:e,children:a(e?`personaForm.actions.saving`:`personaForm.actions.save`)})]})]})}var he=q(`components:persona-bindings`),ge=[`web_search`,`search_documents`,`list_documents`,`read_document`,`load_skill`];function _e({bindings:e,onChange:t}){let{t:n}=r(),[i,a]=(0,Y.useState)([]),[o,s]=(0,Y.useState)([]),[c,l]=(0,Y.useState)([]),[u,d]=(0,Y.useState)([]),[f,p]=(0,Y.useState)(!0);(0,Y.useEffect)(()=>{let e=!1;return Promise.all([U.listServers(),ne.list(),G.list(),ie.getCollections()]).then(([t,n,r,i])=>{e||(t.success&&t.data&&a(t.data),n.success&&n.data&&s(n.data),r.success&&r.data&&l(r.data),i.success&&i.data&&d(i.data))}).catch(e=>{he.error(`Failed to load bindable resources:`,e)}).finally(()=>{e||p(!1)}),()=>{e=!0}},[]);let m=n=>t({...e??{},...n}),h=(t,n)=>{let r=e?.[t]??[];m({[t]:r.includes(n)?r.filter(e=>e!==n):[...r,n]})};return f?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-10`,children:(0,X.jsx)(v,{className:`h-5 w-5 animate-spin text-gray-400`})}):(0,X.jsxs)(`div`,{className:`space-y-6`,"data-testid":`persona-bindings-tab`,children:[(0,X.jsx)(Q,{title:n(`personaForm.bindings.toolServers`),hint:n(`personaForm.bindings.toolServersHint`),emptyLabel:n(`personaForm.bindings.noToolServers`),options:i.map(e=>({id:e.id,label:e.name,detail:e.description})),selected:e?.tool_server_ids??[],onToggle:e=>h(`tool_server_ids`,e),testId:`persona-binding-tool-servers`}),(0,X.jsx)(Q,{title:n(`personaForm.bindings.builtinTools`),hint:n(`personaForm.bindings.builtinToolsHint`),emptyLabel:n(`personaForm.bindings.noBuiltinTools`),options:ge.map(e=>({id:e,label:n(`personaForm.bindings.builtin.${e}`),detail:e})),selected:e?.builtin_tools??[],onToggle:e=>h(`builtin_tools`,e),testId:`persona-binding-builtin-tools`}),(0,X.jsx)(Q,{title:n(`personaForm.bindings.skills`),hint:n(`personaForm.bindings.skillsHint`),emptyLabel:n(`personaForm.bindings.noSkills`),options:o.map(e=>({id:e.id,label:e.name,detail:`$${e.slug}`})),selected:e?.skill_ids??[],onToggle:e=>h(`skill_ids`,e),testId:`persona-binding-skills`}),(0,X.jsx)(Q,{title:n(`personaForm.bindings.collections`),hint:n(`personaForm.bindings.collectionsHint`),emptyLabel:n(`personaForm.bindings.noCollections`),options:u.map(e=>({id:e.id,label:e.name})),selected:e?.knowledge_collection_ids??[],onToggle:t=>{let n=e?.knowledge_collection_ids??[];m({knowledge_collection_ids:n.includes(t)?n.filter(e=>e!==t):[...n,t]})},testId:`persona-binding-collections`}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-800`,children:n(`personaForm.bindings.prompt`)}),(0,X.jsx)(`p`,{className:`mb-2 mt-1 text-xs text-gray-500 dark:text-dark-600`,children:n(`personaForm.bindings.promptHint`)}),(0,X.jsxs)(`select`,{value:e?.prompt_id??``,onChange:e=>m({prompt_id:e.target.value||void 0}),"data-testid":`persona-binding-prompt`,"aria-label":n(`personaForm.bindings.prompt`),className:`w-full rounded-lg border border-gray-200 bg-white px-3 py-2.5 text-sm text-gray-900 focus:ring-2 focus:ring-primary-500/20 dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`,children:[(0,X.jsx)(`option`,{value:``,children:n(`personaForm.bindings.noPrompt`)}),c.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.title},e.id))]})]}),(0,X.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-dark-500`,children:n(`personaForm.bindings.version`,{version:e?.version??0})})]})}function Q({title:e,hint:t,emptyLabel:n,options:r,selected:i,onToggle:a,testId:o}){return(0,X.jsxs)(`div`,{"data-testid":o,children:[(0,X.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-800`,children:e}),(0,X.jsx)(`p`,{className:`mb-2 mt-1 text-xs text-gray-500 dark:text-dark-600`,children:t}),r.length===0?(0,X.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,X.jsx)(`div`,{className:`space-y-1`,children:r.map(e=>(0,X.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,X.jsx)(`input`,{type:`checkbox`,checked:i.includes(e.id),onChange:()=>a(e.id),className:`h-4 w-4 rounded-sm border-gray-300 dark:border-dark-400`}),(0,X.jsx)(`span`,{className:`text-sm text-gray-900 dark:text-dark-800`,children:e.label}),e.detail&&(0,X.jsx)(`span`,{className:`truncate text-xs text-gray-400 dark:text-dark-500`,children:e.detail})]},e.id))})]})}var ve=({label:e,value:t,min:n,max:r,step:i,onChange:a,hint:o,format:s=e=>String(e),colorClass:c=`text-gray-700 dark:text-dark-600`})=>{let l=(t-n)/(r-n)*100;return(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,X.jsx)(`label`,{className:K(`block text-sm font-medium`,c),children:e}),(0,X.jsx)(`input`,{type:`number`,min:n,max:r,step:i,value:s(t),onChange:e=>{let t=parseFloat(e.target.value);isNaN(t)||a(Math.min(r,Math.max(n,t)))},className:`w-20 px-2 py-1 text-sm text-right bg-gray-100 dark:bg-dark-200 border border-gray-300 dark:border-dark-300 rounded-sm focus:outline-hidden focus:ring-1 focus:ring-primary-500 dark:text-dark-600`})]}),(0,X.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":`${l}%`}}),o&&(0,X.jsx)(`p`,{className:K(`text-xs mt-1`,c.replace(`700`,`500`).replace(`600`,`400`)),children:o})]})},$=({label:e,checked:t,onChange:n,colorClass:r=`text-gray-700 dark:text-dark-600`})=>(0,X.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,X.jsx)(`div`,{className:K(`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,X.jsx)(`div`,{className:K(`absolute top-0.5 inset-s-0.5 w-4 h-4 rounded-full bg-white shadow-sm transition-transform`,t&&`translate-x-5 rtl:-translate-x-5`)})}),(0,X.jsx)(`span`,{className:K(`text-sm font-medium`,r),children:e})]});function ye({formData:e,persona:t,memoryStatus:n,loadingMemoryStatus:i,wipingMemories:a,onSettingsChange:s,onWipeMemories:c}){let{t:u}=r();return(0,X.jsxs)(`div`,{className:`space-y-6`,children:[(0,X.jsxs)(`div`,{className:`rounded-xl overflow-hidden border border-emerald-200/50 dark:border-emerald-700/30`,children:[(0,X.jsx)(`div`,{className:`px-5 py-4 bg-linear-to-r from-emerald-500 to-teal-500 dark:from-emerald-600 dark:to-teal-600`,children:(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`div`,{className:`w-10 h-10 rounded-lg bg-white/20 flex items-center justify-center`,children:(0,X.jsx)(T,{className:`h-5 w-5 text-white`})}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`font-semibold text-white`,children:u(`personaForm.memory.title`)}),(0,X.jsx)(`p`,{className:`text-xs text-white/80`,children:u(`personaForm.memory.subtitle`)})]})]}),(0,X.jsx)($,{label:``,checked:e.memory_settings?.enabled||!1,onChange:e=>s(`memory_settings`,{enabled:e})})]})}),e.memory_settings?.enabled&&t?.id&&(0,X.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:i?(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-emerald-600 dark:text-emerald-400`,children:[(0,X.jsx)(_,{className:`h-4 w-4 animate-spin`}),u(`personaForm.memory.loading`)]}):n?(0,X.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,X.jsxs)(`div`,{className:`text-center`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,X.jsx)(T,{className:`h-5 w-5`}),n.memory_count.toLocaleString()]}),(0,X.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:u(`personaForm.memory.memories`)})]}),(0,X.jsxs)(`div`,{className:`text-center`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,X.jsx)(o,{className:`h-5 w-5`}),n.size_mb.toFixed(1)]}),(0,X.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:u(`personaForm.memory.mbUsed`)})]}),(0,X.jsxs)(`div`,{className:`text-center`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,X.jsx)(l,{className:`h-5 w-5`}),n.last_backup?new Date(n.last_backup).toLocaleDateString():u(`personaForm.memory.never`)]}),(0,X.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:u(`personaForm.memory.lastBackup`)})]})]}):(0,X.jsx)(`p`,{className:`text-sm text-emerald-600 dark:text-emerald-400`,children:u(`personaForm.memory.noData`)})}),e.memory_settings?.enabled&&(0,X.jsxs)(`div`,{className:`p-5 bg-white dark:bg-dark-100 space-y-4`,children:[(0,X.jsx)(ve,{label:u(`personaForm.memory.maxMemories`),value:e.memory_settings.max_memories,min:100,max:1e4,step:100,hint:u(`personaForm.memory.maxMemoriesHint`),format:e=>e.toLocaleString(),colorClass:`text-emerald-700 dark:text-emerald-300`,onChange:e=>s(`memory_settings`,{max_memories:e})}),(0,X.jsx)(ve,{label:u(`personaForm.memory.retention`),value:e.memory_settings.retention_days,min:7,max:365,step:7,hint:u(`personaForm.memory.retentionHint`),format:e=>`${Math.round(e)} days`,colorClass:`text-emerald-700 dark:text-emerald-300`,onChange:e=>s(`memory_settings`,{retention_days:e})}),(0,X.jsx)($,{label:u(`personaForm.memory.autoCleanup`),checked:e.memory_settings.auto_cleanup,onChange:e=>s(`memory_settings`,{auto_cleanup:e}),colorClass:`text-emerald-700 dark:text-emerald-300`}),t?.id&&n&&n.memory_count>0&&(0,X.jsx)(`div`,{className:`pt-4 border-t border-gray-200 dark:border-dark-300`,children:(0,X.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,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-sm font-medium text-red-700 dark:text-red-300`,children:u(`personaForm.memory.wipeAll`)}),(0,X.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:u(`personaForm.memory.wipeCannot`)})]}),(0,X.jsxs)(`button`,{type:`button`,onClick:c,disabled:a,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:[a?(0,X.jsx)(_,{className:`h-3.5 w-3.5 animate-spin`}):(0,X.jsx)(N,{className:`h-3.5 w-3.5`}),u(a?`personaForm.memory.wiping`:`personaForm.memory.wipeButton`)]})]})})]}),!e.memory_settings?.enabled&&(0,X.jsx)(`div`,{className:`p-5 bg-gray-50 dark:bg-dark-50`,children:(0,X.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 text-center`,children:u(`personaForm.memory.enableHint`)})})]}),(0,X.jsxs)(`div`,{className:`rounded-xl overflow-hidden border border-primary-200/50 dark:border-primary-700/30`,children:[(0,X.jsx)(`div`,{className:`px-5 py-4 bg-primary-600 dark:bg-primary-600`,children:(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`div`,{className:`w-10 h-10 rounded-lg bg-white/20 flex items-center justify-center`,children:(0,X.jsx)(y,{className:`h-5 w-5 text-white`})}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`font-semibold text-white`,children:u(`personaForm.learning.title`)}),(0,X.jsx)(`p`,{className:`text-xs text-white/80`,children:u(`personaForm.learning.subtitle`)})]})]}),(0,X.jsx)($,{label:``,checked:e.mutation_settings?.enabled||!1,onChange:e=>s(`mutation_settings`,{enabled:e})})]})}),e.mutation_settings?.enabled&&(0,X.jsxs)(`div`,{className:`p-5 bg-white dark:bg-dark-100 space-y-5`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-sm font-medium text-primary-700 dark:text-primary-300 mb-3`,children:u(`personaForm.learning.speed`)}),(0,X.jsx)(`div`,{className:`grid grid-cols-3 gap-3`,children:[{level:`low`,icon:M,label:u(`personaForm.learning.slow`),desc:u(`personaForm.learning.slowDesc`)},{level:`medium`,icon:y,label:u(`personaForm.learning.balanced`),desc:u(`personaForm.learning.balancedDesc`)},{level:`high`,icon:m,label:u(`personaForm.learning.fast`),desc:u(`personaForm.learning.fastDesc`)}].map(({level:t,icon:n,label:r,desc:i})=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>s(`mutation_settings`,{sensitivity:t}),className:K(`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,X.jsx)(n,{className:`h-5 w-5 mx-auto mb-1`}),(0,X.jsx)(`p`,{className:`text-sm font-medium`,children:r}),(0,X.jsx)(`p`,{className:`text-[10px] opacity-70`,children:i})]},t))})]}),(0,X.jsx)($,{label:u(`personaForm.learning.autoAdapt`),checked:e.mutation_settings.auto_adapt,onChange:e=>s(`mutation_settings`,{auto_adapt:e}),colorClass:`text-primary-700 dark:text-primary-300`}),(0,X.jsxs)(`div`,{className:`p-4 bg-primary-50 dark:bg-primary-900/20 rounded-xl`,children:[(0,X.jsxs)(`p`,{className:`text-xs font-medium text-primary-700 dark:text-primary-300 mb-2 flex items-center gap-1.5`,children:[(0,X.jsx)(ee,{className:`h-3.5 w-3.5`}),u(`personaForm.learning.whatLearns`)]}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs text-primary-600 dark:text-primary-400`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),u(`personaForm.learning.conversationTone`)]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),u(`personaForm.learning.responseStyle`)]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),u(`personaForm.learning.userPreferences`)]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),u(`personaForm.learning.topicInterests`)]})]})]})]}),!e.mutation_settings?.enabled&&(0,X.jsx)(`div`,{className:`p-5 bg-gray-50 dark:bg-dark-50`,children:(0,X.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 text-center`,children:u(`personaForm.learning.enableHint`)})})]})]})}function be({parameters:e,onParameterChange:t}){let{t:n}=r(),i=(0,Y.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,X.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:i.map(({key:n,label:r,min:i,max:a,step:o,hint:s,format:c})=>(0,X.jsx)(ve,{label:r,value:e[n]||0,min:i,max:a,step:o,hint:s,format:c,onChange:e=>t(n,e)},n))})}var xe=q(`components:persona-form`),Se=({persona:e,onSubmit:t,onCancel:n})=>{let{preferences:o}=oe(),{t:s}=r(),[c,l]=(0,Y.useState)(le),u=J(e=>e.models),d=J(e=>e.loadModels),f=(0,Y.useMemo)(()=>u.filter(e=>!e.isPersona&&!e.isAgent&&!e.isUnavailable&&!e.isLegacySelection),[u]),[p,_]=(0,Y.useState)([]),[v,y]=(0,Y.useState)(!1),[x,S]=(0,Y.useState)(!1),[C,w]=(0,Y.useState)(null),[T,E]=(0,Y.useState)(`basic`),[D,k]=(0,Y.useState)(!1),A=(0,Y.useRef)(!1),j=(0,Y.useCallback)((e,t)=>{l(n=>({...n,[e]:t})),w(null)},[]),M=(0,Y.useCallback)((e,t)=>{l(n=>({...n,parameters:{...n.parameters,[e]:t}})),w(null)},[]),N=(0,Y.useCallback)((e,t)=>{l(n=>({...n,[e]:{...n[e],...t}})),w(null)},[]),P=(0,Y.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,I=!!c.memory_settings?.enabled,L=i(),{data:R=null,isLoading:z}=a({queryKey:[`persona-memory-status`,F],queryFn:async()=>{if(!F)return null;let e=await W.getMemoryStatus(F);return e.success&&e.data?e.data:null},enabled:!!F&&I}),B=()=>L.invalidateQueries({queryKey:[`persona-memory-status`,F]}),V=async()=>{if(e?.id&&confirm(s(`personaForm.memory.wipeConfirm`))){k(!0);try{let t=await W.wipeMemories(e.id);t.success?(h.success(s(`personaForm.memory.wipeSuccess`,{count:t.data?.deleted_count||0})),await B()):h.error(s(`personaForm.error.saveFailed`))}catch{h.error(s(`personaForm.error.saveFailed`))}finally{k(!1)}}};(0,Y.useEffect)(()=>{A.current||(A.current=!0,(async()=>{y(!0);try{let[t,n]=await Promise.all([te.getModels(),e?Promise.resolve(null):W.getDefaultParameters(),J.getState().models.length===0?d({quiet:!0}):Promise.resolve()]),r=P(t.success&&t.data?t.data:[]);_(r);let i=r.find(e=>e.id===o.embeddingSettings?.model||e.rawModel===o.embeddingSettings?.model)?.id||r[0]?.id||``,a=r.find(t=>t.id===e?.embedding_model||t.rawModel===e?.embedding_model)?.id||e?.embedding_model||r[0]?.id||``;if(e)l({name:e.name,description:e.description||``,model:e.model,parameters:e.parameters,avatar:e.avatar||``,background:e.background||``,embedding_model:a,memory_settings:e.memory_settings||le.memory_settings,mutation_settings:e.mutation_settings||le.mutation_settings,bindings:e.bindings}),e.embedding_model&&!r.find(t=>t.id===e.embedding_model||t.rawModel===e.embedding_model)&&_(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:{};l(t=>({...t,parameters:{...t.parameters,...e},embedding_model:i}))}}catch(e){xe.error(`Error loading data:`,e)}finally{y(!1)}})())},[e,P,d,o.embeddingSettings?.model]);let H=async()=>{S(!0);try{let n={name:c.name,description:c.description,model:c.model,parameters:c.parameters,avatar:c.avatar,background:c.background,embedding_model:c.embedding_model,memory_settings:c.memory_settings,mutation_settings:c.mutation_settings,bindings:c.bindings},r=e?await W.updatePersona(e.id,n):await W.createPersona(c);r.success&&r.data?(h.success(s(e?`personaForm.success.updated`:`personaForm.success.created`)),w(new Date),await t(r.data)):h.error(r.error?`${s(`personaForm.error.saveFailed`)}: ${r.error}`:s(`personaForm.error.saveFailed`))}catch(e){h.error(`${s(`personaForm.error.saveFailed`)}: ${e instanceof Error?e.message:String(e)}`)}finally{S(!1)}},U=(0,Y.useMemo)(()=>[{id:`basic`,label:s(`personaForm.tabs.basic`),icon:b},{id:`parameters`,label:s(`personaForm.tabs.parameters`),icon:g},{id:`memory`,label:s(`personaForm.tabs.memory`),icon:m},{id:`bindings`,label:s(`personaForm.tabs.bindings`),icon:O},{id:`advanced`,label:s(`personaForm.tabs.advanced`),icon:ee}],[s]);return v?(0,X.jsx)(`div`,{className:`flex items-center justify-center p-8`,children:(0,X.jsxs)(`div`,{className:`animate-pulse flex items-center gap-3`,children:[(0,X.jsx)(`div`,{className:`w-5 h-5 border-2 border-primary-500 border-t-transparent rounded-full animate-spin`}),(0,X.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:s(`personaForm.loading`)})]})}):(0,X.jsxs)(`div`,{className:`max-w-4xl mx-auto`,children:[(0,X.jsxs)(`div`,{className:`mb-6`,children:[(0,X.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-dark-800`,children:s(e?`personaForm.title.edit`:`personaForm.title.create`)}),(0,X.jsx)(`p`,{className:`mt-1 text-gray-600 dark:text-dark-600`,children:s(e?`personaForm.subtitle.edit`:`personaForm.subtitle.create`)})]}),(0,X.jsxs)(`form`,{onSubmit:e=>e.preventDefault(),className:`space-y-6`,children:[(0,X.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg shadow-xs border border-gray-200 dark:border-dark-300`,children:[(0,X.jsx)(`div`,{role:`tablist`,"aria-label":s(`personaForm.sections`),className:`flex overflow-x-auto border-b border-gray-200 dark:border-dark-300`,onKeyDown:e=>{let t=U.findIndex(e=>e.id===T),n=document.documentElement.dir===`rtl`,r=n?`ArrowLeft`:`ArrowRight`,i=n?`ArrowRight`:`ArrowLeft`,a=-1;e.key===r?a=(t+1)%U.length:e.key===i?a=(t-1+U.length)%U.length:e.key===`Home`?a=0:e.key===`End`&&(a=U.length-1);let o=U[a];o&&(e.preventDefault(),E(o.id),document.getElementById(`persona-tab-${o.id}`)?.focus())},children:U.map(e=>(0,X.jsxs)(`button`,{id:`persona-tab-${e.id}`,type:`button`,role:`tab`,"aria-selected":T===e.id,"aria-controls":`persona-tabpanel`,tabIndex:T===e.id?0:-1,onClick:()=>E(e.id),className:K(`flex shrink-0 items-center gap-2 whitespace-nowrap 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,X.jsx)(e.icon,{className:`h-4 w-4`,"aria-hidden":`true`}),e.label]},e.id))}),(0,X.jsxs)(`div`,{id:`persona-tabpanel`,role:`tabpanel`,"aria-labelledby":`persona-tab-${T}`,className:`p-6`,children:[T===`basic`&&(0,X.jsx)(pe,{formData:c,availableModels:f,onFieldChange:j,onParameterChange:M}),T===`parameters`&&(0,X.jsx)(be,{parameters:c.parameters,onParameterChange:M}),T===`memory`&&(0,X.jsx)(ye,{formData:c,persona:e,memoryStatus:R,loadingMemoryStatus:z,wipingMemories:D,onSettingsChange:N,onWipeMemories:V}),T===`bindings`&&(0,X.jsx)(_e,{bindings:c.bindings,onChange:e=>j(`bindings`,e)}),T===`advanced`&&(0,X.jsx)(ue,{embeddingModel:c.embedding_model,embeddingModels:p,onEmbeddingModelChange:e=>j(`embedding_model`,e)})]})]}),(0,X.jsx)(me,{submitting:x,lastSaved:C,onCancel:n,onSave:H})]})]})},Ce=q(`components:persona-import-export`),we=({personas:e,onImport:t,onClose:n})=>{let{t:i}=r(),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(``),l=async e=>{try{let t=await W.exportPersona(e.id),n=new Blob([JSON.stringify(t,null,2)],{type:`application/json`}),r=URL.createObjectURL(n),a=document.createElement(`a`);a.href=r,a.download=`${e.name}.json`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(r),h.success(i(`personaImportExport.exportSuccess`,{name:e.name}))}catch(e){let t=e instanceof Error?e.message:String(e);h.error(i(`personaImportExport.exportFailed`)+`: `+t)}};return(0,X.jsxs)(`div`,{className:`max-w-4xl mx-auto`,children:[(0,X.jsxs)(`div`,{className:`mb-6`,children:[(0,X.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-dark-800`,children:i(`personaImportExport.title`)}),(0,X.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 mt-1`,children:i(`personaImportExport.description`)})]}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-6`,children:[(0,X.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-6 shadow-xs border border-gray-200 dark:border-dark-300`,children:[(0,X.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 mb-4`,children:i(`personaImportExport.exportPersonas`)}),e.length===0?(0,X.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 text-center py-8`,children:i(`personaImportExport.noPersonasToExport`)}):(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,X.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:i(`personaImportExport.personasAvailable`,{count:e.length})}),(0,X.jsx)(I,{onClick:async()=>{try{let t=e.map(e=>W.exportPersona(e.id)),n=await Promise.all(t),r={personas:n,exportedAt:Date.now(),version:`1.0.0`,count:n.length},a=new Blob([JSON.stringify(r,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),h.success(i(`personaImportExport.exportAllSuccess`,{count:e.length}))}catch(e){let t=e instanceof Error?e.message:String(e);h.error(i(`personaImportExport.exportAllFailed`)+`: `+t)}},variant:`outline`,size:`sm`,className:`px-3 py-1`,children:i(`personaImportExport.exportAll`)})]}),(0,X.jsx)(`div`,{className:`space-y-2 max-h-80 overflow-y-auto`,children:e.map(e=>(0,X.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-gray-50 dark:bg-dark-200 rounded-md`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`img`,{src:re(e,32),alt:e.name,className:`w-8 h-8 rounded-full`,onError:t=>H(t.currentTarget,e.name,32)}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`font-medium text-gray-900 dark:text-dark-800`,children:e.name}),(0,X.jsx)(`div`,{className:`text-sm text-gray-500 dark:text-dark-500`,children:e.model})]})]}),(0,X.jsx)(I,{onClick:()=>l(e),variant:`outline`,size:`sm`,className:`px-3 py-1`,children:i(`common.export`)})]},e.id))})]})]}),(0,X.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-6 shadow-xs border border-gray-200 dark:border-dark-300`,children:[(0,X.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 mb-4`,children:i(`personaImportExport.importPersonas`)}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:i(`personaImportExport.uploadJsonFile`)}),(0,X.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,X.jsx)(`div`,{className:`text-center text-gray-500 dark:text-dark-500`,children:i(`common.or`).toUpperCase()}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:i(`personaImportExport.pasteJsonLabel`)}),(0,X.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:i(`personaImportExport.pasteJsonPlaceholder`)})]}),(0,X.jsx)(I,{onClick:async()=>{if(!s.trim())h.error(i(`personaImportExport.pasteJsonData`));else{o(!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 W.importPersona(r),t++}catch(e){n++,Ce.error(`Failed to import persona:`,e)}t>0?(h.success(i(`personaImportExport.importMultipleSuccess`,{count:t})),n>0&&h.error(i(`personaImportExport.importMultipleFailed`,{count:n}))):h.error(i(`personaImportExport.importNoneFailed`))}else await W.importPersona(e),h.success(i(`personaImportExport.importSuccess`));c(``),t()}catch(e){let t=e instanceof Error?e.message:String(e);h.error(i(`personaImportExport.importFailed`)+`: `+t)}finally{o(!1)}}},disabled:!s.trim()||a,className:`w-full`,children:i(a?`personaImportExport.importing`:`personaImportExport.importButton`)})]})]})]}),(0,X.jsxs)(`div`,{className:`mt-6 bg-gray-50 dark:bg-dark-200 rounded-lg p-4`,children:[(0,X.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-dark-800 mb-2`,children:i(`personaImportExport.expectedFormat`)}),(0,X.jsx)(`pre`,{className:`text-xs text-gray-600 dark:text-dark-600 overflow-x-auto`,children:`{
|
|
2
|
+
"name": "Assistant Name",
|
|
3
|
+
"description": "Brief description of the assistant's personality",
|
|
4
|
+
"model": "model-name:version",
|
|
5
|
+
"params": {
|
|
6
|
+
"temperature": 0.8,
|
|
7
|
+
"top_p": 0.9,
|
|
8
|
+
"context_window": 4096,
|
|
9
|
+
"system_prompt": "You are a helpful assistant with specific traits..."
|
|
10
|
+
},
|
|
11
|
+
"avatar": "/path/to/avatar.png",
|
|
12
|
+
"background": "/path/to/background.png"
|
|
13
|
+
}`})]}),(0,X.jsx)(`div`,{className:`mt-6 flex justify-end`,children:(0,X.jsx)(I,{onClick:n,variant:`outline`,children:i(`common.close`)})})]})},Te=()=>{let{t:e}=r(),t=i(),[n,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(!1),{data:d=[],isLoading:f,isError:p,refetch:m}=a({queryKey:[`personas`],queryFn:async()=>{let e=await W.getPersonas();if(!e.success)throw Error(e.error||`Failed to load personas`);return e.data||[]}}),g=async()=>{await t.invalidateQueries({queryKey:[`personas`]}),await m()},_=()=>{c(null),o(!0)},v=e=>{c(e),o(!0)},y=async t=>{if(confirm(e(`personaManager.deleteConfirm`,{name:t.name})))try{let n=await W.deletePersona(t.id);n.success?(h.success(e(`personaManager.deleteSuccess`,{name:t.name})),await g()):h.error(e(`personaManager.deleteFailed`)+`: `+n.error)}catch(t){let n=t instanceof Error?t.message:String(t);h.error(e(`personaManager.deleteFailed`)+`: `+n)}},b=async t=>{try{await W.downloadPersona(t.id,t.name),h.success(e(`personaManager.downloadSuccess`,{name:t.name}))}catch(t){let n=t instanceof Error?t.message:String(t);h.error(e(`personaManager.downloadFailed`)+`: `+n)}};return f?(0,X.jsx)(L,{label:e(`personaManager.loading`)}):n?(0,X.jsx)(Se,{persona:s,onSubmit:async e=>{c(e),await g()},onCancel:()=>{o(!1),c(null)}}):l?(0,X.jsx)(we,{personas:d,onImport:g,onClose:()=>u(!1)}):(0,X.jsxs)(`div`,{className:`space-y-6`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,X.jsxs)(`div`,{className:`text-sm text-gray-500 dark:text-dark-500`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-900 dark:text-dark-800`,children:e(`personaManager.stats.title`)}),` `,`· `,e(`personaManager.stats.count`,{count:d.length})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsx)(I,{onClick:()=>u(!0),variant:`outline`,className:`px-4`,children:e(`personaManager.importExport`)}),(0,X.jsx)(I,{onClick:_,className:`px-4`,children:e(`personaManager.createButton`)})]})]}),p&&d.length===0?(0,X.jsx)(V,{message:e(`personaManager.loadFailed`),onRetry:()=>void m()}):d.length===0?(0,X.jsx)(z,{icon:j,titleAs:`h3`,title:e(`personaManager.empty.title`),description:e(`personaManager.empty.description`),action:(0,X.jsx)(I,{onClick:_,className:`px-6 py-2`,children:e(`personaManager.empty.button`)})}):(0,X.jsx)(`div`,{className:`grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3`,children:d.map(e=>(0,X.jsx)(ce,{persona:e,onEdit:v,onDelete:y,onDownload:b},e.id))})]})},Ee=()=>{let{t:e}=r();return(0,X.jsxs)(B,{children:[(0,X.jsx)(R,{title:e(`personaManager.title`),description:e(`personaManager.subtitle`)}),(0,X.jsx)(Te,{})]})};export{Ee as PersonasPage,Ee as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{t as r}from"./useQuery-DCqz3UJt.js";import{t as i}from"./useTranslation-D-_KTORQ.js";import{An as a,Cr as o,Dr as s,Kn as c,Q as l,Rt as u,Vn as d,Y as f,dr as p,er as m,g as h,nt as g,s as _,un as v,v as y}from"./ui-vendor-Bac5e8jE.js";import{o as b,s as x}from"./ui-BPtWIxXL.js";import{t as S}from"./Button-BGE6ZJv5.js";import{t as C}from"./client-DIxMEDnJ.js";import{u as w}from"./api-Bje32kcr.js";import{t as T}from"./utils-DsCVr_wG.js";var E=e(t(),1),D={getAnalytics:e=>C.get(`/costs/analytics`,{params:{days:e}}).then(e=>e.data),listTariffs:()=>C.get(`/costs/tariffs`).then(e=>e.data),createTariff:e=>C.post(`/costs/tariffs`,e).then(e=>e.data),deleteTariff:e=>C.delete(`/costs/tariffs/${encodeURIComponent(e)}`).then(()=>void 0),listBudgets:()=>C.get(`/costs/budgets`).then(e=>e.data),createBudget:e=>C.post(`/costs/budgets`,e).then(e=>e.data),deleteBudget:e=>C.delete(`/costs/budgets/${encodeURIComponent(e)}`).then(()=>void 0),exportUrl:e=>`/api/costs/export?days=${e}`,exportCsv:e=>C.get(`/costs/export`,{params:{days:e},responseType:`blob`}).then(e=>e.data)},O=n(),k=e=>new Intl.NumberFormat(void 0,{style:`currency`,currency:`USD`,maximumFractionDigits:e<1?4:2}).format(e),A=`w-full rounded-lg border border-gray-300 bg-white px-2 py-1.5 text-sm dark:border-dark-300 dark:bg-dark-50`,j=({days:e})=>{let{t}=i(),[n,r]=(0,E.useState)(null),[o,c]=(0,E.useState)([]),[l,d]=(0,E.useState)([]),[f,p]=(0,E.useState)(!0),[m,h]=(0,E.useState)(0),[_,v]=(0,E.useState)({pluginId:``,model:``,inputPerMillion:``,outputPerMillion:``,unitPrice:``}),[b,x]=(0,E.useState)({name:``,principalType:`instance`,principalId:``,period:`monthly`,amountUsd:``,mode:`soft`});(0,E.useEffect)(()=>{let n=!1;return Promise.all([D.getAnalytics(e),D.listTariffs(),D.listBudgets()]).then(([e,t,i])=>{n||(e.success&&e.data&&r(e.data),t.success&&t.data&&c(t.data),i.success&&i.data&&d(i.data))}).catch(()=>s.error(t(`costs.loadFailed`))).finally(()=>{n||p(!1)}),()=>{n=!0}},[e,m,t]);let C=e=>{if(!e.trim())return;let t=Number(e);return Number.isFinite(t)?t:void 0},w=async()=>{try{let e=await D.createTariff({pluginId:_.pluginId.trim(),model:_.model.trim()||void 0,inputPerMillion:C(_.inputPerMillion),outputPerMillion:C(_.outputPerMillion),unitPrice:C(_.unitPrice)});if(!e.success)throw Error(e.message);s.success(t(`costs.tariffSaved`)),v({pluginId:``,model:``,inputPerMillion:``,outputPerMillion:``,unitPrice:``}),h(e=>e+1)}catch(e){s.error(e instanceof Error?e.message:t(`costs.saveFailed`))}},T=async()=>{try{let e=await D.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);s.success(t(`costs.budgetSaved`)),x({name:``,principalType:`instance`,principalId:``,period:`monthly`,amountUsd:``,mode:`soft`}),h(e=>e+1)}catch(e){s.error(e instanceof Error?e.message:t(`costs.saveFailed`))}},j=async()=>{try{let t=await D.exportCsv(e),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`libre-webui-costs.csv`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}catch{s.error(t(`costs.exportFailed`))}};return f&&!n?(0,O.jsx)(`div`,{className:`flex justify-center rounded-lg border border-gray-200 bg-white p-6 dark:border-dark-300 dark:bg-dark-100`,children:(0,O.jsx)(u,{className:`h-5 w-5 animate-spin text-gray-400`})}):(0,O.jsxs)(`div`,{className:`space-y-4 rounded-lg border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,"data-testid":`cost-governance-panel`,children:[(0,O.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:t(`costs.title`)}),(0,O.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:t(`costs.description`)})]}),(0,O.jsxs)(S,{size:`sm`,variant:`outline`,onClick:()=>void j(),children:[(0,O.jsx)(a,{className:`mr-1 h-3.5 w-3.5`}),t(`costs.exportCsv`)]})]}),n&&(0,O.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:[(0,O.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,O.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.totalSpend`)}),(0,O.jsx)(`p`,{className:`text-lg font-semibold`,children:k(n.totalUsd)})]}),(0,O.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,O.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.meteredEvents`)}),(0,O.jsx)(`p`,{className:`text-lg font-semibold`,children:n.meteredEvents})]}),(0,O.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,O.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.unmeteredEvents`)}),(0,O.jsx)(`p`,{className:`text-lg font-semibold`,children:n.unmeteredEvents})]}),(0,O.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,O.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.topModel`)}),(0,O.jsx)(`p`,{className:`truncate text-sm font-medium`,children:n.byModel[0]?`${n.byModel[0].model} (${k(n.byModel[0].usd)})`:`—`})]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-gray-500`,children:t(`costs.budgets`)}),(0,O.jsxs)(`div`,{className:`space-y-2`,children:[n?.budgets.map(e=>{let n=Math.min(1,e.spentUsd/e.amountUsd);return(0,O.jsxs)(`div`,{className:`rounded-lg border border-gray-200 p-2 dark:border-dark-300`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-sm`,children:[(0,O.jsxs)(`span`,{className:`min-w-0 truncate font-medium`,children:[e.name,(0,O.jsxs)(`span`,{className:`ml-2 text-xs font-normal text-gray-500`,children:[t(`costs.mode.${e.mode}`),` ·`,` `,t(`costs.period.${e.period}`),` ·`,` `,e.principalType===`instance`?t(`costs.scope.instance`):`${t(`costs.scope.${e.principalType}`)}: ${e.principalId}`]})]}),(0,O.jsxs)(`span`,{className:`shrink-0 text-xs text-gray-600 dark:text-gray-300`,children:[k(e.spentUsd),` / `,k(e.amountUsd)]}),(0,O.jsx)(`button`,{onClick:()=>{D.deleteBudget(e.id).then(()=>h(e=>e+1)).catch(()=>s.error(t(`costs.saveFailed`)))},className:`shrink-0 rounded-sm p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-950/30`,"aria-label":t(`costs.deleteBudget`),children:(0,O.jsx)(y,{className:`h-3.5 w-3.5`})})]}),(0,O.jsx)(`div`,{className:`mt-1 h-1.5 overflow-hidden rounded-sm bg-gray-200 dark:bg-dark-300`,children:(0,O.jsx)(`div`,{className:n>=1?`h-full bg-red-500`:n>=.8?`h-full bg-amber-500`:`h-full bg-emerald-500`,style:{width:`${Math.round(n*100)}%`}})})]},e.id)}),l.length===0&&(0,O.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.noBudgets`)})]}),(0,O.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-2 sm:grid-cols-6`,children:[(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.budgetName`),value:b.name,onChange:e=>x({...b,name:e.target.value})}),(0,O.jsxs)(`select`,{className:A,value:b.principalType,onChange:e=>x({...b,principalType:e.target.value}),children:[(0,O.jsx)(`option`,{value:`instance`,children:t(`costs.scope.instance`)}),(0,O.jsx)(`option`,{value:`user`,children:t(`costs.scope.user`)}),(0,O.jsx)(`option`,{value:`group`,children:t(`costs.scope.group`)})]}),(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.principalId`),value:b.principalId,disabled:b.principalType===`instance`,onChange:e=>x({...b,principalId:e.target.value})}),(0,O.jsxs)(`select`,{className:A,value:b.period,onChange:e=>x({...b,period:e.target.value}),children:[(0,O.jsx)(`option`,{value:`daily`,children:t(`costs.period.daily`)}),(0,O.jsx)(`option`,{value:`weekly`,children:t(`costs.period.weekly`)}),(0,O.jsx)(`option`,{value:`monthly`,children:t(`costs.period.monthly`)})]}),(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsx)(`input`,{className:A,placeholder:`USD`,inputMode:`decimal`,value:b.amountUsd,onChange:e=>x({...b,amountUsd:e.target.value})}),(0,O.jsxs)(`select`,{className:A,value:b.mode,onChange:e=>x({...b,mode:e.target.value}),children:[(0,O.jsx)(`option`,{value:`observe`,children:t(`costs.mode.observe`)}),(0,O.jsx)(`option`,{value:`soft`,children:t(`costs.mode.soft`)}),(0,O.jsx)(`option`,{value:`hard`,children:t(`costs.mode.hard`)})]})]}),(0,O.jsxs)(S,{size:`sm`,onClick:()=>void T(),children:[(0,O.jsx)(g,{className:`mr-1 h-3.5 w-3.5`}),t(`costs.addBudget`)]})]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-gray-500`,children:t(`costs.tariffs`)}),(0,O.jsx)(`div`,{className:`overflow-x-auto`,children:(0,O.jsxs)(`table`,{className:`w-full text-left text-xs`,children:[(0,O.jsx)(`thead`,{className:`text-gray-500`,children:(0,O.jsxs)(`tr`,{children:[(0,O.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.plugin`)}),(0,O.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.model`)}),(0,O.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.inputPerMillion`)}),(0,O.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.outputPerMillion`)}),(0,O.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.unitPrice`)}),(0,O.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.effectiveFrom`)}),(0,O.jsx)(`th`,{})]})}),(0,O.jsxs)(`tbody`,{children:[o.map(e=>(0,O.jsxs)(`tr`,{className:`border-t border-gray-100 dark:border-dark-300`,children:[(0,O.jsx)(`td`,{className:`py-1 pr-2`,children:e.plugin_id}),(0,O.jsx)(`td`,{className:`py-1 pr-2`,children:e.model??t(`costs.allModels`)}),(0,O.jsx)(`td`,{className:`py-1 pr-2`,children:e.input_per_million===null?`—`:k(e.input_per_million)}),(0,O.jsx)(`td`,{className:`py-1 pr-2`,children:e.output_per_million===null?`—`:k(e.output_per_million)}),(0,O.jsx)(`td`,{className:`py-1 pr-2`,children:e.unit_price===null?`—`:k(e.unit_price)}),(0,O.jsx)(`td`,{className:`py-1 pr-2`,children:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}).format(e.effective_from)}),(0,O.jsx)(`td`,{className:`py-1`,children:(0,O.jsx)(`button`,{onClick:()=>{D.deleteTariff(e.id).then(()=>h(e=>e+1)).catch(()=>s.error(t(`costs.saveFailed`)))},className:`rounded-sm p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-950/30`,"aria-label":t(`costs.deleteTariff`),children:(0,O.jsx)(y,{className:`h-3.5 w-3.5`})})})]},e.id)),o.length===0&&(0,O.jsx)(`tr`,{children:(0,O.jsx)(`td`,{colSpan:7,className:`py-2 text-gray-500`,children:t(`costs.noTariffs`)})})]})]})}),(0,O.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-2 sm:grid-cols-6`,children:[(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.plugin`),value:_.pluginId,onChange:e=>v({..._,pluginId:e.target.value})}),(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.modelOptional`),value:_.model,onChange:e=>v({..._,model:e.target.value})}),(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.inputPerMillion`),inputMode:`decimal`,value:_.inputPerMillion,onChange:e=>v({..._,inputPerMillion:e.target.value})}),(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.outputPerMillion`),inputMode:`decimal`,value:_.outputPerMillion,onChange:e=>v({..._,outputPerMillion:e.target.value})}),(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.unitPrice`),inputMode:`decimal`,value:_.unitPrice,onChange:e=>v({..._,unitPrice:e.target.value})}),(0,O.jsxs)(S,{size:`sm`,onClick:()=>void w(),children:[(0,O.jsx)(g,{className:`mr-1 h-3.5 w-3.5`}),t(`costs.addTariff`)]})]})]})]})},M={strands:`Strands`,"claude-code":`Claude Code`,codex:`Codex`,kiro:`Kiro`,muse:`Muse Code`,opencode:`OpenCode`,pi:`Pi`},N=e=>{if(e.startsWith(`agent-cli:`))return e.slice(10)||void 0};function P(e){if(e.agents!==void 0)return e.agents;let t=new Map;for(let n of e.plugins){let e=N(n.pluginId);if(!e)continue;let r=t.get(e)??{agentId:e,agentName:M[e]??n.pluginName,calls:0,tokens:0,errors:0,averageLatencyMs:0,models:[]},i=r.calls+n.calls;r.averageLatencyMs=i?(r.averageLatencyMs*r.calls+n.averageLatencyMs*n.calls)/i:0,r.calls=i,r.tokens+=n.tokens,r.errors+=n.errors,t.set(e,r)}for(let n of e.models){let e=N(n.pluginId),r=e?t.get(e):void 0;if(!r)continue;let i=r.models.find(e=>e.model===n.model);i?(i.calls+=n.calls,i.tokens+=n.tokens,i.errors+=n.errors):r.models.push({model:n.model,calls:n.calls,tokens:n.tokens,errors:n.errors})}return[...t.values()]}var F=[`#3b82f6`,`#059669`,`#db683c`,`#8b5cf6`,`#e11d48`,`#0891b2`,`#a16207`,`#db2777`,`#0d9488`,`#6366f1`,`#65a30d`,`#a855f7`,`#4879a8`,`#9d6c34`,`#c25280`,`#6f7d35`,`#5363bb`],I=`#6b7280`,L=e=>{let t=e*137.508%360,n=e=>{let n=.65*Math.min(e,1-e);return[0,8,4].map(r=>{let i=(r+t/30)%12;return e-n*Math.max(-1,Math.min(i-3,9-i,1))})},r=0,i=1;for(let e=0;e<16;e++){let e=(r+i)/2,t=n(e).map(e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4);t[0]*.2126+t[1]*.7152+t[2]*.0722<.2?r=e:i=e}return`#${n((r+i)/2).map(e=>Math.round(e*255).toString(16).padStart(2,`0`)).join(``)}`},R=e=>e===null?`other`:`model:${e}`;function z(e,t){return e.range.from===t.range.from&&e.range.to===t.range.to&&e.series.length===t.series.length&&e.series.every((e,n)=>{let r=t.series[n];return e.timestamp===r.timestamp&&e.calls===r.calls&&e.tokens===r.tokens&&e.errors===r.errors})}function ee(e){return e.modelSeries?.length?e.modelSeries.map(e=>({...e,key:R(e.model)})):[{key:`total`,model:void 0,points:e.series}]}function te(e){let t=e.heatmap?.models??[],n=(e.modelSeries??[]).flatMap(e=>e.model===null?[]:[e.model]).filter(e=>!t.includes(e)).sort(),r=new Set([...t,...e.heatmap?.cells.flatMap(e=>e.models.map(e=>e.model))??[],...e.modelSeries?.flatMap(e=>e.model===null?[]:[e.model])??[],...e.models.map(e=>e.model)]),i=[...t,...n,...[...r].filter(e=>!t.includes(e)&&!n.includes(e)).sort()],a=new Map([[`other`,I],[`total`,I]]);return i.forEach((e,t)=>{a.set(R(e),F[t]??L(t))}),a}function ne(e,t,n,r){let i=e.models.filter(e=>e.pluginId===t&&(r===void 0||e.pluginName===r)&&e.calls>0).map(({model:e,calls:t})=>({model:e,calls:t})),a=n-i.reduce((e,t)=>e+t.calls,0);return a>0?[...i,{model:null,calls:a}]:i}function re({analytics:e,metric:t,onMetricChange:n,colors:r,highlighted:a,selected:o,loadingModel:s,canLoadModels:c=!1,onHighlight:l,onSelect:u}){let{t:d,i18n:p}=i(),h=(0,E.useMemo)(()=>ee(e),[e]),g=(0,E.useRef)(null),[_,v]=(0,E.useState)(960),[y,b]=(0,E.useState)();(0,E.useEffect)(()=>{let e=g.current;if(!e)return;let t=new ResizeObserver(e=>{v(Math.max(280,e[0].contentRect.width))});return t.observe(e),()=>t.disconnect()},[]);let x=(e,t=!1)=>new Intl.NumberFormat(p.language,{notation:t&&e>=1e4?`compact`:`standard`,maximumFractionDigits:+!!t}).format(e),S=new Intl.DateTimeFormat(p.language,{month:`short`,day:`numeric`,timeZone:`UTC`}),C=e=>e===void 0?d(`usageAnalytics.activity.allModels`):e===null?d(`usageAnalytics.heatmap.other`):e||`—`,w={top:18,right:20,bottom:32,left:48},D=_-w.left-w.right,k=260-w.top-w.bottom,A=Math.max(1,...h.flatMap(e=>e.points.map(e=>e[t]))),j=Math.ceil(A/4)*4,M=e.series.reduce((e,n)=>e+n[t],0),N=t===`tokens`&&M===0,P=t=>w.left+(e.series.length<=1?D/2:t/(e.series.length-1)*D),F=e=>w.top+k-e/j*k,I=e.series.findIndex(e=>e.timestamp===y),L=I<0?Math.max(0,e.series.length-1):I,R=e.series[L],z=h.find(e=>e.key===a),te=[...new Set([0,Math.floor((e.series.length-1)/2),e.series.length-1])].filter(e=>e>=0),ne=h.map(e=>({...e,value:e.points[L]?.[t]??0})).sort((e,t)=>t.value-e.value),re=e=>e.map((e,n)=>`${n===0?`M`:`L`} ${P(n)} ${F(e[t])}`).join(` `);return(0,O.jsxs)(`section`,{"data-testid":`plugin-usage-chart`,"aria-busy":s!==void 0,className:`min-w-0 overflow-hidden rounded-2xl border border-gray-200/80 bg-white/80 shadow-subtle dark:border-white/8 dark:bg-dark-100/75`,children:[(0,O.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3 border-b border-gray-200/70 px-4 py-4 dark:border-white/[0.07] sm:px-5`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:d(`usageAnalytics.activity.title`)}),(0,O.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:d(`usageAnalytics.activity.${t===`calls`?`callsDescription`:`tokensDescription`}`)})]}),(0,O.jsx)(`div`,{className:`inline-flex rounded-xl bg-gray-100 p-1 dark:bg-dark-200/80`,children:[`calls`,`tokens`].map(e=>(0,O.jsx)(`button`,{type:`button`,"aria-pressed":t===e,className:T(`min-h-9 rounded-lg px-3 text-xs font-medium focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500`,t===e?`bg-white text-gray-950 shadow-xs dark:bg-dark-300 dark:text-dark-950`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),onClick:()=>n(e),children:d(`usageAnalytics.metrics.${e}`)},e))})]}),(0,O.jsxs)(`div`,{className:`px-4 pt-4 sm:px-5`,children:[(0,O.jsxs)(`div`,{className:`mb-3 flex min-h-8 flex-wrap items-center justify-between gap-2`,children:[(0,O.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:d(`usageAnalytics.activity.compareHint`)}),(0,O.jsxs)(`button`,{type:`button`,disabled:!o&&!a,className:T(`inline-flex min-h-9 items-center gap-1.5 rounded-lg px-2 text-xs font-medium text-gray-700 hover:bg-gray-100 focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-primary-500 dark:text-dark-800 dark:hover:bg-dark-200`,!o&&!a&&`invisible`),onClick:()=>{u(void 0),l(void 0)},children:[(0,O.jsx)(f,{className:`h-3.5 w-3.5`}),d(`usageAnalytics.activity.showAll`)]})]}),(0,O.jsx)(`div`,{"data-testid":`usage-model-legend`,className:T(`grid gap-2 sm:grid-cols-2 lg:grid-cols-3`,c&&`h-48 content-start overflow-y-auto pe-1`),children:h.map(e=>{let n=a===e.key,i=o===e.key,s=r.get(e.key)??`#6b7280`,c=e.points.reduce((e,n)=>e+n[t],0);return(0,O.jsxs)(`button`,{type:`button`,"aria-pressed":i,"aria-label":C(e.model),title:C(e.model),onMouseEnter:()=>l(e.key),onMouseLeave:()=>l(void 0),onFocus:()=>l(e.key),onBlur:()=>l(void 0),onClick:()=>u(i?void 0:e.key),className:T(`flex min-h-11 min-w-0 items-center gap-2.5 rounded-xl border px-3 py-2 text-start focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500`,n?`border-gray-400 bg-gray-50 dark:border-dark-500 dark:bg-dark-200`:`border-gray-200/70 hover:bg-gray-50 dark:border-white/[0.07] dark:hover:bg-dark-200/70`),children:[(0,O.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-full`,style:{backgroundColor:s},"aria-hidden":`true`}),(0,O.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs font-medium text-gray-800 dark:text-dark-900`,dir:`auto`,children:C(e.model)}),(0,O.jsx)(`span`,{className:`shrink-0 text-xs tabular-nums text-gray-500 dark:text-dark-500`,children:x(c,!0)}),i&&(0,O.jsx)(m,{className:`h-3.5 w-3.5 shrink-0 text-gray-800 dark:text-dark-900`,"aria-hidden":`true`})]},e.key)})}),(c||h.some(e=>e.model===null))&&(0,O.jsx)(`p`,{className:`mt-2 text-[11px] text-gray-500 dark:text-dark-500`,children:d(`usageAnalytics.activity.topModels`)}),h[0]?.model===void 0&&(0,O.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:d(`usageAnalytics.activity.breakdownUnavailable`)})]}),(0,O.jsx)(`div`,{className:`relative mx-3 mt-4 sm:mx-5`,ref:g,children:N?(0,O.jsx)(`div`,{className:`flex h-[260px] items-center justify-center text-sm text-gray-500 dark:text-dark-500`,children:d(`usageAnalytics.activity.noTokens`)}):(0,O.jsxs)(`svg`,{viewBox:`0 0 ${_} 260`,direction:`ltr`,className:`block h-[260px] w-full touch-pan-y`,role:`img`,"aria-label":d(`usageAnalytics.activity.chartLabel`,{metric:d(`usageAnalytics.metrics.${t}`)}),onPointerMove:t=>{let n=t.currentTarget.getBoundingClientRect(),r=(t.clientX-n.left)*_/n.width,i=Math.round(Math.max(0,Math.min(1,(r-w.left)/D))*(e.series.length-1));e.series[i]&&b(e.series[i].timestamp)},children:[(0,O.jsx)(`title`,{children:d(`usageAnalytics.activity.chartLabel`,{metric:d(`usageAnalytics.metrics.${t}`)})}),[0,.25,.5,.75,1].map(e=>{let t=w.top+k*e;return(0,O.jsxs)(`g`,{children:[(0,O.jsx)(`line`,{x1:w.left,x2:_-w.right,y1:t,y2:t,className:`stroke-gray-200 dark:stroke-white/[0.07]`,strokeDasharray:e===1?void 0:`3 6`}),(0,O.jsx)(`text`,{x:w.left-9,y:t+4,textAnchor:`end`,className:`fill-gray-500 text-[11px] dark:fill-dark-500`,children:x(Math.round(j*(1-e)),!0)})]},e)}),R&&(0,O.jsx)(`line`,{x1:P(L),x2:P(L),y1:w.top,y2:260-w.bottom,className:`stroke-gray-300 dark:stroke-dark-400`,strokeDasharray:`3 4`}),[...h].sort((e,t)=>Number(e.key===a)-Number(t.key===a)).map(e=>{let n=e.key===a,i=r.get(e.key)??`#6b7280`,o=e.points[L];return(0,O.jsxs)(`g`,{opacity:a&&!n?.18:1,children:[(0,O.jsx)(`path`,{"data-testid":`usage-model-line`,"data-model":e.model===void 0?`__total__`:e.model??`__other__`,"data-highlighted":n,d:re(e.points),stroke:i,fill:`none`,strokeWidth:n?3.5:2,strokeDasharray:e.model===null?`6 4`:void 0,strokeLinecap:`round`,strokeLinejoin:`round`,vectorEffect:`non-scaling-stroke`,children:(0,O.jsx)(`title`,{children:C(e.model)})}),o&&(0,O.jsx)(`circle`,{cx:P(L),cy:F(o[t]),r:n?5:3.5,fill:i,className:`stroke-white dark:stroke-dark-100`,strokeWidth:`2`})]},e.key)}),te.map(t=>(0,O.jsx)(`text`,{x:P(t),y:252,textAnchor:t===0?`start`:t===e.series.length-1?`end`:`middle`,className:`fill-gray-500 text-[11px] dark:fill-dark-500`,children:S.format(e.series[t].timestamp)},t))]})}),R&&(0,O.jsxs)(`div`,{className:`border-t border-gray-200/70 px-4 py-4 dark:border-white/[0.07] sm:px-5`,children:[(0,O.jsxs)(`label`,{className:`mb-2 flex flex-wrap items-center justify-between gap-2 text-xs text-gray-500 dark:text-dark-500`,children:[(0,O.jsx)(`span`,{children:d(`usageAnalytics.activity.exploreDay`)}),(0,O.jsx)(`span`,{className:`text-gray-800 dark:text-dark-800`,children:S.format(R.timestamp)}),(0,O.jsx)(`input`,{"data-testid":`usage-chart-day-slider`,type:`range`,min:0,max:Math.max(0,e.series.length-1),step:1,value:L,"aria-label":d(`usageAnalytics.activity.exploreDay`),"aria-valuetext":S.format(R.timestamp),onChange:t=>b(e.series[Number(t.target.value)]?.timestamp),className:`h-6 w-full cursor-pointer accent-gray-700 focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-primary-500 dark:accent-gray-300`,dir:`ltr`})]}),(0,O.jsxs)(`div`,{"data-testid":`usage-chart-day-detail`,"aria-live":`polite`,"aria-atomic":`true`,children:[(0,O.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-baseline justify-between gap-2`,children:[(0,O.jsxs)(`span`,{className:`text-xs font-medium text-gray-700 dark:text-dark-800`,children:[d(`usageAnalytics.activity.dayTotal`),` ·`,` `,S.format(R.timestamp)]}),(0,O.jsxs)(`span`,{className:`text-sm font-medium tabular-nums text-gray-950 dark:text-dark-950`,children:[x(R[t]),` `,d(`usageAnalytics.metrics.${t}`)]})]}),(0,O.jsx)(`div`,{className:T(`grid gap-x-5 gap-y-2 sm:grid-cols-2 lg:grid-cols-3`,c&&`max-h-40 overflow-y-auto`),children:ne.map(e=>(0,O.jsxs)(`div`,{"data-model":e.model===void 0?`__total__`:e.model??`__other__`,className:T(`flex min-w-0 items-center gap-2 text-xs`,a===e.key&&`font-medium`),children:[(0,O.jsx)(`span`,{"aria-hidden":`true`,className:`h-2 w-2 shrink-0 rounded-full`,style:{backgroundColor:r.get(e.key)??`#6b7280`}}),(0,O.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-gray-600 dark:text-dark-700`,title:C(e.model),dir:`auto`,children:C(e.model)}),(0,O.jsx)(`span`,{className:`shrink-0 tabular-nums text-gray-900 dark:text-dark-900`,children:x(e.value)})]},e.key))}),(0,O.jsx)(`p`,{className:`mt-3 h-4 truncate text-xs font-medium text-gray-600 dark:text-dark-700`,children:s===void 0?z?d(`usageAnalytics.activity.highlightedModel`,{model:C(z.model)}):d(`usageAnalytics.activity.allModels`):d(`usageAnalytics.activity.loadingModel`,{model:s})})]})]})]})}var B=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),V=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1}),H=e=>e>=1e4?V.format(e):B.format(e),U=e=>e?e<1e3?`${B.format(e)} ms`:`${(e/1e3).toFixed(+(e<1e4))} s`:`—`,W=(e,t)=>e===0?0:(e-t)/e*100,G=864e5,K=10,q=12,J=30,Y=16,ie=`fill-gray-950/6 dark:fill-white/[0.07]`,ae=[0,.35,.55,.75,1],oe=({heatmap:e,colors:t,chartModels:n,focusedModel:r})=>{let{t:a,i18n:o}=i(),[s,c]=(0,E.useState)(null),l=[...new Set([...e.models,...n])],u=e=>e!==void 0&&(l.includes(e)||e===r)?t.get(R(e))??`#6b7280`:I,{weeks:d,firstColStart:f,cellsByDay:p,maxCalls:m,totalCalls:h}=(0,E.useMemo)(()=>{let t=new Map(e.cells.map(e=>[e.timestamp,e])),n=e.from,r=e.from+(e.days-1)*G,i=n-new Date(n).getUTCDay()*G;return{weeks:Math.ceil((r-i+G)/(7*G)),firstColStart:i,cellsByDay:t,maxCalls:Math.max(1,...e.cells.map(e=>e.calls)),totalCalls:e.cells.reduce((e,t)=>e+t.calls,0)}},[e]),g=new Intl.DateTimeFormat(o.language,{month:`short`,timeZone:`UTC`}),_=new Intl.DateTimeFormat(o.language,{weekday:`short`,timeZone:`UTC`}),v=new Intl.DateTimeFormat(o.language,{dateStyle:`medium`,timeZone:`UTC`}),y=e.from,b=e.from+(e.days-1)*G,x=J+d*q,S=[],C=-1;for(let e=0;e<d;e++){let t=f+e*7*G,n=Math.max(t,y),r=new Date(n).getUTCMonth();r!==C&&t>=y-6*G&&((C!==-1||t>=y)&&S.push({x:J+e*q,label:g.format(n)}),C=r)}let w=e=>e<=0?0:Math.min(4,Math.max(1,Math.ceil(e/m*4))),D=e=>u(e.models[0]?.model),k=(e,t,n)=>{let r=e.currentTarget.closest(`[data-heatmap-wrapper]`);if(!r)return;let i=r.getBoundingClientRect(),a=e.currentTarget.getBoundingClientRect(),o=a.left-i.left+a.width/2;c({x:Math.min(Math.max(o,96),Math.max(i.width-96,96)),y:a.top-i.top,timestamp:t,calls:n.calls,models:n.models})};return(0,O.jsxs)(`section`,{"data-testid":`usage-heatmap`,className:`min-w-0 overflow-hidden rounded-2xl border border-gray-200/80 bg-white/80 shadow-subtle backdrop-blur-md dark:border-white/8 dark:bg-dark-100/75`,children:[(0,O.jsxs)(`div`,{className:`flex flex-col gap-1 border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.07] sm:flex-row sm:items-center sm:justify-between sm:px-5`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:a(`usageAnalytics.heatmap.title`)}),(0,O.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:a(`usageAnalytics.heatmap.description`)})]}),(0,O.jsx)(`span`,{className:`shrink-0 text-xs tabular-nums text-gray-500 dark:text-dark-500`,children:a(`usageAnalytics.heatmap.yearTotal`,{count:h,formatted:H(h)})})]}),(0,O.jsxs)(`div`,{className:`relative p-4 sm:px-5`,"data-heatmap-wrapper":!0,children:[(0,O.jsx)(`div`,{className:`overflow-x-auto`,children:(0,O.jsxs)(`svg`,{viewBox:`0 0 ${x} 100`,direction:`ltr`,className:`h-auto w-full min-w-[640px]`,role:`img`,"aria-label":a(`usageAnalytics.heatmap.title`),onMouseLeave:()=>c(null),children:[S.map(({x:e,label:t})=>(0,O.jsx)(`text`,{x:e,y:10,className:`fill-gray-400 text-[8px] dark:fill-dark-500`,children:t},`${e}-${t}`)),[1,3,5].map(e=>(0,O.jsx)(`text`,{x:0,y:Y+e*q+K-2,className:`fill-gray-400 text-[8px] dark:fill-dark-500`,children:_.format(new Date(Date.UTC(2023,0,1+e)))},e)),Array.from({length:d},(e,t)=>Array.from({length:7},(e,n)=>{let r=f+(t*7+n)*G;if(r<y||r>b)return null;let i=p.get(r),a=i?.calls??0,o=w(a);return(0,O.jsx)(`rect`,{x:J+t*q,y:Y+n*q,width:K,height:K,rx:2,"data-model":i?.models[0]?.model,fill:i&&o>0?D(i):void 0,fillOpacity:o===0?1:ae[o],strokeWidth:+(s?.timestamp===r),className:T(`motion-safe:transition-opacity`,(o===0||!i)&&ie,s?.timestamp===r?`stroke-gray-500 dark:stroke-white/60`:`stroke-transparent`),onMouseEnter:e=>k(e,r,{calls:a,models:i?.models??[]}),children:(0,O.jsx)(`title`,{children:`${v.format(r)} — ${H(a)}`})},r)}))]})}),s&&(0,O.jsxs)(`div`,{className:`pointer-events-none absolute z-10 min-w-40 -translate-x-1/2 -translate-y-full rounded-lg border border-gray-200/80 bg-white/95 px-3 py-2 shadow-card backdrop-blur-md dark:border-white/10 dark:bg-dark-100/95`,style:{left:s.x,top:s.y-6},children:[(0,O.jsx)(`div`,{className:`text-[11px] font-medium text-gray-900 dark:text-dark-900`,children:v.format(s.timestamp)}),(0,O.jsx)(`div`,{className:`mt-0.5 text-[11px] text-gray-500 dark:text-dark-500`,children:s.calls===0?a(`usageAnalytics.heatmap.noCalls`):`${H(s.calls)} ${a(`usageAnalytics.heatmap.calls`)}`}),s.models.slice(0,3).map(e=>(0,O.jsxs)(`div`,{className:`mt-1 flex items-center justify-between gap-3 text-[11px]`,children:[(0,O.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,O.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-[3px]`,style:{backgroundColor:u(e.model)}}),(0,O.jsx)(`span`,{className:`truncate font-mono text-gray-700 dark:text-dark-700`,dir:`ltr`,children:e.model})]}),(0,O.jsx)(`span`,{className:`tabular-nums text-gray-500 dark:text-dark-500`,children:H(e.calls)})]},e.model))]}),(0,O.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center justify-between gap-3`,children:[(0,O.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5`,children:[l.map(e=>(0,O.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-gray-600 dark:text-dark-600`,children:[(0,O.jsx)(`span`,{className:`h-2.5 w-2.5 rounded-[3px]`,style:{backgroundColor:t.get(R(e))??`#6b7280`}}),(0,O.jsx)(`span`,{className:`font-mono`,dir:`ltr`,children:e})]},e)),(0,O.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-gray-600 dark:text-dark-600`,children:[(0,O.jsx)(`span`,{className:`h-2.5 w-2.5 rounded-[3px]`,style:{backgroundColor:I}}),a(`usageAnalytics.heatmap.other`)]})]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] text-gray-500 dark:text-dark-500`,children:[a(`usageAnalytics.heatmap.less`),(0,O.jsx)(`span`,{className:`h-2.5 w-2.5 rounded-[3px] bg-gray-950/6 dark:bg-white/[0.07]`}),ae.slice(1).map(e=>(0,O.jsx)(`span`,{className:`h-2.5 w-2.5 rounded-[3px] bg-gray-500`,style:{opacity:e}},e)),a(`usageAnalytics.heatmap.more`)]})]})]})]})},se=({analytics:e})=>{let{t}=i(),n=P(e),r=e=>(e.meteredCalls??0)>0||e.tokens>0;return(0,O.jsxs)(`section`,{"data-testid":`usage-agent-breakdown`,"aria-labelledby":`usage-agent-heading`,className:`rounded-2xl border border-gray-200/80 bg-white/80 p-4 shadow-subtle dark:border-white/8 dark:bg-dark-100/75 sm:p-5`,children:[(0,O.jsxs)(`h2`,{id:`usage-agent-heading`,className:`flex items-center gap-2 text-sm font-medium text-gray-950 dark:text-dark-950`,children:[(0,O.jsx)(p,{className:`h-4 w-4`,"aria-hidden":`true`}),t(`usageAnalytics.agents.title`)]}),(0,O.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.agents.description`)}),e.agents===void 0&&(0,O.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.agents.legacy`)}),(0,O.jsx)(`div`,{className:`mt-4 grid min-w-0 gap-3 sm:grid-cols-2 xl:grid-cols-3`,children:n.map(e=>(0,O.jsxs)(`article`,{"data-agent":e.agentId,className:`min-w-0 rounded-xl border border-gray-200/70 p-3 dark:border-white/[0.07]`,children:[(0,O.jsx)(`h3`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e.agentName}),(0,O.jsxs)(`dl`,{className:`mt-3 grid grid-cols-2 gap-3`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`dt`,{className:`text-[11px] text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.metrics.calls`)}),(0,O.jsx)(`dd`,{"data-agent-metric":`calls`,className:`mt-1 text-lg tabular-nums text-gray-950 dark:text-dark-950`,children:H(e.calls)})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`dt`,{className:`text-[11px] text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.cards.tokens`)}),(0,O.jsx)(`dd`,{"data-agent-metric":`tokens`,className:`mt-1 text-sm tabular-nums text-gray-950 dark:text-dark-950`,children:r(e)?H(e.tokens):e.calls===0?`—`:e.meteredCalls===0?t(`usageAnalytics.agents.unreported`):`—`})]})]}),e.calls===0?(0,O.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.agents.noCalls`)}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:[t(`usageAnalytics.cards.latency`),`:`,` `,(0,O.jsx)(`span`,{className:`tabular-nums`,dir:`ltr`,children:U(e.averageLatencyMs)})]}),e.meteredCalls!==void 0&&e.meteredCalls>0&&(0,O.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.cards.tokensDetail`,{count:e.meteredCalls})}),e.errors>0&&(0,O.jsxs)(`p`,{className:`mt-2 flex items-center gap-1 text-xs text-gray-600 dark:text-dark-600`,children:[(0,O.jsx)(h,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),t(`usageAnalytics.providers.failures`,{count:e.errors})]}),e.models.length>0&&(0,O.jsxs)(`div`,{className:`mt-3`,children:[(0,O.jsx)(`h4`,{className:`text-xs font-medium text-gray-700 dark:text-dark-700`,children:t(`usageAnalytics.agents.topModels`)}),(0,O.jsx)(`div`,{className:`mt-1 max-h-48 overflow-y-auto`,children:(0,O.jsxs)(`table`,{className:`w-full table-fixed text-start text-xs`,children:[(0,O.jsx)(`thead`,{className:`text-gray-500 dark:text-dark-500`,children:(0,O.jsxs)(`tr`,{children:[(0,O.jsx)(`th`,{className:`w-1/2 py-1 text-start font-normal`,children:t(`usageAnalytics.models.model`)}),(0,O.jsx)(`th`,{className:`px-1 py-1 text-end font-normal`,children:t(`usageAnalytics.metrics.calls`)}),(0,O.jsx)(`th`,{className:`py-1 text-end font-normal`,children:t(`usageAnalytics.metrics.tokens`)})]})}),(0,O.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-white/6`,children:e.models.map(e=>(0,O.jsxs)(`tr`,{"data-agent-model":e.model,children:[(0,O.jsx)(`td`,{className:`wrap-break-word py-1.5 pe-2 text-gray-700 dark:text-dark-700`,children:(0,O.jsx)(`span`,{dir:`auto`,children:e.model})}),(0,O.jsx)(`td`,{className:`px-1 py-1.5 text-end tabular-nums`,children:H(e.calls)}),(0,O.jsx)(`td`,{className:`py-1.5 text-end tabular-nums`,children:r(e)?H(e.tokens):`—`})]},e.model))})]})})]})]})]},e.agentId))})]})},X=()=>{let{t:e}=i(),[t,n]=(0,E.useState)(30),[a,s]=(0,E.useState)(`calls`),[f,m]=(0,E.useState)(),[g,y]=(0,E.useState)(),{data:C,error:D,isLoading:k,isFetching:A,refetch:M}=r({queryKey:[`plugin-usage`,t],refetchInterval:2e4,refetchIntervalInBackground:!1,queryFn:async()=>{let n=await w.getUsage(t);if(!n.success||!n.data)throw Error(n.error||e(`usageAnalytics.loadFailed`));return n.data}}),N=(0,E.useMemo)(()=>new Set(C?ee(C).map(e=>e.key):[]),[C]),P=(0,E.useMemo)(()=>new Set([...N,...C?.models.map(e=>R(e.model))??[]]),[N,C]),F=f&&P.has(f)?f:void 0,I=g&&P.has(g)?g:void 0,L=N.has(`other`),B=(L?[I,F].find(e=>e?.startsWith(`model:`)&&!N.has(e)):void 0)?.slice(6),V=r({queryKey:[`plugin-usage`,t,`model`,B,C?.range.to],enabled:B!==void 0,staleTime:3e4,queryFn:async()=>{let n=await w.getUsage(t,B,C?.range.to);if(!n.success||!n.data)throw Error(n.error||e(`usageAnalytics.loadFailed`));return n.data}}),G=C,K=!!C&&!!V.data&&z(C,V.data),q=(0,E.useMemo)(()=>C&&B!==void 0&&K?{...C,modelSeries:V.data.modelSeries}:C,[C,B,K,V.data]),J=(0,E.useRef)(null);(0,E.useEffect)(()=>{B!==void 0&&V.data&&!K&&!A&&J.current!==V.data&&(J.current=V.data,M())},[B,V.data,K,A,M]);let Y=D??(B===void 0?null:V.error),ie=Y?Y instanceof Error?Y.message:e(`usageAnalytics.loadFailed`):null,ae=B!==void 0&&!K&&!Y?B:void 0,X=(0,E.useMemo)(()=>C?te(C):new Map,[C]),ce=(0,E.useMemo)(()=>new Set(q?ee(q).map(e=>e.key):[]),[q]),Z=I??F,le=e=>m(e),Q=e=>{if(C?.modelSeries?.length&&(e!==null||N.has(`other`)))return R(e)},$=G?.totals,ue=(0,E.useMemo)(()=>[{label:e(`usageAnalytics.cards.calls`),value:H($?.calls??0),detail:e(`usageAnalytics.cards.callsDetail`,{count:$?.uniqueUsers??0}),icon:o},{label:e(`usageAnalytics.cards.tokens`),value:H($?.reportedTokens??0),detail:e(`usageAnalytics.cards.coverage`,{percent:$?.calls?($.meteredCalls/$.calls*100).toFixed(1):`0`}),icon:v},{label:e(`usageAnalytics.cards.success`),value:`${W($?.calls??0,($?.failedCalls??0)+($?.cancelledCalls??0)).toFixed(1)}%`,detail:e(`usageAnalytics.cards.successDetail`,{count:$?.failedCalls??0}),icon:c},{label:e(`usageAnalytics.cards.latency`),value:U($?.averageLatencyMs??0),detail:e(`usageAnalytics.cards.latencyDetail`),icon:d}],[e,$]);return k&&!G?(0,O.jsx)(x,{width:`wide`,children:(0,O.jsxs)(`div`,{role:`status`,className:`flex min-h-[50vh] items-center justify-center`,children:[(0,O.jsx)(u,{className:`h-7 w-7 motion-safe:animate-spin text-primary-500`}),(0,O.jsx)(`span`,{className:`sr-only`,children:e(`common.loading`)})]})}):(0,O.jsxs)(x,{width:`wide`,children:[(0,O.jsx)(b,{eyebrow:e(`usageAnalytics.eyebrow`),title:e(`usageAnalytics.title`),description:e(`usageAnalytics.description`),actions:(0,O.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,O.jsx)(`div`,{className:`inline-flex rounded-xl border border-gray-200 bg-white/70 p-1 dark:border-white/8 dark:bg-dark-100/70`,children:[7,30,90].map(r=>(0,O.jsx)(`button`,{type:`button`,className:T(`min-h-9 rounded-lg px-3 py-1.5 text-xs font-medium motion-safe:transition-colors focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-primary-500`,t===r?`bg-gray-950 text-white dark:bg-white dark:text-gray-950`:`text-gray-500 hover:text-gray-900 dark:text-dark-500 dark:hover:text-dark-900`),"aria-pressed":t===r,onClick:()=>{n(r),y(void 0)},children:e(`usageAnalytics.days`,{count:r})},r))}),(0,O.jsxs)(S,{variant:`outline`,size:`sm`,onClick:()=>{M(),B!==void 0&&V.refetch()},disabled:A||B!==void 0&&V.isFetching,children:[(0,O.jsx)(l,{className:T(`h-4 w-4`,A&&`motion-safe:animate-spin`)}),(0,O.jsx)(`span`,{children:e(`usageAnalytics.refresh`)})]})]})}),ie&&(0,O.jsxs)(`div`,{role:`alert`,className:`mb-6 flex items-center gap-3 rounded-2xl border border-error-200 bg-error-50 px-4 py-3 text-sm text-error-700 dark:border-error-900/40 dark:bg-error-900/30 dark:text-error-300`,children:[(0,O.jsx)(h,{className:`h-4 w-4 shrink-0`}),(0,O.jsx)(`span`,{children:ie})]}),!G&&(0,O.jsx)(j,{days:t}),G&&(0,O.jsxs)(`div`,{className:`min-w-0 space-y-4`,children:[(0,O.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-4`,children:ue.map(e=>{let t=e.icon;return(0,O.jsxs)(`section`,{className:`rounded-2xl border border-gray-200/80 bg-white/75 p-4 shadow-subtle backdrop-blur-md dark:border-white/8 dark:bg-dark-100/70`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,O.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-[0.12em] text-gray-500 dark:text-dark-500`,children:e.label}),(0,O.jsx)(t,{className:`h-4 w-4 text-primary-500 dark:text-primary-400`})]}),(0,O.jsx)(`div`,{className:`mt-2 text-2xl font-normal tracking-[-0.04em] text-gray-950 dark:text-dark-950`,children:e.value}),(0,O.jsx)(`p`,{className:`mt-1.5 text-xs text-gray-500 dark:text-dark-500`,children:e.detail})]},e.label)})}),(0,O.jsx)(se,{analytics:G}),(0,O.jsx)(j,{days:t}),G.heatmap&&G.heatmap.cells.length>0&&(0,O.jsx)(oe,{heatmap:G.heatmap,colors:X,focusedModel:Z?.startsWith(`model:`)?Z.slice(6):void 0,chartModels:(C?.modelSeries??[]).flatMap(e=>e.model===null?[]:[e.model])}),(0,O.jsx)(re,{analytics:q??G,metric:a,onMetricChange:s,colors:X,highlighted:Z,selected:F,onHighlight:y,onSelect:le,loadingModel:ae,canLoadModels:L}),G.totals.calls===0?(0,O.jsxs)(`div`,{className:`rounded-2xl border border-dashed border-gray-300 px-6 py-10 text-center dark:border-white/12`,children:[(0,O.jsx)(p,{className:`mx-auto h-8 w-8 text-gray-400 dark:text-dark-500`}),(0,O.jsx)(`h2`,{className:`mt-4 text-base font-medium text-gray-900 dark:text-dark-900`,children:e(`usageAnalytics.empty.title`)}),(0,O.jsx)(`p`,{className:`mx-auto mt-2 max-w-md text-sm leading-6 text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.empty.description`)})]}):(0,O.jsxs)(`div`,{className:`grid min-w-0 gap-4 xl:grid-cols-[minmax(0,1.15fr)_minmax(0,0.85fr)]`,children:[(0,O.jsxs)(`section`,{className:`min-w-0 overflow-hidden rounded-2xl border border-gray-200/80 bg-white/80 shadow-subtle backdrop-blur-md dark:border-white/8 dark:bg-dark-100/75`,children:[(0,O.jsxs)(`div`,{className:`border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.07] sm:px-5`,children:[(0,O.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e(`usageAnalytics.models.title`)}),(0,O.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.models.description`)})]}),(0,O.jsx)(`div`,{className:`overflow-x-auto`,children:(0,O.jsxs)(`table`,{"data-testid":`usage-model-table`,className:`w-full min-w-[620px] text-start text-sm`,children:[(0,O.jsx)(`thead`,{className:`text-[11px] uppercase tracking-widest text-gray-400 dark:text-dark-500`,children:(0,O.jsxs)(`tr`,{children:[(0,O.jsx)(`th`,{className:`px-5 py-2 text-start font-medium`,children:e(`usageAnalytics.models.model`)}),(0,O.jsx)(`th`,{className:`px-4 py-2 text-end font-medium`,children:e(`usageAnalytics.metrics.calls`)}),(0,O.jsx)(`th`,{className:`px-4 py-2 text-end font-medium`,children:e(`usageAnalytics.metrics.tokens`)}),(0,O.jsx)(`th`,{className:`px-4 py-2 text-end font-medium`,children:e(`usageAnalytics.models.success`)}),(0,O.jsx)(`th`,{className:`px-5 py-2 text-end font-medium`,children:e(`usageAnalytics.models.latency`)})]})}),(0,O.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-white/6`,children:G.models.map(t=>(0,O.jsxs)(`tr`,{"data-testid":`usage-model-row`,"data-model":t.model,"data-highlighted":Z===Q(t.model),onMouseEnter:()=>y(Q(t.model)),onMouseLeave:()=>y(void 0),className:T(Z===Q(t.model)&&Z&&`bg-gray-50 dark:bg-dark-200/70`),children:[(0,O.jsxs)(`td`,{className:`px-5 py-2.5`,children:[(0,O.jsxs)(`button`,{type:`button`,disabled:!Q(t.model),"aria-label":e(`usageAnalytics.activity.highlightModel`,{model:t.model}),"aria-pressed":!!F&&F===Q(t.model),className:`flex min-h-9 max-w-[260px] items-center gap-2 rounded-md text-start font-medium text-gray-900 focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500 dark:text-dark-900`,title:ce.has(R(t.model))?t.model:e(`usageAnalytics.models.notCharted`),onFocus:()=>y(Q(t.model)),onBlur:()=>y(void 0),onClick:()=>le(F===Q(t.model)?void 0:Q(t.model)),children:[(0,O.jsx)(`span`,{"aria-hidden":`true`,className:`h-2.5 w-2.5 shrink-0 rounded-full`,style:{backgroundColor:X.get(R(t.model))??`#6b7280`}}),(0,O.jsx)(`span`,{className:`truncate`,dir:`ltr`,children:t.model})]}),(0,O.jsx)(`div`,{className:`mt-0.5 text-xs text-gray-500 dark:text-dark-500`,children:t.pluginName})]}),(0,O.jsxs)(`td`,{className:`px-4 py-2.5 text-end tabular-nums text-gray-700 dark:text-dark-700`,children:[H(t.calls),(0,O.jsxs)(`div`,{className:`mt-1 text-[11px] text-gray-500 dark:text-dark-500`,title:e(`usageAnalytics.models.share`),children:[(t.calls/G.totals.calls*100).toFixed(1),`%`]})]}),(0,O.jsx)(`td`,{className:`px-4 py-2.5 text-end tabular-nums text-gray-700 dark:text-dark-700`,children:t.tokens?H(t.tokens):`—`}),(0,O.jsxs)(`td`,{className:`px-4 py-2.5 text-end tabular-nums text-gray-700 dark:text-dark-700`,children:[W(t.calls,t.errors).toFixed(1),`%`]}),(0,O.jsx)(`td`,{className:`px-5 py-2.5 text-end tabular-nums text-gray-500 dark:text-dark-500`,children:U(t.averageLatencyMs)})]},JSON.stringify([t.pluginId,t.pluginName,t.model])))})]})})]}),(0,O.jsxs)(`div`,{className:`min-w-0 space-y-4`,children:[(0,O.jsxs)(`section`,{"data-testid":`usage-provider-breakdown`,className:`min-w-0 rounded-2xl border border-gray-200/80 bg-white/80 p-4 shadow-subtle dark:border-white/8 dark:bg-dark-100/75 sm:p-5`,children:[(0,O.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e(`usageAnalytics.providers.title`)}),(0,O.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.providers.description`)}),(0,O.jsx)(`div`,{className:`mt-4 divide-y divide-gray-200/70 dark:divide-white/[0.07]`,children:G.plugins.map(t=>{let n=G.totals.calls?t.calls/G.totals.calls*100:0,r=ne(G,t.pluginId,t.calls,t.pluginName);return(0,O.jsxs)(`article`,{"data-provider":t.pluginId,className:`py-4 first:pt-0 last:pb-0`,children:[(0,O.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,O.jsxs)(`div`,{className:`min-w-0`,children:[(0,O.jsx)(`h3`,{className:`truncate text-sm font-medium text-gray-900 dark:text-dark-900`,title:t.pluginName,children:t.pluginName}),(0,O.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.providers.share`,{percent:n.toFixed(1)})})]}),(0,O.jsxs)(`div`,{className:`shrink-0 text-end`,children:[(0,O.jsx)(`div`,{className:`text-base font-medium tabular-nums text-gray-950 dark:text-dark-950`,children:H(t.calls)}),(0,O.jsx)(`div`,{className:`text-[11px] text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.metrics.calls`)})]})]}),(0,O.jsx)(`div`,{className:`my-3 flex h-2 overflow-hidden rounded-full bg-gray-100 dark:bg-dark-300`,"aria-hidden":`true`,children:r.map(n=>(0,O.jsx)(`span`,{"data-model":n.model??`__other__`,title:`${n.model??e(`usageAnalytics.heatmap.other`)}: ${H(n.calls)}`,style:{width:`${t.calls?n.calls/t.calls*100:0}%`,backgroundColor:X.get(R(n.model))??`#6b7280`,opacity:Z&&Z!==Q(n.model)?.25:1}},R(n.model)))}),(0,O.jsxs)(`dl`,{className:`grid grid-cols-3 gap-2`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`dt`,{className:`text-[10px] text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.metrics.tokens`)}),(0,O.jsx)(`dd`,{className:`mt-1 text-xs tabular-nums text-gray-800 dark:text-dark-800`,title:t.tokens?void 0:e(`usageAnalytics.providers.noTokens`),children:t.tokens?H(t.tokens):`—`})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`dt`,{className:`text-[10px] text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.models.success`)}),(0,O.jsxs)(`dd`,{className:`mt-1 text-xs tabular-nums text-gray-800 dark:text-dark-800`,children:[W(t.calls,t.errors).toFixed(1),`%`]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`dt`,{className:`text-[10px] text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.models.latency`)}),(0,O.jsx)(`dd`,{className:`mt-1 text-xs tabular-nums text-gray-800 dark:text-dark-800`,children:U(t.averageLatencyMs)})]})]}),t.errors>0&&(0,O.jsxs)(`p`,{className:`mt-2 flex items-center gap-1 text-[11px] text-gray-500 dark:text-dark-500`,children:[(0,O.jsx)(h,{className:`h-3 w-3`}),e(`usageAnalytics.providers.failures`,{count:t.errors})]}),(0,O.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:r.map(t=>{let n=Q(t.model),r=t.model??e(`usageAnalytics.heatmap.other`);return(0,O.jsxs)(`button`,{type:`button`,disabled:!n,"aria-label":e(`usageAnalytics.activity.highlightModel`,{model:r}),"aria-pressed":!!F&&F===n,title:r,onMouseEnter:()=>y(n),onMouseLeave:()=>y(void 0),onFocus:()=>y(n),onBlur:()=>y(void 0),onClick:()=>le(F===n?void 0:n),className:T(`flex min-h-8 min-w-0 max-w-full items-center gap-1.5 rounded-md border px-2 py-1 text-[11px] text-gray-600 focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-primary-500 dark:text-dark-700`,Z&&Z===n?`border-gray-400 bg-gray-50 dark:border-dark-500 dark:bg-dark-200`:`border-gray-200/70 dark:border-white/[0.07]`),children:[(0,O.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-full`,style:{backgroundColor:X.get(R(t.model))??`#6b7280`},"aria-hidden":`true`}),(0,O.jsx)(`span`,{className:`truncate`,dir:`auto`,children:r})]},R(t.model))})})]},JSON.stringify([t.pluginId,t.pluginName]))})})]}),(0,O.jsxs)(`section`,{className:`rounded-2xl border border-gray-200/80 bg-white/80 p-4 shadow-subtle backdrop-blur-md dark:border-white/8 dark:bg-dark-100/75 sm:p-5`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(_,{className:`h-4 w-4 text-primary-500 dark:text-primary-400`}),(0,O.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e(`usageAnalytics.capabilities.title`)})]}),(0,O.jsx)(`div`,{className:`mt-5 grid grid-cols-2 gap-3`,children:G.capabilities.map(t=>(0,O.jsxs)(`div`,{className:`rounded-xl bg-gray-50 px-3 py-2.5 dark:bg-dark-200/70`,children:[(0,O.jsx)(`div`,{className:`text-xs font-medium capitalize text-gray-500 dark:text-dark-500`,children:t.capability}),(0,O.jsx)(`div`,{className:`mt-1 text-xl text-gray-950 dark:text-dark-950`,children:H(t.calls)}),(0,O.jsx)(`div`,{className:`mt-1 text-[11px] text-gray-500 dark:text-dark-500`,children:t.capability===`tts`?e(`usageAnalytics.capabilities.characters`,{count:H(t.inputUnits)}):t.capability===`stt`?e(`usageAnalytics.capabilities.bytes`,{count:H(t.inputUnits)}):t.capability===`image`?e(`usageAnalytics.capabilities.images`,{count:H(t.outputUnits)}):t.capability===`video`?e(`usageAnalytics.capabilities.jobs`,{count:H(t.calls)}):t.capability===`embedding`?e(`usageAnalytics.capabilities.inputs`,{count:H(t.inputUnits)}):e(`usageAnalytics.capabilities.reportedTokens`,{count:H(t.tokens)})})]},t.capability))})]})]})]}),(0,O.jsx)(`p`,{className:`px-1 text-xs leading-5 text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.privacyNote`)})]})]})};export{X as default};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{t as r}from"./useQuery-Cs76KYuP.js";import{t as i}from"./useTranslation-CKqEdZ8j.js";import{An as a,Cr as o,Dr as s,Kn as c,Q as l,Rt as u,Vn as d,Y as f,dr as p,er as m,g as h,s as g,tt as _,un as v,v as y}from"./ui-vendor-DsURZnZt.js";import{o as b,s as x}from"./ui-DxaHE9GD.js";import{t as S}from"./Button-D6d7HYoa.js";import{t as C}from"./client-DxPoTB_C.js";import{u as w}from"./api-Dasm8tVY.js";import{t as T}from"./utils-BXRzbHJC.js";var E=e(t(),1),D={getAnalytics:e=>C.get(`/costs/analytics`,{params:{days:e}}).then(e=>e.data),listTariffs:()=>C.get(`/costs/tariffs`).then(e=>e.data),createTariff:e=>C.post(`/costs/tariffs`,e).then(e=>e.data),deleteTariff:e=>C.delete(`/costs/tariffs/${encodeURIComponent(e)}`).then(()=>void 0),listBudgets:()=>C.get(`/costs/budgets`).then(e=>e.data),createBudget:e=>C.post(`/costs/budgets`,e).then(e=>e.data),deleteBudget:e=>C.delete(`/costs/budgets/${encodeURIComponent(e)}`).then(()=>void 0),exportUrl:e=>`/api/costs/export?days=${e}`,exportCsv:e=>C.get(`/costs/export`,{params:{days:e},responseType:`blob`}).then(e=>e.data)},O=n(),k=e=>new Intl.NumberFormat(void 0,{style:`currency`,currency:`USD`,maximumFractionDigits:e<1?4:2}).format(e),A=`w-full rounded-lg border border-gray-300 bg-white px-2 py-1.5 text-sm dark:border-dark-300 dark:bg-dark-50`,j=({days:e})=>{let{t}=i(),[n,r]=(0,E.useState)(null),[o,c]=(0,E.useState)([]),[l,d]=(0,E.useState)([]),[f,p]=(0,E.useState)(!0),[m,h]=(0,E.useState)(0),[g,v]=(0,E.useState)({pluginId:``,model:``,inputPerMillion:``,outputPerMillion:``,unitPrice:``}),[b,x]=(0,E.useState)({name:``,principalType:`instance`,principalId:``,period:`monthly`,amountUsd:``,mode:`soft`});(0,E.useEffect)(()=>{let n=!1;return Promise.all([D.getAnalytics(e),D.listTariffs(),D.listBudgets()]).then(([e,t,i])=>{n||(e.success&&e.data&&r(e.data),t.success&&t.data&&c(t.data),i.success&&i.data&&d(i.data))}).catch(()=>s.error(t(`costs.loadFailed`))).finally(()=>{n||p(!1)}),()=>{n=!0}},[e,m,t]);let C=e=>{if(!e.trim())return;let t=Number(e);return Number.isFinite(t)?t:void 0},w=async()=>{try{let e=await D.createTariff({pluginId:g.pluginId.trim(),model:g.model.trim()||void 0,inputPerMillion:C(g.inputPerMillion),outputPerMillion:C(g.outputPerMillion),unitPrice:C(g.unitPrice)});if(!e.success)throw Error(e.message);s.success(t(`costs.tariffSaved`)),v({pluginId:``,model:``,inputPerMillion:``,outputPerMillion:``,unitPrice:``}),h(e=>e+1)}catch(e){s.error(e instanceof Error?e.message:t(`costs.saveFailed`))}},T=async()=>{try{let e=await D.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);s.success(t(`costs.budgetSaved`)),x({name:``,principalType:`instance`,principalId:``,period:`monthly`,amountUsd:``,mode:`soft`}),h(e=>e+1)}catch(e){s.error(e instanceof Error?e.message:t(`costs.saveFailed`))}},j=async()=>{try{let t=await D.exportCsv(e),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`libre-webui-costs.csv`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}catch{s.error(t(`costs.exportFailed`))}};return f&&!n?(0,O.jsx)(`div`,{className:`flex justify-center rounded-lg border border-gray-200 bg-white p-6 dark:border-dark-300 dark:bg-dark-100`,children:(0,O.jsx)(u,{className:`h-5 w-5 animate-spin text-gray-400`})}):(0,O.jsxs)(`div`,{className:`space-y-4 rounded-lg border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,"data-testid":`cost-governance-panel`,children:[(0,O.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:t(`costs.title`)}),(0,O.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:t(`costs.description`)})]}),(0,O.jsxs)(S,{size:`sm`,variant:`outline`,onClick:()=>void j(),children:[(0,O.jsx)(a,{className:`mr-1 h-3.5 w-3.5`}),t(`costs.exportCsv`)]})]}),n&&(0,O.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:[(0,O.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,O.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.totalSpend`)}),(0,O.jsx)(`p`,{className:`text-lg font-semibold`,children:k(n.totalUsd)})]}),(0,O.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,O.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.meteredEvents`)}),(0,O.jsx)(`p`,{className:`text-lg font-semibold`,children:n.meteredEvents})]}),(0,O.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,O.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.unmeteredEvents`)}),(0,O.jsx)(`p`,{className:`text-lg font-semibold`,children:n.unmeteredEvents})]}),(0,O.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,O.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.topModel`)}),(0,O.jsx)(`p`,{className:`truncate text-sm font-medium`,children:n.byModel[0]?`${n.byModel[0].model} (${k(n.byModel[0].usd)})`:`—`})]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-gray-500`,children:t(`costs.budgets`)}),(0,O.jsxs)(`div`,{className:`space-y-2`,children:[n?.budgets.map(e=>{let n=Math.min(1,e.spentUsd/e.amountUsd);return(0,O.jsxs)(`div`,{className:`rounded-lg border border-gray-200 p-2 dark:border-dark-300`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-sm`,children:[(0,O.jsxs)(`span`,{className:`min-w-0 truncate font-medium`,children:[e.name,(0,O.jsxs)(`span`,{className:`ml-2 text-xs font-normal text-gray-500`,children:[t(`costs.mode.${e.mode}`),` ·`,` `,t(`costs.period.${e.period}`),` ·`,` `,e.principalType===`instance`?t(`costs.scope.instance`):`${t(`costs.scope.${e.principalType}`)}: ${e.principalId}`]})]}),(0,O.jsxs)(`span`,{className:`shrink-0 text-xs text-gray-600 dark:text-gray-300`,children:[k(e.spentUsd),` / `,k(e.amountUsd)]}),(0,O.jsx)(`button`,{onClick:()=>{D.deleteBudget(e.id).then(()=>h(e=>e+1)).catch(()=>s.error(t(`costs.saveFailed`)))},className:`shrink-0 rounded-sm p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-950/30`,"aria-label":t(`costs.deleteBudget`),children:(0,O.jsx)(y,{className:`h-3.5 w-3.5`})})]}),(0,O.jsx)(`div`,{className:`mt-1 h-1.5 overflow-hidden rounded-sm bg-gray-200 dark:bg-dark-300`,children:(0,O.jsx)(`div`,{className:n>=1?`h-full bg-red-500`:n>=.8?`h-full bg-amber-500`:`h-full bg-emerald-500`,style:{width:`${Math.round(n*100)}%`}})})]},e.id)}),l.length===0&&(0,O.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.noBudgets`)})]}),(0,O.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-2 sm:grid-cols-6`,children:[(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.budgetName`),value:b.name,onChange:e=>x({...b,name:e.target.value})}),(0,O.jsxs)(`select`,{className:A,value:b.principalType,onChange:e=>x({...b,principalType:e.target.value}),children:[(0,O.jsx)(`option`,{value:`instance`,children:t(`costs.scope.instance`)}),(0,O.jsx)(`option`,{value:`user`,children:t(`costs.scope.user`)}),(0,O.jsx)(`option`,{value:`group`,children:t(`costs.scope.group`)})]}),(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.principalId`),value:b.principalId,disabled:b.principalType===`instance`,onChange:e=>x({...b,principalId:e.target.value})}),(0,O.jsxs)(`select`,{className:A,value:b.period,onChange:e=>x({...b,period:e.target.value}),children:[(0,O.jsx)(`option`,{value:`daily`,children:t(`costs.period.daily`)}),(0,O.jsx)(`option`,{value:`weekly`,children:t(`costs.period.weekly`)}),(0,O.jsx)(`option`,{value:`monthly`,children:t(`costs.period.monthly`)})]}),(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsx)(`input`,{className:A,placeholder:`USD`,inputMode:`decimal`,value:b.amountUsd,onChange:e=>x({...b,amountUsd:e.target.value})}),(0,O.jsxs)(`select`,{className:A,value:b.mode,onChange:e=>x({...b,mode:e.target.value}),children:[(0,O.jsx)(`option`,{value:`observe`,children:t(`costs.mode.observe`)}),(0,O.jsx)(`option`,{value:`soft`,children:t(`costs.mode.soft`)}),(0,O.jsx)(`option`,{value:`hard`,children:t(`costs.mode.hard`)})]})]}),(0,O.jsxs)(S,{size:`sm`,onClick:()=>void T(),children:[(0,O.jsx)(_,{className:`mr-1 h-3.5 w-3.5`}),t(`costs.addBudget`)]})]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-gray-500`,children:t(`costs.tariffs`)}),(0,O.jsx)(`div`,{className:`overflow-x-auto`,children:(0,O.jsxs)(`table`,{className:`w-full text-left text-xs`,children:[(0,O.jsx)(`thead`,{className:`text-gray-500`,children:(0,O.jsxs)(`tr`,{children:[(0,O.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.plugin`)}),(0,O.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.model`)}),(0,O.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.inputPerMillion`)}),(0,O.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.outputPerMillion`)}),(0,O.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.unitPrice`)}),(0,O.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.effectiveFrom`)}),(0,O.jsx)(`th`,{})]})}),(0,O.jsxs)(`tbody`,{children:[o.map(e=>(0,O.jsxs)(`tr`,{className:`border-t border-gray-100 dark:border-dark-300`,children:[(0,O.jsx)(`td`,{className:`py-1 pr-2`,children:e.plugin_id}),(0,O.jsx)(`td`,{className:`py-1 pr-2`,children:e.model??t(`costs.allModels`)}),(0,O.jsx)(`td`,{className:`py-1 pr-2`,children:e.input_per_million===null?`—`:k(e.input_per_million)}),(0,O.jsx)(`td`,{className:`py-1 pr-2`,children:e.output_per_million===null?`—`:k(e.output_per_million)}),(0,O.jsx)(`td`,{className:`py-1 pr-2`,children:e.unit_price===null?`—`:k(e.unit_price)}),(0,O.jsx)(`td`,{className:`py-1 pr-2`,children:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}).format(e.effective_from)}),(0,O.jsx)(`td`,{className:`py-1`,children:(0,O.jsx)(`button`,{onClick:()=>{D.deleteTariff(e.id).then(()=>h(e=>e+1)).catch(()=>s.error(t(`costs.saveFailed`)))},className:`rounded-sm p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-950/30`,"aria-label":t(`costs.deleteTariff`),children:(0,O.jsx)(y,{className:`h-3.5 w-3.5`})})})]},e.id)),o.length===0&&(0,O.jsx)(`tr`,{children:(0,O.jsx)(`td`,{colSpan:7,className:`py-2 text-gray-500`,children:t(`costs.noTariffs`)})})]})]})}),(0,O.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-2 sm:grid-cols-6`,children:[(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.plugin`),value:g.pluginId,onChange:e=>v({...g,pluginId:e.target.value})}),(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.modelOptional`),value:g.model,onChange:e=>v({...g,model:e.target.value})}),(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.inputPerMillion`),inputMode:`decimal`,value:g.inputPerMillion,onChange:e=>v({...g,inputPerMillion:e.target.value})}),(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.outputPerMillion`),inputMode:`decimal`,value:g.outputPerMillion,onChange:e=>v({...g,outputPerMillion:e.target.value})}),(0,O.jsx)(`input`,{className:A,placeholder:t(`costs.unitPrice`),inputMode:`decimal`,value:g.unitPrice,onChange:e=>v({...g,unitPrice:e.target.value})}),(0,O.jsxs)(S,{size:`sm`,onClick:()=>void w(),children:[(0,O.jsx)(_,{className:`mr-1 h-3.5 w-3.5`}),t(`costs.addTariff`)]})]})]})]})},M={strands:`Strands`,"claude-code":`Claude Code`,codex:`Codex`,kiro:`Kiro`,muse:`Muse Code`,opencode:`OpenCode`,pi:`Pi`},N=e=>{if(e.startsWith(`agent-cli:`))return e.slice(10)||void 0};function P(e){if(e.agents!==void 0)return e.agents;let t=new Map;for(let n of e.plugins){let e=N(n.pluginId);if(!e)continue;let r=t.get(e)??{agentId:e,agentName:M[e]??n.pluginName,calls:0,tokens:0,errors:0,averageLatencyMs:0,models:[]},i=r.calls+n.calls;r.averageLatencyMs=i?(r.averageLatencyMs*r.calls+n.averageLatencyMs*n.calls)/i:0,r.calls=i,r.tokens+=n.tokens,r.errors+=n.errors,t.set(e,r)}for(let n of e.models){let e=N(n.pluginId),r=e?t.get(e):void 0;if(!r)continue;let i=r.models.find(e=>e.model===n.model);i?(i.calls+=n.calls,i.tokens+=n.tokens,i.errors+=n.errors):r.models.push({model:n.model,calls:n.calls,tokens:n.tokens,errors:n.errors})}return[...t.values()]}var F=[`#3b82f6`,`#059669`,`#db683c`,`#8b5cf6`,`#e11d48`,`#0891b2`,`#a16207`,`#db2777`,`#0d9488`,`#6366f1`,`#65a30d`,`#a855f7`,`#4879a8`,`#9d6c34`,`#c25280`,`#6f7d35`,`#5363bb`],I=`#6b7280`,L=e=>{let t=e*137.508%360,n=e=>{let n=.65*Math.min(e,1-e);return[0,8,4].map(r=>{let i=(r+t/30)%12;return e-n*Math.max(-1,Math.min(i-3,9-i,1))})},r=0,i=1;for(let e=0;e<16;e++){let e=(r+i)/2,t=n(e).map(e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4);t[0]*.2126+t[1]*.7152+t[2]*.0722<.2?r=e:i=e}return`#${n((r+i)/2).map(e=>Math.round(e*255).toString(16).padStart(2,`0`)).join(``)}`},R=e=>e===null?`other`:`model:${e}`;function z(e,t){return e.range.from===t.range.from&&e.range.to===t.range.to&&e.series.length===t.series.length&&e.series.every((e,n)=>{let r=t.series[n];return e.timestamp===r.timestamp&&e.calls===r.calls&&e.tokens===r.tokens&&e.errors===r.errors})}function ee(e){return e.modelSeries?.length?e.modelSeries.map(e=>({...e,key:R(e.model)})):[{key:`total`,model:void 0,points:e.series}]}function te(e){let t=e.heatmap?.models??[],n=(e.modelSeries??[]).flatMap(e=>e.model===null?[]:[e.model]).filter(e=>!t.includes(e)).sort(),r=new Set([...t,...e.heatmap?.cells.flatMap(e=>e.models.map(e=>e.model))??[],...e.modelSeries?.flatMap(e=>e.model===null?[]:[e.model])??[],...e.models.map(e=>e.model)]),i=[...t,...n,...[...r].filter(e=>!t.includes(e)&&!n.includes(e)).sort()],a=new Map([[`other`,I],[`total`,I]]);return i.forEach((e,t)=>{a.set(R(e),F[t]??L(t))}),a}function ne(e,t,n,r){let i=e.models.filter(e=>e.pluginId===t&&(r===void 0||e.pluginName===r)&&e.calls>0).map(({model:e,calls:t})=>({model:e,calls:t})),a=n-i.reduce((e,t)=>e+t.calls,0);return a>0?[...i,{model:null,calls:a}]:i}function re({analytics:e,metric:t,onMetricChange:n,colors:r,highlighted:a,selected:o,loadingModel:s,canLoadModels:c=!1,onHighlight:l,onSelect:u}){let{t:d,i18n:p}=i(),h=(0,E.useMemo)(()=>ee(e),[e]),g=(0,E.useRef)(null),[_,v]=(0,E.useState)(960),[y,b]=(0,E.useState)();(0,E.useEffect)(()=>{let e=g.current;if(!e)return;let t=new ResizeObserver(e=>{v(Math.max(280,e[0].contentRect.width))});return t.observe(e),()=>t.disconnect()},[]);let x=(e,t=!1)=>new Intl.NumberFormat(p.language,{notation:t&&e>=1e4?`compact`:`standard`,maximumFractionDigits:+!!t}).format(e),S=new Intl.DateTimeFormat(p.language,{month:`short`,day:`numeric`,timeZone:`UTC`}),C=e=>e===void 0?d(`usageAnalytics.activity.allModels`):e===null?d(`usageAnalytics.heatmap.other`):e||`—`,w={top:18,right:20,bottom:32,left:48},D=_-w.left-w.right,k=260-w.top-w.bottom,A=Math.max(1,...h.flatMap(e=>e.points.map(e=>e[t]))),j=Math.ceil(A/4)*4,M=e.series.reduce((e,n)=>e+n[t],0),N=t===`tokens`&&M===0,P=t=>w.left+(e.series.length<=1?D/2:t/(e.series.length-1)*D),F=e=>w.top+k-e/j*k,I=e.series.findIndex(e=>e.timestamp===y),L=I<0?Math.max(0,e.series.length-1):I,R=e.series[L],z=h.find(e=>e.key===a),te=[...new Set([0,Math.floor((e.series.length-1)/2),e.series.length-1])].filter(e=>e>=0),ne=h.map(e=>({...e,value:e.points[L]?.[t]??0})).sort((e,t)=>t.value-e.value),re=e=>e.map((e,n)=>`${n===0?`M`:`L`} ${P(n)} ${F(e[t])}`).join(` `);return(0,O.jsxs)(`section`,{"data-testid":`plugin-usage-chart`,"aria-busy":s!==void 0,className:`min-w-0 overflow-hidden rounded-2xl border border-gray-200/80 bg-white/80 shadow-subtle dark:border-white/8 dark:bg-dark-100/75`,children:[(0,O.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3 border-b border-gray-200/70 px-4 py-4 dark:border-white/[0.07] sm:px-5`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:d(`usageAnalytics.activity.title`)}),(0,O.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:d(`usageAnalytics.activity.${t===`calls`?`callsDescription`:`tokensDescription`}`)})]}),(0,O.jsx)(`div`,{className:`inline-flex rounded-xl bg-gray-100 p-1 dark:bg-dark-200/80`,children:[`calls`,`tokens`].map(e=>(0,O.jsx)(`button`,{type:`button`,"aria-pressed":t===e,className:T(`min-h-9 rounded-lg px-3 text-xs font-medium focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500`,t===e?`bg-white text-gray-950 shadow-xs dark:bg-dark-300 dark:text-dark-950`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),onClick:()=>n(e),children:d(`usageAnalytics.metrics.${e}`)},e))})]}),(0,O.jsxs)(`div`,{className:`px-4 pt-4 sm:px-5`,children:[(0,O.jsxs)(`div`,{className:`mb-3 flex min-h-8 flex-wrap items-center justify-between gap-2`,children:[(0,O.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:d(`usageAnalytics.activity.compareHint`)}),(0,O.jsxs)(`button`,{type:`button`,disabled:!o&&!a,className:T(`inline-flex min-h-9 items-center gap-1.5 rounded-lg px-2 text-xs font-medium text-gray-700 hover:bg-gray-100 focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-primary-500 dark:text-dark-800 dark:hover:bg-dark-200`,!o&&!a&&`invisible`),onClick:()=>{u(void 0),l(void 0)},children:[(0,O.jsx)(f,{className:`h-3.5 w-3.5`}),d(`usageAnalytics.activity.showAll`)]})]}),(0,O.jsx)(`div`,{"data-testid":`usage-model-legend`,className:T(`grid gap-2 sm:grid-cols-2 lg:grid-cols-3`,c&&`h-48 content-start overflow-y-auto pe-1`),children:h.map(e=>{let n=a===e.key,i=o===e.key,s=r.get(e.key)??`#6b7280`,c=e.points.reduce((e,n)=>e+n[t],0);return(0,O.jsxs)(`button`,{type:`button`,"aria-pressed":i,"aria-label":C(e.model),title:C(e.model),onMouseEnter:()=>l(e.key),onMouseLeave:()=>l(void 0),onFocus:()=>l(e.key),onBlur:()=>l(void 0),onClick:()=>u(i?void 0:e.key),className:T(`flex min-h-11 min-w-0 items-center gap-2.5 rounded-xl border px-3 py-2 text-start focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500`,n?`border-gray-400 bg-gray-50 dark:border-dark-500 dark:bg-dark-200`:`border-gray-200/70 hover:bg-gray-50 dark:border-white/[0.07] dark:hover:bg-dark-200/70`),children:[(0,O.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-full`,style:{backgroundColor:s},"aria-hidden":`true`}),(0,O.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs font-medium text-gray-800 dark:text-dark-900`,dir:`auto`,children:C(e.model)}),(0,O.jsx)(`span`,{className:`shrink-0 text-xs tabular-nums text-gray-500 dark:text-dark-500`,children:x(c,!0)}),i&&(0,O.jsx)(m,{className:`h-3.5 w-3.5 shrink-0 text-gray-800 dark:text-dark-900`,"aria-hidden":`true`})]},e.key)})}),(c||h.some(e=>e.model===null))&&(0,O.jsx)(`p`,{className:`mt-2 text-[11px] text-gray-500 dark:text-dark-500`,children:d(`usageAnalytics.activity.topModels`)}),h[0]?.model===void 0&&(0,O.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:d(`usageAnalytics.activity.breakdownUnavailable`)})]}),(0,O.jsx)(`div`,{className:`relative mx-3 mt-4 sm:mx-5`,ref:g,children:N?(0,O.jsx)(`div`,{className:`flex h-[260px] items-center justify-center text-sm text-gray-500 dark:text-dark-500`,children:d(`usageAnalytics.activity.noTokens`)}):(0,O.jsxs)(`svg`,{viewBox:`0 0 ${_} 260`,direction:`ltr`,className:`block h-[260px] w-full touch-pan-y`,role:`img`,"aria-label":d(`usageAnalytics.activity.chartLabel`,{metric:d(`usageAnalytics.metrics.${t}`)}),onPointerMove:t=>{let n=t.currentTarget.getBoundingClientRect(),r=(t.clientX-n.left)*_/n.width,i=Math.round(Math.max(0,Math.min(1,(r-w.left)/D))*(e.series.length-1));e.series[i]&&b(e.series[i].timestamp)},children:[(0,O.jsx)(`title`,{children:d(`usageAnalytics.activity.chartLabel`,{metric:d(`usageAnalytics.metrics.${t}`)})}),[0,.25,.5,.75,1].map(e=>{let t=w.top+k*e;return(0,O.jsxs)(`g`,{children:[(0,O.jsx)(`line`,{x1:w.left,x2:_-w.right,y1:t,y2:t,className:`stroke-gray-200 dark:stroke-white/[0.07]`,strokeDasharray:e===1?void 0:`3 6`}),(0,O.jsx)(`text`,{x:w.left-9,y:t+4,textAnchor:`end`,className:`fill-gray-500 text-[11px] dark:fill-dark-500`,children:x(Math.round(j*(1-e)),!0)})]},e)}),R&&(0,O.jsx)(`line`,{x1:P(L),x2:P(L),y1:w.top,y2:260-w.bottom,className:`stroke-gray-300 dark:stroke-dark-400`,strokeDasharray:`3 4`}),[...h].sort((e,t)=>Number(e.key===a)-Number(t.key===a)).map(e=>{let n=e.key===a,i=r.get(e.key)??`#6b7280`,o=e.points[L];return(0,O.jsxs)(`g`,{opacity:a&&!n?.18:1,children:[(0,O.jsx)(`path`,{"data-testid":`usage-model-line`,"data-model":e.model===void 0?`__total__`:e.model??`__other__`,"data-highlighted":n,d:re(e.points),stroke:i,fill:`none`,strokeWidth:n?3.5:2,strokeDasharray:e.model===null?`6 4`:void 0,strokeLinecap:`round`,strokeLinejoin:`round`,vectorEffect:`non-scaling-stroke`,children:(0,O.jsx)(`title`,{children:C(e.model)})}),o&&(0,O.jsx)(`circle`,{cx:P(L),cy:F(o[t]),r:n?5:3.5,fill:i,className:`stroke-white dark:stroke-dark-100`,strokeWidth:`2`})]},e.key)}),te.map(t=>(0,O.jsx)(`text`,{x:P(t),y:252,textAnchor:t===0?`start`:t===e.series.length-1?`end`:`middle`,className:`fill-gray-500 text-[11px] dark:fill-dark-500`,children:S.format(e.series[t].timestamp)},t))]})}),R&&(0,O.jsxs)(`div`,{className:`border-t border-gray-200/70 px-4 py-4 dark:border-white/[0.07] sm:px-5`,children:[(0,O.jsxs)(`label`,{className:`mb-2 flex flex-wrap items-center justify-between gap-2 text-xs text-gray-500 dark:text-dark-500`,children:[(0,O.jsx)(`span`,{children:d(`usageAnalytics.activity.exploreDay`)}),(0,O.jsx)(`span`,{className:`text-gray-800 dark:text-dark-800`,children:S.format(R.timestamp)}),(0,O.jsx)(`input`,{"data-testid":`usage-chart-day-slider`,type:`range`,min:0,max:Math.max(0,e.series.length-1),step:1,value:L,"aria-label":d(`usageAnalytics.activity.exploreDay`),"aria-valuetext":S.format(R.timestamp),onChange:t=>b(e.series[Number(t.target.value)]?.timestamp),className:`h-6 w-full cursor-pointer accent-gray-700 focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-primary-500 dark:accent-gray-300`,dir:`ltr`})]}),(0,O.jsxs)(`div`,{"data-testid":`usage-chart-day-detail`,"aria-live":`polite`,"aria-atomic":`true`,children:[(0,O.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-baseline justify-between gap-2`,children:[(0,O.jsxs)(`span`,{className:`text-xs font-medium text-gray-700 dark:text-dark-800`,children:[d(`usageAnalytics.activity.dayTotal`),` ·`,` `,S.format(R.timestamp)]}),(0,O.jsxs)(`span`,{className:`text-sm font-medium tabular-nums text-gray-950 dark:text-dark-950`,children:[x(R[t]),` `,d(`usageAnalytics.metrics.${t}`)]})]}),(0,O.jsx)(`div`,{className:T(`grid gap-x-5 gap-y-2 sm:grid-cols-2 lg:grid-cols-3`,c&&`max-h-40 overflow-y-auto`),children:ne.map(e=>(0,O.jsxs)(`div`,{"data-model":e.model===void 0?`__total__`:e.model??`__other__`,className:T(`flex min-w-0 items-center gap-2 text-xs`,a===e.key&&`font-medium`),children:[(0,O.jsx)(`span`,{"aria-hidden":`true`,className:`h-2 w-2 shrink-0 rounded-full`,style:{backgroundColor:r.get(e.key)??`#6b7280`}}),(0,O.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-gray-600 dark:text-dark-700`,title:C(e.model),dir:`auto`,children:C(e.model)}),(0,O.jsx)(`span`,{className:`shrink-0 tabular-nums text-gray-900 dark:text-dark-900`,children:x(e.value)})]},e.key))}),(0,O.jsx)(`p`,{className:`mt-3 h-4 truncate text-xs font-medium text-gray-600 dark:text-dark-700`,children:s===void 0?z?d(`usageAnalytics.activity.highlightedModel`,{model:C(z.model)}):d(`usageAnalytics.activity.allModels`):d(`usageAnalytics.activity.loadingModel`,{model:s})})]})]})]})}var B=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),V=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1}),H=e=>e>=1e4?V.format(e):B.format(e),U=e=>e?e<1e3?`${B.format(e)} ms`:`${(e/1e3).toFixed(+(e<1e4))} s`:`—`,W=(e,t)=>e===0?0:(e-t)/e*100,G=864e5,K=10,q=12,J=30,Y=16,ie=`fill-gray-950/6 dark:fill-white/[0.07]`,ae=[0,.35,.55,.75,1],oe=({heatmap:e,colors:t,chartModels:n,focusedModel:r})=>{let{t:a,i18n:o}=i(),[s,c]=(0,E.useState)(null),l=[...new Set([...e.models,...n])],u=e=>e!==void 0&&(l.includes(e)||e===r)?t.get(R(e))??`#6b7280`:I,{weeks:d,firstColStart:f,cellsByDay:p,maxCalls:m,totalCalls:h}=(0,E.useMemo)(()=>{let t=new Map(e.cells.map(e=>[e.timestamp,e])),n=e.from,r=e.from+(e.days-1)*G,i=n-new Date(n).getUTCDay()*G;return{weeks:Math.ceil((r-i+G)/(7*G)),firstColStart:i,cellsByDay:t,maxCalls:Math.max(1,...e.cells.map(e=>e.calls)),totalCalls:e.cells.reduce((e,t)=>e+t.calls,0)}},[e]),g=new Intl.DateTimeFormat(o.language,{month:`short`,timeZone:`UTC`}),_=new Intl.DateTimeFormat(o.language,{weekday:`short`,timeZone:`UTC`}),v=new Intl.DateTimeFormat(o.language,{dateStyle:`medium`,timeZone:`UTC`}),y=e.from,b=e.from+(e.days-1)*G,x=J+d*q,S=[],C=-1;for(let e=0;e<d;e++){let t=f+e*7*G,n=Math.max(t,y),r=new Date(n).getUTCMonth();r!==C&&t>=y-6*G&&((C!==-1||t>=y)&&S.push({x:J+e*q,label:g.format(n)}),C=r)}let w=e=>e<=0?0:Math.min(4,Math.max(1,Math.ceil(e/m*4))),D=e=>u(e.models[0]?.model),k=(e,t,n)=>{let r=e.currentTarget.closest(`[data-heatmap-wrapper]`);if(!r)return;let i=r.getBoundingClientRect(),a=e.currentTarget.getBoundingClientRect(),o=a.left-i.left+a.width/2;c({x:Math.min(Math.max(o,96),Math.max(i.width-96,96)),y:a.top-i.top,timestamp:t,calls:n.calls,models:n.models})};return(0,O.jsxs)(`section`,{"data-testid":`usage-heatmap`,className:`min-w-0 overflow-hidden rounded-2xl border border-gray-200/80 bg-white/80 shadow-subtle backdrop-blur-md dark:border-white/8 dark:bg-dark-100/75`,children:[(0,O.jsxs)(`div`,{className:`flex flex-col gap-1 border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.07] sm:flex-row sm:items-center sm:justify-between sm:px-5`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:a(`usageAnalytics.heatmap.title`)}),(0,O.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:a(`usageAnalytics.heatmap.description`)})]}),(0,O.jsx)(`span`,{className:`shrink-0 text-xs tabular-nums text-gray-500 dark:text-dark-500`,children:a(`usageAnalytics.heatmap.yearTotal`,{count:h,formatted:H(h)})})]}),(0,O.jsxs)(`div`,{className:`relative p-4 sm:px-5`,"data-heatmap-wrapper":!0,children:[(0,O.jsx)(`div`,{className:`overflow-x-auto`,children:(0,O.jsxs)(`svg`,{viewBox:`0 0 ${x} 100`,direction:`ltr`,className:`h-auto w-full min-w-[640px]`,role:`img`,"aria-label":a(`usageAnalytics.heatmap.title`),onMouseLeave:()=>c(null),children:[S.map(({x:e,label:t})=>(0,O.jsx)(`text`,{x:e,y:10,className:`fill-gray-400 text-[8px] dark:fill-dark-500`,children:t},`${e}-${t}`)),[1,3,5].map(e=>(0,O.jsx)(`text`,{x:0,y:Y+e*q+K-2,className:`fill-gray-400 text-[8px] dark:fill-dark-500`,children:_.format(new Date(Date.UTC(2023,0,1+e)))},e)),Array.from({length:d},(e,t)=>Array.from({length:7},(e,n)=>{let r=f+(t*7+n)*G;if(r<y||r>b)return null;let i=p.get(r),a=i?.calls??0,o=w(a);return(0,O.jsx)(`rect`,{x:J+t*q,y:Y+n*q,width:K,height:K,rx:2,"data-model":i?.models[0]?.model,fill:i&&o>0?D(i):void 0,fillOpacity:o===0?1:ae[o],strokeWidth:+(s?.timestamp===r),className:T(`motion-safe:transition-opacity`,(o===0||!i)&&ie,s?.timestamp===r?`stroke-gray-500 dark:stroke-white/60`:`stroke-transparent`),onMouseEnter:e=>k(e,r,{calls:a,models:i?.models??[]}),children:(0,O.jsx)(`title`,{children:`${v.format(r)} — ${H(a)}`})},r)}))]})}),s&&(0,O.jsxs)(`div`,{className:`pointer-events-none absolute z-10 min-w-40 -translate-x-1/2 -translate-y-full rounded-lg border border-gray-200/80 bg-white/95 px-3 py-2 shadow-card backdrop-blur-md dark:border-white/10 dark:bg-dark-100/95`,style:{left:s.x,top:s.y-6},children:[(0,O.jsx)(`div`,{className:`text-[11px] font-medium text-gray-900 dark:text-dark-900`,children:v.format(s.timestamp)}),(0,O.jsx)(`div`,{className:`mt-0.5 text-[11px] text-gray-500 dark:text-dark-500`,children:s.calls===0?a(`usageAnalytics.heatmap.noCalls`):`${H(s.calls)} ${a(`usageAnalytics.heatmap.calls`)}`}),s.models.slice(0,3).map(e=>(0,O.jsxs)(`div`,{className:`mt-1 flex items-center justify-between gap-3 text-[11px]`,children:[(0,O.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,O.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-[3px]`,style:{backgroundColor:u(e.model)}}),(0,O.jsx)(`span`,{className:`truncate font-mono text-gray-700 dark:text-dark-700`,dir:`ltr`,children:e.model})]}),(0,O.jsx)(`span`,{className:`tabular-nums text-gray-500 dark:text-dark-500`,children:H(e.calls)})]},e.model))]}),(0,O.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center justify-between gap-3`,children:[(0,O.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5`,children:[l.map(e=>(0,O.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-gray-600 dark:text-dark-600`,children:[(0,O.jsx)(`span`,{className:`h-2.5 w-2.5 rounded-[3px]`,style:{backgroundColor:t.get(R(e))??`#6b7280`}}),(0,O.jsx)(`span`,{className:`font-mono`,dir:`ltr`,children:e})]},e)),(0,O.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-gray-600 dark:text-dark-600`,children:[(0,O.jsx)(`span`,{className:`h-2.5 w-2.5 rounded-[3px]`,style:{backgroundColor:I}}),a(`usageAnalytics.heatmap.other`)]})]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] text-gray-500 dark:text-dark-500`,children:[a(`usageAnalytics.heatmap.less`),(0,O.jsx)(`span`,{className:`h-2.5 w-2.5 rounded-[3px] bg-gray-950/6 dark:bg-white/[0.07]`}),ae.slice(1).map(e=>(0,O.jsx)(`span`,{className:`h-2.5 w-2.5 rounded-[3px] bg-gray-500`,style:{opacity:e}},e)),a(`usageAnalytics.heatmap.more`)]})]})]})]})},se=({analytics:e})=>{let{t}=i(),n=P(e),r=e=>(e.meteredCalls??0)>0||e.tokens>0;return(0,O.jsxs)(`section`,{"data-testid":`usage-agent-breakdown`,"aria-labelledby":`usage-agent-heading`,className:`rounded-2xl border border-gray-200/80 bg-white/80 p-4 shadow-subtle dark:border-white/8 dark:bg-dark-100/75 sm:p-5`,children:[(0,O.jsxs)(`h2`,{id:`usage-agent-heading`,className:`flex items-center gap-2 text-sm font-medium text-gray-950 dark:text-dark-950`,children:[(0,O.jsx)(p,{className:`h-4 w-4`,"aria-hidden":`true`}),t(`usageAnalytics.agents.title`)]}),(0,O.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.agents.description`)}),e.agents===void 0&&(0,O.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.agents.legacy`)}),(0,O.jsx)(`div`,{className:`mt-4 grid min-w-0 gap-3 sm:grid-cols-2 xl:grid-cols-3`,children:n.map(e=>(0,O.jsxs)(`article`,{"data-agent":e.agentId,className:`min-w-0 rounded-xl border border-gray-200/70 p-3 dark:border-white/[0.07]`,children:[(0,O.jsx)(`h3`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e.agentName}),(0,O.jsxs)(`dl`,{className:`mt-3 grid grid-cols-2 gap-3`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`dt`,{className:`text-[11px] text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.metrics.calls`)}),(0,O.jsx)(`dd`,{"data-agent-metric":`calls`,className:`mt-1 text-lg tabular-nums text-gray-950 dark:text-dark-950`,children:H(e.calls)})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`dt`,{className:`text-[11px] text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.cards.tokens`)}),(0,O.jsx)(`dd`,{"data-agent-metric":`tokens`,className:`mt-1 text-sm tabular-nums text-gray-950 dark:text-dark-950`,children:r(e)?H(e.tokens):e.calls===0?`—`:e.meteredCalls===0?t(`usageAnalytics.agents.unreported`):`—`})]})]}),e.calls===0?(0,O.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.agents.noCalls`)}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:[t(`usageAnalytics.cards.latency`),`:`,` `,(0,O.jsx)(`span`,{className:`tabular-nums`,dir:`ltr`,children:U(e.averageLatencyMs)})]}),e.meteredCalls!==void 0&&e.meteredCalls>0&&(0,O.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.cards.tokensDetail`,{count:e.meteredCalls})}),e.errors>0&&(0,O.jsxs)(`p`,{className:`mt-2 flex items-center gap-1 text-xs text-gray-600 dark:text-dark-600`,children:[(0,O.jsx)(h,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),t(`usageAnalytics.providers.failures`,{count:e.errors})]}),e.models.length>0&&(0,O.jsxs)(`div`,{className:`mt-3`,children:[(0,O.jsx)(`h4`,{className:`text-xs font-medium text-gray-700 dark:text-dark-700`,children:t(`usageAnalytics.agents.topModels`)}),(0,O.jsx)(`div`,{className:`mt-1 max-h-48 overflow-y-auto`,children:(0,O.jsxs)(`table`,{className:`w-full table-fixed text-start text-xs`,children:[(0,O.jsx)(`thead`,{className:`text-gray-500 dark:text-dark-500`,children:(0,O.jsxs)(`tr`,{children:[(0,O.jsx)(`th`,{className:`w-1/2 py-1 text-start font-normal`,children:t(`usageAnalytics.models.model`)}),(0,O.jsx)(`th`,{className:`px-1 py-1 text-end font-normal`,children:t(`usageAnalytics.metrics.calls`)}),(0,O.jsx)(`th`,{className:`py-1 text-end font-normal`,children:t(`usageAnalytics.metrics.tokens`)})]})}),(0,O.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-white/6`,children:e.models.map(e=>(0,O.jsxs)(`tr`,{"data-agent-model":e.model,children:[(0,O.jsx)(`td`,{className:`wrap-break-word py-1.5 pe-2 text-gray-700 dark:text-dark-700`,children:(0,O.jsx)(`span`,{dir:`auto`,children:e.model})}),(0,O.jsx)(`td`,{className:`px-1 py-1.5 text-end tabular-nums`,children:H(e.calls)}),(0,O.jsx)(`td`,{className:`py-1.5 text-end tabular-nums`,children:r(e)?H(e.tokens):`—`})]},e.model))})]})})]})]})]},e.agentId))})]})},X=()=>{let{t:e}=i(),[t,n]=(0,E.useState)(30),[a,s]=(0,E.useState)(`calls`),[f,m]=(0,E.useState)(),[_,y]=(0,E.useState)(),{data:C,error:D,isLoading:k,isFetching:A,refetch:M}=r({queryKey:[`plugin-usage`,t],refetchInterval:2e4,refetchIntervalInBackground:!1,queryFn:async()=>{let n=await w.getUsage(t);if(!n.success||!n.data)throw Error(n.error||e(`usageAnalytics.loadFailed`));return n.data}}),N=(0,E.useMemo)(()=>new Set(C?ee(C).map(e=>e.key):[]),[C]),P=(0,E.useMemo)(()=>new Set([...N,...C?.models.map(e=>R(e.model))??[]]),[N,C]),F=f&&P.has(f)?f:void 0,I=_&&P.has(_)?_:void 0,L=N.has(`other`),B=(L?[I,F].find(e=>e?.startsWith(`model:`)&&!N.has(e)):void 0)?.slice(6),V=r({queryKey:[`plugin-usage`,t,`model`,B,C?.range.to],enabled:B!==void 0,staleTime:3e4,queryFn:async()=>{let n=await w.getUsage(t,B,C?.range.to);if(!n.success||!n.data)throw Error(n.error||e(`usageAnalytics.loadFailed`));return n.data}}),G=C,K=!!C&&!!V.data&&z(C,V.data),q=(0,E.useMemo)(()=>C&&B!==void 0&&K?{...C,modelSeries:V.data.modelSeries}:C,[C,B,K,V.data]),J=(0,E.useRef)(null);(0,E.useEffect)(()=>{B!==void 0&&V.data&&!K&&!A&&J.current!==V.data&&(J.current=V.data,M())},[B,V.data,K,A,M]);let Y=D??(B===void 0?null:V.error),ie=Y?Y instanceof Error?Y.message:e(`usageAnalytics.loadFailed`):null,ae=B!==void 0&&!K&&!Y?B:void 0,X=(0,E.useMemo)(()=>C?te(C):new Map,[C]),ce=(0,E.useMemo)(()=>new Set(q?ee(q).map(e=>e.key):[]),[q]),Z=I??F,le=e=>m(e),Q=e=>{if(C?.modelSeries?.length&&(e!==null||N.has(`other`)))return R(e)},$=G?.totals,ue=(0,E.useMemo)(()=>[{label:e(`usageAnalytics.cards.calls`),value:H($?.calls??0),detail:e(`usageAnalytics.cards.callsDetail`,{count:$?.uniqueUsers??0}),icon:o},{label:e(`usageAnalytics.cards.tokens`),value:H($?.reportedTokens??0),detail:e(`usageAnalytics.cards.coverage`,{percent:$?.calls?($.meteredCalls/$.calls*100).toFixed(1):`0`}),icon:v},{label:e(`usageAnalytics.cards.success`),value:`${W($?.calls??0,($?.failedCalls??0)+($?.cancelledCalls??0)).toFixed(1)}%`,detail:e(`usageAnalytics.cards.successDetail`,{count:$?.failedCalls??0}),icon:c},{label:e(`usageAnalytics.cards.latency`),value:U($?.averageLatencyMs??0),detail:e(`usageAnalytics.cards.latencyDetail`),icon:d}],[e,$]);return k&&!G?(0,O.jsx)(x,{width:`wide`,children:(0,O.jsxs)(`div`,{role:`status`,className:`flex min-h-[50vh] items-center justify-center`,children:[(0,O.jsx)(u,{className:`h-7 w-7 motion-safe:animate-spin text-primary-500`}),(0,O.jsx)(`span`,{className:`sr-only`,children:e(`common.loading`)})]})}):(0,O.jsxs)(x,{width:`wide`,children:[(0,O.jsx)(b,{eyebrow:e(`usageAnalytics.eyebrow`),title:e(`usageAnalytics.title`),description:e(`usageAnalytics.description`),actions:(0,O.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,O.jsx)(`div`,{className:`inline-flex rounded-xl border border-gray-200 bg-white/70 p-1 dark:border-white/8 dark:bg-dark-100/70`,children:[7,30,90].map(r=>(0,O.jsx)(`button`,{type:`button`,className:T(`min-h-9 rounded-lg px-3 py-1.5 text-xs font-medium motion-safe:transition-colors focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-primary-500`,t===r?`bg-gray-950 text-white dark:bg-white dark:text-gray-950`:`text-gray-500 hover:text-gray-900 dark:text-dark-500 dark:hover:text-dark-900`),"aria-pressed":t===r,onClick:()=>{n(r),y(void 0)},children:e(`usageAnalytics.days`,{count:r})},r))}),(0,O.jsxs)(S,{variant:`outline`,size:`sm`,onClick:()=>{M(),B!==void 0&&V.refetch()},disabled:A||B!==void 0&&V.isFetching,children:[(0,O.jsx)(l,{className:T(`h-4 w-4`,A&&`motion-safe:animate-spin`)}),(0,O.jsx)(`span`,{children:e(`usageAnalytics.refresh`)})]})]})}),ie&&(0,O.jsxs)(`div`,{role:`alert`,className:`mb-6 flex items-center gap-3 rounded-2xl border border-error-200 bg-error-50 px-4 py-3 text-sm text-error-700 dark:border-error-900/40 dark:bg-error-900/30 dark:text-error-300`,children:[(0,O.jsx)(h,{className:`h-4 w-4 shrink-0`}),(0,O.jsx)(`span`,{children:ie})]}),!G&&(0,O.jsx)(j,{days:t}),G&&(0,O.jsxs)(`div`,{className:`min-w-0 space-y-4`,children:[(0,O.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-4`,children:ue.map(e=>{let t=e.icon;return(0,O.jsxs)(`section`,{className:`rounded-2xl border border-gray-200/80 bg-white/75 p-4 shadow-subtle backdrop-blur-md dark:border-white/8 dark:bg-dark-100/70`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,O.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-[0.12em] text-gray-500 dark:text-dark-500`,children:e.label}),(0,O.jsx)(t,{className:`h-4 w-4 text-primary-500 dark:text-primary-400`})]}),(0,O.jsx)(`div`,{className:`mt-2 text-2xl font-normal tracking-[-0.04em] text-gray-950 dark:text-dark-950`,children:e.value}),(0,O.jsx)(`p`,{className:`mt-1.5 text-xs text-gray-500 dark:text-dark-500`,children:e.detail})]},e.label)})}),(0,O.jsx)(se,{analytics:G}),(0,O.jsx)(j,{days:t}),G.heatmap&&G.heatmap.cells.length>0&&(0,O.jsx)(oe,{heatmap:G.heatmap,colors:X,focusedModel:Z?.startsWith(`model:`)?Z.slice(6):void 0,chartModels:(C?.modelSeries??[]).flatMap(e=>e.model===null?[]:[e.model])}),(0,O.jsx)(re,{analytics:q??G,metric:a,onMetricChange:s,colors:X,highlighted:Z,selected:F,onHighlight:y,onSelect:le,loadingModel:ae,canLoadModels:L}),G.totals.calls===0?(0,O.jsxs)(`div`,{className:`rounded-2xl border border-dashed border-gray-300 px-6 py-10 text-center dark:border-white/12`,children:[(0,O.jsx)(p,{className:`mx-auto h-8 w-8 text-gray-400 dark:text-dark-500`}),(0,O.jsx)(`h2`,{className:`mt-4 text-base font-medium text-gray-900 dark:text-dark-900`,children:e(`usageAnalytics.empty.title`)}),(0,O.jsx)(`p`,{className:`mx-auto mt-2 max-w-md text-sm leading-6 text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.empty.description`)})]}):(0,O.jsxs)(`div`,{className:`grid min-w-0 gap-4 xl:grid-cols-[minmax(0,1.15fr)_minmax(0,0.85fr)]`,children:[(0,O.jsxs)(`section`,{className:`min-w-0 overflow-hidden rounded-2xl border border-gray-200/80 bg-white/80 shadow-subtle backdrop-blur-md dark:border-white/8 dark:bg-dark-100/75`,children:[(0,O.jsxs)(`div`,{className:`border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.07] sm:px-5`,children:[(0,O.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e(`usageAnalytics.models.title`)}),(0,O.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.models.description`)})]}),(0,O.jsx)(`div`,{className:`overflow-x-auto`,children:(0,O.jsxs)(`table`,{"data-testid":`usage-model-table`,className:`w-full min-w-[620px] text-start text-sm`,children:[(0,O.jsx)(`thead`,{className:`text-[11px] uppercase tracking-widest text-gray-400 dark:text-dark-500`,children:(0,O.jsxs)(`tr`,{children:[(0,O.jsx)(`th`,{className:`px-5 py-2 text-start font-medium`,children:e(`usageAnalytics.models.model`)}),(0,O.jsx)(`th`,{className:`px-4 py-2 text-end font-medium`,children:e(`usageAnalytics.metrics.calls`)}),(0,O.jsx)(`th`,{className:`px-4 py-2 text-end font-medium`,children:e(`usageAnalytics.metrics.tokens`)}),(0,O.jsx)(`th`,{className:`px-4 py-2 text-end font-medium`,children:e(`usageAnalytics.models.success`)}),(0,O.jsx)(`th`,{className:`px-5 py-2 text-end font-medium`,children:e(`usageAnalytics.models.latency`)})]})}),(0,O.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-white/6`,children:G.models.map(t=>(0,O.jsxs)(`tr`,{"data-testid":`usage-model-row`,"data-model":t.model,"data-highlighted":Z===Q(t.model),onMouseEnter:()=>y(Q(t.model)),onMouseLeave:()=>y(void 0),className:T(Z===Q(t.model)&&Z&&`bg-gray-50 dark:bg-dark-200/70`),children:[(0,O.jsxs)(`td`,{className:`px-5 py-2.5`,children:[(0,O.jsxs)(`button`,{type:`button`,disabled:!Q(t.model),"aria-label":e(`usageAnalytics.activity.highlightModel`,{model:t.model}),"aria-pressed":!!F&&F===Q(t.model),className:`flex min-h-9 max-w-[260px] items-center gap-2 rounded-md text-start font-medium text-gray-900 focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500 dark:text-dark-900`,title:ce.has(R(t.model))?t.model:e(`usageAnalytics.models.notCharted`),onFocus:()=>y(Q(t.model)),onBlur:()=>y(void 0),onClick:()=>le(F===Q(t.model)?void 0:Q(t.model)),children:[(0,O.jsx)(`span`,{"aria-hidden":`true`,className:`h-2.5 w-2.5 shrink-0 rounded-full`,style:{backgroundColor:X.get(R(t.model))??`#6b7280`}}),(0,O.jsx)(`span`,{className:`truncate`,dir:`ltr`,children:t.model})]}),(0,O.jsx)(`div`,{className:`mt-0.5 text-xs text-gray-500 dark:text-dark-500`,children:t.pluginName})]}),(0,O.jsxs)(`td`,{className:`px-4 py-2.5 text-end tabular-nums text-gray-700 dark:text-dark-700`,children:[H(t.calls),(0,O.jsxs)(`div`,{className:`mt-1 text-[11px] text-gray-500 dark:text-dark-500`,title:e(`usageAnalytics.models.share`),children:[(t.calls/G.totals.calls*100).toFixed(1),`%`]})]}),(0,O.jsx)(`td`,{className:`px-4 py-2.5 text-end tabular-nums text-gray-700 dark:text-dark-700`,children:t.tokens?H(t.tokens):`—`}),(0,O.jsxs)(`td`,{className:`px-4 py-2.5 text-end tabular-nums text-gray-700 dark:text-dark-700`,children:[W(t.calls,t.errors).toFixed(1),`%`]}),(0,O.jsx)(`td`,{className:`px-5 py-2.5 text-end tabular-nums text-gray-500 dark:text-dark-500`,children:U(t.averageLatencyMs)})]},JSON.stringify([t.pluginId,t.pluginName,t.model])))})]})})]}),(0,O.jsxs)(`div`,{className:`min-w-0 space-y-4`,children:[(0,O.jsxs)(`section`,{"data-testid":`usage-provider-breakdown`,className:`min-w-0 rounded-2xl border border-gray-200/80 bg-white/80 p-4 shadow-subtle dark:border-white/8 dark:bg-dark-100/75 sm:p-5`,children:[(0,O.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e(`usageAnalytics.providers.title`)}),(0,O.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.providers.description`)}),(0,O.jsx)(`div`,{className:`mt-4 divide-y divide-gray-200/70 dark:divide-white/[0.07]`,children:G.plugins.map(t=>{let n=G.totals.calls?t.calls/G.totals.calls*100:0,r=ne(G,t.pluginId,t.calls,t.pluginName);return(0,O.jsxs)(`article`,{"data-provider":t.pluginId,className:`py-4 first:pt-0 last:pb-0`,children:[(0,O.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,O.jsxs)(`div`,{className:`min-w-0`,children:[(0,O.jsx)(`h3`,{className:`truncate text-sm font-medium text-gray-900 dark:text-dark-900`,title:t.pluginName,children:t.pluginName}),(0,O.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.providers.share`,{percent:n.toFixed(1)})})]}),(0,O.jsxs)(`div`,{className:`shrink-0 text-end`,children:[(0,O.jsx)(`div`,{className:`text-base font-medium tabular-nums text-gray-950 dark:text-dark-950`,children:H(t.calls)}),(0,O.jsx)(`div`,{className:`text-[11px] text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.metrics.calls`)})]})]}),(0,O.jsx)(`div`,{className:`my-3 flex h-2 overflow-hidden rounded-full bg-gray-100 dark:bg-dark-300`,"aria-hidden":`true`,children:r.map(n=>(0,O.jsx)(`span`,{"data-model":n.model??`__other__`,title:`${n.model??e(`usageAnalytics.heatmap.other`)}: ${H(n.calls)}`,style:{width:`${t.calls?n.calls/t.calls*100:0}%`,backgroundColor:X.get(R(n.model))??`#6b7280`,opacity:Z&&Z!==Q(n.model)?.25:1}},R(n.model)))}),(0,O.jsxs)(`dl`,{className:`grid grid-cols-3 gap-2`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`dt`,{className:`text-[10px] text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.metrics.tokens`)}),(0,O.jsx)(`dd`,{className:`mt-1 text-xs tabular-nums text-gray-800 dark:text-dark-800`,title:t.tokens?void 0:e(`usageAnalytics.providers.noTokens`),children:t.tokens?H(t.tokens):`—`})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`dt`,{className:`text-[10px] text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.models.success`)}),(0,O.jsxs)(`dd`,{className:`mt-1 text-xs tabular-nums text-gray-800 dark:text-dark-800`,children:[W(t.calls,t.errors).toFixed(1),`%`]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`dt`,{className:`text-[10px] text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.models.latency`)}),(0,O.jsx)(`dd`,{className:`mt-1 text-xs tabular-nums text-gray-800 dark:text-dark-800`,children:U(t.averageLatencyMs)})]})]}),t.errors>0&&(0,O.jsxs)(`p`,{className:`mt-2 flex items-center gap-1 text-[11px] text-gray-500 dark:text-dark-500`,children:[(0,O.jsx)(h,{className:`h-3 w-3`}),e(`usageAnalytics.providers.failures`,{count:t.errors})]}),(0,O.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:r.map(t=>{let n=Q(t.model),r=t.model??e(`usageAnalytics.heatmap.other`);return(0,O.jsxs)(`button`,{type:`button`,disabled:!n,"aria-label":e(`usageAnalytics.activity.highlightModel`,{model:r}),"aria-pressed":!!F&&F===n,title:r,onMouseEnter:()=>y(n),onMouseLeave:()=>y(void 0),onFocus:()=>y(n),onBlur:()=>y(void 0),onClick:()=>le(F===n?void 0:n),className:T(`flex min-h-8 min-w-0 max-w-full items-center gap-1.5 rounded-md border px-2 py-1 text-[11px] text-gray-600 focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-primary-500 dark:text-dark-700`,Z&&Z===n?`border-gray-400 bg-gray-50 dark:border-dark-500 dark:bg-dark-200`:`border-gray-200/70 dark:border-white/[0.07]`),children:[(0,O.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-full`,style:{backgroundColor:X.get(R(t.model))??`#6b7280`},"aria-hidden":`true`}),(0,O.jsx)(`span`,{className:`truncate`,dir:`auto`,children:r})]},R(t.model))})})]},JSON.stringify([t.pluginId,t.pluginName]))})})]}),(0,O.jsxs)(`section`,{className:`rounded-2xl border border-gray-200/80 bg-white/80 p-4 shadow-subtle backdrop-blur-md dark:border-white/8 dark:bg-dark-100/75 sm:p-5`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(g,{className:`h-4 w-4 text-primary-500 dark:text-primary-400`}),(0,O.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e(`usageAnalytics.capabilities.title`)})]}),(0,O.jsx)(`div`,{className:`mt-5 grid grid-cols-2 gap-3`,children:G.capabilities.map(t=>(0,O.jsxs)(`div`,{className:`rounded-xl bg-gray-50 px-3 py-2.5 dark:bg-dark-200/70`,children:[(0,O.jsx)(`div`,{className:`text-xs font-medium capitalize text-gray-500 dark:text-dark-500`,children:t.capability}),(0,O.jsx)(`div`,{className:`mt-1 text-xl text-gray-950 dark:text-dark-950`,children:H(t.calls)}),(0,O.jsx)(`div`,{className:`mt-1 text-[11px] text-gray-500 dark:text-dark-500`,children:t.capability===`tts`?e(`usageAnalytics.capabilities.characters`,{count:H(t.inputUnits)}):t.capability===`stt`?e(`usageAnalytics.capabilities.bytes`,{count:H(t.inputUnits)}):t.capability===`image`?e(`usageAnalytics.capabilities.images`,{count:H(t.outputUnits)}):t.capability===`video`?e(`usageAnalytics.capabilities.jobs`,{count:H(t.calls)}):t.capability===`embedding`?e(`usageAnalytics.capabilities.inputs`,{count:H(t.inputUnits)}):e(`usageAnalytics.capabilities.reportedTokens`,{count:H(t.tokens)})})]},t.capability))})]})]})]}),(0,O.jsx)(`p`,{className:`px-1 text-xs leading-5 text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.privacyNote`)})]})]})};export{X as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{t as RichMessageContent,t as default}from"./RichMessageContent-
|
|
1
|
+
export{t as RichMessageContent,t as default}from"./RichMessageContent-DwMoWuR_.js";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["js/markdownMath-CKB9Q-yN.js","js/markdown-math-CCWDDhWR.js","js/markdown-core-CGWDtd6X.js","js/rolldown-runtime-XKyaHtl9.js","js/react-vendor-C1iE8mnY.js","assets/markdown-math-Bv5fr4tV.css","js/markdownHtml-DpKMtcCu.js","js/markdown-html-DRL6swKb.js","js/OptimizedSyntaxHighlighter-DoJF0j0l.js","js/OptimizedSyntaxHighlighter-B8vbflQA.js","js/syntax-highlight-CemL-n1v.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{i as r,s as i}from"./markdown-core-CGWDtd6X.js";import{o as a}from"./logger-DAQsBb8I.js";import{t as o}from"./appStore-
|
|
2
|
+
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{i as r,s as i}from"./markdown-core-CGWDtd6X.js";import{o as a}from"./logger-DAQsBb8I.js";import{t as o}from"./appStore-DCIUnT8X.js";import{t as s}from"./utils-BXRzbHJC.js";import{a as c,i as l,n as u,r as d,s as f,t as p}from"./messageCodeStyles-BugWE4s5.js";var m=e(t(),1),h=null,g=null,_=null,v=null,y=()=>_??=a(()=>import(`./markdownMath-CKB9Q-yN.js`).then(e=>(h=e,e)),__vite__mapDeps([0,1,2,3,4,5])),b=()=>v??=a(()=>import(`./markdownHtml-DpKMtcCu.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(()=>a(()=>import(`./OptimizedSyntaxHighlighter-DoJF0j0l.js`),__vite__mapDeps([8,9,3,4,10,2])));function T({children:e,className:t}){return(0,C.jsx)(`pre`,{dir:`ltr`,className:s(d,`rounded-lg`,t),children:(0,C.jsx)(`code`,{children:e})})}var E=m.memo(({content:e,className:t,allowHtml:n=!1})=>{let a=o(e=>e.theme.mode!==`light`),d=m.useMemo(()=>f(e),[e]),{math:h,html:g}=S({needsMath:x(d),needsHtml:n}),_=m.useMemo(()=>h?[r,h.remarkMath]:[r],[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:s(`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)(i,{remarkPlugins:_,rehypePlugins:v,components:{code({className:e,children:t,node:n,...r}){let i=/language-([^\s]+)/.exec(e||``),o=String(t),d=o.replace(/\n$/,``),f=i?i[1]:null;return f||o.includes(`
|
|
3
3
|
`)?(0,C.jsx)(c,{code:d,language:f,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:d}),children:(0,C.jsx)(w,{language:f||`text`,isDark:a,codeTheme:`night`,backgroundColor:a?p:u,borderRadius:0,customStyle:l,className:`m-0! rounded-none! border-none!`,showLineNumbers:!0,children:d})})})}):(0,C.jsx)(`code`,{dir:`ltr`,className:s(`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),...r,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:s(`my-4 w-full overflow-x-auto rounded-xl border border-line bg-surface shadow-subtle`,`focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/40`),tabIndex:0,children:(0,C.jsx)(`table`,{dir:`auto`,className:`w-full min-w-2xl border-separate border-spacing-0 text-start text-sm`,...n,children:e})})},thead({children:e,node:t,...n}){return(0,C.jsx)(`thead`,{className:`bg-surface-subtle`,...n,children:e})},tbody({children:e,node:t,...n}){return(0,C.jsx)(`tbody`,{...n,children:e})},tr({children:e,node:t,...n}){return(0,C.jsx)(`tr`,{className:`transition-colors hover:bg-black/2.5 [&>td]:last:border-b-0 dark:hover:bg-white/2.5`,...n,children:e})},th({align:e,children:t,node:n,...r}){return(0,C.jsx)(`th`,{className:s(`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:s(`min-w-40 border-b border-e border-line px-3 py-2.5 align-top leading-relaxed text-ink last:border-e-0`,e===`center`?`text-center`:e===`right`?`text-right`:e===`left`?`text-left`:`text-start`),...r,children:t})},a({children:e,node:t,href:n,...r}){let i=!!n&&!n?.startsWith(`#`);return(0,C.jsx)(`a`,{...r,href:n,...i?{target:`_blank`,rel:`noopener noreferrer`}:{},className:`text-primary-600 underline decoration-primary-600/30 underline-offset-2 transition-colors hover:decoration-current dark:text-primary-400 dark:decoration-primary-400/40`,children:e})}},children:d})})});E.displayName=`RichMessageContent`;export{E as t};
|