manifest
Version:
Self-hosted Manifest LLM router with embedded server, SQLite database, and dashboard
2 lines (1 loc) • 32.7 kB
JavaScript
import{i,t as d,a as p,f as Le,g as l,S as _,h as w,s as z,m as J,P as ve,d as ie,o as De,F as ge,z as ke,j as de,n as Be,k as me,T as ze,M as je}from"./vendor-C-Y5oNOq.js";import{e as $e,q as ne,B as le,s as Ne,d as se,t as B,b as pe}from"./index-C4Qw7vZo.js";import{a as He}from"./provider-api-key-urls-1G6okUJ7.js";import{a as Ge}from"./routing-CLLAl6kl.js";import"./auth-CU91cd7V.js";function Ve(e){return $e("/notifications/logs",{agent_name:e})}function qe(e){return $e("/notifications",{agent_name:e})}function Ue(e){return ne(`${le}/notifications`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}function Je(e,t){return ne(`${le}/notifications/${encodeURIComponent(e)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}function Fe(e){return ne(`${le}/notifications/${encodeURIComponent(e)}`,{method:"DELETE"})}async function We(){const e=await $e("/notifications/email-provider");return"configured"in e&&e.configured===!1?null:e}function Ze(e){return ne(`${le}/notifications/email-provider`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}function Ye(){return ne(`${le}/notifications/email-provider`,{method:"DELETE"})}function Xe(e){return ne(`${le}/notifications/email-provider/test`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}function Qe(e){return ne(`${le}/notifications/email-provider/test-saved`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({to:e})})}var et=d('<div class=cloud-email-info><svg class=cloud-email-info__icon width=20 height=20 viewBox="0 0 24 24"fill=none stroke=currentColor stroke-width=2 stroke-linecap=round stroke-linejoin=round aria-hidden=true><path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"></path><polyline points="22,6 12,13 2,6"></polyline></svg><div><div class=cloud-email-info__title>Email alerts</div><div class=cloud-email-info__desc>Alerts will be sent to <strong>');const tt=e=>(()=>{var t=et(),n=t.firstChild,a=n.nextSibling,s=a.firstChild,o=s.nextSibling,u=o.firstChild,v=u.nextSibling;return i(v,()=>e.email),t})();var it=d("<input id=email-provider-api-key class=modal-card__input type=text autocomplete=off autofocus style=-webkit-text-security:disc;text-security:disc>"),we=d("<p class=modal-card__field-error role=alert>"),nt=d('<p class=modal-card__field-hint><a class=modal-card__field-link target=_blank rel="noopener noreferrer">Get <!> API key'),lt=d("<label class=modal-card__field-label for=email-provider-domain>Sending domain"),rt=d('<input id=email-provider-domain class=modal-card__input type=text placeholder="e.g. notifications.mycompany.com">'),at=d('<div class=modal-overlay><div class=modal-card role=dialog aria-modal=true aria-labelledby=provider-modal-title><h2 class=modal-card__title id=provider-modal-title></h2><p class=modal-card__desc>Enter your API credentials to enable email alert delivery.</p><label class=modal-card__field-label>Provider</label><div class=provider-modal-picker><button class=provider-modal-option type=button><img src=/logos/resend.svg alt class=provider-modal-option__logo><span>Resend</span></button><button class=provider-modal-option type=button><img src=/logos/mailgun.svg alt class=provider-modal-option__logo><span>Mailgun</span></button><button class=provider-modal-option type=button><img src=/logos/sendgrid.svg alt class=provider-modal-option__logo><span>SendGrid</span></button></div><label class=modal-card__field-label for=email-provider-api-key>API Key</label><label class=modal-card__field-label for=email-provider-notification>Notification email</label><input id=email-provider-notification class=modal-card__input type=email><p class=modal-card__field-hint>Where threshold alerts will be sent.</p><div class="modal-card__footer modal-card__footer--split"><button class="btn btn--ghost btn--sm"type=button></button><button class="btn btn--primary btn--sm">'),ot=d('<div class=masked-key><span class=masked-key__value></span><button class="btn btn--ghost btn--sm masked-key__edit"type=button>Change'),st=d("<span class=spinner>");const Ce=/^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+$/i,Se={resend:"Resend",mailgun:"Mailgun",sendgrid:"SendGrid"},Ae=e=>{const[t,n]=p("resend"),[a,s]=p(""),[o,u]=p(""),[v,h]=p(""),[C,S]=p(!1),[x,T]=p(!1),[R,f]=p(""),[k,m]=p(""),[b,j]=p(!1),M=Ne.useSession(),D=()=>e.editMode&&!!e.existingKeyPrefix&&t()===e.initialProvider,A=()=>(e.existingKeyPrefix??"")+"••••••••";Le(()=>{if(e.open){n(e.initialProvider),s("");const r=e.editMode&&!!e.existingKeyPrefix;j(!r),u(e.existingDomain??"");const $=e.existingNotificationEmail??(se()?"":M()?.data?.user?.email??"");h($),f(""),m("")}});const H=()=>t()==="mailgun",I=()=>{let r=!0;const $=a().trim(),P=o().trim().toLowerCase();return!b()&&D()?f(""):$?$.length<8?(f("API key must be at least 8 characters"),r=!1):t()==="resend"&&!$.startsWith("re_")?(f("Resend API key must start with re_"),r=!1):t()==="sendgrid"&&!$.startsWith("SG.")?(f("SendGrid API key must start with SG."),r=!1):f(""):(f("API key is required"),r=!1),H()?P?Ce.test(P)?m(""):(m("Invalid domain format"),r=!1):(m("Domain is required"),r=!1):P&&!Ce.test(P)?(m("Invalid domain format"),r=!1):m(""),r},Z=()=>{const r=v().trim();return r||(M()?.data?.user?.email??null)},N=async()=>{const r=a().trim(),$=o().trim().toLowerCase(),P=Z();if(!P)return B.error("Enter a notification email to send the test to"),!1;T(!0);try{const L={provider:t(),apiKey:r,to:P};$&&(L.domain=$);const q=await Xe(L);return q.success?!0:(B.error(q.error??"Email test failed — check your credentials"),!1)}catch{return!1}finally{T(!1)}},re=async()=>{const r=Z();if(!r)return B.error("Enter a notification email to send the test to"),!1;T(!0);try{const $=await Qe(r);return $.success?!0:(B.error($.error??"Email test failed — check your credentials"),!1)}catch{return!1}finally{T(!1)}},ae=async()=>{if(!I()||X())return;(!b()&&D()?await re():await N())&&B.success(`Test email sent to ${Z()}`)},Y=async()=>{if(!I()||C()||x())return;const r=!b()&&D();if(!(r?await re():await N()))return;const P=o().trim().toLowerCase();S(!0);try{const L={provider:t()};r||(L.apiKey=a().trim()),P&&(L.domain=P);const q=v().trim();q&&(L.notificationEmail=q),await Ze(L);const oe=Se[t()]??t();B.success(`${oe} connected`),e.onSaved(),e.onClose()}catch{}finally{S(!1)}},G=r=>{r.key==="Enter"&&Y(),r.key==="Escape"&&e.onClose()},X=()=>C()||x(),Q=()=>!b()&&D()?!!(H()&&!o().trim()):!!(!a().trim()||H()&&!o().trim()),V=()=>x()?"Testing...":C()?"Saving...":e.editMode?"Test & Save":"Test & Connect",ee=()=>He(t()),te=()=>{switch(t()){case"resend":return"re_xxxx...";case"sendgrid":return"SG.xxxx...";default:return"key-xxxx..."}};return l(ve,{get children(){return l(_,{get when(){return e.open},get children(){var r=at(),$=r.firstChild,P=$.firstChild,L=P.nextSibling,q=L.nextSibling,oe=q.nextSibling,ce=oe.firstChild,g=ce.nextSibling,y=g.nextSibling,ue=oe.nextSibling,O=ue.nextSibling,F=O.nextSibling,he=F.nextSibling,_e=he.nextSibling,K=_e.firstChild,fe=K.nextSibling;return r.$$click=()=>e.onClose(),$.$$click=c=>c.stopPropagation(),i(P,()=>e.editMode?"Edit email provider":"Configure email provider"),ce.$$click=()=>{n("resend"),f("")},g.$$click=()=>{n("mailgun"),f("")},y.$$click=()=>{n("sendgrid"),f("")},i($,l(_,{get when(){return b()||!D()},get fallback(){return(()=>{var c=ot(),E=c.firstChild,U=E.nextSibling;return i(E,A),U.$$click=()=>{j(!0),s("")},c})()},get children(){var c=it();return c.$$keydown=G,c.$$input=E=>{s(E.currentTarget.value),f("")},w(E=>{var U=!!R(),W=te();return U!==E.e&&c.classList.toggle("modal-card__input--error",E.e=U),W!==E.t&&z(c,"placeholder",E.t=W),E},{e:void 0,t:void 0}),w(()=>c.value=a()),c}}),O),i($,l(_,{get when(){return R()},get children(){var c=we();return i(c,R),c}}),O),i($,l(_,{get when(){return ee()},get children(){var c=nt(),E=c.firstChild,U=E.firstChild,W=U.nextSibling;return W.nextSibling,i(E,()=>Se[t()]??t(),W),w(()=>z(E,"href",ee())),c}}),O),i($,l(_,{get when(){return H()},get children(){return[lt(),(()=>{var c=rt();return c.$$keydown=G,c.$$input=E=>{u(E.currentTarget.value),m("")},w(()=>c.classList.toggle("modal-card__input--error",!!k())),w(()=>c.value=o()),c})(),l(_,{get when(){return k()},get children(){var c=we();return i(c,k),c}})]}}),O),F.$$keydown=G,F.$$input=c=>h(c.currentTarget.value),K.$$click=ae,i(K,(()=>{var c=J(()=>!!x());return()=>c()?st():"Send test email"})()),fe.$$click=Y,i(fe,V),w(c=>{var E=t()==="resend",U=t()==="mailgun",W=t()==="sendgrid",be=se()?"you@example.com":M()?.data?.user?.email??"you@example.com",ye=X()||Q(),xe=X()||Q();return E!==c.e&&ce.classList.toggle("provider-modal-option--active",c.e=E),U!==c.t&&g.classList.toggle("provider-modal-option--active",c.t=U),W!==c.a&&y.classList.toggle("provider-modal-option--active",c.a=W),be!==c.o&&z(F,"placeholder",c.o=be),ye!==c.i&&(K.disabled=c.i=ye),xe!==c.n&&(fe.disabled=c.n=xe),c},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),w(()=>F.value=v()),r}})}})};ie(["click","input","keydown"]);var dt=d('<div class=provider-card__dropdown><button class=provider-card__dropdown-item><svg width=14 height=14 viewBox="0 0 24 24"fill=none stroke=currentColor stroke-width=2 stroke-linecap=round stroke-linejoin=round aria-hidden=true><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path></svg>Edit</button><button class="provider-card__dropdown-item provider-card__dropdown-item--danger"><svg width=14 height=14 viewBox="0 0 24 24"fill=none stroke=currentColor stroke-width=2 stroke-linecap=round stroke-linejoin=round aria-hidden=true><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg>Remove'),ct=d("<span>"),ut=d('<span class=provider-card__email><svg width=12 height=12 viewBox="0 0 24 24"fill=none stroke=currentColor stroke-width=2 stroke-linecap=round stroke-linejoin=round aria-hidden=true><path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"></path><polyline points="22,6 12,13 2,6">'),gt=d('<div class=provider-card><div class=provider-card__header><span class=provider-card__label>Your provider</span><div class=provider-card__menu><button class=provider-card__menu-btn aria-label="Provider options"><svg width=16 height=16 viewBox="0 0 24 24"fill=currentColor aria-hidden=true><circle cx=12 cy=5 r=2></circle><circle cx=12 cy=12 r=2></circle><circle cx=12 cy=19 r=2></circle></svg></button></div></div><div class=provider-card__body><img alt class=provider-card__logo><div><div class=provider-card__name></div><div class=provider-card__meta><span class=provider-card__key>...');const vt={resend:"/logos/resend.svg",mailgun:"/logos/mailgun.svg",sendgrid:"/logos/sendgrid.svg"},mt={resend:"Resend",mailgun:"Mailgun",sendgrid:"SendGrid"},ht=e=>{const t=()=>vt[e.config.provider]??"/logos/resend.svg",n=()=>mt[e.config.provider]??e.config.provider,[a,s]=p(!1),o=v=>{v.target.closest(".provider-card__menu")||s(!1)},u=()=>{const v=!a();s(v),v&&document.addEventListener("click",o,{once:!0})};return De(()=>document.removeEventListener("click",o)),(()=>{var v=gt(),h=v.firstChild,C=h.firstChild,S=C.nextSibling,x=S.firstChild,T=h.nextSibling,R=T.firstChild,f=R.nextSibling,k=f.firstChild,m=k.nextSibling,b=m.firstChild,j=b.firstChild;return x.$$click=u,i(S,l(_,{get when(){return a()},get children(){var M=dt(),D=M.firstChild,A=D.nextSibling;return D.$$click=()=>{s(!1),e.onEdit()},A.$$click=()=>{s(!1),e.onRemove()},M}}),null),i(k,n),i(m,l(_,{get when(){return e.config.domain},get children(){var M=ct();return i(M,()=>e.config.domain),M}}),b),i(b,()=>e.config.keyPrefix,j),i(m,l(_,{get when(){return e.config.notificationEmail},get children(){var M=ut();return M.firstChild,i(M,()=>e.config.notificationEmail,null),M}}),null),w(()=>z(R,"src",t())),v})()};ie(["click"]);var _t=d("<h3 class=provider-setup__title>Configure email provider"),ft=d("<p class=provider-setup__subtitle>Choose a service to send alert notifications via email."),pt=d("<div class=provider-setup-grid><button class=provider-setup-card><img src=/logos/resend.svg alt class=provider-setup-card__logo><div><div class=provider-setup-card__name>Resend</div><div class=provider-setup-card__desc>Email API</div></div></button><button class=provider-setup-card><img src=/logos/mailgun.svg alt class=provider-setup-card__logo><div><div class=provider-setup-card__name>Mailgun</div><div class=provider-setup-card__desc>Transactional email</div></div></button><button class=provider-setup-card><img src=/logos/sendgrid.svg alt class=provider-setup-card__logo><div><div class=provider-setup-card__name>SendGrid</div><div class=provider-setup-card__desc>Email delivery");const $t=e=>{const[t,n]=p(!1),[a,s]=p("resend"),o=u=>{s(u),n(!0)};return[_t(),ft(),(()=>{var u=pt(),v=u.firstChild,h=v.nextSibling,C=h.nextSibling;return v.$$click=()=>o("resend"),h.$$click=()=>o("mailgun"),C.$$click=()=>o("sendgrid"),u})(),l(Ae,{get open(){return t()},get initialProvider(){return a()},onClose:()=>n(!1),get onSaved(){return e.onConfigured}})]};ie(["click"]);var bt=d("<div style=margin-bottom:var(--gap-lg)>"),yt=d('<div class=provider-card><div class=provider-card__header><span class=provider-card__label>Your provider</span><div class="skeleton skeleton--text"style="width:16px;height:16px;border-radius:calc(var(--radius) - 2px)"></div></div><div class=provider-card__body><div class="skeleton skeleton--rect"style="width:32px;height:32px;border-radius:calc(var(--radius) - 2px);flex-shrink:0"></div><div><div class="skeleton skeleton--text"style=width:80px;height:14px></div><div class="skeleton skeleton--text"style=width:160px;height:12px;margin-top:6px>'),xt=d('<div class=panel><div class="skeleton skeleton--text"style=width:180px;height:16px></div><div class="skeleton skeleton--text"style=width:280px;height:13px;margin-top:6px></div><div style=display:flex;gap:var(--gap-md);margin-top:var(--gap-lg)>'),kt=d('<div class="skeleton skeleton--rect"style=flex:1;height:64px;border-radius:var(--radius)>');const wt=e=>(()=>{var t=bt();return i(t,l(_,{get when(){return!e.loading},get fallback(){return l(_,{get when(){return!!e.emailProvider},get fallback(){return(()=>{var n=xt(),a=n.firstChild,s=a.nextSibling,o=s.nextSibling;return i(o,l(ge,{each:[1,2,3],children:()=>kt()})),n})()},get children(){return yt()}})},get children(){return l(_,{get when(){return e.emailProvider},get fallback(){return l($t,{get onConfigured(){return e.onConfigured}})},get children(){return l(ht,{get config(){return e.emailProvider},get onEdit(){return e.onEdit},get onRemove(){return e.onRemove}})}})}})),t})();var Ct=d(`<div class=modal-overlay><div class=modal-card role=dialog aria-modal=true aria-labelledby=limit-modal-title><h2 class=modal-card__title id=limit-modal-title></h2><p class=modal-card__desc>You'll receive an email alert when usage exceeds the threshold.</p><label class=modal-card__field-label for=limit-metric-select style=margin-top:0>Metric</label><select id=limit-metric-select class="select notification-modal__select"><option value=tokens>Tokens</option><option value=cost>Cost (USD)</option></select><div class=limit-modal__row><div class=limit-modal__col><label class=modal-card__field-label for=limit-threshold-input>Threshold</label><input id=limit-threshold-input class=modal-card__input type=number min=0></div><div class=limit-modal__col><label class=modal-card__field-label for=limit-period-select>Period</label><select id=limit-period-select class="select notification-modal__select"><option value=hour>Per hour</option><option value=day>Per day</option><option value=week>Per week</option><option value=month>Per month</option></select></div></div><div class=limit-block-toggle><span class=limit-block-toggle__label>Block requests when exceeded</span><label class=notification-toggle><input type=checkbox><span class=notification-toggle__slider></span></label></div><div class=modal-card__footer><button class="btn btn--primary btn--sm">`),St=d("<span class=spinner>");const Et=e=>{const[t,n]=p(!1),[a,s]=p("tokens"),[o,u]=p(""),[v,h]=p("day"),C=()=>t()?"both":"notify",S=()=>{n(!1),s("tokens"),u(""),h("day")};Le(()=>{if(e.open&&e.editData){const m=e.editData;s(m.metric_type),u(String(m.threshold)),h(m.period),n(m.action==="block"||m.action==="both")}else e.open&&S()});const[x,T]=p(!1),R=async()=>{if(x())return;const m=Number(o());if(!(isNaN(m)||m<=0)){T(!0);try{await e.onSave({metric_type:a(),threshold:m,period:v(),action:C()}),S()}finally{T(!1)}}},f=()=>{S(),e.onClose()},k=()=>!!e.editData;return l(ve,{get children(){return l(_,{get when(){return e.open},get children(){var m=Ct(),b=m.firstChild,j=b.firstChild,M=j.nextSibling,D=M.nextSibling,A=D.nextSibling,H=A.nextSibling,I=H.firstChild,Z=I.firstChild,N=Z.nextSibling,re=I.nextSibling,ae=re.firstChild,Y=ae.nextSibling,G=H.nextSibling,X=G.firstChild,Q=X.nextSibling,V=Q.firstChild,ee=G.nextSibling,te=ee.firstChild;return m.$$click=()=>f(),b.$$click=r=>r.stopPropagation(),i(j,()=>k()?"Edit rule":"Create rule"),A.addEventListener("change",r=>s(r.currentTarget.value)),N.$$keydown=r=>{r.key==="Enter"&&R()},N.$$input=r=>u(r.currentTarget.value),Y.addEventListener("change",r=>h(r.currentTarget.value)),V.addEventListener("change",r=>n(r.currentTarget.checked)),te.$$click=R,i(te,(()=>{var r=J(()=>!!x());return()=>r()?St():k()?"Save changes":"Create rule"})()),w(r=>{var $=a()==="cost"?"0.01":"1",P=a()==="cost"?"e.g. 10.00":"e.g. 50000",L=!o()||Number(o())<=0||x();return $!==r.e&&z(N,"step",r.e=$),P!==r.t&&z(N,"placeholder",r.t=P),L!==r.a&&(te.disabled=r.a=L),r},{e:void 0,t:void 0,a:void 0}),w(()=>A.value=a()),w(()=>N.value=o()),w(()=>Y.value=v()),w(()=>V.checked=t()),m}})}})};ie(["click","input","keydown"]);var Pt=d('<svg xmlns=http://www.w3.org/2000/svg viewBox="0 0 24 24"fill=currentColor aria-hidden=true><path d="M19.12 12.71a.4.4 0 0 1-.12-.29v-2.41c0-1.91-.75-3.69-2.13-5.02-.86-.84-1.9-1.42-3.02-1.73-.3-.73-1.01-1.24-1.85-1.24s-1.57.53-1.86 1.27C7.19 4.14 5 6.98 5 10.27v2.16c0 .11-.04.22-.12.29l-1.17 1.17a2.411 2.411 0 0 0 1.7 4.12h13.17a2.411 2.411 0 0 0 1.7-4.12l-1.17-1.17ZM18.58 16H5.41a.412.412 0 0 1-.29-.7l1.17-1.17c.46-.46.71-1.06.71-1.71v-2.16c0-2.81 2.17-5.17 4.85-5.25h.16c1.31 0 2.54.5 3.48 1.41.98.95 1.52 2.22 1.52 3.59v2.41c0 .65.25 1.25.71 1.71l1.17 1.17a.412.412 0 0 1-.29.7ZM14.82 20H9.18c.41 1.17 1.51 2 2.82 2s2.41-.83 2.82-2">');const Rt=e=>{const t=()=>e.size??16;return(()=>{var n=Pt();return w(a=>{var s=t(),o=t();return s!==a.e&&z(n,"width",a.e=s),o!==a.t&&z(n,"height",a.t=o),a},{e:void 0,t:void 0}),n})()};var Mt=d('<svg xmlns=http://www.w3.org/2000/svg viewBox="0 0 24 24"fill=currentColor aria-hidden=true><path d="M11.5 2c-5.51 0-10 4.49-10 10s4.49 10 10 10 10-4.49 10-10-4.49-10-10-10m-8 10c0-1.85.63-3.54 1.69-4.9L16.4 18.31A8 8 0 0 1 11.5 20c-4.41 0-8-3.59-8-8m14.31 4.9L6.6 5.69A8 8 0 0 1 11.5 4c4.41 0 8 3.59 8 8 0 1.85-.63 3.54-1.69 4.9">');const Tt=e=>{const t=()=>e.size??16;return(()=>{var n=Mt();return w(a=>{var s=t(),o=t();return s!==a.e&&z(n,"width",a.e=s),o!==a.t&&z(n,"height",a.t=o),a},{e:void 0,t:void 0}),n})()};var Ee=d('<table class="notif-table notif-table--flush"><thead><tr><th>Type</th><th>Threshold</th><th>Triggered</th><th style=text-align:right>Actions</th></tr></thead><tbody>'),Lt=d("<div class=panel><div class=panel__title>Rules"),Dt=d('<tr><td><div class="skeleton skeleton--text"style=width:28px></div></td><td><div class="skeleton skeleton--text"style=width:80px></div></td><td><div class="skeleton skeleton--text"style=width:20px></div></td><td style=text-align:right><div class="skeleton skeleton--text"style=width:16px;margin-left:auto>'),Nt=d("<div class=empty-state><div class=empty-state__title>No rules yet</div><p>Set up alerts for usage spikes, or hard limits to block requests over budget."),At=d('<span class=limit-type-icon title="Email Alert">'),It=d('<span class=limit-type-icon title="Hard Limit">'),Ot=d('<span class=limit-warn-tag><svg width=12 height=12 viewBox="0 0 24 24"fill=none stroke=currentColor stroke-width=2 stroke-linecap=round stroke-linejoin=round aria-hidden=true><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path><line x1=12 y1=9 x2=12 y2=13></line><line x1=12 y1=17 x2=12.01 y2=17></line></svg>No provider'),Kt=d('<tr><td><div class=limit-type-icons></div></td><td><span class=notif-table__mono></span> <span class=notif-table__period></span></td><td class=notif-table__mono></td><td><div class=notif-table__actions><button class=rule-menu__btn aria-label="Rule options"><svg width=16 height=16 viewBox="0 0 24 24"fill=currentColor aria-hidden=true><circle cx=12 cy=5 r=2></circle><circle cx=12 cy=12 r=2></circle><circle cx=12 cy=19 r=2>');function Ie(e){return e.metric_type==="cost"?`$${Number(e.threshold).toFixed(2)}`:`${Number(e.threshold).toLocaleString()} tokens`}const Oe={hour:"Per hour",day:"Per day",week:"Per week",month:"Per month"},Bt=e=>typeof e.is_active=="number"?!!e.is_active:e.is_active,Pe=e=>e==="notify"||e==="both",zt=e=>e==="block"||e==="both",jt=e=>(()=>{var t=Lt();return t.firstChild,i(t,l(_,{get when(){return!e.loading},get fallback(){return(()=>{var n=Ee(),a=n.firstChild,s=a.nextSibling;return i(s,l(ge,{each:[1,2,3],children:()=>Dt()})),n})()},get children(){return l(_,{get when(){return(e.rules??[]).length>0},get fallback(){return Nt()},get children(){var n=Ee(),a=n.firstChild,s=a.nextSibling;return i(s,l(ge,{get each(){return e.rules},children:o=>(()=>{var u=Kt(),v=u.firstChild,h=v.firstChild,C=v.nextSibling,S=C.firstChild,x=S.nextSibling,T=x.nextSibling,R=C.nextSibling,f=R.nextSibling,k=f.firstChild,m=k.firstChild;return i(h,l(_,{get when(){return Pe(o.action??"notify")},get children(){var b=At();return i(b,l(Rt,{size:14})),b}}),null),i(h,l(_,{get when(){return zt(o.action??"notify")},get children(){var b=It();return i(b,l(Tt,{size:14})),b}}),null),i(h,l(_,{get when(){return J(()=>!!Pe(o.action??"notify"))()&&!e.hasProvider},get children(){return Ot()}}),null),i(S,()=>Ie(o)),i(T,()=>(Oe[o.period]??o.period).toLowerCase()),i(R,()=>o.trigger_count??0),m.$$click=b=>e.onToggleMenu(o.id,b),w(()=>u.classList.toggle("notif-table__row--disabled",!Bt(o))),u})()})),n}})}}),null),t})();ie(["click"]);var Re=d('<table class="notif-table notif-table--flush"><thead><tr><th>Date</th><th>Usage</th><th>Threshold</th><th>Resets at</th></tr></thead><tbody>'),Ht=d("<div class=panel><div class=panel__title>History"),Gt=d('<tr><td><div class="skeleton skeleton--text"style=width:100px></div></td><td><div class="skeleton skeleton--text"style=width:60px></div></td><td><div class="skeleton skeleton--text"style=width:60px></div></td><td><div class="skeleton skeleton--text"style=width:100px>'),Vt=d("<div class=empty-state><div class=empty-state__title>No alerts triggered yet"),qt=d("<tr><td class=notif-table__mono></td><td class=notif-table__mono></td><td class=notif-table__mono></td><td class=notif-table__mono>");function Me(e,t){const n=Number(e[t]);return e.metric_type==="cost"?`$${n.toFixed(2)}`:`${n.toLocaleString()} tokens`}function Te(e){const t=e.endsWith("Z")?e:e.replace(" ","T")+"Z";return new Date(t).toLocaleDateString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}const Ut=e=>(()=>{var t=Ht();return t.firstChild,i(t,l(_,{get when(){return!e.loading},get fallback(){return(()=>{var n=Re(),a=n.firstChild,s=a.nextSibling;return i(s,l(ge,{each:[1,2,3],children:()=>Gt()})),n})()},get children(){return l(_,{get when(){return(e.logs??[]).length>0},get fallback(){return Vt()},get children(){var n=Re(),a=n.firstChild,s=a.nextSibling;return i(s,l(ge,{get each(){return e.logs},children:o=>(()=>{var u=qt(),v=u.firstChild,h=v.nextSibling,C=h.nextSibling,S=C.nextSibling;return i(v,()=>Te(o.sent_at)),i(h,()=>Me(o,"actual_value")),i(C,()=>Me(o,"threshold_value")),i(S,()=>Te(o.period_end)),u})()})),n}})}}),null),t})();var Jt=d('<div class=rule-menu__dropdown role=menu style=position:fixed;transform:translateX(-100%)><button class=rule-menu__item role=menuitem><svg width=14 height=14 viewBox="0 0 24 24"fill=none stroke=currentColor stroke-width=2 stroke-linecap=round stroke-linejoin=round aria-hidden=true><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path></svg>Edit</button><button class="rule-menu__item rule-menu__item--danger"role=menuitem><svg width=14 height=14 viewBox="0 0 24 24"fill=none stroke=currentColor stroke-width=2 stroke-linecap=round stroke-linejoin=round aria-hidden=true><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg>Delete'),Ft=d('<div class=modal-overlay><div class=modal-card role=dialog aria-modal=true aria-labelledby=delete-rule-modal-title style=max-width:440px><h2 class=modal-card__title id=delete-rule-modal-title>Delete rule</h2><p class=modal-card__desc>This will permanently delete the <span style=font-weight:600></span> rule (<!> <!>). This action cannot be undone.</p><label class=confirm-modal__confirm-row><input type=checkbox>I understand this action is irreversible</label><div class=confirm-modal__footer><button class="btn btn--ghost btn--sm">Cancel</button><button class="btn btn--danger btn--sm">'),Ke=d("<span class=spinner>"),Wt=d('<div class=modal-overlay><div class=modal-card role=dialog aria-modal=true aria-labelledby=remove-provider-modal-title style=max-width:440px><h2 class=modal-card__title id=remove-provider-modal-title>Remove provider</h2><p class=modal-card__desc>This will disconnect your email provider.</p><div class=confirm-modal__footer><button class="btn btn--ghost btn--sm">Cancel</button><button class="btn btn--danger btn--sm">');const Zt=e=>l(ve,{get children(){return l(_,{get when(){return e.openMenuId},children:t=>{const n=e.rules.find(a=>a.id===e.openMenuId);return n?(()=>{var a=Jt(),s=a.firstChild,o=s.nextSibling;return s.$$click=()=>e.onEdit(n),o.$$click=()=>e.onDelete(n),w(u=>{var v=`${e.menuPos.top}px`,h=`${e.menuPos.left}px`;return v!==u.e&&ke(a,"top",u.e=v),h!==u.t&&ke(a,"left",u.t=h),u},{e:void 0,t:void 0}),a})():null}})}}),Yt=e=>l(ve,{get children(){return l(_,{get when(){return e.target},get children(){var t=Ft(),n=t.firstChild,a=n.firstChild,s=a.nextSibling,o=s.firstChild,u=o.nextSibling,v=u.nextSibling,h=v.nextSibling,C=h.nextSibling,S=C.nextSibling;S.nextSibling;var x=s.nextSibling,T=x.firstChild,R=x.nextSibling,f=R.firstChild,k=f.nextSibling;return de(t,"click",e.onCancel,!0),n.$$click=m=>m.stopPropagation(),i(u,()=>e.target.metric_type==="tokens"?"token":"cost"),i(s,()=>Ie(e.target),h),i(s,()=>Oe[e.target.period]?.toLowerCase()??e.target.period,S),T.addEventListener("change",m=>e.onConfirmChange(m.currentTarget.checked)),de(f,"click",e.onCancel,!0),de(k,"click",e.onDelete,!0),i(k,(()=>{var m=J(()=>!!e.deleting);return()=>m()?Ke():"Delete rule"})()),w(()=>k.disabled=!e.confirmed||e.deleting),w(()=>T.checked=e.confirmed),t}})}}),Xt=e=>l(ve,{get children(){return l(_,{get when(){return e.open},get children(){var t=Wt(),n=t.firstChild,a=n.firstChild,s=a.nextSibling;s.firstChild;var o=s.nextSibling,u=o.firstChild,v=u.nextSibling;return de(t,"click",e.onCancel,!0),n.$$click=h=>h.stopPropagation(),i(s,l(_,{get when(){return e.hasEmailRules},get children(){return[" ","Email alerts won't be sent until you set up a new one."]}}),null),de(u,"click",e.onCancel,!0),de(v,"click",e.onRemove,!0),i(v,(()=>{var h=J(()=>!!e.removing);return()=>h()?Ke():"Remove"})()),w(()=>v.disabled=e.removing),t}})}});ie(["click"]);var Qt=d('<div class=limits-warning-banner role=alert><svg width=20 height=20 viewBox="0 0 24 24"fill=none stroke=currentColor stroke-width=2 stroke-linecap=round stroke-linejoin=round aria-hidden=true><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path><line x1=12 y1=9 x2=12 y2=13></line><line x1=12 y1=17 x2=12.01 y2=17></line></svg><span>One or more hard limits triggered. New proxy requests for this agent will be blocked until the usage resets in the next period.'),ei=d('<div class=limits-routing-cta><svg width=20 height=20 viewBox="0 0 24 24"fill=none stroke=currentColor stroke-width=2 stroke-linecap=round stroke-linejoin=round aria-hidden=true><circle cx=12 cy=12 r=10></circle><line x1=12 y1=16 x2=12 y2=12></line><line x1=12 y1=8 x2=12.01 y2=8></line></svg><div><strong>Enable routing to set hard limits</strong><p>Hard limits automatically block proxy requests when usage exceeds a threshold. Email alerts work without routing — only hard limits require it.'),ti=d("<div style=margin-bottom:var(--gap-lg)>"),ii=d("<div style=margin-top:var(--gap-lg)>"),ni=d('<div class=container--sm><div class=page-header><div><h1>Limits</h1><span class=breadcrumb> › Get notified or block requests when token or cost thresholds are exceeded</span></div><button class="btn btn--primary btn--sm">+ Create rule');const di=()=>{const e=Be(),t=()=>decodeURIComponent(e.agentName),[n,{refetch:a}]=me(()=>t(),g=>qe(g)),[s,{refetch:o}]=me(()=>t(),g=>Ve(g)),[u,{refetch:v}]=me(We),[h]=me(()=>t(),Ge),C=Ne.useSession(),[S,x]=p(!1),[T,R]=p(!1),[f,k]=p(null),[m,b]=p(null),[j,M]=p({top:0,left:0}),[D,A]=p(null),[H,I]=p(!1),[Z,N]=p(!1),[re,ae]=p(!1),[Y,G]=p(!1),X=()=>h()?.enabled??!1,Q=()=>!se()||!!u(),V=()=>b(null),ee=()=>V(),te=(g,y)=>{if(y.stopPropagation(),m()===g)V();else{const O=y.currentTarget.getBoundingClientRect();M({top:O.bottom+4,left:O.right}),b(g),setTimeout(()=>document.addEventListener("click",ee,{once:!0}),0)}};De(()=>document.removeEventListener("click",ee));const r=g=>{V(),k(g),x(!0)},$=async g=>{const y=f();try{y?(await Je(y.id,{...g}),B.success("Rule updated")):(await Ue({agent_name:t(),...g}),B.success("Rule created")),await a(),x(!1),k(null)}catch{}},P=g=>{V(),A(g),I(!1)},L=async()=>{const g=D();if(g){ae(!0);try{await Fe(g.id),await a(),B.success("Rule deleted")}catch{}finally{ae(!1)}A(null),I(!1)}},q=()=>{const g=n();return g?g.some(y=>y.action==="notify"||y.action==="both"):!1},oe=async()=>{G(!0);try{await Ye(),await v(),N(!1),B.success("Email provider removed")}catch{}finally{G(!1)}},ce=()=>{const g=n();return g?g.some(y=>(y.action==="block"||y.action==="both")&&(typeof y.is_active=="number"?!!y.is_active:y.is_active)&&Number(y.trigger_count)>0):!1};return(()=>{var g=ni(),y=g.firstChild,ue=y.firstChild,O=ue.firstChild,F=O.nextSibling,he=F.firstChild,_e=ue.nextSibling;return i(g,l(ze,{get children(){return[J(()=>pe()??t())," Limits - Manifest"]}}),y),i(g,l(je,{name:"description",get content(){return`Configure limits and alerts for ${pe()??t()}.`}}),y),i(F,()=>pe()??t(),he),_e.$$click=()=>{k(null),x(!0)},i(g,l(_,{get when(){return ce()},get children(){return Qt()}}),null),i(g,l(_,{get when(){return J(()=>!!(h()&&!X()))()&&!se()},get children(){return ei()}}),null),i(g,l(_,{get when(){return!se()},get children(){var K=ti();return i(K,l(tt,{get email(){return C().data?.user?.email??""}})),K}}),null),i(g,l(_,{get when(){return se()},get children(){return l(wt,{get emailProvider(){return u()},get loading(){return u.loading},onConfigured:v,onEdit:()=>R(!0),onRemove:()=>N(!0)})}}),null),i(g,l(jt,{get rules(){return n()},get loading(){return n.loading},get hasProvider(){return Q()},onToggleMenu:te}),null),i(g,l(_,{get when(){return J(()=>!s.loading)()&&(s()??[]).length>0},get children(){var K=ii();return i(K,l(Ut,{get logs(){return s()},loading:!1})),K}}),null),i(g,l(Zt,{get openMenuId(){return m()},get menuPos(){return j()},get rules(){return n()??[]},onEdit:r,onDelete:P}),null),i(g,l(Yt,{get target(){return D()},get confirmed(){return H()},get deleting(){return re()},onConfirmChange:I,onCancel:()=>{A(null),I(!1)},onDelete:L}),null),i(g,l(Xt,{get open(){return Z()},get hasEmailRules(){return q()},get removing(){return Y()},onCancel:()=>N(!1),onRemove:oe}),null),i(g,l(Et,{get open(){return S()},onClose:()=>{x(!1),k(null)},onSave:$,get hasProvider(){return Q()},get editData(){return J(()=>!!f())()?{metric_type:f().metric_type,threshold:Number(f().threshold),period:f().period,action:f().action??"notify"}:null}}),null),i(g,l(Ae,{get open(){return T()},get initialProvider(){return u()?.provider??"resend"},editMode:!0,get existingKeyPrefix(){return u()?.keyPrefix??null},get existingDomain(){return u()?.domain??null},get existingNotificationEmail(){return u()?.notificationEmail??null},onClose:()=>R(!1),onSaved:()=>v()}),null),g})()};ie(["click"]);export{di as default};