@kabmo-labs/kabmo 0.30.0 → 0.30.1

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.
@@ -65,7 +65,7 @@
65
65
  by `scripts/build-client.ts`. A page that ships an external font must
66
66
  name it somewhere; this one did not. -->
67
67
  <!--app-head-->
68
- <link rel="stylesheet" crossorigin href="./static/js/index-naa91727.css"><script type="module" crossorigin src="./static/js/index-5vjbp04s.js"></script></head>
68
+ <link rel="stylesheet" crossorigin href="./static/js/index-naa91727.css"><script type="module" crossorigin src="./static/js/index-bwhhehnh.js"></script></head>
69
69
  <body>
70
70
  <div id="app"></div>
71
71
  <!--app-bootstrap-->
@@ -663,7 +663,7 @@ return u.substring(s,qi)
663
663
  `:`c.headers={}
664
664
  for(const [k,v] of c.request.headers.entries())c.headers[k]=v
665
665
  `},listen(e){return(t,r)=>{if(typeof Bun>"u")throw Error(".listen() is designed to run on Bun only. If you are running Elysia in other environment please use a dedicated plugin or export the handler via Elysia.fetch");if(e.compile(),typeof t=="string"){if(!$b(t))throw Error("Port must be a numeric value");t=parseInt(t)}let n=(s,{withAsync:a=!1}={})=>{let c={},l=[];if(e.event.request?.length||e.event.trace?.length||e.extender.higherOrderFunctions.length)return a?Promise.resolve(c):c;for(let[u,d]of Object.entries(s))if(u=encodeURI(u),qb){if(!d)continue;for(let[f,p]of Object.entries(d))if(!(!p||!(f in C6))){if(p instanceof Promise){a&&(c[u]||(c[u]={}),l.push(p.then((h)=>{h instanceof Response&&(c[u][f]=h),Ug(h)&&(c[u][f]=h)})));continue}!(p instanceof Response)&&!Ug(p)||(c[u]||(c[u]={}),c[u][f]=p)}}else{if(!d)continue;if(d instanceof Promise){a&&(c[u]||(c[u]={}),l.push(d.then((f)=>{f instanceof Response&&(c[u]=f)})));continue}if(!(d instanceof Response))continue;c[u]=d}return a?Promise.all(l).then(()=>c):c},o=P6(Rw(Rw(n(e.router.response),R6(e)),e.config.serve?.routes)),i=typeof t=="object"?{development:!qs,reusePort:!0,idleTimeout:30,...e.config.serve||{},...t||{},routes:o,websocket:{...e.config.websocket||{},...xE||{},...t.websocket||{}},fetch:e.fetch}:{development:!qs,reusePort:!0,idleTimeout:30,...e.config.serve||{},routes:o,websocket:{...e.config.websocket||{},...xE||{}},port:t,fetch:e.fetch};if(e.server=Bun.serve(i),e.event.start)for(let s=0;s<e.event.start.length;s++)e.event.start[s].fn(e);r&&r(e.server),process.on("beforeExit",async()=>{if(e.server&&(await e.server.stop?.(),e.server=null,e.event.stop))for(let s=0;s<e.event.stop.length;s++)e.event.stop[s].fn(e)}),e.promisedModules.then(async()=>{e.config.aot,e.compile();let s=P6(Rw(Rw(await n(e.router.response,{withAsync:!0}),R6(e)),e.config.serve?.routes));e.server?.reload({...i,fetch:e.fetch,routes:s}),Bun?.gc(!1)})}},async stop(e,t){if(e.server){if(await e.server.stop(t),e.server=null,e.event.stop?.length)for(let r=0;r<e.event.stop.length;r++)e.event.stop[r].fn(e)}else console.log("Elysia isn't running. Call `app.listen` to start the server.",Error().stack)},ws(e,t,r){let{parse:n,body:o,response:i,...s}=r,a=Ut(o,{modules:e.definitions.typebox,models:e.definitions.type,normalize:e.config.normalize}),c=a?a.provider==="standard"?(u)=>a.schema["~standard"].validate(u).issues:(u)=>a.Check(u)===!1:void 0,l=Ut(i,{modules:e.definitions.typebox,models:e.definitions.type,normalize:e.config.normalize});e.route("WS",t,async(u)=>{let d=u.server??e.server,{set:f,path:p,qi:h,headers:g,query:y,params:b}=u;if(u.validator=l,r.upgrade)if(typeof r.upgrade=="function"){let R=r.upgrade(u);R instanceof Promise&&await R}else r.upgrade&&Object.assign(f.headers,r.upgrade);if(f.cookie&&Fe(f.cookie)){let R=Rg(f.cookie);R&&(f.headers["set-cookie"]=R)}f.headers["set-cookie"]&&Array.isArray(f.headers["set-cookie"])&&(f.headers=cE(new Headers(f.headers),f.headers["set-cookie"]));let w=E6(l),E=T6(n),S;if(typeof r.beforeHandle=="function"){let R=r.beforeHandle(u);R instanceof Promise&&await R}let A=[...r.error?Array.isArray(r.error)?r.error:[r.error]:[],...(e.event.error??[]).map((R)=>typeof R=="function"?R:R.fn)].filter((R)=>R),T=A.length>0,I=T?async(R,F)=>{for(let U of A){let P=U(Object.assign(u,{error:F}));if(P instanceof Promise&&(P=await P),await w(R,P),P)break}}:()=>{};if(!d?.upgrade(u.request,{headers:Fe(f.headers)?f.headers:void 0,data:{...u,get id(){return S||(S=$s())},validator:l,ping(R,F){r.ping?.(R,F)},pong(R,F){r.pong?.(R,F)},open:async(R)=>{try{await w(R,r.open?.(new bp(R,u)))}catch(F){I(R,F)}},message:async(R,F)=>{let U=await E(R,F);if(c&&c(U)){let P=new le("message",a,U);return T?I(R,P):void R.send(P.message)}try{await w(R,r.message?.(new bp(R,u,U),U))}catch(P){I(R,P)}},drain:async(R)=>{try{await w(R,r.drain?.(new bp(R,u)))}catch(F){I(R,F)}},close:async(R,F,U)=>{try{await w(R,r.close?.(new bp(R,u),F,U))}catch(P){I(R,P)}}}}))return Xi(400,"Expected a websocket connection")},{...s,websocket:r})}};var Pw=uo?Bun.env:typeof process<"u"&&process?.env?process.env:{};var D6=/^(.+)\[(\d+)\]$/,M6=new Set(["__proto__","constructor","prototype"]),N6=(e)=>{if(M6.has(e))return!0;let t=e.match(D6);return t?M6.has(t[1]):!1},L6=(e)=>{let t=e.match(D6);return t?{name:t[1],index:parseInt(t[2],10)}:null},R0e=(e)=>{if(!(typeof e!="string"||e.charCodeAt(0)!==123))try{let t=JSON.parse(e);if(t&&typeof t=="object"&&!Array.isArray(t))return t}catch{return}},kE=(e,t,r)=>{let n=t.split("."),o=n.pop();if(N6(o)||n.some(N6))return;let i=e;for(let a of n){let c=L6(a);if(c){Array.isArray(i[c.name])||(i[c.name]=[]);let l=i[c.name][c.index],u=typeof File<"u"&&l instanceof File;(!l||typeof l!="object"||Array.isArray(l)||u)&&(i[c.name][c.index]=R0e(l)??{}),i=i[c.name][c.index]}else(!i[a]||typeof i[a]!="object")&&(i[a]={}),i=i[a]}let s=L6(o);s?(Array.isArray(i[s.name])||(i[s.name]=[]),i[s.name][s.index]=r):i[o]=r},vE=(e)=>{if(e.length===1){let o=e[0];if(typeof o=="string"&&(o.charCodeAt(0)===123||o.charCodeAt(0)===91))try{let i=JSON.parse(o);if(i&&typeof i=="object")return i}catch{}return e[0]}let t=e.find((o)=>typeof o=="string");if(!t||typeof File>"u")return e;let r=e.filter((o)=>o instanceof File);if(!r.length||t.charCodeAt(0)!==123)return e;let n;try{n=JSON.parse(t)}catch{return e}return typeof n!="object"||n===null?e:(!("file"in n)&&r.length===1?n.file=r[0]:!("files"in n)&&r.length>1&&(n.files=r),n)},AE=(e,t)=>{let r=e.schema;if(!r)return;r.$defs?.[r.$ref]&&(r=r.$defs[r.$ref]);let n=es(r);if(n)for(let[o,i]of Object.entries(n))t[o]??=i.default};async function eu(e,t,r){let n=await t.Validate(r);if(n.issues)throw new le(e,t,r,!1,n.issues);return n.value}var TE=(e)=>{let{mapResponse:t,mapEarlyResponse:r}=e["~adapter"].handler,n=e.setHeaders;return async(o)=>{let i=o.url,s=i.indexOf("/",11),a=i.indexOf("?",s+1),c=a===-1?i.substring(s):i.substring(s,a),l={cookie:{},status:200,headers:n?{...n}:{}},u=Object.assign({},e.singleton.decorator,{set:l,store:e.singleton.store,request:o,path:c,qi:a,error:Xi,status:Xi,redirect:Fl}),d;try{if(e.event.request)for(let F=0;F<e.event.request.length;F++){let U=e.event.request[F].fn,P=U(u);if(P instanceof Promise&&(P=await P),P=r(P,l),P)return u.response=P}let f=o.method==="GET"&&o.headers.get("upgrade")?.toLowerCase()==="websocket"?"WS":o.method,p=e.router.dynamic.find(o.method,c)??e.router.dynamic.find(f,c)??e.router.dynamic.find("ALL",c);if(!p)throw u.query=a===-1?{}:Xa(i.substring(a+1)),new np;let{handle:h,validator:g,content:y,route:b}=p.store;if(d=p.store.hooks,d.config?.mount)return await d.config.mount(o);let w;if(o.method!=="GET"&&o.method!=="HEAD")if(y)switch(y){case"application/json":w=await o.json();break;case"text/plain":w=await o.text();break;case"application/x-www-form-urlencoded":w=Xa(await o.text());break;case"application/octet-stream":w=await o.arrayBuffer();break;case"multipart/form-data":{w={};let F=await o.formData(),U=new Map;F.forEach((P,B)=>{let D=U.get(B);D?D.push(P):U.set(B,[P])});for(let[P,B]of U){if(w[P])continue;let D=vE(B);P.includes(".")||P.includes("[")?kE(w,P,D):w[P]=D}break}}else{let F;if(o.body&&(F=o.headers.get("content-type")),F){let U=F.indexOf(";");if(U!==-1&&(F=F.slice(0,U)),u.contentType=F,d.parse)for(let P=0;P<d.parse.length;P++){let B=d.parse[P].fn;if(typeof B=="string")switch(B){case"json":case"application/json":w=await o.json();break;case"text":case"text/plain":w=await o.text();break;case"urlencoded":case"application/x-www-form-urlencoded":w=Xa(await o.text());break;case"arrayBuffer":case"application/octet-stream":w=await o.arrayBuffer();break;case"formdata":case"multipart/form-data":{w={};let D=await o.formData(),J=new Map;D.forEach((Z,ie)=>{let oe=J.get(ie);oe?oe.push(Z):J.set(ie,[Z])});for(let[Z,ie]of J){if(w[Z])continue;let oe=vE(ie);Z.includes(".")||Z.includes("[")?kE(w,Z,oe):w[Z]=oe}break}default:{let D=e["~parser"][B];if(D){let J=D(u,F);if(J instanceof Promise&&(J=await J),J){w=J;break}}break}}else{let D=B(u,F);if(D instanceof Promise&&(D=await D),D){w=D;break}}}if(delete u.contentType,w===void 0)switch(F){case"application/json":w=await o.json();break;case"text/plain":w=await o.text();break;case"application/x-www-form-urlencoded":w=Xa(await o.text());break;case"application/octet-stream":w=await o.arrayBuffer();break;case"multipart/form-data":{w={};let P=await o.formData(),B=new Map;P.forEach((D,J)=>{let Z=B.get(J);Z?Z.push(D):B.set(J,[D])});for(let[D,J]of B){if(w[D])continue;let Z=vE(J);D.includes(".")||D.includes("[")?kE(w,D,Z):w[D]=Z}break}}}}u.route=b,u.body=w,u.params=p?.params||void 0,u.query=a===-1?{}:Xa(i.substring(a+1)),u.headers={};for(let[F,U]of o.headers.entries())u.headers[F]=U;let E={domain:e.config.cookie?.domain??g?.cookie?.config.domain,expires:e.config.cookie?.expires??g?.cookie?.config.expires,httpOnly:e.config.cookie?.httpOnly??g?.cookie?.config.httpOnly,maxAge:e.config.cookie?.maxAge??g?.cookie?.config.maxAge,path:e.config.cookie?.path??g?.cookie?.config.path,priority:e.config.cookie?.priority??g?.cookie?.config.priority,partitioned:e.config.cookie?.partitioned??g?.cookie?.config.partitioned,sameSite:e.config.cookie?.sameSite??g?.cookie?.config.sameSite,secure:e.config.cookie?.secure??g?.cookie?.config.secure,secrets:e.config.cookie?.secrets??g?.cookie?.config.secrets,sign:e.config.cookie?.sign??g?.cookie?.config.sign},S=o.headers.get("cookie");u.cookie=await fw(u.set,S,E);let A=g?.createHeaders?.();A&&AE(A,u.headers);let T=g?.createParams?.();T&&AE(T,u.params);let I=g?.createQuery?.();if(I&&AE(I,u.query),d.transform)for(let F=0;F<d.transform.length;F++){let U=d.transform[F],P=U.fn(u);if(P instanceof Promise&&(P=await P),P instanceof Dt){let B=r(P,u.set);if(B)return u.response=B}U.subType==="derive"&&Object.assign(u,P)}if(g){if(A){let U=structuredClone(u.headers);for(let[P,B]of o.headers)U[P]=B;if(A.provider==="standard")u.headers=await eu("header",A,U);else if(g.headers.Check(U)===!1)throw new le("header",g.headers,U)}else g.headers?.Decode&&(u.headers=g.headers.Decode(u.headers));if(T?.provider==="standard")u.params=await eu("params",T,u.params);else{if(T?.Check(u.params)===!1)throw new le("params",g.params,u.params);g.params?.Decode&&(u.params=g.params.Decode(u.params))}if(g.query?.schema){let U=g.query.schema;U.$defs?.[U.$ref]&&(U=U.$defs[U.$ref]);let P=es(U);if(P)for(let B of Object.keys(P)){let D=P[B];(D.type==="array"||D.items?.type==="string")&&typeof u.query[B]=="string"&&u.query[B]&&(u.query[B]=u.query[B].split(","))}}if(I?.provider==="standard")u.query=await eu("query",I,u.query);else{if(I?.Check(u.query)===!1)throw new le("query",g.query,u.query);g.query?.Decode&&(u.query=g.query.Decode(u.query))}if(g.createCookie?.()){let U={};for(let[P,B]of Object.entries(u.cookie))U[P]=B.value;if(g.cookie.provider==="standard"){U=await eu("cookie",g.cookie,U);for(let P of Object.keys(U))u.cookie[P].value=U[P]}else{if(g.cookie.Check(U)===!1)throw new le("cookie",g.cookie,U);g.cookie?.Decode&&(U=g.cookie.Decode(U))}}let F=g.createBody?.();if(F?.provider==="standard")u.body=await eu("body",F,w);else{if(F?.Check(w)===!1)throw new le("body",g.body,w);if(g.body?.Decode){let U=g.body.Decode(w);U instanceof Promise&&(U=await U),u.body=U?.value??U}}}if(d.beforeHandle)for(let F=0;F<d.beforeHandle.length;F++){let U=d.beforeHandle[F],P=U.fn(u);if(P instanceof Promise&&(P=await P),P instanceof Dt){let B=r(P,u.set);if(B)return u.response=B}if(U.subType==="resolve"){Object.assign(u,P);continue}if(P!==void 0){if(u.response=P,d.afterHandle)for(let D=0;D<d.afterHandle.length;D++){let J=d.afterHandle[D].fn(u);J instanceof Promise&&(J=await J),J&&(P=J)}let B=r(P,u.set);if(B)return u.response=B}}let R=typeof h=="function"?h(u):h;if(R instanceof Promise&&(R=await R),d.afterHandle?.length){u.response=R;for(let F=0;F<d.afterHandle.length;F++){let U=d.afterHandle[F].fn(u);U instanceof Promise&&(U=await U);let P=U instanceof Dt,B=P?U.code:l.status?typeof l.status=="string"?Ji[l.status]:l.status:200;P&&(l.status=B,U=U.response);let D=g?.createResponse?.()?.[B];if(D?.provider==="standard")U=await eu("response",D,U);else if(D?.Check(U)===!1)if(D?.Clean)try{let Z=D.Clean(U);if(D?.Check(Z)===!1)throw new le("response",D,U);U=Z}catch(Z){throw Z instanceof le?Z:new le("response",D,U)}else throw new le("response",D,U);if(D?.Encode&&(u.response=U=D.Encode(U)),D?.Clean)try{u.response=U=D.Clean(U)}catch{}let J=r(U,u.set);if(J!==void 0)return u.response=J}}else{let F=R instanceof Dt,U=F?R.code:l.status?typeof l.status=="string"?Ji[l.status]:l.status:200;F&&(l.status=U,R=R.response);let P=g?.createResponse?.()?.[U];if(P?.provider==="standard")R=await eu("response",P,R);else if(P?.Check(R)===!1)if(P?.Clean)try{let B=P.Clean(R);if(P?.Check(B)===!1)throw new le("response",P,R);R=B}catch(B){throw B instanceof le?B:new le("response",P,R)}else throw new le("response",P,R);if(P?.Encode&&(R=P.Encode(R)),P?.Clean)try{R=P.Clean(R)}catch{}}if(u.set.cookie&&E?.sign){let F=E.secrets?typeof E.secrets=="string"?E.secrets:E.secrets[0]:void 0;if(E.sign===!0){if(F)for(let[U,P]of Object.entries(u.set.cookie))u.set.cookie[U].value=await tp(P.value,F)}else{let U=es(g?.cookie?.schema);if(F)for(let P of E.sign)!U||!(P in U)||u.set.cookie[P]?.value&&(u.set.cookie[P].value=await tp(u.set.cookie[P].value,F))}}return t(u.response=R,u.set)}catch(f){let p=f instanceof Nl&&f.error?f.error:f;return e.handleError(u,p)}finally{let f=d?d.afterResponse:e.event.afterResponse;f&&(Hb?setImmediate(async()=>{for(let p of f)await p.fn(u)}):Promise.resolve().then(async()=>{for(let p of f)await p.fn(u)}))}}},F6=(e)=>{let{mapResponse:t}=e["~adapter"].handler;return async(r,n)=>{let o=Object.assign(r,{error:n,code:n.code});if(o.set=r.set,typeof n?.toResponse=="function"&&!(n instanceof le)&&!(n instanceof Nl))try{let i=n.toResponse();typeof i?.then=="function"&&(i=await i),i instanceof Response&&(r.set.status=i.status),r.response=i}catch{}if(!r.response&&e.event.error)for(let i=0;i<e.event.error.length;i++){let s=e.event.error[i].fn(o);if(s instanceof Promise&&(s=await s),s!=null)return r.response=t(s,r.set)}if(r.response){if(e.event.mapResponse)for(let i=0;i<e.event.mapResponse.length;i++){let s=e.event.mapResponse[i].fn(o);s instanceof Promise&&(s=await s),s!=null&&(r.response=s)}return t(r.response,r.set)}return r.set.status=n.status??500,t(typeof n.cause=="string"?n.cause:n.message,r.set)}};var U6;U6=Symbol.dispose;var P0e=class e{constructor(t={}){this.server=null,this.dependencies={},this["~Prefix"]="",this["~Singleton"]=null,this["~Definitions"]=null,this["~Metadata"]=null,this["~Ephemeral"]=null,this["~Volatile"]=null,this["~Routes"]=null,this.singleton={decorator:{},store:{},derive:{},resolve:{}},this.definitions={typebox:z.Module({}),type:{},error:{}},this.extender={macro:{},higherOrderFunctions:[]},this.validator={global:null,scoped:null,local:null,getCandidate(){return!this.global&&!this.scoped&&!this.local?{body:void 0,headers:void 0,params:void 0,query:void 0,cookie:void 0,response:void 0}:ep(ep(this.global,this.scoped),this.local)}},this.standaloneValidator={global:null,scoped:null,local:null},this.event={},this.router={"~http":void 0,get http(){return this["~http"]||(this["~http"]=new gl({lazy:!0,onParam:EE.default})),this["~http"]},"~dynamic":void 0,get dynamic(){return this["~dynamic"]||(this["~dynamic"]=new gl({onParam:EE.default})),this["~dynamic"]},static:{},response:{},history:[]},this.routeTree={},this.inference={body:!1,cookie:!1,headers:!1,query:!1,set:!1,server:!1,path:!1,route:!1,url:!1},this["~parser"]={},this.handle=async(r)=>this.fetch(r),this.handleError=async(r,n)=>(this.handleError=this.config.aot?SE(this):F6(this))(r,n),this.listen=(r,n)=>(this["~adapter"].listen(this)(r,n),this),this.stop=async(r)=>(await this["~adapter"].stop?.(this,r),this),this[U6]=()=>{this.server&&this.stop()},t.tags&&(t.detail?t.detail.tags=t.tags:t.detail={tags:t.tags}),this.config={aot:Pw.ELYSIA_AOT!=="false",nativeStaticResponse:!0,encodeSchema:!0,normalize:!0,...t,prefix:t.prefix?t.prefix.charCodeAt(0)===47?t.prefix:`/${t.prefix}`:void 0,cookie:{path:"/",...t?.cookie},experimental:t?.experimental??{},seed:t?.seed===void 0?"":t?.seed},this["~adapter"]=t.adapter??(typeof Bun<"u"?O6:Cg),t?.analytic&&(t?.name||t?.seed!==void 0)&&(this.telemetry={stack:Error().stack})}get store(){return this.singleton.store}get decorator(){return this.singleton.decorator}get routes(){return this.router.history}getGlobalRoutes(){return this.router.history}getGlobalDefinitions(){return this.definitions}getServer(){return this.server}getParent(){return null}get promisedModules(){return this._promisedModules||(this._promisedModules=new CT(console.error,()=>{})),this._promisedModules}env(t,r=Pw){if(Ut(t,{modules:this.definitions.typebox,dynamic:!0,additionalProperties:!0,coerce:!0,sanitize:()=>this.config.sanitize}).Check(r)===!1){let n=new le("env",t,r);throw Error(n.all.map((o)=>o.summary).join(`
