@cuongtran001/kanna 0.53.0 → 0.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/assets/{index-CJAUmjXp.js → index-D-7AB5Mj.js} +3 -3
- package/dist/client/assets/{index-CFtYHyY0.js → index-D_O0RuN1.js} +1 -1
- package/dist/client/index.html +1 -1
- package/package.json +1 -1
- package/src/server/agent.oauth-release.test.ts +192 -0
- package/src/server/agent.oauth-rotation.test.ts +104 -0
- package/src/server/agent.test.ts +135 -0
- package/src/server/agent.ts +124 -9
- package/src/server/codex-app-server-protocol.ts +17 -0
- package/src/server/codex-app-server.test.ts +226 -0
- package/src/server/codex-app-server.ts +96 -4
|
@@ -692,7 +692,7 @@ Please change the parent <Route path="${C}"> to <Route path="${C==="/"?"*":`${C}
|
|
|
692
692
|
|
|
693
693
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
694
694
|
|
|
695
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return v.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},Bq="DialogDescriptionWarning",Fq=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${E5(Bq).contentName}}.`;return v.useEffect(()=>{var s;const i=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&i&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},R5=h5,T5=g5,UC=v5,VC=b5,A5=_5,$q=S5,Hq=C5;function N5(e){var t,n,r="";if(typeof e=="string"||typeof e=="number")r+=e;else if(typeof e=="object")if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=N5(e[t]))&&(r&&(r+=" "),r+=n)}else for(n in e)e[n]&&(r&&(r+=" "),r+=n);return r}function M5(){for(var e,t,n=0,r="",i=arguments.length;n<i;n++)(e=arguments[n])&&(t=N5(e))&&(r&&(r+=" "),r+=t);return r}const Uq=(e,t)=>{const n=new Array(e.length+t.length);for(let r=0;r<e.length;r++)n[r]=e[r];for(let r=0;r<t.length;r++)n[e.length+r]=t[r];return n},Vq=(e,t)=>({classGroupId:e,validator:t}),L5=(e=new Map,t=null,n)=>({nextPart:e,validators:t,classGroupId:n}),Kv="-",NN=[],Wq="arbitrary..",Gq=e=>{const t=Kq(e),{conflictingClassGroups:n,conflictingClassGroupModifiers:r}=e;return{getClassGroupId:o=>{if(o.startsWith("[")&&o.endsWith("]"))return qq(o);const l=o.split(Kv),c=l[0]===""&&l.length>1?1:0;return I5(l,c,t)},getConflictingClassGroupIds:(o,l)=>{if(l){const c=r[o],u=n[o];return c?u?Uq(u,c):c:u||NN}return n[o]||NN}}},I5=(e,t,n)=>{if(e.length-t===0)return n.classGroupId;const i=e[t],s=n.nextPart.get(i);if(s){const u=I5(e,t+1,s);if(u)return u}const o=n.validators;if(o===null)return;const l=t===0?e.join(Kv):e.slice(t).join(Kv),c=o.length;for(let u=0;u<c;u++){const p=o[u];if(p.validator(l))return p.classGroupId}},qq=e=>e.slice(1,-1).indexOf(":")===-1?void 0:(()=>{const t=e.slice(1,-1),n=t.indexOf(":"),r=t.slice(0,n);return r?Wq+r:void 0})(),Kq=e=>{const{theme:t,classGroups:n}=e;return Yq(n,t)},Yq=(e,t)=>{const n=L5();for(const r in e){const i=e[r];WC(i,n,r,t)}return n},WC=(e,t,n,r)=>{const i=e.length;for(let s=0;s<i;s++){const o=e[s];Xq(o,t,n,r)}},Xq=(e,t,n,r)=>{if(typeof e=="string"){Qq(e,t,n);return}if(typeof e=="function"){Zq(e,t,n,r);return}Jq(e,t,n,r)},Qq=(e,t,n)=>{const r=e===""?t:j5(t,e);r.classGroupId=n},Zq=(e,t,n,r)=>{if(eK(e)){WC(e(r),t,n,r);return}t.validators===null&&(t.validators=[]),t.validators.push(Vq(n,e))},Jq=(e,t,n,r)=>{const i=Object.entries(e),s=i.length;for(let o=0;o<s;o++){const[l,c]=i[o];WC(c,j5(t,l),n,r)}},j5=(e,t)=>{let n=e;const r=t.split(Kv),i=r.length;for(let s=0;s<i;s++){const o=r[s];let l=n.nextPart.get(o);l||(l=L5(),n.nextPart.set(o,l)),n=l}return n},eK=e=>"isThemeGetter"in e&&e.isThemeGetter===!0,tK=e=>{if(e<1)return{get:()=>{},set:()=>{}};let t=0,n=Object.create(null),r=Object.create(null);const i=(s,o)=>{n[s]=o,t++,t>e&&(t=0,r=n,n=Object.create(null))};return{get(s){let o=n[s];if(o!==void 0)return o;if((o=r[s])!==void 0)return i(s,o),o},set(s,o){s in n?n[s]=o:i(s,o)}}},hw="!",MN=":",nK=[],LN=(e,t,n,r,i)=>({modifiers:e,hasImportantModifier:t,baseClassName:n,maybePostfixModifierPosition:r,isExternal:i}),rK=e=>{const{prefix:t,experimentalParseClassName:n}=e;let r=i=>{const s=[];let o=0,l=0,c=0,u;const p=i.length;for(let x=0;x<p;x++){const S=i[x];if(o===0&&l===0){if(S===MN){s.push(i.slice(c,x)),c=x+1;continue}if(S==="/"){u=x;continue}}S==="["?o++:S==="]"?o--:S==="("?l++:S===")"&&l--}const h=s.length===0?i:i.slice(c);let g=h,b=!1;h.endsWith(hw)?(g=h.slice(0,-1),b=!0):h.startsWith(hw)&&(g=h.slice(1),b=!0);const _=u&&u>c?u-c:void 0;return LN(s,b,g,_)};if(t){const i=t+MN,s=r;r=o=>o.startsWith(i)?s(o.slice(i.length)):LN(nK,!1,o,void 0,!0)}if(n){const i=r;r=s=>n({className:s,parseClassName:i})}return r},iK=e=>{const t=new Map;return e.orderSensitiveModifiers.forEach((n,r)=>{t.set(n,1e6+r)}),n=>{const r=[];let i=[];for(let s=0;s<n.length;s++){const o=n[s],l=o[0]==="[",c=t.has(o);l||c?(i.length>0&&(i.sort(),r.push(...i),i=[]),r.push(o)):i.push(o)}return i.length>0&&(i.sort(),r.push(...i)),r}},sK=e=>({cache:tK(e.cacheSize),parseClassName:rK(e),sortModifiers:iK(e),...Gq(e)}),oK=/\s+/,aK=(e,t)=>{const{parseClassName:n,getClassGroupId:r,getConflictingClassGroupIds:i,sortModifiers:s}=t,o=[],l=e.trim().split(oK);let c="";for(let u=l.length-1;u>=0;u-=1){const p=l[u],{isExternal:h,modifiers:g,hasImportantModifier:b,baseClassName:_,maybePostfixModifierPosition:x}=n(p);if(h){c=p+(c.length>0?" "+c:c);continue}let S=!!x,C=r(S?_.substring(0,x):_);if(!C){if(!S){c=p+(c.length>0?" "+c:c);continue}if(C=r(_),!C){c=p+(c.length>0?" "+c:c);continue}S=!1}const E=g.length===0?"":g.length===1?g[0]:s(g).join(":"),k=b?E+hw:E,T=k+C;if(o.indexOf(T)>-1)continue;o.push(T);const A=i(C,S);for(let N=0;N<A.length;++N){const M=A[N];o.push(k+M)}c=p+(c.length>0?" "+c:c)}return c},lK=(...e)=>{let t=0,n,r,i="";for(;t<e.length;)(n=e[t++])&&(r=D5(n))&&(i&&(i+=" "),i+=r);return i},D5=e=>{if(typeof e=="string")return e;let t,n="";for(let r=0;r<e.length;r++)e[r]&&(t=D5(e[r]))&&(n&&(n+=" "),n+=t);return n},cK=(e,...t)=>{let n,r,i,s;const o=c=>{const u=t.reduce((p,h)=>h(p),e());return n=sK(u),r=n.cache.get,i=n.cache.set,s=l,l(c)},l=c=>{const u=r(c);if(u)return u;const p=aK(c,n);return i(c,p),p};return s=o,(...c)=>s(lK(...c))},uK=[],yr=e=>{const t=n=>n[e]||uK;return t.isThemeGetter=!0,t},P5=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,O5=/^\((?:(\w[\w-]*):)?(.+)\)$/i,dK=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,fK=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,hK=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,pK=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,mK=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,gK=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,el=e=>dK.test(e),qt=e=>!!e&&!Number.isNaN(Number(e)),tl=e=>!!e&&Number.isInteger(Number(e)),kx=e=>e.endsWith("%")&&qt(e.slice(0,-1)),Zo=e=>fK.test(e),z5=()=>!0,vK=e=>hK.test(e)&&!pK.test(e),GC=()=>!1,bK=e=>mK.test(e),yK=e=>gK.test(e),_K=e=>!at(e)&&!ct(e),xK=e=>Ll(e,$5,GC),at=e=>P5.test(e),sc=e=>Ll(e,H5,vK),IN=e=>Ll(e,AK,qt),SK=e=>Ll(e,V5,z5),wK=e=>Ll(e,U5,GC),jN=e=>Ll(e,B5,GC),CK=e=>Ll(e,F5,yK),yg=e=>Ll(e,W5,bK),ct=e=>O5.test(e),eh=e=>Vc(e,H5),kK=e=>Vc(e,U5),DN=e=>Vc(e,B5),EK=e=>Vc(e,$5),RK=e=>Vc(e,F5),_g=e=>Vc(e,W5,!0),TK=e=>Vc(e,V5,!0),Ll=(e,t,n)=>{const r=P5.exec(e);return r?r[1]?t(r[1]):n(r[2]):!1},Vc=(e,t,n=!1)=>{const r=O5.exec(e);return r?r[1]?t(r[1]):n:!1},B5=e=>e==="position"||e==="percentage",F5=e=>e==="image"||e==="url",$5=e=>e==="length"||e==="size"||e==="bg-size",H5=e=>e==="length",AK=e=>e==="number",U5=e=>e==="family-name",V5=e=>e==="number"||e==="weight",W5=e=>e==="shadow",NK=()=>{const e=yr("color"),t=yr("font"),n=yr("text"),r=yr("font-weight"),i=yr("tracking"),s=yr("leading"),o=yr("breakpoint"),l=yr("container"),c=yr("spacing"),u=yr("radius"),p=yr("shadow"),h=yr("inset-shadow"),g=yr("text-shadow"),b=yr("drop-shadow"),_=yr("blur"),x=yr("perspective"),S=yr("aspect"),C=yr("ease"),E=yr("animate"),k=()=>["auto","avoid","all","avoid-page","page","left","right","column"],T=()=>["center","top","bottom","left","right","top-left","left-top","top-right","right-top","bottom-right","right-bottom","bottom-left","left-bottom"],A=()=>[...T(),ct,at],N=()=>["auto","hidden","clip","visible","scroll"],M=()=>["auto","contain","none"],j=()=>[ct,at,c],U=()=>[el,"full","auto",...j()],I=()=>[tl,"none","subgrid",ct,at],P=()=>["auto",{span:["full",tl,ct,at]},tl,ct,at],z=()=>[tl,"auto",ct,at],O=()=>["auto","min","max","fr",ct,at],$=()=>["start","end","center","between","around","evenly","stretch","baseline","center-safe","end-safe"],V=()=>["start","end","center","stretch","center-safe","end-safe"],F=()=>["auto",...j()],H=()=>[el,"auto","full","dvw","dvh","lvw","lvh","svw","svh","min","max","fit",...j()],W=()=>[el,"screen","full","dvw","lvw","svw","min","max","fit",...j()],Z=()=>[el,"screen","full","lh","dvh","lvh","svh","min","max","fit",...j()],D=()=>[e,ct,at],G=()=>[...T(),DN,jN,{position:[ct,at]}],ee=()=>["no-repeat",{repeat:["","x","y","space","round"]}],B=()=>["auto","cover","contain",EK,xK,{size:[ct,at]}],le=()=>[kx,eh,sc],oe=()=>["","none","full",u,ct,at],J=()=>["",qt,eh,sc],ne=()=>["solid","dashed","dotted","double"],se=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],ce=()=>[qt,kx,DN,jN],de=()=>["","none",_,ct,at],Ne=()=>["none",qt,ct,at],we=()=>["none",qt,ct,at],je=()=>[qt,ct,at],fe=()=>[el,"full",...j()];return{cacheSize:500,theme:{animate:["spin","ping","pulse","bounce"],aspect:["video"],blur:[Zo],breakpoint:[Zo],color:[z5],container:[Zo],"drop-shadow":[Zo],ease:["in","out","in-out"],font:[_K],"font-weight":["thin","extralight","light","normal","medium","semibold","bold","extrabold","black"],"inset-shadow":[Zo],leading:["none","tight","snug","normal","relaxed","loose"],perspective:["dramatic","near","normal","midrange","distant","none"],radius:[Zo],shadow:[Zo],spacing:["px",qt],text:[Zo],"text-shadow":[Zo],tracking:["tighter","tight","normal","wide","wider","widest"]},classGroups:{aspect:[{aspect:["auto","square",el,at,ct,S]}],container:["container"],columns:[{columns:[qt,at,ct,l]}],"break-after":[{"break-after":k()}],"break-before":[{"break-before":k()}],"break-inside":[{"break-inside":["auto","avoid","avoid-page","avoid-column"]}],"box-decoration":[{"box-decoration":["slice","clone"]}],box:[{box:["border","content"]}],display:["block","inline-block","inline","flex","inline-flex","table","inline-table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row-group","table-row","flow-root","grid","inline-grid","contents","list-item","hidden"],sr:["sr-only","not-sr-only"],float:[{float:["right","left","none","start","end"]}],clear:[{clear:["left","right","both","none","start","end"]}],isolation:["isolate","isolation-auto"],"object-fit":[{object:["contain","cover","fill","none","scale-down"]}],"object-position":[{object:A()}],overflow:[{overflow:N()}],"overflow-x":[{"overflow-x":N()}],"overflow-y":[{"overflow-y":N()}],overscroll:[{overscroll:M()}],"overscroll-x":[{"overscroll-x":M()}],"overscroll-y":[{"overscroll-y":M()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:U()}],"inset-x":[{"inset-x":U()}],"inset-y":[{"inset-y":U()}],start:[{"inset-s":U(),start:U()}],end:[{"inset-e":U(),end:U()}],"inset-bs":[{"inset-bs":U()}],"inset-be":[{"inset-be":U()}],top:[{top:U()}],right:[{right:U()}],bottom:[{bottom:U()}],left:[{left:U()}],visibility:["visible","invisible","collapse"],z:[{z:[tl,"auto",ct,at]}],basis:[{basis:[el,"full","auto",l,...j()]}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["nowrap","wrap","wrap-reverse"]}],flex:[{flex:[qt,el,"auto","initial","none",at]}],grow:[{grow:["",qt,ct,at]}],shrink:[{shrink:["",qt,ct,at]}],order:[{order:[tl,"first","last","none",ct,at]}],"grid-cols":[{"grid-cols":I()}],"col-start-end":[{col:P()}],"col-start":[{"col-start":z()}],"col-end":[{"col-end":z()}],"grid-rows":[{"grid-rows":I()}],"row-start-end":[{row:P()}],"row-start":[{"row-start":z()}],"row-end":[{"row-end":z()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":O()}],"auto-rows":[{"auto-rows":O()}],gap:[{gap:j()}],"gap-x":[{"gap-x":j()}],"gap-y":[{"gap-y":j()}],"justify-content":[{justify:[...$(),"normal"]}],"justify-items":[{"justify-items":[...V(),"normal"]}],"justify-self":[{"justify-self":["auto",...V()]}],"align-content":[{content:["normal",...$()]}],"align-items":[{items:[...V(),{baseline:["","last"]}]}],"align-self":[{self:["auto",...V(),{baseline:["","last"]}]}],"place-content":[{"place-content":$()}],"place-items":[{"place-items":[...V(),"baseline"]}],"place-self":[{"place-self":["auto",...V()]}],p:[{p:j()}],px:[{px:j()}],py:[{py:j()}],ps:[{ps:j()}],pe:[{pe:j()}],pbs:[{pbs:j()}],pbe:[{pbe:j()}],pt:[{pt:j()}],pr:[{pr:j()}],pb:[{pb:j()}],pl:[{pl:j()}],m:[{m:F()}],mx:[{mx:F()}],my:[{my:F()}],ms:[{ms:F()}],me:[{me:F()}],mbs:[{mbs:F()}],mbe:[{mbe:F()}],mt:[{mt:F()}],mr:[{mr:F()}],mb:[{mb:F()}],ml:[{ml:F()}],"space-x":[{"space-x":j()}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":j()}],"space-y-reverse":["space-y-reverse"],size:[{size:H()}],"inline-size":[{inline:["auto",...W()]}],"min-inline-size":[{"min-inline":["auto",...W()]}],"max-inline-size":[{"max-inline":["none",...W()]}],"block-size":[{block:["auto",...Z()]}],"min-block-size":[{"min-block":["auto",...Z()]}],"max-block-size":[{"max-block":["none",...Z()]}],w:[{w:[l,"screen",...H()]}],"min-w":[{"min-w":[l,"screen","none",...H()]}],"max-w":[{"max-w":[l,"screen","none","prose",{screen:[o]},...H()]}],h:[{h:["screen","lh",...H()]}],"min-h":[{"min-h":["screen","lh","none",...H()]}],"max-h":[{"max-h":["screen","lh",...H()]}],"font-size":[{text:["base",n,eh,sc]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:[r,TK,SK]}],"font-stretch":[{"font-stretch":["ultra-condensed","extra-condensed","condensed","semi-condensed","normal","semi-expanded","expanded","extra-expanded","ultra-expanded",kx,at]}],"font-family":[{font:[kK,wK,t]}],"font-features":[{"font-features":[at]}],"fvn-normal":["normal-nums"],"fvn-ordinal":["ordinal"],"fvn-slashed-zero":["slashed-zero"],"fvn-figure":["lining-nums","oldstyle-nums"],"fvn-spacing":["proportional-nums","tabular-nums"],"fvn-fraction":["diagonal-fractions","stacked-fractions"],tracking:[{tracking:[i,ct,at]}],"line-clamp":[{"line-clamp":[qt,"none",ct,IN]}],leading:[{leading:[s,...j()]}],"list-image":[{"list-image":["none",ct,at]}],"list-style-position":[{list:["inside","outside"]}],"list-style-type":[{list:["disc","decimal","none",ct,at]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"placeholder-color":[{placeholder:D()}],"text-color":[{text:D()}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...ne(),"wavy"]}],"text-decoration-thickness":[{decoration:[qt,"from-font","auto",ct,sc]}],"text-decoration-color":[{decoration:D()}],"underline-offset":[{"underline-offset":[qt,"auto",ct,at]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:j()}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",ct,at]}],whitespace:[{whitespace:["normal","nowrap","pre","pre-line","pre-wrap","break-spaces"]}],break:[{break:["normal","words","all","keep"]}],wrap:[{wrap:["break-word","anywhere","normal"]}],hyphens:[{hyphens:["none","manual","auto"]}],content:[{content:["none",ct,at]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:G()}],"bg-repeat":[{bg:ee()}],"bg-size":[{bg:B()}],"bg-image":[{bg:["none",{linear:[{to:["t","tr","r","br","b","bl","l","tl"]},tl,ct,at],radial:["",ct,at],conic:[tl,ct,at]},RK,CK]}],"bg-color":[{bg:D()}],"gradient-from-pos":[{from:le()}],"gradient-via-pos":[{via:le()}],"gradient-to-pos":[{to:le()}],"gradient-from":[{from:D()}],"gradient-via":[{via:D()}],"gradient-to":[{to:D()}],rounded:[{rounded:oe()}],"rounded-s":[{"rounded-s":oe()}],"rounded-e":[{"rounded-e":oe()}],"rounded-t":[{"rounded-t":oe()}],"rounded-r":[{"rounded-r":oe()}],"rounded-b":[{"rounded-b":oe()}],"rounded-l":[{"rounded-l":oe()}],"rounded-ss":[{"rounded-ss":oe()}],"rounded-se":[{"rounded-se":oe()}],"rounded-ee":[{"rounded-ee":oe()}],"rounded-es":[{"rounded-es":oe()}],"rounded-tl":[{"rounded-tl":oe()}],"rounded-tr":[{"rounded-tr":oe()}],"rounded-br":[{"rounded-br":oe()}],"rounded-bl":[{"rounded-bl":oe()}],"border-w":[{border:J()}],"border-w-x":[{"border-x":J()}],"border-w-y":[{"border-y":J()}],"border-w-s":[{"border-s":J()}],"border-w-e":[{"border-e":J()}],"border-w-bs":[{"border-bs":J()}],"border-w-be":[{"border-be":J()}],"border-w-t":[{"border-t":J()}],"border-w-r":[{"border-r":J()}],"border-w-b":[{"border-b":J()}],"border-w-l":[{"border-l":J()}],"divide-x":[{"divide-x":J()}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":J()}],"divide-y-reverse":["divide-y-reverse"],"border-style":[{border:[...ne(),"hidden","none"]}],"divide-style":[{divide:[...ne(),"hidden","none"]}],"border-color":[{border:D()}],"border-color-x":[{"border-x":D()}],"border-color-y":[{"border-y":D()}],"border-color-s":[{"border-s":D()}],"border-color-e":[{"border-e":D()}],"border-color-bs":[{"border-bs":D()}],"border-color-be":[{"border-be":D()}],"border-color-t":[{"border-t":D()}],"border-color-r":[{"border-r":D()}],"border-color-b":[{"border-b":D()}],"border-color-l":[{"border-l":D()}],"divide-color":[{divide:D()}],"outline-style":[{outline:[...ne(),"none","hidden"]}],"outline-offset":[{"outline-offset":[qt,ct,at]}],"outline-w":[{outline:["",qt,eh,sc]}],"outline-color":[{outline:D()}],shadow:[{shadow:["","none",p,_g,yg]}],"shadow-color":[{shadow:D()}],"inset-shadow":[{"inset-shadow":["none",h,_g,yg]}],"inset-shadow-color":[{"inset-shadow":D()}],"ring-w":[{ring:J()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:D()}],"ring-offset-w":[{"ring-offset":[qt,sc]}],"ring-offset-color":[{"ring-offset":D()}],"inset-ring-w":[{"inset-ring":J()}],"inset-ring-color":[{"inset-ring":D()}],"text-shadow":[{"text-shadow":["none",g,_g,yg]}],"text-shadow-color":[{"text-shadow":D()}],opacity:[{opacity:[qt,ct,at]}],"mix-blend":[{"mix-blend":[...se(),"plus-darker","plus-lighter"]}],"bg-blend":[{"bg-blend":se()}],"mask-clip":[{"mask-clip":["border","padding","content","fill","stroke","view"]},"mask-no-clip"],"mask-composite":[{mask:["add","subtract","intersect","exclude"]}],"mask-image-linear-pos":[{"mask-linear":[qt]}],"mask-image-linear-from-pos":[{"mask-linear-from":ce()}],"mask-image-linear-to-pos":[{"mask-linear-to":ce()}],"mask-image-linear-from-color":[{"mask-linear-from":D()}],"mask-image-linear-to-color":[{"mask-linear-to":D()}],"mask-image-t-from-pos":[{"mask-t-from":ce()}],"mask-image-t-to-pos":[{"mask-t-to":ce()}],"mask-image-t-from-color":[{"mask-t-from":D()}],"mask-image-t-to-color":[{"mask-t-to":D()}],"mask-image-r-from-pos":[{"mask-r-from":ce()}],"mask-image-r-to-pos":[{"mask-r-to":ce()}],"mask-image-r-from-color":[{"mask-r-from":D()}],"mask-image-r-to-color":[{"mask-r-to":D()}],"mask-image-b-from-pos":[{"mask-b-from":ce()}],"mask-image-b-to-pos":[{"mask-b-to":ce()}],"mask-image-b-from-color":[{"mask-b-from":D()}],"mask-image-b-to-color":[{"mask-b-to":D()}],"mask-image-l-from-pos":[{"mask-l-from":ce()}],"mask-image-l-to-pos":[{"mask-l-to":ce()}],"mask-image-l-from-color":[{"mask-l-from":D()}],"mask-image-l-to-color":[{"mask-l-to":D()}],"mask-image-x-from-pos":[{"mask-x-from":ce()}],"mask-image-x-to-pos":[{"mask-x-to":ce()}],"mask-image-x-from-color":[{"mask-x-from":D()}],"mask-image-x-to-color":[{"mask-x-to":D()}],"mask-image-y-from-pos":[{"mask-y-from":ce()}],"mask-image-y-to-pos":[{"mask-y-to":ce()}],"mask-image-y-from-color":[{"mask-y-from":D()}],"mask-image-y-to-color":[{"mask-y-to":D()}],"mask-image-radial":[{"mask-radial":[ct,at]}],"mask-image-radial-from-pos":[{"mask-radial-from":ce()}],"mask-image-radial-to-pos":[{"mask-radial-to":ce()}],"mask-image-radial-from-color":[{"mask-radial-from":D()}],"mask-image-radial-to-color":[{"mask-radial-to":D()}],"mask-image-radial-shape":[{"mask-radial":["circle","ellipse"]}],"mask-image-radial-size":[{"mask-radial":[{closest:["side","corner"],farthest:["side","corner"]}]}],"mask-image-radial-pos":[{"mask-radial-at":T()}],"mask-image-conic-pos":[{"mask-conic":[qt]}],"mask-image-conic-from-pos":[{"mask-conic-from":ce()}],"mask-image-conic-to-pos":[{"mask-conic-to":ce()}],"mask-image-conic-from-color":[{"mask-conic-from":D()}],"mask-image-conic-to-color":[{"mask-conic-to":D()}],"mask-mode":[{mask:["alpha","luminance","match"]}],"mask-origin":[{"mask-origin":["border","padding","content","fill","stroke","view"]}],"mask-position":[{mask:G()}],"mask-repeat":[{mask:ee()}],"mask-size":[{mask:B()}],"mask-type":[{"mask-type":["alpha","luminance"]}],"mask-image":[{mask:["none",ct,at]}],filter:[{filter:["","none",ct,at]}],blur:[{blur:de()}],brightness:[{brightness:[qt,ct,at]}],contrast:[{contrast:[qt,ct,at]}],"drop-shadow":[{"drop-shadow":["","none",b,_g,yg]}],"drop-shadow-color":[{"drop-shadow":D()}],grayscale:[{grayscale:["",qt,ct,at]}],"hue-rotate":[{"hue-rotate":[qt,ct,at]}],invert:[{invert:["",qt,ct,at]}],saturate:[{saturate:[qt,ct,at]}],sepia:[{sepia:["",qt,ct,at]}],"backdrop-filter":[{"backdrop-filter":["","none",ct,at]}],"backdrop-blur":[{"backdrop-blur":de()}],"backdrop-brightness":[{"backdrop-brightness":[qt,ct,at]}],"backdrop-contrast":[{"backdrop-contrast":[qt,ct,at]}],"backdrop-grayscale":[{"backdrop-grayscale":["",qt,ct,at]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[qt,ct,at]}],"backdrop-invert":[{"backdrop-invert":["",qt,ct,at]}],"backdrop-opacity":[{"backdrop-opacity":[qt,ct,at]}],"backdrop-saturate":[{"backdrop-saturate":[qt,ct,at]}],"backdrop-sepia":[{"backdrop-sepia":["",qt,ct,at]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":j()}],"border-spacing-x":[{"border-spacing-x":j()}],"border-spacing-y":[{"border-spacing-y":j()}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["","all","colors","opacity","shadow","transform","none",ct,at]}],"transition-behavior":[{transition:["normal","discrete"]}],duration:[{duration:[qt,"initial",ct,at]}],ease:[{ease:["linear","initial",C,ct,at]}],delay:[{delay:[qt,ct,at]}],animate:[{animate:["none",E,ct,at]}],backface:[{backface:["hidden","visible"]}],perspective:[{perspective:[x,ct,at]}],"perspective-origin":[{"perspective-origin":A()}],rotate:[{rotate:Ne()}],"rotate-x":[{"rotate-x":Ne()}],"rotate-y":[{"rotate-y":Ne()}],"rotate-z":[{"rotate-z":Ne()}],scale:[{scale:we()}],"scale-x":[{"scale-x":we()}],"scale-y":[{"scale-y":we()}],"scale-z":[{"scale-z":we()}],"scale-3d":["scale-3d"],skew:[{skew:je()}],"skew-x":[{"skew-x":je()}],"skew-y":[{"skew-y":je()}],transform:[{transform:[ct,at,"","none","gpu","cpu"]}],"transform-origin":[{origin:A()}],"transform-style":[{transform:["3d","flat"]}],translate:[{translate:fe()}],"translate-x":[{"translate-x":fe()}],"translate-y":[{"translate-y":fe()}],"translate-z":[{"translate-z":fe()}],"translate-none":["translate-none"],accent:[{accent:D()}],appearance:[{appearance:["none","auto"]}],"caret-color":[{caret:D()}],"color-scheme":[{scheme:["normal","dark","light","light-dark","only-dark","only-light"]}],cursor:[{cursor:["auto","default","pointer","wait","text","move","help","not-allowed","none","context-menu","progress","cell","crosshair","vertical-text","alias","copy","no-drop","grab","grabbing","all-scroll","col-resize","row-resize","n-resize","e-resize","s-resize","w-resize","ne-resize","nw-resize","se-resize","sw-resize","ew-resize","ns-resize","nesw-resize","nwse-resize","zoom-in","zoom-out",ct,at]}],"field-sizing":[{"field-sizing":["fixed","content"]}],"pointer-events":[{"pointer-events":["auto","none"]}],resize:[{resize:["none","","y","x"]}],"scroll-behavior":[{scroll:["auto","smooth"]}],"scroll-m":[{"scroll-m":j()}],"scroll-mx":[{"scroll-mx":j()}],"scroll-my":[{"scroll-my":j()}],"scroll-ms":[{"scroll-ms":j()}],"scroll-me":[{"scroll-me":j()}],"scroll-mbs":[{"scroll-mbs":j()}],"scroll-mbe":[{"scroll-mbe":j()}],"scroll-mt":[{"scroll-mt":j()}],"scroll-mr":[{"scroll-mr":j()}],"scroll-mb":[{"scroll-mb":j()}],"scroll-ml":[{"scroll-ml":j()}],"scroll-p":[{"scroll-p":j()}],"scroll-px":[{"scroll-px":j()}],"scroll-py":[{"scroll-py":j()}],"scroll-ps":[{"scroll-ps":j()}],"scroll-pe":[{"scroll-pe":j()}],"scroll-pbs":[{"scroll-pbs":j()}],"scroll-pbe":[{"scroll-pbe":j()}],"scroll-pt":[{"scroll-pt":j()}],"scroll-pr":[{"scroll-pr":j()}],"scroll-pb":[{"scroll-pb":j()}],"scroll-pl":[{"scroll-pl":j()}],"snap-align":[{snap:["start","end","center","align-none"]}],"snap-stop":[{snap:["normal","always"]}],"snap-type":[{snap:["none","x","y","both"]}],"snap-strictness":[{snap:["mandatory","proximity"]}],touch:[{touch:["auto","none","manipulation"]}],"touch-x":[{"touch-pan":["x","left","right"]}],"touch-y":[{"touch-pan":["y","up","down"]}],"touch-pz":["touch-pinch-zoom"],select:[{select:["none","text","all","auto"]}],"will-change":[{"will-change":["auto","scroll","contents","transform",ct,at]}],fill:[{fill:["none",...D()]}],"stroke-w":[{stroke:[qt,eh,sc,IN]}],stroke:[{stroke:["none",...D()]}],"forced-color-adjust":[{"forced-color-adjust":["auto","none"]}]},conflictingClassGroups:{overflow:["overflow-x","overflow-y"],overscroll:["overscroll-x","overscroll-y"],inset:["inset-x","inset-y","inset-bs","inset-be","start","end","top","right","bottom","left"],"inset-x":["right","left"],"inset-y":["top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pbs","pbe","pt","pr","pb","pl"],px:["pr","pl"],py:["pt","pb"],m:["mx","my","ms","me","mbs","mbe","mt","mr","mb","ml"],mx:["mr","ml"],my:["mt","mb"],size:["w","h"],"font-size":["leading"],"fvn-normal":["fvn-ordinal","fvn-slashed-zero","fvn-figure","fvn-spacing","fvn-fraction"],"fvn-ordinal":["fvn-normal"],"fvn-slashed-zero":["fvn-normal"],"fvn-figure":["fvn-normal"],"fvn-spacing":["fvn-normal"],"fvn-fraction":["fvn-normal"],"line-clamp":["display","overflow"],rounded:["rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl"],"rounded-s":["rounded-ss","rounded-es"],"rounded-e":["rounded-se","rounded-ee"],"rounded-t":["rounded-tl","rounded-tr"],"rounded-r":["rounded-tr","rounded-br"],"rounded-b":["rounded-br","rounded-bl"],"rounded-l":["rounded-tl","rounded-bl"],"border-spacing":["border-spacing-x","border-spacing-y"],"border-w":["border-w-x","border-w-y","border-w-s","border-w-e","border-w-bs","border-w-be","border-w-t","border-w-r","border-w-b","border-w-l"],"border-w-x":["border-w-r","border-w-l"],"border-w-y":["border-w-t","border-w-b"],"border-color":["border-color-x","border-color-y","border-color-s","border-color-e","border-color-bs","border-color-be","border-color-t","border-color-r","border-color-b","border-color-l"],"border-color-x":["border-color-r","border-color-l"],"border-color-y":["border-color-t","border-color-b"],translate:["translate-x","translate-y","translate-none"],"translate-none":["translate","translate-x","translate-y","translate-z"],"scroll-m":["scroll-mx","scroll-my","scroll-ms","scroll-me","scroll-mbs","scroll-mbe","scroll-mt","scroll-mr","scroll-mb","scroll-ml"],"scroll-mx":["scroll-mr","scroll-ml"],"scroll-my":["scroll-mt","scroll-mb"],"scroll-p":["scroll-px","scroll-py","scroll-ps","scroll-pe","scroll-pbs","scroll-pbe","scroll-pt","scroll-pr","scroll-pb","scroll-pl"],"scroll-px":["scroll-pr","scroll-pl"],"scroll-py":["scroll-pt","scroll-pb"],touch:["touch-x","touch-y","touch-pz"],"touch-x":["touch"],"touch-y":["touch"],"touch-pz":["touch"]},conflictingClassGroupModifiers:{"font-size":["leading"]},orderSensitiveModifiers:["*","**","after","backdrop","before","details-content","file","first-letter","first-line","marker","placeholder","selection"]}},MK=cK(NK);function he(...e){return MK(M5(e))}function mc(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function LK(e){return e.startsWith("chatId:")?e.slice(7):e}const Kh="data-focus-fallback-ignore",G5="data-allow-focus-retain",Yv="kanna:restore-chat-input-focus",qC="data-chat-input",Xv="data-chat-selection-zone";function gc(e,t){return!!(e!=null&&e.closest(`[${t}]`))}function q5(e){var n;const t=e;return t!=null&&t.matches?t.matches("input:not([type='checkbox']):not([type='radio']):not([type='button']):not([type='submit']):not([type='reset']), textarea, select")||t.isContentEditable||((n=t.getAttribute)==null?void 0:n.call(t,"role"))==="textbox"?!0:gc(e,G5):!1}function IK(e){const t=e;return t!=null&&t.matches?q5(e)||(t.tabIndex??-1)>=0||t.matches("button, a[href], summary")?!0:gc(e,G5):!1}function PN(e){return!!e.querySelector(`[${Kh}][data-state='open']`)}function jK(e){return e?!e.isCollapsed&&e.toString().trim().length>0:!1}function DK(e,t){if(!e)return!1;const n=Array.from(t.querySelectorAll(`textarea[${qC}]`)).filter(o=>!o.disabled);if(n.length===0)return!1;const r=n.indexOf(e),i=r>=0?(r+1)%n.length:0,s=n[i];return s?(s.focus({preventScroll:!0}),!0):!1}function ON(e){const{activeElement:t,fallback:n,hasActiveOverlay:r}=e;if(!n||n.disabled||r||t===n)return"none";if(e.trigger==="escape")return e.defaultPrevented||gc(t,qC)||e.canCancel?"none":"escape-focus";const{pointerStartTarget:i,pointerEndTarget:s,root:o,hasActiveSelection:l}=e,c=s??i;return!o||!c||!o.contains(c)||gc(c,Kh)||gc(t,Kh)||l&&(gc(i,Xv)||gc(c,Xv))||q5(t)?"none":t&&t===c?"restore":IK(t)?"none":"restore"}const Ao=R5,PK=T5,K5=v.forwardRef(({className:e,...t},n)=>f.jsx(UC,{ref:n,className:he("fixed inset-0 z-50 bg-black/50 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));K5.displayName=UC.displayName;const OK={sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg"},Ys=v.forwardRef(({className:e,children:t,size:n="md",...r},i)=>f.jsxs(PK,{children:[f.jsx(K5,{}),f.jsxs(VC,{ref:i,[Kh]:"",onCloseAutoFocus:s=>{var o;s.preventDefault(),window.dispatchEvent(new Event(Yv)),(o=r.onCloseAutoFocus)==null||o.call(r,s)},className:he("fixed left-1/2 top-1/2 z-50 w-full -translate-x-1/2 -translate-y-1/2 rounded-xl border border-border bg-background shadow-xl duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%]","max-h-[85vh] flex flex-col",OK[n],e),...r,children:[t,f.jsxs(Hq,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[f.jsx(eo,{className:"h-4 w-4"}),f.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Ys.displayName=VC.displayName;function KC({className:e,...t}){return f.jsx("div",{className:he("shrink-0 flex flex-col space-y-1.5 p-4 border-b border-border",e),...t})}function No({className:e,...t}){return f.jsx(A5,{className:he("text-lg font-medium leading-none tracking-tight",e),...t})}function Gd({className:e,...t}){return f.jsx($q,{className:he("text-sm text-muted-foreground",e),...t})}function ma({className:e,...t}){return f.jsx("div",{className:he("flex-1 min-h-0 overflow-y-auto px-4 pb-4 pt-3.5",e),...t})}function Rl({className:e,...t}){return f.jsx("div",{className:he("shrink-0 flex justify-end gap-2 border-t border-border bg-background p-2 rounded-b-xl",e),...t})}function zK({className:e,...t}){return f.jsx("button",{className:he("touch-manipulation inline-flex items-center justify-center whitespace-nowrap cursor-pointer text-sm font-medium transition-colors","rounded-full h-9 px-4","bg-primary text-primary-foreground hover:bg-primary/90","disabled:pointer-events-none disabled:bg-primary/20 disabled:text-primary/60",e),...t})}function BK({className:e,...t}){return f.jsx("button",{className:he("touch-manipulation inline-flex items-center justify-center whitespace-nowrap cursor-pointer text-sm font-medium transition-colors","rounded-full h-9 px-4","hover:bg-accent dark:hover:bg-card hover:text-accent-foreground text-muted-foreground","disabled:pointer-events-none disabled:text-muted-foreground/50",e),...t})}function FK({open:e,shareUrl:t,onOpenChange:n,onOpenLink:r,onCopyLink:i}){const[s,o]=v.useState(!1);v.useEffect(()=>{e||o(!1)},[e,t]);const l=async()=>{await i()&&(o(!0),window.setTimeout(()=>{o(!1)},2e3))};return f.jsx(Ao,{open:e,onOpenChange:n,children:f.jsxs(Ys,{size:"md",children:[f.jsxs(KC,{children:[f.jsx(No,{children:"Shared Link"}),f.jsx(Gd,{children:"Shared links are snapshots in time and contain all attachments, tool calls and history. Be mindful of sensitive info."})]}),f.jsx(ma,{className:"space-y-3",children:f.jsxs("div",{className:"flex w-full items-center gap-2 rounded-2xl border border-border bg-muted/40 pl-4 px-3 py-2.5",children:[f.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-sm text-foreground",children:t}),f.jsx("button",{type:"button",onClick:()=>void l(),title:s?"Copied":"Copy link","aria-label":s?"Copied":"Copy link",className:"flex flex-shrink-0 items-center justify-center rounded-lg text-logo hover:text-logo/60 transition-colors hover:bg-background hover:text-foreground",children:s?f.jsx(gi,{className:"h-4 w-4 text-emerald-400"}):f.jsx(El,{className:"h-4 w-4"})})]})}),f.jsx(Rl,{children:f.jsxs(zK,{type:"button",onClick:r,children:[f.jsx(Jb,{className:"mr-2 h-4 w-4"}),"Open"]})})]})})}const zN=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,BN=M5,$K=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return BN(e,n==null?void 0:n.class,n==null?void 0:n.className);const{variants:i,defaultVariants:s}=t,o=Object.keys(i).map(u=>{const p=n==null?void 0:n[u],h=s==null?void 0:s[u];if(p===null)return null;const g=zN(p)||zN(h);return i[u][g]}),l=n&&Object.entries(n).reduce((u,p)=>{let[h,g]=p;return g===void 0||(u[h]=g),u},{}),c=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((u,p)=>{let{class:h,className:g,...b}=p;return Object.entries(b).every(_=>{let[x,S]=_;return Array.isArray(S)?S.includes({...s,...l}[x]):{...s,...l}[x]===S})?[...u,h,g]:u},[]);return BN(e,o,c,n==null?void 0:n.class,n==null?void 0:n.className)},a0=$K("touch-manipulation inline-flex items-center justify-center whitespace-nowrap cursor-pointer rounded-md text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none",{variants:{variant:{default:"bg-primary text-primary-foreground disabled:bg-primary/50 disabled:text-primary-foreground/90 hover:bg-primary/90",juicy:"bg-logo text-primary-foreground disabled:text-primary-foreground/50 hover:bg-logo/90",destructive:"bg-destructive/80 dark:text-white",outline:"border disabled:bg-transparent disabled:text-foreground/50 border-inpu disabled:border-input/90 bg-card hover:bg-muted hover:text-accent-foreground",secondary:"bg-transparent border border-border text-secondary-foreground hover:text-secondary-foreground/60 disabled:text-secondary-foreground/50",ghost:"hover:bg-accent dark:hover:bg-card hover:text-accent-foreground text-muted-foreground disabled:text-muted-foreground/50 border border-border/0 hover:border-border",link:"text-primary disabled:text-primary/50 underline-offset-4 hover:underline",none:""},size:{default:"h-10 px-4 rounded-full py-2",sm:"h-9 rounded-full px-3",lg:"h-11 rounded-full px-8",icon:"h-9 w-9 rounded-full","icon-mobile":"h-11 w-11 rounded-full md:h-9 md:w-9",none:"","icon-sm":"h-5.5 w-5.5 rounded-md"}},defaultVariants:{variant:"default",size:"default"}}),Ke=v.forwardRef(({className:e,variant:t,size:n,type:r="button",...i},s)=>f.jsx("button",{type:r,className:he(a0({variant:t,size:n,className:e})),ref:s,...i}));Ke.displayName="Button";const ir=v.forwardRef(({className:e,type:t,...n},r)=>f.jsx("input",{ref:r,type:t,className:he("flex w-full rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50",e),...n}));ir.displayName="Input";const Y5=v.createContext(null);function HK({children:e}){const[t,n]=v.useState(null),[r,i]=v.useState(""),s=v.useRef(null);v.useEffect(()=>{(t==null?void 0:t.kind)==="prompt"&&(i(t.options.initialValue??""),setTimeout(()=>{var b,_;(b=s.current)==null||b.focus(),(_=s.current)==null||_.select()},0))},[t]);const o=v.useCallback(()=>{n(null),i("")},[]),l=v.useCallback(()=>{t&&(t.kind==="confirm"?t.resolve(!1):t.kind==="prompt"?t.resolve(null):t.resolve(),o())},[o,t]),c=v.useCallback(()=>{t&&(t.kind==="confirm"?t.resolve(!0):t.kind==="prompt"?t.resolve(r.trim()||null):t.resolve(),o())},[o,t,r]),u=v.useCallback(b=>new Promise(_=>{n({kind:"confirm",options:b,resolve:_})}),[]),p=v.useCallback(b=>new Promise(_=>{n({kind:"prompt",options:b,resolve:_})}),[]),h=v.useCallback(b=>new Promise(_=>{n({kind:"alert",options:b,resolve:_})}),[]),g=v.useMemo(()=>({confirm:u,prompt:p,alert:h}),[h,u,p]);return f.jsxs(Y5.Provider,{value:g,children:[e,f.jsx(Ao,{open:t!==null,onOpenChange:b=>{b||!t||l()},children:f.jsx(Ys,{size:"sm",onKeyDown:b=>{b.key!=="Enter"||b.shiftKey||!t||t.kind!=="confirm"||(b.preventDefault(),c())},children:t?f.jsxs(f.Fragment,{children:[f.jsxs(ma,{className:"space-y-4",children:[f.jsx(No,{children:t.options.title}),t.options.description?f.jsx(Gd,{children:t.options.description}):null,t.kind==="prompt"?f.jsx(ir,{ref:s,type:"text",value:r,onChange:b=>i(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),c())},placeholder:t.options.placeholder}):null]}),f.jsxs(Rl,{children:[f.jsx(Ke,{variant:"ghost",size:"sm",onClick:l,className:t.kind==="alert"?"hidden":void 0,children:"cancelLabel"in t.options?t.options.cancelLabel??"Cancel":"Cancel"}),f.jsx(Ke,{variant:t.kind==="confirm"?t.options.confirmVariant??"default":"secondary",size:"sm",onClick:c,disabled:t.kind==="prompt"&&!r.trim(),children:t.kind==="alert"?t.options.closeLabel??"OK":"confirmLabel"in t.options?t.options.confirmLabel??"Confirm":"Confirm"})]})]}):null})})]})}function Np(){const e=v.useContext(Y5);if(!e)throw new Error("useAppDialog must be used within AppDialogProvider");return e}const YC=v.forwardRef(({className:e,...t},n)=>f.jsx("div",{ref:n,className:he("bg-card text-card-foreground",e),...t}));YC.displayName="Card";const XC=v.forwardRef(({className:e,...t},n)=>f.jsx("div",{ref:n,className:he("flex flex-col space-y-1.5 p-2",e),...t}));XC.displayName="CardHeader";const X5=v.forwardRef(({className:e,...t},n)=>f.jsx("h3",{ref:n,className:he("text-2xl font-semibold leading-none tracking-tight",e),...t}));X5.displayName="CardTitle";const Q5=v.forwardRef(({className:e,...t},n)=>f.jsx("p",{ref:n,className:he("text-sm text-muted-foreground",e),...t}));Q5.displayName="CardDescription";const QC=v.forwardRef(({className:e,...t},n)=>f.jsx("div",{ref:n,className:he("p-6 pt-0",e),...t}));QC.displayName="CardContent";const UK=v.forwardRef(({className:e,...t},n)=>f.jsx("div",{ref:n,className:he("flex items-center p-6 pt-0",e),...t}));UK.displayName="CardFooter";const VK=["top","right","bottom","left"],Tl=Math.min,qi=Math.max,Qv=Math.round,xg=Math.floor,Eo=e=>({x:e,y:e}),WK={left:"right",right:"left",bottom:"top",top:"bottom"};function pw(e,t,n){return qi(e,Tl(t,n))}function ga(e,t){return typeof e=="function"?e(t):e}function va(e){return e.split("-")[0]}function qd(e){return e.split("-")[1]}function ZC(e){return e==="x"?"y":"x"}function JC(e){return e==="y"?"height":"width"}function xo(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function ek(e){return ZC(xo(e))}function GK(e,t,n){n===void 0&&(n=!1);const r=qd(e),i=ek(e),s=JC(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=Zv(o)),[o,Zv(o)]}function qK(e){const t=Zv(e);return[mw(e),t,mw(t)]}function mw(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const FN=["left","right"],$N=["right","left"],KK=["top","bottom"],YK=["bottom","top"];function XK(e,t,n){switch(e){case"top":case"bottom":return n?t?$N:FN:t?FN:$N;case"left":case"right":return t?KK:YK;default:return[]}}function QK(e,t,n,r){const i=qd(e);let s=XK(va(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(mw)))),s}function Zv(e){const t=va(e);return WK[t]+e.slice(t.length)}function ZK(e){return{top:0,right:0,bottom:0,left:0,...e}}function Z5(e){return typeof e!="number"?ZK(e):{top:e,right:e,bottom:e,left:e}}function Jv(e){const{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function HN(e,t,n){let{reference:r,floating:i}=e;const s=xo(t),o=ek(t),l=JC(o),c=va(t),u=s==="y",p=r.x+r.width/2-i.width/2,h=r.y+r.height/2-i.height/2,g=r[l]/2-i[l]/2;let b;switch(c){case"top":b={x:p,y:r.y-i.height};break;case"bottom":b={x:p,y:r.y+r.height};break;case"right":b={x:r.x+r.width,y:h};break;case"left":b={x:r.x-i.width,y:h};break;default:b={x:r.x,y:r.y}}switch(qd(t)){case"start":b[o]-=g*(n&&u?-1:1);break;case"end":b[o]+=g*(n&&u?-1:1);break}return b}async function JK(e,t){var n;t===void 0&&(t={});const{x:r,y:i,platform:s,rects:o,elements:l,strategy:c}=e,{boundary:u="clippingAncestors",rootBoundary:p="viewport",elementContext:h="floating",altBoundary:g=!1,padding:b=0}=ga(t,e),_=Z5(b),S=l[g?h==="floating"?"reference":"floating":h],C=Jv(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(S)))==null||n?S:S.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:u,rootBoundary:p,strategy:c})),E=h==="floating"?{x:r,y:i,width:o.floating.width,height:o.floating.height}:o.reference,k=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),T=await(s.isElement==null?void 0:s.isElement(k))?await(s.getScale==null?void 0:s.getScale(k))||{x:1,y:1}:{x:1,y:1},A=Jv(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:E,offsetParent:k,strategy:c}):E);return{top:(C.top-A.top+_.top)/T.y,bottom:(A.bottom-C.bottom+_.bottom)/T.y,left:(C.left-A.left+_.left)/T.x,right:(A.right-C.right+_.right)/T.x}}const eY=50,tY=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:JK},c=await(o.isRTL==null?void 0:o.isRTL(t));let u=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:p,y:h}=HN(u,r,c),g=r,b=0;const _={};for(let x=0;x<s.length;x++){const S=s[x];if(!S)continue;const{name:C,fn:E}=S,{x:k,y:T,data:A,reset:N}=await E({x:p,y:h,initialPlacement:r,placement:g,strategy:i,middlewareData:_,rects:u,platform:l,elements:{reference:e,floating:t}});p=k??p,h=T??h,_[C]={..._[C],...A},N&&b<eY&&(b++,typeof N=="object"&&(N.placement&&(g=N.placement),N.rects&&(u=N.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):N.rects),{x:p,y:h}=HN(u,g,c)),x=-1)}return{x:p,y:h,placement:g,strategy:i,middlewareData:_}},nY=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:i,rects:s,platform:o,elements:l,middlewareData:c}=t,{element:u,padding:p=0}=ga(e,t)||{};if(u==null)return{};const h=Z5(p),g={x:n,y:r},b=ek(i),_=JC(b),x=await o.getDimensions(u),S=b==="y",C=S?"top":"left",E=S?"bottom":"right",k=S?"clientHeight":"clientWidth",T=s.reference[_]+s.reference[b]-g[b]-s.floating[_],A=g[b]-s.reference[b],N=await(o.getOffsetParent==null?void 0:o.getOffsetParent(u));let M=N?N[k]:0;(!M||!await(o.isElement==null?void 0:o.isElement(N)))&&(M=l.floating[k]||s.floating[_]);const j=T/2-A/2,U=M/2-x[_]/2-1,I=Tl(h[C],U),P=Tl(h[E],U),z=I,O=M-x[_]-P,$=M/2-x[_]/2+j,V=pw(z,$,O),F=!c.arrow&&qd(i)!=null&&$!==V&&s.reference[_]/2-($<z?I:P)-x[_]/2<0,H=F?$<z?$-z:$-O:0;return{[b]:g[b]+H,data:{[b]:V,centerOffset:$-V-H,...F&&{alignmentOffset:H}},reset:F}}}),rY=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:i,middlewareData:s,rects:o,initialPlacement:l,platform:c,elements:u}=t,{mainAxis:p=!0,crossAxis:h=!0,fallbackPlacements:g,fallbackStrategy:b="bestFit",fallbackAxisSideDirection:_="none",flipAlignment:x=!0,...S}=ga(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const C=va(i),E=xo(l),k=va(l)===l,T=await(c.isRTL==null?void 0:c.isRTL(u.floating)),A=g||(k||!x?[Zv(l)]:qK(l)),N=_!=="none";!g&&N&&A.push(...QK(l,x,_,T));const M=[l,...A],j=await c.detectOverflow(t,S),U=[];let I=((r=s.flip)==null?void 0:r.overflows)||[];if(p&&U.push(j[C]),h){const $=GK(i,o,T);U.push(j[$[0]],j[$[1]])}if(I=[...I,{placement:i,overflows:U}],!U.every($=>$<=0)){var P,z;const $=(((P=s.flip)==null?void 0:P.index)||0)+1,V=M[$];if(V&&(!(h==="alignment"?E!==xo(V):!1)||I.every(W=>xo(W.placement)===E?W.overflows[0]>0:!0)))return{data:{index:$,overflows:I},reset:{placement:V}};let F=(z=I.filter(H=>H.overflows[0]<=0).sort((H,W)=>H.overflows[1]-W.overflows[1])[0])==null?void 0:z.placement;if(!F)switch(b){case"bestFit":{var O;const H=(O=I.filter(W=>{if(N){const Z=xo(W.placement);return Z===E||Z==="y"}return!0}).map(W=>[W.placement,W.overflows.filter(Z=>Z>0).reduce((Z,D)=>Z+D,0)]).sort((W,Z)=>W[1]-Z[1])[0])==null?void 0:O[0];H&&(F=H);break}case"initialPlacement":F=l;break}if(i!==F)return{reset:{placement:F}}}return{}}}};function UN(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function VN(e){return VK.some(t=>e[t]>=0)}const iY=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=ga(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=UN(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:VN(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=UN(o,n.floating);return{data:{escapedOffsets:l,escaped:VN(l)}}}default:return{}}}}},J5=new Set(["left","top"]);async function sY(e,t){const{placement:n,platform:r,elements:i}=e,s=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=va(n),l=qd(n),c=xo(n)==="y",u=J5.has(o)?-1:1,p=s&&c?-1:1,h=ga(t,e);let{mainAxis:g,crossAxis:b,alignmentAxis:_}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return l&&typeof _=="number"&&(b=l==="end"?_*-1:_),c?{x:b*p,y:g*u}:{x:g*u,y:b*p}}const oY=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:i,y:s,placement:o,middlewareData:l}=t,c=await sY(t,e);return o===((n=l.offset)==null?void 0:n.placement)&&(r=l.arrow)!=null&&r.alignmentOffset?{}:{x:i+c.x,y:s+c.y,data:{...c,placement:o}}}}},aY=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:i,platform:s}=t,{mainAxis:o=!0,crossAxis:l=!1,limiter:c={fn:C=>{let{x:E,y:k}=C;return{x:E,y:k}}},...u}=ga(e,t),p={x:n,y:r},h=await s.detectOverflow(t,u),g=xo(va(i)),b=ZC(g);let _=p[b],x=p[g];if(o){const C=b==="y"?"top":"left",E=b==="y"?"bottom":"right",k=_+h[C],T=_-h[E];_=pw(k,_,T)}if(l){const C=g==="y"?"top":"left",E=g==="y"?"bottom":"right",k=x+h[C],T=x-h[E];x=pw(k,x,T)}const S=c.fn({...t,[b]:_,[g]:x});return{...S,data:{x:S.x-n,y:S.y-r,enabled:{[b]:o,[g]:l}}}}}},lY=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:i,rects:s,middlewareData:o}=t,{offset:l=0,mainAxis:c=!0,crossAxis:u=!0}=ga(e,t),p={x:n,y:r},h=xo(i),g=ZC(h);let b=p[g],_=p[h];const x=ga(l,t),S=typeof x=="number"?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(c){const k=g==="y"?"height":"width",T=s.reference[g]-s.floating[k]+S.mainAxis,A=s.reference[g]+s.reference[k]-S.mainAxis;b<T?b=T:b>A&&(b=A)}if(u){var C,E;const k=g==="y"?"width":"height",T=J5.has(va(i)),A=s.reference[h]-s.floating[k]+(T&&((C=o.offset)==null?void 0:C[h])||0)+(T?0:S.crossAxis),N=s.reference[h]+s.reference[k]+(T?0:((E=o.offset)==null?void 0:E[h])||0)-(T?S.crossAxis:0);_<A?_=A:_>N&&(_=N)}return{[g]:b,[h]:_}}}},cY=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:i,rects:s,platform:o,elements:l}=t,{apply:c=()=>{},...u}=ga(e,t),p=await o.detectOverflow(t,u),h=va(i),g=qd(i),b=xo(i)==="y",{width:_,height:x}=s.floating;let S,C;h==="top"||h==="bottom"?(S=h,C=g===(await(o.isRTL==null?void 0:o.isRTL(l.floating))?"start":"end")?"left":"right"):(C=h,S=g==="end"?"top":"bottom");const E=x-p.top-p.bottom,k=_-p.left-p.right,T=Tl(x-p[S],E),A=Tl(_-p[C],k),N=!t.middlewareData.shift;let M=T,j=A;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(j=k),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(M=E),N&&!g){const I=qi(p.left,0),P=qi(p.right,0),z=qi(p.top,0),O=qi(p.bottom,0);b?j=_-2*(I!==0||P!==0?I+P:qi(p.left,p.right)):M=x-2*(z!==0||O!==0?z+O:qi(p.top,p.bottom))}await c({...t,availableWidth:j,availableHeight:M});const U=await o.getDimensions(l.floating);return _!==U.width||x!==U.height?{reset:{rects:!0}}:{}}}};function l0(){return typeof window<"u"}function Kd(e){return eO(e)?(e.nodeName||"").toLowerCase():"#document"}function Ki(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Io(e){var t;return(t=(eO(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function eO(e){return l0()?e instanceof Node||e instanceof Ki(e).Node:!1}function Xs(e){return l0()?e instanceof Element||e instanceof Ki(e).Element:!1}function Sa(e){return l0()?e instanceof HTMLElement||e instanceof Ki(e).HTMLElement:!1}function WN(e){return!l0()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ki(e).ShadowRoot}function Mp(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=Qs(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function uY(e){return/^(table|td|th)$/.test(Kd(e))}function c0(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const dY=/transform|translate|scale|rotate|perspective|filter/,fY=/paint|layout|strict|content/,oc=e=>!!e&&e!=="none";let Ex;function tk(e){const t=Xs(e)?Qs(e):e;return oc(t.transform)||oc(t.translate)||oc(t.scale)||oc(t.rotate)||oc(t.perspective)||!nk()&&(oc(t.backdropFilter)||oc(t.filter))||dY.test(t.willChange||"")||fY.test(t.contain||"")}function hY(e){let t=Al(e);for(;Sa(t)&&!Cd(t);){if(tk(t))return t;if(c0(t))return null;t=Al(t)}return null}function nk(){return Ex==null&&(Ex=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Ex}function Cd(e){return/^(html|body|#document)$/.test(Kd(e))}function Qs(e){return Ki(e).getComputedStyle(e)}function u0(e){return Xs(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Al(e){if(Kd(e)==="html")return e;const t=e.assignedSlot||e.parentNode||WN(e)&&e.host||Io(e);return WN(t)?t.host:t}function tO(e){const t=Al(e);return Cd(t)?e.ownerDocument?e.ownerDocument.body:e.body:Sa(t)&&Mp(t)?t:tO(t)}function Yh(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=tO(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=Ki(i);if(s){const l=gw(o);return t.concat(o,o.visualViewport||[],Mp(i)?i:[],l&&n?Yh(l):[])}else return t.concat(i,Yh(i,[],n))}function gw(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function nO(e){const t=Qs(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Sa(e),s=i?e.offsetWidth:n,o=i?e.offsetHeight:r,l=Qv(n)!==s||Qv(r)!==o;return l&&(n=s,r=o),{width:n,height:r,$:l}}function rk(e){return Xs(e)?e:e.contextElement}function dd(e){const t=rk(e);if(!Sa(t))return Eo(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=nO(t);let o=(s?Qv(n.width):n.width)/r,l=(s?Qv(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!l||!Number.isFinite(l))&&(l=1),{x:o,y:l}}const pY=Eo(0);function rO(e){const t=Ki(e);return!nk()||!t.visualViewport?pY:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function mY(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Ki(e)?!1:t}function Lc(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),s=rk(e);let o=Eo(1);t&&(r?Xs(r)&&(o=dd(r)):o=dd(e));const l=mY(s,n,r)?rO(s):Eo(0);let c=(i.left+l.x)/o.x,u=(i.top+l.y)/o.y,p=i.width/o.x,h=i.height/o.y;if(s){const g=Ki(s),b=r&&Xs(r)?Ki(r):r;let _=g,x=gw(_);for(;x&&r&&b!==_;){const S=dd(x),C=x.getBoundingClientRect(),E=Qs(x),k=C.left+(x.clientLeft+parseFloat(E.paddingLeft))*S.x,T=C.top+(x.clientTop+parseFloat(E.paddingTop))*S.y;c*=S.x,u*=S.y,p*=S.x,h*=S.y,c+=k,u+=T,_=Ki(x),x=gw(_)}}return Jv({width:p,height:h,x:c,y:u})}function d0(e,t){const n=u0(e).scrollLeft;return t?t.left+n:Lc(Io(e)).left+n}function iO(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-d0(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function gY(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=Io(r),l=t?c0(t.floating):!1;if(r===o||l&&s)return n;let c={scrollLeft:0,scrollTop:0},u=Eo(1);const p=Eo(0),h=Sa(r);if((h||!h&&!s)&&((Kd(r)!=="body"||Mp(o))&&(c=u0(r)),h)){const b=Lc(r);u=dd(r),p.x=b.x+r.clientLeft,p.y=b.y+r.clientTop}const g=o&&!h&&!s?iO(o,c):Eo(0);return{width:n.width*u.x,height:n.height*u.y,x:n.x*u.x-c.scrollLeft*u.x+p.x+g.x,y:n.y*u.y-c.scrollTop*u.y+p.y+g.y}}function vY(e){return Array.from(e.getClientRects())}function bY(e){const t=Io(e),n=u0(e),r=e.ownerDocument.body,i=qi(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=qi(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+d0(e);const l=-n.scrollTop;return Qs(r).direction==="rtl"&&(o+=qi(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const GN=25;function yY(e,t){const n=Ki(e),r=Io(e),i=n.visualViewport;let s=r.clientWidth,o=r.clientHeight,l=0,c=0;if(i){s=i.width,o=i.height;const p=nk();(!p||p&&t==="fixed")&&(l=i.offsetLeft,c=i.offsetTop)}const u=d0(r);if(u<=0){const p=r.ownerDocument,h=p.body,g=getComputedStyle(h),b=p.compatMode==="CSS1Compat"&&parseFloat(g.marginLeft)+parseFloat(g.marginRight)||0,_=Math.abs(r.clientWidth-h.clientWidth-b);_<=GN&&(s-=_)}else u<=GN&&(s+=u);return{width:s,height:o,x:l,y:c}}function _Y(e,t){const n=Lc(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=Sa(e)?dd(e):Eo(1),o=e.clientWidth*s.x,l=e.clientHeight*s.y,c=i*s.x,u=r*s.y;return{width:o,height:l,x:c,y:u}}function qN(e,t,n){let r;if(t==="viewport")r=yY(e,n);else if(t==="document")r=bY(Io(e));else if(Xs(t))r=_Y(t,n);else{const i=rO(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Jv(r)}function sO(e,t){const n=Al(e);return n===t||!Xs(n)||Cd(n)?!1:Qs(n).position==="fixed"||sO(n,t)}function xY(e,t){const n=t.get(e);if(n)return n;let r=Yh(e,[],!1).filter(l=>Xs(l)&&Kd(l)!=="body"),i=null;const s=Qs(e).position==="fixed";let o=s?Al(e):e;for(;Xs(o)&&!Cd(o);){const l=Qs(o),c=tk(o);!c&&l.position==="fixed"&&(i=null),(s?!c&&!i:!c&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||Mp(o)&&!c&&sO(e,o))?r=r.filter(p=>p!==o):i=l,o=Al(o)}return t.set(e,r),r}function SY(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?c0(t)?[]:xY(t,this._c):[].concat(n),r],l=qN(t,o[0],i);let c=l.top,u=l.right,p=l.bottom,h=l.left;for(let g=1;g<o.length;g++){const b=qN(t,o[g],i);c=qi(b.top,c),u=Tl(b.right,u),p=Tl(b.bottom,p),h=qi(b.left,h)}return{width:u-h,height:p-c,x:h,y:c}}function wY(e){const{width:t,height:n}=nO(e);return{width:t,height:n}}function CY(e,t,n){const r=Sa(t),i=Io(t),s=n==="fixed",o=Lc(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const c=Eo(0);function u(){c.x=d0(i)}if(r||!r&&!s)if((Kd(t)!=="body"||Mp(i))&&(l=u0(t)),r){const b=Lc(t,!0,s,t);c.x=b.x+t.clientLeft,c.y=b.y+t.clientTop}else i&&u();s&&!r&&i&&u();const p=i&&!r&&!s?iO(i,l):Eo(0),h=o.left+l.scrollLeft-c.x-p.x,g=o.top+l.scrollTop-c.y-p.y;return{x:h,y:g,width:o.width,height:o.height}}function Rx(e){return Qs(e).position==="static"}function KN(e,t){if(!Sa(e)||Qs(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return Io(e)===n&&(n=n.ownerDocument.body),n}function oO(e,t){const n=Ki(e);if(c0(e))return n;if(!Sa(e)){let i=Al(e);for(;i&&!Cd(i);){if(Xs(i)&&!Rx(i))return i;i=Al(i)}return n}let r=KN(e,t);for(;r&&uY(r)&&Rx(r);)r=KN(r,t);return r&&Cd(r)&&Rx(r)&&!tk(r)?n:r||hY(e)||n}const kY=async function(e){const t=this.getOffsetParent||oO,n=this.getDimensions,r=await n(e.floating);return{reference:CY(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function EY(e){return Qs(e).direction==="rtl"}const RY={convertOffsetParentRelativeRectToViewportRelativeRect:gY,getDocumentElement:Io,getClippingRect:SY,getOffsetParent:oO,getElementRects:kY,getClientRects:vY,getDimensions:wY,getScale:dd,isElement:Xs,isRTL:EY};function aO(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function TY(e,t){let n=null,r;const i=Io(e);function s(){var l;clearTimeout(r),(l=n)==null||l.disconnect(),n=null}function o(l,c){l===void 0&&(l=!1),c===void 0&&(c=1),s();const u=e.getBoundingClientRect(),{left:p,top:h,width:g,height:b}=u;if(l||t(),!g||!b)return;const _=xg(h),x=xg(i.clientWidth-(p+g)),S=xg(i.clientHeight-(h+b)),C=xg(p),k={rootMargin:-_+"px "+-x+"px "+-S+"px "+-C+"px",threshold:qi(0,Tl(1,c))||1};let T=!0;function A(N){const M=N[0].intersectionRatio;if(M!==c){if(!T)return o();M?o(!1,M):r=setTimeout(()=>{o(!1,1e-7)},1e3)}M===1&&!aO(u,e.getBoundingClientRect())&&o(),T=!1}try{n=new IntersectionObserver(A,{...k,root:i.ownerDocument})}catch{n=new IntersectionObserver(A,k)}n.observe(e)}return o(!0),s}function AY(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:i=!0,ancestorResize:s=!0,elementResize:o=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:c=!1}=r,u=rk(e),p=i||s?[...u?Yh(u):[],...t?Yh(t):[]]:[];p.forEach(C=>{i&&C.addEventListener("scroll",n,{passive:!0}),s&&C.addEventListener("resize",n)});const h=u&&l?TY(u,n):null;let g=-1,b=null;o&&(b=new ResizeObserver(C=>{let[E]=C;E&&E.target===u&&b&&t&&(b.unobserve(t),cancelAnimationFrame(g),g=requestAnimationFrame(()=>{var k;(k=b)==null||k.observe(t)})),n()}),u&&!c&&b.observe(u),t&&b.observe(t));let _,x=c?Lc(e):null;c&&S();function S(){const C=Lc(e);x&&!aO(x,C)&&n(),x=C,_=requestAnimationFrame(S)}return n(),()=>{var C;p.forEach(E=>{i&&E.removeEventListener("scroll",n),s&&E.removeEventListener("resize",n)}),h==null||h(),(C=b)==null||C.disconnect(),b=null,c&&cancelAnimationFrame(_)}}const NY=oY,MY=aY,LY=rY,IY=cY,jY=iY,YN=nY,DY=lY,PY=(e,t,n)=>{const r=new Map,i={platform:RY,...n},s={...i.platform,_c:r};return tY(e,t,{...i,platform:s})};var OY=typeof document<"u",zY=function(){},_v=OY?v.useLayoutEffect:zY;function eb(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!eb(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){const s=i[r];if(!(s==="_owner"&&e.$$typeof)&&!eb(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function lO(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function XN(e,t){const n=lO(e);return Math.round(t*n)/n}function Tx(e){const t=v.useRef(e);return _v(()=>{t.current=e}),t}function BY(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:i,elements:{reference:s,floating:o}={},transform:l=!0,whileElementsMounted:c,open:u}=e,[p,h]=v.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[g,b]=v.useState(r);eb(g,r)||b(r);const[_,x]=v.useState(null),[S,C]=v.useState(null),E=v.useCallback(W=>{W!==N.current&&(N.current=W,x(W))},[]),k=v.useCallback(W=>{W!==M.current&&(M.current=W,C(W))},[]),T=s||_,A=o||S,N=v.useRef(null),M=v.useRef(null),j=v.useRef(p),U=c!=null,I=Tx(c),P=Tx(i),z=Tx(u),O=v.useCallback(()=>{if(!N.current||!M.current)return;const W={placement:t,strategy:n,middleware:g};P.current&&(W.platform=P.current),PY(N.current,M.current,W).then(Z=>{const D={...Z,isPositioned:z.current!==!1};$.current&&!eb(j.current,D)&&(j.current=D,xs.flushSync(()=>{h(D)}))})},[g,t,n,P,z]);_v(()=>{u===!1&&j.current.isPositioned&&(j.current.isPositioned=!1,h(W=>({...W,isPositioned:!1})))},[u]);const $=v.useRef(!1);_v(()=>($.current=!0,()=>{$.current=!1}),[]),_v(()=>{if(T&&(N.current=T),A&&(M.current=A),T&&A){if(I.current)return I.current(T,A,O);O()}},[T,A,O,I,U]);const V=v.useMemo(()=>({reference:N,floating:M,setReference:E,setFloating:k}),[E,k]),F=v.useMemo(()=>({reference:T,floating:A}),[T,A]),H=v.useMemo(()=>{const W={position:n,left:0,top:0};if(!F.floating)return W;const Z=XN(F.floating,p.x),D=XN(F.floating,p.y);return l?{...W,transform:"translate("+Z+"px, "+D+"px)",...lO(F.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:Z,top:D}},[n,l,F.floating,p.x,p.y]);return v.useMemo(()=>({...p,update:O,refs:V,elements:F,floatingStyles:H}),[p,O,V,F,H])}const FY=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:i}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?YN({element:r.current,padding:i}).fn(n):{}:r?YN({element:r,padding:i}).fn(n):{}}}},$Y=(e,t)=>{const n=NY(e);return{name:n.name,fn:n.fn,options:[e,t]}},HY=(e,t)=>{const n=MY(e);return{name:n.name,fn:n.fn,options:[e,t]}},UY=(e,t)=>({fn:DY(e).fn,options:[e,t]}),VY=(e,t)=>{const n=LY(e);return{name:n.name,fn:n.fn,options:[e,t]}},WY=(e,t)=>{const n=IY(e);return{name:n.name,fn:n.fn,options:[e,t]}},GY=(e,t)=>{const n=jY(e);return{name:n.name,fn:n.fn,options:[e,t]}},qY=(e,t)=>{const n=FY(e);return{name:n.name,fn:n.fn,options:[e,t]}};var KY="Arrow",cO=v.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return f.jsx(rn.svg,{...s,ref:t,width:r,height:i,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:f.jsx("polygon",{points:"0,0 30,0 15,10"})})});cO.displayName=KY;var YY=cO;function XY(e){const[t,n]=v.useState(void 0);return ii(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(i=>{if(!Array.isArray(i)||!i.length)return;const s=i[0];let o,l;if("borderBoxSize"in s){const c=s.borderBoxSize,u=Array.isArray(c)?c[0]:c;o=u.inlineSize,l=u.blockSize}else o=e.offsetWidth,l=e.offsetHeight;n({width:o,height:l})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var ik="Popper",[uO,Il]=xa(ik),[QY,dO]=uO(ik),fO=e=>{const{__scopePopper:t,children:n}=e,[r,i]=v.useState(null);return f.jsx(QY,{scope:t,anchor:r,onAnchorChange:i,children:n})};fO.displayName=ik;var hO="PopperAnchor",pO=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=dO(hO,n),o=v.useRef(null),l=yn(t,o),c=v.useRef(null);return v.useEffect(()=>{const u=c.current;c.current=(r==null?void 0:r.current)||o.current,u!==c.current&&s.onAnchorChange(c.current)}),r?null:f.jsx(rn.div,{...i,ref:l})});pO.displayName=hO;var sk="PopperContent",[ZY,JY]=uO(sk),mO=v.forwardRef((e,t)=>{var ne,se,ce,de,Ne,we;const{__scopePopper:n,side:r="bottom",sideOffset:i=0,align:s="center",alignOffset:o=0,arrowPadding:l=0,avoidCollisions:c=!0,collisionBoundary:u=[],collisionPadding:p=0,sticky:h="partial",hideWhenDetached:g=!1,updatePositionStrategy:b="optimized",onPlaced:_,...x}=e,S=dO(sk,n),[C,E]=v.useState(null),k=yn(t,je=>E(je)),[T,A]=v.useState(null),N=XY(T),M=(N==null?void 0:N.width)??0,j=(N==null?void 0:N.height)??0,U=r+(s!=="center"?"-"+s:""),I=typeof p=="number"?p:{top:0,right:0,bottom:0,left:0,...p},P=Array.isArray(u)?u:[u],z=P.length>0,O={padding:I,boundary:P.filter(tX),altBoundary:z},{refs:$,floatingStyles:V,placement:F,isPositioned:H,middlewareData:W}=BY({strategy:"fixed",placement:U,whileElementsMounted:(...je)=>AY(...je,{animationFrame:b==="always"}),elements:{reference:S.anchor},middleware:[$Y({mainAxis:i+j,alignmentAxis:o}),c&&HY({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?UY():void 0,...O}),c&&VY({...O}),WY({...O,apply:({elements:je,rects:fe,availableWidth:ot,availableHeight:Mt})=>{const{width:Et,height:Xt}=fe.reference,Dt=je.floating.style;Dt.setProperty("--radix-popper-available-width",`${ot}px`),Dt.setProperty("--radix-popper-available-height",`${Mt}px`),Dt.setProperty("--radix-popper-anchor-width",`${Et}px`),Dt.setProperty("--radix-popper-anchor-height",`${Xt}px`)}}),T&&qY({element:T,padding:l}),nX({arrowWidth:M,arrowHeight:j}),g&&GY({strategy:"referenceHidden",...O})]}),[Z,D]=bO(F),G=Ks(_);ii(()=>{H&&(G==null||G())},[H,G]);const ee=(ne=W.arrow)==null?void 0:ne.x,B=(se=W.arrow)==null?void 0:se.y,le=((ce=W.arrow)==null?void 0:ce.centerOffset)!==0,[oe,J]=v.useState();return ii(()=>{C&&J(window.getComputedStyle(C).zIndex)},[C]),f.jsx("div",{ref:$.setFloating,"data-radix-popper-content-wrapper":"",style:{...V,transform:H?V.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:oe,"--radix-popper-transform-origin":[(de=W.transformOrigin)==null?void 0:de.x,(Ne=W.transformOrigin)==null?void 0:Ne.y].join(" "),...((we=W.hide)==null?void 0:we.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:f.jsx(ZY,{scope:n,placedSide:Z,onArrowChange:A,arrowX:ee,arrowY:B,shouldHideArrow:le,children:f.jsx(rn.div,{"data-side":Z,"data-align":D,...x,ref:k,style:{...x.style,animation:H?void 0:"none"}})})})});mO.displayName=sk;var gO="PopperArrow",eX={top:"bottom",right:"left",bottom:"top",left:"right"},vO=v.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=JY(gO,r),o=eX[s.placedSide];return f.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[o]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:f.jsx(YY,{...i,ref:n,style:{...i.style,display:"block"}})})});vO.displayName=gO;function tX(e){return e!==null}var nX=e=>({name:"transformOrigin",options:e,fn(t){var S,C,E;const{placement:n,rects:r,middlewareData:i}=t,o=((S=i.arrow)==null?void 0:S.centerOffset)!==0,l=o?0:e.arrowWidth,c=o?0:e.arrowHeight,[u,p]=bO(n),h={start:"0%",center:"50%",end:"100%"}[p],g=(((C=i.arrow)==null?void 0:C.x)??0)+l/2,b=(((E=i.arrow)==null?void 0:E.y)??0)+c/2;let _="",x="";return u==="bottom"?(_=o?h:`${g}px`,x=`${-c}px`):u==="top"?(_=o?h:`${g}px`,x=`${r.floating.height+c}px`):u==="right"?(_=`${-c}px`,x=o?h:`${b}px`):u==="left"&&(_=`${r.floating.width+c}px`,x=o?h:`${b}px`),{data:{x:_,y:x}}}});function bO(e){const[t,n="center"]=e.split("-");return[t,n]}var f0=fO,Lp=pO,h0=mO,p0=vO,yO=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),rX="VisuallyHidden",_O=v.forwardRef((e,t)=>f.jsx(rn.span,{...e,ref:t,style:{...yO,...e.style}}));_O.displayName=rX;var iX=_O,[m0]=xa("Tooltip",[Il]),g0=Il(),xO="TooltipProvider",sX=700,vw="tooltip.open",[oX,ok]=m0(xO),SO=e=>{const{__scopeTooltip:t,delayDuration:n=sX,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:s}=e,o=v.useRef(!0),l=v.useRef(!1),c=v.useRef(0);return v.useEffect(()=>{const u=c.current;return()=>window.clearTimeout(u)},[]),f.jsx(oX,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:v.useCallback(()=>{window.clearTimeout(c.current),o.current=!1},[]),onClose:v.useCallback(()=>{window.clearTimeout(c.current),c.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:l,onPointerInTransitChange:v.useCallback(u=>{l.current=u},[]),disableHoverableContent:i,children:s})};SO.displayName=xO;var Xh="Tooltip",[aX,Ip]=m0(Xh),wO=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,c=ok(Xh,e.__scopeTooltip),u=g0(t),[p,h]=v.useState(null),g=ha(),b=v.useRef(0),_=o??c.disableHoverableContent,x=l??c.delayDuration,S=v.useRef(!1),[C,E]=wd({prop:r,defaultProp:i??!1,onChange:M=>{M?(c.onOpen(),document.dispatchEvent(new CustomEvent(vw))):c.onClose(),s==null||s(M)},caller:Xh}),k=v.useMemo(()=>C?S.current?"delayed-open":"instant-open":"closed",[C]),T=v.useCallback(()=>{window.clearTimeout(b.current),b.current=0,S.current=!1,E(!0)},[E]),A=v.useCallback(()=>{window.clearTimeout(b.current),b.current=0,E(!1)},[E]),N=v.useCallback(()=>{window.clearTimeout(b.current),b.current=window.setTimeout(()=>{S.current=!0,E(!0),b.current=0},x)},[x,E]);return v.useEffect(()=>()=>{b.current&&(window.clearTimeout(b.current),b.current=0)},[]),f.jsx(f0,{...u,children:f.jsx(aX,{scope:t,contentId:g,open:C,stateAttribute:k,trigger:p,onTriggerChange:h,onTriggerEnter:v.useCallback(()=>{c.isOpenDelayedRef.current?N():T()},[c.isOpenDelayedRef,N,T]),onTriggerLeave:v.useCallback(()=>{_?A():(window.clearTimeout(b.current),b.current=0)},[A,_]),onOpen:T,onClose:A,disableHoverableContent:_,children:n})})};wO.displayName=Xh;var bw="TooltipTrigger",CO=v.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Ip(bw,n),s=ok(bw,n),o=g0(n),l=v.useRef(null),c=yn(t,l,i.onTriggerChange),u=v.useRef(!1),p=v.useRef(!1),h=v.useCallback(()=>u.current=!1,[]);return v.useEffect(()=>()=>document.removeEventListener("pointerup",h),[h]),f.jsx(Lp,{asChild:!0,...o,children:f.jsx(rn.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:c,onPointerMove:tt(e.onPointerMove,g=>{g.pointerType!=="touch"&&!p.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),p.current=!0)}),onPointerLeave:tt(e.onPointerLeave,()=>{i.onTriggerLeave(),p.current=!1}),onPointerDown:tt(e.onPointerDown,()=>{i.open&&i.onClose(),u.current=!0,document.addEventListener("pointerup",h,{once:!0})}),onFocus:tt(e.onFocus,()=>{u.current||i.onOpen()}),onBlur:tt(e.onBlur,i.onClose),onClick:tt(e.onClick,i.onClose)})})});CO.displayName=bw;var ak="TooltipPortal",[lX,cX]=m0(ak,{forceMount:void 0}),kO=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=Ip(ak,t);return f.jsx(lX,{scope:t,forceMount:n,children:f.jsx(Ts,{present:n||s.open,children:f.jsx(Wd,{asChild:!0,container:i,children:r})})})};kO.displayName=ak;var kd="TooltipContent",EO=v.forwardRef((e,t)=>{const n=cX(kd,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=Ip(kd,e.__scopeTooltip);return f.jsx(Ts,{present:r||o.open,children:o.disableHoverableContent?f.jsx(RO,{side:i,...s,ref:t}):f.jsx(uX,{side:i,...s,ref:t})})}),uX=v.forwardRef((e,t)=>{const n=Ip(kd,e.__scopeTooltip),r=ok(kd,e.__scopeTooltip),i=v.useRef(null),s=yn(t,i),[o,l]=v.useState(null),{trigger:c,onClose:u}=n,p=i.current,{onPointerInTransitChange:h}=r,g=v.useCallback(()=>{l(null),h(!1)},[h]),b=v.useCallback((_,x)=>{const S=_.currentTarget,C={x:_.clientX,y:_.clientY},E=mX(C,S.getBoundingClientRect()),k=gX(C,E),T=vX(x.getBoundingClientRect()),A=yX([...k,...T]);l(A),h(!0)},[h]);return v.useEffect(()=>()=>g(),[g]),v.useEffect(()=>{if(c&&p){const _=S=>b(S,p),x=S=>b(S,c);return c.addEventListener("pointerleave",_),p.addEventListener("pointerleave",x),()=>{c.removeEventListener("pointerleave",_),p.removeEventListener("pointerleave",x)}}},[c,p,b,g]),v.useEffect(()=>{if(o){const _=x=>{const S=x.target,C={x:x.clientX,y:x.clientY},E=(c==null?void 0:c.contains(S))||(p==null?void 0:p.contains(S)),k=!bX(C,o);E?g():k&&(g(),u())};return document.addEventListener("pointermove",_),()=>document.removeEventListener("pointermove",_)}},[c,p,o,u,g]),f.jsx(RO,{...e,ref:s})}),[dX,fX]=m0(Xh,{isInside:!1}),hX=SG("TooltipContent"),RO=v.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,c=Ip(kd,n),u=g0(n),{onClose:p}=c;return v.useEffect(()=>(document.addEventListener(vw,p),()=>document.removeEventListener(vw,p)),[p]),v.useEffect(()=>{if(c.trigger){const h=g=>{const b=g.target;b!=null&&b.contains(c.trigger)&&p()};return window.addEventListener("scroll",h,{capture:!0}),()=>window.removeEventListener("scroll",h,{capture:!0})}},[c.trigger,p]),f.jsx(Vd,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:h=>h.preventDefault(),onDismiss:p,children:f.jsxs(h0,{"data-state":c.stateAttribute,...u,...l,ref:t,style:{...l.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[f.jsx(hX,{children:r}),f.jsx(dX,{scope:n,isInside:!0,children:f.jsx(iX,{id:c.contentId,role:"tooltip",children:i||r})})]})})});EO.displayName=kd;var TO="TooltipArrow",pX=v.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=g0(n);return fX(TO,n).isInside?null:f.jsx(p0,{...i,...r,ref:t})});pX.displayName=TO;function mX(e,t){const n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),s=Math.abs(t.left-e.x);switch(Math.min(n,r,i,s)){case s:return"left";case i:return"right";case n:return"top";case r:return"bottom";default:throw new Error("unreachable")}}function gX(e,t,n=5){const r=[];switch(t){case"top":r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case"bottom":r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case"left":r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case"right":r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}function vX(e){const{top:t,right:n,bottom:r,left:i}=e;return[{x:i,y:t},{x:n,y:t},{x:n,y:r},{x:i,y:r}]}function bX(e,t){const{x:n,y:r}=e;let i=!1;for(let s=0,o=t.length-1;s<t.length;o=s++){const l=t[s],c=t[o],u=l.x,p=l.y,h=c.x,g=c.y;p>r!=g>r&&n<(h-u)*(r-p)/(g-p)+u&&(i=!i)}return i}function yX(e){const t=e.slice();return t.sort((n,r)=>n.x<r.x?-1:n.x>r.x?1:n.y<r.y?-1:n.y>r.y?1:0),_X(t)}function _X(e){if(e.length<=1)return e.slice();const t=[];for(let r=0;r<e.length;r++){const i=e[r];for(;t.length>=2;){const s=t[t.length-1],o=t[t.length-2];if((s.x-o.x)*(i.y-o.y)>=(s.y-o.y)*(i.x-o.x))t.pop();else break}t.push(i)}t.pop();const n=[];for(let r=e.length-1;r>=0;r--){const i=e[r];for(;n.length>=2;){const s=n[n.length-1],o=n[n.length-2];if((s.x-o.x)*(i.y-o.y)>=(s.y-o.y)*(i.x-o.x))n.pop();else break}n.push(i)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}var xX=SO,AO=wO,NO=CO,MO=kO,lk=EO;function LO({className:e,...t}){return f.jsx("kbd",{className:he("pointer-events-none inline-flex h-5 min-w-5 items-center justify-center rounded border border-border/60 bg-muted/50 px-1.5 font-mono text-[11px] font-medium text-current select-none",e),...t})}function SX({className:e,...t}){return f.jsx("span",{className:he("inline-flex items-center gap-0.5",e),...t})}const wX="z-50 overflow-hidden rounded-md border border-border bg-card p-0.5 text-[11px] font-medium text-card-foreground shadow-sm animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",v0=xX,Xr=AO,Qr=NO,Br=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>f.jsx(MO,{children:f.jsx(lk,{ref:r,sideOffset:t,className:he("z-50 overflow-hidden rounded-md bg-card text-card-foreground border border-border px-3 py-1.5 text-xs animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));Br.displayName=lk.displayName;const tb=AO,nb=NO;function IO(e){return e.toUpperCase()}function CX(e){const t=e.split("+");return f.jsx(SX,{children:t.map((n,r)=>f.jsx(LO,{children:IO(n)},`${n}-${r}`))})}const Qh=v.forwardRef(({className:e,sideOffset:t=4,children:n,shortcut:r,...i},s)=>{const o=r===void 0?null:Array.isArray(r)?r[0]??null:r;return f.jsx(MO,{children:f.jsx(lk,{ref:s,sideOffset:t,className:he(wX,e),...i,children:o?CX(o):f.jsx("span",{children:typeof n=="string"?IO(n):n})})})});Qh.displayName="HotkeyTooltipContent";const kX="modulepreload",EX=function(e){return"/"+e},QN={},Y=function(t,n,r){let i=Promise.resolve();if(n&&n.length>0){let o=function(u){return Promise.all(u.map(p=>Promise.resolve(p).then(h=>({status:"fulfilled",value:h}),h=>({status:"rejected",reason:h}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),c=(l==null?void 0:l.nonce)||(l==null?void 0:l.getAttribute("nonce"));i=o(n.map(u=>{if(u=EX(u),u in QN)return;QN[u]=!0;const p=u.endsWith(".css"),h=p?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${u}"]${h}`))return;const g=document.createElement("link");if(g.rel=p?"stylesheet":kX,p||(g.as="script"),g.crossOrigin="",g.href=u,c&&g.setAttribute("nonce",c),document.head.appendChild(g),p)return new Promise((b,_)=>{g.addEventListener("load",b),g.addEventListener("error",()=>_(new Error(`Unable to preload CSS for ${u}`)))})}))}function s(o){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=o,window.dispatchEvent(l),!l.defaultPrevented)throw o}return i.then(o=>{for(const l of o||[])l.status==="rejected"&&s(l.reason);return t().catch(s)})},RX=v.lazy(()=>Y(()=>import("./index-CFtYHyY0.js"),[]).then(e=>({default:e.Toaster})));function TX(){return f.jsx(v.Suspense,{fallback:null,children:f.jsx(RX,{position:"bottom-right",theme:"system",closeButton:!0,duration:6e3})})}const AX="0.53.0",NX={version:AX},rr="Kanna",ZN="kanna",MX=".kanna",LX=".kanna-dev",IX="KANNA_RUNTIME_PROFILE",ck=`kanna/${NX.version}`,jX="[kanna]",DX=`~/${rr}`;function b0(){var t;return(t=globalThis.process)==null?void 0:t.env}function PX(e=b0()){var t;return((t=e==null?void 0:e[IX])==null?void 0:t.trim().toLowerCase())==="dev"?"dev":"prod"}function OX(e=b0()){return PX(e)==="dev"?LX:MX}function zX(e=b0()){return`~/${OX(e)}`}function BX(e=b0()){return`${zX(e)}/keybindings.json`}function Sg(e){return e?`${ZN} ${e}`:ZN}const JN=e=>{let t;const n=new Set,r=(u,p)=>{const h=typeof u=="function"?u(t):u;if(!Object.is(h,t)){const g=t;t=p??(typeof h!="object"||h===null)?h:Object.assign({},t,h),n.forEach(b=>b(t,g))}},i=()=>t,l={setState:r,getState:i,getInitialState:()=>c,subscribe:u=>(n.add(u),()=>n.delete(u))},c=t=e(r,i,l);return l},FX=(e=>e?JN(e):JN),$X=e=>e;function HX(e,t=$X){const n=xn.useSyncExternalStore(e.subscribe,xn.useCallback(()=>t(e.getState()),[e,t]),xn.useCallback(()=>t(e.getInitialState()),[e,t]));return xn.useDebugValue(n),n}const UX=e=>{const t=FX(e),n=r=>HX(t,r);return Object.assign(n,t),n},no=(e=>UX),jO="always",DO="funk",VX=[{value:"blow",label:"Blow"},{value:"bottle",label:"Bottle"},{value:"frog",label:"Frog"},{value:"funk",label:"Funk"},{value:"glass",label:"Glass"},{value:"ping",label:"Ping"},{value:"pop",label:"Pop"},{value:"purr",label:"Purr"},{value:"tink",label:"Tink"}];function WX(e){switch(e){case"never":case"unfocused":case"always":return e;default:return jO}}function GX(e){switch(e){case"blow":case"bottle":case"frog":case"funk":case"glass":case"ping":case"pop":case"purr":case"tink":return e;default:return DO}}const _c=no()(e=>({chatSoundPreference:jO,chatSoundId:DO,setChatSoundPreference:t=>e({chatSoundPreference:WX(t)}),setChatSoundId:t=>e({chatSoundId:GX(t)})})),qX={blow:"/chat-sounds/Blow.mp3",bottle:"/chat-sounds/Bottle.mp3",frog:"/chat-sounds/Frog.mp3",funk:"/chat-sounds/Funk.mp3",glass:"/chat-sounds/Glass.mp3",ping:"/chat-sounds/Ping.mp3",pop:"/chat-sounds/Pop.mp3",purr:"/chat-sounds/Purr.mp3",tink:"/chat-sounds/Tink.mp3"};function KX(e=document){return e.visibilityState!=="visible"||!e.hasFocus()}function YX(e){const t=new Audio(qX[e]);return t.preload="auto",t.play()}async function yw(e,t){if(t<=0)return;const n=Array.from({length:t},(r,i)=>new Promise(s=>{window.setTimeout(()=>{YX(e).catch(()=>{}).finally(()=>s())},i*90)}));await Promise.all(n)}function XX(e,t=document){return e==="never"?!1:e==="always"?!0:KX(t)}function QX(e){return e.projectGroups.reduce((t,n)=>t+n.chats.reduce((r,i)=>r+(i.unread?1:0)+(i.status==="waiting_for_user"?1:0),0),0)}function eM(e){let t=0;const n=new Set;for(const r of e.projectGroups)for(const i of r.chats)i.unread&&(t+=1),i.status==="waiting_for_user"&&n.add(i.chatId);return{unreadCount:t,waitingChatIds:n}}function ZX(e,t){if(!e)return 0;const n=eM(e),r=eM(t),i=Math.max(0,r.unreadCount-n.unreadCount);let s=0;for(const o of r.waitingChatIds)n.waitingChatIds.has(o)||(s+=1);return i+s}function _w(e){return e.split(/[\s_-]+/).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" ")}const JX=[/^(?:\/usr\/bin\/env\s+)?(?:\/bin\/)?(?:bash|zsh|sh)\s+(?:-[a-zA-Z]*c|-c)\s+(['"])([\s\S]*)\1$/,/^(?:\/usr\/bin\/env\s+)?(?:\/bin\/)?(?:bash|zsh|sh)\s+(?:-[a-zA-Z]*c|-c)\s+(.+)$/,/^(?:\/usr\/bin\/env\s+)?(?:cmd(?:\.exe)?)\s+\/c\s+(['"])([\s\S]*)\1$/i,/^(?:\/usr\/bin\/env\s+)?(?:cmd(?:\.exe)?)\s+\/c\s+(.+)$/i,/^(?:\/usr\/bin\/env\s+)?(?:powershell(?:\.exe)?|pwsh)\s+(?:-NoProfile\s+)?-Command\s+(['"])([\s\S]*)\1$/i,/^(?:\/usr\/bin\/env\s+)?(?:powershell(?:\.exe)?|pwsh)\s+(?:-NoProfile\s+)?-Command\s+(.+)$/i];function eQ(e){const t=e.trim();for(const n of JX){const r=t.match(n);if(!r)continue;const i=(r[2]??r[1]??"").trim();if(i)return i}return t}function uk(e){return e.split("/").pop()||e}const tQ=1440*6e4;function nQ(e,t){const n=Math.max(0,t-e),r=Math.floor(n/1e3),i=Math.floor(r/3600),s=Math.floor(r%3600/60),o=r%60;return i>0?`${i}h ${s}m`:s>0?`${s}m ${o}s`:`${o}s`}function rQ(e){const t=new Date(e),n=t.getHours().toString().padStart(2,"0"),r=t.getMinutes().toString().padStart(2,"0");return`${n}:${r}`}function iQ(e,t){if(e===void 0)return null;const n=Math.max(0,t-e),r=6e4,i=60*r,s=tQ,o=7*s;return n<r?"now":n<i?`${Math.floor(n/r)}m`:n<s?`${Math.floor(n/i)}h`:n<o?`${Math.floor(n/s)}d`:`${Math.floor(n/o)}w`}function sQ(e){return e.lastMessageAt??e._creationTime}const dk=1e3,xv=60*dk,id=60*xv,Ax=24*id;function dl(e){const t=Math.max(0,e);if(t<xv)return`${Math.floor(t/dk)}s`;if(t<id)return`${Math.floor(t/xv)}m`;if(t<Ax){const i=Math.floor(t/id),s=Math.floor(t%id/xv);return s===0?`${i}h`:`${i}h ${s}m`}const n=Math.floor(t/Ax),r=Math.floor(t%Ax/id);return r===0?`${n}d`:`${n}d ${r}h`}function xw(e){const t=Math.max(0,e);if(t>=id)return dl(t);const n=Math.floor(t/dk),r=Math.floor(n/60),i=n%60;return`${r}:${i.toString().padStart(2,"0")}`}function Sw(e){switch(e){case"idle":return"Idle";case"starting":return"Starting";case"running":return"Running";case"waiting_for_user":return"Waiting";case"failed":return"Failed"}}function tM(e){switch(e){case"running":return"active";case"waiting_for_user":return"attention";case"failed":return"destructive";case"idle":case"starting":default:return"muted"}}function nM(e){switch(e){case"active":return"text-emerald-500 dark:text-emerald-400";case"attention":return"text-amber-500 dark:text-amber-400";case"destructive":return"text-destructive";case"muted":default:return"text-muted-foreground"}}function fk(e){const t=e+"CollectionProvider",[n,r]=xa(t),[i,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),o=x=>{const{scope:S,children:C}=x,E=xn.useRef(null),k=xn.useRef(new Map).current;return f.jsx(i,{scope:S,itemMap:k,collectionRef:E,children:C})};o.displayName=t;const l=e+"CollectionSlot",c=Nc(l),u=xn.forwardRef((x,S)=>{const{scope:C,children:E}=x,k=s(l,C),T=yn(S,k.collectionRef);return f.jsx(c,{ref:T,children:E})});u.displayName=l;const p=e+"CollectionItemSlot",h="data-radix-collection-item",g=Nc(p),b=xn.forwardRef((x,S)=>{const{scope:C,children:E,...k}=x,T=xn.useRef(null),A=yn(S,T),N=s(p,C);return xn.useEffect(()=>(N.itemMap.set(T,{ref:T,...k}),()=>void N.itemMap.delete(T))),f.jsx(g,{[h]:"",ref:A,children:E})});b.displayName=p;function _(x){const S=s(e+"CollectionConsumer",x);return xn.useCallback(()=>{const E=S.collectionRef.current;if(!E)return[];const k=Array.from(E.querySelectorAll(`[${h}]`));return Array.from(S.itemMap.values()).sort((N,M)=>k.indexOf(N.ref.current)-k.indexOf(M.ref.current))},[S.collectionRef,S.itemMap])}return[{Provider:o,Slot:u,ItemSlot:b},_,r]}var oQ=v.createContext(void 0);function hk(e){const t=v.useContext(oQ);return e||t||"ltr"}var Nx="rovingFocusGroup.onEntryFocus",aQ={bubbles:!1,cancelable:!0},jp="RovingFocusGroup",[ww,PO,lQ]=fk(jp),[cQ,OO]=xa(jp,[lQ]),[uQ,dQ]=cQ(jp),zO=v.forwardRef((e,t)=>f.jsx(ww.Provider,{scope:e.__scopeRovingFocusGroup,children:f.jsx(ww.Slot,{scope:e.__scopeRovingFocusGroup,children:f.jsx(fQ,{...e,ref:t})})}));zO.displayName=jp;var fQ=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:s,currentTabStopId:o,defaultCurrentTabStopId:l,onCurrentTabStopIdChange:c,onEntryFocus:u,preventScrollOnEntryFocus:p=!1,...h}=e,g=v.useRef(null),b=yn(t,g),_=hk(s),[x,S]=wd({prop:o,defaultProp:l??null,onChange:c,caller:jp}),[C,E]=v.useState(!1),k=Ks(u),T=PO(n),A=v.useRef(!1),[N,M]=v.useState(0);return v.useEffect(()=>{const j=g.current;if(j)return j.addEventListener(Nx,k),()=>j.removeEventListener(Nx,k)},[k]),f.jsx(uQ,{scope:n,orientation:r,dir:_,loop:i,currentTabStopId:x,onItemFocus:v.useCallback(j=>S(j),[S]),onItemShiftTab:v.useCallback(()=>E(!0),[]),onFocusableItemAdd:v.useCallback(()=>M(j=>j+1),[]),onFocusableItemRemove:v.useCallback(()=>M(j=>j-1),[]),children:f.jsx(rn.div,{tabIndex:C||N===0?-1:0,"data-orientation":r,...h,ref:b,style:{outline:"none",...e.style},onMouseDown:tt(e.onMouseDown,()=>{A.current=!0}),onFocus:tt(e.onFocus,j=>{const U=!A.current;if(j.target===j.currentTarget&&U&&!C){const I=new CustomEvent(Nx,aQ);if(j.currentTarget.dispatchEvent(I),!I.defaultPrevented){const P=T().filter(F=>F.focusable),z=P.find(F=>F.active),O=P.find(F=>F.id===x),V=[z,O,...P].filter(Boolean).map(F=>F.ref.current);$O(V,p)}}A.current=!1}),onBlur:tt(e.onBlur,()=>E(!1))})})}),BO="RovingFocusGroupItem",FO=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,c=ha(),u=s||c,p=dQ(BO,n),h=p.currentTabStopId===u,g=PO(n),{onFocusableItemAdd:b,onFocusableItemRemove:_,currentTabStopId:x}=p;return v.useEffect(()=>{if(r)return b(),()=>_()},[r,b,_]),f.jsx(ww.ItemSlot,{scope:n,id:u,focusable:r,active:i,children:f.jsx(rn.span,{tabIndex:h?0:-1,"data-orientation":p.orientation,...l,ref:t,onMouseDown:tt(e.onMouseDown,S=>{r?p.onItemFocus(u):S.preventDefault()}),onFocus:tt(e.onFocus,()=>p.onItemFocus(u)),onKeyDown:tt(e.onKeyDown,S=>{if(S.key==="Tab"&&S.shiftKey){p.onItemShiftTab();return}if(S.target!==S.currentTarget)return;const C=mQ(S,p.orientation,p.dir);if(C!==void 0){if(S.metaKey||S.ctrlKey||S.altKey||S.shiftKey)return;S.preventDefault();let k=g().filter(T=>T.focusable).map(T=>T.ref.current);if(C==="last")k.reverse();else if(C==="prev"||C==="next"){C==="prev"&&k.reverse();const T=k.indexOf(S.currentTarget);k=p.loop?gQ(k,T+1):k.slice(T+1)}setTimeout(()=>$O(k))}}),children:typeof o=="function"?o({isCurrentTabStop:h,hasTabStop:x!=null}):o})})});FO.displayName=BO;var hQ={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function pQ(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function mQ(e,t,n){const r=pQ(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return hQ[r]}function $O(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function gQ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var vQ=zO,bQ=FO,Cw=["Enter"," "],yQ=["ArrowDown","PageUp","Home"],HO=["ArrowUp","PageDown","End"],_Q=[...yQ,...HO],xQ={ltr:[...Cw,"ArrowRight"],rtl:[...Cw,"ArrowLeft"]},SQ={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Dp="Menu",[Zh,wQ,CQ]=fk(Dp),[Wc,UO]=xa(Dp,[CQ,Il,OO]),y0=Il(),VO=OO(),[kQ,Gc]=Wc(Dp),[EQ,Pp]=Wc(Dp),WO=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=y0(t),[c,u]=v.useState(null),p=v.useRef(!1),h=Ks(s),g=hk(i);return v.useEffect(()=>{const b=()=>{p.current=!0,document.addEventListener("pointerdown",_,{capture:!0,once:!0}),document.addEventListener("pointermove",_,{capture:!0,once:!0})},_=()=>p.current=!1;return document.addEventListener("keydown",b,{capture:!0}),()=>{document.removeEventListener("keydown",b,{capture:!0}),document.removeEventListener("pointerdown",_,{capture:!0}),document.removeEventListener("pointermove",_,{capture:!0})}},[]),f.jsx(f0,{...l,children:f.jsx(kQ,{scope:t,open:n,onOpenChange:h,content:c,onContentChange:u,children:f.jsx(EQ,{scope:t,onClose:v.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:p,dir:g,modal:o,children:r})})})};WO.displayName=Dp;var RQ="MenuAnchor",pk=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=y0(n);return f.jsx(Lp,{...i,...r,ref:t})});pk.displayName=RQ;var mk="MenuPortal",[TQ,GO]=Wc(mk,{forceMount:void 0}),qO=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=Gc(mk,t);return f.jsx(TQ,{scope:t,forceMount:n,children:f.jsx(Ts,{present:n||s.open,children:f.jsx(Wd,{asChild:!0,container:i,children:r})})})};qO.displayName=mk;var ws="MenuContent",[AQ,gk]=Wc(ws),KO=v.forwardRef((e,t)=>{const n=GO(ws,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=Gc(ws,e.__scopeMenu),o=Pp(ws,e.__scopeMenu);return f.jsx(Zh.Provider,{scope:e.__scopeMenu,children:f.jsx(Ts,{present:r||s.open,children:f.jsx(Zh.Slot,{scope:e.__scopeMenu,children:o.modal?f.jsx(NQ,{...i,ref:t}):f.jsx(MQ,{...i,ref:t})})})})}),NQ=v.forwardRef((e,t)=>{const n=Gc(ws,e.__scopeMenu),r=v.useRef(null),i=yn(t,r);return v.useEffect(()=>{const s=r.current;if(s)return s0(s)},[]),f.jsx(vk,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:tt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),MQ=v.forwardRef((e,t)=>{const n=Gc(ws,e.__scopeMenu);return f.jsx(vk,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),LQ=Nc("MenuContent.ScrollLock"),vk=v.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:l,onEntryFocus:c,onEscapeKeyDown:u,onPointerDownOutside:p,onFocusOutside:h,onInteractOutside:g,onDismiss:b,disableOutsideScroll:_,...x}=e,S=Gc(ws,n),C=Pp(ws,n),E=y0(n),k=VO(n),T=wQ(n),[A,N]=v.useState(null),M=v.useRef(null),j=yn(t,M,S.onContentChange),U=v.useRef(0),I=v.useRef(""),P=v.useRef(0),z=v.useRef(null),O=v.useRef("right"),$=v.useRef(0),V=_?Ap:v.Fragment,F=_?{as:LQ,allowPinchZoom:!0}:void 0,H=Z=>{var ne,se;const D=I.current+Z,G=T().filter(ce=>!ce.disabled),ee=document.activeElement,B=(ne=G.find(ce=>ce.ref.current===ee))==null?void 0:ne.textValue,le=G.map(ce=>ce.textValue),oe=VQ(le,D,B),J=(se=G.find(ce=>ce.textValue===oe))==null?void 0:se.ref.current;(function ce(de){I.current=de,window.clearTimeout(U.current),de!==""&&(U.current=window.setTimeout(()=>ce(""),1e3))})(D),J&&setTimeout(()=>J.focus())};v.useEffect(()=>()=>window.clearTimeout(U.current),[]),r0();const W=v.useCallback(Z=>{var G,ee;return O.current===((G=z.current)==null?void 0:G.side)&&GQ(Z,(ee=z.current)==null?void 0:ee.area)},[]);return f.jsx(AQ,{scope:n,searchRef:I,onItemEnter:v.useCallback(Z=>{W(Z)&&Z.preventDefault()},[W]),onItemLeave:v.useCallback(Z=>{var D;W(Z)||((D=M.current)==null||D.focus(),N(null))},[W]),onTriggerLeave:v.useCallback(Z=>{W(Z)&&Z.preventDefault()},[W]),pointerGraceTimerRef:P,onPointerGraceIntentChange:v.useCallback(Z=>{z.current=Z},[]),children:f.jsx(V,{...F,children:f.jsx(Tp,{asChild:!0,trapped:i,onMountAutoFocus:tt(s,Z=>{var D;Z.preventDefault(),(D=M.current)==null||D.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:f.jsx(Vd,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:u,onPointerDownOutside:p,onFocusOutside:h,onInteractOutside:g,onDismiss:b,children:f.jsx(vQ,{asChild:!0,...k,dir:C.dir,orientation:"vertical",loop:r,currentTabStopId:A,onCurrentTabStopIdChange:N,onEntryFocus:tt(c,Z=>{C.isUsingKeyboardRef.current||Z.preventDefault()}),preventScrollOnEntryFocus:!0,children:f.jsx(h0,{role:"menu","aria-orientation":"vertical","data-state":u3(S.open),"data-radix-menu-content":"",dir:C.dir,...E,...x,ref:j,style:{outline:"none",...x.style},onKeyDown:tt(x.onKeyDown,Z=>{const G=Z.target.closest("[data-radix-menu-content]")===Z.currentTarget,ee=Z.ctrlKey||Z.altKey||Z.metaKey,B=Z.key.length===1;G&&(Z.key==="Tab"&&Z.preventDefault(),!ee&&B&&H(Z.key));const le=M.current;if(Z.target!==le||!_Q.includes(Z.key))return;Z.preventDefault();const J=T().filter(ne=>!ne.disabled).map(ne=>ne.ref.current);HO.includes(Z.key)&&J.reverse(),HQ(J)}),onBlur:tt(e.onBlur,Z=>{Z.currentTarget.contains(Z.target)||(window.clearTimeout(U.current),I.current="")}),onPointerMove:tt(e.onPointerMove,Jh(Z=>{const D=Z.target,G=$.current!==Z.clientX;if(Z.currentTarget.contains(D)&&G){const ee=Z.clientX>$.current?"right":"left";O.current=ee,$.current=Z.clientX}}))})})})})})})});KO.displayName=ws;var IQ="MenuGroup",bk=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return f.jsx(rn.div,{role:"group",...r,ref:t})});bk.displayName=IQ;var jQ="MenuLabel",YO=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return f.jsx(rn.div,{...r,ref:t})});YO.displayName=jQ;var rb="MenuItem",rM="menu.itemSelect",_0=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=v.useRef(null),o=Pp(rb,e.__scopeMenu),l=gk(rb,e.__scopeMenu),c=yn(t,s),u=v.useRef(!1),p=()=>{const h=s.current;if(!n&&h){const g=new CustomEvent(rM,{bubbles:!0,cancelable:!0});h.addEventListener(rM,b=>r==null?void 0:r(b),{once:!0}),e5(h,g),g.defaultPrevented?u.current=!1:o.onClose()}};return f.jsx(XO,{...i,ref:c,disabled:n,onClick:tt(e.onClick,p),onPointerDown:h=>{var g;(g=e.onPointerDown)==null||g.call(e,h),u.current=!0},onPointerUp:tt(e.onPointerUp,h=>{var g;u.current||(g=h.currentTarget)==null||g.click()}),onKeyDown:tt(e.onKeyDown,h=>{const g=l.searchRef.current!=="";n||g&&h.key===" "||Cw.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});_0.displayName=rb;var XO=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=gk(rb,n),l=VO(n),c=v.useRef(null),u=yn(t,c),[p,h]=v.useState(!1),[g,b]=v.useState("");return v.useEffect(()=>{const _=c.current;_&&b((_.textContent??"").trim())},[s.children]),f.jsx(Zh.ItemSlot,{scope:n,disabled:r,textValue:i??g,children:f.jsx(bQ,{asChild:!0,...l,focusable:!r,children:f.jsx(rn.div,{role:"menuitem","data-highlighted":p?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:tt(e.onPointerMove,Jh(_=>{r?o.onItemLeave(_):(o.onItemEnter(_),_.defaultPrevented||_.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:tt(e.onPointerLeave,Jh(_=>o.onItemLeave(_))),onFocus:tt(e.onFocus,()=>h(!0)),onBlur:tt(e.onBlur,()=>h(!1))})})})}),DQ="MenuCheckboxItem",QO=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return f.jsx(n3,{scope:e.__scopeMenu,checked:n,children:f.jsx(_0,{role:"menuitemcheckbox","aria-checked":ib(n)?"mixed":n,...i,ref:t,"data-state":_k(n),onSelect:tt(i.onSelect,()=>r==null?void 0:r(ib(n)?!0:!n),{checkForDefaultPrevented:!1})})})});QO.displayName=DQ;var ZO="MenuRadioGroup",[PQ,OQ]=Wc(ZO,{value:void 0,onValueChange:()=>{}}),JO=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=Ks(r);return f.jsx(PQ,{scope:e.__scopeMenu,value:n,onValueChange:s,children:f.jsx(bk,{...i,ref:t})})});JO.displayName=ZO;var e3="MenuRadioItem",t3=v.forwardRef((e,t)=>{const{value:n,...r}=e,i=OQ(e3,e.__scopeMenu),s=n===i.value;return f.jsx(n3,{scope:e.__scopeMenu,checked:s,children:f.jsx(_0,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":_k(s),onSelect:tt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});t3.displayName=e3;var yk="MenuItemIndicator",[n3,zQ]=Wc(yk,{checked:!1}),r3=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=zQ(yk,n);return f.jsx(Ts,{present:r||ib(s.checked)||s.checked===!0,children:f.jsx(rn.span,{...i,ref:t,"data-state":_k(s.checked)})})});r3.displayName=yk;var BQ="MenuSeparator",i3=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return f.jsx(rn.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});i3.displayName=BQ;var FQ="MenuArrow",s3=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=y0(n);return f.jsx(p0,{...i,...r,ref:t})});s3.displayName=FQ;var $Q="MenuSub",[UEe,o3]=Wc($Q),yh="MenuSubTrigger",a3=v.forwardRef((e,t)=>{const n=Gc(yh,e.__scopeMenu),r=Pp(yh,e.__scopeMenu),i=o3(yh,e.__scopeMenu),s=gk(yh,e.__scopeMenu),o=v.useRef(null),{pointerGraceTimerRef:l,onPointerGraceIntentChange:c}=s,u={__scopeMenu:e.__scopeMenu},p=v.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return v.useEffect(()=>p,[p]),v.useEffect(()=>{const h=l.current;return()=>{window.clearTimeout(h),c(null)}},[l,c]),f.jsx(pk,{asChild:!0,...u,children:f.jsx(XO,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":u3(n.open),...e,ref:BC(t,i.onTriggerChange),onClick:h=>{var g;(g=e.onClick)==null||g.call(e,h),!(e.disabled||h.defaultPrevented)&&(h.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:tt(e.onPointerMove,Jh(h=>{s.onItemEnter(h),!h.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),p()},100))})),onPointerLeave:tt(e.onPointerLeave,Jh(h=>{var b,_;p();const g=(b=n.content)==null?void 0:b.getBoundingClientRect();if(g){const x=(_=n.content)==null?void 0:_.dataset.side,S=x==="right",C=S?-5:5,E=g[S?"left":"right"],k=g[S?"right":"left"];s.onPointerGraceIntentChange({area:[{x:h.clientX+C,y:h.clientY},{x:E,y:g.top},{x:k,y:g.top},{x:k,y:g.bottom},{x:E,y:g.bottom}],side:x}),window.clearTimeout(l.current),l.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(h),h.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:tt(e.onKeyDown,h=>{var b;const g=s.searchRef.current!=="";e.disabled||g&&h.key===" "||xQ[r.dir].includes(h.key)&&(n.onOpenChange(!0),(b=n.content)==null||b.focus(),h.preventDefault())})})})});a3.displayName=yh;var l3="MenuSubContent",c3=v.forwardRef((e,t)=>{const n=GO(ws,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=Gc(ws,e.__scopeMenu),o=Pp(ws,e.__scopeMenu),l=o3(l3,e.__scopeMenu),c=v.useRef(null),u=yn(t,c);return f.jsx(Zh.Provider,{scope:e.__scopeMenu,children:f.jsx(Ts,{present:r||s.open,children:f.jsx(Zh.Slot,{scope:e.__scopeMenu,children:f.jsx(vk,{id:l.contentId,"aria-labelledby":l.triggerId,...i,ref:u,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:p=>{var h;o.isUsingKeyboardRef.current&&((h=c.current)==null||h.focus()),p.preventDefault()},onCloseAutoFocus:p=>p.preventDefault(),onFocusOutside:tt(e.onFocusOutside,p=>{p.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:tt(e.onEscapeKeyDown,p=>{o.onClose(),p.preventDefault()}),onKeyDown:tt(e.onKeyDown,p=>{var b;const h=p.currentTarget.contains(p.target),g=SQ[o.dir].includes(p.key);h&&g&&(s.onOpenChange(!1),(b=l.trigger)==null||b.focus(),p.preventDefault())})})})})})});c3.displayName=l3;function u3(e){return e?"open":"closed"}function ib(e){return e==="indeterminate"}function _k(e){return ib(e)?"indeterminate":e?"checked":"unchecked"}function HQ(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function UQ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function VQ(e,t,n){const i=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=UQ(e,Math.max(s,0));i.length===1&&(o=o.filter(u=>u!==n));const c=o.find(u=>u.toLowerCase().startsWith(i.toLowerCase()));return c!==n?c:void 0}function WQ(e,t){const{x:n,y:r}=e;let i=!1;for(let s=0,o=t.length-1;s<t.length;o=s++){const l=t[s],c=t[o],u=l.x,p=l.y,h=c.x,g=c.y;p>r!=g>r&&n<(h-u)*(r-p)/(g-p)+u&&(i=!i)}return i}function GQ(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return WQ(n,t)}function Jh(e){return t=>t.pointerType==="mouse"?e(t):void 0}var qQ=WO,KQ=pk,YQ=qO,XQ=KO,QQ=bk,ZQ=YO,JQ=_0,eZ=QO,tZ=JO,nZ=t3,rZ=r3,iZ=i3,sZ=s3,oZ=a3,aZ=c3,xk="ContextMenu",[lZ]=xa(xk,[UO]),vi=UO(),[cZ,d3]=lZ(xk),f3=e=>{const{__scopeContextMenu:t,children:n,onOpenChange:r,dir:i,modal:s=!0}=e,[o,l]=v.useState(!1),c=vi(t),u=Ks(r),p=v.useCallback(h=>{l(h),u(h)},[u]);return f.jsx(cZ,{scope:t,open:o,onOpenChange:p,modal:s,children:f.jsx(qQ,{...c,dir:i,open:o,onOpenChange:p,modal:s,children:n})})};f3.displayName=xk;var h3="ContextMenuTrigger",p3=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,disabled:r=!1,...i}=e,s=d3(h3,n),o=vi(n),l=v.useRef({x:0,y:0}),c=v.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...l.current})}),u=v.useRef(0),p=v.useCallback(()=>window.clearTimeout(u.current),[]),h=g=>{l.current={x:g.clientX,y:g.clientY},s.onOpenChange(!0)};return v.useEffect(()=>p,[p]),v.useEffect(()=>void(r&&p()),[r,p]),f.jsxs(f.Fragment,{children:[f.jsx(KQ,{...o,virtualRef:c}),f.jsx(rn.span,{"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,...i,ref:t,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:tt(e.onContextMenu,g=>{p(),h(g),g.preventDefault()}),onPointerDown:r?e.onPointerDown:tt(e.onPointerDown,wg(g=>{p(),u.current=window.setTimeout(()=>h(g),700)})),onPointerMove:r?e.onPointerMove:tt(e.onPointerMove,wg(p)),onPointerCancel:r?e.onPointerCancel:tt(e.onPointerCancel,wg(p)),onPointerUp:r?e.onPointerUp:tt(e.onPointerUp,wg(p))})]})});p3.displayName=h3;var uZ="ContextMenuPortal",m3=e=>{const{__scopeContextMenu:t,...n}=e,r=vi(t);return f.jsx(YQ,{...r,...n})};m3.displayName=uZ;var g3="ContextMenuContent",v3=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=d3(g3,n),s=vi(n),o=v.useRef(!1);return f.jsx(XQ,{...s,...r,ref:t,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:l=>{var c;(c=e.onCloseAutoFocus)==null||c.call(e,l),!l.defaultPrevented&&o.current&&l.preventDefault(),o.current=!1},onInteractOutside:l=>{var c;(c=e.onInteractOutside)==null||c.call(e,l),!l.defaultPrevented&&!i.modal&&(o.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});v3.displayName=g3;var dZ="ContextMenuGroup",fZ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(QQ,{...i,...r,ref:t})});fZ.displayName=dZ;var hZ="ContextMenuLabel",pZ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(ZQ,{...i,...r,ref:t})});pZ.displayName=hZ;var mZ="ContextMenuItem",b3=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(JQ,{...i,...r,ref:t})});b3.displayName=mZ;var gZ="ContextMenuCheckboxItem",vZ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(eZ,{...i,...r,ref:t})});vZ.displayName=gZ;var bZ="ContextMenuRadioGroup",yZ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(tZ,{...i,...r,ref:t})});yZ.displayName=bZ;var _Z="ContextMenuRadioItem",xZ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(nZ,{...i,...r,ref:t})});xZ.displayName=_Z;var SZ="ContextMenuItemIndicator",wZ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(rZ,{...i,...r,ref:t})});wZ.displayName=SZ;var CZ="ContextMenuSeparator",y3=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(iZ,{...i,...r,ref:t})});y3.displayName=CZ;var kZ="ContextMenuArrow",EZ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(sZ,{...i,...r,ref:t})});EZ.displayName=kZ;var RZ="ContextMenuSubTrigger",TZ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(oZ,{...i,...r,ref:t})});TZ.displayName=RZ;var AZ="ContextMenuSubContent",NZ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(aZ,{...i,...r,ref:t,style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});NZ.displayName=AZ;function wg(e){return t=>t.pointerType!=="mouse"?e(t):void 0}var MZ=f3,LZ=p3,IZ=m3,_3=v3,x3=b3,S3=y3;const w3=v.createContext(null);function qc({onOpenChange:e,...t}){const[n,r]=v.useState(0),i=v.useCallback(()=>{r(s=>s+1),e==null||e(!1)},[e]);return f.jsx(w3.Provider,{value:i,children:f.jsx(MZ,{onOpenChange:e,...t},n)})}const Kc=LZ,jl=v.forwardRef(({className:e,...t},n)=>f.jsx(IZ,{children:f.jsx(_3,{ref:n,className:he("z-50 min-w-[170px] overflow-hidden rounded-xl border border-border bg-background p-1 shadow-lg outline-hidden animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",e),...t})}));jl.displayName=_3.displayName;const jn=v.forwardRef(({className:e,onSelect:t,...n},r)=>{const i=v.useContext(w3);return f.jsx(x3,{ref:r,className:he("relative flex cursor-default select-none items-center gap-2.5 rounded-lg px-3 py-2 text-xs font-medium text-foreground outline-hidden transition-colors hover:bg-muted focus:bg-muted data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),onSelect:s=>{t==null||t(s),i==null||i()},...n})});jn.displayName=x3.displayName;const C3=v.forwardRef(({className:e,...t},n)=>f.jsx(S3,{ref:n,className:he("-mx-1 my-1 h-px bg-border",e),...t}));C3.displayName=S3.displayName;var x0="Popover",[k3]=xa(x0,[Il]),Op=Il(),[jZ,Dl]=k3(x0),E3=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=Op(t),c=v.useRef(null),[u,p]=v.useState(!1),[h,g]=wd({prop:r,defaultProp:i??!1,onChange:s,caller:x0});return f.jsx(f0,{...l,children:f.jsx(jZ,{scope:t,contentId:ha(),triggerRef:c,open:h,onOpenChange:g,onOpenToggle:v.useCallback(()=>g(b=>!b),[g]),hasCustomAnchor:u,onCustomAnchorAdd:v.useCallback(()=>p(!0),[]),onCustomAnchorRemove:v.useCallback(()=>p(!1),[]),modal:o,children:n})})};E3.displayName=x0;var R3="PopoverAnchor",DZ=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Dl(R3,n),s=Op(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return v.useEffect(()=>(o(),()=>l()),[o,l]),f.jsx(Lp,{...s,...r,ref:t})});DZ.displayName=R3;var T3="PopoverTrigger",A3=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Dl(T3,n),s=Op(n),o=yn(t,i.triggerRef),l=f.jsx(rn.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":j3(i.open),...r,ref:o,onClick:tt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:f.jsx(Lp,{asChild:!0,...s,children:l})});A3.displayName=T3;var Sk="PopoverPortal",[PZ,OZ]=k3(Sk,{forceMount:void 0}),N3=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=Dl(Sk,t);return f.jsx(PZ,{scope:t,forceMount:n,children:f.jsx(Ts,{present:n||s.open,children:f.jsx(Wd,{asChild:!0,container:i,children:r})})})};N3.displayName=Sk;var Ed="PopoverContent",M3=v.forwardRef((e,t)=>{const n=OZ(Ed,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=Dl(Ed,e.__scopePopover);return f.jsx(Ts,{present:r||s.open,children:s.modal?f.jsx(BZ,{...i,ref:t}):f.jsx(FZ,{...i,ref:t})})});M3.displayName=Ed;var zZ=Nc("PopoverContent.RemoveScroll"),BZ=v.forwardRef((e,t)=>{const n=Dl(Ed,e.__scopePopover),r=v.useRef(null),i=yn(t,r),s=v.useRef(!1);return v.useEffect(()=>{const o=r.current;if(o)return s0(o)},[]),f.jsx(Ap,{as:zZ,allowPinchZoom:!0,children:f.jsx(L3,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:tt(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:tt(e.onPointerDownOutside,o=>{const l=o.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,u=l.button===2||c;s.current=u},{checkForDefaultPrevented:!1}),onFocusOutside:tt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),FZ=v.forwardRef((e,t)=>{const n=Dl(Ed,e.__scopePopover),r=v.useRef(!1),i=v.useRef(!1);return f.jsx(L3,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var o,l;(o=e.onCloseAutoFocus)==null||o.call(e,s),s.defaultPrevented||(r.current||(l=n.triggerRef.current)==null||l.focus(),s.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:s=>{var c,u;(c=e.onInteractOutside)==null||c.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=s.target;((u=n.triggerRef.current)==null?void 0:u.contains(o))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}})}),L3=v.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:l,onPointerDownOutside:c,onFocusOutside:u,onInteractOutside:p,...h}=e,g=Dl(Ed,n),b=Op(n);return r0(),f.jsx(Tp,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:f.jsx(Vd,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:p,onEscapeKeyDown:l,onPointerDownOutside:c,onFocusOutside:u,onDismiss:()=>g.onOpenChange(!1),children:f.jsx(h0,{"data-state":j3(g.open),role:"dialog",id:g.contentId,...b,...h,ref:t,style:{...h.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),I3="PopoverClose",$Z=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Dl(I3,n);return f.jsx(rn.button,{type:"button",...r,ref:t,onClick:tt(e.onClick,()=>i.onOpenChange(!1))})});$Z.displayName=I3;var HZ="PopoverArrow",UZ=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Op(n);return f.jsx(p0,{...i,...r,ref:t})});UZ.displayName=HZ;function j3(e){return e?"open":"closed"}var VZ=E3,WZ=A3,GZ=N3,D3=M3;const wk=VZ,Ck=WZ,S0=v.forwardRef(({className:e,align:t="center",sideOffset:n=4,...r},i)=>f.jsx(GZ,{children:f.jsx(D3,{ref:i,align:t,sideOffset:n,[Kh]:"",onCloseAutoFocus:s=>{var o;s.preventDefault(),window.dispatchEvent(new Event(Yv)),(o=r.onCloseAutoFocus)==null||o.call(r,s)},className:he("z-50 w-72 rounded-xl border border-border bg-background p-4 shadow-lg outline-hidden animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...r})}));S0.displayName=D3.displayName;function qZ({editorLabel:e,starred:t,onCopyPath:n,onShowArchived:r,onOpenInFinder:i,onOpenInEditor:s,onToggleStar:o,onHide:l,children:c}){return f.jsxs(qc,{children:[f.jsx(Kc,{asChild:!0,children:c}),f.jsxs(jl,{children:[f.jsxs(jn,{onSelect:u=>{u.stopPropagation(),o()},children:[t?f.jsx(XW,{className:"h-3.5 w-3.5"}):f.jsx(QP,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:t?"Unstar project":"Star project"})]}),f.jsxs(jn,{onSelect:u=>{u.stopPropagation(),n()},children:[f.jsx(El,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Copy Path"})]}),f.jsxs(jn,{onSelect:u=>{u.stopPropagation(),r()},children:[f.jsx(MC,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Show Archived"})]}),f.jsxs(jn,{onSelect:u=>{u.stopPropagation(),i()},children:[f.jsx(e0,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Show in Finder"})]}),f.jsxs(jn,{onSelect:u=>{u.stopPropagation(),s()},children:[f.jsx(IC,{className:"h-3.5 w-3.5"}),f.jsxs("span",{className:"text-xs font-medium",children:["Open in ",e]})]}),f.jsxs(jn,{onSelect:u=>{u.stopPropagation(),l()},className:"text-destructive hover:bg-destructive/10 focus:bg-destructive/10",children:[f.jsx(X9,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Hide"})]})]})]})}function KZ({canFork:e,onRename:t,onShare:n,onOpenInFinder:r,onFork:i,onArchive:s,onDelete:o,children:l}){return f.jsxs(qc,{children:[f.jsx(Kc,{asChild:!0,children:l}),f.jsxs(jl,{children:[f.jsxs(jn,{onSelect:c=>{c.preventDefault(),t()},children:[f.jsx(Rp,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Rename"})]}),f.jsxs(jn,{onSelect:c=>{c.preventDefault(),n()},children:[f.jsx(zC,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Share"})]}),f.jsxs(jn,{onSelect:c=>{c.preventDefault(),r()},children:[f.jsx(e0,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Open in Finder"})]}),f.jsxs(jn,{disabled:!e,onSelect:c=>{c.preventDefault(),e&&i()},children:[f.jsx(XP,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Fork"})]}),f.jsxs(jn,{onSelect:c=>{c.preventDefault(),s()},children:[f.jsx(MC,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Archive"})]}),f.jsxs(jn,{onSelect:c=>{c.preventDefault(),o()},className:"text-destructive dark:text-red-400 hover:bg-destructive/10 focus:bg-destructive/10 dark:hover:bg-red-500/20 dark:focus:bg-red-500/20",children:[f.jsx(Ud,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Delete"})]})]})]})}function YZ({stackTitle:e,onRename:t,onEditMembers:n,onDelete:r,children:i}){const[s,o]=v.useState(!1);function l(c){return()=>{o(!1),c()}}return f.jsxs(wk,{open:s,onOpenChange:o,children:[f.jsx(Ck,{asChild:!0,children:i}),f.jsxs(S0,{align:"end",sideOffset:4,className:"w-44 p-1",role:"menu","aria-label":`Actions for ${e}`,children:[f.jsxs("button",{type:"button",role:"menuitem",onClick:l(t),className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs font-medium hover:bg-muted focus-visible:bg-muted outline-hidden",children:[f.jsx(Rp,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Rename"})]}),f.jsxs("button",{type:"button",role:"menuitem",onClick:l(n),className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs font-medium hover:bg-muted focus-visible:bg-muted outline-hidden",children:[f.jsx(ZP,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Edit members"})]}),f.jsxs("button",{type:"button",role:"menuitem",onClick:l(r),className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs font-medium text-destructive dark:text-red-400 hover:bg-destructive/10 focus-visible:bg-destructive/10 dark:hover:bg-red-500/20 dark:focus-visible:bg-red-500/20 outline-hidden",children:[f.jsx(Ud,{className:"h-3.5 w-3.5"}),f.jsxs("span",{children:["Delete ",e]})]})]})]})}function XZ({stackTitle:e,onRename:t,onEditMembers:n,onDelete:r,children:i}){return f.jsxs(qc,{children:[f.jsx(Kc,{asChild:!0,children:i}),f.jsxs(jl,{children:[f.jsxs(jn,{onSelect:s=>{s.preventDefault(),t()},children:[f.jsx(Rp,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Rename"})]}),f.jsxs(jn,{onSelect:s=>{s.preventDefault(),n()},children:[f.jsx(ZP,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Edit members"})]}),f.jsxs(jn,{onSelect:s=>{s.preventDefault(),r()},className:"text-destructive dark:text-red-400 hover:bg-destructive/10 focus:bg-destructive/10 dark:hover:bg-red-500/20 dark:focus:bg-red-500/20",children:[f.jsx(Ud,{className:"h-3.5 w-3.5"}),f.jsxs("span",{className:"text-xs font-medium",children:["Delete ",e]})]})]})]})}function QZ(e){return e.status==="running"||e.status==="starting"?"warning":e.status==="waiting_for_user"?"info":e.status==="failed"?"destructive":e.unread?"success":null}function ZZ(e){switch(e){case"warning":return"bg-warning";case"info":return"bg-info";case"success":return"bg-success";case"destructive":return"bg-destructive";default:return""}}function JZ(e){switch(e){case"warning":return"text-warning";case"info":return"text-info";case"success":return"text-success";case"destructive":return"text-destructive";default:return"text-muted-foreground"}}function eJ({chat:e,activeChatId:t,nowMs:n,shortcutHint:r=null,showShortcutHint:i=!1,onSelectChat:s,onRenameChat:o,onShareChat:l,onOpenInFinder:c,onForkChat:u,onArchiveChat:p,onDeleteChat:h}){const g=(e.status==="running"||e.status==="waiting_for_user")&&e.stateEnteredAt!=null,b=g&&e.stateEnteredAt!=null?`${Sw(e.status)} ${xw(n-e.stateEnteredAt)}`:dl(n-(e.lastMessageAt??e._creationTime)),_=i&&r?r:b,x=i&&!!r,S=LK(e.chatId),C=t===S,E=QZ(e),k=e.canFork?"w-12":g?"w-12 md:w-20":"w-6 md:w-14",T=f.jsxs("div",{"data-chat-id":S,className:he("group flex items-center gap-2 pl-2 pr-1 py-1.5 rounded-md cursor-pointer transition-colors duration-150",C?"bg-muted":"hover:bg-muted/40"),onClick:()=>s(e.chatId),children:[f.jsx("span",{className:"relative flex h-3.5 w-3.5 shrink-0 items-center justify-center","aria-hidden":!0,children:E?f.jsx("span",{className:he("h-2 w-2 rounded-full",ZZ(E))}):null}),f.jsx("span",{className:he("truncate flex-1 text-sm",C?"text-foreground font-medium":"text-foreground/90",e.status==="idle"&&!e.unread&&!C?"text-muted-foreground":""),children:e.title}),f.jsxs("div",{className:he("relative h-6 shrink-0",k),children:[_?x?f.jsx("span",{className:"hidden md:flex absolute inset-0 items-center justify-end pr-0.5 text-[11px] text-foreground transition-opacity duration-150 group-hover:opacity-0",children:f.jsx(LO,{className:"h-4 min-w-4 rounded-sm border-border/50 bg-transparent px-1 text-[10px]",children:r})}):f.jsx("span",{className:he("hidden md:flex absolute inset-0 items-center justify-end pr-1 text-[11px] tabular-nums transition-opacity duration-150 group-hover:opacity-0 whitespace-nowrap",g?JZ(E):"text-muted-foreground"),children:_}):null,f.jsxs("div",{className:he("absolute inset-0 flex items-center justify-end gap-0 transition-opacity duration-150",_?"opacity-100 md:opacity-0 md:group-hover:opacity-100":"opacity-100"),children:[e.canFork?f.jsx(Ke,{variant:"ghost",size:"icon",className:"h-6 w-6 cursor-pointer rounded-sm hover:!bg-transparent !border-0",onClick:A=>{A.stopPropagation(),u(e.chatId)},title:"Fork chat",children:f.jsx(XP,{className:"size-3.5"})}):null,f.jsx(Ke,{variant:"ghost",size:"icon",className:"h-6 w-6 cursor-pointer rounded-sm hover:!bg-transparent !border-0",onClick:A=>{A.stopPropagation(),p(e.chatId)},title:"Archive chat",children:f.jsx(MC,{className:"size-3.5"})})]})]})]},e._id);return f.jsx(KZ,{canFork:e.canFork,onRename:()=>o(e.chatId),onShare:()=>l(e.chatId),onOpenInFinder:()=>c(e.localPath),onFork:()=>u(e.chatId),onArchive:()=>p(e.chatId),onDelete:()=>h(e.chatId),children:T})}const tJ=v.memo(eJ);function nJ(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return v.useMemo(()=>r=>{t.forEach(i=>i(r))},t)}const w0=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Yd(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function kk(e){return"nodeType"in e}function Ii(e){var t,n;return e?Yd(e)?e:kk(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function Ek(e){const{Document:t}=Ii(e);return e instanceof t}function zp(e){return Yd(e)?!1:e instanceof Ii(e).HTMLElement}function P3(e){return e instanceof Ii(e).SVGElement}function Xd(e){return e?Yd(e)?e.document:kk(e)?Ek(e)?e:zp(e)||P3(e)?e.ownerDocument:document:document:document}const Mo=w0?v.useLayoutEffect:v.useEffect;function Rk(e){const t=v.useRef(e);return Mo(()=>{t.current=e}),v.useCallback(function(){for(var n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];return t.current==null?void 0:t.current(...r)},[])}function rJ(){const e=v.useRef(null),t=v.useCallback((r,i)=>{e.current=setInterval(r,i)},[]),n=v.useCallback(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[]);return[t,n]}function ep(e,t){t===void 0&&(t=[e]);const n=v.useRef(e);return Mo(()=>{n.current!==e&&(n.current=e)},t),n}function Bp(e,t){const n=v.useRef();return v.useMemo(()=>{const r=e(n.current);return n.current=r,r},[...t])}function sb(e){const t=Rk(e),n=v.useRef(null),r=v.useCallback(i=>{i!==n.current&&(t==null||t(i,n.current)),n.current=i},[]);return[n,r]}function kw(e){const t=v.useRef();return v.useEffect(()=>{t.current=e},[e]),t.current}let Mx={};function Fp(e,t){return v.useMemo(()=>{if(t)return t;const n=Mx[e]==null?0:Mx[e]+1;return Mx[e]=n,e+"-"+n},[e,t])}function O3(e){return function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return r.reduce((s,o)=>{const l=Object.entries(o);for(const[c,u]of l){const p=s[c];p!=null&&(s[c]=p+e*u)}return s},{...t})}}const fd=O3(1),ob=O3(-1);function iJ(e){return"clientX"in e&&"clientY"in e}function Tk(e){if(!e)return!1;const{KeyboardEvent:t}=Ii(e.target);return t&&e instanceof t}function sJ(e){if(!e)return!1;const{TouchEvent:t}=Ii(e.target);return t&&e instanceof t}function Ew(e){if(sJ(e)){if(e.touches&&e.touches.length){const{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){const{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return iJ(e)?{x:e.clientX,y:e.clientY}:null}const tp=Object.freeze({Translate:{toString(e){if(!e)return;const{x:t,y:n}=e;return"translate3d("+(t?Math.round(t):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(e){if(!e)return;const{scaleX:t,scaleY:n}=e;return"scaleX("+t+") scaleY("+n+")"}},Transform:{toString(e){if(e)return[tp.Translate.toString(e),tp.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),iM="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function oJ(e){return e.matches(iM)?e:e.querySelector(iM)}const aJ={display:"none"};function lJ(e){let{id:t,value:n}=e;return xn.createElement("div",{id:t,style:aJ},n)}function cJ(e){let{id:t,announcement:n,ariaLiveType:r="assertive"}=e;const i={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return xn.createElement("div",{id:t,style:i,role:"status","aria-live":r,"aria-atomic":!0},n)}function uJ(){const[e,t]=v.useState("");return{announce:v.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const z3=v.createContext(null);function dJ(e){const t=v.useContext(z3);v.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function fJ(){const[e]=v.useState(()=>new Set),t=v.useCallback(r=>(e.add(r),()=>e.delete(r)),[e]);return[v.useCallback(r=>{let{type:i,event:s}=r;e.forEach(o=>{var l;return(l=o[i])==null?void 0:l.call(o,s)})},[e]),t]}const hJ={draggable:`
|
|
695
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return v.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},Bq="DialogDescriptionWarning",Fq=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${E5(Bq).contentName}}.`;return v.useEffect(()=>{var s;const i=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&i&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},R5=h5,T5=g5,UC=v5,VC=b5,A5=_5,$q=S5,Hq=C5;function N5(e){var t,n,r="";if(typeof e=="string"||typeof e=="number")r+=e;else if(typeof e=="object")if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=N5(e[t]))&&(r&&(r+=" "),r+=n)}else for(n in e)e[n]&&(r&&(r+=" "),r+=n);return r}function M5(){for(var e,t,n=0,r="",i=arguments.length;n<i;n++)(e=arguments[n])&&(t=N5(e))&&(r&&(r+=" "),r+=t);return r}const Uq=(e,t)=>{const n=new Array(e.length+t.length);for(let r=0;r<e.length;r++)n[r]=e[r];for(let r=0;r<t.length;r++)n[e.length+r]=t[r];return n},Vq=(e,t)=>({classGroupId:e,validator:t}),L5=(e=new Map,t=null,n)=>({nextPart:e,validators:t,classGroupId:n}),Kv="-",NN=[],Wq="arbitrary..",Gq=e=>{const t=Kq(e),{conflictingClassGroups:n,conflictingClassGroupModifiers:r}=e;return{getClassGroupId:o=>{if(o.startsWith("[")&&o.endsWith("]"))return qq(o);const l=o.split(Kv),c=l[0]===""&&l.length>1?1:0;return I5(l,c,t)},getConflictingClassGroupIds:(o,l)=>{if(l){const c=r[o],u=n[o];return c?u?Uq(u,c):c:u||NN}return n[o]||NN}}},I5=(e,t,n)=>{if(e.length-t===0)return n.classGroupId;const i=e[t],s=n.nextPart.get(i);if(s){const u=I5(e,t+1,s);if(u)return u}const o=n.validators;if(o===null)return;const l=t===0?e.join(Kv):e.slice(t).join(Kv),c=o.length;for(let u=0;u<c;u++){const p=o[u];if(p.validator(l))return p.classGroupId}},qq=e=>e.slice(1,-1).indexOf(":")===-1?void 0:(()=>{const t=e.slice(1,-1),n=t.indexOf(":"),r=t.slice(0,n);return r?Wq+r:void 0})(),Kq=e=>{const{theme:t,classGroups:n}=e;return Yq(n,t)},Yq=(e,t)=>{const n=L5();for(const r in e){const i=e[r];WC(i,n,r,t)}return n},WC=(e,t,n,r)=>{const i=e.length;for(let s=0;s<i;s++){const o=e[s];Xq(o,t,n,r)}},Xq=(e,t,n,r)=>{if(typeof e=="string"){Qq(e,t,n);return}if(typeof e=="function"){Zq(e,t,n,r);return}Jq(e,t,n,r)},Qq=(e,t,n)=>{const r=e===""?t:j5(t,e);r.classGroupId=n},Zq=(e,t,n,r)=>{if(eK(e)){WC(e(r),t,n,r);return}t.validators===null&&(t.validators=[]),t.validators.push(Vq(n,e))},Jq=(e,t,n,r)=>{const i=Object.entries(e),s=i.length;for(let o=0;o<s;o++){const[l,c]=i[o];WC(c,j5(t,l),n,r)}},j5=(e,t)=>{let n=e;const r=t.split(Kv),i=r.length;for(let s=0;s<i;s++){const o=r[s];let l=n.nextPart.get(o);l||(l=L5(),n.nextPart.set(o,l)),n=l}return n},eK=e=>"isThemeGetter"in e&&e.isThemeGetter===!0,tK=e=>{if(e<1)return{get:()=>{},set:()=>{}};let t=0,n=Object.create(null),r=Object.create(null);const i=(s,o)=>{n[s]=o,t++,t>e&&(t=0,r=n,n=Object.create(null))};return{get(s){let o=n[s];if(o!==void 0)return o;if((o=r[s])!==void 0)return i(s,o),o},set(s,o){s in n?n[s]=o:i(s,o)}}},hw="!",MN=":",nK=[],LN=(e,t,n,r,i)=>({modifiers:e,hasImportantModifier:t,baseClassName:n,maybePostfixModifierPosition:r,isExternal:i}),rK=e=>{const{prefix:t,experimentalParseClassName:n}=e;let r=i=>{const s=[];let o=0,l=0,c=0,u;const p=i.length;for(let x=0;x<p;x++){const S=i[x];if(o===0&&l===0){if(S===MN){s.push(i.slice(c,x)),c=x+1;continue}if(S==="/"){u=x;continue}}S==="["?o++:S==="]"?o--:S==="("?l++:S===")"&&l--}const h=s.length===0?i:i.slice(c);let g=h,b=!1;h.endsWith(hw)?(g=h.slice(0,-1),b=!0):h.startsWith(hw)&&(g=h.slice(1),b=!0);const _=u&&u>c?u-c:void 0;return LN(s,b,g,_)};if(t){const i=t+MN,s=r;r=o=>o.startsWith(i)?s(o.slice(i.length)):LN(nK,!1,o,void 0,!0)}if(n){const i=r;r=s=>n({className:s,parseClassName:i})}return r},iK=e=>{const t=new Map;return e.orderSensitiveModifiers.forEach((n,r)=>{t.set(n,1e6+r)}),n=>{const r=[];let i=[];for(let s=0;s<n.length;s++){const o=n[s],l=o[0]==="[",c=t.has(o);l||c?(i.length>0&&(i.sort(),r.push(...i),i=[]),r.push(o)):i.push(o)}return i.length>0&&(i.sort(),r.push(...i)),r}},sK=e=>({cache:tK(e.cacheSize),parseClassName:rK(e),sortModifiers:iK(e),...Gq(e)}),oK=/\s+/,aK=(e,t)=>{const{parseClassName:n,getClassGroupId:r,getConflictingClassGroupIds:i,sortModifiers:s}=t,o=[],l=e.trim().split(oK);let c="";for(let u=l.length-1;u>=0;u-=1){const p=l[u],{isExternal:h,modifiers:g,hasImportantModifier:b,baseClassName:_,maybePostfixModifierPosition:x}=n(p);if(h){c=p+(c.length>0?" "+c:c);continue}let S=!!x,C=r(S?_.substring(0,x):_);if(!C){if(!S){c=p+(c.length>0?" "+c:c);continue}if(C=r(_),!C){c=p+(c.length>0?" "+c:c);continue}S=!1}const E=g.length===0?"":g.length===1?g[0]:s(g).join(":"),k=b?E+hw:E,T=k+C;if(o.indexOf(T)>-1)continue;o.push(T);const A=i(C,S);for(let N=0;N<A.length;++N){const M=A[N];o.push(k+M)}c=p+(c.length>0?" "+c:c)}return c},lK=(...e)=>{let t=0,n,r,i="";for(;t<e.length;)(n=e[t++])&&(r=D5(n))&&(i&&(i+=" "),i+=r);return i},D5=e=>{if(typeof e=="string")return e;let t,n="";for(let r=0;r<e.length;r++)e[r]&&(t=D5(e[r]))&&(n&&(n+=" "),n+=t);return n},cK=(e,...t)=>{let n,r,i,s;const o=c=>{const u=t.reduce((p,h)=>h(p),e());return n=sK(u),r=n.cache.get,i=n.cache.set,s=l,l(c)},l=c=>{const u=r(c);if(u)return u;const p=aK(c,n);return i(c,p),p};return s=o,(...c)=>s(lK(...c))},uK=[],yr=e=>{const t=n=>n[e]||uK;return t.isThemeGetter=!0,t},P5=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,O5=/^\((?:(\w[\w-]*):)?(.+)\)$/i,dK=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,fK=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,hK=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,pK=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,mK=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,gK=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,el=e=>dK.test(e),qt=e=>!!e&&!Number.isNaN(Number(e)),tl=e=>!!e&&Number.isInteger(Number(e)),kx=e=>e.endsWith("%")&&qt(e.slice(0,-1)),Zo=e=>fK.test(e),z5=()=>!0,vK=e=>hK.test(e)&&!pK.test(e),GC=()=>!1,bK=e=>mK.test(e),yK=e=>gK.test(e),_K=e=>!at(e)&&!ct(e),xK=e=>Ll(e,$5,GC),at=e=>P5.test(e),sc=e=>Ll(e,H5,vK),IN=e=>Ll(e,AK,qt),SK=e=>Ll(e,V5,z5),wK=e=>Ll(e,U5,GC),jN=e=>Ll(e,B5,GC),CK=e=>Ll(e,F5,yK),yg=e=>Ll(e,W5,bK),ct=e=>O5.test(e),eh=e=>Vc(e,H5),kK=e=>Vc(e,U5),DN=e=>Vc(e,B5),EK=e=>Vc(e,$5),RK=e=>Vc(e,F5),_g=e=>Vc(e,W5,!0),TK=e=>Vc(e,V5,!0),Ll=(e,t,n)=>{const r=P5.exec(e);return r?r[1]?t(r[1]):n(r[2]):!1},Vc=(e,t,n=!1)=>{const r=O5.exec(e);return r?r[1]?t(r[1]):n:!1},B5=e=>e==="position"||e==="percentage",F5=e=>e==="image"||e==="url",$5=e=>e==="length"||e==="size"||e==="bg-size",H5=e=>e==="length",AK=e=>e==="number",U5=e=>e==="family-name",V5=e=>e==="number"||e==="weight",W5=e=>e==="shadow",NK=()=>{const e=yr("color"),t=yr("font"),n=yr("text"),r=yr("font-weight"),i=yr("tracking"),s=yr("leading"),o=yr("breakpoint"),l=yr("container"),c=yr("spacing"),u=yr("radius"),p=yr("shadow"),h=yr("inset-shadow"),g=yr("text-shadow"),b=yr("drop-shadow"),_=yr("blur"),x=yr("perspective"),S=yr("aspect"),C=yr("ease"),E=yr("animate"),k=()=>["auto","avoid","all","avoid-page","page","left","right","column"],T=()=>["center","top","bottom","left","right","top-left","left-top","top-right","right-top","bottom-right","right-bottom","bottom-left","left-bottom"],A=()=>[...T(),ct,at],N=()=>["auto","hidden","clip","visible","scroll"],M=()=>["auto","contain","none"],j=()=>[ct,at,c],U=()=>[el,"full","auto",...j()],I=()=>[tl,"none","subgrid",ct,at],P=()=>["auto",{span:["full",tl,ct,at]},tl,ct,at],z=()=>[tl,"auto",ct,at],O=()=>["auto","min","max","fr",ct,at],$=()=>["start","end","center","between","around","evenly","stretch","baseline","center-safe","end-safe"],V=()=>["start","end","center","stretch","center-safe","end-safe"],F=()=>["auto",...j()],H=()=>[el,"auto","full","dvw","dvh","lvw","lvh","svw","svh","min","max","fit",...j()],W=()=>[el,"screen","full","dvw","lvw","svw","min","max","fit",...j()],Z=()=>[el,"screen","full","lh","dvh","lvh","svh","min","max","fit",...j()],D=()=>[e,ct,at],G=()=>[...T(),DN,jN,{position:[ct,at]}],ee=()=>["no-repeat",{repeat:["","x","y","space","round"]}],B=()=>["auto","cover","contain",EK,xK,{size:[ct,at]}],le=()=>[kx,eh,sc],oe=()=>["","none","full",u,ct,at],J=()=>["",qt,eh,sc],ne=()=>["solid","dashed","dotted","double"],se=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],ce=()=>[qt,kx,DN,jN],de=()=>["","none",_,ct,at],Ne=()=>["none",qt,ct,at],we=()=>["none",qt,ct,at],je=()=>[qt,ct,at],fe=()=>[el,"full",...j()];return{cacheSize:500,theme:{animate:["spin","ping","pulse","bounce"],aspect:["video"],blur:[Zo],breakpoint:[Zo],color:[z5],container:[Zo],"drop-shadow":[Zo],ease:["in","out","in-out"],font:[_K],"font-weight":["thin","extralight","light","normal","medium","semibold","bold","extrabold","black"],"inset-shadow":[Zo],leading:["none","tight","snug","normal","relaxed","loose"],perspective:["dramatic","near","normal","midrange","distant","none"],radius:[Zo],shadow:[Zo],spacing:["px",qt],text:[Zo],"text-shadow":[Zo],tracking:["tighter","tight","normal","wide","wider","widest"]},classGroups:{aspect:[{aspect:["auto","square",el,at,ct,S]}],container:["container"],columns:[{columns:[qt,at,ct,l]}],"break-after":[{"break-after":k()}],"break-before":[{"break-before":k()}],"break-inside":[{"break-inside":["auto","avoid","avoid-page","avoid-column"]}],"box-decoration":[{"box-decoration":["slice","clone"]}],box:[{box:["border","content"]}],display:["block","inline-block","inline","flex","inline-flex","table","inline-table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row-group","table-row","flow-root","grid","inline-grid","contents","list-item","hidden"],sr:["sr-only","not-sr-only"],float:[{float:["right","left","none","start","end"]}],clear:[{clear:["left","right","both","none","start","end"]}],isolation:["isolate","isolation-auto"],"object-fit":[{object:["contain","cover","fill","none","scale-down"]}],"object-position":[{object:A()}],overflow:[{overflow:N()}],"overflow-x":[{"overflow-x":N()}],"overflow-y":[{"overflow-y":N()}],overscroll:[{overscroll:M()}],"overscroll-x":[{"overscroll-x":M()}],"overscroll-y":[{"overscroll-y":M()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:U()}],"inset-x":[{"inset-x":U()}],"inset-y":[{"inset-y":U()}],start:[{"inset-s":U(),start:U()}],end:[{"inset-e":U(),end:U()}],"inset-bs":[{"inset-bs":U()}],"inset-be":[{"inset-be":U()}],top:[{top:U()}],right:[{right:U()}],bottom:[{bottom:U()}],left:[{left:U()}],visibility:["visible","invisible","collapse"],z:[{z:[tl,"auto",ct,at]}],basis:[{basis:[el,"full","auto",l,...j()]}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["nowrap","wrap","wrap-reverse"]}],flex:[{flex:[qt,el,"auto","initial","none",at]}],grow:[{grow:["",qt,ct,at]}],shrink:[{shrink:["",qt,ct,at]}],order:[{order:[tl,"first","last","none",ct,at]}],"grid-cols":[{"grid-cols":I()}],"col-start-end":[{col:P()}],"col-start":[{"col-start":z()}],"col-end":[{"col-end":z()}],"grid-rows":[{"grid-rows":I()}],"row-start-end":[{row:P()}],"row-start":[{"row-start":z()}],"row-end":[{"row-end":z()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":O()}],"auto-rows":[{"auto-rows":O()}],gap:[{gap:j()}],"gap-x":[{"gap-x":j()}],"gap-y":[{"gap-y":j()}],"justify-content":[{justify:[...$(),"normal"]}],"justify-items":[{"justify-items":[...V(),"normal"]}],"justify-self":[{"justify-self":["auto",...V()]}],"align-content":[{content:["normal",...$()]}],"align-items":[{items:[...V(),{baseline:["","last"]}]}],"align-self":[{self:["auto",...V(),{baseline:["","last"]}]}],"place-content":[{"place-content":$()}],"place-items":[{"place-items":[...V(),"baseline"]}],"place-self":[{"place-self":["auto",...V()]}],p:[{p:j()}],px:[{px:j()}],py:[{py:j()}],ps:[{ps:j()}],pe:[{pe:j()}],pbs:[{pbs:j()}],pbe:[{pbe:j()}],pt:[{pt:j()}],pr:[{pr:j()}],pb:[{pb:j()}],pl:[{pl:j()}],m:[{m:F()}],mx:[{mx:F()}],my:[{my:F()}],ms:[{ms:F()}],me:[{me:F()}],mbs:[{mbs:F()}],mbe:[{mbe:F()}],mt:[{mt:F()}],mr:[{mr:F()}],mb:[{mb:F()}],ml:[{ml:F()}],"space-x":[{"space-x":j()}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":j()}],"space-y-reverse":["space-y-reverse"],size:[{size:H()}],"inline-size":[{inline:["auto",...W()]}],"min-inline-size":[{"min-inline":["auto",...W()]}],"max-inline-size":[{"max-inline":["none",...W()]}],"block-size":[{block:["auto",...Z()]}],"min-block-size":[{"min-block":["auto",...Z()]}],"max-block-size":[{"max-block":["none",...Z()]}],w:[{w:[l,"screen",...H()]}],"min-w":[{"min-w":[l,"screen","none",...H()]}],"max-w":[{"max-w":[l,"screen","none","prose",{screen:[o]},...H()]}],h:[{h:["screen","lh",...H()]}],"min-h":[{"min-h":["screen","lh","none",...H()]}],"max-h":[{"max-h":["screen","lh",...H()]}],"font-size":[{text:["base",n,eh,sc]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:[r,TK,SK]}],"font-stretch":[{"font-stretch":["ultra-condensed","extra-condensed","condensed","semi-condensed","normal","semi-expanded","expanded","extra-expanded","ultra-expanded",kx,at]}],"font-family":[{font:[kK,wK,t]}],"font-features":[{"font-features":[at]}],"fvn-normal":["normal-nums"],"fvn-ordinal":["ordinal"],"fvn-slashed-zero":["slashed-zero"],"fvn-figure":["lining-nums","oldstyle-nums"],"fvn-spacing":["proportional-nums","tabular-nums"],"fvn-fraction":["diagonal-fractions","stacked-fractions"],tracking:[{tracking:[i,ct,at]}],"line-clamp":[{"line-clamp":[qt,"none",ct,IN]}],leading:[{leading:[s,...j()]}],"list-image":[{"list-image":["none",ct,at]}],"list-style-position":[{list:["inside","outside"]}],"list-style-type":[{list:["disc","decimal","none",ct,at]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"placeholder-color":[{placeholder:D()}],"text-color":[{text:D()}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...ne(),"wavy"]}],"text-decoration-thickness":[{decoration:[qt,"from-font","auto",ct,sc]}],"text-decoration-color":[{decoration:D()}],"underline-offset":[{"underline-offset":[qt,"auto",ct,at]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:j()}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",ct,at]}],whitespace:[{whitespace:["normal","nowrap","pre","pre-line","pre-wrap","break-spaces"]}],break:[{break:["normal","words","all","keep"]}],wrap:[{wrap:["break-word","anywhere","normal"]}],hyphens:[{hyphens:["none","manual","auto"]}],content:[{content:["none",ct,at]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:G()}],"bg-repeat":[{bg:ee()}],"bg-size":[{bg:B()}],"bg-image":[{bg:["none",{linear:[{to:["t","tr","r","br","b","bl","l","tl"]},tl,ct,at],radial:["",ct,at],conic:[tl,ct,at]},RK,CK]}],"bg-color":[{bg:D()}],"gradient-from-pos":[{from:le()}],"gradient-via-pos":[{via:le()}],"gradient-to-pos":[{to:le()}],"gradient-from":[{from:D()}],"gradient-via":[{via:D()}],"gradient-to":[{to:D()}],rounded:[{rounded:oe()}],"rounded-s":[{"rounded-s":oe()}],"rounded-e":[{"rounded-e":oe()}],"rounded-t":[{"rounded-t":oe()}],"rounded-r":[{"rounded-r":oe()}],"rounded-b":[{"rounded-b":oe()}],"rounded-l":[{"rounded-l":oe()}],"rounded-ss":[{"rounded-ss":oe()}],"rounded-se":[{"rounded-se":oe()}],"rounded-ee":[{"rounded-ee":oe()}],"rounded-es":[{"rounded-es":oe()}],"rounded-tl":[{"rounded-tl":oe()}],"rounded-tr":[{"rounded-tr":oe()}],"rounded-br":[{"rounded-br":oe()}],"rounded-bl":[{"rounded-bl":oe()}],"border-w":[{border:J()}],"border-w-x":[{"border-x":J()}],"border-w-y":[{"border-y":J()}],"border-w-s":[{"border-s":J()}],"border-w-e":[{"border-e":J()}],"border-w-bs":[{"border-bs":J()}],"border-w-be":[{"border-be":J()}],"border-w-t":[{"border-t":J()}],"border-w-r":[{"border-r":J()}],"border-w-b":[{"border-b":J()}],"border-w-l":[{"border-l":J()}],"divide-x":[{"divide-x":J()}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":J()}],"divide-y-reverse":["divide-y-reverse"],"border-style":[{border:[...ne(),"hidden","none"]}],"divide-style":[{divide:[...ne(),"hidden","none"]}],"border-color":[{border:D()}],"border-color-x":[{"border-x":D()}],"border-color-y":[{"border-y":D()}],"border-color-s":[{"border-s":D()}],"border-color-e":[{"border-e":D()}],"border-color-bs":[{"border-bs":D()}],"border-color-be":[{"border-be":D()}],"border-color-t":[{"border-t":D()}],"border-color-r":[{"border-r":D()}],"border-color-b":[{"border-b":D()}],"border-color-l":[{"border-l":D()}],"divide-color":[{divide:D()}],"outline-style":[{outline:[...ne(),"none","hidden"]}],"outline-offset":[{"outline-offset":[qt,ct,at]}],"outline-w":[{outline:["",qt,eh,sc]}],"outline-color":[{outline:D()}],shadow:[{shadow:["","none",p,_g,yg]}],"shadow-color":[{shadow:D()}],"inset-shadow":[{"inset-shadow":["none",h,_g,yg]}],"inset-shadow-color":[{"inset-shadow":D()}],"ring-w":[{ring:J()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:D()}],"ring-offset-w":[{"ring-offset":[qt,sc]}],"ring-offset-color":[{"ring-offset":D()}],"inset-ring-w":[{"inset-ring":J()}],"inset-ring-color":[{"inset-ring":D()}],"text-shadow":[{"text-shadow":["none",g,_g,yg]}],"text-shadow-color":[{"text-shadow":D()}],opacity:[{opacity:[qt,ct,at]}],"mix-blend":[{"mix-blend":[...se(),"plus-darker","plus-lighter"]}],"bg-blend":[{"bg-blend":se()}],"mask-clip":[{"mask-clip":["border","padding","content","fill","stroke","view"]},"mask-no-clip"],"mask-composite":[{mask:["add","subtract","intersect","exclude"]}],"mask-image-linear-pos":[{"mask-linear":[qt]}],"mask-image-linear-from-pos":[{"mask-linear-from":ce()}],"mask-image-linear-to-pos":[{"mask-linear-to":ce()}],"mask-image-linear-from-color":[{"mask-linear-from":D()}],"mask-image-linear-to-color":[{"mask-linear-to":D()}],"mask-image-t-from-pos":[{"mask-t-from":ce()}],"mask-image-t-to-pos":[{"mask-t-to":ce()}],"mask-image-t-from-color":[{"mask-t-from":D()}],"mask-image-t-to-color":[{"mask-t-to":D()}],"mask-image-r-from-pos":[{"mask-r-from":ce()}],"mask-image-r-to-pos":[{"mask-r-to":ce()}],"mask-image-r-from-color":[{"mask-r-from":D()}],"mask-image-r-to-color":[{"mask-r-to":D()}],"mask-image-b-from-pos":[{"mask-b-from":ce()}],"mask-image-b-to-pos":[{"mask-b-to":ce()}],"mask-image-b-from-color":[{"mask-b-from":D()}],"mask-image-b-to-color":[{"mask-b-to":D()}],"mask-image-l-from-pos":[{"mask-l-from":ce()}],"mask-image-l-to-pos":[{"mask-l-to":ce()}],"mask-image-l-from-color":[{"mask-l-from":D()}],"mask-image-l-to-color":[{"mask-l-to":D()}],"mask-image-x-from-pos":[{"mask-x-from":ce()}],"mask-image-x-to-pos":[{"mask-x-to":ce()}],"mask-image-x-from-color":[{"mask-x-from":D()}],"mask-image-x-to-color":[{"mask-x-to":D()}],"mask-image-y-from-pos":[{"mask-y-from":ce()}],"mask-image-y-to-pos":[{"mask-y-to":ce()}],"mask-image-y-from-color":[{"mask-y-from":D()}],"mask-image-y-to-color":[{"mask-y-to":D()}],"mask-image-radial":[{"mask-radial":[ct,at]}],"mask-image-radial-from-pos":[{"mask-radial-from":ce()}],"mask-image-radial-to-pos":[{"mask-radial-to":ce()}],"mask-image-radial-from-color":[{"mask-radial-from":D()}],"mask-image-radial-to-color":[{"mask-radial-to":D()}],"mask-image-radial-shape":[{"mask-radial":["circle","ellipse"]}],"mask-image-radial-size":[{"mask-radial":[{closest:["side","corner"],farthest:["side","corner"]}]}],"mask-image-radial-pos":[{"mask-radial-at":T()}],"mask-image-conic-pos":[{"mask-conic":[qt]}],"mask-image-conic-from-pos":[{"mask-conic-from":ce()}],"mask-image-conic-to-pos":[{"mask-conic-to":ce()}],"mask-image-conic-from-color":[{"mask-conic-from":D()}],"mask-image-conic-to-color":[{"mask-conic-to":D()}],"mask-mode":[{mask:["alpha","luminance","match"]}],"mask-origin":[{"mask-origin":["border","padding","content","fill","stroke","view"]}],"mask-position":[{mask:G()}],"mask-repeat":[{mask:ee()}],"mask-size":[{mask:B()}],"mask-type":[{"mask-type":["alpha","luminance"]}],"mask-image":[{mask:["none",ct,at]}],filter:[{filter:["","none",ct,at]}],blur:[{blur:de()}],brightness:[{brightness:[qt,ct,at]}],contrast:[{contrast:[qt,ct,at]}],"drop-shadow":[{"drop-shadow":["","none",b,_g,yg]}],"drop-shadow-color":[{"drop-shadow":D()}],grayscale:[{grayscale:["",qt,ct,at]}],"hue-rotate":[{"hue-rotate":[qt,ct,at]}],invert:[{invert:["",qt,ct,at]}],saturate:[{saturate:[qt,ct,at]}],sepia:[{sepia:["",qt,ct,at]}],"backdrop-filter":[{"backdrop-filter":["","none",ct,at]}],"backdrop-blur":[{"backdrop-blur":de()}],"backdrop-brightness":[{"backdrop-brightness":[qt,ct,at]}],"backdrop-contrast":[{"backdrop-contrast":[qt,ct,at]}],"backdrop-grayscale":[{"backdrop-grayscale":["",qt,ct,at]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[qt,ct,at]}],"backdrop-invert":[{"backdrop-invert":["",qt,ct,at]}],"backdrop-opacity":[{"backdrop-opacity":[qt,ct,at]}],"backdrop-saturate":[{"backdrop-saturate":[qt,ct,at]}],"backdrop-sepia":[{"backdrop-sepia":["",qt,ct,at]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":j()}],"border-spacing-x":[{"border-spacing-x":j()}],"border-spacing-y":[{"border-spacing-y":j()}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["","all","colors","opacity","shadow","transform","none",ct,at]}],"transition-behavior":[{transition:["normal","discrete"]}],duration:[{duration:[qt,"initial",ct,at]}],ease:[{ease:["linear","initial",C,ct,at]}],delay:[{delay:[qt,ct,at]}],animate:[{animate:["none",E,ct,at]}],backface:[{backface:["hidden","visible"]}],perspective:[{perspective:[x,ct,at]}],"perspective-origin":[{"perspective-origin":A()}],rotate:[{rotate:Ne()}],"rotate-x":[{"rotate-x":Ne()}],"rotate-y":[{"rotate-y":Ne()}],"rotate-z":[{"rotate-z":Ne()}],scale:[{scale:we()}],"scale-x":[{"scale-x":we()}],"scale-y":[{"scale-y":we()}],"scale-z":[{"scale-z":we()}],"scale-3d":["scale-3d"],skew:[{skew:je()}],"skew-x":[{"skew-x":je()}],"skew-y":[{"skew-y":je()}],transform:[{transform:[ct,at,"","none","gpu","cpu"]}],"transform-origin":[{origin:A()}],"transform-style":[{transform:["3d","flat"]}],translate:[{translate:fe()}],"translate-x":[{"translate-x":fe()}],"translate-y":[{"translate-y":fe()}],"translate-z":[{"translate-z":fe()}],"translate-none":["translate-none"],accent:[{accent:D()}],appearance:[{appearance:["none","auto"]}],"caret-color":[{caret:D()}],"color-scheme":[{scheme:["normal","dark","light","light-dark","only-dark","only-light"]}],cursor:[{cursor:["auto","default","pointer","wait","text","move","help","not-allowed","none","context-menu","progress","cell","crosshair","vertical-text","alias","copy","no-drop","grab","grabbing","all-scroll","col-resize","row-resize","n-resize","e-resize","s-resize","w-resize","ne-resize","nw-resize","se-resize","sw-resize","ew-resize","ns-resize","nesw-resize","nwse-resize","zoom-in","zoom-out",ct,at]}],"field-sizing":[{"field-sizing":["fixed","content"]}],"pointer-events":[{"pointer-events":["auto","none"]}],resize:[{resize:["none","","y","x"]}],"scroll-behavior":[{scroll:["auto","smooth"]}],"scroll-m":[{"scroll-m":j()}],"scroll-mx":[{"scroll-mx":j()}],"scroll-my":[{"scroll-my":j()}],"scroll-ms":[{"scroll-ms":j()}],"scroll-me":[{"scroll-me":j()}],"scroll-mbs":[{"scroll-mbs":j()}],"scroll-mbe":[{"scroll-mbe":j()}],"scroll-mt":[{"scroll-mt":j()}],"scroll-mr":[{"scroll-mr":j()}],"scroll-mb":[{"scroll-mb":j()}],"scroll-ml":[{"scroll-ml":j()}],"scroll-p":[{"scroll-p":j()}],"scroll-px":[{"scroll-px":j()}],"scroll-py":[{"scroll-py":j()}],"scroll-ps":[{"scroll-ps":j()}],"scroll-pe":[{"scroll-pe":j()}],"scroll-pbs":[{"scroll-pbs":j()}],"scroll-pbe":[{"scroll-pbe":j()}],"scroll-pt":[{"scroll-pt":j()}],"scroll-pr":[{"scroll-pr":j()}],"scroll-pb":[{"scroll-pb":j()}],"scroll-pl":[{"scroll-pl":j()}],"snap-align":[{snap:["start","end","center","align-none"]}],"snap-stop":[{snap:["normal","always"]}],"snap-type":[{snap:["none","x","y","both"]}],"snap-strictness":[{snap:["mandatory","proximity"]}],touch:[{touch:["auto","none","manipulation"]}],"touch-x":[{"touch-pan":["x","left","right"]}],"touch-y":[{"touch-pan":["y","up","down"]}],"touch-pz":["touch-pinch-zoom"],select:[{select:["none","text","all","auto"]}],"will-change":[{"will-change":["auto","scroll","contents","transform",ct,at]}],fill:[{fill:["none",...D()]}],"stroke-w":[{stroke:[qt,eh,sc,IN]}],stroke:[{stroke:["none",...D()]}],"forced-color-adjust":[{"forced-color-adjust":["auto","none"]}]},conflictingClassGroups:{overflow:["overflow-x","overflow-y"],overscroll:["overscroll-x","overscroll-y"],inset:["inset-x","inset-y","inset-bs","inset-be","start","end","top","right","bottom","left"],"inset-x":["right","left"],"inset-y":["top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pbs","pbe","pt","pr","pb","pl"],px:["pr","pl"],py:["pt","pb"],m:["mx","my","ms","me","mbs","mbe","mt","mr","mb","ml"],mx:["mr","ml"],my:["mt","mb"],size:["w","h"],"font-size":["leading"],"fvn-normal":["fvn-ordinal","fvn-slashed-zero","fvn-figure","fvn-spacing","fvn-fraction"],"fvn-ordinal":["fvn-normal"],"fvn-slashed-zero":["fvn-normal"],"fvn-figure":["fvn-normal"],"fvn-spacing":["fvn-normal"],"fvn-fraction":["fvn-normal"],"line-clamp":["display","overflow"],rounded:["rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl"],"rounded-s":["rounded-ss","rounded-es"],"rounded-e":["rounded-se","rounded-ee"],"rounded-t":["rounded-tl","rounded-tr"],"rounded-r":["rounded-tr","rounded-br"],"rounded-b":["rounded-br","rounded-bl"],"rounded-l":["rounded-tl","rounded-bl"],"border-spacing":["border-spacing-x","border-spacing-y"],"border-w":["border-w-x","border-w-y","border-w-s","border-w-e","border-w-bs","border-w-be","border-w-t","border-w-r","border-w-b","border-w-l"],"border-w-x":["border-w-r","border-w-l"],"border-w-y":["border-w-t","border-w-b"],"border-color":["border-color-x","border-color-y","border-color-s","border-color-e","border-color-bs","border-color-be","border-color-t","border-color-r","border-color-b","border-color-l"],"border-color-x":["border-color-r","border-color-l"],"border-color-y":["border-color-t","border-color-b"],translate:["translate-x","translate-y","translate-none"],"translate-none":["translate","translate-x","translate-y","translate-z"],"scroll-m":["scroll-mx","scroll-my","scroll-ms","scroll-me","scroll-mbs","scroll-mbe","scroll-mt","scroll-mr","scroll-mb","scroll-ml"],"scroll-mx":["scroll-mr","scroll-ml"],"scroll-my":["scroll-mt","scroll-mb"],"scroll-p":["scroll-px","scroll-py","scroll-ps","scroll-pe","scroll-pbs","scroll-pbe","scroll-pt","scroll-pr","scroll-pb","scroll-pl"],"scroll-px":["scroll-pr","scroll-pl"],"scroll-py":["scroll-pt","scroll-pb"],touch:["touch-x","touch-y","touch-pz"],"touch-x":["touch"],"touch-y":["touch"],"touch-pz":["touch"]},conflictingClassGroupModifiers:{"font-size":["leading"]},orderSensitiveModifiers:["*","**","after","backdrop","before","details-content","file","first-letter","first-line","marker","placeholder","selection"]}},MK=cK(NK);function he(...e){return MK(M5(e))}function mc(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function LK(e){return e.startsWith("chatId:")?e.slice(7):e}const Kh="data-focus-fallback-ignore",G5="data-allow-focus-retain",Yv="kanna:restore-chat-input-focus",qC="data-chat-input",Xv="data-chat-selection-zone";function gc(e,t){return!!(e!=null&&e.closest(`[${t}]`))}function q5(e){var n;const t=e;return t!=null&&t.matches?t.matches("input:not([type='checkbox']):not([type='radio']):not([type='button']):not([type='submit']):not([type='reset']), textarea, select")||t.isContentEditable||((n=t.getAttribute)==null?void 0:n.call(t,"role"))==="textbox"?!0:gc(e,G5):!1}function IK(e){const t=e;return t!=null&&t.matches?q5(e)||(t.tabIndex??-1)>=0||t.matches("button, a[href], summary")?!0:gc(e,G5):!1}function PN(e){return!!e.querySelector(`[${Kh}][data-state='open']`)}function jK(e){return e?!e.isCollapsed&&e.toString().trim().length>0:!1}function DK(e,t){if(!e)return!1;const n=Array.from(t.querySelectorAll(`textarea[${qC}]`)).filter(o=>!o.disabled);if(n.length===0)return!1;const r=n.indexOf(e),i=r>=0?(r+1)%n.length:0,s=n[i];return s?(s.focus({preventScroll:!0}),!0):!1}function ON(e){const{activeElement:t,fallback:n,hasActiveOverlay:r}=e;if(!n||n.disabled||r||t===n)return"none";if(e.trigger==="escape")return e.defaultPrevented||gc(t,qC)||e.canCancel?"none":"escape-focus";const{pointerStartTarget:i,pointerEndTarget:s,root:o,hasActiveSelection:l}=e,c=s??i;return!o||!c||!o.contains(c)||gc(c,Kh)||gc(t,Kh)||l&&(gc(i,Xv)||gc(c,Xv))||q5(t)?"none":t&&t===c?"restore":IK(t)?"none":"restore"}const Ao=R5,PK=T5,K5=v.forwardRef(({className:e,...t},n)=>f.jsx(UC,{ref:n,className:he("fixed inset-0 z-50 bg-black/50 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));K5.displayName=UC.displayName;const OK={sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg"},Ys=v.forwardRef(({className:e,children:t,size:n="md",...r},i)=>f.jsxs(PK,{children:[f.jsx(K5,{}),f.jsxs(VC,{ref:i,[Kh]:"",onCloseAutoFocus:s=>{var o;s.preventDefault(),window.dispatchEvent(new Event(Yv)),(o=r.onCloseAutoFocus)==null||o.call(r,s)},className:he("fixed left-1/2 top-1/2 z-50 w-full -translate-x-1/2 -translate-y-1/2 rounded-xl border border-border bg-background shadow-xl duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%]","max-h-[85vh] flex flex-col",OK[n],e),...r,children:[t,f.jsxs(Hq,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[f.jsx(eo,{className:"h-4 w-4"}),f.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Ys.displayName=VC.displayName;function KC({className:e,...t}){return f.jsx("div",{className:he("shrink-0 flex flex-col space-y-1.5 p-4 border-b border-border",e),...t})}function No({className:e,...t}){return f.jsx(A5,{className:he("text-lg font-medium leading-none tracking-tight",e),...t})}function Gd({className:e,...t}){return f.jsx($q,{className:he("text-sm text-muted-foreground",e),...t})}function ma({className:e,...t}){return f.jsx("div",{className:he("flex-1 min-h-0 overflow-y-auto px-4 pb-4 pt-3.5",e),...t})}function Rl({className:e,...t}){return f.jsx("div",{className:he("shrink-0 flex justify-end gap-2 border-t border-border bg-background p-2 rounded-b-xl",e),...t})}function zK({className:e,...t}){return f.jsx("button",{className:he("touch-manipulation inline-flex items-center justify-center whitespace-nowrap cursor-pointer text-sm font-medium transition-colors","rounded-full h-9 px-4","bg-primary text-primary-foreground hover:bg-primary/90","disabled:pointer-events-none disabled:bg-primary/20 disabled:text-primary/60",e),...t})}function BK({className:e,...t}){return f.jsx("button",{className:he("touch-manipulation inline-flex items-center justify-center whitespace-nowrap cursor-pointer text-sm font-medium transition-colors","rounded-full h-9 px-4","hover:bg-accent dark:hover:bg-card hover:text-accent-foreground text-muted-foreground","disabled:pointer-events-none disabled:text-muted-foreground/50",e),...t})}function FK({open:e,shareUrl:t,onOpenChange:n,onOpenLink:r,onCopyLink:i}){const[s,o]=v.useState(!1);v.useEffect(()=>{e||o(!1)},[e,t]);const l=async()=>{await i()&&(o(!0),window.setTimeout(()=>{o(!1)},2e3))};return f.jsx(Ao,{open:e,onOpenChange:n,children:f.jsxs(Ys,{size:"md",children:[f.jsxs(KC,{children:[f.jsx(No,{children:"Shared Link"}),f.jsx(Gd,{children:"Shared links are snapshots in time and contain all attachments, tool calls and history. Be mindful of sensitive info."})]}),f.jsx(ma,{className:"space-y-3",children:f.jsxs("div",{className:"flex w-full items-center gap-2 rounded-2xl border border-border bg-muted/40 pl-4 px-3 py-2.5",children:[f.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-sm text-foreground",children:t}),f.jsx("button",{type:"button",onClick:()=>void l(),title:s?"Copied":"Copy link","aria-label":s?"Copied":"Copy link",className:"flex flex-shrink-0 items-center justify-center rounded-lg text-logo hover:text-logo/60 transition-colors hover:bg-background hover:text-foreground",children:s?f.jsx(gi,{className:"h-4 w-4 text-emerald-400"}):f.jsx(El,{className:"h-4 w-4"})})]})}),f.jsx(Rl,{children:f.jsxs(zK,{type:"button",onClick:r,children:[f.jsx(Jb,{className:"mr-2 h-4 w-4"}),"Open"]})})]})})}const zN=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,BN=M5,$K=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return BN(e,n==null?void 0:n.class,n==null?void 0:n.className);const{variants:i,defaultVariants:s}=t,o=Object.keys(i).map(u=>{const p=n==null?void 0:n[u],h=s==null?void 0:s[u];if(p===null)return null;const g=zN(p)||zN(h);return i[u][g]}),l=n&&Object.entries(n).reduce((u,p)=>{let[h,g]=p;return g===void 0||(u[h]=g),u},{}),c=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((u,p)=>{let{class:h,className:g,...b}=p;return Object.entries(b).every(_=>{let[x,S]=_;return Array.isArray(S)?S.includes({...s,...l}[x]):{...s,...l}[x]===S})?[...u,h,g]:u},[]);return BN(e,o,c,n==null?void 0:n.class,n==null?void 0:n.className)},a0=$K("touch-manipulation inline-flex items-center justify-center whitespace-nowrap cursor-pointer rounded-md text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none",{variants:{variant:{default:"bg-primary text-primary-foreground disabled:bg-primary/50 disabled:text-primary-foreground/90 hover:bg-primary/90",juicy:"bg-logo text-primary-foreground disabled:text-primary-foreground/50 hover:bg-logo/90",destructive:"bg-destructive/80 dark:text-white",outline:"border disabled:bg-transparent disabled:text-foreground/50 border-inpu disabled:border-input/90 bg-card hover:bg-muted hover:text-accent-foreground",secondary:"bg-transparent border border-border text-secondary-foreground hover:text-secondary-foreground/60 disabled:text-secondary-foreground/50",ghost:"hover:bg-accent dark:hover:bg-card hover:text-accent-foreground text-muted-foreground disabled:text-muted-foreground/50 border border-border/0 hover:border-border",link:"text-primary disabled:text-primary/50 underline-offset-4 hover:underline",none:""},size:{default:"h-10 px-4 rounded-full py-2",sm:"h-9 rounded-full px-3",lg:"h-11 rounded-full px-8",icon:"h-9 w-9 rounded-full","icon-mobile":"h-11 w-11 rounded-full md:h-9 md:w-9",none:"","icon-sm":"h-5.5 w-5.5 rounded-md"}},defaultVariants:{variant:"default",size:"default"}}),Ke=v.forwardRef(({className:e,variant:t,size:n,type:r="button",...i},s)=>f.jsx("button",{type:r,className:he(a0({variant:t,size:n,className:e})),ref:s,...i}));Ke.displayName="Button";const ir=v.forwardRef(({className:e,type:t,...n},r)=>f.jsx("input",{ref:r,type:t,className:he("flex w-full rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50",e),...n}));ir.displayName="Input";const Y5=v.createContext(null);function HK({children:e}){const[t,n]=v.useState(null),[r,i]=v.useState(""),s=v.useRef(null);v.useEffect(()=>{(t==null?void 0:t.kind)==="prompt"&&(i(t.options.initialValue??""),setTimeout(()=>{var b,_;(b=s.current)==null||b.focus(),(_=s.current)==null||_.select()},0))},[t]);const o=v.useCallback(()=>{n(null),i("")},[]),l=v.useCallback(()=>{t&&(t.kind==="confirm"?t.resolve(!1):t.kind==="prompt"?t.resolve(null):t.resolve(),o())},[o,t]),c=v.useCallback(()=>{t&&(t.kind==="confirm"?t.resolve(!0):t.kind==="prompt"?t.resolve(r.trim()||null):t.resolve(),o())},[o,t,r]),u=v.useCallback(b=>new Promise(_=>{n({kind:"confirm",options:b,resolve:_})}),[]),p=v.useCallback(b=>new Promise(_=>{n({kind:"prompt",options:b,resolve:_})}),[]),h=v.useCallback(b=>new Promise(_=>{n({kind:"alert",options:b,resolve:_})}),[]),g=v.useMemo(()=>({confirm:u,prompt:p,alert:h}),[h,u,p]);return f.jsxs(Y5.Provider,{value:g,children:[e,f.jsx(Ao,{open:t!==null,onOpenChange:b=>{b||!t||l()},children:f.jsx(Ys,{size:"sm",onKeyDown:b=>{b.key!=="Enter"||b.shiftKey||!t||t.kind!=="confirm"||(b.preventDefault(),c())},children:t?f.jsxs(f.Fragment,{children:[f.jsxs(ma,{className:"space-y-4",children:[f.jsx(No,{children:t.options.title}),t.options.description?f.jsx(Gd,{children:t.options.description}):null,t.kind==="prompt"?f.jsx(ir,{ref:s,type:"text",value:r,onChange:b=>i(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),c())},placeholder:t.options.placeholder}):null]}),f.jsxs(Rl,{children:[f.jsx(Ke,{variant:"ghost",size:"sm",onClick:l,className:t.kind==="alert"?"hidden":void 0,children:"cancelLabel"in t.options?t.options.cancelLabel??"Cancel":"Cancel"}),f.jsx(Ke,{variant:t.kind==="confirm"?t.options.confirmVariant??"default":"secondary",size:"sm",onClick:c,disabled:t.kind==="prompt"&&!r.trim(),children:t.kind==="alert"?t.options.closeLabel??"OK":"confirmLabel"in t.options?t.options.confirmLabel??"Confirm":"Confirm"})]})]}):null})})]})}function Np(){const e=v.useContext(Y5);if(!e)throw new Error("useAppDialog must be used within AppDialogProvider");return e}const YC=v.forwardRef(({className:e,...t},n)=>f.jsx("div",{ref:n,className:he("bg-card text-card-foreground",e),...t}));YC.displayName="Card";const XC=v.forwardRef(({className:e,...t},n)=>f.jsx("div",{ref:n,className:he("flex flex-col space-y-1.5 p-2",e),...t}));XC.displayName="CardHeader";const X5=v.forwardRef(({className:e,...t},n)=>f.jsx("h3",{ref:n,className:he("text-2xl font-semibold leading-none tracking-tight",e),...t}));X5.displayName="CardTitle";const Q5=v.forwardRef(({className:e,...t},n)=>f.jsx("p",{ref:n,className:he("text-sm text-muted-foreground",e),...t}));Q5.displayName="CardDescription";const QC=v.forwardRef(({className:e,...t},n)=>f.jsx("div",{ref:n,className:he("p-6 pt-0",e),...t}));QC.displayName="CardContent";const UK=v.forwardRef(({className:e,...t},n)=>f.jsx("div",{ref:n,className:he("flex items-center p-6 pt-0",e),...t}));UK.displayName="CardFooter";const VK=["top","right","bottom","left"],Tl=Math.min,qi=Math.max,Qv=Math.round,xg=Math.floor,Eo=e=>({x:e,y:e}),WK={left:"right",right:"left",bottom:"top",top:"bottom"};function pw(e,t,n){return qi(e,Tl(t,n))}function ga(e,t){return typeof e=="function"?e(t):e}function va(e){return e.split("-")[0]}function qd(e){return e.split("-")[1]}function ZC(e){return e==="x"?"y":"x"}function JC(e){return e==="y"?"height":"width"}function xo(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function ek(e){return ZC(xo(e))}function GK(e,t,n){n===void 0&&(n=!1);const r=qd(e),i=ek(e),s=JC(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=Zv(o)),[o,Zv(o)]}function qK(e){const t=Zv(e);return[mw(e),t,mw(t)]}function mw(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const FN=["left","right"],$N=["right","left"],KK=["top","bottom"],YK=["bottom","top"];function XK(e,t,n){switch(e){case"top":case"bottom":return n?t?$N:FN:t?FN:$N;case"left":case"right":return t?KK:YK;default:return[]}}function QK(e,t,n,r){const i=qd(e);let s=XK(va(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(mw)))),s}function Zv(e){const t=va(e);return WK[t]+e.slice(t.length)}function ZK(e){return{top:0,right:0,bottom:0,left:0,...e}}function Z5(e){return typeof e!="number"?ZK(e):{top:e,right:e,bottom:e,left:e}}function Jv(e){const{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function HN(e,t,n){let{reference:r,floating:i}=e;const s=xo(t),o=ek(t),l=JC(o),c=va(t),u=s==="y",p=r.x+r.width/2-i.width/2,h=r.y+r.height/2-i.height/2,g=r[l]/2-i[l]/2;let b;switch(c){case"top":b={x:p,y:r.y-i.height};break;case"bottom":b={x:p,y:r.y+r.height};break;case"right":b={x:r.x+r.width,y:h};break;case"left":b={x:r.x-i.width,y:h};break;default:b={x:r.x,y:r.y}}switch(qd(t)){case"start":b[o]-=g*(n&&u?-1:1);break;case"end":b[o]+=g*(n&&u?-1:1);break}return b}async function JK(e,t){var n;t===void 0&&(t={});const{x:r,y:i,platform:s,rects:o,elements:l,strategy:c}=e,{boundary:u="clippingAncestors",rootBoundary:p="viewport",elementContext:h="floating",altBoundary:g=!1,padding:b=0}=ga(t,e),_=Z5(b),S=l[g?h==="floating"?"reference":"floating":h],C=Jv(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(S)))==null||n?S:S.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:u,rootBoundary:p,strategy:c})),E=h==="floating"?{x:r,y:i,width:o.floating.width,height:o.floating.height}:o.reference,k=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),T=await(s.isElement==null?void 0:s.isElement(k))?await(s.getScale==null?void 0:s.getScale(k))||{x:1,y:1}:{x:1,y:1},A=Jv(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:E,offsetParent:k,strategy:c}):E);return{top:(C.top-A.top+_.top)/T.y,bottom:(A.bottom-C.bottom+_.bottom)/T.y,left:(C.left-A.left+_.left)/T.x,right:(A.right-C.right+_.right)/T.x}}const eY=50,tY=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:JK},c=await(o.isRTL==null?void 0:o.isRTL(t));let u=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:p,y:h}=HN(u,r,c),g=r,b=0;const _={};for(let x=0;x<s.length;x++){const S=s[x];if(!S)continue;const{name:C,fn:E}=S,{x:k,y:T,data:A,reset:N}=await E({x:p,y:h,initialPlacement:r,placement:g,strategy:i,middlewareData:_,rects:u,platform:l,elements:{reference:e,floating:t}});p=k??p,h=T??h,_[C]={..._[C],...A},N&&b<eY&&(b++,typeof N=="object"&&(N.placement&&(g=N.placement),N.rects&&(u=N.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):N.rects),{x:p,y:h}=HN(u,g,c)),x=-1)}return{x:p,y:h,placement:g,strategy:i,middlewareData:_}},nY=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:i,rects:s,platform:o,elements:l,middlewareData:c}=t,{element:u,padding:p=0}=ga(e,t)||{};if(u==null)return{};const h=Z5(p),g={x:n,y:r},b=ek(i),_=JC(b),x=await o.getDimensions(u),S=b==="y",C=S?"top":"left",E=S?"bottom":"right",k=S?"clientHeight":"clientWidth",T=s.reference[_]+s.reference[b]-g[b]-s.floating[_],A=g[b]-s.reference[b],N=await(o.getOffsetParent==null?void 0:o.getOffsetParent(u));let M=N?N[k]:0;(!M||!await(o.isElement==null?void 0:o.isElement(N)))&&(M=l.floating[k]||s.floating[_]);const j=T/2-A/2,U=M/2-x[_]/2-1,I=Tl(h[C],U),P=Tl(h[E],U),z=I,O=M-x[_]-P,$=M/2-x[_]/2+j,V=pw(z,$,O),F=!c.arrow&&qd(i)!=null&&$!==V&&s.reference[_]/2-($<z?I:P)-x[_]/2<0,H=F?$<z?$-z:$-O:0;return{[b]:g[b]+H,data:{[b]:V,centerOffset:$-V-H,...F&&{alignmentOffset:H}},reset:F}}}),rY=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:i,middlewareData:s,rects:o,initialPlacement:l,platform:c,elements:u}=t,{mainAxis:p=!0,crossAxis:h=!0,fallbackPlacements:g,fallbackStrategy:b="bestFit",fallbackAxisSideDirection:_="none",flipAlignment:x=!0,...S}=ga(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const C=va(i),E=xo(l),k=va(l)===l,T=await(c.isRTL==null?void 0:c.isRTL(u.floating)),A=g||(k||!x?[Zv(l)]:qK(l)),N=_!=="none";!g&&N&&A.push(...QK(l,x,_,T));const M=[l,...A],j=await c.detectOverflow(t,S),U=[];let I=((r=s.flip)==null?void 0:r.overflows)||[];if(p&&U.push(j[C]),h){const $=GK(i,o,T);U.push(j[$[0]],j[$[1]])}if(I=[...I,{placement:i,overflows:U}],!U.every($=>$<=0)){var P,z;const $=(((P=s.flip)==null?void 0:P.index)||0)+1,V=M[$];if(V&&(!(h==="alignment"?E!==xo(V):!1)||I.every(W=>xo(W.placement)===E?W.overflows[0]>0:!0)))return{data:{index:$,overflows:I},reset:{placement:V}};let F=(z=I.filter(H=>H.overflows[0]<=0).sort((H,W)=>H.overflows[1]-W.overflows[1])[0])==null?void 0:z.placement;if(!F)switch(b){case"bestFit":{var O;const H=(O=I.filter(W=>{if(N){const Z=xo(W.placement);return Z===E||Z==="y"}return!0}).map(W=>[W.placement,W.overflows.filter(Z=>Z>0).reduce((Z,D)=>Z+D,0)]).sort((W,Z)=>W[1]-Z[1])[0])==null?void 0:O[0];H&&(F=H);break}case"initialPlacement":F=l;break}if(i!==F)return{reset:{placement:F}}}return{}}}};function UN(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function VN(e){return VK.some(t=>e[t]>=0)}const iY=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=ga(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=UN(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:VN(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=UN(o,n.floating);return{data:{escapedOffsets:l,escaped:VN(l)}}}default:return{}}}}},J5=new Set(["left","top"]);async function sY(e,t){const{placement:n,platform:r,elements:i}=e,s=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=va(n),l=qd(n),c=xo(n)==="y",u=J5.has(o)?-1:1,p=s&&c?-1:1,h=ga(t,e);let{mainAxis:g,crossAxis:b,alignmentAxis:_}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return l&&typeof _=="number"&&(b=l==="end"?_*-1:_),c?{x:b*p,y:g*u}:{x:g*u,y:b*p}}const oY=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:i,y:s,placement:o,middlewareData:l}=t,c=await sY(t,e);return o===((n=l.offset)==null?void 0:n.placement)&&(r=l.arrow)!=null&&r.alignmentOffset?{}:{x:i+c.x,y:s+c.y,data:{...c,placement:o}}}}},aY=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:i,platform:s}=t,{mainAxis:o=!0,crossAxis:l=!1,limiter:c={fn:C=>{let{x:E,y:k}=C;return{x:E,y:k}}},...u}=ga(e,t),p={x:n,y:r},h=await s.detectOverflow(t,u),g=xo(va(i)),b=ZC(g);let _=p[b],x=p[g];if(o){const C=b==="y"?"top":"left",E=b==="y"?"bottom":"right",k=_+h[C],T=_-h[E];_=pw(k,_,T)}if(l){const C=g==="y"?"top":"left",E=g==="y"?"bottom":"right",k=x+h[C],T=x-h[E];x=pw(k,x,T)}const S=c.fn({...t,[b]:_,[g]:x});return{...S,data:{x:S.x-n,y:S.y-r,enabled:{[b]:o,[g]:l}}}}}},lY=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:i,rects:s,middlewareData:o}=t,{offset:l=0,mainAxis:c=!0,crossAxis:u=!0}=ga(e,t),p={x:n,y:r},h=xo(i),g=ZC(h);let b=p[g],_=p[h];const x=ga(l,t),S=typeof x=="number"?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(c){const k=g==="y"?"height":"width",T=s.reference[g]-s.floating[k]+S.mainAxis,A=s.reference[g]+s.reference[k]-S.mainAxis;b<T?b=T:b>A&&(b=A)}if(u){var C,E;const k=g==="y"?"width":"height",T=J5.has(va(i)),A=s.reference[h]-s.floating[k]+(T&&((C=o.offset)==null?void 0:C[h])||0)+(T?0:S.crossAxis),N=s.reference[h]+s.reference[k]+(T?0:((E=o.offset)==null?void 0:E[h])||0)-(T?S.crossAxis:0);_<A?_=A:_>N&&(_=N)}return{[g]:b,[h]:_}}}},cY=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:i,rects:s,platform:o,elements:l}=t,{apply:c=()=>{},...u}=ga(e,t),p=await o.detectOverflow(t,u),h=va(i),g=qd(i),b=xo(i)==="y",{width:_,height:x}=s.floating;let S,C;h==="top"||h==="bottom"?(S=h,C=g===(await(o.isRTL==null?void 0:o.isRTL(l.floating))?"start":"end")?"left":"right"):(C=h,S=g==="end"?"top":"bottom");const E=x-p.top-p.bottom,k=_-p.left-p.right,T=Tl(x-p[S],E),A=Tl(_-p[C],k),N=!t.middlewareData.shift;let M=T,j=A;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(j=k),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(M=E),N&&!g){const I=qi(p.left,0),P=qi(p.right,0),z=qi(p.top,0),O=qi(p.bottom,0);b?j=_-2*(I!==0||P!==0?I+P:qi(p.left,p.right)):M=x-2*(z!==0||O!==0?z+O:qi(p.top,p.bottom))}await c({...t,availableWidth:j,availableHeight:M});const U=await o.getDimensions(l.floating);return _!==U.width||x!==U.height?{reset:{rects:!0}}:{}}}};function l0(){return typeof window<"u"}function Kd(e){return eO(e)?(e.nodeName||"").toLowerCase():"#document"}function Ki(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Io(e){var t;return(t=(eO(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function eO(e){return l0()?e instanceof Node||e instanceof Ki(e).Node:!1}function Xs(e){return l0()?e instanceof Element||e instanceof Ki(e).Element:!1}function Sa(e){return l0()?e instanceof HTMLElement||e instanceof Ki(e).HTMLElement:!1}function WN(e){return!l0()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ki(e).ShadowRoot}function Mp(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=Qs(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function uY(e){return/^(table|td|th)$/.test(Kd(e))}function c0(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const dY=/transform|translate|scale|rotate|perspective|filter/,fY=/paint|layout|strict|content/,oc=e=>!!e&&e!=="none";let Ex;function tk(e){const t=Xs(e)?Qs(e):e;return oc(t.transform)||oc(t.translate)||oc(t.scale)||oc(t.rotate)||oc(t.perspective)||!nk()&&(oc(t.backdropFilter)||oc(t.filter))||dY.test(t.willChange||"")||fY.test(t.contain||"")}function hY(e){let t=Al(e);for(;Sa(t)&&!Cd(t);){if(tk(t))return t;if(c0(t))return null;t=Al(t)}return null}function nk(){return Ex==null&&(Ex=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Ex}function Cd(e){return/^(html|body|#document)$/.test(Kd(e))}function Qs(e){return Ki(e).getComputedStyle(e)}function u0(e){return Xs(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Al(e){if(Kd(e)==="html")return e;const t=e.assignedSlot||e.parentNode||WN(e)&&e.host||Io(e);return WN(t)?t.host:t}function tO(e){const t=Al(e);return Cd(t)?e.ownerDocument?e.ownerDocument.body:e.body:Sa(t)&&Mp(t)?t:tO(t)}function Yh(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=tO(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=Ki(i);if(s){const l=gw(o);return t.concat(o,o.visualViewport||[],Mp(i)?i:[],l&&n?Yh(l):[])}else return t.concat(i,Yh(i,[],n))}function gw(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function nO(e){const t=Qs(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Sa(e),s=i?e.offsetWidth:n,o=i?e.offsetHeight:r,l=Qv(n)!==s||Qv(r)!==o;return l&&(n=s,r=o),{width:n,height:r,$:l}}function rk(e){return Xs(e)?e:e.contextElement}function dd(e){const t=rk(e);if(!Sa(t))return Eo(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=nO(t);let o=(s?Qv(n.width):n.width)/r,l=(s?Qv(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!l||!Number.isFinite(l))&&(l=1),{x:o,y:l}}const pY=Eo(0);function rO(e){const t=Ki(e);return!nk()||!t.visualViewport?pY:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function mY(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Ki(e)?!1:t}function Lc(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),s=rk(e);let o=Eo(1);t&&(r?Xs(r)&&(o=dd(r)):o=dd(e));const l=mY(s,n,r)?rO(s):Eo(0);let c=(i.left+l.x)/o.x,u=(i.top+l.y)/o.y,p=i.width/o.x,h=i.height/o.y;if(s){const g=Ki(s),b=r&&Xs(r)?Ki(r):r;let _=g,x=gw(_);for(;x&&r&&b!==_;){const S=dd(x),C=x.getBoundingClientRect(),E=Qs(x),k=C.left+(x.clientLeft+parseFloat(E.paddingLeft))*S.x,T=C.top+(x.clientTop+parseFloat(E.paddingTop))*S.y;c*=S.x,u*=S.y,p*=S.x,h*=S.y,c+=k,u+=T,_=Ki(x),x=gw(_)}}return Jv({width:p,height:h,x:c,y:u})}function d0(e,t){const n=u0(e).scrollLeft;return t?t.left+n:Lc(Io(e)).left+n}function iO(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-d0(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function gY(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=Io(r),l=t?c0(t.floating):!1;if(r===o||l&&s)return n;let c={scrollLeft:0,scrollTop:0},u=Eo(1);const p=Eo(0),h=Sa(r);if((h||!h&&!s)&&((Kd(r)!=="body"||Mp(o))&&(c=u0(r)),h)){const b=Lc(r);u=dd(r),p.x=b.x+r.clientLeft,p.y=b.y+r.clientTop}const g=o&&!h&&!s?iO(o,c):Eo(0);return{width:n.width*u.x,height:n.height*u.y,x:n.x*u.x-c.scrollLeft*u.x+p.x+g.x,y:n.y*u.y-c.scrollTop*u.y+p.y+g.y}}function vY(e){return Array.from(e.getClientRects())}function bY(e){const t=Io(e),n=u0(e),r=e.ownerDocument.body,i=qi(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=qi(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+d0(e);const l=-n.scrollTop;return Qs(r).direction==="rtl"&&(o+=qi(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const GN=25;function yY(e,t){const n=Ki(e),r=Io(e),i=n.visualViewport;let s=r.clientWidth,o=r.clientHeight,l=0,c=0;if(i){s=i.width,o=i.height;const p=nk();(!p||p&&t==="fixed")&&(l=i.offsetLeft,c=i.offsetTop)}const u=d0(r);if(u<=0){const p=r.ownerDocument,h=p.body,g=getComputedStyle(h),b=p.compatMode==="CSS1Compat"&&parseFloat(g.marginLeft)+parseFloat(g.marginRight)||0,_=Math.abs(r.clientWidth-h.clientWidth-b);_<=GN&&(s-=_)}else u<=GN&&(s+=u);return{width:s,height:o,x:l,y:c}}function _Y(e,t){const n=Lc(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=Sa(e)?dd(e):Eo(1),o=e.clientWidth*s.x,l=e.clientHeight*s.y,c=i*s.x,u=r*s.y;return{width:o,height:l,x:c,y:u}}function qN(e,t,n){let r;if(t==="viewport")r=yY(e,n);else if(t==="document")r=bY(Io(e));else if(Xs(t))r=_Y(t,n);else{const i=rO(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Jv(r)}function sO(e,t){const n=Al(e);return n===t||!Xs(n)||Cd(n)?!1:Qs(n).position==="fixed"||sO(n,t)}function xY(e,t){const n=t.get(e);if(n)return n;let r=Yh(e,[],!1).filter(l=>Xs(l)&&Kd(l)!=="body"),i=null;const s=Qs(e).position==="fixed";let o=s?Al(e):e;for(;Xs(o)&&!Cd(o);){const l=Qs(o),c=tk(o);!c&&l.position==="fixed"&&(i=null),(s?!c&&!i:!c&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||Mp(o)&&!c&&sO(e,o))?r=r.filter(p=>p!==o):i=l,o=Al(o)}return t.set(e,r),r}function SY(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?c0(t)?[]:xY(t,this._c):[].concat(n),r],l=qN(t,o[0],i);let c=l.top,u=l.right,p=l.bottom,h=l.left;for(let g=1;g<o.length;g++){const b=qN(t,o[g],i);c=qi(b.top,c),u=Tl(b.right,u),p=Tl(b.bottom,p),h=qi(b.left,h)}return{width:u-h,height:p-c,x:h,y:c}}function wY(e){const{width:t,height:n}=nO(e);return{width:t,height:n}}function CY(e,t,n){const r=Sa(t),i=Io(t),s=n==="fixed",o=Lc(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const c=Eo(0);function u(){c.x=d0(i)}if(r||!r&&!s)if((Kd(t)!=="body"||Mp(i))&&(l=u0(t)),r){const b=Lc(t,!0,s,t);c.x=b.x+t.clientLeft,c.y=b.y+t.clientTop}else i&&u();s&&!r&&i&&u();const p=i&&!r&&!s?iO(i,l):Eo(0),h=o.left+l.scrollLeft-c.x-p.x,g=o.top+l.scrollTop-c.y-p.y;return{x:h,y:g,width:o.width,height:o.height}}function Rx(e){return Qs(e).position==="static"}function KN(e,t){if(!Sa(e)||Qs(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return Io(e)===n&&(n=n.ownerDocument.body),n}function oO(e,t){const n=Ki(e);if(c0(e))return n;if(!Sa(e)){let i=Al(e);for(;i&&!Cd(i);){if(Xs(i)&&!Rx(i))return i;i=Al(i)}return n}let r=KN(e,t);for(;r&&uY(r)&&Rx(r);)r=KN(r,t);return r&&Cd(r)&&Rx(r)&&!tk(r)?n:r||hY(e)||n}const kY=async function(e){const t=this.getOffsetParent||oO,n=this.getDimensions,r=await n(e.floating);return{reference:CY(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function EY(e){return Qs(e).direction==="rtl"}const RY={convertOffsetParentRelativeRectToViewportRelativeRect:gY,getDocumentElement:Io,getClippingRect:SY,getOffsetParent:oO,getElementRects:kY,getClientRects:vY,getDimensions:wY,getScale:dd,isElement:Xs,isRTL:EY};function aO(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function TY(e,t){let n=null,r;const i=Io(e);function s(){var l;clearTimeout(r),(l=n)==null||l.disconnect(),n=null}function o(l,c){l===void 0&&(l=!1),c===void 0&&(c=1),s();const u=e.getBoundingClientRect(),{left:p,top:h,width:g,height:b}=u;if(l||t(),!g||!b)return;const _=xg(h),x=xg(i.clientWidth-(p+g)),S=xg(i.clientHeight-(h+b)),C=xg(p),k={rootMargin:-_+"px "+-x+"px "+-S+"px "+-C+"px",threshold:qi(0,Tl(1,c))||1};let T=!0;function A(N){const M=N[0].intersectionRatio;if(M!==c){if(!T)return o();M?o(!1,M):r=setTimeout(()=>{o(!1,1e-7)},1e3)}M===1&&!aO(u,e.getBoundingClientRect())&&o(),T=!1}try{n=new IntersectionObserver(A,{...k,root:i.ownerDocument})}catch{n=new IntersectionObserver(A,k)}n.observe(e)}return o(!0),s}function AY(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:i=!0,ancestorResize:s=!0,elementResize:o=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:c=!1}=r,u=rk(e),p=i||s?[...u?Yh(u):[],...t?Yh(t):[]]:[];p.forEach(C=>{i&&C.addEventListener("scroll",n,{passive:!0}),s&&C.addEventListener("resize",n)});const h=u&&l?TY(u,n):null;let g=-1,b=null;o&&(b=new ResizeObserver(C=>{let[E]=C;E&&E.target===u&&b&&t&&(b.unobserve(t),cancelAnimationFrame(g),g=requestAnimationFrame(()=>{var k;(k=b)==null||k.observe(t)})),n()}),u&&!c&&b.observe(u),t&&b.observe(t));let _,x=c?Lc(e):null;c&&S();function S(){const C=Lc(e);x&&!aO(x,C)&&n(),x=C,_=requestAnimationFrame(S)}return n(),()=>{var C;p.forEach(E=>{i&&E.removeEventListener("scroll",n),s&&E.removeEventListener("resize",n)}),h==null||h(),(C=b)==null||C.disconnect(),b=null,c&&cancelAnimationFrame(_)}}const NY=oY,MY=aY,LY=rY,IY=cY,jY=iY,YN=nY,DY=lY,PY=(e,t,n)=>{const r=new Map,i={platform:RY,...n},s={...i.platform,_c:r};return tY(e,t,{...i,platform:s})};var OY=typeof document<"u",zY=function(){},_v=OY?v.useLayoutEffect:zY;function eb(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!eb(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){const s=i[r];if(!(s==="_owner"&&e.$$typeof)&&!eb(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function lO(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function XN(e,t){const n=lO(e);return Math.round(t*n)/n}function Tx(e){const t=v.useRef(e);return _v(()=>{t.current=e}),t}function BY(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:i,elements:{reference:s,floating:o}={},transform:l=!0,whileElementsMounted:c,open:u}=e,[p,h]=v.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[g,b]=v.useState(r);eb(g,r)||b(r);const[_,x]=v.useState(null),[S,C]=v.useState(null),E=v.useCallback(W=>{W!==N.current&&(N.current=W,x(W))},[]),k=v.useCallback(W=>{W!==M.current&&(M.current=W,C(W))},[]),T=s||_,A=o||S,N=v.useRef(null),M=v.useRef(null),j=v.useRef(p),U=c!=null,I=Tx(c),P=Tx(i),z=Tx(u),O=v.useCallback(()=>{if(!N.current||!M.current)return;const W={placement:t,strategy:n,middleware:g};P.current&&(W.platform=P.current),PY(N.current,M.current,W).then(Z=>{const D={...Z,isPositioned:z.current!==!1};$.current&&!eb(j.current,D)&&(j.current=D,xs.flushSync(()=>{h(D)}))})},[g,t,n,P,z]);_v(()=>{u===!1&&j.current.isPositioned&&(j.current.isPositioned=!1,h(W=>({...W,isPositioned:!1})))},[u]);const $=v.useRef(!1);_v(()=>($.current=!0,()=>{$.current=!1}),[]),_v(()=>{if(T&&(N.current=T),A&&(M.current=A),T&&A){if(I.current)return I.current(T,A,O);O()}},[T,A,O,I,U]);const V=v.useMemo(()=>({reference:N,floating:M,setReference:E,setFloating:k}),[E,k]),F=v.useMemo(()=>({reference:T,floating:A}),[T,A]),H=v.useMemo(()=>{const W={position:n,left:0,top:0};if(!F.floating)return W;const Z=XN(F.floating,p.x),D=XN(F.floating,p.y);return l?{...W,transform:"translate("+Z+"px, "+D+"px)",...lO(F.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:Z,top:D}},[n,l,F.floating,p.x,p.y]);return v.useMemo(()=>({...p,update:O,refs:V,elements:F,floatingStyles:H}),[p,O,V,F,H])}const FY=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:i}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?YN({element:r.current,padding:i}).fn(n):{}:r?YN({element:r,padding:i}).fn(n):{}}}},$Y=(e,t)=>{const n=NY(e);return{name:n.name,fn:n.fn,options:[e,t]}},HY=(e,t)=>{const n=MY(e);return{name:n.name,fn:n.fn,options:[e,t]}},UY=(e,t)=>({fn:DY(e).fn,options:[e,t]}),VY=(e,t)=>{const n=LY(e);return{name:n.name,fn:n.fn,options:[e,t]}},WY=(e,t)=>{const n=IY(e);return{name:n.name,fn:n.fn,options:[e,t]}},GY=(e,t)=>{const n=jY(e);return{name:n.name,fn:n.fn,options:[e,t]}},qY=(e,t)=>{const n=FY(e);return{name:n.name,fn:n.fn,options:[e,t]}};var KY="Arrow",cO=v.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return f.jsx(rn.svg,{...s,ref:t,width:r,height:i,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:f.jsx("polygon",{points:"0,0 30,0 15,10"})})});cO.displayName=KY;var YY=cO;function XY(e){const[t,n]=v.useState(void 0);return ii(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(i=>{if(!Array.isArray(i)||!i.length)return;const s=i[0];let o,l;if("borderBoxSize"in s){const c=s.borderBoxSize,u=Array.isArray(c)?c[0]:c;o=u.inlineSize,l=u.blockSize}else o=e.offsetWidth,l=e.offsetHeight;n({width:o,height:l})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var ik="Popper",[uO,Il]=xa(ik),[QY,dO]=uO(ik),fO=e=>{const{__scopePopper:t,children:n}=e,[r,i]=v.useState(null);return f.jsx(QY,{scope:t,anchor:r,onAnchorChange:i,children:n})};fO.displayName=ik;var hO="PopperAnchor",pO=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=dO(hO,n),o=v.useRef(null),l=yn(t,o),c=v.useRef(null);return v.useEffect(()=>{const u=c.current;c.current=(r==null?void 0:r.current)||o.current,u!==c.current&&s.onAnchorChange(c.current)}),r?null:f.jsx(rn.div,{...i,ref:l})});pO.displayName=hO;var sk="PopperContent",[ZY,JY]=uO(sk),mO=v.forwardRef((e,t)=>{var ne,se,ce,de,Ne,we;const{__scopePopper:n,side:r="bottom",sideOffset:i=0,align:s="center",alignOffset:o=0,arrowPadding:l=0,avoidCollisions:c=!0,collisionBoundary:u=[],collisionPadding:p=0,sticky:h="partial",hideWhenDetached:g=!1,updatePositionStrategy:b="optimized",onPlaced:_,...x}=e,S=dO(sk,n),[C,E]=v.useState(null),k=yn(t,je=>E(je)),[T,A]=v.useState(null),N=XY(T),M=(N==null?void 0:N.width)??0,j=(N==null?void 0:N.height)??0,U=r+(s!=="center"?"-"+s:""),I=typeof p=="number"?p:{top:0,right:0,bottom:0,left:0,...p},P=Array.isArray(u)?u:[u],z=P.length>0,O={padding:I,boundary:P.filter(tX),altBoundary:z},{refs:$,floatingStyles:V,placement:F,isPositioned:H,middlewareData:W}=BY({strategy:"fixed",placement:U,whileElementsMounted:(...je)=>AY(...je,{animationFrame:b==="always"}),elements:{reference:S.anchor},middleware:[$Y({mainAxis:i+j,alignmentAxis:o}),c&&HY({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?UY():void 0,...O}),c&&VY({...O}),WY({...O,apply:({elements:je,rects:fe,availableWidth:ot,availableHeight:Mt})=>{const{width:Et,height:Xt}=fe.reference,Dt=je.floating.style;Dt.setProperty("--radix-popper-available-width",`${ot}px`),Dt.setProperty("--radix-popper-available-height",`${Mt}px`),Dt.setProperty("--radix-popper-anchor-width",`${Et}px`),Dt.setProperty("--radix-popper-anchor-height",`${Xt}px`)}}),T&&qY({element:T,padding:l}),nX({arrowWidth:M,arrowHeight:j}),g&&GY({strategy:"referenceHidden",...O})]}),[Z,D]=bO(F),G=Ks(_);ii(()=>{H&&(G==null||G())},[H,G]);const ee=(ne=W.arrow)==null?void 0:ne.x,B=(se=W.arrow)==null?void 0:se.y,le=((ce=W.arrow)==null?void 0:ce.centerOffset)!==0,[oe,J]=v.useState();return ii(()=>{C&&J(window.getComputedStyle(C).zIndex)},[C]),f.jsx("div",{ref:$.setFloating,"data-radix-popper-content-wrapper":"",style:{...V,transform:H?V.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:oe,"--radix-popper-transform-origin":[(de=W.transformOrigin)==null?void 0:de.x,(Ne=W.transformOrigin)==null?void 0:Ne.y].join(" "),...((we=W.hide)==null?void 0:we.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:f.jsx(ZY,{scope:n,placedSide:Z,onArrowChange:A,arrowX:ee,arrowY:B,shouldHideArrow:le,children:f.jsx(rn.div,{"data-side":Z,"data-align":D,...x,ref:k,style:{...x.style,animation:H?void 0:"none"}})})})});mO.displayName=sk;var gO="PopperArrow",eX={top:"bottom",right:"left",bottom:"top",left:"right"},vO=v.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=JY(gO,r),o=eX[s.placedSide];return f.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[o]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:f.jsx(YY,{...i,ref:n,style:{...i.style,display:"block"}})})});vO.displayName=gO;function tX(e){return e!==null}var nX=e=>({name:"transformOrigin",options:e,fn(t){var S,C,E;const{placement:n,rects:r,middlewareData:i}=t,o=((S=i.arrow)==null?void 0:S.centerOffset)!==0,l=o?0:e.arrowWidth,c=o?0:e.arrowHeight,[u,p]=bO(n),h={start:"0%",center:"50%",end:"100%"}[p],g=(((C=i.arrow)==null?void 0:C.x)??0)+l/2,b=(((E=i.arrow)==null?void 0:E.y)??0)+c/2;let _="",x="";return u==="bottom"?(_=o?h:`${g}px`,x=`${-c}px`):u==="top"?(_=o?h:`${g}px`,x=`${r.floating.height+c}px`):u==="right"?(_=`${-c}px`,x=o?h:`${b}px`):u==="left"&&(_=`${r.floating.width+c}px`,x=o?h:`${b}px`),{data:{x:_,y:x}}}});function bO(e){const[t,n="center"]=e.split("-");return[t,n]}var f0=fO,Lp=pO,h0=mO,p0=vO,yO=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),rX="VisuallyHidden",_O=v.forwardRef((e,t)=>f.jsx(rn.span,{...e,ref:t,style:{...yO,...e.style}}));_O.displayName=rX;var iX=_O,[m0]=xa("Tooltip",[Il]),g0=Il(),xO="TooltipProvider",sX=700,vw="tooltip.open",[oX,ok]=m0(xO),SO=e=>{const{__scopeTooltip:t,delayDuration:n=sX,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:s}=e,o=v.useRef(!0),l=v.useRef(!1),c=v.useRef(0);return v.useEffect(()=>{const u=c.current;return()=>window.clearTimeout(u)},[]),f.jsx(oX,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:v.useCallback(()=>{window.clearTimeout(c.current),o.current=!1},[]),onClose:v.useCallback(()=>{window.clearTimeout(c.current),c.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:l,onPointerInTransitChange:v.useCallback(u=>{l.current=u},[]),disableHoverableContent:i,children:s})};SO.displayName=xO;var Xh="Tooltip",[aX,Ip]=m0(Xh),wO=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,c=ok(Xh,e.__scopeTooltip),u=g0(t),[p,h]=v.useState(null),g=ha(),b=v.useRef(0),_=o??c.disableHoverableContent,x=l??c.delayDuration,S=v.useRef(!1),[C,E]=wd({prop:r,defaultProp:i??!1,onChange:M=>{M?(c.onOpen(),document.dispatchEvent(new CustomEvent(vw))):c.onClose(),s==null||s(M)},caller:Xh}),k=v.useMemo(()=>C?S.current?"delayed-open":"instant-open":"closed",[C]),T=v.useCallback(()=>{window.clearTimeout(b.current),b.current=0,S.current=!1,E(!0)},[E]),A=v.useCallback(()=>{window.clearTimeout(b.current),b.current=0,E(!1)},[E]),N=v.useCallback(()=>{window.clearTimeout(b.current),b.current=window.setTimeout(()=>{S.current=!0,E(!0),b.current=0},x)},[x,E]);return v.useEffect(()=>()=>{b.current&&(window.clearTimeout(b.current),b.current=0)},[]),f.jsx(f0,{...u,children:f.jsx(aX,{scope:t,contentId:g,open:C,stateAttribute:k,trigger:p,onTriggerChange:h,onTriggerEnter:v.useCallback(()=>{c.isOpenDelayedRef.current?N():T()},[c.isOpenDelayedRef,N,T]),onTriggerLeave:v.useCallback(()=>{_?A():(window.clearTimeout(b.current),b.current=0)},[A,_]),onOpen:T,onClose:A,disableHoverableContent:_,children:n})})};wO.displayName=Xh;var bw="TooltipTrigger",CO=v.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Ip(bw,n),s=ok(bw,n),o=g0(n),l=v.useRef(null),c=yn(t,l,i.onTriggerChange),u=v.useRef(!1),p=v.useRef(!1),h=v.useCallback(()=>u.current=!1,[]);return v.useEffect(()=>()=>document.removeEventListener("pointerup",h),[h]),f.jsx(Lp,{asChild:!0,...o,children:f.jsx(rn.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:c,onPointerMove:tt(e.onPointerMove,g=>{g.pointerType!=="touch"&&!p.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),p.current=!0)}),onPointerLeave:tt(e.onPointerLeave,()=>{i.onTriggerLeave(),p.current=!1}),onPointerDown:tt(e.onPointerDown,()=>{i.open&&i.onClose(),u.current=!0,document.addEventListener("pointerup",h,{once:!0})}),onFocus:tt(e.onFocus,()=>{u.current||i.onOpen()}),onBlur:tt(e.onBlur,i.onClose),onClick:tt(e.onClick,i.onClose)})})});CO.displayName=bw;var ak="TooltipPortal",[lX,cX]=m0(ak,{forceMount:void 0}),kO=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=Ip(ak,t);return f.jsx(lX,{scope:t,forceMount:n,children:f.jsx(Ts,{present:n||s.open,children:f.jsx(Wd,{asChild:!0,container:i,children:r})})})};kO.displayName=ak;var kd="TooltipContent",EO=v.forwardRef((e,t)=>{const n=cX(kd,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=Ip(kd,e.__scopeTooltip);return f.jsx(Ts,{present:r||o.open,children:o.disableHoverableContent?f.jsx(RO,{side:i,...s,ref:t}):f.jsx(uX,{side:i,...s,ref:t})})}),uX=v.forwardRef((e,t)=>{const n=Ip(kd,e.__scopeTooltip),r=ok(kd,e.__scopeTooltip),i=v.useRef(null),s=yn(t,i),[o,l]=v.useState(null),{trigger:c,onClose:u}=n,p=i.current,{onPointerInTransitChange:h}=r,g=v.useCallback(()=>{l(null),h(!1)},[h]),b=v.useCallback((_,x)=>{const S=_.currentTarget,C={x:_.clientX,y:_.clientY},E=mX(C,S.getBoundingClientRect()),k=gX(C,E),T=vX(x.getBoundingClientRect()),A=yX([...k,...T]);l(A),h(!0)},[h]);return v.useEffect(()=>()=>g(),[g]),v.useEffect(()=>{if(c&&p){const _=S=>b(S,p),x=S=>b(S,c);return c.addEventListener("pointerleave",_),p.addEventListener("pointerleave",x),()=>{c.removeEventListener("pointerleave",_),p.removeEventListener("pointerleave",x)}}},[c,p,b,g]),v.useEffect(()=>{if(o){const _=x=>{const S=x.target,C={x:x.clientX,y:x.clientY},E=(c==null?void 0:c.contains(S))||(p==null?void 0:p.contains(S)),k=!bX(C,o);E?g():k&&(g(),u())};return document.addEventListener("pointermove",_),()=>document.removeEventListener("pointermove",_)}},[c,p,o,u,g]),f.jsx(RO,{...e,ref:s})}),[dX,fX]=m0(Xh,{isInside:!1}),hX=SG("TooltipContent"),RO=v.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,c=Ip(kd,n),u=g0(n),{onClose:p}=c;return v.useEffect(()=>(document.addEventListener(vw,p),()=>document.removeEventListener(vw,p)),[p]),v.useEffect(()=>{if(c.trigger){const h=g=>{const b=g.target;b!=null&&b.contains(c.trigger)&&p()};return window.addEventListener("scroll",h,{capture:!0}),()=>window.removeEventListener("scroll",h,{capture:!0})}},[c.trigger,p]),f.jsx(Vd,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:h=>h.preventDefault(),onDismiss:p,children:f.jsxs(h0,{"data-state":c.stateAttribute,...u,...l,ref:t,style:{...l.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[f.jsx(hX,{children:r}),f.jsx(dX,{scope:n,isInside:!0,children:f.jsx(iX,{id:c.contentId,role:"tooltip",children:i||r})})]})})});EO.displayName=kd;var TO="TooltipArrow",pX=v.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=g0(n);return fX(TO,n).isInside?null:f.jsx(p0,{...i,...r,ref:t})});pX.displayName=TO;function mX(e,t){const n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),s=Math.abs(t.left-e.x);switch(Math.min(n,r,i,s)){case s:return"left";case i:return"right";case n:return"top";case r:return"bottom";default:throw new Error("unreachable")}}function gX(e,t,n=5){const r=[];switch(t){case"top":r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case"bottom":r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case"left":r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case"right":r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}function vX(e){const{top:t,right:n,bottom:r,left:i}=e;return[{x:i,y:t},{x:n,y:t},{x:n,y:r},{x:i,y:r}]}function bX(e,t){const{x:n,y:r}=e;let i=!1;for(let s=0,o=t.length-1;s<t.length;o=s++){const l=t[s],c=t[o],u=l.x,p=l.y,h=c.x,g=c.y;p>r!=g>r&&n<(h-u)*(r-p)/(g-p)+u&&(i=!i)}return i}function yX(e){const t=e.slice();return t.sort((n,r)=>n.x<r.x?-1:n.x>r.x?1:n.y<r.y?-1:n.y>r.y?1:0),_X(t)}function _X(e){if(e.length<=1)return e.slice();const t=[];for(let r=0;r<e.length;r++){const i=e[r];for(;t.length>=2;){const s=t[t.length-1],o=t[t.length-2];if((s.x-o.x)*(i.y-o.y)>=(s.y-o.y)*(i.x-o.x))t.pop();else break}t.push(i)}t.pop();const n=[];for(let r=e.length-1;r>=0;r--){const i=e[r];for(;n.length>=2;){const s=n[n.length-1],o=n[n.length-2];if((s.x-o.x)*(i.y-o.y)>=(s.y-o.y)*(i.x-o.x))n.pop();else break}n.push(i)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}var xX=SO,AO=wO,NO=CO,MO=kO,lk=EO;function LO({className:e,...t}){return f.jsx("kbd",{className:he("pointer-events-none inline-flex h-5 min-w-5 items-center justify-center rounded border border-border/60 bg-muted/50 px-1.5 font-mono text-[11px] font-medium text-current select-none",e),...t})}function SX({className:e,...t}){return f.jsx("span",{className:he("inline-flex items-center gap-0.5",e),...t})}const wX="z-50 overflow-hidden rounded-md border border-border bg-card p-0.5 text-[11px] font-medium text-card-foreground shadow-sm animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",v0=xX,Xr=AO,Qr=NO,Br=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>f.jsx(MO,{children:f.jsx(lk,{ref:r,sideOffset:t,className:he("z-50 overflow-hidden rounded-md bg-card text-card-foreground border border-border px-3 py-1.5 text-xs animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));Br.displayName=lk.displayName;const tb=AO,nb=NO;function IO(e){return e.toUpperCase()}function CX(e){const t=e.split("+");return f.jsx(SX,{children:t.map((n,r)=>f.jsx(LO,{children:IO(n)},`${n}-${r}`))})}const Qh=v.forwardRef(({className:e,sideOffset:t=4,children:n,shortcut:r,...i},s)=>{const o=r===void 0?null:Array.isArray(r)?r[0]??null:r;return f.jsx(MO,{children:f.jsx(lk,{ref:s,sideOffset:t,className:he(wX,e),...i,children:o?CX(o):f.jsx("span",{children:typeof n=="string"?IO(n):n})})})});Qh.displayName="HotkeyTooltipContent";const kX="modulepreload",EX=function(e){return"/"+e},QN={},Y=function(t,n,r){let i=Promise.resolve();if(n&&n.length>0){let o=function(u){return Promise.all(u.map(p=>Promise.resolve(p).then(h=>({status:"fulfilled",value:h}),h=>({status:"rejected",reason:h}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),c=(l==null?void 0:l.nonce)||(l==null?void 0:l.getAttribute("nonce"));i=o(n.map(u=>{if(u=EX(u),u in QN)return;QN[u]=!0;const p=u.endsWith(".css"),h=p?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${u}"]${h}`))return;const g=document.createElement("link");if(g.rel=p?"stylesheet":kX,p||(g.as="script"),g.crossOrigin="",g.href=u,c&&g.setAttribute("nonce",c),document.head.appendChild(g),p)return new Promise((b,_)=>{g.addEventListener("load",b),g.addEventListener("error",()=>_(new Error(`Unable to preload CSS for ${u}`)))})}))}function s(o){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=o,window.dispatchEvent(l),!l.defaultPrevented)throw o}return i.then(o=>{for(const l of o||[])l.status==="rejected"&&s(l.reason);return t().catch(s)})},RX=v.lazy(()=>Y(()=>import("./index-D_O0RuN1.js"),[]).then(e=>({default:e.Toaster})));function TX(){return f.jsx(v.Suspense,{fallback:null,children:f.jsx(RX,{position:"bottom-right",theme:"system",closeButton:!0,duration:6e3})})}const AX="0.54.0",NX={version:AX},rr="Kanna",ZN="kanna",MX=".kanna",LX=".kanna-dev",IX="KANNA_RUNTIME_PROFILE",ck=`kanna/${NX.version}`,jX="[kanna]",DX=`~/${rr}`;function b0(){var t;return(t=globalThis.process)==null?void 0:t.env}function PX(e=b0()){var t;return((t=e==null?void 0:e[IX])==null?void 0:t.trim().toLowerCase())==="dev"?"dev":"prod"}function OX(e=b0()){return PX(e)==="dev"?LX:MX}function zX(e=b0()){return`~/${OX(e)}`}function BX(e=b0()){return`${zX(e)}/keybindings.json`}function Sg(e){return e?`${ZN} ${e}`:ZN}const JN=e=>{let t;const n=new Set,r=(u,p)=>{const h=typeof u=="function"?u(t):u;if(!Object.is(h,t)){const g=t;t=p??(typeof h!="object"||h===null)?h:Object.assign({},t,h),n.forEach(b=>b(t,g))}},i=()=>t,l={setState:r,getState:i,getInitialState:()=>c,subscribe:u=>(n.add(u),()=>n.delete(u))},c=t=e(r,i,l);return l},FX=(e=>e?JN(e):JN),$X=e=>e;function HX(e,t=$X){const n=xn.useSyncExternalStore(e.subscribe,xn.useCallback(()=>t(e.getState()),[e,t]),xn.useCallback(()=>t(e.getInitialState()),[e,t]));return xn.useDebugValue(n),n}const UX=e=>{const t=FX(e),n=r=>HX(t,r);return Object.assign(n,t),n},no=(e=>UX),jO="always",DO="funk",VX=[{value:"blow",label:"Blow"},{value:"bottle",label:"Bottle"},{value:"frog",label:"Frog"},{value:"funk",label:"Funk"},{value:"glass",label:"Glass"},{value:"ping",label:"Ping"},{value:"pop",label:"Pop"},{value:"purr",label:"Purr"},{value:"tink",label:"Tink"}];function WX(e){switch(e){case"never":case"unfocused":case"always":return e;default:return jO}}function GX(e){switch(e){case"blow":case"bottle":case"frog":case"funk":case"glass":case"ping":case"pop":case"purr":case"tink":return e;default:return DO}}const _c=no()(e=>({chatSoundPreference:jO,chatSoundId:DO,setChatSoundPreference:t=>e({chatSoundPreference:WX(t)}),setChatSoundId:t=>e({chatSoundId:GX(t)})})),qX={blow:"/chat-sounds/Blow.mp3",bottle:"/chat-sounds/Bottle.mp3",frog:"/chat-sounds/Frog.mp3",funk:"/chat-sounds/Funk.mp3",glass:"/chat-sounds/Glass.mp3",ping:"/chat-sounds/Ping.mp3",pop:"/chat-sounds/Pop.mp3",purr:"/chat-sounds/Purr.mp3",tink:"/chat-sounds/Tink.mp3"};function KX(e=document){return e.visibilityState!=="visible"||!e.hasFocus()}function YX(e){const t=new Audio(qX[e]);return t.preload="auto",t.play()}async function yw(e,t){if(t<=0)return;const n=Array.from({length:t},(r,i)=>new Promise(s=>{window.setTimeout(()=>{YX(e).catch(()=>{}).finally(()=>s())},i*90)}));await Promise.all(n)}function XX(e,t=document){return e==="never"?!1:e==="always"?!0:KX(t)}function QX(e){return e.projectGroups.reduce((t,n)=>t+n.chats.reduce((r,i)=>r+(i.unread?1:0)+(i.status==="waiting_for_user"?1:0),0),0)}function eM(e){let t=0;const n=new Set;for(const r of e.projectGroups)for(const i of r.chats)i.unread&&(t+=1),i.status==="waiting_for_user"&&n.add(i.chatId);return{unreadCount:t,waitingChatIds:n}}function ZX(e,t){if(!e)return 0;const n=eM(e),r=eM(t),i=Math.max(0,r.unreadCount-n.unreadCount);let s=0;for(const o of r.waitingChatIds)n.waitingChatIds.has(o)||(s+=1);return i+s}function _w(e){return e.split(/[\s_-]+/).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" ")}const JX=[/^(?:\/usr\/bin\/env\s+)?(?:\/bin\/)?(?:bash|zsh|sh)\s+(?:-[a-zA-Z]*c|-c)\s+(['"])([\s\S]*)\1$/,/^(?:\/usr\/bin\/env\s+)?(?:\/bin\/)?(?:bash|zsh|sh)\s+(?:-[a-zA-Z]*c|-c)\s+(.+)$/,/^(?:\/usr\/bin\/env\s+)?(?:cmd(?:\.exe)?)\s+\/c\s+(['"])([\s\S]*)\1$/i,/^(?:\/usr\/bin\/env\s+)?(?:cmd(?:\.exe)?)\s+\/c\s+(.+)$/i,/^(?:\/usr\/bin\/env\s+)?(?:powershell(?:\.exe)?|pwsh)\s+(?:-NoProfile\s+)?-Command\s+(['"])([\s\S]*)\1$/i,/^(?:\/usr\/bin\/env\s+)?(?:powershell(?:\.exe)?|pwsh)\s+(?:-NoProfile\s+)?-Command\s+(.+)$/i];function eQ(e){const t=e.trim();for(const n of JX){const r=t.match(n);if(!r)continue;const i=(r[2]??r[1]??"").trim();if(i)return i}return t}function uk(e){return e.split("/").pop()||e}const tQ=1440*6e4;function nQ(e,t){const n=Math.max(0,t-e),r=Math.floor(n/1e3),i=Math.floor(r/3600),s=Math.floor(r%3600/60),o=r%60;return i>0?`${i}h ${s}m`:s>0?`${s}m ${o}s`:`${o}s`}function rQ(e){const t=new Date(e),n=t.getHours().toString().padStart(2,"0"),r=t.getMinutes().toString().padStart(2,"0");return`${n}:${r}`}function iQ(e,t){if(e===void 0)return null;const n=Math.max(0,t-e),r=6e4,i=60*r,s=tQ,o=7*s;return n<r?"now":n<i?`${Math.floor(n/r)}m`:n<s?`${Math.floor(n/i)}h`:n<o?`${Math.floor(n/s)}d`:`${Math.floor(n/o)}w`}function sQ(e){return e.lastMessageAt??e._creationTime}const dk=1e3,xv=60*dk,id=60*xv,Ax=24*id;function dl(e){const t=Math.max(0,e);if(t<xv)return`${Math.floor(t/dk)}s`;if(t<id)return`${Math.floor(t/xv)}m`;if(t<Ax){const i=Math.floor(t/id),s=Math.floor(t%id/xv);return s===0?`${i}h`:`${i}h ${s}m`}const n=Math.floor(t/Ax),r=Math.floor(t%Ax/id);return r===0?`${n}d`:`${n}d ${r}h`}function xw(e){const t=Math.max(0,e);if(t>=id)return dl(t);const n=Math.floor(t/dk),r=Math.floor(n/60),i=n%60;return`${r}:${i.toString().padStart(2,"0")}`}function Sw(e){switch(e){case"idle":return"Idle";case"starting":return"Starting";case"running":return"Running";case"waiting_for_user":return"Waiting";case"failed":return"Failed"}}function tM(e){switch(e){case"running":return"active";case"waiting_for_user":return"attention";case"failed":return"destructive";case"idle":case"starting":default:return"muted"}}function nM(e){switch(e){case"active":return"text-emerald-500 dark:text-emerald-400";case"attention":return"text-amber-500 dark:text-amber-400";case"destructive":return"text-destructive";case"muted":default:return"text-muted-foreground"}}function fk(e){const t=e+"CollectionProvider",[n,r]=xa(t),[i,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),o=x=>{const{scope:S,children:C}=x,E=xn.useRef(null),k=xn.useRef(new Map).current;return f.jsx(i,{scope:S,itemMap:k,collectionRef:E,children:C})};o.displayName=t;const l=e+"CollectionSlot",c=Nc(l),u=xn.forwardRef((x,S)=>{const{scope:C,children:E}=x,k=s(l,C),T=yn(S,k.collectionRef);return f.jsx(c,{ref:T,children:E})});u.displayName=l;const p=e+"CollectionItemSlot",h="data-radix-collection-item",g=Nc(p),b=xn.forwardRef((x,S)=>{const{scope:C,children:E,...k}=x,T=xn.useRef(null),A=yn(S,T),N=s(p,C);return xn.useEffect(()=>(N.itemMap.set(T,{ref:T,...k}),()=>void N.itemMap.delete(T))),f.jsx(g,{[h]:"",ref:A,children:E})});b.displayName=p;function _(x){const S=s(e+"CollectionConsumer",x);return xn.useCallback(()=>{const E=S.collectionRef.current;if(!E)return[];const k=Array.from(E.querySelectorAll(`[${h}]`));return Array.from(S.itemMap.values()).sort((N,M)=>k.indexOf(N.ref.current)-k.indexOf(M.ref.current))},[S.collectionRef,S.itemMap])}return[{Provider:o,Slot:u,ItemSlot:b},_,r]}var oQ=v.createContext(void 0);function hk(e){const t=v.useContext(oQ);return e||t||"ltr"}var Nx="rovingFocusGroup.onEntryFocus",aQ={bubbles:!1,cancelable:!0},jp="RovingFocusGroup",[ww,PO,lQ]=fk(jp),[cQ,OO]=xa(jp,[lQ]),[uQ,dQ]=cQ(jp),zO=v.forwardRef((e,t)=>f.jsx(ww.Provider,{scope:e.__scopeRovingFocusGroup,children:f.jsx(ww.Slot,{scope:e.__scopeRovingFocusGroup,children:f.jsx(fQ,{...e,ref:t})})}));zO.displayName=jp;var fQ=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:s,currentTabStopId:o,defaultCurrentTabStopId:l,onCurrentTabStopIdChange:c,onEntryFocus:u,preventScrollOnEntryFocus:p=!1,...h}=e,g=v.useRef(null),b=yn(t,g),_=hk(s),[x,S]=wd({prop:o,defaultProp:l??null,onChange:c,caller:jp}),[C,E]=v.useState(!1),k=Ks(u),T=PO(n),A=v.useRef(!1),[N,M]=v.useState(0);return v.useEffect(()=>{const j=g.current;if(j)return j.addEventListener(Nx,k),()=>j.removeEventListener(Nx,k)},[k]),f.jsx(uQ,{scope:n,orientation:r,dir:_,loop:i,currentTabStopId:x,onItemFocus:v.useCallback(j=>S(j),[S]),onItemShiftTab:v.useCallback(()=>E(!0),[]),onFocusableItemAdd:v.useCallback(()=>M(j=>j+1),[]),onFocusableItemRemove:v.useCallback(()=>M(j=>j-1),[]),children:f.jsx(rn.div,{tabIndex:C||N===0?-1:0,"data-orientation":r,...h,ref:b,style:{outline:"none",...e.style},onMouseDown:tt(e.onMouseDown,()=>{A.current=!0}),onFocus:tt(e.onFocus,j=>{const U=!A.current;if(j.target===j.currentTarget&&U&&!C){const I=new CustomEvent(Nx,aQ);if(j.currentTarget.dispatchEvent(I),!I.defaultPrevented){const P=T().filter(F=>F.focusable),z=P.find(F=>F.active),O=P.find(F=>F.id===x),V=[z,O,...P].filter(Boolean).map(F=>F.ref.current);$O(V,p)}}A.current=!1}),onBlur:tt(e.onBlur,()=>E(!1))})})}),BO="RovingFocusGroupItem",FO=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,c=ha(),u=s||c,p=dQ(BO,n),h=p.currentTabStopId===u,g=PO(n),{onFocusableItemAdd:b,onFocusableItemRemove:_,currentTabStopId:x}=p;return v.useEffect(()=>{if(r)return b(),()=>_()},[r,b,_]),f.jsx(ww.ItemSlot,{scope:n,id:u,focusable:r,active:i,children:f.jsx(rn.span,{tabIndex:h?0:-1,"data-orientation":p.orientation,...l,ref:t,onMouseDown:tt(e.onMouseDown,S=>{r?p.onItemFocus(u):S.preventDefault()}),onFocus:tt(e.onFocus,()=>p.onItemFocus(u)),onKeyDown:tt(e.onKeyDown,S=>{if(S.key==="Tab"&&S.shiftKey){p.onItemShiftTab();return}if(S.target!==S.currentTarget)return;const C=mQ(S,p.orientation,p.dir);if(C!==void 0){if(S.metaKey||S.ctrlKey||S.altKey||S.shiftKey)return;S.preventDefault();let k=g().filter(T=>T.focusable).map(T=>T.ref.current);if(C==="last")k.reverse();else if(C==="prev"||C==="next"){C==="prev"&&k.reverse();const T=k.indexOf(S.currentTarget);k=p.loop?gQ(k,T+1):k.slice(T+1)}setTimeout(()=>$O(k))}}),children:typeof o=="function"?o({isCurrentTabStop:h,hasTabStop:x!=null}):o})})});FO.displayName=BO;var hQ={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function pQ(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function mQ(e,t,n){const r=pQ(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return hQ[r]}function $O(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function gQ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var vQ=zO,bQ=FO,Cw=["Enter"," "],yQ=["ArrowDown","PageUp","Home"],HO=["ArrowUp","PageDown","End"],_Q=[...yQ,...HO],xQ={ltr:[...Cw,"ArrowRight"],rtl:[...Cw,"ArrowLeft"]},SQ={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Dp="Menu",[Zh,wQ,CQ]=fk(Dp),[Wc,UO]=xa(Dp,[CQ,Il,OO]),y0=Il(),VO=OO(),[kQ,Gc]=Wc(Dp),[EQ,Pp]=Wc(Dp),WO=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=y0(t),[c,u]=v.useState(null),p=v.useRef(!1),h=Ks(s),g=hk(i);return v.useEffect(()=>{const b=()=>{p.current=!0,document.addEventListener("pointerdown",_,{capture:!0,once:!0}),document.addEventListener("pointermove",_,{capture:!0,once:!0})},_=()=>p.current=!1;return document.addEventListener("keydown",b,{capture:!0}),()=>{document.removeEventListener("keydown",b,{capture:!0}),document.removeEventListener("pointerdown",_,{capture:!0}),document.removeEventListener("pointermove",_,{capture:!0})}},[]),f.jsx(f0,{...l,children:f.jsx(kQ,{scope:t,open:n,onOpenChange:h,content:c,onContentChange:u,children:f.jsx(EQ,{scope:t,onClose:v.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:p,dir:g,modal:o,children:r})})})};WO.displayName=Dp;var RQ="MenuAnchor",pk=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=y0(n);return f.jsx(Lp,{...i,...r,ref:t})});pk.displayName=RQ;var mk="MenuPortal",[TQ,GO]=Wc(mk,{forceMount:void 0}),qO=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=Gc(mk,t);return f.jsx(TQ,{scope:t,forceMount:n,children:f.jsx(Ts,{present:n||s.open,children:f.jsx(Wd,{asChild:!0,container:i,children:r})})})};qO.displayName=mk;var ws="MenuContent",[AQ,gk]=Wc(ws),KO=v.forwardRef((e,t)=>{const n=GO(ws,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=Gc(ws,e.__scopeMenu),o=Pp(ws,e.__scopeMenu);return f.jsx(Zh.Provider,{scope:e.__scopeMenu,children:f.jsx(Ts,{present:r||s.open,children:f.jsx(Zh.Slot,{scope:e.__scopeMenu,children:o.modal?f.jsx(NQ,{...i,ref:t}):f.jsx(MQ,{...i,ref:t})})})})}),NQ=v.forwardRef((e,t)=>{const n=Gc(ws,e.__scopeMenu),r=v.useRef(null),i=yn(t,r);return v.useEffect(()=>{const s=r.current;if(s)return s0(s)},[]),f.jsx(vk,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:tt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),MQ=v.forwardRef((e,t)=>{const n=Gc(ws,e.__scopeMenu);return f.jsx(vk,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),LQ=Nc("MenuContent.ScrollLock"),vk=v.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:l,onEntryFocus:c,onEscapeKeyDown:u,onPointerDownOutside:p,onFocusOutside:h,onInteractOutside:g,onDismiss:b,disableOutsideScroll:_,...x}=e,S=Gc(ws,n),C=Pp(ws,n),E=y0(n),k=VO(n),T=wQ(n),[A,N]=v.useState(null),M=v.useRef(null),j=yn(t,M,S.onContentChange),U=v.useRef(0),I=v.useRef(""),P=v.useRef(0),z=v.useRef(null),O=v.useRef("right"),$=v.useRef(0),V=_?Ap:v.Fragment,F=_?{as:LQ,allowPinchZoom:!0}:void 0,H=Z=>{var ne,se;const D=I.current+Z,G=T().filter(ce=>!ce.disabled),ee=document.activeElement,B=(ne=G.find(ce=>ce.ref.current===ee))==null?void 0:ne.textValue,le=G.map(ce=>ce.textValue),oe=VQ(le,D,B),J=(se=G.find(ce=>ce.textValue===oe))==null?void 0:se.ref.current;(function ce(de){I.current=de,window.clearTimeout(U.current),de!==""&&(U.current=window.setTimeout(()=>ce(""),1e3))})(D),J&&setTimeout(()=>J.focus())};v.useEffect(()=>()=>window.clearTimeout(U.current),[]),r0();const W=v.useCallback(Z=>{var G,ee;return O.current===((G=z.current)==null?void 0:G.side)&&GQ(Z,(ee=z.current)==null?void 0:ee.area)},[]);return f.jsx(AQ,{scope:n,searchRef:I,onItemEnter:v.useCallback(Z=>{W(Z)&&Z.preventDefault()},[W]),onItemLeave:v.useCallback(Z=>{var D;W(Z)||((D=M.current)==null||D.focus(),N(null))},[W]),onTriggerLeave:v.useCallback(Z=>{W(Z)&&Z.preventDefault()},[W]),pointerGraceTimerRef:P,onPointerGraceIntentChange:v.useCallback(Z=>{z.current=Z},[]),children:f.jsx(V,{...F,children:f.jsx(Tp,{asChild:!0,trapped:i,onMountAutoFocus:tt(s,Z=>{var D;Z.preventDefault(),(D=M.current)==null||D.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:f.jsx(Vd,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:u,onPointerDownOutside:p,onFocusOutside:h,onInteractOutside:g,onDismiss:b,children:f.jsx(vQ,{asChild:!0,...k,dir:C.dir,orientation:"vertical",loop:r,currentTabStopId:A,onCurrentTabStopIdChange:N,onEntryFocus:tt(c,Z=>{C.isUsingKeyboardRef.current||Z.preventDefault()}),preventScrollOnEntryFocus:!0,children:f.jsx(h0,{role:"menu","aria-orientation":"vertical","data-state":u3(S.open),"data-radix-menu-content":"",dir:C.dir,...E,...x,ref:j,style:{outline:"none",...x.style},onKeyDown:tt(x.onKeyDown,Z=>{const G=Z.target.closest("[data-radix-menu-content]")===Z.currentTarget,ee=Z.ctrlKey||Z.altKey||Z.metaKey,B=Z.key.length===1;G&&(Z.key==="Tab"&&Z.preventDefault(),!ee&&B&&H(Z.key));const le=M.current;if(Z.target!==le||!_Q.includes(Z.key))return;Z.preventDefault();const J=T().filter(ne=>!ne.disabled).map(ne=>ne.ref.current);HO.includes(Z.key)&&J.reverse(),HQ(J)}),onBlur:tt(e.onBlur,Z=>{Z.currentTarget.contains(Z.target)||(window.clearTimeout(U.current),I.current="")}),onPointerMove:tt(e.onPointerMove,Jh(Z=>{const D=Z.target,G=$.current!==Z.clientX;if(Z.currentTarget.contains(D)&&G){const ee=Z.clientX>$.current?"right":"left";O.current=ee,$.current=Z.clientX}}))})})})})})})});KO.displayName=ws;var IQ="MenuGroup",bk=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return f.jsx(rn.div,{role:"group",...r,ref:t})});bk.displayName=IQ;var jQ="MenuLabel",YO=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return f.jsx(rn.div,{...r,ref:t})});YO.displayName=jQ;var rb="MenuItem",rM="menu.itemSelect",_0=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=v.useRef(null),o=Pp(rb,e.__scopeMenu),l=gk(rb,e.__scopeMenu),c=yn(t,s),u=v.useRef(!1),p=()=>{const h=s.current;if(!n&&h){const g=new CustomEvent(rM,{bubbles:!0,cancelable:!0});h.addEventListener(rM,b=>r==null?void 0:r(b),{once:!0}),e5(h,g),g.defaultPrevented?u.current=!1:o.onClose()}};return f.jsx(XO,{...i,ref:c,disabled:n,onClick:tt(e.onClick,p),onPointerDown:h=>{var g;(g=e.onPointerDown)==null||g.call(e,h),u.current=!0},onPointerUp:tt(e.onPointerUp,h=>{var g;u.current||(g=h.currentTarget)==null||g.click()}),onKeyDown:tt(e.onKeyDown,h=>{const g=l.searchRef.current!=="";n||g&&h.key===" "||Cw.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});_0.displayName=rb;var XO=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=gk(rb,n),l=VO(n),c=v.useRef(null),u=yn(t,c),[p,h]=v.useState(!1),[g,b]=v.useState("");return v.useEffect(()=>{const _=c.current;_&&b((_.textContent??"").trim())},[s.children]),f.jsx(Zh.ItemSlot,{scope:n,disabled:r,textValue:i??g,children:f.jsx(bQ,{asChild:!0,...l,focusable:!r,children:f.jsx(rn.div,{role:"menuitem","data-highlighted":p?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:tt(e.onPointerMove,Jh(_=>{r?o.onItemLeave(_):(o.onItemEnter(_),_.defaultPrevented||_.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:tt(e.onPointerLeave,Jh(_=>o.onItemLeave(_))),onFocus:tt(e.onFocus,()=>h(!0)),onBlur:tt(e.onBlur,()=>h(!1))})})})}),DQ="MenuCheckboxItem",QO=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return f.jsx(n3,{scope:e.__scopeMenu,checked:n,children:f.jsx(_0,{role:"menuitemcheckbox","aria-checked":ib(n)?"mixed":n,...i,ref:t,"data-state":_k(n),onSelect:tt(i.onSelect,()=>r==null?void 0:r(ib(n)?!0:!n),{checkForDefaultPrevented:!1})})})});QO.displayName=DQ;var ZO="MenuRadioGroup",[PQ,OQ]=Wc(ZO,{value:void 0,onValueChange:()=>{}}),JO=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=Ks(r);return f.jsx(PQ,{scope:e.__scopeMenu,value:n,onValueChange:s,children:f.jsx(bk,{...i,ref:t})})});JO.displayName=ZO;var e3="MenuRadioItem",t3=v.forwardRef((e,t)=>{const{value:n,...r}=e,i=OQ(e3,e.__scopeMenu),s=n===i.value;return f.jsx(n3,{scope:e.__scopeMenu,checked:s,children:f.jsx(_0,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":_k(s),onSelect:tt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});t3.displayName=e3;var yk="MenuItemIndicator",[n3,zQ]=Wc(yk,{checked:!1}),r3=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=zQ(yk,n);return f.jsx(Ts,{present:r||ib(s.checked)||s.checked===!0,children:f.jsx(rn.span,{...i,ref:t,"data-state":_k(s.checked)})})});r3.displayName=yk;var BQ="MenuSeparator",i3=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return f.jsx(rn.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});i3.displayName=BQ;var FQ="MenuArrow",s3=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=y0(n);return f.jsx(p0,{...i,...r,ref:t})});s3.displayName=FQ;var $Q="MenuSub",[UEe,o3]=Wc($Q),yh="MenuSubTrigger",a3=v.forwardRef((e,t)=>{const n=Gc(yh,e.__scopeMenu),r=Pp(yh,e.__scopeMenu),i=o3(yh,e.__scopeMenu),s=gk(yh,e.__scopeMenu),o=v.useRef(null),{pointerGraceTimerRef:l,onPointerGraceIntentChange:c}=s,u={__scopeMenu:e.__scopeMenu},p=v.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return v.useEffect(()=>p,[p]),v.useEffect(()=>{const h=l.current;return()=>{window.clearTimeout(h),c(null)}},[l,c]),f.jsx(pk,{asChild:!0,...u,children:f.jsx(XO,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":u3(n.open),...e,ref:BC(t,i.onTriggerChange),onClick:h=>{var g;(g=e.onClick)==null||g.call(e,h),!(e.disabled||h.defaultPrevented)&&(h.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:tt(e.onPointerMove,Jh(h=>{s.onItemEnter(h),!h.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),p()},100))})),onPointerLeave:tt(e.onPointerLeave,Jh(h=>{var b,_;p();const g=(b=n.content)==null?void 0:b.getBoundingClientRect();if(g){const x=(_=n.content)==null?void 0:_.dataset.side,S=x==="right",C=S?-5:5,E=g[S?"left":"right"],k=g[S?"right":"left"];s.onPointerGraceIntentChange({area:[{x:h.clientX+C,y:h.clientY},{x:E,y:g.top},{x:k,y:g.top},{x:k,y:g.bottom},{x:E,y:g.bottom}],side:x}),window.clearTimeout(l.current),l.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(h),h.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:tt(e.onKeyDown,h=>{var b;const g=s.searchRef.current!=="";e.disabled||g&&h.key===" "||xQ[r.dir].includes(h.key)&&(n.onOpenChange(!0),(b=n.content)==null||b.focus(),h.preventDefault())})})})});a3.displayName=yh;var l3="MenuSubContent",c3=v.forwardRef((e,t)=>{const n=GO(ws,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=Gc(ws,e.__scopeMenu),o=Pp(ws,e.__scopeMenu),l=o3(l3,e.__scopeMenu),c=v.useRef(null),u=yn(t,c);return f.jsx(Zh.Provider,{scope:e.__scopeMenu,children:f.jsx(Ts,{present:r||s.open,children:f.jsx(Zh.Slot,{scope:e.__scopeMenu,children:f.jsx(vk,{id:l.contentId,"aria-labelledby":l.triggerId,...i,ref:u,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:p=>{var h;o.isUsingKeyboardRef.current&&((h=c.current)==null||h.focus()),p.preventDefault()},onCloseAutoFocus:p=>p.preventDefault(),onFocusOutside:tt(e.onFocusOutside,p=>{p.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:tt(e.onEscapeKeyDown,p=>{o.onClose(),p.preventDefault()}),onKeyDown:tt(e.onKeyDown,p=>{var b;const h=p.currentTarget.contains(p.target),g=SQ[o.dir].includes(p.key);h&&g&&(s.onOpenChange(!1),(b=l.trigger)==null||b.focus(),p.preventDefault())})})})})})});c3.displayName=l3;function u3(e){return e?"open":"closed"}function ib(e){return e==="indeterminate"}function _k(e){return ib(e)?"indeterminate":e?"checked":"unchecked"}function HQ(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function UQ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function VQ(e,t,n){const i=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=UQ(e,Math.max(s,0));i.length===1&&(o=o.filter(u=>u!==n));const c=o.find(u=>u.toLowerCase().startsWith(i.toLowerCase()));return c!==n?c:void 0}function WQ(e,t){const{x:n,y:r}=e;let i=!1;for(let s=0,o=t.length-1;s<t.length;o=s++){const l=t[s],c=t[o],u=l.x,p=l.y,h=c.x,g=c.y;p>r!=g>r&&n<(h-u)*(r-p)/(g-p)+u&&(i=!i)}return i}function GQ(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return WQ(n,t)}function Jh(e){return t=>t.pointerType==="mouse"?e(t):void 0}var qQ=WO,KQ=pk,YQ=qO,XQ=KO,QQ=bk,ZQ=YO,JQ=_0,eZ=QO,tZ=JO,nZ=t3,rZ=r3,iZ=i3,sZ=s3,oZ=a3,aZ=c3,xk="ContextMenu",[lZ]=xa(xk,[UO]),vi=UO(),[cZ,d3]=lZ(xk),f3=e=>{const{__scopeContextMenu:t,children:n,onOpenChange:r,dir:i,modal:s=!0}=e,[o,l]=v.useState(!1),c=vi(t),u=Ks(r),p=v.useCallback(h=>{l(h),u(h)},[u]);return f.jsx(cZ,{scope:t,open:o,onOpenChange:p,modal:s,children:f.jsx(qQ,{...c,dir:i,open:o,onOpenChange:p,modal:s,children:n})})};f3.displayName=xk;var h3="ContextMenuTrigger",p3=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,disabled:r=!1,...i}=e,s=d3(h3,n),o=vi(n),l=v.useRef({x:0,y:0}),c=v.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...l.current})}),u=v.useRef(0),p=v.useCallback(()=>window.clearTimeout(u.current),[]),h=g=>{l.current={x:g.clientX,y:g.clientY},s.onOpenChange(!0)};return v.useEffect(()=>p,[p]),v.useEffect(()=>void(r&&p()),[r,p]),f.jsxs(f.Fragment,{children:[f.jsx(KQ,{...o,virtualRef:c}),f.jsx(rn.span,{"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,...i,ref:t,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:tt(e.onContextMenu,g=>{p(),h(g),g.preventDefault()}),onPointerDown:r?e.onPointerDown:tt(e.onPointerDown,wg(g=>{p(),u.current=window.setTimeout(()=>h(g),700)})),onPointerMove:r?e.onPointerMove:tt(e.onPointerMove,wg(p)),onPointerCancel:r?e.onPointerCancel:tt(e.onPointerCancel,wg(p)),onPointerUp:r?e.onPointerUp:tt(e.onPointerUp,wg(p))})]})});p3.displayName=h3;var uZ="ContextMenuPortal",m3=e=>{const{__scopeContextMenu:t,...n}=e,r=vi(t);return f.jsx(YQ,{...r,...n})};m3.displayName=uZ;var g3="ContextMenuContent",v3=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=d3(g3,n),s=vi(n),o=v.useRef(!1);return f.jsx(XQ,{...s,...r,ref:t,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:l=>{var c;(c=e.onCloseAutoFocus)==null||c.call(e,l),!l.defaultPrevented&&o.current&&l.preventDefault(),o.current=!1},onInteractOutside:l=>{var c;(c=e.onInteractOutside)==null||c.call(e,l),!l.defaultPrevented&&!i.modal&&(o.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});v3.displayName=g3;var dZ="ContextMenuGroup",fZ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(QQ,{...i,...r,ref:t})});fZ.displayName=dZ;var hZ="ContextMenuLabel",pZ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(ZQ,{...i,...r,ref:t})});pZ.displayName=hZ;var mZ="ContextMenuItem",b3=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(JQ,{...i,...r,ref:t})});b3.displayName=mZ;var gZ="ContextMenuCheckboxItem",vZ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(eZ,{...i,...r,ref:t})});vZ.displayName=gZ;var bZ="ContextMenuRadioGroup",yZ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(tZ,{...i,...r,ref:t})});yZ.displayName=bZ;var _Z="ContextMenuRadioItem",xZ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(nZ,{...i,...r,ref:t})});xZ.displayName=_Z;var SZ="ContextMenuItemIndicator",wZ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(rZ,{...i,...r,ref:t})});wZ.displayName=SZ;var CZ="ContextMenuSeparator",y3=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(iZ,{...i,...r,ref:t})});y3.displayName=CZ;var kZ="ContextMenuArrow",EZ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(sZ,{...i,...r,ref:t})});EZ.displayName=kZ;var RZ="ContextMenuSubTrigger",TZ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(oZ,{...i,...r,ref:t})});TZ.displayName=RZ;var AZ="ContextMenuSubContent",NZ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=vi(n);return f.jsx(aZ,{...i,...r,ref:t,style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});NZ.displayName=AZ;function wg(e){return t=>t.pointerType!=="mouse"?e(t):void 0}var MZ=f3,LZ=p3,IZ=m3,_3=v3,x3=b3,S3=y3;const w3=v.createContext(null);function qc({onOpenChange:e,...t}){const[n,r]=v.useState(0),i=v.useCallback(()=>{r(s=>s+1),e==null||e(!1)},[e]);return f.jsx(w3.Provider,{value:i,children:f.jsx(MZ,{onOpenChange:e,...t},n)})}const Kc=LZ,jl=v.forwardRef(({className:e,...t},n)=>f.jsx(IZ,{children:f.jsx(_3,{ref:n,className:he("z-50 min-w-[170px] overflow-hidden rounded-xl border border-border bg-background p-1 shadow-lg outline-hidden animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",e),...t})}));jl.displayName=_3.displayName;const jn=v.forwardRef(({className:e,onSelect:t,...n},r)=>{const i=v.useContext(w3);return f.jsx(x3,{ref:r,className:he("relative flex cursor-default select-none items-center gap-2.5 rounded-lg px-3 py-2 text-xs font-medium text-foreground outline-hidden transition-colors hover:bg-muted focus:bg-muted data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),onSelect:s=>{t==null||t(s),i==null||i()},...n})});jn.displayName=x3.displayName;const C3=v.forwardRef(({className:e,...t},n)=>f.jsx(S3,{ref:n,className:he("-mx-1 my-1 h-px bg-border",e),...t}));C3.displayName=S3.displayName;var x0="Popover",[k3]=xa(x0,[Il]),Op=Il(),[jZ,Dl]=k3(x0),E3=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=Op(t),c=v.useRef(null),[u,p]=v.useState(!1),[h,g]=wd({prop:r,defaultProp:i??!1,onChange:s,caller:x0});return f.jsx(f0,{...l,children:f.jsx(jZ,{scope:t,contentId:ha(),triggerRef:c,open:h,onOpenChange:g,onOpenToggle:v.useCallback(()=>g(b=>!b),[g]),hasCustomAnchor:u,onCustomAnchorAdd:v.useCallback(()=>p(!0),[]),onCustomAnchorRemove:v.useCallback(()=>p(!1),[]),modal:o,children:n})})};E3.displayName=x0;var R3="PopoverAnchor",DZ=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Dl(R3,n),s=Op(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return v.useEffect(()=>(o(),()=>l()),[o,l]),f.jsx(Lp,{...s,...r,ref:t})});DZ.displayName=R3;var T3="PopoverTrigger",A3=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Dl(T3,n),s=Op(n),o=yn(t,i.triggerRef),l=f.jsx(rn.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":j3(i.open),...r,ref:o,onClick:tt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:f.jsx(Lp,{asChild:!0,...s,children:l})});A3.displayName=T3;var Sk="PopoverPortal",[PZ,OZ]=k3(Sk,{forceMount:void 0}),N3=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=Dl(Sk,t);return f.jsx(PZ,{scope:t,forceMount:n,children:f.jsx(Ts,{present:n||s.open,children:f.jsx(Wd,{asChild:!0,container:i,children:r})})})};N3.displayName=Sk;var Ed="PopoverContent",M3=v.forwardRef((e,t)=>{const n=OZ(Ed,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=Dl(Ed,e.__scopePopover);return f.jsx(Ts,{present:r||s.open,children:s.modal?f.jsx(BZ,{...i,ref:t}):f.jsx(FZ,{...i,ref:t})})});M3.displayName=Ed;var zZ=Nc("PopoverContent.RemoveScroll"),BZ=v.forwardRef((e,t)=>{const n=Dl(Ed,e.__scopePopover),r=v.useRef(null),i=yn(t,r),s=v.useRef(!1);return v.useEffect(()=>{const o=r.current;if(o)return s0(o)},[]),f.jsx(Ap,{as:zZ,allowPinchZoom:!0,children:f.jsx(L3,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:tt(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:tt(e.onPointerDownOutside,o=>{const l=o.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,u=l.button===2||c;s.current=u},{checkForDefaultPrevented:!1}),onFocusOutside:tt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),FZ=v.forwardRef((e,t)=>{const n=Dl(Ed,e.__scopePopover),r=v.useRef(!1),i=v.useRef(!1);return f.jsx(L3,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var o,l;(o=e.onCloseAutoFocus)==null||o.call(e,s),s.defaultPrevented||(r.current||(l=n.triggerRef.current)==null||l.focus(),s.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:s=>{var c,u;(c=e.onInteractOutside)==null||c.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=s.target;((u=n.triggerRef.current)==null?void 0:u.contains(o))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}})}),L3=v.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:l,onPointerDownOutside:c,onFocusOutside:u,onInteractOutside:p,...h}=e,g=Dl(Ed,n),b=Op(n);return r0(),f.jsx(Tp,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:f.jsx(Vd,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:p,onEscapeKeyDown:l,onPointerDownOutside:c,onFocusOutside:u,onDismiss:()=>g.onOpenChange(!1),children:f.jsx(h0,{"data-state":j3(g.open),role:"dialog",id:g.contentId,...b,...h,ref:t,style:{...h.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),I3="PopoverClose",$Z=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Dl(I3,n);return f.jsx(rn.button,{type:"button",...r,ref:t,onClick:tt(e.onClick,()=>i.onOpenChange(!1))})});$Z.displayName=I3;var HZ="PopoverArrow",UZ=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Op(n);return f.jsx(p0,{...i,...r,ref:t})});UZ.displayName=HZ;function j3(e){return e?"open":"closed"}var VZ=E3,WZ=A3,GZ=N3,D3=M3;const wk=VZ,Ck=WZ,S0=v.forwardRef(({className:e,align:t="center",sideOffset:n=4,...r},i)=>f.jsx(GZ,{children:f.jsx(D3,{ref:i,align:t,sideOffset:n,[Kh]:"",onCloseAutoFocus:s=>{var o;s.preventDefault(),window.dispatchEvent(new Event(Yv)),(o=r.onCloseAutoFocus)==null||o.call(r,s)},className:he("z-50 w-72 rounded-xl border border-border bg-background p-4 shadow-lg outline-hidden animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...r})}));S0.displayName=D3.displayName;function qZ({editorLabel:e,starred:t,onCopyPath:n,onShowArchived:r,onOpenInFinder:i,onOpenInEditor:s,onToggleStar:o,onHide:l,children:c}){return f.jsxs(qc,{children:[f.jsx(Kc,{asChild:!0,children:c}),f.jsxs(jl,{children:[f.jsxs(jn,{onSelect:u=>{u.stopPropagation(),o()},children:[t?f.jsx(XW,{className:"h-3.5 w-3.5"}):f.jsx(QP,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:t?"Unstar project":"Star project"})]}),f.jsxs(jn,{onSelect:u=>{u.stopPropagation(),n()},children:[f.jsx(El,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Copy Path"})]}),f.jsxs(jn,{onSelect:u=>{u.stopPropagation(),r()},children:[f.jsx(MC,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Show Archived"})]}),f.jsxs(jn,{onSelect:u=>{u.stopPropagation(),i()},children:[f.jsx(e0,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Show in Finder"})]}),f.jsxs(jn,{onSelect:u=>{u.stopPropagation(),s()},children:[f.jsx(IC,{className:"h-3.5 w-3.5"}),f.jsxs("span",{className:"text-xs font-medium",children:["Open in ",e]})]}),f.jsxs(jn,{onSelect:u=>{u.stopPropagation(),l()},className:"text-destructive hover:bg-destructive/10 focus:bg-destructive/10",children:[f.jsx(X9,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Hide"})]})]})]})}function KZ({canFork:e,onRename:t,onShare:n,onOpenInFinder:r,onFork:i,onArchive:s,onDelete:o,children:l}){return f.jsxs(qc,{children:[f.jsx(Kc,{asChild:!0,children:l}),f.jsxs(jl,{children:[f.jsxs(jn,{onSelect:c=>{c.preventDefault(),t()},children:[f.jsx(Rp,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Rename"})]}),f.jsxs(jn,{onSelect:c=>{c.preventDefault(),n()},children:[f.jsx(zC,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Share"})]}),f.jsxs(jn,{onSelect:c=>{c.preventDefault(),r()},children:[f.jsx(e0,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Open in Finder"})]}),f.jsxs(jn,{disabled:!e,onSelect:c=>{c.preventDefault(),e&&i()},children:[f.jsx(XP,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Fork"})]}),f.jsxs(jn,{onSelect:c=>{c.preventDefault(),s()},children:[f.jsx(MC,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Archive"})]}),f.jsxs(jn,{onSelect:c=>{c.preventDefault(),o()},className:"text-destructive dark:text-red-400 hover:bg-destructive/10 focus:bg-destructive/10 dark:hover:bg-red-500/20 dark:focus:bg-red-500/20",children:[f.jsx(Ud,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Delete"})]})]})]})}function YZ({stackTitle:e,onRename:t,onEditMembers:n,onDelete:r,children:i}){const[s,o]=v.useState(!1);function l(c){return()=>{o(!1),c()}}return f.jsxs(wk,{open:s,onOpenChange:o,children:[f.jsx(Ck,{asChild:!0,children:i}),f.jsxs(S0,{align:"end",sideOffset:4,className:"w-44 p-1",role:"menu","aria-label":`Actions for ${e}`,children:[f.jsxs("button",{type:"button",role:"menuitem",onClick:l(t),className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs font-medium hover:bg-muted focus-visible:bg-muted outline-hidden",children:[f.jsx(Rp,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Rename"})]}),f.jsxs("button",{type:"button",role:"menuitem",onClick:l(n),className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs font-medium hover:bg-muted focus-visible:bg-muted outline-hidden",children:[f.jsx(ZP,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Edit members"})]}),f.jsxs("button",{type:"button",role:"menuitem",onClick:l(r),className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs font-medium text-destructive dark:text-red-400 hover:bg-destructive/10 focus-visible:bg-destructive/10 dark:hover:bg-red-500/20 dark:focus-visible:bg-red-500/20 outline-hidden",children:[f.jsx(Ud,{className:"h-3.5 w-3.5"}),f.jsxs("span",{children:["Delete ",e]})]})]})]})}function XZ({stackTitle:e,onRename:t,onEditMembers:n,onDelete:r,children:i}){return f.jsxs(qc,{children:[f.jsx(Kc,{asChild:!0,children:i}),f.jsxs(jl,{children:[f.jsxs(jn,{onSelect:s=>{s.preventDefault(),t()},children:[f.jsx(Rp,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Rename"})]}),f.jsxs(jn,{onSelect:s=>{s.preventDefault(),n()},children:[f.jsx(ZP,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Edit members"})]}),f.jsxs(jn,{onSelect:s=>{s.preventDefault(),r()},className:"text-destructive dark:text-red-400 hover:bg-destructive/10 focus:bg-destructive/10 dark:hover:bg-red-500/20 dark:focus:bg-red-500/20",children:[f.jsx(Ud,{className:"h-3.5 w-3.5"}),f.jsxs("span",{className:"text-xs font-medium",children:["Delete ",e]})]})]})]})}function QZ(e){return e.status==="running"||e.status==="starting"?"warning":e.status==="waiting_for_user"?"info":e.status==="failed"?"destructive":e.unread?"success":null}function ZZ(e){switch(e){case"warning":return"bg-warning";case"info":return"bg-info";case"success":return"bg-success";case"destructive":return"bg-destructive";default:return""}}function JZ(e){switch(e){case"warning":return"text-warning";case"info":return"text-info";case"success":return"text-success";case"destructive":return"text-destructive";default:return"text-muted-foreground"}}function eJ({chat:e,activeChatId:t,nowMs:n,shortcutHint:r=null,showShortcutHint:i=!1,onSelectChat:s,onRenameChat:o,onShareChat:l,onOpenInFinder:c,onForkChat:u,onArchiveChat:p,onDeleteChat:h}){const g=(e.status==="running"||e.status==="waiting_for_user")&&e.stateEnteredAt!=null,b=g&&e.stateEnteredAt!=null?`${Sw(e.status)} ${xw(n-e.stateEnteredAt)}`:dl(n-(e.lastMessageAt??e._creationTime)),_=i&&r?r:b,x=i&&!!r,S=LK(e.chatId),C=t===S,E=QZ(e),k=e.canFork?"w-12":g?"w-12 md:w-20":"w-6 md:w-14",T=f.jsxs("div",{"data-chat-id":S,className:he("group flex items-center gap-2 pl-2 pr-1 py-1.5 rounded-md cursor-pointer transition-colors duration-150",C?"bg-muted":"hover:bg-muted/40"),onClick:()=>s(e.chatId),children:[f.jsx("span",{className:"relative flex h-3.5 w-3.5 shrink-0 items-center justify-center","aria-hidden":!0,children:E?f.jsx("span",{className:he("h-2 w-2 rounded-full",ZZ(E))}):null}),f.jsx("span",{className:he("truncate flex-1 text-sm",C?"text-foreground font-medium":"text-foreground/90",e.status==="idle"&&!e.unread&&!C?"text-muted-foreground":""),children:e.title}),f.jsxs("div",{className:he("relative h-6 shrink-0",k),children:[_?x?f.jsx("span",{className:"hidden md:flex absolute inset-0 items-center justify-end pr-0.5 text-[11px] text-foreground transition-opacity duration-150 group-hover:opacity-0",children:f.jsx(LO,{className:"h-4 min-w-4 rounded-sm border-border/50 bg-transparent px-1 text-[10px]",children:r})}):f.jsx("span",{className:he("hidden md:flex absolute inset-0 items-center justify-end pr-1 text-[11px] tabular-nums transition-opacity duration-150 group-hover:opacity-0 whitespace-nowrap",g?JZ(E):"text-muted-foreground"),children:_}):null,f.jsxs("div",{className:he("absolute inset-0 flex items-center justify-end gap-0 transition-opacity duration-150",_?"opacity-100 md:opacity-0 md:group-hover:opacity-100":"opacity-100"),children:[e.canFork?f.jsx(Ke,{variant:"ghost",size:"icon",className:"h-6 w-6 cursor-pointer rounded-sm hover:!bg-transparent !border-0",onClick:A=>{A.stopPropagation(),u(e.chatId)},title:"Fork chat",children:f.jsx(XP,{className:"size-3.5"})}):null,f.jsx(Ke,{variant:"ghost",size:"icon",className:"h-6 w-6 cursor-pointer rounded-sm hover:!bg-transparent !border-0",onClick:A=>{A.stopPropagation(),p(e.chatId)},title:"Archive chat",children:f.jsx(MC,{className:"size-3.5"})})]})]})]},e._id);return f.jsx(KZ,{canFork:e.canFork,onRename:()=>o(e.chatId),onShare:()=>l(e.chatId),onOpenInFinder:()=>c(e.localPath),onFork:()=>u(e.chatId),onArchive:()=>p(e.chatId),onDelete:()=>h(e.chatId),children:T})}const tJ=v.memo(eJ);function nJ(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return v.useMemo(()=>r=>{t.forEach(i=>i(r))},t)}const w0=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Yd(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function kk(e){return"nodeType"in e}function Ii(e){var t,n;return e?Yd(e)?e:kk(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function Ek(e){const{Document:t}=Ii(e);return e instanceof t}function zp(e){return Yd(e)?!1:e instanceof Ii(e).HTMLElement}function P3(e){return e instanceof Ii(e).SVGElement}function Xd(e){return e?Yd(e)?e.document:kk(e)?Ek(e)?e:zp(e)||P3(e)?e.ownerDocument:document:document:document}const Mo=w0?v.useLayoutEffect:v.useEffect;function Rk(e){const t=v.useRef(e);return Mo(()=>{t.current=e}),v.useCallback(function(){for(var n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];return t.current==null?void 0:t.current(...r)},[])}function rJ(){const e=v.useRef(null),t=v.useCallback((r,i)=>{e.current=setInterval(r,i)},[]),n=v.useCallback(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[]);return[t,n]}function ep(e,t){t===void 0&&(t=[e]);const n=v.useRef(e);return Mo(()=>{n.current!==e&&(n.current=e)},t),n}function Bp(e,t){const n=v.useRef();return v.useMemo(()=>{const r=e(n.current);return n.current=r,r},[...t])}function sb(e){const t=Rk(e),n=v.useRef(null),r=v.useCallback(i=>{i!==n.current&&(t==null||t(i,n.current)),n.current=i},[]);return[n,r]}function kw(e){const t=v.useRef();return v.useEffect(()=>{t.current=e},[e]),t.current}let Mx={};function Fp(e,t){return v.useMemo(()=>{if(t)return t;const n=Mx[e]==null?0:Mx[e]+1;return Mx[e]=n,e+"-"+n},[e,t])}function O3(e){return function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return r.reduce((s,o)=>{const l=Object.entries(o);for(const[c,u]of l){const p=s[c];p!=null&&(s[c]=p+e*u)}return s},{...t})}}const fd=O3(1),ob=O3(-1);function iJ(e){return"clientX"in e&&"clientY"in e}function Tk(e){if(!e)return!1;const{KeyboardEvent:t}=Ii(e.target);return t&&e instanceof t}function sJ(e){if(!e)return!1;const{TouchEvent:t}=Ii(e.target);return t&&e instanceof t}function Ew(e){if(sJ(e)){if(e.touches&&e.touches.length){const{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){const{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return iJ(e)?{x:e.clientX,y:e.clientY}:null}const tp=Object.freeze({Translate:{toString(e){if(!e)return;const{x:t,y:n}=e;return"translate3d("+(t?Math.round(t):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(e){if(!e)return;const{scaleX:t,scaleY:n}=e;return"scaleX("+t+") scaleY("+n+")"}},Transform:{toString(e){if(e)return[tp.Translate.toString(e),tp.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),iM="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function oJ(e){return e.matches(iM)?e:e.querySelector(iM)}const aJ={display:"none"};function lJ(e){let{id:t,value:n}=e;return xn.createElement("div",{id:t,style:aJ},n)}function cJ(e){let{id:t,announcement:n,ariaLiveType:r="assertive"}=e;const i={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return xn.createElement("div",{id:t,style:i,role:"status","aria-live":r,"aria-atomic":!0},n)}function uJ(){const[e,t]=v.useState("");return{announce:v.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const z3=v.createContext(null);function dJ(e){const t=v.useContext(z3);v.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function fJ(){const[e]=v.useState(()=>new Set),t=v.useCallback(r=>(e.add(r),()=>e.delete(r)),[e]);return[v.useCallback(r=>{let{type:i,event:s}=r;e.forEach(o=>{var l;return(l=o[i])==null?void 0:l.call(o,s)})},[e]),t]}const hJ={draggable:`
|
|
696
696
|
To pick up a draggable item, press the space bar.
|
|
697
697
|
While dragging, use the arrow keys to move the item.
|
|
698
698
|
Press space again to drop the item in its new position, or press escape to cancel.
|
|
@@ -2594,7 +2594,7 @@ XID_Start XIDS`.split(/\s/).map(e=>[O0(e),e])),Goe=new Map([["s",wr(383)],[wr(38
|
|
|
2594
2594
|
`))}function c(b,_,x,S){const C=x.enter("tableCell"),E=x.enter("phrasing"),k=x.containerPhrasing(b,{...S,before:s,after:s});return E(),C(),k}function u(b,_){return Npe(b,{align:_,alignDelimiters:r,padding:n,stringLength:i})}function p(b,_,x){const S=b.children;let C=-1;const E=[],k=_.enter("table");for(;++C<S.length;)E[C]=h(S[C],_,x);return k(),E}function h(b,_,x){const S=b.children;let C=-1;const E=[],k=_.enter("tableRow");for(;++C<S.length;)E[C]=c(S[C],b,_,x);return k(),E}function g(b,_,x){let S=w8.inlineCode(b,_,x);return x.stack.includes("tableCell")&&(S=S.replace(/\|/g,"\\$&")),S}}function vme(){return{exit:{taskListCheckValueChecked:RI,taskListCheckValueUnchecked:RI,paragraph:yme}}}function bme(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:_me}}}function RI(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function yme(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const i=t.children;let s=-1,o;for(;++s<i.length;){const l=i[s];if(l.type==="paragraph"){o=l;break}}o===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(e)}function _me(e,t,n,r){const i=e.children[0],s=typeof e.checked=="boolean"&&i&&i.type==="paragraph",o="["+(e.checked?"x":" ")+"] ",l=n.createTracker(r);s&&l.move(o);let c=w8.listItem(e,t,n,{...r,...l.current()});return s&&(c=c.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,u)),c;function u(p){return p+o}}function xme(){return[Jhe(),_pe(),Cpe(),ume(),vme()]}function Sme(e){return{extensions:[epe(),xpe(e),kpe(),gme(e),bme()]}}const wme={tokenize:Ame,partial:!0},C8={tokenize:Nme,partial:!0},k8={tokenize:Mme,partial:!0},E8={tokenize:Lme,partial:!0},Cme={tokenize:Ime,partial:!0},R8={name:"wwwAutolink",tokenize:Rme,previous:A8},T8={name:"protocolAutolink",tokenize:Tme,previous:N8},wa={name:"emailAutolink",tokenize:Eme,previous:M8},jo={};function kme(){return{text:jo}}let lc=48;for(;lc<123;)jo[lc]=wa,lc++,lc===58?lc=65:lc===91&&(lc=97);jo[43]=wa;jo[45]=wa;jo[46]=wa;jo[95]=wa;jo[72]=[wa,T8];jo[104]=[wa,T8];jo[87]=[wa,R8];jo[119]=[wa,R8];function Eme(e,t,n){const r=this;let i,s;return o;function o(h){return!E1(h)||!M8.call(r,r.previous)||wE(r.events)?n(h):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),l(h))}function l(h){return E1(h)?(e.consume(h),l):h===64?(e.consume(h),c):n(h)}function c(h){return h===46?e.check(Cme,p,u)(h):h===45||h===95||ri(h)?(s=!0,e.consume(h),c):p(h)}function u(h){return e.consume(h),i=!0,c}function p(h){return s&&i&&pi(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(h)):n(h)}}function Rme(e,t,n){const r=this;return i;function i(o){return o!==87&&o!==119||!A8.call(r,r.previous)||wE(r.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(wme,e.attempt(C8,e.attempt(k8,s),n),n)(o))}function s(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function Tme(e,t,n){const r=this;let i="",s=!1;return o;function o(h){return(h===72||h===104)&&N8.call(r,r.previous)&&!wE(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(h),e.consume(h),l):n(h)}function l(h){if(pi(h)&&i.length<5)return i+=String.fromCodePoint(h),e.consume(h),l;if(h===58){const g=i.toLowerCase();if(g==="http"||g==="https")return e.consume(h),c}return n(h)}function c(h){return h===47?(e.consume(h),s?u:(s=!0,c)):n(h)}function u(h){return h===null||Rb(h)||Dn(h)||Pc(h)||F0(h)?n(h):e.attempt(C8,e.attempt(k8,p),n)(h)}function p(h){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(h)}}function Ame(e,t,n){let r=0;return i;function i(o){return(o===87||o===119)&&r<3?(r++,e.consume(o),i):o===46&&r===3?(e.consume(o),s):n(o)}function s(o){return o===null?n(o):t(o)}}function Nme(e,t,n){let r,i,s;return o;function o(u){return u===46||u===95?e.check(E8,c,l)(u):u===null||Dn(u)||Pc(u)||u!==45&&F0(u)?c(u):(s=!0,e.consume(u),o)}function l(u){return u===95?r=!0:(i=r,r=void 0),e.consume(u),o}function c(u){return i||r||!s?n(u):t(u)}}function Mme(e,t){let n=0,r=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&r<n?s(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(E8,t,s)(o):o===null||Dn(o)||Pc(o)?t(o):(e.consume(o),i)}function s(o){return o===41&&r++,e.consume(o),i}}function Lme(e,t,n){return r;function r(l){return l===33||l===34||l===39||l===41||l===42||l===44||l===46||l===58||l===59||l===63||l===95||l===126?(e.consume(l),r):l===38?(e.consume(l),s):l===93?(e.consume(l),i):l===60||l===null||Dn(l)||Pc(l)?t(l):n(l)}function i(l){return l===null||l===40||l===91||Dn(l)||Pc(l)?t(l):r(l)}function s(l){return pi(l)?o(l):n(l)}function o(l){return l===59?(e.consume(l),r):pi(l)?(e.consume(l),o):n(l)}}function Ime(e,t,n){return r;function r(s){return e.consume(s),i}function i(s){return ri(s)?n(s):t(s)}}function A8(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||Dn(e)}function N8(e){return!pi(e)}function M8(e){return!(e===47||E1(e))}function E1(e){return e===43||e===45||e===46||e===95||ri(e)}function wE(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const jme={tokenize:Hme,partial:!0};function Dme(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:Bme,continuation:{tokenize:Fme},exit:$me}},text:{91:{name:"gfmFootnoteCall",tokenize:zme},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Pme,resolveTo:Ome}}}}function Pme(e,t,n){const r=this;let i=r.events.length;const s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;i--;){const c=r.events[i][1];if(c.type==="labelImage"){o=c;break}if(c.type==="gfmFootnoteCall"||c.type==="labelLink"||c.type==="label"||c.type==="image"||c.type==="link")break}return l;function l(c){if(!o||!o._balanced)return n(c);const u=Gs(r.sliceSerialize({start:o.end,end:r.now()}));return u.codePointAt(0)!==94||!s.includes(u.slice(1))?n(c):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(c),e.exit("gfmFootnoteCallLabelMarker"),t(c))}}function Ome(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const s={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},l=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",i,t],["exit",i,t],["enter",s,t],["enter",o,t],["exit",o,t],["exit",s,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...l),e}function zme(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s=0,o;return l;function l(h){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(h),e.exit("gfmFootnoteCallLabelMarker"),c}function c(h){return h!==94?n(h):(e.enter("gfmFootnoteCallMarker"),e.consume(h),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",u)}function u(h){if(s>999||h===93&&!o||h===null||h===91||Dn(h))return n(h);if(h===93){e.exit("chunkString");const g=e.exit("gfmFootnoteCallString");return i.includes(Gs(r.sliceSerialize(g)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(h),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(h)}return Dn(h)||(o=!0),s++,e.consume(h),h===92?p:u}function p(h){return h===91||h===92||h===93?(e.consume(h),s++,u):u(h)}}function Bme(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s,o=0,l;return c;function c(_){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(_),e.exit("gfmFootnoteDefinitionLabelMarker"),u}function u(_){return _===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(_),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",p):n(_)}function p(_){if(o>999||_===93&&!l||_===null||_===91||Dn(_))return n(_);if(_===93){e.exit("chunkString");const x=e.exit("gfmFootnoteDefinitionLabelString");return s=Gs(r.sliceSerialize(x)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(_),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),g}return Dn(_)||(l=!0),o++,e.consume(_),_===92?h:p}function h(_){return _===91||_===92||_===93?(e.consume(_),o++,p):p(_)}function g(_){return _===58?(e.enter("definitionMarker"),e.consume(_),e.exit("definitionMarker"),i.includes(s)||i.push(s),un(e,b,"gfmFootnoteDefinitionWhitespace")):n(_)}function b(_){return t(_)}}function Fme(e,t,n){return e.check(qp,t,e.attempt(jme,t,n))}function $me(e){e.exit("gfmFootnoteDefinition")}function Hme(e,t,n){const r=this;return un(e,i,"gfmFootnoteDefinitionIndent",5);function i(s){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?t(s):n(s)}}function Ume(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:s,resolveAll:i};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function i(o,l){let c=-1;for(;++c<o.length;)if(o[c][0]==="enter"&&o[c][1].type==="strikethroughSequenceTemporary"&&o[c][1]._close){let u=c;for(;u--;)if(o[u][0]==="exit"&&o[u][1].type==="strikethroughSequenceTemporary"&&o[u][1]._open&&o[c][1].end.offset-o[c][1].start.offset===o[u][1].end.offset-o[u][1].start.offset){o[c][1].type="strikethroughSequence",o[u][1].type="strikethroughSequence";const p={type:"strikethrough",start:Object.assign({},o[u][1].start),end:Object.assign({},o[c][1].end)},h={type:"strikethroughText",start:Object.assign({},o[u][1].end),end:Object.assign({},o[c][1].start)},g=[["enter",p,l],["enter",o[u][1],l],["exit",o[u][1],l],["enter",h,l]],b=l.parser.constructs.insideSpan.null;b&&Yi(g,g.length,0,$0(b,o.slice(u+1,c),l)),Yi(g,g.length,0,[["exit",h,l],["enter",o[c][1],l],["exit",o[c][1],l],["exit",p,l]]),Yi(o,u-1,c-u+3,g),c=u+g.length-2;break}}for(c=-1;++c<o.length;)o[c][1].type==="strikethroughSequenceTemporary"&&(o[c][1].type="data");return o}function s(o,l,c){const u=this.previous,p=this.events;let h=0;return g;function g(_){return u===126&&p[p.length-1][1].type!=="characterEscape"?c(_):(o.enter("strikethroughSequenceTemporary"),b(_))}function b(_){const x=Md(u);if(_===126)return h>1?c(_):(o.consume(_),h++,b);if(h<2&&!n)return c(_);const S=o.exit("strikethroughSequenceTemporary"),C=Md(_);return S._open=!C||C===2&&!!x,S._close=!x||x===2&&!!C,l(_)}}}class Vme{constructor(){this.map=[]}add(t,n,r){Wme(this,t,n,r)}consume(t){if(this.map.sort(function(s,o){return s[0]-o[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];r.push(t.slice()),t.length=0;let i=r.pop();for(;i;){for(const s of i)t.push(s);i=r.pop()}this.map.length=0}}function Wme(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i<e.map.length;){if(e.map[i][0]===t){e.map[i][1]+=n,e.map[i][2].push(...r);return}i+=1}e.map.push([t,n,r])}}function Gme(e,t){let n=!1;const r=[];for(;t<e.length;){const i=e[t];if(n){if(i[0]==="enter")i[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const s=r.length-1;r[s]=r[s]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function qme(){return{flow:{null:{name:"table",tokenize:Kme,resolveAll:Yme}}}}function Kme(e,t,n){const r=this;let i=0,s=0,o;return l;function l(I){let P=r.events.length-1;for(;P>-1;){const $=r.events[P][1].type;if($==="lineEnding"||$==="linePrefix")P--;else break}const z=P>-1?r.events[P][1].type:null,O=z==="tableHead"||z==="tableRow"?N:c;return O===N&&r.parser.lazy[r.now().line]?n(I):O(I)}function c(I){return e.enter("tableHead"),e.enter("tableRow"),u(I)}function u(I){return I===124||(o=!0,s+=1),p(I)}function p(I){return I===null?n(I):xt(I)?s>1?(s=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(I),e.exit("lineEnding"),b):n(I):nn(I)?un(e,p,"whitespace")(I):(s+=1,o&&(o=!1,i+=1),I===124?(e.enter("tableCellDivider"),e.consume(I),e.exit("tableCellDivider"),o=!0,p):(e.enter("data"),h(I)))}function h(I){return I===null||I===124||Dn(I)?(e.exit("data"),p(I)):(e.consume(I),I===92?g:h)}function g(I){return I===92||I===124?(e.consume(I),h):h(I)}function b(I){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(I):(e.enter("tableDelimiterRow"),o=!1,nn(I)?un(e,_,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(I):_(I))}function _(I){return I===45||I===58?S(I):I===124?(o=!0,e.enter("tableCellDivider"),e.consume(I),e.exit("tableCellDivider"),x):A(I)}function x(I){return nn(I)?un(e,S,"whitespace")(I):S(I)}function S(I){return I===58?(s+=1,o=!0,e.enter("tableDelimiterMarker"),e.consume(I),e.exit("tableDelimiterMarker"),C):I===45?(s+=1,C(I)):I===null||xt(I)?T(I):A(I)}function C(I){return I===45?(e.enter("tableDelimiterFiller"),E(I)):A(I)}function E(I){return I===45?(e.consume(I),E):I===58?(o=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(I),e.exit("tableDelimiterMarker"),k):(e.exit("tableDelimiterFiller"),k(I))}function k(I){return nn(I)?un(e,T,"whitespace")(I):T(I)}function T(I){return I===124?_(I):I===null||xt(I)?!o||i!==s?A(I):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(I)):A(I)}function A(I){return n(I)}function N(I){return e.enter("tableRow"),M(I)}function M(I){return I===124?(e.enter("tableCellDivider"),e.consume(I),e.exit("tableCellDivider"),M):I===null||xt(I)?(e.exit("tableRow"),t(I)):nn(I)?un(e,M,"whitespace")(I):(e.enter("data"),j(I))}function j(I){return I===null||I===124||Dn(I)?(e.exit("data"),M(I)):(e.consume(I),I===92?U:j)}function U(I){return I===92||I===124?(e.consume(I),j):j(I)}}function Yme(e,t){let n=-1,r=!0,i=0,s=[0,0,0,0],o=[0,0,0,0],l=!1,c=0,u,p,h;const g=new Vme;for(;++n<e.length;){const b=e[n],_=b[1];b[0]==="enter"?_.type==="tableHead"?(l=!1,c!==0&&(TI(g,t,c,u,p),p=void 0,c=0),u={type:"table",start:Object.assign({},_.start),end:Object.assign({},_.end)},g.add(n,0,[["enter",u,t]])):_.type==="tableRow"||_.type==="tableDelimiterRow"?(r=!0,h=void 0,s=[0,0,0,0],o=[0,n+1,0,0],l&&(l=!1,p={type:"tableBody",start:Object.assign({},_.start),end:Object.assign({},_.end)},g.add(n,0,[["enter",p,t]])),i=_.type==="tableDelimiterRow"?2:p?3:1):i&&(_.type==="data"||_.type==="tableDelimiterMarker"||_.type==="tableDelimiterFiller")?(r=!1,o[2]===0&&(s[1]!==0&&(o[0]=o[1],h=Kg(g,t,s,i,void 0,h),s=[0,0,0,0]),o[2]=n)):_.type==="tableCellDivider"&&(r?r=!1:(s[1]!==0&&(o[0]=o[1],h=Kg(g,t,s,i,void 0,h)),s=o,o=[s[1],n,0,0])):_.type==="tableHead"?(l=!0,c=n):_.type==="tableRow"||_.type==="tableDelimiterRow"?(c=n,s[1]!==0?(o[0]=o[1],h=Kg(g,t,s,i,n,h)):o[1]!==0&&(h=Kg(g,t,o,i,n,h)),i=0):i&&(_.type==="data"||_.type==="tableDelimiterMarker"||_.type==="tableDelimiterFiller")&&(o[3]=n)}for(c!==0&&TI(g,t,c,u,p),g.consume(t.events),n=-1;++n<t.events.length;){const b=t.events[n];b[0]==="enter"&&b[1].type==="table"&&(b[1]._align=Gme(t.events,n))}return e}function Kg(e,t,n,r,i,s){const o=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",l="tableContent";n[0]!==0&&(s.end=Object.assign({},rd(t.events,n[0])),e.add(n[0],0,[["exit",s,t]]));const c=rd(t.events,n[1]);if(s={type:o,start:Object.assign({},c),end:Object.assign({},c)},e.add(n[1],0,[["enter",s,t]]),n[2]!==0){const u=rd(t.events,n[2]),p=rd(t.events,n[3]),h={type:l,start:Object.assign({},u),end:Object.assign({},p)};if(e.add(n[2],0,[["enter",h,t]]),r!==2){const g=t.events[n[2]],b=t.events[n[3]];if(g[1].end=Object.assign({},b[1].end),g[1].type="chunkText",g[1].contentType="text",n[3]>n[2]+1){const _=n[2]+1,x=n[3]-n[2]-1;e.add(_,x,[])}}e.add(n[3]+1,0,[["exit",h,t]])}return i!==void 0&&(s.end=Object.assign({},rd(t.events,i)),e.add(i,0,[["exit",s,t]]),s=void 0),s}function TI(e,t,n,r,i){const s=[],o=rd(t.events,n);i&&(i.end=Object.assign({},o),s.push(["exit",i,t])),r.end=Object.assign({},o),s.push(["exit",r,t]),e.add(n+1,0,s)}function rd(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const Xme={name:"tasklistCheck",tokenize:Zme};function Qme(){return{text:{91:Xme}}}function Zme(e,t,n){const r=this;return i;function i(c){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(c):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(c),e.exit("taskListCheckMarker"),s)}function s(c){return Dn(c)?(e.enter("taskListCheckValueUnchecked"),e.consume(c),e.exit("taskListCheckValueUnchecked"),o):c===88||c===120?(e.enter("taskListCheckValueChecked"),e.consume(c),e.exit("taskListCheckValueChecked"),o):n(c)}function o(c){return c===93?(e.enter("taskListCheckMarker"),e.consume(c),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),l):n(c)}function l(c){return xt(c)?t(c):nn(c)?e.check({tokenize:Jme},t,n)(c):n(c)}}function Jme(e,t,n){return un(e,r,"whitespace");function r(i){return i===null?n(i):t(i)}}function ege(e){return H6([kme(),Dme(),Ume(e),qme(),Qme()])}const tge={};function Qc(e){const t=this,n=e||tge,r=t.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),s=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(ege(n)),s.push(xme()),o.push(Sme(n))}function nge(e){const t=e.split(`
|
|
2595
2595
|
`),n=/^\s*(\d+)→(.*)$/;return t.map(r=>{const i=r.match(n);return i?{lineNumber:parseInt(i[1],10),content:i[2]}:{lineNumber:null,content:r}})}function rge(e){return e.replace(/<[^>]+>/g,"")}function ige(e,t){const n=e.split(`
|
|
2596
2596
|
`),r=t.split(`
|
|
2597
|
-
`),i=sge(n,r),s=oge(n,r,i);return age(s)}function sge(e,t){const n=e.length,r=t.length,i=Array.from({length:n+1},()=>Array(r+1).fill(0));for(let s=1;s<=n;s++)for(let o=1;o<=r;o++)i[s][o]=e[s-1]===t[o-1]?i[s-1][o-1]+1:Math.max(i[s-1][o],i[s][o-1]);return i}function oge(e,t,n){const r=[];let i=e.length,s=t.length;for(;i>0||s>0;)i>0&&s>0&&e[i-1]===t[s-1]?(r.push({type:"context",text:e[i-1],oldIdx:i,newIdx:s}),i--,s--):s>0&&(i===0||n[i][s-1]>=n[i-1][s])?(r.push({type:"added",text:t[s-1],oldIdx:i,newIdx:s}),s--):(r.push({type:"removed",text:e[i-1],oldIdx:i,newIdx:s}),i--);return r.reverse()}function age(e){return e.map(t=>{const n=t.type==="removed"?"-":t.type==="added"?"+":" ";return{type:t.type,content:`${n}${t.text}`}})}function Sh({content:e,isDiff:t=!1,oldString:n,newString:r}){const i=v.useMemo(()=>t&&n!==void 0&&r!==void 0?ige(n,r):[],[t,n,r]),s=v.useMemo(()=>t?[]:nge(e),[e,t]),o=v.useMemo(()=>s.some(l=>l.lineNumber!==null),[s]);return t&&i.length>0?f.jsx("div",{className:"my-1 rounded-lg border border-border overflow-hidden",children:f.jsx("div",{className:"overflow-auto max-h-64 md:max-h-[50vh]",children:f.jsx("table",{className:"w-full border-collapse text-xs font-mono",children:f.jsx("tbody",{children:i.map((l,c)=>{const u=l.type==="removed"?"bg-destructive/10 dark:bg-destructive/15":l.type==="added"?"bg-success/10 dark:bg-success/15":"",p=l.type==="removed"?"text-destructive":l.type==="added"?"text-success":"text-foreground";return f.jsxs("tr",{className:u,children:[f.jsx("td",{className:`px-2 py-0 select-none w-0 whitespace-nowrap ${l.type==="removed"?"text-destructive/50":l.type==="added"?"text-success/50":"text-muted-foreground/50"}`,children:l.type==="removed"?"-":l.type==="added"?"+":" "}),f.jsx("td",{className:`px-2 py-0 whitespace-pre select-all ${p}`,children:l.content.slice(1)})]},c)})})})})}):f.jsx("div",{className:"my-1 rounded-lg border border-border overflow-hidden",children:f.jsx("div",{className:"overflow-auto max-h-64 md:max-h-[50vh]",children:f.jsx("table",{className:"w-full border-collapse text-xs font-mono",children:f.jsx("tbody",{children:s.map((l,c)=>f.jsxs("tr",{children:[o&&f.jsx("td",{className:"px-2 py-0 select-none w-0 whitespace-nowrap text-muted-foreground/50 text-right",children:l.lineNumber!==null?l.lineNumber:""}),f.jsx("td",{className:"px-2 py-0 whitespace-pre select-all text-foreground",children:rge(l.content)})]},c))})})})})}function W0({attachment:e,onOpenChange:t}){const[n,r]=v.useState({}),i=v.useMemo(()=>e?Gp(e):null,[e]),s=e?n[e.id]:void 0,o=e!=null&&e.contentUrl?cge(e.contentUrl):"";v.useEffect(()=>{if(!e||!i||i.openInNewTab||i.kind==="image"||i.kind==="pdf"||i.kind==="external")return;const u=i.kind;if((s==null?void 0:s.status)==="loading"||(s==null?void 0:s.status)==="ready")return;let p=!1;return r(h=>({...h,[e.id]:{status:"loading"}})),Pce(e.contentUrl,Nce).then(({content:h,truncated:g})=>{if(p)return;if(u==="table"){const _=e.mimeType==="text/tab-separated-values"?" ":",";r(x=>({...x,[e.id]:{status:"ready",kind:"table",truncated:g,table:zce(h,_)}}));return}const b=u==="json"?Oce(h):h;r(_=>({..._,[e.id]:{status:"ready",kind:u,content:b,truncated:g}}))}).catch(h=>{if(p)return;const g=h instanceof Error?h.message:"Unable to load preview.";r(b=>({...b,[e.id]:{status:"error",message:g}}))}),()=>{p=!0}},[e,s==null?void 0:s.status,i]);async function l(){var u;!o||typeof navigator>"u"||!((u=navigator.clipboard)!=null&&u.writeText)||await navigator.clipboard.writeText(o)}function c(){!o||typeof window>"u"||window.open(o,"_blank","noopener,noreferrer")}return f.jsx(Ao,{open:e!==null&&!(i!=null&&i.openInNewTab),onOpenChange:t,children:f.jsx(Ys,{size:"lg",className:"max-w-[min(92vw,960px)] overflow-hidden p-0",children:e&&i&&!i.openInNewTab?f.jsxs(f.Fragment,{children:[f.jsx(KC,{className:"pr-12",children:f.jsx(No,{className:"text-md",children:e.displayName})}),f.jsx(ma,{className:"bg-muted/20 p-4",children:lge(e,i.kind,s)}),f.jsxs(Rl,{className:"items-center justify-between gap-3 px-4 py-3",children:[f.jsxs(Gd,{className:"truncate",children:[e.mimeType," · ",Yp(e.size)]}),f.jsxs("div",{className:"flex items-center gap-2",children:[f.jsxs(BK,{type:"button",onClick:l,children:[f.jsx(FV,{className:"mr-2 h-4 w-4"}),"Copy Link"]}),f.jsxs(Ke,{type:"button",variant:"outline",onClick:c,children:[f.jsx(Jb,{className:"mr-2 h-4 w-4"}),"Open In New Tab"]})]})]})]}):null})})}function lge(e,t,n){if(t==="image")return f.jsx("div",{className:"flex items-center justify-center",children:f.jsx("img",{src:e.contentUrl,alt:e.displayName,className:"max-h-[70vh] w-auto max-w-full rounded-2xl object-contain"})});if(t==="pdf")return f.jsx("iframe",{src:e.contentUrl,title:e.displayName,className:"h-[70vh] w-full rounded-xl border border-border bg-background"});if(!n||n.status==="loading")return f.jsx("div",{className:"flex h-[50vh] items-center justify-center text-sm text-muted-foreground",children:"Loading preview…"});if(n.status==="error")return f.jsx("div",{className:"flex h-[50vh] items-center justify-center text-sm text-destructive",children:n.message});if(n.kind==="markdown"&&n.content!==void 0)return f.jsxs("div",{className:"space-y-3",children:[n.truncated?f.jsx(AS,{message:"Preview truncated to 1024 KB."}):null,f.jsx("div",{className:"prose prose-sm max-w-none overflow-auto rounded-xl border border-border bg-background p-4 prose-invert",children:f.jsx(Xc,{remarkPlugins:[Qc],components:sf(),children:n.content})})]});if(n.kind==="table"&&n.table){const r=n.table.rows.length>0,[i,...s]=n.table.rows,o=[n.truncated?"Preview truncated to 1024 KB.":null,n.table.truncatedRows?`Showing first ${n.table.rows.length} of ${n.table.rowCount} rows.`:null,n.table.truncatedColumns?`Showing first ${v1} of ${n.table.columnCount} columns.`:null].filter(Boolean);return f.jsxs("div",{className:"space-y-3",children:[o.length>0?f.jsx(AS,{message:o.join(" ")}):null,f.jsx("div",{className:"max-h-[70vh] overflow-auto rounded-xl border border-border bg-background",children:f.jsxs("table",{className:"min-w-full border-collapse text-xs",children:[r?f.jsx("thead",{className:"sticky top-0 bg-muted",children:f.jsx("tr",{children:i.map((l,c)=>f.jsx("th",{className:"border-b border-border px-3 py-2 text-left font-medium text-foreground",children:l||" "},`${l}-${c}`))})}):null,f.jsx("tbody",{children:(r?s:n.table.rows).map((l,c)=>f.jsx("tr",{className:"odd:bg-background even:bg-muted/20",children:l.map((u,p)=>f.jsx("td",{className:"max-w-[320px] border-b border-border px-3 py-2 align-top text-foreground",children:f.jsx("div",{className:"whitespace-pre-wrap break-words",children:u||" "})},`${c}-${p}`))},c))})]})})]})}return f.jsxs("div",{className:"space-y-3",children:[n.truncated?f.jsx(AS,{message:"Preview truncated to 1024 KB."}):null,f.jsx(Sh,{content:n.content??""})]})}function AS({message:e}){return f.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-sm text-muted-foreground",children:e})}function cge(e){return typeof window>"u"?e:new URL(e,document.baseURI||window.location.href).toString()}function uge(e){const t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function dge({path:e,linkText:t}){const n=v.useMemo(()=>aE(e),[e]),[r,i]=v.useState({kind:"loading"}),[s,o]=v.useState(!1);v.useEffect(()=>{const N=new AbortController;return fetch(n,{method:"HEAD",signal:N.signal}).then(M=>{var I,P;if(N.signal.aborted)return;if(!M.ok){i({kind:M.status===404?"missing":"error"});return}const j=((P=(I=M.headers.get("Content-Type"))==null?void 0:I.split(";")[0])==null?void 0:P.trim())||"application/octet-stream",U=Number.parseInt(M.headers.get("Content-Length")??"0",10)||0;i({kind:"ready",mimeType:j,size:U})}).catch(()=>{N.signal.aborted||i({kind:"error"})}),()=>N.abort()},[n]);const l=uge(e),c=t||l,u=qce(c,28),p=r.kind==="ready"?r.mimeType:"application/octet-stream",h=r.kind==="ready"?r.size:0,g={id:`local-file-${n}`,kind:"file",displayName:u,absolutePath:e,relativePath:e,contentUrl:n,mimeType:p,size:h};if(r.kind==="missing")return f.jsx("span",{className:"inline-flex align-bottom","data-testid":"local-file-link",children:f.jsx(Sl,{attachment:g,disabledReason:"File no longer available"})});const b=oE(g),_=M6(b,p),x=h>0?Yp(h):null,S=r.kind==="loading",C=r.kind==="error",E=S?f.jsx("span",{className:"text-muted-foreground",children:"Fetching…"}):C?f.jsx("span",{className:"text-muted-foreground",children:"Unable to load"}):f.jsxs(f.Fragment,{children:[_,x?f.jsxs(f.Fragment,{children:[" · ",f.jsx("span",{className:"tabular-nums",children:x})]}):null]}),k=r.kind==="ready"?Gp(g):null,T=k!==null&&!k.openInNewTab,A=[T?"Preview":"Download",c,_,x].filter(Boolean);return T?f.jsxs(f.Fragment,{children:[f.jsx("span",{className:"inline-flex align-bottom","data-testid":"local-file-link",children:f.jsx(Sl,{attachment:g,onClick:()=>o(!0),meta:E,ariaLabel:A.join(", ")})}),f.jsx(W0,{attachment:s?g:null,onOpenChange:N=>o(N)})]}):f.jsx("span",{className:"inline-flex align-bottom","data-testid":"local-file-link",children:f.jsx(Sl,{attachment:g,href:n,download:l,meta:E,ariaLabel:A.join(", ")})})}const fge={readonly:!1,localLinkMode:"open",attachmentMode:"live"},hge=v.createContext(fge);function G0(){return v.useContext(hge)}const Mb=()=>{},L8=v.createContext(Mb);function I8({children:e,onOpenLocalLink:t}){return f.jsx(L8.Provider,{value:t??Mb,children:e})}const R1={Task:Wv,TaskOutput:Wv,Bash:t0,Glob:Nh,Grep:Nh,ExitPlanMode:hN,Read:VP,Edit:aV,Write:cV,Delete:gV,NotebookEdit:Rp,WebFetch:i9,TodoWrite:S9,WebSearch:Nh,KillShell:qW,AskUserQuestion:KP,Skill:$W,EnterPlanMode:hN},j8=iG;function D8(e){return R1[e]?R1[e]:j8}function P8({icon:e,className:t}){return f.jsx(e,{className:t})}function Ca({children:e,className:t}){return f.jsx("div",{className:he("flex gap-3 justify-start items-center",t),children:e})}function O8({children:e,className:t}){return f.jsx("div",{className:he("flex items-center gap-1.5 text-xs",t),children:e})}function Nl({children:e,className:t}){return f.jsx("span",{className:he("font-medium text-foreground/80",t),children:e})}function pge({children:e}){return f.jsx("span",{className:"text-muted-foreground",children:e})}function mge({children:e,className:t}){return f.jsxs(Ca,{className:he("px-0.5 text-xs tracking-wide",t),children:[f.jsx("div",{className:"w-full h-[1px] bg-border"}),f.jsx(Nl,{className:"whitespace-nowrap text-[11px] tracking-widest text-muted-foreground/60 uppercase flex-shrink-0",children:e}),f.jsx("div",{className:"w-full h-[1px] bg-border"})]})}function q0({children:e,expandedContent:t,defaultExpanded:n=!1}){const[r,i]=v.useState(n);return f.jsxs("div",{className:"flex flex-col w-full",children:[f.jsxs("button",{onClick:()=>i(!r),className:`group/expandable-row cursor-pointer grid grid-cols-[auto_1fr] items-center gap-1 text-sm ${r?"":"hover:opacity-60 transition-opacity"}`,children:[f.jsx("div",{className:"grid grid-cols-[auto_1fr] items-center gap-1.5",children:e}),f.jsx(To,{className:`h-4.5 w-4.5 text-muted-icon translate-y-[0.5px] transition-all duration-200 opacity-0 group-hover/expandable-row:opacity-100 ${r?"rotate-90 opacity-100":""}`})]}),r&&t]})}function AI({label:e,children:t,copyText:n}){const[r,i]=v.useState(!1),s=n??Lb(t),o=v.useCallback(async()=>{await navigator.clipboard.writeText(s),i(!0),setTimeout(()=>i(!1),2e3)},[s]);return f.jsxs("div",{children:[f.jsx("span",{className:"font-medium text-muted-foreground",children:e}),f.jsxs("div",{className:"relative group/codeblock",children:[f.jsx("pre",{className:"my-1 text-xs font-mono whitespace-no-wrap break-all bg-muted border border-border rounded-lg p-2 max-h-64 overflow-auto w-full",children:t}),f.jsx(Ke,{variant:"ghost",size:"icon","aria-label":r?"Copied":"Copy code",className:he("absolute top-[4px] right-[4px] z-10 h-11 w-11 md:h-6.5 md:w-6.5 rounded-sm text-muted-foreground opacity-100 md:opacity-0 md:group-hover/codeblock:opacity-100 transition-opacity [@media(hover:none)]:!opacity-100",!r&&"hover:text-foreground",r&&"hover:!bg-transparent hover:!border-transparent"),onClick:o,children:r?f.jsx(gi,{className:"h-3.5 w-3.5 text-success"}):f.jsx(El,{className:"h-4 w-4"})})]})]})}function z8({children:e,icon:t,className:n}){return f.jsxs("span",{className:he("inline-flex items-center gap-1 px-2 py-1 bg-muted border border-border rounded-full",n),children:[t&&f.jsx(t,{className:"h-3 w-3 text-muted-foreground"}),e]})}function K0({children:e,className:t}){return f.jsxs("div",{className:he("grid grid-cols-[auto_1fr] gap-2 min-w-0",t),children:[f.jsx("div",{className:" min-w-5 flex flex-col relative items-center justify-center",children:f.jsx("div",{className:"min-h-full w-[1px] bg-muted-foreground/20"})}),f.jsx("div",{className:"-ml-[1px] min-w-0 overflow-hidden",children:e})]})}function Lb(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(Array.isArray(e))return e.map(Lb).join("");if(e&&typeof e=="object"&&"props"in e){const t=e.props;return Lb(t.children)}return""}function NI(e,t){return v.isValidElement(e)?v.cloneElement(e,{className:he(e.props.className,t)}):e}function gge({children:e,...t}){const[n,r]=v.useState(!1),i=Lb(e),s=async()=>{await navigator.clipboard.writeText(i),r(!0),setTimeout(()=>r(!1),2e3)};return f.jsxs("div",{className:"relative overflow-x-auto max-w-full min-w-0 no-code-highlight group/pre",children:[f.jsx("pre",{className:"min-w-0 rounded-xl py-2.5 px-3.5 [.no-pre-highlight_&]:bg-background",...t,children:e}),f.jsx(Ke,{variant:"ghost",size:"icon","aria-label":n?"Copied":"Copy code",className:he("absolute top-[35px] -translate-y-[50%] -translate-x-[1px] rounded-md right-1.5 h-11 w-11 md:h-8 md:w-8 text-muted-foreground opacity-100 md:opacity-0 md:group-hover/pre:opacity-100 transition-opacity [@media(hover:none)]:!opacity-100",!n&&"hover:text-foreground",n&&"hover:!bg-transparent hover:!border-transparent"),onClick:s,children:n?f.jsx(gi,{className:"h-4 w-4 text-success"}):f.jsx(El,{className:"h-4 w-4"})})]})}const CE={h1:({children:e})=>f.jsx("h1",{className:"text-[20px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h2:({children:e})=>f.jsx("h2",{className:"text-[18px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h3:({children:e})=>f.jsx("h3",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h4:({children:e})=>f.jsx("h4",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h5:({children:e})=>f.jsx("h5",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h6:({children:e})=>f.jsx("h6",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),pre:gge,code:({children:e,className:t,...n})=>t?f.jsx("code",{className:"block text-xs whitespace-pre",...n,children:e}):f.jsx("code",{className:"break-all px-1 bg-border/60 dark:[.no-pre-highlight_&]:bg-background dark:[.text-pretty_&]:bg-neutral [.no-code-highlight_&]:!bg-transparent py-0.5 rounded text-sm whitespace-wrap",...n,children:e}),table:({children:e,...t})=>f.jsx("div",{className:"border border-border rounded-xl overflow-x-auto",children:f.jsx("table",{className:"table-auto min-w-full divide-y divide-border bg-background",...t,children:e})}),tbody:({children:e,...t})=>f.jsx("tbody",{className:"divide-y divide-border",...t,children:e}),th:({children:e,...t})=>f.jsx("th",{className:"text-left text-xs uppercase text-muted-foreground tracking-wider p-2 pl-0 first:pl-3 bg-muted dark:bg-card [&_*]:font-semibold",...t,children:e}),td:({children:e,...t})=>f.jsx("td",{className:"text-left p-2 pl-0 first:pl-3 [&_*]:font-normal ",...t,children:e}),p:({children:e,...t})=>f.jsx("p",{className:"break-words mt-5 mb-3 first:mt-0 last:mb-0",...t,children:e}),blockquote:({children:e,...t})=>(()=>{const n=v.Children.toArray(e),r=n[0];r!==void 0&&(n[0]=NI(r,"mt-0"));const i=n.length-1,s=n[i];return s!==void 0&&(n[i]=NI(s,"mb-0")),f.jsx("blockquote",{className:"my-2 mt-5 mb-3 first:mt-0 last:mb-0 border-l-2 border-border/80 pl-2 text-muted-foreground",...t,children:n})})(),a:({children:e,...t})=>f.jsx("a",{className:"transition-all underline decoration-2 text-logo decoration-logo/50 hover:text-logo/70 dark:text-logo dark:decoration-logo/70 dark:hover:text-logo/60 dark:hover:decoration-logo/40 ",target:"_blank",rel:"noopener noreferrer",...t,children:e}),img:({src:e,...t})=>{const n=typeof e=="string"&&Gce(e)?aE(e):e;return f.jsx("img",{src:n,...t})}};function vge({children:e,href:t,onClick:n,overrideOpenLocalLink:r,...i}){const s=v.useContext(L8),o=r??s,l=G0(),c=Vce(t);if(c&&l.localLinkMode==="text")return f.jsx("span",{className:"transition-all underline decoration-2 text-logo decoration-logo/50",children:e});if(c&&!j6(c.path)){const u=T1(e).trim();return f.jsx(dge,{path:c.path,linkText:u||void 0})}return f.jsx("a",{className:"transition-all underline decoration-2 text-logo decoration-logo/50 hover:text-logo/70 dark:text-logo dark:decoration-logo/70 dark:hover:text-logo/60 dark:hover:decoration-logo/40 ",href:t,target:c?void 0:"_blank",rel:c?void 0:"noopener noreferrer",onClick:u=>{n==null||n(u),!(u.defaultPrevented||!c||o===Mb)&&(u.preventDefault(),o({...c,clientX:u.clientX,clientY:u.clientY,trigger:"click"}))},onContextMenu:u=>{!c||o===Mb||(u.preventDefault(),o({...c,clientX:u.clientX,clientY:u.clientY,trigger:"contextmenu"}))},...i,children:e})}function sf(e){return{...CE,a:t=>f.jsx(vge,{...t,overrideOpenLocalLink:e==null?void 0:e.onOpenLocalLink})}}function T1(e){return e==null||typeof e=="boolean"?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(T1).join(""):v.isValidElement(e)?T1(e.props.children):""}({...CE});function kE({attachment:e,previewUrl:t,onClick:n,onRemove:r,className:i,size:s="transcript",uploadProgress:o,onCancelUpload:l}){const c=e.contentUrl||t,u=s==="composer",p=o!==void 0;return f.jsxs("div",{className:he("group relative flex flex-row items-end",i),children:[f.jsxs("button",{type:"button",onClick:n,className:he("group/image relative overflow-hidden rounded-xl border border-border/80 bg-background shadow-sm",u?"min-w-[80px]":"min-w-[200px]"),children:[c?f.jsx("img",{src:c,alt:e.displayName,className:he("rounded-xl object-contain bg-muted",u?"min-h-[50px] min-w-[80px] max-h-[120px] max-w-[200px]":"min-h-[100px] min-w-[200px] max-h-[300px] max-w-[300px]")}):f.jsx("div",{className:he("flex items-center justify-center rounded-xl bg-muted text-muted-foreground",u?"min-h-[64px] min-w-[80px]":"min-h-[160px] min-w-[200px]"),children:f.jsx(UP,{className:he(u?"size-6":"size-8")})}),f.jsxs("div",{className:he("pointer-events-none absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/75 via-black/30 to-transparent text-left opacity-0 transition-opacity duration-200 group-hover/image:opacity-100",u?"px-2.5 pb-2 pt-6":"px-4 pb-3 pt-10"),children:[f.jsx("div",{className:he("truncate font-medium text-white",u?"text-xs":"text-sm"),children:e.displayName}),f.jsxs("div",{className:"truncate text-xs text-white/80",children:[e.mimeType," · ",Yp(e.size)]})]})]}),p?f.jsx(I6,{progress:o??null,onCancel:l,size:u?"sm":"md",cancelLabel:`Cancel upload of ${e.displayName}`}):null,r&&!p?f.jsx(B8,{displayName:e.displayName,onRemove:r}):null]})}function Sl({attachment:e,onClick:t,onRemove:n,className:r,uploadProgress:i,onCancelUpload:s,href:o,download:l,meta:c,ariaLabel:u,disabledReason:p}){const h=e.kind==="mention"?"text":oE(e),g=_ge(h),b=e.kind==="mention",_=b?bge(e.displayName):e.displayName,x=b?yge(e.displayName):"",S=i!==void 0,C=!!p,E=he("flex w-[200px] items-center gap-2 rounded-xl border border-border bg-background p-1 pr-3 text-left transition-colors",C?"cursor-not-allowed opacity-60":"hover:bg-accent/50"),k=b?f.jsx("div",{className:"max-w-[150px] truncate text-[11px] text-muted-foreground",children:x?`@${x}`:"@mention"}):p?f.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:p}):c!==void 0?f.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:c}):f.jsxs("div",{className:"truncate text-[11px] text-muted-foreground",children:[e.mimeType," · ",Yp(e.size)]}),T=f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"flex min-h-10 min-w-10 items-center justify-center rounded-lg border border-border bg-muted text-muted-foreground",children:f.jsx(P8,{icon:g,className:"size-5"})}),f.jsxs("div",{className:"min-w-0",children:[f.jsx("div",{className:he("max-w-[150px] truncate text-[13px] font-medium",C?"text-muted-foreground line-through":"text-foreground"),children:_}),k]})]});return f.jsxs("div",{className:he("group relative",r),children:[o&&!C?f.jsx("a",{href:o,download:l,rel:"noopener","aria-label":u,className:E,children:T}):f.jsx("button",{type:"button",onClick:C?void 0:t,title:b?e.displayName:void 0,"aria-label":u,"aria-disabled":C||void 0,disabled:C,className:E,children:T}),S?f.jsx(I6,{progress:i??null,onCancel:s,size:"sm",cancelLabel:`Cancel upload of ${e.displayName}`}):null,n&&!S?f.jsx(B8,{displayName:e.displayName,onRemove:n}):null]})}function bge(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function yge(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(0,n):""}function B8({displayName:e,onRemove:t}){return f.jsx("button",{type:"button",className:"absolute right-2 top-2 rounded-full bg-background/90 p-1 text-muted-foreground shadow-sm transition hover:bg-muted hover:text-foreground",onClick:n=>{n.preventDefault(),n.stopPropagation(),t()},"aria-label":`Remove ${e}`,children:f.jsx(eo,{className:"h-3.5 w-3.5"})})}function _ge(e){switch(e){case"image":return UP;case"pdf":return SW;case"markdown":return NW;case"json":return eV;case"table":return dV;case"code":return nV;case"text":return jC;case"archive":return Z9;case"audio":return iV;case"video":return pV;default:return VP}}function Yp(e){return e<1024?`${e} B`:e<1024*1024?`${Math.max(1,Math.round(e/1024))} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}const xge={sm:"text-sm px-2.5 py-1",md:"text-sm px-3 py-1.5"};function wc({value:e,onValueChange:t,options:n,size:r="md",className:i,optionClassName:s}){return f.jsx("div",{className:he("inline-flex items-center rounded-lg border border-border p-[3px] ",i),children:n.map(o=>{const l=o.value===e,c=o.icon,u=c?v.isValidElement(c)?c:(()=>{const h=c;return f.jsx(h,{className:r==="sm"?"h-3.5 w-3.5":"h-4 w-4"})})():null,p=f.jsxs("button",{type:"button",onClick:()=>t(o.value),disabled:o.disabled,"aria-pressed":l,className:he("rounded-[4px] border transition-colors",c?"grid grid-cols-[auto_auto] items-center gap-2":"inline-flex items-center",xge[r],l?"bg-card text-foreground border-border":"border-transparent text-muted-foreground hover:text-foreground",o.disabled&&"opacity-50 pointer-events-none",s),children:[u,f.jsx("span",{children:o.label})]},o.value);return o.tooltip?f.jsxs(Xr,{children:[f.jsx(Qr,{asChild:!0,children:p}),f.jsx(Br,{children:o.tooltip})]},o.value):p})})}const Y0=v.forwardRef(({className:e,...t},n)=>f.jsx("textarea",{"data-gramm":"false","data-gramm_editor":"false","data-enable-grammarly":"false","data-1p-ignore":!0,autoComplete:"off",className:he("flex w-full rounded-lg border border-border bg-background px-2.5 py-2 text-sm placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));Y0.displayName="Textarea";const Yg={};function MI(e){return!e.isCollapsed&&!e.hasPreviewAttachment&&e.patch===void 0&&e.patchError===void 0&&!e.isPatchLoading}function Sge(e,t){return!e||!t.mimeType||typeof t.size!="number"||t.changeType==="deleted"||!t.mimeType.startsWith("image/")&&t.mimeType!=="application/pdf"?null:{id:`diff:${t.path}`,kind:t.mimeType.startsWith("image/")?"image":"file",displayName:t.path.split("/").pop()??t.path,absolutePath:t.path,relativePath:t.path,contentUrl:`/api/projects/${e}/files/${encodeURIComponent(t.path)}/content`,mimeType:t.mimeType,size:t.size}}function F8(e){return e.isUntracked}function wge(e){return F8(e)?e.path.includes("/"):!1}function NS(e){return f.jsxs(Xr,{delayDuration:0,children:[f.jsx(Qr,{asChild:!0,children:f.jsx("button",{type:"button","aria-label":e.label,title:e.label,onClick:e.onClick,className:he("flex h-11 w-11 md:h-7 md:w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",e.active&&"bg-accent text-foreground"),children:e.children})}),f.jsx(Br,{children:e.label})]})}function $8({checked:e,mixed:t=!1,label:n,className:r,onClick:i}){return f.jsx("button",{type:"button","aria-label":n??(e?"Exclude file from commit":"Include file in commit"),"aria-checked":t?"mixed":e,"aria-pressed":t?"mixed":e,onClick:s=>{s.stopPropagation(),i()},className:he("flex size-4.5 shrink-0 items-center justify-center rounded border transition-colors",e||t?"border-foreground bg-foreground text-background":"border-border bg-background text-transparent",r),children:t?f.jsx(nW,{className:"h-3 w-3",strokeWidth:3}):e?f.jsx(gi,{className:"h-3 w-3",strokeWidth:3}):null})}function EE(e){const t=Date.parse(e);if(!Number.isFinite(t))return"";const n=Date.now()-t,r=6e4,i=60*r,s=24*i,o=7*s,l=30*s,c=365*s;return n<r?"just now":n<i?`${Math.round(n/r)}m ago`:n<s?`${Math.round(n/i)}hr ago`:n<o?`${Math.round(n/s)}d ago`:n<l?`${Math.round(n/o)}wk ago`:n<c?`${Math.round(n/l)}mo ago`:`${Math.round(n/c)}yr ago`}function Cge(e){return e?`Last fetched ${EE(e)}`:"No local fetch recorded"}function kge({entry:e,isPendingPush:t=!1}){const n=EE(e.authoredAt),r=!!e.githubUrl;return f.jsxs("button",{type:"button",disabled:!r,onClick:()=>{!e.githubUrl||typeof window>"u"||window.open(e.githubUrl,"_blank","noopener,noreferrer")},className:he("flex w-full items-start gap-3 rounded-lg border border-border bg-background pl-3 pr-2 py-2 text-left transition-colors",r?"hover:bg-accent":"cursor-default opacity-60"),children:[f.jsxs("div",{className:"min-w-0 flex-1",children:[f.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:e.summary}),e.description?f.jsx("div",{className:"mt-1 line-clamp-2 whitespace-pre-wrap text-xs text-muted-foreground",children:e.description}):null,f.jsxs("div",{className:"mt-1 flex min-w-0 items-center gap-1 text-xs text-muted-foreground",children:[e.authorName?f.jsx("span",{className:"truncate",children:e.authorName}):null,e.authorName&&n?f.jsx("span",{"aria-hidden":"true",children:"•"}):null,n?f.jsx("span",{children:n}):null]})]}),e.tags.length>0?f.jsxs("div",{className:"flex shrink-0 flex-wrap justify-end gap-1",children:[e.tags.map(i=>f.jsx("span",{className:"inline-flex items-center rounded-full bg-muted border border-border px-2 py-0.5 text-[11px]",children:i},i)),t?f.jsx("span",{className:"inline-flex items-center rounded-full bg-muted border border-border px-2 py-0.5 text-[11px]",children:f.jsx(Gh,{className:"size-3"})}):null]}):t?f.jsx("div",{className:"flex shrink-0 flex-wrap justify-end gap-1",children:f.jsx("span",{className:"inline-flex items-center rounded-full bg-muted border border-border px-2 py-0.5 text-[11px]",children:f.jsx(Gh,{className:"size-3"})})}):null]})}function LI(e){switch(e.kind){case"local":return 0;case"pull_request":return 1;case"remote":default:return 2}}function Ege(e){const t=new Map;for(const n of e){const r=t.get(n.name);(!r||LI(n)<LI(r))&&t.set(n.name,n)}return t}function Rge(e,t){const n=Ege([...e.local,...e.pullRequests,...e.remote]);t&&n.delete(t);const r=new Set,i=e.defaultBranchName?n.get(e.defaultBranchName):void 0;i&&r.add(i.name);const s=e.recent.map(l=>n.get(l.name)??l).filter(l=>!!l&&!r.has(l.name));for(const l of s)r.add(l.name);const o=[...n.values()].filter(l=>!r.has(l.name)).sort((l,c)=>l.displayName.localeCompare(c.displayName));return{defaultBranch:i,recent:s,other:o}}function Tge({open:e,onOpenChange:t,onGetGitHubPublishInfo:n,onCheckGitHubRepoAvailability:r,onPublish:i}){const[s,o]=v.useState(null),[l,c]=v.useState(!1),[u,p]=v.useState(""),[h,g]=v.useState(""),[b,_]=v.useState("private"),[x,S]=v.useState(""),[C,E]=v.useState(null),[k,T]=v.useState(!1),[A,N]=v.useState(!1);v.useEffect(()=>{if(!e)return;let U=!1;return c(!0),E(null),n().then(I=>{U||(o(I),p(I.owners[0]??I.activeAccountLogin??""),g(I.suggestedRepoName),_("private"),S(""))}).finally(()=>{U||c(!1)}),()=>{U=!0}},[n,e]),v.useEffect(()=>{if(!e||!(s!=null&&s.ghInstalled)||!s.authenticated)return;const U=u.trim(),I=h.trim();if(!U||!I){E(null);return}let P=!1;T(!0);const z=window.setTimeout(()=>{r({owner:U,name:I}).then(O=>{P||E(O)}).finally(()=>{P||T(!1)})},250);return()=>{P=!0,window.clearTimeout(z)}},[s==null?void 0:s.authenticated,s==null?void 0:s.ghInstalled,h,r,e,u]);async function M(){if(!(!u.trim()||!h.trim())){N(!0);try{const U=await i({owner:u.trim(),name:h.trim(),visibility:b,description:x});U!=null&&U.ok&&t(!1)}finally{N(!1)}}}const j=!!(s!=null&&s.ghInstalled&&s.authenticated&&u.trim()&&h.trim()&&(C!=null&&C.available)&&!k&&!A);return f.jsx(Ao,{open:e,onOpenChange:t,children:f.jsxs(Ys,{size:"sm",className:"max-w-[min(92vw,475px)]",children:[f.jsxs(ma,{className:"space-y-2 px-4 pb-4 pt-4",children:[f.jsxs("div",{className:"space-y-1",children:[f.jsx(No,{children:"Push to GitHub"}),f.jsx(Gd,{children:"Create a GitHub repository from this local project using GitHub CLI."})]}),l?f.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[f.jsx(kn,{className:"size-4 animate-spin"}),f.jsx("span",{children:"Checking GitHub CLI…"})]}):s&&!s.ghInstalled?f.jsxs("div",{className:"space-y-2 text-sm text-muted-foreground",children:[f.jsx("p",{children:"GitHub CLI is not installed."}),f.jsx("div",{className:"rounded-lg border border-border px-3 py-2 font-mono text-xs text-foreground",children:"brew install gh"}),f.jsx("p",{children:"Then run:"}),f.jsx("div",{className:"rounded-lg border border-border px-3 py-2 font-mono text-xs text-foreground",children:"gh auth login"})]}):s&&!s.authenticated?f.jsxs("div",{className:"space-y-2 text-sm text-muted-foreground",children:[f.jsx("p",{children:"GitHub CLI is installed but not signed in."}),f.jsx("div",{className:"rounded-lg border border-border px-3 py-2 font-mono text-xs text-foreground",children:"gh auth login"})]}):f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"space-y-2",children:f.jsxs(pl,{value:u,onValueChange:p,children:[f.jsx(aa,{className:"pl-[11px] [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:f.jsx(vc,{placeholder:"Select owner"})}),f.jsx(la,{children:((s==null?void 0:s.owners)??[]).map(U=>f.jsx(Fs,{value:U,children:f.jsxs("span",{className:"flex items-center gap-2",children:[U===(s==null?void 0:s.activeAccountLogin)?f.jsx(n0,{className:"size-4 text-muted-foreground"}):f.jsx(b9,{className:"size-4 text-muted-foreground"}),f.jsx("span",{className:"pl-[1px]",children:U})]})},U))})]})}),f.jsx("div",{className:"space-y-2",children:f.jsxs("div",{className:"relative",children:[f.jsx(ir,{value:h,onChange:U=>g(U.target.value),placeholder:"my-repo",className:"pl-9 pr-10"}),f.jsx(pW,{className:"pointer-events-none absolute inset-y-0 left-3 my-auto size-4 text-muted-foreground"}),k?f.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-3 flex items-center text-muted-foreground",children:f.jsx(kn,{className:"size-4 animate-spin"})}):C?f.jsx("div",{className:"absolute inset-y-0 right-2 flex items-center",children:f.jsxs(Xr,{delayDuration:0,children:[f.jsx(Qr,{asChild:!0,children:f.jsx("button",{type:"button",tabIndex:-1,"aria-label":C.message,className:he("flex size-6 items-center justify-center rounded-md",C.available?"text-success":"text-destructive"),children:C.available?f.jsx(gi,{className:"size-4"}):f.jsx(Gv,{className:"size-4"})})}),f.jsx(Br,{children:C.message})]})}):null]})}),f.jsx("div",{className:"space-y-2",children:f.jsxs("div",{className:"relative",children:[f.jsx(jC,{className:"pointer-events-none absolute left-3 top-3 size-4 text-muted-foreground"}),f.jsx(Y0,{value:x,onChange:U=>S(U.target.value),rows:3,placeholder:"Optional description",className:"pl-9 outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"})]})}),f.jsx("div",{className:"space-y-2",children:f.jsxs(pl,{value:b,onValueChange:U=>_(U),children:[f.jsx(aa,{className:"pl-[11px] [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:f.jsx(vc,{placeholder:"Select visibility"})}),f.jsxs(la,{children:[f.jsx(Fs,{value:"private",children:f.jsxs("span",{className:"flex items-center gap-2",children:[f.jsx(qV,{className:"size-4 text-muted-foreground"}),f.jsx("span",{className:"pl-[1px]",children:"Private"})]})}),f.jsx(Fs,{value:"public",children:f.jsxs("span",{className:"flex items-center gap-2",children:[f.jsx(LV,{className:"size-4 text-muted-foreground"}),f.jsx("span",{className:"pl-[1px]",children:"Public"})]})})]})]})})]})]}),f.jsxs(Rl,{children:[f.jsx(Ke,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),f.jsx(Ke,{size:"sm",disabled:!j,onClick:()=>void M(),children:A?f.jsxs(f.Fragment,{children:[f.jsx(kn,{className:"mr-1.5 size-3.5 animate-spin"}),"Publishing…"]}):"Push to GitHub"})]})]})})}function H8({value:e,onChange:t,placeholder:n,disabled:r,trailingAction:i}){return f.jsxs("div",{className:"relative",children:[f.jsx(Nh,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),f.jsx(ir,{value:e,onChange:s=>t(s.target.value),placeholder:n,className:he("h-9 pl-7 text-sm",i?"pr-14":void 0),disabled:r}),i?f.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2",children:i}):null]})}function Cc({title:e,entries:t,emptyLabel:n,selectedName:r,disabled:i,stickyTitle:s=!1,onSelect:o}){return t.length===0&&!n?null:f.jsxs("div",{className:"space-y-1",children:[f.jsx("div",{className:he("px-1 py-1 text-[11px] font-medium uppercase tracking-[0.08em] text-muted-foreground",s&&"sticky top-0 z-10 bg-background"),children:e}),t.length===0?f.jsx("div",{className:"px-1 py-1 text-xs text-muted-foreground",children:n}):t.map(l=>{const c=r===l.name;return f.jsxs("button",{type:"button",disabled:i,onClick:()=>o(l),className:he("flex w-full items-start gap-2 rounded-lg px-2 py-2 text-left transition-colors disabled:opacity-60",c?"bg-accent text-foreground":"hover:bg-accent"),children:[l.kind==="pull_request"?f.jsx(qP,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):f.jsx(yc,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),f.jsxs("div",{className:"min-w-0 flex-1",children:[f.jsxs("div",{className:"flex w-full items-center gap-3",children:[f.jsx("div",{className:"min-w-0 flex-1 overflow-hidden whitespace-nowrap text-sm text-foreground",children:l.displayName}),l.updatedAt?f.jsx("div",{className:"ml-auto shrink-0 text-right text-[11px] text-muted-foreground",children:EE(l.updatedAt)}):null]}),l.kind==="pull_request"&&l.description||l.headLabel?f.jsx("div",{className:"truncate text-xs text-muted-foreground",children:l.kind==="pull_request"?l.description??l.headLabel??l.name:l.headLabel??void 0}):null]})]},l.id)})]})}function Age({open:e,onOpenChange:t,branchList:n,currentBranchName:r,onPreviewMergeBranch:i,onMergeBranch:s}){const[o,l]=v.useState(""),[c,u]=v.useState(null),[p,h]=v.useState(null),[g,b]=v.useState(null),[_,x]=v.useState(!1),[S,C]=v.useState(!1),E=v.useMemo(()=>n?Rge(n,r):{defaultBranch:void 0,recent:[],other:[]},[n,r]),k=o.trim().toLowerCase(),T=v.useCallback(P=>k?[P.displayName,P.name,P.description,P.prTitle,P.headLabel].some(z=>z==null?void 0:z.toLowerCase().includes(k)):!0,[k]),A=E.defaultBranch&&T(E.defaultBranch)?E.defaultBranch:void 0,N=E.recent.filter(T),M=E.other.filter(T),j=v.useMemo(()=>c?[E.defaultBranch,...E.recent,...E.other].find(P=>P!==void 0&&P.name===c)??null:null,[E.defaultBranch,E.other,E.recent,c]);v.useEffect(()=>{e||(l(""),u(null),h(null),b(null),x(!1),C(!1))},[e]),v.useEffect(()=>{if(!e||!j){h(null),b(null),x(!1);return}let P=!1;return h(null),b(null),x(!0),i(j).then(z=>{P||h(z)}).catch(z=>{P||b(z instanceof Error?z.message:String(z))}).finally(()=>{P||x(!1)}),()=>{P=!0}},[i,e,j]);const U=!j||!p||_||S||p.status!=="mergeable";async function I(){if(!(!j||U)){C(!0);try{const P=await s(j);P!=null&&P.ok&&t(!1)}finally{C(!1)}}}return f.jsx(Ao,{open:e,onOpenChange:t,children:f.jsxs(Ys,{size:"sm",className:"max-w-[min(92vw,475px)]",children:[f.jsxs(ma,{className:"flex min-h-0 flex-col gap-3 px-4 pb-4 pt-4",children:[f.jsxs("div",{className:"space-y-1",children:[f.jsxs(No,{children:["Merge into ",r??"current branch"]}),f.jsx(Gd,{children:"Choose a branch to continue."})]}),f.jsx(H8,{value:o,onChange:l,placeholder:"Search branches"}),f.jsxs("div",{className:"max-h-[375px] space-y-3 overflow-y-auto pr-1",children:[f.jsx(Cc,{title:"Default Branch",entries:A?[A]:[],emptyLabel:"No default branch available.",selectedName:c,onSelect:P=>u(P.name)}),f.jsx(Cc,{title:"Recent Branches",entries:N,emptyLabel:"No recent branches.",selectedName:c,onSelect:P=>u(P.name)}),f.jsx(Cc,{title:"Other Branches",entries:M,emptyLabel:"No other branches match this search.",selectedName:c,onSelect:P=>u(P.name)})]}),f.jsx("div",{className:"px-2",children:j?_?f.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[f.jsx(kn,{className:"size-3.5 animate-spin"}),f.jsx("span",{children:"Checking merge preview…"})]}):g?f.jsx("div",{className:"text-sm text-destructive",children:g}):p?f.jsxs("div",{className:"flex items-start gap-2",children:[p.status==="up_to_date"?f.jsx(gi,{className:"mt-1 size-3.5 shrink-0 text-success"}):p.status==="conflicts"?f.jsx(Gv,{className:"mt-1 size-3.5 shrink-0 text-warning"}):p.status==="mergeable"?f.jsx(GP,{className:"mt-1 size-3.5 shrink-0 text-muted-foreground"}):f.jsx(Gv,{className:"mt-1 size-3.5 shrink-0 text-destructive"}),f.jsxs("div",{className:"min-w-0 space-y-1",children:[f.jsx("div",{className:"text-sm font-medium text-foreground",children:p.message}),p.detail?f.jsx("div",{className:"line-clamp-2 whitespace-pre-wrap text-xs text-muted-foreground",children:p.detail}):null]})]}):f.jsx("div",{className:"text-sm text-muted-foreground",children:"Preview unavailable."}):f.jsx("div",{className:"text-sm text-muted-foreground",children:"Select a branch to preview the merge."})})]}),f.jsx(Rl,{children:f.jsxs("div",{className:"flex min-w-0 w-full items-center justify-end gap-2",children:[f.jsx(Ke,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),f.jsx(Ke,{className:"max-w-full min-w-0",size:"sm",disabled:U,onClick:()=>void I(),children:S?f.jsxs(f.Fragment,{children:[f.jsx(kn,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),"Merging…"]}):f.jsx("span",{className:"block max-w-full truncate",children:"Merge"})})]})})]})})}function Nge({currentBranchName:e,onListBranches:t,onPreviewMergeBranch:n,onMergeBranch:r,onCheckoutBranch:i,onCreateBranch:s}){const[o,l]=v.useState(!1),[c,u]=v.useState(!1),[p,h]=v.useState(!1),[g,b]=v.useState(!1),[_,x]=v.useState(""),[S,C]=v.useState("branches"),[E,k]=v.useState(null),[T,A]=v.useState(null);v.useEffect(()=>{o&&(h(!0),A(null),t().then(W=>k(W)).catch(W=>{A(W instanceof Error?W.message:String(W))}).finally(()=>{h(!1)}))},[t,o]);const N=_.trim().toLowerCase(),M=W=>W.filter(Z=>N?[Z.displayName,Z.name,Z.description,Z.prTitle,Z.headLabel].some(D=>D==null?void 0:D.toLowerCase().includes(N)):!0),j=(E==null?void 0:E.currentBranchName)??e,U=new Set(((E==null?void 0:E.pullRequests)??[]).map(W=>W.headRefName??W.name)),I=M((E==null?void 0:E.recent)??[]).filter(W=>W.name!==j),P=M((E==null?void 0:E.local)??[]).filter(W=>W.name!==j),z=M((E==null?void 0:E.remote)??[]).filter(W=>W.name!==j&&!U.has(W.name)),O=M((E==null?void 0:E.pullRequests)??[]).filter(W=>W.name!==j),$=(E==null?void 0:E.pullRequests.length)??0;async function V(W){b(!0);try{await i(W),l(!1),x(""),C("branches")}finally{b(!1)}}async function F(){b(!0);try{await s(),l(!1),x(""),C("branches")}finally{b(!1)}}function H(){l(!1),u(!0)}return f.jsxs(wk,{open:o,onOpenChange:l,children:[f.jsx(Ck,{asChild:!0,children:f.jsxs("button",{type:"button",className:"flex min-w-0 max-w-full items-center gap-1 rounded-md px-1.5 py-1 text-sm transition-colors hover:bg-accent hover:text-foreground","aria-label":"Open branch switcher",children:[f.jsx(yc,{className:"h-3.5 w-3.5 shrink-0"}),f.jsx("span",{className:"truncate",children:e??"Detached HEAD"}),f.jsx(Hd,{className:"h-3.5 w-3.5 shrink-0"})]})}),f.jsx(S0,{align:"start",className:"w-[320px] p-2",children:f.jsxs("div",{className:"space-y-2",children:[f.jsx(H8,{value:_,onChange:x,placeholder:S==="pull_requests"?"Search pull requests":"Search branches",disabled:p||g,trailingAction:f.jsx(Ke,{variant:"ghost",size:"sm",onClick:()=>void F(),disabled:p||g,className:"h-7 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:"+ New"})}),f.jsx(wc,{value:S,onValueChange:W=>C(W),size:"sm",className:"w-full",optionClassName:"flex-1 justify-center",options:[{value:"branches",label:"Branches"},{value:"pull_requests",label:`Open PRs ${$}`}]}),f.jsx("div",{className:"max-h-[420px] overflow-y-auto pr-1.5 -mr-[8px]",children:p?f.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-sm text-muted-foreground",children:[f.jsx(kn,{className:"h-4 w-4 animate-spin"}),f.jsx("span",{children:"Loading branches…"})]}):T?f.jsx("div",{className:"rounded-lg border border-border px-3 py-2 text-sm text-muted-foreground",children:T}):S==="pull_requests"?f.jsx(Cc,{title:"Open PRs",entries:O,emptyLabel:(E==null?void 0:E.pullRequestsStatus)==="error"?E.pullRequestsError??"Could not load pull requests.":(E==null?void 0:E.pullRequestsStatus)==="unavailable"?"Pull requests unavailable for this repository.":"No open pull requests.",disabled:g,stickyTitle:!0,onSelect:W=>{V(W)}}):f.jsxs("div",{className:"space-y-3",children:[f.jsx(Cc,{title:"Recent",entries:I,emptyLabel:"No recent branches.",disabled:g,stickyTitle:!0,onSelect:W=>{V(W)}}),f.jsx(Cc,{title:"Local",entries:P,emptyLabel:"No local branches.",disabled:g,stickyTitle:!0,onSelect:W=>{V(W)}}),f.jsx(Cc,{title:"Remote",entries:z,emptyLabel:"No remote branches.",disabled:g,stickyTitle:!0,onSelect:W=>{V(W)}})]})}),j?f.jsx(Ke,{variant:"default",size:"sm",disabled:p||g||!!T,onClick:H,className:"h-9 w-full justify-center rounded-lg px-3 text-sm",children:f.jsxs("span",{className:"block max-w-full truncate",children:[f.jsx(RV,{className:"mr-1.5 inline h-3.5 w-3.5 shrink-0"}),"Merge branch into ",j,"..."]})}):null]})}),f.jsx(Age,{open:c,onOpenChange:u,branchList:E,currentBranchName:j,onPreviewMergeBranch:n,onMergeBranch:r})]})}function Mge({file:e,rootRef:t,projectId:n,isCollapsed:r,isChecked:i,editorLabel:s,diffRenderMode:o,wrapLines:l,onToggleCollapsed:c,onToggleChecked:u,fileActions:p,patch:h,patchError:g,isPatchLoading:b,onLoadPatch:_}){const x=F8(e),S=wge(e),[C,E]=v.useState(null),k=v.useRef(null),T=v.useRef(null),{sentinelRef:A,isStuck:N}=wce({rootRef:t,disabled:r}),M=v.useMemo(()=>Sge(n,e),[e,n]),j=M!==null,U=MI({isCollapsed:r,hasPreviewAttachment:j,patch:h,patchError:g,isPatchLoading:b});v.useEffect(()=>{if(!U)return;const O=`${e.path}\0${e.patchDigest}`;T.current!==O&&(T.current=O,_(e.path).catch(()=>{}))},[e.patchDigest,e.path,_,U]);function I(O){if(Gp(O).openInNewTab){typeof window<"u"&&window.open(new URL(O.contentUrl,window.location.origin).toString(),"_blank","noopener,noreferrer");return}E(O.id)}function P(O){var V;O.preventDefault(),O.stopPropagation();const $=O.currentTarget.getBoundingClientRect();(V=k.current)==null||V.dispatchEvent(new MouseEvent("contextmenu",{bubbles:!0,cancelable:!0,clientX:$.left+$.width/2,clientY:$.bottom,view:window}))}function z(){if(!r){c();return}if(j||h!==void 0){c();return}if(b)return;if(!(g!==void 0||MI({isCollapsed:!1,hasPreviewAttachment:j,patch:h,patchError:g,isPatchLoading:b}))){c();return}_(e.path).then(()=>{c()}).catch(()=>{})}return f.jsxs(qc,{children:[f.jsx(Kc,{asChild:!0,children:f.jsxs("div",{ref:k,className:"relative rounded-lg border border-border bg-background",children:[r?null:f.jsx("div",{ref:A,className:"pointer-events-none absolute inset-x-0 top-0 h-px","aria-hidden":"true"}),f.jsxs("div",{role:"button",tabIndex:0,onClick:z,onKeyDown:O=>{O.key!=="Enter"&&O.key!==" "||(O.preventDefault(),z())},className:he("group/header sticky top-0 z-20 flex cursor-pointer items-center justify-between gap-3 bg-background pl-[7px] pr-2.5 py-1.5 text-[13px] text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",!r&&!N&&"rounded-t-[calc(theme(borderRadius.lg)-1px)]",r&&"rounded-[calc(theme(borderRadius.lg)-1px)]",!r&&"border-b border-border/50"),children:[f.jsxs("div",{className:"flex min-w-0 items-center",children:[f.jsx($8,{checked:i,onClick:u}),f.jsx("div",{className:"min-w-0 truncate select-none ml-2 mr-1",children:e.path})]}),f.jsxs("div",{className:"flex shrink-0 items-center gap-2 select-none",children:[f.jsxs("span",{className:"whitespace-nowrap text-xs font-mono",children:[e.additions>0?f.jsxs("span",{className:"text-success",children:["+",e.additions]}):null,e.deletions>0?f.jsxs("span",{className:e.additions>0?"ml-2 text-destructive":"text-destructive",children:["-",e.deletions]}):null]}),f.jsx("button",{type:"button","aria-label":`Open actions for ${e.path}`,onClick:P,className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:f.jsx(qh,{className:"h-3.5 w-3.5 shrink-0"})}),b&&r&&!M?f.jsx(kn,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):r?f.jsx(Hd,{className:"h-3.5 w-3.5 shrink-0"}):f.jsx($P,{className:"h-3.5 w-3.5 shrink-0"})]})]}),r?null:f.jsx("div",{className:"kanna-diff-patch overflow-hidden rounded-b-[calc(theme(borderRadius.lg)-1px)] pb-[1px]",children:M?f.jsx("div",{className:"flex justify-center p-3",children:M.kind==="image"?f.jsx(kE,{attachment:M,onClick:()=>I(M)}):f.jsx(Sl,{attachment:M,onClick:()=>I(M)})}):b?f.jsxs("div",{className:"flex items-center justify-center px-3 py-8 text-sm text-muted-foreground",children:[f.jsx(kn,{className:"mr-2 h-4 w-4 animate-spin"}),"Loading diff..."]}):g?f.jsx("div",{className:"px-3 py-4 text-sm text-destructive",children:g}):h!==void 0?f.jsx(xce,{patch:h,options:{diffStyle:o,disableFileHeader:!0,disableBackground:!1,overflow:l?"wrap":"scroll",lineDiffType:"word",diffIndicators:"classic"}}):f.jsx("div",{className:"px-3 py-4 text-sm text-muted-foreground",children:"Diff unavailable."})}),f.jsx(W0,{attachment:M&&C===M.id?M:null,onOpenChange:O=>!O&&E(null)})]},e.path)}),f.jsxs(jl,{children:[f.jsxs(jn,{onSelect:O=>{O.stopPropagation(),p.onOpenFile(e.path)},children:[f.jsx(IC,{className:"h-3.5 w-3.5"}),f.jsxs("span",{className:"text-xs font-medium",children:["Open in ",s]})]}),f.jsxs(jn,{onSelect:O=>{O.stopPropagation(),p.onOpenInFinder(e.path)},children:[f.jsx(e0,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Open in Finder"})]}),f.jsxs(jn,{onSelect:O=>{O.stopPropagation(),p.onDiscardFile(e.path)},className:"text-destructive hover:bg-destructive/10 focus:bg-destructive/10",children:[f.jsx(Ud,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Discard Changes"})]}),f.jsxs(jn,{disabled:!x,onSelect:O=>{O.stopPropagation(),x&&p.onIgnoreFile(e.path)},children:[f.jsx(aN,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Ignore File"})]}),f.jsxs(jn,{disabled:!S,onSelect:O=>{O.stopPropagation(),S&&p.onIgnoreFolder(e.path)},children:[f.jsx(aN,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Ignore folder..."})]}),f.jsx(C3,{}),f.jsxs(jn,{onSelect:O=>{O.stopPropagation(),p.onCopyFilePath(e.path)},children:[f.jsx(El,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Copy File Path"})]}),f.jsxs(jn,{onSelect:O=>{O.stopPropagation(),p.onCopyRelativePath(e.path)},children:[f.jsx(El,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Copy Relative Path"})]})]})]})}function Lge({projectId:e,diffs:t,editorLabel:n,diffRenderMode:r,wrapLines:i,onOpenFile:s,onOpenInFinder:o,onDiscardFile:l,onIgnoreFile:c,onIgnoreFolder:u,onCopyFilePath:p,onCopyRelativePath:h,onListBranches:g,onPreviewMergeBranch:b,onMergeBranch:_,onCheckoutBranch:x,onCreateBranch:S,onGenerateCommitMessage:C,onInitializeGit:E,onGetGitHubPublishInfo:k,onCheckGitHubRepoAvailability:T,onSetupGitHub:A,onCommit:N,onSyncWithRemote:M,onLoadPatch:j,onDiffRenderModeChange:U,onWrapLinesChange:I}){var Je;const P=v.useMemo(()=>({onOpenFile:s,onOpenInFinder:o,onDiscardFile:l,onIgnoreFile:c,onIgnoreFolder:u,onCopyFilePath:p,onCopyRelativePath:h}),[s,o,l,c,u,p,h]),z=t.files.length>0,[O,$]=v.useState(!1),[V,F]=v.useState(null),[H,W]=v.useState(!1),[Z,D]=v.useState(!1),[G,ee]=v.useState({}),[B,le]=v.useState({}),[oe,J]=v.useState({}),ne=v.useRef(null),se=v.useRef({}),ce=v.useMemo(()=>t.files.map(Se=>Se.path),[t.files]),de=v.useMemo(()=>ce.join("\0"),[ce]),Ne=Ni(Se=>{var nt;return e?((nt=Se.projectUi[e])==null?void 0:nt.viewMode)??(z?"changes":"history"):z?"changes":"history"}),we=Ni(Se=>{var nt;return e?((nt=Se.projectUi[e])==null?void 0:nt.collapsedPaths)??Yg:Yg}),je=Ni(Se=>{var nt;return e?((nt=Se.projectUi[e])==null?void 0:nt.summary)??"":""}),fe=Ni(Se=>{var nt;return e?((nt=Se.projectUi[e])==null?void 0:nt.description)??"":""}),ot=Ni(Se=>Se.reconcileCollapsedPaths),Mt=Ni(Se=>Se.toggleCollapsedPath),Et=Ni(Se=>Se.setViewMode),Xt=Ni(Se=>Se.setCommitDraft),Dt=Ni(Se=>Se.clearCommitDraft),mt=Hg(Se=>e?Se.checkedPathsByProjectId[e]??Yg:Yg),yt=Hg(Se=>Se.reconcileProject),Wt=Hg(Se=>Se.setChecked),Lt=Hg(Se=>Se.setAllChecked),gt=v.useRef(z);v.useEffect(()=>{e&&ot(e,ce)},[ce,de,e,ot]),v.useEffect(()=>{const Se=Object.fromEntries(t.files.map(Ye=>[Ye.path,Ye.patchDigest])),nt=Ye=>se.current[Ye]===Se[Ye];ee(Ye=>Object.fromEntries(Object.entries(Ye).filter(([De])=>ce.includes(De)&&nt(De)))),le(Ye=>Object.fromEntries(Object.entries(Ye).filter(([De])=>ce.includes(De)&&nt(De)))),J(Ye=>Object.fromEntries(Object.entries(Ye).filter(([De])=>ce.includes(De)&&nt(De)))),se.current=Se},[t.files,ce,de]),v.useEffect(()=>{e&&yt(e,ce)},[ce,de,e,yt]),v.useEffect(()=>{if(!e)return;if(gt.current!==z){Et(e,z?"changes":"history"),gt.current=z;return}gt.current=z},[z,e,Et]);const Bt=v.useMemo(()=>t.files.filter(Se=>mt[Se.path]??!0).map(Se=>Se.path),[mt,t.files]),ge=Bt.length,ye=t.files.length>0&&ge===t.files.length,ze=ge>0&&ge<t.files.length,Xe=je.trim(),Me=Xe.length>0,Be=V!==null,et=O||Be,We=((Je=t.branchHistory)==null?void 0:Je.entries)??[],qe=t.behindCount??0,ft=t.aheadCount??0,rt=t.hasUpstream===!0,Qt=t.hasUpstream===!1&&!!t.branchName,lt=t.hasOriginRemote===!0,Jt=t.branchName?t.branchName.split("/").map(Se=>encodeURIComponent(Se)).join("/"):null,dn=Qt?"publish":qe>0?"pull":"fetch",At=t.originRepoSlug&&Jt?`https://github.com/${t.originRepoSlug}/compare/${Jt}?expand=1`:null,Rt=!!(rt&&At&&t.branchName&&t.branchName!==t.defaultBranchName),Ct=t.status==="ready"&&ge>0&&!et,Ue=t.status==="ready"&&ge>0&&Me&&!et,vt=lt?"commit_and_push":"commit_only",ht=t.branchName??"current branch";async function Ot(Se){if(Ue){F(Se);try{const nt=await N({paths:Bt,summary:Xe,description:fe.trim(),mode:Se});(nt!=null&&nt.ok||nt!=null&&nt.localCommitCreated)&&e&&Dt(e)}finally{F(null)}}}async function Ft(){if(Ct){$(!0);try{const Se=await C({paths:Bt});e&&Xt(e,{summary:Se.subject,description:Se.body})}finally{$(!1)}}}function xe(Se){if(!(!(Se.metaKey||Se.ctrlKey)||Se.key!=="Enter")){if(Se.preventDefault(),Me){Ot(vt);return}Ft()}}async function Ge(Se=dn){if(!(t.status!=="ready"||H)){W(!0);try{await M(Se)}finally{W(!1)}}}const it=v.useCallback(async Se=>{var nt;if(G[Se]!==void 0||oe[Se])return G[Se]??"";J(Ye=>({...Ye,[Se]:!0})),le(Ye=>{if(!(Se in Ye))return Ye;const{[Se]:De,...It}=Ye;return It});try{const Ye=await j(Se);ee(It=>({...It,[Se]:Ye}));const De=(nt=t.files.find(It=>It.path===Se))==null?void 0:nt.patchDigest;return De&&(se.current={...se.current,[Se]:De}),Ye}catch(Ye){const De=Ye instanceof Error?Ye.message:String(Ye);throw le(It=>({...It,[Se]:De})),Ye}finally{J(Ye=>{const{[Se]:De,...It}=Ye;return It})}},[t.files,oe,j,G]);return f.jsx("div",{className:"h-full min-h-0 border-l border-border bg-background md:min-w-[370px]",children:f.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[f.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pl-2.5 pr-2 py-2",children:[f.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:f.jsx(Nge,{currentBranchName:t.branchName,onListBranches:g,onPreviewMergeBranch:b,onMergeBranch:_,onCheckoutBranch:x,onCreateBranch:S})}),t.status==="ready"?lt?dn==="publish"?f.jsxs(Ke,{variant:"ghost",size:"sm",onClick:()=>void Ge(),disabled:H,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[H?f.jsx(kn,{className:"h-3.5 w-3.5 animate-spin"}):f.jsx(vv,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Publish Branch"})]}):f.jsxs("div",{className:"flex items-center gap-1",children:[dn==="fetch"?f.jsxs(Xr,{delayDuration:0,children:[f.jsx(Qr,{asChild:!0,children:f.jsxs(Ke,{variant:"ghost",size:"sm",onClick:()=>void Ge(),disabled:H,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[H?f.jsx(kn,{className:"h-3.5 w-3.5 animate-spin"}):f.jsx(CW,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Fetch"})]})}),f.jsx(Br,{children:Cge(t.lastFetchedAt)})]}):f.jsxs(Ke,{variant:"ghost",size:"sm",onClick:()=>void Ge(),disabled:H,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[H?f.jsx(kn,{className:"h-3.5 w-3.5 animate-spin"}):f.jsx(HP,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Pull"}),f.jsx("span",{className:"inline-flex min-w-4 items-center justify-center rounded-full bg-muted px-1 text-[10px] text-muted-foreground",children:qe})]}),rt&&ft>0?f.jsxs(Ke,{variant:"default",size:"sm",onClick:()=>void Ge("push"),disabled:H,className:"h-7 gap-1.5 px-2 text-xs",children:[H?f.jsx(kn,{className:"h-3.5 w-3.5 animate-spin"}):f.jsx(vv,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Push"}),f.jsx("span",{className:"inline-flex min-w-4 items-center justify-center rounded-full bg-primary-foreground/15 px-1 text-[10px] text-primary-foreground",children:ft})]}):null,Rt&&At?f.jsxs(Ke,{variant:"ghost",size:"sm",onClick:()=>{typeof window>"u"||window.open(At,"_blank","noopener,noreferrer")},className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[f.jsx(qP,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"PR"})]}):null]}):f.jsxs(Ke,{variant:"default",size:"sm",onClick:()=>D(!0),className:"h-7 gap-1.5 px-3 text-xs",children:[f.jsx(NV,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Push to GitHub"})]}):null]}),f.jsxs("div",{className:"relative min-h-0 flex-1",children:[f.jsx("div",{className:"sticky top-0 z-30 pl-[14px] pr-[12px] pt-[6px] bg-gradient-to-b from-background to-transparent",children:f.jsx("div",{className:"relative h-[40px] flex min-w-0 items-center justify-center gap-[13px]",children:f.jsxs("div",{className:"flex min-w-0 flex-1 items-center justify-between gap-[13px] relative",children:[Ne==="changes"?f.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-muted-foreground/70",children:[f.jsx($8,{checked:ye,mixed:ze,label:ze?"Select all files for commit":ye?"Unselect all files from commit":"Select all files for commit",onClick:()=>{!e||t.files.length===0||Lt(e,ce,ze?!0:!ye)}}),f.jsxs("span",{children:[ge," files"]})]}):f.jsx("div",{}),f.jsx("div",{className:"pointer-events-none absolute left-1/2 -translate-x-1/2 top-1/2 -translate-y-1/2",children:f.jsx("div",{className:"pointer-events-auto",children:f.jsx(wc,{value:Ne,onValueChange:Se=>{e&&Et(e,Se)},size:"sm",optionClassName:"flex-1 justify-center",options:[{value:"changes",label:"Changes"},{value:"history",label:"History"}]})})}),Ne==="changes"?f.jsxs("div",{className:"flex items-center gap-1",children:[f.jsx(NS,{label:"Unified diff",active:r==="unified",onClick:()=>U("unified"),children:f.jsx(TW,{className:"h-4 w-4"})}),f.jsx(NS,{label:"Side-by-side diff",active:r==="split",onClick:()=>U("split"),children:f.jsx(z9,{className:"h-4 w-4"})}),f.jsx(NS,{label:i?"Disable word wrap":"Enable word wrap",active:i,onClick:()=>I(!i),children:f.jsx(nG,{className:"h-4 w-4"})})]}):f.jsx("div",{})]})})}),f.jsx("div",{ref:ne,className:"h-full overflow-y-auto [scrollbar-gutter:stable]",children:t.status==="no_repo"?f.jsx("div",{className:"flex h-full items-center justify-center px-6 py-3 text-center",children:f.jsxs("div",{className:"flex max-w-[280px] flex-col items-center gap-3",children:[f.jsx("p",{className:"text-sm text-muted-foreground",children:"Initialize git here to start tracking branches, diffs, and history."}),f.jsx(Ke,{size:"sm",onClick:()=>void E(),children:"Init Git"})]})}):Ne==="history"?We.length===0?f.jsx("div",{className:"flex h-full items-center justify-center px-6 py-3 text-center",children:f.jsxs("p",{className:"text-sm text-muted-foreground",children:["No recent commits on ",t.branchName??"this branch","."]})}):f.jsx("div",{className:"space-y-1.5 p-1.5",children:We.map((Se,nt)=>f.jsx(kge,{entry:Se,isPendingPush:nt<ft},Se.sha))}):t.files.length===0?f.jsx("div",{className:"flex h-full items-center justify-center px-6 py-3 text-center",children:f.jsx("p",{className:"text-sm text-muted-foreground",children:"No file changes."})}):f.jsxs("div",{className:"space-y-1.5 p-1.5 pb-10",children:[t.files.map(Se=>{const nt=we[Se.path]??!0,Ye=mt[Se.path]??!0;return f.jsx(Mge,{file:Se,rootRef:ne,projectId:e,isCollapsed:nt,isChecked:Ye,editorLabel:n,diffRenderMode:r,wrapLines:i,onToggleCollapsed:()=>{e&&Mt(e,Se.path)},onToggleChecked:()=>{e&&Wt(e,Se.path,!Ye)},fileActions:P,patch:G[Se.path],patchError:B[Se.path],isPatchLoading:!!oe[Se.path],onLoadPatch:it},Se.path)}),Ne==="changes"?f.jsxs("div",{className:"pointer-events-none sticky inset-x-0 bottom-11 py-1 pb-6 z-30 overflow-y-auto",children:[f.jsx("div",{className:"absolute inset-x-0 bottom-0 top-0 bg-gradient-to-t from-background to-transparent"}),f.jsx("div",{className:"pointer-events-auto relative",children:f.jsxs("div",{className:"space-y-0 rounded-xl mx-auto max-w-[700px]",children:[f.jsx(ir,{value:je,onChange:Se=>{e&&Xt(e,{summary:Se.target.value,description:fe})},onKeyDown:xe,placeholder:"Commit message (override)",className:"rounded-t-xl rounded-b-none px-3",disabled:et||t.status!=="ready"}),f.jsx(Y0,{value:fe,onChange:Se=>{e&&Xt(e,{summary:je,description:Se.target.value})},onKeyDown:xe,placeholder:"Description",rows:5,className:"-mt-px rounded-t-none rounded-b-xl px-3 outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background mb-2",disabled:et||t.status!=="ready"}),f.jsx("div",{className:"w-full flex flex-row",children:f.jsxs(qc,{children:[f.jsx(Kc,{asChild:!0,children:f.jsx(Ke,{type:"button",className:"-mt-px w-full rounded-xl",disabled:Me?!Ue:!Ct,onClick:()=>{if(Me){Ot(vt);return}Ft()},children:f.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[Me?Be?f.jsx(kn,{strokeWidth:2.5,className:"size-3 shrink-0 animate-spin"}):vt==="commit_and_push"?t.hasUpstream?f.jsx(vv,{strokeWidth:2.5,className:"size-3 shrink-0"}):f.jsx(GP,{strokeWidth:2.5,className:"size-3 shrink-0"}):f.jsx(gi,{strokeWidth:2.5,className:"size-3 shrink-0"}):O?f.jsx(kn,{strokeWidth:2.5,className:"size-3 shrink-0 animate-spin"}):f.jsx(fW,{strokeWidth:2.5,className:"size-3 shrink-0"}),f.jsx("span",{className:"min-w-0 truncate text-left",children:Me?Be?V==="commit_only"?"Committing...":"Committing & Pushing...":vt==="commit_only"?f.jsxs(f.Fragment,{children:["Commit to ",f.jsx(yc,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),ht]}):t.hasUpstream?f.jsxs(f.Fragment,{children:["Commit & push to ",f.jsx(yc,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),ht]}):f.jsxs(f.Fragment,{children:["Commit & publish ",f.jsx(yc,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),ht]}):O?"Generating...":f.jsxs(f.Fragment,{children:["Generate message for ",f.jsx(yc,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),ht]})})]})})}),t.hasUpstream?f.jsx(jl,{children:f.jsx(jn,{disabled:!Me||!Ue,onSelect:Se=>{Se.stopPropagation(),Ot("commit_only")},children:"Commit Only"})}):null]})})]})})]}):null]})})]}),f.jsx(Tge,{open:Z,onOpenChange:D,onGetGitHubPublishInfo:k,onCheckGitHubRepoAvailability:T,onPublish:A})]})})}const Ige=v.memo(Lge);function jge(e,t){const n=getComputedStyle(e),r=parseFloat(n.fontSize);return t*r}function Dge(e,t){const n=getComputedStyle(e.ownerDocument.body),r=parseFloat(n.fontSize);return t*r}function Pge(e){return e/100*window.innerHeight}function Oge(e){return e/100*window.innerWidth}function zge(e){switch(typeof e){case"number":return[e,"px"];case"string":{const t=parseFloat(e);return e.endsWith("%")?[t,"%"]:e.endsWith("px")?[t,"px"]:e.endsWith("rem")?[t,"rem"]:e.endsWith("em")?[t,"em"]:e.endsWith("vh")?[t,"vh"]:e.endsWith("vw")?[t,"vw"]:[t,"%"]}}}function wh({groupSize:e,panelElement:t,styleProp:n}){let r;const[i,s]=zge(n);switch(s){case"%":{r=i/100*e;break}case"px":{r=i;break}case"rem":{r=Dge(t,i);break}case"em":{r=jge(t,i);break}case"vh":{r=Pge(i);break}case"vw":{r=Oge(i);break}}return r}function Mi(e){return parseFloat(e.toFixed(3))}function Ld({group:e}){const{orientation:t,panels:n}=e;return n.reduce((r,i)=>(r+=t==="horizontal"?i.element.offsetWidth:i.element.offsetHeight,r),0)}function A1(e){const{panels:t}=e,n=Ld({group:e});return n===0?t.map(r=>({groupResizeBehavior:r.panelConstraints.groupResizeBehavior,collapsedSize:0,collapsible:r.panelConstraints.collapsible===!0,defaultSize:void 0,disabled:r.panelConstraints.disabled,minSize:0,maxSize:100,panelId:r.id})):t.map(r=>{const{element:i,panelConstraints:s}=r;let o=0;if(s.collapsedSize!==void 0){const p=wh({groupSize:n,panelElement:i,styleProp:s.collapsedSize});o=Mi(p/n*100)}let l;if(s.defaultSize!==void 0){const p=wh({groupSize:n,panelElement:i,styleProp:s.defaultSize});l=Mi(p/n*100)}let c=0;if(s.minSize!==void 0){const p=wh({groupSize:n,panelElement:i,styleProp:s.minSize});c=Mi(p/n*100)}let u=100;if(s.maxSize!==void 0){const p=wh({groupSize:n,panelElement:i,styleProp:s.maxSize});u=Mi(p/n*100)}return{groupResizeBehavior:s.groupResizeBehavior,collapsedSize:o,collapsible:s.collapsible===!0,defaultSize:l,disabled:s.disabled,minSize:c,maxSize:u,panelId:r.id}})}function Mn(e,t="Assertion error"){if(!e)throw Error(t)}function N1(e,t){return Array.from(t).sort(e==="horizontal"?Bge:Fge)}function Bge(e,t){const n=e.element.offsetLeft-t.element.offsetLeft;return n!==0?n:e.element.offsetWidth-t.element.offsetWidth}function Fge(e,t){const n=e.element.offsetTop-t.element.offsetTop;return n!==0?n:e.element.offsetHeight-t.element.offsetHeight}function U8(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function V8(e,t){return{x:e.x>=t.left&&e.x<=t.right?0:Math.min(Math.abs(e.x-t.left),Math.abs(e.x-t.right)),y:e.y>=t.top&&e.y<=t.bottom?0:Math.min(Math.abs(e.y-t.top),Math.abs(e.y-t.bottom))}}function $ge({orientation:e,rects:t,targetRect:n}){const r={x:n.x+n.width/2,y:n.y+n.height/2};let i,s=Number.MAX_VALUE;for(const o of t){const{x:l,y:c}=V8(r,o),u=e==="horizontal"?l:c;u<s&&(s=u,i=o)}return Mn(i,"No rect found"),i}let Xg;function Hge(){return Xg===void 0&&(typeof matchMedia=="function"?Xg=!!matchMedia("(pointer:coarse)").matches:Xg=!1),Xg}function W8(e){const{element:t,orientation:n,panels:r,separators:i}=e,s=N1(n,Array.from(t.children).filter(U8).map(_=>({element:_}))).map(({element:_})=>_),o=[];let l=!1,c=!1,u=-1,p=-1,h=0,g,b=[];{let _=-1;for(const x of s)x.hasAttribute("data-panel")&&(_++,x.ariaDisabled===null&&(h++,u===-1&&(u=_),p=_))}if(h>1){let _=-1;for(const x of s)if(x.hasAttribute("data-panel")){_++;const S=r.find(C=>C.element===x);if(S){if(g){const C=g.element.getBoundingClientRect(),E=x.getBoundingClientRect();let k;if(c){const T=n==="horizontal"?new DOMRect(C.right,C.top,0,C.height):new DOMRect(C.left,C.bottom,C.width,0),A=n==="horizontal"?new DOMRect(E.left,E.top,0,E.height):new DOMRect(E.left,E.top,E.width,0);switch(b.length){case 0:{k=[T,A];break}case 1:{const N=b[0],M=$ge({orientation:n,rects:[C,E],targetRect:N.element.getBoundingClientRect()});k=[N,M===C?A:T];break}default:{k=b;break}}}else b.length?k=b:k=[n==="horizontal"?new DOMRect(C.right,E.top,E.left-C.right,E.height):new DOMRect(E.left,C.bottom,E.width,E.top-C.bottom)];for(const T of k){let A="width"in T?T:T.element.getBoundingClientRect();const N=Hge()?e.resizeTargetMinimumSize.coarse:e.resizeTargetMinimumSize.fine;if(A.width<N){const j=N-A.width;A=new DOMRect(A.x-j/2,A.y,A.width+j,A.height)}if(A.height<N){const j=N-A.height;A=new DOMRect(A.x,A.y-j/2,A.width,A.height+j)}const M=_<=u||_>p;!l&&!M&&o.push({group:e,groupSize:Ld({group:e}),panels:[g,S],separator:"width"in T?void 0:T,rect:A}),l=!1}}c=!1,g=S,b=[]}}else if(x.hasAttribute("data-separator")){x.ariaDisabled!==null&&(l=!0);const S=i.find(C=>C.element===x);S?b.push(S):(g=void 0,b=[])}else c=!0}return o}var vl,pP;let G8=(pP=class{constructor(){Ja(this,vl,{})}addListener(t,n){const r=br(this,vl)[t];return r===void 0?br(this,vl)[t]=[n]:r.includes(n)||r.push(n),()=>{this.removeListener(t,n)}}emit(t,n){const r=br(this,vl)[t];if(r!==void 0)if(r.length===1)r[0].call(null,n);else{let i=!1,s=null;const o=Array.from(r);for(let l=0;l<o.length;l++){const c=o[l];try{c.call(null,n)}catch(u){s===null&&(i=!0,s=u)}}if(i)throw s}}removeAllListeners(){us(this,vl,{})}removeListener(t,n){const r=br(this,vl)[t];if(r!==void 0){const i=r.indexOf(n);i>=0&&r.splice(i,1)}}},vl=new WeakMap,pP),wo=new Map;const q8=new G8;function Uge(e){wo=new Map(wo),wo.delete(e)}function II(e,t){for(const[n]of wo)if(n.id===e)return n}function wl(e,t){for(const[n,r]of wo)if(n.id===e)return r;if(t)throw Error(`Could not find data for Group with id ${e}`)}function Zc(){return wo}function RE(e,t){return q8.addListener("groupChange",n=>{n.group.id===e&&t(n)})}function ya(e,t){const n=wo.get(e);wo=new Map(wo),wo.set(e,t),q8.emit("groupChange",{group:e,prev:n,next:t})}function Vge(e,t,n){let r,i={x:1/0,y:1/0};for(const s of t){const o=V8(n,s.rect);switch(e){case"horizontal":{o.x<=i.x&&(r=s,i=o);break}case"vertical":{o.y<=i.y&&(r=s,i=o);break}}}return r?{distance:i,hitRegion:r}:void 0}function Wge(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function Gge(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:PI(e),b:PI(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();Mn(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:DI(jI(n.a)),b:DI(jI(n.b))};if(i.a===i.b){const s=r.childNodes,o={a:n.a.at(-1),b:n.b.at(-1)};let l=s.length;for(;l--;){const c=s[l];if(c===o.a)return 1;if(c===o.b)return-1}}return Math.sign(i.a-i.b)}const qge=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function Kge(e){const t=getComputedStyle(K8(e)??e).display;return t==="flex"||t==="inline-flex"}function Yge(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||Kge(e))||+t.opacity<1||"transform"in t&&t.transform!=="none"||"webkitTransform"in t&&t.webkitTransform!=="none"||"mixBlendMode"in t&&t.mixBlendMode!=="normal"||"filter"in t&&t.filter!=="none"||"webkitFilter"in t&&t.webkitFilter!=="none"||"isolation"in t&&t.isolation==="isolate"||qge.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function jI(e){let t=e.length;for(;t--;){const n=e[t];if(Mn(n,"Missing node"),Yge(n))return n}return null}function DI(e){return e&&Number(getComputedStyle(e).zIndex)||0}function PI(e){const t=[];for(;e;)t.push(e),e=K8(e);return t}function K8(e){const{parentNode:t}=e;return Wge(t)?t.host:t}function Xge(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function Qge({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!U8(n)||n.contains(e)||e.contains(n))return!0;if(Gge(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(Xge(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function TE(e,t){const n=[];return t.forEach((r,i)=>{if(i.disabled)return;const s=W8(i),o=Vge(i.orientation,s,{x:e.clientX,y:e.clientY});o&&o.distance.x<=0&&o.distance.y<=0&&Qge({groupElement:i.element,hitRegion:o.hitRegion.rect,pointerEventTarget:e.target})&&n.push(o.hitRegion)}),n}function Zge(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function di(e,t,n=0){return Math.abs(Mi(e)-Mi(t))<=n}function bo(e,t){return di(e,t)?0:e>t?1:-1}function od({overrideDisabledPanels:e,panelConstraints:t,prevSize:n,size:r}){const{collapsedSize:i=0,collapsible:s,disabled:o,maxSize:l=100,minSize:c=0}=t;if(o&&!e)return n;if(bo(r,c)<0)if(s){const u=(i+c)/2;bo(r,u)<0?r=i:r=c}else r=c;return r=Math.min(l,r),r=Mi(r),r}function pp({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(di(e,0))return t;const o=s==="imperative-api",l=Object.values(t),c=Object.values(i),u=[...l],[p,h]=r;Mn(p!=null,"Invalid first pivot index"),Mn(h!=null,"Invalid second pivot index");let g=0;switch(s){case"keyboard":{{const x=e<0?h:p,S=n[x];Mn(S,`Panel constraints not found for index ${x}`);const{collapsedSize:C=0,collapsible:E,minSize:k=0}=S;if(E){const T=l[x];if(Mn(T!=null,`Previous layout not found for panel index ${x}`),di(T,C)){const A=k-T;bo(A,Math.abs(e))>0&&(e=e<0?0-A:A)}}}{const x=e<0?p:h,S=n[x];Mn(S,`No panel constraints found for index ${x}`);const{collapsedSize:C=0,collapsible:E,minSize:k=0}=S;if(E){const T=l[x];if(Mn(T!=null,`Previous layout not found for panel index ${x}`),di(T,k)){const A=T-C;bo(A,Math.abs(e))>0&&(e=e<0?0-A:A)}}}break}default:{const x=e<0?h:p,S=n[x];Mn(S,`Panel constraints not found for index ${x}`);const C=l[x],{collapsible:E,collapsedSize:k,minSize:T}=S;if(E&&bo(C,T)<0)if(e>0){const A=T-k,N=A/2,M=C+e;bo(M,T)<0&&(e=bo(e,N)<=0?0:A)}else{const A=T-k,N=100-A/2,M=C-e;bo(M,T)<0&&(e=bo(100+e,N)>0?0:-A)}break}}{const x=e<0?1:-1;let S=e<0?h:p,C=0;for(;;){const k=l[S];Mn(k!=null,`Previous layout not found for panel index ${S}`);const T=od({overrideDisabledPanels:o,panelConstraints:n[S],prevSize:k,size:100})-k;if(C+=T,S+=x,S<0||S>=n.length)break}const E=Math.min(Math.abs(e),Math.abs(C));e=e<0?0-E:E}{let x=e<0?p:h;for(;x>=0&&x<n.length;){const S=Math.abs(e)-Math.abs(g),C=l[x];Mn(C!=null,`Previous layout not found for panel index ${x}`);const E=C-S,k=od({overrideDisabledPanels:o,panelConstraints:n[x],prevSize:C,size:E});if(!di(C,k)&&(g+=C-k,u[x]=k,g.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?x--:x++}}if(Zge(c,u))return i;{const x=e<0?h:p,S=l[x];Mn(S!=null,`Previous layout not found for panel index ${x}`);const C=S+g,E=od({overrideDisabledPanels:o,panelConstraints:n[x],prevSize:S,size:C});if(u[x]=E,!di(E,C)){let k=C-E,T=e<0?h:p;for(;T>=0&&T<n.length;){const A=u[T];Mn(A!=null,`Previous layout not found for panel index ${T}`);const N=A+k,M=od({overrideDisabledPanels:o,panelConstraints:n[T],prevSize:A,size:N});if(di(A,M)||(k-=M-A,u[T]=M),di(k,0))break;e>0?T--:T++}}}const b=Object.values(u).reduce((x,S)=>S+x,0);if(!di(b,100,.1))return i;const _=Object.keys(i);return u.reduce((x,S,C)=>(x[_[C]]=S,x),{})}function Oc(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(t[n]===void 0||bo(e[n],t[n])!==0)return!1;return!0}function zc({layout:e,panelConstraints:t}){const n=Object.values(e),r=[...n],i=r.reduce((l,c)=>l+c,0);if(r.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${r.map(l=>`${l}%`).join(", ")}`);if(!di(i,100)&&r.length>0)for(let l=0;l<t.length;l++){const c=r[l];Mn(c!=null,`No layout data found for index ${l}`);const u=100/i*c;r[l]=u}let s=0;for(let l=0;l<t.length;l++){const c=n[l];Mn(c!=null,`No layout data found for index ${l}`);const u=r[l];Mn(u!=null,`No layout data found for index ${l}`);const p=od({overrideDisabledPanels:!0,panelConstraints:t[l],prevSize:c,size:u});u!=p&&(s+=u-p,r[l]=p)}if(!di(s,0))for(let l=0;l<t.length;l++){const c=r[l];Mn(c!=null,`No layout data found for index ${l}`);const u=c+s,p=od({overrideDisabledPanels:!0,panelConstraints:t[l],prevSize:c,size:u});if(c!==p&&(s-=p-c,r[l]=p,di(s,0)))break}const o=Object.keys(e);return r.reduce((l,c,u)=>(l[o[u]]=c,l),{})}function Y8({groupId:e,panelId:t}){const n=()=>{const l=Zc();for(const[c,{defaultLayoutDeferred:u,derivedPanelConstraints:p,layout:h,groupSize:g,separatorToPanels:b}]of l)if(c.id===e)return{defaultLayoutDeferred:u,derivedPanelConstraints:p,group:c,groupSize:g,layout:h,separatorToPanels:b};throw Error(`Group ${e} not found`)},r=()=>{const l=n().derivedPanelConstraints.find(c=>c.panelId===t);if(l!==void 0)return l;throw Error(`Panel constraints not found for Panel ${t}`)},i=()=>{const l=n().group.panels.find(c=>c.id===t);if(l!==void 0)return l;throw Error(`Layout not found for Panel ${t}`)},s=()=>{const l=n().layout[t];if(l!==void 0)return l;throw Error(`Layout not found for Panel ${t}`)},o=l=>{const c=s();if(l===c)return;const{defaultLayoutDeferred:u,derivedPanelConstraints:p,group:h,groupSize:g,layout:b,separatorToPanels:_}=n(),x=h.panels.findIndex(k=>k.id===t),S=x===h.panels.length-1,C=pp({delta:S?c-l:l-c,initialLayout:b,panelConstraints:p,pivotIndices:S?[x-1,x]:[x,x+1],prevLayout:b,trigger:"imperative-api"}),E=zc({layout:C,panelConstraints:p});Oc(b,E)||ya(h,{defaultLayoutDeferred:u,derivedPanelConstraints:p,groupSize:g,layout:E,separatorToPanels:_})};return{collapse:()=>{const{collapsible:l,collapsedSize:c}=r(),{mutableValues:u}=i(),p=s();l&&p!==c&&(u.expandToSize=p,o(c))},expand:()=>{const{collapsible:l,collapsedSize:c,minSize:u}=r(),{mutableValues:p}=i(),h=s();if(l&&h===c){let g=p.expandToSize??u;g===0&&(g=1),o(g)}},getSize:()=>{const{group:l}=n(),c=s(),{element:u}=i(),p=l.orientation==="horizontal"?u.offsetWidth:u.offsetHeight;return{asPercentage:c,inPixels:p}},isCollapsed:()=>{const{collapsible:l,collapsedSize:c}=r(),u=s();return l&&di(c,u)},resize:l=>{const{group:c}=n(),{element:u}=i(),p=Ld({group:c}),h=wh({groupSize:p,panelElement:u,styleProp:l}),g=Mi(h/p*100);o(g)}}}function OI(e){if(e.defaultPrevented)return;const t=Zc();TE(e,t).forEach(n=>{if(n.separator){const r=n.panels.find(i=>i.panelConstraints.defaultSize!==void 0);if(r){const i=r.panelConstraints.defaultSize,s=Y8({groupId:n.group.id,panelId:r.id});s&&i!==void 0&&(s.resize(i),e.preventDefault())}}})}function Nv(e){const t=Zc();for(const[n]of t)if(n.separators.some(r=>r.element===e))return n;throw Error("Could not find parent Group for separator element")}function X8({groupId:e}){const t=()=>{const n=Zc();for(const[r,i]of n)if(r.id===e)return{group:r,...i};throw Error(`Could not find Group with id "${e}"`)};return{getLayout(){const{defaultLayoutDeferred:n,layout:r}=t();return n?{}:r},setLayout(n){const{defaultLayoutDeferred:r,derivedPanelConstraints:i,group:s,groupSize:o,layout:l,separatorToPanels:c}=t(),u=zc({layout:n,panelConstraints:i});return r?l:(Oc(l,u)||ya(s,{defaultLayoutDeferred:r,derivedPanelConstraints:i,groupSize:o,layout:u,separatorToPanels:c}),u)}}}function cc(e,t){const n=Nv(e),r=wl(n.id,!0),i=n.separators.find(p=>p.element===e);Mn(i,"Matching separator not found");const s=r.separatorToPanels.get(i);Mn(s,"Matching panels not found");const o=s.map(p=>n.panels.indexOf(p)),l=X8({groupId:n.id}).getLayout(),c=pp({delta:t,initialLayout:l,panelConstraints:r.derivedPanelConstraints,pivotIndices:o,prevLayout:l,trigger:"keyboard"}),u=zc({layout:c,panelConstraints:r.derivedPanelConstraints});Oc(l,u)||ya(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:u,separatorToPanels:r.separatorToPanels})}function zI(e){if(e.defaultPrevented)return;const t=e.currentTarget,n=Nv(t);if(!n.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),n.orientation==="vertical"&&cc(t,5);break}case"ArrowLeft":{e.preventDefault(),n.orientation==="horizontal"&&cc(t,-5);break}case"ArrowRight":{e.preventDefault(),n.orientation==="horizontal"&&cc(t,5);break}case"ArrowUp":{e.preventDefault(),n.orientation==="vertical"&&cc(t,-5);break}case"End":{e.preventDefault(),cc(t,100);break}case"Enter":{e.preventDefault();const r=Nv(t),i=wl(r.id,!0),{derivedPanelConstraints:s,layout:o,separatorToPanels:l}=i,c=r.separators.find(g=>g.element===t);Mn(c,"Matching separator not found");const u=l.get(c);Mn(u,"Matching panels not found");const p=u[0],h=s.find(g=>g.panelId===p.id);if(Mn(h,"Panel metadata not found"),h.collapsible){const g=o[p.id],b=h.collapsedSize===g?r.mutableState.expandedPanelSizes[p.id]??h.minSize:h.collapsedSize;cc(t,b-g)}break}case"F6":{e.preventDefault();const r=Nv(t).separators.map(o=>o.element),i=Array.from(r).findIndex(o=>o===e.currentTarget);Mn(i!==null,"Index not found");const s=e.shiftKey?i>0?i-1:r.length-1:i+1<r.length?i+1:0;r[s].focus({preventScroll:!0});break}case"Home":{e.preventDefault(),cc(t,-100);break}}}let yd={cursorFlags:0,state:"inactive"};const AE=new G8;function Bc(){return yd}function Jge(e){return AE.addListener("change",e)}function eve(e){const t=yd,n={...yd};n.cursorFlags=e,yd=n,AE.emit("change",{prev:t,next:n})}function _d(e){const t=yd;yd=e,AE.emit("change",{prev:t,next:e})}function BI(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=Zc(),n=TE(e,t),r=new Map;let i=!1;n.forEach(s=>{s.separator&&(i||(i=!0,s.separator.element.focus({preventScroll:!0})));const o=t.get(s.group);o&&r.set(s.group,o.layout)}),_d({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}),n.length&&e.preventDefault()}const tve=e=>e,MS=()=>{},Q8=1,Z8=2,J8=4,eB=8,FI=3,$I=12;let Qg;function HI(){return Qg===void 0&&(Qg=!1,typeof window<"u"&&(window.navigator.userAgent.includes("Chrome")||window.navigator.userAgent.includes("Firefox"))&&(Qg=!0)),Qg}function nve({cursorFlags:e,groups:t,state:n}){let r=0,i=0;switch(n){case"active":case"hover":t.forEach(s=>{if(!s.mutableState.disableCursor)switch(s.orientation){case"horizontal":{r++;break}case"vertical":{i++;break}}})}if(!(r===0&&i===0)){switch(n){case"active":{if(e&&HI()){const s=(e&Q8)!==0,o=(e&Z8)!==0,l=(e&J8)!==0,c=(e&eB)!==0;if(s)return l?"se-resize":c?"ne-resize":"e-resize";if(o)return l?"sw-resize":c?"nw-resize":"w-resize";if(l)return"s-resize";if(c)return"n-resize"}break}}return HI()?r>0&&i>0?"move":r>0?"ew-resize":"ns-resize":r>0&&i>0?"grab":r>0?"col-resize":"row-resize"}}const UI=new WeakMap;function NE(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=UI.get(e)??{};n===void 0&&(n=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&e.adoptedStyleSheets.push(n));const r=Bc();switch(r.state){case"active":case"hover":{const i=nve({cursorFlags:r.cursorFlags,groups:r.hitRegions.map(o=>o.group),state:r.state}),s=`*, *:hover {cursor: ${i} !important; }`;if(t===s)return;t=s,i?n.cssRules.length===0?n.insertRule(s):n.replaceSync(s):n.cssRules.length===1&&n.deleteRule(0);break}case"inactive":{t=void 0,n.cssRules.length===1&&n.deleteRule(0);break}}UI.set(e,{prevStyle:t,styleSheet:n})}function tB({document:e,event:t,hitRegions:n,initialLayoutMap:r,mountedGroups:i,pointerDownAtPoint:s,prevCursorFlags:o}){let l=0;n.forEach(u=>{const{group:p,groupSize:h}=u,{orientation:g,panels:b}=p,{disableCursor:_}=p.mutableState;let x=0;s?g==="horizontal"?x=(t.clientX-s.x)/h*100:x=(t.clientY-s.y)/h*100:g==="horizontal"?x=t.clientX<0?-100:100:x=t.clientY<0?-100:100;const S=r.get(p),C=i.get(p);if(!S||!C)return;const{defaultLayoutDeferred:E,derivedPanelConstraints:k,groupSize:T,layout:A,separatorToPanels:N}=C;if(k&&A&&N){const M=pp({delta:x,initialLayout:S,panelConstraints:k,pivotIndices:u.panels.map(j=>b.indexOf(j)),prevLayout:A,trigger:"mouse-or-touch"});if(Oc(M,A)){if(x!==0&&!_)switch(g){case"horizontal":{l|=x<0?Q8:Z8;break}case"vertical":{l|=x<0?J8:eB;break}}}else ya(u.group,{defaultLayoutDeferred:E,derivedPanelConstraints:k,groupSize:T,layout:M,separatorToPanels:N})}});let c=0;t.movementX===0?c|=o&FI:c|=l&FI,t.movementY===0?c|=o&$I:c|=l&$I,eve(c),NE(e)}function VI(e){const t=Zc(),n=Bc();switch(n.state){case"active":tB({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}}function WI(e){if(e.defaultPrevented)return;const t=Bc(),n=Zc();switch(t.state){case"active":{if(e.buttons===0){_d({cursorFlags:0,state:"inactive"}),t.hitRegions.forEach(r=>{const i=wl(r.group.id,!0);ya(r.group,i)});return}tB({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break}default:{const r=TE(e,n);r.length===0?t.state!=="inactive"&&_d({cursorFlags:0,state:"inactive"}):_d({cursorFlags:0,hitRegions:r,state:"hover"}),NE(e.currentTarget);break}}}function GI(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(Bc().state){case"hover":_d({cursorFlags:0,state:"inactive"})}}function qI(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=Bc();switch(t.state){case"active":_d({cursorFlags:0,state:"inactive"}),t.hitRegions.length>0&&(NE(e.currentTarget),t.hitRegions.forEach(n=>{const r=wl(n.group.id,!0);ya(n.group,r)}),e.preventDefault())}}function KI(e){let t=0,n=0;const r={};for(const s of e)if(s.defaultSize!==void 0){t++;const o=Mi(s.defaultSize);n+=o,r[s.panelId]=o}else r[s.panelId]=void 0;const i=e.length-t;if(i!==0){const s=Mi((100-n)/i);for(const o of e)o.defaultSize===void 0&&(r[o.panelId]=s)}return r}function rve(e,t,n){if(!n[0])return;const r=e.panels.find(c=>c.element===t);if(!r||!r.onResize)return;const i=Ld({group:e}),s=e.orientation==="horizontal"?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,l={asPercentage:Mi(s/i*100),inPixels:s};r.mutableValues.prevSize=l,r.onResize(l,r.id,o)}function ive(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(e[n]!==t[n])return!1;return!0}function sve({group:e,nextGroupSize:t,prevGroupSize:n,prevLayout:r}){if(n<=0||t<=0||n===t)return r;let i=0,s=0,o=!1;const l=new Map,c=[];for(const h of e.panels){const g=r[h.id]??0;switch(h.panelConstraints.groupResizeBehavior){case"preserve-pixel-size":{o=!0;const b=g/100*n,_=Mi(b/t*100);l.set(h.id,_),i+=_;break}case"preserve-relative-size":default:{c.push(h.id),s+=g;break}}}if(!o||c.length===0)return r;const u=100-i,p={...r};if(l.forEach((h,g)=>{p[g]=h}),s>0)for(const h of c){const g=r[h]??0;p[h]=Mi(g/s*u)}else{const h=Mi(u/c.length);for(const g of c)p[g]=h}return p}function ove(e,t){const n=e.map(i=>i.id),r=Object.keys(t);if(n.length!==r.length)return!1;for(const i of n)if(!r.includes(i))return!1;return!0}const qu=new Map;function ave(e){let t=!0;Mn(e.element.ownerDocument.defaultView,"Cannot register an unmounted Group");const n=e.element.ownerDocument.defaultView.ResizeObserver,r=new Set,i=new Set,s=new n(_=>{for(const x of _){const{borderBoxSize:S,target:C}=x;if(C===e.element){if(t){const E=Ld({group:e});if(E===0)return;const k=wl(e.id);if(!k)return;const T=A1(e),A=k.defaultLayoutDeferred?KI(T):k.layout,N=sve({group:e,nextGroupSize:E,prevGroupSize:k.groupSize,prevLayout:A}),M=zc({layout:N,panelConstraints:T});if(!k.defaultLayoutDeferred&&Oc(k.layout,M)&&ive(k.derivedPanelConstraints,T)&&k.groupSize===E)return;ya(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:T,groupSize:E,layout:M,separatorToPanels:k.separatorToPanels})}}else rve(e,C,S)}});s.observe(e.element),e.panels.forEach(_=>{Mn(!r.has(_.id),`Panel ids must be unique; id "${_.id}" was used more than once`),r.add(_.id),_.onResize&&s.observe(_.element)});const o=Ld({group:e}),l=A1(e),c=e.panels.map(({id:_})=>_).join(",");let u=e.mutableState.defaultLayout;u&&(ove(e.panels,u)||(u=void 0));const p=e.mutableState.layouts[c]??u??KI(l),h=zc({layout:p,panelConstraints:l}),g=e.element.ownerDocument;qu.set(g,(qu.get(g)??0)+1);const b=new Map;return W8(e).forEach(_=>{_.separator&&b.set(_.separator,_.panels)}),ya(e,{defaultLayoutDeferred:o===0,derivedPanelConstraints:l,groupSize:o,layout:h,separatorToPanels:b}),e.separators.forEach(_=>{Mn(!i.has(_.id),`Separator ids must be unique; id "${_.id}" was used more than once`),i.add(_.id),_.element.addEventListener("keydown",zI)}),qu.get(g)===1&&(g.addEventListener("dblclick",OI,!0),g.addEventListener("pointerdown",BI,!0),g.addEventListener("pointerleave",VI),g.addEventListener("pointermove",WI),g.addEventListener("pointerout",GI),g.addEventListener("pointerup",qI,!0)),function(){t=!1,qu.set(g,Math.max(0,(qu.get(g)??0)-1)),Uge(e),e.separators.forEach(_=>{_.element.removeEventListener("keydown",zI)}),qu.get(g)||(g.removeEventListener("dblclick",OI,!0),g.removeEventListener("pointerdown",BI,!0),g.removeEventListener("pointerleave",VI),g.removeEventListener("pointermove",WI),g.removeEventListener("pointerout",GI),g.removeEventListener("pointerup",qI,!0)),s.disconnect()}}function lve(){const[e,t]=v.useState({}),n=v.useCallback(()=>t({}),[]);return[e,n]}function ME(e){const t=v.useId();return`${e??t}`}const Jc=typeof window<"u"?v.useLayoutEffect:v.useEffect;function $h(e){const t=v.useRef(e);return Jc(()=>{t.current=e},[e]),v.useCallback((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[t])}function LE(...e){return $h(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}function IE(e){const t=v.useRef({...e});return Jc(()=>{for(const n in e)t.current[n]=e[n]},[e]),t.current}const nB=v.createContext(null);function cve(e,t){const n=v.useRef({getLayout:()=>({}),setLayout:tve});v.useImperativeHandle(t,()=>n.current,[]),Jc(()=>{Object.assign(n.current,X8({groupId:e}))})}function rB({children:e,className:t,defaultLayout:n,disableCursor:r,disabled:i,elementRef:s,groupRef:o,id:l,onLayoutChange:c,onLayoutChanged:u,orientation:p="horizontal",resizeTargetMinimumSize:h={coarse:20,fine:10},style:g,...b}){const _=v.useRef({onLayoutChange:{},onLayoutChanged:{}}),x=$h(P=>{Oc(_.current.onLayoutChange,P)||(_.current.onLayoutChange=P,c==null||c(P))}),S=$h(P=>{Oc(_.current.onLayoutChanged,P)||(_.current.onLayoutChanged=P,u==null||u(P))}),C=ME(l),E=v.useRef(null),[k,T]=lve(),A=v.useRef({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:h,separators:[]}),N=LE(E,s);cve(C,o);const M=$h((P,z)=>{const O=Bc(),$=II(P),V=wl(P);if(V){let F=!1;switch(O.state){case"active":{F=O.hitRegions.some(H=>H.group===$);break}}return{flexGrow:V.layout[z]??1,pointerEvents:F?"none":void 0}}return{flexGrow:(n==null?void 0:n[z])??1}}),j=IE({defaultLayout:n,disableCursor:r}),U=v.useMemo(()=>({get disableCursor(){return!!j.disableCursor},getPanelStyles:M,id:C,orientation:p,registerPanel:P=>{const z=A.current;return z.panels=N1(p,[...z.panels,P]),T(),()=>{z.panels=z.panels.filter(O=>O!==P),T()}},registerSeparator:P=>{const z=A.current;return z.separators=N1(p,[...z.separators,P]),T(),()=>{z.separators=z.separators.filter(O=>O!==P),T()}},togglePanelDisabled:(P,z)=>{const O=A.current.panels.find(F=>F.id===P);O&&(O.panelConstraints.disabled=z);const $=II(C),V=wl(C);$&&V&&ya($,{...V,derivedPanelConstraints:A1($)})},toggleSeparatorDisabled:(P,z)=>{const O=A.current.separators.find($=>$.id===P);O&&(O.disabled=z)}}),[M,C,T,p,j]),I=v.useRef(null);return Jc(()=>{const P=E.current;if(P===null)return;const z=A.current;let O;if(j.defaultLayout!==void 0&&Object.keys(j.defaultLayout).length===z.panels.length){O={};for(const D of z.panels){const G=j.defaultLayout[D.id];G!==void 0&&(O[D.id]=G)}}const $={disabled:!!i,element:P,id:C,mutableState:{defaultLayout:O,disableCursor:!!j.disableCursor,expandedPanelSizes:A.current.lastExpandedPanelSizes,layouts:A.current.layouts},orientation:p,panels:z.panels,resizeTargetMinimumSize:z.resizeTargetMinimumSize,separators:z.separators};I.current=$;const V=ave($),{defaultLayoutDeferred:F,derivedPanelConstraints:H,layout:W}=wl($.id,!0);!F&&H.length>0&&(x(W),S(W));const Z=RE(C,D=>{const{defaultLayoutDeferred:G,derivedPanelConstraints:ee,layout:B}=D.next;if(G||ee.length===0)return;const le=$.panels.map(({id:J})=>J).join(",");$.mutableState.layouts[le]=B,ee.forEach(J=>{if(J.collapsible){const{layout:ne}=D.prev??{};if(ne){const se=di(J.collapsedSize,B[J.panelId]),ce=di(J.collapsedSize,ne[J.panelId]);se&&!ce&&($.mutableState.expandedPanelSizes[J.panelId]=ne[J.panelId])}}});const oe=Bc().state!=="active";x(B),oe&&S(B)});return()=>{I.current=null,V(),Z()}},[i,C,S,x,p,k,j]),v.useEffect(()=>{const P=I.current;P&&(P.mutableState.defaultLayout=n,P.mutableState.disableCursor=!!r)}),f.jsx(nB.Provider,{value:U,children:f.jsx("div",{...b,className:t,"data-group":!0,"data-testid":C,id:C,ref:N,style:{height:"100%",width:"100%",overflow:"hidden",...g,display:"flex",flexDirection:p==="horizontal"?"row":"column",flexWrap:"nowrap",touchAction:p==="horizontal"?"pan-y":"pan-x"},children:e})})}rB.displayName="Group";function jE(){const e=v.useContext(nB);return Mn(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function uve(e,t){const{id:n}=jE(),r=v.useRef({collapse:MS,expand:MS,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:MS});v.useImperativeHandle(t,()=>r.current,[]),Jc(()=>{Object.assign(r.current,Y8({groupId:n,panelId:e}))})}function iB({children:e,className:t,collapsedSize:n="0%",collapsible:r=!1,defaultSize:i,disabled:s,elementRef:o,groupResizeBehavior:l="preserve-relative-size",id:c,maxSize:u="100%",minSize:p="0%",onResize:h,panelRef:g,style:b,..._}){const x=!!c,S=ME(c),C=IE({disabled:s}),E=v.useRef(null),k=LE(E,o),{getPanelStyles:T,id:A,orientation:N,registerPanel:M,togglePanelDisabled:j}=jE(),U=h!==null,I=$h((z,O,$)=>{h==null||h(z,c,$)});Jc(()=>{const z=E.current;if(z!==null){const O={element:z,id:S,idIsStable:x,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:U?I:void 0,panelConstraints:{groupResizeBehavior:l,collapsedSize:n,collapsible:r,defaultSize:i,disabled:C.disabled,maxSize:u,minSize:p}};return M(O)}},[l,n,r,i,U,S,x,u,p,I,M,C]),v.useEffect(()=>{j(S,!!s)},[s,S,j]),uve(S,g);const P=v.useSyncExternalStore(z=>RE(A,z),()=>JSON.stringify(T(A,S)),()=>JSON.stringify(T(A,S)));return f.jsx("div",{..._,"aria-disabled":s||void 0,"data-panel":!0,"data-testid":S,id:S,ref:k,style:{...dve,display:"flex",flexBasis:0,flexShrink:1,overflow:"visible",...JSON.parse(P)},children:f.jsx("div",{className:t,style:{maxHeight:"100%",maxWidth:"100%",flexGrow:1,overflow:"auto",...b,touchAction:N==="horizontal"?"pan-y":"pan-x"},children:e})})}iB.displayName="Panel";const dve={minHeight:0,maxHeight:"100%",height:"auto",minWidth:0,maxWidth:"100%",width:"auto",border:"none",borderWidth:0,padding:0,margin:0};function fve({layout:e,panelConstraints:t,panelId:n,panelIndex:r}){let i,s;const o=e[n],l=t.find(c=>c.panelId===n);if(l){const c=l.maxSize,u=l.collapsible?l.collapsedSize:l.minSize,p=[r,r+1];s=zc({layout:pp({delta:u-o,initialLayout:e,panelConstraints:t,pivotIndices:p,prevLayout:e}),panelConstraints:t})[n],i=zc({layout:pp({delta:c-o,initialLayout:e,panelConstraints:t,pivotIndices:p,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:s,valueNow:o}}function sB({children:e,className:t,disabled:n,elementRef:r,id:i,style:s,...o}){const l=ME(i),c=IE({disabled:n}),[u,p]=v.useState({}),[h,g]=v.useState("inactive"),b=v.useRef(null),_=LE(b,r),{disableCursor:x,id:S,orientation:C,registerSeparator:E,toggleSeparatorDisabled:k}=jE(),T=C==="horizontal"?"vertical":"horizontal";Jc(()=>{const N=b.current;if(N!==null){const M={disabled:c.disabled,element:N,id:l},j=E(M),U=Jge(P=>{g(P.next.state!=="inactive"&&P.next.hitRegions.some(z=>z.separator===M)?P.next.state:"inactive")}),I=RE(S,P=>{const{derivedPanelConstraints:z,layout:O,separatorToPanels:$}=P.next,V=$.get(M);if(V){const F=V[0],H=V.indexOf(F);p(fve({layout:O,panelConstraints:z,panelId:F.id,panelIndex:H}))}});return()=>{U(),I(),j()}}},[S,l,E,c]),v.useEffect(()=>{k(l,!!n)},[n,l,k]);let A;return n&&!x&&(A="not-allowed"),f.jsx("div",{...o,"aria-controls":u.valueControls,"aria-disabled":n||void 0,"aria-orientation":T,"aria-valuemax":u.valueMax,"aria-valuemin":u.valueMin,"aria-valuenow":u.valueNow,children:e,className:t,"data-separator":n?"disabled":h,"data-testid":l,id:l,ref:_,role:"separator",style:{flexBasis:"auto",cursor:A,...s,flexGrow:0,flexShrink:0,touchAction:"none"},tabIndex:n?void 0:0})}sB.displayName="Separator";const DE=({className:e,...t})=>f.jsx(rB,{className:he("flex h-full w-full",e),...t}),mp=e=>f.jsx(iB,{...e}),PE=({withHandle:e,orientation:t,disabled:n,className:r,...i})=>f.jsx(sB,{disabled:n,className:he("relative flex items-center justify-center bg-transparent focus-visible:outline-none",t==="vertical"?"h-2 w-full -my-1 cursor-row-resize":"h-full w-2 -mx-1 cursor-col-resize",e&&(t==="vertical"?"before:absolute before:inset-x-0 before:top-1/2 before:h-0.5 before:-translate-y-1/2 before:bg-border":"before:absolute before:inset-y-0 before:left-1/2 before:w-px before:-translate-x-1/2 before:bg-border"),r),...i,children:f.jsx("span",{className:"sr-only",children:t==="vertical"?"Resize rows":"Resize columns"})});function oB(e,t,n){const r=typeof e.maxTokens=="number"&&Number.isFinite(e.maxTokens)?e.maxTokens:null,i=r&&r>0?Math.min(100,e.usedTokens/r*100):null,s=r!==null?Math.max(0,Math.round(r-e.usedTokens)):null,o=i!==null?Math.max(0,100-i):null;return{...e,compactsAutomatically:e.compactsAutomatically||n,maxTokens:r??void 0,remainingTokens:s,usedPercentage:i,remainingPercentage:o,updatedAt:t}}function hve(e){const t=e.some(n=>n.kind==="compact_boundary"||n.kind==="compact_summary"||n.kind==="context_cleared");for(let n=e.length-1;n>=0;n-=1){const r=e[n];if(r&&!(r.kind!=="context_window_updated"||r.usage.usedTokens<=0))return oB(r.usage,new Date(r.createdAt).toISOString(),t)}return null}function pve(e,t){return!e||t===null||!Number.isFinite(t)||t<=0?e:oB({...e,maxTokens:t},e.updatedAt,e.compactsAutomatically)}function ch(e){return e==null||!Number.isFinite(e)?"0":e<1e3?`${Math.round(e)}`:e<1e4?`${(e/1e3).toFixed(1).replace(/\.0$/,"")}k`:e<1e6?`${Math.round(e/1e3)}k`:`${(e/1e6).toFixed(1).replace(/\.0$/,"")}m`}const OE=[68,32];function mve(){return{isVisible:!1,mainSizes:[...OE],terminals:[],nextTerminalIndex:0}}function gve(e,t){return e[t]??mve()}function LS(e){if(e.length===0)return[];const t=e.reduce((n,r)=>n+Math.max(r,0),0);return!Number.isFinite(t)||t<=0?Array.from({length:e.length},()=>100/e.length):e.map(n=>Math.max(n,0)/t*100)}function vve(e){let t=e,n="";do n=String.fromCharCode(65+t%26)+n,t=Math.floor(t/26)-1;while(t>=0);return`Terminal ${n}`}function bve(e){if(e.length===0)return e;const t=e.length+1;return e.map(n=>({...n,size:n.size*e.length/t}))}function Ku(e,t,n){return{...e,[t]:n(gve(e,t))}}const ul=no()(Wp(e=>({projects:{},addTerminal:(t,n)=>e(r=>({projects:Ku(r.projects,t,i=>{var c,u;const s=bve(i.terminals),o={id:((u=(c=globalThis.crypto)==null?void 0:c.randomUUID)==null?void 0:u.call(c))??`terminal-${Date.now()}-${i.nextTerminalIndex}`,title:vve(i.nextTerminalIndex),size:100/(s.length+1)},l=n?Math.max(s.findIndex(p=>p.id===n)+1,0):s.length;return{...i,isVisible:!0,nextTerminalIndex:i.nextTerminalIndex+1,terminals:[...s.slice(0,l),o,...s.slice(l)]}})})),removeTerminal:(t,n)=>e(r=>({projects:Ku(r.projects,t,i=>{const s=i.terminals.filter(l=>l.id!==n);if(s.length===0)return{...i,isVisible:!1,terminals:[]};const o=LS(s.map(l=>l.size));return{...i,terminals:s.map((l,c)=>({...l,size:o[c]??100/s.length}))}})})),toggleVisibility:t=>e(n=>({projects:Ku(n.projects,t,r=>({...r,isVisible:r.terminals.length>0?!r.isVisible:!1}))})),resetMainSizes:t=>e(n=>({projects:Ku(n.projects,t,r=>({...r,mainSizes:[...OE]}))})),setMainSizes:(t,n)=>e(r=>{if(n.length!==2)return r;const i=LS(n);return{projects:Ku(r.projects,t,s=>({...s,mainSizes:i}))}}),setTerminalSizes:(t,n)=>e(r=>({projects:Ku(r.projects,t,i=>{if(n.length!==i.terminals.length)return i;const s=LS(n);return{...i,terminals:i.terminals.map((o,l)=>({...o,size:s[l]??o.size}))}})})),clearProject:t=>e(n=>{const{[t]:r,...i}=n.projects;return{projects:i}})}),{name:"terminal-layouts",version:1})),yve={isVisible:!1,mainSizes:[...OE],terminals:[],nextTerminalIndex:0},_ve=35;function xve(e,t){return!Number.isFinite(e)||e<=0||!Number.isFinite(t)||t<=0?0:e*(t/100)}function Sve(e,t){const n=xve(e,t);return n>=0&&n<_ve}const X0=350,wve=[.4,0,.2,1],Cve=8,YI=1e-6;function kve(e,t,n){const r=1-e;return 3*r*r*e*t+3*r*e*e*n+e*e*e}function Eve(e,t,n){const r=1-e;return 3*r*r*e*t+3*r*e*e*n+e*e*e}function Rve(e,t,n){const r=1-e;return 3*r*r*t+6*r*e*(n-t)+3*e*e*(1-n)}function Tve(e,t,n){let r=e;for(let i=0;i<Cve;i+=1){const s=kve(r,t,n)-e;if(Math.abs(s)<YI)return r;const o=Rve(r,t,n);if(Math.abs(o)<YI)break;r-=s/o}return r}function Ave(e){if(e<=0)return 0;if(e>=1)return 1;const[t,n,r,i]=wve,s=Tve(e,t,r);return Eve(s,n,i)}function aB(e,t,n){const r=Ave(n);return[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r]}function Nve({projectId:e,shouldRenderRightSidebarLayout:t,showRightSidebar:n,rightSidebarSize:r}){const i=v.useRef(null),s=v.useRef(null),o=v.useRef(null),l=v.useRef(null),c=v.useRef(null),u=v.useRef(!1),p=v.useRef(null),h=v.useRef(!1),g=v.useRef(!1);return v.useEffect(()=>()=>{l.current!==null&&window.cancelAnimationFrame(l.current),c.current!==null&&window.clearTimeout(c.current)},[]),v.useLayoutEffect(()=>{var M,j,U,I,P,z;if(!t){l.current!==null&&(window.cancelAnimationFrame(l.current),l.current=null),c.current!==null&&(window.clearTimeout(c.current),c.current=null),u.current=!1;return}const b=i.current;if(!b)return;l.current!==null&&(window.cancelAnimationFrame(l.current),l.current=null),c.current!==null&&(window.clearTimeout(c.current),c.current=null);const _=p.current,x=_!==null&&_!==e,S=n&&!g.current,C=!h.current,E=n?[100-r,r]:[100,0],k=x||C&&n,T=S||C?[100,0]:[b.getLayout().workspace??E[0],b.getLayout().rightSidebar??E[1]];if(p.current=e,h.current=t,g.current=n,k||Math.abs(T[0]-E[0])<.1&&Math.abs(T[1]-E[1])<.1){b.setLayout({workspace:E[0],rightSidebar:E[1]}),(M=s.current)==null||M.setAttribute("data-right-sidebar-open",n?"true":"false"),(j=o.current)==null||j.setAttribute("data-right-sidebar-open",n?"true":"false"),(U=o.current)==null||U.setAttribute("data-right-sidebar-animated","false");return}u.current=!0,(I=s.current)==null||I.setAttribute("data-right-sidebar-open",n?"true":"false"),(P=o.current)==null||P.setAttribute("data-right-sidebar-open",n?"true":"false"),(z=o.current)==null||z.setAttribute("data-right-sidebar-animated","true"),b.setLayout({workspace:T[0],rightSidebar:T[1]});const A=performance.now(),N=O=>{const $=Math.min(1,(O-A)/X0),V=aB(T,E,$);if(b.setLayout({workspace:V[0],rightSidebar:V[1]}),$<1){l.current=window.requestAnimationFrame(N);return}b.setLayout({workspace:E[0],rightSidebar:E[1]}),l.current=null,c.current=window.setTimeout(()=>{u.current=!1,c.current=null},0)};l.current=window.requestAnimationFrame(N)},[e,r,t,n]),v.useEffect(()=>{t||(h.current=!1,g.current=!1)},[t]),{isAnimating:u,panelGroupRef:i,sidebarPanelRef:s,sidebarVisualRef:o}}function Mve(e){return e.visibilityState==="visible"?e.activeChatId:null}function Lve(e){e.socket.setFocusedChat(Mve({activeChatId:e.activeChatId,visibilityState:e.visibilityState}))}function Ive({socket:e,activeChatId:t}){v.useEffect(()=>{if(typeof document>"u")return;const n=()=>{Lve({socket:e,activeChatId:t,visibilityState:document.visibilityState})};return n(),document.addEventListener("visibilitychange",n),window.addEventListener("pagehide",n),window.addEventListener("pageshow",n),()=>{document.removeEventListener("visibilitychange",n),window.removeEventListener("pagehide",n),window.removeEventListener("pageshow",n),e.setFocusedChat(null)}},[e,t])}function jve({rootRef:e,fallbackRef:t,enabled:n,canCancel:r}){v.useEffect(()=>{if(!n)return;let i=0,s=null;const o=h=>{const g=h instanceof Element?h:null,b=e.current,_=t.current;if(ON({trigger:"pointer",activeElement:document.activeElement,pointerStartTarget:s,pointerEndTarget:g,root:b,fallback:_,hasActiveOverlay:PN(document),hasActiveSelection:jK(window.getSelection())})!=="restore"){s=null;return}_==null||_.focus({preventScroll:!0}),s=null},l=h=>{cancelAnimationFrame(i),s=h.target instanceof Element?h.target:null},c=h=>{cancelAnimationFrame(i),i=window.requestAnimationFrame(()=>{o(h.target)})},u=()=>{s=null;const h=t.current;!h||h.disabled||h.focus({preventScroll:!0})},p=h=>{if(h.key!=="Escape")return;const g=t.current;ON({trigger:"escape",activeElement:document.activeElement,fallback:g,hasActiveOverlay:PN(document),canCancel:r,defaultPrevented:h.defaultPrevented})==="escape-focus"&&(h.preventDefault(),g==null||g.focus({preventScroll:!0}))};return window.addEventListener("pointerdown",l,!0),window.addEventListener("pointerup",c,!0),window.addEventListener("keydown",p,!0),window.addEventListener(Yv,u),()=>{cancelAnimationFrame(i),window.removeEventListener("pointerdown",l,!0),window.removeEventListener("pointerup",c,!0),window.removeEventListener("keydown",p,!0),window.removeEventListener(Yv,u)}},[r,n,t,e])}function Dve(e){const t=e.previousProjectId!==null&&e.previousProjectId!==e.projectId,n=e.previousProjectId===null&&e.projectId!==null;return!t&&!n&&e.showTerminalPane&&!e.wasTerminalVisible}function Pve({previousProjectId:e,projectId:t,previousShouldRenderTerminalLayout:n,previousShowTerminalPane:r,showTerminalPane:i,terminalLayout:s,liveLayout:o}){const l=e!==null&&e!==t,c=i&&!r,u=!n,p=e===null&&t!==null,h=i?s.mainSizes:[100,0];return{currentLayout:c||u?[100,0]:o,shouldSkipAnimation:l||p&&u,targetLayout:h}}function Ove({chatInputRef:e,projectId:t,shouldRenderTerminalLayout:n,showTerminalPane:r,terminalLayout:i}){const s=v.useRef(null),o=v.useRef(null),l=v.useRef(null),c=v.useRef(null),u=v.useRef(null),p=v.useRef(!1),h=v.useRef(null),g=v.useRef(!1),b=v.useRef(!1),_=v.useRef(!1),[x,S]=v.useState(0);return v.useEffect(()=>{var k;const C=h.current,E=_.current;Dve({previousProjectId:C,projectId:t,showTerminalPane:r,wasTerminalVisible:E})&&S(T=>T+1),C!==null&&C===t&&!r&&E&&((k=e.current)==null||k.focus({preventScroll:!0})),_.current=r,h.current=t},[e,t,r]),v.useEffect(()=>()=>{c.current!==null&&window.cancelAnimationFrame(c.current),u.current!==null&&window.clearTimeout(u.current)},[]),v.useLayoutEffect(()=>{var j,U,I,P,z,O;if(!n){c.current!==null&&(window.cancelAnimationFrame(c.current),c.current=null),u.current!==null&&(window.clearTimeout(u.current),u.current=null),p.current=!1;return}const C=s.current;if(!C)return;c.current!==null&&(window.cancelAnimationFrame(c.current),c.current=null),u.current!==null&&(window.clearTimeout(u.current),u.current=null);const E=h.current,{currentLayout:k,shouldSkipAnimation:T,targetLayout:A}=Pve({previousProjectId:E,projectId:t,previousShouldRenderTerminalLayout:g.current,previousShowTerminalPane:b.current,showTerminalPane:r,terminalLayout:i,liveLayout:[C.getLayout().chat??i.mainSizes[0],C.getLayout().terminal??i.mainSizes[1]]});if(g.current=n,b.current=r,T||Math.abs(k[0]-A[0])<.1&&Math.abs(k[1]-A[1])<.1){C.setLayout({chat:A[0],terminal:A[1]}),(j=o.current)==null||j.setAttribute("data-terminal-open",r?"true":"false"),(U=l.current)==null||U.setAttribute("data-terminal-open",r?"true":"false"),(I=l.current)==null||I.setAttribute("data-terminal-animated","false");return}p.current=!0,(P=o.current)==null||P.setAttribute("data-terminal-open",r?"true":"false"),(z=l.current)==null||z.setAttribute("data-terminal-open",r?"true":"false"),(O=l.current)==null||O.setAttribute("data-terminal-animated","true"),C.setLayout({chat:k[0],terminal:k[1]});const N=performance.now(),M=$=>{const V=Math.min(1,($-N)/X0),F=aB(k,A,V);if(C.setLayout({chat:F[0],terminal:F[1]}),V<1){c.current=window.requestAnimationFrame(M);return}C.setLayout({chat:A[0],terminal:A[1]}),c.current=null,u.current=window.setTimeout(()=>{p.current=!1,u.current=null},0)};c.current=window.requestAnimationFrame(M)},[t,n,r,i]),v.useEffect(()=>{n||(g.current=!1,b.current=!1)},[n]),{isAnimating:p,mainPanelGroupRef:s,terminalFocusRequestVersion:x,terminalPanelRef:o,terminalVisualRef:l}}const XI=e=>Symbol.iterator in e,QI=e=>"entries"in e,ZI=(e,t)=>{const n=e instanceof Map?e:new Map(e.entries()),r=t instanceof Map?t:new Map(t.entries());if(n.size!==r.size)return!1;for(const[i,s]of n)if(!r.has(i)||!Object.is(s,r.get(i)))return!1;return!0},zve=(e,t)=>{const n=e[Symbol.iterator](),r=t[Symbol.iterator]();let i=n.next(),s=r.next();for(;!i.done&&!s.done;){if(!Object.is(i.value,s.value))return!1;i=n.next(),s=r.next()}return!!i.done&&!!s.done};function Bve(e,t){return Object.is(e,t)?!0:typeof e!="object"||e===null||typeof t!="object"||t===null||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t)?!1:XI(e)&&XI(t)?QI(e)&&QI(t)?ZI(e,t):zve(e,t):ZI({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function JI(e){const t=xn.useRef(void 0);return n=>{const r=e(n);return Bve(t.current,r)?t.current:t.current=r}}const Mv="__new__";function uc(e){var s,o;const t=(s=e==null?void 0:e.modelOptions)==null?void 0:s.reasoningEffort,n=yM(t)?t:yM(e==null?void 0:e.effort)?e.effort:rp.reasoningEffort,r=Qee(e==null?void 0:e.model),i=Pk(r,(o=e==null?void 0:e.modelOptions)==null?void 0:o.contextWindow);return{model:r,modelOptions:{reasoningEffort:!o4(r)&&n==="max"?"high":n,contextWindow:i},planMode:!!(e!=null&&e.planMode)}}function Zg(e){var n,r;const t=(n=e==null?void 0:e.modelOptions)==null?void 0:n.reasoningEffort;return{model:Zee(e==null?void 0:e.model),modelOptions:{reasoningEffort:_M(t)?t:_M(e==null?void 0:e.effort)?e.effort:Mw.reasoningEffort,fastMode:typeof((r=e==null?void 0:e.modelOptions)==null?void 0:r.fastMode)=="boolean"?e.modelOptions.fastMode:Mw.fastMode},planMode:!!(e!=null&&e.planMode)}}function Fve(){return{claude:{model:"claude-opus-4-7",modelOptions:{...rp},planMode:!1},codex:{model:"gpt-5.5",modelOptions:{...Mw},planMode:!1}}}function $ve(e,t){if(t===void 0){console.info(`[chat-preferences] ${e}`);return}console.info(`[chat-preferences] ${e}`,t)}function Ib(e,t){if(e==="claude"){const r=t.claude;return{provider:"claude",model:r.model,modelOptions:{...r.modelOptions},planMode:r.planMode}}const n=t.codex;return{provider:"codex",model:n.model,modelOptions:{...n.modelOptions},planMode:n.planMode}}function jb(e){return e.provider==="claude"?{provider:"claude",model:e.model,modelOptions:{...e.modelOptions},planMode:e.planMode}:{provider:"codex",model:e.model,modelOptions:{...e.modelOptions},planMode:e.planMode}}function lB(e){return e.defaultProvider==="last_used"?e.sourceState?jb(e.sourceState):e.legacyComposerState?jb(e.legacyComposerState):Ib("claude",e.providerDefaults):Ib(e.defaultProvider,e.providerDefaults)}function cB(e,t){const n=e.chatStates[t];return n||lB({defaultProvider:e.defaultProvider,providerDefaults:e.providerDefaults,legacyComposerState:e.legacyComposerState})}function Jg(e,t,n){const r=cB(e,t);return{chatStates:{...e.chatStates,[t]:n(r)}}}const hi=no()((e,t)=>({defaultProvider:"last_used",providerDefaults:Fve(),chatStates:{},legacyComposerState:{provider:"claude",model:"claude-opus-4-7",modelOptions:{...rp},planMode:!1},setDefaultProvider:n=>e({defaultProvider:n}),setProviderDefaultModel:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:n==="claude"?uc({...i.providerDefaults.claude,model:r}):Zg({...i.providerDefaults.codex,model:r})}})),setProviderDefaultModelOptions:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:n==="claude"?uc({...i.providerDefaults.claude,modelOptions:{...i.providerDefaults.claude.modelOptions,...r}}):Zg({...i.providerDefaults.codex,modelOptions:{...i.providerDefaults.codex.modelOptions,...r}})}})),setProviderDefaultPlanMode:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:{...i.providerDefaults[n],planMode:r}}})),getComposerState:n=>jb(cB(t(),n)),initializeComposerForChat:(n,r)=>e(i=>{if(i.chatStates[n])return i;const s=lB({defaultProvider:i.defaultProvider,providerDefaults:i.providerDefaults,sourceState:r==null?void 0:r.sourceState,legacyComposerState:i.legacyComposerState});return $ve("initializeComposerForChat",{chatId:n,composerState:s}),{chatStates:{...i.chatStates,[n]:s}}}),setComposerState:(n,r)=>e(i=>({chatStates:{...i.chatStates,[n]:r.provider==="claude"?{provider:"claude",model:uc(r).model,modelOptions:uc(r).modelOptions,planMode:r.planMode}:jb(r)}})),setChatComposerProvider:(n,r)=>e(i=>Jg(i,n,()=>Ib(r,i.providerDefaults))),setChatComposerModel:(n,r)=>e(i=>Jg(i,n,s=>s.provider==="claude"?{provider:"claude",model:uc({...s,model:r}).model,modelOptions:uc({...s,model:r}).modelOptions,planMode:s.planMode}:{provider:"codex",model:r,modelOptions:Zg({...s,model:r}).modelOptions,planMode:s.planMode})),setChatComposerModelOptions:(n,r)=>e(i=>Jg(i,n,s=>s.provider==="claude"?{provider:"claude",model:s.model,modelOptions:uc({...s,modelOptions:{...s.modelOptions,...r}}).modelOptions,planMode:s.planMode}:{provider:"codex",model:s.model,modelOptions:Zg({...s,modelOptions:{...s.modelOptions,...r}}).modelOptions,planMode:s.planMode})),setChatComposerPlanMode:(n,r)=>e(i=>Jg(i,n,s=>({...s,planMode:r}))),resetChatComposerFromProvider:(n,r)=>e(i=>({chatStates:{...i.chatStates,[n]:Ib(r,i.providerDefaults)}}))})),M1=no()(Wp((e,t)=>({drafts:{},attachmentDrafts:{},setDraft:(n,r)=>e(i=>{if(!r){const{[n]:s,...o}=i.drafts;return{drafts:o}}return{drafts:{...i.drafts,[n]:r}}}),clearDraft:n=>e(r=>{const{[n]:i,...s}=r.drafts;return{drafts:s}}),getDraft:n=>t().drafts[n]??"",setAttachmentDrafts:(n,r)=>e(i=>{if(r.length===0){const{[n]:s,...o}=i.attachmentDrafts;return{attachmentDrafts:o}}return{attachmentDrafts:{...i.attachmentDrafts,[n]:r}}}),clearAttachmentDrafts:n=>e(r=>{const{[n]:i,...s}=r.attachmentDrafts;return{attachmentDrafts:s}}),getAttachmentDrafts:n=>t().attachmentDrafts[n]??[]}),{name:"chat-input-drafts"})),zE=no()(e=>({byChatId:{},loadingByChatId:{},setForChat:(t,n)=>e(r=>({byChatId:{...r.byChatId,[t]:n}})),setLoadingForChat:(t,n)=>e(r=>(r.loadingByChatId[t]??!1)===n?r:{loadingByChatId:{...r.loadingByChatId,[t]:n}}),clear:t=>e(n=>{const r=t in n.byChatId,i=t in n.loadingByChatId;if(!r&&!i)return n;const{[t]:s,...o}=n.byChatId,{[t]:l,...c}=n.loadingByChatId;return{byChatId:o,loadingByChatId:c}})}));function Hve(e){return{autoResumeOnRateLimit:!!(e!=null&&e.autoResumeOnRateLimit)}}const Db=no()(Wp(e=>({autoResumeOnRateLimit:!1,setAutoResumeOnRateLimit:t=>e({autoResumeOnRateLimit:t})}),{name:"kanna-preferences",version:1,migrate:e=>Hve(e)}));function Uve(e,t){var n,r,i,s,o,l,c;return{...e,...t,terminal:{...e.terminal,...t.terminal},editor:{...e.editor,...t.editor},providerDefaults:{claude:{...e.providerDefaults.claude,...(n=t.providerDefaults)==null?void 0:n.claude,modelOptions:{...e.providerDefaults.claude.modelOptions,...(i=(r=t.providerDefaults)==null?void 0:r.claude)==null?void 0:i.modelOptions}},codex:{...e.providerDefaults.codex,...(s=t.providerDefaults)==null?void 0:s.codex,modelOptions:{...e.providerDefaults.codex.modelOptions,...(l=(o=t.providerDefaults)==null?void 0:o.codex)==null?void 0:l.modelOptions}}},cloudflareTunnel:{...e.cloudflareTunnel,...t.cloudflareTunnel},claudeAuth:{tokens:((c=t.claudeAuth)==null?void 0:c.tokens)??e.claudeAuth.tokens},auth:{...e.auth,...t.auth},uploads:{...e.uploads,...t.uploads},subagents:e.subagents}}const Us=no()(e=>({settings:null,hydrationStatus:"idle",setHydrationStatus:t=>e({hydrationStatus:t}),setFromServer:t=>e({settings:t,hydrationStatus:"ready"}),applyOptimisticPatch:t=>e(n=>({settings:n.settings?Uve(n.settings,t):n.settings}))})),uB=v.createContext(void 0),Vve=e=>e==="light"||e==="dark"||e==="system";function Wve(e){return e==="dark"?"black-translucent":"default"}function ej(e,t){if(typeof document>"u")return;let n=document.head.querySelector(`meta[name="${e}"]`);n||(n=document.createElement("meta"),n.setAttribute("name",e),document.head.appendChild(n)),n.setAttribute("content",t)}function tj(e){if(typeof document>"u"||typeof window>"u")return;const t=getComputedStyle(document.body).backgroundColor||getComputedStyle(document.documentElement).backgroundColor;t&&ej("theme-color",t),ej("apple-mobile-web-app-status-bar-style",Wve(e)),document.documentElement.style.colorScheme=e}const Lv=()=>typeof window>"u"?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",nj=e=>{if(typeof document>"u")return;const t=e==="system"?Lv():e;document.documentElement.classList.toggle("dark",t==="dark")},Gve=()=>{var t;const e=(t=Us.getState().settings)==null?void 0:t.theme;return e&&Vve(e)?e:"system"};function qve({children:e}){const t=Us(o=>{var l;return(l=o.settings)==null?void 0:l.theme}),n=Us(o=>o.applyOptimisticPatch),[r,i]=v.useState(Gve);v.useEffect(()=>{!t||t===r||i(t)},[t,r]),v.useEffect(()=>{nj(r)},[r]),v.useEffect(()=>{const o=r==="system"?Lv():r;tj(o)},[r]),v.useEffect(()=>{if(r!=="system")return;const o=window.matchMedia("(prefers-color-scheme: dark)"),l=()=>{nj("system"),tj(Lv())};return o.addEventListener?(o.addEventListener("change",l),()=>o.removeEventListener("change",l)):(o.addListener(l),()=>o.removeListener(l))},[r]);const s=v.useMemo(()=>{const o=r==="system"?Lv():r;return{theme:r,resolvedTheme:o,setTheme:l=>{i(l),n({theme:l})}}},[n,r]);return f.jsx(uB.Provider,{value:s,children:e})}function BE(){const e=v.useContext(uB);if(!e)throw new Error("useTheme must be used within ThemeProvider");return e}function uh(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function rj(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}function Kve(e){const t=e&&typeof e=="object"&&"content"in e&&Array.isArray(e.content)?e.content:Array.isArray(e)?e:[],n=[];for(const r of t)if(!(!r||typeof r!="object"||!("type"in r))){if(r.type==="text"&&typeof r.text=="string"){n.push({type:"text",text:r.text});continue}if(r.type==="image"){if("data"in r&&typeof r.data=="string"){n.push({type:"image",data:r.data,mimeType:typeof r.mimeType=="string"?r.mimeType:void 0});continue}"source"in r&&r.source&&typeof r.source=="object"&&"type"in r.source&&r.source.type==="base64"&&"data"in r.source&&typeof r.source.data=="string"&&n.push({type:"image",data:r.source.data,mimeType:typeof r.source.media_type=="string"?r.source.media_type:void 0})}}return n}function Yve(e){const t=e&&typeof e=="object"&&"content"in e&&Array.isArray(e.content)?e.content:Array.isArray(e)?e:null;if(!t)return null;const n=[];for(const r of t)r&&typeof r=="object"&&"type"in r&&r.type==="text"&&typeof r.text=="string"&&n.push(r.text);return n.length>0?n.join(""):null}function Xve(e,t){const n=rj(t);switch(e.toolKind){case"ask_user_question":{const s=uh(n),o=uh(s==null?void 0:s.answers)??(s||{});return{answers:Object.fromEntries(Object.entries(o).map(([l,c])=>Array.isArray(c)?[l,c.map(u=>String(u))]:c&&typeof c=="object"&&Array.isArray(c.answers)?[l,c.answers.map(u=>String(u))]:c==null||c===""?[l,[]]:[l,[String(c)]])),...(s==null?void 0:s.discarded)===!0?{discarded:!0}:{}}}case"exit_plan_mode":{const s=uh(n);return{confirmed:typeof(s==null?void 0:s.confirmed)=="boolean"?s.confirmed:void 0,clearContext:typeof(s==null?void 0:s.clearContext)=="boolean"?s.clearContext:void 0,message:typeof(s==null?void 0:s.message)=="string"?s.message:void 0,...(s==null?void 0:s.discarded)===!0?{discarded:!0}:{}}}case"offer_download":{const s=Yve(n),o=s?rj(s):n,l=uh(o);return{contentUrl:typeof(l==null?void 0:l.contentUrl)=="string"?l.contentUrl:"",relativePath:typeof(l==null?void 0:l.relativePath)=="string"?l.relativePath:"",fileName:typeof(l==null?void 0:l.fileName)=="string"?l.fileName:"",displayName:typeof(l==null?void 0:l.displayName)=="string"?l.displayName:typeof(l==null?void 0:l.fileName)=="string"?l.fileName:"",size:typeof(l==null?void 0:l.size)=="number"?l.size:0,...typeof(l==null?void 0:l.mimeType)=="string"?{mimeType:l.mimeType}:{}}}case"read_file":if(typeof n=="string")return n;const r=Kve(n);if(r.length>0)return{content:r.flatMap(s=>s.type==="text"?[s.text]:[]).join(""),blocks:r};const i=uh(n);return{content:typeof(i==null?void 0:i.content)=="string"?i.content:JSON.stringify(n,null,2)};default:return n}}function dB(e){return new Date(e).toISOString()}function Ri(e){return{id:e._id,messageId:e.messageId,timestamp:dB(e.createdAt),hidden:e.hidden}}function Qve(e){return{id:e._id,messageId:e.messageId,hidden:e.hidden,kind:"tool",toolKind:e.tool.toolKind,toolName:e.tool.toolName,toolId:e.tool.toolId,input:e.tool.input,timestamp:dB(e.createdAt)}}function Zve(e){if(e.debugRaw)try{return JSON.parse(e.debugRaw).tool_use_result}catch{return}}function fB(e){const t=new Map,n=[];for(const r of e)switch(r.kind){case"user_prompt":n.push({...Ri(r),kind:"user_prompt",content:r.content,attachments:r.attachments??[],steered:r.steered,autoContinue:r.autoContinue});break;case"system_init":n.push({...Ri(r),kind:"system_init",provider:r.provider,model:r.model,tools:r.tools,agents:r.agents,slashCommands:r.slashCommands,mcpServers:r.mcpServers,debugRaw:r.debugRaw});break;case"account_info":n.push({...Ri(r),kind:"account_info",accountInfo:r.accountInfo});break;case"assistant_text":n.push({...Ri(r),kind:"assistant_text",text:r.text});break;case"tool_call":{const i=Qve(r);t.set(r.tool.toolId,{hydrated:i,normalized:r.tool}),n.push(i);break}case"tool_result":{const i=t.get(r.toolId);if(i){const s=i.normalized.toolKind==="ask_user_question"||i.normalized.toolKind==="exit_plan_mode"?Zve(r)??r.content:r.content;i.hydrated.result=Xve(i.normalized,s),i.hydrated.rawResult=s,i.hydrated.isError=r.isError,r.persisted&&(i.hydrated.persisted=r.persisted)}break}case"result":n.push({...Ri(r),kind:"result",success:!r.isError,cancelled:r.subtype==="cancelled",result:r.result,durationMs:r.durationMs,costUsd:r.costUsd});break;case"status":n.push({...Ri(r),kind:"status",status:r.status});break;case"context_window_updated":n.push({...Ri(r),kind:"context_window_updated",usage:r.usage});break;case"compact_boundary":n.push({...Ri(r),kind:"compact_boundary"});break;case"compact_summary":n.push({...Ri(r),kind:"compact_summary",summary:r.summary});break;case"context_cleared":n.push({...Ri(r),kind:"context_cleared"});break;case"interrupted":n.push({...Ri(r),kind:"interrupted"});break;case"auto_continue_prompt":n.push({...Ri(r),kind:"auto_continue_prompt",scheduleId:r.scheduleId});break;case"pending_tool_request":n.push({...Ri(r),kind:"pending_tool_request",toolRequestId:r.toolRequestId,toolName:r.toolName,arguments:r.arguments});break;case"tool_request_resolved":break;default:n.push({...Ri(r),kind:"unknown",json:JSON.stringify(r,null,2)});break}return n}const Jve=["AskUserQuestion","ExitPlanMode","TodoWrite"],ebe=new Set(["TodoWrite"]);function tbe(e,t){for(let n=e.length-1;n>=0;n-=1){const r=e[n];if(r.kind!=="tool")continue;const i=r;if(i.toolName===t&&!i.result)return i.id}return null}function nbe(e,t){for(let n=e.length-1;n>=0;n-=1){const r=e[n];if(r.kind!=="tool")continue;const i=r;if(i.toolName===t)return i.id}return null}function rbe(e){const t={};for(const n of Jve)t[n]=ebe.has(n)?nbe(e,n):tbe(e,n);return t}function ibe(e){return e==="starting"||e==="running"||e==="waiting_for_user"}function sbe(e){return e==="starting"||e==="running"||e==="waiting_for_user"}const FE="pushDeviceId";function hB(){return typeof localStorage>"u"?null:localStorage.getItem(FE)}function obe(e){typeof localStorage>"u"||localStorage.setItem(FE,e)}function abe(){typeof localStorage>"u"||localStorage.removeItem(FE)}function lbe(){return!(typeof window>"u"||typeof Notification>"u"||!("serviceWorker"in navigator)||typeof globalThis.PushManager>"u")}function cbe(){var t;if(typeof window>"u")return!1;if(window.isSecureContext)return!0;const e=((t=window.location)==null?void 0:t.hostname)??"";return e==="localhost"||e==="127.0.0.1"||e==="::1"}function L1(){if(!lbe())return{state:"unsupported"};if(!cbe())return{state:"insecure-context"};switch(Notification.permission){case"granted":return{state:"granted"};case"denied":return{state:"denied"};default:return{state:"default"}}}function ube(e){if(typeof Buffer<"u")return new Uint8Array(Buffer.from(e,"base64url"));const t="=".repeat((4-e.length%4)%4),n=(e+t).replace(/-/g,"+").replace(/_/g,"/"),r=atob(n),i=new Uint8Array(r.length);for(let s=0;s<r.length;s+=1)i[s]=r.charCodeAt(s);return i}function dbe(e){const t=e||"";return/iPhone|iPad/i.test(t)?"iPhone / iPad":/Android/i.test(t)?"Android":/Macintosh/i.test(t)?"Mac":/Windows/i.test(t)?"Windows PC":t||"Browser"}async function fbe(e){const t=L1();if(t.state==="unsupported")throw new Error("Push not supported in this browser");if(t.state==="insecure-context")throw new Error("Push requires a secure context (HTTPS)");if(t.state==="denied")throw new Error("Notification permission previously denied");if(await Notification.requestPermission()!=="granted")throw new Error("Notification permission was not granted");const r=await navigator.serviceWorker.register("/sw.js");await navigator.serviceWorker.ready;const i=await r.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:ube(e.vapidPublicKey)}),s=i.toJSON(),o=s.endpoint??i.endpoint,l=s.keys??{};if(!o||!l.p256dh||!l.auth)throw new Error("Subscription returned without endpoint or keys");const c=navigator.userAgent??"",{id:u}=await e.sendToServer({subscription:{endpoint:o,keys:{p256dh:l.p256dh,auth:l.auth}},label:dbe(c),userAgent:c});return u}async function hbe(e){const n=await(await navigator.serviceWorker.ready).pushManager.getSubscription();n&&await n.unsubscribe(),await e.sendToServer(e.pushDeviceId)}typeof navigator<"u"&&"serviceWorker"in navigator&&navigator.serviceWorker.addEventListener("message",e=>{const t=e.data;(t==null?void 0:t.type)==="kanna.navigate"&&typeof t.url=="string"&&(window.location.href=t.url)});const pbe=25e3,mbe=15e3,gbe=4e3,ij="kanna:profile-send-to-starting";function sj(){try{return window.sessionStorage.getItem(ij)==="1"||window.localStorage.getItem(ij)==="1"}catch{return!1}}class vbe{constructor(t){re(this,"url");re(this,"ws",null);re(this,"started",!1);re(this,"reconnectTimer",null);re(this,"reconnectDelayMs",750);re(this,"subscriptions",new Map);re(this,"pending",new Map);re(this,"outboundQueue",[]);re(this,"statusListeners",new Set);re(this,"heartbeatTimer",null);re(this,"pingTimeoutTimer",null);re(this,"pingPromise",null);re(this,"lastOpenAt",0);re(this,"lastMessageAt",0);re(this,"reconnectImmediatelyOnClose",!1);re(this,"handleWindowFocus",()=>{this.ensureHealthyConnection()});re(this,"handleVisibilityChange",()=>{if(document.visibilityState==="visible"){this.startHeartbeat(),this.ensureHealthyConnection();return}this.stopHeartbeat()});re(this,"handleOnline",()=>{this.ensureHealthyConnection()});this.url=t}start(){this.started||(this.started=!0,window.addEventListener("focus",this.handleWindowFocus),window.addEventListener("online",this.handleOnline),document.addEventListener("visibilitychange",this.handleVisibilityChange),this.connect())}dispose(){var t;this.started=!1,this.reconnectTimer&&(window.clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.stopHeartbeat(),this.clearPingState(),window.removeEventListener("focus",this.handleWindowFocus),window.removeEventListener("online",this.handleOnline),document.removeEventListener("visibilitychange",this.handleVisibilityChange),(t=this.ws)==null||t.close(),this.ws=null;for(const n of this.pending.values())n.reject(new Error("Socket disposed"));this.pending.clear()}onStatus(t){return this.statusListeners.add(t),t(this.getStatus()),()=>{this.statusListeners.delete(t)}}subscribe(t,n,r){const i=mc();return this.subscriptions.set(i,{topic:t,listener:n,eventListener:r}),this.enqueue({v:1,type:"subscribe",id:i,topic:t}),()=>{this.subscriptions.delete(i),this.enqueue({v:1,type:"unsubscribe",id:i})}}subscribeTerminal(t,n){const r=mc(),i={type:"terminal",terminalId:t};return this.subscriptions.set(r,{topic:i,listener:n.onSnapshot,eventListener:n.onEvent}),this.enqueue({v:1,type:"subscribe",id:r,topic:i}),()=>{this.subscriptions.delete(r),this.enqueue({v:1,type:"unsubscribe",id:r})}}command(t){const n=mc(),r={v:1,type:"command",id:n,command:t};return new Promise((i,s)=>{this.pending.set(n,{resolve:i,reject:s}),this.enqueue(r)})}setFocusedChat(t){const n=mc();this.enqueue({v:1,type:"command",id:n,command:{type:"push.setFocusedChat",chatId:t}})}ensureHealthyConnection(){return!this.ws||this.ws.readyState===WebSocket.CLOSED||this.ws.readyState===WebSocket.CLOSING?(this.reconnectNow(),Promise.resolve()):this.ws.readyState===WebSocket.CONNECTING||!this.isConnectionStale()?Promise.resolve():this.sendPing()}connect(){this.started&&(this.emitStatus("connecting"),this.ws=new WebSocket(this.url),this.ws.addEventListener("open",()=>{this.reconnectDelayMs=750,this.reconnectImmediatelyOnClose=!1,this.lastOpenAt=Date.now(),this.lastMessageAt=this.lastOpenAt,this.emitStatus("connected"),this.startHeartbeat();for(const[n,r]of this.subscriptions.entries())this.sendNow({v:1,type:"subscribe",id:n,topic:r.topic});for(;this.outboundQueue.length>0;){const n=this.outboundQueue.shift();n&&this.sendNow(n)}const t=hB();t&&this.sendNow({v:1,type:"command",id:mc(),command:{type:"push.identifyDevice",pushDeviceId:t}})}),this.ws.addEventListener("message",t=>{var s,o;this.lastMessageAt=Date.now();const n=performance.now(),r=String(t.data);let i;try{i=JSON.parse(r)}catch{return}if(sj()&&i.type==="snapshot"&&i.snapshot.type==="chat"&&((s=i.snapshot.data)==null?void 0:s.runtime.status)==="starting"&&console.debug("[kanna/send->starting][client-ws]",{stage:"socket_message_received",receivedAt:n,payloadBytes:r.length,chatId:i.snapshot.data.runtime.chatId,status:i.snapshot.data.runtime.status,messageCount:i.snapshot.data.messages.length}),sj()&&i.type==="ack"&&console.debug("[kanna/send->starting][client-ws]",{stage:"socket_ack_received",receivedAt:n,payloadBytes:r.length,commandId:i.id}),i.type==="snapshot"){const l=this.subscriptions.get(i.id);l==null||l.listener(i.snapshot.data);return}if(i.type==="event"){const l=this.subscriptions.get(i.id);(o=l==null?void 0:l.eventListener)==null||o.call(l,i.event);return}if(i.type==="ack"){const l=this.pending.get(i.id);if(!l)return;this.pending.delete(i.id),l.resolve(i.result);return}if(i.type==="error"){if(!i.id){console.error(jX,i.message);return}const l=this.pending.get(i.id);if(!l)return;this.pending.delete(i.id),l.reject(new Error(i.message))}}),this.ws.addEventListener("close",()=>{if(!this.started)return;const t=this.reconnectImmediatelyOnClose;this.reconnectImmediatelyOnClose=!1,this.stopHeartbeat(),this.clearPingState(),this.emitStatus("disconnected");for(const n of this.pending.values())n.reject(new Error("Disconnected"));if(this.pending.clear(),t){this.connect();return}this.scheduleReconnect()}))}scheduleReconnect(){this.reconnectTimer===null&&(this.reconnectTimer=window.setTimeout(()=>{this.reconnectTimer=null,this.connect(),this.reconnectDelayMs=Math.min(this.reconnectDelayMs*2,5e3)},this.reconnectDelayMs))}getStatus(){var t,n;return((t=this.ws)==null?void 0:t.readyState)===WebSocket.OPEN?"connected":((n=this.ws)==null?void 0:n.readyState)===WebSocket.CONNECTING?"connecting":"disconnected"}emitStatus(t){for(const n of this.statusListeners)n(t)}isConnectionStale(){const t=Math.max(this.lastMessageAt,this.lastOpenAt);return t>0&&Date.now()-t>=pbe}sendPing(){if(this.pingPromise)return this.pingPromise;const t=this.command({type:"system.ping"}).then(()=>{this.clearPingState()}).catch(n=>{throw this.clearPingState(),this.reconnectNow(),n});return this.pingTimeoutTimer=window.setTimeout(()=>{this.clearPingState(),this.reconnectNow()},gbe),this.pingPromise=t,t}reconnectNow(){if(this.reconnectTimer!==null&&(window.clearTimeout(this.reconnectTimer),this.reconnectTimer=null),!this.ws||this.ws.readyState===WebSocket.CLOSED){this.connect();return}this.ws.readyState!==WebSocket.CONNECTING&&(this.reconnectImmediatelyOnClose=!0,this.ws.close())}startHeartbeat(){document.visibilityState==="visible"&&this.heartbeatTimer===null&&(this.heartbeatTimer=window.setInterval(()=>{var t;if(document.visibilityState!=="visible"){this.stopHeartbeat();return}((t=this.ws)==null?void 0:t.readyState)===WebSocket.OPEN&&this.ensureHealthyConnection()},mbe))}stopHeartbeat(){this.heartbeatTimer!==null&&(window.clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}clearPingState(){this.pingTimeoutTimer!==null&&(window.clearTimeout(this.pingTimeoutTimer),this.pingTimeoutTimer=null),this.pingPromise=null}enqueue(t){var n;if(((n=this.ws)==null?void 0:n.readyState)===WebSocket.OPEN){this.sendNow(t);return}this.outboundQueue.push(t)}sendNow(t){var n;(n=this.ws)==null||n.send(JSON.stringify(t))}}async function bbe(e){const{toast:t}=await Y(async()=>{const{toast:r}=await import("./index-CFtYHyY0.js");return{toast:r}},[]);t(`${e} ${e===1?"process":"processes"} survived restart`,{description:"Review and stop them in Background tasks (⌘⇧B).",action:{label:"Review",onClick:()=>Vs.getState().openDialog()}})}function ybe(e,t){const n=new Set([...Object.keys(e),...Object.keys(t)]);for(const r of n)if(e[r]!==t[r])return!1;return!0}function _be(e,t){return e===t?!0:!e||!t?!1:e.chatId===t.chatId&&e.projectId===t.projectId&&e.localPath===t.localPath&&e.title===t.title&&e.status===t.status&&e.isDraining===t.isDraining&&e.provider===t.provider&&e.planMode===t.planMode&&ybe(e.sessionTokensByProvider,t.sessionTokensByProvider)}function xbe(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>{var i;return n._id===((i=t[r])==null?void 0:i._id)})}function Sbe(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>{var i;return n.id===((i=t[r])==null?void 0:i.id)})}function wbe(e,t){return e===t?!0:!e||!t?!1:e.hasOlder===t.hasOlder&&e.olderCursor===t.olderCursor&&e.recentLimit===t.recentLimit}function Cbe(e,t){return e.id===t.id&&e.content===t.content&&e.createdAt===t.createdAt&&e.provider===t.provider&&e.model===t.model&&e.planMode===t.planMode&&JSON.stringify(e.modelOptions)===JSON.stringify(t.modelOptions)&&kbe(e.attachments,t.attachments)}function kbe(e,t){return e===t?!0:e.length!==t.length?!1:e.every((n,r)=>{const i=t[r];return!!i&&n.id===i.id&&n.kind===i.kind&&n.displayName===i.displayName&&n.absolutePath===i.absolutePath&&n.relativePath===i.relativePath&&n.contentUrl===i.contentUrl&&n.mimeType===i.mimeType&&n.size===i.size})}function Ebe(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>Cbe(n,t[r]))}function Rbe(e,t){var s,o;if(e===t)return!0;if(!e||!t||e.status!==t.status||e.branchName!==t.branchName||e.defaultBranchName!==t.defaultBranchName||e.hasOriginRemote!==t.hasOriginRemote||e.originRepoSlug!==t.originRepoSlug||e.hasUpstream!==t.hasUpstream||e.aheadCount!==t.aheadCount||e.behindCount!==t.behindCount||e.lastFetchedAt!==t.lastFetchedAt)return!1;const n=((s=e.branchHistory)==null?void 0:s.entries)??[],r=((o=t.branchHistory)==null?void 0:o.entries)??[];return n.length!==r.length||!n.every((l,c)=>{const u=r[c];return!!u&&l.sha===u.sha&&l.summary===u.summary&&l.description===u.description&&l.authorName===u.authorName&&l.authoredAt===u.authoredAt&&l.githubUrl===u.githubUrl&&l.tags.length===u.tags.length&&l.tags.every((p,h)=>p===u.tags[h])})||e.files.length!==t.files.length?!1:e.files.every((l,c)=>{const u=t.files[c];return!!u&&l.path===u.path&&l.changeType===u.changeType&&l.isUntracked===u.isUntracked&&l.additions===u.additions&&l.deletions===u.deletions&&l.patchDigest===u.patchDigest&&l.mimeType===u.mimeType&&l.size===u.size})}function Tbe(e,t){return!!(e&&e.status!=="unknown"&&t&&t.status==="unknown"&&t.files.length===0)}function Abe(e,t){if(e===t)return!0;if(!e||!t)return!1;const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:n.every(i=>{const s=e[i],o=t[i];return!s||!o?!1:s.state===o.state&&s.scheduledAt===o.scheduledAt&&s.resetAt===o.resetAt&&s.detectedAt===o.detectedAt&&s.tz===o.tz})}function Nbe(e,t){if(e===t)return!0;if(!e||!t)return!1;const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:n.every(i=>{const s=e[i],o=t[i];return!s||!o?!1:s.state===o.state&&s.url===o.url&&s.error===o.error&&s.port===o.port&&s.activatedAt===o.activatedAt&&s.stoppedAt===o.stoppedAt})}function Mbe(e,t){return e===t?!0:!e||!t?!1:_be(e.runtime,t.runtime)&&Ebe(e.queuedMessages,t.queuedMessages)&&xbe(e.messages,t.messages)&&wbe(e.history,t.history)&&Sbe(e.availableProviders,t.availableProviders)&&Abe(e.schedules,t.schedules)&&e.liveScheduleId===t.liveScheduleId&&Nbe(e.tunnels,t.tunnels)&&e.liveTunnelId===t.liveTunnelId}function oj(e,t){const n=new Map;for(const r of e)n.set(r._id,r);for(const r of t)n.set(r._id,r);return[...n.values()]}function Lbe(e){for(let t=e.length-1;t>=0;t-=1){const n=e[t];if((n==null?void 0:n.kind)==="user_prompt"&&n.content.trim().length>0)return n.content}return null}const aj="__new_chat__",pB="lever-theme",mB="chat-sound-preferences",gB="terminal-preferences",vB="chat-preferences";function IS(e){if(typeof window>"u")return null;const t=window.localStorage.getItem(e);if(!t)return null;try{const n=JSON.parse(t);return n.state&&typeof n.state=="object"&&!Array.isArray(n.state)?n.state:null}catch{return null}}function Ibe(){if(typeof window>"u")return null;const e={},t=window.localStorage.getItem(pB);(t==="light"||t==="dark"||t==="system")&&(e.theme=t);const n=IS(mB);((n==null?void 0:n.chatSoundPreference)==="never"||(n==null?void 0:n.chatSoundPreference)==="unfocused"||(n==null?void 0:n.chatSoundPreference)==="always")&&(e.chatSoundPreference=n.chatSoundPreference),((n==null?void 0:n.chatSoundId)==="blow"||(n==null?void 0:n.chatSoundId)==="bottle"||(n==null?void 0:n.chatSoundId)==="frog"||(n==null?void 0:n.chatSoundId)==="funk"||(n==null?void 0:n.chatSoundId)==="glass"||(n==null?void 0:n.chatSoundId)==="ping"||(n==null?void 0:n.chatSoundId)==="pop"||(n==null?void 0:n.chatSoundId)==="purr"||(n==null?void 0:n.chatSoundId)==="tink")&&(e.chatSoundId=n.chatSoundId);const r=IS(gB);if(r){e.terminal={},typeof r.scrollbackLines=="number"&&(e.terminal.scrollbackLines=r.scrollbackLines),typeof r.minColumnWidth=="number"&&(e.terminal.minColumnWidth=r.minColumnWidth);const s={};(r.editorPreset==="cursor"||r.editorPreset==="vscode"||r.editorPreset==="xcode"||r.editorPreset==="windsurf"||r.editorPreset==="custom")&&(s.preset=r.editorPreset),typeof r.editorCommandTemplate=="string"&&(s.commandTemplate=r.editorCommandTemplate),Object.keys(s).length>0&&(e.editor=s)}const i=IS(vB);return((i==null?void 0:i.defaultProvider)==="last_used"||(i==null?void 0:i.defaultProvider)==="claude"||(i==null?void 0:i.defaultProvider)==="codex")&&(e.defaultProvider=i.defaultProvider),i!=null&&i.providerDefaults&&typeof i.providerDefaults=="object"&&(e.providerDefaults=i.providerDefaults),e.browserSettingsMigrated=!0,Object.keys(e).length>1?e:null}function jbe(){typeof window>"u"||(window.localStorage.removeItem(pB),window.localStorage.removeItem(mB),window.localStorage.removeItem(gB),window.localStorage.removeItem(vB))}function dh(e){Us.getState().setFromServer(e);const t=ui.getState();t.setScrollbackLines(e.terminal.scrollbackLines),t.setMinColumnWidth(e.terminal.minColumnWidth),t.setEditorPreset(e.editor.preset),t.setEditorCommandTemplate(e.editor.commandTemplate);const n=_c.getState();n.setChatSoundPreference(e.chatSoundPreference),n.setChatSoundId(e.chatSoundId),hi.setState({defaultProvider:e.defaultProvider,providerDefaults:e.providerDefaults})}function Dbe(e){return JSON.stringify({id:e.id,kind:e.kind,displayName:e.displayName,relativePath:e.relativePath,mimeType:e.mimeType,size:e.size,contentUrl:e.contentUrl})}function $E(e,t=[]){return JSON.stringify({content:e,attachments:t.map(Dbe)})}function Pbe(e,t){return e.reduce((n,r)=>r.kind!=="user_prompt"?n:n+($E(r.content,r.attachments??[])===t?1:0),0)}function Obe(e,t,n){const r=new Map;for(const i of n){if(i.kind!=="user_prompt")continue;const s=$E(i.content,i.attachments??[]);r.set(s,(r.get(s)??0)+1)}return e.filter(i=>i.scopeId!==t?!0:(r.get(i.signature)??0)<i.requiredMatchCount)}const zbe=200,Bbe=500;function lj(e,t){var r;const n=e.find(i=>i.chats.some(s=>s.chatId===t));return n?((r=n.chats.find(i=>i.chatId!==t))==null?void 0:r.chatId)??null:null}function cj(e,t){if(!(t!=null&&t.length)||e.length<=1)return e;const n=new Map(e.map((o,l)=>[o.groupKey,l])),r=new Set,i=t.map(o=>{if(r.has(o))return null;r.add(o);const l=n.get(o);return l===void 0?null:e[l]}).filter(o=>!!o);if(i.length===0)return e;const s=[...i,...e.filter(o=>!r.has(o.groupKey))];return s.every((o,l)=>o===e[l])?e:s}function Fbe(e=document){return e.visibilityState==="visible"&&e.hasFocus()}function $be(){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`}function Hbe(){const[e]=v.useState(()=>new vbe($be()));return v.useEffect(()=>(e.start(),()=>{e.dispose()}),[e]),e}const uj="kanna:profile-send-to-starting";function Ube(){try{return window.sessionStorage.getItem(uj)==="1"||window.localStorage.getItem(uj)==="1"}catch{return!1}}function bB(e){return Number((performance.now()-e).toFixed(1))}function rl(e,t,n){!e||!Ube()||console.debug("[kanna/send->starting][client]",{traceId:e.traceId,stage:t,elapsedMs:bB(e.startedAt),serverChatId:e.serverChatId,routeChatIdAtSend:e.routeChatIdAtSend,...n})}function Vbe(e){var t,n;return(e==null?void 0:e.provider)==="claude"&&e.model&&((t=e.modelOptions)!=null&&t.claude)?{provider:"claude",model:e.model,modelOptions:{reasoningEffort:e.modelOptions.claude.reasoningEffort??"high",contextWindow:e.modelOptions.claude.contextWindow??"200k"},planMode:!!e.planMode}:(e==null?void 0:e.provider)==="codex"&&e.model&&((n=e.modelOptions)!=null&&n.codex)?{provider:"codex",model:e.model,modelOptions:{reasoningEffort:e.modelOptions.codex.reasoningEffort??"high",fastMode:e.modelOptions.codex.fastMode??!1},planMode:!!e.planMode}:null}function Wbe(e,t){var n;return t?((n=e.find(r=>r.chats.some(i=>i.chatId===t)))==null?void 0:n.groupKey)??null:null}function Gbe(e,t){return e==="awaiting_disconnect"&&t==="disconnected"?"awaiting_server_ready":"none"}const qbe=30,HE="kanna:ui-update-restart",yB="kanna:last-update-reload-request";function Kbe(e){return e+qbe}function Ybe(e,t){return t>0?t:e}function dj(){return window.sessionStorage.getItem(HE)}function ev(e){window.sessionStorage.setItem(HE,e)}function fh(){window.sessionStorage.removeItem(HE)}function Xbe(e,t){return e?String(e)!==t:!1}function Qbe(){return window.sessionStorage.getItem(yB)}function Zbe(e){window.sessionStorage.setItem(yB,String(e))}function Jbe(){return"/auth/status"}function e0e(e,t,n="application/json"){const r=new Blob([t],{type:`${n}; charset=utf-8`}),i=URL.createObjectURL(r),s=document.createElement("a");s.href=i,s.download=e,s.style.display="none",document.body.append(s),s.click(),s.remove(),URL.revokeObjectURL(i)}async function t0e(e=fetch){return(await e(Jbe(),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}})).ok}function n0e(e){const t=e.selectedProjectId??e.sidebarProjectId??null;return t?{kind:"project_id",projectId:t}:e.fallbackLocalProjectPath?{kind:"local_path",localPath:e.fallbackLocalProjectPath}:null}function r0e(e,t){return!e||!t?null:e.runtime.chatId!==t?(e.runtime.chatId,e.runtime.provider,null):e}function i0e(e){var ff,$r,so;const t=$d(),n=Hbe(),r=Np(),{resolvedTheme:i}=BE(),[s,o]=v.useState({starredProjectGroups:[],projectGroups:[],stacks:[]}),[l,c]=v.useState(null),[u,p]=v.useState(null),[h,g]=v.useState(null),[b,_]=v.useState(null),[x,S]=v.useState([]),[C,E]=v.useState(!1),[k,T]=v.useState(null),[A,N]=v.useState(!1),[M,j]=v.useState({}),[U,I]=v.useState(null),[P,z]=v.useState(null),[O,$]=v.useState(null),[V,F]=v.useState(null),[H,W]=v.useState("connecting"),[Z,D]=v.useState(!1),[G,ee]=v.useState(!1),[B,le]=v.useState(!1),[oe,J]=v.useState(null),[ne,se]=v.useState(!1),[ce,de]=v.useState(!1),[Ne,we]=v.useState(!1),[je,fe]=v.useState(null),[ot,Mt]=v.useState(!1),[Et,Xt]=v.useState(null),[Dt,mt]=v.useState(!1),[yt,Wt]=v.useState(null),[Lt,gt]=v.useState(null),[Bt,ge]=v.useState([]),[ye,ze]=v.useState(null),[Xe,Me]=v.useState(0),Be=v.useRef(new Map),et=M1(JI(X=>Object.keys(X.drafts).sort())),We=M1(JI(X=>Object.keys(X.attachmentDrafts).sort())),qe=v.useRef(0),ft=v.useRef(null),rt=v.useRef({projectId:null,diffs:null}),Qt=vte(ui(X=>X.editorPreset)),lt=v.useMemo(()=>cj(s.projectGroups,l),[l,s.projectGroups]),Jt=v.useRef(lt);v.useLayoutEffect(()=>{Jt.current=lt});const dn=v.useMemo(()=>lt===s.projectGroups?s:{...s,projectGroups:lt},[s,lt]);v.useEffect(()=>n.onStatus(W),[n]),v.useEffect(()=>n.subscribe({type:"sidebar"},X=>{o(X),c(Q=>Q&&cj(X.projectGroups,Q)===X.projectGroups?null:Q),D(!0),fe(null)}),[n]),v.useEffect(()=>{if(H!=="connected")return;const X=[...new Set([...et,...We])].sort();n.command({type:"chat.setDraftProtection",chatIds:X}).catch(Q=>{fe(Q instanceof Error?Q.message:String(Q))})},[We,H,et,n]),v.useEffect(()=>n.subscribe({type:"local-projects"},X=>{p(X),ee(!0),fe(null)}),[n]),v.useEffect(()=>n.subscribe({type:"update"},X=>{g(X),fe(null)}),[n]),v.useEffect(()=>{H==="connected"&&n.command({type:"update.check",force:!0}).catch(X=>{fe(X instanceof Error?X.message:String(X))})},[H,n]),v.useEffect(()=>{const X=h==null?void 0:h.reloadRequestedAt;Xbe(X,Qbe())&&X&&(Zbe(X),ev("awaiting_disconnect"))},[h==null?void 0:h.reloadRequestedAt]),v.useEffect(()=>{const X=dj();if(Gbe(X,H)==="awaiting_server_ready"){ev("awaiting_server_ready");return}},[H]),v.useEffect(()=>{if(dj()!=="awaiting_server_ready")return;let X=!1,Q=null;const Ie=async()=>{try{if(await t0e()){if(X)return;fh(),window.location.reload();return}}catch{}X||(Q=window.setTimeout(()=>{Ie()},500))};return Ie(),()=>{X=!0,Q!==null&&window.clearTimeout(Q)}},[H]),v.useEffect(()=>{function X(){h!=null&&h.lastCheckedAt&&(Date.now()-h.lastCheckedAt<=3600*1e3||n.command({type:"update.check"}).catch(Q=>{fe(Q instanceof Error?Q.message:String(Q))}))}return window.addEventListener("focus",X),()=>{window.removeEventListener("focus",X)}},[n,h==null?void 0:h.lastCheckedAt]),v.useEffect(()=>n.subscribe({type:"keybindings"},X=>{I(X),fe(null)}),[n]),v.useEffect(()=>n.subscribe({type:"app-settings"},X=>{z(X),dh(X),fe(null)}),[n]),v.useEffect(()=>n.subscribe({type:"push-config"},X=>{$(X)}),[n]),v.useEffect(()=>{let X=!1;return n.subscribe({type:"bg-tasks"},Q=>{Vs.getState().applySnapshot(Q.tasks),!X&&Q.orphanRecoveryCount!=null&&Q.orphanRecoveryCount>0&&(X=!0,bbe(Q.orphanRecoveryCount))},Q=>{Q.type==="bg-tasks.added"?Vs.getState().applyDiff({op:"added",task:Q.task}):Q.type==="bg-tasks.updated"?Vs.getState().applyDiff({op:"updated",task:Q.task}):Q.type==="bg-tasks.removed"&&Vs.getState().applyDiff({op:"removed",task:Q.task})})},[n]);const At=v.useCallback(async()=>{try{Us.getState().setHydrationStatus("loading");const X=await n.command({type:"settings.readAppSettings"});z(X),dh(X),fe(null)}catch(X){Us.getState().setHydrationStatus("error"),fe(X instanceof Error?X.message:String(X))}},[n]),Rt=v.useCallback(async X=>{try{Us.getState().applyOptimisticPatch(X);const Q=await n.command({type:"settings.writeAppSettingsPatch",patch:X});z(Q),dh(Q),fe(null)}catch(Q){throw fe(Q instanceof Error?Q.message:String(Q)),await At(),Q}},[At,n]),Ct=v.useCallback(async X=>{try{Us.getState().applyOptimisticPatch({cloudflareTunnel:X});const Q=await n.command({type:"appSettings.setCloudflareTunnel",patch:X});z(Q),dh(Q),fe(null)}catch(Q){throw fe(Q instanceof Error?Q.message:String(Q)),await At(),Q}},[At,n]),Ue=v.useCallback(async X=>{try{Us.getState().applyOptimisticPatch({claudeAuth:X});const Q=await n.command({type:"appSettings.setClaudeAuth",patch:X});z(Q),dh(Q),fe(null)}catch(Q){throw fe(Q instanceof Error?Q.message:String(Q)),await At(),Q}},[At,n]),vt=v.useCallback(async X=>await n.command({type:"appSettings.testOAuthToken",token:X}),[n]),ht=v.useCallback(async()=>{try{const X=await n.command({type:"settings.readLlmProvider"});F(X),fe(null)}catch(X){fe(X instanceof Error?X.message:String(X))}},[n]),Ot=v.useCallback(async X=>{try{const Q=await n.command({type:"settings.writeLlmProvider",provider:X.provider,apiKey:X.apiKey,model:X.model,baseUrl:X.baseUrl});F(Q),fe(null)}catch(Q){throw fe(Q instanceof Error?Q.message:String(Q)),Q}},[n]),Ft=v.useCallback(async X=>await n.command({type:"settings.validateLlmProvider",provider:X.provider,apiKey:X.apiKey,model:X.model,baseUrl:X.baseUrl}),[n]);v.useEffect(()=>{H==="connected"&&At()},[H,At]),v.useEffect(()=>{if(H!=="connected"||(P==null?void 0:P.browserSettingsMigrated)!==!1)return;const X=Ibe();X&&Rt(X).then(jbe).catch(()=>{})},[P==null?void 0:P.browserSettingsMigrated,H,Rt]),v.useEffect(()=>{H==="connected"&&ht()},[H,ht]),v.useEffect(()=>{function X(){Me(Q=>Q+1)}return window.addEventListener("focus",X),document.addEventListener("visibilitychange",X),()=>{window.removeEventListener("focus",X),document.removeEventListener("visibilitychange",X)}},[]),v.useEffect(()=>{if(!e){_(null),le(!0);return}++qe.current,Jt.current.length,Jt.current.reduce((Q,Ie)=>Q+Ie.chats.length,0),_(null),le(!1);const X=n.subscribe({type:"chat",chatId:e,recentLimit:zbe},Q=>{if(Q!=null&&Q.runtime.chatId){const Ie=[...Be.current.values()].filter(_t=>_t.serverChatId===Q.runtime.chatId).sort((_t,Vn)=>Vn.startedAt-_t.startedAt)[0];Ie&&Ie.snapshotAt===void 0&&(Ie.snapshotAt=performance.now(),rl(Ie,"chat_snapshot_received",{status:Q.runtime.status,messageCount:Q.messages.length}))}if(_(Ie=>{const _t=Mbe(Ie,Q);return Q==null||Q.runtime.chatId,Q==null||Q.runtime.provider,Q==null||Q.runtime.status,Q==null||Q.messages.length,_t?Ie:Q}),T((Q==null?void 0:Q.history.olderCursor)??null),N((Q==null?void 0:Q.history.hasOlder)??!1),le(!0),fe(null),Q){const Ie=zE.getState();Ie.setForChat(Q.runtime.chatId,Q.slashCommands??[]),Ie.setLoadingForChat(Q.runtime.chatId,Q.slashCommandsLoading??!1)}});return()=>{Jt.current.length,Jt.current.reduce((Q,Ie)=>Q+Ie.chats.length,0),X()}},[e,n]),v.useEffect(()=>{if(oe)return;const X=lt[0];X&&J(X.groupKey)},[oe,lt]),v.useEffect(()=>{if(!e||!Z||!B)return;if(lt.some(Q=>Q.chats.some(Ie=>Ie.chatId===e))){Lt===e&>(null);return}Lt!==e&&t("/")},[e,B,t,Lt,lt,Z]),v.useEffect(()=>{b&&(J(b.runtime.projectId),Lt===b.runtime.chatId&>(null))},[b,Lt]),v.useEffect(()=>{if(!e||!Z||!Fbe())return;const X=lt.flatMap(Q=>Q.chats).find(Q=>Q.chatId===e);X!=null&&X.unread&&n.command({type:"chat.markRead",chatId:e}).catch(Q=>{fe(Q instanceof Error?Q.message:String(Q))})},[e,Xe,lt,Z,n]),v.useEffect(()=>{S([]),E(!1),T(null),N(!1)},[e]);const xe=v.useMemo(()=>r0e(b,e),[e,b]),Ge=v.useMemo(()=>(xe==null?void 0:xe.runtime.projectId)??Wbe(lt,e)??oe,[e,xe==null?void 0:xe.runtime.projectId,oe,lt]),it=v.useMemo(()=>{const X=Ge?M[Ge]??null:null;return Ge&&X?(rt.current={projectId:Ge,diffs:X},X):Ge&&rt.current.projectId===Ge?rt.current.diffs:X},[Ge,M]);v.useEffect(()=>Ge?n.subscribe({type:"project-git",projectId:Ge},Q=>{j(Ie=>{const _t=Q??null;return Tbe(Ie[Ge]??null,_t)||Rbe(Ie[Ge]??null,_t)?Ie:{...Ie,[Ge]:_t}}),fe(null)}):void 0,[Ge,n]),v.useEffect(()=>{b==null||b.runtime.chatId,b==null||b.runtime.provider,xe==null||xe.runtime.chatId,xe==null||xe.runtime.provider},[e,xe,b,Lt]);const Je=v.useMemo(()=>oj(x,(xe==null?void 0:xe.messages)??[]),[xe==null?void 0:xe.messages,x]),Se=e??aj,nt=v.useMemo(()=>Bt.filter(X=>X.scopeId===Se).map(X=>X.entry),[Se,Bt]),Ye=v.useMemo(()=>[...Je,...nt],[nt,Je]),De=v.useMemo(()=>fB(Ye),[Ye]),It=v.useMemo(()=>Lbe(De),[De]),an=v.useMemo(()=>rbe(De),[De]),Fe=(xe==null?void 0:xe.runtime)??null,Vt=(xe==null?void 0:xe.queuedMessages)??[],qn=((ye==null?void 0:ye.scopeId)===Se&&(!Fe||Fe.status==="idle")?"starting":null)??(Fe==null?void 0:Fe.status)??null,K=(xe==null?void 0:xe.availableProviders)??jh,be=sbe(qn??void 0),Le=ibe(qn??void 0),Pe=(Fe==null?void 0:Fe.isDraining)??!1,ut=((ff=u==null?void 0:u.projects[0])==null?void 0:ff.localPath)??null,Qe=(Fe==null?void 0:Fe.localPath)??ut??(($r=lt[0])==null?void 0:$r.localPath),Nt=!!(oe??(Fe==null?void 0:Fe.projectId)??((so=lt[0])==null?void 0:so.groupKey)??ut);v.useEffect(()=>{(ye==null?void 0:ye.scopeId)===Se&&Fe!=null&&Fe.status&&Fe.status!=="idle"&&ze(null)},[ye,Se,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!(ye!=null&&ye.ackedAt)||ye.scopeId!==Se||Fe!=null&&Fe.status&&Fe.status!=="idle")return;const X=window.setTimeout(()=>{ze(Q=>(Q==null?void 0:Q.scopeId)===Se&&Q.ackedAt===ye.ackedAt?null:Q)},300);return()=>window.clearTimeout(X)},[ye,Se,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!e||(Fe==null?void 0:Fe.status)!=="starting")return;const X=[...Be.current.values()].filter(Q=>Q.serverChatId===e).sort((Q,Ie)=>Ie.startedAt-Q.startedAt)[0];!X||X.startingStatusAt!==void 0||(X.startingStatusAt=performance.now(),rl(X,"runtime_status_starting",{status:Fe.status}))},[e,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!e||!Fe||Fe.status==="starting")return;const X=[...Be.current.values()].filter(Q=>Q.serverChatId===e).sort((Q,Ie)=>Ie.startedAt-Q.startedAt)[0];!X||X.startingRenderedAt!==void 0||(rl(X,"starting_not_observed",{status:Fe.status}),Be.current.delete(X.traceId))},[e,Fe]),v.useLayoutEffect(()=>{if(!e||(Fe==null?void 0:Fe.status)!=="starting"){ft.current=null;return}const X=[...Be.current.values()].filter(Q=>Q.serverChatId===e).sort((Q,Ie)=>Ie.startedAt-Q.startedAt)[0];X&&ft.current!==X.traceId&&(ft.current=X.traceId,X.startingRenderedAt=performance.now(),rl(X,"starting_render_committed",{totalMs:bB(X.startedAt)}),Be.current.delete(X.traceId))},[e,Fe==null?void 0:Fe.status]),v.useEffect(()=>{ge(X=>{const Q=Obe(X,Se,Je);return Q.length===X.length&&Q.every((Ie,_t)=>Ie===X[_t])?X:Q})},[Se,Je]);const Zt=v.useCallback(async()=>{if(!(!e||!k||C||!A)){E(!0);try{const X=await n.command({type:"chat.loadHistory",chatId:e,beforeCursor:k,limit:Bbe});S(Q=>oj(X.messages,Q)),T(X.olderCursor),N(X.hasOlder),fe(null)}catch(X){const Q=X instanceof Error?X.message:String(X);fe(Q)}finally{E(!1)}}},[e,A,k,C,n]),fn=v.useCallback(async X=>{const Q=hi.getState(),Ie=e?Q.getComposerState(e):Q.getComposerState(Mv),_t=await n.command({type:"chat.create",projectId:X});Q.initializeComposerForChat(_t.chatId,{sourceState:Ie}),J(X),gt(_t.chatId),t(`/chat/${_t.chatId}`),se(!1),fe(null)},[e,t,n]),hn=v.useCallback(async X=>X.kind==="project_id"?{projectId:X.projectId}:X.kind==="local_path"?{projectId:(await n.command({type:"project.open",localPath:X.localPath})).projectId,localPath:X.localPath}:{projectId:(await n.command(X.project.mode==="new"?{type:"project.create",localPath:X.project.localPath,title:X.project.title}:{type:"project.open",localPath:X.project.localPath})).projectId,localPath:X.project.localPath},[n]),sr=v.useCallback(async X=>{try{const Q=X.kind==="project_id"?null:X.kind==="local_path"?X.localPath:X.project.localPath;Q&&Wt(Q);const{projectId:Ie}=await hn(X);await fn(Ie)}catch(Q){fe(Q instanceof Error?Q.message:String(Q))}finally{Wt(null)}},[fn,hn]),_i=v.useCallback(async X=>{await sr({kind:"project_id",projectId:X})},[sr]),Rr=v.useCallback(async X=>{try{const Q=await n.command({type:"chat.fork",chatId:X.chatId}),Ie=hi.getState();Ie.initializeComposerForChat(Q.chatId,{sourceState:Ie.getComposerState(X.chatId)}),gt(Q.chatId),t(`/chat/${Q.chatId}`),se(!1),fe(null)}catch(Q){fe(Q instanceof Error?Q.message:String(Q))}},[t,n]),oi=v.useCallback(async X=>{await sr({kind:"local_path",localPath:X})},[sr]),Zi=v.useCallback(async X=>{await sr({kind:"project_request",project:X})},[sr]),xi=v.useCallback(async X=>{try{await n.command({type:"update.check",force:X==null?void 0:X.force}),fe(null)}catch(Q){fe(Q instanceof Error?Q.message:String(Q))}},[n]),Ji=v.useCallback(async()=>{try{const X=await n.command({type:"update.install"});if(!X.ok){fh(),fe(null),await r.alert({title:X.userTitle??"Update failed",description:X.userMessage??"Kanna could not install the update. Try again later.",closeLabel:"OK"});return}if(X.ok&&X.action==="reload"){window.location.reload();return}X.ok&&X.action==="restart"&&ev("awaiting_disconnect"),fe(null)}catch(X){fh(),fe(X instanceof Error?X.message:String(X))}},[r,n]),Di=v.useCallback(async()=>{try{const X=await n.command({type:"update.reload"});if(!X.ok){fh(),fe(null),await r.alert({title:X.userTitle??"Re-deploy failed",description:X.userMessage??"Kanna could not re-deploy. Try again later.",closeLabel:"OK"});return}if(X.action==="reload"){window.location.reload();return}ev("awaiting_disconnect"),fe(null)}catch(X){fh(),fe(X instanceof Error?X.message:String(X))}},[r,n]),kt=v.useCallback(async()=>{try{const X=await fetch("/auth/logout",{method:"POST",headers:{Accept:"application/json"}});if(!X.ok)throw new Error(`Sign out failed with status ${X.status}`);fe(null),window.location.reload()}catch(X){fe(X instanceof Error?X.message:String(X))}},[]),ln=v.useCallback(async(X,Q)=>{var am;const Ie=(Q==null?void 0:Q.attachments)??[];if(e&&be)try{const Ln=Db.getState().autoResumeOnRateLimit;await n.command({type:"message.enqueue",chatId:e,content:X,attachments:Ie,provider:Q==null?void 0:Q.provider,model:Q==null?void 0:Q.model,modelOptions:Q==null?void 0:Q.modelOptions,planMode:Q==null?void 0:Q.planMode,autoResumeOnRateLimit:Ln}),fe(null);return}catch(Ln){throw fe(Ln instanceof Error?Ln.message:String(Ln)),Ln}const _t=mc(),Vn=mc(),Hr=$E(X,Ie),oo=e??aj;ze({scopeId:oo,ackedAt:null});const ts={traceId:Vn,optimisticId:_t,startedAt:performance.now(),serverChatId:e,routeChatIdAtSend:e,contentPreview:X.slice(0,80)};Be.current.set(Vn,ts),rl(ts,"handle_send_called",{optimisticScopeId:oo,attachments:Ie.length,contentLength:X.length,contentPreview:ts.contentPreview});const uy=Pbe(Je,Hr)+Bt.filter(Ln=>Ln.scopeId===oo&&Ln.signature===Hr).length+1;ge(Ln=>[...Ln,{id:_t,scopeId:oo,signature:Hr,requiredMatchCount:uy,entry:{_id:`optimistic:${_t}`,kind:"user_prompt",content:X,attachments:Ie,createdAt:Date.now()}}]),rl(ts,"optimistic_prompt_added",{optimisticId:_t,optimisticScopeId:oo});try{let Ln=oe??((am=lt[0])==null?void 0:am.groupKey)??null;if(!e&&!Ln&&ut&&(Ln=(await n.command({type:"project.open",localPath:ut})).projectId,J(Ln)),!e&&!Ln)throw new Error("Open a project first");const Ul=Db.getState().autoResumeOnRateLimit,Pi=await n.command({type:"chat.send",chatId:e??void 0,projectId:e?void 0:Ln??void 0,clientTraceId:Vn,provider:Q==null?void 0:Q.provider,content:X,attachments:Ie,model:Q==null?void 0:Q.model,modelOptions:Q==null?void 0:Q.modelOptions,planMode:Q==null?void 0:Q.planMode,autoResumeOnRateLimit:Ul});if(ts.ackAt=performance.now(),ts.serverChatId=Pi.chatId??ts.serverChatId,ze(Po=>Po&&{scopeId:!e&&Pi.chatId?Pi.chatId:Po.scopeId,ackedAt:performance.now()}),rl(ts,"chat_send_ack_received",{resultChatId:Pi.chatId??null}),!e&&Pi.chatId){ge(lm=>lm.map(hf=>hf.id===_t?{...hf,scopeId:Pi.chatId}:hf));const Po=hi.getState();Po.setComposerState(Pi.chatId,Vbe(Q)??Po.getComposerState(Mv)),gt(Pi.chatId),t(`/chat/${Pi.chatId}`)}fe(null)}catch(Ln){throw ge(Ul=>Ul.filter(Pi=>Pi.id!==_t)),ze(null),rl(ts,"handle_send_failed",{error:Ln instanceof Error?Ln.message:String(Ln)}),Be.current.delete(Vn),fe(Ln instanceof Error?Ln.message:String(Ln)),Ln}},[e,ut,be,t,Bt,oe,Je,lt,n]),En=v.useCallback(async X=>{if(e)try{await n.command({type:"message.steer",chatId:e,queuedMessageId:X}),fe(null)}catch(Q){fe(Q instanceof Error?Q.message:String(Q))}},[e,n]),pn=v.useCallback(async X=>{if(e)try{await n.command({type:"message.dequeue",chatId:e,queuedMessageId:X}),fe(null)}catch(Q){fe(Q instanceof Error?Q.message:String(Q))}},[e,n]),As=v.useCallback(async()=>{if(e)try{await n.command({type:"chat.cancel",chatId:e})}catch(X){fe(X instanceof Error?X.message:String(X))}},[e,n]),Do=v.useCallback(async()=>{if(e)try{await n.command({type:"chat.stopDraining",chatId:e})}catch(X){fe(X instanceof Error?X.message:String(X))}},[e,n]),Ns=v.useCallback(async X=>{const Q=await r.prompt({title:"Rename Chat",initialValue:X.title,confirmLabel:"Rename"});if(!(!Q||Q===X.title))try{await n.command({type:"chat.rename",chatId:X.chatId,title:Q}),fe(null)}catch(Ie){fe(Ie instanceof Error?Ie.message:String(Ie))}},[r,n]),te=v.useCallback(async X=>{if(await r.confirm({title:"Delete Chat",description:`Delete "${X.title}"? This cannot be undone.`,confirmLabel:"Delete",confirmVariant:"destructive"}))try{if(await n.command({type:"chat.delete",chatId:X.chatId}),X.chatId===e){const Ie=lj(lt,X.chatId);t(Ie?`/chat/${Ie}`:"/")}}catch(Ie){fe(Ie instanceof Error?Ie.message:String(Ie))}},[e,r,t,lt,n]),Oe=v.useCallback(async X=>{try{if(await n.command({type:"chat.archive",chatId:X.chatId}),X.chatId===e){const Q=lj(lt,X.chatId);t(Q?`/chat/${Q}`:"/")}fe(null)}catch(Q){fe(Q instanceof Error?Q.message:String(Q))}},[e,t,lt,n]),Sn=v.useCallback(async X=>{try{gt(X),await n.command({type:"chat.unarchive",chatId:X}),t(`/chat/${X}`),fe(null)}catch(Q){gt(null),fe(Q instanceof Error?Q.message:String(Q))}},[t,n]),or=v.useCallback(async X=>{try{await n.command({type:"project.remove",projectId:X}),ul.getState().clearProject(X),Ni.getState().clearProject(X),(Fe==null?void 0:Fe.projectId)===X&&t("/"),fe(null)}catch(Q){fe(Q instanceof Error?Q.message:String(Q))}},[t,Fe,n]),Ae=v.useCallback(async(X,Q)=>{try{await n.command({type:"project.setStar",projectId:X,starred:Q}),fe(null)}catch(Ie){fe(Ie instanceof Error?Ie.message:String(Ie))}},[n]),Ve=v.useCallback(async X=>{c(X);try{await n.command({type:"sidebar.reorderProjectGroups",projectIds:X}),fe(null)}catch(Q){c(null),fe(Q instanceof Error?Q.message:String(Q))}},[n]),$t=v.useCallback(async(X,Q)=>{try{await n.command({type:"stack.create",title:X,projectIds:Q}),fe(null)}catch(Ie){fe(Ie instanceof Error?Ie.message:String(Ie))}},[n]),ar=v.useCallback(async(X,Q)=>{try{await n.command({type:"stack.rename",stackId:X,title:Q}),fe(null)}catch(Ie){fe(Ie instanceof Error?Ie.message:String(Ie))}},[n]),es=v.useCallback(async X=>{try{await n.command({type:"stack.remove",stackId:X}),fe(null)}catch(Q){fe(Q instanceof Error?Q.message:String(Q))}},[n]),Bl=v.useCallback(async(X,Q)=>{try{await n.command({type:"stack.addProject",stackId:X,projectId:Q}),fe(null)}catch(Ie){fe(Ie instanceof Error?Ie.message:String(Ie))}},[n]),Ta=v.useCallback(async(X,Q)=>{try{await n.command({type:"stack.removeProject",stackId:X,projectId:Q}),fe(null)}catch(Ie){fe(Ie instanceof Error?Ie.message:String(Ie))}},[n]),ay=v.useCallback(async(X,Q,Ie)=>{try{const _t=hi.getState(),Vn=e?_t.getComposerState(e):_t.getComposerState(Mv),Hr=await n.command({type:"chat.create",projectId:X,stackId:Q,stackBindings:Ie});_t.initializeComposerForChat(Hr.chatId,{sourceState:Vn}),J(X),gt(Hr.chatId),t(`/chat/${Hr.chatId}`),se(!1),fe(null)}catch(_t){fe(_t instanceof Error?_t.message:String(_t))}},[e,t,n]),nm=v.useCallback(async X=>{try{const Q=await n.command({type:"stack.listWorktrees",projectId:X});return fe(null),Q.worktrees}catch(Q){return fe(Q instanceof Error?Q.message:String(Q)),[]}},[n]),rm=v.useCallback(async()=>await n.command({type:"sessions.importClaude"}),[n]),ro=v.useCallback(async X=>{const Q=ui.getState();fe(null),await n.command({type:"system.openExternal",...X,editor:X.action==="open_editor"?X.editor??{preset:Q.editorPreset,commandTemplate:Q.editorCommandTemplate}:void 0})},[n]),ly=v.useCallback(async(X,Q)=>{var _t,Vn;const Ie=(Fe==null?void 0:Fe.localPath)??((_t=u==null?void 0:u.projects[0])==null?void 0:_t.localPath)??((Vn=lt[0])==null?void 0:Vn.localPath);if(Ie)try{await ro({action:X,localPath:Ie,editor:Q})}catch(Hr){fe(Hr instanceof Error?Hr.message:String(Hr))}},[u==null?void 0:u.projects,ro,Fe==null?void 0:Fe.localPath,lt]),cy=v.useCallback(async X=>{var Q;try{if(typeof navigator>"u"||!((Q=navigator.clipboard)!=null&&Q.writeText))throw new Error("Clipboard is not available");await navigator.clipboard.writeText(X),fe(null)}catch(Ie){fe(Ie instanceof Error?Ie.message:String(Ie))}},[]),iu=v.useCallback(async(X,Q="open_editor",Ie)=>{try{await ro({action:Q,localPath:X.path,line:X.line,column:X.column,editor:Ie})}catch(_t){fe(_t instanceof Error?_t.message:String(_t))}},[ro]),Ms=v.useCallback(async(X,Q)=>{try{await ro({action:X,localPath:Q})}catch(Ie){fe(Ie instanceof Error?Ie.message:String(Ie))}},[ro]),Fl=v.useCallback(async(X=e)=>{if(!X||ot)return null;Mt(!0);try{const Q=await n.command({type:"chat.exportStandalone",chatId:X,theme:i,attachmentMode:"bundle"});return fe(null),Q}catch(Q){return fe(Q instanceof Error?Q.message:String(Q)),null}finally{Mt(!1)}},[e,ot,i,n]),lf=v.useCallback(async(X=e)=>{if(!X||ot)return;mt(!1);const Q=await Fl(X);if(Q!=null&&Q.ok&&Q.shareUrl){Xt(Q.shareUrl),mt(!0);return}Q&&!Q.ok&&await r.confirm({title:"Share failed",description:Q.error,confirmLabel:"Download transcript JSON",cancelLabel:"Close",confirmVariant:"secondary"})&&e0e(Q.transcriptFileName,Q.transcriptJson)},[e,r,Fl,ot]),Aa=v.useCallback(()=>{Xt(null),mt(!1)},[]),Na=v.useCallback(async()=>{var X;if(!Et)return!1;try{if(typeof navigator>"u"||!((X=navigator.clipboard)!=null&&X.writeText))throw new Error("Clipboard is not available");return await navigator.clipboard.writeText(Et),!0}catch(Q){return await r.alert({title:"Copy failed",description:Q instanceof Error?Q.message:String(Q),closeLabel:"Close"}),!1}},[r,Et]),im=v.useCallback(()=>{Et&&(window.open(Et,"_blank","noopener,noreferrer"),Xt(null))},[Et]),cf=v.useCallback(()=>{var Q;const X=n0e({selectedProjectId:oe,sidebarProjectId:(Q=lt[0])==null?void 0:Q.groupKey,fallbackLocalProjectPath:ut});if(X){sr(X);return}t("/")},[ut,t,oe,lt,sr]),sm=v.useCallback(()=>se(!0),[]),$l=v.useCallback(()=>se(!1),[]),Ls=v.useCallback(()=>de(!0),[]),uf=v.useCallback(()=>de(!1),[]),Hl=v.useCallback(()=>we(!0),[]),io=v.useCallback(()=>we(!1),[]),df=v.useCallback(async(X,Q,Ie)=>{if(e)try{await n.command({type:"chat.respondTool",chatId:e,toolUseId:X,result:{questions:Q,answers:Ie}})}catch(_t){fe(_t instanceof Error?_t.message:String(_t))}},[e,n]),su=v.useCallback(async(X,Q,Ie,_t)=>{if(e){Q&&hi.getState().setChatComposerPlanMode(e,!1);try{await n.command({type:"chat.respondTool",chatId:e,toolUseId:X,result:{confirmed:Q,...Ie?{clearContext:!0}:{},..._t?{message:_t}:{}}})}catch(Vn){fe(Vn instanceof Error?Vn.message:String(Vn))}}},[e,n]),om=v.useCallback(async(X,Q,Ie,_t)=>{if(e)try{await n.command({type:"chat.respondSubagentTool",chatId:e,runId:X,toolUseId:Q,result:{questions:Ie,answers:_t}})}catch(Vn){fe(Vn instanceof Error?Vn.message:String(Vn))}},[e,n]),ou=v.useCallback(async(X,Q,Ie)=>{if(e)try{await n.command({type:"chat.respondSubagentTool",chatId:e,runId:X,toolUseId:Q,result:Ie})}catch(_t){fe(_t instanceof Error?_t.message:String(_t))}},[e,n]),au=v.useCallback(async(X,Q)=>{if(e)try{await n.command({type:"chat.toolRequestAnswer",chatId:e,toolRequestId:X,decision:Q})}catch(Ie){fe(Ie instanceof Error?Ie.message:String(Ie))}},[e,n]);return{socket:n,activeChatId:e,activeProjectId:Ge,sidebarData:dn,localProjects:u,updateSnapshot:h,chatSnapshot:b,chatDiffSnapshot:it,keybindings:U,appSettings:P,pushConfig:O,llmProvider:V,connectionStatus:H,sidebarReady:Z,localProjectsReady:G,commandError:je,startingLocalPath:yt,sidebarOpen:ne,sidebarCollapsed:ce,messages:De,queuedMessages:Vt,previousPrompt:It,latestToolIds:an,runtime:Fe,runtimeStatus:qn,isHistoryLoading:C,hasOlderHistory:A,availableProviders:K,isProcessing:be,canCancel:Le,isDraining:Pe,isExportingStandalone:ot,standaloneShareUrl:Et,standaloneShareComplete:Dt,navbarLocalPath:Qe,editorLabel:Qt,hasSelectedProject:Nt,addProjectModalOpen:Ne,openSidebar:sm,closeSidebar:$l,collapseSidebar:Ls,expandSidebar:uf,openAddProjectModal:Hl,closeAddProjectModal:io,loadOlderHistory:Zt,handleCreateChat:_i,handleForkChat:Rr,handleOpenLocalProject:oi,handleCreateProject:Zi,handleCheckForUpdates:xi,handleInstallUpdate:Ji,handleForceReload:Di,handleReadAppSettings:At,handleWriteAppSettings:Rt,handleWriteCloudflareTunnel:Ct,handleWriteClaudeAuth:Ue,handleTestOAuthToken:vt,handleReadLlmProvider:ht,handleWriteLlmProvider:Ot,handleValidateLlmProvider:Ft,handleSignOut:kt,handleSend:ln,handleSteerQueuedMessage:En,handleRemoveQueuedMessage:pn,handleCancel:As,handleStopDraining:Do,handleRenameChat:Ns,handleShareChat:lf,handleArchiveChat:Oe,handleOpenArchivedChat:Sn,handleDeleteChat:te,handleHideProject:or,handleToggleProjectStar:Ae,handleReorderProjectGroups:Ve,stacks:dn.stacks,handleCreateStack:$t,handleRenameStack:ar,handleRemoveStack:es,handleAddProjectToStack:Bl,handleRemoveProjectFromStack:Ta,handleCreateStackChat:ay,handleListStackWorktrees:nm,importClaudeSessions:rm,handleCopyPath:cy,handleOpenExternal:ly,handleOpenExternalPath:Ms,handleOpenLocalLink:iu,handleCompose:cf,handleAskUserQuestion:df,handleExitPlanMode:su,handleSubagentAskUserQuestion:om,handleSubagentExitPlanMode:ou,handleExportStandalone:Fl,handleCloseStandaloneShareDialog:Aa,handleOpenStandaloneShareLink:im,handleCopyStandaloneShareLink:Na,handleToolRequestAnswer:au}}function _B({message:e}){return f.jsx("div",{className:"text-pretty prose prose-sm dark:prose-invert px-0.5 w-full max-w-[70ch] space-y-4",children:f.jsx(Xc,{remarkPlugins:[Qc],components:sf(),children:e.text})})}const Xp=({children:e,className:t,animate:n=!0,shimmerWidth:r,...i})=>f.jsx("span",{className:he("mx-auto max-w-md text-foreground/60",n&&"animate-shiny-pulse",t),...i,children:e});function fj(e){return(e&&typeof e=="object"&&"content"in e&&Array.isArray(e.content)?e.content:Array.isArray(e)?e:[]).flatMap(n=>!n||typeof n!="object"||!("type"in n)||n.type!=="image"?[]:"data"in n&&typeof n.data=="string"?[{type:"image",data:n.data,mimeType:typeof n.mimeType=="string"?n.mimeType:void 0}]:"source"in n&&n.source&&typeof n.source=="object"&&"type"in n.source&&n.source.type==="base64"&&"data"in n.source&&typeof n.source.data=="string"?[{type:"image",data:n.source.data,mimeType:typeof n.source.media_type=="string"?n.source.media_type:void 0}]:[])}function s0e({images:e}){return f.jsx("div",{className:"flex flex-col gap-3",children:e.map((t,n)=>{const r=t.mimeType||"image/png";return f.jsx("div",{className:"overflow-hidden rounded-lg border border-border bg-muted/20",children:f.jsx("img",{src:`data:${r};base64,${t.data}`,alt:`Read result ${n+1}`,className:"max-h-[50vh] w-full object-contain bg-background"})},`${r}:${n}`)})})}function Pb({message:e,isLoading:t=!1,localPath:n}){var S;const r=e.result!==void 0,i=!r&&t,s=v.useMemo(()=>{if(e.toolKind==="skill")return e.input.skill;if(e.toolKind==="glob")return`Search files ${e.input.pattern==="**/*"?"in all directories":`matching ${e.input.pattern}`}`;if(e.toolKind==="grep"){const C=e.input.pattern,E=e.input.outputMode;return E==="count"?`Count \`${C}\` occurrences`:E==="content"?`Find \`${C}\` in text`:`Find \`${C}\` in files`}return e.toolKind==="bash"?e.input.description||(e.input.command?eQ(e.input.command):"Bash"):e.toolKind==="web_search"?e.input.query||"Web Search":e.toolKind==="read_file"?`Read ${Vg(e.input.filePath,n)}`:e.toolKind==="write_file"?`Write ${Vg(e.input.filePath,n)}`:e.toolKind==="edit_file"?`Edit ${Vg(e.input.filePath,n)}`:e.toolKind==="delete_file"?`Delete ${Vg(e.input.filePath,n)}`:e.toolKind==="mcp_generic"?`${_w(e.input.tool)} from ${_w(e.input.server)}`:e.toolKind==="subagent_task"&&e.input.subagentType||e.toolName},[e.input,e.toolKind,e.toolName,n]),o=v.useMemo(()=>e.toolKind==="subagent_task",[e.toolKind]),l=v.useMemo(()=>{if(e.toolKind==="skill")return e.input.skill},[e.input,e.toolKind]),c=e.toolKind==="bash",u=e.toolKind==="write_file",p=e.toolKind==="edit_file",h=e.toolKind==="delete_file",g=e.toolKind==="read_file",b=v.useMemo(()=>{if(typeof e.result=="string")return e.result;if(!e.result)return"";if(typeof e.result=="object"&&e.result!==null&&"content"in e.result){const C=e.result.content;if(typeof C=="string")return C}return JSON.stringify(e.result,null,2)},[e.result]),_=v.useMemo(()=>{if(!g)return[];if(e.result&&typeof e.result=="object"&&"blocks"in e.result){const C=e.result.blocks;if(Array.isArray(C)){const E=fj(C);if(E.length>0)return E}}return fj(e.rawResult)},[g,e.rawResult,e.result]),x=v.useMemo(()=>{switch(e.toolKind){case"bash":return e.input.command;case"write_file":case"delete_file":return e.input.content;default:return JSON.stringify(e.input,null,2)}},[e]);return f.jsx(Ca,{className:"w-full",children:f.jsxs(q0,{expandedContent:f.jsx(K0,{className:"my-4 text-sm",children:f.jsxs("div",{className:"flex flex-col gap-2",children:[p?f.jsx(Sh,{content:"",isDiff:!0,oldString:e.input.oldString,newString:e.input.newString}):h?f.jsx(Sh,{content:e.input.content}):!g&&!u&&f.jsx(AI,{label:c?f.jsxs("span",{className:"flex items-center gap-2 w-full",children:[f.jsx("span",{children:"Command"}),!!e.input.timeoutMs&&f.jsxs("span",{className:"text-muted-foreground",children:["timeout: ",String(e.input.timeoutMs),"ms"]}),!!e.input.runInBackground&&f.jsx("span",{className:"text-muted-foreground",children:"background"})]}):u?"Contents":"Input",copyText:x,children:x}),r&&g&&!e.isError&&(_.length>0?f.jsxs("div",{children:[f.jsx("span",{className:"font-medium text-muted-foreground",children:"Image"}),f.jsx("div",{className:"mt-1",children:f.jsx(s0e,{images:_})})]}):f.jsx(Sh,{content:b})),u&&!e.isError&&f.jsx(Sh,{content:e.input.content}),r&&!g&&!(u&&!e.isError)&&!(p&&!e.isError)&&!(h&&!e.isError)&&f.jsx(AI,{label:e.isError?"Error":"Result",copyText:b,children:b})]})}),children:[f.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:e.isError?f.jsx(eo,{className:"size-4 text-destructive"}):o?f.jsx(n0,{className:"size-4 text-muted-icon"}):f.jsx(P8,{icon:D8(e.toolName),className:"size-4 text-muted-icon"})}),f.jsx(Nl,{className:"text-left transition-opacity duration-200 truncate",children:f.jsx(Xp,{animate:i,shimmerWidth:Math.max(20,(((S=l||s)==null?void 0:S.length)??33)*3),children:l||s})})]})})}function o0e(e){if(e<1e3)return`${e}ms`;const t=Math.floor(e/1e3),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}h${r>0?` ${r}m`:""}`:r>0?`${r}m${i>0?` ${i}s`:""}`:`${i}s`}function hj({durationMs:e,prefix:t="Worked for"}){return e<=0?null:f.jsxs(mge,{children:[t," ",o0e(e)]})}function xB({message:e}){return e.success?f.jsx(hj,{durationMs:e.durationMs}):f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"px-4 py-3 mx-2 my-1 rounded-lg bg-destructive/10 border border-destructive/20 text-destructive text-sm",children:e.result||"An unknown error occurred."}),f.jsx(hj,{durationMs:e.durationMs,prefix:"Failed after"})]})}function a0e(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(2)} MB`}function l0e(e){return typeof e=="string"?e:JSON.stringify(e,null,2)}function c0e(e){return e.replace(/<persisted-output>\n?/g,"").replace(/\n?<\/persisted-output>/g,"")}function u0e({message:e,localPath:t}){if(e.kind==="tool"&&e.persisted){const n=c0e(l0e(e.rawResult??""));return f.jsxs("div",{className:"rounded-md border border-border bg-muted/30 p-2 space-y-1 text-xs",children:[f.jsxs("div",{className:"font-medium",children:[e.toolName,": output too large (",a0e(e.persisted.originalSize),") — saved to disk"]}),f.jsx("pre",{className:"text-[11px] whitespace-pre-wrap overflow-hidden max-h-48",children:n}),f.jsxs("a",{href:aE(e.persisted.filePath),className:"text-blue-500 hover:underline break-all",target:"_blank",rel:"noreferrer",children:["View full output (",e.persisted.filePath,")"]})]})}switch(e.kind){case"assistant_text":return f.jsx(_B,{message:e});case"tool":return f.jsx(Pb,{message:e,isLoading:!1,localPath:t});case"result":return f.jsx(xB,{message:e});default:return null}}function d0e(e){switch(e){case"AUTH_REQUIRED":return"Auth required";case"UNKNOWN_SUBAGENT":return"Unknown subagent";case"LOOP_DETECTED":return"Loop detected";case"DEPTH_EXCEEDED":return"Depth exceeded";case"TIMEOUT":return"Timeout";case"PROVIDER_ERROR":return"Provider error";case"INTERRUPTED":return"Interrupted";case"USER_CANCELLED":return"Cancelled by you";default:return"Error"}}function f0e({error:e,runId:t,onRetry:n,onOpenSettings:r}){const i=e.code==="TIMEOUT"||e.code==="PROVIDER_ERROR",s=e.code==="AUTH_REQUIRED";return f.jsxs("div",{"data-testid":`subagent-error:${t}`,className:"rounded-md border border-destructive/40 bg-destructive/5 p-3 text-sm",children:[f.jsxs("div",{className:"flex items-center gap-2 font-medium text-destructive",children:[f.jsx(Gv,{className:"h-4 w-4"}),f.jsx("span",{children:d0e(e.code)})]}),f.jsx("p",{className:"mt-1 text-foreground",children:e.message}),f.jsxs("div",{className:"mt-2 flex gap-2",children:[s&&r&&f.jsxs("button",{type:"button",onClick:r,className:"inline-flex items-center gap-1 text-xs underline",children:[f.jsx(zV,{className:"h-3 w-3"})," Open settings"]}),i&&n&&f.jsxs("button",{type:"button",onClick:n,className:"inline-flex items-center gap-1 text-xs underline",children:[f.jsx(EW,{className:"h-3 w-3"})," Retry"]})]})]})}function h0e({question:e,currentIndex:t,totalQuestions:n,onBack:r,children:i}){const s=r&&t>0;return f.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[f.jsxs("div",{className:"relative",children:[f.jsxs("h3",{className:"font-medium text-foreground text-sm p-3 px-4 bg-card border-b border-border text-foreground flex flex-row items-center gap-2",children:[s?f.jsx("button",{onClick:r,className:" text-muted-foreground hover:opacity-60 transition-all flex items-center",children:f.jsx(E9,{className:"h-4 w-4 -ml-0.5",strokeWidth:3})}):n>1?f.jsxs("span",{className:"font-bold text-muted-foreground whitespace-nowrap",children:[t+1," of ",n]}):null,e]}),n>1&&f.jsx("div",{className:"absolute bottom-0 left-0 right-0 h-0.5 bg-border",children:f.jsx("div",{className:"h-full bg-muted-foreground/40 transition-all duration-300",style:{width:`${t/n*100}%`}})})]}),i]})}function pj({label:e,description:t}){return f.jsxs(f.Fragment,{children:[f.jsx("span",{className:"text-foreground text-sm",children:e}),t&&f.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:t})]})}function SB({selected:e,multiSelect:t,onClick:n}){return f.jsx("button",{type:"button",onClick:n,className:he("flex-shrink-0 w-5 h-5 border-1 flex items-center justify-center",t?"rounded":"rounded-full",e?"border-transparent bg-foreground":"border-muted-foreground/50 bg-background",n&&e&&"cursor-pointer"),children:e&&f.jsx(gi,{strokeWidth:3,className:"translate-y-[0.5px] h-3 w-3 text-white dark:text-background"})})}function p0e({option:e,selected:t,multiSelect:n,onClick:r,isLast:i}){const s="w-full text-left p-3 pt-2.5 pl-4 pr-5 bg-background",o=i?"":"border-b border-border";return r?f.jsx("button",{onClick:r,className:he(s,o,"transition-all cursor-pointer"),children:f.jsxs("div",{className:"flex items-center justify-between gap-3",children:[f.jsx("div",{className:"flex-1 min-w-0",children:f.jsx(pj,{label:e.label,description:e.description})}),f.jsx(SB,{selected:t,multiSelect:n})]})}):f.jsx("div",{className:he(s,o),children:f.jsx(pj,{label:e.label,description:e.description})})}function m0e(e){return e==null?void 0:e.answers}function ds(e){return e.id||e.question}function wB({message:e,onSubmit:t,isLatest:n}){var H,W;const r=G0(),i=e.input.questions,s=!!e.result,o=m0e(e.result),l=((H=e.result)==null?void 0:H.discarded)===!0,[c,u]=v.useState(0),[p,h]=v.useState({}),[g,b]=v.useState({}),[_,x]=v.useState(o??null),[S,C]=v.useState(s),E=(Z,D)=>{var oe;const G=(oe=g[Z])==null?void 0:oe.trim(),ee=p[Z]||"",B=D||i.find(J=>ds(J)===Z);if(B!=null&&B.multiSelect)return[ee,G].filter(Boolean).flatMap(J=>J.split(", ").filter(Boolean));const le=G||ee;return le?[le]:[]},k=Z=>{const D=p[ds(Z)]||"";return Z.multiSelect?D.split(", ").filter(Boolean):[D]},T=(Z,D)=>{const G=ds(Z);if(Z.multiSelect){const ee=p[G]?p[G].split(", ").filter(Boolean):[],B=ee.includes(D)?ee.filter(le=>le!==D):[...ee,D];h({...p,[G]:B.join(", ")})}else h({...p,[G]:D}),b({...g,[G]:""}),c<i.length-1&&setTimeout(()=>u(c+1),150)},A=(Z,D)=>{const G=ds(Z);b({...g,[G]:D}),D&&!Z.multiSelect&&h({...p,[G]:""})},N=Z=>{const D=ds(Z);Z.multiSelect&&g[D]&&b({...g,[D]:""})},M=i.every(Z=>E(ds(Z),Z).length>0),j=i[c],U=c===i.length-1,I=j&&E(ds(j),j).length>0,P=()=>{c<i.length-1&&u(c+1)},z=()=>{c>0&&u(c-1)},O=()=>{if(!M)return;const Z={};for(const D of i){const G=ds(D);Z[G]=E(G,D)}x(Z),C(!0),t(e.toolId,i,Z)},$=Z=>{if(Z.key==="Enter"&&!(!j||!I)){if(Z.preventDefault(),U){O();return}P()}};if(S||s){const Z=o||_||{};return f.jsx("div",{className:"w-full",children:f.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[f.jsxs("div",{className:"font-medium text-sm p-3 px-4 pr-5 bg-muted border-b border-border flex flex-row items-center justify-between",children:[f.jsxs("p",{children:["Question",i.length!==1?"s":""]}),f.jsx("p",{className:"",children:l?"Discarded":"Answers"})]}),i.map((D,G)=>{const ee=Z[ds(D)]||Z[D.question]||[],B=G===i.length-1;return f.jsxs("div",{className:he("w-full p-3 pt-2.5 pl-4 pr-5 bg-background flex items-center justify-between gap-3",!B&&"border-b border-border"),children:[f.jsx("div",{className:"text-sm text-pretty",children:D.question}),ee.length>0&&f.jsx("div",{className:"text-sm font-medium text-right max-w-[50%] text-pretty",children:ee.join(", ")}),ee.length===0&&f.jsx("div",{className:"text-sm font-medium text-right italic",children:l?"Discarded":"No Response"})]},ds(D))})]})})}if(r.readonly)return f.jsx("div",{className:"w-full",children:f.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[f.jsxs("div",{className:"font-medium text-sm p-3 px-4 pr-5 bg-muted border-b border-border flex flex-row items-center justify-between gap-3",children:[f.jsxs("p",{children:["Question",i.length!==1?"s":""]}),f.jsx("p",{className:"text-muted-foreground",children:"Awaiting response"})]}),i.map((Z,D)=>{var G;return f.jsxs("div",{className:he("w-full p-3 pt-2.5 pl-4 pr-5 bg-background flex items-center justify-between gap-3",D<i.length-1&&"border-b border-border"),children:[f.jsx("div",{className:"text-sm text-pretty",children:Z.question}),f.jsx("div",{className:"max-w-[50%] text-right text-xs text-muted-foreground text-pretty",children:((G=Z.options)==null?void 0:G.map(ee=>ee.label).join(", "))||"Freeform response"})]},ds(Z))})]})});if(!n)return f.jsx("div",{className:"w-full py-2",children:f.jsxs("div",{className:"flex items-center gap-2",children:[f.jsx(KP,{className:"h-4 w-4 text-muted-foreground"}),f.jsx("span",{className:"text-sm text-muted-foreground",children:"Questions pending (newer question active)"})]})});if(!j)return null;const V=k(j),F=g[ds(j)]||"";return f.jsxs("div",{className:"w-full space-y-3",children:[f.jsxs(h0e,{question:j.question,currentIndex:c,totalQuestions:i.length,onBack:c>0?z:void 0,children:[(W=j.options)==null?void 0:W.map(Z=>f.jsx(p0e,{option:Z,selected:V.includes(Z.label),multiSelect:j.multiSelect,onClick:()=>T(j,Z.label)},Z.label)),f.jsx("div",{className:"transition-all bg-background",children:f.jsxs("div",{className:"flex pr-5 items-center justify-between gap-3",children:[f.jsx("input",{type:"text",value:F,onChange:Z=>A(j,Z.target.value),onKeyDown:$,placeholder:"Other...",className:"flex-1 px-3 !py-1 pl-4 min-h-[55px] min-w-0 text-sm bg-transparent outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background rounded-md text-foreground placeholder:text-muted-foreground"}),f.jsx(SB,{selected:!!F,multiSelect:j.multiSelect,onClick:j.multiSelect&&F?()=>N(j):void 0})]})})]}),f.jsxs("div",{className:"flex justify-end gap-2 mx-2",children:[!U&&I&&(j.multiSelect||!!F)&&f.jsx(Ke,{size:"sm",onClick:P,children:"Next"}),U&&f.jsx(Ke,{size:"sm",onClick:O,disabled:!M,className:he(!M&&"opacity-50 cursor-not-allowed","rounded-full"),children:"Submit"})]})]})}function CB({message:e,onConfirm:t,isLatest:n}){const r=G0(),i=!!e.result,[s,o]=v.useState(!1),[l,c]=v.useState(!1),[u,p]=v.useState(!1),[h,g]=v.useState(""),b=v.useRef(null),_=e.input;v.useEffect(()=>{u&&b.current&&b.current.focus()},[u]);const x=async()=>{_!=null&&_.plan&&(await navigator.clipboard.writeText(_.plan),c(!0),setTimeout(()=>c(!1),2e3))},S=i?e.result:null,C=(S==null?void 0:S.discarded)===!0;return f.jsxs("div",{className:"flex flex-col gap-3",children:[f.jsxs("div",{className:"relative rounded-2xl border border-border overflow-hidden group/plan",children:[(_==null?void 0:_.plan)&&f.jsx(Ke,{variant:"ghost",size:"icon","aria-label":l?"Copied":"Copy plan",className:he("absolute top-2 right-2 z-10 h-11 w-11 md:h-8 md:w-8 rounded-md text-muted-foreground opacity-100 md:opacity-0 md:group-hover/plan:opacity-100 transition-opacity [@media(hover:none)]:!opacity-100",!l&&"hover:text-foreground",l&&"hover:!bg-transparent hover:!border-transparent"),onClick:x,children:l?f.jsx(gi,{className:"h-4 w-4 text-success"}):f.jsx(El,{className:"h-4 w-4"})}),f.jsxs("div",{className:he("!pt-5 !pb-0 px-4 md:py-4.5 md:px-5.5 bg-muted dark:bg-card overflow-scroll no-pre-highlight transition-all",i&&!s?"max-h-[min(400px,40vh)] ":"",i?"hover:!pb-[32px]":""),children:[i&&f.jsxs(Ke,{variant:"ghost",className:"absolute z-10 bottom-2 pr-2.5 !pl-3.5 h-[34px] inline-flex gap-1 text-sm left-[50%] -translate-x-[50%] text-muted-foreground backdrop-blur-sm hover:text-foreground opacity-0 group-hover/plan:opacity-100 transition-all rounded-full border border-border",onClick:()=>o(!s),children:[s?"Show Less":"Show More",f.jsx(Hd,{className:`size-3.5 transition-transform ${s?"rotate-180":""}`})]}),_!=null&&_.plan?f.jsxs("div",{className:"prose prose-sm dark:prose-invert max-w-none",children:[f.jsx(Xc,{remarkPlugins:[Qc],components:sf(),children:_.plan}),f.jsx("div",{className:"mt-5"})]}):f.jsx("p",{className:"text-sm text-muted-foreground",children:"No plan provided"})]})]}),i?f.jsx("div",{className:"flex justify-end mx-2",children:f.jsxs("span",{className:"pl-4 inline text-sm font-medium bg-background text-foreground/60 border border-border py-1.5 px-3 rounded-[20px] leading-relaxed max-w-[85%] sm:max-w-[80%]",children:[f.jsx("em",{children:C?"Discarded":S!=null&&S.clearContext?"Approved & Cleared Context":S!=null&&S.confirmed?"Approved":S!=null&&S.message?`Adjusted: "${S.message}"`:"Adjusted Plan"}),f.jsx(U9,{className:"inline h-4 w-4 ml-1.5 -mt-0.5"})]})}):n?r.readonly?f.jsx("div",{className:"flex justify-end mx-2",children:f.jsx("span",{className:"inline text-sm text-muted-foreground italic",children:"Plan pending in original session"})}):f.jsxs("div",{className:"flex flex-col gap-3",children:[!u&&f.jsxs("div",{className:"flex flex-col md:flex-row items-stretch md:items-center justify-end gap-2 mx-2",children:[f.jsxs(Ke,{size:"sm",onClick:()=>t(e.toolId,!0,!0),className:"rounded-full bg-primary text-background pr-4 md:order-last",children:[f.jsx(_9,{className:"h-4 w-4 mr-1.5"}),"Approve & Clear"]}),f.jsxs("div",{className:"flex items-stretch md:items-center gap-2 md:contents",children:[f.jsxs(Ke,{size:"sm",variant:"outline",onClick:()=>p(!0),className:"rounded-full border-border flex-1 md:flex-initial md:order-first",children:[f.jsx(Rp,{className:"h-4 w-4 mr-1.5"}),"Suggest Edits"]}),f.jsxs(Ke,{size:"sm",variant:"outline",onClick:()=>t(e.toolId,!0),className:"rounded-full border-border flex-1 md:flex-initial",children:[f.jsx(gi,{className:"h-4 w-4 mr-1.5"}),"Approve"]})]})]}),u&&f.jsxs("div",{className:"flex flex-col gap-2",children:[f.jsx("textarea",{ref:b,value:h,onChange:E=>g(E.target.value),onKeyDown:E=>{E.key==="Enter"&&!E.shiftKey&&h.trim()&&(E.preventDefault(),t(e.toolId,!1,void 0,h.trim())),E.key==="Escape"&&(p(!1),g(""))},placeholder:"Describe what you'd like to change...",rows:3,className:"w-full rounded-2xl border border-border bg-muted dark:bg-card px-4 py-3 text-sm text-foreground placeholder:text-muted-foreground resize-none outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"}),f.jsxs("div",{className:"flex items-center justify-end gap-2 mx-2",children:[f.jsx(Ke,{size:"sm",variant:"ghost",onClick:()=>{p(!1),g("")},className:"rounded-full text-muted-foreground",children:"Cancel"}),f.jsxs(Ke,{size:"sm",disabled:!h.trim(),onClick:()=>t(e.toolId,!1,void 0,h.trim()),className:"rounded-full bg-primary text-background disabled:opacity-50 disabled:pointer-events-none",children:[f.jsx(IW,{className:"h-4 w-4 mr-1.5"}),"Adjust Plan"]})]})]})]}):f.jsx("div",{className:"flex justify-end mx-2",children:f.jsx("span",{className:"inline text-sm text-muted-foreground italic",children:"Plan pending (newer prompt active)"})})]})}function g0e({pendingTool:e,onAskUserQuestionSubmit:t,onExitPlanModeSubmit:n}){if(e.toolKind==="ask_user_question"){const r=e.input,i={id:e.toolUseId,kind:"tool",toolKind:"ask_user_question",toolName:"AskUserQuestion",toolId:e.toolUseId,input:{questions:r.questions??[]},timestamp:new Date(e.requestedAt).toISOString()};return f.jsxs("div",{"data-testid":`subagent-pending-tool:${e.toolUseId}`,children:[f.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground mb-1",children:"awaiting your response"}),f.jsx(wB,{message:i,onSubmit:t,isLatest:!0})]})}if(e.toolKind==="exit_plan_mode"){const r=e.input,i={id:e.toolUseId,kind:"tool",toolKind:"exit_plan_mode",toolName:"ExitPlanMode",toolId:e.toolUseId,input:{plan:r.plan,summary:r.summary},timestamp:new Date(e.requestedAt).toISOString()};return f.jsxs("div",{"data-testid":`subagent-pending-tool:${e.toolUseId}`,children:[f.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground mb-1",children:"awaiting your response"}),f.jsx(CB,{message:i,onConfirm:(s,o,l,c)=>n(s,{confirmed:o,clearContext:l,message:c}),isLatest:!0})]})}return null}function kB({run:e,indentDepth:t,localPath:n,onOpenSettings:r,onRetry:i,onSubagentAskUserQuestionSubmit:s,onSubagentExitPlanModeSubmit:o,onCancelSubagentRun:l}){var h;const c=fB(e.entries),u=c.some(g=>g.kind==="assistant_text"),p=e.status==="running"&&u;return f.jsxs("div",{"data-testid":`subagent-message:${e.runId}`,className:he("border-l-2 border-accent pl-3 py-2 space-y-2"),style:{marginLeft:`${t*24}px`},children:[f.jsxs("header",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[f.jsx(LC,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:e.subagentName}),f.jsxs("span",{className:"opacity-60",children:[e.provider,e.model?`/${e.model}`:""]}),((h=e.usage)==null?void 0:h.outputTokens)!=null&&f.jsxs("span",{className:"opacity-60",children:["· ",e.usage.inputTokens??0,"↑ ",e.usage.outputTokens,"↓"]}),e.status==="running"&&f.jsx("span",{className:"ml-auto inline-block animate-pulse",children:p?"streaming...":"running..."}),l&&e.status==="running"&&f.jsx("button",{type:"button","data-testid":`subagent-cancel:${e.runId}`,"aria-label":"Cancel subagent",onClick:()=>l(e.chatId,e.runId),className:"text-muted-foreground hover:text-foreground",children:f.jsx(eo,{className:"h-3.5 w-3.5"})})]}),c.map(g=>f.jsx(u0e,{message:g,localPath:n},g.id)),e.pendingTool&&f.jsx(g0e,{pendingTool:e.pendingTool,onAskUserQuestionSubmit:(g,b,_)=>s==null?void 0:s(e.runId,g,b,_),onExitPlanModeSubmit:(g,b)=>o==null?void 0:o(e.runId,g,b)}),c.length===0&&e.finalText&&f.jsxs("div",{className:he("whitespace-pre-wrap text-sm",p&&"text-foreground/80"),children:[e.finalText,p&&f.jsx("span",{className:"ml-0.5 inline-block w-2 animate-pulse",children:"▍"})]}),e.status==="failed"&&e.error&&f.jsx("div",{children:f.jsx(f0e,{error:e.error,runId:e.runId,subagentId:e.subagentId,onOpenSettings:r,onRetry:i})})]})}function v0e(e){var n;const t=e.match(/^<system-message>\s*([\s\S]*?)\s*<\/system-message>\s*([\s\S]*)$/);return t?{systemMessage:((n=t[1])==null?void 0:n.trim())||null,body:t[2]??""}:{systemMessage:null,body:e}}function b0e({content:e,attachments:t=[],steered:n=!1,autoContinue:r}){const[i,s]=v.useState(null),o=G0(),l=v.useMemo(()=>v0e(e),[e]),c=o.attachmentMode==="metadata",u=!o.readonly||o.attachmentMode==="bundle",p=v.useMemo(()=>t.filter(_=>_.kind==="image"&&(_.contentUrl||c)),[t,c]),h=v.useMemo(()=>t.filter(_=>_.kind!=="image"||!_.contentUrl&&!c),[t,c]),g=t.find(_=>_.id===i)??null;function b(_){if(!u||!_.contentUrl)return;if(Gp(_).openInNewTab){typeof window<"u"&&window.open(new URL(_.contentUrl,document.baseURI||window.location.href).toString(),"_blank","noopener,noreferrer");return}s(_.id)}return f.jsxs(f.Fragment,{children:[f.jsxs("div",{className:"flex flex-col items-end gap-2",children:[p.length>0?f.jsx("div",{className:"flex max-w-[85%] sm:max-w-[80%] flex-wrap justify-end gap-3",children:p.map(_=>f.jsx(kE,{attachment:_,onClick:u?()=>b(_):void 0},_.id))}):null,h.length>0?f.jsx("div",{className:"flex max-w-[85%] sm:max-w-[80%] flex-wrap justify-end gap-2",children:h.map(_=>f.jsx(Sl,{attachment:_,onClick:u?()=>b(_):void 0},_.id))}):null,l.body||!l.body&&t.length===0&&e&&!l.systemMessage?f.jsxs("div",{className:"flex max-w-[85%] items-center gap-2 sm:max-w-[80%]",children:[n?f.jsx(hG,{"aria-label":"Sent mid-turn",className:"size-3.5 shrink-0 text-muted-foreground"}):null,f.jsx("div",{className:"min-w-0 flex-1 rounded-[20px] border border-border bg-muted px-3.5 py-1.5 text-primary prose prose-sm prose-invert [&_p]:whitespace-pre-line",children:f.jsx(Xc,{remarkPlugins:[Qc],components:sf(),children:l.body})})]}):null,r?f.jsx("span",{className:"text-xs text-muted-foreground opacity-70",children:"auto-sent"}):null]}),f.jsx(W0,{attachment:g,onOpenChange:_=>!_&&s(null)})]})}function y0e({json:e}){return f.jsx("div",{className:"flex gap-3 justify-start",children:f.jsx("div",{className:"flex-1 max-w-[90%]",children:f.jsx("pre",{className:"text-xs font-mono whitespace-pre-wrap break-words bg-muted rounded-lg p-3 overflow-auto max-h-96",children:e})})})}function EB({title:e,count:t,children:n,badge:r}){const[i,s]=v.useState(!1);return t===0?null:f.jsxs("div",{className:"flex flex-col gap-1.5",children:[f.jsxs("button",{onClick:()=>s(!i),className:"flex items-center gap-1 cursor-pointer group/section hover:opacity-60 transition-opacity",children:[f.jsx(To,{className:he("h-3.5 w-3.5 text-muted-foreground transition-transform duration-200",i&&"rotate-90")}),f.jsx("span",{className:"text-muted-foreground font-medium",children:e}),f.jsx("span",{className:"text-muted-foreground/60",children:t}),r]}),i&&f.jsx("div",{className:"ml-5",children:n})]})}function jS({title:e,items:t,icon:n,getIcon:r}){return t.length===0?null:f.jsx(EB,{title:e,count:t.length,children:f.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.map(i=>f.jsx(z8,{icon:r?r(i):n,children:i},i))})})}function _0e(e){const t=e.match(/^mcp__([^_]+)__(.+)$/);return t?{server:t[1],tool:t[2]}:null}function RB({status:e}){const t=e==="connected"?"bg-success":e==="pending"?"bg-warning":"bg-destructive";return f.jsx("span",{className:he("inline-block h-2 w-2 rounded-full shrink-0",t)})}function x0e(e){switch(e){case"connected":return"Connected";case"failed":return"Failed";case"needs-auth":return"Needs auth";case"pending":return"Connecting...";case"disabled":return"Disabled";default:return e}}function mj({server:e}){const[t,n]=v.useState(!1),r=e.status==="connected";return f.jsxs("div",{className:"flex flex-col gap-1.5",children:[f.jsxs("button",{onClick:()=>r&&e.tools.length>0&&n(!t),className:he("flex items-center gap-1.5",r&&e.tools.length>0&&"cursor-pointer hover:opacity-60 transition-opacity"),children:[r&&e.tools.length>0&&f.jsx(To,{className:he("h-3 w-3 text-muted-foreground transition-transform duration-200",t&&"rotate-90")}),f.jsx(RB,{status:e.status}),f.jsx("span",{className:"text-muted-foreground font-medium",children:_w(e.name)}),r?f.jsxs("span",{className:"text-muted-foreground/50",children:[e.tools.length," tools"]}):f.jsx("span",{className:"text-muted-foreground/50",children:x0e(e.status)})]}),!r&&e.error&&f.jsx("span",{className:"text-destructive ml-5",children:e.error}),t&&e.tools.length>0&&f.jsx("div",{className:"flex flex-wrap gap-1.5 ml-5",children:e.tools.map(i=>f.jsx(z8,{icon:D8(`mcp__${e.name}__${i}`),children:i},i))})]})}function S0e({servers:e}){if(e.length===0)return null;const t=e.filter(i=>i.status==="connected"),n=e.filter(i=>i.status!=="connected"),r=n.length>0?f.jsxs("span",{className:"flex items-center gap-1 ml-1",children:[f.jsx(RB,{status:"failed"}),f.jsxs("span",{className:"text-muted-foreground/60",children:[n.length," disconnected"]})]}):null;return f.jsx(EB,{title:"MCP Servers",count:e.length,badge:r,children:f.jsxs("div",{className:"flex flex-col gap-2",children:[t.map(i=>f.jsx(mj,{server:i},i.name)),n.map(i=>f.jsx(mj,{server:i},i.name))]})})}function w0e({rawJson:e}){const[t,n]=v.useState(!1);return f.jsxs("div",{className:"flex flex-col gap-1.5",children:[f.jsxs("button",{onClick:()=>n(!t),className:"flex items-center gap-1 cursor-pointer group/section hover:opacity-60 transition-opacity",children:[f.jsx(To,{className:he("h-3.5 w-3.5 text-muted-foreground transition-transform duration-200",t&&"rotate-90")}),f.jsx("span",{className:"text-muted-foreground font-medium",children:"Raw Message"})]}),t&&f.jsx("pre",{className:"ml-5 text-xs whitespace-pre-wrap break-all border border-border rounded-md p-3 overflow-x-auto max-h-96 overflow-y-auto",children:e})]})}function C0e({message:e,rawJson:t}){const{coreTools:n,mcpServersWithTools:r}=v.useMemo(()=>{const i=new Map,s=[];for(const l of e.tools){const c=_0e(l);if(c){const u=i.get(c.server)||[];u.push(c.tool),i.set(c.server,u)}else s.push(l)}const o=e.mcpServers.map(l=>({name:l.name,status:l.status,error:l.error,tools:i.get(l.name)||[]}));return{coreTools:s,mcpServersWithTools:o}},[e.tools,e.mcpServers]);return f.jsx(Ca,{children:f.jsxs(q0,{expandedContent:f.jsx(K0,{className:"my-4 text-xs",children:f.jsxs("div",{className:"flex flex-col gap-3",children:[f.jsx(pge,{children:e.model}),f.jsx(jS,{title:"Tools",items:n,getIcon:i=>R1[i]??j8}),f.jsx(jS,{title:"Agents",items:e.agents,icon:n0}),f.jsx(jS,{title:"Commands",items:e.slashCommands,icon:BW}),f.jsx(S0e,{servers:r}),t&&f.jsx(w0e,{rawJson:t})]})}),children:[f.jsx(c9,{className:"h-5 w-5 text-logo"}),f.jsx(Nl,{children:"Session Started"})]})})}function k0e({message:e}){return f.jsx(Ca,{className:"hidden",children:f.jsxs(q0,{expandedContent:f.jsx(K0,{className:"my-4 text-xs",children:f.jsx("pre",{className:"font-mono whitespace-pre-wrap break-all bg-muted border border-border rounded-lg p-2 max-h-64 overflow-auto",children:JSON.stringify(e.accountInfo,null,2)})}),children:[f.jsx("div",{className:"size-5 flex justify-center items-center ",children:f.jsx(n0,{className:"h-4 w-4 text-muted-foreground"})}),f.jsx(Nl,{children:"Account"})]})})}const E0e={completed:{Icon:gi,iconClass:"text-success",textClass:"text-muted-foreground"},in_progress:{Icon:kn,iconClass:"text-foreground animate-spin",textClass:"text-foreground font-medium"},pending:{Icon:L9,iconClass:"text-muted-foreground",textClass:"text-muted-foreground"}};function R0e({message:e}){const t=e.input.todos;return t.length?f.jsx("div",{className:"w-full",children:f.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[f.jsxs("h3",{className:"font-medium text-foreground text-sm p-3 px-4 bg-card border-b border-border flex items-center gap-2",children:[f.jsx(HV,{className:"h-4 w-4 text-muted-foreground"}),"Progress"]}),f.jsx("div",{children:t.map((n,r)=>{const i=r===t.length-1,{Icon:s,iconClass:o,textClass:l}=E0e[n.status];return f.jsxs("div",{className:he("flex items-center gap-3 px-4 py-2.5 bg-background",!i&&"border-b border-border"),children:[f.jsx(s,{className:he("h-4 w-4 flex-shrink-0",o)}),f.jsx("span",{className:he("text-sm",l),children:n.status==="in_progress"?n.activeForm:n.content})]},r)})})]})}):null}function T0e({message:e}){const t=e.result,n=t==null?void 0:t.contentUrl,[r,i]=v.useState("idle");if(v.useEffect(()=>{if(!n)return;const h=new AbortController;return fetch(n,{method:"HEAD",signal:h.signal}).then(g=>{h.signal.aborted||i(g.ok?"ready":"missing")}).catch(()=>{}),()=>h.abort()},[n]),!t||!n)return null;const s={id:`offer-download-${e.toolId}`,kind:"file",displayName:t.displayName||t.fileName,absolutePath:t.relativePath,relativePath:t.relativePath,contentUrl:n,mimeType:t.mimeType??"application/octet-stream",size:t.size},o=oE(s),l=M6(o,t.mimeType),c=t.size>0?Yp(t.size):null,u=f.jsxs(f.Fragment,{children:[l,c?f.jsxs(f.Fragment,{children:[" · ",f.jsx("span",{className:"tabular-nums",children:c})]}):null]}),p=["Download",s.displayName,l,c].filter(Boolean);return r==="missing"?f.jsx("div",{className:"flex","data-testid":"offer-download-link",children:f.jsx(Sl,{attachment:s,disabledReason:"File no longer available"})}):f.jsx("div",{className:"flex","data-testid":"offer-download-link",children:f.jsx(Sl,{attachment:s,href:n,download:t.fileName||void 0,meta:u,ariaLabel:p.join(", ")})})}function A0e({message:e}){return f.jsx("div",{className:"flex items-center justify-end gap-2 text-sm text-muted-foreground",children:f.jsxs("div",{className:"inline-flex gap-1.5 items-center justify-center whitespace-nowrap text-sm font-medium bg-background text-foreground/60 border border-border h-9 pl-1 pr-4 rounded-full",children:[f.jsx(N9,{className:"h-4 w-4 ml-1.5"}),f.jsx("em",{children:"Interrupted"})]})})}function Ob({size:e=4}){return f.jsxs("svg",{className:"flex-1",viewBox:`0 0 100 ${e}`,preserveAspectRatio:"none",style:{height:`${e}px`},children:[f.jsx("pattern",{id:"zigzag",width:e,height:e,patternUnits:"userSpaceOnUse",children:f.jsx("path",{d:`M0 ${e} L${e/2} 0 L${e} ${e}`,fill:"none",stroke:"currentColor",strokeWidth:"0.5",className:"text-muted-foreground/30",style:{stroke:"currentColor"}})}),f.jsx("rect",{width:"100%",height:e,fill:"url(#zigzag)",className:"text-muted-foreground/30"})]})}function N0e(){return f.jsxs("div",{className:"flex items-center gap-3",children:[f.jsx(Ob,{}),f.jsx("span",{className:"text-[11px] tracking-widest text-muted-foreground uppercase flex-shrink-0",children:"Compacted"}),f.jsx(Ob,{})]})}function M0e(){return f.jsxs("div",{className:"flex items-center gap-3",children:[f.jsx(Ob,{}),f.jsx("span",{className:"text-[11px] tracking-widest text-muted-foreground uppercase flex-shrink-0",children:"Context Cleared"}),f.jsx(Ob,{})]})}function L0e({message:e}){return f.jsx(Ca,{children:f.jsxs(q0,{expandedContent:f.jsx(K0,{className:"my-4 text-xs",children:f.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none",children:f.jsx(Xc,{remarkPlugins:[Qc],components:sf(),children:e.summary})})}),children:[f.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:f.jsx(YP,{className:"h-4.5 w-4.5 text-muted-foreground"})}),f.jsx(Nl,{children:"Summarized"})]})})}const I0e={compacting:"Compacting..."};function j0e({message:e}){const t=I0e[e.status]||e.status;return f.jsxs(Ca,{className:"grid grid-cols-[auto_1fr] items-center gap-1.5 text-sm animate-pulse",children:[f.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:f.jsx(YP,{className:"h-4.5 w-4.5 text-muted-foreground"})}),f.jsx(Nl,{className:"text-left transition-opacity duration-200 truncate",children:t})]})}const D0e={read_file:{key:"read",singular:"read",plural:"reads"},edit_file:{key:"edit",singular:"edit",plural:"edits"},write_file:{key:"write",singular:"write",plural:"writes"},delete_file:{key:"delete",singular:"delete",plural:"deletes"},bash:{key:"bash",singular:"command",plural:"commands"},grep:{key:"grep",singular:"search",plural:"searches"},glob:{key:"glob",singular:"glob",plural:"globs"},subagent_task:{key:"task",singular:"agent",plural:"agents"},web_search:{key:"websearch",singular:"web search",plural:"web searches"},skill:{key:"skill",singular:"skill",plural:"skills"},todo_write:{key:"todo",singular:"todo update",plural:"todo updates"}},P0e={key:"other",singular:"tool call",plural:"tool calls"};function O0e(e){return D0e[e]??P0e}function z0e(e){const t=new Map,n=[];for(const r of e){const i=r.toolKind,s=O0e(i),o=t.get(s.key);o?o.count++:(t.set(s.key,{category:s,count:1}),n.push(s.key))}return n.map(r=>{const{category:i,count:s}=t.get(r);return`${s} ${s===1?i.singular:i.plural}`}).join(", ")}function B0e({messages:e,isLoading:t,localPath:n,expanded:r,onExpandedChange:i}){const s=v.useMemo(()=>z0e(e),[e]),l=e.some(c=>c.result===void 0)&&t;return f.jsx(Ca,{className:"w-full",children:f.jsxs("div",{className:"flex flex-col w-full",children:[f.jsx("button",{onClick:()=>i(!r),className:`group cursor-pointer grid grid-cols-[auto_1fr] items-center gap-1 text-sm ${!r&&!l?"hover:opacity-60 transition-opacity":""}`,children:f.jsxs("div",{className:"grid grid-cols-[auto_1fr] items-center gap-1.5",children:[f.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:f.jsx(To,{className:`h-4.5 w-4.5 text-muted-icon transition-all duration-200 ${r?"rotate-90":""}`})}),f.jsx(Nl,{className:"text-left",children:f.jsx(Xp,{animate:l,children:s})})]})}),r&&f.jsxs("div",{className:"my-4 flex flex-col gap-3",children:[e.map(c=>f.jsx(Pb,{message:c,isLoading:t,localPath:n},c.id)),e.length>5&&f.jsx("button",{onClick:()=>i(!1),className:"cursor-pointer grid grid-cols-[auto_1fr] items-center gap-1 text-xs hover:opacity-80 transition-opacity",children:f.jsxs("div",{className:"grid grid-cols-[auto_1fr] items-center gap-1.5",children:[f.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:f.jsx(To,{className:"h-4.5 w-4.5 text-muted-icon -rotate-90"})}),f.jsx(Nl,{className:"text-left",children:"Collapse"})]})})]})]})})}function F0e(e){if(e!=="system")return e}function DS(e,t){const n=F0e(t),r=new Intl.DateTimeFormat("en-GB",{timeZone:n,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hour12:!1}).formatToParts(new Date(e)),i=o=>{var l;return((l=r.find(c=>c.type===o))==null?void 0:l.value)??"00"};let s=i("hour");return s==="24"&&(s="00"),`${i("day")}/${i("month")}/${i("year")} ${s}:${i("minute")}`}const $0e=/^(\d{2})\/(\d{2})\/(\d{4}) (\d{2}):(\d{2})$/;function gj(e,t){if(e==="system")return-new Date(t).getTimezoneOffset();const n=new Intl.DateTimeFormat("en-US",{timeZone:e,hour12:!1,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}).formatToParts(new Date(t)),r=o=>{var l;return Number(((l=n.find(c=>c.type===o))==null?void 0:l.value)??0)};let i=r("hour");i===24&&(i=0);const s=Date.UTC(r("year"),r("month")-1,r("day"),i,r("minute"),r("second"));return Math.round((s-t)/6e4)}function H0e(e,t){const n=$0e.exec(e.trim());if(!n)return null;const[,r,i,s,o,l]=n,c=Number(r),u=Number(i),p=Number(s),h=Number(o),g=Number(l);if(u<1||u>12||c<1||c>31||h>23||g>59)return null;const b=Date.UTC(p,u-1,c,h,g),_=gj(t,b),x=b-_*6e4,S=gj(t,x);return x-(S-_)*6e4}const U0e={neutral:"border-border bg-card",muted:"border-border/50 bg-card/50 opacity-75",success:"border-emerald-500/30 bg-emerald-500/5",error:"border-destructive/40 bg-destructive/5"},V0e={primary:"default",secondary:"secondary",ghost:"ghost",destructive:"destructive"};function ca({title:e,description:t,body:n,errorMessage:r,tone:i="neutral",actions:s=[]}){const[o,l]=v.useState(null),[c,u]=v.useState(null),p=v.useCallback(async g=>{if(o)return;u(null);let b;try{b=g.onClick()}catch(_){console.error("[transcript-action-card] sync click threw",_),u(_ instanceof Error?_.message:String(_));return}if(b instanceof Promise){l(g.id);try{await b}catch(_){console.error("[transcript-action-card] async click rejected",_),u(_ instanceof Error?_.message:String(_))}finally{l(null)}}},[o]),h=o!==null;return f.jsxs("div",{"data-focus-fallback-ignore":!0,className:he("rounded-lg border px-4 py-3 text-sm space-y-2 transition-colors",U0e[i]),children:[f.jsx("div",{className:"flex items-start justify-between gap-3",children:f.jsxs("div",{className:"space-y-1 min-w-0 flex-1",children:[f.jsx("div",{className:"font-medium leading-tight",children:e}),t?f.jsx("div",{className:"text-muted-foreground text-xs leading-snug",children:t}):null]})}),n?f.jsx("div",{className:"text-xs leading-snug",children:n}):null,r?f.jsx("div",{className:"text-destructive text-xs leading-snug",children:r}):null,c?f.jsx("div",{className:"text-destructive text-xs leading-snug",role:"alert",children:c}):null,s.length>0?f.jsx("div",{className:"flex flex-wrap gap-2 pt-1",children:s.map(g=>{const b=o===g.id;return f.jsxs(Ke,{type:"button",size:"sm",variant:V0e[g.variant??"ghost"],disabled:g.disabled||h&&!b,onClick:()=>{p(g)},className:"gap-1.5",children:[b?f.jsx(kn,{className:"size-3.5 animate-spin"}):null,g.label]},g.id)})}):null]})}function W0e({schedule:e,onAccept:t,onReschedule:n,onCancel:r}){const[i,s]=v.useState(()=>DS(e.scheduledAt??e.resetAt,e.tz)),[o,l]=v.useState(!1),c=v.useMemo(()=>H0e(i,e.tz),[i,e.tz]),u=c!==null&&c>Date.now(),p=c===null?"Use format dd/mm/yyyy hh:mm":u?null:"Time must be in the future";if(e.state==="fired"){const _=DS(e.scheduledAt??e.resetAt,e.tz);return f.jsx(ca,{title:`Auto-continued at ${_}`,tone:"success"})}if(e.state==="cancelled")return f.jsx(ca,{title:"Auto-continue cancelled",tone:"muted"});if(e.state==="proposed"){const _=e.resetAt<=Date.now(),x=[{id:"schedule",label:"Schedule",variant:"primary",disabled:!u,onClick:()=>{c!==null&&t(c)}},{id:"dismiss",label:"Dismiss",variant:"ghost",onClick:()=>r()}];return f.jsx(ca,{title:"Rate limit hit — schedule auto-continue?",description:_?"Reset time has passed — accept to continue now.":void 0,body:f.jsxs("div",{className:"space-y-1",children:[f.jsx(ir,{value:i,onChange:S=>s(S.target.value),placeholder:"dd/mm/yyyy hh:mm"}),p&&f.jsx("div",{className:"text-destructive text-xs",children:p})]}),actions:x})}const h=DS(e.scheduledAt??e.resetAt,e.tz),g=e.tz==="system"?"local":e.tz;if(!o){const _=[{id:"change",label:"Change time",variant:"secondary",onClick:()=>l(!0)},{id:"cancel",label:"Cancel",variant:"ghost",onClick:()=>r()}];return f.jsx(ca,{title:`Auto-continue at ${h} (${g})`,actions:_})}const b=[{id:"save",label:"Save",variant:"primary",disabled:!u,onClick:()=>{c!==null&&(n(c),l(!1))}},{id:"back",label:"Back",variant:"ghost",onClick:()=>l(!1)}];return f.jsx(ca,{title:`Auto-continue at ${h} (${g})`,body:f.jsxs("div",{className:"space-y-1",children:[f.jsx(ir,{value:i,onChange:_=>s(_.target.value),placeholder:"dd/mm/yyyy hh:mm"}),p&&f.jsx("div",{className:"text-destructive text-xs",children:p})]}),actions:b})}function G0e({toolRequestId:e,questions:t,onAnswer:n}){const[r,i]=v.useState({});function s(u){return u.id??u.question}function o(u,p){const h=s(u);u.multiSelect?i(g=>{const b=g[h]??[],_=b.includes(p)?b.filter(x=>x!==p):[...b,p];return{...g,[h]:_}}):i(g=>({...g,[h]:[p]}))}function l(){const u={};for(const p of t){const h=s(p);u[h]=r[h]??[]}n(e,{kind:"answer",payload:{questions:t,answers:u}})}const c=t.every(u=>{var h;const p=s(u);return(((h=r[p])==null?void 0:h.length)??0)>0});return f.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[f.jsxs("div",{className:"font-medium text-sm p-3 px-4 bg-muted border-b border-border flex items-center justify-between",children:[f.jsxs("span",{children:["Question",t.length!==1?"s":""]}),f.jsx("span",{className:"text-xs text-muted-foreground",children:"Reconnected — awaiting your response"})]}),t.map((u,p)=>{var _;const h=s(u),g=r[h]??[],b=p===t.length-1;return f.jsxs("div",{className:`bg-background px-4 py-3 ${b?"":"border-b border-border"}`,children:[f.jsx("p",{className:"text-sm font-medium mb-2",children:u.question}),u.options&&u.options.length>0?f.jsx("div",{className:"flex flex-wrap gap-2",children:u.options.map(x=>f.jsx("button",{onClick:()=>o(u,x.label),className:`rounded-full border px-3 py-1 text-xs transition-colors ${g.includes(x.label)?"border-foreground bg-foreground text-background":"border-border bg-background text-foreground hover:bg-muted"}`,children:x.label},x.label))}):f.jsx("input",{type:"text",className:"w-full rounded-md border border-border bg-muted px-3 py-1.5 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring",placeholder:"Type your answer...",value:((_=r[h])==null?void 0:_[0])??"",onChange:x=>{const S=x.target.value;i(C=>({...C,[h]:S?[S]:[]}))}})]},h)}),f.jsxs("div",{className:"flex justify-end gap-2 px-4 py-3 bg-background border-t border-border",children:[f.jsx(Ke,{size:"sm",variant:"outline",className:"rounded-full",onClick:()=>n(e,{kind:"deny",reason:"user_canceled"}),children:"Cancel"}),f.jsx(Ke,{size:"sm",className:"rounded-full",disabled:!c,onClick:l,children:"Submit"})]})]})}function q0e({toolRequestId:e,plan:t,onAnswer:n}){return f.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[f.jsxs("div",{className:"font-medium text-sm p-3 px-4 bg-muted border-b border-border flex items-center justify-between",children:[f.jsx("span",{children:"Plan"}),f.jsx("span",{className:"text-xs text-muted-foreground",children:"Reconnected — awaiting your response"})]}),f.jsx("div",{className:"bg-background px-4 py-3",children:f.jsx("p",{className:"text-sm whitespace-pre-wrap",children:t})}),f.jsxs("div",{className:"flex justify-end gap-2 px-4 py-3 bg-background border-t border-border",children:[f.jsx(Ke,{size:"sm",variant:"outline",className:"rounded-full",onClick:()=>n(e,{kind:"deny",reason:"user_canceled"}),children:"Edit"}),f.jsx(Ke,{size:"sm",className:"rounded-full",onClick:()=>n(e,{kind:"answer",payload:{confirmed:!0}}),children:"Confirm"})]})]})}function K0e({toolRequestId:e,toolName:t,onAnswer:n}){return f.jsxs("div",{className:"flex items-center gap-3 rounded-2xl border border-border bg-background px-4 py-3 text-sm",children:[f.jsxs("span",{className:"text-muted-foreground flex-1",children:["Pending tool: ",f.jsx("span",{className:"font-mono text-foreground",children:t})]}),f.jsx("button",{className:"text-xs text-muted-foreground underline hover:text-foreground transition-colors",onClick:()=>n(e,{kind:"deny",reason:"user_canceled"}),children:"Cancel"})]})}function Y0e({entry:e,onAnswer:t}){const{toolRequestId:n,toolName:r,arguments:i}=e;if(r==="mcp__kanna__ask_user_question"){const s=i.questions??[];return f.jsx(G0e,{toolRequestId:n,questions:s,onAnswer:t})}if(r==="mcp__kanna__exit_plan_mode"){const s=typeof i.plan=="string"?i.plan:"";return f.jsx(q0e,{toolRequestId:n,plan:s,onAnswer:t})}return f.jsx(K0e,{toolRequestId:n,toolName:r,onAnswer:t})}const X0e=new Set(["AskUserQuestion","ExitPlanMode","TodoWrite"]);function vj(e){if(e.kind!=="tool")return!1;const t=e.toolName;return!X0e.has(t)}function Q0e(e,{isFirstSystem:t,isFirstAccount:n,isLatestTodoWrite:r,hideResult:i,isFinalStatus:s}){let o=!e.hidden;if(o)switch(e.kind){case"system_init":o=t;break;case"account_info":o=n;break;case"tool":o=e.toolKind!=="todo_write"||r;break;case"result":o=!i&&(!e.success||e.durationMs>6e4);break;case"context_window_updated":o=!1;break;case"status":o=s;break;default:o=!0;break}return{isFirstSystem:t,isFirstAccount:n,isLatestTodoWrite:r,hideResult:i,isFinalStatus:s,shouldRender:o}}function Z0e(e,t){const n=e.findIndex(i=>i.kind==="system_init"),r=e.findIndex(i=>i.kind==="account_info");return e.map((i,s)=>{const o=e[s-1],l=e[s+1];return Q0e(i,{isFirstSystem:n===s,isFirstAccount:r===s,isLatestTodoWrite:i.id===t.TodoWrite,hideResult:(l==null?void 0:l.kind)==="context_cleared"||(o==null?void 0:o.kind)==="context_cleared",isFinalStatus:s===e.length-1})})}function J0e(e,t){const n=[];let r=0;for(;r<e.length;){const i=e[r],s=t[r];if(s!=null&&s.shouldRender&&vj(i)){const o=[i],l=r;for(r+=1;r<e.length;){const c=e[r],u=t[r];if(!(u!=null&&u.shouldRender)){r+=1;continue}if(!vj(c))break;o.push(c),r+=1}o.length>=2?n.push({type:"tool-group",messages:o,startIndex:l}):n.push({type:"single",message:i,index:l});continue}n.push({type:"single",message:i,index:r}),r+=1}return n}function bj(e){var n;return e.type==="single"?e.message.id:`tool-group:${((n=e.messages[0])==null?void 0:n.id)??e.startIndex}`}function PS(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>n===t[r])}function eye(e,t){return e.id===t.id&&e.kind===t.kind&&e.displayName===t.displayName&&e.absolutePath===t.absolutePath&&e.relativePath===t.relativePath&&e.contentUrl===t.contentUrl&&e.mimeType===t.mimeType&&e.size===t.size}function tye(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>eye(n,t[r]))}function Id(e,t){var n,r;if(e===t)return!0;if(e.kind!==t.kind||e.id!==t.id||e.hidden!==t.hidden)return!1;switch(e.kind){case"user_prompt":return e.content===(t.kind==="user_prompt"?t.content:null)&&t.kind==="user_prompt"&&e.steered===t.steered&&((n=e.autoContinue)==null?void 0:n.scheduleId)===((r=t.autoContinue)==null?void 0:r.scheduleId)&&tye(e.attachments,t.attachments);case"system_init":return t.kind==="system_init"&&e.provider===t.provider&&e.model===t.model&&PS(e.tools,t.tools)&&PS(e.agents,t.agents)&&PS(e.slashCommands,t.slashCommands)&&e.debugRaw===t.debugRaw;case"account_info":return t.kind==="account_info"&&JSON.stringify(e.accountInfo)===JSON.stringify(t.accountInfo);case"assistant_text":return t.kind==="assistant_text"&&e.text===t.text;case"tool":return t.kind==="tool"&&e.toolKind===t.toolKind&&e.toolName===t.toolName&&e.toolId===t.toolId&&e.isError===t.isError&&JSON.stringify(e.input)===JSON.stringify(t.input)&&JSON.stringify(e.result)===JSON.stringify(t.result)&&JSON.stringify(e.rawResult)===JSON.stringify(t.rawResult);case"result":return t.kind==="result"&&e.success===t.success&&e.cancelled===t.cancelled&&e.result===t.result&&e.durationMs===t.durationMs&&e.costUsd===t.costUsd;case"status":return t.kind==="status"&&e.status===t.status;case"compact_summary":return t.kind==="compact_summary"&&e.summary===t.summary;case"context_window_updated":return t.kind==="context_window_updated"&&JSON.stringify(e.usage)===JSON.stringify(t.usage);case"compact_boundary":case"context_cleared":case"interrupted":return!0;case"unknown":return t.kind==="unknown"&&e.json===t.json;case"auto_continue_prompt":return t.kind==="auto_continue_prompt"&&e.scheduleId===t.scheduleId;case"pending_tool_request":return t.kind==="pending_tool_request"&&e.toolRequestId===t.toolRequestId&&e.toolName===t.toolName}}function nye(e,t){return e.kind!==t.kind||e.id!==t.id?!1:e.kind==="single"&&t.kind==="single"?e.index===t.index&&e.isLoading===t.isLoading&&e.localPath===t.localPath&&e.isFirstSystem===t.isFirstSystem&&e.isFirstAccount===t.isFirstAccount&&e.isLatestAskUserQuestion===t.isLatestAskUserQuestion&&e.isLatestExitPlanMode===t.isLatestExitPlanMode&&e.isLatestTodoWrite===t.isLatestTodoWrite&&e.hideResult===t.hideResult&&e.isFinalStatus===t.isFinalStatus&&Id(e.message,t.message):e.kind==="tool-group"&&t.kind==="tool-group"?e.startIndex===t.startIndex&&e.isLoading===t.isLoading&&e.localPath===t.localPath&&e.messages.length===t.messages.length&&e.messages.every((n,r)=>Id(n,t.messages[r])):!1}function rye(e,t){const n=new Map;let r=e.length!==t.byId.size;const i=e.map((s,o)=>{const l=t.byId.get(s.id),c=l&&nye(l,s)?l:s;return n.set(s.id,c),!r&&t.result[o]!==c&&(r=!0),c});return r?{byId:n,result:i}:t}function iye(e){const t=v.useRef({byId:new Map,result:[]}),n=v.useMemo(()=>rye(e,t.current),[e]);return v.useLayoutEffect(()=>{t.current=n}),n.result}const TB=(e,t)=>{},sye=v.memo(function({message:t,index:n,isLoading:r,localPath:i,isFirstSystem:s,isFirstAccount:o,isLatestAskUserQuestion:l,isLatestExitPlanMode:c,isLatestTodoWrite:u,hideResult:p,isFinalStatus:h,onAskUserQuestionSubmit:g,onExitPlanModeConfirm:b,onToolRequestAnswer:_=TB,schedules:x,onAutoContinueAccept:S,onAutoContinueReschedule:C,onAutoContinueCancel:E}){let k=null;if(t.kind==="user_prompt")k=f.jsx(b0e,{content:t.content,attachments:t.attachments,steered:t.steered,autoContinue:t.autoContinue},t.id);else switch(t.kind){case"auto_continue_prompt":{const T=x[t.scheduleId];if(!T){k=f.jsx("div",{className:"rounded border px-3 py-2 text-sm opacity-70",children:"Auto-continue expired"},t.id);break}k=f.jsx(W0e,{schedule:T,onAccept:A=>S(t.scheduleId,A),onReschedule:A=>C(t.scheduleId,A),onCancel:()=>E(t.scheduleId)},t.id);break}case"unknown":k=f.jsx(y0e,{json:t.json},t.id);break;case"system_init":k=s?f.jsx(C0e,{message:t,rawJson:t.debugRaw},t.id):null;break;case"account_info":k=o?f.jsx(k0e,{message:t},t.id):null;break;case"assistant_text":k=f.jsx(_B,{message:t},t.id);break;case"tool":if(t.isError){k=f.jsx(Pb,{message:t,isLoading:r,localPath:i},t.id);break}if(t.toolKind==="ask_user_question"){k=f.jsx(wB,{message:t,onSubmit:g,isLatest:l},t.id);break}if(t.toolKind==="exit_plan_mode"){k=f.jsx(CB,{message:t,onConfirm:b,isLatest:c},t.id);break}if(t.toolKind==="todo_write"){k=u?f.jsx(R0e,{message:t},t.id):null;break}if(t.toolKind==="offer_download"&&t.result){k=f.jsx(T0e,{message:t},t.id);break}k=f.jsx(Pb,{message:t,isLoading:r,localPath:i},t.id);break;case"result":k=p?null:f.jsx(xB,{message:t},t.id);break;case"context_window_updated":k=null;break;case"interrupted":k=f.jsx(A0e,{message:t},t.id);break;case"compact_boundary":k=f.jsx(N0e,{},t.id);break;case"context_cleared":k=f.jsx(M0e,{},t.id);break;case"compact_summary":k=f.jsx(L0e,{message:t},t.id);break;case"status":k=h?f.jsx(j0e,{message:t},t.id):null;break;case"pending_tool_request":k=f.jsx(Y0e,{entry:t,onAnswer:_},t.id);break}return k?f.jsx("div",{id:`msg-${t.id}`,className:"group relative","data-index":n,[Xv]:"",children:k}):null},(e,t)=>e.index===t.index&&e.isLoading===t.isLoading&&e.localPath===t.localPath&&e.isFirstSystem===t.isFirstSystem&&e.isFirstAccount===t.isFirstAccount&&e.isLatestAskUserQuestion===t.isLatestAskUserQuestion&&e.isLatestExitPlanMode===t.isLatestExitPlanMode&&e.isLatestTodoWrite===t.isLatestTodoWrite&&e.hideResult===t.hideResult&&e.isFinalStatus===t.isFinalStatus&&e.onAskUserQuestionSubmit===t.onAskUserQuestionSubmit&&e.onExitPlanModeConfirm===t.onExitPlanModeConfirm&&e.onToolRequestAnswer===t.onToolRequestAnswer&&e.schedules===t.schedules&&e.onAutoContinueAccept===t.onAutoContinueAccept&&e.onAutoContinueReschedule===t.onAutoContinueReschedule&&e.onAutoContinueCancel===t.onAutoContinueCancel&&Id(e.message,t.message)),oye=v.memo(function({id:t,messages:n,isLoading:r,localPath:i,expanded:s,onExpandedChange:o}){return f.jsx("div",{className:"group relative",[Xv]:"",children:f.jsx(B0e,{messages:n,isLoading:r,localPath:i,expanded:s,onExpandedChange:l=>o(t,l)})})},(e,t)=>e.id===t.id&&e.startIndex===t.startIndex&&e.isLoading===t.isLoading&&e.localPath===t.localPath&&e.expanded===t.expanded&&e.onExpandedChange===t.onExpandedChange&&e.messages.length===t.messages.length&&e.messages.every((n,r)=>Id(n,t.messages[r])));function AB(e,{isLoading:t,localPath:n,latestToolIds:r}){const i=Z0e(e,r),s=J0e(e,i),o=[];for(const l of s){if(l.type==="tool-group"){o.push({kind:"tool-group",id:bj(l),startIndex:l.startIndex,messages:l.messages,isLoading:t&&l.messages.some(p=>p.kind==="tool"&&p.result===void 0),localPath:n});continue}const c=i[l.index];if(!c)continue;const u={kind:"single",id:bj(l),message:l.message,index:l.index,isLoading:l.message.kind==="tool"&&l.message.result===void 0&&t,localPath:n,isFirstSystem:c.isFirstSystem,isFirstAccount:c.isFirstAccount,isLatestAskUserQuestion:l.message.id===r.AskUserQuestion,isLatestExitPlanMode:l.message.id===r.ExitPlanMode,isLatestTodoWrite:c.isLatestTodoWrite,hideResult:c.hideResult,isFinalStatus:c.isFinalStatus};c.shouldRender&&o.push(u)}return o}const aye={};function NB(e,t,n,r,i,s,o){const l=n.get(e.runId)??[];return f.jsxs(xn.Fragment,{children:[f.jsx(kB,{run:e,indentDepth:t,localPath:r,onSubagentAskUserQuestionSubmit:i,onSubagentExitPlanModeSubmit:s,onCancelSubagentRun:o}),l.map(c=>NB(c,t+1,n,r,i,s,o))]},e.runId)}const MB=v.memo(function({row:t,toolGroupExpanded:n,onToolGroupExpandedChange:r,onAskUserQuestionSubmit:i,onExitPlanModeConfirm:s,onToolRequestAnswer:o,schedules:l,onAutoContinueAccept:c,onAutoContinueReschedule:u,onAutoContinueCancel:p}){return t.kind==="tool-group"?f.jsx(oye,{id:t.id,startIndex:t.startIndex,messages:t.messages,isLoading:t.isLoading,localPath:t.localPath,expanded:n??!1,onExpandedChange:r}):f.jsx(sye,{message:t.message,index:t.index,isLoading:t.isLoading,localPath:t.localPath,isFirstSystem:t.isFirstSystem,isFirstAccount:t.isFirstAccount,isLatestAskUserQuestion:t.isLatestAskUserQuestion,isLatestExitPlanMode:t.isLatestExitPlanMode,isLatestTodoWrite:t.isLatestTodoWrite,hideResult:t.hideResult,isFinalStatus:t.isFinalStatus,onAskUserQuestionSubmit:i,onExitPlanModeConfirm:s,onToolRequestAnswer:o,schedules:l,onAutoContinueAccept:c,onAutoContinueReschedule:u,onAutoContinueCancel:p})},(e,t)=>{if(e.toolGroupExpanded!==t.toolGroupExpanded||e.onToolGroupExpandedChange!==t.onToolGroupExpandedChange||e.onAskUserQuestionSubmit!==t.onAskUserQuestionSubmit||e.onExitPlanModeConfirm!==t.onExitPlanModeConfirm||e.onToolRequestAnswer!==t.onToolRequestAnswer||e.schedules!==t.schedules||e.onAutoContinueAccept!==t.onAutoContinueAccept||e.onAutoContinueReschedule!==t.onAutoContinueReschedule||e.onAutoContinueCancel!==t.onAutoContinueCancel||e.row.kind!==t.row.kind||e.row.id!==t.row.id)return!1;if(e.row.kind==="tool-group"&&t.row.kind==="tool-group"){const n=e.row,r=t.row;return n.startIndex===r.startIndex&&n.isLoading===r.isLoading&&n.localPath===r.localPath&&n.messages.length===r.messages.length&&n.messages.every((i,s)=>Id(i,r.messages[s]))}return e.row.kind==="single"&&t.row.kind==="single"?e.row.index===t.row.index&&e.row.isLoading===t.row.isLoading&&e.row.localPath===t.row.localPath&&e.row.isFirstSystem===t.row.isFirstSystem&&e.row.isFirstAccount===t.row.isFirstAccount&&e.row.isLatestAskUserQuestion===t.row.isLatestAskUserQuestion&&e.row.isLatestExitPlanMode===t.row.isLatestExitPlanMode&&e.row.isLatestTodoWrite===t.row.isLatestTodoWrite&&e.row.hideResult===t.row.hideResult&&e.row.isFinalStatus===t.row.isFinalStatus&&Id(e.row.message,t.row.message):!1}),LB={},lye=(e,t)=>{},cye=(e,t)=>{},uye=e=>{};function dye({messages:e,isLoading:t,localPath:n,latestToolIds:r,onOpenLocalLink:i,onAskUserQuestionSubmit:s,onExitPlanModeConfirm:o,onToolRequestAnswer:l=TB,schedules:c=LB,onAutoContinueAccept:u=lye,onAutoContinueReschedule:p=cye,onAutoContinueCancel:h=uye,onTunnelAccept:g,onTunnelStop:b,onTunnelRetry:_,subagentRuns:x=aye,onSubagentAskUserQuestionSubmit:S,onSubagentExitPlanModeSubmit:C,onCancelSubagentRun:E}){const[k,T]=v.useState({}),A=v.useMemo(()=>AB(e,{isLoading:t,localPath:n,latestToolIds:r}),[t,r,n,e]),{runsByUserMessageId:N,childrenByParentRunId:M}=v.useMemo(()=>{const U=new Map,I=new Map;for(const z of Object.values(x))if(z.parentRunId===null){const O=U.get(z.parentUserMessageId)??[];O.push(z),U.set(z.parentUserMessageId,O)}else{const O=I.get(z.parentRunId)??[];O.push(z),I.set(z.parentRunId,O)}const P=(z,O)=>z.startedAt-O.startedAt||z.runId.localeCompare(O.runId);for(const z of U.values())z.sort(P);for(const z of I.values())z.sort(P);return{runsByUserMessageId:U,childrenByParentRunId:I}},[x]),j=v.useCallback((U,I)=>{T(P=>P[U]===I?P:{...P,[U]:I})},[]);return f.jsx(I8,{onOpenLocalLink:i,children:A.map(U=>{const I=U.kind==="single"&&U.message.kind==="user_prompt"?U.message.id:null,P=I?N.get(I)??[]:[];return f.jsxs("div",{className:"mx-auto max-w-[800px] pb-5",children:[f.jsx(MB,{row:U,toolGroupExpanded:U.kind==="tool-group"?k[U.id]??!1:void 0,onToolGroupExpandedChange:j,onAskUserQuestionSubmit:s,onExitPlanModeConfirm:o,onToolRequestAnswer:l,schedules:c,onAutoContinueAccept:u,onAutoContinueReschedule:p,onAutoContinueCancel:h}),P.map(z=>NB(z,0,M,n??"",S,C,E))]},U.id)})})}v.memo(dye);function fye(e=1e3){const[t,n]=v.useState(()=>Date.now()),r=v.useRef(e);return v.useLayoutEffect(()=>{r.current=e}),v.useEffect(()=>{const i=window.setInterval(()=>{n(Date.now())},r.current);return()=>window.clearInterval(i)},[]),t}function hye(e){switch(e.kind){case"bash_shell":return e.command;case"terminal_pty":return`PTY: ${e.cwd}`;case"codex_session":return"Codex session";case"draining_stream":return"Draining stream"}}function pye(e){switch(e.kind){case"bash_shell":return"bash";case"terminal_pty":return"terminal";case"codex_session":return"codex";case"draining_stream":return"stream"}}function mye(e){return"chatId"in e?e.chatId??null:null}function gye(e){return e.kind==="bash_shell"?e.status==="stopping"?"stopping":"running":"active"}function vye(e){return(e.lastOutput??"").split(`
|
|
2597
|
+
`),i=sge(n,r),s=oge(n,r,i);return age(s)}function sge(e,t){const n=e.length,r=t.length,i=Array.from({length:n+1},()=>Array(r+1).fill(0));for(let s=1;s<=n;s++)for(let o=1;o<=r;o++)i[s][o]=e[s-1]===t[o-1]?i[s-1][o-1]+1:Math.max(i[s-1][o],i[s][o-1]);return i}function oge(e,t,n){const r=[];let i=e.length,s=t.length;for(;i>0||s>0;)i>0&&s>0&&e[i-1]===t[s-1]?(r.push({type:"context",text:e[i-1],oldIdx:i,newIdx:s}),i--,s--):s>0&&(i===0||n[i][s-1]>=n[i-1][s])?(r.push({type:"added",text:t[s-1],oldIdx:i,newIdx:s}),s--):(r.push({type:"removed",text:e[i-1],oldIdx:i,newIdx:s}),i--);return r.reverse()}function age(e){return e.map(t=>{const n=t.type==="removed"?"-":t.type==="added"?"+":" ";return{type:t.type,content:`${n}${t.text}`}})}function Sh({content:e,isDiff:t=!1,oldString:n,newString:r}){const i=v.useMemo(()=>t&&n!==void 0&&r!==void 0?ige(n,r):[],[t,n,r]),s=v.useMemo(()=>t?[]:nge(e),[e,t]),o=v.useMemo(()=>s.some(l=>l.lineNumber!==null),[s]);return t&&i.length>0?f.jsx("div",{className:"my-1 rounded-lg border border-border overflow-hidden",children:f.jsx("div",{className:"overflow-auto max-h-64 md:max-h-[50vh]",children:f.jsx("table",{className:"w-full border-collapse text-xs font-mono",children:f.jsx("tbody",{children:i.map((l,c)=>{const u=l.type==="removed"?"bg-destructive/10 dark:bg-destructive/15":l.type==="added"?"bg-success/10 dark:bg-success/15":"",p=l.type==="removed"?"text-destructive":l.type==="added"?"text-success":"text-foreground";return f.jsxs("tr",{className:u,children:[f.jsx("td",{className:`px-2 py-0 select-none w-0 whitespace-nowrap ${l.type==="removed"?"text-destructive/50":l.type==="added"?"text-success/50":"text-muted-foreground/50"}`,children:l.type==="removed"?"-":l.type==="added"?"+":" "}),f.jsx("td",{className:`px-2 py-0 whitespace-pre select-all ${p}`,children:l.content.slice(1)})]},c)})})})})}):f.jsx("div",{className:"my-1 rounded-lg border border-border overflow-hidden",children:f.jsx("div",{className:"overflow-auto max-h-64 md:max-h-[50vh]",children:f.jsx("table",{className:"w-full border-collapse text-xs font-mono",children:f.jsx("tbody",{children:s.map((l,c)=>f.jsxs("tr",{children:[o&&f.jsx("td",{className:"px-2 py-0 select-none w-0 whitespace-nowrap text-muted-foreground/50 text-right",children:l.lineNumber!==null?l.lineNumber:""}),f.jsx("td",{className:"px-2 py-0 whitespace-pre select-all text-foreground",children:rge(l.content)})]},c))})})})})}function W0({attachment:e,onOpenChange:t}){const[n,r]=v.useState({}),i=v.useMemo(()=>e?Gp(e):null,[e]),s=e?n[e.id]:void 0,o=e!=null&&e.contentUrl?cge(e.contentUrl):"";v.useEffect(()=>{if(!e||!i||i.openInNewTab||i.kind==="image"||i.kind==="pdf"||i.kind==="external")return;const u=i.kind;if((s==null?void 0:s.status)==="loading"||(s==null?void 0:s.status)==="ready")return;let p=!1;return r(h=>({...h,[e.id]:{status:"loading"}})),Pce(e.contentUrl,Nce).then(({content:h,truncated:g})=>{if(p)return;if(u==="table"){const _=e.mimeType==="text/tab-separated-values"?" ":",";r(x=>({...x,[e.id]:{status:"ready",kind:"table",truncated:g,table:zce(h,_)}}));return}const b=u==="json"?Oce(h):h;r(_=>({..._,[e.id]:{status:"ready",kind:u,content:b,truncated:g}}))}).catch(h=>{if(p)return;const g=h instanceof Error?h.message:"Unable to load preview.";r(b=>({...b,[e.id]:{status:"error",message:g}}))}),()=>{p=!0}},[e,s==null?void 0:s.status,i]);async function l(){var u;!o||typeof navigator>"u"||!((u=navigator.clipboard)!=null&&u.writeText)||await navigator.clipboard.writeText(o)}function c(){!o||typeof window>"u"||window.open(o,"_blank","noopener,noreferrer")}return f.jsx(Ao,{open:e!==null&&!(i!=null&&i.openInNewTab),onOpenChange:t,children:f.jsx(Ys,{size:"lg",className:"max-w-[min(92vw,960px)] overflow-hidden p-0",children:e&&i&&!i.openInNewTab?f.jsxs(f.Fragment,{children:[f.jsx(KC,{className:"pr-12",children:f.jsx(No,{className:"text-md",children:e.displayName})}),f.jsx(ma,{className:"bg-muted/20 p-4",children:lge(e,i.kind,s)}),f.jsxs(Rl,{className:"items-center justify-between gap-3 px-4 py-3",children:[f.jsxs(Gd,{className:"truncate",children:[e.mimeType," · ",Yp(e.size)]}),f.jsxs("div",{className:"flex items-center gap-2",children:[f.jsxs(BK,{type:"button",onClick:l,children:[f.jsx(FV,{className:"mr-2 h-4 w-4"}),"Copy Link"]}),f.jsxs(Ke,{type:"button",variant:"outline",onClick:c,children:[f.jsx(Jb,{className:"mr-2 h-4 w-4"}),"Open In New Tab"]})]})]})]}):null})})}function lge(e,t,n){if(t==="image")return f.jsx("div",{className:"flex items-center justify-center",children:f.jsx("img",{src:e.contentUrl,alt:e.displayName,className:"max-h-[70vh] w-auto max-w-full rounded-2xl object-contain"})});if(t==="pdf")return f.jsx("iframe",{src:e.contentUrl,title:e.displayName,className:"h-[70vh] w-full rounded-xl border border-border bg-background"});if(!n||n.status==="loading")return f.jsx("div",{className:"flex h-[50vh] items-center justify-center text-sm text-muted-foreground",children:"Loading preview…"});if(n.status==="error")return f.jsx("div",{className:"flex h-[50vh] items-center justify-center text-sm text-destructive",children:n.message});if(n.kind==="markdown"&&n.content!==void 0)return f.jsxs("div",{className:"space-y-3",children:[n.truncated?f.jsx(AS,{message:"Preview truncated to 1024 KB."}):null,f.jsx("div",{className:"prose prose-sm max-w-none overflow-auto rounded-xl border border-border bg-background p-4 prose-invert",children:f.jsx(Xc,{remarkPlugins:[Qc],components:sf(),children:n.content})})]});if(n.kind==="table"&&n.table){const r=n.table.rows.length>0,[i,...s]=n.table.rows,o=[n.truncated?"Preview truncated to 1024 KB.":null,n.table.truncatedRows?`Showing first ${n.table.rows.length} of ${n.table.rowCount} rows.`:null,n.table.truncatedColumns?`Showing first ${v1} of ${n.table.columnCount} columns.`:null].filter(Boolean);return f.jsxs("div",{className:"space-y-3",children:[o.length>0?f.jsx(AS,{message:o.join(" ")}):null,f.jsx("div",{className:"max-h-[70vh] overflow-auto rounded-xl border border-border bg-background",children:f.jsxs("table",{className:"min-w-full border-collapse text-xs",children:[r?f.jsx("thead",{className:"sticky top-0 bg-muted",children:f.jsx("tr",{children:i.map((l,c)=>f.jsx("th",{className:"border-b border-border px-3 py-2 text-left font-medium text-foreground",children:l||" "},`${l}-${c}`))})}):null,f.jsx("tbody",{children:(r?s:n.table.rows).map((l,c)=>f.jsx("tr",{className:"odd:bg-background even:bg-muted/20",children:l.map((u,p)=>f.jsx("td",{className:"max-w-[320px] border-b border-border px-3 py-2 align-top text-foreground",children:f.jsx("div",{className:"whitespace-pre-wrap break-words",children:u||" "})},`${c}-${p}`))},c))})]})})]})}return f.jsxs("div",{className:"space-y-3",children:[n.truncated?f.jsx(AS,{message:"Preview truncated to 1024 KB."}):null,f.jsx(Sh,{content:n.content??""})]})}function AS({message:e}){return f.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-sm text-muted-foreground",children:e})}function cge(e){return typeof window>"u"?e:new URL(e,document.baseURI||window.location.href).toString()}function uge(e){const t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function dge({path:e,linkText:t}){const n=v.useMemo(()=>aE(e),[e]),[r,i]=v.useState({kind:"loading"}),[s,o]=v.useState(!1);v.useEffect(()=>{const N=new AbortController;return fetch(n,{method:"HEAD",signal:N.signal}).then(M=>{var I,P;if(N.signal.aborted)return;if(!M.ok){i({kind:M.status===404?"missing":"error"});return}const j=((P=(I=M.headers.get("Content-Type"))==null?void 0:I.split(";")[0])==null?void 0:P.trim())||"application/octet-stream",U=Number.parseInt(M.headers.get("Content-Length")??"0",10)||0;i({kind:"ready",mimeType:j,size:U})}).catch(()=>{N.signal.aborted||i({kind:"error"})}),()=>N.abort()},[n]);const l=uge(e),c=t||l,u=qce(c,28),p=r.kind==="ready"?r.mimeType:"application/octet-stream",h=r.kind==="ready"?r.size:0,g={id:`local-file-${n}`,kind:"file",displayName:u,absolutePath:e,relativePath:e,contentUrl:n,mimeType:p,size:h};if(r.kind==="missing")return f.jsx("span",{className:"inline-flex align-bottom","data-testid":"local-file-link",children:f.jsx(Sl,{attachment:g,disabledReason:"File no longer available"})});const b=oE(g),_=M6(b,p),x=h>0?Yp(h):null,S=r.kind==="loading",C=r.kind==="error",E=S?f.jsx("span",{className:"text-muted-foreground",children:"Fetching…"}):C?f.jsx("span",{className:"text-muted-foreground",children:"Unable to load"}):f.jsxs(f.Fragment,{children:[_,x?f.jsxs(f.Fragment,{children:[" · ",f.jsx("span",{className:"tabular-nums",children:x})]}):null]}),k=r.kind==="ready"?Gp(g):null,T=k!==null&&!k.openInNewTab,A=[T?"Preview":"Download",c,_,x].filter(Boolean);return T?f.jsxs(f.Fragment,{children:[f.jsx("span",{className:"inline-flex align-bottom","data-testid":"local-file-link",children:f.jsx(Sl,{attachment:g,onClick:()=>o(!0),meta:E,ariaLabel:A.join(", ")})}),f.jsx(W0,{attachment:s?g:null,onOpenChange:N=>o(N)})]}):f.jsx("span",{className:"inline-flex align-bottom","data-testid":"local-file-link",children:f.jsx(Sl,{attachment:g,href:n,download:l,meta:E,ariaLabel:A.join(", ")})})}const fge={readonly:!1,localLinkMode:"open",attachmentMode:"live"},hge=v.createContext(fge);function G0(){return v.useContext(hge)}const Mb=()=>{},L8=v.createContext(Mb);function I8({children:e,onOpenLocalLink:t}){return f.jsx(L8.Provider,{value:t??Mb,children:e})}const R1={Task:Wv,TaskOutput:Wv,Bash:t0,Glob:Nh,Grep:Nh,ExitPlanMode:hN,Read:VP,Edit:aV,Write:cV,Delete:gV,NotebookEdit:Rp,WebFetch:i9,TodoWrite:S9,WebSearch:Nh,KillShell:qW,AskUserQuestion:KP,Skill:$W,EnterPlanMode:hN},j8=iG;function D8(e){return R1[e]?R1[e]:j8}function P8({icon:e,className:t}){return f.jsx(e,{className:t})}function Ca({children:e,className:t}){return f.jsx("div",{className:he("flex gap-3 justify-start items-center",t),children:e})}function O8({children:e,className:t}){return f.jsx("div",{className:he("flex items-center gap-1.5 text-xs",t),children:e})}function Nl({children:e,className:t}){return f.jsx("span",{className:he("font-medium text-foreground/80",t),children:e})}function pge({children:e}){return f.jsx("span",{className:"text-muted-foreground",children:e})}function mge({children:e,className:t}){return f.jsxs(Ca,{className:he("px-0.5 text-xs tracking-wide",t),children:[f.jsx("div",{className:"w-full h-[1px] bg-border"}),f.jsx(Nl,{className:"whitespace-nowrap text-[11px] tracking-widest text-muted-foreground/60 uppercase flex-shrink-0",children:e}),f.jsx("div",{className:"w-full h-[1px] bg-border"})]})}function q0({children:e,expandedContent:t,defaultExpanded:n=!1}){const[r,i]=v.useState(n);return f.jsxs("div",{className:"flex flex-col w-full",children:[f.jsxs("button",{onClick:()=>i(!r),className:`group/expandable-row cursor-pointer grid grid-cols-[auto_1fr] items-center gap-1 text-sm ${r?"":"hover:opacity-60 transition-opacity"}`,children:[f.jsx("div",{className:"grid grid-cols-[auto_1fr] items-center gap-1.5",children:e}),f.jsx(To,{className:`h-4.5 w-4.5 text-muted-icon translate-y-[0.5px] transition-all duration-200 opacity-0 group-hover/expandable-row:opacity-100 ${r?"rotate-90 opacity-100":""}`})]}),r&&t]})}function AI({label:e,children:t,copyText:n}){const[r,i]=v.useState(!1),s=n??Lb(t),o=v.useCallback(async()=>{await navigator.clipboard.writeText(s),i(!0),setTimeout(()=>i(!1),2e3)},[s]);return f.jsxs("div",{children:[f.jsx("span",{className:"font-medium text-muted-foreground",children:e}),f.jsxs("div",{className:"relative group/codeblock",children:[f.jsx("pre",{className:"my-1 text-xs font-mono whitespace-no-wrap break-all bg-muted border border-border rounded-lg p-2 max-h-64 overflow-auto w-full",children:t}),f.jsx(Ke,{variant:"ghost",size:"icon","aria-label":r?"Copied":"Copy code",className:he("absolute top-[4px] right-[4px] z-10 h-11 w-11 md:h-6.5 md:w-6.5 rounded-sm text-muted-foreground opacity-100 md:opacity-0 md:group-hover/codeblock:opacity-100 transition-opacity [@media(hover:none)]:!opacity-100",!r&&"hover:text-foreground",r&&"hover:!bg-transparent hover:!border-transparent"),onClick:o,children:r?f.jsx(gi,{className:"h-3.5 w-3.5 text-success"}):f.jsx(El,{className:"h-4 w-4"})})]})]})}function z8({children:e,icon:t,className:n}){return f.jsxs("span",{className:he("inline-flex items-center gap-1 px-2 py-1 bg-muted border border-border rounded-full",n),children:[t&&f.jsx(t,{className:"h-3 w-3 text-muted-foreground"}),e]})}function K0({children:e,className:t}){return f.jsxs("div",{className:he("grid grid-cols-[auto_1fr] gap-2 min-w-0",t),children:[f.jsx("div",{className:" min-w-5 flex flex-col relative items-center justify-center",children:f.jsx("div",{className:"min-h-full w-[1px] bg-muted-foreground/20"})}),f.jsx("div",{className:"-ml-[1px] min-w-0 overflow-hidden",children:e})]})}function Lb(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(Array.isArray(e))return e.map(Lb).join("");if(e&&typeof e=="object"&&"props"in e){const t=e.props;return Lb(t.children)}return""}function NI(e,t){return v.isValidElement(e)?v.cloneElement(e,{className:he(e.props.className,t)}):e}function gge({children:e,...t}){const[n,r]=v.useState(!1),i=Lb(e),s=async()=>{await navigator.clipboard.writeText(i),r(!0),setTimeout(()=>r(!1),2e3)};return f.jsxs("div",{className:"relative overflow-x-auto max-w-full min-w-0 no-code-highlight group/pre",children:[f.jsx("pre",{className:"min-w-0 rounded-xl py-2.5 px-3.5 [.no-pre-highlight_&]:bg-background",...t,children:e}),f.jsx(Ke,{variant:"ghost",size:"icon","aria-label":n?"Copied":"Copy code",className:he("absolute top-[35px] -translate-y-[50%] -translate-x-[1px] rounded-md right-1.5 h-11 w-11 md:h-8 md:w-8 text-muted-foreground opacity-100 md:opacity-0 md:group-hover/pre:opacity-100 transition-opacity [@media(hover:none)]:!opacity-100",!n&&"hover:text-foreground",n&&"hover:!bg-transparent hover:!border-transparent"),onClick:s,children:n?f.jsx(gi,{className:"h-4 w-4 text-success"}):f.jsx(El,{className:"h-4 w-4"})})]})}const CE={h1:({children:e})=>f.jsx("h1",{className:"text-[20px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h2:({children:e})=>f.jsx("h2",{className:"text-[18px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h3:({children:e})=>f.jsx("h3",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h4:({children:e})=>f.jsx("h4",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h5:({children:e})=>f.jsx("h5",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h6:({children:e})=>f.jsx("h6",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),pre:gge,code:({children:e,className:t,...n})=>t?f.jsx("code",{className:"block text-xs whitespace-pre",...n,children:e}):f.jsx("code",{className:"break-all px-1 bg-border/60 dark:[.no-pre-highlight_&]:bg-background dark:[.text-pretty_&]:bg-neutral [.no-code-highlight_&]:!bg-transparent py-0.5 rounded text-sm whitespace-wrap",...n,children:e}),table:({children:e,...t})=>f.jsx("div",{className:"border border-border rounded-xl overflow-x-auto",children:f.jsx("table",{className:"table-auto min-w-full divide-y divide-border bg-background",...t,children:e})}),tbody:({children:e,...t})=>f.jsx("tbody",{className:"divide-y divide-border",...t,children:e}),th:({children:e,...t})=>f.jsx("th",{className:"text-left text-xs uppercase text-muted-foreground tracking-wider p-2 pl-0 first:pl-3 bg-muted dark:bg-card [&_*]:font-semibold",...t,children:e}),td:({children:e,...t})=>f.jsx("td",{className:"text-left p-2 pl-0 first:pl-3 [&_*]:font-normal ",...t,children:e}),p:({children:e,...t})=>f.jsx("p",{className:"break-words mt-5 mb-3 first:mt-0 last:mb-0",...t,children:e}),blockquote:({children:e,...t})=>(()=>{const n=v.Children.toArray(e),r=n[0];r!==void 0&&(n[0]=NI(r,"mt-0"));const i=n.length-1,s=n[i];return s!==void 0&&(n[i]=NI(s,"mb-0")),f.jsx("blockquote",{className:"my-2 mt-5 mb-3 first:mt-0 last:mb-0 border-l-2 border-border/80 pl-2 text-muted-foreground",...t,children:n})})(),a:({children:e,...t})=>f.jsx("a",{className:"transition-all underline decoration-2 text-logo decoration-logo/50 hover:text-logo/70 dark:text-logo dark:decoration-logo/70 dark:hover:text-logo/60 dark:hover:decoration-logo/40 ",target:"_blank",rel:"noopener noreferrer",...t,children:e}),img:({src:e,...t})=>{const n=typeof e=="string"&&Gce(e)?aE(e):e;return f.jsx("img",{src:n,...t})}};function vge({children:e,href:t,onClick:n,overrideOpenLocalLink:r,...i}){const s=v.useContext(L8),o=r??s,l=G0(),c=Vce(t);if(c&&l.localLinkMode==="text")return f.jsx("span",{className:"transition-all underline decoration-2 text-logo decoration-logo/50",children:e});if(c&&!j6(c.path)){const u=T1(e).trim();return f.jsx(dge,{path:c.path,linkText:u||void 0})}return f.jsx("a",{className:"transition-all underline decoration-2 text-logo decoration-logo/50 hover:text-logo/70 dark:text-logo dark:decoration-logo/70 dark:hover:text-logo/60 dark:hover:decoration-logo/40 ",href:t,target:c?void 0:"_blank",rel:c?void 0:"noopener noreferrer",onClick:u=>{n==null||n(u),!(u.defaultPrevented||!c||o===Mb)&&(u.preventDefault(),o({...c,clientX:u.clientX,clientY:u.clientY,trigger:"click"}))},onContextMenu:u=>{!c||o===Mb||(u.preventDefault(),o({...c,clientX:u.clientX,clientY:u.clientY,trigger:"contextmenu"}))},...i,children:e})}function sf(e){return{...CE,a:t=>f.jsx(vge,{...t,overrideOpenLocalLink:e==null?void 0:e.onOpenLocalLink})}}function T1(e){return e==null||typeof e=="boolean"?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(T1).join(""):v.isValidElement(e)?T1(e.props.children):""}({...CE});function kE({attachment:e,previewUrl:t,onClick:n,onRemove:r,className:i,size:s="transcript",uploadProgress:o,onCancelUpload:l}){const c=e.contentUrl||t,u=s==="composer",p=o!==void 0;return f.jsxs("div",{className:he("group relative flex flex-row items-end",i),children:[f.jsxs("button",{type:"button",onClick:n,className:he("group/image relative overflow-hidden rounded-xl border border-border/80 bg-background shadow-sm",u?"min-w-[80px]":"min-w-[200px]"),children:[c?f.jsx("img",{src:c,alt:e.displayName,className:he("rounded-xl object-contain bg-muted",u?"min-h-[50px] min-w-[80px] max-h-[120px] max-w-[200px]":"min-h-[100px] min-w-[200px] max-h-[300px] max-w-[300px]")}):f.jsx("div",{className:he("flex items-center justify-center rounded-xl bg-muted text-muted-foreground",u?"min-h-[64px] min-w-[80px]":"min-h-[160px] min-w-[200px]"),children:f.jsx(UP,{className:he(u?"size-6":"size-8")})}),f.jsxs("div",{className:he("pointer-events-none absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/75 via-black/30 to-transparent text-left opacity-0 transition-opacity duration-200 group-hover/image:opacity-100",u?"px-2.5 pb-2 pt-6":"px-4 pb-3 pt-10"),children:[f.jsx("div",{className:he("truncate font-medium text-white",u?"text-xs":"text-sm"),children:e.displayName}),f.jsxs("div",{className:"truncate text-xs text-white/80",children:[e.mimeType," · ",Yp(e.size)]})]})]}),p?f.jsx(I6,{progress:o??null,onCancel:l,size:u?"sm":"md",cancelLabel:`Cancel upload of ${e.displayName}`}):null,r&&!p?f.jsx(B8,{displayName:e.displayName,onRemove:r}):null]})}function Sl({attachment:e,onClick:t,onRemove:n,className:r,uploadProgress:i,onCancelUpload:s,href:o,download:l,meta:c,ariaLabel:u,disabledReason:p}){const h=e.kind==="mention"?"text":oE(e),g=_ge(h),b=e.kind==="mention",_=b?bge(e.displayName):e.displayName,x=b?yge(e.displayName):"",S=i!==void 0,C=!!p,E=he("flex w-[200px] items-center gap-2 rounded-xl border border-border bg-background p-1 pr-3 text-left transition-colors",C?"cursor-not-allowed opacity-60":"hover:bg-accent/50"),k=b?f.jsx("div",{className:"max-w-[150px] truncate text-[11px] text-muted-foreground",children:x?`@${x}`:"@mention"}):p?f.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:p}):c!==void 0?f.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:c}):f.jsxs("div",{className:"truncate text-[11px] text-muted-foreground",children:[e.mimeType," · ",Yp(e.size)]}),T=f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"flex min-h-10 min-w-10 items-center justify-center rounded-lg border border-border bg-muted text-muted-foreground",children:f.jsx(P8,{icon:g,className:"size-5"})}),f.jsxs("div",{className:"min-w-0",children:[f.jsx("div",{className:he("max-w-[150px] truncate text-[13px] font-medium",C?"text-muted-foreground line-through":"text-foreground"),children:_}),k]})]});return f.jsxs("div",{className:he("group relative",r),children:[o&&!C?f.jsx("a",{href:o,download:l,rel:"noopener","aria-label":u,className:E,children:T}):f.jsx("button",{type:"button",onClick:C?void 0:t,title:b?e.displayName:void 0,"aria-label":u,"aria-disabled":C||void 0,disabled:C,className:E,children:T}),S?f.jsx(I6,{progress:i??null,onCancel:s,size:"sm",cancelLabel:`Cancel upload of ${e.displayName}`}):null,n&&!S?f.jsx(B8,{displayName:e.displayName,onRemove:n}):null]})}function bge(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function yge(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(0,n):""}function B8({displayName:e,onRemove:t}){return f.jsx("button",{type:"button",className:"absolute right-2 top-2 rounded-full bg-background/90 p-1 text-muted-foreground shadow-sm transition hover:bg-muted hover:text-foreground",onClick:n=>{n.preventDefault(),n.stopPropagation(),t()},"aria-label":`Remove ${e}`,children:f.jsx(eo,{className:"h-3.5 w-3.5"})})}function _ge(e){switch(e){case"image":return UP;case"pdf":return SW;case"markdown":return NW;case"json":return eV;case"table":return dV;case"code":return nV;case"text":return jC;case"archive":return Z9;case"audio":return iV;case"video":return pV;default:return VP}}function Yp(e){return e<1024?`${e} B`:e<1024*1024?`${Math.max(1,Math.round(e/1024))} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}const xge={sm:"text-sm px-2.5 py-1",md:"text-sm px-3 py-1.5"};function wc({value:e,onValueChange:t,options:n,size:r="md",className:i,optionClassName:s}){return f.jsx("div",{className:he("inline-flex items-center rounded-lg border border-border p-[3px] ",i),children:n.map(o=>{const l=o.value===e,c=o.icon,u=c?v.isValidElement(c)?c:(()=>{const h=c;return f.jsx(h,{className:r==="sm"?"h-3.5 w-3.5":"h-4 w-4"})})():null,p=f.jsxs("button",{type:"button",onClick:()=>t(o.value),disabled:o.disabled,"aria-pressed":l,className:he("rounded-[4px] border transition-colors",c?"grid grid-cols-[auto_auto] items-center gap-2":"inline-flex items-center",xge[r],l?"bg-card text-foreground border-border":"border-transparent text-muted-foreground hover:text-foreground",o.disabled&&"opacity-50 pointer-events-none",s),children:[u,f.jsx("span",{children:o.label})]},o.value);return o.tooltip?f.jsxs(Xr,{children:[f.jsx(Qr,{asChild:!0,children:p}),f.jsx(Br,{children:o.tooltip})]},o.value):p})})}const Y0=v.forwardRef(({className:e,...t},n)=>f.jsx("textarea",{"data-gramm":"false","data-gramm_editor":"false","data-enable-grammarly":"false","data-1p-ignore":!0,autoComplete:"off",className:he("flex w-full rounded-lg border border-border bg-background px-2.5 py-2 text-sm placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));Y0.displayName="Textarea";const Yg={};function MI(e){return!e.isCollapsed&&!e.hasPreviewAttachment&&e.patch===void 0&&e.patchError===void 0&&!e.isPatchLoading}function Sge(e,t){return!e||!t.mimeType||typeof t.size!="number"||t.changeType==="deleted"||!t.mimeType.startsWith("image/")&&t.mimeType!=="application/pdf"?null:{id:`diff:${t.path}`,kind:t.mimeType.startsWith("image/")?"image":"file",displayName:t.path.split("/").pop()??t.path,absolutePath:t.path,relativePath:t.path,contentUrl:`/api/projects/${e}/files/${encodeURIComponent(t.path)}/content`,mimeType:t.mimeType,size:t.size}}function F8(e){return e.isUntracked}function wge(e){return F8(e)?e.path.includes("/"):!1}function NS(e){return f.jsxs(Xr,{delayDuration:0,children:[f.jsx(Qr,{asChild:!0,children:f.jsx("button",{type:"button","aria-label":e.label,title:e.label,onClick:e.onClick,className:he("flex h-11 w-11 md:h-7 md:w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",e.active&&"bg-accent text-foreground"),children:e.children})}),f.jsx(Br,{children:e.label})]})}function $8({checked:e,mixed:t=!1,label:n,className:r,onClick:i}){return f.jsx("button",{type:"button","aria-label":n??(e?"Exclude file from commit":"Include file in commit"),"aria-checked":t?"mixed":e,"aria-pressed":t?"mixed":e,onClick:s=>{s.stopPropagation(),i()},className:he("flex size-4.5 shrink-0 items-center justify-center rounded border transition-colors",e||t?"border-foreground bg-foreground text-background":"border-border bg-background text-transparent",r),children:t?f.jsx(nW,{className:"h-3 w-3",strokeWidth:3}):e?f.jsx(gi,{className:"h-3 w-3",strokeWidth:3}):null})}function EE(e){const t=Date.parse(e);if(!Number.isFinite(t))return"";const n=Date.now()-t,r=6e4,i=60*r,s=24*i,o=7*s,l=30*s,c=365*s;return n<r?"just now":n<i?`${Math.round(n/r)}m ago`:n<s?`${Math.round(n/i)}hr ago`:n<o?`${Math.round(n/s)}d ago`:n<l?`${Math.round(n/o)}wk ago`:n<c?`${Math.round(n/l)}mo ago`:`${Math.round(n/c)}yr ago`}function Cge(e){return e?`Last fetched ${EE(e)}`:"No local fetch recorded"}function kge({entry:e,isPendingPush:t=!1}){const n=EE(e.authoredAt),r=!!e.githubUrl;return f.jsxs("button",{type:"button",disabled:!r,onClick:()=>{!e.githubUrl||typeof window>"u"||window.open(e.githubUrl,"_blank","noopener,noreferrer")},className:he("flex w-full items-start gap-3 rounded-lg border border-border bg-background pl-3 pr-2 py-2 text-left transition-colors",r?"hover:bg-accent":"cursor-default opacity-60"),children:[f.jsxs("div",{className:"min-w-0 flex-1",children:[f.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:e.summary}),e.description?f.jsx("div",{className:"mt-1 line-clamp-2 whitespace-pre-wrap text-xs text-muted-foreground",children:e.description}):null,f.jsxs("div",{className:"mt-1 flex min-w-0 items-center gap-1 text-xs text-muted-foreground",children:[e.authorName?f.jsx("span",{className:"truncate",children:e.authorName}):null,e.authorName&&n?f.jsx("span",{"aria-hidden":"true",children:"•"}):null,n?f.jsx("span",{children:n}):null]})]}),e.tags.length>0?f.jsxs("div",{className:"flex shrink-0 flex-wrap justify-end gap-1",children:[e.tags.map(i=>f.jsx("span",{className:"inline-flex items-center rounded-full bg-muted border border-border px-2 py-0.5 text-[11px]",children:i},i)),t?f.jsx("span",{className:"inline-flex items-center rounded-full bg-muted border border-border px-2 py-0.5 text-[11px]",children:f.jsx(Gh,{className:"size-3"})}):null]}):t?f.jsx("div",{className:"flex shrink-0 flex-wrap justify-end gap-1",children:f.jsx("span",{className:"inline-flex items-center rounded-full bg-muted border border-border px-2 py-0.5 text-[11px]",children:f.jsx(Gh,{className:"size-3"})})}):null]})}function LI(e){switch(e.kind){case"local":return 0;case"pull_request":return 1;case"remote":default:return 2}}function Ege(e){const t=new Map;for(const n of e){const r=t.get(n.name);(!r||LI(n)<LI(r))&&t.set(n.name,n)}return t}function Rge(e,t){const n=Ege([...e.local,...e.pullRequests,...e.remote]);t&&n.delete(t);const r=new Set,i=e.defaultBranchName?n.get(e.defaultBranchName):void 0;i&&r.add(i.name);const s=e.recent.map(l=>n.get(l.name)??l).filter(l=>!!l&&!r.has(l.name));for(const l of s)r.add(l.name);const o=[...n.values()].filter(l=>!r.has(l.name)).sort((l,c)=>l.displayName.localeCompare(c.displayName));return{defaultBranch:i,recent:s,other:o}}function Tge({open:e,onOpenChange:t,onGetGitHubPublishInfo:n,onCheckGitHubRepoAvailability:r,onPublish:i}){const[s,o]=v.useState(null),[l,c]=v.useState(!1),[u,p]=v.useState(""),[h,g]=v.useState(""),[b,_]=v.useState("private"),[x,S]=v.useState(""),[C,E]=v.useState(null),[k,T]=v.useState(!1),[A,N]=v.useState(!1);v.useEffect(()=>{if(!e)return;let U=!1;return c(!0),E(null),n().then(I=>{U||(o(I),p(I.owners[0]??I.activeAccountLogin??""),g(I.suggestedRepoName),_("private"),S(""))}).finally(()=>{U||c(!1)}),()=>{U=!0}},[n,e]),v.useEffect(()=>{if(!e||!(s!=null&&s.ghInstalled)||!s.authenticated)return;const U=u.trim(),I=h.trim();if(!U||!I){E(null);return}let P=!1;T(!0);const z=window.setTimeout(()=>{r({owner:U,name:I}).then(O=>{P||E(O)}).finally(()=>{P||T(!1)})},250);return()=>{P=!0,window.clearTimeout(z)}},[s==null?void 0:s.authenticated,s==null?void 0:s.ghInstalled,h,r,e,u]);async function M(){if(!(!u.trim()||!h.trim())){N(!0);try{const U=await i({owner:u.trim(),name:h.trim(),visibility:b,description:x});U!=null&&U.ok&&t(!1)}finally{N(!1)}}}const j=!!(s!=null&&s.ghInstalled&&s.authenticated&&u.trim()&&h.trim()&&(C!=null&&C.available)&&!k&&!A);return f.jsx(Ao,{open:e,onOpenChange:t,children:f.jsxs(Ys,{size:"sm",className:"max-w-[min(92vw,475px)]",children:[f.jsxs(ma,{className:"space-y-2 px-4 pb-4 pt-4",children:[f.jsxs("div",{className:"space-y-1",children:[f.jsx(No,{children:"Push to GitHub"}),f.jsx(Gd,{children:"Create a GitHub repository from this local project using GitHub CLI."})]}),l?f.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[f.jsx(kn,{className:"size-4 animate-spin"}),f.jsx("span",{children:"Checking GitHub CLI…"})]}):s&&!s.ghInstalled?f.jsxs("div",{className:"space-y-2 text-sm text-muted-foreground",children:[f.jsx("p",{children:"GitHub CLI is not installed."}),f.jsx("div",{className:"rounded-lg border border-border px-3 py-2 font-mono text-xs text-foreground",children:"brew install gh"}),f.jsx("p",{children:"Then run:"}),f.jsx("div",{className:"rounded-lg border border-border px-3 py-2 font-mono text-xs text-foreground",children:"gh auth login"})]}):s&&!s.authenticated?f.jsxs("div",{className:"space-y-2 text-sm text-muted-foreground",children:[f.jsx("p",{children:"GitHub CLI is installed but not signed in."}),f.jsx("div",{className:"rounded-lg border border-border px-3 py-2 font-mono text-xs text-foreground",children:"gh auth login"})]}):f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"space-y-2",children:f.jsxs(pl,{value:u,onValueChange:p,children:[f.jsx(aa,{className:"pl-[11px] [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:f.jsx(vc,{placeholder:"Select owner"})}),f.jsx(la,{children:((s==null?void 0:s.owners)??[]).map(U=>f.jsx(Fs,{value:U,children:f.jsxs("span",{className:"flex items-center gap-2",children:[U===(s==null?void 0:s.activeAccountLogin)?f.jsx(n0,{className:"size-4 text-muted-foreground"}):f.jsx(b9,{className:"size-4 text-muted-foreground"}),f.jsx("span",{className:"pl-[1px]",children:U})]})},U))})]})}),f.jsx("div",{className:"space-y-2",children:f.jsxs("div",{className:"relative",children:[f.jsx(ir,{value:h,onChange:U=>g(U.target.value),placeholder:"my-repo",className:"pl-9 pr-10"}),f.jsx(pW,{className:"pointer-events-none absolute inset-y-0 left-3 my-auto size-4 text-muted-foreground"}),k?f.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-3 flex items-center text-muted-foreground",children:f.jsx(kn,{className:"size-4 animate-spin"})}):C?f.jsx("div",{className:"absolute inset-y-0 right-2 flex items-center",children:f.jsxs(Xr,{delayDuration:0,children:[f.jsx(Qr,{asChild:!0,children:f.jsx("button",{type:"button",tabIndex:-1,"aria-label":C.message,className:he("flex size-6 items-center justify-center rounded-md",C.available?"text-success":"text-destructive"),children:C.available?f.jsx(gi,{className:"size-4"}):f.jsx(Gv,{className:"size-4"})})}),f.jsx(Br,{children:C.message})]})}):null]})}),f.jsx("div",{className:"space-y-2",children:f.jsxs("div",{className:"relative",children:[f.jsx(jC,{className:"pointer-events-none absolute left-3 top-3 size-4 text-muted-foreground"}),f.jsx(Y0,{value:x,onChange:U=>S(U.target.value),rows:3,placeholder:"Optional description",className:"pl-9 outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"})]})}),f.jsx("div",{className:"space-y-2",children:f.jsxs(pl,{value:b,onValueChange:U=>_(U),children:[f.jsx(aa,{className:"pl-[11px] [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:f.jsx(vc,{placeholder:"Select visibility"})}),f.jsxs(la,{children:[f.jsx(Fs,{value:"private",children:f.jsxs("span",{className:"flex items-center gap-2",children:[f.jsx(qV,{className:"size-4 text-muted-foreground"}),f.jsx("span",{className:"pl-[1px]",children:"Private"})]})}),f.jsx(Fs,{value:"public",children:f.jsxs("span",{className:"flex items-center gap-2",children:[f.jsx(LV,{className:"size-4 text-muted-foreground"}),f.jsx("span",{className:"pl-[1px]",children:"Public"})]})})]})]})})]})]}),f.jsxs(Rl,{children:[f.jsx(Ke,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),f.jsx(Ke,{size:"sm",disabled:!j,onClick:()=>void M(),children:A?f.jsxs(f.Fragment,{children:[f.jsx(kn,{className:"mr-1.5 size-3.5 animate-spin"}),"Publishing…"]}):"Push to GitHub"})]})]})})}function H8({value:e,onChange:t,placeholder:n,disabled:r,trailingAction:i}){return f.jsxs("div",{className:"relative",children:[f.jsx(Nh,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),f.jsx(ir,{value:e,onChange:s=>t(s.target.value),placeholder:n,className:he("h-9 pl-7 text-sm",i?"pr-14":void 0),disabled:r}),i?f.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2",children:i}):null]})}function Cc({title:e,entries:t,emptyLabel:n,selectedName:r,disabled:i,stickyTitle:s=!1,onSelect:o}){return t.length===0&&!n?null:f.jsxs("div",{className:"space-y-1",children:[f.jsx("div",{className:he("px-1 py-1 text-[11px] font-medium uppercase tracking-[0.08em] text-muted-foreground",s&&"sticky top-0 z-10 bg-background"),children:e}),t.length===0?f.jsx("div",{className:"px-1 py-1 text-xs text-muted-foreground",children:n}):t.map(l=>{const c=r===l.name;return f.jsxs("button",{type:"button",disabled:i,onClick:()=>o(l),className:he("flex w-full items-start gap-2 rounded-lg px-2 py-2 text-left transition-colors disabled:opacity-60",c?"bg-accent text-foreground":"hover:bg-accent"),children:[l.kind==="pull_request"?f.jsx(qP,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):f.jsx(yc,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),f.jsxs("div",{className:"min-w-0 flex-1",children:[f.jsxs("div",{className:"flex w-full items-center gap-3",children:[f.jsx("div",{className:"min-w-0 flex-1 overflow-hidden whitespace-nowrap text-sm text-foreground",children:l.displayName}),l.updatedAt?f.jsx("div",{className:"ml-auto shrink-0 text-right text-[11px] text-muted-foreground",children:EE(l.updatedAt)}):null]}),l.kind==="pull_request"&&l.description||l.headLabel?f.jsx("div",{className:"truncate text-xs text-muted-foreground",children:l.kind==="pull_request"?l.description??l.headLabel??l.name:l.headLabel??void 0}):null]})]},l.id)})]})}function Age({open:e,onOpenChange:t,branchList:n,currentBranchName:r,onPreviewMergeBranch:i,onMergeBranch:s}){const[o,l]=v.useState(""),[c,u]=v.useState(null),[p,h]=v.useState(null),[g,b]=v.useState(null),[_,x]=v.useState(!1),[S,C]=v.useState(!1),E=v.useMemo(()=>n?Rge(n,r):{defaultBranch:void 0,recent:[],other:[]},[n,r]),k=o.trim().toLowerCase(),T=v.useCallback(P=>k?[P.displayName,P.name,P.description,P.prTitle,P.headLabel].some(z=>z==null?void 0:z.toLowerCase().includes(k)):!0,[k]),A=E.defaultBranch&&T(E.defaultBranch)?E.defaultBranch:void 0,N=E.recent.filter(T),M=E.other.filter(T),j=v.useMemo(()=>c?[E.defaultBranch,...E.recent,...E.other].find(P=>P!==void 0&&P.name===c)??null:null,[E.defaultBranch,E.other,E.recent,c]);v.useEffect(()=>{e||(l(""),u(null),h(null),b(null),x(!1),C(!1))},[e]),v.useEffect(()=>{if(!e||!j){h(null),b(null),x(!1);return}let P=!1;return h(null),b(null),x(!0),i(j).then(z=>{P||h(z)}).catch(z=>{P||b(z instanceof Error?z.message:String(z))}).finally(()=>{P||x(!1)}),()=>{P=!0}},[i,e,j]);const U=!j||!p||_||S||p.status!=="mergeable";async function I(){if(!(!j||U)){C(!0);try{const P=await s(j);P!=null&&P.ok&&t(!1)}finally{C(!1)}}}return f.jsx(Ao,{open:e,onOpenChange:t,children:f.jsxs(Ys,{size:"sm",className:"max-w-[min(92vw,475px)]",children:[f.jsxs(ma,{className:"flex min-h-0 flex-col gap-3 px-4 pb-4 pt-4",children:[f.jsxs("div",{className:"space-y-1",children:[f.jsxs(No,{children:["Merge into ",r??"current branch"]}),f.jsx(Gd,{children:"Choose a branch to continue."})]}),f.jsx(H8,{value:o,onChange:l,placeholder:"Search branches"}),f.jsxs("div",{className:"max-h-[375px] space-y-3 overflow-y-auto pr-1",children:[f.jsx(Cc,{title:"Default Branch",entries:A?[A]:[],emptyLabel:"No default branch available.",selectedName:c,onSelect:P=>u(P.name)}),f.jsx(Cc,{title:"Recent Branches",entries:N,emptyLabel:"No recent branches.",selectedName:c,onSelect:P=>u(P.name)}),f.jsx(Cc,{title:"Other Branches",entries:M,emptyLabel:"No other branches match this search.",selectedName:c,onSelect:P=>u(P.name)})]}),f.jsx("div",{className:"px-2",children:j?_?f.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[f.jsx(kn,{className:"size-3.5 animate-spin"}),f.jsx("span",{children:"Checking merge preview…"})]}):g?f.jsx("div",{className:"text-sm text-destructive",children:g}):p?f.jsxs("div",{className:"flex items-start gap-2",children:[p.status==="up_to_date"?f.jsx(gi,{className:"mt-1 size-3.5 shrink-0 text-success"}):p.status==="conflicts"?f.jsx(Gv,{className:"mt-1 size-3.5 shrink-0 text-warning"}):p.status==="mergeable"?f.jsx(GP,{className:"mt-1 size-3.5 shrink-0 text-muted-foreground"}):f.jsx(Gv,{className:"mt-1 size-3.5 shrink-0 text-destructive"}),f.jsxs("div",{className:"min-w-0 space-y-1",children:[f.jsx("div",{className:"text-sm font-medium text-foreground",children:p.message}),p.detail?f.jsx("div",{className:"line-clamp-2 whitespace-pre-wrap text-xs text-muted-foreground",children:p.detail}):null]})]}):f.jsx("div",{className:"text-sm text-muted-foreground",children:"Preview unavailable."}):f.jsx("div",{className:"text-sm text-muted-foreground",children:"Select a branch to preview the merge."})})]}),f.jsx(Rl,{children:f.jsxs("div",{className:"flex min-w-0 w-full items-center justify-end gap-2",children:[f.jsx(Ke,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),f.jsx(Ke,{className:"max-w-full min-w-0",size:"sm",disabled:U,onClick:()=>void I(),children:S?f.jsxs(f.Fragment,{children:[f.jsx(kn,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),"Merging…"]}):f.jsx("span",{className:"block max-w-full truncate",children:"Merge"})})]})})]})})}function Nge({currentBranchName:e,onListBranches:t,onPreviewMergeBranch:n,onMergeBranch:r,onCheckoutBranch:i,onCreateBranch:s}){const[o,l]=v.useState(!1),[c,u]=v.useState(!1),[p,h]=v.useState(!1),[g,b]=v.useState(!1),[_,x]=v.useState(""),[S,C]=v.useState("branches"),[E,k]=v.useState(null),[T,A]=v.useState(null);v.useEffect(()=>{o&&(h(!0),A(null),t().then(W=>k(W)).catch(W=>{A(W instanceof Error?W.message:String(W))}).finally(()=>{h(!1)}))},[t,o]);const N=_.trim().toLowerCase(),M=W=>W.filter(Z=>N?[Z.displayName,Z.name,Z.description,Z.prTitle,Z.headLabel].some(D=>D==null?void 0:D.toLowerCase().includes(N)):!0),j=(E==null?void 0:E.currentBranchName)??e,U=new Set(((E==null?void 0:E.pullRequests)??[]).map(W=>W.headRefName??W.name)),I=M((E==null?void 0:E.recent)??[]).filter(W=>W.name!==j),P=M((E==null?void 0:E.local)??[]).filter(W=>W.name!==j),z=M((E==null?void 0:E.remote)??[]).filter(W=>W.name!==j&&!U.has(W.name)),O=M((E==null?void 0:E.pullRequests)??[]).filter(W=>W.name!==j),$=(E==null?void 0:E.pullRequests.length)??0;async function V(W){b(!0);try{await i(W),l(!1),x(""),C("branches")}finally{b(!1)}}async function F(){b(!0);try{await s(),l(!1),x(""),C("branches")}finally{b(!1)}}function H(){l(!1),u(!0)}return f.jsxs(wk,{open:o,onOpenChange:l,children:[f.jsx(Ck,{asChild:!0,children:f.jsxs("button",{type:"button",className:"flex min-w-0 max-w-full items-center gap-1 rounded-md px-1.5 py-1 text-sm transition-colors hover:bg-accent hover:text-foreground","aria-label":"Open branch switcher",children:[f.jsx(yc,{className:"h-3.5 w-3.5 shrink-0"}),f.jsx("span",{className:"truncate",children:e??"Detached HEAD"}),f.jsx(Hd,{className:"h-3.5 w-3.5 shrink-0"})]})}),f.jsx(S0,{align:"start",className:"w-[320px] p-2",children:f.jsxs("div",{className:"space-y-2",children:[f.jsx(H8,{value:_,onChange:x,placeholder:S==="pull_requests"?"Search pull requests":"Search branches",disabled:p||g,trailingAction:f.jsx(Ke,{variant:"ghost",size:"sm",onClick:()=>void F(),disabled:p||g,className:"h-7 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:"+ New"})}),f.jsx(wc,{value:S,onValueChange:W=>C(W),size:"sm",className:"w-full",optionClassName:"flex-1 justify-center",options:[{value:"branches",label:"Branches"},{value:"pull_requests",label:`Open PRs ${$}`}]}),f.jsx("div",{className:"max-h-[420px] overflow-y-auto pr-1.5 -mr-[8px]",children:p?f.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-sm text-muted-foreground",children:[f.jsx(kn,{className:"h-4 w-4 animate-spin"}),f.jsx("span",{children:"Loading branches…"})]}):T?f.jsx("div",{className:"rounded-lg border border-border px-3 py-2 text-sm text-muted-foreground",children:T}):S==="pull_requests"?f.jsx(Cc,{title:"Open PRs",entries:O,emptyLabel:(E==null?void 0:E.pullRequestsStatus)==="error"?E.pullRequestsError??"Could not load pull requests.":(E==null?void 0:E.pullRequestsStatus)==="unavailable"?"Pull requests unavailable for this repository.":"No open pull requests.",disabled:g,stickyTitle:!0,onSelect:W=>{V(W)}}):f.jsxs("div",{className:"space-y-3",children:[f.jsx(Cc,{title:"Recent",entries:I,emptyLabel:"No recent branches.",disabled:g,stickyTitle:!0,onSelect:W=>{V(W)}}),f.jsx(Cc,{title:"Local",entries:P,emptyLabel:"No local branches.",disabled:g,stickyTitle:!0,onSelect:W=>{V(W)}}),f.jsx(Cc,{title:"Remote",entries:z,emptyLabel:"No remote branches.",disabled:g,stickyTitle:!0,onSelect:W=>{V(W)}})]})}),j?f.jsx(Ke,{variant:"default",size:"sm",disabled:p||g||!!T,onClick:H,className:"h-9 w-full justify-center rounded-lg px-3 text-sm",children:f.jsxs("span",{className:"block max-w-full truncate",children:[f.jsx(RV,{className:"mr-1.5 inline h-3.5 w-3.5 shrink-0"}),"Merge branch into ",j,"..."]})}):null]})}),f.jsx(Age,{open:c,onOpenChange:u,branchList:E,currentBranchName:j,onPreviewMergeBranch:n,onMergeBranch:r})]})}function Mge({file:e,rootRef:t,projectId:n,isCollapsed:r,isChecked:i,editorLabel:s,diffRenderMode:o,wrapLines:l,onToggleCollapsed:c,onToggleChecked:u,fileActions:p,patch:h,patchError:g,isPatchLoading:b,onLoadPatch:_}){const x=F8(e),S=wge(e),[C,E]=v.useState(null),k=v.useRef(null),T=v.useRef(null),{sentinelRef:A,isStuck:N}=wce({rootRef:t,disabled:r}),M=v.useMemo(()=>Sge(n,e),[e,n]),j=M!==null,U=MI({isCollapsed:r,hasPreviewAttachment:j,patch:h,patchError:g,isPatchLoading:b});v.useEffect(()=>{if(!U)return;const O=`${e.path}\0${e.patchDigest}`;T.current!==O&&(T.current=O,_(e.path).catch(()=>{}))},[e.patchDigest,e.path,_,U]);function I(O){if(Gp(O).openInNewTab){typeof window<"u"&&window.open(new URL(O.contentUrl,window.location.origin).toString(),"_blank","noopener,noreferrer");return}E(O.id)}function P(O){var V;O.preventDefault(),O.stopPropagation();const $=O.currentTarget.getBoundingClientRect();(V=k.current)==null||V.dispatchEvent(new MouseEvent("contextmenu",{bubbles:!0,cancelable:!0,clientX:$.left+$.width/2,clientY:$.bottom,view:window}))}function z(){if(!r){c();return}if(j||h!==void 0){c();return}if(b)return;if(!(g!==void 0||MI({isCollapsed:!1,hasPreviewAttachment:j,patch:h,patchError:g,isPatchLoading:b}))){c();return}_(e.path).then(()=>{c()}).catch(()=>{})}return f.jsxs(qc,{children:[f.jsx(Kc,{asChild:!0,children:f.jsxs("div",{ref:k,className:"relative rounded-lg border border-border bg-background",children:[r?null:f.jsx("div",{ref:A,className:"pointer-events-none absolute inset-x-0 top-0 h-px","aria-hidden":"true"}),f.jsxs("div",{role:"button",tabIndex:0,onClick:z,onKeyDown:O=>{O.key!=="Enter"&&O.key!==" "||(O.preventDefault(),z())},className:he("group/header sticky top-0 z-20 flex cursor-pointer items-center justify-between gap-3 bg-background pl-[7px] pr-2.5 py-1.5 text-[13px] text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",!r&&!N&&"rounded-t-[calc(theme(borderRadius.lg)-1px)]",r&&"rounded-[calc(theme(borderRadius.lg)-1px)]",!r&&"border-b border-border/50"),children:[f.jsxs("div",{className:"flex min-w-0 items-center",children:[f.jsx($8,{checked:i,onClick:u}),f.jsx("div",{className:"min-w-0 truncate select-none ml-2 mr-1",children:e.path})]}),f.jsxs("div",{className:"flex shrink-0 items-center gap-2 select-none",children:[f.jsxs("span",{className:"whitespace-nowrap text-xs font-mono",children:[e.additions>0?f.jsxs("span",{className:"text-success",children:["+",e.additions]}):null,e.deletions>0?f.jsxs("span",{className:e.additions>0?"ml-2 text-destructive":"text-destructive",children:["-",e.deletions]}):null]}),f.jsx("button",{type:"button","aria-label":`Open actions for ${e.path}`,onClick:P,className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:f.jsx(qh,{className:"h-3.5 w-3.5 shrink-0"})}),b&&r&&!M?f.jsx(kn,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):r?f.jsx(Hd,{className:"h-3.5 w-3.5 shrink-0"}):f.jsx($P,{className:"h-3.5 w-3.5 shrink-0"})]})]}),r?null:f.jsx("div",{className:"kanna-diff-patch overflow-hidden rounded-b-[calc(theme(borderRadius.lg)-1px)] pb-[1px]",children:M?f.jsx("div",{className:"flex justify-center p-3",children:M.kind==="image"?f.jsx(kE,{attachment:M,onClick:()=>I(M)}):f.jsx(Sl,{attachment:M,onClick:()=>I(M)})}):b?f.jsxs("div",{className:"flex items-center justify-center px-3 py-8 text-sm text-muted-foreground",children:[f.jsx(kn,{className:"mr-2 h-4 w-4 animate-spin"}),"Loading diff..."]}):g?f.jsx("div",{className:"px-3 py-4 text-sm text-destructive",children:g}):h!==void 0?f.jsx(xce,{patch:h,options:{diffStyle:o,disableFileHeader:!0,disableBackground:!1,overflow:l?"wrap":"scroll",lineDiffType:"word",diffIndicators:"classic"}}):f.jsx("div",{className:"px-3 py-4 text-sm text-muted-foreground",children:"Diff unavailable."})}),f.jsx(W0,{attachment:M&&C===M.id?M:null,onOpenChange:O=>!O&&E(null)})]},e.path)}),f.jsxs(jl,{children:[f.jsxs(jn,{onSelect:O=>{O.stopPropagation(),p.onOpenFile(e.path)},children:[f.jsx(IC,{className:"h-3.5 w-3.5"}),f.jsxs("span",{className:"text-xs font-medium",children:["Open in ",s]})]}),f.jsxs(jn,{onSelect:O=>{O.stopPropagation(),p.onOpenInFinder(e.path)},children:[f.jsx(e0,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Open in Finder"})]}),f.jsxs(jn,{onSelect:O=>{O.stopPropagation(),p.onDiscardFile(e.path)},className:"text-destructive hover:bg-destructive/10 focus:bg-destructive/10",children:[f.jsx(Ud,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Discard Changes"})]}),f.jsxs(jn,{disabled:!x,onSelect:O=>{O.stopPropagation(),x&&p.onIgnoreFile(e.path)},children:[f.jsx(aN,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Ignore File"})]}),f.jsxs(jn,{disabled:!S,onSelect:O=>{O.stopPropagation(),S&&p.onIgnoreFolder(e.path)},children:[f.jsx(aN,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Ignore folder..."})]}),f.jsx(C3,{}),f.jsxs(jn,{onSelect:O=>{O.stopPropagation(),p.onCopyFilePath(e.path)},children:[f.jsx(El,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Copy File Path"})]}),f.jsxs(jn,{onSelect:O=>{O.stopPropagation(),p.onCopyRelativePath(e.path)},children:[f.jsx(El,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Copy Relative Path"})]})]})]})}function Lge({projectId:e,diffs:t,editorLabel:n,diffRenderMode:r,wrapLines:i,onOpenFile:s,onOpenInFinder:o,onDiscardFile:l,onIgnoreFile:c,onIgnoreFolder:u,onCopyFilePath:p,onCopyRelativePath:h,onListBranches:g,onPreviewMergeBranch:b,onMergeBranch:_,onCheckoutBranch:x,onCreateBranch:S,onGenerateCommitMessage:C,onInitializeGit:E,onGetGitHubPublishInfo:k,onCheckGitHubRepoAvailability:T,onSetupGitHub:A,onCommit:N,onSyncWithRemote:M,onLoadPatch:j,onDiffRenderModeChange:U,onWrapLinesChange:I}){var Je;const P=v.useMemo(()=>({onOpenFile:s,onOpenInFinder:o,onDiscardFile:l,onIgnoreFile:c,onIgnoreFolder:u,onCopyFilePath:p,onCopyRelativePath:h}),[s,o,l,c,u,p,h]),z=t.files.length>0,[O,$]=v.useState(!1),[V,F]=v.useState(null),[H,W]=v.useState(!1),[Z,D]=v.useState(!1),[G,ee]=v.useState({}),[B,le]=v.useState({}),[oe,J]=v.useState({}),ne=v.useRef(null),se=v.useRef({}),ce=v.useMemo(()=>t.files.map(Se=>Se.path),[t.files]),de=v.useMemo(()=>ce.join("\0"),[ce]),Ne=Ni(Se=>{var nt;return e?((nt=Se.projectUi[e])==null?void 0:nt.viewMode)??(z?"changes":"history"):z?"changes":"history"}),we=Ni(Se=>{var nt;return e?((nt=Se.projectUi[e])==null?void 0:nt.collapsedPaths)??Yg:Yg}),je=Ni(Se=>{var nt;return e?((nt=Se.projectUi[e])==null?void 0:nt.summary)??"":""}),fe=Ni(Se=>{var nt;return e?((nt=Se.projectUi[e])==null?void 0:nt.description)??"":""}),ot=Ni(Se=>Se.reconcileCollapsedPaths),Mt=Ni(Se=>Se.toggleCollapsedPath),Et=Ni(Se=>Se.setViewMode),Xt=Ni(Se=>Se.setCommitDraft),Dt=Ni(Se=>Se.clearCommitDraft),mt=Hg(Se=>e?Se.checkedPathsByProjectId[e]??Yg:Yg),yt=Hg(Se=>Se.reconcileProject),Wt=Hg(Se=>Se.setChecked),Lt=Hg(Se=>Se.setAllChecked),gt=v.useRef(z);v.useEffect(()=>{e&&ot(e,ce)},[ce,de,e,ot]),v.useEffect(()=>{const Se=Object.fromEntries(t.files.map(Ye=>[Ye.path,Ye.patchDigest])),nt=Ye=>se.current[Ye]===Se[Ye];ee(Ye=>Object.fromEntries(Object.entries(Ye).filter(([De])=>ce.includes(De)&&nt(De)))),le(Ye=>Object.fromEntries(Object.entries(Ye).filter(([De])=>ce.includes(De)&&nt(De)))),J(Ye=>Object.fromEntries(Object.entries(Ye).filter(([De])=>ce.includes(De)&&nt(De)))),se.current=Se},[t.files,ce,de]),v.useEffect(()=>{e&&yt(e,ce)},[ce,de,e,yt]),v.useEffect(()=>{if(!e)return;if(gt.current!==z){Et(e,z?"changes":"history"),gt.current=z;return}gt.current=z},[z,e,Et]);const Bt=v.useMemo(()=>t.files.filter(Se=>mt[Se.path]??!0).map(Se=>Se.path),[mt,t.files]),ge=Bt.length,ye=t.files.length>0&&ge===t.files.length,ze=ge>0&&ge<t.files.length,Xe=je.trim(),Me=Xe.length>0,Be=V!==null,et=O||Be,We=((Je=t.branchHistory)==null?void 0:Je.entries)??[],qe=t.behindCount??0,ft=t.aheadCount??0,rt=t.hasUpstream===!0,Qt=t.hasUpstream===!1&&!!t.branchName,lt=t.hasOriginRemote===!0,Jt=t.branchName?t.branchName.split("/").map(Se=>encodeURIComponent(Se)).join("/"):null,dn=Qt?"publish":qe>0?"pull":"fetch",At=t.originRepoSlug&&Jt?`https://github.com/${t.originRepoSlug}/compare/${Jt}?expand=1`:null,Rt=!!(rt&&At&&t.branchName&&t.branchName!==t.defaultBranchName),Ct=t.status==="ready"&&ge>0&&!et,Ue=t.status==="ready"&&ge>0&&Me&&!et,vt=lt?"commit_and_push":"commit_only",ht=t.branchName??"current branch";async function Ot(Se){if(Ue){F(Se);try{const nt=await N({paths:Bt,summary:Xe,description:fe.trim(),mode:Se});(nt!=null&&nt.ok||nt!=null&&nt.localCommitCreated)&&e&&Dt(e)}finally{F(null)}}}async function Ft(){if(Ct){$(!0);try{const Se=await C({paths:Bt});e&&Xt(e,{summary:Se.subject,description:Se.body})}finally{$(!1)}}}function xe(Se){if(!(!(Se.metaKey||Se.ctrlKey)||Se.key!=="Enter")){if(Se.preventDefault(),Me){Ot(vt);return}Ft()}}async function Ge(Se=dn){if(!(t.status!=="ready"||H)){W(!0);try{await M(Se)}finally{W(!1)}}}const it=v.useCallback(async Se=>{var nt;if(G[Se]!==void 0||oe[Se])return G[Se]??"";J(Ye=>({...Ye,[Se]:!0})),le(Ye=>{if(!(Se in Ye))return Ye;const{[Se]:De,...It}=Ye;return It});try{const Ye=await j(Se);ee(It=>({...It,[Se]:Ye}));const De=(nt=t.files.find(It=>It.path===Se))==null?void 0:nt.patchDigest;return De&&(se.current={...se.current,[Se]:De}),Ye}catch(Ye){const De=Ye instanceof Error?Ye.message:String(Ye);throw le(It=>({...It,[Se]:De})),Ye}finally{J(Ye=>{const{[Se]:De,...It}=Ye;return It})}},[t.files,oe,j,G]);return f.jsx("div",{className:"h-full min-h-0 border-l border-border bg-background md:min-w-[370px]",children:f.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[f.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pl-2.5 pr-2 py-2",children:[f.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:f.jsx(Nge,{currentBranchName:t.branchName,onListBranches:g,onPreviewMergeBranch:b,onMergeBranch:_,onCheckoutBranch:x,onCreateBranch:S})}),t.status==="ready"?lt?dn==="publish"?f.jsxs(Ke,{variant:"ghost",size:"sm",onClick:()=>void Ge(),disabled:H,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[H?f.jsx(kn,{className:"h-3.5 w-3.5 animate-spin"}):f.jsx(vv,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Publish Branch"})]}):f.jsxs("div",{className:"flex items-center gap-1",children:[dn==="fetch"?f.jsxs(Xr,{delayDuration:0,children:[f.jsx(Qr,{asChild:!0,children:f.jsxs(Ke,{variant:"ghost",size:"sm",onClick:()=>void Ge(),disabled:H,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[H?f.jsx(kn,{className:"h-3.5 w-3.5 animate-spin"}):f.jsx(CW,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Fetch"})]})}),f.jsx(Br,{children:Cge(t.lastFetchedAt)})]}):f.jsxs(Ke,{variant:"ghost",size:"sm",onClick:()=>void Ge(),disabled:H,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[H?f.jsx(kn,{className:"h-3.5 w-3.5 animate-spin"}):f.jsx(HP,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Pull"}),f.jsx("span",{className:"inline-flex min-w-4 items-center justify-center rounded-full bg-muted px-1 text-[10px] text-muted-foreground",children:qe})]}),rt&&ft>0?f.jsxs(Ke,{variant:"default",size:"sm",onClick:()=>void Ge("push"),disabled:H,className:"h-7 gap-1.5 px-2 text-xs",children:[H?f.jsx(kn,{className:"h-3.5 w-3.5 animate-spin"}):f.jsx(vv,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Push"}),f.jsx("span",{className:"inline-flex min-w-4 items-center justify-center rounded-full bg-primary-foreground/15 px-1 text-[10px] text-primary-foreground",children:ft})]}):null,Rt&&At?f.jsxs(Ke,{variant:"ghost",size:"sm",onClick:()=>{typeof window>"u"||window.open(At,"_blank","noopener,noreferrer")},className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[f.jsx(qP,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"PR"})]}):null]}):f.jsxs(Ke,{variant:"default",size:"sm",onClick:()=>D(!0),className:"h-7 gap-1.5 px-3 text-xs",children:[f.jsx(NV,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Push to GitHub"})]}):null]}),f.jsxs("div",{className:"relative min-h-0 flex-1",children:[f.jsx("div",{className:"sticky top-0 z-30 pl-[14px] pr-[12px] pt-[6px] bg-gradient-to-b from-background to-transparent",children:f.jsx("div",{className:"relative h-[40px] flex min-w-0 items-center justify-center gap-[13px]",children:f.jsxs("div",{className:"flex min-w-0 flex-1 items-center justify-between gap-[13px] relative",children:[Ne==="changes"?f.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-muted-foreground/70",children:[f.jsx($8,{checked:ye,mixed:ze,label:ze?"Select all files for commit":ye?"Unselect all files from commit":"Select all files for commit",onClick:()=>{!e||t.files.length===0||Lt(e,ce,ze?!0:!ye)}}),f.jsxs("span",{children:[ge," files"]})]}):f.jsx("div",{}),f.jsx("div",{className:"pointer-events-none absolute left-1/2 -translate-x-1/2 top-1/2 -translate-y-1/2",children:f.jsx("div",{className:"pointer-events-auto",children:f.jsx(wc,{value:Ne,onValueChange:Se=>{e&&Et(e,Se)},size:"sm",optionClassName:"flex-1 justify-center",options:[{value:"changes",label:"Changes"},{value:"history",label:"History"}]})})}),Ne==="changes"?f.jsxs("div",{className:"flex items-center gap-1",children:[f.jsx(NS,{label:"Unified diff",active:r==="unified",onClick:()=>U("unified"),children:f.jsx(TW,{className:"h-4 w-4"})}),f.jsx(NS,{label:"Side-by-side diff",active:r==="split",onClick:()=>U("split"),children:f.jsx(z9,{className:"h-4 w-4"})}),f.jsx(NS,{label:i?"Disable word wrap":"Enable word wrap",active:i,onClick:()=>I(!i),children:f.jsx(nG,{className:"h-4 w-4"})})]}):f.jsx("div",{})]})})}),f.jsx("div",{ref:ne,className:"h-full overflow-y-auto [scrollbar-gutter:stable]",children:t.status==="no_repo"?f.jsx("div",{className:"flex h-full items-center justify-center px-6 py-3 text-center",children:f.jsxs("div",{className:"flex max-w-[280px] flex-col items-center gap-3",children:[f.jsx("p",{className:"text-sm text-muted-foreground",children:"Initialize git here to start tracking branches, diffs, and history."}),f.jsx(Ke,{size:"sm",onClick:()=>void E(),children:"Init Git"})]})}):Ne==="history"?We.length===0?f.jsx("div",{className:"flex h-full items-center justify-center px-6 py-3 text-center",children:f.jsxs("p",{className:"text-sm text-muted-foreground",children:["No recent commits on ",t.branchName??"this branch","."]})}):f.jsx("div",{className:"space-y-1.5 p-1.5",children:We.map((Se,nt)=>f.jsx(kge,{entry:Se,isPendingPush:nt<ft},Se.sha))}):t.files.length===0?f.jsx("div",{className:"flex h-full items-center justify-center px-6 py-3 text-center",children:f.jsx("p",{className:"text-sm text-muted-foreground",children:"No file changes."})}):f.jsxs("div",{className:"space-y-1.5 p-1.5 pb-10",children:[t.files.map(Se=>{const nt=we[Se.path]??!0,Ye=mt[Se.path]??!0;return f.jsx(Mge,{file:Se,rootRef:ne,projectId:e,isCollapsed:nt,isChecked:Ye,editorLabel:n,diffRenderMode:r,wrapLines:i,onToggleCollapsed:()=>{e&&Mt(e,Se.path)},onToggleChecked:()=>{e&&Wt(e,Se.path,!Ye)},fileActions:P,patch:G[Se.path],patchError:B[Se.path],isPatchLoading:!!oe[Se.path],onLoadPatch:it},Se.path)}),Ne==="changes"?f.jsxs("div",{className:"pointer-events-none sticky inset-x-0 bottom-11 py-1 pb-6 z-30 overflow-y-auto",children:[f.jsx("div",{className:"absolute inset-x-0 bottom-0 top-0 bg-gradient-to-t from-background to-transparent"}),f.jsx("div",{className:"pointer-events-auto relative",children:f.jsxs("div",{className:"space-y-0 rounded-xl mx-auto max-w-[700px]",children:[f.jsx(ir,{value:je,onChange:Se=>{e&&Xt(e,{summary:Se.target.value,description:fe})},onKeyDown:xe,placeholder:"Commit message (override)",className:"rounded-t-xl rounded-b-none px-3",disabled:et||t.status!=="ready"}),f.jsx(Y0,{value:fe,onChange:Se=>{e&&Xt(e,{summary:je,description:Se.target.value})},onKeyDown:xe,placeholder:"Description",rows:5,className:"-mt-px rounded-t-none rounded-b-xl px-3 outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background mb-2",disabled:et||t.status!=="ready"}),f.jsx("div",{className:"w-full flex flex-row",children:f.jsxs(qc,{children:[f.jsx(Kc,{asChild:!0,children:f.jsx(Ke,{type:"button",className:"-mt-px w-full rounded-xl",disabled:Me?!Ue:!Ct,onClick:()=>{if(Me){Ot(vt);return}Ft()},children:f.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[Me?Be?f.jsx(kn,{strokeWidth:2.5,className:"size-3 shrink-0 animate-spin"}):vt==="commit_and_push"?t.hasUpstream?f.jsx(vv,{strokeWidth:2.5,className:"size-3 shrink-0"}):f.jsx(GP,{strokeWidth:2.5,className:"size-3 shrink-0"}):f.jsx(gi,{strokeWidth:2.5,className:"size-3 shrink-0"}):O?f.jsx(kn,{strokeWidth:2.5,className:"size-3 shrink-0 animate-spin"}):f.jsx(fW,{strokeWidth:2.5,className:"size-3 shrink-0"}),f.jsx("span",{className:"min-w-0 truncate text-left",children:Me?Be?V==="commit_only"?"Committing...":"Committing & Pushing...":vt==="commit_only"?f.jsxs(f.Fragment,{children:["Commit to ",f.jsx(yc,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),ht]}):t.hasUpstream?f.jsxs(f.Fragment,{children:["Commit & push to ",f.jsx(yc,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),ht]}):f.jsxs(f.Fragment,{children:["Commit & publish ",f.jsx(yc,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),ht]}):O?"Generating...":f.jsxs(f.Fragment,{children:["Generate message for ",f.jsx(yc,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),ht]})})]})})}),t.hasUpstream?f.jsx(jl,{children:f.jsx(jn,{disabled:!Me||!Ue,onSelect:Se=>{Se.stopPropagation(),Ot("commit_only")},children:"Commit Only"})}):null]})})]})})]}):null]})})]}),f.jsx(Tge,{open:Z,onOpenChange:D,onGetGitHubPublishInfo:k,onCheckGitHubRepoAvailability:T,onPublish:A})]})})}const Ige=v.memo(Lge);function jge(e,t){const n=getComputedStyle(e),r=parseFloat(n.fontSize);return t*r}function Dge(e,t){const n=getComputedStyle(e.ownerDocument.body),r=parseFloat(n.fontSize);return t*r}function Pge(e){return e/100*window.innerHeight}function Oge(e){return e/100*window.innerWidth}function zge(e){switch(typeof e){case"number":return[e,"px"];case"string":{const t=parseFloat(e);return e.endsWith("%")?[t,"%"]:e.endsWith("px")?[t,"px"]:e.endsWith("rem")?[t,"rem"]:e.endsWith("em")?[t,"em"]:e.endsWith("vh")?[t,"vh"]:e.endsWith("vw")?[t,"vw"]:[t,"%"]}}}function wh({groupSize:e,panelElement:t,styleProp:n}){let r;const[i,s]=zge(n);switch(s){case"%":{r=i/100*e;break}case"px":{r=i;break}case"rem":{r=Dge(t,i);break}case"em":{r=jge(t,i);break}case"vh":{r=Pge(i);break}case"vw":{r=Oge(i);break}}return r}function Mi(e){return parseFloat(e.toFixed(3))}function Ld({group:e}){const{orientation:t,panels:n}=e;return n.reduce((r,i)=>(r+=t==="horizontal"?i.element.offsetWidth:i.element.offsetHeight,r),0)}function A1(e){const{panels:t}=e,n=Ld({group:e});return n===0?t.map(r=>({groupResizeBehavior:r.panelConstraints.groupResizeBehavior,collapsedSize:0,collapsible:r.panelConstraints.collapsible===!0,defaultSize:void 0,disabled:r.panelConstraints.disabled,minSize:0,maxSize:100,panelId:r.id})):t.map(r=>{const{element:i,panelConstraints:s}=r;let o=0;if(s.collapsedSize!==void 0){const p=wh({groupSize:n,panelElement:i,styleProp:s.collapsedSize});o=Mi(p/n*100)}let l;if(s.defaultSize!==void 0){const p=wh({groupSize:n,panelElement:i,styleProp:s.defaultSize});l=Mi(p/n*100)}let c=0;if(s.minSize!==void 0){const p=wh({groupSize:n,panelElement:i,styleProp:s.minSize});c=Mi(p/n*100)}let u=100;if(s.maxSize!==void 0){const p=wh({groupSize:n,panelElement:i,styleProp:s.maxSize});u=Mi(p/n*100)}return{groupResizeBehavior:s.groupResizeBehavior,collapsedSize:o,collapsible:s.collapsible===!0,defaultSize:l,disabled:s.disabled,minSize:c,maxSize:u,panelId:r.id}})}function Mn(e,t="Assertion error"){if(!e)throw Error(t)}function N1(e,t){return Array.from(t).sort(e==="horizontal"?Bge:Fge)}function Bge(e,t){const n=e.element.offsetLeft-t.element.offsetLeft;return n!==0?n:e.element.offsetWidth-t.element.offsetWidth}function Fge(e,t){const n=e.element.offsetTop-t.element.offsetTop;return n!==0?n:e.element.offsetHeight-t.element.offsetHeight}function U8(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function V8(e,t){return{x:e.x>=t.left&&e.x<=t.right?0:Math.min(Math.abs(e.x-t.left),Math.abs(e.x-t.right)),y:e.y>=t.top&&e.y<=t.bottom?0:Math.min(Math.abs(e.y-t.top),Math.abs(e.y-t.bottom))}}function $ge({orientation:e,rects:t,targetRect:n}){const r={x:n.x+n.width/2,y:n.y+n.height/2};let i,s=Number.MAX_VALUE;for(const o of t){const{x:l,y:c}=V8(r,o),u=e==="horizontal"?l:c;u<s&&(s=u,i=o)}return Mn(i,"No rect found"),i}let Xg;function Hge(){return Xg===void 0&&(typeof matchMedia=="function"?Xg=!!matchMedia("(pointer:coarse)").matches:Xg=!1),Xg}function W8(e){const{element:t,orientation:n,panels:r,separators:i}=e,s=N1(n,Array.from(t.children).filter(U8).map(_=>({element:_}))).map(({element:_})=>_),o=[];let l=!1,c=!1,u=-1,p=-1,h=0,g,b=[];{let _=-1;for(const x of s)x.hasAttribute("data-panel")&&(_++,x.ariaDisabled===null&&(h++,u===-1&&(u=_),p=_))}if(h>1){let _=-1;for(const x of s)if(x.hasAttribute("data-panel")){_++;const S=r.find(C=>C.element===x);if(S){if(g){const C=g.element.getBoundingClientRect(),E=x.getBoundingClientRect();let k;if(c){const T=n==="horizontal"?new DOMRect(C.right,C.top,0,C.height):new DOMRect(C.left,C.bottom,C.width,0),A=n==="horizontal"?new DOMRect(E.left,E.top,0,E.height):new DOMRect(E.left,E.top,E.width,0);switch(b.length){case 0:{k=[T,A];break}case 1:{const N=b[0],M=$ge({orientation:n,rects:[C,E],targetRect:N.element.getBoundingClientRect()});k=[N,M===C?A:T];break}default:{k=b;break}}}else b.length?k=b:k=[n==="horizontal"?new DOMRect(C.right,E.top,E.left-C.right,E.height):new DOMRect(E.left,C.bottom,E.width,E.top-C.bottom)];for(const T of k){let A="width"in T?T:T.element.getBoundingClientRect();const N=Hge()?e.resizeTargetMinimumSize.coarse:e.resizeTargetMinimumSize.fine;if(A.width<N){const j=N-A.width;A=new DOMRect(A.x-j/2,A.y,A.width+j,A.height)}if(A.height<N){const j=N-A.height;A=new DOMRect(A.x,A.y-j/2,A.width,A.height+j)}const M=_<=u||_>p;!l&&!M&&o.push({group:e,groupSize:Ld({group:e}),panels:[g,S],separator:"width"in T?void 0:T,rect:A}),l=!1}}c=!1,g=S,b=[]}}else if(x.hasAttribute("data-separator")){x.ariaDisabled!==null&&(l=!0);const S=i.find(C=>C.element===x);S?b.push(S):(g=void 0,b=[])}else c=!0}return o}var vl,pP;let G8=(pP=class{constructor(){Ja(this,vl,{})}addListener(t,n){const r=br(this,vl)[t];return r===void 0?br(this,vl)[t]=[n]:r.includes(n)||r.push(n),()=>{this.removeListener(t,n)}}emit(t,n){const r=br(this,vl)[t];if(r!==void 0)if(r.length===1)r[0].call(null,n);else{let i=!1,s=null;const o=Array.from(r);for(let l=0;l<o.length;l++){const c=o[l];try{c.call(null,n)}catch(u){s===null&&(i=!0,s=u)}}if(i)throw s}}removeAllListeners(){us(this,vl,{})}removeListener(t,n){const r=br(this,vl)[t];if(r!==void 0){const i=r.indexOf(n);i>=0&&r.splice(i,1)}}},vl=new WeakMap,pP),wo=new Map;const q8=new G8;function Uge(e){wo=new Map(wo),wo.delete(e)}function II(e,t){for(const[n]of wo)if(n.id===e)return n}function wl(e,t){for(const[n,r]of wo)if(n.id===e)return r;if(t)throw Error(`Could not find data for Group with id ${e}`)}function Zc(){return wo}function RE(e,t){return q8.addListener("groupChange",n=>{n.group.id===e&&t(n)})}function ya(e,t){const n=wo.get(e);wo=new Map(wo),wo.set(e,t),q8.emit("groupChange",{group:e,prev:n,next:t})}function Vge(e,t,n){let r,i={x:1/0,y:1/0};for(const s of t){const o=V8(n,s.rect);switch(e){case"horizontal":{o.x<=i.x&&(r=s,i=o);break}case"vertical":{o.y<=i.y&&(r=s,i=o);break}}}return r?{distance:i,hitRegion:r}:void 0}function Wge(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function Gge(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:PI(e),b:PI(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();Mn(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:DI(jI(n.a)),b:DI(jI(n.b))};if(i.a===i.b){const s=r.childNodes,o={a:n.a.at(-1),b:n.b.at(-1)};let l=s.length;for(;l--;){const c=s[l];if(c===o.a)return 1;if(c===o.b)return-1}}return Math.sign(i.a-i.b)}const qge=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function Kge(e){const t=getComputedStyle(K8(e)??e).display;return t==="flex"||t==="inline-flex"}function Yge(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||Kge(e))||+t.opacity<1||"transform"in t&&t.transform!=="none"||"webkitTransform"in t&&t.webkitTransform!=="none"||"mixBlendMode"in t&&t.mixBlendMode!=="normal"||"filter"in t&&t.filter!=="none"||"webkitFilter"in t&&t.webkitFilter!=="none"||"isolation"in t&&t.isolation==="isolate"||qge.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function jI(e){let t=e.length;for(;t--;){const n=e[t];if(Mn(n,"Missing node"),Yge(n))return n}return null}function DI(e){return e&&Number(getComputedStyle(e).zIndex)||0}function PI(e){const t=[];for(;e;)t.push(e),e=K8(e);return t}function K8(e){const{parentNode:t}=e;return Wge(t)?t.host:t}function Xge(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function Qge({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!U8(n)||n.contains(e)||e.contains(n))return!0;if(Gge(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(Xge(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function TE(e,t){const n=[];return t.forEach((r,i)=>{if(i.disabled)return;const s=W8(i),o=Vge(i.orientation,s,{x:e.clientX,y:e.clientY});o&&o.distance.x<=0&&o.distance.y<=0&&Qge({groupElement:i.element,hitRegion:o.hitRegion.rect,pointerEventTarget:e.target})&&n.push(o.hitRegion)}),n}function Zge(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function di(e,t,n=0){return Math.abs(Mi(e)-Mi(t))<=n}function bo(e,t){return di(e,t)?0:e>t?1:-1}function od({overrideDisabledPanels:e,panelConstraints:t,prevSize:n,size:r}){const{collapsedSize:i=0,collapsible:s,disabled:o,maxSize:l=100,minSize:c=0}=t;if(o&&!e)return n;if(bo(r,c)<0)if(s){const u=(i+c)/2;bo(r,u)<0?r=i:r=c}else r=c;return r=Math.min(l,r),r=Mi(r),r}function pp({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(di(e,0))return t;const o=s==="imperative-api",l=Object.values(t),c=Object.values(i),u=[...l],[p,h]=r;Mn(p!=null,"Invalid first pivot index"),Mn(h!=null,"Invalid second pivot index");let g=0;switch(s){case"keyboard":{{const x=e<0?h:p,S=n[x];Mn(S,`Panel constraints not found for index ${x}`);const{collapsedSize:C=0,collapsible:E,minSize:k=0}=S;if(E){const T=l[x];if(Mn(T!=null,`Previous layout not found for panel index ${x}`),di(T,C)){const A=k-T;bo(A,Math.abs(e))>0&&(e=e<0?0-A:A)}}}{const x=e<0?p:h,S=n[x];Mn(S,`No panel constraints found for index ${x}`);const{collapsedSize:C=0,collapsible:E,minSize:k=0}=S;if(E){const T=l[x];if(Mn(T!=null,`Previous layout not found for panel index ${x}`),di(T,k)){const A=T-C;bo(A,Math.abs(e))>0&&(e=e<0?0-A:A)}}}break}default:{const x=e<0?h:p,S=n[x];Mn(S,`Panel constraints not found for index ${x}`);const C=l[x],{collapsible:E,collapsedSize:k,minSize:T}=S;if(E&&bo(C,T)<0)if(e>0){const A=T-k,N=A/2,M=C+e;bo(M,T)<0&&(e=bo(e,N)<=0?0:A)}else{const A=T-k,N=100-A/2,M=C-e;bo(M,T)<0&&(e=bo(100+e,N)>0?0:-A)}break}}{const x=e<0?1:-1;let S=e<0?h:p,C=0;for(;;){const k=l[S];Mn(k!=null,`Previous layout not found for panel index ${S}`);const T=od({overrideDisabledPanels:o,panelConstraints:n[S],prevSize:k,size:100})-k;if(C+=T,S+=x,S<0||S>=n.length)break}const E=Math.min(Math.abs(e),Math.abs(C));e=e<0?0-E:E}{let x=e<0?p:h;for(;x>=0&&x<n.length;){const S=Math.abs(e)-Math.abs(g),C=l[x];Mn(C!=null,`Previous layout not found for panel index ${x}`);const E=C-S,k=od({overrideDisabledPanels:o,panelConstraints:n[x],prevSize:C,size:E});if(!di(C,k)&&(g+=C-k,u[x]=k,g.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?x--:x++}}if(Zge(c,u))return i;{const x=e<0?h:p,S=l[x];Mn(S!=null,`Previous layout not found for panel index ${x}`);const C=S+g,E=od({overrideDisabledPanels:o,panelConstraints:n[x],prevSize:S,size:C});if(u[x]=E,!di(E,C)){let k=C-E,T=e<0?h:p;for(;T>=0&&T<n.length;){const A=u[T];Mn(A!=null,`Previous layout not found for panel index ${T}`);const N=A+k,M=od({overrideDisabledPanels:o,panelConstraints:n[T],prevSize:A,size:N});if(di(A,M)||(k-=M-A,u[T]=M),di(k,0))break;e>0?T--:T++}}}const b=Object.values(u).reduce((x,S)=>S+x,0);if(!di(b,100,.1))return i;const _=Object.keys(i);return u.reduce((x,S,C)=>(x[_[C]]=S,x),{})}function Oc(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(t[n]===void 0||bo(e[n],t[n])!==0)return!1;return!0}function zc({layout:e,panelConstraints:t}){const n=Object.values(e),r=[...n],i=r.reduce((l,c)=>l+c,0);if(r.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${r.map(l=>`${l}%`).join(", ")}`);if(!di(i,100)&&r.length>0)for(let l=0;l<t.length;l++){const c=r[l];Mn(c!=null,`No layout data found for index ${l}`);const u=100/i*c;r[l]=u}let s=0;for(let l=0;l<t.length;l++){const c=n[l];Mn(c!=null,`No layout data found for index ${l}`);const u=r[l];Mn(u!=null,`No layout data found for index ${l}`);const p=od({overrideDisabledPanels:!0,panelConstraints:t[l],prevSize:c,size:u});u!=p&&(s+=u-p,r[l]=p)}if(!di(s,0))for(let l=0;l<t.length;l++){const c=r[l];Mn(c!=null,`No layout data found for index ${l}`);const u=c+s,p=od({overrideDisabledPanels:!0,panelConstraints:t[l],prevSize:c,size:u});if(c!==p&&(s-=p-c,r[l]=p,di(s,0)))break}const o=Object.keys(e);return r.reduce((l,c,u)=>(l[o[u]]=c,l),{})}function Y8({groupId:e,panelId:t}){const n=()=>{const l=Zc();for(const[c,{defaultLayoutDeferred:u,derivedPanelConstraints:p,layout:h,groupSize:g,separatorToPanels:b}]of l)if(c.id===e)return{defaultLayoutDeferred:u,derivedPanelConstraints:p,group:c,groupSize:g,layout:h,separatorToPanels:b};throw Error(`Group ${e} not found`)},r=()=>{const l=n().derivedPanelConstraints.find(c=>c.panelId===t);if(l!==void 0)return l;throw Error(`Panel constraints not found for Panel ${t}`)},i=()=>{const l=n().group.panels.find(c=>c.id===t);if(l!==void 0)return l;throw Error(`Layout not found for Panel ${t}`)},s=()=>{const l=n().layout[t];if(l!==void 0)return l;throw Error(`Layout not found for Panel ${t}`)},o=l=>{const c=s();if(l===c)return;const{defaultLayoutDeferred:u,derivedPanelConstraints:p,group:h,groupSize:g,layout:b,separatorToPanels:_}=n(),x=h.panels.findIndex(k=>k.id===t),S=x===h.panels.length-1,C=pp({delta:S?c-l:l-c,initialLayout:b,panelConstraints:p,pivotIndices:S?[x-1,x]:[x,x+1],prevLayout:b,trigger:"imperative-api"}),E=zc({layout:C,panelConstraints:p});Oc(b,E)||ya(h,{defaultLayoutDeferred:u,derivedPanelConstraints:p,groupSize:g,layout:E,separatorToPanels:_})};return{collapse:()=>{const{collapsible:l,collapsedSize:c}=r(),{mutableValues:u}=i(),p=s();l&&p!==c&&(u.expandToSize=p,o(c))},expand:()=>{const{collapsible:l,collapsedSize:c,minSize:u}=r(),{mutableValues:p}=i(),h=s();if(l&&h===c){let g=p.expandToSize??u;g===0&&(g=1),o(g)}},getSize:()=>{const{group:l}=n(),c=s(),{element:u}=i(),p=l.orientation==="horizontal"?u.offsetWidth:u.offsetHeight;return{asPercentage:c,inPixels:p}},isCollapsed:()=>{const{collapsible:l,collapsedSize:c}=r(),u=s();return l&&di(c,u)},resize:l=>{const{group:c}=n(),{element:u}=i(),p=Ld({group:c}),h=wh({groupSize:p,panelElement:u,styleProp:l}),g=Mi(h/p*100);o(g)}}}function OI(e){if(e.defaultPrevented)return;const t=Zc();TE(e,t).forEach(n=>{if(n.separator){const r=n.panels.find(i=>i.panelConstraints.defaultSize!==void 0);if(r){const i=r.panelConstraints.defaultSize,s=Y8({groupId:n.group.id,panelId:r.id});s&&i!==void 0&&(s.resize(i),e.preventDefault())}}})}function Nv(e){const t=Zc();for(const[n]of t)if(n.separators.some(r=>r.element===e))return n;throw Error("Could not find parent Group for separator element")}function X8({groupId:e}){const t=()=>{const n=Zc();for(const[r,i]of n)if(r.id===e)return{group:r,...i};throw Error(`Could not find Group with id "${e}"`)};return{getLayout(){const{defaultLayoutDeferred:n,layout:r}=t();return n?{}:r},setLayout(n){const{defaultLayoutDeferred:r,derivedPanelConstraints:i,group:s,groupSize:o,layout:l,separatorToPanels:c}=t(),u=zc({layout:n,panelConstraints:i});return r?l:(Oc(l,u)||ya(s,{defaultLayoutDeferred:r,derivedPanelConstraints:i,groupSize:o,layout:u,separatorToPanels:c}),u)}}}function cc(e,t){const n=Nv(e),r=wl(n.id,!0),i=n.separators.find(p=>p.element===e);Mn(i,"Matching separator not found");const s=r.separatorToPanels.get(i);Mn(s,"Matching panels not found");const o=s.map(p=>n.panels.indexOf(p)),l=X8({groupId:n.id}).getLayout(),c=pp({delta:t,initialLayout:l,panelConstraints:r.derivedPanelConstraints,pivotIndices:o,prevLayout:l,trigger:"keyboard"}),u=zc({layout:c,panelConstraints:r.derivedPanelConstraints});Oc(l,u)||ya(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:u,separatorToPanels:r.separatorToPanels})}function zI(e){if(e.defaultPrevented)return;const t=e.currentTarget,n=Nv(t);if(!n.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),n.orientation==="vertical"&&cc(t,5);break}case"ArrowLeft":{e.preventDefault(),n.orientation==="horizontal"&&cc(t,-5);break}case"ArrowRight":{e.preventDefault(),n.orientation==="horizontal"&&cc(t,5);break}case"ArrowUp":{e.preventDefault(),n.orientation==="vertical"&&cc(t,-5);break}case"End":{e.preventDefault(),cc(t,100);break}case"Enter":{e.preventDefault();const r=Nv(t),i=wl(r.id,!0),{derivedPanelConstraints:s,layout:o,separatorToPanels:l}=i,c=r.separators.find(g=>g.element===t);Mn(c,"Matching separator not found");const u=l.get(c);Mn(u,"Matching panels not found");const p=u[0],h=s.find(g=>g.panelId===p.id);if(Mn(h,"Panel metadata not found"),h.collapsible){const g=o[p.id],b=h.collapsedSize===g?r.mutableState.expandedPanelSizes[p.id]??h.minSize:h.collapsedSize;cc(t,b-g)}break}case"F6":{e.preventDefault();const r=Nv(t).separators.map(o=>o.element),i=Array.from(r).findIndex(o=>o===e.currentTarget);Mn(i!==null,"Index not found");const s=e.shiftKey?i>0?i-1:r.length-1:i+1<r.length?i+1:0;r[s].focus({preventScroll:!0});break}case"Home":{e.preventDefault(),cc(t,-100);break}}}let yd={cursorFlags:0,state:"inactive"};const AE=new G8;function Bc(){return yd}function Jge(e){return AE.addListener("change",e)}function eve(e){const t=yd,n={...yd};n.cursorFlags=e,yd=n,AE.emit("change",{prev:t,next:n})}function _d(e){const t=yd;yd=e,AE.emit("change",{prev:t,next:e})}function BI(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=Zc(),n=TE(e,t),r=new Map;let i=!1;n.forEach(s=>{s.separator&&(i||(i=!0,s.separator.element.focus({preventScroll:!0})));const o=t.get(s.group);o&&r.set(s.group,o.layout)}),_d({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}),n.length&&e.preventDefault()}const tve=e=>e,MS=()=>{},Q8=1,Z8=2,J8=4,eB=8,FI=3,$I=12;let Qg;function HI(){return Qg===void 0&&(Qg=!1,typeof window<"u"&&(window.navigator.userAgent.includes("Chrome")||window.navigator.userAgent.includes("Firefox"))&&(Qg=!0)),Qg}function nve({cursorFlags:e,groups:t,state:n}){let r=0,i=0;switch(n){case"active":case"hover":t.forEach(s=>{if(!s.mutableState.disableCursor)switch(s.orientation){case"horizontal":{r++;break}case"vertical":{i++;break}}})}if(!(r===0&&i===0)){switch(n){case"active":{if(e&&HI()){const s=(e&Q8)!==0,o=(e&Z8)!==0,l=(e&J8)!==0,c=(e&eB)!==0;if(s)return l?"se-resize":c?"ne-resize":"e-resize";if(o)return l?"sw-resize":c?"nw-resize":"w-resize";if(l)return"s-resize";if(c)return"n-resize"}break}}return HI()?r>0&&i>0?"move":r>0?"ew-resize":"ns-resize":r>0&&i>0?"grab":r>0?"col-resize":"row-resize"}}const UI=new WeakMap;function NE(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=UI.get(e)??{};n===void 0&&(n=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&e.adoptedStyleSheets.push(n));const r=Bc();switch(r.state){case"active":case"hover":{const i=nve({cursorFlags:r.cursorFlags,groups:r.hitRegions.map(o=>o.group),state:r.state}),s=`*, *:hover {cursor: ${i} !important; }`;if(t===s)return;t=s,i?n.cssRules.length===0?n.insertRule(s):n.replaceSync(s):n.cssRules.length===1&&n.deleteRule(0);break}case"inactive":{t=void 0,n.cssRules.length===1&&n.deleteRule(0);break}}UI.set(e,{prevStyle:t,styleSheet:n})}function tB({document:e,event:t,hitRegions:n,initialLayoutMap:r,mountedGroups:i,pointerDownAtPoint:s,prevCursorFlags:o}){let l=0;n.forEach(u=>{const{group:p,groupSize:h}=u,{orientation:g,panels:b}=p,{disableCursor:_}=p.mutableState;let x=0;s?g==="horizontal"?x=(t.clientX-s.x)/h*100:x=(t.clientY-s.y)/h*100:g==="horizontal"?x=t.clientX<0?-100:100:x=t.clientY<0?-100:100;const S=r.get(p),C=i.get(p);if(!S||!C)return;const{defaultLayoutDeferred:E,derivedPanelConstraints:k,groupSize:T,layout:A,separatorToPanels:N}=C;if(k&&A&&N){const M=pp({delta:x,initialLayout:S,panelConstraints:k,pivotIndices:u.panels.map(j=>b.indexOf(j)),prevLayout:A,trigger:"mouse-or-touch"});if(Oc(M,A)){if(x!==0&&!_)switch(g){case"horizontal":{l|=x<0?Q8:Z8;break}case"vertical":{l|=x<0?J8:eB;break}}}else ya(u.group,{defaultLayoutDeferred:E,derivedPanelConstraints:k,groupSize:T,layout:M,separatorToPanels:N})}});let c=0;t.movementX===0?c|=o&FI:c|=l&FI,t.movementY===0?c|=o&$I:c|=l&$I,eve(c),NE(e)}function VI(e){const t=Zc(),n=Bc();switch(n.state){case"active":tB({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}}function WI(e){if(e.defaultPrevented)return;const t=Bc(),n=Zc();switch(t.state){case"active":{if(e.buttons===0){_d({cursorFlags:0,state:"inactive"}),t.hitRegions.forEach(r=>{const i=wl(r.group.id,!0);ya(r.group,i)});return}tB({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break}default:{const r=TE(e,n);r.length===0?t.state!=="inactive"&&_d({cursorFlags:0,state:"inactive"}):_d({cursorFlags:0,hitRegions:r,state:"hover"}),NE(e.currentTarget);break}}}function GI(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(Bc().state){case"hover":_d({cursorFlags:0,state:"inactive"})}}function qI(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=Bc();switch(t.state){case"active":_d({cursorFlags:0,state:"inactive"}),t.hitRegions.length>0&&(NE(e.currentTarget),t.hitRegions.forEach(n=>{const r=wl(n.group.id,!0);ya(n.group,r)}),e.preventDefault())}}function KI(e){let t=0,n=0;const r={};for(const s of e)if(s.defaultSize!==void 0){t++;const o=Mi(s.defaultSize);n+=o,r[s.panelId]=o}else r[s.panelId]=void 0;const i=e.length-t;if(i!==0){const s=Mi((100-n)/i);for(const o of e)o.defaultSize===void 0&&(r[o.panelId]=s)}return r}function rve(e,t,n){if(!n[0])return;const r=e.panels.find(c=>c.element===t);if(!r||!r.onResize)return;const i=Ld({group:e}),s=e.orientation==="horizontal"?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,l={asPercentage:Mi(s/i*100),inPixels:s};r.mutableValues.prevSize=l,r.onResize(l,r.id,o)}function ive(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(e[n]!==t[n])return!1;return!0}function sve({group:e,nextGroupSize:t,prevGroupSize:n,prevLayout:r}){if(n<=0||t<=0||n===t)return r;let i=0,s=0,o=!1;const l=new Map,c=[];for(const h of e.panels){const g=r[h.id]??0;switch(h.panelConstraints.groupResizeBehavior){case"preserve-pixel-size":{o=!0;const b=g/100*n,_=Mi(b/t*100);l.set(h.id,_),i+=_;break}case"preserve-relative-size":default:{c.push(h.id),s+=g;break}}}if(!o||c.length===0)return r;const u=100-i,p={...r};if(l.forEach((h,g)=>{p[g]=h}),s>0)for(const h of c){const g=r[h]??0;p[h]=Mi(g/s*u)}else{const h=Mi(u/c.length);for(const g of c)p[g]=h}return p}function ove(e,t){const n=e.map(i=>i.id),r=Object.keys(t);if(n.length!==r.length)return!1;for(const i of n)if(!r.includes(i))return!1;return!0}const qu=new Map;function ave(e){let t=!0;Mn(e.element.ownerDocument.defaultView,"Cannot register an unmounted Group");const n=e.element.ownerDocument.defaultView.ResizeObserver,r=new Set,i=new Set,s=new n(_=>{for(const x of _){const{borderBoxSize:S,target:C}=x;if(C===e.element){if(t){const E=Ld({group:e});if(E===0)return;const k=wl(e.id);if(!k)return;const T=A1(e),A=k.defaultLayoutDeferred?KI(T):k.layout,N=sve({group:e,nextGroupSize:E,prevGroupSize:k.groupSize,prevLayout:A}),M=zc({layout:N,panelConstraints:T});if(!k.defaultLayoutDeferred&&Oc(k.layout,M)&&ive(k.derivedPanelConstraints,T)&&k.groupSize===E)return;ya(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:T,groupSize:E,layout:M,separatorToPanels:k.separatorToPanels})}}else rve(e,C,S)}});s.observe(e.element),e.panels.forEach(_=>{Mn(!r.has(_.id),`Panel ids must be unique; id "${_.id}" was used more than once`),r.add(_.id),_.onResize&&s.observe(_.element)});const o=Ld({group:e}),l=A1(e),c=e.panels.map(({id:_})=>_).join(",");let u=e.mutableState.defaultLayout;u&&(ove(e.panels,u)||(u=void 0));const p=e.mutableState.layouts[c]??u??KI(l),h=zc({layout:p,panelConstraints:l}),g=e.element.ownerDocument;qu.set(g,(qu.get(g)??0)+1);const b=new Map;return W8(e).forEach(_=>{_.separator&&b.set(_.separator,_.panels)}),ya(e,{defaultLayoutDeferred:o===0,derivedPanelConstraints:l,groupSize:o,layout:h,separatorToPanels:b}),e.separators.forEach(_=>{Mn(!i.has(_.id),`Separator ids must be unique; id "${_.id}" was used more than once`),i.add(_.id),_.element.addEventListener("keydown",zI)}),qu.get(g)===1&&(g.addEventListener("dblclick",OI,!0),g.addEventListener("pointerdown",BI,!0),g.addEventListener("pointerleave",VI),g.addEventListener("pointermove",WI),g.addEventListener("pointerout",GI),g.addEventListener("pointerup",qI,!0)),function(){t=!1,qu.set(g,Math.max(0,(qu.get(g)??0)-1)),Uge(e),e.separators.forEach(_=>{_.element.removeEventListener("keydown",zI)}),qu.get(g)||(g.removeEventListener("dblclick",OI,!0),g.removeEventListener("pointerdown",BI,!0),g.removeEventListener("pointerleave",VI),g.removeEventListener("pointermove",WI),g.removeEventListener("pointerout",GI),g.removeEventListener("pointerup",qI,!0)),s.disconnect()}}function lve(){const[e,t]=v.useState({}),n=v.useCallback(()=>t({}),[]);return[e,n]}function ME(e){const t=v.useId();return`${e??t}`}const Jc=typeof window<"u"?v.useLayoutEffect:v.useEffect;function $h(e){const t=v.useRef(e);return Jc(()=>{t.current=e},[e]),v.useCallback((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[t])}function LE(...e){return $h(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}function IE(e){const t=v.useRef({...e});return Jc(()=>{for(const n in e)t.current[n]=e[n]},[e]),t.current}const nB=v.createContext(null);function cve(e,t){const n=v.useRef({getLayout:()=>({}),setLayout:tve});v.useImperativeHandle(t,()=>n.current,[]),Jc(()=>{Object.assign(n.current,X8({groupId:e}))})}function rB({children:e,className:t,defaultLayout:n,disableCursor:r,disabled:i,elementRef:s,groupRef:o,id:l,onLayoutChange:c,onLayoutChanged:u,orientation:p="horizontal",resizeTargetMinimumSize:h={coarse:20,fine:10},style:g,...b}){const _=v.useRef({onLayoutChange:{},onLayoutChanged:{}}),x=$h(P=>{Oc(_.current.onLayoutChange,P)||(_.current.onLayoutChange=P,c==null||c(P))}),S=$h(P=>{Oc(_.current.onLayoutChanged,P)||(_.current.onLayoutChanged=P,u==null||u(P))}),C=ME(l),E=v.useRef(null),[k,T]=lve(),A=v.useRef({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:h,separators:[]}),N=LE(E,s);cve(C,o);const M=$h((P,z)=>{const O=Bc(),$=II(P),V=wl(P);if(V){let F=!1;switch(O.state){case"active":{F=O.hitRegions.some(H=>H.group===$);break}}return{flexGrow:V.layout[z]??1,pointerEvents:F?"none":void 0}}return{flexGrow:(n==null?void 0:n[z])??1}}),j=IE({defaultLayout:n,disableCursor:r}),U=v.useMemo(()=>({get disableCursor(){return!!j.disableCursor},getPanelStyles:M,id:C,orientation:p,registerPanel:P=>{const z=A.current;return z.panels=N1(p,[...z.panels,P]),T(),()=>{z.panels=z.panels.filter(O=>O!==P),T()}},registerSeparator:P=>{const z=A.current;return z.separators=N1(p,[...z.separators,P]),T(),()=>{z.separators=z.separators.filter(O=>O!==P),T()}},togglePanelDisabled:(P,z)=>{const O=A.current.panels.find(F=>F.id===P);O&&(O.panelConstraints.disabled=z);const $=II(C),V=wl(C);$&&V&&ya($,{...V,derivedPanelConstraints:A1($)})},toggleSeparatorDisabled:(P,z)=>{const O=A.current.separators.find($=>$.id===P);O&&(O.disabled=z)}}),[M,C,T,p,j]),I=v.useRef(null);return Jc(()=>{const P=E.current;if(P===null)return;const z=A.current;let O;if(j.defaultLayout!==void 0&&Object.keys(j.defaultLayout).length===z.panels.length){O={};for(const D of z.panels){const G=j.defaultLayout[D.id];G!==void 0&&(O[D.id]=G)}}const $={disabled:!!i,element:P,id:C,mutableState:{defaultLayout:O,disableCursor:!!j.disableCursor,expandedPanelSizes:A.current.lastExpandedPanelSizes,layouts:A.current.layouts},orientation:p,panels:z.panels,resizeTargetMinimumSize:z.resizeTargetMinimumSize,separators:z.separators};I.current=$;const V=ave($),{defaultLayoutDeferred:F,derivedPanelConstraints:H,layout:W}=wl($.id,!0);!F&&H.length>0&&(x(W),S(W));const Z=RE(C,D=>{const{defaultLayoutDeferred:G,derivedPanelConstraints:ee,layout:B}=D.next;if(G||ee.length===0)return;const le=$.panels.map(({id:J})=>J).join(",");$.mutableState.layouts[le]=B,ee.forEach(J=>{if(J.collapsible){const{layout:ne}=D.prev??{};if(ne){const se=di(J.collapsedSize,B[J.panelId]),ce=di(J.collapsedSize,ne[J.panelId]);se&&!ce&&($.mutableState.expandedPanelSizes[J.panelId]=ne[J.panelId])}}});const oe=Bc().state!=="active";x(B),oe&&S(B)});return()=>{I.current=null,V(),Z()}},[i,C,S,x,p,k,j]),v.useEffect(()=>{const P=I.current;P&&(P.mutableState.defaultLayout=n,P.mutableState.disableCursor=!!r)}),f.jsx(nB.Provider,{value:U,children:f.jsx("div",{...b,className:t,"data-group":!0,"data-testid":C,id:C,ref:N,style:{height:"100%",width:"100%",overflow:"hidden",...g,display:"flex",flexDirection:p==="horizontal"?"row":"column",flexWrap:"nowrap",touchAction:p==="horizontal"?"pan-y":"pan-x"},children:e})})}rB.displayName="Group";function jE(){const e=v.useContext(nB);return Mn(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function uve(e,t){const{id:n}=jE(),r=v.useRef({collapse:MS,expand:MS,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:MS});v.useImperativeHandle(t,()=>r.current,[]),Jc(()=>{Object.assign(r.current,Y8({groupId:n,panelId:e}))})}function iB({children:e,className:t,collapsedSize:n="0%",collapsible:r=!1,defaultSize:i,disabled:s,elementRef:o,groupResizeBehavior:l="preserve-relative-size",id:c,maxSize:u="100%",minSize:p="0%",onResize:h,panelRef:g,style:b,..._}){const x=!!c,S=ME(c),C=IE({disabled:s}),E=v.useRef(null),k=LE(E,o),{getPanelStyles:T,id:A,orientation:N,registerPanel:M,togglePanelDisabled:j}=jE(),U=h!==null,I=$h((z,O,$)=>{h==null||h(z,c,$)});Jc(()=>{const z=E.current;if(z!==null){const O={element:z,id:S,idIsStable:x,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:U?I:void 0,panelConstraints:{groupResizeBehavior:l,collapsedSize:n,collapsible:r,defaultSize:i,disabled:C.disabled,maxSize:u,minSize:p}};return M(O)}},[l,n,r,i,U,S,x,u,p,I,M,C]),v.useEffect(()=>{j(S,!!s)},[s,S,j]),uve(S,g);const P=v.useSyncExternalStore(z=>RE(A,z),()=>JSON.stringify(T(A,S)),()=>JSON.stringify(T(A,S)));return f.jsx("div",{..._,"aria-disabled":s||void 0,"data-panel":!0,"data-testid":S,id:S,ref:k,style:{...dve,display:"flex",flexBasis:0,flexShrink:1,overflow:"visible",...JSON.parse(P)},children:f.jsx("div",{className:t,style:{maxHeight:"100%",maxWidth:"100%",flexGrow:1,overflow:"auto",...b,touchAction:N==="horizontal"?"pan-y":"pan-x"},children:e})})}iB.displayName="Panel";const dve={minHeight:0,maxHeight:"100%",height:"auto",minWidth:0,maxWidth:"100%",width:"auto",border:"none",borderWidth:0,padding:0,margin:0};function fve({layout:e,panelConstraints:t,panelId:n,panelIndex:r}){let i,s;const o=e[n],l=t.find(c=>c.panelId===n);if(l){const c=l.maxSize,u=l.collapsible?l.collapsedSize:l.minSize,p=[r,r+1];s=zc({layout:pp({delta:u-o,initialLayout:e,panelConstraints:t,pivotIndices:p,prevLayout:e}),panelConstraints:t})[n],i=zc({layout:pp({delta:c-o,initialLayout:e,panelConstraints:t,pivotIndices:p,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:s,valueNow:o}}function sB({children:e,className:t,disabled:n,elementRef:r,id:i,style:s,...o}){const l=ME(i),c=IE({disabled:n}),[u,p]=v.useState({}),[h,g]=v.useState("inactive"),b=v.useRef(null),_=LE(b,r),{disableCursor:x,id:S,orientation:C,registerSeparator:E,toggleSeparatorDisabled:k}=jE(),T=C==="horizontal"?"vertical":"horizontal";Jc(()=>{const N=b.current;if(N!==null){const M={disabled:c.disabled,element:N,id:l},j=E(M),U=Jge(P=>{g(P.next.state!=="inactive"&&P.next.hitRegions.some(z=>z.separator===M)?P.next.state:"inactive")}),I=RE(S,P=>{const{derivedPanelConstraints:z,layout:O,separatorToPanels:$}=P.next,V=$.get(M);if(V){const F=V[0],H=V.indexOf(F);p(fve({layout:O,panelConstraints:z,panelId:F.id,panelIndex:H}))}});return()=>{U(),I(),j()}}},[S,l,E,c]),v.useEffect(()=>{k(l,!!n)},[n,l,k]);let A;return n&&!x&&(A="not-allowed"),f.jsx("div",{...o,"aria-controls":u.valueControls,"aria-disabled":n||void 0,"aria-orientation":T,"aria-valuemax":u.valueMax,"aria-valuemin":u.valueMin,"aria-valuenow":u.valueNow,children:e,className:t,"data-separator":n?"disabled":h,"data-testid":l,id:l,ref:_,role:"separator",style:{flexBasis:"auto",cursor:A,...s,flexGrow:0,flexShrink:0,touchAction:"none"},tabIndex:n?void 0:0})}sB.displayName="Separator";const DE=({className:e,...t})=>f.jsx(rB,{className:he("flex h-full w-full",e),...t}),mp=e=>f.jsx(iB,{...e}),PE=({withHandle:e,orientation:t,disabled:n,className:r,...i})=>f.jsx(sB,{disabled:n,className:he("relative flex items-center justify-center bg-transparent focus-visible:outline-none",t==="vertical"?"h-2 w-full -my-1 cursor-row-resize":"h-full w-2 -mx-1 cursor-col-resize",e&&(t==="vertical"?"before:absolute before:inset-x-0 before:top-1/2 before:h-0.5 before:-translate-y-1/2 before:bg-border":"before:absolute before:inset-y-0 before:left-1/2 before:w-px before:-translate-x-1/2 before:bg-border"),r),...i,children:f.jsx("span",{className:"sr-only",children:t==="vertical"?"Resize rows":"Resize columns"})});function oB(e,t,n){const r=typeof e.maxTokens=="number"&&Number.isFinite(e.maxTokens)?e.maxTokens:null,i=r&&r>0?Math.min(100,e.usedTokens/r*100):null,s=r!==null?Math.max(0,Math.round(r-e.usedTokens)):null,o=i!==null?Math.max(0,100-i):null;return{...e,compactsAutomatically:e.compactsAutomatically||n,maxTokens:r??void 0,remainingTokens:s,usedPercentage:i,remainingPercentage:o,updatedAt:t}}function hve(e){const t=e.some(n=>n.kind==="compact_boundary"||n.kind==="compact_summary"||n.kind==="context_cleared");for(let n=e.length-1;n>=0;n-=1){const r=e[n];if(r&&!(r.kind!=="context_window_updated"||r.usage.usedTokens<=0))return oB(r.usage,new Date(r.createdAt).toISOString(),t)}return null}function pve(e,t){return!e||t===null||!Number.isFinite(t)||t<=0?e:oB({...e,maxTokens:t},e.updatedAt,e.compactsAutomatically)}function ch(e){return e==null||!Number.isFinite(e)?"0":e<1e3?`${Math.round(e)}`:e<1e4?`${(e/1e3).toFixed(1).replace(/\.0$/,"")}k`:e<1e6?`${Math.round(e/1e3)}k`:`${(e/1e6).toFixed(1).replace(/\.0$/,"")}m`}const OE=[68,32];function mve(){return{isVisible:!1,mainSizes:[...OE],terminals:[],nextTerminalIndex:0}}function gve(e,t){return e[t]??mve()}function LS(e){if(e.length===0)return[];const t=e.reduce((n,r)=>n+Math.max(r,0),0);return!Number.isFinite(t)||t<=0?Array.from({length:e.length},()=>100/e.length):e.map(n=>Math.max(n,0)/t*100)}function vve(e){let t=e,n="";do n=String.fromCharCode(65+t%26)+n,t=Math.floor(t/26)-1;while(t>=0);return`Terminal ${n}`}function bve(e){if(e.length===0)return e;const t=e.length+1;return e.map(n=>({...n,size:n.size*e.length/t}))}function Ku(e,t,n){return{...e,[t]:n(gve(e,t))}}const ul=no()(Wp(e=>({projects:{},addTerminal:(t,n)=>e(r=>({projects:Ku(r.projects,t,i=>{var c,u;const s=bve(i.terminals),o={id:((u=(c=globalThis.crypto)==null?void 0:c.randomUUID)==null?void 0:u.call(c))??`terminal-${Date.now()}-${i.nextTerminalIndex}`,title:vve(i.nextTerminalIndex),size:100/(s.length+1)},l=n?Math.max(s.findIndex(p=>p.id===n)+1,0):s.length;return{...i,isVisible:!0,nextTerminalIndex:i.nextTerminalIndex+1,terminals:[...s.slice(0,l),o,...s.slice(l)]}})})),removeTerminal:(t,n)=>e(r=>({projects:Ku(r.projects,t,i=>{const s=i.terminals.filter(l=>l.id!==n);if(s.length===0)return{...i,isVisible:!1,terminals:[]};const o=LS(s.map(l=>l.size));return{...i,terminals:s.map((l,c)=>({...l,size:o[c]??100/s.length}))}})})),toggleVisibility:t=>e(n=>({projects:Ku(n.projects,t,r=>({...r,isVisible:r.terminals.length>0?!r.isVisible:!1}))})),resetMainSizes:t=>e(n=>({projects:Ku(n.projects,t,r=>({...r,mainSizes:[...OE]}))})),setMainSizes:(t,n)=>e(r=>{if(n.length!==2)return r;const i=LS(n);return{projects:Ku(r.projects,t,s=>({...s,mainSizes:i}))}}),setTerminalSizes:(t,n)=>e(r=>({projects:Ku(r.projects,t,i=>{if(n.length!==i.terminals.length)return i;const s=LS(n);return{...i,terminals:i.terminals.map((o,l)=>({...o,size:s[l]??o.size}))}})})),clearProject:t=>e(n=>{const{[t]:r,...i}=n.projects;return{projects:i}})}),{name:"terminal-layouts",version:1})),yve={isVisible:!1,mainSizes:[...OE],terminals:[],nextTerminalIndex:0},_ve=35;function xve(e,t){return!Number.isFinite(e)||e<=0||!Number.isFinite(t)||t<=0?0:e*(t/100)}function Sve(e,t){const n=xve(e,t);return n>=0&&n<_ve}const X0=350,wve=[.4,0,.2,1],Cve=8,YI=1e-6;function kve(e,t,n){const r=1-e;return 3*r*r*e*t+3*r*e*e*n+e*e*e}function Eve(e,t,n){const r=1-e;return 3*r*r*e*t+3*r*e*e*n+e*e*e}function Rve(e,t,n){const r=1-e;return 3*r*r*t+6*r*e*(n-t)+3*e*e*(1-n)}function Tve(e,t,n){let r=e;for(let i=0;i<Cve;i+=1){const s=kve(r,t,n)-e;if(Math.abs(s)<YI)return r;const o=Rve(r,t,n);if(Math.abs(o)<YI)break;r-=s/o}return r}function Ave(e){if(e<=0)return 0;if(e>=1)return 1;const[t,n,r,i]=wve,s=Tve(e,t,r);return Eve(s,n,i)}function aB(e,t,n){const r=Ave(n);return[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r]}function Nve({projectId:e,shouldRenderRightSidebarLayout:t,showRightSidebar:n,rightSidebarSize:r}){const i=v.useRef(null),s=v.useRef(null),o=v.useRef(null),l=v.useRef(null),c=v.useRef(null),u=v.useRef(!1),p=v.useRef(null),h=v.useRef(!1),g=v.useRef(!1);return v.useEffect(()=>()=>{l.current!==null&&window.cancelAnimationFrame(l.current),c.current!==null&&window.clearTimeout(c.current)},[]),v.useLayoutEffect(()=>{var M,j,U,I,P,z;if(!t){l.current!==null&&(window.cancelAnimationFrame(l.current),l.current=null),c.current!==null&&(window.clearTimeout(c.current),c.current=null),u.current=!1;return}const b=i.current;if(!b)return;l.current!==null&&(window.cancelAnimationFrame(l.current),l.current=null),c.current!==null&&(window.clearTimeout(c.current),c.current=null);const _=p.current,x=_!==null&&_!==e,S=n&&!g.current,C=!h.current,E=n?[100-r,r]:[100,0],k=x||C&&n,T=S||C?[100,0]:[b.getLayout().workspace??E[0],b.getLayout().rightSidebar??E[1]];if(p.current=e,h.current=t,g.current=n,k||Math.abs(T[0]-E[0])<.1&&Math.abs(T[1]-E[1])<.1){b.setLayout({workspace:E[0],rightSidebar:E[1]}),(M=s.current)==null||M.setAttribute("data-right-sidebar-open",n?"true":"false"),(j=o.current)==null||j.setAttribute("data-right-sidebar-open",n?"true":"false"),(U=o.current)==null||U.setAttribute("data-right-sidebar-animated","false");return}u.current=!0,(I=s.current)==null||I.setAttribute("data-right-sidebar-open",n?"true":"false"),(P=o.current)==null||P.setAttribute("data-right-sidebar-open",n?"true":"false"),(z=o.current)==null||z.setAttribute("data-right-sidebar-animated","true"),b.setLayout({workspace:T[0],rightSidebar:T[1]});const A=performance.now(),N=O=>{const $=Math.min(1,(O-A)/X0),V=aB(T,E,$);if(b.setLayout({workspace:V[0],rightSidebar:V[1]}),$<1){l.current=window.requestAnimationFrame(N);return}b.setLayout({workspace:E[0],rightSidebar:E[1]}),l.current=null,c.current=window.setTimeout(()=>{u.current=!1,c.current=null},0)};l.current=window.requestAnimationFrame(N)},[e,r,t,n]),v.useEffect(()=>{t||(h.current=!1,g.current=!1)},[t]),{isAnimating:u,panelGroupRef:i,sidebarPanelRef:s,sidebarVisualRef:o}}function Mve(e){return e.visibilityState==="visible"?e.activeChatId:null}function Lve(e){e.socket.setFocusedChat(Mve({activeChatId:e.activeChatId,visibilityState:e.visibilityState}))}function Ive({socket:e,activeChatId:t}){v.useEffect(()=>{if(typeof document>"u")return;const n=()=>{Lve({socket:e,activeChatId:t,visibilityState:document.visibilityState})};return n(),document.addEventListener("visibilitychange",n),window.addEventListener("pagehide",n),window.addEventListener("pageshow",n),()=>{document.removeEventListener("visibilitychange",n),window.removeEventListener("pagehide",n),window.removeEventListener("pageshow",n),e.setFocusedChat(null)}},[e,t])}function jve({rootRef:e,fallbackRef:t,enabled:n,canCancel:r}){v.useEffect(()=>{if(!n)return;let i=0,s=null;const o=h=>{const g=h instanceof Element?h:null,b=e.current,_=t.current;if(ON({trigger:"pointer",activeElement:document.activeElement,pointerStartTarget:s,pointerEndTarget:g,root:b,fallback:_,hasActiveOverlay:PN(document),hasActiveSelection:jK(window.getSelection())})!=="restore"){s=null;return}_==null||_.focus({preventScroll:!0}),s=null},l=h=>{cancelAnimationFrame(i),s=h.target instanceof Element?h.target:null},c=h=>{cancelAnimationFrame(i),i=window.requestAnimationFrame(()=>{o(h.target)})},u=()=>{s=null;const h=t.current;!h||h.disabled||h.focus({preventScroll:!0})},p=h=>{if(h.key!=="Escape")return;const g=t.current;ON({trigger:"escape",activeElement:document.activeElement,fallback:g,hasActiveOverlay:PN(document),canCancel:r,defaultPrevented:h.defaultPrevented})==="escape-focus"&&(h.preventDefault(),g==null||g.focus({preventScroll:!0}))};return window.addEventListener("pointerdown",l,!0),window.addEventListener("pointerup",c,!0),window.addEventListener("keydown",p,!0),window.addEventListener(Yv,u),()=>{cancelAnimationFrame(i),window.removeEventListener("pointerdown",l,!0),window.removeEventListener("pointerup",c,!0),window.removeEventListener("keydown",p,!0),window.removeEventListener(Yv,u)}},[r,n,t,e])}function Dve(e){const t=e.previousProjectId!==null&&e.previousProjectId!==e.projectId,n=e.previousProjectId===null&&e.projectId!==null;return!t&&!n&&e.showTerminalPane&&!e.wasTerminalVisible}function Pve({previousProjectId:e,projectId:t,previousShouldRenderTerminalLayout:n,previousShowTerminalPane:r,showTerminalPane:i,terminalLayout:s,liveLayout:o}){const l=e!==null&&e!==t,c=i&&!r,u=!n,p=e===null&&t!==null,h=i?s.mainSizes:[100,0];return{currentLayout:c||u?[100,0]:o,shouldSkipAnimation:l||p&&u,targetLayout:h}}function Ove({chatInputRef:e,projectId:t,shouldRenderTerminalLayout:n,showTerminalPane:r,terminalLayout:i}){const s=v.useRef(null),o=v.useRef(null),l=v.useRef(null),c=v.useRef(null),u=v.useRef(null),p=v.useRef(!1),h=v.useRef(null),g=v.useRef(!1),b=v.useRef(!1),_=v.useRef(!1),[x,S]=v.useState(0);return v.useEffect(()=>{var k;const C=h.current,E=_.current;Dve({previousProjectId:C,projectId:t,showTerminalPane:r,wasTerminalVisible:E})&&S(T=>T+1),C!==null&&C===t&&!r&&E&&((k=e.current)==null||k.focus({preventScroll:!0})),_.current=r,h.current=t},[e,t,r]),v.useEffect(()=>()=>{c.current!==null&&window.cancelAnimationFrame(c.current),u.current!==null&&window.clearTimeout(u.current)},[]),v.useLayoutEffect(()=>{var j,U,I,P,z,O;if(!n){c.current!==null&&(window.cancelAnimationFrame(c.current),c.current=null),u.current!==null&&(window.clearTimeout(u.current),u.current=null),p.current=!1;return}const C=s.current;if(!C)return;c.current!==null&&(window.cancelAnimationFrame(c.current),c.current=null),u.current!==null&&(window.clearTimeout(u.current),u.current=null);const E=h.current,{currentLayout:k,shouldSkipAnimation:T,targetLayout:A}=Pve({previousProjectId:E,projectId:t,previousShouldRenderTerminalLayout:g.current,previousShowTerminalPane:b.current,showTerminalPane:r,terminalLayout:i,liveLayout:[C.getLayout().chat??i.mainSizes[0],C.getLayout().terminal??i.mainSizes[1]]});if(g.current=n,b.current=r,T||Math.abs(k[0]-A[0])<.1&&Math.abs(k[1]-A[1])<.1){C.setLayout({chat:A[0],terminal:A[1]}),(j=o.current)==null||j.setAttribute("data-terminal-open",r?"true":"false"),(U=l.current)==null||U.setAttribute("data-terminal-open",r?"true":"false"),(I=l.current)==null||I.setAttribute("data-terminal-animated","false");return}p.current=!0,(P=o.current)==null||P.setAttribute("data-terminal-open",r?"true":"false"),(z=l.current)==null||z.setAttribute("data-terminal-open",r?"true":"false"),(O=l.current)==null||O.setAttribute("data-terminal-animated","true"),C.setLayout({chat:k[0],terminal:k[1]});const N=performance.now(),M=$=>{const V=Math.min(1,($-N)/X0),F=aB(k,A,V);if(C.setLayout({chat:F[0],terminal:F[1]}),V<1){c.current=window.requestAnimationFrame(M);return}C.setLayout({chat:A[0],terminal:A[1]}),c.current=null,u.current=window.setTimeout(()=>{p.current=!1,u.current=null},0)};c.current=window.requestAnimationFrame(M)},[t,n,r,i]),v.useEffect(()=>{n||(g.current=!1,b.current=!1)},[n]),{isAnimating:p,mainPanelGroupRef:s,terminalFocusRequestVersion:x,terminalPanelRef:o,terminalVisualRef:l}}const XI=e=>Symbol.iterator in e,QI=e=>"entries"in e,ZI=(e,t)=>{const n=e instanceof Map?e:new Map(e.entries()),r=t instanceof Map?t:new Map(t.entries());if(n.size!==r.size)return!1;for(const[i,s]of n)if(!r.has(i)||!Object.is(s,r.get(i)))return!1;return!0},zve=(e,t)=>{const n=e[Symbol.iterator](),r=t[Symbol.iterator]();let i=n.next(),s=r.next();for(;!i.done&&!s.done;){if(!Object.is(i.value,s.value))return!1;i=n.next(),s=r.next()}return!!i.done&&!!s.done};function Bve(e,t){return Object.is(e,t)?!0:typeof e!="object"||e===null||typeof t!="object"||t===null||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t)?!1:XI(e)&&XI(t)?QI(e)&&QI(t)?ZI(e,t):zve(e,t):ZI({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function JI(e){const t=xn.useRef(void 0);return n=>{const r=e(n);return Bve(t.current,r)?t.current:t.current=r}}const Mv="__new__";function uc(e){var s,o;const t=(s=e==null?void 0:e.modelOptions)==null?void 0:s.reasoningEffort,n=yM(t)?t:yM(e==null?void 0:e.effort)?e.effort:rp.reasoningEffort,r=Qee(e==null?void 0:e.model),i=Pk(r,(o=e==null?void 0:e.modelOptions)==null?void 0:o.contextWindow);return{model:r,modelOptions:{reasoningEffort:!o4(r)&&n==="max"?"high":n,contextWindow:i},planMode:!!(e!=null&&e.planMode)}}function Zg(e){var n,r;const t=(n=e==null?void 0:e.modelOptions)==null?void 0:n.reasoningEffort;return{model:Zee(e==null?void 0:e.model),modelOptions:{reasoningEffort:_M(t)?t:_M(e==null?void 0:e.effort)?e.effort:Mw.reasoningEffort,fastMode:typeof((r=e==null?void 0:e.modelOptions)==null?void 0:r.fastMode)=="boolean"?e.modelOptions.fastMode:Mw.fastMode},planMode:!!(e!=null&&e.planMode)}}function Fve(){return{claude:{model:"claude-opus-4-7",modelOptions:{...rp},planMode:!1},codex:{model:"gpt-5.5",modelOptions:{...Mw},planMode:!1}}}function $ve(e,t){if(t===void 0){console.info(`[chat-preferences] ${e}`);return}console.info(`[chat-preferences] ${e}`,t)}function Ib(e,t){if(e==="claude"){const r=t.claude;return{provider:"claude",model:r.model,modelOptions:{...r.modelOptions},planMode:r.planMode}}const n=t.codex;return{provider:"codex",model:n.model,modelOptions:{...n.modelOptions},planMode:n.planMode}}function jb(e){return e.provider==="claude"?{provider:"claude",model:e.model,modelOptions:{...e.modelOptions},planMode:e.planMode}:{provider:"codex",model:e.model,modelOptions:{...e.modelOptions},planMode:e.planMode}}function lB(e){return e.defaultProvider==="last_used"?e.sourceState?jb(e.sourceState):e.legacyComposerState?jb(e.legacyComposerState):Ib("claude",e.providerDefaults):Ib(e.defaultProvider,e.providerDefaults)}function cB(e,t){const n=e.chatStates[t];return n||lB({defaultProvider:e.defaultProvider,providerDefaults:e.providerDefaults,legacyComposerState:e.legacyComposerState})}function Jg(e,t,n){const r=cB(e,t);return{chatStates:{...e.chatStates,[t]:n(r)}}}const hi=no()((e,t)=>({defaultProvider:"last_used",providerDefaults:Fve(),chatStates:{},legacyComposerState:{provider:"claude",model:"claude-opus-4-7",modelOptions:{...rp},planMode:!1},setDefaultProvider:n=>e({defaultProvider:n}),setProviderDefaultModel:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:n==="claude"?uc({...i.providerDefaults.claude,model:r}):Zg({...i.providerDefaults.codex,model:r})}})),setProviderDefaultModelOptions:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:n==="claude"?uc({...i.providerDefaults.claude,modelOptions:{...i.providerDefaults.claude.modelOptions,...r}}):Zg({...i.providerDefaults.codex,modelOptions:{...i.providerDefaults.codex.modelOptions,...r}})}})),setProviderDefaultPlanMode:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:{...i.providerDefaults[n],planMode:r}}})),getComposerState:n=>jb(cB(t(),n)),initializeComposerForChat:(n,r)=>e(i=>{if(i.chatStates[n])return i;const s=lB({defaultProvider:i.defaultProvider,providerDefaults:i.providerDefaults,sourceState:r==null?void 0:r.sourceState,legacyComposerState:i.legacyComposerState});return $ve("initializeComposerForChat",{chatId:n,composerState:s}),{chatStates:{...i.chatStates,[n]:s}}}),setComposerState:(n,r)=>e(i=>({chatStates:{...i.chatStates,[n]:r.provider==="claude"?{provider:"claude",model:uc(r).model,modelOptions:uc(r).modelOptions,planMode:r.planMode}:jb(r)}})),setChatComposerProvider:(n,r)=>e(i=>Jg(i,n,()=>Ib(r,i.providerDefaults))),setChatComposerModel:(n,r)=>e(i=>Jg(i,n,s=>s.provider==="claude"?{provider:"claude",model:uc({...s,model:r}).model,modelOptions:uc({...s,model:r}).modelOptions,planMode:s.planMode}:{provider:"codex",model:r,modelOptions:Zg({...s,model:r}).modelOptions,planMode:s.planMode})),setChatComposerModelOptions:(n,r)=>e(i=>Jg(i,n,s=>s.provider==="claude"?{provider:"claude",model:s.model,modelOptions:uc({...s,modelOptions:{...s.modelOptions,...r}}).modelOptions,planMode:s.planMode}:{provider:"codex",model:s.model,modelOptions:Zg({...s,modelOptions:{...s.modelOptions,...r}}).modelOptions,planMode:s.planMode})),setChatComposerPlanMode:(n,r)=>e(i=>Jg(i,n,s=>({...s,planMode:r}))),resetChatComposerFromProvider:(n,r)=>e(i=>({chatStates:{...i.chatStates,[n]:Ib(r,i.providerDefaults)}}))})),M1=no()(Wp((e,t)=>({drafts:{},attachmentDrafts:{},setDraft:(n,r)=>e(i=>{if(!r){const{[n]:s,...o}=i.drafts;return{drafts:o}}return{drafts:{...i.drafts,[n]:r}}}),clearDraft:n=>e(r=>{const{[n]:i,...s}=r.drafts;return{drafts:s}}),getDraft:n=>t().drafts[n]??"",setAttachmentDrafts:(n,r)=>e(i=>{if(r.length===0){const{[n]:s,...o}=i.attachmentDrafts;return{attachmentDrafts:o}}return{attachmentDrafts:{...i.attachmentDrafts,[n]:r}}}),clearAttachmentDrafts:n=>e(r=>{const{[n]:i,...s}=r.attachmentDrafts;return{attachmentDrafts:s}}),getAttachmentDrafts:n=>t().attachmentDrafts[n]??[]}),{name:"chat-input-drafts"})),zE=no()(e=>({byChatId:{},loadingByChatId:{},setForChat:(t,n)=>e(r=>({byChatId:{...r.byChatId,[t]:n}})),setLoadingForChat:(t,n)=>e(r=>(r.loadingByChatId[t]??!1)===n?r:{loadingByChatId:{...r.loadingByChatId,[t]:n}}),clear:t=>e(n=>{const r=t in n.byChatId,i=t in n.loadingByChatId;if(!r&&!i)return n;const{[t]:s,...o}=n.byChatId,{[t]:l,...c}=n.loadingByChatId;return{byChatId:o,loadingByChatId:c}})}));function Hve(e){return{autoResumeOnRateLimit:!!(e!=null&&e.autoResumeOnRateLimit)}}const Db=no()(Wp(e=>({autoResumeOnRateLimit:!1,setAutoResumeOnRateLimit:t=>e({autoResumeOnRateLimit:t})}),{name:"kanna-preferences",version:1,migrate:e=>Hve(e)}));function Uve(e,t){var n,r,i,s,o,l,c;return{...e,...t,terminal:{...e.terminal,...t.terminal},editor:{...e.editor,...t.editor},providerDefaults:{claude:{...e.providerDefaults.claude,...(n=t.providerDefaults)==null?void 0:n.claude,modelOptions:{...e.providerDefaults.claude.modelOptions,...(i=(r=t.providerDefaults)==null?void 0:r.claude)==null?void 0:i.modelOptions}},codex:{...e.providerDefaults.codex,...(s=t.providerDefaults)==null?void 0:s.codex,modelOptions:{...e.providerDefaults.codex.modelOptions,...(l=(o=t.providerDefaults)==null?void 0:o.codex)==null?void 0:l.modelOptions}}},cloudflareTunnel:{...e.cloudflareTunnel,...t.cloudflareTunnel},claudeAuth:{tokens:((c=t.claudeAuth)==null?void 0:c.tokens)??e.claudeAuth.tokens},auth:{...e.auth,...t.auth},uploads:{...e.uploads,...t.uploads},subagents:e.subagents}}const Us=no()(e=>({settings:null,hydrationStatus:"idle",setHydrationStatus:t=>e({hydrationStatus:t}),setFromServer:t=>e({settings:t,hydrationStatus:"ready"}),applyOptimisticPatch:t=>e(n=>({settings:n.settings?Uve(n.settings,t):n.settings}))})),uB=v.createContext(void 0),Vve=e=>e==="light"||e==="dark"||e==="system";function Wve(e){return e==="dark"?"black-translucent":"default"}function ej(e,t){if(typeof document>"u")return;let n=document.head.querySelector(`meta[name="${e}"]`);n||(n=document.createElement("meta"),n.setAttribute("name",e),document.head.appendChild(n)),n.setAttribute("content",t)}function tj(e){if(typeof document>"u"||typeof window>"u")return;const t=getComputedStyle(document.body).backgroundColor||getComputedStyle(document.documentElement).backgroundColor;t&&ej("theme-color",t),ej("apple-mobile-web-app-status-bar-style",Wve(e)),document.documentElement.style.colorScheme=e}const Lv=()=>typeof window>"u"?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",nj=e=>{if(typeof document>"u")return;const t=e==="system"?Lv():e;document.documentElement.classList.toggle("dark",t==="dark")},Gve=()=>{var t;const e=(t=Us.getState().settings)==null?void 0:t.theme;return e&&Vve(e)?e:"system"};function qve({children:e}){const t=Us(o=>{var l;return(l=o.settings)==null?void 0:l.theme}),n=Us(o=>o.applyOptimisticPatch),[r,i]=v.useState(Gve);v.useEffect(()=>{!t||t===r||i(t)},[t,r]),v.useEffect(()=>{nj(r)},[r]),v.useEffect(()=>{const o=r==="system"?Lv():r;tj(o)},[r]),v.useEffect(()=>{if(r!=="system")return;const o=window.matchMedia("(prefers-color-scheme: dark)"),l=()=>{nj("system"),tj(Lv())};return o.addEventListener?(o.addEventListener("change",l),()=>o.removeEventListener("change",l)):(o.addListener(l),()=>o.removeListener(l))},[r]);const s=v.useMemo(()=>{const o=r==="system"?Lv():r;return{theme:r,resolvedTheme:o,setTheme:l=>{i(l),n({theme:l})}}},[n,r]);return f.jsx(uB.Provider,{value:s,children:e})}function BE(){const e=v.useContext(uB);if(!e)throw new Error("useTheme must be used within ThemeProvider");return e}function uh(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function rj(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}function Kve(e){const t=e&&typeof e=="object"&&"content"in e&&Array.isArray(e.content)?e.content:Array.isArray(e)?e:[],n=[];for(const r of t)if(!(!r||typeof r!="object"||!("type"in r))){if(r.type==="text"&&typeof r.text=="string"){n.push({type:"text",text:r.text});continue}if(r.type==="image"){if("data"in r&&typeof r.data=="string"){n.push({type:"image",data:r.data,mimeType:typeof r.mimeType=="string"?r.mimeType:void 0});continue}"source"in r&&r.source&&typeof r.source=="object"&&"type"in r.source&&r.source.type==="base64"&&"data"in r.source&&typeof r.source.data=="string"&&n.push({type:"image",data:r.source.data,mimeType:typeof r.source.media_type=="string"?r.source.media_type:void 0})}}return n}function Yve(e){const t=e&&typeof e=="object"&&"content"in e&&Array.isArray(e.content)?e.content:Array.isArray(e)?e:null;if(!t)return null;const n=[];for(const r of t)r&&typeof r=="object"&&"type"in r&&r.type==="text"&&typeof r.text=="string"&&n.push(r.text);return n.length>0?n.join(""):null}function Xve(e,t){const n=rj(t);switch(e.toolKind){case"ask_user_question":{const s=uh(n),o=uh(s==null?void 0:s.answers)??(s||{});return{answers:Object.fromEntries(Object.entries(o).map(([l,c])=>Array.isArray(c)?[l,c.map(u=>String(u))]:c&&typeof c=="object"&&Array.isArray(c.answers)?[l,c.answers.map(u=>String(u))]:c==null||c===""?[l,[]]:[l,[String(c)]])),...(s==null?void 0:s.discarded)===!0?{discarded:!0}:{}}}case"exit_plan_mode":{const s=uh(n);return{confirmed:typeof(s==null?void 0:s.confirmed)=="boolean"?s.confirmed:void 0,clearContext:typeof(s==null?void 0:s.clearContext)=="boolean"?s.clearContext:void 0,message:typeof(s==null?void 0:s.message)=="string"?s.message:void 0,...(s==null?void 0:s.discarded)===!0?{discarded:!0}:{}}}case"offer_download":{const s=Yve(n),o=s?rj(s):n,l=uh(o);return{contentUrl:typeof(l==null?void 0:l.contentUrl)=="string"?l.contentUrl:"",relativePath:typeof(l==null?void 0:l.relativePath)=="string"?l.relativePath:"",fileName:typeof(l==null?void 0:l.fileName)=="string"?l.fileName:"",displayName:typeof(l==null?void 0:l.displayName)=="string"?l.displayName:typeof(l==null?void 0:l.fileName)=="string"?l.fileName:"",size:typeof(l==null?void 0:l.size)=="number"?l.size:0,...typeof(l==null?void 0:l.mimeType)=="string"?{mimeType:l.mimeType}:{}}}case"read_file":if(typeof n=="string")return n;const r=Kve(n);if(r.length>0)return{content:r.flatMap(s=>s.type==="text"?[s.text]:[]).join(""),blocks:r};const i=uh(n);return{content:typeof(i==null?void 0:i.content)=="string"?i.content:JSON.stringify(n,null,2)};default:return n}}function dB(e){return new Date(e).toISOString()}function Ri(e){return{id:e._id,messageId:e.messageId,timestamp:dB(e.createdAt),hidden:e.hidden}}function Qve(e){return{id:e._id,messageId:e.messageId,hidden:e.hidden,kind:"tool",toolKind:e.tool.toolKind,toolName:e.tool.toolName,toolId:e.tool.toolId,input:e.tool.input,timestamp:dB(e.createdAt)}}function Zve(e){if(e.debugRaw)try{return JSON.parse(e.debugRaw).tool_use_result}catch{return}}function fB(e){const t=new Map,n=[];for(const r of e)switch(r.kind){case"user_prompt":n.push({...Ri(r),kind:"user_prompt",content:r.content,attachments:r.attachments??[],steered:r.steered,autoContinue:r.autoContinue});break;case"system_init":n.push({...Ri(r),kind:"system_init",provider:r.provider,model:r.model,tools:r.tools,agents:r.agents,slashCommands:r.slashCommands,mcpServers:r.mcpServers,debugRaw:r.debugRaw});break;case"account_info":n.push({...Ri(r),kind:"account_info",accountInfo:r.accountInfo});break;case"assistant_text":n.push({...Ri(r),kind:"assistant_text",text:r.text});break;case"tool_call":{const i=Qve(r);t.set(r.tool.toolId,{hydrated:i,normalized:r.tool}),n.push(i);break}case"tool_result":{const i=t.get(r.toolId);if(i){const s=i.normalized.toolKind==="ask_user_question"||i.normalized.toolKind==="exit_plan_mode"?Zve(r)??r.content:r.content;i.hydrated.result=Xve(i.normalized,s),i.hydrated.rawResult=s,i.hydrated.isError=r.isError,r.persisted&&(i.hydrated.persisted=r.persisted)}break}case"result":n.push({...Ri(r),kind:"result",success:!r.isError,cancelled:r.subtype==="cancelled",result:r.result,durationMs:r.durationMs,costUsd:r.costUsd});break;case"status":n.push({...Ri(r),kind:"status",status:r.status});break;case"context_window_updated":n.push({...Ri(r),kind:"context_window_updated",usage:r.usage});break;case"compact_boundary":n.push({...Ri(r),kind:"compact_boundary"});break;case"compact_summary":n.push({...Ri(r),kind:"compact_summary",summary:r.summary});break;case"context_cleared":n.push({...Ri(r),kind:"context_cleared"});break;case"interrupted":n.push({...Ri(r),kind:"interrupted"});break;case"auto_continue_prompt":n.push({...Ri(r),kind:"auto_continue_prompt",scheduleId:r.scheduleId});break;case"pending_tool_request":n.push({...Ri(r),kind:"pending_tool_request",toolRequestId:r.toolRequestId,toolName:r.toolName,arguments:r.arguments});break;case"tool_request_resolved":break;default:n.push({...Ri(r),kind:"unknown",json:JSON.stringify(r,null,2)});break}return n}const Jve=["AskUserQuestion","ExitPlanMode","TodoWrite"],ebe=new Set(["TodoWrite"]);function tbe(e,t){for(let n=e.length-1;n>=0;n-=1){const r=e[n];if(r.kind!=="tool")continue;const i=r;if(i.toolName===t&&!i.result)return i.id}return null}function nbe(e,t){for(let n=e.length-1;n>=0;n-=1){const r=e[n];if(r.kind!=="tool")continue;const i=r;if(i.toolName===t)return i.id}return null}function rbe(e){const t={};for(const n of Jve)t[n]=ebe.has(n)?nbe(e,n):tbe(e,n);return t}function ibe(e){return e==="starting"||e==="running"||e==="waiting_for_user"}function sbe(e){return e==="starting"||e==="running"||e==="waiting_for_user"}const FE="pushDeviceId";function hB(){return typeof localStorage>"u"?null:localStorage.getItem(FE)}function obe(e){typeof localStorage>"u"||localStorage.setItem(FE,e)}function abe(){typeof localStorage>"u"||localStorage.removeItem(FE)}function lbe(){return!(typeof window>"u"||typeof Notification>"u"||!("serviceWorker"in navigator)||typeof globalThis.PushManager>"u")}function cbe(){var t;if(typeof window>"u")return!1;if(window.isSecureContext)return!0;const e=((t=window.location)==null?void 0:t.hostname)??"";return e==="localhost"||e==="127.0.0.1"||e==="::1"}function L1(){if(!lbe())return{state:"unsupported"};if(!cbe())return{state:"insecure-context"};switch(Notification.permission){case"granted":return{state:"granted"};case"denied":return{state:"denied"};default:return{state:"default"}}}function ube(e){if(typeof Buffer<"u")return new Uint8Array(Buffer.from(e,"base64url"));const t="=".repeat((4-e.length%4)%4),n=(e+t).replace(/-/g,"+").replace(/_/g,"/"),r=atob(n),i=new Uint8Array(r.length);for(let s=0;s<r.length;s+=1)i[s]=r.charCodeAt(s);return i}function dbe(e){const t=e||"";return/iPhone|iPad/i.test(t)?"iPhone / iPad":/Android/i.test(t)?"Android":/Macintosh/i.test(t)?"Mac":/Windows/i.test(t)?"Windows PC":t||"Browser"}async function fbe(e){const t=L1();if(t.state==="unsupported")throw new Error("Push not supported in this browser");if(t.state==="insecure-context")throw new Error("Push requires a secure context (HTTPS)");if(t.state==="denied")throw new Error("Notification permission previously denied");if(await Notification.requestPermission()!=="granted")throw new Error("Notification permission was not granted");const r=await navigator.serviceWorker.register("/sw.js");await navigator.serviceWorker.ready;const i=await r.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:ube(e.vapidPublicKey)}),s=i.toJSON(),o=s.endpoint??i.endpoint,l=s.keys??{};if(!o||!l.p256dh||!l.auth)throw new Error("Subscription returned without endpoint or keys");const c=navigator.userAgent??"",{id:u}=await e.sendToServer({subscription:{endpoint:o,keys:{p256dh:l.p256dh,auth:l.auth}},label:dbe(c),userAgent:c});return u}async function hbe(e){const n=await(await navigator.serviceWorker.ready).pushManager.getSubscription();n&&await n.unsubscribe(),await e.sendToServer(e.pushDeviceId)}typeof navigator<"u"&&"serviceWorker"in navigator&&navigator.serviceWorker.addEventListener("message",e=>{const t=e.data;(t==null?void 0:t.type)==="kanna.navigate"&&typeof t.url=="string"&&(window.location.href=t.url)});const pbe=25e3,mbe=15e3,gbe=4e3,ij="kanna:profile-send-to-starting";function sj(){try{return window.sessionStorage.getItem(ij)==="1"||window.localStorage.getItem(ij)==="1"}catch{return!1}}class vbe{constructor(t){re(this,"url");re(this,"ws",null);re(this,"started",!1);re(this,"reconnectTimer",null);re(this,"reconnectDelayMs",750);re(this,"subscriptions",new Map);re(this,"pending",new Map);re(this,"outboundQueue",[]);re(this,"statusListeners",new Set);re(this,"heartbeatTimer",null);re(this,"pingTimeoutTimer",null);re(this,"pingPromise",null);re(this,"lastOpenAt",0);re(this,"lastMessageAt",0);re(this,"reconnectImmediatelyOnClose",!1);re(this,"handleWindowFocus",()=>{this.ensureHealthyConnection()});re(this,"handleVisibilityChange",()=>{if(document.visibilityState==="visible"){this.startHeartbeat(),this.ensureHealthyConnection();return}this.stopHeartbeat()});re(this,"handleOnline",()=>{this.ensureHealthyConnection()});this.url=t}start(){this.started||(this.started=!0,window.addEventListener("focus",this.handleWindowFocus),window.addEventListener("online",this.handleOnline),document.addEventListener("visibilitychange",this.handleVisibilityChange),this.connect())}dispose(){var t;this.started=!1,this.reconnectTimer&&(window.clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.stopHeartbeat(),this.clearPingState(),window.removeEventListener("focus",this.handleWindowFocus),window.removeEventListener("online",this.handleOnline),document.removeEventListener("visibilitychange",this.handleVisibilityChange),(t=this.ws)==null||t.close(),this.ws=null;for(const n of this.pending.values())n.reject(new Error("Socket disposed"));this.pending.clear()}onStatus(t){return this.statusListeners.add(t),t(this.getStatus()),()=>{this.statusListeners.delete(t)}}subscribe(t,n,r){const i=mc();return this.subscriptions.set(i,{topic:t,listener:n,eventListener:r}),this.enqueue({v:1,type:"subscribe",id:i,topic:t}),()=>{this.subscriptions.delete(i),this.enqueue({v:1,type:"unsubscribe",id:i})}}subscribeTerminal(t,n){const r=mc(),i={type:"terminal",terminalId:t};return this.subscriptions.set(r,{topic:i,listener:n.onSnapshot,eventListener:n.onEvent}),this.enqueue({v:1,type:"subscribe",id:r,topic:i}),()=>{this.subscriptions.delete(r),this.enqueue({v:1,type:"unsubscribe",id:r})}}command(t){const n=mc(),r={v:1,type:"command",id:n,command:t};return new Promise((i,s)=>{this.pending.set(n,{resolve:i,reject:s}),this.enqueue(r)})}setFocusedChat(t){const n=mc();this.enqueue({v:1,type:"command",id:n,command:{type:"push.setFocusedChat",chatId:t}})}ensureHealthyConnection(){return!this.ws||this.ws.readyState===WebSocket.CLOSED||this.ws.readyState===WebSocket.CLOSING?(this.reconnectNow(),Promise.resolve()):this.ws.readyState===WebSocket.CONNECTING||!this.isConnectionStale()?Promise.resolve():this.sendPing()}connect(){this.started&&(this.emitStatus("connecting"),this.ws=new WebSocket(this.url),this.ws.addEventListener("open",()=>{this.reconnectDelayMs=750,this.reconnectImmediatelyOnClose=!1,this.lastOpenAt=Date.now(),this.lastMessageAt=this.lastOpenAt,this.emitStatus("connected"),this.startHeartbeat();for(const[n,r]of this.subscriptions.entries())this.sendNow({v:1,type:"subscribe",id:n,topic:r.topic});for(;this.outboundQueue.length>0;){const n=this.outboundQueue.shift();n&&this.sendNow(n)}const t=hB();t&&this.sendNow({v:1,type:"command",id:mc(),command:{type:"push.identifyDevice",pushDeviceId:t}})}),this.ws.addEventListener("message",t=>{var s,o;this.lastMessageAt=Date.now();const n=performance.now(),r=String(t.data);let i;try{i=JSON.parse(r)}catch{return}if(sj()&&i.type==="snapshot"&&i.snapshot.type==="chat"&&((s=i.snapshot.data)==null?void 0:s.runtime.status)==="starting"&&console.debug("[kanna/send->starting][client-ws]",{stage:"socket_message_received",receivedAt:n,payloadBytes:r.length,chatId:i.snapshot.data.runtime.chatId,status:i.snapshot.data.runtime.status,messageCount:i.snapshot.data.messages.length}),sj()&&i.type==="ack"&&console.debug("[kanna/send->starting][client-ws]",{stage:"socket_ack_received",receivedAt:n,payloadBytes:r.length,commandId:i.id}),i.type==="snapshot"){const l=this.subscriptions.get(i.id);l==null||l.listener(i.snapshot.data);return}if(i.type==="event"){const l=this.subscriptions.get(i.id);(o=l==null?void 0:l.eventListener)==null||o.call(l,i.event);return}if(i.type==="ack"){const l=this.pending.get(i.id);if(!l)return;this.pending.delete(i.id),l.resolve(i.result);return}if(i.type==="error"){if(!i.id){console.error(jX,i.message);return}const l=this.pending.get(i.id);if(!l)return;this.pending.delete(i.id),l.reject(new Error(i.message))}}),this.ws.addEventListener("close",()=>{if(!this.started)return;const t=this.reconnectImmediatelyOnClose;this.reconnectImmediatelyOnClose=!1,this.stopHeartbeat(),this.clearPingState(),this.emitStatus("disconnected");for(const n of this.pending.values())n.reject(new Error("Disconnected"));if(this.pending.clear(),t){this.connect();return}this.scheduleReconnect()}))}scheduleReconnect(){this.reconnectTimer===null&&(this.reconnectTimer=window.setTimeout(()=>{this.reconnectTimer=null,this.connect(),this.reconnectDelayMs=Math.min(this.reconnectDelayMs*2,5e3)},this.reconnectDelayMs))}getStatus(){var t,n;return((t=this.ws)==null?void 0:t.readyState)===WebSocket.OPEN?"connected":((n=this.ws)==null?void 0:n.readyState)===WebSocket.CONNECTING?"connecting":"disconnected"}emitStatus(t){for(const n of this.statusListeners)n(t)}isConnectionStale(){const t=Math.max(this.lastMessageAt,this.lastOpenAt);return t>0&&Date.now()-t>=pbe}sendPing(){if(this.pingPromise)return this.pingPromise;const t=this.command({type:"system.ping"}).then(()=>{this.clearPingState()}).catch(n=>{throw this.clearPingState(),this.reconnectNow(),n});return this.pingTimeoutTimer=window.setTimeout(()=>{this.clearPingState(),this.reconnectNow()},gbe),this.pingPromise=t,t}reconnectNow(){if(this.reconnectTimer!==null&&(window.clearTimeout(this.reconnectTimer),this.reconnectTimer=null),!this.ws||this.ws.readyState===WebSocket.CLOSED){this.connect();return}this.ws.readyState!==WebSocket.CONNECTING&&(this.reconnectImmediatelyOnClose=!0,this.ws.close())}startHeartbeat(){document.visibilityState==="visible"&&this.heartbeatTimer===null&&(this.heartbeatTimer=window.setInterval(()=>{var t;if(document.visibilityState!=="visible"){this.stopHeartbeat();return}((t=this.ws)==null?void 0:t.readyState)===WebSocket.OPEN&&this.ensureHealthyConnection()},mbe))}stopHeartbeat(){this.heartbeatTimer!==null&&(window.clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}clearPingState(){this.pingTimeoutTimer!==null&&(window.clearTimeout(this.pingTimeoutTimer),this.pingTimeoutTimer=null),this.pingPromise=null}enqueue(t){var n;if(((n=this.ws)==null?void 0:n.readyState)===WebSocket.OPEN){this.sendNow(t);return}this.outboundQueue.push(t)}sendNow(t){var n;(n=this.ws)==null||n.send(JSON.stringify(t))}}async function bbe(e){const{toast:t}=await Y(async()=>{const{toast:r}=await import("./index-D_O0RuN1.js");return{toast:r}},[]);t(`${e} ${e===1?"process":"processes"} survived restart`,{description:"Review and stop them in Background tasks (⌘⇧B).",action:{label:"Review",onClick:()=>Vs.getState().openDialog()}})}function ybe(e,t){const n=new Set([...Object.keys(e),...Object.keys(t)]);for(const r of n)if(e[r]!==t[r])return!1;return!0}function _be(e,t){return e===t?!0:!e||!t?!1:e.chatId===t.chatId&&e.projectId===t.projectId&&e.localPath===t.localPath&&e.title===t.title&&e.status===t.status&&e.isDraining===t.isDraining&&e.provider===t.provider&&e.planMode===t.planMode&&ybe(e.sessionTokensByProvider,t.sessionTokensByProvider)}function xbe(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>{var i;return n._id===((i=t[r])==null?void 0:i._id)})}function Sbe(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>{var i;return n.id===((i=t[r])==null?void 0:i.id)})}function wbe(e,t){return e===t?!0:!e||!t?!1:e.hasOlder===t.hasOlder&&e.olderCursor===t.olderCursor&&e.recentLimit===t.recentLimit}function Cbe(e,t){return e.id===t.id&&e.content===t.content&&e.createdAt===t.createdAt&&e.provider===t.provider&&e.model===t.model&&e.planMode===t.planMode&&JSON.stringify(e.modelOptions)===JSON.stringify(t.modelOptions)&&kbe(e.attachments,t.attachments)}function kbe(e,t){return e===t?!0:e.length!==t.length?!1:e.every((n,r)=>{const i=t[r];return!!i&&n.id===i.id&&n.kind===i.kind&&n.displayName===i.displayName&&n.absolutePath===i.absolutePath&&n.relativePath===i.relativePath&&n.contentUrl===i.contentUrl&&n.mimeType===i.mimeType&&n.size===i.size})}function Ebe(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>Cbe(n,t[r]))}function Rbe(e,t){var s,o;if(e===t)return!0;if(!e||!t||e.status!==t.status||e.branchName!==t.branchName||e.defaultBranchName!==t.defaultBranchName||e.hasOriginRemote!==t.hasOriginRemote||e.originRepoSlug!==t.originRepoSlug||e.hasUpstream!==t.hasUpstream||e.aheadCount!==t.aheadCount||e.behindCount!==t.behindCount||e.lastFetchedAt!==t.lastFetchedAt)return!1;const n=((s=e.branchHistory)==null?void 0:s.entries)??[],r=((o=t.branchHistory)==null?void 0:o.entries)??[];return n.length!==r.length||!n.every((l,c)=>{const u=r[c];return!!u&&l.sha===u.sha&&l.summary===u.summary&&l.description===u.description&&l.authorName===u.authorName&&l.authoredAt===u.authoredAt&&l.githubUrl===u.githubUrl&&l.tags.length===u.tags.length&&l.tags.every((p,h)=>p===u.tags[h])})||e.files.length!==t.files.length?!1:e.files.every((l,c)=>{const u=t.files[c];return!!u&&l.path===u.path&&l.changeType===u.changeType&&l.isUntracked===u.isUntracked&&l.additions===u.additions&&l.deletions===u.deletions&&l.patchDigest===u.patchDigest&&l.mimeType===u.mimeType&&l.size===u.size})}function Tbe(e,t){return!!(e&&e.status!=="unknown"&&t&&t.status==="unknown"&&t.files.length===0)}function Abe(e,t){if(e===t)return!0;if(!e||!t)return!1;const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:n.every(i=>{const s=e[i],o=t[i];return!s||!o?!1:s.state===o.state&&s.scheduledAt===o.scheduledAt&&s.resetAt===o.resetAt&&s.detectedAt===o.detectedAt&&s.tz===o.tz})}function Nbe(e,t){if(e===t)return!0;if(!e||!t)return!1;const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:n.every(i=>{const s=e[i],o=t[i];return!s||!o?!1:s.state===o.state&&s.url===o.url&&s.error===o.error&&s.port===o.port&&s.activatedAt===o.activatedAt&&s.stoppedAt===o.stoppedAt})}function Mbe(e,t){return e===t?!0:!e||!t?!1:_be(e.runtime,t.runtime)&&Ebe(e.queuedMessages,t.queuedMessages)&&xbe(e.messages,t.messages)&&wbe(e.history,t.history)&&Sbe(e.availableProviders,t.availableProviders)&&Abe(e.schedules,t.schedules)&&e.liveScheduleId===t.liveScheduleId&&Nbe(e.tunnels,t.tunnels)&&e.liveTunnelId===t.liveTunnelId}function oj(e,t){const n=new Map;for(const r of e)n.set(r._id,r);for(const r of t)n.set(r._id,r);return[...n.values()]}function Lbe(e){for(let t=e.length-1;t>=0;t-=1){const n=e[t];if((n==null?void 0:n.kind)==="user_prompt"&&n.content.trim().length>0)return n.content}return null}const aj="__new_chat__",pB="lever-theme",mB="chat-sound-preferences",gB="terminal-preferences",vB="chat-preferences";function IS(e){if(typeof window>"u")return null;const t=window.localStorage.getItem(e);if(!t)return null;try{const n=JSON.parse(t);return n.state&&typeof n.state=="object"&&!Array.isArray(n.state)?n.state:null}catch{return null}}function Ibe(){if(typeof window>"u")return null;const e={},t=window.localStorage.getItem(pB);(t==="light"||t==="dark"||t==="system")&&(e.theme=t);const n=IS(mB);((n==null?void 0:n.chatSoundPreference)==="never"||(n==null?void 0:n.chatSoundPreference)==="unfocused"||(n==null?void 0:n.chatSoundPreference)==="always")&&(e.chatSoundPreference=n.chatSoundPreference),((n==null?void 0:n.chatSoundId)==="blow"||(n==null?void 0:n.chatSoundId)==="bottle"||(n==null?void 0:n.chatSoundId)==="frog"||(n==null?void 0:n.chatSoundId)==="funk"||(n==null?void 0:n.chatSoundId)==="glass"||(n==null?void 0:n.chatSoundId)==="ping"||(n==null?void 0:n.chatSoundId)==="pop"||(n==null?void 0:n.chatSoundId)==="purr"||(n==null?void 0:n.chatSoundId)==="tink")&&(e.chatSoundId=n.chatSoundId);const r=IS(gB);if(r){e.terminal={},typeof r.scrollbackLines=="number"&&(e.terminal.scrollbackLines=r.scrollbackLines),typeof r.minColumnWidth=="number"&&(e.terminal.minColumnWidth=r.minColumnWidth);const s={};(r.editorPreset==="cursor"||r.editorPreset==="vscode"||r.editorPreset==="xcode"||r.editorPreset==="windsurf"||r.editorPreset==="custom")&&(s.preset=r.editorPreset),typeof r.editorCommandTemplate=="string"&&(s.commandTemplate=r.editorCommandTemplate),Object.keys(s).length>0&&(e.editor=s)}const i=IS(vB);return((i==null?void 0:i.defaultProvider)==="last_used"||(i==null?void 0:i.defaultProvider)==="claude"||(i==null?void 0:i.defaultProvider)==="codex")&&(e.defaultProvider=i.defaultProvider),i!=null&&i.providerDefaults&&typeof i.providerDefaults=="object"&&(e.providerDefaults=i.providerDefaults),e.browserSettingsMigrated=!0,Object.keys(e).length>1?e:null}function jbe(){typeof window>"u"||(window.localStorage.removeItem(pB),window.localStorage.removeItem(mB),window.localStorage.removeItem(gB),window.localStorage.removeItem(vB))}function dh(e){Us.getState().setFromServer(e);const t=ui.getState();t.setScrollbackLines(e.terminal.scrollbackLines),t.setMinColumnWidth(e.terminal.minColumnWidth),t.setEditorPreset(e.editor.preset),t.setEditorCommandTemplate(e.editor.commandTemplate);const n=_c.getState();n.setChatSoundPreference(e.chatSoundPreference),n.setChatSoundId(e.chatSoundId),hi.setState({defaultProvider:e.defaultProvider,providerDefaults:e.providerDefaults})}function Dbe(e){return JSON.stringify({id:e.id,kind:e.kind,displayName:e.displayName,relativePath:e.relativePath,mimeType:e.mimeType,size:e.size,contentUrl:e.contentUrl})}function $E(e,t=[]){return JSON.stringify({content:e,attachments:t.map(Dbe)})}function Pbe(e,t){return e.reduce((n,r)=>r.kind!=="user_prompt"?n:n+($E(r.content,r.attachments??[])===t?1:0),0)}function Obe(e,t,n){const r=new Map;for(const i of n){if(i.kind!=="user_prompt")continue;const s=$E(i.content,i.attachments??[]);r.set(s,(r.get(s)??0)+1)}return e.filter(i=>i.scopeId!==t?!0:(r.get(i.signature)??0)<i.requiredMatchCount)}const zbe=200,Bbe=500;function lj(e,t){var r;const n=e.find(i=>i.chats.some(s=>s.chatId===t));return n?((r=n.chats.find(i=>i.chatId!==t))==null?void 0:r.chatId)??null:null}function cj(e,t){if(!(t!=null&&t.length)||e.length<=1)return e;const n=new Map(e.map((o,l)=>[o.groupKey,l])),r=new Set,i=t.map(o=>{if(r.has(o))return null;r.add(o);const l=n.get(o);return l===void 0?null:e[l]}).filter(o=>!!o);if(i.length===0)return e;const s=[...i,...e.filter(o=>!r.has(o.groupKey))];return s.every((o,l)=>o===e[l])?e:s}function Fbe(e=document){return e.visibilityState==="visible"&&e.hasFocus()}function $be(){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`}function Hbe(){const[e]=v.useState(()=>new vbe($be()));return v.useEffect(()=>(e.start(),()=>{e.dispose()}),[e]),e}const uj="kanna:profile-send-to-starting";function Ube(){try{return window.sessionStorage.getItem(uj)==="1"||window.localStorage.getItem(uj)==="1"}catch{return!1}}function bB(e){return Number((performance.now()-e).toFixed(1))}function rl(e,t,n){!e||!Ube()||console.debug("[kanna/send->starting][client]",{traceId:e.traceId,stage:t,elapsedMs:bB(e.startedAt),serverChatId:e.serverChatId,routeChatIdAtSend:e.routeChatIdAtSend,...n})}function Vbe(e){var t,n;return(e==null?void 0:e.provider)==="claude"&&e.model&&((t=e.modelOptions)!=null&&t.claude)?{provider:"claude",model:e.model,modelOptions:{reasoningEffort:e.modelOptions.claude.reasoningEffort??"high",contextWindow:e.modelOptions.claude.contextWindow??"200k"},planMode:!!e.planMode}:(e==null?void 0:e.provider)==="codex"&&e.model&&((n=e.modelOptions)!=null&&n.codex)?{provider:"codex",model:e.model,modelOptions:{reasoningEffort:e.modelOptions.codex.reasoningEffort??"high",fastMode:e.modelOptions.codex.fastMode??!1},planMode:!!e.planMode}:null}function Wbe(e,t){var n;return t?((n=e.find(r=>r.chats.some(i=>i.chatId===t)))==null?void 0:n.groupKey)??null:null}function Gbe(e,t){return e==="awaiting_disconnect"&&t==="disconnected"?"awaiting_server_ready":"none"}const qbe=30,HE="kanna:ui-update-restart",yB="kanna:last-update-reload-request";function Kbe(e){return e+qbe}function Ybe(e,t){return t>0?t:e}function dj(){return window.sessionStorage.getItem(HE)}function ev(e){window.sessionStorage.setItem(HE,e)}function fh(){window.sessionStorage.removeItem(HE)}function Xbe(e,t){return e?String(e)!==t:!1}function Qbe(){return window.sessionStorage.getItem(yB)}function Zbe(e){window.sessionStorage.setItem(yB,String(e))}function Jbe(){return"/auth/status"}function e0e(e,t,n="application/json"){const r=new Blob([t],{type:`${n}; charset=utf-8`}),i=URL.createObjectURL(r),s=document.createElement("a");s.href=i,s.download=e,s.style.display="none",document.body.append(s),s.click(),s.remove(),URL.revokeObjectURL(i)}async function t0e(e=fetch){return(await e(Jbe(),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}})).ok}function n0e(e){const t=e.selectedProjectId??e.sidebarProjectId??null;return t?{kind:"project_id",projectId:t}:e.fallbackLocalProjectPath?{kind:"local_path",localPath:e.fallbackLocalProjectPath}:null}function r0e(e,t){return!e||!t?null:e.runtime.chatId!==t?(e.runtime.chatId,e.runtime.provider,null):e}function i0e(e){var ff,$r,so;const t=$d(),n=Hbe(),r=Np(),{resolvedTheme:i}=BE(),[s,o]=v.useState({starredProjectGroups:[],projectGroups:[],stacks:[]}),[l,c]=v.useState(null),[u,p]=v.useState(null),[h,g]=v.useState(null),[b,_]=v.useState(null),[x,S]=v.useState([]),[C,E]=v.useState(!1),[k,T]=v.useState(null),[A,N]=v.useState(!1),[M,j]=v.useState({}),[U,I]=v.useState(null),[P,z]=v.useState(null),[O,$]=v.useState(null),[V,F]=v.useState(null),[H,W]=v.useState("connecting"),[Z,D]=v.useState(!1),[G,ee]=v.useState(!1),[B,le]=v.useState(!1),[oe,J]=v.useState(null),[ne,se]=v.useState(!1),[ce,de]=v.useState(!1),[Ne,we]=v.useState(!1),[je,fe]=v.useState(null),[ot,Mt]=v.useState(!1),[Et,Xt]=v.useState(null),[Dt,mt]=v.useState(!1),[yt,Wt]=v.useState(null),[Lt,gt]=v.useState(null),[Bt,ge]=v.useState([]),[ye,ze]=v.useState(null),[Xe,Me]=v.useState(0),Be=v.useRef(new Map),et=M1(JI(X=>Object.keys(X.drafts).sort())),We=M1(JI(X=>Object.keys(X.attachmentDrafts).sort())),qe=v.useRef(0),ft=v.useRef(null),rt=v.useRef({projectId:null,diffs:null}),Qt=vte(ui(X=>X.editorPreset)),lt=v.useMemo(()=>cj(s.projectGroups,l),[l,s.projectGroups]),Jt=v.useRef(lt);v.useLayoutEffect(()=>{Jt.current=lt});const dn=v.useMemo(()=>lt===s.projectGroups?s:{...s,projectGroups:lt},[s,lt]);v.useEffect(()=>n.onStatus(W),[n]),v.useEffect(()=>n.subscribe({type:"sidebar"},X=>{o(X),c(Q=>Q&&cj(X.projectGroups,Q)===X.projectGroups?null:Q),D(!0),fe(null)}),[n]),v.useEffect(()=>{if(H!=="connected")return;const X=[...new Set([...et,...We])].sort();n.command({type:"chat.setDraftProtection",chatIds:X}).catch(Q=>{fe(Q instanceof Error?Q.message:String(Q))})},[We,H,et,n]),v.useEffect(()=>n.subscribe({type:"local-projects"},X=>{p(X),ee(!0),fe(null)}),[n]),v.useEffect(()=>n.subscribe({type:"update"},X=>{g(X),fe(null)}),[n]),v.useEffect(()=>{H==="connected"&&n.command({type:"update.check",force:!0}).catch(X=>{fe(X instanceof Error?X.message:String(X))})},[H,n]),v.useEffect(()=>{const X=h==null?void 0:h.reloadRequestedAt;Xbe(X,Qbe())&&X&&(Zbe(X),ev("awaiting_disconnect"))},[h==null?void 0:h.reloadRequestedAt]),v.useEffect(()=>{const X=dj();if(Gbe(X,H)==="awaiting_server_ready"){ev("awaiting_server_ready");return}},[H]),v.useEffect(()=>{if(dj()!=="awaiting_server_ready")return;let X=!1,Q=null;const Ie=async()=>{try{if(await t0e()){if(X)return;fh(),window.location.reload();return}}catch{}X||(Q=window.setTimeout(()=>{Ie()},500))};return Ie(),()=>{X=!0,Q!==null&&window.clearTimeout(Q)}},[H]),v.useEffect(()=>{function X(){h!=null&&h.lastCheckedAt&&(Date.now()-h.lastCheckedAt<=3600*1e3||n.command({type:"update.check"}).catch(Q=>{fe(Q instanceof Error?Q.message:String(Q))}))}return window.addEventListener("focus",X),()=>{window.removeEventListener("focus",X)}},[n,h==null?void 0:h.lastCheckedAt]),v.useEffect(()=>n.subscribe({type:"keybindings"},X=>{I(X),fe(null)}),[n]),v.useEffect(()=>n.subscribe({type:"app-settings"},X=>{z(X),dh(X),fe(null)}),[n]),v.useEffect(()=>n.subscribe({type:"push-config"},X=>{$(X)}),[n]),v.useEffect(()=>{let X=!1;return n.subscribe({type:"bg-tasks"},Q=>{Vs.getState().applySnapshot(Q.tasks),!X&&Q.orphanRecoveryCount!=null&&Q.orphanRecoveryCount>0&&(X=!0,bbe(Q.orphanRecoveryCount))},Q=>{Q.type==="bg-tasks.added"?Vs.getState().applyDiff({op:"added",task:Q.task}):Q.type==="bg-tasks.updated"?Vs.getState().applyDiff({op:"updated",task:Q.task}):Q.type==="bg-tasks.removed"&&Vs.getState().applyDiff({op:"removed",task:Q.task})})},[n]);const At=v.useCallback(async()=>{try{Us.getState().setHydrationStatus("loading");const X=await n.command({type:"settings.readAppSettings"});z(X),dh(X),fe(null)}catch(X){Us.getState().setHydrationStatus("error"),fe(X instanceof Error?X.message:String(X))}},[n]),Rt=v.useCallback(async X=>{try{Us.getState().applyOptimisticPatch(X);const Q=await n.command({type:"settings.writeAppSettingsPatch",patch:X});z(Q),dh(Q),fe(null)}catch(Q){throw fe(Q instanceof Error?Q.message:String(Q)),await At(),Q}},[At,n]),Ct=v.useCallback(async X=>{try{Us.getState().applyOptimisticPatch({cloudflareTunnel:X});const Q=await n.command({type:"appSettings.setCloudflareTunnel",patch:X});z(Q),dh(Q),fe(null)}catch(Q){throw fe(Q instanceof Error?Q.message:String(Q)),await At(),Q}},[At,n]),Ue=v.useCallback(async X=>{try{Us.getState().applyOptimisticPatch({claudeAuth:X});const Q=await n.command({type:"appSettings.setClaudeAuth",patch:X});z(Q),dh(Q),fe(null)}catch(Q){throw fe(Q instanceof Error?Q.message:String(Q)),await At(),Q}},[At,n]),vt=v.useCallback(async X=>await n.command({type:"appSettings.testOAuthToken",token:X}),[n]),ht=v.useCallback(async()=>{try{const X=await n.command({type:"settings.readLlmProvider"});F(X),fe(null)}catch(X){fe(X instanceof Error?X.message:String(X))}},[n]),Ot=v.useCallback(async X=>{try{const Q=await n.command({type:"settings.writeLlmProvider",provider:X.provider,apiKey:X.apiKey,model:X.model,baseUrl:X.baseUrl});F(Q),fe(null)}catch(Q){throw fe(Q instanceof Error?Q.message:String(Q)),Q}},[n]),Ft=v.useCallback(async X=>await n.command({type:"settings.validateLlmProvider",provider:X.provider,apiKey:X.apiKey,model:X.model,baseUrl:X.baseUrl}),[n]);v.useEffect(()=>{H==="connected"&&At()},[H,At]),v.useEffect(()=>{if(H!=="connected"||(P==null?void 0:P.browserSettingsMigrated)!==!1)return;const X=Ibe();X&&Rt(X).then(jbe).catch(()=>{})},[P==null?void 0:P.browserSettingsMigrated,H,Rt]),v.useEffect(()=>{H==="connected"&&ht()},[H,ht]),v.useEffect(()=>{function X(){Me(Q=>Q+1)}return window.addEventListener("focus",X),document.addEventListener("visibilitychange",X),()=>{window.removeEventListener("focus",X),document.removeEventListener("visibilitychange",X)}},[]),v.useEffect(()=>{if(!e){_(null),le(!0);return}++qe.current,Jt.current.length,Jt.current.reduce((Q,Ie)=>Q+Ie.chats.length,0),_(null),le(!1);const X=n.subscribe({type:"chat",chatId:e,recentLimit:zbe},Q=>{if(Q!=null&&Q.runtime.chatId){const Ie=[...Be.current.values()].filter(_t=>_t.serverChatId===Q.runtime.chatId).sort((_t,Vn)=>Vn.startedAt-_t.startedAt)[0];Ie&&Ie.snapshotAt===void 0&&(Ie.snapshotAt=performance.now(),rl(Ie,"chat_snapshot_received",{status:Q.runtime.status,messageCount:Q.messages.length}))}if(_(Ie=>{const _t=Mbe(Ie,Q);return Q==null||Q.runtime.chatId,Q==null||Q.runtime.provider,Q==null||Q.runtime.status,Q==null||Q.messages.length,_t?Ie:Q}),T((Q==null?void 0:Q.history.olderCursor)??null),N((Q==null?void 0:Q.history.hasOlder)??!1),le(!0),fe(null),Q){const Ie=zE.getState();Ie.setForChat(Q.runtime.chatId,Q.slashCommands??[]),Ie.setLoadingForChat(Q.runtime.chatId,Q.slashCommandsLoading??!1)}});return()=>{Jt.current.length,Jt.current.reduce((Q,Ie)=>Q+Ie.chats.length,0),X()}},[e,n]),v.useEffect(()=>{if(oe)return;const X=lt[0];X&&J(X.groupKey)},[oe,lt]),v.useEffect(()=>{if(!e||!Z||!B)return;if(lt.some(Q=>Q.chats.some(Ie=>Ie.chatId===e))){Lt===e&>(null);return}Lt!==e&&t("/")},[e,B,t,Lt,lt,Z]),v.useEffect(()=>{b&&(J(b.runtime.projectId),Lt===b.runtime.chatId&>(null))},[b,Lt]),v.useEffect(()=>{if(!e||!Z||!Fbe())return;const X=lt.flatMap(Q=>Q.chats).find(Q=>Q.chatId===e);X!=null&&X.unread&&n.command({type:"chat.markRead",chatId:e}).catch(Q=>{fe(Q instanceof Error?Q.message:String(Q))})},[e,Xe,lt,Z,n]),v.useEffect(()=>{S([]),E(!1),T(null),N(!1)},[e]);const xe=v.useMemo(()=>r0e(b,e),[e,b]),Ge=v.useMemo(()=>(xe==null?void 0:xe.runtime.projectId)??Wbe(lt,e)??oe,[e,xe==null?void 0:xe.runtime.projectId,oe,lt]),it=v.useMemo(()=>{const X=Ge?M[Ge]??null:null;return Ge&&X?(rt.current={projectId:Ge,diffs:X},X):Ge&&rt.current.projectId===Ge?rt.current.diffs:X},[Ge,M]);v.useEffect(()=>Ge?n.subscribe({type:"project-git",projectId:Ge},Q=>{j(Ie=>{const _t=Q??null;return Tbe(Ie[Ge]??null,_t)||Rbe(Ie[Ge]??null,_t)?Ie:{...Ie,[Ge]:_t}}),fe(null)}):void 0,[Ge,n]),v.useEffect(()=>{b==null||b.runtime.chatId,b==null||b.runtime.provider,xe==null||xe.runtime.chatId,xe==null||xe.runtime.provider},[e,xe,b,Lt]);const Je=v.useMemo(()=>oj(x,(xe==null?void 0:xe.messages)??[]),[xe==null?void 0:xe.messages,x]),Se=e??aj,nt=v.useMemo(()=>Bt.filter(X=>X.scopeId===Se).map(X=>X.entry),[Se,Bt]),Ye=v.useMemo(()=>[...Je,...nt],[nt,Je]),De=v.useMemo(()=>fB(Ye),[Ye]),It=v.useMemo(()=>Lbe(De),[De]),an=v.useMemo(()=>rbe(De),[De]),Fe=(xe==null?void 0:xe.runtime)??null,Vt=(xe==null?void 0:xe.queuedMessages)??[],qn=((ye==null?void 0:ye.scopeId)===Se&&(!Fe||Fe.status==="idle")?"starting":null)??(Fe==null?void 0:Fe.status)??null,K=(xe==null?void 0:xe.availableProviders)??jh,be=sbe(qn??void 0),Le=ibe(qn??void 0),Pe=(Fe==null?void 0:Fe.isDraining)??!1,ut=((ff=u==null?void 0:u.projects[0])==null?void 0:ff.localPath)??null,Qe=(Fe==null?void 0:Fe.localPath)??ut??(($r=lt[0])==null?void 0:$r.localPath),Nt=!!(oe??(Fe==null?void 0:Fe.projectId)??((so=lt[0])==null?void 0:so.groupKey)??ut);v.useEffect(()=>{(ye==null?void 0:ye.scopeId)===Se&&Fe!=null&&Fe.status&&Fe.status!=="idle"&&ze(null)},[ye,Se,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!(ye!=null&&ye.ackedAt)||ye.scopeId!==Se||Fe!=null&&Fe.status&&Fe.status!=="idle")return;const X=window.setTimeout(()=>{ze(Q=>(Q==null?void 0:Q.scopeId)===Se&&Q.ackedAt===ye.ackedAt?null:Q)},300);return()=>window.clearTimeout(X)},[ye,Se,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!e||(Fe==null?void 0:Fe.status)!=="starting")return;const X=[...Be.current.values()].filter(Q=>Q.serverChatId===e).sort((Q,Ie)=>Ie.startedAt-Q.startedAt)[0];!X||X.startingStatusAt!==void 0||(X.startingStatusAt=performance.now(),rl(X,"runtime_status_starting",{status:Fe.status}))},[e,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!e||!Fe||Fe.status==="starting")return;const X=[...Be.current.values()].filter(Q=>Q.serverChatId===e).sort((Q,Ie)=>Ie.startedAt-Q.startedAt)[0];!X||X.startingRenderedAt!==void 0||(rl(X,"starting_not_observed",{status:Fe.status}),Be.current.delete(X.traceId))},[e,Fe]),v.useLayoutEffect(()=>{if(!e||(Fe==null?void 0:Fe.status)!=="starting"){ft.current=null;return}const X=[...Be.current.values()].filter(Q=>Q.serverChatId===e).sort((Q,Ie)=>Ie.startedAt-Q.startedAt)[0];X&&ft.current!==X.traceId&&(ft.current=X.traceId,X.startingRenderedAt=performance.now(),rl(X,"starting_render_committed",{totalMs:bB(X.startedAt)}),Be.current.delete(X.traceId))},[e,Fe==null?void 0:Fe.status]),v.useEffect(()=>{ge(X=>{const Q=Obe(X,Se,Je);return Q.length===X.length&&Q.every((Ie,_t)=>Ie===X[_t])?X:Q})},[Se,Je]);const Zt=v.useCallback(async()=>{if(!(!e||!k||C||!A)){E(!0);try{const X=await n.command({type:"chat.loadHistory",chatId:e,beforeCursor:k,limit:Bbe});S(Q=>oj(X.messages,Q)),T(X.olderCursor),N(X.hasOlder),fe(null)}catch(X){const Q=X instanceof Error?X.message:String(X);fe(Q)}finally{E(!1)}}},[e,A,k,C,n]),fn=v.useCallback(async X=>{const Q=hi.getState(),Ie=e?Q.getComposerState(e):Q.getComposerState(Mv),_t=await n.command({type:"chat.create",projectId:X});Q.initializeComposerForChat(_t.chatId,{sourceState:Ie}),J(X),gt(_t.chatId),t(`/chat/${_t.chatId}`),se(!1),fe(null)},[e,t,n]),hn=v.useCallback(async X=>X.kind==="project_id"?{projectId:X.projectId}:X.kind==="local_path"?{projectId:(await n.command({type:"project.open",localPath:X.localPath})).projectId,localPath:X.localPath}:{projectId:(await n.command(X.project.mode==="new"?{type:"project.create",localPath:X.project.localPath,title:X.project.title}:{type:"project.open",localPath:X.project.localPath})).projectId,localPath:X.project.localPath},[n]),sr=v.useCallback(async X=>{try{const Q=X.kind==="project_id"?null:X.kind==="local_path"?X.localPath:X.project.localPath;Q&&Wt(Q);const{projectId:Ie}=await hn(X);await fn(Ie)}catch(Q){fe(Q instanceof Error?Q.message:String(Q))}finally{Wt(null)}},[fn,hn]),_i=v.useCallback(async X=>{await sr({kind:"project_id",projectId:X})},[sr]),Rr=v.useCallback(async X=>{try{const Q=await n.command({type:"chat.fork",chatId:X.chatId}),Ie=hi.getState();Ie.initializeComposerForChat(Q.chatId,{sourceState:Ie.getComposerState(X.chatId)}),gt(Q.chatId),t(`/chat/${Q.chatId}`),se(!1),fe(null)}catch(Q){fe(Q instanceof Error?Q.message:String(Q))}},[t,n]),oi=v.useCallback(async X=>{await sr({kind:"local_path",localPath:X})},[sr]),Zi=v.useCallback(async X=>{await sr({kind:"project_request",project:X})},[sr]),xi=v.useCallback(async X=>{try{await n.command({type:"update.check",force:X==null?void 0:X.force}),fe(null)}catch(Q){fe(Q instanceof Error?Q.message:String(Q))}},[n]),Ji=v.useCallback(async()=>{try{const X=await n.command({type:"update.install"});if(!X.ok){fh(),fe(null),await r.alert({title:X.userTitle??"Update failed",description:X.userMessage??"Kanna could not install the update. Try again later.",closeLabel:"OK"});return}if(X.ok&&X.action==="reload"){window.location.reload();return}X.ok&&X.action==="restart"&&ev("awaiting_disconnect"),fe(null)}catch(X){fh(),fe(X instanceof Error?X.message:String(X))}},[r,n]),Di=v.useCallback(async()=>{try{const X=await n.command({type:"update.reload"});if(!X.ok){fh(),fe(null),await r.alert({title:X.userTitle??"Re-deploy failed",description:X.userMessage??"Kanna could not re-deploy. Try again later.",closeLabel:"OK"});return}if(X.action==="reload"){window.location.reload();return}ev("awaiting_disconnect"),fe(null)}catch(X){fh(),fe(X instanceof Error?X.message:String(X))}},[r,n]),kt=v.useCallback(async()=>{try{const X=await fetch("/auth/logout",{method:"POST",headers:{Accept:"application/json"}});if(!X.ok)throw new Error(`Sign out failed with status ${X.status}`);fe(null),window.location.reload()}catch(X){fe(X instanceof Error?X.message:String(X))}},[]),ln=v.useCallback(async(X,Q)=>{var am;const Ie=(Q==null?void 0:Q.attachments)??[];if(e&&be)try{const Ln=Db.getState().autoResumeOnRateLimit;await n.command({type:"message.enqueue",chatId:e,content:X,attachments:Ie,provider:Q==null?void 0:Q.provider,model:Q==null?void 0:Q.model,modelOptions:Q==null?void 0:Q.modelOptions,planMode:Q==null?void 0:Q.planMode,autoResumeOnRateLimit:Ln}),fe(null);return}catch(Ln){throw fe(Ln instanceof Error?Ln.message:String(Ln)),Ln}const _t=mc(),Vn=mc(),Hr=$E(X,Ie),oo=e??aj;ze({scopeId:oo,ackedAt:null});const ts={traceId:Vn,optimisticId:_t,startedAt:performance.now(),serverChatId:e,routeChatIdAtSend:e,contentPreview:X.slice(0,80)};Be.current.set(Vn,ts),rl(ts,"handle_send_called",{optimisticScopeId:oo,attachments:Ie.length,contentLength:X.length,contentPreview:ts.contentPreview});const uy=Pbe(Je,Hr)+Bt.filter(Ln=>Ln.scopeId===oo&&Ln.signature===Hr).length+1;ge(Ln=>[...Ln,{id:_t,scopeId:oo,signature:Hr,requiredMatchCount:uy,entry:{_id:`optimistic:${_t}`,kind:"user_prompt",content:X,attachments:Ie,createdAt:Date.now()}}]),rl(ts,"optimistic_prompt_added",{optimisticId:_t,optimisticScopeId:oo});try{let Ln=oe??((am=lt[0])==null?void 0:am.groupKey)??null;if(!e&&!Ln&&ut&&(Ln=(await n.command({type:"project.open",localPath:ut})).projectId,J(Ln)),!e&&!Ln)throw new Error("Open a project first");const Ul=Db.getState().autoResumeOnRateLimit,Pi=await n.command({type:"chat.send",chatId:e??void 0,projectId:e?void 0:Ln??void 0,clientTraceId:Vn,provider:Q==null?void 0:Q.provider,content:X,attachments:Ie,model:Q==null?void 0:Q.model,modelOptions:Q==null?void 0:Q.modelOptions,planMode:Q==null?void 0:Q.planMode,autoResumeOnRateLimit:Ul});if(ts.ackAt=performance.now(),ts.serverChatId=Pi.chatId??ts.serverChatId,ze(Po=>Po&&{scopeId:!e&&Pi.chatId?Pi.chatId:Po.scopeId,ackedAt:performance.now()}),rl(ts,"chat_send_ack_received",{resultChatId:Pi.chatId??null}),!e&&Pi.chatId){ge(lm=>lm.map(hf=>hf.id===_t?{...hf,scopeId:Pi.chatId}:hf));const Po=hi.getState();Po.setComposerState(Pi.chatId,Vbe(Q)??Po.getComposerState(Mv)),gt(Pi.chatId),t(`/chat/${Pi.chatId}`)}fe(null)}catch(Ln){throw ge(Ul=>Ul.filter(Pi=>Pi.id!==_t)),ze(null),rl(ts,"handle_send_failed",{error:Ln instanceof Error?Ln.message:String(Ln)}),Be.current.delete(Vn),fe(Ln instanceof Error?Ln.message:String(Ln)),Ln}},[e,ut,be,t,Bt,oe,Je,lt,n]),En=v.useCallback(async X=>{if(e)try{await n.command({type:"message.steer",chatId:e,queuedMessageId:X}),fe(null)}catch(Q){fe(Q instanceof Error?Q.message:String(Q))}},[e,n]),pn=v.useCallback(async X=>{if(e)try{await n.command({type:"message.dequeue",chatId:e,queuedMessageId:X}),fe(null)}catch(Q){fe(Q instanceof Error?Q.message:String(Q))}},[e,n]),As=v.useCallback(async()=>{if(e)try{await n.command({type:"chat.cancel",chatId:e})}catch(X){fe(X instanceof Error?X.message:String(X))}},[e,n]),Do=v.useCallback(async()=>{if(e)try{await n.command({type:"chat.stopDraining",chatId:e})}catch(X){fe(X instanceof Error?X.message:String(X))}},[e,n]),Ns=v.useCallback(async X=>{const Q=await r.prompt({title:"Rename Chat",initialValue:X.title,confirmLabel:"Rename"});if(!(!Q||Q===X.title))try{await n.command({type:"chat.rename",chatId:X.chatId,title:Q}),fe(null)}catch(Ie){fe(Ie instanceof Error?Ie.message:String(Ie))}},[r,n]),te=v.useCallback(async X=>{if(await r.confirm({title:"Delete Chat",description:`Delete "${X.title}"? This cannot be undone.`,confirmLabel:"Delete",confirmVariant:"destructive"}))try{if(await n.command({type:"chat.delete",chatId:X.chatId}),X.chatId===e){const Ie=lj(lt,X.chatId);t(Ie?`/chat/${Ie}`:"/")}}catch(Ie){fe(Ie instanceof Error?Ie.message:String(Ie))}},[e,r,t,lt,n]),Oe=v.useCallback(async X=>{try{if(await n.command({type:"chat.archive",chatId:X.chatId}),X.chatId===e){const Q=lj(lt,X.chatId);t(Q?`/chat/${Q}`:"/")}fe(null)}catch(Q){fe(Q instanceof Error?Q.message:String(Q))}},[e,t,lt,n]),Sn=v.useCallback(async X=>{try{gt(X),await n.command({type:"chat.unarchive",chatId:X}),t(`/chat/${X}`),fe(null)}catch(Q){gt(null),fe(Q instanceof Error?Q.message:String(Q))}},[t,n]),or=v.useCallback(async X=>{try{await n.command({type:"project.remove",projectId:X}),ul.getState().clearProject(X),Ni.getState().clearProject(X),(Fe==null?void 0:Fe.projectId)===X&&t("/"),fe(null)}catch(Q){fe(Q instanceof Error?Q.message:String(Q))}},[t,Fe,n]),Ae=v.useCallback(async(X,Q)=>{try{await n.command({type:"project.setStar",projectId:X,starred:Q}),fe(null)}catch(Ie){fe(Ie instanceof Error?Ie.message:String(Ie))}},[n]),Ve=v.useCallback(async X=>{c(X);try{await n.command({type:"sidebar.reorderProjectGroups",projectIds:X}),fe(null)}catch(Q){c(null),fe(Q instanceof Error?Q.message:String(Q))}},[n]),$t=v.useCallback(async(X,Q)=>{try{await n.command({type:"stack.create",title:X,projectIds:Q}),fe(null)}catch(Ie){fe(Ie instanceof Error?Ie.message:String(Ie))}},[n]),ar=v.useCallback(async(X,Q)=>{try{await n.command({type:"stack.rename",stackId:X,title:Q}),fe(null)}catch(Ie){fe(Ie instanceof Error?Ie.message:String(Ie))}},[n]),es=v.useCallback(async X=>{try{await n.command({type:"stack.remove",stackId:X}),fe(null)}catch(Q){fe(Q instanceof Error?Q.message:String(Q))}},[n]),Bl=v.useCallback(async(X,Q)=>{try{await n.command({type:"stack.addProject",stackId:X,projectId:Q}),fe(null)}catch(Ie){fe(Ie instanceof Error?Ie.message:String(Ie))}},[n]),Ta=v.useCallback(async(X,Q)=>{try{await n.command({type:"stack.removeProject",stackId:X,projectId:Q}),fe(null)}catch(Ie){fe(Ie instanceof Error?Ie.message:String(Ie))}},[n]),ay=v.useCallback(async(X,Q,Ie)=>{try{const _t=hi.getState(),Vn=e?_t.getComposerState(e):_t.getComposerState(Mv),Hr=await n.command({type:"chat.create",projectId:X,stackId:Q,stackBindings:Ie});_t.initializeComposerForChat(Hr.chatId,{sourceState:Vn}),J(X),gt(Hr.chatId),t(`/chat/${Hr.chatId}`),se(!1),fe(null)}catch(_t){fe(_t instanceof Error?_t.message:String(_t))}},[e,t,n]),nm=v.useCallback(async X=>{try{const Q=await n.command({type:"stack.listWorktrees",projectId:X});return fe(null),Q.worktrees}catch(Q){return fe(Q instanceof Error?Q.message:String(Q)),[]}},[n]),rm=v.useCallback(async()=>await n.command({type:"sessions.importClaude"}),[n]),ro=v.useCallback(async X=>{const Q=ui.getState();fe(null),await n.command({type:"system.openExternal",...X,editor:X.action==="open_editor"?X.editor??{preset:Q.editorPreset,commandTemplate:Q.editorCommandTemplate}:void 0})},[n]),ly=v.useCallback(async(X,Q)=>{var _t,Vn;const Ie=(Fe==null?void 0:Fe.localPath)??((_t=u==null?void 0:u.projects[0])==null?void 0:_t.localPath)??((Vn=lt[0])==null?void 0:Vn.localPath);if(Ie)try{await ro({action:X,localPath:Ie,editor:Q})}catch(Hr){fe(Hr instanceof Error?Hr.message:String(Hr))}},[u==null?void 0:u.projects,ro,Fe==null?void 0:Fe.localPath,lt]),cy=v.useCallback(async X=>{var Q;try{if(typeof navigator>"u"||!((Q=navigator.clipboard)!=null&&Q.writeText))throw new Error("Clipboard is not available");await navigator.clipboard.writeText(X),fe(null)}catch(Ie){fe(Ie instanceof Error?Ie.message:String(Ie))}},[]),iu=v.useCallback(async(X,Q="open_editor",Ie)=>{try{await ro({action:Q,localPath:X.path,line:X.line,column:X.column,editor:Ie})}catch(_t){fe(_t instanceof Error?_t.message:String(_t))}},[ro]),Ms=v.useCallback(async(X,Q)=>{try{await ro({action:X,localPath:Q})}catch(Ie){fe(Ie instanceof Error?Ie.message:String(Ie))}},[ro]),Fl=v.useCallback(async(X=e)=>{if(!X||ot)return null;Mt(!0);try{const Q=await n.command({type:"chat.exportStandalone",chatId:X,theme:i,attachmentMode:"bundle"});return fe(null),Q}catch(Q){return fe(Q instanceof Error?Q.message:String(Q)),null}finally{Mt(!1)}},[e,ot,i,n]),lf=v.useCallback(async(X=e)=>{if(!X||ot)return;mt(!1);const Q=await Fl(X);if(Q!=null&&Q.ok&&Q.shareUrl){Xt(Q.shareUrl),mt(!0);return}Q&&!Q.ok&&await r.confirm({title:"Share failed",description:Q.error,confirmLabel:"Download transcript JSON",cancelLabel:"Close",confirmVariant:"secondary"})&&e0e(Q.transcriptFileName,Q.transcriptJson)},[e,r,Fl,ot]),Aa=v.useCallback(()=>{Xt(null),mt(!1)},[]),Na=v.useCallback(async()=>{var X;if(!Et)return!1;try{if(typeof navigator>"u"||!((X=navigator.clipboard)!=null&&X.writeText))throw new Error("Clipboard is not available");return await navigator.clipboard.writeText(Et),!0}catch(Q){return await r.alert({title:"Copy failed",description:Q instanceof Error?Q.message:String(Q),closeLabel:"Close"}),!1}},[r,Et]),im=v.useCallback(()=>{Et&&(window.open(Et,"_blank","noopener,noreferrer"),Xt(null))},[Et]),cf=v.useCallback(()=>{var Q;const X=n0e({selectedProjectId:oe,sidebarProjectId:(Q=lt[0])==null?void 0:Q.groupKey,fallbackLocalProjectPath:ut});if(X){sr(X);return}t("/")},[ut,t,oe,lt,sr]),sm=v.useCallback(()=>se(!0),[]),$l=v.useCallback(()=>se(!1),[]),Ls=v.useCallback(()=>de(!0),[]),uf=v.useCallback(()=>de(!1),[]),Hl=v.useCallback(()=>we(!0),[]),io=v.useCallback(()=>we(!1),[]),df=v.useCallback(async(X,Q,Ie)=>{if(e)try{await n.command({type:"chat.respondTool",chatId:e,toolUseId:X,result:{questions:Q,answers:Ie}})}catch(_t){fe(_t instanceof Error?_t.message:String(_t))}},[e,n]),su=v.useCallback(async(X,Q,Ie,_t)=>{if(e){Q&&hi.getState().setChatComposerPlanMode(e,!1);try{await n.command({type:"chat.respondTool",chatId:e,toolUseId:X,result:{confirmed:Q,...Ie?{clearContext:!0}:{},..._t?{message:_t}:{}}})}catch(Vn){fe(Vn instanceof Error?Vn.message:String(Vn))}}},[e,n]),om=v.useCallback(async(X,Q,Ie,_t)=>{if(e)try{await n.command({type:"chat.respondSubagentTool",chatId:e,runId:X,toolUseId:Q,result:{questions:Ie,answers:_t}})}catch(Vn){fe(Vn instanceof Error?Vn.message:String(Vn))}},[e,n]),ou=v.useCallback(async(X,Q,Ie)=>{if(e)try{await n.command({type:"chat.respondSubagentTool",chatId:e,runId:X,toolUseId:Q,result:Ie})}catch(_t){fe(_t instanceof Error?_t.message:String(_t))}},[e,n]),au=v.useCallback(async(X,Q)=>{if(e)try{await n.command({type:"chat.toolRequestAnswer",chatId:e,toolRequestId:X,decision:Q})}catch(Ie){fe(Ie instanceof Error?Ie.message:String(Ie))}},[e,n]);return{socket:n,activeChatId:e,activeProjectId:Ge,sidebarData:dn,localProjects:u,updateSnapshot:h,chatSnapshot:b,chatDiffSnapshot:it,keybindings:U,appSettings:P,pushConfig:O,llmProvider:V,connectionStatus:H,sidebarReady:Z,localProjectsReady:G,commandError:je,startingLocalPath:yt,sidebarOpen:ne,sidebarCollapsed:ce,messages:De,queuedMessages:Vt,previousPrompt:It,latestToolIds:an,runtime:Fe,runtimeStatus:qn,isHistoryLoading:C,hasOlderHistory:A,availableProviders:K,isProcessing:be,canCancel:Le,isDraining:Pe,isExportingStandalone:ot,standaloneShareUrl:Et,standaloneShareComplete:Dt,navbarLocalPath:Qe,editorLabel:Qt,hasSelectedProject:Nt,addProjectModalOpen:Ne,openSidebar:sm,closeSidebar:$l,collapseSidebar:Ls,expandSidebar:uf,openAddProjectModal:Hl,closeAddProjectModal:io,loadOlderHistory:Zt,handleCreateChat:_i,handleForkChat:Rr,handleOpenLocalProject:oi,handleCreateProject:Zi,handleCheckForUpdates:xi,handleInstallUpdate:Ji,handleForceReload:Di,handleReadAppSettings:At,handleWriteAppSettings:Rt,handleWriteCloudflareTunnel:Ct,handleWriteClaudeAuth:Ue,handleTestOAuthToken:vt,handleReadLlmProvider:ht,handleWriteLlmProvider:Ot,handleValidateLlmProvider:Ft,handleSignOut:kt,handleSend:ln,handleSteerQueuedMessage:En,handleRemoveQueuedMessage:pn,handleCancel:As,handleStopDraining:Do,handleRenameChat:Ns,handleShareChat:lf,handleArchiveChat:Oe,handleOpenArchivedChat:Sn,handleDeleteChat:te,handleHideProject:or,handleToggleProjectStar:Ae,handleReorderProjectGroups:Ve,stacks:dn.stacks,handleCreateStack:$t,handleRenameStack:ar,handleRemoveStack:es,handleAddProjectToStack:Bl,handleRemoveProjectFromStack:Ta,handleCreateStackChat:ay,handleListStackWorktrees:nm,importClaudeSessions:rm,handleCopyPath:cy,handleOpenExternal:ly,handleOpenExternalPath:Ms,handleOpenLocalLink:iu,handleCompose:cf,handleAskUserQuestion:df,handleExitPlanMode:su,handleSubagentAskUserQuestion:om,handleSubagentExitPlanMode:ou,handleExportStandalone:Fl,handleCloseStandaloneShareDialog:Aa,handleOpenStandaloneShareLink:im,handleCopyStandaloneShareLink:Na,handleToolRequestAnswer:au}}function _B({message:e}){return f.jsx("div",{className:"text-pretty prose prose-sm dark:prose-invert px-0.5 w-full max-w-[70ch] space-y-4",children:f.jsx(Xc,{remarkPlugins:[Qc],components:sf(),children:e.text})})}const Xp=({children:e,className:t,animate:n=!0,shimmerWidth:r,...i})=>f.jsx("span",{className:he("mx-auto max-w-md text-foreground/60",n&&"animate-shiny-pulse",t),...i,children:e});function fj(e){return(e&&typeof e=="object"&&"content"in e&&Array.isArray(e.content)?e.content:Array.isArray(e)?e:[]).flatMap(n=>!n||typeof n!="object"||!("type"in n)||n.type!=="image"?[]:"data"in n&&typeof n.data=="string"?[{type:"image",data:n.data,mimeType:typeof n.mimeType=="string"?n.mimeType:void 0}]:"source"in n&&n.source&&typeof n.source=="object"&&"type"in n.source&&n.source.type==="base64"&&"data"in n.source&&typeof n.source.data=="string"?[{type:"image",data:n.source.data,mimeType:typeof n.source.media_type=="string"?n.source.media_type:void 0}]:[])}function s0e({images:e}){return f.jsx("div",{className:"flex flex-col gap-3",children:e.map((t,n)=>{const r=t.mimeType||"image/png";return f.jsx("div",{className:"overflow-hidden rounded-lg border border-border bg-muted/20",children:f.jsx("img",{src:`data:${r};base64,${t.data}`,alt:`Read result ${n+1}`,className:"max-h-[50vh] w-full object-contain bg-background"})},`${r}:${n}`)})})}function Pb({message:e,isLoading:t=!1,localPath:n}){var S;const r=e.result!==void 0,i=!r&&t,s=v.useMemo(()=>{if(e.toolKind==="skill")return e.input.skill;if(e.toolKind==="glob")return`Search files ${e.input.pattern==="**/*"?"in all directories":`matching ${e.input.pattern}`}`;if(e.toolKind==="grep"){const C=e.input.pattern,E=e.input.outputMode;return E==="count"?`Count \`${C}\` occurrences`:E==="content"?`Find \`${C}\` in text`:`Find \`${C}\` in files`}return e.toolKind==="bash"?e.input.description||(e.input.command?eQ(e.input.command):"Bash"):e.toolKind==="web_search"?e.input.query||"Web Search":e.toolKind==="read_file"?`Read ${Vg(e.input.filePath,n)}`:e.toolKind==="write_file"?`Write ${Vg(e.input.filePath,n)}`:e.toolKind==="edit_file"?`Edit ${Vg(e.input.filePath,n)}`:e.toolKind==="delete_file"?`Delete ${Vg(e.input.filePath,n)}`:e.toolKind==="mcp_generic"?`${_w(e.input.tool)} from ${_w(e.input.server)}`:e.toolKind==="subagent_task"&&e.input.subagentType||e.toolName},[e.input,e.toolKind,e.toolName,n]),o=v.useMemo(()=>e.toolKind==="subagent_task",[e.toolKind]),l=v.useMemo(()=>{if(e.toolKind==="skill")return e.input.skill},[e.input,e.toolKind]),c=e.toolKind==="bash",u=e.toolKind==="write_file",p=e.toolKind==="edit_file",h=e.toolKind==="delete_file",g=e.toolKind==="read_file",b=v.useMemo(()=>{if(typeof e.result=="string")return e.result;if(!e.result)return"";if(typeof e.result=="object"&&e.result!==null&&"content"in e.result){const C=e.result.content;if(typeof C=="string")return C}return JSON.stringify(e.result,null,2)},[e.result]),_=v.useMemo(()=>{if(!g)return[];if(e.result&&typeof e.result=="object"&&"blocks"in e.result){const C=e.result.blocks;if(Array.isArray(C)){const E=fj(C);if(E.length>0)return E}}return fj(e.rawResult)},[g,e.rawResult,e.result]),x=v.useMemo(()=>{switch(e.toolKind){case"bash":return e.input.command;case"write_file":case"delete_file":return e.input.content;default:return JSON.stringify(e.input,null,2)}},[e]);return f.jsx(Ca,{className:"w-full",children:f.jsxs(q0,{expandedContent:f.jsx(K0,{className:"my-4 text-sm",children:f.jsxs("div",{className:"flex flex-col gap-2",children:[p?f.jsx(Sh,{content:"",isDiff:!0,oldString:e.input.oldString,newString:e.input.newString}):h?f.jsx(Sh,{content:e.input.content}):!g&&!u&&f.jsx(AI,{label:c?f.jsxs("span",{className:"flex items-center gap-2 w-full",children:[f.jsx("span",{children:"Command"}),!!e.input.timeoutMs&&f.jsxs("span",{className:"text-muted-foreground",children:["timeout: ",String(e.input.timeoutMs),"ms"]}),!!e.input.runInBackground&&f.jsx("span",{className:"text-muted-foreground",children:"background"})]}):u?"Contents":"Input",copyText:x,children:x}),r&&g&&!e.isError&&(_.length>0?f.jsxs("div",{children:[f.jsx("span",{className:"font-medium text-muted-foreground",children:"Image"}),f.jsx("div",{className:"mt-1",children:f.jsx(s0e,{images:_})})]}):f.jsx(Sh,{content:b})),u&&!e.isError&&f.jsx(Sh,{content:e.input.content}),r&&!g&&!(u&&!e.isError)&&!(p&&!e.isError)&&!(h&&!e.isError)&&f.jsx(AI,{label:e.isError?"Error":"Result",copyText:b,children:b})]})}),children:[f.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:e.isError?f.jsx(eo,{className:"size-4 text-destructive"}):o?f.jsx(n0,{className:"size-4 text-muted-icon"}):f.jsx(P8,{icon:D8(e.toolName),className:"size-4 text-muted-icon"})}),f.jsx(Nl,{className:"text-left transition-opacity duration-200 truncate",children:f.jsx(Xp,{animate:i,shimmerWidth:Math.max(20,(((S=l||s)==null?void 0:S.length)??33)*3),children:l||s})})]})})}function o0e(e){if(e<1e3)return`${e}ms`;const t=Math.floor(e/1e3),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}h${r>0?` ${r}m`:""}`:r>0?`${r}m${i>0?` ${i}s`:""}`:`${i}s`}function hj({durationMs:e,prefix:t="Worked for"}){return e<=0?null:f.jsxs(mge,{children:[t," ",o0e(e)]})}function xB({message:e}){return e.success?f.jsx(hj,{durationMs:e.durationMs}):f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"px-4 py-3 mx-2 my-1 rounded-lg bg-destructive/10 border border-destructive/20 text-destructive text-sm",children:e.result||"An unknown error occurred."}),f.jsx(hj,{durationMs:e.durationMs,prefix:"Failed after"})]})}function a0e(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(2)} MB`}function l0e(e){return typeof e=="string"?e:JSON.stringify(e,null,2)}function c0e(e){return e.replace(/<persisted-output>\n?/g,"").replace(/\n?<\/persisted-output>/g,"")}function u0e({message:e,localPath:t}){if(e.kind==="tool"&&e.persisted){const n=c0e(l0e(e.rawResult??""));return f.jsxs("div",{className:"rounded-md border border-border bg-muted/30 p-2 space-y-1 text-xs",children:[f.jsxs("div",{className:"font-medium",children:[e.toolName,": output too large (",a0e(e.persisted.originalSize),") — saved to disk"]}),f.jsx("pre",{className:"text-[11px] whitespace-pre-wrap overflow-hidden max-h-48",children:n}),f.jsxs("a",{href:aE(e.persisted.filePath),className:"text-blue-500 hover:underline break-all",target:"_blank",rel:"noreferrer",children:["View full output (",e.persisted.filePath,")"]})]})}switch(e.kind){case"assistant_text":return f.jsx(_B,{message:e});case"tool":return f.jsx(Pb,{message:e,isLoading:!1,localPath:t});case"result":return f.jsx(xB,{message:e});default:return null}}function d0e(e){switch(e){case"AUTH_REQUIRED":return"Auth required";case"UNKNOWN_SUBAGENT":return"Unknown subagent";case"LOOP_DETECTED":return"Loop detected";case"DEPTH_EXCEEDED":return"Depth exceeded";case"TIMEOUT":return"Timeout";case"PROVIDER_ERROR":return"Provider error";case"INTERRUPTED":return"Interrupted";case"USER_CANCELLED":return"Cancelled by you";default:return"Error"}}function f0e({error:e,runId:t,onRetry:n,onOpenSettings:r}){const i=e.code==="TIMEOUT"||e.code==="PROVIDER_ERROR",s=e.code==="AUTH_REQUIRED";return f.jsxs("div",{"data-testid":`subagent-error:${t}`,className:"rounded-md border border-destructive/40 bg-destructive/5 p-3 text-sm",children:[f.jsxs("div",{className:"flex items-center gap-2 font-medium text-destructive",children:[f.jsx(Gv,{className:"h-4 w-4"}),f.jsx("span",{children:d0e(e.code)})]}),f.jsx("p",{className:"mt-1 text-foreground",children:e.message}),f.jsxs("div",{className:"mt-2 flex gap-2",children:[s&&r&&f.jsxs("button",{type:"button",onClick:r,className:"inline-flex items-center gap-1 text-xs underline",children:[f.jsx(zV,{className:"h-3 w-3"})," Open settings"]}),i&&n&&f.jsxs("button",{type:"button",onClick:n,className:"inline-flex items-center gap-1 text-xs underline",children:[f.jsx(EW,{className:"h-3 w-3"})," Retry"]})]})]})}function h0e({question:e,currentIndex:t,totalQuestions:n,onBack:r,children:i}){const s=r&&t>0;return f.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[f.jsxs("div",{className:"relative",children:[f.jsxs("h3",{className:"font-medium text-foreground text-sm p-3 px-4 bg-card border-b border-border text-foreground flex flex-row items-center gap-2",children:[s?f.jsx("button",{onClick:r,className:" text-muted-foreground hover:opacity-60 transition-all flex items-center",children:f.jsx(E9,{className:"h-4 w-4 -ml-0.5",strokeWidth:3})}):n>1?f.jsxs("span",{className:"font-bold text-muted-foreground whitespace-nowrap",children:[t+1," of ",n]}):null,e]}),n>1&&f.jsx("div",{className:"absolute bottom-0 left-0 right-0 h-0.5 bg-border",children:f.jsx("div",{className:"h-full bg-muted-foreground/40 transition-all duration-300",style:{width:`${t/n*100}%`}})})]}),i]})}function pj({label:e,description:t}){return f.jsxs(f.Fragment,{children:[f.jsx("span",{className:"text-foreground text-sm",children:e}),t&&f.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:t})]})}function SB({selected:e,multiSelect:t,onClick:n}){return f.jsx("button",{type:"button",onClick:n,className:he("flex-shrink-0 w-5 h-5 border-1 flex items-center justify-center",t?"rounded":"rounded-full",e?"border-transparent bg-foreground":"border-muted-foreground/50 bg-background",n&&e&&"cursor-pointer"),children:e&&f.jsx(gi,{strokeWidth:3,className:"translate-y-[0.5px] h-3 w-3 text-white dark:text-background"})})}function p0e({option:e,selected:t,multiSelect:n,onClick:r,isLast:i}){const s="w-full text-left p-3 pt-2.5 pl-4 pr-5 bg-background",o=i?"":"border-b border-border";return r?f.jsx("button",{onClick:r,className:he(s,o,"transition-all cursor-pointer"),children:f.jsxs("div",{className:"flex items-center justify-between gap-3",children:[f.jsx("div",{className:"flex-1 min-w-0",children:f.jsx(pj,{label:e.label,description:e.description})}),f.jsx(SB,{selected:t,multiSelect:n})]})}):f.jsx("div",{className:he(s,o),children:f.jsx(pj,{label:e.label,description:e.description})})}function m0e(e){return e==null?void 0:e.answers}function ds(e){return e.id||e.question}function wB({message:e,onSubmit:t,isLatest:n}){var H,W;const r=G0(),i=e.input.questions,s=!!e.result,o=m0e(e.result),l=((H=e.result)==null?void 0:H.discarded)===!0,[c,u]=v.useState(0),[p,h]=v.useState({}),[g,b]=v.useState({}),[_,x]=v.useState(o??null),[S,C]=v.useState(s),E=(Z,D)=>{var oe;const G=(oe=g[Z])==null?void 0:oe.trim(),ee=p[Z]||"",B=D||i.find(J=>ds(J)===Z);if(B!=null&&B.multiSelect)return[ee,G].filter(Boolean).flatMap(J=>J.split(", ").filter(Boolean));const le=G||ee;return le?[le]:[]},k=Z=>{const D=p[ds(Z)]||"";return Z.multiSelect?D.split(", ").filter(Boolean):[D]},T=(Z,D)=>{const G=ds(Z);if(Z.multiSelect){const ee=p[G]?p[G].split(", ").filter(Boolean):[],B=ee.includes(D)?ee.filter(le=>le!==D):[...ee,D];h({...p,[G]:B.join(", ")})}else h({...p,[G]:D}),b({...g,[G]:""}),c<i.length-1&&setTimeout(()=>u(c+1),150)},A=(Z,D)=>{const G=ds(Z);b({...g,[G]:D}),D&&!Z.multiSelect&&h({...p,[G]:""})},N=Z=>{const D=ds(Z);Z.multiSelect&&g[D]&&b({...g,[D]:""})},M=i.every(Z=>E(ds(Z),Z).length>0),j=i[c],U=c===i.length-1,I=j&&E(ds(j),j).length>0,P=()=>{c<i.length-1&&u(c+1)},z=()=>{c>0&&u(c-1)},O=()=>{if(!M)return;const Z={};for(const D of i){const G=ds(D);Z[G]=E(G,D)}x(Z),C(!0),t(e.toolId,i,Z)},$=Z=>{if(Z.key==="Enter"&&!(!j||!I)){if(Z.preventDefault(),U){O();return}P()}};if(S||s){const Z=o||_||{};return f.jsx("div",{className:"w-full",children:f.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[f.jsxs("div",{className:"font-medium text-sm p-3 px-4 pr-5 bg-muted border-b border-border flex flex-row items-center justify-between",children:[f.jsxs("p",{children:["Question",i.length!==1?"s":""]}),f.jsx("p",{className:"",children:l?"Discarded":"Answers"})]}),i.map((D,G)=>{const ee=Z[ds(D)]||Z[D.question]||[],B=G===i.length-1;return f.jsxs("div",{className:he("w-full p-3 pt-2.5 pl-4 pr-5 bg-background flex items-center justify-between gap-3",!B&&"border-b border-border"),children:[f.jsx("div",{className:"text-sm text-pretty",children:D.question}),ee.length>0&&f.jsx("div",{className:"text-sm font-medium text-right max-w-[50%] text-pretty",children:ee.join(", ")}),ee.length===0&&f.jsx("div",{className:"text-sm font-medium text-right italic",children:l?"Discarded":"No Response"})]},ds(D))})]})})}if(r.readonly)return f.jsx("div",{className:"w-full",children:f.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[f.jsxs("div",{className:"font-medium text-sm p-3 px-4 pr-5 bg-muted border-b border-border flex flex-row items-center justify-between gap-3",children:[f.jsxs("p",{children:["Question",i.length!==1?"s":""]}),f.jsx("p",{className:"text-muted-foreground",children:"Awaiting response"})]}),i.map((Z,D)=>{var G;return f.jsxs("div",{className:he("w-full p-3 pt-2.5 pl-4 pr-5 bg-background flex items-center justify-between gap-3",D<i.length-1&&"border-b border-border"),children:[f.jsx("div",{className:"text-sm text-pretty",children:Z.question}),f.jsx("div",{className:"max-w-[50%] text-right text-xs text-muted-foreground text-pretty",children:((G=Z.options)==null?void 0:G.map(ee=>ee.label).join(", "))||"Freeform response"})]},ds(Z))})]})});if(!n)return f.jsx("div",{className:"w-full py-2",children:f.jsxs("div",{className:"flex items-center gap-2",children:[f.jsx(KP,{className:"h-4 w-4 text-muted-foreground"}),f.jsx("span",{className:"text-sm text-muted-foreground",children:"Questions pending (newer question active)"})]})});if(!j)return null;const V=k(j),F=g[ds(j)]||"";return f.jsxs("div",{className:"w-full space-y-3",children:[f.jsxs(h0e,{question:j.question,currentIndex:c,totalQuestions:i.length,onBack:c>0?z:void 0,children:[(W=j.options)==null?void 0:W.map(Z=>f.jsx(p0e,{option:Z,selected:V.includes(Z.label),multiSelect:j.multiSelect,onClick:()=>T(j,Z.label)},Z.label)),f.jsx("div",{className:"transition-all bg-background",children:f.jsxs("div",{className:"flex pr-5 items-center justify-between gap-3",children:[f.jsx("input",{type:"text",value:F,onChange:Z=>A(j,Z.target.value),onKeyDown:$,placeholder:"Other...",className:"flex-1 px-3 !py-1 pl-4 min-h-[55px] min-w-0 text-sm bg-transparent outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background rounded-md text-foreground placeholder:text-muted-foreground"}),f.jsx(SB,{selected:!!F,multiSelect:j.multiSelect,onClick:j.multiSelect&&F?()=>N(j):void 0})]})})]}),f.jsxs("div",{className:"flex justify-end gap-2 mx-2",children:[!U&&I&&(j.multiSelect||!!F)&&f.jsx(Ke,{size:"sm",onClick:P,children:"Next"}),U&&f.jsx(Ke,{size:"sm",onClick:O,disabled:!M,className:he(!M&&"opacity-50 cursor-not-allowed","rounded-full"),children:"Submit"})]})]})}function CB({message:e,onConfirm:t,isLatest:n}){const r=G0(),i=!!e.result,[s,o]=v.useState(!1),[l,c]=v.useState(!1),[u,p]=v.useState(!1),[h,g]=v.useState(""),b=v.useRef(null),_=e.input;v.useEffect(()=>{u&&b.current&&b.current.focus()},[u]);const x=async()=>{_!=null&&_.plan&&(await navigator.clipboard.writeText(_.plan),c(!0),setTimeout(()=>c(!1),2e3))},S=i?e.result:null,C=(S==null?void 0:S.discarded)===!0;return f.jsxs("div",{className:"flex flex-col gap-3",children:[f.jsxs("div",{className:"relative rounded-2xl border border-border overflow-hidden group/plan",children:[(_==null?void 0:_.plan)&&f.jsx(Ke,{variant:"ghost",size:"icon","aria-label":l?"Copied":"Copy plan",className:he("absolute top-2 right-2 z-10 h-11 w-11 md:h-8 md:w-8 rounded-md text-muted-foreground opacity-100 md:opacity-0 md:group-hover/plan:opacity-100 transition-opacity [@media(hover:none)]:!opacity-100",!l&&"hover:text-foreground",l&&"hover:!bg-transparent hover:!border-transparent"),onClick:x,children:l?f.jsx(gi,{className:"h-4 w-4 text-success"}):f.jsx(El,{className:"h-4 w-4"})}),f.jsxs("div",{className:he("!pt-5 !pb-0 px-4 md:py-4.5 md:px-5.5 bg-muted dark:bg-card overflow-scroll no-pre-highlight transition-all",i&&!s?"max-h-[min(400px,40vh)] ":"",i?"hover:!pb-[32px]":""),children:[i&&f.jsxs(Ke,{variant:"ghost",className:"absolute z-10 bottom-2 pr-2.5 !pl-3.5 h-[34px] inline-flex gap-1 text-sm left-[50%] -translate-x-[50%] text-muted-foreground backdrop-blur-sm hover:text-foreground opacity-0 group-hover/plan:opacity-100 transition-all rounded-full border border-border",onClick:()=>o(!s),children:[s?"Show Less":"Show More",f.jsx(Hd,{className:`size-3.5 transition-transform ${s?"rotate-180":""}`})]}),_!=null&&_.plan?f.jsxs("div",{className:"prose prose-sm dark:prose-invert max-w-none",children:[f.jsx(Xc,{remarkPlugins:[Qc],components:sf(),children:_.plan}),f.jsx("div",{className:"mt-5"})]}):f.jsx("p",{className:"text-sm text-muted-foreground",children:"No plan provided"})]})]}),i?f.jsx("div",{className:"flex justify-end mx-2",children:f.jsxs("span",{className:"pl-4 inline text-sm font-medium bg-background text-foreground/60 border border-border py-1.5 px-3 rounded-[20px] leading-relaxed max-w-[85%] sm:max-w-[80%]",children:[f.jsx("em",{children:C?"Discarded":S!=null&&S.clearContext?"Approved & Cleared Context":S!=null&&S.confirmed?"Approved":S!=null&&S.message?`Adjusted: "${S.message}"`:"Adjusted Plan"}),f.jsx(U9,{className:"inline h-4 w-4 ml-1.5 -mt-0.5"})]})}):n?r.readonly?f.jsx("div",{className:"flex justify-end mx-2",children:f.jsx("span",{className:"inline text-sm text-muted-foreground italic",children:"Plan pending in original session"})}):f.jsxs("div",{className:"flex flex-col gap-3",children:[!u&&f.jsxs("div",{className:"flex flex-col md:flex-row items-stretch md:items-center justify-end gap-2 mx-2",children:[f.jsxs(Ke,{size:"sm",onClick:()=>t(e.toolId,!0,!0),className:"rounded-full bg-primary text-background pr-4 md:order-last",children:[f.jsx(_9,{className:"h-4 w-4 mr-1.5"}),"Approve & Clear"]}),f.jsxs("div",{className:"flex items-stretch md:items-center gap-2 md:contents",children:[f.jsxs(Ke,{size:"sm",variant:"outline",onClick:()=>p(!0),className:"rounded-full border-border flex-1 md:flex-initial md:order-first",children:[f.jsx(Rp,{className:"h-4 w-4 mr-1.5"}),"Suggest Edits"]}),f.jsxs(Ke,{size:"sm",variant:"outline",onClick:()=>t(e.toolId,!0),className:"rounded-full border-border flex-1 md:flex-initial",children:[f.jsx(gi,{className:"h-4 w-4 mr-1.5"}),"Approve"]})]})]}),u&&f.jsxs("div",{className:"flex flex-col gap-2",children:[f.jsx("textarea",{ref:b,value:h,onChange:E=>g(E.target.value),onKeyDown:E=>{E.key==="Enter"&&!E.shiftKey&&h.trim()&&(E.preventDefault(),t(e.toolId,!1,void 0,h.trim())),E.key==="Escape"&&(p(!1),g(""))},placeholder:"Describe what you'd like to change...",rows:3,className:"w-full rounded-2xl border border-border bg-muted dark:bg-card px-4 py-3 text-sm text-foreground placeholder:text-muted-foreground resize-none outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"}),f.jsxs("div",{className:"flex items-center justify-end gap-2 mx-2",children:[f.jsx(Ke,{size:"sm",variant:"ghost",onClick:()=>{p(!1),g("")},className:"rounded-full text-muted-foreground",children:"Cancel"}),f.jsxs(Ke,{size:"sm",disabled:!h.trim(),onClick:()=>t(e.toolId,!1,void 0,h.trim()),className:"rounded-full bg-primary text-background disabled:opacity-50 disabled:pointer-events-none",children:[f.jsx(IW,{className:"h-4 w-4 mr-1.5"}),"Adjust Plan"]})]})]})]}):f.jsx("div",{className:"flex justify-end mx-2",children:f.jsx("span",{className:"inline text-sm text-muted-foreground italic",children:"Plan pending (newer prompt active)"})})]})}function g0e({pendingTool:e,onAskUserQuestionSubmit:t,onExitPlanModeSubmit:n}){if(e.toolKind==="ask_user_question"){const r=e.input,i={id:e.toolUseId,kind:"tool",toolKind:"ask_user_question",toolName:"AskUserQuestion",toolId:e.toolUseId,input:{questions:r.questions??[]},timestamp:new Date(e.requestedAt).toISOString()};return f.jsxs("div",{"data-testid":`subagent-pending-tool:${e.toolUseId}`,children:[f.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground mb-1",children:"awaiting your response"}),f.jsx(wB,{message:i,onSubmit:t,isLatest:!0})]})}if(e.toolKind==="exit_plan_mode"){const r=e.input,i={id:e.toolUseId,kind:"tool",toolKind:"exit_plan_mode",toolName:"ExitPlanMode",toolId:e.toolUseId,input:{plan:r.plan,summary:r.summary},timestamp:new Date(e.requestedAt).toISOString()};return f.jsxs("div",{"data-testid":`subagent-pending-tool:${e.toolUseId}`,children:[f.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground mb-1",children:"awaiting your response"}),f.jsx(CB,{message:i,onConfirm:(s,o,l,c)=>n(s,{confirmed:o,clearContext:l,message:c}),isLatest:!0})]})}return null}function kB({run:e,indentDepth:t,localPath:n,onOpenSettings:r,onRetry:i,onSubagentAskUserQuestionSubmit:s,onSubagentExitPlanModeSubmit:o,onCancelSubagentRun:l}){var h;const c=fB(e.entries),u=c.some(g=>g.kind==="assistant_text"),p=e.status==="running"&&u;return f.jsxs("div",{"data-testid":`subagent-message:${e.runId}`,className:he("border-l-2 border-accent pl-3 py-2 space-y-2"),style:{marginLeft:`${t*24}px`},children:[f.jsxs("header",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[f.jsx(LC,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:e.subagentName}),f.jsxs("span",{className:"opacity-60",children:[e.provider,e.model?`/${e.model}`:""]}),((h=e.usage)==null?void 0:h.outputTokens)!=null&&f.jsxs("span",{className:"opacity-60",children:["· ",e.usage.inputTokens??0,"↑ ",e.usage.outputTokens,"↓"]}),e.status==="running"&&f.jsx("span",{className:"ml-auto inline-block animate-pulse",children:p?"streaming...":"running..."}),l&&e.status==="running"&&f.jsx("button",{type:"button","data-testid":`subagent-cancel:${e.runId}`,"aria-label":"Cancel subagent",onClick:()=>l(e.chatId,e.runId),className:"text-muted-foreground hover:text-foreground",children:f.jsx(eo,{className:"h-3.5 w-3.5"})})]}),c.map(g=>f.jsx(u0e,{message:g,localPath:n},g.id)),e.pendingTool&&f.jsx(g0e,{pendingTool:e.pendingTool,onAskUserQuestionSubmit:(g,b,_)=>s==null?void 0:s(e.runId,g,b,_),onExitPlanModeSubmit:(g,b)=>o==null?void 0:o(e.runId,g,b)}),c.length===0&&e.finalText&&f.jsxs("div",{className:he("whitespace-pre-wrap text-sm",p&&"text-foreground/80"),children:[e.finalText,p&&f.jsx("span",{className:"ml-0.5 inline-block w-2 animate-pulse",children:"▍"})]}),e.status==="failed"&&e.error&&f.jsx("div",{children:f.jsx(f0e,{error:e.error,runId:e.runId,subagentId:e.subagentId,onOpenSettings:r,onRetry:i})})]})}function v0e(e){var n;const t=e.match(/^<system-message>\s*([\s\S]*?)\s*<\/system-message>\s*([\s\S]*)$/);return t?{systemMessage:((n=t[1])==null?void 0:n.trim())||null,body:t[2]??""}:{systemMessage:null,body:e}}function b0e({content:e,attachments:t=[],steered:n=!1,autoContinue:r}){const[i,s]=v.useState(null),o=G0(),l=v.useMemo(()=>v0e(e),[e]),c=o.attachmentMode==="metadata",u=!o.readonly||o.attachmentMode==="bundle",p=v.useMemo(()=>t.filter(_=>_.kind==="image"&&(_.contentUrl||c)),[t,c]),h=v.useMemo(()=>t.filter(_=>_.kind!=="image"||!_.contentUrl&&!c),[t,c]),g=t.find(_=>_.id===i)??null;function b(_){if(!u||!_.contentUrl)return;if(Gp(_).openInNewTab){typeof window<"u"&&window.open(new URL(_.contentUrl,document.baseURI||window.location.href).toString(),"_blank","noopener,noreferrer");return}s(_.id)}return f.jsxs(f.Fragment,{children:[f.jsxs("div",{className:"flex flex-col items-end gap-2",children:[p.length>0?f.jsx("div",{className:"flex max-w-[85%] sm:max-w-[80%] flex-wrap justify-end gap-3",children:p.map(_=>f.jsx(kE,{attachment:_,onClick:u?()=>b(_):void 0},_.id))}):null,h.length>0?f.jsx("div",{className:"flex max-w-[85%] sm:max-w-[80%] flex-wrap justify-end gap-2",children:h.map(_=>f.jsx(Sl,{attachment:_,onClick:u?()=>b(_):void 0},_.id))}):null,l.body||!l.body&&t.length===0&&e&&!l.systemMessage?f.jsxs("div",{className:"flex max-w-[85%] items-center gap-2 sm:max-w-[80%]",children:[n?f.jsx(hG,{"aria-label":"Sent mid-turn",className:"size-3.5 shrink-0 text-muted-foreground"}):null,f.jsx("div",{className:"min-w-0 flex-1 rounded-[20px] border border-border bg-muted px-3.5 py-1.5 text-primary prose prose-sm prose-invert [&_p]:whitespace-pre-line",children:f.jsx(Xc,{remarkPlugins:[Qc],components:sf(),children:l.body})})]}):null,r?f.jsx("span",{className:"text-xs text-muted-foreground opacity-70",children:"auto-sent"}):null]}),f.jsx(W0,{attachment:g,onOpenChange:_=>!_&&s(null)})]})}function y0e({json:e}){return f.jsx("div",{className:"flex gap-3 justify-start",children:f.jsx("div",{className:"flex-1 max-w-[90%]",children:f.jsx("pre",{className:"text-xs font-mono whitespace-pre-wrap break-words bg-muted rounded-lg p-3 overflow-auto max-h-96",children:e})})})}function EB({title:e,count:t,children:n,badge:r}){const[i,s]=v.useState(!1);return t===0?null:f.jsxs("div",{className:"flex flex-col gap-1.5",children:[f.jsxs("button",{onClick:()=>s(!i),className:"flex items-center gap-1 cursor-pointer group/section hover:opacity-60 transition-opacity",children:[f.jsx(To,{className:he("h-3.5 w-3.5 text-muted-foreground transition-transform duration-200",i&&"rotate-90")}),f.jsx("span",{className:"text-muted-foreground font-medium",children:e}),f.jsx("span",{className:"text-muted-foreground/60",children:t}),r]}),i&&f.jsx("div",{className:"ml-5",children:n})]})}function jS({title:e,items:t,icon:n,getIcon:r}){return t.length===0?null:f.jsx(EB,{title:e,count:t.length,children:f.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.map(i=>f.jsx(z8,{icon:r?r(i):n,children:i},i))})})}function _0e(e){const t=e.match(/^mcp__([^_]+)__(.+)$/);return t?{server:t[1],tool:t[2]}:null}function RB({status:e}){const t=e==="connected"?"bg-success":e==="pending"?"bg-warning":"bg-destructive";return f.jsx("span",{className:he("inline-block h-2 w-2 rounded-full shrink-0",t)})}function x0e(e){switch(e){case"connected":return"Connected";case"failed":return"Failed";case"needs-auth":return"Needs auth";case"pending":return"Connecting...";case"disabled":return"Disabled";default:return e}}function mj({server:e}){const[t,n]=v.useState(!1),r=e.status==="connected";return f.jsxs("div",{className:"flex flex-col gap-1.5",children:[f.jsxs("button",{onClick:()=>r&&e.tools.length>0&&n(!t),className:he("flex items-center gap-1.5",r&&e.tools.length>0&&"cursor-pointer hover:opacity-60 transition-opacity"),children:[r&&e.tools.length>0&&f.jsx(To,{className:he("h-3 w-3 text-muted-foreground transition-transform duration-200",t&&"rotate-90")}),f.jsx(RB,{status:e.status}),f.jsx("span",{className:"text-muted-foreground font-medium",children:_w(e.name)}),r?f.jsxs("span",{className:"text-muted-foreground/50",children:[e.tools.length," tools"]}):f.jsx("span",{className:"text-muted-foreground/50",children:x0e(e.status)})]}),!r&&e.error&&f.jsx("span",{className:"text-destructive ml-5",children:e.error}),t&&e.tools.length>0&&f.jsx("div",{className:"flex flex-wrap gap-1.5 ml-5",children:e.tools.map(i=>f.jsx(z8,{icon:D8(`mcp__${e.name}__${i}`),children:i},i))})]})}function S0e({servers:e}){if(e.length===0)return null;const t=e.filter(i=>i.status==="connected"),n=e.filter(i=>i.status!=="connected"),r=n.length>0?f.jsxs("span",{className:"flex items-center gap-1 ml-1",children:[f.jsx(RB,{status:"failed"}),f.jsxs("span",{className:"text-muted-foreground/60",children:[n.length," disconnected"]})]}):null;return f.jsx(EB,{title:"MCP Servers",count:e.length,badge:r,children:f.jsxs("div",{className:"flex flex-col gap-2",children:[t.map(i=>f.jsx(mj,{server:i},i.name)),n.map(i=>f.jsx(mj,{server:i},i.name))]})})}function w0e({rawJson:e}){const[t,n]=v.useState(!1);return f.jsxs("div",{className:"flex flex-col gap-1.5",children:[f.jsxs("button",{onClick:()=>n(!t),className:"flex items-center gap-1 cursor-pointer group/section hover:opacity-60 transition-opacity",children:[f.jsx(To,{className:he("h-3.5 w-3.5 text-muted-foreground transition-transform duration-200",t&&"rotate-90")}),f.jsx("span",{className:"text-muted-foreground font-medium",children:"Raw Message"})]}),t&&f.jsx("pre",{className:"ml-5 text-xs whitespace-pre-wrap break-all border border-border rounded-md p-3 overflow-x-auto max-h-96 overflow-y-auto",children:e})]})}function C0e({message:e,rawJson:t}){const{coreTools:n,mcpServersWithTools:r}=v.useMemo(()=>{const i=new Map,s=[];for(const l of e.tools){const c=_0e(l);if(c){const u=i.get(c.server)||[];u.push(c.tool),i.set(c.server,u)}else s.push(l)}const o=e.mcpServers.map(l=>({name:l.name,status:l.status,error:l.error,tools:i.get(l.name)||[]}));return{coreTools:s,mcpServersWithTools:o}},[e.tools,e.mcpServers]);return f.jsx(Ca,{children:f.jsxs(q0,{expandedContent:f.jsx(K0,{className:"my-4 text-xs",children:f.jsxs("div",{className:"flex flex-col gap-3",children:[f.jsx(pge,{children:e.model}),f.jsx(jS,{title:"Tools",items:n,getIcon:i=>R1[i]??j8}),f.jsx(jS,{title:"Agents",items:e.agents,icon:n0}),f.jsx(jS,{title:"Commands",items:e.slashCommands,icon:BW}),f.jsx(S0e,{servers:r}),t&&f.jsx(w0e,{rawJson:t})]})}),children:[f.jsx(c9,{className:"h-5 w-5 text-logo"}),f.jsx(Nl,{children:"Session Started"})]})})}function k0e({message:e}){return f.jsx(Ca,{className:"hidden",children:f.jsxs(q0,{expandedContent:f.jsx(K0,{className:"my-4 text-xs",children:f.jsx("pre",{className:"font-mono whitespace-pre-wrap break-all bg-muted border border-border rounded-lg p-2 max-h-64 overflow-auto",children:JSON.stringify(e.accountInfo,null,2)})}),children:[f.jsx("div",{className:"size-5 flex justify-center items-center ",children:f.jsx(n0,{className:"h-4 w-4 text-muted-foreground"})}),f.jsx(Nl,{children:"Account"})]})})}const E0e={completed:{Icon:gi,iconClass:"text-success",textClass:"text-muted-foreground"},in_progress:{Icon:kn,iconClass:"text-foreground animate-spin",textClass:"text-foreground font-medium"},pending:{Icon:L9,iconClass:"text-muted-foreground",textClass:"text-muted-foreground"}};function R0e({message:e}){const t=e.input.todos;return t.length?f.jsx("div",{className:"w-full",children:f.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[f.jsxs("h3",{className:"font-medium text-foreground text-sm p-3 px-4 bg-card border-b border-border flex items-center gap-2",children:[f.jsx(HV,{className:"h-4 w-4 text-muted-foreground"}),"Progress"]}),f.jsx("div",{children:t.map((n,r)=>{const i=r===t.length-1,{Icon:s,iconClass:o,textClass:l}=E0e[n.status];return f.jsxs("div",{className:he("flex items-center gap-3 px-4 py-2.5 bg-background",!i&&"border-b border-border"),children:[f.jsx(s,{className:he("h-4 w-4 flex-shrink-0",o)}),f.jsx("span",{className:he("text-sm",l),children:n.status==="in_progress"?n.activeForm:n.content})]},r)})})]})}):null}function T0e({message:e}){const t=e.result,n=t==null?void 0:t.contentUrl,[r,i]=v.useState("idle");if(v.useEffect(()=>{if(!n)return;const h=new AbortController;return fetch(n,{method:"HEAD",signal:h.signal}).then(g=>{h.signal.aborted||i(g.ok?"ready":"missing")}).catch(()=>{}),()=>h.abort()},[n]),!t||!n)return null;const s={id:`offer-download-${e.toolId}`,kind:"file",displayName:t.displayName||t.fileName,absolutePath:t.relativePath,relativePath:t.relativePath,contentUrl:n,mimeType:t.mimeType??"application/octet-stream",size:t.size},o=oE(s),l=M6(o,t.mimeType),c=t.size>0?Yp(t.size):null,u=f.jsxs(f.Fragment,{children:[l,c?f.jsxs(f.Fragment,{children:[" · ",f.jsx("span",{className:"tabular-nums",children:c})]}):null]}),p=["Download",s.displayName,l,c].filter(Boolean);return r==="missing"?f.jsx("div",{className:"flex","data-testid":"offer-download-link",children:f.jsx(Sl,{attachment:s,disabledReason:"File no longer available"})}):f.jsx("div",{className:"flex","data-testid":"offer-download-link",children:f.jsx(Sl,{attachment:s,href:n,download:t.fileName||void 0,meta:u,ariaLabel:p.join(", ")})})}function A0e({message:e}){return f.jsx("div",{className:"flex items-center justify-end gap-2 text-sm text-muted-foreground",children:f.jsxs("div",{className:"inline-flex gap-1.5 items-center justify-center whitespace-nowrap text-sm font-medium bg-background text-foreground/60 border border-border h-9 pl-1 pr-4 rounded-full",children:[f.jsx(N9,{className:"h-4 w-4 ml-1.5"}),f.jsx("em",{children:"Interrupted"})]})})}function Ob({size:e=4}){return f.jsxs("svg",{className:"flex-1",viewBox:`0 0 100 ${e}`,preserveAspectRatio:"none",style:{height:`${e}px`},children:[f.jsx("pattern",{id:"zigzag",width:e,height:e,patternUnits:"userSpaceOnUse",children:f.jsx("path",{d:`M0 ${e} L${e/2} 0 L${e} ${e}`,fill:"none",stroke:"currentColor",strokeWidth:"0.5",className:"text-muted-foreground/30",style:{stroke:"currentColor"}})}),f.jsx("rect",{width:"100%",height:e,fill:"url(#zigzag)",className:"text-muted-foreground/30"})]})}function N0e(){return f.jsxs("div",{className:"flex items-center gap-3",children:[f.jsx(Ob,{}),f.jsx("span",{className:"text-[11px] tracking-widest text-muted-foreground uppercase flex-shrink-0",children:"Compacted"}),f.jsx(Ob,{})]})}function M0e(){return f.jsxs("div",{className:"flex items-center gap-3",children:[f.jsx(Ob,{}),f.jsx("span",{className:"text-[11px] tracking-widest text-muted-foreground uppercase flex-shrink-0",children:"Context Cleared"}),f.jsx(Ob,{})]})}function L0e({message:e}){return f.jsx(Ca,{children:f.jsxs(q0,{expandedContent:f.jsx(K0,{className:"my-4 text-xs",children:f.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none",children:f.jsx(Xc,{remarkPlugins:[Qc],components:sf(),children:e.summary})})}),children:[f.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:f.jsx(YP,{className:"h-4.5 w-4.5 text-muted-foreground"})}),f.jsx(Nl,{children:"Summarized"})]})})}const I0e={compacting:"Compacting..."};function j0e({message:e}){const t=I0e[e.status]||e.status;return f.jsxs(Ca,{className:"grid grid-cols-[auto_1fr] items-center gap-1.5 text-sm animate-pulse",children:[f.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:f.jsx(YP,{className:"h-4.5 w-4.5 text-muted-foreground"})}),f.jsx(Nl,{className:"text-left transition-opacity duration-200 truncate",children:t})]})}const D0e={read_file:{key:"read",singular:"read",plural:"reads"},edit_file:{key:"edit",singular:"edit",plural:"edits"},write_file:{key:"write",singular:"write",plural:"writes"},delete_file:{key:"delete",singular:"delete",plural:"deletes"},bash:{key:"bash",singular:"command",plural:"commands"},grep:{key:"grep",singular:"search",plural:"searches"},glob:{key:"glob",singular:"glob",plural:"globs"},subagent_task:{key:"task",singular:"agent",plural:"agents"},web_search:{key:"websearch",singular:"web search",plural:"web searches"},skill:{key:"skill",singular:"skill",plural:"skills"},todo_write:{key:"todo",singular:"todo update",plural:"todo updates"}},P0e={key:"other",singular:"tool call",plural:"tool calls"};function O0e(e){return D0e[e]??P0e}function z0e(e){const t=new Map,n=[];for(const r of e){const i=r.toolKind,s=O0e(i),o=t.get(s.key);o?o.count++:(t.set(s.key,{category:s,count:1}),n.push(s.key))}return n.map(r=>{const{category:i,count:s}=t.get(r);return`${s} ${s===1?i.singular:i.plural}`}).join(", ")}function B0e({messages:e,isLoading:t,localPath:n,expanded:r,onExpandedChange:i}){const s=v.useMemo(()=>z0e(e),[e]),l=e.some(c=>c.result===void 0)&&t;return f.jsx(Ca,{className:"w-full",children:f.jsxs("div",{className:"flex flex-col w-full",children:[f.jsx("button",{onClick:()=>i(!r),className:`group cursor-pointer grid grid-cols-[auto_1fr] items-center gap-1 text-sm ${!r&&!l?"hover:opacity-60 transition-opacity":""}`,children:f.jsxs("div",{className:"grid grid-cols-[auto_1fr] items-center gap-1.5",children:[f.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:f.jsx(To,{className:`h-4.5 w-4.5 text-muted-icon transition-all duration-200 ${r?"rotate-90":""}`})}),f.jsx(Nl,{className:"text-left",children:f.jsx(Xp,{animate:l,children:s})})]})}),r&&f.jsxs("div",{className:"my-4 flex flex-col gap-3",children:[e.map(c=>f.jsx(Pb,{message:c,isLoading:t,localPath:n},c.id)),e.length>5&&f.jsx("button",{onClick:()=>i(!1),className:"cursor-pointer grid grid-cols-[auto_1fr] items-center gap-1 text-xs hover:opacity-80 transition-opacity",children:f.jsxs("div",{className:"grid grid-cols-[auto_1fr] items-center gap-1.5",children:[f.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:f.jsx(To,{className:"h-4.5 w-4.5 text-muted-icon -rotate-90"})}),f.jsx(Nl,{className:"text-left",children:"Collapse"})]})})]})]})})}function F0e(e){if(e!=="system")return e}function DS(e,t){const n=F0e(t),r=new Intl.DateTimeFormat("en-GB",{timeZone:n,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hour12:!1}).formatToParts(new Date(e)),i=o=>{var l;return((l=r.find(c=>c.type===o))==null?void 0:l.value)??"00"};let s=i("hour");return s==="24"&&(s="00"),`${i("day")}/${i("month")}/${i("year")} ${s}:${i("minute")}`}const $0e=/^(\d{2})\/(\d{2})\/(\d{4}) (\d{2}):(\d{2})$/;function gj(e,t){if(e==="system")return-new Date(t).getTimezoneOffset();const n=new Intl.DateTimeFormat("en-US",{timeZone:e,hour12:!1,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}).formatToParts(new Date(t)),r=o=>{var l;return Number(((l=n.find(c=>c.type===o))==null?void 0:l.value)??0)};let i=r("hour");i===24&&(i=0);const s=Date.UTC(r("year"),r("month")-1,r("day"),i,r("minute"),r("second"));return Math.round((s-t)/6e4)}function H0e(e,t){const n=$0e.exec(e.trim());if(!n)return null;const[,r,i,s,o,l]=n,c=Number(r),u=Number(i),p=Number(s),h=Number(o),g=Number(l);if(u<1||u>12||c<1||c>31||h>23||g>59)return null;const b=Date.UTC(p,u-1,c,h,g),_=gj(t,b),x=b-_*6e4,S=gj(t,x);return x-(S-_)*6e4}const U0e={neutral:"border-border bg-card",muted:"border-border/50 bg-card/50 opacity-75",success:"border-emerald-500/30 bg-emerald-500/5",error:"border-destructive/40 bg-destructive/5"},V0e={primary:"default",secondary:"secondary",ghost:"ghost",destructive:"destructive"};function ca({title:e,description:t,body:n,errorMessage:r,tone:i="neutral",actions:s=[]}){const[o,l]=v.useState(null),[c,u]=v.useState(null),p=v.useCallback(async g=>{if(o)return;u(null);let b;try{b=g.onClick()}catch(_){console.error("[transcript-action-card] sync click threw",_),u(_ instanceof Error?_.message:String(_));return}if(b instanceof Promise){l(g.id);try{await b}catch(_){console.error("[transcript-action-card] async click rejected",_),u(_ instanceof Error?_.message:String(_))}finally{l(null)}}},[o]),h=o!==null;return f.jsxs("div",{"data-focus-fallback-ignore":!0,className:he("rounded-lg border px-4 py-3 text-sm space-y-2 transition-colors",U0e[i]),children:[f.jsx("div",{className:"flex items-start justify-between gap-3",children:f.jsxs("div",{className:"space-y-1 min-w-0 flex-1",children:[f.jsx("div",{className:"font-medium leading-tight",children:e}),t?f.jsx("div",{className:"text-muted-foreground text-xs leading-snug",children:t}):null]})}),n?f.jsx("div",{className:"text-xs leading-snug",children:n}):null,r?f.jsx("div",{className:"text-destructive text-xs leading-snug",children:r}):null,c?f.jsx("div",{className:"text-destructive text-xs leading-snug",role:"alert",children:c}):null,s.length>0?f.jsx("div",{className:"flex flex-wrap gap-2 pt-1",children:s.map(g=>{const b=o===g.id;return f.jsxs(Ke,{type:"button",size:"sm",variant:V0e[g.variant??"ghost"],disabled:g.disabled||h&&!b,onClick:()=>{p(g)},className:"gap-1.5",children:[b?f.jsx(kn,{className:"size-3.5 animate-spin"}):null,g.label]},g.id)})}):null]})}function W0e({schedule:e,onAccept:t,onReschedule:n,onCancel:r}){const[i,s]=v.useState(()=>DS(e.scheduledAt??e.resetAt,e.tz)),[o,l]=v.useState(!1),c=v.useMemo(()=>H0e(i,e.tz),[i,e.tz]),u=c!==null&&c>Date.now(),p=c===null?"Use format dd/mm/yyyy hh:mm":u?null:"Time must be in the future";if(e.state==="fired"){const _=DS(e.scheduledAt??e.resetAt,e.tz);return f.jsx(ca,{title:`Auto-continued at ${_}`,tone:"success"})}if(e.state==="cancelled")return f.jsx(ca,{title:"Auto-continue cancelled",tone:"muted"});if(e.state==="proposed"){const _=e.resetAt<=Date.now(),x=[{id:"schedule",label:"Schedule",variant:"primary",disabled:!u,onClick:()=>{c!==null&&t(c)}},{id:"dismiss",label:"Dismiss",variant:"ghost",onClick:()=>r()}];return f.jsx(ca,{title:"Rate limit hit — schedule auto-continue?",description:_?"Reset time has passed — accept to continue now.":void 0,body:f.jsxs("div",{className:"space-y-1",children:[f.jsx(ir,{value:i,onChange:S=>s(S.target.value),placeholder:"dd/mm/yyyy hh:mm"}),p&&f.jsx("div",{className:"text-destructive text-xs",children:p})]}),actions:x})}const h=DS(e.scheduledAt??e.resetAt,e.tz),g=e.tz==="system"?"local":e.tz;if(!o){const _=[{id:"change",label:"Change time",variant:"secondary",onClick:()=>l(!0)},{id:"cancel",label:"Cancel",variant:"ghost",onClick:()=>r()}];return f.jsx(ca,{title:`Auto-continue at ${h} (${g})`,actions:_})}const b=[{id:"save",label:"Save",variant:"primary",disabled:!u,onClick:()=>{c!==null&&(n(c),l(!1))}},{id:"back",label:"Back",variant:"ghost",onClick:()=>l(!1)}];return f.jsx(ca,{title:`Auto-continue at ${h} (${g})`,body:f.jsxs("div",{className:"space-y-1",children:[f.jsx(ir,{value:i,onChange:_=>s(_.target.value),placeholder:"dd/mm/yyyy hh:mm"}),p&&f.jsx("div",{className:"text-destructive text-xs",children:p})]}),actions:b})}function G0e({toolRequestId:e,questions:t,onAnswer:n}){const[r,i]=v.useState({});function s(u){return u.id??u.question}function o(u,p){const h=s(u);u.multiSelect?i(g=>{const b=g[h]??[],_=b.includes(p)?b.filter(x=>x!==p):[...b,p];return{...g,[h]:_}}):i(g=>({...g,[h]:[p]}))}function l(){const u={};for(const p of t){const h=s(p);u[h]=r[h]??[]}n(e,{kind:"answer",payload:{questions:t,answers:u}})}const c=t.every(u=>{var h;const p=s(u);return(((h=r[p])==null?void 0:h.length)??0)>0});return f.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[f.jsxs("div",{className:"font-medium text-sm p-3 px-4 bg-muted border-b border-border flex items-center justify-between",children:[f.jsxs("span",{children:["Question",t.length!==1?"s":""]}),f.jsx("span",{className:"text-xs text-muted-foreground",children:"Reconnected — awaiting your response"})]}),t.map((u,p)=>{var _;const h=s(u),g=r[h]??[],b=p===t.length-1;return f.jsxs("div",{className:`bg-background px-4 py-3 ${b?"":"border-b border-border"}`,children:[f.jsx("p",{className:"text-sm font-medium mb-2",children:u.question}),u.options&&u.options.length>0?f.jsx("div",{className:"flex flex-wrap gap-2",children:u.options.map(x=>f.jsx("button",{onClick:()=>o(u,x.label),className:`rounded-full border px-3 py-1 text-xs transition-colors ${g.includes(x.label)?"border-foreground bg-foreground text-background":"border-border bg-background text-foreground hover:bg-muted"}`,children:x.label},x.label))}):f.jsx("input",{type:"text",className:"w-full rounded-md border border-border bg-muted px-3 py-1.5 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring",placeholder:"Type your answer...",value:((_=r[h])==null?void 0:_[0])??"",onChange:x=>{const S=x.target.value;i(C=>({...C,[h]:S?[S]:[]}))}})]},h)}),f.jsxs("div",{className:"flex justify-end gap-2 px-4 py-3 bg-background border-t border-border",children:[f.jsx(Ke,{size:"sm",variant:"outline",className:"rounded-full",onClick:()=>n(e,{kind:"deny",reason:"user_canceled"}),children:"Cancel"}),f.jsx(Ke,{size:"sm",className:"rounded-full",disabled:!c,onClick:l,children:"Submit"})]})]})}function q0e({toolRequestId:e,plan:t,onAnswer:n}){return f.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[f.jsxs("div",{className:"font-medium text-sm p-3 px-4 bg-muted border-b border-border flex items-center justify-between",children:[f.jsx("span",{children:"Plan"}),f.jsx("span",{className:"text-xs text-muted-foreground",children:"Reconnected — awaiting your response"})]}),f.jsx("div",{className:"bg-background px-4 py-3",children:f.jsx("p",{className:"text-sm whitespace-pre-wrap",children:t})}),f.jsxs("div",{className:"flex justify-end gap-2 px-4 py-3 bg-background border-t border-border",children:[f.jsx(Ke,{size:"sm",variant:"outline",className:"rounded-full",onClick:()=>n(e,{kind:"deny",reason:"user_canceled"}),children:"Edit"}),f.jsx(Ke,{size:"sm",className:"rounded-full",onClick:()=>n(e,{kind:"answer",payload:{confirmed:!0}}),children:"Confirm"})]})]})}function K0e({toolRequestId:e,toolName:t,onAnswer:n}){return f.jsxs("div",{className:"flex items-center gap-3 rounded-2xl border border-border bg-background px-4 py-3 text-sm",children:[f.jsxs("span",{className:"text-muted-foreground flex-1",children:["Pending tool: ",f.jsx("span",{className:"font-mono text-foreground",children:t})]}),f.jsx("button",{className:"text-xs text-muted-foreground underline hover:text-foreground transition-colors",onClick:()=>n(e,{kind:"deny",reason:"user_canceled"}),children:"Cancel"})]})}function Y0e({entry:e,onAnswer:t}){const{toolRequestId:n,toolName:r,arguments:i}=e;if(r==="mcp__kanna__ask_user_question"){const s=i.questions??[];return f.jsx(G0e,{toolRequestId:n,questions:s,onAnswer:t})}if(r==="mcp__kanna__exit_plan_mode"){const s=typeof i.plan=="string"?i.plan:"";return f.jsx(q0e,{toolRequestId:n,plan:s,onAnswer:t})}return f.jsx(K0e,{toolRequestId:n,toolName:r,onAnswer:t})}const X0e=new Set(["AskUserQuestion","ExitPlanMode","TodoWrite"]);function vj(e){if(e.kind!=="tool")return!1;const t=e.toolName;return!X0e.has(t)}function Q0e(e,{isFirstSystem:t,isFirstAccount:n,isLatestTodoWrite:r,hideResult:i,isFinalStatus:s}){let o=!e.hidden;if(o)switch(e.kind){case"system_init":o=t;break;case"account_info":o=n;break;case"tool":o=e.toolKind!=="todo_write"||r;break;case"result":o=!i&&(!e.success||e.durationMs>6e4);break;case"context_window_updated":o=!1;break;case"status":o=s;break;default:o=!0;break}return{isFirstSystem:t,isFirstAccount:n,isLatestTodoWrite:r,hideResult:i,isFinalStatus:s,shouldRender:o}}function Z0e(e,t){const n=e.findIndex(i=>i.kind==="system_init"),r=e.findIndex(i=>i.kind==="account_info");return e.map((i,s)=>{const o=e[s-1],l=e[s+1];return Q0e(i,{isFirstSystem:n===s,isFirstAccount:r===s,isLatestTodoWrite:i.id===t.TodoWrite,hideResult:(l==null?void 0:l.kind)==="context_cleared"||(o==null?void 0:o.kind)==="context_cleared",isFinalStatus:s===e.length-1})})}function J0e(e,t){const n=[];let r=0;for(;r<e.length;){const i=e[r],s=t[r];if(s!=null&&s.shouldRender&&vj(i)){const o=[i],l=r;for(r+=1;r<e.length;){const c=e[r],u=t[r];if(!(u!=null&&u.shouldRender)){r+=1;continue}if(!vj(c))break;o.push(c),r+=1}o.length>=2?n.push({type:"tool-group",messages:o,startIndex:l}):n.push({type:"single",message:i,index:l});continue}n.push({type:"single",message:i,index:r}),r+=1}return n}function bj(e){var n;return e.type==="single"?e.message.id:`tool-group:${((n=e.messages[0])==null?void 0:n.id)??e.startIndex}`}function PS(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>n===t[r])}function eye(e,t){return e.id===t.id&&e.kind===t.kind&&e.displayName===t.displayName&&e.absolutePath===t.absolutePath&&e.relativePath===t.relativePath&&e.contentUrl===t.contentUrl&&e.mimeType===t.mimeType&&e.size===t.size}function tye(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>eye(n,t[r]))}function Id(e,t){var n,r;if(e===t)return!0;if(e.kind!==t.kind||e.id!==t.id||e.hidden!==t.hidden)return!1;switch(e.kind){case"user_prompt":return e.content===(t.kind==="user_prompt"?t.content:null)&&t.kind==="user_prompt"&&e.steered===t.steered&&((n=e.autoContinue)==null?void 0:n.scheduleId)===((r=t.autoContinue)==null?void 0:r.scheduleId)&&tye(e.attachments,t.attachments);case"system_init":return t.kind==="system_init"&&e.provider===t.provider&&e.model===t.model&&PS(e.tools,t.tools)&&PS(e.agents,t.agents)&&PS(e.slashCommands,t.slashCommands)&&e.debugRaw===t.debugRaw;case"account_info":return t.kind==="account_info"&&JSON.stringify(e.accountInfo)===JSON.stringify(t.accountInfo);case"assistant_text":return t.kind==="assistant_text"&&e.text===t.text;case"tool":return t.kind==="tool"&&e.toolKind===t.toolKind&&e.toolName===t.toolName&&e.toolId===t.toolId&&e.isError===t.isError&&JSON.stringify(e.input)===JSON.stringify(t.input)&&JSON.stringify(e.result)===JSON.stringify(t.result)&&JSON.stringify(e.rawResult)===JSON.stringify(t.rawResult);case"result":return t.kind==="result"&&e.success===t.success&&e.cancelled===t.cancelled&&e.result===t.result&&e.durationMs===t.durationMs&&e.costUsd===t.costUsd;case"status":return t.kind==="status"&&e.status===t.status;case"compact_summary":return t.kind==="compact_summary"&&e.summary===t.summary;case"context_window_updated":return t.kind==="context_window_updated"&&JSON.stringify(e.usage)===JSON.stringify(t.usage);case"compact_boundary":case"context_cleared":case"interrupted":return!0;case"unknown":return t.kind==="unknown"&&e.json===t.json;case"auto_continue_prompt":return t.kind==="auto_continue_prompt"&&e.scheduleId===t.scheduleId;case"pending_tool_request":return t.kind==="pending_tool_request"&&e.toolRequestId===t.toolRequestId&&e.toolName===t.toolName}}function nye(e,t){return e.kind!==t.kind||e.id!==t.id?!1:e.kind==="single"&&t.kind==="single"?e.index===t.index&&e.isLoading===t.isLoading&&e.localPath===t.localPath&&e.isFirstSystem===t.isFirstSystem&&e.isFirstAccount===t.isFirstAccount&&e.isLatestAskUserQuestion===t.isLatestAskUserQuestion&&e.isLatestExitPlanMode===t.isLatestExitPlanMode&&e.isLatestTodoWrite===t.isLatestTodoWrite&&e.hideResult===t.hideResult&&e.isFinalStatus===t.isFinalStatus&&Id(e.message,t.message):e.kind==="tool-group"&&t.kind==="tool-group"?e.startIndex===t.startIndex&&e.isLoading===t.isLoading&&e.localPath===t.localPath&&e.messages.length===t.messages.length&&e.messages.every((n,r)=>Id(n,t.messages[r])):!1}function rye(e,t){const n=new Map;let r=e.length!==t.byId.size;const i=e.map((s,o)=>{const l=t.byId.get(s.id),c=l&&nye(l,s)?l:s;return n.set(s.id,c),!r&&t.result[o]!==c&&(r=!0),c});return r?{byId:n,result:i}:t}function iye(e){const t=v.useRef({byId:new Map,result:[]}),n=v.useMemo(()=>rye(e,t.current),[e]);return v.useLayoutEffect(()=>{t.current=n}),n.result}const TB=(e,t)=>{},sye=v.memo(function({message:t,index:n,isLoading:r,localPath:i,isFirstSystem:s,isFirstAccount:o,isLatestAskUserQuestion:l,isLatestExitPlanMode:c,isLatestTodoWrite:u,hideResult:p,isFinalStatus:h,onAskUserQuestionSubmit:g,onExitPlanModeConfirm:b,onToolRequestAnswer:_=TB,schedules:x,onAutoContinueAccept:S,onAutoContinueReschedule:C,onAutoContinueCancel:E}){let k=null;if(t.kind==="user_prompt")k=f.jsx(b0e,{content:t.content,attachments:t.attachments,steered:t.steered,autoContinue:t.autoContinue},t.id);else switch(t.kind){case"auto_continue_prompt":{const T=x[t.scheduleId];if(!T){k=f.jsx("div",{className:"rounded border px-3 py-2 text-sm opacity-70",children:"Auto-continue expired"},t.id);break}k=f.jsx(W0e,{schedule:T,onAccept:A=>S(t.scheduleId,A),onReschedule:A=>C(t.scheduleId,A),onCancel:()=>E(t.scheduleId)},t.id);break}case"unknown":k=f.jsx(y0e,{json:t.json},t.id);break;case"system_init":k=s?f.jsx(C0e,{message:t,rawJson:t.debugRaw},t.id):null;break;case"account_info":k=o?f.jsx(k0e,{message:t},t.id):null;break;case"assistant_text":k=f.jsx(_B,{message:t},t.id);break;case"tool":if(t.isError){k=f.jsx(Pb,{message:t,isLoading:r,localPath:i},t.id);break}if(t.toolKind==="ask_user_question"){k=f.jsx(wB,{message:t,onSubmit:g,isLatest:l},t.id);break}if(t.toolKind==="exit_plan_mode"){k=f.jsx(CB,{message:t,onConfirm:b,isLatest:c},t.id);break}if(t.toolKind==="todo_write"){k=u?f.jsx(R0e,{message:t},t.id):null;break}if(t.toolKind==="offer_download"&&t.result){k=f.jsx(T0e,{message:t},t.id);break}k=f.jsx(Pb,{message:t,isLoading:r,localPath:i},t.id);break;case"result":k=p?null:f.jsx(xB,{message:t},t.id);break;case"context_window_updated":k=null;break;case"interrupted":k=f.jsx(A0e,{message:t},t.id);break;case"compact_boundary":k=f.jsx(N0e,{},t.id);break;case"context_cleared":k=f.jsx(M0e,{},t.id);break;case"compact_summary":k=f.jsx(L0e,{message:t},t.id);break;case"status":k=h?f.jsx(j0e,{message:t},t.id):null;break;case"pending_tool_request":k=f.jsx(Y0e,{entry:t,onAnswer:_},t.id);break}return k?f.jsx("div",{id:`msg-${t.id}`,className:"group relative","data-index":n,[Xv]:"",children:k}):null},(e,t)=>e.index===t.index&&e.isLoading===t.isLoading&&e.localPath===t.localPath&&e.isFirstSystem===t.isFirstSystem&&e.isFirstAccount===t.isFirstAccount&&e.isLatestAskUserQuestion===t.isLatestAskUserQuestion&&e.isLatestExitPlanMode===t.isLatestExitPlanMode&&e.isLatestTodoWrite===t.isLatestTodoWrite&&e.hideResult===t.hideResult&&e.isFinalStatus===t.isFinalStatus&&e.onAskUserQuestionSubmit===t.onAskUserQuestionSubmit&&e.onExitPlanModeConfirm===t.onExitPlanModeConfirm&&e.onToolRequestAnswer===t.onToolRequestAnswer&&e.schedules===t.schedules&&e.onAutoContinueAccept===t.onAutoContinueAccept&&e.onAutoContinueReschedule===t.onAutoContinueReschedule&&e.onAutoContinueCancel===t.onAutoContinueCancel&&Id(e.message,t.message)),oye=v.memo(function({id:t,messages:n,isLoading:r,localPath:i,expanded:s,onExpandedChange:o}){return f.jsx("div",{className:"group relative",[Xv]:"",children:f.jsx(B0e,{messages:n,isLoading:r,localPath:i,expanded:s,onExpandedChange:l=>o(t,l)})})},(e,t)=>e.id===t.id&&e.startIndex===t.startIndex&&e.isLoading===t.isLoading&&e.localPath===t.localPath&&e.expanded===t.expanded&&e.onExpandedChange===t.onExpandedChange&&e.messages.length===t.messages.length&&e.messages.every((n,r)=>Id(n,t.messages[r])));function AB(e,{isLoading:t,localPath:n,latestToolIds:r}){const i=Z0e(e,r),s=J0e(e,i),o=[];for(const l of s){if(l.type==="tool-group"){o.push({kind:"tool-group",id:bj(l),startIndex:l.startIndex,messages:l.messages,isLoading:t&&l.messages.some(p=>p.kind==="tool"&&p.result===void 0),localPath:n});continue}const c=i[l.index];if(!c)continue;const u={kind:"single",id:bj(l),message:l.message,index:l.index,isLoading:l.message.kind==="tool"&&l.message.result===void 0&&t,localPath:n,isFirstSystem:c.isFirstSystem,isFirstAccount:c.isFirstAccount,isLatestAskUserQuestion:l.message.id===r.AskUserQuestion,isLatestExitPlanMode:l.message.id===r.ExitPlanMode,isLatestTodoWrite:c.isLatestTodoWrite,hideResult:c.hideResult,isFinalStatus:c.isFinalStatus};c.shouldRender&&o.push(u)}return o}const aye={};function NB(e,t,n,r,i,s,o){const l=n.get(e.runId)??[];return f.jsxs(xn.Fragment,{children:[f.jsx(kB,{run:e,indentDepth:t,localPath:r,onSubagentAskUserQuestionSubmit:i,onSubagentExitPlanModeSubmit:s,onCancelSubagentRun:o}),l.map(c=>NB(c,t+1,n,r,i,s,o))]},e.runId)}const MB=v.memo(function({row:t,toolGroupExpanded:n,onToolGroupExpandedChange:r,onAskUserQuestionSubmit:i,onExitPlanModeConfirm:s,onToolRequestAnswer:o,schedules:l,onAutoContinueAccept:c,onAutoContinueReschedule:u,onAutoContinueCancel:p}){return t.kind==="tool-group"?f.jsx(oye,{id:t.id,startIndex:t.startIndex,messages:t.messages,isLoading:t.isLoading,localPath:t.localPath,expanded:n??!1,onExpandedChange:r}):f.jsx(sye,{message:t.message,index:t.index,isLoading:t.isLoading,localPath:t.localPath,isFirstSystem:t.isFirstSystem,isFirstAccount:t.isFirstAccount,isLatestAskUserQuestion:t.isLatestAskUserQuestion,isLatestExitPlanMode:t.isLatestExitPlanMode,isLatestTodoWrite:t.isLatestTodoWrite,hideResult:t.hideResult,isFinalStatus:t.isFinalStatus,onAskUserQuestionSubmit:i,onExitPlanModeConfirm:s,onToolRequestAnswer:o,schedules:l,onAutoContinueAccept:c,onAutoContinueReschedule:u,onAutoContinueCancel:p})},(e,t)=>{if(e.toolGroupExpanded!==t.toolGroupExpanded||e.onToolGroupExpandedChange!==t.onToolGroupExpandedChange||e.onAskUserQuestionSubmit!==t.onAskUserQuestionSubmit||e.onExitPlanModeConfirm!==t.onExitPlanModeConfirm||e.onToolRequestAnswer!==t.onToolRequestAnswer||e.schedules!==t.schedules||e.onAutoContinueAccept!==t.onAutoContinueAccept||e.onAutoContinueReschedule!==t.onAutoContinueReschedule||e.onAutoContinueCancel!==t.onAutoContinueCancel||e.row.kind!==t.row.kind||e.row.id!==t.row.id)return!1;if(e.row.kind==="tool-group"&&t.row.kind==="tool-group"){const n=e.row,r=t.row;return n.startIndex===r.startIndex&&n.isLoading===r.isLoading&&n.localPath===r.localPath&&n.messages.length===r.messages.length&&n.messages.every((i,s)=>Id(i,r.messages[s]))}return e.row.kind==="single"&&t.row.kind==="single"?e.row.index===t.row.index&&e.row.isLoading===t.row.isLoading&&e.row.localPath===t.row.localPath&&e.row.isFirstSystem===t.row.isFirstSystem&&e.row.isFirstAccount===t.row.isFirstAccount&&e.row.isLatestAskUserQuestion===t.row.isLatestAskUserQuestion&&e.row.isLatestExitPlanMode===t.row.isLatestExitPlanMode&&e.row.isLatestTodoWrite===t.row.isLatestTodoWrite&&e.row.hideResult===t.row.hideResult&&e.row.isFinalStatus===t.row.isFinalStatus&&Id(e.row.message,t.row.message):!1}),LB={},lye=(e,t)=>{},cye=(e,t)=>{},uye=e=>{};function dye({messages:e,isLoading:t,localPath:n,latestToolIds:r,onOpenLocalLink:i,onAskUserQuestionSubmit:s,onExitPlanModeConfirm:o,onToolRequestAnswer:l=TB,schedules:c=LB,onAutoContinueAccept:u=lye,onAutoContinueReschedule:p=cye,onAutoContinueCancel:h=uye,onTunnelAccept:g,onTunnelStop:b,onTunnelRetry:_,subagentRuns:x=aye,onSubagentAskUserQuestionSubmit:S,onSubagentExitPlanModeSubmit:C,onCancelSubagentRun:E}){const[k,T]=v.useState({}),A=v.useMemo(()=>AB(e,{isLoading:t,localPath:n,latestToolIds:r}),[t,r,n,e]),{runsByUserMessageId:N,childrenByParentRunId:M}=v.useMemo(()=>{const U=new Map,I=new Map;for(const z of Object.values(x))if(z.parentRunId===null){const O=U.get(z.parentUserMessageId)??[];O.push(z),U.set(z.parentUserMessageId,O)}else{const O=I.get(z.parentRunId)??[];O.push(z),I.set(z.parentRunId,O)}const P=(z,O)=>z.startedAt-O.startedAt||z.runId.localeCompare(O.runId);for(const z of U.values())z.sort(P);for(const z of I.values())z.sort(P);return{runsByUserMessageId:U,childrenByParentRunId:I}},[x]),j=v.useCallback((U,I)=>{T(P=>P[U]===I?P:{...P,[U]:I})},[]);return f.jsx(I8,{onOpenLocalLink:i,children:A.map(U=>{const I=U.kind==="single"&&U.message.kind==="user_prompt"?U.message.id:null,P=I?N.get(I)??[]:[];return f.jsxs("div",{className:"mx-auto max-w-[800px] pb-5",children:[f.jsx(MB,{row:U,toolGroupExpanded:U.kind==="tool-group"?k[U.id]??!1:void 0,onToolGroupExpandedChange:j,onAskUserQuestionSubmit:s,onExitPlanModeConfirm:o,onToolRequestAnswer:l,schedules:c,onAutoContinueAccept:u,onAutoContinueReschedule:p,onAutoContinueCancel:h}),P.map(z=>NB(z,0,M,n??"",S,C,E))]},U.id)})})}v.memo(dye);function fye(e=1e3){const[t,n]=v.useState(()=>Date.now()),r=v.useRef(e);return v.useLayoutEffect(()=>{r.current=e}),v.useEffect(()=>{const i=window.setInterval(()=>{n(Date.now())},r.current);return()=>window.clearInterval(i)},[]),t}function hye(e){switch(e.kind){case"bash_shell":return e.command;case"terminal_pty":return`PTY: ${e.cwd}`;case"codex_session":return"Codex session";case"draining_stream":return"Draining stream"}}function pye(e){switch(e.kind){case"bash_shell":return"bash";case"terminal_pty":return"terminal";case"codex_session":return"codex";case"draining_stream":return"stream"}}function mye(e){return"chatId"in e?e.chatId??null:null}function gye(e){return e.kind==="bash_shell"?e.status==="stopping"?"stopping":"running":"active"}function vye(e){return(e.lastOutput??"").split(`
|
|
2598
2598
|
`).slice(-12)}function bye(){return typeof window>"u"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches}const IB=v.memo(function({task:t,index:n,now:r,isFocused:i,isExpanded:s,isDimmed:o,graceMs:l,variant:c="desktop",onFocus:u,onToggleExpand:p,onStopConfirmed:h,onForceKill:g,onConfirmStart:b,onConfirmEnd:_,stopButtonRef:x,_testInitialPhase:S}){const C=v.useRef(null),E=v.useRef(null),k=x??E,T=v.useRef(null),[A,N]=v.useState(()=>S==="confirm"?{phase:"confirm"}:S==="stopping"?{phase:"stopping",startedAt:0}:S==="forceAvailable"?{phase:"forceAvailable"}:{phase:"idle"}),M=hye(t),j=pye(t),U=mye(t),I=gye(t),P=A.phase==="stopping"||A.phase==="forceAvailable"?null:nQ(t.startedAt,r),z=rQ(t.startedAt),O=vye(t),$=bye(),V=$||n>=8?0:n*24,F=$?{}:{animationName:"bg-task-row-enter",animationDuration:"180ms",animationTimingFunction:"cubic-bezier(0.25, 0.46, 0.45, 0.94)",animationFillMode:"both",animationDelay:`${V}ms`};v.useEffect(()=>{if(A.phase!=="stopping")return;const oe=setTimeout(()=>{N({phase:"forceAvailable"})},l);return()=>clearTimeout(oe)},[A.phase,l]),v.useEffect(()=>{var oe;A.phase==="confirm"&&((oe=T.current)==null||oe.focus())},[A.phase]);const H=v.useCallback(()=>{N({phase:"confirm"}),b(t.id)},[t.id,b]),W=v.useCallback(()=>{var oe;N({phase:"idle"}),_(),(oe=k.current)==null||oe.focus()},[_]),Z=v.useCallback(()=>{N({phase:"stopping",startedAt:Date.now()}),_(),h(t.id)},[t.id,_,h]),D=v.useCallback(()=>{g(t.id)},[t.id,g]),G=v.useCallback(oe=>{if(oe.key==="Escape"&&A.phase==="confirm"){oe.preventDefault(),oe.stopPropagation(),W();return}oe.key==="Enter"&&(oe.preventDefault(),p(t.id)),(oe.metaKey||oe.ctrlKey)&&oe.key==="."&&(oe.preventDefault(),A.phase==="idle"?H():A.phase==="confirm"?Z():A.phase==="forceAvailable"&&D())},[t.id,p,A.phase,H,Z,W,D]),ee=v.useCallback(oe=>{oe.stopPropagation(),p(t.id)},[t.id,p]),B=$?{}:{animationName:"bg-task-confirm-slide-in",animationDuration:"180ms",animationTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)",animationFillMode:"both"},le=()=>A.phase==="idle"?c==="mobile"?f.jsxs("button",{ref:k,type:"button","aria-label":"Stop task",onClick:oe=>{oe.stopPropagation(),H()},disabled:I==="stopping",className:he("w-full flex items-center justify-center gap-1.5 px-3 py-2 rounded-md","text-sm text-muted-foreground hover:text-destructive-text border border-border/60 hover:border-destructive-text/40","focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring","disabled:opacity-40 disabled:pointer-events-none","transition-colors"),"data-mobile-stop-line":!0,children:[f.jsx(gN,{className:"w-3 h-3 fill-current","aria-hidden":!0}),"Stop"]}):f.jsxs(Xr,{children:[f.jsx(Qr,{asChild:!0,children:f.jsx("button",{ref:k,type:"button","aria-label":"Stop task",onClick:oe=>{oe.stopPropagation(),H()},disabled:I==="stopping",className:he("flex-shrink-0 inline-flex items-center justify-center w-5 h-5 rounded-sm","text-muted-foreground hover:text-destructive-text","focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring","disabled:opacity-40 disabled:pointer-events-none","transition-colors"),children:f.jsx(gN,{className:"w-3 h-3 fill-current","aria-hidden":!0})})}),f.jsx(Br,{side:"top",children:"Stop (⌘.)"})]}):A.phase==="confirm"?c==="mobile"?f.jsxs("span",{className:"grid grid-cols-2 gap-2 w-full",style:B,"data-confirm-area":!0,"data-mobile-stop-line":!0,children:[f.jsx("button",{ref:T,type:"button","aria-label":"Confirm stop",onClick:oe=>{oe.stopPropagation(),Z()},className:he("flex items-center justify-center rounded-md px-3 py-2 text-sm font-medium border","focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring","transition-colors"),style:{color:"var(--destructive-text)",borderColor:"var(--destructive-text)"},children:"Confirm stop?"}),f.jsx("button",{type:"button","aria-label":"Cancel stop",onClick:oe=>{oe.stopPropagation(),W()},className:he("flex items-center justify-center rounded-md px-3 py-2 text-sm","text-muted-foreground hover:text-foreground","border border-border/60 hover:border-border","focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring","transition-colors"),children:"Cancel"})]}):f.jsxs("span",{className:"flex items-center gap-1.5 flex-shrink-0",style:B,"data-confirm-area":!0,children:[f.jsx("button",{ref:T,type:"button","aria-label":"Confirm stop",onClick:oe=>{oe.stopPropagation(),Z()},className:he("inline-flex items-center rounded-sm px-1.5 py-0.5 text-xs font-medium","focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring","transition-colors"),style:{color:"var(--destructive-text)"},children:"Confirm stop?"}),f.jsx("button",{type:"button","aria-label":"Cancel stop",onClick:oe=>{oe.stopPropagation(),W()},className:he("inline-flex items-center rounded-sm px-1.5 py-0.5 text-xs","text-muted-foreground hover:text-foreground","border border-border/60 hover:border-border","focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring","transition-colors"),children:"Cancel"})]}):A.phase==="forceAvailable"?c==="mobile"?f.jsx("button",{type:"button","aria-label":"Force kill task",onClick:oe=>{oe.stopPropagation(),D()},className:he("w-full flex items-center justify-center rounded-md px-3 py-2 text-sm font-medium border","focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring","transition-colors"),style:{color:"var(--destructive-text)",borderColor:"var(--destructive-text)"},"data-mobile-stop-line":!0,children:"Force kill"}):f.jsxs(Xr,{children:[f.jsx(Qr,{asChild:!0,children:f.jsx("button",{type:"button","aria-label":"Force kill task",onClick:oe=>{oe.stopPropagation(),D()},className:he("flex-shrink-0 inline-flex items-center rounded-sm px-1.5 py-0.5 text-xs font-medium","focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring","transition-colors"),style:{color:"var(--destructive-text)"},children:"Force kill"})}),f.jsx(Br,{side:"top",children:"Send SIGKILL immediately"})]}):null;return c==="mobile"?f.jsxs("div",{ref:C,role:"option","aria-selected":i,tabIndex:i?0:-1,"data-task-id":t.id,"data-row-enter":!0,"data-mobile-row":!0,onFocus:()=>u(t.id),onKeyDown:G,className:he("group relative flex flex-col px-3 py-3 rounded-md transition-all cursor-default gap-1.5","hover:bg-secondary focus-visible:bg-secondary","focus-visible:outline-2 focus-visible:outline-offset-0 focus-visible:outline-ring",i&&"bg-secondary"),style:{...F,...o?{opacity:.6,pointerEvents:"none"}:{}},children:[f.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[f.jsx("span",{className:"inline-block w-[6px] h-[6px] rounded-full flex-shrink-0 mt-px",style:{backgroundColor:A.phase==="stopping"||I==="stopping"?"var(--muted-foreground)":"var(--warning)"},"aria-hidden":!0}),f.jsx("span",{className:"flex-1 min-w-0 truncate font-mono text-sm font-semibold leading-snug",children:M}),P!==null?f.jsx("span",{className:"flex-shrink-0 font-mono text-[13px] font-medium tabular-nums text-muted-foreground leading-snug",children:P}):f.jsx("span",{className:"flex-shrink-0 font-mono text-[13px] italic text-muted-foreground leading-snug",children:"stopping…"})]}),f.jsxs("div",{className:"flex items-center gap-1.5 pl-[14px] min-w-0 flex-wrap",children:[f.jsx("span",{className:"text-xs text-muted-foreground font-sans leading-none flex-shrink-0",children:j}),U&&f.jsxs(f.Fragment,{children:[f.jsx("span",{className:"text-xs text-muted-foreground leading-none flex-shrink-0","aria-hidden":!0,children:"·"}),f.jsx("a",{href:`/chat/${U}`,className:"text-xs text-muted-foreground hover:text-foreground underline underline-offset-2 leading-none truncate max-w-[160px] focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring rounded-sm",onClick:oe=>oe.stopPropagation(),children:"chat"})]}),f.jsx("span",{className:"text-xs text-muted-foreground leading-none flex-shrink-0","aria-hidden":!0,children:"·"}),f.jsxs("span",{className:"text-xs text-muted-foreground font-sans tabular-nums leading-none flex-shrink-0",children:["started ",z]}),f.jsx("span",{className:"text-xs font-sans leading-none flex-shrink-0",style:A.phase==="stopping"||A.phase==="forceAvailable"?{color:"var(--muted-foreground)"}:I!=="stopping"?{color:"var(--warning)"}:void 0,children:A.phase==="stopping"||A.phase==="forceAvailable"||I==="stopping"?"stopping":"running"})]}),t.kind==="bash_shell"&&M.length>40&&f.jsxs("details",{className:"pl-[14px]","data-full-command":!0,children:[f.jsx("summary",{className:"text-xs text-muted-foreground cursor-pointer select-none list-none underline underline-offset-2",children:"full command"}),f.jsx("pre",{className:"mt-1 text-xs font-mono text-muted-foreground whitespace-pre-wrap break-all leading-relaxed",children:M})]}),f.jsx("div",{className:"pl-[14px]","data-mobile-stop-line-wrapper":!0,children:le()}),s&&f.jsx("pre",{className:"mt-1 pl-[14px] text-xs font-mono leading-[1.55] text-muted-foreground max-h-[240px] overflow-y-auto whitespace-pre-wrap break-all","aria-label":"Last output",children:O.join(`
|
|
2599
2599
|
`)||"(no output)"})]}):f.jsxs("div",{ref:C,role:"option","aria-selected":i,tabIndex:i?0:-1,"data-task-id":t.id,"data-row-enter":!0,onFocus:()=>u(t.id),onKeyDown:G,className:he("group relative flex flex-col px-3 py-2.5 rounded-md transition-all cursor-default","hover:bg-secondary focus-visible:bg-secondary","focus-visible:outline-2 focus-visible:outline-offset-0 focus-visible:outline-ring",i&&"bg-secondary"),style:{...F,...o?{opacity:.6,pointerEvents:"none"}:{}},children:[f.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[f.jsx("span",{className:"inline-block w-[6px] h-[6px] rounded-full flex-shrink-0 mt-px",style:{backgroundColor:A.phase==="stopping"||I==="stopping"?"var(--muted-foreground)":"var(--warning)"},"aria-hidden":!0}),f.jsx("span",{className:"flex-1 min-w-0 truncate font-mono text-sm font-semibold leading-snug",children:M}),P!==null?f.jsx("span",{className:"flex-shrink-0 font-mono text-[13px] font-medium tabular-nums text-muted-foreground leading-snug",children:P}):f.jsx("span",{className:"flex-shrink-0 font-mono text-[13px] italic text-muted-foreground leading-snug",children:(A.phase==="forceAvailable","stopping…")}),f.jsxs(Xr,{children:[f.jsx(Qr,{asChild:!0,children:f.jsx("button",{type:"button","aria-label":s?"Collapse output":"Expand output",onClick:ee,className:he("flex-shrink-0 inline-flex items-center justify-center w-5 h-5 rounded-sm","text-muted-foreground hover:text-foreground","focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring","transition-transform duration-150",s&&"rotate-90"),children:f.jsx(To,{className:"w-3.5 h-3.5","aria-hidden":!0})})}),f.jsxs(Br,{side:"top",children:[s?"Collapse output":"Expand output"," (Enter)"]})]})]}),f.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5 pl-[14px] min-w-0",children:[f.jsx("span",{className:"text-xs text-muted-foreground font-sans leading-none flex-shrink-0",children:j}),U&&f.jsxs(f.Fragment,{children:[f.jsx("span",{className:"text-xs text-muted-foreground leading-none flex-shrink-0","aria-hidden":!0,children:"·"}),f.jsx("a",{href:`/chat/${U}`,className:"text-xs text-muted-foreground hover:text-foreground underline underline-offset-2 leading-none truncate max-w-[200px] focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring rounded-sm",onClick:oe=>oe.stopPropagation(),children:"chat"})]}),f.jsx("span",{className:"text-xs text-muted-foreground leading-none flex-shrink-0","aria-hidden":!0,children:"·"}),f.jsxs("span",{className:"text-xs text-muted-foreground font-sans tabular-nums leading-none flex-shrink-0",children:["started ",z]}),f.jsx("span",{className:"text-xs font-sans leading-none flex-shrink-0",style:A.phase==="stopping"||A.phase==="forceAvailable"?{color:"var(--muted-foreground)"}:I!=="stopping"?{color:"var(--warning)"}:void 0,children:A.phase==="stopping"||A.phase==="forceAvailable"||I==="stopping"?"stopping":"running"}),f.jsx("span",{className:"flex-1"}),le()]}),s&&f.jsx("pre",{className:"mt-2 pl-[14px] text-xs font-mono leading-[1.55] text-muted-foreground max-h-[240px] overflow-y-auto whitespace-pre-wrap break-all","aria-label":"Last output",children:O.join(`
|
|
2600
2600
|
`)||"(no output)"})]})});function yye({orphans:e,now:t,variant:n,onStop:r,graceMs:i}){const[s,o]=v.useState("idle"),[l,c]=v.useState(null),[u,p]=v.useState(null),h=v.useId(),g=v.useCallback(()=>{o("confirm")},[]),b=v.useCallback(()=>{o("idle")},[]),_=v.useCallback(()=>{o("idle");for(const E of e)r(E.id,!1)},[e,r]),x=v.useCallback(E=>{c(E)},[]),S=v.useCallback(()=>{c(null)},[]),C=v.useCallback(E=>{p(k=>k===E?null:E)},[]);return e.length===0?null:f.jsxs("div",{className:"mb-3","data-orphan-section":!0,children:[f.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 mb-1",children:[f.jsx("span",{id:h,className:"text-xs text-muted-foreground font-sans","data-orphan-header":!0,children:"Found from previous session"}),s==="idle"?f.jsx("button",{type:"button",onClick:g,className:he("text-xs text-muted-foreground hover:text-foreground","focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring rounded-sm","transition-colors"),"data-kill-all-btn":!0,children:"Kill all"}):f.jsxs("span",{className:"flex items-center gap-2","data-kill-all-confirm":!0,children:[f.jsxs("button",{type:"button",onClick:_,className:he("text-xs font-medium","focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring rounded-sm","transition-colors"),style:{color:"var(--destructive-text)"},children:["Kill ",e.length," orphan",e.length!==1?"s":"","?"]}),f.jsx("button",{type:"button",onClick:b,className:he("text-xs text-muted-foreground hover:text-foreground","focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring rounded-sm","transition-colors"),children:"Cancel"})]})]}),f.jsx("div",{role:"listbox","aria-labelledby":h,"aria-label":"Orphan tasks from previous session",className:"flex flex-col gap-0.5",style:{opacity:.85},children:e.map((E,k)=>f.jsx(IB,{task:E,index:k,now:t,isFocused:!1,isExpanded:E.id===u,isDimmed:l!==null&&l!==E.id,graceMs:i,variant:n,onFocus:()=>{},onToggleExpand:C,onStopConfirmed:T=>r(T,!1),onForceKill:T=>r(T,!0),onConfirmStart:x,onConfirmEnd:S},E.id))})]})}function _ye({tasks:e,onStop:t,graceMs:n=3e3,variant:r="desktop"}){var U;const i=fye(1e3),s=v.useRef(null),o=v.useId(),[l,c]=v.useState(null),[u,p]=v.useState(null),[h,g]=v.useState(null),b=e.filter(I=>I.kind==="bash_shell"&&I.orphan===!0),_=e.filter(I=>!(I.kind==="bash_shell"&&I.orphan===!0)),S=_.findIndex(I=>I.id===l)>=0?l:((U=_[0])==null?void 0:U.id)??null,C=v.useCallback(I=>{c(I)},[]),E=v.useCallback(I=>{p(P=>P===I?null:I)},[]),k=v.useCallback(I=>{t(I,!1)},[t]),T=v.useCallback(I=>{t(I,!0)},[t]),A=v.useCallback(I=>{g(I)},[]),N=v.useCallback(()=>{g(null)},[]),M=v.useCallback(I=>{var z,O,$,V;if(_.length===0)return;const P=_.findIndex(F=>F.id===S);if(I.key==="ArrowDown"){I.preventDefault();const F=Math.min(P+1,_.length-1),H=(z=_[F])==null?void 0:z.id;if(H){c(H);const W=(O=s.current)==null?void 0:O.querySelector(`[data-task-id="${H}"]`);W==null||W.focus()}}else if(I.key==="ArrowUp"){I.preventDefault();const F=Math.max(P-1,0),H=($=_[F])==null?void 0:$.id;if(H){c(H);const W=(V=s.current)==null?void 0:V.querySelector(`[data-task-id="${H}"]`);W==null||W.focus()}}},[_,S]),j=e.length;return f.jsx(v0,{children:f.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[f.jsxs("div",{className:"flex flex-row items-center justify-between gap-4 shrink-0 p-4 border-b border-border",children:[f.jsx("h2",{id:o,className:"text-[18px] font-medium leading-none",children:"Background tasks"}),j>0&&f.jsxs("span",{className:"text-xs text-muted-foreground font-sans tabular-nums flex-shrink-0 mr-6",children:[j," running"]})]}),f.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 pb-4 pt-3.5",children:[b.length>0&&f.jsx(yye,{orphans:b,now:i,variant:r,onStop:t,graceMs:n}),e.length===0?f.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"No background tasks. Anything an agent leaves running here will appear so you can stop it."}):_.length===0?null:f.jsx("div",{ref:s,role:"listbox","aria-label":"Background tasks","aria-labelledby":o,onKeyDown:M,className:"flex flex-col gap-0.5",children:_.map((I,P)=>f.jsx(IB,{task:I,index:P,now:i,isFocused:I.id===S,isExpanded:I.id===u,isDimmed:h!==null&&h!==I.id,graceMs:n,variant:r,onFocus:C,onToggleExpand:E,onStopConfirmed:k,onForceKill:T,onConfirmStart:A,onConfirmEnd:N},I.id))})]})]})})}function xye({open:e,onOpenChange:t,tasks:n,onStop:r,graceMs:i,variant:s="desktop"}){const o=v.useId(),l=s==="mobile"?"max-w-none w-full rounded-t-xl rounded-b-none left-0 right-0 bottom-0 top-auto translate-x-0 translate-y-0 max-h-[80vh]":"";return f.jsx(Ao,{open:e,onOpenChange:t,children:f.jsxs(Ys,{className:he("w-[min(720px,calc(100vw-2rem))] p-0",l,s==="mobile"&&"data-[state=open]:slide-in-from-bottom data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-left-0 data-[state=closed]:slide-out-to-left-0 data-[state=open]:slide-in-from-top-[0%] data-[state=closed]:slide-out-to-top-[0%]"),size:"lg","aria-labelledby":o,"data-variant":s,children:[f.jsx(No,{id:o,className:"sr-only",children:"Background tasks"}),f.jsx(_ye,{tasks:n,onStop:r,graceMs:i,variant:s})]})})}function Sye({open:e,onOpenChange:t,socket:n,variant:r}){const i=Vs(c=>c.tasks),s=i4(),o=r??(s?"mobile":"desktop"),l=v.useCallback((c,u)=>{if(!n)return;const p={type:"bg-tasks.stop",id:c,force:u};n.command(p).catch(()=>{})},[n]);return f.jsx(xye,{open:e,onOpenChange:t,tasks:i,onStop:l,variant:o})}const wye=`
|
|
@@ -2626,7 +2626,7 @@ XID_Start XIDS`.split(/\s/).map(e=>[O0(e),e])),Goe=new Map([["s",wr(383)],[wr(38
|
|
|
2626
2626
|
}
|
|
2627
2627
|
`;if(typeof document<"u"){const e=document.createElement("style");e.textContent=wye,document.head.appendChild(e)}const Cye=4,yj=80;function kye(e){return e.length<=yj?e:`${e.slice(0,yj-1).trimEnd()}…`}function Eye({items:e,activeIndex:t,loading:n,onSelect:r,onHoverIndex:i}){const s=v.useRef(null);return v.useEffect(()=>{var l;const o=(l=s.current)==null?void 0:l.children.item(t);o==null||o.scrollIntoView({block:"nearest"})},[t]),e.length===0&&n?f.jsx("ul",{"aria-busy":"true","aria-label":"Loading slash commands",className:"absolute bottom-full left-0 mb-2 w-full max-w-md md:max-w-xl rounded-md border border-border bg-popover shadow-md overflow-hidden",children:Array.from({length:Cye}).map((o,l)=>f.jsxs("li",{className:"flex flex-col gap-1 px-3 py-1.5 sm:flex-row sm:items-center sm:gap-3","data-testid":"slash-picker-skeleton-row",children:[f.jsx("span",{className:"h-3 w-28 rounded bg-muted animate-pulse"}),f.jsx("span",{className:"hidden h-3 w-16 rounded bg-muted/70 animate-pulse sm:inline-block"}),f.jsx("span",{className:"h-3 w-40 max-w-full rounded bg-muted/60 animate-pulse sm:ml-auto"})]},l))}):e.length===0?f.jsx("div",{className:"absolute bottom-full left-0 mb-2 w-full max-w-md md:max-w-xl rounded-md border border-border bg-popover p-2 text-sm text-muted-foreground shadow-md",children:"No matching commands"}):f.jsx("ul",{ref:s,role:"listbox",className:"absolute bottom-full left-0 mb-2 w-full max-w-md md:max-w-xl max-h-64 overflow-auto rounded-md border border-border bg-popover shadow-md",children:e.map((o,l)=>f.jsxs("li",{role:"option","aria-selected":l===t,onMouseDown:c=>{c.preventDefault(),r(o)},onMouseEnter:()=>i(l),className:he("flex flex-col gap-0.5 px-3 py-1.5 cursor-pointer text-sm sm:flex-row sm:items-center sm:gap-3",l===t&&"bg-accent text-accent-foreground"),children:[f.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[f.jsxs("span",{className:"font-mono break-all sm:whitespace-nowrap sm:break-normal",children:["/",o.name]}),o.argumentHint?f.jsx("span",{className:"shrink-0 font-mono text-xs text-muted-foreground whitespace-nowrap",children:o.argumentHint}):null]}),o.description?f.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-muted-foreground sm:text-right",children:kye(o.description)}):null]},o.name))})}const Rye=4;function Tye({items:e,activeIndex:t,loading:n,onSelect:r,onHoverIndex:i}){const s=v.useRef(null);return v.useEffect(()=>{var l;const o=(l=s.current)==null?void 0:l.children.item(t);o==null||o.scrollIntoView({block:"nearest"})},[t]),e.length===0&&n?f.jsx("ul",{"aria-busy":"true","aria-label":"Loading file suggestions",className:"absolute bottom-full left-0 mb-2 w-full max-w-md md:max-w-xl rounded-md border border-border bg-popover shadow-md overflow-hidden",children:Array.from({length:Rye}).map((o,l)=>f.jsxs("li",{className:"flex items-center gap-2 px-3 py-1.5","data-testid":"mention-picker-skeleton-row",children:[f.jsx("span",{className:"h-3.5 w-3.5 rounded bg-muted animate-pulse"}),f.jsx("span",{className:"h-3 w-40 max-w-full rounded bg-muted animate-pulse"})]},l))}):e.length===0?f.jsx("div",{className:"absolute bottom-full left-0 mb-2 w-full max-w-md md:max-w-xl rounded-md border border-border bg-popover p-2 text-sm text-muted-foreground shadow-md",children:"No matching files"}):f.jsx("ul",{ref:s,role:"listbox",className:"absolute bottom-full left-0 mb-2 w-full max-w-md md:max-w-xl max-h-64 overflow-auto rounded-md border border-border bg-popover shadow-md",children:e.map((o,l)=>{const c=o.kind==="agent",u=o.kind==="path"?o.path:null,p=(u==null?void 0:u.kind)==="dir"?WP:jC;return f.jsxs("li",{role:"option","aria-selected":l===t,onMouseDown:h=>{h.preventDefault(),r(o)},onMouseEnter:()=>i(l),className:he("flex items-center gap-2 px-3 py-1.5 cursor-pointer text-sm",l===t&&"bg-accent text-accent-foreground"),children:[f.jsx(d9,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),c?f.jsxs(f.Fragment,{children:[f.jsx(LC,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),f.jsxs("span",{className:"font-mono truncate",children:["agent/",o.subagent.name]}),o.subagent.description?f.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",children:o.subagent.description}):null]}):u?f.jsxs(f.Fragment,{children:[f.jsx(p,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),f.jsx("span",{className:"font-mono truncate",children:u.path})]}):null]},c?`agent:${o.subagent.id}`:`path:${u==null?void 0:u.kind}:${u==null?void 0:u.path}`)})})}const Aye=/^\/(\S*)$/;function Nye(e){const{command:t,value:n,caret:r}=e,i=n.slice(0,r),s=n.slice(r),o=/^\/(\S*)$/.exec(i);if(!o)return{value:n,caret:r};const l=o[0].length,c=i.slice(0,i.length-l),u=t.argumentHint?`/${t.name} `:`/${t.name}`,p=`${c}${u}${s}`,h=c.length+u.length;return{value:p,caret:h}}function Mye(e,t){if(t<=0)return{open:!1,query:""};const n=e.slice(0,t),r=Aye.exec(n);return r?{open:!0,query:r[1]??""}:{open:!1,query:""}}function Lye(e,t){const n=(o,l)=>o.name.localeCompare(l.name);if(t==="")return[...e].sort(n);const r=t.toLowerCase(),i=[],s=[];for(const o of e){const l=o.name.toLowerCase();l.startsWith(r)?i.push(o):l.includes(r)&&s.push(o)}return[...i.sort(n),...s.sort(n)]}const tv={open:!1,query:"",tokenStart:-1};function Iye(e,t){if(t<=0)return tv;const n=e.slice(0,t);let r=-1;for(let s=n.length-1;s>=0;s--){const o=n[s];if(o==="@"){r=s;break}if(o===" "||o===`
|
|
2628
2628
|
`||o===" ")return tv}if(r===-1)return tv;const i=r===0?"":n[r-1];return i!==""&&i!==" "&&i!==`
|
|
2629
|
-
`&&i!==" "?tv:{open:!0,query:n.slice(r+1),tokenStart:r}}function _j(e){const t=e.value.slice(0,e.tokenStart),n=e.value.slice(e.caret),r=e.mention.kind==="agent"?`@agent/${e.mention.name}`:`@${e.mention.path}`,i=`${t}${r}${n}`,s=t.length+r.length;return{value:i,caret:s}}const jye=120;async function Dye(e){const t=new URLSearchParams({query:e.query});try{const n=await fetch(`/api/projects/${e.projectId}/paths?${t.toString()}`,{signal:e.signal});return n.ok?(await n.json()).paths??[]:[]}catch{return[]}}function Pye(e){const[t,n]=v.useState({items:[],loading:!1,error:null}),r=v.useRef(null),i=v.useRef(null);return v.useEffect(()=>{var o;if(!e.enabled||!e.projectId){n({items:[],loading:!1,error:null});return}r.current&&clearTimeout(r.current),(o=i.current)==null||o.abort(),n(l=>({...l,loading:!0,error:null}));const s=new AbortController;return i.current=s,r.current=setTimeout(async()=>{const l=await Dye({projectId:e.projectId,query:e.query,signal:s.signal});s.signal.aborted||n({items:l,loading:!1,error:null})},jye),()=>{r.current&&clearTimeout(r.current),s.abort()}},[e.enabled,e.projectId,e.query]),t}const Oye=[];function zye(e,t){const n=t.toLowerCase();if(n&&!("agent/".startsWith(n)||n.startsWith("agent/")))return[];const r=n.startsWith("agent/")?n.slice(6):"";return e.filter(i=>i.name.toLowerCase().includes(r)).sort((i,s)=>i.name.localeCompare(s.name)).map(i=>({kind:"agent",subagent:i}))}function Bye(e){const t=Us(n=>{var r;return((r=n.settings)==null?void 0:r.subagents)??Oye});return v.useMemo(()=>({items:e.enabled?zye(t,e.query):[]}),[e.enabled,e.query,t])}const xj=[];function Fye(e,t){return t?e.byChatId[t]??xj:xj}function $ye(e,t){return t?e.loadingByChatId[t]??!1:!1}function Hye(e){return zE(t=>Fye(t,e))}function Uye(e){return zE(t=>$ye(t,e))}const jB=v.forwardRef(({className:e,children:t,...n},r)=>f.jsx("div",{ref:r,className:he("relative overflow-y-auto overscroll-contain touch-pan-y scrollbar-hide",e),style:{WebkitOverflowScrolling:"touch"},...n,children:t}));jB.displayName="ScrollArea";function Vye(){const[e,t]=v.useState(()=>{if(typeof window>"u")return!1;const n=navigator.standalone===!0,r=window.matchMedia("(display-mode: standalone)").matches;return n||r});return v.useEffect(()=>{const n=window.matchMedia("(display-mode: standalone)"),r=i=>{t(i.matches||navigator.standalone===!0)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}function Wye({className:e,...t}){return f.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",className:he("shrink-0",e),...t,children:f.jsx("path",{d:"M17.3041 3.541h-3.6718l6.696 16.918H24Zm-10.6082 0L0 20.459h3.7442l1.3693-3.5527h7.0052l1.3693 3.5528h3.7442L10.5363 3.5409Zm-.3712 10.2232 2.2914-5.9456 2.2914 5.9456Z"})})}function Gye({className:e,...t}){return f.jsx("svg",{viewBox:"0 0 158.7128 157.296",fill:"currentColor","aria-hidden":"true",className:he("shrink-0",e),...t,children:f.jsx("path",{d:"M60.8734 57.2556V42.3124c0-1.2586.4722-2.2029 1.5728-2.8314l30.0443-17.3023c4.0899-2.3593 8.9662-3.4599 13.9988-3.4599 18.8759 0 30.8307 14.6289 30.8307 30.2006 0 1.1007 0 2.3593-.158 3.6178l-31.1446-18.2467c-1.8872-1.1006-3.7754-1.1006-5.6629 0L60.8734 57.2556Zm70.1542 58.2005V79.7487c0-2.2028-.9446-3.7756-2.8318-4.8763l-39.481-22.9651 12.8982-7.3934c1.1007-.6285 2.0453-.6285 3.1458 0l30.0441 17.3024c8.6523 5.0341 14.4708 15.7296 14.4708 26.1107 0 11.9539-7.0769 22.965-18.2461 27.527ZM51.593 83.9964l-12.8982-7.5497c-1.1007-.6285-1.5728-1.5728-1.5728-2.8314V39.0105c0-16.8303 12.8982-29.5722 30.3585-29.5722 6.607 0 12.7403 2.2029 17.9324 6.1349l-30.987 17.9324c-1.8871 1.1007-2.8314 2.6735-2.8314 4.8764v45.6159ZM79.3562 100.0403 60.8733 89.6592V67.6383l18.4829-10.3811 18.4812 10.3811v22.0209l-18.4812 10.3811Zm11.8757 47.8188c-6.607 0-12.7403-2.2031-17.9324-6.1344l30.9866-17.9333c1.8872-1.1005 2.8318-2.6728 2.8318-4.8759v-45.616l13.0564 7.5498c1.1005.6285 1.5723 1.5728 1.5723 2.8314v34.6051c0 16.8297-13.0564 29.5723-30.5147 29.5723ZM53.9522 112.7822 23.9079 95.4798c-8.652-5.0343-14.471-15.7296-14.471-26.1107 0-12.1119 7.2356-22.9652 18.403-27.5272v35.8634c0 2.2028.9443 3.7756 2.8314 4.8763l39.3248 22.8068-12.8982 7.3938c-1.1007.6287-2.045.6287-3.1456 0ZM52.2229 138.5791c-17.7745 0-30.8306-13.3713-30.8306-29.8871 0-1.2585.1578-2.5169.3143-3.7754l30.987 17.9323c1.8871 1.1005 3.7757 1.1005 5.6628 0l39.4811-22.807v14.9435c0 1.2585-.4721 2.2021-1.5728 2.8308l-30.0443 17.3025c-4.0898 2.359-8.9662 3.4605-13.9989 3.4605h.0014ZM91.2319 157.296c19.0327 0 34.9188-13.5272 38.5383-31.4594 17.6164-4.562 28.9425-21.0779 28.9425-37.908 0-11.0112-4.719-21.7066-13.2133-29.4143.7867-3.3035 1.2595-6.607 1.2595-9.909 0-22.4929-18.2471-39.3247-39.3251-39.3247-4.2461 0-8.3363.6285-12.4262 2.045-7.0792-6.9213-16.8318-11.3254-27.5271-11.3254-19.0331 0-34.9191 13.5268-38.5384 31.4591C11.3255 36.0212 0 52.5373 0 69.3675c0 11.0112 4.7184 21.7065 13.2125 29.4142-.7865 3.3035-1.2586 6.6067-1.2586 9.9092 0 22.4923 18.2466 39.3241 39.3248 39.3241 4.2462 0 8.3362-.6277 12.426-2.0441 7.0776 6.921 16.8302 11.3251 27.5271 11.3251Z"})})}const Sj={claude:Wye,codex:Gye};function na({onClick:e,selected:t,icon:n,label:r,description:i,disabled:s}){return f.jsxs("button",{onClick:e,disabled:s,className:he("w-full flex items-center gap-2 p-2 border border-border/0 rounded-lg text-left transition-opacity",t?"bg-muted border-border":"hover:opacity-60",s&&"opacity-40 cursor-not-allowed"),children:[n,f.jsxs("div",{children:[f.jsx("div",{className:"text-sm font-medium",children:r}),i?f.jsx("div",{className:"text-xs text-muted-foreground",children:i}):null]})]})}function Yu({trigger:e,triggerClassName:t,disabled:n=!1,children:r}){const[i,s]=v.useState(!1);return n?f.jsx("button",{disabled:!0,className:he("flex items-center gap-1.5 px-2 py-1 text-sm rounded-md text-muted-foreground [&>svg]:shrink-0 opacity-70 cursor-default [&>span]:whitespace-nowrap",t),children:e}):f.jsxs(wk,{open:i,onOpenChange:s,children:[f.jsx(Ck,{asChild:!0,children:f.jsx("button",{className:he("flex items-center gap-1.5 px-2 py-1 text-sm rounded-md transition-colors text-muted-foreground [&>svg]:shrink-0 [&>span]:whitespace-nowrap","hover:bg-muted/50",t),children:e})}),f.jsx(S0,{align:"center",className:"w-64 p-1",children:f.jsx("div",{className:"space-y-1",children:typeof r=="function"?r(()=>s(!1)):r})})]})}function I1({availableProviders:e,selectedProvider:t,showProviderPicker:n=!0,showCodexCliRequirementHints:r=!1,model:i,modelOptions:s,onProviderChange:o,onModelChange:l,onModelOptionChange:c,planMode:u=!1,onPlanModeChange:p,includePlanMode:h=!0,className:g}){var N,M,j,U,I;const b=e.find(P=>P.id===t)??e[0],_=Sj[t],x=cN,S=h&&(b==null?void 0:b.supportsPlanMode)&&p,C=t==="claude"?s:null,E=t==="codex"?s:null,k=((N=b.models.find(P=>P.id===i))==null?void 0:N.contextWindowOptions)??[],T=(C==null?void 0:C.contextWindow)??Lw[0].id,A=T==="1m"?pN:mN;return f.jsxs("div",{className:he("flex md:justify-center items-center gap-0.5",g),children:[n?f.jsx(Yu,{disabled:!o,trigger:f.jsxs(f.Fragment,{children:[f.jsx(_,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:(b==null?void 0:b.label)??t})]}),children:P=>e.map(z=>{const O=Sj[z.id];return f.jsx(na,{onClick:()=>{o==null||o(z.id),P()},selected:t===z.id,icon:f.jsx(O,{className:"h-4 w-4 text-muted-foreground"}),label:z.label},z.id)})}):null,f.jsx(Yu,{trigger:f.jsxs(f.Fragment,{children:[f.jsx(x,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:((M=b.models.find(P=>P.id===i))==null?void 0:M.label)??i})]}),children:P=>b.models.map(z=>{const O=cN;return f.jsx(na,{onClick:()=>{l(t,z.id),P()},selected:i===z.id,icon:f.jsx(O,{className:"h-4 w-4 text-muted-foreground"}),label:r&&t==="codex"&&z.id==="gpt-5.5"?f.jsxs(f.Fragment,{children:[z.label," ",f.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"codex-cli >= 0.124"})]}):z.label},z.id)})}),f.jsx(Yu,{trigger:f.jsxs(f.Fragment,{children:[f.jsx(vx,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:t==="claude"?((j=cb.find(P=>P.id===s.reasoningEffort))==null?void 0:j.label)??s.reasoningEffort:((U=Nw.find(P=>P.id===s.reasoningEffort))==null?void 0:U.label)??s.reasoningEffort})]}),children:P=>t==="claude"?cb.map(z=>f.jsx(na,{onClick:()=>{c({type:"claudeReasoningEffort",effort:z.id}),P()},selected:s.reasoningEffort===z.id,icon:f.jsx(vx,{className:"h-4 w-4 text-muted-foreground"}),label:z.label,disabled:z.id==="max"&&!o4(i)},z.id)):Nw.map(z=>f.jsx(na,{onClick:()=>{c({type:"codexReasoningEffort",effort:z.id}),P()},selected:s.reasoningEffort===z.id,icon:f.jsx(vx,{className:"h-4 w-4 text-muted-foreground"}),label:z.label},z.id))}),t==="claude"&&k.length>1?f.jsx(Yu,{trigger:f.jsxs(f.Fragment,{children:[f.jsx(A,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:((I=k.find(P=>P.id===T))==null?void 0:I.label)??T})]}),children:P=>k.map(z=>f.jsx(na,{onClick:()=>{c({type:"contextWindow",contextWindow:z.id}),P()},selected:T===z.id,icon:z.id==="1m"?f.jsx(pN,{className:"h-4 w-4 text-muted-foreground"}):f.jsx(mN,{className:"h-4 w-4 text-muted-foreground"}),label:z.label,description:z.id==="1m"?"Expanded context window":"Standard context window"},z.id))}):null,t==="codex"?f.jsx(Yu,{trigger:f.jsxs(f.Fragment,{children:[E!=null&&E.fastMode?f.jsx(hg,{className:"h-3.5 w-3.5"}):f.jsx(hg,{className:"h-3.5 w-3.5 -scale-x-100"}),f.jsx("span",{children:E!=null&&E.fastMode?"Fast Mode":"Standard"})]}),triggerClassName:E!=null&&E.fastMode?"text-success":void 0,children:P=>f.jsxs(f.Fragment,{children:[f.jsx(na,{onClick:()=>{c({type:"fastMode",fastMode:!1}),P()},selected:!(E!=null&&E.fastMode),icon:f.jsx(hg,{className:"h-4 w-4 text-muted-foreground -scale-x-100"}),label:"Standard"}),f.jsx(na,{onClick:()=>{c({type:"fastMode",fastMode:!0}),P()},selected:!!(E!=null&&E.fastMode),icon:f.jsx(hg,{className:"h-4 w-4 text-muted-foreground"}),label:"Fast Mode"})]})}):null,S?f.jsx(Yu,{trigger:f.jsxs(f.Fragment,{children:[u?f.jsx(Wv,{className:"h-3.5 w-3.5"}):f.jsx(dN,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:u?"Plan Mode":"Full Access"})]}),triggerClassName:u?"text-info":void 0,children:P=>f.jsxs(f.Fragment,{children:[f.jsx(na,{onClick:()=>{p(!1),P()},selected:!u,icon:f.jsx(dN,{className:"h-4 w-4 text-muted-foreground"}),label:"Full Access",description:"Execution without approval"}),f.jsx(na,{onClick:()=>{p(!0),P()},selected:u,icon:f.jsx(Wv,{className:"h-4 w-4 text-muted-foreground"}),label:"Plan Mode",description:"Review a plan before execution"})]})}):null]})}function qye(e){return e===null||!Number.isFinite(e)?null:e<10?`${e.toFixed(1).replace(/\.0$/,"")}%`:`${Math.round(e)}%`}function wj({usage:e}){const t=qye(e.usedPercentage),n=Math.max(0,Math.min(100,e.usedPercentage??0)),r=9.75,i=2*Math.PI*r,s=i-n/100*i;return f.jsxs(Xr,{delayDuration:0,children:[f.jsx(Qr,{asChild:!0,children:f.jsx("button",{type:"button",className:"group inline-flex items-center justify-center rounded-full transition-opacity hover:opacity-85","aria-label":e.maxTokens!==void 0&&t?`Context window ${t} used`:`Context window ${ch(e.usedTokens)} tokens used`,children:f.jsxs("span",{className:"relative flex h-6 w-6 items-center justify-center",children:[f.jsxs("svg",{viewBox:"0 0 24 24",className:"-rotate-90 absolute inset-0 h-full w-full transform-gpu","aria-hidden":"true",children:[f.jsx("circle",{cx:"12",cy:"12",r,fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-muted-foreground/20"}),f.jsx("circle",{cx:"12",cy:"12",r,fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeDasharray:i,strokeDashoffset:s,className:"text-muted-foreground transition-[stroke-dashoffset] duration-500 ease-out"})]}),f.jsx("span",{className:he("relative flex h-[15px] w-[15px] items-center justify-center rounded-full bg-background text-[9px] font-medium","text-muted-foreground"),children:e.usedPercentage!==null?Math.round(e.usedPercentage):ch(e.usedTokens)})]})})}),f.jsx(Br,{side:"top",align:"center",className:"w-max max-w-none px-3 py-2",children:f.jsx("div",{className:"space-y-1.5 leading-tight",children:e.maxTokens!==void 0&&t?f.jsxs("div",{className:"whitespace-nowrap text-xs font-medium text-foreground",children:[f.jsx("span",{children:t}),f.jsx("span",{className:"mx-1",children:"·"}),f.jsx("span",{children:ch(e.usedTokens)}),f.jsx("span",{children:"/"}),f.jsxs("span",{children:[ch(e.maxTokens)," context used"]})]}):f.jsxs("div",{className:"text-sm text-foreground",children:[ch(e.usedTokens)," tokens used so far"]})})})]})}class DB extends Error{constructor(){super("Upload aborted"),this.name="UploadAbortedError"}}const Kye=80;function Yye(e){const t=e.XHR??XMLHttpRequest,n=new t;let r=!1,i=0,s=-1;return{promise:new Promise((l,c)=>{function u(h,g,b=!1){const _=g>0?g:e.file.size,x=_>0?Math.floor(h/_*100):0,S=Date.now(),C=S-i>=Kye;!b&&!C&&!(x!==s)||(i=S,s=x,e.onProgress({loaded:h,total:_}))}n.upload.addEventListener("progress",h=>{u(h.loaded,h.lengthComputable?h.total:e.file.size)}),n.upload.addEventListener("load",()=>{u(e.file.size,e.file.size,!0)}),n.addEventListener("load",()=>{if(r)return;let h;try{h=n.responseText?JSON.parse(n.responseText):null}catch{h=null}if(n.status>=200&&n.status<300){const b=h==null?void 0:h.attachments;if(!Array.isArray(b)){c(new Error("Upload failed: malformed response"));return}l({attachments:b});return}const g=h==null?void 0:h.error;c(new Error(typeof g=="string"?g:"Upload failed"))}),n.addEventListener("error",()=>{r||c(new Error("Upload failed"))}),n.addEventListener("abort",()=>{c(new DB)});const p=new FormData;p.append("files",e.file),n.open("POST",`/api/projects/${encodeURIComponent(e.projectId)}/uploads`),n.send(p)}),abort:()=>{if(!r){r=!0;try{n.abort()}catch{}}}}}const Xye="(^|[\\s\\n\\t])@agent/([a-z0-9_-]+)";function Qye(){return new RegExp(Xye,"gi")}const Zye=[],PB=50,Jye=3,e_e={"image/gif":"gif","image/jpeg":"jpg","image/png":"png","image/webp":"webp"};function t_e(e){const t=e.maxAttachments??PB;return e.currentAttachmentCount+e.queuedAttachmentCount+e.incomingAttachmentCount>t}function n_e(e){return e?e.types.includes("text/plain")||e.types.includes("text/html"):!1}function OB(e){return e_e[e.type]??"bin"}function r_e(e){const t=e.name.trim().toLowerCase();if(!t)return!0;const n=OB(e);return t===`image.${n}`||t==="image.png"}function i_e(e,t,n){if(e.name&&!r_e(e))return e;const r=OB(e),i=t===0?"":`-${t}`,s=`clipboard-${n}${i}.${r}`;return Object.defineProperty(e,"name",{configurable:!0,value:s}),e}function s_e(e,t){const n=[];for(const r of e){if(r.kind!=="file"||!r.type.startsWith("image/"))continue;const i=r.getAsFile();i&&n.push(i_e(i,n.length,t))}return n}function o_e(e){return e.replace(/(?:\r\n|\r|\n)+$/,"")}function a_e(e){return`${e.value.slice(0,e.selectionStart)}${e.insertedText}${e.value.slice(e.selectionEnd)}`}function l_e(e,t){return e.provider!=="claude"?{...e,model:t}:{...e,model:t,modelOptions:{...e.modelOptions,contextWindow:Pk(t,e.modelOptions.contextWindow)}}}function c_e(e,t,n){return!t||e.provider===t?e:t==="claude"?{provider:"claude",model:n.claude.model,modelOptions:{...n.claude.modelOptions},planMode:e.planMode}:{provider:"codex",model:n.codex.model,modelOptions:{...n.codex.modelOptions},planMode:e.planMode}}const u_e=v.forwardRef(function({onSubmit:t,onLayoutChange:n,onCancel:r,disabled:i,canCancel:s,chatId:o,projectId:l,inputElementRef:c,activeProvider:u,availableProviders:p,contextWindowSnapshot:h=null,previousPrompt:g=null},b){var qn;const{getDraft:_,setDraft:x,clearDraft:S,getAttachmentDrafts:C,setAttachmentDrafts:E,clearAttachmentDrafts:k}=M1(),{providerDefaults:T,getComposerState:A,initializeComposerForChat:N,setChatComposerModel:M,setChatComposerPlanMode:j,resetChatComposerFromProvider:U}=hi(),I=o??Mv,z=hi(K=>K.chatStates[I])??A(I),[O,$]=v.useState(()=>o?_(o):""),V=v.useRef(null),F=Vye(),[H,W]=v.useState(()=>Cj(o?C(o):[])),[Z,D]=v.useState(null),[G,ee]=v.useState(null),B=v.useRef([]),le=v.useRef(0),oe=v.useRef([]),J=v.useRef(0),ne=v.useRef(new Set),se=v.useRef(l??null),ce=v.useRef(o??null),de=c_e(z,u,T),Ne=z.provider,we=Hye(o??null),je=Uye(o??null),[fe,ot]=v.useState(0),[Mt,Et]=v.useState(!1),[Xt,Dt]=v.useState(0);v.useEffect(()=>{O.startsWith("/")||Et(!1)},[O]);const mt=((qn=V.current)==null?void 0:qn.selectionStart)??O.length,yt=v.useMemo(()=>Mye(O,mt),[O,mt,Xt]),Wt=v.useMemo(()=>yt.open?Lye(we,yt.query):[],[yt.open,yt.query,we]),Lt=yt.open&&(we.length>0||je)&&!Mt&&Ne==="claude";v.useEffect(()=>{Lt&&ot(0)},[Lt,yt.query]);const[gt,Bt]=v.useState(0),[ge,ye]=v.useState(!1),ze=v.useMemo(()=>Iye(O,mt),[O,mt,Xt]),Xe=Pye({projectId:l??null,query:ze.query,enabled:ze.open&&!ge}),Me=Bye({query:ze.query,enabled:ze.open&&!ge}),Be=v.useMemo(()=>[...Me.items,...Xe.items.map(K=>({kind:"path",path:K}))],[Xe.items,Me.items]),et=Us(K=>{var be;return((be=K.settings)==null?void 0:be.subagents)??Zye}),We=v.useMemo(()=>{const K=new Map(et.map(Le=>[Le.name.toLowerCase(),Le]));return[...O.matchAll(Qye())].map(Le=>{const Pe=Le[2],ut=K.get(Pe.toLowerCase());return ut?{kind:"ok",label:ut.name,id:ut.id}:{kind:"missing",label:Pe}})},[O,et]),qe=ze.open&&!ge&&!Lt&&(Be.length>0||Xe.loading);v.useEffect(()=>{qe&&Bt(0)},[qe,ze.query]),v.useEffect(()=>{ze.open||ye(!1)},[ze.open,ze.tokenStart]);function ft(K){const{value:be,caret:Le}=Nye({value:O,caret:mt,command:K});$(be),o&&x(o,be),Et(!0),requestAnimationFrame(()=>{const Pe=V.current;Pe&&(Pe.focus(),Pe.setSelectionRange(Le,Le))})}function rt(K){if(K.kind==="agent"){const{value:Nt,caret:Zt}=_j({value:O,caret:mt,tokenStart:ze.tokenStart,mention:{kind:"agent",name:K.subagent.name}});$(Nt),o&&x(o,Nt),ye(!0),requestAnimationFrame(()=>{const fn=V.current;fn&&(fn.focus(),fn.setSelectionRange(Zt,Zt))});return}if(!l){ye(!0);return}const be=K.path,{value:Le,caret:Pe}=_j({value:O,caret:mt,tokenStart:ze.tokenStart,mention:{kind:"path",path:be.path}});$(Le),o&&x(o,Le);const ut=be.path.endsWith("/")?be.path.slice(0,-1):be.path;if(!H.some(Nt=>Nt.kind==="mention"&&Nt.relativePath===`./${ut}`)){const Nt=be.kind==="file"?`/api/projects/${l}/files/${encodeURIComponent(ut)}/content`:"";W(Zt=>[...Zt,{id:crypto.randomUUID(),kind:"mention",displayName:ut,absolutePath:"",relativePath:`./${ut}`,contentUrl:Nt,mimeType:"",size:0,status:"uploaded"}])}ye(!0),requestAnimationFrame(()=>{const Nt=V.current;Nt&&(Nt.focus(),Nt.setSelectionRange(Pe,Pe))})}const Qt=p.find(K=>K.id===Ne)??p[0],lt=(Qt==null?void 0:Qt.supportsPlanMode)??!1,Jt=v.useMemo(()=>{if(de.provider!=="claude")return h;const K=de.modelOptions,be=tte(Pk(de.model,K.contextWindow));return pve(h,be)},[h,de.model,de.modelOptions,de.provider]),dn=H.filter(K=>K.status==="uploaded"),At=H.some(K=>K.status==="uploading"),Rt=O.trim().length>0,Ct=O.trim().length>0||dn.length>0,Ue=[...H].sort((K,be)=>K.kind===be.kind?0:K.kind==="image"?-1:1),vt=H.find(K=>K.id===Z)??null,ht=v.useCallback(K=>{K.previewUrl&&URL.revokeObjectURL(K.previewUrl)},[]),Ot=v.useCallback(K=>{const be=(K==null?void 0:K.cleanupPreviews)??!0;J.current+=1,ne.current.clear(),W(Le=>(be&&Le.forEach(ht),[])),B.current=[],le.current=0,D(null),ee(null)},[ht]),Ft=v.useCallback(()=>{const K=V.current;if(K){if(K.value.length===0){K.style.height="";return}K.style.height="auto",K.style.height=`${K.scrollHeight}px`}},[]),xe=v.useCallback(K=>{V.current=K,c&&(typeof c=="function"?c(K):c.current=K)},[c]);v.useLayoutEffect(()=>{Ft(),n==null||n()},[Ft,n,O]),v.useEffect(()=>{const K=()=>{Ft(),n==null||n()};return window.addEventListener("resize",K),()=>window.removeEventListener("resize",K)},[Ft,n]),v.useLayoutEffect(()=>{n==null||n()},[H.length,n,G]),v.useEffect(()=>{var K;(K=V.current)==null||K.focus()},[o]),v.useEffect(()=>{ce.current=o??null},[o]),v.useEffect(()=>{N(I)},[I,N]),v.useEffect(()=>{J.current+=1,B.current=[],le.current=0,ne.current.clear(),D(null),ee(null),W(K=>(K.forEach(ht),Cj(o?C(o):[])))},[o,ht,C]),v.useEffect(()=>{const K=se.current;se.current=l??null,!(K===null||l===K)&&(Ot(),o&&k(o))},[l,o,Ot,k]),v.useEffect(()=>{oe.current=H},[H]),v.useEffect(()=>{if(!o)return;const K=H.filter(be=>be.status==="uploaded").map(({previewUrl:be,status:Le,uploadProgress:Pe,cancelUpload:ut,...Qe})=>Qe);if(K.length===0){k(o);return}E(o,K)},[H,o,k,E]),v.useEffect(()=>()=>{oe.current.forEach(ht)},[ht]);function Ge(K){hi.getState().setComposerState(I,K(de))}function it(K){Ge(be=>({...be,modelOptions:{...be.modelOptions,reasoningEffort:K}}))}function Je(K){Ge(be=>be.provider!=="claude"?be:l_e({...be,modelOptions:{...be.modelOptions,contextWindow:K}},be.model))}function Se(K){j(I,K)}function nt(){Se(!de.planMode)}const Ye=v.useCallback(()=>{if(l)for(;le.current<Jye&&B.current.length>0;){const K=B.current.shift();if(!K)break;le.current+=1;const be=crypto.randomUUID(),Le=K.type.startsWith("image/")?URL.createObjectURL(K):void 0,Pe=J.current,ut=Yye({projectId:l,file:K,onProgress:({loaded:Qe,total:Nt})=>{if(Pe!==J.current)return;const Zt=Nt>0?Qe/Nt:0;W(fn=>fn.map(hn=>hn.id===be?{...hn,uploadProgress:Zt}:hn))}});W(Qe=>[...Qe,{id:be,kind:K.type.startsWith("image/")?"image":"file",displayName:K.name,absolutePath:"",relativePath:"",contentUrl:"",mimeType:K.type||"application/octet-stream",size:K.size,status:"uploading",previewUrl:Le,uploadProgress:0,cancelUpload:ut.abort}]),(async()=>{try{const{attachments:Qe}=await ut.promise,Nt=Qe[0];if(!Nt)throw new Error("Upload failed");if(Pe!==J.current){OS(Nt),Le&&URL.revokeObjectURL(Le);return}if(ne.current.has(be)){ne.current.delete(be),Le&&URL.revokeObjectURL(Le),OS(Nt);return}W(Zt=>Zt.map(fn=>fn.id!==be?fn:{...fn,...Nt,previewUrl:fn.previewUrl,status:"uploaded",uploadProgress:1,cancelUpload:void 0})),ee(null)}catch(Qe){if(Pe!==J.current){Le&&URL.revokeObjectURL(Le);return}if(Qe instanceof DB){W(Nt=>Nt.filter(Zt=>Zt.id!==be)),ne.current.delete(be),Le&&URL.revokeObjectURL(Le);return}W(Nt=>Nt.map(Zt=>Zt.id===be?{...Zt,status:"failed",cancelUpload:void 0}:Zt)),ee(Qe instanceof Error?Qe.message:String(Qe))}finally{le.current=Math.max(0,le.current-1),Ye()}})()}},[l]),De=v.useCallback(K=>{if(!l){ee("Open a project before uploading files.");return}if(t_e({currentAttachmentCount:oe.current.length,queuedAttachmentCount:B.current.length,incomingAttachmentCount:K.length})){ee(`You can upload up to ${PB} files at a time.`);return}B.current.push(...K),ee(null),Ye()},[Ye,l]);v.useImperativeHandle(b,()=>({enqueueFiles:De}),[De]);async function It(){if(!Ct||At)return;const K=O,be=oe.current,Le=Z,Pe=G,ut=dn.map(({previewUrl:Zt,status:fn,uploadProgress:hn,cancelUpload:sr,..._i})=>_i);let Qe;de.provider==="claude"?Qe={claude:{...de.modelOptions}}:Qe={codex:{...de.modelOptions}};const Nt={provider:Ne,model:de.model,modelOptions:Qe,planMode:lt?de.planMode:!1,attachments:ut};$(""),o&&S(o),V.current&&(V.current.style.height="auto"),Ot({cleanupPreviews:!1}),ce.current&&k(ce.current);try{await t(K,Nt),be.forEach(ht)}catch(Zt){console.error("[ChatInput] Submit failed:",Zt),$(K),o&&x(o,K),W(be),D(Le),ee(Pe)}}function an(K){if(qe){if(K.key==="Escape"){K.preventDefault(),ye(!0);return}if(K.key==="ArrowDown"){K.preventDefault(),Bt(Le=>Math.min(Be.length-1,Le+1));return}if(K.key==="ArrowUp"){K.preventDefault(),Bt(Le=>Math.max(0,Le-1));return}if(K.key==="Enter"||K.key==="Tab"){K.preventDefault();const Le=Be[gt];Le&&rt(Le);return}}if(Lt){if(K.key==="Escape"){K.preventDefault(),Et(!0);return}if(K.key==="ArrowDown"){K.preventDefault(),ot(Le=>Math.min(Wt.length-1,Le+1));return}if(K.key==="ArrowUp"){K.preventDefault(),ot(Le=>Math.max(0,Le-1));return}if(K.key==="Enter"||K.key==="Tab"){K.preventDefault();const Le=Wt[fe];Le&&ft(Le);return}}if(K.key==="Tab"&&!K.shiftKey){K.preventDefault(),DK(V.current,document);return}if(K.key==="Tab"&&K.shiftKey&<){K.preventDefault(),nt();return}if(K.key==="Escape"&&s){K.preventDefault(),r==null||r();return}if(K.key==="ArrowUp"&&!K.shiftKey&&!K.altKey&&!K.ctrlKey&&!K.metaKey&&O.length===0&&g){K.preventDefault(),$(g),o&&x(o,g);return}const be="ontouchstart"in window||navigator.maxTouchPoints>0;K.key==="Enter"&&!K.shiftKey&&!be&&!i&&Rt&&!At&&(K.preventDefault(),It())}function Fe(K){const be=s_e(K.clipboardData.items,Date.now()),Le=K.clipboardData.getData("text/plain"),Pe=o_e(Le),ut=Le.length>0&&Pe!==Le;if(!(be.length===0&&!ut)){if(be.length>0&&De(be),ut){K.preventDefault();const Qe=K.currentTarget,Nt=a_e({value:O,insertedText:Pe,selectionStart:Qe.selectionStart,selectionEnd:Qe.selectionEnd}),Zt=Qe.selectionStart+Pe.length;$(Nt),o&&x(o,Nt),Ft(),requestAnimationFrame(()=>{Qe.selectionStart=Zt,Qe.selectionEnd=Zt});return}n_e(K.clipboardData)||K.preventDefault()}}function Vt(K){if(Gp(K).openInNewTab){typeof window<"u"&&window.open(new URL(K.contentUrl,window.location.origin).toString(),"_blank","noopener,noreferrer");return}D(K.id)}function _n(K){var be;K.status==="uploading"&&((be=K.cancelUpload)==null||be.call(K)),ne.current.add(K.id),W(Le=>{const Pe=Le.find(ut=>ut.id===K.id);return Pe&&ht(Pe),Le.filter(ut=>ut.id!==K.id)}),Z===K.id&&D(null),K.status==="uploaded"&&(ne.current.delete(K.id),OS(K))}return f.jsxs("div",{children:[f.jsxs("div",{className:he("px-3 pt-0",F&&"px-5"),children:[f.jsxs("div",{className:"max-w-[840px] mx-auto rounded-[32px]",children:[We.length>0?f.jsx("div",{className:"flex flex-wrap gap-1 px-2 pt-2",children:We.map((K,be)=>f.jsxs("span",{className:he("inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs",K.kind==="ok"?"bg-accent text-accent-foreground":"bg-destructive/15 text-destructive"),children:[f.jsx(LC,{className:"h-3 w-3"}),"agent/",K.label,K.kind==="missing"&&f.jsx("span",{className:"ml-1 font-medium",children:"unknown"})]},`${K.kind}:${K.label}:${be}`))}):null,H.length>0?f.jsx(jB,{className:"overflow-x-auto overflow-y-hidden whitespace-nowrap px-2 pb-2",children:f.jsx("div",{className:"flex items-end gap-2 pt-2",children:Ue.map(K=>f.jsx("div",{className:he("flex shrink-0 flex-col justify-end",K.status==="failed"&&"text-destructive"),children:K.kind==="image"?f.jsx(kE,{attachment:K,previewUrl:K.previewUrl,size:"composer",onClick:K.status==="uploaded"?()=>Vt(K):void 0,onRemove:()=>_n(K),uploadProgress:K.status==="uploading"?K.uploadProgress??null:void 0,onCancelUpload:K.status==="uploading"?()=>_n(K):void 0}):f.jsx(Sl,{attachment:K,onClick:K.status==="uploaded"&&K.contentUrl?()=>Vt(K):void 0,onRemove:()=>_n(K),uploadProgress:K.status==="uploading"?K.uploadProgress??null:void 0,onCancelUpload:K.status==="uploading"?()=>_n(K):void 0})},K.id))})}):null,f.jsxs("div",{className:"relative flex items-end max-w-[840px] mx-auto border bg-background dark:bg-card/90 border-border rounded-[29px] pr-1.5 transition-colors focus-within:border-ring/60 focus-within:ring-2 focus-within:ring-ring/30",children:[Lt&&f.jsx(Eye,{items:Wt,activeIndex:fe,loading:je,onSelect:ft,onHoverIndex:ot}),qe&&f.jsx(Tye,{items:Be,activeIndex:gt,loading:Xe.loading,onSelect:rt,onHoverIndex:Bt}),f.jsxs("label",{"aria-label":"Add attachment",className:he(a0({variant:"ghost",size:"icon"}),"relative flex-shrink-0 ml-1 mb-1 h-11 w-11 rounded-full text-muted-foreground hover:text-foreground",i&&"pointer-events-none opacity-50"),children:[f.jsx(uW,{className:"h-5 w-5"}),f.jsx("input",{type:"file",multiple:!0,disabled:i,"aria-label":"Add attachment",className:"absolute inset-0 cursor-pointer opacity-0",onChange:K=>{const be=[...K.target.files??[]];be.length>0&&De(be),K.target.value=""}})]}),f.jsx(Y0,{ref:xe,placeholder:"Build something...",value:O,autoFocus:!0,[qC]:"",rows:1,onChange:K=>{$(K.target.value),o&&x(o,K.target.value),Ft(),Dt(be=>be+1)},onSelect:()=>Dt(K=>K+1),onKeyUp:()=>Dt(K=>K+1),onPaste:Fe,onKeyDown:an,disabled:i,className:"flex-1 text-base p-3 md:p-4 !pr-2 pl-0 md:pl-6 resize-none max-h-[200px] outline-none focus:outline-none focus-visible:outline-none focus-visible:ring-0 bg-transparent border-0 shadow-none"}),f.jsx(Ke,{type:"button",onPointerDown:K=>{K.preventDefault(),!i&&Rt&&!At?It():s?r==null||r():!i&&Ct&&!At&&It()},disabled:i||!s&&!Ct||At,size:"icon","aria-label":s?"Stop":"Send message",className:"flex-shrink-0 bg-primary text-background rounded-full cursor-pointer h-11 w-11 mb-1 -mr-0.5 md:mr-0 md:mb-1.5 touch-manipulation disabled:opacity-50",children:Rt?f.jsx(Gh,{className:"h-5 w-5 md:h-6 md:w-6"}):s?f.jsx("div",{className:"w-3 h-3 md:w-4 md:h-4 rounded-xs bg-current"}):f.jsx(Gh,{className:"h-5 w-5 md:h-6 md:w-6"})})]})]}),G?f.jsx("div",{className:"max-w-[840px] mx-auto mt-2 px-1 text-sm text-destructive",children:G}):null]}),f.jsxs("div",{className:he("relative py-3 max-w-[840px] mx-auto",F&&"p-5 pt-3"),children:[f.jsxs("div",{className:"overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden flex flex-row",children:[f.jsx("div",{className:"min-w-3"}),f.jsx(I1,{availableProviders:p,selectedProvider:Ne,showCodexCliRequirementHints:!0,model:de.model,modelOptions:de.modelOptions,onProviderChange:K=>{U(I,K)},onModelChange:(K,be)=>{M(I,be)},onModelOptionChange:K=>{switch(K.type){case"claudeReasoningEffort":it(K.effort);break;case"codexReasoningEffort":it(K.effort);break;case"contextWindow":Je(K.contextWindow);break;case"fastMode":Ge(be=>be.provider==="claude"?be:{...be,modelOptions:{...be.modelOptions,fastMode:K.fastMode}});break}},planMode:de.planMode,onPlanModeChange:Se,includePlanMode:lt,className:"max-w-[840px] mx-auto"}),Jt?f.jsx("div",{className:"flex items-center md:hidden mx-[13px]",children:f.jsx(wj,{usage:Jt})}):null,f.jsx("div",{className:"min-w-3"})]}),Jt?f.jsx("div",{className:"absolute right-[29px] top-1/2 translate-x-1/2 -translate-y-1/2 hidden md:block",children:f.jsx(wj,{usage:Jt})}):null]}),f.jsx(W0,{attachment:vt,onOpenChange:K=>!K&&D(null)})]})}),d_e=v.memo(u_e);async function OS(e){if(!e.contentUrl)return;const t=e.contentUrl.replace(/\/content$/,"");await fetch(t,{method:"DELETE"}).catch(()=>{})}function Cj(e){return e.map(t=>({...t,status:"uploaded"}))}const f_e=v.memo(function({inputRef:t,onLayoutChange:n,chatInputRef:r,chatInputElementRef:i,activeChatId:s,previousPrompt:o,hasSelectedProject:l,canCancel:c,projectId:u,activeProvider:p,availableProviders:h,contextWindowSnapshot:g,onSubmit:b,onCancel:_}){return f.jsx("div",{className:"absolute bottom-0 left-0 right-0 z-20 pointer-events-none",children:f.jsx("div",{className:"bg-gradient-to-t from-background via-background pointer-events-auto",ref:t,children:f.jsx(d_e,{ref:r,inputElementRef:i,onLayoutChange:n,onSubmit:b,onCancel:_,disabled:!l,canCancel:c,chatId:s,projectId:u,activeProvider:p,availableProviders:h,contextWindowSnapshot:g,previousPrompt:o},s??"new-chat")})})});var zS={exports:{}},BS={};/**
|
|
2629
|
+
`&&i!==" "?tv:{open:!0,query:n.slice(r+1),tokenStart:r}}function _j(e){const t=e.value.slice(0,e.tokenStart),n=e.value.slice(e.caret),r=e.mention.kind==="agent"?`@agent/${e.mention.name}`:`@${e.mention.path}`,i=`${t}${r}${n}`,s=t.length+r.length;return{value:i,caret:s}}const jye=120;async function Dye(e){const t=new URLSearchParams({query:e.query});try{const n=await fetch(`/api/projects/${e.projectId}/paths?${t.toString()}`,{signal:e.signal});return n.ok?(await n.json()).paths??[]:[]}catch{return[]}}function Pye(e){const[t,n]=v.useState({items:[],loading:!1,error:null}),r=v.useRef(null),i=v.useRef(null);return v.useEffect(()=>{var o;if(!e.enabled||!e.projectId){n({items:[],loading:!1,error:null});return}r.current&&clearTimeout(r.current),(o=i.current)==null||o.abort(),n(l=>({...l,loading:!0,error:null}));const s=new AbortController;return i.current=s,r.current=setTimeout(async()=>{const l=await Dye({projectId:e.projectId,query:e.query,signal:s.signal});s.signal.aborted||n({items:l,loading:!1,error:null})},jye),()=>{r.current&&clearTimeout(r.current),s.abort()}},[e.enabled,e.projectId,e.query]),t}const Oye=[];function zye(e,t){const n=t.toLowerCase();if(n&&!("agent/".startsWith(n)||n.startsWith("agent/")))return[];const r=n.startsWith("agent/")?n.slice(6):"";return e.filter(i=>i.name.toLowerCase().includes(r)).sort((i,s)=>i.name.localeCompare(s.name)).map(i=>({kind:"agent",subagent:i}))}function Bye(e){const t=Us(n=>{var r;return((r=n.settings)==null?void 0:r.subagents)??Oye});return v.useMemo(()=>({items:e.enabled?zye(t,e.query):[]}),[e.enabled,e.query,t])}const xj=[];function Fye(e,t){return t?e.byChatId[t]??xj:xj}function $ye(e,t){return t?e.loadingByChatId[t]??!1:!1}function Hye(e){return zE(t=>Fye(t,e))}function Uye(e){return zE(t=>$ye(t,e))}const jB=v.forwardRef(({className:e,children:t,...n},r)=>f.jsx("div",{ref:r,className:he("relative overflow-y-auto overscroll-contain touch-pan-y scrollbar-hide",e),style:{WebkitOverflowScrolling:"touch"},...n,children:t}));jB.displayName="ScrollArea";function Vye(){const[e,t]=v.useState(()=>{if(typeof window>"u")return!1;const n=navigator.standalone===!0,r=window.matchMedia("(display-mode: standalone)").matches;return n||r});return v.useEffect(()=>{const n=window.matchMedia("(display-mode: standalone)"),r=i=>{t(i.matches||navigator.standalone===!0)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}function Wye({className:e,...t}){return f.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",className:he("shrink-0",e),...t,children:f.jsx("path",{d:"M17.3041 3.541h-3.6718l6.696 16.918H24Zm-10.6082 0L0 20.459h3.7442l1.3693-3.5527h7.0052l1.3693 3.5528h3.7442L10.5363 3.5409Zm-.3712 10.2232 2.2914-5.9456 2.2914 5.9456Z"})})}function Gye({className:e,...t}){return f.jsx("svg",{viewBox:"0 0 158.7128 157.296",fill:"currentColor","aria-hidden":"true",className:he("shrink-0",e),...t,children:f.jsx("path",{d:"M60.8734 57.2556V42.3124c0-1.2586.4722-2.2029 1.5728-2.8314l30.0443-17.3023c4.0899-2.3593 8.9662-3.4599 13.9988-3.4599 18.8759 0 30.8307 14.6289 30.8307 30.2006 0 1.1007 0 2.3593-.158 3.6178l-31.1446-18.2467c-1.8872-1.1006-3.7754-1.1006-5.6629 0L60.8734 57.2556Zm70.1542 58.2005V79.7487c0-2.2028-.9446-3.7756-2.8318-4.8763l-39.481-22.9651 12.8982-7.3934c1.1007-.6285 2.0453-.6285 3.1458 0l30.0441 17.3024c8.6523 5.0341 14.4708 15.7296 14.4708 26.1107 0 11.9539-7.0769 22.965-18.2461 27.527ZM51.593 83.9964l-12.8982-7.5497c-1.1007-.6285-1.5728-1.5728-1.5728-2.8314V39.0105c0-16.8303 12.8982-29.5722 30.3585-29.5722 6.607 0 12.7403 2.2029 17.9324 6.1349l-30.987 17.9324c-1.8871 1.1007-2.8314 2.6735-2.8314 4.8764v45.6159ZM79.3562 100.0403 60.8733 89.6592V67.6383l18.4829-10.3811 18.4812 10.3811v22.0209l-18.4812 10.3811Zm11.8757 47.8188c-6.607 0-12.7403-2.2031-17.9324-6.1344l30.9866-17.9333c1.8872-1.1005 2.8318-2.6728 2.8318-4.8759v-45.616l13.0564 7.5498c1.1005.6285 1.5723 1.5728 1.5723 2.8314v34.6051c0 16.8297-13.0564 29.5723-30.5147 29.5723ZM53.9522 112.7822 23.9079 95.4798c-8.652-5.0343-14.471-15.7296-14.471-26.1107 0-12.1119 7.2356-22.9652 18.403-27.5272v35.8634c0 2.2028.9443 3.7756 2.8314 4.8763l39.3248 22.8068-12.8982 7.3938c-1.1007.6287-2.045.6287-3.1456 0ZM52.2229 138.5791c-17.7745 0-30.8306-13.3713-30.8306-29.8871 0-1.2585.1578-2.5169.3143-3.7754l30.987 17.9323c1.8871 1.1005 3.7757 1.1005 5.6628 0l39.4811-22.807v14.9435c0 1.2585-.4721 2.2021-1.5728 2.8308l-30.0443 17.3025c-4.0898 2.359-8.9662 3.4605-13.9989 3.4605h.0014ZM91.2319 157.296c19.0327 0 34.9188-13.5272 38.5383-31.4594 17.6164-4.562 28.9425-21.0779 28.9425-37.908 0-11.0112-4.719-21.7066-13.2133-29.4143.7867-3.3035 1.2595-6.607 1.2595-9.909 0-22.4929-18.2471-39.3247-39.3251-39.3247-4.2461 0-8.3363.6285-12.4262 2.045-7.0792-6.9213-16.8318-11.3254-27.5271-11.3254-19.0331 0-34.9191 13.5268-38.5384 31.4591C11.3255 36.0212 0 52.5373 0 69.3675c0 11.0112 4.7184 21.7065 13.2125 29.4142-.7865 3.3035-1.2586 6.6067-1.2586 9.9092 0 22.4923 18.2466 39.3241 39.3248 39.3241 4.2462 0 8.3362-.6277 12.426-2.0441 7.0776 6.921 16.8302 11.3251 27.5271 11.3251Z"})})}const Sj={claude:Wye,codex:Gye};function na({onClick:e,selected:t,icon:n,label:r,description:i,disabled:s}){return f.jsxs("button",{onClick:e,disabled:s,className:he("w-full flex items-center gap-2 p-2 border border-border/0 rounded-lg text-left transition-opacity",t?"bg-muted border-border":"hover:opacity-60",s&&"opacity-40 cursor-not-allowed"),children:[n,f.jsxs("div",{children:[f.jsx("div",{className:"text-sm font-medium",children:r}),i?f.jsx("div",{className:"text-xs text-muted-foreground",children:i}):null]})]})}function Yu({trigger:e,triggerClassName:t,disabled:n=!1,children:r}){const[i,s]=v.useState(!1);return n?f.jsx("button",{disabled:!0,className:he("flex items-center gap-1.5 px-2 py-1 text-sm rounded-md text-muted-foreground [&>svg]:shrink-0 opacity-70 cursor-default [&>span]:whitespace-nowrap",t),children:e}):f.jsxs(wk,{open:i,onOpenChange:s,children:[f.jsx(Ck,{asChild:!0,children:f.jsx("button",{className:he("flex items-center gap-1.5 px-2 py-1 text-sm rounded-md transition-colors text-muted-foreground [&>svg]:shrink-0 [&>span]:whitespace-nowrap","hover:bg-muted/50",t),children:e})}),f.jsx(S0,{align:"center",className:"w-64 p-1",children:f.jsx("div",{className:"space-y-1",children:typeof r=="function"?r(()=>s(!1)):r})})]})}function I1({availableProviders:e,selectedProvider:t,showProviderPicker:n=!0,showCodexCliRequirementHints:r=!1,model:i,modelOptions:s,onProviderChange:o,onModelChange:l,onModelOptionChange:c,planMode:u=!1,onPlanModeChange:p,includePlanMode:h=!0,className:g}){var N,M,j,U,I;const b=e.find(P=>P.id===t)??e[0],_=Sj[t],x=cN,S=h&&(b==null?void 0:b.supportsPlanMode)&&p,C=t==="claude"?s:null,E=t==="codex"?s:null,k=((N=b.models.find(P=>P.id===i))==null?void 0:N.contextWindowOptions)??[],T=(C==null?void 0:C.contextWindow)??Lw[0].id,A=T==="1m"?pN:mN;return f.jsxs("div",{className:he("flex md:justify-center items-center gap-0.5",g),children:[n?f.jsx(Yu,{disabled:!o,trigger:f.jsxs(f.Fragment,{children:[f.jsx(_,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:(b==null?void 0:b.label)??t})]}),children:P=>e.map(z=>{const O=Sj[z.id];return f.jsx(na,{onClick:()=>{o==null||o(z.id),P()},selected:t===z.id,icon:f.jsx(O,{className:"h-4 w-4 text-muted-foreground"}),label:z.label},z.id)})}):null,f.jsx(Yu,{trigger:f.jsxs(f.Fragment,{children:[f.jsx(x,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:((M=b.models.find(P=>P.id===i))==null?void 0:M.label)??i})]}),children:P=>b.models.map(z=>{const O=cN;return f.jsx(na,{onClick:()=>{l(t,z.id),P()},selected:i===z.id,icon:f.jsx(O,{className:"h-4 w-4 text-muted-foreground"}),label:r&&t==="codex"&&z.id==="gpt-5.5"?f.jsxs(f.Fragment,{children:[z.label," ",f.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"codex-cli >= 0.124"})]}):z.label},z.id)})}),f.jsx(Yu,{trigger:f.jsxs(f.Fragment,{children:[f.jsx(vx,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:t==="claude"?((j=cb.find(P=>P.id===s.reasoningEffort))==null?void 0:j.label)??s.reasoningEffort:((U=Nw.find(P=>P.id===s.reasoningEffort))==null?void 0:U.label)??s.reasoningEffort})]}),children:P=>t==="claude"?cb.map(z=>f.jsx(na,{onClick:()=>{c({type:"claudeReasoningEffort",effort:z.id}),P()},selected:s.reasoningEffort===z.id,icon:f.jsx(vx,{className:"h-4 w-4 text-muted-foreground"}),label:z.label,disabled:z.id==="max"&&!o4(i)},z.id)):Nw.map(z=>f.jsx(na,{onClick:()=>{c({type:"codexReasoningEffort",effort:z.id}),P()},selected:s.reasoningEffort===z.id,icon:f.jsx(vx,{className:"h-4 w-4 text-muted-foreground"}),label:z.label},z.id))}),t==="claude"&&k.length>1?f.jsx(Yu,{trigger:f.jsxs(f.Fragment,{children:[f.jsx(A,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:((I=k.find(P=>P.id===T))==null?void 0:I.label)??T})]}),children:P=>k.map(z=>f.jsx(na,{onClick:()=>{c({type:"contextWindow",contextWindow:z.id}),P()},selected:T===z.id,icon:z.id==="1m"?f.jsx(pN,{className:"h-4 w-4 text-muted-foreground"}):f.jsx(mN,{className:"h-4 w-4 text-muted-foreground"}),label:z.label,description:z.id==="1m"?"Expanded context window":"Standard context window"},z.id))}):null,t==="codex"?f.jsx(Yu,{trigger:f.jsxs(f.Fragment,{children:[E!=null&&E.fastMode?f.jsx(hg,{className:"h-3.5 w-3.5"}):f.jsx(hg,{className:"h-3.5 w-3.5 -scale-x-100"}),f.jsx("span",{children:E!=null&&E.fastMode?"Fast Mode":"Standard"})]}),triggerClassName:E!=null&&E.fastMode?"text-success":void 0,children:P=>f.jsxs(f.Fragment,{children:[f.jsx(na,{onClick:()=>{c({type:"fastMode",fastMode:!1}),P()},selected:!(E!=null&&E.fastMode),icon:f.jsx(hg,{className:"h-4 w-4 text-muted-foreground -scale-x-100"}),label:"Standard"}),f.jsx(na,{onClick:()=>{c({type:"fastMode",fastMode:!0}),P()},selected:!!(E!=null&&E.fastMode),icon:f.jsx(hg,{className:"h-4 w-4 text-muted-foreground"}),label:"Fast Mode"})]})}):null,S?f.jsx(Yu,{trigger:f.jsxs(f.Fragment,{children:[u?f.jsx(Wv,{className:"h-3.5 w-3.5"}):f.jsx(dN,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:u?"Plan Mode":"Full Access"})]}),triggerClassName:u?"text-info":void 0,children:P=>f.jsxs(f.Fragment,{children:[f.jsx(na,{onClick:()=>{p(!1),P()},selected:!u,icon:f.jsx(dN,{className:"h-4 w-4 text-muted-foreground"}),label:"Full Access",description:"Execution without approval"}),f.jsx(na,{onClick:()=>{p(!0),P()},selected:u,icon:f.jsx(Wv,{className:"h-4 w-4 text-muted-foreground"}),label:"Plan Mode",description:"Review a plan before execution"})]})}):null]})}function qye(e){return e===null||!Number.isFinite(e)?null:e<10?`${e.toFixed(1).replace(/\.0$/,"")}%`:`${Math.round(e)}%`}function wj({usage:e}){const t=qye(e.usedPercentage),n=Math.max(0,Math.min(100,e.usedPercentage??0)),r=9.75,i=2*Math.PI*r,s=i-n/100*i;return f.jsxs(Xr,{delayDuration:0,children:[f.jsx(Qr,{asChild:!0,children:f.jsx("button",{type:"button",className:"group inline-flex items-center justify-center rounded-full transition-opacity hover:opacity-85","aria-label":e.maxTokens!==void 0&&t?`Context window ${t} used`:`Context window ${ch(e.usedTokens)} tokens used`,children:f.jsxs("span",{className:"relative flex h-6 w-6 items-center justify-center",children:[f.jsxs("svg",{viewBox:"0 0 24 24",className:"-rotate-90 absolute inset-0 h-full w-full transform-gpu","aria-hidden":"true",children:[f.jsx("circle",{cx:"12",cy:"12",r,fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-muted-foreground/20"}),f.jsx("circle",{cx:"12",cy:"12",r,fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeDasharray:i,strokeDashoffset:s,className:"text-muted-foreground transition-[stroke-dashoffset] duration-500 ease-out"})]}),f.jsx("span",{className:he("relative flex h-[15px] w-[15px] items-center justify-center rounded-full bg-background text-[9px] font-medium","text-muted-foreground"),children:e.usedPercentage!==null?Math.round(e.usedPercentage):ch(e.usedTokens)})]})})}),f.jsx(Br,{side:"top",align:"center",className:"w-max max-w-none px-3 py-2",children:f.jsx("div",{className:"space-y-1.5 leading-tight",children:e.maxTokens!==void 0&&t?f.jsxs("div",{className:"whitespace-nowrap text-xs font-medium text-foreground",children:[f.jsx("span",{children:t}),f.jsx("span",{className:"mx-1",children:"·"}),f.jsx("span",{children:ch(e.usedTokens)}),f.jsx("span",{children:"/"}),f.jsxs("span",{children:[ch(e.maxTokens)," context used"]})]}):f.jsxs("div",{className:"text-sm text-foreground",children:[ch(e.usedTokens)," tokens used so far"]})})})]})}class DB extends Error{constructor(){super("Upload aborted"),this.name="UploadAbortedError"}}const Kye=80;function Yye(e){const t=e.XHR??XMLHttpRequest,n=new t;let r=!1,i=0,s=-1;return{promise:new Promise((l,c)=>{function u(h,g,b=!1){const _=g>0?g:e.file.size,x=_>0?Math.floor(h/_*100):0,S=Date.now(),C=S-i>=Kye;!b&&!C&&!(x!==s)||(i=S,s=x,e.onProgress({loaded:h,total:_}))}n.upload.addEventListener("progress",h=>{u(h.loaded,h.lengthComputable?h.total:e.file.size)}),n.upload.addEventListener("load",()=>{u(e.file.size,e.file.size,!0)}),n.addEventListener("load",()=>{if(r)return;let h;try{h=n.responseText?JSON.parse(n.responseText):null}catch{h=null}if(n.status>=200&&n.status<300){const b=h==null?void 0:h.attachments;if(!Array.isArray(b)){c(new Error("Upload failed: malformed response"));return}l({attachments:b});return}const g=h==null?void 0:h.error;c(new Error(typeof g=="string"?g:"Upload failed"))}),n.addEventListener("error",()=>{r||c(new Error("Upload failed"))}),n.addEventListener("abort",()=>{c(new DB)});const p=new FormData;p.append("files",e.file),n.open("POST",`/api/projects/${encodeURIComponent(e.projectId)}/uploads`),n.send(p)}),abort:()=>{if(!r){r=!0;try{n.abort()}catch{}}}}}const Xye="(^|[\\s\\n\\t])@agent/([a-z0-9_-]+)";function Qye(){return new RegExp(Xye,"gi")}const Zye=[],PB=50,Jye=3,e_e={"image/gif":"gif","image/jpeg":"jpg","image/png":"png","image/webp":"webp"};function t_e(e){const t=e.maxAttachments??PB;return e.currentAttachmentCount+e.queuedAttachmentCount+e.incomingAttachmentCount>t}function n_e(e){return e?e.types.includes("text/plain")||e.types.includes("text/html"):!1}function OB(e){return e_e[e.type]??"bin"}function r_e(e){const t=e.name.trim().toLowerCase();if(!t)return!0;const n=OB(e);return t===`image.${n}`||t==="image.png"}function i_e(e,t,n){if(e.name&&!r_e(e))return e;const r=OB(e),i=t===0?"":`-${t}`,s=`clipboard-${n}${i}.${r}`;return Object.defineProperty(e,"name",{configurable:!0,value:s}),e}function s_e(e,t){const n=[];for(const r of e){if(r.kind!=="file"||!r.type.startsWith("image/"))continue;const i=r.getAsFile();i&&n.push(i_e(i,n.length,t))}return n}function o_e(e){return e.replace(/(?:\r\n|\r|\n)+$/,"")}function a_e(e){return`${e.value.slice(0,e.selectionStart)}${e.insertedText}${e.value.slice(e.selectionEnd)}`}function l_e(e,t){return e.provider!=="claude"?{...e,model:t}:{...e,model:t,modelOptions:{...e.modelOptions,contextWindow:Pk(t,e.modelOptions.contextWindow)}}}function c_e(e,t,n){return!t||e.provider===t?e:t==="claude"?{provider:"claude",model:n.claude.model,modelOptions:{...n.claude.modelOptions},planMode:e.planMode}:{provider:"codex",model:n.codex.model,modelOptions:{...n.codex.modelOptions},planMode:e.planMode}}const u_e=v.forwardRef(function({onSubmit:t,onLayoutChange:n,onCancel:r,disabled:i,canCancel:s,chatId:o,projectId:l,inputElementRef:c,activeProvider:u,availableProviders:p,contextWindowSnapshot:h=null,previousPrompt:g=null},b){var qn;const{getDraft:_,setDraft:x,clearDraft:S,getAttachmentDrafts:C,setAttachmentDrafts:E,clearAttachmentDrafts:k}=M1(),{providerDefaults:T,getComposerState:A,initializeComposerForChat:N,setChatComposerModel:M,setChatComposerPlanMode:j,resetChatComposerFromProvider:U}=hi(),I=o??Mv,z=hi(K=>K.chatStates[I])??A(I),[O,$]=v.useState(()=>o?_(o):""),V=v.useRef(null),F=Vye(),[H,W]=v.useState(()=>Cj(o?C(o):[])),[Z,D]=v.useState(null),[G,ee]=v.useState(null),B=v.useRef([]),le=v.useRef(0),oe=v.useRef([]),J=v.useRef(0),ne=v.useRef(new Set),se=v.useRef(l??null),ce=v.useRef(o??null),de=c_e(z,u,T),Ne=z.provider,we=Hye(o??null),je=Uye(o??null),[fe,ot]=v.useState(0),[Mt,Et]=v.useState(!1),[Xt,Dt]=v.useState(0);v.useEffect(()=>{O.startsWith("/")||Et(!1)},[O]);const mt=((qn=V.current)==null?void 0:qn.selectionStart)??O.length,yt=v.useMemo(()=>Mye(O,mt),[O,mt,Xt]),Wt=v.useMemo(()=>yt.open?Lye(we,yt.query):[],[yt.open,yt.query,we]),Lt=yt.open&&(we.length>0||je)&&!Mt&&Ne==="claude";v.useEffect(()=>{Lt&&ot(0)},[Lt,yt.query]);const[gt,Bt]=v.useState(0),[ge,ye]=v.useState(!1),ze=v.useMemo(()=>Iye(O,mt),[O,mt,Xt]),Xe=Pye({projectId:l??null,query:ze.query,enabled:ze.open&&!ge}),Me=Bye({query:ze.query,enabled:ze.open&&!ge}),Be=v.useMemo(()=>[...Me.items,...Xe.items.map(K=>({kind:"path",path:K}))],[Xe.items,Me.items]),et=Us(K=>{var be;return((be=K.settings)==null?void 0:be.subagents)??Zye}),We=v.useMemo(()=>{const K=new Map(et.map(Le=>[Le.name.toLowerCase(),Le]));return[...O.matchAll(Qye())].map(Le=>{const Pe=Le[2],ut=K.get(Pe.toLowerCase());return ut?{kind:"ok",label:ut.name,id:ut.id}:{kind:"missing",label:Pe}})},[O,et]),qe=ze.open&&!ge&&!Lt&&(Be.length>0||Xe.loading);v.useEffect(()=>{qe&&Bt(0)},[qe,ze.query]),v.useEffect(()=>{ze.open||ye(!1)},[ze.open,ze.tokenStart]);function ft(K){const{value:be,caret:Le}=Nye({value:O,caret:mt,command:K});$(be),o&&x(o,be),Et(!0),requestAnimationFrame(()=>{const Pe=V.current;Pe&&(Pe.focus(),Pe.setSelectionRange(Le,Le))})}function rt(K){if(K.kind==="agent"){const{value:Nt,caret:Zt}=_j({value:O,caret:mt,tokenStart:ze.tokenStart,mention:{kind:"agent",name:K.subagent.name}});$(Nt),o&&x(o,Nt),ye(!0),requestAnimationFrame(()=>{const fn=V.current;fn&&(fn.focus(),fn.setSelectionRange(Zt,Zt))});return}if(!l){ye(!0);return}const be=K.path,{value:Le,caret:Pe}=_j({value:O,caret:mt,tokenStart:ze.tokenStart,mention:{kind:"path",path:be.path}});$(Le),o&&x(o,Le);const ut=be.path.endsWith("/")?be.path.slice(0,-1):be.path;if(!H.some(Nt=>Nt.kind==="mention"&&Nt.relativePath===`./${ut}`)){const Nt=be.kind==="file"?`/api/projects/${l}/files/${encodeURIComponent(ut)}/content`:"";W(Zt=>[...Zt,{id:crypto.randomUUID(),kind:"mention",displayName:ut,absolutePath:"",relativePath:`./${ut}`,contentUrl:Nt,mimeType:"",size:0,status:"uploaded"}])}ye(!0),requestAnimationFrame(()=>{const Nt=V.current;Nt&&(Nt.focus(),Nt.setSelectionRange(Pe,Pe))})}const Qt=p.find(K=>K.id===Ne)??p[0],lt=(Qt==null?void 0:Qt.supportsPlanMode)??!1,Jt=v.useMemo(()=>{if(de.provider!=="claude")return h;const K=de.modelOptions,be=tte(Pk(de.model,K.contextWindow));return pve(h,be)},[h,de.model,de.modelOptions,de.provider]),dn=H.filter(K=>K.status==="uploaded"),At=H.some(K=>K.status==="uploading"),Rt=O.trim().length>0,Ct=O.trim().length>0||dn.length>0,Ue=[...H].sort((K,be)=>K.kind===be.kind?0:K.kind==="image"?-1:1),vt=H.find(K=>K.id===Z)??null,ht=v.useCallback(K=>{K.previewUrl&&URL.revokeObjectURL(K.previewUrl)},[]),Ot=v.useCallback(K=>{const be=(K==null?void 0:K.cleanupPreviews)??!0;J.current+=1,ne.current.clear(),W(Le=>(be&&Le.forEach(ht),[])),B.current=[],le.current=0,D(null),ee(null)},[ht]),Ft=v.useCallback(()=>{const K=V.current;if(K){if(K.value.length===0){K.style.height="";return}K.style.height="auto",K.style.height=`${K.scrollHeight}px`}},[]),xe=v.useCallback(K=>{V.current=K,c&&(typeof c=="function"?c(K):c.current=K)},[c]);v.useLayoutEffect(()=>{Ft(),n==null||n()},[Ft,n,O]),v.useEffect(()=>{const K=()=>{Ft(),n==null||n()};return window.addEventListener("resize",K),()=>window.removeEventListener("resize",K)},[Ft,n]),v.useLayoutEffect(()=>{n==null||n()},[H.length,n,G]),v.useEffect(()=>{var K;(K=V.current)==null||K.focus()},[o]),v.useEffect(()=>{ce.current=o??null},[o]),v.useEffect(()=>{N(I)},[I,N]),v.useEffect(()=>{J.current+=1,B.current=[],le.current=0,ne.current.clear(),D(null),ee(null),W(K=>(K.forEach(ht),Cj(o?C(o):[])))},[o,ht,C]),v.useEffect(()=>{const K=se.current;se.current=l??null,!(K===null||l===K)&&(Ot(),o&&k(o))},[l,o,Ot,k]),v.useEffect(()=>{oe.current=H},[H]),v.useEffect(()=>{if(!o)return;const K=H.filter(be=>be.status==="uploaded").map(({previewUrl:be,status:Le,uploadProgress:Pe,cancelUpload:ut,...Qe})=>Qe);if(K.length===0){k(o);return}E(o,K)},[H,o,k,E]),v.useEffect(()=>()=>{oe.current.forEach(ht)},[ht]);function Ge(K){hi.getState().setComposerState(I,K(de))}function it(K){Ge(be=>({...be,modelOptions:{...be.modelOptions,reasoningEffort:K}}))}function Je(K){Ge(be=>be.provider!=="claude"?be:l_e({...be,modelOptions:{...be.modelOptions,contextWindow:K}},be.model))}function Se(K){j(I,K)}function nt(){Se(!de.planMode)}const Ye=v.useCallback(()=>{if(l)for(;le.current<Jye&&B.current.length>0;){const K=B.current.shift();if(!K)break;le.current+=1;const be=crypto.randomUUID(),Le=K.type.startsWith("image/")?URL.createObjectURL(K):void 0,Pe=J.current,ut=Yye({projectId:l,file:K,onProgress:({loaded:Qe,total:Nt})=>{if(Pe!==J.current)return;const Zt=Nt>0?Qe/Nt:0;W(fn=>fn.map(hn=>hn.id===be?{...hn,uploadProgress:Zt}:hn))}});W(Qe=>[...Qe,{id:be,kind:K.type.startsWith("image/")?"image":"file",displayName:K.name,absolutePath:"",relativePath:"",contentUrl:"",mimeType:K.type||"application/octet-stream",size:K.size,status:"uploading",previewUrl:Le,uploadProgress:0,cancelUpload:ut.abort}]),(async()=>{try{const{attachments:Qe}=await ut.promise,Nt=Qe[0];if(!Nt)throw new Error("Upload failed");if(Pe!==J.current){OS(Nt),Le&&URL.revokeObjectURL(Le);return}if(ne.current.has(be)){ne.current.delete(be),Le&&URL.revokeObjectURL(Le),OS(Nt);return}W(Zt=>Zt.map(fn=>fn.id!==be?fn:{...fn,...Nt,previewUrl:fn.previewUrl,status:"uploaded",uploadProgress:1,cancelUpload:void 0})),ee(null)}catch(Qe){if(Pe!==J.current){Le&&URL.revokeObjectURL(Le);return}if(Qe instanceof DB){W(Nt=>Nt.filter(Zt=>Zt.id!==be)),ne.current.delete(be),Le&&URL.revokeObjectURL(Le);return}W(Nt=>Nt.map(Zt=>Zt.id===be?{...Zt,status:"failed",cancelUpload:void 0}:Zt)),ee(Qe instanceof Error?Qe.message:String(Qe))}finally{le.current=Math.max(0,le.current-1),Ye()}})()}},[l]),De=v.useCallback(K=>{if(!l){ee("Open a project before uploading files.");return}if(t_e({currentAttachmentCount:oe.current.length,queuedAttachmentCount:B.current.length,incomingAttachmentCount:K.length})){ee(`You can upload up to ${PB} files at a time.`);return}B.current.push(...K),ee(null),Ye()},[Ye,l]);v.useImperativeHandle(b,()=>({enqueueFiles:De}),[De]);async function It(){if(!Ct||At)return;const K=O,be=oe.current,Le=Z,Pe=G,ut=dn.map(({previewUrl:Zt,status:fn,uploadProgress:hn,cancelUpload:sr,..._i})=>_i);let Qe;de.provider==="claude"?Qe={claude:{...de.modelOptions}}:Qe={codex:{...de.modelOptions}};const Nt={provider:Ne,model:de.model,modelOptions:Qe,planMode:lt?de.planMode:!1,attachments:ut};$(""),o&&S(o),V.current&&(V.current.style.height="auto"),Ot({cleanupPreviews:!1}),ce.current&&k(ce.current);try{await t(K,Nt),be.forEach(ht)}catch(Zt){console.error("[ChatInput] Submit failed:",Zt),$(K),o&&x(o,K),W(be),D(Le),ee(Pe)}}function an(K){if(K.nativeEvent.isComposing||K.keyCode===229)return;if(qe){if(K.key==="Escape"){K.preventDefault(),ye(!0);return}if(K.key==="ArrowDown"){K.preventDefault(),Bt(Le=>Math.min(Be.length-1,Le+1));return}if(K.key==="ArrowUp"){K.preventDefault(),Bt(Le=>Math.max(0,Le-1));return}if(K.key==="Enter"||K.key==="Tab"){K.preventDefault();const Le=Be[gt];Le&&rt(Le);return}}if(Lt){if(K.key==="Escape"){K.preventDefault(),Et(!0);return}if(K.key==="ArrowDown"){K.preventDefault(),ot(Le=>Math.min(Wt.length-1,Le+1));return}if(K.key==="ArrowUp"){K.preventDefault(),ot(Le=>Math.max(0,Le-1));return}if(K.key==="Enter"||K.key==="Tab"){K.preventDefault();const Le=Wt[fe];Le&&ft(Le);return}}if(K.key==="Tab"&&!K.shiftKey){K.preventDefault(),DK(V.current,document);return}if(K.key==="Tab"&&K.shiftKey&<){K.preventDefault(),nt();return}if(K.key==="Escape"&&s){K.preventDefault(),r==null||r();return}if(K.key==="ArrowUp"&&!K.shiftKey&&!K.altKey&&!K.ctrlKey&&!K.metaKey&&O.length===0&&g){K.preventDefault(),$(g),o&&x(o,g);return}const be="ontouchstart"in window||navigator.maxTouchPoints>0;K.key==="Enter"&&!K.shiftKey&&!be&&!i&&Rt&&!At&&(K.preventDefault(),It())}function Fe(K){const be=s_e(K.clipboardData.items,Date.now()),Le=K.clipboardData.getData("text/plain"),Pe=o_e(Le),ut=Le.length>0&&Pe!==Le;if(!(be.length===0&&!ut)){if(be.length>0&&De(be),ut){K.preventDefault();const Qe=K.currentTarget,Nt=a_e({value:O,insertedText:Pe,selectionStart:Qe.selectionStart,selectionEnd:Qe.selectionEnd}),Zt=Qe.selectionStart+Pe.length;$(Nt),o&&x(o,Nt),Ft(),requestAnimationFrame(()=>{Qe.selectionStart=Zt,Qe.selectionEnd=Zt});return}n_e(K.clipboardData)||K.preventDefault()}}function Vt(K){if(Gp(K).openInNewTab){typeof window<"u"&&window.open(new URL(K.contentUrl,window.location.origin).toString(),"_blank","noopener,noreferrer");return}D(K.id)}function _n(K){var be;K.status==="uploading"&&((be=K.cancelUpload)==null||be.call(K)),ne.current.add(K.id),W(Le=>{const Pe=Le.find(ut=>ut.id===K.id);return Pe&&ht(Pe),Le.filter(ut=>ut.id!==K.id)}),Z===K.id&&D(null),K.status==="uploaded"&&(ne.current.delete(K.id),OS(K))}return f.jsxs("div",{children:[f.jsxs("div",{className:he("px-3 pt-0",F&&"px-5"),children:[f.jsxs("div",{className:"max-w-[840px] mx-auto rounded-[32px]",children:[We.length>0?f.jsx("div",{className:"flex flex-wrap gap-1 px-2 pt-2",children:We.map((K,be)=>f.jsxs("span",{className:he("inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs",K.kind==="ok"?"bg-accent text-accent-foreground":"bg-destructive/15 text-destructive"),children:[f.jsx(LC,{className:"h-3 w-3"}),"agent/",K.label,K.kind==="missing"&&f.jsx("span",{className:"ml-1 font-medium",children:"unknown"})]},`${K.kind}:${K.label}:${be}`))}):null,H.length>0?f.jsx(jB,{className:"overflow-x-auto overflow-y-hidden whitespace-nowrap px-2 pb-2",children:f.jsx("div",{className:"flex items-end gap-2 pt-2",children:Ue.map(K=>f.jsx("div",{className:he("flex shrink-0 flex-col justify-end",K.status==="failed"&&"text-destructive"),children:K.kind==="image"?f.jsx(kE,{attachment:K,previewUrl:K.previewUrl,size:"composer",onClick:K.status==="uploaded"?()=>Vt(K):void 0,onRemove:()=>_n(K),uploadProgress:K.status==="uploading"?K.uploadProgress??null:void 0,onCancelUpload:K.status==="uploading"?()=>_n(K):void 0}):f.jsx(Sl,{attachment:K,onClick:K.status==="uploaded"&&K.contentUrl?()=>Vt(K):void 0,onRemove:()=>_n(K),uploadProgress:K.status==="uploading"?K.uploadProgress??null:void 0,onCancelUpload:K.status==="uploading"?()=>_n(K):void 0})},K.id))})}):null,f.jsxs("div",{className:"relative flex items-end max-w-[840px] mx-auto border bg-background dark:bg-card/90 border-border rounded-[29px] pr-1.5 transition-colors focus-within:border-ring/60 focus-within:ring-2 focus-within:ring-ring/30",children:[Lt&&f.jsx(Eye,{items:Wt,activeIndex:fe,loading:je,onSelect:ft,onHoverIndex:ot}),qe&&f.jsx(Tye,{items:Be,activeIndex:gt,loading:Xe.loading,onSelect:rt,onHoverIndex:Bt}),f.jsxs("label",{"aria-label":"Add attachment",className:he(a0({variant:"ghost",size:"icon"}),"relative flex-shrink-0 ml-1 mb-1 h-11 w-11 rounded-full text-muted-foreground hover:text-foreground",i&&"pointer-events-none opacity-50"),children:[f.jsx(uW,{className:"h-5 w-5"}),f.jsx("input",{type:"file",multiple:!0,disabled:i,"aria-label":"Add attachment",className:"absolute inset-0 cursor-pointer opacity-0",onChange:K=>{const be=[...K.target.files??[]];be.length>0&&De(be),K.target.value=""}})]}),f.jsx(Y0,{ref:xe,placeholder:"Build something...",value:O,autoFocus:!0,[qC]:"",rows:1,onChange:K=>{$(K.target.value),o&&x(o,K.target.value),Ft(),Dt(be=>be+1)},onSelect:()=>Dt(K=>K+1),onKeyUp:()=>Dt(K=>K+1),onPaste:Fe,onKeyDown:an,disabled:i,className:"flex-1 text-base p-3 md:p-4 !pr-2 pl-0 md:pl-6 resize-none max-h-[200px] outline-none focus:outline-none focus-visible:outline-none focus-visible:ring-0 bg-transparent border-0 shadow-none"}),f.jsx(Ke,{type:"button",onPointerDown:K=>{K.preventDefault(),!i&&Rt&&!At?It():s?r==null||r():!i&&Ct&&!At&&It()},disabled:i||!s&&!Ct||At,size:"icon","aria-label":s?"Stop":"Send message",className:"flex-shrink-0 bg-primary text-background rounded-full cursor-pointer h-11 w-11 mb-1 -mr-0.5 md:mr-0 md:mb-1.5 touch-manipulation disabled:opacity-50",children:Rt?f.jsx(Gh,{className:"h-5 w-5 md:h-6 md:w-6"}):s?f.jsx("div",{className:"w-3 h-3 md:w-4 md:h-4 rounded-xs bg-current"}):f.jsx(Gh,{className:"h-5 w-5 md:h-6 md:w-6"})})]})]}),G?f.jsx("div",{className:"max-w-[840px] mx-auto mt-2 px-1 text-sm text-destructive",children:G}):null]}),f.jsxs("div",{className:he("relative py-3 max-w-[840px] mx-auto",F&&"p-5 pt-3"),children:[f.jsxs("div",{className:"overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden flex flex-row",children:[f.jsx("div",{className:"min-w-3"}),f.jsx(I1,{availableProviders:p,selectedProvider:Ne,showCodexCliRequirementHints:!0,model:de.model,modelOptions:de.modelOptions,onProviderChange:K=>{U(I,K)},onModelChange:(K,be)=>{M(I,be)},onModelOptionChange:K=>{switch(K.type){case"claudeReasoningEffort":it(K.effort);break;case"codexReasoningEffort":it(K.effort);break;case"contextWindow":Je(K.contextWindow);break;case"fastMode":Ge(be=>be.provider==="claude"?be:{...be,modelOptions:{...be.modelOptions,fastMode:K.fastMode}});break}},planMode:de.planMode,onPlanModeChange:Se,includePlanMode:lt,className:"max-w-[840px] mx-auto"}),Jt?f.jsx("div",{className:"flex items-center md:hidden mx-[13px]",children:f.jsx(wj,{usage:Jt})}):null,f.jsx("div",{className:"min-w-3"})]}),Jt?f.jsx("div",{className:"absolute right-[29px] top-1/2 translate-x-1/2 -translate-y-1/2 hidden md:block",children:f.jsx(wj,{usage:Jt})}):null]}),f.jsx(W0,{attachment:vt,onOpenChange:K=>!K&&D(null)})]})}),d_e=v.memo(u_e);async function OS(e){if(!e.contentUrl)return;const t=e.contentUrl.replace(/\/content$/,"");await fetch(t,{method:"DELETE"}).catch(()=>{})}function Cj(e){return e.map(t=>({...t,status:"uploaded"}))}const f_e=v.memo(function({inputRef:t,onLayoutChange:n,chatInputRef:r,chatInputElementRef:i,activeChatId:s,previousPrompt:o,hasSelectedProject:l,canCancel:c,projectId:u,activeProvider:p,availableProviders:h,contextWindowSnapshot:g,onSubmit:b,onCancel:_}){return f.jsx("div",{className:"absolute bottom-0 left-0 right-0 z-20 pointer-events-none",children:f.jsx("div",{className:"bg-gradient-to-t from-background via-background pointer-events-auto",ref:t,children:f.jsx(d_e,{ref:r,inputElementRef:i,onLayoutChange:n,onSubmit:b,onCancel:_,disabled:!l,canCancel:c,chatId:s,projectId:u,activeProvider:p,availableProviders:h,contextWindowSnapshot:g,previousPrompt:o},s??"new-chat")})})});var zS={exports:{}},BS={};/**
|
|
2630
2630
|
* @license React
|
|
2631
2631
|
* use-sync-external-store-shim.production.js
|
|
2632
2632
|
*
|