@kabmo-labs/kabmo 0.14.0 → 0.14.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.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/static/js/index-bnrrw242.css +1 -0
- package/dist/client/static/js/{index-nfsg1jpt.js → index-w6jx0h0p.js} +602 -602
- package/marketplace/plugins/command-runner/package.json +2 -2
- package/marketplace/plugins/command-runner/src/server/ring.test.ts +41 -0
- package/marketplace/plugins/command-runner/src/server/run-types.ts +6 -0
- package/marketplace/plugins/command-runner/src/server/runner-harness.ts +69 -0
- package/marketplace/plugins/command-runner/src/server/runner-path.test.ts +127 -0
- package/marketplace/plugins/command-runner/src/server/runner.test.ts +2 -72
- package/marketplace/plugins/command-runner/src/server/runner.ts +31 -3
- package/package.json +2 -2
- package/src/client/components/common/session-row/index.tsx +11 -1
- package/src/client/components/common/session-row/session-row.test.tsx +10 -0
- package/src/client/components/layout/session-sidebar/modern/Skeleton.tsx +5 -4
- package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +11 -2
- package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +111 -0
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +1 -0
- package/src/client/components/workspace/chat-timeline/ThinkingSection.test.tsx +117 -0
- package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +10 -9
- package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +21 -1
- package/src/client/components/workspace/editor/viewers/SvgPreview.tsx +16 -2
- package/src/client/hooks/chat/timeline/row-window-reveal.ts +130 -0
- package/src/client/hooks/chat/timeline/row-window.test.ts +35 -0
- package/src/client/hooks/chat/timeline/row-window.ts +59 -133
- package/src/client/hooks/chat/timeline/thinking-open.ts +67 -0
- package/src/shared/lib/chat/timeline/trace-groups.test.ts +12 -0
- package/src/shared/lib/chat/timeline/trace-groups.ts +29 -2
- package/src/shared/lib/workspace/session-state/store.ts +5 -0
- package/dist/client/static/js/index-tsgy3gd1.css +0 -1
package/dist/client/index.html
CHANGED
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
href="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap"
|
|
65
65
|
/>
|
|
66
66
|
<!--app-head-->
|
|
67
|
-
<link rel="stylesheet" crossorigin href="./static/js/index-
|
|
67
|
+
<link rel="stylesheet" crossorigin href="./static/js/index-bnrrw242.css"><script type="module" crossorigin src="./static/js/index-w6jx0h0p.js"></script></head>
|
|
68
68
|
<body>
|
|
69
69
|
<div id="app"></div>
|
|
70
70
|
<!--app-bootstrap-->
|
package/dist/client/index.js
CHANGED
|
@@ -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(!Dh(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),Bh){if(!d)continue;for(let[m,p]of Object.entries(d))if(!(!p||!(m in yF))){if(p instanceof Promise){a&&(c[u]||(c[u]={}),l.push(p.then((h)=>{h instanceof Response&&(c[u][m]=h),cm(h)&&(c[u][m]=h)})));continue}!(p instanceof Response)&&!cm(p)||(c[u]||(c[u]={}),c[u][m]=p)}}else{if(!d)continue;if(d instanceof Promise){a&&(c[u]||(c[u]={}),l.push(d.then((m)=>{m instanceof Response&&(c[u]=m)})));continue}if(!(d instanceof Response))continue;c[u]=d}return a?Promise.all(l).then(()=>c):c},o=gF(xy(xy(n(e.router.response),fF(e)),e.config.serve?.routes)),i=typeof t=="object"?{development:!Gi,reusePort:!0,idleTimeout:30,...e.config.serve||{},...t||{},routes:o,websocket:{...e.config.websocket||{},...Gk||{},...t.websocket||{}},fetch:e.fetch}:{development:!Gi,reusePort:!0,idleTimeout:30,...e.config.serve||{},routes:o,websocket:{...e.config.websocket||{},...Gk||{}},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=gF(xy(xy(await n(e.router.response,{withAsync:!0}),fF(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=At(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=At(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:m,path:p,qi:h,headers:g,query:y,params:b}=u;if(u.validator=l,r.upgrade)if(typeof r.upgrade=="function"){let v=r.upgrade(u);v instanceof Promise&&await v}else r.upgrade&&Object.assign(m.headers,r.upgrade);if(m.cookie&&Ie(m.cookie)){let v=Zp(m.cookie);v&&(m.headers["set-cookie"]=v)}m.headers["set-cookie"]&&Array.isArray(m.headers["set-cookie"])&&(m.headers=Nk(new Headers(m.headers),m.headers["set-cookie"]));let w=mF(l),T=pF(n),S;if(typeof r.beforeHandle=="function"){let v=r.beforeHandle(u);v instanceof Promise&&await v}let A=[...r.error?Array.isArray(r.error)?r.error:[r.error]:[],...(e.event.error??[]).map((v)=>typeof v=="function"?v:v.fn)].filter((v)=>v),E=A.length>0,O=E?async(v,D)=>{for(let L of A){let I=L(Object.assign(u,{error:D}));if(I instanceof Promise&&(I=await I),await w(v,I),I)break}}:()=>{};if(!d?.upgrade(u.request,{headers:Ie(m.headers)?m.headers:void 0,data:{...u,get id(){return S||(S=Vi())},validator:l,ping(v,D){r.ping?.(v,D)},pong(v,D){r.pong?.(v,D)},open:async(v)=>{try{await w(v,r.open?.(new xu(v,u)))}catch(D){O(v,D)}},message:async(v,D)=>{let L=await T(v,D);if(c&&c(L)){let I=new se("message",a,L);return E?O(v,I):void v.send(I.message)}try{await w(v,r.message?.(new xu(v,u,L),L))}catch(I){O(v,I)}},drain:async(v)=>{try{await w(v,r.drain?.(new xu(v,u)))}catch(D){O(v,D)}},close:async(v,D,L)=>{try{await w(v,r.close?.(new xu(v,u),D,L))}catch(I){O(v,I)}}}}))return ni(400,"Expected a websocket connection")},{...s,websocket:r})}};var Sy=Nn?Bun.env:typeof process<"u"&&process?.env?process.env:{};var kF=/^(.+)\[(\d+)\]$/,wF=new Set(["__proto__","constructor","prototype"]),xF=(e)=>{if(wF.has(e))return!0;let t=e.match(kF);return t?wF.has(t[1]):!1},SF=(e)=>{let t=e.match(kF);return t?{name:t[1],index:parseInt(t[2],10)}:null},_ie=(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}},zk=(e,t,r)=>{let n=t.split("."),o=n.pop();if(xF(o)||n.some(xF))return;let i=e;for(let a of n){let c=SF(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]=_ie(l)??{}),i=i[c.name][c.index]}else(!i[a]||typeof i[a]!="object")&&(i[a]={}),i=i[a]}let s=SF(o);s?(Array.isArray(i[s.name])||(i[s.name]=[]),i[s.name][s.index]=r):i[o]=r},Yk=(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)},Jk=(e,t)=>{let r=e.schema;if(!r)return;r.$defs?.[r.$ref]&&(r=r.$defs[r.$ref]);let n=ai(r);if(n)for(let[o,i]of Object.entries(n))t[o]??=i.default};async function kc(e,t,r){let n=await t.Validate(r);if(n.issues)throw new se(e,t,r,!1,n.issues);return n.value}var Xk=(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:ni,status:ni,redirect:oc}),d;try{if(e.event.request)for(let D=0;D<e.event.request.length;D++){let L=e.event.request[D].fn,I=L(u);if(I instanceof Promise&&(I=await I),I=r(I,l),I)return u.response=I}let m=o.method==="GET"&&o.headers.get("upgrade")?.toLowerCase()==="websocket"?"WS":o.method,p=e.router.dynamic.find(o.method,c)??e.router.dynamic.find(m,c)??e.router.dynamic.find("ALL",c);if(!p)throw u.query=a===-1?{}:qs(i.substring(a+1)),new iu;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=qs(await o.text());break;case"application/octet-stream":w=await o.arrayBuffer();break;case"multipart/form-data":{w={};let D=await o.formData(),L=new Map;D.forEach((I,j)=>{let B=L.get(j);B?B.push(I):L.set(j,[I])});for(let[I,j]of L){if(w[I])continue;let B=Yk(j);I.includes(".")||I.includes("[")?zk(w,I,B):w[I]=B}break}}else{let D;if(o.body&&(D=o.headers.get("content-type")),D){let L=D.indexOf(";");if(L!==-1&&(D=D.slice(0,L)),u.contentType=D,d.parse)for(let I=0;I<d.parse.length;I++){let j=d.parse[I].fn;if(typeof j=="string")switch(j){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=qs(await o.text());break;case"arrayBuffer":case"application/octet-stream":w=await o.arrayBuffer();break;case"formdata":case"multipart/form-data":{w={};let B=await o.formData(),J=new Map;B.forEach((te,ie)=>{let ne=J.get(ie);ne?ne.push(te):J.set(ie,[te])});for(let[te,ie]of J){if(w[te])continue;let ne=Yk(ie);te.includes(".")||te.includes("[")?zk(w,te,ne):w[te]=ne}break}default:{let B=e["~parser"][j];if(B){let J=B(u,D);if(J instanceof Promise&&(J=await J),J){w=J;break}}break}}else{let B=j(u,D);if(B instanceof Promise&&(B=await B),B){w=B;break}}}if(delete u.contentType,w===void 0)switch(D){case"application/json":w=await o.json();break;case"text/plain":w=await o.text();break;case"application/x-www-form-urlencoded":w=qs(await o.text());break;case"application/octet-stream":w=await o.arrayBuffer();break;case"multipart/form-data":{w={};let I=await o.formData(),j=new Map;I.forEach((B,J)=>{let te=j.get(J);te?te.push(B):j.set(J,[B])});for(let[B,J]of j){if(w[B])continue;let te=Yk(J);B.includes(".")||B.includes("[")?zk(w,B,te):w[B]=te}break}}}}u.route=b,u.body=w,u.params=p?.params||void 0,u.query=a===-1?{}:qs(i.substring(a+1)),u.headers={};for(let[D,L]of o.headers.entries())u.headers[D]=L;let T={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 ay(u.set,S,T);let A=g?.createHeaders?.();A&&Jk(A,u.headers);let E=g?.createParams?.();E&&Jk(E,u.params);let O=g?.createQuery?.();if(O&&Jk(O,u.query),d.transform)for(let D=0;D<d.transform.length;D++){let L=d.transform[D],I=L.fn(u);if(I instanceof Promise&&(I=await I),I instanceof vt){let j=r(I,u.set);if(j)return u.response=j}L.subType==="derive"&&Object.assign(u,I)}if(g){if(A){let L=structuredClone(u.headers);for(let[I,j]of o.headers)L[I]=j;if(A.provider==="standard")u.headers=await kc("header",A,L);else if(g.headers.Check(L)===!1)throw new se("header",g.headers,L)}else g.headers?.Decode&&(u.headers=g.headers.Decode(u.headers));if(E?.provider==="standard")u.params=await kc("params",E,u.params);else{if(E?.Check(u.params)===!1)throw new se("params",g.params,u.params);g.params?.Decode&&(u.params=g.params.Decode(u.params))}if(g.query?.schema){let L=g.query.schema;L.$defs?.[L.$ref]&&(L=L.$defs[L.$ref]);let I=ai(L);if(I)for(let j of Object.keys(I)){let B=I[j];(B.type==="array"||B.items?.type==="string")&&typeof u.query[j]=="string"&&u.query[j]&&(u.query[j]=u.query[j].split(","))}}if(O?.provider==="standard")u.query=await kc("query",O,u.query);else{if(O?.Check(u.query)===!1)throw new se("query",g.query,u.query);g.query?.Decode&&(u.query=g.query.Decode(u.query))}if(g.createCookie?.()){let L={};for(let[I,j]of Object.entries(u.cookie))L[I]=j.value;if(g.cookie.provider==="standard"){L=await kc("cookie",g.cookie,L);for(let I of Object.keys(L))u.cookie[I].value=L[I]}else{if(g.cookie.Check(L)===!1)throw new se("cookie",g.cookie,L);g.cookie?.Decode&&(L=g.cookie.Decode(L))}}let D=g.createBody?.();if(D?.provider==="standard")u.body=await kc("body",D,w);else{if(D?.Check(w)===!1)throw new se("body",g.body,w);if(g.body?.Decode){let L=g.body.Decode(w);L instanceof Promise&&(L=await L),u.body=L?.value??L}}}if(d.beforeHandle)for(let D=0;D<d.beforeHandle.length;D++){let L=d.beforeHandle[D],I=L.fn(u);if(I instanceof Promise&&(I=await I),I instanceof vt){let j=r(I,u.set);if(j)return u.response=j}if(L.subType==="resolve"){Object.assign(u,I);continue}if(I!==void 0){if(u.response=I,d.afterHandle)for(let B=0;B<d.afterHandle.length;B++){let J=d.afterHandle[B].fn(u);J instanceof Promise&&(J=await J),J&&(I=J)}let j=r(I,u.set);if(j)return u.response=j}}let v=typeof h=="function"?h(u):h;if(v instanceof Promise&&(v=await v),d.afterHandle?.length){u.response=v;for(let D=0;D<d.afterHandle.length;D++){let L=d.afterHandle[D].fn(u);L instanceof Promise&&(L=await L);let I=L instanceof vt,j=I?L.code:l.status?typeof l.status=="string"?ri[l.status]:l.status:200;I&&(l.status=j,L=L.response);let B=g?.createResponse?.()?.[j];if(B?.provider==="standard")L=await kc("response",B,L);else if(B?.Check(L)===!1)if(B?.Clean)try{let te=B.Clean(L);if(B?.Check(te)===!1)throw new se("response",B,L);L=te}catch(te){throw te instanceof se?te:new se("response",B,L)}else throw new se("response",B,L);if(B?.Encode&&(u.response=L=B.Encode(L)),B?.Clean)try{u.response=L=B.Clean(L)}catch{}let J=r(L,u.set);if(J!==void 0)return u.response=J}}else{let D=v instanceof vt,L=D?v.code:l.status?typeof l.status=="string"?ri[l.status]:l.status:200;D&&(l.status=L,v=v.response);let I=g?.createResponse?.()?.[L];if(I?.provider==="standard")v=await kc("response",I,v);else if(I?.Check(v)===!1)if(I?.Clean)try{let j=I.Clean(v);if(I?.Check(j)===!1)throw new se("response",I,v);v=j}catch(j){throw j instanceof se?j:new se("response",I,v)}else throw new se("response",I,v);if(I?.Encode&&(v=I.Encode(v)),I?.Clean)try{v=I.Clean(v)}catch{}}if(u.set.cookie&&T?.sign){let D=T.secrets?typeof T.secrets=="string"?T.secrets:T.secrets[0]:void 0;if(T.sign===!0){if(D)for(let[L,I]of Object.entries(u.set.cookie))u.set.cookie[L].value=await nu(I.value,D)}else{let L=ai(g?.cookie?.schema);if(D)for(let I of T.sign)!L||!(I in L)||u.set.cookie[I]?.value&&(u.set.cookie[I].value=await nu(u.set.cookie[I].value,D))}}return t(u.response=v,u.set)}catch(m){let p=m instanceof tc&&m.error?m.error:m;return e.handleError(u,p)}finally{let m=d?d.afterResponse:e.event.afterResponse;m&&(Nh?setImmediate(async()=>{for(let p of m)await p.fn(u)}):Promise.resolve().then(async()=>{for(let p of m)await p.fn(u)}))}}},vF=(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 se)&&!(n instanceof tc))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 TF;TF=Symbol.dispose;var ese=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:V.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}:ru(ru(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 Ba({lazy:!0,onParam:Qk.default})),this["~http"]},"~dynamic":void 0,get dynamic(){return this["~dynamic"]||(this["~dynamic"]=new Ba({onParam:Qk.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?$k(this):vF(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[TF]=()=>{this.server&&this.stop()},t.tags&&(t.detail?t.detail.tags=t.tags:t.detail={tags:t.tags}),this.config={aot:Sy.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"?bF:tm),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 tk(console.error,()=>{})),this._promisedModules}env(t,r=Sy){if(At(t,{modules:this.definitions.typebox,dynamic:!0,additionalProperties:!0,coerce:!0,sanitize:()=>this.config.sanitize}).Check(r)===!1){let n=new se("env",t,r);throw Error(n.all.map((o)=>o.summary).join(`
|
|
666
|
-
`))}return this}wrap(t){return this.extender.higherOrderFunctions.push({checksum:Ki(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]=At(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,m=()=>{let I=this.definitions.type,j=!this.config.aot,B=this.config.normalize,J=this.definitions.typebox,te=()=>this.config.sanitize,ie=()=>{if(u.cookie||c.find((ne)=>ne.cookie))return aF({modules:J,validator:u.cookie,defaultConfig:this.config.cookie,normalize:B,config:u.cookie?.config??{},dynamic:j,models:I,validators:c.map((ne)=>ne.cookie),sanitize:te})};return d?{body:At(u.body,{modules:J,dynamic:j,models:I,normalize:B,additionalCoerce:(()=>{let ne=Kk(u.body,I,J);return ne&&N in ne&&(pr("File",ne)||pr("Files",ne))?Wk():om()})(),validators:c.map((ne)=>ne.body),sanitize:te}),headers:At(u.headers,{modules:J,dynamic:j,models:I,additionalProperties:!0,coerce:!0,additionalCoerce:xc(),validators:c.map((ne)=>ne.headers),sanitize:te}),params:At(u.params,{modules:J,dynamic:j,models:I,coerce:!0,additionalCoerce:xc(),validators:c.map((ne)=>ne.params),sanitize:te}),query:At(u.query,{modules:J,dynamic:j,models:I,normalize:B,coerce:!0,additionalCoerce:jk(),validators:c.map((ne)=>ne.query),sanitize:te}),cookie:ie(),response:gy(u.response,{modules:J,dynamic:j,models:I,normalize:B,validators:c.map((ne)=>ne.response),sanitize:te})}:{createBody(){return this.body?this.body:this.body=At(u.body,{modules:J,dynamic:j,models:I,normalize:B,additionalCoerce:(()=>{let ne=Kk(u.body,I,J);return ne&&N in ne&&(pr("File",ne)||pr("Files",ne))?Wk():om()})(),validators:c.map((ne)=>ne.body),sanitize:te})},createHeaders(){return this.headers?this.headers:this.headers=At(u.headers,{modules:J,dynamic:j,models:I,normalize:B,additionalProperties:!B,coerce:!0,additionalCoerce:xc(),validators:c.map((ne)=>ne.headers),sanitize:te})},createParams(){return this.params?this.params:this.params=At(u.params,{modules:J,dynamic:j,models:I,normalize:B,coerce:!0,additionalCoerce:xc(),validators:c.map((ne)=>ne.params),sanitize:te})},createQuery(){return this.query?this.query:this.query=At(u.query,{modules:J,dynamic:j,models:I,normalize:B,coerce:!0,additionalCoerce:jk(),validators:c.map((ne)=>ne.query),sanitize:te})},createCookie(){return this.cookie?this.cookie:this.cookie=ie()},createResponse(){return this.response?this.response:this.response=gy(u.response,{modules:J,dynamic:j,models:I,normalize:B,validators:c.map((ne)=>ne.response),sanitize:te})}}};(l.body||l.cookie||l.headers||l.params||l.query||l.response)&&(o=ti(o,l)),o.tags&&(o.detail?o.detail.tags=o.tags:o.detail={tags:o.tags}),Ie(this.config.detail)&&(o.detail=Jt(Object.assign({},this.config.detail),o.detail));let p=Ie(this.event)?ti(this.event,rk(o)):{...i1(rk(o))};if(c.length&&Object.assign(p,{standaloneValidator:c}),this.config.aot===!1){let I=m();this.router.dynamic.add(t,r,{validator:I,hooks:p,content:o?.type,handle:n,route:r});let j=sc(r,{dynamic:!0});if(r!==j&&this.router.dynamic.add(t,j,{validator:I,hooks:p,content:o?.type,handle:n,route:r}),!this.config.strictPath){let B=ic(r);this.router.dynamic.add(t,B,{validator:I,hooks:p,content:o?.type,handle:n,route:r});let J=sc(B);B!==J&&this.router.dynamic.add(t,B,{validator:I,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 I=h.createNativeStaticHandler?.(n,p,{headers:Object.assign({},this.setHeaders)});return I instanceof Promise?I.then((j)=>{if(j)return j}):I?.()}:void 0,y=this.config.nativeStaticResponse===!0,b=(I)=>{!y||!g||(Bh?this.router.response[I]?this.router.response[I][t]=g():this.router.response[I]={[t]:g()}:this.router.response[I]=g())};b(r);let w,T=()=>{if(w)return w;let I=lF({app:this,path:r,method:t,hooks:p,validator:m(),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=I),I},S;if(`${t}_${r}`in this.routeTree)for(let I=0;I<this.router.history.length;I++){let j=this.router.history[I];if(j.path===r&&j.method===t){S=I;break}}else this.routeTree[`${t}_${r}`]=this.router.history.length;let A=S??this.router.history.length,E=this.router.history,O=d?T():(I)=>w?w(I):(E[A].composed=T())(I);S!==void 0?this.router.history[S]=Object.assign({method:t,path:r,composed:O,compile:T,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:O,compile:T,handler:n,hooks:p},o.webSocket?{websocket:o.websocket}:void 0));let v={handler:d?E[A].composed:void 0,compile(){return this.handler=T()}},D=this.router.static,L=r.indexOf(":")===-1&&r.indexOf("*")===-1;if(t==="WS"){if(L){r in D?D[r][t]=A:D[r]={[t]:A};return}this.router.http.add("WS",r,v),this.config.strictPath||this.router.http.add("WS",ic(r),v);let I=sc(r,{dynamic:!0});r!==I&&this.router.http.add("WS",I,v);return}if(L)r in D?D[r][t]=A:D[r]={[t]:A},this.config.strictPath||b(ic(r));else{if(this.router.http.add(t,r,v),!this.config.strictPath){let j=ic(r);b(j),this.router.http.add(t,j,v)}let I=sc(r,{dynamic:!0});r!==I&&(this.router.http.add(t,I,v),b(I))}}headers(t){return t?(this.setHeaders||(this.setHeaders={}),this.setHeaders=Jt(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",eF(n));return this}error(t,r){switch(typeof t){case"string":return r.prototype[ac]=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[ac]=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=Yt(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=hc({[o]:i.map((s)=>s.fn)},this.inference,this.config.sucrose));for(let s of i){let a=s1(s,"global",{skipIfHasType:!0});switch((this.config.name||this.config.seed)&&(a.checksum=Ki(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(Yt(a,"derive"));break;case"beforeHandle":this.event.beforeHandle??=[],this.event.beforeHandle.push(a);break;case"resolve":this.event.beforeHandle??=[],this.event.beforeHandle.push(Yt(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 $i(this.event.parse,t),$i(this.event.transform,t),$i(this.event.beforeHandle,t),$i(this.event.afterHandle,t),$i(this.event.mapResponse,t),$i(this.event.afterResponse,t),$i(this.event.trace,t),$i(this.event.error,t),t==="scoped"?(this.validator.scoped=ru(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=ru(this.validator.global,ru(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=Lh(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=Jt(this.singleton,o.singleton),this.definitions=Jt(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:m,query:p,params:h,cookie:g,response:y,...b}=r,w=u;this.applyMacro(b);let T=d||m||p||h||g||y;this.add(a,c,l,ti(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||T?[...b.standaloneValidator??[],...w.standaloneValidator??[],...T?[{body:d,headers:m,query:p,params:h,cookie:g,response:y}]:[]]:void 0}),void 0)}else this.add(a,c,l,ti(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=Jt(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=Lh(this.inference),n.extender={...this.extender},n.getServer=()=>this.getServer();let o=r(n);if(this.singleton=Jt(this.singleton,n.singleton),this.definitions=Jt(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:m,cookie:p,response:h,...g}=t,y=l||u||d||m||p||h;this.add(i,s,a,ti(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:m,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:m,...p}=t,h=a||c||l||u||d||m,g=i;i=n.router.history.length;for(let y=g;y<n.router.history.length;y++){let{method:b,path:w,handler:T,hooks:S}=n.router.history[y];this.add(b,w,T,ti(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:m}]: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),Ie(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?Ki(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 Ie(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){ik(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=oy(this.inference,t.inference),Ie(t.singleton.decorator)&&this.decorate(t.singleton.decorator),Ie(t.singleton.store)&&this.state(t.singleton.store),Ie(t.definitions.type)&&this.model(t.definitions.type),Ie(t.definitions.error)&&this.error(t.definitions.error),Ie(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?Ki(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}),Ie(t.event)&&(this.event=ZS(this.event,_S(t.event),o))}else Ie(t.event)&&(this.event=ZS(this.event,_S(t.event)));return t.validator.global&&(this.validator.global=ti(this.validator.global,{...t.validator.global})),t.validator.scoped&&(this.validator.local=ti(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=Ki(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 l1){a1(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=Jt(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(Oh(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(Oh(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||!Ie(n)?this:r?((r in this.singleton.store)?this.singleton.store[r]=Jt(this.singleton.store[r],n,{override:o==="override"}):this.singleton.store[r]=n,this):n===null?this:(this.singleton.store=Jt(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]=Jt(this.singleton.decorator[r],n,{override:o==="override"}):this.singleton.decorator[r]=n,this):n===null?this:(this.singleton.decorator=Jt(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=V.Module({...this.definitions.typebox.$defs,...o}),this;case"function":let s=t(this.definitions.type);return this.definitions.type=s,this.definitions.typebox=V.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=V.Module({...this.definitions.typebox.$defs,...a}),this}return r?(this.definitions.type[t]=r,("~standard"in r)?this:(this.definitions.typebox=V.Module({...this.definitions.typebox.$defs,[t]:r}),this)):this}Ref(t){return V.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?by(this):Xk(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=by(this),this)}get fetch(){let t=this.config.aot?by(this):Xk(this);return Object.defineProperty(this,"fetch",{value:t,configurable:!0,writable:!0}),t}get modules(){return this.promisedModules}},ro=ese;var ky={name:"@kabmo-labs/kabmo",version:"0.14.0",description:"Web console and diagnostic workbench for AI coding agents \u2014 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","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","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","@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","@xterm/addon-fit":"^0.11.0","@xterm/addon-webgl":"^0.19.0","@xterm/xterm":"^6.0.0",dompurify:"^3.4.15",elysia:"^1.4.30","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","read-excel-file":"^9.3.12",remend:"^1.3.1",ripgrep:"^0.3.1",shiki:"^4.4.3","smol-toml":"^1.9.1",tailwindcss:"^4.1.14",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 AF=KC("{\"index\":\"./dist/client/index.html\",\"files\":[{\"input\":\"../../index.html\",\"path\":\"./dist/client/static/js/index-nfsg1jpt.js\",\"loader\":\"js\",\"isEntry\":true,\"headers\":{\"etag\":\"Ve85MGES9vo\",\"content-type\":\"text/javascript;charset=utf-8\"}},{\"input\":\"../../index.html\",\"path\":\"./dist/client/index.html\",\"loader\":\"html\",\"isEntry\":true,\"headers\":{\"etag\":\"T_SVbvOFb7I\",\"content-type\":\"text/html;charset=utf-8\"}},{\"input\":\"../../index.html\",\"path\":\"./dist/client/static/js/index-tsgy3gd1.css\",\"loader\":\"css\",\"isEntry\":true,\"headers\":{\"etag\":\"mllQfgNQLSE\",\"content-type\":\"text/css;charset=utf-8\"}},{\"input\":\"../../public/manifest.webmanifest\",\"path\":\"./dist/client/static/manifest-42r8wcmg.webmanifest\",\"loader\":\"file\",\"isEntry\":false,\"headers\":{\"etag\":\"xGK4yFzs1NA\",\"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 f(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 ae={"cache-control":"no-store"};import{brotliCompressSync as nse,constants as ose}from"zlib";function Ln(e){if(e.buffer instanceof ArrayBuffer)return e;return new Uint8Array(e)}var Zk=1024,EF=/^(text\/|application\/(json|javascript|xml|wasm|svg))/,ise=["zstd","br","gzip"];function RF(e){return EF.test(e)}function _k(e){if(!e)return null;for(let t of ise)if(e.includes(t))return t;return null}function ev(e,t){if(t==="zstd")return Ln(Bun.zstdCompressSync(e,{level:3}));if(t==="br")return Ln(nse(e,{params:{[ose.BROTLI_PARAM_QUALITY]:4}}));return Ln(Bun.gzipSync(e,{level:6}))}async function Gs(e,t){if(!t)return e;let r=e.headers.get("content-type")??"";if(r.includes("text/event-stream"))return e;if(!EF.test(r))return e;if(e.status===204||e.status===304)return e;let n=_k(t);if(!n)return e;let o=Ln(new Uint8Array(await e.arrayBuffer()));if(o.byteLength<Zk)return sse(e,o);let i=ev(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 sse(e,t){return new Response(t,{status:e.status,headers:e.headers})}function z(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:G});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 G=()=>tv();function tv(){return new Response(JSON.stringify({error:"Method not allowed"}),{status:405,headers:{"content-type":"application/json; charset=utf-8"}})}async function ci(e){try{return{ok:!0,body:await e.json()}}catch(t){return{ok:!1,error:t instanceof Error?t.message:String(t)}}}function gn(e,t){let r=e[t];return r?r:null}function Bn(e,t=500){return f({error:e instanceof Error?e.message:String(e)},{status:t})}async function ase(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 cse(e){return async({request:t,params:r})=>{try{let n=await ase(await e({request:t,params:r}));return await Gs(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 PF(e,t){let r=e;for(let{method:n,path:o,handler:i}of t){let s=cse(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 Rt(e,t,r){return[{method:"GET",path:t,handler:r??G},...["POST","PUT","PATCH","DELETE"].map((n)=>({method:n,path:t,handler:e}))]}import{existsSync as rv,realpathSync as lse}from"fs";import{homedir as IF,tmpdir as LGe}from"os";import*as qt from"path";var CF="omp",use=".omp";function MF(){return Bun.env.PI_CONFIG_DIR||use}function Un(){return qt.join(IF(),MF())}function le(){let e=Bun.env.PI_CODING_AGENT_DIR;if(e)return qt.resolve(e);return qt.join(Un(),"agent")}function OF(){let e=Bun.env.PI_CODING_AGENT_DIR;if(e)return qt.resolve(e)===qt.join(Un(),"agent");return!0}function dse(){if(process.platform!=="linux"&&process.platform!=="darwin")return;if(!OF())return;let e=Bun.env.XDG_DATA_HOME;if(!e)return;try{let t=qt.join(e,CF);return rv(t)?t:void 0}catch{return}}function pse(e){let t=dse();return qt.join(t??le(),e)}function no(){return pse("sessions")}function NF(){return qt.join(le(),"projects.json")}function FF(){if(process.platform!=="linux"&&process.platform!=="darwin")return Un();if(!OF())return Un();let e=Bun.env.XDG_DATA_HOME;if(!e)return Un();try{let t=qt.join(e,CF);return rv(t)?t:Un()}catch{return Un()}}function DF(){return qt.join(FF(),"plugins")}function nv(){return qt.join(FF(),"marketplaces.json")}function LF(e){let t=IF(),r=MF(),n=qt.resolve(e);for(let o of[r,".git"]){let i=n;while(i!==t){if(rv(qt.join(i,o)))return qt.join(i,r,"plugins");let s=qt.dirname(i);if(s===i)break;i=s}}return qt.join(n,r,"plugins")}function vy(e){try{return lse.native(e)}catch{return e}}async function Y(e){try{return await Bun.file(e).stat(),!0}catch{return!1}}function Su(e){let t=vy(e);return t.replace(/\/+$/,"")||t}import iv from"fs";import*as Ay from"path";function k(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function fr(e){let t=[];for(let r of e.split(`
|
|
666
|
+
`))}return this}wrap(t){return this.extender.higherOrderFunctions.push({checksum:Ki(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]=At(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,m=()=>{let I=this.definitions.type,j=!this.config.aot,B=this.config.normalize,J=this.definitions.typebox,te=()=>this.config.sanitize,ie=()=>{if(u.cookie||c.find((ne)=>ne.cookie))return aF({modules:J,validator:u.cookie,defaultConfig:this.config.cookie,normalize:B,config:u.cookie?.config??{},dynamic:j,models:I,validators:c.map((ne)=>ne.cookie),sanitize:te})};return d?{body:At(u.body,{modules:J,dynamic:j,models:I,normalize:B,additionalCoerce:(()=>{let ne=Kk(u.body,I,J);return ne&&N in ne&&(pr("File",ne)||pr("Files",ne))?Wk():om()})(),validators:c.map((ne)=>ne.body),sanitize:te}),headers:At(u.headers,{modules:J,dynamic:j,models:I,additionalProperties:!0,coerce:!0,additionalCoerce:xc(),validators:c.map((ne)=>ne.headers),sanitize:te}),params:At(u.params,{modules:J,dynamic:j,models:I,coerce:!0,additionalCoerce:xc(),validators:c.map((ne)=>ne.params),sanitize:te}),query:At(u.query,{modules:J,dynamic:j,models:I,normalize:B,coerce:!0,additionalCoerce:jk(),validators:c.map((ne)=>ne.query),sanitize:te}),cookie:ie(),response:gy(u.response,{modules:J,dynamic:j,models:I,normalize:B,validators:c.map((ne)=>ne.response),sanitize:te})}:{createBody(){return this.body?this.body:this.body=At(u.body,{modules:J,dynamic:j,models:I,normalize:B,additionalCoerce:(()=>{let ne=Kk(u.body,I,J);return ne&&N in ne&&(pr("File",ne)||pr("Files",ne))?Wk():om()})(),validators:c.map((ne)=>ne.body),sanitize:te})},createHeaders(){return this.headers?this.headers:this.headers=At(u.headers,{modules:J,dynamic:j,models:I,normalize:B,additionalProperties:!B,coerce:!0,additionalCoerce:xc(),validators:c.map((ne)=>ne.headers),sanitize:te})},createParams(){return this.params?this.params:this.params=At(u.params,{modules:J,dynamic:j,models:I,normalize:B,coerce:!0,additionalCoerce:xc(),validators:c.map((ne)=>ne.params),sanitize:te})},createQuery(){return this.query?this.query:this.query=At(u.query,{modules:J,dynamic:j,models:I,normalize:B,coerce:!0,additionalCoerce:jk(),validators:c.map((ne)=>ne.query),sanitize:te})},createCookie(){return this.cookie?this.cookie:this.cookie=ie()},createResponse(){return this.response?this.response:this.response=gy(u.response,{modules:J,dynamic:j,models:I,normalize:B,validators:c.map((ne)=>ne.response),sanitize:te})}}};(l.body||l.cookie||l.headers||l.params||l.query||l.response)&&(o=ti(o,l)),o.tags&&(o.detail?o.detail.tags=o.tags:o.detail={tags:o.tags}),Ie(this.config.detail)&&(o.detail=Jt(Object.assign({},this.config.detail),o.detail));let p=Ie(this.event)?ti(this.event,rk(o)):{...i1(rk(o))};if(c.length&&Object.assign(p,{standaloneValidator:c}),this.config.aot===!1){let I=m();this.router.dynamic.add(t,r,{validator:I,hooks:p,content:o?.type,handle:n,route:r});let j=sc(r,{dynamic:!0});if(r!==j&&this.router.dynamic.add(t,j,{validator:I,hooks:p,content:o?.type,handle:n,route:r}),!this.config.strictPath){let B=ic(r);this.router.dynamic.add(t,B,{validator:I,hooks:p,content:o?.type,handle:n,route:r});let J=sc(B);B!==J&&this.router.dynamic.add(t,B,{validator:I,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 I=h.createNativeStaticHandler?.(n,p,{headers:Object.assign({},this.setHeaders)});return I instanceof Promise?I.then((j)=>{if(j)return j}):I?.()}:void 0,y=this.config.nativeStaticResponse===!0,b=(I)=>{!y||!g||(Bh?this.router.response[I]?this.router.response[I][t]=g():this.router.response[I]={[t]:g()}:this.router.response[I]=g())};b(r);let w,T=()=>{if(w)return w;let I=lF({app:this,path:r,method:t,hooks:p,validator:m(),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=I),I},S;if(`${t}_${r}`in this.routeTree)for(let I=0;I<this.router.history.length;I++){let j=this.router.history[I];if(j.path===r&&j.method===t){S=I;break}}else this.routeTree[`${t}_${r}`]=this.router.history.length;let A=S??this.router.history.length,E=this.router.history,O=d?T():(I)=>w?w(I):(E[A].composed=T())(I);S!==void 0?this.router.history[S]=Object.assign({method:t,path:r,composed:O,compile:T,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:O,compile:T,handler:n,hooks:p},o.webSocket?{websocket:o.websocket}:void 0));let v={handler:d?E[A].composed:void 0,compile(){return this.handler=T()}},D=this.router.static,L=r.indexOf(":")===-1&&r.indexOf("*")===-1;if(t==="WS"){if(L){r in D?D[r][t]=A:D[r]={[t]:A};return}this.router.http.add("WS",r,v),this.config.strictPath||this.router.http.add("WS",ic(r),v);let I=sc(r,{dynamic:!0});r!==I&&this.router.http.add("WS",I,v);return}if(L)r in D?D[r][t]=A:D[r]={[t]:A},this.config.strictPath||b(ic(r));else{if(this.router.http.add(t,r,v),!this.config.strictPath){let j=ic(r);b(j),this.router.http.add(t,j,v)}let I=sc(r,{dynamic:!0});r!==I&&(this.router.http.add(t,I,v),b(I))}}headers(t){return t?(this.setHeaders||(this.setHeaders={}),this.setHeaders=Jt(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",eF(n));return this}error(t,r){switch(typeof t){case"string":return r.prototype[ac]=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[ac]=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=Yt(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=hc({[o]:i.map((s)=>s.fn)},this.inference,this.config.sucrose));for(let s of i){let a=s1(s,"global",{skipIfHasType:!0});switch((this.config.name||this.config.seed)&&(a.checksum=Ki(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(Yt(a,"derive"));break;case"beforeHandle":this.event.beforeHandle??=[],this.event.beforeHandle.push(a);break;case"resolve":this.event.beforeHandle??=[],this.event.beforeHandle.push(Yt(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 $i(this.event.parse,t),$i(this.event.transform,t),$i(this.event.beforeHandle,t),$i(this.event.afterHandle,t),$i(this.event.mapResponse,t),$i(this.event.afterResponse,t),$i(this.event.trace,t),$i(this.event.error,t),t==="scoped"?(this.validator.scoped=ru(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=ru(this.validator.global,ru(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=Lh(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=Jt(this.singleton,o.singleton),this.definitions=Jt(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:m,query:p,params:h,cookie:g,response:y,...b}=r,w=u;this.applyMacro(b);let T=d||m||p||h||g||y;this.add(a,c,l,ti(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||T?[...b.standaloneValidator??[],...w.standaloneValidator??[],...T?[{body:d,headers:m,query:p,params:h,cookie:g,response:y}]:[]]:void 0}),void 0)}else this.add(a,c,l,ti(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=Jt(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=Lh(this.inference),n.extender={...this.extender},n.getServer=()=>this.getServer();let o=r(n);if(this.singleton=Jt(this.singleton,n.singleton),this.definitions=Jt(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:m,cookie:p,response:h,...g}=t,y=l||u||d||m||p||h;this.add(i,s,a,ti(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:m,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:m,...p}=t,h=a||c||l||u||d||m,g=i;i=n.router.history.length;for(let y=g;y<n.router.history.length;y++){let{method:b,path:w,handler:T,hooks:S}=n.router.history[y];this.add(b,w,T,ti(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:m}]: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),Ie(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?Ki(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 Ie(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){ik(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=oy(this.inference,t.inference),Ie(t.singleton.decorator)&&this.decorate(t.singleton.decorator),Ie(t.singleton.store)&&this.state(t.singleton.store),Ie(t.definitions.type)&&this.model(t.definitions.type),Ie(t.definitions.error)&&this.error(t.definitions.error),Ie(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?Ki(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}),Ie(t.event)&&(this.event=ZS(this.event,_S(t.event),o))}else Ie(t.event)&&(this.event=ZS(this.event,_S(t.event)));return t.validator.global&&(this.validator.global=ti(this.validator.global,{...t.validator.global})),t.validator.scoped&&(this.validator.local=ti(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=Ki(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 l1){a1(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=Jt(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(Oh(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(Oh(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||!Ie(n)?this:r?((r in this.singleton.store)?this.singleton.store[r]=Jt(this.singleton.store[r],n,{override:o==="override"}):this.singleton.store[r]=n,this):n===null?this:(this.singleton.store=Jt(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]=Jt(this.singleton.decorator[r],n,{override:o==="override"}):this.singleton.decorator[r]=n,this):n===null?this:(this.singleton.decorator=Jt(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=V.Module({...this.definitions.typebox.$defs,...o}),this;case"function":let s=t(this.definitions.type);return this.definitions.type=s,this.definitions.typebox=V.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=V.Module({...this.definitions.typebox.$defs,...a}),this}return r?(this.definitions.type[t]=r,("~standard"in r)?this:(this.definitions.typebox=V.Module({...this.definitions.typebox.$defs,[t]:r}),this)):this}Ref(t){return V.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?by(this):Xk(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=by(this),this)}get fetch(){let t=this.config.aot?by(this):Xk(this);return Object.defineProperty(this,"fetch",{value:t,configurable:!0,writable:!0}),t}get modules(){return this.promisedModules}},ro=ese;var ky={name:"@kabmo-labs/kabmo",version:"0.14.1",description:"Web console and diagnostic workbench for AI coding agents \u2014 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","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","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","@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","@xterm/addon-fit":"^0.11.0","@xterm/addon-webgl":"^0.19.0","@xterm/xterm":"^6.0.0",dompurify:"^3.4.15",elysia:"^1.4.30","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","read-excel-file":"^9.3.12",remend:"^1.3.1",ripgrep:"^0.3.1",shiki:"^4.4.3","smol-toml":"^1.9.1",tailwindcss:"^4.1.14",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 AF=KC("{\"index\":\"./dist/client/index.html\",\"files\":[{\"input\":\"../../index.html\",\"path\":\"./dist/client/static/js/index-w6jx0h0p.js\",\"loader\":\"js\",\"isEntry\":true,\"headers\":{\"etag\":\"nIbSvUDxwJY\",\"content-type\":\"text/javascript;charset=utf-8\"}},{\"input\":\"../../index.html\",\"path\":\"./dist/client/index.html\",\"loader\":\"html\",\"isEntry\":true,\"headers\":{\"etag\":\"iFkdlRSDfsA\",\"content-type\":\"text/html;charset=utf-8\"}},{\"input\":\"../../index.html\",\"path\":\"./dist/client/static/js/index-bnrrw242.css\",\"loader\":\"css\",\"isEntry\":true,\"headers\":{\"etag\":\"y1WYGLyipKI\",\"content-type\":\"text/css;charset=utf-8\"}},{\"input\":\"../../public/manifest.webmanifest\",\"path\":\"./dist/client/static/manifest-42r8wcmg.webmanifest\",\"loader\":\"file\",\"isEntry\":false,\"headers\":{\"etag\":\"xGK4yFzs1NA\",\"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 f(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 ae={"cache-control":"no-store"};import{brotliCompressSync as nse,constants as ose}from"zlib";function Ln(e){if(e.buffer instanceof ArrayBuffer)return e;return new Uint8Array(e)}var Zk=1024,EF=/^(text\/|application\/(json|javascript|xml|wasm|svg))/,ise=["zstd","br","gzip"];function RF(e){return EF.test(e)}function _k(e){if(!e)return null;for(let t of ise)if(e.includes(t))return t;return null}function ev(e,t){if(t==="zstd")return Ln(Bun.zstdCompressSync(e,{level:3}));if(t==="br")return Ln(nse(e,{params:{[ose.BROTLI_PARAM_QUALITY]:4}}));return Ln(Bun.gzipSync(e,{level:6}))}async function Gs(e,t){if(!t)return e;let r=e.headers.get("content-type")??"";if(r.includes("text/event-stream"))return e;if(!EF.test(r))return e;if(e.status===204||e.status===304)return e;let n=_k(t);if(!n)return e;let o=Ln(new Uint8Array(await e.arrayBuffer()));if(o.byteLength<Zk)return sse(e,o);let i=ev(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 sse(e,t){return new Response(t,{status:e.status,headers:e.headers})}function z(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:G});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 G=()=>tv();function tv(){return new Response(JSON.stringify({error:"Method not allowed"}),{status:405,headers:{"content-type":"application/json; charset=utf-8"}})}async function ci(e){try{return{ok:!0,body:await e.json()}}catch(t){return{ok:!1,error:t instanceof Error?t.message:String(t)}}}function gn(e,t){let r=e[t];return r?r:null}function Bn(e,t=500){return f({error:e instanceof Error?e.message:String(e)},{status:t})}async function ase(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 cse(e){return async({request:t,params:r})=>{try{let n=await ase(await e({request:t,params:r}));return await Gs(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 PF(e,t){let r=e;for(let{method:n,path:o,handler:i}of t){let s=cse(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 Rt(e,t,r){return[{method:"GET",path:t,handler:r??G},...["POST","PUT","PATCH","DELETE"].map((n)=>({method:n,path:t,handler:e}))]}import{existsSync as rv,realpathSync as lse}from"fs";import{homedir as IF,tmpdir as LGe}from"os";import*as qt from"path";var CF="omp",use=".omp";function MF(){return Bun.env.PI_CONFIG_DIR||use}function Un(){return qt.join(IF(),MF())}function le(){let e=Bun.env.PI_CODING_AGENT_DIR;if(e)return qt.resolve(e);return qt.join(Un(),"agent")}function OF(){let e=Bun.env.PI_CODING_AGENT_DIR;if(e)return qt.resolve(e)===qt.join(Un(),"agent");return!0}function dse(){if(process.platform!=="linux"&&process.platform!=="darwin")return;if(!OF())return;let e=Bun.env.XDG_DATA_HOME;if(!e)return;try{let t=qt.join(e,CF);return rv(t)?t:void 0}catch{return}}function pse(e){let t=dse();return qt.join(t??le(),e)}function no(){return pse("sessions")}function NF(){return qt.join(le(),"projects.json")}function FF(){if(process.platform!=="linux"&&process.platform!=="darwin")return Un();if(!OF())return Un();let e=Bun.env.XDG_DATA_HOME;if(!e)return Un();try{let t=qt.join(e,CF);return rv(t)?t:Un()}catch{return Un()}}function DF(){return qt.join(FF(),"plugins")}function nv(){return qt.join(FF(),"marketplaces.json")}function LF(e){let t=IF(),r=MF(),n=qt.resolve(e);for(let o of[r,".git"]){let i=n;while(i!==t){if(rv(qt.join(i,o)))return qt.join(i,r,"plugins");let s=qt.dirname(i);if(s===i)break;i=s}}return qt.join(n,r,"plugins")}function vy(e){try{return lse.native(e)}catch{return e}}async function Y(e){try{return await Bun.file(e).stat(),!0}catch{return!1}}function Su(e){let t=vy(e);return t.replace(/\/+$/,"")||t}import iv from"fs";import*as Ay from"path";function k(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function fr(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 BF(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 mr(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 BF(e.slice(s,c))}return BF(e.slice(s))}function jF(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(mr(e,"type",n)==="message")t++;r=o+1}return t}function UF(e){if(e===void 0)return;return e.trim()?e:null}function mse(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 fse(e,t){if(mr(e,"type")!=="session")return;let r=mr(e,"id");if(!r)return;return{id:r,cwd:mr(e,"cwd"),title:t===null?void 0:t??mr(e,"title"),parentSession:mr(e,"parentSession"),timestamp:mr(e,"timestamp")}}function WF(e,t){let r=t[0],n=UF(r?.type==="title"&&typeof r.title==="string"?r.title:void 0),o=mse(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&&mr(c,"type")==="title"){i=UF(mr(c,"title")),s=!1;continue}return fse(c,i)}return}var ov=4096,gse=16384,HF=1048576;async function KF(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 hse={session_exit:!0};function yse(e){let t,r,n,o=!1;try{let a=JSON.parse(e);if(k(a))o=!0,t=a.type,r=a.customType,n=a.timestamp}catch{}if(!o)n=mr(e,"timestamp"),t=mr(e,"type"),r=mr(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"&&hse[r]===!0;return{at:i,lifecycle:s}}async function qF(e,t,r){if(t<=0)return;let n=gse;for(;;){let o=Math.max(0,t-n),i;if(t<=ov)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=yse(c);if(l&&!l.lifecycle)return l.at}if(o===0||n>=HF)return;n=Math.min(n*4,HF)}}var $F=/User invoked the \\?"([^"\\]+)\\?" skill/,Ty="skill-prompt";function VF(e){if(typeof e==="string")return e;if(!Array.isArray(e))return"";return e.map((t)=>k(t)&&typeof t.text==="string"?t.text:"").join("")}function GF(e,t){let r=e.trim();if(!r)return"";let n=t?.trim();return n?`/skill:${r} ${n}`:`/skill:${r}`}function um(e){if(e.type==="custom_message"&&e.customType===Ty){if(e.attribution!==void 0&&e.attribution!=="user")return;let r=k(e.details)?e.details:void 0,n=typeof r?.name==="string"?r.name:$F.exec(VF(e.content))?.[1];if(!n)return;let o=typeof r?.args==="string"?r.args:void 0;return GF(n,o)||void 0}if(e.type!=="message")return;let t=k(e.message)?e.message:void 0;if(!t||t.role!=="user")return;return VF(t.content).trim()||void 0}function zF(e){let t,r=e.indexOf('"role"');while(r!==-1){let o=mr(e,"role",r),i=mr(e,"content",r)??mr(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(mr(e,"customType",n)===Ty){let o=$F.exec(e.slice(n))?.[1];if(o)return GF(o)}n=e.indexOf('"customType"',n+12)}return t}var vc=256;async function YF(e){try{let{text:t,size:r,mtime:n,mtimeMs:o}=await KF(e,ov),i=await qF(e,r,t),s=fr(t),a=WF(t,s);if(!a)return;let c=0,l="",u;for(let d=1;d<s.length;d++){let m=s[d];if(m.type==="compaction"&&typeof m.shortSummary==="string")u=m.shortSummary;if(m.type==="message"&&m.message)c++;if(!l){let p=um(m);if(p)l=p}}return l||=zF(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,jF(t)),size:r,firstMessage:l||"(no messages)"}}catch{return}}var JF=3,bse=2048;async function sv(e=no()){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 iv.promises.readdir(e,{withFileTypes:!0})){if(!a.isDirectory())continue;try{let c=await Bun.file(Ay.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 iv.promises.readdir(e,{withFileTypes:!0})}catch{}for(let s of i){if(!s.isDirectory())continue;let a=Ay.join(e,s.name);try{o.set(s.name,(await Bun.file(a).stat()).mtimeMs)}catch{continue}let c=[];try{c=await iv.promises.readdir(a,{withFileTypes:!0})}catch{continue}for(let l of c){if(!l.isFile()||!l.name.endsWith(".jsonl"))continue;n.push(Ay.join(a,l.name))}}return t.set(e,{dirMtimes:o,files:n}),globalThis.__kabmoSessionIdIndex?.delete(e),n}function wse(){let e=globalThis.__kabmoSessionScanCache;if(e&&e.version===JF)return e.entries;let t={version:JF,entries:new Map};return globalThis.__kabmoSessionScanCache=t,t.entries}async function dm(e){let t;try{t=await Bun.file(e).stat()}catch{return}let r=wse(),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 YF(e);if(o){r.set(e,o);while(r.size>bse){let i=r.keys().next().value;if(i===void 0)break;r.delete(i)}}return o}async function xse(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 Sse=32;async function av(e=no()){let t=await sv(e),r=await xse(t,Sse,(o)=>dm(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 cv(e=no()){let t=globalThis.__kabmoSessionIdIndex??=new Map,r=t.get(e);if(r)return r.entries;let n=new Map;for(let o of await av(e))if(!n.has(o.id))n.set(o.id,o.path);return t.set(e,{entries:n}),n}function Pt(){globalThis.__kabmoSessionFileListCache?.clear(),globalThis.__kabmoSessionScanCache?.entries.clear(),globalThis.__kabmoSessionIdIndex?.clear()}async function ku(e){try{let r=(await Bun.file(e).slice(0,vc+4096).text()).split(`
|