666
- `))}return this}wrap(t){return this.extender.higherOrderFunctions.push({checksum:Hs(JSON.stringify({name:this.config.name,seed:this.config.seed,content:t.toString()})),fn:t}),this}get models(){let t={};for(let r of Object.keys(this.definitions.type))t[r]=Ut(this.definitions.typebox.Import(r),{models:this.definitions.type});return t.modules=this.definitions.typebox,t}add(t,r,n,o,i){let s=i?.skipPrefix??!1,a=i?.allowMeta??!1;o??={},this.applyMacro(o);let c=[];if(o.standaloneValidator&&(c=c.concat(o.standaloneValidator)),this.standaloneValidator.local&&(c=c.concat(this.standaloneValidator.local)),this.standaloneValidator.scoped&&(c=c.concat(this.standaloneValidator.scoped)),this.standaloneValidator.global&&(c=c.concat(this.standaloneValidator.global)),r!==""&&r.charCodeAt(0)!==47&&(r="/"+r),this.config.prefix&&!s&&(r=this.config.prefix+r),o?.type)switch(o.type){case"text":o.type="text/plain";break;case"json":o.type="application/json";break;case"formdata":o.type="multipart/form-data";break;case"urlencoded":o.type="application/x-www-form-urlencoded";break;case"arrayBuffer":o.type="application/octet-stream";break;default:break}let l=this.validator.getCandidate(),u={body:o?.body??l?.body,headers:o?.headers??l?.headers,params:o?.params??l?.params,query:o?.query??l?.query,cookie:o?.cookie??l?.cookie,response:o?.response??l?.response},d=this.config.precompile===!0||typeof this.config.precompile=="object"&&this.config.precompile.compose===!0,f=()=>{let P=this.definitions.type,B=!this.config.aot,D=this.config.normalize,J=this.definitions.typebox,Z=()=>this.config.sanitize,ie=()=>{if(u.cookie||c.find((oe)=>oe.cookie))return S6({modules:J,validator:u.cookie,defaultConfig:this.config.cookie,normalize:D,config:u.cookie?.config??{},dynamic:B,models:P,validators:c.map((oe)=>oe.cookie),sanitize:Z})};return d?{body:Ut(u.body,{modules:J,dynamic:B,models:P,normalize:D,additionalCoerce:(()=>{let oe=yE(u.body,P,J);return oe&&N in oe&&(Ir("File",oe)||Ir("Files",oe))?gE():Ng()})(),validators:c.map((oe)=>oe.body),sanitize:Z}),headers:Ut(u.headers,{modules:J,dynamic:B,models:P,additionalProperties:!0,coerce:!0,additionalCoerce:Zl(),validators:c.map((oe)=>oe.headers),sanitize:Z}),params:Ut(u.params,{modules:J,dynamic:B,models:P,coerce:!0,additionalCoerce:Zl(),validators:c.map((oe)=>oe.params),sanitize:Z}),query:Ut(u.query,{modules:J,dynamic:B,models:P,normalize:D,coerce:!0,additionalCoerce:fE(),validators:c.map((oe)=>oe.query),sanitize:Z}),cookie:ie(),response:kw(u.response,{modules:J,dynamic:B,models:P,normalize:D,validators:c.map((oe)=>oe.response),sanitize:Z})}:{createBody(){return this.body?this.body:this.body=Ut(u.body,{modules:J,dynamic:B,models:P,normalize:D,additionalCoerce:(()=>{let oe=yE(u.body,P,J);return oe&&N in oe&&(Ir("File",oe)||Ir("Files",oe))?gE():Ng()})(),validators:c.map((oe)=>oe.body),sanitize:Z})},createHeaders(){return this.headers?this.headers:this.headers=Ut(u.headers,{modules:J,dynamic:B,models:P,normalize:D,additionalProperties:!D,coerce:!0,additionalCoerce:Zl(),validators:c.map((oe)=>oe.headers),sanitize:Z})},createParams(){return this.params?this.params:this.params=Ut(u.params,{modules:J,dynamic:B,models:P,normalize:D,coerce:!0,additionalCoerce:Zl(),validators:c.map((oe)=>oe.params),sanitize:Z})},createQuery(){return this.query?this.query:this.query=Ut(u.query,{modules:J,dynamic:B,models:P,normalize:D,coerce:!0,additionalCoerce:fE(),validators:c.map((oe)=>oe.query),sanitize:Z})},createCookie(){return this.cookie?this.cookie:this.cookie=ie()},createResponse(){return this.response?this.response:this.response=kw(u.response,{modules:J,dynamic:B,models:P,normalize:D,validators:c.map((oe)=>oe.response),sanitize:Z})}}};(l.body||l.cookie||l.headers||l.params||l.query||l.response)&&(o=Yi(o,l)),o.tags&&(o.detail?o.detail.tags=o.tags:o.detail={tags:o.tags}),Fe(this.config.detail)&&(o.detail=cr(Object.assign({},this.config.detail),o.detail));let p=Fe(this.event)?Yi(this.event,OT(o)):{...bD(OT(o))};if(c.length&&Object.assign(p,{standaloneValidator:c}),this.config.aot===!1){let P=f();this.router.dynamic.add(t,r,{validator:P,hooks:p,content:o?.type,handle:n,route:r});let B=Bl(r,{dynamic:!0});if(r!==B&&this.router.dynamic.add(t,B,{validator:P,hooks:p,content:o?.type,handle:n,route:r}),!this.config.strictPath){let D=Ul(r);this.router.dynamic.add(t,D,{validator:P,hooks:p,content:o?.type,handle:n,route:r});let J=Bl(D);D!==J&&this.router.dynamic.add(t,D,{validator:P,hooks:p,content:o?.type,handle:n,route:r})}this.router.history.push({method:t,path:r,composed:null,handler:n,compile:void 0,hooks:p});return}let h=this["~adapter"].handler,g=typeof n!="function"?()=>{let P=h.createNativeStaticHandler?.(n,p,{headers:Object.assign({},this.setHeaders)});return P instanceof Promise?P.then((B)=>{if(B)return B}):P?.()}:void 0,y=this.config.nativeStaticResponse===!0,b=(P)=>{!y||!g||(qb?this.router.response[P]?this.router.response[P][t]=g():this.router.response[P]={[t]:g()}:this.router.response[P]=g())};b(r);let w,E=()=>{if(w)return w;let P=k6({app:this,path:r,method:t,hooks:p,validator:f(),handler:typeof n!="function"&&typeof h.createStaticHandler!="function"?()=>n:n,allowMeta:a,inference:this.inference});return this.router.history[A]&&(w=this.router.history[A].composed=P),P},S;if(`${t}_${r}`in this.routeTree)for(let P=0;P<this.router.history.length;P++){let B=this.router.history[P];if(B.path===r&&B.method===t){S=P;break}}else this.routeTree[`${t}_${r}`]=this.router.history.length;let A=S??this.router.history.length,T=this.router.history,I=d?E():(P)=>w?w(P):(T[A].composed=E())(P);S!==void 0?this.router.history[S]=Object.assign({method:t,path:r,composed:I,compile:E,handler:n,hooks:p},c.length?{standaloneValidators:c}:void 0,o.webSocket?{websocket:o.websocket}:void 0):this.router.history.push(Object.assign({method:t,path:r,composed:I,compile:E,handler:n,hooks:p},o.webSocket?{websocket:o.websocket}:void 0));let R={handler:d?T[A].composed:void 0,compile(){return this.handler=E()}},F=this.router.static,U=r.indexOf(":")===-1&&r.indexOf("*")===-1;if(t==="WS"){if(U){r in F?F[r][t]=A:F[r]={[t]:A};return}this.router.http.add("WS",r,R),this.config.strictPath||this.router.http.add("WS",Ul(r),R);let P=Bl(r,{dynamic:!0});r!==P&&this.router.http.add("WS",P,R);return}if(U)r in F?F[r][t]=A:F[r]={[t]:A},this.config.strictPath||b(Ul(r));else{if(this.router.http.add(t,r,R),!this.config.strictPath){let B=Ul(r);b(B),this.router.http.add(t,B,R)}let P=Bl(r,{dynamic:!0});r!==P&&(this.router.http.add(t,P,R),b(P))}}headers(t){return t?(this.setHeaders||(this.setHeaders={}),this.setHeaders=cr(this.setHeaders,t),this):this}onStart(t){return this.on("start",t),this}onRequest(t){return this.on("request",t),this}onParse(t,r){return r?this.on(t,"parse",r):typeof t=="string"?this.on("parse",this["~parser"][t]):this.on("parse",t)}parser(t,r){return this["~parser"][t]=r,this}onTransform(t,r){return r?this.on(t,"transform",r):this.on("transform",t)}resolve(t,r){r||(r=t,t={as:"local"});let n={subType:"resolve",fn:r};return this.onBeforeHandle(t,n)}mapResolve(t,r){r||(r=t,t={as:"local"});let n={subType:"mapResolve",fn:r};return this.onBeforeHandle(t,n)}onBeforeHandle(t,r){return r?this.on(t,"beforeHandle",r):this.on("beforeHandle",t)}onAfterHandle(t,r){return r?this.on(t,"afterHandle",r):this.on("afterHandle",t)}mapResponse(t,r){return r?this.on(t,"mapResponse",r):this.on("mapResponse",t)}onAfterResponse(t,r){return r?this.on(t,"afterResponse",r):this.on("afterResponse",t)}trace(t,r){r||(r=t,t={as:"local"}),Array.isArray(r)||(r=[r]);for(let n of r)this.on(t,"trace",m6(n));return this}error(t,r){switch(typeof t){case"string":return r.prototype[jl]=t,this.definitions.error[t]=r,this;case"function":return this.definitions.error=t(this.definitions.error),this}for(let[n,o]of Object.entries(t))o.prototype[jl]=n,this.definitions.error[n]=o;return this}onError(t,r){return r?this.on(t,"error",r):this.on("error",t)}onStop(t){return this.on("stop",t),this}on(t,r,n){let o;switch(typeof t){case"string":o=t,n=r;break;case"object":o=r,!Array.isArray(r)&&typeof r=="object"&&(n=r);break}Array.isArray(n)?n=ar(n):typeof n=="function"?n=[{fn:n}]:n=[n];let i=n;for(let s of i)s.scope=typeof t=="string"?"local":t?.as??"local",(o==="resolve"||o==="derive")&&(s.subType=o);o!=="trace"&&(this.inference=Yl({[o]:i.map((s)=>s.fn)},this.inference,this.config.sucrose));for(let s of i){let a=wD(s,"global",{skipIfHasType:!0});switch((this.config.name||this.config.seed)&&(a.checksum=Hs(this.config.name+JSON.stringify(this.config.seed))),o){case"start":this.event.start??=[],this.event.start.push(a);break;case"request":this.event.request??=[],this.event.request.push(a);break;case"parse":this.event.parse??=[],this.event.parse.push(a);break;case"transform":this.event.transform??=[],this.event.transform.push(a);break;case"derive":this.event.transform??=[],this.event.transform.push(ar(a,"derive"));break;case"beforeHandle":this.event.beforeHandle??=[],this.event.beforeHandle.push(a);break;case"resolve":this.event.beforeHandle??=[],this.event.beforeHandle.push(ar(a,"resolve"));break;case"afterHandle":this.event.afterHandle??=[],this.event.afterHandle.push(a);break;case"mapResponse":this.event.mapResponse??=[],this.event.mapResponse.push(a);break;case"afterResponse":this.event.afterResponse??=[],this.event.afterResponse.push(a);break;case"trace":this.event.trace??=[],this.event.trace.push(a);break;case"error":this.event.error??=[],this.event.error.push(a);break;case"stop":this.event.stop??=[],this.event.stop.push(a);break}}return this}as(t){return Ks(this.event.parse,t),Ks(this.event.transform,t),Ks(this.event.beforeHandle,t),Ks(this.event.afterHandle,t),Ks(this.event.mapResponse,t),Ks(this.event.afterResponse,t),Ks(this.event.trace,t),Ks(this.event.error,t),t==="scoped"?(this.validator.scoped=ep(this.validator.scoped,this.validator.local),this.validator.local=null,this.standaloneValidator.local!==null&&(this.standaloneValidator.scoped||=[],this.standaloneValidator.scoped.push(...this.standaloneValidator.local),this.standaloneValidator.local=null)):t==="global"&&(this.validator.global=ep(this.validator.global,ep(this.validator.scoped,this.validator.local)),this.validator.scoped=null,this.validator.local=null,this.standaloneValidator.local!==null&&(this.standaloneValidator.scoped||=[],this.standaloneValidator.scoped.push(...this.standaloneValidator.local),this.standaloneValidator.local=null),this.standaloneValidator.scoped!==null&&(this.standaloneValidator.global||=[],this.standaloneValidator.global.push(...this.standaloneValidator.scoped),this.standaloneValidator.scoped=null)),this}group(t,r,n){let o=new e({...this.config,prefix:""});o.singleton={...this.singleton},o.definitions={...this.definitions},o.getServer=()=>this.getServer(),o.inference=Kb(this.inference),o.extender={...this.extender},o["~parser"]=this["~parser"],o.standaloneValidator={local:[...this.standaloneValidator.local??[]],scoped:[...this.standaloneValidator.scoped??[]],global:[...this.standaloneValidator.global??[]]};let i=typeof r=="object",s=(i?n:r)(o);return this.singleton=cr(this.singleton,o.singleton),this.definitions=cr(this.definitions,o.definitions),s.event.request?.length&&(this.event.request=[...this.event.request||[],...s.event.request||[]]),s.event.mapResponse?.length&&(this.event.mapResponse=[...this.event.mapResponse||[],...s.event.mapResponse||[]]),this.model(s.definitions.type),Object.values(o.router.history).forEach(({method:a,path:c,handler:l,hooks:u})=>{if(c=(i?"":this.config.prefix??"")+t+c,i){let{body:d,headers:f,query:p,params:h,cookie:g,response:y,...b}=r,w=u;this.applyMacro(b);let E=d||f||p||h||g||y;this.add(a,c,l,Yi(b,{...w||{},error:w.error?Array.isArray(w.error)?[...w.error??[],...s.event.error??[]]:[w.error,...s.event.error??[]]:s.event.error,standaloneValidator:b.standaloneValidator||w.standaloneValidator||E?[...b.standaloneValidator??[],...w.standaloneValidator??[],...E?[{body:d,headers:f,query:p,params:h,cookie:g,response:y}]:[]]:void 0}),void 0)}else this.add(a,c,l,Yi(u,{error:s.event.error}),{skipPrefix:!0})}),this}guard(t,r){if(!r){if(typeof t=="object"){this.applyMacro(t),t.detail&&(this.config.detail?this.config.detail=cr(Object.assign({},this.config.detail),t.detail):this.config.detail=t.detail),t.tags&&(this.config.detail?this.config.detail.tags=t.tags:this.config.detail={tags:t.tags});let i=t.as??"local";if(t.schema==="standalone"){this.standaloneValidator[i]||(this.standaloneValidator[i]=[]);let s=t?.response?typeof t.response=="string"||N in t.response||"~standard"in t.response?{200:t.response}:t?.response:void 0;this.standaloneValidator[i].push({body:t.body,headers:t.headers,params:t.params,query:t.query,response:s,cookie:t.cookie})}else this.validator[i]={body:t.body??this.validator[i]?.body,headers:t.headers??this.validator[i]?.headers,params:t.params??this.validator[i]?.params,query:t.query??this.validator[i]?.query,response:t.response??this.validator[i]?.response,cookie:t.cookie??this.validator[i]?.cookie};return t.parse&&this.on({as:i},"parse",t.parse),t.transform&&this.on({as:i},"transform",t.transform),t.derive&&this.on({as:i},"derive",t.derive),t.beforeHandle&&this.on({as:i},"beforeHandle",t.beforeHandle),t.resolve&&this.on({as:i},"resolve",t.resolve),t.afterHandle&&this.on({as:i},"afterHandle",t.afterHandle),t.mapResponse&&this.on({as:i},"mapResponse",t.mapResponse),t.afterResponse&&this.on({as:i},"afterResponse",t.afterResponse),t.error&&this.on({as:i},"error",t.error),this}return this.guard({},t)}let n=new e({...this.config,prefix:""});n.singleton={...this.singleton},n.definitions={...this.definitions},n.inference=Kb(this.inference),n.extender={...this.extender},n.getServer=()=>this.getServer();let o=r(n);if(this.singleton=cr(this.singleton,n.singleton),this.definitions=cr(this.definitions,n.definitions),o.getServer=()=>this.server,o.event.request?.length&&(this.event.request=[...this.event.request||[],...o.event.request||[]]),o.event.mapResponse?.length&&(this.event.mapResponse=[...this.event.mapResponse||[],...o.event.mapResponse||[]]),this.model(o.definitions.type),Object.values(n.router.history).forEach(({method:i,path:s,handler:a,hooks:c})=>{let{body:l,headers:u,query:d,params:f,cookie:p,response:h,...g}=t,y=l||u||d||f||p||h;this.add(i,s,a,Yi(g,{...c||{},error:c.error?Array.isArray(c.error)?[...c.error??[],...o.event.error??[]]:[c.error,...o.event.error??[]]:o.event.error,standaloneValidator:y?[...c.standaloneValidator??[],{body:l,headers:u,query:d,params:f,cookie:p,response:h}]:c.standaloneValidator}))}),n.promisedModules.size>0){let i=n.router.history.length;for(let s of n.promisedModules.promises)this.promisedModules.add(s.then(()=>{let{body:a,headers:c,query:l,params:u,cookie:d,response:f,...p}=t,h=a||c||l||u||d||f,g=i;i=n.router.history.length;for(let y=g;y<n.router.history.length;y++){let{method:b,path:w,handler:E,hooks:S}=n.router.history[y];this.add(b,w,E,Yi(p,{...S||{},error:S.error?Array.isArray(S.error)?[...S.error??[],...o.event.error??[]]:[S.error,...o.event.error??[]]:o.event.error,standaloneValidator:h?[...S.standaloneValidator??[],{body:a,headers:c,query:l,params:u,cookie:d,response:f}]:S.standaloneValidator}))}}))}return this}use(t){if(!t)return this;if(Array.isArray(t)){let r=this;for(let n of t)r=r.use(n);return r}return t instanceof Promise?(this.promisedModules.add(t.then((r)=>{if(typeof r=="function")return r(this);if(r instanceof e)return this._use(r).compile();if(r.constructor?.name==="Elysia")return this._use(r).compile();if(typeof r.default=="function")return r.default(this);if(r.default instanceof e)return this._use(r.default);if(r.constructor?.name==="Elysia")return this._use(r.default);if(r.constructor?.name==="_Elysia")return this._use(r.default);try{return this._use(r.default)}catch(n){throw console.error('Invalid plugin type. Expected Elysia instance, function, or module with "default" as Elysia instance or function that returns Elysia instance.'),n}}).then((r)=>(r&&typeof r.compile=="function"&&r.compile(),r))),this):this._use(t)}propagatePromiseModules(t){if(t.promisedModules.size<=0)return this;for(let r of t.promisedModules.promises)this.promisedModules.add(r.then((n)=>{if(!n)return;let o=this._use(n);return o instanceof Promise?o.then((i)=>{i?i.compile():n.compile()}):n.compile()}));return this}_use(t){if(typeof t=="function"){let o=t(this);return o instanceof Promise?(this.promisedModules.add(o.then((i)=>{if(i instanceof e){i.getServer=()=>this.getServer(),i.getGlobalRoutes=()=>this.getGlobalRoutes(),i.getGlobalDefinitions=()=>this.getGlobalDefinitions(),i.model(this.definitions.type),i.error(this.definitions.error);for(let{method:s,path:a,handler:c,hooks:l}of Object.values(i.router.history))this.add(s,a,c,l,void 0);return i===this?void 0:(this.propagatePromiseModules(i),i)}return typeof i=="function"?i(this):typeof i.default=="function"?i.default(this):this._use(i)}).then((i)=>(i&&typeof i.compile=="function"&&i.compile(),i))),this):o}this.propagatePromiseModules(t);let r=t.config.name,n=t.config.seed;if(t.getParent=()=>this,t.getServer=()=>this.getServer(),t.getGlobalRoutes=()=>this.getGlobalRoutes(),t.getGlobalDefinitions=()=>this.getGlobalDefinitions(),t.standaloneValidator?.scoped&&(this.standaloneValidator.local?this.standaloneValidator.local=this.standaloneValidator.local.concat(t.standaloneValidator.scoped):this.standaloneValidator.local=t.standaloneValidator.scoped),t.standaloneValidator?.global&&(this.standaloneValidator.global?this.standaloneValidator.global=this.standaloneValidator.global.concat(t.standaloneValidator.global):this.standaloneValidator.global=t.standaloneValidator.global),Fe(t["~parser"])&&(this["~parser"]={...t["~parser"],...this["~parser"]}),t.setHeaders&&this.headers(t.setHeaders),r){r in this.dependencies||(this.dependencies[r]=[]);let o=n!==void 0?Hs(r+JSON.stringify(n)):0;this.dependencies[r].some(({checksum:i})=>o===i)||(this.extender.macro={...this.extender.macro,...t.extender.macro},this.extender.higherOrderFunctions=this.extender.higherOrderFunctions.concat(t.extender.higherOrderFunctions))}else Fe(t.extender.macro)&&(this.extender.macro={...this.extender.macro,...t.extender.macro}),t.extender.higherOrderFunctions.length&&(this.extender.higherOrderFunctions=this.extender.higherOrderFunctions.concat(t.extender.higherOrderFunctions));if(t.extender.higherOrderFunctions.length){LT(this.extender.higherOrderFunctions);let o=[];for(let i=0;i<this.extender.higherOrderFunctions.length;i++){let s=this.extender.higherOrderFunctions[i];s.checksum&&(o.includes(s.checksum)&&(this.extender.higherOrderFunctions.splice(i,1),i--),o.push(s.checksum))}o.length=0}this.inference=dw(this.inference,t.inference),Fe(t.singleton.decorator)&&this.decorate(t.singleton.decorator),Fe(t.singleton.store)&&this.state(t.singleton.store),Fe(t.definitions.type)&&this.model(t.definitions.type),Fe(t.definitions.error)&&this.error(t.definitions.error),Fe(t.extender.macro)&&(this.extender.macro={...this.extender.macro,...t.extender.macro});for(let{method:o,path:i,handler:s,hooks:a}of Object.values(t.router.history))this.add(o,i,s,a);if(r){r in this.dependencies||(this.dependencies[r]=[]);let o=n!==void 0?Hs(r+JSON.stringify(n)):0;if(this.dependencies[r].some(({checksum:i})=>o===i))return this;this.dependencies[r].push(this.config?.analytic?{name:t.config.name,seed:t.config.seed,checksum:o,dependencies:t.dependencies,stack:t.telemetry?.stack,routes:t.router.history,decorators:t.singleton,store:t.singleton.store,error:t.definitions.error,derive:t.event.transform?.filter((i)=>i?.subType==="derive").map((i)=>({fn:i.toString(),stack:Error().stack??""})),resolve:t.event.transform?.filter((i)=>i?.subType==="resolve").map((i)=>({fn:i.toString(),stack:Error().stack??""}))}:{name:t.config.name,seed:t.config.seed,checksum:o,dependencies:t.dependencies}),Fe(t.event)&&(this.event=RT(this.event,PT(t.event),o))}else Fe(t.event)&&(this.event=RT(this.event,PT(t.event)));return t.validator.global&&(this.validator.global=Yi(this.validator.global,{...t.validator.global})),t.validator.scoped&&(this.validator.local=Yi(this.validator.local,{...t.validator.scoped})),this}macro(t,r){if(typeof t=="string"&&!r)throw Error("Macro function is required");return typeof t=="string"?this.extender.macro[t]=r:this.extender.macro={...this.extender.macro,...t},this}applyMacro(t,r=t,{iteration:n=0,applied:o={}}={}){if(n>=16)return;let i=this.extender.macro;for(let[s,a]of Object.entries(r)){if(!(s in i))continue;let c=typeof i[s]=="function"?i[s](a):i[s];if(!c||typeof i[s]=="object"&&a===!1)return;let l=Hs(s+JSON.stringify(c.seed??a));if(!(l in o)){o[l]=!0;for(let[u,d]of Object.entries(c))if(u!=="seed"){if(u in kD){SD(t,u,d),delete t[s];continue}if(u==="introspect"){d?.(t),delete t[s];continue}if(u==="detail"){t.detail||(t.detail={}),t.detail=cr(t.detail,d,{mergeArray:!0}),delete t[s];continue}if(u in i){this.applyMacro(t,{[u]:d},{applied:o,iteration:n+1}),delete t[s];continue}switch((u==="derive"||u==="resolve")&&typeof d=="function"&&(d={fn:d,subType:u}),typeof t[u]){case"function":t[u]=[t[u],d];break;case"object":Array.isArray(t[u])?t[u].push(d):t[u]=[t[u],d];break;case"undefined":t[u]=d;break}delete t[s]}}}}mount(t,r,n){if(t instanceof e||typeof t=="function"||t.length===0||t==="/"){let a=typeof t=="function"?t:t instanceof e?t.compile().fetch:r instanceof e?r.compile().fetch:typeof r=="function"?r:(()=>{throw Error("Invalid handler")})(),c=({request:l,path:u})=>a(new Request(jb(l.url,u),l));return this.route("ALL","/*",c,{parse:"none",...n,detail:{...n?.detail,hide:!0},config:{mount:a}}),this}let o=r instanceof e?r.compile().fetch:typeof r=="function"?r:(()=>{throw Error("Invalid handler")})(),i=(typeof t=="string"&&this.config.prefix?this.config.prefix+t:t).length-(t.endsWith("*")?1:0),s=({request:a,path:c})=>o(new Request(jb(a.url,c.slice(i)||"/"),a));return this.route("ALL",t,s,{parse:"none",...n,detail:{...n?.detail,hide:!0},config:{mount:o}}),this.route("ALL",t+(t.endsWith("/")?"*":"/*"),s,{parse:"none",...n,detail:{...n?.detail,hide:!0},config:{mount:o}}),this}get(t,r,n){return this.add("GET",t,r,n),this}post(t,r,n){return this.add("POST",t,r,n),this}put(t,r,n){return this.add("PUT",t,r,n),this}patch(t,r,n){return this.add("PATCH",t,r,n),this}delete(t,r,n){return this.add("DELETE",t,r,n),this}options(t,r,n){return this.add("OPTIONS",t,r,n),this}all(t,r,n){return this.add("ALL",t,r,n),this}head(t,r,n){return this.add("HEAD",t,r,n),this}connect(t,r,n){return this.add("CONNECT",t,r,n),this}route(t,r,n,o){return this.add(t.toUpperCase(),r,n,o,o?.config),this}ws(t,r){return this["~adapter"].ws?this["~adapter"].ws(this,t,r):console.warn("Current adapter doesn't support WebSocket"),this}state(t,r,n){r===void 0?(n=t,t={as:"append"},r=""):n===void 0&&(typeof t=="string"?(n=r,r=t,t={as:"append"}):typeof t=="object"&&(n=r,r=""));let{as:o}=t;if(typeof r!="string")return this;switch(typeof n){case"object":return!n||!Fe(n)?this:r?((r in this.singleton.store)?this.singleton.store[r]=cr(this.singleton.store[r],n,{override:o==="override"}):this.singleton.store[r]=n,this):n===null?this:(this.singleton.store=cr(this.singleton.store,n,{override:o==="override"}),this);case"function":return r?(o==="override"||!(r in this.singleton.store))&&(this.singleton.store[r]=n):this.singleton.store=n(this.singleton.store),this;default:return(o==="override"||!(r in this.singleton.store))&&(this.singleton.store[r]=n),this}}decorate(t,r,n){r===void 0?(n=t,t={as:"append"},r=""):n===void 0&&(typeof t=="string"?(n=r,r=t,t={as:"append"}):typeof t=="object"&&(n=r,r=""));let{as:o}=t;if(typeof r!="string")return this;switch(typeof n){case"object":return r?((r in this.singleton.decorator)?this.singleton.decorator[r]=cr(this.singleton.decorator[r],n,{override:o==="override"}):this.singleton.decorator[r]=n,this):n===null?this:(this.singleton.decorator=cr(this.singleton.decorator,n,{override:o==="override"}),this);case"function":return r?(o==="override"||!(r in this.singleton.decorator))&&(this.singleton.decorator[r]=n):this.singleton.decorator=n(this.singleton.decorator),this;default:return(o==="override"||!(r in this.singleton.decorator))&&(this.singleton.decorator[r]=n),this}}derive(t,r){r||(r=t,t={as:"local"});let n={subType:"derive",fn:r};return this.onTransform(t,n)}model(t,r){let n=(o)=>{let i={};for(let s in o)"~standard"in o[s]||(i[s]=o[s]);return i};switch(typeof t){case"object":let o={},i=Object.entries(t);if(!i.length)return this;for(let[c,l]of i)c in this.definitions.type||("~standard"in l?this.definitions.type[c]=l:(o[c]=this.definitions.type[c]=l,o[c].$id??=`#/components/schemas/${c}`));return this.definitions.typebox=z.Module({...this.definitions.typebox.$defs,...o}),this;case"function":let s=t(this.definitions.type);return this.definitions.type=s,this.definitions.typebox=z.Module(n(s)),this;case"string":if(!r)break;if(this.definitions.type[t]=r,"~standard"in r)return this;let a={...r,id:r.$id??`#/components/schemas/${t}`};return this.definitions.typebox=z.Module({...this.definitions.typebox.$defs,...a}),this}return r?(this.definitions.type[t]=r,("~standard"in r)?this:(this.definitions.typebox=z.Module({...this.definitions.typebox.$defs,[t]:r}),this)):this}Ref(t){return z.Ref(t)}mapDerive(t,r){r||(r=t,t={as:"local"});let n={subType:"mapDerive",fn:r};return this.onTransform(t,n)}affix(t,r,n){if(n==="")return this;let o=["_","-"," "],i=(l)=>l[0].toUpperCase()+l.slice(1),s=t==="prefix"?(l,u)=>o.includes(l.at(-1)??"")?l+u:l+i(u):o.includes(n.at(-1)??"")?(l,u)=>u+l:(l,u)=>u+i(l),a=(l)=>{let u={};switch(l){case"decorator":for(let d in this.singleton.decorator)u[s(n,d)]=this.singleton.decorator[d];this.singleton.decorator=u;break;case"state":for(let d in this.singleton.store)u[s(n,d)]=this.singleton.store[d];this.singleton.store=u;break;case"model":for(let d in this.definitions.type)u[s(n,d)]=this.definitions.type[d];this.definitions.type=u;break;case"error":for(let d in this.definitions.error)u[s(n,d)]=this.definitions.error[d];this.definitions.error=u;break}},c=Array.isArray(r)?r:[r];for(let l of c.some((u)=>u==="all")?["decorator","state","model","error"]:c)a(l);return this}prefix(t,r){return this.affix("prefix",t,r)}suffix(t,r){return this.affix("suffix",t,r)}compile(){return this["~adapter"].beforeCompile?.(this),this["~adapter"].isWebStandard?(this._handle=this.config.aot?Tw(this):TE(this),Object.defineProperty(this,"fetch",{value:this._handle,configurable:!0,writable:!0}),typeof this.server?.reload=="function"&&this.server.reload({...this.server||{},fetch:this.fetch}),this):(typeof this.server?.reload=="function"&&this.server.reload(this.server||{}),this._handle=Tw(this),this)}get fetch(){let t=this.config.aot?Tw(this):TE(this);return Object.defineProperty(this,"fetch",{value:t,configurable:!0,writable:!0}),t}get modules(){return this.promisedModules}},Bo=P0e;var Iw={name:"@kabmo-labs/kabmo",version:"0.30.0",description:"Web console and diagnostic workbench for AI coding agents: Elysia + Preact on Bun.",license:"MIT",author:"Wijanarko Putra Rajeb <wijanarko.rajeb@gmail.com>",type:"module",engines:{bun:">=1.4.0"},publishConfig:{access:"public"},bin:{kabmo:"./src/cli/kabmo.js"},repository:{type:"git",url:"git+https://github.com/kabmo-labs/kabmo.git"},homepage:"https://github.com/kabmo-labs/kabmo#readme",bugs:{url:"https://github.com/kabmo-labs/kabmo/issues"},keywords:["kabmo","coding-agent","agent","console","elysia","preact","bun"],files:["src","extensions","index.html","bunfig.toml","public","tsconfig.json","marketplace","dist/client"],scripts:{dev:"bun run --hot src/server/index.ts --kabmo-server","dev:lan":"HOST=0.0.0.0 bun run --hot src/server/index.ts --kabmo-server",build:"bun run scripts/build-client.ts","editor:themes":"bun run scripts/editor-themes.mjs","icons:tints":"bun run scripts/icon-tints.mjs","icons:tints:check":"bun run scripts/icon-tints.mjs --check","editor:themes:check":"bun run scripts/editor-themes.mjs --check","omp:schema":"bun run scripts/omp-schema.mjs","omp:schema:check":"bun run scripts/omp-schema.mjs --check",start:"NODE_ENV=production bun run src/server/index.ts --kabmo-server",typecheck:"tsc",clean:"rm -rf dist",lint:"tsc --noEmit","check:fast":"bun check --no-script",test:"bun test","test:e2e":"playwright test --config tests/e2e/playwright.config.ts","readme:media":"bun run scripts/readme-media.ts","shell:wordmark":"bun run scripts/shell-wordmark.mjs","shell:docs":"bun run scripts/shell-document-types.mjs --write","shell:docs:check":"bun run scripts/shell-document-types.mjs --check","typecheck:e2e":"tsc --noEmit -p tests/e2e","typecheck:consumer":"tsc --noEmit -p tsconfig.consumer.json","publish:plugins":"bash .github/scripts/publish-plugin-packages.sh packages/kabmo-sdk packages/kabmo-ui"},dependencies:{"@codemirror/autocomplete":"6.20.4","@codemirror/commands":"6.11.1","@codemirror/language":"6.13.1","@codemirror/legacy-modes":"^6.5.5","@codemirror/lint":"^6.9.7","@codemirror/merge":"6.12.3","@codemirror/search":"6.7.2","@codemirror/state":"6.7.6","@codemirror/view":"6.43.15","@dskripchenko/drawio":"^0.1.0","@fontsource/fira-code":"^5.3.0","@kabmo-labs/kabmo-sdk":"workspace:*","@kabmo-labs/kabmo-ui":"workspace:*","@shikijs/langs":"^4.4.3","@shikijs/themes":"^4.4.3","@tailwindcss/postcss":"^4.1.14",dompurify:"^3.4.15",elysia:"^1.4.30","ghostty-web":"0.4.0-next.21.g640db46","jsonc-parser":"^3.3.1",katex:"^0.18.7","lucide-preact":"^1.47.0",mammoth:"^1.13.0",marked:"^18.0.11","marked-linkify-it":"^4.0.2",mermaid:"^12.0.0",postcss:"^8.5.16",preact:"^10.29.8",remend:"^1.3.1",ripgrep:"^0.3.1",shiki:"^4.4.3","smol-toml":"^1.9.1",tailwindcss:"^4.1.14",xlsx:"https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",yaml:"^2.9.1"},devDependencies:{"@playwright/test":"^1.64.0","@semantic-release/changelog":"^7.0.0","@semantic-release/commit-analyzer":"^13.0.1","@semantic-release/git":"^11.0.1","@semantic-release/github":"^12.0.10","@semantic-release/npm":"^13.2.0","@semantic-release/release-notes-generator":"^14.1.1","@types/bun":"1.4.4","@types/node":"^22.14.0","bun-types":"1.4.4","conventional-changelog-conventionalcommits":"^9.3.1","happy-dom":"^20.14.5","semantic-release":"^25.0.9",typescript:"~5.8.2"},workspaces:["packages/*"]};var B6=tN("{\"index\":\"./dist/client/index.html\",\"files\":[{\"input\":\"../../index.html\",\"path\":\"./dist/client/static/js/index-5vjbp04s.js\",\"loader\":\"js\",\"isEntry\":true,\"headers\":{\"etag\":\"JXuSy1ZgpDk\",\"content-type\":\"text/javascript;charset=utf-8\"}},{\"input\":\"../../index.html\",\"path\":\"./dist/client/index.html\",\"loader\":\"html\",\"isEntry\":true,\"headers\":{\"etag\":\"N1KVX8uT2Uo\",\"content-type\":\"text/html;charset=utf-8\"}},{\"input\":\"../../index.html\",\"path\":\"./dist/client/static/js/index-naa91727.css\",\"loader\":\"css\",\"isEntry\":true,\"headers\":{\"etag\":\"1eoKiYFHIic\",\"content-type\":\"text/css;charset=utf-8\"}},{\"input\":\"../../public/manifest.webmanifest\",\"path\":\"./dist/client/static/manifest-vdvdqpre.webmanifest\",\"loader\":\"file\",\"isEntry\":false,\"headers\":{\"etag\":\"Wy1bbZc2uM4\",\"content-type\":\"application/manifest+json\"}},{\"input\":\"../../public/icon.svg\",\"path\":\"./dist/client/static/icon-8h6v1jcy.svg\",\"loader\":\"file\",\"isEntry\":false,\"headers\":{\"etag\":\"yFEme-ESbP4\",\"content-type\":\"image/svg+xml\"}},{\"input\":\"../../public/icon-192x192.png\",\"path\":\"./dist/client/static/icon-192x192-kz5bvz85.png\",\"loader\":\"file\",\"isEntry\":false,\"headers\":{\"etag\":\"819lS3sfyKU\",\"content-type\":\"image/png\"}},{\"input\":\"../../public/apple-touch-icon.png\",\"path\":\"./dist/client/static/apple-touch-icon-bbhgf3mq.png\",\"loader\":\"file\",\"isEntry\":false,\"headers\":{\"etag\":\"K8vRUA9jdJc\",\"content-type\":\"image/png\"}}]}");function m(e,t={}){let r=new Headers(t.headers);if(!r.has("content-type"))r.set("content-type","application/json; charset=utf-8");return new Response(JSON.stringify(e),{status:t.status??200,headers:r})}var re={"cache-control":"no-store"};import{brotliCompressSync as O0e,constants as M0e}from"zlib";function fo(e){if(e.buffer instanceof ArrayBuffer)return e;return new Uint8Array(e)}var RE=1024,j6=/^(text\/|application\/(json|javascript|xml|wasm|svg))/,N0e=["zstd","br","gzip"];function H6(e){return j6.test(e)}function PE(e){if(!e)return null;for(let t of N0e)if(e.includes(t))return t;return null}function IE(e,t){if(t==="zstd")return fo(Bun.zstdCompressSync(e,{level:3}));if(t==="br")return fo(O0e(e,{params:{[M0e.BROTLI_PARAM_QUALITY]:4}}));return fo(Bun.gzipSync(e,{level:6}))}async function _a(e,t){if(!t)return e;let r=e.headers.get("content-type")??"";if(r.includes("text/event-stream"))return e;if(!j6.test(r))return e;if(e.status===204||e.status===304)return e;let n=PE(t);if(!n)return e;let o=fo(new Uint8Array(await e.arrayBuffer()));if(o.byteLength<RE)return L0e(e,o);let i=IE(o,n),s=new Headers(e.headers);return s.set("content-encoding",n),s.set("content-length",String(i.byteLength)),s.append("vary","accept-encoding"),new Response(i,{status:e.status,headers:s})}function L0e(e,t){return new Response(t,{status:e.status,headers:e.headers})}function G(e,t,r={}){let n=[];if(e.loader)n.push({method:"GET",path:t,handler:e.loader});else if(e.action)n.push({method:"GET",path:t,handler:V});if(e.action)for(let o of r.mutating??["POST","PUT","PATCH","DELETE"])n.push({method:o,path:t,handler:e.action});return n}var V=()=>tu();function tu(){return new Response(JSON.stringify({error:"Method not allowed"}),{status:405,headers:{"content-type":"application/json; charset=utf-8"}})}async function $t(e){try{return{ok:!0,body:await e.json()}}catch(t){return{ok:!1,error:t instanceof Error?t.message:String(t)}}}function br(e,t){let r=e[t];return r?r:null}function go(e,t=500){return m({error:e instanceof Error?e.message:String(e)},{status:t})}async function D0e(e){if(e instanceof Response)return e;if(e instanceof ReadableStream)return new Response(e,{headers:{"content-type":"text/event-stream","cache-control":"no-cache"}});return new Response(JSON.stringify(e??null),{status:200,headers:{"content-type":"application/json; charset=utf-8"}})}function F0e(e){return async({request:t,params:r})=>{try{let n=await D0e(await e({request:t,params:r}));return await _a(n,t.headers.get("accept-encoding"))}catch(n){let o=n instanceof Error?n.message:String(n);return new Response(JSON.stringify({error:o}),{status:500,headers:{"content-type":"application/json; charset=utf-8"}})}}}function W6(e,t){let r=e;for(let{method:n,path:o,handler:i}of t){let s=F0e(i);if(n==="GET")r=r.get(o,s);else if(n==="POST")r=r.post(o,s);else if(n==="PUT")r=r.put(o,s);else if(n==="PATCH")r=r.patch(o,s);else r=r.delete(o,s)}return r}function nt(e,t,r){return[{method:"GET",path:t,handler:r??V},...["POST","PUT","PATCH","DELETE"].map((n)=>({method:n,path:t,handler:e}))]}import{existsSync as CE,realpathSync as U0e}from"fs";import{homedir as $6,tmpdir as zct}from"os";import*as _t from"path";var K6="omp",B0e=".omp";function q6(){return Bun.env.PI_CONFIG_DIR||B0e}function ho(){return _t.join($6(),q6())}function ce(){let e=Bun.env.PI_CODING_AGENT_DIR;if(e)return _t.resolve(e);return _t.join(ho(),"agent")}function V6(){let e=Bun.env.PI_CODING_AGENT_DIR;if(e)return _t.resolve(e)===_t.join(ho(),"agent");return!0}function j0e(){if(process.platform!=="linux"&&process.platform!=="darwin")return;if(!V6())return;let e=Bun.env.XDG_DATA_HOME;if(!e)return;try{let t=_t.join(e,K6);return CE(t)?t:void 0}catch{return}}function H0e(e){let t=j0e();return _t.join(t??ce(),e)}function jo(){return H0e("sessions")}function G6(){return _t.join(ce(),"projects.json")}function z6(){if(process.platform!=="linux"&&process.platform!=="darwin")return ho();if(!V6())return ho();let e=Bun.env.XDG_DATA_HOME;if(!e)return ho();try{let t=_t.join(e,K6);return CE(t)?t:ho()}catch{return ho()}}function Y6(){return _t.join(z6(),"plugins")}function OE(){return _t.join(z6(),"marketplaces.json")}function J6(e){let t=$6(),r=q6(),n=_t.resolve(e);for(let o of[r,".git"]){let i=n;while(i!==t){if(CE(_t.join(i,o)))return _t.join(i,r,"plugins");let s=_t.dirname(i);if(s===i)break;i=s}}return _t.join(n,r,"plugins")}function ru(e){try{return U0e.native(e)}catch{return e}}async function X(e){try{return await Bun.file(e).stat(),!0}catch{return!1}}function yo(e){let t=ru(e);return t.replace(/\/+$/,"")||t}import NE from"fs";import*as Ow from"path";function x(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Or(e){let t=[];for(let r of e.split(`
666
+ `))}return this}wrap(t){return this.extender.higherOrderFunctions.push({checksum:Hs(JSON.stringify({name:this.config.name,seed:this.config.seed,content:t.toString()})),fn:t}),this}get models(){let t={};for(let r of Object.keys(this.definitions.type))t[r]=Ut(this.definitions.typebox.Import(r),{models:this.definitions.type});return t.modules=this.definitions.typebox,t}add(t,r,n,o,i){let s=i?.skipPrefix??!1,a=i?.allowMeta??!1;o??={},this.applyMacro(o);let c=[];if(o.standaloneValidator&&(c=c.concat(o.standaloneValidator)),this.standaloneValidator.local&&(c=c.concat(this.standaloneValidator.local)),this.standaloneValidator.scoped&&(c=c.concat(this.standaloneValidator.scoped)),this.standaloneValidator.global&&(c=c.concat(this.standaloneValidator.global)),r!==""&&r.charCodeAt(0)!==47&&(r="/"+r),this.config.prefix&&!s&&(r=this.config.prefix+r),o?.type)switch(o.type){case"text":o.type="text/plain";break;case"json":o.type="application/json";break;case"formdata":o.type="multipart/form-data";break;case"urlencoded":o.type="application/x-www-form-urlencoded";break;case"arrayBuffer":o.type="application/octet-stream";break;default:break}let l=this.validator.getCandidate(),u={body:o?.body??l?.body,headers:o?.headers??l?.headers,params:o?.params??l?.params,query:o?.query??l?.query,cookie:o?.cookie??l?.cookie,response:o?.response??l?.response},d=this.config.precompile===!0||typeof this.config.precompile=="object"&&this.config.precompile.compose===!0,f=()=>{let P=this.definitions.type,B=!this.config.aot,D=this.config.normalize,J=this.definitions.typebox,Z=()=>this.config.sanitize,ie=()=>{if(u.cookie||c.find((oe)=>oe.cookie))return S6({modules:J,validator:u.cookie,defaultConfig:this.config.cookie,normalize:D,config:u.cookie?.config??{},dynamic:B,models:P,validators:c.map((oe)=>oe.cookie),sanitize:Z})};return d?{body:Ut(u.body,{modules:J,dynamic:B,models:P,normalize:D,additionalCoerce:(()=>{let oe=yE(u.body,P,J);return oe&&N in oe&&(Ir("File",oe)||Ir("Files",oe))?gE():Ng()})(),validators:c.map((oe)=>oe.body),sanitize:Z}),headers:Ut(u.headers,{modules:J,dynamic:B,models:P,additionalProperties:!0,coerce:!0,additionalCoerce:Zl(),validators:c.map((oe)=>oe.headers),sanitize:Z}),params:Ut(u.params,{modules:J,dynamic:B,models:P,coerce:!0,additionalCoerce:Zl(),validators:c.map((oe)=>oe.params),sanitize:Z}),query:Ut(u.query,{modules:J,dynamic:B,models:P,normalize:D,coerce:!0,additionalCoerce:fE(),validators:c.map((oe)=>oe.query),sanitize:Z}),cookie:ie(),response:kw(u.response,{modules:J,dynamic:B,models:P,normalize:D,validators:c.map((oe)=>oe.response),sanitize:Z})}:{createBody(){return this.body?this.body:this.body=Ut(u.body,{modules:J,dynamic:B,models:P,normalize:D,additionalCoerce:(()=>{let oe=yE(u.body,P,J);return oe&&N in oe&&(Ir("File",oe)||Ir("Files",oe))?gE():Ng()})(),validators:c.map((oe)=>oe.body),sanitize:Z})},createHeaders(){return this.headers?this.headers:this.headers=Ut(u.headers,{modules:J,dynamic:B,models:P,normalize:D,additionalProperties:!D,coerce:!0,additionalCoerce:Zl(),validators:c.map((oe)=>oe.headers),sanitize:Z})},createParams(){return this.params?this.params:this.params=Ut(u.params,{modules:J,dynamic:B,models:P,normalize:D,coerce:!0,additionalCoerce:Zl(),validators:c.map((oe)=>oe.params),sanitize:Z})},createQuery(){return this.query?this.query:this.query=Ut(u.query,{modules:J,dynamic:B,models:P,normalize:D,coerce:!0,additionalCoerce:fE(),validators:c.map((oe)=>oe.query),sanitize:Z})},createCookie(){return this.cookie?this.cookie:this.cookie=ie()},createResponse(){return this.response?this.response:this.response=kw(u.response,{modules:J,dynamic:B,models:P,normalize:D,validators:c.map((oe)=>oe.response),sanitize:Z})}}};(l.body||l.cookie||l.headers||l.params||l.query||l.response)&&(o=Yi(o,l)),o.tags&&(o.detail?o.detail.tags=o.tags:o.detail={tags:o.tags}),Fe(this.config.detail)&&(o.detail=cr(Object.assign({},this.config.detail),o.detail));let p=Fe(this.event)?Yi(this.event,OT(o)):{...bD(OT(o))};if(c.length&&Object.assign(p,{standaloneValidator:c}),this.config.aot===!1){let P=f();this.router.dynamic.add(t,r,{validator:P,hooks:p,content:o?.type,handle:n,route:r});let B=Bl(r,{dynamic:!0});if(r!==B&&this.router.dynamic.add(t,B,{validator:P,hooks:p,content:o?.type,handle:n,route:r}),!this.config.strictPath){let D=Ul(r);this.router.dynamic.add(t,D,{validator:P,hooks:p,content:o?.type,handle:n,route:r});let J=Bl(D);D!==J&&this.router.dynamic.add(t,D,{validator:P,hooks:p,content:o?.type,handle:n,route:r})}this.router.history.push({method:t,path:r,composed:null,handler:n,compile:void 0,hooks:p});return}let h=this["~adapter"].handler,g=typeof n!="function"?()=>{let P=h.createNativeStaticHandler?.(n,p,{headers:Object.assign({},this.setHeaders)});return P instanceof Promise?P.then((B)=>{if(B)return B}):P?.()}:void 0,y=this.config.nativeStaticResponse===!0,b=(P)=>{!y||!g||(qb?this.router.response[P]?this.router.response[P][t]=g():this.router.response[P]={[t]:g()}:this.router.response[P]=g())};b(r);let w,E=()=>{if(w)return w;let P=k6({app:this,path:r,method:t,hooks:p,validator:f(),handler:typeof n!="function"&&typeof h.createStaticHandler!="function"?()=>n:n,allowMeta:a,inference:this.inference});return this.router.history[A]&&(w=this.router.history[A].composed=P),P},S;if(`${t}_${r}`in this.routeTree)for(let P=0;P<this.router.history.length;P++){let B=this.router.history[P];if(B.path===r&&B.method===t){S=P;break}}else this.routeTree[`${t}_${r}`]=this.router.history.length;let A=S??this.router.history.length,T=this.router.history,I=d?E():(P)=>w?w(P):(T[A].composed=E())(P);S!==void 0?this.router.history[S]=Object.assign({method:t,path:r,composed:I,compile:E,handler:n,hooks:p},c.length?{standaloneValidators:c}:void 0,o.webSocket?{websocket:o.websocket}:void 0):this.router.history.push(Object.assign({method:t,path:r,composed:I,compile:E,handler:n,hooks:p},o.webSocket?{websocket:o.websocket}:void 0));let R={handler:d?T[A].composed:void 0,compile(){return this.handler=E()}},F=this.router.static,U=r.indexOf(":")===-1&&r.indexOf("*")===-1;if(t==="WS"){if(U){r in F?F[r][t]=A:F[r]={[t]:A};return}this.router.http.add("WS",r,R),this.config.strictPath||this.router.http.add("WS",Ul(r),R);let P=Bl(r,{dynamic:!0});r!==P&&this.router.http.add("WS",P,R);return}if(U)r in F?F[r][t]=A:F[r]={[t]:A},this.config.strictPath||b(Ul(r));else{if(this.router.http.add(t,r,R),!this.config.strictPath){let B=Ul(r);b(B),this.router.http.add(t,B,R)}let P=Bl(r,{dynamic:!0});r!==P&&(this.router.http.add(t,P,R),b(P))}}headers(t){return t?(this.setHeaders||(this.setHeaders={}),this.setHeaders=cr(this.setHeaders,t),this):this}onStart(t){return this.on("start",t),this}onRequest(t){return this.on("request",t),this}onParse(t,r){return r?this.on(t,"parse",r):typeof t=="string"?this.on("parse",this["~parser"][t]):this.on("parse",t)}parser(t,r){return this["~parser"][t]=r,this}onTransform(t,r){return r?this.on(t,"transform",r):this.on("transform",t)}resolve(t,r){r||(r=t,t={as:"local"});let n={subType:"resolve",fn:r};return this.onBeforeHandle(t,n)}mapResolve(t,r){r||(r=t,t={as:"local"});let n={subType:"mapResolve",fn:r};return this.onBeforeHandle(t,n)}onBeforeHandle(t,r){return r?this.on(t,"beforeHandle",r):this.on("beforeHandle",t)}onAfterHandle(t,r){return r?this.on(t,"afterHandle",r):this.on("afterHandle",t)}mapResponse(t,r){return r?this.on(t,"mapResponse",r):this.on("mapResponse",t)}onAfterResponse(t,r){return r?this.on(t,"afterResponse",r):this.on("afterResponse",t)}trace(t,r){r||(r=t,t={as:"local"}),Array.isArray(r)||(r=[r]);for(let n of r)this.on(t,"trace",m6(n));return this}error(t,r){switch(typeof t){case"string":return r.prototype[jl]=t,this.definitions.error[t]=r,this;case"function":return this.definitions.error=t(this.definitions.error),this}for(let[n,o]of Object.entries(t))o.prototype[jl]=n,this.definitions.error[n]=o;return this}onError(t,r){return r?this.on(t,"error",r):this.on("error",t)}onStop(t){return this.on("stop",t),this}on(t,r,n){let o;switch(typeof t){case"string":o=t,n=r;break;case"object":o=r,!Array.isArray(r)&&typeof r=="object"&&(n=r);break}Array.isArray(n)?n=ar(n):typeof n=="function"?n=[{fn:n}]:n=[n];let i=n;for(let s of i)s.scope=typeof t=="string"?"local":t?.as??"local",(o==="resolve"||o==="derive")&&(s.subType=o);o!=="trace"&&(this.inference=Yl({[o]:i.map((s)=>s.fn)},this.inference,this.config.sucrose));for(let s of i){let a=wD(s,"global",{skipIfHasType:!0});switch((this.config.name||this.config.seed)&&(a.checksum=Hs(this.config.name+JSON.stringify(this.config.seed))),o){case"start":this.event.start??=[],this.event.start.push(a);break;case"request":this.event.request??=[],this.event.request.push(a);break;case"parse":this.event.parse??=[],this.event.parse.push(a);break;case"transform":this.event.transform??=[],this.event.transform.push(a);break;case"derive":this.event.transform??=[],this.event.transform.push(ar(a,"derive"));break;case"beforeHandle":this.event.beforeHandle??=[],this.event.beforeHandle.push(a);break;case"resolve":this.event.beforeHandle??=[],this.event.beforeHandle.push(ar(a,"resolve"));break;case"afterHandle":this.event.afterHandle??=[],this.event.afterHandle.push(a);break;case"mapResponse":this.event.mapResponse??=[],this.event.mapResponse.push(a);break;case"afterResponse":this.event.afterResponse??=[],this.event.afterResponse.push(a);break;case"trace":this.event.trace??=[],this.event.trace.push(a);break;case"error":this.event.error??=[],this.event.error.push(a);break;case"stop":this.event.stop??=[],this.event.stop.push(a);break}}return this}as(t){return Ks(this.event.parse,t),Ks(this.event.transform,t),Ks(this.event.beforeHandle,t),Ks(this.event.afterHandle,t),Ks(this.event.mapResponse,t),Ks(this.event.afterResponse,t),Ks(this.event.trace,t),Ks(this.event.error,t),t==="scoped"?(this.validator.scoped=ep(this.validator.scoped,this.validator.local),this.validator.local=null,this.standaloneValidator.local!==null&&(this.standaloneValidator.scoped||=[],this.standaloneValidator.scoped.push(...this.standaloneValidator.local),this.standaloneValidator.local=null)):t==="global"&&(this.validator.global=ep(this.validator.global,ep(this.validator.scoped,this.validator.local)),this.validator.scoped=null,this.validator.local=null,this.standaloneValidator.local!==null&&(this.standaloneValidator.scoped||=[],this.standaloneValidator.scoped.push(...this.standaloneValidator.local),this.standaloneValidator.local=null),this.standaloneValidator.scoped!==null&&(this.standaloneValidator.global||=[],this.standaloneValidator.global.push(...this.standaloneValidator.scoped),this.standaloneValidator.scoped=null)),this}group(t,r,n){let o=new e({...this.config,prefix:""});o.singleton={...this.singleton},o.definitions={...this.definitions},o.getServer=()=>this.getServer(),o.inference=Kb(this.inference),o.extender={...this.extender},o["~parser"]=this["~parser"],o.standaloneValidator={local:[...this.standaloneValidator.local??[]],scoped:[...this.standaloneValidator.scoped??[]],global:[...this.standaloneValidator.global??[]]};let i=typeof r=="object",s=(i?n:r)(o);return this.singleton=cr(this.singleton,o.singleton),this.definitions=cr(this.definitions,o.definitions),s.event.request?.length&&(this.event.request=[...this.event.request||[],...s.event.request||[]]),s.event.mapResponse?.length&&(this.event.mapResponse=[...this.event.mapResponse||[],...s.event.mapResponse||[]]),this.model(s.definitions.type),Object.values(o.router.history).forEach(({method:a,path:c,handler:l,hooks:u})=>{if(c=(i?"":this.config.prefix??"")+t+c,i){let{body:d,headers:f,query:p,params:h,cookie:g,response:y,...b}=r,w=u;this.applyMacro(b);let E=d||f||p||h||g||y;this.add(a,c,l,Yi(b,{...w||{},error:w.error?Array.isArray(w.error)?[...w.error??[],...s.event.error??[]]:[w.error,...s.event.error??[]]:s.event.error,standaloneValidator:b.standaloneValidator||w.standaloneValidator||E?[...b.standaloneValidator??[],...w.standaloneValidator??[],...E?[{body:d,headers:f,query:p,params:h,cookie:g,response:y}]:[]]:void 0}),void 0)}else this.add(a,c,l,Yi(u,{error:s.event.error}),{skipPrefix:!0})}),this}guard(t,r){if(!r){if(typeof t=="object"){this.applyMacro(t),t.detail&&(this.config.detail?this.config.detail=cr(Object.assign({},this.config.detail),t.detail):this.config.detail=t.detail),t.tags&&(this.config.detail?this.config.detail.tags=t.tags:this.config.detail={tags:t.tags});let i=t.as??"local";if(t.schema==="standalone"){this.standaloneValidator[i]||(this.standaloneValidator[i]=[]);let s=t?.response?typeof t.response=="string"||N in t.response||"~standard"in t.response?{200:t.response}:t?.response:void 0;this.standaloneValidator[i].push({body:t.body,headers:t.headers,params:t.params,query:t.query,response:s,cookie:t.cookie})}else this.validator[i]={body:t.body??this.validator[i]?.body,headers:t.headers??this.validator[i]?.headers,params:t.params??this.validator[i]?.params,query:t.query??this.validator[i]?.query,response:t.response??this.validator[i]?.response,cookie:t.cookie??this.validator[i]?.cookie};return t.parse&&this.on({as:i},"parse",t.parse),t.transform&&this.on({as:i},"transform",t.transform),t.derive&&this.on({as:i},"derive",t.derive),t.beforeHandle&&this.on({as:i},"beforeHandle",t.beforeHandle),t.resolve&&this.on({as:i},"resolve",t.resolve),t.afterHandle&&this.on({as:i},"afterHandle",t.afterHandle),t.mapResponse&&this.on({as:i},"mapResponse",t.mapResponse),t.afterResponse&&this.on({as:i},"afterResponse",t.afterResponse),t.error&&this.on({as:i},"error",t.error),this}return this.guard({},t)}let n=new e({...this.config,prefix:""});n.singleton={...this.singleton},n.definitions={...this.definitions},n.inference=Kb(this.inference),n.extender={...this.extender},n.getServer=()=>this.getServer();let o=r(n);if(this.singleton=cr(this.singleton,n.singleton),this.definitions=cr(this.definitions,n.definitions),o.getServer=()=>this.server,o.event.request?.length&&(this.event.request=[...this.event.request||[],...o.event.request||[]]),o.event.mapResponse?.length&&(this.event.mapResponse=[...this.event.mapResponse||[],...o.event.mapResponse||[]]),this.model(o.definitions.type),Object.values(n.router.history).forEach(({method:i,path:s,handler:a,hooks:c})=>{let{body:l,headers:u,query:d,params:f,cookie:p,response:h,...g}=t,y=l||u||d||f||p||h;this.add(i,s,a,Yi(g,{...c||{},error:c.error?Array.isArray(c.error)?[...c.error??[],...o.event.error??[]]:[c.error,...o.event.error??[]]:o.event.error,standaloneValidator:y?[...c.standaloneValidator??[],{body:l,headers:u,query:d,params:f,cookie:p,response:h}]:c.standaloneValidator}))}),n.promisedModules.size>0){let i=n.router.history.length;for(let s of n.promisedModules.promises)this.promisedModules.add(s.then(()=>{let{body:a,headers:c,query:l,params:u,cookie:d,response:f,...p}=t,h=a||c||l||u||d||f,g=i;i=n.router.history.length;for(let y=g;y<n.router.history.length;y++){let{method:b,path:w,handler:E,hooks:S}=n.router.history[y];this.add(b,w,E,Yi(p,{...S||{},error:S.error?Array.isArray(S.error)?[...S.error??[],...o.event.error??[]]:[S.error,...o.event.error??[]]:o.event.error,standaloneValidator:h?[...S.standaloneValidator??[],{body:a,headers:c,query:l,params:u,cookie:d,response:f}]:S.standaloneValidator}))}}))}return this}use(t){if(!t)return this;if(Array.isArray(t)){let r=this;for(let n of t)r=r.use(n);return r}return t instanceof Promise?(this.promisedModules.add(t.then((r)=>{if(typeof r=="function")return r(this);if(r instanceof e)return this._use(r).compile();if(r.constructor?.name==="Elysia")return this._use(r).compile();if(typeof r.default=="function")return r.default(this);if(r.default instanceof e)return this._use(r.default);if(r.constructor?.name==="Elysia")return this._use(r.default);if(r.constructor?.name==="_Elysia")return this._use(r.default);try{return this._use(r.default)}catch(n){throw console.error('Invalid plugin type. Expected Elysia instance, function, or module with "default" as Elysia instance or function that returns Elysia instance.'),n}}).then((r)=>(r&&typeof r.compile=="function"&&r.compile(),r))),this):this._use(t)}propagatePromiseModules(t){if(t.promisedModules.size<=0)return this;for(let r of t.promisedModules.promises)this.promisedModules.add(r.then((n)=>{if(!n)return;let o=this._use(n);return o instanceof Promise?o.then((i)=>{i?i.compile():n.compile()}):n.compile()}));return this}_use(t){if(typeof t=="function"){let o=t(this);return o instanceof Promise?(this.promisedModules.add(o.then((i)=>{if(i instanceof e){i.getServer=()=>this.getServer(),i.getGlobalRoutes=()=>this.getGlobalRoutes(),i.getGlobalDefinitions=()=>this.getGlobalDefinitions(),i.model(this.definitions.type),i.error(this.definitions.error);for(let{method:s,path:a,handler:c,hooks:l}of Object.values(i.router.history))this.add(s,a,c,l,void 0);return i===this?void 0:(this.propagatePromiseModules(i),i)}return typeof i=="function"?i(this):typeof i.default=="function"?i.default(this):this._use(i)}).then((i)=>(i&&typeof i.compile=="function"&&i.compile(),i))),this):o}this.propagatePromiseModules(t);let r=t.config.name,n=t.config.seed;if(t.getParent=()=>this,t.getServer=()=>this.getServer(),t.getGlobalRoutes=()=>this.getGlobalRoutes(),t.getGlobalDefinitions=()=>this.getGlobalDefinitions(),t.standaloneValidator?.scoped&&(this.standaloneValidator.local?this.standaloneValidator.local=this.standaloneValidator.local.concat(t.standaloneValidator.scoped):this.standaloneValidator.local=t.standaloneValidator.scoped),t.standaloneValidator?.global&&(this.standaloneValidator.global?this.standaloneValidator.global=this.standaloneValidator.global.concat(t.standaloneValidator.global):this.standaloneValidator.global=t.standaloneValidator.global),Fe(t["~parser"])&&(this["~parser"]={...t["~parser"],...this["~parser"]}),t.setHeaders&&this.headers(t.setHeaders),r){r in this.dependencies||(this.dependencies[r]=[]);let o=n!==void 0?Hs(r+JSON.stringify(n)):0;this.dependencies[r].some(({checksum:i})=>o===i)||(this.extender.macro={...this.extender.macro,...t.extender.macro},this.extender.higherOrderFunctions=this.extender.higherOrderFunctions.concat(t.extender.higherOrderFunctions))}else Fe(t.extender.macro)&&(this.extender.macro={...this.extender.macro,...t.extender.macro}),t.extender.higherOrderFunctions.length&&(this.extender.higherOrderFunctions=this.extender.higherOrderFunctions.concat(t.extender.higherOrderFunctions));if(t.extender.higherOrderFunctions.length){LT(this.extender.higherOrderFunctions);let o=[];for(let i=0;i<this.extender.higherOrderFunctions.length;i++){let s=this.extender.higherOrderFunctions[i];s.checksum&&(o.includes(s.checksum)&&(this.extender.higherOrderFunctions.splice(i,1),i--),o.push(s.checksum))}o.length=0}this.inference=dw(this.inference,t.inference),Fe(t.singleton.decorator)&&this.decorate(t.singleton.decorator),Fe(t.singleton.store)&&this.state(t.singleton.store),Fe(t.definitions.type)&&this.model(t.definitions.type),Fe(t.definitions.error)&&this.error(t.definitions.error),Fe(t.extender.macro)&&(this.extender.macro={...this.extender.macro,...t.extender.macro});for(let{method:o,path:i,handler:s,hooks:a}of Object.values(t.router.history))this.add(o,i,s,a);if(r){r in this.dependencies||(this.dependencies[r]=[]);let o=n!==void 0?Hs(r+JSON.stringify(n)):0;if(this.dependencies[r].some(({checksum:i})=>o===i))return this;this.dependencies[r].push(this.config?.analytic?{name:t.config.name,seed:t.config.seed,checksum:o,dependencies:t.dependencies,stack:t.telemetry?.stack,routes:t.router.history,decorators:t.singleton,store:t.singleton.store,error:t.definitions.error,derive:t.event.transform?.filter((i)=>i?.subType==="derive").map((i)=>({fn:i.toString(),stack:Error().stack??""})),resolve:t.event.transform?.filter((i)=>i?.subType==="resolve").map((i)=>({fn:i.toString(),stack:Error().stack??""}))}:{name:t.config.name,seed:t.config.seed,checksum:o,dependencies:t.dependencies}),Fe(t.event)&&(this.event=RT(this.event,PT(t.event),o))}else Fe(t.event)&&(this.event=RT(this.event,PT(t.event)));return t.validator.global&&(this.validator.global=Yi(this.validator.global,{...t.validator.global})),t.validator.scoped&&(this.validator.local=Yi(this.validator.local,{...t.validator.scoped})),this}macro(t,r){if(typeof t=="string"&&!r)throw Error("Macro function is required");return typeof t=="string"?this.extender.macro[t]=r:this.extender.macro={...this.extender.macro,...t},this}applyMacro(t,r=t,{iteration:n=0,applied:o={}}={}){if(n>=16)return;let i=this.extender.macro;for(let[s,a]of Object.entries(r)){if(!(s in i))continue;let c=typeof i[s]=="function"?i[s](a):i[s];if(!c||typeof i[s]=="object"&&a===!1)return;let l=Hs(s+JSON.stringify(c.seed??a));if(!(l in o)){o[l]=!0;for(let[u,d]of Object.entries(c))if(u!=="seed"){if(u in kD){SD(t,u,d),delete t[s];continue}if(u==="introspect"){d?.(t),delete t[s];continue}if(u==="detail"){t.detail||(t.detail={}),t.detail=cr(t.detail,d,{mergeArray:!0}),delete t[s];continue}if(u in i){this.applyMacro(t,{[u]:d},{applied:o,iteration:n+1}),delete t[s];continue}switch((u==="derive"||u==="resolve")&&typeof d=="function"&&(d={fn:d,subType:u}),typeof t[u]){case"function":t[u]=[t[u],d];break;case"object":Array.isArray(t[u])?t[u].push(d):t[u]=[t[u],d];break;case"undefined":t[u]=d;break}delete t[s]}}}}mount(t,r,n){if(t instanceof e||typeof t=="function"||t.length===0||t==="/"){let a=typeof t=="function"?t:t instanceof e?t.compile().fetch:r instanceof e?r.compile().fetch:typeof r=="function"?r:(()=>{throw Error("Invalid handler")})(),c=({request:l,path:u})=>a(new Request(jb(l.url,u),l));return this.route("ALL","/*",c,{parse:"none",...n,detail:{...n?.detail,hide:!0},config:{mount:a}}),this}let o=r instanceof e?r.compile().fetch:typeof r=="function"?r:(()=>{throw Error("Invalid handler")})(),i=(typeof t=="string"&&this.config.prefix?this.config.prefix+t:t).length-(t.endsWith("*")?1:0),s=({request:a,path:c})=>o(new Request(jb(a.url,c.slice(i)||"/"),a));return this.route("ALL",t,s,{parse:"none",...n,detail:{...n?.detail,hide:!0},config:{mount:o}}),this.route("ALL",t+(t.endsWith("/")?"*":"/*"),s,{parse:"none",...n,detail:{...n?.detail,hide:!0},config:{mount:o}}),this}get(t,r,n){return this.add("GET",t,r,n),this}post(t,r,n){return this.add("POST",t,r,n),this}put(t,r,n){return this.add("PUT",t,r,n),this}patch(t,r,n){return this.add("PATCH",t,r,n),this}delete(t,r,n){return this.add("DELETE",t,r,n),this}options(t,r,n){return this.add("OPTIONS",t,r,n),this}all(t,r,n){return this.add("ALL",t,r,n),this}head(t,r,n){return this.add("HEAD",t,r,n),this}connect(t,r,n){return this.add("CONNECT",t,r,n),this}route(t,r,n,o){return this.add(t.toUpperCase(),r,n,o,o?.config),this}ws(t,r){return this["~adapter"].ws?this["~adapter"].ws(this,t,r):console.warn("Current adapter doesn't support WebSocket"),this}state(t,r,n){r===void 0?(n=t,t={as:"append"},r=""):n===void 0&&(typeof t=="string"?(n=r,r=t,t={as:"append"}):typeof t=="object"&&(n=r,r=""));let{as:o}=t;if(typeof r!="string")return this;switch(typeof n){case"object":return!n||!Fe(n)?this:r?((r in this.singleton.store)?this.singleton.store[r]=cr(this.singleton.store[r],n,{override:o==="override"}):this.singleton.store[r]=n,this):n===null?this:(this.singleton.store=cr(this.singleton.store,n,{override:o==="override"}),this);case"function":return r?(o==="override"||!(r in this.singleton.store))&&(this.singleton.store[r]=n):this.singleton.store=n(this.singleton.store),this;default:return(o==="override"||!(r in this.singleton.store))&&(this.singleton.store[r]=n),this}}decorate(t,r,n){r===void 0?(n=t,t={as:"append"},r=""):n===void 0&&(typeof t=="string"?(n=r,r=t,t={as:"append"}):typeof t=="object"&&(n=r,r=""));let{as:o}=t;if(typeof r!="string")return this;switch(typeof n){case"object":return r?((r in this.singleton.decorator)?this.singleton.decorator[r]=cr(this.singleton.decorator[r],n,{override:o==="override"}):this.singleton.decorator[r]=n,this):n===null?this:(this.singleton.decorator=cr(this.singleton.decorator,n,{override:o==="override"}),this);case"function":return r?(o==="override"||!(r in this.singleton.decorator))&&(this.singleton.decorator[r]=n):this.singleton.decorator=n(this.singleton.decorator),this;default:return(o==="override"||!(r in this.singleton.decorator))&&(this.singleton.decorator[r]=n),this}}derive(t,r){r||(r=t,t={as:"local"});let n={subType:"derive",fn:r};return this.onTransform(t,n)}model(t,r){let n=(o)=>{let i={};for(let s in o)"~standard"in o[s]||(i[s]=o[s]);return i};switch(typeof t){case"object":let o={},i=Object.entries(t);if(!i.length)return this;for(let[c,l]of i)c in this.definitions.type||("~standard"in l?this.definitions.type[c]=l:(o[c]=this.definitions.type[c]=l,o[c].$id??=`#/components/schemas/${c}`));return this.definitions.typebox=z.Module({...this.definitions.typebox.$defs,...o}),this;case"function":let s=t(this.definitions.type);return this.definitions.type=s,this.definitions.typebox=z.Module(n(s)),this;case"string":if(!r)break;if(this.definitions.type[t]=r,"~standard"in r)return this;let a={...r,id:r.$id??`#/components/schemas/${t}`};return this.definitions.typebox=z.Module({...this.definitions.typebox.$defs,...a}),this}return r?(this.definitions.type[t]=r,("~standard"in r)?this:(this.definitions.typebox=z.Module({...this.definitions.typebox.$defs,[t]:r}),this)):this}Ref(t){return z.Ref(t)}mapDerive(t,r){r||(r=t,t={as:"local"});let n={subType:"mapDerive",fn:r};return this.onTransform(t,n)}affix(t,r,n){if(n==="")return this;let o=["_","-"," "],i=(l)=>l[0].toUpperCase()+l.slice(1),s=t==="prefix"?(l,u)=>o.includes(l.at(-1)??"")?l+u:l+i(u):o.includes(n.at(-1)??"")?(l,u)=>u+l:(l,u)=>u+i(l),a=(l)=>{let u={};switch(l){case"decorator":for(let d in this.singleton.decorator)u[s(n,d)]=this.singleton.decorator[d];this.singleton.decorator=u;break;case"state":for(let d in this.singleton.store)u[s(n,d)]=this.singleton.store[d];this.singleton.store=u;break;case"model":for(let d in this.definitions.type)u[s(n,d)]=this.definitions.type[d];this.definitions.type=u;break;case"error":for(let d in this.definitions.error)u[s(n,d)]=this.definitions.error[d];this.definitions.error=u;break}},c=Array.isArray(r)?r:[r];for(let l of c.some((u)=>u==="all")?["decorator","state","model","error"]:c)a(l);return this}prefix(t,r){return this.affix("prefix",t,r)}suffix(t,r){return this.affix("suffix",t,r)}compile(){return this["~adapter"].beforeCompile?.(this),this["~adapter"].isWebStandard?(this._handle=this.config.aot?Tw(this):TE(this),Object.defineProperty(this,"fetch",{value:this._handle,configurable:!0,writable:!0}),typeof this.server?.reload=="function"&&this.server.reload({...this.server||{},fetch:this.fetch}),this):(typeof this.server?.reload=="function"&&this.server.reload(this.server||{}),this._handle=Tw(this),this)}get fetch(){let t=this.config.aot?Tw(this):TE(this);return Object.defineProperty(this,"fetch",{value:t,configurable:!0,writable:!0}),t}get modules(){return this.promisedModules}},Bo=P0e;var Iw={name:"@kabmo-labs/kabmo",version:"0.30.1",description:"Web console and diagnostic workbench for AI coding agents: Elysia + Preact on Bun.",license:"MIT",author:"Wijanarko Putra Rajeb <wijanarko.rajeb@gmail.com>",type:"module",engines:{bun:">=1.4.0"},publishConfig:{access:"public"},bin:{kabmo:"./src/cli/kabmo.js"},repository:{type:"git",url:"git+https://github.com/kabmo-labs/kabmo.git"},homepage:"https://github.com/kabmo-labs/kabmo#readme",bugs:{url:"https://github.com/kabmo-labs/kabmo/issues"},keywords:["kabmo","coding-agent","agent","console","elysia","preact","bun"],files:["src","extensions","index.html","bunfig.toml","public","tsconfig.json","marketplace","dist/client"],scripts:{dev:"bun run --hot src/server/index.ts --kabmo-server","dev:lan":"HOST=0.0.0.0 bun run --hot src/server/index.ts --kabmo-server",build:"bun run scripts/build-client.ts","editor:themes":"bun run scripts/editor-themes.mjs","icons:tints":"bun run scripts/icon-tints.mjs","icons:tints:check":"bun run scripts/icon-tints.mjs --check","editor:themes:check":"bun run scripts/editor-themes.mjs --check","omp:schema":"bun run scripts/omp-schema.mjs","omp:schema:check":"bun run scripts/omp-schema.mjs --check",start:"NODE_ENV=production bun run src/server/index.ts --kabmo-server",typecheck:"tsc",clean:"rm -rf dist",lint:"tsc --noEmit","check:fast":"bun check --no-script",test:"bun test","test:e2e":"playwright test --config tests/e2e/playwright.config.ts","readme:media":"bun run scripts/readme-media.ts","shell:wordmark":"bun run scripts/shell-wordmark.mjs","shell:docs":"bun run scripts/shell-document-types.mjs --write","shell:docs:check":"bun run scripts/shell-document-types.mjs --check","typecheck:e2e":"tsc --noEmit -p tests/e2e","typecheck:consumer":"tsc --noEmit -p tsconfig.consumer.json","publish:plugins":"bash .github/scripts/publish-plugin-packages.sh packages/kabmo-sdk packages/kabmo-ui"},dependencies:{"@codemirror/autocomplete":"6.20.4","@codemirror/commands":"6.11.1","@codemirror/language":"6.13.1","@codemirror/legacy-modes":"^6.5.5","@codemirror/lint":"^6.9.7","@codemirror/merge":"6.12.3","@codemirror/search":"6.7.2","@codemirror/state":"6.7.6","@codemirror/view":"6.43.15","@dskripchenko/drawio":"^0.1.0","@fontsource/fira-code":"^5.3.0","@kabmo-labs/kabmo-sdk":"workspace:*","@kabmo-labs/kabmo-ui":"workspace:*","@shikijs/langs":"^4.4.3","@shikijs/themes":"^4.4.3","@tailwindcss/postcss":"^4.1.14",dompurify:"^3.4.15",elysia:"^1.4.30","ghostty-web":"0.4.0-next.21.g640db46","jsonc-parser":"^3.3.1",katex:"^0.18.7","lucide-preact":"^1.47.0",mammoth:"^1.13.0",marked:"^18.0.11","marked-linkify-it":"^4.0.2",mermaid:"^12.0.0",postcss:"^8.5.16",preact:"^10.29.8",remend:"^1.3.1",ripgrep:"^0.3.1",shiki:"^4.4.3","smol-toml":"^1.9.1",tailwindcss:"^4.1.14",xlsx:"https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",yaml:"^2.9.1"},devDependencies:{"@playwright/test":"^1.64.0","@semantic-release/changelog":"^7.0.0","@semantic-release/commit-analyzer":"^13.0.1","@semantic-release/git":"^11.0.1","@semantic-release/github":"^12.0.10","@semantic-release/npm":"^13.2.0","@semantic-release/release-notes-generator":"^14.1.1","@types/bun":"1.4.4","@types/node":"^22.14.0","bun-types":"1.4.4","conventional-changelog-conventionalcommits":"^9.3.1","happy-dom":"^20.14.5","semantic-release":"^25.0.9",typescript:"~5.8.2"},workspaces:["packages/*"]};var B6=tN("{\"index\":\"./dist/client/index.html\",\"files\":[{\"input\":\"../../index.html\",\"path\":\"./dist/client/static/js/index-bwhhehnh.js\",\"loader\":\"js\",\"isEntry\":true,\"headers\":{\"etag\":\"C7wREa5xVXE\",\"content-type\":\"text/javascript;charset=utf-8\"}},{\"input\":\"../../index.html\",\"path\":\"./dist/client/index.html\",\"loader\":\"html\",\"isEntry\":true,\"headers\":{\"etag\":\"89QME0zsokk\",\"content-type\":\"text/html;charset=utf-8\"}},{\"input\":\"../../index.html\",\"path\":\"./dist/client/static/js/index-naa91727.css\",\"loader\":\"css\",\"isEntry\":true,\"headers\":{\"etag\":\"1eoKiYFHIic\",\"content-type\":\"text/css;charset=utf-8\"}},{\"input\":\"../../public/manifest.webmanifest\",\"path\":\"./dist/client/static/manifest-vdvdqpre.webmanifest\",\"loader\":\"file\",\"isEntry\":false,\"headers\":{\"etag\":\"Wy1bbZc2uM4\",\"content-type\":\"application/manifest+json\"}},{\"input\":\"../../public/icon.svg\",\"path\":\"./dist/client/static/icon-8h6v1jcy.svg\",\"loader\":\"file\",\"isEntry\":false,\"headers\":{\"etag\":\"yFEme-ESbP4\",\"content-type\":\"image/svg+xml\"}},{\"input\":\"../../public/icon-192x192.png\",\"path\":\"./dist/client/static/icon-192x192-kz5bvz85.png\",\"loader\":\"file\",\"isEntry\":false,\"headers\":{\"etag\":\"819lS3sfyKU\",\"content-type\":\"image/png\"}},{\"input\":\"../../public/apple-touch-icon.png\",\"path\":\"./dist/client/static/apple-touch-icon-bbhgf3mq.png\",\"loader\":\"file\",\"isEntry\":false,\"headers\":{\"etag\":\"K8vRUA9jdJc\",\"content-type\":\"image/png\"}}]}");function m(e,t={}){let r=new Headers(t.headers);if(!r.has("content-type"))r.set("content-type","application/json; charset=utf-8");return new Response(JSON.stringify(e),{status:t.status??200,headers:r})}var re={"cache-control":"no-store"};import{brotliCompressSync as O0e,constants as M0e}from"zlib";function fo(e){if(e.buffer instanceof ArrayBuffer)return e;return new Uint8Array(e)}var RE=1024,j6=/^(text\/|application\/(json|javascript|xml|wasm|svg))/,N0e=["zstd","br","gzip"];function H6(e){return j6.test(e)}function PE(e){if(!e)return null;for(let t of N0e)if(e.includes(t))return t;return null}function IE(e,t){if(t==="zstd")return fo(Bun.zstdCompressSync(e,{level:3}));if(t==="br")return fo(O0e(e,{params:{[M0e.BROTLI_PARAM_QUALITY]:4}}));return fo(Bun.gzipSync(e,{level:6}))}async function _a(e,t){if(!t)return e;let r=e.headers.get("content-type")??"";if(r.includes("text/event-stream"))return e;if(!j6.test(r))return e;if(e.status===204||e.status===304)return e;let n=PE(t);if(!n)return e;let o=fo(new Uint8Array(await e.arrayBuffer()));if(o.byteLength<RE)return L0e(e,o);let i=IE(o,n),s=new Headers(e.headers);return s.set("content-encoding",n),s.set("content-length",String(i.byteLength)),s.append("vary","accept-encoding"),new Response(i,{status:e.status,headers:s})}function L0e(e,t){return new Response(t,{status:e.status,headers:e.headers})}function G(e,t,r={}){let n=[];if(e.loader)n.push({method:"GET",path:t,handler:e.loader});else if(e.action)n.push({method:"GET",path:t,handler:V});if(e.action)for(let o of r.mutating??["POST","PUT","PATCH","DELETE"])n.push({method:o,path:t,handler:e.action});return n}var V=()=>tu();function tu(){return new Response(JSON.stringify({error:"Method not allowed"}),{status:405,headers:{"content-type":"application/json; charset=utf-8"}})}async function $t(e){try{return{ok:!0,body:await e.json()}}catch(t){return{ok:!1,error:t instanceof Error?t.message:String(t)}}}function br(e,t){let r=e[t];return r?r:null}function go(e,t=500){return m({error:e instanceof Error?e.message:String(e)},{status:t})}async function D0e(e){if(e instanceof Response)return e;if(e instanceof ReadableStream)return new Response(e,{headers:{"content-type":"text/event-stream","cache-control":"no-cache"}});return new Response(JSON.stringify(e??null),{status:200,headers:{"content-type":"application/json; charset=utf-8"}})}function F0e(e){return async({request:t,params:r})=>{try{let n=await D0e(await e({request:t,params:r}));return await _a(n,t.headers.get("accept-encoding"))}catch(n){let o=n instanceof Error?n.message:String(n);return new Response(JSON.stringify({error:o}),{status:500,headers:{"content-type":"application/json; charset=utf-8"}})}}}function W6(e,t){let r=e;for(let{method:n,path:o,handler:i}of t){let s=F0e(i);if(n==="GET")r=r.get(o,s);else if(n==="POST")r=r.post(o,s);else if(n==="PUT")r=r.put(o,s);else if(n==="PATCH")r=r.patch(o,s);else r=r.delete(o,s)}return r}function nt(e,t,r){return[{method:"GET",path:t,handler:r??V},...["POST","PUT","PATCH","DELETE"].map((n)=>({method:n,path:t,handler:e}))]}import{existsSync as CE,realpathSync as U0e}from"fs";import{homedir as $6,tmpdir as zct}from"os";import*as _t from"path";var K6="omp",B0e=".omp";function q6(){return Bun.env.PI_CONFIG_DIR||B0e}function ho(){return _t.join($6(),q6())}function ce(){let e=Bun.env.PI_CODING_AGENT_DIR;if(e)return _t.resolve(e);return _t.join(ho(),"agent")}function V6(){let e=Bun.env.PI_CODING_AGENT_DIR;if(e)return _t.resolve(e)===_t.join(ho(),"agent");return!0}function j0e(){if(process.platform!=="linux"&&process.platform!=="darwin")return;if(!V6())return;let e=Bun.env.XDG_DATA_HOME;if(!e)return;try{let t=_t.join(e,K6);return CE(t)?t:void 0}catch{return}}function H0e(e){let t=j0e();return _t.join(t??ce(),e)}function jo(){return H0e("sessions")}function G6(){return _t.join(ce(),"projects.json")}function z6(){if(process.platform!=="linux"&&process.platform!=="darwin")return ho();if(!V6())return ho();let e=Bun.env.XDG_DATA_HOME;if(!e)return ho();try{let t=_t.join(e,K6);return CE(t)?t:ho()}catch{return ho()}}function Y6(){return _t.join(z6(),"plugins")}function OE(){return _t.join(z6(),"marketplaces.json")}function J6(e){let t=$6(),r=q6(),n=_t.resolve(e);for(let o of[r,".git"]){let i=n;while(i!==t){if(CE(_t.join(i,o)))return _t.join(i,r,"plugins");let s=_t.dirname(i);if(s===i)break;i=s}}return _t.join(n,r,"plugins")}function ru(e){try{return U0e.native(e)}catch{return e}}async function X(e){try{return await Bun.file(e).stat(),!0}catch{return!1}}function yo(e){let t=ru(e);return t.replace(/\/+$/,"")||t}import NE from"fs";import*as Ow from"path";function x(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Or(e){let t=[];for(let r of e.split(`
667
667
  `)){let n=r.trim();if(!n)continue;try{t.push(JSON.parse(n))}catch{}}return t}function X6(e){let t=e.endsWith("\\")?e.slice(0,-1):e;try{return JSON.parse(`"${t}"`)}catch{return t.replace(/\\n/g,`
