myapikey 0.14.1 → 0.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "myapikey",
3
- "version": "0.14.1",
3
+ "version": "0.14.2",
4
4
  "type": "module",
5
5
  "description": "Personal LLM API gateway & proxy — one address + one API key for all your models. Forwards OpenAI & Anthropic calls to your backends with failover and a circuit breaker. Pure passthrough, no format translation. Self-hosted (CLI + web UI).",
6
6
  "keywords": [
@@ -279,8 +279,8 @@ var ku=e=>{throw TypeError(e)};var Zm=(e,t,n)=>t.has(e)||ku("Cannot "+n);var Oo=
279
279
  *
280
280
  * This source code is licensed under the ISC license.
281
281
  * See the LICENSE file in the root directory of this source tree.
282
- */const Tl=Ne("zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]),Qa=Q({__name:"Dialog",props:{open:{type:Boolean},defaultOpen:{type:Boolean},modal:{type:Boolean},unmountOnHide:{type:Boolean}},emits:["update:open"],setup(e,{emit:t}){const o=Rt(e,t);return(r,a)=>(_(),D(l(R1),Ot($t(l(o))),{default:y(()=>[ae(r.$slots,"default")]),_:3},16))}}),Za=Q({__name:"DialogContent",props:{forceMount:{type:Boolean},disableOutsidePointerEvents:{type:Boolean},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},emits:["escapeKeyDown","pointerDownOutside","focusOutside","interactOutside","openAutoFocus","closeAutoFocus"],setup(e,{emit:t}){const n=e,s=t,o=X(()=>{const{class:a,...i}=n;return i}),r=Rt(o,s);return(a,i)=>(_(),D(l(h0),null,{default:y(()=>[v(l(f0),{class:"fixed inset-0 z-50 bg-black/80"}),v(l(a0),Ie(l(r),{class:l(Ye)("fixed left-[50%] top-[50%] z-50 flex max-h-[90vh] w-full max-w-lg translate-x-[-50%] translate-y-[-50%] flex-col gap-4 overflow-hidden border bg-background p-6 shadow-lg sm:rounded-lg",n.class)}),{default:y(()=>[ae(a.$slots,"default"),v(l(D1),{class:"absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:ring-offset-background"},{default:y(()=>[v(l(Ja),{class:"h-4 w-4"}),i[0]||(i[0]=x("span",{class:"sr-only"},"Close",-1))]),_:1})]),_:3},16,["class"])]),_:3}))}}),el=Q({__name:"DialogTitle",props:{asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},setup(e){const t=e;return(n,s)=>(_(),D(l(g0),{class:Ce(l(Ye)("text-lg font-semibold leading-none tracking-tight",t.class))},{default:y(()=>[ae(n.$slots,"default")]),_:3},8,["class"]))}}),tl=Q({__name:"DialogDescription",props:{asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},setup(e){const t=e;return(n,s)=>(_(),D(l(i0),{class:Ce(l(Ye)("text-sm text-muted-foreground",t.class))},{default:y(()=>[ae(n.$slots,"default")]),_:3},8,["class"]))}}),vo=Q({__name:"Checkbox",props:ys({class:{type:[Boolean,null,String,Object,Array]},id:{}},{modelValue:{type:Boolean},modelModifiers:{}}),emits:["update:modelValue"],setup(e){const t=e,n=_r(e,"modelValue");return(s,o)=>(_(),D(l(Uw),{modelValue:n.value,"onUpdate:modelValue":o[0]||(o[0]=r=>n.value=r),id:t.id,class:Ce(l(Ye)("peer h-4 w-4 shrink-0 cursor-pointer rounded-[4px] border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",t.class))},{default:y(()=>[v(l(jw),{class:"flex h-full w-full items-center justify-center text-current"},{default:y(()=>[v(l(Pn),{class:"h-3.5 w-3.5"})]),_:1})]),_:1},8,["modelValue","id","class"]))}}),Mm=Q({__name:"Separator",props:{class:{type:[Boolean,null,String,Object,Array]},orientation:{}},setup(e){const t=e;return(n,s)=>(_(),D(l(Pk),{orientation:t.orientation??"horizontal",class:Ce(l(Ye)("shrink-0 bg-border",t.orientation==="vertical"?"h-full w-px":"h-px w-full",t.class))},null,8,["orientation","class"]))}}),lC={class:"flex gap-3 pr-8"},iC={key:0,class:"flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-destructive/15 text-destructive"},uC={class:"min-w-0 flex-1 space-y-1.5"},cC={class:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end"},gu=Q({__name:"ConfirmDialog",props:ys({title:{},description:{},confirmText:{default:""},cancelText:{default:""},variant:{default:"default"},loading:{type:Boolean,default:!1}},{open:{type:Boolean,default:!1},openModifiers:{}}),emits:ys(["confirm"],["update:open"]),setup(e,{emit:t}){const{t:n}=It(),s=_r(e,"open"),o=t;return(r,a)=>(_(),D(l(Qa),{open:s.value,"onUpdate:open":a[2]||(a[2]=i=>s.value=i)},{default:y(()=>[v(l(Za),{class:"max-w-sm"},{default:y(()=>[x("div",lC,[e.variant==="destructive"?(_(),W("span",iC,[v(l(rC),{class:"h-4 w-4"})])):pe("",!0),x("div",uC,[v(l(el),{class:"text-base leading-tight"},{default:y(()=>[j(S(e.title),1)]),_:1}),e.description?(_(),D(l(tl),{key:0},{default:y(()=>[j(S(e.description),1)]),_:1})):pe("",!0)])]),x("div",cC,[v(l(Re),{variant:"outline",disabled:e.loading,onClick:a[0]||(a[0]=i=>s.value=!1)},{default:y(()=>[j(S(e.cancelText||l(n)("common.cancel")),1)]),_:1},8,["disabled"]),v(l(Re),{variant:e.variant,disabled:e.loading,onClick:a[1]||(a[1]=i=>o("confirm"))},{default:y(()=>[e.loading?(_(),D(l(kt),{key:0,class:"h-4 w-4 animate-spin"})):pe("",!0),j(" "+S(e.confirmText||l(n)("common.confirm")),1)]),_:1},8,["variant","disabled"])])]),_:1})]),_:1},8,["open"]))}}),dC={class:"space-y-3"},fC={key:0,class:"space-y-1.5"},pC={class:"text-xs font-medium text-muted-foreground"},mC={class:"space-y-1.5"},hC={class:"text-xs font-medium text-muted-foreground"},vC={class:"space-y-2 rounded-md border bg-background/50 p-3"},gC={class:"space-y-2"},yC={class:"flex items-center gap-2.5"},bC={class:"flex items-center gap-2.5 pl-7"},_C={class:"flex items-center gap-2.5"},wC={class:"text-xs text-muted-foreground"},xC={key:1,class:"space-y-1.5"},kC={class:"text-xs font-medium text-muted-foreground"},CC={class:"text-xs text-muted-foreground"},SC={key:2,class:"space-y-1.5"},AC={class:"text-xs font-medium text-muted-foreground"},EC={class:"text-xs text-muted-foreground"},OC={key:3,class:"space-y-1.5"},TC={class:"text-xs font-medium text-muted-foreground"},PC={key:4,class:"text-sm text-destructive"},yu=Q({__name:"NewSourceForm",props:{formatsOnly:{type:Boolean}},setup(e,{expose:t}){const n=e,{t:s}=It(),o=N(""),r=N(""),a=N(""),i=N(""),u=N(!0),c=N(!1),d=N(!1),f=N("");function p(h){if(h==="openai"){if(u.value&&!c.value)return;u.value=!u.value}else{if(c.value&&!u.value)return;c.value=!c.value}}const m=X(()=>{const h=[];return u.value&&h.push("openai"),c.value&&h.push("anthropic"),h}),w=X(()=>({name:o.value.trim(),baseUrlOpenai:r.value,baseUrlAnthropic:a.value,apiKey:i.value,formats:m.value,supportsResponses:u.value&&d.value}));function k(){o.value=i.value="",r.value=a.value="",u.value=!0,c.value=!1,d.value=!1,f.value=""}function E(){if(!m.value.length)f.value=s("sources.errFormat");else{if(n.formatsOnly)return f.value="",!0;if(!o.value.trim()||!i.value)f.value=s("sources.errRequired");else if(u.value&&!r.value.trim()||c.value&&!a.value.trim())f.value=s("sources.errBaseUrl");else return f.value="",!0}return!1}return t({reset:k,validate:E,payload:w}),(h,g)=>(_(),W("div",dC,[e.formatsOnly?pe("",!0):(_(),W("div",fC,[x("label",pC,S(l(s)("sources.nameLabel")),1),v(l(Tt),{modelValue:o.value,"onUpdate:modelValue":g[0]||(g[0]=T=>o.value=T),placeholder:l(s)("sources.namePh"),autocomplete:"off","aria-label":"name"},null,8,["modelValue","placeholder"])])),x("div",mC,[x("label",hC,S(l(s)("sources.formats")),1),x("div",vC,[x("div",gC,[x("div",yC,[v(l(vo),{"model-value":u.value,disabled:u.value&&!c.value,"aria-label":"openai","onUpdate:modelValue":g[1]||(g[1]=T=>p("openai"))},null,8,["model-value","disabled"]),g[7]||(g[7]=x("span",{class:"text-sm font-medium leading-none"},"openai",-1)),g[8]||(g[8]=x("span",{class:"text-xs text-muted-foreground"},"/chat/completions",-1))]),x("div",bC,[v(l(vo),{modelValue:d.value,"onUpdate:modelValue":g[2]||(g[2]=T=>d.value=T),disabled:!u.value,"aria-label":l(s)("sources.responses")},null,8,["modelValue","disabled","aria-label"]),x("span",{class:Ce(["text-sm leading-none",u.value?"":"text-muted-foreground"])},S(l(s)("sources.responses")),3),g[9]||(g[9]=x("span",{class:"text-xs text-muted-foreground"},"/responses",-1))])]),v(l(Mm)),x("div",_C,[v(l(vo),{"model-value":c.value,disabled:c.value&&!u.value,"aria-label":"anthropic","onUpdate:modelValue":g[3]||(g[3]=T=>p("anthropic"))},null,8,["model-value","disabled"]),g[10]||(g[10]=x("span",{class:"text-sm font-medium leading-none"},"anthropic",-1)),g[11]||(g[11]=x("span",{class:"text-xs text-muted-foreground"},"/messages",-1))])]),x("p",wC,S(l(s)("sources.addHint")),1)]),!e.formatsOnly&&u.value?(_(),W("div",xC,[x("label",kC,S(l(s)("sources.urlLabelOpenai")),1),v(l(Tt),{modelValue:r.value,"onUpdate:modelValue":g[4]||(g[4]=T=>r.value=T),placeholder:l(s)("sources.urlPhOpenai"),autocomplete:"off","aria-label":"openai base url"},null,8,["modelValue","placeholder"]),x("p",CC,S(l(s)("sources.urlHintOpenai")),1)])):pe("",!0),!e.formatsOnly&&c.value?(_(),W("div",SC,[x("label",AC,S(l(s)("sources.urlLabelAnthropic")),1),v(l(Tt),{modelValue:a.value,"onUpdate:modelValue":g[5]||(g[5]=T=>a.value=T),placeholder:l(s)("sources.urlPhAnthropic"),autocomplete:"off","aria-label":"anthropic base url"},null,8,["modelValue","placeholder"]),x("p",EC,S(l(s)("sources.urlHintAnthropic")),1)])):pe("",!0),e.formatsOnly?pe("",!0):(_(),W("div",OC,[x("label",TC,S(l(s)("sources.keyLabel")),1),v(l(Tt),{modelValue:i.value,"onUpdate:modelValue":g[6]||(g[6]=T=>i.value=T),type:"password",placeholder:l(s)("sources.keyPh"),autocomplete:"new-password","aria-label":"api key"},null,8,["modelValue","placeholder"])])),f.value?(_(),W("p",PC,S(f.value),1)):pe("",!0)]))}}),$C={class:"flex shrink-0 items-center gap-2 pr-8"},IC={class:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-primary/15 text-primary"},MC={class:"min-w-0"},RC={class:"min-h-0 flex-1 space-y-4 overflow-y-auto"},LC={key:0,class:"py-4 text-center text-sm text-muted-foreground"},DC={key:1,class:"py-4 text-center text-sm text-destructive"},FC={class:"space-y-1"},NC={key:0,class:"space-y-1.5 rounded-md border bg-muted/30 p-3 text-xs leading-relaxed text-muted-foreground"},qC={key:3,class:"space-y-3 rounded-lg border bg-muted/30 p-4"},BC={class:"flex justify-end gap-2"},VC={key:4,class:"space-y-2"},UC={key:0,class:"flex items-center gap-3"},HC={class:"min-w-0 flex-1"},jC={class:"flex items-center gap-2"},WC={class:"truncate font-medium"},KC={key:0,class:"mt-0.5 truncate font-mono text-xs text-muted-foreground"},zC={key:1,class:"mt-0.5 truncate font-mono text-xs text-muted-foreground"},GC={key:1,class:"space-y-3"},YC={class:"space-y-1.5"},XC={class:"text-xs font-medium text-muted-foreground"},JC={class:"space-y-1.5"},QC={class:"text-xs font-medium text-muted-foreground"},ZC={class:"space-y-3 rounded-md border bg-background/50 p-3"},eS={class:"space-y-2"},tS={class:"flex items-center gap-2.5"},nS={class:"flex items-center gap-2.5 pl-7"},sS={class:"flex items-center gap-2.5"},oS={key:0,class:"space-y-1.5"},rS={class:"text-xs font-medium text-muted-foreground"},aS={class:"text-xs text-muted-foreground"},lS={key:1,class:"space-y-1.5"},iS={class:"text-xs font-medium text-muted-foreground"},uS={class:"text-xs text-muted-foreground"},cS={class:"space-y-1.5"},dS={class:"flex items-center justify-between"},fS={class:"text-xs font-medium text-muted-foreground"},pS={key:0,class:"text-xs text-muted-foreground"},mS={class:"space-y-1.5"},hS={class:"text-xs font-medium text-muted-foreground"},vS={class:"text-xs text-muted-foreground"},gS={class:"flex justify-end gap-2"},yS=Q({__name:"SourcesDialog",props:{open:{type:Boolean,default:!1},openModifiers:{}},emits:ys(["changed"],["update:open"]),setup(e,{emit:t}){const{t:n}=It(),s=_r(e,"open"),o=t,r=N([]),a=N(!1),i=N(""),u=N(null),c=N(!1),d=N(!1),f=N(!1),p=N(null),m=N(""),w=N(""),k=N(""),E=N(""),h=N(""),g=N(!0),T=N(!1),b=N(!1),P=N(!1),A=N({}),C=N(null),I=N(!1),R=N(!1);async function z(){a.value=!0,i.value="";try{const fe=await Ue("GET","/admin/providers");r.value=fe.providers}catch(fe){i.value=fe.message}finally{a.value=!1}}Fe(s,fe=>{fe&&z()});function de(fe){if(fe==="openai"){if(g.value&&!T.value)return;g.value=!g.value}else{if(T.value&&!g.value)return;T.value=!T.value}}function Z(){const fe=[];return g.value&&fe.push("openai"),T.value&&fe.push("anthropic"),fe}async function ie(){var fe,ue;if(!c.value&&(fe=u.value)!=null&&fe.validate()){c.value=!0;try{const ye=await Ue("POST","/admin/providers",u.value.payload);r.value=[...r.value,ye.provider],(ue=u.value)==null||ue.reset(),d.value=!1,Le(n("sources.added"),"success"),o("changed")}catch(ye){Le(ye.message,"error")}finally{c.value=!1}}}function ke(fe){p.value=fe.id,m.value=fe.name,w.value=fe.baseUrlOpenai,k.value=fe.baseUrlAnthropic,E.value="",h.value=fe.rpm?String(fe.rpm):"",g.value=fe.formats.includes("openai"),T.value=fe.formats.includes("anthropic"),b.value=!!fe.supportsResponses}function J(){p.value=null}async function te(fe){if(P.value)return;const ue=Z();if(!m.value){Le(n("sources.errRequired"),"error");return}if(!ue.length){Le(n("sources.errFormat"),"error");return}if(g.value&&!w.value||T.value&&!k.value){Le(n("sources.errBaseUrl"),"error");return}P.value=!0;try{const ye={name:m.value,baseUrlOpenai:w.value,baseUrlAnthropic:k.value,formats:ue,supportsResponses:g.value&&b.value,rpm:Number(h.value)||0};E.value&&(ye.apiKey=E.value);const Ee=await Ue("PUT",`/admin/providers/${fe.id}`,ye);r.value=r.value.map(st=>st.id===fe.id?Ee.provider:st),p.value=null,Le(n("sources.updated"),"success"),o("changed")}catch(ye){Le(ye.message,"error")}finally{P.value=!1}}async function ce(fe){A.value[fe.id]=!0;try{const ue=await Ue("POST",`/admin/providers/${fe.id}/discover`);r.value=r.value.map(ye=>ye.id===fe.id?{...ye,discoveredModels:ue.models}:ye),Le(n("sources.refreshDone",{name:fe.name}),ue.models.length?"success":"default"),o("changed")}catch(ue){Le(ue.message,"error")}finally{A.value[fe.id]=!1}}function ge(fe){C.value=fe,I.value=!0}async function $e(){const fe=C.value;if(!(!fe||R.value)){R.value=!0;try{await Ue("DELETE",`/admin/providers/${fe.id}`),r.value=r.value.filter(ue=>ue.id!==fe.id),Le(n("sources.removed",{name:fe.name}),"success"),o("changed"),I.value=!1}catch(ue){Le(ue.message,"error")}finally{R.value=!1}}}function K(fe){var ue;return((ue=fe.discoveredModels)==null?void 0:ue.length)??0}function he(fe){return K(fe)>0?"found":fe.discoveredAt?"empty":"never"}function ee(fe){const ue=he(fe);return ue==="found"?n("sources.discoveredCount",{n:K(fe)}):n(ue==="empty"?"sources.noModelsFound":"sources.notScanned")}function lt(fe){const ue=he(fe);return ue==="empty"?n("sources.noModelsHint"):ue==="never"?n("sources.notScannedHint"):""}return(fe,ue)=>(_(),W(Se,null,[v(l(Qa),{open:s.value,"onUpdate:open":ue[11]||(ue[11]=ye=>s.value=ye)},{default:y(()=>[v(l(Za),{class:"max-w-xl"},{default:y(()=>[x("div",$C,[x("span",IC,[v(l(wi),{class:"h-4 w-4"})]),x("div",MC,[v(l(el),{class:"text-base"},{default:y(()=>[j(S(l(n)("sources.manage")),1)]),_:1}),v(l(tl),null,{default:y(()=>[j(S(l(n)("sources.subtitle")),1)]),_:1})])]),x("div",RC,[a.value?(_(),W("p",LC,S(l(n)("common.loading")),1)):i.value?(_(),W("p",DC,S(i.value),1)):pe("",!0),x("div",FC,[x("button",{type:"button",class:"inline-flex items-center gap-1 text-xs font-medium text-muted-foreground hover:text-foreground",onClick:ue[0]||(ue[0]=ye=>f.value=!f.value)},[v(l(Tm),{class:"h-3.5 w-3.5"}),j(" "+S(l(n)("sources.baseHelpToggle"))+" ",1),v(l(Xa),{class:Ce(["h-3.5 w-3.5 transition-transform",{"rotate-180":f.value}])},null,8,["class"])]),f.value?(_(),W("div",NC,[x("p",null,S(l(n)("sources.baseHelpSplit")),1),x("p",null,[ue[13]||(ue[13]=x("span",{class:"font-medium text-foreground"},"openai",-1)),j(" — "+S(l(n)("sources.baseHelpOpenai")),1)]),x("p",null,[ue[14]||(ue[14]=x("span",{class:"font-medium text-foreground"},"anthropic",-1)),j(" — "+S(l(n)("sources.baseHelpAnthropic")),1)])])):pe("",!0)]),!d.value&&r.value.length?(_(),D(l(Re),{key:2,variant:"outline",class:"w-full justify-center",onClick:ue[1]||(ue[1]=ye=>d.value=!0)},{default:y(()=>[v(l(es),{class:"h-4 w-4"}),j(S(l(n)("sources.add")),1)]),_:1})):(_(),W("div",qC,[v(yu,{ref_key:"newForm",ref:u},null,512),x("div",BC,[r.value.length?(_(),D(l(Re),{key:0,variant:"ghost",size:"sm",onClick:ue[2]||(ue[2]=ye=>d.value=!1)},{default:y(()=>[j(S(l(n)("sources.cancel")),1)]),_:1})):pe("",!0),v(l(Re),{size:"sm",disabled:c.value,onClick:ie},{default:y(()=>[c.value?(_(),D(l(kt),{key:0,class:"h-4 w-4 animate-spin"})):(_(),D(l(es),{key:1,class:"h-4 w-4"})),j(S(l(n)("sources.addBtn")),1)]),_:1},8,["disabled"])])])),r.value.length?(_(),W("div",VC,[(_(!0),W(Se,null,tt(r.value,ye=>(_(),W("div",{key:ye.id,class:"rounded-lg border p-3"},[p.value!==ye.id?(_(),W("div",UC,[x("div",HC,[x("div",jC,[x("span",WC,S(ye.name),1),(_(!0),W(Se,null,tt(ye.formats,Ee=>(_(),D(l(yt),{key:Ee,variant:"secondary"},{default:y(()=>[j(S(Ee),1)]),_:2},1024))),128)),ye.rpm?(_(),D(l(yt),{key:0,variant:"outline",title:l(n)("sources.rpmBadgeHint")},{default:y(()=>[j(S(l(n)("sources.rpmBadge",{n:ye.rpm})),1)]),_:2},1032,["title"])):pe("",!0),v(l(yt),{variant:"muted",title:lt(ye)},{default:y(()=>[j(S(ee(ye)),1)]),_:2},1032,["title"])]),ye.formats.includes("openai")?(_(),W("div",KC,[ue[15]||(ue[15]=x("span",{class:"opacity-60"},"openai ·",-1)),j(" "+S(ye.baseUrlOpenai),1)])):pe("",!0),ye.formats.includes("anthropic")?(_(),W("div",zC,[ue[16]||(ue[16]=x("span",{class:"opacity-60"},"anthropic ·",-1)),j(" "+S(ye.baseUrlAnthropic),1)])):pe("",!0)]),v(l(hi),null,{default:y(()=>[v(l(vi),null,{default:y(()=>[v(l(Re),{variant:"ghost",size:"icon",class:"h-8 w-8","aria-label":l(n)("sources.moreActions")},{default:y(()=>[v(l(_i),{class:"h-4 w-4"})]),_:1},8,["aria-label"])]),_:1}),v(l(gi),{align:"end"},{default:y(()=>[v(l(Wn),{disabled:A.value[ye.id],onSelect:Ee=>ce(ye)},{default:y(()=>[A.value[ye.id]?(_(),D(l(kt),{key:0,class:"animate-spin"})):(_(),D(l(mr),{key:1})),j(" "+S(l(n)("sources.refreshModels")),1)]),_:2},1032,["disabled","onSelect"]),v(l(Wn),{onSelect:Ee=>ke(ye)},{default:y(()=>[v(l(Pm)),j(" "+S(l(n)("sources.editLabel")),1)]),_:1},8,["onSelect"]),v(l(yi)),v(l(Wn),{class:"text-destructive focus:bg-destructive/10 focus:text-destructive",onSelect:Ee=>ge(ye)},{default:y(()=>[v(l(xi)),j(" "+S(l(n)("sources.deleteLabel")),1)]),_:1},8,["onSelect"])]),_:2},1024)]),_:2},1024)])):(_(),W("div",GC,[x("div",YC,[x("label",XC,S(l(n)("sources.nameLabel")),1),v(l(Tt),{modelValue:m.value,"onUpdate:modelValue":ue[3]||(ue[3]=Ee=>m.value=Ee),placeholder:l(n)("sources.namePh"),autocomplete:"off","aria-label":"name"},null,8,["modelValue","placeholder"])]),x("div",JC,[x("label",QC,S(l(n)("sources.formats")),1),x("div",ZC,[x("div",eS,[x("div",tS,[v(l(vo),{"model-value":g.value,disabled:g.value&&!T.value,"aria-label":"openai","onUpdate:modelValue":ue[4]||(ue[4]=Ee=>de("openai"))},null,8,["model-value","disabled"]),ue[17]||(ue[17]=x("span",{class:"text-sm font-medium leading-none"},"openai",-1)),ue[18]||(ue[18]=x("span",{class:"text-xs text-muted-foreground"},"/chat/completions",-1))]),x("div",nS,[v(l(vo),{modelValue:b.value,"onUpdate:modelValue":ue[5]||(ue[5]=Ee=>b.value=Ee),disabled:!g.value,"aria-label":l(n)("sources.responses")},null,8,["modelValue","disabled","aria-label"]),x("span",{class:Ce(["text-sm leading-none",g.value?"":"text-muted-foreground"])},S(l(n)("sources.responses")),3),ue[19]||(ue[19]=x("span",{class:"text-xs text-muted-foreground"},"/responses",-1))])]),v(l(Mm)),x("div",sS,[v(l(vo),{"model-value":T.value,disabled:T.value&&!g.value,"aria-label":"anthropic","onUpdate:modelValue":ue[6]||(ue[6]=Ee=>de("anthropic"))},null,8,["model-value","disabled"]),ue[20]||(ue[20]=x("span",{class:"text-sm font-medium leading-none"},"anthropic",-1)),ue[21]||(ue[21]=x("span",{class:"text-xs text-muted-foreground"},"/messages",-1))])])]),g.value?(_(),W("div",oS,[x("label",rS,S(l(n)("sources.urlLabelOpenai")),1),v(l(Tt),{modelValue:w.value,"onUpdate:modelValue":ue[7]||(ue[7]=Ee=>w.value=Ee),placeholder:l(n)("sources.urlPhOpenai"),autocomplete:"off","aria-label":"openai base url"},null,8,["modelValue","placeholder"]),x("p",aS,S(l(n)("sources.urlHintOpenai")),1)])):pe("",!0),T.value?(_(),W("div",lS,[x("label",iS,S(l(n)("sources.urlLabelAnthropic")),1),v(l(Tt),{modelValue:k.value,"onUpdate:modelValue":ue[8]||(ue[8]=Ee=>k.value=Ee),placeholder:l(n)("sources.urlPhAnthropic"),autocomplete:"off","aria-label":"anthropic base url"},null,8,["modelValue","placeholder"]),x("p",uS,S(l(n)("sources.urlHintAnthropic")),1)])):pe("",!0),x("div",cS,[x("div",dS,[x("label",fS,S(l(n)("sources.keyLabel")),1),ye.apiKey?(_(),W("span",pS,S(l(n)("sources.currentKeyLabel"))+": "+S(ye.apiKey),1)):pe("",!0)]),v(l(Tt),{modelValue:E.value,"onUpdate:modelValue":ue[9]||(ue[9]=Ee=>E.value=Ee),type:"password",placeholder:l(n)("sources.keyPhEdit"),autocomplete:"new-password","aria-label":"api key"},null,8,["modelValue","placeholder"])]),x("div",mS,[x("label",hS,S(l(n)("sources.rpmLabel")),1),v(l(Tt),{modelValue:h.value,"onUpdate:modelValue":ue[10]||(ue[10]=Ee=>h.value=Ee),type:"number",min:"0",inputmode:"numeric",placeholder:l(n)("sources.rpmPh"),"aria-label":"rpm"},null,8,["modelValue","placeholder"]),x("p",vS,S(l(n)("sources.rpmHint")),1)]),x("div",gS,[v(l(Re),{variant:"ghost",size:"sm",onClick:J},{default:y(()=>[j(S(l(n)("sources.cancel")),1)]),_:1}),v(l(Re),{size:"sm",disabled:P.value,onClick:Ee=>te(ye)},{default:y(()=>[P.value?(_(),D(l(kt),{key:0,class:"h-4 w-4 animate-spin"})):pe("",!0),j(S(l(n)("sources.saveBtn")),1)]),_:1},8,["disabled","onClick"])])]))]))),128))])):pe("",!0)])]),_:1})]),_:1},8,["open"]),v(gu,{open:I.value,"onUpdate:open":ue[12]||(ue[12]=ye=>I.value=ye),variant:"destructive",title:l(n)("sources.remove"),description:C.value?l(n)("sources.confirmRemove",{name:C.value.name}):"","confirm-text":l(n)("sources.remove"),loading:R.value,onConfirm:$e},null,8,["open","title","description","confirm-text","loading"])],64))}}),zo=Q({__name:"Select",props:{open:{type:Boolean},defaultOpen:{type:Boolean},defaultValue:{},modelValue:{},nullableValue:{},by:{type:[String,Function]},dir:{},multiple:{type:Boolean},autocomplete:{},disabled:{type:Boolean},name:{},required:{type:Boolean}},emits:["update:modelValue","update:open"],setup(e,{emit:t}){const o=Rt(e,t);return(r,a)=>(_(),D(l(zx),Ot($t(l(o))),{default:y(()=>[ae(r.$slots,"default")]),_:3},16))}}),Go=Q({__name:"SelectTrigger",props:{disabled:{type:Boolean},reference:{},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},setup(e){const t=e,n=X(()=>{const{class:s,...o}=t;return o});return(s,o)=>(_(),D(l(xk),Ie(n.value,{class:l(Ye)("flex h-9 w-full items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-1 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",t.class)}),{default:y(()=>[ae(s.$slots,"default"),v(l(dk),{"as-child":""},{default:y(()=>[v(l(Xa),{class:"h-4 w-4 opacity-50"})]),_:1})]),_:3},16,["class"]))}}),Yo=Q({__name:"SelectValue",props:{placeholder:{},asChild:{type:Boolean},as:{}},setup(e){const t=e;return(n,s)=>(_(),D(l(Ck),Ot($t(t)),{default:y(()=>[ae(n.$slots,"default")]),_:3},16))}}),Xo=Q({__name:"SelectContent",props:{forceMount:{type:Boolean},position:{default:"popper"},bodyLock:{type:Boolean},memoDependencies:{},side:{},sideOffset:{},sideFlip:{type:Boolean},align:{},alignOffset:{},alignFlip:{type:Boolean},avoidCollisions:{type:Boolean},collisionBoundary:{},collisionPadding:{},arrowPadding:{},hideShiftedArrow:{type:Boolean},sticky:{},hideWhenDetached:{type:Boolean},positionStrategy:{},updatePositionStrategy:{},disableUpdateOnLayoutShift:{type:Boolean},prioritizePosition:{type:Boolean},reference:{},dir:{},asChild:{type:Boolean},as:{},disableOutsidePointerEvents:{type:Boolean},class:{type:[Boolean,null,String,Object,Array]}},emits:["closeAutoFocus","escapeKeyDown","pointerDownOutside"],setup(e,{emit:t}){const n=e,s=t,o=X(()=>{const{class:a,...i}=n;return i}),r=Rt(o,s);return(a,i)=>(_(),D(l(_k),null,{default:y(()=>[v(l(uk),Ie(l(r),{class:l(Ye)("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md",n.position==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:translate-x-1 data-[side=right]:-translate-x-1 data-[side=top]:-translate-y-1",n.class)}),{default:y(()=>[v(l(Ak),{class:Ce(l(Ye)("p-1",n.position==="popper"&&"w-full min-w-[var(--reka-select-trigger-width)]"))},{default:y(()=>[ae(a.$slots,"default")]),_:3},8,["class"])]),_:3},16,["class"])]),_:3}))}}),bS={class:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center"},ln=Q({__name:"SelectItem",props:{value:{},disabled:{type:Boolean},textValue:{},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},setup(e){const t=e,n=X(()=>{const{class:s,...o}=t;return o});return(s,o)=>(_(),D(l(mk),Ie(n.value,{class:l(Ye)("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t.class)}),{default:y(()=>[x("span",bS,[v(l(vk),null,{default:y(()=>[v(l(Pn),{class:"h-4 w-4"})]),_:1})]),v(l(yk),null,{default:y(()=>[ae(s.$slots,"default")]),_:3})]),_:3},16,["class"]))}}),_S={key:0,class:"mt-1.5 flex flex-wrap gap-1"},wS=["aria-label","onClick"],xS=["onMousedown"],kS={key:1,class:"h-3.5 w-3.5 shrink-0","aria-hidden":"true"},CS={class:"flex-1 truncate"},SS={key:0,class:"px-2 py-1 text-xs text-muted-foreground"},AS={key:1,class:"px-2 py-1 text-xs text-muted-foreground"},Rm=Q({__name:"Combobox",props:{modelValue:{},options:{},placeholder:{},limit:{default:300},multi:{type:Boolean}},emits:["update:modelValue"],setup(e,{emit:t}){const n=e,s=t,{t:o}=It(),r=N(null),a=N(!1),i=N(""),u=X(()=>Array.isArray(n.modelValue)?n.modelValue:[]),c=X(()=>{const b=(n.multi?i.value:String(n.modelValue??"")).trim().toLowerCase();return b?n.options.filter(P=>P.toLowerCase().includes(b)):n.options}),d=X(()=>c.value.slice(0,n.limit)),f=X(()=>c.value.length-d.value.length);function p(b){n.multi?(i.value=String(b),a.value=!0):(s("update:modelValue",String(b)),a.value=!0)}function m(b){if(n.multi){const P=u.value.includes(b)?u.value.filter(A=>A!==b):[...u.value,b];s("update:modelValue",P)}else s("update:modelValue",b),a.value=!1}function w(b){s("update:modelValue",u.value.filter(P=>P!==b))}function k(b){var A;const P=b.relatedTarget;P&&((A=r.value)!=null&&A.contains(P))||(a.value=!1)}const E=N(null),h=X(()=>Math.min(Math.max(d.value.length*34+8,48),224));function g(){var A;const b=(A=r.value)==null?void 0:A.getBoundingClientRect();if(!b)return;const P=b.bottom+6+h.value<=window.innerHeight;E.value={top:P?b.bottom+6:Math.max(b.top-6-h.value,8),left:Math.max(Math.min(b.left,window.innerWidth-b.width-8),8),width:b.width}}function T(){a.value&&g()}return Fe(a,async b=>{b?(await vt(),g(),window.addEventListener("scroll",T,!0),window.addEventListener("resize",T)):(window.removeEventListener("scroll",T,!0),window.removeEventListener("resize",T))}),Fe(h,()=>a.value&&g()),yr(()=>{window.removeEventListener("scroll",T,!0),window.removeEventListener("resize",T)}),(b,P)=>(_(),W("div",{ref_key:"rootRef",ref:r,class:"relative",onFocusin:P[0]||(P[0]=A=>a.value=!0),onFocusout:k},[v(l(Tt),{"model-value":e.multi?i.value:e.modelValue,placeholder:e.placeholder,autocomplete:"off",spellcheck:"false","onUpdate:modelValue":p},null,8,["model-value","placeholder"]),e.multi&&u.value.length?(_(),W("div",_S,[(_(!0),W(Se,null,tt(u.value,A=>(_(),W("span",{key:A,class:"inline-flex items-center gap-1 rounded-md border-transparent bg-primary text-primary-foreground shadow-sm px-2 py-0.5 font-mono text-xs"},[j(S(A)+" ",1),x("button",{type:"button",class:"opacity-70 hover:opacity-100","aria-label":l(o)("common.dismiss"),onClick:C=>w(A)},[v(l(Ja),{class:"h-3 w-3"})],8,wS)]))),128))])):pe("",!0),(_(),D(Pa,{to:"body"},[a.value&&(d.value.length||e.multi&&i.value.trim())?(_(),W("ul",{key:0,class:"fixed z-[60] max-h-56 overflow-auto rounded-md border bg-popover p-1 text-sm shadow-md",style:dn(E.value?{top:`${E.value.top}px`,left:`${E.value.left}px`,width:`${E.value.width}px`}:void 0)},[(_(!0),W(Se,null,tt(d.value,A=>(_(),W("li",{key:A},[x("button",{type:"button",class:Ce(["flex w-full items-center gap-2 rounded px-2 py-1.5 text-left font-mono hover:bg-accent hover:text-accent-foreground",A===e.modelValue||u.value.includes(A)?"text-primary":""]),onMousedown:Gt(C=>m(A),["prevent"])},[A===e.modelValue||u.value.includes(A)?(_(),D(l(Pn),{key:0,class:"h-3.5 w-3.5 shrink-0"})):(_(),W("span",kS)),x("span",CS,S(A),1)],42,xS)]))),128)),d.value.length?f.value>0?(_(),W("li",AS,S(l(o)("combobox.more",{n:f.value})),1)):pe("",!0):(_(),W("li",SS,S(l(o)("combobox.noMatch")),1))],4)):pe("",!0)]))],544))}}),ES={class:"flex shrink-0 items-center gap-2 pr-8"},OS={class:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-primary/15 text-primary"},TS={class:"min-w-0"},PS={class:"min-h-0 flex-1 space-y-3 overflow-y-auto"},$S={class:"space-y-1.5"},IS={class:"text-xs font-medium text-muted-foreground"},MS={class:"text-xs text-muted-foreground"},RS={class:"font-medium text-foreground"},LS={key:0,class:"space-y-3 rounded-lg border bg-muted/30 p-4"},DS={class:"text-xs text-muted-foreground"},FS={key:1,class:"space-y-1.5"},NS={class:"flex items-center justify-between gap-2"},qS={class:"text-xs font-medium text-muted-foreground"},BS={key:0,class:"text-xs text-muted-foreground"},VS={key:0,class:"text-xs text-muted-foreground"},US={class:"space-y-1.5"},HS={class:"text-xs font-medium text-muted-foreground"},jS=["placeholder"],WS={key:0,class:"text-xs text-muted-foreground"},KS={class:"flex shrink-0 justify-end gap-2"},Pl="__new__",bd="__none__",zS=Q({__name:"AddModelsDialog",props:ys({providers:{}},{open:{type:Boolean,default:!1},openModifiers:{}}),emits:ys(["changed"],["update:open"]),setup(e,{emit:t}){const{t:n}=It(),s=e,o=_r(e,"open"),r=t,a=N(""),i=N(""),u=N(!1),c=N(null),d=N([]),f=N([]);Fe(o,P=>{var A;P&&(a.value=s.providers.length?s.providers[0].id:Pl,i.value="",d.value=[],f.value=[],(A=c.value)==null||A.reset())}),Fe(a,()=>{d.value=[]});const p=X(()=>a.value===Pl),m=X(()=>a.value===bd);function w(P){const A=[...P.formats];return P.supportsResponses&&!A.includes("responses")&&A.push("responses"),A}const k=X(()=>{var A,C;if(p.value||m.value)return w({formats:((A=c.value)==null?void 0:A.payload.formats)??[],supportsResponses:(C=c.value)==null?void 0:C.payload.supportsResponses});const P=s.providers.find(I=>I.id===a.value);return P?w(P):[]}),E=X(()=>{const P=new Set,A=[];for(const C of i.value.split(/[\s,;]+/)){const I=C.trim();I&&!P.has(I)&&(P.add(I),A.push(I))}return A}),h=X(()=>{const P=new Set,A=[];for(const C of[...E.value,...d.value])P.has(C)||(P.add(C),A.push(C));return A}),g=X(()=>{if(m.value)return[];const P=s.providers.find(A=>A.id===a.value);return P?P.discoveredModels??[]:f.value}),T=X(()=>!!a.value&&h.value.length>0&&k.value.length>0&&!u.value);async function b(){var P,A,C;if(T.value&&!(p.value&&!((P=c.value)!=null&&P.validate()))){u.value=!0;try{let I=a.value,R=[],z=!1;if(p.value){const J=await Ue("POST","/admin/providers",c.value.payload);I=J.provider.id,a.value=I,f.value=J.discovered??J.provider.discoveredModels??[],R=w(J.provider),z=!0,Le(n("sources.added"),"success")}else if(m.value)R=w({formats:((A=c.value)==null?void 0:A.payload.formats)??[],supportsResponses:(C=c.value)==null?void 0:C.payload.supportsResponses});else{const J=s.providers.find(te=>te.id===I);R=J?w(J):[]}const de=[];for(const J of h.value)for(const te of R)de.push({name:J,slot:te});const Z=await Promise.allSettled(de.map(J=>Ue("POST","/admin/models",{name:J.name,format:J.slot,providers:m.value?[]:[I]}))),ie=new Set;let ke=0;if(Z.forEach((J,te)=>{J.status==="fulfilled"?ie.add(de[te].name):ke++}),ie.size&&Le(n("models.addedToast",{n:ie.size}),"success"),(z||ie.size)&&r("changed"),ke){const J=h.value.filter(te=>!ie.has(te));Le(n("models.addModelsFailed",{n:J.length}),"error"),i.value=J.join(`
283
- `),d.value=[]}else o.value=!1}finally{u.value=!1}}}return(P,A)=>(_(),D(l(Qa),{open:o.value,"onUpdate:open":A[4]||(A[4]=C=>o.value=C)},{default:y(()=>[v(l(Za),{class:Ce(p.value?"max-w-lg":"max-w-md")},{default:y(()=>[x("div",ES,[x("span",OS,[v(l(es),{class:"h-4 w-4"})]),x("div",TS,[v(l(el),{class:"text-base"},{default:y(()=>[j(S(l(n)("models.addModels")),1)]),_:1}),v(l(tl),null,{default:y(()=>[j(S(l(n)("models.addModelsDesc")),1)]),_:1})])]),x("div",PS,[x("div",$S,[x("label",IS,S(l(n)("models.providerLabel")),1),v(l(zo),{modelValue:a.value,"onUpdate:modelValue":A[0]||(A[0]=C=>a.value=C)},{default:y(()=>[v(l(Go),null,{default:y(()=>[v(l(Yo),{placeholder:l(n)("models.providerPh")},null,8,["placeholder"])]),_:1}),v(l(Xo),null,{default:y(()=>[v(l(ln),{value:Pl},{default:y(()=>[j(S(l(n)("models.newSourceOpt")),1)]),_:1}),v(l(ln),{value:bd},{default:y(()=>[j(S(l(n)("models.noneSourceOpt")),1)]),_:1}),(_(!0),W(Se,null,tt(e.providers,C=>(_(),D(l(ln),{key:C.id,value:C.id},{default:y(()=>[j(S(C.name),1)]),_:2},1032,["value"]))),128))]),_:1})]),_:1},8,["modelValue"]),x("p",MS,[j(S(l(n)("models.addModelsSlotsHint"))+" ",1),x("span",RS,S(k.value.join(" / ")||"—"),1)])]),p.value||m.value?(_(),W("div",LS,[x("p",DS,S(p.value?l(n)("models.addModelsNewHint"):l(n)("models.addModelsNoneHint")),1),v(yu,{ref_key:"newForm",ref:c,"formats-only":m.value},null,8,["formats-only"])])):pe("",!0),!p.value&&!m.value?(_(),W("div",FS,[x("div",NS,[x("label",qS,S(l(n)("models.addModelsDiscoveredLabel")),1),g.value.length?(_(),W("span",BS,S(l(n)("models.addModelsDiscoveredHint")),1)):pe("",!0)]),g.value.length?(_(),D(Rm,{key:1,modelValue:d.value,"onUpdate:modelValue":A[1]||(A[1]=C=>d.value=C),multi:"",options:g.value,placeholder:l(n)("models.searchPh")},null,8,["modelValue","options","placeholder"])):(_(),W("p",VS,S(l(n)("models.addModelsDiscoveredEmpty")),1))])):pe("",!0),x("div",US,[x("label",HS,S(l(n)("models.namesLabel")),1),yo(x("textarea",{"onUpdate:modelValue":A[2]||(A[2]=C=>i.value=C),placeholder:l(n)("models.addModelsNamesPh"),rows:"6",spellcheck:"false",class:"flex w-full resize-y rounded-md border border-input bg-transparent px-3 py-2 font-mono text-sm shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50"},null,8,jS),[[$g,i.value]]),h.value.length?(_(),W("p",WS,S(l(n)("models.addModelsCount",{n:h.value.length})),1)):pe("",!0)])]),x("div",KS,[v(l(Re),{variant:"outline",disabled:u.value,onClick:A[3]||(A[3]=C=>o.value=!1)},{default:y(()=>[j(S(l(n)("common.cancel")),1)]),_:1},8,["disabled"]),v(l(Re),{disabled:!T.value,onClick:b},{default:y(()=>[u.value?(_(),D(l(kt),{key:0,class:"h-4 w-4 animate-spin"})):(_(),D(l(es),{key:1,class:"h-4 w-4"})),j(" "+S(l(n)("models.addModelsBtn")),1)]),_:1},8,["disabled"])])]),_:1},8,["class"])]),_:1},8,["open"]))}}),GS={class:"flex shrink-0 items-center gap-2 pr-8"},YS={class:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-primary/15 text-primary"},XS={class:"min-w-0"},JS={class:"min-h-0 flex-1 space-y-3 overflow-y-auto"},QS={class:"space-y-1.5"},ZS={class:"text-xs font-medium text-muted-foreground"},eA={key:0,class:"text-xs text-muted-foreground"},tA={key:1,class:"text-xs text-muted-foreground"},nA={class:"font-medium text-foreground"},sA={key:2,class:"text-xs text-amber-600 dark:text-amber-500"},oA={key:0,class:"space-y-3 rounded-lg border bg-muted/30 p-4"},rA={class:"text-xs text-muted-foreground"},aA={class:"space-y-1.5"},lA={class:"text-xs font-medium text-muted-foreground"},iA={class:"text-xs text-muted-foreground"},uA={class:"flex shrink-0 justify-end gap-2"},$l="__new__",cA=Q({__name:"AddSourceDialog",props:ys({modelName:{},providers:{},enabledFormats:{},chainByFormat:{}},{open:{type:Boolean,default:!1},openModifiers:{}}),emits:ys(["added"],["update:open"]),setup(e,{emit:t}){const{t:n}=It(),s=e,o=_r(e,"open"),r=t,a=encodeURIComponent,i=N(""),u=N(""),c=N(!1),d=N(null),f=N(null);function p(I,R){return R==="responses"?!!I.supportsResponses:I.formats.includes(R)}const m=X(()=>{var I,R;return h.value?((I=d.value)==null?void 0:I.payload)??null:s.providers.find(z=>z.id===i.value)??(((R=f.value)==null?void 0:R.id)===i.value?f.value:null)});function w(I){const R=s.providers.find(z=>z.id===I);return R?s.enabledFormats.filter(z=>p(R,z)):[]}function k(I){return s.enabledFormats.filter(R=>(s.chainByFormat[R]??[]).includes(I))}const E=X(()=>s.providers.filter(I=>s.enabledFormats.some(R=>p(I,R))).sort((I,R)=>I.name.localeCompare(R.name))),h=X(()=>i.value===$l),g=X(()=>{var I,R;return h.value?((I=f.value)==null?void 0:I.discoveredModels)??[]:((R=s.providers.find(z=>z.id===i.value))==null?void 0:R.discoveredModels)??[]}),T={openai:"models.fmtOpenaiShort",anthropic:"models.fmtAnthropicShort",responses:"models.fmtResponsesShort"},b=X(()=>{if(!i.value)return[];if(h.value){const I=m.value;return I?s.enabledFormats.filter(R=>p(I,R)).map(R=>n(T[R]??R)):[]}return w(i.value).map(I=>n(T[I]??I))}),P=X(()=>!!i.value&&!h.value&&k(i.value).length>0),A=X(()=>!!i.value&&!c.value);Fe(o,I=>{var R,z;I&&(i.value=((R=E.value[0])==null?void 0:R.id)??$l,u.value="",f.value=null,(z=d.value)==null||z.reset())});async function C(){var I;if(A.value&&!(h.value&&!((I=d.value)!=null&&I.validate()))){c.value=!0;try{let R=i.value,z=!1;if(h.value){const te=await Ue("POST","/admin/providers",d.value.payload);R=te.provider.id,i.value=R,f.value={...te.provider,discoveredModels:te.discovered??te.provider.discoveredModels??[]},z=!0,Le(n("sources.added"),"success")}const de=f.value&&f.value.id===R?f.value:s.providers.find(te=>te.id===R),Z=de?s.enabledFormats.filter(te=>p(de,te)):[],ie=u.value.trim();(await Promise.allSettled(Z.map(te=>Ue("POST",`/admin/models/${a(s.modelName)}/providers`,{format:te,providerId:R,model:ie||void 0})))).filter(te=>te.status==="rejected").length?(Le(n("models.addSourcePartial"),"error"),z&&r("added")):(Le(n("models.sourceAdded"),"success"),r("added"),o.value=!1)}finally{c.value=!1}}}return(I,R)=>(_(),D(l(Qa),{open:o.value,"onUpdate:open":R[3]||(R[3]=z=>o.value=z)},{default:y(()=>[v(l(Za),{class:Ce(h.value?"max-w-lg":"max-w-md")},{default:y(()=>[x("div",GS,[x("span",YS,[v(l(es),{class:"h-4 w-4"})]),x("div",XS,[v(l(el),{class:"text-base"},{default:y(()=>[j(S(l(n)("models.addSourceTitle")),1)]),_:1}),v(l(tl),null,{default:y(()=>[j(S(l(n)("models.addSourceDesc")),1)]),_:1})])]),x("div",JS,[x("div",QS,[x("label",ZS,S(l(n)("models.providerLabel")),1),v(l(zo),{modelValue:i.value,"onUpdate:modelValue":R[0]||(R[0]=z=>i.value=z)},{default:y(()=>[v(l(Go),null,{default:y(()=>[v(l(Yo),{placeholder:l(n)("models.providerPh")},null,8,["placeholder"])]),_:1}),v(l(Xo),null,{default:y(()=>[v(l(ln),{value:$l},{default:y(()=>[j(S(l(n)("models.newSourceOpt")),1)]),_:1}),(_(!0),W(Se,null,tt(E.value,z=>(_(),D(l(ln),{key:z.id,value:z.id},{default:y(()=>[j(S(z.name),1)]),_:2},1032,["value"]))),128))]),_:1})]),_:1},8,["modelValue"]),E.value.length?pe("",!0):(_(),W("p",eA,S(l(n)("models.addSourceNone")),1)),b.value.length?(_(),W("p",tA,[j(S(l(n)("models.addSourceTargetsHint"))+" ",1),x("span",nA,S(b.value.join(" / ")),1)])):pe("",!0),P.value?(_(),W("p",sA,S(l(n)("models.addSourceDupHint")),1)):pe("",!0)]),h.value?(_(),W("div",oA,[x("p",rA,S(l(n)("models.addSourceNewHint")),1),v(yu,{ref_key:"newForm",ref:d},null,512)])):pe("",!0),x("div",aA,[x("label",lA,S(l(n)("models.upstreamLabel")),1),v(Rm,{modelValue:u.value,"onUpdate:modelValue":R[1]||(R[1]=z=>u.value=z),options:g.value,placeholder:l(n)("models.upstreamPh")},null,8,["modelValue","options","placeholder"]),x("p",iA,S(l(n)("models.upstreamHint")),1)])]),x("div",uA,[v(l(Re),{variant:"outline",disabled:c.value,onClick:R[2]||(R[2]=z=>o.value=!1)},{default:y(()=>[j(S(l(n)("common.cancel")),1)]),_:1},8,["disabled"]),v(l(Re),{disabled:!A.value,onClick:C},{default:y(()=>[c.value?(_(),D(l(kt),{key:0,class:"h-4 w-4 animate-spin"})):(_(),D(l(es),{key:1,class:"h-4 w-4"})),j(" "+S(l(n)("models.addToChain")),1)]),_:1},8,["disabled"])])]),_:1},8,["class"])]),_:1},8,["open"]))}}),dA={class:"space-y-4"},fA={class:"flex h-11 w-11 items-center justify-center rounded-xl bg-primary/15 text-primary"},pA={class:"space-y-1"},mA={class:"font-medium"},hA={class:"max-w-sm text-sm text-muted-foreground"},vA={class:"flex flex-wrap items-center gap-2"},gA={class:"relative min-w-[180px] flex-1"},yA={class:"text-xs text-muted-foreground"},bA={key:0,class:"py-6 text-center text-sm text-muted-foreground"},_A={key:1,class:"py-6 text-center text-sm text-destructive"},wA={key:0,class:"relative overflow-hidden rounded-lg border border-border/60 bg-card"},xA={class:"flex items-center gap-2.5 border-b border-border/60 bg-muted/30 px-3 py-2"},kA={class:"text-sm font-semibold"},CA={class:"ml-auto inline-flex items-center rounded-md bg-primary/15 px-1.5 py-0.5 text-xs font-medium tabular-nums text-primary"},SA={class:"divide-y divide-border"},AA={class:"flex items-center gap-3"},EA=["aria-expanded","aria-label","onClick","onKeydown"],OA={class:"flex min-w-0 flex-1 flex-col items-start"},TA={class:"flex w-full items-center gap-1.5"},PA={class:"truncate font-mono text-sm font-medium"},$A=["title","aria-label","onClick"],IA={class:"w-full truncate text-xs text-muted-foreground"},MA={class:"flex shrink-0 items-center gap-1.5"},RA=["disabled","title","aria-label","onClick"],LA={key:0,class:"mt-2 space-y-3 rounded-md border bg-muted/30 p-2"},DA={class:"flex items-center gap-2 px-1"},FA={class:"text-xs font-semibold"},NA={class:"font-mono text-[11px] text-muted-foreground"},qA={key:0,class:"flex items-start gap-2 rounded bg-muted px-2 py-1.5 text-xs text-muted-foreground"},BA={class:"shrink-0 font-medium"},VA={key:1,class:"px-1 py-1 text-xs text-muted-foreground"},UA={class:"w-4 shrink-0 text-right text-xs text-muted-foreground"},HA={class:"flex items-center gap-1.5 text-sm"},jA={key:2,class:"flex items-center gap-1"},WA=["value","placeholder","aria-label","title","onKeyup","onBlur"],KA=["title","onClick"],zA={key:7,class:"flex items-center gap-1"},GA=["value","placeholder","aria-label","title","onInput","onKeyup","onBlur"],YA=["title","onClick"],XA={class:"ml-auto flex items-center gap-0.5 opacity-0 transition-opacity focus-within:opacity-100 group-hover:opacity-100"},JA={key:0,class:"flex justify-center pt-1"},QA={class:"relative overflow-hidden rounded-lg border border-border/60 bg-card"},ZA={class:"flex items-center gap-2.5 border-b border-border/60 bg-muted/30 px-3 py-2"},eE={class:"text-sm font-semibold"},tE={class:"ml-auto inline-flex items-center rounded-md bg-muted px-1.5 py-0.5 text-xs font-medium tabular-nums text-muted-foreground"},nE={key:0},sE={key:0,class:"py-3 text-center text-xs text-muted-foreground"},oE={key:1,class:"divide-y divide-border"},rE=["aria-expanded","aria-label","onClick"],aE={class:"text-sm font-medium"},lE={class:"inline-flex items-center rounded-md bg-muted px-1.5 py-0.5 text-xs font-medium tabular-nums text-muted-foreground"},iE={key:0,class:"divide-y divide-border/50 bg-muted/10"},uE={class:"flex min-w-0 items-center gap-1.5"},cE={class:"truncate font-mono text-sm"},dE=["title","aria-label","onClick"],fE={class:"flex shrink-0 items-center gap-1.5"},pE=["disabled","title","aria-label","onClick"],mE=8,hE=Q({__name:"Models",setup(e){const{t}=It(),n=["openai","anthropic","responses"],s=N([]),o=N([]),r=N(""),a=N(!1),i=N(""),u=N(!0),c=N(new Set),d=N(!1),f=N(!1),p=N(!1),m=N(!1),w=N({}),k=N({}),E=N({}),h=N({}),g=N({}),T=N({}),b=N({}),P=N({}),A=N(""),C=N(null),I=N(!1),R={mounted:B=>B.focus()},z=N(null),de=N(!1),Z=encodeURIComponent;async function ie(){a.value=!0,r.value="";try{const[B,q]=await Promise.all([Ue("GET","/admin/models"),Ue("GET","/admin/providers")]);s.value=B.models,o.value=q.providers}catch(B){r.value=B.message}finally{a.value=!1}}const ke=X(()=>new Map(o.value.map(B=>[B.id,B]))),J=X(()=>{const B=new Map;for(const q of o.value)for(const ne of q.discoveredModels??[]){const F=B.get(ne);F?F.push(q.id):B.set(ne,[q.id])}return B}),te=X(()=>{const B=new Set;for(const ne of o.value)for(const F of ne.discoveredModels??[])B.add(F);for(const ne of s.value)B.add(ne.name);const q=ne=>({enabled:(ne==null?void 0:ne.enabled)??!1,chain:((ne==null?void 0:ne.providers)??[]).map(F=>({id:F.id,name:F.name,model:F.model}))});return[...B].map(ne=>{const F=s.value.find(Ae=>Ae.name===ne),_e=(J.value.get(ne)??[]).map(Ae=>ke.value.get(Ae)).filter(Ae=>!!Ae).map(Ae=>({id:Ae.id,name:Ae.name,formats:Ae.formats,supportsResponses:Ae.supportsResponses}));return{name:ne,openai:q(F==null?void 0:F.openai),anthropic:q(F==null?void 0:F.anthropic),responses:q(F==null?void 0:F.responses),offering:_e}})});function ce(B){return n.filter(q=>B[q].enabled)}function ge(B){return n.filter(q=>B.offering.some(ne=>oe(ne,q)))}function $e(B){return ge(B).filter(q=>!B[q].enabled)}function K(B,q){return B[q].enabled?"enabled":ge(B).includes(q)?"enableable":"unsupported"}function he(B,q){return B.offering.filter(ne=>oe(ne,q)).map(ne=>ne.id)}const ee=X(()=>{const B=i.value.trim().toLowerCase();return te.value.filter(q=>!B||q.name.toLowerCase().includes(B))}),lt=X(()=>ee.value.filter(B=>B.openai.enabled||B.anthropic.enabled||B.responses.enabled)),fe=X(()=>ee.value.filter(B=>!(B.openai.enabled||B.anthropic.enabled||B.responses.enabled)&&ge(B).length>0)),ue=["embed","whisper","tts","dall-e","dall_e","image","moderation","audio","transcribe","rerank","realtime","sora"];function ye(B){const q=B.toLowerCase();return ue.some(ne=>q.includes(ne))}const Ee=N(!0),st=X(()=>fe.value.filter(B=>ye(B.name)).length),qe=X(()=>Ee.value?fe.value.filter(B=>!ye(B.name)):fe.value),ft=X(()=>{const B=[];for(const q of o.value){const ne=qe.value.filter(F=>F.offering.some(_e=>_e.id===q.id)).sort((F,_e)=>F.name.localeCompare(_e.name));ne.length&&B.push({source:q,rows:ne})}return B}),St=N({});function M(B,q){return i.value.trim()?!0:B in St.value?St.value[B]:q<=mE}function L(B,q){i.value.trim()||(St.value={...St.value,[B]:!M(B,q)})}function G(B){const q=ce(B);return o.value.filter(ne=>q.some(F=>oe(ne,F)))}function le(B){const q={};for(const ne of n)q[ne]=B[ne].chain.map(F=>F.id);return q}function oe(B,q){return q==="responses"?!!B.supportsResponses:B.formats.includes(q)}const se={openai:{key:"models.fmtOpenai",chip:"models.fmtOpenaiShort",endpoint:"/chat/completions"},anthropic:{key:"models.fmtAnthropic",chip:"models.fmtAnthropicShort",endpoint:"/messages"},responses:{key:"models.fmtResponses",chip:"models.fmtResponsesShort",endpoint:"/responses"}};function O(B){return c.value.has(B)}function $(B){const q=new Set(c.value);q.has(B)?q.delete(B):q.add(B),c.value=q}async function V(B){const q=await Xi(B);Le(t(q?"connect.copied":"connect.copyFailed"),q?"success":"error")}function H(B,q){B.target===B.currentTarget&&(B.key==="Enter"||B.key===" ")&&(B.preventDefault(),$(q))}function me(B){return B.length?B.map(q=>q.name).join(" → "):t("models.noSourcesShort")}function re(B){return ce(B).map(q=>`${t(se[q].chip)}: ${me(B[q].chain)}`).join(" · ")}function U(B,q){const ne=B[q].chain;if(!ne.length)return!1;const F=_e=>{var Ae;return((Ae=ke.value.get(_e))==null?void 0:Ae.discoveredModels)??[]};return!ne.some(_e=>F(_e.id).includes(_e.model??B.name))&&ne.some(_e=>F(_e.id).length>0)}function Y(B){return ce(B).some(q=>U(B,q))}function ve(B){let q=!1,ne=null,F=null;for(const _e of ce(B)){const Ae=`${B.name}:${_e}`;h.value[Ae]&&(q=!0);const ot=b.value[Ae];ot!=null&&ot.ok&&!ne?ne=ot:ot&&!ot.ok&&!F&&(F=ot)}return q?{state:"testing"}:ne?{state:"ok",provider:ne.provider}:F?{state:"fail",status:F.status,error:F.error}:null}function Te(B,q){const ne=K(B,q);return ne==="enabled"?`border-transparent ${tn[q].solid} text-white shadow-sm`:ne==="enableable"?"border-dashed border-input text-muted-foreground hover:bg-accent hover:text-accent-foreground":"border-transparent text-muted-foreground/40"}function De(B,q){const ne=K(B,q);return ne==="enabled"?`${t(se[q].key)} · ${t("models.chipOn")}`:ne==="enableable"?`${t(se[q].key)} · ${t("models.chipOff")}`:`${t(se[q].key)} · ${t("models.chipNa")}`}async function Xe(B,q){B[q].enabled?await Zt(B,q):await je(B,q)}async function je(B,q){const ne=`${B.name}:${q}`;k.value[ne]=!0;const F=B.offering.filter(ot=>oe(ot,q)),_e=F.map(ot=>({id:ot.id,name:ot.name})),Ae=s.value.find(ot=>ot.name===B.name);if(Ae){Ae[q].enabled=!0;for(const ot of _e)Ae[q].providers.find($s=>$s.id===ot.id)||Ae[q].providers.push(ot)}else s.value.push({name:B.name,openai:{enabled:q==="openai",providers:q==="openai"?_e:[]},anthropic:{enabled:q==="anthropic",providers:q==="anthropic"?_e:[]},responses:{enabled:q==="responses",providers:q==="responses"?_e:[]}});try{await Ue("POST","/admin/models",{name:B.name,format:q,providers:F.map(ot=>ot.id)}),Le(t("models.enabledToast",{name:`${B.name} [${q}]`}),"success")}catch(ot){await ie(),Le(ot.message,"error")}finally{k.value[ne]=!1}}async function Kt(){if(f.value)return;f.value=!0;const B=[];for(const F of qe.value)for(const _e of $e(F))B.push({name:F.name,fmt:_e,providers:he(F,_e)});for(const F of B)k.value[`${F.name}:${F.fmt}`]=!0;const q=await Promise.allSettled(B.map(F=>Ue("POST","/admin/models",{name:F.name,format:F.fmt,providers:F.providers})));for(const F of B)k.value[`${F.name}:${F.fmt}`]=!1;if(await ie(),f.value=!1,!B.length)return;const ne=q.filter(F=>F.status==="rejected").length;ne?ne===B.length?Le(t("models.enableAllFailed"),"error"):Le(t("models.enableAllPartial",{failed:ne}),"error"):Le(t("models.enableAllDone"),"success")}async function Zt(B,q){const ne=s.value.find(F=>F.name===B.name);ne&&(ne[q].enabled=!1);try{await Ue("POST",`/admin/models/${Z(B.name)}/disable`,{format:q}),Le(t("models.disabledToast",{name:`${B.name} [${q}]`}),"success")}catch(F){await ie(),Le(F.message,"error")}}function Ts(B){z.value=B,de.value=!0}async function Ar(B,q){const ne=`${B.name}:${q}`;if(!h.value[ne]){h.value[ne]=!0;try{const F=await Ue("POST",`/admin/models/${Z(B.name)}/test?format=${q}`);b.value[ne]=F.result}catch(F){b.value[ne]={ok:!1,status:0,format:q,error:F.message}}finally{h.value[ne]=!1}}}async function Bt(B){const q=ce(B);q.length&&await Promise.all(q.map(ne=>Ar(B,ne)))}async function rn(B,q,ne){const F=`${B.name}:${q}:${ne}`;if(!g.value[F]){g.value[F]=!0;try{const _e=await Ue("POST",`/admin/models/${Z(B.name)}/providers/test?format=${q}&index=${ne}`);T.value[F]=_e.result}catch(_e){T.value[F]={ok:!1,status:0,format:q,error:_e.message}}finally{g.value[F]=!1}}}async function Er(){const B=z.value;if(B){w.value[B.name]=!0;try{await Ue("DELETE",`/admin/models/${Z(B.name)}`),s.value=s.value.filter(q=>q.name!==B.name),Le(t("models.removedToast",{name:B.name}),"success"),de.value=!1}catch(q){Le(q.message,"error")}finally{w.value[B.name]=!1}}}async function Ao(B,q,ne){const F=s.value.find(Ae=>Ae.name===B.name);if(!F)return;const _e=F[ne].providers.slice();F[ne].providers=q.map(Ae=>_e[Ae]);try{await Ue("PUT",`/admin/models/${Z(B.name)}/priority`,{format:ne,order:q})}catch(Ae){F[ne].providers=_e,Le(Ae.message,"error")}}function Nm(B,q,ne){if(q===0)return;const F=B[ne].chain.map((_e,Ae)=>Ae);[F[q-1],F[q]]=[F[q],F[q-1]],Ao(B,F,ne)}function qm(B,q,ne){if(q>=B[ne].chain.length-1)return;const F=B[ne].chain.map((_e,Ae)=>Ae);[F[q+1],F[q]]=[F[q],F[q+1]],Ao(B,F,ne)}function Bm(B){C.value=B,I.value=!0}function Js(B,q,ne){return`${B.name}:${q}:${ne}`}function Vm(B,q,ne){return A.value===Js(B,q,ne)}function bu(B,q,ne,F){const _e=Js(B,q,F);P.value[_e]=ne.model??"",A.value=_e}function Um(B,q,ne){return P.value[Js(B,q,ne)]??""}function Hm(B,q,ne,F){P.value[Js(B,q,ne)]=F}async function jm(B,q,ne,F){const _e=Js(B,q,F);A.value="";const Ae=(P.value[_e]??"").trim(),ot=(ne.model??"").trim();if(Ae===ot)return;const $s=s.value.find(Qs=>Qs.name===B.name);$s&&($s[q].providers[F].model=Ae||void 0),P.value[_e]=Ae;try{await Ue("PUT",`/admin/models/${Z(B.name)}/map`,{format:q,index:F,model:Ae}),Le(t("models.mapSaved"),"success")}catch(Qs){await ie(),Le(Qs.message,"error")}}function Wm(B,q,ne,F,_e){P.value[Js(B,q,F)]=ne.model??"",_e.blur()}const nl=N(""),Eo=N("");function Ps(B){var q;return((q=ke.value.get(B))==null?void 0:q.rpm)??0}function Km(B){return nl.value===B.id}function _u(B){nl.value=B.id,Eo.value=Ps(B.id)?String(Ps(B.id)):""}function zm(B){Eo.value=B}async function Gm(B,q){const ne=ke.value.get(B);ne&&await Ue("PUT",`/admin/providers/${B}`,{name:ne.name,baseUrlOpenai:ne.baseUrlOpenai,baseUrlAnthropic:ne.baseUrlAnthropic,formats:ne.formats,supportsResponses:ne.supportsResponses??!1,rpm:q})}async function Ym(B){const q=B.id;nl.value="";const ne=Number(Eo.value),F=Number.isFinite(ne)&&ne>0?Math.floor(ne):0;if(F!==Ps(q))try{await Gm(q,F),o.value=o.value.map(_e=>_e.id===q?{..._e,rpm:F}:_e),Le(F?t("sources.rpmSaved",{n:F}):t("sources.rpmCleared"),F?"success":"default")}catch(_e){Le(_e.message,"error")}}function Xm(B,q){Eo.value=Ps(B.id)?String(Ps(B.id)):"",q.blur()}async function Jm(B,q,ne){const F=`${B.name}:${q}:${ne}`;if(E.value[F])return;E.value[F]=!0;const _e=s.value.find(Ae=>Ae.name===B.name);_e&&_e[q].providers.splice(ne,1);try{await Ue("DELETE",`/admin/models/${Z(B.name)}/providers?format=${q}&index=${ne}`),Le(t("models.sourceRemoved"),"success")}catch(Ae){await ie(),Le(Ae.message,"error")}finally{E.value[F]=!1}}async function Qm(){if(d.value||!o.value.length)return;d.value=!0;const B=o.value,q=await Promise.allSettled(B.map(F=>Ue("POST",`/admin/providers/${F.id}/discover`)));await ie();const ne=q.map((F,_e)=>F.status==="rejected"?B[_e].name:null).filter(F=>!!F);ne.length?ne.length===B.length?Le(t("sources.refreshAllFailed"),"error"):Le(t("sources.refreshAllPartial",{failed:ne.join("、")}),"error"):Le(t("sources.refreshAllDone"),"success"),d.value=!1}return dt(ie),(B,q)=>{var ne;return _(),W("div",dA,[!a.value&&!o.value.length?(_(),D(l(hn),{key:0},{default:y(()=>[v(l(vn),{class:"flex flex-col items-center gap-3 py-12 text-center"},{default:y(()=>[x("span",fA,[v(l(wi),{class:"h-5 w-5"})]),x("div",pA,[x("div",mA,S(l(t)("models.empty")),1),x("p",hA,S(l(t)("models.emptyHint")),1)]),v(l(Re),{onClick:q[0]||(q[0]=F=>p.value=!0)},{default:y(()=>[v(l(es),{class:"h-4 w-4"}),j(S(l(t)("models.addSource")),1)]),_:1})]),_:1})]),_:1})):(_(),D(l(hn),{key:1},{default:y(()=>[v(l(Mn),null,{default:y(()=>[v(l(Rn),{class:"flex items-center gap-2 text-base"},{default:y(()=>[v(l(Em),{class:"h-4 w-4 text-primary"}),j(" "+S(l(t)("models.title")),1)]),_:1}),v(l(gs),null,{default:y(()=>[j(S(l(t)("models.desc")),1)]),_:1})]),_:1}),v(l(vn),{class:"space-y-4"},{default:y(()=>[x("div",vA,[x("div",gA,[v(l(Im),{class:"absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),v(l(Tt),{modelValue:i.value,"onUpdate:modelValue":q[1]||(q[1]=F=>i.value=F),placeholder:l(t)("models.searchPh"),class:"pl-8"},null,8,["modelValue","placeholder"])]),v(l(Re),{size:"sm",onClick:q[2]||(q[2]=F=>m.value=!0)},{default:y(()=>[v(l(es),{class:"h-4 w-4"}),j(S(l(t)("models.addModels")),1)]),_:1}),v(l(Re),{variant:"outline",size:"sm",onClick:q[3]||(q[3]=F=>p.value=!0)},{default:y(()=>[v(l(wi),{class:"h-4 w-4"}),j(S(l(t)("models.manageSources")),1)]),_:1})]),x("p",yA,S(l(t)("models.chipLegend")),1),a.value?(_(),W("p",bA,S(l(t)("common.loading")),1)):r.value?(_(),W("p",_A,S(r.value),1)):(_(),W(Se,{key:2},[lt.value.length?(_(),W("section",wA,[q[16]||(q[16]=x("div",{class:"pointer-events-none absolute inset-y-0 left-0 w-1 bg-primary","aria-hidden":"true"},null,-1)),x("div",xA,[q[13]||(q[13]=x("span",{class:"h-2 w-2 shrink-0 rounded-full bg-primary"},null,-1)),x("span",kA,S(l(t)("models.enabledSection")),1),x("span",CA,S(lt.value.length),1)]),x("div",SA,[(_(!0),W(Se,null,tt(lt.value,F=>{var _e,Ae,ot,$s,Qs;return _(),W("div",{key:F.name,class:"px-3 py-2.5"},[x("div",AA,[x("div",{role:"button",tabindex:"0",class:"flex min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-md text-left outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background","aria-expanded":O(F.name),"aria-label":O(F.name)?l(t)("models.collapseAria"):l(t)("models.expandAria"),onClick:Pe=>$(F.name),onKeydown:Pe=>H(Pe,F.name)},[v(l(bi),{class:Ce(["h-4 w-4 shrink-0 text-muted-foreground transition-transform",{"rotate-90":O(F.name)}])},null,8,["class"]),x("span",OA,[x("span",TA,[x("span",PA,S(F.name),1),x("button",{type:"button",title:l(t)("connect.copy"),"aria-label":l(t)("connect.copy"),class:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground/50 transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:Gt(Pe=>V(F.name),["stop"])},[v(l(Xn),{class:"h-3 w-3"})],8,$A),((_e=ve(F))==null?void 0:_e.state)==="testing"?(_(),D(l(yt),{key:0,variant:"muted",class:"gap-1"},{default:y(()=>[v(l(kt),{class:"h-3 w-3 animate-spin"}),j(S(l(t)("models.probeTesting")),1)]),_:1})):((Ae=ve(F))==null?void 0:Ae.state)==="ok"?(_(),D(l(yt),{key:1,variant:"success",title:l(t)("models.probeOkHint",{name:((ot=ve(F))==null?void 0:ot.provider)??""})},{default:y(()=>[j(S(l(t)("models.probeOk")),1)]),_:1},8,["title"])):(($s=ve(F))==null?void 0:$s.state)==="fail"?(_(),D(l(yt),{key:2,variant:"destructive",title:((Qs=ve(F))==null?void 0:Qs.error)||l(t)("models.probeFailHint")},{default:y(()=>{var Pe;return[j(S(l(t)("models.probeFail"))+" · "+S(((Pe=ve(F))==null?void 0:Pe.status)||"?"),1)]}),_:2},1032,["title"])):Y(F)?(_(),D(l(yt),{key:3,variant:"secondary",title:l(t)("models.delistedHint")},{default:y(()=>[j(S(l(t)("models.delisted")),1)]),_:1},8,["title"])):pe("",!0)]),x("span",IA,S(re(F)),1)])],40,EA),x("div",MA,[(_(),W(Se,null,tt(n,Pe=>x("button",{key:Pe,type:"button",disabled:K(F,Pe)==="unsupported"||k.value[`${F.name}:${Pe}`],title:De(F,Pe),"aria-label":De(F,Pe),class:Ce(["inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-xs font-medium transition-colors disabled:cursor-not-allowed",Te(F,Pe)]),onClick:mt=>Xe(F,Pe)},[k.value[`${F.name}:${Pe}`]?(_(),D(l(kt),{key:0,class:"h-3 w-3 animate-spin"})):(_(),W("span",{key:1,class:Ce(["rounded-full",K(F,Pe)==="enabled"?"h-1.5 w-1.5 bg-current":K(F,Pe)==="enableable"?"h-1.5 w-1.5 border border-current":"h-1.5 w-1.5"])},null,2)),j(" "+S(l(t)(se[Pe].chip)),1)],10,RA)),64))]),v(l(hi),null,{default:y(()=>[v(l(vi),null,{default:y(()=>[v(l(Re),{variant:"ghost",size:"icon",class:"h-8 w-8 shrink-0 text-muted-foreground","aria-label":l(t)("models.moreActions")},{default:y(()=>[v(l(_i),{class:"h-4 w-4"})]),_:1},8,["aria-label"])]),_:1}),v(l(gi),{align:"end"},{default:y(()=>{var Pe;return[v(l(Wn),{disabled:((Pe=ve(F))==null?void 0:Pe.state)==="testing"||!ce(F).length,onSelect:mt=>Bt(F)},{default:y(()=>{var mt;return[((mt=ve(F))==null?void 0:mt.state)==="testing"?(_(),D(l(kt),{key:0,class:"animate-spin"})):(_(),D(l(Tl),{key:1})),j(" "+S(l(t)("models.testModel")),1)]}),_:2},1032,["disabled","onSelect"]),v(l(yi)),v(l(Wn),{class:"text-destructive focus:bg-destructive/10 focus:text-destructive",onSelect:mt=>Ts(F)},{default:y(()=>[v(l(xi)),j(" "+S(l(t)("models.removeModel")),1)]),_:1},8,["onSelect"])]}),_:2},1024)]),_:2},1024)]),O(F.name)?(_(),W("div",LA,[(_(!0),W(Se,null,tt(ce(F),Pe=>(_(),W("div",{key:Pe,class:"space-y-1"},[x("div",DA,[x("span",{class:Ce(["h-2 w-2 rounded-full",l(tn)[Pe].solid])},null,2),x("span",FA,S(l(t)(se[Pe].key)),1),x("span",NA,S(se[Pe].endpoint),1)]),U(F,Pe)?(_(),W("div",qA,[x("span",BA,S(l(t)("models.delisted")),1),x("span",null,S(l(t)("models.delistedHint")),1)])):pe("",!0),F[Pe].chain.length?pe("",!0):(_(),W("div",VA,S(l(t)("models.noSources")),1)),(_(!0),W(Se,null,tt(F[Pe].chain,(mt,pt)=>{var wu,xu;return _(),W("div",{key:pt,class:"group flex items-center gap-2 rounded px-1 py-1 hover:bg-muted/40"},[x("span",UA,S(pt+1)+".",1),x("span",HA,[x("span",{class:Ce(["h-1.5 w-1.5 rounded-full",l(si)(mt.id).solid])},null,2),j(" "+S(mt.name),1)]),pt===0?(_(),D(l(yt),{key:0,variant:"default"},{default:y(()=>[j(S(l(t)("models.primary")),1)]),_:1})):(_(),D(l(yt),{key:1,variant:"muted"},{default:y(()=>[j(S(l(t)("models.fallback")),1)]),_:1})),Km(mt)?(_(),W("span",jA,[v(l(Ko),{class:"h-3 w-3 text-muted-foreground"}),yo(x("input",{type:"number",min:"0",inputmode:"numeric",value:Eo.value,placeholder:l(t)("sources.rpmPh"),"aria-label":l(t)("sources.rpmLabel"),title:l(t)("sources.rpmHint"),class:"h-6 w-16 rounded-md border border-input bg-background px-2 font-mono text-xs shadow-sm transition-colors placeholder:font-sans placeholder:text-muted-foreground/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",onInput:q[4]||(q[4]=it=>zm(it.target.value)),onKeyup:[q[5]||(q[5]=Bs(it=>it.target.blur(),["enter"])),Bs(it=>Xm(mt,it.target),["esc"])],onBlur:it=>Ym(mt)},null,40,WA),[[R]])])):Ps(mt.id)>0?(_(),W("button",{key:3,type:"button",title:l(t)("sources.rpmBadgeHint"),class:"inline-flex items-center gap-1 rounded-full border border-input bg-background px-2 py-0.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:it=>_u(mt)},[v(l(Ko),{class:"h-3 w-3"}),j(" "+S(l(t)("sources.rpmBadge",{n:Ps(mt.id)})),1)],8,KA)):pe("",!0),g.value[`${F.name}:${Pe}:${pt}`]?(_(),D(l(yt),{key:4,variant:"muted",class:"gap-1"},{default:y(()=>[v(l(kt),{class:"h-3 w-3 animate-spin"}),j(S(l(t)("models.probeTesting")),1)]),_:1})):(wu=T.value[`${F.name}:${Pe}:${pt}`])!=null&&wu.ok?(_(),D(l(yt),{key:5,variant:"success",title:l(t)("models.probeOkHint",{name:mt.name})},{default:y(()=>[j(S(l(t)("models.probeOk")),1)]),_:1},8,["title"])):T.value[`${F.name}:${Pe}:${pt}`]?(_(),D(l(yt),{key:6,variant:"destructive",title:((xu=T.value[`${F.name}:${Pe}:${pt}`])==null?void 0:xu.error)||l(t)("models.probeFailHint")},{default:y(()=>{var it;return[j(S(l(t)("models.probeFail"))+" · "+S(((it=T.value[`${F.name}:${Pe}:${pt}`])==null?void 0:it.status)||"?"),1)]}),_:2},1032,["title"])):pe("",!0),Vm(F,Pe,pt)?(_(),W("div",zA,[q[14]||(q[14]=x("span",{class:"text-xs text-muted-foreground"},"→",-1)),yo(x("input",{type:"text",value:Um(F,Pe,pt),placeholder:l(t)("models.upstreamPh"),"aria-label":l(t)("models.upstreamLabel"),title:l(t)("models.upstreamHint"),spellcheck:"false",class:"h-6 w-40 rounded-md border border-input bg-background px-2 font-mono text-xs shadow-sm transition-colors placeholder:font-sans placeholder:text-muted-foreground/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",onInput:it=>Hm(F,Pe,pt,it.target.value),onKeyup:[q[6]||(q[6]=Bs(it=>it.target.blur(),["enter"])),Bs(it=>Wm(F,Pe,mt,pt,it.target),["esc"])],onBlur:it=>jm(F,Pe,mt,pt)},null,40,GA),[[R]])])):mt.model?(_(),W("button",{key:8,type:"button",title:l(t)("models.upstreamHint"),class:"inline-flex items-center gap-1 rounded border border-transparent px-1.5 py-0.5 font-mono text-xs text-muted-foreground transition-colors hover:border-border hover:bg-background hover:text-foreground",onClick:it=>bu(F,Pe,mt,pt)},[q[15]||(q[15]=x("span",null,"→",-1)),j(S(mt.model),1)],8,YA)):pe("",!0),x("div",XA,[v(l(Re),{variant:"ghost",size:"icon",class:"h-7 w-7",disabled:pt===0,"aria-label":l(t)("models.moveUpAria"),onClick:it=>Nm(F,pt,Pe)},{default:y(()=>[v(l(Zk),{class:"h-4 w-4"})]),_:1},8,["disabled","aria-label","onClick"]),v(l(Re),{variant:"ghost",size:"icon",class:"h-7 w-7",disabled:pt===F[Pe].chain.length-1,"aria-label":l(t)("models.moveDownAria"),onClick:it=>qm(F,pt,Pe)},{default:y(()=>[v(l(Qk),{class:"h-4 w-4"})]),_:1},8,["disabled","aria-label","onClick"]),v(l(hi),null,{default:y(()=>[v(l(vi),null,{default:y(()=>[v(l(Re),{variant:"ghost",size:"icon",class:"h-7 w-7 text-muted-foreground","aria-label":l(t)("models.moreActions")},{default:y(()=>[v(l(_i),{class:"h-4 w-4"})]),_:1},8,["aria-label"])]),_:1}),v(l(gi),{align:"end"},{default:y(()=>[v(l(Wn),{disabled:g.value[`${F.name}:${Pe}:${pt}`],onSelect:it=>rn(F,Pe,pt)},{default:y(()=>[g.value[`${F.name}:${Pe}:${pt}`]?(_(),D(l(kt),{key:0,class:"animate-spin"})):(_(),D(l(Tl),{key:1})),j(" "+S(l(t)("models.testSource")),1)]),_:2},1032,["disabled","onSelect"]),v(l(Wn),{onSelect:it=>bu(F,Pe,mt,pt)},{default:y(()=>[v(l(Pm),{class:"h-4 w-4"}),j(" "+S(l(t)("models.editUpstream")),1)]),_:1},8,["onSelect"]),v(l(Wn),{onSelect:it=>_u(mt)},{default:y(()=>[v(l(Ko),{class:"h-4 w-4"}),j(" "+S(l(t)("sources.rpmLabel")),1)]),_:1},8,["onSelect"]),v(l(yi)),v(l(Wn),{class:"text-destructive focus:bg-destructive/10 focus:text-destructive",onSelect:it=>Jm(F,Pe,pt)},{default:y(()=>[v(l(xi),{class:"h-4 w-4"}),j(" "+S(l(t)("models.removeSource")),1)]),_:1},8,["onSelect"])]),_:2},1024)]),_:2},1024)])])}),128))]))),128)),G(F).length?(_(),W("div",JA,[v(l(Re),{variant:"outline",size:"sm",class:"h-7 gap-1 border-dashed text-muted-foreground",onClick:Pe=>Bm(F)},{default:y(()=>[v(l(es),{class:"h-3.5 w-3.5"}),j(" "+S(l(t)("models.addSourceToChain")),1)]),_:1},8,["onClick"])])):pe("",!0)])):pe("",!0)])}),128))])])):pe("",!0),x("section",QA,[q[18]||(q[18]=x("div",{class:"pointer-events-none absolute inset-y-0 left-0 w-1 bg-muted-foreground/40","aria-hidden":"true"},null,-1)),x("div",ZA,[x("button",{type:"button",class:"flex min-w-0 flex-1 items-center gap-2.5 rounded px-1 py-0.5 text-left hover:bg-muted/50",onClick:q[7]||(q[7]=F=>u.value=!u.value)},[v(l(Xa),{class:Ce(["h-4 w-4 shrink-0 text-muted-foreground transition-transform",{"-rotate-90":!u.value}])},null,8,["class"]),q[17]||(q[17]=x("span",{class:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/40"},null,-1)),x("span",eE,S(l(t)("models.availableSection")),1),x("span",tE,S(qe.value.length),1)]),st.value>0?(_(),D(l(Re),{key:0,variant:"ghost",size:"sm",class:Ce(["h-7 gap-1.5 px-2.5",Ee.value?"bg-accent text-accent-foreground":"text-muted-foreground"]),title:Ee.value?l(t)("models.filterChatHint",{n:st.value}):l(t)("models.filterAllHint"),onClick:q[8]||(q[8]=F=>Ee.value=!Ee.value)},{default:y(()=>[v(l(Om),{class:"h-3.5 w-3.5"}),j(" "+S(Ee.value?l(t)("models.filterChatOnly"):l(t)("models.filterInclude")),1)]),_:1},8,["class","title"])):pe("",!0),v(l(Re),{variant:"ghost",size:"sm",class:"h-7 gap-1.5 px-2.5",disabled:d.value,title:l(t)("sources.refreshAll"),onClick:Qm},{default:y(()=>[d.value?(_(),D(l(kt),{key:0,class:"h-3.5 w-3.5 animate-spin"})):(_(),D(l(mr),{key:1,class:"h-3.5 w-3.5"})),j(" "+S(l(t)("sources.refreshAll")),1)]),_:1},8,["disabled","title"]),qe.value.length?(_(),D(l(Re),{key:1,size:"sm",variant:"secondary",class:"h-7 gap-1.5 px-2.5",disabled:f.value,onClick:Kt},{default:y(()=>[f.value?(_(),D(l(kt),{key:0,class:"h-3.5 w-3.5 animate-spin"})):(_(),D(l(Tl),{key:1,class:"h-3.5 w-3.5"})),j(" "+S(l(t)("models.enableAll")),1)]),_:1},8,["disabled"])):pe("",!0)]),u.value?(_(),W("div",nE,[qe.value.length?(_(),W("div",oE,[(_(!0),W(Se,null,tt(ft.value,F=>(_(),W("div",{key:F.source.id},[x("button",{type:"button",class:"flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-muted/40","aria-expanded":M(F.source.id,F.rows.length),"aria-label":F.source.name,onClick:_e=>L(F.source.id,F.rows.length)},[v(l(bi),{class:Ce(["h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform",{"rotate-90":M(F.source.id,F.rows.length)}])},null,8,["class"]),x("span",{class:Ce(["h-1.5 w-1.5 shrink-0 rounded-full",l(si)(F.source.id).solid])},null,2),x("span",aE,S(F.source.name),1),x("span",lE,S(F.rows.length),1)],8,rE),M(F.source.id,F.rows.length)?(_(),W("div",iE,[(_(!0),W(Se,null,tt(F.rows,_e=>(_(),W("div",{key:_e.name,class:"flex items-center justify-between gap-2 px-3 py-2 pl-9"},[x("div",uE,[x("span",cE,S(_e.name),1),x("button",{type:"button",title:l(t)("connect.copy"),"aria-label":l(t)("connect.copy"),class:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground/50 transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:Ae=>V(_e.name)},[v(l(Xn),{class:"h-3 w-3"})],8,dE)]),x("div",fE,[(_(),W(Se,null,tt(n,Ae=>x("button",{key:Ae,type:"button",disabled:K(_e,Ae)==="unsupported"||k.value[`${_e.name}:${Ae}`],title:De(_e,Ae),"aria-label":De(_e,Ae),class:Ce(["inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-xs font-medium transition-colors disabled:cursor-not-allowed",Te(_e,Ae)]),onClick:ot=>Xe(_e,Ae)},[k.value[`${_e.name}:${Ae}`]?(_(),D(l(kt),{key:0,class:"h-3 w-3 animate-spin"})):(_(),W("span",{key:1,class:Ce(["rounded-full",K(_e,Ae)==="enabled"?"h-1.5 w-1.5 bg-current":K(_e,Ae)==="enableable"?"h-1.5 w-1.5 border border-current":"h-1.5 w-1.5"])},null,2)),j(" "+S(l(t)(se[Ae].chip)),1)],10,pE)),64))])]))),128))])):pe("",!0)]))),128))])):(_(),W("p",sE,S(Ee.value&&fe.value.length?l(t)("models.availableAllFiltered",{n:st.value}):l(t)("models.availableDesc")),1))])):pe("",!0)])],64))]),_:1})]),_:1})),v(yS,{open:p.value,"onUpdate:open":q[9]||(q[9]=F=>p.value=F),onChanged:ie},null,8,["open"]),v(zS,{open:m.value,"onUpdate:open":q[10]||(q[10]=F=>m.value=F),providers:o.value,onChanged:ie},null,8,["open","providers"]),v(cA,{open:I.value,"onUpdate:open":q[11]||(q[11]=F=>I.value=F),"model-name":((ne=C.value)==null?void 0:ne.name)??"",providers:o.value,"enabled-formats":C.value?ce(C.value):[],"chain-by-format":C.value?le(C.value):{},onAdded:ie},null,8,["open","model-name","providers","enabled-formats","chain-by-format"]),v(gu,{open:de.value,"onUpdate:open":q[12]||(q[12]=F=>de.value=F),variant:"destructive",title:l(t)("models.removeModel"),description:z.value?l(t)("models.confirmRemove",{name:z.value.name}):"","confirm-text":l(t)("models.removeModel"),loading:z.value?!!w.value[z.value.name]:!1,onConfirm:Er},null,8,["open","title","description","confirm-text","loading"])])}}}),vE={class:"relative w-full overflow-auto"},Lm=Q({__name:"Table",props:{class:{type:[Boolean,null,String,Object,Array]}},setup(e){const t=e;return(n,s)=>(_(),W("div",vE,[x("table",{class:Ce(l(Ye)("w-full caption-bottom text-sm",t.class))},[ae(n.$slots,"default")],2)]))}}),Dm=Q({__name:"TableHeader",props:{class:{type:[Boolean,null,String,Object,Array]}},setup(e){const t=e;return(n,s)=>(_(),W("thead",{class:Ce(l(Ye)("[&_tr]:border-b",t.class))},[ae(n.$slots,"default")],2))}}),Fm=Q({__name:"TableBody",props:{class:{type:[Boolean,null,String,Object,Array]}},setup(e){const t=e;return(n,s)=>(_(),W("tbody",{class:Ce(l(Ye)("[&_tr:last-child]:border-0",t.class))},[ae(n.$slots,"default")],2))}}),io=Q({__name:"TableRow",props:{class:{type:[Boolean,null,String,Object,Array]}},setup(e){const t=e;return(n,s)=>(_(),W("tr",{class:Ce(l(Ye)("border-b transition-colors hover:bg-muted/40 data-[state=selected]:bg-muted",t.class))},[ae(n.$slots,"default")],2))}}),zt=Q({__name:"TableHead",props:{class:{type:[Boolean,null,String,Object,Array]}},setup(e){const t=e;return(n,s)=>(_(),W("th",{class:Ce(l(Ye)("h-10 px-3 text-left align-middle text-xs font-medium uppercase tracking-wide text-muted-foreground [&:has([role=checkbox])]:pr-0",t.class))},[ae(n.$slots,"default")],2))}}),Dt=Q({__name:"TableCell",props:{class:{type:[Boolean,null,String,Object,Array]}},setup(e){const t=e;return(n,s)=>(_(),W("td",{class:Ce(l(Ye)("p-3 align-middle [&:has([role=checkbox])]:pr-0",t.class))},[ae(n.$slots,"default")],2))}}),gE=Q({__name:"Popover",props:{defaultOpen:{type:Boolean},open:{type:Boolean},modal:{type:Boolean}},emits:["update:open"],setup(e,{emit:t}){const o=Rt(e,t);return(r,a)=>(_(),D(l(gx),Ot($t(l(o))),{default:y(()=>[ae(r.$slots,"default")]),_:3},16))}}),yE=Q({__name:"PopoverTrigger",props:{asChild:{type:Boolean},as:{}},setup(e){const t=e;return(n,s)=>(_(),D(l(Ox),Ot($t(t)),{default:y(()=>[ae(n.$slots,"default")]),_:3},16))}}),bE=Q({__name:"PopoverContent",props:{forceMount:{type:Boolean},memoDependencies:{},side:{},sideOffset:{default:4},sideFlip:{type:Boolean},align:{},alignOffset:{},alignFlip:{type:Boolean},avoidCollisions:{type:Boolean},collisionBoundary:{},collisionPadding:{},arrowPadding:{},hideShiftedArrow:{type:Boolean},sticky:{},hideWhenDetached:{type:Boolean},positionStrategy:{},updatePositionStrategy:{},disableUpdateOnLayoutShift:{type:Boolean},prioritizePosition:{type:Boolean},reference:{},dir:{},asChild:{type:Boolean},as:{},disableOutsidePointerEvents:{type:Boolean},class:{type:[Boolean,null,String,Object,Array]}},emits:["escapeKeyDown","pointerDownOutside","focusOutside","interactOutside","openAutoFocus","closeAutoFocus"],setup(e,{emit:t}){const n=e,s=t,o=X(()=>{const{class:a,...i}=n;return i}),r=Rt(o,s);return(a,i)=>(_(),D(l(Ax),null,{default:y(()=>[v(l(Cx),Ie(l(r),{class:l(Ye)("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2",n.class)}),{default:y(()=>[ae(a.$slots,"default")]),_:3},16,["class"])]),_:3}))}}),_E={class:"flex items-center justify-between gap-2"},wE={class:"flex gap-1"},xE={class:"sr-only"},kE={class:"flex flex-wrap items-center gap-2"},CE={class:"relative flex-1 sm:max-w-sm"},SE={key:0,class:"inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-primary px-1 text-[10px] font-medium text-primary-foreground"},AE={class:"space-y-2.5"},EE={class:"flex items-center justify-between"},OE={class:"text-xs font-medium"},TE={class:"space-y-2"},PE={class:"grid grid-cols-[3.5rem_1fr] items-center gap-2"},$E={class:"text-xs text-muted-foreground"},IE={class:"grid grid-cols-[3.5rem_1fr] items-center gap-2"},ME={class:"text-xs text-muted-foreground"},RE={class:"grid grid-cols-[3.5rem_1fr] items-center gap-2"},LE={class:"text-xs text-muted-foreground"},DE={key:0,class:"flex flex-wrap items-center gap-1.5"},FE={class:"text-muted-foreground"},NE={class:"font-medium"},qE=["aria-label","onClick"],BE={class:"flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-muted-foreground"},VE={key:1,class:"space-y-2 rounded-lg border border-amber-500/30 bg-amber-500/5 p-3"},UE={class:"flex items-center gap-1.5 text-xs font-medium text-amber-700 dark:text-amber-400"},HE={class:"space-y-1.5"},jE={class:"font-medium"},WE={class:"break-all text-muted-foreground"},KE={key:2,class:"space-y-2 rounded-lg border border-orange-500/30 bg-orange-500/5 p-3"},zE={class:"flex items-center gap-1.5 text-xs font-medium text-orange-700 dark:text-orange-400"},GE={class:"space-y-1.5"},YE={class:"font-medium"},XE={class:"text-muted-foreground"},JE={key:3,class:"py-6 text-center text-sm text-muted-foreground"},QE={key:4,class:"py-6 text-center text-sm text-muted-foreground"},ZE={key:5,class:"overflow-x-auto"},eO={class:"flex flex-wrap items-center gap-x-2 gap-y-1 text-xs"},tO={class:"font-mono text-muted-foreground"},nO={class:"font-medium"},sO={class:"text-muted-foreground"},oO={class:"text-muted-foreground"},rO={class:"break-all text-muted-foreground"},aO={key:0,class:"text-muted-foreground/60"},lO={class:"inline-flex items-center gap-1.5"},iO={class:"grid grid-cols-[auto_1fr] gap-x-4 gap-y-1.5 px-2 py-2 text-xs sm:grid-cols-[auto_1fr_auto_1fr]"},uO={class:"text-muted-foreground"},cO={class:"font-mono"},dO={class:"text-muted-foreground"},fO={class:"font-mono"},pO={class:"text-muted-foreground"},mO={class:"text-muted-foreground"},hO={class:"break-all font-mono"},vO={class:"text-muted-foreground"},gO={class:"font-mono"},yO={class:"text-foreground/80"},bO={class:"text-foreground/80"},_O={class:"text-amber-600 dark:text-amber-400"},wO={class:"text-muted-foreground"},xO={class:"break-all font-mono"},_d="myapikey.logs.filters",kO=Q({__name:"Logs",setup(e){const{t}=It(),n=N([]),s=N(!0),o=N(!1),r=N([]),a=N([]),i=N("all"),u=N("all"),c=N("all"),d=N(""),f=N(new Set),p=N(!1);try{const K=JSON.parse(localStorage.getItem(_d)||"null");K&&(typeof K.model=="string"&&(i.value=K.model),typeof K.provider=="string"&&(u.value=K.provider),(K.status==="success"||K.status==="error")&&(c.value=K.status),typeof K.query=="string"&&(d.value=K.query))}catch{}Fe([i,u,c,d],()=>{try{localStorage.setItem(_d,JSON.stringify({model:i.value,provider:u.value,status:c.value,query:d.value}))}catch{}});let m;async function w(){o.value=!0;try{const[K,he]=await Promise.all([Ue("GET","/admin/logs").catch(()=>null),Ue("GET","/admin/circuit").catch(()=>null)]);K&&(n.value=K.logs),he&&(r.value=he.providers.filter(ee=>ee.state==="cooling"),a.value=he.providers.filter(ee=>ee.rpm>0&&ee.rpmUsed>=ee.rpm&&ee.state!=="cooling"))}finally{o.value=!1}}async function k(K){await Ue("POST",`/admin/circuit/${K}/reset`).catch(()=>{}),await w()}function E(){h(),m=window.setInterval(w,4e3)}function h(){m&&(clearInterval(m),m=void 0)}function g(){s.value=!s.value,s.value?(w(),E()):h()}function T(K){return K>=200&&K<300?"success":K>=400?"destructive":"muted"}function b(K){var he;return((he=tn[K])==null?void 0:he.badge)??""}function P(K){return K<1e3?`${K}ms`:`${(K/1e3).toFixed(1)}s`}function A(K){return K?K<1e3?String(K):K<1e6?(K/1e3).toFixed(K<1e4?1:0).replace(/\.0$/,"")+"k":(K/1e6).toFixed(1)+"M":"0"}function C(K){if(K<=0)return"0";const he=Math.round(K*1e3)/10;return Number.isInteger(he)?String(he):he.toFixed(1)}function I(K){return new Date(K).toLocaleTimeString()}function R(K){return new Date(K).toLocaleString()}function z(K){return`${K.ts}-${K.model}-${K.provider}-${K.status}-${K.kind??"call"}`}function de(K){return f.value.has(z(K))}function Z(K){const he=new Set(f.value),ee=z(K);he.has(ee)?he.delete(ee):he.add(ee),f.value=he}const ie=X(()=>[...new Set(n.value.map(K=>K.model))].sort()),ke=X(()=>[...new Set(n.value.map(K=>K.provider))].sort()),J=X(()=>{const K=d.value.trim().toLowerCase();return n.value.filter(he=>{var ee;return!(i.value!=="all"&&he.model!==i.value||u.value!=="all"&&he.provider!==u.value||c.value==="success"&&!(he.status>=200&&he.status<300)||c.value==="error"&&he.status<400||K&&!(he.model.toLowerCase().includes(K)||(ee=he.upstreamModel)!=null&&ee.toLowerCase().includes(K)||he.provider.toLowerCase().includes(K)))})}),te=X(()=>{const K=J.value.filter(fe=>fe.kind!=="cooldown"),he=K.length,ee=K.filter(fe=>fe.status>=400).length,lt=he?Math.round(K.reduce((fe,ue)=>fe+ue.ms,0)/he):0;return{total:he,fail:ee,avgMs:lt,errorRateStr:C(he?ee/he:0)}}),ce=X(()=>(i.value!=="all"?1:0)+(u.value!=="all"?1:0)+(c.value!=="all"?1:0)),ge=X(()=>{const K=[];return i.value!=="all"&&K.push({key:"model",label:t("logs.filter.model"),value:i.value,clear:()=>i.value="all"}),u.value!=="all"&&K.push({key:"provider",label:t("logs.filter.provider"),value:u.value,clear:()=>u.value="all"}),c.value!=="all"&&K.push({key:"status",label:t("logs.filter.status"),value:c.value==="success"?t("logs.filter.success"):t("logs.filter.error"),clear:()=>c.value="all"}),K});function $e(){i.value="all",u.value="all",c.value="all"}return dt(()=>{w(),E()}),bn(h),(K,he)=>(_(),D(l(hn),null,{default:y(()=>[v(l(Mn),null,{default:y(()=>[x("div",_E,[v(l(Rn),{class:"flex items-center gap-2 text-base"},{default:y(()=>[v(l(Sm),{class:"h-4 w-4 text-primary"}),j(" "+S(l(t)("logs.title"))+" ",1),s.value?(_(),D(l(yt),{key:0,variant:"success",class:"gap-1.5"},{default:y(()=>[he[5]||(he[5]=x("span",{class:"relative flex h-1.5 w-1.5"},[x("span",{class:"absolute inline-flex h-full w-full animate-ping rounded-full bg-current opacity-75"}),x("span",{class:"relative inline-flex h-1.5 w-1.5 rounded-full bg-current"})],-1)),j(" "+S(l(t)("logs.live")),1)]),_:1})):pe("",!0)]),_:1}),x("div",wE,[v(l(Re),{variant:"outline",size:"sm",disabled:o.value,onClick:w},{default:y(()=>[o.value?(_(),D(l(kt),{key:0,class:"h-3.5 w-3.5 animate-spin"})):(_(),D(l(mr),{key:1,class:"h-3.5 w-3.5"})),x("span",xE,S(l(t)("logs.refresh")),1)]),_:1},8,["disabled"]),v(l(Re),{variant:"outline",size:"sm","aria-pressed":s.value,onClick:g},{default:y(()=>[s.value?(_(),D(l(eC),{key:0,class:"h-3.5 w-3.5"})):(_(),D(l(tC),{key:1,class:"h-3.5 w-3.5"})),j(" "+S(s.value?l(t)("logs.pause"):l(t)("logs.resume")),1)]),_:1},8,["aria-pressed"])])]),v(l(gs),null,{default:y(()=>[j(S(l(t)("logs.desc")),1)]),_:1})]),_:1}),v(l(vn),{class:"space-y-3"},{default:y(()=>[x("div",kE,[x("div",CE,[v(l(Im),{class:"pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),v(l(Tt),{modelValue:d.value,"onUpdate:modelValue":he[0]||(he[0]=ee=>d.value=ee),placeholder:l(t)("logs.searchPh"),class:"h-8 pl-8"},null,8,["modelValue","placeholder"])]),v(l(gE),{open:p.value,"onUpdate:open":he[4]||(he[4]=ee=>p.value=ee)},{default:y(()=>[v(l(yE),{"as-child":""},{default:y(()=>[v(l(Re),{variant:"outline",size:"sm",class:"h-8 gap-1.5"},{default:y(()=>[v(l(Om),{class:"h-3.5 w-3.5"}),j(" "+S(l(t)("logs.filter.title"))+" ",1),ce.value?(_(),W("span",SE,S(ce.value),1)):pe("",!0)]),_:1})]),_:1}),v(l(bE),{align:"start",class:"w-72 p-3"},{default:y(()=>[x("div",AE,[x("div",EE,[x("span",OE,S(l(t)("logs.filter.title")),1),ce.value?(_(),W("button",{key:0,type:"button",class:"text-xs text-primary hover:underline",onClick:$e},S(l(t)("logs.filter.clear")),1)):pe("",!0)]),x("div",TE,[x("div",PE,[x("span",$E,S(l(t)("logs.filter.model")),1),v(l(zo),{modelValue:i.value,"onUpdate:modelValue":he[1]||(he[1]=ee=>i.value=ee)},{default:y(()=>[v(l(Go),{class:"h-8 w-full"},{default:y(()=>[v(l(Yo),{placeholder:l(t)("logs.filter.model")},null,8,["placeholder"])]),_:1}),v(l(Xo),null,{default:y(()=>[v(l(ln),{value:"all"},{default:y(()=>[j(S(l(t)("logs.filter.all")),1)]),_:1}),(_(!0),W(Se,null,tt(ie.value,ee=>(_(),D(l(ln),{key:ee,value:ee},{default:y(()=>[j(S(ee),1)]),_:2},1032,["value"]))),128))]),_:1})]),_:1},8,["modelValue"])]),x("div",IE,[x("span",ME,S(l(t)("logs.filter.provider")),1),v(l(zo),{modelValue:u.value,"onUpdate:modelValue":he[2]||(he[2]=ee=>u.value=ee)},{default:y(()=>[v(l(Go),{class:"h-8 w-full"},{default:y(()=>[v(l(Yo),{placeholder:l(t)("logs.filter.provider")},null,8,["placeholder"])]),_:1}),v(l(Xo),null,{default:y(()=>[v(l(ln),{value:"all"},{default:y(()=>[j(S(l(t)("logs.filter.all")),1)]),_:1}),(_(!0),W(Se,null,tt(ke.value,ee=>(_(),D(l(ln),{key:ee,value:ee},{default:y(()=>[j(S(ee),1)]),_:2},1032,["value"]))),128))]),_:1})]),_:1},8,["modelValue"])]),x("div",RE,[x("span",LE,S(l(t)("logs.filter.status")),1),v(l(zo),{modelValue:c.value,"onUpdate:modelValue":he[3]||(he[3]=ee=>c.value=ee)},{default:y(()=>[v(l(Go),{class:"h-8 w-full"},{default:y(()=>[v(l(Yo),{placeholder:l(t)("logs.filter.status")},null,8,["placeholder"])]),_:1}),v(l(Xo),null,{default:y(()=>[v(l(ln),{value:"all"},{default:y(()=>[j(S(l(t)("logs.filter.all")),1)]),_:1}),v(l(ln),{value:"success"},{default:y(()=>[j(S(l(t)("logs.filter.success")),1)]),_:1}),v(l(ln),{value:"error"},{default:y(()=>[j(S(l(t)("logs.filter.error")),1)]),_:1})]),_:1})]),_:1},8,["modelValue"])])])])]),_:1})]),_:1},8,["open"])]),ge.value.length?(_(),W("div",DE,[(_(!0),W(Se,null,tt(ge.value,ee=>(_(),W("span",{key:ee.key,class:"inline-flex items-center gap-1 rounded-full border border-input bg-muted/40 py-0.5 pl-2.5 pr-1 text-xs"},[x("span",FE,S(ee.label)+":",1),x("span",NE,S(ee.value),1),x("button",{type:"button",class:"rounded-full p-0.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground","aria-label":l(t)("logs.filter.remove",{label:ee.label}),onClick:ee.clear},[v(l(Ja),{class:"h-3 w-3"})],8,qE)]))),128)),x("button",{type:"button",class:"text-xs text-muted-foreground hover:text-foreground",onClick:$e},S(l(t)("logs.filter.clear")),1)])):pe("",!0),x("div",BE,[x("span",null,S(l(t)("logs.summary.window",{n:te.value.total})),1),x("span",{class:Ce({"text-destructive":te.value.fail>0})},S(l(t)("logs.summary.errorRate",{pct:te.value.errorRateStr})),3),x("span",null,S(l(t)("logs.summary.avgLatency",{ms:P(te.value.avgMs)})),1)]),r.value.length?(_(),W("div",VE,[x("div",UE,[v(l(Ol),{class:"h-4 w-4"}),j(" "+S(l(t)("logs.circuit.stripTitle")),1)]),x("ul",HE,[(_(!0),W(Se,null,tt(r.value,ee=>(_(),W("li",{key:ee.id,class:"flex flex-wrap items-center gap-x-2 gap-y-1 text-xs"},[x("span",jE,S(ee.name),1),v(l(yt),{variant:"warning",class:"gap-1 whitespace-nowrap"},{default:y(()=>[v(l(Ol),{class:"h-3 w-3"}),j(" "+S(l(t)("logs.circuit.remaining",{s:ee.secondsLeft})),1)]),_:2},1024),x("span",WE,S(ee.lastReason||l(t)("logs.circuit.reasonUnknown")),1),v(l(Re),{variant:"outline",size:"sm",class:"ml-auto h-6 gap-1",onClick:lt=>k(ee.id)},{default:y(()=>[v(l(mr),{class:"h-3 w-3"}),j(" "+S(l(t)("logs.circuit.reset")),1)]),_:1},8,["onClick"])]))),128))])])):pe("",!0),a.value.length?(_(),W("div",KE,[x("div",zE,[v(l(Ko),{class:"h-4 w-4"}),j(" "+S(l(t)("logs.pacing.stripTitle")),1)]),x("ul",GE,[(_(!0),W(Se,null,tt(a.value,ee=>(_(),W("li",{key:ee.id,class:"flex flex-wrap items-center gap-x-2 gap-y-1 text-xs"},[x("span",YE,S(ee.name),1),v(l(yt),{variant:"outline",class:"gap-1 whitespace-nowrap"},{default:y(()=>[v(l(Ko),{class:"h-3 w-3"}),j(" "+S(l(t)("logs.pacing.at",{used:ee.rpmUsed,cap:ee.rpm})),1)]),_:2},1024),x("span",XE,S(l(t)("logs.pacing.reason")),1)]))),128))])])):pe("",!0),n.value.length?J.value.length?(_(),W("div",ZE,[v(l(Lm),null,{default:y(()=>[v(l(Dm),null,{default:y(()=>[v(l(io),null,{default:y(()=>[v(l(zt),{class:"w-8"}),v(l(zt),null,{default:y(()=>[j(S(l(t)("logs.col.time")),1)]),_:1}),v(l(zt),null,{default:y(()=>[j(S(l(t)("logs.col.model")),1)]),_:1}),v(l(zt),null,{default:y(()=>[j(S(l(t)("logs.col.provider")),1)]),_:1}),v(l(zt),null,{default:y(()=>[j(S(l(t)("logs.col.format")),1)]),_:1}),v(l(zt),{class:"text-right"},{default:y(()=>[j(S(l(t)("logs.col.latency")),1)]),_:1}),v(l(zt),{class:"text-right"},{default:y(()=>[j(S(l(t)("logs.col.status")),1)]),_:1})]),_:1})]),_:1}),v(l(Fm),null,{default:y(()=>[(_(!0),W(Se,null,tt(J.value,ee=>(_(),W(Se,{key:z(ee)},[ee.kind==="cooldown"?(_(),D(l(io),{key:0,class:"bg-amber-500/5 hover:bg-amber-500/10"},{default:y(()=>[v(l(Dt),{colspan:"7",class:"py-2"},{default:y(()=>[x("div",eO,[x("span",tO,S(I(ee.ts)),1),v(l(yt),{variant:"warning",class:"gap-1 whitespace-nowrap"},{default:y(()=>[v(l(Ol),{class:"h-3 w-3"}),j(" "+S(l(t)("logs.circuit.badge")),1)]),_:1}),x("span",nO,S(ee.provider),1),x("span",sO,S(l(t)("logs.circuit.failures",{n:ee.fails})),1),x("span",oO,S(l(t)("logs.circuit.cooldown",{s:Math.round((ee.cooldownMs??0)/1e3)})),1),x("span",rO,S(ee.error||l(t)("logs.circuit.reasonUnknown")),1)])]),_:2},1024)]),_:2},1024)):(_(),W(Se,{key:1},[v(l(io),{class:"cursor-pointer hover:bg-muted/50",onClick:lt=>Z(ee)},{default:y(()=>[v(l(Dt),{class:"w-8 text-muted-foreground"},{default:y(()=>[(_(),D(br(de(ee)?l(Xa):l(bi)),{class:"h-3.5 w-3.5"}))]),_:2},1024),v(l(Dt),{class:"font-mono text-xs text-muted-foreground",title:R(ee.ts)},{default:y(()=>[j(S(I(ee.ts)),1)]),_:2},1032,["title"]),v(l(Dt),{class:"font-mono text-xs"},{default:y(()=>[j(S(ee.model),1),ee.upstreamModel?(_(),W("span",aO," → "+S(ee.upstreamModel),1)):pe("",!0)]),_:2},1024),v(l(Dt),{class:"text-sm"},{default:y(()=>[j(S(ee.provider),1)]),_:2},1024),v(l(Dt),null,{default:y(()=>[x("span",lO,[v(l(yt),{variant:"outline",class:Ce(b(ee.format))},{default:y(()=>[j(S(ee.format),1)]),_:2},1032,["class"]),ee.stream?(_(),D(l(yt),{key:0,variant:"muted",class:"text-[10px]"},{default:y(()=>[j(S(l(t)("logs.stream")),1)]),_:1})):pe("",!0)])]),_:2},1024),v(l(Dt),{class:"text-right font-mono text-xs text-muted-foreground"},{default:y(()=>[j(S(P(ee.ms)),1)]),_:2},1024),v(l(Dt),{class:"text-right"},{default:y(()=>[v(l(yt),{variant:T(ee.status),class:"font-mono"},{default:y(()=>[j(S(ee.status),1)]),_:2},1032,["variant"])]),_:2},1024)]),_:2},1032,["onClick"]),de(ee)?(_(),D(l(io),{key:0,class:"hover:bg-transparent"},{default:y(()=>[v(l(Dt),{colspan:"7",class:"bg-muted/30"},{default:y(()=>[x("dl",iO,[x("dt",uO,S(l(t)("logs.detail.time")),1),x("dd",cO,S(R(ee.ts)),1),x("dt",dO,S(l(t)("logs.detail.latency")),1),x("dd",fO,S(P(ee.ms)),1),x("dt",pO,S(l(t)("logs.detail.stream")),1),x("dd",null,S(ee.stream?l(t)("logs.detail.streamYes"):l(t)("logs.detail.streamNo")),1),ee.upstreamModel?(_(),W(Se,{key:0},[x("dt",mO,S(l(t)("logs.detail.upstreamModel")),1),x("dd",hO,S(ee.upstreamModel),1)],64)):pe("",!0),ee.usage?(_(),W(Se,{key:1},[x("dt",vO,S(l(t)("logs.detail.tokens")),1),x("dd",gO,[x("span",yO,"↑ "+S(A(ee.usage.input)),1),he[7]||(he[7]=x("span",{class:"text-muted-foreground/50"}," · ",-1)),x("span",bO,"↓ "+S(A(ee.usage.output)),1),ee.usage.estimated?(_(),D(l(yt),{key:0,variant:"muted",class:"ml-1.5 text-[10px]"},{default:y(()=>[j("≈ "+S(l(t)("logs.detail.estimated")),1)]),_:1})):pe("",!0),(ee.usage.cacheRead||0)+(ee.usage.cacheCreation||0)?(_(),W(Se,{key:1},[he[6]||(he[6]=x("span",{class:"text-muted-foreground/50"}," · ",-1)),x("span",_O,"⚡ "+S(l(t)("logs.detail.cache"))+" "+S(A((ee.usage.cacheRead||0)+(ee.usage.cacheCreation||0))),1)],64)):pe("",!0)])],64)):pe("",!0),x("dt",wO,S(l(t)("logs.detail.error")),1),x("dd",xO,S(ee.error||l(t)("logs.detail.errorNone")),1)])]),_:2},1024)]),_:2},1024)):pe("",!0)],64))],64))),128))]),_:1})]),_:1})])):(_(),W("p",QE,S(l(t)("logs.noMatch")),1)):(_(),W("p",JE,S(l(t)("logs.empty")),1))]),_:1})]),_:1}))}}),CO={key:0,class:"py-4 text-center text-xs text-muted-foreground"},SO={class:"flex items-center gap-1.5"},AO={class:"truncate font-mono text-xs"},EO={class:"flex items-center gap-2"},OO={class:"h-1.5 w-full max-w-[120px] overflow-hidden rounded-full bg-muted"},TO={class:"font-mono text-xs tabular-nums"},PO={key:0},$O={class:"text-foreground/80"},IO={class:"text-foreground/80"},MO={key:1,class:"text-muted-foreground/40"},RO={key:0,class:"inline-flex flex-col items-end leading-tight"},LO={class:"text-amber-600 dark:text-amber-400"},DO={class:"text-[10px] text-muted-foreground/60"},FO={key:1,class:"text-muted-foreground/40"},Vr=Q({__name:"StatsBreakdown",props:{title:{},buckets:{},max:{},kind:{}},setup(e){const{t}=It();function n(d){return d<1e3?`${d}ms`:`${(d/1e3).toFixed(1)}s`}function s(d){return d?d<1e3?String(d):d<1e6?(d/1e3).toFixed(d<1e4?1:0).replace(/\.0$/,"")+"k":(d/1e6).toFixed(1)+"M":"0"}function o(d){if(!d)return"0%";const f=Math.round(d*1e3)/10;return(f%1===0?f.toFixed(0):f.toFixed(1))+"%"}const r=e,a=()=>r.buckets.some(d=>d.inputTokens||d.outputTokens),i=()=>r.buckets.some(d=>d.cacheRead||d.cacheCreation);function u(d,f){return f?Math.round(d/f*100):0}function c(d){var f;return(f=tn[d])==null?void 0:f.solid}return(d,f)=>(_(),D(l(hn),null,{default:y(()=>[v(l(Mn),{class:"pb-2"},{default:y(()=>[v(l(Rn),{class:"text-sm"},{default:y(()=>[j(S(e.title),1)]),_:1})]),_:1}),v(l(vn),null,{default:y(()=>[e.buckets.length?(_(),D(l(Lm),{key:1},{default:y(()=>[v(l(Dm),null,{default:y(()=>[v(l(io),null,{default:y(()=>[v(l(zt),null,{default:y(()=>[j(S(l(t)("stats.col.name")),1)]),_:1}),v(l(zt),{class:"w-1/3"},{default:y(()=>[j(S(l(t)("stats.col.calls")),1)]),_:1}),v(l(zt),{class:"text-right"},{default:y(()=>[j(S(l(t)("stats.col.success")),1)]),_:1}),v(l(zt),{class:"text-right"},{default:y(()=>[j(S(l(t)("stats.col.error")),1)]),_:1}),v(l(zt),{class:"text-right"},{default:y(()=>[j(S(l(t)("stats.col.avgLatency")),1)]),_:1}),a()?(_(),D(l(zt),{key:0,class:"text-right"},{default:y(()=>[j(S(l(t)("stats.col.tokens")),1)]),_:1})):pe("",!0),i()?(_(),D(l(zt),{key:1,class:"text-right"},{default:y(()=>[j(S(l(t)("stats.col.cacheHit")),1)]),_:1})):pe("",!0)]),_:1})]),_:1}),v(l(Fm),null,{default:y(()=>[(_(!0),W(Se,null,tt(e.buckets,p=>(_(),D(l(io),{key:p.key},{default:y(()=>[v(l(Dt),{class:"py-1.5"},{default:y(()=>[x("div",SO,[e.kind==="format"&&c(p.key)?(_(),W("span",{key:0,class:Ce(["h-2 w-2 shrink-0 rounded-full",c(p.key)])},null,2)):e.kind==="provider"&&p.id?(_(),W("span",{key:1,class:Ce(["h-2 w-2 shrink-0 rounded-full",l(si)(p.id).solid])},null,2)):pe("",!0),x("span",AO,S(p.key),1)])]),_:2},1024),v(l(Dt),{class:"py-1.5"},{default:y(()=>[x("div",EO,[x("div",OO,[x("div",{class:"h-full rounded-full bg-primary/50",style:dn({width:u(p.calls,e.max)+"%"})},null,4)]),x("span",TO,S(p.calls),1)])]),_:2},1024),v(l(Dt),{class:"py-1.5 text-right font-mono text-xs text-emerald-600 dark:text-emerald-400"},{default:y(()=>[j(S(p.success),1)]),_:2},1024),v(l(Dt),{class:Ce(["py-1.5 text-right font-mono text-xs",p.error?"text-destructive":"text-muted-foreground"])},{default:y(()=>[j(S(p.error),1)]),_:2},1032,["class"]),v(l(Dt),{class:"py-1.5 text-right font-mono text-xs text-muted-foreground"},{default:y(()=>[j(S(n(p.avgMs)),1)]),_:2},1024),a()?(_(),D(l(Dt),{key:0,class:"py-1.5 text-right font-mono text-xs tabular-nums"},{default:y(()=>[p.inputTokens||p.outputTokens?(_(),W("span",PO,[x("span",$O,S(s(p.inputTokens)),1),f[0]||(f[0]=x("span",{class:"text-muted-foreground/50"}," / ",-1)),x("span",IO,S(s(p.outputTokens)),1)])):(_(),W("span",MO,"—"))]),_:2},1024)):pe("",!0),i()?(_(),D(l(Dt),{key:1,class:"py-1.5 text-right font-mono text-xs tabular-nums"},{default:y(()=>[p.cacheRead||p.cacheCreation?(_(),W("span",RO,[x("span",LO,S(o(p.cacheHitRate)),1),x("span",DO,"↑"+S(s(p.cacheRead)),1)])):(_(),W("span",FO,"—"))]),_:2},1024)):pe("",!0)]),_:2},1024))),128))]),_:1})]),_:1})):(_(),W("p",CO,S(l(t)("stats.empty")),1))]),_:1})]),_:1}))}}),NO={class:"flex flex-wrap items-center justify-between gap-2"},qO={class:"flex items-center gap-2"},BO={class:"inline-flex rounded-md border bg-muted/30 p-0.5"},VO=["onClick"],UO={class:"sr-only"},HO={key:0,class:"flex items-center justify-center gap-2 py-10 text-sm text-muted-foreground"},jO={key:1,class:"py-10 text-center text-sm text-muted-foreground"},WO={class:"grid grid-cols-2 gap-2 sm:grid-cols-3 lg:grid-cols-6"},KO={class:"rounded-lg border bg-muted/20 p-3"},zO={class:"text-xs text-muted-foreground"},GO={class:"mt-1 font-mono text-xl tabular-nums"},YO={class:"rounded-lg border bg-muted/20 p-3"},XO={class:"text-xs text-muted-foreground"},JO={class:"mt-1 font-mono text-xl tabular-nums text-emerald-600 dark:text-emerald-400"},QO={class:"rounded-lg border bg-muted/20 p-3"},ZO={class:"text-xs text-muted-foreground"},eT={class:"mt-1 font-mono text-xl tabular-nums text-destructive"},tT={class:"rounded-lg border bg-muted/20 p-3"},nT={class:"text-xs text-muted-foreground"},sT={class:"mt-1 font-mono text-xl tabular-nums"},oT={class:"rounded-lg border bg-muted/20 p-3"},rT={class:"text-xs text-muted-foreground"},aT={class:"mt-1 font-mono text-xl tabular-nums"},lT={class:"rounded-lg border bg-muted/20 p-3"},iT={class:"text-xs text-muted-foreground"},uT={class:"mt-1 font-mono text-xl tabular-nums"},cT={key:0,class:"grid grid-cols-3 gap-2"},dT={class:"rounded-lg border bg-muted/20 p-3"},fT={class:"text-xs text-muted-foreground"},pT={class:"mt-1 font-mono text-lg tabular-nums"},mT={class:"rounded-lg border bg-muted/20 p-3"},hT={class:"text-xs text-muted-foreground"},vT={class:"mt-1 font-mono text-lg tabular-nums"},gT={class:"rounded-lg border bg-muted/20 p-3"},yT={class:"text-xs text-muted-foreground"},bT={class:"mt-1 font-mono text-lg tabular-nums"},_T={class:"mb-2 flex items-center justify-between gap-2"},wT={class:"text-sm font-medium"},xT={key:0,class:"text-[11px] text-muted-foreground"},kT={class:"font-mono tabular-nums text-foreground"},CT={class:"rounded-lg border p-3"},ST={class:"relative pt-9"},AT={class:"flex h-40 gap-px"},ET={class:"pointer-events-none absolute bottom-full left-1/2 z-20 mb-1 hidden -translate-x-1/2 whitespace-nowrap rounded-md border bg-background px-2 py-1 text-center text-xs shadow-md group-hover:block"},OT={class:"font-medium"},TT={class:"font-mono tabular-nums"},PT={class:"text-[10px]"},$T={class:"text-emerald-600 dark:text-emerald-400"},IT={class:"text-destructive"},MT={class:"mt-1.5 flex justify-between text-[10px] text-muted-foreground"},RT={class:"grid gap-4 lg:grid-cols-2"},LT={class:"lg:col-span-2"},DT={key:1,class:"space-y-3"},FT={class:"text-sm font-medium"},NT={class:"grid gap-4 lg:grid-cols-2"},wd=160,qT=Q({__name:"Stats",setup(e){const{t}=It(),n=[{v:"24h",key:"h24"},{v:"7d",key:"d7"},{v:"30d",key:"d30"},{v:"90d",key:"d90"},{v:"all",key:"all"}],s=N(localStorage.getItem("myapikey.stats.range")||"7d");n.some(T=>T.v===s.value)||(s.value="7d"),Fe(s,T=>{try{localStorage.setItem("myapikey.stats.range",T)}catch{}});const o=N(null),r=N(!1);async function a(){r.value=!0;try{o.value=await Ue("GET",`/admin/stats?range=${s.value}`)}catch{o.value=null}finally{r.value=!1}}Fe(s,a),dt(a);function i(T){return T<1e3?`${T}ms`:`${(T/1e3).toFixed(1)}s`}function u(T){if(!T)return"0%";const b=Math.round(T*1e3)/10;return(b%1===0?b.toFixed(0):b.toFixed(1))+"%"}function c(T){const[b,P,A]=T.split("-").map(Number);return new Date(b,P-1,A).toLocaleDateString(void 0,{month:"short",day:"numeric"})}const d=X(()=>{var T;return((T=o.value)==null?void 0:T.byDay.reduce((b,P)=>Math.max(b,P.calls),0))??0});function f(T){const b=d.value||1,P=T.calls/b*wd,A=T.error/b*wd;return{success:Math.max(0,Math.round(P-A)),error:Math.round(A)}}function p(T){return T.reduce((b,P)=>Math.max(b,P.calls),0)||1}const m=X(()=>!!o.value&&o.value.totals.calls>0),w=X(()=>{var T,b;return(((T=o.value)==null?void 0:T.totals.cacheRead)??0)+(((b=o.value)==null?void 0:b.totals.cacheCreation)??0)}),k=X(()=>!!o.value&&!!(o.value.totals.inputTokens||o.value.totals.outputTokens||w.value)),E=X(()=>{var P;const T=(((P=o.value)==null?void 0:P.byProviderModel)??[]).filter(A=>A.cacheRead||A.cacheCreation),b=new Map;for(const A of T){const C=A.providerId||A.provider;let I=b.get(C);I||(I={providerId:A.providerId,provider:A.provider,models:[],cacheRead:0},b.set(C,I)),I.models.push({key:A.model,calls:A.calls,success:A.success,error:0,avgMs:0,inputTokens:A.inputTokens,outputTokens:A.outputTokens,cacheRead:A.cacheRead,cacheCreation:A.cacheCreation,cacheHitRate:A.cacheHitRate}),I.cacheRead+=A.cacheRead}return[...b.values()].sort((A,C)=>C.cacheRead-A.cacheRead)}),h=X(()=>E.value.length>0);function g(T){return T?T<1e3?String(T):T<1e6?(T/1e3).toFixed(T<1e4?1:0).replace(/\.0$/,"")+"k":(T/1e6).toFixed(1)+"M":"0"}return(T,b)=>(_(),D(l(hn),null,{default:y(()=>[v(l(Mn),null,{default:y(()=>[x("div",NO,[v(l(Rn),{class:"flex items-center gap-2 text-base"},{default:y(()=>[v(l(Am),{class:"h-4 w-4 text-primary"}),j(" "+S(l(t)("stats.title")),1)]),_:1}),x("div",qO,[x("div",BO,[(_(),W(Se,null,tt(n,P=>x("button",{key:P.v,type:"button",class:Ce(["rounded-sm px-2.5 py-1 text-xs transition-colors",s.value===P.v?"bg-background font-medium shadow-sm":"text-muted-foreground hover:text-foreground"]),onClick:A=>s.value=P.v},S(l(t)(`stats.ranges.${P.key}`)),11,VO)),64))]),v(l(Re),{variant:"outline",size:"sm",disabled:r.value,onClick:a},{default:y(()=>[r.value?(_(),D(l(kt),{key:0,class:"h-3.5 w-3.5 animate-spin"})):(_(),D(l(mr),{key:1,class:"h-3.5 w-3.5"})),x("span",UO,S(l(t)("stats.refresh")),1)]),_:1},8,["disabled"])])]),v(l(gs),null,{default:y(()=>[j(S(l(t)("stats.desc")),1)]),_:1})]),_:1}),v(l(vn),{class:"space-y-5"},{default:y(()=>[r.value&&!o.value?(_(),W("div",HO,[v(l(kt),{class:"h-4 w-4 animate-spin"}),j(" "+S(l(t)("stats.loading")),1)])):m.value?o.value?(_(),W(Se,{key:2},[x("div",WO,[x("div",KO,[x("div",zO,S(l(t)("stats.totals.calls")),1),x("div",GO,S(o.value.totals.calls),1)]),x("div",YO,[x("div",XO,S(l(t)("stats.totals.success")),1),x("div",JO,S(o.value.totals.success),1)]),x("div",QO,[x("div",ZO,S(l(t)("stats.totals.error")),1),x("div",eT,S(o.value.totals.error),1)]),x("div",tT,[x("div",nT,S(l(t)("stats.totals.errorRate")),1),x("div",sT,S(u(o.value.totals.errorRate)),1)]),x("div",oT,[x("div",rT,S(l(t)("stats.totals.avgLatency")),1),x("div",aT,S(i(o.value.totals.avgMs)),1)]),x("div",lT,[x("div",iT,S(l(t)("stats.totals.p95")),1),x("div",uT,S(i(o.value.totals.p95Ms)),1)])]),k.value?(_(),W("div",cT,[x("div",dT,[x("div",fT,"↑ "+S(l(t)("stats.totals.inputTokens")),1),x("div",pT,S(g(o.value.totals.inputTokens)),1)]),x("div",mT,[x("div",hT,"↓ "+S(l(t)("stats.totals.outputTokens")),1),x("div",vT,S(g(o.value.totals.outputTokens)),1)]),x("div",gT,[x("div",yT,"⚡ "+S(l(t)("stats.totals.cache")),1),x("div",bT,S(g(w.value)),1)])])):pe("",!0),x("div",null,[x("div",_T,[x("div",wT,S(l(t)("stats.byDay")),1),d.value?(_(),W("div",xT,[j(S(l(t)("stats.peak"))+" ",1),x("span",kT,S(d.value),1)])):pe("",!0)]),x("div",CT,[x("div",ST,[x("div",AT,[(_(!0),W(Se,null,tt(o.value.byDay,P=>(_(),W("div",{key:P.day,class:"group relative flex min-w-0 flex-1 cursor-default flex-col justify-end"},[x("div",{style:dn({height:f(P).success+"px"}),class:"w-full rounded-t-sm bg-emerald-500/70 transition-colors group-hover:bg-emerald-500"},null,4),x("div",{style:dn({height:f(P).error+"px"}),class:Ce(["w-full transition-colors group-hover:bg-destructive",f(P).error?"bg-destructive/70":""])},null,6),x("div",ET,[x("div",OT,S(c(P.day)),1),x("div",TT,S(P.calls)+" "+S(l(t)("stats.callsAxis")),1),x("div",PT,[x("span",$T,S(P.success),1),b[0]||(b[0]=x("span",{class:"text-muted-foreground"}," / ",-1)),x("span",IT,S(P.error),1)])])]))),128))])]),x("div",MT,[x("span",null,S(o.value.byDay.length?c(o.value.byDay[0].day):""),1),x("span",null,S(o.value.byDay.length?c(o.value.byDay[o.value.byDay.length-1].day):""),1)])])]),x("div",RT,[x("div",LT,[v(Vr,{title:l(t)("stats.byModel"),buckets:o.value.byModel,max:p(o.value.byModel),kind:"model"},null,8,["title","buckets","max"])]),v(Vr,{title:l(t)("stats.byProvider"),buckets:o.value.byProvider,max:p(o.value.byProvider),kind:"provider"},null,8,["title","buckets","max"]),v(Vr,{title:l(t)("stats.byFormat"),buckets:o.value.byFormat,max:p(o.value.byFormat),kind:"format"},null,8,["title","buckets","max"])]),h.value?(_(),W("div",DT,[x("div",FT,S(l(t)("stats.cacheBySource")),1),x("div",NT,[(_(!0),W(Se,null,tt(E.value,P=>(_(),D(Vr,{key:P.providerId||P.provider,title:P.provider,buckets:P.models,max:p(P.models),kind:"model"},null,8,["title","buckets","max"]))),128))])])):pe("",!0)],64)):pe("",!0):(_(),W("div",jO,S(l(t)("stats.empty")),1))]),_:1})]),_:1}))}}),BT={class:"space-y-4"},VT={class:"space-y-2"},UT={class:"min-w-0"},HT={class:"mt-0.5 truncate font-mono text-sm"},jT={class:"min-w-0"},WT={class:"mt-0.5 truncate font-mono text-sm"},KT={class:"text-xs text-muted-foreground"},zT={class:"flex items-center justify-between gap-3 rounded-lg border border-primary/40 bg-primary/5 p-3"},GT={class:"min-w-0"},YT={class:"text-xs font-medium text-primary"},XT={class:"truncate font-mono text-sm"},JT={class:"flex items-center gap-1"},QT={class:"overflow-x-auto rounded-md border bg-muted/40 p-3 font-mono text-xs leading-relaxed"},ZT=Q({__name:"Connect",setup(e){const{t}=It(),n={openai:"openai",anthropic:"anthropic",responses:"responses",curl:null,"curl-anthropic":"anthropic"};function s(w){const k=n[w];return k?tn[k]:null}const o=N(null),r=N(null),a=N(""),i=N(!1),u=X(()=>{const w=window.location.hostname;if((w==="localhost"||w==="127.0.0.1")&&r.value){const k=window.location.port;return`${window.location.protocol}//${r.value}${k?":"+k:""}`}return window.location.origin}),c=X(()=>`${u.value}/openai/v1`),d=X(()=>`${u.value}/anthropic`);async function f(){o.value=(await Ue("GET","/admin/api-key")).apiKey,r.value=(await Ue("GET","/admin/connection")).lanIp}async function p(w,k){await Xi(k)?(a.value=w,setTimeout(()=>{a.value===w&&(a.value="")},1500)):Le(t("connect.copyFailed"),"error")}const m=X(()=>[{key:"openai",title:t("connect.openaiTitle"),text:`export OPENAI_BASE_URL=${c.value}
282
+ */const Tl=Ne("zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]),Qa=Q({__name:"Dialog",props:{open:{type:Boolean},defaultOpen:{type:Boolean},modal:{type:Boolean},unmountOnHide:{type:Boolean}},emits:["update:open"],setup(e,{emit:t}){const o=Rt(e,t);return(r,a)=>(_(),D(l(R1),Ot($t(l(o))),{default:y(()=>[ae(r.$slots,"default")]),_:3},16))}}),Za=Q({__name:"DialogContent",props:{forceMount:{type:Boolean},disableOutsidePointerEvents:{type:Boolean},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},emits:["escapeKeyDown","pointerDownOutside","focusOutside","interactOutside","openAutoFocus","closeAutoFocus"],setup(e,{emit:t}){const n=e,s=t,o=X(()=>{const{class:a,...i}=n;return i}),r=Rt(o,s);return(a,i)=>(_(),D(l(h0),null,{default:y(()=>[v(l(f0),{class:"fixed inset-0 z-50 bg-black/80"}),v(l(a0),Ie(l(r),{class:l(Ye)("fixed left-[50%] top-[50%] z-50 flex max-h-[90vh] w-full max-w-lg translate-x-[-50%] translate-y-[-50%] flex-col gap-4 overflow-hidden border bg-background p-6 shadow-lg sm:rounded-lg",n.class)}),{default:y(()=>[ae(a.$slots,"default"),v(l(D1),{class:"absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:ring-offset-background"},{default:y(()=>[v(l(Ja),{class:"h-4 w-4"}),i[0]||(i[0]=x("span",{class:"sr-only"},"Close",-1))]),_:1})]),_:3},16,["class"])]),_:3}))}}),el=Q({__name:"DialogTitle",props:{asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},setup(e){const t=e;return(n,s)=>(_(),D(l(g0),{class:Ce(l(Ye)("text-lg font-semibold leading-none tracking-tight",t.class))},{default:y(()=>[ae(n.$slots,"default")]),_:3},8,["class"]))}}),tl=Q({__name:"DialogDescription",props:{asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},setup(e){const t=e;return(n,s)=>(_(),D(l(i0),{class:Ce(l(Ye)("text-sm text-muted-foreground",t.class))},{default:y(()=>[ae(n.$slots,"default")]),_:3},8,["class"]))}}),vo=Q({__name:"Checkbox",props:ys({class:{type:[Boolean,null,String,Object,Array]},id:{}},{modelValue:{type:Boolean},modelModifiers:{}}),emits:["update:modelValue"],setup(e){const t=e,n=_r(e,"modelValue");return(s,o)=>(_(),D(l(Uw),{modelValue:n.value,"onUpdate:modelValue":o[0]||(o[0]=r=>n.value=r),id:t.id,class:Ce(l(Ye)("peer h-4 w-4 shrink-0 cursor-pointer rounded-[4px] border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",t.class))},{default:y(()=>[v(l(jw),{class:"flex h-full w-full items-center justify-center text-current"},{default:y(()=>[v(l(Pn),{class:"h-3.5 w-3.5"})]),_:1})]),_:1},8,["modelValue","id","class"]))}}),Mm=Q({__name:"Separator",props:{class:{type:[Boolean,null,String,Object,Array]},orientation:{}},setup(e){const t=e;return(n,s)=>(_(),D(l(Pk),{orientation:t.orientation??"horizontal",class:Ce(l(Ye)("shrink-0 bg-border",t.orientation==="vertical"?"h-full w-px":"h-px w-full",t.class))},null,8,["orientation","class"]))}}),lC={class:"flex gap-3 pr-8"},iC={key:0,class:"flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-destructive/15 text-destructive"},uC={class:"min-w-0 flex-1 space-y-1.5"},cC={class:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end"},gu=Q({__name:"ConfirmDialog",props:ys({title:{},description:{},confirmText:{default:""},cancelText:{default:""},variant:{default:"default"},loading:{type:Boolean,default:!1}},{open:{type:Boolean,default:!1},openModifiers:{}}),emits:ys(["confirm"],["update:open"]),setup(e,{emit:t}){const{t:n}=It(),s=_r(e,"open"),o=t;return(r,a)=>(_(),D(l(Qa),{open:s.value,"onUpdate:open":a[2]||(a[2]=i=>s.value=i)},{default:y(()=>[v(l(Za),{class:"max-w-sm"},{default:y(()=>[x("div",lC,[e.variant==="destructive"?(_(),W("span",iC,[v(l(rC),{class:"h-4 w-4"})])):pe("",!0),x("div",uC,[v(l(el),{class:"text-base leading-tight"},{default:y(()=>[j(S(e.title),1)]),_:1}),e.description?(_(),D(l(tl),{key:0},{default:y(()=>[j(S(e.description),1)]),_:1})):pe("",!0)])]),x("div",cC,[v(l(Re),{variant:"outline",disabled:e.loading,onClick:a[0]||(a[0]=i=>s.value=!1)},{default:y(()=>[j(S(e.cancelText||l(n)("common.cancel")),1)]),_:1},8,["disabled"]),v(l(Re),{variant:e.variant,disabled:e.loading,onClick:a[1]||(a[1]=i=>o("confirm"))},{default:y(()=>[e.loading?(_(),D(l(kt),{key:0,class:"h-4 w-4 animate-spin"})):pe("",!0),j(" "+S(e.confirmText||l(n)("common.confirm")),1)]),_:1},8,["variant","disabled"])])]),_:1})]),_:1},8,["open"]))}}),dC={class:"space-y-3"},fC={key:0,class:"space-y-1.5"},pC={class:"text-xs font-medium text-muted-foreground"},mC={class:"space-y-1.5"},hC={class:"text-xs font-medium text-muted-foreground"},vC={class:"space-y-2 rounded-md border bg-background/50 p-3"},gC={class:"space-y-2"},yC={class:"flex items-center gap-2.5"},bC={class:"flex items-center gap-2.5 pl-7"},_C={class:"flex items-center gap-2.5"},wC={class:"text-xs text-muted-foreground"},xC={key:1,class:"space-y-1.5"},kC={class:"text-xs font-medium text-muted-foreground"},CC={class:"text-xs text-muted-foreground"},SC={key:2,class:"space-y-1.5"},AC={class:"text-xs font-medium text-muted-foreground"},EC={class:"text-xs text-muted-foreground"},OC={key:3,class:"space-y-1.5"},TC={class:"text-xs font-medium text-muted-foreground"},PC={key:4,class:"text-sm text-destructive"},yu=Q({__name:"NewSourceForm",props:{formatsOnly:{type:Boolean}},setup(e,{expose:t}){const n=e,{t:s}=It(),o=N(""),r=N(""),a=N(""),i=N(""),u=N(!0),c=N(!1),d=N(!1),f=N("");function p(h){if(h==="openai"){if(u.value&&!c.value)return;u.value=!u.value}else{if(c.value&&!u.value)return;c.value=!c.value}}const m=X(()=>{const h=[];return u.value&&h.push("openai"),c.value&&h.push("anthropic"),h}),w=X(()=>({name:o.value.trim(),baseUrlOpenai:r.value,baseUrlAnthropic:a.value,apiKey:i.value,formats:m.value,supportsResponses:u.value&&d.value}));function k(){o.value=i.value="",r.value=a.value="",u.value=!0,c.value=!1,d.value=!1,f.value=""}function E(){if(!m.value.length)f.value=s("sources.errFormat");else{if(n.formatsOnly)return f.value="",!0;if(!o.value.trim()||!i.value)f.value=s("sources.errRequired");else if(u.value&&!r.value.trim()||c.value&&!a.value.trim())f.value=s("sources.errBaseUrl");else return f.value="",!0}return!1}return t({reset:k,validate:E,payload:w}),(h,g)=>(_(),W("div",dC,[e.formatsOnly?pe("",!0):(_(),W("div",fC,[x("label",pC,S(l(s)("sources.nameLabel")),1),v(l(Tt),{modelValue:o.value,"onUpdate:modelValue":g[0]||(g[0]=T=>o.value=T),placeholder:l(s)("sources.namePh"),autocomplete:"off","aria-label":"name"},null,8,["modelValue","placeholder"])])),x("div",mC,[x("label",hC,S(l(s)("sources.formats")),1),x("div",vC,[x("div",gC,[x("div",yC,[v(l(vo),{"model-value":u.value,disabled:u.value&&!c.value,"aria-label":"openai","onUpdate:modelValue":g[1]||(g[1]=T=>p("openai"))},null,8,["model-value","disabled"]),g[7]||(g[7]=x("span",{class:"text-sm font-medium leading-none"},"openai",-1)),g[8]||(g[8]=x("span",{class:"text-xs text-muted-foreground"},"/chat/completions",-1))]),x("div",bC,[v(l(vo),{modelValue:d.value,"onUpdate:modelValue":g[2]||(g[2]=T=>d.value=T),disabled:!u.value,"aria-label":l(s)("sources.responses")},null,8,["modelValue","disabled","aria-label"]),x("span",{class:Ce(["text-sm leading-none",u.value?"":"text-muted-foreground"])},S(l(s)("sources.responses")),3),g[9]||(g[9]=x("span",{class:"text-xs text-muted-foreground"},"/responses",-1))])]),v(l(Mm)),x("div",_C,[v(l(vo),{"model-value":c.value,disabled:c.value&&!u.value,"aria-label":"anthropic","onUpdate:modelValue":g[3]||(g[3]=T=>p("anthropic"))},null,8,["model-value","disabled"]),g[10]||(g[10]=x("span",{class:"text-sm font-medium leading-none"},"anthropic",-1)),g[11]||(g[11]=x("span",{class:"text-xs text-muted-foreground"},"/messages",-1))])]),x("p",wC,S(l(s)("sources.addHint")),1)]),!e.formatsOnly&&u.value?(_(),W("div",xC,[x("label",kC,S(l(s)("sources.urlLabelOpenai")),1),v(l(Tt),{modelValue:r.value,"onUpdate:modelValue":g[4]||(g[4]=T=>r.value=T),placeholder:l(s)("sources.urlPhOpenai"),autocomplete:"off","aria-label":"openai base url"},null,8,["modelValue","placeholder"]),x("p",CC,S(l(s)("sources.urlHintOpenai")),1)])):pe("",!0),!e.formatsOnly&&c.value?(_(),W("div",SC,[x("label",AC,S(l(s)("sources.urlLabelAnthropic")),1),v(l(Tt),{modelValue:a.value,"onUpdate:modelValue":g[5]||(g[5]=T=>a.value=T),placeholder:l(s)("sources.urlPhAnthropic"),autocomplete:"off","aria-label":"anthropic base url"},null,8,["modelValue","placeholder"]),x("p",EC,S(l(s)("sources.urlHintAnthropic")),1)])):pe("",!0),e.formatsOnly?pe("",!0):(_(),W("div",OC,[x("label",TC,S(l(s)("sources.keyLabel")),1),v(l(Tt),{modelValue:i.value,"onUpdate:modelValue":g[6]||(g[6]=T=>i.value=T),type:"password",placeholder:l(s)("sources.keyPh"),autocomplete:"new-password","aria-label":"api key"},null,8,["modelValue","placeholder"])])),f.value?(_(),W("p",PC,S(f.value),1)):pe("",!0)]))}}),$C={class:"flex shrink-0 items-center gap-2 pr-8"},IC={class:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-primary/15 text-primary"},MC={class:"min-w-0"},RC={class:"min-h-0 flex-1 space-y-4 overflow-y-auto px-1 py-1.5"},LC={key:0,class:"py-4 text-center text-sm text-muted-foreground"},DC={key:1,class:"py-4 text-center text-sm text-destructive"},FC={class:"space-y-1"},NC={key:0,class:"space-y-1.5 rounded-md border bg-muted/30 p-3 text-xs leading-relaxed text-muted-foreground"},qC={key:3,class:"space-y-3 rounded-lg border bg-muted/30 p-4"},BC={class:"flex justify-end gap-2"},VC={key:4,class:"space-y-2"},UC={key:0,class:"flex items-center gap-3"},HC={class:"min-w-0 flex-1"},jC={class:"flex items-center gap-2"},WC={class:"truncate font-medium"},KC={key:0,class:"mt-0.5 truncate font-mono text-xs text-muted-foreground"},zC={key:1,class:"mt-0.5 truncate font-mono text-xs text-muted-foreground"},GC={key:1,class:"space-y-3"},YC={class:"space-y-1.5"},XC={class:"text-xs font-medium text-muted-foreground"},JC={class:"space-y-1.5"},QC={class:"text-xs font-medium text-muted-foreground"},ZC={class:"space-y-3 rounded-md border bg-background/50 p-3"},eS={class:"space-y-2"},tS={class:"flex items-center gap-2.5"},nS={class:"flex items-center gap-2.5 pl-7"},sS={class:"flex items-center gap-2.5"},oS={key:0,class:"space-y-1.5"},rS={class:"text-xs font-medium text-muted-foreground"},aS={class:"text-xs text-muted-foreground"},lS={key:1,class:"space-y-1.5"},iS={class:"text-xs font-medium text-muted-foreground"},uS={class:"text-xs text-muted-foreground"},cS={class:"space-y-1.5"},dS={class:"flex items-center justify-between"},fS={class:"text-xs font-medium text-muted-foreground"},pS={key:0,class:"text-xs text-muted-foreground"},mS={class:"space-y-1.5"},hS={class:"text-xs font-medium text-muted-foreground"},vS={class:"text-xs text-muted-foreground"},gS={class:"flex justify-end gap-2"},yS=Q({__name:"SourcesDialog",props:{open:{type:Boolean,default:!1},openModifiers:{}},emits:ys(["changed"],["update:open"]),setup(e,{emit:t}){const{t:n}=It(),s=_r(e,"open"),o=t,r=N([]),a=N(!1),i=N(""),u=N(null),c=N(!1),d=N(!1),f=N(!1),p=N(null),m=N(""),w=N(""),k=N(""),E=N(""),h=N(""),g=N(!0),T=N(!1),b=N(!1),P=N(!1),A=N({}),C=N(null),I=N(!1),R=N(!1);async function z(){a.value=!0,i.value="";try{const fe=await Ue("GET","/admin/providers");r.value=fe.providers}catch(fe){i.value=fe.message}finally{a.value=!1}}Fe(s,fe=>{fe&&z()});function de(fe){if(fe==="openai"){if(g.value&&!T.value)return;g.value=!g.value}else{if(T.value&&!g.value)return;T.value=!T.value}}function Z(){const fe=[];return g.value&&fe.push("openai"),T.value&&fe.push("anthropic"),fe}async function ie(){var fe,ue;if(!c.value&&(fe=u.value)!=null&&fe.validate()){c.value=!0;try{const ye=await Ue("POST","/admin/providers",u.value.payload);r.value=[...r.value,ye.provider],(ue=u.value)==null||ue.reset(),d.value=!1,Le(n("sources.added"),"success"),o("changed")}catch(ye){Le(ye.message,"error")}finally{c.value=!1}}}function ke(fe){p.value=fe.id,m.value=fe.name,w.value=fe.baseUrlOpenai,k.value=fe.baseUrlAnthropic,E.value="",h.value=fe.rpm?String(fe.rpm):"",g.value=fe.formats.includes("openai"),T.value=fe.formats.includes("anthropic"),b.value=!!fe.supportsResponses}function J(){p.value=null}async function te(fe){if(P.value)return;const ue=Z();if(!m.value){Le(n("sources.errRequired"),"error");return}if(!ue.length){Le(n("sources.errFormat"),"error");return}if(g.value&&!w.value||T.value&&!k.value){Le(n("sources.errBaseUrl"),"error");return}P.value=!0;try{const ye={name:m.value,baseUrlOpenai:w.value,baseUrlAnthropic:k.value,formats:ue,supportsResponses:g.value&&b.value,rpm:Number(h.value)||0};E.value&&(ye.apiKey=E.value);const Ee=await Ue("PUT",`/admin/providers/${fe.id}`,ye);r.value=r.value.map(st=>st.id===fe.id?Ee.provider:st),p.value=null,Le(n("sources.updated"),"success"),o("changed")}catch(ye){Le(ye.message,"error")}finally{P.value=!1}}async function ce(fe){A.value[fe.id]=!0;try{const ue=await Ue("POST",`/admin/providers/${fe.id}/discover`);r.value=r.value.map(ye=>ye.id===fe.id?{...ye,discoveredModels:ue.models}:ye),Le(n("sources.refreshDone",{name:fe.name}),ue.models.length?"success":"default"),o("changed")}catch(ue){Le(ue.message,"error")}finally{A.value[fe.id]=!1}}function ge(fe){C.value=fe,I.value=!0}async function $e(){const fe=C.value;if(!(!fe||R.value)){R.value=!0;try{await Ue("DELETE",`/admin/providers/${fe.id}`),r.value=r.value.filter(ue=>ue.id!==fe.id),Le(n("sources.removed",{name:fe.name}),"success"),o("changed"),I.value=!1}catch(ue){Le(ue.message,"error")}finally{R.value=!1}}}function K(fe){var ue;return((ue=fe.discoveredModels)==null?void 0:ue.length)??0}function he(fe){return K(fe)>0?"found":fe.discoveredAt?"empty":"never"}function ee(fe){const ue=he(fe);return ue==="found"?n("sources.discoveredCount",{n:K(fe)}):n(ue==="empty"?"sources.noModelsFound":"sources.notScanned")}function lt(fe){const ue=he(fe);return ue==="empty"?n("sources.noModelsHint"):ue==="never"?n("sources.notScannedHint"):""}return(fe,ue)=>(_(),W(Se,null,[v(l(Qa),{open:s.value,"onUpdate:open":ue[11]||(ue[11]=ye=>s.value=ye)},{default:y(()=>[v(l(Za),{class:"max-w-xl"},{default:y(()=>[x("div",$C,[x("span",IC,[v(l(wi),{class:"h-4 w-4"})]),x("div",MC,[v(l(el),{class:"text-base"},{default:y(()=>[j(S(l(n)("sources.manage")),1)]),_:1}),v(l(tl),null,{default:y(()=>[j(S(l(n)("sources.subtitle")),1)]),_:1})])]),x("div",RC,[a.value?(_(),W("p",LC,S(l(n)("common.loading")),1)):i.value?(_(),W("p",DC,S(i.value),1)):pe("",!0),x("div",FC,[x("button",{type:"button",class:"inline-flex items-center gap-1 text-xs font-medium text-muted-foreground hover:text-foreground",onClick:ue[0]||(ue[0]=ye=>f.value=!f.value)},[v(l(Tm),{class:"h-3.5 w-3.5"}),j(" "+S(l(n)("sources.baseHelpToggle"))+" ",1),v(l(Xa),{class:Ce(["h-3.5 w-3.5 transition-transform",{"rotate-180":f.value}])},null,8,["class"])]),f.value?(_(),W("div",NC,[x("p",null,S(l(n)("sources.baseHelpSplit")),1),x("p",null,[ue[13]||(ue[13]=x("span",{class:"font-medium text-foreground"},"openai",-1)),j(" — "+S(l(n)("sources.baseHelpOpenai")),1)]),x("p",null,[ue[14]||(ue[14]=x("span",{class:"font-medium text-foreground"},"anthropic",-1)),j(" — "+S(l(n)("sources.baseHelpAnthropic")),1)])])):pe("",!0)]),!d.value&&r.value.length?(_(),D(l(Re),{key:2,variant:"outline",class:"w-full justify-center",onClick:ue[1]||(ue[1]=ye=>d.value=!0)},{default:y(()=>[v(l(es),{class:"h-4 w-4"}),j(S(l(n)("sources.add")),1)]),_:1})):(_(),W("div",qC,[v(yu,{ref_key:"newForm",ref:u},null,512),x("div",BC,[r.value.length?(_(),D(l(Re),{key:0,variant:"ghost",size:"sm",onClick:ue[2]||(ue[2]=ye=>d.value=!1)},{default:y(()=>[j(S(l(n)("sources.cancel")),1)]),_:1})):pe("",!0),v(l(Re),{size:"sm",disabled:c.value,onClick:ie},{default:y(()=>[c.value?(_(),D(l(kt),{key:0,class:"h-4 w-4 animate-spin"})):(_(),D(l(es),{key:1,class:"h-4 w-4"})),j(S(l(n)("sources.addBtn")),1)]),_:1},8,["disabled"])])])),r.value.length?(_(),W("div",VC,[(_(!0),W(Se,null,tt(r.value,ye=>(_(),W("div",{key:ye.id,class:"rounded-lg border p-3"},[p.value!==ye.id?(_(),W("div",UC,[x("div",HC,[x("div",jC,[x("span",WC,S(ye.name),1),(_(!0),W(Se,null,tt(ye.formats,Ee=>(_(),D(l(yt),{key:Ee,variant:"secondary"},{default:y(()=>[j(S(Ee),1)]),_:2},1024))),128)),ye.rpm?(_(),D(l(yt),{key:0,variant:"outline",title:l(n)("sources.rpmBadgeHint")},{default:y(()=>[j(S(l(n)("sources.rpmBadge",{n:ye.rpm})),1)]),_:2},1032,["title"])):pe("",!0),v(l(yt),{variant:"muted",title:lt(ye)},{default:y(()=>[j(S(ee(ye)),1)]),_:2},1032,["title"])]),ye.formats.includes("openai")?(_(),W("div",KC,[ue[15]||(ue[15]=x("span",{class:"opacity-60"},"openai ·",-1)),j(" "+S(ye.baseUrlOpenai),1)])):pe("",!0),ye.formats.includes("anthropic")?(_(),W("div",zC,[ue[16]||(ue[16]=x("span",{class:"opacity-60"},"anthropic ·",-1)),j(" "+S(ye.baseUrlAnthropic),1)])):pe("",!0)]),v(l(hi),null,{default:y(()=>[v(l(vi),null,{default:y(()=>[v(l(Re),{variant:"ghost",size:"icon",class:"h-8 w-8","aria-label":l(n)("sources.moreActions")},{default:y(()=>[v(l(_i),{class:"h-4 w-4"})]),_:1},8,["aria-label"])]),_:1}),v(l(gi),{align:"end"},{default:y(()=>[v(l(Wn),{disabled:A.value[ye.id],onSelect:Ee=>ce(ye)},{default:y(()=>[A.value[ye.id]?(_(),D(l(kt),{key:0,class:"animate-spin"})):(_(),D(l(mr),{key:1})),j(" "+S(l(n)("sources.refreshModels")),1)]),_:2},1032,["disabled","onSelect"]),v(l(Wn),{onSelect:Ee=>ke(ye)},{default:y(()=>[v(l(Pm)),j(" "+S(l(n)("sources.editLabel")),1)]),_:1},8,["onSelect"]),v(l(yi)),v(l(Wn),{class:"text-destructive focus:bg-destructive/10 focus:text-destructive",onSelect:Ee=>ge(ye)},{default:y(()=>[v(l(xi)),j(" "+S(l(n)("sources.deleteLabel")),1)]),_:1},8,["onSelect"])]),_:2},1024)]),_:2},1024)])):(_(),W("div",GC,[x("div",YC,[x("label",XC,S(l(n)("sources.nameLabel")),1),v(l(Tt),{modelValue:m.value,"onUpdate:modelValue":ue[3]||(ue[3]=Ee=>m.value=Ee),placeholder:l(n)("sources.namePh"),autocomplete:"off","aria-label":"name"},null,8,["modelValue","placeholder"])]),x("div",JC,[x("label",QC,S(l(n)("sources.formats")),1),x("div",ZC,[x("div",eS,[x("div",tS,[v(l(vo),{"model-value":g.value,disabled:g.value&&!T.value,"aria-label":"openai","onUpdate:modelValue":ue[4]||(ue[4]=Ee=>de("openai"))},null,8,["model-value","disabled"]),ue[17]||(ue[17]=x("span",{class:"text-sm font-medium leading-none"},"openai",-1)),ue[18]||(ue[18]=x("span",{class:"text-xs text-muted-foreground"},"/chat/completions",-1))]),x("div",nS,[v(l(vo),{modelValue:b.value,"onUpdate:modelValue":ue[5]||(ue[5]=Ee=>b.value=Ee),disabled:!g.value,"aria-label":l(n)("sources.responses")},null,8,["modelValue","disabled","aria-label"]),x("span",{class:Ce(["text-sm leading-none",g.value?"":"text-muted-foreground"])},S(l(n)("sources.responses")),3),ue[19]||(ue[19]=x("span",{class:"text-xs text-muted-foreground"},"/responses",-1))])]),v(l(Mm)),x("div",sS,[v(l(vo),{"model-value":T.value,disabled:T.value&&!g.value,"aria-label":"anthropic","onUpdate:modelValue":ue[6]||(ue[6]=Ee=>de("anthropic"))},null,8,["model-value","disabled"]),ue[20]||(ue[20]=x("span",{class:"text-sm font-medium leading-none"},"anthropic",-1)),ue[21]||(ue[21]=x("span",{class:"text-xs text-muted-foreground"},"/messages",-1))])])]),g.value?(_(),W("div",oS,[x("label",rS,S(l(n)("sources.urlLabelOpenai")),1),v(l(Tt),{modelValue:w.value,"onUpdate:modelValue":ue[7]||(ue[7]=Ee=>w.value=Ee),placeholder:l(n)("sources.urlPhOpenai"),autocomplete:"off","aria-label":"openai base url"},null,8,["modelValue","placeholder"]),x("p",aS,S(l(n)("sources.urlHintOpenai")),1)])):pe("",!0),T.value?(_(),W("div",lS,[x("label",iS,S(l(n)("sources.urlLabelAnthropic")),1),v(l(Tt),{modelValue:k.value,"onUpdate:modelValue":ue[8]||(ue[8]=Ee=>k.value=Ee),placeholder:l(n)("sources.urlPhAnthropic"),autocomplete:"off","aria-label":"anthropic base url"},null,8,["modelValue","placeholder"]),x("p",uS,S(l(n)("sources.urlHintAnthropic")),1)])):pe("",!0),x("div",cS,[x("div",dS,[x("label",fS,S(l(n)("sources.keyLabel")),1),ye.apiKey?(_(),W("span",pS,S(l(n)("sources.currentKeyLabel"))+": "+S(ye.apiKey),1)):pe("",!0)]),v(l(Tt),{modelValue:E.value,"onUpdate:modelValue":ue[9]||(ue[9]=Ee=>E.value=Ee),type:"password",placeholder:l(n)("sources.keyPhEdit"),autocomplete:"new-password","aria-label":"api key"},null,8,["modelValue","placeholder"])]),x("div",mS,[x("label",hS,S(l(n)("sources.rpmLabel")),1),v(l(Tt),{modelValue:h.value,"onUpdate:modelValue":ue[10]||(ue[10]=Ee=>h.value=Ee),type:"number",min:"0",inputmode:"numeric",placeholder:l(n)("sources.rpmPh"),"aria-label":"rpm"},null,8,["modelValue","placeholder"]),x("p",vS,S(l(n)("sources.rpmHint")),1)]),x("div",gS,[v(l(Re),{variant:"ghost",size:"sm",onClick:J},{default:y(()=>[j(S(l(n)("sources.cancel")),1)]),_:1}),v(l(Re),{size:"sm",disabled:P.value,onClick:Ee=>te(ye)},{default:y(()=>[P.value?(_(),D(l(kt),{key:0,class:"h-4 w-4 animate-spin"})):pe("",!0),j(S(l(n)("sources.saveBtn")),1)]),_:1},8,["disabled","onClick"])])]))]))),128))])):pe("",!0)])]),_:1})]),_:1},8,["open"]),v(gu,{open:I.value,"onUpdate:open":ue[12]||(ue[12]=ye=>I.value=ye),variant:"destructive",title:l(n)("sources.remove"),description:C.value?l(n)("sources.confirmRemove",{name:C.value.name}):"","confirm-text":l(n)("sources.remove"),loading:R.value,onConfirm:$e},null,8,["open","title","description","confirm-text","loading"])],64))}}),zo=Q({__name:"Select",props:{open:{type:Boolean},defaultOpen:{type:Boolean},defaultValue:{},modelValue:{},nullableValue:{},by:{type:[String,Function]},dir:{},multiple:{type:Boolean},autocomplete:{},disabled:{type:Boolean},name:{},required:{type:Boolean}},emits:["update:modelValue","update:open"],setup(e,{emit:t}){const o=Rt(e,t);return(r,a)=>(_(),D(l(zx),Ot($t(l(o))),{default:y(()=>[ae(r.$slots,"default")]),_:3},16))}}),Go=Q({__name:"SelectTrigger",props:{disabled:{type:Boolean},reference:{},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},setup(e){const t=e,n=X(()=>{const{class:s,...o}=t;return o});return(s,o)=>(_(),D(l(xk),Ie(n.value,{class:l(Ye)("flex h-9 w-full items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-1 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",t.class)}),{default:y(()=>[ae(s.$slots,"default"),v(l(dk),{"as-child":""},{default:y(()=>[v(l(Xa),{class:"h-4 w-4 opacity-50"})]),_:1})]),_:3},16,["class"]))}}),Yo=Q({__name:"SelectValue",props:{placeholder:{},asChild:{type:Boolean},as:{}},setup(e){const t=e;return(n,s)=>(_(),D(l(Ck),Ot($t(t)),{default:y(()=>[ae(n.$slots,"default")]),_:3},16))}}),Xo=Q({__name:"SelectContent",props:{forceMount:{type:Boolean},position:{default:"popper"},bodyLock:{type:Boolean},memoDependencies:{},side:{},sideOffset:{},sideFlip:{type:Boolean},align:{},alignOffset:{},alignFlip:{type:Boolean},avoidCollisions:{type:Boolean},collisionBoundary:{},collisionPadding:{},arrowPadding:{},hideShiftedArrow:{type:Boolean},sticky:{},hideWhenDetached:{type:Boolean},positionStrategy:{},updatePositionStrategy:{},disableUpdateOnLayoutShift:{type:Boolean},prioritizePosition:{type:Boolean},reference:{},dir:{},asChild:{type:Boolean},as:{},disableOutsidePointerEvents:{type:Boolean},class:{type:[Boolean,null,String,Object,Array]}},emits:["closeAutoFocus","escapeKeyDown","pointerDownOutside"],setup(e,{emit:t}){const n=e,s=t,o=X(()=>{const{class:a,...i}=n;return i}),r=Rt(o,s);return(a,i)=>(_(),D(l(_k),null,{default:y(()=>[v(l(uk),Ie(l(r),{class:l(Ye)("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md",n.position==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:translate-x-1 data-[side=right]:-translate-x-1 data-[side=top]:-translate-y-1",n.class)}),{default:y(()=>[v(l(Ak),{class:Ce(l(Ye)("p-1",n.position==="popper"&&"w-full min-w-[var(--reka-select-trigger-width)]"))},{default:y(()=>[ae(a.$slots,"default")]),_:3},8,["class"])]),_:3},16,["class"])]),_:3}))}}),bS={class:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center"},ln=Q({__name:"SelectItem",props:{value:{},disabled:{type:Boolean},textValue:{},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},setup(e){const t=e,n=X(()=>{const{class:s,...o}=t;return o});return(s,o)=>(_(),D(l(mk),Ie(n.value,{class:l(Ye)("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t.class)}),{default:y(()=>[x("span",bS,[v(l(vk),null,{default:y(()=>[v(l(Pn),{class:"h-4 w-4"})]),_:1})]),v(l(yk),null,{default:y(()=>[ae(s.$slots,"default")]),_:3})]),_:3},16,["class"]))}}),_S={key:0,class:"mt-1.5 flex flex-wrap gap-1"},wS=["aria-label","onClick"],xS=["onMousedown"],kS={key:1,class:"h-3.5 w-3.5 shrink-0","aria-hidden":"true"},CS={class:"flex-1 truncate"},SS={key:0,class:"px-2 py-1 text-xs text-muted-foreground"},AS={key:1,class:"px-2 py-1 text-xs text-muted-foreground"},Rm=Q({__name:"Combobox",props:{modelValue:{},options:{},placeholder:{},limit:{default:300},multi:{type:Boolean}},emits:["update:modelValue"],setup(e,{emit:t}){const n=e,s=t,{t:o}=It(),r=N(null),a=N(!1),i=N(""),u=X(()=>Array.isArray(n.modelValue)?n.modelValue:[]),c=X(()=>{const b=(n.multi?i.value:String(n.modelValue??"")).trim().toLowerCase();return b?n.options.filter(P=>P.toLowerCase().includes(b)):n.options}),d=X(()=>c.value.slice(0,n.limit)),f=X(()=>c.value.length-d.value.length);function p(b){n.multi?(i.value=String(b),a.value=!0):(s("update:modelValue",String(b)),a.value=!0)}function m(b){if(n.multi){const P=u.value.includes(b)?u.value.filter(A=>A!==b):[...u.value,b];s("update:modelValue",P)}else s("update:modelValue",b),a.value=!1}function w(b){s("update:modelValue",u.value.filter(P=>P!==b))}function k(b){var A;const P=b.relatedTarget;P&&((A=r.value)!=null&&A.contains(P))||(a.value=!1)}const E=N(null),h=X(()=>Math.min(Math.max(d.value.length*34+8,48),224));function g(){var A;const b=(A=r.value)==null?void 0:A.getBoundingClientRect();if(!b)return;const P=b.bottom+6+h.value<=window.innerHeight;E.value={top:P?b.bottom+6:Math.max(b.top-6-h.value,8),left:Math.max(Math.min(b.left,window.innerWidth-b.width-8),8),width:b.width}}function T(){a.value&&g()}return Fe(a,async b=>{b?(await vt(),g(),window.addEventListener("scroll",T,!0),window.addEventListener("resize",T)):(window.removeEventListener("scroll",T,!0),window.removeEventListener("resize",T))}),Fe(h,()=>a.value&&g()),yr(()=>{window.removeEventListener("scroll",T,!0),window.removeEventListener("resize",T)}),(b,P)=>(_(),W("div",{ref_key:"rootRef",ref:r,class:"relative",onFocusin:P[0]||(P[0]=A=>a.value=!0),onFocusout:k},[v(l(Tt),{"model-value":e.multi?i.value:e.modelValue,placeholder:e.placeholder,autocomplete:"off",spellcheck:"false","onUpdate:modelValue":p},null,8,["model-value","placeholder"]),e.multi&&u.value.length?(_(),W("div",_S,[(_(!0),W(Se,null,tt(u.value,A=>(_(),W("span",{key:A,class:"inline-flex items-center gap-1 rounded-md border-transparent bg-primary text-primary-foreground shadow-sm px-2 py-0.5 font-mono text-xs"},[j(S(A)+" ",1),x("button",{type:"button",class:"opacity-70 hover:opacity-100","aria-label":l(o)("common.dismiss"),onClick:C=>w(A)},[v(l(Ja),{class:"h-3 w-3"})],8,wS)]))),128))])):pe("",!0),(_(),D(Pa,{to:"body"},[a.value&&(d.value.length||e.multi&&i.value.trim())?(_(),W("ul",{key:0,class:"fixed z-[60] max-h-56 overflow-auto rounded-md border bg-popover p-1 text-sm shadow-md",style:dn(E.value?{top:`${E.value.top}px`,left:`${E.value.left}px`,width:`${E.value.width}px`}:void 0)},[(_(!0),W(Se,null,tt(d.value,A=>(_(),W("li",{key:A},[x("button",{type:"button",class:Ce(["flex w-full items-center gap-2 rounded px-2 py-1.5 text-left font-mono hover:bg-accent hover:text-accent-foreground",A===e.modelValue||u.value.includes(A)?"text-primary":""]),onMousedown:Gt(C=>m(A),["prevent"])},[A===e.modelValue||u.value.includes(A)?(_(),D(l(Pn),{key:0,class:"h-3.5 w-3.5 shrink-0"})):(_(),W("span",kS)),x("span",CS,S(A),1)],42,xS)]))),128)),d.value.length?f.value>0?(_(),W("li",AS,S(l(o)("combobox.more",{n:f.value})),1)):pe("",!0):(_(),W("li",SS,S(l(o)("combobox.noMatch")),1))],4)):pe("",!0)]))],544))}}),ES={class:"flex shrink-0 items-center gap-2 pr-8"},OS={class:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-primary/15 text-primary"},TS={class:"min-w-0"},PS={class:"min-h-0 flex-1 space-y-3 overflow-y-auto px-1 py-1.5"},$S={class:"space-y-1.5"},IS={class:"text-xs font-medium text-muted-foreground"},MS={class:"text-xs text-muted-foreground"},RS={class:"font-medium text-foreground"},LS={key:0,class:"space-y-3 rounded-lg border bg-muted/30 p-4"},DS={class:"text-xs text-muted-foreground"},FS={key:1,class:"space-y-1.5"},NS={class:"flex items-center justify-between gap-2"},qS={class:"text-xs font-medium text-muted-foreground"},BS={key:0,class:"text-xs text-muted-foreground"},VS={key:0,class:"text-xs text-muted-foreground"},US={class:"space-y-1.5"},HS={class:"text-xs font-medium text-muted-foreground"},jS=["placeholder"],WS={key:0,class:"text-xs text-muted-foreground"},KS={class:"flex shrink-0 justify-end gap-2"},Pl="__new__",bd="__none__",zS=Q({__name:"AddModelsDialog",props:ys({providers:{}},{open:{type:Boolean,default:!1},openModifiers:{}}),emits:ys(["changed"],["update:open"]),setup(e,{emit:t}){const{t:n}=It(),s=e,o=_r(e,"open"),r=t,a=N(""),i=N(""),u=N(!1),c=N(null),d=N([]),f=N([]);Fe(o,P=>{var A;P&&(a.value=s.providers.length?s.providers[0].id:Pl,i.value="",d.value=[],f.value=[],(A=c.value)==null||A.reset())}),Fe(a,()=>{d.value=[]});const p=X(()=>a.value===Pl),m=X(()=>a.value===bd);function w(P){const A=[...P.formats];return P.supportsResponses&&!A.includes("responses")&&A.push("responses"),A}const k=X(()=>{var A,C;if(p.value||m.value)return w({formats:((A=c.value)==null?void 0:A.payload.formats)??[],supportsResponses:(C=c.value)==null?void 0:C.payload.supportsResponses});const P=s.providers.find(I=>I.id===a.value);return P?w(P):[]}),E=X(()=>{const P=new Set,A=[];for(const C of i.value.split(/[\s,;]+/)){const I=C.trim();I&&!P.has(I)&&(P.add(I),A.push(I))}return A}),h=X(()=>{const P=new Set,A=[];for(const C of[...E.value,...d.value])P.has(C)||(P.add(C),A.push(C));return A}),g=X(()=>{if(m.value)return[];const P=s.providers.find(A=>A.id===a.value);return P?P.discoveredModels??[]:f.value}),T=X(()=>!!a.value&&h.value.length>0&&k.value.length>0&&!u.value);async function b(){var P,A,C;if(T.value&&!(p.value&&!((P=c.value)!=null&&P.validate()))){u.value=!0;try{let I=a.value,R=[],z=!1;if(p.value){const J=await Ue("POST","/admin/providers",c.value.payload);I=J.provider.id,a.value=I,f.value=J.discovered??J.provider.discoveredModels??[],R=w(J.provider),z=!0,Le(n("sources.added"),"success")}else if(m.value)R=w({formats:((A=c.value)==null?void 0:A.payload.formats)??[],supportsResponses:(C=c.value)==null?void 0:C.payload.supportsResponses});else{const J=s.providers.find(te=>te.id===I);R=J?w(J):[]}const de=[];for(const J of h.value)for(const te of R)de.push({name:J,slot:te});const Z=await Promise.allSettled(de.map(J=>Ue("POST","/admin/models",{name:J.name,format:J.slot,providers:m.value?[]:[I]}))),ie=new Set;let ke=0;if(Z.forEach((J,te)=>{J.status==="fulfilled"?ie.add(de[te].name):ke++}),ie.size&&Le(n("models.addedToast",{n:ie.size}),"success"),(z||ie.size)&&r("changed"),ke){const J=h.value.filter(te=>!ie.has(te));Le(n("models.addModelsFailed",{n:J.length}),"error"),i.value=J.join(`
283
+ `),d.value=[]}else o.value=!1}finally{u.value=!1}}}return(P,A)=>(_(),D(l(Qa),{open:o.value,"onUpdate:open":A[4]||(A[4]=C=>o.value=C)},{default:y(()=>[v(l(Za),{class:Ce(p.value?"max-w-lg":"max-w-md")},{default:y(()=>[x("div",ES,[x("span",OS,[v(l(es),{class:"h-4 w-4"})]),x("div",TS,[v(l(el),{class:"text-base"},{default:y(()=>[j(S(l(n)("models.addModels")),1)]),_:1}),v(l(tl),null,{default:y(()=>[j(S(l(n)("models.addModelsDesc")),1)]),_:1})])]),x("div",PS,[x("div",$S,[x("label",IS,S(l(n)("models.providerLabel")),1),v(l(zo),{modelValue:a.value,"onUpdate:modelValue":A[0]||(A[0]=C=>a.value=C)},{default:y(()=>[v(l(Go),null,{default:y(()=>[v(l(Yo),{placeholder:l(n)("models.providerPh")},null,8,["placeholder"])]),_:1}),v(l(Xo),null,{default:y(()=>[v(l(ln),{value:Pl},{default:y(()=>[j(S(l(n)("models.newSourceOpt")),1)]),_:1}),v(l(ln),{value:bd},{default:y(()=>[j(S(l(n)("models.noneSourceOpt")),1)]),_:1}),(_(!0),W(Se,null,tt(e.providers,C=>(_(),D(l(ln),{key:C.id,value:C.id},{default:y(()=>[j(S(C.name),1)]),_:2},1032,["value"]))),128))]),_:1})]),_:1},8,["modelValue"]),x("p",MS,[j(S(l(n)("models.addModelsSlotsHint"))+" ",1),x("span",RS,S(k.value.join(" / ")||"—"),1)])]),p.value||m.value?(_(),W("div",LS,[x("p",DS,S(p.value?l(n)("models.addModelsNewHint"):l(n)("models.addModelsNoneHint")),1),v(yu,{ref_key:"newForm",ref:c,"formats-only":m.value},null,8,["formats-only"])])):pe("",!0),!p.value&&!m.value?(_(),W("div",FS,[x("div",NS,[x("label",qS,S(l(n)("models.addModelsDiscoveredLabel")),1),g.value.length?(_(),W("span",BS,S(l(n)("models.addModelsDiscoveredHint")),1)):pe("",!0)]),g.value.length?(_(),D(Rm,{key:1,modelValue:d.value,"onUpdate:modelValue":A[1]||(A[1]=C=>d.value=C),multi:"",options:g.value,placeholder:l(n)("models.searchPh")},null,8,["modelValue","options","placeholder"])):(_(),W("p",VS,S(l(n)("models.addModelsDiscoveredEmpty")),1))])):pe("",!0),x("div",US,[x("label",HS,S(l(n)("models.namesLabel")),1),yo(x("textarea",{"onUpdate:modelValue":A[2]||(A[2]=C=>i.value=C),placeholder:l(n)("models.addModelsNamesPh"),rows:"6",spellcheck:"false",class:"flex w-full resize-y rounded-md border border-input bg-transparent px-3 py-2 font-mono text-sm shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50"},null,8,jS),[[$g,i.value]]),h.value.length?(_(),W("p",WS,S(l(n)("models.addModelsCount",{n:h.value.length})),1)):pe("",!0)])]),x("div",KS,[v(l(Re),{variant:"outline",disabled:u.value,onClick:A[3]||(A[3]=C=>o.value=!1)},{default:y(()=>[j(S(l(n)("common.cancel")),1)]),_:1},8,["disabled"]),v(l(Re),{disabled:!T.value,onClick:b},{default:y(()=>[u.value?(_(),D(l(kt),{key:0,class:"h-4 w-4 animate-spin"})):(_(),D(l(es),{key:1,class:"h-4 w-4"})),j(" "+S(l(n)("models.addModelsBtn")),1)]),_:1},8,["disabled"])])]),_:1},8,["class"])]),_:1},8,["open"]))}}),GS={class:"flex shrink-0 items-center gap-2 pr-8"},YS={class:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-primary/15 text-primary"},XS={class:"min-w-0"},JS={class:"min-h-0 flex-1 space-y-3 overflow-y-auto px-1 py-1.5"},QS={class:"space-y-1.5"},ZS={class:"text-xs font-medium text-muted-foreground"},eA={key:0,class:"text-xs text-muted-foreground"},tA={key:1,class:"text-xs text-muted-foreground"},nA={class:"font-medium text-foreground"},sA={key:2,class:"text-xs text-amber-600 dark:text-amber-500"},oA={key:0,class:"space-y-3 rounded-lg border bg-muted/30 p-4"},rA={class:"text-xs text-muted-foreground"},aA={class:"space-y-1.5"},lA={class:"text-xs font-medium text-muted-foreground"},iA={class:"text-xs text-muted-foreground"},uA={class:"flex shrink-0 justify-end gap-2"},$l="__new__",cA=Q({__name:"AddSourceDialog",props:ys({modelName:{},providers:{},enabledFormats:{},chainByFormat:{}},{open:{type:Boolean,default:!1},openModifiers:{}}),emits:ys(["added"],["update:open"]),setup(e,{emit:t}){const{t:n}=It(),s=e,o=_r(e,"open"),r=t,a=encodeURIComponent,i=N(""),u=N(""),c=N(!1),d=N(null),f=N(null);function p(I,R){return R==="responses"?!!I.supportsResponses:I.formats.includes(R)}const m=X(()=>{var I,R;return h.value?((I=d.value)==null?void 0:I.payload)??null:s.providers.find(z=>z.id===i.value)??(((R=f.value)==null?void 0:R.id)===i.value?f.value:null)});function w(I){const R=s.providers.find(z=>z.id===I);return R?s.enabledFormats.filter(z=>p(R,z)):[]}function k(I){return s.enabledFormats.filter(R=>(s.chainByFormat[R]??[]).includes(I))}const E=X(()=>s.providers.filter(I=>s.enabledFormats.some(R=>p(I,R))).sort((I,R)=>I.name.localeCompare(R.name))),h=X(()=>i.value===$l),g=X(()=>{var I,R;return h.value?((I=f.value)==null?void 0:I.discoveredModels)??[]:((R=s.providers.find(z=>z.id===i.value))==null?void 0:R.discoveredModels)??[]}),T={openai:"models.fmtOpenaiShort",anthropic:"models.fmtAnthropicShort",responses:"models.fmtResponsesShort"},b=X(()=>{if(!i.value)return[];if(h.value){const I=m.value;return I?s.enabledFormats.filter(R=>p(I,R)).map(R=>n(T[R]??R)):[]}return w(i.value).map(I=>n(T[I]??I))}),P=X(()=>!!i.value&&!h.value&&k(i.value).length>0),A=X(()=>!!i.value&&!c.value);Fe(o,I=>{var R,z;I&&(i.value=((R=E.value[0])==null?void 0:R.id)??$l,u.value="",f.value=null,(z=d.value)==null||z.reset())});async function C(){var I;if(A.value&&!(h.value&&!((I=d.value)!=null&&I.validate()))){c.value=!0;try{let R=i.value,z=!1;if(h.value){const te=await Ue("POST","/admin/providers",d.value.payload);R=te.provider.id,i.value=R,f.value={...te.provider,discoveredModels:te.discovered??te.provider.discoveredModels??[]},z=!0,Le(n("sources.added"),"success")}const de=f.value&&f.value.id===R?f.value:s.providers.find(te=>te.id===R),Z=de?s.enabledFormats.filter(te=>p(de,te)):[],ie=u.value.trim();(await Promise.allSettled(Z.map(te=>Ue("POST",`/admin/models/${a(s.modelName)}/providers`,{format:te,providerId:R,model:ie||void 0})))).filter(te=>te.status==="rejected").length?(Le(n("models.addSourcePartial"),"error"),z&&r("added")):(Le(n("models.sourceAdded"),"success"),r("added"),o.value=!1)}finally{c.value=!1}}}return(I,R)=>(_(),D(l(Qa),{open:o.value,"onUpdate:open":R[3]||(R[3]=z=>o.value=z)},{default:y(()=>[v(l(Za),{class:Ce(h.value?"max-w-lg":"max-w-md")},{default:y(()=>[x("div",GS,[x("span",YS,[v(l(es),{class:"h-4 w-4"})]),x("div",XS,[v(l(el),{class:"text-base"},{default:y(()=>[j(S(l(n)("models.addSourceTitle")),1)]),_:1}),v(l(tl),null,{default:y(()=>[j(S(l(n)("models.addSourceDesc")),1)]),_:1})])]),x("div",JS,[x("div",QS,[x("label",ZS,S(l(n)("models.providerLabel")),1),v(l(zo),{modelValue:i.value,"onUpdate:modelValue":R[0]||(R[0]=z=>i.value=z)},{default:y(()=>[v(l(Go),null,{default:y(()=>[v(l(Yo),{placeholder:l(n)("models.providerPh")},null,8,["placeholder"])]),_:1}),v(l(Xo),null,{default:y(()=>[v(l(ln),{value:$l},{default:y(()=>[j(S(l(n)("models.newSourceOpt")),1)]),_:1}),(_(!0),W(Se,null,tt(E.value,z=>(_(),D(l(ln),{key:z.id,value:z.id},{default:y(()=>[j(S(z.name),1)]),_:2},1032,["value"]))),128))]),_:1})]),_:1},8,["modelValue"]),E.value.length?pe("",!0):(_(),W("p",eA,S(l(n)("models.addSourceNone")),1)),b.value.length?(_(),W("p",tA,[j(S(l(n)("models.addSourceTargetsHint"))+" ",1),x("span",nA,S(b.value.join(" / ")),1)])):pe("",!0),P.value?(_(),W("p",sA,S(l(n)("models.addSourceDupHint")),1)):pe("",!0)]),h.value?(_(),W("div",oA,[x("p",rA,S(l(n)("models.addSourceNewHint")),1),v(yu,{ref_key:"newForm",ref:d},null,512)])):pe("",!0),x("div",aA,[x("label",lA,S(l(n)("models.upstreamLabel")),1),v(Rm,{modelValue:u.value,"onUpdate:modelValue":R[1]||(R[1]=z=>u.value=z),options:g.value,placeholder:l(n)("models.upstreamPh")},null,8,["modelValue","options","placeholder"]),x("p",iA,S(l(n)("models.upstreamHint")),1)])]),x("div",uA,[v(l(Re),{variant:"outline",disabled:c.value,onClick:R[2]||(R[2]=z=>o.value=!1)},{default:y(()=>[j(S(l(n)("common.cancel")),1)]),_:1},8,["disabled"]),v(l(Re),{disabled:!A.value,onClick:C},{default:y(()=>[c.value?(_(),D(l(kt),{key:0,class:"h-4 w-4 animate-spin"})):(_(),D(l(es),{key:1,class:"h-4 w-4"})),j(" "+S(l(n)("models.addToChain")),1)]),_:1},8,["disabled"])])]),_:1},8,["class"])]),_:1},8,["open"]))}}),dA={class:"space-y-4"},fA={class:"flex h-11 w-11 items-center justify-center rounded-xl bg-primary/15 text-primary"},pA={class:"space-y-1"},mA={class:"font-medium"},hA={class:"max-w-sm text-sm text-muted-foreground"},vA={class:"flex flex-wrap items-center gap-2"},gA={class:"relative min-w-[180px] flex-1"},yA={class:"text-xs text-muted-foreground"},bA={key:0,class:"py-6 text-center text-sm text-muted-foreground"},_A={key:1,class:"py-6 text-center text-sm text-destructive"},wA={key:0,class:"relative overflow-hidden rounded-lg border border-border/60 bg-card"},xA={class:"flex items-center gap-2.5 border-b border-border/60 bg-muted/30 px-3 py-2"},kA={class:"text-sm font-semibold"},CA={class:"ml-auto inline-flex items-center rounded-md bg-primary/15 px-1.5 py-0.5 text-xs font-medium tabular-nums text-primary"},SA={class:"divide-y divide-border"},AA={class:"flex items-center gap-3"},EA=["aria-expanded","aria-label","onClick","onKeydown"],OA={class:"flex min-w-0 flex-1 flex-col items-start"},TA={class:"flex w-full items-center gap-1.5"},PA={class:"truncate font-mono text-sm font-medium"},$A=["title","aria-label","onClick"],IA={class:"w-full truncate text-xs text-muted-foreground"},MA={class:"flex shrink-0 items-center gap-1.5"},RA=["disabled","title","aria-label","onClick"],LA={key:0,class:"mt-2 space-y-3 rounded-md border bg-muted/30 p-2"},DA={class:"flex items-center gap-2 px-1"},FA={class:"text-xs font-semibold"},NA={class:"font-mono text-[11px] text-muted-foreground"},qA={key:0,class:"flex items-start gap-2 rounded bg-muted px-2 py-1.5 text-xs text-muted-foreground"},BA={class:"shrink-0 font-medium"},VA={key:1,class:"px-1 py-1 text-xs text-muted-foreground"},UA={class:"w-4 shrink-0 text-right text-xs text-muted-foreground"},HA={class:"flex items-center gap-1.5 text-sm"},jA={key:2,class:"flex items-center gap-1"},WA=["value","placeholder","aria-label","title","onKeyup","onBlur"],KA=["title","onClick"],zA={key:7,class:"flex items-center gap-1"},GA=["value","placeholder","aria-label","title","onInput","onKeyup","onBlur"],YA=["title","onClick"],XA={class:"ml-auto flex items-center gap-0.5 opacity-0 transition-opacity focus-within:opacity-100 group-hover:opacity-100"},JA={key:0,class:"flex justify-center pt-1"},QA={class:"relative overflow-hidden rounded-lg border border-border/60 bg-card"},ZA={class:"flex items-center gap-2.5 border-b border-border/60 bg-muted/30 px-3 py-2"},eE={class:"text-sm font-semibold"},tE={class:"ml-auto inline-flex items-center rounded-md bg-muted px-1.5 py-0.5 text-xs font-medium tabular-nums text-muted-foreground"},nE={key:0},sE={key:0,class:"py-3 text-center text-xs text-muted-foreground"},oE={key:1,class:"divide-y divide-border"},rE=["aria-expanded","aria-label","onClick"],aE={class:"text-sm font-medium"},lE={class:"inline-flex items-center rounded-md bg-muted px-1.5 py-0.5 text-xs font-medium tabular-nums text-muted-foreground"},iE={key:0,class:"divide-y divide-border/50 bg-muted/10"},uE={class:"flex min-w-0 items-center gap-1.5"},cE={class:"truncate font-mono text-sm"},dE=["title","aria-label","onClick"],fE={class:"flex shrink-0 items-center gap-1.5"},pE=["disabled","title","aria-label","onClick"],mE=8,hE=Q({__name:"Models",setup(e){const{t}=It(),n=["openai","anthropic","responses"],s=N([]),o=N([]),r=N(""),a=N(!1),i=N(""),u=N(!0),c=N(new Set),d=N(!1),f=N(!1),p=N(!1),m=N(!1),w=N({}),k=N({}),E=N({}),h=N({}),g=N({}),T=N({}),b=N({}),P=N({}),A=N(""),C=N(null),I=N(!1),R={mounted:B=>B.focus()},z=N(null),de=N(!1),Z=encodeURIComponent;async function ie(){a.value=!0,r.value="";try{const[B,q]=await Promise.all([Ue("GET","/admin/models"),Ue("GET","/admin/providers")]);s.value=B.models,o.value=q.providers}catch(B){r.value=B.message}finally{a.value=!1}}const ke=X(()=>new Map(o.value.map(B=>[B.id,B]))),J=X(()=>{const B=new Map;for(const q of o.value)for(const ne of q.discoveredModels??[]){const F=B.get(ne);F?F.push(q.id):B.set(ne,[q.id])}return B}),te=X(()=>{const B=new Set;for(const ne of o.value)for(const F of ne.discoveredModels??[])B.add(F);for(const ne of s.value)B.add(ne.name);const q=ne=>({enabled:(ne==null?void 0:ne.enabled)??!1,chain:((ne==null?void 0:ne.providers)??[]).map(F=>({id:F.id,name:F.name,model:F.model}))});return[...B].map(ne=>{const F=s.value.find(Ae=>Ae.name===ne),_e=(J.value.get(ne)??[]).map(Ae=>ke.value.get(Ae)).filter(Ae=>!!Ae).map(Ae=>({id:Ae.id,name:Ae.name,formats:Ae.formats,supportsResponses:Ae.supportsResponses}));return{name:ne,openai:q(F==null?void 0:F.openai),anthropic:q(F==null?void 0:F.anthropic),responses:q(F==null?void 0:F.responses),offering:_e}})});function ce(B){return n.filter(q=>B[q].enabled)}function ge(B){return n.filter(q=>B.offering.some(ne=>oe(ne,q)))}function $e(B){return ge(B).filter(q=>!B[q].enabled)}function K(B,q){return B[q].enabled?"enabled":ge(B).includes(q)?"enableable":"unsupported"}function he(B,q){return B.offering.filter(ne=>oe(ne,q)).map(ne=>ne.id)}const ee=X(()=>{const B=i.value.trim().toLowerCase();return te.value.filter(q=>!B||q.name.toLowerCase().includes(B))}),lt=X(()=>ee.value.filter(B=>B.openai.enabled||B.anthropic.enabled||B.responses.enabled)),fe=X(()=>ee.value.filter(B=>!(B.openai.enabled||B.anthropic.enabled||B.responses.enabled)&&ge(B).length>0)),ue=["embed","whisper","tts","dall-e","dall_e","image","moderation","audio","transcribe","rerank","realtime","sora"];function ye(B){const q=B.toLowerCase();return ue.some(ne=>q.includes(ne))}const Ee=N(!0),st=X(()=>fe.value.filter(B=>ye(B.name)).length),qe=X(()=>Ee.value?fe.value.filter(B=>!ye(B.name)):fe.value),ft=X(()=>{const B=[];for(const q of o.value){const ne=qe.value.filter(F=>F.offering.some(_e=>_e.id===q.id)).sort((F,_e)=>F.name.localeCompare(_e.name));ne.length&&B.push({source:q,rows:ne})}return B}),St=N({});function M(B,q){return i.value.trim()?!0:B in St.value?St.value[B]:q<=mE}function L(B,q){i.value.trim()||(St.value={...St.value,[B]:!M(B,q)})}function G(B){const q=ce(B);return o.value.filter(ne=>q.some(F=>oe(ne,F)))}function le(B){const q={};for(const ne of n)q[ne]=B[ne].chain.map(F=>F.id);return q}function oe(B,q){return q==="responses"?!!B.supportsResponses:B.formats.includes(q)}const se={openai:{key:"models.fmtOpenai",chip:"models.fmtOpenaiShort",endpoint:"/chat/completions"},anthropic:{key:"models.fmtAnthropic",chip:"models.fmtAnthropicShort",endpoint:"/messages"},responses:{key:"models.fmtResponses",chip:"models.fmtResponsesShort",endpoint:"/responses"}};function O(B){return c.value.has(B)}function $(B){const q=new Set(c.value);q.has(B)?q.delete(B):q.add(B),c.value=q}async function V(B){const q=await Xi(B);Le(t(q?"connect.copied":"connect.copyFailed"),q?"success":"error")}function H(B,q){B.target===B.currentTarget&&(B.key==="Enter"||B.key===" ")&&(B.preventDefault(),$(q))}function me(B){return B.length?B.map(q=>q.name).join(" → "):t("models.noSourcesShort")}function re(B){return ce(B).map(q=>`${t(se[q].chip)}: ${me(B[q].chain)}`).join(" · ")}function U(B,q){const ne=B[q].chain;if(!ne.length)return!1;const F=_e=>{var Ae;return((Ae=ke.value.get(_e))==null?void 0:Ae.discoveredModels)??[]};return!ne.some(_e=>F(_e.id).includes(_e.model??B.name))&&ne.some(_e=>F(_e.id).length>0)}function Y(B){return ce(B).some(q=>U(B,q))}function ve(B){let q=!1,ne=null,F=null;for(const _e of ce(B)){const Ae=`${B.name}:${_e}`;h.value[Ae]&&(q=!0);const ot=b.value[Ae];ot!=null&&ot.ok&&!ne?ne=ot:ot&&!ot.ok&&!F&&(F=ot)}return q?{state:"testing"}:ne?{state:"ok",provider:ne.provider}:F?{state:"fail",status:F.status,error:F.error}:null}function Te(B,q){const ne=K(B,q);return ne==="enabled"?`border-transparent ${tn[q].solid} text-white shadow-sm`:ne==="enableable"?"border-dashed border-input text-muted-foreground hover:bg-accent hover:text-accent-foreground":"border-transparent text-muted-foreground/40"}function De(B,q){const ne=K(B,q);return ne==="enabled"?`${t(se[q].key)} · ${t("models.chipOn")}`:ne==="enableable"?`${t(se[q].key)} · ${t("models.chipOff")}`:`${t(se[q].key)} · ${t("models.chipNa")}`}async function Xe(B,q){B[q].enabled?await Zt(B,q):await je(B,q)}async function je(B,q){const ne=`${B.name}:${q}`;k.value[ne]=!0;const F=B.offering.filter(ot=>oe(ot,q)),_e=F.map(ot=>({id:ot.id,name:ot.name})),Ae=s.value.find(ot=>ot.name===B.name);if(Ae){Ae[q].enabled=!0;for(const ot of _e)Ae[q].providers.find($s=>$s.id===ot.id)||Ae[q].providers.push(ot)}else s.value.push({name:B.name,openai:{enabled:q==="openai",providers:q==="openai"?_e:[]},anthropic:{enabled:q==="anthropic",providers:q==="anthropic"?_e:[]},responses:{enabled:q==="responses",providers:q==="responses"?_e:[]}});try{await Ue("POST","/admin/models",{name:B.name,format:q,providers:F.map(ot=>ot.id)}),Le(t("models.enabledToast",{name:`${B.name} [${q}]`}),"success")}catch(ot){await ie(),Le(ot.message,"error")}finally{k.value[ne]=!1}}async function Kt(){if(f.value)return;f.value=!0;const B=[];for(const F of qe.value)for(const _e of $e(F))B.push({name:F.name,fmt:_e,providers:he(F,_e)});for(const F of B)k.value[`${F.name}:${F.fmt}`]=!0;const q=await Promise.allSettled(B.map(F=>Ue("POST","/admin/models",{name:F.name,format:F.fmt,providers:F.providers})));for(const F of B)k.value[`${F.name}:${F.fmt}`]=!1;if(await ie(),f.value=!1,!B.length)return;const ne=q.filter(F=>F.status==="rejected").length;ne?ne===B.length?Le(t("models.enableAllFailed"),"error"):Le(t("models.enableAllPartial",{failed:ne}),"error"):Le(t("models.enableAllDone"),"success")}async function Zt(B,q){const ne=s.value.find(F=>F.name===B.name);ne&&(ne[q].enabled=!1);try{await Ue("POST",`/admin/models/${Z(B.name)}/disable`,{format:q}),Le(t("models.disabledToast",{name:`${B.name} [${q}]`}),"success")}catch(F){await ie(),Le(F.message,"error")}}function Ts(B){z.value=B,de.value=!0}async function Ar(B,q){const ne=`${B.name}:${q}`;if(!h.value[ne]){h.value[ne]=!0;try{const F=await Ue("POST",`/admin/models/${Z(B.name)}/test?format=${q}`);b.value[ne]=F.result}catch(F){b.value[ne]={ok:!1,status:0,format:q,error:F.message}}finally{h.value[ne]=!1}}}async function Bt(B){const q=ce(B);q.length&&await Promise.all(q.map(ne=>Ar(B,ne)))}async function rn(B,q,ne){const F=`${B.name}:${q}:${ne}`;if(!g.value[F]){g.value[F]=!0;try{const _e=await Ue("POST",`/admin/models/${Z(B.name)}/providers/test?format=${q}&index=${ne}`);T.value[F]=_e.result}catch(_e){T.value[F]={ok:!1,status:0,format:q,error:_e.message}}finally{g.value[F]=!1}}}async function Er(){const B=z.value;if(B){w.value[B.name]=!0;try{await Ue("DELETE",`/admin/models/${Z(B.name)}`),s.value=s.value.filter(q=>q.name!==B.name),Le(t("models.removedToast",{name:B.name}),"success"),de.value=!1}catch(q){Le(q.message,"error")}finally{w.value[B.name]=!1}}}async function Ao(B,q,ne){const F=s.value.find(Ae=>Ae.name===B.name);if(!F)return;const _e=F[ne].providers.slice();F[ne].providers=q.map(Ae=>_e[Ae]);try{await Ue("PUT",`/admin/models/${Z(B.name)}/priority`,{format:ne,order:q})}catch(Ae){F[ne].providers=_e,Le(Ae.message,"error")}}function Nm(B,q,ne){if(q===0)return;const F=B[ne].chain.map((_e,Ae)=>Ae);[F[q-1],F[q]]=[F[q],F[q-1]],Ao(B,F,ne)}function qm(B,q,ne){if(q>=B[ne].chain.length-1)return;const F=B[ne].chain.map((_e,Ae)=>Ae);[F[q+1],F[q]]=[F[q],F[q+1]],Ao(B,F,ne)}function Bm(B){C.value=B,I.value=!0}function Js(B,q,ne){return`${B.name}:${q}:${ne}`}function Vm(B,q,ne){return A.value===Js(B,q,ne)}function bu(B,q,ne,F){const _e=Js(B,q,F);P.value[_e]=ne.model??"",A.value=_e}function Um(B,q,ne){return P.value[Js(B,q,ne)]??""}function Hm(B,q,ne,F){P.value[Js(B,q,ne)]=F}async function jm(B,q,ne,F){const _e=Js(B,q,F);A.value="";const Ae=(P.value[_e]??"").trim(),ot=(ne.model??"").trim();if(Ae===ot)return;const $s=s.value.find(Qs=>Qs.name===B.name);$s&&($s[q].providers[F].model=Ae||void 0),P.value[_e]=Ae;try{await Ue("PUT",`/admin/models/${Z(B.name)}/map`,{format:q,index:F,model:Ae}),Le(t("models.mapSaved"),"success")}catch(Qs){await ie(),Le(Qs.message,"error")}}function Wm(B,q,ne,F,_e){P.value[Js(B,q,F)]=ne.model??"",_e.blur()}const nl=N(""),Eo=N("");function Ps(B){var q;return((q=ke.value.get(B))==null?void 0:q.rpm)??0}function Km(B){return nl.value===B.id}function _u(B){nl.value=B.id,Eo.value=Ps(B.id)?String(Ps(B.id)):""}function zm(B){Eo.value=B}async function Gm(B,q){const ne=ke.value.get(B);ne&&await Ue("PUT",`/admin/providers/${B}`,{name:ne.name,baseUrlOpenai:ne.baseUrlOpenai,baseUrlAnthropic:ne.baseUrlAnthropic,formats:ne.formats,supportsResponses:ne.supportsResponses??!1,rpm:q})}async function Ym(B){const q=B.id;nl.value="";const ne=Number(Eo.value),F=Number.isFinite(ne)&&ne>0?Math.floor(ne):0;if(F!==Ps(q))try{await Gm(q,F),o.value=o.value.map(_e=>_e.id===q?{..._e,rpm:F}:_e),Le(F?t("sources.rpmSaved",{n:F}):t("sources.rpmCleared"),F?"success":"default")}catch(_e){Le(_e.message,"error")}}function Xm(B,q){Eo.value=Ps(B.id)?String(Ps(B.id)):"",q.blur()}async function Jm(B,q,ne){const F=`${B.name}:${q}:${ne}`;if(E.value[F])return;E.value[F]=!0;const _e=s.value.find(Ae=>Ae.name===B.name);_e&&_e[q].providers.splice(ne,1);try{await Ue("DELETE",`/admin/models/${Z(B.name)}/providers?format=${q}&index=${ne}`),Le(t("models.sourceRemoved"),"success")}catch(Ae){await ie(),Le(Ae.message,"error")}finally{E.value[F]=!1}}async function Qm(){if(d.value||!o.value.length)return;d.value=!0;const B=o.value,q=await Promise.allSettled(B.map(F=>Ue("POST",`/admin/providers/${F.id}/discover`)));await ie();const ne=q.map((F,_e)=>F.status==="rejected"?B[_e].name:null).filter(F=>!!F);ne.length?ne.length===B.length?Le(t("sources.refreshAllFailed"),"error"):Le(t("sources.refreshAllPartial",{failed:ne.join("、")}),"error"):Le(t("sources.refreshAllDone"),"success"),d.value=!1}return dt(ie),(B,q)=>{var ne;return _(),W("div",dA,[!a.value&&!o.value.length?(_(),D(l(hn),{key:0},{default:y(()=>[v(l(vn),{class:"flex flex-col items-center gap-3 py-12 text-center"},{default:y(()=>[x("span",fA,[v(l(wi),{class:"h-5 w-5"})]),x("div",pA,[x("div",mA,S(l(t)("models.empty")),1),x("p",hA,S(l(t)("models.emptyHint")),1)]),v(l(Re),{onClick:q[0]||(q[0]=F=>p.value=!0)},{default:y(()=>[v(l(es),{class:"h-4 w-4"}),j(S(l(t)("models.addSource")),1)]),_:1})]),_:1})]),_:1})):(_(),D(l(hn),{key:1},{default:y(()=>[v(l(Mn),null,{default:y(()=>[v(l(Rn),{class:"flex items-center gap-2 text-base"},{default:y(()=>[v(l(Em),{class:"h-4 w-4 text-primary"}),j(" "+S(l(t)("models.title")),1)]),_:1}),v(l(gs),null,{default:y(()=>[j(S(l(t)("models.desc")),1)]),_:1})]),_:1}),v(l(vn),{class:"space-y-4"},{default:y(()=>[x("div",vA,[x("div",gA,[v(l(Im),{class:"absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),v(l(Tt),{modelValue:i.value,"onUpdate:modelValue":q[1]||(q[1]=F=>i.value=F),placeholder:l(t)("models.searchPh"),class:"pl-8"},null,8,["modelValue","placeholder"])]),v(l(Re),{size:"sm",onClick:q[2]||(q[2]=F=>m.value=!0)},{default:y(()=>[v(l(es),{class:"h-4 w-4"}),j(S(l(t)("models.addModels")),1)]),_:1}),v(l(Re),{variant:"outline",size:"sm",onClick:q[3]||(q[3]=F=>p.value=!0)},{default:y(()=>[v(l(wi),{class:"h-4 w-4"}),j(S(l(t)("models.manageSources")),1)]),_:1})]),x("p",yA,S(l(t)("models.chipLegend")),1),a.value?(_(),W("p",bA,S(l(t)("common.loading")),1)):r.value?(_(),W("p",_A,S(r.value),1)):(_(),W(Se,{key:2},[lt.value.length?(_(),W("section",wA,[q[16]||(q[16]=x("div",{class:"pointer-events-none absolute inset-y-0 left-0 w-1 bg-primary","aria-hidden":"true"},null,-1)),x("div",xA,[q[13]||(q[13]=x("span",{class:"h-2 w-2 shrink-0 rounded-full bg-primary"},null,-1)),x("span",kA,S(l(t)("models.enabledSection")),1),x("span",CA,S(lt.value.length),1)]),x("div",SA,[(_(!0),W(Se,null,tt(lt.value,F=>{var _e,Ae,ot,$s,Qs;return _(),W("div",{key:F.name,class:"px-3 py-2.5"},[x("div",AA,[x("div",{role:"button",tabindex:"0",class:"flex min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-md text-left outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background","aria-expanded":O(F.name),"aria-label":O(F.name)?l(t)("models.collapseAria"):l(t)("models.expandAria"),onClick:Pe=>$(F.name),onKeydown:Pe=>H(Pe,F.name)},[v(l(bi),{class:Ce(["h-4 w-4 shrink-0 text-muted-foreground transition-transform",{"rotate-90":O(F.name)}])},null,8,["class"]),x("span",OA,[x("span",TA,[x("span",PA,S(F.name),1),x("button",{type:"button",title:l(t)("connect.copy"),"aria-label":l(t)("connect.copy"),class:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground/50 transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:Gt(Pe=>V(F.name),["stop"])},[v(l(Xn),{class:"h-3 w-3"})],8,$A),((_e=ve(F))==null?void 0:_e.state)==="testing"?(_(),D(l(yt),{key:0,variant:"muted",class:"gap-1"},{default:y(()=>[v(l(kt),{class:"h-3 w-3 animate-spin"}),j(S(l(t)("models.probeTesting")),1)]),_:1})):((Ae=ve(F))==null?void 0:Ae.state)==="ok"?(_(),D(l(yt),{key:1,variant:"success",title:l(t)("models.probeOkHint",{name:((ot=ve(F))==null?void 0:ot.provider)??""})},{default:y(()=>[j(S(l(t)("models.probeOk")),1)]),_:1},8,["title"])):(($s=ve(F))==null?void 0:$s.state)==="fail"?(_(),D(l(yt),{key:2,variant:"destructive",title:((Qs=ve(F))==null?void 0:Qs.error)||l(t)("models.probeFailHint")},{default:y(()=>{var Pe;return[j(S(l(t)("models.probeFail"))+" · "+S(((Pe=ve(F))==null?void 0:Pe.status)||"?"),1)]}),_:2},1032,["title"])):Y(F)?(_(),D(l(yt),{key:3,variant:"secondary",title:l(t)("models.delistedHint")},{default:y(()=>[j(S(l(t)("models.delisted")),1)]),_:1},8,["title"])):pe("",!0)]),x("span",IA,S(re(F)),1)])],40,EA),x("div",MA,[(_(),W(Se,null,tt(n,Pe=>x("button",{key:Pe,type:"button",disabled:K(F,Pe)==="unsupported"||k.value[`${F.name}:${Pe}`],title:De(F,Pe),"aria-label":De(F,Pe),class:Ce(["inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-xs font-medium transition-colors disabled:cursor-not-allowed",Te(F,Pe)]),onClick:mt=>Xe(F,Pe)},[k.value[`${F.name}:${Pe}`]?(_(),D(l(kt),{key:0,class:"h-3 w-3 animate-spin"})):(_(),W("span",{key:1,class:Ce(["rounded-full",K(F,Pe)==="enabled"?"h-1.5 w-1.5 bg-current":K(F,Pe)==="enableable"?"h-1.5 w-1.5 border border-current":"h-1.5 w-1.5"])},null,2)),j(" "+S(l(t)(se[Pe].chip)),1)],10,RA)),64))]),v(l(hi),null,{default:y(()=>[v(l(vi),null,{default:y(()=>[v(l(Re),{variant:"ghost",size:"icon",class:"h-8 w-8 shrink-0 text-muted-foreground","aria-label":l(t)("models.moreActions")},{default:y(()=>[v(l(_i),{class:"h-4 w-4"})]),_:1},8,["aria-label"])]),_:1}),v(l(gi),{align:"end"},{default:y(()=>{var Pe;return[v(l(Wn),{disabled:((Pe=ve(F))==null?void 0:Pe.state)==="testing"||!ce(F).length,onSelect:mt=>Bt(F)},{default:y(()=>{var mt;return[((mt=ve(F))==null?void 0:mt.state)==="testing"?(_(),D(l(kt),{key:0,class:"animate-spin"})):(_(),D(l(Tl),{key:1})),j(" "+S(l(t)("models.testModel")),1)]}),_:2},1032,["disabled","onSelect"]),v(l(yi)),v(l(Wn),{class:"text-destructive focus:bg-destructive/10 focus:text-destructive",onSelect:mt=>Ts(F)},{default:y(()=>[v(l(xi)),j(" "+S(l(t)("models.removeModel")),1)]),_:1},8,["onSelect"])]}),_:2},1024)]),_:2},1024)]),O(F.name)?(_(),W("div",LA,[(_(!0),W(Se,null,tt(ce(F),Pe=>(_(),W("div",{key:Pe,class:"space-y-1"},[x("div",DA,[x("span",{class:Ce(["h-2 w-2 rounded-full",l(tn)[Pe].solid])},null,2),x("span",FA,S(l(t)(se[Pe].key)),1),x("span",NA,S(se[Pe].endpoint),1)]),U(F,Pe)?(_(),W("div",qA,[x("span",BA,S(l(t)("models.delisted")),1),x("span",null,S(l(t)("models.delistedHint")),1)])):pe("",!0),F[Pe].chain.length?pe("",!0):(_(),W("div",VA,S(l(t)("models.noSources")),1)),(_(!0),W(Se,null,tt(F[Pe].chain,(mt,pt)=>{var wu,xu;return _(),W("div",{key:pt,class:"group flex items-center gap-2 rounded px-1 py-1 hover:bg-muted/40"},[x("span",UA,S(pt+1)+".",1),x("span",HA,[x("span",{class:Ce(["h-1.5 w-1.5 rounded-full",l(si)(mt.id).solid])},null,2),j(" "+S(mt.name),1)]),pt===0?(_(),D(l(yt),{key:0,variant:"default"},{default:y(()=>[j(S(l(t)("models.primary")),1)]),_:1})):(_(),D(l(yt),{key:1,variant:"muted"},{default:y(()=>[j(S(l(t)("models.fallback")),1)]),_:1})),Km(mt)?(_(),W("span",jA,[v(l(Ko),{class:"h-3 w-3 text-muted-foreground"}),yo(x("input",{type:"number",min:"0",inputmode:"numeric",value:Eo.value,placeholder:l(t)("sources.rpmPh"),"aria-label":l(t)("sources.rpmLabel"),title:l(t)("sources.rpmHint"),class:"h-6 w-16 rounded-md border border-input bg-background px-2 font-mono text-xs shadow-sm transition-colors placeholder:font-sans placeholder:text-muted-foreground/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",onInput:q[4]||(q[4]=it=>zm(it.target.value)),onKeyup:[q[5]||(q[5]=Bs(it=>it.target.blur(),["enter"])),Bs(it=>Xm(mt,it.target),["esc"])],onBlur:it=>Ym(mt)},null,40,WA),[[R]])])):Ps(mt.id)>0?(_(),W("button",{key:3,type:"button",title:l(t)("sources.rpmBadgeHint"),class:"inline-flex items-center gap-1 rounded-full border border-input bg-background px-2 py-0.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:it=>_u(mt)},[v(l(Ko),{class:"h-3 w-3"}),j(" "+S(l(t)("sources.rpmBadge",{n:Ps(mt.id)})),1)],8,KA)):pe("",!0),g.value[`${F.name}:${Pe}:${pt}`]?(_(),D(l(yt),{key:4,variant:"muted",class:"gap-1"},{default:y(()=>[v(l(kt),{class:"h-3 w-3 animate-spin"}),j(S(l(t)("models.probeTesting")),1)]),_:1})):(wu=T.value[`${F.name}:${Pe}:${pt}`])!=null&&wu.ok?(_(),D(l(yt),{key:5,variant:"success",title:l(t)("models.probeOkHint",{name:mt.name})},{default:y(()=>[j(S(l(t)("models.probeOk")),1)]),_:1},8,["title"])):T.value[`${F.name}:${Pe}:${pt}`]?(_(),D(l(yt),{key:6,variant:"destructive",title:((xu=T.value[`${F.name}:${Pe}:${pt}`])==null?void 0:xu.error)||l(t)("models.probeFailHint")},{default:y(()=>{var it;return[j(S(l(t)("models.probeFail"))+" · "+S(((it=T.value[`${F.name}:${Pe}:${pt}`])==null?void 0:it.status)||"?"),1)]}),_:2},1032,["title"])):pe("",!0),Vm(F,Pe,pt)?(_(),W("div",zA,[q[14]||(q[14]=x("span",{class:"text-xs text-muted-foreground"},"→",-1)),yo(x("input",{type:"text",value:Um(F,Pe,pt),placeholder:l(t)("models.upstreamPh"),"aria-label":l(t)("models.upstreamLabel"),title:l(t)("models.upstreamHint"),spellcheck:"false",class:"h-6 w-40 rounded-md border border-input bg-background px-2 font-mono text-xs shadow-sm transition-colors placeholder:font-sans placeholder:text-muted-foreground/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",onInput:it=>Hm(F,Pe,pt,it.target.value),onKeyup:[q[6]||(q[6]=Bs(it=>it.target.blur(),["enter"])),Bs(it=>Wm(F,Pe,mt,pt,it.target),["esc"])],onBlur:it=>jm(F,Pe,mt,pt)},null,40,GA),[[R]])])):mt.model?(_(),W("button",{key:8,type:"button",title:l(t)("models.upstreamHint"),class:"inline-flex items-center gap-1 rounded border border-transparent px-1.5 py-0.5 font-mono text-xs text-muted-foreground transition-colors hover:border-border hover:bg-background hover:text-foreground",onClick:it=>bu(F,Pe,mt,pt)},[q[15]||(q[15]=x("span",null,"→",-1)),j(S(mt.model),1)],8,YA)):pe("",!0),x("div",XA,[v(l(Re),{variant:"ghost",size:"icon",class:"h-7 w-7",disabled:pt===0,"aria-label":l(t)("models.moveUpAria"),onClick:it=>Nm(F,pt,Pe)},{default:y(()=>[v(l(Zk),{class:"h-4 w-4"})]),_:1},8,["disabled","aria-label","onClick"]),v(l(Re),{variant:"ghost",size:"icon",class:"h-7 w-7",disabled:pt===F[Pe].chain.length-1,"aria-label":l(t)("models.moveDownAria"),onClick:it=>qm(F,pt,Pe)},{default:y(()=>[v(l(Qk),{class:"h-4 w-4"})]),_:1},8,["disabled","aria-label","onClick"]),v(l(hi),null,{default:y(()=>[v(l(vi),null,{default:y(()=>[v(l(Re),{variant:"ghost",size:"icon",class:"h-7 w-7 text-muted-foreground","aria-label":l(t)("models.moreActions")},{default:y(()=>[v(l(_i),{class:"h-4 w-4"})]),_:1},8,["aria-label"])]),_:1}),v(l(gi),{align:"end"},{default:y(()=>[v(l(Wn),{disabled:g.value[`${F.name}:${Pe}:${pt}`],onSelect:it=>rn(F,Pe,pt)},{default:y(()=>[g.value[`${F.name}:${Pe}:${pt}`]?(_(),D(l(kt),{key:0,class:"animate-spin"})):(_(),D(l(Tl),{key:1})),j(" "+S(l(t)("models.testSource")),1)]),_:2},1032,["disabled","onSelect"]),v(l(Wn),{onSelect:it=>bu(F,Pe,mt,pt)},{default:y(()=>[v(l(Pm),{class:"h-4 w-4"}),j(" "+S(l(t)("models.editUpstream")),1)]),_:1},8,["onSelect"]),v(l(Wn),{onSelect:it=>_u(mt)},{default:y(()=>[v(l(Ko),{class:"h-4 w-4"}),j(" "+S(l(t)("sources.rpmLabel")),1)]),_:1},8,["onSelect"]),v(l(yi)),v(l(Wn),{class:"text-destructive focus:bg-destructive/10 focus:text-destructive",onSelect:it=>Jm(F,Pe,pt)},{default:y(()=>[v(l(xi),{class:"h-4 w-4"}),j(" "+S(l(t)("models.removeSource")),1)]),_:1},8,["onSelect"])]),_:2},1024)]),_:2},1024)])])}),128))]))),128)),G(F).length?(_(),W("div",JA,[v(l(Re),{variant:"outline",size:"sm",class:"h-7 gap-1 border-dashed text-muted-foreground",onClick:Pe=>Bm(F)},{default:y(()=>[v(l(es),{class:"h-3.5 w-3.5"}),j(" "+S(l(t)("models.addSourceToChain")),1)]),_:1},8,["onClick"])])):pe("",!0)])):pe("",!0)])}),128))])])):pe("",!0),x("section",QA,[q[18]||(q[18]=x("div",{class:"pointer-events-none absolute inset-y-0 left-0 w-1 bg-muted-foreground/40","aria-hidden":"true"},null,-1)),x("div",ZA,[x("button",{type:"button",class:"flex min-w-0 flex-1 items-center gap-2.5 rounded px-1 py-0.5 text-left hover:bg-muted/50",onClick:q[7]||(q[7]=F=>u.value=!u.value)},[v(l(Xa),{class:Ce(["h-4 w-4 shrink-0 text-muted-foreground transition-transform",{"-rotate-90":!u.value}])},null,8,["class"]),q[17]||(q[17]=x("span",{class:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/40"},null,-1)),x("span",eE,S(l(t)("models.availableSection")),1),x("span",tE,S(qe.value.length),1)]),st.value>0?(_(),D(l(Re),{key:0,variant:"ghost",size:"sm",class:Ce(["h-7 gap-1.5 px-2.5",Ee.value?"bg-accent text-accent-foreground":"text-muted-foreground"]),title:Ee.value?l(t)("models.filterChatHint",{n:st.value}):l(t)("models.filterAllHint"),onClick:q[8]||(q[8]=F=>Ee.value=!Ee.value)},{default:y(()=>[v(l(Om),{class:"h-3.5 w-3.5"}),j(" "+S(Ee.value?l(t)("models.filterChatOnly"):l(t)("models.filterInclude")),1)]),_:1},8,["class","title"])):pe("",!0),v(l(Re),{variant:"ghost",size:"sm",class:"h-7 gap-1.5 px-2.5",disabled:d.value,title:l(t)("sources.refreshAll"),onClick:Qm},{default:y(()=>[d.value?(_(),D(l(kt),{key:0,class:"h-3.5 w-3.5 animate-spin"})):(_(),D(l(mr),{key:1,class:"h-3.5 w-3.5"})),j(" "+S(l(t)("sources.refreshAll")),1)]),_:1},8,["disabled","title"]),qe.value.length?(_(),D(l(Re),{key:1,size:"sm",variant:"secondary",class:"h-7 gap-1.5 px-2.5",disabled:f.value,onClick:Kt},{default:y(()=>[f.value?(_(),D(l(kt),{key:0,class:"h-3.5 w-3.5 animate-spin"})):(_(),D(l(Tl),{key:1,class:"h-3.5 w-3.5"})),j(" "+S(l(t)("models.enableAll")),1)]),_:1},8,["disabled"])):pe("",!0)]),u.value?(_(),W("div",nE,[qe.value.length?(_(),W("div",oE,[(_(!0),W(Se,null,tt(ft.value,F=>(_(),W("div",{key:F.source.id},[x("button",{type:"button",class:"flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-muted/40","aria-expanded":M(F.source.id,F.rows.length),"aria-label":F.source.name,onClick:_e=>L(F.source.id,F.rows.length)},[v(l(bi),{class:Ce(["h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform",{"rotate-90":M(F.source.id,F.rows.length)}])},null,8,["class"]),x("span",{class:Ce(["h-1.5 w-1.5 shrink-0 rounded-full",l(si)(F.source.id).solid])},null,2),x("span",aE,S(F.source.name),1),x("span",lE,S(F.rows.length),1)],8,rE),M(F.source.id,F.rows.length)?(_(),W("div",iE,[(_(!0),W(Se,null,tt(F.rows,_e=>(_(),W("div",{key:_e.name,class:"flex items-center justify-between gap-2 px-3 py-2 pl-9"},[x("div",uE,[x("span",cE,S(_e.name),1),x("button",{type:"button",title:l(t)("connect.copy"),"aria-label":l(t)("connect.copy"),class:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground/50 transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:Ae=>V(_e.name)},[v(l(Xn),{class:"h-3 w-3"})],8,dE)]),x("div",fE,[(_(),W(Se,null,tt(n,Ae=>x("button",{key:Ae,type:"button",disabled:K(_e,Ae)==="unsupported"||k.value[`${_e.name}:${Ae}`],title:De(_e,Ae),"aria-label":De(_e,Ae),class:Ce(["inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-xs font-medium transition-colors disabled:cursor-not-allowed",Te(_e,Ae)]),onClick:ot=>Xe(_e,Ae)},[k.value[`${_e.name}:${Ae}`]?(_(),D(l(kt),{key:0,class:"h-3 w-3 animate-spin"})):(_(),W("span",{key:1,class:Ce(["rounded-full",K(_e,Ae)==="enabled"?"h-1.5 w-1.5 bg-current":K(_e,Ae)==="enableable"?"h-1.5 w-1.5 border border-current":"h-1.5 w-1.5"])},null,2)),j(" "+S(l(t)(se[Ae].chip)),1)],10,pE)),64))])]))),128))])):pe("",!0)]))),128))])):(_(),W("p",sE,S(Ee.value&&fe.value.length?l(t)("models.availableAllFiltered",{n:st.value}):l(t)("models.availableDesc")),1))])):pe("",!0)])],64))]),_:1})]),_:1})),v(yS,{open:p.value,"onUpdate:open":q[9]||(q[9]=F=>p.value=F),onChanged:ie},null,8,["open"]),v(zS,{open:m.value,"onUpdate:open":q[10]||(q[10]=F=>m.value=F),providers:o.value,onChanged:ie},null,8,["open","providers"]),v(cA,{open:I.value,"onUpdate:open":q[11]||(q[11]=F=>I.value=F),"model-name":((ne=C.value)==null?void 0:ne.name)??"",providers:o.value,"enabled-formats":C.value?ce(C.value):[],"chain-by-format":C.value?le(C.value):{},onAdded:ie},null,8,["open","model-name","providers","enabled-formats","chain-by-format"]),v(gu,{open:de.value,"onUpdate:open":q[12]||(q[12]=F=>de.value=F),variant:"destructive",title:l(t)("models.removeModel"),description:z.value?l(t)("models.confirmRemove",{name:z.value.name}):"","confirm-text":l(t)("models.removeModel"),loading:z.value?!!w.value[z.value.name]:!1,onConfirm:Er},null,8,["open","title","description","confirm-text","loading"])])}}}),vE={class:"relative w-full overflow-auto"},Lm=Q({__name:"Table",props:{class:{type:[Boolean,null,String,Object,Array]}},setup(e){const t=e;return(n,s)=>(_(),W("div",vE,[x("table",{class:Ce(l(Ye)("w-full caption-bottom text-sm",t.class))},[ae(n.$slots,"default")],2)]))}}),Dm=Q({__name:"TableHeader",props:{class:{type:[Boolean,null,String,Object,Array]}},setup(e){const t=e;return(n,s)=>(_(),W("thead",{class:Ce(l(Ye)("[&_tr]:border-b",t.class))},[ae(n.$slots,"default")],2))}}),Fm=Q({__name:"TableBody",props:{class:{type:[Boolean,null,String,Object,Array]}},setup(e){const t=e;return(n,s)=>(_(),W("tbody",{class:Ce(l(Ye)("[&_tr:last-child]:border-0",t.class))},[ae(n.$slots,"default")],2))}}),io=Q({__name:"TableRow",props:{class:{type:[Boolean,null,String,Object,Array]}},setup(e){const t=e;return(n,s)=>(_(),W("tr",{class:Ce(l(Ye)("border-b transition-colors hover:bg-muted/40 data-[state=selected]:bg-muted",t.class))},[ae(n.$slots,"default")],2))}}),zt=Q({__name:"TableHead",props:{class:{type:[Boolean,null,String,Object,Array]}},setup(e){const t=e;return(n,s)=>(_(),W("th",{class:Ce(l(Ye)("h-10 px-3 text-left align-middle text-xs font-medium uppercase tracking-wide text-muted-foreground [&:has([role=checkbox])]:pr-0",t.class))},[ae(n.$slots,"default")],2))}}),Dt=Q({__name:"TableCell",props:{class:{type:[Boolean,null,String,Object,Array]}},setup(e){const t=e;return(n,s)=>(_(),W("td",{class:Ce(l(Ye)("p-3 align-middle [&:has([role=checkbox])]:pr-0",t.class))},[ae(n.$slots,"default")],2))}}),gE=Q({__name:"Popover",props:{defaultOpen:{type:Boolean},open:{type:Boolean},modal:{type:Boolean}},emits:["update:open"],setup(e,{emit:t}){const o=Rt(e,t);return(r,a)=>(_(),D(l(gx),Ot($t(l(o))),{default:y(()=>[ae(r.$slots,"default")]),_:3},16))}}),yE=Q({__name:"PopoverTrigger",props:{asChild:{type:Boolean},as:{}},setup(e){const t=e;return(n,s)=>(_(),D(l(Ox),Ot($t(t)),{default:y(()=>[ae(n.$slots,"default")]),_:3},16))}}),bE=Q({__name:"PopoverContent",props:{forceMount:{type:Boolean},memoDependencies:{},side:{},sideOffset:{default:4},sideFlip:{type:Boolean},align:{},alignOffset:{},alignFlip:{type:Boolean},avoidCollisions:{type:Boolean},collisionBoundary:{},collisionPadding:{},arrowPadding:{},hideShiftedArrow:{type:Boolean},sticky:{},hideWhenDetached:{type:Boolean},positionStrategy:{},updatePositionStrategy:{},disableUpdateOnLayoutShift:{type:Boolean},prioritizePosition:{type:Boolean},reference:{},dir:{},asChild:{type:Boolean},as:{},disableOutsidePointerEvents:{type:Boolean},class:{type:[Boolean,null,String,Object,Array]}},emits:["escapeKeyDown","pointerDownOutside","focusOutside","interactOutside","openAutoFocus","closeAutoFocus"],setup(e,{emit:t}){const n=e,s=t,o=X(()=>{const{class:a,...i}=n;return i}),r=Rt(o,s);return(a,i)=>(_(),D(l(Ax),null,{default:y(()=>[v(l(Cx),Ie(l(r),{class:l(Ye)("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2",n.class)}),{default:y(()=>[ae(a.$slots,"default")]),_:3},16,["class"])]),_:3}))}}),_E={class:"flex items-center justify-between gap-2"},wE={class:"flex gap-1"},xE={class:"sr-only"},kE={class:"flex flex-wrap items-center gap-2"},CE={class:"relative flex-1 sm:max-w-sm"},SE={key:0,class:"inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-primary px-1 text-[10px] font-medium text-primary-foreground"},AE={class:"space-y-2.5"},EE={class:"flex items-center justify-between"},OE={class:"text-xs font-medium"},TE={class:"space-y-2"},PE={class:"grid grid-cols-[3.5rem_1fr] items-center gap-2"},$E={class:"text-xs text-muted-foreground"},IE={class:"grid grid-cols-[3.5rem_1fr] items-center gap-2"},ME={class:"text-xs text-muted-foreground"},RE={class:"grid grid-cols-[3.5rem_1fr] items-center gap-2"},LE={class:"text-xs text-muted-foreground"},DE={key:0,class:"flex flex-wrap items-center gap-1.5"},FE={class:"text-muted-foreground"},NE={class:"font-medium"},qE=["aria-label","onClick"],BE={class:"flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-muted-foreground"},VE={key:1,class:"space-y-2 rounded-lg border border-amber-500/30 bg-amber-500/5 p-3"},UE={class:"flex items-center gap-1.5 text-xs font-medium text-amber-700 dark:text-amber-400"},HE={class:"space-y-1.5"},jE={class:"font-medium"},WE={class:"break-all text-muted-foreground"},KE={key:2,class:"space-y-2 rounded-lg border border-orange-500/30 bg-orange-500/5 p-3"},zE={class:"flex items-center gap-1.5 text-xs font-medium text-orange-700 dark:text-orange-400"},GE={class:"space-y-1.5"},YE={class:"font-medium"},XE={class:"text-muted-foreground"},JE={key:3,class:"py-6 text-center text-sm text-muted-foreground"},QE={key:4,class:"py-6 text-center text-sm text-muted-foreground"},ZE={key:5,class:"overflow-x-auto"},eO={class:"flex flex-wrap items-center gap-x-2 gap-y-1 text-xs"},tO={class:"font-mono text-muted-foreground"},nO={class:"font-medium"},sO={class:"text-muted-foreground"},oO={class:"text-muted-foreground"},rO={class:"break-all text-muted-foreground"},aO={key:0,class:"text-muted-foreground/60"},lO={class:"inline-flex items-center gap-1.5"},iO={class:"grid grid-cols-[auto_1fr] gap-x-4 gap-y-1.5 px-2 py-2 text-xs sm:grid-cols-[auto_1fr_auto_1fr]"},uO={class:"text-muted-foreground"},cO={class:"font-mono"},dO={class:"text-muted-foreground"},fO={class:"font-mono"},pO={class:"text-muted-foreground"},mO={class:"text-muted-foreground"},hO={class:"break-all font-mono"},vO={class:"text-muted-foreground"},gO={class:"font-mono"},yO={class:"text-foreground/80"},bO={class:"text-foreground/80"},_O={class:"text-amber-600 dark:text-amber-400"},wO={class:"text-muted-foreground"},xO={class:"break-all font-mono"},_d="myapikey.logs.filters",kO=Q({__name:"Logs",setup(e){const{t}=It(),n=N([]),s=N(!0),o=N(!1),r=N([]),a=N([]),i=N("all"),u=N("all"),c=N("all"),d=N(""),f=N(new Set),p=N(!1);try{const K=JSON.parse(localStorage.getItem(_d)||"null");K&&(typeof K.model=="string"&&(i.value=K.model),typeof K.provider=="string"&&(u.value=K.provider),(K.status==="success"||K.status==="error")&&(c.value=K.status),typeof K.query=="string"&&(d.value=K.query))}catch{}Fe([i,u,c,d],()=>{try{localStorage.setItem(_d,JSON.stringify({model:i.value,provider:u.value,status:c.value,query:d.value}))}catch{}});let m;async function w(){o.value=!0;try{const[K,he]=await Promise.all([Ue("GET","/admin/logs").catch(()=>null),Ue("GET","/admin/circuit").catch(()=>null)]);K&&(n.value=K.logs),he&&(r.value=he.providers.filter(ee=>ee.state==="cooling"),a.value=he.providers.filter(ee=>ee.rpm>0&&ee.rpmUsed>=ee.rpm&&ee.state!=="cooling"))}finally{o.value=!1}}async function k(K){await Ue("POST",`/admin/circuit/${K}/reset`).catch(()=>{}),await w()}function E(){h(),m=window.setInterval(w,4e3)}function h(){m&&(clearInterval(m),m=void 0)}function g(){s.value=!s.value,s.value?(w(),E()):h()}function T(K){return K>=200&&K<300?"success":K>=400?"destructive":"muted"}function b(K){var he;return((he=tn[K])==null?void 0:he.badge)??""}function P(K){return K<1e3?`${K}ms`:`${(K/1e3).toFixed(1)}s`}function A(K){return K?K<1e3?String(K):K<1e6?(K/1e3).toFixed(K<1e4?1:0).replace(/\.0$/,"")+"k":(K/1e6).toFixed(1)+"M":"0"}function C(K){if(K<=0)return"0";const he=Math.round(K*1e3)/10;return Number.isInteger(he)?String(he):he.toFixed(1)}function I(K){return new Date(K).toLocaleTimeString()}function R(K){return new Date(K).toLocaleString()}function z(K){return`${K.ts}-${K.model}-${K.provider}-${K.status}-${K.kind??"call"}`}function de(K){return f.value.has(z(K))}function Z(K){const he=new Set(f.value),ee=z(K);he.has(ee)?he.delete(ee):he.add(ee),f.value=he}const ie=X(()=>[...new Set(n.value.map(K=>K.model))].sort()),ke=X(()=>[...new Set(n.value.map(K=>K.provider))].sort()),J=X(()=>{const K=d.value.trim().toLowerCase();return n.value.filter(he=>{var ee;return!(i.value!=="all"&&he.model!==i.value||u.value!=="all"&&he.provider!==u.value||c.value==="success"&&!(he.status>=200&&he.status<300)||c.value==="error"&&he.status<400||K&&!(he.model.toLowerCase().includes(K)||(ee=he.upstreamModel)!=null&&ee.toLowerCase().includes(K)||he.provider.toLowerCase().includes(K)))})}),te=X(()=>{const K=J.value.filter(fe=>fe.kind!=="cooldown"),he=K.length,ee=K.filter(fe=>fe.status>=400).length,lt=he?Math.round(K.reduce((fe,ue)=>fe+ue.ms,0)/he):0;return{total:he,fail:ee,avgMs:lt,errorRateStr:C(he?ee/he:0)}}),ce=X(()=>(i.value!=="all"?1:0)+(u.value!=="all"?1:0)+(c.value!=="all"?1:0)),ge=X(()=>{const K=[];return i.value!=="all"&&K.push({key:"model",label:t("logs.filter.model"),value:i.value,clear:()=>i.value="all"}),u.value!=="all"&&K.push({key:"provider",label:t("logs.filter.provider"),value:u.value,clear:()=>u.value="all"}),c.value!=="all"&&K.push({key:"status",label:t("logs.filter.status"),value:c.value==="success"?t("logs.filter.success"):t("logs.filter.error"),clear:()=>c.value="all"}),K});function $e(){i.value="all",u.value="all",c.value="all"}return dt(()=>{w(),E()}),bn(h),(K,he)=>(_(),D(l(hn),null,{default:y(()=>[v(l(Mn),null,{default:y(()=>[x("div",_E,[v(l(Rn),{class:"flex items-center gap-2 text-base"},{default:y(()=>[v(l(Sm),{class:"h-4 w-4 text-primary"}),j(" "+S(l(t)("logs.title"))+" ",1),s.value?(_(),D(l(yt),{key:0,variant:"success",class:"gap-1.5"},{default:y(()=>[he[5]||(he[5]=x("span",{class:"relative flex h-1.5 w-1.5"},[x("span",{class:"absolute inline-flex h-full w-full animate-ping rounded-full bg-current opacity-75"}),x("span",{class:"relative inline-flex h-1.5 w-1.5 rounded-full bg-current"})],-1)),j(" "+S(l(t)("logs.live")),1)]),_:1})):pe("",!0)]),_:1}),x("div",wE,[v(l(Re),{variant:"outline",size:"sm",disabled:o.value,onClick:w},{default:y(()=>[o.value?(_(),D(l(kt),{key:0,class:"h-3.5 w-3.5 animate-spin"})):(_(),D(l(mr),{key:1,class:"h-3.5 w-3.5"})),x("span",xE,S(l(t)("logs.refresh")),1)]),_:1},8,["disabled"]),v(l(Re),{variant:"outline",size:"sm","aria-pressed":s.value,onClick:g},{default:y(()=>[s.value?(_(),D(l(eC),{key:0,class:"h-3.5 w-3.5"})):(_(),D(l(tC),{key:1,class:"h-3.5 w-3.5"})),j(" "+S(s.value?l(t)("logs.pause"):l(t)("logs.resume")),1)]),_:1},8,["aria-pressed"])])]),v(l(gs),null,{default:y(()=>[j(S(l(t)("logs.desc")),1)]),_:1})]),_:1}),v(l(vn),{class:"space-y-3"},{default:y(()=>[x("div",kE,[x("div",CE,[v(l(Im),{class:"pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),v(l(Tt),{modelValue:d.value,"onUpdate:modelValue":he[0]||(he[0]=ee=>d.value=ee),placeholder:l(t)("logs.searchPh"),class:"h-8 pl-8"},null,8,["modelValue","placeholder"])]),v(l(gE),{open:p.value,"onUpdate:open":he[4]||(he[4]=ee=>p.value=ee)},{default:y(()=>[v(l(yE),{"as-child":""},{default:y(()=>[v(l(Re),{variant:"outline",size:"sm",class:"h-8 gap-1.5"},{default:y(()=>[v(l(Om),{class:"h-3.5 w-3.5"}),j(" "+S(l(t)("logs.filter.title"))+" ",1),ce.value?(_(),W("span",SE,S(ce.value),1)):pe("",!0)]),_:1})]),_:1}),v(l(bE),{align:"start",class:"w-72 p-3"},{default:y(()=>[x("div",AE,[x("div",EE,[x("span",OE,S(l(t)("logs.filter.title")),1),ce.value?(_(),W("button",{key:0,type:"button",class:"text-xs text-primary hover:underline",onClick:$e},S(l(t)("logs.filter.clear")),1)):pe("",!0)]),x("div",TE,[x("div",PE,[x("span",$E,S(l(t)("logs.filter.model")),1),v(l(zo),{modelValue:i.value,"onUpdate:modelValue":he[1]||(he[1]=ee=>i.value=ee)},{default:y(()=>[v(l(Go),{class:"h-8 w-full"},{default:y(()=>[v(l(Yo),{placeholder:l(t)("logs.filter.model")},null,8,["placeholder"])]),_:1}),v(l(Xo),null,{default:y(()=>[v(l(ln),{value:"all"},{default:y(()=>[j(S(l(t)("logs.filter.all")),1)]),_:1}),(_(!0),W(Se,null,tt(ie.value,ee=>(_(),D(l(ln),{key:ee,value:ee},{default:y(()=>[j(S(ee),1)]),_:2},1032,["value"]))),128))]),_:1})]),_:1},8,["modelValue"])]),x("div",IE,[x("span",ME,S(l(t)("logs.filter.provider")),1),v(l(zo),{modelValue:u.value,"onUpdate:modelValue":he[2]||(he[2]=ee=>u.value=ee)},{default:y(()=>[v(l(Go),{class:"h-8 w-full"},{default:y(()=>[v(l(Yo),{placeholder:l(t)("logs.filter.provider")},null,8,["placeholder"])]),_:1}),v(l(Xo),null,{default:y(()=>[v(l(ln),{value:"all"},{default:y(()=>[j(S(l(t)("logs.filter.all")),1)]),_:1}),(_(!0),W(Se,null,tt(ke.value,ee=>(_(),D(l(ln),{key:ee,value:ee},{default:y(()=>[j(S(ee),1)]),_:2},1032,["value"]))),128))]),_:1})]),_:1},8,["modelValue"])]),x("div",RE,[x("span",LE,S(l(t)("logs.filter.status")),1),v(l(zo),{modelValue:c.value,"onUpdate:modelValue":he[3]||(he[3]=ee=>c.value=ee)},{default:y(()=>[v(l(Go),{class:"h-8 w-full"},{default:y(()=>[v(l(Yo),{placeholder:l(t)("logs.filter.status")},null,8,["placeholder"])]),_:1}),v(l(Xo),null,{default:y(()=>[v(l(ln),{value:"all"},{default:y(()=>[j(S(l(t)("logs.filter.all")),1)]),_:1}),v(l(ln),{value:"success"},{default:y(()=>[j(S(l(t)("logs.filter.success")),1)]),_:1}),v(l(ln),{value:"error"},{default:y(()=>[j(S(l(t)("logs.filter.error")),1)]),_:1})]),_:1})]),_:1},8,["modelValue"])])])])]),_:1})]),_:1},8,["open"])]),ge.value.length?(_(),W("div",DE,[(_(!0),W(Se,null,tt(ge.value,ee=>(_(),W("span",{key:ee.key,class:"inline-flex items-center gap-1 rounded-full border border-input bg-muted/40 py-0.5 pl-2.5 pr-1 text-xs"},[x("span",FE,S(ee.label)+":",1),x("span",NE,S(ee.value),1),x("button",{type:"button",class:"rounded-full p-0.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground","aria-label":l(t)("logs.filter.remove",{label:ee.label}),onClick:ee.clear},[v(l(Ja),{class:"h-3 w-3"})],8,qE)]))),128)),x("button",{type:"button",class:"text-xs text-muted-foreground hover:text-foreground",onClick:$e},S(l(t)("logs.filter.clear")),1)])):pe("",!0),x("div",BE,[x("span",null,S(l(t)("logs.summary.window",{n:te.value.total})),1),x("span",{class:Ce({"text-destructive":te.value.fail>0})},S(l(t)("logs.summary.errorRate",{pct:te.value.errorRateStr})),3),x("span",null,S(l(t)("logs.summary.avgLatency",{ms:P(te.value.avgMs)})),1)]),r.value.length?(_(),W("div",VE,[x("div",UE,[v(l(Ol),{class:"h-4 w-4"}),j(" "+S(l(t)("logs.circuit.stripTitle")),1)]),x("ul",HE,[(_(!0),W(Se,null,tt(r.value,ee=>(_(),W("li",{key:ee.id,class:"flex flex-wrap items-center gap-x-2 gap-y-1 text-xs"},[x("span",jE,S(ee.name),1),v(l(yt),{variant:"warning",class:"gap-1 whitespace-nowrap"},{default:y(()=>[v(l(Ol),{class:"h-3 w-3"}),j(" "+S(l(t)("logs.circuit.remaining",{s:ee.secondsLeft})),1)]),_:2},1024),x("span",WE,S(ee.lastReason||l(t)("logs.circuit.reasonUnknown")),1),v(l(Re),{variant:"outline",size:"sm",class:"ml-auto h-6 gap-1",onClick:lt=>k(ee.id)},{default:y(()=>[v(l(mr),{class:"h-3 w-3"}),j(" "+S(l(t)("logs.circuit.reset")),1)]),_:1},8,["onClick"])]))),128))])])):pe("",!0),a.value.length?(_(),W("div",KE,[x("div",zE,[v(l(Ko),{class:"h-4 w-4"}),j(" "+S(l(t)("logs.pacing.stripTitle")),1)]),x("ul",GE,[(_(!0),W(Se,null,tt(a.value,ee=>(_(),W("li",{key:ee.id,class:"flex flex-wrap items-center gap-x-2 gap-y-1 text-xs"},[x("span",YE,S(ee.name),1),v(l(yt),{variant:"outline",class:"gap-1 whitespace-nowrap"},{default:y(()=>[v(l(Ko),{class:"h-3 w-3"}),j(" "+S(l(t)("logs.pacing.at",{used:ee.rpmUsed,cap:ee.rpm})),1)]),_:2},1024),x("span",XE,S(l(t)("logs.pacing.reason")),1)]))),128))])])):pe("",!0),n.value.length?J.value.length?(_(),W("div",ZE,[v(l(Lm),null,{default:y(()=>[v(l(Dm),null,{default:y(()=>[v(l(io),null,{default:y(()=>[v(l(zt),{class:"w-8"}),v(l(zt),null,{default:y(()=>[j(S(l(t)("logs.col.time")),1)]),_:1}),v(l(zt),null,{default:y(()=>[j(S(l(t)("logs.col.model")),1)]),_:1}),v(l(zt),null,{default:y(()=>[j(S(l(t)("logs.col.provider")),1)]),_:1}),v(l(zt),null,{default:y(()=>[j(S(l(t)("logs.col.format")),1)]),_:1}),v(l(zt),{class:"text-right"},{default:y(()=>[j(S(l(t)("logs.col.latency")),1)]),_:1}),v(l(zt),{class:"text-right"},{default:y(()=>[j(S(l(t)("logs.col.status")),1)]),_:1})]),_:1})]),_:1}),v(l(Fm),null,{default:y(()=>[(_(!0),W(Se,null,tt(J.value,ee=>(_(),W(Se,{key:z(ee)},[ee.kind==="cooldown"?(_(),D(l(io),{key:0,class:"bg-amber-500/5 hover:bg-amber-500/10"},{default:y(()=>[v(l(Dt),{colspan:"7",class:"py-2"},{default:y(()=>[x("div",eO,[x("span",tO,S(I(ee.ts)),1),v(l(yt),{variant:"warning",class:"gap-1 whitespace-nowrap"},{default:y(()=>[v(l(Ol),{class:"h-3 w-3"}),j(" "+S(l(t)("logs.circuit.badge")),1)]),_:1}),x("span",nO,S(ee.provider),1),x("span",sO,S(l(t)("logs.circuit.failures",{n:ee.fails})),1),x("span",oO,S(l(t)("logs.circuit.cooldown",{s:Math.round((ee.cooldownMs??0)/1e3)})),1),x("span",rO,S(ee.error||l(t)("logs.circuit.reasonUnknown")),1)])]),_:2},1024)]),_:2},1024)):(_(),W(Se,{key:1},[v(l(io),{class:"cursor-pointer hover:bg-muted/50",onClick:lt=>Z(ee)},{default:y(()=>[v(l(Dt),{class:"w-8 text-muted-foreground"},{default:y(()=>[(_(),D(br(de(ee)?l(Xa):l(bi)),{class:"h-3.5 w-3.5"}))]),_:2},1024),v(l(Dt),{class:"font-mono text-xs text-muted-foreground",title:R(ee.ts)},{default:y(()=>[j(S(I(ee.ts)),1)]),_:2},1032,["title"]),v(l(Dt),{class:"font-mono text-xs"},{default:y(()=>[j(S(ee.model),1),ee.upstreamModel?(_(),W("span",aO," → "+S(ee.upstreamModel),1)):pe("",!0)]),_:2},1024),v(l(Dt),{class:"text-sm"},{default:y(()=>[j(S(ee.provider),1)]),_:2},1024),v(l(Dt),null,{default:y(()=>[x("span",lO,[v(l(yt),{variant:"outline",class:Ce(b(ee.format))},{default:y(()=>[j(S(ee.format),1)]),_:2},1032,["class"]),ee.stream?(_(),D(l(yt),{key:0,variant:"muted",class:"text-[10px]"},{default:y(()=>[j(S(l(t)("logs.stream")),1)]),_:1})):pe("",!0)])]),_:2},1024),v(l(Dt),{class:"text-right font-mono text-xs text-muted-foreground"},{default:y(()=>[j(S(P(ee.ms)),1)]),_:2},1024),v(l(Dt),{class:"text-right"},{default:y(()=>[v(l(yt),{variant:T(ee.status),class:"font-mono"},{default:y(()=>[j(S(ee.status),1)]),_:2},1032,["variant"])]),_:2},1024)]),_:2},1032,["onClick"]),de(ee)?(_(),D(l(io),{key:0,class:"hover:bg-transparent"},{default:y(()=>[v(l(Dt),{colspan:"7",class:"bg-muted/30"},{default:y(()=>[x("dl",iO,[x("dt",uO,S(l(t)("logs.detail.time")),1),x("dd",cO,S(R(ee.ts)),1),x("dt",dO,S(l(t)("logs.detail.latency")),1),x("dd",fO,S(P(ee.ms)),1),x("dt",pO,S(l(t)("logs.detail.stream")),1),x("dd",null,S(ee.stream?l(t)("logs.detail.streamYes"):l(t)("logs.detail.streamNo")),1),ee.upstreamModel?(_(),W(Se,{key:0},[x("dt",mO,S(l(t)("logs.detail.upstreamModel")),1),x("dd",hO,S(ee.upstreamModel),1)],64)):pe("",!0),ee.usage?(_(),W(Se,{key:1},[x("dt",vO,S(l(t)("logs.detail.tokens")),1),x("dd",gO,[x("span",yO,"↑ "+S(A(ee.usage.input)),1),he[7]||(he[7]=x("span",{class:"text-muted-foreground/50"}," · ",-1)),x("span",bO,"↓ "+S(A(ee.usage.output)),1),ee.usage.estimated?(_(),D(l(yt),{key:0,variant:"muted",class:"ml-1.5 text-[10px]"},{default:y(()=>[j("≈ "+S(l(t)("logs.detail.estimated")),1)]),_:1})):pe("",!0),(ee.usage.cacheRead||0)+(ee.usage.cacheCreation||0)?(_(),W(Se,{key:1},[he[6]||(he[6]=x("span",{class:"text-muted-foreground/50"}," · ",-1)),x("span",_O,"⚡ "+S(l(t)("logs.detail.cache"))+" "+S(A((ee.usage.cacheRead||0)+(ee.usage.cacheCreation||0))),1)],64)):pe("",!0)])],64)):pe("",!0),x("dt",wO,S(l(t)("logs.detail.error")),1),x("dd",xO,S(ee.error||l(t)("logs.detail.errorNone")),1)])]),_:2},1024)]),_:2},1024)):pe("",!0)],64))],64))),128))]),_:1})]),_:1})])):(_(),W("p",QE,S(l(t)("logs.noMatch")),1)):(_(),W("p",JE,S(l(t)("logs.empty")),1))]),_:1})]),_:1}))}}),CO={key:0,class:"py-4 text-center text-xs text-muted-foreground"},SO={class:"flex items-center gap-1.5"},AO={class:"truncate font-mono text-xs"},EO={class:"flex items-center gap-2"},OO={class:"h-1.5 w-full max-w-[120px] overflow-hidden rounded-full bg-muted"},TO={class:"font-mono text-xs tabular-nums"},PO={key:0},$O={class:"text-foreground/80"},IO={class:"text-foreground/80"},MO={key:1,class:"text-muted-foreground/40"},RO={key:0,class:"inline-flex flex-col items-end leading-tight"},LO={class:"text-amber-600 dark:text-amber-400"},DO={class:"text-[10px] text-muted-foreground/60"},FO={key:1,class:"text-muted-foreground/40"},Vr=Q({__name:"StatsBreakdown",props:{title:{},buckets:{},max:{},kind:{}},setup(e){const{t}=It();function n(d){return d<1e3?`${d}ms`:`${(d/1e3).toFixed(1)}s`}function s(d){return d?d<1e3?String(d):d<1e6?(d/1e3).toFixed(d<1e4?1:0).replace(/\.0$/,"")+"k":(d/1e6).toFixed(1)+"M":"0"}function o(d){if(!d)return"0%";const f=Math.round(d*1e3)/10;return(f%1===0?f.toFixed(0):f.toFixed(1))+"%"}const r=e,a=()=>r.buckets.some(d=>d.inputTokens||d.outputTokens),i=()=>r.buckets.some(d=>d.cacheRead||d.cacheCreation);function u(d,f){return f?Math.round(d/f*100):0}function c(d){var f;return(f=tn[d])==null?void 0:f.solid}return(d,f)=>(_(),D(l(hn),null,{default:y(()=>[v(l(Mn),{class:"pb-2"},{default:y(()=>[v(l(Rn),{class:"text-sm"},{default:y(()=>[j(S(e.title),1)]),_:1})]),_:1}),v(l(vn),null,{default:y(()=>[e.buckets.length?(_(),D(l(Lm),{key:1},{default:y(()=>[v(l(Dm),null,{default:y(()=>[v(l(io),null,{default:y(()=>[v(l(zt),null,{default:y(()=>[j(S(l(t)("stats.col.name")),1)]),_:1}),v(l(zt),{class:"w-1/3"},{default:y(()=>[j(S(l(t)("stats.col.calls")),1)]),_:1}),v(l(zt),{class:"text-right"},{default:y(()=>[j(S(l(t)("stats.col.success")),1)]),_:1}),v(l(zt),{class:"text-right"},{default:y(()=>[j(S(l(t)("stats.col.error")),1)]),_:1}),v(l(zt),{class:"text-right"},{default:y(()=>[j(S(l(t)("stats.col.avgLatency")),1)]),_:1}),a()?(_(),D(l(zt),{key:0,class:"text-right"},{default:y(()=>[j(S(l(t)("stats.col.tokens")),1)]),_:1})):pe("",!0),i()?(_(),D(l(zt),{key:1,class:"text-right"},{default:y(()=>[j(S(l(t)("stats.col.cacheHit")),1)]),_:1})):pe("",!0)]),_:1})]),_:1}),v(l(Fm),null,{default:y(()=>[(_(!0),W(Se,null,tt(e.buckets,p=>(_(),D(l(io),{key:p.key},{default:y(()=>[v(l(Dt),{class:"py-1.5"},{default:y(()=>[x("div",SO,[e.kind==="format"&&c(p.key)?(_(),W("span",{key:0,class:Ce(["h-2 w-2 shrink-0 rounded-full",c(p.key)])},null,2)):e.kind==="provider"&&p.id?(_(),W("span",{key:1,class:Ce(["h-2 w-2 shrink-0 rounded-full",l(si)(p.id).solid])},null,2)):pe("",!0),x("span",AO,S(p.key),1)])]),_:2},1024),v(l(Dt),{class:"py-1.5"},{default:y(()=>[x("div",EO,[x("div",OO,[x("div",{class:"h-full rounded-full bg-primary/50",style:dn({width:u(p.calls,e.max)+"%"})},null,4)]),x("span",TO,S(p.calls),1)])]),_:2},1024),v(l(Dt),{class:"py-1.5 text-right font-mono text-xs text-emerald-600 dark:text-emerald-400"},{default:y(()=>[j(S(p.success),1)]),_:2},1024),v(l(Dt),{class:Ce(["py-1.5 text-right font-mono text-xs",p.error?"text-destructive":"text-muted-foreground"])},{default:y(()=>[j(S(p.error),1)]),_:2},1032,["class"]),v(l(Dt),{class:"py-1.5 text-right font-mono text-xs text-muted-foreground"},{default:y(()=>[j(S(n(p.avgMs)),1)]),_:2},1024),a()?(_(),D(l(Dt),{key:0,class:"py-1.5 text-right font-mono text-xs tabular-nums"},{default:y(()=>[p.inputTokens||p.outputTokens?(_(),W("span",PO,[x("span",$O,S(s(p.inputTokens)),1),f[0]||(f[0]=x("span",{class:"text-muted-foreground/50"}," / ",-1)),x("span",IO,S(s(p.outputTokens)),1)])):(_(),W("span",MO,"—"))]),_:2},1024)):pe("",!0),i()?(_(),D(l(Dt),{key:1,class:"py-1.5 text-right font-mono text-xs tabular-nums"},{default:y(()=>[p.cacheRead||p.cacheCreation?(_(),W("span",RO,[x("span",LO,S(o(p.cacheHitRate)),1),x("span",DO,"↑"+S(s(p.cacheRead)),1)])):(_(),W("span",FO,"—"))]),_:2},1024)):pe("",!0)]),_:2},1024))),128))]),_:1})]),_:1})):(_(),W("p",CO,S(l(t)("stats.empty")),1))]),_:1})]),_:1}))}}),NO={class:"flex flex-wrap items-center justify-between gap-2"},qO={class:"flex items-center gap-2"},BO={class:"inline-flex rounded-md border bg-muted/30 p-0.5"},VO=["onClick"],UO={class:"sr-only"},HO={key:0,class:"flex items-center justify-center gap-2 py-10 text-sm text-muted-foreground"},jO={key:1,class:"py-10 text-center text-sm text-muted-foreground"},WO={class:"grid grid-cols-2 gap-2 sm:grid-cols-3 lg:grid-cols-6"},KO={class:"rounded-lg border bg-muted/20 p-3"},zO={class:"text-xs text-muted-foreground"},GO={class:"mt-1 font-mono text-xl tabular-nums"},YO={class:"rounded-lg border bg-muted/20 p-3"},XO={class:"text-xs text-muted-foreground"},JO={class:"mt-1 font-mono text-xl tabular-nums text-emerald-600 dark:text-emerald-400"},QO={class:"rounded-lg border bg-muted/20 p-3"},ZO={class:"text-xs text-muted-foreground"},eT={class:"mt-1 font-mono text-xl tabular-nums text-destructive"},tT={class:"rounded-lg border bg-muted/20 p-3"},nT={class:"text-xs text-muted-foreground"},sT={class:"mt-1 font-mono text-xl tabular-nums"},oT={class:"rounded-lg border bg-muted/20 p-3"},rT={class:"text-xs text-muted-foreground"},aT={class:"mt-1 font-mono text-xl tabular-nums"},lT={class:"rounded-lg border bg-muted/20 p-3"},iT={class:"text-xs text-muted-foreground"},uT={class:"mt-1 font-mono text-xl tabular-nums"},cT={key:0,class:"grid grid-cols-3 gap-2"},dT={class:"rounded-lg border bg-muted/20 p-3"},fT={class:"text-xs text-muted-foreground"},pT={class:"mt-1 font-mono text-lg tabular-nums"},mT={class:"rounded-lg border bg-muted/20 p-3"},hT={class:"text-xs text-muted-foreground"},vT={class:"mt-1 font-mono text-lg tabular-nums"},gT={class:"rounded-lg border bg-muted/20 p-3"},yT={class:"text-xs text-muted-foreground"},bT={class:"mt-1 font-mono text-lg tabular-nums"},_T={class:"mb-2 flex items-center justify-between gap-2"},wT={class:"text-sm font-medium"},xT={key:0,class:"text-[11px] text-muted-foreground"},kT={class:"font-mono tabular-nums text-foreground"},CT={class:"rounded-lg border p-3"},ST={class:"relative pt-9"},AT={class:"flex h-40 gap-px"},ET={class:"pointer-events-none absolute bottom-full left-1/2 z-20 mb-1 hidden -translate-x-1/2 whitespace-nowrap rounded-md border bg-background px-2 py-1 text-center text-xs shadow-md group-hover:block"},OT={class:"font-medium"},TT={class:"font-mono tabular-nums"},PT={class:"text-[10px]"},$T={class:"text-emerald-600 dark:text-emerald-400"},IT={class:"text-destructive"},MT={class:"mt-1.5 flex justify-between text-[10px] text-muted-foreground"},RT={class:"grid gap-4 lg:grid-cols-2"},LT={class:"lg:col-span-2"},DT={key:1,class:"space-y-3"},FT={class:"text-sm font-medium"},NT={class:"grid gap-4 lg:grid-cols-2"},wd=160,qT=Q({__name:"Stats",setup(e){const{t}=It(),n=[{v:"24h",key:"h24"},{v:"7d",key:"d7"},{v:"30d",key:"d30"},{v:"90d",key:"d90"},{v:"all",key:"all"}],s=N(localStorage.getItem("myapikey.stats.range")||"7d");n.some(T=>T.v===s.value)||(s.value="7d"),Fe(s,T=>{try{localStorage.setItem("myapikey.stats.range",T)}catch{}});const o=N(null),r=N(!1);async function a(){r.value=!0;try{o.value=await Ue("GET",`/admin/stats?range=${s.value}`)}catch{o.value=null}finally{r.value=!1}}Fe(s,a),dt(a);function i(T){return T<1e3?`${T}ms`:`${(T/1e3).toFixed(1)}s`}function u(T){if(!T)return"0%";const b=Math.round(T*1e3)/10;return(b%1===0?b.toFixed(0):b.toFixed(1))+"%"}function c(T){const[b,P,A]=T.split("-").map(Number);return new Date(b,P-1,A).toLocaleDateString(void 0,{month:"short",day:"numeric"})}const d=X(()=>{var T;return((T=o.value)==null?void 0:T.byDay.reduce((b,P)=>Math.max(b,P.calls),0))??0});function f(T){const b=d.value||1,P=T.calls/b*wd,A=T.error/b*wd;return{success:Math.max(0,Math.round(P-A)),error:Math.round(A)}}function p(T){return T.reduce((b,P)=>Math.max(b,P.calls),0)||1}const m=X(()=>!!o.value&&o.value.totals.calls>0),w=X(()=>{var T,b;return(((T=o.value)==null?void 0:T.totals.cacheRead)??0)+(((b=o.value)==null?void 0:b.totals.cacheCreation)??0)}),k=X(()=>!!o.value&&!!(o.value.totals.inputTokens||o.value.totals.outputTokens||w.value)),E=X(()=>{var P;const T=(((P=o.value)==null?void 0:P.byProviderModel)??[]).filter(A=>A.cacheRead||A.cacheCreation),b=new Map;for(const A of T){const C=A.providerId||A.provider;let I=b.get(C);I||(I={providerId:A.providerId,provider:A.provider,models:[],cacheRead:0},b.set(C,I)),I.models.push({key:A.model,calls:A.calls,success:A.success,error:0,avgMs:0,inputTokens:A.inputTokens,outputTokens:A.outputTokens,cacheRead:A.cacheRead,cacheCreation:A.cacheCreation,cacheHitRate:A.cacheHitRate}),I.cacheRead+=A.cacheRead}return[...b.values()].sort((A,C)=>C.cacheRead-A.cacheRead)}),h=X(()=>E.value.length>0);function g(T){return T?T<1e3?String(T):T<1e6?(T/1e3).toFixed(T<1e4?1:0).replace(/\.0$/,"")+"k":(T/1e6).toFixed(1)+"M":"0"}return(T,b)=>(_(),D(l(hn),null,{default:y(()=>[v(l(Mn),null,{default:y(()=>[x("div",NO,[v(l(Rn),{class:"flex items-center gap-2 text-base"},{default:y(()=>[v(l(Am),{class:"h-4 w-4 text-primary"}),j(" "+S(l(t)("stats.title")),1)]),_:1}),x("div",qO,[x("div",BO,[(_(),W(Se,null,tt(n,P=>x("button",{key:P.v,type:"button",class:Ce(["rounded-sm px-2.5 py-1 text-xs transition-colors",s.value===P.v?"bg-background font-medium shadow-sm":"text-muted-foreground hover:text-foreground"]),onClick:A=>s.value=P.v},S(l(t)(`stats.ranges.${P.key}`)),11,VO)),64))]),v(l(Re),{variant:"outline",size:"sm",disabled:r.value,onClick:a},{default:y(()=>[r.value?(_(),D(l(kt),{key:0,class:"h-3.5 w-3.5 animate-spin"})):(_(),D(l(mr),{key:1,class:"h-3.5 w-3.5"})),x("span",UO,S(l(t)("stats.refresh")),1)]),_:1},8,["disabled"])])]),v(l(gs),null,{default:y(()=>[j(S(l(t)("stats.desc")),1)]),_:1})]),_:1}),v(l(vn),{class:"space-y-5"},{default:y(()=>[r.value&&!o.value?(_(),W("div",HO,[v(l(kt),{class:"h-4 w-4 animate-spin"}),j(" "+S(l(t)("stats.loading")),1)])):m.value?o.value?(_(),W(Se,{key:2},[x("div",WO,[x("div",KO,[x("div",zO,S(l(t)("stats.totals.calls")),1),x("div",GO,S(o.value.totals.calls),1)]),x("div",YO,[x("div",XO,S(l(t)("stats.totals.success")),1),x("div",JO,S(o.value.totals.success),1)]),x("div",QO,[x("div",ZO,S(l(t)("stats.totals.error")),1),x("div",eT,S(o.value.totals.error),1)]),x("div",tT,[x("div",nT,S(l(t)("stats.totals.errorRate")),1),x("div",sT,S(u(o.value.totals.errorRate)),1)]),x("div",oT,[x("div",rT,S(l(t)("stats.totals.avgLatency")),1),x("div",aT,S(i(o.value.totals.avgMs)),1)]),x("div",lT,[x("div",iT,S(l(t)("stats.totals.p95")),1),x("div",uT,S(i(o.value.totals.p95Ms)),1)])]),k.value?(_(),W("div",cT,[x("div",dT,[x("div",fT,"↑ "+S(l(t)("stats.totals.inputTokens")),1),x("div",pT,S(g(o.value.totals.inputTokens)),1)]),x("div",mT,[x("div",hT,"↓ "+S(l(t)("stats.totals.outputTokens")),1),x("div",vT,S(g(o.value.totals.outputTokens)),1)]),x("div",gT,[x("div",yT,"⚡ "+S(l(t)("stats.totals.cache")),1),x("div",bT,S(g(w.value)),1)])])):pe("",!0),x("div",null,[x("div",_T,[x("div",wT,S(l(t)("stats.byDay")),1),d.value?(_(),W("div",xT,[j(S(l(t)("stats.peak"))+" ",1),x("span",kT,S(d.value),1)])):pe("",!0)]),x("div",CT,[x("div",ST,[x("div",AT,[(_(!0),W(Se,null,tt(o.value.byDay,P=>(_(),W("div",{key:P.day,class:"group relative flex min-w-0 flex-1 cursor-default flex-col justify-end"},[x("div",{style:dn({height:f(P).success+"px"}),class:"w-full rounded-t-sm bg-emerald-500/70 transition-colors group-hover:bg-emerald-500"},null,4),x("div",{style:dn({height:f(P).error+"px"}),class:Ce(["w-full transition-colors group-hover:bg-destructive",f(P).error?"bg-destructive/70":""])},null,6),x("div",ET,[x("div",OT,S(c(P.day)),1),x("div",TT,S(P.calls)+" "+S(l(t)("stats.callsAxis")),1),x("div",PT,[x("span",$T,S(P.success),1),b[0]||(b[0]=x("span",{class:"text-muted-foreground"}," / ",-1)),x("span",IT,S(P.error),1)])])]))),128))])]),x("div",MT,[x("span",null,S(o.value.byDay.length?c(o.value.byDay[0].day):""),1),x("span",null,S(o.value.byDay.length?c(o.value.byDay[o.value.byDay.length-1].day):""),1)])])]),x("div",RT,[x("div",LT,[v(Vr,{title:l(t)("stats.byModel"),buckets:o.value.byModel,max:p(o.value.byModel),kind:"model"},null,8,["title","buckets","max"])]),v(Vr,{title:l(t)("stats.byProvider"),buckets:o.value.byProvider,max:p(o.value.byProvider),kind:"provider"},null,8,["title","buckets","max"]),v(Vr,{title:l(t)("stats.byFormat"),buckets:o.value.byFormat,max:p(o.value.byFormat),kind:"format"},null,8,["title","buckets","max"])]),h.value?(_(),W("div",DT,[x("div",FT,S(l(t)("stats.cacheBySource")),1),x("div",NT,[(_(!0),W(Se,null,tt(E.value,P=>(_(),D(Vr,{key:P.providerId||P.provider,title:P.provider,buckets:P.models,max:p(P.models),kind:"model"},null,8,["title","buckets","max"]))),128))])])):pe("",!0)],64)):pe("",!0):(_(),W("div",jO,S(l(t)("stats.empty")),1))]),_:1})]),_:1}))}}),BT={class:"space-y-4"},VT={class:"space-y-2"},UT={class:"min-w-0"},HT={class:"mt-0.5 truncate font-mono text-sm"},jT={class:"min-w-0"},WT={class:"mt-0.5 truncate font-mono text-sm"},KT={class:"text-xs text-muted-foreground"},zT={class:"flex items-center justify-between gap-3 rounded-lg border border-primary/40 bg-primary/5 p-3"},GT={class:"min-w-0"},YT={class:"text-xs font-medium text-primary"},XT={class:"truncate font-mono text-sm"},JT={class:"flex items-center gap-1"},QT={class:"overflow-x-auto rounded-md border bg-muted/40 p-3 font-mono text-xs leading-relaxed"},ZT=Q({__name:"Connect",setup(e){const{t}=It(),n={openai:"openai",anthropic:"anthropic",responses:"responses",curl:null,"curl-anthropic":"anthropic"};function s(w){const k=n[w];return k?tn[k]:null}const o=N(null),r=N(null),a=N(""),i=N(!1),u=X(()=>{const w=window.location.hostname;if((w==="localhost"||w==="127.0.0.1")&&r.value){const k=window.location.port;return`${window.location.protocol}//${r.value}${k?":"+k:""}`}return window.location.origin}),c=X(()=>`${u.value}/openai/v1`),d=X(()=>`${u.value}/anthropic`);async function f(){o.value=(await Ue("GET","/admin/api-key")).apiKey,r.value=(await Ue("GET","/admin/connection")).lanIp}async function p(w,k){await Xi(k)?(a.value=w,setTimeout(()=>{a.value===w&&(a.value="")},1500)):Le(t("connect.copyFailed"),"error")}const m=X(()=>[{key:"openai",title:t("connect.openaiTitle"),text:`export OPENAI_BASE_URL=${c.value}
284
284
  export OPENAI_API_KEY=${o.value??""}`},{key:"anthropic",title:t("connect.anthropicTitle"),text:`export ANTHROPIC_BASE_URL=${d.value}
285
285
  export ANTHROPIC_API_KEY=${o.value??""}`},{key:"curl",title:t("connect.curlTitle"),text:`curl ${c.value}/chat/completions \\
286
286
  -H "Authorization: Bearer ${o.value??""}" \\
@@ -15,7 +15,7 @@
15
15
  document.documentElement.classList.add("dark");
16
16
  }
17
17
  </script>
18
- <script type="module" crossorigin src="/assets/index-Cl4xh-Yi.js"></script>
18
+ <script type="module" crossorigin src="/assets/index-B760GVAz.js"></script>
19
19
  <link rel="stylesheet" crossorigin href="/assets/index-ldNYk-oG.css">
20
20
  </head>
21
21
  <body>