@qitqode/qitqode-android-arm64 0.2.14 → 0.2.15
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/bun +2 -2
- package/bundle/{chunk-6wmtbebc.js → chunk-2fged9vy.js} +1 -1
- package/bundle/{chunk-358wdvj7.js → chunk-2pw56zpj.js} +1 -1
- package/bundle/{chunk-6kch0q2d.js → chunk-2tkgtasa.js} +1 -1
- package/bundle/{chunk-07b4pkk6.js → chunk-4b56k59w.js} +1 -1
- package/bundle/{chunk-47jkx37s.js → chunk-4gzggzc0.js} +1 -1
- package/bundle/{chunk-fpzkyzny.js → chunk-4jfnhghx.js} +1 -1
- package/bundle/{chunk-4hvenszg.js → chunk-4xcwnwd6.js} +1 -1
- package/bundle/{chunk-1mfdmm2t.js → chunk-4yd2vvh6.js} +1 -1
- package/bundle/{chunk-y1v7mf1a.js → chunk-5asf8f41.js} +72 -72
- package/bundle/chunk-5re7995e.js +2 -0
- package/bundle/{chunk-nrzca9yd.js → chunk-6k0y2332.js} +1 -1
- package/bundle/{chunk-pp10epga.js → chunk-6qwnty59.js} +1 -1
- package/bundle/{chunk-fd04358e.js → chunk-6zdzbmzs.js} +298 -297
- package/bundle/{chunk-2w79k0mh.js → chunk-76wm7tw8.js} +1 -1
- package/bundle/{chunk-k6gdmqff.js → chunk-7t63wz2f.js} +1 -1
- package/bundle/{chunk-hx13a8es.js → chunk-83n11xym.js} +1 -1
- package/bundle/{chunk-e8s4mp5n.js → chunk-878sb0es.js} +1 -1
- package/bundle/{chunk-4p9fny77.js → chunk-8mqcar7f.js} +1 -1
- package/bundle/{chunk-j1bv93m4.js → chunk-ae1b15bd.js} +1 -1
- package/bundle/{chunk-avzaqy6a.js → chunk-apneazwv.js} +1 -1
- package/bundle/{chunk-gnh8c49b.js → chunk-aw5yv01t.js} +1 -1
- package/bundle/{chunk-1gdt9q05.js → chunk-b6m5tr80.js} +1 -1
- package/bundle/{chunk-7xc73qb1.js → chunk-baq0wk3q.js} +1 -1
- package/bundle/{chunk-ffz334ab.js → chunk-c1wc4b5q.js} +1 -1
- package/bundle/{chunk-2ascwm7j.js → chunk-csy1v12x.js} +1 -1
- package/bundle/{chunk-9z7y4x7q.js → chunk-djdfpezf.js} +1 -1
- package/bundle/{chunk-9zsp3qkh.js → chunk-dpbm03yh.js} +1 -1
- package/bundle/{chunk-7a4sb6q7.js → chunk-e37gd3p2.js} +1 -1
- package/bundle/{chunk-bga4kqd1.js → chunk-estc7tzt.js} +1 -1
- package/bundle/{chunk-9gxyt2ay.js → chunk-f0x3q5dj.js} +1 -1
- package/bundle/{chunk-vnstr4g1.js → chunk-ffynh19k.js} +1 -1
- package/bundle/{chunk-y3dpyz2d.js → chunk-fgr9xshx.js} +1 -1
- package/bundle/{chunk-qpggztkq.js → chunk-fswt9qc0.js} +1 -1
- package/bundle/{chunk-2g4kxtz0.js → chunk-gww6abk3.js} +1 -1
- package/bundle/{chunk-qqsj69m2.js → chunk-h6b5966p.js} +1 -1
- package/bundle/{chunk-jvx7jtm4.js → chunk-hmm0gj34.js} +1 -1
- package/bundle/{chunk-8b9z8j3z.js → chunk-hmmn62jg.js} +1 -1
- package/bundle/{chunk-26e51217.js → chunk-j89sv999.js} +1 -1
- package/bundle/{chunk-05bkxat0.js → chunk-k4wfq9cn.js} +1 -1
- package/bundle/{chunk-n6pn4f3r.js → chunk-k8dbc1p5.js} +1 -1
- package/bundle/{chunk-9thgxbze.js → chunk-k9b4005p.js} +1 -1
- package/bundle/{chunk-9znfb8f2.js → chunk-kegvr7wt.js} +1 -1
- package/bundle/{chunk-00r3he5x.js → chunk-kht2kwam.js} +1 -1
- package/bundle/{chunk-gkf7x1yj.js → chunk-knqpyc7s.js} +1 -1
- package/bundle/chunk-mdxtt9wv.js +8 -0
- package/bundle/{chunk-8jkqyf9n.js → chunk-mnjz8nqs.js} +1 -1
- package/bundle/{chunk-zpjtse0z.js → chunk-mq3w4z8k.js} +2 -2
- package/bundle/{chunk-0ks20gz1.js → chunk-mreacz8r.js} +1 -1
- package/bundle/{chunk-ykvgmje9.js → chunk-n4qbnecw.js} +1 -1
- package/bundle/{chunk-gvf6ek9f.js → chunk-pqzx9ha6.js} +1 -1
- package/bundle/{chunk-kdqhwa65.js → chunk-q896qkhe.js} +1 -1
- package/bundle/{chunk-ngygp66y.js → chunk-qk6jh32z.js} +1 -1
- package/bundle/{chunk-6d4xc6br.js → chunk-rk4c0zat.js} +1 -1
- package/bundle/{chunk-dn0437c1.js → chunk-rt49c6js.js} +1 -1
- package/bundle/{chunk-34yk99ep.js → chunk-tkbjcznz.js} +1 -1
- package/bundle/{chunk-7s9msscb.js → chunk-vgmgg994.js} +1 -1
- package/bundle/{chunk-chnr7pe5.js → chunk-vsv4p060.js} +1 -1
- package/bundle/{chunk-vzkdzhn0.js → chunk-w0t1ajhg.js} +1 -1
- package/bundle/{chunk-w4fr00s7.js → chunk-wne3v1fk.js} +1 -1
- package/bundle/{chunk-w214dwws.js → chunk-wyavgt96.js} +1 -1
- package/bundle/{chunk-ae1g5y4r.js → chunk-xxck1man.js} +1 -1
- package/bundle/{chunk-g738e799.js → chunk-y4cz5s3h.js} +1 -1
- package/bundle/{chunk-583d91xq.js → chunk-yhpwceqg.js} +1 -1
- package/bundle/{chunk-y5ydtbpd.js → chunk-yms3bsm7.js} +1 -1
- package/bundle/{chunk-wmj3xndt.js → chunk-ytfq6rn9.js} +1 -1
- package/bundle/{chunk-qz20b42s.js → chunk-yvtkx4x4.js} +1 -1
- package/bundle/{chunk-jwv6fda1.js → chunk-ywj77e0m.js} +1 -1
- package/bundle/{chunk-y18ptwk2.js → chunk-z93n3cbm.js} +1 -1
- package/bundle/{chunk-6y0wgz2j.js → chunk-zbt53cb5.js} +1 -1
- package/bundle/{chunk-bm8azfnt.js → chunk-zhhcfqhh.js} +1 -1
- package/bundle/{chunk-2q78bdtj.js → chunk-zwxp07yc.js} +1 -1
- package/bundle/index.js +3 -3
- package/bundle/worker.js +1 -1
- package/package.json +1 -1
- package/bundle/chunk-1a08ffyd.js +0 -2
- package/bundle/chunk-jvvctqjd.js +0 -8
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{fe as b}from"./chunk-w8nj5ph5.js";import{cg as t}from"./chunk-psmwrvqs.js";import{Ah as u}from"./chunk-
|
|
2
|
+
import{fe as b}from"./chunk-w8nj5ph5.js";import{cg as t}from"./chunk-psmwrvqs.js";import{Ah as u}from"./chunk-6zdzbmzs.js";import"./chunk-qn1fhqyw.js";import"./chunk-674pexjx.js";import"./chunk-zjyaze0d.js";import"./chunk-xdcwx384.js";import"./chunk-rd08wx37.js";import"./chunk-fp2xgnjn.js";import{Sk as y,Zj as m}from"./chunk-5asf8f41.js";import{ol as v}from"./chunk-2pw56zpj.js";import{Ml as a}from"./chunk-rt49c6js.js";import"./chunk-4gzggzc0.js";import"./chunk-31a47ptm.js";import"./chunk-ywj77e0m.js";import"./chunk-83n11xym.js";import"./chunk-h036zy9e.js";import"./chunk-j3agzs13.js";import"./chunk-3152y1q9.js";import"./chunk-71jmhvef.js";import"./chunk-qrztx1b4.js";import"./chunk-ae1b15bd.js";import"./chunk-6qwnty59.js";import"./chunk-crqycrs4.js";import"./chunk-1bq15kf0.js";import"./chunk-pdcxmr6x.js";import"./chunk-cqtkxwd8.js";import"./chunk-a1mbach4.js";import"./chunk-m6967jtv.js";import"./chunk-j2snkw45.js";import"./chunk-bmdqb48f.js";import"./chunk-3cs1qf8x.js";import"./chunk-4xqwt6dr.js";import"./chunk-g77kddrs.js";import"./chunk-kegvr7wt.js";import"./chunk-2tkgtasa.js";import"./chunk-6cztstry.js";import"./chunk-4yd2vvh6.js";import"./chunk-fkq0v5qv.js";import"./chunk-1e75j4m1.js";import"./chunk-2w3n0q9m.js";import"./chunk-6dd2dx69.js";import"./chunk-fdmz0502.js";import"./chunk-5re7995e.js";import"./chunk-mnjz8nqs.js";import"./chunk-6yshpz0z.js";import"./chunk-5dvy83ms.js";import"./chunk-ffx0cr44.js";import"./chunk-33mzqyyb.js";import"./chunk-sg9enzsp.js";import"./chunk-5q98z8ck.js";import"./chunk-wfpnv00c.js";import{gI as s}from"./chunk-9kc2th5c.js";import"./chunk-hf39qx6t.js";import"./chunk-x0de4z05.js";import"./chunk-sh03ka27.js";import{EOL as f}from"os";var M=b({command:"models [provider]",describe:"list all available models",builder:(r)=>{return r.positional("provider",{describe:"provider ID to filter models by",type:"string",array:!1}).option("verbose",{describe:"use more verbose model output (includes metadata like costs)",type:"boolean"}).option("refresh",{describe:"refresh the models cache from models.dev",type:"boolean"})},handler:async(r)=>{if(r.refresh)await v.refresh(!0),t.println(t.Style.TEXT_SUCCESS_BOLD+"Models cache refreshed"+t.Style.TEXT_NORMAL);await a.provide({directory:process.cwd(),async fn(){await u.runPromise(s.gen(function*(){let n=yield*(yield*y.Service).list(),l=(e,o)=>{let i=n[e],d=Object.entries(i.models).sort(([c],[p])=>c.localeCompare(p));for(let[c,p]of d)if(process.stdout.write(`${e}/${c}`),process.stdout.write(f),o)process.stdout.write(JSON.stringify(p,null,2)),process.stdout.write(f)};if(r.provider){let e=m.make(r.provider);if(!n[e]){yield*s.sync(()=>t.error(`Provider not found: ${r.provider}`));return}yield*s.sync(()=>l(e,r.verbose));return}let h=Object.keys(n).sort((e,o)=>{let i=e.startsWith("opencode"),d=o.startsWith("opencode");if(i&&!d)return-1;if(!i&&d)return 1;return e.localeCompare(o)});yield*s.sync(()=>{for(let e of h)l(m.make(e),r.verbose)})}))}})}});export{M as ModelsCommand};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{h as _}from"./chunk-
|
|
2
|
+
import{h as _}from"./chunk-zbt53cb5.js";import{G as W,H as Y,I as G}from"./chunk-djdfpezf.js";import{fe as X}from"./chunk-w8nj5ph5.js";import{cg as j}from"./chunk-psmwrvqs.js";import{Dg as O}from"./chunk-f0x3q5dj.js";import{Ah as v}from"./chunk-6zdzbmzs.js";import"./chunk-qn1fhqyw.js";import"./chunk-674pexjx.js";import"./chunk-zjyaze0d.js";import"./chunk-xdcwx384.js";import"./chunk-rd08wx37.js";import"./chunk-fp2xgnjn.js";import{wj as H}from"./chunk-5asf8f41.js";import"./chunk-2pw56zpj.js";import"./chunk-rt49c6js.js";import"./chunk-4gzggzc0.js";import"./chunk-31a47ptm.js";import"./chunk-ywj77e0m.js";import"./chunk-83n11xym.js";import"./chunk-h036zy9e.js";import"./chunk-j3agzs13.js";import"./chunk-3152y1q9.js";import"./chunk-71jmhvef.js";import"./chunk-qrztx1b4.js";import"./chunk-ae1b15bd.js";import{cp as K,xp as F}from"./chunk-6qwnty59.js";import"./chunk-crqycrs4.js";import"./chunk-1bq15kf0.js";import"./chunk-pdcxmr6x.js";import"./chunk-cqtkxwd8.js";import"./chunk-a1mbach4.js";import"./chunk-m6967jtv.js";import"./chunk-j2snkw45.js";import"./chunk-bmdqb48f.js";import"./chunk-3cs1qf8x.js";import"./chunk-4xqwt6dr.js";import"./chunk-g77kddrs.js";import"./chunk-kegvr7wt.js";import"./chunk-2tkgtasa.js";import"./chunk-6cztstry.js";import"./chunk-4yd2vvh6.js";import"./chunk-fkq0v5qv.js";import"./chunk-1e75j4m1.js";import"./chunk-2w3n0q9m.js";import"./chunk-6dd2dx69.js";import"./chunk-fdmz0502.js";import"./chunk-5re7995e.js";import"./chunk-mnjz8nqs.js";import"./chunk-6yshpz0z.js";import"./chunk-5dvy83ms.js";import"./chunk-ffx0cr44.js";import"./chunk-33mzqyyb.js";import"./chunk-sg9enzsp.js";import"./chunk-5q98z8ck.js";import"./chunk-wfpnv00c.js";import{gI as z}from"./chunk-9kc2th5c.js";import"./chunk-hf39qx6t.js";import"./chunk-x0de4z05.js";import"./chunk-sh03ka27.js";var Q="forgewise";function R(D){return z.gen(function*(){let M=yield*D.get(Q);if(!M||M.type!=="api")return;return(M.metadata??{}).sub})}var w=()=>z.gen(function*(){if((yield*_())==="revoked")return null;let D=yield*z.promise(()=>K());if(!D)return yield*z.sync(()=>j.println(j.Style.TEXT_DANGER+"Not signed in to Forgewise. Run `qitqode auth login` first."+j.Style.TEXT_NORMAL)),null;let M=yield*H.Service,T=D.method==="sso"?yield*R(M):void 0;return{key:D.key,method:D.method,sub:T}}),b=()=>z.gen(function*(){let D=yield*w();if(!D)return;let M=yield*z.tryPromise({try:()=>O(D),catch:(P)=>P}).pipe(z.map((P)=>({ok:!0,result:P})),z.catch((P)=>z.succeed({ok:!1,error:P})));if(!M.ok){let P=M.error instanceof F?M.error.message:"Could not fetch balance.";yield*z.sync(()=>j.println(j.Style.TEXT_DANGER+P+j.Style.TEXT_NORMAL));return}let T=M.result;if(!T){yield*z.sync(()=>j.println(j.Style.TEXT_DANGER+"Could not fetch balance."+j.Style.TEXT_NORMAL));return}yield*z.sync(()=>j.println(j.Style.TEXT_SUCCESS+"Qredits balance: "+j.Style.TEXT_NORMAL+j.Style.TEXT_HIGHLIGHT_BOLD+G(T.balance)+j.Style.TEXT_NORMAL))}).pipe(z.withSpan("qredits.balance")),q=()=>z.gen(function*(){let D=yield*w();if(!D)return;let M=D.method==="sso"&&D.sub?{userId:D.sub,accessToken:D.key}:{},T=yield*z.tryPromise({try:()=>Y({...M,limit:20}),catch:(J)=>J}).pipe(z.map((J)=>({ok:!0,result:J})),z.catch((J)=>z.succeed({ok:!1,error:J})));if(!T.ok){let J=T.error,$=J instanceof F?J.message+"\nPer-session spend is available with `qitqode usage`.":J instanceof W?J.message:String(J);yield*z.sync(()=>j.println(j.Style.TEXT_DANGER+"Could not fetch history: "+$+j.Style.TEXT_NORMAL));return}let P=T.result;if(P.length===0){yield*z.sync(()=>j.println("No spend history yet."));return}let Z=j.Style.TEXT_DIM,V=j.Style.TEXT_NORMAL,x=j.Style.TEXT_DANGER;yield*z.sync(()=>{j.println(Z+" Date Description Amount"+V),j.println(Z+" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500"+V);for(let J of P){let $=(J.date||"").slice(0,10).padEnd(18),L=(J.description||"").slice(0,32).padEnd(32),N=(J.amount<0?"-":" ")+G(Math.abs(J.amount)),B=J.amount<0?x:V;j.println(` ${Z}${$}${V} ${L} ${B}${N}${V}`)}})}).pipe(z.withSpan("qredits.history")),m=X({command:"qredits <command>",describe:"Check Qredits balance and spend history",builder:(D)=>D.command(X({command:"balance",describe:"Show current Qredits balance",builder:(M)=>M,async handler(){j.empty(),await v.runPromise(b())}})).command(X({command:"history",describe:"Show recent Qredit spend history",builder:(M)=>M,async handler(){j.empty(),await v.runPromise(q())}})).demandCommand(),async handler(){}});export{q as historyEffect,b as balanceEffect,m as QreditsCommand};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{kg as Ai,lg as t1,mg as b1,ng as k1,og as p1,pg as e1,qg as s1,rg as f1,sg as rA,tg as nA,ug as a1,xg as cA}from"./chunk-583d91xq.js";import{yg as Er,zg as L1}from"./chunk-e8s4mp5n.js";import{Dg as W1}from"./chunk-9gxyt2ay.js";import{Ig as Sc}from"./chunk-5qhsfjzq.js";import{Kg as Ey}from"./chunk-4s1n38ds.js";import{Lg as r2}from"./chunk-2w79k0mh.js";import{$g as pn,Ah as e,Mg as Ml,Ng as zl,Og as dn,Pg as _i,Wg as Xr,Xg as Tl,Yg as Km,_g as Hm,ah as tn,bh as nm,dh as mm,fh as _r,gh as bc,jh as j1,kh as ql,mh as tc,nh as _l,oh as ol,ph as ji,qh as Ll,rh as Fl,sh as b0,th as Rm,vh as w1,wh as Dr,xh as Ii,yh as Wr}from"./chunk-fd04358e.js";import{Aj as f0,Bj as qi,Cj as R1,Gj as fj,Gk as qr,Hj as tr,Hk as Fn,Ij as Rr,Ik as AA,Jj as D2,Kj as yr,Lj as br,Mj as vn,Nj as un,Nk as l1,Qj as Ym,Sk as ir,Tk as Cr,Uk as Ar,Wk as $2,Xk as I0,Yj as v1,Zj as s,_j as er,bl as Z,cl as cr,vj as wr,vk as Pi,wj as rm,wk as Qr,xj as J1,yj as O1}from"./chunk-y1v7mf1a.js";import{el as al,ol as uI}from"./chunk-358wdvj7.js";import{Bl as mA,Cl as b,El as Wn,Gl as y0,Kl as Gr,Ml as o,pl as Lr,tl as bj,ul as mr,vl as Kn,wl as Hn}from"./chunk-dn0437c1.js";import{Yl as jn}from"./chunk-47jkx37s.js";import{Bm as im,Cm as o1,Dm as M1,Hm as T1,Im as fi,Xm as l0,um as _n,wm as tj,zm as d}from"./chunk-31a47ptm.js";import{On as g}from"./chunk-3152y1q9.js";import{cp as P1,xp as C1}from"./chunk-pp10epga.js";import{xr as bI,yr as eI,zr as Di}from"./chunk-9znfb8f2.js";import{Ir as fI,Jr as r1}from"./chunk-6kch0q2d.js";import{Pr as CI,Sr as Wi,cs as B0,ds as Pr,es as WI,fs as x0,gs as XI,hs as KI,is as HI,js as RI,ks as zr,ls as Ql,ms as k0,ns as VI,os as YI,ps as ZI,qs as JI,rs as p0,ss as OI,ts as sI,us as LI,vs as qI,ws as _I,xs as _2,ys as Im}from"./chunk-6cztstry.js";import{ct as r0}from"./chunk-fdmz0502.js";import{ft as lA,rt as aI}from"./chunk-8jkqyf9n.js";import{It as Tj,Kt as c0}from"./chunk-6yshpz0z.js";import{Pt as p,Yt as _}from"./chunk-5dvy83ms.js";import{cu as kl,du as IA,hu as Xn,mu as Zn}from"./chunk-ffx0cr44.js";import{nu as I}from"./chunk-33mzqyyb.js";import{Hz as In,gA as cI,hA as lI}from"./chunk-wfpnv00c.js";import{AC as u2,BC as Vn,BG as vI,BI as t2,BM as Pm,CI as S0,DA as An,DG as h0,DI as b2,DM as El,EI as Al,FA as Xl,FF as M,FI as Sl,FM as ml,GA as zn,GI as e2,HC as AI,HG as O0,HI as s2,II as X2,JI as ec,JM as K2,KA as x2,KI as wl,LI as f2,MA as C2,NG as Bn,OO as Fr,PK as PI,QO as cl,RO as R0,SG as wI,SM as Dm,UE as S1,UH as Pl,VC as MI,VO as F,XC as Tn,XM as sc,_G as Gl,_M as jm,bB as on,cC as Dl,dD as L2,dG as J0,dH as $m,dM as T0,eC as k2,eD as q2,eH as $I,eM as Nl,fF as Sm,fH as Ul,fN as Ri,gD as H0,gI as P,iH as o2,iM as rI,jG as t,jN as Ci,kC as p2,kI as GI,lC as a2,lN as gr,mD as d2,mI as NI,mJ as UI,nC as Qm,nI as Li,oC as $r,oI as Cl,pC as Y0,qG as vm,qM as nI,rC as Br,rG as wm,rI as EI,sC as Sn,sI as QI,sM as iI,tC as L0,tG as SI,tM as mI,vC as Um,vF as z2,wC as Il,xC as vl,xG as hn,xM as X0,yC as or,yI as DI,zC as Am,zF as Z0,zI as v0,zM as K0}from"./chunk-9kc2th5c.js";import{uP as Av,vP as nr,wP as Nr,yP as sn}from"./chunk-sh03ka27.js";var pm=nr((hy)=>{Object.defineProperty(hy,"__esModule",{value:!0});hy.default=tA;var My=/[A-Z]/g;function Ty(r){return r.toLowerCase()}function tA(r,n){let i=r.replace(My,Ty),m=n.replace(My,Ty);return i===m}});var Rc=nr((By)=>{Object.defineProperty(By,"__esModule",{value:!0});By.DnsTxt=void 0;class Hc{constructor(r={}){this.binary=r?r.binary:!1}encode(r={}){return Object.entries(r).map(([n,i])=>{let m=`${n}=${i}`;return Buffer.from(m)})}decode(r){var n={};try{let m=r.toString().split(/=(.+)/),c=m[0],l=m[1];n[c]=l}catch(i){}return n}decodeAll(r){return r.filter((n)=>n.length>1).map((n)=>this.decode(n)).reduce((n,i)=>{var m=n;let[c]=Object.keys(i),[l]=Object.values(i);return m[c]=l,m},{})}}By.DnsTxt=Hc;By.default=Hc});var Vc=nr((py)=>{Object.defineProperty(py,"__esModule",{value:!0});py.toType=py.toString=void 0;var ky=(r)=>{return"_"+r},sA=(r)=>{return["name","protocol","subtype"].includes(r)},fA=(r)=>{let n={name:r.name,protocol:r.protocol,subtype:r.subtype};return Object.entries(n).filter(([m,c])=>sA(m)&&c!==void 0).reduce((m,[c,l])=>{switch(typeof l){case"object":l.map((y)=>m.push(ky(y)));break;default:m.push(ky(l));break}return m},[]).join(".")};py.toString=fA;var rS=(r)=>{let n=r.split("."),i;for(let m in n){if(n[m][0]!=="_")continue;n[m]=n[m].slice(1)}if(n.includes("sub"))i=n.shift(),n.shift();return{name:n.shift(),protocol:n.shift()||null,subtype:i}};py.toType=rS});var Zc=nr((en)=>{var dy=en&&en.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(en,"__esModule",{value:!0});en.Service=void 0;var uy=dy(sn("os")),iS=dy(Rc()),mS=sn("events"),cS=Vc(),am=".local";class Yc extends mS.EventEmitter{constructor(r){super();if(this.probe=!0,this.published=!1,this.activated=!1,this.destroyed=!1,this.txtService=new iS.default,!r.name)throw Error("ServiceConfig requires `name` property to be set");if(!r.type)throw Error("ServiceConfig requires `type` property to be set");if(!r.port)throw Error("ServiceConfig requires `port` property to be set");this.name=r.name.split(".").join("-"),this.protocol=r.protocol||"tcp",this.type=(0,cS.toString)({name:r.type,protocol:this.protocol}),this.port=r.port,this.host=r.host||uy.default.hostname(),this.fqdn=`${this.name}.${this.type}${am}`,this.txt=r.txt,this.subtypes=r.subtypes,this.disableIPv6=!!r.disableIPv6}records(){var r=[this.RecordPTR(this),this.RecordSRV(this),this.RecordTXT(this)];for(let i of this.subtypes||[])r.push(this.RecordSubtypePTR(this,i));let n=Object.values(uy.default.networkInterfaces());for(let i of n){let m=i;for(let c of m){if(c.internal||c.mac==="00:00:00:00:00:00")continue;switch(c.family){case"IPv4":r.push(this.RecordA(this,c.address));break;case"IPv6":if(this.disableIPv6)break;r.push(this.RecordAAAA(this,c.address));break}}}return r}RecordPTR(r){return{name:`${r.type}${am}`,type:"PTR",ttl:28800,data:r.fqdn}}RecordSubtypePTR(r,n){return{name:`_${n}._sub.${r.type}${am}`,type:"PTR",ttl:28800,data:`${r.name}.${r.type}${am}`}}RecordSRV(r){return{name:r.fqdn,type:"SRV",ttl:120,data:{port:r.port,target:r.host}}}RecordTXT(r){return{name:r.fqdn,type:"TXT",ttl:4500,data:this.txtService.encode(r.txt)}}RecordA(r,n){return{name:r.host,type:"A",ttl:120,data:n}}RecordAAAA(r,n){return{name:r.host,type:"AAAA",ttl:120,data:n}}}en.Service=Yc;en.default=Yc});var by=nr((fn)=>{var ty=fn&&fn.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(fn,"__esModule",{value:!0});fn.Registry=void 0;var lS=ty(pm()),Jc=ty(Zc()),yS=3600000,jS=3,IS=function(){};class Oc{constructor(r){this.services=[],this.server=r}publish(r){function n(c,l,y){if(c.activated)return;if(c.activated=!0,l.services.push(c),!(c instanceof Jc.default))return;if(y===null||y===void 0?void 0:y.probe)l.probe(l.server.mdns,c,(j)=>{if(j){if(c.stop!==void 0)c.stop();console.log(Error("Service name is already in use on the network"));return}l.announce(l.server,c)});else l.announce(l.server,c)}function i(c,l,y){if(!y)y=IS;if(!c.activated)return process.nextTick(y);if(!(c instanceof Jc.default))return process.nextTick(y);l.teardown(l.server,c,y);let j=l.services.indexOf(c);if(j!==-1)l.services.splice(j,1)}let m=new Jc.default(r);return m.start=n.bind(null,m,this),m.stop=i.bind(null,m,this),m.start({probe:r.probe!==!1}),m}unpublishAll(r){this.teardown(this.server,this.services,r),this.services=[]}destroy(){this.services.map((r)=>r.destroyed=!0)}probe(r,n,i){var m=!1,c=0,l;let y=()=>{if(!n.activated||n.destroyed)return;r.query(n.fqdn,"ANY",function(){m=!0,l=setTimeout(++c<3?y:S,250),l.unref()})},j=(v)=>{if(!m)return;if(v.answers.some(A)||v.additionals.some(A))S(!0)},A=(v)=>{return(0,lS.default)(v.name,n.fqdn)},S=(v)=>{r.removeListener("response",j),clearTimeout(l),i(!!v)};r.on("response",j),setTimeout(y,Math.random()*250)}announce(r,n){var i=1000,m=n.records();r.register(m);let c=()=>{if(!n.activated||n.destroyed)return;r.mdns.respond(m,function(){if(!n.published)n.activated=!0,n.published=!0,n.emit("up");if(i=i*jS,i<yS&&!n.destroyed)setTimeout(c,i).unref()})};c()}teardown(r,n,i){if(!Array.isArray(n))n=[n];n=n.filter((c)=>c.activated);var m=n.flatMap(function(c){c.activated=!1;var l=c.records();return l.forEach((y)=>{y.ttl=0}),l});if(m.length===0)return i&&process.nextTick(i);r.unregister(m),r.mdns.respond(m,function(){if(n.forEach(function(c){c.published=!1}),typeof i==="function")i.apply(null,arguments)})}}fn.Registry=Oc;fn.default=Oc});var ey=nr((AS)=>{AS.toString=function(r){switch(r){case 1:return"A";case 10:return"NULL";case 28:return"AAAA";case 18:return"AFSDB";case 42:return"APL";case 257:return"CAA";case 60:return"CDNSKEY";case 59:return"CDS";case 37:return"CERT";case 5:return"CNAME";case 49:return"DHCID";case 32769:return"DLV";case 39:return"DNAME";case 48:return"DNSKEY";case 43:return"DS";case 55:return"HIP";case 13:return"HINFO";case 45:return"IPSECKEY";case 25:return"KEY";case 36:return"KX";case 29:return"LOC";case 15:return"MX";case 35:return"NAPTR";case 2:return"NS";case 47:return"NSEC";case 50:return"NSEC3";case 51:return"NSEC3PARAM";case 12:return"PTR";case 46:return"RRSIG";case 17:return"RP";case 24:return"SIG";case 6:return"SOA";case 99:return"SPF";case 33:return"SRV";case 44:return"SSHFP";case 32768:return"TA";case 249:return"TKEY";case 52:return"TLSA";case 250:return"TSIG";case 16:return"TXT";case 252:return"AXFR";case 251:return"IXFR";case 41:return"OPT";case 255:return"ANY"}return"UNKNOWN_"+r};AS.toType=function(r){switch(r.toUpperCase()){case"A":return 1;case"NULL":return 10;case"AAAA":return 28;case"AFSDB":return 18;case"APL":return 42;case"CAA":return 257;case"CDNSKEY":return 60;case"CDS":return 59;case"CERT":return 37;case"CNAME":return 5;case"DHCID":return 49;case"DLV":return 32769;case"DNAME":return 39;case"DNSKEY":return 48;case"DS":return 43;case"HIP":return 55;case"HINFO":return 13;case"IPSECKEY":return 45;case"KEY":return 25;case"KX":return 36;case"LOC":return 29;case"MX":return 15;case"NAPTR":return 35;case"NS":return 2;case"NSEC":return 47;case"NSEC3":return 50;case"NSEC3PARAM":return 51;case"PTR":return 12;case"RRSIG":return 46;case"RP":return 17;case"SIG":return 24;case"SOA":return 6;case"SPF":return 99;case"SRV":return 33;case"SSHFP":return 44;case"TA":return 32768;case"TKEY":return 249;case"TLSA":return 52;case"TSIG":return 250;case"TXT":return 16;case"AXFR":return 252;case"IXFR":return 251;case"OPT":return 41;case"ANY":return 255;case"*":return 255}if(r.toUpperCase().startsWith("UNKNOWN_"))return parseInt(r.slice(8));return 0}});var sy=nr((wS)=>{wS.toString=function(r){switch(r){case 0:return"NOERROR";case 1:return"FORMERR";case 2:return"SERVFAIL";case 3:return"NXDOMAIN";case 4:return"NOTIMP";case 5:return"REFUSED";case 6:return"YXDOMAIN";case 7:return"YXRRSET";case 8:return"NXRRSET";case 9:return"NOTAUTH";case 10:return"NOTZONE";case 11:return"RCODE_11";case 12:return"RCODE_12";case 13:return"RCODE_13";case 14:return"RCODE_14";case 15:return"RCODE_15"}return"RCODE_"+r};wS.toRcode=function(r){switch(r.toUpperCase()){case"NOERROR":return 0;case"FORMERR":return 1;case"SERVFAIL":return 2;case"NXDOMAIN":return 3;case"NOTIMP":return 4;case"REFUSED":return 5;case"YXDOMAIN":return 6;case"YXRRSET":return 7;case"NXRRSET":return 8;case"NOTAUTH":return 9;case"NOTZONE":return 10;case"RCODE_11":return 11;case"RCODE_12":return 12;case"RCODE_13":return 13;case"RCODE_14":return 14;case"RCODE_15":return 15}return 0}});var fy=nr((NS)=>{NS.toString=function(r){switch(r){case 0:return"QUERY";case 1:return"IQUERY";case 2:return"STATUS";case 3:return"OPCODE_3";case 4:return"NOTIFY";case 5:return"UPDATE";case 6:return"OPCODE_6";case 7:return"OPCODE_7";case 8:return"OPCODE_8";case 9:return"OPCODE_9";case 10:return"OPCODE_10";case 11:return"OPCODE_11";case 12:return"OPCODE_12";case 13:return"OPCODE_13";case 14:return"OPCODE_14";case 15:return"OPCODE_15"}return"OPCODE_"+r};NS.toOpcode=function(r){switch(r.toUpperCase()){case"QUERY":return 0;case"IQUERY":return 1;case"STATUS":return 2;case"OPCODE_3":return 3;case"NOTIFY":return 4;case"UPDATE":return 5;case"OPCODE_6":return 6;case"OPCODE_7":return 7;case"OPCODE_8":return 8;case"OPCODE_9":return 9;case"OPCODE_10":return 10;case"OPCODE_11":return 11;case"OPCODE_12":return 12;case"OPCODE_13":return 13;case"OPCODE_14":return 14;case"OPCODE_15":return 15}return 0}});var rj=nr((DS)=>{DS.toString=function(r){switch(r){case 1:return"IN";case 2:return"CS";case 3:return"CH";case 4:return"HS";case 255:return"ANY"}return"UNKNOWN_"+r};DS.toClass=function(r){switch(r.toUpperCase()){case"IN":return 1;case"CS":return 2;case"CH":return 3;case"HS":return 4;case"ANY":return 255}return 0}});var nj=nr((CS)=>{CS.toString=function(r){switch(r){case 1:return"LLQ";case 2:return"UL";case 3:return"NSID";case 5:return"DAU";case 6:return"DHU";case 7:return"N3U";case 8:return"CLIENT_SUBNET";case 9:return"EXPIRE";case 10:return"COOKIE";case 11:return"TCP_KEEPALIVE";case 12:return"PADDING";case 13:return"CHAIN";case 14:return"KEY_TAG";case 26946:return"DEVICEID"}if(r<0)return null;return`OPTION_${r}`};CS.toCode=function(r){if(typeof r==="number")return r;if(!r)return-1;switch(r.toUpperCase()){case"OPTION_0":return 0;case"LLQ":return 1;case"UL":return 2;case"NSID":return 3;case"OPTION_4":return 4;case"DAU":return 5;case"DHU":return 6;case"N3U":return 7;case"CLIENT_SUBNET":return 8;case"EXPIRE":return 9;case"COOKIE":return 10;case"TCP_KEEPALIVE":return 11;case"PADDING":return 12;case"CHAIN":return 13;case"KEY_TAG":return 14;case"DEVICEID":return 26946;case"OPTION_65535":return 65535}let n=r.match(/_(\d+)$/);if(n)return parseInt(n[1],10);return-1}});var cj=nr((mj,Lc)=>{var ij=function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.decode=w,r.encode=v,r.familyOf=S,r.name=void 0,r.sizeOf=A,r.v6=r.v4=void 0;let n=/^(\d{1,3}\.){3,3}\d{1,3}$/,i=4,m=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i,c=16,l={name:"v4",size:i,isFormat:(N)=>n.test(N),encode(N,E,Q){Q=~~Q,E=E||new Uint8Array(Q+i);let W=N.length,H=0;for(let X=0;X<W;){let K=N.charCodeAt(X++);if(K===46)E[Q++]=H,H=0;else H=H*10+(K-48)}return E[Q]=H,E},decode(N,E){return E=~~E,`${N[E++]}.${N[E++]}.${N[E++]}.${N[E]}`}};r.v4=l;let y={name:"v6",size:c,isFormat:(N)=>N.length>0&&m.test(N),encode(N,E,Q){Q=~~Q;let W=Q+c,H=-1,X=0,K=0,J=!0,q=!1;E=E||new Uint8Array(Q+c);for(let z=0;z<N.length;z++){let L=N.charCodeAt(z);if(L===58){if(J){if(H!==-1){if(Q<W)E[Q]=0;if(Q<W-1)E[Q+1]=0;Q+=2}else if(Q<W)H=Q}else{if(q===!0){if(Q<W)E[Q]=K;Q++}else{if(Q<W)E[Q]=X>>8;if(Q<W-1)E[Q+1]=X&255;Q+=2}X=0,K=0}J=!0,q=!1}else if(L===46){if(Q<W)E[Q]=K;Q++,K=0,X=0,J=!1,q=!0}else{if(J=!1,L>=97)L-=87;else if(L>=65)L-=55;else L-=48,K=K*10+L;X=(X<<4)+L}}if(J===!1)if(q===!0){if(Q<W)E[Q]=K;Q++}else{if(Q<W)E[Q]=X>>8;if(Q<W-1)E[Q+1]=X&255;Q+=2}else if(H===0){if(Q<W)E[Q]=0;if(Q<W-1)E[Q+1]=0;Q+=2}else if(H!==-1){Q+=2;for(let z=Math.min(Q-1,W-1);z>=H+2;z--)E[z]=E[z-2];E[H]=0,E[H+1]=0,H=Q}if(H!==Q&&H!==-1){if(Q>W-2)Q=W-2;while(W>H)E[--W]=Q<W&&Q>H?E[--Q]:0}else while(Q<W)E[Q++]=0;return E},decode(N,E){E=~~E;let Q="";for(let W=0;W<c;W+=2){if(W!==0)Q+=":";Q+=(N[E+W]<<8|N[E+W+1]).toString(16)}return Q.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}};r.v6=y;let j="ip";r.name=j;function A(N){if(l.isFormat(N))return l.size;if(y.isFormat(N))return y.size;throw Error(`Invalid ip address: ${N}`)}function S(N){return A(N)===l.size?1:2}function v(N,E,Q){Q=~~Q;let W=A(N);if(typeof E==="function")E=E(Q+W);if(W===l.size)return l.encode(N,E,Q);return y.encode(N,E,Q)}function w(N,E,Q){if(E=~~E,Q=Q||N.length-E,Q===l.size)return l.decode(N,E,Q);if(Q===y.size)return y.decode(N,E,Q);throw Error(`Invalid buffer size needs to be ${l.size} for v4 or ${y.size} for v6.`)}return"default"in r?r.default:r}({});if(typeof define==="function"&&define.amd)define([],function(){return ij});else if(typeof Lc==="object"&&typeof mj==="object")Lc.exports=ij});var lj=nr((YS)=>{var Y=sn("buffer").Buffer,Cn=ey(),KS=sy(),HS=fy(),dm=rj(),gc=nj(),ri=cj(),R=YS.name={};R.encode=function(r,n,i,{mail:m=!1}={}){if(!n)n=Y.alloc(R.encodingLength(r));if(!i)i=0;let c=i,l=r.replace(/^\.|\.$/gm,"");if(l.length){let y=[];if(m){let j="";l.split(".").forEach((A)=>{if(A.endsWith("\\"))j+=(j.length?".":"")+A.slice(0,-1);else if(y.length===0&&j.length)y.push(j+"."+A);else y.push(A)})}else y=l.split(".");for(let j=0;j<y.length;j++){let A=n.write(y[j],i+1);n[i]=A,i+=A+1}}return n[i++]=0,R.encode.bytes=i-c,n};R.encode.bytes=0;R.decode=function(r,n,{mail:i=!1}={}){if(!n)n=0;let m=[],c=n,l=0,y=0,j=!1;while(!0){if(n>=r.length)throw Error("Cannot decode name (buffer overflow)");let A=r[n++];if(y+=j?0:1,A===0)break;else if((A&192)===0){if(n+A>r.length)throw Error("Cannot decode name (buffer overflow)");if(l+=A+1,l>254)throw Error("Cannot decode name (name too long)");let S=r.toString("utf-8",n,n+A);if(i)S=S.replace(/\./g,"\\.");m.push(S),n+=A,y+=j?0:A}else if((A&192)===192){if(n+1>r.length)throw Error("Cannot decode name (buffer overflow)");let S=r.readUInt16BE(n-1)-49152;if(S>=c)throw Error("Cannot decode name (bad pointer)");n=S,c=S,y+=j?0:1,j=!0}else throw Error("Cannot decode name (bad label)")}return R.decode.bytes=y,m.length===0?".":m.join(".")};R.decode.bytes=0;R.encodingLength=function(r){if(r==="."||r==="..")return 1;return Y.byteLength(r.replace(/^\.|\.$/gm,""))+2};var O={};O.encode=function(r,n,i){if(!n)n=Y.alloc(O.encodingLength(r));if(!i)i=0;let m=n.write(r,i+1);return n[i]=m,O.encode.bytes=m+1,n};O.encode.bytes=0;O.decode=function(r,n){if(!n)n=0;let i=r[n],m=r.toString("utf-8",n+1,n+1+i);return O.decode.bytes=i+1,m};O.decode.bytes=0;O.encodingLength=function(r){return Y.byteLength(r)+1};var ur={};ur.encode=function(r,n,i){if(!n)n=ur.encodingLength(r);if(!i)i=0;let m=(r.flags||0)&32767,c=r.type==="response"?32768:0;return n.writeUInt16BE(r.id||0,i),n.writeUInt16BE(m|c,i+2),n.writeUInt16BE(r.questions.length,i+4),n.writeUInt16BE(r.answers.length,i+6),n.writeUInt16BE(r.authorities.length,i+8),n.writeUInt16BE(r.additionals.length,i+10),n};ur.encode.bytes=12;ur.decode=function(r,n){if(!n)n=0;if(r.length<12)throw Error("Header must be 12 bytes");let i=r.readUInt16BE(n+2);return{id:r.readUInt16BE(n),type:i&32768?"response":"query",flags:i&32767,flag_qr:(i>>15&1)===1,opcode:HS.toString(i>>11&15),flag_aa:(i>>10&1)===1,flag_tc:(i>>9&1)===1,flag_rd:(i>>8&1)===1,flag_ra:(i>>7&1)===1,flag_z:(i>>6&1)===1,flag_ad:(i>>5&1)===1,flag_cd:(i>>4&1)===1,rcode:KS.toString(i&15),questions:Array(r.readUInt16BE(n+4)),answers:Array(r.readUInt16BE(n+6)),authorities:Array(r.readUInt16BE(n+8)),additionals:Array(r.readUInt16BE(n+10))}};ur.decode.bytes=12;ur.encodingLength=function(){return 12};var wn=YS.unknown={};wn.encode=function(r,n,i){if(!n)n=Y.alloc(wn.encodingLength(r));if(!i)i=0;return n.writeUInt16BE(r.length,i),r.copy(n,i+2),wn.encode.bytes=r.length+2,n};wn.encode.bytes=0;wn.decode=function(r,n){if(!n)n=0;let i=r.readUInt16BE(n),m=r.slice(n+2,n+2+i);return wn.decode.bytes=i+2,m};wn.decode.bytes=0;wn.encodingLength=function(r){return r.length+2};var $n=YS.ns={};$n.encode=function(r,n,i){if(!n)n=Y.alloc($n.encodingLength(r));if(!i)i=0;return R.encode(r,n,i+2),n.writeUInt16BE(R.encode.bytes,i),$n.encode.bytes=R.encode.bytes+2,n};$n.encode.bytes=0;$n.decode=function(r,n){if(!n)n=0;let i=r.readUInt16BE(n),m=R.decode(r,n+2);return $n.decode.bytes=i+2,m};$n.decode.bytes=0;$n.encodingLength=function(r){return R.encodingLength(r)+2};var Gn=YS.soa={};Gn.encode=function(r,n,i){if(!n)n=Y.alloc(Gn.encodingLength(r));if(!i)i=0;let m=i;return i+=2,R.encode(r.mname,n,i),i+=R.encode.bytes,R.encode(r.rname,n,i,{mail:!0}),i+=R.encode.bytes,n.writeUInt32BE(r.serial||0,i),i+=4,n.writeUInt32BE(r.refresh||0,i),i+=4,n.writeUInt32BE(r.retry||0,i),i+=4,n.writeUInt32BE(r.expire||0,i),i+=4,n.writeUInt32BE(r.minimum||0,i),i+=4,n.writeUInt16BE(i-m-2,m),Gn.encode.bytes=i-m,n};Gn.encode.bytes=0;Gn.decode=function(r,n){if(!n)n=0;let i=n,m={};return n+=2,m.mname=R.decode(r,n),n+=R.decode.bytes,m.rname=R.decode(r,n,{mail:!0}),n+=R.decode.bytes,m.serial=r.readUInt32BE(n),n+=4,m.refresh=r.readUInt32BE(n),n+=4,m.retry=r.readUInt32BE(n),n+=4,m.expire=r.readUInt32BE(n),n+=4,m.minimum=r.readUInt32BE(n),n+=4,Gn.decode.bytes=n-i,m};Gn.decode.bytes=0;Gn.encodingLength=function(r){return 22+R.encodingLength(r.mname)+R.encodingLength(r.rname)};var Nn=YS.txt={};Nn.encode=function(r,n,i){if(!Array.isArray(r))r=[r];for(let c=0;c<r.length;c++){if(typeof r[c]==="string")r[c]=Y.from(r[c]);if(!Y.isBuffer(r[c]))throw Error("Must be a Buffer")}if(!n)n=Y.alloc(Nn.encodingLength(r));if(!i)i=0;let m=i;return i+=2,r.forEach(function(c){n[i++]=c.length,c.copy(n,i,0,c.length),i+=c.length}),n.writeUInt16BE(i-m-2,m),Nn.encode.bytes=i-m,n};Nn.encode.bytes=0;Nn.decode=function(r,n){if(!n)n=0;let i=n,m=r.readUInt16BE(n);n+=2;let c=[];while(m>0){let l=r[n++];if(--m,m<l)throw Error("Buffer overflow");c.push(r.slice(n,n+l)),n+=l,m-=l}return Nn.decode.bytes=n-i,c};Nn.decode.bytes=0;Nn.encodingLength=function(r){if(!Array.isArray(r))r=[r];let n=2;return r.forEach(function(i){if(typeof i==="string")n+=Y.byteLength(i)+1;else n+=i.length+1}),n};var En=YS.null={};En.encode=function(r,n,i){if(!n)n=Y.alloc(En.encodingLength(r));if(!i)i=0;if(typeof r==="string")r=Y.from(r);if(!r)r=Y.alloc(0);let m=i;i+=2;let c=r.length;return r.copy(n,i,0,c),i+=c,n.writeUInt16BE(i-m-2,m),En.encode.bytes=i-m,n};En.encode.bytes=0;En.decode=function(r,n){if(!n)n=0;let i=n,m=r.readUInt16BE(n);n+=2;let c=r.slice(n,n+m);return n+=m,En.decode.bytes=n-i,c};En.decode.bytes=0;En.encodingLength=function(r){if(!r)return 2;return(Y.isBuffer(r)?r.length:Y.byteLength(r))+2};var Qn=YS.hinfo={};Qn.encode=function(r,n,i){if(!n)n=Y.alloc(Qn.encodingLength(r));if(!i)i=0;let m=i;return i+=2,O.encode(r.cpu,n,i),i+=O.encode.bytes,O.encode(r.os,n,i),i+=O.encode.bytes,n.writeUInt16BE(i-m-2,m),Qn.encode.bytes=i-m,n};Qn.encode.bytes=0;Qn.decode=function(r,n){if(!n)n=0;let i=n,m={};return n+=2,m.cpu=O.decode(r,n),n+=O.decode.bytes,m.os=O.decode(r,n),n+=O.decode.bytes,Qn.decode.bytes=n-i,m};Qn.decode.bytes=0;Qn.encodingLength=function(r){return O.encodingLength(r.cpu)+O.encodingLength(r.os)+2};var pr=YS.ptr={},RS=YS.cname=pr,VS=YS.dname=pr;pr.encode=function(r,n,i){if(!n)n=Y.alloc(pr.encodingLength(r));if(!i)i=0;return R.encode(r,n,i+2),n.writeUInt16BE(R.encode.bytes,i),pr.encode.bytes=R.encode.bytes+2,n};pr.encode.bytes=0;pr.decode=function(r,n){if(!n)n=0;let i=R.decode(r,n+2);return pr.decode.bytes=R.decode.bytes+2,i};pr.decode.bytes=0;pr.encodingLength=function(r){return R.encodingLength(r)+2};var Dn=YS.srv={};Dn.encode=function(r,n,i){if(!n)n=Y.alloc(Dn.encodingLength(r));if(!i)i=0;n.writeUInt16BE(r.priority||0,i+2),n.writeUInt16BE(r.weight||0,i+4),n.writeUInt16BE(r.port||0,i+6),R.encode(r.target,n,i+8);let m=R.encode.bytes+6;return n.writeUInt16BE(m,i),Dn.encode.bytes=m+2,n};Dn.encode.bytes=0;Dn.decode=function(r,n){if(!n)n=0;let i=r.readUInt16BE(n),m={};return m.priority=r.readUInt16BE(n+2),m.weight=r.readUInt16BE(n+4),m.port=r.readUInt16BE(n+6),m.target=R.decode(r,n+8),Dn.decode.bytes=i+2,m};Dn.decode.bytes=0;Dn.encodingLength=function(r){return 8+R.encodingLength(r.target)};var Zr=YS.caa={};Zr.ISSUER_CRITICAL=128;Zr.encode=function(r,n,i){let m=Zr.encodingLength(r);if(!n)n=Y.alloc(Zr.encodingLength(r));if(!i)i=0;if(r.issuerCritical)r.flags=Zr.ISSUER_CRITICAL;return n.writeUInt16BE(m-2,i),i+=2,n.writeUInt8(r.flags||0,i),i+=1,O.encode(r.tag,n,i),i+=O.encode.bytes,n.write(r.value,i),i+=Y.byteLength(r.value),Zr.encode.bytes=m,n};Zr.encode.bytes=0;Zr.decode=function(r,n){if(!n)n=0;let i=r.readUInt16BE(n);n+=2;let m=n,c={};return c.flags=r.readUInt8(n),n+=1,c.tag=O.decode(r,n),n+=O.decode.bytes,c.value=r.toString("utf-8",n,m+i),c.issuerCritical=!!(c.flags&Zr.ISSUER_CRITICAL),Zr.decode.bytes=i+2,c};Zr.decode.bytes=0;Zr.encodingLength=function(r){return O.encodingLength(r.tag)+O.encodingLength(r.value)+2};var Ln=YS.mx={};Ln.encode=function(r,n,i){if(!n)n=Y.alloc(Ln.encodingLength(r));if(!i)i=0;let m=i;return i+=2,n.writeUInt16BE(r.preference||0,i),i+=2,R.encode(r.exchange,n,i),i+=R.encode.bytes,n.writeUInt16BE(i-m-2,m),Ln.encode.bytes=i-m,n};Ln.encode.bytes=0;Ln.decode=function(r,n){if(!n)n=0;let i=n,m={};return n+=2,m.preference=r.readUInt16BE(n),n+=2,m.exchange=R.decode(r,n),n+=R.decode.bytes,Ln.decode.bytes=n-i,m};Ln.encodingLength=function(r){return 4+R.encodingLength(r.exchange)};var Un=YS.a={};Un.encode=function(r,n,i){if(!n)n=Y.alloc(Un.encodingLength(r));if(!i)i=0;return n.writeUInt16BE(4,i),i+=2,ri.v4.encode(r,n,i),Un.encode.bytes=6,n};Un.encode.bytes=0;Un.decode=function(r,n){if(!n)n=0;n+=2;let i=ri.v4.decode(r,n);return Un.decode.bytes=6,i};Un.decode.bytes=0;Un.encodingLength=function(){return 6};var Pn=YS.aaaa={};Pn.encode=function(r,n,i){if(!n)n=Y.alloc(Pn.encodingLength(r));if(!i)i=0;return n.writeUInt16BE(16,i),i+=2,ri.v6.encode(r,n,i),Pn.encode.bytes=18,n};Pn.encode.bytes=0;Pn.decode=function(r,n){if(!n)n=0;n+=2;let i=ri.v6.decode(r,n);return Pn.decode.bytes=18,i};Pn.decode.bytes=0;Pn.encodingLength=function(){return 18};var Kr=YS.option={};Kr.encode=function(r,n,i){if(!n)n=Y.alloc(Kr.encodingLength(r));if(!i)i=0;let m=i,c=gc.toCode(r.code);if(n.writeUInt16BE(c,i),i+=2,r.data)n.writeUInt16BE(r.data.length,i),i+=2,r.data.copy(n,i),i+=r.data.length;else switch(c){case 8:let l=r.sourcePrefixLength||0,y=r.family||ri.familyOf(r.ip),j=ri.encode(r.ip,Y.alloc),A=Math.ceil(l/8);n.writeUInt16BE(A+4,i),i+=2,n.writeUInt16BE(y,i),i+=2,n.writeUInt8(l,i++),n.writeUInt8(r.scopePrefixLength||0,i++),j.copy(n,i,0,A),i+=A;break;case 11:if(r.timeout)n.writeUInt16BE(2,i),i+=2,n.writeUInt16BE(r.timeout,i),i+=2;else n.writeUInt16BE(0,i),i+=2;break;case 12:let S=r.length||0;n.writeUInt16BE(S,i),i+=2,n.fill(0,i,i+S),i+=S;break;case 14:let v=r.tags.length*2;n.writeUInt16BE(v,i),i+=2;for(let w of r.tags)n.writeUInt16BE(w,i),i+=2;break;default:throw Error(`Unknown roption code: ${r.code}`)}return Kr.encode.bytes=i-m,n};Kr.encode.bytes=0;Kr.decode=function(r,n){if(!n)n=0;let i={};i.code=r.readUInt16BE(n),i.type=gc.toString(i.code),n+=2;let m=r.readUInt16BE(n);switch(n+=2,i.data=r.slice(n,n+m),i.code){case 8:i.family=r.readUInt16BE(n),n+=2,i.sourcePrefixLength=r.readUInt8(n++),i.scopePrefixLength=r.readUInt8(n++);let c=Y.alloc(i.family===1?4:16);r.copy(c,0,n,n+m-4),i.ip=ri.decode(c);break;case 11:if(m>0)i.timeout=r.readUInt16BE(n),n+=2;break;case 14:i.tags=[];for(let l=0;l<m;l+=2)i.tags.push(r.readUInt16BE(n)),n+=2}return Kr.decode.bytes=m+4,i};Kr.decode.bytes=0;Kr.encodingLength=function(r){if(r.data)return r.data.length+4;switch(gc.toCode(r.code)){case 8:let i=r.sourcePrefixLength||0;return Math.ceil(i/8)+8;case 11:return typeof r.timeout==="number"?6:4;case 12:return r.length+4;case 14:return 4+r.tags.length*2}throw Error(`Unknown roption code: ${r.code}`)};var Or=YS.opt={};Or.encode=function(r,n,i){if(!n)n=Y.alloc(Or.encodingLength(r));if(!i)i=0;let m=i,c=Gi(r,Kr);return n.writeUInt16BE(c,i),i=pi(r,Kr,n,i+2),Or.encode.bytes=i-m,n};Or.encode.bytes=0;Or.decode=function(r,n){if(!n)n=0;let i=n,m=[],c=r.readUInt16BE(n);n+=2;let l=0;while(c>0)m[l++]=Kr.decode(r,n),n+=Kr.decode.bytes,c-=Kr.decode.bytes;return Or.decode.bytes=n-i,m};Or.decode.bytes=0;Or.encodingLength=function(r){return 2+Gi(r||[],Kr)};var Ur=YS.dnskey={};Ur.PROTOCOL_DNSSEC=3;Ur.ZONE_KEY=128;Ur.SECURE_ENTRYPOINT=32768;Ur.encode=function(r,n,i){if(!n)n=Y.alloc(Ur.encodingLength(r));if(!i)i=0;let m=i,c=r.key;if(!Y.isBuffer(c))throw Error("Key must be a Buffer");return i+=2,n.writeUInt16BE(r.flags,i),i+=2,n.writeUInt8(Ur.PROTOCOL_DNSSEC,i),i+=1,n.writeUInt8(r.algorithm,i),i+=1,c.copy(n,i,0,c.length),i+=c.length,Ur.encode.bytes=i-m,n.writeUInt16BE(Ur.encode.bytes-2,m),n};Ur.encode.bytes=0;Ur.decode=function(r,n){if(!n)n=0;let i=n;var m={},c=r.readUInt16BE(n);if(n+=2,m.flags=r.readUInt16BE(n),n+=2,r.readUInt8(n)!==Ur.PROTOCOL_DNSSEC)throw Error("Protocol must be 3");return n+=1,m.algorithm=r.readUInt8(n),n+=1,m.key=r.slice(n,i+c+2),n+=m.key.length,Ur.decode.bytes=n-i,m};Ur.decode.bytes=0;Ur.encodingLength=function(r){return 6+Y.byteLength(r.key)};var sr=YS.rrsig={};sr.encode=function(r,n,i){if(!n)n=Y.alloc(sr.encodingLength(r));if(!i)i=0;let m=i,c=r.signature;if(!Y.isBuffer(c))throw Error("Signature must be a Buffer");return i+=2,n.writeUInt16BE(Cn.toType(r.typeCovered),i),i+=2,n.writeUInt8(r.algorithm,i),i+=1,n.writeUInt8(r.labels,i),i+=1,n.writeUInt32BE(r.originalTTL,i),i+=4,n.writeUInt32BE(r.expiration,i),i+=4,n.writeUInt32BE(r.inception,i),i+=4,n.writeUInt16BE(r.keyTag,i),i+=2,R.encode(r.signersName,n,i),i+=R.encode.bytes,c.copy(n,i,0,c.length),i+=c.length,sr.encode.bytes=i-m,n.writeUInt16BE(sr.encode.bytes-2,m),n};sr.encode.bytes=0;sr.decode=function(r,n){if(!n)n=0;let i=n;var m={},c=r.readUInt16BE(n);return n+=2,m.typeCovered=Cn.toString(r.readUInt16BE(n)),n+=2,m.algorithm=r.readUInt8(n),n+=1,m.labels=r.readUInt8(n),n+=1,m.originalTTL=r.readUInt32BE(n),n+=4,m.expiration=r.readUInt32BE(n),n+=4,m.inception=r.readUInt32BE(n),n+=4,m.keyTag=r.readUInt16BE(n),n+=2,m.signersName=R.decode(r,n),n+=R.decode.bytes,m.signature=r.slice(n,i+c+2),n+=m.signature.length,sr.decode.bytes=n-i,m};sr.decode.bytes=0;sr.encodingLength=function(r){return 20+R.encodingLength(r.signersName)+Y.byteLength(r.signature)};var fr=YS.rp={};fr.encode=function(r,n,i){if(!n)n=Y.alloc(fr.encodingLength(r));if(!i)i=0;let m=i;return i+=2,R.encode(r.mbox||".",n,i,{mail:!0}),i+=R.encode.bytes,R.encode(r.txt||".",n,i),i+=R.encode.bytes,fr.encode.bytes=i-m,n.writeUInt16BE(fr.encode.bytes-2,m),n};fr.encode.bytes=0;fr.decode=function(r,n){if(!n)n=0;let i=n,m={};return n+=2,m.mbox=R.decode(r,n,{mail:!0})||".",n+=R.decode.bytes,m.txt=R.decode(r,n)||".",n+=R.decode.bytes,fr.decode.bytes=n-i,m};fr.decode.bytes=0;fr.encodingLength=function(r){return 2+R.encodingLength(r.mbox||".")+R.encodingLength(r.txt||".")};var jr={};jr.encode=function(r,n,i){if(!n)n=Y.alloc(jr.encodingLength(r));if(!i)i=0;let m=i;var c=[];for(var l=0;l<r.length;l++){var y=Cn.toType(r[l]);if(c[y>>8]===void 0)c[y>>8]=[];c[y>>8][y>>3&31]|=1<<7-(y&7)}for(l=0;l<c.length;l++)if(c[l]!==void 0){var j=Y.from(c[l]);n.writeUInt8(l,i),i+=1,n.writeUInt8(j.length,i),i+=1,j.copy(n,i),i+=j.length}return jr.encode.bytes=i-m,n};jr.encode.bytes=0;jr.decode=function(r,n,i){if(!n)n=0;let m=n;var c=[];while(n-m<i){var l=r.readUInt8(n);n+=1;var y=r.readUInt8(n);n+=1;for(var j=0;j<y;j++){var A=r.readUInt8(n+j);for(var S=0;S<8;S++)if(A&1<<7-S){var v=Cn.toString(l<<8|j<<3|S);c.push(v)}}n+=y}return jr.decode.bytes=n-m,c};jr.decode.bytes=0;jr.encodingLength=function(r){var n=[];for(var i=0;i<r.length;i++){var m=Cn.toType(r[i]);n[m>>8]=Math.max(n[m>>8]||0,m&255)}var c=0;for(i=0;i<n.length;i++)if(n[i]!==void 0)c+=2+Math.ceil((n[i]+1)/8);return c};var rn=YS.nsec={};rn.encode=function(r,n,i){if(!n)n=Y.alloc(rn.encodingLength(r));if(!i)i=0;let m=i;return i+=2,R.encode(r.nextDomain,n,i),i+=R.encode.bytes,jr.encode(r.rrtypes,n,i),i+=jr.encode.bytes,rn.encode.bytes=i-m,n.writeUInt16BE(rn.encode.bytes-2,m),n};rn.encode.bytes=0;rn.decode=function(r,n){if(!n)n=0;let i=n;var m={},c=r.readUInt16BE(n);return n+=2,m.nextDomain=R.decode(r,n),n+=R.decode.bytes,m.rrtypes=jr.decode(r,n,c-(n-i)),n+=jr.decode.bytes,rn.decode.bytes=n-i,m};rn.decode.bytes=0;rn.encodingLength=function(r){return 2+R.encodingLength(r.nextDomain)+jr.encodingLength(r.rrtypes)};var nn=YS.nsec3={};nn.encode=function(r,n,i){if(!n)n=Y.alloc(nn.encodingLength(r));if(!i)i=0;let m=i,c=r.salt;if(!Y.isBuffer(c))throw Error("salt must be a Buffer");let l=r.nextDomain;if(!Y.isBuffer(l))throw Error("nextDomain must be a Buffer");return i+=2,n.writeUInt8(r.algorithm,i),i+=1,n.writeUInt8(r.flags,i),i+=1,n.writeUInt16BE(r.iterations,i),i+=2,n.writeUInt8(c.length,i),i+=1,c.copy(n,i,0,c.length),i+=c.length,n.writeUInt8(l.length,i),i+=1,l.copy(n,i,0,l.length),i+=l.length,jr.encode(r.rrtypes,n,i),i+=jr.encode.bytes,nn.encode.bytes=i-m,n.writeUInt16BE(nn.encode.bytes-2,m),n};nn.encode.bytes=0;nn.decode=function(r,n){if(!n)n=0;let i=n;var m={},c=r.readUInt16BE(n);n+=2,m.algorithm=r.readUInt8(n),n+=1,m.flags=r.readUInt8(n),n+=1,m.iterations=r.readUInt16BE(n),n+=2;let l=r.readUInt8(n);n+=1,m.salt=r.slice(n,n+l),n+=l;let y=r.readUInt8(n);return n+=1,m.nextDomain=r.slice(n,n+y),n+=y,m.rrtypes=jr.decode(r,n,c-(n-i)),n+=jr.decode.bytes,nn.decode.bytes=n-i,m};nn.decode.bytes=0;nn.encodingLength=function(r){return 8+r.salt.length+r.nextDomain.length+jr.encodingLength(r.rrtypes)};var mn=YS.ds={};mn.encode=function(r,n,i){if(!n)n=Y.alloc(mn.encodingLength(r));if(!i)i=0;let m=i,c=r.digest;if(!Y.isBuffer(c))throw Error("Digest must be a Buffer");return i+=2,n.writeUInt16BE(r.keyTag,i),i+=2,n.writeUInt8(r.algorithm,i),i+=1,n.writeUInt8(r.digestType,i),i+=1,c.copy(n,i,0,c.length),i+=c.length,mn.encode.bytes=i-m,n.writeUInt16BE(mn.encode.bytes-2,m),n};mn.encode.bytes=0;mn.decode=function(r,n){if(!n)n=0;let i=n;var m={},c=r.readUInt16BE(n);return n+=2,m.keyTag=r.readUInt16BE(n),n+=2,m.algorithm=r.readUInt8(n),n+=1,m.digestType=r.readUInt8(n),n+=1,m.digest=r.slice(n,i+c+2),n+=m.digest.length,mn.decode.bytes=n-i,m};mn.decode.bytes=0;mn.encodingLength=function(r){return 6+Y.byteLength(r.digest)};var Jr=YS.sshfp={};Jr.getFingerprintLengthForHashType=function(n){switch(n){case 1:return 20;case 2:return 32}};Jr.encode=function(n,i,m){if(!i)i=Y.alloc(Jr.encodingLength(n));if(!m)m=0;let c=m;m+=2,i[m]=n.algorithm,m+=1,i[m]=n.hash,m+=1;let l=Y.from(n.fingerprint.toUpperCase(),"hex");if(l.length!==Jr.getFingerprintLengthForHashType(n.hash))throw Error("Invalid fingerprint length");return l.copy(i,m),m+=l.byteLength,Jr.encode.bytes=m-c,i.writeUInt16BE(Jr.encode.bytes-2,c),i};Jr.encode.bytes=0;Jr.decode=function(n,i){if(!i)i=0;let m=i,c={};i+=2,c.algorithm=n[i],i+=1,c.hash=n[i],i+=1;let l=Jr.getFingerprintLengthForHashType(c.hash);return c.fingerprint=n.slice(i,i+l).toString("hex").toUpperCase(),i+=l,Jr.decode.bytes=i-m,c};Jr.decode.bytes=0;Jr.encodingLength=function(r){return 4+Y.from(r.fingerprint,"hex").byteLength};var cn=YS.naptr={};cn.encode=function(r,n,i){if(!n)n=Y.alloc(cn.encodingLength(r));if(!i)i=0;let m=i;return i+=2,n.writeUInt16BE(r.order||0,i),i+=2,n.writeUInt16BE(r.preference||0,i),i+=2,O.encode(r.flags,n,i),i+=O.encode.bytes,O.encode(r.services,n,i),i+=O.encode.bytes,O.encode(r.regexp,n,i),i+=O.encode.bytes,R.encode(r.replacement,n,i),i+=R.encode.bytes,cn.encode.bytes=i-m,n.writeUInt16BE(cn.encode.bytes-2,m),n};cn.encode.bytes=0;cn.decode=function(r,n){if(!n)n=0;let i=n,m={};return n+=2,m.order=r.readUInt16BE(n),n+=2,m.preference=r.readUInt16BE(n),n+=2,m.flags=O.decode(r,n),n+=O.decode.bytes,m.services=O.decode(r,n),n+=O.decode.bytes,m.regexp=O.decode(r,n),n+=O.decode.bytes,m.replacement=R.decode(r,n),n+=R.decode.bytes,cn.decode.bytes=n-i,m};cn.decode.bytes=0;cn.encodingLength=function(r){return O.encodingLength(r.flags)+O.encodingLength(r.services)+O.encodingLength(r.regexp)+R.encodingLength(r.replacement)+6};var ln=YS.tlsa={};ln.encode=function(r,n,i){if(!n)n=Y.alloc(ln.encodingLength(r));if(!i)i=0;let m=i,c=r.certificate;if(!Y.isBuffer(c))throw Error("Certificate must be a Buffer");return i+=2,n.writeUInt8(r.usage,i),i+=1,n.writeUInt8(r.selector,i),i+=1,n.writeUInt8(r.matchingType,i),i+=1,c.copy(n,i,0,c.length),i+=c.length,ln.encode.bytes=i-m,n.writeUInt16BE(ln.encode.bytes-2,m),n};ln.encode.bytes=0;ln.decode=function(r,n){if(!n)n=0;let i=n,m={},c=r.readUInt16BE(n);return n+=2,m.usage=r.readUInt8(n),n+=1,m.selector=r.readUInt8(n),n+=1,m.matchingType=r.readUInt8(n),n+=1,m.certificate=r.slice(n,i+c+2),n+=m.certificate.length,ln.decode.bytes=n-i,m};ln.decode.bytes=0;ln.encodingLength=function(r){return 5+Y.byteLength(r.certificate)};var Fc=YS.record=function(r){switch(r.toUpperCase()){case"A":return Un;case"PTR":return pr;case"CNAME":return RS;case"DNAME":return VS;case"TXT":return Nn;case"NULL":return En;case"AAAA":return Pn;case"SRV":return Dn;case"HINFO":return Qn;case"CAA":return Zr;case"NS":return $n;case"SOA":return Gn;case"MX":return Ln;case"OPT":return Or;case"DNSKEY":return Ur;case"RRSIG":return sr;case"RP":return fr;case"NSEC":return rn;case"NSEC3":return nn;case"SSHFP":return Jr;case"DS":return mn;case"NAPTR":return cn;case"TLSA":return ln}return wn},vr=YS.answer={};vr.encode=function(r,n,i){if(!n)n=Y.alloc(vr.encodingLength(r));if(!i)i=0;let m=i;if(R.encode(r.name,n,i),i+=R.encode.bytes,n.writeUInt16BE(Cn.toType(r.type),i),r.type.toUpperCase()==="OPT"){if(r.name!==".")throw Error("OPT name must be root.");n.writeUInt16BE(r.udpPayloadSize||4096,i+2),n.writeUInt8(r.extendedRcode||0,i+4),n.writeUInt8(r.ednsVersion||0,i+5),n.writeUInt16BE(r.flags||0,i+6),i+=8,Or.encode(r.options||[],n,i),i+=Or.encode.bytes}else{let c=dm.toClass(r.class===void 0?"IN":r.class);if(r.flush)c|=32768;n.writeUInt16BE(c,i+2),n.writeUInt32BE(r.ttl||0,i+4),i+=8;let l=Fc(r.type);l.encode(r.data,n,i),i+=l.encode.bytes}return vr.encode.bytes=i-m,n};vr.encode.bytes=0;vr.decode=function(r,n){if(!n)n=0;let i={},m=n;if(i.name=R.decode(r,n),n+=R.decode.bytes,i.type=Cn.toString(r.readUInt16BE(n)),i.type==="OPT")i.udpPayloadSize=r.readUInt16BE(n+2),i.extendedRcode=r.readUInt8(n+4),i.ednsVersion=r.readUInt8(n+5),i.flags=r.readUInt16BE(n+6),i.flag_do=(i.flags>>15&1)===1,i.options=Or.decode(r,n+8),n+=8+Or.decode.bytes;else{let c=r.readUInt16BE(n+2);i.ttl=r.readUInt32BE(n+4),i.class=dm.toString(c&-32769),i.flush=!!(c&32768);let l=Fc(i.type);i.data=l.decode(r,n+8),n+=8+l.decode.bytes}return vr.decode.bytes=n-m,i};vr.decode.bytes=0;vr.encodingLength=function(r){let n=r.data!==null&&r.data!==void 0?r.data:r.options;return R.encodingLength(r.name)+8+Fc(r.type).encodingLength(n)};var ar=YS.question={};ar.encode=function(r,n,i){if(!n)n=Y.alloc(ar.encodingLength(r));if(!i)i=0;let m=i;return R.encode(r.name,n,i),i+=R.encode.bytes,n.writeUInt16BE(Cn.toType(r.type),i),i+=2,n.writeUInt16BE(dm.toClass(r.class===void 0?"IN":r.class),i),i+=2,ar.encode.bytes=i-m,r};ar.encode.bytes=0;ar.decode=function(r,n){if(!n)n=0;let i=n,m={};if(m.name=R.decode(r,n),n+=R.decode.bytes,m.type=Cn.toString(r.readUInt16BE(n)),n+=2,m.class=dm.toString(r.readUInt16BE(n)),n+=2,!!(m.class&32768))m.class&=-32769;return ar.decode.bytes=n-i,m};ar.decode.bytes=0;ar.encodingLength=function(r){return R.encodingLength(r.name)+4};YS.AUTHORITATIVE_ANSWER=1024;YS.TRUNCATED_RESPONSE=512;YS.RECURSION_DESIRED=256;YS.RECURSION_AVAILABLE=128;YS.AUTHENTIC_DATA=32;YS.CHECKING_DISABLED=16;YS.DNSSEC_OK=32768;YS.encode=function(r,n,i){let m=!n;if(m)n=Y.alloc(YS.encodingLength(r));if(!i)i=0;let c=i;if(!r.questions)r.questions=[];if(!r.answers)r.answers=[];if(!r.authorities)r.authorities=[];if(!r.additionals)r.additionals=[];if(ur.encode(r,n,i),i+=ur.encode.bytes,i=pi(r.questions,ar,n,i),i=pi(r.answers,vr,n,i),i=pi(r.authorities,vr,n,i),i=pi(r.additionals,vr,n,i),YS.encode.bytes=i-c,m&&YS.encode.bytes!==n.length)return n.slice(0,YS.encode.bytes);return n};YS.encode.bytes=0;YS.decode=function(r,n){if(!n)n=0;let i=n,m=ur.decode(r,n);return n+=ur.decode.bytes,n=um(m.questions,ar,r,n),n=um(m.answers,vr,r,n),n=um(m.authorities,vr,r,n),n=um(m.additionals,vr,r,n),YS.decode.bytes=n-i,m};YS.decode.bytes=0;YS.encodingLength=function(r){return ur.encodingLength(r)+Gi(r.questions||[],ar)+Gi(r.answers||[],vr)+Gi(r.authorities||[],vr)+Gi(r.additionals||[],vr)};YS.streamEncode=function(r){let n=YS.encode(r),i=Y.alloc(2);i.writeUInt16BE(n.byteLength);let m=Y.concat([i,n]);return YS.streamEncode.bytes=m.byteLength,m};YS.streamEncode.bytes=0;YS.streamDecode=function(r){let n=r.readUInt16BE(0);if(r.byteLength<n+2)return null;let i=YS.decode(r.slice(2));return YS.streamDecode.bytes=YS.decode.bytes,i};YS.streamDecode.bytes=0;function Gi(r,n){let i=0;for(let m=0;m<r.length;m++)i+=n.encodingLength(r[m]);return i}function pi(r,n,i,m){for(let c=0;c<r.length;c++)n.encode(r[c],i,m),m+=n.encode.bytes;return m}function um(r,n,i,m){for(let c=0;c<r.length;c++)r[c]=n.decode(i,m),m+=n.decode.bytes;return m}});var Ij=nr((nD,jj)=>{var yj=BS;process.nextTick(hS,42);jj.exports=zS;function zS(r){var n=m;return i;function i(c){n(c||MS)}function m(c){var l=[c];n=y,r(j);function y(A){l.push(A)}function j(A){var S=arguments;n=oS(A)?m:v;while(l.length)v(l.shift());function v(w){yj(TS,w,S)}}}}function oS(r){return Object.prototype.toString.call(r)==="[object Error]"}function MS(){}function TS(r,n){r.apply(null,n)}function hS(r){if(r===42)yj=process.nextTick}function BS(r,n,i){process.nextTick(function(){r(n,i)})}});var vj=nr((iD,Sj)=>{var zc=lj(),xS=sn("dgram"),kS=Ij(),pS=sn("events"),Mc=sn("os"),oc=function(){};Sj.exports=function(r){if(!r)r={};var n=new pS.EventEmitter,i=typeof r.port==="number"?r.port:5353,m=r.type||"udp4",c=r.ip||r.host||(m==="udp4"?"224.0.0.251":null),l={address:c,port:i},y={},j=!1,A=null;if(m==="udp6"&&(!c||!r.interface))throw Error("For IPv6 multicast you must specify `ip` and `interface`");var S=r.socket||xS.createSocket({type:m,reuseAddr:r.reuseAddr!==!1,toString:function(){return m}});S.on("error",function(w){if(w.code==="EACCES"||w.code==="EADDRINUSE")n.emit("error",w);else n.emit("warning",w)}),S.on("message",function(w,N){try{w=zc.decode(w)}catch(E){n.emit("warning",E);return}if(n.emit("packet",w,N),w.type==="query")n.emit("query",w,N);if(w.type==="response")n.emit("response",w,N)}),S.on("listening",function(){if(!i)i=l.port=S.address().port;if(r.multicast!==!1)n.update(),A=setInterval(n.update,5000),S.setMulticastTTL(r.ttl||255),S.setMulticastLoopback(r.loopback!==!1)});var v=kS(function(w){if(!i||r.bind===!1)return w(null);S.once("error",w),S.bind(i,r.bind||r.interface,function(){S.removeListener("error",w),w(null)})});return v(function(w){if(w)return n.emit("error",w);n.emit("ready")}),n.send=function(w,N,E){if(typeof N==="function")return n.send(w,null,N);if(!E)E=oc;if(!N)N=l;else if(!N.host&&!N.address)N.address=l.address;v(Q);function Q(W){if(j)return E();if(W)return E(W);var H=zc.encode(w);S.send(H,0,H.length,N.port,N.address||N.host,E)}},n.response=n.respond=function(w,N,E){if(Array.isArray(w))w={answers:w};w.type="response",w.flags=(w.flags||0)|zc.AUTHORITATIVE_ANSWER,n.send(w,N,E)},n.query=function(w,N,E,Q){if(typeof N==="function")return n.query(w,null,null,N);if(typeof N==="object"&&N&&N.port)return n.query(w,null,N,E);if(typeof E==="function")return n.query(w,N,null,E);if(!Q)Q=oc;if(typeof w==="string")w=[{name:w,type:N||"ANY"}];if(Array.isArray(w))w={type:"query",questions:w};w.type="query",n.send(w,E,Q)},n.destroy=function(w){if(!w)w=oc;if(j)return process.nextTick(w);j=!0,clearInterval(A);for(var N in y)try{S.dropMembership(c,N)}catch(E){}y={},S.close(w)},n.update=function(){var w=r.interface?[].concat(r.interface):uS(),N=!1;for(var E=0;E<w.length;E++){var Q=w[E];if(y[Q])continue;try{S.addMembership(c,Q),y[Q]=!0,N=!0}catch(W){n.emit("warning",W)}}if(N){if(S.setMulticastInterface)try{S.setMulticastInterface(r.interface||aS())}catch(W){n.emit("warning",W)}n.emit("networkInterface")}},n};function aS(){var r=Mc.networkInterfaces(),n=Object.keys(r);for(var i=0;i<n.length;i++){var m=r[n[i]];for(var c=0;c<m.length;c++){var l=m[c];if(Aj(l.family)&&!l.internal){if(Mc.platform()==="darwin"&&n[i]==="en0")return l.address;return"0.0.0.0"}}}return"127.0.0.1"}function uS(){var r=Mc.networkInterfaces(),n=Object.keys(r),i=[];for(var m=0;m<n.length;m++){var c=r[n[m]];for(var l=0;l<c.length;l++){var y=c[l];if(Aj(y.family)){i.push(y.address);break}}}return i}function Aj(r){return r===4||r==="IPv4"}});var $j=nr((mD,wj)=>{wj.exports=function r(n,i){if(n===i)return!0;if(n&&i&&typeof n=="object"&&typeof i=="object"){if(n.constructor!==i.constructor)return!1;var m,c,l;if(Array.isArray(n)){if(m=n.length,m!=i.length)return!1;for(c=m;c--!==0;)if(!r(n[c],i[c]))return!1;return!0}if(n instanceof Map&&i instanceof Map){if(n.size!==i.size)return!1;for(c of n.entries())if(!i.has(c[0]))return!1;for(c of n.entries())if(!r(c[1],i.get(c[0])))return!1;return!0}if(n instanceof Set&&i instanceof Set){if(n.size!==i.size)return!1;for(c of n.entries())if(!i.has(c[0]))return!1;return!0}if(ArrayBuffer.isView(n)&&ArrayBuffer.isView(i)){if(m=n.length,m!=i.length)return!1;for(c=m;c--!==0;)if(n[c]!==i[c])return!1;return!0}if(n.constructor===RegExp)return n.source===i.source&&n.flags===i.flags;if(n.valueOf!==Object.prototype.valueOf)return n.valueOf()===i.valueOf();if(n.toString!==Object.prototype.toString)return n.toString()===i.toString();if(l=Object.keys(n),m=l.length,m!==Object.keys(i).length)return!1;for(c=m;c--!==0;)if(!Object.prototype.hasOwnProperty.call(i,l[c]))return!1;for(c=m;c--!==0;){var y=l[c];if(!r(n[y],i[y]))return!1}return!0}return n!==n&&i!==i}});var Gj=nr((ni)=>{var Tc=ni&&ni.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(ni,"__esModule",{value:!0});ni.Server=void 0;var dS=Tc(vj()),tS=Tc($j()),bS=Tc(pm());class hc{constructor(r,n){this.registry={},this.mdns=(0,dS.default)(r),this.mdns.setMaxListeners(0),this.mdns.on("query",this.respondToQuery.bind(this)),this.errorCallback=n!==null&&n!==void 0?n:function(i){throw i}}register(r){let n=(i)=>{var m=this.registry[i.type];if(!m)m=this.registry[i.type]=[];else if(m.some(this.isDuplicateRecord(i)))return;m.push(i)};if(Array.isArray(r))r.forEach(n);else n(r)}unregister(r){let n=(i)=>{let m=i.type;if(!(m in this.registry))return;this.registry[m]=this.registry[m].filter((c)=>c.name!==i.name)};if(Array.isArray(r))r.forEach(n);else n(r)}respondToQuery(r){let n=this;r.questions.forEach((i)=>{var{type:m,name:c}=i,l=m==="ANY"?Object.keys(n.registry).map(n.recordsFor.bind(n,c)).flat(1):n.recordsFor(c,m);if(l.length===0)return;var y=[];if(m!=="ANY")l.forEach((j)=>{if(j.type!=="PTR")return;y=y.concat(n.recordsFor(j.data,"SRV")).concat(n.recordsFor(j.data,"TXT"))}),y.filter(function(j){return j.type==="SRV"}).map(function(j){return j.data.target}).filter(this.unique()).forEach(function(j){y=y.concat(n.recordsFor(j,"A")).concat(n.recordsFor(j,"AAAA"))});n.mdns.respond({answers:l,additionals:y},(j)=>{if(j)this.errorCallback(j)})})}recordsFor(r,n){if(!(n in this.registry))return[];return this.registry[n].filter((i)=>{var m=~r.indexOf(".")?i.name:i.name.split(".")[0];return(0,bS.default)(m,r)})}isDuplicateRecord(r){return(n)=>{return r.type===n.type&&r.name===n.name&&(0,tS.default)(r.data,n.data)}}unique(){var r=[];return(n)=>{if(~r.indexOf(n))return!1;return r.push(n),!0}}}ni.Server=hc;ni.default=hc});var Ej=nr((Nj)=>{Object.defineProperty(Nj,"__esModule",{value:!0});Nj.default=(r,n)=>{if(n===void 0)return!0;let i=r.txt,m=Object.entries(n).map(([c,l])=>{let y=i[c];if(y===void 0)return!1;if(l!=y)return!1;return!0});if(m.length==0)return!0;if(m.includes(!1))return!1;return!0}});var Dj=nr((Qj)=>{Object.defineProperty(Qj,"__esModule",{value:!0});Qj.default=(r)=>Object.keys(r).filter((n)=>!n.includes("binary")).reduce((n,i)=>{return Object.assign(n,{[i]:r[i]})},{})});var Pj=nr((Uj)=>{Object.defineProperty(Uj,"__esModule",{value:!0});Uj.default=fS;function fS(r,n){if(r===void 0||n===void 0)return!1;let i=Object.keys(r),m=Object.keys(n);if(i.length!=m.length)return!1;for(let c of i)if(r[c]!=n[c])return!1;return!0}});var Xj=nr((ii)=>{var ui=ii&&ii.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(ii,"__esModule",{value:!0});ii.Browser=void 0;var nv=ui(Rc()),qn=ui(pm()),iv=sn("events"),Bc=Vc(),Cj=ui(Ej()),mv=ui(Dj()),cv=ui(Pj()),Wj=".local",lv="_services._dns-sd._udp"+Wj;class tm extends iv.EventEmitter{constructor(r,n,i){super();if(this.onresponse=void 0,this.serviceMap={},this.wildcard=!1,this._services=[],typeof n==="function")return new tm(r,null,n);if(this.mdns=r,this.txt=new nv.default(n!==null&&n.txt!=null?n.txt:void 0),n===null||n.type===void 0)this.name=lv,this.wildcard=!0;else{if(this.name=(0,Bc.toString)({name:n.type,protocol:n.protocol||"tcp"})+Wj,n.name)this.name=n.name+"."+this.name;this.wildcard=!1}if(n!=null&&n.txt!==void 0)this.txtQuery=(0,mv.default)(n.txt);if(i)this.on("up",i);this.start()}start(){if(this.onresponse||this.name===void 0)return;var r=this,n={};if(!this.wildcard)n[this.name]=!0;this.onresponse=(i,m)=>{if(r.wildcard)i.answers.forEach((c)=>{if(c.type!=="PTR"||c.name!==r.name||c.name in n)return;n[c.data]=!0,r.mdns.query(c.data,"PTR")});Object.keys(n).forEach(function(c){r.goodbyes(c,i).forEach(r.removeService.bind(r));var l=r.buildServicesFor(c,i,r.txt,m);if(l.length===0)return;l.forEach((y)=>{if(r.serviceMap[y.fqdn]){r.updateService(y);return}r.addService(y)})})},this.mdns.on("response",this.onresponse),this.update()}stop(){if(!this.onresponse)return;this.mdns.removeListener("response",this.onresponse),this.onresponse=void 0}update(){this.mdns.query(this.name,"PTR")}get services(){return this._services}addService(r){if((0,Cj.default)(r,this.txtQuery)===!1)return;this._services.push(r),this.serviceMap[r.fqdn]=!0,this.emit("up",r)}updateService(r){var n;if((0,cv.default)(r.txt,((n=this._services.find((i)=>(0,qn.default)(i.fqdn,r.fqdn)))===null||n===void 0?void 0:n.txt)||{}))return;if(!(0,Cj.default)(r,this.txtQuery)){this.removeService(r.fqdn);return}this._services=this._services.map(function(i){if(!(0,qn.default)(i.fqdn,r.fqdn))return i;return r}),this.emit("txt-update",r)}removeService(r){var n,i;if(this._services.some(function(m,c){if((0,qn.default)(m.fqdn,r))return n=m,i=c,!0}),!n||i===void 0)return;this._services.splice(i,1),delete this.serviceMap[r],this.emit("down",n)}goodbyes(r,n){return n.answers.concat(n.additionals).filter((i)=>i.type==="PTR"&&i.ttl===0&&(0,qn.default)(i.name,r)).map((i)=>i.data)}buildServicesFor(r,n,i,m){var c=n.answers.concat(n.additionals).filter((l)=>l.ttl>0);return c.filter((l)=>l.type==="PTR"&&(0,qn.default)(l.name,r)).map((l)=>{let y={addresses:[],subtypes:[]};if(c.filter((j)=>{return j.type==="PTR"&&(0,qn.default)(j.data,l.data)&&j.name.includes("._sub")}).forEach((j)=>{let A=(0,Bc.toType)(j.name);y.subtypes.push(A.subtype)}),c.filter((j)=>{return(j.type==="SRV"||j.type==="TXT")&&(0,qn.default)(j.name,l.data)}).forEach((j)=>{if(j.type==="SRV"){var A=j.name.split("."),S=A[0],v=(0,Bc.toType)(A.slice(1,-1).join("."));y.name=S,y.fqdn=j.name,y.host=j.data.target,y.referer=m,y.port=j.data.port,y.type=v.name,y.protocol=v.protocol}else if(j.type==="TXT")y.rawTxt=j.data,y.txt=this.txt.decodeAll(j.data)}),!y.name)return;return c.filter((j)=>(j.type==="A"||j.type==="AAAA")&&(0,qn.default)(j.name,y.host)).forEach((j)=>y.addresses.push(j.data)),y}).filter((l)=>!!l)}}ii.Browser=tm;ii.default=tm});var Kj=nr((dr)=>{var bm=dr&&dr.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(dr,"__esModule",{value:!0});dr.Browser=dr.Service=dr.Bonjour=void 0;var yv=bm(by()),jv=bm(Gj()),xc=bm(Xj());dr.Browser=xc.default;var Iv=bm(Zc());dr.Service=Iv.default;class kc{constructor(r={},n){this.server=new jv.default(r,n),this.registry=new yv.default(this.server)}publish(r){return this.registry.publish(r)}unpublishAll(r){return this.registry.unpublishAll(r)}find(r=null,n){return new xc.default(this.server.mdns,r,n)}findOne(r=null,n=1e4,i){let m=new xc.default(this.server.mdns,r);var c;return m.once("up",(l)=>{if(c!==void 0)clearTimeout(c);if(m.stop(),i)i(l)}),c=setTimeout(()=>{if(m.stop(),i)i(null)},n),m}destroy(r){this.registry.destroy(),this.server.mdns.destroy(r)}}dr.Bonjour=kc;dr.default=kc});var bl={};Nr(bl,{url:()=>vA,openapi:()=>p$,listen:()=>a$,Server:()=>bl,Default:()=>x$});var cc=(r)=>{let n=r.split("/");if(n[0]==="")n.shift();return n},el=(r)=>{let{groups:n,path:i}=wA(r),m=cc(i);return $A(m,n)},wA=(r)=>{let n=[];return r=r.replace(/\{[^}]+\}/g,(i,m)=>{let c=`@${m}`;return n.push([c,i]),c}),{groups:n,path:r}},$A=(r,n)=>{for(let i=n.length-1;i>=0;i--){let[m]=n[i];for(let c=r.length-1;c>=0;c--)if(r[c].includes(m)){r[c]=r[c].replace(m,n[i][1]);break}}return r},gm={},sl=(r,n)=>{if(r==="*")return"*";let i=r.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);if(i){let m=`${r}#${n}`;if(!gm[m])if(i[2])gm[m]=n&&n[0]!==":"&&n[0]!=="*"?[m,i[1],new RegExp(`^${i[2]}(?=/${n})`)]:[r,i[1],new RegExp(`^${i[2]}$`)];else gm[m]=[r,i[1],!0];return gm[m]}return null},vi=(r,n)=>{try{return n(r)}catch{return r.replace(/(?:%[0-9A-Fa-f]{2})+/g,(i)=>{try{return n(i)}catch{return i}})}},fl=(r)=>vi(r,decodeURI),lc=(r)=>{let n=r.url,i=n.indexOf("/",n.indexOf(":")+4),m=i;for(;m<n.length;m++){let c=n.charCodeAt(m);if(c===37){let l=n.indexOf("?",m),y=n.indexOf("#",m),j=l===-1?y===-1?void 0:y:y===-1?l:Math.min(l,y),A=n.slice(i,j);return fl(A.includes("%25")?A.replace(/%25/g,"%2525"):A)}else if(c===63||c===35)break}return n.slice(i,m)};var ry=(r)=>{let n=lc(r);return n.length>1&&n.at(-1)==="/"?n.slice(0,-1):n},On=(r,n,...i)=>{if(i.length)n=On(n,...i);return`${r?.[0]==="/"?"":"/"}${r}${n==="/"?"":`${r?.at(-1)==="/"?"":"/"}${n?.[0]==="/"?n.slice(1):n}`}`},Fm=(r)=>{if(r.charCodeAt(r.length-1)!==63||!r.includes(":"))return null;let n=r.split("/"),i=[],m="";return n.forEach((c)=>{if(c!==""&&!/\:/.test(c))m+="/"+c;else if(/\:/.test(c))if(/\?/.test(c)){if(i.length===0&&m==="")i.push("/");else i.push(m);let l=c.replace("?","");m+="/"+l,i.push(m)}else m+="/"+c}),i.filter((c,l,y)=>y.indexOf(c)===l)},mc=(r)=>{if(!/[%+]/.test(r))return r;if(r.indexOf("+")!==-1)r=r.replace(/\+/g," ");return r.indexOf("%")!==-1?vi(r,oi):r},ny=(r,n,i)=>{let m;if(!i&&n&&!/[%+]/.test(n)){let y=r.indexOf("?",8);if(y===-1)return;if(!r.startsWith(n,y+1))y=r.indexOf(`&${n}`,y+1);while(y!==-1){let j=r.charCodeAt(y+n.length+1);if(j===61){let A=y+n.length+2,S=r.indexOf("&",A);return mc(r.slice(A,S===-1?void 0:S))}else if(j==38||isNaN(j))return"";y=r.indexOf(`&${n}`,y+1)}if(m=/[%+]/.test(r),!m)return}let c={};m??=/[%+]/.test(r);let l=r.indexOf("?",8);while(l!==-1){let y=r.indexOf("&",l+1),j=r.indexOf("=",l);if(j>y&&y!==-1)j=-1;let A=r.slice(l+1,j===-1?y===-1?void 0:y:j);if(m)A=mc(A);if(l=y,A==="")continue;let S;if(j===-1)S="";else if(S=r.slice(j+1,y===-1?void 0:y),m)S=mc(S);if(i){if(!(c[A]&&Array.isArray(c[A])))c[A]=[];c[A].push(S)}else c[A]??=S}return n?c[n]:c},iy=ny,my=(r,n)=>{return ny(r,n,!0)},oi=decodeURIComponent;var GA=/^[\w!#$%&'*.^`|~+-]+$/,NA=/^[ !#-:<-[\]-~]*$/,cy=(r)=>{let n=0,i=r.length;while(n<i){let m=r.charCodeAt(n);if(m!==32&&m!==9)break;n++}while(i>n){let m=r.charCodeAt(i-1);if(m!==32&&m!==9)break;i--}return n===0&&i===r.length?r:r.slice(n,i)},yc=(r,n)=>{if(n&&r.indexOf(n)===-1)return{};let i=r.split(";"),m=Object.create(null);for(let c of i){let l=c.indexOf("=");if(l===-1)continue;let y=cy(c.substring(0,l));if(n&&n!==y||!GA.test(y)||y in m)continue;let j=cy(c.substring(l+1));if(j.startsWith('"')&&j.endsWith('"'))j=j.slice(1,-1);if(NA.test(j)){if(m[y]=j.indexOf("%")!==-1?vi(j,oi):j,n)break}}return m};var ly=(r,n,i)=>{let m=r.req.raw.headers.get("Cookie");if(typeof n==="string"){if(!m)return;let l=n;if(i==="secure")l="__Secure-"+n;else if(i==="host")l="__Host-"+n;return yc(m,l)[l]}if(!m)return{};return yc(m)};var kr=class extends Error{res;status;constructor(r=500,n){super(n?.message,{cause:n?.cause});this.res=n?.res,this.status=r}getResponse(){if(this.res)return new Response(this.res.body,{status:this.status,headers:this.res.headers});return new Response(this.message,{status:this.status})}};var jc=async(r)=>{return await EA(r,{name:"SHA-256",alias:"sha256"})};var EA=async(r,n)=>{let i;if(ArrayBuffer.isView(r)||r instanceof ArrayBuffer)i=r;else{if(typeof r==="object")r=JSON.stringify(r);i=new TextEncoder().encode(String(r))}if(crypto&&crypto.subtle){let m=await crypto.subtle.digest({name:n.name},i);return Array.prototype.map.call(new Uint8Array(m),(l)=>("00"+l.toString(16)).slice(-2)).join("")}return null};var yy=(r,n)=>{let i=r.length,m=n.length,c=Math.max(i,m),l=i^m;for(let y=0;y<c;y++){let j=y<i?r.charCodeAt(y):0,A=y<m?n.charCodeAt(y):0;l|=j^A}return l===0},jy=async(r,n,i)=>{if(!i)i=jc;let[m,c]=await Promise.all([i(r),i(n)]);if(m==null||c==null||typeof m!=="string"||typeof c!=="string")return!1;let l=yy(m,c),y=yy(r,n);return l&&y},Ic=async(r,n,i)=>{if(typeof r==="string"&&typeof n==="string")return jy(r,n,i);if(!i)i=jc;let[m,c]=await Promise.all([i(r),i(n)]);if(!m||!c||typeof m!=="string"||typeof c!=="string")return!1;return jy(m,c)};var zm=(r,n)=>{return new Response(r,{headers:{"Content-Type":n.replace(/^[^;]+/,(m)=>m.toLowerCase())}}).formData()};var QA=/^application\/([a-z-\.]+\+)?json(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/i,DA=/^multipart\/form-data(;\s?boundary=[a-zA-Z0-9'"()+_,\-./:=?]+)?$/i,UA=/^application\/x-www-form-urlencoded(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/i,Ac=(r,n)=>{return async(i,m)=>{let c={},l=i.req.header("Content-Type");switch(r){case"json":if(!l||!QA.test(l))break;try{c=await i.req.json()}catch{throw new kr(400,{message:"Malformed JSON in request body"})}break;case"form":{if(!l||!(DA.test(l)||UA.test(l)))break;let j;if(i.req.bodyCache.formData)j=await i.req.bodyCache.formData;else try{let S=await i.req.arrayBuffer();j=await zm(S,l),i.req.bodyCache.formData=j}catch(S){let v="Malformed FormData request.";throw v+=S instanceof Error?` ${S.message}`:` ${String(S)}`,new kr(400,{message:v})}let A=Object.create(null);j.forEach((S,v)=>{if(v.endsWith("[]"))(A[v]??=[]).push(S);else if(Array.isArray(A[v]))A[v].push(S);else if(Object.hasOwn(A,v))A[v]=[A[v],S];else A[v]=S}),c=A;break}case"query":c=Object.fromEntries(Object.entries(i.req.queries()).map(([j,A])=>{return A.length===1?[j,A[0]]:[j,A]}));break;case"param":c=i.req.param();break;case"header":c=i.req.header();break;case"cookie":c=ly(i);break}let y=await n(c,i);if(y instanceof Response)return y;return i.req.addValidatedData(r,y),await m()}};var Iy={header:["cookie"]};function PA(r,n,i){if(!(i in Iy))return r;let m=Iy[i]||[];if(n==="arktype")return CA(r,m);if(n==="valibot")return WA(r,m);return r}function CA(r,n){return r.map((i)=>{if(i&&typeof i==="object"&&"data"in i&&typeof i.data==="object"&&i.data!==null&&!Array.isArray(i.data)){let m={...i.data};for(let l of n)delete m[l];let c=Object.create(Object.getPrototypeOf(i));return Object.assign(c,i,{data:m}),c}return i})}function WA(r,n){return r.map((i)=>{if(i&&typeof i==="object"&&"path"in i&&Array.isArray(i.path)){for(let m of i.path)if(typeof m==="object"&&"input"in m&&typeof m.input==="object"&&m.input!==null&&!Array.isArray(m.input))for(let c of n)delete m.input[c]}return i})}var Ay=(r,n,i)=>Ac(r,async(m,c)=>{let l=await n["~standard"].validate(m);if(i){let y=await i(l.issues?{data:m,error:l.issues,success:!1,target:r}:{data:m,success:!0,target:r},c);if(y){if(y instanceof Response)return y;if("response"in y)return y.response}}if(l.issues){let y=PA(l.issues,n["~standard"].vendor,r);return c.json({data:m,error:y,success:!1},400)}return l.value});var vc=Symbol("openapi"),KA=["GET","PUT","POST","DELETE","OPTIONS","HEAD","PATCH","TRACE"],HA=(r)=>r.split("/").map((n)=>{let i=n;if(i.startsWith(":")){let m=i.match(/^:([^{?]+)(?:{(.+)})?(\?)?$/);if(m)i=`{${m[1]}}`;else{if(i=i.slice(1,i.length),i.endsWith("?"))i=i.slice(0,-1);i=`{${i}}`}}return i}).join("/"),Sy=(r)=>r.charAt(0).toUpperCase()+r.slice(1),RA=(r)=>{let n=r.method.toLowerCase();if(r.path==="/")return`${n}Index`;for(let i of r.path.split("/"))if(i.charCodeAt(0)===123)n+=`By${Sy(i.slice(1,-1))}`;else n+=Sy(i);return n},VA=(r)=>("$ref"in r)?r.$ref:`${r.in} ${r.name}`;function vy(...r){let n=r.flatMap((i)=>i??[]).reduce((i,m)=>{return i.set(VA(m),m),i},new Map);return Array.from(n.values())}var wi=new Map;function YA(r){let n=[];for(let[i,m]of wi)if(m&&r.match(i))n.push(m);return n}function ZA(){wi.clear()}function wy(r,...n){return n.reduce((i,m)=>{if(!m||!i)return i;for(let[c,l]of Object.entries(m)){if(l==null)continue;if(c in i&&(typeof l==="object"||typeof l==="function"&&c==="operationId"))if(Array.isArray(l)){let y=[...i[c]??[],...l];if(c==="tags")i[c]=Array.from(new Set(y));else if(c==="parameters")i[c]=vy(y);else i[c]=y}else if(typeof l==="function")i[c]=l(r);else if(c==="parameters")i[c]=vy(i[c],l);else i[c]={...i[c],...l};else i[c]=l}return i},{operationId:RA(r)})}function $y({route:r,specs:n,paths:i}){let m=HA(r.path),c=r.method.toLowerCase();if(c==="all"){if(!n)return;if(wi.has(m)){let l=wi.get(m)??{};wi.set(m,wy(r,l,n))}else wi.set(m,n)}else{let l=YA(m);if(!(m in i))i[m]={};if(i[m])i[m][c]=wy(r,...l,i[m]?.[c],n)}}function JA(r,n){let{exclude:i,excludeStaticFile:m}=n.options,c={},l=Array.isArray(i)?i:[i];for(let[y,j]of Object.entries(r)){if(j==null)continue;if(l.some((v)=>{if(typeof v==="string")return y===v;return v.test(y)}))continue;if(y.includes("*")&&!y.includes("{"))continue;if(m){let v=y.includes("{"),N=(y.split("/").pop()||"").includes(".");if(!v&&N)continue}for(let v of Object.keys(j)){let w=j[v];if(w==null)continue;if(y.includes("{")){w.parameters=w.parameters?[...w.parameters]:[];let N=y.split("/").filter((E)=>E.startsWith("{")&&!w.parameters.find((Q)=>Q.in==="path"&&Q.name===E.slice(1,E.length-1)));for(let E of N){let Q=E.slice(1,E.length-1);if(w.parameters.findIndex((H)=>{if("$ref"in H){let X=H.$ref.split("/").pop();if(X){let K=n.components.parameters?.[X];if(K&&!("$ref"in K))return K.in==="path"&&K.name===Q}return!1}return H.in==="path"&&H.name===Q})===-1)w.parameters.push({schema:{type:"string"},in:"path",name:Q,required:!0})}}if(!w.responses)w.responses={200:{}}}c[y]=j}return c}var Gy={documentation:{},excludeStaticFile:!0,exclude:[],excludeMethods:["OPTIONS"],excludeTags:[]};function Qy(r,n){let i;return async(m)=>{if(i)return m.json(i);return i=await wc(r,n,m),m.json(i)}}async function wc(r,n=Gy,i){let m={components:{},options:{...Gy,...n}},c=m.options.documentation??{};ZA();let l=await OA(r,m);for(let j in l)for(let A in l[j])if(LA({valueOrFunc:l[j][A]?.hide,method:A,path:j,c:i}))l[j][A]=void 0;let y=$c(c.components,m.components);return{openapi:"3.1.0",...c,tags:c.tags?.filter((j)=>!m.options.excludeTags?.includes(j?.name)),info:{title:"Hono Documentation",description:"Development documentation",version:"0.0.0",...c.info},paths:{...JA(l,m),...c.paths},components:y}}async function OA(r,n){let i={};for(let m of r.routes){let c=m.handler[vc];if(!c){if(n.options.includeEmptyPaths)$y({route:m,paths:i});continue}let l=m.method;if(l!=="ALL"){if(n.options.excludeMethods?.includes(l))continue;if(!KA.includes(l))continue}let y=n.options.defaultOptions?.[l],{schema:j,components:A={}}=await qA(c,y);n.components=$c(n.components,A),$y({route:m,specs:j,paths:i})}return i}function LA(r){let{valueOrFunc:n,c:i,method:m,path:c}=r;if(n!=null){if(typeof n==="boolean")return n;if(typeof n==="function")return n({c:i,method:m,path:c})}return!1}async function qA(r,n){if("spec"in r){let c={},l={...n,...r.spec,responses:{...n?.responses,...r.spec.responses}};if(l.responses)for(let y of Object.keys(l.responses)){let j=l.responses[y];if(!j||!("content"in j))continue;for(let A of Object.keys(j.content??{})){let S=j.content?.[A];if(!S)continue;if(S.schema&&"toOpenAPISchema"in S.schema){let v=await S.schema.toOpenAPISchema();if(S.schema=v.schema,v.components)c=$c(c,v.components)}}}return{schema:l,components:c}}let i=await r.toOpenAPISchema(),m=n??{};if(r.target==="form"||r.target==="json"){let c=r.options?.media??r.target==="json"?"application/json":"multipart/form-data";if(!m.requestBody||!("content"in m.requestBody)||!m.requestBody.content)m.requestBody={content:{[c]:{schema:i.schema}}};else m.requestBody.content[c]={schema:i.schema}}else{let c=[];if("$ref"in i.schema){let y=i.schema.$ref.split("/").pop();if(y&&i.components?.schemas?.[y]){let j=i.components.schemas[y],A=Ny(r.target,j)[0];if(!i.components.parameters)i.components.parameters={};i.components.parameters[y]=A,delete i.components.schemas[y],c.push({$ref:`#/components/parameters/${y}`})}}else c=Ny(r.target,i.schema);m.parameters=c}return{schema:m,components:i.components}}function Ny(r,n){let i=[];for(let[m,c]of Object.entries(n.properties??{})){let l={in:r==="param"?"path":r,name:m,schema:c};if(n.required?.includes(m))l.required=!0;if(l.schema&&"description"in l.schema&&l.schema.description)l.description=l.schema.description,l.schema.description=void 0;i.push(l)}return i}function $c(...r){return r.reduce((n,i,m)=>{if(i==null||m===0)return n;if(n.schemas&&Object.keys(n.schemas).length>0||i.schemas&&Object.keys(i.schemas).length>0)n.schemas={...n.schemas,...i.schemas};if(n.parameters&&Object.keys(n.parameters).length>0||i.parameters&&Object.keys(i.parameters).length>0)n.parameters={...n.parameters,...i.parameters};return n},r[0]??{})}function $(r,n){return{vendor:r["~standard"].vendor,validate:r["~standard"].validate,toJSONSchema:(i)=>Ey(r,{...n,...i}),toOpenAPISchema:(i)=>Sc(r,{...n,...i})}}function D(r,n,i,m){let c=Ay(r,n,i);return Object.assign(c,{[vc]:{target:r,...$(n,m),options:m}})}function G(r){return Object.assign(async(i,m)=>{await m()},{[vc]:{spec:r}})}var Gc=(r,n,i)=>{return(m,c)=>{let l=-1;return y(0);async function y(j){if(j<=l)throw Error("next() called multiple times");l=j;let A,S=!1,v;if(r[j])v=r[j][0][0],m.req.routeIndex=j;else v=j===r.length&&c||void 0;if(v)try{A=await v(m,()=>y(j+1))}catch(w){if(w instanceof Error&&n)m.error=w,A=await n(w,m),S=!0;else throw w}else if(m.finalized===!1&&i)A=await i(m);if(A&&(m.finalized===!1||S))m.res=A;return m}}};var Dy=Symbol();var Nc=(r)=>("headers"in r),Uy=async(r,n=Object.create(null))=>{let{all:i=!1,dot:m=!1}=n,y=(Nc(r)?r.headers:r.raw.headers).get("Content-Type")?.split(";")[0].trim().toLowerCase();if(y==="multipart/form-data"||y==="application/x-www-form-urlencoded")return _A(r,{all:i,dot:m});return{}};async function _A(r,n){let i=Nc(r)?r.headers:r.raw.headers,m=await r.arrayBuffer(),c=zm(m,i.get("Content-Type")||"");if(!Nc(r))r.bodyCache.formData=c;let l=await c;if(l)return gA(l,n);return{}}function gA(r,n){let i=Object.create(null);if(r.forEach((m,c)=>{if(!(n.all||c.endsWith("[]")))i[c]=m;else FA(i,c,m)}),n.dot)Object.entries(i).forEach(([m,c])=>{if(m.includes("."))zA(i,m,c),delete i[m]});return i}var FA=(r,n,i)=>{if(r[n]!==void 0)if(Array.isArray(r[n]))r[n].push(i);else r[n]=[r[n],i];else if(!n.endsWith("[]"))r[n]=i;else r[n]=[i]},zA=(r,n,i)=>{if(/(?:^|\.)__proto__\./.test(n))return;let m=r,c=n.split(".");c.forEach((l,y)=>{if(y===c.length-1)m[l]=i;else{if(!m[l]||typeof m[l]!=="object"||Array.isArray(m[l])||m[l]instanceof File)m[l]=Object.create(null);m=m[l]}})};var Py=(r)=>vi(r,oi),Cy=class{raw;#r;#n;routeIndex=0;path;bodyCache={};constructor(r,n="/",i=[[]]){this.raw=r,this.path=n,this.#n=i,this.#r={}}param(r){return r?this.#i(r):this.#l()}#i(r){let n=this.#n[0][this.routeIndex][1][r],i=this.#c(n);return i&&/\%/.test(i)?Py(i):i}#l(){let r={},n=Object.keys(this.#n[0][this.routeIndex][1]);for(let i of n){let m=this.#c(this.#n[0][this.routeIndex][1][i]);if(m!==void 0)r[i]=/\%/.test(m)?Py(m):m}return r}#c(r){return this.#n[1]?this.#n[1][r]:r}query(r){return iy(this.url,r)}queries(r){return my(this.url,r)}header(r){if(r)return this.raw.headers.get(r)??void 0;let n={};return this.raw.headers.forEach((i,m)=>{n[m]=i}),n}async parseBody(r){return Uy(this,r)}#m=(r)=>{let{bodyCache:n,raw:i}=this,m=n[r];if(m)return m;let c=Object.keys(n)[0];if(c)return n[c].then((l)=>{if(c==="json")l=JSON.stringify(l);return new Response(l)[r]()});return n[r]=i[r]()};json(){return this.#m("text").then((r)=>JSON.parse(r))}text(){return this.#m("text")}arrayBuffer(){return this.#m("arrayBuffer")}bytes(){return this.#m("arrayBuffer").then((r)=>new Uint8Array(r))}blob(){return this.#m("blob")}formData(){return this.#m("formData")}addValidatedData(r,n){this.#r[r]=n}valid(r){return this.#r[r]}get url(){return this.raw.url}get method(){return this.raw.method}get[Dy](){return this.#n}get matchedRoutes(){return this.#n[0].map(([[,r]])=>r)}get routePath(){return this.#n[0].map(([[,r]])=>r)[this.routeIndex].path}};var om={Stringify:1,BeforeStream:2,Stream:3},Wy=(r,n)=>{let i=new String(r);return i.isEscaped=!0,i.callbacks=n,i};var Mi=async(r,n,i,m,c)=>{if(typeof r==="object"&&!(r instanceof String)){if(!(r instanceof Promise))r=r.toString();if(r instanceof Promise)r=await r}let l=r.callbacks;if(!l?.length)return Promise.resolve(r);if(c)c[0]+=r;else c=[r];let y=Promise.all(l.map((j)=>j({phase:n,buffer:c,context:m}))).then((j)=>Promise.all(j.filter(Boolean).map((A)=>Mi(A,n,!1,m,c))).then(()=>c[0]));if(i)return Wy(await y,l);else return y};var Xy="text/plain; charset=UTF-8",Ec=(r,n)=>{return{"Content-Type":r,...n}},Ti=(r,n)=>new Response(r,n),Qc=class{#r;#n;env={};#i;finalized=!1;error;#l;#c;#m;#S;#I;#A;#j;#v;#w;constructor(r,n){if(this.#r=r,n)this.#c=n.executionCtx,this.env=n.env,this.#A=n.notFoundHandler,this.#w=n.path,this.#v=n.matchResult}get req(){return this.#n??=new Cy(this.#r,this.#w,this.#v),this.#n}get event(){if(this.#c&&"respondWith"in this.#c)return this.#c;else throw Error("This context has no FetchEvent")}get executionCtx(){if(this.#c)return this.#c;else throw Error("This context has no ExecutionContext")}get res(){return this.#m||=Ti(null,{headers:this.#j??=new Headers})}set res(r){if(this.#m&&r){r=Ti(r.body,r);for(let[n,i]of this.#m.headers.entries()){if(n==="content-type")continue;if(n==="set-cookie"){let m=this.#m.headers.getSetCookie();r.headers.delete("set-cookie");for(let c of m)r.headers.append("set-cookie",c)}else r.headers.set(n,i)}}this.#m=r,this.finalized=!0}render=(...r)=>{return this.#I??=(n)=>this.html(n),this.#I(...r)};setLayout=(r)=>this.#S=r;getLayout=()=>this.#S;setRenderer=(r)=>{this.#I=r};header=(r,n,i)=>{if(this.finalized)this.#m=Ti(this.#m.body,this.#m);let m=this.#m?this.#m.headers:this.#j??=new Headers;if(n===void 0)m.delete(r);else if(i?.append)m.append(r,n);else m.set(r,n)};status=(r)=>{this.#l=r};set=(r,n)=>{this.#i??=new Map,this.#i.set(r,n)};get=(r)=>{return this.#i?this.#i.get(r):void 0};get var(){if(!this.#i)return{};return Object.fromEntries(this.#i)}#y(r,n,i){let m=this.#m?new Headers(this.#m.headers):this.#j??new Headers;if(typeof n==="object"&&"headers"in n){let l=n.headers instanceof Headers?n.headers:new Headers(n.headers);for(let[y,j]of l)if(y.toLowerCase()==="set-cookie")m.append(y,j);else m.set(y,j)}if(i)for(let[l,y]of Object.entries(i))if(typeof y==="string")m.set(l,y);else{m.delete(l);for(let j of y)m.append(l,j)}let c=typeof n==="number"?n:n?.status??this.#l;return Ti(r,{status:c,headers:m})}newResponse=(...r)=>this.#y(...r);body=(r,n,i)=>this.#y(r,n,i);text=(r,n,i)=>{return!this.#j&&!this.#l&&!n&&!i&&!this.finalized?new Response(r):this.#y(r,n,Ec(Xy,i))};json=(r,n,i)=>{return this.#y(JSON.stringify(r),n,Ec("application/json",i))};html=(r,n,i)=>{let m=(c)=>this.#y(c,n,Ec("text/html; charset=UTF-8",i));return typeof r==="object"?Mi(r,om.Stringify,!1,{}).then(m):m(r)};redirect=(r,n)=>{let i=String(r);return this.header("Location",!/[^\x00-\xFF]/.test(i)?i:encodeURI(i)),this.newResponse(null,n??302)};notFound=()=>{return this.#A??=()=>Ti(),this.#A(this)}};var B="ALL",Ky="all",Hy=["get","post","put","delete","options","patch"],Mm="Can not add a route since the matcher is already built.",Tm=class extends Error{};var Dc="__COMPOSED_HANDLER";var oA=(r)=>{return r.text("404 Not Found",404)},Ry=(r,n)=>{if("getResponse"in r){let i=r.getResponse();return n.newResponse(i.body,i)}return console.error(r),n.text("Internal Server Error",500)},Vy=class r{get;post;put;delete;options;patch;all;on;use;router;getPath;_basePath="/";#r="/";routes=[];constructor(n={}){[...Hy,Ky].forEach((l)=>{this[l]=(y,...j)=>{if(typeof y==="string")this.#r=y;else this.#l(l,this.#r,y);return j.forEach((A)=>{this.#l(l,this.#r,A)}),this}}),this.on=(l,y,...j)=>{for(let A of[y].flat()){this.#r=A;for(let S of[l].flat())j.map((v)=>{this.#l(S.toUpperCase(),this.#r,v)})}return this},this.use=(l,...y)=>{if(typeof l==="string")this.#r=l;else this.#r="*",y.unshift(l);return y.forEach((j)=>{this.#l(B,this.#r,j)}),this};let{strict:m,...c}=n;Object.assign(this,c),this.getPath=m??!0?n.getPath??lc:ry}#n(){let n=new r({router:this.router,getPath:this.getPath});return n.errorHandler=this.errorHandler,n.#i=this.#i,n.routes=this.routes,n}#i=oA;errorHandler=Ry;route(n,i){let m=this.basePath(n);return i.routes.map((c)=>{let l;if(i.errorHandler===Ry)l=c.handler;else l=async(y,j)=>(await Gc([],i.errorHandler)(y,()=>c.handler(y,j))).res,l[Dc]=c.handler;m.#l(c.method,c.path,l,c.basePath)}),this}basePath(n){let i=this.#n();return i._basePath=On(this._basePath,n),i}onError=(n)=>{return this.errorHandler=n,this};notFound=(n)=>{return this.#i=n,this};mount(n,i,m){let c,l;if(m)if(typeof m==="function")l=m;else if(l=m.optionHandler,m.replaceRequest===!1)c=(A)=>A;else c=m.replaceRequest;let y=l?(A)=>{let S=l(A);return Array.isArray(S)?S:[S]}:(A)=>{let S=void 0;try{S=A.executionCtx}catch{}return[A.env,S]};c||=(()=>{let A=On(this._basePath,n),S=A==="/"?0:A.length;return(v)=>{let w=new URL(v.url);return w.pathname=this.getPath(v).slice(S)||"/",new Request(w,v)}})();let j=async(A,S)=>{let v=await i(c(A.req.raw),...y(A));if(v)return v;await S()};return this.#l(B,On(n,"*"),j),this}#l(n,i,m,c){n=n.toUpperCase(),i=On(this._basePath,i);let l={basePath:c!==void 0?On(this._basePath,c):this._basePath,path:i,method:n,handler:m};this.router.add(n,i,[m,l]),this.routes.push(l)}#c(n,i){if(n instanceof Error)return this.errorHandler(n,i);throw n}#m(n,i,m,c){if(c==="HEAD")return(async()=>new Response(null,await this.#m(n,i,m,"GET")))();let l=this.getPath(n,{env:m}),y=this.router.match(c,l),j=new Qc(n,{path:l,matchResult:y,env:m,executionCtx:i,notFoundHandler:this.#i});if(y[0].length===1){let S;try{S=y[0][0][0][0](j,async()=>{j.res=await this.#i(j)})}catch(v){return this.#c(v,j)}return S instanceof Promise?S.then((v)=>v||(j.finalized?j.res:this.#i(j))).catch((v)=>this.#c(v,j)):S??this.#i(j)}let A=Gc(y[0],this.errorHandler,this.#i);return(async()=>{try{let S=await A(j);if(!S.finalized)throw Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");return S.res}catch(S){return this.#c(S,j)}})()}fetch=(n,...i)=>{return this.#m(n,i[1],i[0],n.method)};request=(n,i,m,c)=>{if(n instanceof Request)return this.fetch(i?new Request(n,i):n,m,c);return n=n.toString(),this.fetch(new Request(/^https?:\/\//.test(n)?n:`http://localhost${On("/",n)}`,i),m,c)};fire=()=>{addEventListener("fetch",(n)=>{n.respondWith(this.#m(n.request,n,void 0,n.request.method))})}};var hi=[];function hm(r,n){let i=this.buildAllMatchers(),m=(c,l)=>{let y=i[c]||i[B],j=y[2][l];if(j)return j;let A=l.match(y[0]);if(!A)return[[],hi];let S=A.indexOf("",1);return[y[1][S],A]};return this.match=m,m(r,n)}var Bm="[^/]+",Bi=".*",xi="(?:|/.*)",bn=Symbol(),MA=new Set(".\\+*[^]$()");function TA(r,n){if(r.length===1)return n.length===1?r<n?-1:1:-1;if(n.length===1)return 1;if(r===Bi||r===xi)return 1;else if(n===Bi||n===xi)return-1;if(r===Bm)return 1;else if(n===Bm)return-1;return r.length===n.length?r<n?-1:1:n.length-r.length}var Yy=class r{#r;#n;#i=Object.create(null);insert(n,i,m,c,l){if(n.length===0){if(this.#r!==void 0)throw bn;if(l)return;this.#r=i;return}let[y,...j]=n,A=y==="*"?j.length===0?["","",Bi]:["","",Bm]:y==="/*"?["","",xi]:y.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/),S;if(A){let v=A[1],w=A[2]||Bm;if(v&&A[2]){if(w===".*")throw bn;if(w=w.replace(/^\((?!\?:)(?=[^)]+\)$)/,"(?:"),/\((?!\?:)/.test(w))throw bn}if(S=this.#i[w],!S){if(Object.keys(this.#i).some((N)=>N!==Bi&&N!==xi))throw bn;if(l)return;if(S=this.#i[w]=new r,v!=="")S.#n=c.varIndex++}if(!l&&v!=="")m.push([v,S.#n])}else if(S=this.#i[y],!S){if(Object.keys(this.#i).some((v)=>v.length>1&&v!==Bi&&v!==xi))throw bn;if(l)return;S=this.#i[y]=new r}S.insert(j,i,m,c,l)}buildRegExpStr(){let i=Object.keys(this.#i).sort(TA).map((m)=>{let c=this.#i[m];return(typeof c.#n==="number"?`(${m})@${c.#n}`:MA.has(m)?`\\${m}`:m)+c.buildRegExpStr()});if(typeof this.#r==="number")i.unshift(`#${this.#r}`);if(i.length===0)return"";if(i.length===1)return i[0];return"(?:"+i.join("|")+")"}};var Zy=class{#r={varIndex:0};#n=new Yy;insert(r,n,i){let m=[],c=[];for(let y=0;;){let j=!1;if(r=r.replace(/\{[^}]+\}/g,(A)=>{let S=`@\\${y}`;return c[y]=[S,A],y++,j=!0,S}),!j)break}let l=r.match(/(?::[^\/]+)|(?:\/\*$)|./g)||[];for(let y=c.length-1;y>=0;y--){let[j]=c[y];for(let A=l.length-1;A>=0;A--)if(l[A].indexOf(j)!==-1){l[A]=l[A].replace(j,c[y][1]);break}}return this.#n.insert(l,n,m,this.#r,i),m}buildRegExp(){let r=this.#n.buildRegExpStr();if(r==="")return[/^$/,[],[]];let n=0,i=[],m=[];return r=r.replace(/#(\d+)|@(\d+)|\.\*\$/g,(c,l,y)=>{if(l!==void 0)return i[++n]=Number(l),"$()";if(y!==void 0)return m[Number(y)]=++n,"";return""}),[new RegExp(`^${r}`),i,m]}};var hA=[/^$/,[],Object.create(null)],Jy=Object.create(null);function Oy(r){return Jy[r]??=new RegExp(r==="*"?"":`^${r.replace(/\/\*$|([.\\+*[^\]$()])/g,(n,i)=>i?`\\${i}`:"(?:|/.*)")}$`)}function BA(){Jy=Object.create(null)}function xA(r){let n=new Zy,i=[];if(r.length===0)return hA;let m=r.map((S)=>[!/\*|\/:/.test(S[0]),...S]).sort(([S,v],[w,N])=>S?1:w?-1:v.length-N.length),c=Object.create(null);for(let S=0,v=-1,w=m.length;S<w;S++){let[N,E,Q]=m[S];if(N)c[E]=[Q.map(([H])=>[H,Object.create(null)]),hi];else v++;let W;try{W=n.insert(E,v,N)}catch(H){throw H===bn?new Tm(E):H}if(N)continue;i[v]=Q.map(([H,X])=>{let K=Object.create(null);X-=1;for(;X>=0;X--){let[J,q]=W[X];K[J]=q}return[H,K]})}let[l,y,j]=n.buildRegExp();for(let S=0,v=i.length;S<v;S++)for(let w=0,N=i[S].length;w<N;w++){let E=i[S][w]?.[1];if(!E)continue;let Q=Object.keys(E);for(let W=0,H=Q.length;W<H;W++)E[Q[W]]=j[E[Q[W]]]}let A=[];for(let S in y)A[S]=i[y[S]];return[l,A,c]}function $i(r,n){if(!r)return;for(let i of Object.keys(r).sort((m,c)=>c.length-m.length))if(Oy(i).test(n))return[...r[i]];return}var xm=class{name="RegExpRouter";#r;#n;constructor(){this.#r={[B]:Object.create(null)},this.#n={[B]:Object.create(null)}}add(r,n,i){let m=this.#r,c=this.#n;if(!m||!c)throw Error(Mm);if(!m[r])[m,c].forEach((j)=>{j[r]=Object.create(null),Object.keys(j[B]).forEach((A)=>{j[r][A]=[...j[B][A]]})});if(n==="/*")n="*";let l=(n.match(/\/:/g)||[]).length;if(/\*$/.test(n)){let j=Oy(n);if(r===B)Object.keys(m).forEach((A)=>{m[A][n]||=$i(m[A],n)||$i(m[B],n)||[]});else m[r][n]||=$i(m[r],n)||$i(m[B],n)||[];Object.keys(m).forEach((A)=>{if(r===B||r===A)Object.keys(m[A]).forEach((S)=>{j.test(S)&&m[A][S].push([i,l])})}),Object.keys(c).forEach((A)=>{if(r===B||r===A)Object.keys(c[A]).forEach((S)=>j.test(S)&&c[A][S].push([i,l]))});return}let y=Fm(n)||[n];for(let j=0,A=y.length;j<A;j++){let S=y[j];Object.keys(c).forEach((v)=>{if(r===B||r===v)c[v][S]||=[...$i(m[v],S)||$i(m[B],S)||[]],c[v][S].push([i,l-A+j+1])})}}match=hm;buildAllMatchers(){let r=Object.create(null);return Object.keys(this.#n).concat(Object.keys(this.#r)).forEach((n)=>{r[n]||=this.#i(n)}),this.#r=this.#n=void 0,BA(),r}#i(r){let n=[],i=r===B;if([this.#r,this.#n].forEach((m)=>{let c=m[r]?Object.keys(m[r]).map((l)=>[l,m[r][l]]):[];if(c.length!==0)i||=!0,n.push(...c);else if(r!==B)n.push(...Object.keys(m[B]).map((l)=>[l,m[B][l]]))}),!i)return null;else return xA(n)}};var kA=class{name="PreparedRegExpRouter";#r;#n;constructor(r,n){this.#r=r,this.#n=n}#i(r,n){let i=this.#r[r];i[1].forEach((m)=>m&&m.push(n)),Object.values(i[2]).forEach((m)=>m[0].push(n))}#l(r,n,i,m,c){let l=this.#r[r];if(!c)l[2][n][0].push([i,{}]);else m.forEach((y)=>{if(typeof y==="number")l[1][y].push([i,c]);else l[2][y||n][0].push([i,c])})}add(r,n,i){if(!this.#r[r]){let c=this.#r[B],l={};for(let y in c[2])l[y]=[c[2][y][0].slice(),hi];this.#r[r]=[c[0],c[1].map((y)=>Array.isArray(y)?y.slice():0),l]}if(n==="/*"||n==="*"){let c=[i,{}];if(r===B)for(let l in this.#r)this.#i(l,c);else this.#i(r,c);return}let m=this.#n[n];if(!m)throw Error(`Path ${n} is not registered`);for(let[c,l]of m)if(r===B)for(let y in this.#r)this.#l(y,n,i,c,l);else this.#l(r,n,i,c,l)}buildAllMatchers(){return this.#r}match=hm};var Uc=class{name="SmartRouter";#r=[];#n=[];constructor(r){this.#r=r.routers}add(r,n,i){if(!this.#n)throw Error(Mm);this.#n.push([r,n,i])}match(r,n){if(!this.#n)throw Error("Fatal error");let i=this.#r,m=this.#n,c=i.length,l=0,y;for(;l<c;l++){let j=i[l];try{for(let A=0,S=m.length;A<S;A++)j.add(...m[A]);y=j.match(r,n)}catch(A){if(A instanceof Tm)continue;throw A}this.match=j.match.bind(j),this.#r=[j],this.#n=void 0;break}if(l===c)throw Error("Fatal error");return this.name=`SmartRouter + ${this.activeRouter.name}`,y}get activeRouter(){if(this.#n||this.#r.length!==1)throw Error("No active router has been determined yet.");return this.#r[0]}};var ki=Object.create(null),pA=(r)=>{for(let n in r)return!0;return!1},Ly=class r{#r;#n;#i;#l=0;#c=ki;constructor(n,i,m){if(this.#n=m||Object.create(null),this.#r=[],n&&i){let c=Object.create(null);c[n]={handler:i,possibleKeys:[],score:0},this.#r=[c]}this.#i=[]}insert(n,i,m){this.#l=++this.#l;let c=this,l=el(i),y=[];for(let j=0,A=l.length;j<A;j++){let S=l[j],v=l[j+1],w=sl(S,v),N=Array.isArray(w)?w[0]:S;if(N in c.#n){if(c=c.#n[N],w)y.push(w[1]);continue}if(c.#n[N]=new r,w)c.#i.push(w),y.push(w[1]);c=c.#n[N]}return c.#r.push({[n]:{handler:m,possibleKeys:y.filter((j,A,S)=>S.indexOf(j)===A),score:this.#l}}),c}#m(n,i,m,c,l){for(let y=0,j=i.#r.length;y<j;y++){let A=i.#r[y],S=A[m]||A[B],v={};if(S!==void 0){if(S.params=Object.create(null),n.push(S),c!==ki||l&&l!==ki)for(let w=0,N=S.possibleKeys.length;w<N;w++){let E=S.possibleKeys[w],Q=v[S.score];S.params[E]=l?.[E]&&!Q?l[E]:c[E]??l?.[E],v[S.score]=!0}}}}search(n,i){let m=[];this.#c=ki;let l=[this],y=cc(i),j=[],A=y.length,S=null;for(let v=0;v<A;v++){let w=y[v],N=v===A-1,E=[];for(let W=0,H=l.length;W<H;W++){let X=l[W],K=X.#n[w];if(K)if(K.#c=X.#c,N){if(K.#n["*"])this.#m(m,K.#n["*"],n,X.#c);this.#m(m,K,n,X.#c)}else E.push(K);for(let J=0,q=X.#i.length;J<q;J++){let z=X.#i[J],L=X.#c===ki?{}:{...X.#c};if(z==="*"){let hr=X.#n["*"];if(hr)this.#m(m,hr,n,X.#c),hr.#c=L,E.push(hr);continue}let[rr,Tr,Yr]=z;if(!w&&!(Yr instanceof RegExp))continue;let k=X.#n[rr];if(Yr instanceof RegExp){if(S===null){S=Array(A);let Si=i[0]==="/"?1:0;for(let zi=0;zi<A;zi++)S[zi]=Si,Si+=y[zi].length+1}let hr=i.substring(S[v]),Jn=Yr.exec(hr);if(Jn){if(L[Tr]=Jn[0],this.#m(m,k,n,X.#c,L),Jn[0].length===hr.length&&k.#n["*"])this.#m(m,k.#n["*"],n,X.#c,L);if(pA(k.#n)){k.#c=L;let Si=Jn[0].match(/\//)?.length??0;(j[Si]||=[]).push(k)}continue}}if(Yr===!0||Yr.test(w))if(L[Tr]=w,N){if(this.#m(m,k,n,L,X.#c),k.#n["*"])this.#m(m,k.#n["*"],n,L,X.#c)}else k.#c=L,E.push(k)}}let Q=j.shift();l=Q?E.concat(Q):E}if(m.length>1)m.sort((v,w)=>{return v.score-w.score});return[m.map(({handler:v,params:w})=>[v,w])]}};var Pc=class{name="TrieRouter";#r;constructor(){this.#r=new Ly}add(r,n,i){let m=Fm(n);if(m){for(let c=0,l=m.length;c<l;c++)this.#r.insert(r,m[c],i);return}this.#r.insert(r,n,i)}match(r,n){return this.#r.search(r,n)}};var V=class extends Vy{constructor(r={}){super(r);this.router=r.router??new Uc({routers:[new xm,new Pc]})}};var Cc=/^\s*(?:text\/(?!event-stream(?:[;\s]|$))[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|msgpack|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|vnd\.msgpack|wasm|x-httpd-php|x-javascript|x-msgpack|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml|msgpack))(?:[;\s]|$)/i;var aA={br:".br",zstd:".zst",gzip:".gz"},aN=Object.keys(aA);var Wc="x-hono-disable-ssg",vE=(()=>{try{return new Response("SSG is disabled",{status:404,headers:{[Wc]:"true"}})}catch{return null}})();var{write:uE}=Bun;var qy=class{#r;constructor(r){this.#r=r,this.raw=r.raw,this.url=r.url?new URL(r.url):null,this.protocol=r.protocol??null}send(r,n){this.#r.send(r,n??{})}raw;binaryType="arraybuffer";get readyState(){return this.#r.readyState}url;protocol;close(r,n){this.#r.close(r,n)}},_y=(r)=>{return new MessageEvent("message",{data:r})},gy=(r)=>{return(...n)=>{if(typeof n[0]==="function"){let[i,m]=n;return async function(l,y){let j=await i(l),A=await r(l,j,m);if(A)return A;await y()}}else{let[i,m,c]=n;return(async()=>{let l=await r(i,m,c);if(!l)throw Error("Failed to upgrade WebSocket");return l})()}}};var km=(r)=>("server"in r.env)?r.env.server:r.env;var Xc=(r)=>{return new qy({send:(n,i)=>{r.send(n,i?.compress)},raw:r,readyState:r.readyState,url:r.data.url,protocol:r.data.protocol,close(n,i){r.close(n,i)}})},Fy=gy((r,n)=>{let i=km(r);if(!i)throw TypeError("env has to include the 2nd argument of fetch.");if(i.upgrade(r.req.raw,{data:{events:n,url:new URL(r.req.url),protocol:r.req.header("sec-websocket-protocol")?.split(",")[0]?.trim()??""}}))return new Response(null);return}),zy={open(r){let n=r.data.events;if(n.onOpen)n.onOpen(new Event("open"),Xc(r))},close(r,n,i){let m=r.data.events;if(m.onClose)m.onClose(new CloseEvent("close",{code:n,reason:i}),Xc(r))},message(r,n){let i=r.data.events;if(i.onMessage){let m=typeof n==="string"?n:n.buffer;i.onMessage(_y(m),Xc(r))}}},Kc=()=>({upgradeWebSocket:Fy,websocket:zy});var oy={create(r){let n=Kc();return{upgradeWebSocket:n.upgradeWebSocket,async listen(i){let m={fetch:r.fetch,hostname:i.hostname,idleTimeout:0,websocket:n.websocket},c=(y)=>{try{return Bun.serve({...m,port:y})}catch{return}},l=i.port===0?c(4096)??c(0):c(i.port);if(!l)throw Error(`Failed to start server on port ${i.port}`);if(!l.port)throw Error(`Failed to resolve server address for port ${i.port}`);return{port:l.port,stop(y){return Promise.resolve(l.stop(y))}}}}}};var Ei={};Nr(Ei,{unpublish:()=>Rj,publish:()=>Sv,MDNS:()=>Ei});var Hj=Av(Kj(),1),di=_.create({service:"mdns"}),yn,em;function Sv(r,n){if(em===r)return;if(yn)Rj();try{let i=n??"qitqode.local",m=`qitqode-${r}`;yn=new Hj.Bonjour;let c=yn.publish({name:m,type:"http",host:i,port:r,txt:{path:"/"}});c.on("up",()=>{di.info("mDNS service published",{name:m,port:r})}),c.on("error",(l)=>{di.error("mDNS service error",{error:l})}),em=r}catch(i){if(di.error("mDNS publish failed",{error:i}),yn)try{yn.destroy()}catch{}yn=void 0,em=void 0}}function Rj(){if(yn){try{yn.unpublishAll(),yn.destroy()}catch(r){di.error("mDNS unpublish failed",{error:r})}yn=void 0,em=void 0,di.info("mDNS service unpublished")}}var Vj=(r)=>{let n=atob(r),i=new Uint8Array(new ArrayBuffer(n.length)),m=n.length/2;for(let c=0,l=n.length-1;c<=m;c++,l--)i[c]=n.charCodeAt(c),i[l]=n.charCodeAt(l);return i};var vv=/^ *(?:[Bb][Aa][Ss][Ii][Cc]) +([A-Za-z0-9._~+/-]+=*) *$/,wv=/^([^:]*):(.*)$/,$v=new TextDecoder,Yj=(r)=>{let n=vv.exec(r.headers.get("Authorization")||"");if(!n)return;let i=void 0;try{i=wv.exec($v.decode(Vj(n[1])))}catch{}if(!i)return;return{username:i[1],password:i[2]}};var Zj=(r,...n)=>{let i="username"in r&&"password"in r,m="verifyUser"in r;if(!(i||m))throw Error('basic auth middleware requires options for "username and password" or "verifyUser"');if(!r.realm)r.realm="Secure Area";if(!r.invalidUserMessage)r.invalidUserMessage="Unauthorized";if(i)n.unshift({username:r.username,password:r.password});return async function(l,y){let j=Yj(l.req.raw);if(j)if(m){if(await r.verifyUser(j.username,j.password,l)){if(r.onAuthSuccess)await r.onAuthSuccess(l,j.username);await y();return}}else for(let N of n){let[E,Q]=await Promise.all([Ic(N.username,j.username,r.hashFunction),Ic(N.password,j.password,r.hashFunction)]);if(E&&Q){if(r.onAuthSuccess)await r.onAuthSuccess(l,j.username);await y();return}}let A=401,S={"WWW-Authenticate":'Basic realm="'+r.realm?.replace(/"/g,"\\\"")+'"'},v=typeof r.invalidUserMessage==="function"?await r.invalidUserMessage(l):r.invalidUserMessage,w=typeof v==="string"?new Response(v,{status:A,headers:S}):new Response(JSON.stringify(v),{status:A,headers:{...S,"content-type":"application/json"}});throw new kr(A,{res:w})}};var Jj=(r)=>{let n={origin:"*",allowMethods:["GET","HEAD","PUT","POST","DELETE","PATCH"],allowHeaders:[],exposeHeaders:[],...r},i=((c)=>{if(typeof c==="string")if(c==="*")return()=>c;else return(l)=>c===l?l:null;else if(typeof c==="function")return c;else return(l)=>c.includes(l)?l:null})(n.origin),m=((c)=>{if(typeof c==="function")return c;else if(Array.isArray(c))return()=>c;else return()=>[]})(n.allowMethods);return async function(l,y){function j(S,v){l.res.headers.set(S,v)}let A=await i(l.req.header("origin")||"",l);if(A)j("Access-Control-Allow-Origin",A);if(n.credentials)j("Access-Control-Allow-Credentials","true");if(n.exposeHeaders?.length)j("Access-Control-Expose-Headers",n.exposeHeaders.join(","));if(l.req.method==="OPTIONS"){if(n.origin!=="*")j("Vary","Origin");if(n.maxAge!=null)j("Access-Control-Max-Age",n.maxAge.toString());let S=await m(l.req.header("origin")||"",l);if(S.length)j("Access-Control-Allow-Methods",S.join(","));let v=n.allowHeaders;if(!v?.length){let w=l.req.header("Access-Control-Request-Headers");if(w)v=w.split(/\s*,\s*/)}if(v?.length)j("Access-Control-Allow-Headers",v.join(",")),l.res.headers.append("Vary","Access-Control-Request-Headers");return l.res.headers.delete("Content-Length"),l.res.headers.delete("Content-Type"),new Response(null,{headers:l.res.headers,status:204,statusText:"No Content"})}if(await y(),n.origin!=="*")l.header("Vary","Origin",{append:!0})}};var Lj=(r)=>r===32||r===9||r===10||r===13,sm=(r,n)=>{while(n<r.length){if(!Lj(r.charCodeAt(n)))break;n++}return n},ti=(r,n)=>{while(n>0){if(!Lj(r.charCodeAt(n-1)))break;n--}return n},Oj=(r,n)=>{while(n<r.length){let i=r.charCodeAt(n);if(i===59)return[n+1,!0];if(i===44)return[n+1,!1];n++}return[n,!1]},Gv=(r,n)=>{let i=n,m=!1;while(i<r.length){let c=r.charCodeAt(i);if(m&&c===92)i++;else if(c===34)m=!m;else if(!m&&c===44)return i+1;i++}return i},Nv=(r,n)=>{n=sm(r,n);let i=n,m,c,l=!1;while(i<r.length){let A=r.charCodeAt(i);if(A===61){m=r.slice(n,ti(r,i)),i++;break}if(A===59)return[i+1,void 0,void 0,!0];if(A===44)return[i+1,void 0,void 0,!1];i++}if(m===void 0)return[i,void 0,void 0,!1];if(i=sm(r,i),r.charCodeAt(i)===61){let A=Oj(r,i+1);return[A[0],m,void 0,A[1]]}let y=!1,j=i;while(i<r.length){let A=r.charCodeAt(i);if(y&&A===92)i++;else if(A===34){if(y){let S=sm(r,i+1),v=r.charCodeAt(S);if(S<r.length&&!(v===59||v===44)){let w=Oj(r,S);return[w[0],m,void 0,w[1]]}if(c=r.slice(j+1,i),c.includes("\\"))c=c.replace(/\\(.)/g,"$1");if(v===44)return[S+1,m,c,!1];if(v===59)l=!0,S++;i=S;break}y=!0}else if(!y&&(A===59||A===44)){if(c=r.slice(j,ti(r,i)),A===59)l=!0;i++;break}i++}return[i,m,c??r.slice(j,ti(r,i)),l]},Ev=(r,n)=>{let i={type:"",params:{},q:1};n=sm(r,n);let m=n;while(m<r.length){let j=r.charCodeAt(m);if(j===59||j===44){if(i.type=r.slice(n,ti(r,m)),m++,j===44)return[m,i.type?i:void 0];if(!i.type)return[Gv(r,m),void 0];break}m++}if(!i.type)return i.type=r.slice(n,ti(r,r.length)),[r.length,i.type?i:void 0];let c,l,y;while(m<r.length){if([m,c,l,y]=Nv(r,m),c&&l)i.params[c]=l;if(!y)break}return[m,i]},qj=(r)=>{if(!r)return[];let n=[],i=0,m,c=!1,l;while(i<r.length)if([i,m]=Ev(r,i),m){if(m.q=Qv(m.params.q),n.push(m),l&&l.q<m.q)c=!0;l=m}if(c)n.sort((y,j)=>j.q-y.q);return n},Qv=(r)=>{if(r===void 0)return 1;if(r==="")return 1;if(r==="NaN")return 0;let n=Number(r);if(n===1/0)return 1;if(n===-1/0)return 0;if(Number.isNaN(n))return 1;if(n<0||n>1)return 1;return n};var Dv=["gzip","deflate"],Uv=/(?:^|,)\s*?no-transform\s*?(?:,|$)/i,Pv=(r,n)=>{if(r===void 0)return;let i=qj(r),m=i.find((l)=>l.type==="*")?.q,c;for(let l of n){let y=i.find((A)=>A.type.toLowerCase()===l),j=y?y.q:m??0;if(j===1)return l;else if(j>0&&(!c||j>c.q))c={encoding:l,q:j}}return c?.encoding},_j=(r)=>{let n=r?.threshold??1024,i=r?.encoding?[r.encoding]:Dv,m=r?.contentTypeFilter??Cc,c=typeof m==="function"?(l)=>{let y=l.headers.get("Content-Type");return y&&m(y)}:(l)=>{let y=l.headers.get("Content-Type");return y&&m.test(y)};return async function(y,j){await j();let A=y.res.headers.get("Content-Length");if(y.res.status===206||y.res.headers.has("Content-Encoding")||y.res.headers.has("Transfer-Encoding")||y.req.method==="HEAD"||A&&Number(A)<n||!c(y.res)||!Cv(y.res))return;let S=y.req.header("Accept-Encoding"),v=Pv(S,i);if(!v||!y.res.body)return;let w=new CompressionStream(v);y.res=new Response(y.res.body.pipeThrough(w),y.res),y.res.headers.delete("Content-Length"),y.res.headers.set("Content-Encoding",v);let N=y.res.headers.get("ETag");if(N&&!N.startsWith("W/"))y.res.headers.set("ETag",`W/${N}`)}},Cv=(r)=>{let n=r.headers.get("Cache-Control");return!n||!Uv.test(n)};import{randomUUID as Wv}from"crypto";var fm="ticket",gj="x-qitqode-ticket",Fj="1",Xv=/^\/pty\/[^/]+\/connect$/,Kv=60000,bi=new Map;function Hv(){let r=Date.now();for(let[n,i]of bi)if(i.expiresAt<=r)bi.delete(n)}function zj(r){return Xv.test(r)}function oj(r,n=Kv){Hv();let i=Wv();return bi.set(i,{ptyID:r,expiresAt:Date.now()+n}),{ticket:i,expires_in:Math.round(n/1000)}}function Mj(r,n){let i=bi.get(r);if(!i)return!1;if(bi.delete(r),i.expiresAt<=Date.now())return!1;return i.ptyID===n}var n0=_.create({service:"server"}),hj=(r,n)=>{let i=Tj(r),m=i.errorID;n0.error("failed",{error_id:m,error:r});let c=()=>n.json(new r0.Unknown({message:"Internal server error",diagnostic:i}).toObject(),{status:500,headers:{"x-qitqode-error-id":m}});if(r instanceof r0){let l;if(r instanceof Wn)l=404;else if(r instanceof ir.ModelNotFoundError)l=400;else if(r.name==="ProviderAuthValidationFailed")l=400;else if(r.name.startsWith("Worktree"))l=400;else l=500;if(l===500)return c();return n.json(r.toObject(),{status:l,headers:{"x-qitqode-error-id":m}})}if(r instanceof Z.BusyError)return n.json(new r0.Unknown({message:r.message,diagnostic:i}).toObject(),{status:409,headers:{"x-qitqode-error-id":m}});if(r instanceof kr)return r.getResponse();return c()},Bj=(r,n)=>{if(r.req.method==="OPTIONS")return n();let i=p.QITQODE_SERVER_PASSWORD;if(!i)return n();let m=new URL(r.req.url).pathname;if(zj(m)&&r.req.query(fm))return n();let c=p.QITQODE_SERVER_USERNAME??"qitqode";return Zj({username:c,password:i})(r,n)},xj=async(r,n)=>{let i=r.req.path==="/log";if(!i)n0.info("request",{method:r.req.method,path:r.req.path});let m=n0.time("request",{method:r.req.method,path:r.req.path});if(await n(),!i)m.stop()};function kj(r){return Jj({maxAge:86400,origin(n){if(!n)return;if(r?.cors?.includes(n))return n}})}function Rv(r){return r==="localhost"||r==="::1"||/^127(\.\d{1,3}){3}$/.test(r)||r==="127.0.0.1"}function Vv(r){if(r.startsWith("[")){let n=r.indexOf("]");return n===-1?r:r.slice(1,n)}return r.split(":")[0]}function pj(r){let n=r.hostname===void 0,i=r.hostname==="0.0.0.0"||r.hostname==="::";return(m,c)=>{if(n||i)return c();let l=m.req.header("host");if(!l)return c();let y=Vv(l);if(Rv(y))return c();if(r.hostname&&y===r.hostname)return c();if(r.mdnsDomain&&y===r.mdnsDomain)return c();if(r.allowedHosts?.includes(y))return c();throw n0.warn("rejected request with unexpected Host header",{host:y}),new kr(403,{message:`Forbidden: unexpected Host header "${y}"`})}}var Yv=_j(),aj=(r,n)=>{let i=r.req.path,m=r.req.method;if(i==="/event"||i==="/global/event")return n();if(m==="POST"&&/\/session\/[^/]+\/(message|prompt_async)$/.test(i))return n();return Yv(r,n)};var a={};Nr(a,{waitForSync:()=>hv,status:()=>Mv,startWorkspaceSyncing:()=>ac,sessionRestore:()=>gv,remove:()=>zv,list:()=>Fv,isSyncing:()=>Tv,get:()=>i2,create:()=>qv,Workspace:()=>a,Info:()=>i0,Event:()=>si,ConnectionStatus:()=>n2});var uj=["forgewise"];var Zv=new TextEncoder;function Jv(r){return Zv.encode(r).byteLength}function dj(r,n=16384){let i=[...uj.filter((l)=>(l in r)),...Object.keys(r).filter((l)=>!uj.includes(l))],m={},c=0;for(let l of i){let y={...m,[l]:r[l]},j=JSON.stringify(y);if(Jv(j)>n)continue;m[l]=r[l],c+=1}if(c===0)return;return JSON.stringify(m)}var Hr=tj("workspace",{id:_n().$type().primaryKey(),type:_n().notNull(),name:_n().notNull().default(""),branch:_n(),directory:_n(),extra:_n({mode:"json"}),project_id:_n().$type().notNull().references(()=>bj.id,{onDelete:"cascade"})});async function ej(r,n,i){let m=r.getReader(),c=new TextDecoder,l="",y="",j=1000,A=()=>{m.cancel().catch(()=>{return})};if(n.addEventListener("abort",A),n.aborted)A();try{while(!n.aborted){let S=await m.read().catch(()=>({done:!0,value:void 0}));if(S.done)break;l+=c.decode(S.value,{stream:!0}),l=l.replace(/\r\n/g,`
|
|
2
|
+
import{kg as Ai,lg as t1,mg as b1,ng as k1,og as p1,pg as e1,qg as s1,rg as f1,sg as rA,tg as nA,ug as a1,xg as cA}from"./chunk-yhpwceqg.js";import{yg as Er,zg as L1}from"./chunk-878sb0es.js";import{Dg as W1}from"./chunk-f0x3q5dj.js";import{Ig as Sc}from"./chunk-5qhsfjzq.js";import{Kg as Ey}from"./chunk-4s1n38ds.js";import{Lg as r2}from"./chunk-76wm7tw8.js";import{$g as pn,Ah as e,Mg as Ml,Ng as zl,Og as dn,Pg as _i,Wg as Xr,Xg as Tl,Yg as Km,_g as Hm,ah as tn,bh as nm,dh as mm,fh as _r,gh as bc,jh as j1,kh as ql,mh as tc,nh as _l,oh as ol,ph as ji,qh as Ll,rh as Fl,sh as b0,th as Rm,vh as w1,wh as Dr,xh as Ii,yh as Wr}from"./chunk-6zdzbmzs.js";import{Aj as f0,Bj as qi,Cj as R1,Gj as fj,Gk as qr,Hj as tr,Hk as Fn,Ij as Rr,Ik as AA,Jj as D2,Kj as yr,Lj as br,Mj as vn,Nj as un,Nk as l1,Qj as Ym,Sk as ir,Tk as Cr,Uk as Ar,Wk as $2,Xk as I0,Yj as v1,Zj as s,_j as er,bl as Z,cl as cr,vj as wr,vk as Pi,wj as rm,wk as Qr,xj as J1,yj as O1}from"./chunk-5asf8f41.js";import{el as al,ol as uI}from"./chunk-2pw56zpj.js";import{Bl as mA,Cl as b,El as Wn,Gl as y0,Kl as Gr,Ml as o,pl as Lr,tl as bj,ul as mr,vl as Kn,wl as Hn}from"./chunk-rt49c6js.js";import{Yl as jn}from"./chunk-4gzggzc0.js";import{Bm as im,Cm as o1,Dm as M1,Hm as T1,Im as fi,Xm as l0,um as _n,wm as tj,zm as d}from"./chunk-31a47ptm.js";import{On as g}from"./chunk-3152y1q9.js";import{cp as P1,xp as C1}from"./chunk-6qwnty59.js";import{xr as bI,yr as eI,zr as Di}from"./chunk-kegvr7wt.js";import{Ir as fI,Jr as r1}from"./chunk-2tkgtasa.js";import{Pr as CI,Sr as Wi,cs as B0,ds as Pr,es as WI,fs as x0,gs as XI,hs as KI,is as HI,js as RI,ks as zr,ls as Ql,ms as k0,ns as VI,os as YI,ps as ZI,qs as JI,rs as p0,ss as OI,ts as sI,us as LI,vs as qI,ws as _I,xs as _2,ys as Im}from"./chunk-6cztstry.js";import{ct as r0}from"./chunk-fdmz0502.js";import{ft as lA,rt as aI}from"./chunk-mnjz8nqs.js";import{It as Tj,Kt as c0}from"./chunk-6yshpz0z.js";import{Pt as p,Yt as _}from"./chunk-5dvy83ms.js";import{cu as kl,du as IA,hu as Xn,mu as Zn}from"./chunk-ffx0cr44.js";import{nu as I}from"./chunk-33mzqyyb.js";import{Hz as In,gA as cI,hA as lI}from"./chunk-wfpnv00c.js";import{AC as u2,BC as Vn,BG as vI,BI as t2,BM as Pm,CI as S0,DA as An,DG as h0,DI as b2,DM as El,EI as Al,FA as Xl,FF as M,FI as Sl,FM as ml,GA as zn,GI as e2,HC as AI,HG as O0,HI as s2,II as X2,JI as ec,JM as K2,KA as x2,KI as wl,LI as f2,MA as C2,NG as Bn,OO as Fr,PK as PI,QO as cl,RO as R0,SG as wI,SM as Dm,UE as S1,UH as Pl,VC as MI,VO as F,XC as Tn,XM as sc,_G as Gl,_M as jm,bB as on,cC as Dl,dD as L2,dG as J0,dH as $m,dM as T0,eC as k2,eD as q2,eH as $I,eM as Nl,fF as Sm,fH as Ul,fN as Ri,gD as H0,gI as P,iH as o2,iM as rI,jG as t,jN as Ci,kC as p2,kI as GI,lC as a2,lN as gr,mD as d2,mI as NI,mJ as UI,nC as Qm,nI as Li,oC as $r,oI as Cl,pC as Y0,qG as vm,qM as nI,rC as Br,rG as wm,rI as EI,sC as Sn,sI as QI,sM as iI,tC as L0,tG as SI,tM as mI,vC as Um,vF as z2,wC as Il,xC as vl,xG as hn,xM as X0,yC as or,yI as DI,zC as Am,zF as Z0,zI as v0,zM as K0}from"./chunk-9kc2th5c.js";import{uP as Av,vP as nr,wP as Nr,yP as sn}from"./chunk-sh03ka27.js";var pm=nr((hy)=>{Object.defineProperty(hy,"__esModule",{value:!0});hy.default=tA;var My=/[A-Z]/g;function Ty(r){return r.toLowerCase()}function tA(r,n){let i=r.replace(My,Ty),m=n.replace(My,Ty);return i===m}});var Rc=nr((By)=>{Object.defineProperty(By,"__esModule",{value:!0});By.DnsTxt=void 0;class Hc{constructor(r={}){this.binary=r?r.binary:!1}encode(r={}){return Object.entries(r).map(([n,i])=>{let m=`${n}=${i}`;return Buffer.from(m)})}decode(r){var n={};try{let m=r.toString().split(/=(.+)/),c=m[0],l=m[1];n[c]=l}catch(i){}return n}decodeAll(r){return r.filter((n)=>n.length>1).map((n)=>this.decode(n)).reduce((n,i)=>{var m=n;let[c]=Object.keys(i),[l]=Object.values(i);return m[c]=l,m},{})}}By.DnsTxt=Hc;By.default=Hc});var Vc=nr((py)=>{Object.defineProperty(py,"__esModule",{value:!0});py.toType=py.toString=void 0;var ky=(r)=>{return"_"+r},sA=(r)=>{return["name","protocol","subtype"].includes(r)},fA=(r)=>{let n={name:r.name,protocol:r.protocol,subtype:r.subtype};return Object.entries(n).filter(([m,c])=>sA(m)&&c!==void 0).reduce((m,[c,l])=>{switch(typeof l){case"object":l.map((y)=>m.push(ky(y)));break;default:m.push(ky(l));break}return m},[]).join(".")};py.toString=fA;var rS=(r)=>{let n=r.split("."),i;for(let m in n){if(n[m][0]!=="_")continue;n[m]=n[m].slice(1)}if(n.includes("sub"))i=n.shift(),n.shift();return{name:n.shift(),protocol:n.shift()||null,subtype:i}};py.toType=rS});var Zc=nr((en)=>{var dy=en&&en.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(en,"__esModule",{value:!0});en.Service=void 0;var uy=dy(sn("os")),iS=dy(Rc()),mS=sn("events"),cS=Vc(),am=".local";class Yc extends mS.EventEmitter{constructor(r){super();if(this.probe=!0,this.published=!1,this.activated=!1,this.destroyed=!1,this.txtService=new iS.default,!r.name)throw Error("ServiceConfig requires `name` property to be set");if(!r.type)throw Error("ServiceConfig requires `type` property to be set");if(!r.port)throw Error("ServiceConfig requires `port` property to be set");this.name=r.name.split(".").join("-"),this.protocol=r.protocol||"tcp",this.type=(0,cS.toString)({name:r.type,protocol:this.protocol}),this.port=r.port,this.host=r.host||uy.default.hostname(),this.fqdn=`${this.name}.${this.type}${am}`,this.txt=r.txt,this.subtypes=r.subtypes,this.disableIPv6=!!r.disableIPv6}records(){var r=[this.RecordPTR(this),this.RecordSRV(this),this.RecordTXT(this)];for(let i of this.subtypes||[])r.push(this.RecordSubtypePTR(this,i));let n=Object.values(uy.default.networkInterfaces());for(let i of n){let m=i;for(let c of m){if(c.internal||c.mac==="00:00:00:00:00:00")continue;switch(c.family){case"IPv4":r.push(this.RecordA(this,c.address));break;case"IPv6":if(this.disableIPv6)break;r.push(this.RecordAAAA(this,c.address));break}}}return r}RecordPTR(r){return{name:`${r.type}${am}`,type:"PTR",ttl:28800,data:r.fqdn}}RecordSubtypePTR(r,n){return{name:`_${n}._sub.${r.type}${am}`,type:"PTR",ttl:28800,data:`${r.name}.${r.type}${am}`}}RecordSRV(r){return{name:r.fqdn,type:"SRV",ttl:120,data:{port:r.port,target:r.host}}}RecordTXT(r){return{name:r.fqdn,type:"TXT",ttl:4500,data:this.txtService.encode(r.txt)}}RecordA(r,n){return{name:r.host,type:"A",ttl:120,data:n}}RecordAAAA(r,n){return{name:r.host,type:"AAAA",ttl:120,data:n}}}en.Service=Yc;en.default=Yc});var by=nr((fn)=>{var ty=fn&&fn.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(fn,"__esModule",{value:!0});fn.Registry=void 0;var lS=ty(pm()),Jc=ty(Zc()),yS=3600000,jS=3,IS=function(){};class Oc{constructor(r){this.services=[],this.server=r}publish(r){function n(c,l,y){if(c.activated)return;if(c.activated=!0,l.services.push(c),!(c instanceof Jc.default))return;if(y===null||y===void 0?void 0:y.probe)l.probe(l.server.mdns,c,(j)=>{if(j){if(c.stop!==void 0)c.stop();console.log(Error("Service name is already in use on the network"));return}l.announce(l.server,c)});else l.announce(l.server,c)}function i(c,l,y){if(!y)y=IS;if(!c.activated)return process.nextTick(y);if(!(c instanceof Jc.default))return process.nextTick(y);l.teardown(l.server,c,y);let j=l.services.indexOf(c);if(j!==-1)l.services.splice(j,1)}let m=new Jc.default(r);return m.start=n.bind(null,m,this),m.stop=i.bind(null,m,this),m.start({probe:r.probe!==!1}),m}unpublishAll(r){this.teardown(this.server,this.services,r),this.services=[]}destroy(){this.services.map((r)=>r.destroyed=!0)}probe(r,n,i){var m=!1,c=0,l;let y=()=>{if(!n.activated||n.destroyed)return;r.query(n.fqdn,"ANY",function(){m=!0,l=setTimeout(++c<3?y:S,250),l.unref()})},j=(v)=>{if(!m)return;if(v.answers.some(A)||v.additionals.some(A))S(!0)},A=(v)=>{return(0,lS.default)(v.name,n.fqdn)},S=(v)=>{r.removeListener("response",j),clearTimeout(l),i(!!v)};r.on("response",j),setTimeout(y,Math.random()*250)}announce(r,n){var i=1000,m=n.records();r.register(m);let c=()=>{if(!n.activated||n.destroyed)return;r.mdns.respond(m,function(){if(!n.published)n.activated=!0,n.published=!0,n.emit("up");if(i=i*jS,i<yS&&!n.destroyed)setTimeout(c,i).unref()})};c()}teardown(r,n,i){if(!Array.isArray(n))n=[n];n=n.filter((c)=>c.activated);var m=n.flatMap(function(c){c.activated=!1;var l=c.records();return l.forEach((y)=>{y.ttl=0}),l});if(m.length===0)return i&&process.nextTick(i);r.unregister(m),r.mdns.respond(m,function(){if(n.forEach(function(c){c.published=!1}),typeof i==="function")i.apply(null,arguments)})}}fn.Registry=Oc;fn.default=Oc});var ey=nr((AS)=>{AS.toString=function(r){switch(r){case 1:return"A";case 10:return"NULL";case 28:return"AAAA";case 18:return"AFSDB";case 42:return"APL";case 257:return"CAA";case 60:return"CDNSKEY";case 59:return"CDS";case 37:return"CERT";case 5:return"CNAME";case 49:return"DHCID";case 32769:return"DLV";case 39:return"DNAME";case 48:return"DNSKEY";case 43:return"DS";case 55:return"HIP";case 13:return"HINFO";case 45:return"IPSECKEY";case 25:return"KEY";case 36:return"KX";case 29:return"LOC";case 15:return"MX";case 35:return"NAPTR";case 2:return"NS";case 47:return"NSEC";case 50:return"NSEC3";case 51:return"NSEC3PARAM";case 12:return"PTR";case 46:return"RRSIG";case 17:return"RP";case 24:return"SIG";case 6:return"SOA";case 99:return"SPF";case 33:return"SRV";case 44:return"SSHFP";case 32768:return"TA";case 249:return"TKEY";case 52:return"TLSA";case 250:return"TSIG";case 16:return"TXT";case 252:return"AXFR";case 251:return"IXFR";case 41:return"OPT";case 255:return"ANY"}return"UNKNOWN_"+r};AS.toType=function(r){switch(r.toUpperCase()){case"A":return 1;case"NULL":return 10;case"AAAA":return 28;case"AFSDB":return 18;case"APL":return 42;case"CAA":return 257;case"CDNSKEY":return 60;case"CDS":return 59;case"CERT":return 37;case"CNAME":return 5;case"DHCID":return 49;case"DLV":return 32769;case"DNAME":return 39;case"DNSKEY":return 48;case"DS":return 43;case"HIP":return 55;case"HINFO":return 13;case"IPSECKEY":return 45;case"KEY":return 25;case"KX":return 36;case"LOC":return 29;case"MX":return 15;case"NAPTR":return 35;case"NS":return 2;case"NSEC":return 47;case"NSEC3":return 50;case"NSEC3PARAM":return 51;case"PTR":return 12;case"RRSIG":return 46;case"RP":return 17;case"SIG":return 24;case"SOA":return 6;case"SPF":return 99;case"SRV":return 33;case"SSHFP":return 44;case"TA":return 32768;case"TKEY":return 249;case"TLSA":return 52;case"TSIG":return 250;case"TXT":return 16;case"AXFR":return 252;case"IXFR":return 251;case"OPT":return 41;case"ANY":return 255;case"*":return 255}if(r.toUpperCase().startsWith("UNKNOWN_"))return parseInt(r.slice(8));return 0}});var sy=nr((wS)=>{wS.toString=function(r){switch(r){case 0:return"NOERROR";case 1:return"FORMERR";case 2:return"SERVFAIL";case 3:return"NXDOMAIN";case 4:return"NOTIMP";case 5:return"REFUSED";case 6:return"YXDOMAIN";case 7:return"YXRRSET";case 8:return"NXRRSET";case 9:return"NOTAUTH";case 10:return"NOTZONE";case 11:return"RCODE_11";case 12:return"RCODE_12";case 13:return"RCODE_13";case 14:return"RCODE_14";case 15:return"RCODE_15"}return"RCODE_"+r};wS.toRcode=function(r){switch(r.toUpperCase()){case"NOERROR":return 0;case"FORMERR":return 1;case"SERVFAIL":return 2;case"NXDOMAIN":return 3;case"NOTIMP":return 4;case"REFUSED":return 5;case"YXDOMAIN":return 6;case"YXRRSET":return 7;case"NXRRSET":return 8;case"NOTAUTH":return 9;case"NOTZONE":return 10;case"RCODE_11":return 11;case"RCODE_12":return 12;case"RCODE_13":return 13;case"RCODE_14":return 14;case"RCODE_15":return 15}return 0}});var fy=nr((NS)=>{NS.toString=function(r){switch(r){case 0:return"QUERY";case 1:return"IQUERY";case 2:return"STATUS";case 3:return"OPCODE_3";case 4:return"NOTIFY";case 5:return"UPDATE";case 6:return"OPCODE_6";case 7:return"OPCODE_7";case 8:return"OPCODE_8";case 9:return"OPCODE_9";case 10:return"OPCODE_10";case 11:return"OPCODE_11";case 12:return"OPCODE_12";case 13:return"OPCODE_13";case 14:return"OPCODE_14";case 15:return"OPCODE_15"}return"OPCODE_"+r};NS.toOpcode=function(r){switch(r.toUpperCase()){case"QUERY":return 0;case"IQUERY":return 1;case"STATUS":return 2;case"OPCODE_3":return 3;case"NOTIFY":return 4;case"UPDATE":return 5;case"OPCODE_6":return 6;case"OPCODE_7":return 7;case"OPCODE_8":return 8;case"OPCODE_9":return 9;case"OPCODE_10":return 10;case"OPCODE_11":return 11;case"OPCODE_12":return 12;case"OPCODE_13":return 13;case"OPCODE_14":return 14;case"OPCODE_15":return 15}return 0}});var rj=nr((DS)=>{DS.toString=function(r){switch(r){case 1:return"IN";case 2:return"CS";case 3:return"CH";case 4:return"HS";case 255:return"ANY"}return"UNKNOWN_"+r};DS.toClass=function(r){switch(r.toUpperCase()){case"IN":return 1;case"CS":return 2;case"CH":return 3;case"HS":return 4;case"ANY":return 255}return 0}});var nj=nr((CS)=>{CS.toString=function(r){switch(r){case 1:return"LLQ";case 2:return"UL";case 3:return"NSID";case 5:return"DAU";case 6:return"DHU";case 7:return"N3U";case 8:return"CLIENT_SUBNET";case 9:return"EXPIRE";case 10:return"COOKIE";case 11:return"TCP_KEEPALIVE";case 12:return"PADDING";case 13:return"CHAIN";case 14:return"KEY_TAG";case 26946:return"DEVICEID"}if(r<0)return null;return`OPTION_${r}`};CS.toCode=function(r){if(typeof r==="number")return r;if(!r)return-1;switch(r.toUpperCase()){case"OPTION_0":return 0;case"LLQ":return 1;case"UL":return 2;case"NSID":return 3;case"OPTION_4":return 4;case"DAU":return 5;case"DHU":return 6;case"N3U":return 7;case"CLIENT_SUBNET":return 8;case"EXPIRE":return 9;case"COOKIE":return 10;case"TCP_KEEPALIVE":return 11;case"PADDING":return 12;case"CHAIN":return 13;case"KEY_TAG":return 14;case"DEVICEID":return 26946;case"OPTION_65535":return 65535}let n=r.match(/_(\d+)$/);if(n)return parseInt(n[1],10);return-1}});var cj=nr((mj,Lc)=>{var ij=function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.decode=w,r.encode=v,r.familyOf=S,r.name=void 0,r.sizeOf=A,r.v6=r.v4=void 0;let n=/^(\d{1,3}\.){3,3}\d{1,3}$/,i=4,m=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i,c=16,l={name:"v4",size:i,isFormat:(N)=>n.test(N),encode(N,E,Q){Q=~~Q,E=E||new Uint8Array(Q+i);let W=N.length,H=0;for(let X=0;X<W;){let K=N.charCodeAt(X++);if(K===46)E[Q++]=H,H=0;else H=H*10+(K-48)}return E[Q]=H,E},decode(N,E){return E=~~E,`${N[E++]}.${N[E++]}.${N[E++]}.${N[E]}`}};r.v4=l;let y={name:"v6",size:c,isFormat:(N)=>N.length>0&&m.test(N),encode(N,E,Q){Q=~~Q;let W=Q+c,H=-1,X=0,K=0,J=!0,q=!1;E=E||new Uint8Array(Q+c);for(let z=0;z<N.length;z++){let L=N.charCodeAt(z);if(L===58){if(J){if(H!==-1){if(Q<W)E[Q]=0;if(Q<W-1)E[Q+1]=0;Q+=2}else if(Q<W)H=Q}else{if(q===!0){if(Q<W)E[Q]=K;Q++}else{if(Q<W)E[Q]=X>>8;if(Q<W-1)E[Q+1]=X&255;Q+=2}X=0,K=0}J=!0,q=!1}else if(L===46){if(Q<W)E[Q]=K;Q++,K=0,X=0,J=!1,q=!0}else{if(J=!1,L>=97)L-=87;else if(L>=65)L-=55;else L-=48,K=K*10+L;X=(X<<4)+L}}if(J===!1)if(q===!0){if(Q<W)E[Q]=K;Q++}else{if(Q<W)E[Q]=X>>8;if(Q<W-1)E[Q+1]=X&255;Q+=2}else if(H===0){if(Q<W)E[Q]=0;if(Q<W-1)E[Q+1]=0;Q+=2}else if(H!==-1){Q+=2;for(let z=Math.min(Q-1,W-1);z>=H+2;z--)E[z]=E[z-2];E[H]=0,E[H+1]=0,H=Q}if(H!==Q&&H!==-1){if(Q>W-2)Q=W-2;while(W>H)E[--W]=Q<W&&Q>H?E[--Q]:0}else while(Q<W)E[Q++]=0;return E},decode(N,E){E=~~E;let Q="";for(let W=0;W<c;W+=2){if(W!==0)Q+=":";Q+=(N[E+W]<<8|N[E+W+1]).toString(16)}return Q.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}};r.v6=y;let j="ip";r.name=j;function A(N){if(l.isFormat(N))return l.size;if(y.isFormat(N))return y.size;throw Error(`Invalid ip address: ${N}`)}function S(N){return A(N)===l.size?1:2}function v(N,E,Q){Q=~~Q;let W=A(N);if(typeof E==="function")E=E(Q+W);if(W===l.size)return l.encode(N,E,Q);return y.encode(N,E,Q)}function w(N,E,Q){if(E=~~E,Q=Q||N.length-E,Q===l.size)return l.decode(N,E,Q);if(Q===y.size)return y.decode(N,E,Q);throw Error(`Invalid buffer size needs to be ${l.size} for v4 or ${y.size} for v6.`)}return"default"in r?r.default:r}({});if(typeof define==="function"&&define.amd)define([],function(){return ij});else if(typeof Lc==="object"&&typeof mj==="object")Lc.exports=ij});var lj=nr((YS)=>{var Y=sn("buffer").Buffer,Cn=ey(),KS=sy(),HS=fy(),dm=rj(),gc=nj(),ri=cj(),R=YS.name={};R.encode=function(r,n,i,{mail:m=!1}={}){if(!n)n=Y.alloc(R.encodingLength(r));if(!i)i=0;let c=i,l=r.replace(/^\.|\.$/gm,"");if(l.length){let y=[];if(m){let j="";l.split(".").forEach((A)=>{if(A.endsWith("\\"))j+=(j.length?".":"")+A.slice(0,-1);else if(y.length===0&&j.length)y.push(j+"."+A);else y.push(A)})}else y=l.split(".");for(let j=0;j<y.length;j++){let A=n.write(y[j],i+1);n[i]=A,i+=A+1}}return n[i++]=0,R.encode.bytes=i-c,n};R.encode.bytes=0;R.decode=function(r,n,{mail:i=!1}={}){if(!n)n=0;let m=[],c=n,l=0,y=0,j=!1;while(!0){if(n>=r.length)throw Error("Cannot decode name (buffer overflow)");let A=r[n++];if(y+=j?0:1,A===0)break;else if((A&192)===0){if(n+A>r.length)throw Error("Cannot decode name (buffer overflow)");if(l+=A+1,l>254)throw Error("Cannot decode name (name too long)");let S=r.toString("utf-8",n,n+A);if(i)S=S.replace(/\./g,"\\.");m.push(S),n+=A,y+=j?0:A}else if((A&192)===192){if(n+1>r.length)throw Error("Cannot decode name (buffer overflow)");let S=r.readUInt16BE(n-1)-49152;if(S>=c)throw Error("Cannot decode name (bad pointer)");n=S,c=S,y+=j?0:1,j=!0}else throw Error("Cannot decode name (bad label)")}return R.decode.bytes=y,m.length===0?".":m.join(".")};R.decode.bytes=0;R.encodingLength=function(r){if(r==="."||r==="..")return 1;return Y.byteLength(r.replace(/^\.|\.$/gm,""))+2};var O={};O.encode=function(r,n,i){if(!n)n=Y.alloc(O.encodingLength(r));if(!i)i=0;let m=n.write(r,i+1);return n[i]=m,O.encode.bytes=m+1,n};O.encode.bytes=0;O.decode=function(r,n){if(!n)n=0;let i=r[n],m=r.toString("utf-8",n+1,n+1+i);return O.decode.bytes=i+1,m};O.decode.bytes=0;O.encodingLength=function(r){return Y.byteLength(r)+1};var ur={};ur.encode=function(r,n,i){if(!n)n=ur.encodingLength(r);if(!i)i=0;let m=(r.flags||0)&32767,c=r.type==="response"?32768:0;return n.writeUInt16BE(r.id||0,i),n.writeUInt16BE(m|c,i+2),n.writeUInt16BE(r.questions.length,i+4),n.writeUInt16BE(r.answers.length,i+6),n.writeUInt16BE(r.authorities.length,i+8),n.writeUInt16BE(r.additionals.length,i+10),n};ur.encode.bytes=12;ur.decode=function(r,n){if(!n)n=0;if(r.length<12)throw Error("Header must be 12 bytes");let i=r.readUInt16BE(n+2);return{id:r.readUInt16BE(n),type:i&32768?"response":"query",flags:i&32767,flag_qr:(i>>15&1)===1,opcode:HS.toString(i>>11&15),flag_aa:(i>>10&1)===1,flag_tc:(i>>9&1)===1,flag_rd:(i>>8&1)===1,flag_ra:(i>>7&1)===1,flag_z:(i>>6&1)===1,flag_ad:(i>>5&1)===1,flag_cd:(i>>4&1)===1,rcode:KS.toString(i&15),questions:Array(r.readUInt16BE(n+4)),answers:Array(r.readUInt16BE(n+6)),authorities:Array(r.readUInt16BE(n+8)),additionals:Array(r.readUInt16BE(n+10))}};ur.decode.bytes=12;ur.encodingLength=function(){return 12};var wn=YS.unknown={};wn.encode=function(r,n,i){if(!n)n=Y.alloc(wn.encodingLength(r));if(!i)i=0;return n.writeUInt16BE(r.length,i),r.copy(n,i+2),wn.encode.bytes=r.length+2,n};wn.encode.bytes=0;wn.decode=function(r,n){if(!n)n=0;let i=r.readUInt16BE(n),m=r.slice(n+2,n+2+i);return wn.decode.bytes=i+2,m};wn.decode.bytes=0;wn.encodingLength=function(r){return r.length+2};var $n=YS.ns={};$n.encode=function(r,n,i){if(!n)n=Y.alloc($n.encodingLength(r));if(!i)i=0;return R.encode(r,n,i+2),n.writeUInt16BE(R.encode.bytes,i),$n.encode.bytes=R.encode.bytes+2,n};$n.encode.bytes=0;$n.decode=function(r,n){if(!n)n=0;let i=r.readUInt16BE(n),m=R.decode(r,n+2);return $n.decode.bytes=i+2,m};$n.decode.bytes=0;$n.encodingLength=function(r){return R.encodingLength(r)+2};var Gn=YS.soa={};Gn.encode=function(r,n,i){if(!n)n=Y.alloc(Gn.encodingLength(r));if(!i)i=0;let m=i;return i+=2,R.encode(r.mname,n,i),i+=R.encode.bytes,R.encode(r.rname,n,i,{mail:!0}),i+=R.encode.bytes,n.writeUInt32BE(r.serial||0,i),i+=4,n.writeUInt32BE(r.refresh||0,i),i+=4,n.writeUInt32BE(r.retry||0,i),i+=4,n.writeUInt32BE(r.expire||0,i),i+=4,n.writeUInt32BE(r.minimum||0,i),i+=4,n.writeUInt16BE(i-m-2,m),Gn.encode.bytes=i-m,n};Gn.encode.bytes=0;Gn.decode=function(r,n){if(!n)n=0;let i=n,m={};return n+=2,m.mname=R.decode(r,n),n+=R.decode.bytes,m.rname=R.decode(r,n,{mail:!0}),n+=R.decode.bytes,m.serial=r.readUInt32BE(n),n+=4,m.refresh=r.readUInt32BE(n),n+=4,m.retry=r.readUInt32BE(n),n+=4,m.expire=r.readUInt32BE(n),n+=4,m.minimum=r.readUInt32BE(n),n+=4,Gn.decode.bytes=n-i,m};Gn.decode.bytes=0;Gn.encodingLength=function(r){return 22+R.encodingLength(r.mname)+R.encodingLength(r.rname)};var Nn=YS.txt={};Nn.encode=function(r,n,i){if(!Array.isArray(r))r=[r];for(let c=0;c<r.length;c++){if(typeof r[c]==="string")r[c]=Y.from(r[c]);if(!Y.isBuffer(r[c]))throw Error("Must be a Buffer")}if(!n)n=Y.alloc(Nn.encodingLength(r));if(!i)i=0;let m=i;return i+=2,r.forEach(function(c){n[i++]=c.length,c.copy(n,i,0,c.length),i+=c.length}),n.writeUInt16BE(i-m-2,m),Nn.encode.bytes=i-m,n};Nn.encode.bytes=0;Nn.decode=function(r,n){if(!n)n=0;let i=n,m=r.readUInt16BE(n);n+=2;let c=[];while(m>0){let l=r[n++];if(--m,m<l)throw Error("Buffer overflow");c.push(r.slice(n,n+l)),n+=l,m-=l}return Nn.decode.bytes=n-i,c};Nn.decode.bytes=0;Nn.encodingLength=function(r){if(!Array.isArray(r))r=[r];let n=2;return r.forEach(function(i){if(typeof i==="string")n+=Y.byteLength(i)+1;else n+=i.length+1}),n};var En=YS.null={};En.encode=function(r,n,i){if(!n)n=Y.alloc(En.encodingLength(r));if(!i)i=0;if(typeof r==="string")r=Y.from(r);if(!r)r=Y.alloc(0);let m=i;i+=2;let c=r.length;return r.copy(n,i,0,c),i+=c,n.writeUInt16BE(i-m-2,m),En.encode.bytes=i-m,n};En.encode.bytes=0;En.decode=function(r,n){if(!n)n=0;let i=n,m=r.readUInt16BE(n);n+=2;let c=r.slice(n,n+m);return n+=m,En.decode.bytes=n-i,c};En.decode.bytes=0;En.encodingLength=function(r){if(!r)return 2;return(Y.isBuffer(r)?r.length:Y.byteLength(r))+2};var Qn=YS.hinfo={};Qn.encode=function(r,n,i){if(!n)n=Y.alloc(Qn.encodingLength(r));if(!i)i=0;let m=i;return i+=2,O.encode(r.cpu,n,i),i+=O.encode.bytes,O.encode(r.os,n,i),i+=O.encode.bytes,n.writeUInt16BE(i-m-2,m),Qn.encode.bytes=i-m,n};Qn.encode.bytes=0;Qn.decode=function(r,n){if(!n)n=0;let i=n,m={};return n+=2,m.cpu=O.decode(r,n),n+=O.decode.bytes,m.os=O.decode(r,n),n+=O.decode.bytes,Qn.decode.bytes=n-i,m};Qn.decode.bytes=0;Qn.encodingLength=function(r){return O.encodingLength(r.cpu)+O.encodingLength(r.os)+2};var pr=YS.ptr={},RS=YS.cname=pr,VS=YS.dname=pr;pr.encode=function(r,n,i){if(!n)n=Y.alloc(pr.encodingLength(r));if(!i)i=0;return R.encode(r,n,i+2),n.writeUInt16BE(R.encode.bytes,i),pr.encode.bytes=R.encode.bytes+2,n};pr.encode.bytes=0;pr.decode=function(r,n){if(!n)n=0;let i=R.decode(r,n+2);return pr.decode.bytes=R.decode.bytes+2,i};pr.decode.bytes=0;pr.encodingLength=function(r){return R.encodingLength(r)+2};var Dn=YS.srv={};Dn.encode=function(r,n,i){if(!n)n=Y.alloc(Dn.encodingLength(r));if(!i)i=0;n.writeUInt16BE(r.priority||0,i+2),n.writeUInt16BE(r.weight||0,i+4),n.writeUInt16BE(r.port||0,i+6),R.encode(r.target,n,i+8);let m=R.encode.bytes+6;return n.writeUInt16BE(m,i),Dn.encode.bytes=m+2,n};Dn.encode.bytes=0;Dn.decode=function(r,n){if(!n)n=0;let i=r.readUInt16BE(n),m={};return m.priority=r.readUInt16BE(n+2),m.weight=r.readUInt16BE(n+4),m.port=r.readUInt16BE(n+6),m.target=R.decode(r,n+8),Dn.decode.bytes=i+2,m};Dn.decode.bytes=0;Dn.encodingLength=function(r){return 8+R.encodingLength(r.target)};var Zr=YS.caa={};Zr.ISSUER_CRITICAL=128;Zr.encode=function(r,n,i){let m=Zr.encodingLength(r);if(!n)n=Y.alloc(Zr.encodingLength(r));if(!i)i=0;if(r.issuerCritical)r.flags=Zr.ISSUER_CRITICAL;return n.writeUInt16BE(m-2,i),i+=2,n.writeUInt8(r.flags||0,i),i+=1,O.encode(r.tag,n,i),i+=O.encode.bytes,n.write(r.value,i),i+=Y.byteLength(r.value),Zr.encode.bytes=m,n};Zr.encode.bytes=0;Zr.decode=function(r,n){if(!n)n=0;let i=r.readUInt16BE(n);n+=2;let m=n,c={};return c.flags=r.readUInt8(n),n+=1,c.tag=O.decode(r,n),n+=O.decode.bytes,c.value=r.toString("utf-8",n,m+i),c.issuerCritical=!!(c.flags&Zr.ISSUER_CRITICAL),Zr.decode.bytes=i+2,c};Zr.decode.bytes=0;Zr.encodingLength=function(r){return O.encodingLength(r.tag)+O.encodingLength(r.value)+2};var Ln=YS.mx={};Ln.encode=function(r,n,i){if(!n)n=Y.alloc(Ln.encodingLength(r));if(!i)i=0;let m=i;return i+=2,n.writeUInt16BE(r.preference||0,i),i+=2,R.encode(r.exchange,n,i),i+=R.encode.bytes,n.writeUInt16BE(i-m-2,m),Ln.encode.bytes=i-m,n};Ln.encode.bytes=0;Ln.decode=function(r,n){if(!n)n=0;let i=n,m={};return n+=2,m.preference=r.readUInt16BE(n),n+=2,m.exchange=R.decode(r,n),n+=R.decode.bytes,Ln.decode.bytes=n-i,m};Ln.encodingLength=function(r){return 4+R.encodingLength(r.exchange)};var Un=YS.a={};Un.encode=function(r,n,i){if(!n)n=Y.alloc(Un.encodingLength(r));if(!i)i=0;return n.writeUInt16BE(4,i),i+=2,ri.v4.encode(r,n,i),Un.encode.bytes=6,n};Un.encode.bytes=0;Un.decode=function(r,n){if(!n)n=0;n+=2;let i=ri.v4.decode(r,n);return Un.decode.bytes=6,i};Un.decode.bytes=0;Un.encodingLength=function(){return 6};var Pn=YS.aaaa={};Pn.encode=function(r,n,i){if(!n)n=Y.alloc(Pn.encodingLength(r));if(!i)i=0;return n.writeUInt16BE(16,i),i+=2,ri.v6.encode(r,n,i),Pn.encode.bytes=18,n};Pn.encode.bytes=0;Pn.decode=function(r,n){if(!n)n=0;n+=2;let i=ri.v6.decode(r,n);return Pn.decode.bytes=18,i};Pn.decode.bytes=0;Pn.encodingLength=function(){return 18};var Kr=YS.option={};Kr.encode=function(r,n,i){if(!n)n=Y.alloc(Kr.encodingLength(r));if(!i)i=0;let m=i,c=gc.toCode(r.code);if(n.writeUInt16BE(c,i),i+=2,r.data)n.writeUInt16BE(r.data.length,i),i+=2,r.data.copy(n,i),i+=r.data.length;else switch(c){case 8:let l=r.sourcePrefixLength||0,y=r.family||ri.familyOf(r.ip),j=ri.encode(r.ip,Y.alloc),A=Math.ceil(l/8);n.writeUInt16BE(A+4,i),i+=2,n.writeUInt16BE(y,i),i+=2,n.writeUInt8(l,i++),n.writeUInt8(r.scopePrefixLength||0,i++),j.copy(n,i,0,A),i+=A;break;case 11:if(r.timeout)n.writeUInt16BE(2,i),i+=2,n.writeUInt16BE(r.timeout,i),i+=2;else n.writeUInt16BE(0,i),i+=2;break;case 12:let S=r.length||0;n.writeUInt16BE(S,i),i+=2,n.fill(0,i,i+S),i+=S;break;case 14:let v=r.tags.length*2;n.writeUInt16BE(v,i),i+=2;for(let w of r.tags)n.writeUInt16BE(w,i),i+=2;break;default:throw Error(`Unknown roption code: ${r.code}`)}return Kr.encode.bytes=i-m,n};Kr.encode.bytes=0;Kr.decode=function(r,n){if(!n)n=0;let i={};i.code=r.readUInt16BE(n),i.type=gc.toString(i.code),n+=2;let m=r.readUInt16BE(n);switch(n+=2,i.data=r.slice(n,n+m),i.code){case 8:i.family=r.readUInt16BE(n),n+=2,i.sourcePrefixLength=r.readUInt8(n++),i.scopePrefixLength=r.readUInt8(n++);let c=Y.alloc(i.family===1?4:16);r.copy(c,0,n,n+m-4),i.ip=ri.decode(c);break;case 11:if(m>0)i.timeout=r.readUInt16BE(n),n+=2;break;case 14:i.tags=[];for(let l=0;l<m;l+=2)i.tags.push(r.readUInt16BE(n)),n+=2}return Kr.decode.bytes=m+4,i};Kr.decode.bytes=0;Kr.encodingLength=function(r){if(r.data)return r.data.length+4;switch(gc.toCode(r.code)){case 8:let i=r.sourcePrefixLength||0;return Math.ceil(i/8)+8;case 11:return typeof r.timeout==="number"?6:4;case 12:return r.length+4;case 14:return 4+r.tags.length*2}throw Error(`Unknown roption code: ${r.code}`)};var Or=YS.opt={};Or.encode=function(r,n,i){if(!n)n=Y.alloc(Or.encodingLength(r));if(!i)i=0;let m=i,c=Gi(r,Kr);return n.writeUInt16BE(c,i),i=pi(r,Kr,n,i+2),Or.encode.bytes=i-m,n};Or.encode.bytes=0;Or.decode=function(r,n){if(!n)n=0;let i=n,m=[],c=r.readUInt16BE(n);n+=2;let l=0;while(c>0)m[l++]=Kr.decode(r,n),n+=Kr.decode.bytes,c-=Kr.decode.bytes;return Or.decode.bytes=n-i,m};Or.decode.bytes=0;Or.encodingLength=function(r){return 2+Gi(r||[],Kr)};var Ur=YS.dnskey={};Ur.PROTOCOL_DNSSEC=3;Ur.ZONE_KEY=128;Ur.SECURE_ENTRYPOINT=32768;Ur.encode=function(r,n,i){if(!n)n=Y.alloc(Ur.encodingLength(r));if(!i)i=0;let m=i,c=r.key;if(!Y.isBuffer(c))throw Error("Key must be a Buffer");return i+=2,n.writeUInt16BE(r.flags,i),i+=2,n.writeUInt8(Ur.PROTOCOL_DNSSEC,i),i+=1,n.writeUInt8(r.algorithm,i),i+=1,c.copy(n,i,0,c.length),i+=c.length,Ur.encode.bytes=i-m,n.writeUInt16BE(Ur.encode.bytes-2,m),n};Ur.encode.bytes=0;Ur.decode=function(r,n){if(!n)n=0;let i=n;var m={},c=r.readUInt16BE(n);if(n+=2,m.flags=r.readUInt16BE(n),n+=2,r.readUInt8(n)!==Ur.PROTOCOL_DNSSEC)throw Error("Protocol must be 3");return n+=1,m.algorithm=r.readUInt8(n),n+=1,m.key=r.slice(n,i+c+2),n+=m.key.length,Ur.decode.bytes=n-i,m};Ur.decode.bytes=0;Ur.encodingLength=function(r){return 6+Y.byteLength(r.key)};var sr=YS.rrsig={};sr.encode=function(r,n,i){if(!n)n=Y.alloc(sr.encodingLength(r));if(!i)i=0;let m=i,c=r.signature;if(!Y.isBuffer(c))throw Error("Signature must be a Buffer");return i+=2,n.writeUInt16BE(Cn.toType(r.typeCovered),i),i+=2,n.writeUInt8(r.algorithm,i),i+=1,n.writeUInt8(r.labels,i),i+=1,n.writeUInt32BE(r.originalTTL,i),i+=4,n.writeUInt32BE(r.expiration,i),i+=4,n.writeUInt32BE(r.inception,i),i+=4,n.writeUInt16BE(r.keyTag,i),i+=2,R.encode(r.signersName,n,i),i+=R.encode.bytes,c.copy(n,i,0,c.length),i+=c.length,sr.encode.bytes=i-m,n.writeUInt16BE(sr.encode.bytes-2,m),n};sr.encode.bytes=0;sr.decode=function(r,n){if(!n)n=0;let i=n;var m={},c=r.readUInt16BE(n);return n+=2,m.typeCovered=Cn.toString(r.readUInt16BE(n)),n+=2,m.algorithm=r.readUInt8(n),n+=1,m.labels=r.readUInt8(n),n+=1,m.originalTTL=r.readUInt32BE(n),n+=4,m.expiration=r.readUInt32BE(n),n+=4,m.inception=r.readUInt32BE(n),n+=4,m.keyTag=r.readUInt16BE(n),n+=2,m.signersName=R.decode(r,n),n+=R.decode.bytes,m.signature=r.slice(n,i+c+2),n+=m.signature.length,sr.decode.bytes=n-i,m};sr.decode.bytes=0;sr.encodingLength=function(r){return 20+R.encodingLength(r.signersName)+Y.byteLength(r.signature)};var fr=YS.rp={};fr.encode=function(r,n,i){if(!n)n=Y.alloc(fr.encodingLength(r));if(!i)i=0;let m=i;return i+=2,R.encode(r.mbox||".",n,i,{mail:!0}),i+=R.encode.bytes,R.encode(r.txt||".",n,i),i+=R.encode.bytes,fr.encode.bytes=i-m,n.writeUInt16BE(fr.encode.bytes-2,m),n};fr.encode.bytes=0;fr.decode=function(r,n){if(!n)n=0;let i=n,m={};return n+=2,m.mbox=R.decode(r,n,{mail:!0})||".",n+=R.decode.bytes,m.txt=R.decode(r,n)||".",n+=R.decode.bytes,fr.decode.bytes=n-i,m};fr.decode.bytes=0;fr.encodingLength=function(r){return 2+R.encodingLength(r.mbox||".")+R.encodingLength(r.txt||".")};var jr={};jr.encode=function(r,n,i){if(!n)n=Y.alloc(jr.encodingLength(r));if(!i)i=0;let m=i;var c=[];for(var l=0;l<r.length;l++){var y=Cn.toType(r[l]);if(c[y>>8]===void 0)c[y>>8]=[];c[y>>8][y>>3&31]|=1<<7-(y&7)}for(l=0;l<c.length;l++)if(c[l]!==void 0){var j=Y.from(c[l]);n.writeUInt8(l,i),i+=1,n.writeUInt8(j.length,i),i+=1,j.copy(n,i),i+=j.length}return jr.encode.bytes=i-m,n};jr.encode.bytes=0;jr.decode=function(r,n,i){if(!n)n=0;let m=n;var c=[];while(n-m<i){var l=r.readUInt8(n);n+=1;var y=r.readUInt8(n);n+=1;for(var j=0;j<y;j++){var A=r.readUInt8(n+j);for(var S=0;S<8;S++)if(A&1<<7-S){var v=Cn.toString(l<<8|j<<3|S);c.push(v)}}n+=y}return jr.decode.bytes=n-m,c};jr.decode.bytes=0;jr.encodingLength=function(r){var n=[];for(var i=0;i<r.length;i++){var m=Cn.toType(r[i]);n[m>>8]=Math.max(n[m>>8]||0,m&255)}var c=0;for(i=0;i<n.length;i++)if(n[i]!==void 0)c+=2+Math.ceil((n[i]+1)/8);return c};var rn=YS.nsec={};rn.encode=function(r,n,i){if(!n)n=Y.alloc(rn.encodingLength(r));if(!i)i=0;let m=i;return i+=2,R.encode(r.nextDomain,n,i),i+=R.encode.bytes,jr.encode(r.rrtypes,n,i),i+=jr.encode.bytes,rn.encode.bytes=i-m,n.writeUInt16BE(rn.encode.bytes-2,m),n};rn.encode.bytes=0;rn.decode=function(r,n){if(!n)n=0;let i=n;var m={},c=r.readUInt16BE(n);return n+=2,m.nextDomain=R.decode(r,n),n+=R.decode.bytes,m.rrtypes=jr.decode(r,n,c-(n-i)),n+=jr.decode.bytes,rn.decode.bytes=n-i,m};rn.decode.bytes=0;rn.encodingLength=function(r){return 2+R.encodingLength(r.nextDomain)+jr.encodingLength(r.rrtypes)};var nn=YS.nsec3={};nn.encode=function(r,n,i){if(!n)n=Y.alloc(nn.encodingLength(r));if(!i)i=0;let m=i,c=r.salt;if(!Y.isBuffer(c))throw Error("salt must be a Buffer");let l=r.nextDomain;if(!Y.isBuffer(l))throw Error("nextDomain must be a Buffer");return i+=2,n.writeUInt8(r.algorithm,i),i+=1,n.writeUInt8(r.flags,i),i+=1,n.writeUInt16BE(r.iterations,i),i+=2,n.writeUInt8(c.length,i),i+=1,c.copy(n,i,0,c.length),i+=c.length,n.writeUInt8(l.length,i),i+=1,l.copy(n,i,0,l.length),i+=l.length,jr.encode(r.rrtypes,n,i),i+=jr.encode.bytes,nn.encode.bytes=i-m,n.writeUInt16BE(nn.encode.bytes-2,m),n};nn.encode.bytes=0;nn.decode=function(r,n){if(!n)n=0;let i=n;var m={},c=r.readUInt16BE(n);n+=2,m.algorithm=r.readUInt8(n),n+=1,m.flags=r.readUInt8(n),n+=1,m.iterations=r.readUInt16BE(n),n+=2;let l=r.readUInt8(n);n+=1,m.salt=r.slice(n,n+l),n+=l;let y=r.readUInt8(n);return n+=1,m.nextDomain=r.slice(n,n+y),n+=y,m.rrtypes=jr.decode(r,n,c-(n-i)),n+=jr.decode.bytes,nn.decode.bytes=n-i,m};nn.decode.bytes=0;nn.encodingLength=function(r){return 8+r.salt.length+r.nextDomain.length+jr.encodingLength(r.rrtypes)};var mn=YS.ds={};mn.encode=function(r,n,i){if(!n)n=Y.alloc(mn.encodingLength(r));if(!i)i=0;let m=i,c=r.digest;if(!Y.isBuffer(c))throw Error("Digest must be a Buffer");return i+=2,n.writeUInt16BE(r.keyTag,i),i+=2,n.writeUInt8(r.algorithm,i),i+=1,n.writeUInt8(r.digestType,i),i+=1,c.copy(n,i,0,c.length),i+=c.length,mn.encode.bytes=i-m,n.writeUInt16BE(mn.encode.bytes-2,m),n};mn.encode.bytes=0;mn.decode=function(r,n){if(!n)n=0;let i=n;var m={},c=r.readUInt16BE(n);return n+=2,m.keyTag=r.readUInt16BE(n),n+=2,m.algorithm=r.readUInt8(n),n+=1,m.digestType=r.readUInt8(n),n+=1,m.digest=r.slice(n,i+c+2),n+=m.digest.length,mn.decode.bytes=n-i,m};mn.decode.bytes=0;mn.encodingLength=function(r){return 6+Y.byteLength(r.digest)};var Jr=YS.sshfp={};Jr.getFingerprintLengthForHashType=function(n){switch(n){case 1:return 20;case 2:return 32}};Jr.encode=function(n,i,m){if(!i)i=Y.alloc(Jr.encodingLength(n));if(!m)m=0;let c=m;m+=2,i[m]=n.algorithm,m+=1,i[m]=n.hash,m+=1;let l=Y.from(n.fingerprint.toUpperCase(),"hex");if(l.length!==Jr.getFingerprintLengthForHashType(n.hash))throw Error("Invalid fingerprint length");return l.copy(i,m),m+=l.byteLength,Jr.encode.bytes=m-c,i.writeUInt16BE(Jr.encode.bytes-2,c),i};Jr.encode.bytes=0;Jr.decode=function(n,i){if(!i)i=0;let m=i,c={};i+=2,c.algorithm=n[i],i+=1,c.hash=n[i],i+=1;let l=Jr.getFingerprintLengthForHashType(c.hash);return c.fingerprint=n.slice(i,i+l).toString("hex").toUpperCase(),i+=l,Jr.decode.bytes=i-m,c};Jr.decode.bytes=0;Jr.encodingLength=function(r){return 4+Y.from(r.fingerprint,"hex").byteLength};var cn=YS.naptr={};cn.encode=function(r,n,i){if(!n)n=Y.alloc(cn.encodingLength(r));if(!i)i=0;let m=i;return i+=2,n.writeUInt16BE(r.order||0,i),i+=2,n.writeUInt16BE(r.preference||0,i),i+=2,O.encode(r.flags,n,i),i+=O.encode.bytes,O.encode(r.services,n,i),i+=O.encode.bytes,O.encode(r.regexp,n,i),i+=O.encode.bytes,R.encode(r.replacement,n,i),i+=R.encode.bytes,cn.encode.bytes=i-m,n.writeUInt16BE(cn.encode.bytes-2,m),n};cn.encode.bytes=0;cn.decode=function(r,n){if(!n)n=0;let i=n,m={};return n+=2,m.order=r.readUInt16BE(n),n+=2,m.preference=r.readUInt16BE(n),n+=2,m.flags=O.decode(r,n),n+=O.decode.bytes,m.services=O.decode(r,n),n+=O.decode.bytes,m.regexp=O.decode(r,n),n+=O.decode.bytes,m.replacement=R.decode(r,n),n+=R.decode.bytes,cn.decode.bytes=n-i,m};cn.decode.bytes=0;cn.encodingLength=function(r){return O.encodingLength(r.flags)+O.encodingLength(r.services)+O.encodingLength(r.regexp)+R.encodingLength(r.replacement)+6};var ln=YS.tlsa={};ln.encode=function(r,n,i){if(!n)n=Y.alloc(ln.encodingLength(r));if(!i)i=0;let m=i,c=r.certificate;if(!Y.isBuffer(c))throw Error("Certificate must be a Buffer");return i+=2,n.writeUInt8(r.usage,i),i+=1,n.writeUInt8(r.selector,i),i+=1,n.writeUInt8(r.matchingType,i),i+=1,c.copy(n,i,0,c.length),i+=c.length,ln.encode.bytes=i-m,n.writeUInt16BE(ln.encode.bytes-2,m),n};ln.encode.bytes=0;ln.decode=function(r,n){if(!n)n=0;let i=n,m={},c=r.readUInt16BE(n);return n+=2,m.usage=r.readUInt8(n),n+=1,m.selector=r.readUInt8(n),n+=1,m.matchingType=r.readUInt8(n),n+=1,m.certificate=r.slice(n,i+c+2),n+=m.certificate.length,ln.decode.bytes=n-i,m};ln.decode.bytes=0;ln.encodingLength=function(r){return 5+Y.byteLength(r.certificate)};var Fc=YS.record=function(r){switch(r.toUpperCase()){case"A":return Un;case"PTR":return pr;case"CNAME":return RS;case"DNAME":return VS;case"TXT":return Nn;case"NULL":return En;case"AAAA":return Pn;case"SRV":return Dn;case"HINFO":return Qn;case"CAA":return Zr;case"NS":return $n;case"SOA":return Gn;case"MX":return Ln;case"OPT":return Or;case"DNSKEY":return Ur;case"RRSIG":return sr;case"RP":return fr;case"NSEC":return rn;case"NSEC3":return nn;case"SSHFP":return Jr;case"DS":return mn;case"NAPTR":return cn;case"TLSA":return ln}return wn},vr=YS.answer={};vr.encode=function(r,n,i){if(!n)n=Y.alloc(vr.encodingLength(r));if(!i)i=0;let m=i;if(R.encode(r.name,n,i),i+=R.encode.bytes,n.writeUInt16BE(Cn.toType(r.type),i),r.type.toUpperCase()==="OPT"){if(r.name!==".")throw Error("OPT name must be root.");n.writeUInt16BE(r.udpPayloadSize||4096,i+2),n.writeUInt8(r.extendedRcode||0,i+4),n.writeUInt8(r.ednsVersion||0,i+5),n.writeUInt16BE(r.flags||0,i+6),i+=8,Or.encode(r.options||[],n,i),i+=Or.encode.bytes}else{let c=dm.toClass(r.class===void 0?"IN":r.class);if(r.flush)c|=32768;n.writeUInt16BE(c,i+2),n.writeUInt32BE(r.ttl||0,i+4),i+=8;let l=Fc(r.type);l.encode(r.data,n,i),i+=l.encode.bytes}return vr.encode.bytes=i-m,n};vr.encode.bytes=0;vr.decode=function(r,n){if(!n)n=0;let i={},m=n;if(i.name=R.decode(r,n),n+=R.decode.bytes,i.type=Cn.toString(r.readUInt16BE(n)),i.type==="OPT")i.udpPayloadSize=r.readUInt16BE(n+2),i.extendedRcode=r.readUInt8(n+4),i.ednsVersion=r.readUInt8(n+5),i.flags=r.readUInt16BE(n+6),i.flag_do=(i.flags>>15&1)===1,i.options=Or.decode(r,n+8),n+=8+Or.decode.bytes;else{let c=r.readUInt16BE(n+2);i.ttl=r.readUInt32BE(n+4),i.class=dm.toString(c&-32769),i.flush=!!(c&32768);let l=Fc(i.type);i.data=l.decode(r,n+8),n+=8+l.decode.bytes}return vr.decode.bytes=n-m,i};vr.decode.bytes=0;vr.encodingLength=function(r){let n=r.data!==null&&r.data!==void 0?r.data:r.options;return R.encodingLength(r.name)+8+Fc(r.type).encodingLength(n)};var ar=YS.question={};ar.encode=function(r,n,i){if(!n)n=Y.alloc(ar.encodingLength(r));if(!i)i=0;let m=i;return R.encode(r.name,n,i),i+=R.encode.bytes,n.writeUInt16BE(Cn.toType(r.type),i),i+=2,n.writeUInt16BE(dm.toClass(r.class===void 0?"IN":r.class),i),i+=2,ar.encode.bytes=i-m,r};ar.encode.bytes=0;ar.decode=function(r,n){if(!n)n=0;let i=n,m={};if(m.name=R.decode(r,n),n+=R.decode.bytes,m.type=Cn.toString(r.readUInt16BE(n)),n+=2,m.class=dm.toString(r.readUInt16BE(n)),n+=2,!!(m.class&32768))m.class&=-32769;return ar.decode.bytes=n-i,m};ar.decode.bytes=0;ar.encodingLength=function(r){return R.encodingLength(r.name)+4};YS.AUTHORITATIVE_ANSWER=1024;YS.TRUNCATED_RESPONSE=512;YS.RECURSION_DESIRED=256;YS.RECURSION_AVAILABLE=128;YS.AUTHENTIC_DATA=32;YS.CHECKING_DISABLED=16;YS.DNSSEC_OK=32768;YS.encode=function(r,n,i){let m=!n;if(m)n=Y.alloc(YS.encodingLength(r));if(!i)i=0;let c=i;if(!r.questions)r.questions=[];if(!r.answers)r.answers=[];if(!r.authorities)r.authorities=[];if(!r.additionals)r.additionals=[];if(ur.encode(r,n,i),i+=ur.encode.bytes,i=pi(r.questions,ar,n,i),i=pi(r.answers,vr,n,i),i=pi(r.authorities,vr,n,i),i=pi(r.additionals,vr,n,i),YS.encode.bytes=i-c,m&&YS.encode.bytes!==n.length)return n.slice(0,YS.encode.bytes);return n};YS.encode.bytes=0;YS.decode=function(r,n){if(!n)n=0;let i=n,m=ur.decode(r,n);return n+=ur.decode.bytes,n=um(m.questions,ar,r,n),n=um(m.answers,vr,r,n),n=um(m.authorities,vr,r,n),n=um(m.additionals,vr,r,n),YS.decode.bytes=n-i,m};YS.decode.bytes=0;YS.encodingLength=function(r){return ur.encodingLength(r)+Gi(r.questions||[],ar)+Gi(r.answers||[],vr)+Gi(r.authorities||[],vr)+Gi(r.additionals||[],vr)};YS.streamEncode=function(r){let n=YS.encode(r),i=Y.alloc(2);i.writeUInt16BE(n.byteLength);let m=Y.concat([i,n]);return YS.streamEncode.bytes=m.byteLength,m};YS.streamEncode.bytes=0;YS.streamDecode=function(r){let n=r.readUInt16BE(0);if(r.byteLength<n+2)return null;let i=YS.decode(r.slice(2));return YS.streamDecode.bytes=YS.decode.bytes,i};YS.streamDecode.bytes=0;function Gi(r,n){let i=0;for(let m=0;m<r.length;m++)i+=n.encodingLength(r[m]);return i}function pi(r,n,i,m){for(let c=0;c<r.length;c++)n.encode(r[c],i,m),m+=n.encode.bytes;return m}function um(r,n,i,m){for(let c=0;c<r.length;c++)r[c]=n.decode(i,m),m+=n.decode.bytes;return m}});var Ij=nr((nD,jj)=>{var yj=BS;process.nextTick(hS,42);jj.exports=zS;function zS(r){var n=m;return i;function i(c){n(c||MS)}function m(c){var l=[c];n=y,r(j);function y(A){l.push(A)}function j(A){var S=arguments;n=oS(A)?m:v;while(l.length)v(l.shift());function v(w){yj(TS,w,S)}}}}function oS(r){return Object.prototype.toString.call(r)==="[object Error]"}function MS(){}function TS(r,n){r.apply(null,n)}function hS(r){if(r===42)yj=process.nextTick}function BS(r,n,i){process.nextTick(function(){r(n,i)})}});var vj=nr((iD,Sj)=>{var zc=lj(),xS=sn("dgram"),kS=Ij(),pS=sn("events"),Mc=sn("os"),oc=function(){};Sj.exports=function(r){if(!r)r={};var n=new pS.EventEmitter,i=typeof r.port==="number"?r.port:5353,m=r.type||"udp4",c=r.ip||r.host||(m==="udp4"?"224.0.0.251":null),l={address:c,port:i},y={},j=!1,A=null;if(m==="udp6"&&(!c||!r.interface))throw Error("For IPv6 multicast you must specify `ip` and `interface`");var S=r.socket||xS.createSocket({type:m,reuseAddr:r.reuseAddr!==!1,toString:function(){return m}});S.on("error",function(w){if(w.code==="EACCES"||w.code==="EADDRINUSE")n.emit("error",w);else n.emit("warning",w)}),S.on("message",function(w,N){try{w=zc.decode(w)}catch(E){n.emit("warning",E);return}if(n.emit("packet",w,N),w.type==="query")n.emit("query",w,N);if(w.type==="response")n.emit("response",w,N)}),S.on("listening",function(){if(!i)i=l.port=S.address().port;if(r.multicast!==!1)n.update(),A=setInterval(n.update,5000),S.setMulticastTTL(r.ttl||255),S.setMulticastLoopback(r.loopback!==!1)});var v=kS(function(w){if(!i||r.bind===!1)return w(null);S.once("error",w),S.bind(i,r.bind||r.interface,function(){S.removeListener("error",w),w(null)})});return v(function(w){if(w)return n.emit("error",w);n.emit("ready")}),n.send=function(w,N,E){if(typeof N==="function")return n.send(w,null,N);if(!E)E=oc;if(!N)N=l;else if(!N.host&&!N.address)N.address=l.address;v(Q);function Q(W){if(j)return E();if(W)return E(W);var H=zc.encode(w);S.send(H,0,H.length,N.port,N.address||N.host,E)}},n.response=n.respond=function(w,N,E){if(Array.isArray(w))w={answers:w};w.type="response",w.flags=(w.flags||0)|zc.AUTHORITATIVE_ANSWER,n.send(w,N,E)},n.query=function(w,N,E,Q){if(typeof N==="function")return n.query(w,null,null,N);if(typeof N==="object"&&N&&N.port)return n.query(w,null,N,E);if(typeof E==="function")return n.query(w,N,null,E);if(!Q)Q=oc;if(typeof w==="string")w=[{name:w,type:N||"ANY"}];if(Array.isArray(w))w={type:"query",questions:w};w.type="query",n.send(w,E,Q)},n.destroy=function(w){if(!w)w=oc;if(j)return process.nextTick(w);j=!0,clearInterval(A);for(var N in y)try{S.dropMembership(c,N)}catch(E){}y={},S.close(w)},n.update=function(){var w=r.interface?[].concat(r.interface):uS(),N=!1;for(var E=0;E<w.length;E++){var Q=w[E];if(y[Q])continue;try{S.addMembership(c,Q),y[Q]=!0,N=!0}catch(W){n.emit("warning",W)}}if(N){if(S.setMulticastInterface)try{S.setMulticastInterface(r.interface||aS())}catch(W){n.emit("warning",W)}n.emit("networkInterface")}},n};function aS(){var r=Mc.networkInterfaces(),n=Object.keys(r);for(var i=0;i<n.length;i++){var m=r[n[i]];for(var c=0;c<m.length;c++){var l=m[c];if(Aj(l.family)&&!l.internal){if(Mc.platform()==="darwin"&&n[i]==="en0")return l.address;return"0.0.0.0"}}}return"127.0.0.1"}function uS(){var r=Mc.networkInterfaces(),n=Object.keys(r),i=[];for(var m=0;m<n.length;m++){var c=r[n[m]];for(var l=0;l<c.length;l++){var y=c[l];if(Aj(y.family)){i.push(y.address);break}}}return i}function Aj(r){return r===4||r==="IPv4"}});var $j=nr((mD,wj)=>{wj.exports=function r(n,i){if(n===i)return!0;if(n&&i&&typeof n=="object"&&typeof i=="object"){if(n.constructor!==i.constructor)return!1;var m,c,l;if(Array.isArray(n)){if(m=n.length,m!=i.length)return!1;for(c=m;c--!==0;)if(!r(n[c],i[c]))return!1;return!0}if(n instanceof Map&&i instanceof Map){if(n.size!==i.size)return!1;for(c of n.entries())if(!i.has(c[0]))return!1;for(c of n.entries())if(!r(c[1],i.get(c[0])))return!1;return!0}if(n instanceof Set&&i instanceof Set){if(n.size!==i.size)return!1;for(c of n.entries())if(!i.has(c[0]))return!1;return!0}if(ArrayBuffer.isView(n)&&ArrayBuffer.isView(i)){if(m=n.length,m!=i.length)return!1;for(c=m;c--!==0;)if(n[c]!==i[c])return!1;return!0}if(n.constructor===RegExp)return n.source===i.source&&n.flags===i.flags;if(n.valueOf!==Object.prototype.valueOf)return n.valueOf()===i.valueOf();if(n.toString!==Object.prototype.toString)return n.toString()===i.toString();if(l=Object.keys(n),m=l.length,m!==Object.keys(i).length)return!1;for(c=m;c--!==0;)if(!Object.prototype.hasOwnProperty.call(i,l[c]))return!1;for(c=m;c--!==0;){var y=l[c];if(!r(n[y],i[y]))return!1}return!0}return n!==n&&i!==i}});var Gj=nr((ni)=>{var Tc=ni&&ni.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(ni,"__esModule",{value:!0});ni.Server=void 0;var dS=Tc(vj()),tS=Tc($j()),bS=Tc(pm());class hc{constructor(r,n){this.registry={},this.mdns=(0,dS.default)(r),this.mdns.setMaxListeners(0),this.mdns.on("query",this.respondToQuery.bind(this)),this.errorCallback=n!==null&&n!==void 0?n:function(i){throw i}}register(r){let n=(i)=>{var m=this.registry[i.type];if(!m)m=this.registry[i.type]=[];else if(m.some(this.isDuplicateRecord(i)))return;m.push(i)};if(Array.isArray(r))r.forEach(n);else n(r)}unregister(r){let n=(i)=>{let m=i.type;if(!(m in this.registry))return;this.registry[m]=this.registry[m].filter((c)=>c.name!==i.name)};if(Array.isArray(r))r.forEach(n);else n(r)}respondToQuery(r){let n=this;r.questions.forEach((i)=>{var{type:m,name:c}=i,l=m==="ANY"?Object.keys(n.registry).map(n.recordsFor.bind(n,c)).flat(1):n.recordsFor(c,m);if(l.length===0)return;var y=[];if(m!=="ANY")l.forEach((j)=>{if(j.type!=="PTR")return;y=y.concat(n.recordsFor(j.data,"SRV")).concat(n.recordsFor(j.data,"TXT"))}),y.filter(function(j){return j.type==="SRV"}).map(function(j){return j.data.target}).filter(this.unique()).forEach(function(j){y=y.concat(n.recordsFor(j,"A")).concat(n.recordsFor(j,"AAAA"))});n.mdns.respond({answers:l,additionals:y},(j)=>{if(j)this.errorCallback(j)})})}recordsFor(r,n){if(!(n in this.registry))return[];return this.registry[n].filter((i)=>{var m=~r.indexOf(".")?i.name:i.name.split(".")[0];return(0,bS.default)(m,r)})}isDuplicateRecord(r){return(n)=>{return r.type===n.type&&r.name===n.name&&(0,tS.default)(r.data,n.data)}}unique(){var r=[];return(n)=>{if(~r.indexOf(n))return!1;return r.push(n),!0}}}ni.Server=hc;ni.default=hc});var Ej=nr((Nj)=>{Object.defineProperty(Nj,"__esModule",{value:!0});Nj.default=(r,n)=>{if(n===void 0)return!0;let i=r.txt,m=Object.entries(n).map(([c,l])=>{let y=i[c];if(y===void 0)return!1;if(l!=y)return!1;return!0});if(m.length==0)return!0;if(m.includes(!1))return!1;return!0}});var Dj=nr((Qj)=>{Object.defineProperty(Qj,"__esModule",{value:!0});Qj.default=(r)=>Object.keys(r).filter((n)=>!n.includes("binary")).reduce((n,i)=>{return Object.assign(n,{[i]:r[i]})},{})});var Pj=nr((Uj)=>{Object.defineProperty(Uj,"__esModule",{value:!0});Uj.default=fS;function fS(r,n){if(r===void 0||n===void 0)return!1;let i=Object.keys(r),m=Object.keys(n);if(i.length!=m.length)return!1;for(let c of i)if(r[c]!=n[c])return!1;return!0}});var Xj=nr((ii)=>{var ui=ii&&ii.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(ii,"__esModule",{value:!0});ii.Browser=void 0;var nv=ui(Rc()),qn=ui(pm()),iv=sn("events"),Bc=Vc(),Cj=ui(Ej()),mv=ui(Dj()),cv=ui(Pj()),Wj=".local",lv="_services._dns-sd._udp"+Wj;class tm extends iv.EventEmitter{constructor(r,n,i){super();if(this.onresponse=void 0,this.serviceMap={},this.wildcard=!1,this._services=[],typeof n==="function")return new tm(r,null,n);if(this.mdns=r,this.txt=new nv.default(n!==null&&n.txt!=null?n.txt:void 0),n===null||n.type===void 0)this.name=lv,this.wildcard=!0;else{if(this.name=(0,Bc.toString)({name:n.type,protocol:n.protocol||"tcp"})+Wj,n.name)this.name=n.name+"."+this.name;this.wildcard=!1}if(n!=null&&n.txt!==void 0)this.txtQuery=(0,mv.default)(n.txt);if(i)this.on("up",i);this.start()}start(){if(this.onresponse||this.name===void 0)return;var r=this,n={};if(!this.wildcard)n[this.name]=!0;this.onresponse=(i,m)=>{if(r.wildcard)i.answers.forEach((c)=>{if(c.type!=="PTR"||c.name!==r.name||c.name in n)return;n[c.data]=!0,r.mdns.query(c.data,"PTR")});Object.keys(n).forEach(function(c){r.goodbyes(c,i).forEach(r.removeService.bind(r));var l=r.buildServicesFor(c,i,r.txt,m);if(l.length===0)return;l.forEach((y)=>{if(r.serviceMap[y.fqdn]){r.updateService(y);return}r.addService(y)})})},this.mdns.on("response",this.onresponse),this.update()}stop(){if(!this.onresponse)return;this.mdns.removeListener("response",this.onresponse),this.onresponse=void 0}update(){this.mdns.query(this.name,"PTR")}get services(){return this._services}addService(r){if((0,Cj.default)(r,this.txtQuery)===!1)return;this._services.push(r),this.serviceMap[r.fqdn]=!0,this.emit("up",r)}updateService(r){var n;if((0,cv.default)(r.txt,((n=this._services.find((i)=>(0,qn.default)(i.fqdn,r.fqdn)))===null||n===void 0?void 0:n.txt)||{}))return;if(!(0,Cj.default)(r,this.txtQuery)){this.removeService(r.fqdn);return}this._services=this._services.map(function(i){if(!(0,qn.default)(i.fqdn,r.fqdn))return i;return r}),this.emit("txt-update",r)}removeService(r){var n,i;if(this._services.some(function(m,c){if((0,qn.default)(m.fqdn,r))return n=m,i=c,!0}),!n||i===void 0)return;this._services.splice(i,1),delete this.serviceMap[r],this.emit("down",n)}goodbyes(r,n){return n.answers.concat(n.additionals).filter((i)=>i.type==="PTR"&&i.ttl===0&&(0,qn.default)(i.name,r)).map((i)=>i.data)}buildServicesFor(r,n,i,m){var c=n.answers.concat(n.additionals).filter((l)=>l.ttl>0);return c.filter((l)=>l.type==="PTR"&&(0,qn.default)(l.name,r)).map((l)=>{let y={addresses:[],subtypes:[]};if(c.filter((j)=>{return j.type==="PTR"&&(0,qn.default)(j.data,l.data)&&j.name.includes("._sub")}).forEach((j)=>{let A=(0,Bc.toType)(j.name);y.subtypes.push(A.subtype)}),c.filter((j)=>{return(j.type==="SRV"||j.type==="TXT")&&(0,qn.default)(j.name,l.data)}).forEach((j)=>{if(j.type==="SRV"){var A=j.name.split("."),S=A[0],v=(0,Bc.toType)(A.slice(1,-1).join("."));y.name=S,y.fqdn=j.name,y.host=j.data.target,y.referer=m,y.port=j.data.port,y.type=v.name,y.protocol=v.protocol}else if(j.type==="TXT")y.rawTxt=j.data,y.txt=this.txt.decodeAll(j.data)}),!y.name)return;return c.filter((j)=>(j.type==="A"||j.type==="AAAA")&&(0,qn.default)(j.name,y.host)).forEach((j)=>y.addresses.push(j.data)),y}).filter((l)=>!!l)}}ii.Browser=tm;ii.default=tm});var Kj=nr((dr)=>{var bm=dr&&dr.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(dr,"__esModule",{value:!0});dr.Browser=dr.Service=dr.Bonjour=void 0;var yv=bm(by()),jv=bm(Gj()),xc=bm(Xj());dr.Browser=xc.default;var Iv=bm(Zc());dr.Service=Iv.default;class kc{constructor(r={},n){this.server=new jv.default(r,n),this.registry=new yv.default(this.server)}publish(r){return this.registry.publish(r)}unpublishAll(r){return this.registry.unpublishAll(r)}find(r=null,n){return new xc.default(this.server.mdns,r,n)}findOne(r=null,n=1e4,i){let m=new xc.default(this.server.mdns,r);var c;return m.once("up",(l)=>{if(c!==void 0)clearTimeout(c);if(m.stop(),i)i(l)}),c=setTimeout(()=>{if(m.stop(),i)i(null)},n),m}destroy(r){this.registry.destroy(),this.server.mdns.destroy(r)}}dr.Bonjour=kc;dr.default=kc});var bl={};Nr(bl,{url:()=>vA,openapi:()=>p$,listen:()=>a$,Server:()=>bl,Default:()=>x$});var cc=(r)=>{let n=r.split("/");if(n[0]==="")n.shift();return n},el=(r)=>{let{groups:n,path:i}=wA(r),m=cc(i);return $A(m,n)},wA=(r)=>{let n=[];return r=r.replace(/\{[^}]+\}/g,(i,m)=>{let c=`@${m}`;return n.push([c,i]),c}),{groups:n,path:r}},$A=(r,n)=>{for(let i=n.length-1;i>=0;i--){let[m]=n[i];for(let c=r.length-1;c>=0;c--)if(r[c].includes(m)){r[c]=r[c].replace(m,n[i][1]);break}}return r},gm={},sl=(r,n)=>{if(r==="*")return"*";let i=r.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);if(i){let m=`${r}#${n}`;if(!gm[m])if(i[2])gm[m]=n&&n[0]!==":"&&n[0]!=="*"?[m,i[1],new RegExp(`^${i[2]}(?=/${n})`)]:[r,i[1],new RegExp(`^${i[2]}$`)];else gm[m]=[r,i[1],!0];return gm[m]}return null},vi=(r,n)=>{try{return n(r)}catch{return r.replace(/(?:%[0-9A-Fa-f]{2})+/g,(i)=>{try{return n(i)}catch{return i}})}},fl=(r)=>vi(r,decodeURI),lc=(r)=>{let n=r.url,i=n.indexOf("/",n.indexOf(":")+4),m=i;for(;m<n.length;m++){let c=n.charCodeAt(m);if(c===37){let l=n.indexOf("?",m),y=n.indexOf("#",m),j=l===-1?y===-1?void 0:y:y===-1?l:Math.min(l,y),A=n.slice(i,j);return fl(A.includes("%25")?A.replace(/%25/g,"%2525"):A)}else if(c===63||c===35)break}return n.slice(i,m)};var ry=(r)=>{let n=lc(r);return n.length>1&&n.at(-1)==="/"?n.slice(0,-1):n},On=(r,n,...i)=>{if(i.length)n=On(n,...i);return`${r?.[0]==="/"?"":"/"}${r}${n==="/"?"":`${r?.at(-1)==="/"?"":"/"}${n?.[0]==="/"?n.slice(1):n}`}`},Fm=(r)=>{if(r.charCodeAt(r.length-1)!==63||!r.includes(":"))return null;let n=r.split("/"),i=[],m="";return n.forEach((c)=>{if(c!==""&&!/\:/.test(c))m+="/"+c;else if(/\:/.test(c))if(/\?/.test(c)){if(i.length===0&&m==="")i.push("/");else i.push(m);let l=c.replace("?","");m+="/"+l,i.push(m)}else m+="/"+c}),i.filter((c,l,y)=>y.indexOf(c)===l)},mc=(r)=>{if(!/[%+]/.test(r))return r;if(r.indexOf("+")!==-1)r=r.replace(/\+/g," ");return r.indexOf("%")!==-1?vi(r,oi):r},ny=(r,n,i)=>{let m;if(!i&&n&&!/[%+]/.test(n)){let y=r.indexOf("?",8);if(y===-1)return;if(!r.startsWith(n,y+1))y=r.indexOf(`&${n}`,y+1);while(y!==-1){let j=r.charCodeAt(y+n.length+1);if(j===61){let A=y+n.length+2,S=r.indexOf("&",A);return mc(r.slice(A,S===-1?void 0:S))}else if(j==38||isNaN(j))return"";y=r.indexOf(`&${n}`,y+1)}if(m=/[%+]/.test(r),!m)return}let c={};m??=/[%+]/.test(r);let l=r.indexOf("?",8);while(l!==-1){let y=r.indexOf("&",l+1),j=r.indexOf("=",l);if(j>y&&y!==-1)j=-1;let A=r.slice(l+1,j===-1?y===-1?void 0:y:j);if(m)A=mc(A);if(l=y,A==="")continue;let S;if(j===-1)S="";else if(S=r.slice(j+1,y===-1?void 0:y),m)S=mc(S);if(i){if(!(c[A]&&Array.isArray(c[A])))c[A]=[];c[A].push(S)}else c[A]??=S}return n?c[n]:c},iy=ny,my=(r,n)=>{return ny(r,n,!0)},oi=decodeURIComponent;var GA=/^[\w!#$%&'*.^`|~+-]+$/,NA=/^[ !#-:<-[\]-~]*$/,cy=(r)=>{let n=0,i=r.length;while(n<i){let m=r.charCodeAt(n);if(m!==32&&m!==9)break;n++}while(i>n){let m=r.charCodeAt(i-1);if(m!==32&&m!==9)break;i--}return n===0&&i===r.length?r:r.slice(n,i)},yc=(r,n)=>{if(n&&r.indexOf(n)===-1)return{};let i=r.split(";"),m=Object.create(null);for(let c of i){let l=c.indexOf("=");if(l===-1)continue;let y=cy(c.substring(0,l));if(n&&n!==y||!GA.test(y)||y in m)continue;let j=cy(c.substring(l+1));if(j.startsWith('"')&&j.endsWith('"'))j=j.slice(1,-1);if(NA.test(j)){if(m[y]=j.indexOf("%")!==-1?vi(j,oi):j,n)break}}return m};var ly=(r,n,i)=>{let m=r.req.raw.headers.get("Cookie");if(typeof n==="string"){if(!m)return;let l=n;if(i==="secure")l="__Secure-"+n;else if(i==="host")l="__Host-"+n;return yc(m,l)[l]}if(!m)return{};return yc(m)};var kr=class extends Error{res;status;constructor(r=500,n){super(n?.message,{cause:n?.cause});this.res=n?.res,this.status=r}getResponse(){if(this.res)return new Response(this.res.body,{status:this.status,headers:this.res.headers});return new Response(this.message,{status:this.status})}};var jc=async(r)=>{return await EA(r,{name:"SHA-256",alias:"sha256"})};var EA=async(r,n)=>{let i;if(ArrayBuffer.isView(r)||r instanceof ArrayBuffer)i=r;else{if(typeof r==="object")r=JSON.stringify(r);i=new TextEncoder().encode(String(r))}if(crypto&&crypto.subtle){let m=await crypto.subtle.digest({name:n.name},i);return Array.prototype.map.call(new Uint8Array(m),(l)=>("00"+l.toString(16)).slice(-2)).join("")}return null};var yy=(r,n)=>{let i=r.length,m=n.length,c=Math.max(i,m),l=i^m;for(let y=0;y<c;y++){let j=y<i?r.charCodeAt(y):0,A=y<m?n.charCodeAt(y):0;l|=j^A}return l===0},jy=async(r,n,i)=>{if(!i)i=jc;let[m,c]=await Promise.all([i(r),i(n)]);if(m==null||c==null||typeof m!=="string"||typeof c!=="string")return!1;let l=yy(m,c),y=yy(r,n);return l&&y},Ic=async(r,n,i)=>{if(typeof r==="string"&&typeof n==="string")return jy(r,n,i);if(!i)i=jc;let[m,c]=await Promise.all([i(r),i(n)]);if(!m||!c||typeof m!=="string"||typeof c!=="string")return!1;return jy(m,c)};var zm=(r,n)=>{return new Response(r,{headers:{"Content-Type":n.replace(/^[^;]+/,(m)=>m.toLowerCase())}}).formData()};var QA=/^application\/([a-z-\.]+\+)?json(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/i,DA=/^multipart\/form-data(;\s?boundary=[a-zA-Z0-9'"()+_,\-./:=?]+)?$/i,UA=/^application\/x-www-form-urlencoded(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/i,Ac=(r,n)=>{return async(i,m)=>{let c={},l=i.req.header("Content-Type");switch(r){case"json":if(!l||!QA.test(l))break;try{c=await i.req.json()}catch{throw new kr(400,{message:"Malformed JSON in request body"})}break;case"form":{if(!l||!(DA.test(l)||UA.test(l)))break;let j;if(i.req.bodyCache.formData)j=await i.req.bodyCache.formData;else try{let S=await i.req.arrayBuffer();j=await zm(S,l),i.req.bodyCache.formData=j}catch(S){let v="Malformed FormData request.";throw v+=S instanceof Error?` ${S.message}`:` ${String(S)}`,new kr(400,{message:v})}let A=Object.create(null);j.forEach((S,v)=>{if(v.endsWith("[]"))(A[v]??=[]).push(S);else if(Array.isArray(A[v]))A[v].push(S);else if(Object.hasOwn(A,v))A[v]=[A[v],S];else A[v]=S}),c=A;break}case"query":c=Object.fromEntries(Object.entries(i.req.queries()).map(([j,A])=>{return A.length===1?[j,A[0]]:[j,A]}));break;case"param":c=i.req.param();break;case"header":c=i.req.header();break;case"cookie":c=ly(i);break}let y=await n(c,i);if(y instanceof Response)return y;return i.req.addValidatedData(r,y),await m()}};var Iy={header:["cookie"]};function PA(r,n,i){if(!(i in Iy))return r;let m=Iy[i]||[];if(n==="arktype")return CA(r,m);if(n==="valibot")return WA(r,m);return r}function CA(r,n){return r.map((i)=>{if(i&&typeof i==="object"&&"data"in i&&typeof i.data==="object"&&i.data!==null&&!Array.isArray(i.data)){let m={...i.data};for(let l of n)delete m[l];let c=Object.create(Object.getPrototypeOf(i));return Object.assign(c,i,{data:m}),c}return i})}function WA(r,n){return r.map((i)=>{if(i&&typeof i==="object"&&"path"in i&&Array.isArray(i.path)){for(let m of i.path)if(typeof m==="object"&&"input"in m&&typeof m.input==="object"&&m.input!==null&&!Array.isArray(m.input))for(let c of n)delete m.input[c]}return i})}var Ay=(r,n,i)=>Ac(r,async(m,c)=>{let l=await n["~standard"].validate(m);if(i){let y=await i(l.issues?{data:m,error:l.issues,success:!1,target:r}:{data:m,success:!0,target:r},c);if(y){if(y instanceof Response)return y;if("response"in y)return y.response}}if(l.issues){let y=PA(l.issues,n["~standard"].vendor,r);return c.json({data:m,error:y,success:!1},400)}return l.value});var vc=Symbol("openapi"),KA=["GET","PUT","POST","DELETE","OPTIONS","HEAD","PATCH","TRACE"],HA=(r)=>r.split("/").map((n)=>{let i=n;if(i.startsWith(":")){let m=i.match(/^:([^{?]+)(?:{(.+)})?(\?)?$/);if(m)i=`{${m[1]}}`;else{if(i=i.slice(1,i.length),i.endsWith("?"))i=i.slice(0,-1);i=`{${i}}`}}return i}).join("/"),Sy=(r)=>r.charAt(0).toUpperCase()+r.slice(1),RA=(r)=>{let n=r.method.toLowerCase();if(r.path==="/")return`${n}Index`;for(let i of r.path.split("/"))if(i.charCodeAt(0)===123)n+=`By${Sy(i.slice(1,-1))}`;else n+=Sy(i);return n},VA=(r)=>("$ref"in r)?r.$ref:`${r.in} ${r.name}`;function vy(...r){let n=r.flatMap((i)=>i??[]).reduce((i,m)=>{return i.set(VA(m),m),i},new Map);return Array.from(n.values())}var wi=new Map;function YA(r){let n=[];for(let[i,m]of wi)if(m&&r.match(i))n.push(m);return n}function ZA(){wi.clear()}function wy(r,...n){return n.reduce((i,m)=>{if(!m||!i)return i;for(let[c,l]of Object.entries(m)){if(l==null)continue;if(c in i&&(typeof l==="object"||typeof l==="function"&&c==="operationId"))if(Array.isArray(l)){let y=[...i[c]??[],...l];if(c==="tags")i[c]=Array.from(new Set(y));else if(c==="parameters")i[c]=vy(y);else i[c]=y}else if(typeof l==="function")i[c]=l(r);else if(c==="parameters")i[c]=vy(i[c],l);else i[c]={...i[c],...l};else i[c]=l}return i},{operationId:RA(r)})}function $y({route:r,specs:n,paths:i}){let m=HA(r.path),c=r.method.toLowerCase();if(c==="all"){if(!n)return;if(wi.has(m)){let l=wi.get(m)??{};wi.set(m,wy(r,l,n))}else wi.set(m,n)}else{let l=YA(m);if(!(m in i))i[m]={};if(i[m])i[m][c]=wy(r,...l,i[m]?.[c],n)}}function JA(r,n){let{exclude:i,excludeStaticFile:m}=n.options,c={},l=Array.isArray(i)?i:[i];for(let[y,j]of Object.entries(r)){if(j==null)continue;if(l.some((v)=>{if(typeof v==="string")return y===v;return v.test(y)}))continue;if(y.includes("*")&&!y.includes("{"))continue;if(m){let v=y.includes("{"),N=(y.split("/").pop()||"").includes(".");if(!v&&N)continue}for(let v of Object.keys(j)){let w=j[v];if(w==null)continue;if(y.includes("{")){w.parameters=w.parameters?[...w.parameters]:[];let N=y.split("/").filter((E)=>E.startsWith("{")&&!w.parameters.find((Q)=>Q.in==="path"&&Q.name===E.slice(1,E.length-1)));for(let E of N){let Q=E.slice(1,E.length-1);if(w.parameters.findIndex((H)=>{if("$ref"in H){let X=H.$ref.split("/").pop();if(X){let K=n.components.parameters?.[X];if(K&&!("$ref"in K))return K.in==="path"&&K.name===Q}return!1}return H.in==="path"&&H.name===Q})===-1)w.parameters.push({schema:{type:"string"},in:"path",name:Q,required:!0})}}if(!w.responses)w.responses={200:{}}}c[y]=j}return c}var Gy={documentation:{},excludeStaticFile:!0,exclude:[],excludeMethods:["OPTIONS"],excludeTags:[]};function Qy(r,n){let i;return async(m)=>{if(i)return m.json(i);return i=await wc(r,n,m),m.json(i)}}async function wc(r,n=Gy,i){let m={components:{},options:{...Gy,...n}},c=m.options.documentation??{};ZA();let l=await OA(r,m);for(let j in l)for(let A in l[j])if(LA({valueOrFunc:l[j][A]?.hide,method:A,path:j,c:i}))l[j][A]=void 0;let y=$c(c.components,m.components);return{openapi:"3.1.0",...c,tags:c.tags?.filter((j)=>!m.options.excludeTags?.includes(j?.name)),info:{title:"Hono Documentation",description:"Development documentation",version:"0.0.0",...c.info},paths:{...JA(l,m),...c.paths},components:y}}async function OA(r,n){let i={};for(let m of r.routes){let c=m.handler[vc];if(!c){if(n.options.includeEmptyPaths)$y({route:m,paths:i});continue}let l=m.method;if(l!=="ALL"){if(n.options.excludeMethods?.includes(l))continue;if(!KA.includes(l))continue}let y=n.options.defaultOptions?.[l],{schema:j,components:A={}}=await qA(c,y);n.components=$c(n.components,A),$y({route:m,specs:j,paths:i})}return i}function LA(r){let{valueOrFunc:n,c:i,method:m,path:c}=r;if(n!=null){if(typeof n==="boolean")return n;if(typeof n==="function")return n({c:i,method:m,path:c})}return!1}async function qA(r,n){if("spec"in r){let c={},l={...n,...r.spec,responses:{...n?.responses,...r.spec.responses}};if(l.responses)for(let y of Object.keys(l.responses)){let j=l.responses[y];if(!j||!("content"in j))continue;for(let A of Object.keys(j.content??{})){let S=j.content?.[A];if(!S)continue;if(S.schema&&"toOpenAPISchema"in S.schema){let v=await S.schema.toOpenAPISchema();if(S.schema=v.schema,v.components)c=$c(c,v.components)}}}return{schema:l,components:c}}let i=await r.toOpenAPISchema(),m=n??{};if(r.target==="form"||r.target==="json"){let c=r.options?.media??r.target==="json"?"application/json":"multipart/form-data";if(!m.requestBody||!("content"in m.requestBody)||!m.requestBody.content)m.requestBody={content:{[c]:{schema:i.schema}}};else m.requestBody.content[c]={schema:i.schema}}else{let c=[];if("$ref"in i.schema){let y=i.schema.$ref.split("/").pop();if(y&&i.components?.schemas?.[y]){let j=i.components.schemas[y],A=Ny(r.target,j)[0];if(!i.components.parameters)i.components.parameters={};i.components.parameters[y]=A,delete i.components.schemas[y],c.push({$ref:`#/components/parameters/${y}`})}}else c=Ny(r.target,i.schema);m.parameters=c}return{schema:m,components:i.components}}function Ny(r,n){let i=[];for(let[m,c]of Object.entries(n.properties??{})){let l={in:r==="param"?"path":r,name:m,schema:c};if(n.required?.includes(m))l.required=!0;if(l.schema&&"description"in l.schema&&l.schema.description)l.description=l.schema.description,l.schema.description=void 0;i.push(l)}return i}function $c(...r){return r.reduce((n,i,m)=>{if(i==null||m===0)return n;if(n.schemas&&Object.keys(n.schemas).length>0||i.schemas&&Object.keys(i.schemas).length>0)n.schemas={...n.schemas,...i.schemas};if(n.parameters&&Object.keys(n.parameters).length>0||i.parameters&&Object.keys(i.parameters).length>0)n.parameters={...n.parameters,...i.parameters};return n},r[0]??{})}function $(r,n){return{vendor:r["~standard"].vendor,validate:r["~standard"].validate,toJSONSchema:(i)=>Ey(r,{...n,...i}),toOpenAPISchema:(i)=>Sc(r,{...n,...i})}}function D(r,n,i,m){let c=Ay(r,n,i);return Object.assign(c,{[vc]:{target:r,...$(n,m),options:m}})}function G(r){return Object.assign(async(i,m)=>{await m()},{[vc]:{spec:r}})}var Gc=(r,n,i)=>{return(m,c)=>{let l=-1;return y(0);async function y(j){if(j<=l)throw Error("next() called multiple times");l=j;let A,S=!1,v;if(r[j])v=r[j][0][0],m.req.routeIndex=j;else v=j===r.length&&c||void 0;if(v)try{A=await v(m,()=>y(j+1))}catch(w){if(w instanceof Error&&n)m.error=w,A=await n(w,m),S=!0;else throw w}else if(m.finalized===!1&&i)A=await i(m);if(A&&(m.finalized===!1||S))m.res=A;return m}}};var Dy=Symbol();var Nc=(r)=>("headers"in r),Uy=async(r,n=Object.create(null))=>{let{all:i=!1,dot:m=!1}=n,y=(Nc(r)?r.headers:r.raw.headers).get("Content-Type")?.split(";")[0].trim().toLowerCase();if(y==="multipart/form-data"||y==="application/x-www-form-urlencoded")return _A(r,{all:i,dot:m});return{}};async function _A(r,n){let i=Nc(r)?r.headers:r.raw.headers,m=await r.arrayBuffer(),c=zm(m,i.get("Content-Type")||"");if(!Nc(r))r.bodyCache.formData=c;let l=await c;if(l)return gA(l,n);return{}}function gA(r,n){let i=Object.create(null);if(r.forEach((m,c)=>{if(!(n.all||c.endsWith("[]")))i[c]=m;else FA(i,c,m)}),n.dot)Object.entries(i).forEach(([m,c])=>{if(m.includes("."))zA(i,m,c),delete i[m]});return i}var FA=(r,n,i)=>{if(r[n]!==void 0)if(Array.isArray(r[n]))r[n].push(i);else r[n]=[r[n],i];else if(!n.endsWith("[]"))r[n]=i;else r[n]=[i]},zA=(r,n,i)=>{if(/(?:^|\.)__proto__\./.test(n))return;let m=r,c=n.split(".");c.forEach((l,y)=>{if(y===c.length-1)m[l]=i;else{if(!m[l]||typeof m[l]!=="object"||Array.isArray(m[l])||m[l]instanceof File)m[l]=Object.create(null);m=m[l]}})};var Py=(r)=>vi(r,oi),Cy=class{raw;#r;#n;routeIndex=0;path;bodyCache={};constructor(r,n="/",i=[[]]){this.raw=r,this.path=n,this.#n=i,this.#r={}}param(r){return r?this.#i(r):this.#l()}#i(r){let n=this.#n[0][this.routeIndex][1][r],i=this.#c(n);return i&&/\%/.test(i)?Py(i):i}#l(){let r={},n=Object.keys(this.#n[0][this.routeIndex][1]);for(let i of n){let m=this.#c(this.#n[0][this.routeIndex][1][i]);if(m!==void 0)r[i]=/\%/.test(m)?Py(m):m}return r}#c(r){return this.#n[1]?this.#n[1][r]:r}query(r){return iy(this.url,r)}queries(r){return my(this.url,r)}header(r){if(r)return this.raw.headers.get(r)??void 0;let n={};return this.raw.headers.forEach((i,m)=>{n[m]=i}),n}async parseBody(r){return Uy(this,r)}#m=(r)=>{let{bodyCache:n,raw:i}=this,m=n[r];if(m)return m;let c=Object.keys(n)[0];if(c)return n[c].then((l)=>{if(c==="json")l=JSON.stringify(l);return new Response(l)[r]()});return n[r]=i[r]()};json(){return this.#m("text").then((r)=>JSON.parse(r))}text(){return this.#m("text")}arrayBuffer(){return this.#m("arrayBuffer")}bytes(){return this.#m("arrayBuffer").then((r)=>new Uint8Array(r))}blob(){return this.#m("blob")}formData(){return this.#m("formData")}addValidatedData(r,n){this.#r[r]=n}valid(r){return this.#r[r]}get url(){return this.raw.url}get method(){return this.raw.method}get[Dy](){return this.#n}get matchedRoutes(){return this.#n[0].map(([[,r]])=>r)}get routePath(){return this.#n[0].map(([[,r]])=>r)[this.routeIndex].path}};var om={Stringify:1,BeforeStream:2,Stream:3},Wy=(r,n)=>{let i=new String(r);return i.isEscaped=!0,i.callbacks=n,i};var Mi=async(r,n,i,m,c)=>{if(typeof r==="object"&&!(r instanceof String)){if(!(r instanceof Promise))r=r.toString();if(r instanceof Promise)r=await r}let l=r.callbacks;if(!l?.length)return Promise.resolve(r);if(c)c[0]+=r;else c=[r];let y=Promise.all(l.map((j)=>j({phase:n,buffer:c,context:m}))).then((j)=>Promise.all(j.filter(Boolean).map((A)=>Mi(A,n,!1,m,c))).then(()=>c[0]));if(i)return Wy(await y,l);else return y};var Xy="text/plain; charset=UTF-8",Ec=(r,n)=>{return{"Content-Type":r,...n}},Ti=(r,n)=>new Response(r,n),Qc=class{#r;#n;env={};#i;finalized=!1;error;#l;#c;#m;#S;#I;#A;#j;#v;#w;constructor(r,n){if(this.#r=r,n)this.#c=n.executionCtx,this.env=n.env,this.#A=n.notFoundHandler,this.#w=n.path,this.#v=n.matchResult}get req(){return this.#n??=new Cy(this.#r,this.#w,this.#v),this.#n}get event(){if(this.#c&&"respondWith"in this.#c)return this.#c;else throw Error("This context has no FetchEvent")}get executionCtx(){if(this.#c)return this.#c;else throw Error("This context has no ExecutionContext")}get res(){return this.#m||=Ti(null,{headers:this.#j??=new Headers})}set res(r){if(this.#m&&r){r=Ti(r.body,r);for(let[n,i]of this.#m.headers.entries()){if(n==="content-type")continue;if(n==="set-cookie"){let m=this.#m.headers.getSetCookie();r.headers.delete("set-cookie");for(let c of m)r.headers.append("set-cookie",c)}else r.headers.set(n,i)}}this.#m=r,this.finalized=!0}render=(...r)=>{return this.#I??=(n)=>this.html(n),this.#I(...r)};setLayout=(r)=>this.#S=r;getLayout=()=>this.#S;setRenderer=(r)=>{this.#I=r};header=(r,n,i)=>{if(this.finalized)this.#m=Ti(this.#m.body,this.#m);let m=this.#m?this.#m.headers:this.#j??=new Headers;if(n===void 0)m.delete(r);else if(i?.append)m.append(r,n);else m.set(r,n)};status=(r)=>{this.#l=r};set=(r,n)=>{this.#i??=new Map,this.#i.set(r,n)};get=(r)=>{return this.#i?this.#i.get(r):void 0};get var(){if(!this.#i)return{};return Object.fromEntries(this.#i)}#y(r,n,i){let m=this.#m?new Headers(this.#m.headers):this.#j??new Headers;if(typeof n==="object"&&"headers"in n){let l=n.headers instanceof Headers?n.headers:new Headers(n.headers);for(let[y,j]of l)if(y.toLowerCase()==="set-cookie")m.append(y,j);else m.set(y,j)}if(i)for(let[l,y]of Object.entries(i))if(typeof y==="string")m.set(l,y);else{m.delete(l);for(let j of y)m.append(l,j)}let c=typeof n==="number"?n:n?.status??this.#l;return Ti(r,{status:c,headers:m})}newResponse=(...r)=>this.#y(...r);body=(r,n,i)=>this.#y(r,n,i);text=(r,n,i)=>{return!this.#j&&!this.#l&&!n&&!i&&!this.finalized?new Response(r):this.#y(r,n,Ec(Xy,i))};json=(r,n,i)=>{return this.#y(JSON.stringify(r),n,Ec("application/json",i))};html=(r,n,i)=>{let m=(c)=>this.#y(c,n,Ec("text/html; charset=UTF-8",i));return typeof r==="object"?Mi(r,om.Stringify,!1,{}).then(m):m(r)};redirect=(r,n)=>{let i=String(r);return this.header("Location",!/[^\x00-\xFF]/.test(i)?i:encodeURI(i)),this.newResponse(null,n??302)};notFound=()=>{return this.#A??=()=>Ti(),this.#A(this)}};var B="ALL",Ky="all",Hy=["get","post","put","delete","options","patch"],Mm="Can not add a route since the matcher is already built.",Tm=class extends Error{};var Dc="__COMPOSED_HANDLER";var oA=(r)=>{return r.text("404 Not Found",404)},Ry=(r,n)=>{if("getResponse"in r){let i=r.getResponse();return n.newResponse(i.body,i)}return console.error(r),n.text("Internal Server Error",500)},Vy=class r{get;post;put;delete;options;patch;all;on;use;router;getPath;_basePath="/";#r="/";routes=[];constructor(n={}){[...Hy,Ky].forEach((l)=>{this[l]=(y,...j)=>{if(typeof y==="string")this.#r=y;else this.#l(l,this.#r,y);return j.forEach((A)=>{this.#l(l,this.#r,A)}),this}}),this.on=(l,y,...j)=>{for(let A of[y].flat()){this.#r=A;for(let S of[l].flat())j.map((v)=>{this.#l(S.toUpperCase(),this.#r,v)})}return this},this.use=(l,...y)=>{if(typeof l==="string")this.#r=l;else this.#r="*",y.unshift(l);return y.forEach((j)=>{this.#l(B,this.#r,j)}),this};let{strict:m,...c}=n;Object.assign(this,c),this.getPath=m??!0?n.getPath??lc:ry}#n(){let n=new r({router:this.router,getPath:this.getPath});return n.errorHandler=this.errorHandler,n.#i=this.#i,n.routes=this.routes,n}#i=oA;errorHandler=Ry;route(n,i){let m=this.basePath(n);return i.routes.map((c)=>{let l;if(i.errorHandler===Ry)l=c.handler;else l=async(y,j)=>(await Gc([],i.errorHandler)(y,()=>c.handler(y,j))).res,l[Dc]=c.handler;m.#l(c.method,c.path,l,c.basePath)}),this}basePath(n){let i=this.#n();return i._basePath=On(this._basePath,n),i}onError=(n)=>{return this.errorHandler=n,this};notFound=(n)=>{return this.#i=n,this};mount(n,i,m){let c,l;if(m)if(typeof m==="function")l=m;else if(l=m.optionHandler,m.replaceRequest===!1)c=(A)=>A;else c=m.replaceRequest;let y=l?(A)=>{let S=l(A);return Array.isArray(S)?S:[S]}:(A)=>{let S=void 0;try{S=A.executionCtx}catch{}return[A.env,S]};c||=(()=>{let A=On(this._basePath,n),S=A==="/"?0:A.length;return(v)=>{let w=new URL(v.url);return w.pathname=this.getPath(v).slice(S)||"/",new Request(w,v)}})();let j=async(A,S)=>{let v=await i(c(A.req.raw),...y(A));if(v)return v;await S()};return this.#l(B,On(n,"*"),j),this}#l(n,i,m,c){n=n.toUpperCase(),i=On(this._basePath,i);let l={basePath:c!==void 0?On(this._basePath,c):this._basePath,path:i,method:n,handler:m};this.router.add(n,i,[m,l]),this.routes.push(l)}#c(n,i){if(n instanceof Error)return this.errorHandler(n,i);throw n}#m(n,i,m,c){if(c==="HEAD")return(async()=>new Response(null,await this.#m(n,i,m,"GET")))();let l=this.getPath(n,{env:m}),y=this.router.match(c,l),j=new Qc(n,{path:l,matchResult:y,env:m,executionCtx:i,notFoundHandler:this.#i});if(y[0].length===1){let S;try{S=y[0][0][0][0](j,async()=>{j.res=await this.#i(j)})}catch(v){return this.#c(v,j)}return S instanceof Promise?S.then((v)=>v||(j.finalized?j.res:this.#i(j))).catch((v)=>this.#c(v,j)):S??this.#i(j)}let A=Gc(y[0],this.errorHandler,this.#i);return(async()=>{try{let S=await A(j);if(!S.finalized)throw Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");return S.res}catch(S){return this.#c(S,j)}})()}fetch=(n,...i)=>{return this.#m(n,i[1],i[0],n.method)};request=(n,i,m,c)=>{if(n instanceof Request)return this.fetch(i?new Request(n,i):n,m,c);return n=n.toString(),this.fetch(new Request(/^https?:\/\//.test(n)?n:`http://localhost${On("/",n)}`,i),m,c)};fire=()=>{addEventListener("fetch",(n)=>{n.respondWith(this.#m(n.request,n,void 0,n.request.method))})}};var hi=[];function hm(r,n){let i=this.buildAllMatchers(),m=(c,l)=>{let y=i[c]||i[B],j=y[2][l];if(j)return j;let A=l.match(y[0]);if(!A)return[[],hi];let S=A.indexOf("",1);return[y[1][S],A]};return this.match=m,m(r,n)}var Bm="[^/]+",Bi=".*",xi="(?:|/.*)",bn=Symbol(),MA=new Set(".\\+*[^]$()");function TA(r,n){if(r.length===1)return n.length===1?r<n?-1:1:-1;if(n.length===1)return 1;if(r===Bi||r===xi)return 1;else if(n===Bi||n===xi)return-1;if(r===Bm)return 1;else if(n===Bm)return-1;return r.length===n.length?r<n?-1:1:n.length-r.length}var Yy=class r{#r;#n;#i=Object.create(null);insert(n,i,m,c,l){if(n.length===0){if(this.#r!==void 0)throw bn;if(l)return;this.#r=i;return}let[y,...j]=n,A=y==="*"?j.length===0?["","",Bi]:["","",Bm]:y==="/*"?["","",xi]:y.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/),S;if(A){let v=A[1],w=A[2]||Bm;if(v&&A[2]){if(w===".*")throw bn;if(w=w.replace(/^\((?!\?:)(?=[^)]+\)$)/,"(?:"),/\((?!\?:)/.test(w))throw bn}if(S=this.#i[w],!S){if(Object.keys(this.#i).some((N)=>N!==Bi&&N!==xi))throw bn;if(l)return;if(S=this.#i[w]=new r,v!=="")S.#n=c.varIndex++}if(!l&&v!=="")m.push([v,S.#n])}else if(S=this.#i[y],!S){if(Object.keys(this.#i).some((v)=>v.length>1&&v!==Bi&&v!==xi))throw bn;if(l)return;S=this.#i[y]=new r}S.insert(j,i,m,c,l)}buildRegExpStr(){let i=Object.keys(this.#i).sort(TA).map((m)=>{let c=this.#i[m];return(typeof c.#n==="number"?`(${m})@${c.#n}`:MA.has(m)?`\\${m}`:m)+c.buildRegExpStr()});if(typeof this.#r==="number")i.unshift(`#${this.#r}`);if(i.length===0)return"";if(i.length===1)return i[0];return"(?:"+i.join("|")+")"}};var Zy=class{#r={varIndex:0};#n=new Yy;insert(r,n,i){let m=[],c=[];for(let y=0;;){let j=!1;if(r=r.replace(/\{[^}]+\}/g,(A)=>{let S=`@\\${y}`;return c[y]=[S,A],y++,j=!0,S}),!j)break}let l=r.match(/(?::[^\/]+)|(?:\/\*$)|./g)||[];for(let y=c.length-1;y>=0;y--){let[j]=c[y];for(let A=l.length-1;A>=0;A--)if(l[A].indexOf(j)!==-1){l[A]=l[A].replace(j,c[y][1]);break}}return this.#n.insert(l,n,m,this.#r,i),m}buildRegExp(){let r=this.#n.buildRegExpStr();if(r==="")return[/^$/,[],[]];let n=0,i=[],m=[];return r=r.replace(/#(\d+)|@(\d+)|\.\*\$/g,(c,l,y)=>{if(l!==void 0)return i[++n]=Number(l),"$()";if(y!==void 0)return m[Number(y)]=++n,"";return""}),[new RegExp(`^${r}`),i,m]}};var hA=[/^$/,[],Object.create(null)],Jy=Object.create(null);function Oy(r){return Jy[r]??=new RegExp(r==="*"?"":`^${r.replace(/\/\*$|([.\\+*[^\]$()])/g,(n,i)=>i?`\\${i}`:"(?:|/.*)")}$`)}function BA(){Jy=Object.create(null)}function xA(r){let n=new Zy,i=[];if(r.length===0)return hA;let m=r.map((S)=>[!/\*|\/:/.test(S[0]),...S]).sort(([S,v],[w,N])=>S?1:w?-1:v.length-N.length),c=Object.create(null);for(let S=0,v=-1,w=m.length;S<w;S++){let[N,E,Q]=m[S];if(N)c[E]=[Q.map(([H])=>[H,Object.create(null)]),hi];else v++;let W;try{W=n.insert(E,v,N)}catch(H){throw H===bn?new Tm(E):H}if(N)continue;i[v]=Q.map(([H,X])=>{let K=Object.create(null);X-=1;for(;X>=0;X--){let[J,q]=W[X];K[J]=q}return[H,K]})}let[l,y,j]=n.buildRegExp();for(let S=0,v=i.length;S<v;S++)for(let w=0,N=i[S].length;w<N;w++){let E=i[S][w]?.[1];if(!E)continue;let Q=Object.keys(E);for(let W=0,H=Q.length;W<H;W++)E[Q[W]]=j[E[Q[W]]]}let A=[];for(let S in y)A[S]=i[y[S]];return[l,A,c]}function $i(r,n){if(!r)return;for(let i of Object.keys(r).sort((m,c)=>c.length-m.length))if(Oy(i).test(n))return[...r[i]];return}var xm=class{name="RegExpRouter";#r;#n;constructor(){this.#r={[B]:Object.create(null)},this.#n={[B]:Object.create(null)}}add(r,n,i){let m=this.#r,c=this.#n;if(!m||!c)throw Error(Mm);if(!m[r])[m,c].forEach((j)=>{j[r]=Object.create(null),Object.keys(j[B]).forEach((A)=>{j[r][A]=[...j[B][A]]})});if(n==="/*")n="*";let l=(n.match(/\/:/g)||[]).length;if(/\*$/.test(n)){let j=Oy(n);if(r===B)Object.keys(m).forEach((A)=>{m[A][n]||=$i(m[A],n)||$i(m[B],n)||[]});else m[r][n]||=$i(m[r],n)||$i(m[B],n)||[];Object.keys(m).forEach((A)=>{if(r===B||r===A)Object.keys(m[A]).forEach((S)=>{j.test(S)&&m[A][S].push([i,l])})}),Object.keys(c).forEach((A)=>{if(r===B||r===A)Object.keys(c[A]).forEach((S)=>j.test(S)&&c[A][S].push([i,l]))});return}let y=Fm(n)||[n];for(let j=0,A=y.length;j<A;j++){let S=y[j];Object.keys(c).forEach((v)=>{if(r===B||r===v)c[v][S]||=[...$i(m[v],S)||$i(m[B],S)||[]],c[v][S].push([i,l-A+j+1])})}}match=hm;buildAllMatchers(){let r=Object.create(null);return Object.keys(this.#n).concat(Object.keys(this.#r)).forEach((n)=>{r[n]||=this.#i(n)}),this.#r=this.#n=void 0,BA(),r}#i(r){let n=[],i=r===B;if([this.#r,this.#n].forEach((m)=>{let c=m[r]?Object.keys(m[r]).map((l)=>[l,m[r][l]]):[];if(c.length!==0)i||=!0,n.push(...c);else if(r!==B)n.push(...Object.keys(m[B]).map((l)=>[l,m[B][l]]))}),!i)return null;else return xA(n)}};var kA=class{name="PreparedRegExpRouter";#r;#n;constructor(r,n){this.#r=r,this.#n=n}#i(r,n){let i=this.#r[r];i[1].forEach((m)=>m&&m.push(n)),Object.values(i[2]).forEach((m)=>m[0].push(n))}#l(r,n,i,m,c){let l=this.#r[r];if(!c)l[2][n][0].push([i,{}]);else m.forEach((y)=>{if(typeof y==="number")l[1][y].push([i,c]);else l[2][y||n][0].push([i,c])})}add(r,n,i){if(!this.#r[r]){let c=this.#r[B],l={};for(let y in c[2])l[y]=[c[2][y][0].slice(),hi];this.#r[r]=[c[0],c[1].map((y)=>Array.isArray(y)?y.slice():0),l]}if(n==="/*"||n==="*"){let c=[i,{}];if(r===B)for(let l in this.#r)this.#i(l,c);else this.#i(r,c);return}let m=this.#n[n];if(!m)throw Error(`Path ${n} is not registered`);for(let[c,l]of m)if(r===B)for(let y in this.#r)this.#l(y,n,i,c,l);else this.#l(r,n,i,c,l)}buildAllMatchers(){return this.#r}match=hm};var Uc=class{name="SmartRouter";#r=[];#n=[];constructor(r){this.#r=r.routers}add(r,n,i){if(!this.#n)throw Error(Mm);this.#n.push([r,n,i])}match(r,n){if(!this.#n)throw Error("Fatal error");let i=this.#r,m=this.#n,c=i.length,l=0,y;for(;l<c;l++){let j=i[l];try{for(let A=0,S=m.length;A<S;A++)j.add(...m[A]);y=j.match(r,n)}catch(A){if(A instanceof Tm)continue;throw A}this.match=j.match.bind(j),this.#r=[j],this.#n=void 0;break}if(l===c)throw Error("Fatal error");return this.name=`SmartRouter + ${this.activeRouter.name}`,y}get activeRouter(){if(this.#n||this.#r.length!==1)throw Error("No active router has been determined yet.");return this.#r[0]}};var ki=Object.create(null),pA=(r)=>{for(let n in r)return!0;return!1},Ly=class r{#r;#n;#i;#l=0;#c=ki;constructor(n,i,m){if(this.#n=m||Object.create(null),this.#r=[],n&&i){let c=Object.create(null);c[n]={handler:i,possibleKeys:[],score:0},this.#r=[c]}this.#i=[]}insert(n,i,m){this.#l=++this.#l;let c=this,l=el(i),y=[];for(let j=0,A=l.length;j<A;j++){let S=l[j],v=l[j+1],w=sl(S,v),N=Array.isArray(w)?w[0]:S;if(N in c.#n){if(c=c.#n[N],w)y.push(w[1]);continue}if(c.#n[N]=new r,w)c.#i.push(w),y.push(w[1]);c=c.#n[N]}return c.#r.push({[n]:{handler:m,possibleKeys:y.filter((j,A,S)=>S.indexOf(j)===A),score:this.#l}}),c}#m(n,i,m,c,l){for(let y=0,j=i.#r.length;y<j;y++){let A=i.#r[y],S=A[m]||A[B],v={};if(S!==void 0){if(S.params=Object.create(null),n.push(S),c!==ki||l&&l!==ki)for(let w=0,N=S.possibleKeys.length;w<N;w++){let E=S.possibleKeys[w],Q=v[S.score];S.params[E]=l?.[E]&&!Q?l[E]:c[E]??l?.[E],v[S.score]=!0}}}}search(n,i){let m=[];this.#c=ki;let l=[this],y=cc(i),j=[],A=y.length,S=null;for(let v=0;v<A;v++){let w=y[v],N=v===A-1,E=[];for(let W=0,H=l.length;W<H;W++){let X=l[W],K=X.#n[w];if(K)if(K.#c=X.#c,N){if(K.#n["*"])this.#m(m,K.#n["*"],n,X.#c);this.#m(m,K,n,X.#c)}else E.push(K);for(let J=0,q=X.#i.length;J<q;J++){let z=X.#i[J],L=X.#c===ki?{}:{...X.#c};if(z==="*"){let hr=X.#n["*"];if(hr)this.#m(m,hr,n,X.#c),hr.#c=L,E.push(hr);continue}let[rr,Tr,Yr]=z;if(!w&&!(Yr instanceof RegExp))continue;let k=X.#n[rr];if(Yr instanceof RegExp){if(S===null){S=Array(A);let Si=i[0]==="/"?1:0;for(let zi=0;zi<A;zi++)S[zi]=Si,Si+=y[zi].length+1}let hr=i.substring(S[v]),Jn=Yr.exec(hr);if(Jn){if(L[Tr]=Jn[0],this.#m(m,k,n,X.#c,L),Jn[0].length===hr.length&&k.#n["*"])this.#m(m,k.#n["*"],n,X.#c,L);if(pA(k.#n)){k.#c=L;let Si=Jn[0].match(/\//)?.length??0;(j[Si]||=[]).push(k)}continue}}if(Yr===!0||Yr.test(w))if(L[Tr]=w,N){if(this.#m(m,k,n,L,X.#c),k.#n["*"])this.#m(m,k.#n["*"],n,L,X.#c)}else k.#c=L,E.push(k)}}let Q=j.shift();l=Q?E.concat(Q):E}if(m.length>1)m.sort((v,w)=>{return v.score-w.score});return[m.map(({handler:v,params:w})=>[v,w])]}};var Pc=class{name="TrieRouter";#r;constructor(){this.#r=new Ly}add(r,n,i){let m=Fm(n);if(m){for(let c=0,l=m.length;c<l;c++)this.#r.insert(r,m[c],i);return}this.#r.insert(r,n,i)}match(r,n){return this.#r.search(r,n)}};var V=class extends Vy{constructor(r={}){super(r);this.router=r.router??new Uc({routers:[new xm,new Pc]})}};var Cc=/^\s*(?:text\/(?!event-stream(?:[;\s]|$))[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|msgpack|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|vnd\.msgpack|wasm|x-httpd-php|x-javascript|x-msgpack|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml|msgpack))(?:[;\s]|$)/i;var aA={br:".br",zstd:".zst",gzip:".gz"},aN=Object.keys(aA);var Wc="x-hono-disable-ssg",vE=(()=>{try{return new Response("SSG is disabled",{status:404,headers:{[Wc]:"true"}})}catch{return null}})();var{write:uE}=Bun;var qy=class{#r;constructor(r){this.#r=r,this.raw=r.raw,this.url=r.url?new URL(r.url):null,this.protocol=r.protocol??null}send(r,n){this.#r.send(r,n??{})}raw;binaryType="arraybuffer";get readyState(){return this.#r.readyState}url;protocol;close(r,n){this.#r.close(r,n)}},_y=(r)=>{return new MessageEvent("message",{data:r})},gy=(r)=>{return(...n)=>{if(typeof n[0]==="function"){let[i,m]=n;return async function(l,y){let j=await i(l),A=await r(l,j,m);if(A)return A;await y()}}else{let[i,m,c]=n;return(async()=>{let l=await r(i,m,c);if(!l)throw Error("Failed to upgrade WebSocket");return l})()}}};var km=(r)=>("server"in r.env)?r.env.server:r.env;var Xc=(r)=>{return new qy({send:(n,i)=>{r.send(n,i?.compress)},raw:r,readyState:r.readyState,url:r.data.url,protocol:r.data.protocol,close(n,i){r.close(n,i)}})},Fy=gy((r,n)=>{let i=km(r);if(!i)throw TypeError("env has to include the 2nd argument of fetch.");if(i.upgrade(r.req.raw,{data:{events:n,url:new URL(r.req.url),protocol:r.req.header("sec-websocket-protocol")?.split(",")[0]?.trim()??""}}))return new Response(null);return}),zy={open(r){let n=r.data.events;if(n.onOpen)n.onOpen(new Event("open"),Xc(r))},close(r,n,i){let m=r.data.events;if(m.onClose)m.onClose(new CloseEvent("close",{code:n,reason:i}),Xc(r))},message(r,n){let i=r.data.events;if(i.onMessage){let m=typeof n==="string"?n:n.buffer;i.onMessage(_y(m),Xc(r))}}},Kc=()=>({upgradeWebSocket:Fy,websocket:zy});var oy={create(r){let n=Kc();return{upgradeWebSocket:n.upgradeWebSocket,async listen(i){let m={fetch:r.fetch,hostname:i.hostname,idleTimeout:0,websocket:n.websocket},c=(y)=>{try{return Bun.serve({...m,port:y})}catch{return}},l=i.port===0?c(4096)??c(0):c(i.port);if(!l)throw Error(`Failed to start server on port ${i.port}`);if(!l.port)throw Error(`Failed to resolve server address for port ${i.port}`);return{port:l.port,stop(y){return Promise.resolve(l.stop(y))}}}}}};var Ei={};Nr(Ei,{unpublish:()=>Rj,publish:()=>Sv,MDNS:()=>Ei});var Hj=Av(Kj(),1),di=_.create({service:"mdns"}),yn,em;function Sv(r,n){if(em===r)return;if(yn)Rj();try{let i=n??"qitqode.local",m=`qitqode-${r}`;yn=new Hj.Bonjour;let c=yn.publish({name:m,type:"http",host:i,port:r,txt:{path:"/"}});c.on("up",()=>{di.info("mDNS service published",{name:m,port:r})}),c.on("error",(l)=>{di.error("mDNS service error",{error:l})}),em=r}catch(i){if(di.error("mDNS publish failed",{error:i}),yn)try{yn.destroy()}catch{}yn=void 0,em=void 0}}function Rj(){if(yn){try{yn.unpublishAll(),yn.destroy()}catch(r){di.error("mDNS unpublish failed",{error:r})}yn=void 0,em=void 0,di.info("mDNS service unpublished")}}var Vj=(r)=>{let n=atob(r),i=new Uint8Array(new ArrayBuffer(n.length)),m=n.length/2;for(let c=0,l=n.length-1;c<=m;c++,l--)i[c]=n.charCodeAt(c),i[l]=n.charCodeAt(l);return i};var vv=/^ *(?:[Bb][Aa][Ss][Ii][Cc]) +([A-Za-z0-9._~+/-]+=*) *$/,wv=/^([^:]*):(.*)$/,$v=new TextDecoder,Yj=(r)=>{let n=vv.exec(r.headers.get("Authorization")||"");if(!n)return;let i=void 0;try{i=wv.exec($v.decode(Vj(n[1])))}catch{}if(!i)return;return{username:i[1],password:i[2]}};var Zj=(r,...n)=>{let i="username"in r&&"password"in r,m="verifyUser"in r;if(!(i||m))throw Error('basic auth middleware requires options for "username and password" or "verifyUser"');if(!r.realm)r.realm="Secure Area";if(!r.invalidUserMessage)r.invalidUserMessage="Unauthorized";if(i)n.unshift({username:r.username,password:r.password});return async function(l,y){let j=Yj(l.req.raw);if(j)if(m){if(await r.verifyUser(j.username,j.password,l)){if(r.onAuthSuccess)await r.onAuthSuccess(l,j.username);await y();return}}else for(let N of n){let[E,Q]=await Promise.all([Ic(N.username,j.username,r.hashFunction),Ic(N.password,j.password,r.hashFunction)]);if(E&&Q){if(r.onAuthSuccess)await r.onAuthSuccess(l,j.username);await y();return}}let A=401,S={"WWW-Authenticate":'Basic realm="'+r.realm?.replace(/"/g,"\\\"")+'"'},v=typeof r.invalidUserMessage==="function"?await r.invalidUserMessage(l):r.invalidUserMessage,w=typeof v==="string"?new Response(v,{status:A,headers:S}):new Response(JSON.stringify(v),{status:A,headers:{...S,"content-type":"application/json"}});throw new kr(A,{res:w})}};var Jj=(r)=>{let n={origin:"*",allowMethods:["GET","HEAD","PUT","POST","DELETE","PATCH"],allowHeaders:[],exposeHeaders:[],...r},i=((c)=>{if(typeof c==="string")if(c==="*")return()=>c;else return(l)=>c===l?l:null;else if(typeof c==="function")return c;else return(l)=>c.includes(l)?l:null})(n.origin),m=((c)=>{if(typeof c==="function")return c;else if(Array.isArray(c))return()=>c;else return()=>[]})(n.allowMethods);return async function(l,y){function j(S,v){l.res.headers.set(S,v)}let A=await i(l.req.header("origin")||"",l);if(A)j("Access-Control-Allow-Origin",A);if(n.credentials)j("Access-Control-Allow-Credentials","true");if(n.exposeHeaders?.length)j("Access-Control-Expose-Headers",n.exposeHeaders.join(","));if(l.req.method==="OPTIONS"){if(n.origin!=="*")j("Vary","Origin");if(n.maxAge!=null)j("Access-Control-Max-Age",n.maxAge.toString());let S=await m(l.req.header("origin")||"",l);if(S.length)j("Access-Control-Allow-Methods",S.join(","));let v=n.allowHeaders;if(!v?.length){let w=l.req.header("Access-Control-Request-Headers");if(w)v=w.split(/\s*,\s*/)}if(v?.length)j("Access-Control-Allow-Headers",v.join(",")),l.res.headers.append("Vary","Access-Control-Request-Headers");return l.res.headers.delete("Content-Length"),l.res.headers.delete("Content-Type"),new Response(null,{headers:l.res.headers,status:204,statusText:"No Content"})}if(await y(),n.origin!=="*")l.header("Vary","Origin",{append:!0})}};var Lj=(r)=>r===32||r===9||r===10||r===13,sm=(r,n)=>{while(n<r.length){if(!Lj(r.charCodeAt(n)))break;n++}return n},ti=(r,n)=>{while(n>0){if(!Lj(r.charCodeAt(n-1)))break;n--}return n},Oj=(r,n)=>{while(n<r.length){let i=r.charCodeAt(n);if(i===59)return[n+1,!0];if(i===44)return[n+1,!1];n++}return[n,!1]},Gv=(r,n)=>{let i=n,m=!1;while(i<r.length){let c=r.charCodeAt(i);if(m&&c===92)i++;else if(c===34)m=!m;else if(!m&&c===44)return i+1;i++}return i},Nv=(r,n)=>{n=sm(r,n);let i=n,m,c,l=!1;while(i<r.length){let A=r.charCodeAt(i);if(A===61){m=r.slice(n,ti(r,i)),i++;break}if(A===59)return[i+1,void 0,void 0,!0];if(A===44)return[i+1,void 0,void 0,!1];i++}if(m===void 0)return[i,void 0,void 0,!1];if(i=sm(r,i),r.charCodeAt(i)===61){let A=Oj(r,i+1);return[A[0],m,void 0,A[1]]}let y=!1,j=i;while(i<r.length){let A=r.charCodeAt(i);if(y&&A===92)i++;else if(A===34){if(y){let S=sm(r,i+1),v=r.charCodeAt(S);if(S<r.length&&!(v===59||v===44)){let w=Oj(r,S);return[w[0],m,void 0,w[1]]}if(c=r.slice(j+1,i),c.includes("\\"))c=c.replace(/\\(.)/g,"$1");if(v===44)return[S+1,m,c,!1];if(v===59)l=!0,S++;i=S;break}y=!0}else if(!y&&(A===59||A===44)){if(c=r.slice(j,ti(r,i)),A===59)l=!0;i++;break}i++}return[i,m,c??r.slice(j,ti(r,i)),l]},Ev=(r,n)=>{let i={type:"",params:{},q:1};n=sm(r,n);let m=n;while(m<r.length){let j=r.charCodeAt(m);if(j===59||j===44){if(i.type=r.slice(n,ti(r,m)),m++,j===44)return[m,i.type?i:void 0];if(!i.type)return[Gv(r,m),void 0];break}m++}if(!i.type)return i.type=r.slice(n,ti(r,r.length)),[r.length,i.type?i:void 0];let c,l,y;while(m<r.length){if([m,c,l,y]=Nv(r,m),c&&l)i.params[c]=l;if(!y)break}return[m,i]},qj=(r)=>{if(!r)return[];let n=[],i=0,m,c=!1,l;while(i<r.length)if([i,m]=Ev(r,i),m){if(m.q=Qv(m.params.q),n.push(m),l&&l.q<m.q)c=!0;l=m}if(c)n.sort((y,j)=>j.q-y.q);return n},Qv=(r)=>{if(r===void 0)return 1;if(r==="")return 1;if(r==="NaN")return 0;let n=Number(r);if(n===1/0)return 1;if(n===-1/0)return 0;if(Number.isNaN(n))return 1;if(n<0||n>1)return 1;return n};var Dv=["gzip","deflate"],Uv=/(?:^|,)\s*?no-transform\s*?(?:,|$)/i,Pv=(r,n)=>{if(r===void 0)return;let i=qj(r),m=i.find((l)=>l.type==="*")?.q,c;for(let l of n){let y=i.find((A)=>A.type.toLowerCase()===l),j=y?y.q:m??0;if(j===1)return l;else if(j>0&&(!c||j>c.q))c={encoding:l,q:j}}return c?.encoding},_j=(r)=>{let n=r?.threshold??1024,i=r?.encoding?[r.encoding]:Dv,m=r?.contentTypeFilter??Cc,c=typeof m==="function"?(l)=>{let y=l.headers.get("Content-Type");return y&&m(y)}:(l)=>{let y=l.headers.get("Content-Type");return y&&m.test(y)};return async function(y,j){await j();let A=y.res.headers.get("Content-Length");if(y.res.status===206||y.res.headers.has("Content-Encoding")||y.res.headers.has("Transfer-Encoding")||y.req.method==="HEAD"||A&&Number(A)<n||!c(y.res)||!Cv(y.res))return;let S=y.req.header("Accept-Encoding"),v=Pv(S,i);if(!v||!y.res.body)return;let w=new CompressionStream(v);y.res=new Response(y.res.body.pipeThrough(w),y.res),y.res.headers.delete("Content-Length"),y.res.headers.set("Content-Encoding",v);let N=y.res.headers.get("ETag");if(N&&!N.startsWith("W/"))y.res.headers.set("ETag",`W/${N}`)}},Cv=(r)=>{let n=r.headers.get("Cache-Control");return!n||!Uv.test(n)};import{randomUUID as Wv}from"crypto";var fm="ticket",gj="x-qitqode-ticket",Fj="1",Xv=/^\/pty\/[^/]+\/connect$/,Kv=60000,bi=new Map;function Hv(){let r=Date.now();for(let[n,i]of bi)if(i.expiresAt<=r)bi.delete(n)}function zj(r){return Xv.test(r)}function oj(r,n=Kv){Hv();let i=Wv();return bi.set(i,{ptyID:r,expiresAt:Date.now()+n}),{ticket:i,expires_in:Math.round(n/1000)}}function Mj(r,n){let i=bi.get(r);if(!i)return!1;if(bi.delete(r),i.expiresAt<=Date.now())return!1;return i.ptyID===n}var n0=_.create({service:"server"}),hj=(r,n)=>{let i=Tj(r),m=i.errorID;n0.error("failed",{error_id:m,error:r});let c=()=>n.json(new r0.Unknown({message:"Internal server error",diagnostic:i}).toObject(),{status:500,headers:{"x-qitqode-error-id":m}});if(r instanceof r0){let l;if(r instanceof Wn)l=404;else if(r instanceof ir.ModelNotFoundError)l=400;else if(r.name==="ProviderAuthValidationFailed")l=400;else if(r.name.startsWith("Worktree"))l=400;else l=500;if(l===500)return c();return n.json(r.toObject(),{status:l,headers:{"x-qitqode-error-id":m}})}if(r instanceof Z.BusyError)return n.json(new r0.Unknown({message:r.message,diagnostic:i}).toObject(),{status:409,headers:{"x-qitqode-error-id":m}});if(r instanceof kr)return r.getResponse();return c()},Bj=(r,n)=>{if(r.req.method==="OPTIONS")return n();let i=p.QITQODE_SERVER_PASSWORD;if(!i)return n();let m=new URL(r.req.url).pathname;if(zj(m)&&r.req.query(fm))return n();let c=p.QITQODE_SERVER_USERNAME??"qitqode";return Zj({username:c,password:i})(r,n)},xj=async(r,n)=>{let i=r.req.path==="/log";if(!i)n0.info("request",{method:r.req.method,path:r.req.path});let m=n0.time("request",{method:r.req.method,path:r.req.path});if(await n(),!i)m.stop()};function kj(r){return Jj({maxAge:86400,origin(n){if(!n)return;if(r?.cors?.includes(n))return n}})}function Rv(r){return r==="localhost"||r==="::1"||/^127(\.\d{1,3}){3}$/.test(r)||r==="127.0.0.1"}function Vv(r){if(r.startsWith("[")){let n=r.indexOf("]");return n===-1?r:r.slice(1,n)}return r.split(":")[0]}function pj(r){let n=r.hostname===void 0,i=r.hostname==="0.0.0.0"||r.hostname==="::";return(m,c)=>{if(n||i)return c();let l=m.req.header("host");if(!l)return c();let y=Vv(l);if(Rv(y))return c();if(r.hostname&&y===r.hostname)return c();if(r.mdnsDomain&&y===r.mdnsDomain)return c();if(r.allowedHosts?.includes(y))return c();throw n0.warn("rejected request with unexpected Host header",{host:y}),new kr(403,{message:`Forbidden: unexpected Host header "${y}"`})}}var Yv=_j(),aj=(r,n)=>{let i=r.req.path,m=r.req.method;if(i==="/event"||i==="/global/event")return n();if(m==="POST"&&/\/session\/[^/]+\/(message|prompt_async)$/.test(i))return n();return Yv(r,n)};var a={};Nr(a,{waitForSync:()=>hv,status:()=>Mv,startWorkspaceSyncing:()=>ac,sessionRestore:()=>gv,remove:()=>zv,list:()=>Fv,isSyncing:()=>Tv,get:()=>i2,create:()=>qv,Workspace:()=>a,Info:()=>i0,Event:()=>si,ConnectionStatus:()=>n2});var uj=["forgewise"];var Zv=new TextEncoder;function Jv(r){return Zv.encode(r).byteLength}function dj(r,n=16384){let i=[...uj.filter((l)=>(l in r)),...Object.keys(r).filter((l)=>!uj.includes(l))],m={},c=0;for(let l of i){let y={...m,[l]:r[l]},j=JSON.stringify(y);if(Jv(j)>n)continue;m[l]=r[l],c+=1}if(c===0)return;return JSON.stringify(m)}var Hr=tj("workspace",{id:_n().$type().primaryKey(),type:_n().notNull(),name:_n().notNull().default(""),branch:_n(),directory:_n(),extra:_n({mode:"json"}),project_id:_n().$type().notNull().references(()=>bj.id,{onDelete:"cascade"})});async function ej(r,n,i){let m=r.getReader(),c=new TextDecoder,l="",y="",j=1000,A=()=>{m.cancel().catch(()=>{return})};if(n.addEventListener("abort",A),n.aborted)A();try{while(!n.aborted){let S=await m.read().catch(()=>({done:!0,value:void 0}));if(S.done)break;l+=c.decode(S.value,{stream:!0}),l=l.replace(/\r\n/g,`
|
|
3
3
|
`).replace(/\r/g,`
|
|
4
4
|
`);let v=l.split(`
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Gj as s,Lj as e,Mj as j,Nj as v,Zj as u,_j as f}from"./chunk-
|
|
2
|
+
import{Gj as s,Lj as e,Mj as j,Nj as v,Zj as u,_j as f}from"./chunk-5asf8f41.js";import{Cl as D,Gl as b,Hl as a,Il as t,tl as r,ul as C,vl as k,wl as m}from"./chunk-rt49c6js.js";import{Bm as c,Im as i,tm as x,um as q,wm as n,xm as o,zm as K}from"./chunk-31a47ptm.js";import{Yt as Q_}from"./chunk-5dvy83ms.js";import{cu as d,hu as g,mu as O_}from"./chunk-ffx0cr44.js";import{wP as S_}from"./chunk-sh03ka27.js";var l={};S_(l,{run:()=>h_,encodeDir:()=>k_,ClaudeImport:()=>l});import E_ from"path";import W_ from"path";import{access as X_,readFile as Y_}from"fs/promises";var G=n("external_import",{source:q().$type().notNull(),source_key:q().notNull(),session_id:q().$type().notNull(),source_path:q().notNull(),source_mtime:x().notNull(),time_imported:x().notNull(),message_ids:q({mode:"json"}).$type()},(N)=>[o({columns:[N.source,N.source_key]})]);function Z_(){return{scanned:0,imported:0,resynced:0,skipped:0,errors:[]}}async function L_(N){if(!N||!await g.exists(N))return{id:b.global,worktree:N||"/",vcs:null};if(!await a(N))return{id:b.global,worktree:N,vcs:null};return{id:await t(N),worktree:N,vcs:"git"}}function __(N){return N.split(`
|
|
3
3
|
`).map((_)=>_.trim()).filter(Boolean).flatMap((_)=>{try{return[JSON.parse(_)]}catch{return[]}})}function N_(N){let _=N.find((H)=>H.trim()&&!H.trim().startsWith("<"));if(!_)return;return _.trim().replace(/\s+/g," ").slice(0,100)}function R_(N,_){return D.use((H)=>H.select().from(G).where(c(K(G.source,N),K(G.source_key,_))).get())}function G_(N,_){if(!_)return{existing:void 0,existingUpdated:void 0};let H=_,O=D.use((Z)=>Z.select({updated:C.time_updated}).from(C).where(K(C.id,H.session_id)).get());if(!O)return D.use((Z)=>Z.delete(G).where(c(K(G.source,N),K(G.source_key,H.source_key))).run()),{existing:void 0,existingUpdated:void 0};return{existing:_,existingUpdated:O.updated}}function J_(N,_,H,O){N.insert(r).values({id:_.id,worktree:_.worktree,vcs:_.vcs,sandboxes:[],time_created:H,time_updated:O}).onConflictDoNothing().run()}function K_(N,_,H){if(_.message_ids?.length)for(let O=0;O<_.message_ids.length;O+=500)N.delete(k).where(i(k.id,_.message_ids.slice(O,O+500))).run();else N.delete(k).where(K(k.session_id,H)).run()}function A_(N,_,H){N.update(C).set({project_id:H.projectId,directory:H.directory,version:H.version,time_updated:Math.max(H.existingUpdated??0,H.timeUpdated)}).where(K(C.id,_)).run()}function $_(N){return async(_)=>F_({...N,force:_?.force})}async function F_(N){let _=Z_();if(!await X_(N.root).then(()=>!0).catch(()=>!1))return _;let H=await d.scan(N.pattern,{cwd:N.root,absolute:!0});for(let O of H){_.scanned++;try{let Z=W_.basename(O,".jsonl"),A=await g.statAsync(O);if(!A){_.skipped++;continue}let F=Math.floor(Number(A.mtimeMs)),Y=R_(N.source,Z);if(Y&&Y.source_mtime===F&&!N.force){_.skipped++;continue}let S=G_(N.source,Y);Y=S.existing;let T=S.existingUpdated,Q=Y?Y.session_id:e.descending(),V=N.parse(await Y_(O,"utf-8"),Q);if(!V||V.messages.length===0){_.skipped++;continue}let E=await L_(V.cwd),U=Date.now(),X=V.messages.map(($)=>$.info.id);if(D.transaction(($)=>{if(J_($,E,V.timeCreated,V.timeUpdated),Y)K_($,Y,Q),A_($,Q,{projectId:E.id,directory:V.cwd,version:V.version,existingUpdated:T,timeUpdated:V.timeUpdated});else $.insert(C).values({id:Q,project_id:E.id,slug:s.create(),directory:V.cwd,title:V.title,version:V.version,time_created:V.timeCreated,time_updated:V.timeUpdated}).run();for(let L of V.messages){let{id:B,sessionID:I,agentID:w,...z}=L.info;$.insert(k).values({id:B,session_id:Q,agent_id:"main",time_created:L.info.time.created,data:z}).onConflictDoUpdate({target:k.id,set:{data:z}}).run();for(let J of L.parts){let{id:y,sessionID:p,messageID:P,...h}=J.part;$.insert(m).values({id:y,message_id:L.info.id,session_id:Q,time_created:J.time,data:h}).onConflictDoUpdate({target:m.id,set:{data:h}}).run()}}$.insert(G).values({source:N.source,source_key:Z,session_id:Q,source_path:O,source_mtime:F,time_imported:U,message_ids:X}).onConflictDoUpdate({target:[G.source,G.source_key],set:{session_id:Q,source_path:O,source_mtime:F,time_imported:U,message_ids:X}}).run()}),Y)_.resynced++;else _.imported++}catch(Z){_.errors.push(`${O}: ${Z}`)}}if(_.imported+_.resynced>0||_.errors.length>0)N.log.info(N.logMessage,{..._,errors:_.errors.length});return _}var B_=Q_.create({service:"claude-import"});function k_(N){return N.replace(/[^a-zA-Z0-9]/g,"-")}function z_(N){if(!N)return{providerID:u.anthropic,modelID:f.make("unknown")};let _=N.indexOf("/");if(_===-1)return{providerID:u.anthropic,modelID:f.make(N)};return{providerID:u.make(N.slice(0,_)),modelID:f.make(N.slice(_+1))}}function H_(N){let _=N??{};return{input:_.input_tokens??0,output:_.output_tokens??0,reasoning:0,cache:{read:_.cache_read_input_tokens??0,write:_.cache_creation_input_tokens??0}}}function C_(N){if(typeof N==="string")return N;if(Array.isArray(N))return N.map((_)=>_&&typeof _==="object"&&("type"in _)&&_.type==="text"?_.text:JSON.stringify(_)).join(`
|
|
4
4
|
`);return N==null?"":JSON.stringify(N)}function U_(N,_){let H=__(N);if(H.length===0)return;let O,Z,A,F=0,Y,S=[],T=new Map,Q=null,V=null,E=z_(void 0),U=()=>{if(Q)S.push(Q);Q=null};for(let X of H){if(X.type!=="user"&&X.type!=="assistant")continue;let $=X.timestamp?Date.parse(X.timestamp):Date.now();if(!O&&X.cwd)O=X.cwd;if(!Z&&X.version)Z=X.version;if(A===void 0)A=$;F=Math.max(F,$);let L=X.message;if(!L)continue;if(X.type==="user"){let z=L.content,J=typeof z==="string"?[]:Array.isArray(z)?z:[];for(let W of J.filter((R)=>R?.type==="tool_result")){let R=T.get(W.tool_use_id);if(!R)continue;let M=C_(W.content);R.part.state=W.is_error?{status:"error",input:R.part.state.input??{},error:M,time:{start:R.start,end:$}}:{status:"completed",input:R.part.state.input??{},output:M,title:R.part.tool,metadata:{},time:{start:R.start,end:$}}}let y=typeof z==="string"?z.trim()?[z]:[]:J.filter((W)=>W?.type==="text"&&typeof W.text==="string"&&W.text.trim()).map((W)=>W.text),p=J.filter((W)=>W?.type==="image"&&W.source);if(y.length===0&&p.length===0)continue;U();let P=j.ascending(),h=[];for(let W of y)h.push({part:{id:v.ascending(),sessionID:_,messageID:P,type:"text",text:W},time:$});for(let W of p){let R=W.source.media_type??"image/png",M=W.source.type==="base64"?`data:${R};base64,${W.source.data}`:W.source.url??"";if(M)h.push({part:{id:v.ascending(),sessionID:_,messageID:P,type:"file",mime:R,url:M},time:$})}let V_={id:P,sessionID:_,role:"user",agent:"main",time:{created:$},model:{providerID:E.providerID,modelID:E.modelID}};if(S.push({info:V_,parts:h}),V=P,!Y)Y=N_(y);continue}let B=z_(L.model);if(E=B,!V){let z=j.ascending();S.push({info:{id:z,sessionID:_,role:"user",agent:"main",time:{created:$},model:{providerID:B.providerID,modelID:B.modelID}},parts:[]}),V=z}if(!Q||Q.info.role!=="assistant"||Q.info.parentID!==V)U(),Q={info:{id:j.ascending(),sessionID:_,role:"assistant",time:{created:$,completed:$},parentID:V,modelID:B.modelID,providerID:B.providerID,mode:"build",agent:"main",path:{cwd:O??X.cwd??"",root:O??X.cwd??""},cost:0,tokens:H_(L.usage)},parts:[]};let I=Q.info;I.time.completed=$,I.tokens=H_(L.usage);let w=Q.info.id;for(let z of Array.isArray(L.content)?L.content:[])if(z?.type==="thinking"||z?.type==="reasoning")Q.parts.push({part:{id:v.ascending(),sessionID:_,messageID:w,type:"reasoning",text:z.thinking??z.text??"",time:{start:$,end:$}},time:$});else if(z?.type==="text"&&typeof z.text==="string")Q.parts.push({part:{id:v.ascending(),sessionID:_,messageID:w,type:"text",text:z.text},time:$});else if(z?.type==="tool_use"){let J={id:v.ascending(),sessionID:_,messageID:w,type:"tool",callID:z.id,tool:z.name,state:{status:"pending",input:z.input??{},raw:JSON.stringify(z.input??{})}};Q.parts.push({part:J,time:$}),T.set(z.id,{part:J,start:$})}}return U(),{cwd:O??"",version:Z??"claude-code",title:Y??"Claude Code session",timeCreated:A??Date.now(),timeUpdated:F||A||Date.now(),messages:S}}var h_=$_({source:"cc",root:E_.join(O_.Path.home,".claude","projects"),pattern:"*/*.jsonl",log:B_,logMessage:"claude import",parse:U_});
|
|
5
5
|
export{G as kg,Z_ as lg,L_ as mg,__ as ng,N_ as og,R_ as pg,G_ as qg,J_ as rg,K_ as sg,A_ as tg,$_ as ug,k_ as vg,h_ as wg,l as xg};
|