668
668
  `).replace(/\\r/g,"\r").replace(/\\t/g,"\t").replace(/\\"/g,'"').replace(/\\\\/g,"\\")}}function Cr(e,t,r=0){let n=e.indexOf(`"${t}"`,r);if(n===-1)return;let o=e.indexOf(":",n+t.length+2);if(o===-1)return;let i=o+1;while(i<e.length){let c=e.charCodeAt(i);if(c!==32&&c!==9&&c!==10&&c!==13)break;i++}if(e.charCodeAt(i)!==34)return;let s=i+1,a=!1;for(let c=s;c<e.length;c++){let l=e.charCodeAt(c);if(a){a=!1;continue}if(l===92){a=!0;continue}if(l===34)return X6(e.slice(s,c))}return X6(e.slice(s))}function Z6(e){let t=0,r=0;while(r<e.length){let n=e.indexOf('"type"',r);if(n===-1)break;let o=e.indexOf(":",n+6);if(o===-1)break;if(Cr(e,"type",n)==="message")t++;r=o+1}return t}function Q6(e){if(e===void 0)return;return e.trim()?e:null}function W0e(e,t){if(e?.type!=="session"||typeof e.id!=="string")return;return{id:e.id,cwd:typeof e.cwd==="string"?e.cwd:void 0,title:t===null?void 0:t??(typeof e.title==="string"?e.title:void 0),parentSession:typeof e.parentSession==="string"?e.parentSession:void 0,timestamp:typeof e.timestamp==="string"?e.timestamp:void 0}}function $0e(e,t){if(Cr(e,"type")!=="session")return;let r=Cr(e,"id");if(!r)return;return{id:r,cwd:Cr(e,"cwd"),title:t===null?void 0:t??Cr(e,"title"),parentSession:Cr(e,"parentSession"),timestamp:Cr(e,"timestamp")}}function _6(e,t){let r=t[0],n=Q6(r?.type==="title"&&typeof r.title==="string"?r.title:void 0),o=W0e(t[r?.type==="title"?1:0],n);if(o)return o;let i,s=!0;for(let a of e.split(/\r?\n/)){let c=a.trim();if(!c)continue;if(s&&Cr(c,"type")==="title"){i=Q6(Cr(c,"title")),s=!1;continue}return $0e(c,i)}return}var ME=4096,K0e=16384,e5=1048576;async function t5(e,t){let r=Bun.file(e),n=await r.stat(),o=Math.min(t,n.size);return{text:o>0?await r.slice(0,o).text():"",size:n.size,mtime:new Date(n.mtimeMs),mtimeMs:n.mtimeMs}}var q0e={session_exit:!0};function V0e(e){let t,r,n,o=!1;try{let a=JSON.parse(e);if(x(a))o=!0,t=a.type,r=a.customType,n=a.timestamp}catch{}if(!o)n=Cr(e,"timestamp"),t=Cr(e,"type"),r=Cr(e,"customType");let i;if(typeof n==="number"&&Number.isFinite(n))i=new Date(n);else if(typeof n==="string"){let a=new Date(n);if(!Number.isNaN(a.getTime()))i=a}if(!i)return;let s=t==="custom"&&typeof r==="string"&&q0e[r]===!0;return{at:i,lifecycle:s}}async function r5(e,t,r){if(t<=0)return;let n=K0e;for(;;){let o=Math.max(0,t-n),i;if(t<=ME)i=r;else if(o===0)try{i=await Bun.file(e).text()}catch{return}else try{i=await Bun.file(e).slice(o-1).text()}catch{return}let s=i.split(`
