llm-simple-router 0.3.6 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -49
- package/dist/admin/constants.d.ts +1 -8
- package/dist/admin/constants.js +2 -8
- package/dist/admin/logs.js +18 -3
- package/dist/admin/router-keys.js +1 -2
- package/dist/cli.js +0 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.js +9 -0
- package/dist/db/index.d.ts +4 -4
- package/dist/db/index.js +2 -2
- package/dist/db/logs.d.ts +18 -33
- package/dist/db/logs.js +40 -17
- package/dist/db/metrics.d.ts +33 -0
- package/dist/db/metrics.js +7 -0
- package/dist/db/migrations/018_add_failover_field.sql +2 -0
- package/dist/db/retry-rules.d.ts +2 -2
- package/dist/db/retry-rules.js +26 -13
- package/dist/index.js +3 -5
- package/dist/monitor/request-tracker.d.ts +6 -0
- package/dist/monitor/request-tracker.js +23 -54
- package/dist/monitor/stream-extractor.d.ts +11 -0
- package/dist/monitor/stream-extractor.js +51 -0
- package/dist/proxy/anthropic.js +19 -32
- package/dist/proxy/log-helpers.d.ts +11 -4
- package/dist/proxy/log-helpers.js +5 -3
- package/dist/proxy/openai.js +18 -34
- package/dist/proxy/orchestrator.d.ts +52 -0
- package/dist/proxy/orchestrator.js +100 -0
- package/dist/proxy/proxy-core.d.ts +14 -26
- package/dist/proxy/proxy-core.js +40 -337
- package/dist/proxy/proxy-handler.d.ts +18 -0
- package/dist/proxy/proxy-handler.js +223 -0
- package/dist/proxy/proxy-logging.d.ts +28 -0
- package/dist/proxy/proxy-logging.js +122 -0
- package/dist/proxy/resilience.d.ts +63 -0
- package/dist/proxy/resilience.js +188 -0
- package/dist/proxy/scope.d.ts +18 -0
- package/dist/proxy/scope.js +37 -0
- package/dist/proxy/semaphore.d.ts +9 -2
- package/dist/proxy/semaphore.js +34 -7
- package/dist/proxy/stream-proxy.d.ts +7 -0
- package/dist/proxy/stream-proxy.js +263 -0
- package/dist/proxy/{upstream-call.d.ts → transport.d.ts} +25 -18
- package/dist/proxy/transport.js +128 -0
- package/dist/proxy/types.d.ts +58 -0
- package/dist/proxy/types.js +30 -0
- package/frontend-dist/assets/CardContent-CTnwqTdL.js +1 -0
- package/frontend-dist/assets/{CardHeader-BBKKDXEh.js → CardHeader-CfUeY7tk.js} +1 -1
- package/frontend-dist/assets/CardTitle-CWiDwWqd.js +1 -0
- package/frontend-dist/assets/Checkbox-BxNz70R_.js +1 -0
- package/frontend-dist/assets/CollapsibleTrigger-Uz1aGdtH.js +1 -0
- package/frontend-dist/assets/Collection-1EHC87X5.js +3 -0
- package/frontend-dist/assets/Dashboard-C3FL30UN.js +3 -0
- package/frontend-dist/assets/DialogTitle-CAOFxr83.js +1 -0
- package/frontend-dist/assets/Input-DRIid2C6.js +1 -0
- package/frontend-dist/assets/Label-UyNN2jyE.js +1 -0
- package/frontend-dist/assets/LogDetailDialog-8BT4vIlV.js +3 -0
- package/frontend-dist/assets/Login-CnzH6TdS.js +1 -0
- package/frontend-dist/assets/Logs-CbK8NB_X.js +1 -0
- package/frontend-dist/assets/ModelMappings-DeRFgsYG.js +1 -0
- package/frontend-dist/assets/Monitor-Dd80bdUn.js +1 -0
- package/frontend-dist/assets/PopperContent-B3fZao7v.js +1 -0
- package/frontend-dist/assets/Providers-B_DbV-_y.js +1 -0
- package/frontend-dist/assets/ProxyEnhancement-up1fnPzq.js +5 -0
- package/frontend-dist/assets/RetryRules-Dkuhjh0u.js +1 -0
- package/frontend-dist/assets/RouterKeys-CvMMAa4t.js +1 -0
- package/frontend-dist/assets/RovingFocusItem-X0bfqWWS.js +1 -0
- package/frontend-dist/assets/SelectValue-zO8t-tx1.js +1 -0
- package/frontend-dist/assets/Setup-ByT2ThOQ.js +1 -0
- package/frontend-dist/assets/Switch-BEMjVugO.js +1 -0
- package/frontend-dist/assets/TableHeader-DpHWSnxK.js +1 -0
- package/frontend-dist/assets/TabsTrigger-Db6RqsZc.js +1 -0
- package/frontend-dist/assets/VisuallyHidden-hs8pj8OP.js +1 -0
- package/frontend-dist/assets/VisuallyHiddenInput-1m0nNADN.js +1 -0
- package/frontend-dist/assets/alert-dialog-PP91kaO8.js +1 -0
- package/frontend-dist/assets/button-Dcc0gF5i.js +1 -0
- package/frontend-dist/assets/{client-BBW9-06a.js → client-DIIo9zPK.js} +2 -2
- package/frontend-dist/assets/{createLucideIcon-CCI4wMy0.js → createLucideIcon-DGZkBjcJ.js} +1 -1
- package/frontend-dist/assets/dialog-CxSyR-fN.js +1 -0
- package/frontend-dist/assets/format-CPdJtjZ5.js +1 -0
- package/frontend-dist/assets/index-BL-LAtac.css +1 -0
- package/frontend-dist/assets/index-CvT41fGL.js +1 -0
- package/frontend-dist/assets/lib-Bl0OuBjh.js +1 -0
- package/frontend-dist/assets/{ohash.D__AXeF1-Bj3Sy1wQ.js → ohash.D__AXeF1-B64hB831.js} +1 -1
- package/frontend-dist/assets/{useClipboard-XyA4kDfF.js → useClipboard-CWc1cTDo.js} +1 -1
- package/frontend-dist/assets/useForwardExpose-AkE0lq8y.js +1 -0
- package/frontend-dist/assets/useNonce-DGyPxdjq.js +1 -0
- package/frontend-dist/assets/x-BuUpx9Fr.js +1 -0
- package/frontend-dist/index.html +7 -7
- package/package.json +1 -1
- package/dist/admin/services.d.ts +0 -7
- package/dist/admin/services.js +0 -63
- package/dist/proxy/retry.d.ts +0 -43
- package/dist/proxy/retry.js +0 -121
- package/dist/proxy/upstream-call.js +0 -208
- package/frontend-dist/assets/CardContent-DKzAH8lX.js +0 -1
- package/frontend-dist/assets/CardTitle-BQtpsfYd.js +0 -1
- package/frontend-dist/assets/Checkbox-DhBbPKjw.js +0 -1
- package/frontend-dist/assets/CollapsibleTrigger-BC4bE5yr.js +0 -1
- package/frontend-dist/assets/Dashboard-3z77m9VQ.js +0 -3
- package/frontend-dist/assets/DialogTitle-Bh2A7j2j.js +0 -1
- package/frontend-dist/assets/Input-C5_w9X6Y.js +0 -1
- package/frontend-dist/assets/Label-9sUKofNb.js +0 -1
- package/frontend-dist/assets/Login-Dxo1j9ZV.js +0 -1
- package/frontend-dist/assets/Logs-KthJmRch.js +0 -3
- package/frontend-dist/assets/ModelMappings-Dci1SkBO.js +0 -1
- package/frontend-dist/assets/PopperContent-DGr-wo47.js +0 -1
- package/frontend-dist/assets/Providers-wZxNIXXh.js +0 -1
- package/frontend-dist/assets/ProxyEnhancement-CcvyXQNb.js +0 -1
- package/frontend-dist/assets/RetryRules-B9Cw-Ycd.js +0 -1
- package/frontend-dist/assets/RouterKeys-yZrj5YNm.js +0 -1
- package/frontend-dist/assets/RovingFocusItem-CvMnUs02.js +0 -1
- package/frontend-dist/assets/SelectValue-DhqRtJKk.js +0 -1
- package/frontend-dist/assets/Setup-DPk7lIZy.js +0 -1
- package/frontend-dist/assets/TableHeader-D9I1uQTp.js +0 -1
- package/frontend-dist/assets/TabsTrigger-D4xjbMaQ.js +0 -1
- package/frontend-dist/assets/VisuallyHiddenInput-Dr8wp-H0.js +0 -1
- package/frontend-dist/assets/alert-dialog-ChPy9vB2.js +0 -1
- package/frontend-dist/assets/badge-HGT44FNA.js +0 -3
- package/frontend-dist/assets/button-B3kgf-D2.js +0 -1
- package/frontend-dist/assets/dialog-BFhbK4vw.js +0 -1
- package/frontend-dist/assets/index-DSrFEJ7Y.css +0 -1
- package/frontend-dist/assets/index-SUCErp6B.js +0 -1
- package/frontend-dist/assets/lib-D-4ywYag.js +0 -1
- package/frontend-dist/assets/useForwardExpose-CIZH3-CG.js +0 -1
- package/frontend-dist/assets/x-CTNEl6Fz.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{B as e,F as t,K as n,L as r,S as i,Y as a,_ as o,a as s,b as c,f as l,g as u,gt as d,i as f,k as p,mt as m,ot as h,r as g,s as _,t as v,x as y,y as b,yt as x,z as S}from"./client-DIIo9zPK.js";import{t as C}from"./createLucideIcon-DGZkBjcJ.js";import{t as w}from"./x-BuUpx9Fr.js";import{n as T,r as E}from"./button-Dcc0gF5i.js";import{r as D,t as O}from"./lib-Bl0OuBjh.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var k=C(`activity`,[[`path`,{d:`M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2`,key:`169zse`}]]),A=C(`arrow-left-right`,[[`path`,{d:`M8 3 4 7l4 4`,key:`9rb6wj`}],[`path`,{d:`M4 7h16`,key:`6tx8e3`}],[`path`,{d:`m16 21 4-4-4-4`,key:`siv7j2`}],[`path`,{d:`M20 17H4`,key:`h6l3hr`}]]),j=C(`circle-check`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),M=C(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),N=C(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),P=C(`key-round`,[[`path`,{d:`M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z`,key:`1s6t7t`}],[`circle`,{cx:`16.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`w0ekpg`}]]),F=C(`layout-dashboard`,[[`rect`,{width:`7`,height:`9`,x:`3`,y:`3`,rx:`1`,key:`10lvy0`}],[`rect`,{width:`7`,height:`5`,x:`14`,y:`3`,rx:`1`,key:`16une8`}],[`rect`,{width:`7`,height:`9`,x:`14`,y:`12`,rx:`1`,key:`1hutg5`}],[`rect`,{width:`7`,height:`5`,x:`3`,y:`16`,rx:`1`,key:`ldoo1y`}]]),I=C(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),L=C(`log-out`,[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]),R=C(`octagon-x`,[[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`M2.586 16.726A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2h6.624a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586z`,key:`2d38gg`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),z=C(`refresh-ccw`,[[`path`,{d:`M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`14sxne`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16`,key:`1hlbsb`}],[`path`,{d:`M16 16h5v5`,key:`ccwih5`}]]),B=C(`server`,[[`rect`,{width:`20`,height:`8`,x:`2`,y:`2`,rx:`2`,ry:`2`,key:`ngkwjq`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,ry:`2`,key:`iecqi9`}],[`line`,{x1:`6`,x2:`6.01`,y1:`6`,y2:`6`,key:`16zg32`}],[`line`,{x1:`6`,x2:`6.01`,y1:`18`,y2:`18`,key:`nzw8ys`}]]),V=C(`sparkles`,[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]]),H=C(`triangle-alert`,[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),U={class:`w-56 bg-sidebar text-sidebar-foreground flex-shrink-0 flex flex-col`},W={class:`p-4 border-b border-sidebar-border`},G={class:`flex items-center gap-2`},K={class:`flex-1 p-2 space-y-1`},q={class:`p-3 border-t border-sidebar-border`},J=i({__name:`Sidebar`,setup(n){let i=[{path:`/`,label:`仪表盘`,icon:F},{path:`/providers`,label:`供应商`,icon:B},{path:`/mappings`,label:`模型映射`,icon:A},{path:`/router-keys`,label:`API 密钥`,icon:P},{path:`/retry-rules`,label:`重试规则`,icon:z},{path:`/proxy-enhancement`,label:`代理增强(实验性)`,icon:V},{path:`/monitor`,label:`实时监控`,icon:k},{path:`/logs`,label:`请求日志`,icon:M}],p=f(),h=s();function g(e){return e===`/`?p.path===`/`:p.path.startsWith(e)}async function _(){try{await v.logout()}finally{h.push(`/login`)}}return(n,s)=>{let f=S(`router-link`);return t(),b(`aside`,U,[u(`div`,W,[u(`div`,G,[s[0]||=u(`div`,{class:`w-8 h-8 bg-sidebar-primary rounded-lg flex items-center justify-center`},[u(`svg`,{class:`w-5 h-5 text-sidebar-primary-foreground`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`},[u(`path`,{"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z`})])],-1),s[1]||=u(`span`,{class:`font-semibold text-sm`},`LLM Router`,-1),y(m(D),{variant:`secondary`,class:`text-[10px] px-1.5 py-0 h-4 leading-none`},{default:a(()=>[c(`v`+x(m(`0.4.0`)),1)]),_:1})])]),u(`nav`,K,[(t(),b(l,null,r(i,n=>y(f,{key:n.path,to:n.path,class:d([`flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-colors`,g(n.path)?`bg-sidebar-accent text-sidebar-primary`:`text-sidebar-foreground hover:bg-sidebar-accent`])},{default:a(()=>[(t(),o(e(n.icon),{class:`w-4 h-4`})),c(` `+x(n.label),1)]),_:2},1032,[`to`,`class`])),64))]),u(`div`,q,[y(m(T),{variant:`ghost`,class:`w-full justify-start text-sidebar-foreground hover:text-sidebar-foreground hover:bg-sidebar-accent`,onClick:_},{default:a(()=>[y(m(L),{class:`w-4 h-4`}),s[2]||=c(` 登出 `,-1)]),_:1})])])}}}),Y=i({__name:`Sonner`,props:{id:{},invert:{type:Boolean},theme:{},position:{},closeButtonPosition:{},hotkey:{},richColors:{type:Boolean},expand:{type:Boolean},duration:{},gap:{},visibleToasts:{},closeButton:{type:Boolean},toastOptions:{},class:{},style:{},offset:{},mobileOffset:{},dir:{},swipeDirections:{},icons:{},containerAriaLabel:{}},setup(e){let n=e;return(e,r)=>(t(),o(m(O),p({class:m(E)(`toaster group`,n.class),style:{"--normal-bg":`var(--popover)`,"--normal-text":`var(--popover-foreground)`,"--normal-border":`var(--border)`,"--border-radius":`var(--radius)`}},n),{"success-icon":a(()=>[y(m(j),{class:`size-4`})]),"info-icon":a(()=>[y(m(N),{class:`size-4`})]),"warning-icon":a(()=>[y(m(H),{class:`size-4`})]),"error-icon":a(()=>[y(m(R),{class:`size-4`})]),"loading-icon":a(()=>[u(`div`,null,[y(m(I),{class:`size-4 animate-spin`})])]),"close-icon":a(()=>[y(m(w),{class:`size-4`})]),_:1},16,[`class`]))}}),X={key:0,class:`min-h-screen flex`},Z={class:`flex-1 overflow-auto bg-muted`},Q=_(i({__name:`App`,setup(e){let r=s(),i=f(),a=h(!1),c=[`/login`,`/setup`];async function d(){if(c.includes(i.path)){a.value=!1;return}try{await v.getStats(),a.value=!0}catch{a.value=!1,r.push(`/login`)}}return d(),n(()=>i.path,d),(e,n)=>{let r=S(`router-view`);return t(),b(l,null,[a.value?(t(),b(`div`,X,[y(J),u(`main`,Z,[y(r)])])):(t(),o(r,{key:1})),y(m(Y),{richColors:``,position:`top-center`})],64)}}}));Q.use(g),Q.mount(`#app`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{A as e,B as t,D as n,F as r,H as i,K as a,L as o,M as s,R as c,S as l,Y as u,_ as d,_t as f,b as p,f as m,g as h,gt as g,h as _,j as ee,k as v,mt as y,ot as b,q as x,v as S,vt as C,x as w,y as T,yt as E}from"./client-DIIo9zPK.js";import{D,b as O,i as k,r as A}from"./button-Dcc0gF5i.js";var j=l({__name:`Badge`,props:{asChild:{type:Boolean},as:{},variant:{},class:{type:[Boolean,null,String,Object,Array]}},setup(e){let t=e,n=O(t,`class`);return(i,a)=>(r(),d(y(k),v({"data-slot":`badge`,"data-variant":e.variant,class:y(A)(y(M)({variant:e.variant}),t.class)},y(n)),{default:u(()=>[c(i.$slots,`default`)]),_:3},16,[`data-variant`,`class`]))}}),M=D(`h-5 gap-1 rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium transition-all has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&>svg]:size-3! group/badge inline-flex w-fit shrink-0 items-center justify-center overflow-hidden whitespace-nowrap focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none`,{variants:{variant:{default:`bg-primary text-primary-foreground [a]:hover:bg-primary/80`,secondary:`bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80`,destructive:`bg-destructive/10 [a]:hover:bg-destructive/20 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 text-destructive dark:bg-destructive/20`,outline:`border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground`,ghost:`hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50`,link:`text-primary underline-offset-4 hover:underline`}},defaultVariants:{variant:`default`}}),N=1,P=new class{subscribers;toasts;dismissedToasts;constructor(){this.subscribers=[],this.toasts=[],this.dismissedToasts=new Set}subscribe=e=>(this.subscribers.push(e),()=>{let t=this.subscribers.indexOf(e);this.subscribers.splice(t,1)});publish=e=>{this.subscribers.forEach(t=>t(e))};addToast=e=>{this.publish(e),this.toasts=[...this.toasts,e]};create=e=>{let{message:t,...n}=e,r=typeof e.id==`number`||e.id&&e.id?.length>0?e.id:N++,i=this.toasts.find(e=>e.id===r),a=e.dismissible===void 0?!0:e.dismissible;return this.dismissedToasts.has(r)&&this.dismissedToasts.delete(r),i?this.toasts=this.toasts.map(n=>n.id===r?(this.publish({...n,...e,id:r,title:t}),{...n,...e,id:r,dismissible:a,title:t}):n):this.addToast({title:t,...n,dismissible:a,id:r}),r};dismiss=e=>(e?(this.dismissedToasts.add(e),requestAnimationFrame(()=>this.subscribers.forEach(t=>t({id:e,dismiss:!0})))):this.toasts.forEach(e=>{this.subscribers.forEach(t=>t({id:e.id,dismiss:!0}))}),e);message=(e,t)=>this.create({...t,message:e,type:`default`});error=(e,t)=>this.create({...t,type:`error`,message:e});success=(e,t)=>this.create({...t,type:`success`,message:e});info=(e,t)=>this.create({...t,type:`info`,message:e});warning=(e,t)=>this.create({...t,type:`warning`,message:e});loading=(e,t)=>this.create({...t,type:`loading`,message:e});promise=(e,t)=>{if(!t)return;let r;t.loading!==void 0&&(r=this.create({...t,promise:e,type:`loading`,message:t.loading,description:typeof t.description==`function`?void 0:t.description}));let i=Promise.resolve(e instanceof Function?e():e),a=r!==void 0,o,s=i.then(async e=>{if(o=[`resolve`,e],n(e))a=!1,this.create({id:r,type:`default`,message:e});else if(I(e)&&!e.ok){a=!1;let i=typeof t.error==`function`?await t.error(`HTTP error! status: ${e.status}`):t.error,o=typeof t.description==`function`?await t.description(`HTTP error! status: ${e.status}`):t.description,s=typeof i==`object`&&!n(i)?i:{message:i||``,id:r||``};this.create({id:r,type:`error`,description:o,...s})}else if(e instanceof Error){a=!1;let i=typeof t.error==`function`?await t.error(e):t.error,o=typeof t.description==`function`?await t.description(e):t.description,s=typeof i==`object`&&!n(i)?i:{message:i||``,id:r||``};this.create({id:r,type:`error`,description:o,...s})}else if(t.success!==void 0){a=!1;let i=typeof t.success==`function`?await t.success(e):t.success,o=typeof t.description==`function`?await t.description(e):t.description,s=typeof i==`object`&&!n(i)?i:{message:i||``,id:r||``};this.create({id:r,type:`success`,description:o,...s})}}).catch(async e=>{if(o=[`reject`,e],t.error!==void 0){a=!1;let i=typeof t.error==`function`?await t.error(e):t.error,o=typeof t.description==`function`?await t.description(e):t.description,s=typeof i==`object`&&!n(i)?i:{message:i||``,id:r||``};this.create({id:r,type:`error`,description:o,...s})}}).finally(()=>{a&&(this.dismiss(r),r=void 0),t.finally?.()}),c=()=>new Promise((e,t)=>s.then(()=>o[0]===`reject`?t(o[1]):e(o[1])).catch(t));return typeof r!=`string`&&typeof r!=`number`?{unwrap:c}:Object.assign(r,{unwrap:c})};custom=(e,t)=>{let n=t?.id||N++,r=this.toasts.find(e=>e.id===n),i=t?.dismissible===void 0?!0:t.dismissible;return this.dismissedToasts.has(n)&&this.dismissedToasts.delete(n),r?this.toasts=this.toasts.map(r=>r.id===n?(this.publish({...r,component:e,dismissible:i,id:n,...t}),{...r,component:e,dismissible:i,id:n,...t}):r):this.addToast({component:e,dismissible:i,id:n,...t}),n};getActiveToasts=()=>this.toasts.filter(e=>!this.dismissedToasts.has(e.id))};function F(e,t){let n=t?.id||N++;return P.create({message:e,id:n,type:`default`,...t}),n}var I=e=>e&&typeof e==`object`&&`ok`in e&&typeof e.ok==`boolean`&&`status`in e&&typeof e.status==`number`,L=Object.assign(F,{success:P.success,info:P.info,warning:P.warning,error:P.error,custom:P.custom,message:P.message,promise:P.promise,dismiss:P.dismiss,loading:P.loading},{getHistory:()=>P.toasts,getToasts:()=>P.getActiveToasts()});function R(e){return e.label!==void 0}var z=3,B=`24px`,V=`16px`,H=4e3,te=356,U=14,ne=45,re=200;function ie(){let e=b(!1);return x(()=>{let t=()=>{e.value=document.hidden};return document.addEventListener(`visibilitychange`,t),()=>window.removeEventListener(`visibilitychange`,t)}),{isDocumentHidden:e}}function W(...e){return e.filter(Boolean).join(` `)}function ae(e){let[t,n]=e.split(`-`),r=[];return t&&r.push(t),n&&r.push(n),r}function G(e,t){let n={};return[e,t].forEach((e,t)=>{let r=t===1,i=r?`--mobile-offset`:`--offset`,a=r?V:B;function o(e){[`top`,`right`,`bottom`,`left`].forEach(t=>{n[`${i}-${t}`]=typeof e==`number`?`${e}px`:e})}typeof e==`number`||typeof e==`string`?o(e):typeof e==`object`?[`top`,`right`,`bottom`,`left`].forEach(t=>{e[t]===void 0?n[`${i}-${t}`]=a:n[`${i}-${t}`]=typeof e[t]==`number`?`${e[t]}px`:e[t]}):o(a)}),n}var oe=[`data-rich-colors`,`data-styled`,`data-mounted`,`data-promise`,`data-swiped`,`data-removed`,`data-visible`,`data-y-position`,`data-x-position`,`data-index`,`data-front`,`data-swiping`,`data-dismissible`,`data-type`,`data-invert`,`data-swipe-out`,`data-swipe-direction`,`data-expanded`,`data-testid`],se=[`aria-label`,`data-disabled`,`data-close-button-position`],ce=l({__name:`Toast`,props:{toast:{},toasts:{},index:{},swipeDirections:{},expanded:{type:Boolean},invert:{type:Boolean},heights:{},gap:{},position:{},closeButtonPosition:{},visibleToasts:{},expandByDefault:{type:Boolean},closeButton:{type:Boolean},interacting:{type:Boolean},style:{},cancelButtonStyle:{},actionButtonStyle:{},duration:{},class:{},unstyled:{type:Boolean},descriptionClass:{},loadingIcon:{},classes:{},icons:{},closeButtonAriaLabel:{},defaultRichColors:{type:Boolean}},emits:[`update:heights`,`update:height`,`removeToast`],setup(n,{emit:i}){let o=n,l=i,u=b(null),w=b(null),D=b(!1),O=b(!1),k=b(!1),A=b(!1),j=b(!1),M=b(0),N=b(0),P=b(o.toast.duration||o.duration||H),F=b(null),I=b(null),L=_(()=>o.index===0),z=_(()=>o.index+1<=o.visibleToasts),B=_(()=>o.toast.type),V=_(()=>o.toast.dismissible!==!1),te=_(()=>o.toast.class||``),U=_(()=>o.descriptionClass||``),G=_(()=>{let e=o.toast.position||o.position,t=o.heights.filter(t=>t.position===e).findIndex(e=>e.toastId===o.toast.id);return t>=0?t:0}),ce=_(()=>{let e=o.toast.position||o.position;return o.heights.filter(t=>t.position===e).reduce((e,t,n)=>n>=G.value?e:e+t.height,0)}),K=_(()=>G.value*o.gap+ce.value||0),le=_(()=>o.toast.closeButton??o.closeButton),ue=_(()=>o.toast.duration||o.duration||H),q=b(0),J=b(0),Y=b(null),X=_(()=>o.position.split(`-`)),de=_(()=>X.value[0]),fe=_(()=>X.value[1]),pe=_(()=>typeof o.toast.title!=`string`),me=_(()=>typeof o.toast.description!=`string`),{isDocumentHidden:Z}=ie(),Q=_(()=>B.value&&B.value===`loading`);s(()=>{D.value=!0,P.value=ue.value}),x(async()=>{if(!D.value||!I.value)return;await e();let t=I.value,n=t.style.height;t.style.height=`auto`;let r=t.getBoundingClientRect().height;t.style.height=n,N.value=r,l(`update:height`,{toastId:o.toast.id,height:r,position:o.toast.position||o.position})});function $(){O.value=!0,M.value=K.value,setTimeout(()=>{l(`removeToast`,o.toast)},re)}function he(){if(Q.value||!V.value)return{};$(),o.toast.onDismiss?.(o.toast)}function ge(e){e.button!==2&&(Q.value||!V.value||(F.value=new Date,M.value=K.value,e.target.setPointerCapture(e.pointerId),e.target.tagName!==`BUTTON`&&(k.value=!0,Y.value={x:e.clientX,y:e.clientY})))}function _e(){if(A.value||!V.value)return;Y.value=null;let e=Number(I.value?.style.getPropertyValue(`--swipe-amount-x`).replace(`px`,``)||0),t=Number(I.value?.style.getPropertyValue(`--swipe-amount-y`).replace(`px`,``)||0),n=new Date().getTime()-(F.value?.getTime()||0),r=u.value===`x`?e:t,i=Math.abs(r)/n;if(Math.abs(r)>=ne||i>.11){M.value=K.value,o.toast.onDismiss?.(o.toast),u.value===`x`?w.value=e>0?`right`:`left`:w.value=t>0?`down`:`up`,$(),A.value=!0;return}else I.value?.style.setProperty(`--swipe-amount-x`,`0px`),I.value?.style.setProperty(`--swipe-amount-y`,`0px`);j.value=!1,k.value=!1,u.value=null}function ve(e){if(!Y.value||!V.value||(window?.getSelection()?.toString()?.length??!1))return;let t=e.clientY-Y.value.y,n=e.clientX-Y.value.x,r=o.swipeDirections??ae(o.position);!u.value&&(Math.abs(n)>1||Math.abs(t)>1)&&(u.value=Math.abs(n)>Math.abs(t)?`x`:`y`);let i={x:0,y:0},a=e=>1/(1.5+Math.abs(e)/20);if(u.value===`y`){if(r.includes(`top`)||r.includes(`bottom`))if(r.includes(`top`)&&t<0||r.includes(`bottom`)&&t>0)i.y=t;else{let e=t*a(t);i.y=Math.abs(e)<Math.abs(t)?e:t}}else if(u.value===`x`&&(r.includes(`left`)||r.includes(`right`)))if(r.includes(`left`)&&n<0||r.includes(`right`)&&n>0)i.x=n;else{let e=n*a(n);i.x=Math.abs(e)<Math.abs(n)?e:n}(Math.abs(i.x)>0||Math.abs(i.y)>0)&&(j.value=!0),I.value?.style.setProperty(`--swipe-amount-x`,`${i.x}px`),I.value?.style.setProperty(`--swipe-amount-y`,`${i.y}px`)}s(()=>{if(D.value=!0,!I.value)return;let e=I.value.getBoundingClientRect().height;N.value=e,l(`update:heights`,[{toastId:o.toast.id,height:e,position:o.toast.position},...o.heights])}),ee(()=>{I.value&&l(`removeToast`,o.toast)}),x(e=>{if(o.toast.promise&&B.value===`loading`||o.toast.duration===1/0||o.toast.type===`loading`)return;let t;o.expanded||o.interacting||Z.value?(()=>{if(J.value<q.value){let e=new Date().getTime()-q.value;P.value-=e}J.value=new Date().getTime()})():P.value!==1/0&&(q.value=new Date().getTime(),t=setTimeout(()=>{o.toast.onAutoClose?.(o.toast),$()},P.value)),e(()=>{clearTimeout(t)})}),a(()=>o.toast.delete,e=>{e!==void 0&&e&&($(),o.toast.onDismiss?.(o.toast))},{deep:!0});function ye(){k.value=!1,u.value=null,Y.value=null}return(e,n)=>(r(),T(`li`,{tabindex:`0`,ref_key:`toastRef`,ref:I,class:g(y(W)(o.class,te.value,e.classes?.toast,e.toast.classes?.toast,e.classes?.[B.value],e.toast?.classes?.[B.value])),"data-sonner-toast":``,"data-rich-colors":e.toast.richColors??e.defaultRichColors,"data-styled":!(e.toast.component||e.toast?.unstyled||e.unstyled),"data-mounted":D.value,"data-promise":!!e.toast.promise,"data-swiped":j.value,"data-removed":O.value,"data-visible":z.value,"data-y-position":de.value,"data-x-position":fe.value,"data-index":e.index,"data-front":L.value,"data-swiping":k.value,"data-dismissible":V.value,"data-type":B.value,"data-invert":e.toast.invert||e.invert,"data-swipe-out":A.value,"data-swipe-direction":w.value,"data-expanded":!!(e.expanded||e.expandByDefault&&D.value),"data-testid":e.toast.testId,style:C({"--index":e.index,"--toasts-before":e.index,"--z-index":e.toasts.length-e.index,"--offset":`${O.value?M.value:K.value}px`,"--initial-height":e.expandByDefault?`auto`:`${N.value}px`,...e.style,...o.toast.style}),onDragend:ye,onPointerdown:ge,onPointerup:_e,onPointermove:ve},[le.value&&!e.toast.component&&B.value!==`loading`?(r(),T(`button`,{key:0,"aria-label":e.closeButtonAriaLabel||`Close toast`,"data-disabled":Q.value,"data-close-button":`true`,"data-close-button-position":e.closeButtonPosition,class:g(y(W)(e.classes?.closeButton,e.toast?.classes?.closeButton)),onClick:he},[e.icons?.close?(r(),d(t(e.icons?.close),{key:0})):c(e.$slots,`close-icon`,{key:1})],10,se)):S(`v-if`,!0),e.toast.component?(r(),d(t(e.toast.component),v({key:1},e.toast.componentProps,{onCloseToast:he,isPaused:e.$props.expanded||e.$props.interacting||y(Z)}),null,16,[`isPaused`])):(r(),T(m,{key:2},[B.value!==`default`||e.toast.icon||e.toast.promise?(r(),T(`div`,{key:0,"data-icon":``,class:g(y(W)(e.classes?.icon,e.toast?.classes?.icon))},[e.toast.icon?(r(),d(t(e.toast.icon),{key:0})):(r(),T(m,{key:1},[B.value===`loading`?c(e.$slots,`loading-icon`,{key:0}):B.value===`success`?c(e.$slots,`success-icon`,{key:1}):B.value===`error`?c(e.$slots,`error-icon`,{key:2}):B.value===`warning`?c(e.$slots,`warning-icon`,{key:3}):B.value===`info`?c(e.$slots,`info-icon`,{key:4}):S(`v-if`,!0)],64))],2)):S(`v-if`,!0),h(`div`,{"data-content":``,class:g(y(W)(e.classes?.content,e.toast?.classes?.content))},[h(`div`,{"data-title":``,class:g(y(W)(e.classes?.title,e.toast.classes?.title))},[pe.value?(r(),d(t(e.toast.title),f(v({key:0},e.toast.componentProps)),null,16)):(r(),T(m,{key:1},[p(E(e.toast.title),1)],64))],2),e.toast.description?(r(),T(`div`,{key:0,"data-description":``,class:g(y(W)(e.descriptionClass,U.value,e.classes?.description,e.toast.classes?.description))},[me.value?(r(),d(t(e.toast.description),f(v({key:0},e.toast.componentProps)),null,16)):(r(),T(m,{key:1},[p(E(e.toast.description),1)],64))],2)):S(`v-if`,!0)],2),e.toast.cancel?(r(),T(`button`,{key:1,style:C(e.toast.cancelButtonStyle||e.cancelButtonStyle),class:g(y(W)(e.classes?.cancelButton,e.toast.classes?.cancelButton)),"data-button":``,"data-cancel":``,onClick:n[0]||=t=>{y(R)(e.toast.cancel)&&V.value&&(e.toast.cancel.onClick?.(t),$())}},E(y(R)(e.toast.cancel)?e.toast.cancel?.label:e.toast.cancel),7)):S(`v-if`,!0),e.toast.action?(r(),T(`button`,{key:2,style:C(e.toast.actionButtonStyle||e.actionButtonStyle),class:g(y(W)(e.classes?.actionButton,e.toast.classes?.actionButton)),"data-button":``,"data-action":``,onClick:n[1]||=t=>{y(R)(e.toast.action)&&(e.toast.action.onClick?.(t),!t.defaultPrevented&&$())}},E(y(R)(e.toast.action)?e.toast.action?.label:e.toast.action),7)):S(`v-if`,!0)],64))],46,oe))}}),K=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},le={},ue={xmlns:`http://www.w3.org/2000/svg`,width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stoke-width":`1.5`,"stroke-linecap":`round`,"stroke-linejoin":`round`};function q(e,t){return r(),T(`svg`,ue,t[0]||=[h(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`},null,-1),h(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`},null,-1)])}var J=K(le,[[`render`,q]]),Y=[`data-visible`],X={class:`sonner-spinner`},de=l({__name:`Loader`,props:{visible:{type:Boolean}},setup(e){let t=Array(12).fill(0);return(e,n)=>(r(),T(`div`,{class:`sonner-loading-wrapper`,"data-visible":e.visible},[h(`div`,X,[(r(!0),T(m,null,o(y(t),e=>(r(),T(`div`,{key:`spinner-bar-${e}`,class:`sonner-loading-bar`}))),128))])],8,Y))}}),fe={},pe={xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 20 20`,fill:`currentColor`,height:`20`,width:`20`};function me(e,t){return r(),T(`svg`,pe,t[0]||=[h(`path`,{"fill-rule":`evenodd`,d:`M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z`,"clip-rule":`evenodd`},null,-1)])}var Z=K(fe,[[`render`,me]]),Q={},$={xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 20 20`,fill:`currentColor`,height:`20`,width:`20`};function he(e,t){return r(),T(`svg`,$,t[0]||=[h(`path`,{"fill-rule":`evenodd`,d:`M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z`,"clip-rule":`evenodd`},null,-1)])}var ge=K(Q,[[`render`,he]]),_e={},ve={xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`currentColor`,height:`20`,width:`20`};function ye(e,t){return r(),T(`svg`,ve,t[0]||=[h(`path`,{"fill-rule":`evenodd`,d:`M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003zM12 8.25a.75.75 0 01.75.75v3.75a.75.75 0 01-1.5 0V9a.75.75 0 01.75-.75zm0 8.25a.75.75 0 100-1.5.75.75 0 000 1.5z`,"clip-rule":`evenodd`},null,-1)])}var be=K(_e,[[`render`,ye]]),xe={},Se={xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 20 20`,fill:`currentColor`,height:`20`,width:`20`};function Ce(e,t){return r(),T(`svg`,Se,t[0]||=[h(`path`,{"fill-rule":`evenodd`,d:`M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z`,"clip-rule":`evenodd`},null,-1)])}var we=K(xe,[[`render`,Ce]]),Te=[`aria-label`],Ee=[`data-sonner-theme`,`dir`,`data-theme`,`data-rich-colors`,`data-y-position`,`data-x-position`],De=typeof window<`u`&&typeof document<`u`;function Oe(){if(typeof window>`u`||typeof document>`u`)return`ltr`;let e=document.documentElement.getAttribute(`dir`);return e===`auto`||!e?window.getComputedStyle(document.documentElement).direction:e}var ke=l({name:`Toaster`,inheritAttrs:!1,__name:`Toaster`,props:{id:{},invert:{type:Boolean,default:!1},theme:{default:`light`},position:{default:`bottom-right`},closeButtonPosition:{default:`top-left`},hotkey:{default:()=>[`altKey`,`KeyT`]},richColors:{type:Boolean,default:!1},expand:{type:Boolean,default:!1},duration:{},gap:{default:U},visibleToasts:{default:z},closeButton:{type:Boolean,default:!1},toastOptions:{default:()=>({})},class:{default:``},style:{},offset:{default:B},mobileOffset:{default:V},dir:{default:`auto`},swipeDirections:{},icons:{},containerAriaLabel:{default:`Notifications`}},setup(t){let n=t,a=i(),s=b([]),l=_(()=>n.id?s.value.filter(e=>e.toasterId===n.id):s.value.filter(e=>!e.toasterId));function f(e,t){return l.value.filter(n=>!n.position&&t===0||n.position===e)}let p=_(()=>{let e=l.value.filter(e=>e.position).map(e=>e.position);return e.length>0?Array.from(new Set([n.position].concat(e))):[n.position]}),ee=_(()=>{let e={};return p.value.forEach(t=>{e[t]=s.value.filter(e=>e.position===t)}),e}),E=b([]),D=b({}),O=b(!1);x(()=>{p.value.forEach(e=>{e in D.value||(D.value[e]=!1)})});let k=b(n.theme===`system`?typeof window<`u`&&window.matchMedia&&window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`:n.theme),A=b(null),j=b(null),M=b(!1),N=n.hotkey.join(`+`).replace(/Key/g,``).replace(/Digit/g,``);function F(e){s.value.find(t=>t.id===e.id)?.delete||P.dismiss(e.id),s.value=s.value.filter(({id:t})=>t!==e.id),setTimeout(()=>{s.value.find(t=>t.id===e.id)||(E.value=E.value.filter(t=>t.toastId!==e.id))},re+50)}function I(e){M.value&&!e.currentTarget?.contains?.(e.relatedTarget)&&(M.value=!1,j.value&&=(j.value.focus({preventScroll:!0}),null))}function L(e){e.target instanceof HTMLElement&&e.target.dataset.dismissible===`false`||M.value||(M.value=!0,j.value=e.relatedTarget)}function R(e){e.target&&e.target instanceof HTMLElement&&e.target.dataset.dismissible===`false`||(O.value=!0)}x(t=>{t(P.subscribe(t=>{if(t.dismiss){requestAnimationFrame(()=>{s.value=s.value.map(e=>e.id===t.id?{...e,delete:!0}:e)});return}e(()=>{let e=s.value.findIndex(e=>e.id===t.id);e===-1?s.value=[t,...s.value]:s.value=[...s.value.slice(0,e),{...s.value[e],...t},...s.value.slice(e+1)]})}))}),x(e=>{if(typeof window>`u`)return;if(n.theme!==`system`){k.value=n.theme;return}let t=window.matchMedia(`(prefers-color-scheme: dark)`),r=e=>{k.value=e?`dark`:`light`};r(t.matches);let i=e=>{r(e.matches)};try{t.addEventListener(`change`,i)}catch{t.addListener(i)}e(()=>{try{t.removeEventListener(`change`,i)}catch{t.removeListener(i)}})}),x(()=>{A.value&&j.value&&(j.value.focus({preventScroll:!0}),j.value=null,M.value=!1)}),x(()=>{s.value.length<=1&&Object.keys(D.value).forEach(e=>{D.value[e]=!1})}),x(e=>{function t(e){let t=n.hotkey.every(t=>e[t]||e.code===t),r=Array.isArray(A.value)?A.value[0]:A.value;t&&(p.value.forEach(e=>{D.value[e]=!0}),r?.focus());let i=document.activeElement===A.value||r?.contains(document.activeElement);e.code===`Escape`&&i&&p.value.forEach(e=>{D.value[e]=!1})}De&&(document.addEventListener(`keydown`,t),e(()=>{document.removeEventListener(`keydown`,t)}))});function z(e){let t=e.currentTarget,n=t.getAttribute(`data-y-position`)+`-`+t.getAttribute(`data-x-position`);D.value[n]=!0}function B(e){if(!O.value){let t=e.currentTarget,n=t.getAttribute(`data-y-position`)+`-`+t.getAttribute(`data-x-position`);D.value[n]=!1}}function V(){Object.keys(D.value).forEach(e=>{D.value[e]=!1})}function H(){O.value=!1}function U(e){E.value=e}function ne(e){let t=E.value.findIndex(t=>t.toastId===e.toastId);if(t!==-1)E.value[t]=e;else{let t=E.value.findIndex(t=>t.position===e.position);t===-1?E.value.unshift(e):E.value.splice(t,0,e)}}return(e,t)=>(r(),T(m,null,[S(` Remove item from normal navigation flow, only available via hotkey `),h(`section`,{"aria-label":`${e.containerAriaLabel} ${y(N)}`,tabIndex:-1,"aria-live":`polite`,"aria-relevant":`additions text`,"aria-atomic":`false`},[(r(!0),T(m,null,o(p.value,(t,i)=>(r(),T(`ol`,v({key:t,ref_for:!0,ref_key:`listRef`,ref:A,"data-sonner-toaster":``,"data-sonner-theme":k.value,class:n.class,dir:e.dir===`auto`?Oe():e.dir,tabIndex:-1,"data-theme":e.theme,"data-rich-colors":e.richColors,"data-y-position":t.split(`-`)[0],"data-x-position":t.split(`-`)[1],style:{"--front-toast-height":`${E.value[0]?.height||0}px`,"--width":`${y(te)}px`,"--gap":`${e.gap}px`,...e.style,...y(a).style,...y(G)(e.offset,e.mobileOffset)}},{ref_for:!0},e.$attrs,{onBlur:I,onFocus:L,onMouseenter:z,onMousemove:z,onMouseleave:B,onDragend:V,onPointerdown:R,onPointerup:H}),[(r(!0),T(m,null,o(f(t,i),(i,a)=>(r(),d(ce,{key:i.id,heights:E.value,icons:e.icons,index:a,toast:i,defaultRichColors:e.richColors,duration:e.toastOptions?.duration??e.duration,class:g(e.toastOptions?.class??``),descriptionClass:e.toastOptions?.descriptionClass,invert:e.invert,visibleToasts:e.visibleToasts,closeButton:e.toastOptions?.closeButton??e.closeButton,interacting:O.value,position:t,closeButtonPosition:e.toastOptions?.closeButtonPosition??e.closeButtonPosition,style:C(e.toastOptions?.style),unstyled:e.toastOptions?.unstyled,classes:e.toastOptions?.classes,cancelButtonStyle:e.toastOptions?.cancelButtonStyle,actionButtonStyle:e.toastOptions?.actionButtonStyle,"close-button-aria-label":e.toastOptions?.closeButtonAriaLabel,toasts:ee.value[t],expandByDefault:e.expand,gap:e.gap,expanded:D.value[t]||!1,swipeDirections:n.swipeDirections,"onUpdate:heights":U,"onUpdate:height":ne,onRemoveToast:F},{"close-icon":u(()=>[c(e.$slots,`close-icon`,{},()=>[w(J)])]),"loading-icon":u(()=>[c(e.$slots,`loading-icon`,{},()=>[w(de,{visible:i.type===`loading`},null,8,[`visible`])])]),"success-icon":u(()=>[c(e.$slots,`success-icon`,{},()=>[w(Z)])]),"error-icon":u(()=>[c(e.$slots,`error-icon`,{},()=>[w(we)])]),"warning-icon":u(()=>[c(e.$slots,`warning-icon`,{},()=>[w(be)])]),"info-icon":u(()=>[c(e.$slots,`info-icon`,{},()=>[w(ge)])]),_:2},1032,[`heights`,`icons`,`index`,`toast`,`defaultRichColors`,`duration`,`class`,`descriptionClass`,`invert`,`visibleToasts`,`closeButton`,`interacting`,`position`,`closeButtonPosition`,`style`,`unstyled`,`classes`,`cancelButtonStyle`,`actionButtonStyle`,`close-button-aria-label`,`toasts`,`expandByDefault`,`gap`,`expanded`,`swipeDirections`]))),128))],16,Ee))),128))],8,Te)],2112))}});export{L as n,j as r,ke as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./createLucideIcon-
|
|
1
|
+
import{t as e}from"./createLucideIcon-DGZkBjcJ.js";var t=e(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]);function n(e){return typeof e==`string`?`'${e}'`:new r().serialize(e)}var r=function(){class e{#e=new Map;compare(e,t){let n=typeof e,r=typeof t;return n===`string`&&r===`string`?e.localeCompare(t):n===`number`&&r===`number`?e-t:String.prototype.localeCompare.call(this.serialize(e,!0),this.serialize(t,!0))}serialize(e,t){if(e===null)return`null`;switch(typeof e){case`string`:return t?e:`'${e}'`;case`bigint`:return`${e}n`;case`object`:return this.$object(e);case`function`:return this.$function(e)}return String(e)}serializeObject(e){let t=Object.prototype.toString.call(e);if(t!==`[object Object]`)return this.serializeBuiltInType(t.length<10?`unknown:${t}`:t.slice(8,-1),e);let n=e.constructor,r=n===Object||n===void 0?``:n.name;if(r!==``&&globalThis[r]===n)return this.serializeBuiltInType(r,e);if(typeof e.toJSON==`function`){let t=e.toJSON();return r+(typeof t==`object`&&t?this.$object(t):`(${this.serialize(t)})`)}return this.serializeObjectEntries(r,Object.entries(e))}serializeBuiltInType(e,t){let n=this[`$`+e];if(n)return n.call(this,t);if(typeof t?.entries==`function`)return this.serializeObjectEntries(e,t.entries());throw Error(`Cannot serialize ${e}`)}serializeObjectEntries(e,t){let n=Array.from(t).sort((e,t)=>this.compare(e[0],t[0])),r=`${e}{`;for(let e=0;e<n.length;e++){let[t,i]=n[e];r+=`${this.serialize(t,!0)}:${this.serialize(i)}`,e<n.length-1&&(r+=`,`)}return r+`}`}$object(e){let t=this.#e.get(e);return t===void 0&&(this.#e.set(e,`#${this.#e.size}`),t=this.serializeObject(e),this.#e.set(e,t)),t}$function(e){let t=Function.prototype.toString.call(e);return t.slice(-15)===`[native code] }`?`${e.name||``}()[native]`:`${e.name}(${e.length})${t.replace(/\s*\n\s*/g,``)}`}$Array(e){let t=`[`;for(let n=0;n<e.length;n++)t+=this.serialize(e[n]),n<e.length-1&&(t+=`,`);return t+`]`}$Date(e){try{return`Date(${e.toISOString()})`}catch{return`Date(null)`}}$ArrayBuffer(e){return`ArrayBuffer[${new Uint8Array(e).join(`,`)}]`}$Set(e){return`Set${this.$Array(Array.from(e).sort((e,t)=>this.compare(e,t)))}`}$Map(e){return this.serializeObjectEntries(`Map`,e.entries())}}for(let t of[`Error`,`RegExp`,`URL`])e.prototype[`$`+t]=function(e){return`${t}(${e})`};for(let t of[`Int8Array`,`Uint8Array`,`Uint8ClampedArray`,`Int16Array`,`Uint16Array`,`Int32Array`,`Uint32Array`,`Float32Array`,`Float64Array`])e.prototype[`$`+t]=function(e){return`${t}[${e.join(`,`)}]`};for(let t of[`BigInt64Array`,`BigUint64Array`])e.prototype[`$`+t]=function(e){return`${t}[${e.join(`n,`)}${e.length>0?`n`:``}]`};return e}();function i(e,t){return e===t||n(e)===n(t)}export{t as n,i as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ot as e}from"./client-
|
|
1
|
+
import{ot as e}from"./client-DIIo9zPK.js";var t=2e3;function n(){let n=e(!1);async function i(e){try{return navigator.clipboard?.writeText?await navigator.clipboard.writeText(e):r(e),n.value=!0,setTimeout(()=>{n.value=!1},t),!0}catch{try{return r(e),n.value=!0,setTimeout(()=>{n.value=!1},t),!0}catch{return!1}}}return{copied:n,copy:i}}function r(e){let t=document.createElement(`textarea`);if(t.value=e,t.style.cssText=`position:fixed;left:-9999px;opacity:0`,document.body.appendChild(t),t.select(),!document.execCommand(`copy`))throw Error(`execCommand copy failed`);document.body.removeChild(t)}export{n as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{C as e,P as t,h as n,ot as r,pt as i}from"./client-DIIo9zPK.js";import{l as a}from"./button-Dcc0gF5i.js";function o(){let o=e(),s=r(),c=n(()=>l());t(()=>{c.value!==l()&&i(s)});function l(){return s.value&&`$el`in s.value&&[`#text`,`#comment`].includes(s.value.$el.nodeName)?s.value.$el.nextElementSibling:a(s)}let u=Object.assign({},o.exposed),d={};for(let e in o.props)Object.defineProperty(d,e,{enumerable:!0,configurable:!0,get:()=>o.props[e]});if(Object.keys(u).length>0)for(let e in u)Object.defineProperty(d,e,{enumerable:!0,configurable:!0,get:()=>u[e]});Object.defineProperty(d,`$el`,{enumerable:!0,configurable:!0,get:()=>o.vnode.el}),o.exposed=d;function f(e){if(s.value=e,e&&(Object.defineProperty(d,`$el`,{enumerable:!0,configurable:!0,get:()=>e instanceof Element?e:e.$el}),!(e instanceof Element)&&!Object.hasOwn(e,`$el`))){let t=e.$.exposed,n=Object.assign({},d);for(let e in t)Object.defineProperty(n,e,{enumerable:!0,configurable:!0,get:()=>t[e]});o.exposed=n}}return{forwardRef:f,currentRef:s,currentElement:c}}export{o as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{h as e,ot as t}from"./client-DIIo9zPK.js";import{v as n}from"./Collection-1EHC87X5.js";function r(e,t=-1/0,n=1/0){return Math.min(n,Math.max(t,e))}function i(r){let i=n({nonce:t()});return e(()=>r?.value||i.nonce?.value)}export{r as n,i as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./createLucideIcon-DGZkBjcJ.js";var t=e(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]);export{t};
|
package/frontend-dist/index.html
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
<link rel="icon" type="image/svg+xml" href="/admin/favicon.svg" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>frontend</title>
|
|
8
|
-
<script type="module" crossorigin src="/admin/assets/index-
|
|
9
|
-
<link rel="modulepreload" crossorigin href="/admin/assets/client-
|
|
10
|
-
<link rel="modulepreload" crossorigin href="/admin/assets/button-
|
|
11
|
-
<link rel="modulepreload" crossorigin href="/admin/assets/createLucideIcon-
|
|
12
|
-
<link rel="modulepreload" crossorigin href="/admin/assets/x-
|
|
13
|
-
<link rel="modulepreload" crossorigin href="/admin/assets/lib-
|
|
14
|
-
<link rel="stylesheet" crossorigin href="/admin/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/admin/assets/index-CvT41fGL.js"></script>
|
|
9
|
+
<link rel="modulepreload" crossorigin href="/admin/assets/client-DIIo9zPK.js">
|
|
10
|
+
<link rel="modulepreload" crossorigin href="/admin/assets/button-Dcc0gF5i.js">
|
|
11
|
+
<link rel="modulepreload" crossorigin href="/admin/assets/createLucideIcon-DGZkBjcJ.js">
|
|
12
|
+
<link rel="modulepreload" crossorigin href="/admin/assets/x-BuUpx9Fr.js">
|
|
13
|
+
<link rel="modulepreload" crossorigin href="/admin/assets/lib-Bl0OuBjh.js">
|
|
14
|
+
<link rel="stylesheet" crossorigin href="/admin/assets/index-BL-LAtac.css">
|
|
15
15
|
</head>
|
|
16
16
|
<body>
|
|
17
17
|
<div id="app"></div>
|
package/package.json
CHANGED
package/dist/admin/services.d.ts
DELETED
package/dist/admin/services.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { getAllBackendServices, getBackendServiceById, createBackendService, updateBackendService, deleteBackendService } from "../db/index.js";
|
|
2
|
-
import { decrypt, encrypt } from "../utils/crypto.js";
|
|
3
|
-
function maskApiKey(encrypted, key) {
|
|
4
|
-
const decrypted = decrypt(encrypted, key);
|
|
5
|
-
if (decrypted.length <= 8)
|
|
6
|
-
return "****";
|
|
7
|
-
return `${decrypted.slice(0, 4)}...${decrypted.slice(-4)}`;
|
|
8
|
-
}
|
|
9
|
-
export const adminServiceRoutes = (app, options, done) => {
|
|
10
|
-
const { db, encryptionKey } = options;
|
|
11
|
-
app.get("/admin/api/services", async (_request, reply) => {
|
|
12
|
-
const services = getAllBackendServices(db);
|
|
13
|
-
return reply.send(services.map((s) => ({
|
|
14
|
-
...s,
|
|
15
|
-
api_key: maskApiKey(s.api_key, encryptionKey),
|
|
16
|
-
})));
|
|
17
|
-
});
|
|
18
|
-
app.post("/admin/api/services", async (request, reply) => {
|
|
19
|
-
const body = request.body;
|
|
20
|
-
if (!body.name || !body.api_type || !body.base_url || !body.api_key) {
|
|
21
|
-
return reply.code(400).send({ error: { message: "Missing required fields: name, api_type, base_url, api_key" } });
|
|
22
|
-
}
|
|
23
|
-
if (!["openai", "anthropic"].includes(body.api_type)) {
|
|
24
|
-
return reply.code(400).send({ error: { message: "api_type must be 'openai' or 'anthropic'" } });
|
|
25
|
-
}
|
|
26
|
-
const encryptedKey = encrypt(body.api_key, encryptionKey);
|
|
27
|
-
const id = createBackendService(db, {
|
|
28
|
-
name: body.name,
|
|
29
|
-
api_type: body.api_type,
|
|
30
|
-
base_url: body.base_url,
|
|
31
|
-
api_key: encryptedKey,
|
|
32
|
-
is_active: body.is_active ?? 1,
|
|
33
|
-
});
|
|
34
|
-
return reply.code(201).send({ id });
|
|
35
|
-
});
|
|
36
|
-
app.put("/admin/api/services/:id", async (request, reply) => {
|
|
37
|
-
const { id } = request.params;
|
|
38
|
-
const existing = getBackendServiceById(db, id);
|
|
39
|
-
if (!existing) {
|
|
40
|
-
return reply.code(404).send({ error: { message: "Service not found" } });
|
|
41
|
-
}
|
|
42
|
-
const body = request.body;
|
|
43
|
-
const fields = {};
|
|
44
|
-
if (body.name !== undefined)
|
|
45
|
-
fields.name = body.name;
|
|
46
|
-
if (body.api_type !== undefined)
|
|
47
|
-
fields.api_type = body.api_type;
|
|
48
|
-
if (body.base_url !== undefined)
|
|
49
|
-
fields.base_url = body.base_url;
|
|
50
|
-
if (body.is_active !== undefined)
|
|
51
|
-
fields.is_active = body.is_active;
|
|
52
|
-
if (body.api_key)
|
|
53
|
-
fields.api_key = encrypt(body.api_key, encryptionKey);
|
|
54
|
-
updateBackendService(db, id, fields);
|
|
55
|
-
return reply.send({ success: true });
|
|
56
|
-
});
|
|
57
|
-
app.delete("/admin/api/services/:id", async (request, reply) => {
|
|
58
|
-
const { id } = request.params;
|
|
59
|
-
deleteBackendService(db, id);
|
|
60
|
-
return reply.send({ success: true });
|
|
61
|
-
});
|
|
62
|
-
done();
|
|
63
|
-
};
|
package/dist/proxy/retry.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { ProxyResult, StreamProxyResult } from "./proxy-core.js";
|
|
2
|
-
import type { FastifyReply } from "fastify";
|
|
3
|
-
import type { RetryRuleMatcher } from "./retry-rules.js";
|
|
4
|
-
export interface RetryConfig {
|
|
5
|
-
maxRetries: number;
|
|
6
|
-
baseDelayMs: number;
|
|
7
|
-
ruleMatcher?: RetryRuleMatcher;
|
|
8
|
-
}
|
|
9
|
-
export interface Attempt {
|
|
10
|
-
attemptIndex: number;
|
|
11
|
-
statusCode: number | null;
|
|
12
|
-
error: string | null;
|
|
13
|
-
latencyMs: number;
|
|
14
|
-
responseBody: string | null;
|
|
15
|
-
}
|
|
16
|
-
export interface RetryResult<T> {
|
|
17
|
-
result: T;
|
|
18
|
-
attempts: Attempt[];
|
|
19
|
-
}
|
|
20
|
-
export type ProxyFn<T = ProxyResult | StreamProxyResult> = () => Promise<T>;
|
|
21
|
-
export interface RetryStrategy {
|
|
22
|
-
getDelay(attempt: number): number;
|
|
23
|
-
}
|
|
24
|
-
export declare class FixedIntervalStrategy implements RetryStrategy {
|
|
25
|
-
private delayMs;
|
|
26
|
-
constructor(delayMs: number);
|
|
27
|
-
getDelay(): number;
|
|
28
|
-
}
|
|
29
|
-
export declare class ExponentialBackoffStrategy implements RetryStrategy {
|
|
30
|
-
private baseMs;
|
|
31
|
-
private capMs;
|
|
32
|
-
constructor(baseMs: number, capMs: number);
|
|
33
|
-
getDelay(attempt: number): number;
|
|
34
|
-
}
|
|
35
|
-
export declare function createStrategy(rule: {
|
|
36
|
-
retry_strategy: string;
|
|
37
|
-
retry_delay_ms: number;
|
|
38
|
-
max_delay_ms: number;
|
|
39
|
-
}): RetryStrategy;
|
|
40
|
-
export declare function buildRetryConfig(maxRetries: number, baseDelayMs: number, ruleMatcher?: RetryRuleMatcher): RetryConfig;
|
|
41
|
-
export declare function isRetryableResult(statusCode: number, body?: string, config?: RetryConfig): boolean;
|
|
42
|
-
export declare function isRetryableThrow(err: unknown): boolean;
|
|
43
|
-
export declare function retryableCall<T extends ProxyResult | StreamProxyResult>(fn: ProxyFn<T>, config: RetryConfig, reply?: FastifyReply): Promise<RetryResult<T>>;
|
package/dist/proxy/retry.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
export class FixedIntervalStrategy {
|
|
2
|
-
delayMs;
|
|
3
|
-
constructor(delayMs) {
|
|
4
|
-
this.delayMs = delayMs;
|
|
5
|
-
}
|
|
6
|
-
getDelay() { return this.delayMs; }
|
|
7
|
-
}
|
|
8
|
-
const EXPONENTIAL_BASE = 2;
|
|
9
|
-
export class ExponentialBackoffStrategy {
|
|
10
|
-
baseMs;
|
|
11
|
-
capMs;
|
|
12
|
-
constructor(baseMs, capMs) {
|
|
13
|
-
this.baseMs = baseMs;
|
|
14
|
-
this.capMs = capMs;
|
|
15
|
-
}
|
|
16
|
-
getDelay(attempt) {
|
|
17
|
-
return Math.min(this.baseMs * EXPONENTIAL_BASE ** attempt, this.capMs);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export function createStrategy(rule) {
|
|
21
|
-
if (rule.retry_strategy === "fixed")
|
|
22
|
-
return new FixedIntervalStrategy(rule.retry_delay_ms);
|
|
23
|
-
return new ExponentialBackoffStrategy(rule.retry_delay_ms, rule.max_delay_ms);
|
|
24
|
-
}
|
|
25
|
-
// ---------- Constants ----------
|
|
26
|
-
const RETRYABLE_THROW_CODES = new Set(["ETIMEDOUT", "ECONNRESET", "ECONNREFUSED"]);
|
|
27
|
-
const HTTP_BAD_REQUEST = 400;
|
|
28
|
-
const HTTP_TOO_MANY_REQUESTS = 429;
|
|
29
|
-
const MS_PER_SECOND = 1000;
|
|
30
|
-
// ---------- Shared helpers ----------
|
|
31
|
-
export function buildRetryConfig(maxRetries, baseDelayMs, ruleMatcher) {
|
|
32
|
-
return {
|
|
33
|
-
maxRetries,
|
|
34
|
-
baseDelayMs,
|
|
35
|
-
ruleMatcher,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
// ---------- Predicates ----------
|
|
39
|
-
export function isRetryableResult(statusCode, body, config) {
|
|
40
|
-
if (body && config?.ruleMatcher?.test(statusCode, body))
|
|
41
|
-
return true;
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
export function isRetryableThrow(err) {
|
|
45
|
-
if (err && typeof err === "object" && "code" in err) {
|
|
46
|
-
return RETRYABLE_THROW_CODES.has(err.code ?? "");
|
|
47
|
-
}
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
// ---------- Internal helpers ----------
|
|
51
|
-
function sleep(ms) {
|
|
52
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
53
|
-
}
|
|
54
|
-
function parseRetryAfter(headers) {
|
|
55
|
-
if (!headers)
|
|
56
|
-
return null;
|
|
57
|
-
const val = headers["retry-after"] ?? headers["Retry-After"];
|
|
58
|
-
if (!val)
|
|
59
|
-
return null;
|
|
60
|
-
const seconds = parseInt(val, 10);
|
|
61
|
-
return isNaN(seconds) ? null : seconds * MS_PER_SECOND;
|
|
62
|
-
}
|
|
63
|
-
function extractHeaders(result) {
|
|
64
|
-
return "headers" in result ? result.headers : result.upstreamResponseHeaders ?? {};
|
|
65
|
-
}
|
|
66
|
-
function extractBody(result) {
|
|
67
|
-
return "body" in result ? result.body : result.responseBody ?? null;
|
|
68
|
-
}
|
|
69
|
-
// ---------- Core ----------
|
|
70
|
-
export async function retryableCall(fn, config, reply) {
|
|
71
|
-
const attempts = [];
|
|
72
|
-
for (let attempt = 0;; attempt++) {
|
|
73
|
-
const start = Date.now();
|
|
74
|
-
try {
|
|
75
|
-
const result = await fn();
|
|
76
|
-
const elapsed = Date.now() - start;
|
|
77
|
-
const body = extractBody(result);
|
|
78
|
-
attempts.push({
|
|
79
|
-
attemptIndex: attempt,
|
|
80
|
-
statusCode: result.statusCode,
|
|
81
|
-
error: null,
|
|
82
|
-
latencyMs: elapsed,
|
|
83
|
-
responseBody: body,
|
|
84
|
-
});
|
|
85
|
-
if (result.statusCode < HTTP_BAD_REQUEST)
|
|
86
|
-
return { result, attempts };
|
|
87
|
-
// 通过 matcher 获取匹配规则(含策略参数)
|
|
88
|
-
const matchedRule = body ? config.ruleMatcher?.match(result.statusCode, body) ?? null : null;
|
|
89
|
-
if (!matchedRule)
|
|
90
|
-
return { result, attempts };
|
|
91
|
-
const maxAttempts = matchedRule.max_retries;
|
|
92
|
-
if (attempt >= maxAttempts)
|
|
93
|
-
return { result, attempts };
|
|
94
|
-
if (reply && (reply.raw.writableFinished || reply.raw.headersSent))
|
|
95
|
-
return { result, attempts };
|
|
96
|
-
const strategy = createStrategy(matchedRule);
|
|
97
|
-
const headers = extractHeaders(result);
|
|
98
|
-
const retryAfterMs = result.statusCode === HTTP_TOO_MANY_REQUESTS ? parseRetryAfter(headers) : null;
|
|
99
|
-
const delay = Math.max(strategy.getDelay(attempt), retryAfterMs ?? 0);
|
|
100
|
-
await sleep(delay);
|
|
101
|
-
}
|
|
102
|
-
catch (err) {
|
|
103
|
-
const elapsed = Date.now() - start;
|
|
104
|
-
const errMsg = err instanceof Error ? err.message : String(err);
|
|
105
|
-
attempts.push({
|
|
106
|
-
attemptIndex: attempt,
|
|
107
|
-
statusCode: null,
|
|
108
|
-
error: errMsg,
|
|
109
|
-
latencyMs: elapsed,
|
|
110
|
-
responseBody: null,
|
|
111
|
-
});
|
|
112
|
-
if (!isRetryableThrow(err))
|
|
113
|
-
throw err;
|
|
114
|
-
if (attempt >= config.maxRetries)
|
|
115
|
-
throw err;
|
|
116
|
-
if (reply && (reply.raw.writableFinished || reply.raw.headersSent))
|
|
117
|
-
throw err;
|
|
118
|
-
await sleep(config.baseDelayMs);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import { request as httpRequestFn } from "http";
|
|
2
|
-
import { request as httpsRequestFn } from "https";
|
|
3
|
-
import { PassThrough } from "stream";
|
|
4
|
-
// ---------- Constants ----------
|
|
5
|
-
const UPSTREAM_SUCCESS = 200;
|
|
6
|
-
const UPSTREAM_BAD_GATEWAY = 502;
|
|
7
|
-
const HTTPS_DEFAULT_PORT = 443;
|
|
8
|
-
const HTTP_DEFAULT_PORT = 80;
|
|
9
|
-
// ---------- Request utilities ----------
|
|
10
|
-
/** 根据 URL scheme 选择 http 或 https 模块 */
|
|
11
|
-
export function createUpstreamRequest(url, options) {
|
|
12
|
-
return url.protocol === "https:" ? httpsRequestFn(options) : httpRequestFn(options);
|
|
13
|
-
}
|
|
14
|
-
/** 从 URL + headers 构造 Node.js http.request 所需的 options */
|
|
15
|
-
export function buildRequestOptions(url, headers, method = "POST") {
|
|
16
|
-
return {
|
|
17
|
-
hostname: url.hostname,
|
|
18
|
-
port: Number(url.port) || (url.protocol === "https:" ? HTTPS_DEFAULT_PORT : HTTP_DEFAULT_PORT),
|
|
19
|
-
path: url.pathname,
|
|
20
|
-
method,
|
|
21
|
-
headers,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
// ---------- Non-stream proxy ----------
|
|
25
|
-
export function proxyNonStream(backend, apiKey, body, clientHeaders, upstreamPath, buildHeaders) {
|
|
26
|
-
return new Promise((resolve, reject) => {
|
|
27
|
-
const url = new URL(`${backend.base_url}${upstreamPath}`);
|
|
28
|
-
const payload = JSON.stringify(body);
|
|
29
|
-
const upstreamHeaders = buildHeaders(clientHeaders, apiKey, Buffer.byteLength(payload));
|
|
30
|
-
const options = buildRequestOptions(url, upstreamHeaders);
|
|
31
|
-
const req = createUpstreamRequest(url, options);
|
|
32
|
-
req.on("response", (res) => {
|
|
33
|
-
const chunks = [];
|
|
34
|
-
res.on("data", (chunk) => chunks.push(chunk));
|
|
35
|
-
res.on("end", () => {
|
|
36
|
-
resolve({
|
|
37
|
-
statusCode: res.statusCode || UPSTREAM_BAD_GATEWAY,
|
|
38
|
-
body: Buffer.concat(chunks).toString("utf-8"),
|
|
39
|
-
headers: filterHeaders(res.headers),
|
|
40
|
-
sentHeaders: { ...upstreamHeaders },
|
|
41
|
-
sentBody: payload,
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
req.on("error", (err) => reject(err));
|
|
46
|
-
req.write(payload);
|
|
47
|
-
req.end();
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
// ---------- Stream proxy (SSE) ----------
|
|
51
|
-
export function proxyStream(backend, apiKey, body, clientHeaders, reply, timeoutMs, upstreamPath, buildHeaders, metricsTransform) {
|
|
52
|
-
return new Promise((resolve, reject) => {
|
|
53
|
-
const url = new URL(`${backend.base_url}${upstreamPath}`);
|
|
54
|
-
const payload = JSON.stringify(body);
|
|
55
|
-
const upstreamHeaders = buildHeaders(clientHeaders, apiKey, Buffer.byteLength(payload));
|
|
56
|
-
const options = buildRequestOptions(url, upstreamHeaders);
|
|
57
|
-
const upstreamReq = createUpstreamRequest(url, options);
|
|
58
|
-
upstreamReq.on("response", (upstreamRes) => {
|
|
59
|
-
const statusCode = upstreamRes.statusCode || UPSTREAM_BAD_GATEWAY;
|
|
60
|
-
if (statusCode !== UPSTREAM_SUCCESS) {
|
|
61
|
-
const chunks = [];
|
|
62
|
-
upstreamRes.on("data", (chunk) => chunks.push(chunk));
|
|
63
|
-
upstreamRes.on("end", () => {
|
|
64
|
-
const errorBody = Buffer.concat(chunks).toString("utf-8");
|
|
65
|
-
resolve({
|
|
66
|
-
statusCode,
|
|
67
|
-
responseBody: errorBody,
|
|
68
|
-
upstreamResponseHeaders: filterHeaders(upstreamRes.headers),
|
|
69
|
-
sentHeaders: upstreamHeaders,
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const sseHeaders = filterHeaders(upstreamRes.headers);
|
|
75
|
-
sseHeaders["Content-Type"] = "text/event-stream";
|
|
76
|
-
sseHeaders["Cache-Control"] = "no-cache";
|
|
77
|
-
sseHeaders["Connection"] = "keep-alive";
|
|
78
|
-
reply.raw.writeHead(statusCode, sseHeaders);
|
|
79
|
-
const passThrough = new PassThrough();
|
|
80
|
-
if (metricsTransform) {
|
|
81
|
-
metricsTransform.pipe(passThrough).pipe(reply.raw);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
passThrough.pipe(reply.raw);
|
|
85
|
-
}
|
|
86
|
-
const pipeEntry = metricsTransform ?? passThrough;
|
|
87
|
-
const captureChunks = [];
|
|
88
|
-
let idleTimer = null;
|
|
89
|
-
let resolved = false;
|
|
90
|
-
function cleanup() {
|
|
91
|
-
if (idleTimer)
|
|
92
|
-
clearTimeout(idleTimer);
|
|
93
|
-
idleTimer = null;
|
|
94
|
-
if (!passThrough.destroyed)
|
|
95
|
-
passThrough.destroy();
|
|
96
|
-
if (metricsTransform && !metricsTransform.destroyed)
|
|
97
|
-
metricsTransform.destroy();
|
|
98
|
-
if (!upstreamRes.destroyed)
|
|
99
|
-
upstreamRes.destroy();
|
|
100
|
-
}
|
|
101
|
-
function collectMetrics(isComplete) {
|
|
102
|
-
if (!metricsTransform)
|
|
103
|
-
return undefined;
|
|
104
|
-
const result = metricsTransform.getExtractor().getMetrics();
|
|
105
|
-
if (!isComplete) {
|
|
106
|
-
return { ...result, is_complete: 0 };
|
|
107
|
-
}
|
|
108
|
-
return result;
|
|
109
|
-
}
|
|
110
|
-
reply.raw.on("close", () => {
|
|
111
|
-
if (!resolved) {
|
|
112
|
-
cleanup();
|
|
113
|
-
resolve({ statusCode, responseBody: undefined, upstreamResponseHeaders: sseHeaders, sentHeaders: upstreamHeaders, metricsResult: collectMetrics(false) });
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
passThrough.on("error", () => {
|
|
117
|
-
cleanup();
|
|
118
|
-
if (!resolved) {
|
|
119
|
-
resolved = true;
|
|
120
|
-
resolve({ statusCode, responseBody: undefined, upstreamResponseHeaders: sseHeaders, sentHeaders: upstreamHeaders, metricsResult: collectMetrics(false) });
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
function resetIdleTimer() {
|
|
124
|
-
if (idleTimer)
|
|
125
|
-
clearTimeout(idleTimer);
|
|
126
|
-
idleTimer = setTimeout(() => {
|
|
127
|
-
cleanup();
|
|
128
|
-
if (!resolved) {
|
|
129
|
-
resolved = true;
|
|
130
|
-
resolve({ statusCode, responseBody: undefined, upstreamResponseHeaders: sseHeaders, sentHeaders: upstreamHeaders, metricsResult: collectMetrics(false) });
|
|
131
|
-
}
|
|
132
|
-
}, timeoutMs);
|
|
133
|
-
}
|
|
134
|
-
resetIdleTimer();
|
|
135
|
-
upstreamRes.on("data", (chunk) => {
|
|
136
|
-
if (resolved)
|
|
137
|
-
return;
|
|
138
|
-
resetIdleTimer();
|
|
139
|
-
pipeEntry.write(chunk);
|
|
140
|
-
captureChunks.push(chunk);
|
|
141
|
-
});
|
|
142
|
-
upstreamRes.on("end", () => {
|
|
143
|
-
if (resolved)
|
|
144
|
-
return;
|
|
145
|
-
resolved = true;
|
|
146
|
-
if (idleTimer)
|
|
147
|
-
clearTimeout(idleTimer);
|
|
148
|
-
pipeEntry.end();
|
|
149
|
-
reply.raw.end();
|
|
150
|
-
resolve({
|
|
151
|
-
statusCode,
|
|
152
|
-
responseBody: Buffer.concat(captureChunks).toString("utf-8"),
|
|
153
|
-
upstreamResponseHeaders: sseHeaders,
|
|
154
|
-
sentHeaders: upstreamHeaders,
|
|
155
|
-
metricsResult: collectMetrics(true),
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
upstreamRes.on("error", (err) => {
|
|
159
|
-
if (resolved)
|
|
160
|
-
return;
|
|
161
|
-
resolved = true;
|
|
162
|
-
cleanup();
|
|
163
|
-
reject(err);
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
upstreamReq.on("error", (err) => reject(err));
|
|
167
|
-
upstreamReq.write(payload);
|
|
168
|
-
upstreamReq.end();
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
// ---------- GET proxy ----------
|
|
172
|
-
export function proxyGetRequest(backend, apiKey, clientHeaders, upstreamPath, buildHeaders) {
|
|
173
|
-
return new Promise((resolve, reject) => {
|
|
174
|
-
const url = new URL(`${backend.base_url}${upstreamPath}`);
|
|
175
|
-
const headers = buildHeaders(clientHeaders, apiKey);
|
|
176
|
-
const options = buildRequestOptions(url, headers, "GET");
|
|
177
|
-
const req = createUpstreamRequest(url, options);
|
|
178
|
-
req.on("response", (res) => {
|
|
179
|
-
const chunks = [];
|
|
180
|
-
res.on("data", (chunk) => chunks.push(chunk));
|
|
181
|
-
res.on("end", () => {
|
|
182
|
-
resolve({
|
|
183
|
-
statusCode: res.statusCode || UPSTREAM_BAD_GATEWAY,
|
|
184
|
-
body: Buffer.concat(chunks).toString("utf-8"),
|
|
185
|
-
headers: filterHeaders(res.headers),
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
req.on("error", (err) => reject(err));
|
|
190
|
-
req.end();
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
// ---------- Shared header filter ----------
|
|
194
|
-
const SKIP_DOWNSTREAM = new Set([
|
|
195
|
-
"content-length",
|
|
196
|
-
"transfer-encoding",
|
|
197
|
-
"connection",
|
|
198
|
-
"keep-alive",
|
|
199
|
-
]);
|
|
200
|
-
function filterHeaders(raw) {
|
|
201
|
-
const out = {};
|
|
202
|
-
for (const [key, value] of Object.entries(raw)) {
|
|
203
|
-
if (value == null || SKIP_DOWNSTREAM.has(key.toLowerCase()))
|
|
204
|
-
continue;
|
|
205
|
-
out[key] = Array.isArray(value) ? value.join(", ") : value;
|
|
206
|
-
}
|
|
207
|
-
return out;
|
|
208
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,I as t,gt as n,mt as r,y as i,z as a}from"./client-BBW9-06a.js";import{r as o}from"./button-B3kgf-D2.js";var s=[`data-size`],c=e({__name:`Card`,props:{class:{type:[Boolean,null,String,Object,Array]},size:{default:`default`}},setup(e){let c=e;return(l,u)=>(t(),i(`div`,{"data-slot":`card`,"data-size":e.size,class:n(r(o)(`ring-foreground/10 bg-card text-card-foreground gap-4 overflow-hidden rounded-lg py-4 text-sm ring-1 has-data-[slot=card-footer]:pb-0 has-[>img:first-child]:pt-0 data-[size=sm]:gap-3 data-[size=sm]:py-3 data-[size=sm]:has-data-[slot=card-footer]:pb-0 *:[img:first-child]:rounded-t-lg *:[img:last-child]:rounded-b-lg group/card flex flex-col`,c.class))},[a(l.$slots,`default`)],10,s))}}),l=e({__name:`CardContent`,props:{class:{type:[Boolean,null,String,Object,Array]}},setup(e){let s=e;return(e,c)=>(t(),i(`div`,{"data-slot":`card-content`,class:n(r(o)(`px-4 group-data-[size=sm]/card:px-3`,s.class))},[a(e.$slots,`default`)],2))}});export{c as n,l as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,I as t,gt as n,mt as r,y as i,z as a}from"./client-BBW9-06a.js";import{r as o}from"./button-B3kgf-D2.js";var s=e({__name:`CardTitle`,props:{class:{type:[Boolean,null,String,Object,Array]}},setup(e){let s=e;return(e,c)=>(t(),i(`div`,{"data-slot":`card-title`,class:n(r(o)(`text-base leading-snug font-medium group-data-[size=sm]/card:text-sm cn-font-heading`,s.class))},[a(e.$slots,`default`)],2))}});export{s as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{A as e,C as t,I as n,S as r,T as i,V as a,Y as o,_ as s,_t as c,h as l,l as u,mt as d,u as f,v as p,z as m}from"./client-BBW9-06a.js";import{n as h,t as g}from"./ohash.D__AXeF1-Bj3Sy1wQ.js";import{i as _,r as v}from"./button-B3kgf-D2.js";import{h as y,p as b,u as x,w as S,x as C}from"./badge-HGT44FNA.js";import{c as w,h as T,t as E}from"./useForwardExpose-CIZH3-CG.js";import{t as D}from"./VisuallyHiddenInput-Dr8wp-H0.js";import{t as O}from"./RovingFocusItem-CvMnUs02.js";function k(e,t){return C(e)?!1:Array.isArray(e)?e.some(e=>g(e,t)):g(e,t)}var[A,j]=S(`CheckboxGroupRoot`);function M(e){return e===`indeterminate`}function N(e){return M(e)?`indeterminate`:e?`checked`:`unchecked`}var[P,F]=S(`CheckboxRoot`),I=t({inheritAttrs:!1,__name:`CheckboxRoot`,props:{defaultValue:{type:null,required:!1},modelValue:{type:null,required:!1,default:void 0},disabled:{type:Boolean,required:!1},value:{type:null,required:!1,default:`on`},id:{type:String,required:!1},trueValue:{type:null,required:!1,default:()=>!0},falseValue:{type:null,required:!1,default:()=>!1},asChild:{type:Boolean,required:!1},as:{type:null,required:!1,default:`button`},name:{type:String,required:!1},required:{type:Boolean,required:!1}},emits:[`update:modelValue`],setup(t,{emit:r}){let i=t,c=r,{forwardRef:h,currentElement:v}=E(),b=A(null),x=w(i,`modelValue`,c,{defaultValue:i.defaultValue??i.falseValue,passive:i.modelValue===void 0}),S=l(()=>b?.disabled.value||i.disabled),T=l(()=>g(x.value,i.trueValue)),j=l(()=>C(b?.modelValue.value)?x.value===`indeterminate`?`indeterminate`:T.value:k(b.modelValue.value,i.value));function P(){if(C(b?.modelValue.value))x.value===`indeterminate`?x.value=i.trueValue:x.value=T.value?i.falseValue:i.trueValue;else{let e=[...b.modelValue.value||[]];if(k(e,i.value)){let t=e.findIndex(e=>g(e,i.value));e.splice(t,1)}else e.push(i.value);b.modelValue.value=e}}let I=y(v),L=l(()=>i.id&&v.value?document.querySelector(`[for="${i.id}"]`)?.innerText:void 0);return F({disabled:S,state:j}),(t,r)=>(n(),s(a(d(b)?.rovingFocus.value?d(O):d(_)),e(t.$attrs,{id:t.id,ref:d(h),role:`checkbox`,"as-child":t.asChild,as:t.as,type:t.as===`button`?`button`:void 0,"aria-checked":d(M)(j.value)?`mixed`:j.value,"aria-required":t.required,"aria-label":t.$attrs[`aria-label`]||L.value,"data-state":d(N)(j.value),"data-disabled":S.value?``:void 0,disabled:S.value,focusable:d(b)?.rovingFocus.value?!S.value:void 0,onKeydown:u(f(()=>{},[`prevent`]),[`enter`]),onClick:P}),{default:o(()=>[m(t.$slots,`default`,{modelValue:d(x),state:j.value}),d(I)&&t.name&&!d(b)?(n(),s(d(D),{key:0,type:`checkbox`,checked:!!j.value,name:t.name,value:t.value,disabled:S.value,required:t.required},null,8,[`checked`,`name`,`value`,`disabled`,`required`])):p(`v-if`,!0)]),_:3},16,[`id`,`as-child`,`as`,`type`,`aria-checked`,`aria-required`,`aria-label`,`data-state`,`data-disabled`,`disabled`,`focusable`,`onKeydown`]))}}),L=t({__name:`CheckboxIndicator`,props:{forceMount:{type:Boolean,required:!1},asChild:{type:Boolean,required:!1},as:{type:null,required:!1,default:`span`}},setup(t){let{forwardRef:i}=E(),a=P();return(t,c)=>(n(),s(d(x),{present:t.forceMount||d(M)(d(a).state.value)||d(a).state.value===!0},{default:o(()=>[r(d(_),e({ref:d(i),"data-state":d(N)(d(a).state.value),"data-disabled":d(a).disabled.value?``:void 0,style:{pointerEvents:`none`},"as-child":t.asChild,as:t.as},t.$attrs),{default:o(()=>[m(t.$slots,`default`)]),_:3},16,[`data-state`,`data-disabled`,`as-child`,`as`])]),_:3},8,[`present`]))}}),R=t({__name:`Checkbox`,props:{defaultValue:{},modelValue:{},disabled:{type:Boolean},value:{},id:{},trueValue:{},falseValue:{},asChild:{type:Boolean},as:{},name:{},required:{type:Boolean},class:{type:[Boolean,null,String,Object,Array]}},emits:[`update:modelValue`],setup(t,{emit:a}){let l=t,u=a,f=b(T(l,`class`),u);return(t,a)=>(n(),s(d(I),e({"data-slot":`checkbox`},d(f),{class:d(v)(`border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary aria-invalid:aria-checked:border-primary aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 flex size-4 items-center justify-center rounded-md border transition-colors group-has-disabled/field:opacity-50 focus-visible:ring-3 aria-invalid:ring-3 peer relative shrink-0 outline-none after:absolute after:-inset-x-3 after:-inset-y-2 disabled:cursor-not-allowed disabled:opacity-50`,l.class)}),{default:o(e=>[r(d(L),{"data-slot":`checkbox-indicator`,class:`[&>svg]:size-3.5 grid place-content-center text-current transition-none`},{default:o(()=>[m(t.$slots,`default`,c(i(e)),()=>[r(d(h))])]),_:2},1024)]),_:3},16,[`class`]))}});export{R as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{A as e,C as t,I as n,K as r,N as i,S as a,T as o,Y as s,_ as c,_t as l,dt as u,h as d,j as f,mt as p,ot as m,v as h,z as g}from"./client-BBW9-06a.js";import{i as _}from"./button-B3kgf-D2.js";import{d as v,p as y,u as b,w as x}from"./badge-HGT44FNA.js";import{a as S,c as C,t as w}from"./useForwardExpose-CIZH3-CG.js";var[T,E]=x(`CollapsibleRoot`),D=t({__name:`CollapsibleRoot`,props:{defaultOpen:{type:Boolean,required:!1,default:!1},open:{type:Boolean,required:!1,default:void 0},disabled:{type:Boolean,required:!1},unmountOnHide:{type:Boolean,required:!1,default:!0},asChild:{type:Boolean,required:!1},as:{type:null,required:!1}},emits:[`update:open`],setup(e,{expose:t,emit:r}){let i=e,a=C(i,`open`,r,{defaultValue:i.defaultOpen,passive:i.open===void 0}),{disabled:o,unmountOnHide:l}=u(i);return E({contentId:``,disabled:o,open:a,unmountOnHide:l,onOpenToggle:()=>{o.value||(a.value=!a.value)}}),t({open:a}),w(),(e,t)=>(n(),c(p(_),{as:e.as,"as-child":i.asChild,"data-state":p(a)?`open`:`closed`,"data-disabled":p(o)?``:void 0},{default:s(()=>[g(e.$slots,`default`,{open:p(a)})]),_:3},8,[`as`,`as-child`,`data-state`,`data-disabled`]))}}),O=t({inheritAttrs:!1,__name:`CollapsibleContent`,props:{forceMount:{type:Boolean,required:!1},asChild:{type:Boolean,required:!1},as:{type:null,required:!1}},emits:[`contentFound`],setup(t,{emit:o}){let l=t,u=o,y=T();y.contentId||=v(void 0,`reka-collapsible-content`);let x=m(),{forwardRef:C,currentElement:E}=w(),D=m(0),O=m(0),k=d(()=>y.open.value),A=m(k.value),j=m();r(()=>[k.value,x.value?.present],async()=>{await f();let e=E.value;if(!e)return;j.value=j.value||{transitionDuration:e.style.transitionDuration,animationName:e.style.animationName},e.style.transitionDuration=`0s`,e.style.animationName=`none`;let t=e.getBoundingClientRect();O.value=t.height,D.value=t.width,A.value||(e.style.transitionDuration=j.value.transitionDuration,e.style.animationName=j.value.animationName)},{immediate:!0});let M=d(()=>A.value&&y.open.value);return i(()=>{requestAnimationFrame(()=>{A.value=!1})}),S(E,`beforematch`,e=>{requestAnimationFrame(()=>{y.onOpenToggle(),u(`contentFound`)})}),(t,r)=>(n(),c(p(b),{ref_key:`presentRef`,ref:x,present:t.forceMount||p(y).open.value,"force-mount":!0},{default:s(({present:n})=>[a(p(_),e(t.$attrs,{id:p(y).contentId,ref:p(C),"as-child":l.asChild,as:t.as,hidden:n?void 0:p(y).unmountOnHide.value?``:`until-found`,"data-state":M.value?void 0:p(y).open.value?`open`:`closed`,"data-disabled":p(y).disabled?.value?``:void 0,style:{"--reka-collapsible-content-height":`${O.value}px`,"--reka-collapsible-content-width":`${D.value}px`}}),{default:s(()=>[!p(y).unmountOnHide.value||n?g(t.$slots,`default`,{key:0}):h(`v-if`,!0)]),_:2},1040,[`id`,`as-child`,`as`,`hidden`,`data-state`,`data-disabled`,`style`])]),_:3},8,[`present`]))}}),k=t({__name:`CollapsibleTrigger`,props:{asChild:{type:Boolean,required:!1},as:{type:null,required:!1,default:`button`}},setup(e){let t=e;w();let r=T();return(e,i)=>(n(),c(p(_),{type:e.as===`button`?`button`:void 0,as:e.as,"as-child":t.asChild,"aria-controls":p(r).contentId,"aria-expanded":p(r).open.value,"data-state":p(r).open.value?`open`:`closed`,"data-disabled":p(r).disabled?.value?``:void 0,disabled:p(r).disabled?.value,onClick:p(r).onOpenToggle},{default:s(()=>[g(e.$slots,`default`)]),_:3},8,[`type`,`as`,`as-child`,`aria-controls`,`aria-expanded`,`data-state`,`data-disabled`,`disabled`,`onClick`]))}}),A=t({__name:`Collapsible`,props:{defaultOpen:{type:Boolean},open:{type:Boolean},disabled:{type:Boolean},unmountOnHide:{type:Boolean},asChild:{type:Boolean},as:{}},emits:[`update:open`],setup(t,{emit:r}){let i=y(t,r);return(t,r)=>(n(),c(p(D),e({"data-slot":`collapsible`},p(i)),{default:s(e=>[g(t.$slots,`default`,l(o(e)))]),_:3},16))}}),j=t({__name:`CollapsibleContent`,props:{forceMount:{type:Boolean},asChild:{type:Boolean},as:{}},setup(t){let r=t;return(t,i)=>(n(),c(p(O),e({"data-slot":`collapsible-content`},r),{default:s(()=>[g(t.$slots,`default`)]),_:3},16))}}),M=t({__name:`CollapsibleTrigger`,props:{asChild:{type:Boolean},as:{}},setup(t){let r=t;return(t,i)=>(n(),c(p(k),e({"data-slot":`collapsible-trigger`},r),{default:s(()=>[g(t.$slots,`default`)]),_:3},16))}});export{j as n,A as r,M as t};
|