669
669
  `);if(o>0)s.shift();for(let a=s.length-1;a>=0;a--){let c=s[a].trim();if(!c.includes('"timestamp"'))continue;let l=V0e(c);if(l&&!l.lifecycle)return l.at}if(o===0||n>=e5)return;n=Math.min(n*4,e5)}}var o5=/User invoked the \\?"([^"\\]+)\\?" skill/,Cw="skill-prompt";function n5(e){if(typeof e==="string")return e;if(!Array.isArray(e))return"";return e.map((t)=>x(t)&&typeof t.text==="string"?t.text:"").join("")}function i5(e,t){let r=e.trim();if(!r)return"";let n=t?.trim();return n?`/skill:${r} ${n}`:`/skill:${r}`}function jg(e){if(e.type==="custom_message"&&e.customType===Cw){if(e.attribution!==void 0&&e.attribution!=="user")return;let r=x(e.details)?e.details:void 0,n=typeof r?.name==="string"?r.name:o5.exec(n5(e.content))?.[1];if(!n)return;let o=typeof r?.args==="string"?r.args:void 0;return i5(n,o)||void 0}if(e.type!=="message")return;let t=x(e.message)?e.message:void 0;if(!t||t.role!=="user")return;return n5(t.content).trim()||void 0}function s5(e){let t,r=e.indexOf('"role"');while(r!==-1){let o=Cr(e,"role",r),i=Cr(e,"content",r)??Cr(e,"text",r);if(i){if(o==="user")return i;if(!t&&(o==="developer"||o==="assistant"))t=i}r=e.indexOf('"role"',r+6)}let n=e.indexOf('"customType"');while(n!==-1){if(Cr(e,"customType",n)===Cw){let o=o5.exec(e.slice(n))?.[1];if(o)return i5(o)}n=e.indexOf('"customType"',n+12)}return t}var nu=256;async function a5(e){try{let{text:t,size:r,mtime:n,mtimeMs:o}=await t5(e,ME),i=await r5(e,r,t),s=Or(t),a=_6(t,s);if(!a)return;let c=0,l="",u;for(let d=1;d<s.length;d++){let f=s[d];if(f.type==="compaction"&&typeof f.shortSummary==="string")u=f.shortSummary;if(f.type==="message"&&f.message)c++;if(!l){let p=jg(f);if(p)l=p}}return l||=s5(t)??"",{path:e,id:a.id,cwd:a.cwd??"",title:a.title??u,parentSessionPath:a.parentSession,created:new Date(a.timestamp??""),modified:i??n,fileMtime:n,fileMtimeMs:o,messageCount:Math.max(c,Z6(t)),size:r,firstMessage:l||"(no messages)"}}catch{return}}var c5=3,G0e=2048;async function LE(e=jo()){try{await Bun.file(e).stat()}catch{return[]}if(!globalThis.__kabmoSessionFileListCache)globalThis.__kabmoSessionFileListCache=new Map;let t=globalThis.__kabmoSessionFileListCache,r=t.get(e);if(r){let s=!0;for(let a of await NE.promises.readdir(e,{withFileTypes:!0})){if(!a.isDirectory())continue;try{let c=await Bun.file(Ow.join(e,a.name)).stat();if(r.dirMtimes.get(a.name)!==c.mtimeMs){s=!1;break}}catch{s=!1;break}}if(s&&r.dirMtimes.size>0)return r.files}let n=[],o=new Map,i=[];try{i=await NE.promises.readdir(e,{withFileTypes:!0})}catch{}for(let s of i){if(!s.isDirectory())continue;let a=Ow.join(e,s.name);try{o.set(s.name,(await Bun.file(a).stat()).mtimeMs)}catch{continue}let c=[];try{c=await NE.promises.readdir(a,{withFileTypes:!0})}catch{continue}for(let l of c){if(!l.isFile()||!l.name.endsWith(".jsonl"))continue;n.push(Ow.join(a,l.name))}}return t.set(e,{dirMtimes:o,files:n}),globalThis.__kabmoSessionIdIndex?.delete(e),n}function z0e(){let e=globalThis.__kabmoSessionScanCache;if(e&&e.version===c5)return e.entries;let t={version:c5,entries:new Map};return globalThis.__kabmoSessionScanCache=t,t.entries}async function Hg(e){let t;try{t=await Bun.file(e).stat()}catch{return}let r=z0e(),n=r.get(e);if(n){let i=n;if(i.size===t.size&&i.fileMtimeMs===t.mtimeMs)return r.delete(e),r.set(e,i),i;r.delete(e)}let o=await a5(e);if(o){r.set(e,o);while(r.size>G0e){let i=r.keys().next().value;if(i===void 0)break;r.delete(i)}}return o}async function Y0e(e,t,r){let n=Array(e.length),o=0,i=Array(Math.min(t,e.length)).fill(null).map(async()=>{for(;;){let s=o++;if(s>=e.length)return;n[s]=await r(e[s])}});return await Promise.all(i),n}var J0e=32;async function DE(e=jo()){let t=await LE(e),r=await Y0e(t,J0e,(o)=>Hg(o)),n=[];for(let o of r)if(o)n.push(o);return n.sort((o,i)=>i.modified.getTime()-o.modified.getTime()),n}async function FE(e=jo()){let t=globalThis.__kabmoSessionIdIndex??=new Map,r=t.get(e);if(r)return r.entries;let n=new Map;for(let o of await DE(e))if(!n.has(o.id))n.set(o.id,o.path);return t.set(e,{entries:n}),n}function St(){globalThis.__kabmoSessionFileListCache?.clear(),globalThis.__kabmoSessionScanCache?.entries.clear(),globalThis.__kabmoSessionIdIndex?.clear()}async function ec(e){try{let r=(await Bun.file(e).slice(0,nu+4096).text()).split(`